fast-xml-parser
Advanced tools
+5
-0
@@ -5,2 +5,7 @@ <small>Note: If you find missing information about particular minor version, that version must have been changed without any functional change in this library.</small> | ||
| **5.5.0 / 2026-03-10** | ||
| - support path-expression-matcher | ||
| - fix: stopNode should not be parsed | ||
| - performance improvement for stopNode checking | ||
| **5.4.2 / 2026-03-03** | ||
@@ -7,0 +12,0 @@ - support maxEntityCount option |
@@ -1,2 +0,2 @@ | ||
| !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.XMLBuilder=e():t.XMLBuilder=e()}(this,()=>(()=>{"use strict";var t={d:(e,i)=>{for(var s in i)t.o(i,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:i[s]})},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={};function i(t,e){let i="";return e.format&&e.indentBy.length>0&&(i="\n"),s(t,e,"",i)}function s(t,e,i,p){let u="",h=!1;if(!Array.isArray(t)){if(null!=t){let i=t.toString();return i=a(i,e),i}return""}for(let l=0;l<t.length;l++){const d=t[l],c=n(d);if(void 0===c)continue;let f="";if(f=0===i.length?c:`${i}.${c}`,c===e.textNodeName){let t=d[c];r(f,e)||(t=e.tagValueProcessor(c,t),t=a(t,e)),h&&(u+=p),u+=t,h=!1;continue}if(c===e.cdataPropName){h&&(u+=p),u+=`<![CDATA[${d[c][0][e.textNodeName]}]]>`,h=!1;continue}if(c===e.commentPropName){u+=p+`\x3c!--${d[c][0][e.textNodeName]}--\x3e`,h=!0;continue}if("?"===c[0]){const t=o(d[":@"],e),i="?xml"===c?"":p;let s=d[c][0][e.textNodeName];s=0!==s.length?" "+s:"",u+=i+`<${c}${s}${t}?>`,h=!0;continue}let g=p;""!==g&&(g+=e.indentBy);const b=p+`<${c}${o(d[":@"],e)}`,N=s(d[c],e,f,g);-1!==e.unpairedTags.indexOf(c)?e.suppressUnpairedNode?u+=b+">":u+=b+"/>":N&&0!==N.length||!e.suppressEmptyNode?N&&N.endsWith(">")?u+=b+`>${N}${p}</${c}>`:(u+=b+">",N&&""!==p&&(N.includes("/>")||N.includes("</"))?u+=p+e.indentBy+N+p:u+=N,u+=`</${c}>`):u+=b+"/>",h=!0}return u}function n(t){const e=Object.keys(t);for(let i=0;i<e.length;i++){const s=e[i];if(Object.prototype.hasOwnProperty.call(t,s)&&":@"!==s)return s}}function o(t,e){let i="";if(t&&!e.ignoreAttributes)for(let s in t){if(!Object.prototype.hasOwnProperty.call(t,s))continue;let n=e.attributeValueProcessor(s,t[s]);n=a(n,e),!0===n&&e.suppressBooleanAttributes?i+=` ${s.substr(e.attributeNamePrefix.length)}`:i+=` ${s.substr(e.attributeNamePrefix.length)}="${n}"`}return i}function r(t,e){let i=(t=t.substr(0,t.length-e.textNodeName.length-1)).substr(t.lastIndexOf(".")+1);for(let s in e.stopNodes)if(e.stopNodes[s]===t||e.stopNodes[s]==="*."+i)return!0;return!1}function a(t,e){if(t&&t.length>0&&e.processEntities)for(let i=0;i<e.entities.length;i++){const s=e.entities[i];t=t.replace(s.regex,s.val)}return t}t.r(e),t.d(e,{default:()=>c});const p={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:"&"},{regex:new RegExp(">","g"),val:">"},{regex:new RegExp("<","g"),val:"<"},{regex:new RegExp("'","g"),val:"'"},{regex:new RegExp('"',"g"),val:"""}],processEntities:!0,stopNodes:[],oneListGroup:!1};function u(t){var e;this.options=Object.assign({},p,t),!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 i of e){if("string"==typeof i&&t===i)return!0;if(i instanceof RegExp&&i.test(t))return!0}}:()=>!1,this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=d),this.processTextOrObjNode=h,this.options.format?(this.indentate=l,this.tagEndChar=">\n",this.newLine="\n"):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}function h(t,e,i,s){const n=this.j2x(t,i+1,s.concat(e));return void 0!==t[this.options.textNodeName]&&1===Object.keys(t).length?this.buildTextValNode(t[this.options.textNodeName],e,n.attrStr,i):this.buildObjectNode(n.val,e,n.attrStr,i)}function l(t){return this.options.indentBy.repeat(t)}function d(t){return!(!t.startsWith(this.options.attributeNamePrefix)||t===this.options.textNodeName)&&t.substr(this.attrPrefixLen)}u.prototype.build=function(t){return this.options.preserveOrder?i(t,this.options):(Array.isArray(t)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(t={[this.options.arrayNodeName]:t}),this.j2x(t,0,[]).val)},u.prototype.j2x=function(t,e,i){let s="",n="";const o=i.join(".");for(let r in t)if(Object.prototype.hasOwnProperty.call(t,r))if(void 0===t[r])this.isAttribute(r)&&(n+="");else if(null===t[r])this.isAttribute(r)||r===this.options.cdataPropName?n+="":"?"===r[0]?n+=this.indentate(e)+"<"+r+"?"+this.tagEndChar:n+=this.indentate(e)+"<"+r+"/"+this.tagEndChar;else if(t[r]instanceof Date)n+=this.buildTextValNode(t[r],r,"",e);else if("object"!=typeof t[r]){const i=this.isAttribute(r);if(i&&!this.ignoreAttributesFn(i,o))s+=this.buildAttrPairStr(i,""+t[r]);else if(!i)if(r===this.options.textNodeName){let e=this.options.tagValueProcessor(r,""+t[r]);n+=this.replaceEntitiesValue(e)}else n+=this.buildTextValNode(t[r],r,"",e)}else if(Array.isArray(t[r])){const s=t[r].length;let o="",a="";for(let p=0;p<s;p++){const s=t[r][p];if(void 0===s);else if(null===s)"?"===r[0]?n+=this.indentate(e)+"<"+r+"?"+this.tagEndChar:n+=this.indentate(e)+"<"+r+"/"+this.tagEndChar;else if("object"==typeof s)if(this.options.oneListGroup){const t=this.j2x(s,e+1,i.concat(r));o+=t.val,this.options.attributesGroupName&&s.hasOwnProperty(this.options.attributesGroupName)&&(a+=t.attrStr)}else o+=this.processTextOrObjNode(s,r,e,i);else if(this.options.oneListGroup){let t=this.options.tagValueProcessor(r,s);t=this.replaceEntitiesValue(t),o+=t}else o+=this.buildTextValNode(s,r,"",e)}this.options.oneListGroup&&(o=this.buildObjectNode(o,r,a,e)),n+=o}else if(this.options.attributesGroupName&&r===this.options.attributesGroupName){const e=Object.keys(t[r]),i=e.length;for(let n=0;n<i;n++)s+=this.buildAttrPairStr(e[n],""+t[r][e[n]])}else n+=this.processTextOrObjNode(t[r],r,e,i);return{attrStr:s,val:n}},u.prototype.buildAttrPairStr=function(t,e){return e=this.options.attributeValueProcessor(t,""+e),e=this.replaceEntitiesValue(e),this.options.suppressBooleanAttributes&&"true"===e?" "+t:" "+t+'="'+e+'"'},u.prototype.buildObjectNode=function(t,e,i,s){if(""===t)return"?"===e[0]?this.indentate(s)+"<"+e+i+"?"+this.tagEndChar:this.indentate(s)+"<"+e+i+this.closeTag(e)+this.tagEndChar;{let n="</"+e+this.tagEndChar,o="";return"?"===e[0]&&(o="?",n=""),!i&&""!==i||-1!==t.indexOf("<")?!1!==this.options.commentPropName&&e===this.options.commentPropName&&0===o.length?this.indentate(s)+`\x3c!--${t}--\x3e`+this.newLine:this.indentate(s)+"<"+e+i+o+this.tagEndChar+t+this.indentate(s)+n:this.indentate(s)+"<"+e+i+o+">"+t+n}},u.prototype.closeTag=function(t){let e="";return-1!==this.options.unpairedTags.indexOf(t)?this.options.suppressUnpairedNode||(e="/"):e=this.options.suppressEmptyNode?"/":`></${t}`,e},u.prototype.buildTextValNode=function(t,e,i,s){if(!1!==this.options.cdataPropName&&e===this.options.cdataPropName)return this.indentate(s)+`<![CDATA[${t}]]>`+this.newLine;if(!1!==this.options.commentPropName&&e===this.options.commentPropName)return this.indentate(s)+`\x3c!--${t}--\x3e`+this.newLine;if("?"===e[0])return this.indentate(s)+"<"+e+i+"?"+this.tagEndChar;{let n=this.options.tagValueProcessor(e,t);return n=this.replaceEntitiesValue(n),""===n?this.indentate(s)+"<"+e+i+this.closeTag(e)+this.tagEndChar:this.indentate(s)+"<"+e+i+">"+n+"</"+e+this.tagEndChar}},u.prototype.replaceEntitiesValue=function(t){if(t&&t.length>0&&this.options.processEntities)for(let e=0;e<this.options.entities.length;e++){const i=this.options.entities[e];t=t.replace(i.regex,i.val)}return t};const c=u;return e})()); | ||
| !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.XMLBuilder=e():t.XMLBuilder=e()}(this,()=>(()=>{"use strict";var t={d:(e,i)=>{for(var s in i)t.o(i,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:i[s]})},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,{default:()=>N});class i{constructor(t,e={}){this.pattern=t,this.separator=e.separator||".",this.segments=this._parse(t),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 i=0,s="";for(;i<t.length;)t[i]===this.separator?i+1<t.length&&t[i+1]===this.separator?(s.trim()&&(e.push(this._parseSegment(s.trim())),s=""),e.push({type:"deep-wildcard"}),i+=2):(s.trim()&&e.push(this._parseSegment(s.trim())),s="",i++):(s+=t[i],i++);return s.trim()&&e.push(this._parseSegment(s.trim())),e}_parseSegment(t){const e={type:"tag"};let i=null,s=t;const n=t.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);if(n&&(s=n[1]+n[3],n[2])){const t=n[2].slice(1,-1);t&&(i=t)}let o,r,a=s;if(s.includes("::")){const e=s.indexOf("::");if(o=s.substring(0,e).trim(),a=s.substring(e+2).trim(),!o)throw new Error(`Invalid namespace in pattern: ${t}`)}let h=null;if(a.includes(":")){const t=a.lastIndexOf(":"),e=a.substring(0,t).trim(),i=a.substring(t+1).trim();["first","last","odd","even"].includes(i)||/^nth\(\d+\)$/.test(i)?(r=e,h=i):r=a}else r=a;if(!r)throw new Error(`Invalid segment pattern: ${t}`);if(e.tag=r,o&&(e.namespace=o),i)if(i.includes("=")){const t=i.indexOf("=");e.attrName=i.substring(0,t).trim(),e.attrValue=i.substring(t+1).trim()}else e.attrName=i.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 s{constructor(t={}){this.separator=t.separator||".",this.path=[],this.siblingStacks=[]}push(t,e=null,i=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 n=this.siblingStacks[s],o=i?`${i}:${t}`:t,r=n.get(o)||0;let a=0;for(const t of n.values())a+=t;n.set(o,r+1);const h={tag:t,position:a,counter:r};null!=i&&(h.namespace=i),null!=e&&(h.values=e),this.path.push(h)}pop(){if(0===this.path.length)return;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;const e=this.path[this.path.length-1];return e.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 i=t||this.separator;return this.path.map(t=>e&&t.namespace?`${t.namespace}:${t.tag}`:t.tag).join(i)}toArray(){return this.path.map(t=>t.tag)}reset(){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++){const i=t[e],s=this.path[e],n=e===this.path.length-1;if(!this._matchSegment(i,s,n))return!1}return!0}_matchWithDeepWildcard(t){let e=this.path.length-1,i=t.length-1;for(;i>=0&&e>=0;){const s=t[i];if("deep-wildcard"===s.type){if(i--,i<0)return!0;const s=t[i];let n=!1;for(let t=e;t>=0;t--){const o=t===this.path.length-1;if(this._matchSegment(s,this.path[t],o)){e=t-1,i--,n=!0;break}}if(!n)return!1}else{const t=e===this.path.length-1;if(!this._matchSegment(s,this.path[e],t))return!1;e--,i--}}return i<0}_matchSegment(t,e,i){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(!i)return!1;if(!e.values||!(t.attrName in e.values))return!1;if(void 0!==t.attrValue){const i=e.values[t.attrName];if(String(i)!==String(t.attrValue))return!1}}if(void 0!==t.position){if(!i)return!1;const s=e.counter??0;if("first"===t.position&&0!==s)return!1;if("odd"===t.position&&s%2!=1)return!1;if("even"===t.position&&s%2!=0)return!1;if("nth"===t.position&&s!==t.positionValue)return!1}return!0}snapshot(){return{path:this.path.map(t=>({...t})),siblingStacks:this.siblingStacks.map(t=>new Map(t))}}restore(t){this.path=t.path.map(t=>({...t})),this.siblingStacks=t.siblingStacks.map(t=>new Map(t))}}function n(t,e){let n="";e.format&&e.indentBy.length>0&&(n="\n");const r=[];if(e.stopNodes&&Array.isArray(e.stopNodes))for(let t=0;t<e.stopNodes.length;t++){const s=e.stopNodes[t];"string"==typeof s?r.push(new i(s)):s instanceof i&&r.push(s)}return o(t,e,n,new s,r)}function o(t,e,i,s,n){let h="",d=!1;if(!Array.isArray(t)){if(null!=t){let i=t.toString();return i=c(i,e),i}return""}for(let f=0;f<t.length;f++){const g=t[f],m=p(g);if(void 0===m)continue;const b=r(g[":@"],e);s.push(m,b);const N=l(s,n);if(m===e.textNodeName){let t=g[m];N||(t=e.tagValueProcessor(m,t),t=c(t,e)),d&&(h+=i),h+=t,d=!1,s.pop();continue}if(m===e.cdataPropName){d&&(h+=i),h+=`<![CDATA[${g[m][0][e.textNodeName]}]]>`,d=!1,s.pop();continue}if(m===e.commentPropName){h+=i+`\x3c!--${g[m][0][e.textNodeName]}--\x3e`,d=!0,s.pop();continue}if("?"===m[0]){const t=u(g[":@"],e,N),n="?xml"===m?"":i;let o=g[m][0][e.textNodeName];o=0!==o.length?" "+o:"",h+=n+`<${m}${o}${t}?>`,d=!0,s.pop();continue}let y=i;""!==y&&(y+=e.indentBy);const x=i+`<${m}${u(g[":@"],e,N)}`;let P;P=N?a(g[m],e):o(g[m],e,y,s,n),-1!==e.unpairedTags.indexOf(m)?e.suppressUnpairedNode?h+=x+">":h+=x+"/>":P&&0!==P.length||!e.suppressEmptyNode?P&&P.endsWith(">")?h+=x+`>${P}${i}</${m}>`:(h+=x+">",P&&""!==i&&(P.includes("/>")||P.includes("</"))?h+=i+e.indentBy+P+i:h+=P,h+=`</${m}>`):h+=x+"/>",d=!0,s.pop()}return h}function r(t,e){if(!t||e.ignoreAttributes)return null;const i={};let s=!1;for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n.startsWith(e.attributeNamePrefix)?n.substr(e.attributeNamePrefix.length):n]=t[n],s=!0);return s?i:null}function a(t,e){if(!Array.isArray(t))return null!=t?t.toString():"";let i="";for(let s=0;s<t.length;s++){const n=t[s],o=p(n);if(o===e.textNodeName)i+=n[o];else if(o===e.cdataPropName)i+=n[o][0][e.textNodeName];else if(o===e.commentPropName)i+=n[o][0][e.textNodeName];else{if(o&&"?"===o[0])continue;if(o){const t=h(n[":@"],e),s=a(n[o],e);s&&0!==s.length?i+=`<${o}${t}>${s}</${o}>`:i+=`<${o}${t}/>`}}}return i}function h(t,e){let i="";if(t&&!e.ignoreAttributes)for(let s in t){if(!Object.prototype.hasOwnProperty.call(t,s))continue;let n=t[s];!0===n&&e.suppressBooleanAttributes?i+=` ${s.substr(e.attributeNamePrefix.length)}`:i+=` ${s.substr(e.attributeNamePrefix.length)}="${n}"`}return i}function p(t){const e=Object.keys(t);for(let i=0;i<e.length;i++){const s=e[i];if(Object.prototype.hasOwnProperty.call(t,s)&&":@"!==s)return s}}function u(t,e,i){let s="";if(t&&!e.ignoreAttributes)for(let n in t){if(!Object.prototype.hasOwnProperty.call(t,n))continue;let o;i?o=t[n]:(o=e.attributeValueProcessor(n,t[n]),o=c(o,e)),!0===o&&e.suppressBooleanAttributes?s+=` ${n.substr(e.attributeNamePrefix.length)}`:s+=` ${n.substr(e.attributeNamePrefix.length)}="${o}"`}return s}function l(t,e){if(!e||0===e.length)return!1;for(let i=0;i<e.length;i++)if(t.matches(e[i]))return!0;return!1}function c(t,e){if(t&&t.length>0&&e.processEntities)for(let i=0;i<e.entities.length;i++){const s=e.entities[i];t=t.replace(s.regex,s.val)}return t}const d={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:"&"},{regex:new RegExp(">","g"),val:">"},{regex:new RegExp("<","g"),val:"<"},{regex:new RegExp("'","g"),val:"'"},{regex:new RegExp('"',"g"),val:"""}],processEntities:!0,stopNodes:[],oneListGroup:!1,jPath:!0};function f(t){if(this.options=Object.assign({},d,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 i(e)):e instanceof i&&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 i of e){if("string"==typeof i&&t===i)return!0;if(i instanceof RegExp&&i.test(t))return!0}}:()=>!1,this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=b),this.processTextOrObjNode=g,this.options.format?(this.indentate=m,this.tagEndChar=">\n",this.newLine="\n"):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}function g(t,e,i,s){const n=this.extractAttributes(t);if(s.push(e,n),this.checkStopNode(s)){const n=this.buildRawContent(t),o=this.buildAttributesForStopNode(t);return s.pop(),this.buildObjectNode(n,e,o,i)}const o=this.j2x(t,i+1,s);return s.pop(),void 0!==t[this.options.textNodeName]&&1===Object.keys(t).length?this.buildTextValNode(t[this.options.textNodeName],e,o.attrStr,i,s):this.buildObjectNode(o.val,e,o.attrStr,i)}function m(t){return this.options.indentBy.repeat(t)}function b(t){return!(!t.startsWith(this.options.attributeNamePrefix)||t===this.options.textNodeName)&&t.substr(this.attrPrefixLen)}f.prototype.build=function(t){if(this.options.preserveOrder)return n(t,this.options);{Array.isArray(t)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(t={[this.options.arrayNodeName]:t});const e=new s;return this.j2x(t,0,e).val}},f.prototype.j2x=function(t,e,i){let s="",n="";const o=this.options.jPath?i.toString():i,r=this.checkStopNode(i);for(let a in t)if(Object.prototype.hasOwnProperty.call(t,a))if(void 0===t[a])this.isAttribute(a)&&(n+="");else if(null===t[a])this.isAttribute(a)||a===this.options.cdataPropName?n+="":"?"===a[0]?n+=this.indentate(e)+"<"+a+"?"+this.tagEndChar:n+=this.indentate(e)+"<"+a+"/"+this.tagEndChar;else if(t[a]instanceof Date)n+=this.buildTextValNode(t[a],a,"",e,i);else if("object"!=typeof t[a]){const h=this.isAttribute(a);if(h&&!this.ignoreAttributesFn(h,o))s+=this.buildAttrPairStr(h,""+t[a],r);else if(!h)if(a===this.options.textNodeName){let e=this.options.tagValueProcessor(a,""+t[a]);n+=this.replaceEntitiesValue(e)}else{i.push(a);const s=this.checkStopNode(i);if(i.pop(),s){const i=""+t[a];n+=""===i?this.indentate(e)+"<"+a+this.closeTag(a)+this.tagEndChar:this.indentate(e)+"<"+a+">"+i+"</"+a+this.tagEndChar}else n+=this.buildTextValNode(t[a],a,"",e,i)}}else if(Array.isArray(t[a])){const s=t[a].length;let o="",r="";for(let h=0;h<s;h++){const s=t[a][h];if(void 0===s);else if(null===s)"?"===a[0]?n+=this.indentate(e)+"<"+a+"?"+this.tagEndChar:n+=this.indentate(e)+"<"+a+"/"+this.tagEndChar;else if("object"==typeof s)if(this.options.oneListGroup){i.push(a);const t=this.j2x(s,e+1,i);i.pop(),o+=t.val,this.options.attributesGroupName&&s.hasOwnProperty(this.options.attributesGroupName)&&(r+=t.attrStr)}else o+=this.processTextOrObjNode(s,a,e,i);else if(this.options.oneListGroup){let t=this.options.tagValueProcessor(a,s);t=this.replaceEntitiesValue(t),o+=t}else{i.push(a);const t=this.checkStopNode(i);if(i.pop(),t){const t=""+s;o+=""===t?this.indentate(e)+"<"+a+this.closeTag(a)+this.tagEndChar:this.indentate(e)+"<"+a+">"+t+"</"+a+this.tagEndChar}else o+=this.buildTextValNode(s,a,"",e,i)}}this.options.oneListGroup&&(o=this.buildObjectNode(o,a,r,e)),n+=o}else if(this.options.attributesGroupName&&a===this.options.attributesGroupName){const e=Object.keys(t[a]),i=e.length;for(let n=0;n<i;n++)s+=this.buildAttrPairStr(e[n],""+t[a][e[n]],r)}else n+=this.processTextOrObjNode(t[a],a,e,i);return{attrStr:s,val:n}},f.prototype.buildAttrPairStr=function(t,e,i){return i||(e=this.options.attributeValueProcessor(t,""+e),e=this.replaceEntitiesValue(e)),this.options.suppressBooleanAttributes&&"true"===e?" "+t:" "+t+'="'+e+'"'},f.prototype.extractAttributes=function(t){if(!t||"object"!=typeof t)return null;const e={};let i=!1;if(this.options.attributesGroupName&&t[this.options.attributesGroupName]){const s=t[this.options.attributesGroupName];for(let t in s)Object.prototype.hasOwnProperty.call(s,t)&&(e[t.startsWith(this.options.attributeNamePrefix)?t.substring(this.options.attributeNamePrefix.length):t]=s[t],i=!0)}else for(let s in t){if(!Object.prototype.hasOwnProperty.call(t,s))continue;const n=this.isAttribute(s);n&&(e[n]=t[s],i=!0)}return i?e:null},f.prototype.buildRawContent=function(t){if("string"==typeof t)return t;if("object"!=typeof t||null===t)return String(t);if(void 0!==t[this.options.textNodeName])return t[this.options.textNodeName];let e="";for(let i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;if(this.isAttribute(i))continue;if(this.options.attributesGroupName&&i===this.options.attributesGroupName)continue;const s=t[i];if(i===this.options.textNodeName)e+=s;else if(Array.isArray(s)){for(let t of s)if("string"==typeof t||"number"==typeof t)e+=`<${i}>${t}</${i}>`;else if("object"==typeof t&&null!==t){const s=this.buildRawContent(t),n=this.buildAttributesForStopNode(t);e+=""===s?`<${i}${n}/>`:`<${i}${n}>${s}</${i}>`}}else if("object"==typeof s&&null!==s){const t=this.buildRawContent(s),n=this.buildAttributesForStopNode(s);e+=""===t?`<${i}${n}/>`:`<${i}${n}>${t}</${i}>`}else e+=`<${i}>${s}</${i}>`}return e},f.prototype.buildAttributesForStopNode=function(t){if(!t||"object"!=typeof t)return"";let e="";if(this.options.attributesGroupName&&t[this.options.attributesGroupName]){const i=t[this.options.attributesGroupName];for(let t in i){if(!Object.prototype.hasOwnProperty.call(i,t))continue;const s=t.startsWith(this.options.attributeNamePrefix)?t.substring(this.options.attributeNamePrefix.length):t,n=i[t];!0===n&&this.options.suppressBooleanAttributes?e+=" "+s:e+=" "+s+'="'+n+'"'}}else for(let i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;const s=this.isAttribute(i);if(s){const n=t[i];!0===n&&this.options.suppressBooleanAttributes?e+=" "+s:e+=" "+s+'="'+n+'"'}}return e},f.prototype.buildObjectNode=function(t,e,i,s){if(""===t)return"?"===e[0]?this.indentate(s)+"<"+e+i+"?"+this.tagEndChar:this.indentate(s)+"<"+e+i+this.closeTag(e)+this.tagEndChar;{let n="</"+e+this.tagEndChar,o="";return"?"===e[0]&&(o="?",n=""),!i&&""!==i||-1!==t.indexOf("<")?!1!==this.options.commentPropName&&e===this.options.commentPropName&&0===o.length?this.indentate(s)+`\x3c!--${t}--\x3e`+this.newLine:this.indentate(s)+"<"+e+i+o+this.tagEndChar+t+this.indentate(s)+n:this.indentate(s)+"<"+e+i+o+">"+t+n}},f.prototype.closeTag=function(t){let e="";return-1!==this.options.unpairedTags.indexOf(t)?this.options.suppressUnpairedNode||(e="/"):e=this.options.suppressEmptyNode?"/":`></${t}`,e},f.prototype.checkStopNode=function(t){if(!this.stopNodeExpressions||0===this.stopNodeExpressions.length)return!1;for(let e=0;e<this.stopNodeExpressions.length;e++)if(t.matches(this.stopNodeExpressions[e]))return!0;return!1},f.prototype.buildTextValNode=function(t,e,i,s,n){if(!1!==this.options.cdataPropName&&e===this.options.cdataPropName)return this.indentate(s)+`<![CDATA[${t}]]>`+this.newLine;if(!1!==this.options.commentPropName&&e===this.options.commentPropName)return this.indentate(s)+`\x3c!--${t}--\x3e`+this.newLine;if("?"===e[0])return this.indentate(s)+"<"+e+i+"?"+this.tagEndChar;{let n=this.options.tagValueProcessor(e,t);return n=this.replaceEntitiesValue(n),""===n?this.indentate(s)+"<"+e+i+this.closeTag(e)+this.tagEndChar:this.indentate(s)+"<"+e+i+">"+n+"</"+e+this.tagEndChar}},f.prototype.replaceEntitiesValue=function(t){if(t&&t.length>0&&this.options.processEntities)for(let e=0;e<this.options.entities.length;e++){const i=this.options.entities[e];t=t.replace(i.regex,i.val)}return t};const N=f;return e})()); | ||
| //# sourceMappingURL=fxbuilder.min.js.map |
+1
-1
@@ -1,1 +0,1 @@ | ||
| (()=>{"use strict";var t={d:(e,n)=>{for(var i in n)t.o(n,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:n[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:()=>gt,XMLParser:()=>it,XMLValidator:()=>xt});const n=":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("^["+n+"]["+n+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040]*$");function s(t,e){const n=[];let i=e.exec(t);for(;i;){const s=[];s.startIndex=e.lastIndex-i[0].length;const r=i.length;for(let t=0;t<r;t++)s.push(i[t]);n.push(s),i=e.exec(t)}return n}const r=function(t){return!(null==i.exec(t))},o={allowBooleanAttributes:!1,unpairedTags:[]};function a(t,e){e=Object.assign({},o,e);const n=[];let i=!1,s=!1;"\ufeff"===t[0]&&(t=t.substr(1));for(let r=0;r<t.length;r++)if("<"===t[r]&&"?"===t[r+1]){if(r+=2,r=u(t,r),r.err)return r}else{if("<"!==t[r]){if(l(t[r]))continue;return m("InvalidChar","char '"+t[r]+"' is not expected.",N(t,r))}{let o=r;if(r++,"!"===t[r]){r=d(t,r);continue}{let a=!1;"/"===t[r]&&(a=!0,r++);let h="";for(;r<t.length&&">"!==t[r]&&" "!==t[r]&&"\t"!==t[r]&&"\n"!==t[r]&&"\r"!==t[r];r++)h+=t[r];if(h=h.trim(),"/"===h[h.length-1]&&(h=h.substring(0,h.length-1),r--),!b(h)){let e;return e=0===h.trim().length?"Invalid space after '<'.":"Tag '"+h+"' is an invalid name.",m("InvalidTag",e,N(t,r))}const p=c(t,r);if(!1===p)return m("InvalidAttr","Attributes for '"+h+"' have open quote.",N(t,r));let f=p.value;if(r=p.index,"/"===f[f.length-1]){const n=r-f.length;f=f.substring(0,f.length-1);const s=g(f,e);if(!0!==s)return m(s.err.code,s.err.msg,N(t,n+s.err.line));i=!0}else if(a){if(!p.tagClosed)return m("InvalidTag","Closing tag '"+h+"' doesn't have proper closing.",N(t,r));if(f.trim().length>0)return m("InvalidTag","Closing tag '"+h+"' can't have attributes or invalid starting.",N(t,o));if(0===n.length)return m("InvalidTag","Closing tag '"+h+"' has not been opened.",N(t,o));{const e=n.pop();if(h!==e.tagName){let n=N(t,e.tagStartPos);return m("InvalidTag","Expected closing tag '"+e.tagName+"' (opened in line "+n.line+", col "+n.col+") instead of closing tag '"+h+"'.",N(t,o))}0==n.length&&(s=!0)}}else{const a=g(f,e);if(!0!==a)return m(a.err.code,a.err.msg,N(t,r-f.length+a.err.line));if(!0===s)return m("InvalidXml","Multiple possible root nodes found.",N(t,r));-1!==e.unpairedTags.indexOf(h)||n.push({tagName:h,tagStartPos:o}),i=!0}for(r++;r<t.length;r++)if("<"===t[r]){if("!"===t[r+1]){r++,r=d(t,r);continue}if("?"!==t[r+1])break;if(r=u(t,++r),r.err)return r}else if("&"===t[r]){const e=x(t,r);if(-1==e)return m("InvalidChar","char '&' is not expected.",N(t,r));r=e}else if(!0===s&&!l(t[r]))return m("InvalidXml","Extra text at the end",N(t,r));"<"===t[r]&&r--}}}return i?1==n.length?m("InvalidTag","Unclosed tag '"+n[0].tagName+"'.",N(t,n[0].tagStartPos)):!(n.length>0)||m("InvalidXml","Invalid '"+JSON.stringify(n.map(t=>t.tagName),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1}):m("InvalidXml","Start tag expected.",1)}function l(t){return" "===t||"\t"===t||"\n"===t||"\r"===t}function u(t,e){const n=e;for(;e<t.length;e++)if("?"==t[e]||" "==t[e]){const i=t.substr(n,e-n);if(e>5&&"xml"===i)return m("InvalidXml","XML declaration allowed only at the start of the document.",N(t,e));if("?"==t[e]&&">"==t[e+1]){e++;break}continue}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]){let n=1;for(e+=8;e<t.length;e++)if("<"===t[e])n++;else if(">"===t[e]&&(n--,0===n))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}const h='"',p="'";function c(t,e){let n="",i="",s=!1;for(;e<t.length;e++){if(t[e]===h||t[e]===p)""===i?i=t[e]:i!==t[e]||(i="");else if(">"===t[e]&&""===i){s=!0;break}n+=t[e]}return""===i&&{value:n,index:e,tagClosed:s}}const f=new RegExp("(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['\"])(([\\s\\S])*?)\\5)?","g");function g(t,e){const n=s(t,f),i={};for(let t=0;t<n.length;t++){if(0===n[t][1].length)return m("InvalidAttr","Attribute '"+n[t][2]+"' has no space in starting.",y(n[t]));if(void 0!==n[t][3]&&void 0===n[t][4])return m("InvalidAttr","Attribute '"+n[t][2]+"' is without value.",y(n[t]));if(void 0===n[t][3]&&!e.allowBooleanAttributes)return m("InvalidAttr","boolean attribute '"+n[t][2]+"' is not allowed.",y(n[t]));const s=n[t][2];if(!E(s))return m("InvalidAttr","Attribute '"+s+"' is an invalid name.",y(n[t]));if(Object.prototype.hasOwnProperty.call(i,s))return m("InvalidAttr","Attribute '"+s+"' is repeated.",y(n[t]));i[s]=1}return!0}function x(t,e){if(";"===t[++e])return-1;if("#"===t[e])return function(t,e){let n=/\d/;for("x"===t[e]&&(e++,n=/[\da-fA-F]/);e<t.length;e++){if(";"===t[e])return e;if(!t[e].match(n))break}return-1}(t,++e);let n=0;for(;e<t.length;e++,n++)if(!(t[e].match(/\w/)&&n<20)){if(";"===t[e])break;return-1}return e}function m(t,e,n){return{err:{code:t,msg:e,line:n.line||n,col:n.col}}}function E(t){return r(t)}function b(t){return r(t)}function N(t,e){const n=t.substring(0,e).split(/\r?\n/);return{line:n.length,col:n[n.length-1].length+1}}function y(t){return t.startIndex+t[1].length}const 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:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(t,e,n){return t},captureMetaData:!1,maxNestedTags:100,strictReservedNames:!0};function w(t){return"boolean"==typeof t?{enabled:t,maxEntitySize:1e4,maxExpansionDepth:10,maxTotalExpansions:1e3,maxExpandedLength:1e5,maxEntityCount:100,allowedTags:null,tagFilter:null}:"object"==typeof t&&null!==t?{enabled:!1!==t.enabled,maxEntitySize:t.maxEntitySize??1e4,maxExpansionDepth:t.maxExpansionDepth??10,maxTotalExpansions:t.maxTotalExpansions??1e3,maxExpandedLength:t.maxExpandedLength??1e5,maxEntityCount:t.maxEntityCount??100,allowedTags:t.allowedTags??null,tagFilter:t.tagFilter??null}:w(!0)}const v=function(t){const e=Object.assign({},T,t);return e.processEntities=w(e.processEntities),e};let O;O="function"!=typeof Symbol?"@@xmlMetadata":Symbol("XML Node Metadata");class I{constructor(t){this.tagname=t,this.child=[],this[":@"]=Object.create(null)}add(t,e){"__proto__"===t&&(t="#__proto__"),this.child.push({[t]:e})}addChild(t,e){"__proto__"===t.tagname&&(t.tagname="#__proto__"),t[":@"]&&Object.keys(t[":@"]).length>0?this.child.push({[t.tagname]:t.child,":@":t[":@"]}):this.child.push({[t.tagname]:t.child}),void 0!==e&&(this.child[this.child.length-1][O]={startIndex:e})}static getMetaDataSymbol(){return O}}class P{constructor(t){this.suppressValidationErr=!t,this.options=t}readDocType(t,e){const n=Object.create(null);let 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;let s=1,r=!1,o=!1,a="";for(;e<t.length;e++)if("<"!==t[e]||o)if(">"===t[e]){if(o?"-"===t[e-1]&&"-"===t[e-2]&&(o=!1,s--):s--,0===s)break}else"["===t[e]?r=!0:a+=t[e];else{if(r&&S(t,"!ENTITY",e)){let s,r;if(e+=7,[s,r,e]=this.readEntityExp(t,e+1,this.suppressValidationErr),-1===r.indexOf("&")){if(!1!==this.options.enabled&&this.options.maxEntityCount&&i>=this.options.maxEntityCount)throw new Error(`Entity count (${i+1}) exceeds maximum allowed (${this.options.maxEntityCount})`);const t=s.replace(/[.\-+*:]/g,"\\.");n[s]={regx:RegExp(`&${t};`,"g"),val:r},i++}}else if(r&&S(t,"!ELEMENT",e)){e+=8;const{index:n}=this.readElementExp(t,e+1);e=n}else if(r&&S(t,"!ATTLIST",e))e+=8;else if(r&&S(t,"!NOTATION",e)){e+=9;const{index:n}=this.readNotationExp(t,e+1,this.suppressValidationErr);e=n}else{if(!S(t,"!--",e))throw new Error("Invalid DOCTYPE");o=!0}s++,a=""}if(0!==s)throw new Error("Unclosed DOCTYPE")}return{entities:n,i:e}}readEntityExp(t,e){e=A(t,e);let n="";for(;e<t.length&&!/\s/.test(t[e])&&'"'!==t[e]&&"'"!==t[e];)n+=t[e],e++;if(C(n),e=A(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")}let i="";if([e,i]=this.readIdentifierVal(t,e,"entity"),!1!==this.options.enabled&&this.options.maxEntitySize&&i.length>this.options.maxEntitySize)throw new Error(`Entity "${n}" size (${i.length}) exceeds maximum allowed size (${this.options.maxEntitySize})`);return[n,i,--e]}readNotationExp(t,e){e=A(t,e);let n="";for(;e<t.length&&!/\s/.test(t[e]);)n+=t[e],e++;!this.suppressValidationErr&&C(n),e=A(t,e);const i=t.substring(e,e+6).toUpperCase();if(!this.suppressValidationErr&&"SYSTEM"!==i&&"PUBLIC"!==i)throw new Error(`Expected SYSTEM or PUBLIC, found "${i}"`);e+=i.length,e=A(t,e);let s=null,r=null;if("PUBLIC"===i)[e,s]=this.readIdentifierVal(t,e,"publicIdentifier"),'"'!==t[e=A(t,e)]&&"'"!==t[e]||([e,r]=this.readIdentifierVal(t,e,"systemIdentifier"));else if("SYSTEM"===i&&([e,r]=this.readIdentifierVal(t,e,"systemIdentifier"),!this.suppressValidationErr&&!r))throw new Error("Missing mandatory system identifier for SYSTEM notation");return{notationName:n,publicIdentifier:s,systemIdentifier:r,index:--e}}readIdentifierVal(t,e,n){let i="";const s=t[e];if('"'!==s&&"'"!==s)throw new Error(`Expected quoted string, found "${s}"`);for(e++;e<t.length&&t[e]!==s;)i+=t[e],e++;if(t[e]!==s)throw new Error(`Unterminated ${n} value`);return[++e,i]}readElementExp(t,e){e=A(t,e);let n="";for(;e<t.length&&!/\s/.test(t[e]);)n+=t[e],e++;if(!this.suppressValidationErr&&!r(n))throw new Error(`Invalid element name: "${n}"`);let i="";if("E"===t[e=A(t,e)]&&S(t,"MPTY",e))e+=4;else if("A"===t[e]&&S(t,"NY",e))e+=2;else if("("===t[e]){for(e++;e<t.length&&")"!==t[e];)i+=t[e],e++;if(")"!==t[e])throw new Error("Unterminated content model")}else if(!this.suppressValidationErr)throw new Error(`Invalid Element Expression, found "${t[e]}"`);return{elementName:n,contentModel:i.trim(),index:e}}readAttlistExp(t,e){e=A(t,e);let n="";for(;e<t.length&&!/\s/.test(t[e]);)n+=t[e],e++;C(n),e=A(t,e);let i="";for(;e<t.length&&!/\s/.test(t[e]);)i+=t[e],e++;if(!C(i))throw new Error(`Invalid attribute name: "${i}"`);e=A(t,e);let s="";if("NOTATION"===t.substring(e,e+8).toUpperCase()){if(s="NOTATION","("!==t[e=A(t,e+=8)])throw new Error(`Expected '(', found "${t[e]}"`);e++;let n=[];for(;e<t.length&&")"!==t[e];){let i="";for(;e<t.length&&"|"!==t[e]&&")"!==t[e];)i+=t[e],e++;if(i=i.trim(),!C(i))throw new Error(`Invalid notation name: "${i}"`);n.push(i),"|"===t[e]&&(e++,e=A(t,e))}if(")"!==t[e])throw new Error("Unterminated list of notations");e++,s+=" ("+n.join("|")+")"}else{for(;e<t.length&&!/\s/.test(t[e]);)s+=t[e],e++;const n=["CDATA","ID","IDREF","IDREFS","ENTITY","ENTITIES","NMTOKEN","NMTOKENS"];if(!this.suppressValidationErr&&!n.includes(s.toUpperCase()))throw new Error(`Invalid attribute type: "${s}"`)}e=A(t,e);let r="";return"#REQUIRED"===t.substring(e,e+8).toUpperCase()?(r="#REQUIRED",e+=8):"#IMPLIED"===t.substring(e,e+7).toUpperCase()?(r="#IMPLIED",e+=7):[e,r]=this.readIdentifierVal(t,e,"ATTLIST"),{elementName:n,attributeName:i,attributeType:s,defaultValue:r,index:e}}}const A=(t,e)=>{for(;e<t.length&&/\s/.test(t[e]);)e++;return e};function S(t,e,n){for(let i=0;i<e.length;i++)if(e[i]!==t[n+i+1])return!1;return!0}function C(t){if(r(t))return t;throw new Error(`Invalid entity name ${t}`)}const $=/^[-+]?0x[a-fA-F0-9]+$/,V=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,D={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};const j=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;class L{constructor(t){var e;if(this.options=t,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:"'"},gt:{regex:/&(gt|#62|#x3E);/g,val:">"},lt:{regex:/&(lt|#60|#x3C);/g,val:"<"},quot:{regex:/&(quot|#34|#x22);/g,val:'"'}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:"&"},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:" "},cent:{regex:/&(cent|#162);/g,val:"¢"},pound:{regex:/&(pound|#163);/g,val:"£"},yen:{regex:/&(yen|#165);/g,val:"¥"},euro:{regex:/&(euro|#8364);/g,val:"€"},copyright:{regex:/&(copy|#169);/g,val:"©"},reg:{regex:/&(reg|#174);/g,val:"®"},inr:{regex:/&(inr|#8377);/g,val:"₹"},num_dec:{regex:/&#([0-9]{1,7});/g,val:(t,e)=>K(e,10,"&#")},num_hex:{regex:/&#x([0-9a-fA-F]{1,6});/g,val:(t,e)=>K(e,16,"&#x")}},this.addExternalEntities=F,this.parseXml=R,this.parseTextData=M,this.resolveNameSpace=k,this.buildAttributesMap=U,this.isItStopNode=X,this.replaceEntitiesValue=Y,this.readStopNodeData=q,this.saveTextToParentTag=G,this.addChild=B,this.ignoreAttributesFn="function"==typeof(e=this.options.ignoreAttributes)?e:Array.isArray(e)?t=>{for(const n of e){if("string"==typeof n&&t===n)return!0;if(n instanceof RegExp&&n.test(t))return!0}}:()=>!1,this.entityExpansionCount=0,this.currentExpandedLength=0,this.options.stopNodes&&this.options.stopNodes.length>0){this.stopNodesExact=new Set,this.stopNodesWildcard=new Set;for(let t=0;t<this.options.stopNodes.length;t++){const e=this.options.stopNodes[t];"string"==typeof e&&(e.startsWith("*.")?this.stopNodesWildcard.add(e.substring(2)):this.stopNodesExact.add(e))}}}}function F(t){const e=Object.keys(t);for(let n=0;n<e.length;n++){const i=e[n],s=i.replace(/[.\-+*:]/g,"\\.");this.lastEntities[i]={regex:new RegExp("&"+s+";","g"),val:t[i]}}}function M(t,e,n,i,s,r,o){if(void 0!==t&&(this.options.trimValues&&!i&&(t=t.trim()),t.length>0)){o||(t=this.replaceEntitiesValue(t,e,n));const i=this.options.tagValueProcessor(e,t,n,s,r);return null==i?t:typeof i!=typeof t||i!==t?i:this.options.trimValues||t.trim()===t?Z(t,this.options.parseTagValue,this.options.numberParseOptions):t}}function k(t){if(this.options.removeNSPrefix){const e=t.split(":"),n="/"===t.charAt(0)?"/":"";if("xmlns"===e[0])return"";2===e.length&&(t=n+e[1])}return t}const _=new RegExp("([^\\s=]+)\\s*(=\\s*(['\"])([\\s\\S]*?)\\3)?","gm");function U(t,e,n){if(!0!==this.options.ignoreAttributes&&"string"==typeof t){const i=s(t,_),r=i.length,o={};for(let t=0;t<r;t++){const s=this.resolveNameSpace(i[t][1]);if(this.ignoreAttributesFn(s,e))continue;let r=i[t][4],a=this.options.attributeNamePrefix+s;if(s.length)if(this.options.transformAttributeName&&(a=this.options.transformAttributeName(a)),"__proto__"===a&&(a="#__proto__"),void 0!==r){this.options.trimValues&&(r=r.trim()),r=this.replaceEntitiesValue(r,n,e);const t=this.options.attributeValueProcessor(s,r,e);o[a]=null==t?r:typeof t!=typeof r||t!==r?t:Z(r,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(o[a]=!0)}if(!Object.keys(o).length)return;if(this.options.attributesGroupName){const t={};return t[this.options.attributesGroupName]=o,t}return o}}const R=function(t){t=t.replace(/\r\n?/g,"\n");const e=new I("!xml");let n=e,i="",s="";this.entityExpansionCount=0,this.currentExpandedLength=0;const r=new P(this.options.processEntities);for(let o=0;o<t.length;o++)if("<"===t[o])if("/"===t[o+1]){const e=z(t,">",o,"Closing Tag is not closed.");let r=t.substring(o+2,e).trim();if(this.options.removeNSPrefix){const t=r.indexOf(":");-1!==t&&(r=r.substr(t+1))}this.options.transformTagName&&(r=this.options.transformTagName(r)),n&&(i=this.saveTextToParentTag(i,n,s));const a=s.substring(s.lastIndexOf(".")+1);if(r&&-1!==this.options.unpairedTags.indexOf(r))throw new Error(`Unpaired tag can not be used as closing tag: </${r}>`);let l=0;a&&-1!==this.options.unpairedTags.indexOf(a)?(l=s.lastIndexOf(".",s.lastIndexOf(".")-1),this.tagsNodeStack.pop()):l=s.lastIndexOf("."),s=s.substring(0,l),n=this.tagsNodeStack.pop(),i="",o=e}else if("?"===t[o+1]){let e=W(t,o,!1,"?>");if(!e)throw new Error("Pi Tag is not closed.");if(i=this.saveTextToParentTag(i,n,s),this.options.ignoreDeclaration&&"?xml"===e.tagName||this.options.ignorePiTags);else{const t=new I(e.tagName);t.add(this.options.textNodeName,""),e.tagName!==e.tagExp&&e.attrExpPresent&&(t[":@"]=this.buildAttributesMap(e.tagExp,s,e.tagName)),this.addChild(n,t,s,o)}o=e.closeIndex+1}else if("!--"===t.substr(o+1,3)){const e=z(t,"--\x3e",o+4,"Comment is not closed.");if(this.options.commentPropName){const r=t.substring(o+4,e-2);i=this.saveTextToParentTag(i,n,s),n.add(this.options.commentPropName,[{[this.options.textNodeName]:r}])}o=e}else if("!D"===t.substr(o+1,2)){const e=r.readDocType(t,o);this.docTypeEntities=e.entities,o=e.i}else if("!["===t.substr(o+1,2)){const e=z(t,"]]>",o,"CDATA is not closed.")-2,r=t.substring(o+9,e);i=this.saveTextToParentTag(i,n,s);let a=this.parseTextData(r,n.tagname,s,!0,!1,!0,!0);null==a&&(a=""),this.options.cdataPropName?n.add(this.options.cdataPropName,[{[this.options.textNodeName]:r}]):n.add(this.options.textNodeName,a),o=e+2}else{let r=W(t,o,this.options.removeNSPrefix),a=r.tagName;const l=r.rawTagName;let u=r.tagExp,d=r.attrExpPresent,h=r.closeIndex;if(this.options.transformTagName){const t=this.options.transformTagName(a);u===a&&(u=t),a=t}if(this.options.strictReservedNames&&(a===this.options.commentPropName||a===this.options.cdataPropName))throw new Error(`Invalid tag name: ${a}`);n&&i&&"!xml"!==n.tagname&&(i=this.saveTextToParentTag(i,n,s,!1));const p=n;p&&-1!==this.options.unpairedTags.indexOf(p.tagname)&&(n=this.tagsNodeStack.pop(),s=s.substring(0,s.lastIndexOf("."))),a!==e.tagname&&(s+=s?"."+a:a);const c=o;if(this.isItStopNode(this.stopNodesExact,this.stopNodesWildcard,s,a)){let e="";if(u.length>0&&u.lastIndexOf("/")===u.length-1)"/"===a[a.length-1]?(a=a.substr(0,a.length-1),s=s.substr(0,s.length-1),u=a):u=u.substr(0,u.length-1),o=r.closeIndex;else if(-1!==this.options.unpairedTags.indexOf(a))o=r.closeIndex;else{const n=this.readStopNodeData(t,l,h+1);if(!n)throw new Error(`Unexpected end of ${l}`);o=n.i,e=n.tagContent}const i=new I(a);a!==u&&d&&(i[":@"]=this.buildAttributesMap(u,s,a)),e&&(e=this.parseTextData(e,a,s,!0,d,!0,!0)),s=s.substr(0,s.lastIndexOf(".")),i.add(this.options.textNodeName,e),this.addChild(n,i,s,c)}else{if(u.length>0&&u.lastIndexOf("/")===u.length-1){if("/"===a[a.length-1]?(a=a.substr(0,a.length-1),s=s.substr(0,s.length-1),u=a):u=u.substr(0,u.length-1),this.options.transformTagName){const t=this.options.transformTagName(a);u===a&&(u=t),a=t}const t=new I(a);a!==u&&d&&(t[":@"]=this.buildAttributesMap(u,s,a)),this.addChild(n,t,s,c),s=s.substr(0,s.lastIndexOf("."))}else{if(-1!==this.options.unpairedTags.indexOf(a)){const t=new I(a);a!==u&&d&&(t[":@"]=this.buildAttributesMap(u,s)),this.addChild(n,t,s,c),s=s.substr(0,s.lastIndexOf(".")),o=r.closeIndex;continue}{const t=new I(a);if(this.tagsNodeStack.length>this.options.maxNestedTags)throw new Error("Maximum nested tags exceeded");this.tagsNodeStack.push(n),a!==u&&d&&(t[":@"]=this.buildAttributesMap(u,s,a)),this.addChild(n,t,s,c),n=t}}i="",o=h}}else i+=t[o];return e.child};function B(t,e,n,i){this.options.captureMetaData||(i=void 0);const s=this.options.updateTag(e.tagname,n,e[":@"]);!1===s||("string"==typeof s?(e.tagname=s,t.addChild(e,i)):t.addChild(e,i))}const Y=function(t,e,n){if(-1===t.indexOf("&"))return t;const i=this.options.processEntities;if(!i.enabled)return t;if(i.allowedTags&&!i.allowedTags.includes(e))return t;if(i.tagFilter&&!i.tagFilter(e,n))return t;for(let e in this.docTypeEntities){const n=this.docTypeEntities[e],s=t.match(n.regx);if(s){if(this.entityExpansionCount+=s.length,i.maxTotalExpansions&&this.entityExpansionCount>i.maxTotalExpansions)throw new Error(`Entity expansion limit exceeded: ${this.entityExpansionCount} > ${i.maxTotalExpansions}`);const e=t.length;if(t=t.replace(n.regx,n.val),i.maxExpandedLength&&(this.currentExpandedLength+=t.length-e,this.currentExpandedLength>i.maxExpandedLength))throw new Error(`Total expanded content size exceeded: ${this.currentExpandedLength} > ${i.maxExpandedLength}`)}}if(-1===t.indexOf("&"))return t;for(let e in this.lastEntities){const n=this.lastEntities[e];t=t.replace(n.regex,n.val)}if(-1===t.indexOf("&"))return t;if(this.options.htmlEntities)for(let e in this.htmlEntities){const n=this.htmlEntities[e];t=t.replace(n.regex,n.val)}return t.replace(this.ampEntity.regex,this.ampEntity.val)};function G(t,e,n,i){return t&&(void 0===i&&(i=0===e.child.length),void 0!==(t=this.parseTextData(t,e.tagname,n,!1,!!e[":@"]&&0!==Object.keys(e[":@"]).length,i))&&""!==t&&e.add(this.options.textNodeName,t),t=""),t}function X(t,e,n,i){return!(!e||!e.has(i))||!(!t||!t.has(n))}function z(t,e,n,i){const s=t.indexOf(e,n);if(-1===s)throw new Error(i);return s+e.length-1}function W(t,e,n,i=">"){const s=function(t,e,n=">"){let i,s="";for(let r=e;r<t.length;r++){let e=t[r];if(i)e===i&&(i="");else if('"'===e||"'"===e)i=e;else if(e===n[0]){if(!n[1])return{data:s,index:r};if(t[r+1]===n[1])return{data:s,index:r}}else"\t"===e&&(e=" ");s+=e}}(t,e+1,i);if(!s)return;let r=s.data;const o=s.index,a=r.search(/\s/);let l=r,u=!0;-1!==a&&(l=r.substring(0,a),r=r.substring(a+1).trimStart());const d=l;if(n){const t=l.indexOf(":");-1!==t&&(l=l.substr(t+1),u=l!==s.data.substr(t+1))}return{tagName:l,tagExp:r,closeIndex:o,attrExpPresent:u,rawTagName:d}}function q(t,e,n){const i=n;let s=1;for(;n<t.length;n++)if("<"===t[n])if("/"===t[n+1]){const r=z(t,">",n,`${e} is not closed`);if(t.substring(n+2,r).trim()===e&&(s--,0===s))return{tagContent:t.substring(i,n),i:r};n=r}else if("?"===t[n+1])n=z(t,"?>",n+1,"StopNode is not closed.");else if("!--"===t.substr(n+1,3))n=z(t,"--\x3e",n+3,"StopNode is not closed.");else if("!["===t.substr(n+1,2))n=z(t,"]]>",n,"StopNode is not closed.")-2;else{const i=W(t,n,">");i&&((i&&i.tagName)===e&&"/"!==i.tagExp[i.tagExp.length-1]&&s++,n=i.closeIndex)}}function Z(t,e,n){if(e&&"string"==typeof t){const e=t.trim();return"true"===e||"false"!==e&&function(t,e={}){if(e=Object.assign({},D,e),!t||"string"!=typeof t)return t;let n=t.trim();if(void 0!==e.skipLike&&e.skipLike.test(n))return t;if("0"===t)return 0;if(e.hex&&$.test(n))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")}(n);if(n.includes("e")||n.includes("E"))return function(t,e,n){if(!n.eNotation)return t;const i=e.match(j);if(i){let s=i[1]||"";const r=-1===i[3].indexOf("e")?"E":"e",o=i[2],a=s?t[o.length+1]===r:t[o.length]===r;return o.length>1&&a?t:1!==o.length||!i[3].startsWith(`.${r}`)&&i[3][0]!==r?n.leadingZeros&&!a?(e=(i[1]||"")+i[3],Number(e)):t:Number(e)}return t}(t,n,e);{const s=V.exec(n);if(s){const r=s[1]||"",o=s[2];let a=(i=s[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 l=r?"."===t[o.length+1]:"."===t[o.length];if(!e.leadingZeros&&(o.length>1||1===o.length&&!l))return t;{const i=Number(n),s=String(i);if(0===i)return i;if(-1!==s.search(/[eE]/))return e.eNotation?i:t;if(-1!==n.indexOf("."))return"0"===s||s===a||s===`${r}${a}`?i:t;let l=o?a:n;return o?l===s||r+l===s?i:t:l===s||l===r+s?i:t}}return t}var i}(t,n)}return void 0!==t?t:""}function K(t,e,n){const i=Number.parseInt(t,e);return i>=0&&i<=1114111?String.fromCodePoint(i):n+t+";"}const Q=I.getMetaDataSymbol();function J(t,e){return H(t,e)}function H(t,e,n){let i;const s={};for(let r=0;r<t.length;r++){const o=t[r],a=tt(o);let l="";if(l=void 0===n?a:n+"."+a,a===e.textNodeName)void 0===i?i=o[a]:i+=""+o[a];else{if(void 0===a)continue;if(o[a]){let t=H(o[a],e,l);const n=nt(t,e);o[":@"]?et(t,o[":@"],l,e):1!==Object.keys(t).length||void 0===t[e.textNodeName]||e.alwaysCreateTextNode?0===Object.keys(t).length&&(e.alwaysCreateTextNode?t[e.textNodeName]="":t=""):t=t[e.textNodeName],void 0!==o[Q]&&"object"==typeof t&&null!==t&&(t[Q]=o[Q]),void 0!==s[a]&&Object.prototype.hasOwnProperty.call(s,a)?(Array.isArray(s[a])||(s[a]=[s[a]]),s[a].push(t)):e.isArray(a,l,n)?s[a]=[t]:s[a]=t}}}return"string"==typeof i?i.length>0&&(s[e.textNodeName]=i):void 0!==i&&(s[e.textNodeName]=i),s}function tt(t){const e=Object.keys(t);for(let t=0;t<e.length;t++){const n=e[t];if(":@"!==n)return n}}function et(t,e,n,i){if(e){const s=Object.keys(e),r=s.length;for(let o=0;o<r;o++){const r=s[o];i.isArray(r,n+"."+r,!0,!0)?t[r]=[e[r]]:t[r]=e[r]}}}function nt(t,e){const{textNodeName:n}=e,i=Object.keys(t).length;return 0===i||!(1!==i||!t[n]&&"boolean"!=typeof t[n]&&0!==t[n])}class it{constructor(t){this.externalEntities={},this.options=v(t)}parse(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={});const n=a(t,e);if(!0!==n)throw Error(`${n.err.msg}:${n.err.line}:${n.err.col}`)}const n=new L(this.options);n.addExternalEntities(this.externalEntities);const i=n.parseXml(t);return this.options.preserveOrder||void 0===i?i:J(i,this.options)}addEntity(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 '
'");if("&"===e)throw new Error("An entity with value '&' is not permitted");this.externalEntities[t]=e}static getMetaDataSymbol(){return I.getMetaDataSymbol()}}function st(t,e){let n="";return e.format&&e.indentBy.length>0&&(n="\n"),rt(t,e,"",n)}function rt(t,e,n,i){let s="",r=!1;if(!Array.isArray(t)){if(null!=t){let n=t.toString();return n=ut(n,e),n}return""}for(let o=0;o<t.length;o++){const a=t[o],l=ot(a);if(void 0===l)continue;let u="";if(u=0===n.length?l:`${n}.${l}`,l===e.textNodeName){let t=a[l];lt(u,e)||(t=e.tagValueProcessor(l,t),t=ut(t,e)),r&&(s+=i),s+=t,r=!1;continue}if(l===e.cdataPropName){r&&(s+=i),s+=`<![CDATA[${a[l][0][e.textNodeName]}]]>`,r=!1;continue}if(l===e.commentPropName){s+=i+`\x3c!--${a[l][0][e.textNodeName]}--\x3e`,r=!0;continue}if("?"===l[0]){const t=at(a[":@"],e),n="?xml"===l?"":i;let o=a[l][0][e.textNodeName];o=0!==o.length?" "+o:"",s+=n+`<${l}${o}${t}?>`,r=!0;continue}let d=i;""!==d&&(d+=e.indentBy);const h=i+`<${l}${at(a[":@"],e)}`,p=rt(a[l],e,u,d);-1!==e.unpairedTags.indexOf(l)?e.suppressUnpairedNode?s+=h+">":s+=h+"/>":p&&0!==p.length||!e.suppressEmptyNode?p&&p.endsWith(">")?s+=h+`>${p}${i}</${l}>`:(s+=h+">",p&&""!==i&&(p.includes("/>")||p.includes("</"))?s+=i+e.indentBy+p+i:s+=p,s+=`</${l}>`):s+=h+"/>",r=!0}return s}function ot(t){const e=Object.keys(t);for(let n=0;n<e.length;n++){const i=e[n];if(Object.prototype.hasOwnProperty.call(t,i)&&":@"!==i)return i}}function at(t,e){let n="";if(t&&!e.ignoreAttributes)for(let i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;let s=e.attributeValueProcessor(i,t[i]);s=ut(s,e),!0===s&&e.suppressBooleanAttributes?n+=` ${i.substr(e.attributeNamePrefix.length)}`:n+=` ${i.substr(e.attributeNamePrefix.length)}="${s}"`}return n}function lt(t,e){let n=(t=t.substr(0,t.length-e.textNodeName.length-1)).substr(t.lastIndexOf(".")+1);for(let i in e.stopNodes)if(e.stopNodes[i]===t||e.stopNodes[i]==="*."+n)return!0;return!1}function ut(t,e){if(t&&t.length>0&&e.processEntities)for(let n=0;n<e.entities.length;n++){const i=e.entities[n];t=t.replace(i.regex,i.val)}return t}const dt={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:"&"},{regex:new RegExp(">","g"),val:">"},{regex:new RegExp("<","g"),val:"<"},{regex:new RegExp("'","g"),val:"'"},{regex:new RegExp('"',"g"),val:"""}],processEntities:!0,stopNodes:[],oneListGroup:!1};function ht(t){var e;this.options=Object.assign({},dt,t),!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 n of e){if("string"==typeof n&&t===n)return!0;if(n instanceof RegExp&&n.test(t))return!0}}:()=>!1,this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=ft),this.processTextOrObjNode=pt,this.options.format?(this.indentate=ct,this.tagEndChar=">\n",this.newLine="\n"):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}function pt(t,e,n,i){const s=this.j2x(t,n+1,i.concat(e));return void 0!==t[this.options.textNodeName]&&1===Object.keys(t).length?this.buildTextValNode(t[this.options.textNodeName],e,s.attrStr,n):this.buildObjectNode(s.val,e,s.attrStr,n)}function ct(t){return this.options.indentBy.repeat(t)}function ft(t){return!(!t.startsWith(this.options.attributeNamePrefix)||t===this.options.textNodeName)&&t.substr(this.attrPrefixLen)}ht.prototype.build=function(t){return this.options.preserveOrder?st(t,this.options):(Array.isArray(t)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(t={[this.options.arrayNodeName]:t}),this.j2x(t,0,[]).val)},ht.prototype.j2x=function(t,e,n){let i="",s="";const r=n.join(".");for(let o in t)if(Object.prototype.hasOwnProperty.call(t,o))if(void 0===t[o])this.isAttribute(o)&&(s+="");else if(null===t[o])this.isAttribute(o)||o===this.options.cdataPropName?s+="":"?"===o[0]?s+=this.indentate(e)+"<"+o+"?"+this.tagEndChar:s+=this.indentate(e)+"<"+o+"/"+this.tagEndChar;else if(t[o]instanceof Date)s+=this.buildTextValNode(t[o],o,"",e);else if("object"!=typeof t[o]){const n=this.isAttribute(o);if(n&&!this.ignoreAttributesFn(n,r))i+=this.buildAttrPairStr(n,""+t[o]);else if(!n)if(o===this.options.textNodeName){let e=this.options.tagValueProcessor(o,""+t[o]);s+=this.replaceEntitiesValue(e)}else s+=this.buildTextValNode(t[o],o,"",e)}else if(Array.isArray(t[o])){const i=t[o].length;let r="",a="";for(let l=0;l<i;l++){const i=t[o][l];if(void 0===i);else if(null===i)"?"===o[0]?s+=this.indentate(e)+"<"+o+"?"+this.tagEndChar:s+=this.indentate(e)+"<"+o+"/"+this.tagEndChar;else if("object"==typeof i)if(this.options.oneListGroup){const t=this.j2x(i,e+1,n.concat(o));r+=t.val,this.options.attributesGroupName&&i.hasOwnProperty(this.options.attributesGroupName)&&(a+=t.attrStr)}else r+=this.processTextOrObjNode(i,o,e,n);else if(this.options.oneListGroup){let t=this.options.tagValueProcessor(o,i);t=this.replaceEntitiesValue(t),r+=t}else r+=this.buildTextValNode(i,o,"",e)}this.options.oneListGroup&&(r=this.buildObjectNode(r,o,a,e)),s+=r}else if(this.options.attributesGroupName&&o===this.options.attributesGroupName){const e=Object.keys(t[o]),n=e.length;for(let s=0;s<n;s++)i+=this.buildAttrPairStr(e[s],""+t[o][e[s]])}else s+=this.processTextOrObjNode(t[o],o,e,n);return{attrStr:i,val:s}},ht.prototype.buildAttrPairStr=function(t,e){return e=this.options.attributeValueProcessor(t,""+e),e=this.replaceEntitiesValue(e),this.options.suppressBooleanAttributes&&"true"===e?" "+t:" "+t+'="'+e+'"'},ht.prototype.buildObjectNode=function(t,e,n,i){if(""===t)return"?"===e[0]?this.indentate(i)+"<"+e+n+"?"+this.tagEndChar:this.indentate(i)+"<"+e+n+this.closeTag(e)+this.tagEndChar;{let s="</"+e+this.tagEndChar,r="";return"?"===e[0]&&(r="?",s=""),!n&&""!==n||-1!==t.indexOf("<")?!1!==this.options.commentPropName&&e===this.options.commentPropName&&0===r.length?this.indentate(i)+`\x3c!--${t}--\x3e`+this.newLine:this.indentate(i)+"<"+e+n+r+this.tagEndChar+t+this.indentate(i)+s:this.indentate(i)+"<"+e+n+r+">"+t+s}},ht.prototype.closeTag=function(t){let e="";return-1!==this.options.unpairedTags.indexOf(t)?this.options.suppressUnpairedNode||(e="/"):e=this.options.suppressEmptyNode?"/":`></${t}`,e},ht.prototype.buildTextValNode=function(t,e,n,i){if(!1!==this.options.cdataPropName&&e===this.options.cdataPropName)return this.indentate(i)+`<![CDATA[${t}]]>`+this.newLine;if(!1!==this.options.commentPropName&&e===this.options.commentPropName)return this.indentate(i)+`\x3c!--${t}--\x3e`+this.newLine;if("?"===e[0])return this.indentate(i)+"<"+e+n+"?"+this.tagEndChar;{let s=this.options.tagValueProcessor(e,t);return s=this.replaceEntitiesValue(s),""===s?this.indentate(i)+"<"+e+n+this.closeTag(e)+this.tagEndChar:this.indentate(i)+"<"+e+n+">"+s+"</"+e+this.tagEndChar}},ht.prototype.replaceEntitiesValue=function(t){if(t&&t.length>0&&this.options.processEntities)for(let e=0;e<this.options.entities.length;e++){const n=this.options.entities[e];t=t.replace(n.regex,n.val)}return t};const gt=ht,xt={validate:a};module.exports=e})(); | ||
| (()=>{"use strict";var t={d:(e,i)=>{for(var n in i)t.o(i,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:i[n]})},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:()=>Tt,XMLParser:()=>ht,XMLValidator:()=>Pt});const i=":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",n=new RegExp("^["+i+"]["+i+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040]*$");function s(t,e){const i=[];let n=e.exec(t);for(;n;){const s=[];s.startIndex=e.lastIndex-n[0].length;const r=n.length;for(let t=0;t<r;t++)s.push(n[t]);i.push(s),n=e.exec(t)}return i}const r=function(t){return!(null==n.exec(t))},o={allowBooleanAttributes:!1,unpairedTags:[]};function a(t,e){e=Object.assign({},o,e);const i=[];let n=!1,s=!1;"\ufeff"===t[0]&&(t=t.substr(1));for(let r=0;r<t.length;r++)if("<"===t[r]&&"?"===t[r+1]){if(r+=2,r=l(t,r),r.err)return r}else{if("<"!==t[r]){if(h(t[r]))continue;return x("InvalidChar","char '"+t[r]+"' is not expected.",E(t,r))}{let o=r;if(r++,"!"===t[r]){r=p(t,r);continue}{let a=!1;"/"===t[r]&&(a=!0,r++);let u="";for(;r<t.length&&">"!==t[r]&&" "!==t[r]&&"\t"!==t[r]&&"\n"!==t[r]&&"\r"!==t[r];r++)u+=t[r];if(u=u.trim(),"/"===u[u.length-1]&&(u=u.substring(0,u.length-1),r--),!N(u)){let e;return e=0===u.trim().length?"Invalid space after '<'.":"Tag '"+u+"' is an invalid name.",x("InvalidTag",e,E(t,r))}const c=d(t,r);if(!1===c)return x("InvalidAttr","Attributes for '"+u+"' have open quote.",E(t,r));let g=c.value;if(r=c.index,"/"===g[g.length-1]){const i=r-g.length;g=g.substring(0,g.length-1);const s=f(g,e);if(!0!==s)return x(s.err.code,s.err.msg,E(t,i+s.err.line));n=!0}else if(a){if(!c.tagClosed)return x("InvalidTag","Closing tag '"+u+"' doesn't have proper closing.",E(t,r));if(g.trim().length>0)return x("InvalidTag","Closing tag '"+u+"' can't have attributes or invalid starting.",E(t,o));if(0===i.length)return x("InvalidTag","Closing tag '"+u+"' has not been opened.",E(t,o));{const e=i.pop();if(u!==e.tagName){let i=E(t,e.tagStartPos);return x("InvalidTag","Expected closing tag '"+e.tagName+"' (opened in line "+i.line+", col "+i.col+") instead of closing tag '"+u+"'.",E(t,o))}0==i.length&&(s=!0)}}else{const a=f(g,e);if(!0!==a)return x(a.err.code,a.err.msg,E(t,r-g.length+a.err.line));if(!0===s)return x("InvalidXml","Multiple possible root nodes found.",E(t,r));-1!==e.unpairedTags.indexOf(u)||i.push({tagName:u,tagStartPos:o}),n=!0}for(r++;r<t.length;r++)if("<"===t[r]){if("!"===t[r+1]){r++,r=p(t,r);continue}if("?"!==t[r+1])break;if(r=l(t,++r),r.err)return r}else if("&"===t[r]){const e=m(t,r);if(-1==e)return x("InvalidChar","char '&' is not expected.",E(t,r));r=e}else if(!0===s&&!h(t[r]))return x("InvalidXml","Extra text at the end",E(t,r));"<"===t[r]&&r--}}}return n?1==i.length?x("InvalidTag","Unclosed tag '"+i[0].tagName+"'.",E(t,i[0].tagStartPos)):!(i.length>0)||x("InvalidXml","Invalid '"+JSON.stringify(i.map(t=>t.tagName),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1}):x("InvalidXml","Start tag expected.",1)}function h(t){return" "===t||"\t"===t||"\n"===t||"\r"===t}function l(t,e){const i=e;for(;e<t.length;e++)if("?"==t[e]||" "==t[e]){const n=t.substr(i,e-i);if(e>5&&"xml"===n)return x("InvalidXml","XML declaration allowed only at the start of the document.",E(t,e));if("?"==t[e]&&">"==t[e+1]){e++;break}continue}return e}function p(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]){let i=1;for(e+=8;e<t.length;e++)if("<"===t[e])i++;else if(">"===t[e]&&(i--,0===i))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}const u='"',c="'";function d(t,e){let i="",n="",s=!1;for(;e<t.length;e++){if(t[e]===u||t[e]===c)""===n?n=t[e]:n!==t[e]||(n="");else if(">"===t[e]&&""===n){s=!0;break}i+=t[e]}return""===n&&{value:i,index:e,tagClosed:s}}const g=new RegExp("(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['\"])(([\\s\\S])*?)\\5)?","g");function f(t,e){const i=s(t,g),n={};for(let t=0;t<i.length;t++){if(0===i[t][1].length)return x("InvalidAttr","Attribute '"+i[t][2]+"' has no space in starting.",y(i[t]));if(void 0!==i[t][3]&&void 0===i[t][4])return x("InvalidAttr","Attribute '"+i[t][2]+"' is without value.",y(i[t]));if(void 0===i[t][3]&&!e.allowBooleanAttributes)return x("InvalidAttr","boolean attribute '"+i[t][2]+"' is not allowed.",y(i[t]));const s=i[t][2];if(!b(s))return x("InvalidAttr","Attribute '"+s+"' is an invalid name.",y(i[t]));if(Object.prototype.hasOwnProperty.call(n,s))return x("InvalidAttr","Attribute '"+s+"' is repeated.",y(i[t]));n[s]=1}return!0}function m(t,e){if(";"===t[++e])return-1;if("#"===t[e])return function(t,e){let i=/\d/;for("x"===t[e]&&(e++,i=/[\da-fA-F]/);e<t.length;e++){if(";"===t[e])return e;if(!t[e].match(i))break}return-1}(t,++e);let i=0;for(;e<t.length;e++,i++)if(!(t[e].match(/\w/)&&i<20)){if(";"===t[e])break;return-1}return e}function x(t,e,i){return{err:{code:t,msg:e,line:i.line||i,col:i.col}}}function b(t){return r(t)}function N(t){return r(t)}function E(t,e){const i=t.substring(0,e).split(/\r?\n/);return{line:i.length,col:i[i.length-1].length+1}}function y(t){return t.startIndex+t[1].length}const v={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:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(t,e,i){return t},captureMetaData:!1,maxNestedTags:100,strictReservedNames:!0,jPath:!0};function w(t){return"boolean"==typeof t?{enabled:t,maxEntitySize:1e4,maxExpansionDepth:10,maxTotalExpansions:1e3,maxExpandedLength:1e5,maxEntityCount:100,allowedTags:null,tagFilter:null}:"object"==typeof t&&null!==t?{enabled:!1!==t.enabled,maxEntitySize:t.maxEntitySize??1e4,maxExpansionDepth:t.maxExpansionDepth??10,maxTotalExpansions:t.maxTotalExpansions??1e3,maxExpandedLength:t.maxExpandedLength??1e5,maxEntityCount:t.maxEntityCount??100,allowedTags:t.allowedTags??null,tagFilter:t.tagFilter??null}:w(!0)}const S=function(t){const e=Object.assign({},v,t);return e.processEntities=w(e.processEntities),e.stopNodes&&Array.isArray(e.stopNodes)&&(e.stopNodes=e.stopNodes.map(t=>"string"==typeof t&&t.startsWith("*.")?".."+t.substring(2):t)),e};let T;T="function"!=typeof Symbol?"@@xmlMetadata":Symbol("XML Node Metadata");class P{constructor(t){this.tagname=t,this.child=[],this[":@"]=Object.create(null)}add(t,e){"__proto__"===t&&(t="#__proto__"),this.child.push({[t]:e})}addChild(t,e){"__proto__"===t.tagname&&(t.tagname="#__proto__"),t[":@"]&&Object.keys(t[":@"]).length>0?this.child.push({[t.tagname]:t.child,":@":t[":@"]}):this.child.push({[t.tagname]:t.child}),void 0!==e&&(this.child[this.child.length-1][T]={startIndex:e})}static getMetaDataSymbol(){return T}}class A{constructor(t){this.suppressValidationErr=!t,this.options=t}readDocType(t,e){const i=Object.create(null);let n=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;let s=1,r=!1,o=!1,a="";for(;e<t.length;e++)if("<"!==t[e]||o)if(">"===t[e]){if(o?"-"===t[e-1]&&"-"===t[e-2]&&(o=!1,s--):s--,0===s)break}else"["===t[e]?r=!0:a+=t[e];else{if(r&&C(t,"!ENTITY",e)){let s,r;if(e+=7,[s,r,e]=this.readEntityExp(t,e+1,this.suppressValidationErr),-1===r.indexOf("&")){if(!1!==this.options.enabled&&this.options.maxEntityCount&&n>=this.options.maxEntityCount)throw new Error(`Entity count (${n+1}) exceeds maximum allowed (${this.options.maxEntityCount})`);const t=s.replace(/[.\-+*:]/g,"\\.");i[s]={regx:RegExp(`&${t};`,"g"),val:r},n++}}else if(r&&C(t,"!ELEMENT",e)){e+=8;const{index:i}=this.readElementExp(t,e+1);e=i}else if(r&&C(t,"!ATTLIST",e))e+=8;else if(r&&C(t,"!NOTATION",e)){e+=9;const{index:i}=this.readNotationExp(t,e+1,this.suppressValidationErr);e=i}else{if(!C(t,"!--",e))throw new Error("Invalid DOCTYPE");o=!0}s++,a=""}if(0!==s)throw new Error("Unclosed DOCTYPE")}return{entities:i,i:e}}readEntityExp(t,e){e=O(t,e);let i="";for(;e<t.length&&!/\s/.test(t[e])&&'"'!==t[e]&&"'"!==t[e];)i+=t[e],e++;if($(i),e=O(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")}let n="";if([e,n]=this.readIdentifierVal(t,e,"entity"),!1!==this.options.enabled&&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]}readNotationExp(t,e){e=O(t,e);let i="";for(;e<t.length&&!/\s/.test(t[e]);)i+=t[e],e++;!this.suppressValidationErr&&$(i),e=O(t,e);const 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=O(t,e);let s=null,r=null;if("PUBLIC"===n)[e,s]=this.readIdentifierVal(t,e,"publicIdentifier"),'"'!==t[e=O(t,e)]&&"'"!==t[e]||([e,r]=this.readIdentifierVal(t,e,"systemIdentifier"));else if("SYSTEM"===n&&([e,r]=this.readIdentifierVal(t,e,"systemIdentifier"),!this.suppressValidationErr&&!r))throw new Error("Missing mandatory system identifier for SYSTEM notation");return{notationName:i,publicIdentifier:s,systemIdentifier:r,index:--e}}readIdentifierVal(t,e,i){let n="";const s=t[e];if('"'!==s&&"'"!==s)throw new Error(`Expected quoted string, found "${s}"`);for(e++;e<t.length&&t[e]!==s;)n+=t[e],e++;if(t[e]!==s)throw new Error(`Unterminated ${i} value`);return[++e,n]}readElementExp(t,e){e=O(t,e);let i="";for(;e<t.length&&!/\s/.test(t[e]);)i+=t[e],e++;if(!this.suppressValidationErr&&!r(i))throw new Error(`Invalid element name: "${i}"`);let n="";if("E"===t[e=O(t,e)]&&C(t,"MPTY",e))e+=4;else if("A"===t[e]&&C(t,"NY",e))e+=2;else if("("===t[e]){for(e++;e<t.length&&")"!==t[e];)n+=t[e],e++;if(")"!==t[e])throw new Error("Unterminated content model")}else if(!this.suppressValidationErr)throw new Error(`Invalid Element Expression, found "${t[e]}"`);return{elementName:i,contentModel:n.trim(),index:e}}readAttlistExp(t,e){e=O(t,e);let i="";for(;e<t.length&&!/\s/.test(t[e]);)i+=t[e],e++;$(i),e=O(t,e);let n="";for(;e<t.length&&!/\s/.test(t[e]);)n+=t[e],e++;if(!$(n))throw new Error(`Invalid attribute name: "${n}"`);e=O(t,e);let s="";if("NOTATION"===t.substring(e,e+8).toUpperCase()){if(s="NOTATION","("!==t[e=O(t,e+=8)])throw new Error(`Expected '(', found "${t[e]}"`);e++;let i=[];for(;e<t.length&&")"!==t[e];){let n="";for(;e<t.length&&"|"!==t[e]&&")"!==t[e];)n+=t[e],e++;if(n=n.trim(),!$(n))throw new Error(`Invalid notation name: "${n}"`);i.push(n),"|"===t[e]&&(e++,e=O(t,e))}if(")"!==t[e])throw new Error("Unterminated list of notations");e++,s+=" ("+i.join("|")+")"}else{for(;e<t.length&&!/\s/.test(t[e]);)s+=t[e],e++;const i=["CDATA","ID","IDREF","IDREFS","ENTITY","ENTITIES","NMTOKEN","NMTOKENS"];if(!this.suppressValidationErr&&!i.includes(s.toUpperCase()))throw new Error(`Invalid attribute type: "${s}"`)}e=O(t,e);let r="";return"#REQUIRED"===t.substring(e,e+8).toUpperCase()?(r="#REQUIRED",e+=8):"#IMPLIED"===t.substring(e,e+7).toUpperCase()?(r="#IMPLIED",e+=7):[e,r]=this.readIdentifierVal(t,e,"ATTLIST"),{elementName:i,attributeName:n,attributeType:s,defaultValue:r,index:e}}}const O=(t,e)=>{for(;e<t.length&&/\s/.test(t[e]);)e++;return e};function C(t,e,i){for(let n=0;n<e.length;n++)if(e[n]!==t[i+n+1])return!1;return!0}function $(t){if(r(t))return t;throw new Error(`Invalid entity name ${t}`)}const I=/^[-+]?0x[a-fA-F0-9]+$/,j=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,_={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};const V=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;class k{constructor(t,e={}){this.pattern=t,this.separator=e.separator||".",this.segments=this._parse(t),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 i=0,n="";for(;i<t.length;)t[i]===this.separator?i+1<t.length&&t[i+1]===this.separator?(n.trim()&&(e.push(this._parseSegment(n.trim())),n=""),e.push({type:"deep-wildcard"}),i+=2):(n.trim()&&e.push(this._parseSegment(n.trim())),n="",i++):(n+=t[i],i++);return n.trim()&&e.push(this._parseSegment(n.trim())),e}_parseSegment(t){const e={type:"tag"};let i=null,n=t;const s=t.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);if(s&&(n=s[1]+s[3],s[2])){const t=s[2].slice(1,-1);t&&(i=t)}let r,o,a=n;if(n.includes("::")){const e=n.indexOf("::");if(r=n.substring(0,e).trim(),a=n.substring(e+2).trim(),!r)throw new Error(`Invalid namespace in pattern: ${t}`)}let h=null;if(a.includes(":")){const t=a.lastIndexOf(":"),e=a.substring(0,t).trim(),i=a.substring(t+1).trim();["first","last","odd","even"].includes(i)||/^nth\(\d+\)$/.test(i)?(o=e,h=i):o=a}else o=a;if(!o)throw new Error(`Invalid segment pattern: ${t}`);if(e.tag=o,r&&(e.namespace=r),i)if(i.includes("=")){const t=i.indexOf("=");e.attrName=i.substring(0,t).trim(),e.attrValue=i.substring(t+1).trim()}else e.attrName=i.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 D{constructor(t={}){this.separator=t.separator||".",this.path=[],this.siblingStacks=[]}push(t,e=null,i=null){this.path.length>0&&(this.path[this.path.length-1].values=void 0);const n=this.path.length;this.siblingStacks[n]||(this.siblingStacks[n]=new Map);const s=this.siblingStacks[n],r=i?`${i}:${t}`:t,o=s.get(r)||0;let a=0;for(const t of s.values())a+=t;s.set(r,o+1);const h={tag:t,position:a,counter:o};null!=i&&(h.namespace=i),null!=e&&(h.values=e),this.path.push(h)}pop(){if(0===this.path.length)return;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;const e=this.path[this.path.length-1];return e.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 i=t||this.separator;return this.path.map(t=>e&&t.namespace?`${t.namespace}:${t.tag}`:t.tag).join(i)}toArray(){return this.path.map(t=>t.tag)}reset(){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++){const i=t[e],n=this.path[e],s=e===this.path.length-1;if(!this._matchSegment(i,n,s))return!1}return!0}_matchWithDeepWildcard(t){let e=this.path.length-1,i=t.length-1;for(;i>=0&&e>=0;){const n=t[i];if("deep-wildcard"===n.type){if(i--,i<0)return!0;const n=t[i];let s=!1;for(let t=e;t>=0;t--){const r=t===this.path.length-1;if(this._matchSegment(n,this.path[t],r)){e=t-1,i--,s=!0;break}}if(!s)return!1}else{const t=e===this.path.length-1;if(!this._matchSegment(n,this.path[e],t))return!1;e--,i--}}return i<0}_matchSegment(t,e,i){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(!i)return!1;if(!e.values||!(t.attrName in e.values))return!1;if(void 0!==t.attrValue){const i=e.values[t.attrName];if(String(i)!==String(t.attrValue))return!1}}if(void 0!==t.position){if(!i)return!1;const n=e.counter??0;if("first"===t.position&&0!==n)return!1;if("odd"===t.position&&n%2!=1)return!1;if("even"===t.position&&n%2!=0)return!1;if("nth"===t.position&&n!==t.positionValue)return!1}return!0}snapshot(){return{path:this.path.map(t=>({...t})),siblingStacks:this.siblingStacks.map(t=>new Map(t))}}restore(t){this.path=t.path.map(t=>({...t})),this.siblingStacks=t.siblingStacks.map(t=>new Map(t))}}function M(t,e){if(!t)return{};const i=e.attributesGroupName?t[e.attributesGroupName]:t;if(!i)return{};const n={};for(const t in i)t.startsWith(e.attributeNamePrefix)?n[t.substring(e.attributeNamePrefix.length)]=i[t]:n[t]=i[t];return n}function F(t){if(!t||"string"!=typeof t)return;const e=t.indexOf(":");if(-1!==e&&e>0){const i=t.substring(0,e);if("xmlns"!==i)return i}}class L{constructor(t){var e;if(this.options=t,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:"'"},gt:{regex:/&(gt|#62|#x3E);/g,val:">"},lt:{regex:/&(lt|#60|#x3C);/g,val:"<"},quot:{regex:/&(quot|#34|#x22);/g,val:'"'}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:"&"},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:" "},cent:{regex:/&(cent|#162);/g,val:"¢"},pound:{regex:/&(pound|#163);/g,val:"£"},yen:{regex:/&(yen|#165);/g,val:"¥"},euro:{regex:/&(euro|#8364);/g,val:"€"},copyright:{regex:/&(copy|#169);/g,val:"©"},reg:{regex:/&(reg|#174);/g,val:"®"},inr:{regex:/&(inr|#8377);/g,val:"₹"},num_dec:{regex:/&#([0-9]{1,7});/g,val:(t,e)=>tt(e,10,"&#")},num_hex:{regex:/&#x([0-9a-fA-F]{1,6});/g,val:(t,e)=>tt(e,16,"&#x")}},this.addExternalEntities=W,this.parseXml=Y,this.parseTextData=R,this.resolveNameSpace=G,this.buildAttributesMap=U,this.isItStopNode=Z,this.replaceEntitiesValue=z,this.readStopNodeData=J,this.saveTextToParentTag=q,this.addChild=X,this.ignoreAttributesFn="function"==typeof(e=this.options.ignoreAttributes)?e:Array.isArray(e)?t=>{for(const i of e){if("string"==typeof i&&t===i)return!0;if(i instanceof RegExp&&i.test(t))return!0}}:()=>!1,this.entityExpansionCount=0,this.currentExpandedLength=0,this.matcher=new D,this.isCurrentNodeStopNode=!1,this.options.stopNodes&&this.options.stopNodes.length>0){this.stopNodeExpressions=[];for(let t=0;t<this.options.stopNodes.length;t++){const e=this.options.stopNodes[t];"string"==typeof e?this.stopNodeExpressions.push(new k(e)):e instanceof k&&this.stopNodeExpressions.push(e)}}}}function W(t){const e=Object.keys(t);for(let i=0;i<e.length;i++){const n=e[i],s=n.replace(/[.\-+*:]/g,"\\.");this.lastEntities[n]={regex:new RegExp("&"+s+";","g"),val:t[n]}}}function R(t,e,i,n,s,r,o){if(void 0!==t&&(this.options.trimValues&&!n&&(t=t.trim()),t.length>0)){o||(t=this.replaceEntitiesValue(t,e,i));const n=this.options.jPath?i.toString():i,a=this.options.tagValueProcessor(e,t,n,s,r);return null==a?t:typeof a!=typeof t||a!==t?a:this.options.trimValues||t.trim()===t?H(t,this.options.parseTagValue,this.options.numberParseOptions):t}}function G(t){if(this.options.removeNSPrefix){const e=t.split(":"),i="/"===t.charAt(0)?"/":"";if("xmlns"===e[0])return"";2===e.length&&(t=i+e[1])}return t}const B=new RegExp("([^\\s=]+)\\s*(=\\s*(['\"])([\\s\\S]*?)\\3)?","gm");function U(t,e,i){if(!0!==this.options.ignoreAttributes&&"string"==typeof t){const n=s(t,B),r=n.length,o={},a={};for(let t=0;t<r;t++){const s=this.resolveNameSpace(n[t][1]),r=n[t][4];if(s.length&&void 0!==r){let t=r;this.options.trimValues&&(t=t.trim()),t=this.replaceEntitiesValue(t,i,e),a[s]=t}}Object.keys(a).length>0&&"object"==typeof e&&e.updateCurrent&&e.updateCurrent(a);for(let t=0;t<r;t++){const s=this.resolveNameSpace(n[t][1]),r=this.options.jPath?e.toString():e;if(this.ignoreAttributesFn(s,r))continue;let a=n[t][4],h=this.options.attributeNamePrefix+s;if(s.length)if(this.options.transformAttributeName&&(h=this.options.transformAttributeName(h)),"__proto__"===h&&(h="#__proto__"),void 0!==a){this.options.trimValues&&(a=a.trim()),a=this.replaceEntitiesValue(a,i,e);const t=this.options.jPath?e.toString():e,n=this.options.attributeValueProcessor(s,a,t);o[h]=null==n?a:typeof n!=typeof a||n!==a?n:H(a,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(o[h]=!0)}if(!Object.keys(o).length)return;if(this.options.attributesGroupName){const t={};return t[this.options.attributesGroupName]=o,t}return o}}const Y=function(t){t=t.replace(/\r\n?/g,"\n");const e=new P("!xml");let i=e,n="";this.matcher.reset(),this.entityExpansionCount=0,this.currentExpandedLength=0;const s=new A(this.options.processEntities);for(let r=0;r<t.length;r++)if("<"===t[r])if("/"===t[r+1]){const e=K(t,">",r,"Closing Tag is not closed.");let s=t.substring(r+2,e).trim();if(this.options.removeNSPrefix){const t=s.indexOf(":");-1!==t&&(s=s.substr(t+1))}this.options.transformTagName&&(s=this.options.transformTagName(s)),i&&(n=this.saveTextToParentTag(n,i,this.matcher));const o=this.matcher.getCurrentTag();if(s&&-1!==this.options.unpairedTags.indexOf(s))throw new Error(`Unpaired tag can not be used as closing tag: </${s}>`);o&&-1!==this.options.unpairedTags.indexOf(o)&&(this.matcher.pop(),this.tagsNodeStack.pop()),this.matcher.pop(),this.isCurrentNodeStopNode=!1,i=this.tagsNodeStack.pop(),n="",r=e}else if("?"===t[r+1]){let e=Q(t,r,!1,"?>");if(!e)throw new Error("Pi Tag is not closed.");if(n=this.saveTextToParentTag(n,i,this.matcher),this.options.ignoreDeclaration&&"?xml"===e.tagName||this.options.ignorePiTags);else{const t=new P(e.tagName);t.add(this.options.textNodeName,""),e.tagName!==e.tagExp&&e.attrExpPresent&&(t[":@"]=this.buildAttributesMap(e.tagExp,this.matcher,e.tagName)),this.addChild(i,t,this.matcher,r)}r=e.closeIndex+1}else if("!--"===t.substr(r+1,3)){const e=K(t,"--\x3e",r+4,"Comment is not closed.");if(this.options.commentPropName){const s=t.substring(r+4,e-2);n=this.saveTextToParentTag(n,i,this.matcher),i.add(this.options.commentPropName,[{[this.options.textNodeName]:s}])}r=e}else if("!D"===t.substr(r+1,2)){const e=s.readDocType(t,r);this.docTypeEntities=e.entities,r=e.i}else if("!["===t.substr(r+1,2)){const e=K(t,"]]>",r,"CDATA is not closed.")-2,s=t.substring(r+9,e);n=this.saveTextToParentTag(n,i,this.matcher);let o=this.parseTextData(s,i.tagname,this.matcher,!0,!1,!0,!0);null==o&&(o=""),this.options.cdataPropName?i.add(this.options.cdataPropName,[{[this.options.textNodeName]:s}]):i.add(this.options.textNodeName,o),r=e+2}else{let s=Q(t,r,this.options.removeNSPrefix);if(!s){const e=t.substring(Math.max(0,r-50),Math.min(t.length,r+50));throw new Error(`readTagExp returned undefined at position ${r}. Context: "${e}"`)}let o=s.tagName;const a=s.rawTagName;let h=s.tagExp,l=s.attrExpPresent,p=s.closeIndex;if(this.options.transformTagName){const t=this.options.transformTagName(o);h===o&&(h=t),o=t}if(this.options.strictReservedNames&&(o===this.options.commentPropName||o===this.options.cdataPropName))throw new Error(`Invalid tag name: ${o}`);i&&n&&"!xml"!==i.tagname&&(n=this.saveTextToParentTag(n,i,this.matcher,!1));const u=i;u&&-1!==this.options.unpairedTags.indexOf(u.tagname)&&(i=this.tagsNodeStack.pop(),this.matcher.pop());let c=!1;h.length>0&&h.lastIndexOf("/")===h.length-1&&(c=!0,"/"===o[o.length-1]?(o=o.substr(0,o.length-1),h=o):h=h.substr(0,h.length-1),l=o!==h);let d,g=null,f={};d=F(a),o!==e.tagname&&this.matcher.push(o,{},d),o!==h&&l&&(g=this.buildAttributesMap(h,this.matcher,o),g&&(f=M(g,this.options))),o!==e.tagname&&(this.isCurrentNodeStopNode=this.isItStopNode(this.stopNodeExpressions,this.matcher));const m=r;if(this.isCurrentNodeStopNode){let e="";if(c)r=s.closeIndex;else if(-1!==this.options.unpairedTags.indexOf(o))r=s.closeIndex;else{const i=this.readStopNodeData(t,a,p+1);if(!i)throw new Error(`Unexpected end of ${a}`);r=i.i,e=i.tagContent}const n=new P(o);g&&(n[":@"]=g),n.add(this.options.textNodeName,e),this.matcher.pop(),this.isCurrentNodeStopNode=!1,this.addChild(i,n,this.matcher,m)}else{if(c){if(this.options.transformTagName){const t=this.options.transformTagName(o);h===o&&(h=t),o=t}const t=new P(o);g&&(t[":@"]=g),this.addChild(i,t,this.matcher,m),this.matcher.pop(),this.isCurrentNodeStopNode=!1}else{if(-1!==this.options.unpairedTags.indexOf(o)){const t=new P(o);g&&(t[":@"]=g),this.addChild(i,t,this.matcher,m),this.matcher.pop(),this.isCurrentNodeStopNode=!1,r=s.closeIndex;continue}{const t=new P(o);if(this.tagsNodeStack.length>this.options.maxNestedTags)throw new Error("Maximum nested tags exceeded");this.tagsNodeStack.push(i),g&&(t[":@"]=g),this.addChild(i,t,this.matcher,m),i=t}}n="",r=p}}else n+=t[r];return e.child};function X(t,e,i,n){this.options.captureMetaData||(n=void 0);const s=this.options.jPath?i.toString():i,r=this.options.updateTag(e.tagname,s,e[":@"]);!1===r||("string"==typeof r?(e.tagname=r,t.addChild(e,n)):t.addChild(e,n))}function z(t,e,i){const n=this.options.processEntities;if(!n||!n.enabled)return t;if(n.allowedTags){const s=this.options.jPath?i.toString():i;if(!(Array.isArray(n.allowedTags)?n.allowedTags.includes(e):n.allowedTags(e,s)))return t}if(n.tagFilter){const s=this.options.jPath?i.toString():i;if(!n.tagFilter(e,s))return t}for(let e in this.docTypeEntities){const i=this.docTypeEntities[e],s=t.match(i.regx);if(s){if(this.entityExpansionCount+=s.length,n.maxTotalExpansions&&this.entityExpansionCount>n.maxTotalExpansions)throw new Error(`Entity expansion limit exceeded: ${this.entityExpansionCount} > ${n.maxTotalExpansions}`);const e=t.length;if(t=t.replace(i.regx,i.val),n.maxExpandedLength&&(this.currentExpandedLength+=t.length-e,this.currentExpandedLength>n.maxExpandedLength))throw new Error(`Total expanded content size exceeded: ${this.currentExpandedLength} > ${n.maxExpandedLength}`)}}if(-1===t.indexOf("&"))return t;for(let e in this.lastEntities){const i=this.lastEntities[e];t=t.replace(i.regex,i.val)}if(-1===t.indexOf("&"))return t;if(this.options.htmlEntities)for(let e in this.htmlEntities){const i=this.htmlEntities[e];t=t.replace(i.regex,i.val)}return t.replace(this.ampEntity.regex,this.ampEntity.val)}function q(t,e,i,n){return t&&(void 0===n&&(n=0===e.child.length),void 0!==(t=this.parseTextData(t,e.tagname,i,!1,!!e[":@"]&&0!==Object.keys(e[":@"]).length,n))&&""!==t&&e.add(this.options.textNodeName,t),t=""),t}function Z(t,e){if(!t||0===t.length)return!1;for(let i=0;i<t.length;i++)if(e.matches(t[i]))return!0;return!1}function K(t,e,i,n){const s=t.indexOf(e,i);if(-1===s)throw new Error(n);return s+e.length-1}function Q(t,e,i,n=">"){const s=function(t,e,i=">"){let n,s="";for(let r=e;r<t.length;r++){let e=t[r];if(n)e===n&&(n="");else if('"'===e||"'"===e)n=e;else if(e===i[0]){if(!i[1])return{data:s,index:r};if(t[r+1]===i[1])return{data:s,index:r}}else"\t"===e&&(e=" ");s+=e}}(t,e+1,n);if(!s)return;let r=s.data;const o=s.index,a=r.search(/\s/);let h=r,l=!0;-1!==a&&(h=r.substring(0,a),r=r.substring(a+1).trimStart());const p=h;if(i){const t=h.indexOf(":");-1!==t&&(h=h.substr(t+1),l=h!==s.data.substr(t+1))}return{tagName:h,tagExp:r,closeIndex:o,attrExpPresent:l,rawTagName:p}}function J(t,e,i){const n=i;let s=1;for(;i<t.length;i++)if("<"===t[i])if("/"===t[i+1]){const r=K(t,">",i,`${e} is not closed`);if(t.substring(i+2,r).trim()===e&&(s--,0===s))return{tagContent:t.substring(n,i),i:r};i=r}else if("?"===t[i+1])i=K(t,"?>",i+1,"StopNode is not closed.");else if("!--"===t.substr(i+1,3))i=K(t,"--\x3e",i+3,"StopNode is not closed.");else if("!["===t.substr(i+1,2))i=K(t,"]]>",i,"StopNode is not closed.")-2;else{const n=Q(t,i,">");n&&((n&&n.tagName)===e&&"/"!==n.tagExp[n.tagExp.length-1]&&s++,i=n.closeIndex)}}function H(t,e,i){if(e&&"string"==typeof t){const e=t.trim();return"true"===e||"false"!==e&&function(t,e={}){if(e=Object.assign({},_,e),!t||"string"!=typeof t)return t;let i=t.trim();if(void 0!==e.skipLike&&e.skipLike.test(i))return t;if("0"===t)return 0;if(e.hex&&I.test(i))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")}(i);if(i.includes("e")||i.includes("E"))return function(t,e,i){if(!i.eNotation)return t;const n=e.match(V);if(n){let s=n[1]||"";const r=-1===n[3].indexOf("e")?"E":"e",o=n[2],a=s?t[o.length+1]===r:t[o.length]===r;return o.length>1&&a?t:1!==o.length||!n[3].startsWith(`.${r}`)&&n[3][0]!==r?i.leadingZeros&&!a?(e=(n[1]||"")+n[3],Number(e)):t:Number(e)}return t}(t,i,e);{const s=j.exec(i);if(s){const r=s[1]||"",o=s[2];let a=(n=s[3])&&-1!==n.indexOf(".")?("."===(n=n.replace(/0+$/,""))?n="0":"."===n[0]?n="0"+n:"."===n[n.length-1]&&(n=n.substring(0,n.length-1)),n):n;const h=r?"."===t[o.length+1]:"."===t[o.length];if(!e.leadingZeros&&(o.length>1||1===o.length&&!h))return t;{const n=Number(i),s=String(n);if(0===n)return n;if(-1!==s.search(/[eE]/))return e.eNotation?n:t;if(-1!==i.indexOf("."))return"0"===s||s===a||s===`${r}${a}`?n:t;let h=o?a:i;return o?h===s||r+h===s?n:t:h===s||h===r+s?n:t}}return t}var n}(t,i)}return void 0!==t?t:""}function tt(t,e,i){const n=Number.parseInt(t,e);return n>=0&&n<=1114111?String.fromCodePoint(n):i+t+";"}const et=P.getMetaDataSymbol();function it(t,e){if(!t||"object"!=typeof t)return{};if(!e)return t;const i={};for(const n in t)n.startsWith(e)?i[n.substring(e.length)]=t[n]:i[n]=t[n];return i}function nt(t,e,i){return st(t,e,i)}function st(t,e,i){let n;const s={};for(let r=0;r<t.length;r++){const o=t[r],a=rt(o);if(void 0!==a&&a!==e.textNodeName){const t=it(o[":@"]||{},e.attributeNamePrefix);i.push(a,t)}if(a===e.textNodeName)void 0===n?n=o[a]:n+=""+o[a];else{if(void 0===a)continue;if(o[a]){let t=st(o[a],e,i);const n=at(t,e);if(o[":@"]?ot(t,o[":@"],i,e):1!==Object.keys(t).length||void 0===t[e.textNodeName]||e.alwaysCreateTextNode?0===Object.keys(t).length&&(e.alwaysCreateTextNode?t[e.textNodeName]="":t=""):t=t[e.textNodeName],void 0!==o[et]&&"object"==typeof t&&null!==t&&(t[et]=o[et]),void 0!==s[a]&&Object.prototype.hasOwnProperty.call(s,a))Array.isArray(s[a])||(s[a]=[s[a]]),s[a].push(t);else{const r=e.jPath?i.toString():i;e.isArray(a,r,n)?s[a]=[t]:s[a]=t}void 0!==a&&a!==e.textNodeName&&i.pop()}}}return"string"==typeof n?n.length>0&&(s[e.textNodeName]=n):void 0!==n&&(s[e.textNodeName]=n),s}function rt(t){const e=Object.keys(t);for(let t=0;t<e.length;t++){const i=e[t];if(":@"!==i)return i}}function ot(t,e,i,n){if(e){const s=Object.keys(e),r=s.length;for(let o=0;o<r;o++){const r=s[o],a=r.startsWith(n.attributeNamePrefix)?r.substring(n.attributeNamePrefix.length):r,h=n.jPath?i.toString()+"."+a:i;n.isArray(r,h,!0,!0)?t[r]=[e[r]]:t[r]=e[r]}}}function at(t,e){const{textNodeName:i}=e,n=Object.keys(t).length;return 0===n||!(1!==n||!t[i]&&"boolean"!=typeof t[i]&&0!==t[i])}class ht{constructor(t){this.externalEntities={},this.options=S(t)}parse(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={});const i=a(t,e);if(!0!==i)throw Error(`${i.err.msg}:${i.err.line}:${i.err.col}`)}const i=new L(this.options);i.addExternalEntities(this.externalEntities);const n=i.parseXml(t);return this.options.preserveOrder||void 0===n?n:nt(n,this.options,i.matcher)}addEntity(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 '
'");if("&"===e)throw new Error("An entity with value '&' is not permitted");this.externalEntities[t]=e}static getMetaDataSymbol(){return P.getMetaDataSymbol()}}class lt{constructor(t,e={}){this.pattern=t,this.separator=e.separator||".",this.segments=this._parse(t),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 i=0,n="";for(;i<t.length;)t[i]===this.separator?i+1<t.length&&t[i+1]===this.separator?(n.trim()&&(e.push(this._parseSegment(n.trim())),n=""),e.push({type:"deep-wildcard"}),i+=2):(n.trim()&&e.push(this._parseSegment(n.trim())),n="",i++):(n+=t[i],i++);return n.trim()&&e.push(this._parseSegment(n.trim())),e}_parseSegment(t){const e={type:"tag"};let i=null,n=t;const s=t.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);if(s&&(n=s[1]+s[3],s[2])){const t=s[2].slice(1,-1);t&&(i=t)}let r,o,a=n;if(n.includes("::")){const e=n.indexOf("::");if(r=n.substring(0,e).trim(),a=n.substring(e+2).trim(),!r)throw new Error(`Invalid namespace in pattern: ${t}`)}let h=null;if(a.includes(":")){const t=a.lastIndexOf(":"),e=a.substring(0,t).trim(),i=a.substring(t+1).trim();["first","last","odd","even"].includes(i)||/^nth\(\d+\)$/.test(i)?(o=e,h=i):o=a}else o=a;if(!o)throw new Error(`Invalid segment pattern: ${t}`);if(e.tag=o,r&&(e.namespace=r),i)if(i.includes("=")){const t=i.indexOf("=");e.attrName=i.substring(0,t).trim(),e.attrValue=i.substring(t+1).trim()}else e.attrName=i.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 pt{constructor(t={}){this.separator=t.separator||".",this.path=[],this.siblingStacks=[]}push(t,e=null,i=null){this.path.length>0&&(this.path[this.path.length-1].values=void 0);const n=this.path.length;this.siblingStacks[n]||(this.siblingStacks[n]=new Map);const s=this.siblingStacks[n],r=i?`${i}:${t}`:t,o=s.get(r)||0;let a=0;for(const t of s.values())a+=t;s.set(r,o+1);const h={tag:t,position:a,counter:o};null!=i&&(h.namespace=i),null!=e&&(h.values=e),this.path.push(h)}pop(){if(0===this.path.length)return;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;const e=this.path[this.path.length-1];return e.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 i=t||this.separator;return this.path.map(t=>e&&t.namespace?`${t.namespace}:${t.tag}`:t.tag).join(i)}toArray(){return this.path.map(t=>t.tag)}reset(){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++){const i=t[e],n=this.path[e],s=e===this.path.length-1;if(!this._matchSegment(i,n,s))return!1}return!0}_matchWithDeepWildcard(t){let e=this.path.length-1,i=t.length-1;for(;i>=0&&e>=0;){const n=t[i];if("deep-wildcard"===n.type){if(i--,i<0)return!0;const n=t[i];let s=!1;for(let t=e;t>=0;t--){const r=t===this.path.length-1;if(this._matchSegment(n,this.path[t],r)){e=t-1,i--,s=!0;break}}if(!s)return!1}else{const t=e===this.path.length-1;if(!this._matchSegment(n,this.path[e],t))return!1;e--,i--}}return i<0}_matchSegment(t,e,i){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(!i)return!1;if(!e.values||!(t.attrName in e.values))return!1;if(void 0!==t.attrValue){const i=e.values[t.attrName];if(String(i)!==String(t.attrValue))return!1}}if(void 0!==t.position){if(!i)return!1;const n=e.counter??0;if("first"===t.position&&0!==n)return!1;if("odd"===t.position&&n%2!=1)return!1;if("even"===t.position&&n%2!=0)return!1;if("nth"===t.position&&n!==t.positionValue)return!1}return!0}snapshot(){return{path:this.path.map(t=>({...t})),siblingStacks:this.siblingStacks.map(t=>new Map(t))}}restore(t){this.path=t.path.map(t=>({...t})),this.siblingStacks=t.siblingStacks.map(t=>new Map(t))}}function ut(t,e){let i="";e.format&&e.indentBy.length>0&&(i="\n");const n=[];if(e.stopNodes&&Array.isArray(e.stopNodes))for(let t=0;t<e.stopNodes.length;t++){const i=e.stopNodes[t];"string"==typeof i?n.push(new lt(i)):i instanceof lt&&n.push(i)}return ct(t,e,i,new pt,n)}function ct(t,e,i,n,s){let r="",o=!1;if(!Array.isArray(t)){if(null!=t){let i=t.toString();return i=Nt(i,e),i}return""}for(let a=0;a<t.length;a++){const h=t[a],l=mt(h);if(void 0===l)continue;const p=dt(h[":@"],e);n.push(l,p);const u=bt(n,s);if(l===e.textNodeName){let t=h[l];u||(t=e.tagValueProcessor(l,t),t=Nt(t,e)),o&&(r+=i),r+=t,o=!1,n.pop();continue}if(l===e.cdataPropName){o&&(r+=i),r+=`<![CDATA[${h[l][0][e.textNodeName]}]]>`,o=!1,n.pop();continue}if(l===e.commentPropName){r+=i+`\x3c!--${h[l][0][e.textNodeName]}--\x3e`,o=!0,n.pop();continue}if("?"===l[0]){const t=xt(h[":@"],e,u),s="?xml"===l?"":i;let a=h[l][0][e.textNodeName];a=0!==a.length?" "+a:"",r+=s+`<${l}${a}${t}?>`,o=!0,n.pop();continue}let c=i;""!==c&&(c+=e.indentBy);const d=i+`<${l}${xt(h[":@"],e,u)}`;let g;g=u?gt(h[l],e):ct(h[l],e,c,n,s),-1!==e.unpairedTags.indexOf(l)?e.suppressUnpairedNode?r+=d+">":r+=d+"/>":g&&0!==g.length||!e.suppressEmptyNode?g&&g.endsWith(">")?r+=d+`>${g}${i}</${l}>`:(r+=d+">",g&&""!==i&&(g.includes("/>")||g.includes("</"))?r+=i+e.indentBy+g+i:r+=g,r+=`</${l}>`):r+=d+"/>",o=!0,n.pop()}return r}function dt(t,e){if(!t||e.ignoreAttributes)return null;const i={};let n=!1;for(let s in t)Object.prototype.hasOwnProperty.call(t,s)&&(i[s.startsWith(e.attributeNamePrefix)?s.substr(e.attributeNamePrefix.length):s]=t[s],n=!0);return n?i:null}function gt(t,e){if(!Array.isArray(t))return null!=t?t.toString():"";let i="";for(let n=0;n<t.length;n++){const s=t[n],r=mt(s);if(r===e.textNodeName)i+=s[r];else if(r===e.cdataPropName)i+=s[r][0][e.textNodeName];else if(r===e.commentPropName)i+=s[r][0][e.textNodeName];else{if(r&&"?"===r[0])continue;if(r){const t=ft(s[":@"],e),n=gt(s[r],e);n&&0!==n.length?i+=`<${r}${t}>${n}</${r}>`:i+=`<${r}${t}/>`}}}return i}function ft(t,e){let i="";if(t&&!e.ignoreAttributes)for(let n in t){if(!Object.prototype.hasOwnProperty.call(t,n))continue;let s=t[n];!0===s&&e.suppressBooleanAttributes?i+=` ${n.substr(e.attributeNamePrefix.length)}`:i+=` ${n.substr(e.attributeNamePrefix.length)}="${s}"`}return i}function mt(t){const e=Object.keys(t);for(let i=0;i<e.length;i++){const n=e[i];if(Object.prototype.hasOwnProperty.call(t,n)&&":@"!==n)return n}}function xt(t,e,i){let n="";if(t&&!e.ignoreAttributes)for(let s in t){if(!Object.prototype.hasOwnProperty.call(t,s))continue;let r;i?r=t[s]:(r=e.attributeValueProcessor(s,t[s]),r=Nt(r,e)),!0===r&&e.suppressBooleanAttributes?n+=` ${s.substr(e.attributeNamePrefix.length)}`:n+=` ${s.substr(e.attributeNamePrefix.length)}="${r}"`}return n}function bt(t,e){if(!e||0===e.length)return!1;for(let i=0;i<e.length;i++)if(t.matches(e[i]))return!0;return!1}function Nt(t,e){if(t&&t.length>0&&e.processEntities)for(let i=0;i<e.entities.length;i++){const n=e.entities[i];t=t.replace(n.regex,n.val)}return t}const Et={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:"&"},{regex:new RegExp(">","g"),val:">"},{regex:new RegExp("<","g"),val:"<"},{regex:new RegExp("'","g"),val:"'"},{regex:new RegExp('"',"g"),val:"""}],processEntities:!0,stopNodes:[],oneListGroup:!1,jPath:!0};function yt(t){if(this.options=Object.assign({},Et,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 lt(e)):e instanceof lt&&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 i of e){if("string"==typeof i&&t===i)return!0;if(i instanceof RegExp&&i.test(t))return!0}}:()=>!1,this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=St),this.processTextOrObjNode=vt,this.options.format?(this.indentate=wt,this.tagEndChar=">\n",this.newLine="\n"):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}function vt(t,e,i,n){const s=this.extractAttributes(t);if(n.push(e,s),this.checkStopNode(n)){const s=this.buildRawContent(t),r=this.buildAttributesForStopNode(t);return n.pop(),this.buildObjectNode(s,e,r,i)}const r=this.j2x(t,i+1,n);return n.pop(),void 0!==t[this.options.textNodeName]&&1===Object.keys(t).length?this.buildTextValNode(t[this.options.textNodeName],e,r.attrStr,i,n):this.buildObjectNode(r.val,e,r.attrStr,i)}function wt(t){return this.options.indentBy.repeat(t)}function St(t){return!(!t.startsWith(this.options.attributeNamePrefix)||t===this.options.textNodeName)&&t.substr(this.attrPrefixLen)}yt.prototype.build=function(t){if(this.options.preserveOrder)return ut(t,this.options);{Array.isArray(t)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(t={[this.options.arrayNodeName]:t});const e=new pt;return this.j2x(t,0,e).val}},yt.prototype.j2x=function(t,e,i){let n="",s="";const r=this.options.jPath?i.toString():i,o=this.checkStopNode(i);for(let a in t)if(Object.prototype.hasOwnProperty.call(t,a))if(void 0===t[a])this.isAttribute(a)&&(s+="");else if(null===t[a])this.isAttribute(a)||a===this.options.cdataPropName?s+="":"?"===a[0]?s+=this.indentate(e)+"<"+a+"?"+this.tagEndChar:s+=this.indentate(e)+"<"+a+"/"+this.tagEndChar;else if(t[a]instanceof Date)s+=this.buildTextValNode(t[a],a,"",e,i);else if("object"!=typeof t[a]){const h=this.isAttribute(a);if(h&&!this.ignoreAttributesFn(h,r))n+=this.buildAttrPairStr(h,""+t[a],o);else if(!h)if(a===this.options.textNodeName){let e=this.options.tagValueProcessor(a,""+t[a]);s+=this.replaceEntitiesValue(e)}else{i.push(a);const n=this.checkStopNode(i);if(i.pop(),n){const i=""+t[a];s+=""===i?this.indentate(e)+"<"+a+this.closeTag(a)+this.tagEndChar:this.indentate(e)+"<"+a+">"+i+"</"+a+this.tagEndChar}else s+=this.buildTextValNode(t[a],a,"",e,i)}}else if(Array.isArray(t[a])){const n=t[a].length;let r="",o="";for(let h=0;h<n;h++){const n=t[a][h];if(void 0===n);else if(null===n)"?"===a[0]?s+=this.indentate(e)+"<"+a+"?"+this.tagEndChar:s+=this.indentate(e)+"<"+a+"/"+this.tagEndChar;else if("object"==typeof n)if(this.options.oneListGroup){i.push(a);const t=this.j2x(n,e+1,i);i.pop(),r+=t.val,this.options.attributesGroupName&&n.hasOwnProperty(this.options.attributesGroupName)&&(o+=t.attrStr)}else r+=this.processTextOrObjNode(n,a,e,i);else if(this.options.oneListGroup){let t=this.options.tagValueProcessor(a,n);t=this.replaceEntitiesValue(t),r+=t}else{i.push(a);const t=this.checkStopNode(i);if(i.pop(),t){const t=""+n;r+=""===t?this.indentate(e)+"<"+a+this.closeTag(a)+this.tagEndChar:this.indentate(e)+"<"+a+">"+t+"</"+a+this.tagEndChar}else r+=this.buildTextValNode(n,a,"",e,i)}}this.options.oneListGroup&&(r=this.buildObjectNode(r,a,o,e)),s+=r}else if(this.options.attributesGroupName&&a===this.options.attributesGroupName){const e=Object.keys(t[a]),i=e.length;for(let s=0;s<i;s++)n+=this.buildAttrPairStr(e[s],""+t[a][e[s]],o)}else s+=this.processTextOrObjNode(t[a],a,e,i);return{attrStr:n,val:s}},yt.prototype.buildAttrPairStr=function(t,e,i){return i||(e=this.options.attributeValueProcessor(t,""+e),e=this.replaceEntitiesValue(e)),this.options.suppressBooleanAttributes&&"true"===e?" "+t:" "+t+'="'+e+'"'},yt.prototype.extractAttributes=function(t){if(!t||"object"!=typeof t)return null;const e={};let i=!1;if(this.options.attributesGroupName&&t[this.options.attributesGroupName]){const n=t[this.options.attributesGroupName];for(let t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t.startsWith(this.options.attributeNamePrefix)?t.substring(this.options.attributeNamePrefix.length):t]=n[t],i=!0)}else for(let n in t){if(!Object.prototype.hasOwnProperty.call(t,n))continue;const s=this.isAttribute(n);s&&(e[s]=t[n],i=!0)}return i?e:null},yt.prototype.buildRawContent=function(t){if("string"==typeof t)return t;if("object"!=typeof t||null===t)return String(t);if(void 0!==t[this.options.textNodeName])return t[this.options.textNodeName];let e="";for(let i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;if(this.isAttribute(i))continue;if(this.options.attributesGroupName&&i===this.options.attributesGroupName)continue;const n=t[i];if(i===this.options.textNodeName)e+=n;else if(Array.isArray(n)){for(let t of n)if("string"==typeof t||"number"==typeof t)e+=`<${i}>${t}</${i}>`;else if("object"==typeof t&&null!==t){const n=this.buildRawContent(t),s=this.buildAttributesForStopNode(t);e+=""===n?`<${i}${s}/>`:`<${i}${s}>${n}</${i}>`}}else if("object"==typeof n&&null!==n){const t=this.buildRawContent(n),s=this.buildAttributesForStopNode(n);e+=""===t?`<${i}${s}/>`:`<${i}${s}>${t}</${i}>`}else e+=`<${i}>${n}</${i}>`}return e},yt.prototype.buildAttributesForStopNode=function(t){if(!t||"object"!=typeof t)return"";let e="";if(this.options.attributesGroupName&&t[this.options.attributesGroupName]){const i=t[this.options.attributesGroupName];for(let t in i){if(!Object.prototype.hasOwnProperty.call(i,t))continue;const n=t.startsWith(this.options.attributeNamePrefix)?t.substring(this.options.attributeNamePrefix.length):t,s=i[t];!0===s&&this.options.suppressBooleanAttributes?e+=" "+n:e+=" "+n+'="'+s+'"'}}else for(let i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;const n=this.isAttribute(i);if(n){const s=t[i];!0===s&&this.options.suppressBooleanAttributes?e+=" "+n:e+=" "+n+'="'+s+'"'}}return e},yt.prototype.buildObjectNode=function(t,e,i,n){if(""===t)return"?"===e[0]?this.indentate(n)+"<"+e+i+"?"+this.tagEndChar:this.indentate(n)+"<"+e+i+this.closeTag(e)+this.tagEndChar;{let s="</"+e+this.tagEndChar,r="";return"?"===e[0]&&(r="?",s=""),!i&&""!==i||-1!==t.indexOf("<")?!1!==this.options.commentPropName&&e===this.options.commentPropName&&0===r.length?this.indentate(n)+`\x3c!--${t}--\x3e`+this.newLine:this.indentate(n)+"<"+e+i+r+this.tagEndChar+t+this.indentate(n)+s:this.indentate(n)+"<"+e+i+r+">"+t+s}},yt.prototype.closeTag=function(t){let e="";return-1!==this.options.unpairedTags.indexOf(t)?this.options.suppressUnpairedNode||(e="/"):e=this.options.suppressEmptyNode?"/":`></${t}`,e},yt.prototype.checkStopNode=function(t){if(!this.stopNodeExpressions||0===this.stopNodeExpressions.length)return!1;for(let e=0;e<this.stopNodeExpressions.length;e++)if(t.matches(this.stopNodeExpressions[e]))return!0;return!1},yt.prototype.buildTextValNode=function(t,e,i,n,s){if(!1!==this.options.cdataPropName&&e===this.options.cdataPropName)return this.indentate(n)+`<![CDATA[${t}]]>`+this.newLine;if(!1!==this.options.commentPropName&&e===this.options.commentPropName)return this.indentate(n)+`\x3c!--${t}--\x3e`+this.newLine;if("?"===e[0])return this.indentate(n)+"<"+e+i+"?"+this.tagEndChar;{let s=this.options.tagValueProcessor(e,t);return s=this.replaceEntitiesValue(s),""===s?this.indentate(n)+"<"+e+i+this.closeTag(e)+this.tagEndChar:this.indentate(n)+"<"+e+i+">"+s+"</"+e+this.tagEndChar}},yt.prototype.replaceEntitiesValue=function(t){if(t&&t.length>0&&this.options.processEntities)for(let e=0;e<this.options.entities.length;e++){const i=this.options.entities[e];t=t.replace(i.regex,i.val)}return t};const Tt=yt,Pt={validate:a};module.exports=e})(); |
+46
-19
@@ -0,1 +1,3 @@ | ||
| const { Matcher, Expression } = require('path-expression-matcher'); | ||
| type ProcessEntitiesOptions = { | ||
@@ -56,3 +58,3 @@ /** | ||
| * @param tagName - The name of the current tag | ||
| * @param jPath - The jPath of the current tag | ||
| * @param jPathOrMatcher - The jPath string (if jPath: true) or Matcher instance (if jPath: false) | ||
| * @returns `true` to allow entity replacement, `false` to skip | ||
@@ -62,3 +64,3 @@ * | ||
| */ | ||
| tagFilter?: ((tagName: string, jPath: string) => boolean) | null; | ||
| tagFilter?: ((tagName: string, jPathOrMatcher: string | Matcher) => boolean) | null; | ||
| }; | ||
@@ -108,3 +110,3 @@ | ||
| */ | ||
| ignoreAttributes?: boolean | (string | RegExp)[] | ((attrName: string, jPath: string) => boolean); | ||
| ignoreAttributes?: boolean | (string | RegExp)[] | ((attrName: string, jPathOrMatcher: string | Matcher) => boolean); | ||
@@ -163,2 +165,7 @@ /** | ||
| * | ||
| * @param tagName - The name of the tag | ||
| * @param tagValue - The value of the tag | ||
| * @param jPathOrMatcher - The jPath string (if jPath: true) or Matcher instance (if jPath: false) | ||
| * @param hasAttributes - Whether the tag has attributes | ||
| * @param isLeafNode - Whether the tag is a leaf node | ||
| * @returns {undefined|null} `undefined` or `null` to set original value. | ||
@@ -170,5 +177,5 @@ * @returns {unknown} | ||
| * | ||
| * Defaults to `(tagName, val, jPath, hasAttributes, isLeafNode) => val` | ||
| * Defaults to `(tagName, val, jPathOrMatcher, hasAttributes, isLeafNode) => val` | ||
| */ | ||
| tagValueProcessor?: (tagName: string, tagValue: string, jPath: string, hasAttributes: boolean, isLeafNode: boolean) => unknown; | ||
| tagValueProcessor?: (tagName: string, tagValue: string, jPathOrMatcher: string | Matcher, hasAttributes: boolean, isLeafNode: boolean) => unknown; | ||
@@ -178,11 +185,11 @@ /** | ||
| * | ||
| * @param attrName | ||
| * @param attrValue | ||
| * @param jPath | ||
| * @param attrName - The name of the attribute | ||
| * @param attrValue - The value of the attribute | ||
| * @param jPathOrMatcher - The jPath string (if jPath: true) or Matcher instance (if jPath: false) | ||
| * @returns {undefined|null} `undefined` or `null` to set original value | ||
| * @returns {unknown} | ||
| * | ||
| * Defaults to `(attrName, val, jPath) => val` | ||
| * Defaults to `(attrName, val, jPathOrMatcher) => val` | ||
| */ | ||
| attributeValueProcessor?: (attrName: string, attrValue: string, jPath: string) => unknown; | ||
| attributeValueProcessor?: (attrName: string, attrValue: string, jPathOrMatcher: string | Matcher) => unknown; | ||
@@ -199,5 +206,9 @@ /** | ||
| * | ||
| * Accepts string patterns or Expression objects from path-expression-matcher | ||
| * | ||
| * String patterns starting with "*." are automatically converted to ".." for backward compatibility | ||
| * | ||
| * Defaults to `[]` | ||
| */ | ||
| stopNodes?: string[]; | ||
| stopNodes?: (string | Expression)[]; | ||
@@ -221,6 +232,6 @@ /** | ||
| * | ||
| * @param tagName | ||
| * @param jPath | ||
| * @param isLeafNode | ||
| * @param isAttribute | ||
| * @param tagName - The name of the tag | ||
| * @param jPathOrMatcher - The jPath string (if jPath: true) or Matcher instance (if jPath: false) | ||
| * @param isLeafNode - Whether the tag is a leaf node | ||
| * @param isAttribute - Whether this is an attribute | ||
| * @returns {boolean} | ||
@@ -230,3 +241,3 @@ * | ||
| */ | ||
| isArray?: (tagName: string, jPath: string, isLeafNode: boolean, isAttribute: boolean) => boolean; | ||
| isArray?: (tagName: string, jPathOrMatcher: string | Matcher, isLeafNode: boolean, isAttribute: boolean) => boolean; | ||
@@ -285,8 +296,11 @@ /** | ||
| * | ||
| * @param tagName - The name of the tag | ||
| * @param jPathOrMatcher - The jPath string (if jPath: true) or Matcher instance (if jPath: false) | ||
| * @param attrs - The attributes object | ||
| * @returns {string} new tag name. | ||
| * @returns false to skip the tag | ||
| * | ||
| * Defaults to `(tagName, jPath, attrs) => tagName` | ||
| * Defaults to `(tagName, jPathOrMatcher, attrs) => tagName` | ||
| */ | ||
| updateTag?: (tagName: string, jPath: string, attrs: { [k: string]: string }) => string | boolean; | ||
| updateTag?: (tagName: string, jPathOrMatcher: string | Matcher, attrs: { [k: string]: string }) => string | boolean; | ||
@@ -312,2 +326,13 @@ /** | ||
| strictReservedNames?: boolean; | ||
| /** | ||
| * Controls whether callbacks receive jPath as string or Matcher instance | ||
| * | ||
| * When `true` - callbacks receive jPath as string (backward compatible) | ||
| * | ||
| * When `false` - callbacks receive Matcher instance for advanced pattern matching | ||
| * | ||
| * Defaults to `true` | ||
| */ | ||
| jPath?: boolean; | ||
| }; | ||
@@ -449,5 +474,7 @@ | ||
| * | ||
| * Accepts string patterns or Expression objects from path-expression-matcher | ||
| * | ||
| * Defaults to `[]` | ||
| */ | ||
| stopNodes?: string[]; | ||
| stopNodes?: (string | Expression)[]; | ||
@@ -454,0 +481,0 @@ /** |
+1
-1
@@ -1,2 +0,2 @@ | ||
| !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,i)=>{for(var n in i)t.o(i,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:i[n]})},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:()=>mt,XMLParser:()=>rt,XMLValidator:()=>xt});var i=":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",n=new RegExp("^["+i+"]["+i+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040]*$");function r(t,e){for(var i=[],n=e.exec(t);n;){var r=[];r.startIndex=e.lastIndex-n[0].length;for(var s=n.length,o=0;o<s;o++)r.push(n[o]);i.push(r),n=e.exec(t)}return i}var s=function(t){return!(null==n.exec(t))},o={allowBooleanAttributes:!1,unpairedTags:[]};function a(t,e){e=Object.assign({},o,e);var i=[],n=!1,r=!1;"\ufeff"===t[0]&&(t=t.substr(1));for(var s=0;s<t.length;s++)if("<"===t[s]&&"?"===t[s+1]){if((s=u(t,s+=2)).err)return s}else{if("<"!==t[s]){if(l(t[s]))continue;return x("InvalidChar","char '"+t[s]+"' is not expected.",E(t,s))}var a=s;if("!"===t[++s]){s=d(t,s);continue}var h=!1;"/"===t[s]&&(h=!0,s++);for(var p="";s<t.length&&">"!==t[s]&&" "!==t[s]&&"\t"!==t[s]&&"\n"!==t[s]&&"\r"!==t[s];s++)p+=t[s];if("/"===(p=p.trim())[p.length-1]&&(p=p.substring(0,p.length-1),s--),!b(p))return x("InvalidTag",0===p.trim().length?"Invalid space after '<'.":"Tag '"+p+"' is an invalid name.",E(t,s));var g=f(t,s);if(!1===g)return x("InvalidAttr","Attributes for '"+p+"' have open quote.",E(t,s));var v=g.value;if(s=g.index,"/"===v[v.length-1]){var N=s-v.length,y=c(v=v.substring(0,v.length-1),e);if(!0!==y)return x(y.err.code,y.err.msg,E(t,N+y.err.line));n=!0}else if(h){if(!g.tagClosed)return x("InvalidTag","Closing tag '"+p+"' doesn't have proper closing.",E(t,s));if(v.trim().length>0)return x("InvalidTag","Closing tag '"+p+"' can't have attributes or invalid starting.",E(t,a));if(0===i.length)return x("InvalidTag","Closing tag '"+p+"' has not been opened.",E(t,a));var T=i.pop();if(p!==T.tagName){var w=E(t,T.tagStartPos);return x("InvalidTag","Expected closing tag '"+T.tagName+"' (opened in line "+w.line+", col "+w.col+") instead of closing tag '"+p+"'.",E(t,a))}0==i.length&&(r=!0)}else{var I=c(v,e);if(!0!==I)return x(I.err.code,I.err.msg,E(t,s-v.length+I.err.line));if(!0===r)return x("InvalidXml","Multiple possible root nodes found.",E(t,s));-1!==e.unpairedTags.indexOf(p)||i.push({tagName:p,tagStartPos:a}),n=!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=u(t,++s)).err)return s}else if("&"===t[s]){var O=m(t,s);if(-1==O)return x("InvalidChar","char '&' is not expected.",E(t,s));s=O}else if(!0===r&&!l(t[s]))return x("InvalidXml","Extra text at the end",E(t,s));"<"===t[s]&&s--}return n?1==i.length?x("InvalidTag","Unclosed tag '"+i[0].tagName+"'.",E(t,i[0].tagStartPos)):!(i.length>0)||x("InvalidXml","Invalid '"+JSON.stringify(i.map(function(t){return t.tagName}),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1}):x("InvalidXml","Start tag expected.",1)}function l(t){return" "===t||"\t"===t||"\n"===t||"\r"===t}function u(t,e){for(var i=e;e<t.length;e++)if("?"!=t[e]&&" "!=t[e]);else{var n=t.substr(i,e-i);if(e>5&&"xml"===n)return x("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 i=1;for(e+=8;e<t.length;e++)if("<"===t[e])i++;else if(">"===t[e]&&0===--i)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 h='"',p="'";function f(t,e){for(var i="",n="",r=!1;e<t.length;e++){if(t[e]===h||t[e]===p)""===n?n=t[e]:n!==t[e]||(n="");else if(">"===t[e]&&""===n){r=!0;break}i+=t[e]}return""===n&&{value:i,index:e,tagClosed:r}}var g=new RegExp("(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['\"])(([\\s\\S])*?)\\5)?","g");function c(t,e){for(var i=r(t,g),n={},s=0;s<i.length;s++){if(0===i[s][1].length)return x("InvalidAttr","Attribute '"+i[s][2]+"' has no space in starting.",N(i[s]));if(void 0!==i[s][3]&&void 0===i[s][4])return x("InvalidAttr","Attribute '"+i[s][2]+"' is without value.",N(i[s]));if(void 0===i[s][3]&&!e.allowBooleanAttributes)return x("InvalidAttr","boolean attribute '"+i[s][2]+"' is not allowed.",N(i[s]));var o=i[s][2];if(!v(o))return x("InvalidAttr","Attribute '"+o+"' is an invalid name.",N(i[s]));if(Object.prototype.hasOwnProperty.call(n,o))return x("InvalidAttr","Attribute '"+o+"' is repeated.",N(i[s]));n[o]=1}return!0}function m(t,e){if(";"===t[++e])return-1;if("#"===t[e])return function(t,e){var i=/\d/;for("x"===t[e]&&(e++,i=/[\da-fA-F]/);e<t.length;e++){if(";"===t[e])return e;if(!t[e].match(i))break}return-1}(t,++e);for(var i=0;e<t.length;e++,i++)if(!(t[e].match(/\w/)&&i<20)){if(";"===t[e])break;return-1}return e}function x(t,e,i){return{err:{code:t,msg:e,line:i.line||i,col:i.col}}}function v(t){return s(t)}function b(t){return s(t)}function E(t,e){var i=t.substring(0,e).split(/\r?\n/);return{line:i.length,col:i[i.length-1].length+1}}function N(t){return t.startIndex+t[1].length}var y={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,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(t,e,i){return t},captureMetaData:!1,maxNestedTags:100,strictReservedNames:!0};function T(t){return"boolean"==typeof t?{enabled:t,maxEntitySize:1e4,maxExpansionDepth:10,maxTotalExpansions:1e3,maxExpandedLength:1e5,maxEntityCount:100,allowedTags:null,tagFilter:null}:"object"==typeof t&&null!==t?{enabled:!1!==t.enabled,maxEntitySize:null!=(e=t.maxEntitySize)?e:1e4,maxExpansionDepth:null!=(i=t.maxExpansionDepth)?i:10,maxTotalExpansions:null!=(n=t.maxTotalExpansions)?n:1e3,maxExpandedLength:null!=(r=t.maxExpandedLength)?r:1e5,maxEntityCount:null!=(s=t.maxEntityCount)?s:100,allowedTags:null!=(o=t.allowedTags)?o:null,tagFilter:null!=(a=t.tagFilter)?a:null}:T(!0);var e,i,n,r,s,o,a}var w,I=function(t){var e=Object.assign({},y,t);return e.processEntities=T(e.processEntities),e};w="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 i;"__proto__"===t&&(t="#__proto__"),this.child.push(((i={})[t]=e,i))},e.addChild=function(t,e){var i,n;"__proto__"===t.tagname&&(t.tagname="#__proto__"),t[":@"]&&Object.keys(t[":@"]).length>0?this.child.push(((i={})[t.tagname]=t.child,i[":@"]=t[":@"],i)):this.child.push(((n={})[t.tagname]=t.child,n)),void 0!==e&&(this.child[this.child.length-1][w]={startIndex:e})},t.getMetaDataSymbol=function(){return w},t}(),A=function(){function t(t){this.suppressValidationErr=!t,this.options=t}var e=t.prototype;return e.readDocType=function(t,e){var i=Object.create(null),n=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 r=1,s=!1,o=!1;e<t.length;e++)if("<"!==t[e]||o)if(">"===t[e]){if(o?"-"===t[e-1]&&"-"===t[e-2]&&(o=!1,r--):r--,0===r)break}else"["===t[e]?s=!0:t[e];else{if(s&&S(t,"!ENTITY",e)){e+=7;var a=void 0,l=void 0,u=this.readEntityExp(t,e+1,this.suppressValidationErr);if(a=u[0],l=u[1],e=u[2],-1===l.indexOf("&")){if(!1!==this.options.enabled&&this.options.maxEntityCount&&n>=this.options.maxEntityCount)throw new Error("Entity count ("+(n+1)+") exceeds maximum allowed ("+this.options.maxEntityCount+")");var d=a.replace(/[.\-+*:]/g,"\\.");i[a]={regx:RegExp("&"+d+";","g"),val:l},n++}}else if(s&&S(t,"!ELEMENT",e))e+=8,e=this.readElementExp(t,e+1).index;else if(s&&S(t,"!ATTLIST",e))e+=8;else if(s&&S(t,"!NOTATION",e))e+=9,e=this.readNotationExp(t,e+1,this.suppressValidationErr).index;else{if(!S(t,"!--",e))throw new Error("Invalid DOCTYPE");o=!0}r++}if(0!==r)throw new Error("Unclosed DOCTYPE");return{entities:i,i:e}},e.readEntityExp=function(t,e){e=P(t,e);for(var i="";e<t.length&&!/\s/.test(t[e])&&'"'!==t[e]&&"'"!==t[e];)i+=t[e],e++;if(C(i),e=P(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,r=this.readIdentifierVal(t,e,"entity");if(e=r[0],n=r[1],!1!==this.options.enabled&&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){e=P(t,e);for(var i="";e<t.length&&!/\s/.test(t[e]);)i+=t[e],e++;!this.suppressValidationErr&&C(i),e=P(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=P(t,e);var r=null,s=null;if("PUBLIC"===n){var o=this.readIdentifierVal(t,e,"publicIdentifier");if(e=o[0],r=o[1],'"'===t[e=P(t,e)]||"'"===t[e]){var a=this.readIdentifierVal(t,e,"systemIdentifier");e=a[0],s=a[1]}}else if("SYSTEM"===n){var l=this.readIdentifierVal(t,e,"systemIdentifier");if(e=l[0],s=l[1],!this.suppressValidationErr&&!s)throw new Error("Missing mandatory system identifier for SYSTEM notation")}return{notationName:i,publicIdentifier:r,systemIdentifier:s,index:--e}},e.readIdentifierVal=function(t,e,i){var n="",r=t[e];if('"'!==r&&"'"!==r)throw new Error('Expected quoted string, found "'+r+'"');for(e++;e<t.length&&t[e]!==r;)n+=t[e],e++;if(t[e]!==r)throw new Error("Unterminated "+i+" value");return[++e,n]},e.readElementExp=function(t,e){e=P(t,e);for(var i="";e<t.length&&!/\s/.test(t[e]);)i+=t[e],e++;if(!this.suppressValidationErr&&!s(i))throw new Error('Invalid element name: "'+i+'"');var n="";if("E"===t[e=P(t,e)]&&S(t,"MPTY",e))e+=4;else if("A"===t[e]&&S(t,"NY",e))e+=2;else if("("===t[e]){for(e++;e<t.length&&")"!==t[e];)n+=t[e],e++;if(")"!==t[e])throw new Error("Unterminated content model")}else if(!this.suppressValidationErr)throw new Error('Invalid Element Expression, found "'+t[e]+'"');return{elementName:i,contentModel:n.trim(),index:e}},e.readAttlistExp=function(t,e){e=P(t,e);for(var i="";e<t.length&&!/\s/.test(t[e]);)i+=t[e],e++;C(i),e=P(t,e);for(var n="";e<t.length&&!/\s/.test(t[e]);)n+=t[e],e++;if(!C(n))throw new Error('Invalid attribute name: "'+n+'"');e=P(t,e);var r="";if("NOTATION"===t.substring(e,e+8).toUpperCase()){if(r="NOTATION","("!==t[e=P(t,e+=8)])throw new Error("Expected '(', found \""+t[e]+'"');e++;for(var s=[];e<t.length&&")"!==t[e];){for(var o="";e<t.length&&"|"!==t[e]&&")"!==t[e];)o+=t[e],e++;if(!C(o=o.trim()))throw new Error('Invalid notation name: "'+o+'"');s.push(o),"|"===t[e]&&(e++,e=P(t,e))}if(")"!==t[e])throw new Error("Unterminated list of notations");e++,r+=" ("+s.join("|")+")"}else{for(;e<t.length&&!/\s/.test(t[e]);)r+=t[e],e++;if(!this.suppressValidationErr&&!["CDATA","ID","IDREF","IDREFS","ENTITY","ENTITIES","NMTOKEN","NMTOKENS"].includes(r.toUpperCase()))throw new Error('Invalid attribute type: "'+r+'"')}e=P(t,e);var a="";if("#REQUIRED"===t.substring(e,e+8).toUpperCase())a="#REQUIRED",e+=8;else if("#IMPLIED"===t.substring(e,e+7).toUpperCase())a="#IMPLIED",e+=7;else{var l=this.readIdentifierVal(t,e,"ATTLIST");e=l[0],a=l[1]}return{elementName:i,attributeName:n,attributeType:r,defaultValue:a,index:e}},t}(),P=function(t,e){for(;e<t.length&&/\s/.test(t[e]);)e++;return e};function S(t,e,i){for(var n=0;n<e.length;n++)if(e[n]!==t[i+n+1])return!1;return!0}function C(t){if(s(t))return t;throw new Error("Invalid entity name "+t)}const V=/^[-+]?0x[a-fA-F0-9]+$/,j=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,D={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};const L=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;function M(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=Array(e);i<e;i++)n[i]=t[i];return n}var F=function(t){var e;if(this.options=t,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:"'"},gt:{regex:/&(gt|#62|#x3E);/g,val:">"},lt:{regex:/&(lt|#60|#x3C);/g,val:"<"},quot:{regex:/&(quot|#34|#x22);/g,val:'"'}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:"&"},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:" "},cent:{regex:/&(cent|#162);/g,val:"¢"},pound:{regex:/&(pound|#163);/g,val:"£"},yen:{regex:/&(yen|#165);/g,val:"¥"},euro:{regex:/&(euro|#8364);/g,val:"€"},copyright:{regex:/&(copy|#169);/g,val:"©"},reg:{regex:/&(reg|#174);/g,val:"®"},inr:{regex:/&(inr|#8377);/g,val:"₹"},num_dec:{regex:/&#([0-9]{1,7});/g,val:function(t,e){return Q(e,10,"&#")}},num_hex:{regex:/&#x([0-9a-fA-F]{1,6});/g,val:function(t,e){return Q(e,16,"&#x")}}},this.addExternalEntities=k,this.parseXml=B,this.parseTextData=_,this.resolveNameSpace=$,this.buildAttributesMap=R,this.isItStopNode=z,this.replaceEntitiesValue=G,this.readStopNodeData=Z,this.saveTextToParentTag=X,this.addChild=Y,this.ignoreAttributesFn="function"==typeof(e=this.options.ignoreAttributes)?e:Array.isArray(e)?function(t){for(var i,n=function(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return M(t,e);var i={}.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(t):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?M(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}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);!(i=n()).done;){var r=i.value;if("string"==typeof r&&t===r)return!0;if(r instanceof RegExp&&r.test(t))return!0}}:function(){return!1},this.entityExpansionCount=0,this.currentExpandedLength=0,this.options.stopNodes&&this.options.stopNodes.length>0){this.stopNodesExact=new Set,this.stopNodesWildcard=new Set;for(var i=0;i<this.options.stopNodes.length;i++){var n=this.options.stopNodes[i];"string"==typeof n&&(n.startsWith("*.")?this.stopNodesWildcard.add(n.substring(2)):this.stopNodesExact.add(n))}}};function k(t){for(var e=Object.keys(t),i=0;i<e.length;i++){var n=e[i],r=n.replace(/[.\-+*:]/g,"\\.");this.lastEntities[n]={regex:new RegExp("&"+r+";","g"),val:t[n]}}}function _(t,e,i,n,r,s,o){if(void 0!==t&&(this.options.trimValues&&!n&&(t=t.trim()),t.length>0)){o||(t=this.replaceEntitiesValue(t,e,i));var a=this.options.tagValueProcessor(e,t,i,r,s);return null==a?t:typeof a!=typeof t||a!==t?a:this.options.trimValues||t.trim()===t?K(t,this.options.parseTagValue,this.options.numberParseOptions):t}}function $(t){if(this.options.removeNSPrefix){var e=t.split(":"),i="/"===t.charAt(0)?"/":"";if("xmlns"===e[0])return"";2===e.length&&(t=i+e[1])}return t}var U=new RegExp("([^\\s=]+)\\s*(=\\s*(['\"])([\\s\\S]*?)\\3)?","gm");function R(t,e,i){if(!0!==this.options.ignoreAttributes&&"string"==typeof t){for(var n=r(t,U),s=n.length,o={},a=0;a<s;a++){var l=this.resolveNameSpace(n[a][1]);if(!this.ignoreAttributesFn(l,e)){var u=n[a][4],d=this.options.attributeNamePrefix+l;if(l.length)if(this.options.transformAttributeName&&(d=this.options.transformAttributeName(d)),"__proto__"===d&&(d="#__proto__"),void 0!==u){this.options.trimValues&&(u=u.trim()),u=this.replaceEntitiesValue(u,i,e);var h=this.options.attributeValueProcessor(l,u,e);o[d]=null==h?u:typeof h!=typeof u||h!==u?h:K(u,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(o[d]=!0)}}if(!Object.keys(o).length)return;if(this.options.attributesGroupName){var p={};return p[this.options.attributesGroupName]=o,p}return o}}var B=function(t){t=t.replace(/\r\n?/g,"\n");var e=new O("!xml"),i=e,n="",r="";this.entityExpansionCount=0,this.currentExpandedLength=0;for(var s=new A(this.options.processEntities),o=0;o<t.length;o++)if("<"===t[o])if("/"===t[o+1]){var a=W(t,">",o,"Closing Tag is not closed."),l=t.substring(o+2,a).trim();if(this.options.removeNSPrefix){var u=l.indexOf(":");-1!==u&&(l=l.substr(u+1))}this.options.transformTagName&&(l=this.options.transformTagName(l)),i&&(n=this.saveTextToParentTag(n,i,r));var d=r.substring(r.lastIndexOf(".")+1);if(l&&-1!==this.options.unpairedTags.indexOf(l))throw new Error("Unpaired tag can not be used as closing tag: </"+l+">");var h=0;d&&-1!==this.options.unpairedTags.indexOf(d)?(h=r.lastIndexOf(".",r.lastIndexOf(".")-1),this.tagsNodeStack.pop()):h=r.lastIndexOf("."),r=r.substring(0,h),i=this.tagsNodeStack.pop(),n="",o=a}else if("?"===t[o+1]){var p=q(t,o,!1,"?>");if(!p)throw new Error("Pi Tag is not closed.");if(n=this.saveTextToParentTag(n,i,r),this.options.ignoreDeclaration&&"?xml"===p.tagName||this.options.ignorePiTags);else{var f=new O(p.tagName);f.add(this.options.textNodeName,""),p.tagName!==p.tagExp&&p.attrExpPresent&&(f[":@"]=this.buildAttributesMap(p.tagExp,r,p.tagName)),this.addChild(i,f,r,o)}o=p.closeIndex+1}else if("!--"===t.substr(o+1,3)){var g=W(t,"--\x3e",o+4,"Comment is not closed.");if(this.options.commentPropName){var c,m=t.substring(o+4,g-2);n=this.saveTextToParentTag(n,i,r),i.add(this.options.commentPropName,[(c={},c[this.options.textNodeName]=m,c)])}o=g}else if("!D"===t.substr(o+1,2)){var x=s.readDocType(t,o);this.docTypeEntities=x.entities,o=x.i}else if("!["===t.substr(o+1,2)){var v=W(t,"]]>",o,"CDATA is not closed.")-2,b=t.substring(o+9,v);n=this.saveTextToParentTag(n,i,r);var E,N=this.parseTextData(b,i.tagname,r,!0,!1,!0,!0);null==N&&(N=""),this.options.cdataPropName?i.add(this.options.cdataPropName,[(E={},E[this.options.textNodeName]=b,E)]):i.add(this.options.textNodeName,N),o=v+2}else{var y=q(t,o,this.options.removeNSPrefix),T=y.tagName,w=y.rawTagName,I=y.tagExp,P=y.attrExpPresent,S=y.closeIndex;if(this.options.transformTagName){var C=this.options.transformTagName(T);I===T&&(I=C),T=C}if(this.options.strictReservedNames&&(T===this.options.commentPropName||T===this.options.cdataPropName))throw new Error("Invalid tag name: "+T);i&&n&&"!xml"!==i.tagname&&(n=this.saveTextToParentTag(n,i,r,!1));var V=i;V&&-1!==this.options.unpairedTags.indexOf(V.tagname)&&(i=this.tagsNodeStack.pop(),r=r.substring(0,r.lastIndexOf("."))),T!==e.tagname&&(r+=r?"."+T:T);var j=o;if(this.isItStopNode(this.stopNodesExact,this.stopNodesWildcard,r,T)){var D="";if(I.length>0&&I.lastIndexOf("/")===I.length-1)"/"===T[T.length-1]?(T=T.substr(0,T.length-1),r=r.substr(0,r.length-1),I=T):I=I.substr(0,I.length-1),o=y.closeIndex;else if(-1!==this.options.unpairedTags.indexOf(T))o=y.closeIndex;else{var L=this.readStopNodeData(t,w,S+1);if(!L)throw new Error("Unexpected end of "+w);o=L.i,D=L.tagContent}var M=new O(T);T!==I&&P&&(M[":@"]=this.buildAttributesMap(I,r,T)),D&&(D=this.parseTextData(D,T,r,!0,P,!0,!0)),r=r.substr(0,r.lastIndexOf(".")),M.add(this.options.textNodeName,D),this.addChild(i,M,r,j)}else{if(I.length>0&&I.lastIndexOf("/")===I.length-1){if("/"===T[T.length-1]?(T=T.substr(0,T.length-1),r=r.substr(0,r.length-1),I=T):I=I.substr(0,I.length-1),this.options.transformTagName){var F=this.options.transformTagName(T);I===T&&(I=F),T=F}var k=new O(T);T!==I&&P&&(k[":@"]=this.buildAttributesMap(I,r,T)),this.addChild(i,k,r,j),r=r.substr(0,r.lastIndexOf("."))}else{if(-1!==this.options.unpairedTags.indexOf(T)){var _=new O(T);T!==I&&P&&(_[":@"]=this.buildAttributesMap(I,r)),this.addChild(i,_,r,j),r=r.substr(0,r.lastIndexOf(".")),o=y.closeIndex;continue}var $=new O(T);if(this.tagsNodeStack.length>this.options.maxNestedTags)throw new Error("Maximum nested tags exceeded");this.tagsNodeStack.push(i),T!==I&&P&&($[":@"]=this.buildAttributesMap(I,r,T)),this.addChild(i,$,r,j),i=$}n="",o=S}}else n+=t[o];return e.child};function Y(t,e,i,n){this.options.captureMetaData||(n=void 0);var r=this.options.updateTag(e.tagname,i,e[":@"]);!1===r||("string"==typeof r?(e.tagname=r,t.addChild(e,n)):t.addChild(e,n))}var G=function(t,e,i){if(-1===t.indexOf("&"))return t;var n=this.options.processEntities;if(!n.enabled)return t;if(n.allowedTags&&!n.allowedTags.includes(e))return t;if(n.tagFilter&&!n.tagFilter(e,i))return t;for(var r in this.docTypeEntities){var s=this.docTypeEntities[r],o=t.match(s.regx);if(o){if(this.entityExpansionCount+=o.length,n.maxTotalExpansions&&this.entityExpansionCount>n.maxTotalExpansions)throw new Error("Entity expansion limit exceeded: "+this.entityExpansionCount+" > "+n.maxTotalExpansions);var a=t.length;if(t=t.replace(s.regx,s.val),n.maxExpandedLength&&(this.currentExpandedLength+=t.length-a,this.currentExpandedLength>n.maxExpandedLength))throw new Error("Total expanded content size exceeded: "+this.currentExpandedLength+" > "+n.maxExpandedLength)}}if(-1===t.indexOf("&"))return t;for(var l in this.lastEntities){var u=this.lastEntities[l];t=t.replace(u.regex,u.val)}if(-1===t.indexOf("&"))return t;if(this.options.htmlEntities)for(var d in this.htmlEntities){var h=this.htmlEntities[d];t=t.replace(h.regex,h.val)}return t.replace(this.ampEntity.regex,this.ampEntity.val)};function X(t,e,i,n){return t&&(void 0===n&&(n=0===e.child.length),void 0!==(t=this.parseTextData(t,e.tagname,i,!1,!!e[":@"]&&0!==Object.keys(e[":@"]).length,n))&&""!==t&&e.add(this.options.textNodeName,t),t=""),t}function z(t,e,i,n){return!(!e||!e.has(n))||!(!t||!t.has(i))}function W(t,e,i,n){var r=t.indexOf(e,i);if(-1===r)throw new Error(n);return r+e.length-1}function q(t,e,i,n){void 0===n&&(n=">");var r=function(t,e,i){var n;void 0===i&&(i=">");for(var r="",s=e;s<t.length;s++){var o=t[s];if(n)o===n&&(n="");else if('"'===o||"'"===o)n=o;else if(o===i[0]){if(!i[1])return{data:r,index:s};if(t[s+1]===i[1])return{data:r,index:s}}else"\t"===o&&(o=" ");r+=o}}(t,e+1,n);if(r){var s=r.data,o=r.index,a=s.search(/\s/),l=s,u=!0;-1!==a&&(l=s.substring(0,a),s=s.substring(a+1).trimStart());var d=l;if(i){var h=l.indexOf(":");-1!==h&&(u=(l=l.substr(h+1))!==r.data.substr(h+1))}return{tagName:l,tagExp:s,closeIndex:o,attrExpPresent:u,rawTagName:d}}}function Z(t,e,i){for(var n=i,r=1;i<t.length;i++)if("<"===t[i])if("/"===t[i+1]){var s=W(t,">",i,e+" is not closed");if(t.substring(i+2,s).trim()===e&&0===--r)return{tagContent:t.substring(n,i),i:s};i=s}else if("?"===t[i+1])i=W(t,"?>",i+1,"StopNode is not closed.");else if("!--"===t.substr(i+1,3))i=W(t,"--\x3e",i+3,"StopNode is not closed.");else if("!["===t.substr(i+1,2))i=W(t,"]]>",i,"StopNode is not closed.")-2;else{var o=q(t,i,">");o&&((o&&o.tagName)===e&&"/"!==o.tagExp[o.tagExp.length-1]&&r++,i=o.closeIndex)}}function K(t,e,i){if(e&&"string"==typeof t){var n=t.trim();return"true"===n||"false"!==n&&function(t,e={}){if(e=Object.assign({},D,e),!t||"string"!=typeof t)return t;let i=t.trim();if(void 0!==e.skipLike&&e.skipLike.test(i))return t;if("0"===t)return 0;if(e.hex&&V.test(i))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")}(i);if(i.includes("e")||i.includes("E"))return function(t,e,i){if(!i.eNotation)return t;const n=e.match(L);if(n){let r=n[1]||"";const s=-1===n[3].indexOf("e")?"E":"e",o=n[2],a=r?t[o.length+1]===s:t[o.length]===s;return o.length>1&&a?t:1!==o.length||!n[3].startsWith(`.${s}`)&&n[3][0]!==s?i.leadingZeros&&!a?(e=(n[1]||"")+n[3],Number(e)):t:Number(e)}return t}(t,i,e);{const r=j.exec(i);if(r){const s=r[1]||"",o=r[2];let a=(n=r[3])&&-1!==n.indexOf(".")?("."===(n=n.replace(/0+$/,""))?n="0":"."===n[0]?n="0"+n:"."===n[n.length-1]&&(n=n.substring(0,n.length-1)),n):n;const l=s?"."===t[o.length+1]:"."===t[o.length];if(!e.leadingZeros&&(o.length>1||1===o.length&&!l))return t;{const n=Number(i),r=String(n);if(0===n)return n;if(-1!==r.search(/[eE]/))return e.eNotation?n:t;if(-1!==i.indexOf("."))return"0"===r||r===a||r===`${s}${a}`?n:t;let l=o?a:i;return o?l===r||s+l===r?n:t:l===r||l===s+r?n:t}}return t}var n}(t,i)}return void 0!==t?t:""}function Q(t,e,i){var n=Number.parseInt(t,e);return n>=0&&n<=1114111?String.fromCodePoint(n):i+t+";"}var J=O.getMetaDataSymbol();function H(t,e){return tt(t,e)}function tt(t,e,i){for(var n,r={},s=0;s<t.length;s++){var o,a=t[s],l=et(a);if(o=void 0===i?l:i+"."+l,l===e.textNodeName)void 0===n?n=a[l]:n+=""+a[l];else{if(void 0===l)continue;if(a[l]){var u=tt(a[l],e,o),d=nt(u,e);a[":@"]?it(u,a[":@"],o,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!==a[J]&&"object"==typeof u&&null!==u&&(u[J]=a[J]),void 0!==r[l]&&Object.prototype.hasOwnProperty.call(r,l)?(Array.isArray(r[l])||(r[l]=[r[l]]),r[l].push(u)):e.isArray(l,o,d)?r[l]=[u]:r[l]=u}}}return"string"==typeof n?n.length>0&&(r[e.textNodeName]=n):void 0!==n&&(r[e.textNodeName]=n),r}function et(t){for(var e=Object.keys(t),i=0;i<e.length;i++){var n=e[i];if(":@"!==n)return n}}function it(t,e,i,n){if(e)for(var r=Object.keys(e),s=r.length,o=0;o<s;o++){var a=r[o];n.isArray(a,i+"."+a,!0,!0)?t[a]=[e[a]]:t[a]=e[a]}}function nt(t,e){var i=e.textNodeName,n=Object.keys(t).length;return 0===n||!(1!==n||!t[i]&&"boolean"!=typeof t[i]&&0!==t[i])}var rt=function(){function t(t){this.externalEntities={},this.options=I(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 i=a(t,e);if(!0!==i)throw Error(i.err.msg+":"+i.err.line+":"+i.err.col)}var n=new F(this.options);n.addExternalEntities(this.externalEntities);var r=n.parseXml(t);return this.options.preserveOrder||void 0===r?r:H(r,this.options)},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 '
'");if("&"===e)throw new Error("An entity with value '&' is not permitted");this.externalEntities[t]=e},t.getMetaDataSymbol=function(){return O.getMetaDataSymbol()},t}();function st(t,e){let i="";return e.format&&e.indentBy.length>0&&(i="\n"),ot(t,e,"",i)}function ot(t,e,i,n){let r="",s=!1;if(!Array.isArray(t)){if(null!=t){let i=t.toString();return i=dt(i,e),i}return""}for(let o=0;o<t.length;o++){const a=t[o],l=at(a);if(void 0===l)continue;let u="";if(u=0===i.length?l:`${i}.${l}`,l===e.textNodeName){let t=a[l];ut(u,e)||(t=e.tagValueProcessor(l,t),t=dt(t,e)),s&&(r+=n),r+=t,s=!1;continue}if(l===e.cdataPropName){s&&(r+=n),r+=`<![CDATA[${a[l][0][e.textNodeName]}]]>`,s=!1;continue}if(l===e.commentPropName){r+=n+`\x3c!--${a[l][0][e.textNodeName]}--\x3e`,s=!0;continue}if("?"===l[0]){const t=lt(a[":@"],e),i="?xml"===l?"":n;let o=a[l][0][e.textNodeName];o=0!==o.length?" "+o:"",r+=i+`<${l}${o}${t}?>`,s=!0;continue}let d=n;""!==d&&(d+=e.indentBy);const h=n+`<${l}${lt(a[":@"],e)}`,p=ot(a[l],e,u,d);-1!==e.unpairedTags.indexOf(l)?e.suppressUnpairedNode?r+=h+">":r+=h+"/>":p&&0!==p.length||!e.suppressEmptyNode?p&&p.endsWith(">")?r+=h+`>${p}${n}</${l}>`:(r+=h+">",p&&""!==n&&(p.includes("/>")||p.includes("</"))?r+=n+e.indentBy+p+n:r+=p,r+=`</${l}>`):r+=h+"/>",s=!0}return r}function at(t){const e=Object.keys(t);for(let i=0;i<e.length;i++){const n=e[i];if(Object.prototype.hasOwnProperty.call(t,n)&&":@"!==n)return n}}function lt(t,e){let i="";if(t&&!e.ignoreAttributes)for(let n in t){if(!Object.prototype.hasOwnProperty.call(t,n))continue;let r=e.attributeValueProcessor(n,t[n]);r=dt(r,e),!0===r&&e.suppressBooleanAttributes?i+=` ${n.substr(e.attributeNamePrefix.length)}`:i+=` ${n.substr(e.attributeNamePrefix.length)}="${r}"`}return i}function ut(t,e){let i=(t=t.substr(0,t.length-e.textNodeName.length-1)).substr(t.lastIndexOf(".")+1);for(let n in e.stopNodes)if(e.stopNodes[n]===t||e.stopNodes[n]==="*."+i)return!0;return!1}function dt(t,e){if(t&&t.length>0&&e.processEntities)for(let i=0;i<e.entities.length;i++){const n=e.entities[i];t=t.replace(n.regex,n.val)}return t}const ht={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:"&"},{regex:new RegExp(">","g"),val:">"},{regex:new RegExp("<","g"),val:"<"},{regex:new RegExp("'","g"),val:"'"},{regex:new RegExp('"',"g"),val:"""}],processEntities:!0,stopNodes:[],oneListGroup:!1};function pt(t){var e;this.options=Object.assign({},ht,t),!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 i of e){if("string"==typeof i&&t===i)return!0;if(i instanceof RegExp&&i.test(t))return!0}}:()=>!1,this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=ct),this.processTextOrObjNode=ft,this.options.format?(this.indentate=gt,this.tagEndChar=">\n",this.newLine="\n"):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}function ft(t,e,i,n){const r=this.j2x(t,i+1,n.concat(e));return void 0!==t[this.options.textNodeName]&&1===Object.keys(t).length?this.buildTextValNode(t[this.options.textNodeName],e,r.attrStr,i):this.buildObjectNode(r.val,e,r.attrStr,i)}function gt(t){return this.options.indentBy.repeat(t)}function ct(t){return!(!t.startsWith(this.options.attributeNamePrefix)||t===this.options.textNodeName)&&t.substr(this.attrPrefixLen)}pt.prototype.build=function(t){return this.options.preserveOrder?st(t,this.options):(Array.isArray(t)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(t={[this.options.arrayNodeName]:t}),this.j2x(t,0,[]).val)},pt.prototype.j2x=function(t,e,i){let n="",r="";const s=i.join(".");for(let o in t)if(Object.prototype.hasOwnProperty.call(t,o))if(void 0===t[o])this.isAttribute(o)&&(r+="");else if(null===t[o])this.isAttribute(o)||o===this.options.cdataPropName?r+="":"?"===o[0]?r+=this.indentate(e)+"<"+o+"?"+this.tagEndChar:r+=this.indentate(e)+"<"+o+"/"+this.tagEndChar;else if(t[o]instanceof Date)r+=this.buildTextValNode(t[o],o,"",e);else if("object"!=typeof t[o]){const i=this.isAttribute(o);if(i&&!this.ignoreAttributesFn(i,s))n+=this.buildAttrPairStr(i,""+t[o]);else if(!i)if(o===this.options.textNodeName){let e=this.options.tagValueProcessor(o,""+t[o]);r+=this.replaceEntitiesValue(e)}else r+=this.buildTextValNode(t[o],o,"",e)}else if(Array.isArray(t[o])){const n=t[o].length;let s="",a="";for(let l=0;l<n;l++){const n=t[o][l];if(void 0===n);else if(null===n)"?"===o[0]?r+=this.indentate(e)+"<"+o+"?"+this.tagEndChar:r+=this.indentate(e)+"<"+o+"/"+this.tagEndChar;else if("object"==typeof n)if(this.options.oneListGroup){const t=this.j2x(n,e+1,i.concat(o));s+=t.val,this.options.attributesGroupName&&n.hasOwnProperty(this.options.attributesGroupName)&&(a+=t.attrStr)}else s+=this.processTextOrObjNode(n,o,e,i);else if(this.options.oneListGroup){let t=this.options.tagValueProcessor(o,n);t=this.replaceEntitiesValue(t),s+=t}else s+=this.buildTextValNode(n,o,"",e)}this.options.oneListGroup&&(s=this.buildObjectNode(s,o,a,e)),r+=s}else if(this.options.attributesGroupName&&o===this.options.attributesGroupName){const e=Object.keys(t[o]),i=e.length;for(let r=0;r<i;r++)n+=this.buildAttrPairStr(e[r],""+t[o][e[r]])}else r+=this.processTextOrObjNode(t[o],o,e,i);return{attrStr:n,val:r}},pt.prototype.buildAttrPairStr=function(t,e){return e=this.options.attributeValueProcessor(t,""+e),e=this.replaceEntitiesValue(e),this.options.suppressBooleanAttributes&&"true"===e?" "+t:" "+t+'="'+e+'"'},pt.prototype.buildObjectNode=function(t,e,i,n){if(""===t)return"?"===e[0]?this.indentate(n)+"<"+e+i+"?"+this.tagEndChar:this.indentate(n)+"<"+e+i+this.closeTag(e)+this.tagEndChar;{let r="</"+e+this.tagEndChar,s="";return"?"===e[0]&&(s="?",r=""),!i&&""!==i||-1!==t.indexOf("<")?!1!==this.options.commentPropName&&e===this.options.commentPropName&&0===s.length?this.indentate(n)+`\x3c!--${t}--\x3e`+this.newLine:this.indentate(n)+"<"+e+i+s+this.tagEndChar+t+this.indentate(n)+r:this.indentate(n)+"<"+e+i+s+">"+t+r}},pt.prototype.closeTag=function(t){let e="";return-1!==this.options.unpairedTags.indexOf(t)?this.options.suppressUnpairedNode||(e="/"):e=this.options.suppressEmptyNode?"/":`></${t}`,e},pt.prototype.buildTextValNode=function(t,e,i,n){if(!1!==this.options.cdataPropName&&e===this.options.cdataPropName)return this.indentate(n)+`<![CDATA[${t}]]>`+this.newLine;if(!1!==this.options.commentPropName&&e===this.options.commentPropName)return this.indentate(n)+`\x3c!--${t}--\x3e`+this.newLine;if("?"===e[0])return this.indentate(n)+"<"+e+i+"?"+this.tagEndChar;{let r=this.options.tagValueProcessor(e,t);return r=this.replaceEntitiesValue(r),""===r?this.indentate(n)+"<"+e+i+this.closeTag(e)+this.tagEndChar:this.indentate(n)+"<"+e+i+">"+r+"</"+e+this.tagEndChar}},pt.prototype.replaceEntitiesValue=function(t){if(t&&t.length>0&&this.options.processEntities)for(let e=0;e<this.options.entities.length;e++){const i=this.options.entities[e];t=t.replace(i.regex,i.val)}return t};const mt=pt;var xt={validate:a};return e})()); | ||
| !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,i)=>{for(var r in i)t.o(i,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:i[r]})},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:()=>Pt,XMLParser:()=>lt,XMLValidator:()=>At});var i=":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",r=new RegExp("^["+i+"]["+i+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040]*$");function n(t,e){for(var i=[],r=e.exec(t);r;){var n=[];n.startIndex=e.lastIndex-r[0].length;for(var s=r.length,o=0;o<s;o++)n.push(r[o]);i.push(n),r=e.exec(t)}return i}var s=function(t){return!(null==r.exec(t))},o={allowBooleanAttributes:!1,unpairedTags:[]};function a(t,e){e=Object.assign({},o,e);var i=[],r=!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=l(t,s+=2)).err)return s}else{if("<"!==t[s]){if(h(t[s]))continue;return v("InvalidChar","char '"+t[s]+"' is not expected.",N(t,s))}var a=s;if("!"===t[++s]){s=p(t,s);continue}var u=!1;"/"===t[s]&&(u=!0,s++);for(var d="";s<t.length&&">"!==t[s]&&" "!==t[s]&&"\t"!==t[s]&&"\n"!==t[s]&&"\r"!==t[s];s++)d+=t[s];if("/"===(d=d.trim())[d.length-1]&&(d=d.substring(0,d.length-1),s--),!b(d))return v("InvalidTag",0===d.trim().length?"Invalid space after '<'.":"Tag '"+d+"' is an invalid name.",N(t,s));var c=f(t,s);if(!1===c)return v("InvalidAttr","Attributes for '"+d+"' have open quote.",N(t,s));var x=c.value;if(s=c.index,"/"===x[x.length-1]){var E=s-x.length,y=g(x=x.substring(0,x.length-1),e);if(!0!==y)return v(y.err.code,y.err.msg,N(t,E+y.err.line));r=!0}else if(u){if(!c.tagClosed)return v("InvalidTag","Closing tag '"+d+"' doesn't have proper closing.",N(t,s));if(x.trim().length>0)return v("InvalidTag","Closing tag '"+d+"' can't have attributes or invalid starting.",N(t,a));if(0===i.length)return v("InvalidTag","Closing tag '"+d+"' has not been opened.",N(t,a));var w=i.pop();if(d!==w.tagName){var S=N(t,w.tagStartPos);return v("InvalidTag","Expected closing tag '"+w.tagName+"' (opened in line "+S.line+", col "+S.col+") instead of closing tag '"+d+"'.",N(t,a))}0==i.length&&(n=!0)}else{var T=g(x,e);if(!0!==T)return v(T.err.code,T.err.msg,N(t,s-x.length+T.err.line));if(!0===n)return v("InvalidXml","Multiple possible root nodes found.",N(t,s));-1!==e.unpairedTags.indexOf(d)||i.push({tagName:d,tagStartPos:a}),r=!0}for(s++;s<t.length;s++)if("<"===t[s]){if("!"===t[s+1]){s=p(t,++s);continue}if("?"!==t[s+1])break;if((s=l(t,++s)).err)return s}else if("&"===t[s]){var P=m(t,s);if(-1==P)return v("InvalidChar","char '&' is not expected.",N(t,s));s=P}else if(!0===n&&!h(t[s]))return v("InvalidXml","Extra text at the end",N(t,s));"<"===t[s]&&s--}return r?1==i.length?v("InvalidTag","Unclosed tag '"+i[0].tagName+"'.",N(t,i[0].tagStartPos)):!(i.length>0)||v("InvalidXml","Invalid '"+JSON.stringify(i.map(function(t){return t.tagName}),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1}):v("InvalidXml","Start tag expected.",1)}function h(t){return" "===t||"\t"===t||"\n"===t||"\r"===t}function l(t,e){for(var i=e;e<t.length;e++)if("?"!=t[e]&&" "!=t[e]);else{var r=t.substr(i,e-i);if(e>5&&"xml"===r)return v("InvalidXml","XML declaration allowed only at the start of the document.",N(t,e));if("?"==t[e]&&">"==t[e+1]){e++;break}}return e}function p(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 i=1;for(e+=8;e<t.length;e++)if("<"===t[e])i++;else if(">"===t[e]&&0===--i)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 u='"',d="'";function f(t,e){for(var i="",r="",n=!1;e<t.length;e++){if(t[e]===u||t[e]===d)""===r?r=t[e]:r!==t[e]||(r="");else if(">"===t[e]&&""===r){n=!0;break}i+=t[e]}return""===r&&{value:i,index:e,tagClosed:n}}var c=new RegExp("(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['\"])(([\\s\\S])*?)\\5)?","g");function g(t,e){for(var i=n(t,c),r={},s=0;s<i.length;s++){if(0===i[s][1].length)return v("InvalidAttr","Attribute '"+i[s][2]+"' has no space in starting.",E(i[s]));if(void 0!==i[s][3]&&void 0===i[s][4])return v("InvalidAttr","Attribute '"+i[s][2]+"' is without value.",E(i[s]));if(void 0===i[s][3]&&!e.allowBooleanAttributes)return v("InvalidAttr","boolean attribute '"+i[s][2]+"' is not allowed.",E(i[s]));var o=i[s][2];if(!x(o))return v("InvalidAttr","Attribute '"+o+"' is an invalid name.",E(i[s]));if(Object.prototype.hasOwnProperty.call(r,o))return v("InvalidAttr","Attribute '"+o+"' is repeated.",E(i[s]));r[o]=1}return!0}function m(t,e){if(";"===t[++e])return-1;if("#"===t[e])return function(t,e){var i=/\d/;for("x"===t[e]&&(e++,i=/[\da-fA-F]/);e<t.length;e++){if(";"===t[e])return e;if(!t[e].match(i))break}return-1}(t,++e);for(var i=0;e<t.length;e++,i++)if(!(t[e].match(/\w/)&&i<20)){if(";"===t[e])break;return-1}return e}function v(t,e,i){return{err:{code:t,msg:e,line:i.line||i,col:i.col}}}function x(t){return s(t)}function b(t){return s(t)}function N(t,e){var i=t.substring(0,e).split(/\r?\n/);return{line:i.length,col:i[i.length-1].length+1}}function E(t){return t.startIndex+t[1].length}var y={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,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(t,e,i){return t},captureMetaData:!1,maxNestedTags:100,strictReservedNames:!0,jPath:!0};function w(t){return"boolean"==typeof t?{enabled:t,maxEntitySize:1e4,maxExpansionDepth:10,maxTotalExpansions:1e3,maxExpandedLength:1e5,maxEntityCount:100,allowedTags:null,tagFilter:null}:"object"==typeof t&&null!==t?{enabled:!1!==t.enabled,maxEntitySize:null!=(e=t.maxEntitySize)?e:1e4,maxExpansionDepth:null!=(i=t.maxExpansionDepth)?i:10,maxTotalExpansions:null!=(r=t.maxTotalExpansions)?r:1e3,maxExpandedLength:null!=(n=t.maxExpandedLength)?n:1e5,maxEntityCount:null!=(s=t.maxEntityCount)?s:100,allowedTags:null!=(o=t.allowedTags)?o:null,tagFilter:null!=(a=t.tagFilter)?a:null}:w(!0);var e,i,r,n,s,o,a}var S,T=function(t){var e=Object.assign({},y,t);return e.processEntities=w(e.processEntities),e.stopNodes&&Array.isArray(e.stopNodes)&&(e.stopNodes=e.stopNodes.map(function(t){return"string"==typeof t&&t.startsWith("*.")?".."+t.substring(2):t})),e};S="function"!=typeof Symbol?"@@xmlMetadata":Symbol("XML Node Metadata");var P=function(){function t(t){this.tagname=t,this.child=[],this[":@"]=Object.create(null)}var e=t.prototype;return e.add=function(t,e){var i;"__proto__"===t&&(t="#__proto__"),this.child.push(((i={})[t]=e,i))},e.addChild=function(t,e){var i,r;"__proto__"===t.tagname&&(t.tagname="#__proto__"),t[":@"]&&Object.keys(t[":@"]).length>0?this.child.push(((i={})[t.tagname]=t.child,i[":@"]=t[":@"],i)):this.child.push(((r={})[t.tagname]=t.child,r)),void 0!==e&&(this.child[this.child.length-1][S]={startIndex:e})},t.getMetaDataSymbol=function(){return S},t}(),A=function(){function t(t){this.suppressValidationErr=!t,this.options=t}var e=t.prototype;return e.readDocType=function(t,e){var i=Object.create(null),r=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,o=!1;e<t.length;e++)if("<"!==t[e]||o)if(">"===t[e]){if(o?"-"===t[e-1]&&"-"===t[e-2]&&(o=!1,n--):n--,0===n)break}else"["===t[e]?s=!0:t[e];else{if(s&&C(t,"!ENTITY",e)){e+=7;var a=void 0,h=void 0,l=this.readEntityExp(t,e+1,this.suppressValidationErr);if(a=l[0],h=l[1],e=l[2],-1===h.indexOf("&")){if(!1!==this.options.enabled&&this.options.maxEntityCount&&r>=this.options.maxEntityCount)throw new Error("Entity count ("+(r+1)+") exceeds maximum allowed ("+this.options.maxEntityCount+")");var p=a.replace(/[.\-+*:]/g,"\\.");i[a]={regx:RegExp("&"+p+";","g"),val:h},r++}}else if(s&&C(t,"!ELEMENT",e))e+=8,e=this.readElementExp(t,e+1).index;else if(s&&C(t,"!ATTLIST",e))e+=8;else if(s&&C(t,"!NOTATION",e))e+=9,e=this.readNotationExp(t,e+1,this.suppressValidationErr).index;else{if(!C(t,"!--",e))throw new Error("Invalid DOCTYPE");o=!0}n++}if(0!==n)throw new Error("Unclosed DOCTYPE");return{entities:i,i:e}},e.readEntityExp=function(t,e){e=O(t,e);for(var i="";e<t.length&&!/\s/.test(t[e])&&'"'!==t[e]&&"'"!==t[e];)i+=t[e],e++;if(I(i),e=O(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 r,n=this.readIdentifierVal(t,e,"entity");if(e=n[0],r=n[1],!1!==this.options.enabled&&this.options.maxEntitySize&&r.length>this.options.maxEntitySize)throw new Error('Entity "'+i+'" size ('+r.length+") exceeds maximum allowed size ("+this.options.maxEntitySize+")");return[i,r,--e]},e.readNotationExp=function(t,e){e=O(t,e);for(var i="";e<t.length&&!/\s/.test(t[e]);)i+=t[e],e++;!this.suppressValidationErr&&I(i),e=O(t,e);var r=t.substring(e,e+6).toUpperCase();if(!this.suppressValidationErr&&"SYSTEM"!==r&&"PUBLIC"!==r)throw new Error('Expected SYSTEM or PUBLIC, found "'+r+'"');e+=r.length,e=O(t,e);var n=null,s=null;if("PUBLIC"===r){var o=this.readIdentifierVal(t,e,"publicIdentifier");if(e=o[0],n=o[1],'"'===t[e=O(t,e)]||"'"===t[e]){var a=this.readIdentifierVal(t,e,"systemIdentifier");e=a[0],s=a[1]}}else if("SYSTEM"===r){var h=this.readIdentifierVal(t,e,"systemIdentifier");if(e=h[0],s=h[1],!this.suppressValidationErr&&!s)throw new Error("Missing mandatory system identifier for SYSTEM notation")}return{notationName:i,publicIdentifier:n,systemIdentifier:s,index:--e}},e.readIdentifierVal=function(t,e,i){var r="",n=t[e];if('"'!==n&&"'"!==n)throw new Error('Expected quoted string, found "'+n+'"');for(e++;e<t.length&&t[e]!==n;)r+=t[e],e++;if(t[e]!==n)throw new Error("Unterminated "+i+" value");return[++e,r]},e.readElementExp=function(t,e){e=O(t,e);for(var i="";e<t.length&&!/\s/.test(t[e]);)i+=t[e],e++;if(!this.suppressValidationErr&&!s(i))throw new Error('Invalid element name: "'+i+'"');var r="";if("E"===t[e=O(t,e)]&&C(t,"MPTY",e))e+=4;else if("A"===t[e]&&C(t,"NY",e))e+=2;else if("("===t[e]){for(e++;e<t.length&&")"!==t[e];)r+=t[e],e++;if(")"!==t[e])throw new Error("Unterminated content model")}else if(!this.suppressValidationErr)throw new Error('Invalid Element Expression, found "'+t[e]+'"');return{elementName:i,contentModel:r.trim(),index:e}},e.readAttlistExp=function(t,e){e=O(t,e);for(var i="";e<t.length&&!/\s/.test(t[e]);)i+=t[e],e++;I(i),e=O(t,e);for(var r="";e<t.length&&!/\s/.test(t[e]);)r+=t[e],e++;if(!I(r))throw new Error('Invalid attribute name: "'+r+'"');e=O(t,e);var n="";if("NOTATION"===t.substring(e,e+8).toUpperCase()){if(n="NOTATION","("!==t[e=O(t,e+=8)])throw new Error("Expected '(', found \""+t[e]+'"');e++;for(var s=[];e<t.length&&")"!==t[e];){for(var o="";e<t.length&&"|"!==t[e]&&")"!==t[e];)o+=t[e],e++;if(!I(o=o.trim()))throw new Error('Invalid notation name: "'+o+'"');s.push(o),"|"===t[e]&&(e++,e=O(t,e))}if(")"!==t[e])throw new Error("Unterminated list of notations");e++,n+=" ("+s.join("|")+")"}else{for(;e<t.length&&!/\s/.test(t[e]);)n+=t[e],e++;if(!this.suppressValidationErr&&!["CDATA","ID","IDREF","IDREFS","ENTITY","ENTITIES","NMTOKEN","NMTOKENS"].includes(n.toUpperCase()))throw new Error('Invalid attribute type: "'+n+'"')}e=O(t,e);var a="";if("#REQUIRED"===t.substring(e,e+8).toUpperCase())a="#REQUIRED",e+=8;else if("#IMPLIED"===t.substring(e,e+7).toUpperCase())a="#IMPLIED",e+=7;else{var h=this.readIdentifierVal(t,e,"ATTLIST");e=h[0],a=h[1]}return{elementName:i,attributeName:r,attributeType:n,defaultValue:a,index:e}},t}(),O=function(t,e){for(;e<t.length&&/\s/.test(t[e]);)e++;return e};function C(t,e,i){for(var r=0;r<e.length;r++)if(e[r]!==t[i+r+1])return!1;return!0}function I(t){if(s(t))return t;throw new Error("Invalid entity name "+t)}const j=/^[-+]?0x[a-fA-F0-9]+$/,$=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,_={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};const V=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;function k(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,r=Array(e);i<e;i++)r[i]=t[i];return r}class D{constructor(t,e={}){this.pattern=t,this.separator=e.separator||".",this.segments=this._parse(t),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 i=0,r="";for(;i<t.length;)t[i]===this.separator?i+1<t.length&&t[i+1]===this.separator?(r.trim()&&(e.push(this._parseSegment(r.trim())),r=""),e.push({type:"deep-wildcard"}),i+=2):(r.trim()&&e.push(this._parseSegment(r.trim())),r="",i++):(r+=t[i],i++);return r.trim()&&e.push(this._parseSegment(r.trim())),e}_parseSegment(t){const e={type:"tag"};let i=null,r=t;const n=t.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);if(n&&(r=n[1]+n[3],n[2])){const t=n[2].slice(1,-1);t&&(i=t)}let s,o,a=r;if(r.includes("::")){const e=r.indexOf("::");if(s=r.substring(0,e).trim(),a=r.substring(e+2).trim(),!s)throw new Error(`Invalid namespace in pattern: ${t}`)}let h=null;if(a.includes(":")){const t=a.lastIndexOf(":"),e=a.substring(0,t).trim(),i=a.substring(t+1).trim();["first","last","odd","even"].includes(i)||/^nth\(\d+\)$/.test(i)?(o=e,h=i):o=a}else o=a;if(!o)throw new Error(`Invalid segment pattern: ${t}`);if(e.tag=o,s&&(e.namespace=s),i)if(i.includes("=")){const t=i.indexOf("=");e.attrName=i.substring(0,t).trim(),e.attrValue=i.substring(t+1).trim()}else e.attrName=i.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 M{constructor(t={}){this.separator=t.separator||".",this.path=[],this.siblingStacks=[]}push(t,e=null,i=null){this.path.length>0&&(this.path[this.path.length-1].values=void 0);const r=this.path.length;this.siblingStacks[r]||(this.siblingStacks[r]=new Map);const n=this.siblingStacks[r],s=i?`${i}:${t}`:t,o=n.get(s)||0;let a=0;for(const t of n.values())a+=t;n.set(s,o+1);const h={tag:t,position:a,counter:o};null!=i&&(h.namespace=i),null!=e&&(h.values=e),this.path.push(h)}pop(){if(0===this.path.length)return;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;const e=this.path[this.path.length-1];return e.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 i=t||this.separator;return this.path.map(t=>e&&t.namespace?`${t.namespace}:${t.tag}`:t.tag).join(i)}toArray(){return this.path.map(t=>t.tag)}reset(){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++){const i=t[e],r=this.path[e],n=e===this.path.length-1;if(!this._matchSegment(i,r,n))return!1}return!0}_matchWithDeepWildcard(t){let e=this.path.length-1,i=t.length-1;for(;i>=0&&e>=0;){const r=t[i];if("deep-wildcard"===r.type){if(i--,i<0)return!0;const r=t[i];let n=!1;for(let t=e;t>=0;t--){const s=t===this.path.length-1;if(this._matchSegment(r,this.path[t],s)){e=t-1,i--,n=!0;break}}if(!n)return!1}else{const t=e===this.path.length-1;if(!this._matchSegment(r,this.path[e],t))return!1;e--,i--}}return i<0}_matchSegment(t,e,i){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(!i)return!1;if(!e.values||!(t.attrName in e.values))return!1;if(void 0!==t.attrValue){const i=e.values[t.attrName];if(String(i)!==String(t.attrValue))return!1}}if(void 0!==t.position){if(!i)return!1;const r=e.counter??0;if("first"===t.position&&0!==r)return!1;if("odd"===t.position&&r%2!=1)return!1;if("even"===t.position&&r%2!=0)return!1;if("nth"===t.position&&r!==t.positionValue)return!1}return!0}snapshot(){return{path:this.path.map(t=>({...t})),siblingStacks:this.siblingStacks.map(t=>new Map(t))}}restore(t){this.path=t.path.map(t=>({...t})),this.siblingStacks=t.siblingStacks.map(t=>new Map(t))}}function F(t,e){if(!t)return{};var i=e.attributesGroupName?t[e.attributesGroupName]:t;if(!i)return{};var r={};for(var n in i)n.startsWith(e.attributeNamePrefix)?r[n.substring(e.attributeNamePrefix.length)]=i[n]:r[n]=i[n];return r}function L(t){if(t&&"string"==typeof t){var e=t.indexOf(":");if(-1!==e&&e>0){var i=t.substring(0,e);if("xmlns"!==i)return i}}}var W=function(t){var e;if(this.options=t,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:"'"},gt:{regex:/&(gt|#62|#x3E);/g,val:">"},lt:{regex:/&(lt|#60|#x3C);/g,val:"<"},quot:{regex:/&(quot|#34|#x22);/g,val:'"'}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:"&"},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:" "},cent:{regex:/&(cent|#162);/g,val:"¢"},pound:{regex:/&(pound|#163);/g,val:"£"},yen:{regex:/&(yen|#165);/g,val:"¥"},euro:{regex:/&(euro|#8364);/g,val:"€"},copyright:{regex:/&(copy|#169);/g,val:"©"},reg:{regex:/&(reg|#174);/g,val:"®"},inr:{regex:/&(inr|#8377);/g,val:"₹"},num_dec:{regex:/&#([0-9]{1,7});/g,val:function(t,e){return et(e,10,"&#")}},num_hex:{regex:/&#x([0-9a-fA-F]{1,6});/g,val:function(t,e){return et(e,16,"&#x")}}},this.addExternalEntities=R,this.parseXml=X,this.parseTextData=G,this.resolveNameSpace=U,this.buildAttributesMap=Y,this.isItStopNode=K,this.replaceEntitiesValue=q,this.readStopNodeData=H,this.saveTextToParentTag=Z,this.addChild=z,this.ignoreAttributesFn="function"==typeof(e=this.options.ignoreAttributes)?e:Array.isArray(e)?function(t){for(var i,r=function(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return k(t,e);var i={}.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(t):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?k(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}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);!(i=r()).done;){var n=i.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,this.matcher=new M,this.isCurrentNodeStopNode=!1,this.options.stopNodes&&this.options.stopNodes.length>0){this.stopNodeExpressions=[];for(var i=0;i<this.options.stopNodes.length;i++){var r=this.options.stopNodes[i];"string"==typeof r?this.stopNodeExpressions.push(new D(r)):r instanceof D&&this.stopNodeExpressions.push(r)}}};function R(t){for(var e=Object.keys(t),i=0;i<e.length;i++){var r=e[i],n=r.replace(/[.\-+*:]/g,"\\.");this.lastEntities[r]={regex:new RegExp("&"+n+";","g"),val:t[r]}}}function G(t,e,i,r,n,s,o){if(void 0!==t&&(this.options.trimValues&&!r&&(t=t.trim()),t.length>0)){o||(t=this.replaceEntitiesValue(t,e,i));var a=this.options.jPath?i.toString():i,h=this.options.tagValueProcessor(e,t,a,n,s);return null==h?t:typeof h!=typeof t||h!==t?h:this.options.trimValues||t.trim()===t?tt(t,this.options.parseTagValue,this.options.numberParseOptions):t}}function U(t){if(this.options.removeNSPrefix){var e=t.split(":"),i="/"===t.charAt(0)?"/":"";if("xmlns"===e[0])return"";2===e.length&&(t=i+e[1])}return t}var B=new RegExp("([^\\s=]+)\\s*(=\\s*(['\"])([\\s\\S]*?)\\3)?","gm");function Y(t,e,i){if(!0!==this.options.ignoreAttributes&&"string"==typeof t){for(var r=n(t,B),s=r.length,o={},a={},h=0;h<s;h++){var l=this.resolveNameSpace(r[h][1]),p=r[h][4];if(l.length&&void 0!==p){var u=p;this.options.trimValues&&(u=u.trim()),u=this.replaceEntitiesValue(u,i,e),a[l]=u}}Object.keys(a).length>0&&"object"==typeof e&&e.updateCurrent&&e.updateCurrent(a);for(var d=0;d<s;d++){var f=this.resolveNameSpace(r[d][1]),c=this.options.jPath?e.toString():e;if(!this.ignoreAttributesFn(f,c)){var g=r[d][4],m=this.options.attributeNamePrefix+f;if(f.length)if(this.options.transformAttributeName&&(m=this.options.transformAttributeName(m)),"__proto__"===m&&(m="#__proto__"),void 0!==g){this.options.trimValues&&(g=g.trim()),g=this.replaceEntitiesValue(g,i,e);var v=this.options.jPath?e.toString():e,x=this.options.attributeValueProcessor(f,g,v);o[m]=null==x?g:typeof x!=typeof g||x!==g?x:tt(g,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(o[m]=!0)}}if(!Object.keys(o).length)return;if(this.options.attributesGroupName){var b={};return b[this.options.attributesGroupName]=o,b}return o}}var X=function(t){t=t.replace(/\r\n?/g,"\n");var e=new P("!xml"),i=e,r="";this.matcher.reset(),this.entityExpansionCount=0,this.currentExpandedLength=0;for(var n=new A(this.options.processEntities),s=0;s<t.length;s++)if("<"===t[s])if("/"===t[s+1]){var o=Q(t,">",s,"Closing Tag is not closed."),a=t.substring(s+2,o).trim();if(this.options.removeNSPrefix){var h=a.indexOf(":");-1!==h&&(a=a.substr(h+1))}this.options.transformTagName&&(a=this.options.transformTagName(a)),i&&(r=this.saveTextToParentTag(r,i,this.matcher));var l=this.matcher.getCurrentTag();if(a&&-1!==this.options.unpairedTags.indexOf(a))throw new Error("Unpaired tag can not be used as closing tag: </"+a+">");l&&-1!==this.options.unpairedTags.indexOf(l)&&(this.matcher.pop(),this.tagsNodeStack.pop()),this.matcher.pop(),this.isCurrentNodeStopNode=!1,i=this.tagsNodeStack.pop(),r="",s=o}else if("?"===t[s+1]){var p=J(t,s,!1,"?>");if(!p)throw new Error("Pi Tag is not closed.");if(r=this.saveTextToParentTag(r,i,this.matcher),this.options.ignoreDeclaration&&"?xml"===p.tagName||this.options.ignorePiTags);else{var u=new P(p.tagName);u.add(this.options.textNodeName,""),p.tagName!==p.tagExp&&p.attrExpPresent&&(u[":@"]=this.buildAttributesMap(p.tagExp,this.matcher,p.tagName)),this.addChild(i,u,this.matcher,s)}s=p.closeIndex+1}else if("!--"===t.substr(s+1,3)){var d=Q(t,"--\x3e",s+4,"Comment is not closed.");if(this.options.commentPropName){var f,c=t.substring(s+4,d-2);r=this.saveTextToParentTag(r,i,this.matcher),i.add(this.options.commentPropName,[(f={},f[this.options.textNodeName]=c,f)])}s=d}else if("!D"===t.substr(s+1,2)){var g=n.readDocType(t,s);this.docTypeEntities=g.entities,s=g.i}else if("!["===t.substr(s+1,2)){var m=Q(t,"]]>",s,"CDATA is not closed.")-2,v=t.substring(s+9,m);r=this.saveTextToParentTag(r,i,this.matcher);var x,b=this.parseTextData(v,i.tagname,this.matcher,!0,!1,!0,!0);null==b&&(b=""),this.options.cdataPropName?i.add(this.options.cdataPropName,[(x={},x[this.options.textNodeName]=v,x)]):i.add(this.options.textNodeName,b),s=m+2}else{var N=J(t,s,this.options.removeNSPrefix);if(!N){var E=t.substring(Math.max(0,s-50),Math.min(t.length,s+50));throw new Error("readTagExp returned undefined at position "+s+'. Context: "'+E+'"')}var y=N.tagName,w=N.rawTagName,S=N.tagExp,T=N.attrExpPresent,O=N.closeIndex;if(this.options.transformTagName){var C=this.options.transformTagName(y);S===y&&(S=C),y=C}if(this.options.strictReservedNames&&(y===this.options.commentPropName||y===this.options.cdataPropName))throw new Error("Invalid tag name: "+y);i&&r&&"!xml"!==i.tagname&&(r=this.saveTextToParentTag(r,i,this.matcher,!1));var I=i;I&&-1!==this.options.unpairedTags.indexOf(I.tagname)&&(i=this.tagsNodeStack.pop(),this.matcher.pop());var j=!1;S.length>0&&S.lastIndexOf("/")===S.length-1&&(j=!0,S="/"===y[y.length-1]?y=y.substr(0,y.length-1):S.substr(0,S.length-1),T=y!==S);var $,_=null;$=L(w),y!==e.tagname&&this.matcher.push(y,{},$),y!==S&&T&&(_=this.buildAttributesMap(S,this.matcher,y))&&F(_,this.options),y!==e.tagname&&(this.isCurrentNodeStopNode=this.isItStopNode(this.stopNodeExpressions,this.matcher));var V=s;if(this.isCurrentNodeStopNode){var k="";if(j)s=N.closeIndex;else if(-1!==this.options.unpairedTags.indexOf(y))s=N.closeIndex;else{var D=this.readStopNodeData(t,w,O+1);if(!D)throw new Error("Unexpected end of "+w);s=D.i,k=D.tagContent}var M=new P(y);_&&(M[":@"]=_),M.add(this.options.textNodeName,k),this.matcher.pop(),this.isCurrentNodeStopNode=!1,this.addChild(i,M,this.matcher,V)}else{if(j){if(this.options.transformTagName){var W=this.options.transformTagName(y);S===y&&(S=W),y=W}var R=new P(y);_&&(R[":@"]=_),this.addChild(i,R,this.matcher,V),this.matcher.pop(),this.isCurrentNodeStopNode=!1}else{if(-1!==this.options.unpairedTags.indexOf(y)){var G=new P(y);_&&(G[":@"]=_),this.addChild(i,G,this.matcher,V),this.matcher.pop(),this.isCurrentNodeStopNode=!1,s=N.closeIndex;continue}var U=new P(y);if(this.tagsNodeStack.length>this.options.maxNestedTags)throw new Error("Maximum nested tags exceeded");this.tagsNodeStack.push(i),_&&(U[":@"]=_),this.addChild(i,U,this.matcher,V),i=U}r="",s=O}}else r+=t[s];return e.child};function z(t,e,i,r){this.options.captureMetaData||(r=void 0);var n=this.options.jPath?i.toString():i,s=this.options.updateTag(e.tagname,n,e[":@"]);!1===s||("string"==typeof s?(e.tagname=s,t.addChild(e,r)):t.addChild(e,r))}function q(t,e,i){var r=this.options.processEntities;if(!r||!r.enabled)return t;if(r.allowedTags){var n=this.options.jPath?i.toString():i;if(!(Array.isArray(r.allowedTags)?r.allowedTags.includes(e):r.allowedTags(e,n)))return t}if(r.tagFilter){var s=this.options.jPath?i.toString():i;if(!r.tagFilter(e,s))return t}for(var o in this.docTypeEntities){var a=this.docTypeEntities[o],h=t.match(a.regx);if(h){if(this.entityExpansionCount+=h.length,r.maxTotalExpansions&&this.entityExpansionCount>r.maxTotalExpansions)throw new Error("Entity expansion limit exceeded: "+this.entityExpansionCount+" > "+r.maxTotalExpansions);var l=t.length;if(t=t.replace(a.regx,a.val),r.maxExpandedLength&&(this.currentExpandedLength+=t.length-l,this.currentExpandedLength>r.maxExpandedLength))throw new Error("Total expanded content size exceeded: "+this.currentExpandedLength+" > "+r.maxExpandedLength)}}if(-1===t.indexOf("&"))return t;for(var p in this.lastEntities){var u=this.lastEntities[p];t=t.replace(u.regex,u.val)}if(-1===t.indexOf("&"))return t;if(this.options.htmlEntities)for(var d in this.htmlEntities){var f=this.htmlEntities[d];t=t.replace(f.regex,f.val)}return t.replace(this.ampEntity.regex,this.ampEntity.val)}function Z(t,e,i,r){return t&&(void 0===r&&(r=0===e.child.length),void 0!==(t=this.parseTextData(t,e.tagname,i,!1,!!e[":@"]&&0!==Object.keys(e[":@"]).length,r))&&""!==t&&e.add(this.options.textNodeName,t),t=""),t}function K(t,e){if(!t||0===t.length)return!1;for(var i=0;i<t.length;i++)if(e.matches(t[i]))return!0;return!1}function Q(t,e,i,r){var n=t.indexOf(e,i);if(-1===n)throw new Error(r);return n+e.length-1}function J(t,e,i,r){void 0===r&&(r=">");var n=function(t,e,i){var r;void 0===i&&(i=">");for(var n="",s=e;s<t.length;s++){var o=t[s];if(r)o===r&&(r="");else if('"'===o||"'"===o)r=o;else if(o===i[0]){if(!i[1])return{data:n,index:s};if(t[s+1]===i[1])return{data:n,index:s}}else"\t"===o&&(o=" ");n+=o}}(t,e+1,r);if(n){var s=n.data,o=n.index,a=s.search(/\s/),h=s,l=!0;-1!==a&&(h=s.substring(0,a),s=s.substring(a+1).trimStart());var p=h;if(i){var u=h.indexOf(":");-1!==u&&(l=(h=h.substr(u+1))!==n.data.substr(u+1))}return{tagName:h,tagExp:s,closeIndex:o,attrExpPresent:l,rawTagName:p}}}function H(t,e,i){for(var r=i,n=1;i<t.length;i++)if("<"===t[i])if("/"===t[i+1]){var s=Q(t,">",i,e+" is not closed");if(t.substring(i+2,s).trim()===e&&0===--n)return{tagContent:t.substring(r,i),i:s};i=s}else if("?"===t[i+1])i=Q(t,"?>",i+1,"StopNode is not closed.");else if("!--"===t.substr(i+1,3))i=Q(t,"--\x3e",i+3,"StopNode is not closed.");else if("!["===t.substr(i+1,2))i=Q(t,"]]>",i,"StopNode is not closed.")-2;else{var o=J(t,i,">");o&&((o&&o.tagName)===e&&"/"!==o.tagExp[o.tagExp.length-1]&&n++,i=o.closeIndex)}}function tt(t,e,i){if(e&&"string"==typeof t){var r=t.trim();return"true"===r||"false"!==r&&function(t,e={}){if(e=Object.assign({},_,e),!t||"string"!=typeof t)return t;let i=t.trim();if(void 0!==e.skipLike&&e.skipLike.test(i))return t;if("0"===t)return 0;if(e.hex&&j.test(i))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")}(i);if(i.includes("e")||i.includes("E"))return function(t,e,i){if(!i.eNotation)return t;const r=e.match(V);if(r){let n=r[1]||"";const s=-1===r[3].indexOf("e")?"E":"e",o=r[2],a=n?t[o.length+1]===s:t[o.length]===s;return o.length>1&&a?t:1!==o.length||!r[3].startsWith(`.${s}`)&&r[3][0]!==s?i.leadingZeros&&!a?(e=(r[1]||"")+r[3],Number(e)):t:Number(e)}return t}(t,i,e);{const n=$.exec(i);if(n){const s=n[1]||"",o=n[2];let a=(r=n[3])&&-1!==r.indexOf(".")?("."===(r=r.replace(/0+$/,""))?r="0":"."===r[0]?r="0"+r:"."===r[r.length-1]&&(r=r.substring(0,r.length-1)),r):r;const h=s?"."===t[o.length+1]:"."===t[o.length];if(!e.leadingZeros&&(o.length>1||1===o.length&&!h))return t;{const r=Number(i),n=String(r);if(0===r)return r;if(-1!==n.search(/[eE]/))return e.eNotation?r:t;if(-1!==i.indexOf("."))return"0"===n||n===a||n===`${s}${a}`?r:t;let h=o?a:i;return o?h===n||s+h===n?r:t:h===n||h===s+n?r:t}}return t}var r}(t,i)}return void 0!==t?t:""}function et(t,e,i){var r=Number.parseInt(t,e);return r>=0&&r<=1114111?String.fromCodePoint(r):i+t+";"}var it=P.getMetaDataSymbol();function rt(t,e){if(!t||"object"!=typeof t)return{};if(!e)return t;var i={};for(var r in t)r.startsWith(e)?i[r.substring(e.length)]=t[r]:i[r]=t[r];return i}function nt(t,e,i){return st(t,e,i)}function st(t,e,i){for(var r,n={},s=0;s<t.length;s++){var o=t[s],a=ot(o);if(void 0!==a&&a!==e.textNodeName){var h=rt(o[":@"]||{},e.attributeNamePrefix);i.push(a,h)}if(a===e.textNodeName)void 0===r?r=o[a]:r+=""+o[a];else{if(void 0===a)continue;if(o[a]){var l=st(o[a],e,i),p=ht(l,e);if(o[":@"]?at(l,o[":@"],i,e):1!==Object.keys(l).length||void 0===l[e.textNodeName]||e.alwaysCreateTextNode?0===Object.keys(l).length&&(e.alwaysCreateTextNode?l[e.textNodeName]="":l=""):l=l[e.textNodeName],void 0!==o[it]&&"object"==typeof l&&null!==l&&(l[it]=o[it]),void 0!==n[a]&&Object.prototype.hasOwnProperty.call(n,a))Array.isArray(n[a])||(n[a]=[n[a]]),n[a].push(l);else{var u=e.jPath?i.toString():i;e.isArray(a,u,p)?n[a]=[l]:n[a]=l}void 0!==a&&a!==e.textNodeName&&i.pop()}}}return"string"==typeof r?r.length>0&&(n[e.textNodeName]=r):void 0!==r&&(n[e.textNodeName]=r),n}function ot(t){for(var e=Object.keys(t),i=0;i<e.length;i++){var r=e[i];if(":@"!==r)return r}}function at(t,e,i,r){if(e)for(var n=Object.keys(e),s=n.length,o=0;o<s;o++){var a=n[o],h=a.startsWith(r.attributeNamePrefix)?a.substring(r.attributeNamePrefix.length):a,l=r.jPath?i.toString()+"."+h:i;r.isArray(a,l,!0,!0)?t[a]=[e[a]]:t[a]=e[a]}}function ht(t,e){var i=e.textNodeName,r=Object.keys(t).length;return 0===r||!(1!==r||!t[i]&&"boolean"!=typeof t[i]&&0!==t[i])}var lt=function(){function t(t){this.externalEntities={},this.options=T(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 i=a(t,e);if(!0!==i)throw Error(i.err.msg+":"+i.err.line+":"+i.err.col)}var r=new W(this.options);r.addExternalEntities(this.externalEntities);var n=r.parseXml(t);return this.options.preserveOrder||void 0===n?n:nt(n,this.options,r.matcher)},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 '
'");if("&"===e)throw new Error("An entity with value '&' is not permitted");this.externalEntities[t]=e},t.getMetaDataSymbol=function(){return P.getMetaDataSymbol()},t}();class pt{constructor(t,e={}){this.pattern=t,this.separator=e.separator||".",this.segments=this._parse(t),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 i=0,r="";for(;i<t.length;)t[i]===this.separator?i+1<t.length&&t[i+1]===this.separator?(r.trim()&&(e.push(this._parseSegment(r.trim())),r=""),e.push({type:"deep-wildcard"}),i+=2):(r.trim()&&e.push(this._parseSegment(r.trim())),r="",i++):(r+=t[i],i++);return r.trim()&&e.push(this._parseSegment(r.trim())),e}_parseSegment(t){const e={type:"tag"};let i=null,r=t;const n=t.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);if(n&&(r=n[1]+n[3],n[2])){const t=n[2].slice(1,-1);t&&(i=t)}let s,o,a=r;if(r.includes("::")){const e=r.indexOf("::");if(s=r.substring(0,e).trim(),a=r.substring(e+2).trim(),!s)throw new Error(`Invalid namespace in pattern: ${t}`)}let h=null;if(a.includes(":")){const t=a.lastIndexOf(":"),e=a.substring(0,t).trim(),i=a.substring(t+1).trim();["first","last","odd","even"].includes(i)||/^nth\(\d+\)$/.test(i)?(o=e,h=i):o=a}else o=a;if(!o)throw new Error(`Invalid segment pattern: ${t}`);if(e.tag=o,s&&(e.namespace=s),i)if(i.includes("=")){const t=i.indexOf("=");e.attrName=i.substring(0,t).trim(),e.attrValue=i.substring(t+1).trim()}else e.attrName=i.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 ut{constructor(t={}){this.separator=t.separator||".",this.path=[],this.siblingStacks=[]}push(t,e=null,i=null){this.path.length>0&&(this.path[this.path.length-1].values=void 0);const r=this.path.length;this.siblingStacks[r]||(this.siblingStacks[r]=new Map);const n=this.siblingStacks[r],s=i?`${i}:${t}`:t,o=n.get(s)||0;let a=0;for(const t of n.values())a+=t;n.set(s,o+1);const h={tag:t,position:a,counter:o};null!=i&&(h.namespace=i),null!=e&&(h.values=e),this.path.push(h)}pop(){if(0===this.path.length)return;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;const e=this.path[this.path.length-1];return e.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 i=t||this.separator;return this.path.map(t=>e&&t.namespace?`${t.namespace}:${t.tag}`:t.tag).join(i)}toArray(){return this.path.map(t=>t.tag)}reset(){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++){const i=t[e],r=this.path[e],n=e===this.path.length-1;if(!this._matchSegment(i,r,n))return!1}return!0}_matchWithDeepWildcard(t){let e=this.path.length-1,i=t.length-1;for(;i>=0&&e>=0;){const r=t[i];if("deep-wildcard"===r.type){if(i--,i<0)return!0;const r=t[i];let n=!1;for(let t=e;t>=0;t--){const s=t===this.path.length-1;if(this._matchSegment(r,this.path[t],s)){e=t-1,i--,n=!0;break}}if(!n)return!1}else{const t=e===this.path.length-1;if(!this._matchSegment(r,this.path[e],t))return!1;e--,i--}}return i<0}_matchSegment(t,e,i){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(!i)return!1;if(!e.values||!(t.attrName in e.values))return!1;if(void 0!==t.attrValue){const i=e.values[t.attrName];if(String(i)!==String(t.attrValue))return!1}}if(void 0!==t.position){if(!i)return!1;const r=e.counter??0;if("first"===t.position&&0!==r)return!1;if("odd"===t.position&&r%2!=1)return!1;if("even"===t.position&&r%2!=0)return!1;if("nth"===t.position&&r!==t.positionValue)return!1}return!0}snapshot(){return{path:this.path.map(t=>({...t})),siblingStacks:this.siblingStacks.map(t=>new Map(t))}}restore(t){this.path=t.path.map(t=>({...t})),this.siblingStacks=t.siblingStacks.map(t=>new Map(t))}}function dt(t,e){let i="";e.format&&e.indentBy.length>0&&(i="\n");const r=[];if(e.stopNodes&&Array.isArray(e.stopNodes))for(let t=0;t<e.stopNodes.length;t++){const i=e.stopNodes[t];"string"==typeof i?r.push(new pt(i)):i instanceof pt&&r.push(i)}return ft(t,e,i,new ut,r)}function ft(t,e,i,r,n){let s="",o=!1;if(!Array.isArray(t)){if(null!=t){let i=t.toString();return i=Nt(i,e),i}return""}for(let a=0;a<t.length;a++){const h=t[a],l=vt(h);if(void 0===l)continue;const p=ct(h[":@"],e);r.push(l,p);const u=bt(r,n);if(l===e.textNodeName){let t=h[l];u||(t=e.tagValueProcessor(l,t),t=Nt(t,e)),o&&(s+=i),s+=t,o=!1,r.pop();continue}if(l===e.cdataPropName){o&&(s+=i),s+=`<![CDATA[${h[l][0][e.textNodeName]}]]>`,o=!1,r.pop();continue}if(l===e.commentPropName){s+=i+`\x3c!--${h[l][0][e.textNodeName]}--\x3e`,o=!0,r.pop();continue}if("?"===l[0]){const t=xt(h[":@"],e,u),n="?xml"===l?"":i;let a=h[l][0][e.textNodeName];a=0!==a.length?" "+a:"",s+=n+`<${l}${a}${t}?>`,o=!0,r.pop();continue}let d=i;""!==d&&(d+=e.indentBy);const f=i+`<${l}${xt(h[":@"],e,u)}`;let c;c=u?gt(h[l],e):ft(h[l],e,d,r,n),-1!==e.unpairedTags.indexOf(l)?e.suppressUnpairedNode?s+=f+">":s+=f+"/>":c&&0!==c.length||!e.suppressEmptyNode?c&&c.endsWith(">")?s+=f+`>${c}${i}</${l}>`:(s+=f+">",c&&""!==i&&(c.includes("/>")||c.includes("</"))?s+=i+e.indentBy+c+i:s+=c,s+=`</${l}>`):s+=f+"/>",o=!0,r.pop()}return s}function ct(t,e){if(!t||e.ignoreAttributes)return null;const i={};let r=!1;for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n.startsWith(e.attributeNamePrefix)?n.substr(e.attributeNamePrefix.length):n]=t[n],r=!0);return r?i:null}function gt(t,e){if(!Array.isArray(t))return null!=t?t.toString():"";let i="";for(let r=0;r<t.length;r++){const n=t[r],s=vt(n);if(s===e.textNodeName)i+=n[s];else if(s===e.cdataPropName)i+=n[s][0][e.textNodeName];else if(s===e.commentPropName)i+=n[s][0][e.textNodeName];else{if(s&&"?"===s[0])continue;if(s){const t=mt(n[":@"],e),r=gt(n[s],e);r&&0!==r.length?i+=`<${s}${t}>${r}</${s}>`:i+=`<${s}${t}/>`}}}return i}function mt(t,e){let i="";if(t&&!e.ignoreAttributes)for(let r in t){if(!Object.prototype.hasOwnProperty.call(t,r))continue;let n=t[r];!0===n&&e.suppressBooleanAttributes?i+=` ${r.substr(e.attributeNamePrefix.length)}`:i+=` ${r.substr(e.attributeNamePrefix.length)}="${n}"`}return i}function vt(t){const e=Object.keys(t);for(let i=0;i<e.length;i++){const r=e[i];if(Object.prototype.hasOwnProperty.call(t,r)&&":@"!==r)return r}}function xt(t,e,i){let r="";if(t&&!e.ignoreAttributes)for(let n in t){if(!Object.prototype.hasOwnProperty.call(t,n))continue;let s;i?s=t[n]:(s=e.attributeValueProcessor(n,t[n]),s=Nt(s,e)),!0===s&&e.suppressBooleanAttributes?r+=` ${n.substr(e.attributeNamePrefix.length)}`:r+=` ${n.substr(e.attributeNamePrefix.length)}="${s}"`}return r}function bt(t,e){if(!e||0===e.length)return!1;for(let i=0;i<e.length;i++)if(t.matches(e[i]))return!0;return!1}function Nt(t,e){if(t&&t.length>0&&e.processEntities)for(let i=0;i<e.entities.length;i++){const r=e.entities[i];t=t.replace(r.regex,r.val)}return t}const Et={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:"&"},{regex:new RegExp(">","g"),val:">"},{regex:new RegExp("<","g"),val:"<"},{regex:new RegExp("'","g"),val:"'"},{regex:new RegExp('"',"g"),val:"""}],processEntities:!0,stopNodes:[],oneListGroup:!1,jPath:!0};function yt(t){if(this.options=Object.assign({},Et,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 pt(e)):e instanceof pt&&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 i of e){if("string"==typeof i&&t===i)return!0;if(i instanceof RegExp&&i.test(t))return!0}}:()=>!1,this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=Tt),this.processTextOrObjNode=wt,this.options.format?(this.indentate=St,this.tagEndChar=">\n",this.newLine="\n"):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}function wt(t,e,i,r){const n=this.extractAttributes(t);if(r.push(e,n),this.checkStopNode(r)){const n=this.buildRawContent(t),s=this.buildAttributesForStopNode(t);return r.pop(),this.buildObjectNode(n,e,s,i)}const s=this.j2x(t,i+1,r);return r.pop(),void 0!==t[this.options.textNodeName]&&1===Object.keys(t).length?this.buildTextValNode(t[this.options.textNodeName],e,s.attrStr,i,r):this.buildObjectNode(s.val,e,s.attrStr,i)}function St(t){return this.options.indentBy.repeat(t)}function Tt(t){return!(!t.startsWith(this.options.attributeNamePrefix)||t===this.options.textNodeName)&&t.substr(this.attrPrefixLen)}yt.prototype.build=function(t){if(this.options.preserveOrder)return dt(t,this.options);{Array.isArray(t)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(t={[this.options.arrayNodeName]:t});const e=new ut;return this.j2x(t,0,e).val}},yt.prototype.j2x=function(t,e,i){let r="",n="";const s=this.options.jPath?i.toString():i,o=this.checkStopNode(i);for(let a in t)if(Object.prototype.hasOwnProperty.call(t,a))if(void 0===t[a])this.isAttribute(a)&&(n+="");else if(null===t[a])this.isAttribute(a)||a===this.options.cdataPropName?n+="":"?"===a[0]?n+=this.indentate(e)+"<"+a+"?"+this.tagEndChar:n+=this.indentate(e)+"<"+a+"/"+this.tagEndChar;else if(t[a]instanceof Date)n+=this.buildTextValNode(t[a],a,"",e,i);else if("object"!=typeof t[a]){const h=this.isAttribute(a);if(h&&!this.ignoreAttributesFn(h,s))r+=this.buildAttrPairStr(h,""+t[a],o);else if(!h)if(a===this.options.textNodeName){let e=this.options.tagValueProcessor(a,""+t[a]);n+=this.replaceEntitiesValue(e)}else{i.push(a);const r=this.checkStopNode(i);if(i.pop(),r){const i=""+t[a];n+=""===i?this.indentate(e)+"<"+a+this.closeTag(a)+this.tagEndChar:this.indentate(e)+"<"+a+">"+i+"</"+a+this.tagEndChar}else n+=this.buildTextValNode(t[a],a,"",e,i)}}else if(Array.isArray(t[a])){const r=t[a].length;let s="",o="";for(let h=0;h<r;h++){const r=t[a][h];if(void 0===r);else if(null===r)"?"===a[0]?n+=this.indentate(e)+"<"+a+"?"+this.tagEndChar:n+=this.indentate(e)+"<"+a+"/"+this.tagEndChar;else if("object"==typeof r)if(this.options.oneListGroup){i.push(a);const t=this.j2x(r,e+1,i);i.pop(),s+=t.val,this.options.attributesGroupName&&r.hasOwnProperty(this.options.attributesGroupName)&&(o+=t.attrStr)}else s+=this.processTextOrObjNode(r,a,e,i);else if(this.options.oneListGroup){let t=this.options.tagValueProcessor(a,r);t=this.replaceEntitiesValue(t),s+=t}else{i.push(a);const t=this.checkStopNode(i);if(i.pop(),t){const t=""+r;s+=""===t?this.indentate(e)+"<"+a+this.closeTag(a)+this.tagEndChar:this.indentate(e)+"<"+a+">"+t+"</"+a+this.tagEndChar}else s+=this.buildTextValNode(r,a,"",e,i)}}this.options.oneListGroup&&(s=this.buildObjectNode(s,a,o,e)),n+=s}else if(this.options.attributesGroupName&&a===this.options.attributesGroupName){const e=Object.keys(t[a]),i=e.length;for(let n=0;n<i;n++)r+=this.buildAttrPairStr(e[n],""+t[a][e[n]],o)}else n+=this.processTextOrObjNode(t[a],a,e,i);return{attrStr:r,val:n}},yt.prototype.buildAttrPairStr=function(t,e,i){return i||(e=this.options.attributeValueProcessor(t,""+e),e=this.replaceEntitiesValue(e)),this.options.suppressBooleanAttributes&&"true"===e?" "+t:" "+t+'="'+e+'"'},yt.prototype.extractAttributes=function(t){if(!t||"object"!=typeof t)return null;const e={};let i=!1;if(this.options.attributesGroupName&&t[this.options.attributesGroupName]){const r=t[this.options.attributesGroupName];for(let t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t.startsWith(this.options.attributeNamePrefix)?t.substring(this.options.attributeNamePrefix.length):t]=r[t],i=!0)}else for(let r in t){if(!Object.prototype.hasOwnProperty.call(t,r))continue;const n=this.isAttribute(r);n&&(e[n]=t[r],i=!0)}return i?e:null},yt.prototype.buildRawContent=function(t){if("string"==typeof t)return t;if("object"!=typeof t||null===t)return String(t);if(void 0!==t[this.options.textNodeName])return t[this.options.textNodeName];let e="";for(let i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;if(this.isAttribute(i))continue;if(this.options.attributesGroupName&&i===this.options.attributesGroupName)continue;const r=t[i];if(i===this.options.textNodeName)e+=r;else if(Array.isArray(r)){for(let t of r)if("string"==typeof t||"number"==typeof t)e+=`<${i}>${t}</${i}>`;else if("object"==typeof t&&null!==t){const r=this.buildRawContent(t),n=this.buildAttributesForStopNode(t);e+=""===r?`<${i}${n}/>`:`<${i}${n}>${r}</${i}>`}}else if("object"==typeof r&&null!==r){const t=this.buildRawContent(r),n=this.buildAttributesForStopNode(r);e+=""===t?`<${i}${n}/>`:`<${i}${n}>${t}</${i}>`}else e+=`<${i}>${r}</${i}>`}return e},yt.prototype.buildAttributesForStopNode=function(t){if(!t||"object"!=typeof t)return"";let e="";if(this.options.attributesGroupName&&t[this.options.attributesGroupName]){const i=t[this.options.attributesGroupName];for(let t in i){if(!Object.prototype.hasOwnProperty.call(i,t))continue;const r=t.startsWith(this.options.attributeNamePrefix)?t.substring(this.options.attributeNamePrefix.length):t,n=i[t];!0===n&&this.options.suppressBooleanAttributes?e+=" "+r:e+=" "+r+'="'+n+'"'}}else for(let i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;const r=this.isAttribute(i);if(r){const n=t[i];!0===n&&this.options.suppressBooleanAttributes?e+=" "+r:e+=" "+r+'="'+n+'"'}}return e},yt.prototype.buildObjectNode=function(t,e,i,r){if(""===t)return"?"===e[0]?this.indentate(r)+"<"+e+i+"?"+this.tagEndChar:this.indentate(r)+"<"+e+i+this.closeTag(e)+this.tagEndChar;{let n="</"+e+this.tagEndChar,s="";return"?"===e[0]&&(s="?",n=""),!i&&""!==i||-1!==t.indexOf("<")?!1!==this.options.commentPropName&&e===this.options.commentPropName&&0===s.length?this.indentate(r)+`\x3c!--${t}--\x3e`+this.newLine:this.indentate(r)+"<"+e+i+s+this.tagEndChar+t+this.indentate(r)+n:this.indentate(r)+"<"+e+i+s+">"+t+n}},yt.prototype.closeTag=function(t){let e="";return-1!==this.options.unpairedTags.indexOf(t)?this.options.suppressUnpairedNode||(e="/"):e=this.options.suppressEmptyNode?"/":`></${t}`,e},yt.prototype.checkStopNode=function(t){if(!this.stopNodeExpressions||0===this.stopNodeExpressions.length)return!1;for(let e=0;e<this.stopNodeExpressions.length;e++)if(t.matches(this.stopNodeExpressions[e]))return!0;return!1},yt.prototype.buildTextValNode=function(t,e,i,r,n){if(!1!==this.options.cdataPropName&&e===this.options.cdataPropName)return this.indentate(r)+`<![CDATA[${t}]]>`+this.newLine;if(!1!==this.options.commentPropName&&e===this.options.commentPropName)return this.indentate(r)+`\x3c!--${t}--\x3e`+this.newLine;if("?"===e[0])return this.indentate(r)+"<"+e+i+"?"+this.tagEndChar;{let n=this.options.tagValueProcessor(e,t);return n=this.replaceEntitiesValue(n),""===n?this.indentate(r)+"<"+e+i+this.closeTag(e)+this.tagEndChar:this.indentate(r)+"<"+e+i+">"+n+"</"+e+this.tagEndChar}},yt.prototype.replaceEntitiesValue=function(t){if(t&&t.length>0&&this.options.processEntities)for(let e=0;e<this.options.entities.length;e++){const i=this.options.entities[e];t=t.replace(i.regex,i.val)}return t};const Pt=yt;var At={validate:a};return e})()); | ||
| //# sourceMappingURL=fxp.min.js.map |
@@ -1,2 +0,2 @@ | ||
| !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.XMLParser=e():t.XMLParser=e()}(this,()=>(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},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,{default:()=>et});var r={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,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(t,e,r){return t},captureMetaData:!1,maxNestedTags:100,strictReservedNames:!0};function n(t){return"boolean"==typeof t?{enabled:t,maxEntitySize:1e4,maxExpansionDepth:10,maxTotalExpansions:1e3,maxExpandedLength:1e5,maxEntityCount:100,allowedTags:null,tagFilter:null}:"object"==typeof t&&null!==t?{enabled:!1!==t.enabled,maxEntitySize:null!=(e=t.maxEntitySize)?e:1e4,maxExpansionDepth:null!=(r=t.maxExpansionDepth)?r:10,maxTotalExpansions:null!=(i=t.maxTotalExpansions)?i:1e3,maxExpandedLength:null!=(a=t.maxExpandedLength)?a:1e5,maxEntityCount:null!=(s=t.maxEntityCount)?s:100,allowedTags:null!=(o=t.allowedTags)?o:null,tagFilter:null!=(l=t.tagFilter)?l:null}:n(!0);var e,r,i,a,s,o,l}var i=function(t){var e=Object.assign({},r,t);return e.processEntities=n(e.processEntities),e},a=":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",s=new RegExp("^["+a+"]["+a+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040]*$");function o(t,e){for(var r=[],n=e.exec(t);n;){var i=[];i.startIndex=e.lastIndex-n[0].length;for(var a=n.length,s=0;s<a;s++)i.push(n[s]);r.push(i),n=e.exec(t)}return r}var l,u=function(t){return!(null==s.exec(t))};l="function"!=typeof Symbol?"@@xmlMetadata":Symbol("XML Node Metadata");var d=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,n;"__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(((n={})[t.tagname]=t.child,n)),void 0!==e&&(this.child[this.child.length-1][l]={startIndex:e})},t.getMetaDataSymbol=function(){return l},t}(),f=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),n=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 i=1,a=!1,s=!1;e<t.length;e++)if("<"!==t[e]||s)if(">"===t[e]){if(s?"-"===t[e-1]&&"-"===t[e-2]&&(s=!1,i--):i--,0===i)break}else"["===t[e]?a=!0:t[e];else{if(a&&p(t,"!ENTITY",e)){e+=7;var o=void 0,l=void 0,u=this.readEntityExp(t,e+1,this.suppressValidationErr);if(o=u[0],l=u[1],e=u[2],-1===l.indexOf("&")){if(!1!==this.options.enabled&&this.options.maxEntityCount&&n>=this.options.maxEntityCount)throw new Error("Entity count ("+(n+1)+") exceeds maximum allowed ("+this.options.maxEntityCount+")");var d=o.replace(/[.\-+*:]/g,"\\.");r[o]={regx:RegExp("&"+d+";","g"),val:l},n++}}else if(a&&p(t,"!ELEMENT",e))e+=8,e=this.readElementExp(t,e+1).index;else if(a&&p(t,"!ATTLIST",e))e+=8;else if(a&&p(t,"!NOTATION",e))e+=9,e=this.readNotationExp(t,e+1,this.suppressValidationErr).index;else{if(!p(t,"!--",e))throw new Error("Invalid DOCTYPE");s=!0}i++}if(0!==i)throw new Error("Unclosed DOCTYPE");return{entities:r,i:e}},e.readEntityExp=function(t,e){e=h(t,e);for(var r="";e<t.length&&!/\s/.test(t[e])&&'"'!==t[e]&&"'"!==t[e];)r+=t[e],e++;if(g(r),e=h(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,i=this.readIdentifierVal(t,e,"entity");if(e=i[0],n=i[1],!1!==this.options.enabled&&this.options.maxEntitySize&&n.length>this.options.maxEntitySize)throw new Error('Entity "'+r+'" size ('+n.length+") exceeds maximum allowed size ("+this.options.maxEntitySize+")");return[r,n,--e]},e.readNotationExp=function(t,e){e=h(t,e);for(var r="";e<t.length&&!/\s/.test(t[e]);)r+=t[e],e++;!this.suppressValidationErr&&g(r),e=h(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=h(t,e);var i=null,a=null;if("PUBLIC"===n){var s=this.readIdentifierVal(t,e,"publicIdentifier");if(e=s[0],i=s[1],'"'===t[e=h(t,e)]||"'"===t[e]){var o=this.readIdentifierVal(t,e,"systemIdentifier");e=o[0],a=o[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:r,publicIdentifier:i,systemIdentifier:a,index:--e}},e.readIdentifierVal=function(t,e,r){var n="",i=t[e];if('"'!==i&&"'"!==i)throw new Error('Expected quoted string, found "'+i+'"');for(e++;e<t.length&&t[e]!==i;)n+=t[e],e++;if(t[e]!==i)throw new Error("Unterminated "+r+" value");return[++e,n]},e.readElementExp=function(t,e){e=h(t,e);for(var r="";e<t.length&&!/\s/.test(t[e]);)r+=t[e],e++;if(!this.suppressValidationErr&&!u(r))throw new Error('Invalid element name: "'+r+'"');var n="";if("E"===t[e=h(t,e)]&&p(t,"MPTY",e))e+=4;else if("A"===t[e]&&p(t,"NY",e))e+=2;else if("("===t[e]){for(e++;e<t.length&&")"!==t[e];)n+=t[e],e++;if(")"!==t[e])throw new Error("Unterminated content model")}else if(!this.suppressValidationErr)throw new Error('Invalid Element Expression, found "'+t[e]+'"');return{elementName:r,contentModel:n.trim(),index:e}},e.readAttlistExp=function(t,e){e=h(t,e);for(var r="";e<t.length&&!/\s/.test(t[e]);)r+=t[e],e++;g(r),e=h(t,e);for(var n="";e<t.length&&!/\s/.test(t[e]);)n+=t[e],e++;if(!g(n))throw new Error('Invalid attribute name: "'+n+'"');e=h(t,e);var i="";if("NOTATION"===t.substring(e,e+8).toUpperCase()){if(i="NOTATION","("!==t[e=h(t,e+=8)])throw new Error("Expected '(', found \""+t[e]+'"');e++;for(var a=[];e<t.length&&")"!==t[e];){for(var s="";e<t.length&&"|"!==t[e]&&")"!==t[e];)s+=t[e],e++;if(!g(s=s.trim()))throw new Error('Invalid notation name: "'+s+'"');a.push(s),"|"===t[e]&&(e++,e=h(t,e))}if(")"!==t[e])throw new Error("Unterminated list of notations");e++,i+=" ("+a.join("|")+")"}else{for(;e<t.length&&!/\s/.test(t[e]);)i+=t[e],e++;if(!this.suppressValidationErr&&!["CDATA","ID","IDREF","IDREFS","ENTITY","ENTITIES","NMTOKEN","NMTOKENS"].includes(i.toUpperCase()))throw new Error('Invalid attribute type: "'+i+'"')}e=h(t,e);var o="";if("#REQUIRED"===t.substring(e,e+8).toUpperCase())o="#REQUIRED",e+=8;else if("#IMPLIED"===t.substring(e,e+7).toUpperCase())o="#IMPLIED",e+=7;else{var l=this.readIdentifierVal(t,e,"ATTLIST");e=l[0],o=l[1]}return{elementName:r,attributeName:n,attributeType:i,defaultValue:o,index:e}},t}(),h=function(t,e){for(;e<t.length&&/\s/.test(t[e]);)e++;return e};function p(t,e,r){for(var n=0;n<e.length;n++)if(e[n]!==t[r+n+1])return!1;return!0}function g(t){if(u(t))return t;throw new Error("Invalid entity name "+t)}const c=/^[-+]?0x[a-fA-F0-9]+$/,v=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,m={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};const x=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;function E(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}var b=function(t){var e;if(this.options=t,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:"'"},gt:{regex:/&(gt|#62|#x3E);/g,val:">"},lt:{regex:/&(lt|#60|#x3C);/g,val:"<"},quot:{regex:/&(quot|#34|#x22);/g,val:'"'}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:"&"},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:" "},cent:{regex:/&(cent|#162);/g,val:"¢"},pound:{regex:/&(pound|#163);/g,val:"£"},yen:{regex:/&(yen|#165);/g,val:"¥"},euro:{regex:/&(euro|#8364);/g,val:"€"},copyright:{regex:/&(copy|#169);/g,val:"©"},reg:{regex:/&(reg|#174);/g,val:"®"},inr:{regex:/&(inr|#8377);/g,val:"₹"},num_dec:{regex:/&#([0-9]{1,7});/g,val:function(t,e){return _(e,10,"&#")}},num_hex:{regex:/&#x([0-9a-fA-F]{1,6});/g,val:function(t,e){return _(e,16,"&#x")}}},this.addExternalEntities=N,this.parseXml=O,this.parseTextData=y,this.resolveNameSpace=T,this.buildAttributesMap=I,this.isItStopNode=P,this.replaceEntitiesValue=A,this.readStopNodeData=F,this.saveTextToParentTag=C,this.addChild=S,this.ignoreAttributesFn="function"==typeof(e=this.options.ignoreAttributes)?e:Array.isArray(e)?function(t){for(var r,n=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 E(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)?E(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}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=n()).done;){var i=r.value;if("string"==typeof i&&t===i)return!0;if(i instanceof RegExp&&i.test(t))return!0}}:function(){return!1},this.entityExpansionCount=0,this.currentExpandedLength=0,this.options.stopNodes&&this.options.stopNodes.length>0){this.stopNodesExact=new Set,this.stopNodesWildcard=new Set;for(var r=0;r<this.options.stopNodes.length;r++){var n=this.options.stopNodes[r];"string"==typeof n&&(n.startsWith("*.")?this.stopNodesWildcard.add(n.substring(2)):this.stopNodesExact.add(n))}}};function N(t){for(var e=Object.keys(t),r=0;r<e.length;r++){var n=e[r],i=n.replace(/[.\-+*:]/g,"\\.");this.lastEntities[n]={regex:new RegExp("&"+i+";","g"),val:t[n]}}}function y(t,e,r,n,i,a,s){if(void 0!==t&&(this.options.trimValues&&!n&&(t=t.trim()),t.length>0)){s||(t=this.replaceEntitiesValue(t,e,r));var o=this.options.tagValueProcessor(e,t,r,i,a);return null==o?t:typeof o!=typeof t||o!==t?o:this.options.trimValues||t.trim()===t?V(t,this.options.parseTagValue,this.options.numberParseOptions):t}}function T(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 w=new RegExp("([^\\s=]+)\\s*(=\\s*(['\"])([\\s\\S]*?)\\3)?","gm");function I(t,e,r){if(!0!==this.options.ignoreAttributes&&"string"==typeof t){for(var n=o(t,w),i=n.length,a={},s=0;s<i;s++){var l=this.resolveNameSpace(n[s][1]);if(!this.ignoreAttributesFn(l,e)){var u=n[s][4],d=this.options.attributeNamePrefix+l;if(l.length)if(this.options.transformAttributeName&&(d=this.options.transformAttributeName(d)),"__proto__"===d&&(d="#__proto__"),void 0!==u){this.options.trimValues&&(u=u.trim()),u=this.replaceEntitiesValue(u,r,e);var f=this.options.attributeValueProcessor(l,u,e);a[d]=null==f?u:typeof f!=typeof u||f!==u?f:V(u,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(a[d]=!0)}}if(!Object.keys(a).length)return;if(this.options.attributesGroupName){var h={};return h[this.options.attributesGroupName]=a,h}return a}}var O=function(t){t=t.replace(/\r\n?/g,"\n");var e=new d("!xml"),r=e,n="",i="";this.entityExpansionCount=0,this.currentExpandedLength=0;for(var a=new f(this.options.processEntities),s=0;s<t.length;s++)if("<"===t[s])if("/"===t[s+1]){var o=D(t,">",s,"Closing Tag is not closed."),l=t.substring(s+2,o).trim();if(this.options.removeNSPrefix){var u=l.indexOf(":");-1!==u&&(l=l.substr(u+1))}this.options.transformTagName&&(l=this.options.transformTagName(l)),r&&(n=this.saveTextToParentTag(n,r,i));var h=i.substring(i.lastIndexOf(".")+1);if(l&&-1!==this.options.unpairedTags.indexOf(l))throw new Error("Unpaired tag can not be used as closing tag: </"+l+">");var p=0;h&&-1!==this.options.unpairedTags.indexOf(h)?(p=i.lastIndexOf(".",i.lastIndexOf(".")-1),this.tagsNodeStack.pop()):p=i.lastIndexOf("."),i=i.substring(0,p),r=this.tagsNodeStack.pop(),n="",s=o}else if("?"===t[s+1]){var g=M(t,s,!1,"?>");if(!g)throw new Error("Pi Tag is not closed.");if(n=this.saveTextToParentTag(n,r,i),this.options.ignoreDeclaration&&"?xml"===g.tagName||this.options.ignorePiTags);else{var c=new d(g.tagName);c.add(this.options.textNodeName,""),g.tagName!==g.tagExp&&g.attrExpPresent&&(c[":@"]=this.buildAttributesMap(g.tagExp,i,g.tagName)),this.addChild(r,c,i,s)}s=g.closeIndex+1}else if("!--"===t.substr(s+1,3)){var v=D(t,"--\x3e",s+4,"Comment is not closed.");if(this.options.commentPropName){var m,x=t.substring(s+4,v-2);n=this.saveTextToParentTag(n,r,i),r.add(this.options.commentPropName,[(m={},m[this.options.textNodeName]=x,m)])}s=v}else if("!D"===t.substr(s+1,2)){var E=a.readDocType(t,s);this.docTypeEntities=E.entities,s=E.i}else if("!["===t.substr(s+1,2)){var b=D(t,"]]>",s,"CDATA is not closed.")-2,N=t.substring(s+9,b);n=this.saveTextToParentTag(n,r,i);var y,T=this.parseTextData(N,r.tagname,i,!0,!1,!0,!0);null==T&&(T=""),this.options.cdataPropName?r.add(this.options.cdataPropName,[(y={},y[this.options.textNodeName]=N,y)]):r.add(this.options.textNodeName,T),s=b+2}else{var w=M(t,s,this.options.removeNSPrefix),I=w.tagName,O=w.rawTagName,S=w.tagExp,A=w.attrExpPresent,C=w.closeIndex;if(this.options.transformTagName){var P=this.options.transformTagName(I);S===I&&(S=P),I=P}if(this.options.strictReservedNames&&(I===this.options.commentPropName||I===this.options.cdataPropName))throw new Error("Invalid tag name: "+I);r&&n&&"!xml"!==r.tagname&&(n=this.saveTextToParentTag(n,r,i,!1));var F=r;F&&-1!==this.options.unpairedTags.indexOf(F.tagname)&&(r=this.tagsNodeStack.pop(),i=i.substring(0,i.lastIndexOf("."))),I!==e.tagname&&(i+=i?"."+I:I);var V=s;if(this.isItStopNode(this.stopNodesExact,this.stopNodesWildcard,i,I)){var _="";if(S.length>0&&S.lastIndexOf("/")===S.length-1)"/"===I[I.length-1]?(I=I.substr(0,I.length-1),i=i.substr(0,i.length-1),S=I):S=S.substr(0,S.length-1),s=w.closeIndex;else if(-1!==this.options.unpairedTags.indexOf(I))s=w.closeIndex;else{var j=this.readStopNodeData(t,O,C+1);if(!j)throw new Error("Unexpected end of "+O);s=j.i,_=j.tagContent}var k=new d(I);I!==S&&A&&(k[":@"]=this.buildAttributesMap(S,i,I)),_&&(_=this.parseTextData(_,I,i,!0,A,!0,!0)),i=i.substr(0,i.lastIndexOf(".")),k.add(this.options.textNodeName,_),this.addChild(r,k,i,V)}else{if(S.length>0&&S.lastIndexOf("/")===S.length-1){if("/"===I[I.length-1]?(I=I.substr(0,I.length-1),i=i.substr(0,i.length-1),S=I):S=S.substr(0,S.length-1),this.options.transformTagName){var L=this.options.transformTagName(I);S===I&&(S=L),I=L}var U=new d(I);I!==S&&A&&(U[":@"]=this.buildAttributesMap(S,i,I)),this.addChild(r,U,i,V),i=i.substr(0,i.lastIndexOf("."))}else{if(-1!==this.options.unpairedTags.indexOf(I)){var R=new d(I);I!==S&&A&&(R[":@"]=this.buildAttributesMap(S,i)),this.addChild(r,R,i,V),i=i.substr(0,i.lastIndexOf(".")),s=w.closeIndex;continue}var Y=new d(I);if(this.tagsNodeStack.length>this.options.maxNestedTags)throw new Error("Maximum nested tags exceeded");this.tagsNodeStack.push(r),I!==S&&A&&(Y[":@"]=this.buildAttributesMap(S,i,I)),this.addChild(r,Y,i,V),r=Y}n="",s=C}}else n+=t[s];return e.child};function S(t,e,r,n){this.options.captureMetaData||(n=void 0);var i=this.options.updateTag(e.tagname,r,e[":@"]);!1===i||("string"==typeof i?(e.tagname=i,t.addChild(e,n)):t.addChild(e,n))}var A=function(t,e,r){if(-1===t.indexOf("&"))return t;var n=this.options.processEntities;if(!n.enabled)return t;if(n.allowedTags&&!n.allowedTags.includes(e))return t;if(n.tagFilter&&!n.tagFilter(e,r))return t;for(var i in this.docTypeEntities){var a=this.docTypeEntities[i],s=t.match(a.regx);if(s){if(this.entityExpansionCount+=s.length,n.maxTotalExpansions&&this.entityExpansionCount>n.maxTotalExpansions)throw new Error("Entity expansion limit exceeded: "+this.entityExpansionCount+" > "+n.maxTotalExpansions);var o=t.length;if(t=t.replace(a.regx,a.val),n.maxExpandedLength&&(this.currentExpandedLength+=t.length-o,this.currentExpandedLength>n.maxExpandedLength))throw new Error("Total expanded content size exceeded: "+this.currentExpandedLength+" > "+n.maxExpandedLength)}}if(-1===t.indexOf("&"))return t;for(var l in this.lastEntities){var u=this.lastEntities[l];t=t.replace(u.regex,u.val)}if(-1===t.indexOf("&"))return t;if(this.options.htmlEntities)for(var d in this.htmlEntities){var f=this.htmlEntities[d];t=t.replace(f.regex,f.val)}return t.replace(this.ampEntity.regex,this.ampEntity.val)};function C(t,e,r,n){return t&&(void 0===n&&(n=0===e.child.length),void 0!==(t=this.parseTextData(t,e.tagname,r,!1,!!e[":@"]&&0!==Object.keys(e[":@"]).length,n))&&""!==t&&e.add(this.options.textNodeName,t),t=""),t}function P(t,e,r,n){return!(!e||!e.has(n))||!(!t||!t.has(r))}function D(t,e,r,n){var i=t.indexOf(e,r);if(-1===i)throw new Error(n);return i+e.length-1}function M(t,e,r,n){void 0===n&&(n=">");var i=function(t,e,r){var n;void 0===r&&(r=">");for(var i="",a=e;a<t.length;a++){var s=t[a];if(n)s===n&&(n="");else if('"'===s||"'"===s)n=s;else if(s===r[0]){if(!r[1])return{data:i,index:a};if(t[a+1]===r[1])return{data:i,index:a}}else"\t"===s&&(s=" ");i+=s}}(t,e+1,n);if(i){var a=i.data,s=i.index,o=a.search(/\s/),l=a,u=!0;-1!==o&&(l=a.substring(0,o),a=a.substring(o+1).trimStart());var d=l;if(r){var f=l.indexOf(":");-1!==f&&(u=(l=l.substr(f+1))!==i.data.substr(f+1))}return{tagName:l,tagExp:a,closeIndex:s,attrExpPresent:u,rawTagName:d}}}function F(t,e,r){for(var n=r,i=1;r<t.length;r++)if("<"===t[r])if("/"===t[r+1]){var a=D(t,">",r,e+" is not closed");if(t.substring(r+2,a).trim()===e&&0===--i)return{tagContent:t.substring(n,r),i:a};r=a}else if("?"===t[r+1])r=D(t,"?>",r+1,"StopNode is not closed.");else if("!--"===t.substr(r+1,3))r=D(t,"--\x3e",r+3,"StopNode is not closed.");else if("!["===t.substr(r+1,2))r=D(t,"]]>",r,"StopNode is not closed.")-2;else{var s=M(t,r,">");s&&((s&&s.tagName)===e&&"/"!==s.tagExp[s.tagExp.length-1]&&i++,r=s.closeIndex)}}function V(t,e,r){if(e&&"string"==typeof t){var n=t.trim();return"true"===n||"false"!==n&&function(t,e={}){if(e=Object.assign({},m,e),!t||"string"!=typeof t)return t;let r=t.trim();if(void 0!==e.skipLike&&e.skipLike.test(r))return t;if("0"===t)return 0;if(e.hex&&c.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(r.includes("e")||r.includes("E"))return function(t,e,r){if(!r.eNotation)return t;const n=e.match(x);if(n){let i=n[1]||"";const a=-1===n[3].indexOf("e")?"E":"e",s=n[2],o=i?t[s.length+1]===a:t[s.length]===a;return s.length>1&&o?t:1!==s.length||!n[3].startsWith(`.${a}`)&&n[3][0]!==a?r.leadingZeros&&!o?(e=(n[1]||"")+n[3],Number(e)):t:Number(e)}return t}(t,r,e);{const i=v.exec(r);if(i){const a=i[1]||"",s=i[2];let o=(n=i[3])&&-1!==n.indexOf(".")?("."===(n=n.replace(/0+$/,""))?n="0":"."===n[0]?n="0"+n:"."===n[n.length-1]&&(n=n.substring(0,n.length-1)),n):n;const l=a?"."===t[s.length+1]:"."===t[s.length];if(!e.leadingZeros&&(s.length>1||1===s.length&&!l))return t;{const n=Number(r),i=String(n);if(0===n)return n;if(-1!==i.search(/[eE]/))return e.eNotation?n:t;if(-1!==r.indexOf("."))return"0"===i||i===o||i===`${a}${o}`?n:t;let l=s?o:r;return s?l===i||a+l===i?n:t:l===i||l===a+i?n:t}}return t}var n}(t,r)}return void 0!==t?t:""}function _(t,e,r){var n=Number.parseInt(t,e);return n>=0&&n<=1114111?String.fromCodePoint(n):r+t+";"}var j=d.getMetaDataSymbol();function k(t,e){return L(t,e)}function L(t,e,r){for(var n,i={},a=0;a<t.length;a++){var s,o=t[a],l=U(o);if(s=void 0===r?l:r+"."+l,l===e.textNodeName)void 0===n?n=o[l]:n+=""+o[l];else{if(void 0===l)continue;if(o[l]){var u=L(o[l],e,s),d=Y(u,e);o[":@"]?R(u,o[":@"],s,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[j]&&"object"==typeof u&&null!==u&&(u[j]=o[j]),void 0!==i[l]&&Object.prototype.hasOwnProperty.call(i,l)?(Array.isArray(i[l])||(i[l]=[i[l]]),i[l].push(u)):e.isArray(l,s,d)?i[l]=[u]:i[l]=u}}}return"string"==typeof n?n.length>0&&(i[e.textNodeName]=n):void 0!==n&&(i[e.textNodeName]=n),i}function U(t){for(var e=Object.keys(t),r=0;r<e.length;r++){var n=e[r];if(":@"!==n)return n}}function R(t,e,r,n){if(e)for(var i=Object.keys(e),a=i.length,s=0;s<a;s++){var o=i[s];n.isArray(o,r+"."+o,!0,!0)?t[o]=[e[o]]:t[o]=e[o]}}function Y(t,e){var r=e.textNodeName,n=Object.keys(t).length;return 0===n||!(1!==n||!t[r]&&"boolean"!=typeof t[r]&&0!==t[r])}var X={allowBooleanAttributes:!1,unpairedTags:[]};function z(t){return" "===t||"\t"===t||"\n"===t||"\r"===t}function B(t,e){for(var r=e;e<t.length;e++)if("?"!=t[e]&&" "!=t[e]);else{var n=t.substr(r,e-r);if(e>5&&"xml"===n)return K("InvalidXml","XML declaration allowed only at the start of the document.",H(t,e));if("?"==t[e]&&">"==t[e+1]){e++;break}}return e}function $(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}function W(t,e){for(var r="",n="",i=!1;e<t.length;e++){if('"'===t[e]||"'"===t[e])""===n?n=t[e]:n!==t[e]||(n="");else if(">"===t[e]&&""===n){i=!0;break}r+=t[e]}return""===n&&{value:r,index:e,tagClosed:i}}var Z=new RegExp("(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['\"])(([\\s\\S])*?)\\5)?","g");function q(t,e){for(var r=o(t,Z),n={},i=0;i<r.length;i++){if(0===r[i][1].length)return K("InvalidAttr","Attribute '"+r[i][2]+"' has no space in starting.",tt(r[i]));if(void 0!==r[i][3]&&void 0===r[i][4])return K("InvalidAttr","Attribute '"+r[i][2]+"' is without value.",tt(r[i]));if(void 0===r[i][3]&&!e.allowBooleanAttributes)return K("InvalidAttr","boolean attribute '"+r[i][2]+"' is not allowed.",tt(r[i]));var a=r[i][2];if(!Q(a))return K("InvalidAttr","Attribute '"+a+"' is an invalid name.",tt(r[i]));if(Object.prototype.hasOwnProperty.call(n,a))return K("InvalidAttr","Attribute '"+a+"' is repeated.",tt(r[i]));n[a]=1}return!0}function G(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 K(t,e,r){return{err:{code:t,msg:e,line:r.line||r,col:r.col}}}function Q(t){return u(t)}function J(t){return u(t)}function H(t,e){var r=t.substring(0,e).split(/\r?\n/);return{line:r.length,col:r[r.length-1].length+1}}function tt(t){return t.startIndex+t[1].length}var et=function(){function t(t){this.externalEntities={},this.options=i(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=function(t,e){e=Object.assign({},X,e);var r=[],n=!1,i=!1;"\ufeff"===t[0]&&(t=t.substr(1));for(var a=0;a<t.length;a++)if("<"===t[a]&&"?"===t[a+1]){if((a=B(t,a+=2)).err)return a}else{if("<"!==t[a]){if(z(t[a]))continue;return K("InvalidChar","char '"+t[a]+"' is not expected.",H(t,a))}var s=a;if("!"===t[++a]){a=$(t,a);continue}var o=!1;"/"===t[a]&&(o=!0,a++);for(var l="";a<t.length&&">"!==t[a]&&" "!==t[a]&&"\t"!==t[a]&&"\n"!==t[a]&&"\r"!==t[a];a++)l+=t[a];if("/"===(l=l.trim())[l.length-1]&&(l=l.substring(0,l.length-1),a--),!J(l))return K("InvalidTag",0===l.trim().length?"Invalid space after '<'.":"Tag '"+l+"' is an invalid name.",H(t,a));var u=W(t,a);if(!1===u)return K("InvalidAttr","Attributes for '"+l+"' have open quote.",H(t,a));var d=u.value;if(a=u.index,"/"===d[d.length-1]){var f=a-d.length,h=q(d=d.substring(0,d.length-1),e);if(!0!==h)return K(h.err.code,h.err.msg,H(t,f+h.err.line));n=!0}else if(o){if(!u.tagClosed)return K("InvalidTag","Closing tag '"+l+"' doesn't have proper closing.",H(t,a));if(d.trim().length>0)return K("InvalidTag","Closing tag '"+l+"' can't have attributes or invalid starting.",H(t,s));if(0===r.length)return K("InvalidTag","Closing tag '"+l+"' has not been opened.",H(t,s));var p=r.pop();if(l!==p.tagName){var g=H(t,p.tagStartPos);return K("InvalidTag","Expected closing tag '"+p.tagName+"' (opened in line "+g.line+", col "+g.col+") instead of closing tag '"+l+"'.",H(t,s))}0==r.length&&(i=!0)}else{var c=q(d,e);if(!0!==c)return K(c.err.code,c.err.msg,H(t,a-d.length+c.err.line));if(!0===i)return K("InvalidXml","Multiple possible root nodes found.",H(t,a));-1!==e.unpairedTags.indexOf(l)||r.push({tagName:l,tagStartPos:s}),n=!0}for(a++;a<t.length;a++)if("<"===t[a]){if("!"===t[a+1]){a=$(t,++a);continue}if("?"!==t[a+1])break;if((a=B(t,++a)).err)return a}else if("&"===t[a]){var v=G(t,a);if(-1==v)return K("InvalidChar","char '&' is not expected.",H(t,a));a=v}else if(!0===i&&!z(t[a]))return K("InvalidXml","Extra text at the end",H(t,a));"<"===t[a]&&a--}return n?1==r.length?K("InvalidTag","Unclosed tag '"+r[0].tagName+"'.",H(t,r[0].tagStartPos)):!(r.length>0)||K("InvalidXml","Invalid '"+JSON.stringify(r.map(function(t){return t.tagName}),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1}):K("InvalidXml","Start tag expected.",1)}(t,e);if(!0!==r)throw Error(r.err.msg+":"+r.err.line+":"+r.err.col)}var n=new b(this.options);n.addExternalEntities(this.externalEntities);var i=n.parseXml(t);return this.options.preserveOrder||void 0===i?i:k(i,this.options)},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 '
'");if("&"===e)throw new Error("An entity with value '&' is not permitted");this.externalEntities[t]=e},t.getMetaDataSymbol=function(){return d.getMetaDataSymbol()},t}();return e})()); | ||
| !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.XMLParser=e():t.XMLParser=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,{default:()=>st});var r={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,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(t,e,r){return t},captureMetaData:!1,maxNestedTags:100,strictReservedNames:!0,jPath:!0};function i(t){return"boolean"==typeof t?{enabled:t,maxEntitySize:1e4,maxExpansionDepth:10,maxTotalExpansions:1e3,maxExpandedLength:1e5,maxEntityCount:100,allowedTags:null,tagFilter:null}:"object"==typeof t&&null!==t?{enabled:!1!==t.enabled,maxEntitySize:null!=(e=t.maxEntitySize)?e:1e4,maxExpansionDepth:null!=(r=t.maxExpansionDepth)?r:10,maxTotalExpansions:null!=(n=t.maxTotalExpansions)?n:1e3,maxExpandedLength:null!=(a=t.maxExpandedLength)?a:1e5,maxEntityCount:null!=(s=t.maxEntityCount)?s:100,allowedTags:null!=(o=t.allowedTags)?o:null,tagFilter:null!=(h=t.tagFilter)?h:null}:i(!0);var e,r,n,a,s,o,h}var n=function(t){var e=Object.assign({},r,t);return e.processEntities=i(e.processEntities),e.stopNodes&&Array.isArray(e.stopNodes)&&(e.stopNodes=e.stopNodes.map(function(t){return"string"==typeof t&&t.startsWith("*.")?".."+t.substring(2):t})),e},a=":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",s=new RegExp("^["+a+"]["+a+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040]*$");function o(t,e){for(var r=[],i=e.exec(t);i;){var n=[];n.startIndex=e.lastIndex-i[0].length;for(var a=i.length,s=0;s<a;s++)n.push(i[s]);r.push(n),i=e.exec(t)}return r}var h,l=function(t){return!(null==s.exec(t))};h="function"!=typeof Symbol?"@@xmlMetadata":Symbol("XML Node Metadata");var u=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][h]={startIndex:e})},t.getMetaDataSymbol=function(){return h},t}(),p=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,a=!1,s=!1;e<t.length;e++)if("<"!==t[e]||s)if(">"===t[e]){if(s?"-"===t[e-1]&&"-"===t[e-2]&&(s=!1,n--):n--,0===n)break}else"["===t[e]?a=!0:t[e];else{if(a&&f(t,"!ENTITY",e)){e+=7;var o=void 0,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&&this.options.maxEntityCount&&i>=this.options.maxEntityCount)throw new Error("Entity count ("+(i+1)+") exceeds maximum allowed ("+this.options.maxEntityCount+")");var u=o.replace(/[.\-+*:]/g,"\\.");r[o]={regx:RegExp("&"+u+";","g"),val:h},i++}}else if(a&&f(t,"!ELEMENT",e))e+=8,e=this.readElementExp(t,e+1).index;else if(a&&f(t,"!ATTLIST",e))e+=8;else if(a&&f(t,"!NOTATION",e))e+=9,e=this.readNotationExp(t,e+1,this.suppressValidationErr).index;else{if(!f(t,"!--",e))throw new Error("Invalid DOCTYPE");s=!0}n++}if(0!==n)throw new Error("Unclosed DOCTYPE");return{entities:r,i:e}},e.readEntityExp=function(t,e){e=d(t,e);for(var r="";e<t.length&&!/\s/.test(t[e])&&'"'!==t[e]&&"'"!==t[e];)r+=t[e],e++;if(g(r),e=d(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 i,n=this.readIdentifierVal(t,e,"entity");if(e=n[0],i=n[1],!1!==this.options.enabled&&this.options.maxEntitySize&&i.length>this.options.maxEntitySize)throw new Error('Entity "'+r+'" size ('+i.length+") exceeds maximum allowed size ("+this.options.maxEntitySize+")");return[r,i,--e]},e.readNotationExp=function(t,e){e=d(t,e);for(var r="";e<t.length&&!/\s/.test(t[e]);)r+=t[e],e++;!this.suppressValidationErr&&g(r),e=d(t,e);var i=t.substring(e,e+6).toUpperCase();if(!this.suppressValidationErr&&"SYSTEM"!==i&&"PUBLIC"!==i)throw new Error('Expected SYSTEM or PUBLIC, found "'+i+'"');e+=i.length,e=d(t,e);var n=null,a=null;if("PUBLIC"===i){var s=this.readIdentifierVal(t,e,"publicIdentifier");if(e=s[0],n=s[1],'"'===t[e=d(t,e)]||"'"===t[e]){var o=this.readIdentifierVal(t,e,"systemIdentifier");e=o[0],a=o[1]}}else if("SYSTEM"===i){var h=this.readIdentifierVal(t,e,"systemIdentifier");if(e=h[0],a=h[1],!this.suppressValidationErr&&!a)throw new Error("Missing mandatory system identifier for SYSTEM notation")}return{notationName:r,publicIdentifier:n,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(e++;e<t.length&&t[e]!==n;)i+=t[e],e++;if(t[e]!==n)throw new Error("Unterminated "+r+" value");return[++e,i]},e.readElementExp=function(t,e){e=d(t,e);for(var r="";e<t.length&&!/\s/.test(t[e]);)r+=t[e],e++;if(!this.suppressValidationErr&&!l(r))throw new Error('Invalid element name: "'+r+'"');var i="";if("E"===t[e=d(t,e)]&&f(t,"MPTY",e))e+=4;else if("A"===t[e]&&f(t,"NY",e))e+=2;else if("("===t[e]){for(e++;e<t.length&&")"!==t[e];)i+=t[e],e++;if(")"!==t[e])throw new Error("Unterminated content model")}else if(!this.suppressValidationErr)throw new Error('Invalid Element Expression, found "'+t[e]+'"');return{elementName:r,contentModel:i.trim(),index:e}},e.readAttlistExp=function(t,e){e=d(t,e);for(var r="";e<t.length&&!/\s/.test(t[e]);)r+=t[e],e++;g(r),e=d(t,e);for(var i="";e<t.length&&!/\s/.test(t[e]);)i+=t[e],e++;if(!g(i))throw new Error('Invalid attribute name: "'+i+'"');e=d(t,e);var n="";if("NOTATION"===t.substring(e,e+8).toUpperCase()){if(n="NOTATION","("!==t[e=d(t,e+=8)])throw new Error("Expected '(', found \""+t[e]+'"');e++;for(var a=[];e<t.length&&")"!==t[e];){for(var s="";e<t.length&&"|"!==t[e]&&")"!==t[e];)s+=t[e],e++;if(!g(s=s.trim()))throw new Error('Invalid notation name: "'+s+'"');a.push(s),"|"===t[e]&&(e++,e=d(t,e))}if(")"!==t[e])throw new Error("Unterminated list of notations");e++,n+=" ("+a.join("|")+")"}else{for(;e<t.length&&!/\s/.test(t[e]);)n+=t[e],e++;if(!this.suppressValidationErr&&!["CDATA","ID","IDREF","IDREFS","ENTITY","ENTITIES","NMTOKEN","NMTOKENS"].includes(n.toUpperCase()))throw new Error('Invalid attribute type: "'+n+'"')}e=d(t,e);var o="";if("#REQUIRED"===t.substring(e,e+8).toUpperCase())o="#REQUIRED",e+=8;else if("#IMPLIED"===t.substring(e,e+7).toUpperCase())o="#IMPLIED",e+=7;else{var h=this.readIdentifierVal(t,e,"ATTLIST");e=h[0],o=h[1]}return{elementName:r,attributeName:i,attributeType:n,defaultValue:o,index:e}},t}(),d=function(t,e){for(;e<t.length&&/\s/.test(t[e]);)e++;return e};function f(t,e,r){for(var i=0;i<e.length;i++)if(e[i]!==t[r+i+1])return!1;return!0}function g(t){if(l(t))return t;throw new Error("Invalid entity name "+t)}const c=/^[-+]?0x[a-fA-F0-9]+$/,m=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,v={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};const x=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;function E(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 b{constructor(t,e={}){this.pattern=t,this.separator=e.separator||".",this.segments=this._parse(t),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 a,s,o=i;if(i.includes("::")){const e=i.indexOf("::");if(a=i.substring(0,e).trim(),o=i.substring(e+2).trim(),!a)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)?(s=e,h=r):s=o}else s=o;if(!s)throw new Error(`Invalid segment pattern: ${t}`);if(e.tag=s,a&&(e.namespace=a),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 N{constructor(t={}){this.separator=t.separator||".",this.path=[],this.siblingStacks=[]}push(t,e=null,r=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],a=r?`${r}:${t}`:t,s=n.get(a)||0;let o=0;for(const t of n.values())o+=t;n.set(a,s+1);const h={tag:t,position:o,counter:s};null!=r&&(h.namespace=r),null!=e&&(h.values=e),this.path.push(h)}pop(){if(0===this.path.length)return;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;const e=this.path[this.path.length-1];return e.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;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.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++){const r=t[e],i=this.path[e],n=e===this.path.length-1;if(!this._matchSegment(r,i,n))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--){const a=t===this.path.length-1;if(this._matchSegment(i,this.path[t],a)){e=t-1,r--,n=!0;break}}if(!n)return!1}else{const t=e===this.path.length-1;if(!this._matchSegment(i,this.path[e],t))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){const r=e.values[t.attrName];if(String(r)!==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}snapshot(){return{path:this.path.map(t=>({...t})),siblingStacks:this.siblingStacks.map(t=>new Map(t))}}restore(t){this.path=t.path.map(t=>({...t})),this.siblingStacks=t.siblingStacks.map(t=>new Map(t))}}function y(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 w(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 T=function(t){var e;if(this.options=t,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:"'"},gt:{regex:/&(gt|#62|#x3E);/g,val:">"},lt:{regex:/&(lt|#60|#x3C);/g,val:"<"},quot:{regex:/&(quot|#34|#x22);/g,val:'"'}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:"&"},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:" "},cent:{regex:/&(cent|#162);/g,val:"¢"},pound:{regex:/&(pound|#163);/g,val:"£"},yen:{regex:/&(yen|#165);/g,val:"¥"},euro:{regex:/&(euro|#8364);/g,val:"€"},copyright:{regex:/&(copy|#169);/g,val:"©"},reg:{regex:/&(reg|#174);/g,val:"®"},inr:{regex:/&(inr|#8377);/g,val:"₹"},num_dec:{regex:/&#([0-9]{1,7});/g,val:function(t,e){return U(e,10,"&#")}},num_hex:{regex:/&#x([0-9a-fA-F]{1,6});/g,val:function(t,e){return U(e,16,"&#x")}}},this.addExternalEntities=S,this.parseXml=O,this.parseTextData=I,this.resolveNameSpace=P,this.buildAttributesMap=A,this.isItStopNode=k,this.replaceEntitiesValue=_,this.readStopNodeData=F,this.saveTextToParentTag=j,this.addChild=D,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 E(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)?E(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,this.matcher=new N,this.isCurrentNodeStopNode=!1,this.options.stopNodes&&this.options.stopNodes.length>0){this.stopNodeExpressions=[];for(var r=0;r<this.options.stopNodes.length;r++){var i=this.options.stopNodes[r];"string"==typeof i?this.stopNodeExpressions.push(new b(i)):i instanceof b&&this.stopNodeExpressions.push(i)}}};function S(t){for(var e=Object.keys(t),r=0;r<e.length;r++){var i=e[r],n=i.replace(/[.\-+*:]/g,"\\.");this.lastEntities[i]={regex:new RegExp("&"+n+";","g"),val:t[i]}}}function I(t,e,r,i,n,a,s){if(void 0!==t&&(this.options.trimValues&&!i&&(t=t.trim()),t.length>0)){s||(t=this.replaceEntitiesValue(t,e,r));var o=this.options.jPath?r.toString():r,h=this.options.tagValueProcessor(e,t,o,n,a);return null==h?t:typeof h!=typeof t||h!==t?h:this.options.trimValues||t.trim()===t?L(t,this.options.parseTagValue,this.options.numberParseOptions):t}}function P(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 C=new RegExp("([^\\s=]+)\\s*(=\\s*(['\"])([\\s\\S]*?)\\3)?","gm");function A(t,e,r){if(!0!==this.options.ignoreAttributes&&"string"==typeof t){for(var i=o(t,C),n=i.length,a={},s={},h=0;h<n;h++){var l=this.resolveNameSpace(i[h][1]),u=i[h][4];if(l.length&&void 0!==u){var p=u;this.options.trimValues&&(p=p.trim()),p=this.replaceEntitiesValue(p,r,e),s[l]=p}}Object.keys(s).length>0&&"object"==typeof e&&e.updateCurrent&&e.updateCurrent(s);for(var d=0;d<n;d++){var f=this.resolveNameSpace(i[d][1]),g=this.options.jPath?e.toString():e;if(!this.ignoreAttributesFn(f,g)){var c=i[d][4],m=this.options.attributeNamePrefix+f;if(f.length)if(this.options.transformAttributeName&&(m=this.options.transformAttributeName(m)),"__proto__"===m&&(m="#__proto__"),void 0!==c){this.options.trimValues&&(c=c.trim()),c=this.replaceEntitiesValue(c,r,e);var v=this.options.jPath?e.toString():e,x=this.options.attributeValueProcessor(f,c,v);a[m]=null==x?c:typeof x!=typeof c||x!==c?x:L(c,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(a[m]=!0)}}if(!Object.keys(a).length)return;if(this.options.attributesGroupName){var E={};return E[this.options.attributesGroupName]=a,E}return a}}var O=function(t){t=t.replace(/\r\n?/g,"\n");var e=new u("!xml"),r=e,i="";this.matcher.reset(),this.entityExpansionCount=0,this.currentExpandedLength=0;for(var n=new p(this.options.processEntities),a=0;a<t.length;a++)if("<"===t[a])if("/"===t[a+1]){var s=V(t,">",a,"Closing Tag is not closed."),o=t.substring(a+2,s).trim();if(this.options.removeNSPrefix){var h=o.indexOf(":");-1!==h&&(o=o.substr(h+1))}this.options.transformTagName&&(o=this.options.transformTagName(o)),r&&(i=this.saveTextToParentTag(i,r,this.matcher));var l=this.matcher.getCurrentTag();if(o&&-1!==this.options.unpairedTags.indexOf(o))throw new Error("Unpaired tag can not be used as closing tag: </"+o+">");l&&-1!==this.options.unpairedTags.indexOf(l)&&(this.matcher.pop(),this.tagsNodeStack.pop()),this.matcher.pop(),this.isCurrentNodeStopNode=!1,r=this.tagsNodeStack.pop(),i="",a=s}else if("?"===t[a+1]){var d=M(t,a,!1,"?>");if(!d)throw new Error("Pi Tag is not closed.");if(i=this.saveTextToParentTag(i,r,this.matcher),this.options.ignoreDeclaration&&"?xml"===d.tagName||this.options.ignorePiTags);else{var f=new u(d.tagName);f.add(this.options.textNodeName,""),d.tagName!==d.tagExp&&d.attrExpPresent&&(f[":@"]=this.buildAttributesMap(d.tagExp,this.matcher,d.tagName)),this.addChild(r,f,this.matcher,a)}a=d.closeIndex+1}else if("!--"===t.substr(a+1,3)){var g=V(t,"--\x3e",a+4,"Comment is not closed.");if(this.options.commentPropName){var c,m=t.substring(a+4,g-2);i=this.saveTextToParentTag(i,r,this.matcher),r.add(this.options.commentPropName,[(c={},c[this.options.textNodeName]=m,c)])}a=g}else if("!D"===t.substr(a+1,2)){var v=n.readDocType(t,a);this.docTypeEntities=v.entities,a=v.i}else if("!["===t.substr(a+1,2)){var x=V(t,"]]>",a,"CDATA is not closed.")-2,E=t.substring(a+9,x);i=this.saveTextToParentTag(i,r,this.matcher);var b,N=this.parseTextData(E,r.tagname,this.matcher,!0,!1,!0,!0);null==N&&(N=""),this.options.cdataPropName?r.add(this.options.cdataPropName,[(b={},b[this.options.textNodeName]=E,b)]):r.add(this.options.textNodeName,N),a=x+2}else{var T=M(t,a,this.options.removeNSPrefix);if(!T){var S=t.substring(Math.max(0,a-50),Math.min(t.length,a+50));throw new Error("readTagExp returned undefined at position "+a+'. Context: "'+S+'"')}var I=T.tagName,P=T.rawTagName,C=T.tagExp,A=T.attrExpPresent,O=T.closeIndex;if(this.options.transformTagName){var D=this.options.transformTagName(I);C===I&&(C=D),I=D}if(this.options.strictReservedNames&&(I===this.options.commentPropName||I===this.options.cdataPropName))throw new Error("Invalid tag name: "+I);r&&i&&"!xml"!==r.tagname&&(i=this.saveTextToParentTag(i,r,this.matcher,!1));var _=r;_&&-1!==this.options.unpairedTags.indexOf(_.tagname)&&(r=this.tagsNodeStack.pop(),this.matcher.pop());var j=!1;C.length>0&&C.lastIndexOf("/")===C.length-1&&(j=!0,C="/"===I[I.length-1]?I=I.substr(0,I.length-1):C.substr(0,C.length-1),A=I!==C);var k,F=null;k=w(P),I!==e.tagname&&this.matcher.push(I,{},k),I!==C&&A&&(F=this.buildAttributesMap(C,this.matcher,I))&&y(F,this.options),I!==e.tagname&&(this.isCurrentNodeStopNode=this.isItStopNode(this.stopNodeExpressions,this.matcher));var L=a;if(this.isCurrentNodeStopNode){var U="";if(j)a=T.closeIndex;else if(-1!==this.options.unpairedTags.indexOf(I))a=T.closeIndex;else{var $=this.readStopNodeData(t,P,O+1);if(!$)throw new Error("Unexpected end of "+P);a=$.i,U=$.tagContent}var R=new u(I);F&&(R[":@"]=F),R.add(this.options.textNodeName,U),this.matcher.pop(),this.isCurrentNodeStopNode=!1,this.addChild(r,R,this.matcher,L)}else{if(j){if(this.options.transformTagName){var Y=this.options.transformTagName(I);C===I&&(C=Y),I=Y}var W=new u(I);F&&(W[":@"]=F),this.addChild(r,W,this.matcher,L),this.matcher.pop(),this.isCurrentNodeStopNode=!1}else{if(-1!==this.options.unpairedTags.indexOf(I)){var X=new u(I);F&&(X[":@"]=F),this.addChild(r,X,this.matcher,L),this.matcher.pop(),this.isCurrentNodeStopNode=!1,a=T.closeIndex;continue}var z=new u(I);if(this.tagsNodeStack.length>this.options.maxNestedTags)throw new Error("Maximum nested tags exceeded");this.tagsNodeStack.push(r),F&&(z[":@"]=F),this.addChild(r,z,this.matcher,L),r=z}i="",a=O}}else i+=t[a];return e.child};function D(t,e,r,i){this.options.captureMetaData||(i=void 0);var n=this.options.jPath?r.toString():r,a=this.options.updateTag(e.tagname,n,e[":@"]);!1===a||("string"==typeof a?(e.tagname=a,t.addChild(e,i)):t.addChild(e,i))}function _(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 a=this.options.jPath?r.toString():r;if(!i.tagFilter(e,a))return t}for(var s in this.docTypeEntities){var o=this.docTypeEntities[s],h=t.match(o.regx);if(h){if(this.entityExpansionCount+=h.length,i.maxTotalExpansions&&this.entityExpansionCount>i.maxTotalExpansions)throw new Error("Entity expansion limit exceeded: "+this.entityExpansionCount+" > "+i.maxTotalExpansions);var l=t.length;if(t=t.replace(o.regx,o.val),i.maxExpandedLength&&(this.currentExpandedLength+=t.length-l,this.currentExpandedLength>i.maxExpandedLength))throw new Error("Total expanded content size exceeded: "+this.currentExpandedLength+" > "+i.maxExpandedLength)}}if(-1===t.indexOf("&"))return t;for(var u in this.lastEntities){var p=this.lastEntities[u];t=t.replace(p.regex,p.val)}if(-1===t.indexOf("&"))return t;if(this.options.htmlEntities)for(var d in this.htmlEntities){var f=this.htmlEntities[d];t=t.replace(f.regex,f.val)}return t.replace(this.ampEntity.regex,this.ampEntity.val)}function j(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 k(t,e){if(!t||0===t.length)return!1;for(var r=0;r<t.length;r++)if(e.matches(t[r]))return!0;return!1}function V(t,e,r,i){var n=t.indexOf(e,r);if(-1===n)throw new Error(i);return n+e.length-1}function M(t,e,r,i){void 0===i&&(i=">");var n=function(t,e,r){var i;void 0===r&&(r=">");for(var n="",a=e;a<t.length;a++){var s=t[a];if(i)s===i&&(i="");else if('"'===s||"'"===s)i=s;else if(s===r[0]){if(!r[1])return{data:n,index:a};if(t[a+1]===r[1])return{data:n,index:a}}else"\t"===s&&(s=" ");n+=s}}(t,e+1,i);if(n){var a=n.data,s=n.index,o=a.search(/\s/),h=a,l=!0;-1!==o&&(h=a.substring(0,o),a=a.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:a,closeIndex:s,attrExpPresent:l,rawTagName:u}}}function F(t,e,r){for(var i=r,n=1;r<t.length;r++)if("<"===t[r])if("/"===t[r+1]){var a=V(t,">",r,e+" is not closed");if(t.substring(r+2,a).trim()===e&&0===--n)return{tagContent:t.substring(i,r),i:a};r=a}else if("?"===t[r+1])r=V(t,"?>",r+1,"StopNode is not closed.");else if("!--"===t.substr(r+1,3))r=V(t,"--\x3e",r+3,"StopNode is not closed.");else if("!["===t.substr(r+1,2))r=V(t,"]]>",r,"StopNode is not closed.")-2;else{var s=M(t,r,">");s&&((s&&s.tagName)===e&&"/"!==s.tagExp[s.tagExp.length-1]&&n++,r=s.closeIndex)}}function L(t,e,r){if(e&&"string"==typeof t){var i=t.trim();return"true"===i||"false"!==i&&function(t,e={}){if(e=Object.assign({},v,e),!t||"string"!=typeof t)return t;let r=t.trim();if(void 0!==e.skipLike&&e.skipLike.test(r))return t;if("0"===t)return 0;if(e.hex&&c.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(r.includes("e")||r.includes("E"))return function(t,e,r){if(!r.eNotation)return t;const i=e.match(x);if(i){let n=i[1]||"";const a=-1===i[3].indexOf("e")?"E":"e",s=i[2],o=n?t[s.length+1]===a:t[s.length]===a;return s.length>1&&o?t:1!==s.length||!i[3].startsWith(`.${a}`)&&i[3][0]!==a?r.leadingZeros&&!o?(e=(i[1]||"")+i[3],Number(e)):t:Number(e)}return t}(t,r,e);{const n=m.exec(r);if(n){const a=n[1]||"",s=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=a?"."===t[s.length+1]:"."===t[s.length];if(!e.leadingZeros&&(s.length>1||1===s.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===`${a}${o}`?i:t;let h=s?o:r;return s?h===n||a+h===n?i:t:h===n||h===a+n?i:t}}return t}var i}(t,r)}return void 0!==t?t:""}function U(t,e,r){var i=Number.parseInt(t,e);return i>=0&&i<=1114111?String.fromCodePoint(i):r+t+";"}var $=u.getMetaDataSymbol();function R(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 Y(t,e,r){return W(t,e,r)}function W(t,e,r){for(var i,n={},a=0;a<t.length;a++){var s=t[a],o=X(s);if(void 0!==o&&o!==e.textNodeName){var h=R(s[":@"]||{},e.attributeNamePrefix);r.push(o,h)}if(o===e.textNodeName)void 0===i?i=s[o]:i+=""+s[o];else{if(void 0===o)continue;if(s[o]){var l=W(s[o],e,r),u=B(l,e);if(s[":@"]?z(l,s[":@"],r,e):1!==Object.keys(l).length||void 0===l[e.textNodeName]||e.alwaysCreateTextNode?0===Object.keys(l).length&&(e.alwaysCreateTextNode?l[e.textNodeName]="":l=""):l=l[e.textNodeName],void 0!==s[$]&&"object"==typeof l&&null!==l&&(l[$]=s[$]),void 0!==n[o]&&Object.prototype.hasOwnProperty.call(n,o))Array.isArray(n[o])||(n[o]=[n[o]]),n[o].push(l);else{var p=e.jPath?r.toString():r;e.isArray(o,p,u)?n[o]=[l]:n[o]=l}void 0!==o&&o!==e.textNodeName&&r.pop()}}}return"string"==typeof i?i.length>0&&(n[e.textNodeName]=i):void 0!==i&&(n[e.textNodeName]=i),n}function X(t){for(var e=Object.keys(t),r=0;r<e.length;r++){var i=e[r];if(":@"!==i)return i}}function z(t,e,r,i){if(e)for(var n=Object.keys(e),a=n.length,s=0;s<a;s++){var o=n[s],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 B(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 G={allowBooleanAttributes:!1,unpairedTags:[]};function Z(t){return" "===t||"\t"===t||"\n"===t||"\r"===t}function q(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 et("InvalidXml","XML declaration allowed only at the start of the document.",nt(t,e));if("?"==t[e]&&">"==t[e+1]){e++;break}}return e}function K(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}function Q(t,e){for(var r="",i="",n=!1;e<t.length;e++){if('"'===t[e]||"'"===t[e])""===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 J=new RegExp("(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['\"])(([\\s\\S])*?)\\5)?","g");function H(t,e){for(var r=o(t,J),i={},n=0;n<r.length;n++){if(0===r[n][1].length)return et("InvalidAttr","Attribute '"+r[n][2]+"' has no space in starting.",at(r[n]));if(void 0!==r[n][3]&&void 0===r[n][4])return et("InvalidAttr","Attribute '"+r[n][2]+"' is without value.",at(r[n]));if(void 0===r[n][3]&&!e.allowBooleanAttributes)return et("InvalidAttr","boolean attribute '"+r[n][2]+"' is not allowed.",at(r[n]));var a=r[n][2];if(!rt(a))return et("InvalidAttr","Attribute '"+a+"' is an invalid name.",at(r[n]));if(Object.prototype.hasOwnProperty.call(i,a))return et("InvalidAttr","Attribute '"+a+"' is repeated.",at(r[n]));i[a]=1}return!0}function tt(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 et(t,e,r){return{err:{code:t,msg:e,line:r.line||r,col:r.col}}}function rt(t){return l(t)}function it(t){return l(t)}function nt(t,e){var r=t.substring(0,e).split(/\r?\n/);return{line:r.length,col:r[r.length-1].length+1}}function at(t){return t.startIndex+t[1].length}var st=function(){function t(t){this.externalEntities={},this.options=n(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=function(t,e){e=Object.assign({},G,e);var r=[],i=!1,n=!1;"\ufeff"===t[0]&&(t=t.substr(1));for(var a=0;a<t.length;a++)if("<"===t[a]&&"?"===t[a+1]){if((a=q(t,a+=2)).err)return a}else{if("<"!==t[a]){if(Z(t[a]))continue;return et("InvalidChar","char '"+t[a]+"' is not expected.",nt(t,a))}var s=a;if("!"===t[++a]){a=K(t,a);continue}var o=!1;"/"===t[a]&&(o=!0,a++);for(var h="";a<t.length&&">"!==t[a]&&" "!==t[a]&&"\t"!==t[a]&&"\n"!==t[a]&&"\r"!==t[a];a++)h+=t[a];if("/"===(h=h.trim())[h.length-1]&&(h=h.substring(0,h.length-1),a--),!it(h))return et("InvalidTag",0===h.trim().length?"Invalid space after '<'.":"Tag '"+h+"' is an invalid name.",nt(t,a));var l=Q(t,a);if(!1===l)return et("InvalidAttr","Attributes for '"+h+"' have open quote.",nt(t,a));var u=l.value;if(a=l.index,"/"===u[u.length-1]){var p=a-u.length,d=H(u=u.substring(0,u.length-1),e);if(!0!==d)return et(d.err.code,d.err.msg,nt(t,p+d.err.line));i=!0}else if(o){if(!l.tagClosed)return et("InvalidTag","Closing tag '"+h+"' doesn't have proper closing.",nt(t,a));if(u.trim().length>0)return et("InvalidTag","Closing tag '"+h+"' can't have attributes or invalid starting.",nt(t,s));if(0===r.length)return et("InvalidTag","Closing tag '"+h+"' has not been opened.",nt(t,s));var f=r.pop();if(h!==f.tagName){var g=nt(t,f.tagStartPos);return et("InvalidTag","Expected closing tag '"+f.tagName+"' (opened in line "+g.line+", col "+g.col+") instead of closing tag '"+h+"'.",nt(t,s))}0==r.length&&(n=!0)}else{var c=H(u,e);if(!0!==c)return et(c.err.code,c.err.msg,nt(t,a-u.length+c.err.line));if(!0===n)return et("InvalidXml","Multiple possible root nodes found.",nt(t,a));-1!==e.unpairedTags.indexOf(h)||r.push({tagName:h,tagStartPos:s}),i=!0}for(a++;a<t.length;a++)if("<"===t[a]){if("!"===t[a+1]){a=K(t,++a);continue}if("?"!==t[a+1])break;if((a=q(t,++a)).err)return a}else if("&"===t[a]){var m=tt(t,a);if(-1==m)return et("InvalidChar","char '&' is not expected.",nt(t,a));a=m}else if(!0===n&&!Z(t[a]))return et("InvalidXml","Extra text at the end",nt(t,a));"<"===t[a]&&a--}return i?1==r.length?et("InvalidTag","Unclosed tag '"+r[0].tagName+"'.",nt(t,r[0].tagStartPos)):!(r.length>0)||et("InvalidXml","Invalid '"+JSON.stringify(r.map(function(t){return t.tagName}),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1}):et("InvalidXml","Start tag expected.",1)}(t,e);if(!0!==r)throw Error(r.err.msg+":"+r.err.line+":"+r.err.col)}var i=new T(this.options);i.addExternalEntities(this.externalEntities);var n=i.parseXml(t);return this.options.preserveOrder||void 0===n?n:Y(n,this.options,i.matcher)},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 '
'");if("&"===e)throw new Error("An entity with value '&' is not permitted");this.externalEntities[t]=e},t.getMetaDataSymbol=function(){return u.getMetaDataSymbol()},t}();return e})()); | ||
| //# sourceMappingURL=fxparser.min.js.map |
+4
-3
| { | ||
| "name": "fast-xml-parser", | ||
| "version": "5.4.2", | ||
| "version": "5.5.0", | ||
| "description": "Validate XML, Parse XML, Build XML without C/C++ based libraries", | ||
@@ -90,5 +90,6 @@ "main": "./lib/fxp.cjs", | ||
| "dependencies": { | ||
| "fast-xml-builder": "^1.0.0", | ||
| "fast-xml-builder": "file:../../fxp-builder", | ||
| "path-expression-matcher": "^1.1.2", | ||
| "strnum": "^2.1.2" | ||
| } | ||
| } | ||
| } |
+8
-7
@@ -155,9 +155,10 @@ # [fast-xml-parser](https://www.npmjs.com/package/fast-xml-parser) | ||
| <td><ol> | ||
| <li><a href="./docs/v4/1.GettingStarted.md">Getting Started</a></li> | ||
| <li><a href="./docs/v4/2.XMLparseOptions.md">XML Parser</a></li> | ||
| <li><a href="./docs/v4/3.XMLBuilder.md">XML Builder</a></li> | ||
| <li><a href="./docs/v4/4.XMLValidator.md">XML Validator</a></li> | ||
| <li><a href="./docs/v4/5.Entities.md">Entities</a></li> | ||
| <li><a href="./docs/v4/6.HTMLParsing.md">HTML Document Parsing</a></li> | ||
| <li><a href="./docs/v4/7.PITags.md">PI Tag processing</a></li> | ||
| <li><a href="./docs/v4,v5/1.GettingStarted.md">Getting Started</a></li> | ||
| <li><a href="./docs/v4,v5/2.XMLparseOptions.md">XML Parser</a></li> | ||
| <li><a href="./docs/v4,v5/3.XMLBuilder.md">XML Builder</a></li> | ||
| <li><a href="./docs/v4,v5/4.XMLValidator.md">XML Validator</a></li> | ||
| <li><a href="./docs/v4,v5/5.Entities.md">Entities</a></li> | ||
| <li><a href="./docs/v4,v5/6.HTMLParsing.md">HTML Document Parsing</a></li> | ||
| <li><a href="./docs/v4,v5/7.PITags.md">PI Tag processing</a></li> | ||
| <li><a href="./docs/v4,v5/8.PathExpression.md">Path Expression</a></li> | ||
| </ol></td> | ||
@@ -164,0 +165,0 @@ <td><ol> |
+46
-19
@@ -0,1 +1,3 @@ | ||
| import { Matcher, Expression } from 'path-expression-matcher'; | ||
| export type ProcessEntitiesOptions = { | ||
@@ -56,3 +58,3 @@ /** | ||
| * @param tagName - The name of the current tag | ||
| * @param jPath - The jPath of the current tag | ||
| * @param jPathOrMatcher - The jPath string (if jPath: true) or Matcher instance (if jPath: false) | ||
| * @returns `true` to allow entity replacement, `false` to skip | ||
@@ -62,3 +64,3 @@ * | ||
| */ | ||
| tagFilter?: ((tagName: string, jPath: string) => boolean) | null; | ||
| tagFilter?: ((tagName: string, jPathOrMatcher: string | Matcher) => boolean) | null; | ||
| }; | ||
@@ -108,3 +110,3 @@ | ||
| */ | ||
| ignoreAttributes?: boolean | (string | RegExp)[] | ((attrName: string, jPath: string) => boolean); | ||
| ignoreAttributes?: boolean | (string | RegExp)[] | ((attrName: string, jPathOrMatcher: string | Matcher) => boolean); | ||
@@ -163,2 +165,7 @@ /** | ||
| * | ||
| * @param tagName - The name of the tag | ||
| * @param tagValue - The value of the tag | ||
| * @param jPathOrMatcher - The jPath string (if jPath: true) or Matcher instance (if jPath: false) | ||
| * @param hasAttributes - Whether the tag has attributes | ||
| * @param isLeafNode - Whether the tag is a leaf node | ||
| * @returns {undefined|null} `undefined` or `null` to set original value. | ||
@@ -170,5 +177,5 @@ * @returns {unknown} | ||
| * | ||
| * Defaults to `(tagName, val, jPath, hasAttributes, isLeafNode) => val` | ||
| * Defaults to `(tagName, val, jPathOrMatcher, hasAttributes, isLeafNode) => val` | ||
| */ | ||
| tagValueProcessor?: (tagName: string, tagValue: string, jPath: string, hasAttributes: boolean, isLeafNode: boolean) => unknown; | ||
| tagValueProcessor?: (tagName: string, tagValue: string, jPathOrMatcher: string | Matcher, hasAttributes: boolean, isLeafNode: boolean) => unknown; | ||
@@ -178,11 +185,11 @@ /** | ||
| * | ||
| * @param attrName | ||
| * @param attrValue | ||
| * @param jPath | ||
| * @param attrName - The name of the attribute | ||
| * @param attrValue - The value of the attribute | ||
| * @param jPathOrMatcher - The jPath string (if jPath: true) or Matcher instance (if jPath: false) | ||
| * @returns {undefined|null} `undefined` or `null` to set original value | ||
| * @returns {unknown} | ||
| * | ||
| * Defaults to `(attrName, val, jPath) => val` | ||
| * Defaults to `(attrName, val, jPathOrMatcher) => val` | ||
| */ | ||
| attributeValueProcessor?: (attrName: string, attrValue: string, jPath: string) => unknown; | ||
| attributeValueProcessor?: (attrName: string, attrValue: string, jPathOrMatcher: string | Matcher) => unknown; | ||
@@ -199,5 +206,9 @@ /** | ||
| * | ||
| * Accepts string patterns or Expression objects from path-expression-matcher | ||
| * | ||
| * String patterns starting with "*." are automatically converted to ".." for backward compatibility | ||
| * | ||
| * Defaults to `[]` | ||
| */ | ||
| stopNodes?: string[]; | ||
| stopNodes?: (string | Expression)[]; | ||
@@ -221,6 +232,6 @@ /** | ||
| * | ||
| * @param tagName | ||
| * @param jPath | ||
| * @param isLeafNode | ||
| * @param isAttribute | ||
| * @param tagName - The name of the tag | ||
| * @param jPathOrMatcher - The jPath string (if jPath: true) or Matcher instance (if jPath: false) | ||
| * @param isLeafNode - Whether the tag is a leaf node | ||
| * @param isAttribute - Whether this is an attribute | ||
| * @returns {boolean} | ||
@@ -230,3 +241,3 @@ * | ||
| */ | ||
| isArray?: (tagName: string, jPath: string, isLeafNode: boolean, isAttribute: boolean) => boolean; | ||
| isArray?: (tagName: string, jPathOrMatcher: string | Matcher, isLeafNode: boolean, isAttribute: boolean) => boolean; | ||
@@ -285,8 +296,11 @@ /** | ||
| * | ||
| * @param tagName - The name of the tag | ||
| * @param jPathOrMatcher - The jPath string (if jPath: true) or Matcher instance (if jPath: false) | ||
| * @param attrs - The attributes object | ||
| * @returns {string} new tag name. | ||
| * @returns false to skip the tag | ||
| * | ||
| * Defaults to `(tagName, jPath, attrs) => tagName` | ||
| * Defaults to `(tagName, jPathOrMatcher, attrs) => tagName` | ||
| */ | ||
| updateTag?: (tagName: string, jPath: string, attrs: { [k: string]: string }) => string | boolean; | ||
| updateTag?: (tagName: string, jPathOrMatcher: string | Matcher, attrs: { [k: string]: string }) => string | boolean; | ||
@@ -312,2 +326,13 @@ /** | ||
| strictReservedNames?: boolean; | ||
| /** | ||
| * Controls whether callbacks receive jPath as string or Matcher instance | ||
| * | ||
| * When `true` - callbacks receive jPath as string (backward compatible) | ||
| * | ||
| * When `false` - callbacks receive Matcher instance for advanced pattern matching | ||
| * | ||
| * Defaults to `true` | ||
| */ | ||
| jPath?: boolean; | ||
| }; | ||
@@ -451,5 +476,7 @@ | ||
| * | ||
| * Accepts string patterns or Expression objects from path-expression-matcher | ||
| * | ||
| * Defaults to `[]` | ||
| */ | ||
| stopNodes?: string[]; | ||
| stopNodes?: (string | Expression)[]; | ||
@@ -456,0 +483,0 @@ /** |
| 'use strict'; | ||
| import XmlNode from './xmlNode.js'; | ||
| import { Matcher } from 'path-expression-matcher'; | ||
@@ -8,9 +9,33 @@ const METADATA_SYMBOL = XmlNode.getMetaDataSymbol(); | ||
| /** | ||
| * Helper function to strip attribute prefix from attribute map | ||
| * @param {object} attrs - Attributes with prefix (e.g., {"@_class": "code"}) | ||
| * @param {string} prefix - Attribute prefix to remove (e.g., "@_") | ||
| * @returns {object} Attributes without prefix (e.g., {"class": "code"}) | ||
| */ | ||
| function stripAttributePrefix(attrs, prefix) { | ||
| if (!attrs || typeof attrs !== 'object') return {}; | ||
| if (!prefix) return attrs; | ||
| const rawAttrs = {}; | ||
| for (const key in attrs) { | ||
| if (key.startsWith(prefix)) { | ||
| const rawName = key.substring(prefix.length); | ||
| rawAttrs[rawName] = attrs[key]; | ||
| } else { | ||
| // Attribute without prefix (shouldn't normally happen, but be safe) | ||
| rawAttrs[key] = attrs[key]; | ||
| } | ||
| } | ||
| return rawAttrs; | ||
| } | ||
| /** | ||
| * | ||
| * @param {array} node | ||
| * @param {any} options | ||
| * @param {Matcher} matcher - Path matcher instance | ||
| * @returns | ||
| */ | ||
| export default function prettify(node, options) { | ||
| return compress(node, options); | ||
| export default function prettify(node, options, matcher) { | ||
| return compress(node, options, matcher); | ||
| } | ||
@@ -22,6 +47,6 @@ | ||
| * @param {object} options | ||
| * @param {string} jPath | ||
| * @param {Matcher} matcher - Path matcher instance | ||
| * @returns object | ||
| */ | ||
| function compress(arr, options, jPath) { | ||
| function compress(arr, options, matcher) { | ||
| let text; | ||
@@ -32,6 +57,12 @@ const compressedObj = {}; //This is intended to be a plain object | ||
| const property = propName(tagObj); | ||
| let newJpath = ""; | ||
| if (jPath === undefined) newJpath = property; | ||
| else newJpath = jPath + "." + property; | ||
| // Push current property to matcher WITH RAW ATTRIBUTES (no prefix) | ||
| if (property !== undefined && property !== options.textNodeName) { | ||
| const rawAttrs = stripAttributePrefix( | ||
| tagObj[":@"] || {}, | ||
| options.attributeNamePrefix | ||
| ); | ||
| matcher.push(property, rawAttrs); | ||
| } | ||
| if (property === options.textNodeName) { | ||
@@ -44,7 +75,7 @@ if (text === undefined) text = tagObj[property]; | ||
| let val = compress(tagObj[property], options, newJpath); | ||
| let val = compress(tagObj[property], options, matcher); | ||
| const isLeaf = isLeafTag(val, options); | ||
| if (tagObj[":@"]) { | ||
| assignAttributes(val, tagObj[":@"], newJpath, options); | ||
| assignAttributes(val, tagObj[":@"], matcher, options); | ||
| } else if (Object.keys(val).length === 1 && val[options.textNodeName] !== undefined && !options.alwaysCreateTextNode) { | ||
@@ -70,3 +101,6 @@ val = val[options.textNodeName]; | ||
| //also determine if it is a leaf node | ||
| if (options.isArray(property, newJpath, isLeaf)) { | ||
| // Pass jPath string or matcher based on options.jPath setting | ||
| const jPathOrMatcher = options.jPath ? matcher.toString() : matcher; | ||
| if (options.isArray(property, jPathOrMatcher, isLeaf)) { | ||
| compressedObj[property] = [val]; | ||
@@ -77,2 +111,7 @@ } else { | ||
| } | ||
| // Pop property from matcher after processing | ||
| if (property !== undefined && property !== options.textNodeName) { | ||
| matcher.pop(); | ||
| } | ||
| } | ||
@@ -98,3 +137,3 @@ | ||
| function assignAttributes(obj, attrMap, jpath, options) { | ||
| function assignAttributes(obj, attrMap, matcher, options) { | ||
| if (attrMap) { | ||
@@ -104,4 +143,16 @@ const keys = Object.keys(attrMap); | ||
| for (let i = 0; i < len; i++) { | ||
| const atrrName = keys[i]; | ||
| if (options.isArray(atrrName, jpath + "." + atrrName, true, true)) { | ||
| const atrrName = keys[i]; // This is the PREFIXED name (e.g., "@_class") | ||
| // Strip prefix for matcher path (for isArray callback) | ||
| const rawAttrName = atrrName.startsWith(options.attributeNamePrefix) | ||
| ? atrrName.substring(options.attributeNamePrefix.length) | ||
| : atrrName; | ||
| // For attributes, we need to create a temporary path | ||
| // Pass jPath string or matcher based on options.jPath setting | ||
| const jPathOrMatcher = options.jPath | ||
| ? matcher.toString() + "." + rawAttrName | ||
| : matcher; | ||
| if (options.isArray(atrrName, jPathOrMatcher, true, true)) { | ||
| obj[atrrName] = [attrMap[atrrName]]; | ||
@@ -131,2 +182,2 @@ } else { | ||
| return false; | ||
| } | ||
| } |
@@ -43,2 +43,3 @@ export const defaultOptions = { | ||
| strictReservedNames: true, | ||
| jPath: true, // if true, pass jPath string to callbacks; if false, pass matcher instance | ||
| }; | ||
@@ -89,4 +90,16 @@ | ||
| built.processEntities = normalizeProcessEntities(built.processEntities); | ||
| // Convert old-style stopNodes for backward compatibility | ||
| if (built.stopNodes && Array.isArray(built.stopNodes)) { | ||
| built.stopNodes = built.stopNodes.map(node => { | ||
| if (typeof node === 'string' && node.startsWith('*.')) { | ||
| // Old syntax: *.tagname meant "tagname anywhere" | ||
| // Convert to new syntax: ..tagname | ||
| return '..' + node.substring(2); | ||
| } | ||
| return node; | ||
| }); | ||
| } | ||
| //console.debug(built.processEntities) | ||
| return built; | ||
| }; |
@@ -9,3 +9,5 @@ 'use strict'; | ||
| import getIgnoreAttributesFn from "../ignoreAttributes.js"; | ||
| import { Expression, Matcher } from 'path-expression-matcher'; | ||
| // const regx = | ||
@@ -18,2 +20,53 @@ // '<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\/)(NAME)\\s*>))([^<]*)' | ||
| // Helper functions for attribute and namespace handling | ||
| /** | ||
| * Extract raw attributes (without prefix) from prefixed attribute map | ||
| * @param {object} prefixedAttrs - Attributes with prefix from buildAttributesMap | ||
| * @param {object} options - Parser options containing attributeNamePrefix | ||
| * @returns {object} Raw attributes for matcher | ||
| */ | ||
| function extractRawAttributes(prefixedAttrs, options) { | ||
| if (!prefixedAttrs) return {}; | ||
| // Handle attributesGroupName option | ||
| const attrs = options.attributesGroupName | ||
| ? prefixedAttrs[options.attributesGroupName] | ||
| : prefixedAttrs; | ||
| if (!attrs) return {}; | ||
| const rawAttrs = {}; | ||
| for (const key in attrs) { | ||
| // Remove the attribute prefix to get raw name | ||
| if (key.startsWith(options.attributeNamePrefix)) { | ||
| const rawName = key.substring(options.attributeNamePrefix.length); | ||
| rawAttrs[rawName] = attrs[key]; | ||
| } else { | ||
| // Attribute without prefix (shouldn't normally happen, but be safe) | ||
| rawAttrs[key] = attrs[key]; | ||
| } | ||
| } | ||
| return rawAttrs; | ||
| } | ||
| /** | ||
| * Extract namespace from raw tag name | ||
| * @param {string} rawTagName - Tag name possibly with namespace (e.g., "soap:Envelope") | ||
| * @returns {string|undefined} Namespace or undefined | ||
| */ | ||
| function extractNamespace(rawTagName) { | ||
| if (!rawTagName || typeof rawTagName !== 'string') return undefined; | ||
| const colonIndex = rawTagName.indexOf(':'); | ||
| if (colonIndex !== -1 && colonIndex > 0) { | ||
| const ns = rawTagName.substring(0, colonIndex); | ||
| // Don't treat xmlns as a namespace | ||
| if (ns !== 'xmlns') { | ||
| return ns; | ||
| } | ||
| } | ||
| return undefined; | ||
| } | ||
| export default class OrderedObjParser { | ||
@@ -63,12 +116,19 @@ constructor(options) { | ||
| // Initialize path matcher for path-expression-matcher | ||
| this.matcher = new Matcher(); | ||
| // Flag to track if current node is a stop node (optimization) | ||
| this.isCurrentNodeStopNode = false; | ||
| // Pre-compile stopNodes expressions | ||
| if (this.options.stopNodes && this.options.stopNodes.length > 0) { | ||
| this.stopNodesExact = new Set(); | ||
| this.stopNodesWildcard = new Set(); | ||
| this.stopNodeExpressions = []; | ||
| for (let i = 0; i < this.options.stopNodes.length; i++) { | ||
| const stopNodeExp = this.options.stopNodes[i]; | ||
| if (typeof stopNodeExp !== 'string') continue; | ||
| if (stopNodeExp.startsWith("*.")) { | ||
| this.stopNodesWildcard.add(stopNodeExp.substring(2)); | ||
| } else { | ||
| this.stopNodesExact.add(stopNodeExp); | ||
| if (typeof stopNodeExp === 'string') { | ||
| // Convert string to Expression object | ||
| this.stopNodeExpressions.push(new Expression(stopNodeExp)); | ||
| } else if (stopNodeExp instanceof Expression) { | ||
| // Already an Expression object | ||
| this.stopNodeExpressions.push(stopNodeExp); | ||
| } | ||
@@ -96,3 +156,3 @@ } | ||
| * @param {string} tagName | ||
| * @param {string} jPath | ||
| * @param {string|Matcher} jPath - jPath string or Matcher instance based on options.jPath | ||
| * @param {boolean} dontTrim | ||
@@ -111,3 +171,5 @@ * @param {boolean} hasAttributes | ||
| const newval = this.options.tagValueProcessor(tagName, val, jPath, hasAttributes, isLeafNode); | ||
| // Pass jPath string or matcher based on options.jPath setting | ||
| const jPathOrMatcher = this.options.jPath ? jPath.toString() : jPath; | ||
| const newval = this.options.tagValueProcessor(tagName, val, jPathOrMatcher, hasAttributes, isLeafNode); | ||
| if (newval === null || newval === undefined) { | ||
@@ -159,9 +221,38 @@ //don't parse | ||
| const attrs = {}; | ||
| // First pass: parse all attributes and update matcher with raw values | ||
| // This ensures the matcher has all attribute values when processors run | ||
| const rawAttrsForMatcher = {}; | ||
| for (let i = 0; i < len; i++) { | ||
| const attrName = this.resolveNameSpace(matches[i][1]); | ||
| if (this.ignoreAttributesFn(attrName, jPath)) { | ||
| const oldVal = matches[i][4]; | ||
| if (attrName.length && oldVal !== undefined) { | ||
| let parsedVal = oldVal; | ||
| if (this.options.trimValues) { | ||
| parsedVal = parsedVal.trim(); | ||
| } | ||
| parsedVal = this.replaceEntitiesValue(parsedVal, tagName, jPath); | ||
| rawAttrsForMatcher[attrName] = parsedVal; | ||
| } | ||
| } | ||
| // Update matcher with raw attribute values BEFORE running processors | ||
| if (Object.keys(rawAttrsForMatcher).length > 0 && typeof jPath === 'object' && jPath.updateCurrent) { | ||
| jPath.updateCurrent(rawAttrsForMatcher); | ||
| } | ||
| // Second pass: now process attributes with matcher having full attribute context | ||
| for (let i = 0; i < len; i++) { | ||
| const attrName = this.resolveNameSpace(matches[i][1]); | ||
| // Convert jPath to string if needed for ignoreAttributesFn | ||
| const jPathStr = this.options.jPath ? jPath.toString() : jPath; | ||
| if (this.ignoreAttributesFn(attrName, jPathStr)) { | ||
| continue | ||
| } | ||
| let oldVal = matches[i][4]; | ||
| let aName = this.options.attributeNamePrefix + attrName; | ||
| if (attrName.length) { | ||
@@ -178,3 +269,6 @@ if (this.options.transformAttributeName) { | ||
| oldVal = this.replaceEntitiesValue(oldVal, tagName, jPath); | ||
| const newVal = this.options.attributeValueProcessor(attrName, oldVal, jPath); | ||
| // Pass jPath string or matcher based on options.jPath setting | ||
| const jPathOrMatcher = this.options.jPath ? jPath.toString() : jPath; | ||
| const newVal = this.options.attributeValueProcessor(attrName, oldVal, jPathOrMatcher); | ||
| if (newVal === null || newVal === undefined) { | ||
@@ -199,2 +293,3 @@ //don't parse | ||
| } | ||
| if (!Object.keys(attrs).length) { | ||
@@ -217,4 +312,6 @@ return; | ||
| let textData = ""; | ||
| let jPath = ""; | ||
| // Reset matcher for new document | ||
| this.matcher.reset(); | ||
| // Reset entity expansion counters for this document | ||
@@ -246,18 +343,18 @@ this.entityExpansionCount = 0; | ||
| if (currentNode) { | ||
| textData = this.saveTextToParentTag(textData, currentNode, jPath); | ||
| textData = this.saveTextToParentTag(textData, currentNode, this.matcher); | ||
| } | ||
| //check if last tag of nested tag was unpaired tag | ||
| const lastTagName = jPath.substring(jPath.lastIndexOf(".") + 1); | ||
| const lastTagName = this.matcher.getCurrentTag(); | ||
| if (tagName && this.options.unpairedTags.indexOf(tagName) !== -1) { | ||
| throw new Error(`Unpaired tag can not be used as closing tag: </${tagName}>`); | ||
| } | ||
| let propIndex = 0 | ||
| if (lastTagName && this.options.unpairedTags.indexOf(lastTagName) !== -1) { | ||
| propIndex = jPath.lastIndexOf('.', jPath.lastIndexOf('.') - 1) | ||
| // Pop the unpaired tag | ||
| this.matcher.pop(); | ||
| this.tagsNodeStack.pop(); | ||
| } else { | ||
| propIndex = jPath.lastIndexOf("."); | ||
| } | ||
| jPath = jPath.substring(0, propIndex); | ||
| // Pop the closing tag | ||
| this.matcher.pop(); | ||
| this.isCurrentNodeStopNode = false; // Reset flag when closing tag | ||
@@ -272,3 +369,3 @@ currentNode = this.tagsNodeStack.pop();//avoid recursion, set the parent tag scope | ||
| textData = this.saveTextToParentTag(textData, currentNode, jPath); | ||
| textData = this.saveTextToParentTag(textData, currentNode, this.matcher); | ||
| if ((this.options.ignoreDeclaration && tagData.tagName === "?xml") || this.options.ignorePiTags) { | ||
@@ -282,5 +379,5 @@ //do nothing | ||
| if (tagData.tagName !== tagData.tagExp && tagData.attrExpPresent) { | ||
| childNode[":@"] = this.buildAttributesMap(tagData.tagExp, jPath, tagData.tagName); | ||
| childNode[":@"] = this.buildAttributesMap(tagData.tagExp, this.matcher, tagData.tagName); | ||
| } | ||
| this.addChild(currentNode, childNode, jPath, i); | ||
| this.addChild(currentNode, childNode, this.matcher, i); | ||
| } | ||
@@ -295,3 +392,3 @@ | ||
| textData = this.saveTextToParentTag(textData, currentNode, jPath); | ||
| textData = this.saveTextToParentTag(textData, currentNode, this.matcher); | ||
@@ -309,5 +406,5 @@ currentNode.add(this.options.commentPropName, [{ [this.options.textNodeName]: comment }]); | ||
| textData = this.saveTextToParentTag(textData, currentNode, jPath); | ||
| textData = this.saveTextToParentTag(textData, currentNode, this.matcher); | ||
| let val = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true, true); | ||
| let val = this.parseTextData(tagExp, currentNode.tagname, this.matcher, true, false, true, true); | ||
| if (val == undefined) val = ""; | ||
@@ -325,2 +422,10 @@ | ||
| let result = readTagExp(xmlData, i, this.options.removeNSPrefix); | ||
| // Safety check: readTagExp can return undefined | ||
| if (!result) { | ||
| // Log context for debugging | ||
| const context = xmlData.substring(Math.max(0, i - 50), Math.min(xmlData.length, i + 50)); | ||
| throw new Error(`readTagExp returned undefined at position ${i}. Context: "${context}"`); | ||
| } | ||
| let tagName = result.tagName; | ||
@@ -352,3 +457,3 @@ const rawTagName = result.rawTagName; | ||
| //when nested tag is found | ||
| textData = this.saveTextToParentTag(textData, currentNode, jPath, false); | ||
| textData = this.saveTextToParentTag(textData, currentNode, this.matcher, false); | ||
| } | ||
@@ -361,19 +466,57 @@ } | ||
| currentNode = this.tagsNodeStack.pop(); | ||
| jPath = jPath.substring(0, jPath.lastIndexOf(".")); | ||
| this.matcher.pop(); | ||
| } | ||
| // Clean up self-closing syntax BEFORE processing attributes | ||
| // This is where tagExp gets the trailing / removed | ||
| let isSelfClosing = false; | ||
| if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) { | ||
| isSelfClosing = true; | ||
| if (tagName[tagName.length - 1] === "/") { | ||
| tagName = tagName.substr(0, tagName.length - 1); | ||
| tagExp = tagName; | ||
| } else { | ||
| tagExp = tagExp.substr(0, tagExp.length - 1); | ||
| } | ||
| // Re-check attrExpPresent after cleaning | ||
| attrExpPresent = (tagName !== tagExp); | ||
| } | ||
| // Now process attributes with CLEAN tagExp (no trailing /) | ||
| let prefixedAttrs = null; | ||
| let rawAttrs = {}; | ||
| let namespace = undefined; | ||
| // Extract namespace from rawTagName | ||
| namespace = extractNamespace(rawTagName); | ||
| // Push tag to matcher FIRST (with empty attrs for now) so callbacks see correct path | ||
| if (tagName !== xmlObj.tagname) { | ||
| jPath += jPath ? "." + tagName : tagName; | ||
| this.matcher.push(tagName, {}, namespace); | ||
| } | ||
| // Now build attributes - callbacks will see correct matcher state | ||
| if (tagName !== tagExp && attrExpPresent) { | ||
| // Build attributes (returns prefixed attributes for the tree) | ||
| // Note: buildAttributesMap now internally updates the matcher with raw attributes | ||
| prefixedAttrs = this.buildAttributesMap(tagExp, this.matcher, tagName); | ||
| if (prefixedAttrs) { | ||
| // Extract raw attributes (without prefix) for our use | ||
| rawAttrs = extractRawAttributes(prefixedAttrs, this.options); | ||
| } | ||
| } | ||
| // Now check if this is a stop node (after attributes are set) | ||
| if (tagName !== xmlObj.tagname) { | ||
| this.isCurrentNodeStopNode = this.isItStopNode(this.stopNodeExpressions, this.matcher); | ||
| } | ||
| const startIndex = i; | ||
| if (this.isItStopNode(this.stopNodesExact, this.stopNodesWildcard, jPath, tagName)) { | ||
| if (this.isCurrentNodeStopNode) { | ||
| let tagContent = ""; | ||
| //self-closing tag | ||
| if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) { | ||
| if (tagName[tagName.length - 1] === "/") { //remove trailing '/' | ||
| tagName = tagName.substr(0, tagName.length - 1); | ||
| jPath = jPath.substr(0, jPath.length - 1); | ||
| tagExp = tagName; | ||
| } else { | ||
| tagExp = tagExp.substr(0, tagExp.length - 1); | ||
| } | ||
| // For self-closing tags, content is empty | ||
| if (isSelfClosing) { | ||
| i = result.closeIndex; | ||
@@ -383,3 +526,2 @@ } | ||
| else if (this.options.unpairedTags.indexOf(tagName) !== -1) { | ||
| i = result.closeIndex; | ||
@@ -398,24 +540,16 @@ } | ||
| if (tagName !== tagExp && attrExpPresent) { | ||
| childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName); | ||
| if (prefixedAttrs) { | ||
| childNode[":@"] = prefixedAttrs; | ||
| } | ||
| if (tagContent) { | ||
| tagContent = this.parseTextData(tagContent, tagName, jPath, true, attrExpPresent, true, true); | ||
| } | ||
| jPath = jPath.substr(0, jPath.lastIndexOf(".")); | ||
| // For stop nodes, store raw content as-is without any processing | ||
| childNode.add(this.options.textNodeName, tagContent); | ||
| this.addChild(currentNode, childNode, jPath, startIndex); | ||
| this.matcher.pop(); // Pop the stop node tag | ||
| this.isCurrentNodeStopNode = false; // Reset flag | ||
| this.addChild(currentNode, childNode, this.matcher, startIndex); | ||
| } else { | ||
| //selfClosing tag | ||
| if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) { | ||
| if (tagName[tagName.length - 1] === "/") { //remove trailing '/' | ||
| tagName = tagName.substr(0, tagName.length - 1); | ||
| jPath = jPath.substr(0, jPath.length - 1); | ||
| tagExp = tagName; | ||
| } else { | ||
| tagExp = tagExp.substr(0, tagExp.length - 1); | ||
| } | ||
| if (isSelfClosing) { | ||
| if (this.options.transformTagName) { | ||
@@ -430,15 +564,17 @@ const newTagName = this.options.transformTagName(tagName); | ||
| const childNode = new xmlNode(tagName); | ||
| if (tagName !== tagExp && attrExpPresent) { | ||
| childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName); | ||
| if (prefixedAttrs) { | ||
| childNode[":@"] = prefixedAttrs; | ||
| } | ||
| this.addChild(currentNode, childNode, jPath, startIndex); | ||
| jPath = jPath.substr(0, jPath.lastIndexOf(".")); | ||
| this.addChild(currentNode, childNode, this.matcher, startIndex); | ||
| this.matcher.pop(); // Pop self-closing tag | ||
| this.isCurrentNodeStopNode = false; // Reset flag | ||
| } | ||
| else if(this.options.unpairedTags.indexOf(tagName) !== -1){//unpaired tag | ||
| else if (this.options.unpairedTags.indexOf(tagName) !== -1) {//unpaired tag | ||
| const childNode = new xmlNode(tagName); | ||
| if(tagName !== tagExp && attrExpPresent){ | ||
| childNode[":@"] = this.buildAttributesMap(tagExp, jPath); | ||
| if (prefixedAttrs) { | ||
| childNode[":@"] = prefixedAttrs; | ||
| } | ||
| this.addChild(currentNode, childNode, jPath, startIndex); | ||
| jPath = jPath.substr(0, jPath.lastIndexOf(".")); | ||
| this.addChild(currentNode, childNode, this.matcher, startIndex); | ||
| this.matcher.pop(); // Pop unpaired tag | ||
| this.isCurrentNodeStopNode = false; // Reset flag | ||
| i = result.closeIndex; | ||
@@ -456,6 +592,6 @@ // Continue to next iteration without changing currentNode | ||
| if (tagName !== tagExp && attrExpPresent) { | ||
| childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName); | ||
| if (prefixedAttrs) { | ||
| childNode[":@"] = prefixedAttrs; | ||
| } | ||
| this.addChild(currentNode, childNode, jPath, startIndex); | ||
| this.addChild(currentNode, childNode, this.matcher, startIndex); | ||
| currentNode = childNode; | ||
@@ -474,6 +610,9 @@ } | ||
| function addChild(currentNode, childNode, jPath, startIndex) { | ||
| function addChild(currentNode, childNode, matcher, startIndex) { | ||
| // unset startIndex if not requested | ||
| if (!this.options.captureMetaData) startIndex = undefined; | ||
| const result = this.options.updateTag(childNode.tagname, jPath, childNode[":@"]) | ||
| // Pass jPath string or matcher based on options.jPath setting | ||
| const jPathOrMatcher = this.options.jPath ? matcher.toString() : matcher; | ||
| const result = this.options.updateTag(childNode.tagname, jPathOrMatcher, childNode[":@"]) | ||
| if (result === false) { | ||
@@ -489,23 +628,30 @@ //do nothing | ||
| const replaceEntitiesValue = function (val, tagName, jPath) { | ||
| // Performance optimization: Early return if no entities to replace | ||
| if (val.indexOf('&') === -1) { | ||
| return val; | ||
| } | ||
| /** | ||
| * @param {object} val - Entity object with regex and val properties | ||
| * @param {string} tagName - Tag name | ||
| * @param {string|Matcher} jPath - jPath string or Matcher instance based on options.jPath | ||
| */ | ||
| function replaceEntitiesValue(val, tagName, jPath) { | ||
| const entityConfig = this.options.processEntities; | ||
| if (!entityConfig.enabled) { | ||
| if (!entityConfig || !entityConfig.enabled) { | ||
| return val; | ||
| } | ||
| // Check tag-specific filtering | ||
| // Check if tag is allowed to contain entities | ||
| if (entityConfig.allowedTags) { | ||
| if (!entityConfig.allowedTags.includes(tagName)) { | ||
| return val; // Skip entity replacement for current tag as not set | ||
| const jPathOrMatcher = this.options.jPath ? jPath.toString() : jPath; | ||
| const allowed = Array.isArray(entityConfig.allowedTags) | ||
| ? entityConfig.allowedTags.includes(tagName) | ||
| : entityConfig.allowedTags(tagName, jPathOrMatcher); | ||
| if (!allowed) { | ||
| return val; | ||
| } | ||
| } | ||
| // Apply custom tag filter if provided | ||
| if (entityConfig.tagFilter) { | ||
| if (!entityConfig.tagFilter(tagName, jPath)) { | ||
| const jPathOrMatcher = this.options.jPath ? jPath.toString() : jPath; | ||
| if (!entityConfig.tagFilter(tagName, jPathOrMatcher)) { | ||
| return val; // Skip based on custom filter | ||
@@ -572,3 +718,3 @@ } | ||
| function saveTextToParentTag(textData, parentNode, jPath, isLeafNode) { | ||
| function saveTextToParentTag(textData, parentNode, matcher, isLeafNode) { | ||
| if (textData) { //store previously collected data as textNode | ||
@@ -579,3 +725,3 @@ if (isLeafNode === undefined) isLeafNode = parentNode.child.length === 0 | ||
| parentNode.tagname, | ||
| jPath, | ||
| matcher, | ||
| false, | ||
@@ -594,10 +740,13 @@ parentNode[":@"] ? Object.keys(parentNode[":@"]).length !== 0 : false, | ||
| /** | ||
| * @param {Set} stopNodesExact | ||
| * @param {Set} stopNodesWildcard | ||
| * @param {string} jPath | ||
| * @param {string} currentTagName | ||
| * @param {Array<Expression>} stopNodeExpressions - Array of compiled Expression objects | ||
| * @param {Matcher} matcher - Current path matcher | ||
| */ | ||
| function isItStopNode(stopNodesExact, stopNodesWildcard, jPath, currentTagName) { | ||
| if (stopNodesWildcard && stopNodesWildcard.has(currentTagName)) return true; | ||
| if (stopNodesExact && stopNodesExact.has(jPath)) return true; | ||
| function isItStopNode(stopNodeExpressions, matcher) { | ||
| if (!stopNodeExpressions || stopNodeExpressions.length === 0) return false; | ||
| for (let i = 0; i < stopNodeExpressions.length; i++) { | ||
| if (matcher.matches(stopNodeExpressions[i])) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
@@ -604,0 +753,0 @@ } |
@@ -38,3 +38,3 @@ import { buildOptions } from './OptionsBuilder.js'; | ||
| if (this.options.preserveOrder || orderedResult === undefined) return orderedResult; | ||
| else return prettify(orderedResult, this.options); | ||
| else return prettify(orderedResult, this.options, orderedObjParser.matcher); | ||
| } | ||
@@ -41,0 +41,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
835432
36.75%4596
7.41%226
0.44%3
50%46
48.39%- Removed