hyper-html-api 0.11.3 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/conformance/MANIFEST.json +2 -2
  2. package/conformance/cases/stylevar-read.expected.json +12 -0
  3. package/conformance/cases/stylevar-read.html +7 -0
  4. package/conformance/cases/stylevar-read.meta +6 -0
  5. package/conformance/cases/stylevar-read.parsed.json +12 -0
  6. package/conformance/cases/stylevar-read.rules +1 -0
  7. package/conformance/cases/write-refused-raw-style.data.json +1 -0
  8. package/conformance/cases/write-refused-raw-style.error.json +11 -0
  9. package/conformance/cases/write-refused-raw-style.html +1 -0
  10. package/conformance/cases/write-refused-raw-style.meta +4 -0
  11. package/conformance/cases/write-refused-stylevar-values.data.json +1 -0
  12. package/conformance/cases/write-refused-stylevar-values.error.json +43 -0
  13. package/conformance/cases/write-refused-stylevar-values.html +1 -0
  14. package/conformance/cases/write-refused-stylevar-values.meta +5 -0
  15. package/conformance/cases/write-stylevar-clear.after.html +1 -0
  16. package/conformance/cases/write-stylevar-clear.after.json +4 -0
  17. package/conformance/cases/write-stylevar-clear.data.json +1 -0
  18. package/conformance/cases/write-stylevar-clear.html +1 -0
  19. package/conformance/cases/write-stylevar-clear.meta +5 -0
  20. package/conformance/cases/write-stylevar-clear.write.json +4 -0
  21. package/conformance/cases/write-stylevar-set.after.html +2 -0
  22. package/conformance/cases/write-stylevar-set.after.json +5 -0
  23. package/conformance/cases/write-stylevar-set.data.json +1 -0
  24. package/conformance/cases/write-stylevar-set.html +1 -0
  25. package/conformance/cases/write-stylevar-set.meta +6 -0
  26. package/conformance/cases/write-stylevar-set.write.json +4 -0
  27. package/conformance/cases/write-stylevar-unchanged.after.html +1 -0
  28. package/conformance/cases/write-stylevar-unchanged.after.json +3 -0
  29. package/conformance/cases/write-stylevar-unchanged.data.json +1 -0
  30. package/conformance/cases/write-stylevar-unchanged.html +1 -0
  31. package/conformance/cases/write-stylevar-unchanged.meta +5 -0
  32. package/conformance/cases/write-stylevar-unchanged.write.json +4 -0
  33. package/conformance/write-policy.json +23 -1
  34. package/dist/hyper-html-api.engine.esm.js +1 -1
  35. package/dist/hyper-html-api.engine.min.js +1 -1
  36. package/dist/hyper-html-api.min.js +8 -8
  37. package/dist/hyper-html-api.upgrade.min.js +2 -2
  38. package/package.json +4 -2
  39. package/packed-contract.json +1 -1
  40. package/src/engine/apply.js +16 -0
  41. package/src/engine/extract.js +2 -0
  42. package/src/engine/index.js +2 -1
  43. package/src/engine/round-trip.js +5 -0
  44. package/src/engine/style-vars.js +141 -0
  45. package/src/engine/write-policy.js +60 -0
  46. package/src/page.js +343 -0
  47. package/src/upgrade/run.js +30 -0
