hyper-html-api 0.10.0 → 0.10.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.
- package/dist/hyper-html-api.engine.min.js +1 -1
- package/dist/hyper-html-api.min.js +8 -6
- package/dist/hyper-html-api.upgrade.min.js +2 -2
- package/package.json +2 -2
- package/src/adapters/cheerio.js +12 -0
- package/src/adapters/dom.js +47 -0
- package/src/engine/diff.js +52 -20
- package/src/engine/row-match.js +16 -10
- package/src/engine/splice.js +14 -0
- package/src/lib/content-dom.js +58 -28
- package/src/lib/region-capabilities.js +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
var hyperHtmlApiData=(()=>{var Q=Object.defineProperty;var Ke=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var Ve=Object.prototype.hasOwnProperty;var Ee=(e,t)=>{for(var n in t)Q(e,n,{get:t[n],enumerable:!0})},Je=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Fe(t))!Ve.call(e,r)&&r!==n&&Q(e,r,{get:()=>t[r],enumerable:!(o=Ke(t,r))||o.enumerable});return e};var Ye=e=>Je(Q({},"__esModule",{value:!0}),e);var Mt={};Ee(Mt,{applyData:()=>ge,default:()=>Nt,engine:()=>Y,extractData:()=>ye});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"],ee=new Set(G),Te=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"]);var R={};Ee(R,{EmptyListInsert:()=>v,MAX_RULE_DEPTH:()=>j,MaxRuleDepthExceeded:()=>I,NoRulesTag:()=>te,RuleTargetReadOnly:()=>H,RulesParseError:()=>P,ShapeMismatch:()=>W,UnknownRulesVersion:()=>$,WriteRefused:()=>q,WriteRejected:()=>ne});var P=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},$=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},j=20,I=class extends Error{constructor(t){super(`rule depth exceeded ${j} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},W=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},v=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}},H=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},q=class extends Error{constructor(t){super(`write refused: ${t.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=t}},te=class extends Error{constructor(t){super(`no <script data-rules-name~="${t}"> rules tag in this document`),this.name="NoRulesTag",this.token=t}},ne=class extends Error{constructor(t,n){super(`write rejected: ${t.length} unknown key(s), ${n.length} rule(s) with no matching element`),this.name="WriteRejected",this.unknownKeys=t,this.unmatched=n}};function S(e){let t=0,n=null,o=-1;for(let r=0;r<e.length;r++){let 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&&(o=r)}return o}function re(e){let t=S(e);return t===-1?{selector:e,prop:null}:{selector:e.slice(0,t),prop:e.slice(t+1)||null}}function M(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 oe(e,t,n,{depth:0,path:[]},o)}function oe(e,t,n,o,r){if(o.depth>j)throw new I(o.path);if(typeof n=="string")return Ge(e,t,n,o,r);if(Array.isArray(n)){let[s,l]=n,c=e.find(t,s,r);return Oe(r,o,c),c.map((i,f)=>oe(e,i,l,{depth:o.depth+1,path:[...o.path,f]},r))}if(typeof n=="object"&&n!==null){let s={};for(let[l,c]of Object.entries(n))s[l]=oe(e,t,c,{depth:o.depth+1,path:[...o.path,l]},r);return s}return null}function Ge(e,t,n,o,r){if(n.endsWith("[]")){let c=n.slice(0,-2),i=e.find(t,c,r);return Oe(r,o,i),i.map(f=>e.text(f))}if(n.startsWith("@"))return Ae(e,t,n.slice(1));let s=S(n);if(s!==-1){let c=n.slice(0,s),i=n.slice(s+1),f=c?e.find(t,c,r):[t];return f.length===0?null:Ae(e,f[0],i)}if(n===".")return e.text(t);let l=e.find(t,n,r);return l.length===0?null:e.text(l[0])}function Oe(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 Ae(e,t,n){if(ee.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o||null}function Se(e,t,n,o){let r=e.length,s=t.length,l=new Array(r).fill(-1);if(o){let a=new Set;for(let m=0;m<r;m++){let g=o[m];!(g>=0&&g<s)||a.has(g)||(l[m]=g,a.add(g))}}if(r===0||s===0)return l;let c=e.map(a=>xe(a,n)),i=t.map(a=>xe(a,n)),f=new Array(s).fill(!1);for(let a of l)a>=0&&(f[a]=!0);let u=new Map;i.forEach((a,m)=>{f[m]||u.set(a,u.has(a)?-1:m)});let p=new Map;c.forEach((a,m)=>{l[m]>=0||p.set(a,(p.get(a)||0)+1)}),c.forEach((a,m)=>{if(l[m]>=0||p.get(a)!==1)return;let g=u.get(a);g===void 0||g===-1||f[g]||(l[m]=g,f[g]=!0)});let d=[];for(let a=0;a<r;a++)l[a]<0&&d.push(a);let w=[];for(let a=0;a<s;a++)f[a]||w.push(a);if(d.length===0||w.length===0)return l;let h=r*s+1,y=(a,m)=>Xe(e[a],t[m],n)*h+Math.abs(a-m);for(let[a,m]of Ze(d,w,y))l[a]=m;return l}var Re=e=>typeof e=="object"&&e!==null;function xe(e,t){if(!Re(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 Xe(e,t,n){if(!Re(n))return e===t?0:1;let o=Object.keys(n);if(o.length===0)return 0;let r=0;for(let s of o){let l=JSON.stringify(e?.[s]),c=JSON.stringify(t?.[s]);l!==c&&r++}return r}function Ze(e,t,n){return e.length<=t.length?be(e,t,n,!1):be(t,e,(o,r)=>n(r,o),!0)}function be(e,t,n,o){let r=e.length,s=t.length,l=[];for(let p=0;p<=r;p++)l.push(new Float64Array(s+1).fill(1/0));let c=[];for(let p=0;p<=r;p++)c.push(new Uint8Array(s+1));for(let p=0;p<=s;p++)l[r][p]=0;for(let p=r-1;p>=0;p--)for(let d=s-1;d>=0;d--){let w=n(e[p],t[d])+l[p+1][d+1],h=l[p][d+1];w<=h?(l[p][d]=w,c[p][d]=1):l[p][d]=h}let i=[],f=0,u=0;for(;f<r&&u<s;)c[f][u]&&(i.push(o?[t[u],e[f]]:[e[f],t[u]]),f++),u++;return i}function se(e,t,n,o,r,s,l,c={}){let i=e.find(t,n,c);if(r.length===0){i.forEach(E=>e.remove(E)),ie(c,"onRowsApplied",s.path,[]);return}let f=r.length>i.length,u=i[0]||null;if(f&&!u&&(u=nt(e,t,n,c),!u))throw new v(s.path);let p=i.map(E=>tt(e,E,o,c)),d=null;if(f&&u){d=e.clone(u),c.templateAttr&&e.removeAttr(d,c.templateAttr);let E=e.stripIds(d);E>0&&console.warn(`[hyper-html-api] stripped ${E} id attribute(s) from cloned template at "${s.path.join(".")||"(root)"}"`)}let w=Se(r,p,o,Qe(e,i,r,s,c)),h=i[0]||u,y=e.parent(h),a=i.length>0?Ne(e,y,h):0,m=rt(e,i),g=new Set,x=[],O=r.map((E,A)=>{let T=w[A];if(T>=0)return g.add(T),x.push(!1),i[T];x.push(!0);let N=e.clone(d);return e.stripIds(N),N});i.forEach((E,A)=>{g.has(A)||e.remove(E)}),m?O.forEach((E,A)=>{let T=a+A;e.children(y).findIndex(ze=>e.sameNode(ze,E))!==T&&e.insertAt(y,E,T)}):ot(e,O,x,y,a),et(e,O,o,r,s,l,c),ie(c,"onRowsApplied",s.path,O)}function ie(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 s=ie(r,"identifyRows",o.path,n);if(!Array.isArray(s))return null;let l=new Array(n.length).fill(-1),c=new Set;for(let i=0;i<n.length;i++)if(s[i]){for(let f=0;f<t.length;f++)if(!(c.has(f)||!e.sameNode(t[f],s[i]))){l[i]=f,c.add(f);break}}return l}function et(e,t,n,o,r,s,l){t.forEach((c,i)=>{if(n===null){let f=o[i],u=f==null?"":String(f);e.text(c)!==u&&e.text(c,u)}else{let f=s(e,c,n,o[i],{depth:r.depth+1,path:[...r.path,i]},l);f&&f!==c&&(t[i]=f)}})}function tt(e,t,n,o){return n===null?e.text(t):M(e,t,n,o.onRowsRead?{...o,onRowsRead:void 0}:o)}function Ne(e,t,n){let o=e.children(t);for(let r=0;r<o.length;r++)if(e.sameNode(o[r],n))return r;return-1}function nt(e,t,n,o){if(!o.templateAttr)return null;let r=t;for(;r;){let s=e.find(r,n,{includeRulesTag:!1,templateAttr:null});for(let l of s)if(e.attr(l,o.templateAttr)!=null)return l;r=e.parent(r)}return null}function rt(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 s of t){let l=o.findIndex(c=>e.sameNode(c,s));if(l===-1)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,o,r){let s=null,l=r;for(let c=0;c<t.length;c++){if(!n[c]){s=t[c];continue}let i=s?e.parent(s):o;if(!i)continue;let f=s?Ne(e,i,s)+1:l++;e.insertAt(i,t[c],f),s=t[c]}}var Me=new Set(["checked","selected","disabled","readOnly","paused"]);function L(e,t,n,o,r={}){if(Object.prototype.hasOwnProperty.call(r,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");let s=[];if(ce(n,o,[],s),s.length)throw new W(s);X(e,t,n,o,{depth:0,path:[]},r)}function X(e,t,n,o,r,s={}){if(r.depth>j)throw new I(r.path);if(o===void 0)return t;if(typeof n=="string")return it(e,t,n,o,r,s);if(Array.isArray(n)){let[l,c]=n;return se(e,t,l,c,o,r,X,s),t}if(typeof n=="object"&&n!==null){for(let[l,c]of Object.entries(n)){let i=X(e,t,c,o==null?o:o[l],{depth:r.depth+1,path:[...r.path,l]},s);i&&i!==t&&(t=i)}return t}return t}function it(e,t,n,o,r,s){if(n.endsWith("[]")){let i=n.slice(0,-2);return se(e,t,i,null,o,r,X,s),t}if(n.startsWith("@"))return Ie(e,t,n.slice(1),o);let l=S(n);if(l!==-1){let i=n.slice(0,l),f=n.slice(l+1),u=i?e.find(t,i,s):[t];return u.length===0||Ie(e,u[0],f,o),t}if(n===".")return Ce(e,t,o),t;let c=e.find(t,n,s);return c.length===0||Ce(e,c[0],o),t}function Ce(e,t,n){let o=n==null?"":String(n);e.text(t)!==o&&e.text(t,o)}function Ie(e,t,n,o){if(_.has(n)){let s=e.prop(t,n);if(s===o||s!=null&&o!=null&&String(s)===String(o))return t;throw new H(n)}if(n==="outerHTML"){let s=o==null?"":String(o);return e.replaceWith(t,s)}if(Te.has(n)){let s=st(n,o);return e.prop(t,n)!==s&&e.prop(t,n,s),t}let r=o==null?"":String(o);return e.attr(t,n)!==r&&e.attr(t,n,r),t}function st(e,t){return t==null?Me.has(e)?!1:"":Me.has(e)?t==="false"?!1:!!t:t}function ce(e,t,n,o){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((r,s)=>{typeof r=="object"&&r!==null&&o.push({path:U([...n,s]),expected:"scalar",got:B(r)})}):o.push({path:U(n),expected:"array",got:B(t)});return}t!==null&&typeof t=="object"&&o.push({path:U(n),expected:"scalar",got:B(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:U(n),expected:"array",got:B(t)});return}let r=e[1];t.forEach((s,l)=>ce(r,s,[...n,l],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:U(n),expected:"object",got:B(t)});return}for(let[r,s]of Object.entries(e))ce(s,t[r],[...n,r],o)}}}function B(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function U(e){return e.join(".")}function le(e){try{return JSON.parse(e)}catch(t){throw new P(`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 p=!1,d=l+1;for(;d<r.length&&/\s/.test(r[d]);)d++;if(d<r.length&&/[a-zA-Z_]/.test(r[d])&&(p=!0),!p){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 p=c,d=l+1;for(;d<r.length&&r[d]!==p;)r[d]==="\\"&&d++,d++;s.push({type:t.STRING,value:r.substring(l+1,d),quoted:!0,sourceQuote:p}),l=d+1;continue}let i=l,f;for(;i<r.length&&!/[{},]/.test(r[i]);)if(r[i]===":"){let p=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],d=!1;for(let w of p){let h=w.substring(1);if(r.substring(i+1,i+1+h.length)===h){d=!0,i+=h.length;break}}if(!d)break}else if(r[i]==="["){for(i++;i<r.length&&r[i]!=="]";){if(r[i]==='"'||r[i]==="'"){let p=r[i];for(i++;i<r.length&&r[i]!==p;)r[i]==="\\"&&i++,i++}i++}i<r.length&&r[i]==="]"&&i++}else i++;f=r.substring(l,i);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=i}return s}function o(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 i=r[l+1];if(i&&(i.type==="}"||i.type==="]"))continue;s+=c.value;continue}if(c.type===t.STRING&&c.quoted){let i=c.value;c.sourceQuote==="'"&&(i=i.replace(/\\'/g,"'"),i=i.replace(/(\\*)"/g,(f,u)=>u.length%2===0?u+'\\"':f)),s+=`"${i}"`;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=o(r);return JSON.parse(s)}catch(r){throw new P("Invalid extraction rules syntax: "+r.message,r)}}var ct="1",Le=/^[a-zA-Z0-9_-]+$/;function k(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!Le.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${Le})`);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 s=r[0],l=e.attr(s,"data-rules-version");if(l!==ct)throw new $(l);return{rules:z(e.text(s)),tagNode:s}}var Pe=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"]})}),lt=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),je=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui"]);function fe(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 ft(e,t){if(fe(e,t))return!0;for(let[n,o]of Object.entries(lt))if(o.includes(t)&&fe(e,n))return!0;return!1}function K(e){let t=Pe[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function ut(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let o=Pe[t];if(!o)throw new Error(`Unknown region capability: ${t}`);if(o.tokens.some(r=>ft(n,r))||o.bundles.some(r=>fe(n,r)))return n;n=n.parentElement}return null}function ke(e,t){return!!ut(e,t)}var ue=Object.freeze({refusedRuleForms:["innerHTML","outerHTML"],refusedTargets:["script","style","template","noscript","iframe","object","embed","xmp","plaintext","noembed","noframes","meta","link","base","animate","set","animatemotion","animatetransform"],refusedAttributes:["style","srcdoc","is","http-equiv","sandbox","allow","nonce","integrity","charset","htmlclaytoken","htmlclayid","data-rules-name","data-rules-version","clay","contenteditable",...je],refusedAttributePrefixes:["on"],urlAttributes:["href","src","srcset","action","formaction","poster","cite","data","ping","background","longdesc","usemap","xlink:href","manifest","codebase","icon"],refusedSchemes:["javascript","vbscript","data"]}),at=new Set(["textContent","innerText"]);function De(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 dt=/^[^\t\n\f\r "'>/=\u0000-\u001f\u007f]+$/;function _e(e,t,n=ue){if(!dt.test(String(e)))return`attribute name ${JSON.stringify(String(e))} is not valid`;let o=String(e).toLowerCase();if(n.refusedAttributePrefixes.some(r=>o.startsWith(r)))return`attribute "${o}" can run script`;if(n.refusedAttributes.includes(o))return`attribute "${o}" is not content`;if(n.urlAttributes.includes(o)&&t!=null){let r=o==="srcset"?String(t).split(",").map(s=>s.trim().split(/\s+/)[0]).filter(Boolean):[String(t)];for(let s of r){let l=De(s);if(l&&n.refusedSchemes.includes(l))return`"${l}:" URLs are not allowed in "${o}"`}}return null}function ae(e,t){let n=e.prop(t,"tagName");return n?String(n).toLowerCase():""}function ht(e,t){let n=ae(e,t)||"node",o=e.attr(t,"id");return o?`<${n}#${o}>`:`<${n}>`}function pt(e,t,n){let o=t;for(;o;){let r=ae(e,o);if(r&&n.refusedTargets.includes(r))return r;o=e.parent(o)}return null}function $e(e,t){return e.find(t,"script[data-rules-name]",{includeRulesTag:!0,templateAttr:null}).length>0}function mt(e,t){return ae(e,t)==="script"&&e.attr(t,"data-rules-name")!=null?!0:$e(e,t)}function Z(e,t=ue){let n=[],o=(i,f)=>(n.push({target:ht(e,i),reason:f}),!1),r=i=>{let f=pt(e,i,t);return f?o(i,`inside <${f}>, which is not content`):!0},s=i=>r(i)?$e(e,i)?o(i,"a text write here would delete the data rules tag"):!0:!1,l=(i,f,u)=>{if(!r(i))return!1;let p=_e(f,u,t);return p?o(i,p):!0};return{...e,text(i,f){if(f===void 0)return e.text(i);s(i)&&e.text(i,f)},attr(i,f,u){if(u===void 0)return e.attr(i,f);l(i,f,u)&&e.attr(i,f,u)},prop(i,f,u){if(u===void 0)return e.prop(i,f);if(t.refusedRuleForms.includes(f))return o(i,`"@${f}" writes HTML, only text is allowed`);if(at.has(f)){s(i)&&e.prop(i,f,u);return}l(i,f==="className"?"class":f,u)&&e.prop(i,f,u)},remove(i){if(mt(e,i)){o(i,"removing this would delete the data rules tag");return}e.remove(i)},replaceWith(i,f){return f===e.prop(i,"outerHTML")||o(i,'"@outerHTML" writes HTML, only text is allowed'),i},refusals:n,assertClean(){if(n.length)throw new q(n.slice())}}}function F(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function We(e){return e.reduce((t,n)=>typeof n=="number"?`${t}[${n}]`:t?`${t}.${n}`:n,"")}function de(e,t,n,o,r={}){let s=[],l=[];function c(f,u,p){if(Array.isArray(f)){let[,d]=f;if(!Array.isArray(u)||!F(d))return;u.forEach((w,h)=>c(d,w,[...p,h]));return}if(!(!F(f)||!F(u)))for(let d of Object.keys(u))Object.prototype.hasOwnProperty.call(f,d)?c(f[d],u[d],[...p,d]):s.push(We([...p,d]))}function i(f,u,p,d){if(p!==void 0){if(typeof u=="string"){if(u.endsWith("[]")||u==="."||u.startsWith("@"))return;let w=S(u),h=w===-1?u:u.slice(0,w);if(!h)return;e.find(f,h,r).length===0&&l.push({path:We(d),selector:h});return}if(!Array.isArray(u)&&F(u)&&F(p))for(let[w,h]of Object.entries(u))i(f,h,p[w],[...d,w])}}return c(n,o,[]),i(t,n,o,[]),{unknownKeys:s,unmatched:l}}function he(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let o=t&&t.ownerDocument?t.ownerDocument:t;return k(e,o,n)}return null}var gt=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function ve(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"&&n!=="file"&&(t.value=e.value),e.tagName==="INPUT"&&(n==="checkbox"||n==="radio")&&(t.checked=e.checked),e.tagName==="OPTION"&&(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 He(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 qe(e,t,n,o,r,s,l,c){if(e.nodeType===1&&((l?ke(e,n):He(e,o,s,!1))||r&&(l&&e!==s?e.matches(r):He(e,r,s,l))))return null;let i=t.importNode(e,!1);c.cloneToLive.set(i,e),c.liveToClone.set(e,i);let f=e.nodeType===1&&e.tagName==="TEMPLATE"?e.content:e,u=i.nodeType===1&&i.tagName==="TEMPLATE"?i.content:i;f!==e&&(c.cloneToLive.set(u,f),c.liveToClone.set(f,u));for(let p of f.childNodes||[]){let d=qe(p,t,n,o,r,s,l,c);d&&(u.appendChild(d),p.nodeType===1&&ve(p,d))}return e.nodeType===1&&ve(e,i),i}function V(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 s=r.implementation.createHTMLDocument(""),l=new WeakMap,c=new WeakMap,i=e.nodeType===9?e.documentElement:e;n&&s.documentElement.matches(n);let f=K(t),u=qe(i,s,t,f,n,i,o,{cloneToLive:l,liveToClone:c});e.nodeType===9&&u&&(s.replaceChild(u,s.documentElement),c.set(e,s),l.set(s,e));let p=d=>{if(gt.test(d))throw new Error(`Filtered content queries do not support stateful selector: ${d}`)};return{root:u,document:s,capability:t,selector:K(t),cloneToLive:l,liveToClone:c,original(d){return l.get(d)||null},cloneOf(d){return c.get(d)||null},query(d,w=u){return p(d),Array.from(w.querySelectorAll(d),h=>l.get(h)||h)},text(d=u){return(d===u?u:c.get(d))?.textContent||""},html(d=u){return(d===u?u:c.get(d))?.innerHTML??""},clone(d=u){let w=d===u?u:c.get(d);return w?s.importNode(w,!0):null}}}function Be(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function wt(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var b={semanticExclude:!0,find(e,t,n={}){let o=wt(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(c=>!Be(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(i=>!i.closest||!i.closest(c))}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 C(e,t={}){if(t.exclude===null)return b;let n=[K("data"),t.exclude].filter(Boolean).join(", "),o=e.nodeType===9?e:e.ownerDocument||e,r=e.nodeType===9?e.documentElement:e;if(!t._write&&!r?.matches?.(n)&&!r?.querySelector?.(n)&&!o?.querySelector?.(n))return b;let s=e.nodeType===9||!e.isConnected?e:e.ownerDocument,l=e.nodeType===9?e:e.ownerDocument,c=null,i=()=>c||(c=V(s,{capability:"data",exclude:t.exclude||null})),f=h=>{let y=i();return h===e?y.cloneOf(e):y.cloneOf(h)||h},u=h=>c?.original(h)||h,p=(h,y)=>{i().liveToClone.set(h,y),i().cloneToLive.set(y,h);let a=h.childNodes||[],m=y.childNodes||[];for(let g=0;g<Math.min(a.length,m.length);g++)p(a[g],m[g])},d=(h,y,a,m)=>{let g=Array.from(h.childNodes).filter(T=>c.cloneOf(T)),O=g[0];for(;O&&g.includes(O);)O=O.nextSibling;for(let T of g)T.remove();if(a==="innerHTML"){let T=l.createElement("template");T.innerHTML=m;for(let N of Array.from(T.content.childNodes))h.insertBefore(N,O||null)}else h.insertBefore(l.createTextNode(m),O||null);let E=V(h,{capability:"data",exclude:t.exclude||null});y.replaceChildren(...Array.from(E.root?.childNodes||[]));let A=T=>{let N=E.original(T);N&&(c.liveToClone.set(N,T),c.cloneToLive.set(T,N));for(let we of Array.from(T.childNodes||[]))A(we)};for(let T of Array.from(y.childNodes))A(T)},w={...b,find(h,y,a={}){let m=f(h);if(!m?.querySelectorAll)return[];let g=i().query(y,m);a.includeRulesTag||(g=g.filter(E=>!Be(E)));let x=[];a.skip&&x.push(a.skip);let O=a.templateAttr===null?null:a.templateAttr||"cms-template";if(O&&x.push(`[${O}]`),x.length){let E=x.join(", ");g=g.filter(A=>!A.closest?.(E))}return g},parent(h){let y=f(h)?.parentElement;return y?u(y):null},children(h){return Array.from(f(h)?.children||[],u)},text(h,y){if(y===void 0){let g=u(h);return!g?.matches?.(n)&&!g?.querySelector?.(n)?b.text(g):(f(h)?.textContent||"").trim()}let a=u(h);if(!a?.matches?.(n)&&!a?.querySelector?.(n)&&!c){b.text(a,y);return}let m=i().cloneOf(a);m?d(a,m,"textContent",y):b.text(a,y)},attr(h,y,a){let m=u(h);if(a===void 0)return b.attr(m,y);b.attr(m,y,a);let g=c?.cloneOf(m);g&&(b.attr(g,y,a),V(m,{capability:"data",exclude:t.exclude||null}).root===null&&(g.remove(),c.liveToClone.delete(m),c.cloneToLive.delete(g)))},removeAttr(h,y){let a=u(h);b.removeAttr(a,y);let m=c?.cloneOf(a);m&&b.removeAttr(m,y)},prop(h,y,a){let m=u(h);if(a===void 0)return y==="innerHTML"||y==="outerHTML"||y==="textContent"||y==="innerText"?b.prop(f(m),y):b.prop(m,y);let g=y==="innerHTML"||y==="textContent"||y==="innerText",x=g?i().cloneOf(m):c?.cloneOf(m);x&&g?d(m,x,y,a):(b.prop(m,y,a),x&&b.prop(x,y,a))},clone(h){let y=f(h);return y===h?b.clone(h):l.importNode(y,!0)},insertAt(h,y,a){let m=u(h),x=w.children(m)[a]||(()=>{for(let A=m.children.length-1;A>=0;A--){let T=m.children[A];if(i().cloneOf(T))return T.nextElementSibling}return m.firstElementChild})(),O=u(y);m.insertBefore(O,x||null);let E=i().cloneOf(m);if(E){let A=i().cloneOf(O);A||(A=l.importNode(O,!0),p(O,A));let T=Array.from(E.children);E.insertBefore(A,T[a]||null)}},remove(h){let y=u(h),a=i().cloneOf(y);b.remove(y),a&&b.remove(a)},replaceWith(h,y){let a=u(h),m=i().cloneOf(a),g=b.replaceWith(a,y);if(m){let x=V(g,{capability:"data",exclude:t.exclude||null});if(!x.root)m.remove();else{m.replaceWith(x.root);let O=E=>{let A=x.original(E);A&&(c.liveToClone.set(A,E),c.cloneToLive.set(E,A));for(let T of Array.from(E.childNodes||[]))O(T)};O(x.root)}}return g}};return w}var J=b;var Y={extract:(e,t,n={})=>M(C(e,n),e,t,n),apply:(e,t,n,o={})=>L(C(e,{...o,_write:!0}),e,t,n,o),findRulesIn:(e,t)=>k(J,e,t),findRules:(e,t)=>he(J,e,t),bind:(e,t,n={})=>{let o=he(J,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:()=>M(C(e,n),e,o.rules,n),set:r=>L(C(e,{...n,_write:!0}),e,o.rules,r,n)}},parseStrict:le,parseRelaxed:z,ruleAttrIndex:S,splitRule:re,errors:R,DOM_PROPERTIES:G},pe=e=>!!e&&typeof e.nodeType=="number";function Ue(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=k(J,t,"api");if(!n)throw new R.NoRulesTag("api");return n.rules}function Et(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 Tt(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 At(e,t){let n=[];for(;t!==e;){let o=t.parentNode;n.push(Array.prototype.indexOf.call(o.childNodes,t)),t=o}return n.reverse()}function Ot(e,t){return t.reduce((n,o)=>n.childNodes[o],e)}function D(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=D(e,"option"),o=D(t,"option");n.forEach((i,f)=>o[f].selected=i.selected);let r=D(e,"input"),s=D(t,"input");r.forEach((i,f)=>{let u=i.type.toLowerCase();u!=="file"&&(s[f].value=i.value),(u==="checkbox"||u==="radio")&&(s[f].checked=i.checked)});let l=D(e,"textarea"),c=D(t,"textarea");l.forEach((i,f)=>c[f].value=i.value)}function me(e,t){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]"))return;let n=e.startsWith("@")?0:S(e);if(n===-1)return;let o=e.slice(n+1);if(_.has(o))throw new R.RuleTargetReadOnly(o);return}if(Array.isArray(e)){if(!Array.isArray(t))return;t.forEach(n=>me(e[1],n));return}if(e&&typeof e=="object"&&t&&typeof t=="object"&&!Array.isArray(t))for(let[n,o]of Object.entries(e))me(o,t[n])}}function bt(e,t,n){let o={templateAttr:"cms-template"},r=Et(e),s=At(r,e),l=Tt(r);xt(r,l);let c=Ot(l,s),i=C(l,{...o,_write:!0}),f=de(i,c,t,n,o);if(f.unknownKeys.length||f.unmatched.length)throw new R.WriteRejected(f.unknownKeys,f.unmatched);let u=Z(i);L(u,c,t,n,o),u.assertClean(),me(t,n);let p=Z(C(r,{...o,_write:!0}));L(p,e,t,n,o),p.assertClean()}function St(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 ye(e,t){let n=pe(e)?e:document,o=pe(e)?t:e;return o===void 0?M(C(n),n,Ue(n)):Y.bind(n,o).get()}function ge(e,t,n){try{if(!pe(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");let o=n===void 0?Ue(e):Y.bind(e,n).rules;bt(e,o,t)}catch(o){throw St(o)}return e}var Rt={engine:Y,extractData:ye,applyData:ge},Nt=Rt;return Ye(Mt);})();
|
|
1
|
+
var hyperHtmlApiData=(()=>{var te=Object.defineProperty;var Ke=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var Ve=Object.prototype.hasOwnProperty;var Te=(e,t)=>{for(var n in t)te(e,n,{get:t[n],enumerable:!0})},Je=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Fe(t))!Ve.call(e,o)&&o!==n&&te(e,o,{get:()=>t[o],enumerable:!(r=Ke(t,o))||r.enumerable});return e};var Ye=e=>Je(te({},"__esModule",{value:!0}),e);var It={};Te(It,{applyData:()=>Ae,default:()=>Pt,engine:()=>G,extractData:()=>we});var X=["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"],ne=new Set(X),Ee=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"]);var R={};Te(R,{EmptyListInsert:()=>v,MAX_RULE_DEPTH:()=>j,MaxRuleDepthExceeded:()=>P,NoRulesTag:()=>re,RuleTargetReadOnly:()=>B,RulesParseError:()=>L,ShapeMismatch:()=>W,UnknownRulesVersion:()=>$,WriteRefused:()=>H,WriteRejected:()=>oe});var L=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},$=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},j=20,P=class extends Error{constructor(t){super(`rule depth exceeded ${j} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},W=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},v=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}},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}},re=class extends Error{constructor(t){super(`no <script data-rules-name~="${t}"> rules tag in this document`),this.name="NoRulesTag",this.token=t}},oe=class extends Error{constructor(t,n){super(`write rejected: ${t.length} unknown key(s), ${n.length} rule(s) with no matching element`),this.name="WriteRejected",this.unknownKeys=t,this.unmatched=n}};function S(e){let t=0,n=null,r=-1;for(let o=0;o<e.length;o++){let s=e[o];s==="\\"?o++:n?s===n&&(n=null):s==='"'||s==="'"?n=s:s==="["||s==="("?t++:s==="]"||s===")"?t>0&&t--:s==="@"&&t===0&&(r=o)}return r}function ie(e){let t=S(e);return t===-1?{selector:e,prop:null}:{selector:e.slice(0,t),prop:e.slice(t+1)||null}}function N(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 se(e,t,n,{depth:0,path:[]},r)}function se(e,t,n,r,o){if(r.depth>j)throw new P(r.path);if(typeof n=="string")return Ge(e,t,n,r,o);if(Array.isArray(n)){let[s,l]=n,c=e.find(t,s,o);return xe(o,r,c),c.map((i,f)=>se(e,i,l,{depth:r.depth+1,path:[...r.path,f]},o))}if(typeof n=="object"&&n!==null){let s={};for(let[l,c]of Object.entries(n))s[l]=se(e,t,c,{depth:r.depth+1,path:[...r.path,l]},o);return s}return null}function Ge(e,t,n,r,o){if(n.endsWith("[]")){let c=n.slice(0,-2),i=e.find(t,c,o);return xe(o,r,i),i.map(f=>e.text(f))}if(n.startsWith("@"))return Oe(e,t,n.slice(1));let s=S(n);if(s!==-1){let c=n.slice(0,s),i=n.slice(s+1),f=c?e.find(t,c,o):[t];return f.length===0?null:Oe(e,f[0],i)}if(n===".")return e.text(t);let l=e.find(t,n,o);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(ne.has(n)){let o=e.prop(t,n);return o==null?null:String(o)}let r=e.attr(t,n);return r||null}function Re(e,t,n,r){let o=e.length,s=t.length,l=new Array(o).fill(-1);if(r){let d=new Set;for(let y=0;y<o;y++){let w=r[y];!(w>=0&&w<s)||d.has(w)||(l[y]=w,d.add(w))}}if(o===0||s===0)return l;let c=e.map(d=>be(d,n)),i=t.map(d=>be(d,n)),f=new Array(s).fill(!1);for(let d of l)d>=0&&(f[d]=!0);let u=new Map;i.forEach((d,y)=>{f[y]||u.set(d,u.has(d)?-1:y)});let m=new Map;c.forEach((d,y)=>{l[y]>=0||m.set(d,(m.get(d)||0)+1)}),c.forEach((d,y)=>{if(l[y]>=0||m.get(d)!==1)return;let w=u.get(d);w===void 0||w===-1||f[w]||(l[y]=w,f[w]=!0)});let h=[];for(let d=0;d<o;d++)l[d]<0&&h.push(d);let T=[];for(let d=0;d<s;d++)f[d]||T.push(d);if(h.length===0||T.length===0)return l;let a=o*s+1,p=Xe(e,t,n),g=(d,y)=>p(d,y)*a+Math.abs(d-y);for(let[d,y]of Ze(h,T,g))l[d]=y;return l}var Ce=e=>typeof e=="object"&&e!==null;function be(e,t){if(!Ce(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(r=>{let o=JSON.stringify(e?.[r]);return o===void 0?" undef":o}))}function Xe(e,t,n){if(!Ce(n))return(c,i)=>e[c]===t[i]?0:1;let r=Object.keys(n),o=c=>r.map(i=>JSON.stringify(c?.[i])),s=e.map(o),l=t.map(o);return(c,i)=>{let f=s[c],u=l[i],m=0;for(let h=0;h<r.length;h++)f[h]!==u[h]&&m++;return m}}function Ze(e,t,n){return e.length<=t.length?Se(e,t,n,!1):Se(t,e,(r,o)=>n(o,r),!0)}function Se(e,t,n,r){let o=e.length,s=t.length,l=[];for(let m=0;m<=o;m++)l.push(new Float64Array(s+1).fill(1/0));let c=[];for(let m=0;m<=o;m++)c.push(new Uint8Array(s+1));for(let m=0;m<=s;m++)l[o][m]=0;for(let m=o-1;m>=0;m--)for(let h=s-1;h>=0;h--){let T=n(e[m],t[h])+l[m+1][h+1],a=l[m][h+1];T<=a?(l[m][h]=T,c[m][h]=1):l[m][h]=a}let i=[],f=0,u=0;for(;f<o&&u<s;)c[f][u]&&(i.push(r?[t[u],e[f]]:[e[f],t[u]]),f++),u++;return i}function le(e,t,n,r,o,s,l,c={}){let i=e.find(t,n,c);if(o.length===0){i.forEach(E=>e.remove(E)),ce(c,"onRowsApplied",s.path,[]);return}let f=o.length>i.length,u=i[0]||null;if(f&&!u&&(u=nt(e,t,n,c),!u))throw new v(s.path);let m=i.map(E=>tt(e,E,r,c)),h=null;if(f&&u){h=e.clone(u),c.templateAttr&&e.removeAttr(h,c.templateAttr);let E=e.stripIds(h);E>0&&console.warn(`[hyper-html-api] stripped ${E} id attribute(s) from cloned template at "${s.path.join(".")||"(root)"}"`)}let T=Re(o,m,r,Qe(e,i,o,s,c)),a=i[0]||u,p=e.parent(a),g=i.length>0?Ne(e,p,a):0,d=ot(e,i),y=new Set,w=[],A=o.map((E,x)=>{let O=T[x];if(O>=0)return y.add(O),w.push(!1),i[O];w.push(!0);let C=e.clone(h);return e.stripIds(C),C});i.forEach((E,x)=>{y.has(x)||e.remove(E)}),d?rt(e,p,g,A,w):it(e,A,w,p,g),et(e,A,r,o,s,l,c),ce(c,"onRowsApplied",s.path,A)}function ce(e,t,n,r){if(typeof e[t]=="function")try{return e[t](n.slice(),r)}catch(o){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,o);return}}function Qe(e,t,n,r,o){let s=ce(o,"identifyRows",r.path,n);if(!Array.isArray(s))return null;let l=new Array(n.length).fill(-1),c=new Set,i=new Map(t.map((f,u)=>[e.identity(f),u]));for(let f=0;f<n.length;f++){if(!s[f])continue;let u=i.get(e.identity(s[f]));u===void 0||c.has(u)||(l[f]=u,c.add(u))}return l}function et(e,t,n,r,o,s,l){t.forEach((c,i)=>{if(n===null){let f=r[i],u=f==null?"":String(f);e.text(c)!==u&&e.text(c,u)}else{let f=s(e,c,n,r[i],{depth:o.depth+1,path:[...o.path,i]},l);f&&f!==c&&(t[i]=f)}})}function tt(e,t,n,r){return n===null?e.text(t):N(e,t,n,r.onRowsRead?{...r,onRowsRead:void 0}:r)}function Ne(e,t,n){let r=e.children(t);for(let o=0;o<r.length;o++)if(e.sameNode(r[o],n))return o;return-1}function nt(e,t,n,r){if(!r.templateAttr)return null;let o=t;for(;o;){let s=e.find(o,n,{includeRulesTag:!1,templateAttr:null});for(let l of s)if(e.attr(l,r.templateAttr)!=null)return l;o=e.parent(o)}return null}function rt(e,t,n,r,o){let s=e.children(t),l=s.map(i=>e.identity(i)),c=!1;r.forEach((i,f)=>{let u=e.identity(i),m=n+f;if(l[m]===u)return;if(!o[f]){let T=l.indexOf(u);T!==-1&&(l.splice(T,1),s.splice(T,1))}let h=Math.min(m,s.length);h<s.length?e.insertBefore(s[h],i):s.length?c?e.insertAfter(s[s.length-1],i):(e.insertAt(t,i,m),c=!0):e.insertAt(t,i,0),l.splice(h,0,u),s.splice(h,0,i)})}function ot(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])),o=[];for(let s of t){let l=r.get(e.identity(s));if(l===void 0)return!1;o.push(l)}return o.sort((s,l)=>s-l),o[o.length-1]-o[0]===o.length-1}function it(e,t,n,r,o){let s=null,l=o;for(let c=0;c<t.length;c++){if(!n[c]){s=t[c];continue}let i=s?e.parent(s):r;if(!i)continue;let f=s?Ne(e,i,s)+1:l++;e.insertAt(i,t[c],f),s=t[c]}}var Me=new Set(["checked","selected","disabled","readOnly","paused"]);function I(e,t,n,r,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.");let s=[];if(fe(n,r,[],s),s.length)throw new W(s);Z(e,t,n,r,{depth:0,path:[]},o)}function Z(e,t,n,r,o,s={}){if(o.depth>j)throw new P(o.path);if(r===void 0)return t;if(typeof n=="string")return st(e,t,n,r,o,s);if(Array.isArray(n)){let[l,c]=n;return le(e,t,l,c,r,o,Z,s),t}if(typeof n=="object"&&n!==null){for(let[l,c]of Object.entries(n)){let i=Z(e,t,c,r==null?r:r[l],{depth:o.depth+1,path:[...o.path,l]},s);i&&i!==t&&(t=i)}return t}return t}function st(e,t,n,r,o,s){if(n.endsWith("[]")){let i=n.slice(0,-2);return le(e,t,i,null,r,o,Z,s),t}if(n.startsWith("@"))return Ie(e,t,n.slice(1),r);let l=S(n);if(l!==-1){let i=n.slice(0,l),f=n.slice(l+1),u=i?e.find(t,i,s):[t];return u.length===0||Ie(e,u[0],f,r),t}if(n===".")return Pe(e,t,r),t;let c=e.find(t,n,s);return c.length===0||Pe(e,c[0],r),t}function Pe(e,t,n){let r=n==null?"":String(n);e.text(t)!==r&&e.text(t,r)}function Ie(e,t,n,r){if(_.has(n)){let s=e.prop(t,n);if(s===r||s!=null&&r!=null&&String(s)===String(r))return t;throw new B(n)}if(n==="outerHTML"){let s=r==null?"":String(r);return e.replaceWith(t,s)}if(Ee.has(n)){let s=ct(n,r);return e.prop(t,n)!==s&&e.prop(t,n,s),t}let o=r==null?"":String(r);return e.attr(t,n)!==o&&e.attr(t,n,o),t}function ct(e,t){return t==null?Me.has(e)?!1:"":Me.has(e)?t==="false"?!1:!!t:t}function fe(e,t,n,r){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((o,s)=>{typeof o=="object"&&o!==null&&r.push({path:U([...n,s]),expected:"scalar",got:q(o)})}):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 o=e[1];t.forEach((s,l)=>fe(o,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[o,s]of Object.entries(e))fe(s,t[o],[...n,o],r)}}}function q(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function U(e){return e.join(".")}function ue(e){try{return JSON.parse(e)}catch(t){throw new L(`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(o){let s=[],l=0;for(;l<o.length;){let c=o[l];if(/\s/.test(c)){l++;continue}if("{}".includes(c)){s.push({type:c,value:c}),l++;continue}if(c==="["){let m=!1,h=l+1;for(;h<o.length&&/\s/.test(o[h]);)h++;if(h<o.length&&/[a-zA-Z_]/.test(o[h])&&(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,h=l+1;for(;h<o.length&&o[h]!==m;)o[h]==="\\"&&h++,h++;s.push({type:t.STRING,value:o.substring(l+1,h),quoted:!0,sourceQuote:m}),l=h+1;continue}let i=l,f;for(;i<o.length&&!/[{},]/.test(o[i]);)if(o[i]===":"){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"],h=!1;for(let T of m){let a=T.substring(1);if(o.substring(i+1,i+1+a.length)===a){h=!0,i+=a.length;break}}if(!h)break}else if(o[i]==="["){for(i++;i<o.length&&o[i]!=="]";){if(o[i]==='"'||o[i]==="'"){let m=o[i];for(i++;i<o.length&&o[i]!==m;)o[i]==="\\"&&i++,i++}i++}i<o.length&&o[i]==="]"&&i++}else i++;f=o.substring(l,i);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=i}return s}function r(o){let s="";for(let l=0;l<o.length;l++){let c=o[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 i=o[l+1];if(i&&(i.type==="}"||i.type==="]"))continue;s+=c.value;continue}if(c.type===t.STRING&&c.quoted){let i=c.value;c.sourceQuote==="'"&&(i=i.replace(/\\'/g,"'"),i=i.replace(/(\\*)"/g,(f,u)=>u.length%2===0?u+'\\"':f)),s+=`"${i}"`;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 o=n(e),s=r(o);return JSON.parse(s)}catch(o){throw new L("Invalid extraction rules syntax: "+o.message,o)}}var lt="1",Le=/^[a-zA-Z0-9_-]+$/;function k(e,t,n){let r;if(n===void 0)r="script[data-rules-name]";else{if(typeof n!="string"||!Le.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${Le})`);r=`script[data-rules-name~="${n}"]`}let o=e.find(t,r,{includeRulesTag:!0});if(o.length===0)return null;n!==void 0&&o.length>1&&console.warn(`hyper-html-api: ${o.length} rules tags match data-rules-name~="${n}"; using the first.`);let s=o[0],l=e.attr(s,"data-rules-version");if(l!==lt)throw new $(l);return{rules:z(e.text(s)),tagNode:s}}var Q=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"]})}),ft=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),je=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui","live"]);function 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 ae(e,t){if(K(e,t))return!0;for(let[n,r]of Object.entries(ft))if(r.includes(t)&&K(e,n))return!0;return!1}function F(e){let t=Q[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function ut(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let r=Q[t];if(!r)throw new Error(`Unknown region capability: ${t}`);if(r.tokens.some(o=>ae(n,o))||r.bundles.some(o=>K(n,o)))return n;n=n.parentElement}return null}function ke(e,t){return!!ut(e,t)}var de=Object.freeze({refusedRuleForms:["innerHTML","outerHTML"],refusedTargets:["script","style","template","noscript","iframe","object","embed","xmp","plaintext","noembed","noframes","meta","link","base","animate","set","animatemotion","animatetransform"],refusedAttributes:["style","srcdoc","is","http-equiv","sandbox","allow","nonce","integrity","charset","htmlclaytoken","htmlclayid","data-rules-name","data-rules-version","clay","contenteditable",...je],refusedAttributePrefixes:["on"],urlAttributes:["href","src","srcset","action","formaction","poster","cite","data","ping","background","longdesc","usemap","xlink:href","manifest","codebase","icon"],refusedSchemes:["javascript","vbscript","data"]}),at=new Set(["textContent","innerText"]);function De(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 dt=/^[^\t\n\f\r "'>/=\u0000-\u001f\u007f]+$/;function _e(e,t,n=de){if(!dt.test(String(e)))return`attribute name ${JSON.stringify(String(e))} is not valid`;let r=String(e).toLowerCase();if(n.refusedAttributePrefixes.some(o=>r.startsWith(o)))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 o=r==="srcset"?String(t).split(",").map(s=>s.trim().split(/\s+/)[0]).filter(Boolean):[String(t)];for(let s of o){let l=De(s);if(l&&n.refusedSchemes.includes(l))return`"${l}:" URLs are not allowed in "${r}"`}}return null}function he(e,t){let n=e.prop(t,"tagName");return n?String(n).toLowerCase():""}function ht(e,t){let n=he(e,t)||"node",r=e.attr(t,"id");return r?`<${n}#${r}>`:`<${n}>`}function pt(e,t,n){let r=t;for(;r;){let o=he(e,r);if(o&&n.refusedTargets.includes(o))return o;r=e.parent(r)}return null}function $e(e,t){return e.find(t,"script[data-rules-name]",{includeRulesTag:!0,templateAttr:null}).length>0}function mt(e,t){return he(e,t)==="script"&&e.attr(t,"data-rules-name")!=null?!0:$e(e,t)}function ee(e,t=de){let n=[],r=(i,f)=>(n.push({target:ht(e,i),reason:f}),!1),o=i=>{let f=pt(e,i,t);return f?r(i,`inside <${f}>, which is not content`):!0},s=i=>o(i)?$e(e,i)?r(i,"a text write here would delete the data rules tag"):!0:!1,l=(i,f,u)=>{if(!o(i))return!1;let m=_e(f,u,t);return m?r(i,m):!0};return{...e,text(i,f){if(f===void 0)return e.text(i);s(i)&&e.text(i,f)},attr(i,f,u){if(u===void 0)return e.attr(i,f);l(i,f,u)&&e.attr(i,f,u)},prop(i,f,u){if(u===void 0)return e.prop(i,f);if(t.refusedRuleForms.includes(f))return r(i,`"@${f}" writes HTML, only text is allowed`);if(at.has(f)){s(i)&&e.prop(i,f,u);return}l(i,f==="className"?"class":f,u)&&e.prop(i,f,u)},remove(i){if(mt(e,i)){r(i,"removing this would delete the data rules tag");return}e.remove(i)},replaceWith(i,f){return f===e.prop(i,"outerHTML")||r(i,'"@outerHTML" writes HTML, only text is allowed'),i},refusals:n,assertClean(){if(n.length)throw new H(n.slice())}}}function V(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function We(e){return e.reduce((t,n)=>typeof n=="number"?`${t}[${n}]`:t?`${t}.${n}`:n,"")}function pe(e,t,n,r,o={}){let s=[],l=[];function c(f,u,m){if(Array.isArray(f)){let[,h]=f;if(!Array.isArray(u)||!V(h))return;u.forEach((T,a)=>c(h,T,[...m,a]));return}if(!(!V(f)||!V(u)))for(let h of Object.keys(u))Object.prototype.hasOwnProperty.call(f,h)?c(f[h],u[h],[...m,h]):s.push(We([...m,h]))}function i(f,u,m,h){if(m!==void 0){if(typeof u=="string"){if(u.endsWith("[]")||u==="."||u.startsWith("@"))return;let T=S(u),a=T===-1?u:u.slice(0,T);if(!a)return;e.find(f,a,o).length===0&&l.push({path:We(h),selector:a});return}if(!Array.isArray(u)&&V(u)&&V(m))for(let[T,a]of Object.entries(u))i(f,a,m[T],[...h,T])}}return c(n,r,[]),i(t,n,r,[]),{unknownKeys:s,unmatched:l}}function me(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 k(e,r,n)}return null}var gt=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function wt(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 ve(e,t,n,r){if(r)return!!e.closest?.(t);let o=e;for(;o?.nodeType===1;){if(o.matches(t))return!0;if(o===n)break;o=o.parentElement}return!1}function Be(e,t,n,r,o,s){return(s?ke(e,t):ve(e,n,o,!1))||!!(r&&(s&&e!==o?e.matches(r):ve(e,r,o,s)))}function At(e,t){let n=Q[t];return n.tokens.some(r=>ae(e,r))||n.bundles.some(r=>K(e,r))}var Tt=new Set(["INPUT","TEXTAREA","SELECT","OPTION"]);function He(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 o=e,s=t;if(e.nodeType===1){if(Tt.has(e.tagName)&&n.controls.push(e,t),e.tagName==="TEMPLATE"){for(;t.firstChild;)t.removeChild(t.firstChild);o=e.content,s=t.content,n.cloneToLive.set(s,o),n.liveToClone.set(o,s)}}else if(e.nodeType!==11)return;let l=s.firstChild;for(let c=o.firstChild;c&&l;c=c.nextSibling)He(c,l,n,r),l=l.nextSibling}function J(e,{capability:t="data",exclude:n=null,inherit:r=!0,provenance:o=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=o||new WeakMap,i=new WeakMap,f=e.nodeType===9?e.documentElement:e;n&&l.documentElement.matches(n);let u=F(t),m=r?a=>At(a,t)||!!(n&&a.matches(n)):a=>Be(a,t,u,n,f,!1),h=null;if(f.nodeType!==1||!Be(f,t,u,n,f,r)){h=l.importNode(f,!0);let a={cloneToLive:c,liveToClone:i,dropped:[],controls:[]};He(f,h,a,m);for(let p of a.dropped)p.remove();for(let p=0;p<a.controls.length;p+=2)wt(a.controls[p],a.controls[p+1])}e.nodeType===9&&h&&(l.replaceChild(h,l.documentElement),i.set(e,l),c.set(l,e));let T=a=>{if(gt.test(a))throw new Error(`Filtered content queries do not support stateful selector: ${a}`)};return{root:h,document:l,capability:t,selector:F(t),cloneToLive:c,liveToClone:i,original(a){return c.get(a)||null},cloneOf(a){return i.get(a)||null},query(a,p=h){return T(a),Array.from(p.querySelectorAll(a),g=>c.get(g)||g)},text(a=h){return(a===h?h:i.get(a))?.textContent||""},html(a=h){return(a===h?h:i.get(a))?.innerHTML??""},clone(a=h){let p=a===h?h:i.get(a);return p?l.importNode(p,!0):null}}}function qe(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function Et(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var b={semanticExclude:!0,find(e,t,n={}){let r=Et(e);if(!r||!r.querySelectorAll)return[];let o=Array.from(r.querySelectorAll(t));n.includeRulesTag||(o=o.filter(c=>!qe(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(", ");o=o.filter(i=>!i.closest||!i.closest(c))}return o},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 r=e?e[t]:void 0;return r!==void 0?r:null}e[t]=n},clone(e){return e.cloneNode(!0)},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 o=r.content.firstElementChild;if(!o)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(o,e),o},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 b;let n=[F("data"),t.exclude].filter(Boolean).join(", "),r=e.nodeType===9?e:e.ownerDocument||e,o=e.nodeType===9?e.documentElement:e;if(!t._write&&!o?.matches?.(n)&&!o?.querySelector?.(n)&&!r?.querySelector?.(n))return b;let s=e.nodeType===9||!e.isConnected?e:e.ownerDocument,l=e.nodeType===9?e:e.ownerDocument,c=null,i=()=>c||(c=J(s,{capability:"data",exclude:t.exclude||null})),f=a=>{let p=i();return a===e?p.cloneOf(e):p.cloneOf(a)||a},u=a=>c?.original(a)||a,m=(a,p)=>{i().liveToClone.set(a,p),i().cloneToLive.set(p,a);let g=a.childNodes||[],d=p.childNodes||[];for(let y=0;y<Math.min(g.length,d.length);y++)m(g[y],d[y])},h=(a,p,g,d)=>{let y=Array.from(a.childNodes).filter(O=>c.cloneOf(O)),A=y[0];for(;A&&y.includes(A);)A=A.nextSibling;for(let O of y)O.remove();if(g==="innerHTML"){let O=l.createElement("template");O.innerHTML=d;for(let C of Array.from(O.content.childNodes))a.insertBefore(C,A||null)}else a.insertBefore(l.createTextNode(d),A||null);let E=J(a,{capability:"data",exclude:t.exclude||null});p.replaceChildren(...Array.from(E.root?.childNodes||[]));let x=O=>{let C=E.original(O);C&&(c.liveToClone.set(C,O),c.cloneToLive.set(O,C));for(let ze of Array.from(O.childNodes||[]))x(ze)};for(let O of Array.from(p.childNodes))x(O)},T={...b,find(a,p,g={}){let d=f(a);if(!d?.querySelectorAll)return[];let y=i().query(p,d);g.includeRulesTag||(y=y.filter(E=>!qe(E)));let w=[];g.skip&&w.push(g.skip);let A=g.templateAttr===null?null:g.templateAttr||"cms-template";if(A&&w.push(`[${A}]`),w.length){let E=w.join(", ");y=y.filter(x=>!x.closest?.(E))}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)?b.text(y):(f(a)?.textContent||"").trim()}let g=u(a);if(!g?.matches?.(n)&&!g?.querySelector?.(n)&&!c){b.text(g,p);return}let d=i().cloneOf(g);d?h(g,d,"textContent",p):b.text(g,p)},attr(a,p,g){let d=u(a);if(g===void 0)return b.attr(d,p);b.attr(d,p,g);let y=c?.cloneOf(d);y&&(b.attr(y,p,g),J(d,{capability:"data",exclude:t.exclude||null}).root===null&&(y.remove(),c.liveToClone.delete(d),c.cloneToLive.delete(y)))},removeAttr(a,p){let g=u(a);b.removeAttr(g,p);let d=c?.cloneOf(g);d&&b.removeAttr(d,p)},prop(a,p,g){let d=u(a);if(g===void 0)return p==="innerHTML"||p==="outerHTML"||p==="textContent"||p==="innerText"?b.prop(f(d),p):b.prop(d,p);let y=p==="innerHTML"||p==="textContent"||p==="innerText",w=y?i().cloneOf(d):c?.cloneOf(d);w&&y?h(d,w,p,g):(b.prop(d,p,g),w&&b.prop(w,p,g))},clone(a){let p=f(a);return p===a?b.clone(a):l.importNode(p,!0)},insertAt(a,p,g){let d=u(a),w=T.children(d)[g]||(()=>{for(let x=d.children.length-1;x>=0;x--){let O=d.children[x];if(i().cloneOf(O))return O.nextElementSibling}return d.firstElementChild})(),A=u(p);d.insertBefore(A,w||null);let E=i().cloneOf(d);if(E){let x=i().cloneOf(A);x||(x=l.importNode(A,!0),m(A,x));let O=Array.from(E.children);E.insertBefore(x,O[g]||null)}},insertBefore(a,p){let g=u(a),d=u(p);g.parentNode.insertBefore(d,g);let y=i().cloneOf(g.parentNode);if(y){let w=i().cloneOf(d);w||(w=l.importNode(d,!0),m(d,w));let A=i().cloneOf(g);A?A.before(w):y.appendChild(w)}},insertAfter(a,p){let g=u(a),d=u(p);g.parentNode.insertBefore(d,g.nextSibling);let y=i().cloneOf(g.parentNode);if(y){let w=i().cloneOf(d);w||(w=l.importNode(d,!0),m(d,w));let A=i().cloneOf(g);A?A.after(w):y.appendChild(w)}},identity(a){return u(a)||null},remove(a){let p=u(a),g=i().cloneOf(p);b.remove(p),g&&b.remove(g)},replaceWith(a,p){let g=u(a),d=i().cloneOf(g),y=b.replaceWith(g,p);if(d){let w=J(y,{capability:"data",exclude:t.exclude||null});if(!w.root)d.remove();else{d.replaceWith(w.root);let A=E=>{let x=w.original(E);x&&(c.liveToClone.set(x,E),c.cloneToLive.set(E,x));for(let O of Array.from(E.childNodes||[]))A(O)};A(w.root)}}return y}};return T}var Y=b;var G={extract:(e,t,n={})=>N(M(e,n),e,t,n),apply:(e,t,n,r={})=>I(M(e,{...r,_write:!0}),e,t,n,r),findRulesIn:(e,t)=>k(Y,e,t),findRules:(e,t)=>me(Y,e,t),bind:(e,t,n={})=>{let r=me(Y,e,t);if(!r){let o=typeof t=="string"?`data-rules-name~="${t}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${o}`)}return{...r,get:()=>N(M(e,n),e,r.rules,n),set:o=>I(M(e,{...n,_write:!0}),e,r.rules,o,n)}},parseStrict:ue,parseRelaxed:z,ruleAttrIndex:S,splitRule:ie,errors:R,DOM_PROPERTIES:X},ye=e=>!!e&&typeof e.nodeType=="number";function Ue(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=k(Y,t,"api");if(!n)throw new R.NoRulesTag("api");return n.rules}function Ot(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 xt(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 r=t.parentNode;n.push(Array.prototype.indexOf.call(r.childNodes,t)),t=r}return n.reverse()}function St(e,t){return t.reduce((n,r)=>n.childNodes[r],e)}function D(e,t){let n=e.querySelectorAll?Array.from(e.querySelectorAll(t)):[];return e.matches?.(t)&&n.unshift(e),n}function Rt(e,t){let n=D(e,"option"),r=D(t,"option");n.forEach((i,f)=>r[f].selected=i.selected);let o=D(e,"input"),s=D(t,"input");o.forEach((i,f)=>{let u=i.type.toLowerCase();u!=="file"&&(s[f].value=i.value),(u==="checkbox"||u==="radio")&&(s[f].checked=i.checked)});let l=D(e,"textarea"),c=D(t,"textarea");l.forEach((i,f)=>c[f].value=i.value)}function ge(e,t){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]"))return;let n=e.startsWith("@")?0:S(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=>ge(e[1],n));return}if(e&&typeof e=="object"&&t&&typeof t=="object"&&!Array.isArray(t))for(let[n,r]of Object.entries(e))ge(r,t[n])}}function Ct(e,t,n){let r={templateAttr:"cms-template"},o=Ot(e),s=bt(o,e),l=xt(o);Rt(o,l);let c=St(l,s),i=M(l,{...r,_write:!0}),f=pe(i,c,t,n,r);if(f.unknownKeys.length||f.unmatched.length)throw new R.WriteRejected(f.unknownKeys,f.unmatched);let u=ee(i);I(u,c,t,n,r),u.assertClean(),ge(t,n);let m=ee(M(o,{...r,_write:!0}));I(m,e,t,n,r),m.assertClean()}function Nt(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 we(e,t){let n=ye(e)?e:document,r=ye(e)?t:e;return r===void 0?N(M(n),n,Ue(n)):G.bind(n,r).get()}function Ae(e,t,n){try{if(!ye(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");let r=n===void 0?Ue(e):G.bind(e,n).rules;Ct(e,r,t)}catch(r){throw Nt(r)}return e}var Mt={engine:G,extractData:we,applyData:Ae},Pt=Mt;return Ye(It);})();
|