var A=0,L=1,R=2,k=3,$=4;function X(t,n={},...o){let r={type:1,name:typeof t=="function"?t.name:t,attributes:n||{},children:o.map(e=>typeof e=="string"?{type:2,value:O(String(e))}:e),parent:void 0,loc:[]};return typeof t=="function"&&w(r,t),r}var S=Symbol("Fragment"),_=new Set(["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"]),g=new Set(["script","style"]),v=/([\@\.a-z0-9_\:\-]*)\s*?=?\s*?(['"]?)([\s\S]*?)\2\s+/gim,i=/(?:<(\/?)([a-zA-Z][a-zA-Z0-9\:-]*)(?:\s([^>]*?))?((?:\s*\/)?)>|(<\!\-\-)([\s\S]*?)(\-\->)|(<\!)([\s\S]*?)(>))/gm;function M(t){let n={},o;if(t)for(v.lastIndex=0,t=" "+(t||"")+" ";o=v.exec(t);)o[0]!==" "&&(n[o[1]]=o[3]);return n}function P(t){let n=typeof t=="string"?t:t.value,o,r,e,s,l,d,N,E,a,c=[];i.lastIndex=0,r=o={type:0,children:[]};let u=0;function y(){s=n.substring(u,i.lastIndex-e[0].length),s&&r.children.push({type:2,value:s,parent:r})}for(;e=i.exec(n);){if(d=e[5]||e[8],N=e[6]||e[9],E=e[7]||e[10],g.has(r.name)&&e[2]!==r.name){l=i.lastIndex-e[0].length,r.children.length>0&&(r.children[0].value+=e[0]);continue}else if(d==="<!--"){if(l=i.lastIndex-e[0].length,g.has(r.name))continue;a={type:3,value:N,parent:r,loc:[{start:l,end:l+d.length},{start:i.lastIndex-E.length,end:i.lastIndex}]},c.push(a),a.parent.children.push(a)}else if(d==="<!")l=i.lastIndex-e[0].length,a={type:4,value:N,parent:r,loc:[{start:l,end:l+d.length},{start:i.lastIndex-E.length,end:i.lastIndex}]},c.push(a),a.parent.children.push(a);else if(e[1]!=="/")if(y(),g.has(r.name)){u=i.lastIndex,y();continue}else a={type:1,name:e[2]+"",attributes:M(e[3]),parent:r,children:[],loc:[{start:i.lastIndex-e[0].length,end:i.lastIndex}]},c.push(a),a.parent.children.push(a),e[4]&&e[4].indexOf("/")>-1||_.has(a.name)?(a.loc[1]=a.loc[0],a.isSelfClosingTag=!0):r=a;else y(),e[2]+""===r.name?(a=r,r=a.parent,a.loc.push({start:i.lastIndex-e[0].length,end:i.lastIndex}),s=n.substring(a.loc[0].end,a.loc[1].start),a.children.length===0&&a.children.push({type:2,value:s,parent:r})):e[2]+""===c[c.length-1].name&&c[c.length-1].isSelfClosingTag===!0&&(a=c[c.length-1],a.loc.push({start:i.lastIndex-e[0].length,end:i.lastIndex}));u=i.lastIndex}return s=n.slice(u),r.children.push({type:2,value:s,parent:r}),o}var h=class{constructor(n){this.callback=n}async visit(n,o,r){if(await this.callback(n,o,r),Array.isArray(n.children)){let e=[];for(let s=0;s<n.children.length;s++){let l=n.children[s];e.push(this.visit(l,n,s))}await Promise.all(e)}}},m=class{constructor(n){this.callback=n}visit(n,o,r){if(this.callback(n,o,r),Array.isArray(n.children))for(let e=0;e<n.children.length;e++){let s=n.children[e];this.visit(s,n,e)}}},p=Symbol("HTMLString"),b=Symbol("AttrString"),x=Symbol("RenderFn");function f(t,n=[p]){let o={value:t};for(let r of n)Object.defineProperty(o,r,{value:!0,enumerable:!1,writable:!1});return o}function j(t){return f(t)}function w(t,n){return Object.defineProperty(t,x,{value:n,enumerable:!1}),t}var I={"&":"&amp;","<":"&lt;",">":"&gt;"};function O(t){return t.replace(/[&<>]/g,n=>I[n]||n)}function T(t){let n="";for(let[o,r]of Object.entries(t))n+=` ${o}="${r}"`;return f(n,[p,b])}function V(t,...n){let o="";for(let r=0;r<t.length;r++){o+=t[r];let e=n[r];o.endsWith("...")&&e&&typeof e=="object"?(o=o.slice(0,-3).trimEnd(),o+=T(e).value):e&&e[b]?(o=o.trimEnd(),o+=e.value):e&&e[p]?o+=e.value:typeof e=="string"?o+=O(e):(e||e===0)&&(o+=String(e))}return f(o)}function F(t,n){return new h(n).visit(t)}function H(t,n){return new m(n).visit(t)}async function C(t){let{name:n,attributes:o={}}=t,r=await Promise.all(t.children.map(e=>D(e))).then(e=>e.join(""));if(x in t){let e=await t[x](o,f(r));return e&&e[p]?e.value:O(String(e))}return n===S?r:_.has(n)?`<${t.name}${T(o).value}>`:`<${t.name}${T(o).value}>${r}</${t.name}>`}async function D(t){switch(t.type){case 0:return Promise.all(t.children.map(n=>D(n))).then(n=>n.join(""));case 1:return C(t);case 2:return`${t.value}`;case 3:return`<!--${t.value}-->`;case 4:return`<!${t.value}>`}}async function U(t,n=[]){if(!Array.isArray(n))throw new Error(`Invalid second argument for \`transform\`! Expected \`Transformer[]\` but got \`${typeof n}\``);let r=typeof t=="string"?P(t):t;for(let e of n)r=await e(r);return D(r)}export{k as COMMENT_NODE,$ as DOCTYPE_NODE,A as DOCUMENT_NODE,L as ELEMENT_NODE,S as Fragment,x as RenderFn,R as TEXT_NODE,j as __unsafeHTML,w as __unsafeRenderFn,T as attrs,X as h,V as html,P as parse,D as render,U as transform,F as walk,H as walkSync};
