hyper-html-api 0.12.0 → 0.14.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 (83) hide show
  1. package/README.md +4 -1
  2. package/conformance/MANIFEST.json +2 -2
  3. package/conformance/cases/all-matches-read-quoted.expected.json +3 -0
  4. package/conformance/cases/all-matches-read-quoted.html +5 -0
  5. package/conformance/cases/all-matches-read-quoted.meta +7 -0
  6. package/conformance/cases/all-matches-read-quoted.parsed.json +3 -0
  7. package/conformance/cases/all-matches-read.expected.json +3 -0
  8. package/conformance/cases/all-matches-read.html +6 -0
  9. package/conformance/cases/all-matches-read.meta +7 -0
  10. package/conformance/cases/all-matches-read.parsed.json +3 -0
  11. package/conformance/cases/stylevar-read.expected.json +12 -0
  12. package/conformance/cases/stylevar-read.html +7 -0
  13. package/conformance/cases/stylevar-read.meta +6 -0
  14. package/conformance/cases/stylevar-read.parsed.json +12 -0
  15. package/conformance/cases/stylevar-read.rules +1 -0
  16. package/conformance/cases/write-all-matches-attr.after.html +1 -0
  17. package/conformance/cases/write-all-matches-attr.after.json +3 -0
  18. package/conformance/cases/write-all-matches-attr.data.json +1 -0
  19. package/conformance/cases/write-all-matches-attr.html +1 -0
  20. package/conformance/cases/write-all-matches-attr.meta +6 -0
  21. package/conformance/cases/write-all-matches-attr.write.json +4 -0
  22. package/conformance/cases/write-all-matches-group.after.html +1 -0
  23. package/conformance/cases/write-all-matches-group.after.json +3 -0
  24. package/conformance/cases/write-all-matches-group.data.json +1 -0
  25. package/conformance/cases/write-all-matches-group.html +1 -0
  26. package/conformance/cases/write-all-matches-group.meta +6 -0
  27. package/conformance/cases/write-all-matches-group.write.json +4 -0
  28. package/conformance/cases/write-all-matches-text.after.html +1 -0
  29. package/conformance/cases/write-all-matches-text.after.json +3 -0
  30. package/conformance/cases/write-all-matches-text.data.json +1 -0
  31. package/conformance/cases/write-all-matches-text.html +1 -0
  32. package/conformance/cases/write-all-matches-text.meta +6 -0
  33. package/conformance/cases/write-all-matches-text.write.json +4 -0
  34. package/conformance/cases/write-all-matches-unmatched.data.json +1 -0
  35. package/conformance/cases/write-all-matches-unmatched.error.json +14 -0
  36. package/conformance/cases/write-all-matches-unmatched.html +1 -0
  37. package/conformance/cases/write-all-matches-unmatched.meta +6 -0
  38. package/conformance/cases/write-refused-raw-style.data.json +1 -0
  39. package/conformance/cases/write-refused-raw-style.error.json +11 -0
  40. package/conformance/cases/write-refused-raw-style.html +1 -0
  41. package/conformance/cases/write-refused-raw-style.meta +4 -0
  42. package/conformance/cases/write-refused-stylevar-values.data.json +1 -0
  43. package/conformance/cases/write-refused-stylevar-values.error.json +43 -0
  44. package/conformance/cases/write-refused-stylevar-values.html +1 -0
  45. package/conformance/cases/write-refused-stylevar-values.meta +5 -0
  46. package/conformance/cases/write-stylevar-clear.after.html +1 -0
  47. package/conformance/cases/write-stylevar-clear.after.json +4 -0
  48. package/conformance/cases/write-stylevar-clear.data.json +1 -0
  49. package/conformance/cases/write-stylevar-clear.html +1 -0
  50. package/conformance/cases/write-stylevar-clear.meta +5 -0
  51. package/conformance/cases/write-stylevar-clear.write.json +4 -0
  52. package/conformance/cases/write-stylevar-set.after.html +2 -0
  53. package/conformance/cases/write-stylevar-set.after.json +5 -0
  54. package/conformance/cases/write-stylevar-set.data.json +1 -0
  55. package/conformance/cases/write-stylevar-set.html +1 -0
  56. package/conformance/cases/write-stylevar-set.meta +6 -0
  57. package/conformance/cases/write-stylevar-set.write.json +4 -0
  58. package/conformance/cases/write-stylevar-unchanged.after.html +1 -0
  59. package/conformance/cases/write-stylevar-unchanged.after.json +3 -0
  60. package/conformance/cases/write-stylevar-unchanged.data.json +1 -0
  61. package/conformance/cases/write-stylevar-unchanged.html +1 -0
  62. package/conformance/cases/write-stylevar-unchanged.meta +5 -0
  63. package/conformance/cases/write-stylevar-unchanged.write.json +4 -0
  64. package/conformance/write-policy.json +23 -1
  65. package/dist/hyper-html-api.engine.esm.js +1 -1
  66. package/dist/hyper-html-api.engine.min.js +1 -1
  67. package/dist/hyper-html-api.min.js +8 -8
  68. package/dist/hyper-html-api.upgrade.min.js +2 -2
  69. package/package.json +4 -3
  70. package/src/engine/apply.js +22 -7
  71. package/src/engine/extract.js +8 -3
  72. package/src/engine/index.js +2 -1
  73. package/src/engine/round-trip.js +14 -1
  74. package/src/engine/rule-syntax.js +13 -3
  75. package/src/engine/style-vars.js +141 -0
  76. package/src/engine/write-plan.js +2 -3
  77. package/src/engine/write-policy.js +60 -0
  78. package/src/page.js +15 -5
  79. package/src/site.js +164 -0
  80. package/src/upgrade/migrate.js +2 -1
  81. package/src/upgrade/run.js +30 -0
  82. package/src/upgrade/shape-match.js +32 -13
  83. package/src/write.js +1 -1