@@ -1,2 +1,2 @@
1
- var hyperHtmlApiUpgrade=(()=>{var ce=Object.defineProperty;var st=Object.getOwnPropertyDescriptor;var ct=Object.getOwnPropertyNames;var lt=Object.prototype.hasOwnProperty;var Re=(e,t)=>{for(var n in t)ce(e,n,{get:t[n],enumerable:!0})},ft=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ct(t))!lt.call(e,r)&&r!==n&&ce(e,r,{get:()=>t[r],enumerable:!(o=st(t,r))||o.enumerable});return e};var ut=e=>ft(ce({},"__esModule",{value:!0}),e);var Gt={};Re(Gt,{default:()=>Xt,engine:()=>Ee,upgrade:()=>ot});var Y=["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"],X=new Set(Y),le=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),G=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]),Ne=new Set(["checked","selected","disabled","readOnly","paused"]);function fe(e,t){return t==null?Ne.has(e)?!1:"":Ne.has(e)?t==="false"?!1:!!t:t}var ee={};Re(ee,{EmptyListInsert:()=>M,MAX_RULE_DEPTH:()=>D,MaxRuleDepthExceeded:()=>k,NoRulesTag:()=>ue,RuleTargetReadOnly:()=>v,RulesParseError:()=>_,ShapeMismatch:()=>U,UnknownRulesVersion:()=>P,WriteNotRoundTripped:()=>Q,WriteRefused:()=>Z,WriteRejected:()=>ae});var _=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},P=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},D=20,k=class extends Error{constructor(t){super(`rule depth exceeded ${D} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},U=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},M=class extends Error{constructor(t,n){super(n?`cannot add items to empty list at "${t.join(".")}" \u2014 ${n}`:`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}},v=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},Z=class extends Error{constructor(t){super(`write refused: ${t.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=t}};function at(e){return e.reduce((n,o)=>typeof o=="number"?`${n}[${o}]`:n?`${n}.${o}`:String(o),"")||"(root)"}var Q=class extends Error{constructor(t){super(`write did not round-trip at "${at(t)}"`),this.name="WriteNotRoundTripped",this.path=t}},ue=class extends Error{constructor(t){super(`no <script data-rules-name~="${t}"> rules tag in this document`),this.name="NoRulesTag",this.token=t}},ae=class extends Error{constructor(t,n){super(`write rejected: ${t.length} unknown key(s), ${n.length} rule(s) with no matching element`),this.name="WriteRejected",this.unknownKeys=t,this.unmatched=n}};function S(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 de(e){let t=S(e);return t===-1?{selector:e,prop:null}:{selector:e.slice(0,t),prop:e.slice(t+1)||null}}function he(e){let t=0,n=null,o=-1,r=!1;for(let i=0;i<e.length;i++){let s=e[i];s==="\\"?i++:n?s===n&&(n=null):s==='"'||s==="'"?n=s:s==="["||s==="("?t++:s==="]"||s===")"?t>0&&t--:t===0&&s===">"?o=i:t===0&&s===","&&(r=!0)}return r||o===-1||!dt(e,o+1)?null:e.slice(0,o).trim()||null}function dt(e,t){let n=t,o=e.replace(/\s+$/,"").length;for(;n<o&&/\s/.test(e[n]);)n++;let r=0,i=null;for(;n<o;n++){let s=e[n];if(s==="\\")n++;else if(i)s===i&&(i=null);else if(s==='"'||s==="'")i=s;else if(s==="["||s==="(")r++;else if(s==="]"||s===")")r>0&&r--;else if(r===0&&(s==="+"||s==="~"||/\s/.test(s)))return!1}return!0}function N(e,t,n,o={}){if(Object.prototype.hasOwnProperty.call(o,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return pe(e,t,n,{depth:0,path:[]},o)}function pe(e,t,n,o,r){if(o.depth>D)throw new k(o.path);if(typeof n=="string")return ht(e,t,n,o,r);if(Array.isArray(n)){let[i,s]=n,c=e.find(t,i,r);return Me(r,o,c),c.map((l,a)=>pe(e,l,s,{depth:o.depth+1,path:[...o.path,a]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[s,c]of Object.entries(n))i[s]=pe(e,t,c,{depth:o.depth+1,path:[...o.path,s]},r);return i}return null}function ht(e,t,n,o,r){if(n.endsWith("[]")){let c=n.slice(0,-2),l=e.find(t,c,r);return Me(r,o,l),l.map(a=>e.text(a))}if(n.startsWith("@"))return Ce(e,t,n.slice(1));let i=S(n);if(i!==-1){let c=n.slice(0,i),l=n.slice(i+1),a=c?e.find(t,c,r):[t];return a.length===0?null:Ce(e,a[0],l)}if(n===".")return e.text(t);let s=e.find(t,n,r);return s.length===0?null:e.text(s[0])}function Me(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(o){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,o)}}function Ce(e,t,n){if(X.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o??null}function Ie(e,t,n,o){let r=e.length,i=t.length,s=new Array(r).fill(-1);if(o){let u=new Set;for(let m=0;m<r;m++){let w=o[m];!(w>=0&&w<i)||u.has(w)||(s[m]=w,u.add(w))}}if(r===0||i===0)return s;let c=e.map(u=>Pe(u,n)),l=t.map(u=>Pe(u,n)),a=new Array(i).fill(!1);for(let u of s)u>=0&&(a[u]=!0);let d=new Map;l.forEach((u,m)=>{a[m]||d.set(u,d.has(u)?-1:m)});let y=new Map;c.forEach((u,m)=>{s[m]>=0||y.set(u,(y.get(u)||0)+1)}),c.forEach((u,m)=>{if(s[m]>=0||y.get(u)!==1)return;let w=d.get(u);w===void 0||w===-1||a[w]||(s[m]=w,a[w]=!0)});let p=[];for(let u=0;u<r;u++)s[u]<0&&p.push(u);let T=[];for(let u=0;u<i;u++)a[u]||T.push(u);if(p.length===0||T.length===0)return s;let f=r*i+1,h=pt(e,t,n),g=(u,m)=>h(u,m)*f+Math.abs(u-m);for(let[u,m]of mt(p,T,g))s[u]=m;return s}var Le=e=>typeof e=="object"&&e!==null;function Pe(e,t){if(!Le(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(o=>{let r=JSON.stringify(e?.[o]);return r===void 0?" undef":r}))}function pt(e,t,n){if(!Le(n))return(c,l)=>e[c]===t[l]?0:1;let o=Object.keys(n),r=c=>o.map(l=>JSON.stringify(c?.[l])),i=e.map(r),s=t.map(r);return(c,l)=>{let a=i[c],d=s[l],y=0;for(let p=0;p<o.length;p++)a[p]!==d[p]&&y++;return y}}function mt(e,t,n){return e.length<=t.length?ke(e,t,n,!1):ke(t,e,(o,r)=>n(r,o),!0)}function ke(e,t,n,o){let r=e.length,i=t.length,s=[];for(let y=0;y<=r;y++)s.push(new Float64Array(i+1).fill(1/0));let c=[];for(let y=0;y<=r;y++)c.push(new Uint8Array(i+1));for(let y=0;y<=i;y++)s[r][y]=0;for(let y=r-1;y>=0;y--)for(let p=i-1;p>=0;p--){let T=n(e[y],t[p])+s[y+1][p+1],f=s[y][p+1];T<=f?(s[y][p]=T,c[y][p]=1):s[y][p]=f}let l=[],a=0,d=0;for(;a<r&&d<i;)c[a][d]&&(l.push(o?[t[d],e[a]]:[e[a],t[d]]),a++),d++;return l}function ye(e,t,n,o,r,i,s,c={}){let l=e.find(t,n,c);if(r.length===0){l.forEach(A=>e.remove(A)),me(c,"onRowsApplied",i.path,[]);return}let a=r.length>l.length,d=l[0]||null;if(a&&!d&&(d=At(e,t,n,c),!d))throw new M(i.path);let y=l.map(A=>wt(e,A,o,c)),p=null;if(a&&d){p=e.clone(d),c.templateAttr&&e.removeAttr(p,c.templateAttr);let A=e.stripIds(p);A>0&&console.warn(`[hyper-html-api] stripped ${A} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let T=Ie(r,y,o,yt(e,l,r,i,c)),f=l.length>0?e.parent(l[0]):Ot(e,t,n,d,i,c),h=l.length>0?We(e,f,l[0]):0,g=Rt(e,l),u=new Set,m=[],w=r.map((A,b)=>{let E=T[b];if(E>=0)return u.add(E),m.push(!1),l[E];m.push(!0);let x=e.clone(p);return e.stripIds(x),x});l.forEach((A,b)=>{u.has(b)||e.remove(A)}),g?St(e,f,h,w,m):Nt(e,w,m,f,h),gt(e,w,o,r,i,s,c),me(c,"onRowsApplied",i.path,w)}function me(e,t,n,o){if(typeof e[t]=="function")try{return e[t](n.slice(),o)}catch(r){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,r);return}}function yt(e,t,n,o,r){let i=me(r,"identifyRows",o.path,n);if(!Array.isArray(i))return null;let s=new Array(n.length).fill(-1),c=new Set,l=new Map(t.map((a,d)=>[e.identity(a),d]));for(let a=0;a<n.length;a++){if(!i[a])continue;let d=l.get(e.identity(i[a]));d===void 0||c.has(d)||(s[a]=d,c.add(d))}return s}function gt(e,t,n,o,r,i,s){t.forEach((c,l)=>{if(n===null){let a=o[l],d=a==null?"":String(a);e.text(c)!==d&&e.text(c,d)}else{let a=i(e,c,n,o[l],{depth:r.depth+1,path:[...r.path,l]},s);a&&a!==c&&(t[l]=a)}})}function wt(e,t,n,o){return n===null?e.text(t):N(e,t,n,o.onRowsRead?{...o,onRowsRead:void 0}:o)}function We(e,t,n){let o=e.children(t);for(let r=0;r<o.length;r++)if(e.sameNode(o[r],n))return r;return-1}function At(e,t,n,o){if(!o.templateAttr)return null;let r=/^\s*:scope\s*>\s*/.test(n),i=new RegExp(":not\\(\\["+o.templateAttr.replace(/[.*+?^${}()|[\]\\-]/g,"\\$&")+"\\]\\)","g"),s=n.replace(/^\s*:scope\s*>\s*/,"").replace(i,""),c=r?Tt(s):0,l=he(s),a=t;for(;a;){let d=e.find(a,s,{includeRulesTag:!1,templateAttr:null});for(let y of d)if(e.attr(y,o.templateAttr)!=null&&!(r&&!Et(e,t,y,c))&&!(l&&!e.matches(e.parent(y),l)))return y;a=e.parent(a)}return null}function Tt(e){let t=0,n=null,o=1;for(let r=0;r<e.length;r++){let i=e[r];if(i==="\\")r++;else if(n)i===n&&(n=null);else if(i==='"'||i==="'")n=i;else if(i==="["||i==="(")t++;else if(i==="]"||i===")")t>0&&t--;else if(t===0&&i===">")o++;else{if(t===0&&(i==="+"||i==="~"))return null;if(t===0&&/\s/.test(i)){if(!xt(e,r))return null;for(;r+1<e.length&&/\s/.test(e[r+1]);)r++}}}return o}function xt(e,t){let n=t;for(;n<e.length&&/\s/.test(e[n]);)n++;let o=t>0?e[t-1]:"",r=n<e.length?e[n]:"";return je(o)||je(r)}function je(e){return e===">"||e==="+"||e==="~"}function Et(e,t,n,o){if(o===null)return!0;let r=n;for(let l=0;l<o;l++)if(r=e.parent(r),!r)return!1;let i=e.prop(t,"tagName");if(!i)return!0;let s=e.prop(r,"tagName");if(!s||String(s).toLowerCase()!==String(i).toLowerCase())return!1;let c=new Set(_e(e,r));return _e(e,t).every(l=>c.has(l))}function _e(e,t){let n=e.attr(t,"class");return n?String(n).split(/\s+/).filter(Boolean):[]}function Ot(e,t,n,o,r,i){let s=e.parent(o);if(s&&bt(e,t,s)&&!$e(e,s,i))return s;let c=he(n);if(!c)throw new M(r.path,`the list selector "${n}" names no container to hold the new rows \u2014 write it as "container > row" (for example "ol.comments > li") so the cloned row lands in the list`);let a=(c===":scope"?e.prop(t,"tagName")?[t]:[]:e.find(t,c,i)).filter(d=>!$e(e,d,i));if(a.length===0)throw new M(r.path,`no container matching "${c}" inside this context to hold the new rows`);if(a.length>1)throw new M(r.path,`"${c}" matches ${a.length} containers inside this context, so the new rows have no single destination`);return a[0]}function bt(e,t,n){let o=n;for(;o;){if(e.sameNode(o,t))return!0;o=e.parent(o)}return e.parent(t)?!1:e.find(t,"*",{includeRulesTag:!0,templateAttr:null}).some(r=>e.sameNode(r,n))}var De=["no-data","editor-ui"];function $e(e,t,n){let o=t;for(;o;){if(n.templateAttr&&e.attr(o,n.templateAttr)!=null||De.some(i=>e.attr(o,i)!=null))return!0;let r=e.attr(o,"clay");if(r&&r.split(/\s+/).some(i=>De.includes(i)))return!0;o=e.parent(o)}return!1}function St(e,t,n,o,r){let i=e.children(t),s=i.map(l=>e.identity(l)),c=!1;o.forEach((l,a)=>{let d=e.identity(l),y=n+a;if(s[y]===d)return;if(!r[a]){let T=s.indexOf(d);T!==-1&&(s.splice(T,1),i.splice(T,1))}let p=Math.min(y,i.length);p<i.length?e.insertBefore(i[p],l):i.length?c?e.insertAfter(i[i.length-1],l):(e.insertAt(t,l,y),c=!0):e.insertAt(t,l,0),s.splice(p,0,d),i.splice(p,0,l)})}function Rt(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let o=new Map(e.children(n).map((i,s)=>[e.identity(i),s])),r=[];for(let i of t){let s=o.get(e.identity(i));if(s===void 0)return!1;r.push(s)}return r.sort((i,s)=>i-s),r[r.length-1]-r[0]===r.length-1}function Nt(e,t,n,o,r){let i=null,s=r;for(let c=0;c<t.length;c++){if(!n[c]){i=t[c];continue}let l=i?e.parent(i):o;if(!l)continue;let a=i?We(e,l,i)+1:s++;e.insertAt(l,t[c],a),i=t[c]}}function I(e,t,n,o,r={}){if(Object.prototype.hasOwnProperty.call(r,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");let i=[];if(ge(n,o,[],i),i.length)throw new U(i);te(e,t,n,o,{depth:0,path:[]},r)}function te(e,t,n,o,r,i={}){if(r.depth>D)throw new k(r.path);if(o===void 0)return t;if(typeof n=="string")return Ct(e,t,n,o,r,i);if(Array.isArray(n)){let[s,c]=n;return ye(e,t,s,c,o,r,te,i),t}if(typeof n=="object"&&n!==null){for(let[s,c]of Object.entries(n)){let l=te(e,t,c,o==null?o:o[s],{depth:r.depth+1,path:[...r.path,s]},i);l&&l!==t&&(t=l)}return t}return t}function Ct(e,t,n,o,r,i){if(n.endsWith("[]")){let l=n.slice(0,-2);return ye(e,t,l,null,o,r,te,i),t}if(n.startsWith("@"))return ve(e,t,n.slice(1),o);let s=S(n);if(s!==-1){let l=n.slice(0,s),a=n.slice(s+1),d=l?e.find(t,l,i):[t];return d.length===0||ve(e,d[0],a,o),t}if(n===".")return Ue(e,t,o),t;let c=e.find(t,n,i);return c.length===0||Ue(e,c[0],o),t}function Ue(e,t,n){let o=n==null?"":String(n);e.text(t)!==o&&e.text(t,o)}function ve(e,t,n,o){if(G.has(n)){let r=e.prop(t,n);if(r===o||r!=null&&o!=null&&String(r)===String(o))return t;throw new v(n)}if(n==="outerHTML"){let r=o==null?"":String(o);return e.replaceWith(t,r)}if(le.has(n)){let r=fe(n,o);return e.prop(t,n)!==r&&e.prop(t,n,r),t}if(o==null)e.attr(t,n)!=null&&e.removeAttr(t,n);else{let r=String(o);e.attr(t,n)!==r&&e.attr(t,n,r)}return t}function ge(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:B([...n,i]),expected:"scalar",got:H(r)})}):o.push({path:B(n),expected:"array",got:H(t)});return}t!==null&&typeof t=="object"&&o.push({path:B(n),expected:"scalar",got:H(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:B(n),expected:"array",got:H(t)});return}let r=e[1];t.forEach((i,s)=>ge(r,i,[...n,s],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:B(n),expected:"object",got:H(t)});return}for(let[r,i]of Object.entries(e))ge(i,t[r],[...n,r],o)}}}function H(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function B(e){return e.join(".")}function we(e){try{return JSON.parse(e)}catch(t){throw new _(`Invalid strict JSON: ${t.message}`,t)}}function L(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=[],s=0;for(;s<r.length;){let c=r[s];if(/\s/.test(c)){s++;continue}if("{}".includes(c)){i.push({type:c,value:c}),s++;continue}if(c==="["){let y=!1,p=s+1;for(;p<r.length&&/\s/.test(r[p]);)p++;if(p<r.length&&/[a-zA-Z_]/.test(r[p])&&(y=!0),!y){i.push({type:c,value:c}),s++;continue}}if(c==="]"){i.push({type:c,value:c}),s++;continue}if(c===":"){i.push({type:t.COLON,value:c}),s++;continue}if(c===","){i.push({type:t.COMMA,value:c}),s++;continue}if(c==='"'||c==="'"){let y=c,p=s+1;for(;p<r.length&&r[p]!==y;)r[p]==="\\"&&p++,p++;i.push({type:t.STRING,value:r.substring(s+1,p),quoted:!0,sourceQuote:y}),s=p+1;continue}let l=s,a;for(;l<r.length&&!/[{},]/.test(r[l]);)if(r[l]===":"){let y=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],p=!1;for(let T of y){let f=T.substring(1);if(r.substring(l+1,l+1+f.length)===f){p=!0,l+=f.length;break}}if(!p)break}else if(r[l]==="["){for(l++;l<r.length&&r[l]!=="]";){if(r[l]==='"'||r[l]==="'"){let y=r[l];for(l++;l<r.length&&r[l]!==y;)r[l]==="\\"&&l++,l++}l++}l<r.length&&r[l]==="]"&&l++}else l++;a=r.substring(s,l);let d=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(a)?d=t.NUMBER:a==="true"||a==="false"||a==="null"?d=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(a)&&(d=t.SELECTOR),i.push({type:d,value:a,quoted:!1}),s=l}return i}function o(r){let i="";for(let s=0;s<r.length;s++){let c=r[s];if("{}".includes(c.type)||"[]".includes(c.type)){i+=c.value;continue}if(c.type===t.COLON){i+=c.value;continue}if(c.type===t.COMMA){let l=r[s+1];if(l&&(l.type==="}"||l.type==="]"))continue;i+=c.value;continue}if(c.type===t.STRING&&c.quoted){let l=c.value;c.sourceQuote==="'"&&(l=l.replace(/\\'/g,"'"),l=l.replace(/(\\*)"/g,(a,d)=>d.length%2===0?d+'\\"':a)),i+=`"${l}"`;continue}if(c.type===t.NUMBER||c.type===t.BOOLEAN){i+=c.value;continue}if(c.type===t.SELECTOR||c.type===t.IDENTIFIER){i+=`"${c.value}"`;continue}i+=`"${c.value}"`}return i}try{let r=n(e),i=o(r);return JSON.parse(i)}catch(r){throw new _("Invalid extraction rules syntax: "+r.message,r)}}var Ae="1",He=/^[a-zA-Z0-9_-]+$/;function q(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!He.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${He})`);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],s=e.attr(i,"data-rules-version");if(s!==Ae)throw new P(s);return{rules:L(e.text(i)),tagNode:i}}var ne=Object.freeze({data:Object.freeze({tokens:["no-data"],bundles:["editor-ui"]}),save:Object.freeze({tokens:["no-save"],bundles:["editor-ui"]}),snapshot:Object.freeze({tokens:["no-snapshot"],bundles:["editor-ui"]}),watch:Object.freeze({tokens:["no-watch"],bundles:["editor-ui"]}),undo:Object.freeze({tokens:["no-undo"],bundles:["editor-ui"]}),history:Object.freeze({tokens:[],bundles:["editor-ui"]})}),Mt=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),Be=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui","live"]);function K(e,t){if(!e||e.nodeType!==1)return!1;let n=e.getAttribute?.("clay");return!!(n&&n.split(/\s+/).includes(t)||e.hasAttribute?.(t))}function Te(e,t){if(K(e,t))return!0;for(let[n,o]of Object.entries(Mt))if(o.includes(t)&&K(e,n))return!0;return!1}function z(e){let t=ne[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function Pt(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let o=ne[t];if(!o)throw new Error(`Unknown region capability: ${t}`);if(o.tokens.some(r=>Te(n,r))||o.bundles.some(r=>K(n,r)))return n;n=n.parentElement}return null}function qe(e,t){return!!Pt(e,t)}var kt=Object.freeze({refusedRuleForms:["innerHTML","outerHTML"],refusedTargets:["script","style","template","noscript","iframe","object","embed","xmp","plaintext","noembed","noframes","meta","link","base","animate","set","animatemotion","animatetransform"],refusedAttributes:["style","srcdoc","is","http-equiv","sandbox","allow","nonce","integrity","charset","htmlclaytoken","htmlclayid","data-rules-name","data-rules-version","clay","contenteditable",...Be],refusedAttributePrefixes:["on"],urlAttributes:["href","src","srcset","action","formaction","poster","cite","data","ping","background","longdesc","usemap","xlink:href","manifest","codebase","icon"],refusedSchemes:["javascript","vbscript","data"]});function xe(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 q(e,o,n)}return null}var _t=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function Dt(e,t){if(!/^(INPUT|TEXTAREA|SELECT|OPTION)$/.test(e.tagName||""))return;let n=(e.getAttribute?.("type")||"").toLowerCase();"value"in e&&"value"in t&&e.tagName!=="OPTION"&&n!=="checkbox"&&n!=="radio"&&n!=="file"&&(t.value=e.value),e.tagName==="INPUT"&&(n==="checkbox"||n==="radio")&&(t.checked=e.checked),e.tagName==="OPTION"&&(t.selected=e.selected),"indeterminate"in e&&"indeterminate"in t&&(t.indeterminate=e.indeterminate)}function Ke(e,t,n,o){if(o)return!!e.closest?.(t);let r=e;for(;r?.nodeType===1;){if(r.matches(t))return!0;if(r===n)break;r=r.parentElement}return!1}function ze(e,t,n,o,r,i){return(i?qe(e,t):Ke(e,n,r,!1))||!!(o&&(i&&e!==r?e.matches(o):Ke(e,o,r,i)))}function $t(e,t){let n=ne[t];return n.tokens.some(o=>Te(e,o))||n.bundles.some(o=>K(e,o))}var Wt=new Set(["INPUT","TEXTAREA","SELECT","OPTION"]);function Fe(e,t,n,o){if(e.nodeType===1&&o(e)){n.dropped.push(t);return}n.cloneToLive.set(t,e),n.liveToClone.set(e,t);let r=e,i=t;if(e.nodeType===1){if(Wt.has(e.tagName)&&n.controls.push(e,t),e.tagName==="TEMPLATE"){for(;t.firstChild;)t.removeChild(t.firstChild);r=e.content,i=t.content,n.cloneToLive.set(i,r),n.liveToClone.set(r,i)}}else if(e.nodeType!==11)return;let s=i.firstChild;for(let c=r.firstChild;c&&s;c=c.nextSibling)Fe(c,s,n,o),s=s.nextSibling}function F(e,{capability:t="data",exclude:n=null,inherit:o=!0,provenance:r=null}={}){if(!e)throw new TypeError("createContentView requires a DOM context");let i=e.nodeType===9?e:e.ownerDocument;if(!i?.implementation?.createHTMLDocument)throw new TypeError("createContentView requires an HTML DOM implementation");let s=i.implementation.createHTMLDocument(""),c=r||new WeakMap,l=new WeakMap,a=e.nodeType===9?e.documentElement:e;n&&s.documentElement.matches(n);let d=z(t),y=o?f=>$t(f,t)||!!(n&&f.matches(n)):f=>ze(f,t,d,n,a,!1),p=null;if(a.nodeType!==1||!ze(a,t,d,n,a,o)){p=s.importNode(a,!0);let f={cloneToLive:c,liveToClone:l,dropped:[],controls:[]};Fe(a,p,f,y);for(let h of f.dropped)h.remove();for(let h=0;h<f.controls.length;h+=2)Dt(f.controls[h],f.controls[h+1])}e.nodeType===9&&p&&(s.replaceChild(p,s.documentElement),l.set(e,s),c.set(s,e));let T=f=>{if(_t.test(f))throw new Error(`Filtered content queries do not support stateful selector: ${f}`)};return{root:p,document:s,capability:t,selector:z(t),cloneToLive:c,liveToClone:l,original(f){return c.get(f)||null},cloneOf(f){return l.get(f)||null},query(f,h=p){return T(f),Array.from(h.querySelectorAll(f),g=>c.get(g)||g)},text(f=p){return(f===p?p:l.get(f))?.textContent||""},html(f=p){return(f===p?p:l.get(f))?.innerHTML??""},clone(f=p){let h=f===p?p:l.get(f);return h?s.importNode(h,!0):null}}}function Je(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function Ut(e){return e?(e.nodeType===9||e.nodeType===11,e):null}function Ve(e,t,n){!e||e.nodeType!==1||(t==="value"&&e.tagName==="INPUT"?e.value=n===null?"":n:t==="checked"&&e.tagName==="INPUT"?e.checked=n!==null:t==="selected"&&e.tagName==="OPTION"&&(e.selected=n!==null))}function Ye(e,t){e&&e.tagName==="TEXTAREA"&&(e.value=t)}function Xe(e){if(!e||e.nodeType!==1)return;let t=[e,...e.querySelectorAll?e.querySelectorAll("textarea, input, option"):[]];for(let n of t)if(n.tagName==="TEXTAREA")n.value=n.defaultValue;else if(n.tagName==="INPUT"){let o=n.type;o!=="file"&&o!=="checkbox"&&o!=="radio"&&(n.value=n.defaultValue),n.checked=n.defaultChecked}else n.tagName==="OPTION"&&(n.selected=n.defaultSelected)}var O={semanticExclude:!0,find(e,t,n={}){let o=Ut(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(c=>!Je(c)));let i=[];n.skip&&i.push(n.skip);let s=n.templateAttr===null?null:n.templateAttr||"cms-template";if(s&&i.push("["+s+"]"),i.length){let c=i.join(", ");r=r.filter(l=>!l.closest||!l.closest(c))}return r},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},matches(e,t){return!!(e&&e.matches)&&e.matches(t)},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t,Ye(e,t)},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n),Ve(e,t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t),Ve(e,t,null)},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){let t=e.cloneNode(!0);return Xe(t),t},insertAt(e,t,n){let o=e.children[n]||null;e.insertBefore(t,o)},insertBefore(e,t){e.parentNode.insertBefore(t,e)},insertAfter(e,t){e.parentNode.insertBefore(t,e.nextSibling)},identity(e){return e||null},remove(e){e&&e.parentNode&&e.parentNode.removeChild(e)},replaceWith(e,t){if(!e||!e.parentNode)throw new Error("dom.replaceWith: node has no parent");let o=e.ownerDocument.createElement("template");o.innerHTML=t;let r=o.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(r,e),r},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(o=>{o.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};function V(e,t={}){if(t.exclude===null)return O;let n=[z("data"),t.exclude].filter(Boolean).join(", "),o=e.nodeType===9?e:e.ownerDocument||e,r=e.nodeType===9?e.documentElement:e;if(!t._write&&!r?.matches?.(n)&&!r?.querySelector?.(n)&&!o?.querySelector?.(n))return O;let i=e.nodeType===9||!e.isConnected?e:e.ownerDocument,s=e.nodeType===9?e:e.ownerDocument,c=null,l=()=>c||(c=F(i,{capability:"data",exclude:t.exclude||null})),a=f=>{let h=l();return f===e?h.cloneOf(e):h.cloneOf(f)||f},d=f=>c?.original(f)||f,y=(f,h)=>{l().liveToClone.set(f,h),l().cloneToLive.set(h,f);let g=f.childNodes||[],u=h.childNodes||[];for(let m=0;m<Math.min(g.length,u.length);m++)y(g[m],u[m])},p=(f,h,g,u)=>{let m=Array.from(f.childNodes).filter(x=>c.cloneOf(x)),A=m[0];for(;A&&m.includes(A);)A=A.nextSibling;for(let x of m)x.remove();if(g==="innerHTML"){let x=s.createElement("template");x.innerHTML=u;for(let W of Array.from(x.content.childNodes))f.insertBefore(W,A||null)}else f.insertBefore(s.createTextNode(u),A||null),Ye(f,u);let b=F(f,{capability:"data",exclude:t.exclude||null});h.replaceChildren(...Array.from(b.root?.childNodes||[]));let E=x=>{let W=b.original(x);W&&(c.liveToClone.set(W,x),c.cloneToLive.set(x,W));for(let it of Array.from(x.childNodes||[]))E(it)};for(let x of Array.from(h.childNodes))E(x)},T={...O,find(f,h,g={}){let u=a(f);if(!u?.querySelectorAll)return[];let m=l().query(h,u);g.includeRulesTag||(m=m.filter(b=>!Je(b)));let w=[];g.skip&&w.push(g.skip);let A=g.templateAttr===null?null:g.templateAttr||"cms-template";if(A&&w.push(`[${A}]`),w.length){let b=w.join(", ");m=m.filter(E=>!E.closest?.(b))}return m},parent(f){let h=a(f)?.parentElement;return h?d(h):null},children(f){return Array.from(a(f)?.children||[],d)},text(f,h){if(h===void 0){let m=d(f);return!m?.matches?.(n)&&!m?.querySelector?.(n)?O.text(m):(a(f)?.textContent||"").trim()}let g=d(f);if(!g?.matches?.(n)&&!g?.querySelector?.(n)&&!c){O.text(g,h);return}let u=l().cloneOf(g);u?p(g,u,"textContent",h):O.text(g,h)},attr(f,h,g){let u=d(f);if(g===void 0)return O.attr(u,h);O.attr(u,h,g);let m=c?.cloneOf(u);m&&(O.attr(m,h,g),F(u,{capability:"data",exclude:t.exclude||null}).root===null&&(m.remove(),c.liveToClone.delete(u),c.cloneToLive.delete(m)))},removeAttr(f,h){let g=d(f);O.removeAttr(g,h);let u=c?.cloneOf(g);u&&O.removeAttr(u,h)},prop(f,h,g){let u=d(f);if(g===void 0)return h==="innerHTML"||h==="outerHTML"||h==="textContent"||h==="innerText"?O.prop(a(u),h):O.prop(u,h);let m=h==="innerHTML"||h==="textContent"||h==="innerText",w=m?l().cloneOf(u):c?.cloneOf(u);w&&m?p(u,w,h,g):(O.prop(u,h,g),w&&O.prop(w,h,g))},clone(f){let h=a(f);if(h===f)return O.clone(f);let g=s.importNode(h,!0);return Xe(g),g},insertAt(f,h,g){let u=d(f),w=T.children(u)[g]||(()=>{for(let E=u.children.length-1;E>=0;E--){let x=u.children[E];if(l().cloneOf(x))return x.nextElementSibling}return u.firstElementChild})(),A=d(h);u.insertBefore(A,w||null);let b=l().cloneOf(u);if(b){let E=l().cloneOf(A);E||(E=s.importNode(A,!0),y(A,E));let x=Array.from(b.children);b.insertBefore(E,x[g]||null)}},insertBefore(f,h){let g=d(f),u=d(h);g.parentNode.insertBefore(u,g);let m=l().cloneOf(g.parentNode);if(m){let w=l().cloneOf(u);w||(w=s.importNode(u,!0),y(u,w));let A=l().cloneOf(g);A?A.before(w):m.appendChild(w)}},insertAfter(f,h){let g=d(f),u=d(h);g.parentNode.insertBefore(u,g.nextSibling);let m=l().cloneOf(g.parentNode);if(m){let w=l().cloneOf(u);w||(w=s.importNode(u,!0),y(u,w));let A=l().cloneOf(g);A?A.after(w):m.appendChild(w)}},identity(f){return d(f)||null},remove(f){let h=d(f),g=l().cloneOf(h);O.remove(h),g&&O.remove(g)},replaceWith(f,h){let g=d(f),u=l().cloneOf(g),m=O.replaceWith(g,h);if(u){let w=F(m,{capability:"data",exclude:t.exclude||null});if(!w.root)u.remove();else{u.replaceWith(w.root);let A=b=>{let E=w.original(b);E&&(c.liveToClone.set(E,b),c.cloneToLive.set(b,E));for(let x of Array.from(b.childNodes||[]))A(x)};A(w.root)}}return m}};return T}var R=O;var Ee={extract:(e,t,n={})=>N(V(e,n),e,t,n),apply:(e,t,n,o={})=>I(V(e,{...o,_write:!0}),e,t,n,o),findRulesIn:(e,t)=>q(R,e,t),findRules:(e,t)=>xe(R,e,t),bind:(e,t,n={})=>{let o=xe(R,e,t);if(!o){let r=typeof t=="string"?`data-rules-name~="${t}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${r}`)}return{...o,get:()=>N(V(e,n),e,o.rules,n),set:r=>I(V(e,{...n,_write:!0}),e,o.rules,r,n)}},parseStrict:we,parseRelaxed:L,ruleAttrIndex:S,splitRule:de,errors:ee,DOM_PROPERTIES:Y};var vt="hha:upgrade-check:";function C(e,t){let n=e.querySelector(`meta[name="${t}"]`),o=n?n.getAttribute("content"):null;return o&&o.trim()?o.trim():null}function Ge(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function Ht(e,t){let n=Ge(e),o=Ge(t);if(!n||!o)return!1;let r=Math.max(n.length,o.length);for(let i=0;i<r;i++){let s=n[i]||0,c=o[i]||0;if(s!==c)return s>c}return!1}function Bt(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function qt(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function Ze({force:e=!1,doc:t,loc:n,fetchFn:o,now:r,ttlMs:i=864e5}={}){if(t=t||(typeof document<"u"?document:null),n=n||(typeof location<"u"?location:null),o=o||(p=>fetch(p)),r=r??Date.now(),!t)return null;let s=C(t,"hyper-source");if(!s)return null;let c=C(t,"hyper-version"),l;try{l=new URL(s,n?n.href:void 0)}catch{return null}if(n&&l.origin===n.origin&&l.pathname===n.pathname)return null;let a=`${vt}${l.href}:${c||"none"}`,d,y=e?null:Bt(a);if(y&&typeof y.checkedAt=="number"&&r-y.checkedAt<i)d=y.sourceVersion;else{try{let p=await o(l.href);if(!p.ok)throw new Error(`HTTP ${p.status}`);let T=await p.text(),f=new DOMParser().parseFromString(T,"text/html");d=C(f,"hyper-version")}catch{d=null}qt(a,{checkedAt:r,sourceVersion:d})}return d?{available:Ht(d,c||"0.0.0"),currentVersion:c,sourceVersion:d,sourceUrl:l.href}:null}var Kt="script[data-rules-name]";function zt(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function re(e,t){let n=e.find(t,Kt,{includeRulesTag:!0}),o=new Set,r=[];for(let i of n){let s=zt(e.attr(i,"data-rules-name"));if(!s)continue;if(o.has(s)){console.warn(`hyper-html-api: duplicate rules tag name "${s}"; using the first.`);continue}let c=e.attr(i,"data-rules-version");if(c!==Ae)throw new P(c);o.add(s),r.push({name:s,rules:L(e.text(i))})}return r}function Oe(e,t){let n={};for(let{name:o,rules:r}of re(e,t))n[o]=N(e,t,r);return n}function Qe(e){let t=e||document,n=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:Oe(R,t),version:C(n,"hyper-version")}}var J=class extends Error{constructor(t,n){super(`could not fetch upgrade source: ${t}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=t,this.cause=n}},oe=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}},j=class extends Error{constructor(t,n){super(t),this.name="UpgradeTransformInvalid",this.cause=n}},ie=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 Ft="text/hyper-upgrade";function et(e,t){let n=e.find(t,`script[type="${Ft}"]`);if(n.length===0)return null;if(n.length>1)throw new ie(n.length);return e.text(n[0])||null}var Vt=new Function("url","return import(url)");async function tt(e){let t=new Blob([e],{type:"text/javascript"}),n=URL.createObjectURL(t),o;try{o=await Vt(n)}catch(r){throw new j(`transform failed to load: ${r&&r.message?r.message:r}`,r)}finally{URL.revokeObjectURL(n)}if(typeof o.default!="function")throw new j("transform must `export default` a function");return o.default}function se(e,t){let n={carriedOver:0,discarded:0,listItems:0},o=be(t,e,n);return Se(t,e,n),{data:o,summary:n}}function be(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=>be(o,r,n))):void 0}if(typeof e=="object"&&e!==null){let o={};for(let[r,i]of Object.entries(e)){let s=be(i,t?.[r],n);s!==void 0&&(o[r]=s)}return o}}function Se(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)?Se(e[r],t[r],n):n.discarded+=$(t[r]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(r=>Se(o,r,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=$(t))}}function $(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+$(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+$(n),0):1}function nt(e,t,n){let o=re(e,t),r={carriedOver:0,discarded:0,listItems:0},i={},s=new Set;for(let{name:c,rules:l}of o){if(s.add(c),!Object.prototype.hasOwnProperty.call(n,c)){i[c]={carriedOver:0,discarded:0,listItems:0};continue}let{data:a,summary:d}=se(n[c],l);I(e,t,l,a),i[c]=d,r.carriedOver+=d.carriedOver,r.discarded+=d.discarded,r.listItems+=d.listItems}for(let c of Object.keys(n))s.has(c)||(r.discarded+=$(n[c]));return{totals:r,byName:i,rulesTagCount:o.length}}async function rt({sourceUrl:e,dataByName:t,fromVersion:n,doc:o,loc:r,fetchFn:i}={}){if(o=o||(typeof document<"u"?document:null),r=r||(typeof location<"u"?location:null),i=i||(u=>fetch(u)),!o)throw new Error("upgrade.run requires a document context");if(e=e||C(o,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let s=new URL(e,r?r.href:void 0);n=n!==void 0?n:C(o,"hyper-version"),t=t||Oe(R,o);let c;try{c=await i(s.href)}catch(u){throw new J(s.href,u)}if(!c.ok)throw new J(s.href,new Error(`HTTP ${c.status}`));let l=await c.text(),a=new DOMParser().parseFromString(l,"text/html"),d=C(a,"hyper-version"),y=t,p=!1,T=et(R,a);if(T){let m=await(await tt(T))(y,{fromVersion:n,toVersion:d});if(!m||typeof m!="object"||Array.isArray(m))throw new j("transform must return a plain object map of { rulesName: data }");y=m,p=!0}let{totals:f,byName:h,rulesTagCount:g}=nt(R,a,y);if(g===0&&Object.keys(y).length>0)throw new oe(s.href);return{html:Jt(a),fromVersion:n,toVersion:d,summary:{transformApplied:p,totals:f,byName:h}}}function Jt(e){return`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
2
- `+e.documentElement.outerHTML}var ot={checkForUpdate:Ze,run:rt,extractAll:Qe,shapeMatch:se};var Yt={engine:Ee,upgrade:ot},Xt=Yt;return ut(Gt);})();
1
+ var hyperHtmlApiUpgrade=(()=>{var fe=Object.defineProperty;var dt=Object.getOwnPropertyDescriptor;var pt=Object.getOwnPropertyNames;var ht=Object.prototype.hasOwnProperty;var Pe=(e,t)=>{for(var n in t)fe(e,n,{get:t[n],enumerable:!0})},mt=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of pt(t))!ht.call(e,r)&&r!==n&&fe(e,r,{get:()=>t[r],enumerable:!(o=dt(t,r))||o.enumerable});return e};var yt=e=>mt(fe({},"__esModule",{value:!0}),e);var ln={};Pe(ln,{default:()=>cn,engine:()=>Se,upgrade:()=>ut});var G=["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(G),ue=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),Q=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]),Me=new Set(["checked","selected","disabled","readOnly","paused"]);function ae(e,t){return t==null?Me.has(e)?!1:"":Me.has(e)?t==="false"?!1:!!t:t}var ne={};Pe(ne,{EmptyListInsert:()=>P,MAX_RULE_DEPTH:()=>D,MaxRuleDepthExceeded:()=>k,NoRulesTag:()=>de,RuleTargetReadOnly:()=>H,RulesParseError:()=>_,ShapeMismatch:()=>U,UnknownRulesVersion:()=>M,WriteNotRoundTripped:()=>te,WriteRefused:()=>ee,WriteRejected:()=>pe});var _=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},M=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},D=20,k=class extends Error{constructor(t){super(`rule depth exceeded ${D} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},U=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},P=class extends Error{constructor(t,n){super(n?`cannot add items to empty list at "${t.join(".")}" \u2014 ${n}`:`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}},H=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},ee=class extends Error{constructor(t){super(`write refused: ${t.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=t}};function gt(e){return e.reduce((n,o)=>typeof o=="number"?`${n}[${o}]`:n?`${n}.${o}`:String(o),"")||"(root)"}var te=class extends Error{constructor(t){super(`write did not round-trip at "${gt(t)}"`),this.name="WriteNotRoundTripped",this.path=t}},de=class extends Error{constructor(t){super(`no <script data-rules-name~="${t}"> rules tag in this document`),this.name="NoRulesTag",this.token=t}},pe=class extends Error{constructor(t,n){super(`write rejected: ${t.length} unknown key(s), ${n.length} rule(s) with no matching element`),this.name="WriteRejected",this.unknownKeys=t,this.unmatched=n}};function S(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 he(e){let t=S(e);return t===-1?{selector:e,prop:null}:{selector:e.slice(0,t),prop:e.slice(t+1)||null}}function me(e){let t=0,n=null,o=-1,r=!1;for(let i=0;i<e.length;i++){let s=e[i];s==="\\"?i++:n?s===n&&(n=null):s==='"'||s==="'"?n=s:s==="["||s==="("?t++:s==="]"||s===")"?t>0&&t--:t===0&&s===">"?o=i:t===0&&s===","&&(r=!0)}return r||o===-1||!At(e,o+1)?null:e.slice(0,o).trim()||null}function At(e,t){let n=t,o=e.replace(/\s+$/,"").length;for(;n<o&&/\s/.test(e[n]);)n++;let r=0,i=null;for(;n<o;n++){let s=e[n];if(s==="\\")n++;else if(i)s===i&&(i=null);else if(s==='"'||s==="'")i=s;else if(s==="["||s==="(")r++;else if(s==="]"||s===")")r>0&&r--;else if(r===0&&(s==="+"||s==="~"||/\s/.test(s)))return!1}return!0}var wt=/^--[A-Za-z0-9_-]+$/;function I(e){return typeof e=="string"&&wt.test(e)}function ke(e){let t=[],n=[],o=null,r=0;for(let i=0;i<e.length;i++){let s=e[i];if(o){s==="\\"?i++:s===o&&(o=null);continue}if(s==="/"&&e[i+1]==="*"){let c=e.indexOf("*/",i+2);i=c===-1?e.length:c+1;continue}s==='"'||s==="'"?o=s:s==="("?n.push(")"):s==="["?n.push("]"):s==="{"?n.push("}"):(s===")"||s==="]"||s==="}")&&n[n.length-1]===s?n.pop():s===";"&&n.length===0&&(t.push(e.slice(r,i)),r=i+1)}return t.push(e.slice(r)),t}function Tt(e){let t="",n=null;for(let o=0;o<e.length;o++){let r=e[o];if(n){t+=r,r==="\\"&&o+1<e.length?t+=e[++o]:r===n&&(n=null);continue}if(r==="/"&&e[o+1]==="*"){let i=e.indexOf("*/",o+2);o=i===-1?e.length:i+1,t+=" ";continue}(r==='"'||r==="'")&&(n=r),t+=r}return t}function Ie(e){e=Tt(e);let t=e.indexOf(":");if(t===-1)return null;let n=e.slice(0,t).trim(),o=e.slice(t+1).trim(),r=/!\s*important\s*$/i.exec(o);return r&&(o=o.slice(0,r.index).trim()),{name:n,value:o,important:!!r}}function q(e,t){if(e==null)return null;let n=null;for(let o of ke(String(e))){let r=Ie(o);!r||r.name!==t||(!n||r.important||!n.important)&&(n=r)}return n?n.value:null}function Le(e,t,n){let o=e==null?"":String(e),r=n==null||n==="",i=ke(o),s=i.map(Ie),c=s.some(h=>h&&h.name===t&&h.important),l=[],u=!1;i.forEach((h,m)=>{let T=s[m];if(!T||T.name!==t){l.push(h);return}if(r||u)return;let f=/^\s*/.exec(h)[0];l.push(`${f}${t}: ${n}${c?" !important":""}`),u=!0});let d=l.join(";");if(!r&&!u){let h=d.trimEnd();d=h===""?`${t}: ${n}`:`${h}${h.endsWith(";")?" ":"; "}${t}: ${n}`}return d.trim()===""?null:d}function ye(e,t,n,o){let r=e.attr(t,"style");if((q(r,n)??"")===o)return;let i=Le(r,n,o);i==null?e.removeAttr(t,"style"):e.attr(t,"style",i)}function N(e,t,n,o={}){if(Object.prototype.hasOwnProperty.call(o,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return ge(e,t,n,{depth:0,path:[]},o)}function ge(e,t,n,o,r){if(o.depth>D)throw new k(o.path);if(typeof n=="string")return xt(e,t,n,o,r);if(Array.isArray(n)){let[i,s]=n,c=e.find(t,i,r);return $e(r,o,c),c.map((l,u)=>ge(e,l,s,{depth:o.depth+1,path:[...o.path,u]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[s,c]of Object.entries(n))i[s]=ge(e,t,c,{depth:o.depth+1,path:[...o.path,s]},r);return i}return null}function xt(e,t,n,o,r){if(n.endsWith("[]")){let c=n.slice(0,-2),l=e.find(t,c,r);return $e(r,o,l),l.map(u=>e.text(u))}if(n.startsWith("@"))return je(e,t,n.slice(1));let i=S(n);if(i!==-1){let c=n.slice(0,i),l=n.slice(i+1),u=c?e.find(t,c,r):[t];return u.length===0?null:je(e,u[0],l)}if(n===".")return e.text(t);let s=e.find(t,n,r);return s.length===0?null:e.text(s[0])}function $e(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(o){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,o)}}function je(e,t,n){if(I(n))return q(e.attr(t,"style"),n);if(Z.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o??null}function ve(e,t,n,o){let r=e.length,i=t.length,s=new Array(r).fill(-1);if(o){let a=new Set;for(let y=0;y<r;y++){let A=o[y];!(A>=0&&A<i)||a.has(A)||(s[y]=A,a.add(A))}}if(r===0||i===0)return s;let c=e.map(a=>_e(a,n)),l=t.map(a=>_e(a,n)),u=new Array(i).fill(!1);for(let a of s)a>=0&&(u[a]=!0);let d=new Map;l.forEach((a,y)=>{u[y]||d.set(a,d.has(a)?-1:y)});let h=new Map;c.forEach((a,y)=>{s[y]>=0||h.set(a,(h.get(a)||0)+1)}),c.forEach((a,y)=>{if(s[y]>=0||h.get(a)!==1)return;let A=d.get(a);A===void 0||A===-1||u[A]||(s[y]=A,u[A]=!0)});let m=[];for(let a=0;a<r;a++)s[a]<0&&m.push(a);let T=[];for(let a=0;a<i;a++)u[a]||T.push(a);if(m.length===0||T.length===0)return s;let f=r*i+1,p=Ot(e,t,n),g=(a,y)=>p(a,y)*f+Math.abs(a-y);for(let[a,y]of Et(m,T,g))s[a]=y;return s}var We=e=>typeof e=="object"&&e!==null;function _e(e,t){if(!We(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(o=>{let r=JSON.stringify(e?.[o]);return r===void 0?" undef":r}))}function Ot(e,t,n){if(!We(n))return(c,l)=>e[c]===t[l]?0:1;let o=Object.keys(n),r=c=>o.map(l=>JSON.stringify(c?.[l])),i=e.map(r),s=t.map(r);return(c,l)=>{let u=i[c],d=s[l],h=0;for(let m=0;m<o.length;m++)u[m]!==d[m]&&h++;return h}}function Et(e,t,n){return e.length<=t.length?De(e,t,n,!1):De(t,e,(o,r)=>n(r,o),!0)}function De(e,t,n,o){let r=e.length,i=t.length,s=[];for(let h=0;h<=r;h++)s.push(new Float64Array(i+1).fill(1/0));let c=[];for(let h=0;h<=r;h++)c.push(new Uint8Array(i+1));for(let h=0;h<=i;h++)s[r][h]=0;for(let h=r-1;h>=0;h--)for(let m=i-1;m>=0;m--){let T=n(e[h],t[m])+s[h+1][m+1],f=s[h][m+1];T<=f?(s[h][m]=T,c[h][m]=1):s[h][m]=f}let l=[],u=0,d=0;for(;u<r&&d<i;)c[u][d]&&(l.push(o?[t[d],e[u]]:[e[u],t[d]]),u++),d++;return l}function we(e,t,n,o,r,i,s,c={}){let l=e.find(t,n,c);if(r.length===0){l.forEach(w=>e.remove(w)),Ae(c,"onRowsApplied",i.path,[]);return}let u=r.length>l.length,d=l[0]||null;if(u&&!d&&(d=Nt(e,t,n,c),!d))throw new P(i.path);let h=l.map(w=>Rt(e,w,o,c)),m=null;if(u&&d){m=e.clone(d),c.templateAttr&&e.removeAttr(m,c.templateAttr);let w=e.stripIds(m);w>0&&console.warn(`[hyper-html-api] stripped ${w} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let T=ve(r,h,o,bt(e,l,r,i,c)),f=l.length>0?e.parent(l[0]):kt(e,t,n,d,i,c),p=l.length>0?Be(e,f,l[0]):0,g=jt(e,l),a=new Set,y=[],A=r.map((w,b)=>{let O=T[b];if(O>=0)return a.add(O),y.push(!1),l[O];y.push(!0);let x=e.clone(m);return e.stripIds(x),x});l.forEach((w,b)=>{a.has(b)||e.remove(w)}),g?Lt(e,f,p,A,y):$t(e,A,y,f,p),St(e,A,o,r,i,s,c),Ae(c,"onRowsApplied",i.path,A)}function Ae(e,t,n,o){if(typeof e[t]=="function")try{return e[t](n.slice(),o)}catch(r){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,r);return}}function bt(e,t,n,o,r){let i=Ae(r,"identifyRows",o.path,n);if(!Array.isArray(i))return null;let s=new Array(n.length).fill(-1),c=new Set,l=new Map(t.map((u,d)=>[e.identity(u),d]));for(let u=0;u<n.length;u++){if(!i[u])continue;let d=l.get(e.identity(i[u]));d===void 0||c.has(d)||(s[u]=d,c.add(d))}return s}function St(e,t,n,o,r,i,s){t.forEach((c,l)=>{if(n===null){let u=o[l],d=u==null?"":String(u);e.text(c)!==d&&e.text(c,d)}else{let u=i(e,c,n,o[l],{depth:r.depth+1,path:[...r.path,l]},s);u&&u!==c&&(t[l]=u)}})}function Rt(e,t,n,o){return n===null?e.text(t):N(e,t,n,o.onRowsRead?{...o,onRowsRead:void 0}:o)}function Be(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 Nt(e,t,n,o){if(!o.templateAttr)return null;let r=/^\s*:scope\s*>\s*/.test(n),i=new RegExp(":not\\(\\["+o.templateAttr.replace(/[.*+?^${}()|[\]\\-]/g,"\\$&")+"\\]\\)","g"),s=n.replace(/^\s*:scope\s*>\s*/,"").replace(i,""),c=r?Ct(s):0,l=me(s),u=t;for(;u;){let d=e.find(u,s,{includeRulesTag:!1,templateAttr:null});for(let h of d)if(e.attr(h,o.templateAttr)!=null&&!(r&&!Mt(e,t,h,c))&&!(l&&!e.matches(e.parent(h),l)))return h;u=e.parent(u)}return null}function Ct(e){let t=0,n=null,o=1;for(let r=0;r<e.length;r++){let i=e[r];if(i==="\\")r++;else if(n)i===n&&(n=null);else if(i==='"'||i==="'")n=i;else if(i==="["||i==="(")t++;else if(i==="]"||i===")")t>0&&t--;else if(t===0&&i===">")o++;else{if(t===0&&(i==="+"||i==="~"))return null;if(t===0&&/\s/.test(i)){if(!Pt(e,r))return null;for(;r+1<e.length&&/\s/.test(e[r+1]);)r++}}}return o}function Pt(e,t){let n=t;for(;n<e.length&&/\s/.test(e[n]);)n++;let o=t>0?e[t-1]:"",r=n<e.length?e[n]:"";return Ue(o)||Ue(r)}function Ue(e){return e===">"||e==="+"||e==="~"}function Mt(e,t,n,o){if(o===null)return!0;let r=n;for(let l=0;l<o;l++)if(r=e.parent(r),!r)return!1;let i=e.prop(t,"tagName");if(!i)return!0;let s=e.prop(r,"tagName");if(!s||String(s).toLowerCase()!==String(i).toLowerCase())return!1;let c=new Set(He(e,r));return He(e,t).every(l=>c.has(l))}function He(e,t){let n=e.attr(t,"class");return n?String(n).split(/\s+/).filter(Boolean):[]}function kt(e,t,n,o,r,i){let s=e.parent(o);if(s&&It(e,t,s)&&!Ve(e,s,i))return s;let c=me(n);if(!c)throw new P(r.path,`the list selector "${n}" names no container to hold the new rows \u2014 write it as "container > row" (for example "ol.comments > li") so the cloned row lands in the list`);let u=(c===":scope"?e.prop(t,"tagName")?[t]:[]:e.find(t,c,i)).filter(d=>!Ve(e,d,i));if(u.length===0)throw new P(r.path,`no container matching "${c}" inside this context to hold the new rows`);if(u.length>1)throw new P(r.path,`"${c}" matches ${u.length} containers inside this context, so the new rows have no single destination`);return u[0]}function It(e,t,n){let o=n;for(;o;){if(e.sameNode(o,t))return!0;o=e.parent(o)}return e.parent(t)?!1:e.find(t,"*",{includeRulesTag:!0,templateAttr:null}).some(r=>e.sameNode(r,n))}var qe=["no-data","editor-ui"];function Ve(e,t,n){let o=t;for(;o;){if(n.templateAttr&&e.attr(o,n.templateAttr)!=null||qe.some(i=>e.attr(o,i)!=null))return!0;let r=e.attr(o,"clay");if(r&&r.split(/\s+/).some(i=>qe.includes(i)))return!0;o=e.parent(o)}return!1}function Lt(e,t,n,o,r){let i=e.children(t),s=i.map(l=>e.identity(l)),c=!1;o.forEach((l,u)=>{let d=e.identity(l),h=n+u;if(s[h]===d)return;if(!r[u]){let T=s.indexOf(d);T!==-1&&(s.splice(T,1),i.splice(T,1))}let m=Math.min(h,i.length);m<i.length?e.insertBefore(i[m],l):i.length?c?e.insertAfter(i[i.length-1],l):(e.insertAt(t,l,h),c=!0):e.insertAt(t,l,0),s.splice(m,0,d),i.splice(m,0,l)})}function jt(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let o=new Map(e.children(n).map((i,s)=>[e.identity(i),s])),r=[];for(let i of t){let s=o.get(e.identity(i));if(s===void 0)return!1;r.push(s)}return r.sort((i,s)=>i-s),r[r.length-1]-r[0]===r.length-1}function $t(e,t,n,o,r){let i=null,s=r;for(let c=0;c<t.length;c++){if(!n[c]){i=t[c];continue}let l=i?e.parent(i):o;if(!l)continue;let u=i?Be(e,l,i)+1:s++;e.insertAt(l,t[c],u),i=t[c]}}function L(e,t,n,o,r={}){if(Object.prototype.hasOwnProperty.call(r,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");let i=[];if(Te(n,o,[],i),i.length)throw new U(i);re(e,t,n,o,{depth:0,path:[]},r)}function re(e,t,n,o,r,i={}){if(r.depth>D)throw new k(r.path);if(o===void 0)return t;if(typeof n=="string")return _t(e,t,n,o,r,i);if(Array.isArray(n)){let[s,c]=n;return we(e,t,s,c,o,r,re,i),t}if(typeof n=="object"&&n!==null){for(let[s,c]of Object.entries(n)){let l=re(e,t,c,o==null?o:o[s],{depth:r.depth+1,path:[...r.path,s]},i);l&&l!==t&&(t=l)}return t}return t}function _t(e,t,n,o,r,i){if(n.endsWith("[]")){let l=n.slice(0,-2);return we(e,t,l,null,o,r,re,i),t}if(n.startsWith("@"))return Fe(e,t,n.slice(1),o);let s=S(n);if(s!==-1){let l=n.slice(0,s),u=n.slice(s+1),d=l?e.find(t,l,i):[t];return d.length===0||Fe(e,d[0],u,o),t}if(n===".")return ze(e,t,o),t;let c=e.find(t,n,i);return c.length===0||ze(e,c[0],o),t}function ze(e,t,n){let o=n==null?"":String(n);e.text(t)!==o&&e.text(t,o)}function Dt(e,t,n,o){if(e.styleVar){e.styleVar(t,n,o);return}ye(e,t,n,o)}function Fe(e,t,n,o){if(I(n))return Dt(e,t,n,o==null?"":String(o).trim()),t;if(Q.has(n)){let r=e.prop(t,n);if(r===o||r!=null&&o!=null&&String(r)===String(o))return t;throw new H(n)}if(n==="outerHTML"){let r=o==null?"":String(o);return e.replaceWith(t,r)}if(ue.has(n)){let r=ae(n,o);return e.prop(t,n)!==r&&e.prop(t,n,r),t}if(o==null)e.attr(t,n)!=null&&e.removeAttr(t,n);else{let r=String(o);e.attr(t,n)!==r&&e.attr(t,n,r)}return t}function Te(e,t,n,o){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((r,i)=>{typeof r=="object"&&r!==null&&o.push({path:B([...n,i]),expected:"scalar",got:V(r)})}):o.push({path:B(n),expected:"array",got:V(t)});return}t!==null&&typeof t=="object"&&o.push({path:B(n),expected:"scalar",got:V(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:B(n),expected:"array",got:V(t)});return}let r=e[1];t.forEach((i,s)=>Te(r,i,[...n,s],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:B(n),expected:"object",got:V(t)});return}for(let[r,i]of Object.entries(e))Te(i,t[r],[...n,r],o)}}}function V(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function B(e){return e.join(".")}function xe(e){try{return JSON.parse(e)}catch(t){throw new _(`Invalid strict JSON: ${t.message}`,t)}}function j(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=[],s=0;for(;s<r.length;){let c=r[s];if(/\s/.test(c)){s++;continue}if("{}".includes(c)){i.push({type:c,value:c}),s++;continue}if(c==="["){let h=!1,m=s+1;for(;m<r.length&&/\s/.test(r[m]);)m++;if(m<r.length&&/[a-zA-Z_]/.test(r[m])&&(h=!0),!h){i.push({type:c,value:c}),s++;continue}}if(c==="]"){i.push({type:c,value:c}),s++;continue}if(c===":"){i.push({type:t.COLON,value:c}),s++;continue}if(c===","){i.push({type:t.COMMA,value:c}),s++;continue}if(c==='"'||c==="'"){let h=c,m=s+1;for(;m<r.length&&r[m]!==h;)r[m]==="\\"&&m++,m++;i.push({type:t.STRING,value:r.substring(s+1,m),quoted:!0,sourceQuote:h}),s=m+1;continue}let l=s,u;for(;l<r.length&&!/[{},]/.test(r[l]);)if(r[l]===":"){let h=[":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 T of h){let f=T.substring(1);if(r.substring(l+1,l+1+f.length)===f){m=!0,l+=f.length;break}}if(!m)break}else if(r[l]==="["){for(l++;l<r.length&&r[l]!=="]";){if(r[l]==='"'||r[l]==="'"){let h=r[l];for(l++;l<r.length&&r[l]!==h;)r[l]==="\\"&&l++,l++}l++}l<r.length&&r[l]==="]"&&l++}else l++;u=r.substring(s,l);let d=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(u)?d=t.NUMBER:u==="true"||u==="false"||u==="null"?d=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(u)&&(d=t.SELECTOR),i.push({type:d,value:u,quoted:!1}),s=l}return i}function o(r){let i="";for(let s=0;s<r.length;s++){let c=r[s];if("{}".includes(c.type)||"[]".includes(c.type)){i+=c.value;continue}if(c.type===t.COLON){i+=c.value;continue}if(c.type===t.COMMA){let l=r[s+1];if(l&&(l.type==="}"||l.type==="]"))continue;i+=c.value;continue}if(c.type===t.STRING&&c.quoted){let l=c.value;c.sourceQuote==="'"&&(l=l.replace(/\\'/g,"'"),l=l.replace(/(\\*)"/g,(u,d)=>d.length%2===0?d+'\\"':u)),i+=`"${l}"`;continue}if(c.type===t.NUMBER||c.type===t.BOOLEAN){i+=c.value;continue}if(c.type===t.SELECTOR||c.type===t.IDENTIFIER){i+=`"${c.value}"`;continue}i+=`"${c.value}"`}return i}try{let r=n(e),i=o(r);return JSON.parse(i)}catch(r){throw new _("Invalid extraction rules syntax: "+r.message,r)}}var Oe="1",Ke=/^[a-zA-Z0-9_-]+$/;function z(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!Ke.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${Ke})`);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],s=e.attr(i,"data-rules-version");if(s!==Oe)throw new M(s);return{rules:j(e.text(i)),tagNode:i}}var oe=Object.freeze({data:Object.freeze({tokens:["no-data"],bundles:["editor-ui"]}),save:Object.freeze({tokens:["no-save"],bundles:["editor-ui"]}),snapshot:Object.freeze({tokens:["no-snapshot"],bundles:["editor-ui"]}),watch:Object.freeze({tokens:["no-watch"],bundles:["editor-ui"]}),undo:Object.freeze({tokens:["no-undo"],bundles:["editor-ui"]}),history:Object.freeze({tokens:[],bundles:["editor-ui"]})}),vt=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),Je=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui","live"]);function F(e,t){if(!e||e.nodeType!==1)return!1;let n=e.getAttribute?.("clay");return!!(n&&n.split(/\s+/).includes(t)||e.hasAttribute?.(t))}function Ee(e,t){if(F(e,t))return!0;for(let[n,o]of Object.entries(vt))if(o.includes(t)&&F(e,n))return!0;return!1}function K(e){let t=oe[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function Wt(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let o=oe[t];if(!o)throw new Error(`Unknown region capability: ${t}`);if(o.tokens.some(r=>Ee(n,r))||o.bundles.some(r=>F(n,r)))return n;n=n.parentElement}return null}function Ye(e,t){return!!Wt(e,t)}var Ut=Object.freeze({refusedRuleForms:["innerHTML","outerHTML"],refusedTargets:["script","style","template","noscript","iframe","object","embed","xmp","plaintext","noembed","noframes","meta","link","base","animate","set","animatemotion","animatetransform"],refusedAttributes:["style","srcdoc","is","http-equiv","sandbox","allow","nonce","integrity","charset","htmlclaytoken","htmlclayid","data-rules-name","data-rules-version","clay","contenteditable",...Je],refusedAttributePrefixes:["on"],urlAttributes:["href","src","srcset","action","formaction","poster","cite","data","ping","background","longdesc","usemap","xlink:href","manifest","codebase","icon"],refusedSchemes:["javascript","vbscript","data"],customPropertyValues:Object.freeze({maxLength:200,refusedCharacters:[";","{","}","<",">","\\"],refusedFunctions:["url","src","image","image-set","-webkit-image-set","cross-fade","element","expression","paint"]})});function be(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 z(e,o,n)}return null}var Bt=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function zt(e,t){if(!/^(INPUT|TEXTAREA|SELECT|OPTION)$/.test(e.tagName||""))return;let n=(e.getAttribute?.("type")||"").toLowerCase();"value"in e&&"value"in t&&e.tagName!=="OPTION"&&n!=="checkbox"&&n!=="radio"&&n!=="file"&&(t.value=e.value),e.tagName==="INPUT"&&(n==="checkbox"||n==="radio")&&(t.checked=e.checked),e.tagName==="OPTION"&&(t.selected=e.selected),"indeterminate"in e&&"indeterminate"in t&&(t.indeterminate=e.indeterminate)}function Xe(e,t,n,o){if(o)return!!e.closest?.(t);let r=e;for(;r?.nodeType===1;){if(r.matches(t))return!0;if(r===n)break;r=r.parentElement}return!1}function Ge(e,t,n,o,r,i){return(i?Ye(e,t):Xe(e,n,r,!1))||!!(o&&(i&&e!==r?e.matches(o):Xe(e,o,r,i)))}function Ft(e,t){let n=oe[t];return n.tokens.some(o=>Ee(e,o))||n.bundles.some(o=>F(e,o))}var Kt=new Set(["INPUT","TEXTAREA","SELECT","OPTION"]);function Ze(e,t,n,o){if(e.nodeType===1&&o(e)){n.dropped.push(t);return}n.cloneToLive.set(t,e),n.liveToClone.set(e,t);let r=e,i=t;if(e.nodeType===1){if(Kt.has(e.tagName)&&n.controls.push(e,t),e.tagName==="TEMPLATE"){for(;t.firstChild;)t.removeChild(t.firstChild);r=e.content,i=t.content,n.cloneToLive.set(i,r),n.liveToClone.set(r,i)}}else if(e.nodeType!==11)return;let s=i.firstChild;for(let c=r.firstChild;c&&s;c=c.nextSibling)Ze(c,s,n,o),s=s.nextSibling}function J(e,{capability:t="data",exclude:n=null,inherit:o=!0,provenance:r=null}={}){if(!e)throw new TypeError("createContentView requires a DOM context");let i=e.nodeType===9?e:e.ownerDocument;if(!i?.implementation?.createHTMLDocument)throw new TypeError("createContentView requires an HTML DOM implementation");let s=i.implementation.createHTMLDocument(""),c=r||new WeakMap,l=new WeakMap,u=e.nodeType===9?e.documentElement:e;n&&s.documentElement.matches(n);let d=K(t),h=o?f=>Ft(f,t)||!!(n&&f.matches(n)):f=>Ge(f,t,d,n,u,!1),m=null;if(u.nodeType!==1||!Ge(u,t,d,n,u,o)){m=s.importNode(u,!0);let f={cloneToLive:c,liveToClone:l,dropped:[],controls:[]};Ze(u,m,f,h);for(let p of f.dropped)p.remove();for(let p=0;p<f.controls.length;p+=2)zt(f.controls[p],f.controls[p+1])}e.nodeType===9&&m&&(s.replaceChild(m,s.documentElement),l.set(e,s),c.set(s,e));let T=f=>{if(Bt.test(f))throw new Error(`Filtered content queries do not support stateful selector: ${f}`)};return{root:m,document:s,capability:t,selector:K(t),cloneToLive:c,liveToClone:l,original(f){return c.get(f)||null},cloneOf(f){return l.get(f)||null},query(f,p=m){return T(f),Array.from(p.querySelectorAll(f),g=>c.get(g)||g)},text(f=m){return(f===m?m:l.get(f))?.textContent||""},html(f=m){return(f===m?m:l.get(f))?.innerHTML??""},clone(f=m){let p=f===m?m:l.get(f);return p?s.importNode(p,!0):null}}}function et(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function Jt(e){return e?(e.nodeType===9||e.nodeType===11,e):null}function Qe(e,t,n){!e||e.nodeType!==1||(t==="value"&&e.tagName==="INPUT"?e.value=n===null?"":n:t==="checked"&&e.tagName==="INPUT"?e.checked=n!==null:t==="selected"&&e.tagName==="OPTION"&&(e.selected=n!==null))}function tt(e,t){e&&e.tagName==="TEXTAREA"&&(e.value=t)}function nt(e){if(!e||e.nodeType!==1)return;let t=[e,...e.querySelectorAll?e.querySelectorAll("textarea, input, option"):[]];for(let n of t)if(n.tagName==="TEXTAREA")n.value=n.defaultValue;else if(n.tagName==="INPUT"){let o=n.type;o!=="file"&&o!=="checkbox"&&o!=="radio"&&(n.value=n.defaultValue),n.checked=n.defaultChecked}else n.tagName==="OPTION"&&(n.selected=n.defaultSelected)}var E={semanticExclude:!0,find(e,t,n={}){let o=Jt(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(c=>!et(c)));let i=[];n.skip&&i.push(n.skip);let s=n.templateAttr===null?null:n.templateAttr||"cms-template";if(s&&i.push("["+s+"]"),i.length){let c=i.join(", ");r=r.filter(l=>!l.closest||!l.closest(c))}return r},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},matches(e,t){return!!(e&&e.matches)&&e.matches(t)},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t,tt(e,t)},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n),Qe(e,t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t),Qe(e,t,null)},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){let t=e.cloneNode(!0);return nt(t),t},insertAt(e,t,n){let o=e.children[n]||null;e.insertBefore(t,o)},insertBefore(e,t){e.parentNode.insertBefore(t,e)},insertAfter(e,t){e.parentNode.insertBefore(t,e.nextSibling)},identity(e){return e||null},remove(e){e&&e.parentNode&&e.parentNode.removeChild(e)},replaceWith(e,t){if(!e||!e.parentNode)throw new Error("dom.replaceWith: node has no parent");let o=e.ownerDocument.createElement("template");o.innerHTML=t;let r=o.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(r,e),r},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(o=>{o.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};function Y(e,t={}){if(t.exclude===null)return E;let n=[K("data"),t.exclude].filter(Boolean).join(", "),o=e.nodeType===9?e:e.ownerDocument||e,r=e.nodeType===9?e.documentElement:e;if(!t._write&&!r?.matches?.(n)&&!r?.querySelector?.(n)&&!o?.querySelector?.(n))return E;let i=e.nodeType===9||!e.isConnected?e:e.ownerDocument,s=e.nodeType===9?e:e.ownerDocument,c=null,l=()=>c||(c=J(i,{capability:"data",exclude:t.exclude||null})),u=f=>{let p=l();return f===e?p.cloneOf(e):p.cloneOf(f)||f},d=f=>c?.original(f)||f,h=(f,p)=>{l().liveToClone.set(f,p),l().cloneToLive.set(p,f);let g=f.childNodes||[],a=p.childNodes||[];for(let y=0;y<Math.min(g.length,a.length);y++)h(g[y],a[y])},m=(f,p,g,a)=>{let y=Array.from(f.childNodes).filter(x=>c.cloneOf(x)),w=y[0];for(;w&&y.includes(w);)w=w.nextSibling;for(let x of y)x.remove();if(g==="innerHTML"){let x=s.createElement("template");x.innerHTML=a;for(let W of Array.from(x.content.childNodes))f.insertBefore(W,w||null)}else f.insertBefore(s.createTextNode(a),w||null),tt(f,a);let b=J(f,{capability:"data",exclude:t.exclude||null});p.replaceChildren(...Array.from(b.root?.childNodes||[]));let O=x=>{let W=b.original(x);W&&(c.liveToClone.set(W,x),c.cloneToLive.set(x,W));for(let at of Array.from(x.childNodes||[]))O(at)};for(let x of Array.from(p.childNodes))O(x)},T={...E,find(f,p,g={}){let a=u(f);if(!a?.querySelectorAll)return[];let y=l().query(p,a);g.includeRulesTag||(y=y.filter(b=>!et(b)));let A=[];g.skip&&A.push(g.skip);let w=g.templateAttr===null?null:g.templateAttr||"cms-template";if(w&&A.push(`[${w}]`),A.length){let b=A.join(", ");y=y.filter(O=>!O.closest?.(b))}return y},parent(f){let p=u(f)?.parentElement;return p?d(p):null},children(f){return Array.from(u(f)?.children||[],d)},text(f,p){if(p===void 0){let y=d(f);return!y?.matches?.(n)&&!y?.querySelector?.(n)?E.text(y):(u(f)?.textContent||"").trim()}let g=d(f);if(!g?.matches?.(n)&&!g?.querySelector?.(n)&&!c){E.text(g,p);return}let a=l().cloneOf(g);a?m(g,a,"textContent",p):E.text(g,p)},attr(f,p,g){let a=d(f);if(g===void 0)return E.attr(a,p);E.attr(a,p,g);let y=c?.cloneOf(a);y&&(E.attr(y,p,g),J(a,{capability:"data",exclude:t.exclude||null}).root===null&&(y.remove(),c.liveToClone.delete(a),c.cloneToLive.delete(y)))},removeAttr(f,p){let g=d(f);E.removeAttr(g,p);let a=c?.cloneOf(g);a&&E.removeAttr(a,p)},prop(f,p,g){let a=d(f);if(g===void 0)return p==="innerHTML"||p==="outerHTML"||p==="textContent"||p==="innerText"?E.prop(u(a),p):E.prop(a,p);let y=p==="innerHTML"||p==="textContent"||p==="innerText",A=y?l().cloneOf(a):c?.cloneOf(a);A&&y?m(a,A,p,g):(E.prop(a,p,g),A&&E.prop(A,p,g))},clone(f){let p=u(f);if(p===f)return E.clone(f);let g=s.importNode(p,!0);return nt(g),g},insertAt(f,p,g){let a=d(f),A=T.children(a)[g]||(()=>{for(let O=a.children.length-1;O>=0;O--){let x=a.children[O];if(l().cloneOf(x))return x.nextElementSibling}return a.firstElementChild})(),w=d(p);a.insertBefore(w,A||null);let b=l().cloneOf(a);if(b){let O=l().cloneOf(w);O||(O=s.importNode(w,!0),h(w,O));let x=Array.from(b.children);b.insertBefore(O,x[g]||null)}},insertBefore(f,p){let g=d(f),a=d(p);g.parentNode.insertBefore(a,g);let y=l().cloneOf(g.parentNode);if(y){let A=l().cloneOf(a);A||(A=s.importNode(a,!0),h(a,A));let w=l().cloneOf(g);w?w.before(A):y.appendChild(A)}},insertAfter(f,p){let g=d(f),a=d(p);g.parentNode.insertBefore(a,g.nextSibling);let y=l().cloneOf(g.parentNode);if(y){let A=l().cloneOf(a);A||(A=s.importNode(a,!0),h(a,A));let w=l().cloneOf(g);w?w.after(A):y.appendChild(A)}},identity(f){return d(f)||null},remove(f){let p=d(f),g=l().cloneOf(p);E.remove(p),g&&E.remove(g)},replaceWith(f,p){let g=d(f),a=l().cloneOf(g),y=E.replaceWith(g,p);if(a){let A=J(y,{capability:"data",exclude:t.exclude||null});if(!A.root)a.remove();else{a.replaceWith(A.root);let w=b=>{let O=A.original(b);O&&(c.liveToClone.set(O,b),c.cloneToLive.set(b,O));for(let x of Array.from(b.childNodes||[]))w(x)};w(A.root)}}return y}};return T}var R=E;var Se={extract:(e,t,n={})=>N(Y(e,n),e,t,n),apply:(e,t,n,o={})=>L(Y(e,{...o,_write:!0}),e,t,n,o),findRulesIn:(e,t)=>z(R,e,t),findRules:(e,t)=>be(R,e,t),bind:(e,t,n={})=>{let o=be(R,e,t);if(!o){let r=typeof t=="string"?`data-rules-name~="${t}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${r}`)}return{...o,get:()=>N(Y(e,n),e,o.rules,n),set:r=>L(Y(e,{...n,_write:!0}),e,o.rules,r,n)}},parseStrict:xe,parseRelaxed:j,ruleAttrIndex:S,splitRule:he,errors:ne,DOM_PROPERTIES:G};var Yt="hha:upgrade-check:";function C(e,t){let n=e.querySelector(`meta[name="${t}"]`),o=n?n.getAttribute("content"):null;return o&&o.trim()?o.trim():null}function rt(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function Xt(e,t){let n=rt(e),o=rt(t);if(!n||!o)return!1;let r=Math.max(n.length,o.length);for(let i=0;i<r;i++){let s=n[i]||0,c=o[i]||0;if(s!==c)return s>c}return!1}function Gt(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function Zt(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function ot({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 s=C(t,"hyper-source");if(!s)return null;let c=C(t,"hyper-version"),l;try{l=new URL(s,n?n.href:void 0)}catch{return null}if(n&&l.origin===n.origin&&l.pathname===n.pathname)return null;let u=`${Yt}${l.href}:${c||"none"}`,d,h=e?null:Gt(u);if(h&&typeof h.checkedAt=="number"&&r-h.checkedAt<i)d=h.sourceVersion;else{try{let m=await o(l.href);if(!m.ok)throw new Error(`HTTP ${m.status}`);let T=await m.text(),f=new DOMParser().parseFromString(T,"text/html");d=C(f,"hyper-version")}catch{d=null}Zt(u,{checkedAt:r,sourceVersion:d})}return d?{available:Xt(d,c||"0.0.0"),currentVersion:c,sourceVersion:d,sourceUrl:l.href}:null}var Qt="script[data-rules-name]";function en(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function ie(e,t){let n=e.find(t,Qt,{includeRulesTag:!0}),o=new Set,r=[];for(let i of n){let s=en(e.attr(i,"data-rules-name"));if(!s)continue;if(o.has(s)){console.warn(`hyper-html-api: duplicate rules tag name "${s}"; using the first.`);continue}let c=e.attr(i,"data-rules-version");if(c!==Oe)throw new M(c);o.add(s),r.push({name:s,rules:j(e.text(i))})}return r}function Re(e,t){let n={};for(let{name:o,rules:r}of ie(e,t))n[o]=N(e,t,r);return n}function it(e){let t=e||document,n=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:Re(R,t),version:C(n,"hyper-version")}}var X=class extends Error{constructor(t,n){super(`could not fetch upgrade source: ${t}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=t,this.cause=n}},se=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}},$=class extends Error{constructor(t,n){super(t),this.name="UpgradeTransformInvalid",this.cause=n}},ce=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 tn="text/hyper-upgrade";function st(e,t){let n=e.find(t,`script[type="${tn}"]`);if(n.length===0)return null;if(n.length>1)throw new ce(n.length);return e.text(n[0])||null}var nn=new Function("url","return import(url)");async function ct(e){let t=new Blob([e],{type:"text/javascript"}),n=URL.createObjectURL(t),o;try{o=await nn(n)}catch(r){throw new $(`transform failed to load: ${r&&r.message?r.message:r}`,r)}finally{URL.revokeObjectURL(n)}if(typeof o.default!="function")throw new $("transform must `export default` a function");return o.default}function le(e,t){let n={carriedOver:0,discarded:0,listItems:0},o=Ne(t,e,n);return Ce(t,e,n),{data:o,summary:n}}function Ne(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=>Ne(o,r,n))):void 0}if(typeof e=="object"&&e!==null){let o={};for(let[r,i]of Object.entries(e)){let s=Ne(i,t?.[r],n);s!==void 0&&(o[r]=s)}return o}}function Ce(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)?Ce(e[r],t[r],n):n.discarded+=v(t[r]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(r=>Ce(o,r,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=v(t))}}function v(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+v(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+v(n),0):1}function lt(e,t,n){let o=ie(e,t),r={carriedOver:0,discarded:0,listItems:0},i={},s=new Set;for(let{name:c,rules:l}of o){if(s.add(c),!Object.prototype.hasOwnProperty.call(n,c)){i[c]={carriedOver:0,discarded:0,listItems:0};continue}let{data:u,summary:d}=le(n[c],l);L(e,t,l,u),i[c]=d,r.carriedOver+=d.carriedOver,r.discarded+=d.discarded,r.listItems+=d.listItems}for(let c of Object.keys(n))s.has(c)||(r.discarded+=v(n[c]));return{totals:r,byName:i,rulesTagCount:o.length}}async function ft({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||(a=>fetch(a)),!o)throw new Error("upgrade.run requires a document context");if(e=e||C(o,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let s=new URL(e,r?r.href:void 0);n=n!==void 0?n:C(o,"hyper-version"),t=t||Re(R,o);let c;try{c=await i(s.href)}catch(a){throw new X(s.href,a)}if(!c.ok)throw new X(s.href,new Error(`HTTP ${c.status}`));let l=await c.text(),u=new DOMParser().parseFromString(l,"text/html"),d=C(u,"hyper-version"),h=t,m=!1,T=st(R,u);if(T){let y=await(await ct(T))(h,{fromVersion:n,toVersion:d});if(!y||typeof y!="object"||Array.isArray(y))throw new $("transform must return a plain object map of { rulesName: data }");h=y,m=!0}let{totals:f,byName:p,rulesTagCount:g}=lt(R,u,h);if(g===0&&Object.keys(h).length>0)throw new se(s.href);return{html:on(u),fromVersion:n,toVersion:d,summary:{transformApplied:m,totals:f,byName:p}}}function rn(e){for(let t of e.querySelectorAll("input")){let n=(t.getAttribute("type")||"").toLowerCase();n!=="file"&&(n==="checkbox"||n==="radio"?t.checked!==t.hasAttribute("checked")&&t.toggleAttribute("checked",t.checked):t.value!==(t.getAttribute("value")??"")&&t.setAttribute("value",t.value))}for(let t of e.querySelectorAll("textarea"))t.value!==t.textContent&&(t.textContent=t.value);for(let t of e.querySelectorAll("select")){let n=[...t.options];if(!t.multiple){let o=n.findIndex(r=>r.hasAttribute("selected"));if(t.selectedIndex===o||o===-1&&t.selectedIndex<=0)continue}for(let o of n)o.selected!==o.hasAttribute("selected")&&o.toggleAttribute("selected",o.selected)}}function on(e){return rn(e),`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
2
+ `+e.documentElement.outerHTML}var ut={checkForUpdate:ot,run:ft,extractAll:it,shapeMatch:le};var sn={engine:Se,upgrade:ut},cn=sn;return yt(ln);})();
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "apply",
10
10
  "CMS"
