moddle-xml
Advanced tools
Comparing version 8.0.7 to 8.0.8
@@ -9,2 +9,6 @@ # Changelog | ||
## 8.0.8 | ||
* `FIX`: handle default `xml` namespace | ||
## 8.0.7 | ||
@@ -11,0 +15,0 @@ |
@@ -10,3 +10,4 @@ import { forEach, assign, find, filter, isString, map } from 'min-dash'; | ||
var DEFAULT_NS_MAP = { | ||
'xsi': 'http://www.w3.org/2001/XMLSchema-instance' | ||
'xsi': 'http://www.w3.org/2001/XMLSchema-instance', | ||
'xml': 'http://www.w3.org/XML/1998/namespace' | ||
}; | ||
@@ -814,4 +815,5 @@ | ||
return uriMap; | ||
}, {}); | ||
}, { | ||
'http://www.w3.org/XML/1998/namespace': 'xml' // add default xml ns | ||
}); | ||
parser | ||
@@ -1456,3 +1458,3 @@ .ns(uriMap) | ||
if (!existing || local) { | ||
if (nsPrefix !== 'xml' && (!existing || local)) { | ||
namespaces.add(ns, wellknown); | ||
@@ -1459,0 +1461,0 @@ } |
@@ -14,3 +14,4 @@ 'use strict'; | ||
var DEFAULT_NS_MAP = { | ||
'xsi': 'http://www.w3.org/2001/XMLSchema-instance' | ||
'xsi': 'http://www.w3.org/2001/XMLSchema-instance', | ||
'xml': 'http://www.w3.org/XML/1998/namespace' | ||
}; | ||
@@ -818,4 +819,5 @@ | ||
return uriMap; | ||
}, {}); | ||
}, { | ||
'http://www.w3.org/XML/1998/namespace': 'xml' // add default xml ns | ||
}); | ||
parser | ||
@@ -1460,3 +1462,3 @@ .ns(uriMap) | ||
if (!existing || local) { | ||
if (nsPrefix !== 'xml' && (!existing || local)) { | ||
namespaces.add(ns, wellknown); | ||
@@ -1463,0 +1465,0 @@ } |
@@ -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=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,y=/&#(\d+);|&#x([0-9a-f]+);|&(\w+);/gi,m={amp:"&",apos:"'",gt:">",lt:"<",quot:'"'};function g(e,t,n,r){return r?h.call(m,r)?m[r]:"&"+r+";":d(t||parseInt(n,16))}function v(e){return e.length>3&&-1!==e.indexOf("&")?e.replace(y,g):e}Object.keys(m).forEach(function(e){m[e.toUpperCase()]=m[e]});var b="http://www.w3.org/2001/XMLSchema-instance",x="xsi",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,y=null,m=!1;function g(e){e instanceof Error||(e=P(e)),y=e,f(e,l)}function B(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[b]=x,h=!0,u=n,this},this.parse=function(e){if("string"!=typeof e)throw P("required args <xml=string>");return y=null,function(e){var o,f,y,b,x,P,E,$,j,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,z=!1,L=!1,S=0,q=0,F="",G=0;function H(){if(null!==M)return M;var e,t,n,r,i,o,s,a,p,c,f,l=h&&U.xmlns,y=h&&d?[]:null,m=G,g=F,b=g.length,x={},w={};e:for(;m<b;m++)if(p=!1,!(32===(c=g.charCodeAt(m))||c<14&&c>8)){for((c<65||c>122||c>90&&c<97)&&95!==c&&58!==c&&(B("illegal first char attribute name"),p=!0),f=m+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){B("missing attribute value"),m=f;continue e}if(61===c)break;B("illegal attribute name char"),p=!0}if("xmlns:xmlns"===(a=g.substring(m,f))&&(B("illegal declaration of xmlns"),p=!0),34===(c=g.charCodeAt(f+1)))-1===(f=g.indexOf('"',m=f+2))&&-1!==(f=g.indexOf("'",m))&&(B("attribute value quote missmatch"),p=!0);else if(39===c)-1===(f=g.indexOf("'",m=f+2))&&-1!==(f=g.indexOf('"',m))&&(B("attribute value quote missmatch"),p=!0);else for(B("missing attribute value quotes"),p=!0,f+=1;f<b&&!(32===(c=g.charCodeAt(f+1))||c<14&&c>8);f++);for(-1===f&&(B("missing closing quotes"),f=b,p=!0),p||(o=g.substring(m,f)),m=f;f+1<b&&!(32===(c=g.charCodeAt(f+1))||c<14&&c>8);f++)m===f&&(B("illegal character after attribute end"),p=!0);if(m=f+1,!p)if(a in w)B("attribute <"+a+"> already defined");else if(w[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=v(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),x[a]=o;continue}y.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),n=U[n]||n,o=n+o.substring(c)):o=l+":"+o),x[a]=o):B(T(a.substring(0,c))):x[a]=o;else x[a]=o}if(d)for(m=0,b=y.length;m<b;m++){if(a=y[m++],o=y[m],-1!==(c=a.indexOf(":"))){if(!(n=U[a.substring(0,c)])){B(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),n=U[n]||n,o=n+o.substring(c)):o=l+":"+o)}x[a]=o}return M=x}l=function(){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}},c&&(C=Object.create({},{name:O(function(){return $}),originalName:O(function(){return j}),attrs:O(H),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()&&B(w));if(q!==S)if(I.length){if(t&&(t(e.substring(q,S),v,l),m))return}else if(e.substring(q,S).trim()&&(B(w),m))return;if(33===(x=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),m))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),v,l),m))return;q+=3;continue}}if(63!==x){for(f=S+1;;f++){if(P=e.charCodeAt(f),isNaN(P))return q=-1,g("unclosed tag");if(34===P)b=e.indexOf('"',f+1),f=-1!==b?b:f;else if(39===P)b=e.indexOf("'",f+1),f=-1!==b?b:f;else if(62===P){q=f;break}}if(33!==x){if(M={},47===x){if(z=!1,L=!0,!I.length)return g("missing open tag");if(f=$=I.pop(),b=S+2+f.length,e.substring(S+2,b)!==f)return g("closing tag mismatch");for(;b<q;b++)if(!(32===(x=e.charCodeAt(b))||x>8&&x<14))return g("close tag")}else{if(47===e.charCodeAt(q-1)?(f=$=e.substring(S+1,q-1),z=!0,L=!0):(f=$=e.substring(S+1,q),z=!0,L=!1),!(x>96&&x<123||x>64&&x<91||95===x||58===x))return g("illegal first char nodeName");for(b=1,y=f.length;b<y;b++)if(!((x=f.charCodeAt(b))>96&&x<123||x>64&&x<91||x>47&&x<59||45===x||95===x||46==x)){if(32===x||x<14&&x>8){$=f.substring(0,b),M=null;break}return g("invalid nodeName")}L||I.push($)}if(h){if(o=U,z&&(L||D.push(o),null===M&&(d=-1!==f.indexOf("xmlns",b))&&(G=b,F=f,H(),d=!1)),j=$,-1!==(x=$.indexOf(":"))){if(!(E=U[$.substring(0,x)]))return g("missing namespace on <"+j+">");$=$.substr(x+1)}else E=U.xmlns;E&&($=E+":"+$)}if(z&&(G=b,F=f,n&&(c?n(C,v,L,l):n($,H,v,L,l),m)))return;if(L){if(r&&(r(c?C:$,v,z,l),m))return;h&&(U=z?o:D.pop())}q+=1}else{if(p&&(p(e.substring(S,q+1),v,l),m))return;q+=1}}else{if(-1===(q=e.indexOf("?>",S)))return g("unclosed question");if(a&&(a(e.substring(S,q+2),l),m))return;q+=2}}}(e),l=E,m=!1,y},this.stop=function(){m=!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);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 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,10)}};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 z(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 L(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,a(e,c(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 H(e){this.properties=new F(this),this.factory=new C(this,this.properties),this.registry=new S(e,this.properties),this.typeCache={}}function W(e){return e.xml&&"lowerCase"===e.xml.tagAlias}L.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},L.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)},L.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},L.prototype.redefineProperty=function(e,t,n){var r=e.ns.prefix,i=t.split("#"),o=z(i[0],r),s=z(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},L.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},L.prototype.removeNamedProperty=function(e){var t=e.ns,n=this.propertiesByName;delete n[t.name],delete n[t.localName]},L.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},L.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},L.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")},L.prototype.hasProperty=function(e){return this.propertiesByName[e]},L.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)},S.prototype.getPackage=function(e){return this.packageMap[e]},S.prototype.getPackages=function(){return this.packages},S.prototype.registerPackage=function(e){e=l({},e);var t=this.packageMap;q(t,e,"prefix"),q(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)},S.prototype.registerType=function(e,t){var n=z((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=z(e.name,n.prefix),r=t.name;I(e.type)||(e.type=z(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},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=z(n,I(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)},S.prototype.getEffectiveDescriptor=function(e){var t=z(e),n=new L(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})},H.prototype.create=function(e,t){var n=this.getType(e);if(!n)throw new Error("unknown type <"+e+">");return new n(t)},H.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},H.prototype.createAny=function(e,n,r){var i=z(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}),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},H.prototype.getPackage=function(e){return this.registry.getPackage(e)},H.prototype.getPackages=function(){return this.registry.getPackages()},H.prototype.getElementDescriptor=function(e){return e.$descriptor},H.prototype.hasType=function(e,t){return void 0===t&&(t=e,e=this),t in e.$model.getElementDescriptor(e).allTypesByName},H.prototype.getPropertyDescriptor=function(e,t){return this.getElementDescriptor(e).propertiesByName[t]},H.prototype.getTypeDescriptor=function(e){return this.registry.typeMap[e]};var X={xsi:"http://www.w3.org/2001/XMLSchema-instance"},_="xsi:type";function V(e){return e.xml&&e.xml.serialize}function K(e){return V(e)===_}function J(e,t){return W(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){l(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 H&&(e={model:e}),l(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({}),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=U(r.type,e):"xmlns"!==n&&(t=z(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},se.prototype.getPropertyForNode=function(e){var t,n,r=z(e.name),i=this.type,s=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=z(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:Y(n=s.getType(t)).name})):u;var c=s.getPackage(r.prefix);if(c){if(t=J(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:Y(n).name})}else if(u=o(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?(l(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=z(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=z(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(l({},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,d=/ encoding="([^"]+)"/i,h=/^utf-8$/i;function y(e,t){try{p.peek().handleText(e)}catch(e){c(e,t)}}var m=i.getPackages().reduce(function(e,t){return e[t.uri]=t.prefix,e},{});a.ns(m).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=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",y).on("text",function(e,t,n){!function(e,t){(e=e.trim())&&y(e,t)}(t(e),n)}).on("error",u).on("warn",c),setTimeout(function(){var t;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){t=e}var i=r.element;t||i||(t=Q("failed to parse document as <"+r.type.$descriptor.name+">")),n(t,t?void 0:i,s)},0)},ue.prototype.handler=function(e){return new ae(this.model,e)};var ce='<?xml version="1.0" encoding="UTF-8"?>\n',fe=/<|>|'|"|&|\n\r|\n/g,le=/<|>|&/g;function de(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 he(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}function ye(e){return r(e)?e:(e.prefix?e.prefix+":":"")+e.localName}function me(e){return t=e.getUsed(),n=function(e){return{name:"xmlns"+(e.prefix?":"+e.prefix:""),value:e.uri}},r=[],a(t,function(e,t){r.push(n(e,t))}),r;var t,n,r}var ge={"\n":"#10","\n\r":"#10",'"':"#34","'":"#39","<":"#60",">":"#62","&":"#38"},ve={"<":"lt",">":"gt","&":"amp"};function be(e,t,n){return(e=r(e)?e:""+e).replace(t,function(e){return"&"+n[e]+";"})}function xe(e){this.tagName=e}function Ne(){}function we(e){this.tagName=e}function Pe(e,t){this.body=[],this.attrs=[],this.parent=e,this.propertyDescriptor=t}function Te(e,t){Pe.call(this,e,t)}function Oe(){this.value="",this.write=function(e){this.value+=e}}function Ae(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}}xe.prototype.build=function(e){return this.element=e,this},xe.prototype.serializeTo=function(e){e.appendIndent().append("<"+this.tagName+">"+this.element.id+"</"+this.tagName+">").appendNewLine()},Ne.prototype.serializeValue=Ne.prototype.serializeTo=function(e){e.append(this.escape?be(this.value,le,ve):this.value)},Ne.prototype.build=function(e,t){return this.value=t,"String"===e.type&&-1!==t.search(le)&&(this.escape=!0),this},he(we,Ne),we.prototype.serializeTo=function(e){e.appendIndent().append("<"+this.tagName+">"),this.serializeValue(e),e.append("</"+this.tagName+">").appendNewLine()},Pe.prototype.build=function(e){this.element=e;var t,n,r=e.$descriptor,i=this.propertyDescriptor,o=r.isGeneric;return t=o?this.parseGeneric(e):this.parseNsAttributes(e),this.ns=i?this.nsPropertyTagName(i):this.nsTagName(r),this.tagName=this.addTagName(this.ns),o||(n=function(e){return s(e.$descriptor.properties,function(t){var n=t.name;if(t.isVirtual)return!1;if(!e.hasOwnProperty(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},Pe.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,W(r)?(i=n).charAt(0).toLowerCase()+i.slice(1):n)},e);var n,r,i}(this.logNamespaceUsed(e.ns),e)},Pe.prototype.nsPropertyTagName=function(e){return function(e,t){return l({localName:t.ns.localName},e)}(this.logNamespaceUsed(e.ns),e)},Pe.prototype.isLocalNs=function(e){return e.uri===this.ns.uri},Pe.prototype.nsAttributeName=function(e){var t;if(t=r(e)?z(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)},Pe.prototype.parseGeneric=function(e){var t=this,n=this.body,r=[];return a(e,function(i,o){"$body"===o?n.push((new Ne).build({type:"String"},i)):"$children"===o?a(i,function(e){n.push(new Pe(t).build(e))}):0!==o.indexOf("$")&&t.parseNsAttribute(e,o,i)&&r.push({name:o,value:i})}),r},Pe.prototype.parseNsAttribute=function(e,t,n){var r,i=e.$model,o=z(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)}},Pe.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},Pe.prototype.parseGenericAttributes=function(e,t){var n=this;a(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)}})},Pe.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 Ne).build(e,i[0]));else if(R(e.type))a(i,function(r){n.push(new we(t.addTagName(t.nsPropertyTagName(e))).build(e,r))});else if(o)a(i,function(r){n.push(new xe(t.addTagName(t.nsPropertyTagName(e))).build(r))});else{var s=K(e),p=function(e){return"property"===V(e)}(e);a(i,function(r){var i;i=s?new Te(t,e):p?new Pe(t,e):new Pe(t),n.push(i.build(r))})}})},Pe.prototype.getNamespaces=function(e){var t,n=this.namespaces,r=this.parent;return n||(t=r&&r.getNamespaces(),e||!t?this.namespaces=n=new de(t):n=t),n},Pe.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},Pe.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},Pe.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)})},Pe.prototype.addTagName=function(e){var t=this.logNamespaceUsed(e);return this.getNamespaces().logUsed(t),ye(e)},Pe.prototype.addAttribute=function(e,t){var n=this.attrs;r(t)&&(t=be(t,fe,ge)),n.push({name:e,value:t})},Pe.prototype.serializeAttributes=function(e){var t=this.attrs,n=this.namespaces;n&&(t=me(n).concat(t)),a(t,function(t){e.append(" ").append(ye(t.name)).append('="').append(t.value).append('"')})},Pe.prototype.serializeTo=function(e){var t=this.body[0],n=t&&t.constructor!==Ne;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()},he(Te,Pe),Te.prototype.parseNsAttributes=function(e){var t=Pe.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},Te.prototype.isLocalNs=function(e){return e.uri===(this.typeNs||this.ns).uri},e.Reader=ue,e.Writer=function(e){return e=l({format:!1,preamble:!0},e||{}),{toXML:function(t,n){var r=n||new Oe,i=new Ae(r,e.format);if(e.preamble&&i.append(ce),(new Pe).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=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 h=String.fromCharCode,d=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?d.call(y,r)?y[r]:"&"+r+";":h(t||parseInt(n,16))}function v(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 b="http://www.w3.org/2001/XMLSchema-instance",x="xsi",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,h=!1,d=!1,m=null,y=!1;function g(e){e instanceof Error||(e=P(e)),m=e,f(e,l)}function B(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[b]=x,d=!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,x,P,E,$,j,C,M,D=d?[]:null,U=d?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=d&&U.xmlns,m=d&&h?[]:null,y=G,g=F,b=g.length,x={},w={};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&&(B("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){B("missing attribute value"),y=f;continue e}if(61===c)break;B("illegal attribute name char"),p=!0}if("xmlns:xmlns"===(a=g.substring(y,f))&&(B("illegal declaration of xmlns"),p=!0),34===(c=g.charCodeAt(f+1)))-1===(f=g.indexOf('"',y=f+2))&&-1!==(f=g.indexOf("'",y))&&(B("attribute value quote missmatch"),p=!0);else if(39===c)-1===(f=g.indexOf("'",y=f+2))&&-1!==(f=g.indexOf('"',y))&&(B("attribute value quote missmatch"),p=!0);else for(B("missing attribute value quotes"),p=!0,f+=1;f<b&&!(32===(c=g.charCodeAt(f+1))||c<14&&c>8);f++);for(-1===f&&(B("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&&(B("illegal character after attribute end"),p=!0);if(y=f+1,!p)if(a in w)B("attribute <"+a+"> already defined");else if(w[a]=!0,d)if(h){if(null!==(i="xmlns"===a?"xmlns":120===a.charCodeAt(0)&&"xmlns:"===a.substr(0,6)?a.substr(6):null)){if(e=v(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),x[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),n=U[n]||n,o=n+o.substring(c)):o=l+":"+o),x[a]=o):B(T(a.substring(0,c))):x[a]=o;else x[a]=o}if(h)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)])){B(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),n=U[n]||n,o=n+o.substring(c)):o=l+":"+o)}x[a]=o}return M=x}l=function(){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}},c&&(C=Object.create({},{name:O(function(){return $}),originalName:O(function(){return j}),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()&&B(w));if(q!==S)if(I.length){if(t&&(t(e.substring(q,S),v,l),y))return}else if(e.substring(q,S).trim()&&(B(w),y))return;if(33===(x=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),v,l),y))return;q+=3;continue}}if(63!==x){for(f=S+1;;f++){if(P=e.charCodeAt(f),isNaN(P))return q=-1,g("unclosed tag");if(34===P)b=e.indexOf('"',f+1),f=-1!==b?b:f;else if(39===P)b=e.indexOf("'",f+1),f=-1!==b?b:f;else if(62===P){q=f;break}}if(33!==x){if(M={},47===x){if(L=!1,z=!0,!I.length)return g("missing open tag");if(f=$=I.pop(),b=S+2+f.length,e.substring(S+2,b)!==f)return g("closing tag mismatch");for(;b<q;b++)if(!(32===(x=e.charCodeAt(b))||x>8&&x<14))return g("close tag")}else{if(47===e.charCodeAt(q-1)?(f=$=e.substring(S+1,q-1),L=!0,z=!0):(f=$=e.substring(S+1,q),L=!0,z=!1),!(x>96&&x<123||x>64&&x<91||95===x||58===x))return g("illegal first char nodeName");for(b=1,m=f.length;b<m;b++)if(!((x=f.charCodeAt(b))>96&&x<123||x>64&&x<91||x>47&&x<59||45===x||95===x||46==x)){if(32===x||x<14&&x>8){$=f.substring(0,b),M=null;break}return g("invalid nodeName")}z||I.push($)}if(d){if(o=U,L&&(z||D.push(o),null===M&&(h=-1!==f.indexOf("xmlns",b))&&(G=b,F=f,X(),h=!1)),j=$,-1!==(x=$.indexOf(":"))){if(!(E=U[$.substring(0,x)]))return g("missing namespace on <"+j+">");$=$.substr(x+1)}else E=U.xmlns;E&&($=E+":"+$)}if(L&&(G=b,F=f,n&&(c?n(C,v,z,l):n($,X,v,z,l),y)))return;if(z){if(r&&(r(c?C:$,v,L,l),y))return;d&&(U=L?o:D.pop())}q+=1}else{if(p&&(p(e.substring(S,q+1),v,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);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 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,10)}};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,a(e,c(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),a(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||(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)},S.prototype.getPackage=function(e){return this.packageMap[e]},S.prototype.getPackages=function(){return this.packages},S.prototype.registerPackage=function(e){e=l({},e);var t=this.packageMap;q(t,e,"prefix"),q(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)},S.prototype.registerType=function(e,t){var n=L((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=L(e.name,n.prefix),r=t.name;I(e.type)||(e.type=L(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},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+">");a(r.superClass,n?o:s),t(r,!n),a(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=r(e)?e:e.ns.name,i=t[n];return i||(e=this.registry.getEffectiveDescriptor(n),i=t[n]=this.factory.createType(e)),i},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}),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},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){l(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}),l(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({}),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=U(r.type,e):"xmlns"!==n&&(t=L(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},se.prototype.getPropertyForNode=function(e){var t,n,r=L(e.name),i=this.type,s=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,s),l({},u,{effectiveType:Y(n=s.getType(t)).name})):u;var c=s.getPackage(r.prefix);if(c){if(t=J(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:Y(n).name})}else if(u=o(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?(l(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(l({},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,h=/ 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"});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=h.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=e.trim())&&m(e,t)}(t(e),n)}).on("error",u).on("warn",c),setTimeout(function(){var t;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){t=e}var i=r.element;t||i||(t=Q("failed to parse document as <"+r.type.$descriptor.name+">")),n(t,t?void 0:i,s)},0)},ue.prototype.handler=function(e){return new ae(this.model,e)};var ce='<?xml version="1.0" encoding="UTF-8"?>\n',fe=/<|>|'|"|&|\n\r|\n/g,le=/<|>|&/g;function he(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 me(e){return r(e)?e:(e.prefix?e.prefix+":":"")+e.localName}function ye(e){return t=e.getUsed(),n=function(e){return{name:"xmlns"+(e.prefix?":"+e.prefix:""),value:e.uri}},r=[],a(t,function(e,t){r.push(n(e,t))}),r;var t,n,r}var ge={"\n":"#10","\n\r":"#10",'"':"#34","'":"#39","<":"#60",">":"#62","&":"#38"},ve={"<":"lt",">":"gt","&":"amp"};function be(e,t,n){return(e=r(e)?e:""+e).replace(t,function(e){return"&"+n[e]+";"})}function xe(e){this.tagName=e}function Ne(){}function we(e){this.tagName=e}function Pe(e,t){this.body=[],this.attrs=[],this.parent=e,this.propertyDescriptor=t}function Te(e,t){Pe.call(this,e,t)}function Oe(){this.value="",this.write=function(e){this.value+=e}}function Ae(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}}xe.prototype.build=function(e){return this.element=e,this},xe.prototype.serializeTo=function(e){e.appendIndent().append("<"+this.tagName+">"+this.element.id+"</"+this.tagName+">").appendNewLine()},Ne.prototype.serializeValue=Ne.prototype.serializeTo=function(e){e.append(this.escape?be(this.value,le,ve):this.value)},Ne.prototype.build=function(e,t){return this.value=t,"String"===e.type&&-1!==t.search(le)&&(this.escape=!0),this},de(we,Ne),we.prototype.serializeTo=function(e){e.appendIndent().append("<"+this.tagName+">"),this.serializeValue(e),e.append("</"+this.tagName+">").appendNewLine()},Pe.prototype.build=function(e){this.element=e;var t,n,r=e.$descriptor,i=this.propertyDescriptor,o=r.isGeneric;return t=o?this.parseGeneric(e):this.parseNsAttributes(e),this.ns=i?this.nsPropertyTagName(i):this.nsTagName(r),this.tagName=this.addTagName(this.ns),o||(n=function(e){return s(e.$descriptor.properties,function(t){var n=t.name;if(t.isVirtual)return!1;if(!e.hasOwnProperty(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},Pe.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,H(r)?(i=n).charAt(0).toLowerCase()+i.slice(1):n)},e);var n,r,i}(this.logNamespaceUsed(e.ns),e)},Pe.prototype.nsPropertyTagName=function(e){return function(e,t){return l({localName:t.ns.localName},e)}(this.logNamespaceUsed(e.ns),e)},Pe.prototype.isLocalNs=function(e){return e.uri===this.ns.uri},Pe.prototype.nsAttributeName=function(e){var t;if(t=r(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}:l({localName:t.localName},n)},Pe.prototype.parseGeneric=function(e){var t=this,n=this.body,r=[];return a(e,function(i,o){"$body"===o?n.push((new Ne).build({type:"String"},i)):"$children"===o?a(i,function(e){n.push(new Pe(t).build(e))}):0!==o.indexOf("$")&&t.parseNsAttribute(e,o,i)&&r.push({name:o,value:i})}),r},Pe.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)}},Pe.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},Pe.prototype.parseGenericAttributes=function(e,t){var n=this;a(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)}})},Pe.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 Ne).build(e,i[0]));else if(R(e.type))a(i,function(r){n.push(new we(t.addTagName(t.nsPropertyTagName(e))).build(e,r))});else if(o)a(i,function(r){n.push(new xe(t.addTagName(t.nsPropertyTagName(e))).build(r))});else{var s=K(e),p=function(e){return"property"===V(e)}(e);a(i,function(r){var i;i=s?new Te(t,e):p?new Pe(t,e):new Pe(t),n.push(i.build(r))})}})},Pe.prototype.getNamespaces=function(e){var t,n=this.namespaces,r=this.parent;return n||(t=r&&r.getNamespaces(),e||!t?this.namespaces=n=new he(t):n=t),n},Pe.prototype.logNamespace=function(e,t,n){var r=this.getNamespaces(n),i=e.uri,o=e.prefix,s=r.byUri(i);return"xml"===o||s&&!n||r.add(e,t),r.mapPrefix(o,i),e},Pe.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},Pe.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)})},Pe.prototype.addTagName=function(e){var t=this.logNamespaceUsed(e);return this.getNamespaces().logUsed(t),me(e)},Pe.prototype.addAttribute=function(e,t){var n=this.attrs;r(t)&&(t=be(t,fe,ge)),n.push({name:e,value:t})},Pe.prototype.serializeAttributes=function(e){var t=this.attrs,n=this.namespaces;n&&(t=ye(n).concat(t)),a(t,function(t){e.append(" ").append(me(t.name)).append('="').append(t.value).append('"')})},Pe.prototype.serializeTo=function(e){var t=this.body[0],n=t&&t.constructor!==Ne;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()},de(Te,Pe),Te.prototype.parseNsAttributes=function(e){var t=Pe.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},Te.prototype.isLocalNs=function(e){return e.uri===(this.typeNs||this.ns).uri},e.Reader=ue,e.Writer=function(e){return e=l({format:!1,preamble:!0},e||{}),{toXML:function(t,n){var r=n||new Oe,i=new Ae(r,e.format);if(e.preamble&&i.append(ce),(new Pe).build(t).serializeTo(i),!n)return r.value}}},Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "moddle-xml", | ||
"version": "8.0.7", | ||
"version": "8.0.8", | ||
"description": "XML import/export for documents described with moddle", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
209729
5818