UNPKG

bpmn-js

Version:

A bpmn 2.0 toolkit and web modeler

10 lines 418 kB
/*! bpmn-js - bpmn-modeler v1.1.0 | Copyright (c) 2014-present, camunda Services GmbH | bpmn.io/license */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.BpmnJS=t()}(this,function(){"use strict";"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function e(e,t){return e(t={exports:{}},t.exports),t.exports}var t=e(function(e){"function"==typeof Object.create?e.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:e.exports=function(e,t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}}),n=e(function(e){var t=e.exports=function(e,n){if(n||(n=16),void 0===e&&(e=128),e<=0)return"0";for(var i=Math.log(Math.pow(2,e))/Math.log(n),r=2;i===1/0;r*=2)i=Math.log(Math.pow(2,e/r))/Math.log(n)*r;var o=i-Math.floor(i),a="";for(r=0;r<Math.floor(i);r++){a=Math.floor(Math.random()*n).toString(n)+a}if(o){var s=Math.pow(n,o);a=Math.floor(Math.random()*s).toString(n)+a}var c=parseInt(a,n);return c!==1/0&&c>=Math.pow(2,e)?t(e,n):a};t.rack=function(e,n,i){var r=function(r){var a=0;do{if(a++>10){if(!i)throw new Error("too many ID collisions, use more bits");e+=i}var s=t(e,n)}while(Object.hasOwnProperty.call(o,s));return o[s]=r,s},o=r.hats={};return r.get=function(e){return r.hats[e]},r.set=function(e,t){return r.hats[e]=t,r},r.bits=e||128,r.base=n||16,r}});function i(e){if(!(this instanceof i))return new i(e);e=e||[128,36,1],this._seed=e.length?n.rack(e[0],e[1],e[2]):e}var r=i;function o(e){return Array.prototype.concat.apply([],e)}i.prototype.next=function(e){return this._seed(e||!0)},i.prototype.nextPrefixed=function(e,t){var n;do{n=e+this.next(!0)}while(this.assigned(n));return this.claim(n,t),n},i.prototype.claim=function(e,t){this._seed.set(e,t||!0)},i.prototype.assigned=function(e){return this._seed.get(e)||!1},i.prototype.unclaim=function(e){delete this._seed.hats[e]},i.prototype.clear=function(){var e,t=this._seed.hats;for(e in t)this.unclaim(e)};var a=Object.prototype.toString,s=Object.prototype.hasOwnProperty;function c(e){return null===e||void 0===e}function p(e){return"[object Array]"===a.call(e)}function l(e){return"[object Object]"===a.call(e)}function u(e){return"[object Number]"===a.call(e)}function h(e){return"[object Function]"===a.call(e)}function d(e){return"[object String]"===a.call(e)}function m(e,t){return s.call(e,t)}function f(e,t){var n;return t=D(t),g(e,function(e,i){if(t(e,i))return n=e,!1}),n}function y(e,t){t=D(t);var n=p(e)?-1:void 0;return g(e,function(e,i){if(t(e,i))return n=i,!1}),n}function v(e,t){var n=[];return g(e,function(e,i){t(e,i)&&n.push(e)}),n}function g(e,t){if(!c(e)){var n=p(e)?B:N;for(var i in e){if(m(e,i))if(!1===t(e[i],n(i)))return}}}function b(e,t){return c(e)?[]:(function(e){if(!p(e))throw new Error("must supply array")}(e),t=D(t),e.filter(function(e,n){return!t(e,n)}))}function x(e,t,n){return g(e,function(e,i){n=t(n,e,i)}),n}function _(e,t){return x(e,function(e,n,i){return e&&t(n,i)},!0)}function E(e,t){return!!f(e,t)}function w(e,t){var n=[];return g(e,function(e,i){n.push(t(e,i))}),n}function S(e){return e&&Object.keys(e)||[]}function C(e){return w(e,function(e){return e})}function T(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return t=k(t),g(e,function(e){var i=t(e)||"_",r=n[i];r||(r=n[i]=[]),r.push(e)}),n}function R(e){e=k(e);for(var t={},n=arguments.length,i=Array(n>1?n-1:0),r=1;r<n;r++)i[r-1]=arguments[r];return g(i,function(n){return T(n,e,t)}),w(t,function(e,t){return e[0]})}var A=R;function P(e,t){t=k(t);var n=[];return g(e,function(e,i){for(var r=t(e,i),o={d:r,v:e},a=0;a<n.length;a++){if(r<n[a].d)return void n.splice(a,0,o)}n.push(o)}),w(n,function(e){return e.v})}function M(e){return function(t){return _(e,function(e,n){return t[n]===e})}}function k(e){return h(e)?e:function(t){return t[e]}}function D(e){return h(e)?e:function(t){return t===e}}function N(e){return e}function B(e){return Number(e)}var O=Array.prototype.slice;function I(e,t){var n;return function(){var i=O.call(arguments);n&&clearTimeout(n),n=setTimeout(function(){e.apply(void 0,function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}(i))},t)}}function L(e,t){return e.bind(t)}var j=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e};function z(e){for(var t=arguments.length,n=Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];return j.apply(void 0,[e].concat(n))}function F(e,t){var n={},i=Object(e);return g(t,function(t){t in i&&(n[t]=e[t])}),n}function $(e,t,n){return 2==arguments.length?e.getAttribute(t):null===n?e.removeAttribute(t):(e.setAttribute(t,n),e)}var W=[].indexOf,H=function(e,t){if(W)return e.indexOf(t);for(var n=0;n<e.length;++n)if(e[n]===t)return n;return-1},G=/\s+/,V=Object.prototype.toString;function q(e){return new U(e)}function U(e){if(!e||!e.nodeType)throw new Error("A DOM element reference is required");this.el=e,this.list=e.classList}function Y(e){for(var t;e.childNodes.length;)t=e.childNodes[0],e.removeChild(t);return e}U.prototype.add=function(e){if(this.list)return this.list.add(e),this;var t=this.array();return~H(t,e)||t.push(e),this.el.className=t.join(" "),this},U.prototype.remove=function(e){if("[object RegExp]"==V.call(e))return this.removeMatching(e);if(this.list)return this.list.remove(e),this;var t=this.array(),n=H(t,e);return~n&&t.splice(n,1),this.el.className=t.join(" "),this},U.prototype.removeMatching=function(e){for(var t=this.array(),n=0;n<t.length;n++)e.test(t[n])&&this.remove(t[n]);return this},U.prototype.toggle=function(e,t){return this.list?(void 0!==t?t!==this.list.toggle(e,t)&&this.list.toggle(e):this.list.toggle(e),this):(void 0!==t?t?this.add(e):this.remove(e):this.has(e)?this.remove(e):this.add(e),this)},U.prototype.array=function(){var e=(this.el.getAttribute("class")||"").replace(/^\s+|\s+$/g,"").split(G);return""===e[0]&&e.shift(),e},U.prototype.has=U.prototype.contains=function(e){return this.list?this.list.contains(e):!!~H(this.array(),e)};var K=Element.prototype,X=K.matchesSelector||K.webkitMatchesSelector||K.mozMatchesSelector||K.msMatchesSelector||K.oMatchesSelector,Z=function(e,t){if(X)return X.call(e,t);for(var n=e.parentNode.querySelectorAll(t),i=0;i<n.length;++i)if(n[i]==e)return!0;return!1};var Q,J=function(e,t,n){for(var i=n?e:e.parentNode;i&&i!==document;){if(Z(i,t))return i;i=i.parentNode}},ee=window.addEventListener?"addEventListener":"attachEvent",te=window.removeEventListener?"removeEventListener":"detachEvent",ne="addEventListener"!==ee?"on":"",ie={bind:function(e,t,n,i){return e[ee](ne+t,n,i||!1),n},unbind:function(e,t,n,i){return e[te](ne+t,n,i||!1),n}},re=["focus","blur"],oe={bind:function(e,t,n,i,r){return-1!==re.indexOf(n)&&(r=!0),ie.bind(e,n,function(n){var r=n.target||n.srcElement;n.delegateTarget=J(r,t,!0,e),n.delegateTarget&&i.call(e,n)},r)},unbind:function(e,t,n,i){-1!==re.indexOf(t)&&(i=!0),ie.unbind(e,t,n,i)}},ae=function(e,t){if("string"!=typeof e)throw new TypeError("String expected");t||(t=document);var n=/<([\w:]+)/.exec(e);if(!n)return t.createTextNode(e);e=e.replace(/^\s+|\s+$/g,"");var i=n[1];if("body"==i){var r=t.createElement("html");return r.innerHTML=e,r.removeChild(r.lastChild)}var o=ce[i]||ce._default,a=o[0],s=o[1],c=o[2];(r=t.createElement("div")).innerHTML=s+e+c;for(;a--;)r=r.lastChild;if(r.firstChild==r.lastChild)return r.removeChild(r.firstChild);var p=t.createDocumentFragment();for(;r.firstChild;)p.appendChild(r.removeChild(r.firstChild));return p},se=!1;"undefined"!=typeof document&&((Q=document.createElement("div")).innerHTML=' <link/><table></table><a href="/a">a</a><input type="checkbox"/>',se=!Q.getElementsByTagName("link").length,Q=void 0);var ce={legend:[1,"<fieldset>","</fieldset>"],tr:[2,"<table><tbody>","</tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],_default:se?[1,"X<div>","</div>"]:[0,"",""]};ce.td=ce.th=[3,"<table><tbody><tr>","</tr></tbody></table>"],ce.option=ce.optgroup=[1,'<select multiple="multiple">',"</select>"],ce.thead=ce.tbody=ce.colgroup=ce.caption=ce.tfoot=[1,"<table>","</table>"],ce.polyline=ce.ellipse=ce.polygon=ce.circle=ce.text=ce.line=ce.path=ce.rect=ce.g=[1,'<svg xmlns="http://www.w3.org/2000/svg" version="1.1">',"</svg>"];var pe="undefined"!=typeof Element?Element.prototype:{},le=pe.matches||pe.matchesSelector||pe.webkitMatchesSelector||pe.mozMatchesSelector||pe.msMatchesSelector||pe.oMatchesSelector,ue=function(e,t){if(!e||1!==e.nodeType)return!1;if(le)return le.call(e,t);for(var n=e.parentNode.querySelectorAll(t),i=0;i<n.length;i++)if(n[i]==e)return!0;return!1};function he(e,t){return(t=t||document).querySelector(e)}function de(e,t){return(t=t||document).querySelectorAll(e)}function me(e){e.parentNode&&e.parentNode.removeChild(e)}function fe(e,t){return t.appendChild(function(e,t){if(e.ownerDocument!==t.ownerDocument)try{return t.ownerDocument.importNode(e,!0)}catch(e){}return e}(e,t)),e}function ye(e,t){return fe(t,e),e}var ve=2,ge={"alignment-baseline":1,"baseline-shift":1,clip:1,"clip-path":1,"clip-rule":1,color:1,"color-interpolation":1,"color-interpolation-filters":1,"color-profile":1,"color-rendering":1,cursor:1,direction:1,display:1,"dominant-baseline":1,"enable-background":1,fill:1,"fill-opacity":1,"fill-rule":1,filter:1,"flood-color":1,"flood-opacity":1,font:1,"font-family":1,"font-size":ve,"font-size-adjust":1,"font-stretch":1,"font-style":1,"font-variant":1,"font-weight":1,"glyph-orientation-horizontal":1,"glyph-orientation-vertical":1,"image-rendering":1,kerning:1,"letter-spacing":1,"lighting-color":1,marker:1,"marker-end":1,"marker-mid":1,"marker-start":1,mask:1,opacity:1,overflow:1,"pointer-events":1,"shape-rendering":1,"stop-color":1,"stop-opacity":1,stroke:1,"stroke-dasharray":1,"stroke-dashoffset":1,"stroke-linecap":1,"stroke-linejoin":1,"stroke-miterlimit":1,"stroke-opacity":1,"stroke-width":ve,"text-anchor":1,"text-decoration":1,"text-rendering":1,"unicode-bidi":1,visibility:1,"word-spacing":1,"writing-mode":1};function be(e,t,n){var i=t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),r=ge[i];r?(r===ve&&"number"==typeof n&&(n=String(n)+"px"),e.style[i]=n):e.setAttributeNS(null,t,n)}function xe(e,t,n){if("string"==typeof t){if(void 0===n)return function(e,t){return ge[t]?e.style[t]:e.getAttributeNS(null,t)}(e,t);be(e,t,n)}else!function(e,t){var n,i,r=Object.keys(t);for(n=0;i=r[n];n++)be(e,i,t[i])}(e,t);return e}function _e(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0;n<e.length;++n)if(e[n]===t)return n;return-1}var Ee=/\s+/,we=Object.prototype.toString;function Se(e){return void 0!==e}function Ce(e){return new Te(e)}function Te(e){if(!e||!e.nodeType)throw new Error("A DOM element reference is required");this.el=e,this.list=e.classList}function Re(e){var t=e.parentNode;return t&&t.removeChild(e),e}function Ae(e){for(var t;t=e.firstChild;)Re(t);return e}Te.prototype.add=function(e){if(this.list)return this.list.add(e),this;var t=this.array();return~_e(t,e)||t.push(e),Se(this.el.className.baseVal)?this.el.className.baseVal=t.join(" "):this.el.className=t.join(" "),this},Te.prototype.remove=function(e){if("[object RegExp]"===we.call(e))return this.removeMatching(e);if(this.list)return this.list.remove(e),this;var t=this.array(),n=_e(t,e);return~n&&t.splice(n,1),this.el.className.baseVal=t.join(" "),this},Te.prototype.removeMatching=function(e){for(var t=this.array(),n=0;n<t.length;n++)e.test(t[n])&&this.remove(t[n]);return this},Te.prototype.toggle=function(e,t){return this.list?(Se(t)?t!==this.list.toggle(e,t)&&this.list.toggle(e):this.list.toggle(e),this):(Se(t)?t?this.add(e):this.remove(e):this.has(e)?this.remove(e):this.add(e),this)},Te.prototype.array=function(){var e=(this.el.getAttribute("class")||"").replace(/^\s+|\s+$/g,"").split(Ee);return""===e[0]&&e.shift(),e},Te.prototype.has=Te.prototype.contains=function(e){return this.list?this.list.contains(e):!!~_e(this.array(),e)};var Pe={svg:"http://www.w3.org/2000/svg"},Me='<svg xmlns="'+Pe.svg+'"';function ke(e){return"<svg"===e.substring(0,4)?-1===e.indexOf(Pe.svg)&&(e=Me+e.substring(4)):e=Me+">"+e+"</svg>",function(e){var t;return(t=new DOMParser).async=!1,t.parseFromString(e,"text/xml")}(e)}function De(e,t){var n;return"<"===e.charAt(0)?(n=ke(e).firstChild,n=document.importNode(n,!0)):n=document.createElementNS(Pe.svg,e),t&&xe(n,t),n}var Ne=De("svg");function Be(e,t,n,i,r,o){var a=Ne.createSVGMatrix();switch(arguments.length){case 0:return a;case 6:e={a:e,b:t,c:n,d:i,e:r,f:o}}return function(e,t){var n,i,r=Object.keys(t);for(n=0;i=r[n];n++)e[i]=t[i];return e}(a,e)}function Oe(e){return e?Ne.createSVGTransformFromMatrix(e):Ne.createSVGTransform()}var Ie=/([&<>]{1})/g,Le=/([\n\r"]{1})/g,je={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"'"};function ze(e,t){return e.replace(t,function(e,t){return je[t]||t})}function Fe(e,t){var n,i,r,o,a;switch(e.nodeType){case 3:t.push(ze(e.textContent,Ie));break;case 1:if(t.push("<",e.tagName),e.hasAttributes())for(n=0,i=(r=e.attributes).length;n<i;++n)o=r.item(n),t.push(" ",o.name,'="',ze(o.value,Le),'"');if(e.hasChildNodes()){for(t.push(">"),n=0,i=(a=e.childNodes).length;n<i;++n)Fe(a.item(n),t);t.push("</",e.tagName,">")}else t.push("/>");break;case 8:t.push("\x3c!--",ze(e.nodeValue,Ie),"--\x3e");break;case 4:t.push("<![CDATA[",e.nodeValue,"]]>");break;default:throw new Error("unable to handle node "+e.nodeType)}return t}function $e(e,t){if(void 0!==t){try{!function(e,t){var n,i=ke(t).documentElement;if(Ae(e),t)for(n=i.firstChild;n;)fe(n,e),n=n.nextSibling}(e,t)}catch(e){throw new Error("error parsing SVG: "+e.message)}return e}return function(e){for(var t=e.firstChild,n=[];t;)Fe(t,n),t=t.nextSibling;return n.join("")}(e)}function We(e,t){return t instanceof SVGMatrix?e.createSVGTransformFromMatrix(t):t}function He(e,t){var n=e.transform.baseVal;if(1===arguments.length)return n.consolidate();t.length?function(e,t){var n,i;for(e.clear(),n=0;i=t[n];n++)e.appendItem(We(e,i));e.consolidate()}(n,t):n.initialize(We(n,t))}var Ge=/^class /;function Ve(e){return"[object Array]"===Object.prototype.toString.call(e)}function qe(){var e=Array.prototype.slice.call(arguments);1===e.length&&Ve(e[0])&&(e=e[0]);var t=e.pop();return t.$inject=e,t}var Ue=/constructor\s*[^(]*\(\s*([^)]*)\)/m,Ye=/^function\s*[^(]*\(\s*([^)]*)\)/m,Ke=/\/\*([^*]*)\*\//m;function Xe(e){if("function"!=typeof e)throw new Error('Cannot annotate "'+e+'". Expected a function!');var t=e.toString().match(function(e){return Ge.test(e.toString())}(e)?Ue:Ye);return t&&t[1]&&t[1].split(",").map(function(e){return(t=e.match(Ke))?t[1].trim():e.trim()})||[]}var Ze="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};function Qe(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}function Je(e,t){return Object.hasOwnProperty.call(e,t)}var et=1e3;function tt(e,t){var n=this;t=t||et,e.on(["render.shape","render.connection"],t,function(e,t){var i=e.type,r=t.element,o=t.gfx;if(n.canRender(r))return"render.shape"===i?n.drawShape(o,r):n.drawConnection(o,r)}),e.on(["render.getShapePath","render.getConnectionPath"],t,function(e,t){if(n.canRender(t))return"render.getShapePath"===e.type?n.getShapePath(t):n.getConnectionPath(t)})}function nt(e){return e.join(",").replace(/,?([A-z]),?/g,"$1")}function it(e){for(var t,n="",i=0;t=e[i];i++)n+=t.x+","+t.y+" ";return n}function rt(e,t){var n=De("polyline");return xe(n,{points:it(e)}),t&&xe(n,t),n}tt.prototype.canRender=function(){},tt.prototype.drawShape=function(){},tt.prototype.drawConnection=function(){},tt.prototype.getShapePath=function(){},tt.prototype.getConnectionPath=function(){};var ot=1;function at(e,t){tt.call(this,e,ot),this.CONNECTION_STYLE=t.style(["no-fill"],{strokeWidth:5,stroke:"fuchsia"}),this.SHAPE_STYLE=t.style({fill:"white",stroke:"fuchsia",strokeWidth:2})}t(at,tt),at.prototype.canRender=function(){return!0},at.prototype.drawShape=function(e,t){var n=De("rect");return xe(n,{x:0,y:0,width:t.width||0,height:t.height||0}),xe(n,this.SHAPE_STYLE),ye(e,n),n},at.prototype.drawConnection=function(e,t){var n=rt(t.waypoints,this.CONNECTION_STYLE);return ye(e,n),n},at.prototype.getShapePath=function(e){var t=e.x,n=e.y,i=e.width;return nt([["M",t,n],["l",i,0],["l",0,e.height],["l",-i,0],["z"]])},at.prototype.getConnectionPath=function(e){var t,n,i=e.waypoints,r=[];for(t=0;n=i[t];t++)n=n.original||n,r.push([0===t?"M":"L",n.x,n.y]);return nt(r)},at.$inject=["eventBus","styles"];var st={__init__:["defaultRenderer"],defaultRenderer:["type",at],styles:["type",function(){var e={"no-fill":{fill:"none"},"no-border":{strokeOpacity:0},"no-events":{pointerEvents:"none"}},t=this;this.cls=function(e,t,n){return z(this.style(t,n),{class:e})},this.style=function(t,n){p(t)||n||(n=t,t=[]);var i=x(t,function(t,n){return z(t,e[n]||{})},{});return n?z(i,n):i},this.computeStyle=function(e,n,i){return p(n)||(i=n,n=[]),t.style(n||[],z({},i,e||{}))}}]};function ct(e,t){if(!e||!t)return-1;var n=e.indexOf(t);return-1!==n&&e.splice(n,1),n}function pt(e,t,n){if(e&&t){"number"!=typeof n&&(n=-1);var i=e.indexOf(t);if(-1!==i){if(i===n)return;if(-1===n)return;e.splice(i,1)}-1!==n?e.splice(n,0,t):e.push(t)}}function lt(e,t){return e&&t?e.indexOf(t):-1}function ut(e,t,n){var i=!n||-1===e.indexOf(t);return i&&e.push(t),i}function ht(e,t,n){n=n||0,p(e)||(e=[e]),g(e,function(e,i){var r=t(e,i,n);p(r)&&r.length&&ht(r,t,n+1)})}function dt(e,t){return function(e,t,n){var i=[],r=[];return ht(e,function(e,o,a){ut(i,e,t);var s=e.children;if((-1===n||a<n)&&s&&ut(r,s,t))return s}),i}(e,!t,-1)}function mt(e,t){var n,i,r,o;return t=!!t,p(e)||(e=[e]),g(e,function(e){var a=e;e.waypoints&&!t&&(a=mt(e.waypoints,!0));var s=a.x,c=a.y,p=a.height||0,l=a.width||0;(s<n||void 0===n)&&(n=s),(c<i||void 0===i)&&(i=c),(s+l>r||void 0===r)&&(r=s+l),(c+p>o||void 0===o)&&(o=c+p)}),{x:n,y:i,height:o-i,width:r-n}}function ft(e){return"waypoints"in e?"connection":"x"in e?"shape":"root"}function yt(e,t){return Math.round(e*t)/t}function vt(e){return u(e)?e+"px":e}function gt(e,t,n){var i=De("g");Ce(i).add(t);var r=void 0!==n?n:e.childNodes.length-1;return e.insertBefore(i,e.childNodes[r]),i}var bt={shape:["x","y","width","height"],connection:["waypoints"]};function xt(e,t,n,i){this._eventBus=t,this._elementRegistry=i,this._graphicsFactory=n,this._init(e||{})}function _t(e,t){var n="matrix("+t.a+","+t.b+","+t.c+","+t.d+","+t.e+","+t.f+")";e.setAttribute("transform",n)}xt.$inject=["config.canvas","eventBus","graphicsFactory","elementRegistry"],xt.prototype._init=function(e){var t=this._eventBus,n=this._container=function(e){var t=(e=z({},{width:"100%",height:"100%"},e)).container||document.body,n=document.createElement("div");return n.setAttribute("class","djs-container"),z(n.style,{position:"relative",overflow:"hidden",width:vt(e.width),height:vt(e.height)}),t.appendChild(n),n}(e),i=this._svg=De("svg");xe(i,{width:"100%",height:"100%"}),ye(n,i);var r=this._viewport=gt(i,"viewport");this._layers={},!1!==e.deferUpdate&&(this._viewboxChanged=I(L(this._viewboxChanged,this),300)),t.on("diagram.init",function(){t.fire("canvas.init",{svg:i,viewport:r})},this),t.on(["shape.added","connection.added","shape.removed","connection.removed","elements.changed"],function(){delete this._cachedViewbox},this),t.on("diagram.destroy",500,this._destroy,this),t.on("diagram.clear",500,this._clear,this)},xt.prototype._destroy=function(e){this._eventBus.fire("canvas.destroy",{svg:this._svg,viewport:this._viewport});var t=this._container.parentNode;t&&t.removeChild(this._container),delete this._svg,delete this._container,delete this._layers,delete this._rootElement,delete this._viewport},xt.prototype._clear=function(){var e=this;this._elementRegistry.getAll().forEach(function(t){var n=ft(t);"root"===n?e.setRootElement(null,!0):e._removeElement(t,n)}),delete this._cachedViewbox},xt.prototype.getDefaultLayer=function(){return this.getLayer("base",0)},xt.prototype.getLayer=function(e,t){if(!e)throw new Error("must specify a name");var n=this._layers[e];if(n||(n=this._layers[e]=this._createLayer(e,t)),void 0!==t&&n.index!==t)throw new Error("layer <"+e+"> already created at index <"+t+">");return n.group},xt.prototype._createLayer=function(e,t){t||(t=0);var n=x(this._layers,function(e,n){return t>=n.index&&e++,e},0);return{group:gt(this._viewport,"layer-"+e,n),index:t}},xt.prototype.getContainer=function(){return this._container},xt.prototype._updateMarker=function(e,t,n){var i;e.id||(e=this._elementRegistry.get(e)),(i=this._elementRegistry._elements[e.id])&&(g([i.gfx,i.secondaryGfx],function(e){e&&(n?Ce(e).add(t):Ce(e).remove(t))}),this._eventBus.fire("element.marker.update",{element:e,gfx:i.gfx,marker:t,add:!!n}))},xt.prototype.addMarker=function(e,t){this._updateMarker(e,t,!0)},xt.prototype.removeMarker=function(e,t){this._updateMarker(e,t,!1)},xt.prototype.hasMarker=function(e,t){return e.id||(e=this._elementRegistry.get(e)),Ce(this.getGraphics(e)).has(t)},xt.prototype.toggleMarker=function(e,t){this.hasMarker(e,t)?this.removeMarker(e,t):this.addMarker(e,t)},xt.prototype.getRootElement=function(){return this._rootElement||this.setRootElement({id:"__implicitroot",children:[]}),this._rootElement},xt.prototype.setRootElement=function(e,t){e&&this._ensureValid("root",e);var n=this._rootElement,i=this._elementRegistry,r=this._eventBus;if(n){if(!t)throw new Error("rootElement already set, need to specify override");r.fire("root.remove",{element:n}),r.fire("root.removed",{element:n}),i.remove(n)}if(e){var o=this.getDefaultLayer();r.fire("root.add",{element:e}),i.add(e,o,this._svg),r.fire("root.added",{element:e,gfx:o})}return this._rootElement=e,e},xt.prototype._ensureValid=function(e,t){if(!t.id)throw new Error("element must have an id");if(this._elementRegistry.get(t.id))throw new Error("element with id "+t.id+" already exists");var n=bt[e];if(!_(n,function(e){return void 0!==t[e]}))throw new Error("must supply { "+n.join(", ")+" } with "+e)},xt.prototype._setParent=function(e,t,n){pt(t.children,e,n),e.parent=t},xt.prototype._addElement=function(e,t,n,i){n=n||this.getRootElement();var r=this._eventBus,o=this._graphicsFactory;this._ensureValid(e,t),r.fire(e+".add",{element:t,parent:n}),this._setParent(t,n,i);var a=o.create(e,t,i);return this._elementRegistry.add(t,a),o.update(e,t,a),r.fire(e+".added",{element:t,gfx:a}),t},xt.prototype.addShape=function(e,t,n){return this._addElement("shape",e,t,n)},xt.prototype.addConnection=function(e,t,n){return this._addElement("connection",e,t,n)},xt.prototype._removeElement=function(e,t){var n=this._elementRegistry,i=this._graphicsFactory,r=this._eventBus;if(e=n.get(e.id||e))return r.fire(t+".remove",{element:e}),i.remove(e),ct(e.parent&&e.parent.children,e),e.parent=null,r.fire(t+".removed",{element:e}),n.remove(e),e},xt.prototype.removeShape=function(e){return this._removeElement(e,"shape")},xt.prototype.removeConnection=function(e){return this._removeElement(e,"connection")},xt.prototype.getGraphics=function(e,t){return this._elementRegistry.getGraphics(e,t)},xt.prototype._changeViewbox=function(e){this._eventBus.fire("canvas.viewbox.changing"),e.apply(this),this._cachedViewbox=null,this._viewboxChanged()},xt.prototype._viewboxChanged=function(){this._eventBus.fire("canvas.viewbox.changed",{viewbox:this.viewbox()})},xt.prototype.viewbox=function(e){if(void 0===e&&this._cachedViewbox)return this._cachedViewbox;var t,n,i,r,o,a,s=this._viewport,c=this.getSize();return e?(this._changeViewbox(function(){r=Math.min(c.width/e.width,c.height/e.height);var t=this._svg.createSVGMatrix().scale(r).translate(-e.x,-e.y);He(s,t)}),e):(t=this.getDefaultLayer().getBBox(),n=(i=He(s))?i.matrix:Be(),r=yt(n.a,1e3),o=yt(-n.e||0,1e3),a=yt(-n.f||0,1e3),e=this._cachedViewbox={x:o?o/r:0,y:a?a/r:0,width:c.width/r,height:c.height/r,scale:r,inner:{width:t.width,height:t.height,x:t.x,y:t.y},outer:c})},xt.prototype.scroll=function(e){var t=this._viewport,n=t.getCTM();return e&&this._changeViewbox(function(){e=z({dx:0,dy:0},e||{}),n=this._svg.createSVGMatrix().translate(e.dx,e.dy).multiply(n),_t(t,n)}),{x:n.e,y:n.f}},xt.prototype.zoom=function(e,t){return e?"fit-viewport"===e?this._fitViewport(t):(this._changeViewbox(function(){"object"!=typeof t&&(n=this.viewbox().outer,t={x:n.width/2,y:n.height/2}),i=this._setZoom(e,t)}),yt(i.a,1e3)):this.viewbox(e).scale;var n,i},xt.prototype._fitViewport=function(e){var t,n,i=this.viewbox(),r=i.outer,o=i.inner;return o.x>=0&&o.y>=0&&o.x+o.width<=r.width&&o.y+o.height<=r.height&&!e?n={x:0,y:0,width:Math.max(o.width+o.x,r.width),height:Math.max(o.height+o.y,r.height)}:(t=Math.min(1,r.width/o.width,r.height/o.height),n={x:o.x+(e?o.width/2-r.width/t/2:0),y:o.y+(e?o.height/2-r.height/t/2:0),width:r.width/t,height:r.height/t}),this.viewbox(n),this.viewbox(!1).scale},xt.prototype._setZoom=function(e,t){var n,i,r,o,a=this._svg,s=this._viewport,c=a.createSVGMatrix(),p=a.createSVGPoint(),l=(i=s.getCTM()).a;return t?(n=z(p,t).matrixTransform(i.inverse()),r=c.translate(n.x,n.y).scale(1/l*e).translate(-n.x,-n.y),o=i.multiply(r)):o=c.scale(e),_t(this._viewport,o),o},xt.prototype.getSize=function(){return{width:this._container.clientWidth,height:this._container.clientHeight}},xt.prototype.getAbsoluteBBox=function(e){var t,n=this.viewbox();e.waypoints?t=this.getGraphics(e).getBBox():t=e;return{x:t.x*n.scale-n.x*n.scale,y:t.y*n.scale-n.y*n.scale,width:t.width*n.scale,height:t.height*n.scale}},xt.prototype.resized=function(){delete this._cachedViewbox,this._eventBus.fire("canvas.resized")};var Et="data-element-id";function wt(e){this._elements={},this._eventBus=e}wt.$inject=["eventBus"],wt.prototype.add=function(e,t,n){var i=e.id;this._validateId(i),xe(t,Et,i),n&&xe(n,Et,i),this._elements[i]={element:e,gfx:t,secondaryGfx:n}},wt.prototype.remove=function(e){var t=this._elements,n=e.id||e,i=n&&t[n];i&&(xe(i.gfx,Et,""),i.secondaryGfx&&xe(i.secondaryGfx,Et,""),delete t[n])},wt.prototype.updateId=function(e,t){this._validateId(t),"string"==typeof e&&(e=this.get(e)),this._eventBus.fire("element.updateId",{element:e,newId:t});var n=this.getGraphics(e),i=this.getGraphics(e,!0);this.remove(e),e.id=t,this.add(e,n,i)},wt.prototype.get=function(e){var t;t="string"==typeof e?e:e&&xe(e,Et);var n=this._elements[t];return n&&n.element},wt.prototype.filter=function(e){var t=[];return this.forEach(function(n,i){e(n,i)&&t.push(n)}),t},wt.prototype.getAll=function(){return this.filter(function(e){return e})},wt.prototype.forEach=function(e){var t=this._elements;Object.keys(t).forEach(function(n){var i=t[n],r=i.element,o=i.gfx;return e(r,o)})},wt.prototype.getGraphics=function(e,t){var n=e.id||e,i=this._elements[n];return i&&(t?i.secondaryGfx:i.gfx)},wt.prototype._validateId=function(e){if(!e)throw new Error("element must have an id");if(this._elements[e])throw new Error("element with id "+e+" already added")};var St={extend:function(e,t,n,i){var r=n.inverse;return Object.defineProperty(e,"remove",{value:function(e){var n=this.indexOf(e);return-1!==n&&(this.splice(n,1),t.unset(e,r,i)),e}}),Object.defineProperty(e,"contains",{value:function(e){return-1!==this.indexOf(e)}}),Object.defineProperty(e,"add",{value:function(e){this.contains(e)||(this.push(e),t.set(e,r,i))}}),Object.defineProperty(e,"__refs_collection",{value:!0}),e},isExtended:function(e){return!0===e.__refs_collection}};function Ct(e,t,n){Object.defineProperty(n,t.name,{enumerable:t.enumerable,value:St.extend(n[t.name]||[],e,t,n)})}function Tt(e,t){if(!(this instanceof Tt))return new Tt(e,t);e.inverse=t,t.inverse=e,this.props={},this.props[e.name]=e,this.props[t.name]=t}Tt.prototype.bind=function(e,t){if("string"==typeof t){if(!this.props[t])throw new Error("no property <"+t+"> in ref");t=this.props[t]}t.collection?Ct(this,t,e):function(e,t,n){var i=t.inverse,r=n[t.name];Object.defineProperty(n,t.name,{enumerable:t.enumerable,get:function(){return r},set:function(t){if(t!==r){var o=r;r=null,o&&e.unset(o,i,n),r=t,e.set(r,i,n)}}})}(this,t,e)},Tt.prototype.ensureRefsCollection=function(e,t){var n=e[t.name];return St.isExtended(n)||Ct(this,t,e),n},Tt.prototype.ensureBound=function(e,t){(function(e,t){return Object.prototype.hasOwnProperty.call(e,t.name||t)})(e,t)||this.bind(e,t)},Tt.prototype.unset=function(e,t,n){e&&(this.ensureBound(e,t),t.collection?this.ensureRefsCollection(e,t).remove(n):e[t.name]=void 0)},Tt.prototype.set=function(e,t,n){e&&(this.ensureBound(e,t),t.collection?this.ensureRefsCollection(e,t).add(n):e[t.name]=n)};var Rt=Tt,At=St;Rt.Collection=At;var Pt=new Rt({name:"children",enumerable:!0,collection:!0},{name:"parent"}),Mt=new Rt({name:"label",enumerable:!0},{name:"labelTarget"}),kt=new Rt({name:"attachers",collection:!0},{name:"host"}),Dt=new Rt({name:"outgoing",collection:!0},{name:"source"}),Nt=new Rt({name:"incoming",collection:!0},{name:"target"});function Bt(){Object.defineProperty(this,"businessObject",{writable:!0}),Pt.bind(this,"parent"),Mt.bind(this,"label"),Dt.bind(this,"outgoing"),Nt.bind(this,"incoming")}function Ot(){Bt.call(this),Pt.bind(this,"children"),kt.bind(this,"host"),kt.bind(this,"attachers")}function It(){Ot.call(this)}function Lt(){Ot.call(this),Mt.bind(this,"labelTarget")}function jt(){Bt.call(this),Dt.bind(this,"source"),Nt.bind(this,"target")}t(Ot,Bt),t(It,Ot),t(Lt,Ot),t(jt,Bt);var zt={connection:jt,shape:Ot,label:Lt,root:It};function Ft(){this._uid=12}Ft.prototype.createRoot=function(e){return this.create("root",e)},Ft.prototype.createLabel=function(e){return this.create("label",e)},Ft.prototype.createShape=function(e){return this.create("shape",e)},Ft.prototype.createConnection=function(e){return this.create("connection",e)},Ft.prototype.create=function(e,t){return(t=z({},t||{})).id||(t.id=e+"_"+this._uid++),function(e,t){var n=zt[e];if(!n)throw new Error("unknown type: <"+e+">");return z(new n,t)}(e,t)};var $t=Array.prototype.slice;function Wt(){this._listeners={},this.on("diagram.destroy",1,this._destroy,this)}function Ht(){}function Gt(e,t,n,i,r){var o=Oe();o.setTranslate(t,n);var a=Oe();a.setRotate(i,0,0);var s=Oe();s.setScale(r||1,r||1),He(e,[o,a,s])}function Vt(e,t,n){var i=Oe();i.setTranslate(t,n),He(e,i)}function qt(e,t){var n=Oe();n.setRotate(t,0,0),He(e,n)}function Ut(e,t){this._eventBus=e,this._elementRegistry=t}function Yt(e,t,n){t.insertBefore(e,n||t.firstChild)}Wt.prototype.on=function(e,t,n,i){if(e=p(e)?e:[e],h(t)&&(i=n,n=t,t=1e3),!u(t))throw new Error("priority must be a number");var r=n;i&&((r=L(n,i)).__fn=n.__fn||n);var o=this,a={priority:t,callback:r};e.forEach(function(e){o._addListener(e,a)})},Wt.prototype.once=function(e,t,n,i){var r=this;if(h(t)&&(i=n,n=t,t=1e3),!u(t))throw new Error("priority must be a number");function o(){return r.off(e,o),n.apply(i,arguments)}o.__fn=n,this.on(e,t,o)},Wt.prototype.off=function(e,t){var n,i,r,o=this._getListeners(e);if(t)for(r=o.length-1;n=o[r];r--)(i=n.callback)!==t&&i.__fn!==t||o.splice(r,1);else o.length=0},Wt.prototype.createEvent=function(e){var t=new Ht;return t.init(e),t},Wt.prototype.fire=function(e,t){var n,i,r,o;if(o=$t.call(arguments),"object"==typeof e&&(e=(n=e).type),!e)throw new Error("no event type specified");if(i=this._listeners[e]){n=t instanceof Ht?t:this.createEvent(t),o[0]=n;var a=n.type;e!==a&&(n.type=e);try{r=this._invokeListeners(n,o,i)}finally{e!==a&&(n.type=a)}return void 0===r&&n.defaultPrevented&&(r=!1),r}},Wt.prototype.handleError=function(e){return!1===this.fire("error",{error:e})},Wt.prototype._destroy=function(){this._listeners={}},Wt.prototype._invokeListeners=function(e,t,n){var i,r,o;for(i=0;(r=n[i])&&!e.cancelBubble;i++)o=this._invokeListener(e,t,r);return o},Wt.prototype._invokeListener=function(e,t,n){var i;try{void 0!==(i=function(e,t){return e.apply(null,t)}(n.callback,t))&&(e.returnValue=i,e.stopPropagation()),!1===i&&e.preventDefault()}catch(e){if(!this.handleError(e))throw console.error("unhandled error in event listener"),console.error(e.stack),e}return i},Wt.prototype._addListener=function(e,t){var n,i,r=this._getListeners(e);for(i=0;n=r[i];i++)if(n.priority<t.priority)return void r.splice(i,0,t);r.push(t)},Wt.prototype._getListeners=function(e){var t=this._listeners[e];return t||(this._listeners[e]=t=[]),t},Ht.prototype.stopPropagation=function(){this.cancelBubble=!0},Ht.prototype.preventDefault=function(){this.defaultPrevented=!0},Ht.prototype.init=function(e){z(this,e||{})},Ut.$inject=["eventBus","elementRegistry"],Ut.prototype._getChildren=function(e){var t,n=this._elementRegistry.getGraphics(e);return e.parent?(t=function(e){return e.parentNode.childNodes[1]}(n))||(Ce(t=De("g")).add("djs-children"),ye(n.parentNode,t)):t=n,t},Ut.prototype._clear=function(e){var t=function(e){return he(".djs-visual",e)}(e);return Y(t),t},Ut.prototype._createContainer=function(e,t,n){var i=De("g");Ce(i).add("djs-group"),void 0!==n?Yt(i,t,t.childNodes[n]):ye(t,i);var r=De("g");Ce(r).add("djs-element"),Ce(r).add("djs-"+e),ye(i,r);var o=De("g");return Ce(o).add("djs-visual"),ye(r,o),r},Ut.prototype.create=function(e,t,n){var i=this._getChildren(t.parent);return this._createContainer(e,i,n)},Ut.prototype.updateContainments=function(e){var t=this,n=this._elementRegistry;g(x(e,function(e,t){return t.parent&&(e[t.parent.id]=t.parent),e},{}),function(e){var i=e.children;if(i){var r=t._getChildren(e);g(i.slice().reverse(),function(e){Yt(n.getGraphics(e).parentNode,r)})}})},Ut.prototype.drawShape=function(e,t){return this._eventBus.fire("render.shape",{gfx:e,element:t})},Ut.prototype.getShapePath=function(e){return this._eventBus.fire("render.getShapePath",e)},Ut.prototype.drawConnection=function(e,t){return this._eventBus.fire("render.connection",{gfx:e,element:t})},Ut.prototype.getConnectionPath=function(e){return this._eventBus.fire("render.getConnectionPath",e)},Ut.prototype.update=function(e,t,n){if(t.parent){var i=this._clear(n);if("shape"===e)this.drawShape(i,t),Vt(n,t.x,t.y);else{if("connection"!==e)throw new Error("unknown type: "+e);this.drawConnection(i,t)}t.hidden?xe(n,"display","none"):xe(n,"display","block")}},Ut.prototype.remove=function(e){Re(this._elementRegistry.getGraphics(e).parentNode)};var Kt={__depends__:[st],__init__:["canvas"],canvas:["type",xt],elementRegistry:["type",wt],elementFactory:["type",Ft],eventBus:["type",Wt],graphicsFactory:["type",Ut]};function Xt(e){var t=[],n=[];function i(e){return t.indexOf(e)>=0}e.forEach(function e(r){i(r)||((r.__depends__||[]).forEach(e),i(r)||(function(e){t.push(e)}(r),(r.__init__||[]).forEach(function(e){n.push(e)})))});var r=new function e(t,n){n=n||{get:function(e,t){if(i.push(e),!1===t)return null;throw s('No provider for "'+e+'"!')}};var i=[],r=this._providers=Object.create(n._providers||null),o=this._instances=Object.create(null),a=o.injector=this,s=function(e){var t=i.join(" -> ");return i.length=0,new Error(t?e+" (Resolving: "+t+")":e)},c=function e(t,a){if(!r[t]&&-1!==t.indexOf(".")){for(var c=t.split("."),p=e(c.shift());c.length;)p=p[c.shift()];return p}if(Je(o,t))return o[t];if(Je(r,t)){if(-1!==i.indexOf(t))throw i.push(t),s("Cannot resolve circular dependency!");return i.push(t),o[t]=r[t][0](r[t][1]),i.pop(),o[t]}return n.get(t,a)},p=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("function"!=typeof e){if(!Ve(e))throw new Error('Cannot invoke "'+e+'". Expected a function!');e=qe(e.slice())}return{fn:e,dependencies:(e.$inject||Xe(e)).map(function(e){return Je(t,e)?t[e]:c(e)})}},l=function(e){var t=p(e),n=t.dependencies,i=t.fn;return new(Function.prototype.bind.apply(i,[null].concat(Qe(n))))},u=function(e,t,n){var i=p(e,n),r=i.dependencies,o=i.fn;return o.call.apply(o,[t].concat(Qe(r)))},h=function(e){return qe(function(t){return e.get(t)})},d={factory:u,type:l,value:function(e){return e}};t.forEach(function(t){function n(e,t){return"value"!==e&&Ve(t)&&(t=qe(t.slice())),t}if(t instanceof function(){var e=[];this.factory=function(t,n){return e.push([t,"factory",n]),this},this.value=function(t,n){return e.push([t,"value",n]),this},this.type=function(t,n){return e.push([t,"type",n]),this},this.forEach=function(t){e.forEach(t)}})t.forEach(function(e){var t=e[0],i=e[1],o=e[2];r[t]=[d[i],n(i,o),i]});else if("object"===(void 0===t?"undefined":Ze(t)))if(t.__exports__){var i=Object.keys(t).reduce(function(e,n){return"__"!==n.substring(0,2)&&(e[n]=t[n]),e},Object.create(null)),o=new e((t.__modules__||[]).concat([i]),a),s=qe(function(e){return o.get(e)});t.__exports__.forEach(function(e){r[e]=[s,e,"private",o]})}else Object.keys(t).forEach(function(e){if("private"!==t[e][2]){var i=t[e][0],o=t[e][1];r[e]=[d[i],n(i,o),i]}else r[e]=t[e]})}),this.get=c,this.invoke=u,this.instantiate=l,this.createChild=function(t,n){if(n&&n.length){var i,o,s,c,p=Object.create(null),l=Object.create(null),u=[],d=[],m=[];for(var f in r)i=r[f],-1!==n.indexOf(f)&&("private"===i[2]?-1===(o=u.indexOf(i[3]))?(s=i[3].createChild([],n),c=h(s),u.push(i[3]),d.push(s),m.push(c),p[f]=[c,f,"private",s]):p[f]=[m[o],f,"private",d[o]]:p[f]=[i[2],i[1]],l[f]=!0),"factory"!==i[2]&&"type"!==i[2]||!i[1].$scope||n.forEach(function(e){-1!==i[1].$scope.indexOf(e)&&(p[f]=[i[2],i[1]],l[e]=!0)});n.forEach(function(e){if(!l[e])throw new Error('No provider for "'+e+'". Cannot use provider from the parent!')}),t.unshift(p)}return new e(t,a)}}(t);return n.forEach(function(e){try{r["string"==typeof e?"get":"invoke"](e)}catch(e){throw console.error("Failed to instantiate component"),console.error(e.stack),e}}),r}function Zt(e,t){this.injector=t=t||function(e){return Xt([{config:["value",e=e||{}]},Kt].concat(e.modules||[]))}(e),this.get=t.get,this.invoke=t.invoke,this.get("eventBus").fire("diagram.init")}Zt.prototype.destroy=function(){this.get("eventBus").fire("diagram.destroy")},Zt.prototype.clear=function(){this.get("eventBus").fire("diagram.clear")};var Qt=Object.freeze({default:Zt}),Jt=Qt&&Zt||Qt;function en(){}function tn(e,t){this.model=e,this.properties=t}en.prototype.get=function(e){return this.$model.properties.get(this,e)},en.prototype.set=function(e,t){this.$model.properties.set(this,e,t)},tn.prototype.createType=function(e){var t=this.model,n=this.properties,i=Object.create(en.prototype);g(e.properties,function(e){e.isMany||void 0===e.default||(i[e.name]=e.default)}),n.defineModel(i,t),n.defineDescriptor(i,e);var r=e.ns.name;function o(e){n.define(this,"$type",{value:r,enumerable:!0}),n.define(this,"$attrs",{value:{}}),n.define(this,"$parent",{writable:!0}),g(e,L(function(e,t){this.set(t,e)},this))}return o.prototype=i,o.hasType=i.$instanceOf=this.model.hasType,n.defineModel(o,t),n.defineDescriptor(o,e),o};var nn={String:!0,Boolean:!0,Integer:!0,Real:!0,Element:!0},rn={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 on(e,t){var n=rn[e];return n?n(t):t}function an(e){return!!nn[e]}function sn(e){return!!rn[e]}function cn(e,t){var n,i,r=e.split(/:/);if(1===r.length)n=e,i=t;else{if(2!==r.length)throw new Error("expected <prefix:localName> or <localName>, got "+e);n=r[1],i=r[0]}return{name:e=(i?i+":":"")+n,prefix:i,localName:n}}function pn(e){this.ns=e,this.name=e.name,this.allTypes=[],this.allTypesByName={},this.properties=[],this.propertiesByName={}}function ln(e,t){this.packageMap={},this.typeMap={},this.packages=[],this.properties=t,g(e,L(this.registerPackage,this))}function un(e,t,n){var i=t[n];if(i in e)throw new Error("package with "+n+" <"+i+"> already defined")}function hn(e){this.model=e}function dn(e,t,n){Object.defineProperty(e,t.name,{enumerable:!t.isReference,writable:!0,value:n,configurable:!0})}function mn(e){this.properties=new hn(this),this.factory=new tn(this,this.properties),this.registry=new ln(e,this.properties),this.typeCache={}}pn.prototype.build=function(){return F(this,["ns","name","allTypes","allTypesByName","properties","propertiesByName","bodyProperty","idProperty"])},pn.prototype.addProperty=function(e,t,n){"boolean"==typeof t&&(n=t,t=void 0),this.addNamedProperty(e,!1!==n);var i=this.properties;void 0!==t?i.splice(t,0,e):i.push(e)},pn.prototype.replaceProperty=function(e,t,n){var i=e.ns,r=this.properties,o=this.propertiesByName,a=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 s=r.indexOf(e);if(-1===s)throw new Error("property <"+i.name+"> not found in property list");r.splice(s,1),this.addProperty(t,n?void 0:s,a),o[i.name]=o[i.localName]=t},pn.prototype.redefineProperty=function(e,t,n){var i=e.ns.prefix,r=t.split("#"),o=cn(r[0],i),a=cn(r[1],o.prefix).name,s=this.propertiesByName[a];if(!s)throw new Error("refined property <"+a+"> not found");this.replaceProperty(s,e,n),delete e.redefines},pn.prototype.addNamedProperty=function(e,t){var n=e.ns,i=this.propertiesByName;t&&(this.assertNotDefined(e,n.name),this.assertNotDefined(e,n.localName)),i[n.name]=i[n.localName]=e},pn.prototype.removeNamedProperty=function(e){var t=e.ns,n=this.propertiesByName;delete n[t.name],delete n[t.localName]},pn.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},pn.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},pn.prototype.assertNotDefined=function(e,t){var n=e.name,i=this.propertiesByName[n];if(i)throw new Error("property <"+n+"> already defined; override of <"+i.definedBy.ns.name+"#"+i.ns.name+"> by <"+e.definedBy.ns.name+"#"+e.ns.name+"> not allowed without redefines")},pn.prototype.hasProperty=function(e){return this.propertiesByName[e]},pn.prototype.addTrait=function(e,t){var n=this.allTypesByName,i=this.allTypes,r=e.name;r in n||(g(e.properties,L(function(n){n=z({},n,{name:n.ns.localName,inherited:t}),Object.defineProperty(n,"definedBy",{value:e});var i=n.replaces,r=n.redefines;i||r?this.redefineProperty(n,i||r,i):(n.isBody&&this.setBodyProperty(n),n.isId&&this.setIdProperty(n),this.addProperty(n))},this)),i.push(e),n[r]=e)},ln.prototype.getPackage=function(e){return this.packageMap[e]},ln.prototype.getPackages=function(){return this.packages},ln.prototype.registerPackage=function(e){e=z({},e);var t=this.packageMap;un(t,e,"prefix"),un(t,e,"uri"),g(e.types,L(function(t){this.registerType(t,e)},this)),t[e.uri]=t[e.prefix]=e,this.packages.push(e)},ln.prototype.registerType=function(e,t){var n=cn((e=z({},e,{superClass:(e.superClass||[]).slice(),extends:(e.extends||[]).slice(),properties:(e.properties||[]).slice(),meta:z(e.meta||{})})).name,t.prefix),i=n.name,r={};g(e.properties,L(function(e){var t=cn(e.name,n.prefix),i=t.name;an(e.type)||(e.type=cn(e.type,t.prefix).name),z(e,{ns:t,name:i}),r[i]=e},this)),z(e,{ns:n,name:i,propertiesByName:r}),g(e.extends,L(function(e){var t=this.typeMap[e];t.traits=t.traits||[],t.traits.push(i)},this)),this.definePackage(e,t),this.typeMap[i]=e},ln.prototype.mapTypes=function(e,t,n){var i=an(e.name)?{name:e.name}:this.typeMap[e.name],r=this;function o(e){return a(e,!0)}function a(n,i){var o=cn(n,an(n)?"":e.prefix);r.mapTypes(o,t,i)}if(!i)throw new Error("unknown type <"+e.name+">");g(i.superClass,n?o:a),t(i,!n),g(i.traits,o)},ln.prototype.getEffectiveDescriptor=function(e){var t=cn(e),n=new pn(t);this.mapTypes(t,function(e,t){n.addTrait(e,t)});var i=n.build();return this.definePackage(i,i.allTypes[i.allTypes.length-1].$pkg),i},ln.prototype.definePackage=function(e,t){this.properties.define(e,"$pkg",{value:t})},hn.prototype.set=function(e,t,n){var i=this.model.getPropertyDescriptor(e,t),r=i&&i.name;void 0===n?i?delete e[r]:delete e.$attrs[t]:i?r in e?e[r]=n:dn(e,i,n):e.$attrs[t]=n},hn.prototype.get=function(e,t){var n=this.model.getPropertyDescriptor(e,t);if(!n)return e.$attrs[t];var i=n.name;return!e[i]&&n.isMany&&dn(e,n,[]),e[i]},hn.prototype.define=function(e,t,n){Object.defineProperty(e,t,n)},hn.prototype.defineDescriptor=function(e,t){this.define(e,"$descriptor",{value:t})},hn.prototype.defineModel=function(e,t){this.define(e,"$model",{value:t})},mn.prototype.create=function(e,t){var n=this.getType(e);if(!n)throw new Error("unknown type <"+e+">");return new n(t)},mn.prototype.getType=function(e){var t=this.typeCache,n=d(e)?e:e.ns.name,i=t[n];return i||(e=this.registry.getEffectiveDescriptor(n),i=t[n]=this.factory.createType(e)),i},mn.prototype.createAny=function(e,t,n){var i=cn(e),r={$type:e,$instanceOf:function(e){return e===this.$type}},o={name:e,isGeneric:!0,ns:{prefix:i.prefix,localName:i.localName,uri:t}};return this.properties.defineDescriptor(r,o),this.properties.defineModel(r,this),this.properties.define(r,"$parent",{enumerable:!1,writable:!0}),g(n,function(e,t){l(e)&&void 0!==e.value?r[e.name]=e.value:r[t]=e}),r},mn.prototype.getPackage=function(e){return this.registry.getPackage(e)},mn.prototype.getPackages=function(){return this.registry.getPackages()},mn.prototype.getElementDescriptor=function(e){return e.$descriptor},mn.prototype.hasType=function(e,t){return void 0===t&&(t=e,e=this),t in e.$model.getElementDescriptor(e).allTypesByName},mn.prototype.getPropertyDescriptor=function(e,t){return this.getElementDescriptor(e).propertiesByName[t]},mn.prototype.getTypeDescriptor=function(e){return this.registry.typeMap[e]};var fn=e(function(e,t){ /** * Tiny stack for browser or server * * @copyright 2015 Jason Mulligan <jason.mulligan@avoidwork.com> * @license BSD-3-Clause * @version 1.0.0 */ !function(t){function n(){this.data=[null],this.top=0}n.prototype.clear=function(){return this.data=[null],this.top=0,this},n.prototype.length=function(){return this.top},n.prototype.empty=function(){return 0===this.top},n.prototype.peek=function(){return this.data[this.top]},n.prototype.pop=function(){return this.top>0?(this.top--,this.data.pop()):void 0},n.prototype.push=function(e){return this.data[++this.top]=e,this},n.prototype.search=function(e){var t=this.data.indexOf(e);return-1===t?-1:this.data.length-t},e.exports=function(){return new n}}()}),yn=String.fromCharCode,vn=Object.prototype.hasOwnProperty,gn=/&#(\d+);|&#x([0-9a-f]+);|&(\w+);/gi,bn={amp:"&",apos:"'",gt:">",lt:"<",quot:'"'};function xn(e,t,n,i){return i?vn.call(bn,i)?bn[i]:"&"+i+";":yn(t||parseInt(n,16))}function _n(e){return e.length>3&&-1!==e.indexOf("&")?e.replace(gn,xn):e}Object.keys(bn).forEach(function(e){bn[e.toUpperCase()]=bn[e]});var En="http://www.w3.org/2001/XMLSchema-instance",wn="xsi",Sn="xsi:type";function Cn(e){return new Error(e)}function Tn(e){return"missing namespace for prefix <"+e+">"}function Rn(e){return{get:e,enumerable:!0}}function An(e){var t,n={};for(t in e)n[t]=e[t];return n}function Pn(e){return e+"$uri"}function Mn(){return{line:0,column:0}}function kn(e){throw e}function Dn(e){if(!this)return new Dn(e);var t,n,i,r,o,a,s,c,p,l=e&&e.proxy,u=kn,h=Mn,d=!1,m=!1,f=null,y=!1;function v(e){e instanceof Error||(e=Cn(e)),f=e,u(e,h)}function g(e){o&&(e instanceof Error||(e=Cn(e)),o(e,h))}this.on=function(e,p){if("function"!=typeof p)throw Cn("required args <name, cb>");switch(e){case"openTag":n=p;break;case"text":t=p;break;case"closeTag":i=p;break;case"error":u=p;break;case"warn":o=p;break;case"cdata":r=p;break;case"attention":c=p;break;case"question":s=p;break;case"comment":a=p;break;default:throw Cn("unsupported event: "+e)}return this},this.ns=function(e){if(void 0===e&&(e={}),"object"!=typeof e)throw Cn("required args <nsMap={}>");var t,n={};for(t in e)n[t]=e[t];return n[En]=wn,m=!0,p=n,this},this.parse=function(e){if("string"!=typeof e)throw Cn("required args <xml=string>");return f=null,function(e){var o,u,f,b,x,_,E,w,S,C,T=m?[]:null,R=m?function(e){var t,n,i={};for(t in e)i[n=e[t]]=n,i[Pn(n)]=t;return i}(p):null,A=[],P=0,M=!1,k=!1,D=0,N=0,B="",O=0;function I(){if(null!==C)return C;var e,t,n,i,r,o,a,s,c,l,u,h=m&&R.xmlns,f=m&&d?[]:null,y=O,v=B,b=v.length,x={},_={};e:for(;y<b;y++)if(c=!1,!(32===(l=v.charCodeAt(y))||l<14&&l>8)){for((l<65||l>122||l>90&&l<97)&&95!==l&&58!==l&&(g("illegal first char attribute name"),c=!0),u=y+1;u<b;u++)if(!((l=v.charCodeAt(u))>96&&l<123||l>64&&l<91||l>47&&l<59||46===l||45===l||95===l)){if(32===l||l<14&&l>8){g("missing attribute value"),y=u;continue e}if(61===l)break;g("illegal attribute name char"),c=!0}if("xmlns:xmlns"===(s=v.substring(y,u))&&(g("illegal declaration of xmlns"),c=!0),34===(l=v.charCodeAt(u+1)))-1===(u=v.indexOf('"',y=u+2))&&-1!==(u=v.indexOf("'",y))&&(g("attribute value quote missmatch"),c=!0);else if(39===l)-1===(u=v.indexOf("'",y=u+2))&&-1!==(u=v.indexOf('"',y))&&(g("attribute value quote missmatch"),c=!0);else for(g("missing attribute value quotes"),c=!0,u+=1;u<b&&!(32===(l=v.charCodeAt(u+1))||l<14&&l>8);u++);for(-1===u&&(g("missing closing quotes"),u=b,c=!0),c||(o=v.substring(y,u)),y=u;u+1<b&&!(32===(l=v.charCodeAt(u+1))||l<14&&l>8);u++)y===u&&(g("illegal character after attribute end"),c=!0);if(y=u+1,!c)if(s in _)g("attribute <"+s+"> already defined");else if(_[s]=!0,m)if(d){if(null!==(r="xmlns"===s?"xmlns":120===s.charCodeAt(0)&&"xmlns:"===s.substr(0,6)?s.substr(6):null)){if(e=_n(o),t=Pn(r),!(a=p[e])){if("xmlns"===r||t in R&&R[t]!==e)do{a="ns"+P++}while(void 0!==R[a]);else a=r;p[e]=a}R[r]!==a&&(i||(R=An(R),i=!0),R[r]=a,"xmlns"===r&&(R[Pn(a)]=e,h=a),R[t]=e),x[s]=o;continue}f.push(s,o)}else-1!==(l=s.indexOf(":"))?(n=R[s.substring(0,l)])?((s=h===n?s.substr(l+1):n+s.substr(l))===Sn&&(-1!==(l=o.indexOf(":"))?(n=o.substring(0,l),n=R[n]||n,o=n+o.substring(l)):o=h+":"+o),x[s]=o):g(Tn(s.substring(0,l))):x[s]=o;else x[s]=o}if(d)for(y=0,b=f.length;y<b;y++){