function r(e){return e==" "||e==` `||e=="\r"||e==" "}function m(e){return e=='"'||e=="'"}const i="<",u=">",o="<",h=">";class n{constructor(t){this.options=t}consume(t,s){return t==i?(s(new p(this.options)),""):t==u&&this.options.encodePlaintextTagDelimiters?h:t}}class p{constructor(t){this.options=t,this.nameBuffer="",this.isClosingTag=!1}consume(t,s){if(this.nameBuffer.length==0){if(r(t))return s(new n(this.options)),(this.options.encodePlaintextTagDelimiters?o:"<")+t;if(t=="/")return this.isClosingTag=!0,""}return r(t)?this.isNameBufferAnAllowedTag()?(s(new l(0,this.options)),i+(this.isClosingTag?"/":"")+this.nameBuffer+t):(s(new l(1,this.options)),this.options.tagReplacementText):t==i?(this.nameBuffer+=o,""):t==u?(s(new n(this.options)),this.isNameBufferAnAllowedTag()?i+(this.isClosingTag?"/":"")+this.nameBuffer+t:this.options.tagReplacementText):t=="-"&&this.nameBuffer=="!-"?(s(new g(this.options)),""):(this.nameBuffer+=t,"")}isNameBufferAnAllowedTag(){const t=this.nameBuffer.toLowerCase();return this.options.allowedTags?this.options.allowedTags.has(t):this.options.disallowedTags?!this.options.disallowedTags.has(t):!1}}class l{constructor(t,s){this.mode=t,this.options=s}consume(t,s){return t==u?s(new n(this.options)):m(t)&&s(new a(this.mode,t,this.options)),this.mode==1?"":t==i?o:t}}class a{constructor(t,s,f){this.mode=t,this.quoteCharacter=s,this.options=f}consume(t,s){return t==this.quoteCharacter&&s(new l(this.mode,this.options)),this.mode==1?"":t==i?o:t==u?h:t}}class g{constructor(t){this.options=t,this.consecutiveHyphens=0}consume(t,s){return t==">"&&this.consecutiveHyphens>=2?s(new n(this.options)):t=="-"?this.consecutiveHyphens++:this.consecutiveHyphens=0,""}}const T={tagReplacementText:"",encodePlaintextTagDelimiters:!0};class d{constructor(t={}){this.state=new n(Object.assign(Object.assign({},T),t)),this.transitionFunction=(s=>{this.state=s}).bind(this)}consume(t){let s="";for(const f of t)s+=this.state.consume(f,this.transitionFunction);return s}}function w(e,t={}){return new d(t).consume(e)}export{w as s};