UNPKG

fast-xml-parser

Version:

Validate XML, Parse XML, Build XML without C/C++ based libraries

1 lines 54.2 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.fxp=e():t.fxp=e()}(this,()=>(()=>{"use strict";var t={d:(e,r)=>{for(var i in r)t.o(r,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:r[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{XMLBuilder:()=>Wt,XMLParser:()=>Pt,XMLValidator:()=>Xt});var r=":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",i=new RegExp("^["+r+"]["+r+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040]*$");function n(t,e){for(var r=[],i=e.exec(t);i;){var n=[];n.startIndex=e.lastIndex-i[0].length;for(var s=i.length,a=0;a<s;a++)n.push(i[a]);r.push(n),i=e.exec(t)}return r}var s=function(t){return!(null==i.exec(t))},a=["hasOwnProperty","toString","valueOf","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__"],o=["__proto__","constructor","prototype"],h={allowBooleanAttributes:!1,unpairedTags:[]};function l(t,e){e=Object.assign({},h,e);var r=[],i=!1,n=!1;"\ufeff"===t[0]&&(t=t.substr(1));for(var s=0;s<t.length;s++)if("<"===t[s]&&"?"===t[s+1]){if((s=p(t,s+=2)).err)return s}else{if("<"!==t[s]){if(u(t[s]))continue;return b("InvalidChar","char '"+t[s]+"' is not expected.",E(t,s))}var a=s;if("!"===t[++s]){s=d(t,s);continue}var o=!1;"/"===t[s]&&(o=!0,s++);for(var l="";s<t.length&&">"!==t[s]&&" "!==t[s]&&"\t"!==t[s]&&"\n"!==t[s]&&"\r"!==t[s];s++)l+=t[s];if("/"===(l=l.trim())[l.length-1]&&(l=l.substring(0,l.length-1),s--),!y(l))return b("InvalidTag",0===l.trim().length?"Invalid space after '<'.":"Tag '"+l+"' is an invalid name.",E(t,s));var c=g(t,s);if(!1===c)return b("InvalidAttr","Attributes for '"+l+"' have open quote.",E(t,s));var f=c.value;if(s=c.index,"/"===f[f.length-1]){var m=s-f.length,N=v(f=f.substring(0,f.length-1),e);if(!0!==N)return b(N.err.code,N.err.msg,E(t,m+N.err.line));i=!0}else if(o){if(!c.tagClosed)return b("InvalidTag","Closing tag '"+l+"' doesn't have proper closing.",E(t,s));if(f.trim().length>0)return b("InvalidTag","Closing tag '"+l+"' can't have attributes or invalid starting.",E(t,a));if(0===r.length)return b("InvalidTag","Closing tag '"+l+"' has not been opened.",E(t,a));var w=r.pop();if(l!==w.tagName){var S=E(t,w.tagStartPos);return b("InvalidTag","Expected closing tag '"+w.tagName+"' (opened in line "+S.line+", col "+S.col+") instead of closing tag '"+l+"'.",E(t,a))}0==r.length&&(n=!0)}else{var _=v(f,e);if(!0!==_)return b(_.err.code,_.err.msg,E(t,s-f.length+_.err.line));if(!0===n)return b("InvalidXml","Multiple possible root nodes found.",E(t,s));-1!==e.unpairedTags.indexOf(l)||r.push({tagName:l,tagStartPos:a}),i=!0}for(s++;s<t.length;s++)if("<"===t[s]){if("!"===t[s+1]){s=d(t,++s);continue}if("?"!==t[s+1])break;if((s=p(t,++s)).err)return s}else if("&"===t[s]){var A=x(t,s);if(-1==A)return b("InvalidChar","char '&' is not expected.",E(t,s));s=A}else if(!0===n&&!u(t[s]))return b("InvalidXml","Extra text at the end",E(t,s));"<"===t[s]&&s--}return i?1==r.length?b("InvalidTag","Unclosed tag '"+r[0].tagName+"'.",E(t,r[0].tagStartPos)):!(r.length>0)||b("InvalidXml","Invalid '"+JSON.stringify(r.map(function(t){return t.tagName}),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1}):b("InvalidXml","Start tag expected.",1)}function u(t){return" "===t||"\t"===t||"\n"===t||"\r"===t}function p(t,e){for(var r=e;e<t.length;e++)if("?"!=t[e]&&" "!=t[e]);else{var i=t.substr(r,e-r);if(e>5&&"xml"===i)return b("InvalidXml","XML declaration allowed only at the start of the document.",E(t,e));if("?"==t[e]&&">"==t[e+1]){e++;break}}return e}function d(t,e){if(t.length>e+5&&"-"===t[e+1]&&"-"===t[e+2]){for(e+=3;e<t.length;e++)if("-"===t[e]&&"-"===t[e+1]&&">"===t[e+2]){e+=2;break}}else if(t.length>e+8&&"D"===t[e+1]&&"O"===t[e+2]&&"C"===t[e+3]&&"T"===t[e+4]&&"Y"===t[e+5]&&"P"===t[e+6]&&"E"===t[e+7]){var r=1;for(e+=8;e<t.length;e++)if("<"===t[e])r++;else if(">"===t[e]&&0===--r)break}else if(t.length>e+9&&"["===t[e+1]&&"C"===t[e+2]&&"D"===t[e+3]&&"A"===t[e+4]&&"T"===t[e+5]&&"A"===t[e+6]&&"["===t[e+7])for(e+=8;e<t.length;e++)if("]"===t[e]&&"]"===t[e+1]&&">"===t[e+2]){e+=2;break}return e}var c='"',f="'";function g(t,e){for(var r="",i="",n=!1;e<t.length;e++){if(t[e]===c||t[e]===f)""===i?i=t[e]:i!==t[e]||(i="");else if(">"===t[e]&&""===i){n=!0;break}r+=t[e]}return""===i&&{value:r,index:e,tagClosed:n}}var m=new RegExp("(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['\"])(([\\s\\S])*?)\\5)?","g");function v(t,e){for(var r=n(t,m),i={},s=0;s<r.length;s++){if(0===r[s][1].length)return b("InvalidAttr","Attribute '"+r[s][2]+"' has no space in starting.",w(r[s]));if(void 0!==r[s][3]&&void 0===r[s][4])return b("InvalidAttr","Attribute '"+r[s][2]+"' is without value.",w(r[s]));if(void 0===r[s][3]&&!e.allowBooleanAttributes)return b("InvalidAttr","boolean attribute '"+r[s][2]+"' is not allowed.",w(r[s]));var a=r[s][2];if(!N(a))return b("InvalidAttr","Attribute '"+a+"' is an invalid name.",w(r[s]));if(Object.prototype.hasOwnProperty.call(i,a))return b("InvalidAttr","Attribute '"+a+"' is repeated.",w(r[s]));i[a]=1}return!0}function x(t,e){if(";"===t[++e])return-1;if("#"===t[e])return function(t,e){var r=/\d/;for("x"===t[e]&&(e++,r=/[\da-fA-F]/);e<t.length;e++){if(";"===t[e])return e;if(!t[e].match(r))break}return-1}(t,++e);for(var r=0;e<t.length;e++,r++)if(!(t[e].match(/\w/)&&r<20)){if(";"===t[e])break;return-1}return e}function b(t,e,r){return{err:{code:t,msg:e,line:r.line||r,col:r.col}}}function N(t){return s(t)}function y(t){return s(t)}function E(t,e){var r=t.substring(0,e).split(/\r?\n/);return{line:r.length,col:r[r.length-1].length+1}}function w(t){return t.startIndex+t[1].length}var S=function(t){return a.includes(t)?"__"+t:t},_={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(t,e){return e},attributeValueProcessor:function(t,e){return e},stopNodes:[],alwaysCreateTextNode:!1,isArray:function(){return!1},commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,entityDecoder:null,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(t,e,r){return t},captureMetaData:!1,maxNestedTags:100,strictReservedNames:!0,jPath:!0,onDangerousProperty:S};function A(t,e){if("string"==typeof t){var r=t.toLowerCase();if(a.some(function(t){return r===t.toLowerCase()}))throw new Error("[SECURITY] Invalid "+e+': "'+t+'" is a reserved JavaScript keyword that could cause prototype pollution');if(o.some(function(t){return r===t.toLowerCase()}))throw new Error("[SECURITY] Invalid "+e+': "'+t+'" is a reserved JavaScript keyword that could cause prototype pollution')}}function T(t,e){return"boolean"==typeof t?{enabled:t,maxEntitySize:1e4,maxExpansionDepth:1e4,maxTotalExpansions:1/0,maxExpandedLength:1e5,maxEntityCount:1e3,allowedTags:null,tagFilter:null,appliesTo:"all"}:"object"==typeof t&&null!==t?{enabled:!1!==t.enabled,maxEntitySize:Math.max(1,null!=(r=t.maxEntitySize)?r:1e4),maxExpansionDepth:Math.max(1,null!=(i=t.maxExpansionDepth)?i:1e4),maxTotalExpansions:Math.max(1,null!=(n=t.maxTotalExpansions)?n:1/0),maxExpandedLength:Math.max(1,null!=(s=t.maxExpandedLength)?s:1e5),maxEntityCount:Math.max(1,null!=(a=t.maxEntityCount)?a:1e3),allowedTags:null!=(o=t.allowedTags)?o:null,tagFilter:null!=(h=t.tagFilter)?h:null,appliesTo:null!=(l=t.appliesTo)?l:"all"}:T(!0);var r,i,n,s,a,o,h,l}var C,P=function(t){for(var e=Object.assign({},_,t),r=0,i=[{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"}];r<i.length;r++){var n=i[r],s=n.value,a=n.name;s&&A(s,a)}return null===e.onDangerousProperty&&(e.onDangerousProperty=S),e.processEntities=T(e.processEntities,e.htmlEntities),e.unpairedTagsSet=new Set(e.unpairedTags),e.stopNodes&&Array.isArray(e.stopNodes)&&(e.stopNodes=e.stopNodes.map(function(t){return"string"==typeof t&&t.startsWith("*.")?".."+t.substring(2):t})),e};C="function"!=typeof Symbol?"@@xmlMetadata":Symbol("XML Node Metadata");var O=function(){function t(t){this.tagname=t,this.child=[],this[":@"]=Object.create(null)}var e=t.prototype;return e.add=function(t,e){var r;"__proto__"===t&&(t="#__proto__"),this.child.push(((r={})[t]=e,r))},e.addChild=function(t,e){var r,i;"__proto__"===t.tagname&&(t.tagname="#__proto__"),t[":@"]&&Object.keys(t[":@"]).length>0?this.child.push(((r={})[t.tagname]=t.child,r[":@"]=t[":@"],r)):this.child.push(((i={})[t.tagname]=t.child,i)),void 0!==e&&(this.child[this.child.length-1][C]={startIndex:e})},t.getMetaDataSymbol=function(){return C},t}(),I=function(){function t(t){this.suppressValidationErr=!t,this.options=t}var e=t.prototype;return e.readDocType=function(t,e){var r=Object.create(null),i=0;if("O"!==t[e+3]||"C"!==t[e+4]||"T"!==t[e+5]||"Y"!==t[e+6]||"P"!==t[e+7]||"E"!==t[e+8])throw new Error("Invalid Tag instead of DOCTYPE");e+=9;for(var n=1,s=!1,a=!1;e<t.length;e++)if("<"!==t[e]||a)if(">"===t[e]){if(a?"-"===t[e-1]&&"-"===t[e-2]&&(a=!1,n--):n--,0===n)break}else"["===t[e]?s=!0:t[e];else{if(s&&D(t,"!ENTITY",e)){e+=7;var o,h=void 0,l=this.readEntityExp(t,e+1,this.suppressValidationErr);if(o=l[0],h=l[1],e=l[2],-1===h.indexOf("&")){if(!1!==this.options.enabled&&null!=this.options.maxEntityCount&&i>=this.options.maxEntityCount)throw new Error("Entity count ("+(i+1)+") exceeds maximum allowed ("+this.options.maxEntityCount+")");r[o]=h,i++}}else if(s&&D(t,"!ELEMENT",e))e+=8,e=this.readElementExp(t,e+1).index;else if(s&&D(t,"!ATTLIST",e))e+=8;else if(s&&D(t,"!NOTATION",e))e+=9,e=this.readNotationExp(t,e+1,this.suppressValidationErr).index;else{if(!D(t,"!--",e))throw new Error("Invalid DOCTYPE");a=!0}n++}if(0!==n)throw new Error("Unclosed DOCTYPE");return{entities:r,i:e}},e.readEntityExp=function(t,e){for(var r=e=j(t,e);e<t.length&&!/\s/.test(t[e])&&'"'!==t[e]&&"'"!==t[e];)e++;var i=t.substring(r,e);if($(i),e=j(t,e),!this.suppressValidationErr){if("SYSTEM"===t.substring(e,e+6).toUpperCase())throw new Error("External entities are not supported");if("%"===t[e])throw new Error("Parameter entities are not supported")}var n,s=this.readIdentifierVal(t,e,"entity");if(e=s[0],n=s[1],!1!==this.options.enabled&&null!=this.options.maxEntitySize&&n.length>this.options.maxEntitySize)throw new Error('Entity "'+i+'" size ('+n.length+") exceeds maximum allowed size ("+this.options.maxEntitySize+")");return[i,n,--e]},e.readNotationExp=function(t,e){for(var r=e=j(t,e);e<t.length&&!/\s/.test(t[e]);)e++;var i=t.substring(r,e);!this.suppressValidationErr&&$(i),e=j(t,e);var n=t.substring(e,e+6).toUpperCase();if(!this.suppressValidationErr&&"SYSTEM"!==n&&"PUBLIC"!==n)throw new Error('Expected SYSTEM or PUBLIC, found "'+n+'"');e+=n.length,e=j(t,e);var s=null,a=null;if("PUBLIC"===n){var o=this.readIdentifierVal(t,e,"publicIdentifier");if(e=o[0],s=o[1],'"'===t[e=j(t,e)]||"'"===t[e]){var h=this.readIdentifierVal(t,e,"systemIdentifier");e=h[0],a=h[1]}}else if("SYSTEM"===n){var l=this.readIdentifierVal(t,e,"systemIdentifier");if(e=l[0],a=l[1],!this.suppressValidationErr&&!a)throw new Error("Missing mandatory system identifier for SYSTEM notation")}return{notationName:i,publicIdentifier:s,systemIdentifier:a,index:--e}},e.readIdentifierVal=function(t,e,r){var i,n=t[e];if('"'!==n&&"'"!==n)throw new Error('Expected quoted string, found "'+n+'"');for(var s=++e;e<t.length&&t[e]!==n;)e++;if(i=t.substring(s,e),t[e]!==n)throw new Error("Unterminated "+r+" value");return[++e,i]},e.readElementExp=function(t,e){for(var r=e=j(t,e);e<t.length&&!/\s/.test(t[e]);)e++;var i=t.substring(r,e);if(!this.suppressValidationErr&&!s(i))throw new Error('Invalid element name: "'+i+'"');var n="";if("E"===t[e=j(t,e)]&&D(t,"MPTY",e))e+=4;else if("A"===t[e]&&D(t,"NY",e))e+=2;else if("("===t[e]){for(var a=++e;e<t.length&&")"!==t[e];)e++;if(n=t.substring(a,e),")"!==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:n.trim(),index:e}},e.readAttlistExp=function(t,e){for(var r=e=j(t,e);e<t.length&&!/\s/.test(t[e]);)e++;var i=t.substring(r,e);for($(i),r=e=j(t,e);e<t.length&&!/\s/.test(t[e]);)e++;var n=t.substring(r,e);if(!$(n))throw new Error('Invalid attribute name: "'+n+'"');e=j(t,e);var s="";if("NOTATION"===t.substring(e,e+8).toUpperCase()){if(s="NOTATION","("!==t[e=j(t,e+=8)])throw new Error("Expected '(', found \""+t[e]+'"');e++;for(var a=[];e<t.length&&")"!==t[e];){for(var o=e;e<t.length&&"|"!==t[e]&&")"!==t[e];)e++;var h=t.substring(o,e);if(!$(h=h.trim()))throw new Error('Invalid notation name: "'+h+'"');a.push(h),"|"===t[e]&&(e++,e=j(t,e))}if(")"!==t[e])throw new Error("Unterminated list of notations");e++,s+=" ("+a.join("|")+")"}else{for(var l=e;e<t.length&&!/\s/.test(t[e]);)e++;if(s+=t.substring(l,e),!this.suppressValidationErr&&!["CDATA","ID","IDREF","IDREFS","ENTITY","ENTITIES","NMTOKEN","NMTOKENS"].includes(s.toUpperCase()))throw new Error('Invalid attribute type: "'+s+'"')}e=j(t,e);var u="";if("#REQUIRED"===t.substring(e,e+8).toUpperCase())u="#REQUIRED",e+=8;else if("#IMPLIED"===t.substring(e,e+7).toUpperCase())u="#IMPLIED",e+=7;else{var p=this.readIdentifierVal(t,e,"ATTLIST");e=p[0],u=p[1]}return{elementName:i,attributeName:n,attributeType:s,defaultValue:u,index:e}},t}(),j=function(t,e){for(;e<t.length&&/\s/.test(t[e]);)e++;return e};function D(t,e,r){for(var i=0;i<e.length;i++)if(e[i]!==t[r+i+1])return!1;return!0}function $(t){if(s(t))return t;throw new Error("Invalid entity name "+t)}const M=/^[-+]?0x[a-fA-F0-9]+$/,V=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,L={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0,infinity:"original"};const k=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;function F(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,i=Array(e);r<e;r++)i[r]=t[r];return i}class R{constructor(t){this._matcher=t}get separator(){return this._matcher.separator}getCurrentTag(){const t=this._matcher.path;return t.length>0?t[t.length-1].tag:void 0}getCurrentNamespace(){const t=this._matcher.path;return t.length>0?t[t.length-1].namespace:void 0}getAttrValue(t){const e=this._matcher.path;if(0!==e.length)return e[e.length-1].values?.[t]}hasAttr(t){const e=this._matcher.path;if(0===e.length)return!1;const r=e[e.length-1];return void 0!==r.values&&t in r.values}getPosition(){const t=this._matcher.path;return 0===t.length?-1:t[t.length-1].position??0}getCounter(){const t=this._matcher.path;return 0===t.length?-1:t[t.length-1].counter??0}getIndex(){return this.getPosition()}getDepth(){return this._matcher.path.length}toString(t,e=!0){return this._matcher.toString(t,e)}toArray(){return this._matcher.path.map(t=>t.tag)}matches(t){return this._matcher.matches(t)}matchesAny(t){return t.matchesAny(this._matcher)}}class G{constructor(t={}){this.separator=t.separator||".",this.path=[],this.siblingStacks=[],this._pathStringCache=null,this._view=new R(this)}push(t,e=null,r=null){this._pathStringCache=null,this.path.length>0&&(this.path[this.path.length-1].values=void 0);const i=this.path.length;this.siblingStacks[i]||(this.siblingStacks[i]=new Map);const n=this.siblingStacks[i],s=r?`${r}:${t}`:t,a=n.get(s)||0;let o=0;for(const t of n.values())o+=t;n.set(s,a+1);const h={tag:t,position:o,counter:a};null!=r&&(h.namespace=r),null!=e&&(h.values=e),this.path.push(h)}pop(){if(0===this.path.length)return;this._pathStringCache=null;const t=this.path.pop();return this.siblingStacks.length>this.path.length+1&&(this.siblingStacks.length=this.path.length+1),t}updateCurrent(t){if(this.path.length>0){const e=this.path[this.path.length-1];null!=t&&(e.values=t)}}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(t){if(0!==this.path.length)return this.path[this.path.length-1].values?.[t]}hasAttr(t){if(0===this.path.length)return!1;const e=this.path[this.path.length-1];return void 0!==e.values&&t in e.values}getPosition(){return 0===this.path.length?-1:this.path[this.path.length-1].position??0}getCounter(){return 0===this.path.length?-1:this.path[this.path.length-1].counter??0}getIndex(){return this.getPosition()}getDepth(){return this.path.length}toString(t,e=!0){const r=t||this.separator;if(r===this.separator&&!0===e){if(null!==this._pathStringCache)return this._pathStringCache;const t=this.path.map(t=>t.namespace?`${t.namespace}:${t.tag}`:t.tag).join(r);return this._pathStringCache=t,t}return this.path.map(t=>e&&t.namespace?`${t.namespace}:${t.tag}`:t.tag).join(r)}toArray(){return this.path.map(t=>t.tag)}reset(){this._pathStringCache=null,this.path=[],this.siblingStacks=[]}matches(t){const e=t.segments;return 0!==e.length&&(t.hasDeepWildcard()?this._matchWithDeepWildcard(e):this._matchSimple(e))}_matchSimple(t){if(this.path.length!==t.length)return!1;for(let e=0;e<t.length;e++)if(!this._matchSegment(t[e],this.path[e],e===this.path.length-1))return!1;return!0}_matchWithDeepWildcard(t){let e=this.path.length-1,r=t.length-1;for(;r>=0&&e>=0;){const i=t[r];if("deep-wildcard"===i.type){if(r--,r<0)return!0;const i=t[r];let n=!1;for(let t=e;t>=0;t--)if(this._matchSegment(i,this.path[t],t===this.path.length-1)){e=t-1,r--,n=!0;break}if(!n)return!1}else{if(!this._matchSegment(i,this.path[e],e===this.path.length-1))return!1;e--,r--}}return r<0}_matchSegment(t,e,r){if("*"!==t.tag&&t.tag!==e.tag)return!1;if(void 0!==t.namespace&&"*"!==t.namespace&&t.namespace!==e.namespace)return!1;if(void 0!==t.attrName){if(!r)return!1;if(!e.values||!(t.attrName in e.values))return!1;if(void 0!==t.attrValue&&String(e.values[t.attrName])!==String(t.attrValue))return!1}if(void 0!==t.position){if(!r)return!1;const i=e.counter??0;if("first"===t.position&&0!==i)return!1;if("odd"===t.position&&i%2!=1)return!1;if("even"===t.position&&i%2!=0)return!1;if("nth"===t.position&&i!==t.positionValue)return!1}return!0}matchesAny(t){return t.matchesAny(this)}snapshot(){return{path:this.path.map(t=>({...t})),siblingStacks:this.siblingStacks.map(t=>new Map(t))}}restore(t){this._pathStringCache=null,this.path=t.path.map(t=>({...t})),this.siblingStacks=t.siblingStacks.map(t=>new Map(t))}readOnly(){return this._view}}class U{constructor(t,e={},r){this.pattern=t,this.separator=e.separator||".",this.segments=this._parse(t),this.data=r,this._hasDeepWildcard=this.segments.some(t=>"deep-wildcard"===t.type),this._hasAttributeCondition=this.segments.some(t=>void 0!==t.attrName),this._hasPositionSelector=this.segments.some(t=>void 0!==t.position)}_parse(t){const e=[];let r=0,i="";for(;r<t.length;)t[r]===this.separator?r+1<t.length&&t[r+1]===this.separator?(i.trim()&&(e.push(this._parseSegment(i.trim())),i=""),e.push({type:"deep-wildcard"}),r+=2):(i.trim()&&e.push(this._parseSegment(i.trim())),i="",r++):(i+=t[r],r++);return i.trim()&&e.push(this._parseSegment(i.trim())),e}_parseSegment(t){const e={type:"tag"};let r=null,i=t;const n=t.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);if(n&&(i=n[1]+n[3],n[2])){const t=n[2].slice(1,-1);t&&(r=t)}let s,a,o=i;if(i.includes("::")){const e=i.indexOf("::");if(s=i.substring(0,e).trim(),o=i.substring(e+2).trim(),!s)throw new Error(`Invalid namespace in pattern: ${t}`)}let h=null;if(o.includes(":")){const t=o.lastIndexOf(":"),e=o.substring(0,t).trim(),r=o.substring(t+1).trim();["first","last","odd","even"].includes(r)||/^nth\(\d+\)$/.test(r)?(a=e,h=r):a=o}else a=o;if(!a)throw new Error(`Invalid segment pattern: ${t}`);if(e.tag=a,s&&(e.namespace=s),r)if(r.includes("=")){const t=r.indexOf("=");e.attrName=r.substring(0,t).trim(),e.attrValue=r.substring(t+1).trim()}else e.attrName=r.trim();if(h){const t=h.match(/^nth\((\d+)\)$/);t?(e.position="nth",e.positionValue=parseInt(t[1],10)):e.position=h}return e}get length(){return this.segments.length}hasDeepWildcard(){return this._hasDeepWildcard}hasAttributeCondition(){return this._hasAttributeCondition}hasPositionSelector(){return this._hasPositionSelector}toString(){return this.pattern}}class B{constructor(){this._byDepthAndTag=new Map,this._wildcardByDepth=new Map,this._deepWildcards=[],this._patterns=new Set,this._sealed=!1}add(t){if(this._sealed)throw new TypeError("ExpressionSet is sealed. Create a new ExpressionSet to add more expressions.");if(this._patterns.has(t.pattern))return this;if(this._patterns.add(t.pattern),t.hasDeepWildcard())return this._deepWildcards.push(t),this;const e=t.length,r=t.segments[t.segments.length-1],i=r?.tag;if(i&&"*"!==i){const r=`${e}:${i}`;this._byDepthAndTag.has(r)||this._byDepthAndTag.set(r,[]),this._byDepthAndTag.get(r).push(t)}else this._wildcardByDepth.has(e)||this._wildcardByDepth.set(e,[]),this._wildcardByDepth.get(e).push(t);return this}addAll(t){for(const e of t)this.add(e);return this}has(t){return this._patterns.has(t.pattern)}get size(){return this._patterns.size}seal(){return this._sealed=!0,this}get isSealed(){return this._sealed}matchesAny(t){return null!==this.findMatch(t)}findMatch(t){const e=t.getDepth(),r=`${e}:${t.getCurrentTag()}`,i=this._byDepthAndTag.get(r);if(i)for(let e=0;e<i.length;e++)if(t.matches(i[e]))return i[e];const n=this._wildcardByDepth.get(e);if(n)for(let e=0;e<n.length;e++)if(t.matches(n[e]))return n[e];for(let e=0;e<this._deepWildcards.length;e++)if(t.matches(this._deepWildcards[e]))return this._deepWildcards[e];return null}}const W={cent:"¢",pound:"£",curren:"¤",yen:"¥",euro:"€",dollar:"$",euro:"€",fnof:"ƒ",inr:"₹",af:"؋",birr:"ብር",peso:"₱",rub:"₽",won:"₩",yuan:"¥",cedil:"¸"},X={amp:"&",apos:"'",gt:">",lt:"<",quot:'"'},Y={nbsp:" ",copy:"©",reg:"®",trade:"™",mdash:"—",ndash:"–",hellip:"…",laquo:"«",raquo:"»",lsquo:"‘",rsquo:"’",ldquo:"“",rdquo:"”",bull:"•",para:"¶",sect:"§",deg:"°",frac12:"½",frac14:"¼",frac34:"¾"},z=new Set("!?\\\\/[]$%{}^&*()<>|+");function q(t){if("#"===t[0])throw new Error(`[EntityReplacer] Invalid character '#' in entity name: "${t}"`);for(const e of t)if(z.has(e))throw new Error(`[EntityReplacer] Invalid character '${e}' in entity name: "${t}"`);return t}function Z(...t){const e=Object.create(null);for(const r of t)if(r)for(const t of Object.keys(r)){const i=r[t];if("string"==typeof i)e[t]=i;else if(i&&"object"==typeof i&&void 0!==i.val){const r=i.val;"string"==typeof r&&(e[t]=r)}}return e}const J="external",K="base",Q="all",H=Object.freeze({allow:0,leave:1,remove:2,throw:3}),tt=new Set([9,10,13]);class et{constructor(t={}){var e;this._limit=t.limit||{},this._maxTotalExpansions=this._limit.maxTotalExpansions||0,this._maxExpandedLength=this._limit.maxExpandedLength||0,this._postCheck="function"==typeof t.postCheck?t.postCheck:t=>t,this._limitTiers=(e=this._limit.applyLimitsTo??J)&&e!==J?e===Q?new Set([Q]):e===K?new Set([K]):Array.isArray(e)?new Set(e):new Set([J]):new Set([J]),this._numericAllowed=t.numericAllowed??!0,this._baseMap=Z(X,t.namedEntities||null),this._externalMap=Object.create(null),this._inputMap=Object.create(null),this._totalExpansions=0,this._expandedLength=0,this._removeSet=new Set(t.remove&&Array.isArray(t.remove)?t.remove:[]),this._leaveSet=new Set(t.leave&&Array.isArray(t.leave)?t.leave:[]);const r=function(t){if(!t)return{xmlVersion:1,onLevel:H.allow,nullLevel:H.remove};const e=1.1===t.xmlVersion?1.1:1,r=H[t.onNCR]??H.allow,i=H[t.nullNCR]??H.remove;return{xmlVersion:e,onLevel:r,nullLevel:Math.max(i,H.remove)}}(t.ncr);this._ncrXmlVersion=r.xmlVersion,this._ncrOnLevel=r.onLevel,this._ncrNullLevel=r.nullLevel}setExternalEntities(t){if(t)for(const e of Object.keys(t))q(e);this._externalMap=Z(t)}addExternalEntity(t,e){q(t),"string"==typeof e&&-1===e.indexOf("&")&&(this._externalMap[t]=e)}addInputEntities(t){this._totalExpansions=0,this._expandedLength=0,this._inputMap=Z(t)}reset(){return this._inputMap=Object.create(null),this._totalExpansions=0,this._expandedLength=0,this}setXmlVersion(t){this._ncrXmlVersion=1.1===t?1.1:1}decode(t){if("string"!=typeof t||0===t.length)return t;const e=t,r=[],i=t.length;let n=0,s=0;const a=this._maxTotalExpansions>0,o=this._maxExpandedLength>0,h=a||o;for(;s<i;){if(38!==t.charCodeAt(s)){s++;continue}let e=s+1;for(;e<i&&59!==t.charCodeAt(e)&&e-s<=32;)e++;if(e>=i||59!==t.charCodeAt(e)){s++;continue}const l=t.slice(s+1,e);if(0===l.length){s++;continue}let u,p;if(this._removeSet.has(l))u="",void 0===p&&(p=J);else{if(this._leaveSet.has(l)){s++;continue}if(35===l.charCodeAt(0)){const t=this._resolveNCR(l);if(void 0===t){s++;continue}u=t,p=K}else{const t=this._resolveName(l);u=t?.value,p=t?.tier}}if(void 0!==u){if(s>n&&r.push(t.slice(n,s)),r.push(u),n=e+1,s=n,h&&this._tierCounts(p)){if(a&&(this._totalExpansions++,this._totalExpansions>this._maxTotalExpansions))throw new Error(`[EntityReplacer] Entity expansion count limit exceeded: ${this._totalExpansions} > ${this._maxTotalExpansions}`);if(o){const t=u.length-(l.length+2);if(t>0&&(this._expandedLength+=t,this._expandedLength>this._maxExpandedLength))throw new Error(`[EntityReplacer] Expanded content length limit exceeded: ${this._expandedLength} > ${this._maxExpandedLength}`)}}}else s++}n<i&&r.push(t.slice(n));const l=0===r.length?t:r.join("");return this._postCheck(l,e)}_tierCounts(t){return!!this._limitTiers.has(Q)||this._limitTiers.has(t)}_resolveName(t){return t in this._inputMap?{value:this._inputMap[t],tier:J}:t in this._externalMap?{value:this._externalMap[t],tier:J}:t in this._baseMap?{value:this._baseMap[t],tier:K}:void 0}_classifyNCR(t){return 0===t?this._ncrNullLevel:t>=55296&&t<=57343||1===this._ncrXmlVersion&&t>=1&&t<=31&&!tt.has(t)?H.remove:-1}_applyNCRAction(t,e,r){switch(t){case H.allow:return String.fromCodePoint(r);case H.remove:return"";case H.leave:return;case H.throw:throw new Error(`[EntityDecoder] Prohibited numeric character reference &${e}; (U+${r.toString(16).toUpperCase().padStart(4,"0")})`);default:return String.fromCodePoint(r)}}_resolveNCR(t){const e=t.charCodeAt(1);let r;if(r=120===e||88===e?parseInt(t.slice(2),16):parseInt(t.slice(1),10),Number.isNaN(r)||r<0||r>1114111)return;const i=this._classifyNCR(r);if(!this._numericAllowed&&i<H.remove)return;const n=-1===i?this._ncrOnLevel:Math.max(this._ncrOnLevel,i);return this._applyNCRAction(n,t,r)}}function rt(){return rt=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var i in r)({}).hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t},rt.apply(null,arguments)}function it(t,e){if(!t)return{};var r=e.attributesGroupName?t[e.attributesGroupName]:t;if(!r)return{};var i={};for(var n in r)n.startsWith(e.attributeNamePrefix)?i[n.substring(e.attributeNamePrefix.length)]=r[n]:i[n]=r[n];return i}function nt(t){if(t&&"string"==typeof t){var e=t.indexOf(":");if(-1!==e&&e>0){var r=t.substring(0,e);if("xmlns"!==r)return r}}}var st=function(t){var e;this.options=t,this.currentNode=null,this.tagsNodeStack=[],this.parseXml=ut,this.parseTextData=at,this.resolveNameSpace=ot,this.buildAttributesMap=lt,this.isItStopNode=ft,this.replaceEntitiesValue=dt,this.readStopNodeData=xt,this.saveTextToParentTag=ct,this.addChild=pt,this.ignoreAttributesFn="function"==typeof(e=this.options.ignoreAttributes)?e:Array.isArray(e)?function(t){for(var r,i=function(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return F(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?F(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e);!(r=i()).done;){var n=r.value;if("string"==typeof n&&t===n)return!0;if(n instanceof RegExp&&n.test(t))return!0}}:function(){return!1},this.entityExpansionCount=0,this.currentExpandedLength=0;var r=rt({},X);this.options.entityDecoder?this.entityDecoder=this.options.entityDecoder:("object"==typeof this.options.htmlEntities?r=this.options.htmlEntities:!0===this.options.htmlEntities&&(r=rt({},Y,W)),this.entityDecoder=new et({namedEntities:r,numericAllowed:this.options.htmlEntities,limit:{maxTotalExpansions:this.options.processEntities.maxTotalExpansions,maxExpandedLength:this.options.processEntities.maxExpandedLength,applyLimitsTo:this.options.processEntities.appliesTo}})),this.matcher=new G,this.readonlyMatcher=this.matcher.readOnly(),this.isCurrentNodeStopNode=!1,this.stopNodeExpressionsSet=new B;var i=this.options.stopNodes;if(i&&i.length>0){for(var n=0;n<i.length;n++){var s=i[n];"string"==typeof s?this.stopNodeExpressionsSet.add(new U(s)):s instanceof U&&this.stopNodeExpressionsSet.add(s)}this.stopNodeExpressionsSet.seal()}};function at(t,e,r,i,n,s,a){var o=this.options;if(void 0!==t&&(o.trimValues&&!i&&(t=t.trim()),t.length>0)){a||(t=this.replaceEntitiesValue(t,e,r));var h=o.jPath?r.toString():r,l=o.tagValueProcessor(e,t,h,n,s);return null==l?t:typeof l!=typeof t||l!==t?l:o.trimValues||t.trim()===t?bt(t,o.parseTagValue,o.numberParseOptions):t}}function ot(t){if(this.options.removeNSPrefix){var e=t.split(":"),r="/"===t.charAt(0)?"/":"";if("xmlns"===e[0])return"";2===e.length&&(t=r+e[1])}return t}var ht=new RegExp("([^\\s=]+)\\s*(=\\s*(['\"])([\\s\\S]*?)\\3)?","gm");function lt(t,e,r,i){void 0===i&&(i=!1);var s=this.options;if(!0===i||!0!==s.ignoreAttributes&&"string"==typeof t){for(var a=n(t,ht),o=a.length,h={},l=new Array(o),u=!1,p={},d=0;d<o;d++){var c=this.resolveNameSpace(a[d][1]),f=a[d][4];if(c.length&&void 0!==f){var g=f;s.trimValues&&(g=g.trim()),g=this.replaceEntitiesValue(g,r,this.readonlyMatcher),l[d]=g,p[c]=g,u=!0}}u&&"object"==typeof e&&e.updateCurrent&&e.updateCurrent(p);for(var m=s.jPath?e.toString():this.readonlyMatcher,v=!1,x=0;x<o;x++){var b=this.resolveNameSpace(a[x][1]);if(!this.ignoreAttributesFn(b,m)){var N=s.attributeNamePrefix+b;if(b.length)if(s.transformAttributeName&&(N=s.transformAttributeName(N)),N=yt(N,s),void 0!==a[x][4]){var y=l[x],E=s.attributeValueProcessor(b,y,m);h[N]=null==E?y:typeof E!=typeof y||E!==y?E:bt(y,s.parseAttributeValue,s.numberParseOptions),v=!0}else s.allowBooleanAttributes&&(h[N]=!0,v=!0)}}if(!v)return;if(s.attributesGroupName){var w={};return w[s.attributesGroupName]=h,w}return h}}var ut=function(t){t=t.replace(/\r\n?/g,"\n");var e=new O("!xml"),r=e,i="";this.matcher.reset(),this.entityDecoder.reset(),this.entityExpansionCount=0,this.currentExpandedLength=0;for(var n=this.options,s=new I(n.processEntities),a=t.length,o=0;o<a;o++)if("<"===t[o]){var h=t.charCodeAt(o+1);if(47===h){var l=gt(t,">",o,"Closing Tag is not closed."),u=t.substring(o+2,l).trim();if(n.removeNSPrefix){var p=u.indexOf(":");-1!==p&&(u=u.substr(p+1))}u=Nt(n.transformTagName,u,"",n).tagName,r&&(i=this.saveTextToParentTag(i,r,this.readonlyMatcher));var d=this.matcher.getCurrentTag();if(u&&n.unpairedTagsSet.has(u))throw new Error("Unpaired tag can not be used as closing tag: </"+u+">");d&&n.unpairedTagsSet.has(d)&&(this.matcher.pop(),this.tagsNodeStack.pop()),this.matcher.pop(),this.isCurrentNodeStopNode=!1,r=this.tagsNodeStack.pop(),i="",o=l}else if(63===h){var c=vt(t,o,!1,"?>");if(!c)throw new Error("Pi Tag is not closed.");i=this.saveTextToParentTag(i,r,this.readonlyMatcher);var f=this.buildAttributesMap(c.tagExp,this.matcher,c.tagName,!0);if(f){var g=f[this.options.attributeNamePrefix+"version"];this.entityDecoder.setXmlVersion(Number(g)||1)}if(n.ignoreDeclaration&&"?xml"===c.tagName||n.ignorePiTags);else{var m=new O(c.tagName);m.add(n.textNodeName,""),c.tagName!==c.tagExp&&c.attrExpPresent&&!0!==n.ignoreAttributes&&(m[":@"]=f),this.addChild(r,m,this.readonlyMatcher,o)}o=c.closeIndex+1}else if(33===h&&45===t.charCodeAt(o+2)&&45===t.charCodeAt(o+3)){var v=gt(t,"--\x3e",o+4,"Comment is not closed.");if(n.commentPropName){var x,b=t.substring(o+4,v-2);i=this.saveTextToParentTag(i,r,this.readonlyMatcher),r.add(n.commentPropName,[(x={},x[n.textNodeName]=b,x)])}o=v}else if(33===h&&68===t.charCodeAt(o+2)){var N=s.readDocType(t,o);this.entityDecoder.addInputEntities(N.entities),o=N.i}else if(33===h&&91===t.charCodeAt(o+2)){var y=gt(t,"]]>",o,"CDATA is not closed.")-2,E=t.substring(o+9,y);i=this.saveTextToParentTag(i,r,this.readonlyMatcher);var w,S=this.parseTextData(E,r.tagname,this.readonlyMatcher,!0,!1,!0,!0);null==S&&(S=""),n.cdataPropName?r.add(n.cdataPropName,[(w={},w[n.textNodeName]=E,w)]):r.add(n.textNodeName,S),o=y+2}else{var _=vt(t,o,n.removeNSPrefix);if(!_){var A=t.substring(Math.max(0,o-50),Math.min(a,o+50));throw new Error("readTagExp returned undefined at position "+o+'. Context: "'+A+'"')}var T=_.tagName,C=_.rawTagName,P=_.tagExp,j=_.attrExpPresent,D=_.closeIndex,$=Nt(n.transformTagName,T,P,n);if(T=$.tagName,P=$.tagExp,n.strictReservedNames&&(T===n.commentPropName||T===n.cdataPropName||T===n.textNodeName||T===n.attributesGroupName))throw new Error("Invalid tag name: "+T);r&&i&&"!xml"!==r.tagname&&(i=this.saveTextToParentTag(i,r,this.readonlyMatcher,!1));var M=r;M&&n.unpairedTagsSet.has(M.tagname)&&(r=this.tagsNodeStack.pop(),this.matcher.pop());var V=!1;P.length>0&&P.lastIndexOf("/")===P.length-1&&(V=!0,P="/"===T[T.length-1]?T=T.substr(0,T.length-1):P.substr(0,P.length-1),j=T!==P);var L,k=null;L=nt(C),T!==e.tagname&&this.matcher.push(T,{},L),T!==P&&j&&(k=this.buildAttributesMap(P,this.matcher,T))&&it(k,n),T!==e.tagname&&(this.isCurrentNodeStopNode=this.isItStopNode());var F=o;if(this.isCurrentNodeStopNode){var R="";if(V)o=_.closeIndex;else if(n.unpairedTagsSet.has(T))o=_.closeIndex;else{var G=this.readStopNodeData(t,C,D+1);if(!G)throw new Error("Unexpected end of "+C);o=G.i,R=G.tagContent}var U=new O(T);k&&(U[":@"]=k),U.add(n.textNodeName,R),this.matcher.pop(),this.isCurrentNodeStopNode=!1,this.addChild(r,U,this.readonlyMatcher,F)}else{if(V){var B=Nt(n.transformTagName,T,P,n);T=B.tagName,P=B.tagExp;var W=new O(T);k&&(W[":@"]=k),this.addChild(r,W,this.readonlyMatcher,F),this.matcher.pop(),this.isCurrentNodeStopNode=!1}else{if(n.unpairedTagsSet.has(T)){var X=new O(T);k&&(X[":@"]=k),this.addChild(r,X,this.readonlyMatcher,F),this.matcher.pop(),this.isCurrentNodeStopNode=!1,o=_.closeIndex;continue}var Y=new O(T);if(this.tagsNodeStack.length>n.maxNestedTags)throw new Error("Maximum nested tags exceeded");this.tagsNodeStack.push(r),k&&(Y[":@"]=k),this.addChild(r,Y,this.readonlyMatcher,F),r=Y}i="",o=D}}}else i+=t[o];return e.child};function pt(t,e,r,i){this.options.captureMetaData||(i=void 0);var n=this.options.jPath?r.toString():r,s=this.options.updateTag(e.tagname,n,e[":@"]);!1===s||("string"==typeof s?(e.tagname=s,t.addChild(e,i)):t.addChild(e,i))}function dt(t,e,r){var i=this.options.processEntities;if(!i||!i.enabled)return t;if(i.allowedTags){var n=this.options.jPath?r.toString():r;if(!(Array.isArray(i.allowedTags)?i.allowedTags.includes(e):i.allowedTags(e,n)))return t}if(i.tagFilter){var s=this.options.jPath?r.toString():r;if(!i.tagFilter(e,s))return t}return this.entityDecoder.decode(t)}function ct(t,e,r,i){return t&&(void 0===i&&(i=0===e.child.length),void 0!==(t=this.parseTextData(t,e.tagname,r,!1,!!e[":@"]&&0!==Object.keys(e[":@"]).length,i))&&""!==t&&e.add(this.options.textNodeName,t),t=""),t}function ft(){return 0!==this.stopNodeExpressionsSet.size&&this.matcher.matchesAny(this.stopNodeExpressionsSet)}function gt(t,e,r,i){var n=t.indexOf(e,r);if(-1===n)throw new Error(i);return n+e.length-1}function mt(t,e,r,i){var n=t.indexOf(e,r);if(-1===n)throw new Error(i);return n}function vt(t,e,r,i){void 0===i&&(i=">");var n=function(t,e,r){void 0===r&&(r=">");for(var i=0,n=[],s=t.length,a=r.charCodeAt(0),o=r.length>1?r.charCodeAt(1):-1,h=e;h<s;h++){var l=t.charCodeAt(h);if(i)l===i&&(i=0);else if(34===l||39===l)i=l;else if(l===a){if(-1===o)return{data:String.fromCharCode.apply(String,n),index:h};if(t.charCodeAt(h+1)===o)return{data:String.fromCharCode.apply(String,n),index:h}}else if(9===l){n.push(32);continue}n.push(l)}}(t,e+1,i);if(n){var s=n.data,a=n.index,o=s.search(/\s/),h=s,l=!0;-1!==o&&(h=s.substring(0,o),s=s.substring(o+1).trimStart());var u=h;if(r){var p=h.indexOf(":");-1!==p&&(l=(h=h.substr(p+1))!==n.data.substr(p+1))}return{tagName:h,tagExp:s,closeIndex:a,attrExpPresent:l,rawTagName:u}}}function xt(t,e,r){for(var i=r,n=1,s=t.length;r<s;r++)if("<"===t[r]){var a=t.charCodeAt(r+1);if(47===a){var o=mt(t,">",r,e+" is not closed");if(t.substring(r+2,o).trim()===e&&0===--n)return{tagContent:t.substring(i,r),i:o};r=o}else if(63===a)r=gt(t,"?>",r+1,"StopNode is not closed.");else if(33===a&&45===t.charCodeAt(r+2)&&45===t.charCodeAt(r+3))r=gt(t,"--\x3e",r+3,"StopNode is not closed.");else if(33===a&&91===t.charCodeAt(r+2))r=gt(t,"]]>",r,"StopNode is not closed.")-2;else{var h=vt(t,r,">");h&&((h&&h.tagName)===e&&"/"!==h.tagExp[h.tagExp.length-1]&&n++,r=h.closeIndex)}}}function bt(t,e,r){if(e&&"string"==typeof t){var i=t.trim();return"true"===i||"false"!==i&&function(t,e={}){if(e=Object.assign({},L,e),!t||"string"!=typeof t)return t;let r=t.trim();if(0===r.length)return t;if(void 0!==e.skipLike&&e.skipLike.test(r))return t;if("0"===r)return 0;if(e.hex&&M.test(r))return function(t){if(parseInt)return parseInt(t,16);if(Number.parseInt)return Number.parseInt(t,16);if(window&&window.parseInt)return window.parseInt(t,16);throw new Error("parseInt, Number.parseInt, window.parseInt are not supported")}(r);if(isFinite(r)){if(r.includes("e")||r.includes("E"))return function(t,e,r){if(!r.eNotation)return t;const i=e.match(k);if(i){let n=i[1]||"";const s=-1===i[3].indexOf("e")?"E":"e",a=i[2],o=n?t[a.length+1]===s:t[a.length]===s;return a.length>1&&o?t:(1!==a.length||!i[3].startsWith(`.${s}`)&&i[3][0]!==s)&&a.length>0?r.leadingZeros&&!o?(e=(i[1]||"")+i[3],Number(e)):t:Number(e)}return t}(t,r,e);{const n=V.exec(r);if(n){const s=n[1]||"",a=n[2];let o=(i=n[3])&&-1!==i.indexOf(".")?("."===(i=i.replace(/0+$/,""))?i="0":"."===i[0]?i="0"+i:"."===i[i.length-1]&&(i=i.substring(0,i.length-1)),i):i;const h=s?"."===t[a.length+1]:"."===t[a.length];if(!e.leadingZeros&&(a.length>1||1===a.length&&!h))return t;{const i=Number(r),n=String(i);if(0===i)return i;if(-1!==n.search(/[eE]/))return e.eNotation?i:t;if(-1!==r.indexOf("."))return"0"===n||n===o||n===`${s}${o}`?i:t;let h=a?o:r;return a?h===n||s+h===n?i:t:h===n||h===s+n?i:t}}return t}}var i;return function(t,e,r){const i=e===1/0;switch(r.infinity.toLowerCase()){case"null":return null;case"infinity":return e;case"string":return i?"Infinity":"-Infinity";default:return t}}(t,Number(r),e)}(t,r)}return void 0!==t?t:""}function Nt(t,e,r,i){if(t){var n=t(e);r===e&&(r=n),e=n}return{tagName:e=yt(e,i),tagExp:r}}function yt(t,e){if(o.includes(t))throw new Error('[SECURITY] Invalid name: "'+t+'" is a reserved JavaScript keyword that could cause prototype pollution');return a.includes(t)?e.onDangerousProperty(t):t}var Et=O.getMetaDataSymbol();function wt(t,e){if(!t||"object"!=typeof t)return{};if(!e)return t;var r={};for(var i in t)i.startsWith(e)?r[i.substring(e.length)]=t[i]:r[i]=t[i];return r}function St(t,e,r,i){return _t(t,e,r,i)}function _t(t,e,r,i){for(var n,s={},a=0;a<t.length;a++){var o=t[a],h=At(o);if(void 0!==h&&h!==e.textNodeName){var l=wt(o[":@"]||{},e.attributeNamePrefix);r.push(h,l)}if(h===e.textNodeName)void 0===n?n=o[h]:n+=""+o[h];else{if(void 0===h)continue;if(o[h]){var u=_t(o[h],e,r,i),p=Ct(u,e);if(o[":@"]?Tt(u,o[":@"],i,e):1!==Object.keys(u).length||void 0===u[e.textNodeName]||e.alwaysCreateTextNode?0===Object.keys(u).length&&(e.alwaysCreateTextNode?u[e.textNodeName]="":u=""):u=u[e.textNodeName],void 0!==o[Et]&&"object"==typeof u&&null!==u&&(u[Et]=o[Et]),void 0!==s[h]&&Object.prototype.hasOwnProperty.call(s,h))Array.isArray(s[h])||(s[h]=[s[h]]),s[h].push(u);else{var d=e.jPath?i.toString():i;e.isArray(h,d,p)?s[h]=[u]:s[h]=u}void 0!==h&&h!==e.textNodeName&&r.pop()}}}return"string"==typeof n?n.length>0&&(s[e.textNodeName]=n):void 0!==n&&(s[e.textNodeName]=n),s}function At(t){for(var e=Object.keys(t),r=0;r<e.length;r++){var i=e[r];if(":@"!==i)return i}}function Tt(t,e,r,i){if(e)for(var n=Object.keys(e),s=n.length,a=0;a<s;a++){var o=n[a],h=o.startsWith(i.attributeNamePrefix)?o.substring(i.attributeNamePrefix.length):o,l=i.jPath?r.toString()+"."+h:r;i.isArray(o,l,!0,!0)?t[o]=[e[o]]:t[o]=e[o]}}function Ct(t,e){var r=e.textNodeName,i=Object.keys(t).length;return 0===i||!(1!==i||!t[r]&&"boolean"!=typeof t[r]&&0!==t[r])}var Pt=function(){function t(t){this.externalEntities={},this.options=P(t)}var e=t.prototype;return e.parse=function(t,e){if("string"!=typeof t&&t.toString)t=t.toString();else if("string"!=typeof t)throw new Error("XML data is accepted in String or Bytes[] form.");if(e){!0===e&&(e={});var r=l(t,e);if(!0!==r)throw Error(r.err.msg+":"+r.err.line+":"+r.err.col)}var i=new st(this.options);i.entityDecoder.setExternalEntities(this.externalEntities);var n=i.parseXml(t);return this.options.preserveOrder||void 0===n?n:St(n,this.options,i.matcher,i.readonlyMatcher)},e.addEntity=function(t,e){if(-1!==e.indexOf("&"))throw new Error("Entity value can't have '&'");if(-1!==t.indexOf("&")||-1!==t.indexOf(";"))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},t.getMetaDataSymbol=function(){return O.getMetaDataSymbol()},t}();function Ot(t,e){let r="";e.format&&e.indentBy.length>0&&(r="\n");const i=[];if(e.stopNodes&&Array.isArray(e.stopNodes))for(let t=0;t<e.stopNodes.length;t++){const r=e.stopNodes[t];"string"==typeof r?i.push(new U(r)):r instanceof U&&i.push(r)}return It(t,e,r,new G,i)}function It(t,e,r,i,n){let s="",a=!1;if(e.maxNestedTags&&i.getDepth()>e.maxNestedTags)throw new Error("Maximum nested tags exceeded");if(!Array.isArray(t)){if(null!=t){let r=t.toString();return r=kt(r,e),r}return""}for(let o=0;o<t.length;o++){const h=t[o],l=Mt(h);if(void 0===l)continue;const u=jt(h[":@"],e);i.push(l,u);const p=Lt(i,n);if(l===e.textNodeName){let t=h[l];p||(t=e.tagValueProcessor(l,t),t=kt(t,e)),a&&(s+=r),s+=t,a=!1,i.pop();continue}if(l===e.cdataPropName){a&&(s+=r);const t=h[l][0][e.textNodeName];s+=`<![CDATA[${String(t).replace(/\]\]>/g,"]]]]><![CDATA[>")}]]>`,a=!1,i.pop();continue}if(l===e.commentPropName){const t=h[l][0][e.textNodeName];s+=r+`\x3c!--${String(t).replace(/--/g,"- -").replace(/-$/,"- ")}--\x3e`,a=!0,i.pop();continue}if("?"===l[0]){const t=Vt(h[":@"],e,p),n="?xml"===l?"":r;let o=h[l][0][e.textNodeName];o=0!==o.length?" "+o:"",s+=n+`<${l}${o}${t}?>`,a=!0,i.pop();continue}let d=r;""!==d&&(d+=e.indentBy);const c=r+`<${l}${Vt(h[":@"],e,p)}`;let f;f=p?Dt(h[l],e):It(h[l],e,d,i,n),-1!==e.unpairedTags.indexOf(l)?e.suppressUnpairedNode?s+=c+">":s+=c+"/>":f&&0!==f.length||!e.suppressEmptyNode?f&&f.endsWith(">")?s+=c+`>${f}${r}</${l}>`:(s+=c+">",f&&""!==r&&(f.includes("/>")||f.includes("</"))?s+=r+e.indentBy+f+r:s+=f,s+=`</${l}>`):s+=c+"/>",a=!0,i.pop()}return s}function jt(t,e){if(!t||e.ignoreAttributes)return null;const r={};let i=!1;for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n.startsWith(e.attributeNamePrefix)?n.substr(e.attributeNamePrefix.length):n]=t[n],i=!0);return i?r:null}function Dt(t,e){if(!Array.isArray(t))return null!=t?t.toString():"";let r="";for(let i=0;i<t.length;i++){const n=t[i],s=Mt(n);if(s===e.textNodeName)r+=n[s];else if(s===e.cdataPropName)r+=n[s][0][e.textNodeName];else if(s===e.commentPropName)r+=n[s][0][e.textNodeName];else{if(s&&"?"===s[0])continue;if(s){const t=$t(n[":@"],e),i=Dt(n[s],e);i&&0!==i.length?r+=`<${s}${t}>${i}</${s}>`:r+=`<${s}${t}/>`}}}return r}function $t(t,e){let r="";if(t&&!e.ignoreAttributes)for(let i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;let n=t[i];!0===n&&e.suppressBooleanAttributes?r+=` ${i.substr(e.attributeNamePrefix.length)}`:r+=` ${i.substr(e.attributeNamePrefix.length)}="${n}"`}return r}function Mt(t){const e=Object.keys(t);for(let r=0;r<e.length;r++){const i=e[r];if(Object.prototype.hasOwnProperty.call(t,i)&&":@"!==i)return i}}function Vt(t,e,r){let i="";if(t&&!e.ignoreAttributes)for(let n in t){if(!Object.prototype.hasOwnProperty.call(t,n))continue;let s;r?s=t[n]:(s=e.attributeValueProcessor(n,t[n]),s=kt(s,e)),!0===s&&e.suppressBooleanAttributes?i+=` ${n.substr(e.attributeNamePrefix.length)}`:i+=` ${n.substr(e.attributeNamePrefix.length)}="${s}"`}return i}function Lt(t,e){if(!e||0===e.length)return!1;for(let r=0;r<e.length;r++)if(t.matches(e[r]))return!0;return!1}function kt(t,e){if(t&&t.length>0&&e.processEntities)for(let r=0;r<e.entities.length;r++){const i=e.entities[r];t=t.replace(i.regex,i.val)}return t}const Ft={attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,cdataPropName:!1,format:!1,indentBy:" ",suppressEmptyNode:!1,suppressUnpairedNode:!0,suppressBooleanAttributes:!0,tagValueProcessor:function(t,e){return e},attributeValueProcessor:function(t,e){return e},preserveOrder:!1,commentPropName:!1,unpairedTags:[],entities:[{regex:new RegExp("&","g"),val:"&amp;"},{regex:new RegExp(">","g"),val:"&gt;"},{regex:new RegExp("<","g"),val:"&lt;"},{regex:new RegExp("'","g"),val:"&apos;"},{regex:new RegExp('"',"g"),val:"&quot;"}],processEntities:!0,stopNodes:[],oneListGroup:!1,maxNestedTags:100,jPath:!0};function Rt(t){if(this.options=Object.assign({},Ft,t),this.options.stopNodes&&Array.isArray(this.options.stopNodes)&&(this.options.stopNodes=this.options.stopNodes.map(t=>"string"==typeof t&&t.startsWith("*.")?".."+t.substring(2):t)),this.stopNodeExpressions=[],this.options.stopNodes&&Array.isArray(this.options.stopNodes))for(let t=0;t<this.options.stopNodes.length;t++){const e=this.options.stopNodes[t];"string"==typeof e?this.stopNodeExpressions.push(new U(e)):e instanceof U&&this.stopNodeExpressions.push(e)}var e;!0===this.options.ignoreAttributes||this.options.attributesGroupName?this.isAttribute=function(){return!1}:(this.ignoreAttributesFn="function"==typeof(e=this.options.ignoreAttributes)?e:Array.isArray(e)?t=>{for(const r of e){if("string"==typeof r&&t===r)return!0;if(r instanceof RegExp&&r.test(t))return!0}}:()=>!1,this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=Bt),this.processTextOrObjNode=Gt,this.options.format?(this.indentate=Ut,this.tagEndChar=">\n",this.newLine="\n"):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}function Gt(t,e,r,i){const n=this.extractAttributes(t);if(i.push(e,n),this.checkStopNode(i)){const n=this.buildRawContent(t),s=this.buildAttributesForStopNode(t);return i.pop(),this.buildObjectNode(n,e,s,r)}const s=this.j2x(t,r+1,i);return i.pop(),void 0!==t[this.options.textNodeName]&&1===Object.keys(t).length?this.buildTextValNode(t[this.options.textNodeName],e,s.attrStr,r,i):this.buildObjectNode(s.val,e,s.attrStr,r)}function Ut(t){return this.options.indentBy.repeat(t)}function Bt(t){return!(!t.startsWith(this.options.attributeNamePrefix)||t===this.options.textNodeName)&&t.substr(this.attrPrefixLen)}Rt.prototype.build=function(t){if(this.options.preserveOrder)return Ot(t,this.options);{Array.isArray(t)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(t={[this.options.arrayNodeName]:t});const e=new G;return this.j2x(t,0,e).val}},Rt.prototype.j2x=function(t,e,r){let i="",n="";if(this.options.maxNestedTags&&r.getDepth()>=this.options.maxNestedTags)throw new Error("Maximum nested tags exceeded");const s=this.options.jPath?r.toString():r,a=this.checkStopNode(r);for(let o in t)if(Object.prototype.hasOwnProperty.call(t,o))if(void 0===t[o])this.isAttribute(o)&&(n+="");else if(null===t[o])this.isAttribute(o)||o===this.options.cdataPropName?n+="":"?"===o[0]?n+=this.indentate(e)+"<"+o+"?"+this.tagEndChar:n+=this.indentate(e)+"<"+o+"/"+this.tagEndChar;else if(t[o]instanceof Date)n+=this.buildTextValNode(t[o],o,"",e,r);else if("object"!=typeof t[o]){const h=this.isAttribute(o);if(h&&!this.ignoreAttributesFn(h,s))i+=this.buildAttrPairStr(h,""+t[o],a);else if(!h)if(o===this.options.textNodeName){let e=this.options.tagValueProcessor(o,""+t[o]);n+=this.replaceEntitiesValue(e)}else{r.push(o);const i=this.checkStopNode(r);if(r.pop(),i){const r=""+t[o];n+=""===r?this.indentate(e)+"<"+o+this.closeTag(o)+this.tagEndChar:this.indentate(e)+"<"+o+">"+r+"</"+o+this.tagEndChar}else n+=this.buildTextValNode(t[o],o,"",e,r)}}else if(Array.isArray(t[o])){const i=t[o].length;let s="",a="";for(let h=0;h<i;h++){const i=t[o][h];if(void 0===i);else if(null===i)"?"===o[0]?n+=this.indentate(e)+"<"+o+"?"+this.tagEndChar:n+=this.indentate(e)+"<"+o+"/"+this.tagEndChar;else if("object"==typeof i)if(this.options.oneListGroup){r.push(o);const t=this.j2x(i,e+1,r);r.pop(),s+=t.val,this.options.attributesGroupName&&i.hasOwnProperty(this.options.attributesGroupName)&&(a+=t.attrStr)}else s+=this.processTextOrObjNode(i,o,e,r);else if(this.options.oneListGroup){let t=this.options.tagValueProcessor(o,i);t=this.replaceEntitiesValue(t),s+=t}else{r.push(o);const t=this.checkStopNode(r);if(r.pop(),t){const t=""+i;s+=""===t?this.indentate(e)+"<"+o+this.closeTag(o)+this.tagEndChar:this.indentate(e)+"<"+o+">"+t+"</"+o+this.tagEndChar}else s+=this.buildTextValNode(i,o,"",e,r)}}this.options.oneListGroup&&(s=this.buildObjectNode(s,o,a,e)),n+=s}else if(this.options.attributesGroupName&&o===this.options.attributesGroupName){const e=Object.keys(t[o]),r=e.length;for(let n=0;n<r;n++)i+=this.buildAttrPairStr(e[n],""+t[o][e[n]],a)}else n+=this.processTextOrObjNode(t[o],o,e,r);return{attrStr:i,val:n}},Rt.prototype.buildAttrPairStr=function(t,e,r){retu