import{ELEMENT_NODE as a,walkSync as p}from"../index.js";function f(t){var n;if(t===void 0)return{allowElements:[],dropElements:["script"],allowComponents:!1,allowCustomElements:!1,allowComments:!1};{let e=new Set([]);(n=t.allowElements)!=null&&n.includes("script")||e.add("script");for(let o of t.dropElements??[])e.add(o);return{allowComponents:!1,allowCustomElements:!1,allowComments:!1,...t,dropElements:Array.from(e)}}}function E(t){return t.name.includes("-")?"custom-element":/[\_\$A-Z]/.test(t.name[0])||t.name.includes(".")?"component":"element"}function w(t,n,e){var o,l,s,r;return((o=e.allowElements)==null?void 0:o.length)>0&&e.allowElements.includes(t)?"allow":((l=e.blockElements)==null?void 0:l.length)>0&&e.blockElements.includes(t)?"block":((s=e.dropElements)==null?void 0:s.length)>0&&e.dropElements.find(u=>u===t)||n==="component"&&!e.allowComponents||n==="custom-element"&&!e.allowCustomElements||((r=e.allowElements)==null?void 0:r.length)>0?"drop":"allow"}function b(t,n){var o,l,s,r,u,m,d,c;let e=t.attributes;for(let i of Object.keys(t.attributes))((o=n.allowAttributes)==null?void 0:o[i])&&((l=n.allowAttributes)==null?void 0:l[i].includes(t.name))||((r=(s=n.allowAttributes)==null?void 0:s[i])==null?void 0:r.includes("*"))||(((u=n.dropAttributes)==null?void 0:u[i])&&((m=n.dropAttributes)==null?void 0:m[i].includes(t.name))||((c=(d=n.dropAttributes)==null?void 0:d[i])==null?void 0:c.includes("*")))&&delete e[i];return e}function g(t,n,e){let o=E(n),{name:l}=n,s=w(l,o,t);return s==="drop"?()=>{e.children=e.children.filter(r=>r!==n)}:s==="block"?()=>{e.children=e.children.map(r=>r===n?r.children:r).flat(1)}:()=>{n.attributes=b(n,t)}}function N(t){let n=f(t);return e=>{let o=[];p(e,(l,s)=>{switch(l.type){case a:{o.push(g(n,l,s));return}default:return}});for(let l of o)l();return e}}export{N as default};