"use strict";var Html5parser=(()=>{var E=Object.defineProperty;var pe=Object.getOwnPropertyDescriptor;var fe=Object.getOwnPropertyNames;var de=Object.prototype.hasOwnProperty;var Te=(e,t)=>{for(var n in t)E(e,n,{get:t[n],enumerable:!0})},ge=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let f of fe(t))!de.call(e,f)&&f!==n&&E(e,f,{get:()=>t[f],enumerable:!(o=pe(t,f))||o.enumerable});return e};var ce=e=>ge(E({},"__esModule",{value:!0}),e);var _e={};Te(_e,{SyntaxKind:()=>L,TokenKind:()=>C,parse:()=>ie,removeAttribute:()=>ue,setAttribute:()=>le,stringify:()=>V,tokenize:()=>N,walk:()=>q});var L=(n=>(n.Text="Text",n.Tag="Tag",n))(L||{});var P=new Set(["area","base","basefont","bgsound","br","col","command","embed","frame","hr","image","img","input","keygen","link","meta","param","source","track","wbr","!doctype","","!","!--"]),R=new Set(["li","option","select","textarea"]),G=new Set(["title","textarea"]),U=new Set(["style","xmp","iframe","noembed","noframes"]),_=new Set(["script"]),j=new Set(["noscript"]),F=new Set(["plaintext"]);var C=(u=>(u[u.Literal=0]="Literal",u[u.OpenTag=1]="OpenTag",u[u.OpenTagEnd=2]="OpenTagEnd",u[u.CloseTag=3]="CloseTag",u[u.Whitespace=4]="Whitespace",u[u.AttrValueEq=5]="AttrValueEq",u[u.AttrValueNq=6]="AttrValueNq",u[u.AttrValueSq=7]="AttrValueSq",u[u.AttrValueDq=8]="AttrValueDq",u))(C||{}),p,v,J,s,l,$,r,g,b,h,O,S,M;function H(e){return{lower:e.toLowerCase().split("").map(t=>t.charCodeAt(0)),upper:e.toUpperCase().split("").map(t=>t.charCodeAt(0)),length:e.length}}var A=H("!doctype");function y(){return r===32||r===10||r===9||r===9||r===13||r===12}function Q(e,t){p=0,v=e,J=e.length,s=0,l=0,$=[],g=0,b=0,h=void 0,O=0,S="",M=t}function me(e){return G.has(e)?1:U.has(e)?2:_.has(e)?3:F.has(e)?4:M.scriptingEnabled&&j.has(e)?2:0}function be(e){S=e,O=me(e)}function Ie(e){e!=="/"&&O!==0&&(b=O,h=H(S),S==="textarea"&&v.charCodeAt(s)===10&&(s++,l++)),O=0,S=""}function xe(){b=0,h=void 0}function D(){s-=2,p=0}function N(e,t={}){for(Q(e,{scriptingEnabled:t.scriptingEnabled!==!1});l<J;){switch(r=v.charCodeAt(l),p){case 0:ke();break;case 1:Oe();break;case 2:Se();break;case 3:X();break;case 4:ve();break;case 5:ye();break;case 6:Ae();break;case 7:Ce();break;case 8:he();break;case 9:Ne();break;case 10:qe();break;case 11:Ke();break;case 12:we();break;case 13:Ve();break;case 14:Ee();break;default:W()}l++}switch(p){case 0:case 1:case 4:case 5:case 6:case 7:case 11:case 12:case 13:a(0);break;case 2:a(1);break;case 3:break;case 8:a(1,12);break;case 9:l-s===A.length?a(1):(a(1,void 0,s+1),a(0));break;case 10:l-s===2?a(1):(a(1,void 0,s+1),a(0));break;case 14:a(3);break;default:break}let n=$;return Q("",M),n}function a(e,t=p,n=l){let o=v.substring(s,n);(e===1||e===3)&&(o=o.toLowerCase()),e===1&&be(o),e===3&&xe(),(e===0||e===4)&&n===s||$.push({type:e,start:s,end:n,value:o}),e===2||e===3?(s=n+1,p=0,e===2&&Ie(o)):(s=n,p=t)}function ke(){b!==4&&r===60&&a(0,1)}function Oe(){if(b!==0){r===47?(p=14,s=l+1):p=0;return}r>=97&&r<=122||r>=65&&r<=90?(p=2,s=l):r===47?(p=14,s=l+1):r===60?a(0):r===33?(p=8,s=l):r===63?(s=l,a(1,12)):p=0}function Se(){y()?a(1,3):r===62?(a(1),a(2)):r===47&&a(1,7)}function X(){r===62?(a(4),a(2)):r===47?a(4,7):r===61?(a(4),a(5,void 0,l+1)):r===39?a(4,5):r===34?a(4,6):y()||a(4,4)}function ve(){r===62?(a(6),a(2)):r===47?a(6,7):r===61?(a(6),a(5,3,l+1)):y()&&a(6,3)}function ye(){r===39&&a(7,3,l+1)}function Ae(){r===34&&a(8,3,l+1)}function Ce(){r===62?a(2):(a(6,3),X())}function he(){switch(r){case 45:p=10;break;case 100:case 68:p=9;break;default:a(1,12);break}}function Ne(){g=l-s,g===A.length?y()?a(1,3):W():r===62?(a(1,void 0,s+1),a(0),a(2)):A.lower[g]!==r&&A.upper[g]!==r&&a(1,12,s+1)}function qe(){r===45?a(1,11,l+1):a(1,12,s+1)}function Ke(){r===45&&a(0,13)}function we(){r===62&&(a(0),a(2))}function Ve(){g=l-s,g===2?r===62?a(2):r===45?a(0,void 0,s+1):p=11:r!==45&&(p=11)}function Ee(){if(g=l-s,b!==0){let e=h;e||W(),r===60?(D(),a(0,1)):g<e.length?e.lower[g]!==r&&e.upper[g]!==r&&D():r===62?a(3):y()||D()}else r===62&&a(3)}function W(){throw new SyntaxError(`Unexpected token "${v.charAt(l)}" at ${l} when parse ${p}`)}function Y(e){return e.split(`
`).reduce((t,n)=>(t.push(n.length+1+t[t.length-1]),t),[0])}function Z(e,t){let n=NaN,o=NaN;for(let f=1;f<e.length;f++)if(e[f]>t){n=f,o=t-e[f-1]+1;break}return[n,o]}function ee(e,t,n,o){if(o.enter&&o.enter(e,t,n),e.type==="Tag"&&Array.isArray(e.body))for(let f=0;f<e.body.length;f++)ee(e.body[f],e,f,o);o.leave&&o.leave(e,t,n)}function q(e,t){for(let n=0;n<e.length;n++)ee(e[n],void 0,n,t)}var c,I,m,d,B,i,T,x,K,ae;function te(e,t){e===void 0?(I=0,m.length=0,x=""):(m=N(e,{scriptingEnabled:t?.scriptingEnabled}),I=m.length,x=e),c=0,d=void 0,B=[],i=void 0,T=void 0,K=void 0,ae=t}function z(e){d?e.type==="Tag"&&e.name===d.tag.name&&R.has(e.name)?(d=d.parent,z(e)):d.tag.body&&(d.tag.end=e.end,d.tag.body.push(e)):B.push(e)}function Le(e){d={parent:d,tag:e},T=void 0}function k(e=i.start,t=i.end,n=i.value){return{start:e,end:t,value:n,type:"Text"}}function De(){return{start:i.start-1,end:i.end,type:"Tag",open:k(i.start-1),name:i.value,rawName:x.substring(i.start,i.end),attributes:[],attributeMap:void 0,body:null,close:null}}function ne(){return{start:i.start,end:i.end,name:k(),value:void 0}}function $e(){return{start:i.start,end:i.end,value:i.type===6?i.value:i.value.substr(1,i.value.length-2),quote:i.type===6?void 0:i.type===7?"'":'"'}}function w(e=T){e.value+=i.value,e.end=i.end}function Me(){K===void 0&&(K=Y(x));let[e,t]=Z(K,i.start);throw new Error(`Unexpected token "${i.value}(${i.type})" at [${e},${t}]`+(d?` when parsing tag: ${JSON.stringify(d.tag.name)}.`:""))}function We(e){e.attributeMap={};for(let t of e.attributes)e.attributeMap[t.name.value]=t}function Be(){let e=0,t,n=De();if(z(n),n.name===""||n.name==="!"||n.name==="!--"){if(n.open.value="<"+n.open.value,c===I)return;if(i=m[++c],i.type!==2)for(T=k(),n.body=[T];++c<I;){if(i=m[c],i.type===2){T=void 0;break}w()}n.close=k(i.start,i.end+1,`${i.value}>`),n.end=n.close.end;return}for(;++c<I;)if(i=m[c],i.type===2){n.end=n.open.end=i.end+1,n.open.value=x.substring(n.open.start,n.open.end),i.value===""&&!P.has(n.name)?(n.body=[],Le(n)):n.body=void 0;break}else e===0?i.type!==4&&(t=ne(),e=1,n.attributes.push(t)):e===1?i.type===4?e=2:i.type===5?e=3:w(t.name):e===2?i.type!==4&&(i.type===5?e=3:(t=ne(),e=1,n.attributes.push(t))):e===3?i.type!==4&&(t.value=$e(),i.type===6?e=4:(t.end=t.value.end,e=0)):i.type===4?(t.end=t.value.end,e=0):w(t.value)}function ze(){let e=d;for(;!(!e||i.value.trim()===e.tag.name);)e=e.parent;e&&(e.tag.close=k(i.start-2,i.end+1,x.substring(i.start-2,i.end+1)),e.tag.end=e.tag.close.end,e=e.parent,d=e)}function ie(e,t){for(te(e,{setAttributeMap:!1,scriptingEnabled:!0,...t});c<I;){switch(i=m[c],i.type){case 0:T?w(T):(T=k(),z(T));break;case 1:T=void 0,Be();break;case 3:T=void 0,ze();break;default:Me();break}c++}let n=B;return ae?.setAttributeMap&&q(n,{enter(o){o.type==="Tag"&&We(o)}}),te(),n}function le(e,t,n){let o=se(e,t);o?(o.name.value=t,o.value=n===void 0?void 0:{start:o.value?.start??o.end,end:o.value?.end??o.end,value:n,quote:o.value?.quote??'"'},o.end=o.value?.end??o.name.end):e.attributes.push(Ue(t,n)),e.attributeMap&&(e.attributeMap[t]=se(e,t))}function ue(e,t){for(let n=e.attributes.length-1;n>=0;n--)e.attributes[n].name.value===t&&e.attributes.splice(n,1);e.attributeMap&&delete e.attributeMap[t]}function V(e){return Array.isArray(e)?e.map(re).join(""):re(e)}function re(e){return e.type==="Text"?e.value:Pe(e)}function Pe(e){if(e.body===null)return oe(e,!1);if(e.name==="!--"||e.name==="!"||e.name==="")return Re(e);let t=oe(e);if(e.body===void 0)return t;let n=e.close===null?"":`</${e.rawName}>`;return t+V(e.body)+n}function Re(e){let t=e.body?V(e.body):"";return e.name==="!--"?`<!--${t}${e.close===null?"":"-->"}`:e.name==="!"?`<!${t}${e.close===null?"":">"}`:`<${t}${e.close===null?"":">"}`}function oe(e,t=!0){let n=e.attributes.map(Ge).join(" ");return`<${e.rawName}${n?` ${n}`:""}${t?">":""}`}function Ge(e){return e.value?e.value.quote===void 0?`${e.name.value}=${e.value.value}`:`${e.name.value}=${e.value.quote}${e.value.value}${e.value.quote}`:e.name.value}function se(e,t){return e.attributes.find(n=>n.name.value===t)}function Ue(e,t){return{start:0,end:0,name:{start:0,end:0,type:"Text",value:e},value:t===void 0?void 0:{start:0,end:0,value:t,quote:'"'}}}return ce(_e);})();
//# sourceMappingURL=index.umd.js.map