11
11
  ],
12
- "version": "0.11.3",
12
+ "version": "0.13.0",
13
13
  "homepage": "https://github.com/panphora/hyper-html-api",
14
14
  "bugs": {
15
15
  "url": "https://github.com/panphora/hyper-html-api/issues"
@@ -34,6 +34,7 @@
34
34
  "./dom": "./src/adapters/dom.js",
35
35
  "./data": "./src/data.js",
36
36
  "./upgrade": "./src/upgrade.js",
37
+ "./page": "./src/page.js",
37
38
  "./write": "./src/write.js"
38
39
  },
39
40
  "scripts": {
@@ -64,9 +65,10 @@
64
65
  "url": "git+https://github.com/panphora/hyper-html-api.git"
65
66
  },
66
67
  "dependencies": {
67
- "hyper-morph": "^1.6.3"
68
+ "hyper-morph": "^1.7.0"
68
69
  },
69
70
  "devDependencies": {
71
+ "@panphora/clayjs": "^1.13.1",
70
72
  "@web/test-runner": "^0.20.0",
71
73
  "@web/test-runner-playwright": "^0.11.0",
72
74
  "chai": "^4.3.6",
@@ -1 +1 @@
1
- {"load":["hyper-html-api","hyper-html-api/cheerio","hyper-html-api/cms","hyper-html-api/data","hyper-html-api/dom","hyper-html-api/engine","hyper-html-api/upgrade","hyper-html-api/write"]}
1
+ {"load":["hyper-html-api","hyper-html-api/cheerio","hyper-html-api/cms","hyper-html-api/data","hyper-html-api/dom","hyper-html-api/engine","hyper-html-api/page","hyper-html-api/upgrade","hyper-html-api/write"]}
@@ -11,6 +11,7 @@ import {
11
11
  } from './errors.js'
12
12
  import { listDiff } from './diff.js'
13
13
  import { ruleAttrIndex } from './rule-syntax.js'
14
+ import { isCustomPropertyName, setStyleVar } from './style-vars.js'
14
15
 
15
16
  export function apply(adapter, root, rules, data, opts = {}) {
16
17
  if (Object.prototype.hasOwnProperty.call(opts, 'exclude') && adapter.semanticExclude === false) {
@@ -100,10 +101,25 @@ function writeText(adapter, node, value) {
100
101
  if (adapter.text(node) !== target) adapter.text(node, target)
101
102
  }
102
103
 
104
+ // One custom property in the style attribute. A guarded adapter takes it
105
+ // through styleVar(), so its policy sees the property name and the value,
106
+ // never a whole style string it would have to diff.
107
+ function writeCustomProperty(adapter, node, name, want) {
108
+ if (adapter.styleVar) {
109
+ adapter.styleVar(node, name, want)
110
+ return
111
+ }
112
+ setStyleVar(adapter, node, name, want)
113
+ }
114
+
103
115
  // Returns the (possibly new) node. For outerHTML, the original is detached
104
116
  // and a freshly parsed element takes its place; that new node is returned.
105
117
  // For every other write, returns the original node unchanged.
106
118
  function writePropOrAttr(adapter, node, name, value) {
119
+ if (isCustomPropertyName(name)) {
120
+ writeCustomProperty(adapter, node, name, value == null ? '' : String(value).trim())
121
+ return node
122
+ }
107
123
  if (DOM_PROPERTIES_READ_ONLY_SET.has(name)) {
108
124
  const current = adapter.prop(node, name)
109
125
  if (current === value || (current != null && value != null && String(current) === String(value))) return node
@@ -1,6 +1,7 @@
1
1
  import { DOM_PROPERTIES_SET } from './dom-properties.js'
2
2
  import { MaxRuleDepthExceeded, MAX_RULE_DEPTH } from './errors.js'
3
3
  import { ruleAttrIndex } from './rule-syntax.js'
4
+ import { isCustomPropertyName, readStyleVar } from './style-vars.js'
4
5
 
5
6
  export function extract(adapter, root, rules, opts = {}) {
6
7
  if (Object.prototype.hasOwnProperty.call(opts, 'exclude') && adapter.semanticExclude === false) {
@@ -88,6 +89,7 @@ function reportRows(opts, trace, nodes) {
88
89
  }
89
90
 
90
91
  function readPropOrAttr(adapter, node, name) {
92
+ if (isCustomPropertyName(name)) return readStyleVar(adapter.attr(node, 'style'), name)
91
93
  if (DOM_PROPERTIES_SET.has(name)) {
92
94
  const v = adapter.prop(node, name)
93
95
  return v == null ? null : String(v)
@@ -9,8 +9,9 @@ export { parseStrict, parseRelaxed } from './rules.js'
9
9
  export { ruleAttrIndex, splitRule } from './rule-syntax.js'
10
10
  export * as errors from './errors.js'
11
11
  export { DOM_PROPERTIES, DOM_PROPERTIES_SET, DOM_PROPERTIES_READ_ONLY_SET } from './dom-properties.js'
12
- export { WRITE_POLICY, guardAdapter, checkAttribute, urlScheme } from './write-policy.js'
12
+ export { WRITE_POLICY, guardAdapter, checkAttribute, checkCustomPropertyValue, urlScheme } from './write-policy.js'
13
13
  export { planWrite } from './write-plan.js'
14
+ export { isCustomPropertyName, readStyleVar, writeStyleVar } from './style-vars.js'
14
15
  export { assertRoundTrip } from './round-trip.js'
15
16
  export { trackAdapter, spliceDocument } from './splice.js'
16
17
 
@@ -5,6 +5,7 @@ import {
5
5
  } from './dom-properties.js'
6
6
  import { WriteNotRoundTripped } from './errors.js'
7
7
  import { ruleAttrIndex } from './rule-syntax.js'
8
+ import { isCustomPropertyName } from './style-vars.js'
8
9
 
9
10
  // Props whose read-side value keeps its whitespace. Every other text rule reads
10
11
  // trimmed, which is what writeText compares against.
@@ -75,6 +76,10 @@ function checkList(shape, want, got, path) {
75
76
  }
76
77
 
77
78
  function checkPropOrAttr(name, want, got, path) {
79
+ if (isCustomPropertyName(name)) {
80
+ if ((want == null ? '' : String(want).trim()) !== (got ?? '')) fail(path)
81
+ return
82
+ }
78
83
  if (!DOM_PROPERTIES_SET.has(name)) {
79
84
  if (want == null) {
80
85
  if (got != null) fail(path)
@@ -0,0 +1,141 @@
1
+ // One CSS custom property inside an inline style attribute, read and written
2
+ // as text. Not through CSSOM: the cheerio adapter has none, and both adapters
3
+ // must return the same string for the same attribute.
4
+
5
+ const CUSTOM_PROPERTY = /^--[A-Za-z0-9_-]+$/
6
+
7
+ export function isCustomPropertyName(name) {
8
+ return typeof name === 'string' && CUSTOM_PROPERTY.test(name)
9
+ }
10
+
11
+ // Split on top-level semicolons, ignoring any inside quotes, brackets or
12
+ // comments, so url("a;b") or a comment never cuts a declaration in half.
13
+ // Brackets close only their own kind, as in CSS.
14
+ function splitDeclarations(text) {
15
+ const parts = []
16
+ const stack = []
17
+ let quote = null
18
+ let start = 0
19
+ for (let i = 0; i < text.length; i++) {
20
+ const c = text[i]
21
+ if (quote) {
22
+ if (c === '\\') i++
23
+ else if (c === quote) quote = null
24
+ continue
25
+ }
26
+ if (c === '/' && text[i + 1] === '*') {
27
+ const end = text.indexOf('*/', i + 2)
28
+ i = end === -1 ? text.length : end + 1
29
+ continue
30
+ }
31
+ if (c === '"' || c === "'") quote = c
32
+ else if (c === '(') stack.push(')')
33
+ else if (c === '[') stack.push(']')
34
+ else if (c === '{') stack.push('}')
35
+ else if ((c === ')' || c === ']' || c === '}') && stack[stack.length - 1] === c) stack.pop()
36
+ else if (c === ';' && stack.length === 0) {
37
+ parts.push(text.slice(start, i))
38
+ start = i + 1
39
+ }
40
+ }
41
+ parts.push(text.slice(start))
42
+ return parts
43
+ }
44
+
45
+ // The declaration with its comments removed. Quotes are respected, so a
46
+ // comment-like run inside a string stays.
47
+ function stripComments(text) {
48
+ let out = ''
49
+ let quote = null
50
+ for (let i = 0; i < text.length; i++) {
51
+ const c = text[i]
52
+ if (quote) {
53
+ out += c
54
+ if (c === '\\' && i + 1 < text.length) out += text[++i]
55
+ else if (c === quote) quote = null
56
+ continue
57
+ }
58
+ if (c === '/' && text[i + 1] === '*') {
59
+ const end = text.indexOf('*/', i + 2)
60
+ i = end === -1 ? text.length : end + 1
61
+ out += ' '
62
+ continue
63
+ }
64
+ if (c === '"' || c === "'") quote = c
65
+ out += c
66
+ }
67
+ return out
68
+ }
69
+
70
+ function parseDeclaration(raw) {
71
+ raw = stripComments(raw)
72
+ const colon = raw.indexOf(':')
73
+ if (colon === -1) return null
74
+ const name = raw.slice(0, colon).trim()
75
+ let value = raw.slice(colon + 1).trim()
76
+ const bang = /!\s*important\s*$/i.exec(value)
77
+ if (bang) value = value.slice(0, bang.index).trim()
78
+ return { name, value, important: !!bang }
79
+ }
80
+
81
+ // The declaration that wins: the last one, unless an earlier one is
82
+ // !important and the last one is not. Absent reads as null.
83
+ export function readStyleVar(styleText, name) {
84
+ if (styleText == null) return null
85
+ let winner = null
86
+ for (const raw of splitDeclarations(String(styleText))) {
87
+ const decl = parseDeclaration(raw)
88
+ if (!decl || decl.name !== name) continue
89
+ if (!winner || decl.important || !winner.important) winner = decl
90
+ }
91
+ return winner ? winner.value : null
92
+ }
93
+
94
+ // Returns the new attribute text, or null when nothing is left in it. An empty
95
+ // or null value removes every declaration of the property. Otherwise the first
96
+ // declaration is rewritten in place (keeping !important if any copy had it),
97
+ // later duplicates are dropped, and a property not yet present is appended.
98
+ export function writeStyleVar(styleText, name, value) {
99
+ const text = styleText == null ? '' : String(styleText)
100
+ const remove = value == null || value === ''
101
+ const parts = splitDeclarations(text)
102
+ const decls = parts.map(parseDeclaration)
103
+ const important = decls.some((d) => d && d.name === name && d.important)
104
+ const out = []
105
+ let placed = false
106
+ parts.forEach((raw, i) => {
107
+ const decl = decls[i]
108
+ if (!decl || decl.name !== name) {
109
+ out.push(raw)
110
+ return
111
+ }
112
+ if (remove || placed) return
113
+ const lead = /^\s*/.exec(raw)[0]
114
+ out.push(`${lead}${name}: ${value}${important ? ' !important' : ''}`)
115
+ placed = true
116
+ })
117
+ let next = out.join(';')
118
+ if (!remove && !placed) {
119
+ const body = next.trimEnd()
120
+ next = body === '' ? `${name}: ${value}` : `${body}${body.endsWith(';') ? ' ' : '; '}${name}: ${value}`
121
+ }
122
+ return next.trim() === '' ? null : next
123
+ }
124
+
125
+ // Writes one custom property through an adapter, touching nothing when the
126
+ // value is already there. An empty value removes the property, and the style
127
+ // attribute with it once nothing is left.
128
+ export function setStyleVar(adapter, node, name, want) {
129
+ const current = adapter.attr(node, 'style')
130
+ if ((readStyleVar(current, name) ?? '') === want) return
131
+ const next = writeStyleVar(current, name, want)
132
+ if (next == null) adapter.removeAttr(node, 'style')
133
+ else adapter.attr(node, 'style', next)
134
+ }
135
+
136
+ // Every declaration in the attribute, in order, parsed. Empty segments (a
137
+ // trailing semicolon, stray whitespace) are dropped.
138
+ export function listDeclarations(styleText) {
139
+ if (styleText == null) return []
140
+ return splitDeclarations(String(styleText)).map(parseDeclaration).filter(Boolean)
141
+ }
@@ -1,5 +1,6 @@
1
1
  import { POLICY_TOKENS } from '../lib/region-capabilities.js'
2
2
  import { WriteRefused } from './errors.js'
3
+ import { isCustomPropertyName, readStyleVar, setStyleVar } from './style-vars.js'
3
4
 
4
5
  export const WRITE_POLICY = Object.freeze({
5
6
  refusedRuleForms: ['innerHTML', 'outerHTML'],
@@ -12,6 +13,11 @@ export const WRITE_POLICY = Object.freeze({
12
13
  refusedAttributePrefixes: ['on'],
13
14
  urlAttributes: ['href', 'src', 'srcset', 'action', 'formaction', 'poster', 'cite', 'data', 'ping', 'background', 'longdesc', 'usemap', 'xlink:href', 'manifest', 'codebase', 'icon'],
14
15
  refusedSchemes: ['javascript', 'vbscript', 'data'],
16
+ customPropertyValues: Object.freeze({
17
+ maxLength: 200,
18
+ refusedCharacters: [';', '{', '}', '<', '>', '\\'],
19
+ refusedFunctions: ['url', 'src', 'image', 'image-set', '-webkit-image-set', 'cross-fade', 'element', 'expression', 'paint'],
20
+ }),
15
21
  })
16
22
 
17
23
  const TEXT_PROPS = new Set(['textContent', 'innerText'])
@@ -71,6 +77,48 @@ function isOrHoldsRulesTag(adapter, node) {
71
77
  return holdsRulesTag(adapter, node)
72
78
  }
73
79
 
80
+ // Every quote closed, every bracket closed by its own kind, no comment and no
81
+ // control character. A value that fails this would swallow the declarations
82
+ // after it in the style attribute.
83
+ function unbalancedReason(text) {
84
+ if (/[\u0000-\u001f\u007f]/.test(text)) return 'control characters are not allowed in a custom property value'
85
+ const stack = []
86
+ let quote = null
87
+ for (let i = 0; i < text.length; i++) {
88
+ const c = text[i]
89
+ if (quote) {
90
+ if (c === quote) quote = null
91
+ continue
92
+ }
93
+ if (c === '"' || c === "'") quote = c
94
+ else if (c === '/' && text[i + 1] === '*') return 'comments are not allowed in a custom property value'
95
+ else if (c === '(') stack.push(')')
96
+ else if (c === '[') stack.push(']')
97
+ else if (c === ')' || c === ']') {
98
+ if (stack.pop() !== c) return `"${c}" does not close anything in this custom property value`
99
+ }
100
+ }
101
+ if (quote) return 'a custom property value must close its quotes'
102
+ if (stack.length) return 'a custom property value must close its brackets'
103
+ return null
104
+ }
105
+
106
+ // A custom property value that cannot load anything, close its declaration, or
107
+ // carry markup. Colors, font stacks, lengths and keywords all pass.
108
+ export function checkCustomPropertyValue(value, policy = WRITE_POLICY) {
109
+ const rules = policy.customPropertyValues
110
+ const text = String(value)
111
+ if (text.length > rules.maxLength) return `custom property values are limited to ${rules.maxLength} characters`
112
+ const ch = rules.refusedCharacters.find((c) => text.includes(c))
113
+ if (ch) return `${JSON.stringify(ch)} is not allowed in a custom property value`
114
+ const unbalanced = unbalancedReason(text)
115
+ if (unbalanced) return unbalanced
116
+ const lower = text.toLowerCase()
117
+ const fn = rules.refusedFunctions.find((f) => new RegExp(`(^|[^a-z0-9_-])${f.replace(/[-]/g, '\\-')}\\s*\\(`).test(lower))
118
+ if (fn) return `"${fn}()" is not allowed in a custom property value`
119
+ return null
120
+ }
121
+
74
122
  // Wraps an adapter so every write is checked against the policy first. A write
75
123
  // that breaks it is skipped and recorded; call assertClean() after apply() to
76
124
  // throw one WriteRefused listing every violation.
@@ -108,6 +156,18 @@ export function guardAdapter(adapter, policy = WRITE_POLICY) {
108
156
  removeAttr(node, name) {
109
157
  if (allowAttr(node, name, null)) adapter.removeAttr(node, name)
110
158
  },
159
+ // The engine's @--name write: one custom property, checked by name and
160
+ // value. Every other declaration in the attribute is left as it is.
161
+ styleVar(node, name, value) {
162
+ if ((readStyleVar(adapter.attr(node, 'style'), name) ?? '') === value) return
163
+ if (!allowTarget(node)) return
164
+ if (!isCustomPropertyName(name)) return refuse(node, `"${name}" is not a custom property`)
165
+ if (value !== '') {
166
+ const reason = checkCustomPropertyValue(value, policy)
167
+ if (reason) return refuse(node, reason)
168
+ }
169
+ setStyleVar(adapter, node, name, value)
170
+ },
111
171
  prop(node, name, value) {
112
172
  if (value === undefined) return adapter.prop(node, name)
113
173
  if (policy.refusedRuleForms.includes(name)) return refuse(node, `"@${name}" writes HTML, only text is allowed`)