UNPKG

react-xml-viewer

Version:
6 lines 51.4 kB
(function(f,b){typeof exports=="object"&&typeof module<"u"?module.exports=b(require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["react/jsx-runtime","react"],b):(f=typeof globalThis<"u"?globalThis:f||self,f.ReactXmlViewer=b(f.ReactJsxRuntime,f.React))})(this,function(f,b){"use strict";function Oe(n){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>n[t]})}}return e.default=n,Object.freeze(e)}const R=Oe(b),D=":@",F="#text",X="#comment",U="#cdata",ee="DECLARATION_TAG",$e="TAG",L={tagColor:"#d43900",textColor:"#333",attributeKeyColor:"#2a7ab0",attributeValueColor:"#008000",separatorColor:"#333",commentColor:"#aaa",cdataColor:"#1d781d",fontFamily:"monospace",lineNumberBackground:"#eee",lineNumberColor:"#222"};function te(n,e){const t=b.useRef(n),r=b.useRef();return b.useEffect(()=>{t.current=n},[n]),b.useEffect(()=>()=>{r.current&&clearTimeout(r.current)},[]),b.useCallback((...s)=>{r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{t.current(...s)},e)},[e])}const Fe={lines:{},push:()=>{}},ne=b.createContext(Fe),Le=({children:n,enabled:e=!1})=>{const[t,r]=b.useState({}),s=b.useRef({}),i=b.useCallback(()=>{r(s.current)},[]),a=te(i,100),o=b.useCallback((h,u)=>{var c;e&&(((c=s.current[h])==null?void 0:c.element)!==u.element&&(s.current[h]=u),a())},[]),l=b.useMemo(()=>({lines:t,push:o}),[t,o,e]);return f.jsx(ne.Provider,{value:l,children:n})},re=()=>b.useContext(ne),Ve={theme:L,collapsible:!1,indentSize:2},se=b.createContext(Ve),S=()=>b.useContext(se);function ke(n,e){return new Array(e*n+1).join(" ")}function ie(n){return typeof n=="string"&&n.includes(` `)}function je(n){return typeof n=="string"?!1:n.length===1&&F in n[0]&&!ie(n[0][F])}function Be(n){switch(n){case F:case U:case X:return n;default:return n.startsWith("?")?ee:$e}}function Xe(n,e){const t={};for(const r in n)r!==e&&(t[r]=n[r]);return t}function Ue(n){const e=n[D],t=Xe(n,D),[[r,s]]=Object.entries(t),i=Be(r);return{attributes:e,tagKey:r,subElements:s,type:i}}function We(n,e){return Object.keys(L).every(r=>n[r]===e[r])}const oe=":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",ze=oe+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040",Ye="["+oe+"]["+ze+"]*",Ke=new RegExp("^"+Ye+"$");function ae(n,e){const t=[];let r=e.exec(n);for(;r;){const s=[];s.startIndex=e.lastIndex-r[0].length;const i=r.length;for(let a=0;a<i;a++)s.push(r[a]);t.push(s),r=e.exec(n)}return t}const le=function(n){const e=Ke.exec(n);return!(e===null||typeof e>"u")};function qe(n){return typeof n<"u"}const W=["hasOwnProperty","toString","valueOf","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__"],ue=["__proto__","constructor","prototype"],Ge={allowBooleanAttributes:!1,unpairedTags:[]};function ce(n,e){e=Object.assign({},Ge,e);const t=[];let r=!1,s=!1;n[0]==="\uFEFF"&&(n=n.substr(1));for(let i=0;i<n.length;i++)if(n[i]==="<"&&n[i+1]==="?"){if(i+=2,i=fe(n,i),i.err)return i}else if(n[i]==="<"){let a=i;if(i++,n[i]==="!"){i=de(n,i);continue}else{let o=!1;n[i]==="/"&&(o=!0,i++);let l="";for(;i<n.length&&n[i]!==">"&&n[i]!==" "&&n[i]!==" "&&n[i]!==` `&&n[i]!=="\r";i++)l+=n[i];if(l=l.trim(),l[l.length-1]==="/"&&(l=l.substring(0,l.length-1),i--),!tt(l)){let c;return l.trim().length===0?c="Invalid space after '<'.":c="Tag '"+l+"' is an invalid name.",y("InvalidTag",c,N(n,i))}const h=Qe(n,i);if(h===!1)return y("InvalidAttr","Attributes for '"+l+"' have open quote.",N(n,i));let u=h.value;if(i=h.index,u[u.length-1]==="/"){const c=i-u.length;u=u.substring(0,u.length-1);const d=pe(u,e);if(d===!0)r=!0;else return y(d.err.code,d.err.msg,N(n,c+d.err.line))}else if(o)if(h.tagClosed){if(u.trim().length>0)return y("InvalidTag","Closing tag '"+l+"' can't have attributes or invalid starting.",N(n,a));if(t.length===0)return y("InvalidTag","Closing tag '"+l+"' has not been opened.",N(n,a));{const c=t.pop();if(l!==c.tagName){let d=N(n,c.tagStartPos);return y("InvalidTag","Expected closing tag '"+c.tagName+"' (opened in line "+d.line+", col "+d.col+") instead of closing tag '"+l+"'.",N(n,a))}t.length==0&&(s=!0)}}else return y("InvalidTag","Closing tag '"+l+"' doesn't have proper closing.",N(n,i));else{const c=pe(u,e);if(c!==!0)return y(c.err.code,c.err.msg,N(n,i-u.length+c.err.line));if(s===!0)return y("InvalidXml","Multiple possible root nodes found.",N(n,i));e.unpairedTags.indexOf(l)!==-1||t.push({tagName:l,tagStartPos:a}),r=!0}for(i++;i<n.length;i++)if(n[i]==="<")if(n[i+1]==="!"){i++,i=de(n,i);continue}else if(n[i+1]==="?"){if(i=fe(n,++i),i.err)return i}else break;else if(n[i]==="&"){const c=De(n,i);if(c==-1)return y("InvalidChar","char '&' is not expected.",N(n,i));i=c}else if(s===!0&&!he(n[i]))return y("InvalidXml","Extra text at the end",N(n,i));n[i]==="<"&&i--}}else{if(he(n[i]))continue;return y("InvalidChar","char '"+n[i]+"' is not expected.",N(n,i))}if(r){if(t.length==1)return y("InvalidTag","Unclosed tag '"+t[0].tagName+"'.",N(n,t[0].tagStartPos));if(t.length>0)return y("InvalidXml","Invalid '"+JSON.stringify(t.map(i=>i.tagName),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1})}else return y("InvalidXml","Start tag expected.",1);return!0}function he(n){return n===" "||n===" "||n===` `||n==="\r"}function fe(n,e){const t=e;for(;e<n.length;e++)if(n[e]=="?"||n[e]==" "){const r=n.substr(t,e-t);if(e>5&&r==="xml")return y("InvalidXml","XML declaration allowed only at the start of the document.",N(n,e));if(n[e]=="?"&&n[e+1]==">"){e++;break}else continue}return e}function de(n,e){if(n.length>e+5&&n[e+1]==="-"&&n[e+2]==="-"){for(e+=3;e<n.length;e++)if(n[e]==="-"&&n[e+1]==="-"&&n[e+2]===">"){e+=2;break}}else if(n.length>e+8&&n[e+1]==="D"&&n[e+2]==="O"&&n[e+3]==="C"&&n[e+4]==="T"&&n[e+5]==="Y"&&n[e+6]==="P"&&n[e+7]==="E"){let t=1;for(e+=8;e<n.length;e++)if(n[e]==="<")t++;else if(n[e]===">"&&(t--,t===0))break}else if(n.length>e+9&&n[e+1]==="["&&n[e+2]==="C"&&n[e+3]==="D"&&n[e+4]==="A"&&n[e+5]==="T"&&n[e+6]==="A"&&n[e+7]==="["){for(e+=8;e<n.length;e++)if(n[e]==="]"&&n[e+1]==="]"&&n[e+2]===">"){e+=2;break}}return e}const Ze='"',Je="'";function Qe(n,e){let t="",r="",s=!1;for(;e<n.length;e++){if(n[e]===Ze||n[e]===Je)r===""?r=n[e]:r!==n[e]||(r="");else if(n[e]===">"&&r===""){s=!0;break}t+=n[e]}return r!==""?!1:{value:t,index:e,tagClosed:s}}const He=new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`,"g");function pe(n,e){const t=ae(n,He),r={};for(let s=0;s<t.length;s++){if(t[s][1].length===0)return y("InvalidAttr","Attribute '"+t[s][2]+"' has no space in starting.",O(t[s]));if(t[s][3]!==void 0&&t[s][4]===void 0)return y("InvalidAttr","Attribute '"+t[s][2]+"' is without value.",O(t[s]));if(t[s][3]===void 0&&!e.allowBooleanAttributes)return y("InvalidAttr","boolean attribute '"+t[s][2]+"' is not allowed.",O(t[s]));const i=t[s][2];if(!et(i))return y("InvalidAttr","Attribute '"+i+"' is an invalid name.",O(t[s]));if(!Object.prototype.hasOwnProperty.call(r,i))r[i]=1;else return y("InvalidAttr","Attribute '"+i+"' is repeated.",O(t[s]))}return!0}function Re(n,e){let t=/\d/;for(n[e]==="x"&&(e++,t=/[\da-fA-F]/);e<n.length;e++){if(n[e]===";")return e;if(!n[e].match(t))break}return-1}function De(n,e){if(e++,n[e]===";")return-1;if(n[e]==="#")return e++,Re(n,e);let t=0;for(;e<n.length;e++,t++)if(!(n[e].match(/\w/)&&t<20)){if(n[e]===";")break;return-1}return e}function y(n,e,t){return{err:{code:n,msg:e,line:t.line||t,col:t.col}}}function et(n){return le(n)}function tt(n){return le(n)}function N(n,e){const t=n.substring(0,e).split(/\r?\n/);return{line:t.length,col:t[t.length-1].length+1}}function O(n){return n.startIndex+n[1].length}const nt={cent:"¢",pound:"£",curren:"¤",yen:"¥",euro:"€",dollar:"$",euro:"€",fnof:"ƒ",inr:"₹",af:"؋",birr:"ብር",peso:"₱",rub:"₽",won:"₩",yuan:"¥",cedil:"¸"},ge={amp:"&",apos:"'",gt:">",lt:"<",quot:'"'},rt={nbsp:" ",copy:"©",reg:"®",trade:"™",mdash:"—",ndash:"–",hellip:"…",laquo:"«",raquo:"»",lsquo:"‘",rsquo:"’",ldquo:"“",rdquo:"”",bull:"•",para:"¶",sect:"§",deg:"°",frac12:"½",frac14:"¼",frac34:"¾"},st=new Set("!?\\\\/[]$%{}^&*()<>|+");function be(n){if(n[0]==="#")throw new Error(`[EntityReplacer] Invalid character '#' in entity name: "${n}"`);for(const e of n)if(st.has(e))throw new Error(`[EntityReplacer] Invalid character '${e}' in entity name: "${n}"`);return n}function z(...n){const e=Object.create(null);for(const t of n)if(t)for(const r of Object.keys(t)){const s=t[r];if(typeof s=="string")e[r]=s;else if(s&&typeof s=="object"&&s.val!==void 0){const i=s.val;typeof i=="string"&&(e[r]=i)}}return e}const x="external",V="base",Y="all";function it(n){return!n||n===x?new Set([x]):n===Y?new Set([Y]):n===V?new Set([V]):Array.isArray(n)?new Set(n):new Set([x])}const w=Object.freeze({allow:0,leave:1,remove:2,throw:3}),ot=new Set([9,10,13]);function at(n){if(!n)return{xmlVersion:1,onLevel:w.allow,nullLevel:w.remove};const e=n.xmlVersion===1.1?1.1:1,t=w[n.onNCR]??w.allow,r=w[n.nullNCR]??w.remove,s=Math.max(r,w.remove);return{xmlVersion:e,onLevel:t,nullLevel:s}}class lt{constructor(e={}){this._limit=e.limit||{},this._maxTotalExpansions=this._limit.maxTotalExpansions||0,this._maxExpandedLength=this._limit.maxExpandedLength||0,this._postCheck=typeof e.postCheck=="function"?e.postCheck:r=>r,this._limitTiers=it(this._limit.applyLimitsTo??x),this._numericAllowed=e.numericAllowed??!0,this._baseMap=z(ge,e.namedEntities||null),this._externalMap=Object.create(null),this._inputMap=Object.create(null),this._totalExpansions=0,this._expandedLength=0,this._removeSet=new Set(e.remove&&Array.isArray(e.remove)?e.remove:[]),this._leaveSet=new Set(e.leave&&Array.isArray(e.leave)?e.leave:[]);const t=at(e.ncr);this._ncrXmlVersion=t.xmlVersion,this._ncrOnLevel=t.onLevel,this._ncrNullLevel=t.nullLevel}setExternalEntities(e){if(e)for(const t of Object.keys(e))be(t);this._externalMap=z(e)}addExternalEntity(e,t){be(e),typeof t=="string"&&t.indexOf("&")===-1&&(this._externalMap[e]=t)}addInputEntities(e){this._totalExpansions=0,this._expandedLength=0,this._inputMap=z(e)}reset(){return this._inputMap=Object.create(null),this._totalExpansions=0,this._expandedLength=0,this}setXmlVersion(e){this._ncrXmlVersion=e===1.1?1.1:1}decode(e){if(typeof e!="string"||e.length===0)return e;const t=e,r=[],s=e.length;let i=0,a=0;const o=this._maxTotalExpansions>0,l=this._maxExpandedLength>0,h=o||l;for(;a<s;){if(e.charCodeAt(a)!==38){a++;continue}let c=a+1;for(;c<s&&e.charCodeAt(c)!==59&&c-a<=32;)c++;if(c>=s||e.charCodeAt(c)!==59){a++;continue}const d=e.slice(a+1,c);if(d.length===0){a++;continue}let p,g;if(this._removeSet.has(d))p="",g===void 0&&(g=x);else if(this._leaveSet.has(d)){a++;continue}else if(d.charCodeAt(0)===35){const m=this._resolveNCR(d);if(m===void 0){a++;continue}p=m,g=V}else{const m=this._resolveName(d);p=m==null?void 0:m.value,g=m==null?void 0:m.tier}if(p===void 0){a++;continue}if(a>i&&r.push(e.slice(i,a)),r.push(p),i=c+1,a=i,h&&this._tierCounts(g)){if(o&&(this._totalExpansions++,this._totalExpansions>this._maxTotalExpansions))throw new Error(`[EntityReplacer] Entity expansion count limit exceeded: ${this._totalExpansions} > ${this._maxTotalExpansions}`);if(l){const m=p.length-(d.length+2);if(m>0&&(this._expandedLength+=m,this._expandedLength>this._maxExpandedLength))throw new Error(`[EntityReplacer] Expanded content length limit exceeded: ${this._expandedLength} > ${this._maxExpandedLength}`)}}}i<s&&r.push(e.slice(i));const u=r.length===0?e:r.join("");return this._postCheck(u,t)}_tierCounts(e){return this._limitTiers.has(Y)?!0:this._limitTiers.has(e)}_resolveName(e){if(e in this._inputMap)return{value:this._inputMap[e],tier:x};if(e in this._externalMap)return{value:this._externalMap[e],tier:x};if(e in this._baseMap)return{value:this._baseMap[e],tier:V}}_classifyNCR(e){return e===0?this._ncrNullLevel:e>=55296&&e<=57343||this._ncrXmlVersion===1&&e>=1&&e<=31&&!ot.has(e)?w.remove:-1}_applyNCRAction(e,t,r){switch(e){case w.allow:return String.fromCodePoint(r);case w.remove:return"";case w.leave:return;case w.throw:throw new Error(`[EntityDecoder] Prohibited numeric character reference &${t}; (U+${r.toString(16).toUpperCase().padStart(4,"0")})`);default:return String.fromCodePoint(r)}}_resolveNCR(e){const t=e.charCodeAt(1);let r;if(t===120||t===88?r=parseInt(e.slice(2),16):r=parseInt(e.slice(1),10),Number.isNaN(r)||r<0||r>1114111)return;const s=this._classifyNCR(r);if(!this._numericAllowed&&s<w.remove)return;const i=s===-1?this._ncrOnLevel:Math.max(this._ncrOnLevel,s);return this._applyNCRAction(i,e,r)}}const me=n=>W.includes(n)?"__"+n:n,ut={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(n,e){return e},attributeValueProcessor:function(n,e){return e},stopNodes:[],alwaysCreateTextNode:!1,isArray:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,entityDecoder:null,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(n,e,t){return n},captureMetaData:!1,maxNestedTags:100,strictReservedNames:!0,jPath:!0,onDangerousProperty:me};function ct(n,e){if(typeof n!="string")return;const t=n.toLowerCase();if(W.some(r=>t===r.toLowerCase()))throw new Error(`[SECURITY] Invalid ${e}: "${n}" is a reserved JavaScript keyword that could cause prototype pollution`);if(ue.some(r=>t===r.toLowerCase()))throw new Error(`[SECURITY] Invalid ${e}: "${n}" is a reserved JavaScript keyword that could cause prototype pollution`)}function ye(n,e){return typeof n=="boolean"?{enabled:n,maxEntitySize:1e4,maxExpansionDepth:1e4,maxTotalExpansions:1/0,maxExpandedLength:1e5,maxEntityCount:1e3,allowedTags:null,tagFilter:null,appliesTo:"all"}:typeof n=="object"&&n!==null?{enabled:n.enabled!==!1,maxEntitySize:Math.max(1,n.maxEntitySize??1e4),maxExpansionDepth:Math.max(1,n.maxExpansionDepth??1e4),maxTotalExpansions:Math.max(1,n.maxTotalExpansions??1/0),maxExpandedLength:Math.max(1,n.maxExpandedLength??1e5),maxEntityCount:Math.max(1,n.maxEntityCount??1e3),allowedTags:n.allowedTags??null,tagFilter:n.tagFilter??null,appliesTo:n.appliesTo??"all"}:ye(!0)}const ht=function(n){const e=Object.assign({},ut,n),t=[{value:e.attributeNamePrefix,name:"attributeNamePrefix"},{value:e.attributesGroupName,name:"attributesGroupName"},{value:e.textNodeName,name:"textNodeName"},{value:e.cdataPropName,name:"cdataPropName"},{value:e.commentPropName,name:"commentPropName"}];for(const{value:r,name:s}of t)r&&ct(r,s);return e.onDangerousProperty===null&&(e.onDangerousProperty=me),e.processEntities=ye(e.processEntities,e.htmlEntities),e.unpairedTagsSet=new Set(e.unpairedTags),e.stopNodes&&Array.isArray(e.stopNodes)&&(e.stopNodes=e.stopNodes.map(r=>typeof r=="string"&&r.startsWith("*.")?".."+r.substring(2):r)),e};let k;typeof Symbol!="function"?k="@@xmlMetadata":k=Symbol("XML Node Metadata");class A{constructor(e){this.tagname=e,this.child=[],this[":@"]=Object.create(null)}add(e,t){e==="__proto__"&&(e="#__proto__"),this.child.push({[e]:t})}addChild(e,t){e.tagname==="__proto__"&&(e.tagname="#__proto__"),e[":@"]&&Object.keys(e[":@"]).length>0?this.child.push({[e.tagname]:e.child,":@":e[":@"]}):this.child.push({[e.tagname]:e.child}),t!==void 0&&(this.child[this.child.length-1][k]={startIndex:t})}static getMetaDataSymbol(){return k}}const Ee=":A-Za-z_À-ÖØ-öø-˿Ͱ-ͽͿ-҆҈-῿‌-‍⁰-↏Ⰰ-⿯、-퟿豈-﷏ﷰ-�",ft=Ee+"\\-\\.\\d·̀-ͯ‿-⁀",Ne=":A-Za-z_À-˿Ͱ-ͽͿ-҆҈-῿‌-‍⁰-↏Ⰰ-⿯、-퟿豈-﷏ﷰ-�𐀀-󯿿",dt=Ne+"\\-\\.\\d·̀-ͯ҇‿-⁀",we=(n,e,t="")=>{const r=n.replace(":",""),s=e.replace(":",""),i=`[${r}][${s}]*`;return{name:new RegExp(`^[${n}][${e}]*$`,t),ncName:new RegExp(`^${i}$`,t),qName:new RegExp(`^${i}(?::${i})?$`,t),nmToken:new RegExp(`^[${e}]+$`,t),nmTokens:new RegExp(`^[${e}]+(?:\\s+[${e}]+)*$`,t)}},pt=we(Ee,ft),gt=we(Ne,dt,"u"),bt=(n="1.0")=>n==="1.1"?gt:pt,Ce=(n,{xmlVersion:e="1.0"}={})=>bt(e).qName.test(n);class mt{constructor(e,t){this.suppressValidationErr=!e,this.options=e,this.xmlVersion=t||1}setXmlVersion(e=1){this.xmlVersion=e}readDocType(e,t){const r=Object.create(null);let s=0;if(e[t+3]==="O"&&e[t+4]==="C"&&e[t+5]==="T"&&e[t+6]==="Y"&&e[t+7]==="P"&&e[t+8]==="E"){t=t+9;let i=1,a=!1,o=!1,l="";for(;t<e.length;t++)if(e[t]==="<"&&!o){if(a&&P(e,"!ENTITY",t)){t+=7;let h,u;if([h,u,t]=this.readEntityExp(e,t+1,this.suppressValidationErr),u.indexOf("&")===-1){if(this.options.enabled!==!1&&this.options.maxEntityCount!=null&&s>=this.options.maxEntityCount)throw new Error(`Entity count (${s+1}) exceeds maximum allowed (${this.options.maxEntityCount})`);r[h]=u,s++}}else if(a&&P(e,"!ELEMENT",t)){t+=8;const{index:h}=this.readElementExp(e,t+1);t=h}else if(a&&P(e,"!ATTLIST",t))t+=8;else if(a&&P(e,"!NOTATION",t)){t+=9;const{index:h}=this.readNotationExp(e,t+1,this.suppressValidationErr);t=h}else if(P(e,"!--",t))o=!0;else throw new Error("Invalid DOCTYPE");i++,l=""}else if(e[t]===">"){if(o?e[t-1]==="-"&&e[t-2]==="-"&&(o=!1,i--):i--,i===0)break}else e[t]==="["?a=!0:l+=e[t];if(i!==0)throw new Error("Unclosed DOCTYPE")}else throw new Error("Invalid Tag instead of DOCTYPE");return{entities:r,i:t}}readEntityExp(e,t){t=C(e,t);const r=t;for(;t<e.length&&!/\s/.test(e[t])&&e[t]!=='"'&&e[t]!=="'";)t++;let s=e.substring(r,t);if($(s,{xmlVersion:this.xmlVersion}),t=C(e,t),!this.suppressValidationErr){if(e.substring(t,t+6).toUpperCase()==="SYSTEM")throw new Error("External entities are not supported");if(e[t]==="%")throw new Error("Parameter entities are not supported")}let i="";if([t,i]=this.readIdentifierVal(e,t,"entity"),this.options.enabled!==!1&&this.options.maxEntitySize!=null&&i.length>this.options.maxEntitySize)throw new Error(`Entity "${s}" size (${i.length}) exceeds maximum allowed size (${this.options.maxEntitySize})`);return t--,[s,i,t]}readNotationExp(e,t){t=C(e,t);const r=t;for(;t<e.length&&!/\s/.test(e[t]);)t++;let s=e.substring(r,t);!this.suppressValidationErr&&$(s,{xmlVersion:this.xmlVersion}),t=C(e,t);const i=e.substring(t,t+6).toUpperCase();if(!this.suppressValidationErr&&i!=="SYSTEM"&&i!=="PUBLIC")throw new Error(`Expected SYSTEM or PUBLIC, found "${i}"`);t+=i.length,t=C(e,t);let a=null,o=null;if(i==="PUBLIC")[t,a]=this.readIdentifierVal(e,t,"publicIdentifier"),t=C(e,t),(e[t]==='"'||e[t]==="'")&&([t,o]=this.readIdentifierVal(e,t,"systemIdentifier"));else if(i==="SYSTEM"&&([t,o]=this.readIdentifierVal(e,t,"systemIdentifier"),!this.suppressValidationErr&&!o))throw new Error("Missing mandatory system identifier for SYSTEM notation");return{notationName:s,publicIdentifier:a,systemIdentifier:o,index:--t}}readIdentifierVal(e,t,r){let s="";const i=e[t];if(i!=='"'&&i!=="'")throw new Error(`Expected quoted string, found "${i}"`);t++;const a=t;for(;t<e.length&&e[t]!==i;)t++;if(s=e.substring(a,t),e[t]!==i)throw new Error(`Unterminated ${r} value`);return t++,[t,s]}readElementExp(e,t){t=C(e,t);const r=t;for(;t<e.length&&!/\s/.test(e[t]);)t++;let s=e.substring(r,t);if(!this.suppressValidationErr&&!Ce(s,{xmlVersion:this.xmlVersion}))throw new Error(`Invalid element name: "${s}"`);t=C(e,t);let i="";if(e[t]==="E"&&P(e,"MPTY",t))t+=4;else if(e[t]==="A"&&P(e,"NY",t))t+=2;else if(e[t]==="("){t++;const a=t;for(;t<e.length&&e[t]!==")";)t++;if(i=e.substring(a,t),e[t]!==")")throw new Error("Unterminated content model")}else if(!this.suppressValidationErr)throw new Error(`Invalid Element Expression, found "${e[t]}"`);return{elementName:s,contentModel:i.trim(),index:t}}readAttlistExp(e,t){t=C(e,t);let r=t;for(;t<e.length&&!/\s/.test(e[t]);)t++;let s=e.substring(r,t);for($(s,{xmlVersion:this.xmlVersion}),t=C(e,t),r=t;t<e.length&&!/\s/.test(e[t]);)t++;let i=e.substring(r,t);if(!$(i,{xmlVersion:this.xmlVersion}))throw new Error(`Invalid attribute name: "${i}"`);t=C(e,t);let a="";if(e.substring(t,t+8).toUpperCase()==="NOTATION"){if(a="NOTATION",t+=8,t=C(e,t),e[t]!=="(")throw new Error(`Expected '(', found "${e[t]}"`);t++;let l=[];for(;t<e.length&&e[t]!==")";){const h=t;for(;t<e.length&&e[t]!=="|"&&e[t]!==")";)t++;let u=e.substring(h,t);if(u=u.trim(),!$(u,{xmlVersion:this.xmlVersion}))throw new Error(`Invalid notation name: "${u}"`);l.push(u),e[t]==="|"&&(t++,t=C(e,t))}if(e[t]!==")")throw new Error("Unterminated list of notations");t++,a+=" ("+l.join("|")+")"}else{const l=t;for(;t<e.length&&!/\s/.test(e[t]);)t++;a+=e.substring(l,t);const h=["CDATA","ID","IDREF","IDREFS","ENTITY","ENTITIES","NMTOKEN","NMTOKENS"];if(!this.suppressValidationErr&&!h.includes(a.toUpperCase()))throw new Error(`Invalid attribute type: "${a}"`)}t=C(e,t);let o="";return e.substring(t,t+8).toUpperCase()==="#REQUIRED"?(o="#REQUIRED",t+=8):e.substring(t,t+7).toUpperCase()==="#IMPLIED"?(o="#IMPLIED",t+=7):[t,o]=this.readIdentifierVal(e,t,"ATTLIST"),{elementName:s,attributeName:i,attributeType:a,defaultValue:o,index:t}}}const C=(n,e)=>{for(;e<n.length&&/\s/.test(n[e]);)e++;return e};function P(n,e,t){for(let r=0;r<e.length;r++)if(e[r]!==n[t+r+1])return!1;return!0}function $(n,e){if(Ce(n,{xmlVersion:e}))return n;throw new Error(`Invalid entity name ${n}`)}const yt=/^[-+]?0x[a-fA-F0-9]+$/,Et=/^0b[01]+$/,Nt=/^0o[0-7]+$/,wt=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,Ct={hex:!0,binary:!1,octal:!1,leadingZeros:!0,decimalPoint:".",eNotation:!0,infinity:"original"};function Tt(n,e={}){if(e=Object.assign({},Ct,e),!n||typeof n!="string")return n;let t=n.trim();if(t.length===0)return n;if(e.skipLike!==void 0&&e.skipLike.test(t))return n;if(t==="0")return 0;if(e.hex&&yt.test(t))return K(t,16);if(e.binary&&Et.test(t))return K(t,2);if(e.octal&&Nt.test(t))return K(t,8);if(isFinite(t)){if(t.includes("e")||t.includes("E"))return St(n,t,e);{const r=wt.exec(t);if(r){const s=r[1]||"",i=r[2];let a=vt(r[3]);const o=s?n[i.length+1]===".":n[i.length]===".";if(!e.leadingZeros&&(i.length>1||i.length===1&&!o))return n;{const l=Number(t),h=String(l);if(l===0)return l;if(h.search(/[eE]/)!==-1)return e.eNotation?l:n;if(t.indexOf(".")!==-1)return h==="0"||h===a||h===`${s}${a}`?l:n;let u=i?a:t;return i?u===h||s+u===h?l:n:u===h||u===s+h?l:n}}else return n}}else return At(n,Number(t),e)}const _t=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;function St(n,e,t){if(!t.eNotation)return n;const r=e.match(_t);if(r){let s=r[1]||"";const i=r[3].indexOf("e")===-1?"E":"e",a=r[2],o=s?n[a.length+1]===i:n[a.length]===i;return a.length>1&&o?n:a.length===1&&(r[3].startsWith(`.${i}`)||r[3][0]===i)?Number(e):a.length>0?t.leadingZeros&&!o?(e=(r[1]||"")+r[3],Number(e)):n:Number(e)}else return n}function vt(n){return n&&n.indexOf(".")!==-1&&(n=n.replace(/0+$/,""),n==="."?n="0":n[0]==="."?n="0"+n:n[n.length-1]==="."&&(n=n.substring(0,n.length-1))),n}function K(n,e){const t=n.trim();if((e===2||e===8)&&(n=t.substring(2)),parseInt)return parseInt(n,e);if(Number.parseInt)return Number.parseInt(n,e);if(window&&window.parseInt)return window.parseInt(n,e);throw new Error("parseInt, Number.parseInt, window.parseInt are not supported")}function At(n,e,t){const r=e===1/0;switch(t.infinity.toLowerCase()){case"null":return null;case"infinity":return e;case"string":return r?"Infinity":"-Infinity";case"original":default:return n}}function It(n){return typeof n=="function"?n:Array.isArray(n)?e=>{for(const t of n)if(typeof t=="string"&&e===t||t instanceof RegExp&&t.test(e))return!0}:()=>!1}class Te{constructor(e,t={},r){this.pattern=e,this.separator=t.separator||".",this.segments=this._parse(e),this.data=r,this._hasDeepWildcard=this.segments.some(s=>s.type==="deep-wildcard"),this._hasAttributeCondition=this.segments.some(s=>s.attrName!==void 0),this._hasPositionSelector=this.segments.some(s=>s.position!==void 0)}_parse(e){const t=[];let r=0,s="";for(;r<e.length;)e[r]===this.separator?r+1<e.length&&e[r+1]===this.separator?(s.trim()&&(t.push(this._parseSegment(s.trim())),s=""),t.push({type:"deep-wildcard"}),r+=2):(s.trim()&&t.push(this._parseSegment(s.trim())),s="",r++):(s+=e[r],r++);return s.trim()&&t.push(this._parseSegment(s.trim())),t}_parseSegment(e){const t={type:"tag"};let r=null,s=e;const i=e.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);if(i&&(s=i[1]+i[3],i[2])){const u=i[2].slice(1,-1);u&&(r=u)}let a,o=s;if(s.includes("::")){const u=s.indexOf("::");if(a=s.substring(0,u).trim(),o=s.substring(u+2).trim(),!a)throw new Error(`Invalid namespace in pattern: ${e}`)}let l,h=null;if(o.includes(":")){const u=o.lastIndexOf(":"),c=o.substring(0,u).trim(),d=o.substring(u+1).trim();["first","last","odd","even"].includes(d)||/^nth\(\d+\)$/.test(d)?(l=c,h=d):l=o}else l=o;if(!l)throw new Error(`Invalid segment pattern: ${e}`);if(t.tag=l,a&&(t.namespace=a),r)if(r.includes("=")){const u=r.indexOf("=");t.attrName=r.substring(0,u).trim(),t.attrValue=r.substring(u+1).trim()}else t.attrName=r.trim();if(h){const u=h.match(/^nth\((\d+)\)$/);u?(t.position="nth",t.positionValue=parseInt(u[1],10)):t.position=h}return t}get length(){return this.segments.length}hasDeepWildcard(){return this._hasDeepWildcard}hasAttributeCondition(){return this._hasAttributeCondition}hasPositionSelector(){return this._hasPositionSelector}toString(){return this.pattern}}class xt{constructor(){this._byDepthAndTag=new Map,this._wildcardByDepth=new Map,this._deepWildcards=[],this._patterns=new Set,this._sealed=!1}add(e){if(this._sealed)throw new TypeError("ExpressionSet is sealed. Create a new ExpressionSet to add more expressions.");if(this._patterns.has(e.pattern))return this;if(this._patterns.add(e.pattern),e.hasDeepWildcard())return this._deepWildcards.push(e),this;const t=e.length,r=e.segments[e.segments.length-1],s=r==null?void 0:r.tag;if(!s||s==="*")this._wildcardByDepth.has(t)||this._wildcardByDepth.set(t,[]),this._wildcardByDepth.get(t).push(e);else{const i=`${t}:${s}`;this._byDepthAndTag.has(i)||this._byDepthAndTag.set(i,[]),this._byDepthAndTag.get(i).push(e)}return this}addAll(e){for(const t of e)this.add(t);return this}has(e){return this._patterns.has(e.pattern)}get size(){return this._patterns.size}seal(){return this._sealed=!0,this}get isSealed(){return this._sealed}matchesAny(e){return this.findMatch(e)!==null}findMatch(e){const t=e.getDepth(),r=e.getCurrentTag(),s=`${t}:${r}`,i=this._byDepthAndTag.get(s);if(i){for(let o=0;o<i.length;o++)if(e.matches(i[o]))return i[o]}const a=this._wildcardByDepth.get(t);if(a){for(let o=0;o<a.length;o++)if(e.matches(a[o]))return a[o]}for(let o=0;o<this._deepWildcards.length;o++)if(e.matches(this._deepWildcards[o]))return this._deepWildcards[o];return null}}class Pt{constructor(e){this._matcher=e}get separator(){return this._matcher.separator}getCurrentTag(){const e=this._matcher.path;return e.length>0?e[e.length-1].tag:void 0}getCurrentNamespace(){const e=this._matcher.path;return e.length>0?e[e.length-1].namespace:void 0}getAttrValue(e){var r;const t=this._matcher.path;if(t.length!==0)return(r=t[t.length-1].values)==null?void 0:r[e]}hasAttr(e){const t=this._matcher.path;if(t.length===0)return!1;const r=t[t.length-1];return r.values!==void 0&&e in r.values}getPosition(){const e=this._matcher.path;return e.length===0?-1:e[e.length-1].position??0}getCounter(){const e=this._matcher.path;return e.length===0?-1:e[e.length-1].counter??0}getIndex(){return this.getPosition()}getDepth(){return this._matcher.path.length}toString(e,t=!0){return this._matcher.toString(e,t)}toArray(){return this._matcher.path.map(e=>e.tag)}matches(e){return this._matcher.matches(e)}matchesAny(e){return e.matchesAny(this._matcher)}}class Mt{constructor(e={}){this.separator=e.separator||".",this.path=[],this.siblingStacks=[],this._pathStringCache=null,this._view=new Pt(this)}push(e,t=null,r=null){this._pathStringCache=null,this.path.length>0&&(this.path[this.path.length-1].values=void 0);const s=this.path.length;this.siblingStacks[s]||(this.siblingStacks[s]=new Map);const i=this.siblingStacks[s],a=r?`${r}:${e}`:e,o=i.get(a)||0;let l=0;for(const u of i.values())l+=u;i.set(a,o+1);const h={tag:e,position:l,counter:o};r!=null&&(h.namespace=r),t!=null&&(h.values=t),this.path.push(h)}pop(){if(this.path.length===0)return;this._pathStringCache=null;const e=this.path.pop();return this.siblingStacks.length>this.path.length+1&&(this.siblingStacks.length=this.path.length+1),e}updateCurrent(e){if(this.path.length>0){const t=this.path[this.path.length-1];e!=null&&(t.values=e)}}getCurrentTag(){return this.path.length>0?this.path[this.path.length-1].tag:void 0}getCurrentNamespace(){return this.path.length>0?this.path[this.path.length-1].namespace:void 0}getAttrValue(e){var t;if(this.path.length!==0)return(t=this.path[this.path.length-1].values)==null?void 0:t[e]}hasAttr(e){if(this.path.length===0)return!1;const t=this.path[this.path.length-1];return t.values!==void 0&&e in t.values}getPosition(){return this.path.length===0?-1:this.path[this.path.length-1].position??0}getCounter(){return this.path.length===0?-1:this.path[this.path.length-1].counter??0}getIndex(){return this.getPosition()}getDepth(){return this.path.length}toString(e,t=!0){const r=e||this.separator;if(r===this.separator&&t===!0){if(this._pathStringCache!==null)return this._pathStringCache;const i=this.path.map(a=>a.namespace?`${a.namespace}:${a.tag}`:a.tag).join(r);return this._pathStringCache=i,i}return this.path.map(i=>t&&i.namespace?`${i.namespace}:${i.tag}`:i.tag).join(r)}toArray(){return this.path.map(e=>e.tag)}reset(){this._pathStringCache=null,this.path=[],this.siblingStacks=[]}matches(e){const t=e.segments;return t.length===0?!1:e.hasDeepWildcard()?this._matchWithDeepWildcard(t):this._matchSimple(t)}_matchSimple(e){if(this.path.length!==e.length)return!1;for(let t=0;t<e.length;t++)if(!this._matchSegment(e[t],this.path[t],t===this.path.length-1))return!1;return!0}_matchWithDeepWildcard(e){let t=this.path.length-1,r=e.length-1;for(;r>=0&&t>=0;){const s=e[r];if(s.type==="deep-wildcard"){if(r--,r<0)return!0;const i=e[r];let a=!1;for(let o=t;o>=0;o--)if(this._matchSegment(i,this.path[o],o===this.path.length-1)){t=o-1,r--,a=!0;break}if(!a)return!1}else{if(!this._matchSegment(s,this.path[t],t===this.path.length-1))return!1;t--,r--}}return r<0}_matchSegment(e,t,r){if(e.tag!=="*"&&e.tag!==t.tag||e.namespace!==void 0&&e.namespace!=="*"&&e.namespace!==t.namespace||e.attrName!==void 0&&(!r||!t.values||!(e.attrName in t.values)||e.attrValue!==void 0&&String(t.values[e.attrName])!==String(e.attrValue)))return!1;if(e.position!==void 0){if(!r)return!1;const s=t.counter??0;if(e.position==="first"&&s!==0)return!1;if(e.position==="odd"&&s%2!==1)return!1;if(e.position==="even"&&s%2!==0)return!1;if(e.position==="nth"&&s!==e.positionValue)return!1}return!0}matchesAny(e){return e.matchesAny(this)}snapshot(){return{path:this.path.map(e=>({...e})),siblingStacks:this.siblingStacks.map(e=>new Map(e))}}restore(e){this._pathStringCache=null,this.path=e.path.map(t=>({...t})),this.siblingStacks=e.siblingStacks.map(t=>new Map(t))}readOnly(){return this._view}}function Ot(n,e){if(!n)return{};const t=e.attributesGroupName?n[e.attributesGroupName]:n;if(!t)return{};const r={};for(const s in t)if(s.startsWith(e.attributeNamePrefix)){const i=s.substring(e.attributeNamePrefix.length);r[i]=t[s]}else r[s]=t[s];return r}function $t(n){if(!n||typeof n!="string")return;const e=n.indexOf(":");if(e!==-1&&e>0){const t=n.substring(0,e);if(t!=="xmlns")return t}}class Ft{constructor(e,t){this.options=e,this.currentNode=null,this.tagsNodeStack=[],this.parseXml=Bt,this.parseTextData=Lt,this.resolveNameSpace=Vt,this.buildAttributesMap=jt,this.isItStopNode=zt,this.replaceEntitiesValue=Ut,this.readStopNodeData=qt,this.saveTextToParentTag=Wt,this.addChild=Xt,this.ignoreAttributesFn=It(this.options.ignoreAttributes),this.entityExpansionCount=0,this.currentExpandedLength=0;let r={...ge};this.options.entityDecoder?this.entityDecoder=this.options.entityDecoder:(typeof this.options.htmlEntities=="object"?r=this.options.htmlEntities:this.options.htmlEntities===!0&&(r={...rt,...nt}),this.entityDecoder=new lt({namedEntities:{...r,...t},numericAllowed:this.options.htmlEntities,limit:{maxTotalExpansions:this.options.processEntities.maxTotalExpansions,maxExpandedLength:this.options.processEntities.maxExpandedLength,applyLimitsTo:this.options.processEntities.appliesTo}})),this.matcher=new Mt,this.readonlyMatcher=this.matcher.readOnly(),this.isCurrentNodeStopNode=!1,this.stopNodeExpressionsSet=new xt;const s=this.options.stopNodes;if(s&&s.length>0){for(let i=0;i<s.length;i++){const a=s[i];typeof a=="string"?this.stopNodeExpressionsSet.add(new Te(a)):a instanceof Te&&this.stopNodeExpressionsSet.add(a)}this.stopNodeExpressionsSet.seal()}}}function Lt(n,e,t,r,s,i,a){const o=this.options;if(n!==void 0&&(o.trimValues&&!r&&(n=n.trim()),n.length>0)){a||(n=this.replaceEntitiesValue(n,e,t));const l=o.jPath?t.toString():t,h=o.tagValueProcessor(e,n,l,s,i);return h==null?n:typeof h!=typeof n||h!==n?h:o.trimValues||n.trim()===n?G(n,o.parseTagValue,o.numberParseOptions):n}}function Vt(n){if(this.options.removeNSPrefix){const e=n.split(":"),t=n.charAt(0)==="/"?"/":"";if(e[0]==="xmlns")return"";e.length===2&&(n=t+e[1])}return n}const kt=new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`,"gm");function jt(n,e,t,r=!1){const s=this.options;if(r===!0||s.ignoreAttributes!==!0&&typeof n=="string"){const i=ae(n,kt),a=i.length,o={},l=new Array(a);let h=!1;const u={};for(let p=0;p<a;p++){const g=this.resolveNameSpace(i[p][1]),m=i[p][4];if(g.length&&m!==void 0){let E=m;s.trimValues&&(E=E.trim()),E=this.replaceEntitiesValue(E,t,this.readonlyMatcher),l[p]=E,u[g]=E,h=!0}}h&&typeof e=="object"&&e.updateCurrent&&e.updateCurrent(u);const c=s.jPath?e.toString():this.readonlyMatcher;let d=!1;for(let p=0;p<a;p++){const g=this.resolveNameSpace(i[p][1]);if(this.ignoreAttributesFn(g,c))continue;let m=s.attributeNamePrefix+g;if(g.length)if(s.transformAttributeName&&(m=s.transformAttributeName(m)),m=_e(m,s),i[p][4]!==void 0){const E=l[p],v=s.attributeValueProcessor(g,E,c);v==null?o[m]=E:typeof v!=typeof E||v!==E?o[m]=v:o[m]=G(E,s.parseAttributeValue,s.numberParseOptions),d=!0}else s.allowBooleanAttributes&&(o[m]=!0,d=!0)}if(!d)return;if(s.attributesGroupName&&!s.preserveOrder){const p={};return p[s.attributesGroupName]=o,p}return o}}const Bt=function(n){n=n.replace(/\r\n?/g,` `);const e=new A("!xml");let t=e,r="";this.matcher.reset(),this.entityDecoder.reset(),this.entityExpansionCount=0,this.currentExpandedLength=0;const s=this.options,i=new mt(s.processEntities),a=n.length;for(let o=0;o<a;o++)if(n[o]==="<"){const h=n.charCodeAt(o+1);if(h===47){const u=M(n,">",o,"Closing Tag is not closed.");let c=n.substring(o+2,u).trim();if(s.removeNSPrefix){const p=c.indexOf(":");p!==-1&&(c=c.substr(p+1))}c=Z(s.transformTagName,c,"",s).tagName,t&&(r=this.saveTextToParentTag(r,t,this.readonlyMatcher));const d=this.matcher.getCurrentTag();if(c&&s.unpairedTagsSet.has(c))throw new Error(`Unpaired tag can not be used as closing tag: </${c}>`);d&&s.unpairedTagsSet.has(d)&&(this.matcher.pop(),this.tagsNodeStack.pop()),this.matcher.pop(),this.isCurrentNodeStopNode=!1,t=this.tagsNodeStack.pop(),r="",o=u}else if(h===63){let u=q(n,o,!1,"?>");if(!u)throw new Error("Pi Tag is not closed.");r=this.saveTextToParentTag(r,t,this.readonlyMatcher);const c=this.buildAttributesMap(u.tagExp,this.matcher,u.tagName,!0);if(c){const d=c[this.options.attributeNamePrefix+"version"];this.entityDecoder.setXmlVersion(Number(d)||1),i.setXmlVersion(Number(d)||1)}if(!(s.ignoreDeclaration&&u.tagName==="?xml"||s.ignorePiTags)){const d=new A(u.tagName);d.add(s.textNodeName,""),u.tagName!==u.tagExp&&u.attrExpPresent&&s.ignoreAttributes!==!0&&(d[":@"]=c),this.addChild(t,d,this.readonlyMatcher,o)}o=u.closeIndex+1}else if(h===33&&n.charCodeAt(o+2)===45&&n.charCodeAt(o+3)===45){const u=M(n,"-->",o+4,"Comment is not closed.");if(s.commentPropName){const c=n.substring(o+4,u-2);r=this.saveTextToParentTag(r,t,this.readonlyMatcher),t.add(s.commentPropName,[{[s.textNodeName]:c}])}o=u}else if(h===33&&n.charCodeAt(o+2)===68){const u=i.readDocType(n,o);this.entityDecoder.addInputEntities(u.entities),o=u.i}else if(h===33&&n.charCodeAt(o+2)===91){const u=M(n,"]]>",o,"CDATA is not closed.")-2,c=n.substring(o+9,u);r=this.saveTextToParentTag(r,t,this.readonlyMatcher);let d=this.parseTextData(c,t.tagname,this.readonlyMatcher,!0,!1,!0,!0);d==null&&(d=""),s.cdataPropName?t.add(s.cdataPropName,[{[s.textNodeName]:c}]):t.add(s.textNodeName,d),o=u+2}else{let u=q(n,o,s.removeNSPrefix);if(!u){const T=n.substring(Math.max(0,o-50),Math.min(a,o+50));throw new Error(`readTagExp returned undefined at position ${o}. Context: "${T}"`)}let c=u.tagName;const d=u.rawTagName;let p=u.tagExp,g=u.attrExpPresent,m=u.closeIndex;if({tagName:c,tagExp:p}=Z(s.transformTagName,c,p,s),s.strictReservedNames&&(c===s.commentPropName||c===s.cdataPropName||c===s.textNodeName||c===s.attributesGroupName))throw new Error(`Invalid tag name: ${c}`);t&&r&&t.tagname!=="!xml"&&(r=this.saveTextToParentTag(r,t,this.readonlyMatcher,!1));const E=t;E&&s.unpairedTagsSet.has(E.tagname)&&(t=this.tagsNodeStack.pop(),this.matcher.pop());let v=!1;p.length>0&&p.lastIndexOf("/")===p.length-1&&(v=!0,c[c.length-1]==="/"?(c=c.substr(0,c.length-1),p=c):p=p.substr(0,p.length-1),g=c!==p);let _=null,Me;Me=$t(d),c!==e.tagname&&this.matcher.push(c,{},Me),c!==p&&g&&(_=this.buildAttributesMap(p,this.matcher,c),_&&Ot(_,s)),c!==e.tagname&&(this.isCurrentNodeStopNode=this.isItStopNode());const B=o;if(this.isCurrentNodeStopNode){let T="";if(v)o=u.closeIndex;else if(s.unpairedTagsSet.has(c))o=u.closeIndex;else{const H=this.readStopNodeData(n,d,m+1);if(!H)throw new Error(`Unexpected end of ${d}`);o=H.i,T=H.tagContent}const Q=new A(c);_&&(Q[":@"]=_),Q.add(s.textNodeName,T),this.matcher.pop(),this.isCurrentNodeStopNode=!1,this.addChild(t,Q,this.readonlyMatcher,B)}else{if(v){({tagName:c,tagExp:p}=Z(s.transformTagName,c,p,s));const T=new A(c);_&&(T[":@"]=_),this.addChild(t,T,this.readonlyMatcher,B),this.matcher.pop(),this.isCurrentNodeStopNode=!1}else if(s.unpairedTagsSet.has(c)){const T=new A(c);_&&(T[":@"]=_),this.addChild(t,T,this.readonlyMatcher,B),this.matcher.pop(),this.isCurrentNodeStopNode=!1,o=u.closeIndex;continue}else{const T=new A(c);if(this.tagsNodeStack.length>s.maxNestedTags)throw new Error("Maximum nested tags exceeded");this.tagsNodeStack.push(t),_&&(T[":@"]=_),this.addChild(t,T,this.readonlyMatcher,B),t=T}r="",o=m}}}else r+=n[o];return e.child};function Xt(n,e,t,r){this.options.captureMetaData||(r=void 0);const s=this.options.jPath?t.toString():t,i=this.options.updateTag(e.tagname,s,e[":@"]);i===!1||(typeof i=="string"&&(e.tagname=i),n.addChild(e,r))}function Ut(n,e,t){const r=this.options.processEntities;if(!r||!r.enabled)return n;if(r.allowedTags){const s=this.options.jPath?t.toString():t;if(!(Array.isArray(r.allowedTags)?r.allowedTags.includes(e):r.allowedTags(e,s)))return n}if(r.tagFilter){const s=this.options.jPath?t.toString():t;if(!r.tagFilter(e,s))return n}return this.entityDecoder.decode(n)}function Wt(n,e,t,r){return n&&(r===void 0&&(r=e.child.length===0),n=this.parseTextData(n,e.tagname,t,!1,e[":@"]?Object.keys(e[":@"]).length!==0:!1,r),n!==void 0&&n!==""&&e.add(this.options.textNodeName,n),n=""),n}function zt(){return this.stopNodeExpressionsSet.size===0?!1:this.matcher.matchesAny(this.stopNodeExpressionsSet)}function Yt(n,e,t=">"){let r=0;const s=n.length,i=t.charCodeAt(0),a=t.length>1?t.charCodeAt(1):-1;let o="",l=e;for(let h=e;h<s;h++){const u=n.charCodeAt(h);if(r)u===r&&(r=0);else if(u===34||u===39)r=u;else if(u===i)if(a!==-1){if(n.charCodeAt(h+1)===a)return o+=n.substring(l,h),{data:o,index:h}}else return o+=n.substring(l,h),{data:o,index:h};else u===9&&!r&&(o+=n.substring(l,h)+" ",l=h+1)}}function M(n,e,t,r){const s=n.indexOf(e,t);if(s===-1)throw new Error(r);return s+e.length-1}function Kt(n,e,t,r){const s=n.indexOf(e,t);if(s===-1)throw new Error(r);return s}function q(n,e,t,r=">"){const s=Yt(n,e+1,r);if(!s)return;let i=s.data;const a=s.index,o=i.search(/\s/);let l=i,h=!0;o!==-1&&(l=i.substring(0,o),i=i.substring(o+1).trimStart());const u=l;if(t){const c=l.indexOf(":");c!==-1&&(l=l.substr(c+1),h=l!==s.data.substr(c+1))}return{tagName:l,tagExp:i,closeIndex:a,attrExpPresent:h,rawTagName:u}}function qt(n,e,t){const r=t;let s=1;const i=n.length;for(;t<i;t++)if(n[t]==="<"){const a=n.charCodeAt(t+1);if(a===47){const o=Kt(n,">",t,`${e} is not closed`);if(n.substring(t+2,o).trim()===e&&(s--,s===0))return{tagContent:n.substring(r,t),i:o};t=o}else if(a===63)t=M(n,"?>",t+1,"StopNode is not closed.");else if(a===33&&n.charCodeAt(t+2)===45&&n.charCodeAt(t+3)===45)t=M(n,"-->",t+3,"StopNode is not closed.");else if(a===33&&n.charCodeAt(t+2)===91)t=M(n,"]]>",t,"StopNode is not closed.")-2;else{const o=q(n,t,!1);o&&((o&&o.tagName)===e&&o.tagExp[o.tagExp.length-1]!=="/"&&s++,t=o.closeIndex)}}}function G(n,e,t){if(e&&typeof n=="string"){const r=n.trim();return r==="true"?!0:r==="false"?!1:Tt(n,t)}else return qe(n)?n:""}function Z(n,e,t,r){if(n){const s=n(e);t===e&&(t=s),e=s}return e=_e(e,r),{tagName:e,tagExp:t}}function _e(n,e){if(ue.includes(n))throw new Error(`[SECURITY] Invalid name: "${n}" is a reserved JavaScript keyword that could cause prototype pollution`);return W.includes(n)?e.onDangerousProperty(n):n}const J=A.getMetaDataSymbol();function Gt(n,e){if(!n||typeof n!="object")return{};if(!e)return n;const t={};for(const r in n)if(r.startsWith(e)){const s=r.substring(e.length);t[s]=n[r]}else t[r]=n[r];return t}function Zt(n,e,t,r){return Se(n,e,t,r)}function Se(n,e,t,r){let s;const i={};for(let a=0;a<n.length;a++){const o=n[a],l=Jt(o);if(l!==void 0&&l!==e.textNodeName){const h=Gt(o[":@"]||{},e.attributeNamePrefix);t.push(l,h)}if(l===e.textNodeName)s===void 0?s=o[l]:s+=""+o[l];else{if(l===void 0)continue;if(o[l]){let h=Se(o[l],e,t,r);const u=Ht(h,e);if(Object.keys(h).length===0&&e.alwaysCreateTextNode&&(h[e.textNodeName]=""),o[":@"]?Qt(h,o[":@"],r,e):Object.keys(h).length===1&&h[e.textNodeName]!==void 0&&!e.alwaysCreateTextNode?h=h[e.textNodeName]:Object.keys(h).length===0&&(e.alwaysCreateTextNode?h[e.textNodeName]="":h=""),o[J]!==void 0&&typeof h=="object"&&h!==null&&(h[J]=o[J]),i[l]!==void 0&&Object.prototype.hasOwnProperty.call(i,l))Array.isArray(i[l])||(i[l]=[i[l]]),i[l].push(h);else{const c=e.jPath?r.toString():r;e.isArray(l,c,u)?i[l]=[h]:i[l]=h}l!==void 0&&l!==e.textNodeName&&t.pop()}}}return typeof s=="string"?s.length>0&&(i[e.textNodeName]=s):s!==void 0&&(i[e.textNodeName]=s),i}function Jt(n){const e=Object.keys(n);for(let t=0;t<e.length;t++){const r=e[t];if(r!==":@")return r}}function Qt(n,e,t,r){if(e){const s=Object.keys(e),i=s.length;for(let a=0;a<i;a++){const o=s[a],l=o.startsWith(r.attributeNamePrefix)?o.substring(r.attributeNamePrefix.length):o,h=r.jPath?t.toString()+"."+l:t;r.isArray(o,h,!0,!0)?n[o]=[e[o]]:n[o]=e[o]}}}function Ht(n,e){const{textNodeName:t}=e,r=Object.keys(n).length;return!!(r===0||r===1&&(n[t]||typeof n[t]=="boolean"||n[t]===0))}class Rt{constructor(e){this.externalEntities={},this.options=ht(e)}parse(e,t){if(typeof e!="string"&&e.toString)e=e.toString();else if(typeof e!="string")throw new Error("XML data is accepted in String or Bytes[] form.");if(t){t===!0&&(t={});const i=ce(e,t);if(i!==!0)throw Error(`${i.err.msg}:${i.err.line}:${i.err.col}`)}const r=new Ft(this.options,this.externalEntities),s=r.parseXml(e);return this.options.preserveOrder||s===void 0?s:Zt(s,this.options,r.matcher,r.readonlyMatcher)}addEntity(e,t){if(t.indexOf("&")!==-1)throw new Error("Entity value can't have '&'");if(e.indexOf("&")!==-1||e.indexOf(";")!==-1)throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '&#xD;'");if(t==="&")throw new Error("An entity with value '&' is not permitted");this.externalEntities[e]=t}static getMetaDataSymbol(){return A.getMetaDataSymbol()}}const Dt={validate:ce},en=new Rt({preserveOrder:!0,ignoreAttributes:!1,attributeNamePrefix:"",allowBooleanAttributes:!0,commentPropName:X,cdataPropName:U,parseTagValue:!1});function tn(n){return b.useMemo(()=>{try{if(!Dt.validate(n))throw new Error("Invalid XML!");const e=en.parse(n);if(typeof n=="string"&&n.trim().length>0&&e.length===0)throw new Error("Invalid XML!");return{json:e,valid:!0}}catch(e){return{json:null,valid:!1,errorMessage:`Fail to parse: ${e.message}`}}},[n])}function I(n,e=!0){const{push:t}=re(),r=b.useRef(null);return b.useEffect(()=>{e&&r.current&&n&&t(n,{element:r.current})},[r.current,t,n,e]),r}function nn(n){const{indentation:e,children:t,isInline:r,keyValue:s}=n,{theme:i}=S(),a=I(s),o=I(`${s}-close`,!r);return f.jsxs("div",{style:{color:i.cdataColor},children:[f.jsx("span",{ref:a,children:`${e}<![CDATA[`}),t,f.jsx("span",{ref:o,children:`${r?"":e}]]>`})]})}const rn=n=>R.createElement("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",...n},R.createElement("path",{d:"M9 17.898C9 18.972 10.2649 19.546 11.0731 18.8388L17.3838 13.3169C18.1806 12.6197 18.1806 11.3801 17.3838 10.6829L11.0731 5.16108C10.2649 4.45388 9 5.02785 9 6.1018V17.898Z"}));function ve(n){const{collapsible:e,theme:t}=S(),{collapsed:r}=n;return e?f.jsx("span",{style:{position:"relative"},children:f.jsx("span",{style:{position:"absolute",right:"0",border:0,padding:0,background:"none"},children:f.jsx(rn,{fill:t.separatorColor,style:{transform:`rotate(${r?0:90}deg)`,transition:"transform 0.2s"}})})}):null}function Ae(n){const{collapsible:e,initialCollapsedDepth:t}=S(),r=t!=null,[s,i]=b.useState(()=>!r||!e?!1:n>=t),a=()=>i(o=>!o);return b.useEffect(()=>{i(!r||!e?!1:n>=t)},[t,n,e]),{collapsed:s,buttonProps:e?{onClick:a,role:"button",style:{cursor:"pointer"}}:{}}}function sn(n){const{indentation:e,children:t,isInline:r,level:s,keyValue:i}=n,{theme:a}=S(),{collapsed:o,buttonProps:l}=Ae(s),h=I(i),u=I(`${i}-close`,!r),c=o?"none":void 0;return f.jsxs("div",{style:{color:a.commentColor},children:[f.jsxs("span",{...l,children:[f.jsx("span",{children:e}),f.jsx(ve,{collapsed:o}),f.jsx("span",{ref:h,children:"<!-- "})]}),f.jsx("span",{style:{display:c},children:t}),o&&"...",f.jsx("span",{style:{display:c},ref:u,children:`${r||o?" ":e}-->`})]})}function Ie(n){const{attributes:e}=n,{theme:t}=S();return e?f.jsx("span",{children:Object.entries(e).map(([r,s])=>f.jsxs("span",{children:[f.jsx("span",{style:{color:t.attributeKeyColor},children:` ${r}`}),f.jsx("span",{style:{color:t.separatorColor},children:"="}),f.jsx("span",{style:{color:t.attributeValueColor},children:`"${s}"`})]},`attribute-${r}`))}):null}function on(n){const{indentation:e,tagKey:t,attributes:r,keyValue:s}=n,{theme:i}=S(),a=I(s);return f.jsxs("div",{ref:a,children:[f.jsx("span",{style:{color:i.separatorColor},children:`${e}<?`}),f.jsx("span",{style:{color:i.tagColor},children:`${t.slice(1)}`}),f.jsx(Ie,{attributes:r}),f.jsx("span",{style:{color:i.separatorColor},children:"?>"})]})}function an(n){const{indentation:e,tagKey:t,attributes:r,children:s,isInline:i,hasChildren:a,level:o,keyValue:l}=n,{collapsed:h,buttonProps:u}=Ae(o),{theme:c}=S(),d=I(l),p=I(`${l}-close`,!i),g=h?"none":void 0;return f.jsxs("div",{ref:d,children:[f.jsxs("span",{...u,children:[f.jsx("span",{children:e}),f.jsx(ve,{collapsed:h}),f.jsx("span",{style:{color:c.separatorColor},children:"<"}),f.jsx("span",{style:{color:c.tagColor},children:`${t}`}),!h&&f.jsx(Ie,{attributes:r}),!h&&f.jsx("span",{style:{color:c.separatorColor},children:a?">":" />"})]}),a&&f.jsxs(f.Fragment,{children:[f.jsx("span",{style:{display:g},children:s}),h&&f.jsx("span",{style:{color:"#777"},children:"..."}),f.jsx("span",{style:{color:c.separatorColor,display:g},children:`${i||h?"":e}</`}),f.jsx("span",{style:{color:c.tagColor,display:g},children:`${t}`}),f.jsx("span",{style:{color:c.separatorColor,display:g},ref:p,children:">"})]})]})}function ln(n){const{children:e,keyValue:t}=n,r=I(t);return f.jsx("div",{ref:r,children:e})}function un(n){const{hasSiblings:e,text:t,indentation:r,isText:s,keyValue:i}=n,{theme:a}=S(),o=s?{color:a.textColor}:void 0;return ie(t)||e?f.jsx("div",{style:o,children:t.split(` `).filter(l=>!!l.trim()).map((l,h)=>f.jsx(ln,{keyValue:`${i}${h}`,children:`${r}${l.trim()}`},`${i}${h}`))}):f.jsx("span",{style:o,children:t})}function cn(n){const{elements:e,level:t=0,isText:r=!0,parentKey:s=""}=n,{indentSize:i}=S();return!Array.isArray(e)||e.length===0?null:f.jsx(f.Fragment,{children:e.map((a,o)=>{const{tagKey:l,attributes:h,subElements:u,type:c}=Ue(a),d=e.length>1,p=ke(i,t),g=`${s}-${t+1}-${o+1}`,m=je(u);switch(c){case F:return f.jsx(un,{text:u,indentation:p,hasSiblings:d,isText:r,keyValue:g},g);case X:return f.jsx(sn,{keyValue:g,isInline:m,indentation:p,level:t,children:f.jsx(j,{elements:u,level:t+1,parentKey:g,isText:!1})},g);case U:return f.jsx(nn,{keyValue:g,indentation:p,isInline:m,children:f.jsx(j,{elements:u,level:t+1,parentKey:g,isText:!1})},g);case ee:return f.jsx(on,{indentation:p,tagKey:l,attributes:h,keyValue:g},g);default:return f.jsx(an,{indentation:p,tagKey:l,attributes:h,isInline:m,hasChildren:u.length>0,level:t,keyValue:g,children:f.jsx(j,{elements:u,level:t+1,parentKey:g})},g)}})})}const j=b.memo(cn);function hn(){return f.jsx("div",{children:"Invalid XML!"})}function xe(n){return n?n.checkVisibility?n.checkVisibility():!!(n.offsetWidth||n.offsetHeight||n.getClientRects().length):!1}function Pe(n){return!n||!n.parentElement?0:xe(n.parentElement)?n.parentElement.offsetTop:Pe(n.parentElement)}function fn({viewerContainer:n}){const{lines:e}=re(),{theme:t}=S(),[r,s]=b.useState({width:0,height:0}),i=b.useRef(null),a=b.useCallback(c=>s(c),[]),o=te(a,300),{sortedLines:l,numberOfLines:h}=b.useMemo(()=>{const c=Object.values(e).map(d=>{var g;const p=xe(d.element);return{...d,offset:p?(g=d.element)==null?void 0:g.offsetTop:Pe(d.element),visible:p}}).sort((d,p)=>d.offset===p.offset?d.visible===p.visible?0:d.visible?-1:1:d.offset-p.offset).map((d,p)=>({...d,lineNumber:p+1}));return{sortedLines:c.filter(d=>d.visible),numberOfLines:c.length+1}},[e,r.width,r.height]),u=b.useMemo(()=>new ResizeObserver(function(c){const{width:d,height:p}=c[0].contentRect;o({width:d,height:p})}),[o]);return b.useEffect(()=>{n&&u.observe(n)},[n,u]),b.useEffe