UNPKG

@loaders.gl/xml

Version:

Framework-independent loaders for the XML (eXtensible Markup Language) format

21 lines (20 loc) 49.5 kB
(function webpackUniversalModuleDefinition(root, factory) { if (typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if (typeof define === 'function' && define.amd) define([], factory); else if (typeof exports === 'object') exports['loaders'] = factory(); else root['loaders'] = factory();})(globalThis, function () { "use strict";var __exports__=(()=>{var Nt=Object.create;var O=Object.defineProperty;var St=Object.getOwnPropertyDescriptor;var bt=Object.getOwnPropertyNames;var It=Object.getPrototypeOf,At=Object.prototype.hasOwnProperty;var yt=(s,t,e)=>t in s?O(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var xt=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports),Ft=(s,t)=>{for(var e in t)O(s,e,{get:t[e],enumerable:!0})},U=(s,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of bt(t))!At.call(s,r)&&r!==e&&O(s,r,{get:()=>t[r],enumerable:!(i=St(t,r))||i.enumerable});return s},v=(s,t,e)=>(U(s,t,"default"),e&&U(e,t,"default")),wt=(s,t,e)=>(e=s!=null?Nt(It(s)):{},U(t||!s||!s.__esModule?O(e,"default",{value:s,enumerable:!0}):e,s)),Ct=s=>U(O({},"__esModule",{value:!0}),s);var tt=(s,t,e)=>(yt(s,typeof t!="symbol"?t+"":t,e),e);var st=xt((Se,et)=>{et.exports=globalThis.loaders});var V={};Ft(V,{HTMLLoader:()=>Et,SAXParser:()=>N,XMLLoader:()=>I,_uncapitalize:()=>q,_uncapitalizeKeys:()=>x,convertXMLFieldToArrayInPlace:()=>mt,convertXMLValueToArray:()=>D});v(V,wt(st(),1));var it={ontext:()=>{},onprocessinginstruction:()=>{},onsgmldeclaration:()=>{},ondoctype:()=>{},oncomment:()=>{},onopentagstart:()=>{},onattribute:()=>{},onopentag:()=>{},onclosetag:()=>{},onopencdata:()=>{},oncdata:()=>{},onclosecdata:()=>{},onerror:()=>{},onend:()=>{},onready:()=>{},onscript:()=>{},onopennamespace:()=>{},onclosenamespace:()=>{}},Ot={...it,strict:!1,MAX_BUFFER_LENGTH:64*1024,lowercase:!1,lowercasetags:!1,noscript:!1,strictEntities:!1,xmlns:void 0,position:void 0,trim:void 0,normalize:void 0},_t=["text","processinginstruction","sgmldeclaration","doctype","comment","opentagstart","attribute","opentag","closetag","opencdata","cdata","closecdata","error","end","ready","script","opennamespace","closenamespace"],Pt=["comment","sgmlDecl","textNode","tagName","doctype","procInstName","procInstBody","entity","attribName","attribValue","cdata","script"],_=/[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/,Y=/[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040.\d-]/,Lt=/[#:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/,Mt=/[#:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040.\d-]/,P={amp:"&",gt:">",lt:"<",quot:'"',apos:"'",AElig:198,Aacute:193,Acirc:194,Agrave:192,Aring:197,Atilde:195,Auml:196,Ccedil:199,ETH:208,Eacute:201,Ecirc:202,Egrave:200,Euml:203,Iacute:205,Icirc:206,Igrave:204,Iuml:207,Ntilde:209,Oacute:211,Ocirc:212,Ograve:210,Oslash:216,Otilde:213,Ouml:214,THORN:222,Uacute:218,Ucirc:219,Ugrave:217,Uuml:220,Yacute:221,aacute:225,acirc:226,aelig:230,agrave:224,aring:229,atilde:227,auml:228,ccedil:231,eacute:233,ecirc:234,egrave:232,eth:240,euml:235,iacute:237,icirc:238,igrave:236,iuml:239,ntilde:241,oacute:243,ocirc:244,ograve:242,oslash:248,otilde:245,ouml:246,szlig:223,thorn:254,uacute:250,ucirc:251,ugrave:249,uuml:252,yacute:253,yuml:255,copy:169,reg:174,nbsp:160,iexcl:161,cent:162,pound:163,curren:164,yen:165,brvbar:166,sect:167,uml:168,ordf:170,laquo:171,not:172,shy:173,macr:175,deg:176,plusmn:177,sup1:185,sup2:178,sup3:179,acute:180,micro:181,para:182,middot:183,cedil:184,ordm:186,raquo:187,frac14:188,frac12:189,frac34:190,iquest:191,times:215,divide:247,OElig:338,oelig:339,Scaron:352,scaron:353,Yuml:376,fnof:402,circ:710,tilde:732,Alpha:913,Beta:914,Gamma:915,Delta:916,Epsilon:917,Zeta:918,Eta:919,Theta:920,Iota:921,Kappa:922,Lambda:923,Mu:924,Nu:925,Xi:926,Omicron:927,Pi:928,Rho:929,Sigma:931,Tau:932,Upsilon:933,Phi:934,Chi:935,Psi:936,Omega:937,alpha:945,beta:946,gamma:947,delta:948,epsilon:949,zeta:950,eta:951,theta:952,iota:953,kappa:954,lambda:955,mu:956,nu:957,xi:958,omicron:959,pi:960,rho:961,sigmaf:962,sigma:963,tau:964,upsilon:965,phi:966,chi:967,psi:968,omega:969,thetasym:977,upsih:978,piv:982,ensp:8194,emsp:8195,thinsp:8201,zwnj:8204,zwj:8205,lrm:8206,rlm:8207,ndash:8211,mdash:8212,lsquo:8216,rsquo:8217,sbquo:8218,ldquo:8220,rdquo:8221,bdquo:8222,dagger:8224,Dagger:8225,bull:8226,hellip:8230,permil:8240,prime:8242,Prime:8243,lsaquo:8249,rsaquo:8250,oline:8254,frasl:8260,euro:8364,image:8465,weierp:8472,real:8476,trade:8482,alefsym:8501,larr:8592,uarr:8593,rarr:8594,darr:8595,harr:8596,crarr:8629,lArr:8656,uArr:8657,rArr:8658,dArr:8659,hArr:8660,forall:8704,part:8706,exist:8707,empty:8709,nabla:8711,isin:8712,notin:8713,ni:8715,prod:8719,sum:8721,minus:8722,lowast:8727,radic:8730,prop:8733,infin:8734,ang:8736,and:8743,or:8744,cap:8745,cup:8746,int:8747,there4:8756,sim:8764,cong:8773,asymp:8776,ne:8800,equiv:8801,le:8804,ge:8805,sub:8834,sup:8835,nsub:8836,sube:8838,supe:8839,oplus:8853,otimes:8855,perp:8869,sdot:8901,lceil:8968,rceil:8969,lfloor:8970,rfloor:8971,lang:9001,rang:9002,loz:9674,spades:9824,clubs:9827,hearts:9829,diams:9830};Object.keys(P).forEach(s=>{let t=P[s];P[s]=typeof t=="number"?String.fromCharCode(t):t});var f=class{EVENTS=_t;ENTITIES={...P};XML_ENTITIES={amp:"&",gt:">",lt:"<",quot:'"',apos:"'"};S=0;opt;trackPosition=!1;column=0;line=0;c="";error;q="";bufferCheckPosition;closed=!1;tags=[];looseCase="";closedRoot=!1;sawRoot=!1;strict=!1;tag;strictEntities;state;noscript=!1;attribList=[];ns;position=0;STATE={BEGIN:this.S++,BEGIN_WHITESPACE:this.S++,TEXT:this.S++,TEXT_ENTITY:this.S++,OPEN_WAKA:this.S++,SGML_DECL:this.S++,SGML_DECL_QUOTED:this.S++,DOCTYPE:this.S++,DOCTYPE_QUOTED:this.S++,DOCTYPE_DTD:this.S++,DOCTYPE_DTD_QUOTED:this.S++,COMMENT_STARTING:this.S++,COMMENT:this.S++,COMMENT_ENDING:this.S++,COMMENT_ENDED:this.S++,CDATA:this.S++,CDATA_ENDING:this.S++,CDATA_ENDING_2:this.S++,PROC_INST:this.S++,PROC_INST_BODY:this.S++,PROC_INST_ENDING:this.S++,OPEN_TAG:this.S++,OPEN_TAG_SLASH:this.S++,ATTRIB:this.S++,ATTRIB_NAME:this.S++,ATTRIB_NAME_SAW_WHITE:this.S++,ATTRIB_VALUE:this.S++,ATTRIB_VALUE_QUOTED:this.S++,ATTRIB_VALUE_CLOSED:this.S++,ATTRIB_VALUE_UNQUOTED:this.S++,ATTRIB_VALUE_ENTITY_Q:this.S++,ATTRIB_VALUE_ENTITY_U:this.S++,CLOSE_TAG:this.S++,CLOSE_TAG_SAW_WHITE:this.S++,SCRIPT:this.S++,SCRIPT_ENDING:this.S++};BUFFERS=Pt;CDATA="[CDATA[";DOCTYPE="DOCTYPE";XML_NAMESPACE="http://www.w3.org/XML/1998/namespace";XMLNS_NAMESPACE="http://www.w3.org/2000/xmlns/";rootNS={xml:this.XML_NAMESPACE,xmlns:this.XMLNS_NAMESPACE};comment;sgmlDecl;textNode="";tagName;doctype;procInstName;procInstBody;entity="";attribName;attribValue;cdata="";script="";startTagPosition=0;constructor(){this.S=0;for(let t in this.STATE)this.STATE.hasOwnProperty(t)&&(this.STATE[this.STATE[t]]=t);this.S=this.STATE}static charAt(t,e){let i="";return e<t.length&&(i=t.charAt(e)),i}static isWhitespace(t){return t===" "||t===` `||t==="\r"||t===" "}static isQuote(t){return t==='"'||t==="'"}static isAttribEnd(t){return t===">"||f.isWhitespace(t)}static isMatch(t,e){return t.test(e)}static notMatch(t,e){return!f.isMatch(t,e)}static qname(t,e){let r=t.indexOf(":")<0?["",t]:t.split(":"),n=r[0],o=r[1];return e&&t==="xmlns"&&(n="xmlns",o=""),{prefix:n,local:o}}write(t){if(this.error)throw this.error;if(this.closed)return this.errorFunction("Cannot write after close. Assign an onready handler.");if(t===null)return this.end();typeof t=="object"&&(t=t.toString());let e=0,i;for(;i=f.charAt(t,e++),this.c=i,!!i;)switch(this.trackPosition&&(this.position++,i===` `?(this.line++,this.column=0):this.column++),this.state){case this.S.BEGIN:if(this.state=this.S.BEGIN_WHITESPACE,i==="\uFEFF")continue;this.beginWhiteSpace(i);continue;case this.S.BEGIN_WHITESPACE:this.beginWhiteSpace(i);continue;case this.S.TEXT:if(this.sawRoot&&!this.closedRoot){let o=e-1;for(;i&&i!=="<"&&i!=="&";)i=f.charAt(t,e++),i&&this.trackPosition&&(this.position++,i===` `?(this.line++,this.column=0):this.column++);this.textNode+=t.substring(o,e-1)}i==="<"&&!(this.sawRoot&&this.closedRoot&&!this.strict)?(this.state=this.S.OPEN_WAKA,this.startTagPosition=this.position):(!f.isWhitespace(i)&&(!this.sawRoot||this.closedRoot)&&this.strictFail("Text data outside of root node."),i==="&"?this.state=this.S.TEXT_ENTITY:this.textNode+=i);continue;case this.S.SCRIPT:i==="<"?this.state=this.S.SCRIPT_ENDING:this.script+=i;continue;case this.S.SCRIPT_ENDING:i==="/"?this.state=this.S.CLOSE_TAG:(this.script+=`<${i}`,this.state=this.S.SCRIPT);continue;case this.S.OPEN_WAKA:if(i==="!")this.state=this.S.SGML_DECL,this.sgmlDecl="";else if(!f.isWhitespace(i))if(f.isMatch(_,i))this.state=this.S.OPEN_TAG,this.tagName=i;else if(i==="/")this.state=this.S.CLOSE_TAG,this.tagName="";else if(i==="?")this.state=this.S.PROC_INST,this.procInstName=this.procInstBody="";else{if(this.strictFail("Unencoded <"),this.startTagPosition+1<this.position){let o=this.position-this.startTagPosition;i=new Array(o).join(" ")+i}this.textNode+=`<${i}`,this.state=this.S.TEXT}continue;case this.S.SGML_DECL:(this.sgmlDecl+i).toUpperCase()===this.CDATA?(this.emitNode("onopencdata"),this.state=this.S.CDATA,this.sgmlDecl="",this.cdata=""):this.sgmlDecl+i==="--"?(this.state=this.S.COMMENT,this.comment="",this.sgmlDecl=""):(this.sgmlDecl+i).toUpperCase()===this.DOCTYPE?(this.state=this.S.DOCTYPE,(this.doctype||this.sawRoot)&&this.strictFail("Inappropriately located doctype declaration"),this.doctype="",this.sgmlDecl=""):i===">"?(this.emitNode("onsgmldeclaration",this.sgmlDecl),this.sgmlDecl="",this.state=this.S.TEXT):f.isQuote(i)?(this.state=this.S.SGML_DECL_QUOTED,this.sgmlDecl+=i):this.sgmlDecl+=i;continue;case this.S.SGML_DECL_QUOTED:i===this.q&&(this.state=this.S.SGML_DECL,this.q=""),this.sgmlDecl+=i;continue;case this.S.DOCTYPE:i===">"?(this.state=this.S.TEXT,this.emitNode("ondoctype",this.doctype),this.doctype=!0):(this.doctype+=i,i==="["?this.state=this.S.DOCTYPE_DTD:f.isQuote(i)&&(this.state=this.S.DOCTYPE_QUOTED,this.q=i));continue;case this.S.DOCTYPE_QUOTED:this.doctype+=i,i===this.q&&(this.q="",this.state=this.S.DOCTYPE);continue;case this.S.DOCTYPE_DTD:this.doctype+=i,i==="]"?this.state=this.S.DOCTYPE:f.isQuote(i)&&(this.state=this.S.DOCTYPE_DTD_QUOTED,this.q=i);continue;case this.S.DOCTYPE_DTD_QUOTED:this.doctype+=i,i===this.q&&(this.state=this.S.DOCTYPE_DTD,this.q="");continue;case this.S.COMMENT:i==="-"?this.state=this.S.COMMENT_ENDING:this.comment+=i;continue;case this.S.COMMENT_ENDING:i==="-"?(this.state=this.S.COMMENT_ENDED,this.comment=this.textApplyOptions(this.comment),this.comment&&this.emitNode("oncomment",this.comment),this.comment=""):(this.comment+=`-${i}`,this.state=this.S.COMMENT);continue;case this.S.COMMENT_ENDED:i!==">"?(this.strictFail("Malformed comment"),this.comment+=`--${i}`,this.state=this.S.COMMENT):this.state=this.S.TEXT;continue;case this.S.CDATA:i==="]"?this.state=this.S.CDATA_ENDING:this.cdata+=i;continue;case this.S.CDATA_ENDING:i==="]"?this.state=this.S.CDATA_ENDING_2:(this.cdata+=`]${i}`,this.state=this.S.CDATA);continue;case this.S.CDATA_ENDING_2:i===">"?(this.cdata&&this.emitNode("oncdata",this.cdata),this.emitNode("onclosecdata"),this.cdata="",this.state=this.S.TEXT):i==="]"?this.cdata+="]":(this.cdata+=`]]${i}`,this.state=this.S.CDATA);continue;case this.S.PROC_INST:i==="?"?this.state=this.S.PROC_INST_ENDING:f.isWhitespace(i)?this.state=this.S.PROC_INST_BODY:this.procInstName+=i;continue;case this.S.PROC_INST_BODY:if(!this.procInstBody&&f.isWhitespace(i))continue;i==="?"?this.state=this.S.PROC_INST_ENDING:this.procInstBody+=i;continue;case this.S.PROC_INST_ENDING:i===">"?(this.emitNode("onprocessinginstruction",{name:this.procInstName,body:this.procInstBody}),this.procInstName=this.procInstBody="",this.state=this.S.TEXT):(this.procInstBody+=`?${i}`,this.state=this.S.PROC_INST_BODY);continue;case this.S.OPEN_TAG:f.isMatch(Y,i)?this.tagName+=i:(this.newTag(),i===">"?this.openTag():i==="/"?this.state=this.S.OPEN_TAG_SLASH:(f.isWhitespace(i)||this.strictFail("Invalid character in tag name"),this.state=this.S.ATTRIB));continue;case this.S.OPEN_TAG_SLASH:i===">"?(this.openTag(!0),this.closeTag()):(this.strictFail("Forward-slash in opening tag not followed by >"),this.state=this.S.ATTRIB);continue;case this.S.ATTRIB:if(f.isWhitespace(i))continue;i===">"?this.openTag():i==="/"?this.state=this.S.OPEN_TAG_SLASH:f.isMatch(_,i)?(this.attribName=i,this.attribValue="",this.state=this.S.ATTRIB_NAME):this.strictFail("Invalid attribute name");continue;case this.S.ATTRIB_NAME:i==="="?this.state=this.S.ATTRIB_VALUE:i===">"?(this.strictFail("Attribute without value"),this.attribValue=this.attribName,this.attrib(),this.openTag()):f.isWhitespace(i)?this.state=this.S.ATTRIB_NAME_SAW_WHITE:f.isMatch(Y,i)?this.attribName+=i:this.strictFail("Invalid attribute name");continue;case this.S.ATTRIB_NAME_SAW_WHITE:if(i==="=")this.state=this.S.ATTRIB_VALUE;else{if(f.isWhitespace(i))continue;this.strictFail("Attribute without value"),this.tag.attributes[this.attribName]="",this.attribValue="",this.emitNode("onattribute",{name:this.attribName,value:""}),this.attribName="",i===">"?this.openTag():f.isMatch(_,i)?(this.attribName=i,this.state=this.S.ATTRIB_NAME):(this.strictFail("Invalid attribute name"),this.state=this.S.ATTRIB)}continue;case this.S.ATTRIB_VALUE:if(f.isWhitespace(i))continue;f.isQuote(i)?(this.q=i,this.state=this.S.ATTRIB_VALUE_QUOTED):(this.strictFail("Unquoted attribute value"),this.state=this.S.ATTRIB_VALUE_UNQUOTED,this.attribValue=i);continue;case this.S.ATTRIB_VALUE_QUOTED:if(i!==this.q){i==="&"?this.state=this.S.ATTRIB_VALUE_ENTITY_Q:this.attribValue+=i;continue}this.attrib(),this.q="",this.state=this.S.ATTRIB_VALUE_CLOSED;continue;case this.S.ATTRIB_VALUE_CLOSED:f.isWhitespace(i)?this.state=this.S.ATTRIB:i===">"?this.openTag():i==="/"?this.state=this.S.OPEN_TAG_SLASH:f.isMatch(_,i)?(this.strictFail("No whitespace between attributes"),this.attribName=i,this.attribValue="",this.state=this.S.ATTRIB_NAME):this.strictFail("Invalid attribute name");continue;case this.S.ATTRIB_VALUE_UNQUOTED:if(!f.isAttribEnd(i)){i==="&"?this.state=this.S.ATTRIB_VALUE_ENTITY_U:this.attribValue+=i;continue}this.attrib(),i===">"?this.openTag():this.state=this.S.ATTRIB;continue;case this.S.CLOSE_TAG:if(this.tagName)i===">"?this.closeTag():f.isMatch(Y,i)?this.tagName+=i:this.script?(this.script+=`</${this.tagName}`,this.tagName="",this.state=this.S.SCRIPT):(f.isWhitespace(i)||this.strictFail("Invalid tagname in closing tag"),this.state=this.S.CLOSE_TAG_SAW_WHITE);else{if(f.isWhitespace(i))continue;f.notMatch(_,i)?this.script?(this.script+=`</${i}`,this.state=this.S.SCRIPT):this.strictFail("Invalid tagname in closing tag."):this.tagName=i}continue;case this.S.CLOSE_TAG_SAW_WHITE:if(f.isWhitespace(i))continue;i===">"?this.closeTag():this.strictFail("Invalid characters in closing tag");continue;case this.S.TEXT_ENTITY:case this.S.ATTRIB_VALUE_ENTITY_Q:case this.S.ATTRIB_VALUE_ENTITY_U:let r,n;switch(this.state){case this.S.TEXT_ENTITY:r=this.S.TEXT,n="textNode";break;case this.S.ATTRIB_VALUE_ENTITY_Q:r=this.S.ATTRIB_VALUE_QUOTED,n="attribValue";break;case this.S.ATTRIB_VALUE_ENTITY_U:r=this.S.ATTRIB_VALUE_UNQUOTED,n="attribValue";break;default:throw new Error(`Unknown state: ${this.state}`)}i===";"?(this[n]+=this.parseEntity(),this.entity="",this.state=r):f.isMatch(this.entity.length?Mt:Lt,i)?this.entity+=i:(this.strictFail("Invalid character in entity name"),this[n]+=`&${this.entity}${i}`,this.entity="",this.state=r);continue;default:throw new Error(`Unknown state: ${this.state}`)}return this.position>=this.bufferCheckPosition&&this.checkBufferLength(),this}emit(t,e){if(this.events.hasOwnProperty(t)){let i=t.replace(/^on/,"");this.events[t](e,i,this)}}clearBuffers(){for(let t=0,e=this.BUFFERS.length;t<e;t++)this[this[t]]=""}flushBuffers(){this.closeText(),this.cdata!==""&&(this.emitNode("oncdata",this.cdata),this.cdata=""),this.script!==""&&(this.emitNode("onscript",this.script),this.script="")}end(){return this.sawRoot&&!this.closedRoot&&this.strictFail("Unclosed root tag"),this.state!==this.S.BEGIN&&this.state!==this.S.BEGIN_WHITESPACE&&this.state!==this.S.TEXT&&this.errorFunction("Unexpected end"),this.closeText(),this.c="",this.closed=!0,this.emit("onend"),new N(this.opt)}errorFunction(t){this.closeText(),this.trackPosition&&(t+=` Line: ${this.line} Column: ${this.column} Char: ${this.c}`);let e=new Error(t);return this.error=e,this.emit("onerror",e),this}attrib(){if(this.strict||(this.attribName=this.attribName[this.looseCase]()),this.attribList.indexOf(this.attribName)!==-1||this.tag.attributes.hasOwnProperty(this.attribName)){this.attribName=this.attribValue="";return}if(this.opt.xmlns){let t=f.qname(this.attribName,!0),e=t.prefix,i=t.local;if(e==="xmlns")if(i==="xml"&&this.attribValue!==this.XML_NAMESPACE)this.strictFail(`xml: prefix must be bound to ${this.XML_NAMESPACE} Actual: ${this.attribValue}`);else if(i==="xmlns"&&this.attribValue!==this.XMLNS_NAMESPACE)this.strictFail(`xmlns: prefix must be bound to ${this.XMLNS_NAMESPACE} Actual: ${this.attribValue}`);else{let r=this.tag,n=this.tags[this.tags.length-1]||this;r.ns===n.ns&&(r.ns=Object.create(n.ns)),r.ns[i]=this.attribValue}this.attribList.push([this.attribName,this.attribValue])}else this.tag.attributes[this.attribName]=this.attribValue,this.emitNode("onattribute",{name:this.attribName,value:this.attribValue});this.attribName=this.attribValue=""}newTag(){this.strict||(this.tagName=this.tagName[this.looseCase]());let t=this.tags[this.tags.length-1]||this,e=this.tag={name:this.tagName,attributes:{}};this.opt.xmlns&&(e.ns=t.ns),this.attribList.length=0,this.emitNode("onopentagstart",e)}parseEntity(){let t=this.entity,e=t.toLowerCase(),i=NaN,r="";return this.ENTITIES[t]?this.ENTITIES[t]:this.ENTITIES[e]?this.ENTITIES[e]:(t=e,t.charAt(0)==="#"&&(t.charAt(1)==="x"?(t=t.slice(2),i=parseInt(t,16),r=i.toString(16)):(t=t.slice(1),i=parseInt(t,10),r=i.toString(10))),t=t.replace(/^0+/,""),isNaN(i)||r.toLowerCase()!==t?(this.strictFail("Invalid character entity"),`&${this.entity};`):String.fromCodePoint(i))}beginWhiteSpace(t){t==="<"?(this.state=this.S.OPEN_WAKA,this.startTagPosition=this.position):f.isWhitespace(t)||(this.strictFail("Non-whitespace before first tag."),this.textNode=t,this.state=this.S.TEXT)}strictFail(t){if(typeof this!="object"||!(this instanceof N))throw new Error("bad call to strictFail");this.strict&&this.errorFunction(t)}textApplyOptions(t){return this.opt.trim&&(t=t.trim()),this.opt.normalize&&(t=t.replace(/\s+/g," ")),t}emitNode(t,e){this.textNode&&this.closeText(),this.emit(t,e)}closeText(){this.textNode=this.textApplyOptions(this.textNode),this.textNode!==void 0&&this.textNode!==""&&this.textNode!=="undefined"&&this.emit("ontext",this.textNode),this.textNode=""}checkBufferLength(){let t=Math.max(this.opt.MAX_BUFFER_LENGTH,10),e=0;for(let r=0,n=this.BUFFERS.length;r<n;r++){let o=this[this.BUFFERS[r]]?.length||0;if(o>t)switch(this.BUFFERS[r]){case"textNode":this.closeText();break;case"cdata":this.emitNode("oncdata",this.cdata),this.cdata="";break;case"script":this.emitNode("onscript",this.script),this.script="";break;default:this.errorFunction(`Max buffer length exceeded: ${this.BUFFERS[r]}`)}e=Math.max(e,o)}let i=this.opt.MAX_BUFFER_LENGTH-e;this.bufferCheckPosition=i+this.position}openTag(t){if(this.opt.xmlns){let e=this.tag,i=f.qname(this.tagName);e.prefix=i.prefix,e.local=i.local,e.uri=e.ns[i.prefix]||"",e.prefix&&!e.uri&&(this.strictFail(`Unbound namespace prefix: ${JSON.stringify(this.tagName)}`),e.uri=i.prefix);let r=this.tags[this.tags.length-1]||this;if(e.ns&&r.ns!==e.ns){let n=this;Object.keys(e.ns).forEach(o=>{n.emitNode("onopennamespace",{prefix:o,uri:e.ns[o]})})}for(let n=0,o=this.attribList.length;n<o;n++){let l=this.attribList[n],a=l[0],h=l[1],u=f.qname(a,!0),c=u.prefix,d=u.local,C=c===""?"":e.ns[c]||"",A={name:a,value:h,prefix:c,local:d,uri:C};c&&c!=="xmlns"&&!C&&(this.strictFail(`Unbound namespace prefix: ${JSON.stringify(c)}`),A.uri=c),this.tag.attributes[a]=A,this.emitNode("onattribute",A)}this.attribList.length=0}this.tag.isSelfClosing=Boolean(t),this.sawRoot=!0,this.tags.push(this.tag),this.emitNode("onopentag",this.tag),t||(!this.noscript&&this.tagName.toLowerCase()==="script"?this.state=this.S.SCRIPT:this.state=this.S.TEXT,this.tag=null,this.tagName=""),this.attribName=this.attribValue="",this.attribList.length=0}closeTag(){if(!this.tagName){this.strictFail("Weird empty close tag."),this.textNode+="</>",this.state=this.S.TEXT;return}if(this.script){if(this.tagName!=="script"){this.script+=`</${this.tagName}>`,this.tagName="",this.state=this.S.SCRIPT;return}this.emitNode("onscript",this.script),this.script=""}let t=this.tags.length,e=this.tagName;for(this.strict||(e=e[this.looseCase]());t--&&this.tags[t].name!==e;)this.strictFail("Unexpected close tag");if(t<0){this.strictFail(`Unmatched closing tag: ${this.tagName}`),this.textNode+=`</${this.tagName}>`,this.state=this.S.TEXT;return}this.tagName=e;let i=this.tags.length;for(;i-- >t;){let r=this.tag=this.tags.pop();this.tagName=this.tag.name,this.emitNode("onclosetag",this.tagName);let n={};for(let l in r.ns)r.ns.hasOwnProperty(l)&&(n[l]=r.ns[l]);let o=this.tags[this.tags.length-1]||this;if(this.opt.xmlns&&r.ns!==o.ns){let l=this;Object.keys(r.ns).forEach(a=>{let h=r.ns[a];l.emitNode("onclosenamespace",{prefix:a,uri:h})})}}t===0&&(this.closedRoot=!0),this.tagName=this.attribValue=this.attribName="",this.attribList.length=0,this.state=this.S.TEXT}},N=class extends f{opt=Ot;events=it;constructor(t){super(),this.clearBuffers(),this.opt=t={...this.opt,...t},this.events={...this.events,...t},this.q=this.c="",this.opt.lowercase=this.opt.lowercase||this.opt.lowercasetags,this.bufferCheckPosition=this.opt.MAX_BUFFER_LENGTH,this.looseCase=this.opt.lowercase?"toLowerCase":"toUpperCase",this.tags=[],this.closed=this.closedRoot=this.sawRoot=!1,this.tag=this.error=null,this.strict=Boolean(this.opt.strict),this.noscript=Boolean(this.opt.strict||this.opt.noscript),this.state=this.S.BEGIN,this.strictEntities=this.opt.strictEntities,this.ENTITIES=this.strictEntities?Object.create(this.XML_ENTITIES):Object.create(this.ENTITIES),this.attribList=[],this.opt.xmlns&&(this.ns=Object.create(this.rootNS)),this.trackPosition=this.opt.position!==!1,this.trackPosition&&(this.position=this.line=this.column=0),this.emit("onready")}resume(){return this.error=null,this}close(){return this.write(null)}flush(){this.flushBuffers()}};tt(N,"ENTITIES",P);function q(s){return typeof s=="string"?s.charAt(0).toLowerCase()+s.slice(1):s}function x(s){if(Array.isArray(s))return s.map(t=>x(t));if(s&&typeof s=="object"){let t={};for(let[e,i]of Object.entries(s))t[q(e)]=x(i);return t}return s}var rt=":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD",Bt=rt+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040",Rt="["+rt+"]["+Bt+"]*",Vt=new RegExp("^"+Rt+"$");function k(s,t){let e=[],i=t.exec(s);for(;i;){let r=[];r.startIndex=t.lastIndex-i[0].length;let n=i.length;for(let o=0;o<n;o++)r.push(i[o]);e.push(r),i=t.exec(s)}return e}var F=function(s){let t=Vt.exec(s);return!(t===null||typeof t>"u")};function nt(s){return typeof s<"u"}var Ut={allowBooleanAttributes:!1,unpairedTags:[]};function ct(s,t){t=Object.assign({},Ut,t);let e=[],i=!1,r=!1;s[0]==="\uFEFF"&&(s=s.substr(1));for(let n=0;n<s.length;n++)if(s[n]==="<"&&s[n+1]==="?"){if(n+=2,n=at(s,n),n.err)return n}else if(s[n]==="<"){let o=n;if(n++,s[n]==="!"){n=ht(s,n);continue}else{let l=!1;s[n]==="/"&&(l=!0,n++);let a="";for(;n<s.length&&s[n]!==">"&&s[n]!==" "&&s[n]!==" "&&s[n]!==` `&&s[n]!=="\r";n++)a+=s[n];if(a=a.trim(),a[a.length-1]==="/"&&(a=a.substring(0,a.length-1),n--),!Xt(a)){let c;return a.trim().length===0?c="Invalid space after '<'.":c="Tag '"+a+"' is an invalid name.",p("InvalidTag",c,T(s,n))}let h=Wt(s,n);if(h===!1)return p("InvalidAttr","Attributes for '"+a+"' have open quote.",T(s,n));let u=h.value;if(n=h.index,u[u.length-1]==="/"){let c=n-u.length;u=u.substring(0,u.length-1);let d=lt(u,t);if(d===!0)i=!0;else return p(d.err.code,d.err.msg,T(s,c+d.err.line))}else if(l)if(h.tagClosed){if(u.trim().length>0)return p("InvalidTag","Closing tag '"+a+"' can't have attributes or invalid starting.",T(s,o));if(e.length===0)return p("InvalidTag","Closing tag '"+a+"' has not been opened.",T(s,o));{let c=e.pop();if(a!==c.tagName){let d=T(s,c.tagStartPos);return p("InvalidTag","Expected closing tag '"+c.tagName+"' (opened in line "+d.line+", col "+d.col+") instead of closing tag '"+a+"'.",T(s,o))}e.length==0&&(r=!0)}}else return p("InvalidTag","Closing tag '"+a+"' doesn't have proper closing.",T(s,n));else{let c=lt(u,t);if(c!==!0)return p(c.err.code,c.err.msg,T(s,n-u.length+c.err.line));if(r===!0)return p("InvalidXml","Multiple possible root nodes found.",T(s,n));t.unpairedTags.indexOf(a)!==-1||e.push({tagName:a,tagStartPos:o}),i=!0}for(n++;n<s.length;n++)if(s[n]==="<")if(s[n+1]==="!"){n++,n=ht(s,n);continue}else if(s[n+1]==="?"){if(n=at(s,++n),n.err)return n}else break;else if(s[n]==="&"){let c=Yt(s,n);if(c==-1)return p("InvalidChar","char '&' is not expected.",T(s,n));n=c}else if(r===!0&&!ot(s[n]))return p("InvalidXml","Extra text at the end",T(s,n));s[n]==="<"&&n--}}else{if(ot(s[n]))continue;return p("InvalidChar","char '"+s[n]+"' is not expected.",T(s,n))}if(i){if(e.length==1)return p("InvalidTag","Unclosed tag '"+e[0].tagName+"'.",T(s,e[0].tagStartPos));if(e.length>0)return p("InvalidXml","Invalid '"+JSON.stringify(e.map(n=>n.tagName),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1})}else return p("InvalidXml","Start tag expected.",1);return!0}function ot(s){return s===" "||s===" "||s===` `||s==="\r"}function at(s,t){let e=t;for(;t<s.length;t++)if(s[t]=="?"||s[t]==" "){let i=s.substr(e,t-e);if(t>5&&i==="xml")return p("InvalidXml","XML declaration allowed only at the start of the document.",T(s,t));if(s[t]=="?"&&s[t+1]==">"){t++;break}else continue}return t}function ht(s,t){if(s.length>t+5&&s[t+1]==="-"&&s[t+2]==="-"){for(t+=3;t<s.length;t++)if(s[t]==="-"&&s[t+1]==="-"&&s[t+2]===">"){t+=2;break}}else if(s.length>t+8&&s[t+1]==="D"&&s[t+2]==="O"&&s[t+3]==="C"&&s[t+4]==="T"&&s[t+5]==="Y"&&s[t+6]==="P"&&s[t+7]==="E"){let e=1;for(t+=8;t<s.length;t++)if(s[t]==="<")e++;else if(s[t]===">"&&(e--,e===0))break}else if(s.length>t+9&&s[t+1]==="["&&s[t+2]==="C"&&s[t+3]==="D"&&s[t+4]==="A"&&s[t+5]==="T"&&s[t+6]==="A"&&s[t+7]==="["){for(t+=8;t<s.length;t++)if(s[t]==="]"&&s[t+1]==="]"&&s[t+2]===">"){t+=2;break}}return t}var vt='"',kt="'";function Wt(s,t){let e="",i="",r=!1;for(;t<s.length;t++){if(s[t]===vt||s[t]===kt)i===""?i=s[t]:i!==s[t]||(i="");else if(s[t]===">"&&i===""){r=!0;break}e+=s[t]}return i!==""?!1:{value:e,index:t,tagClosed:r}}var $t=new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`,"g");function lt(s,t){let e=k(s,$t),i={};for(let r=0;r<e.length;r++){if(e[r][1].length===0)return p("InvalidAttr","Attribute '"+e[r][2]+"' has no space in starting.",L(e[r]));if(e[r][3]!==void 0&&e[r][4]===void 0)return p("InvalidAttr","Attribute '"+e[r][2]+"' is without value.",L(e[r]));if(e[r][3]===void 0&&!t.allowBooleanAttributes)return p("InvalidAttr","boolean attribute '"+e[r][2]+"' is not allowed.",L(e[r]));let n=e[r][2];if(!qt(n))return p("InvalidAttr","Attribute '"+n+"' is an invalid name.",L(e[r]));if(!i.hasOwnProperty(n))i[n]=1;else return p("InvalidAttr","Attribute '"+n+"' is repeated.",L(e[r]))}return!0}function Gt(s,t){let e=/\d/;for(s[t]==="x"&&(t++,e=/[\da-fA-F]/);t<s.length;t++){if(s[t]===";")return t;if(!s[t].match(e))break}return-1}function Yt(s,t){if(t++,s[t]===";")return-1;if(s[t]==="#")return t++,Gt(s,t);let e=0;for(;t<s.length;t++,e++)if(!(s[t].match(/\w/)&&e<20)){if(s[t]===";")break;return-1}return t}function p(s,t,e){return{err:{code:s,msg:t,line:e.line||e,col:e.col}}}function qt(s){return F(s)}function Xt(s){return F(s)}function T(s,t){let e=s.substring(0,t).split(/\r?\n/);return{line:e.length,col:e[e.length-1].length+1}}function L(s){return s.startIndex+s[1].length}var jt={preserveOrder:!1,attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,removeNSPrefix:!1,allowBooleanAttributes:!1,parseTagValue:!0,parseAttributeValue:!1,trimValues:!0,cdataPropName:!1,numberParseOptions:{hex:!0,leadingZeros:!0,eNotation:!0},tagValueProcessor:function(s,t){return t},attributeValueProcessor:function(s,t){return t},stopNodes:[],alwaysCreateTextNode:!1,isArray:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(s,t,e){return s},captureMetaData:!1};function ut(s){return typeof s=="boolean"?{enabled:s,maxEntitySize:1e4,maxExpansionDepth:10,maxTotalExpansions:1e3,maxExpandedLength:1e5,allowedTags:null,tagFilter:null}:typeof s=="object"&&s!==null?{enabled:s.enabled!==!1,maxEntitySize:s.maxEntitySize??1e4,maxExpansionDepth:s.maxExpansionDepth??10,maxTotalExpansions:s.maxTotalExpansions??1e3,maxExpandedLength:s.maxExpandedLength??1e5,allowedTags:s.allowedTags??null,tagFilter:s.tagFilter??null}:ut(!0)}var ft=function(s){let t=Object.assign({},jt,s);return t.processEntities=ut(t.processEntities),t};var W;typeof Symbol!="function"?W="@@xmlMetadata":W=Symbol("XML Node Metadata");var m=class{constructor(t){this.tagname=t,this.child=[],this[":@"]={}}add(t,e){t==="__proto__"&&(t="#__proto__"),this.child.push({[t]:e})}addChild(t,e){t.tagname==="__proto__"&&(t.tagname="#__proto__"),t[":@"]&&Object.keys(t[":@"]).length>0?this.child.push({[t.tagname]:t.child,[":@"]:t[":@"]}):this.child.push({[t.tagname]:t.child}),e!==void 0&&(this.child[this.child.length-1][W]={startIndex:e})}static getMetaDataSymbol(){return W}};var B=class{constructor(t){this.suppressValidationErr=!t,this.options=t}readDocType(t,e){let i={};if(t[e+3]==="O"&&t[e+4]==="C"&&t[e+5]==="T"&&t[e+6]==="Y"&&t[e+7]==="P"&&t[e+8]==="E"){e=e+9;let r=1,n=!1,o=!1,l="";for(;e<t.length;e++)if(t[e]==="<"&&!o){if(n&&S(t,"!ENTITY",e)){e+=7;let a,h;if([a,h,e]=this.readEntityExp(t,e+1,this.suppressValidationErr),h.indexOf("&")===-1){let u=a.replace(/[.\-+*:]/g,"\\.");i[a]={regx:RegExp(`&${u};`,"g"),val:h}}}else if(n&&S(t,"!ELEMENT",e)){e+=8;let{index:a}=this.readElementExp(t,e+1);e=a}else if(n&&S(t,"!ATTLIST",e))e+=8;else if(n&&S(t,"!NOTATION",e)){e+=9;let{index:a}=this.readNotationExp(t,e+1,this.suppressValidationErr);e=a}else if(S(t,"!--",e))o=!0;else throw new Error("Invalid DOCTYPE");r++,l=""}else if(t[e]===">"){if(o?t[e-1]==="-"&&t[e-2]==="-"&&(o=!1,r--):r--,r===0)break}else t[e]==="["?n=!0:l+=t[e];if(r!==0)throw new Error("Unclosed DOCTYPE")}else throw new Error("Invalid Tag instead of DOCTYPE");return{entities:i,i:e}}readEntityExp(t,e){e=E(t,e);let i="";for(;e<t.length&&!/\s/.test(t[e])&&t[e]!=='"'&&t[e]!=="'";)i+=t[e],e++;if(M(i),e=E(t,e),!this.suppressValidationErr){if(t.substring(e,e+6).toUpperCase()==="SYSTEM")throw new Error("External entities are not supported");if(t[e]==="%")throw new Error("Parameter entities are not supported")}let r="";if([e,r]=this.readIdentifierVal(t,e,"entity"),this.options.enabled!==!1&&this.options.maxEntitySize&&r.length>this.options.maxEntitySize)throw new Error(`Entity "${i}" size (${r.length}) exceeds maximum allowed size (${this.options.maxEntitySize})`);return e--,[i,r,e]}readNotationExp(t,e){e=E(t,e);let i="";for(;e<t.length&&!/\s/.test(t[e]);)i+=t[e],e++;!this.suppressValidationErr&&M(i),e=E(t,e);let r=t.substring(e,e+6).toUpperCase();if(!this.suppressValidationErr&&r!=="SYSTEM"&&r!=="PUBLIC")throw new Error(`Expected SYSTEM or PUBLIC, found "${r}"`);e+=r.length,e=E(t,e);let n=null,o=null;if(r==="PUBLIC")[e,n]=this.readIdentifierVal(t,e,"publicIdentifier"),e=E(t,e),(t[e]==='"'||t[e]==="'")&&([e,o]=this.readIdentifierVal(t,e,"systemIdentifier"));else if(r==="SYSTEM"&&([e,o]=this.readIdentifierVal(t,e,"systemIdentifier"),!this.suppressValidationErr&&!o))throw new Error("Missing mandatory system identifier for SYSTEM notation");return{notationName:i,publicIdentifier:n,systemIdentifier:o,index:--e}}readIdentifierVal(t,e,i){let r="",n=t[e];if(n!=='"'&&n!=="'")throw new Error(`Expected quoted string, found "${n}"`);for(e++;e<t.length&&t[e]!==n;)r+=t[e],e++;if(t[e]!==n)throw new Error(`Unterminated ${i} value`);return e++,[e,r]}readElementExp(t,e){e=E(t,e);let i="";for(;e<t.length&&!/\s/.test(t[e]);)i+=t[e],e++;if(!this.suppressValidationErr&&!F(i))throw new Error(`Invalid element name: "${i}"`);e=E(t,e);let r="";if(t[e]==="E"&&S(t,"MPTY",e))e+=4;else if(t[e]==="A"&&S(t,"NY",e))e+=2;else if(t[e]==="("){for(e++;e<t.length&&t[e]!==")";)r+=t[e],e++;if(t[e]!==")")throw new Error("Unterminated content model")}else if(!this.suppressValidationErr)throw new Error(`Invalid Element Expression, found "${t[e]}"`);return{elementName:i,contentModel:r.trim(),index:e}}readAttlistExp(t,e){e=E(t,e);let i="";for(;e<t.length&&!/\s/.test(t[e]);)i+=t[e],e++;M(i),e=E(t,e);let r="";for(;e<t.length&&!/\s/.test(t[e]);)r+=t[e],e++;if(!M(r))throw new Error(`Invalid attribute name: "${r}"`);e=E(t,e);let n="";if(t.substring(e,e+8).toUpperCase()==="NOTATION"){if(n="NOTATION",e+=8,e=E(t,e),t[e]!=="(")throw new Error(`Expected '(', found "${t[e]}"`);e++;let l=[];for(;e<t.length&&t[e]!==")";){let a="";for(;e<t.length&&t[e]!=="|"&&t[e]!==")";)a+=t[e],e++;if(a=a.trim(),!M(a))throw new Error(`Invalid notation name: "${a}"`);l.push(a),t[e]==="|"&&(e++,e=E(t,e))}if(t[e]!==")")throw new Error("Unterminated list of notations");e++,n+=" ("+l.join("|")+")"}else{for(;e<t.length&&!/\s/.test(t[e]);)n+=t[e],e++;let l=["CDATA","ID","IDREF","IDREFS","ENTITY","ENTITIES","NMTOKEN","NMTOKENS"];if(!this.suppressValidationErr&&!l.includes(n.toUpperCase()))throw new Error(`Invalid attribute type: "${n}"`)}e=E(t,e);let o="";return t.substring(e,e+8).toUpperCase()==="#REQUIRED"?(o="#REQUIRED",e+=8):t.substring(e,e+7).toUpperCase()==="#IMPLIED"?(o="#IMPLIED",e+=7):[e,o]=this.readIdentifierVal(t,e,"ATTLIST"),{elementName:i,attributeName:r,attributeType:n,defaultValue:o,index:e}}},E=(s,t)=>{for(;t<s.length&&/\s/.test(s[t]);)t++;return t};function S(s,t,e){for(let i=0;i<t.length;i++)if(t[i]!==s[e+i+1])return!1;return!0}function M(s){if(F(s))return s;throw new Error(`Invalid entity name ${s}`)}var zt=/^[-+]?0x[a-fA-F0-9]+$/,Qt=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,Ht={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};function X(s,t={}){if(t=Object.assign({},Ht,t),!s||typeof s!="string")return s;let e=s.trim();if(t.skipLike!==void 0&&t.skipLike.test(e))return s;if(s==="0")return 0;if(t.hex&&zt.test(e))return Dt(e,16);if(e.includes("e")||e.includes("E"))return Kt(s,e,t);{let i=Qt.exec(e);if(i){let r=i[1]||"",n=i[2],o=Jt(i[3]),l=r?s[n.length+1]===".":s[n.length]===".";if(!t.leadingZeros&&(n.length>1||n.length===1&&!l))return s;{let a=Number(e),h=String(a);if(a===0)return a;if(h.search(/[eE]/)!==-1)return t.eNotation?a:s;if(e.indexOf(".")!==-1)return h==="0"||h===o||h===`${r}${o}`?a:s;let u=n?o:e;return n?u===h||r+u===h?a:s:u===h||u===r+h?a:s}}else return s}}var Zt=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;function Kt(s,t,e){if(!e.eNotation)return s;let i=t.match(Zt);if(i){let r=i[1]||"",n=i[3].indexOf("e")===-1?"E":"e",o=i[2],l=r?s[o.length+1]===n:s[o.length]===n;return o.length>1&&l?s:o.length===1&&(i[3].startsWith(`.${n}`)||i[3][0]===n)?Number(t):e.leadingZeros&&!l?(t=(i[1]||"")+i[3],Number(t)):s}else return s}function Jt(s){return s&&s.indexOf(".")!==-1&&(s=s.replace(/0+$/,""),s==="."?s="0":s[0]==="."?s="0"+s:s[s.length-1]==="."&&(s=s.substring(0,s.length-1))),s}function Dt(s,t){if(parseInt)return parseInt(s,t);if(Number.parseInt)return Number.parseInt(s,t);if(window&&window.parseInt)return window.parseInt(s,t);throw new Error("parseInt, Number.parseInt, window.parseInt are not supported")}function j(s){return typeof s=="function"?s:Array.isArray(s)?t=>{for(let e of s)if(typeof e=="string"&&t===e||e instanceof RegExp&&e.test(t))return!0}:()=>!1}var R=class{constructor(t){if(this.options=t,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:"'"},gt:{regex:/&(gt|#62|#x3E);/g,val:">"},lt:{regex:/&(lt|#60|#x3C);/g,val:"<"},quot:{regex:/&(quot|#34|#x22);/g,val:'"'}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:"&"},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:" "},cent:{regex:/&(cent|#162);/g,val:"\xA2"},pound:{regex:/&(pound|#163);/g,val:"\xA3"},yen:{regex:/&(yen|#165);/g,val:"\xA5"},euro:{regex:/&(euro|#8364);/g,val:"\u20AC"},copyright:{regex:/&(copy|#169);/g,val:"\xA9"},reg:{regex:/&(reg|#174);/g,val:"\xAE"},inr:{regex:/&(inr|#8377);/g,val:"\u20B9"},num_dec:{regex:/&#([0-9]{1,7});/g,val:(e,i)=>pt(i,10,"&#")},num_hex:{regex:/&#x([0-9a-fA-F]{1,6});/g,val:(e,i)=>pt(i,16,"&#x")}},this.addExternalEntities=te,this.parseXml=ne,this.parseTextData=ee,this.resolveNameSpace=se,this.buildAttributesMap=re,this.isItStopNode=le,this.replaceEntitiesValue=ae,this.readStopNodeData=ue,this.saveTextToParentTag=he,this.addChild=oe,this.ignoreAttributesFn=j(this.options.ignoreAttributes),this.entityExpansionCount=0,this.currentExpandedLength=0,this.options.stopNodes&&this.options.stopNodes.length>0){this.stopNodesExact=new Set,this.stopNodesWildcard=new Set;for(let e=0;e<this.options.stopNodes.length;e++){let i=this.options.stopNodes[e];typeof i=="string"&&(i.startsWith("*.")?this.stopNodesWildcard.add(i.substring(2)):this.stopNodesExact.add(i))}}}};function te(s){let t=Object.keys(s);for(let e=0;e<t.length;e++){let i=t[e],r=i.replace(/[.\-+*:]/g,"\\.");this.lastEntities[i]={regex:new RegExp("&"+r+";","g"),val:s[i]}}}function ee(s,t,e,i,r,n,o){if(s!==void 0&&(this.options.trimValues&&!i&&(s=s.trim()),s.length>0)){o||(s=this.replaceEntitiesValue(s,t,e));let l=this.options.tagValueProcessor(t,s,e,r,n);return l==null?s:typeof l!=typeof s||l!==s?l:this.options.trimValues?Q(s,this.options.parseTagValue,this.options.numberParseOptions):s.trim()===s?Q(s,this.options.parseTagValue,this.options.numberParseOptions):s}}function se(s){if(this.options.removeNSPrefix){let t=s.split(":"),e=s.charAt(0)==="/"?"/":"";if(t[0]==="xmlns")return"";t.length===2&&(s=e+t[1])}return s}var ie=new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`,"gm");function re(s,t,e){if(this.options.ignoreAttributes!==!0&&typeof s=="string"){let i=k(s,ie),r=i.length,n={};for(let o=0;o<r;o++){let l=this.resolveNameSpace(i[o][1]);if(this.ignoreAttributesFn(l,t))continue;let a=i[o][4],h=this.options.attributeNamePrefix+l;if(l.length)if(this.options.transformAttributeName&&(h=this.options.transformAttributeName(h)),h==="__proto__"&&(h="#__proto__"),a!==void 0){this.options.trimValues&&(a=a.trim()),a=this.replaceEntitiesValue(a,e,t);let u=this.options.attributeValueProcessor(l,a,t);u==null?n[h]=a:typeof u!=typeof a||u!==a?n[h]=u:n[h]=Q(a,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(n[h]=!0)}if(!Object.keys(n).length)return;if(this.options.attributesGroupName){let o={};return o[this.options.attributesGroupName]=n,o}return n}}var ne=function(s){s=s.replace(/\r\n?/g,` `);let t=new m("!xml"),e=t,i="",r="";this.entityExpansionCount=0,this.currentExpandedLength=0;let n=new B(this.options.processEntities);for(let o=0;o<s.length;o++)if(s[o]==="<")if(s[o+1]==="/"){let a=b(s,">",o,"Closing Tag is not closed."),h=s.substring(o+2,a).trim();if(this.options.removeNSPrefix){let d=h.indexOf(":");d!==-1&&(h=h.substr(d+1))}this.options.transformTagName&&(h=this.options.transformTagName(h)),e&&(i=this.saveTextToParentTag(i,e,r));let u=r.substring(r.lastIndexOf(".")+1);if(h&&this.options.unpairedTags.indexOf(h)!==-1)throw new Error(`Unpaired tag can not be used as closing tag: </${h}>`);let c=0;u&&this.options.unpairedTags.indexOf(u)!==-1?(c=r.lastIndexOf(".",r.lastIndexOf(".")-1),this.tagsNodeStack.pop()):c=r.lastIndexOf("."),r=r.substring(0,c),e=this.tagsNodeStack.pop(),i="",o=a}else if(s[o+1]==="?"){let a=z(s,o,!1,"?>");if(!a)throw new Error("Pi Tag is not closed.");if(i=this.saveTextToParentTag(i,e,r),!(this.options.ignoreDeclaration&&a.tagName==="?xml"||this.options.ignorePiTags)){let h=new m(a.tagName);h.add(this.options.textNodeName,""),a.tagName!==a.tagExp&&a.attrExpPresent&&(h[":@"]=this.buildAttributesMap(a.tagExp,r,a.tagName)),this.addChild(e,h,r,o)}o=a.closeIndex+1}else if(s.substr(o+1,3)==="!--"){let a=b(s,"-->",o+4,"Comment is not closed.");if(this.options.commentPropName){let h=s.substring(o+4,a-2);i=this.saveTextToParentTag(i,e,r),e.add(this.options.commentPropName,[{[this.options.textNodeName]:h}])}o=a}else if(s.substr(o+1,2)==="!D"){let a=n.readDocType(s,o);this.docTypeEntities=a.entities,o=a.i}else if(s.substr(o+1,2)==="!["){let a=b(s,"]]>",o,"CDATA is not closed.")-2,h=s.substring(o+9,a);i=this.saveTextToParentTag(i,e,r);let u=this.parseTextData(h,e.tagname,r,!0,!1,!0,!0);u==null&&(u=""),this.options.cdataPropName?e.add(this.options.cdataPropName,[{[this.options.textNodeName]:h}]):e.add(this.options.textNodeName,u),o=a+2}else{let a=z(s,o,this.options.removeNSPrefix),h=a.tagName,u=a.rawTagName,c=a.tagExp,d=a.attrExpPresent,C=a.closeIndex;if(this.options.transformTagName){let g=this.options.transformTagName(h);c===h&&(c=g),h=g}e&&i&&e.tagname!=="!xml"&&(i=this.saveTextToParentTag(i,e,r,!1));let A=e;A&&this.options.unpairedTags.indexOf(A.tagname)!==-1&&(e=this.tagsNodeStack.pop(),r=r.substring(0,r.lastIndexOf("."))),h!==t.tagname&&(r+=r?"."+h:h);let $=o;if(this.isItStopNode(this.stopNodesExact,this.stopNodesWildcard,r,h)){let g="";if(c.length>0&&c.lastIndexOf("/")===c.length-1)h[h.length-1]==="/"?(h=h.substr(0,h.length-1),r=r.substr(0,r.length-1),c=h):c=c.substr(0,c.length-1),o=a.closeIndex;else if(this.options.unpairedTags.indexOf(h)!==-1)o=a.closeIndex;else{let G=this.readStopNodeData(s,u,C+1);if(!G)throw new Error(`Unexpected end of ${u}`);o=G.i,g=G.tagContent}let y=new m(h);h!==c&&d&&(y[":@"]=this.buildAttributesMap(c,r,h)),g&&(g=this.parseTextData(g,h,r,!0,d,!0,!0)),r=r.substr(0,r.lastIndexOf(".")),y.add(this.options.textNodeName,g),this.addChild(e,y,r,$)}else{if(c.length>0&&c.lastIndexOf("/")===c.length-1){if(h[h.length-1]==="/"?(h=h.substr(0,h.length-1),r=r.substr(0,r.length-1),c=h):c=c.substr(0,c.length-1),this.options.transformTagName){let y=this.options.transformTagName(h);c===h&&(c=y),h=y}let g=new m(h);h!==c&&d&&(g[":@"]=this.buildAttributesMap(c,r,h)),this.addChild(e,g,r,$),r=r.substr(0,r.lastIndexOf("."))}else{let g=new m(h);this.tagsNodeStack.push(e),h!==c&&d&&(g[":@"]=this.buildAttributesMap(c,r,h)),this.addChild(e,g,r,$),e=g}i="",o=C}}else i+=s[o];return t.child};function oe(s,t,e,i){this.options.captureMetaData||(i=void 0);let r=this.options.updateTag(t.tagname,e,t[":@"]);r===!1||(typeof r=="string"&&(t.tagname=r),s.addChild(t,i))}var ae=function(s,t,e){if(s.indexOf("&")===-1)return s;let i=this.options.processEntities;if(!i.enabled||i.allowedTags&&!i.allowedTags.includes(t)||i.tagFilter&&!i.tagFilter(t,e))return s;for(let r in this.docTypeEntities){let n=this.docTypeEntities[r],o=s.match(n.regx);if(o){if(this.entityExpansionCount+=o.length,i.maxTotalExpansions&&this.entityExpansionCount>i.maxTotalExpansions)throw new Error(`Entity expansion limit exceeded: ${this.entityExpansionCount} > ${i.maxTotalExpansions}`);let l=s.length;if(s=s.replace(n.regx,n.val),i.maxExpandedLength&&(this.currentExpandedLength+=s.length-l,this.currentExpandedLength>i.maxExpandedLength))throw new Error(`Total expanded content size exceeded: ${this.currentExpandedLength} > ${i.maxExpandedLength}`)}}if(s.indexOf("&")===-1)return s;for(let r in this.lastEntities){let n=this.lastEntities[r];s=s.replace(n.regex,n.val)}if(s.indexOf("&")===-1)return s;if(this.options.htmlEntities)for(let r in this.htmlEntities){let n=this.htmlEntities[r];s=s.replace(n.regex,n.val)}return s=s.replace(this.ampEntity.regex,this.ampEntity.val),s};function he(s,t,e,i){return s&&(i===void 0&&(i=t.child.length===0),s=this.parseTextData(s,t.tagname,e,!1,t[":@"]?Object.keys(t[":@"]).length!==0:!1,i),s!==void 0&&s!==""&&t.add(this.options.textNodeName,s),s=""),s}function le(s,t,e,i){return!!(t&&t.has(i)||s&&s.has(e))}function ce(s,t,e=">"){let i,r="";for(let n=t;n<s.length;n++){let o=s[n];if(i)o===i&&(i="");else if(o==='"'||o==="'")i=o;else if(o===e[0])if(e[1]){if(s[n+1]===e[1])return{data:r,index:n}}else return{data:r,index:n};else o===" "&&(o=" ");r+=o}}function b(s,t,e,i){let r=s.indexOf(t,e);if(r===-1)throw new Error(i);return r+t.length-1}function z(s,t,e,i=">"){let r=ce(s,t+1,i);if(!r)return;let n=r.data,o=r.index,l=n.search(/\s/),a=n,h=!0;l!==-1&&(a=n.substring(0,l),n=n.substring(l+1).trimStart());let u=a;if(e){let c=a.indexOf(":");c!==-1&&(a=a.substr(c+1),h=a!==r.data.substr(c+1))}return{tagName:a,tagExp:n,closeIndex:o,attrExpPresent:h,rawTagName:u}}function ue(s,t,e){let i=e,r=1;for(;e<s.length;e++)if(s[e]==="<")if(s[e+1]==="/"){let n=b(s,">",e,`${t} is not closed`);if(s.substring(e+2,n).trim()===t&&(r--,r===0))return{tagContent:s.substring(i,e),i:n};e=n}else if(s[e+1]==="?")e=b(s,"?>",e+1,"StopNode is not closed.");else if(s.substr(e+1,3)==="!--")e=b(s,"-->",e+3,"StopNode is not closed.");else if(s.substr(e+1,2)==="![")e=b(s,"]]>",e,"StopNode is not closed.")-2;else{let n=z(s,e,">");n&&((n&&n.tagName)===t&&n.tagExp[n.tagExp.length-1]!=="/"&&r++,e=n.closeIndex)}}function Q(s,t,e){if(t&&typeof s=="string"){let i=s.trim();return i==="true"?!0:i==="false"?!1:X(s,e)}else return nt(s)?s:""}function pt(s,t,e){let i=Number.parseInt(s,t);return i>=0&&i<=1114111?String.fromCodePoint(i):e+s+";"}var H=m.getMetaDataSymbol();function Z(s,t){return dt(s,t)}function dt(s,t,e){let i,r={};for(let n=0;n<s.length;n++){let o=s[n],l=fe(o),a="";if(e===void 0?a=l:a=e+"."+l,l===t.textNodeName)i===void 0?i=o[l]:i+=""+o[l];else{if(l===void 0)continue;if(o[l]){let h=dt(o[l],t,a),u=de(h,t);o[H]!==void 0&&(h[H]=o[H]),o[":@"]?pe(h,o[":@"],a,t):Object.keys(h).length===1&&h[t.textNodeName]!==void 0&&!t.alwaysCreateTextNode?h=h[t.textNodeName]:Object.keys(h).length===0&&(t.alwaysCreateTextNode?h[t.textNodeName]="":h=""),r[l]!==void 0&&r.hasOwnProperty(l)?(Array.isArray(r[l])||(r[l]=[r[l]]),r[l].push(h)):t.isArray(l,a,u)?r[l]=[h]:r[l]=h}}}return typeof i=="string"?i.length>0&&(r[t.textNodeName]=i):i!==void 0&&(r[t.textNodeName]=i),r}function fe(s){let t=Object.keys(s);for(let e=0;e<t.length;e++){let i=t[e];if(i!==":@")return i}}function pe(s,t,e,i){if(t){let r=Object.keys(t),n=r.length;for(let o=0;o<n;o++){let l=r[o];i.isArray(l,e+"."+l,!0,!0)?s[l]=[t[l]]:s[l]=t[l]}}}function de(s,t){let{textNodeName:e}=t,i=Object.keys(s).length;return!!(i===0||i===1&&(s[e]||typeof s[e]=="boolean"||s[e]===0))}var w=class{constructor(t){this.externalEntities={},this.options=ft(t)}parse(t,e){if(typeof t!="string"&&t.toString)t=t.toString();else if(typeof t!="string")throw new Error("XML data is accepted in String or Bytes[] form.");if(e){e===!0&&(e={});let n=ct(t,e);if(n!==!0)throw Error(`${n.err.msg}:${n.err.line}:${n.err.col}`)}let i=new R(this.options);i.addExternalEntities(this.externalEntities);let r=i.parseXml(t);return this.options.preserveOrder||r===void 0?r:Z(r,this.options)}addEntity(t,e){if(e.indexOf("&")!==-1)throw new Error("Entity value can't have '&'");if(t.indexOf("&")!==-1||t.indexOf(";")!==-1)throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '&#xD;'");if(e==="&")throw new Error("An entity with value '&' is not permitted");this.externalEntities[t]=e}static getMetaDataSymbol(){return m.getMetaDataSymbol()}};function K(s,t){if(t?._parser&&t._parser!=="fast-xml-parser")throw new Error(t?._parser);let e={allowBooleanAttributes:!0,ignoreDeclaration:!0,removeNSPrefix:t?.removeNSPrefix,textNodeName:t?.textNodeName,isArray:(r,n,o,l)=>Boolean(t?.arrayPaths?.some(h=>n===h)),...t?._fastXML},i=ge(s,e);return t?.uncapitalizeKeys?x(i):i}function ge(s,t){return new w({ignoreAttributes:!1,attributeNamePrefix:"",...t}).parse(s)}var Te="4.4.3",I={dataType:null,batchType:null,name:"XML",id:"xml",module:"xml",version:Te,worker:!1,extensions:["xml"],mimeTypes:["application/xml","text/xml"],testText:Ee,options:{xml:{_parser:"fast-xml-parser",uncapitalizeKeys:!1,removeNSPrefix:!1,textNodeName:"value",arrayPaths:[]}},parse:async(s,t)=>K(new TextDecoder().decode(s),{...I.options.xml,...t?.xml}),parseTextSync:(s,t)=>K(s,{...I.options.xml,...t?.xml})};function Ee(s){return s.startsWith("<?xml")}function J(s,t){return gt(s||{},t)}function gt(s,t,e=0){if(e>3)return t;let i={...s};for(let[r,n]of Object.entries(t))n&&typeof n=="object"&&!Array.isArray(n)?i[r]=gt(i[r]||{},t[r],e+1):i[r]=t[r];return i}var Et={...I,name:"HTML",id:"html",extensions:["html","htm"],mimeTypes:["text/html"],testText:me,parse:async(s,t)=>Tt(new TextDecoder().decode(s),t),parseTextSync:(s,t)=>Tt(s,t)};function me(s){return s.startsWith("<html")}function Tt(s,t){return t=J(t,{xml:{_parser:"fast-xml-parser",_fastXML:{htmlEntities:!0}}}),I.parseTextSync?.(s,t)}function D(s){return Array.isArray(s)?s:(s&&typeof s=="object"&&s[0],s?[s]:[])}function mt(s,t){s[t]=D(s[t])}return Ct(V);})(); return __exports__; });