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.
- package/README.md +4 -1
- package/conformance/MANIFEST.json +2 -2
- package/conformance/cases/all-matches-read-quoted.expected.json +3 -0
- package/conformance/cases/all-matches-read-quoted.html +5 -0
- package/conformance/cases/all-matches-read-quoted.meta +7 -0
- package/conformance/cases/all-matches-read-quoted.parsed.json +3 -0
- package/conformance/cases/all-matches-read.expected.json +3 -0
- package/conformance/cases/all-matches-read.html +6 -0
- package/conformance/cases/all-matches-read.meta +7 -0
- package/conformance/cases/all-matches-read.parsed.json +3 -0
- package/conformance/cases/stylevar-read.expected.json +12 -0
- package/conformance/cases/stylevar-read.html +7 -0
- package/conformance/cases/stylevar-read.meta +6 -0
- package/conformance/cases/stylevar-read.parsed.json +12 -0
- package/conformance/cases/stylevar-read.rules +1 -0
- package/conformance/cases/write-all-matches-attr.after.html +1 -0
- package/conformance/cases/write-all-matches-attr.after.json +3 -0
- package/conformance/cases/write-all-matches-attr.data.json +1 -0
- package/conformance/cases/write-all-matches-attr.html +1 -0
- package/conformance/cases/write-all-matches-attr.meta +6 -0
- package/conformance/cases/write-all-matches-attr.write.json +4 -0
- package/conformance/cases/write-all-matches-group.after.html +1 -0
- package/conformance/cases/write-all-matches-group.after.json +3 -0
- package/conformance/cases/write-all-matches-group.data.json +1 -0
- package/conformance/cases/write-all-matches-group.html +1 -0
- package/conformance/cases/write-all-matches-group.meta +6 -0
- package/conformance/cases/write-all-matches-group.write.json +4 -0
- package/conformance/cases/write-all-matches-text.after.html +1 -0
- package/conformance/cases/write-all-matches-text.after.json +3 -0
- package/conformance/cases/write-all-matches-text.data.json +1 -0
- package/conformance/cases/write-all-matches-text.html +1 -0
- package/conformance/cases/write-all-matches-text.meta +6 -0
- package/conformance/cases/write-all-matches-text.write.json +4 -0
- package/conformance/cases/write-all-matches-unmatched.data.json +1 -0
- package/conformance/cases/write-all-matches-unmatched.error.json +14 -0
- package/conformance/cases/write-all-matches-unmatched.html +1 -0
- package/conformance/cases/write-all-matches-unmatched.meta +6 -0
- package/conformance/cases/write-refused-raw-style.data.json +1 -0
- package/conformance/cases/write-refused-raw-style.error.json +11 -0
- package/conformance/cases/write-refused-raw-style.html +1 -0
- package/conformance/cases/write-refused-raw-style.meta +4 -0
- package/conformance/cases/write-refused-stylevar-values.data.json +1 -0
- package/conformance/cases/write-refused-stylevar-values.error.json +43 -0
- package/conformance/cases/write-refused-stylevar-values.html +1 -0
- package/conformance/cases/write-refused-stylevar-values.meta +5 -0
- package/conformance/cases/write-stylevar-clear.after.html +1 -0
- package/conformance/cases/write-stylevar-clear.after.json +4 -0
- package/conformance/cases/write-stylevar-clear.data.json +1 -0
- package/conformance/cases/write-stylevar-clear.html +1 -0
- package/conformance/cases/write-stylevar-clear.meta +5 -0
- package/conformance/cases/write-stylevar-clear.write.json +4 -0
- package/conformance/cases/write-stylevar-set.after.html +2 -0
- package/conformance/cases/write-stylevar-set.after.json +5 -0
- package/conformance/cases/write-stylevar-set.data.json +1 -0
- package/conformance/cases/write-stylevar-set.html +1 -0
- package/conformance/cases/write-stylevar-set.meta +6 -0
- package/conformance/cases/write-stylevar-set.write.json +4 -0
- package/conformance/cases/write-stylevar-unchanged.after.html +1 -0
- package/conformance/cases/write-stylevar-unchanged.after.json +3 -0
- package/conformance/cases/write-stylevar-unchanged.data.json +1 -0
- package/conformance/cases/write-stylevar-unchanged.html +1 -0
- package/conformance/cases/write-stylevar-unchanged.meta +5 -0
- package/conformance/cases/write-stylevar-unchanged.write.json +4 -0
- package/conformance/write-policy.json +23 -1
- package/dist/hyper-html-api.engine.esm.js +1 -1
- package/dist/hyper-html-api.engine.min.js +1 -1
- package/dist/hyper-html-api.min.js +8 -8
- package/dist/hyper-html-api.upgrade.min.js +2 -2
- package/package.json +4 -3
- package/src/engine/apply.js +22 -7
- package/src/engine/extract.js +8 -3
- package/src/engine/index.js +2 -1
- package/src/engine/round-trip.js +14 -1
- package/src/engine/rule-syntax.js +13 -3
- package/src/engine/style-vars.js +141 -0
- package/src/engine/write-plan.js +2 -3
- package/src/engine/write-policy.js +60 -0
- package/src/page.js +15 -5
- package/src/site.js +164 -0
- package/src/upgrade/migrate.js +2 -1
- package/src/upgrade/run.js +30 -0
- package/src/upgrade/shape-match.js +32 -13
- package/src/write.js +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
var Qe=Object.defineProperty;var et=(e,t)=>{for(var n in t)Qe(e,n,{get:t[n],enumerable:!0})};var G=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],Y=new Set(G),re=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),$=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]),Ee=new Set(["checked","selected","disabled","readOnly","paused"]);function ie(e,t){return t==null?Ee.has(e)?!1:"":Ee.has(e)?t==="false"?!1:!!t:t}var R={};et(R,{EmptyListInsert:()=>N,MAX_RULE_DEPTH:()=>L,MaxRuleDepthExceeded:()=>P,NoRulesTag:()=>oe,RuleTargetReadOnly:()=>B,RulesParseError:()=>k,ShapeMismatch:()=>v,UnknownRulesVersion:()=>W,WriteNotRoundTripped:()=>Z,WriteRefused:()=>H,WriteRejected:()=>se});var k=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},W=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},L=20,P=class extends Error{constructor(t){super(`rule depth exceeded ${L} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},v=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},N=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}},B=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},H=class extends Error{constructor(t){super(`write refused: ${t.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=t}};function tt(e){return e.reduce((n,r)=>typeof r=="number"?`${n}[${r}]`:n?`${n}.${r}`:String(r),"")||"(root)"}var Z=class extends Error{constructor(t){super(`write did not round-trip at "${tt(t)}"`),this.name="WriteNotRoundTripped",this.path=t}},oe=class extends Error{constructor(t){super(`no <script data-rules-name~="${t}"> rules tag in this document`),this.name="NoRulesTag",this.token=t}},se=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 b(e){let t=0,n=null,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--:s==="@"&&t===0&&(r=i)}return r}function le(e){let t=b(e);return t===-1?{selector:e,prop:null}:{selector:e.slice(0,t),prop:e.slice(t+1)||null}}function ce(e){let t=0,n=null,r=-1,i=!1;for(let s=0;s<e.length;s++){let l=e[s];l==="\\"?s++:n?l===n&&(n=null):l==='"'||l==="'"?n=l:l==="["||l==="("?t++:l==="]"||l===")"?t>0&&t--:t===0&&l===">"?r=s:t===0&&l===","&&(i=!0)}return i||r===-1||!nt(e,r+1)?null:e.slice(0,r).trim()||null}function nt(e,t){let n=t,r=e.replace(/\s+$/,"").length;for(;n<r&&/\s/.test(e[n]);)n++;let i=0,s=null;for(;n<r;n++){let l=e[n];if(l==="\\")n++;else if(s)l===s&&(s=null);else if(l==='"'||l==="'")s=l;else if(l==="["||l==="(")i++;else if(l==="]"||l===")")i>0&&i--;else if(i===0&&(l==="+"||l==="~"||/\s/.test(l)))return!1}return!0}function C(e,t,n,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.");return fe(e,t,n,{depth:0,path:[]},r)}function fe(e,t,n,r,i){if(r.depth>L)throw new P(r.path);if(typeof n=="string")return rt(e,t,n,r,i);if(Array.isArray(n)){let[s,l]=n,c=e.find(t,s,i);return xe(i,r,c),c.map((o,f)=>fe(e,o,l,{depth:r.depth+1,path:[...r.path,f]},i))}if(typeof n=="object"&&n!==null){let s={};for(let[l,c]of Object.entries(n))s[l]=fe(e,t,c,{depth:r.depth+1,path:[...r.path,l]},i);return s}return null}function rt(e,t,n,r,i){if(n.endsWith("[]")){let c=n.slice(0,-2),o=e.find(t,c,i);return xe(i,r,o),o.map(f=>e.text(f))}if(n.startsWith("@"))return Oe(e,t,n.slice(1));let s=b(n);if(s!==-1){let c=n.slice(0,s),o=n.slice(s+1),f=c?e.find(t,c,i):[t];return f.length===0?null:Oe(e,f[0],o)}if(n===".")return e.text(t);let l=e.find(t,n,i);return l.length===0?null:e.text(l[0])}function xe(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(r){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,r)}}function Oe(e,t,n){if(Y.has(n)){let i=e.prop(t,n);return i==null?null:String(i)}let r=e.attr(t,n);return r??null}function Re(e,t,n,r){let i=e.length,s=t.length,l=new Array(i).fill(-1);if(r){let h=new Set;for(let y=0;y<i;y++){let A=r[y];!(A>=0&&A<s)||h.has(A)||(l[y]=A,h.add(A))}}if(i===0||s===0)return l;let c=e.map(h=>Se(h,n)),o=t.map(h=>Se(h,n)),f=new Array(s).fill(!1);for(let h of l)h>=0&&(f[h]=!0);let u=new Map;o.forEach((h,y)=>{f[y]||u.set(h,u.has(h)?-1:y)});let m=new Map;c.forEach((h,y)=>{l[y]>=0||m.set(h,(m.get(h)||0)+1)}),c.forEach((h,y)=>{if(l[y]>=0||m.get(h)!==1)return;let A=u.get(h);A===void 0||A===-1||f[A]||(l[y]=A,f[A]=!0)});let d=[];for(let h=0;h<i;h++)l[h]<0&&d.push(h);let w=[];for(let h=0;h<s;h++)f[h]||w.push(h);if(d.length===0||w.length===0)return l;let a=i*s+1,p=it(e,t,n),g=(h,y)=>p(h,y)*a+Math.abs(h-y);for(let[h,y]of ot(d,w,g))l[h]=y;return l}var Ne=e=>typeof e=="object"&&e!==null;function Se(e,t){if(!Ne(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(r=>{let i=JSON.stringify(e?.[r]);return i===void 0?" undef":i}))}function it(e,t,n){if(!Ne(n))return(c,o)=>e[c]===t[o]?0:1;let r=Object.keys(n),i=c=>r.map(o=>JSON.stringify(c?.[o])),s=e.map(i),l=t.map(i);return(c,o)=>{let f=s[c],u=l[o],m=0;for(let d=0;d<r.length;d++)f[d]!==u[d]&&m++;return m}}function ot(e,t,n){return e.length<=t.length?be(e,t,n,!1):be(t,e,(r,i)=>n(i,r),!0)}function be(e,t,n,r){let i=e.length,s=t.length,l=[];for(let m=0;m<=i;m++)l.push(new Float64Array(s+1).fill(1/0));let c=[];for(let m=0;m<=i;m++)c.push(new Uint8Array(s+1));for(let m=0;m<=s;m++)l[i][m]=0;for(let m=i-1;m>=0;m--)for(let d=s-1;d>=0;d--){let w=n(e[m],t[d])+l[m+1][d+1],a=l[m][d+1];w<=a?(l[m][d]=w,c[m][d]=1):l[m][d]=a}let o=[],f=0,u=0;for(;f<i&&u<s;)c[f][u]&&(o.push(r?[t[u],e[f]]:[e[f],t[u]]),f++),u++;return o}function ae(e,t,n,r,i,s,l,c={}){let o=e.find(t,n,c);if(i.length===0){o.forEach(T=>e.remove(T)),ue(c,"onRowsApplied",s.path,[]);return}let f=i.length>o.length,u=o[0]||null;if(f&&!u&&(u=ft(e,t,n,c),!u))throw new N(s.path);let m=o.map(T=>ct(e,T,r,c)),d=null;if(f&&u){d=e.clone(u),c.templateAttr&&e.removeAttr(d,c.templateAttr);let T=e.stripIds(d);T>0&&console.warn(`[hyper-html-api] stripped ${T} id attribute(s) from cloned template at "${s.path.join(".")||"(root)"}"`)}let w=Re(i,m,r,st(e,o,i,s,c)),a=o.length>0?e.parent(o[0]):dt(e,t,n,u,s,c),p=o.length>0?ke(e,a,o[0]):0,g=yt(e,o),h=new Set,y=[],A=i.map((T,S)=>{let O=w[S];if(O>=0)return h.add(O),y.push(!1),o[O];y.push(!0);let E=e.clone(d);return e.stripIds(E),E});o.forEach((T,S)=>{h.has(S)||e.remove(T)}),g?mt(e,a,p,A,y):gt(e,A,y,a,p),lt(e,A,r,i,s,l,c),ue(c,"onRowsApplied",s.path,A)}function ue(e,t,n,r){if(typeof e[t]=="function")try{return e[t](n.slice(),r)}catch(i){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,i);return}}function st(e,t,n,r,i){let s=ue(i,"identifyRows",r.path,n);if(!Array.isArray(s))return null;let l=new Array(n.length).fill(-1),c=new Set,o=new Map(t.map((f,u)=>[e.identity(f),u]));for(let f=0;f<n.length;f++){if(!s[f])continue;let u=o.get(e.identity(s[f]));u===void 0||c.has(u)||(l[f]=u,c.add(u))}return l}function lt(e,t,n,r,i,s,l){t.forEach((c,o)=>{if(n===null){let f=r[o],u=f==null?"":String(f);e.text(c)!==u&&e.text(c,u)}else{let f=s(e,c,n,r[o],{depth:i.depth+1,path:[...i.path,o]},l);f&&f!==c&&(t[o]=f)}})}function ct(e,t,n,r){return n===null?e.text(t):C(e,t,n,r.onRowsRead?{...r,onRowsRead:void 0}:r)}function ke(e,t,n){let r=e.children(t);for(let i=0;i<r.length;i++)if(e.sameNode(r[i],n))return i;return-1}function ft(e,t,n,r){if(!r.templateAttr)return null;let i=/^\s*:scope\s*>\s*/.test(n),s=new RegExp(":not\\(\\["+r.templateAttr.replace(/[.*+?^${}()|[\]\\-]/g,"\\$&")+"\\]\\)","g"),l=n.replace(/^\s*:scope\s*>\s*/,"").replace(s,""),c=i?ut(l):0,o=ce(l),f=t;for(;f;){let u=e.find(f,l,{includeRulesTag:!1,templateAttr:null});for(let m of u)if(e.attr(m,r.templateAttr)!=null&&!(i&&!ht(e,t,m,c))&&!(o&&!e.matches(e.parent(m),o)))return m;f=e.parent(f)}return null}function ut(e){let t=0,n=null,r=1;for(let i=0;i<e.length;i++){let s=e[i];if(s==="\\")i++;else if(n)s===n&&(n=null);else if(s==='"'||s==="'")n=s;else if(s==="["||s==="(")t++;else if(s==="]"||s===")")t>0&&t--;else if(t===0&&s===">")r++;else{if(t===0&&(s==="+"||s==="~"))return null;if(t===0&&/\s/.test(s)){if(!at(e,i))return null;for(;i+1<e.length&&/\s/.test(e[i+1]);)i++}}}return r}function at(e,t){let n=t;for(;n<e.length&&/\s/.test(e[n]);)n++;let r=t>0?e[t-1]:"",i=n<e.length?e[n]:"";return Ce(r)||Ce(i)}function Ce(e){return e===">"||e==="+"||e==="~"}function ht(e,t,n,r){if(r===null)return!0;let i=n;for(let o=0;o<r;o++)if(i=e.parent(i),!i)return!1;let s=e.prop(t,"tagName");if(!s)return!0;let l=e.prop(i,"tagName");if(!l||String(l).toLowerCase()!==String(s).toLowerCase())return!1;let c=new Set(Me(e,i));return Me(e,t).every(o=>c.has(o))}function Me(e,t){let n=e.attr(t,"class");return n?String(n).split(/\s+/).filter(Boolean):[]}function dt(e,t,n,r,i,s){let l=e.parent(r);if(l&&pt(e,t,l)&&!Ie(e,l,s))return l;let c=ce(n);if(!c)throw new N(i.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 f=(c===":scope"?e.prop(t,"tagName")?[t]:[]:e.find(t,c,s)).filter(u=>!Ie(e,u,s));if(f.length===0)throw new N(i.path,`no container matching "${c}" inside this context to hold the new rows`);if(f.length>1)throw new N(i.path,`"${c}" matches ${f.length} containers inside this context, so the new rows have no single destination`);return f[0]}function pt(e,t,n){let r=n;for(;r;){if(e.sameNode(r,t))return!0;r=e.parent(r)}return e.parent(t)?!1:e.find(t,"*",{includeRulesTag:!0,templateAttr:null}).some(i=>e.sameNode(i,n))}var Pe=["no-data","editor-ui"];function Ie(e,t,n){let r=t;for(;r;){if(n.templateAttr&&e.attr(r,n.templateAttr)!=null||Pe.some(s=>e.attr(r,s)!=null))return!0;let i=e.attr(r,"clay");if(i&&i.split(/\s+/).some(s=>Pe.includes(s)))return!0;r=e.parent(r)}return!1}function mt(e,t,n,r,i){let s=e.children(t),l=s.map(o=>e.identity(o)),c=!1;r.forEach((o,f)=>{let u=e.identity(o),m=n+f;if(l[m]===u)return;if(!i[f]){let w=l.indexOf(u);w!==-1&&(l.splice(w,1),s.splice(w,1))}let d=Math.min(m,s.length);d<s.length?e.insertBefore(s[d],o):s.length?c?e.insertAfter(s[s.length-1],o):(e.insertAt(t,o,m),c=!0):e.insertAt(t,o,0),l.splice(d,0,u),s.splice(d,0,o)})}function yt(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let r=new Map(e.children(n).map((s,l)=>[e.identity(s),l])),i=[];for(let s of t){let l=r.get(e.identity(s));if(l===void 0)return!1;i.push(l)}return i.sort((s,l)=>s-l),i[i.length-1]-i[0]===i.length-1}function gt(e,t,n,r,i){let s=null,l=i;for(let c=0;c<t.length;c++){if(!n[c]){s=t[c];continue}let o=s?e.parent(s):r;if(!o)continue;let f=s?ke(e,o,s)+1:l++;e.insertAt(o,t[c],f),s=t[c]}}function I(e,t,n,r,i={}){if(Object.prototype.hasOwnProperty.call(i,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");let s=[];if(he(n,r,[],s),s.length)throw new v(s);Q(e,t,n,r,{depth:0,path:[]},i)}function Q(e,t,n,r,i,s={}){if(i.depth>L)throw new P(i.path);if(r===void 0)return t;if(typeof n=="string")return At(e,t,n,r,i,s);if(Array.isArray(n)){let[l,c]=n;return ae(e,t,l,c,r,i,Q,s),t}if(typeof n=="object"&&n!==null){for(let[l,c]of Object.entries(n)){let o=Q(e,t,c,r==null?r:r[l],{depth:i.depth+1,path:[...i.path,l]},s);o&&o!==t&&(t=o)}return t}return t}function At(e,t,n,r,i,s){if(n.endsWith("[]")){let o=n.slice(0,-2);return ae(e,t,o,null,r,i,Q,s),t}if(n.startsWith("@"))return je(e,t,n.slice(1),r);let l=b(n);if(l!==-1){let o=n.slice(0,l),f=n.slice(l+1),u=o?e.find(t,o,s):[t];return u.length===0||je(e,u[0],f,r),t}if(n===".")return Le(e,t,r),t;let c=e.find(t,n,s);return c.length===0||Le(e,c[0],r),t}function Le(e,t,n){let r=n==null?"":String(n);e.text(t)!==r&&e.text(t,r)}function je(e,t,n,r){if($.has(n)){let i=e.prop(t,n);if(i===r||i!=null&&r!=null&&String(i)===String(r))return t;throw new B(n)}if(n==="outerHTML"){let i=r==null?"":String(r);return e.replaceWith(t,i)}if(re.has(n)){let i=ie(n,r);return e.prop(t,n)!==i&&e.prop(t,n,i),t}if(r==null)e.attr(t,n)!=null&&e.removeAttr(t,n);else{let i=String(r);e.attr(t,n)!==i&&e.attr(t,n,i)}return t}function he(e,t,n,r){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((i,s)=>{typeof i=="object"&&i!==null&&r.push({path:U([...n,s]),expected:"scalar",got:q(i)})}):r.push({path:U(n),expected:"array",got:q(t)});return}t!==null&&typeof t=="object"&&r.push({path:U(n),expected:"scalar",got:q(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){r.push({path:U(n),expected:"array",got:q(t)});return}let i=e[1];t.forEach((s,l)=>he(i,s,[...n,l],r));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){r.push({path:U(n),expected:"object",got:q(t)});return}for(let[i,s]of Object.entries(e))he(s,t[i],[...n,i],r)}}}function q(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function U(e){return e.join(".")}function de(e){try{return JSON.parse(e)}catch(t){throw new k(`Invalid strict JSON: ${t.message}`,t)}}function z(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(i){let s=[],l=0;for(;l<i.length;){let c=i[l];if(/\s/.test(c)){l++;continue}if("{}".includes(c)){s.push({type:c,value:c}),l++;continue}if(c==="["){let m=!1,d=l+1;for(;d<i.length&&/\s/.test(i[d]);)d++;if(d<i.length&&/[a-zA-Z_]/.test(i[d])&&(m=!0),!m){s.push({type:c,value:c}),l++;continue}}if(c==="]"){s.push({type:c,value:c}),l++;continue}if(c===":"){s.push({type:t.COLON,value:c}),l++;continue}if(c===","){s.push({type:t.COMMA,value:c}),l++;continue}if(c==='"'||c==="'"){let m=c,d=l+1;for(;d<i.length&&i[d]!==m;)i[d]==="\\"&&d++,d++;s.push({type:t.STRING,value:i.substring(l+1,d),quoted:!0,sourceQuote:m}),l=d+1;continue}let o=l,f;for(;o<i.length&&!/[{},]/.test(i[o]);)if(i[o]===":"){let m=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],d=!1;for(let w of m){let a=w.substring(1);if(i.substring(o+1,o+1+a.length)===a){d=!0,o+=a.length;break}}if(!d)break}else if(i[o]==="["){for(o++;o<i.length&&i[o]!=="]";){if(i[o]==='"'||i[o]==="'"){let m=i[o];for(o++;o<i.length&&i[o]!==m;)i[o]==="\\"&&o++,o++}o++}o<i.length&&i[o]==="]"&&o++}else o++;f=i.substring(l,o);let u=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(f)?u=t.NUMBER:f==="true"||f==="false"||f==="null"?u=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(f)&&(u=t.SELECTOR),s.push({type:u,value:f,quoted:!1}),l=o}return s}function r(i){let s="";for(let l=0;l<i.length;l++){let c=i[l];if("{}".includes(c.type)||"[]".includes(c.type)){s+=c.value;continue}if(c.type===t.COLON){s+=c.value;continue}if(c.type===t.COMMA){let o=i[l+1];if(o&&(o.type==="}"||o.type==="]"))continue;s+=c.value;continue}if(c.type===t.STRING&&c.quoted){let o=c.value;c.sourceQuote==="'"&&(o=o.replace(/\\'/g,"'"),o=o.replace(/(\\*)"/g,(f,u)=>u.length%2===0?u+'\\"':f)),s+=`"${o}"`;continue}if(c.type===t.NUMBER||c.type===t.BOOLEAN){s+=c.value;continue}if(c.type===t.SELECTOR||c.type===t.IDENTIFIER){s+=`"${c.value}"`;continue}s+=`"${c.value}"`}return s}try{let i=n(e),s=r(i);return JSON.parse(s)}catch(i){throw new k("Invalid extraction rules syntax: "+i.message,i)}}var Tt="1",_e=/^[a-zA-Z0-9_-]+$/;function j(e,t,n){let r;if(n===void 0)r="script[data-rules-name]";else{if(typeof n!="string"||!_e.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${_e})`);r=`script[data-rules-name~="${n}"]`}let i=e.find(t,r,{includeRulesTag:!0});if(i.length===0)return null;n!==void 0&&i.length>1&&console.warn(`hyper-html-api: ${i.length} rules tags match data-rules-name~="${n}"; using the first.`);let s=i[0],l=e.attr(s,"data-rules-version");if(l!==Tt)throw new W(l);return{rules:z(e.text(s)),tagNode:s}}var ee=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"])}),De=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 pe(e,t){if(K(e,t))return!0;for(let[n,r]of Object.entries(wt))if(r.includes(t)&&K(e,n))return!0;return!1}function F(e){let t=ee[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function Et(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let r=ee[t];if(!r)throw new Error(`Unknown region capability: ${t}`);if(r.tokens.some(i=>pe(n,i))||r.bundles.some(i=>K(n,i)))return n;n=n.parentElement}return null}function $e(e,t){return!!Et(e,t)}var me=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",...De],refusedAttributePrefixes:["on"],urlAttributes:["href","src","srcset","action","formaction","poster","cite","data","ping","background","longdesc","usemap","xlink:href","manifest","codebase","icon"],refusedSchemes:["javascript","vbscript","data"]}),Ot=new Set(["textContent","innerText"]);function We(e){let n=String(e).replace(/^[\u0000- ]+|[\u0000- ]+$/g,"").replace(/[\t\n\r]/g,"").match(/^([a-zA-Z][a-zA-Z0-9+.-]*):/);return n?n[1].toLowerCase():null}var xt=/^[^\t\n\f\r "'>/=\u0000-\u001f\u007f]+$/;function ve(e,t,n=me){if(!xt.test(String(e)))return`attribute name ${JSON.stringify(String(e))} is not valid`;let r=String(e).toLowerCase();if(n.refusedAttributePrefixes.some(i=>r.startsWith(i)))return`attribute "${r}" can run script`;if(n.refusedAttributes.includes(r))return`attribute "${r}" is not content`;if(n.urlAttributes.includes(r)&&t!=null){let i=r==="srcset"?String(t).split(",").map(s=>s.trim().split(/\s+/)[0]).filter(Boolean):[String(t)];for(let s of i){let l=We(s);if(l&&n.refusedSchemes.includes(l))return`"${l}:" URLs are not allowed in "${r}"`}}return null}function ye(e,t){let n=e.prop(t,"tagName");return n?String(n).toLowerCase():""}function St(e,t){let n=ye(e,t)||"node",r=e.attr(t,"id");return r?`<${n}#${r}>`:`<${n}>`}function bt(e,t,n){let r=t;for(;r;){let i=ye(e,r);if(i&&n.refusedTargets.includes(i))return i;r=e.parent(r)}return null}function Be(e,t){return e.find(t,"script[data-rules-name]",{includeRulesTag:!0,templateAttr:null}).length>0}function Rt(e,t){return ye(e,t)==="script"&&e.attr(t,"data-rules-name")!=null?!0:Be(e,t)}function te(e,t=me){let n=[],r=(o,f)=>(n.push({target:St(e,o),reason:f}),!1),i=o=>{let f=bt(e,o,t);return f?r(o,`inside <${f}>, which is not content`):!0},s=o=>i(o)?Be(e,o)?r(o,"a text write here would delete the data rules tag"):!0:!1,l=(o,f,u)=>{if(!i(o))return!1;let m=ve(f,u,t);return m?r(o,m):!0};return{...e,text(o,f){if(f===void 0)return e.text(o);s(o)&&e.text(o,f)},attr(o,f,u){if(u===void 0)return e.attr(o,f);l(o,f,u)&&e.attr(o,f,u)},removeAttr(o,f){l(o,f,null)&&e.removeAttr(o,f)},prop(o,f,u){if(u===void 0)return e.prop(o,f);if(t.refusedRuleForms.includes(f))return r(o,`"@${f}" writes HTML, only text is allowed`);if(Ot.has(f)){s(o)&&e.prop(o,f,u);return}l(o,f==="className"?"class":f,u)&&e.prop(o,f,u)},remove(o){if(Rt(e,o)){r(o,"removing this would delete the data rules tag");return}e.remove(o)},replaceWith(o,f){return f===e.prop(o,"outerHTML")||r(o,'"@outerHTML" writes HTML, only text is allowed'),o},refusals:n,assertClean(){if(n.length)throw new H(n.slice())}}}function V(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function He(e){return e.reduce((t,n)=>typeof n=="number"?`${t}[${n}]`:t?`${t}.${n}`:n,"")}function ge(e,t,n,r,i={}){let s=[],l=[];function c(f,u,m){if(Array.isArray(f)){let[,d]=f;if(!Array.isArray(u)||!V(d))return;u.forEach((w,a)=>c(d,w,[...m,a]));return}if(!(!V(f)||!V(u)))for(let d of Object.keys(u))Object.prototype.hasOwnProperty.call(f,d)?c(f[d],u[d],[...m,d]):s.push(He([...m,d]))}function o(f,u,m,d){if(m!==void 0){if(typeof u=="string"){if(u.endsWith("[]")||u==="."||u.startsWith("@"))return;let w=b(u),a=w===-1?u:u.slice(0,w);if(!a)return;e.find(f,a,i).length===0&&l.push({path:He(d),selector:a});return}if(!Array.isArray(u)&&V(u)&&V(m))for(let[w,a]of Object.entries(u))o(f,a,m[w],[...d,w])}}return c(n,r,[]),o(t,n,r,[]),{unknownKeys:s,unmatched:l}}function Ae(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let r=t&&t.ownerDocument?t.ownerDocument:t;return j(e,r,n)}return null}var Ct=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function Mt(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 qe(e,t,n,r){if(r)return!!e.closest?.(t);let i=e;for(;i?.nodeType===1;){if(i.matches(t))return!0;if(i===n)break;i=i.parentElement}return!1}function Ue(e,t,n,r,i,s){return(s?$e(e,t):qe(e,n,i,!1))||!!(r&&(s&&e!==i?e.matches(r):qe(e,r,i,s)))}function Pt(e,t){let n=ee[t];return n.tokens.some(r=>pe(e,r))||n.bundles.some(r=>K(e,r))}var It=new Set(["INPUT","TEXTAREA","SELECT","OPTION"]);function ze(e,t,n,r){if(e.nodeType===1&&r(e)){n.dropped.push(t);return}n.cloneToLive.set(t,e),n.liveToClone.set(e,t);let i=e,s=t;if(e.nodeType===1){if(It.has(e.tagName)&&n.controls.push(e,t),e.tagName==="TEMPLATE"){for(;t.firstChild;)t.removeChild(t.firstChild);i=e.content,s=t.content,n.cloneToLive.set(s,i),n.liveToClone.set(i,s)}}else if(e.nodeType!==11)return;let l=s.firstChild;for(let c=i.firstChild;c&&l;c=c.nextSibling)ze(c,l,n,r),l=l.nextSibling}function J(e,{capability:t="data",exclude:n=null,inherit:r=!0,provenance:i=null}={}){if(!e)throw new TypeError("createContentView requires a DOM context");let s=e.nodeType===9?e:e.ownerDocument;if(!s?.implementation?.createHTMLDocument)throw new TypeError("createContentView requires an HTML DOM implementation");let l=s.implementation.createHTMLDocument(""),c=i||new WeakMap,o=new WeakMap,f=e.nodeType===9?e.documentElement:e;n&&l.documentElement.matches(n);let u=F(t),m=r?a=>Pt(a,t)||!!(n&&a.matches(n)):a=>Ue(a,t,u,n,f,!1),d=null;if(f.nodeType!==1||!Ue(f,t,u,n,f,r)){d=l.importNode(f,!0);let a={cloneToLive:c,liveToClone:o,dropped:[],controls:[]};ze(f,d,a,m);for(let p of a.dropped)p.remove();for(let p=0;p<a.controls.length;p+=2)Mt(a.controls[p],a.controls[p+1])}e.nodeType===9&&d&&(l.replaceChild(d,l.documentElement),o.set(e,l),c.set(l,e));let w=a=>{if(Ct.test(a))throw new Error(`Filtered content queries do not support stateful selector: ${a}`)};return{root:d,document:l,capability:t,selector:F(t),cloneToLive:c,liveToClone:o,original(a){return c.get(a)||null},cloneOf(a){return o.get(a)||null},query(a,p=d){return w(a),Array.from(p.querySelectorAll(a),g=>c.get(g)||g)},text(a=d){return(a===d?d:o.get(a))?.textContent||""},html(a=d){return(a===d?d:o.get(a))?.innerHTML??""},clone(a=d){let p=a===d?d:o.get(a);return p?l.importNode(p,!0):null}}}function Fe(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function kt(e){return e?(e.nodeType===9||e.nodeType===11,e):null}function Ke(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 Ve(e,t){e&&e.tagName==="TEXTAREA"&&(e.value=t)}function Je(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 r=n.type;r!=="file"&&r!=="checkbox"&&r!=="radio"&&(n.value=n.defaultValue),n.checked=n.defaultChecked}else n.tagName==="OPTION"&&(n.selected=n.defaultSelected)}var x={semanticExclude:!0,find(e,t,n={}){let r=kt(e);if(!r||!r.querySelectorAll)return[];let i=Array.from(r.querySelectorAll(t));n.includeRulesTag||(i=i.filter(c=>!Fe(c)));let s=[];n.skip&&s.push(n.skip);let l=n.templateAttr===null?null:n.templateAttr||"cms-template";if(l&&s.push("["+l+"]"),s.length){let c=s.join(", ");i=i.filter(o=>!o.closest||!o.closest(c))}return i},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,Ve(e,t)},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n),Ke(e,t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t),Ke(e,t,null)},prop(e,t,n){if(n===void 0){let r=e?e[t]:void 0;return r!==void 0?r:null}e[t]=n},clone(e){let t=e.cloneNode(!0);return Je(t),t},insertAt(e,t,n){let r=e.children[n]||null;e.insertBefore(t,r)},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 r=e.ownerDocument.createElement("template");r.innerHTML=t;let i=r.content.firstElementChild;if(!i)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(i,e),i},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(r=>{r.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};function M(e,t={}){if(t.exclude===null)return x;let n=[F("data"),t.exclude].filter(Boolean).join(", "),r=e.nodeType===9?e:e.ownerDocument||e,i=e.nodeType===9?e.documentElement:e;if(!t._write&&!i?.matches?.(n)&&!i?.querySelector?.(n)&&!r?.querySelector?.(n))return x;let s=e.nodeType===9||!e.isConnected?e:e.ownerDocument,l=e.nodeType===9?e:e.ownerDocument,c=null,o=()=>c||(c=J(s,{capability:"data",exclude:t.exclude||null})),f=a=>{let p=o();return a===e?p.cloneOf(e):p.cloneOf(a)||a},u=a=>c?.original(a)||a,m=(a,p)=>{o().liveToClone.set(a,p),o().cloneToLive.set(p,a);let g=a.childNodes||[],h=p.childNodes||[];for(let y=0;y<Math.min(g.length,h.length);y++)m(g[y],h[y])},d=(a,p,g,h)=>{let y=Array.from(a.childNodes).filter(E=>c.cloneOf(E)),T=y[0];for(;T&&y.includes(T);)T=T.nextSibling;for(let E of y)E.remove();if(g==="innerHTML"){let E=l.createElement("template");E.innerHTML=h;for(let D of Array.from(E.content.childNodes))a.insertBefore(D,T||null)}else a.insertBefore(l.createTextNode(h),T||null),Ve(a,h);let S=J(a,{capability:"data",exclude:t.exclude||null});p.replaceChildren(...Array.from(S.root?.childNodes||[]));let O=E=>{let D=S.original(E);D&&(c.liveToClone.set(D,E),c.cloneToLive.set(E,D));for(let Ze of Array.from(E.childNodes||[]))O(Ze)};for(let E of Array.from(p.childNodes))O(E)},w={...x,find(a,p,g={}){let h=f(a);if(!h?.querySelectorAll)return[];let y=o().query(p,h);g.includeRulesTag||(y=y.filter(S=>!Fe(S)));let A=[];g.skip&&A.push(g.skip);let T=g.templateAttr===null?null:g.templateAttr||"cms-template";if(T&&A.push(`[${T}]`),A.length){let S=A.join(", ");y=y.filter(O=>!O.closest?.(S))}return y},parent(a){let p=f(a)?.parentElement;return p?u(p):null},children(a){return Array.from(f(a)?.children||[],u)},text(a,p){if(p===void 0){let y=u(a);return!y?.matches?.(n)&&!y?.querySelector?.(n)?x.text(y):(f(a)?.textContent||"").trim()}let g=u(a);if(!g?.matches?.(n)&&!g?.querySelector?.(n)&&!c){x.text(g,p);return}let h=o().cloneOf(g);h?d(g,h,"textContent",p):x.text(g,p)},attr(a,p,g){let h=u(a);if(g===void 0)return x.attr(h,p);x.attr(h,p,g);let y=c?.cloneOf(h);y&&(x.attr(y,p,g),J(h,{capability:"data",exclude:t.exclude||null}).root===null&&(y.remove(),c.liveToClone.delete(h),c.cloneToLive.delete(y)))},removeAttr(a,p){let g=u(a);x.removeAttr(g,p);let h=c?.cloneOf(g);h&&x.removeAttr(h,p)},prop(a,p,g){let h=u(a);if(g===void 0)return p==="innerHTML"||p==="outerHTML"||p==="textContent"||p==="innerText"?x.prop(f(h),p):x.prop(h,p);let y=p==="innerHTML"||p==="textContent"||p==="innerText",A=y?o().cloneOf(h):c?.cloneOf(h);A&&y?d(h,A,p,g):(x.prop(h,p,g),A&&x.prop(A,p,g))},clone(a){let p=f(a);if(p===a)return x.clone(a);let g=l.importNode(p,!0);return Je(g),g},insertAt(a,p,g){let h=u(a),A=w.children(h)[g]||(()=>{for(let O=h.children.length-1;O>=0;O--){let E=h.children[O];if(o().cloneOf(E))return E.nextElementSibling}return h.firstElementChild})(),T=u(p);h.insertBefore(T,A||null);let S=o().cloneOf(h);if(S){let O=o().cloneOf(T);O||(O=l.importNode(T,!0),m(T,O));let E=Array.from(S.children);S.insertBefore(O,E[g]||null)}},insertBefore(a,p){let g=u(a),h=u(p);g.parentNode.insertBefore(h,g);let y=o().cloneOf(g.parentNode);if(y){let A=o().cloneOf(h);A||(A=l.importNode(h,!0),m(h,A));let T=o().cloneOf(g);T?T.before(A):y.appendChild(A)}},insertAfter(a,p){let g=u(a),h=u(p);g.parentNode.insertBefore(h,g.nextSibling);let y=o().cloneOf(g.parentNode);if(y){let A=o().cloneOf(h);A||(A=l.importNode(h,!0),m(h,A));let T=o().cloneOf(g);T?T.after(A):y.appendChild(A)}},identity(a){return u(a)||null},remove(a){let p=u(a),g=o().cloneOf(p);x.remove(p),g&&x.remove(g)},replaceWith(a,p){let g=u(a),h=o().cloneOf(g),y=x.replaceWith(g,p);if(h){let A=J(y,{capability:"data",exclude:t.exclude||null});if(!A.root)h.remove();else{h.replaceWith(A.root);let T=S=>{let O=A.original(S);O&&(c.liveToClone.set(O,S),c.cloneToLive.set(S,O));for(let E of Array.from(S.childNodes||[]))T(E)};T(A.root)}}return y}};return w}var X=x;var ne={extract:(e,t,n={})=>C(M(e,n),e,t,n),apply:(e,t,n,r={})=>I(M(e,{...r,_write:!0}),e,t,n,r),findRulesIn:(e,t)=>j(X,e,t),findRules:(e,t)=>Ae(X,e,t),bind:(e,t,n={})=>{let r=Ae(X,e,t);if(!r){let i=typeof t=="string"?`data-rules-name~="${t}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${i}`)}return{...r,get:()=>C(M(e,n),e,r.rules,n),set:i=>I(M(e,{...n,_write:!0}),e,r.rules,i,n)}},parseStrict:de,parseRelaxed:z,ruleAttrIndex:b,splitRule:le,errors:R,DOM_PROPERTIES:G},Te=e=>!!e&&typeof e.nodeType=="number";function Xe(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=j(X,t,"api");if(!n)throw new R.NoRulesTag("api");return n.rules}function Lt(e){if(e.nodeType===9)return e;let t=e.ownerDocument?.documentElement;if(t?.contains(e))return t;let n=e;for(;n.parentNode;)n=n.parentNode;return n}function jt(e){if(e.nodeType!==11||!e.host)return e.cloneNode(!0);let t=e.ownerDocument.createDocumentFragment();for(let n of e.childNodes)t.appendChild(n.cloneNode(!0));return t}function _t(e,t){let n=[];for(;t!==e;){let r=t.parentNode;n.push(Array.prototype.indexOf.call(r.childNodes,t)),t=r}return n.reverse()}function Dt(e,t){return t.reduce((n,r)=>n.childNodes[r],e)}function _(e,t){let n=e.querySelectorAll?Array.from(e.querySelectorAll(t)):[];return e.matches?.(t)&&n.unshift(e),n}function $t(e,t){let n=_(e,"option"),r=_(t,"option");n.forEach((o,f)=>r[f].selected=o.selected);let i=_(e,"input"),s=_(t,"input");i.forEach((o,f)=>{let u=o.type.toLowerCase();u!=="file"&&(s[f].value=o.value),(u==="checkbox"||u==="radio")&&(s[f].checked=o.checked)});let l=_(e,"textarea"),c=_(t,"textarea");l.forEach((o,f)=>c[f].value=o.value)}function we(e,t){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]"))return;let n=e.startsWith("@")?0:b(e);if(n===-1)return;let r=e.slice(n+1);if($.has(r))throw new R.RuleTargetReadOnly(r);return}if(Array.isArray(e)){if(!Array.isArray(t))return;t.forEach(n=>we(e[1],n));return}if(e&&typeof e=="object"&&t&&typeof t=="object"&&!Array.isArray(t))for(let[n,r]of Object.entries(e))we(r,t[n])}}function Wt(e,t,n){let r={templateAttr:"cms-template"},i=Lt(e),s=_t(i,e),l=jt(i);$t(i,l);let c=Dt(l,s),o=M(l,{...r,_write:!0}),f=ge(o,c,t,n,r);if(f.unknownKeys.length||f.unmatched.length)throw new R.WriteRejected(f.unknownKeys,f.unmatched);let u=te(o);I(u,c,t,n,r),u.assertClean(),we(t,n);let m=te(M(i,{...r,_write:!0}));I(m,e,t,n,r),m.assertClean()}function vt(e){if(!(e instanceof Error))return e;let t=e.name||"Error";try{e.code=t}catch{Object.defineProperty(e,"code",{value:t,configurable:!0,enumerable:!0})}return e instanceof R.WriteRefused?e.details=e.refusals:e instanceof R.WriteRejected?e.details={unknownKeys:e.unknownKeys,unmatched:e.unmatched}:e instanceof R.ShapeMismatch?e.details=e.mismatches:Array.isArray(e.path)?e.details={path:e.path}:typeof e.target=="string"?e.details={target:e.target}:e.token!==void 0?e.details={token:e.token}:e.version!==void 0?e.details={version:e.version}:e.details={},e}function Ge(e,t){let n=Te(e)?e:document,r=Te(e)?t:e;return r===void 0?C(M(n),n,Xe(n)):ne.bind(n,r).get()}function Ye(e,t,n){try{if(!Te(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");let r=n===void 0?Xe(e):ne.bind(e,n).rules;Wt(e,r,t)}catch(r){throw vt(r)}return e}var Bt={engine:ne,extractData:Ge,applyData:Ye},Fn=Bt;export{Ye as applyData,Fn as default,ne as engine,Ge as extractData};
|
|
1
|
+
var lt=Object.defineProperty;var ct=(e,t)=>{for(var n in t)lt(e,n,{get:t[n],enumerable:!0})};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),ce=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),B=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]),be=new Set(["checked","selected","disabled","readOnly","paused"]);function fe(e,t){return t==null?be.has(e)?!1:"":be.has(e)?t==="false"?!1:!!t:t}var R={};ct(R,{EmptyListInsert:()=>C,MAX_RULE_DEPTH:()=>$,MaxRuleDepthExceeded:()=>L,NoRulesTag:()=>ue,RuleTargetReadOnly:()=>V,RulesParseError:()=>j,ShapeMismatch:()=>q,UnknownRulesVersion:()=>H,WriteNotRoundTripped:()=>te,WriteRefused:()=>U,WriteRejected:()=>ae});var j=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},H=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},$=20,L=class extends Error{constructor(t){super(`rule depth exceeded ${$} 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}},C=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}},U=class extends Error{constructor(t){super(`write refused: ${t.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=t}};function ft(e){return e.reduce((n,i)=>typeof i=="number"?`${n}[${i}]`:n?`${n}.${i}`:String(i),"")||"(root)"}var te=class extends Error{constructor(t){super(`write did not round-trip at "${ft(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 N(e){let t=0,n=null,i=-1;for(let r=0;r<e.length;r++){let o=e[r];o==="\\"?r++:n?o===n&&(n=null):o==='"'||o==="'"?n=o:o==="["||o==="("?t++:o==="]"||o===")"?t>0&&t--:o==="@"&&t===0&&(i=r)}return i}var Re="[*]";function b(e){let t=N(e),n=t===-1?e:e.slice(0,t),i=n.endsWith(Re),r={selector:i?n.slice(0,-Re.length):n,prop:t===-1?null:e.slice(t+1)||null};return i&&(r.all=!0),r}function he(e){let t=0,n=null,i=-1,r=!1;for(let o=0;o<e.length;o++){let l=e[o];l==="\\"?o++:n?l===n&&(n=null):l==='"'||l==="'"?n=l:l==="["||l==="("?t++:l==="]"||l===")"?t>0&&t--:t===0&&l===">"?i=o:t===0&&l===","&&(r=!0)}return r||i===-1||!ut(e,i+1)?null:e.slice(0,i).trim()||null}function ut(e,t){let n=t,i=e.replace(/\s+$/,"").length;for(;n<i&&/\s/.test(e[n]);)n++;let r=0,o=null;for(;n<i;n++){let l=e[n];if(l==="\\")n++;else if(o)l===o&&(o=null);else if(l==='"'||l==="'")o=l;else if(l==="["||l==="(")r++;else if(l==="]"||l===")")r>0&&r--;else if(r===0&&(l==="+"||l==="~"||/\s/.test(l)))return!1}return!0}var at=/^--[A-Za-z0-9_-]+$/;function P(e){return typeof e=="string"&&at.test(e)}function Ne(e){let t=[],n=[],i=null,r=0;for(let o=0;o<e.length;o++){let l=e[o];if(i){l==="\\"?o++:l===i&&(i=null);continue}if(l==="/"&&e[o+1]==="*"){let c=e.indexOf("*/",o+2);o=c===-1?e.length:c+1;continue}l==='"'||l==="'"?i=l:l==="("?n.push(")"):l==="["?n.push("]"):l==="{"?n.push("}"):(l===")"||l==="]"||l==="}")&&n[n.length-1]===l?n.pop():l===";"&&n.length===0&&(t.push(e.slice(r,o)),r=o+1)}return t.push(e.slice(r)),t}function ht(e){let t="",n=null;for(let i=0;i<e.length;i++){let r=e[i];if(n){t+=r,r==="\\"&&i+1<e.length?t+=e[++i]:r===n&&(n=null);continue}if(r==="/"&&e[i+1]==="*"){let o=e.indexOf("*/",i+2);i=o===-1?e.length:o+1,t+=" ";continue}(r==='"'||r==="'")&&(n=r),t+=r}return t}function Ce(e){e=ht(e);let t=e.indexOf(":");if(t===-1)return null;let n=e.slice(0,t).trim(),i=e.slice(t+1).trim(),r=/!\s*important\s*$/i.exec(i);return r&&(i=i.slice(0,r.index).trim()),{name:n,value:i,important:!!r}}function _(e,t){if(e==null)return null;let n=null;for(let i of Ne(String(e))){let r=Ce(i);!r||r.name!==t||(!n||r.important||!n.important)&&(n=r)}return n?n.value:null}function Pe(e,t,n){let i=e==null?"":String(e),r=n==null||n==="",o=Ne(i),l=o.map(Ce),c=l.some(h=>h&&h.name===t&&h.important),s=[],f=!1;o.forEach((h,p)=>{let T=l[p];if(!T||T.name!==t){s.push(h);return}if(r||f)return;let a=/^\s*/.exec(h)[0];s.push(`${a}${t}: ${n}${c?" !important":""}`),f=!0});let u=s.join(";");if(!r&&!f){let h=u.trimEnd();u=h===""?`${t}: ${n}`:`${h}${h.endsWith(";")?" ":"; "}${t}: ${n}`}return u.trim()===""?null:u}function ne(e,t,n,i){let r=e.attr(t,"style");if((_(r,n)??"")===i)return;let o=Pe(r,n,i);o==null?e.removeAttr(t,"style"):e.attr(t,"style",o)}function M(e,t,n,i={}){if(Object.prototype.hasOwnProperty.call(i,"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:[]},i)}function pe(e,t,n,i,r){if(i.depth>$)throw new L(i.path);if(typeof n=="string")return dt(e,t,n,i,r);if(Array.isArray(n)){let[o,l]=n,c=e.find(t,o,r);return Me(r,i,c),c.map((s,f)=>pe(e,s,l,{depth:i.depth+1,path:[...i.path,f]},r))}if(typeof n=="object"&&n!==null){let o={};for(let[l,c]of Object.entries(n))o[l]=pe(e,t,c,{depth:i.depth+1,path:[...i.path,l]},r);return o}return null}function dt(e,t,n,i,r){if(n.endsWith("[]")){let f=n.slice(0,-2),u=e.find(t,f,r);return Me(r,i,u),u.map(h=>e.text(h))}if(n.startsWith("@"))return de(e,t,n.slice(1));let o=N(n);if(o!==-1){let{selector:f,all:u}=b(n),h=n.slice(o+1),p=f?e.find(t,f,r):[t];return u&&r.allMatches?p.map(T=>de(e,T,h)):p.length===0?null:de(e,p[0],h)}if(n===".")return e.text(t);let{selector:l,all:c}=b(n),s=e.find(t,l,r);return c&&r.allMatches?s.map(f=>e.text(f)):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(i){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,i)}}function de(e,t,n){if(P(n))return _(e.attr(t,"style"),n);if(ee.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let i=e.attr(t,n);return i??null}function Ie(e,t,n,i){let r=e.length,o=t.length,l=new Array(r).fill(-1);if(i){let d=new Set;for(let y=0;y<r;y++){let A=i[y];!(A>=0&&A<o)||d.has(A)||(l[y]=A,d.add(A))}}if(r===0||o===0)return l;let c=e.map(d=>ke(d,n)),s=t.map(d=>ke(d,n)),f=new Array(o).fill(!1);for(let d of l)d>=0&&(f[d]=!0);let u=new Map;s.forEach((d,y)=>{f[y]||u.set(d,u.has(d)?-1:y)});let h=new Map;c.forEach((d,y)=>{l[y]>=0||h.set(d,(h.get(d)||0)+1)}),c.forEach((d,y)=>{if(l[y]>=0||h.get(d)!==1)return;let A=u.get(d);A===void 0||A===-1||f[A]||(l[y]=A,f[A]=!0)});let p=[];for(let d=0;d<r;d++)l[d]<0&&p.push(d);let T=[];for(let d=0;d<o;d++)f[d]||T.push(d);if(p.length===0||T.length===0)return l;let a=r*o+1,m=pt(e,t,n),g=(d,y)=>m(d,y)*a+Math.abs(d-y);for(let[d,y]of mt(p,T,g))l[d]=y;return l}var je=e=>typeof e=="object"&&e!==null;function ke(e,t){if(!je(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(i=>{let r=JSON.stringify(e?.[i]);return r===void 0?" undef":r}))}function pt(e,t,n){if(!je(n))return(c,s)=>e[c]===t[s]?0:1;let i=Object.keys(n),r=c=>i.map(s=>JSON.stringify(c?.[s])),o=e.map(r),l=t.map(r);return(c,s)=>{let f=o[c],u=l[s],h=0;for(let p=0;p<i.length;p++)f[p]!==u[p]&&h++;return h}}function mt(e,t,n){return e.length<=t.length?Le(e,t,n,!1):Le(t,e,(i,r)=>n(r,i),!0)}function Le(e,t,n,i){let r=e.length,o=t.length,l=[];for(let h=0;h<=r;h++)l.push(new Float64Array(o+1).fill(1/0));let c=[];for(let h=0;h<=r;h++)c.push(new Uint8Array(o+1));for(let h=0;h<=o;h++)l[r][h]=0;for(let h=r-1;h>=0;h--)for(let p=o-1;p>=0;p--){let T=n(e[h],t[p])+l[h+1][p+1],a=l[h][p+1];T<=a?(l[h][p]=T,c[h][p]=1):l[h][p]=a}let s=[],f=0,u=0;for(;f<r&&u<o;)c[f][u]&&(s.push(i?[t[u],e[f]]:[e[f],t[u]]),f++),u++;return s}function ye(e,t,n,i,r,o,l,c={}){let s=e.find(t,n,c);if(r.length===0){s.forEach(w=>e.remove(w)),me(c,"onRowsApplied",o.path,[]);return}let f=r.length>s.length,u=s[0]||null;if(f&&!u&&(u=Tt(e,t,n,c),!u))throw new C(o.path);let h=s.map(w=>At(e,w,i,c)),p=null;if(f&&u){p=e.clone(u),c.templateAttr&&e.removeAttr(p,c.templateAttr);let w=e.stripIds(p);w>0&&console.warn(`[hyper-html-api] stripped ${w} id attribute(s) from cloned template at "${o.path.join(".")||"(root)"}"`)}let T=Ie(r,h,i,yt(e,s,r,o,c)),a=s.length>0?e.parent(s[0]):St(e,t,n,u,o,c),m=s.length>0?ve(e,a,s[0]):0,g=Rt(e,s),d=new Set,y=[],A=r.map((w,x)=>{let O=T[x];if(O>=0)return d.add(O),y.push(!1),s[O];y.push(!0);let E=e.clone(p);return e.stripIds(E),E});s.forEach((w,x)=>{d.has(x)||e.remove(w)}),g?bt(e,a,m,A,y):Nt(e,A,y,a,m),gt(e,A,i,r,o,l,c),me(c,"onRowsApplied",o.path,A)}function me(e,t,n,i){if(typeof e[t]=="function")try{return e[t](n.slice(),i)}catch(r){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,r);return}}function yt(e,t,n,i,r){let o=me(r,"identifyRows",i.path,n);if(!Array.isArray(o))return null;let l=new Array(n.length).fill(-1),c=new Set,s=new Map(t.map((f,u)=>[e.identity(f),u]));for(let f=0;f<n.length;f++){if(!o[f])continue;let u=s.get(e.identity(o[f]));u===void 0||c.has(u)||(l[f]=u,c.add(u))}return l}function gt(e,t,n,i,r,o,l){t.forEach((c,s)=>{if(n===null){let f=i[s],u=f==null?"":String(f);e.text(c)!==u&&e.text(c,u)}else{let f=o(e,c,n,i[s],{depth:r.depth+1,path:[...r.path,s]},l);f&&f!==c&&(t[s]=f)}})}function At(e,t,n,i){return n===null?e.text(t):M(e,t,n,i.onRowsRead?{...i,onRowsRead:void 0}:i)}function ve(e,t,n){let i=e.children(t);for(let r=0;r<i.length;r++)if(e.sameNode(i[r],n))return r;return-1}function Tt(e,t,n,i){if(!i.templateAttr)return null;let r=/^\s*:scope\s*>\s*/.test(n),o=new RegExp(":not\\(\\["+i.templateAttr.replace(/[.*+?^${}()|[\]\\-]/g,"\\$&")+"\\]\\)","g"),l=n.replace(/^\s*:scope\s*>\s*/,"").replace(o,""),c=r?wt(l):0,s=he(l),f=t;for(;f;){let u=e.find(f,l,{includeRulesTag:!1,templateAttr:null});for(let h of u)if(e.attr(h,i.templateAttr)!=null&&!(r&&!Ot(e,t,h,c))&&!(s&&!e.matches(e.parent(h),s)))return h;f=e.parent(f)}return null}function wt(e){let t=0,n=null,i=1;for(let r=0;r<e.length;r++){let o=e[r];if(o==="\\")r++;else if(n)o===n&&(n=null);else if(o==='"'||o==="'")n=o;else if(o==="["||o==="(")t++;else if(o==="]"||o===")")t>0&&t--;else if(t===0&&o===">")i++;else{if(t===0&&(o==="+"||o==="~"))return null;if(t===0&&/\s/.test(o)){if(!Et(e,r))return null;for(;r+1<e.length&&/\s/.test(e[r+1]);)r++}}}return i}function Et(e,t){let n=t;for(;n<e.length&&/\s/.test(e[n]);)n++;let i=t>0?e[t-1]:"",r=n<e.length?e[n]:"";return $e(i)||$e(r)}function $e(e){return e===">"||e==="+"||e==="~"}function Ot(e,t,n,i){if(i===null)return!0;let r=n;for(let s=0;s<i;s++)if(r=e.parent(r),!r)return!1;let o=e.prop(t,"tagName");if(!o)return!0;let l=e.prop(r,"tagName");if(!l||String(l).toLowerCase()!==String(o).toLowerCase())return!1;let c=new Set(_e(e,r));return _e(e,t).every(s=>c.has(s))}function _e(e,t){let n=e.attr(t,"class");return n?String(n).split(/\s+/).filter(Boolean):[]}function St(e,t,n,i,r,o){let l=e.parent(i);if(l&&xt(e,t,l)&&!We(e,l,o))return l;let c=he(n);if(!c)throw new C(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 f=(c===":scope"?e.prop(t,"tagName")?[t]:[]:e.find(t,c,o)).filter(u=>!We(e,u,o));if(f.length===0)throw new C(r.path,`no container matching "${c}" inside this context to hold the new rows`);if(f.length>1)throw new C(r.path,`"${c}" matches ${f.length} containers inside this context, so the new rows have no single destination`);return f[0]}function xt(e,t,n){let i=n;for(;i;){if(e.sameNode(i,t))return!0;i=e.parent(i)}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 We(e,t,n){let i=t;for(;i;){if(n.templateAttr&&e.attr(i,n.templateAttr)!=null||De.some(o=>e.attr(i,o)!=null))return!0;let r=e.attr(i,"clay");if(r&&r.split(/\s+/).some(o=>De.includes(o)))return!0;i=e.parent(i)}return!1}function bt(e,t,n,i,r){let o=e.children(t),l=o.map(s=>e.identity(s)),c=!1;i.forEach((s,f)=>{let u=e.identity(s),h=n+f;if(l[h]===u)return;if(!r[f]){let T=l.indexOf(u);T!==-1&&(l.splice(T,1),o.splice(T,1))}let p=Math.min(h,o.length);p<o.length?e.insertBefore(o[p],s):o.length?c?e.insertAfter(o[o.length-1],s):(e.insertAt(t,s,h),c=!0):e.insertAt(t,s,0),l.splice(p,0,u),o.splice(p,0,s)})}function Rt(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let i=new Map(e.children(n).map((o,l)=>[e.identity(o),l])),r=[];for(let o of t){let l=i.get(e.identity(o));if(l===void 0)return!1;r.push(l)}return r.sort((o,l)=>o-l),r[r.length-1]-r[0]===r.length-1}function Nt(e,t,n,i,r){let o=null,l=r;for(let c=0;c<t.length;c++){if(!n[c]){o=t[c];continue}let s=o?e.parent(o):i;if(!s)continue;let f=o?ve(e,s,o)+1:l++;e.insertAt(s,t[c],f),o=t[c]}}function I(e,t,n,i,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 o=[];if(ge(n,i,[],o),o.length)throw new q(o);re(e,t,n,i,{depth:0,path:[]},r)}function re(e,t,n,i,r,o={}){if(r.depth>$)throw new L(r.path);if(i===void 0)return t;if(typeof n=="string")return Ct(e,t,n,i,r,o);if(Array.isArray(n)){let[l,c]=n;return ye(e,t,l,c,i,r,re,o),t}if(typeof n=="object"&&n!==null){for(let[l,c]of Object.entries(n)){let s=re(e,t,c,i==null?i:i[l],{depth:r.depth+1,path:[...r.path,l]},o);s&&s!==t&&(t=s)}return t}return t}function Ct(e,t,n,i,r,o){if(n.endsWith("[]")){let u=n.slice(0,-2);return ye(e,t,u,null,i,r,re,o),t}if(n.startsWith("@"))return He(e,t,n.slice(1),i);let l=N(n);if(l!==-1){let{selector:u,all:h}=b(n),p=n.slice(l+1),T=u?e.find(t,u,o):[t];for(let a of h?T:T.slice(0,1))He(e,a,p,i);return t}if(n===".")return Be(e,t,i),t;let{selector:c,all:s}=b(n),f=e.find(t,c,o);for(let u of s?f:f.slice(0,1))Be(e,u,i);return t}function Be(e,t,n){let i=n==null?"":String(n);e.text(t)!==i&&e.text(t,i)}function Pt(e,t,n,i){if(e.styleVar){e.styleVar(t,n,i);return}ne(e,t,n,i)}function He(e,t,n,i){if(P(n))return Pt(e,t,n,i==null?"":String(i).trim()),t;if(B.has(n)){let r=e.prop(t,n);if(r===i||r!=null&&i!=null&&String(r)===String(i))return t;throw new V(n)}if(n==="outerHTML"){let r=i==null?"":String(i);return e.replaceWith(t,r)}if(ce.has(n)){let r=fe(n,i);return e.prop(t,n)!==r&&e.prop(t,n,r),t}if(i==null)e.attr(t,n)!=null&&e.removeAttr(t,n);else{let r=String(i);e.attr(t,n)!==r&&e.attr(t,n,r)}return t}function ge(e,t,n,i){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((r,o)=>{typeof r=="object"&&r!==null&&i.push({path:F([...n,o]),expected:"scalar",got:z(r)})}):i.push({path:F(n),expected:"array",got:z(t)});return}t!==null&&typeof t=="object"&&i.push({path:F(n),expected:"scalar",got:z(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){i.push({path:F(n),expected:"array",got:z(t)});return}let r=e[1];t.forEach((o,l)=>ge(r,o,[...n,l],i));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){i.push({path:F(n),expected:"object",got:z(t)});return}for(let[r,o]of Object.entries(e))ge(o,t[r],[...n,r],i)}}}function z(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function F(e){return e.join(".")}function Ae(e){try{return JSON.parse(e)}catch(t){throw new j(`Invalid strict JSON: ${t.message}`,t)}}function K(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 o=[],l=0;for(;l<r.length;){let c=r[l];if(/\s/.test(c)){l++;continue}if("{}".includes(c)){o.push({type:c,value:c}),l++;continue}if(c==="["){let h=!1,p=l+1;for(;p<r.length&&/\s/.test(r[p]);)p++;if(p<r.length&&/[a-zA-Z_]/.test(r[p])&&(h=!0),!h){o.push({type:c,value:c}),l++;continue}}if(c==="]"){o.push({type:c,value:c}),l++;continue}if(c===":"){o.push({type:t.COLON,value:c}),l++;continue}if(c===","){o.push({type:t.COMMA,value:c}),l++;continue}if(c==='"'||c==="'"){let h=c,p=l+1;for(;p<r.length&&r[p]!==h;)r[p]==="\\"&&p++,p++;o.push({type:t.STRING,value:r.substring(l+1,p),quoted:!0,sourceQuote:h}),l=p+1;continue}let s=l,f;for(;s<r.length&&!/[{},]/.test(r[s]);)if(r[s]===":"){let h=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],p=!1;for(let T of h){let a=T.substring(1);if(r.substring(s+1,s+1+a.length)===a){p=!0,s+=a.length;break}}if(!p)break}else if(r[s]==="["){for(s++;s<r.length&&r[s]!=="]";){if(r[s]==='"'||r[s]==="'"){let h=r[s];for(s++;s<r.length&&r[s]!==h;)r[s]==="\\"&&s++,s++}s++}s<r.length&&r[s]==="]"&&s++}else s++;f=r.substring(l,s);let u=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(f)?u=t.NUMBER:f==="true"||f==="false"||f==="null"?u=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(f)&&(u=t.SELECTOR),o.push({type:u,value:f,quoted:!1}),l=s}return o}function i(r){let o="";for(let l=0;l<r.length;l++){let c=r[l];if("{}".includes(c.type)||"[]".includes(c.type)){o+=c.value;continue}if(c.type===t.COLON){o+=c.value;continue}if(c.type===t.COMMA){let s=r[l+1];if(s&&(s.type==="}"||s.type==="]"))continue;o+=c.value;continue}if(c.type===t.STRING&&c.quoted){let s=c.value;c.sourceQuote==="'"&&(s=s.replace(/\\'/g,"'"),s=s.replace(/(\\*)"/g,(f,u)=>u.length%2===0?u+'\\"':f)),o+=`"${s}"`;continue}if(c.type===t.NUMBER||c.type===t.BOOLEAN){o+=c.value;continue}if(c.type===t.SELECTOR||c.type===t.IDENTIFIER){o+=`"${c.value}"`;continue}o+=`"${c.value}"`}return o}try{let r=n(e),o=i(r);return JSON.parse(o)}catch(r){throw new j("Invalid extraction rules syntax: "+r.message,r)}}var Mt="1",qe=/^[a-zA-Z0-9_-]+$/;function D(e,t,n){let i;if(n===void 0)i="script[data-rules-name]";else{if(typeof n!="string"||!qe.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${qe})`);i=`script[data-rules-name~="${n}"]`}let r=e.find(t,i,{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 o=r[0],l=e.attr(o,"data-rules-version");if(l!==Mt)throw new H(l);return{rules:K(e.text(o)),tagNode:o}}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"]})}),kt=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),Ve=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 Te(e,t){if(J(e,t))return!0;for(let[n,i]of Object.entries(kt))if(i.includes(t)&&J(e,n))return!0;return!1}function X(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 Lt(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let i=ie[t];if(!i)throw new Error(`Unknown region capability: ${t}`);if(i.tokens.some(r=>Te(n,r))||i.bundles.some(r=>J(n,r)))return n;n=n.parentElement}return null}function Ue(e,t){return!!Lt(e,t)}var oe=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",...Ve],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"]})}),It=new Set(["textContent","innerText"]);function ze(e){let n=String(e).replace(/^[\u0000- ]+|[\u0000- ]+$/g,"").replace(/[\t\n\r]/g,"").match(/^([a-zA-Z][a-zA-Z0-9+.-]*):/);return n?n[1].toLowerCase():null}var jt=/^[^\t\n\f\r "'>/=\u0000-\u001f\u007f]+$/;function Fe(e,t,n=oe){if(!jt.test(String(e)))return`attribute name ${JSON.stringify(String(e))} is not valid`;let i=String(e).toLowerCase();if(n.refusedAttributePrefixes.some(r=>i.startsWith(r)))return`attribute "${i}" can run script`;if(n.refusedAttributes.includes(i))return`attribute "${i}" is not content`;if(n.urlAttributes.includes(i)&&t!=null){let r=i==="srcset"?String(t).split(",").map(o=>o.trim().split(/\s+/)[0]).filter(Boolean):[String(t)];for(let o of r){let l=ze(o);if(l&&n.refusedSchemes.includes(l))return`"${l}:" URLs are not allowed in "${i}"`}}return null}function we(e,t){let n=e.prop(t,"tagName");return n?String(n).toLowerCase():""}function $t(e,t){let n=we(e,t)||"node",i=e.attr(t,"id");return i?`<${n}#${i}>`:`<${n}>`}function _t(e,t,n){let i=t;for(;i;){let r=we(e,i);if(r&&n.refusedTargets.includes(r))return r;i=e.parent(i)}return null}function Ke(e,t){return e.find(t,"script[data-rules-name]",{includeRulesTag:!0,templateAttr:null}).length>0}function Dt(e,t){return we(e,t)==="script"&&e.attr(t,"data-rules-name")!=null?!0:Ke(e,t)}function Wt(e){if(/[\u0000-\u001f\u007f]/.test(e))return"control characters are not allowed in a custom property value";let t=[],n=null;for(let i=0;i<e.length;i++){let r=e[i];if(n){r===n&&(n=null);continue}if(r==='"'||r==="'")n=r;else{if(r==="/"&&e[i+1]==="*")return"comments are not allowed in a custom property value";if(r==="(")t.push(")");else if(r==="[")t.push("]");else if((r===")"||r==="]")&&t.pop()!==r)return`"${r}" does not close anything in this custom property value`}}return n?"a custom property value must close its quotes":t.length?"a custom property value must close its brackets":null}function Je(e,t=oe){let n=t.customPropertyValues,i=String(e);if(i.length>n.maxLength)return`custom property values are limited to ${n.maxLength} characters`;let r=n.refusedCharacters.find(s=>i.includes(s));if(r)return`${JSON.stringify(r)} is not allowed in a custom property value`;let o=Wt(i);if(o)return o;let l=i.toLowerCase(),c=n.refusedFunctions.find(s=>new RegExp(`(^|[^a-z0-9_-])${s.replace(/[-]/g,"\\-")}\\s*\\(`).test(l));return c?`"${c}()" is not allowed in a custom property value`:null}function se(e,t=oe){let n=[],i=(s,f)=>(n.push({target:$t(e,s),reason:f}),!1),r=s=>{let f=_t(e,s,t);return f?i(s,`inside <${f}>, which is not content`):!0},o=s=>r(s)?Ke(e,s)?i(s,"a text write here would delete the data rules tag"):!0:!1,l=(s,f,u)=>{if(!r(s))return!1;let h=Fe(f,u,t);return h?i(s,h):!0};return{...e,text(s,f){if(f===void 0)return e.text(s);o(s)&&e.text(s,f)},attr(s,f,u){if(u===void 0)return e.attr(s,f);l(s,f,u)&&e.attr(s,f,u)},removeAttr(s,f){l(s,f,null)&&e.removeAttr(s,f)},styleVar(s,f,u){if((_(e.attr(s,"style"),f)??"")!==u&&r(s)){if(!P(f))return i(s,`"${f}" is not a custom property`);if(u!==""){let h=Je(u,t);if(h)return i(s,h)}ne(e,s,f,u)}},prop(s,f,u){if(u===void 0)return e.prop(s,f);if(t.refusedRuleForms.includes(f))return i(s,`"@${f}" writes HTML, only text is allowed`);if(It.has(f)){o(s)&&e.prop(s,f,u);return}l(s,f==="className"?"class":f,u)&&e.prop(s,f,u)},remove(s){if(Dt(e,s)){i(s,"removing this would delete the data rules tag");return}e.remove(s)},replaceWith(s,f){return f===e.prop(s,"outerHTML")||i(s,'"@outerHTML" writes HTML, only text is allowed'),s},refusals:n,assertClean(){if(n.length)throw new U(n.slice())}}}function Y(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Xe(e){return e.reduce((t,n)=>typeof n=="number"?`${t}[${n}]`:t?`${t}.${n}`:n,"")}function Ee(e,t,n,i,r={}){let o=[],l=[];function c(f,u,h){if(Array.isArray(f)){let[,p]=f;if(!Array.isArray(u)||!Y(p))return;u.forEach((T,a)=>c(p,T,[...h,a]));return}if(!(!Y(f)||!Y(u)))for(let p of Object.keys(u))Object.prototype.hasOwnProperty.call(f,p)?c(f[p],u[p],[...h,p]):o.push(Xe([...h,p]))}function s(f,u,h,p){if(h!==void 0){if(typeof u=="string"){if(u.endsWith("[]")||u==="."||u.startsWith("@"))return;let{selector:T}=b(u);if(!T)return;e.find(f,T,r).length===0&&l.push({path:Xe(p),selector:T});return}if(!Array.isArray(u)&&Y(u)&&Y(h))for(let[T,a]of Object.entries(u))s(f,a,h[T],[...p,T])}}return c(n,i,[]),s(t,n,i,[]),{unknownKeys:o,unmatched:l}}function Oe(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let i=t&&t.ownerDocument?t.ownerDocument:t;return D(e,i,n)}return null}var Bt=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function Ht(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 Ye(e,t,n,i){if(i)return!!e.closest?.(t);let r=e;for(;r?.nodeType===1;){if(r.matches(t))return!0;if(r===n)break;r=r.parentElement}return!1}function Ge(e,t,n,i,r,o){return(o?Ue(e,t):Ye(e,n,r,!1))||!!(i&&(o&&e!==r?e.matches(i):Ye(e,i,r,o)))}function qt(e,t){let n=ie[t];return n.tokens.some(i=>Te(e,i))||n.bundles.some(i=>J(e,i))}var Vt=new Set(["INPUT","TEXTAREA","SELECT","OPTION"]);function Ze(e,t,n,i){if(e.nodeType===1&&i(e)){n.dropped.push(t);return}n.cloneToLive.set(t,e),n.liveToClone.set(e,t);let r=e,o=t;if(e.nodeType===1){if(Vt.has(e.tagName)&&n.controls.push(e,t),e.tagName==="TEMPLATE"){for(;t.firstChild;)t.removeChild(t.firstChild);r=e.content,o=t.content,n.cloneToLive.set(o,r),n.liveToClone.set(r,o)}}else if(e.nodeType!==11)return;let l=o.firstChild;for(let c=r.firstChild;c&&l;c=c.nextSibling)Ze(c,l,n,i),l=l.nextSibling}function G(e,{capability:t="data",exclude:n=null,inherit:i=!0,provenance:r=null}={}){if(!e)throw new TypeError("createContentView requires a DOM context");let o=e.nodeType===9?e:e.ownerDocument;if(!o?.implementation?.createHTMLDocument)throw new TypeError("createContentView requires an HTML DOM implementation");let l=o.implementation.createHTMLDocument(""),c=r||new WeakMap,s=new WeakMap,f=e.nodeType===9?e.documentElement:e;n&&l.documentElement.matches(n);let u=X(t),h=i?a=>qt(a,t)||!!(n&&a.matches(n)):a=>Ge(a,t,u,n,f,!1),p=null;if(f.nodeType!==1||!Ge(f,t,u,n,f,i)){p=l.importNode(f,!0);let a={cloneToLive:c,liveToClone:s,dropped:[],controls:[]};Ze(f,p,a,h);for(let m of a.dropped)m.remove();for(let m=0;m<a.controls.length;m+=2)Ht(a.controls[m],a.controls[m+1])}e.nodeType===9&&p&&(l.replaceChild(p,l.documentElement),s.set(e,l),c.set(l,e));let T=a=>{if(Bt.test(a))throw new Error(`Filtered content queries do not support stateful selector: ${a}`)};return{root:p,document:l,capability:t,selector:X(t),cloneToLive:c,liveToClone:s,original(a){return c.get(a)||null},cloneOf(a){return s.get(a)||null},query(a,m=p){return T(a),Array.from(m.querySelectorAll(a),g=>c.get(g)||g)},text(a=p){return(a===p?p:s.get(a))?.textContent||""},html(a=p){return(a===p?p:s.get(a))?.innerHTML??""},clone(a=p){let m=a===p?p:s.get(a);return m?l.importNode(m,!0):null}}}function et(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 Qe(e,t,n){!e||e.nodeType!==1||(t==="value"&&e.tagName==="INPUT"?e.value=n===null?"":n:t==="checked"&&e.tagName==="INPUT"?e.checked=n!==null:t==="selected"&&e.tagName==="OPTION"&&(e.selected=n!==null))}function tt(e,t){e&&e.tagName==="TEXTAREA"&&(e.value=t)}function nt(e){if(!e||e.nodeType!==1)return;let t=[e,...e.querySelectorAll?e.querySelectorAll("textarea, input, option"):[]];for(let n of t)if(n.tagName==="TEXTAREA")n.value=n.defaultValue;else if(n.tagName==="INPUT"){let i=n.type;i!=="file"&&i!=="checkbox"&&i!=="radio"&&(n.value=n.defaultValue),n.checked=n.defaultChecked}else n.tagName==="OPTION"&&(n.selected=n.defaultSelected)}var S={semanticExclude:!0,find(e,t,n={}){let i=Ut(e);if(!i||!i.querySelectorAll)return[];let r=Array.from(i.querySelectorAll(t));n.includeRulesTag||(r=r.filter(c=>!et(c)));let o=[];n.skip&&o.push(n.skip);let l=n.templateAttr===null?null:n.templateAttr||"cms-template";if(l&&o.push("["+l+"]"),o.length){let c=o.join(", ");r=r.filter(s=>!s.closest||!s.closest(c))}return r},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},matches(e,t){return!!(e&&e.matches)&&e.matches(t)},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t,tt(e,t)},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n),Qe(e,t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t),Qe(e,t,null)},prop(e,t,n){if(n===void 0){let i=e?e[t]:void 0;return i!==void 0?i:null}e[t]=n},clone(e){let t=e.cloneNode(!0);return nt(t),t},insertAt(e,t,n){let i=e.children[n]||null;e.insertBefore(t,i)},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 i=e.ownerDocument.createElement("template");i.innerHTML=t;let r=i.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(i=>{i.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};function k(e,t={}){if(t.exclude===null)return S;let n=[X("data"),t.exclude].filter(Boolean).join(", "),i=e.nodeType===9?e:e.ownerDocument||e,r=e.nodeType===9?e.documentElement:e;if(!t._write&&!r?.matches?.(n)&&!r?.querySelector?.(n)&&!i?.querySelector?.(n))return S;let o=e.nodeType===9||!e.isConnected?e:e.ownerDocument,l=e.nodeType===9?e:e.ownerDocument,c=null,s=()=>c||(c=G(o,{capability:"data",exclude:t.exclude||null})),f=a=>{let m=s();return a===e?m.cloneOf(e):m.cloneOf(a)||a},u=a=>c?.original(a)||a,h=(a,m)=>{s().liveToClone.set(a,m),s().cloneToLive.set(m,a);let g=a.childNodes||[],d=m.childNodes||[];for(let y=0;y<Math.min(g.length,d.length);y++)h(g[y],d[y])},p=(a,m,g,d)=>{let y=Array.from(a.childNodes).filter(E=>c.cloneOf(E)),w=y[0];for(;w&&y.includes(w);)w=w.nextSibling;for(let E of y)E.remove();if(g==="innerHTML"){let E=l.createElement("template");E.innerHTML=d;for(let v of Array.from(E.content.childNodes))a.insertBefore(v,w||null)}else a.insertBefore(l.createTextNode(d),w||null),tt(a,d);let x=G(a,{capability:"data",exclude:t.exclude||null});m.replaceChildren(...Array.from(x.root?.childNodes||[]));let O=E=>{let v=x.original(E);v&&(c.liveToClone.set(v,E),c.cloneToLive.set(E,v));for(let st of Array.from(E.childNodes||[]))O(st)};for(let E of Array.from(m.childNodes))O(E)},T={...S,find(a,m,g={}){let d=f(a);if(!d?.querySelectorAll)return[];let y=s().query(m,d);g.includeRulesTag||(y=y.filter(x=>!et(x)));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 x=A.join(", ");y=y.filter(O=>!O.closest?.(x))}return y},parent(a){let m=f(a)?.parentElement;return m?u(m):null},children(a){return Array.from(f(a)?.children||[],u)},text(a,m){if(m===void 0){let y=u(a);return!y?.matches?.(n)&&!y?.querySelector?.(n)?S.text(y):(f(a)?.textContent||"").trim()}let g=u(a);if(!g?.matches?.(n)&&!g?.querySelector?.(n)&&!c){S.text(g,m);return}let d=s().cloneOf(g);d?p(g,d,"textContent",m):S.text(g,m)},attr(a,m,g){let d=u(a);if(g===void 0)return S.attr(d,m);S.attr(d,m,g);let y=c?.cloneOf(d);y&&(S.attr(y,m,g),G(d,{capability:"data",exclude:t.exclude||null}).root===null&&(y.remove(),c.liveToClone.delete(d),c.cloneToLive.delete(y)))},removeAttr(a,m){let g=u(a);S.removeAttr(g,m);let d=c?.cloneOf(g);d&&S.removeAttr(d,m)},prop(a,m,g){let d=u(a);if(g===void 0)return m==="innerHTML"||m==="outerHTML"||m==="textContent"||m==="innerText"?S.prop(f(d),m):S.prop(d,m);let y=m==="innerHTML"||m==="textContent"||m==="innerText",A=y?s().cloneOf(d):c?.cloneOf(d);A&&y?p(d,A,m,g):(S.prop(d,m,g),A&&S.prop(A,m,g))},clone(a){let m=f(a);if(m===a)return S.clone(a);let g=l.importNode(m,!0);return nt(g),g},insertAt(a,m,g){let d=u(a),A=T.children(d)[g]||(()=>{for(let O=d.children.length-1;O>=0;O--){let E=d.children[O];if(s().cloneOf(E))return E.nextElementSibling}return d.firstElementChild})(),w=u(m);d.insertBefore(w,A||null);let x=s().cloneOf(d);if(x){let O=s().cloneOf(w);O||(O=l.importNode(w,!0),h(w,O));let E=Array.from(x.children);x.insertBefore(O,E[g]||null)}},insertBefore(a,m){let g=u(a),d=u(m);g.parentNode.insertBefore(d,g);let y=s().cloneOf(g.parentNode);if(y){let A=s().cloneOf(d);A||(A=l.importNode(d,!0),h(d,A));let w=s().cloneOf(g);w?w.before(A):y.appendChild(A)}},insertAfter(a,m){let g=u(a),d=u(m);g.parentNode.insertBefore(d,g.nextSibling);let y=s().cloneOf(g.parentNode);if(y){let A=s().cloneOf(d);A||(A=l.importNode(d,!0),h(d,A));let w=s().cloneOf(g);w?w.after(A):y.appendChild(A)}},identity(a){return u(a)||null},remove(a){let m=u(a),g=s().cloneOf(m);S.remove(m),g&&S.remove(g)},replaceWith(a,m){let g=u(a),d=s().cloneOf(g),y=S.replaceWith(g,m);if(d){let A=G(y,{capability:"data",exclude:t.exclude||null});if(!A.root)d.remove();else{d.replaceWith(A.root);let w=x=>{let O=A.original(x);O&&(c.liveToClone.set(O,x),c.cloneToLive.set(x,O));for(let E of Array.from(x.childNodes||[]))w(E)};w(A.root)}}return y}};return T}var Z=S;var le={extract:(e,t,n={})=>M(k(e,n),e,t,n),apply:(e,t,n,i={})=>I(k(e,{...i,_write:!0}),e,t,n,i),findRulesIn:(e,t)=>D(Z,e,t),findRules:(e,t)=>Oe(Z,e,t),bind:(e,t,n={})=>{let i=Oe(Z,e,t);if(!i){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{...i,get:()=>M(k(e,n),e,i.rules,n),set:r=>I(k(e,{...n,_write:!0}),e,i.rules,r,n)}},parseStrict:Ae,parseRelaxed:K,ruleAttrIndex:N,splitRule:b,errors:R,DOM_PROPERTIES:Q},Se=e=>!!e&&typeof e.nodeType=="number";function rt(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=D(Z,t,"api");if(!n)throw new R.NoRulesTag("api");return n.rules}function zt(e){if(e.nodeType===9)return e;let t=e.ownerDocument?.documentElement;if(t?.contains(e))return t;let n=e;for(;n.parentNode;)n=n.parentNode;return n}function Ft(e){if(e.nodeType!==11||!e.host)return e.cloneNode(!0);let t=e.ownerDocument.createDocumentFragment();for(let n of e.childNodes)t.appendChild(n.cloneNode(!0));return t}function Kt(e,t){let n=[];for(;t!==e;){let i=t.parentNode;n.push(Array.prototype.indexOf.call(i.childNodes,t)),t=i}return n.reverse()}function Jt(e,t){return t.reduce((n,i)=>n.childNodes[i],e)}function W(e,t){let n=e.querySelectorAll?Array.from(e.querySelectorAll(t)):[];return e.matches?.(t)&&n.unshift(e),n}function Xt(e,t){let n=W(e,"option"),i=W(t,"option");n.forEach((s,f)=>i[f].selected=s.selected);let r=W(e,"input"),o=W(t,"input");r.forEach((s,f)=>{let u=s.type.toLowerCase();u!=="file"&&(o[f].value=s.value),(u==="checkbox"||u==="radio")&&(o[f].checked=s.checked)});let l=W(e,"textarea"),c=W(t,"textarea");l.forEach((s,f)=>c[f].value=s.value)}function xe(e,t){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]"))return;let n=e.startsWith("@")?0:N(e);if(n===-1)return;let i=e.slice(n+1);if(B.has(i))throw new R.RuleTargetReadOnly(i);return}if(Array.isArray(e)){if(!Array.isArray(t))return;t.forEach(n=>xe(e[1],n));return}if(e&&typeof e=="object"&&t&&typeof t=="object"&&!Array.isArray(t))for(let[n,i]of Object.entries(e))xe(i,t[n])}}function Yt(e,t,n){let i={templateAttr:"cms-template"},r=zt(e),o=Kt(r,e),l=Ft(r);Xt(r,l);let c=Jt(l,o),s=k(l,{...i,_write:!0}),f=Ee(s,c,t,n,i);if(f.unknownKeys.length||f.unmatched.length)throw new R.WriteRejected(f.unknownKeys,f.unmatched);let u=se(s);I(u,c,t,n,i),u.assertClean(),xe(t,n);let h=se(k(r,{...i,_write:!0}));I(h,e,t,n,i),h.assertClean()}function Gt(e){if(!(e instanceof Error))return e;let t=e.name||"Error";try{e.code=t}catch{Object.defineProperty(e,"code",{value:t,configurable:!0,enumerable:!0})}return e instanceof R.WriteRefused?e.details=e.refusals:e instanceof R.WriteRejected?e.details={unknownKeys:e.unknownKeys,unmatched:e.unmatched}:e instanceof R.ShapeMismatch?e.details=e.mismatches:Array.isArray(e.path)?e.details={path:e.path}:typeof e.target=="string"?e.details={target:e.target}:e.token!==void 0?e.details={token:e.token}:e.version!==void 0?e.details={version:e.version}:e.details={},e}function it(e,t){let n=Se(e)?e:document,i=Se(e)?t:e;return i===void 0?M(k(n),n,rt(n)):le.bind(n,i).get()}function ot(e,t,n){try{if(!Se(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");let i=n===void 0?rt(e):le.bind(e,n).rules;Yt(e,i,t)}catch(i){throw Gt(i)}return e}var Zt={engine:le,extractData:it,applyData:ot},ur=Zt;export{ot as applyData,ur as default,le as engine,it as extractData};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var hyperHtmlApiData=(()=>{var re=Object.defineProperty;var tt=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var rt=Object.prototype.hasOwnProperty;var Se=(e,t)=>{for(var n in t)re(e,n,{get:t[n],enumerable:!0})},it=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of nt(t))!rt.call(e,r)&&r!==n&&re(e,r,{get:()=>t[r],enumerable:!(i=tt(t,r))||i.enumerable});return e};var ot=e=>it(re({},"__esModule",{value:!0}),e);var Vt={};Se(Vt,{applyData:()=>xe,default:()=>Ft,engine:()=>G,extractData:()=>Oe});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"],Z=new Set(Y),ie=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),$=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]),be=new Set(["checked","selected","disabled","readOnly","paused"]);function oe(e,t){return t==null?be.has(e)?!1:"":be.has(e)?t==="false"?!1:!!t:t}var R={};Se(R,{EmptyListInsert:()=>N,MAX_RULE_DEPTH:()=>L,MaxRuleDepthExceeded:()=>P,NoRulesTag:()=>se,RuleTargetReadOnly:()=>B,RulesParseError:()=>k,ShapeMismatch:()=>v,UnknownRulesVersion:()=>W,WriteNotRoundTripped:()=>Q,WriteRefused:()=>H,WriteRejected:()=>le});var k=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},W=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},L=20,P=class extends Error{constructor(t){super(`rule depth exceeded ${L} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},v=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},N=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}},B=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},H=class extends Error{constructor(t){super(`write refused: ${t.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=t}};function st(e){return e.reduce((n,i)=>typeof i=="number"?`${n}[${i}]`:n?`${n}.${i}`:String(i),"")||"(root)"}var Q=class extends Error{constructor(t){super(`write did not round-trip at "${st(t)}"`),this.name="WriteNotRoundTripped",this.path=t}},se=class extends Error{constructor(t){super(`no <script data-rules-name~="${t}"> rules tag in this document`),this.name="NoRulesTag",this.token=t}},le=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 b(e){let t=0,n=null,i=-1;for(let r=0;r<e.length;r++){let s=e[r];s==="\\"?r++:n?s===n&&(n=null):s==='"'||s==="'"?n=s:s==="["||s==="("?t++:s==="]"||s===")"?t>0&&t--:s==="@"&&t===0&&(i=r)}return i}function ce(e){let t=b(e);return t===-1?{selector:e,prop:null}:{selector:e.slice(0,t),prop:e.slice(t+1)||null}}function fe(e){let t=0,n=null,i=-1,r=!1;for(let s=0;s<e.length;s++){let l=e[s];l==="\\"?s++:n?l===n&&(n=null):l==='"'||l==="'"?n=l:l==="["||l==="("?t++:l==="]"||l===")"?t>0&&t--:t===0&&l===">"?i=s:t===0&&l===","&&(r=!0)}return r||i===-1||!lt(e,i+1)?null:e.slice(0,i).trim()||null}function lt(e,t){let n=t,i=e.replace(/\s+$/,"").length;for(;n<i&&/\s/.test(e[n]);)n++;let r=0,s=null;for(;n<i;n++){let l=e[n];if(l==="\\")n++;else if(s)l===s&&(s=null);else if(l==='"'||l==="'")s=l;else if(l==="["||l==="(")r++;else if(l==="]"||l===")")r>0&&r--;else if(r===0&&(l==="+"||l==="~"||/\s/.test(l)))return!1}return!0}function C(e,t,n,i={}){if(Object.prototype.hasOwnProperty.call(i,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return ue(e,t,n,{depth:0,path:[]},i)}function ue(e,t,n,i,r){if(i.depth>L)throw new P(i.path);if(typeof n=="string")return ct(e,t,n,i,r);if(Array.isArray(n)){let[s,l]=n,c=e.find(t,s,r);return Ne(r,i,c),c.map((o,f)=>ue(e,o,l,{depth:i.depth+1,path:[...i.path,f]},r))}if(typeof n=="object"&&n!==null){let s={};for(let[l,c]of Object.entries(n))s[l]=ue(e,t,c,{depth:i.depth+1,path:[...i.path,l]},r);return s}return null}function ct(e,t,n,i,r){if(n.endsWith("[]")){let c=n.slice(0,-2),o=e.find(t,c,r);return Ne(r,i,o),o.map(f=>e.text(f))}if(n.startsWith("@"))return Re(e,t,n.slice(1));let s=b(n);if(s!==-1){let c=n.slice(0,s),o=n.slice(s+1),f=c?e.find(t,c,r):[t];return f.length===0?null:Re(e,f[0],o)}if(n===".")return e.text(t);let l=e.find(t,n,r);return l.length===0?null:e.text(l[0])}function Ne(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(i){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,i)}}function Re(e,t,n){if(Z.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let i=e.attr(t,n);return i??null}function Pe(e,t,n,i){let r=e.length,s=t.length,l=new Array(r).fill(-1);if(i){let h=new Set;for(let y=0;y<r;y++){let A=i[y];!(A>=0&&A<s)||h.has(A)||(l[y]=A,h.add(A))}}if(r===0||s===0)return l;let c=e.map(h=>Ce(h,n)),o=t.map(h=>Ce(h,n)),f=new Array(s).fill(!1);for(let h of l)h>=0&&(f[h]=!0);let u=new Map;o.forEach((h,y)=>{f[y]||u.set(h,u.has(h)?-1:y)});let m=new Map;c.forEach((h,y)=>{l[y]>=0||m.set(h,(m.get(h)||0)+1)}),c.forEach((h,y)=>{if(l[y]>=0||m.get(h)!==1)return;let A=u.get(h);A===void 0||A===-1||f[A]||(l[y]=A,f[A]=!0)});let d=[];for(let h=0;h<r;h++)l[h]<0&&d.push(h);let w=[];for(let h=0;h<s;h++)f[h]||w.push(h);if(d.length===0||w.length===0)return l;let a=r*s+1,p=ft(e,t,n),g=(h,y)=>p(h,y)*a+Math.abs(h-y);for(let[h,y]of ut(d,w,g))l[h]=y;return l}var Ie=e=>typeof e=="object"&&e!==null;function Ce(e,t){if(!Ie(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(i=>{let r=JSON.stringify(e?.[i]);return r===void 0?" undef":r}))}function ft(e,t,n){if(!Ie(n))return(c,o)=>e[c]===t[o]?0:1;let i=Object.keys(n),r=c=>i.map(o=>JSON.stringify(c?.[o])),s=e.map(r),l=t.map(r);return(c,o)=>{let f=s[c],u=l[o],m=0;for(let d=0;d<i.length;d++)f[d]!==u[d]&&m++;return m}}function ut(e,t,n){return e.length<=t.length?Me(e,t,n,!1):Me(t,e,(i,r)=>n(r,i),!0)}function Me(e,t,n,i){let r=e.length,s=t.length,l=[];for(let m=0;m<=r;m++)l.push(new Float64Array(s+1).fill(1/0));let c=[];for(let m=0;m<=r;m++)c.push(new Uint8Array(s+1));for(let m=0;m<=s;m++)l[r][m]=0;for(let m=r-1;m>=0;m--)for(let d=s-1;d>=0;d--){let w=n(e[m],t[d])+l[m+1][d+1],a=l[m][d+1];w<=a?(l[m][d]=w,c[m][d]=1):l[m][d]=a}let o=[],f=0,u=0;for(;f<r&&u<s;)c[f][u]&&(o.push(i?[t[u],e[f]]:[e[f],t[u]]),f++),u++;return o}function he(e,t,n,i,r,s,l,c={}){let o=e.find(t,n,c);if(r.length===0){o.forEach(T=>e.remove(T)),ae(c,"onRowsApplied",s.path,[]);return}let f=r.length>o.length,u=o[0]||null;if(f&&!u&&(u=pt(e,t,n,c),!u))throw new N(s.path);let m=o.map(T=>dt(e,T,i,c)),d=null;if(f&&u){d=e.clone(u),c.templateAttr&&e.removeAttr(d,c.templateAttr);let T=e.stripIds(d);T>0&&console.warn(`[hyper-html-api] stripped ${T} id attribute(s) from cloned template at "${s.path.join(".")||"(root)"}"`)}let w=Pe(r,m,i,at(e,o,r,s,c)),a=o.length>0?e.parent(o[0]):At(e,t,n,u,s,c),p=o.length>0?De(e,a,o[0]):0,g=Et(e,o),h=new Set,y=[],A=r.map((T,S)=>{let O=w[S];if(O>=0)return h.add(O),y.push(!1),o[O];y.push(!0);let E=e.clone(d);return e.stripIds(E),E});o.forEach((T,S)=>{h.has(S)||e.remove(T)}),g?wt(e,a,p,A,y):Ot(e,A,y,a,p),ht(e,A,i,r,s,l,c),ae(c,"onRowsApplied",s.path,A)}function ae(e,t,n,i){if(typeof e[t]=="function")try{return e[t](n.slice(),i)}catch(r){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,r);return}}function at(e,t,n,i,r){let s=ae(r,"identifyRows",i.path,n);if(!Array.isArray(s))return null;let l=new Array(n.length).fill(-1),c=new Set,o=new Map(t.map((f,u)=>[e.identity(f),u]));for(let f=0;f<n.length;f++){if(!s[f])continue;let u=o.get(e.identity(s[f]));u===void 0||c.has(u)||(l[f]=u,c.add(u))}return l}function ht(e,t,n,i,r,s,l){t.forEach((c,o)=>{if(n===null){let f=i[o],u=f==null?"":String(f);e.text(c)!==u&&e.text(c,u)}else{let f=s(e,c,n,i[o],{depth:r.depth+1,path:[...r.path,o]},l);f&&f!==c&&(t[o]=f)}})}function dt(e,t,n,i){return n===null?e.text(t):C(e,t,n,i.onRowsRead?{...i,onRowsRead:void 0}:i)}function De(e,t,n){let i=e.children(t);for(let r=0;r<i.length;r++)if(e.sameNode(i[r],n))return r;return-1}function pt(e,t,n,i){if(!i.templateAttr)return null;let r=/^\s*:scope\s*>\s*/.test(n),s=new RegExp(":not\\(\\["+i.templateAttr.replace(/[.*+?^${}()|[\]\\-]/g,"\\$&")+"\\]\\)","g"),l=n.replace(/^\s*:scope\s*>\s*/,"").replace(s,""),c=r?mt(l):0,o=fe(l),f=t;for(;f;){let u=e.find(f,l,{includeRulesTag:!1,templateAttr:null});for(let m of u)if(e.attr(m,i.templateAttr)!=null&&!(r&&!gt(e,t,m,c))&&!(o&&!e.matches(e.parent(m),o)))return m;f=e.parent(f)}return null}function mt(e){let t=0,n=null,i=1;for(let r=0;r<e.length;r++){let s=e[r];if(s==="\\")r++;else if(n)s===n&&(n=null);else if(s==='"'||s==="'")n=s;else if(s==="["||s==="(")t++;else if(s==="]"||s===")")t>0&&t--;else if(t===0&&s===">")i++;else{if(t===0&&(s==="+"||s==="~"))return null;if(t===0&&/\s/.test(s)){if(!yt(e,r))return null;for(;r+1<e.length&&/\s/.test(e[r+1]);)r++}}}return i}function yt(e,t){let n=t;for(;n<e.length&&/\s/.test(e[n]);)n++;let i=t>0?e[t-1]:"",r=n<e.length?e[n]:"";return ke(i)||ke(r)}function ke(e){return e===">"||e==="+"||e==="~"}function gt(e,t,n,i){if(i===null)return!0;let r=n;for(let o=0;o<i;o++)if(r=e.parent(r),!r)return!1;let s=e.prop(t,"tagName");if(!s)return!0;let l=e.prop(r,"tagName");if(!l||String(l).toLowerCase()!==String(s).toLowerCase())return!1;let c=new Set(Le(e,r));return Le(e,t).every(o=>c.has(o))}function Le(e,t){let n=e.attr(t,"class");return n?String(n).split(/\s+/).filter(Boolean):[]}function At(e,t,n,i,r,s){let l=e.parent(i);if(l&&Tt(e,t,l)&&!_e(e,l,s))return l;let c=fe(n);if(!c)throw new N(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 f=(c===":scope"?e.prop(t,"tagName")?[t]:[]:e.find(t,c,s)).filter(u=>!_e(e,u,s));if(f.length===0)throw new N(r.path,`no container matching "${c}" inside this context to hold the new rows`);if(f.length>1)throw new N(r.path,`"${c}" matches ${f.length} containers inside this context, so the new rows have no single destination`);return f[0]}function Tt(e,t,n){let i=n;for(;i;){if(e.sameNode(i,t))return!0;i=e.parent(i)}return e.parent(t)?!1:e.find(t,"*",{includeRulesTag:!0,templateAttr:null}).some(r=>e.sameNode(r,n))}var je=["no-data","editor-ui"];function _e(e,t,n){let i=t;for(;i;){if(n.templateAttr&&e.attr(i,n.templateAttr)!=null||je.some(s=>e.attr(i,s)!=null))return!0;let r=e.attr(i,"clay");if(r&&r.split(/\s+/).some(s=>je.includes(s)))return!0;i=e.parent(i)}return!1}function wt(e,t,n,i,r){let s=e.children(t),l=s.map(o=>e.identity(o)),c=!1;i.forEach((o,f)=>{let u=e.identity(o),m=n+f;if(l[m]===u)return;if(!r[f]){let w=l.indexOf(u);w!==-1&&(l.splice(w,1),s.splice(w,1))}let d=Math.min(m,s.length);d<s.length?e.insertBefore(s[d],o):s.length?c?e.insertAfter(s[s.length-1],o):(e.insertAt(t,o,m),c=!0):e.insertAt(t,o,0),l.splice(d,0,u),s.splice(d,0,o)})}function Et(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let i=new Map(e.children(n).map((s,l)=>[e.identity(s),l])),r=[];for(let s of t){let l=i.get(e.identity(s));if(l===void 0)return!1;r.push(l)}return r.sort((s,l)=>s-l),r[r.length-1]-r[0]===r.length-1}function Ot(e,t,n,i,r){let s=null,l=r;for(let c=0;c<t.length;c++){if(!n[c]){s=t[c];continue}let o=s?e.parent(s):i;if(!o)continue;let f=s?De(e,o,s)+1:l++;e.insertAt(o,t[c],f),s=t[c]}}function I(e,t,n,i,r={}){if(Object.prototype.hasOwnProperty.call(r,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");let s=[];if(de(n,i,[],s),s.length)throw new v(s);ee(e,t,n,i,{depth:0,path:[]},r)}function ee(e,t,n,i,r,s={}){if(r.depth>L)throw new P(r.path);if(i===void 0)return t;if(typeof n=="string")return xt(e,t,n,i,r,s);if(Array.isArray(n)){let[l,c]=n;return he(e,t,l,c,i,r,ee,s),t}if(typeof n=="object"&&n!==null){for(let[l,c]of Object.entries(n)){let o=ee(e,t,c,i==null?i:i[l],{depth:r.depth+1,path:[...r.path,l]},s);o&&o!==t&&(t=o)}return t}return t}function xt(e,t,n,i,r,s){if(n.endsWith("[]")){let o=n.slice(0,-2);return he(e,t,o,null,i,r,ee,s),t}if(n.startsWith("@"))return We(e,t,n.slice(1),i);let l=b(n);if(l!==-1){let o=n.slice(0,l),f=n.slice(l+1),u=o?e.find(t,o,s):[t];return u.length===0||We(e,u[0],f,i),t}if(n===".")return $e(e,t,i),t;let c=e.find(t,n,s);return c.length===0||$e(e,c[0],i),t}function $e(e,t,n){let i=n==null?"":String(n);e.text(t)!==i&&e.text(t,i)}function We(e,t,n,i){if($.has(n)){let r=e.prop(t,n);if(r===i||r!=null&&i!=null&&String(r)===String(i))return t;throw new B(n)}if(n==="outerHTML"){let r=i==null?"":String(i);return e.replaceWith(t,r)}if(ie.has(n)){let r=oe(n,i);return e.prop(t,n)!==r&&e.prop(t,n,r),t}if(i==null)e.attr(t,n)!=null&&e.removeAttr(t,n);else{let r=String(i);e.attr(t,n)!==r&&e.attr(t,n,r)}return t}function de(e,t,n,i){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((r,s)=>{typeof r=="object"&&r!==null&&i.push({path:U([...n,s]),expected:"scalar",got:q(r)})}):i.push({path:U(n),expected:"array",got:q(t)});return}t!==null&&typeof t=="object"&&i.push({path:U(n),expected:"scalar",got:q(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){i.push({path:U(n),expected:"array",got:q(t)});return}let r=e[1];t.forEach((s,l)=>de(r,s,[...n,l],i));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){i.push({path:U(n),expected:"object",got:q(t)});return}for(let[r,s]of Object.entries(e))de(s,t[r],[...n,r],i)}}}function q(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function U(e){return e.join(".")}function pe(e){try{return JSON.parse(e)}catch(t){throw new k(`Invalid strict JSON: ${t.message}`,t)}}function z(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(r){let s=[],l=0;for(;l<r.length;){let c=r[l];if(/\s/.test(c)){l++;continue}if("{}".includes(c)){s.push({type:c,value:c}),l++;continue}if(c==="["){let m=!1,d=l+1;for(;d<r.length&&/\s/.test(r[d]);)d++;if(d<r.length&&/[a-zA-Z_]/.test(r[d])&&(m=!0),!m){s.push({type:c,value:c}),l++;continue}}if(c==="]"){s.push({type:c,value:c}),l++;continue}if(c===":"){s.push({type:t.COLON,value:c}),l++;continue}if(c===","){s.push({type:t.COMMA,value:c}),l++;continue}if(c==='"'||c==="'"){let m=c,d=l+1;for(;d<r.length&&r[d]!==m;)r[d]==="\\"&&d++,d++;s.push({type:t.STRING,value:r.substring(l+1,d),quoted:!0,sourceQuote:m}),l=d+1;continue}let o=l,f;for(;o<r.length&&!/[{},]/.test(r[o]);)if(r[o]===":"){let m=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],d=!1;for(let w of m){let a=w.substring(1);if(r.substring(o+1,o+1+a.length)===a){d=!0,o+=a.length;break}}if(!d)break}else if(r[o]==="["){for(o++;o<r.length&&r[o]!=="]";){if(r[o]==='"'||r[o]==="'"){let m=r[o];for(o++;o<r.length&&r[o]!==m;)r[o]==="\\"&&o++,o++}o++}o<r.length&&r[o]==="]"&&o++}else o++;f=r.substring(l,o);let u=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(f)?u=t.NUMBER:f==="true"||f==="false"||f==="null"?u=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(f)&&(u=t.SELECTOR),s.push({type:u,value:f,quoted:!1}),l=o}return s}function i(r){let s="";for(let l=0;l<r.length;l++){let c=r[l];if("{}".includes(c.type)||"[]".includes(c.type)){s+=c.value;continue}if(c.type===t.COLON){s+=c.value;continue}if(c.type===t.COMMA){let o=r[l+1];if(o&&(o.type==="}"||o.type==="]"))continue;s+=c.value;continue}if(c.type===t.STRING&&c.quoted){let o=c.value;c.sourceQuote==="'"&&(o=o.replace(/\\'/g,"'"),o=o.replace(/(\\*)"/g,(f,u)=>u.length%2===0?u+'\\"':f)),s+=`"${o}"`;continue}if(c.type===t.NUMBER||c.type===t.BOOLEAN){s+=c.value;continue}if(c.type===t.SELECTOR||c.type===t.IDENTIFIER){s+=`"${c.value}"`;continue}s+=`"${c.value}"`}return s}try{let r=n(e),s=i(r);return JSON.parse(s)}catch(r){throw new k("Invalid extraction rules syntax: "+r.message,r)}}var St="1",ve=/^[a-zA-Z0-9_-]+$/;function j(e,t,n){let i;if(n===void 0)i="script[data-rules-name]";else{if(typeof n!="string"||!ve.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${ve})`);i=`script[data-rules-name~="${n}"]`}let r=e.find(t,i,{includeRulesTag:!0});if(r.length===0)return null;n!==void 0&&r.length>1&&console.warn(`hyper-html-api: ${r.length} rules tags match data-rules-name~="${n}"; using the first.`);let s=r[0],l=e.attr(s,"data-rules-version");if(l!==St)throw new W(l);return{rules:z(e.text(s)),tagNode:s}}var te=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"]})}),bt=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 me(e,t){if(K(e,t))return!0;for(let[n,i]of Object.entries(bt))if(i.includes(t)&&K(e,n))return!0;return!1}function F(e){let t=te[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function Rt(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let i=te[t];if(!i)throw new Error(`Unknown region capability: ${t}`);if(i.tokens.some(r=>me(n,r))||i.bundles.some(r=>K(n,r)))return n;n=n.parentElement}return null}function He(e,t){return!!Rt(e,t)}var ye=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"]}),Nt=new Set(["textContent","innerText"]);function qe(e){let n=String(e).replace(/^[\u0000- ]+|[\u0000- ]+$/g,"").replace(/[\t\n\r]/g,"").match(/^([a-zA-Z][a-zA-Z0-9+.-]*):/);return n?n[1].toLowerCase():null}var Ct=/^[^\t\n\f\r "'>/=\u0000-\u001f\u007f]+$/;function Ue(e,t,n=ye){if(!Ct.test(String(e)))return`attribute name ${JSON.stringify(String(e))} is not valid`;let i=String(e).toLowerCase();if(n.refusedAttributePrefixes.some(r=>i.startsWith(r)))return`attribute "${i}" can run script`;if(n.refusedAttributes.includes(i))return`attribute "${i}" is not content`;if(n.urlAttributes.includes(i)&&t!=null){let r=i==="srcset"?String(t).split(",").map(s=>s.trim().split(/\s+/)[0]).filter(Boolean):[String(t)];for(let s of r){let l=qe(s);if(l&&n.refusedSchemes.includes(l))return`"${l}:" URLs are not allowed in "${i}"`}}return null}function ge(e,t){let n=e.prop(t,"tagName");return n?String(n).toLowerCase():""}function Mt(e,t){let n=ge(e,t)||"node",i=e.attr(t,"id");return i?`<${n}#${i}>`:`<${n}>`}function Pt(e,t,n){let i=t;for(;i;){let r=ge(e,i);if(r&&n.refusedTargets.includes(r))return r;i=e.parent(i)}return null}function ze(e,t){return e.find(t,"script[data-rules-name]",{includeRulesTag:!0,templateAttr:null}).length>0}function It(e,t){return ge(e,t)==="script"&&e.attr(t,"data-rules-name")!=null?!0:ze(e,t)}function ne(e,t=ye){let n=[],i=(o,f)=>(n.push({target:Mt(e,o),reason:f}),!1),r=o=>{let f=Pt(e,o,t);return f?i(o,`inside <${f}>, which is not content`):!0},s=o=>r(o)?ze(e,o)?i(o,"a text write here would delete the data rules tag"):!0:!1,l=(o,f,u)=>{if(!r(o))return!1;let m=Ue(f,u,t);return m?i(o,m):!0};return{...e,text(o,f){if(f===void 0)return e.text(o);s(o)&&e.text(o,f)},attr(o,f,u){if(u===void 0)return e.attr(o,f);l(o,f,u)&&e.attr(o,f,u)},removeAttr(o,f){l(o,f,null)&&e.removeAttr(o,f)},prop(o,f,u){if(u===void 0)return e.prop(o,f);if(t.refusedRuleForms.includes(f))return i(o,`"@${f}" writes HTML, only text is allowed`);if(Nt.has(f)){s(o)&&e.prop(o,f,u);return}l(o,f==="className"?"class":f,u)&&e.prop(o,f,u)},remove(o){if(It(e,o)){i(o,"removing this would delete the data rules tag");return}e.remove(o)},replaceWith(o,f){return f===e.prop(o,"outerHTML")||i(o,'"@outerHTML" writes HTML, only text is allowed'),o},refusals:n,assertClean(){if(n.length)throw new H(n.slice())}}}function V(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Ke(e){return e.reduce((t,n)=>typeof n=="number"?`${t}[${n}]`:t?`${t}.${n}`:n,"")}function Ae(e,t,n,i,r={}){let s=[],l=[];function c(f,u,m){if(Array.isArray(f)){let[,d]=f;if(!Array.isArray(u)||!V(d))return;u.forEach((w,a)=>c(d,w,[...m,a]));return}if(!(!V(f)||!V(u)))for(let d of Object.keys(u))Object.prototype.hasOwnProperty.call(f,d)?c(f[d],u[d],[...m,d]):s.push(Ke([...m,d]))}function o(f,u,m,d){if(m!==void 0){if(typeof u=="string"){if(u.endsWith("[]")||u==="."||u.startsWith("@"))return;let w=b(u),a=w===-1?u:u.slice(0,w);if(!a)return;e.find(f,a,r).length===0&&l.push({path:Ke(d),selector:a});return}if(!Array.isArray(u)&&V(u)&&V(m))for(let[w,a]of Object.entries(u))o(f,a,m[w],[...d,w])}}return c(n,i,[]),o(t,n,i,[]),{unknownKeys:s,unmatched:l}}function Te(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let i=t&&t.ownerDocument?t.ownerDocument:t;return j(e,i,n)}return null}var Lt=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function jt(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 Fe(e,t,n,i){if(i)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 Ve(e,t,n,i,r,s){return(s?He(e,t):Fe(e,n,r,!1))||!!(i&&(s&&e!==r?e.matches(i):Fe(e,i,r,s)))}function _t(e,t){let n=te[t];return n.tokens.some(i=>me(e,i))||n.bundles.some(i=>K(e,i))}var Dt=new Set(["INPUT","TEXTAREA","SELECT","OPTION"]);function Je(e,t,n,i){if(e.nodeType===1&&i(e)){n.dropped.push(t);return}n.cloneToLive.set(t,e),n.liveToClone.set(e,t);let r=e,s=t;if(e.nodeType===1){if(Dt.has(e.tagName)&&n.controls.push(e,t),e.tagName==="TEMPLATE"){for(;t.firstChild;)t.removeChild(t.firstChild);r=e.content,s=t.content,n.cloneToLive.set(s,r),n.liveToClone.set(r,s)}}else if(e.nodeType!==11)return;let l=s.firstChild;for(let c=r.firstChild;c&&l;c=c.nextSibling)Je(c,l,n,i),l=l.nextSibling}function J(e,{capability:t="data",exclude:n=null,inherit:i=!0,provenance:r=null}={}){if(!e)throw new TypeError("createContentView requires a DOM context");let s=e.nodeType===9?e:e.ownerDocument;if(!s?.implementation?.createHTMLDocument)throw new TypeError("createContentView requires an HTML DOM implementation");let l=s.implementation.createHTMLDocument(""),c=r||new WeakMap,o=new WeakMap,f=e.nodeType===9?e.documentElement:e;n&&l.documentElement.matches(n);let u=F(t),m=i?a=>_t(a,t)||!!(n&&a.matches(n)):a=>Ve(a,t,u,n,f,!1),d=null;if(f.nodeType!==1||!Ve(f,t,u,n,f,i)){d=l.importNode(f,!0);let a={cloneToLive:c,liveToClone:o,dropped:[],controls:[]};Je(f,d,a,m);for(let p of a.dropped)p.remove();for(let p=0;p<a.controls.length;p+=2)jt(a.controls[p],a.controls[p+1])}e.nodeType===9&&d&&(l.replaceChild(d,l.documentElement),o.set(e,l),c.set(l,e));let w=a=>{if(Lt.test(a))throw new Error(`Filtered content queries do not support stateful selector: ${a}`)};return{root:d,document:l,capability:t,selector:F(t),cloneToLive:c,liveToClone:o,original(a){return c.get(a)||null},cloneOf(a){return o.get(a)||null},query(a,p=d){return w(a),Array.from(p.querySelectorAll(a),g=>c.get(g)||g)},text(a=d){return(a===d?d:o.get(a))?.textContent||""},html(a=d){return(a===d?d:o.get(a))?.innerHTML??""},clone(a=d){let p=a===d?d:o.get(a);return p?l.importNode(p,!0):null}}}function Ge(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function $t(e){return e?(e.nodeType===9||e.nodeType===11,e):null}function Xe(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 Ze(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 i=n.type;i!=="file"&&i!=="checkbox"&&i!=="radio"&&(n.value=n.defaultValue),n.checked=n.defaultChecked}else n.tagName==="OPTION"&&(n.selected=n.defaultSelected)}var x={semanticExclude:!0,find(e,t,n={}){let i=$t(e);if(!i||!i.querySelectorAll)return[];let r=Array.from(i.querySelectorAll(t));n.includeRulesTag||(r=r.filter(c=>!Ge(c)));let s=[];n.skip&&s.push(n.skip);let l=n.templateAttr===null?null:n.templateAttr||"cms-template";if(l&&s.push("["+l+"]"),s.length){let c=s.join(", ");r=r.filter(o=>!o.closest||!o.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),Xe(e,t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t),Xe(e,t,null)},prop(e,t,n){if(n===void 0){let i=e?e[t]:void 0;return i!==void 0?i:null}e[t]=n},clone(e){let t=e.cloneNode(!0);return Ze(t),t},insertAt(e,t,n){let i=e.children[n]||null;e.insertBefore(t,i)},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 i=e.ownerDocument.createElement("template");i.innerHTML=t;let r=i.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(i=>{i.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};function M(e,t={}){if(t.exclude===null)return x;let n=[F("data"),t.exclude].filter(Boolean).join(", "),i=e.nodeType===9?e:e.ownerDocument||e,r=e.nodeType===9?e.documentElement:e;if(!t._write&&!r?.matches?.(n)&&!r?.querySelector?.(n)&&!i?.querySelector?.(n))return x;let s=e.nodeType===9||!e.isConnected?e:e.ownerDocument,l=e.nodeType===9?e:e.ownerDocument,c=null,o=()=>c||(c=J(s,{capability:"data",exclude:t.exclude||null})),f=a=>{let p=o();return a===e?p.cloneOf(e):p.cloneOf(a)||a},u=a=>c?.original(a)||a,m=(a,p)=>{o().liveToClone.set(a,p),o().cloneToLive.set(p,a);let g=a.childNodes||[],h=p.childNodes||[];for(let y=0;y<Math.min(g.length,h.length);y++)m(g[y],h[y])},d=(a,p,g,h)=>{let y=Array.from(a.childNodes).filter(E=>c.cloneOf(E)),T=y[0];for(;T&&y.includes(T);)T=T.nextSibling;for(let E of y)E.remove();if(g==="innerHTML"){let E=l.createElement("template");E.innerHTML=h;for(let D of Array.from(E.content.childNodes))a.insertBefore(D,T||null)}else a.insertBefore(l.createTextNode(h),T||null),Ye(a,h);let S=J(a,{capability:"data",exclude:t.exclude||null});p.replaceChildren(...Array.from(S.root?.childNodes||[]));let O=E=>{let D=S.original(E);D&&(c.liveToClone.set(D,E),c.cloneToLive.set(E,D));for(let et of Array.from(E.childNodes||[]))O(et)};for(let E of Array.from(p.childNodes))O(E)},w={...x,find(a,p,g={}){let h=f(a);if(!h?.querySelectorAll)return[];let y=o().query(p,h);g.includeRulesTag||(y=y.filter(S=>!Ge(S)));let A=[];g.skip&&A.push(g.skip);let T=g.templateAttr===null?null:g.templateAttr||"cms-template";if(T&&A.push(`[${T}]`),A.length){let S=A.join(", ");y=y.filter(O=>!O.closest?.(S))}return y},parent(a){let p=f(a)?.parentElement;return p?u(p):null},children(a){return Array.from(f(a)?.children||[],u)},text(a,p){if(p===void 0){let y=u(a);return!y?.matches?.(n)&&!y?.querySelector?.(n)?x.text(y):(f(a)?.textContent||"").trim()}let g=u(a);if(!g?.matches?.(n)&&!g?.querySelector?.(n)&&!c){x.text(g,p);return}let h=o().cloneOf(g);h?d(g,h,"textContent",p):x.text(g,p)},attr(a,p,g){let h=u(a);if(g===void 0)return x.attr(h,p);x.attr(h,p,g);let y=c?.cloneOf(h);y&&(x.attr(y,p,g),J(h,{capability:"data",exclude:t.exclude||null}).root===null&&(y.remove(),c.liveToClone.delete(h),c.cloneToLive.delete(y)))},removeAttr(a,p){let g=u(a);x.removeAttr(g,p);let h=c?.cloneOf(g);h&&x.removeAttr(h,p)},prop(a,p,g){let h=u(a);if(g===void 0)return p==="innerHTML"||p==="outerHTML"||p==="textContent"||p==="innerText"?x.prop(f(h),p):x.prop(h,p);let y=p==="innerHTML"||p==="textContent"||p==="innerText",A=y?o().cloneOf(h):c?.cloneOf(h);A&&y?d(h,A,p,g):(x.prop(h,p,g),A&&x.prop(A,p,g))},clone(a){let p=f(a);if(p===a)return x.clone(a);let g=l.importNode(p,!0);return Ze(g),g},insertAt(a,p,g){let h=u(a),A=w.children(h)[g]||(()=>{for(let O=h.children.length-1;O>=0;O--){let E=h.children[O];if(o().cloneOf(E))return E.nextElementSibling}return h.firstElementChild})(),T=u(p);h.insertBefore(T,A||null);let S=o().cloneOf(h);if(S){let O=o().cloneOf(T);O||(O=l.importNode(T,!0),m(T,O));let E=Array.from(S.children);S.insertBefore(O,E[g]||null)}},insertBefore(a,p){let g=u(a),h=u(p);g.parentNode.insertBefore(h,g);let y=o().cloneOf(g.parentNode);if(y){let A=o().cloneOf(h);A||(A=l.importNode(h,!0),m(h,A));let T=o().cloneOf(g);T?T.before(A):y.appendChild(A)}},insertAfter(a,p){let g=u(a),h=u(p);g.parentNode.insertBefore(h,g.nextSibling);let y=o().cloneOf(g.parentNode);if(y){let A=o().cloneOf(h);A||(A=l.importNode(h,!0),m(h,A));let T=o().cloneOf(g);T?T.after(A):y.appendChild(A)}},identity(a){return u(a)||null},remove(a){let p=u(a),g=o().cloneOf(p);x.remove(p),g&&x.remove(g)},replaceWith(a,p){let g=u(a),h=o().cloneOf(g),y=x.replaceWith(g,p);if(h){let A=J(y,{capability:"data",exclude:t.exclude||null});if(!A.root)h.remove();else{h.replaceWith(A.root);let T=S=>{let O=A.original(S);O&&(c.liveToClone.set(O,S),c.cloneToLive.set(S,O));for(let E of Array.from(S.childNodes||[]))T(E)};T(A.root)}}return y}};return w}var X=x;var G={extract:(e,t,n={})=>C(M(e,n),e,t,n),apply:(e,t,n,i={})=>I(M(e,{...i,_write:!0}),e,t,n,i),findRulesIn:(e,t)=>j(X,e,t),findRules:(e,t)=>Te(X,e,t),bind:(e,t,n={})=>{let i=Te(X,e,t);if(!i){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{...i,get:()=>C(M(e,n),e,i.rules,n),set:r=>I(M(e,{...n,_write:!0}),e,i.rules,r,n)}},parseStrict:pe,parseRelaxed:z,ruleAttrIndex:b,splitRule:ce,errors:R,DOM_PROPERTIES:Y},we=e=>!!e&&typeof e.nodeType=="number";function Qe(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=j(X,t,"api");if(!n)throw new R.NoRulesTag("api");return n.rules}function Wt(e){if(e.nodeType===9)return e;let t=e.ownerDocument?.documentElement;if(t?.contains(e))return t;let n=e;for(;n.parentNode;)n=n.parentNode;return n}function vt(e){if(e.nodeType!==11||!e.host)return e.cloneNode(!0);let t=e.ownerDocument.createDocumentFragment();for(let n of e.childNodes)t.appendChild(n.cloneNode(!0));return t}function Bt(e,t){let n=[];for(;t!==e;){let i=t.parentNode;n.push(Array.prototype.indexOf.call(i.childNodes,t)),t=i}return n.reverse()}function Ht(e,t){return t.reduce((n,i)=>n.childNodes[i],e)}function _(e,t){let n=e.querySelectorAll?Array.from(e.querySelectorAll(t)):[];return e.matches?.(t)&&n.unshift(e),n}function qt(e,t){let n=_(e,"option"),i=_(t,"option");n.forEach((o,f)=>i[f].selected=o.selected);let r=_(e,"input"),s=_(t,"input");r.forEach((o,f)=>{let u=o.type.toLowerCase();u!=="file"&&(s[f].value=o.value),(u==="checkbox"||u==="radio")&&(s[f].checked=o.checked)});let l=_(e,"textarea"),c=_(t,"textarea");l.forEach((o,f)=>c[f].value=o.value)}function Ee(e,t){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]"))return;let n=e.startsWith("@")?0:b(e);if(n===-1)return;let i=e.slice(n+1);if($.has(i))throw new R.RuleTargetReadOnly(i);return}if(Array.isArray(e)){if(!Array.isArray(t))return;t.forEach(n=>Ee(e[1],n));return}if(e&&typeof e=="object"&&t&&typeof t=="object"&&!Array.isArray(t))for(let[n,i]of Object.entries(e))Ee(i,t[n])}}function Ut(e,t,n){let i={templateAttr:"cms-template"},r=Wt(e),s=Bt(r,e),l=vt(r);qt(r,l);let c=Ht(l,s),o=M(l,{...i,_write:!0}),f=Ae(o,c,t,n,i);if(f.unknownKeys.length||f.unmatched.length)throw new R.WriteRejected(f.unknownKeys,f.unmatched);let u=ne(o);I(u,c,t,n,i),u.assertClean(),Ee(t,n);let m=ne(M(r,{...i,_write:!0}));I(m,e,t,n,i),m.assertClean()}function zt(e){if(!(e instanceof Error))return e;let t=e.name||"Error";try{e.code=t}catch{Object.defineProperty(e,"code",{value:t,configurable:!0,enumerable:!0})}return e instanceof R.WriteRefused?e.details=e.refusals:e instanceof R.WriteRejected?e.details={unknownKeys:e.unknownKeys,unmatched:e.unmatched}:e instanceof R.ShapeMismatch?e.details=e.mismatches:Array.isArray(e.path)?e.details={path:e.path}:typeof e.target=="string"?e.details={target:e.target}:e.token!==void 0?e.details={token:e.token}:e.version!==void 0?e.details={version:e.version}:e.details={},e}function Oe(e,t){let n=we(e)?e:document,i=we(e)?t:e;return i===void 0?C(M(n),n,Qe(n)):G.bind(n,i).get()}function xe(e,t,n){try{if(!we(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");let i=n===void 0?Qe(e):G.bind(e,n).rules;Ut(e,i,t)}catch(i){throw zt(i)}return e}var Kt={engine:G,extractData:Oe,applyData:xe},Ft=Kt;return ot(Vt);})();
|
|
1
|
+
var hyperHtmlApiData=(()=>{var ce=Object.defineProperty;var ft=Object.getOwnPropertyDescriptor;var ut=Object.getOwnPropertyNames;var at=Object.prototype.hasOwnProperty;var Ce=(e,t)=>{for(var n in t)ce(e,n,{get:t[n],enumerable:!0})},ht=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ut(t))!at.call(e,r)&&r!==n&&ce(e,r,{get:()=>t[r],enumerable:!(i=ft(t,r))||i.enumerable});return e};var dt=e=>ht(ce({},"__esModule",{value:!0}),e);var sn={};Ce(sn,{applyData:()=>Ne,default:()=>on,engine:()=>Q,extractData:()=>Re});var ee=["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"],te=new Set(ee),fe=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),B=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]),Pe=new Set(["checked","selected","disabled","readOnly","paused"]);function ue(e,t){return t==null?Pe.has(e)?!1:"":Pe.has(e)?t==="false"?!1:!!t:t}var R={};Ce(R,{EmptyListInsert:()=>C,MAX_RULE_DEPTH:()=>$,MaxRuleDepthExceeded:()=>L,NoRulesTag:()=>ae,RuleTargetReadOnly:()=>V,RulesParseError:()=>j,ShapeMismatch:()=>q,UnknownRulesVersion:()=>H,WriteNotRoundTripped:()=>ne,WriteRefused:()=>U,WriteRejected:()=>he});var j=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},H=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},$=20,L=class extends Error{constructor(t){super(`rule depth exceeded ${$} 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}},C=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}},U=class extends Error{constructor(t){super(`write refused: ${t.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=t}};function pt(e){return e.reduce((n,i)=>typeof i=="number"?`${n}[${i}]`:n?`${n}.${i}`:String(i),"")||"(root)"}var ne=class extends Error{constructor(t){super(`write did not round-trip at "${pt(t)}"`),this.name="WriteNotRoundTripped",this.path=t}},ae=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 N(e){let t=0,n=null,i=-1;for(let r=0;r<e.length;r++){let o=e[r];o==="\\"?r++:n?o===n&&(n=null):o==='"'||o==="'"?n=o:o==="["||o==="("?t++:o==="]"||o===")"?t>0&&t--:o==="@"&&t===0&&(i=r)}return i}var Me="[*]";function b(e){let t=N(e),n=t===-1?e:e.slice(0,t),i=n.endsWith(Me),r={selector:i?n.slice(0,-Me.length):n,prop:t===-1?null:e.slice(t+1)||null};return i&&(r.all=!0),r}function de(e){let t=0,n=null,i=-1,r=!1;for(let o=0;o<e.length;o++){let l=e[o];l==="\\"?o++:n?l===n&&(n=null):l==='"'||l==="'"?n=l:l==="["||l==="("?t++:l==="]"||l===")"?t>0&&t--:t===0&&l===">"?i=o:t===0&&l===","&&(r=!0)}return r||i===-1||!mt(e,i+1)?null:e.slice(0,i).trim()||null}function mt(e,t){let n=t,i=e.replace(/\s+$/,"").length;for(;n<i&&/\s/.test(e[n]);)n++;let r=0,o=null;for(;n<i;n++){let l=e[n];if(l==="\\")n++;else if(o)l===o&&(o=null);else if(l==='"'||l==="'")o=l;else if(l==="["||l==="(")r++;else if(l==="]"||l===")")r>0&&r--;else if(r===0&&(l==="+"||l==="~"||/\s/.test(l)))return!1}return!0}var yt=/^--[A-Za-z0-9_-]+$/;function P(e){return typeof e=="string"&&yt.test(e)}function ke(e){let t=[],n=[],i=null,r=0;for(let o=0;o<e.length;o++){let l=e[o];if(i){l==="\\"?o++:l===i&&(i=null);continue}if(l==="/"&&e[o+1]==="*"){let c=e.indexOf("*/",o+2);o=c===-1?e.length:c+1;continue}l==='"'||l==="'"?i=l:l==="("?n.push(")"):l==="["?n.push("]"):l==="{"?n.push("}"):(l===")"||l==="]"||l==="}")&&n[n.length-1]===l?n.pop():l===";"&&n.length===0&&(t.push(e.slice(r,o)),r=o+1)}return t.push(e.slice(r)),t}function gt(e){let t="",n=null;for(let i=0;i<e.length;i++){let r=e[i];if(n){t+=r,r==="\\"&&i+1<e.length?t+=e[++i]:r===n&&(n=null);continue}if(r==="/"&&e[i+1]==="*"){let o=e.indexOf("*/",i+2);i=o===-1?e.length:o+1,t+=" ";continue}(r==='"'||r==="'")&&(n=r),t+=r}return t}function Le(e){e=gt(e);let t=e.indexOf(":");if(t===-1)return null;let n=e.slice(0,t).trim(),i=e.slice(t+1).trim(),r=/!\s*important\s*$/i.exec(i);return r&&(i=i.slice(0,r.index).trim()),{name:n,value:i,important:!!r}}function _(e,t){if(e==null)return null;let n=null;for(let i of ke(String(e))){let r=Le(i);!r||r.name!==t||(!n||r.important||!n.important)&&(n=r)}return n?n.value:null}function Ie(e,t,n){let i=e==null?"":String(e),r=n==null||n==="",o=ke(i),l=o.map(Le),c=l.some(h=>h&&h.name===t&&h.important),s=[],f=!1;o.forEach((h,p)=>{let T=l[p];if(!T||T.name!==t){s.push(h);return}if(r||f)return;let a=/^\s*/.exec(h)[0];s.push(`${a}${t}: ${n}${c?" !important":""}`),f=!0});let u=s.join(";");if(!r&&!f){let h=u.trimEnd();u=h===""?`${t}: ${n}`:`${h}${h.endsWith(";")?" ":"; "}${t}: ${n}`}return u.trim()===""?null:u}function re(e,t,n,i){let r=e.attr(t,"style");if((_(r,n)??"")===i)return;let o=Ie(r,n,i);o==null?e.removeAttr(t,"style"):e.attr(t,"style",o)}function M(e,t,n,i={}){if(Object.prototype.hasOwnProperty.call(i,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return me(e,t,n,{depth:0,path:[]},i)}function me(e,t,n,i,r){if(i.depth>$)throw new L(i.path);if(typeof n=="string")return At(e,t,n,i,r);if(Array.isArray(n)){let[o,l]=n,c=e.find(t,o,r);return je(r,i,c),c.map((s,f)=>me(e,s,l,{depth:i.depth+1,path:[...i.path,f]},r))}if(typeof n=="object"&&n!==null){let o={};for(let[l,c]of Object.entries(n))o[l]=me(e,t,c,{depth:i.depth+1,path:[...i.path,l]},r);return o}return null}function At(e,t,n,i,r){if(n.endsWith("[]")){let f=n.slice(0,-2),u=e.find(t,f,r);return je(r,i,u),u.map(h=>e.text(h))}if(n.startsWith("@"))return pe(e,t,n.slice(1));let o=N(n);if(o!==-1){let{selector:f,all:u}=b(n),h=n.slice(o+1),p=f?e.find(t,f,r):[t];return u&&r.allMatches?p.map(T=>pe(e,T,h)):p.length===0?null:pe(e,p[0],h)}if(n===".")return e.text(t);let{selector:l,all:c}=b(n),s=e.find(t,l,r);return c&&r.allMatches?s.map(f=>e.text(f)):s.length===0?null:e.text(s[0])}function je(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(i){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,i)}}function pe(e,t,n){if(P(n))return _(e.attr(t,"style"),n);if(te.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let i=e.attr(t,n);return i??null}function De(e,t,n,i){let r=e.length,o=t.length,l=new Array(r).fill(-1);if(i){let d=new Set;for(let y=0;y<r;y++){let A=i[y];!(A>=0&&A<o)||d.has(A)||(l[y]=A,d.add(A))}}if(r===0||o===0)return l;let c=e.map(d=>$e(d,n)),s=t.map(d=>$e(d,n)),f=new Array(o).fill(!1);for(let d of l)d>=0&&(f[d]=!0);let u=new Map;s.forEach((d,y)=>{f[y]||u.set(d,u.has(d)?-1:y)});let h=new Map;c.forEach((d,y)=>{l[y]>=0||h.set(d,(h.get(d)||0)+1)}),c.forEach((d,y)=>{if(l[y]>=0||h.get(d)!==1)return;let A=u.get(d);A===void 0||A===-1||f[A]||(l[y]=A,f[A]=!0)});let p=[];for(let d=0;d<r;d++)l[d]<0&&p.push(d);let T=[];for(let d=0;d<o;d++)f[d]||T.push(d);if(p.length===0||T.length===0)return l;let a=r*o+1,m=Tt(e,t,n),g=(d,y)=>m(d,y)*a+Math.abs(d-y);for(let[d,y]of wt(p,T,g))l[d]=y;return l}var We=e=>typeof e=="object"&&e!==null;function $e(e,t){if(!We(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(i=>{let r=JSON.stringify(e?.[i]);return r===void 0?" undef":r}))}function Tt(e,t,n){if(!We(n))return(c,s)=>e[c]===t[s]?0:1;let i=Object.keys(n),r=c=>i.map(s=>JSON.stringify(c?.[s])),o=e.map(r),l=t.map(r);return(c,s)=>{let f=o[c],u=l[s],h=0;for(let p=0;p<i.length;p++)f[p]!==u[p]&&h++;return h}}function wt(e,t,n){return e.length<=t.length?_e(e,t,n,!1):_e(t,e,(i,r)=>n(r,i),!0)}function _e(e,t,n,i){let r=e.length,o=t.length,l=[];for(let h=0;h<=r;h++)l.push(new Float64Array(o+1).fill(1/0));let c=[];for(let h=0;h<=r;h++)c.push(new Uint8Array(o+1));for(let h=0;h<=o;h++)l[r][h]=0;for(let h=r-1;h>=0;h--)for(let p=o-1;p>=0;p--){let T=n(e[h],t[p])+l[h+1][p+1],a=l[h][p+1];T<=a?(l[h][p]=T,c[h][p]=1):l[h][p]=a}let s=[],f=0,u=0;for(;f<r&&u<o;)c[f][u]&&(s.push(i?[t[u],e[f]]:[e[f],t[u]]),f++),u++;return s}function ge(e,t,n,i,r,o,l,c={}){let s=e.find(t,n,c);if(r.length===0){s.forEach(w=>e.remove(w)),ye(c,"onRowsApplied",o.path,[]);return}let f=r.length>s.length,u=s[0]||null;if(f&&!u&&(u=xt(e,t,n,c),!u))throw new C(o.path);let h=s.map(w=>St(e,w,i,c)),p=null;if(f&&u){p=e.clone(u),c.templateAttr&&e.removeAttr(p,c.templateAttr);let w=e.stripIds(p);w>0&&console.warn(`[hyper-html-api] stripped ${w} id attribute(s) from cloned template at "${o.path.join(".")||"(root)"}"`)}let T=De(r,h,i,Et(e,s,r,o,c)),a=s.length>0?e.parent(s[0]):Ct(e,t,n,u,o,c),m=s.length>0?Ve(e,a,s[0]):0,g=kt(e,s),d=new Set,y=[],A=r.map((w,x)=>{let O=T[x];if(O>=0)return d.add(O),y.push(!1),s[O];y.push(!0);let E=e.clone(p);return e.stripIds(E),E});s.forEach((w,x)=>{d.has(x)||e.remove(w)}),g?Mt(e,a,m,A,y):Lt(e,A,y,a,m),Ot(e,A,i,r,o,l,c),ye(c,"onRowsApplied",o.path,A)}function ye(e,t,n,i){if(typeof e[t]=="function")try{return e[t](n.slice(),i)}catch(r){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,r);return}}function Et(e,t,n,i,r){let o=ye(r,"identifyRows",i.path,n);if(!Array.isArray(o))return null;let l=new Array(n.length).fill(-1),c=new Set,s=new Map(t.map((f,u)=>[e.identity(f),u]));for(let f=0;f<n.length;f++){if(!o[f])continue;let u=s.get(e.identity(o[f]));u===void 0||c.has(u)||(l[f]=u,c.add(u))}return l}function Ot(e,t,n,i,r,o,l){t.forEach((c,s)=>{if(n===null){let f=i[s],u=f==null?"":String(f);e.text(c)!==u&&e.text(c,u)}else{let f=o(e,c,n,i[s],{depth:r.depth+1,path:[...r.path,s]},l);f&&f!==c&&(t[s]=f)}})}function St(e,t,n,i){return n===null?e.text(t):M(e,t,n,i.onRowsRead?{...i,onRowsRead:void 0}:i)}function Ve(e,t,n){let i=e.children(t);for(let r=0;r<i.length;r++)if(e.sameNode(i[r],n))return r;return-1}function xt(e,t,n,i){if(!i.templateAttr)return null;let r=/^\s*:scope\s*>\s*/.test(n),o=new RegExp(":not\\(\\["+i.templateAttr.replace(/[.*+?^${}()|[\]\\-]/g,"\\$&")+"\\]\\)","g"),l=n.replace(/^\s*:scope\s*>\s*/,"").replace(o,""),c=r?bt(l):0,s=de(l),f=t;for(;f;){let u=e.find(f,l,{includeRulesTag:!1,templateAttr:null});for(let h of u)if(e.attr(h,i.templateAttr)!=null&&!(r&&!Nt(e,t,h,c))&&!(s&&!e.matches(e.parent(h),s)))return h;f=e.parent(f)}return null}function bt(e){let t=0,n=null,i=1;for(let r=0;r<e.length;r++){let o=e[r];if(o==="\\")r++;else if(n)o===n&&(n=null);else if(o==='"'||o==="'")n=o;else if(o==="["||o==="(")t++;else if(o==="]"||o===")")t>0&&t--;else if(t===0&&o===">")i++;else{if(t===0&&(o==="+"||o==="~"))return null;if(t===0&&/\s/.test(o)){if(!Rt(e,r))return null;for(;r+1<e.length&&/\s/.test(e[r+1]);)r++}}}return i}function Rt(e,t){let n=t;for(;n<e.length&&/\s/.test(e[n]);)n++;let i=t>0?e[t-1]:"",r=n<e.length?e[n]:"";return ve(i)||ve(r)}function ve(e){return e===">"||e==="+"||e==="~"}function Nt(e,t,n,i){if(i===null)return!0;let r=n;for(let s=0;s<i;s++)if(r=e.parent(r),!r)return!1;let o=e.prop(t,"tagName");if(!o)return!0;let l=e.prop(r,"tagName");if(!l||String(l).toLowerCase()!==String(o).toLowerCase())return!1;let c=new Set(Be(e,r));return Be(e,t).every(s=>c.has(s))}function Be(e,t){let n=e.attr(t,"class");return n?String(n).split(/\s+/).filter(Boolean):[]}function Ct(e,t,n,i,r,o){let l=e.parent(i);if(l&&Pt(e,t,l)&&!qe(e,l,o))return l;let c=de(n);if(!c)throw new C(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 f=(c===":scope"?e.prop(t,"tagName")?[t]:[]:e.find(t,c,o)).filter(u=>!qe(e,u,o));if(f.length===0)throw new C(r.path,`no container matching "${c}" inside this context to hold the new rows`);if(f.length>1)throw new C(r.path,`"${c}" matches ${f.length} containers inside this context, so the new rows have no single destination`);return f[0]}function Pt(e,t,n){let i=n;for(;i;){if(e.sameNode(i,t))return!0;i=e.parent(i)}return e.parent(t)?!1:e.find(t,"*",{includeRulesTag:!0,templateAttr:null}).some(r=>e.sameNode(r,n))}var He=["no-data","editor-ui"];function qe(e,t,n){let i=t;for(;i;){if(n.templateAttr&&e.attr(i,n.templateAttr)!=null||He.some(o=>e.attr(i,o)!=null))return!0;let r=e.attr(i,"clay");if(r&&r.split(/\s+/).some(o=>He.includes(o)))return!0;i=e.parent(i)}return!1}function Mt(e,t,n,i,r){let o=e.children(t),l=o.map(s=>e.identity(s)),c=!1;i.forEach((s,f)=>{let u=e.identity(s),h=n+f;if(l[h]===u)return;if(!r[f]){let T=l.indexOf(u);T!==-1&&(l.splice(T,1),o.splice(T,1))}let p=Math.min(h,o.length);p<o.length?e.insertBefore(o[p],s):o.length?c?e.insertAfter(o[o.length-1],s):(e.insertAt(t,s,h),c=!0):e.insertAt(t,s,0),l.splice(p,0,u),o.splice(p,0,s)})}function kt(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let i=new Map(e.children(n).map((o,l)=>[e.identity(o),l])),r=[];for(let o of t){let l=i.get(e.identity(o));if(l===void 0)return!1;r.push(l)}return r.sort((o,l)=>o-l),r[r.length-1]-r[0]===r.length-1}function Lt(e,t,n,i,r){let o=null,l=r;for(let c=0;c<t.length;c++){if(!n[c]){o=t[c];continue}let s=o?e.parent(o):i;if(!s)continue;let f=o?Ve(e,s,o)+1:l++;e.insertAt(s,t[c],f),o=t[c]}}function I(e,t,n,i,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 o=[];if(Ae(n,i,[],o),o.length)throw new q(o);ie(e,t,n,i,{depth:0,path:[]},r)}function ie(e,t,n,i,r,o={}){if(r.depth>$)throw new L(r.path);if(i===void 0)return t;if(typeof n=="string")return It(e,t,n,i,r,o);if(Array.isArray(n)){let[l,c]=n;return ge(e,t,l,c,i,r,ie,o),t}if(typeof n=="object"&&n!==null){for(let[l,c]of Object.entries(n)){let s=ie(e,t,c,i==null?i:i[l],{depth:r.depth+1,path:[...r.path,l]},o);s&&s!==t&&(t=s)}return t}return t}function It(e,t,n,i,r,o){if(n.endsWith("[]")){let u=n.slice(0,-2);return ge(e,t,u,null,i,r,ie,o),t}if(n.startsWith("@"))return ze(e,t,n.slice(1),i);let l=N(n);if(l!==-1){let{selector:u,all:h}=b(n),p=n.slice(l+1),T=u?e.find(t,u,o):[t];for(let a of h?T:T.slice(0,1))ze(e,a,p,i);return t}if(n===".")return Ue(e,t,i),t;let{selector:c,all:s}=b(n),f=e.find(t,c,o);for(let u of s?f:f.slice(0,1))Ue(e,u,i);return t}function Ue(e,t,n){let i=n==null?"":String(n);e.text(t)!==i&&e.text(t,i)}function jt(e,t,n,i){if(e.styleVar){e.styleVar(t,n,i);return}re(e,t,n,i)}function ze(e,t,n,i){if(P(n))return jt(e,t,n,i==null?"":String(i).trim()),t;if(B.has(n)){let r=e.prop(t,n);if(r===i||r!=null&&i!=null&&String(r)===String(i))return t;throw new V(n)}if(n==="outerHTML"){let r=i==null?"":String(i);return e.replaceWith(t,r)}if(fe.has(n)){let r=ue(n,i);return e.prop(t,n)!==r&&e.prop(t,n,r),t}if(i==null)e.attr(t,n)!=null&&e.removeAttr(t,n);else{let r=String(i);e.attr(t,n)!==r&&e.attr(t,n,r)}return t}function Ae(e,t,n,i){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((r,o)=>{typeof r=="object"&&r!==null&&i.push({path:F([...n,o]),expected:"scalar",got:z(r)})}):i.push({path:F(n),expected:"array",got:z(t)});return}t!==null&&typeof t=="object"&&i.push({path:F(n),expected:"scalar",got:z(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){i.push({path:F(n),expected:"array",got:z(t)});return}let r=e[1];t.forEach((o,l)=>Ae(r,o,[...n,l],i));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){i.push({path:F(n),expected:"object",got:z(t)});return}for(let[r,o]of Object.entries(e))Ae(o,t[r],[...n,r],i)}}}function z(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function F(e){return e.join(".")}function Te(e){try{return JSON.parse(e)}catch(t){throw new j(`Invalid strict JSON: ${t.message}`,t)}}function K(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 o=[],l=0;for(;l<r.length;){let c=r[l];if(/\s/.test(c)){l++;continue}if("{}".includes(c)){o.push({type:c,value:c}),l++;continue}if(c==="["){let h=!1,p=l+1;for(;p<r.length&&/\s/.test(r[p]);)p++;if(p<r.length&&/[a-zA-Z_]/.test(r[p])&&(h=!0),!h){o.push({type:c,value:c}),l++;continue}}if(c==="]"){o.push({type:c,value:c}),l++;continue}if(c===":"){o.push({type:t.COLON,value:c}),l++;continue}if(c===","){o.push({type:t.COMMA,value:c}),l++;continue}if(c==='"'||c==="'"){let h=c,p=l+1;for(;p<r.length&&r[p]!==h;)r[p]==="\\"&&p++,p++;o.push({type:t.STRING,value:r.substring(l+1,p),quoted:!0,sourceQuote:h}),l=p+1;continue}let s=l,f;for(;s<r.length&&!/[{},]/.test(r[s]);)if(r[s]===":"){let h=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],p=!1;for(let T of h){let a=T.substring(1);if(r.substring(s+1,s+1+a.length)===a){p=!0,s+=a.length;break}}if(!p)break}else if(r[s]==="["){for(s++;s<r.length&&r[s]!=="]";){if(r[s]==='"'||r[s]==="'"){let h=r[s];for(s++;s<r.length&&r[s]!==h;)r[s]==="\\"&&s++,s++}s++}s<r.length&&r[s]==="]"&&s++}else s++;f=r.substring(l,s);let u=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(f)?u=t.NUMBER:f==="true"||f==="false"||f==="null"?u=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(f)&&(u=t.SELECTOR),o.push({type:u,value:f,quoted:!1}),l=s}return o}function i(r){let o="";for(let l=0;l<r.length;l++){let c=r[l];if("{}".includes(c.type)||"[]".includes(c.type)){o+=c.value;continue}if(c.type===t.COLON){o+=c.value;continue}if(c.type===t.COMMA){let s=r[l+1];if(s&&(s.type==="}"||s.type==="]"))continue;o+=c.value;continue}if(c.type===t.STRING&&c.quoted){let s=c.value;c.sourceQuote==="'"&&(s=s.replace(/\\'/g,"'"),s=s.replace(/(\\*)"/g,(f,u)=>u.length%2===0?u+'\\"':f)),o+=`"${s}"`;continue}if(c.type===t.NUMBER||c.type===t.BOOLEAN){o+=c.value;continue}if(c.type===t.SELECTOR||c.type===t.IDENTIFIER){o+=`"${c.value}"`;continue}o+=`"${c.value}"`}return o}try{let r=n(e),o=i(r);return JSON.parse(o)}catch(r){throw new j("Invalid extraction rules syntax: "+r.message,r)}}var $t="1",Fe=/^[a-zA-Z0-9_-]+$/;function D(e,t,n){let i;if(n===void 0)i="script[data-rules-name]";else{if(typeof n!="string"||!Fe.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${Fe})`);i=`script[data-rules-name~="${n}"]`}let r=e.find(t,i,{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 o=r[0],l=e.attr(o,"data-rules-version");if(l!==$t)throw new H(l);return{rules:K(e.text(o)),tagNode:o}}var oe=Object.freeze({data:Object.freeze({tokens:["no-data"],bundles:["editor-ui"]}),save:Object.freeze({tokens:["no-save"],bundles:["editor-ui"]}),snapshot:Object.freeze({tokens:["no-snapshot"],bundles:["editor-ui"]}),watch:Object.freeze({tokens:["no-watch"],bundles:["editor-ui"]}),undo:Object.freeze({tokens:["no-undo"],bundles:["editor-ui"]}),history:Object.freeze({tokens:[],bundles:["editor-ui"]})}),_t=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),Ke=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 we(e,t){if(J(e,t))return!0;for(let[n,i]of Object.entries(_t))if(i.includes(t)&&J(e,n))return!0;return!1}function X(e){let t=oe[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function Dt(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let i=oe[t];if(!i)throw new Error(`Unknown region capability: ${t}`);if(i.tokens.some(r=>we(n,r))||i.bundles.some(r=>J(n,r)))return n;n=n.parentElement}return null}function Je(e,t){return!!Dt(e,t)}var se=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",...Ke],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"]})}),Wt=new Set(["textContent","innerText"]);function Xe(e){let n=String(e).replace(/^[\u0000- ]+|[\u0000- ]+$/g,"").replace(/[\t\n\r]/g,"").match(/^([a-zA-Z][a-zA-Z0-9+.-]*):/);return n?n[1].toLowerCase():null}var vt=/^[^\t\n\f\r "'>/=\u0000-\u001f\u007f]+$/;function Ye(e,t,n=se){if(!vt.test(String(e)))return`attribute name ${JSON.stringify(String(e))} is not valid`;let i=String(e).toLowerCase();if(n.refusedAttributePrefixes.some(r=>i.startsWith(r)))return`attribute "${i}" can run script`;if(n.refusedAttributes.includes(i))return`attribute "${i}" is not content`;if(n.urlAttributes.includes(i)&&t!=null){let r=i==="srcset"?String(t).split(",").map(o=>o.trim().split(/\s+/)[0]).filter(Boolean):[String(t)];for(let o of r){let l=Xe(o);if(l&&n.refusedSchemes.includes(l))return`"${l}:" URLs are not allowed in "${i}"`}}return null}function Ee(e,t){let n=e.prop(t,"tagName");return n?String(n).toLowerCase():""}function Bt(e,t){let n=Ee(e,t)||"node",i=e.attr(t,"id");return i?`<${n}#${i}>`:`<${n}>`}function Ht(e,t,n){let i=t;for(;i;){let r=Ee(e,i);if(r&&n.refusedTargets.includes(r))return r;i=e.parent(i)}return null}function Ge(e,t){return e.find(t,"script[data-rules-name]",{includeRulesTag:!0,templateAttr:null}).length>0}function qt(e,t){return Ee(e,t)==="script"&&e.attr(t,"data-rules-name")!=null?!0:Ge(e,t)}function Vt(e){if(/[\u0000-\u001f\u007f]/.test(e))return"control characters are not allowed in a custom property value";let t=[],n=null;for(let i=0;i<e.length;i++){let r=e[i];if(n){r===n&&(n=null);continue}if(r==='"'||r==="'")n=r;else{if(r==="/"&&e[i+1]==="*")return"comments are not allowed in a custom property value";if(r==="(")t.push(")");else if(r==="[")t.push("]");else if((r===")"||r==="]")&&t.pop()!==r)return`"${r}" does not close anything in this custom property value`}}return n?"a custom property value must close its quotes":t.length?"a custom property value must close its brackets":null}function Ze(e,t=se){let n=t.customPropertyValues,i=String(e);if(i.length>n.maxLength)return`custom property values are limited to ${n.maxLength} characters`;let r=n.refusedCharacters.find(s=>i.includes(s));if(r)return`${JSON.stringify(r)} is not allowed in a custom property value`;let o=Vt(i);if(o)return o;let l=i.toLowerCase(),c=n.refusedFunctions.find(s=>new RegExp(`(^|[^a-z0-9_-])${s.replace(/[-]/g,"\\-")}\\s*\\(`).test(l));return c?`"${c}()" is not allowed in a custom property value`:null}function le(e,t=se){let n=[],i=(s,f)=>(n.push({target:Bt(e,s),reason:f}),!1),r=s=>{let f=Ht(e,s,t);return f?i(s,`inside <${f}>, which is not content`):!0},o=s=>r(s)?Ge(e,s)?i(s,"a text write here would delete the data rules tag"):!0:!1,l=(s,f,u)=>{if(!r(s))return!1;let h=Ye(f,u,t);return h?i(s,h):!0};return{...e,text(s,f){if(f===void 0)return e.text(s);o(s)&&e.text(s,f)},attr(s,f,u){if(u===void 0)return e.attr(s,f);l(s,f,u)&&e.attr(s,f,u)},removeAttr(s,f){l(s,f,null)&&e.removeAttr(s,f)},styleVar(s,f,u){if((_(e.attr(s,"style"),f)??"")!==u&&r(s)){if(!P(f))return i(s,`"${f}" is not a custom property`);if(u!==""){let h=Ze(u,t);if(h)return i(s,h)}re(e,s,f,u)}},prop(s,f,u){if(u===void 0)return e.prop(s,f);if(t.refusedRuleForms.includes(f))return i(s,`"@${f}" writes HTML, only text is allowed`);if(Wt.has(f)){o(s)&&e.prop(s,f,u);return}l(s,f==="className"?"class":f,u)&&e.prop(s,f,u)},remove(s){if(qt(e,s)){i(s,"removing this would delete the data rules tag");return}e.remove(s)},replaceWith(s,f){return f===e.prop(s,"outerHTML")||i(s,'"@outerHTML" writes HTML, only text is allowed'),s},refusals:n,assertClean(){if(n.length)throw new U(n.slice())}}}function Y(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Qe(e){return e.reduce((t,n)=>typeof n=="number"?`${t}[${n}]`:t?`${t}.${n}`:n,"")}function Oe(e,t,n,i,r={}){let o=[],l=[];function c(f,u,h){if(Array.isArray(f)){let[,p]=f;if(!Array.isArray(u)||!Y(p))return;u.forEach((T,a)=>c(p,T,[...h,a]));return}if(!(!Y(f)||!Y(u)))for(let p of Object.keys(u))Object.prototype.hasOwnProperty.call(f,p)?c(f[p],u[p],[...h,p]):o.push(Qe([...h,p]))}function s(f,u,h,p){if(h!==void 0){if(typeof u=="string"){if(u.endsWith("[]")||u==="."||u.startsWith("@"))return;let{selector:T}=b(u);if(!T)return;e.find(f,T,r).length===0&&l.push({path:Qe(p),selector:T});return}if(!Array.isArray(u)&&Y(u)&&Y(h))for(let[T,a]of Object.entries(u))s(f,a,h[T],[...p,T])}}return c(n,i,[]),s(t,n,i,[]),{unknownKeys:o,unmatched:l}}function Se(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let i=t&&t.ownerDocument?t.ownerDocument:t;return D(e,i,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 et(e,t,n,i){if(i)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 tt(e,t,n,i,r,o){return(o?Je(e,t):et(e,n,r,!1))||!!(i&&(o&&e!==r?e.matches(i):et(e,i,r,o)))}function Kt(e,t){let n=oe[t];return n.tokens.some(i=>we(e,i))||n.bundles.some(i=>J(e,i))}var Jt=new Set(["INPUT","TEXTAREA","SELECT","OPTION"]);function nt(e,t,n,i){if(e.nodeType===1&&i(e)){n.dropped.push(t);return}n.cloneToLive.set(t,e),n.liveToClone.set(e,t);let r=e,o=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,o=t.content,n.cloneToLive.set(o,r),n.liveToClone.set(r,o)}}else if(e.nodeType!==11)return;let l=o.firstChild;for(let c=r.firstChild;c&&l;c=c.nextSibling)nt(c,l,n,i),l=l.nextSibling}function G(e,{capability:t="data",exclude:n=null,inherit:i=!0,provenance:r=null}={}){if(!e)throw new TypeError("createContentView requires a DOM context");let o=e.nodeType===9?e:e.ownerDocument;if(!o?.implementation?.createHTMLDocument)throw new TypeError("createContentView requires an HTML DOM implementation");let l=o.implementation.createHTMLDocument(""),c=r||new WeakMap,s=new WeakMap,f=e.nodeType===9?e.documentElement:e;n&&l.documentElement.matches(n);let u=X(t),h=i?a=>Kt(a,t)||!!(n&&a.matches(n)):a=>tt(a,t,u,n,f,!1),p=null;if(f.nodeType!==1||!tt(f,t,u,n,f,i)){p=l.importNode(f,!0);let a={cloneToLive:c,liveToClone:s,dropped:[],controls:[]};nt(f,p,a,h);for(let m of a.dropped)m.remove();for(let m=0;m<a.controls.length;m+=2)Ft(a.controls[m],a.controls[m+1])}e.nodeType===9&&p&&(l.replaceChild(p,l.documentElement),s.set(e,l),c.set(l,e));let T=a=>{if(zt.test(a))throw new Error(`Filtered content queries do not support stateful selector: ${a}`)};return{root:p,document:l,capability:t,selector:X(t),cloneToLive:c,liveToClone:s,original(a){return c.get(a)||null},cloneOf(a){return s.get(a)||null},query(a,m=p){return T(a),Array.from(m.querySelectorAll(a),g=>c.get(g)||g)},text(a=p){return(a===p?p:s.get(a))?.textContent||""},html(a=p){return(a===p?p:s.get(a))?.innerHTML??""},clone(a=p){let m=a===p?p:s.get(a);return m?l.importNode(m,!0):null}}}function it(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function Xt(e){return e?(e.nodeType===9||e.nodeType===11,e):null}function rt(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 ot(e,t){e&&e.tagName==="TEXTAREA"&&(e.value=t)}function st(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 i=n.type;i!=="file"&&i!=="checkbox"&&i!=="radio"&&(n.value=n.defaultValue),n.checked=n.defaultChecked}else n.tagName==="OPTION"&&(n.selected=n.defaultSelected)}var S={semanticExclude:!0,find(e,t,n={}){let i=Xt(e);if(!i||!i.querySelectorAll)return[];let r=Array.from(i.querySelectorAll(t));n.includeRulesTag||(r=r.filter(c=>!it(c)));let o=[];n.skip&&o.push(n.skip);let l=n.templateAttr===null?null:n.templateAttr||"cms-template";if(l&&o.push("["+l+"]"),o.length){let c=o.join(", ");r=r.filter(s=>!s.closest||!s.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,ot(e,t)},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n),rt(e,t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t),rt(e,t,null)},prop(e,t,n){if(n===void 0){let i=e?e[t]:void 0;return i!==void 0?i:null}e[t]=n},clone(e){let t=e.cloneNode(!0);return st(t),t},insertAt(e,t,n){let i=e.children[n]||null;e.insertBefore(t,i)},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 i=e.ownerDocument.createElement("template");i.innerHTML=t;let r=i.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(i=>{i.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};function k(e,t={}){if(t.exclude===null)return S;let n=[X("data"),t.exclude].filter(Boolean).join(", "),i=e.nodeType===9?e:e.ownerDocument||e,r=e.nodeType===9?e.documentElement:e;if(!t._write&&!r?.matches?.(n)&&!r?.querySelector?.(n)&&!i?.querySelector?.(n))return S;let o=e.nodeType===9||!e.isConnected?e:e.ownerDocument,l=e.nodeType===9?e:e.ownerDocument,c=null,s=()=>c||(c=G(o,{capability:"data",exclude:t.exclude||null})),f=a=>{let m=s();return a===e?m.cloneOf(e):m.cloneOf(a)||a},u=a=>c?.original(a)||a,h=(a,m)=>{s().liveToClone.set(a,m),s().cloneToLive.set(m,a);let g=a.childNodes||[],d=m.childNodes||[];for(let y=0;y<Math.min(g.length,d.length);y++)h(g[y],d[y])},p=(a,m,g,d)=>{let y=Array.from(a.childNodes).filter(E=>c.cloneOf(E)),w=y[0];for(;w&&y.includes(w);)w=w.nextSibling;for(let E of y)E.remove();if(g==="innerHTML"){let E=l.createElement("template");E.innerHTML=d;for(let v of Array.from(E.content.childNodes))a.insertBefore(v,w||null)}else a.insertBefore(l.createTextNode(d),w||null),ot(a,d);let x=G(a,{capability:"data",exclude:t.exclude||null});m.replaceChildren(...Array.from(x.root?.childNodes||[]));let O=E=>{let v=x.original(E);v&&(c.liveToClone.set(v,E),c.cloneToLive.set(E,v));for(let ct of Array.from(E.childNodes||[]))O(ct)};for(let E of Array.from(m.childNodes))O(E)},T={...S,find(a,m,g={}){let d=f(a);if(!d?.querySelectorAll)return[];let y=s().query(m,d);g.includeRulesTag||(y=y.filter(x=>!it(x)));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 x=A.join(", ");y=y.filter(O=>!O.closest?.(x))}return y},parent(a){let m=f(a)?.parentElement;return m?u(m):null},children(a){return Array.from(f(a)?.children||[],u)},text(a,m){if(m===void 0){let y=u(a);return!y?.matches?.(n)&&!y?.querySelector?.(n)?S.text(y):(f(a)?.textContent||"").trim()}let g=u(a);if(!g?.matches?.(n)&&!g?.querySelector?.(n)&&!c){S.text(g,m);return}let d=s().cloneOf(g);d?p(g,d,"textContent",m):S.text(g,m)},attr(a,m,g){let d=u(a);if(g===void 0)return S.attr(d,m);S.attr(d,m,g);let y=c?.cloneOf(d);y&&(S.attr(y,m,g),G(d,{capability:"data",exclude:t.exclude||null}).root===null&&(y.remove(),c.liveToClone.delete(d),c.cloneToLive.delete(y)))},removeAttr(a,m){let g=u(a);S.removeAttr(g,m);let d=c?.cloneOf(g);d&&S.removeAttr(d,m)},prop(a,m,g){let d=u(a);if(g===void 0)return m==="innerHTML"||m==="outerHTML"||m==="textContent"||m==="innerText"?S.prop(f(d),m):S.prop(d,m);let y=m==="innerHTML"||m==="textContent"||m==="innerText",A=y?s().cloneOf(d):c?.cloneOf(d);A&&y?p(d,A,m,g):(S.prop(d,m,g),A&&S.prop(A,m,g))},clone(a){let m=f(a);if(m===a)return S.clone(a);let g=l.importNode(m,!0);return st(g),g},insertAt(a,m,g){let d=u(a),A=T.children(d)[g]||(()=>{for(let O=d.children.length-1;O>=0;O--){let E=d.children[O];if(s().cloneOf(E))return E.nextElementSibling}return d.firstElementChild})(),w=u(m);d.insertBefore(w,A||null);let x=s().cloneOf(d);if(x){let O=s().cloneOf(w);O||(O=l.importNode(w,!0),h(w,O));let E=Array.from(x.children);x.insertBefore(O,E[g]||null)}},insertBefore(a,m){let g=u(a),d=u(m);g.parentNode.insertBefore(d,g);let y=s().cloneOf(g.parentNode);if(y){let A=s().cloneOf(d);A||(A=l.importNode(d,!0),h(d,A));let w=s().cloneOf(g);w?w.before(A):y.appendChild(A)}},insertAfter(a,m){let g=u(a),d=u(m);g.parentNode.insertBefore(d,g.nextSibling);let y=s().cloneOf(g.parentNode);if(y){let A=s().cloneOf(d);A||(A=l.importNode(d,!0),h(d,A));let w=s().cloneOf(g);w?w.after(A):y.appendChild(A)}},identity(a){return u(a)||null},remove(a){let m=u(a),g=s().cloneOf(m);S.remove(m),g&&S.remove(g)},replaceWith(a,m){let g=u(a),d=s().cloneOf(g),y=S.replaceWith(g,m);if(d){let A=G(y,{capability:"data",exclude:t.exclude||null});if(!A.root)d.remove();else{d.replaceWith(A.root);let w=x=>{let O=A.original(x);O&&(c.liveToClone.set(O,x),c.cloneToLive.set(x,O));for(let E of Array.from(x.childNodes||[]))w(E)};w(A.root)}}return y}};return T}var Z=S;var Q={extract:(e,t,n={})=>M(k(e,n),e,t,n),apply:(e,t,n,i={})=>I(k(e,{...i,_write:!0}),e,t,n,i),findRulesIn:(e,t)=>D(Z,e,t),findRules:(e,t)=>Se(Z,e,t),bind:(e,t,n={})=>{let i=Se(Z,e,t);if(!i){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{...i,get:()=>M(k(e,n),e,i.rules,n),set:r=>I(k(e,{...n,_write:!0}),e,i.rules,r,n)}},parseStrict:Te,parseRelaxed:K,ruleAttrIndex:N,splitRule:b,errors:R,DOM_PROPERTIES:ee},xe=e=>!!e&&typeof e.nodeType=="number";function lt(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=D(Z,t,"api");if(!n)throw new R.NoRulesTag("api");return n.rules}function Yt(e){if(e.nodeType===9)return e;let t=e.ownerDocument?.documentElement;if(t?.contains(e))return t;let n=e;for(;n.parentNode;)n=n.parentNode;return n}function Gt(e){if(e.nodeType!==11||!e.host)return e.cloneNode(!0);let t=e.ownerDocument.createDocumentFragment();for(let n of e.childNodes)t.appendChild(n.cloneNode(!0));return t}function Zt(e,t){let n=[];for(;t!==e;){let i=t.parentNode;n.push(Array.prototype.indexOf.call(i.childNodes,t)),t=i}return n.reverse()}function Qt(e,t){return t.reduce((n,i)=>n.childNodes[i],e)}function W(e,t){let n=e.querySelectorAll?Array.from(e.querySelectorAll(t)):[];return e.matches?.(t)&&n.unshift(e),n}function en(e,t){let n=W(e,"option"),i=W(t,"option");n.forEach((s,f)=>i[f].selected=s.selected);let r=W(e,"input"),o=W(t,"input");r.forEach((s,f)=>{let u=s.type.toLowerCase();u!=="file"&&(o[f].value=s.value),(u==="checkbox"||u==="radio")&&(o[f].checked=s.checked)});let l=W(e,"textarea"),c=W(t,"textarea");l.forEach((s,f)=>c[f].value=s.value)}function be(e,t){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]"))return;let n=e.startsWith("@")?0:N(e);if(n===-1)return;let i=e.slice(n+1);if(B.has(i))throw new R.RuleTargetReadOnly(i);return}if(Array.isArray(e)){if(!Array.isArray(t))return;t.forEach(n=>be(e[1],n));return}if(e&&typeof e=="object"&&t&&typeof t=="object"&&!Array.isArray(t))for(let[n,i]of Object.entries(e))be(i,t[n])}}function tn(e,t,n){let i={templateAttr:"cms-template"},r=Yt(e),o=Zt(r,e),l=Gt(r);en(r,l);let c=Qt(l,o),s=k(l,{...i,_write:!0}),f=Oe(s,c,t,n,i);if(f.unknownKeys.length||f.unmatched.length)throw new R.WriteRejected(f.unknownKeys,f.unmatched);let u=le(s);I(u,c,t,n,i),u.assertClean(),be(t,n);let h=le(k(r,{...i,_write:!0}));I(h,e,t,n,i),h.assertClean()}function nn(e){if(!(e instanceof Error))return e;let t=e.name||"Error";try{e.code=t}catch{Object.defineProperty(e,"code",{value:t,configurable:!0,enumerable:!0})}return e instanceof R.WriteRefused?e.details=e.refusals:e instanceof R.WriteRejected?e.details={unknownKeys:e.unknownKeys,unmatched:e.unmatched}:e instanceof R.ShapeMismatch?e.details=e.mismatches:Array.isArray(e.path)?e.details={path:e.path}:typeof e.target=="string"?e.details={target:e.target}:e.token!==void 0?e.details={token:e.token}:e.version!==void 0?e.details={version:e.version}:e.details={},e}function Re(e,t){let n=xe(e)?e:document,i=xe(e)?t:e;return i===void 0?M(k(n),n,lt(n)):Q.bind(n,i).get()}function Ne(e,t,n){try{if(!xe(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");let i=n===void 0?lt(e):Q.bind(e,n).rules;tn(e,i,t)}catch(i){throw nn(i)}return e}var rn={engine:Q,extractData:Re,applyData:Ne},on=rn;return dt(sn);})();
|