UNPKG

nomnoml

Version:

The sassy UML renderer that generates diagrams from text

1 lines 97.6 kB
var WebApp=function(e,t,n,r){"use strict";function i(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}function o(e,t){return t.forEach((function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach((function(n){if("default"!==n&&!(n in e)){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}}))})),Object.freeze(e)}var a=i(t),s=i(n);function c(e){return e.replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#x27;/g,"'").replace(/&#x60;/g,"`")}function l(e,t,n={}){var r,i,o,a,s=0,c=function(){s=!1===n.leading?0:Date.now(),r=null,a=e.apply(i,o),r||(i=o=null)};return function(){var l=Date.now();s||!1!==n.leading||(s=l);var d=t-(l-s);return i=this,o=arguments,d<=0||d>t?(r&&(clearTimeout(r),r=null),s=l,a=e.apply(i,o),r||(i=o=null)):r||!1===n.trailing||(r=setTimeout(c,d)),a}}function d(e,t,n=!1){var r,i;function o(t,n){r=null,n&&(i=e.apply(t,n))}return function(...a){if(r&&clearTimeout(r),n){var s=!r;r=setTimeout(o,t),s&&(i=e.apply(this,a))}else r=function(e,t,...n){return setTimeout((()=>e.apply(null,n)),t)}(o,t,this,a);return i}}function h(e,t){return{x:e.x-t.x,y:e.y-t.y}}class u{constructor(e,t){this.onChange=t,this.offset={x:0,y:0},this.zoomLevel=0,this.superSampling=window.devicePixelRatio||1;var n=!1;var r=()=>{n=!1,e.style.width="33%"};e.addEventListener("mousedown",(t=>{e.style.width="100%",n=h({x:t.pageX,y:t.pageY},this.offset)})),e.addEventListener("mouseup",r),e.addEventListener("mouseleave",r),e.addEventListener("wheel",l((e=>{this.zoomLevel=Math.min(10,this.zoomLevel-(e.deltaY<0?-1:1)),t()}),50),{passive:!0}),e.addEventListener("mousemove",l((e=>{0!=n&&(this.offset=h({x:e.pageX,y:e.pageY},n),t())}),50),{passive:!0})}positionCanvas(e){var t=window,n=e.width/this.superSampling,r=e.height/this.superSampling;e.style.top=300*(1-r/t.innerHeight)+this.offset.y+"px",e.style.left=150+(t.innerWidth-n)/2+this.offset.x+"px",e.style.width=n+"px",e.style.height=r+"px"}zoom(){return this.superSampling*Math.exp(this.zoomLevel/10)}magnify(e){this.zoomLevel=Math.min(10,this.zoomLevel+e),this.onChange()}reset(){this.zoomLevel=1,this.offset={x:0,y:0},this.onChange()}}class f{constructor(e,t){this.editor=e,this.lineNumbers=t}clearState(){this.mark?.clear(),this.lineMark?.clear(),this.lineNumbers.classList.remove("error")}setError(e){this.mark?.clear(),this.lineMark?.clear(),this.lineNumbers.classList.add("error"),this.lineMark=this.editor.markText({line:e.line-1,ch:0},{line:e.line-1,ch:100},{css:"background: #f884"}),this.mark=this.editor.markText({line:e.line-1,ch:e.column-2},{line:e.line-1,ch:e.column+1},{css:"background: #f88a"})}}var g="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function p(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function v(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}var m,y={exports:{}};var w,x=p((m||(m=1,w=y,function(){function e(e,t){return void 0===t?t={autoBom:!1}:"object"!=typeof t&&(console.warn("Deprecated: Expected third argument to be a object"),t={autoBom:!t}),t.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)?new Blob(["\ufeff",e],{type:e.type}):e}function t(e,t,n){var r=new XMLHttpRequest;r.open("GET",e),r.responseType="blob",r.onload=function(){a(r.response,t,n)},r.onerror=function(){console.error("could not download file")},r.send()}function n(e){var t=new XMLHttpRequest;t.open("HEAD",e,!1);try{t.send()}catch(e){}return 200<=t.status&&299>=t.status}function r(e){try{e.dispatchEvent(new MouseEvent("click"))}catch(n){var t=document.createEvent("MouseEvents");t.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),e.dispatchEvent(t)}}var i="object"==typeof window&&window.window===window?window:"object"==typeof self&&self.self===self?self:"object"==typeof g&&g.global===g?g:void 0,o=i.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),a=i.saveAs||("object"!=typeof window||window!==i?function(){}:"download"in HTMLAnchorElement.prototype&&!o?function(e,o,a){var s=i.URL||i.webkitURL,c=document.createElement("a");o=o||e.name||"download",c.download=o,c.rel="noopener","string"==typeof e?(c.href=e,c.origin===location.origin?r(c):n(c.href)?t(e,o,a):r(c,c.target="_blank")):(c.href=s.createObjectURL(e),setTimeout((function(){s.revokeObjectURL(c.href)}),4e4),setTimeout((function(){r(c)}),0))}:"msSaveOrOpenBlob"in navigator?function(i,o,a){if(o=o||i.name||"download","string"!=typeof i)navigator.msSaveOrOpenBlob(e(i,a),o);else if(n(i))t(i,o,a);else{var s=document.createElement("a");s.href=i,s.target="_blank",setTimeout((function(){r(s)}))}}:function(e,n,r,a){if((a=a||open("","_blank"))&&(a.document.title=a.document.body.innerText="downloading..."),"string"==typeof e)return t(e,n,r);var s="application/octet-stream"===e.type,c=/constructor/i.test(i.HTMLElement)||i.safari,l=/CriOS\/[\d]+/.test(navigator.userAgent);if((l||s&&c||o)&&"undefined"!=typeof FileReader){var d=new FileReader;d.onloadend=function(){var e=d.result;e=l?e:e.replace(/^data:[^;]*;/,"data:attachment/file;"),a?a.location.href=e:location=e,a=null},d.readAsDataURL(e)}else{var h=i.URL||i.webkitURL,u=h.createObjectURL(e);a?a.location=u:location.href=u,a=null,setTimeout((function(){h.revokeObjectURL(u)}),4e4)}});i.saveAs=a.saveAs=a,w.exports=a}()),y.exports));class b{constructor(e){this.canvasElement=e,this.filename="graph",this.source=""}pngDownload(){var e=this.canvasElement;e.msToBlob?x(e.msToBlob(),this.filename+".png"):this.canvasElement.toBlob((e=>x(e,this.filename+".png")))}svgDownload(e){var t=e(this.source,document);x(new Blob([t],{type:"image/svg+xml"}),this.filename+".svg")}srcDownload(){var e=this.source;x(new Blob([e],{type:"text/txt"}),this.filename+".nomnoml")}setFilename(e){e=e||"nomnoml",this.filename=e.replace(/[^ a-zA-Z0-9_-]/g,"_")}}class k{constructor(){this.callbacks={}}on(e,t){this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t)}off(e,t){var n=this.callbacks[e];if(n){var r=n.indexOf(t);-1!==r&&n.splice(r,1),0===n.length&&delete this.callbacks[e]}}trigger(e,...t){var n=this.callbacks[e];if(n)for(let e of n)e.apply(null,t)}}class E{constructor(e,t){this.context=e,this.path=t}static from(e){var t=e.indexOf("/");return"#"==e[0]&&t>-1?{context:E.urlDecode(e.substr(1,t-1)),path:E.urlDecode(e.substr(t+1))}:{context:"",path:""}}static urlEncode(e){return encodeURIComponent(e).replace(/'/g,"%27").replace(/"/g,"%22")}static urlDecode(e){return decodeURIComponent(e.replace(/\+/g," "))}}class _{constructor(){this.signals=new k,this.activeFile={name:"",date:"1970-01-01",backingStore:"url"},this.storage=new M}finishedInsertingFiles(){this.signals.trigger("updated")}async moveToFileStorage(e,t){new N(e).insert(t),this.signals.trigger("updated")}async moveToLocalStorage(e){this.storage=new M,await this.storage.save(e)}async discard(e){var t=new N(e.name);await t.clear(),this.signals.trigger("updated")}async configureByRoute(e){var t=E.from(e);this.storage=this.routedStorage(t);var n=await this.storage.files();this.activeFile=n.find((e=>e.name===t.path))??S(t.path,"local_file"),this.signals.trigger("updated")}routedStorage(e){return"view"===e.context?new z(decodeURIComponent(e.path)):"file"===e.context?new N(e.path):new M}}function S(e,t){return{date:(new Date).toISOString(),name:e,backingStore:t}}class M{constructor(){this.kind="local_default",this.storageKey="nomnoml.lastSource"}async files(){return JSON.parse(localStorage["nomnoml.file_index"]||"[]")}async read(){return localStorage[this.storageKey]}async insert(e){}async save(e){localStorage[this.storageKey]=e}async clear(){}}class z{constructor(e){this.source=e,this.kind="url"}async files(){return JSON.parse(localStorage["nomnoml.file_index"]||"[]")}async read(){return this.source}async insert(e){}async save(e){}async clear(){}}class N{constructor(e){this.name=e,this.kind="local_file",this.storageKey="nomnoml.files/"+e}async files(){return JSON.parse(localStorage["nomnoml.file_index"]||"[]")}async read(){return localStorage[this.storageKey]}async insert(e){var t=S(this.name,"local_file"),n=await this.files();n.find((e=>e.name===this.name))||(n.push(t),n.sort(((e,t)=>e.name.localeCompare(t.name))),localStorage["nomnoml.file_index"]=JSON.stringify(n)),localStorage[this.storageKey]=e}async save(e){localStorage[this.storageKey]=e}async clear(){localStorage.removeItem(this.storageKey);var e=(await this.files()).filter((e=>e.name!=this.name));localStorage["nomnoml.file_index"]=JSON.stringify(e)}}class L{constructor(e,t,n){function r(n){return function(){n?t.classList.add(e):t.classList.remove(e)}}for(var i of n)i.addEventListener("mouseenter",r(!0)),i.addEventListener("mouseleave",r(!1))}}var T,I,C,O={exports:{}},j={exports:{}};j.exports;function P(){return T||(T=1,function(e,t){!function(e){class t{constructor(){var e={};e._next=e._prev=e,this._sentinel=e}dequeue(){var e=this._sentinel,t=e._prev;if(t!==e)return n(t),t}enqueue(e){var t=this._sentinel,r=e;r._prev&&r._next&&n(r),r._next=t._next,t._next._prev=r,t._next=r,r._prev=t}toString(){for(var e=[],t=this._sentinel,n=t._prev;n!==t;)e.push(JSON.stringify(n,r)),n=n._prev;return"["+e.join(", ")+"]"}}function n(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function r(e,t){if("_next"!==e&&"_prev"!==e)return t}var i=Object.freeze({__proto__:null,List:t});const o={};function a(e){var t=[];for(var n of e)t.push(...n);return t}function s(e,t){return null!=e&&e.hasOwnProperty(t)}function c(e){const t=null==e?0:e.length;return t?e[t-1]:void 0}function l(e,t){e=Object(e);const n={};return Object.keys(e).forEach((r=>{n[r]=t(e[r],r)})),n}function d(e,t){var n=Number.POSITIVE_INFINITY,r=void 0;for(var i of e){var o=t(i);o<n&&(n=o,r=i)}return r}function h(e,t){var n=e<t?1:-1;let r=-1,i=Math.max(Math.ceil((t-e)/(n||1)),0);const o=new Array(i);for(;i--;)o[++r]=e,e+=n;return o}function u(e,t){return e.slice().sort(((e,n)=>t(e)-t(n)))}function f(e){return o[e]||(o[e]=0),`${e}${++o[e]}`}function g(e){return e?Object.keys(e).map((t=>e[t])):[]}function p(e,t){for(var n=[],r=0;r<e;r++)n.push(t());return n}function v(e){return void 0===e}function m(e,t){for(var n of Object.keys(e))t(e[n],n)}function y(e){return 0===Object.keys(e).length}function w(e){var t={},n=e.nodes().filter((t=>!e.children(t).length)),r=p(Math.max(...n.map((t=>e.node(t).rank)))+1,(()=>[]));return u(n,(t=>e.node(t).rank)).forEach((function n(i){if(!s(t,i)){t[i]=!0;var o=e.node(i);r[o.rank].push(i),e.successors(i).forEach(n)}})),r}function x(e,t){for(var n=0,r=1;r<t.length;++r)n+=b(e,t[r-1],t[r]);return n}function b(e,t,n){for(var r={},i=0;i<n.length;i++)r[n[i]]=i;for(var o=a(t.map((function(t){return u(e.outEdges(t).map((function(t){return{pos:r[t.w],weight:e.edge(t).weight}})),(e=>e.pos))}))),s=1;s<n.length;)s<<=1;var c=2*s-1;s-=1;var l=p(c,(()=>0)),d=0;return o.forEach((function(e){var t=e.pos+s;l[t]+=e.weight;for(var n=0;t>0;)t%2&&(n+=l[t+1]),l[t=t-1>>1]+=e.weight;d+=e.weight*n})),d}function k(e,t){return t?t.map((function(t){var n=e.inEdges(t);if(n.length){var r=n.reduce((function(t,n){var r=e.edge(n),i=e.node(n.v);return{sum:t.sum+r.weight*i.order,weight:t.weight+r.weight}}),{sum:0,weight:0});return{v:t,barycenter:r.sum/r.weight,weight:r.weight}}return{v:t}})):[]}function E(e,t){for(var n={},r=0;r<e.length;r++){var i=e[r],o=n[i.v]={indegree:0,in:[],out:[],vs:[i.v],i:r};void 0!==i.barycenter&&(o.barycenter=i.barycenter,o.weight=i.weight)}for(var a of t.edges()){var s=n[a.v],c=n[a.w];void 0!==s&&void 0!==c&&(c.indegree++,s.out.push(n[a.w]))}return function(e){var t=[];function n(e){return function(t){t.merged||(void 0===t.barycenter||void 0===e.barycenter||t.barycenter>=e.barycenter)&&function(e,t){var n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}(e,t)}}function r(t){return function(n){n.in.push(t),0==--n.indegree&&e.push(n)}}for(;e.length;){var i=e.pop();t.push(i),i.in.reverse().forEach(n(i)),i.out.forEach(r(i))}return t.filter((e=>!e.merged)).map((function(e){var t={vs:e.vs,i:e.i};return"barycenter"in e&&(t.barycenter=e.barycenter),"weight"in e&&(t.weight=e.weight),t}))}(g(n).filter((e=>!e.indegree)))}var _="\0";class S{constructor(e={}){this._label=void 0,this._nodeCount=0,this._edgeCount=0,this._isDirected=!s(e,"directed")||e.directed,this._isMultigraph=!!s(e,"multigraph")&&e.multigraph,this._isCompound=!!s(e,"compound")&&e.compound,this._defaultNodeLabelFn=()=>{},this._defaultEdgeLabelFn=()=>{},this._nodes={},this._isCompound&&(this._parent={},this._children={},this._children["\0"]={}),this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={}}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(e){return this._label=e,this}graph(){return this._label}setDefaultNodeLabel(e){var t;return t=e,this._defaultNodeLabelFn="function"!=typeof t?()=>e:e,this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var e=this;return this.nodes().filter((function(t){return y(e._in[t])}))}sinks(){var e=this;return this.nodes().filter((t=>y(e._out[t])))}setNodes(e,t){for(var n of e)void 0!==t?this.setNode(n,t):this.setNode(n);return this}setNode(e,t){return s(this._nodes,e)?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]=_,this._children[e]={},this._children["\0"][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)}node(e){return this._nodes[e]}hasNode(e){return s(this._nodes,e)}removeNode(e){var t=this;if(s(this._nodes,e)){var n=e=>{t.removeEdge(this._edgeObjs[e])};if(delete this._nodes[e],this._isCompound){for(var r of(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e)))t.setParent(r);delete this._children[e]}for(var i of Object.keys(this._in[e]))n(i);for(var i of(delete this._in[e],delete this._preds[e],Object.keys(this._out[e])))n(i);delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,t){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(void 0===t)t=_;else{for(var n=t+="";!v(n);n=this.parent(n))if(n===e)throw new Error(`Setting ${t} as parent of ${e} would create a cycle`);this.setNode(t)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=t,this._children[t][e]=!0,this}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}parent(e){if(this._isCompound){var t=this._parent[e];if(t!==_)return t}}children(e){if(v(e)&&(e=_),this._isCompound){var t=this._children[e];return t?Object.keys(t):void 0}return e===_?this.nodes():this.hasNode(e)?[]:void 0}predecessors(e){var t=this._preds[e];if(t)return Object.keys(t)}successors(e){var t=this._sucs[e];if(t)return Object.keys(t)}neighbors(e){var t=this.predecessors(e);if(t)return function(e,t){var n=[...e];for(var r of t)-1===n.indexOf(r)&&n.push(r);return n}(t,this.successors(e))}isLeaf(e){return 0===(this.isDirected()?this.successors(e):this.neighbors(e)).length}filterNodes(e){var t=new S({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph());var n=this;m(this._nodes,(function(n,r){e(r)&&t.setNode(r,n)})),m(this._edgeObjs,(function(e){t.hasNode(e.v)&&t.hasNode(e.w)&&t.setEdge(e,n.edge(e))}));var r={};function i(e){var o=n.parent(e);return void 0===o||t.hasNode(o)?(r[e]=o,o):o in r?r[o]:i(o)}if(this._isCompound)for(var o of t.nodes())t.setParent(o,i(o));return t}setDefaultEdgeLabel(e){var t;return t=e,this._defaultEdgeLabelFn="function"!=typeof t?()=>e:e,this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,t){var n=this,r=arguments;return e.reduce((function(e,i){return r.length>1?n.setEdge(e,i,t):n.setEdge(e,i),i})),this}setEdge(e,t,n,r){var i=!1,o=e;"object"==typeof o&&null!==o&&"v"in o?(e=o.v,t=o.w,r=o.name,2===arguments.length&&(n=arguments[1],i=!0)):(e=o,t=arguments[1],r=arguments[3],arguments.length>2&&(n=arguments[2],i=!0)),e=""+e,t=""+t,v(r)||(r=""+r);var a=L(this._isDirected,e,t,r);if(s(this._edgeLabels,a))return i&&(this._edgeLabels[a]=n),this;if(!v(r)&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(e),this.setNode(t),this._edgeLabels[a]=i?n:this._defaultEdgeLabelFn(e,t,r);var c=function(e,t,n,r){var i=""+t,o=""+n;if(!e&&i>o){var a=i;i=o,o=a}var s={v:i,w:o};return r&&(s.name=r),s}(this._isDirected,e,t,r);return e=c.v,t=c.w,Object.freeze(c),this._edgeObjs[a]=c,z(this._preds[t],e),z(this._sucs[e],t),this._in[t][a]=c,this._out[e][a]=c,this._edgeCount++,this}edge(e,t,n){var r="object"==typeof e?T(this._isDirected,e):L(this._isDirected,e,t,n);return this._edgeLabels[r]}hasEdge(e,t,n){var r=1===arguments.length?T(this._isDirected,arguments[0]):L(this._isDirected,e,t,n);return s(this._edgeLabels,r)}removeEdge(e,t,n){var r="object"==typeof e?T(this._isDirected,e):L(this._isDirected,e,t,n),i=this._edgeObjs[r];return i&&(e=i.v,t=i.w,delete this._edgeLabels[r],delete this._edgeObjs[r],N(this._preds[t],e),N(this._sucs[e],t),delete this._in[t][r],delete this._out[e][r],this._edgeCount--),this}inEdges(e,t){var n=this._in[e];if(n){var r=Object.values(n);return t?r.filter((function(e){return e.v===t})):r}}outEdges(e,t){var n=this._out[e];if(n){var r=Object.values(n);return t?r.filter((function(e){return e.w===t})):r}}nodeEdges(e,t){var n=this.inEdges(e,t);if(n)return n.concat(this.outEdges(e,t))}}class M extends S{}function z(e,t){e[t]?e[t]++:e[t]=1}function N(e,t){--e[t]||delete e[t]}function L(e,t,n,r){var i=""+t,o=""+n;if(!e&&i>o){var a=i;i=o,o=a}return i+""+o+""+(v(r)?"\0":r)}function T(e,t){return L(e,t.v,t.w,t.name)}function I(e,t,n,r){var i;do{i=f(r)}while(e.hasNode(i));return n.dummy=t,e.setNode(i,n),i}function C(e){var t=(new S).setGraph(e.graph());for(var n of e.nodes())t.setNode(n,e.node(n));for(var r of e.edges()){var i=t.edge(r.v,r.w)||{weight:0,minlen:1},o=e.edge(r);t.setEdge(r.v,r.w,{weight:i.weight+o.weight,minlen:Math.max(i.minlen,o.minlen)})}return t}function O(e){var t=new S({multigraph:e.isMultigraph()}).setGraph(e.graph());for(var n of e.nodes())e.children(n).length||t.setNode(n,e.node(n));for(var r of e.edges())t.setEdge(r,e.edge(r));return t}function j(e,t){var n,r,i=e.x,o=e.y,a=t.x-i,s=t.y-o,c=e.width/2,l=e.height/2;if(!a&&!s)throw new Error("Not possible to find intersection inside of the rectangle");return Math.abs(s)*c>Math.abs(a)*l?(s<0&&(l=-l),n=l*a/s,r=l):(a<0&&(c=-c),n=c,r=c*s/a),{x:i+n,y:o+r}}function P(e){var t=p(F(e)+1,(()=>[]));for(var n of e.nodes()){var r=e.node(n),i=r.rank;void 0!==i&&(t[i][r.order]=n)}return t}function A(e){var t=Math.min(...e.nodes().map((t=>e.node(t).rank)).filter((e=>void 0!==e)));for(var n of e.nodes()){var r=e.node(n);s(r,"rank")&&(r.rank-=t)}}function R(e){var t=Math.min(...e.nodes().map((t=>e.node(t).rank)).filter((e=>void 0!==e))),n=[];for(var r of e.nodes()){var i=e.node(r).rank-t;n[i]||(n[i]=[]),n[i].push(r)}for(var o=0,a=e.graph().nodeRankFactor,s=0;s<n.length;s++){var c=n[s];if(void 0===c&&s%a!=0)--o;else if(o&&null!=c)for(var r of c)e.node(r).rank+=o}}function D(e,t,n,r){var i={width:0,height:0};return arguments.length>=4&&(i.rank=n,i.order=r),I(e,"border",i,t)}function F(e){var t=e.nodes().map((t=>e.node(t).rank)).filter((e=>void 0!==e));return Math.max(...t)}function B(e,t){var n=[],r=[];for(var i of e)t(i)?n.push(i):r.push(i);return{lhs:n,rhs:r}}function $(e,t){var n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function q(e,t){return t()}var V=Object.freeze({__proto__:null,addDummyNode:I,simplify:C,asNonCompoundGraph:O,successorWeights:function(e){var t={};for(var n of e.nodes()){var r={};for(var i of e.outEdges(n))r[i.w]=(r[i.w]||0)+e.edge(i).weight;t[n]=r}return t},predecessorWeights:function(e){var t={};for(var n of e.nodes()){var r={};for(var i of e.inEdges(n))r[i.v]=(r[i.v]||0)+e.edge(i).weight;t[n]=r}return t},intersectRect:j,buildLayerMatrix:P,normalizeRanks:A,removeEmptyRanks:R,addBorderNode:D,maxRank:F,partition:B,time:$,notime:q});function G(e,t){var n,r=B(e,(function(e){return s(e,"barycenter")})),i=r.lhs,o=u(r.rhs,(e=>-e.i)),c=[],l=0,d=0,h=0;for(var f of(i.sort((n=!!t,function(e,t){return e.barycenter<t.barycenter?-1:e.barycenter>t.barycenter?1:n?t.i-e.i:e.i-t.i})),h=W(c,o,h),i))h+=f.vs.length,c.push(f.vs),l+=f.barycenter*f.weight,d+=f.weight,h=W(c,o,h);var g={vs:a(c)};return d&&(g.barycenter=l/d,g.weight=d),g}function W(e,t,n){for(var r;t.length&&(r=c(t)).i<=n;)t.pop(),e.push(r.vs),n++;return n}function H(e,t,n,r){var i=e.children(t),o=e.node(t),c=o?o.borderLeft:void 0,l=o?o.borderRight:void 0,d={};c&&(i=i.filter((e=>e!==c&&e!==l)));var h=k(e,i);for(var u of h)if(e.children(u.v).length){var f=H(e,u.v,n,r);d[u.v]=f,s(f,"barycenter")&&Y(u,f)}var g=E(h,n);!function(e,t){for(var n of e)n.vs=a(n.vs.map((function(e){return t[e]?t[e].vs:[e]})))}(g,d);var p=G(g,r);if(c&&(p.vs=[c,...p.vs,l],e.predecessors(c).length)){var v=e.node(e.predecessors(c)[0]),m=e.node(e.predecessors(l)[0]);s(p,"barycenter")||(p.barycenter=0,p.weight=0),p.barycenter=(p.barycenter*p.weight+v.order+m.order)/(p.weight+2),p.weight+=2}return p}function Y(e,t){void 0!==e.barycenter?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}function J(e,t,n){var r=function(e){for(var t;e.hasNode(t=f("_root")););return t}(e),i=new S({compound:!0}).setGraph({root:r}).setDefaultNodeLabel((t=>e.node(t)));for(var o of e.nodes()){var a=e.node(o),c=e.parent(o);if(a.rank===t||a.minRank<=t&&t<=a.maxRank){for(var l of(i.setNode(o),i.setParent(o,c||r),e[n](o))){var d=l.v===o?l.w:l.v,h=i.edge(d,o),u=void 0!==h?h.weight:0;i.setEdge(d,o,{weight:e.edge(l).weight+u})}s(a,"minRank")&&i.setNode(o,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]})}}return i}function U(e,t,n){var r,i={};for(var o of n)!function(){for(var n,a=e.parent(o);a;){var s=e.parent(a);if(s?(n=i[s],i[s]=a):(n=r,r=a),n&&n!==a)return void t.setEdge(n,a);a=s}}()}function K(e){var t=F(e),n=Q(e,h(1,t+1),"inEdges"),r=Q(e,h(t-1,-1),"outEdges"),i=w(e);X(e,i);for(var o,a=Number.POSITIVE_INFINITY,s=0,c=0;c<4;++s,++c){Z(s%2?n:r,s%4>=2);var l=x(e,i=P(e));l<a&&(c=0,o=i.map((e=>e.slice(0))),a=l)}X(e,o)}function Q(e,t,n){return t.map((t=>J(e,t,n)))}function Z(e,t){var n=new S;for(var r of e){var i=r.graph().root,o=H(r,i,n,t);o.vs.map((function(e,t){r.node(e).order=t})),U(r,n,o.vs)}}function X(e,t){for(var n of t)n.map((function(t,n){e.node(t).order=n}))}var ee=Object.freeze({__proto__:null,order:K,addSubgraphConstraints:U,barycenter:k,buildLayerGraph:J,crossCount:x,initOrder:w,resolveConflicts:E,sortSubgraph:H,sort:G});function te(e,t){var n={};return t.reduce((function(t,r){for(var i=0,o=0,a=t.length,s=c(r),l=0;l<r.length;l++){var d=r[l],h=re(e,d),u=h?e.node(h).order:a;if(h||d===s){for(var f of r.slice(o,l+1))for(var g of e.predecessors(f)){var p=e.node(g),v=p.order;!(v<i||u<v)||p.dummy&&e.node(f).dummy||ie(n,g,f)}o=l+1,i=u}}return r})),n}function ne(e,t){var n={};function r(t,r,i,o,a){var s;for(var c of h(r,i))if(s=t[c],e.node(s).dummy)for(var l of e.predecessors(s)){var d=e.node(l);d.dummy&&(d.order<o||d.order>a)&&ie(n,l,s)}}return t.reduce((function(t,n){for(var i,o=-1,a=0,s=0;s<n.length;s++){var c=s,l=n[s];if(void 0!==l){if("border"===e.node(l).dummy){var d=e.predecessors(l);d.length&&(r(n,a,c,o,i=e.node(d[0]).order),a=c,o=i)}r(n,a,n.length,i,t.length)}}return n})),n}function re(e,t){if(e.node(t).dummy)for(var n of e.predecessors(t))if(e.node(n).dummy)return n}function ie(e,t,n){if(t>n){var r=t;t=n,n=r}var i=e[t];i||(e[t]=i={}),i[n]=!0}function oe(e,t,n){if(t>n){var r=t;t=n,n=r}return s(e[t],n)}function ae(e,t,n,r){var i={},o={},a={};for(var s of t)for(var c=0;c<s.length;c++)i[d=s[c]]=d,o[d]=d,a[d]=c;for(var s of t){var l=-1;for(var d of s){var h=r(d);if(h.length)for(var f=((h=u(h,(e=>a[e]))).length-1)/2,g=Math.floor(f),p=Math.ceil(f);g<=p;++g){var v=h[g];o[d]===d&&l<a[v]&&!oe(n,d,v)&&(o[v]=d,o[d]=i[d]=i[v],l=a[v])}}}return{root:i,align:o}}function se(e,t,n,r,i){var o={},a=function(e,t,n,r){var i=new S,o=e.graph(),a=ue(o.nodesep,o.edgesep,r);for(var s of t){var c=null;for(var l of s){var d=n[l];if(i.setNode(d),c){var h=n[c],u=i.edge(h,d);i.setEdge(h,d,Math.max(a(e,l,c),u||0))}c=l}}return i}(e,t,n,i),s=i?"borderLeft":"borderRight";function c(e,t){for(var n=a.nodes(),r=n.pop(),i={};r;)i[r]?e(r):(i[r]=!0,n.push(r),n=n.concat(t(r))),r=n.pop()}for(var l of(c((function(e){o[e]=a.inEdges(e).reduce((function(e,t){return Math.max(e,o[t.v]+a.edge(t))}),0)}),(e=>a.predecessors(e))),c((function(t){var n=a.outEdges(t).reduce((function(e,t){return Math.min(e,o[t.w]-a.edge(t))}),Number.POSITIVE_INFINITY),r=e.node(t);n!==Number.POSITIVE_INFINITY&&r.borderType!==s&&(o[t]=Math.max(o[t],n))}),(e=>a.successors(e))),Object.keys(r))){var d=r[l];o[d]=o[n[d]]}return o}function ce(e,t){return d(g(t),(function(t){var n=Number.NEGATIVE_INFINITY,r=Number.POSITIVE_INFINITY;for(var i in t){var o=t[i],a=fe(e,i)/2;n=Math.max(o+a,n),r=Math.min(o-a,r)}return n-r}))}function le(e,t){var n=g(t),r=Math.min(...n),i=Math.max(...n);for(var o of["ul","ur","dl","dr"]){var a=o[1],s=e[o];if(s!==t){var c=g(s),d="l"===a?r-Math.min(...c):i-Math.max(...c);d&&(e[o]=l(s,(e=>e+d)))}}}function de(e,t){return l(e.ul,(function(n,r){if(t)return e[t.toLowerCase()][r];var i=u([e.ul[r],e.ur[r],e.dl[r],e.dr[r]],(e=>e));return(i[1]+i[2])/2}))}function he(e){var t,n=P(e),r=Object.assign(Object.assign({},te(e,n)),ne(e,n)),i={ul:{},ur:{},dl:{},dr:{}};for(var o of["u","d"])for(var a of(t="u"===o?n:n.map((e=>e)).reverse(),["l","r"])){"r"===a&&(t=t.map((e=>e.map((e=>e)).reverse())));var s=ae(0,t,r,("u"===o?e.predecessors:e.successors).bind(e)),c=se(e,t,s.root,s.align,"r"===a);"r"===a&&(c=l(c,(e=>-e))),i[o+a]=c}return le(i,ce(e,i)),de(i,e.graph().align)}function ue(e,t,n){return function(r,i,o){var a,c=r.node(i),l=r.node(o),d=0;if(d+=c.width/2,s(c,"labelpos"))switch(c.labelpos.toLowerCase()){case"l":a=-c.width/2;break;case"r":a=c.width/2}if(a&&(d+=n?a:-a),a=0,d+=(c.dummy?t:e)/2,d+=(l.dummy?t:e)/2,d+=l.width/2,s(l,"labelpos"))switch(l.labelpos.toLowerCase()){case"l":a=l.width/2;break;case"r":a=-l.width/2}return a&&(d+=n?a:-a),a=0,d}}function fe(e,t){return e.node(t).width}var ge=Object.freeze({__proto__:null,findType1Conflicts:te,findType2Conflicts:ne,findOtherInnerSegmentNode:re,addConflict:ie,hasConflict:oe,verticalAlignment:ae,horizontalCompaction:se,findSmallestWidthAlignment:ce,alignCoordinates:le,balance:de,positionX:he,sep:ue,width:fe});function pe(e){!function(e){var t=P(e),n=e.graph().ranksep,r=0;for(var i of t){var o=Math.max(...i.map((t=>e.node(t).height)));for(var a of i)e.node(a).y=r+o/2;r+=o+n}}(e=O(e));var t=he(e);for(var n in t)e.node(n).x=t[n]}var ve=Object.freeze({__proto__:null,bk:ge,position:pe});function me(e){var t={};e.sources().forEach((function n(r){var i=e.node(r);if(s(t,r))return i.rank;t[r]=!0;var o=Math.min(...e.outEdges(r).map((t=>n(t.w)-e.edge(t).minlen)));return o!==Number.POSITIVE_INFINITY&&null!=o||(o=0),i.rank=o}))}function ye(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}function we(e){var t,n=new S({directed:!1}),r=e.nodes()[0],i=e.nodeCount();for(n.setNode(r,{});o(e)<i;)t=a(e),s(e,n.hasNode(t.v)?ye(e,t):-ye(e,t));return n;function o(e){return n.nodes().forEach((function t(r){for(var i of e.nodeEdges(r)){var o=i.v,a=r===o?i.w:o;n.hasNode(a)||ye(e,i)||(n.setNode(a,{}),n.setEdge(r,a,{}),t(a))}})),n.nodeCount()}function a(e){return d(e.edges(),(function(t){if(n.hasNode(t.v)!==n.hasNode(t.w))return ye(e,t)}))}function s(e,t){for(var r of n.nodes())e.node(r).rank+=t}}class xe{constructor(){this._arr=[],this._keyIndices={}}size(){return this._arr.length}keys(){return this._arr.map((function(e){return e.key}))}has(e){return e in this._keyIndices}priority(e){var t=this._keyIndices[e];if(void 0!==t)return this._arr[t].priority}min(){if(0===this.size())throw new Error("Queue underflow");return this._arr[0].key}add(e,t){var n=this._keyIndices;if(!((e=String(e))in n)){var r=this._arr,i=r.length;return n[e]=i,r.push({key:e,priority:t}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,t){var n=this._keyIndices[e];if(t>this._arr[n].priority)throw new Error("New priority is greater than current priority. Key: "+e+" Old: "+this._arr[n].priority+" New: "+t);this._arr[n].priority=t,this._decrease(n)}_heapify(e){var t=this._arr,n=2*e,r=n+1,i=e;n<t.length&&(i=t[n].priority<t[i].priority?n:i,r<t.length&&(i=t[r].priority<t[i].priority?r:i),i!==e&&(this._swap(e,i),this._heapify(i)))}_decrease(e){for(var t,n=this._arr,r=n[e].priority;0!==e&&!(n[t=e>>1].priority<r);)this._swap(e,t),e=t}_swap(e,t){var n=this._arr,r=this._keyIndices,i=n[e],o=n[t];n[e]=o,n[t]=i,r[o.key]=e,r[i.key]=t}}var be=()=>1;function ke(e,t,n,r){return function(e,t,n,r){var i,o,a={},s=new xe,c=function(e){var t=e.v!==i?e.v:e.w,r=a[t],c=n(e),l=o.distance+c;if(c<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+e+" Weight: "+c);l<r.distance&&(r.distance=l,r.predecessor=i,s.decrease(t,l))};for(e.nodes().forEach((function(e){var n=e===t?0:Number.POSITIVE_INFINITY;a[e]={distance:n},s.add(e,n)}));s.size()>0&&(i=s.removeMin(),(o=a[i]).distance!==Number.POSITIVE_INFINITY);)r(i).forEach(c);return a}(e,String(t),n||be,r||function(t){return e.outEdges(t)})}function Ee(e){var t=0,n=[],r={},i=[];function o(a){var s=r[a]={onStack:!0,lowlink:t,index:t++};if(n.push(a),e.successors(a).forEach((function(e){e in r?r[e].onStack&&(s.lowlink=Math.min(s.lowlink,r[e].index)):(o(e),s.lowlink=Math.min(s.lowlink,r[e].lowlink))})),s.lowlink===s.index){var c,l=[];do{c=n.pop(),r[c].onStack=!1,l.push(c)}while(a!==c);i.push(l)}}return e.nodes().forEach((function(e){e in r||o(e)})),i}var _e=()=>1;class Se extends Error{}function Me(e){var t={},n={},r=[];function i(o){if(o in n)throw new Se;if(!(o in t)){for(var a of(n[o]=!0,t[o]=!0,e.predecessors(o)))i(a);delete n[o],r.push(o)}}for(var o of e.sinks())i(o);if(Object.keys(t).length!==e.nodeCount())throw new Se;return r}function ze(e,t,n){var r=Array.isArray(t)?t:[t],i=(e.isDirected()?e.successors:e.neighbors).bind(e),o=[],a={};for(var s of r){if(!e.hasNode(s))throw new Error("Graph does not have node: "+s);Ne(e,s,"post"===n,a,i,o)}return o}function Ne(e,t,n,r,i,o){if(!(t in r)){for(var a of(r[t]=!0,n||o.push(t),i(t)))Ne(e,a,n,r,i,o);n&&o.push(t)}}function Le(e,t){return ze(e,t,"post")}function Te(e,t){return ze(e,t,"pre")}var Ie=Object.freeze({__proto__:null,components:function(e){var t,n={},r=[];function i(r){if(!(r in n)){for(var o of(n[r]=!0,t.push(r),e.successors(r)))i(o);for(var a of e.predecessors(r))i(a)}}for(var o of e.nodes())t=[],i(o),t.length&&r.push(t);return r},dijkstra:ke,dijkstraAll:function(e,t,n){var r={};for(var i of e.nodes())r[i]=ke(e,i,t,n);return r},findCycles:function(e){return Ee(e).filter((function(t){return t.length>1||1===t.length&&e.hasEdge(t[0],t[0])}))},floydWarshall:function(e,t,n){return function(e,t,n){var r={},i=e.nodes();return i.forEach((function(e){r[e]={},r[e][e]={distance:0},i.forEach((function(t){e!==t&&(r[e][t]={distance:Number.POSITIVE_INFINITY})})),n(e).forEach((function(n){var i=n.v===e?n.w:n.v,o=t(n);r[e][i]={distance:o,predecessor:e}}))})),i.forEach((function(e){var t=r[e];i.forEach((function(n){var o=r[n];i.forEach((function(n){var r=o[e],i=t[n],a=o[n],s=r.distance+i.distance;s<a.distance&&(a.distance=s,a.predecessor=i.predecessor)}))}))})),r}(e,t||_e,n||function(t){return e.outEdges(t)})},isAcyclic:function(e){try{Me(e)}catch(e){if(e instanceof Se)return!1;throw e}return!0},postorder:Le,preorder:Te,prim:function(e,t){var n,r=new M({}),i={},o=new xe;function a(e){var r=e.v===n?e.w:e.v,a=o.priority(r);if(void 0!==a){var s=t(e);s<a&&(i[r]=n,o.decrease(r,s))}}if(0===e.nodeCount())return r;for(n of e.nodes())o.add(n,Number.POSITIVE_INFINITY),r.setNode(n);o.decrease(e.nodes()[0],0);for(var s=!1;o.size()>0;){if((n=o.removeMin())in i)r.setEdge(n,i[n]);else{if(s)throw new Error("Input graph is not connected: "+e);s=!0}e.nodeEdges(n).forEach(a)}return r},tarjan:Ee,topsort:Me});function Ce(e){me(e=C(e));var t,n=we(e);for(Ae(n),Oe(n,e);t=De(n);)Be(n,e,t,Fe(n,e,t))}function Oe(e,t){var n=Le(e,e.nodes());for(var r of n=n.slice(0,n.length-1))je(e,t,r)}function je(e,t,n){var r=e.node(n).parent;e.edge(n,r).cutvalue=Pe(e,t,n)}function Pe(e,t,n){var r,i,o=e.node(n).parent,a=!0,s=t.edge(n,o),c=0;for(var l of(s||(a=!1,s=t.edge(o,n)),c=s.weight,t.nodeEdges(n))){var d=l.v===n,h=d?l.w:l.v;if(h!==o){var u=d===a,f=t.edge(l).weight;if(c+=u?f:-f,r=n,i=h,e.hasEdge(r,i)){var g=e.edge(n,h).cutvalue;c+=u?-g:g}}}return c}function Ae(e,t){arguments.length<2&&(t=e.nodes()[0]),Re(e,{},1,t)}function Re(e,t,n,r,i){var o=n,a=e.node(r);for(var c of(t[r]=!0,e.neighbors(r)))s(t,c)||(n=Re(e,t,n,c,r));return a.low=o,a.lim=n++,i?a.parent=i:delete a.parent,n}function De(e){for(var t of e.edges())if(e.edge(t).cutvalue<0)return t}function Fe(e,t,n){var r=n.v,i=n.w;t.hasEdge(r,i)||(r=n.w,i=n.v);var o=e.node(r),a=e.node(i),s=o,c=!1;return o.lim>a.lim&&(s=a,c=!0),d(t.edges().filter((function(t){return c===$e(e,e.node(t.v),s)&&c!==$e(e,e.node(t.w),s)})),(e=>ye(t,e)))}function Be(e,t,n,r){var i=n.v,o=n.w;e.removeEdge(i,o),e.setEdge(r.v,r.w,{}),Ae(e),Oe(e,t),function(e,t){var n=function(e,t){for(var n of e.nodes())if(!t.node(n).parent)return n}(e,t),r=Te(e,n);for(var i of r=r.slice(1)){var o=e.node(i).parent,a=t.edge(i,o),s=!1;a||(a=t.edge(o,i),s=!0),t.node(i).rank=t.node(o).rank+(s?a.minlen:-a.minlen)}}(e,t)}function $e(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}function qe(e){switch(e.graph().ranker){case"network-simplex":default:We(e);break;case"tight-tree":Ge(e);break;case"longest-path":Ve(e)}}Ce.initLowLimValues=Ae,Ce.initCutValues=Oe,Ce.calcCutValue=Pe,Ce.leaveEdge=De,Ce.enterEdge=Fe,Ce.exchangeEdges=Be;var Ve=me;function Ge(e){me(e),we(e)}function We(e){Ce(e)}var He=Object.freeze({__proto__:null,rank:qe,tightTreeRanker:Ge,networkSimplexRanker:We,networkSimplex:Ce,feasibleTree:we,longestPath:me}),Ye=e=>1;function Je(e,n){if(e.nodeCount()<=1)return[];var r=function(e,n){var r=new S,i=0,o=0;for(var a of e.nodes())r.setNode(a,{v:a,in:0,out:0});for(var s of e.edges()){var c=r.edge(s.v,s.w)||0,l=n(s),d=c+l;r.setEdge(s.v,s.w,d),o=Math.max(o,r.node(s.v).out+=l),i=Math.max(i,r.node(s.w).in+=l)}var h=p(o+i+3,(()=>new t)),u=i+1;for(var a of r.nodes())Ke(h,u,r.node(a));return{graph:r,buckets:h,zeroIdx:u}}(e,n||Ye);return a(function(e,t,n){for(var r,i=[],o=t[t.length-1],a=t[0];e.nodeCount();){for(;r=a.dequeue();)Ue(e,t,n,r);for(;r=o.dequeue();)Ue(e,t,n,r);if(e.nodeCount())for(var s=t.length-2;s>0;--s)if(r=t[s].dequeue()){i=i.concat(Ue(e,t,n,r,!0));break}}return i}(r.graph,r.buckets,r.zeroIdx).map((t=>e.outEdges(t.v,t.w))))}function Ue(e,t,n,r,i){var o=i?[]:void 0;for(var a of e.inEdges(r.v)){var s=e.edge(a),c=e.node(a.v);i&&o.push({v:a.v,w:a.w}),c.out-=s,Ke(t,n,c)}for(var a of e.outEdges(r.v)){s=e.edge(a);var l=a.w,d=e.node(l);d.in-=s,Ke(t,n,d)}return e.removeNode(r.v),o}function Ke(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}var Qe={run:function(e){var t="greedy"===e.graph().acyclicer?Je(e,function(e){return function(t){return e.edge(t).weight}}(e)):function(e){var t=[],n={},r={};function i(o){if(!s(r,o)){for(var a of(r[o]=!0,n[o]=!0,e.outEdges(o)))s(n,a.w)?t.push(a):i(a.w);delete n[o]}}return e.nodes().forEach(i),t}(e);for(var n of t){var r=e.edge(n);e.removeEdge(n),r.forwardName=n.name,r.reversed=!0,e.setEdge(n.w,n.v,r,f("rev"))}},undo:function(e){for(var t of e.edges()){var n=e.edge(t);if(n.reversed){e.removeEdge(t);var r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}}}};function Ze(e){e.children().forEach((function t(n){var r=e.children(n),i=e.node(n);if(r.length&&r.forEach(t),s(i,"minRank")){i.borderLeft=[],i.borderRight=[];for(var o=i.minRank,a=i.maxRank+1;o<a;++o)Xe(e,"borderLeft","_bl",n,i,o),Xe(e,"borderRight","_br",n,i,o)}}))}function Xe(e,t,n,r,i,o){var a={width:0,height:0,rank:o,borderType:t},s=i[t][o-1],c=I(e,"border",a,n);i[t][o]=c,e.setParent(c,r),s&&e.setEdge(s,c,{weight:1})}var et={adjust:function(e){var t=e.graph().rankdir.toLowerCase();"lr"!==t&&"rl"!==t||tt(e)},undo:function(e){var t=e.graph().rankdir.toLowerCase();"bt"!==t&&"rl"!==t||function(e){for(var t of e.nodes())rt(e.node(t));for(var n of e.edges()){var r=e.edge(n);r.points.forEach(rt),s(r,"y")&&rt(r)}}(e),"lr"!==t&&"rl"!==t||(function(e){for(var t of e.nodes())it(e.node(t));for(var n of e.edges()){var r=e.edge(n);r.points.forEach(it),s(r,"x")&&it(r)}}(e),tt(e))}};function tt(e){for(var t of e.nodes())nt(e.node(t));for(var n of e.edges())nt(e.edge(n))}function nt(e){var t=e.width;e.width=e.height,e.height=t}function rt(e){e.y=-e.y}function it(e){var t=e.x;e.x=e.y,e.y=t}var ot=Object.freeze({__proto__:null,debugOrdering:function(e){var t=P(e),n=new S({compound:!0,multigraph:!0}).setGraph({});for(var r of e.nodes())n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank);for(var i of e.edges())n.setEdge(i.v,i.w,{},i.name);var o=0;for(var a of t){var s="layer"+o;o++,n.setNode(s,{rank:"same"}),a.reduce((function(e,t){return n.setEdge(e.toString(),t,{style:"invis"}),t}))}return n}}),at={run:function(e){for(var t of(e.graph().dummyChains=[],e.edges()))st(e,t)},undo:function(e){for(var t of e.graph().dummyChains){var n,r=e.node(t),i=r.edgeLabel;for(e.setEdge(r.edgeObj,i);r.dummy;)n=e.successors(t)[0],e.removeNode(t),i.points.push({x:r.x,y:r.y}),"edge-label"===r.dummy&&(i.x=r.x,i.y=r.y,i.width=r.width,i.height=r.height),t=n,r=e.node(t)}}};function st(e,t){var n=t.v,r=e.node(n).rank,i=t.w,o=e.node(i).rank,a=t.name,s=e.edge(t),c=s.labelRank;if(o!==r+1){var l,d,h;for(e.removeEdge(t),h=0,++r;r<o;++h,++r)s.points=[],l=I(e,"edge",d={width:0,height:0,edgeLabel:s,edgeObj:t,rank:r},"_d"),r===c&&(d.width=s.width,d.height=s.height,d.dummy="edge-label",d.labelpos=s.labelpos),e.setEdge(n,l,{weight:s.weight},a),0===h&&e.graph().dummyChains.push(l),n=l;e.setEdge(n,i,{weight:s.weight},a)}}function ct(e){var t=function(e){var t={},n=0;function r(i){var o=n;e.children(i).forEach(r),t[i]={low:o,lim:n++}}return e.children().forEach(r),t}(e);for(var n of e.graph().dummyChains)for(var r=e.node(n),i=r.edgeObj,o=lt(e,t,i.v,i.w),a=o.path,s=o.lca,c=0,l=a[c],d=!0;n!==i.w;){if(r=e.node(n),d){for(;(l=a[c])!==s&&e.node(l).maxRank<r.rank;)c++;l===s&&(d=!1)}if(!d){for(;c<a.length-1&&e.node(l=a[c+1]).minRank<=r.rank;)c++;l=a[c]}e.setParent(n,l),n=e.successors(n)[0]}}function lt(e,t,n,r){var i,o,a=[],s=[],c=Math.min(t[n].low,t[r].low),l=Math.max(t[n].lim,t[r].lim);i=n;do{i=e.parent(i),a.push(i)}while(i&&(t[i].low>c||l>t[i].lim));for(o=i,i=r;(i=e.parent(i))!==o;)s.push(i);return{path:a.concat(s.reverse()),lca:o}}var dt={run:function(e){var t=I(e,"root",{},"_root"),n=function(e){var t={};function n(r,i){var o=e.children(r);if(o&&o.length)for(var a of o)n(a,i+1);t[r]=i}for(var r of e.children())n(r,1);return t}(e),r=Math.max(...g(n))-1,i=2*r+1;for(var o of(e.graph().nestingRoot=t,e.edges()))e.edge(o).minlen*=i;var a=function(e){return e.edges().reduce(((t,n)=>t+e.edge(n).weight),0)}(e)+1;for(var s of e.children())ht(e,t,i,a,r,n,s);e.graph().nodeRankFactor=i},cleanup:function(e){var t=e.graph();for(var n of(e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges()))e.edge(n).nestingEdge&&e.removeEdge(n)}};function ht(e,t,n,r,i,o,a){var s=e.children(a);if(s.length){var c=D(e,"_bt"),l=D(e,"_bb"),d=e.node(a);for(var h of(e.setParent(c,a),d.borderTop=c,e.setParent(l,a),d.borderBottom=l,s)){ht(e,t,n,r,i,o,h);var u=e.node(h),f=u.borderTop?u.borderTop:h,g=u.borderBottom?u.borderBottom:h,p=u.borderTop?r:2*r,v=f!==g?1:i-o[a]+1;e.setEdge(c,f,{weight:p,minlen:v,nestingEdge:!0}),e.setEdge(g,l,{weight:p,minlen:v,nestingEdge:!0})}e.parent(a)||e.setEdge(t,c,{weight:0,minlen:i+o[a]})}else a!==t&&e.setEdge(t,a,{weight:0,minlen:n})}function ut(e){return"edge-proxy"==e.dummy}function ft(e){return"selfedge"==e.dummy}var gt=50,pt=20,vt=50,mt="tb",yt=1,wt=1,xt=0,bt=0,kt=10,Et="r";function _t(e={}){var t={};for(var n of Object.keys(e))t[n.toLowerCase()]=e[n];return t}function St(e){return e.nodes().map((function(t){var n=e.node(t),r=e.parent(t),i={v:t};return void 0!==n&&(i.value=n),void 0!==r&&(i.parent=r),i}))}function Mt(e){return e.edges().map((function(t){var n=e.edge(t),r={v:t.v,w:t.w};return void 0!==t.name&&(r.name=t.name),void 0!==n&&(r.value=n),r}))}var zt=Object.freeze({__proto__:null,write:function(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:St(e),edges:Mt(e)};return void 0!==e.graph()&&(t.value=JSON.parse(JSON.stringify(e.graph()))),t},read:function(e){var t=new S(e.options).setGraph(e.value);for(var n of e.nodes)t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent);for(var n of e.edges)t.setEdge({v:n.v,w:n.w,name:n.name},n.value);return t}}),Nt={Graph:S,GraphLike:M,alg:Ie,json:zt,PriorityQueue:xe};e.Graph=S,e.GraphLike=M,e.PriorityQueue=xe,e.acyclic=Qe,e.addBorderSegments=Ze,e.alg=Ie,e.coordinateSystem=et,e.data=i,e.debug=ot,e.graphlib=Nt,e.greedyFAS=Je,e.json=zt,e.layout=function(e,t){var n=t&&t.debugTiming?$:q;n("layout",(function(){var t=n(" buildLayoutGraph",(function(){return function(e){var t,n,r,i,o,a,s,c,l,d,h,u,f,g,p,v=new S({multigraph:!0,compound:!0}),m=_t(e.graph()),y={nodesep:null!==(t=m.nodesep)&&void 0!==t?t:vt,edgesep:null!==(n=m.edgesep)&&void 0!==n?n:pt,ranksep:null!==(r=m.ranksep)&&void 0!==r?r:gt,marginx:+(null!==(i=m.marginx)&&void 0!==i?i:0),marginy:+(null!==(o=m.marginy)&&void 0!==o?o:0),acyclicer:m.acyclicer,ranker:null!==(a=m.ranker)&&void 0!==a?a:"network-simplex",rankdir:null!==(s=m.rankdir)&&void 0!==s?s:mt,align:m.align};for(var w of(v.setGraph(y),e.nodes())){var x=_t(e.node(w)),b={width:+(null!==(c=x&&x.width)&&void 0!==c?c:0),height:+(null!==(l=x&&x.height)&&void 0!==l?l:0)};v.setNode(w,b),v.setParent(w,e.parent(w))}for(var k of e.edges()){var E=_t(e.edge(k)),_={minlen:null!==(d=E.minlen)&&void 0!==d?d:yt,weight:null!==(h=E.weight)&&void 0!==h?h:wt,width:null!==(u=E.width)&&void 0!==u?u:xt,height:null!==(f=E.height)&&void 0!==f?f:bt,labeloffset:null!==(g=E.labeloffset)&&void 0!==g?g:kt,labelpos:null!==(p=E.labelpos)&&void 0!==p?p:Et};v.setEdge(k,_)}return v}(e)}));n(" runLayout",(function(){!function(e,t){t(" makeSpaceForEdgeLabels",(function(){!function(e){var t=e.graph();for(var n of(t.ranksep/=2,e.edges())){var r=e.edge(n);r.minlen*=2,"c"!==r.labelpos.toLowerCase()&&("TB"===t.rankdir||"BT"===t.rankdir?r.width+=r.labeloffset:r.height+=r.labeloffset)}}(e)})),t(" removeSelfEdges",(function(){!function(e){for(var t of e.edges())if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}}(e)})),t(" acyclic",(function(){Qe.run(e)})),t(" nestingGraph.run",(function(){dt.run(e)})),t(" rank",(function(){qe(O(e))})),t(" injectEdgeLabelProxies",(function(){!function(e){for(var t of e.edges()){var n=e.edge(t);if(n.width&&n.height){var r=e.node(t.v),i=e.node(t.w);I(e,"edge-proxy",{rank:(i.rank-r.rank)/2+r.rank,e:t},"_ep")}}}(e)})),t(" removeEmptyRanks",(function(){R(e)})),t(" nestingGraph.cleanup",(function(){dt.cleanup(e)})),t(" normalizeRanks",(function(){A(e)})),t(" assignRankMinMax",(function(){!function(e){var t=0;for(var n of e.nodes()){var r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}e.graph().maxRank=t}(e)})),t(" removeEdgeLabelProxies",(function(){!function(e){for(var t of e.nodes()){var n=e.node(t);ut(n)&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))}}(e)})),t(" normalize.run",(function(){at.run(e)})),t(" parentDummyChains",(function(){ct(e)})),t(" addBorderSegments",(function(){Ze(e)})),t(" order",(function(){K(e)})),t(" insertSelfEdges",(function(){!function(e){var t,n=P(e);for(var r of n)for(var i=0,o=0;o<r.length;o++){var a=r[o],s=e.node(a);for(var c of(s.order=o+i,null!==(t=s.selfEdges)&&void 0!==t?t:[]))I(e,"selfedge",{width:c.label.width,height:c.label.height,rank:s.rank,order:o+ ++i,e:c.e,label:c.label},"_se");delete s.selfEdges}}(e)})),t(" adjustCoordinateSystem",(function(){et.adjust(e)})),t(" position",(function(){pe(e)})),t(" positionSelfEdges",(function(){!function(e){for(var t of e.nodes()){var n=e.node(t);if(ft(n)){var r=e.node(n.e.v),i=r.x+r.width/2,o=r.y,a=n.x-i,s=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:i+2*a/3,y:o-s},{x:i+5*a/6,y:o-s},{x:i+a,y:o},{x:i+5*a/6,y:o+s},{x:i+2*a/3,y:o+s}],n.label.x=n.x,n.label.y=n.y}}}(e)})),t(" removeBorderNodes",(function(){!function(e){for(var t of e.nodes())if(e.children(t).length){var n=e.node(t),r=e.node(n.borderTop),i=e.node(n.borderBottom),o=e.node(c(n.borderLeft)),a=e.node(c(n.borderRight));n.width=Math.abs(a.x-o.x),n.height=Math.abs(i.y-r.y),n.x=o.x+n.width/2,n.y=r.y+n.height/2}for(var t of e.nodes())"border"===e.node(t).dummy&&e.removeNode(t)}(e)})),t(" normalize.undo",(function(){at.undo(e)})),t(" fixupEdgeLabelCoords",(function(){!function(e){for(var t of e.edges()){var n=e.edge(t);if(s(n,"x"))switch("l"!==n.labelpos&&"r"!==n.labelpos||(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset}}}(e)})),t(" undoCoordinateSystem",(function(){et.undo(e)})),t(" translateGraph",(function(){!function(e){var t,n,r,i=Number.POSITIVE_INFINITY,o=0,a=Number.POSITIVE_INFINITY,c=0,l=e.graph(),d=null!==(t=l.marginx)&&void 0!==t?t:0,h=null!==(n=l.marginy)&&void 0!==n?n:0;function u(e){var t=e.x,n=e.y,r=e.width,s=e.height;i=Math.min(i,t-r/2),o=Math.max(o,t+r/2),a=Math.min(a,n-s/2),c=Math.max(c,n+s/2)}for(var f of e.nodes())u(e.node(f));for(var g of e.edges())s(v=e.edge(g),"x")&&u(v);for(var f of(i-=d,a-=h,e.nodes())){var p=e.node(f);p.x-=i,p.y-=a}for(var g of e.edges()){var v=e.edge(g);for(var m of null!==(r=v.points)&&void 0!==r?r:[])m.x-=i,m.y-=a;v.hasOwnProperty("x")&&(v.x-=i),v.hasOwnProperty("y")&&(v.y-=a)}l.width=o-i+d,l.height=c-a+h}(e)})),t(" assignNodeIntersects",(function(){!function(e){for(var t of e.edges()){var n,r,i=e.edge(t),o=e.node(t.v),a=e.node(t.w);i.points?(n=i.points[0],r=i.points[i.points.length-1]):(i.points=[],n=a,r=o),i.points.unshift(j(o,n)),i.points.push(j(a,r))}}(e)})),t(" reversePoints",(function(){!function(e){for(var t of e.edges()){var n=e.edge(t);n.reversed&&n.points.reverse()}}(e)})),t(" acyclic.undo",(function(){Qe.undo(e)}))}(t,n)})),n(" updateInputGraph",(function(){!function(e,t){for(var n of e.nodes()){var r=e.node(n),i=t.node(n);r&&(r.x=i.x,r.y=i.y,t.children(n).length&&(r.width=i.width,r.height=i.height))}for(var o of e.edges()){var a=e.edge(o),c=t.edge(o);a.points=c.points,s(c,"x")&&(a.x=c.x,a.y=c.y)}e.graph().width=t.graph().width,e.graph().height=t.graph().height}(e,t)}))}))},e.nestingGraph=dt,e.normalize=at,e.order=ee,e.parentDummyChains=ct,e.position=ve,e.rank=He,e.util=V,e.version="0.1.3",Object.defineProperty(e,"__esModule",{value:!0})}(t)}(0,j.exports)),j.exports}var A,R=v(Object.freeze({__proto__:null,default:{}}));var D=(A||(A=1,function(e,t){!function(e,t){function n([e,t],n){const r=[];for(let i=0;i<n;i++)r.push(e+(t-e)*i/(n-1));return r}function r(e,t){let n=0;for(let r=0,i=e.length;r<i;r++)n+=t(e[r]);return n}function i(e){return e[e.length-1]}function o(e,t){const n={};for(let r=0;r<e.length;r++)n[e[r][t]]=e[r];return n}var a=Object.freeze({__proto__:null,indexBy:o,last:i,range:n,sum:r});function s(e,t,n={}){return{title:{bold:t.bold||!1,underline:t.underline||!1,italic:t.italic||!1,center:t.center||!1},body:{bold:n.bold||!1,underline:n.underline||!1,italic:n.italic||!1,center:n.center||!1},dashed:e.dashed||!1,fill:e.fill||void 0,stroke:e.stroke||void 0,visual:e.visual||"class",direction:e.direction||void 0}}const c={abstract:s({visual:"class"},{center:!0,italic:!0}),actor:s({visual:"actor"},{center:!0},{center:!0}),choice:s({visual:"rhomb"},{center:!0},{center:!0}),class:s({visual:"class"},{center:!0,bold:!0}),database:s({visual:"database"},{center:!0,bold:!0},{center:!0}),end:s({visual:"end"},{}),frame:s({visual:"frame"},{}),hidden:s({visual:"hidden"},{}),input:s({visual:"input"},{center:!0}),instance:s({visual:"class"},{center:!0,underline:!0}),label:s({visual:"none"},{center:!0}),lollipop:s({visual:"lollipop"},{center:!0}),note:s({visual:"note"},{}),pipe:s({visual:"pipe"},{center:!0,bold:!0}),package:s({visual:"package"},{}),receiver:s({visual:"receiver"},{}),reference:s({visual:"class",dashed:!0},{center:!0}),sender:s({visual:"sender"},{}),socket:s({visual:"socket"},{}),start:s({visual:"start"},{}),state:s({visual:"roundrect"},{center:!0}),sync:s({visual:"sync"},{center:!0}),table:s({visual:"table"},{center:!0,bold:!0}),transceiver:s({visual:"transceiver"},{}),usecase:s({visual:"ellipse"},{center:!0},{center:!0})};function l(e,t,n){t.width=Math.max(...t.parts.map((e=>e.width??0))),t.height=r(t.parts,(e=>e.height??0??0)),t.dividers=[];let o=0;for(const e of t.parts)e.