hyper-html-api 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- var hyperHtmlApiData=(()=>{var Y=Object.defineProperty;var ke=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var _e=Object.prototype.hasOwnProperty;var de=(e,t)=>{for(var n in t)Y(e,n,{get:t[n],enumerable:!0})},$e=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of De(t))!_e.call(e,r)&&r!==n&&Y(e,r,{get:()=>t[r],enumerable:!(o=ke(t,r))||o.enumerable});return e};var We=e=>$e(Y({},"__esModule",{value:!0}),e);var st={};de(st,{applyData:()=>ue,default:()=>it,engine:()=>z,extractData:()=>fe});var F=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],X=new Set(F),he=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),G=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var V={};de(V,{EmptyListInsert:()=>$,MAX_RULE_DEPTH:()=>I,MaxRuleDepthExceeded:()=>N,NoRulesTag:()=>Z,RuleTargetReadOnly:()=>W,RulesParseError:()=>L,ShapeMismatch:()=>_,UnknownRulesVersion:()=>D,WriteRefused:()=>K,WriteRejected:()=>Q});var L=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},D=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},I=20,N=class extends Error{constructor(t){super(`rule depth exceeded ${I} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},_=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},$=class extends Error{constructor(t){super(`cannot add items to empty list at "${t.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=t}},W=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},K=class extends Error{constructor(t){super(`write refused: ${t.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=t}},Z=class extends Error{constructor(t){super(`no <script data-rules-name~="${t}"> rules tag in this document`),this.name="NoRulesTag",this.token=t}},Q=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 R(e){let t=0,n=null,o=-1;for(let r=0;r<e.length;r++){let i=e[r];i==="\\"?r++:n?i===n&&(n=null):i==='"'||i==="'"?n=i:i==="["||i==="("?t++:i==="]"||i===")"?t>0&&t--:i==="@"&&t===0&&(o=r)}return o}function ee(e){let t=R(e);return t===-1?{selector:e,prop:null}:{selector:e.slice(0,t),prop:e.slice(t+1)||null}}function C(e,t,n,o={}){if(Object.prototype.hasOwnProperty.call(o,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return te(e,t,n,{depth:0,path:[]},o)}function te(e,t,n,o,r){if(o.depth>I)throw new N(o.path);if(typeof n=="string")return ve(e,t,n,o,r);if(Array.isArray(n)){let[i,c]=n,s=e.find(t,i,r);return me(r,o,s),s.map((l,u)=>te(e,l,c,{depth:o.depth+1,path:[...o.path,u]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[c,s]of Object.entries(n))i[c]=te(e,t,s,{depth:o.depth+1,path:[...o.path,c]},r);return i}return null}function ve(e,t,n,o,r){if(n.endsWith("[]")){let s=n.slice(0,-2),l=e.find(t,s,r);return me(r,o,l),l.map(u=>e.text(u))}if(n.startsWith("@"))return pe(e,t,n.slice(1));let i=R(n);if(i!==-1){let s=n.slice(0,i),l=n.slice(i+1),u=s?e.find(t,s,r):[t];return u.length===0?null:pe(e,u[0],l)}if(n===".")return e.text(t);let c=e.find(t,n,r);return c.length===0?null:e.text(c[0])}function me(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(o){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,o)}}function pe(e,t,n){if(X.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o||null}function we(e,t,n,o){let r=e.length,i=t.length,c=new Array(r).fill(-1);if(o){let f=new Set;for(let h=0;h<r;h++){let y=o[h];!(y>=0&&y<i)||f.has(y)||(c[h]=y,f.add(y))}}if(r===0||i===0)return c;let s=e.map(f=>ye(f,n)),l=t.map(f=>ye(f,n)),u=new Array(i).fill(!1);for(let f of c)f>=0&&(u[f]=!0);let a=new Map;l.forEach((f,h)=>{u[h]||a.set(f,a.has(f)?-1:h)});let g=new Map;s.forEach((f,h)=>{c[h]>=0||g.set(f,(g.get(f)||0)+1)}),s.forEach((f,h)=>{if(c[h]>=0||g.get(f)!==1)return;let y=a.get(f);y===void 0||y===-1||u[y]||(c[h]=y,u[y]=!0)});let d=[];for(let f=0;f<r;f++)c[f]<0&&d.push(f);let O=[];for(let f=0;f<i;f++)u[f]||O.push(f);if(d.length===0||O.length===0)return c;let m=r*i+1,p=(f,h)=>He(e[f],t[h],n)*m+Math.abs(f-h);for(let[f,h]of Be(d,O,p))c[f]=h;return c}var Ee=e=>typeof e=="object"&&e!==null;function ye(e,t){if(!Ee(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(o=>{let r=JSON.stringify(e?.[o]);return r===void 0?" undef":r}))}function He(e,t,n){if(!Ee(n))return e===t?0:1;let o=Object.keys(n);if(o.length===0)return 0;let r=0;for(let i of o){let c=JSON.stringify(e?.[i]),s=JSON.stringify(t?.[i]);c!==s&&r++}return r}function Be(e,t,n){return e.length<=t.length?ge(e,t,n,!1):ge(t,e,(o,r)=>n(r,o),!0)}function ge(e,t,n,o){let r=e.length,i=t.length,c=[];for(let g=0;g<=r;g++)c.push(new Float64Array(i+1).fill(1/0));let s=[];for(let g=0;g<=r;g++)s.push(new Uint8Array(i+1));for(let g=0;g<=i;g++)c[r][g]=0;for(let g=r-1;g>=0;g--)for(let d=i-1;d>=0;d--){let O=n(e[g],t[d])+c[g+1][d+1],m=c[g][d+1];O<=m?(c[g][d]=O,s[g][d]=1):c[g][d]=m}let l=[],u=0,a=0;for(;u<r&&a<i;)s[u][a]&&(l.push(o?[t[a],e[u]]:[e[u],t[a]]),u++),a++;return l}function re(e,t,n,o,r,i,c,s={}){let l=e.find(t,n,s);if(r.length===0){l.forEach(w=>e.remove(w)),ne(s,"onRowsApplied",i.path,[]);return}let u=r.length>l.length,a=l[0]||null;if(u&&!a&&(a=Fe(e,t,n,s),!a))throw new $(i.path);let g=l.map(w=>ze(e,w,o,s)),d=null;if(u&&a){d=e.clone(a),s.templateAttr&&e.removeAttr(d,s.templateAttr);let w=e.stripIds(d);w>0&&console.warn(`[hyper-html-api] stripped ${w} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let O=we(r,g,o,qe(e,l,r,i,s)),m=l[0]||a,p=e.parent(m),f=l.length>0?Te(e,p,m):0,h=Ke(e,l),y=new Set,x=[],A=r.map((w,T)=>{let E=O[T];if(E>=0)return y.add(E),x.push(!1),l[E];x.push(!0);let S=e.clone(d);return e.stripIds(S),S});l.forEach((w,T)=>{y.has(T)||e.remove(w)}),h?A.forEach((w,T)=>{let E=f+T;e.children(p).findIndex(Pe=>e.sameNode(Pe,w))!==E&&e.insertAt(p,w,E)}):Ve(e,A,x,p,f),Ue(e,A,o,r,i,c,s),ne(s,"onRowsApplied",i.path,A)}function ne(e,t,n,o){if(typeof e[t]=="function")try{return e[t](n.slice(),o)}catch(r){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,r);return}}function qe(e,t,n,o,r){let i=ne(r,"identifyRows",o.path,n);if(!Array.isArray(i))return null;let c=new Array(n.length).fill(-1),s=new Set;for(let l=0;l<n.length;l++)if(i[l]){for(let u=0;u<t.length;u++)if(!(s.has(u)||!e.sameNode(t[u],i[l]))){c[l]=u,s.add(u);break}}return c}function Ue(e,t,n,o,r,i,c){t.forEach((s,l)=>{if(n===null){let u=o[l],a=u==null?"":String(u);e.text(s)!==a&&e.text(s,a)}else{let u=i(e,s,n,o[l],{depth:r.depth+1,path:[...r.path,l]},c);u&&u!==s&&(t[l]=u)}})}function ze(e,t,n,o){return n===null?e.text(t):C(e,t,n,o.onRowsRead?{...o,onRowsRead:void 0}:o)}function Te(e,t,n){let o=e.children(t);for(let r=0;r<o.length;r++)if(e.sameNode(o[r],n))return r;return-1}function Fe(e,t,n,o){if(!o.templateAttr)return null;let r=t;for(;r;){let i=e.find(r,n,{includeRulesTag:!1,templateAttr:null});for(let c of i)if(e.attr(c,o.templateAttr)!=null)return c;r=e.parent(r)}return null}function Ke(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let o=e.children(n),r=[];for(let i of t){let c=o.findIndex(s=>e.sameNode(s,i));if(c===-1)return!1;r.push(c)}return r.sort((i,c)=>i-c),r[r.length-1]-r[0]===r.length-1}function Ve(e,t,n,o,r){let i=null,c=r;for(let s=0;s<t.length;s++){if(!n[s]){i=t[s];continue}let l=i?e.parent(i):o;if(!l)continue;let u=i?Te(e,l,i)+1:c++;e.insertAt(l,t[s],u),i=t[s]}}var Ae=new Set(["checked","selected","disabled","readOnly","paused"]);function j(e,t,n,o,r={}){if(Object.prototype.hasOwnProperty.call(r,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");let i=[];if(oe(n,o,[],i),i.length)throw new _(i);J(e,t,n,o,{depth:0,path:[]},r)}function J(e,t,n,o,r,i={}){if(r.depth>I)throw new N(r.path);if(o===void 0)return t;if(typeof n=="string")return Je(e,t,n,o,r,i);if(Array.isArray(n)){let[c,s]=n;return re(e,t,c,s,o,r,J,i),t}if(typeof n=="object"&&n!==null){for(let[c,s]of Object.entries(n)){let l=J(e,t,s,o==null?o:o[c],{depth:r.depth+1,path:[...r.path,c]},i);l&&l!==t&&(t=l)}return t}return t}function Je(e,t,n,o,r,i){if(n.endsWith("[]")){let l=n.slice(0,-2);return re(e,t,l,null,o,r,J,i),t}if(n.startsWith("@"))return Oe(e,t,n.slice(1),o);let c=R(n);if(c!==-1){let l=n.slice(0,c),u=n.slice(c+1),a=l?e.find(t,l,i):[t];return a.length===0||Oe(e,a[0],u,o),t}if(n===".")return xe(e,t,o),t;let s=e.find(t,n,i);return s.length===0||xe(e,s[0],o),t}function xe(e,t,n){let o=n==null?"":String(n);e.text(t)!==o&&e.text(t,o)}function Oe(e,t,n,o){if(G.has(n)){let i=e.prop(t,n);if(i===o||i!=null&&o!=null&&String(i)===String(o))return t;throw new W(n)}if(n==="outerHTML"){let i=o==null?"":String(o);return e.replaceWith(t,i)}if(he.has(n)){let i=Ye(n,o);return e.prop(t,n)!==i&&e.prop(t,n,i),t}let r=o==null?"":String(o);return e.attr(t,n)!==r&&e.attr(t,n,r),t}function Ye(e,t){return t==null?Ae.has(e)?!1:"":Ae.has(e)?t==="false"?!1:!!t:t}function oe(e,t,n,o){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((r,i)=>{typeof r=="object"&&r!==null&&o.push({path:H([...n,i]),expected:"scalar",got:v(r)})}):o.push({path:H(n),expected:"array",got:v(t)});return}t!==null&&typeof t=="object"&&o.push({path:H(n),expected:"scalar",got:v(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:H(n),expected:"array",got:v(t)});return}let r=e[1];t.forEach((i,c)=>oe(r,i,[...n,c],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:H(n),expected:"object",got:v(t)});return}for(let[r,i]of Object.entries(e))oe(i,t[r],[...n,r],o)}}}function v(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function H(e){return e.join(".")}function ie(e){try{return JSON.parse(e)}catch(t){throw new L(`Invalid strict JSON: ${t.message}`,t)}}function B(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(r){let i=[],c=0;for(;c<r.length;){let s=r[c];if(/\s/.test(s)){c++;continue}if("{}".includes(s)){i.push({type:s,value:s}),c++;continue}if(s==="["){let g=!1,d=c+1;for(;d<r.length&&/\s/.test(r[d]);)d++;if(d<r.length&&/[a-zA-Z_]/.test(r[d])&&(g=!0),!g){i.push({type:s,value:s}),c++;continue}}if(s==="]"){i.push({type:s,value:s}),c++;continue}if(s===":"){i.push({type:t.COLON,value:s}),c++;continue}if(s===","){i.push({type:t.COMMA,value:s}),c++;continue}if(s==='"'||s==="'"){let g=s,d=c+1;for(;d<r.length&&r[d]!==g;)r[d]==="\\"&&d++,d++;i.push({type:t.STRING,value:r.substring(c+1,d),quoted:!0,sourceQuote:g}),c=d+1;continue}let l=c,u;for(;l<r.length&&!/[{},]/.test(r[l]);)if(r[l]===":"){let g=[":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 O of g){let m=O.substring(1);if(r.substring(l+1,l+1+m.length)===m){d=!0,l+=m.length;break}}if(!d)break}else if(r[l]==="["){for(l++;l<r.length&&r[l]!=="]";){if(r[l]==='"'||r[l]==="'"){let g=r[l];for(l++;l<r.length&&r[l]!==g;)r[l]==="\\"&&l++,l++}l++}l<r.length&&r[l]==="]"&&l++}else l++;u=r.substring(c,l);let a=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(u)?a=t.NUMBER:u==="true"||u==="false"||u==="null"?a=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(u)&&(a=t.SELECTOR),i.push({type:a,value:u,quoted:!1}),c=l}return i}function o(r){let i="";for(let c=0;c<r.length;c++){let s=r[c];if("{}".includes(s.type)||"[]".includes(s.type)){i+=s.value;continue}if(s.type===t.COLON){i+=s.value;continue}if(s.type===t.COMMA){let l=r[c+1];if(l&&(l.type==="}"||l.type==="]"))continue;i+=s.value;continue}if(s.type===t.STRING&&s.quoted){let l=s.value;s.sourceQuote==="'"&&(l=l.replace(/\\'/g,"'"),l=l.replace(/(\\*)"/g,(u,a)=>a.length%2===0?a+'\\"':u)),i+=`"${l}"`;continue}if(s.type===t.NUMBER||s.type===t.BOOLEAN){i+=s.value;continue}if(s.type===t.SELECTOR||s.type===t.IDENTIFIER){i+=`"${s.value}"`;continue}i+=`"${s.value}"`}return i}try{let r=n(e),i=o(r);return JSON.parse(i)}catch(r){throw new L("Invalid extraction rules syntax: "+r.message,r)}}var Xe="1",be=/^[a-zA-Z0-9_-]+$/;function P(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!be.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${be})`);o=`script[data-rules-name~="${n}"]`}let r=e.find(t,o,{includeRulesTag:!0});if(r.length===0)return null;n!==void 0&&r.length>1&&console.warn(`hyper-html-api: ${r.length} rules tags match data-rules-name~="${n}"; using the first.`);let i=r[0],c=e.attr(i,"data-rules-version");if(c!==Xe)throw new D(c);return{rules:B(e.text(i)),tagNode:i}}var Se=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"]})}),Ge=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),Re=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui"]);function se(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 Ze(e,t){if(se(e,t))return!0;for(let[n,o]of Object.entries(Ge))if(o.includes(t)&&se(e,n))return!0;return!1}function q(e){let t=Se[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function Qe(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let o=Se[t];if(!o)throw new Error(`Unknown region capability: ${t}`);if(o.tokens.some(r=>Ze(n,r))||o.bundles.some(r=>se(n,r)))return n;n=n.parentElement}return null}function Ce(e,t){return!!Qe(e,t)}var et=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",...Re],refusedAttributePrefixes:["on"],urlAttributes:["href","src","srcset","action","formaction","poster","cite","data","ping","background","longdesc","usemap","xlink:href","manifest","codebase","icon"],refusedSchemes:["javascript","vbscript","data"]});function le(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let o=t&&t.ownerDocument?t.ownerDocument:t;return P(e,o,n)}return null}var nt=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function Ne(e,t){if(!/^(INPUT|TEXTAREA|SELECT|OPTION)$/.test(e.tagName||""))return;let n=(e.getAttribute?.("type")||"").toLowerCase();if("value"in e&&"value"in t&&e.tagName!=="OPTION"&&n!=="checkbox"&&n!=="radio"&&(t.value=e.value),"checked"in e&&"checked"in t&&(t.checked=e.checked),"selected"in e&&"selected"in t&&(t.selected=e.selected),e.tagName==="SELECT")for(let o=0;o<e.options.length;o++)t.options[o].selected=e.options[o].selected;"indeterminate"in e&&"indeterminate"in t&&(t.indeterminate=e.indeterminate)}function Me(e,t,n,o){if(o)return!!e.closest?.(t);let r=e;for(;r?.nodeType===1;){if(r.matches(t))return!0;if(r===n)break;r=r.parentElement}return!1}function Le(e,t,n,o,r,i,c,s){if(e.nodeType===1&&((c?Ce(e,n):Me(e,o,i,!1))||r&&Me(e,r,i,c)))return null;let l=t.importNode(e,!1);s.cloneToLive.set(l,e),s.liveToClone.set(e,l);let u=e.nodeType===1&&e.tagName==="TEMPLATE"?e.content:e,a=l.nodeType===1&&l.tagName==="TEMPLATE"?l.content:l;u!==e&&(s.cloneToLive.set(a,u),s.liveToClone.set(u,a));for(let g of u.childNodes||[]){let d=Le(g,t,n,o,r,i,c,s);d&&(a.appendChild(d),g.nodeType===1&&Ne(g,d))}return e.nodeType===1&&Ne(e,l),l}function U(e,{capability:t="data",exclude:n=null,inherit:o=!0}={}){if(!e)throw new TypeError("createContentView requires a DOM context");let r=e.nodeType===9?e:e.ownerDocument;if(!r?.implementation?.createHTMLDocument)throw new TypeError("createContentView requires an HTML DOM implementation");let i=r.implementation.createHTMLDocument(""),c=new WeakMap,s=new WeakMap,l=e.nodeType===9?e.documentElement:e;n&&i.documentElement.matches(n);let u=q(t),a=Le(l,i,t,u,n,l,o,{cloneToLive:c,liveToClone:s});e.nodeType===9&&a&&(i.replaceChild(a,i.documentElement),s.set(e,i),c.set(i,e));let g=d=>{if(nt.test(d))throw new Error(`Filtered content queries do not support stateful selector: ${d}`)};return{root:a,document:i,capability:t,selector:q(t),cloneToLive:c,liveToClone:s,original(d){return c.get(d)||null},cloneOf(d){return s.get(d)||null},query(d,O=a){return g(d),Array.from(O.querySelectorAll(d),m=>c.get(m)||m)},text(d=a){return(d===a?a:s.get(d))?.textContent||""},html(d=a){return(d===a?a:s.get(d))?.innerHTML??""},clone(d=a){let O=d===a?a:s.get(d);return O?i.importNode(O,!0):null}}}function Ie(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function rt(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var b={semanticExclude:!0,find(e,t,n={}){let o=rt(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(s=>!Ie(s)));let i=[];n.skip&&i.push(n.skip);let c=n.templateAttr===null?null:n.templateAttr||"cms-template";if(c&&i.push("["+c+"]"),i.length){let s=i.join(", ");r=r.filter(l=>!l.closest||!l.closest(s))}return r},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t)},prop(e,t,n){if(n===void 0){let o=e?e[t]:void 0;return o!==void 0?o:null}e[t]=n},clone(e){return e.cloneNode(!0)},insertAt(e,t,n){let o=e.children[n]||null;e.insertBefore(t,o)},remove(e){e&&e.parentNode&&e.parentNode.removeChild(e)},replaceWith(e,t){if(!e||!e.parentNode)throw new Error("dom.replaceWith: node has no parent");let o=e.ownerDocument.createElement("template");o.innerHTML=t;let r=o.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(r,e),r},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(o=>{o.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};function M(e,t={}){if(t.exclude===null)return b;let n=[q("data"),t.exclude].filter(Boolean).join(", "),o=e.nodeType===9?e:e.ownerDocument||e,r=e.nodeType===9?e.documentElement:e;if(!t._write&&!r?.matches?.(n)&&!r?.querySelector?.(n)&&!o?.querySelector?.(n))return b;let i=e.nodeType===9||!e.isConnected?e:e.ownerDocument,c=e.nodeType===9?e:e.ownerDocument,s=null,l=()=>s||(s=U(i,{capability:"data",exclude:t.exclude||null})),u=m=>{let p=l();return m===e?p.cloneOf(e):p.cloneOf(m)||m},a=m=>s?.original(m)||m,g=(m,p)=>{l().liveToClone.set(m,p),l().cloneToLive.set(p,m);let f=m.childNodes||[],h=p.childNodes||[];for(let y=0;y<Math.min(f.length,h.length);y++)g(f[y],h[y])},d=(m,p,f,h)=>{let y=Array.from(m.childNodes).filter(E=>s.cloneOf(E)),A=y[0];for(;A&&y.includes(A);)A=A.nextSibling;for(let E of y)E.remove();if(f==="innerHTML"){let E=c.createElement("template");E.innerHTML=h;for(let S of Array.from(E.content.childNodes))m.insertBefore(S,A||null)}else m.insertBefore(c.createTextNode(h),A||null);let w=U(m,{capability:"data",exclude:t.exclude||null});p.replaceChildren(...Array.from(w.root?.childNodes||[]));let T=E=>{let S=w.original(E);S&&(s.liveToClone.set(S,E),s.cloneToLive.set(E,S));for(let ae of Array.from(E.childNodes||[]))T(ae)};for(let E of Array.from(p.childNodes))T(E)},O={...b,find(m,p,f={}){let h=u(m);if(!h?.querySelectorAll)return[];let y=l().query(p,h);f.includeRulesTag||(y=y.filter(w=>!Ie(w)));let x=[];f.skip&&x.push(f.skip);let A=f.templateAttr===null?null:f.templateAttr||"cms-template";if(A&&x.push(`[${A}]`),x.length){let w=x.join(", ");y=y.filter(T=>!T.closest?.(w))}return y},parent(m){let p=u(m)?.parentElement;return p?a(p):null},children(m){return Array.from(u(m)?.children||[],a)},text(m,p){if(p===void 0){let y=a(m);return!y?.matches?.(n)&&!y?.querySelector?.(n)?b.text(y):(u(m)?.textContent||"").trim()}let f=a(m);if(!f?.matches?.(n)&&!f?.querySelector?.(n)&&!s){b.text(f,p);return}let h=l().cloneOf(f);h?d(f,h,"textContent",p):b.text(f,p)},attr(m,p,f){let h=a(m);if(f===void 0)return b.attr(h,p);b.attr(h,p,f);let y=s?.cloneOf(h);y&&(b.attr(y,p,f),U(h,{capability:"data",exclude:t.exclude||null}).root===null&&(y.remove(),s.liveToClone.delete(h),s.cloneToLive.delete(y)))},removeAttr(m,p){let f=a(m);b.removeAttr(f,p);let h=s?.cloneOf(f);h&&b.removeAttr(h,p)},prop(m,p,f){let h=a(m);if(f===void 0)return p==="innerHTML"||p==="outerHTML"||p==="textContent"||p==="innerText"?b.prop(u(h),p):b.prop(h,p);let y=p==="innerHTML"||p==="textContent"||p==="innerText",x=y?l().cloneOf(h):s?.cloneOf(h);x&&y?d(h,x,p,f):(b.prop(h,p,f),x&&b.prop(x,p,f))},clone(m){let p=u(m);return p===m?b.clone(m):c.importNode(p,!0)},insertAt(m,p,f){let h=a(m),x=O.children(h)[f]||(()=>{for(let T=h.children.length-1;T>=0;T--){let E=h.children[T];if(l().cloneOf(E))return E.nextElementSibling}return h.firstElementChild})(),A=a(p);h.insertBefore(A,x||null);let w=l().cloneOf(h);if(w){let T=l().cloneOf(A);T||(T=c.importNode(A,!0),g(A,T));let E=Array.from(w.children);w.insertBefore(T,E[f]||null)}},remove(m){let p=a(m),f=l().cloneOf(p);b.remove(p),f&&b.remove(f)},replaceWith(m,p){let f=a(m),h=l().cloneOf(f),y=b.replaceWith(f,p);if(h){let x=U(y,{capability:"data",exclude:t.exclude||null});if(!x.root)h.remove();else{h.replaceWith(x.root);let A=w=>{let T=x.original(w);T&&(s.liveToClone.set(T,w),s.cloneToLive.set(w,T));for(let E of Array.from(w.childNodes||[]))A(E)};A(x.root)}}return y}};return O}var k=b;var z={extract:(e,t,n={})=>C(M(e,n),e,t,n),apply:(e,t,n,o={})=>j(M(e,{...o,_write:!0}),e,t,n,o),findRulesIn:(e,t)=>P(k,e,t),findRules:(e,t)=>le(k,e,t),bind:(e,t,n={})=>{let o=le(k,e,t);if(!o){let r=typeof t=="string"?`data-rules-name~="${t}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${r}`)}return{...o,get:()=>C(M(e,n),e,o.rules,n),set:r=>j(M(e,{...n,_write:!0}),e,o.rules,r,n)}},parseStrict:ie,parseRelaxed:B,ruleAttrIndex:R,splitRule:ee,errors:V,DOM_PROPERTIES:F},ce=e=>!!e&&typeof e.nodeType=="number";function je(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=k.find(t,"script[data-rules-name]",{includeRulesTag:!0});if(n.length===0)throw new Error('hyper-html-api: no rules tag found. Add <script type="application/json" data-rules-name="\u2026" data-rules-version="1"> or pass rules.');if(n.length>1)throw new Error('hyper-html-api: multiple rules tags found; pass a name, e.g. extractData("api").');return P(k,t).rules}function fe(e,t){let n=ce(e)?e:document,o=ce(e)?t:e;return o===void 0?C(M(n),n,je(n)):z.bind(n,o).get()}function ue(e,t,n){if(!ce(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");return n===void 0?j(M(e),e,je(e),t):z.bind(e,n).set(t),e}var ot={engine:z,extractData:fe,applyData:ue},it=ot;return We(st);})();
1
+ var hyperHtmlApiData=(()=>{var Y=Object.defineProperty;var ke=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var _e=Object.prototype.hasOwnProperty;var de=(e,t)=>{for(var n in t)Y(e,n,{get:t[n],enumerable:!0})},$e=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of De(t))!_e.call(e,r)&&r!==n&&Y(e,r,{get:()=>t[r],enumerable:!(o=ke(t,r))||o.enumerable});return e};var We=e=>$e(Y({},"__esModule",{value:!0}),e);var st={};de(st,{applyData:()=>ue,default:()=>it,engine:()=>z,extractData:()=>fe});var F=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],X=new Set(F),he=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),G=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var V={};de(V,{EmptyListInsert:()=>$,MAX_RULE_DEPTH:()=>I,MaxRuleDepthExceeded:()=>N,NoRulesTag:()=>Z,RuleTargetReadOnly:()=>W,RulesParseError:()=>L,ShapeMismatch:()=>_,UnknownRulesVersion:()=>D,WriteRefused:()=>K,WriteRejected:()=>Q});var L=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},D=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},I=20,N=class extends Error{constructor(t){super(`rule depth exceeded ${I} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},_=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},$=class extends Error{constructor(t){super(`cannot add items to empty list at "${t.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=t}},W=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},K=class extends Error{constructor(t){super(`write refused: ${t.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=t}},Z=class extends Error{constructor(t){super(`no <script data-rules-name~="${t}"> rules tag in this document`),this.name="NoRulesTag",this.token=t}},Q=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 R(e){let t=0,n=null,o=-1;for(let r=0;r<e.length;r++){let i=e[r];i==="\\"?r++:n?i===n&&(n=null):i==='"'||i==="'"?n=i:i==="["||i==="("?t++:i==="]"||i===")"?t>0&&t--:i==="@"&&t===0&&(o=r)}return o}function ee(e){let t=R(e);return t===-1?{selector:e,prop:null}:{selector:e.slice(0,t),prop:e.slice(t+1)||null}}function C(e,t,n,o={}){if(Object.prototype.hasOwnProperty.call(o,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return te(e,t,n,{depth:0,path:[]},o)}function te(e,t,n,o,r){if(o.depth>I)throw new N(o.path);if(typeof n=="string")return ve(e,t,n,o,r);if(Array.isArray(n)){let[i,c]=n,s=e.find(t,i,r);return me(r,o,s),s.map((l,u)=>te(e,l,c,{depth:o.depth+1,path:[...o.path,u]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[c,s]of Object.entries(n))i[c]=te(e,t,s,{depth:o.depth+1,path:[...o.path,c]},r);return i}return null}function ve(e,t,n,o,r){if(n.endsWith("[]")){let s=n.slice(0,-2),l=e.find(t,s,r);return me(r,o,l),l.map(u=>e.text(u))}if(n.startsWith("@"))return pe(e,t,n.slice(1));let i=R(n);if(i!==-1){let s=n.slice(0,i),l=n.slice(i+1),u=s?e.find(t,s,r):[t];return u.length===0?null:pe(e,u[0],l)}if(n===".")return e.text(t);let c=e.find(t,n,r);return c.length===0?null:e.text(c[0])}function me(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(o){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,o)}}function pe(e,t,n){if(X.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o||null}function we(e,t,n,o){let r=e.length,i=t.length,c=new Array(r).fill(-1);if(o){let f=new Set;for(let h=0;h<r;h++){let y=o[h];!(y>=0&&y<i)||f.has(y)||(c[h]=y,f.add(y))}}if(r===0||i===0)return c;let s=e.map(f=>ye(f,n)),l=t.map(f=>ye(f,n)),u=new Array(i).fill(!1);for(let f of c)f>=0&&(u[f]=!0);let a=new Map;l.forEach((f,h)=>{u[h]||a.set(f,a.has(f)?-1:h)});let g=new Map;s.forEach((f,h)=>{c[h]>=0||g.set(f,(g.get(f)||0)+1)}),s.forEach((f,h)=>{if(c[h]>=0||g.get(f)!==1)return;let y=a.get(f);y===void 0||y===-1||u[y]||(c[h]=y,u[y]=!0)});let d=[];for(let f=0;f<r;f++)c[f]<0&&d.push(f);let O=[];for(let f=0;f<i;f++)u[f]||O.push(f);if(d.length===0||O.length===0)return c;let m=r*i+1,p=(f,h)=>He(e[f],t[h],n)*m+Math.abs(f-h);for(let[f,h]of Be(d,O,p))c[f]=h;return c}var Ee=e=>typeof e=="object"&&e!==null;function ye(e,t){if(!Ee(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(o=>{let r=JSON.stringify(e?.[o]);return r===void 0?" undef":r}))}function He(e,t,n){if(!Ee(n))return e===t?0:1;let o=Object.keys(n);if(o.length===0)return 0;let r=0;for(let i of o){let c=JSON.stringify(e?.[i]),s=JSON.stringify(t?.[i]);c!==s&&r++}return r}function Be(e,t,n){return e.length<=t.length?ge(e,t,n,!1):ge(t,e,(o,r)=>n(r,o),!0)}function ge(e,t,n,o){let r=e.length,i=t.length,c=[];for(let g=0;g<=r;g++)c.push(new Float64Array(i+1).fill(1/0));let s=[];for(let g=0;g<=r;g++)s.push(new Uint8Array(i+1));for(let g=0;g<=i;g++)c[r][g]=0;for(let g=r-1;g>=0;g--)for(let d=i-1;d>=0;d--){let O=n(e[g],t[d])+c[g+1][d+1],m=c[g][d+1];O<=m?(c[g][d]=O,s[g][d]=1):c[g][d]=m}let l=[],u=0,a=0;for(;u<r&&a<i;)s[u][a]&&(l.push(o?[t[a],e[u]]:[e[u],t[a]]),u++),a++;return l}function re(e,t,n,o,r,i,c,s={}){let l=e.find(t,n,s);if(r.length===0){l.forEach(w=>e.remove(w)),ne(s,"onRowsApplied",i.path,[]);return}let u=r.length>l.length,a=l[0]||null;if(u&&!a&&(a=Fe(e,t,n,s),!a))throw new $(i.path);let g=l.map(w=>ze(e,w,o,s)),d=null;if(u&&a){d=e.clone(a),s.templateAttr&&e.removeAttr(d,s.templateAttr);let w=e.stripIds(d);w>0&&console.warn(`[hyper-html-api] stripped ${w} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let O=we(r,g,o,qe(e,l,r,i,s)),m=l[0]||a,p=e.parent(m),f=l.length>0?Te(e,p,m):0,h=Ke(e,l),y=new Set,x=[],A=r.map((w,T)=>{let E=O[T];if(E>=0)return y.add(E),x.push(!1),l[E];x.push(!0);let S=e.clone(d);return e.stripIds(S),S});l.forEach((w,T)=>{y.has(T)||e.remove(w)}),h?A.forEach((w,T)=>{let E=f+T;e.children(p).findIndex(Pe=>e.sameNode(Pe,w))!==E&&e.insertAt(p,w,E)}):Ve(e,A,x,p,f),Ue(e,A,o,r,i,c,s),ne(s,"onRowsApplied",i.path,A)}function ne(e,t,n,o){if(typeof e[t]=="function")try{return e[t](n.slice(),o)}catch(r){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,r);return}}function qe(e,t,n,o,r){let i=ne(r,"identifyRows",o.path,n);if(!Array.isArray(i))return null;let c=new Array(n.length).fill(-1),s=new Set;for(let l=0;l<n.length;l++)if(i[l]){for(let u=0;u<t.length;u++)if(!(s.has(u)||!e.sameNode(t[u],i[l]))){c[l]=u,s.add(u);break}}return c}function Ue(e,t,n,o,r,i,c){t.forEach((s,l)=>{if(n===null){let u=o[l],a=u==null?"":String(u);e.text(s)!==a&&e.text(s,a)}else{let u=i(e,s,n,o[l],{depth:r.depth+1,path:[...r.path,l]},c);u&&u!==s&&(t[l]=u)}})}function ze(e,t,n,o){return n===null?e.text(t):C(e,t,n,o.onRowsRead?{...o,onRowsRead:void 0}:o)}function Te(e,t,n){let o=e.children(t);for(let r=0;r<o.length;r++)if(e.sameNode(o[r],n))return r;return-1}function Fe(e,t,n,o){if(!o.templateAttr)return null;let r=t;for(;r;){let i=e.find(r,n,{includeRulesTag:!1,templateAttr:null});for(let c of i)if(e.attr(c,o.templateAttr)!=null)return c;r=e.parent(r)}return null}function Ke(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let o=e.children(n),r=[];for(let i of t){let c=o.findIndex(s=>e.sameNode(s,i));if(c===-1)return!1;r.push(c)}return r.sort((i,c)=>i-c),r[r.length-1]-r[0]===r.length-1}function Ve(e,t,n,o,r){let i=null,c=r;for(let s=0;s<t.length;s++){if(!n[s]){i=t[s];continue}let l=i?e.parent(i):o;if(!l)continue;let u=i?Te(e,l,i)+1:c++;e.insertAt(l,t[s],u),i=t[s]}}var Ae=new Set(["checked","selected","disabled","readOnly","paused"]);function j(e,t,n,o,r={}){if(Object.prototype.hasOwnProperty.call(r,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");let i=[];if(oe(n,o,[],i),i.length)throw new _(i);J(e,t,n,o,{depth:0,path:[]},r)}function J(e,t,n,o,r,i={}){if(r.depth>I)throw new N(r.path);if(o===void 0)return t;if(typeof n=="string")return Je(e,t,n,o,r,i);if(Array.isArray(n)){let[c,s]=n;return re(e,t,c,s,o,r,J,i),t}if(typeof n=="object"&&n!==null){for(let[c,s]of Object.entries(n)){let l=J(e,t,s,o==null?o:o[c],{depth:r.depth+1,path:[...r.path,c]},i);l&&l!==t&&(t=l)}return t}return t}function Je(e,t,n,o,r,i){if(n.endsWith("[]")){let l=n.slice(0,-2);return re(e,t,l,null,o,r,J,i),t}if(n.startsWith("@"))return Oe(e,t,n.slice(1),o);let c=R(n);if(c!==-1){let l=n.slice(0,c),u=n.slice(c+1),a=l?e.find(t,l,i):[t];return a.length===0||Oe(e,a[0],u,o),t}if(n===".")return xe(e,t,o),t;let s=e.find(t,n,i);return s.length===0||xe(e,s[0],o),t}function xe(e,t,n){let o=n==null?"":String(n);e.text(t)!==o&&e.text(t,o)}function Oe(e,t,n,o){if(G.has(n)){let i=e.prop(t,n);if(i===o||i!=null&&o!=null&&String(i)===String(o))return t;throw new W(n)}if(n==="outerHTML"){let i=o==null?"":String(o);return e.replaceWith(t,i)}if(he.has(n)){let i=Ye(n,o);return e.prop(t,n)!==i&&e.prop(t,n,i),t}let r=o==null?"":String(o);return e.attr(t,n)!==r&&e.attr(t,n,r),t}function Ye(e,t){return t==null?Ae.has(e)?!1:"":Ae.has(e)?t==="false"?!1:!!t:t}function oe(e,t,n,o){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((r,i)=>{typeof r=="object"&&r!==null&&o.push({path:H([...n,i]),expected:"scalar",got:v(r)})}):o.push({path:H(n),expected:"array",got:v(t)});return}t!==null&&typeof t=="object"&&o.push({path:H(n),expected:"scalar",got:v(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:H(n),expected:"array",got:v(t)});return}let r=e[1];t.forEach((i,c)=>oe(r,i,[...n,c],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:H(n),expected:"object",got:v(t)});return}for(let[r,i]of Object.entries(e))oe(i,t[r],[...n,r],o)}}}function v(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function H(e){return e.join(".")}function ie(e){try{return JSON.parse(e)}catch(t){throw new L(`Invalid strict JSON: ${t.message}`,t)}}function B(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(r){let i=[],c=0;for(;c<r.length;){let s=r[c];if(/\s/.test(s)){c++;continue}if("{}".includes(s)){i.push({type:s,value:s}),c++;continue}if(s==="["){let g=!1,d=c+1;for(;d<r.length&&/\s/.test(r[d]);)d++;if(d<r.length&&/[a-zA-Z_]/.test(r[d])&&(g=!0),!g){i.push({type:s,value:s}),c++;continue}}if(s==="]"){i.push({type:s,value:s}),c++;continue}if(s===":"){i.push({type:t.COLON,value:s}),c++;continue}if(s===","){i.push({type:t.COMMA,value:s}),c++;continue}if(s==='"'||s==="'"){let g=s,d=c+1;for(;d<r.length&&r[d]!==g;)r[d]==="\\"&&d++,d++;i.push({type:t.STRING,value:r.substring(c+1,d),quoted:!0,sourceQuote:g}),c=d+1;continue}let l=c,u;for(;l<r.length&&!/[{},]/.test(r[l]);)if(r[l]===":"){let g=[":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 O of g){let m=O.substring(1);if(r.substring(l+1,l+1+m.length)===m){d=!0,l+=m.length;break}}if(!d)break}else if(r[l]==="["){for(l++;l<r.length&&r[l]!=="]";){if(r[l]==='"'||r[l]==="'"){let g=r[l];for(l++;l<r.length&&r[l]!==g;)r[l]==="\\"&&l++,l++}l++}l<r.length&&r[l]==="]"&&l++}else l++;u=r.substring(c,l);let a=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(u)?a=t.NUMBER:u==="true"||u==="false"||u==="null"?a=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(u)&&(a=t.SELECTOR),i.push({type:a,value:u,quoted:!1}),c=l}return i}function o(r){let i="";for(let c=0;c<r.length;c++){let s=r[c];if("{}".includes(s.type)||"[]".includes(s.type)){i+=s.value;continue}if(s.type===t.COLON){i+=s.value;continue}if(s.type===t.COMMA){let l=r[c+1];if(l&&(l.type==="}"||l.type==="]"))continue;i+=s.value;continue}if(s.type===t.STRING&&s.quoted){let l=s.value;s.sourceQuote==="'"&&(l=l.replace(/\\'/g,"'"),l=l.replace(/(\\*)"/g,(u,a)=>a.length%2===0?a+'\\"':u)),i+=`"${l}"`;continue}if(s.type===t.NUMBER||s.type===t.BOOLEAN){i+=s.value;continue}if(s.type===t.SELECTOR||s.type===t.IDENTIFIER){i+=`"${s.value}"`;continue}i+=`"${s.value}"`}return i}try{let r=n(e),i=o(r);return JSON.parse(i)}catch(r){throw new L("Invalid extraction rules syntax: "+r.message,r)}}var Xe="1",be=/^[a-zA-Z0-9_-]+$/;function P(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!be.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${be})`);o=`script[data-rules-name~="${n}"]`}let r=e.find(t,o,{includeRulesTag:!0});if(r.length===0)return null;n!==void 0&&r.length>1&&console.warn(`hyper-html-api: ${r.length} rules tags match data-rules-name~="${n}"; using the first.`);let i=r[0],c=e.attr(i,"data-rules-version");if(c!==Xe)throw new D(c);return{rules:B(e.text(i)),tagNode:i}}var Se=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"]})}),Ge=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),Re=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui"]);function se(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 Ze(e,t){if(se(e,t))return!0;for(let[n,o]of Object.entries(Ge))if(o.includes(t)&&se(e,n))return!0;return!1}function q(e){let t=Se[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function Qe(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let o=Se[t];if(!o)throw new Error(`Unknown region capability: ${t}`);if(o.tokens.some(r=>Ze(n,r))||o.bundles.some(r=>se(n,r)))return n;n=n.parentElement}return null}function Ce(e,t){return!!Qe(e,t)}var et=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",...Re],refusedAttributePrefixes:["on"],urlAttributes:["href","src","srcset","action","formaction","poster","cite","data","ping","background","longdesc","usemap","xlink:href","manifest","codebase","icon"],refusedSchemes:["javascript","vbscript","data"]});function le(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let o=t&&t.ownerDocument?t.ownerDocument:t;return P(e,o,n)}return null}var nt=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function Ne(e,t){if(!/^(INPUT|TEXTAREA|SELECT|OPTION)$/.test(e.tagName||""))return;let n=(e.getAttribute?.("type")||"").toLowerCase();if("value"in e&&"value"in t&&e.tagName!=="OPTION"&&n!=="checkbox"&&n!=="radio"&&(t.value=e.value),"checked"in e&&"checked"in t&&(t.checked=e.checked),"selected"in e&&"selected"in t&&(t.selected=e.selected),e.tagName==="SELECT")for(let o=0;o<e.options.length;o++)t.options[o].selected=e.options[o].selected;"indeterminate"in e&&"indeterminate"in t&&(t.indeterminate=e.indeterminate)}function Me(e,t,n,o){if(o)return!!e.closest?.(t);let r=e;for(;r?.nodeType===1;){if(r.matches(t))return!0;if(r===n)break;r=r.parentElement}return!1}function Le(e,t,n,o,r,i,c,s){if(e.nodeType===1&&((c?Ce(e,n):Me(e,o,i,!1))||r&&(c&&e!==i?e.matches(r):Me(e,r,i,c))))return null;let l=t.importNode(e,!1);s.cloneToLive.set(l,e),s.liveToClone.set(e,l);let u=e.nodeType===1&&e.tagName==="TEMPLATE"?e.content:e,a=l.nodeType===1&&l.tagName==="TEMPLATE"?l.content:l;u!==e&&(s.cloneToLive.set(a,u),s.liveToClone.set(u,a));for(let g of u.childNodes||[]){let d=Le(g,t,n,o,r,i,c,s);d&&(a.appendChild(d),g.nodeType===1&&Ne(g,d))}return e.nodeType===1&&Ne(e,l),l}function U(e,{capability:t="data",exclude:n=null,inherit:o=!0}={}){if(!e)throw new TypeError("createContentView requires a DOM context");let r=e.nodeType===9?e:e.ownerDocument;if(!r?.implementation?.createHTMLDocument)throw new TypeError("createContentView requires an HTML DOM implementation");let i=r.implementation.createHTMLDocument(""),c=new WeakMap,s=new WeakMap,l=e.nodeType===9?e.documentElement:e;n&&i.documentElement.matches(n);let u=q(t),a=Le(l,i,t,u,n,l,o,{cloneToLive:c,liveToClone:s});e.nodeType===9&&a&&(i.replaceChild(a,i.documentElement),s.set(e,i),c.set(i,e));let g=d=>{if(nt.test(d))throw new Error(`Filtered content queries do not support stateful selector: ${d}`)};return{root:a,document:i,capability:t,selector:q(t),cloneToLive:c,liveToClone:s,original(d){return c.get(d)||null},cloneOf(d){return s.get(d)||null},query(d,O=a){return g(d),Array.from(O.querySelectorAll(d),m=>c.get(m)||m)},text(d=a){return(d===a?a:s.get(d))?.textContent||""},html(d=a){return(d===a?a:s.get(d))?.innerHTML??""},clone(d=a){let O=d===a?a:s.get(d);return O?i.importNode(O,!0):null}}}function Ie(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function rt(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var b={semanticExclude:!0,find(e,t,n={}){let o=rt(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(s=>!Ie(s)));let i=[];n.skip&&i.push(n.skip);let c=n.templateAttr===null?null:n.templateAttr||"cms-template";if(c&&i.push("["+c+"]"),i.length){let s=i.join(", ");r=r.filter(l=>!l.closest||!l.closest(s))}return r},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t)},prop(e,t,n){if(n===void 0){let o=e?e[t]:void 0;return o!==void 0?o:null}e[t]=n},clone(e){return e.cloneNode(!0)},insertAt(e,t,n){let o=e.children[n]||null;e.insertBefore(t,o)},remove(e){e&&e.parentNode&&e.parentNode.removeChild(e)},replaceWith(e,t){if(!e||!e.parentNode)throw new Error("dom.replaceWith: node has no parent");let o=e.ownerDocument.createElement("template");o.innerHTML=t;let r=o.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(r,e),r},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(o=>{o.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};function M(e,t={}){if(t.exclude===null)return b;let n=[q("data"),t.exclude].filter(Boolean).join(", "),o=e.nodeType===9?e:e.ownerDocument||e,r=e.nodeType===9?e.documentElement:e;if(!t._write&&!r?.matches?.(n)&&!r?.querySelector?.(n)&&!o?.querySelector?.(n))return b;let i=e.nodeType===9||!e.isConnected?e:e.ownerDocument,c=e.nodeType===9?e:e.ownerDocument,s=null,l=()=>s||(s=U(i,{capability:"data",exclude:t.exclude||null})),u=m=>{let p=l();return m===e?p.cloneOf(e):p.cloneOf(m)||m},a=m=>s?.original(m)||m,g=(m,p)=>{l().liveToClone.set(m,p),l().cloneToLive.set(p,m);let f=m.childNodes||[],h=p.childNodes||[];for(let y=0;y<Math.min(f.length,h.length);y++)g(f[y],h[y])},d=(m,p,f,h)=>{let y=Array.from(m.childNodes).filter(E=>s.cloneOf(E)),A=y[0];for(;A&&y.includes(A);)A=A.nextSibling;for(let E of y)E.remove();if(f==="innerHTML"){let E=c.createElement("template");E.innerHTML=h;for(let S of Array.from(E.content.childNodes))m.insertBefore(S,A||null)}else m.insertBefore(c.createTextNode(h),A||null);let w=U(m,{capability:"data",exclude:t.exclude||null});p.replaceChildren(...Array.from(w.root?.childNodes||[]));let T=E=>{let S=w.original(E);S&&(s.liveToClone.set(S,E),s.cloneToLive.set(E,S));for(let ae of Array.from(E.childNodes||[]))T(ae)};for(let E of Array.from(p.childNodes))T(E)},O={...b,find(m,p,f={}){let h=u(m);if(!h?.querySelectorAll)return[];let y=l().query(p,h);f.includeRulesTag||(y=y.filter(w=>!Ie(w)));let x=[];f.skip&&x.push(f.skip);let A=f.templateAttr===null?null:f.templateAttr||"cms-template";if(A&&x.push(`[${A}]`),x.length){let w=x.join(", ");y=y.filter(T=>!T.closest?.(w))}return y},parent(m){let p=u(m)?.parentElement;return p?a(p):null},children(m){return Array.from(u(m)?.children||[],a)},text(m,p){if(p===void 0){let y=a(m);return!y?.matches?.(n)&&!y?.querySelector?.(n)?b.text(y):(u(m)?.textContent||"").trim()}let f=a(m);if(!f?.matches?.(n)&&!f?.querySelector?.(n)&&!s){b.text(f,p);return}let h=l().cloneOf(f);h?d(f,h,"textContent",p):b.text(f,p)},attr(m,p,f){let h=a(m);if(f===void 0)return b.attr(h,p);b.attr(h,p,f);let y=s?.cloneOf(h);y&&(b.attr(y,p,f),U(h,{capability:"data",exclude:t.exclude||null}).root===null&&(y.remove(),s.liveToClone.delete(h),s.cloneToLive.delete(y)))},removeAttr(m,p){let f=a(m);b.removeAttr(f,p);let h=s?.cloneOf(f);h&&b.removeAttr(h,p)},prop(m,p,f){let h=a(m);if(f===void 0)return p==="innerHTML"||p==="outerHTML"||p==="textContent"||p==="innerText"?b.prop(u(h),p):b.prop(h,p);let y=p==="innerHTML"||p==="textContent"||p==="innerText",x=y?l().cloneOf(h):s?.cloneOf(h);x&&y?d(h,x,p,f):(b.prop(h,p,f),x&&b.prop(x,p,f))},clone(m){let p=u(m);return p===m?b.clone(m):c.importNode(p,!0)},insertAt(m,p,f){let h=a(m),x=O.children(h)[f]||(()=>{for(let T=h.children.length-1;T>=0;T--){let E=h.children[T];if(l().cloneOf(E))return E.nextElementSibling}return h.firstElementChild})(),A=a(p);h.insertBefore(A,x||null);let w=l().cloneOf(h);if(w){let T=l().cloneOf(A);T||(T=c.importNode(A,!0),g(A,T));let E=Array.from(w.children);w.insertBefore(T,E[f]||null)}},remove(m){let p=a(m),f=l().cloneOf(p);b.remove(p),f&&b.remove(f)},replaceWith(m,p){let f=a(m),h=l().cloneOf(f),y=b.replaceWith(f,p);if(h){let x=U(y,{capability:"data",exclude:t.exclude||null});if(!x.root)h.remove();else{h.replaceWith(x.root);let A=w=>{let T=x.original(w);T&&(s.liveToClone.set(T,w),s.cloneToLive.set(w,T));for(let E of Array.from(w.childNodes||[]))A(E)};A(x.root)}}return y}};return O}var k=b;var z={extract:(e,t,n={})=>C(M(e,n),e,t,n),apply:(e,t,n,o={})=>j(M(e,{...o,_write:!0}),e,t,n,o),findRulesIn:(e,t)=>P(k,e,t),findRules:(e,t)=>le(k,e,t),bind:(e,t,n={})=>{let o=le(k,e,t);if(!o){let r=typeof t=="string"?`data-rules-name~="${t}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${r}`)}return{...o,get:()=>C(M(e,n),e,o.rules,n),set:r=>j(M(e,{...n,_write:!0}),e,o.rules,r,n)}},parseStrict:ie,parseRelaxed:B,ruleAttrIndex:R,splitRule:ee,errors:V,DOM_PROPERTIES:F},ce=e=>!!e&&typeof e.nodeType=="number";function je(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=k.find(t,"script[data-rules-name]",{includeRulesTag:!0});if(n.length===0)throw new Error('hyper-html-api: no rules tag found. Add <script type="application/json" data-rules-name="\u2026" data-rules-version="1"> or pass rules.');if(n.length>1)throw new Error('hyper-html-api: multiple rules tags found; pass a name, e.g. extractData("api").');return P(k,t).rules}function fe(e,t){let n=ce(e)?e:document,o=ce(e)?t:e;return o===void 0?C(M(n),n,je(n)):z.bind(n,o).get()}function ue(e,t,n){if(!ce(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");return n===void 0?j(M(e),e,je(e),t):z.bind(e,n).set(t),e}var ot={engine:z,extractData:fe,applyData:ue},it=ot;return We(st);})();