@@ -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 ue=Object.defineProperty;var pt=Object.getOwnPropertyDescriptor;var ht=Object.getOwnPropertyNames;var mt=Object.prototype.hasOwnProperty;var Pe=(e,t)=>{for(var n in t)ue(e,n,{get:t[n],enumerable:!0})},yt=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ht(t))!mt.call(e,r)&&r!==n&&ue(e,r,{get:()=>t[r],enumerable:!(o=pt(t,r))||o.enumerable});return e};var gt=e=>yt(ue({},"__esModule",{value:!0}),e);var un={};Pe(un,{default:()=>fn,engine:()=>Re,upgrade:()=>at});var Q=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],ee=new Set(Q),ae=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),D=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]),ke=new Set(["checked","selected","disabled","readOnly","paused"]);function de(e,t){return t==null?ke.has(e)?!1:"":ke.has(e)?t==="false"?!1:!!t:t}var re={};Pe(re,{EmptyListInsert:()=>P,MAX_RULE_DEPTH:()=>W,MaxRuleDepthExceeded:()=>I,NoRulesTag:()=>pe,RuleTargetReadOnly:()=>V,RulesParseError:()=>v,ShapeMismatch:()=>q,UnknownRulesVersion:()=>k,WriteNotRoundTripped:()=>ne,WriteRefused:()=>te,WriteRejected:()=>he});var v=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},k=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},W=20,I=class extends Error{constructor(t){super(`rule depth exceeded ${W} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},q=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}},V=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},te=class extends Error{constructor(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 ne=class extends Error{constructor(t){super(`write did not round-trip at "${At(t)}"`),this.name="WriteNotRoundTripped",this.path=t}},pe=class extends Error{constructor(t){super(`no <script data-rules-name~="${t}"> rules tag in this document`),this.name="NoRulesTag",this.token=t}},he=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}var Ie="[*]";function R(e){let t=S(e),n=t===-1?e:e.slice(0,t),o=n.endsWith(Ie),r={selector:o?n.slice(0,-Ie.length):n,prop:t===-1?null:e.slice(t+1)||null};return o&&(r.all=!0),r}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||!wt(e,o+1)?null:e.slice(0,o).trim()||null}function wt(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 Tt=/^--[A-Za-z0-9_-]+$/;function L(e){return typeof e=="string"&&Tt.test(e)}function Le(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 xt(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 je(e){e=xt(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 B(e,t){if(e==null)return null;let n=null;for(let o of Le(String(e))){let r=je(o);!r||r.name!==t||(!n||r.important||!n.important)&&(n=r)}return n?n.value:null}function $e(e,t,n){let o=e==null?"":String(e),r=n==null||n==="",i=Le(o),s=i.map(je),c=s.some(p=>p&&p.name===t&&p.important),l=[],a=!1;i.forEach((p,h)=>{let T=s[h];if(!T||T.name!==t){l.push(p);return}if(r||a)return;let f=/^\s*/.exec(p)[0];l.push(`${f}${t}: ${n}${c?" !important":""}`),a=!0});let u=l.join(";");if(!r&&!a){let p=u.trimEnd();u=p===""?`${t}: ${n}`:`${p}${p.endsWith(";")?" ":"; "}${t}: ${n}`}return u.trim()===""?null:u}function ye(e,t,n,o){let r=e.attr(t,"style");if((B(r,n)??"")===o)return;let i=$e(r,n,o);i==null?e.removeAttr(t,"style"):e.attr(t,"style",i)}function C(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 Ae(e,t,n,{depth:0,path:[]},o)}function Ae(e,t,n,o,r){if(o.depth>W)throw new I(o.path);if(typeof n=="string")return Ot(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,a)=>Ae(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]=Ae(e,t,c,{depth:o.depth+1,path:[...o.path,s]},r);return i}return null}function Ot(e,t,n,o,r){if(n.endsWith("[]")){let a=n.slice(0,-2),u=e.find(t,a,r);return _e(r,o,u),u.map(p=>e.text(p))}if(n.startsWith("@"))return ge(e,t,n.slice(1));let i=S(n);if(i!==-1){let{selector:a,all:u}=R(n),p=n.slice(i+1),h=a?e.find(t,a,r):[t];return u&&r.allMatches?h.map(T=>ge(e,T,p)):h.length===0?null:ge(e,h[0],p)}if(n===".")return e.text(t);let{selector:s,all:c}=R(n),l=e.find(t,s,r);return c&&r.allMatches?l.map(a=>e.text(a)):l.length===0?null:e.text(l[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 ge(e,t,n){if(L(n))return B(e.attr(t,"style"),n);if(ee.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o??null}function We(e,t,n,o){let r=e.length,i=t.length,s=new Array(r).fill(-1);if(o){let d=new Set;for(let y=0;y<r;y++){let A=o[y];!(A>=0&&A<i)||d.has(A)||(s[y]=A,d.add(A))}}if(r===0||i===0)return s;let c=e.map(d=>De(d,n)),l=t.map(d=>De(d,n)),a=new Array(i).fill(!1);for(let d of s)d>=0&&(a[d]=!0);let u=new Map;l.forEach((d,y)=>{a[y]||u.set(d,u.has(d)?-1:y)});let p=new Map;c.forEach((d,y)=>{s[y]>=0||p.set(d,(p.get(d)||0)+1)}),c.forEach((d,y)=>{if(s[y]>=0||p.get(d)!==1)return;let A=u.get(d);A===void 0||A===-1||a[A]||(s[y]=A,a[A]=!0)});let h=[];for(let d=0;d<r;d++)s[d]<0&&h.push(d);let T=[];for(let d=0;d<i;d++)a[d]||T.push(d);if(h.length===0||T.length===0)return s;let f=r*i+1,m=Et(e,t,n),g=(d,y)=>m(d,y)*f+Math.abs(d-y);for(let[d,y]of bt(h,T,g))s[d]=y;return s}var Ue=e=>typeof e=="object"&&e!==null;function De(e,t){if(!Ue(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 Et(e,t,n){if(!Ue(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],u=s[l],p=0;for(let h=0;h<o.length;h++)a[h]!==u[h]&&p++;return p}}function bt(e,t,n){return e.length<=t.length?ve(e,t,n,!1):ve(t,e,(o,r)=>n(r,o),!0)}function ve(e,t,n,o){let r=e.length,i=t.length,s=[];for(let p=0;p<=r;p++)s.push(new Float64Array(i+1).fill(1/0));let c=[];for(let p=0;p<=r;p++)c.push(new Uint8Array(i+1));for(let p=0;p<=i;p++)s[r][p]=0;for(let p=r-1;p>=0;p--)for(let h=i-1;h>=0;h--){let T=n(e[p],t[h])+s[p+1][h+1],f=s[p][h+1];T<=f?(s[p][h]=T,c[p][h]=1):s[p][h]=f}let l=[],a=0,u=0;for(;a<r&&u<i;)c[a][u]&&(l.push(o?[t[u],e[a]]:[e[a],t[u]]),a++),u++;return l}function Te(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)),we(c,"onRowsApplied",i.path,[]);return}let a=r.length>l.length,u=l[0]||null;if(a&&!u&&(u=Ct(e,t,n,c),!u))throw new P(i.path);let p=l.map(w=>Nt(e,w,o,c)),h=null;if(a&&u){h=e.clone(u),c.templateAttr&&e.removeAttr(h,c.templateAttr);let w=e.stripIds(h);w>0&&console.warn(`[hyper-html-api] stripped ${w} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let T=We(r,p,o,St(e,l,r,i,c)),f=l.length>0?e.parent(l[0]):It(e,t,n,u,i,c),m=l.length>0?ze(e,f,l[0]):0,g=$t(e,l),d=new Set,y=[],A=r.map((w,b)=>{let O=T[b];if(O>=0)return d.add(O),y.push(!1),l[O];y.push(!0);let x=e.clone(h);return e.stripIds(x),x});l.forEach((w,b)=>{d.has(b)||e.remove(w)}),g?jt(e,f,m,A,y):_t(e,A,y,f,m),Rt(e,A,o,r,i,s,c),we(c,"onRowsApplied",i.path,A)}function we(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 St(e,t,n,o,r){let i=we(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,u)=>[e.identity(a),u]));for(let a=0;a<n.length;a++){if(!i[a])continue;let u=l.get(e.identity(i[a]));u===void 0||c.has(u)||(s[a]=u,c.add(u))}return s}function Rt(e,t,n,o,r,i,s){t.forEach((c,l)=>{if(n===null){let a=o[l],u=a==null?"":String(a);e.text(c)!==u&&e.text(c,u)}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 Nt(e,t,n,o){return n===null?e.text(t):C(e,t,n,o.onRowsRead?{...o,onRowsRead:void 0}:o)}function ze(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 Ct(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?Mt(s):0,l=me(s),a=t;for(;a;){let u=e.find(a,s,{includeRulesTag:!1,templateAttr:null});for(let p of u)if(e.attr(p,o.templateAttr)!=null&&!(r&&!kt(e,t,p,c))&&!(l&&!e.matches(e.parent(p),l)))return p;a=e.parent(a)}return null}function Mt(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 He(o)||He(r)}function He(e){return e===">"||e==="+"||e==="~"}function kt(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(qe(e,r));return qe(e,t).every(l=>c.has(l))}function qe(e,t){let n=e.attr(t,"class");return n?String(n).split(/\s+/).filter(Boolean):[]}function It(e,t,n,o,r,i){let s=e.parent(o);if(s&&Lt(e,t,s)&&!Be(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 a=(c===":scope"?e.prop(t,"tagName")?[t]:[]:e.find(t,c,i)).filter(u=>!Be(e,u,i));if(a.length===0)throw new P(r.path,`no container matching "${c}" inside this context to hold the new rows`);if(a.length>1)throw new P(r.path,`"${c}" matches ${a.length} containers inside this context, so the new rows have no single destination`);return a[0]}function Lt(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 Ve=["no-data","editor-ui"];function Be(e,t,n){let o=t;for(;o;){if(n.templateAttr&&e.attr(o,n.templateAttr)!=null||Ve.some(i=>e.attr(o,i)!=null))return!0;let r=e.attr(o,"clay");if(r&&r.split(/\s+/).some(i=>Ve.includes(i)))return!0;o=e.parent(o)}return!1}function jt(e,t,n,o,r){let i=e.children(t),s=i.map(l=>e.identity(l)),c=!1;o.forEach((l,a)=>{let u=e.identity(l),p=n+a;if(s[p]===u)return;if(!r[a]){let T=s.indexOf(u);T!==-1&&(s.splice(T,1),i.splice(T,1))}let h=Math.min(p,i.length);h<i.length?e.insertBefore(i[h],l):i.length?c?e.insertAfter(i[i.length-1],l):(e.insertAt(t,l,p),c=!0):e.insertAt(t,l,0),s.splice(h,0,u),i.splice(h,0,l)})}function $t(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 a=i?ze(e,l,i)+1:s++;e.insertAt(l,t[c],a),i=t[c]}}function j(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(xe(n,o,[],i),i.length)throw new q(i);oe(e,t,n,o,{depth:0,path:[]},r)}function oe(e,t,n,o,r,i={}){if(r.depth>W)throw new I(r.path);if(o===void 0)return t;if(typeof n=="string")return Dt(e,t,n,o,r,i);if(Array.isArray(n)){let[s,c]=n;return Te(e,t,s,c,o,r,oe,i),t}if(typeof n=="object"&&n!==null){for(let[s,c]of Object.entries(n)){let l=oe(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 Dt(e,t,n,o,r,i){if(n.endsWith("[]")){let u=n.slice(0,-2);return Te(e,t,u,null,o,r,oe,i),t}if(n.startsWith("@"))return Ke(e,t,n.slice(1),o);let s=S(n);if(s!==-1){let{selector:u,all:p}=R(n),h=n.slice(s+1),T=u?e.find(t,u,i):[t];for(let f of p?T:T.slice(0,1))Ke(e,f,h,o);return t}if(n===".")return Fe(e,t,o),t;let{selector:c,all:l}=R(n),a=e.find(t,c,i);for(let u of l?a:a.slice(0,1))Fe(e,u,o);return t}function Fe(e,t,n){let o=n==null?"":String(n);e.text(t)!==o&&e.text(t,o)}function vt(e,t,n,o){if(e.styleVar){e.styleVar(t,n,o);return}ye(e,t,n,o)}function Ke(e,t,n,o){if(L(n))return vt(e,t,n,o==null?"":String(o).trim()),t;if(D.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(ae.has(n)){let r=de(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 xe(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:F([...n,i]),expected:"scalar",got:z(r)})}):o.push({path:F(n),expected:"array",got:z(t)});return}t!==null&&typeof t=="object"&&o.push({path:F(n),expected:"scalar",got:z(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:F(n),expected:"array",got:z(t)});return}let r=e[1];t.forEach((i,s)=>xe(r,i,[...n,s],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:F(n),expected:"object",got:z(t)});return}for(let[r,i]of Object.entries(e))xe(i,t[r],[...n,r],o)}}}function z(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function F(e){return e.join(".")}function Oe(e){try{return JSON.parse(e)}catch(t){throw new v(`Invalid strict JSON: ${t.message}`,t)}}function $(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 p=!1,h=s+1;for(;h<r.length&&/\s/.test(r[h]);)h++;if(h<r.length&&/[a-zA-Z_]/.test(r[h])&&(p=!0),!p){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 p=c,h=s+1;for(;h<r.length&&r[h]!==p;)r[h]==="\\"&&h++,h++;i.push({type:t.STRING,value:r.substring(s+1,h),quoted:!0,sourceQuote:p}),s=h+1;continue}let l=s,a;for(;l<r.length&&!/[{},]/.test(r[l]);)if(r[l]===":"){let p=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],h=!1;for(let T of p){let f=T.substring(1);if(r.substring(l+1,l+1+f.length)===f){h=!0,l+=f.length;break}}if(!h)break}else if(r[l]==="["){for(l++;l<r.length&&r[l]!=="]";){if(r[l]==='"'||r[l]==="'"){let p=r[l];for(l++;l<r.length&&r[l]!==p;)r[l]==="\\"&&l++,l++}l++}l<r.length&&r[l]==="]"&&l++}else l++;a=r.substring(s,l);let u=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(a)?u=t.NUMBER:a==="true"||a==="false"||a==="null"?u=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(a)&&(u=t.SELECTOR),i.push({type:u,value:a,quoted:!1}),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,u)=>u.length%2===0?u+'\\"':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 v("Invalid extraction rules syntax: "+r.message,r)}}var Ee="1",Je=/^[a-zA-Z0-9_-]+$/;function K(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!Je.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${Je})`);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!==Ee)throw new k(s);return{rules:$(e.text(i)),tagNode:i}}var ie=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"]})}),Wt=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),Ye=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui","live"]);function J(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 be(e,t){if(J(e,t))return!0;for(let[n,o]of Object.entries(Wt))if(o.includes(t)&&J(e,n))return!0;return!1}function Y(e){let t=ie[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function Ut(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let o=ie[t];if(!o)throw new Error(`Unknown region capability: ${t}`);if(o.tokens.some(r=>be(n,r))||o.bundles.some(r=>J(n,r)))return n;n=n.parentElement}return null}function Xe(e,t){return!!Ut(e,t)}var Ht=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",...Ye],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 Se(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let o=t&&t.ownerDocument?t.ownerDocument:t;return K(e,o,n)}return null}var zt=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function Ft(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 Ge(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?Xe(e,t):Ge(e,n,r,!1))||!!(o&&(i&&e!==r?e.matches(o):Ge(e,o,r,i)))}function Kt(e,t){let n=ie[t];return n.tokens.some(o=>be(e,o))||n.bundles.some(o=>J(e,o))}var Jt=new Set(["INPUT","TEXTAREA","SELECT","OPTION"]);function Qe(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(Jt.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)Qe(c,s,n,o),s=s.nextSibling}function X(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 u=Y(t),p=o?f=>Kt(f,t)||!!(n&&f.matches(n)):f=>Ze(f,t,u,n,a,!1),h=null;if(a.nodeType!==1||!Ze(a,t,u,n,a,o)){h=s.importNode(a,!0);let f={cloneToLive:c,liveToClone:l,dropped:[],controls:[]};Qe(a,h,f,p);for(let m of f.dropped)m.remove();for(let m=0;m<f.controls.length;m+=2)Ft(f.controls[m],f.controls[m+1])}e.nodeType===9&&h&&(s.replaceChild(h,s.documentElement),l.set(e,s),c.set(s,e));let T=f=>{if(zt.test(f))throw new Error(`Filtered content queries do not support stateful selector: ${f}`)};return{root:h,document:s,capability:t,selector:Y(t),cloneToLive:c,liveToClone:l,original(f){return c.get(f)||null},cloneOf(f){return l.get(f)||null},query(f,m=h){return T(f),Array.from(m.querySelectorAll(f),g=>c.get(g)||g)},text(f=h){return(f===h?h:l.get(f))?.textContent||""},html(f=h){return(f===h?h:l.get(f))?.innerHTML??""},clone(f=h){let m=f===h?h:l.get(f);return m?s.importNode(m,!0):null}}}function tt(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function Yt(e){return e?(e.nodeType===9||e.nodeType===11,e):null}function et(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 nt(e,t){e&&e.tagName==="TEXTAREA"&&(e.value=t)}function rt(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=Yt(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(c=>!tt(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,nt(e,t)},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n),et(e,t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t),et(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 rt(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 G(e,t={}){if(t.exclude===null)return E;let n=[Y("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=X(i,{capability:"data",exclude:t.exclude||null})),a=f=>{let m=l();return f===e?m.cloneOf(e):m.cloneOf(f)||f},u=f=>c?.original(f)||f,p=(f,m)=>{l().liveToClone.set(f,m),l().cloneToLive.set(m,f);let g=f.childNodes||[],d=m.childNodes||[];for(let y=0;y<Math.min(g.length,d.length);y++)p(g[y],d[y])},h=(f,m,g,d)=>{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=d;for(let H of Array.from(x.content.childNodes))f.insertBefore(H,w||null)}else f.insertBefore(s.createTextNode(d),w||null),nt(f,d);let b=X(f,{capability:"data",exclude:t.exclude||null});m.replaceChildren(...Array.from(b.root?.childNodes||[]));let O=x=>{let H=b.original(x);H&&(c.liveToClone.set(H,x),c.cloneToLive.set(x,H));for(let dt of Array.from(x.childNodes||[]))O(dt)};for(let x of Array.from(m.childNodes))O(x)},T={...E,find(f,m,g={}){let d=a(f);if(!d?.querySelectorAll)return[];let y=l().query(m,d);g.includeRulesTag||(y=y.filter(b=>!tt(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 m=a(f)?.parentElement;return m?u(m):null},children(f){return Array.from(a(f)?.children||[],u)},text(f,m){if(m===void 0){let y=u(f);return!y?.matches?.(n)&&!y?.querySelector?.(n)?E.text(y):(a(f)?.textContent||"").trim()}let g=u(f);if(!g?.matches?.(n)&&!g?.querySelector?.(n)&&!c){E.text(g,m);return}let d=l().cloneOf(g);d?h(g,d,"textContent",m):E.text(g,m)},attr(f,m,g){let d=u(f);if(g===void 0)return E.attr(d,m);E.attr(d,m,g);let y=c?.cloneOf(d);y&&(E.attr(y,m,g),X(d,{capability:"data",exclude:t.exclude||null}).root===null&&(y.remove(),c.liveToClone.delete(d),c.cloneToLive.delete(y)))},removeAttr(f,m){let g=u(f);E.removeAttr(g,m);let d=c?.cloneOf(g);d&&E.removeAttr(d,m)},prop(f,m,g){let d=u(f);if(g===void 0)return m==="innerHTML"||m==="outerHTML"||m==="textContent"||m==="innerText"?E.prop(a(d),m):E.prop(d,m);let y=m==="innerHTML"||m==="textContent"||m==="innerText",A=y?l().cloneOf(d):c?.cloneOf(d);A&&y?h(d,A,m,g):(E.prop(d,m,g),A&&E.prop(A,m,g))},clone(f){let m=a(f);if(m===f)return E.clone(f);let g=s.importNode(m,!0);return rt(g),g},insertAt(f,m,g){let d=u(f),A=T.children(d)[g]||(()=>{for(let O=d.children.length-1;O>=0;O--){let x=d.children[O];if(l().cloneOf(x))return x.nextElementSibling}return d.firstElementChild})(),w=u(m);d.insertBefore(w,A||null);let b=l().cloneOf(d);if(b){let O=l().cloneOf(w);O||(O=s.importNode(w,!0),p(w,O));let x=Array.from(b.children);b.insertBefore(O,x[g]||null)}},insertBefore(f,m){let g=u(f),d=u(m);g.parentNode.insertBefore(d,g);let y=l().cloneOf(g.parentNode);if(y){let A=l().cloneOf(d);A||(A=s.importNode(d,!0),p(d,A));let w=l().cloneOf(g);w?w.before(A):y.appendChild(A)}},insertAfter(f,m){let g=u(f),d=u(m);g.parentNode.insertBefore(d,g.nextSibling);let y=l().cloneOf(g.parentNode);if(y){let A=l().cloneOf(d);A||(A=s.importNode(d,!0),p(d,A));let w=l().cloneOf(g);w?w.after(A):y.appendChild(A)}},identity(f){return u(f)||null},remove(f){let m=u(f),g=l().cloneOf(m);E.remove(m),g&&E.remove(g)},replaceWith(f,m){let g=u(f),d=l().cloneOf(g),y=E.replaceWith(g,m);if(d){let A=X(y,{capability:"data",exclude:t.exclude||null});if(!A.root)d.remove();else{d.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 N=E;var Re={extract:(e,t,n={})=>C(G(e,n),e,t,n),apply:(e,t,n,o={})=>j(G(e,{...o,_write:!0}),e,t,n,o),findRulesIn:(e,t)=>K(N,e,t),findRules:(e,t)=>Se(N,e,t),bind:(e,t,n={})=>{let o=Se(N,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:()=>C(G(e,n),e,o.rules,n),set:r=>j(G(e,{...n,_write:!0}),e,o.rules,r,n)}},parseStrict:Oe,parseRelaxed:$,ruleAttrIndex:S,splitRule:R,errors:re,DOM_PROPERTIES:Q};var Xt="hha:upgrade-check:";function M(e,t){let n=e.querySelector(`meta[name="${t}"]`),o=n?n.getAttribute("content"):null;return o&&o.trim()?o.trim():null}function ot(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function Gt(e,t){let n=ot(e),o=ot(t);if(!n||!o)return!1;let r=Math.max(n.length,o.length);for(let i=0;i<r;i++){let s=n[i]||0,c=o[i]||0;if(s!==c)return s>c}return!1}function Zt(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 it({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||(h=>fetch(h)),r=r??Date.now(),!t)return null;let s=M(t,"hyper-source");if(!s)return null;let c=M(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=`${Xt}${l.href}:${c||"none"}`,u,p=e?null:Zt(a);if(p&&typeof p.checkedAt=="number"&&r-p.checkedAt<i)u=p.sourceVersion;else{try{let h=await o(l.href);if(!h.ok)throw new Error(`HTTP ${h.status}`);let T=await h.text(),f=new DOMParser().parseFromString(T,"text/html");u=M(f,"hyper-version")}catch{u=null}Qt(a,{checkedAt:r,sourceVersion:u})}return u?{available:Gt(u,c||"0.0.0"),currentVersion:c,sourceVersion:u,sourceUrl:l.href}:null}var en="script[data-rules-name]";function tn(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function se(e,t){let n=e.find(t,en,{includeRulesTag:!0}),o=new Set,r=[];for(let i of n){let s=tn(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!==Ee)throw new k(c);o.add(s),r.push({name:s,rules:$(e.text(i))})}return r}function Ne(e,t){let n={};for(let{name:o,rules:r}of se(e,t))n[o]=C(e,t,r);return n}function st(e){let t=e||document,n=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:Ne(N,t),version:M(n,"hyper-version")}}var Z=class extends Error{constructor(t,n){super(`could not fetch upgrade source: ${t}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=t,this.cause=n}},ce=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}},le=class extends Error{constructor(t){super(`found ${t} script[type="text/hyper-upgrade"] tags; only one is allowed per document.`),this.name="UpgradeMultipleTransforms",this.count=t}};var nn="text/hyper-upgrade";function ct(e,t){let n=e.find(t,`script[type="${nn}"]`);if(n.length===0)return null;if(n.length>1)throw new le(n.length);return e.text(n[0])||null}var rn=new Function("url","return import(url)");async function lt(e){let t=new Blob([e],{type:"text/javascript"}),n=URL.createObjectURL(t),o;try{o=await rn(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 fe(e,t){let n={carriedOver:0,discarded:0,listItems:0},o=Ce(t,e,n);return Me(t,e,n),{data:o,summary:n}}function Ce(e,t,n,o=!1){if(typeof e=="string")return e.endsWith("[]")?Array.isArray(t)?(n.listItems+=t.length,n.carriedOver+=t.length,t):o?[]:void 0:t==null||typeof t=="object"?o&&!on(e)?null:void 0:(n.carriedOver++,t);if(Array.isArray(e)){let[,r]=e;return Array.isArray(t)?(n.listItems+=t.length,t.map(i=>Ce(r,i,n,!0))):o?[]:void 0}if(typeof e=="object"&&e!==null){let r={};for(let[i,s]of Object.entries(e)){let c=Ce(s,t?.[i],n,o);c!==void 0&&(r[i]=c)}return r}}function on(e){let t=S(e);return t!==-1&&D.has(e.slice(t+1))}function Me(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)?Me(e[r],t[r],n):n.discarded+=U(t[r]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(r=>Me(o,r,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=U(t))}}function U(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+U(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+U(n),0):1}function ft(e,t,n){let o=se(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:u}=fe(n[c],l);j(e,t,l,a,{templateAttr:"cms-template"}),i[c]=u,r.carriedOver+=u.carriedOver,r.discarded+=u.discarded,r.listItems+=u.listItems}for(let c of Object.keys(n))s.has(c)||(r.discarded+=U(n[c]));return{totals:r,byName:i,rulesTagCount:o.length}}async function ut({sourceUrl:e,dataByName:t,fromVersion:n,doc:o,loc:r,fetchFn:i}={}){if(o=o||(typeof document<"u"?document:null),r=r||(typeof location<"u"?location:null),i=i||(d=>fetch(d)),!o)throw new Error("upgrade.run requires a document context");if(e=e||M(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:M(o,"hyper-version"),t=t||Ne(N,o);let c;try{c=await i(s.href)}catch(d){throw new Z(s.href,d)}if(!c.ok)throw new Z(s.href,new Error(`HTTP ${c.status}`));let l=await c.text(),a=new DOMParser().parseFromString(l,"text/html"),u=M(a,"hyper-version"),p=t,h=!1,T=ct(N,a);if(T){let y=await(await lt(T))(p,{fromVersion:n,toVersion:u});if(!y||typeof y!="object"||Array.isArray(y))throw new _("transform must return a plain object map of { rulesName: data }");p=y,h=!0}let{totals:f,byName:m,rulesTagCount:g}=ft(N,a,p);if(g===0&&Object.keys(p).length>0)throw new ce(s.href);return{html:cn(a),fromVersion:n,toVersion:u,summary:{transformApplied:h,totals:f,byName:m}}}function sn(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 cn(e){return sn(e),`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
2
+ `+e.documentElement.outerHTML}var at={checkForUpdate:it,run:ut,extractAll:st,shapeMatch:fe};var ln={engine:Re,upgrade:at},fn=ln;return gt(un);})();
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "apply",
10
10
  "CMS"
11
11
  ],
12
- "version": "0.12.0",
12
+ "version": "0.14.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"
@@ -35,7 +35,8 @@
35
35
  "./data": "./src/data.js",
36
36
  "./upgrade": "./src/upgrade.js",
37
37
  "./page": "./src/page.js",
38
- "./write": "./src/write.js"
38
+ "./write": "./src/write.js",
39
+ "./site": "./src/site.js"
39
40
  },
40
41
  "scripts": {
41
42
  "build": "npx esbuild src/hyper-html-api.js --bundle --minify --format=iife --global-name=HyperHtmlApi --outfile=dist/hyper-html-api.min.js && npm run build:engine && npm run build:engine:esm",
@@ -65,7 +66,7 @@
65
66
  "url": "git+https://github.com/panphora/hyper-html-api.git"
66
67
  },
67
68
  "dependencies": {
68
- "hyper-morph": "^1.6.3"
69
+ "hyper-morph": "^1.7.0"
69
70
  },
70
71
  "devDependencies": {
71
72
  "@panphora/clayjs": "^1.13.1",
@@ -10,7 +10,8 @@ import {
10
10
  ShapeMismatch,
11
11
  } from './errors.js'
12
12
  import { listDiff } from './diff.js'
13
- import { ruleAttrIndex } from './rule-syntax.js'
13
+ import { ruleAttrIndex, splitRule } 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) {
@@ -69,11 +70,10 @@ function applyScalar(adapter, ctx, rule, value, trace, opts) {
69
70
 
70
71
  const at = ruleAttrIndex(rule)
71
72
  if (at !== -1) {
72
- const selector = rule.slice(0, at)
73
+ const { selector, all } = splitRule(rule)
73
74
  const name = rule.slice(at + 1)
74
75
  const matches = selector ? adapter.find(ctx, selector, opts) : [ctx]
75
- if (matches.length === 0) return ctx
76
- writePropOrAttr(adapter, matches[0], name, value)
76
+ for (const node of all ? matches : matches.slice(0, 1)) writePropOrAttr(adapter, node, name, value)
77
77
  return ctx
78
78
  }
79
79
 
@@ -82,9 +82,9 @@ function applyScalar(adapter, ctx, rule, value, trace, opts) {
82
82
  return ctx
83
83
  }
84
84
 
85
- const matches = adapter.find(ctx, rule, opts)
86
- if (matches.length === 0) return ctx
87
- writeText(adapter, matches[0], value)
85
+ const { selector, all } = splitRule(rule)
86
+ const matches = adapter.find(ctx, selector, opts)
87
+ for (const node of all ? matches : matches.slice(0, 1)) writeText(adapter, node, value)
88
88
  return ctx
89
89
  }
90
90
 
@@ -100,10 +100,25 @@ function writeText(adapter, node, value) {
100
100
  if (adapter.text(node) !== target) adapter.text(node, target)
101
101
  }
102
102
 
103
+ // One custom property in the style attribute. A guarded adapter takes it
104
+ // through styleVar(), so its policy sees the property name and the value,
105
+ // never a whole style string it would have to diff.
106
+ function writeCustomProperty(adapter, node, name, want) {
107
+ if (adapter.styleVar) {
108
+ adapter.styleVar(node, name, want)
109
+ return
110
+ }
111
+ setStyleVar(adapter, node, name, want)
112
+ }
113
+
103
114
  // Returns the (possibly new) node. For outerHTML, the original is detached
104
115
  // and a freshly parsed element takes its place; that new node is returned.
105
116
  // For every other write, returns the original node unchanged.
106
117
  function writePropOrAttr(adapter, node, name, value) {
118
+ if (isCustomPropertyName(name)) {
119
+ writeCustomProperty(adapter, node, name, value == null ? '' : String(value).trim())
120
+ return node
121
+ }
107
122
  if (DOM_PROPERTIES_READ_ONLY_SET.has(name)) {
108
123
  const current = adapter.prop(node, name)
109
124
  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
- import { ruleAttrIndex } from './rule-syntax.js'
3
+ import { ruleAttrIndex, splitRule } 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) {
@@ -62,16 +63,19 @@ function extractScalar(adapter, ctx, rule, trace, opts) {
62
63
 
63
64
  const at = ruleAttrIndex(rule)
64
65
  if (at !== -1) {
65
- const selector = rule.slice(0, at)
66
+ const { selector, all } = splitRule(rule)
66
67
  const name = rule.slice(at + 1)
67
68
  const matches = selector ? adapter.find(ctx, selector, opts) : [ctx]
69
+ if (all && opts.allMatches) return matches.map((n) => readPropOrAttr(adapter, n, name))
68
70
  if (matches.length === 0) return null
69
71
  return readPropOrAttr(adapter, matches[0], name)
70
72
  }
71
73
 
72
74
  if (rule === '.') return adapter.text(ctx)
73
75
 
74
- const matches = adapter.find(ctx, rule, opts)
76
+ const { selector, all } = splitRule(rule)
77
+ const matches = adapter.find(ctx, selector, opts)
78
+ if (all && opts.allMatches) return matches.map((n) => adapter.text(n))
75
79
  return matches.length === 0 ? null : adapter.text(matches[0])
76
80
  }
77
81
 
@@ -88,6 +92,7 @@ function reportRows(opts, trace, nodes) {
88
92
  }
89
93
 
90
94
  function readPropOrAttr(adapter, node, name) {
95
+ if (isCustomPropertyName(name)) return readStyleVar(adapter.attr(node, 'style'), name)
91
96
  if (DOM_PROPERTIES_SET.has(name)) {
92
97
  const v = adapter.prop(node, name)
93
98
  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
 
@@ -4,7 +4,8 @@ import {
4
4
  coercePropValue,
5
5
  } from './dom-properties.js'
6
6
  import { WriteNotRoundTripped } from './errors.js'
7
- import { ruleAttrIndex } from './rule-syntax.js'
7
+ import { ruleAttrIndex, splitRule } 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.
@@ -46,6 +47,14 @@ function checkScalarRule(rule, want, got, path) {
46
47
  return
47
48
  }
48
49
  const at = ruleAttrIndex(rule)
50
+ if (splitRule(rule).all) {
51
+ if (!Array.isArray(got) || got.length === 0) fail(path)
52
+ for (const one of got) {
53
+ if (at !== -1) checkPropOrAttr(rule.slice(at + 1), want, one, path)
54
+ else checkText(want, one, path)
55
+ }
56
+ return
57
+ }
49
58
  if (at !== -1) {
50
59
  checkPropOrAttr(rule.slice(at + 1), want, got, path)
51
60
  return
@@ -75,6 +84,10 @@ function checkList(shape, want, got, path) {
75
84
  }
76
85
 
77
86
  function checkPropOrAttr(name, want, got, path) {
87
+ if (isCustomPropertyName(name)) {
88
+ if ((want == null ? '' : String(want).trim()) !== (got ?? '')) fail(path)
89
+ return
90
+ }
78
91
  if (!DOM_PROPERTIES_SET.has(name)) {
79
92
  if (want == null) {
80
93
  if (got != null) fail(path)
@@ -34,12 +34,22 @@ export function ruleAttrIndex(rule) {
34
34
  return found
35
35
  }
36
36
 
37
+ const ALL = '[*]'
38
+
37
39
  // "<selector>@<prop>" split at that separator. selector is "" for a leading "@"
38
- // (the context node itself); prop is null when the rule names no prop.
40
+ // (the context node itself); prop is null when the rule names no prop. A selector
41
+ // that ends in "[*]" names every match instead of the first: `all` is true and
42
+ // the marker is removed, because "[*]" is not CSS and no adapter can run it.
39
43
  export function splitRule(rule) {
40
44
  const at = ruleAttrIndex(rule)
41
- if (at === -1) return { selector: rule, prop: null }
42
- return { selector: rule.slice(0, at), prop: rule.slice(at + 1) || null }
45
+ const head = at === -1 ? rule : rule.slice(0, at)
46
+ const all = head.endsWith(ALL)
47
+ const split = {
48
+ selector: all ? head.slice(0, -ALL.length) : head,
49
+ prop: at === -1 ? null : rule.slice(at + 1) || null,
50
+ }
51
+ if (all) split.all = true
52
+ return split
43
53
  }
44
54
 
45
55
  // The list grammar needs a second split: "container > row" says where a row
@@ -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,4 +1,4 @@
1
- import { ruleAttrIndex } from './rule-syntax.js'
1
+ import { splitRule } from './rule-syntax.js'
2
2
 
3
3
  function isPlainObject(v) {
4
4
  return v !== null && typeof v === 'object' && !Array.isArray(v)
@@ -34,8 +34,7 @@ export function planWrite(adapter, root, rules, data, opts = {}) {
34
34
  if (value === undefined) return
35
35
  if (typeof rule === 'string') {
36
36
  if (rule.endsWith('[]') || rule === '.' || rule.startsWith('@')) return
37
- const at = ruleAttrIndex(rule)
38
- const selector = at === -1 ? rule : rule.slice(0, at)
37
+ const { selector } = splitRule(rule)
39
38
  if (!selector) return
40
39
  if (adapter.find(ctx, selector, opts).length === 0) unmatched.push({ path: label(path), selector })
41
40
  return