Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

moddle-xml

Package Overview
Dependencies
Maintainers
9
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

moddle-xml - npm Package Compare versions

Comparing version 9.0.5 to 9.0.6

5

CHANGELOG.md

@@ -9,5 +9,10 @@ # Changelog

## 9.0.6
* `FIX`: correctly handle duplicated attributes ([#66](https://github.com/bpmn-io/moddle-xml/issues/66))
## 9.0.5
* `FIX`: correct serialization of `xml` namespace attributes on `Any` elements ([#60](https://github.com/bpmn-io/moddle-xml/issues/60))
* `FIX`: do not trim non-empty element text ([#58](https://github.com/bpmn-io/moddle-xml/issues/58))

@@ -14,0 +19,0 @@ ## 9.0.4

20

dist/index.esm.js

@@ -1,2 +0,2 @@

import { forEach, assign, find, filter, has, isString } from 'min-dash';
import { forEach, assign, find, filter, has, isString, findIndex } from 'min-dash';
import { Parser } from 'saxen';

@@ -1605,3 +1605,19 @@ import { coerceType, parseNameNS, isSimpleType, Moddle } from 'moddle';

attrs.push({ name: name, value: value });
// de-duplicate attributes
// https://github.com/bpmn-io/moddle-xml/issues/66
var idx = findIndex(attrs, function(element) {
return (
element.name.localName === name.localName &&
element.name.uri === name.uri &&
element.name.prefix === name.prefix
);
});
var attr = { name: name, value: value };
if (idx !== -1) {
attrs.splice(idx, 1, attr);
} else {
attrs.push(attr);
}
};

@@ -1608,0 +1624,0 @@

@@ -1609,3 +1609,19 @@ 'use strict';

attrs.push({ name: name, value: value });
// de-duplicate attributes
// https://github.com/bpmn-io/moddle-xml/issues/66
var idx = minDash.findIndex(attrs, function(element) {
return (
element.name.localName === name.localName &&
element.name.uri === name.uri &&
element.name.prefix === name.prefix
);
});
var attr = { name: name, value: value };
if (idx !== -1) {
attrs.splice(idx, 1, attr);
} else {
attrs.push(attr);
}
};

@@ -1612,0 +1628,0 @@

2

dist/moddle-xml.umd.prod.js

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ModdleXML={})}(this,(function(e){"use strict";var t=Object.prototype.toString,n=Object.prototype.hasOwnProperty;function r(e){return"[object String]"===t.call(e)}function i(e,t){return n.call(e,t)}function o(e,n){var r;return n=function(e){return n=e,r=t.call(n),"[object Function]"===r||"[object AsyncFunction]"===r||"[object GeneratorFunction]"===r||"[object AsyncGeneratorFunction]"===r||"[object Proxy]"===r?e:function(t){return t===e};var n,r}(n),a(e,(function(e,t){if(n(e,t))return r=e,!1})),r}function s(e,t){var n=[];return a(e,(function(e,r){t(e,r)&&n.push(e)})),n}function a(e,n){var r;if(void 0!==e){var o=function(e){return"[object Array]"===t.call(e)}(e)?u:p;for(var s in e)if(i(e,s)&&!1===n(r=e[s],o(s)))return r}}function p(e){return e}function u(e){return Number(e)}function c(e,t){return e.bind(t)}function f(){return(f=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function l(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return f.apply(void 0,[e].concat(n))}var d=String.fromCharCode,h=Object.prototype.hasOwnProperty,m=/&#(\d+);|&#x([0-9a-f]+);|&(\w+);/gi,y={amp:"&",apos:"'",gt:">",lt:"<",quot:'"'};function g(e,t,n,r){return r?h.call(y,r)?y[r]:"&"+r+";":d(t||parseInt(n,16))}function b(e){return e.length>3&&-1!==e.indexOf("&")?e.replace(m,g):e}Object.keys(y).forEach((function(e){y[e.toUpperCase()]=y[e]}));var v="xsi:type",x="non-whitespace outside of root node";function N(e){return new Error(e)}function w(e){return"missing namespace for prefix <"+e+">"}function P(e){return{get:e,enumerable:!0}}function T(e){var t,n={};for(t in e)n[t]=e[t];return n}function O(e){return e+"$uri"}function A(){return{line:0,column:0}}function k(e){throw e}function E(e){if(!this)return new E(e);var t,n,r,i,o,s,a,p,u,c=e&&e.proxy,f=k,l=A,d=!1,h=!1,m=null,y=!1;function g(e){e instanceof Error||(e=N(e)),m=e,f(e,l)}function $(e){o&&(e instanceof Error||(e=N(e)),o(e,l))}this.on=function(e,u){if("function"!=typeof u)throw N("required args <name, cb>");switch(e){case"openTag":n=u;break;case"text":t=u;break;case"closeTag":r=u;break;case"error":f=u;break;case"warn":o=u;break;case"cdata":i=u;break;case"attention":p=u;break;case"question":a=u;break;case"comment":s=u;break;default:throw N("unsupported event: "+e)}return this},this.ns=function(e){if(void 0===e&&(e={}),"object"!=typeof e)throw N("required args <nsMap={}>");var t,n={};for(t in e)n[t]=e[t];return n["http://www.w3.org/2001/XMLSchema-instance"]="xsi",h=!0,u=n,this},this.parse=function(e){if("string"!=typeof e)throw N("required args <xml=string>");return m=null,function(e){var o,f,m,N,A,k,E,j,B,C,M,D=h?[]:null,U=h?function(e){var t,n,r={};for(t in e)r[n=e[t]]=n,r[O(n)]=t;return r}(u):null,I=[],R=0,L=!1,z=!1,S=0,q=0,F="",G=0;function X(){if(null!==M)return M;var e,t,n,r,i,o,s,a,p,c,f,l=h&&U.xmlns,m=h&&d?[]:null,y=G,g=F,x=g.length,N={},P={};e:for(;y<x;y++)if(p=!1,!(32===(c=g.charCodeAt(y))||c<14&&c>8)){for((c<65||c>122||c>90&&c<97)&&95!==c&&58!==c&&($("illegal first char attribute name"),p=!0),f=y+1;f<x;f++)if(!((c=g.charCodeAt(f))>96&&c<123||c>64&&c<91||c>47&&c<59||46===c||45===c||95===c)){if(32===c||c<14&&c>8){$("missing attribute value"),y=f;continue e}if(61===c)break;$("illegal attribute name char"),p=!0}if("xmlns:xmlns"===(a=g.substring(y,f))&&($("illegal declaration of xmlns"),p=!0),34===(c=g.charCodeAt(f+1)))-1===(f=g.indexOf('"',y=f+2))&&-1!==(f=g.indexOf("'",y))&&($("attribute value quote missmatch"),p=!0);else if(39===c)-1===(f=g.indexOf("'",y=f+2))&&-1!==(f=g.indexOf('"',y))&&($("attribute value quote missmatch"),p=!0);else for($("missing attribute value quotes"),p=!0,f+=1;f<x&&!(32===(c=g.charCodeAt(f+1))||c<14&&c>8);f++);for(-1===f&&($("missing closing quotes"),f=x,p=!0),p||(o=g.substring(y,f)),y=f;f+1<x&&!(32===(c=g.charCodeAt(f+1))||c<14&&c>8);f++)y===f&&($("illegal character after attribute end"),p=!0);if(y=f+1,!p)if(a in P)$("attribute <"+a+"> already defined");else if(P[a]=!0,h)if(d){if(null!==(i="xmlns"===a?"xmlns":120===a.charCodeAt(0)&&"xmlns:"===a.substr(0,6)?a.substr(6):null)){if(e=b(o),t=O(i),!(s=u[e])){if("xmlns"===i||t in U&&U[t]!==e)do{s="ns"+R++}while(void 0!==U[s]);else s=i;u[e]=s}U[i]!==s&&(r||(U=T(U),r=!0),U[i]=s,"xmlns"===i&&(U[O(s)]=e,l=s),U[t]=e),N[a]=o;continue}m.push(a,o)}else-1!==(c=a.indexOf(":"))?(n=U[a.substring(0,c)])?((a=l===n?a.substr(c+1):n+a.substr(c))===v&&(-1!==(c=o.indexOf(":"))?(n=o.substring(0,c),o=(n=U[n]||n)+o.substring(c)):o=l+":"+o),N[a]=o):$(w(a.substring(0,c))):N[a]=o;else N[a]=o}if(d)for(y=0,x=m.length;y<x;y++){if(a=m[y++],o=m[y],-1!==(c=a.indexOf(":"))){if(!(n=U[a.substring(0,c)])){$(w(a.substring(0,c)));continue}(a=l===n?a.substr(c+1):n+a.substr(c))===v&&(-1!==(c=o.indexOf(":"))?(n=o.substring(0,c),o=(n=U[n]||n)+o.substring(c)):o=l+":"+o)}N[a]=o}return M=N}function H(){for(var t,n,r=/(\r\n|\r|\n)/g,i=0,o=0,s=0,a=q;S>=s&&(t=r.exec(e))&&!((a=t[0].length+t.index)>S);)i+=1,s=a;return-1==S?(o=a,n=e.substring(q)):0===q?n=e.substring(q,S):(o=S-s,n=-1==q?e.substring(S):e.substring(S,q+1)),{data:n,line:i,column:o}}l=H,c&&(C=Object.create({},{name:P((function(){return j})),originalName:P((function(){return B})),attrs:P(X),ns:P((function(){return U}))}));for(;-1!==q;){if(-1===(S=60===e.charCodeAt(q)?q:e.indexOf("<",q)))return I.length?g("unexpected end of file"):0===q?g("missing start tag"):void(q<e.length&&e.substring(q).trim()&&$(x));if(q!==S)if(I.length){if(t&&(t(e.substring(q,S),b,l),y))return}else if(e.substring(q,S).trim()&&($(x),y))return;if(33===(A=e.charCodeAt(S+1))){if(91===(N=e.charCodeAt(S+2))&&"CDATA["===e.substr(S+3,6)){if(-1===(q=e.indexOf("]]>",S)))return g("unclosed cdata");if(i&&(i(e.substring(S+9,q),l),y))return;q+=3;continue}if(45===N&&45===e.charCodeAt(S+3)){if(-1===(q=e.indexOf("--\x3e",S)))return g("unclosed comment");if(s&&(s(e.substring(S+4,q),b,l),y))return;q+=3;continue}}if(63!==A){for(f=S+1;;f++){if(k=e.charCodeAt(f),isNaN(k))return q=-1,g("unclosed tag");if(34===k)f=-1!==(N=e.indexOf('"',f+1))?N:f;else if(39===k)f=-1!==(N=e.indexOf("'",f+1))?N:f;else if(62===k){q=f;break}}if(33!==A){if(M={},47===A){if(L=!1,z=!0,!I.length)return g("missing open tag");if(f=j=I.pop(),N=S+2+f.length,e.substring(S+2,N)!==f)return g("closing tag mismatch");for(;N<q;N++)if(!(32===(A=e.charCodeAt(N))||A>8&&A<14))return g("close tag")}else{if(47===e.charCodeAt(q-1)?(f=j=e.substring(S+1,q-1),L=!0,z=!0):(f=j=e.substring(S+1,q),L=!0,z=!1),!(A>96&&A<123||A>64&&A<91||95===A||58===A))return g("illegal first char nodeName");for(N=1,m=f.length;N<m;N++)if(!((A=f.charCodeAt(N))>96&&A<123||A>64&&A<91||A>47&&A<59||45===A||95===A||46==A)){if(32===A||A<14&&A>8){j=f.substring(0,N),M=null;break}return g("invalid nodeName")}z||I.push(j)}if(h){if(o=U,L&&(z||D.push(o),null===M&&(d=-1!==f.indexOf("xmlns",N))&&(G=N,F=f,X(),d=!1)),B=j,-1!==(A=j.indexOf(":"))){if(!(E=U[j.substring(0,A)]))return g("missing namespace on <"+B+">");j=j.substr(A+1)}else E=U.xmlns;E&&(j=E+":"+j)}if(L&&(G=N,F=f,n&&(c?n(C,b,z,l):n(j,X,b,z,l),y)))return;if(z){if(r&&(r(c?C:j,b,L,l),y))return;h&&(U=L?o:D.pop())}q+=1}else{if(p&&(p(e.substring(S,q+1),b,l),y))return;q+=1}}else{if(-1===(q=e.indexOf("?>",S)))return g("unclosed question");if(a&&(a(e.substring(S,q+2),l),y))return;q+=2}}}(e),l=A,y=!1,m},this.stop=function(){y=!0}}function $(){}function j(e,t){this.model=e,this.properties=t}$.prototype.get=function(e){return this.$model.properties.get(this,e)},$.prototype.set=function(e,t){this.$model.properties.set(this,e,t)},j.prototype.createType=function(e){var t=this.model,n=this.properties,r=Object.create($.prototype);a(e.properties,(function(e){e.isMany||void 0===e.default||(r[e.name]=e.default)})),n.defineModel(r,t),n.defineDescriptor(r,e);var i=e.ns.name;function o(e){n.define(this,"$type",{value:i,enumerable:!0}),n.define(this,"$attrs",{value:{}}),n.define(this,"$parent",{writable:!0}),a(e,c((function(e,t){this.set(t,e)}),this))}return o.prototype=r,o.hasType=r.$instanceOf=this.model.hasType,n.defineModel(o,t),n.defineDescriptor(o,e),o};var B={String:!0,Boolean:!0,Integer:!0,Real:!0,Element:!0},C={String:function(e){return e},Boolean:function(e){return"true"===e},Integer:function(e){return parseInt(e,10)},Real:function(e){return parseFloat(e)}};function M(e,t){var n=C[e];return n?n(t):t}function D(e){return!!B[e]}function U(e){return!!C[e]}function I(e,t){var n,r,i=e.split(/:/);if(1===i.length)n=e,r=t;else{if(2!==i.length)throw new Error("expected <prefix:localName> or <localName>, got "+e);n=i[1],r=i[0]}return{name:e=(r?r+":":"")+n,prefix:r,localName:n}}function R(e){this.ns=e,this.name=e.name,this.allTypes=[],this.allTypesByName={},this.properties=[],this.propertiesByName={}}function L(e,t){this.packageMap={},this.typeMap={},this.packages=[],this.properties=t,a(e,c(this.registerPackage,this))}function z(e,t,n){var r=t[n];if(r in e)throw new Error("package with "+n+" <"+r+"> already defined")}function S(e){this.model=e}function q(e,t,n){Object.defineProperty(e,t.name,{enumerable:!t.isReference,writable:!0,value:n,configurable:!0})}function F(e){this.properties=new S(this),this.factory=new j(this,this.properties),this.registry=new L(e,this.properties),this.typeCache={}}function G(e){return e.xml&&"lowerCase"===e.xml.tagAlias}R.prototype.build=function(){return e=this,t=["ns","name","allTypes","allTypesByName","properties","propertiesByName","bodyProperty","idProperty"],n={},r=Object(e),a(t,(function(t){t in r&&(n[t]=e[t])})),n;var e,t,n,r},R.prototype.addProperty=function(e,t,n){"boolean"==typeof t&&(n=t,t=void 0),this.addNamedProperty(e,!1!==n);var r=this.properties;void 0!==t?r.splice(t,0,e):r.push(e)},R.prototype.replaceProperty=function(e,t,n){var r=e.ns,i=this.properties,o=this.propertiesByName,s=e.name!==t.name;if(e.isId){if(!t.isId)throw new Error("property <"+t.ns.name+"> must be id property to refine <"+e.ns.name+">");this.setIdProperty(t,!1)}if(e.isBody){if(!t.isBody)throw new Error("property <"+t.ns.name+"> must be body property to refine <"+e.ns.name+">");this.setBodyProperty(t,!1)}var a=i.indexOf(e);if(-1===a)throw new Error("property <"+r.name+"> not found in property list");i.splice(a,1),this.addProperty(t,n?void 0:a,s),o[r.name]=o[r.localName]=t},R.prototype.redefineProperty=function(e,t,n){var r=e.ns.prefix,i=t.split("#"),o=I(i[0],r),s=I(i[1],o.prefix).name,a=this.propertiesByName[s];if(!a)throw new Error("refined property <"+s+"> not found");this.replaceProperty(a,e,n),delete e.redefines},R.prototype.addNamedProperty=function(e,t){var n=e.ns,r=this.propertiesByName;t&&(this.assertNotDefined(e,n.name),this.assertNotDefined(e,n.localName)),r[n.name]=r[n.localName]=e},R.prototype.removeNamedProperty=function(e){var t=e.ns,n=this.propertiesByName;delete n[t.name],delete n[t.localName]},R.prototype.setBodyProperty=function(e,t){if(t&&this.bodyProperty)throw new Error("body property defined multiple times (<"+this.bodyProperty.ns.name+">, <"+e.ns.name+">)");this.bodyProperty=e},R.prototype.setIdProperty=function(e,t){if(t&&this.idProperty)throw new Error("id property defined multiple times (<"+this.idProperty.ns.name+">, <"+e.ns.name+">)");this.idProperty=e},R.prototype.assertNotDefined=function(e,t){var n=e.name,r=this.propertiesByName[n];if(r)throw new Error("property <"+n+"> already defined; override of <"+r.definedBy.ns.name+"#"+r.ns.name+"> by <"+e.definedBy.ns.name+"#"+e.ns.name+"> not allowed without redefines")},R.prototype.hasProperty=function(e){return this.propertiesByName[e]},R.prototype.addTrait=function(e,t){var n=this.allTypesByName,r=this.allTypes,i=e.name;i in n||(a(e.properties,c((function(n){n=l({},n,{name:n.ns.localName,inherited:t}),Object.defineProperty(n,"definedBy",{value:e});var r=n.replaces,i=n.redefines;r||i?this.redefineProperty(n,r||i,r):(n.isBody&&this.setBodyProperty(n),n.isId&&this.setIdProperty(n),this.addProperty(n))}),this)),r.push(e),n[i]=e)},L.prototype.getPackage=function(e){return this.packageMap[e]},L.prototype.getPackages=function(){return this.packages},L.prototype.registerPackage=function(e){e=l({},e);var t=this.packageMap;z(t,e,"prefix"),z(t,e,"uri"),a(e.types,c((function(t){this.registerType(t,e)}),this)),t[e.uri]=t[e.prefix]=e,this.packages.push(e)},L.prototype.registerType=function(e,t){var n=I((e=l({},e,{superClass:(e.superClass||[]).slice(),extends:(e.extends||[]).slice(),properties:(e.properties||[]).slice(),meta:l(e.meta||{})})).name,t.prefix),r=n.name,i={};a(e.properties,c((function(e){var t=I(e.name,n.prefix),r=t.name;D(e.type)||(e.type=I(e.type,t.prefix).name),l(e,{ns:t,name:r}),i[r]=e}),this)),l(e,{ns:n,name:r,propertiesByName:i}),a(e.extends,c((function(e){var t=this.typeMap[e];t.traits=t.traits||[],t.traits.push(r)}),this)),this.definePackage(e,t),this.typeMap[r]=e},L.prototype.mapTypes=function(e,t,n){var r=D(e.name)?{name:e.name}:this.typeMap[e.name],i=this;function o(e){return s(e,!0)}function s(n,r){var o=I(n,D(n)?"":e.prefix);i.mapTypes(o,t,r)}if(!r)throw new Error("unknown type <"+e.name+">");a(r.superClass,n?o:s),t(r,!n),a(r.traits,o)},L.prototype.getEffectiveDescriptor=function(e){var t=I(e),n=new R(t);this.mapTypes(t,(function(e,t){n.addTrait(e,t)}));var r=n.build();return this.definePackage(r,r.allTypes[r.allTypes.length-1].$pkg),r},L.prototype.definePackage=function(e,t){this.properties.define(e,"$pkg",{value:t})},S.prototype.set=function(e,t,n){var r=this.model.getPropertyDescriptor(e,t),i=r&&r.name;void 0===n?r?delete e[i]:delete e.$attrs[t]:r?i in e?e[i]=n:q(e,r,n):e.$attrs[t]=n},S.prototype.get=function(e,t){var n=this.model.getPropertyDescriptor(e,t);if(!n)return e.$attrs[t];var r=n.name;return!e[r]&&n.isMany&&q(e,n,[]),e[r]},S.prototype.define=function(e,t,n){Object.defineProperty(e,t,n)},S.prototype.defineDescriptor=function(e,t){this.define(e,"$descriptor",{value:t})},S.prototype.defineModel=function(e,t){this.define(e,"$model",{value:t})},F.prototype.create=function(e,t){var n=this.getType(e);if(!n)throw new Error("unknown type <"+e+">");return new n(t)},F.prototype.getType=function(e){var t=this.typeCache,n=r(e)?e:e.ns.name,i=t[n];return i||(e=this.registry.getEffectiveDescriptor(n),i=t[n]=this.factory.createType(e)),i},F.prototype.createAny=function(e,n,r){var i=I(e),o={$type:e,$instanceOf:function(e){return e===this.$type}},s={name:e,isGeneric:!0,ns:{prefix:i.prefix,localName:i.localName,uri:n}};return this.properties.defineDescriptor(o,s),this.properties.defineModel(o,this),this.properties.define(o,"$parent",{enumerable:!1,writable:!0}),this.properties.define(o,"$instanceOf",{enumerable:!1,writable:!0}),a(r,(function(e,n){var r;r=e,"[object Object]"===t.call(r)&&void 0!==e.value?o[e.name]=e.value:o[n]=e})),o},F.prototype.getPackage=function(e){return this.registry.getPackage(e)},F.prototype.getPackages=function(){return this.registry.getPackages()},F.prototype.getElementDescriptor=function(e){return e.$descriptor},F.prototype.hasType=function(e,t){return void 0===t&&(t=e,e=this),t in e.$model.getElementDescriptor(e).allTypesByName},F.prototype.getPropertyDescriptor=function(e,t){return this.getElementDescriptor(e).propertiesByName[t]},F.prototype.getTypeDescriptor=function(e){return this.registry.typeMap[e]};var X={xsi:"http://www.w3.org/2001/XMLSchema-instance",xml:"http://www.w3.org/XML/1998/namespace"},H="xsi:type";function W(e){return e.xml&&e.xml.serialize}function _(e){return W(e)===H}function V(e,t){return G(t)?e.prefix+":"+((n=e.localName).charAt(0).toUpperCase()+n.slice(1)):e.name;var n}function K(e){return new Error(e)}function J(e){return e.$descriptor}function Q(e){l(this,e),this.elementsById={},this.references=[],this.warnings=[],this.addReference=function(e){this.references.push(e)},this.addElement=function(e){if(!e)throw K("expected element");var t,n=this.elementsById,r=J(e).idProperty;if(r&&(t=e.get(r.name))){if(!/^([a-z][\w-.]*:)?[a-z_][\w-.]*$/i.test(t))throw new Error("illegal ID <"+t+">");if(n[t])throw K("duplicate ID <"+t+">");n[t]=e}},this.addWarning=function(e){this.warnings.push(e)}}function Y(){}function Z(){}function ee(){}function te(e,t){this.property=e,this.context=t}function ne(e,t){this.element=t,this.propertyDesc=e}function re(){}function ie(e,t,n){this.model=e,this.type=e.getType(t),this.context=n}function oe(e,t,n){ie.call(this,e,t,n)}function se(e,t,n){this.model=e,this.context=n}function ae(e){e instanceof F&&(e={model:e}),l(this,{lax:!1},e)}Y.prototype.handleEnd=function(){},Y.prototype.handleText=function(){},Y.prototype.handleNode=function(){},Z.prototype=Object.create(Y.prototype),Z.prototype.handleNode=function(){return this},ee.prototype=Object.create(Y.prototype),ee.prototype.handleText=function(e){this.body=(this.body||"")+e},te.prototype=Object.create(ee.prototype),te.prototype.handleNode=function(e){if(this.element)throw K("expected no sub nodes");return this.element=this.createReference(e),this},te.prototype.handleEnd=function(){this.element.id=this.body},te.prototype.createReference=function(e){return{property:this.property.ns.name,id:""}},ne.prototype=Object.create(ee.prototype),ne.prototype.handleEnd=function(){var e=this.body||"",t=this.element,n=this.propertyDesc;e=M(n.type,e),n.isMany?t.get(n.name).push(e):t.set(n.name,e)},re.prototype=Object.create(ee.prototype),re.prototype.handleNode=function(e){var t=this,n=this.element;return n?t=this.handleChild(e):(n=this.element=this.createElement(e),this.context.addElement(n)),t},ie.prototype=Object.create(re.prototype),ie.prototype.addReference=function(e){this.context.addReference(e)},ie.prototype.handleText=function(e){if(!J(this.element).bodyProperty)throw K("unexpected body text <"+e+">");ee.prototype.handleText.call(this,e)},ie.prototype.handleEnd=function(){var e=this.body,t=this.element,n=J(t).bodyProperty;n&&void 0!==e&&(e=M(n.type,e),t.set(n.name,e))},ie.prototype.createElement=function(e){var t,n=e.attributes,r=this.type,i=J(r),o=this.context,s=new r({}),p=this.model;return a(n,(function(e,n){var r=i.propertiesByName[n];r&&r.isReference?r.isMany?a(e.split(" "),(function(e){o.addReference({element:s,property:r.ns.name,id:e})})):o.addReference({element:s,property:r.ns.name,id:e}):(r?e=M(r.type,e):"xmlns"!==n&&(t=I(n,i.ns.prefix),p.getPackage(t.prefix)&&o.addWarning({message:"unknown attribute <"+n+">",element:s,property:n,value:e})),s.set(n,e))})),s},ie.prototype.getPropertyForNode=function(e){var t,n,r=I(e.name),i=this.type,s=this.model,a=J(i),p=r.name,u=a.propertiesByName[p];if(u&&!u.isAttr)return _(u)&&(t=e.attributes[H])?(t=function(e,t){var n=I(e);return function(e,t){var n=e.name,r=e.localName,i=t.xml&&t.xml.typePrefix;return i&&0===r.indexOf(i)?e.prefix+":"+r.slice(i.length):n}(n,t.getPackage(n.prefix))}(t,s),l({},u,{effectiveType:J(n=s.getType(t)).name})):u;var c=s.getPackage(r.prefix);if(c){if(t=V(r,c),n=s.getType(t),u=o(a.properties,(function(e){return!e.isVirtual&&!e.isReference&&!e.isAttribute&&n.hasType(e.type)})))return l({},u,{effectiveType:J(n).name})}else if(u=o(a.properties,(function(e){return!e.isReference&&!e.isAttribute&&"Element"===e.type})))return u;throw K("unrecognized element <"+r.name+">")},ie.prototype.toString=function(){return"ElementDescriptor["+J(this.type).name+"]"},ie.prototype.valueHandler=function(e,t){return new ne(e,t)},ie.prototype.referenceHandler=function(e){return new te(e,this.context)},ie.prototype.handler=function(e){return"Element"===e?new se(this.model,e,this.context):new ie(this.model,e,this.context)},ie.prototype.handleChild=function(e){var t,n,r,i;if(t=this.getPropertyForNode(e),r=this.element,U(n=t.effectiveType||t.type))return this.valueHandler(t,r);var o=(i=t.isReference?this.referenceHandler(t).handleNode(e):this.handler(n).handleNode(e)).element;return void 0!==o&&(t.isMany?r.get(t.name).push(o):r.set(t.name,o),t.isReference?(l(o,{element:r}),this.context.addReference(o)):o.$parent=r),i},oe.prototype=Object.create(ie.prototype),oe.prototype.createElement=function(e){var t=e.name,n=I(t),r=this.model,i=this.type,o=r.getPackage(n.prefix),s=o&&V(n,o)||t;if(!i.hasType(s))throw K("unexpected element <"+e.originalName+">");return ie.prototype.createElement.call(this,e)},se.prototype=Object.create(re.prototype),se.prototype.createElement=function(e){var t=e.name,n=I(t).prefix,r=e.ns[n+"$uri"],i=e.attributes;return this.model.createAny(t,r,i)},se.prototype.handleChild=function(e){var t=new se(this.model,"Element",this.context).handleNode(e),n=this.element,r=t.element;return void 0!==r&&((n.$children=n.$children||[]).push(r),r.$parent=n),t},se.prototype.handleEnd=function(){this.body&&(this.element.$body=this.body)},ae.prototype.fromXML=function(e,t,n){var r=t.rootHandler;t instanceof ie?(r=t,t={}):"string"==typeof t?(r=this.handler(t),t={}):"string"==typeof r&&(r=this.handler(r));var i=this.model,o=this.lax,s=new Q(l({},t,{rootHandler:r})),a=new E({proxy:!0}),p=function(){var e=[];return Object.defineProperty(e,"peek",{value:function(){return this[this.length-1]}}),e}();function u(e,t,n){var r=t(),i=r.line,o=r.column,a=r.data;"<"===a.charAt(0)&&-1!==a.indexOf(" ")&&(a=a.slice(0,a.indexOf(" "))+">");var p="unparsable content "+(a?a+" ":"")+"detected\n\tline: "+i+"\n\tcolumn: "+o+"\n\tnested error: "+e.message;if(n)return s.addWarning({message:p,error:e}),!0;throw K(p)}function c(e,t){return u(e,t,!0)}r.context=s,p.push(r);var f=/^<\?xml /i,d=/ encoding="([^"]+)"/i,h=/^utf-8$/i;function m(e,t){try{p.peek().handleText(e)}catch(e){c(e,t)}}var y=i.getPackages().reduce((function(e,t){return e[t.uri]=t.prefix,e}),{"http://www.w3.org/XML/1998/namespace":"xml"});return a.ns(y).on("openTag",(function(e,t,n,r){var i=e.attrs||{},s=Object.keys(i).reduce((function(e,n){var r=t(i[n]);return e[n]=r,e}),{});!function(e,t){var n=p.peek();try{p.push(n.handleNode(e))}catch(e){u(e,t,o)&&p.push(new Z)}}({name:e.name,originalName:e.originalName,attributes:s,ns:e.ns},r)})).on("question",(function(e){if(f.test(e)){var t=d.exec(e),n=t&&t[1];n&&!h.test(n)&&s.addWarning({message:"unsupported document encoding <"+n+">, falling back to UTF-8"})}})).on("closeTag",(function(){p.pop().handleEnd()})).on("cdata",m).on("text",(function(e,t,n){!function(e,t){e.trim()&&m(e,t)}(t(e),n)})).on("error",u).on("warn",c),new Promise((function(t,n){var i;try{a.parse(e),function(){var e,t,n=s.elementsById,r=s.references;for(e=0;t=r[e];e++){var i=t.element,o=n[t.id],a=J(i).propertiesByName[t.property];if(o||s.addWarning({message:"unresolved reference <"+t.id+">",element:t.element,property:t.property,value:t.id}),a.isMany){var p=i.get(a.name),u=p.indexOf(t);-1===u&&(u=p.length),o?p[u]=o:p.splice(u,1)}else i.set(a.name,o)}}()}catch(e){i=e}var o=r.element;i||o||(i=K("failed to parse document as <"+r.type.$descriptor.name+">"));var p=s.warnings,u=s.references,c=s.elementsById;return i?(i.warnings=p,n(i)):t({rootElement:o,elementsById:c,references:u,warnings:p})}))},ae.prototype.handler=function(e){return new oe(this.model,e)};var pe=/<|>|'|"|&|\n\r|\n/g,ue=/<|>|&/g;function ce(e){var t={},n={},r={},i=[],o=[];this.byUri=function(t){return n[t]||e&&e.byUri(t)},this.add=function(e,t){n[e.uri]=e,t?i.push(e):o.push(e),this.mapPrefix(e.prefix,e.uri)},this.uriByPrefix=function(e){return t[e||"xmlns"]},this.mapPrefix=function(e,n){t[e||"xmlns"]=n},this.getNSKey=function(e){return void 0!==e.prefix?e.uri+"|"+e.prefix:e.uri},this.logUsed=function(t){var n=t.uri,i=this.getNSKey(t);r[i]=this.byUri(n),e&&e.logUsed(t)},this.getUsed=function(e){var t=this;return[].concat(i,o).filter((function(e){var n=t.getNSKey(e);return r[n]}))}}function fe(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}function le(e){return r(e)?e:(e.prefix?e.prefix+":":"")+e.localName}var de={"\n":"#10","\n\r":"#10",'"':"#34","'":"#39","<":"#60",">":"#62","&":"#38"},he={"<":"lt",">":"gt","&":"amp"};function me(e,t,n){return(e=r(e)?e:""+e).replace(t,(function(e){return"&"+n[e]+";"}))}function ye(e){this.tagName=e}function ge(){}function be(e){this.tagName=e}function ve(e,t){this.body=[],this.attrs=[],this.parent=e,this.propertyDescriptor=t}function xe(e,t){ve.call(this,e,t)}function Ne(){this.value="",this.write=function(e){this.value+=e}}function we(e,t){var n=[""];this.append=function(t){return e.write(t),this},this.appendNewLine=function(){return t&&e.write("\n"),this},this.appendIndent=function(){return t&&e.write(n.join(" ")),this},this.indent=function(){return n.push(""),this},this.unindent=function(){return n.pop(),this}}ye.prototype.build=function(e){return this.element=e,this},ye.prototype.serializeTo=function(e){e.appendIndent().append("<"+this.tagName+">"+this.element.id+"</"+this.tagName+">").appendNewLine()},ge.prototype.serializeValue=ge.prototype.serializeTo=function(e){e.append(this.escape?me(this.value,ue,he):this.value)},ge.prototype.build=function(e,t){return this.value=t,"String"===e.type&&-1!==t.search(ue)&&(this.escape=!0),this},fe(be,ge),be.prototype.serializeTo=function(e){e.appendIndent().append("<"+this.tagName+">"),this.serializeValue(e),e.append("</"+this.tagName+">").appendNewLine()},ve.prototype.build=function(e){this.element=e;var t,n,r=e.$descriptor,o=this.propertyDescriptor,a=r.isGeneric;return t=a?this.parseGeneric(e):this.parseNsAttributes(e),this.ns=o?this.nsPropertyTagName(o):this.nsTagName(r),this.tagName=this.addTagName(this.ns),a||(n=function(e){return s(e.$descriptor.properties,(function(t){var n=t.name;if(t.isVirtual)return!1;if(!i(e,n))return!1;var r=e[n];return r!==t.default&&null!==r&&(!t.isMany||r.length)}))}(e),this.parseAttributes(s(n,(function(e){return e.isAttr}))),this.parseContainments(function(e){return s(e,(function(e){return!e.isAttr}))}(n))),this.parseGenericAttributes(e,t),this},ve.prototype.nsTagName=function(e){return function(e,t){return t.isGeneric?l({localName:t.ns.localName},e):l({localName:(n=t.ns.localName,r=t.$pkg,G(r)?(i=n).charAt(0).toLowerCase()+i.slice(1):n)},e);var n,r,i}(this.logNamespaceUsed(e.ns),e)},ve.prototype.nsPropertyTagName=function(e){return function(e,t){return l({localName:t.ns.localName},e)}(this.logNamespaceUsed(e.ns),e)},ve.prototype.isLocalNs=function(e){return e.uri===this.ns.uri},ve.prototype.nsAttributeName=function(e){var t;if(t=r(e)?I(e):e.ns,e.inherited)return{localName:t.localName};var n=this.logNamespaceUsed(t);return this.getNamespaces().logUsed(n),this.isLocalNs(n)?{localName:t.localName}:l({localName:t.localName},n)},ve.prototype.parseGeneric=function(e){var t=this,n=this.body,r=[];return a(e,(function(i,o){"$body"===o?n.push((new ge).build({type:"String"},i)):"$children"===o?a(i,(function(e){n.push(new ve(t).build(e))})):0!==o.indexOf("$")&&t.parseNsAttribute(e,o,i)&&r.push({name:o,value:i})})),r},ve.prototype.parseNsAttribute=function(e,t,n){var r,i=e.$model,o=I(t);if("xmlns"===o.prefix&&(r={prefix:o.localName,uri:n}),o.prefix||"xmlns"!==o.localName||(r={uri:n}),!r)return{name:t,value:n};if(i&&i.getPackage(n))this.logNamespace(r,!0,!0);else{var s=this.logNamespaceUsed(r,!0);this.getNamespaces().logUsed(s)}},ve.prototype.parseNsAttributes=function(e,t){var n=this,r=e.$attrs,i=[];return a(r,(function(t,r){var o=n.parseNsAttribute(e,r,t);o&&i.push(o)})),i},ve.prototype.parseGenericAttributes=function(e,t){var n=this;a(t,(function(t){if(t.name!==H)try{n.addAttribute(n.nsAttributeName(t.name),t.value)}catch(n){console.warn("missing namespace information for ",t.name,"=",t.value,"on",e,n)}}))},ve.prototype.parseContainments=function(e){var t=this,n=this.body,r=this.element;a(e,(function(e){var i=r.get(e.name),o=e.isReference;if(e.isMany||(i=[i]),e.isBody)n.push((new ge).build(e,i[0]));else if(U(e.type))a(i,(function(r){n.push(new be(t.addTagName(t.nsPropertyTagName(e))).build(e,r))}));else if(o)a(i,(function(r){n.push(new ye(t.addTagName(t.nsPropertyTagName(e))).build(r))}));else{var s=_(e),p=function(e){return"property"===W(e)}(e);a(i,(function(r){var i;i=s?new xe(t,e):p?new ve(t,e):new ve(t),n.push(i.build(r))}))}}))},ve.prototype.getNamespaces=function(e){var t,n=this.namespaces,r=this.parent;return n||(t=r&&r.getNamespaces(),e||!t?this.namespaces=n=new ce(t):n=t),n},ve.prototype.logNamespace=function(e,t,n){var r=this.getNamespaces(n),i=e.uri,o=e.prefix;return r.byUri(i)&&!n||r.add(e,t),r.mapPrefix(o,i),e},ve.prototype.logNamespaceUsed=function(e,t){var n,r,i,o=this.element.$model,s=this.getNamespaces(t),a=e.prefix,p=e.uri;if(!a&&!p)return{localName:e.localName};if(i=X[a]||o&&(o.getPackage(a)||{}).uri,!(p=p||i||s.uriByPrefix(a)))throw new Error("no namespace uri given for prefix <"+a+">");if(!(e=s.byUri(p))){for(n=a,r=1;s.uriByPrefix(n);)n=a+"_"+r++;e=this.logNamespace({prefix:n,uri:p},i===p)}return a&&s.mapPrefix(a,p),e},ve.prototype.parseAttributes=function(e){var t=this,n=this.element;a(e,(function(e){var r=n.get(e.name);if(e.isReference)if(e.isMany){var i=[];a(r,(function(e){i.push(e.id)})),r=i.join(" ")}else r=r.id;t.addAttribute(t.nsAttributeName(e),r)}))},ve.prototype.addTagName=function(e){var t=this.logNamespaceUsed(e);return this.getNamespaces().logUsed(t),le(e)},ve.prototype.addAttribute=function(e,t){var n=this.attrs;r(t)&&(t=me(t,pe,de)),n.push({name:e,value:t})},ve.prototype.serializeAttributes=function(e){var t=this.attrs,n=this.namespaces;n&&(t=function(e){return e.getUsed().filter((function(e){return"xml"!==e.prefix})).map((function(e){return{name:"xmlns"+(e.prefix?":"+e.prefix:""),value:e.uri}}))}(n).concat(t)),a(t,(function(t){e.append(" ").append(le(t.name)).append('="').append(t.value).append('"')}))},ve.prototype.serializeTo=function(e){var t=this.body[0],n=t&&t.constructor!==ge;e.appendIndent().append("<"+this.tagName),this.serializeAttributes(e),e.append(t?">":" />"),t&&(n&&e.appendNewLine().indent(),a(this.body,(function(t){t.serializeTo(e)})),n&&e.unindent().appendIndent(),e.append("</"+this.tagName+">")),e.appendNewLine()},fe(xe,ve),xe.prototype.parseNsAttributes=function(e){var t=ve.prototype.parseNsAttributes.call(this,e),n=e.$descriptor;if(n.name===this.propertyDescriptor.type)return t;var r=this.typeNs=this.nsTagName(n);this.getNamespaces().logUsed(this.typeNs);var i=e.$model.getPackage(r.uri),o=i.xml&&i.xml.typePrefix||"";return this.addAttribute(this.nsAttributeName(H),(r.prefix?r.prefix+":":"")+o+n.ns.localName),t},xe.prototype.isLocalNs=function(e){return e.uri===(this.typeNs||this.ns).uri},e.Reader=ae,e.Writer=function(e){return e=l({format:!1,preamble:!0},e||{}),{toXML:function(t,n){var r=n||new Ne,i=new we(r,e.format);if(e.preamble&&i.append('<?xml version="1.0" encoding="UTF-8"?>\n'),(new ve).build(t).serializeTo(i),!n)return r.value}}},Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ModdleXML={})}(this,(function(e){"use strict";var t=Object.prototype.toString,n=Object.prototype.hasOwnProperty;function r(e){return"[object Array]"===t.call(e)}function i(e){return"[object String]"===t.call(e)}function o(e,t){return n.call(e,t)}function s(e,t){var n;return t=u(t),p(e,(function(e,r){if(t(e,r))return n=e,!1})),n}function a(e,t){var n=[];return p(e,(function(e,r){t(e,r)&&n.push(e)})),n}function p(e,t){var n;if(void 0!==e){var i=r(e)?f:c;for(var s in e)if(o(e,s)&&!1===t(n=e[s],i(s)))return n}}function u(e){return n=e,"[object Function]"===(r=t.call(n))||"[object AsyncFunction]"===r||"[object GeneratorFunction]"===r||"[object AsyncGeneratorFunction]"===r||"[object Proxy]"===r?e:function(t){return t===e};var n,r}function c(e){return e}function f(e){return Number(e)}function l(e,t){return e.bind(t)}function d(){return(d=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function h(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return d.apply(void 0,[e].concat(n))}var m=String.fromCharCode,y=Object.prototype.hasOwnProperty,g=/&#(\d+);|&#x([0-9a-f]+);|&(\w+);/gi,v={amp:"&",apos:"'",gt:">",lt:"<",quot:'"'};function b(e,t,n,r){return r?y.call(v,r)?v[r]:"&"+r+";":m(t||parseInt(n,16))}function x(e){return e.length>3&&-1!==e.indexOf("&")?e.replace(g,b):e}Object.keys(v).forEach((function(e){v[e.toUpperCase()]=v[e]}));var N="xsi:type",w="non-whitespace outside of root node";function P(e){return new Error(e)}function T(e){return"missing namespace for prefix <"+e+">"}function O(e){return{get:e,enumerable:!0}}function A(e){var t,n={};for(t in e)n[t]=e[t];return n}function k(e){return e+"$uri"}function E(){return{line:0,column:0}}function $(e){throw e}function j(e){if(!this)return new j(e);var t,n,r,i,o,s,a,p,u,c=e&&e.proxy,f=$,l=E,d=!1,h=!1,m=null,y=!1;function g(e){e instanceof Error||(e=P(e)),m=e,f(e,l)}function v(e){o&&(e instanceof Error||(e=P(e)),o(e,l))}this.on=function(e,u){if("function"!=typeof u)throw P("required args <name, cb>");switch(e){case"openTag":n=u;break;case"text":t=u;break;case"closeTag":r=u;break;case"error":f=u;break;case"warn":o=u;break;case"cdata":i=u;break;case"attention":p=u;break;case"question":a=u;break;case"comment":s=u;break;default:throw P("unsupported event: "+e)}return this},this.ns=function(e){if(void 0===e&&(e={}),"object"!=typeof e)throw P("required args <nsMap={}>");var t,n={};for(t in e)n[t]=e[t];return n["http://www.w3.org/2001/XMLSchema-instance"]="xsi",h=!0,u=n,this},this.parse=function(e){if("string"!=typeof e)throw P("required args <xml=string>");return m=null,function(e){var o,f,m,b,P,E,$,j,B,C,M,D=h?[]:null,U=h?function(e){var t,n,r={};for(t in e)r[n=e[t]]=n,r[k(n)]=t;return r}(u):null,I=[],R=0,L=!1,z=!1,S=0,q=0,F="",G=0;function X(){if(null!==M)return M;var e,t,n,r,i,o,s,a,p,c,f,l=h&&U.xmlns,m=h&&d?[]:null,y=G,g=F,b=g.length,w={},P={};e:for(;y<b;y++)if(p=!1,!(32===(c=g.charCodeAt(y))||c<14&&c>8)){for((c<65||c>122||c>90&&c<97)&&95!==c&&58!==c&&(v("illegal first char attribute name"),p=!0),f=y+1;f<b;f++)if(!((c=g.charCodeAt(f))>96&&c<123||c>64&&c<91||c>47&&c<59||46===c||45===c||95===c)){if(32===c||c<14&&c>8){v("missing attribute value"),y=f;continue e}if(61===c)break;v("illegal attribute name char"),p=!0}if("xmlns:xmlns"===(a=g.substring(y,f))&&(v("illegal declaration of xmlns"),p=!0),34===(c=g.charCodeAt(f+1)))-1===(f=g.indexOf('"',y=f+2))&&-1!==(f=g.indexOf("'",y))&&(v("attribute value quote missmatch"),p=!0);else if(39===c)-1===(f=g.indexOf("'",y=f+2))&&-1!==(f=g.indexOf('"',y))&&(v("attribute value quote missmatch"),p=!0);else for(v("missing attribute value quotes"),p=!0,f+=1;f<b&&!(32===(c=g.charCodeAt(f+1))||c<14&&c>8);f++);for(-1===f&&(v("missing closing quotes"),f=b,p=!0),p||(o=g.substring(y,f)),y=f;f+1<b&&!(32===(c=g.charCodeAt(f+1))||c<14&&c>8);f++)y===f&&(v("illegal character after attribute end"),p=!0);if(y=f+1,!p)if(a in P)v("attribute <"+a+"> already defined");else if(P[a]=!0,h)if(d){if(null!==(i="xmlns"===a?"xmlns":120===a.charCodeAt(0)&&"xmlns:"===a.substr(0,6)?a.substr(6):null)){if(e=x(o),t=k(i),!(s=u[e])){if("xmlns"===i||t in U&&U[t]!==e)do{s="ns"+R++}while(void 0!==U[s]);else s=i;u[e]=s}U[i]!==s&&(r||(U=A(U),r=!0),U[i]=s,"xmlns"===i&&(U[k(s)]=e,l=s),U[t]=e),w[a]=o;continue}m.push(a,o)}else-1!==(c=a.indexOf(":"))?(n=U[a.substring(0,c)])?((a=l===n?a.substr(c+1):n+a.substr(c))===N&&(-1!==(c=o.indexOf(":"))?(n=o.substring(0,c),o=(n=U[n]||n)+o.substring(c)):o=l+":"+o),w[a]=o):v(T(a.substring(0,c))):w[a]=o;else w[a]=o}if(d)for(y=0,b=m.length;y<b;y++){if(a=m[y++],o=m[y],-1!==(c=a.indexOf(":"))){if(!(n=U[a.substring(0,c)])){v(T(a.substring(0,c)));continue}(a=l===n?a.substr(c+1):n+a.substr(c))===N&&(-1!==(c=o.indexOf(":"))?(n=o.substring(0,c),o=(n=U[n]||n)+o.substring(c)):o=l+":"+o)}w[a]=o}return M=w}function H(){for(var t,n,r=/(\r\n|\r|\n)/g,i=0,o=0,s=0,a=q;S>=s&&(t=r.exec(e))&&!((a=t[0].length+t.index)>S);)i+=1,s=a;return-1==S?(o=a,n=e.substring(q)):0===q?n=e.substring(q,S):(o=S-s,n=-1==q?e.substring(S):e.substring(S,q+1)),{data:n,line:i,column:o}}l=H,c&&(C=Object.create({},{name:O((function(){return j})),originalName:O((function(){return B})),attrs:O(X),ns:O((function(){return U}))}));for(;-1!==q;){if(-1===(S=60===e.charCodeAt(q)?q:e.indexOf("<",q)))return I.length?g("unexpected end of file"):0===q?g("missing start tag"):void(q<e.length&&e.substring(q).trim()&&v(w));if(q!==S)if(I.length){if(t&&(t(e.substring(q,S),x,l),y))return}else if(e.substring(q,S).trim()&&(v(w),y))return;if(33===(P=e.charCodeAt(S+1))){if(91===(b=e.charCodeAt(S+2))&&"CDATA["===e.substr(S+3,6)){if(-1===(q=e.indexOf("]]>",S)))return g("unclosed cdata");if(i&&(i(e.substring(S+9,q),l),y))return;q+=3;continue}if(45===b&&45===e.charCodeAt(S+3)){if(-1===(q=e.indexOf("--\x3e",S)))return g("unclosed comment");if(s&&(s(e.substring(S+4,q),x,l),y))return;q+=3;continue}}if(63!==P){for(f=S+1;;f++){if(E=e.charCodeAt(f),isNaN(E))return q=-1,g("unclosed tag");if(34===E)f=-1!==(b=e.indexOf('"',f+1))?b:f;else if(39===E)f=-1!==(b=e.indexOf("'",f+1))?b:f;else if(62===E){q=f;break}}if(33!==P){if(M={},47===P){if(L=!1,z=!0,!I.length)return g("missing open tag");if(f=j=I.pop(),b=S+2+f.length,e.substring(S+2,b)!==f)return g("closing tag mismatch");for(;b<q;b++)if(!(32===(P=e.charCodeAt(b))||P>8&&P<14))return g("close tag")}else{if(47===e.charCodeAt(q-1)?(f=j=e.substring(S+1,q-1),L=!0,z=!0):(f=j=e.substring(S+1,q),L=!0,z=!1),!(P>96&&P<123||P>64&&P<91||95===P||58===P))return g("illegal first char nodeName");for(b=1,m=f.length;b<m;b++)if(!((P=f.charCodeAt(b))>96&&P<123||P>64&&P<91||P>47&&P<59||45===P||95===P||46==P)){if(32===P||P<14&&P>8){j=f.substring(0,b),M=null;break}return g("invalid nodeName")}z||I.push(j)}if(h){if(o=U,L&&(z||D.push(o),null===M&&(d=-1!==f.indexOf("xmlns",b))&&(G=b,F=f,X(),d=!1)),B=j,-1!==(P=j.indexOf(":"))){if(!($=U[j.substring(0,P)]))return g("missing namespace on <"+B+">");j=j.substr(P+1)}else $=U.xmlns;$&&(j=$+":"+j)}if(L&&(G=b,F=f,n&&(c?n(C,x,z,l):n(j,X,x,z,l),y)))return;if(z){if(r&&(r(c?C:j,x,L,l),y))return;h&&(U=L?o:D.pop())}q+=1}else{if(p&&(p(e.substring(S,q+1),x,l),y))return;q+=1}}else{if(-1===(q=e.indexOf("?>",S)))return g("unclosed question");if(a&&(a(e.substring(S,q+2),l),y))return;q+=2}}}(e),l=E,y=!1,m},this.stop=function(){y=!0}}function B(){}function C(e,t){this.model=e,this.properties=t}B.prototype.get=function(e){return this.$model.properties.get(this,e)},B.prototype.set=function(e,t){this.$model.properties.set(this,e,t)},C.prototype.createType=function(e){var t=this.model,n=this.properties,r=Object.create(B.prototype);p(e.properties,(function(e){e.isMany||void 0===e.default||(r[e.name]=e.default)})),n.defineModel(r,t),n.defineDescriptor(r,e);var i=e.ns.name;function o(e){n.define(this,"$type",{value:i,enumerable:!0}),n.define(this,"$attrs",{value:{}}),n.define(this,"$parent",{writable:!0}),p(e,l((function(e,t){this.set(t,e)}),this))}return o.prototype=r,o.hasType=r.$instanceOf=this.model.hasType,n.defineModel(o,t),n.defineDescriptor(o,e),o};var M={String:!0,Boolean:!0,Integer:!0,Real:!0,Element:!0},D={String:function(e){return e},Boolean:function(e){return"true"===e},Integer:function(e){return parseInt(e,10)},Real:function(e){return parseFloat(e)}};function U(e,t){var n=D[e];return n?n(t):t}function I(e){return!!M[e]}function R(e){return!!D[e]}function L(e,t){var n,r,i=e.split(/:/);if(1===i.length)n=e,r=t;else{if(2!==i.length)throw new Error("expected <prefix:localName> or <localName>, got "+e);n=i[1],r=i[0]}return{name:e=(r?r+":":"")+n,prefix:r,localName:n}}function z(e){this.ns=e,this.name=e.name,this.allTypes=[],this.allTypesByName={},this.properties=[],this.propertiesByName={}}function S(e,t){this.packageMap={},this.typeMap={},this.packages=[],this.properties=t,p(e,l(this.registerPackage,this))}function q(e,t,n){var r=t[n];if(r in e)throw new Error("package with "+n+" <"+r+"> already defined")}function F(e){this.model=e}function G(e,t,n){Object.defineProperty(e,t.name,{enumerable:!t.isReference,writable:!0,value:n,configurable:!0})}function X(e){this.properties=new F(this),this.factory=new C(this,this.properties),this.registry=new S(e,this.properties),this.typeCache={}}function H(e){return e.xml&&"lowerCase"===e.xml.tagAlias}z.prototype.build=function(){return e=this,t=["ns","name","allTypes","allTypesByName","properties","propertiesByName","bodyProperty","idProperty"],n={},r=Object(e),p(t,(function(t){t in r&&(n[t]=e[t])})),n;var e,t,n,r},z.prototype.addProperty=function(e,t,n){"boolean"==typeof t&&(n=t,t=void 0),this.addNamedProperty(e,!1!==n);var r=this.properties;void 0!==t?r.splice(t,0,e):r.push(e)},z.prototype.replaceProperty=function(e,t,n){var r=e.ns,i=this.properties,o=this.propertiesByName,s=e.name!==t.name;if(e.isId){if(!t.isId)throw new Error("property <"+t.ns.name+"> must be id property to refine <"+e.ns.name+">");this.setIdProperty(t,!1)}if(e.isBody){if(!t.isBody)throw new Error("property <"+t.ns.name+"> must be body property to refine <"+e.ns.name+">");this.setBodyProperty(t,!1)}var a=i.indexOf(e);if(-1===a)throw new Error("property <"+r.name+"> not found in property list");i.splice(a,1),this.addProperty(t,n?void 0:a,s),o[r.name]=o[r.localName]=t},z.prototype.redefineProperty=function(e,t,n){var r=e.ns.prefix,i=t.split("#"),o=L(i[0],r),s=L(i[1],o.prefix).name,a=this.propertiesByName[s];if(!a)throw new Error("refined property <"+s+"> not found");this.replaceProperty(a,e,n),delete e.redefines},z.prototype.addNamedProperty=function(e,t){var n=e.ns,r=this.propertiesByName;t&&(this.assertNotDefined(e,n.name),this.assertNotDefined(e,n.localName)),r[n.name]=r[n.localName]=e},z.prototype.removeNamedProperty=function(e){var t=e.ns,n=this.propertiesByName;delete n[t.name],delete n[t.localName]},z.prototype.setBodyProperty=function(e,t){if(t&&this.bodyProperty)throw new Error("body property defined multiple times (<"+this.bodyProperty.ns.name+">, <"+e.ns.name+">)");this.bodyProperty=e},z.prototype.setIdProperty=function(e,t){if(t&&this.idProperty)throw new Error("id property defined multiple times (<"+this.idProperty.ns.name+">, <"+e.ns.name+">)");this.idProperty=e},z.prototype.assertNotDefined=function(e,t){var n=e.name,r=this.propertiesByName[n];if(r)throw new Error("property <"+n+"> already defined; override of <"+r.definedBy.ns.name+"#"+r.ns.name+"> by <"+e.definedBy.ns.name+"#"+e.ns.name+"> not allowed without redefines")},z.prototype.hasProperty=function(e){return this.propertiesByName[e]},z.prototype.addTrait=function(e,t){var n=this.allTypesByName,r=this.allTypes,i=e.name;i in n||(p(e.properties,l((function(n){n=h({},n,{name:n.ns.localName,inherited:t}),Object.defineProperty(n,"definedBy",{value:e});var r=n.replaces,i=n.redefines;r||i?this.redefineProperty(n,r||i,r):(n.isBody&&this.setBodyProperty(n),n.isId&&this.setIdProperty(n),this.addProperty(n))}),this)),r.push(e),n[i]=e)},S.prototype.getPackage=function(e){return this.packageMap[e]},S.prototype.getPackages=function(){return this.packages},S.prototype.registerPackage=function(e){e=h({},e);var t=this.packageMap;q(t,e,"prefix"),q(t,e,"uri"),p(e.types,l((function(t){this.registerType(t,e)}),this)),t[e.uri]=t[e.prefix]=e,this.packages.push(e)},S.prototype.registerType=function(e,t){var n=L((e=h({},e,{superClass:(e.superClass||[]).slice(),extends:(e.extends||[]).slice(),properties:(e.properties||[]).slice(),meta:h(e.meta||{})})).name,t.prefix),r=n.name,i={};p(e.properties,l((function(e){var t=L(e.name,n.prefix),r=t.name;I(e.type)||(e.type=L(e.type,t.prefix).name),h(e,{ns:t,name:r}),i[r]=e}),this)),h(e,{ns:n,name:r,propertiesByName:i}),p(e.extends,l((function(e){var t=this.typeMap[e];t.traits=t.traits||[],t.traits.push(r)}),this)),this.definePackage(e,t),this.typeMap[r]=e},S.prototype.mapTypes=function(e,t,n){var r=I(e.name)?{name:e.name}:this.typeMap[e.name],i=this;function o(e){return s(e,!0)}function s(n,r){var o=L(n,I(n)?"":e.prefix);i.mapTypes(o,t,r)}if(!r)throw new Error("unknown type <"+e.name+">");p(r.superClass,n?o:s),t(r,!n),p(r.traits,o)},S.prototype.getEffectiveDescriptor=function(e){var t=L(e),n=new z(t);this.mapTypes(t,(function(e,t){n.addTrait(e,t)}));var r=n.build();return this.definePackage(r,r.allTypes[r.allTypes.length-1].$pkg),r},S.prototype.definePackage=function(e,t){this.properties.define(e,"$pkg",{value:t})},F.prototype.set=function(e,t,n){var r=this.model.getPropertyDescriptor(e,t),i=r&&r.name;void 0===n?r?delete e[i]:delete e.$attrs[t]:r?i in e?e[i]=n:G(e,r,n):e.$attrs[t]=n},F.prototype.get=function(e,t){var n=this.model.getPropertyDescriptor(e,t);if(!n)return e.$attrs[t];var r=n.name;return!e[r]&&n.isMany&&G(e,n,[]),e[r]},F.prototype.define=function(e,t,n){Object.defineProperty(e,t,n)},F.prototype.defineDescriptor=function(e,t){this.define(e,"$descriptor",{value:t})},F.prototype.defineModel=function(e,t){this.define(e,"$model",{value:t})},X.prototype.create=function(e,t){var n=this.getType(e);if(!n)throw new Error("unknown type <"+e+">");return new n(t)},X.prototype.getType=function(e){var t=this.typeCache,n=i(e)?e:e.ns.name,r=t[n];return r||(e=this.registry.getEffectiveDescriptor(n),r=t[n]=this.factory.createType(e)),r},X.prototype.createAny=function(e,n,r){var i=L(e),o={$type:e,$instanceOf:function(e){return e===this.$type}},s={name:e,isGeneric:!0,ns:{prefix:i.prefix,localName:i.localName,uri:n}};return this.properties.defineDescriptor(o,s),this.properties.defineModel(o,this),this.properties.define(o,"$parent",{enumerable:!1,writable:!0}),this.properties.define(o,"$instanceOf",{enumerable:!1,writable:!0}),p(r,(function(e,n){var r;r=e,"[object Object]"===t.call(r)&&void 0!==e.value?o[e.name]=e.value:o[n]=e})),o},X.prototype.getPackage=function(e){return this.registry.getPackage(e)},X.prototype.getPackages=function(){return this.registry.getPackages()},X.prototype.getElementDescriptor=function(e){return e.$descriptor},X.prototype.hasType=function(e,t){return void 0===t&&(t=e,e=this),t in e.$model.getElementDescriptor(e).allTypesByName},X.prototype.getPropertyDescriptor=function(e,t){return this.getElementDescriptor(e).propertiesByName[t]},X.prototype.getTypeDescriptor=function(e){return this.registry.typeMap[e]};var W={xsi:"http://www.w3.org/2001/XMLSchema-instance",xml:"http://www.w3.org/XML/1998/namespace"},_="xsi:type";function V(e){return e.xml&&e.xml.serialize}function K(e){return V(e)===_}function J(e,t){return H(t)?e.prefix+":"+((n=e.localName).charAt(0).toUpperCase()+n.slice(1)):e.name;var n}function Q(e){return new Error(e)}function Y(e){return e.$descriptor}function Z(e){h(this,e),this.elementsById={},this.references=[],this.warnings=[],this.addReference=function(e){this.references.push(e)},this.addElement=function(e){if(!e)throw Q("expected element");var t,n=this.elementsById,r=Y(e).idProperty;if(r&&(t=e.get(r.name))){if(!/^([a-z][\w-.]*:)?[a-z_][\w-.]*$/i.test(t))throw new Error("illegal ID <"+t+">");if(n[t])throw Q("duplicate ID <"+t+">");n[t]=e}},this.addWarning=function(e){this.warnings.push(e)}}function ee(){}function te(){}function ne(){}function re(e,t){this.property=e,this.context=t}function ie(e,t){this.element=t,this.propertyDesc=e}function oe(){}function se(e,t,n){this.model=e,this.type=e.getType(t),this.context=n}function ae(e,t,n){se.call(this,e,t,n)}function pe(e,t,n){this.model=e,this.context=n}function ue(e){e instanceof X&&(e={model:e}),h(this,{lax:!1},e)}ee.prototype.handleEnd=function(){},ee.prototype.handleText=function(){},ee.prototype.handleNode=function(){},te.prototype=Object.create(ee.prototype),te.prototype.handleNode=function(){return this},ne.prototype=Object.create(ee.prototype),ne.prototype.handleText=function(e){this.body=(this.body||"")+e},re.prototype=Object.create(ne.prototype),re.prototype.handleNode=function(e){if(this.element)throw Q("expected no sub nodes");return this.element=this.createReference(e),this},re.prototype.handleEnd=function(){this.element.id=this.body},re.prototype.createReference=function(e){return{property:this.property.ns.name,id:""}},ie.prototype=Object.create(ne.prototype),ie.prototype.handleEnd=function(){var e=this.body||"",t=this.element,n=this.propertyDesc;e=U(n.type,e),n.isMany?t.get(n.name).push(e):t.set(n.name,e)},oe.prototype=Object.create(ne.prototype),oe.prototype.handleNode=function(e){var t=this,n=this.element;return n?t=this.handleChild(e):(n=this.element=this.createElement(e),this.context.addElement(n)),t},se.prototype=Object.create(oe.prototype),se.prototype.addReference=function(e){this.context.addReference(e)},se.prototype.handleText=function(e){if(!Y(this.element).bodyProperty)throw Q("unexpected body text <"+e+">");ne.prototype.handleText.call(this,e)},se.prototype.handleEnd=function(){var e=this.body,t=this.element,n=Y(t).bodyProperty;n&&void 0!==e&&(e=U(n.type,e),t.set(n.name,e))},se.prototype.createElement=function(e){var t,n=e.attributes,r=this.type,i=Y(r),o=this.context,s=new r({}),a=this.model;return p(n,(function(e,n){var r=i.propertiesByName[n];r&&r.isReference?r.isMany?p(e.split(" "),(function(e){o.addReference({element:s,property:r.ns.name,id:e})})):o.addReference({element:s,property:r.ns.name,id:e}):(r?e=U(r.type,e):"xmlns"!==n&&(t=L(n,i.ns.prefix),a.getPackage(t.prefix)&&o.addWarning({message:"unknown attribute <"+n+">",element:s,property:n,value:e})),s.set(n,e))})),s},se.prototype.getPropertyForNode=function(e){var t,n,r=L(e.name),i=this.type,o=this.model,a=Y(i),p=r.name,u=a.propertiesByName[p];if(u&&!u.isAttr)return K(u)&&(t=e.attributes[_])?(t=function(e,t){var n=L(e);return function(e,t){var n=e.name,r=e.localName,i=t.xml&&t.xml.typePrefix;return i&&0===r.indexOf(i)?e.prefix+":"+r.slice(i.length):n}(n,t.getPackage(n.prefix))}(t,o),h({},u,{effectiveType:Y(n=o.getType(t)).name})):u;var c=o.getPackage(r.prefix);if(c){if(t=J(r,c),n=o.getType(t),u=s(a.properties,(function(e){return!e.isVirtual&&!e.isReference&&!e.isAttribute&&n.hasType(e.type)})))return h({},u,{effectiveType:Y(n).name})}else if(u=s(a.properties,(function(e){return!e.isReference&&!e.isAttribute&&"Element"===e.type})))return u;throw Q("unrecognized element <"+r.name+">")},se.prototype.toString=function(){return"ElementDescriptor["+Y(this.type).name+"]"},se.prototype.valueHandler=function(e,t){return new ie(e,t)},se.prototype.referenceHandler=function(e){return new re(e,this.context)},se.prototype.handler=function(e){return"Element"===e?new pe(this.model,e,this.context):new se(this.model,e,this.context)},se.prototype.handleChild=function(e){var t,n,r,i;if(t=this.getPropertyForNode(e),r=this.element,R(n=t.effectiveType||t.type))return this.valueHandler(t,r);var o=(i=t.isReference?this.referenceHandler(t).handleNode(e):this.handler(n).handleNode(e)).element;return void 0!==o&&(t.isMany?r.get(t.name).push(o):r.set(t.name,o),t.isReference?(h(o,{element:r}),this.context.addReference(o)):o.$parent=r),i},ae.prototype=Object.create(se.prototype),ae.prototype.createElement=function(e){var t=e.name,n=L(t),r=this.model,i=this.type,o=r.getPackage(n.prefix),s=o&&J(n,o)||t;if(!i.hasType(s))throw Q("unexpected element <"+e.originalName+">");return se.prototype.createElement.call(this,e)},pe.prototype=Object.create(oe.prototype),pe.prototype.createElement=function(e){var t=e.name,n=L(t).prefix,r=e.ns[n+"$uri"],i=e.attributes;return this.model.createAny(t,r,i)},pe.prototype.handleChild=function(e){var t=new pe(this.model,"Element",this.context).handleNode(e),n=this.element,r=t.element;return void 0!==r&&((n.$children=n.$children||[]).push(r),r.$parent=n),t},pe.prototype.handleEnd=function(){this.body&&(this.element.$body=this.body)},ue.prototype.fromXML=function(e,t,n){var r=t.rootHandler;t instanceof se?(r=t,t={}):"string"==typeof t?(r=this.handler(t),t={}):"string"==typeof r&&(r=this.handler(r));var i=this.model,o=this.lax,s=new Z(h({},t,{rootHandler:r})),a=new j({proxy:!0}),p=function(){var e=[];return Object.defineProperty(e,"peek",{value:function(){return this[this.length-1]}}),e}();function u(e,t,n){var r=t(),i=r.line,o=r.column,a=r.data;"<"===a.charAt(0)&&-1!==a.indexOf(" ")&&(a=a.slice(0,a.indexOf(" "))+">");var p="unparsable content "+(a?a+" ":"")+"detected\n\tline: "+i+"\n\tcolumn: "+o+"\n\tnested error: "+e.message;if(n)return s.addWarning({message:p,error:e}),!0;throw Q(p)}function c(e,t){return u(e,t,!0)}r.context=s,p.push(r);var f=/^<\?xml /i,l=/ encoding="([^"]+)"/i,d=/^utf-8$/i;function m(e,t){try{p.peek().handleText(e)}catch(e){c(e,t)}}var y=i.getPackages().reduce((function(e,t){return e[t.uri]=t.prefix,e}),{"http://www.w3.org/XML/1998/namespace":"xml"});return a.ns(y).on("openTag",(function(e,t,n,r){var i=e.attrs||{},s=Object.keys(i).reduce((function(e,n){var r=t(i[n]);return e[n]=r,e}),{});!function(e,t){var n=p.peek();try{p.push(n.handleNode(e))}catch(e){u(e,t,o)&&p.push(new te)}}({name:e.name,originalName:e.originalName,attributes:s,ns:e.ns},r)})).on("question",(function(e){if(f.test(e)){var t=l.exec(e),n=t&&t[1];n&&!d.test(n)&&s.addWarning({message:"unsupported document encoding <"+n+">, falling back to UTF-8"})}})).on("closeTag",(function(){p.pop().handleEnd()})).on("cdata",m).on("text",(function(e,t,n){!function(e,t){e.trim()&&m(e,t)}(t(e),n)})).on("error",u).on("warn",c),new Promise((function(t,n){var i;try{a.parse(e),function(){var e,t,n=s.elementsById,r=s.references;for(e=0;t=r[e];e++){var i=t.element,o=n[t.id],a=Y(i).propertiesByName[t.property];if(o||s.addWarning({message:"unresolved reference <"+t.id+">",element:t.element,property:t.property,value:t.id}),a.isMany){var p=i.get(a.name),u=p.indexOf(t);-1===u&&(u=p.length),o?p[u]=o:p.splice(u,1)}else i.set(a.name,o)}}()}catch(e){i=e}var o=r.element;i||o||(i=Q("failed to parse document as <"+r.type.$descriptor.name+">"));var p=s.warnings,u=s.references,c=s.elementsById;return i?(i.warnings=p,n(i)):t({rootElement:o,elementsById:c,references:u,warnings:p})}))},ue.prototype.handler=function(e){return new ae(this.model,e)};var ce=/<|>|'|"|&|\n\r|\n/g,fe=/<|>|&/g;function le(e){var t={},n={},r={},i=[],o=[];this.byUri=function(t){return n[t]||e&&e.byUri(t)},this.add=function(e,t){n[e.uri]=e,t?i.push(e):o.push(e),this.mapPrefix(e.prefix,e.uri)},this.uriByPrefix=function(e){return t[e||"xmlns"]},this.mapPrefix=function(e,n){t[e||"xmlns"]=n},this.getNSKey=function(e){return void 0!==e.prefix?e.uri+"|"+e.prefix:e.uri},this.logUsed=function(t){var n=t.uri,i=this.getNSKey(t);r[i]=this.byUri(n),e&&e.logUsed(t)},this.getUsed=function(e){var t=this;return[].concat(i,o).filter((function(e){var n=t.getNSKey(e);return r[n]}))}}function de(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}function he(e){return i(e)?e:(e.prefix?e.prefix+":":"")+e.localName}var me={"\n":"#10","\n\r":"#10",'"':"#34","'":"#39","<":"#60",">":"#62","&":"#38"},ye={"<":"lt",">":"gt","&":"amp"};function ge(e,t,n){return(e=i(e)?e:""+e).replace(t,(function(e){return"&"+n[e]+";"}))}function ve(e){this.tagName=e}function be(){}function xe(e){this.tagName=e}function Ne(e,t){this.body=[],this.attrs=[],this.parent=e,this.propertyDescriptor=t}function we(e,t){Ne.call(this,e,t)}function Pe(){this.value="",this.write=function(e){this.value+=e}}function Te(e,t){var n=[""];this.append=function(t){return e.write(t),this},this.appendNewLine=function(){return t&&e.write("\n"),this},this.appendIndent=function(){return t&&e.write(n.join(" ")),this},this.indent=function(){return n.push(""),this},this.unindent=function(){return n.pop(),this}}ve.prototype.build=function(e){return this.element=e,this},ve.prototype.serializeTo=function(e){e.appendIndent().append("<"+this.tagName+">"+this.element.id+"</"+this.tagName+">").appendNewLine()},be.prototype.serializeValue=be.prototype.serializeTo=function(e){e.append(this.escape?ge(this.value,fe,ye):this.value)},be.prototype.build=function(e,t){return this.value=t,"String"===e.type&&-1!==t.search(fe)&&(this.escape=!0),this},de(xe,be),xe.prototype.serializeTo=function(e){e.appendIndent().append("<"+this.tagName+">"),this.serializeValue(e),e.append("</"+this.tagName+">").appendNewLine()},Ne.prototype.build=function(e){this.element=e;var t,n,r=e.$descriptor,i=this.propertyDescriptor,s=r.isGeneric;return t=s?this.parseGeneric(e):this.parseNsAttributes(e),this.ns=i?this.nsPropertyTagName(i):this.nsTagName(r),this.tagName=this.addTagName(this.ns),s||(n=function(e){return a(e.$descriptor.properties,(function(t){var n=t.name;if(t.isVirtual)return!1;if(!o(e,n))return!1;var r=e[n];return r!==t.default&&null!==r&&(!t.isMany||r.length)}))}(e),this.parseAttributes(a(n,(function(e){return e.isAttr}))),this.parseContainments(function(e){return a(e,(function(e){return!e.isAttr}))}(n))),this.parseGenericAttributes(e,t),this},Ne.prototype.nsTagName=function(e){return function(e,t){return t.isGeneric?h({localName:t.ns.localName},e):h({localName:(n=t.ns.localName,r=t.$pkg,H(r)?(i=n).charAt(0).toLowerCase()+i.slice(1):n)},e);var n,r,i}(this.logNamespaceUsed(e.ns),e)},Ne.prototype.nsPropertyTagName=function(e){return function(e,t){return h({localName:t.ns.localName},e)}(this.logNamespaceUsed(e.ns),e)},Ne.prototype.isLocalNs=function(e){return e.uri===this.ns.uri},Ne.prototype.nsAttributeName=function(e){var t;if(t=i(e)?L(e):e.ns,e.inherited)return{localName:t.localName};var n=this.logNamespaceUsed(t);return this.getNamespaces().logUsed(n),this.isLocalNs(n)?{localName:t.localName}:h({localName:t.localName},n)},Ne.prototype.parseGeneric=function(e){var t=this,n=this.body,r=[];return p(e,(function(i,o){"$body"===o?n.push((new be).build({type:"String"},i)):"$children"===o?p(i,(function(e){n.push(new Ne(t).build(e))})):0!==o.indexOf("$")&&t.parseNsAttribute(e,o,i)&&r.push({name:o,value:i})})),r},Ne.prototype.parseNsAttribute=function(e,t,n){var r,i=e.$model,o=L(t);if("xmlns"===o.prefix&&(r={prefix:o.localName,uri:n}),o.prefix||"xmlns"!==o.localName||(r={uri:n}),!r)return{name:t,value:n};if(i&&i.getPackage(n))this.logNamespace(r,!0,!0);else{var s=this.logNamespaceUsed(r,!0);this.getNamespaces().logUsed(s)}},Ne.prototype.parseNsAttributes=function(e,t){var n=this,r=e.$attrs,i=[];return p(r,(function(t,r){var o=n.parseNsAttribute(e,r,t);o&&i.push(o)})),i},Ne.prototype.parseGenericAttributes=function(e,t){var n=this;p(t,(function(t){if(t.name!==_)try{n.addAttribute(n.nsAttributeName(t.name),t.value)}catch(n){console.warn("missing namespace information for ",t.name,"=",t.value,"on",e,n)}}))},Ne.prototype.parseContainments=function(e){var t=this,n=this.body,r=this.element;p(e,(function(e){var i=r.get(e.name),o=e.isReference;if(e.isMany||(i=[i]),e.isBody)n.push((new be).build(e,i[0]));else if(R(e.type))p(i,(function(r){n.push(new xe(t.addTagName(t.nsPropertyTagName(e))).build(e,r))}));else if(o)p(i,(function(r){n.push(new ve(t.addTagName(t.nsPropertyTagName(e))).build(r))}));else{var s=K(e),a=function(e){return"property"===V(e)}(e);p(i,(function(r){var i;i=s?new we(t,e):a?new Ne(t,e):new Ne(t),n.push(i.build(r))}))}}))},Ne.prototype.getNamespaces=function(e){var t,n=this.namespaces,r=this.parent;return n||(t=r&&r.getNamespaces(),e||!t?this.namespaces=n=new le(t):n=t),n},Ne.prototype.logNamespace=function(e,t,n){var r=this.getNamespaces(n),i=e.uri,o=e.prefix;return r.byUri(i)&&!n||r.add(e,t),r.mapPrefix(o,i),e},Ne.prototype.logNamespaceUsed=function(e,t){var n,r,i,o=this.element.$model,s=this.getNamespaces(t),a=e.prefix,p=e.uri;if(!a&&!p)return{localName:e.localName};if(i=W[a]||o&&(o.getPackage(a)||{}).uri,!(p=p||i||s.uriByPrefix(a)))throw new Error("no namespace uri given for prefix <"+a+">");if(!(e=s.byUri(p))){for(n=a,r=1;s.uriByPrefix(n);)n=a+"_"+r++;e=this.logNamespace({prefix:n,uri:p},i===p)}return a&&s.mapPrefix(a,p),e},Ne.prototype.parseAttributes=function(e){var t=this,n=this.element;p(e,(function(e){var r=n.get(e.name);if(e.isReference)if(e.isMany){var i=[];p(r,(function(e){i.push(e.id)})),r=i.join(" ")}else r=r.id;t.addAttribute(t.nsAttributeName(e),r)}))},Ne.prototype.addTagName=function(e){var t=this.logNamespaceUsed(e);return this.getNamespaces().logUsed(t),he(e)},Ne.prototype.addAttribute=function(e,t){var n=this.attrs;i(t)&&(t=ge(t,ce,me));var o=function(e,t){t=u(t);var n=r(e)?-1:void 0;return p(e,(function(e,r){if(t(e,r))return n=r,!1})),n}(n,(function(t){return t.name.localName===e.localName&&t.name.uri===e.uri&&t.name.prefix===e.prefix})),s={name:e,value:t};-1!==o?n.splice(o,1,s):n.push(s)},Ne.prototype.serializeAttributes=function(e){var t=this.attrs,n=this.namespaces;n&&(t=function(e){return e.getUsed().filter((function(e){return"xml"!==e.prefix})).map((function(e){return{name:"xmlns"+(e.prefix?":"+e.prefix:""),value:e.uri}}))}(n).concat(t)),p(t,(function(t){e.append(" ").append(he(t.name)).append('="').append(t.value).append('"')}))},Ne.prototype.serializeTo=function(e){var t=this.body[0],n=t&&t.constructor!==be;e.appendIndent().append("<"+this.tagName),this.serializeAttributes(e),e.append(t?">":" />"),t&&(n&&e.appendNewLine().indent(),p(this.body,(function(t){t.serializeTo(e)})),n&&e.unindent().appendIndent(),e.append("</"+this.tagName+">")),e.appendNewLine()},de(we,Ne),we.prototype.parseNsAttributes=function(e){var t=Ne.prototype.parseNsAttributes.call(this,e),n=e.$descriptor;if(n.name===this.propertyDescriptor.type)return t;var r=this.typeNs=this.nsTagName(n);this.getNamespaces().logUsed(this.typeNs);var i=e.$model.getPackage(r.uri),o=i.xml&&i.xml.typePrefix||"";return this.addAttribute(this.nsAttributeName(_),(r.prefix?r.prefix+":":"")+o+n.ns.localName),t},we.prototype.isLocalNs=function(e){return e.uri===(this.typeNs||this.ns).uri},e.Reader=ue,e.Writer=function(e){return e=h({format:!1,preamble:!0},e||{}),{toXML:function(t,n){var r=n||new Pe,i=new Te(r,e.format);if(e.preamble&&i.append('<?xml version="1.0" encoding="UTF-8"?>\n'),(new Ne).build(t).serializeTo(i),!n)return r.value}}},Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "moddle-xml",
"version": "9.0.5",
"version": "9.0.6",
"description": "XML import/export for documents described with moddle",

@@ -12,2 +12,3 @@ "scripts": {

"build": "rollup -c",
"prepare": "npm run build",
"test:build": "mocha --reporter=spec --recursive test/distro",

@@ -48,3 +49,3 @@ "prepublishOnly": "run-s distro"

"eslint": "^7.14.0",
"eslint-plugin-bpmn-io": "^0.11.0",
"eslint-plugin-bpmn-io": "^0.12.0",
"esm": "^3.2.25",

@@ -51,0 +52,0 @@ "mocha": "^8.2.1",

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc