@progress/kendo-ui
Version:
This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.
3 lines • 205 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("kendo.drawing.cmn.chunk.js"),require("kendo.common.cmn.chunk.js")):"function"==typeof define&&define.amd?define(["exports","kendo.drawing.cmn.chunk.min","kendo.common.cmn.chunk.min"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).kendo=t.kendo||{},t.kendo._globals=t.kendo._globals||{},t.kendo._globals.DiagramCommonCmnChunk={}),t.kendo._globals.DrawingCmnChunk,t.kendo._globals.CommonCmnChunk)}(this,(function(t,e,i){const s="width",n="height",o="x",r="y",h="transparent",a="start",l="end",c={none:"none",arrowStart:"ArrowStart",filledCircle:"FilledCircle",arrowEnd:"ArrowEnd"},d=Math.PI/180,u=1e-6,p="change",g={arrow:"default",grip:"pointer",cross:"pointer",add:"pointer",move:"move",select:"pointer",south:"s-resize",east:"e-resize",west:"w-resize",north:"n-resize",rowresize:"row-resize",colresize:"col-resize"},f=10,m="Auto",_="Top",y="Right",w="Left",v="Bottom",x="dragStart",b="drag",C="dragEnd",S="itemRotate",M="itemBoundsChange",k="mouseEnter",T="mouseLeave",E="zoomStart",L="zoomEnd",P="pan",I="rotated",z="source",D="target",N={"-1":z,1:D},O="Connection Editing",B="cascading",R=9007199254740992,A="select",V="none",H=Number.MAX_VALUE,F=-Number.MAX_VALUE,U="transformed",W=t=>Math.abs(t)<u,q=t=>void 0!==t,K=q,Y=t=>"function"==typeof t,j=t=>null==t,G=t=>t===Object(t),X=(t,e)=>Object.hasOwnProperty.call(t,e),J=t=>"[object String]"===Object.prototype.toString.call(t),Z=t=>!isNaN(parseFloat(t))&&isFinite(t),$=t=>{if(null===t)return!0;if(Array.isArray(t)||J(t))return 0===t.length;for(const e in t)if(X(t,e))return!1;return!0},Q=(t,e)=>{if(G(e))for(const i in e)i&&(t[i]=e[i])},tt=(t,e)=>{const i=[];for(let s=0;s<t;++s)i[s]=e;return i},et=(t,e)=>{const i=Math.floor(Math.random()*e)+t;return parseInt(i.toString(),10)},it=(t,e)=>{if(e(t),t.childNodes)for(let i=0;i<t.childNodes.length;i++){const s=t.childNodes[i];it(s,e)}},st=(t,e)=>{if(t===e)return 0;const i=e.x-t.x,s=t.y-e.y,n=Math.atan(i/s);return s>=0?i<0?n+2*Math.PI:n:n+Math.PI},nt=t=>t?t<0?-1:1:0,ot=(t,e)=>180*st(t,e)/Math.PI,rt=(t,e,i)=>{for(let s=0;s<t.length;s++)e.call(i,t[s],s,t)},ht=(t,e)=>{for(let i=0;i<t.length;++i)if(e(t[i]))return t[i];return null},at=(t,e)=>{let i=t.indexOf(e);for(;-1!==i;)t.splice(i,1),i=t.indexOf(e);return t},lt=(t,e)=>(t||[]).includes(e),ct=(t,e)=>t.indexOf(e),dt=(t,e)=>e.indexOf(t),ut=(t,e)=>t.filter(e),pt=(t,e,i,s)=>{let n=void 0!==i;for(let o=0;o<t.length;o++){const r=t[o];n?i=e.call(s,i,r,o,t):(i=r,n=!0)}if(!n)throw new Error("Reduce of empty array with no initial value");return i},gt=(t,e,i)=>t.find(e.bind(i))||void 0,ft=(t,e,i)=>0===t.length?null:j(e)?t[0]:gt(t,e,i),mt=(t,e,i)=>(t.splice(i,0,e),t),_t=(t,e,i)=>{let s,n=!0;for(let o=0;o<t.length&&(s=t[o],n=n&&e.call(i,s,o,t),n);o++);return n},yt=t=>{t.splice(0,t.length)},wt=(t,e,i)=>{if(j(t))throw new Error("First array is not specified.");if(j(e))throw new Error("Second array is not specified.");if(t.length!==e.length)throw new Error("The two arrays should have equal length");const s=[];for(let i=0;i<t.length;i++)s.push({x:t[i],y:e[i]});j(i)?s.sort(((t,e)=>t.x-e.x)):s.sort(((t,e)=>i(t.x,e.x))),yt(t),yt(e);for(let i=0;i<s.length;i++)t.push(s[i].x),e.push(s[i].y)},vt=(t,e)=>{t.push(...e)},xt=()=>{},bt="string",Ct="function",St=function(){this._defaultPrevented=!0},Mt=function(){return!0===this._defaultPrevented};class kt{constructor(){this.options={},this.events=[],this._events={}}destroy(){this.unbind()}bind(t,e,i){if(!e&&G(t)&&!Array.isArray(t)){for(const e in t)t[e]&&this.bind(e,t[e]);return this}const s=typeof t===bt?[t]:t,n=typeof e===Ct;let o,r;for(let t=0,h=s.length;t<h;t++){const h=s[t];r=n?e:e[h],r&&(i&&(o=r,r=(...t)=>{this.unbind(h,r),o.apply(this,t)},r.original=o),this._events[h]=this._events[h]||[],this._events[h].push(r))}return this}one(t,e){return this.bind(t,e,!0)}first(t,e){const i=typeof t===bt?[String(t)]:Array.from(t),s=typeof e===Ct;let n;for(let t=0,o=i.length;t<o;t++){const o=i[t];n=s?e:e[o],n&&(this._events[o]=this._events[o]||[],this._events[o].unshift(n))}return this}trigger(t,e){let i=this._events[t];if(i){const t=e||{};t.sender=this,t._defaultPrevented=!1,t.preventDefault=St,t.isDefaultPrevented=Mt,i=i.slice();for(let e=0,s=i.length;e<s;e++)i[e].call(this,t);return!0===t._defaultPrevented}return!1}unbind(t,e){const i=this._events[t];if(void 0===t)this._events={};else if(i)if(e)for(let t=i.length-1;t>=0;t--)i[t]!==e&&i[t].original!==e||i.splice(t,1);else this._events[t]=[];return this}_setEvents(t){const e=(this.events||[]).length;for(let i=0;i<e;i++){const e=this.events[i];this.options[e]&&t[e]&&(this.unbind(e,this.options[e]),this._events&&this._events[e]&&delete this._events[e])}this.bind(this.events,t)}}var Tt=Object.freeze({__proto__:null,DFT:it,Observable:kt,addRange:vt,all:_t,bisort:wt,clear:yt,contains:lt,defined:K,deserializePoints:t=>{const e=t.split(";"),i=[];if(e.length%2!=0)throw new Error("Not an array of points.");for(let t=0;t<e.length;t+=2)i.push({x:parseInt(e[t],10),y:parseInt(e[t+1],10)});return i},find:gt,findAngle:ot,findRadian:st,first:ft,fold:pt,forEach:rt,getAny:ht,getMatrixAngle:t=>null===t||0===t.d?0:180*Math.atan2(t.b,t.d)/Math.PI,getMatrixScaling:t=>[Math.sqrt(t.a*t.a+t.c*t.c),Math.sqrt(t.b*t.b+t.d*t.d)],grep:ut,has:X,inArray:dt,indexOf:ct,initArray:tt,insert:mt,isBoolean:t=>"[object Boolean]"===Object.prototype.toString.call(t),isDefined:q,isEmpty:$,isFunction:Y,isNearZero:W,isNumber:Z,isObject:G,isString:J,isType:(t,e)=>Object.prototype.toString.call(t)==="[object "+e+"]",isUndefined:j,noop:xt,randomInteger:et,remove:at,serializePoints:t=>{const e=[];for(let i=0;i<t.length;i++){const s=t[i];e.push(s.x+";"+s.y)}return e.join(";")},sign:nt,simpleExtend:Q});const Et={easeInOut:t=>-Math.cos(t*Math.PI)/2+.5};class Lt{constructor(){this.adapters=[],this.target=0,this.tick=0,this.interval=20,this.duration=800,this.lastTime=null,this.handlers=[],this.timerDelegate=()=>{},this.intervalId=null,this.caller=null,this.timerDelegate=()=>{this.onTimerEvent()}}addAdapter(t){this.adapters.push(t)}onComplete(t){this.handlers.push(t)}removeHandler(t){this.handlers=this.handlers.filter((e=>e!==t))}trigger(){this.handlers&&rt(this.handlers,(t=>t.call(null!==this.caller?this.caller:this)))}onStep(){}seekTo(t){this.seekFromTo(this.tick,t)}seekFromTo(t,e){this.target=Math.max(0,Math.min(1,e)),this.tick=Math.max(0,Math.min(1,t)),this.lastTime=(new Date).getTime(),this.intervalId||(this.intervalId=window.setInterval(this.timerDelegate,this.interval))}stop(){this.intervalId&&(window.clearInterval(this.intervalId),this.intervalId=null,this.trigger())}play(t){0!==this.adapters.length&&(null!==t&&(this.caller=t),this.initState(),this.seekFromTo(0,1))}reverse(){this.seekFromTo(1,0)}initState(){if(0!==this.adapters.length)for(let t=0;t<this.adapters.length;t++)this.adapters[t].initState()}propagate(){const t=Et.easeInOut(this.tick);for(let e=0;e<this.adapters.length;e++)this.adapters[e].update(t)}onTimerEvent(){const t=(new Date).getTime(),e=t-this.lastTime;this.lastTime=t;const i=e/this.duration*(this.tick<this.target?1:-1);Math.abs(i)>=Math.abs(this.tick-this.target)?this.tick=this.target:this.tick+=i;try{this.propagate()}finally{this.onStep.call(this),this.target===this.tick&&this.stop()}}}function Pt(t){j(t)&&(t=10);let e="";const i="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";for(let s=t;s>0;--s)e+=i.charAt(Math.round(61*Math.random()));return e}class It{constructor(){this._buckets={},this.length=0}add(t,e){const i=this._createGetBucket(t);return q(e)&&(i.value=e),i}get(t){return this._bucketExists(t)?this._createGetBucket(t):null}set(t,e){this.add(t,e)}containsKey(t){return this._bucketExists(t)}remove(t){if(this._bucketExists(t)){const e=this._hash(t);return delete this._buckets[e],this.length--,t}}forEach(t){const e=this._hashes();for(let i=0,s=e.length;i<s;i++){const s=e[i],n=this._buckets[s];j(n)||t(n)}}clone(){const t=new It,e=this._hashes();for(let i=0,s=e.length;i<s;i++){const s=e[i],n=this._buckets[s];j(n)||t.add(n.key,n.value)}return t}_hashes(){const t=[];for(const e in this._buckets)Object.prototype.hasOwnProperty.call(this._buckets,e)&&t.push(e);return t}_bucketExists(t){const e=this._hash(t);return q(this._buckets[e])}_createGetBucket(t){const e=this._hash(t);let i=this._buckets[e];return j(i)&&(i={key:t},this._buckets[e]=i,this.length++),i}_hash(t){if(Z(t))return t;if(J(t))return this._hashString(t);if(G(t))return this._objectHashId(t);throw console.log(t),new Error("Unsupported key type.")}_hashString(t){let e=0;if(0===t.length)return e;for(let i=0;i<t.length;i++){e=32*e-e+t.charCodeAt(i)}return e}_objectHashId(t){let e=t._hashId;return j(e)&&(e=Pt(),t._hashId=e),e}}class zt extends kt{constructor(t){if(super(),this._hashTable=new It,this.length=0,q(t))if(Array.isArray(t))for(let e=0;e<t.length;e++)this.add(t[e]);else t.forEach((function(t,e){this.add(t,e)}),this)}add(t,e){let i=this._hashTable.get(t);i||(i=this._hashTable.add(t),this.length++,this.trigger("changed")),i.value=e}set(t,e){this.add(t,e)}get(t){const e=this._hashTable.get(t);if(e)return e.value;throw new Error("Cannot find key "+t)}containsKey(t){return this._hashTable.containsKey(t)}remove(t){if(this.containsKey(t))return this.trigger("changed"),this.length--,this._hashTable.remove(t)}forEach(t,e){this._hashTable.forEach((function(i){t.call(e,i.key,i.value)}))}forEachValue(t,e){this._hashTable.forEach((function(i){t.call(e,i.value)}))}forEachKey(t,e){this._hashTable.forEach((function(i){t.call(e,i.key)}))}keys(){const t=[];return this.forEachKey((function(e){t.push(e)})),t}}const Dt={_distanceToLineSquared:function(t,e,i){function s(t,e){return(t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y)}if(e===i)return s(t,e);const n=i.x-e.x,o=i.y-e.y;let r=(t.x-e.x)*n+(t.y-e.y)*o;return r<0?s(e,t):(r=(i.x-t.x)*n+(i.y-t.y)*o,r<0?s(i,t):(r=(i.x-t.x)*o-(i.y-t.y)*n,r*r/(n*n+o*o)))},distanceToLine:function(t,e,i){return Math.sqrt(this._distanceToLineSquared(t,e,i))},distanceToPolyline:function(t,e){let i=Number.MAX_VALUE;if(j(e)||0===e.length)return Number.MAX_VALUE;for(let s=0;s<e.length-1;s++){const n=e[s],o=e[s+1],r=this._distanceToLineSquared(t,n,o);r<i&&(i=r)}return Math.sqrt(i)}};class Nt{constructor(t,e){this.r=t,this.angle=e}}class Ot extends e.P{constructor(t,e){super(t,e)}clone(){return new Ot(this.x,this.y)}plus(t){return new Ot(this.x+t.x,this.y+t.y)}minus(t){return new Ot(this.x-t.x,this.y-t.y)}offset(t){return new Ot(this.x-t,this.y-t)}times(t){return new Ot(this.x*t,this.y*t)}normalize(){return 0===this.length()?new Ot:this.times(1/this.length())}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}toString(){return"("+this.x+","+this.y+")"}lengthSquared(){return this.x*this.x+this.y*this.y}middleOf(t,e){return new Ot(e.x-t.x,e.y-t.y).times(.5).plus(t)}toPolar(t){let e=1;t&&(e=180/Math.PI);const i=Math.atan2(Math.abs(this.y),Math.abs(this.x)),s=Math.PI/2,n=this.length();if(0===this.x){if(0===this.y)return new Nt(0,0);if(this.y>0)return new Nt(n,e*s);if(this.y<0)return new Nt(n,3*e*s)}else if(this.x>0){if(0===this.y)return new Nt(n,0);if(this.y>0)return new Nt(n,e*i);if(this.y<0)return new Nt(n,e*(4*s-i))}else{if(0===this.y)return new Nt(n,2*s);if(this.y>0)return new Nt(n,e*(2*s-i));if(this.y<0)return new Nt(n,e*(2*s+i))}}isOnLine(t,e){if(t.x>e.x){const i=e;e=t,t=i}const i=new Bt(t.x,t.y).inflate(3,3),s=new Bt(e.x,e.y).inflate(3,3);let n,o;return!!i.union(s).contains(this)&&(t.x===e.x||t.y===e.y||(t.y<e.y?(n=i.x+(s.x-i.x)*(this.y-(i.y+i.height))/(s.y+s.height-(i.y+i.height)),o=i.x+i.width+(s.x+s.width-(i.x+i.width))*(this.y-i.y)/(s.y-i.y)):(n=i.x+(s.x-i.x)*(this.y-i.y)/(s.y-i.y),o=i.x+i.width+(s.x+s.width-(i.x+i.width))*(this.y-(i.y+i.height))/(s.y+s.height-(i.y+i.height))),this.x>n&&this.x<o))}parse(t){const e=t.slice(1,t.length-1).split(","),i=parseInt(e[0],10),s=parseInt(e[1],10);if(!isNaN(i)&&!isNaN(s))return new Ot(i,s)}}class Bt{constructor(t,e,i,s){this.x=t||0,this.y=e||0,this.width=i||0,this.height=s||0}contains(t){return t.x>=this.x&&t.x<=this.x+this.width&&t.y>=this.y&&t.y<=this.y+this.height}inflate(t,e){return void 0===e&&(e=t),this.x-=t,this.y-=e,this.width+=2*t+1,this.height+=2*e+1,this}offset(t,e){let i=t,s=e;return t instanceof Ot&&(i=t.x,s=t.y),this.x+=i,this.y+=s,this}union(t){const e=Math.min(this.x,t.x),i=Math.min(this.y,t.y),s=Math.max(this.x+this.width,t.x+t.width),n=Math.max(this.y+this.height,t.y+t.height);return new Bt(e,i,s-e,n-i)}center(){return new Ot(this.x+this.width/2,this.y+this.height/2)}top(){return new Ot(this.x+this.width/2,this.y)}right(){return new Ot(this.x+this.width,this.y+this.height/2)}bottom(){return new Ot(this.x+this.width/2,this.y+this.height)}left(){return new Ot(this.x,this.y+this.height/2)}topLeft(){return new Ot(this.x,this.y)}topRight(){return new Ot(this.x+this.width,this.y)}bottomLeft(){return new Ot(this.x,this.y+this.height)}bottomRight(){return new Ot(this.x+this.width,this.y+this.height)}clone(){return new Bt(this.x,this.y,this.width,this.height)}isEmpty(){return!this.width&&!this.height}equals(t){return this.x===t.x&&this.y===t.y&&this.width===t.width&&this.height===t.height}rotatedBounds(t){const e=this.clone(),i=this.rotatedPoints(t),s=i[0],n=i[1],o=i[2],r=i[3];return e.x=Math.min(o.x,s.x,n.x,r.x),e.y=Math.min(o.y,s.y,n.y,r.y),e.width=Math.max(o.x,s.x,n.x,r.x)-e.x,e.height=Math.max(o.y,s.y,n.y,r.y)-e.y,e}rotatedPoints(t){const e=this.center(),i=this.bottomRight().rotate(t,e);return[this.topLeft().rotate(t,e),this.topRight().rotate(t,e),i,this.bottomLeft().rotate(t,e)]}toString(t){return t=t||" ",this.x+t+this.y+t+this.width+t+this.height}scale(t,e,i,s,n){let o=this.topLeft();const r=this.center();o.rotate(n,r).rotate(n,s);const h=i.minus(o),a=new Ot(h.x*t,h.y*e),l=h.minus(a);o=o.plus(l),o.rotate(n,s).rotate(n,r),this.x=o.x,this.y=o.y,this.width*=t,this.height*=e}zoom(t){return this.x*=t,this.y*=t,this.width*=t,this.height*=t,this}overlaps(t){const e=this.bottomRight(),i=t.bottomRight();return!(e.x<t.x||e.y<t.y||i.x<this.x||i.y<this.y)}static toRect(t){return t instanceof Bt||(t=new Bt(t.x,t.y,t.width,t.height)),t}static empty(){return new Bt(0,0,0,0)}static fromPoints(t,e){if(isNaN(t.x)||isNaN(t.y)||isNaN(e.x)||isNaN(e.y))throw new Error("Some values are NaN.");return new Bt(Math.min(t.x,e.x),Math.min(t.y,e.y),Math.abs(t.x-e.x),Math.abs(t.y-e.y))}}class Rt{constructor(t){this.container=Bt.toRect(t)}align(t,e){const i=e.toLowerCase().split(" ");for(let e=0;e<i.length;e++)t=this._singleAlign(t,i[e]);return t}_singleAlign(t,e){return Y(this[e])?this[e](t):t}left(t){return this._align(t,this._left)}center(t){return this._align(t,this._center)}right(t){return this._align(t,this._right)}stretch(t){return this._align(t,this._stretch)}top(t){return this._align(t,this._top)}middle(t){return this._align(t,this._middle)}bottom(t){return this._align(t,this._bottom)}_left(t,e){e.x=t.x}_center(t,e){e.x=(t.width-e.width)/2||0}_right(t,e){e.x=t.width-e.width}_top(t,e){e.y=t.y}_middle(t,e){e.y=(t.height-e.height)/2||0}_bottom(t,e){e.y=t.height-e.height}_stretch(t,e){e.x=0,e.y=0,e.height=t.height,e.width=t.width}_align(t,e){return t=Bt.toRect(t),e(this.container,t),t}}class At{constructor(){this._tail=null,this._head=null,this.length=0}enqueue(t){const e={value:t,next:null};this._head?(this._tail.next=e,this._tail=this._tail.next):(this._head=e,this._tail=this._head),this.length++}dequeue(){if(this.length<1)throw new Error("The queue is empty.");const t=this._head.value;return this._head=this._head.next,this.length--,t}contains(t){let e=this._head;for(;e;){if(e.value===t)return!0;e=e.next}return!1}}const Vt="object";function Ht(t,e){for(const i in e){if("__proto__"===i||"constructor"===i)continue;const s=e[i],n=typeof s;let o;if(o=n===Vt&&null!==s?s.constructor:null,o&&o!==Array)if(s instanceof Date)t[i]=new Date(s.getTime());else if("function"==typeof s.clone)t[i]=s.clone();else{const e=t[i];t[i]=typeof e===Vt&&e||{},Ht(t[i],s)}else"undefined"!==n&&(t[i]=s)}return t}function Ft(t,...e){const i=e.length;for(let s=0;s<i;s++)Ht(t,e[s]);return t}const Ut={type:"Tree",subtype:"Down",roots:null,animate:!1,limitToView:!1,friction:.9,nodeDistance:50,iterations:300,horizontalSeparation:90,verticalSeparation:50,underneathVerticalTopOffset:15,underneathHorizontalOffset:15,underneathVerticalSeparation:15,grid:{width:1500,offsetX:50,offsetY:50,componentSpacingX:20,componentSpacingY:20},layerSeparation:50,layeredIterations:2,startRadialAngle:0,endRadialAngle:360,radialSeparation:150,radialFirstLevelSeparation:200,keepComponentsInOneRadialLayout:!1,ignoreContainers:!0,layoutContainerChildren:!1,ignoreInvisible:!0,animateTransitions:!1};class Wt{constructor(){this.defaultOptions={...Ut,grid:{...Ut.grid}}}gridLayoutComponents(t){if(!t)throw new Error("No components supplied.");rt(t,(function(t){t.calcBounds()})),t.sort((function(t,e){return e.bounds.width-t.bounds.width}));const e=this.options.grid.width,i=this.options.grid.componentSpacingX,s=this.options.grid.componentSpacingY,n=this.options.grid.offsetX,o=[],r=[];let h=0,a=n,l=this.options.grid.offsetY;for(;t.length>0;){a>=e&&(a=n,l+=h+s,h=0);const c=t.pop();this.moveToOffset(c,new Ot(a,l));for(let t=0;t<c.nodes.length;t++)r.push(c.nodes[t]);for(let t=0;t<c.links.length;t++)o.push(c.links[t]);const d=c.bounds;let u=d.height;(u<=0||isNaN(u))&&(u=0);let p=d.width;(p<=0||isNaN(p))&&(p=0),u>=h&&(h=u),a+=p+i}return{nodes:r,links:o}}moveToOffset(t,e){let i,s;const n=t.bounds,o=e.x-n.x,r=e.y-n.y;for(i=0;i<t.nodes.length;i++){const e=t.nodes[i];let s=e.bounds();0===s.width&&0===s.height&&0===s.x&&0===s.y&&(s=new Bt(0,0,0,0)),s.x+=o,s.y+=r,e.bounds(s)}for(i=0;i<t.links.length;i++){const e=t.links[i];if(e.points){const t=[],i=e.points;for(s=0;s<i.length;s++){const e=i[s];e.x+=o,e.y+=r,t.push(e)}e.points=t}}return this.currentHorizontalOffset+=n.width+this.options.grid.offsetX,new Ot(o,r)}transferOptions(t){this.options=Ft({},this.defaultOptions),j(t)||(this.options=Ft(this.options,t||{}))}}class qt{constructor(t,e){if(j(t))throw new Error("No diagram given");this.diagram=t,this.nodeMap=new zt,this.linkMap=new zt,this.capture(e||t)}capture(t){let e,i,s,n,o,r,h;if(t&&"Graph"===t.type){for(n=0;n<t.nodes.length;n++)e=t.nodes[n],s=e.associatedShape,this.nodeMap.set(s.visual.id,new Bt(e.x,e.y,e.width,e.height));for(n=0;n<t.links.length;n++)r=t.links[n],o=r.associatedConnection,this.linkMap.set(o.visual.id,r.points())}else if(t instanceof Array)for(i=t,n=0;n<i.length;n++)e=i[n],s=e.associatedShape,s&&this.nodeMap.set(s.visual.id,new Bt(e.x,e.y,e.width,e.height));else if(Object.prototype.hasOwnProperty.call(t,"links")&&Object.prototype.hasOwnProperty.call(t,"nodes")){for(i=t.nodes,h=t.links,n=0;n<i.length;n++)e=i[n],s=e.associatedShape,s&&this.nodeMap.set(s.visual.id,new Bt(e.x,e.y,e.width,e.height));for(n=0;n<h.length;n++)r=h[n],o=r.associatedConnection,o&&this.linkMap.set(o.visual.id,r.points)}else{const t=this.diagram.shapes,e=this.diagram.connections;for(n=0;n<t.length;n++)s=t[n],this.nodeMap.set(s.visual.id,s.bounds());for(n=0;n<e.length;n++)o=e[n],this.linkMap.set(o.visual.id,o.points())}}}let Kt=class t{constructor(t,e){if(this.links=[],this.outgoing=[],this.incoming=[],this.weight=1,this.data=null,this.type="Node",this.isVirtual=!1,q(t)?this.id=t:this.id=Pt(),q(e)){this.associatedShape=e;const t=e.bounds();this.width=t.width,this.height=t.height,this.x=t.x,this.y=t.y}else this.associatedShape=null;this.shortForm="Node '"+this.id+"'"}isIsolated(){return $(this.links)}bounds(t){if(!q(t))return new Bt(this.x,this.y,this.width,this.height);this.x=t.x,this.y=t.y,this.width=t.width,this.height=t.height}isLinkedTo(t){return ht(this.links,(e=>e.getComplement(this)===t))}getChildren(){if(0===this.outgoing.length)return[];const t=[];for(let e=0,i=this.outgoing.length;e<i;e++){const i=this.outgoing[e];t.push(i.getComplement(this))}return t}getParents(){if(0===this.incoming.length)return[];const t=[];for(let e=0,i=this.incoming.length;e<i;e++){const i=this.incoming[e];t.push(i.getComplement(this))}return t}clone(){const e=new t;return q(this.weight)&&(e.weight=this.weight),q(this.balance)&&(e.balance=this.balance),q(this.owner)&&(e.owner=this.owner),e.associatedShape=this.associatedShape,e.x=this.x,e.y=this.y,e.width=this.width,e.height=this.height,e}adjacentTo(t){return null!==this.isLinkedTo(t)}removeLink(t){t.source===this&&(at(this.links,t),at(this.outgoing,t),t.source=null),t.target===this&&(at(this.links,t),at(this.incoming,t),t.target=null)}hasLinkTo(t){return ht(this.outgoing,(function(e){return e.target===t}))}degree(){return this.links.length}incidentWith(t){return lt(this.links,t)}getLinksWith(t){return _t(this.links,(function(e){return e.getComplement(this)===t}),this)}getNeighbors(){const t=[];return rt(this.incoming,(function(e){t.push(e.getComplement(this))}),this),rt(this.outgoing,(function(e){t.push(e.getComplement(this))}),this),t}};class Yt{constructor(t,e,i,s){if(j(t))throw new Error("The source of the new link is not set.");if(j(e))throw new Error("The target of the new link is not set.");let n,o;n=J(t)?new Kt(t):t,o=J(e)?new Kt(e):e,this.source=n,this.target=o,this.source.links.push(this),this.target.links.push(this),this.source.outgoing.push(this),this.target.incoming.push(this),q(i)?this.id=i:this.id=Pt(),q(s)?this.associatedConnection=s:this.associatedConnection=null,this.type="Link",this.shortForm="Link '"+this.source.id+"->"+this.target.id+"'"}getComplement(t){if(this.source!==t&&this.target!==t)throw new Error("The given node is not incident with this link.");return this.source===t?this.target:this.source}getCommonNode(t){return this.source===t.source||this.source===t.target?this.source:this.target===t.source||this.target===t.target?this.target:null}isBridging(t,e){return this.source===t&&this.target===e||this.source===e&&this.target===t}getNodes(){return[this.source,this.target]}incidentWith(t){return this.source===t||this.target===t}adjacentTo(t){return lt(this.source.links,t)||lt(this.target.links,t)}changeSource(t){at(this.source.links,this),at(this.source.outgoing,this),t.links.push(this),t.outgoing.push(this),this.source=t}changeTarget(t){at(this.target.links,this),at(this.target.incoming,this),t.links.push(this),t.incoming.push(this),this.target=t}changesNodes(t,e){this.source===t?this.changeSource(e):this.target===t&&this.changeTarget(e)}reverse(){const t=this.source,e=this.target;return this.source=e,at(t.outgoing,this),this.source.outgoing.push(this),this.target=t,at(e.incoming,this),this.target.incoming.push(this),this}directTo(t){if(this.source!==t&&this.target!==t)throw new Error("The given node is not incident with this link.");this.target!==t&&this.reverse()}createReverseEdge(){const t=this.clone();return t.reverse(),t.reversed=!0,t}clone(){return new Yt(this.source,this.target)}}class jt{constructor(t){this.links=[],this.nodes=[],this._nodeMap=new zt,this.diagram=null,this._root=null,this.bounds=new Bt,this._hasCachedRelationships=!1,this.type="Graph",this.componentIndex=0,q(t)?J(t)?this.id=t:(this.diagram=t,this.id=t.id):this.id=Pt()}cacheRelationships(t){if(j(t)&&(t=!1),!this._hasCachedRelationships||t){for(let t=0,e=this.nodes.length;t<e;t++){const e=this.nodes[t];e.children=this.getChildren(e),e.parents=this.getParents(e)}this._hasCachedRelationships=!0}}assignLevels(t,e,i){if(!t)throw new Error("Start node not specified.");j(e)&&(e=0),this.cacheRelationships(),j(i)&&(i=new zt,rt(this.nodes,(function(t){i.add(t,!1)}))),i.set(t,!0),t.level=e;const s=t.children;for(let t=0,n=s.length;t<n;t++){const n=s[t];n&&!i.get(n)&&this.assignLevels(n,e+1,i)}}root(t){if(j(t)){if(this._root)return this._root;{const t=ft(this.nodes,(function(t){return 0===t.incoming.length}));return t||ft(this.nodes)}}this._root=t}getConnectedComponents(){this.componentIndex=0,this.setItemIndices();const t=tt(this.nodes.length,-1);for(let e=0;e<this.nodes.length;e++)-1===t[e]&&(this._collectConnectedNodes(t,e),this.componentIndex++);const e=[];let i;for(i=0;i<this.componentIndex;++i)e[i]=new jt;for(i=0;i<t.length;++i){e[t[i]].addNodeAndOutgoings(this.nodes[i])}return e.sort((function(t,e){return e.nodes.length-t.nodes.length})),e}_collectConnectedNodes(t,e){t[e]=this.componentIndex;const i=this.nodes[e];rt(i.links,(function(e){const s=e.getComplement(i).index;-1===t[s]&&this._collectConnectedNodes(t,s)}),this)}calcBounds(){if(this.isEmpty())return this.bounds=new Bt,this.bounds;let t=null;for(let e=0,i=this.nodes.length;e<i;e++){const i=this.nodes[e];t=t?t.union(i.bounds()):i.bounds()}return this.bounds=t,this.bounds}getSpanningTree(t){const e=new jt,i=new zt;let s,n;const o=t.clone();e.root(o),o.level=0,o.id=t.id,i.add(t,e.root()),t.level=0;const r=[],h=[];e._addNode(e.root()),r.push(t),h.push(t);let a=1;for(;h.length>0;){const t=h.pop();for(let o=0;o<t.links.length;o++){const l=t.links[o].getComplement(t);if(lt(r,l))continue;l.level=t.level+1,a<l.level+1&&(a=l.level+1),lt(h,l)||h.push(l),lt(r,l)||r.push(l),i.containsKey(t)?s=i.get(t):(s=t.clone(),s.level=t.level,s.id=t.id,i.add(t,s)),i.containsKey(l)?n=i.get(l):(n=l.clone(),n.level=l.level,n.id=l.id,i.add(l,n));const c=new Yt(s,n);e.addLink(c)}}const l=[];for(let t=0;t<a;t++)l.push([]);return rt(e.nodes,(function(t){l[t.level].push(t)})),e.treeLevels=l,e.cacheRelationships(),e}takeRandomNode(t,e){if(j(t)&&(t=[]),j(e)&&(e=4),0===this.nodes.length)return null;if(1===this.nodes.length)return lt(t,this.nodes[0])?null:this.nodes[0];const i=this.nodes.filter((function(i){return!lt(t,i)&&i.degree()<=e}));return $(i)?null:i[et(0,i.length)]}isEmpty(){return $(this.nodes)}isHealthy(){return _t(this.links,(function(t){return lt(this.nodes,t.source)&<(this.nodes,t.target)}),this)}getParents(t){if(!this.hasNode(t))throw new Error("The given node is not part of this graph.");return t.getParents()}getChildren(t){if(!this.hasNode(t))throw new Error("The given node is not part of this graph.");return t.getChildren()}addLink(t,e,i){if(j(t))throw new Error("The source of the link is not defined.");if(j(e)){if(q(t.type)&&"Link"===t.type)return void this.addExistingLink(t);throw new Error("The target of the link is not defined.")}let s=this.getNode(t);j(s)&&(s=this.addNode(t));let n=this.getNode(e);j(n)&&(n=this.addNode(e));const o=new Yt(s,n);return q(i)&&(o.owner=i),this.links.push(o),o}removeAllLinks(){for(;this.links.length>0;){const t=this.links[0];this.removeLink(t)}}addExistingLink(t){if(!this.hasLink(t)){if(this.links.push(t),this.hasNode(t.source.id)){const e=this.getNode(t.source.id);t.changeSource(e)}else this.addNode(t.source);if(this.hasNode(t.target.id)){const e=this.getNode(t.target.id);t.changeTarget(e)}else this.addNode(t.target)}}hasLink(t){if(J(t))return ht(this.links,(function(e){return e.id===t}));if("Link"===t.type)return lt(this.links,t);throw new Error("The given object is neither an identifier nor a Link.")}getNode(t){const e=t.id||t;if(this._nodeMap.containsKey(e))return this._nodeMap.get(e)}hasNode(t){const e=t.id||t;return this._nodeMap.containsKey(e)}_addNode(t){this.nodes.push(t),this._nodeMap.add(t.id,t)}_removeNode(t){at(this.nodes,t),this._nodeMap.remove(t.id)}removeNode(t){let e=t;if(J(t)&&(e=this.getNode(t)),!q(e))throw new Error("The identifier should be a Node or the Id (string) of a node.");{const t=e.links;e.links=[];for(let e=0,i=t.length;e<i;e++){const i=t[e];this.removeLink(i)}this._removeNode(e)}}areConnected(t,e){return ht(this.links,(function(i){return i.source===t&&i.target===e||i.source===e&&i.target===t}))}removeLink(t){at(this.links,t),at(t.source.outgoing,t),at(t.source.links,t),at(t.target.incoming,t),at(t.target.links,t)}addNode(t,e,i){let s=null;if(!q(t))throw new Error("No Node or identifier for a new Node is given.");if(J(t)){if(this.hasNode(t))return this.getNode(t);s=new Kt(t)}else{if(this.hasNode(t))return this.getNode(t);s=t}return q(e)&&s.bounds(e),q(i)&&(s.owner=i),this._addNode(s),s}addNodeAndOutgoings(t){this.hasNode(t)||this._addNode(t);const e=t.outgoing;t.outgoing=[],rt(e,(function(t){this.addExistingLink(t)}),this)}setItemIndices(){let t;for(t=0;t<this.nodes.length;++t)this.nodes[t].index=t;for(t=0;t<this.links.length;++t)this.links[t].index=t}clone(t){const e=new jt,i=q(t)&&!0===t;i&&(e.nodeMap=new zt,e.linkMap=new zt);const s=new zt;return rt(this.nodes,(function(t){const n=t.clone();s.set(t,n),e._addNode(n),i&&e.nodeMap.set(n,t)})),rt(this.links,(function(t){if(s.containsKey(t.source)&&s.containsKey(t.target)){const n=e.addLink(s.get(t.source),s.get(t.target));i&&e.linkMap.set(n,t)}})),e}linearize(t){return jt.Utils.linearize(this,t)}depthFirstTraversal(t,e){if(j(t))throw new Error("You need to supply a starting node.");if(j(e))throw new Error("You need to supply an action.");if(!this.hasNode(t))throw new Error("The given start-node is not part of this graph");const i=this.getNode(t);this._dftIterator(i,e,[])}_dftIterator(t,e,i){e(t),i.push(t);const s=t.getChildren();for(let t=0,n=s.length;t<n;t++){const n=s[t];lt(i,n)||this._dftIterator(n,e,i)}}breadthFirstTraversal(t,e){if(j(t))throw new Error("You need to supply a starting node.");if(j(e))throw new Error("You need to supply an action.");if(!this.hasNode(t))throw new Error("The given start-node is not part of this graph");const i=this.getNode(t),s=new At,n=[];for(s.enqueue(i);s.length>0;){const t=s.dequeue();e(t),n.push(t);const i=t.getChildren();for(let t=0,e=i.length;t<e;t++){const e=i[t];lt(n,e)||s.contains(e)||s.enqueue(e)}}}_stronglyConnectedComponents(t,e,i,s,n,o,r){i.add(e,r),s.add(e,r),r++,o.push(e);const h=e.getChildren();let a;for(let l=0,c=h.length;l<c;l++)a=h[l],i.containsKey(a)?lt(o,a)&&s.add(e,Math.min(s.get(e),i.get(a))):(this._stronglyConnectedComponents(t,a,i,s,n,o,r),s.add(e,Math.min(s.get(e),s.get(a))));if(s.get(e)===i.get(e)){const i=[];do{a=o.pop(),i.push(a)}while(a!==e);(!t||i.length>1)&&n.push(i)}}findCycles(t){j(t)&&(t=!0);const e=new zt,i=new zt,s=[],n=[];for(let o=0,r=this.nodes.length;o<r;o++){const r=this.nodes[o];e.containsKey(r)||this._stronglyConnectedComponents(t,r,e,i,s,n,0)}return s}isAcyclic(){return $(this.findCycles())}isSubGraph(t){const e=t.linearize(),i=this.linearize();return _t(e,(function(t){return lt(i,t)}))}makeAcyclic(){if(this.isEmpty()||this.nodes.length<=1||this.links.length<=1)return[];if(2===this.nodes.length){const t=[];if(this.links.length>1){const e=this.links[0].source;for(let i=0,s=this.links.length;i<s;i++){const s=this.links[i];if(s.source===e)continue;const n=s.reverse();t.push(n)}}return t}const t=this.clone(!0),e=this.nodes.length,i=new zt,s=function(t){return 0===t.outgoing.length?2-e:0===t.incoming.length?e-2:t.outgoing.length-t.incoming.length},n=function(t){const e=s(t);i.containsKey(e)||i.set(e,[]),i.get(e).push(t)};rt(t.nodes,(function(t){n(t)}));let o=[];const r=[];for(;t.nodes.length>0;){let h,a,l;if(i.containsKey(2-e)){const o=i.get(2-e);for(;o.length>0;){a=o.pop();for(let t=0;t<a.links.length;t++){const e=a.links[t];h=e.getComplement(a),l=s(h),at(i.get(l),h),h.removeLink(e),n(h)}t._removeNode(a),r.unshift(a)}}if(i.containsKey(e-2)){const r=i.get(e-2);for(;r.length>0;){h=r.pop();for(let t=0;t<h.links.length;t++){const e=h.links[t];a=e.getComplement(h),l=s(a),at(i.get(l),a),a.removeLink(e),n(a)}o.push(h),t._removeNode(h)}}if(t.nodes.length>0)for(let r=e-3;r>2-e;r--)if(i.containsKey(r)&&i.get(r).length>0){const e=i.get(r).pop();for(let t=0;t<e.links.length;t++){const o=e.links[t],r=o.getComplement(e);l=s(r),at(i.get(l),r),r.removeLink(o),n(r)}o.push(e),t._removeNode(e);break}}o=o.concat(r);const h=new zt;for(let e=0;e<this.nodes.length;e++)h.set(t.nodeMap.get(o[e]),e);const a=[];return rt(this.links,(function(t){h.get(t.source)>h.get(t.target)&&(t.reverse(),a.push(t))})),a}}jt.Predefined={EightGraph:()=>jt.Utils.parse(["1->2","2->3","3->4","4->1","3->5","5->6","6->7","7->3"]),Mindmap:()=>jt.Utils.parse(["0->1","0->2","0->3","0->4","0->5","1->6","1->7","7->8","2->9","9->10","9->11","3->12","12->13","13->14","4->15","4->16","15->17","15->18","18->19","18->20","14->21","14->22","5->23","23->24","23->25","6->26"]),ThreeGraph:()=>jt.Utils.parse(["1->2","2->3","3->1"]),BinaryTree:t=>(j(t)&&(t=5),jt.Utils.createBalancedTree(t,2)),Linear:t=>(j(t)&&(t=10),jt.Utils.createBalancedTree(t,1)),Tree:(t,e)=>jt.Utils.createBalancedTree(t,e),Forest:(t,e,i)=>jt.Utils.createBalancedForest(t,e,i),Workflow:()=>jt.Utils.parse(["0->1","1->2","2->3","1->4","4->3","3->5","5->6","6->3","6->7","5->4"]),Grid(t,e){const i=new jt;if(t<=0&&e<=0)return i;for(let s=0;s<t+1;s++){let t=null;for(let n=0;n<e+1;n++){const e=new Kt(s.toString()+"."+n.toString());if(i.addNode(e),t&&i.addLink(t,e),s>0){const t=i.getNode((s-1).toString()+"."+n.toString());i.addLink(t,e)}t=e}}return i}},jt.Utils={parse(t){let e;const i=new jt,s=t.slice();for(let t=0,n=s.length;t<n;t++){const n=s[t];if(J(n)){if(n.indexOf("->")<0)throw new Error("The link should be specified as 'a->b'.");const t=n.split("->");if(2!==t.length)throw new Error("The link should be specified as 'a->b'.");e=new Yt(t[0],t[1]),i.addLink(e)}if(G(n)){if(!e)throw new Error("Specification found before Link definition.");Ft(e,n)}}return i},linearize(t,e){if(j(t))throw new Error("Expected an instance of a Graph object in slot one.");j(e)&&(e=!1);const i=[];for(let s=0,n=t.links.length;s<n;s++){const n=t.links[s];i.push(n.source.id+"->"+n.target.id),e&&i.push({id:n.id})}return i},_addShape:(t,e,i,s)=>(j(e)&&(e=new Ot(0,0)),j(i)&&(i=Pt()),s=Ft({width:20,height:20,id:i,radius:10,fill:"#778899",data:"circle",undoable:!1,x:e.x,y:e.y},s),t.addShape(s)),_addConnection:(t,e,i,s)=>t.connect(e,i,s),createDiagramFromGraph(t,e,i,s){if(j(t))throw new Error("The diagram surface is undefined.");if(j(e))throw new Error("No graph specification defined.");j(i)&&(i=!0),j(s)&&(s=!1);const n=t.element.clientWidth||200,o=t.element.clientHeight||200,r=[];let h,a;for(let i=0,l=e.nodes.length;i<l;i++){h=e.nodes[i];let l=h.position;j(l)&&(l=q(h.x)&&q(h.y)?new Ot(h.x,h.y):new Ot(et(10,n-20),et(10,o-20)));const c={};"0"===h.id||s&&Ft(c,{width:150*Math.random()+20,height:80*Math.random()+50,data:"rectangle",fill:{color:"#778899"}}),a=this._addShape(t,l,h.id,c);const d=a.bounds();q(d)&&(h.x=d.x,h.y=d.y,h.width=d.width,h.height=d.height),r[h.id]=a}for(let i=0;i<e.links.length;i++){const s=e.links[i],n=r[s.source.id];if(j(n))continue;const o=r[s.target.id];j(o)||this._addConnection(t,n,o,{id:s.id})}if(i){new Gt(t).layoutGraph(e,{limitToView:!1});for(let t=0;t<e.nodes.length;t++)h=e.nodes[t],a=r[h.id],a.bounds(new Bt(h.x,h.y,h.width,h.height))}},createBalancedTree(t,e){j(t)&&(t=3),j(e)&&(e=3);const i=new jt;let s,n=-1,o=[];if(t<=0||e<=0)return i;const r=new Kt((++n).toString());i.addNode(r),i.root(r),o.push(r);for(let r=0;r<t;r++){s=[];for(let t=0;t<o.length;t++){const r=o[t];for(let t=0;t<e;t++){const t=new Kt((++n).toString());i.addLink(r,t),s.push(t)}}o=s}return i},createBalancedForest(t,e,i){j(t)&&(t=3),j(e)&&(e=3),j(i)&&(i=5);const s=new jt;let n,o=-1,r=[];if(t<=0||e<=0||i<=0)return s;for(let h=0;h<i;h++){const i=new Kt((++o).toString());s.addNode(i),r=[i];for(let i=0;i<t;i++){n=[];for(let t=0;t<r.length;t++){const i=r[t];for(let t=0;t<e;t++){const t=new Kt((++o).toString());s.addLink(i,t),n.push(t)}}r=n}}return s},createRandomConnectedGraph(t,e,i){j(t)&&(t=40),j(e)&&(e=4),j(i)&&(i=!1);const s=new jt;let n=-1;if(t<=0)return s;const o=new Kt((++n).toString());if(s.addNode(o),1===t)return s;if(t>1){for(let i=1;i<t;i++){const t=s.takeRandomNode([],e);if(!t)break;const n=s.addNode(i.toString());s.addLink(t,n)}if(!i&&t>1){const i=et(1,t);for(let t=0;t<i;t++){const t=s.takeRandomNode([],e),i=s.takeRandomNode([],e);t&&i&&!s.areConnected(t,i)&&s.addLink(t,i)}}return s}},randomDiagram(t,e,i,s,n){const o=jt.Utils.createRandomConnectedGraph(e,i,s);jt.Utils.createDiagramFromGraph(t,o,!1,n)}};class Gt extends Wt{constructor(t){if(super(),j(t))throw new Error("Diagram is not specified.");this.diagram=t}layout(t){this.transferOptions(t);const e=new Xt(this.diagram).convert(t);if(e.isEmpty())return;const i=e.getConnectedComponents();if($(i))return;for(let e=0;e<i.length;e++){const s=i[e];this.layoutGraph(s,t)}const s=this.gridLayoutComponents(i);return new qt(this.diagram,s)}layoutGraph(t,e){q(e)&&this.transferOptions(e),this.graph=t;const i=9*this.options.nodeDistance;this.temperature=i;const s=this._expectedBounds();this.width=s.width,this.height=s.height;for(let t=0;t<this.options.iterations;t++)this.refineStage=t>=5*this.options.iterations/6,this.tick(),this.temperature=this.refineStage?i/30:i*(1-t/(2*this.options.iterations))}tick(){let t;for(t=0;t<this.graph.nodes.length;t++)this._repulsion(this.graph.nodes[t]);for(t=0;t<this.graph.links.length;t++)this._attraction(this.graph.links[t]);for(t=0;t<this.graph.nodes.length;t++){const e=this.graph.nodes[t],i=Math.sqrt(e.dx*e.dx+e.dy*e.dy);if(0===i)return;e.x+=Math.min(i,this.temperature)*e.dx/i,e.y+=Math.min(i,this.temperature)*e.dy/i,this.options.limitToView&&(e.x=Math.min(this.width,Math.max(e.width/2,e.x)),e.y=Math.min(this.height,Math.max(e.height/2,e.y)))}}_shake(t){const e=Math.random()*this.options.nodeDistance/4,i=2*Math.random()*Math.PI;t.x+=e*Math.cos(i),t.y-=e*Math.sin(i)}_InverseSquareForce(t,e,i){let s;if(this.refineStage){const t=e.x-i.x,n=e.y-i.y,o=e.width/2,r=e.height/2,h=i.width/2,a=i.height/2;s=Math.pow(t,2)/Math.pow(o+h+this.options.nodeDistance,2)+Math.pow(n,2)/Math.pow(r+a+this.options.nodeDistance,2)}else s=Math.pow(t,2)/Math.pow(this.options.nodeDistance,2);return 4*s/3}_SquareForce(t,e,i){return 1/this._InverseSquareForce(t,e,i)}_repulsion(t){t.dx=0,t.dy=0,rt(this.graph.nodes,(function(e){if(e===t)return;for(;t.x===e.x&&t.y===e.y;)this._shake(e);const i=t.x-e.x,s=t.y-e.y,n=Math.sqrt(i*i+s*s),o=2*this._SquareForce(n,t,e);t.dx+=i/n*o,t.dy+=s/n*o}),this)}_attraction(t){const e=t.target,i=t.source;if(i===e)return;for(;i.x===e.x&&i.y===e.y;)this._shake(e);const s=i.x-e.x,n=i.y-e.y,o=Math.sqrt(s*s+n*n),r=5*this._InverseSquareForce(o,i,e),h=s/o*r,a=n/o*r;e.dx+=h,e.dy+=a,i.dx-=h,i.dy-=a}_expectedBounds(){const t=this.graph.nodes.length;if(0===t)return;const e=pt(this.graph.nodes,(function(t,e){const i=e.width*e.height;return i>0?t+=Math.sqrt(i):0}),0,this)/t*Math.ceil(Math.sqrt(t));return{width:4*(e*Math.sqrt(1.5)),height:4*(e/Math.sqrt(1.5))}}}class Xt{constructor(t){this.nodeMap=new zt,this.shapeMap=new zt,this.nodes=[],this.edges=[],this.edgeMap=new zt,this.finalNodes=[],this.finalLinks=[],this.ignoredConnections=[],this.ignoredShapes=[],this.hyperMap=new zt,this.hyperTree=new jt,this.finalGraph=null,this.diagram=t}convert(t){if(j(this.diagram))throw new Error("No diagram to convert.");return this.options=Ft({ignoreInvisible:!0,ignoreContainers:!0,layoutContainerChildren:!1},t||{}),this.clear(),this._renormalizeShapes(),this._renormalizeConnections(),this.finalNodes=new zt(this.nodes),this.finalLinks=new zt(this.edges),this.finalGraph=new jt,this.finalNodes.forEach((function(t){this.finalGraph.addNode(t)}),this),this.finalLinks.forEach((function(t){this.finalGraph.addExistingLink(t)}),this),this.finalGraph}mapConnection(t){return this.edgeMap.get(t.id)}mapShape(t){return this.nodeMap.get(t.id)}getEdge(t,e){return ft(t.links,(function(i){return i.getComplement(t)===e}))}clear(){this.finalGraph=null,this.hyperTree=!this.options.ignoreContainers&&this.options.layoutContainerChildren?new jt:null,this.hyperMap=!this.options.ignoreContainers&&this.options.layoutContainerChildren?new zt:null,this.nodeMap=new zt,this.shapeMap=new zt,this.nodes=[],this.edges=[],this.edgeMap=new zt,this.ignoredConnections=[],this.ignoredShapes=[],this.finalNodes=[],this.finalLinks=[]}listToRoot(t){const e=[];let i=t.container;if(!i)return e;for(e.push(i);i.parentContainer;)i=i.parentContainer,e.push(i);return e.reverse(),e}firstNonIgnorableContainer(t){return t.isContainer&&!this.isIgnorableItem(t)?t:t.parentContainer?this.firstNonIgnorableContainer(t.parentContainer):null}isContainerConnection(t,e){return!(!t.isContainer||!this.isDescendantOf(t,e))||e.isContainer&&this.isDescendantOf(e,t)}isDescendantOf(t,e){if(!t.isContainer)throw new Error("Expecting a container.");if(t===e)return!1;if(lt(t.children,e))return!0;const i=[];for(let s=0,n=t.children.length;s<n;s++){const n=t.children[s];n.isContainer&&this.isDescendantOf(n,e)&&i.push(n)}return i.length>0}isIgnorableItem(t){return this.options.ignoreInvisible?(!t.isCollapsed||!this._isVisible(t))&&!(!t.isCollapsed&&this._isVisible(t)):t.isCollapsed&&!this._isTop(t)}isShapeMapped(t){return t.isCollapsed&&!this._isVisible(t)&&!this._isTop(t)}leastCommonAncestor(t,e){if(!t)throw new Error("Parameter should not be null.");if(!e)throw new Error("Parameter should not be null.");if(!this.hyperTree)throw new Error("No hypertree available.");const i=this.listToRoot(t),s=this.listToRoot(e);let n=null;if($(i)||$(s))return this.hyperTree.root().data;let o=i[0],r=s[0],h=0;for(;o===r&&(n=i[h],h++,!(h>=i.length||h>=s.length));)o=i[h],r=s[h];return n?this.hyperTree.nodes.filter((function(t){return t.data.container===n})):this.hyperTree.root().data}_isTop(t){return!t.parentContainer}_isVisible(t){return!!t.visible()&&(t.parentContainer?this._isVisible(t.parentContainer):t.visible())}_isCollapsed(t){return!(!t.isContainer||!t.isCollapsed)||t.parentContainer&&this._isCollapsed(t.parentContainer)}_renormalizeShapes(){if(!this.options.ignoreContainers)throw new Error("Containers are not supported yet, but stay tuned.");for(let t=0,e=this.diagram.shapes.length;t<e;t++){const e=this.diagram.shapes[t];if(this.options.ignoreInvisible&&!this._isVisible(e)||e.isContainer){this.ignoredShapes.push(e);continue}const i=new Kt(e.id,e);i.isVirtual=!1,this.nodeMap.add(e.id,i),this.nodes.push(i)}}_renormalizeConnections(){if(0!==this.diagram.connections.length)for(let t=0,e=this.diagram.connections.length;t<e;t++){const e=this.diagram.connections[t];if(this.isIgnorableItem(e)){this.ignoredConnections.push(e);continue}let i=e.sourceConnector?e.sourceConnector.shape:null,s=e.targetConnector?e.targetConnector.shape:null;if(!i||!s){this.ignoredConnections.push(e);continue}if(lt(this.ignoredShapes,i)&&!this.shapeMap.containsKey(i)){this.ignoredConnections.push(e);continue}if(lt(this.ignoredShapes,s)&&!this.shapeMap.containsKey(s)){this.ignoredConnections.push(e);continue}this.shapeMap.containsKey(i)&&(i=this.shapeMap[i]),this.shapeMap.containsKey(s)&&(s=this.shapeMap[s]);const n=this.mapShape(i),o=this.mapShape(s);if(n===o||this.areConnectedAlready(n,o))this.ignoredConnections.push(e);else{if(null===n||null===o)throw new Error("A shape was not mapped to a node.");if(!this.options.ignoreContainers)throw new Error("Containers are not supported yet, but stay tuned.");{if(n.isVirtual||o.isVirtual){this.ignoredConnections.push(e);continue}const t=new Yt(n,o,e.id,e);this.edgeMap.add(e.id,t),this.edges.push(t)}}}}areConnectedAlready(t,e){return ht(this.edges,(function(i){return i.source===t&&i.target===e||i.source===e&&i.target===t}))}}function Jt(t,e,i,s,n){const o=(e.x-t.x)*(s.y-i.y)-(e.y-t.y)*(s.x-i.x);if(W(o))return;const r=((t.y-i.y)*(s.x-i.x)-(t.x-i.x)*(s.y-i.y))/o,h=((t.y-i.y)*(e.x-t.x)-(t.x-i.x)*(e.y-t.y))/o;return n&&(r<0||r>1||h<0||h>1)?void 0:new Ot(t.x+r*(e.x-t.x),t.y+r*(e.y-t.y))}const Zt={lines:(t,e,i,s)=>Jt(t,e,i,s),segments:(t,e,i,s)=>Jt(t,e,i,s,!0),rectWithLine:(t,e,i)=>Zt.segments(e,i,t.topLeft(),t.topRight())||Zt.segments(e,i,t.topRight(),t.bottomRight())||Zt.segments(e,i,t.bottomLeft(),t.bottomRight())||Zt.segments(e,i,t.topLeft(),t.bottomLeft()),rects(t,e,i){let s=e.topLeft(),n=e.topRight(),o=e.bottomLeft(),r=e.bottomRight();const h=e.center();i&&(s=s.rotate(i,h),n=n.rotate(i,h),o=o.rotate(i,h),r=r.rotate(i,h));let a=t.contains(s)||t.contains(n)||t.contains(o)||t.contains(r)||Zt.rectWithLine(t,s,n)||Zt.rectWithLine(t,s,o)||Zt.rectWithLine(t,n,r)||Zt.rectWithLine(t,o,r);if(!a){if(s=t.topLeft(),n=t.topRight(),o=t.bottomLeft(),r=t.bottomRight(),i){const t=360-i;s=s.rotate(t,h),n=n.rotate(t,h),o=o.rotate(t,h),r=r.rotate(t,h)}a=e.contains(s)||e.contains(n)||e.contains(o)||e.contains(r)}return a}},$t=(t,e)=>t.map(e);class Qt{constructor(t,e,i,s,n,o){this.a=t||0,this.b=e||0,this.c=i||0,this.d=s||0,this.e=n||0,this.f=o||0}fromMatrix(t){const e=new Qt;return e.a=t.a,e.b=t.b,e.c=t.c,e.d=t.d,e.e=t.e,e.f=t.f,e}}class te{constructor(t,e,i,s,n,o){this.a=t||0,this.b=e||0,this.c=i||0,this.d=s||0,this.e=n||0,this.f=o||0}plus(t){this.a+=t.a,this.b+=t.b,this.c+=t.c,this.d+=t.d,this.e+=t.e,this.f+=t.f}minus(t){this.a-=t.a,this.b-=t.b,this.c-=t.c,this.d-=t.d,this.e-=t.e,this.f-=t.f}times(t){return new te(this.a*t.a+this.c*t.b,this.b*t.a+this.d*t.b,this.a*t.c+this.c*t.d,this.b*t.c+this.d*t.d,this.a*t.e+this.c*t.f+this.e,this.b*t.e+this.d*t.f+this.f)}apply(t){return new Ot(this.a*t.x+this.c*t.y+this.e,this.b*t.x+this.d*t.y+this.f)}applyRect(t){return Bt.fromPoints(this.apply(t.topLeft()),this.apply(t.bottomRight()))}toString(){return"matrix("+this.a+" "+this.b+" "+this.c+" "+this.d+" "+this.e+" "+this.f+")"}static fromSVGMatrix(t){const e=new te;return e.a=t.a,e.b=t.b,e.c=t.c,e.d=t.d,e.e=t.e,e.f=t.f,e}static fromMatrixVector(t){const e=new te;return e.a=t.a,e.b=t.b,e.c=t.c,e.d=t.d,e.e=t.e,e.f=t.f,e}static fromList(t){if(6!==t.length)throw new Error("The given list should consist of six elements.");const e=new te;return e.a=t[0],e.b=t[1],e.c=t[2],e.d=t[3],e.e=t[4],e.f=t[5],e}static translation(t,e){const i=new te;return i.a=1,i.b=0,i.c=0,i.d=1,i.e=t,i.f=e,i}static unit(){return new te(1,0,0,1,0,0)}static rotation(t,e,i){const s=new te;return s.a=Math.cos(t*Math.PI/180),s.b=Math.sin(t*Math.PI/180),s.c=-s.b,s.d=s.a,s.e=e-e*s.a+i*s.b||0,s.f=i-i*s.a-e*s.b||0,s}static scaling(t,e){const i=new te;return i.a=t,i.b=0,i.c=0,i.d=e,i.e=0,i.f=0,i}static parse(t){let e,i;if(t){if("matrix"===(t=t.trim()).slice(0,6).toLowerCase()){if(i=t.slice(7,t.length-1).trim(),e=i.split(","),6===e.length)return te.fromList($t(e,(function(t){return parseFloat(t)})));if(e=i.split(" "),6===e.length)return te.fromList($t(e,(function(t){return parseFloat(t)})))}if("("===t.slice(0,1)&&")"===t.slice(t.length-1)&&(t=t.substr(1,t.length-1)),t.indexOf(",")>0&&(e=t.split(","),6===e.length))return te.fromList($t(e,(function(t){return parseFloat(t)})));if(t.indexOf(" ")>0&&(e=t.split(" "),6===e.length))return te.fromList($t(e,(function(t){return parseFloat(t)})))}return e}}class ee{constructor(t,e,i){this.point=t,this.left=e,this.right=i}}class ie{constructor(t,e){this.width=t,this.height=e}static Empty(){return new ie(0,0)}}class se{constructor(t,e,i){this.x=e||0,this.y=i||0,this.angle=t}toString(){return this.x&&this.y?`rotate(${this.angle},${this.x},${this.y})`:`rotate(${this.angle})`}toMatrix(){return te.rotation(this.angle,this.x,this.y)}center(){return new Ot(this.x,this.y)}invert(){return new se(360-this.angle,this.x,this.y)}static create(t){return new se(t.angle,t.x,t.y)}static parse(t){const e=t.slice(1,t.length-1).split(","),i=parseFloat(e[0]),s=parseFloat(e[1]),n=parseFloat(e[2]);return new se(i,s,n)}}se.ZERO=new se(0);class ne{constructor(t,e){this.x=t,this.y=e}toMatrix(){return te.scaling(this.x,this.y)}toString(){return`scale(${this.x},${this.y})`}invert(){return new ne(1/this.x,1/this.y)}}class oe{constructor(t,e){this.x=t,this.y=e}toMatrixVector(){return new Qt(0,0,0,0,this.x,this.y)}toMatrix(){return te.translation(this.x,this.y)}toString(){return`translate(${this.x},${this.y})`}plus(t){this.x+=t.x,this.y+=t.y}times(t){this.x*=t,this.y*=t}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}normalize(){0!==this.Length&&this.times(1/this.length())}invert(){return new oe(-this.x,-this.y)}}class re{constructor(t,e,i,s,n,o){this.translate=new oe(t,e),void 0!==i&&void 0!==s&&(this.scale=new ne(i,s)),void 0!==n&&(this.rotate=o?new se(n,o.x,o.y):new se(n))}toString(){const t=function(t){return t?t.toString():""};return t(this.translate)+t(this.rotate)+t(this.scale)}render(t){t._transform=this,t._renderTransform()}toMatrix(){let t=te.unit();return this.translate&&(t=t.times(this.translate.toMatrix())),this.rotate&&(t=t.times(this.rotate.toMatrix())),this.scale&&(t=t.times(this.scale.toMatrix())),t}invert(){const t=this.rotate?this.rotate.invert():void 0,e=t?t.toMatrix():te.unit(),i=this.scale?this.scale.invert():void 0,s=i?i.toMatrix():te.unit();let n=new Ot(-this.translate.x,-this.translate.y);n=e.times(s).apply(n);const o=new oe(n.x,n.y),r=new re;return r.translate=o,r.rotate=t,r.scale=i,r}}function he(t,e){const i=this.options;let s,n,o=!1;for(let r=0;r<e.length;r++)n=e[r],s=t[n],Z(s)&&i[n]!==s&&(i[n]=s,o=!0);return o}class ae{constructor(t){this.options=Ft({},this.options,t),this.id=this.options.id,this._originSize=Bt.empty(),this._transform=new re}visible(t){return this.drawingContainer().visible(t)}redraw(t){t&&t.id&&(this.id=t.id)}position(t,e){const i=this.options;if(!K(t))return new Ot(i.x,i.y);K(e)?(i.x=t,i.y=e):t instanceof Ot&&(i.x=t.x,i.y=t.y),this._transform.translate=new oe(i.x,i.y),this._renderTransform()}rotate(t,e){return K(t)&&(this._transform.rotate=new se(t,e.x,e.y),this._renderTransform()),this._transform.rotate||se.ZERO}drawingContainer(){return this.drawingElement}_renderTransform(){const t=this._transform.toMatrix();this.drawingContainer().transform(new e.M(t.a,t.b,t.c,t.d,t.e,t.f))}_hover(){}_diffNumericOptions(t,e){return he.call(this,t,e)}_measure(t){let i;if(!this._measured||t){const t=this._boundingBox()||new e.R([0,0],[0,0]),s=t.topLeft();i=new Bt(s.x,s.y,t.width(),t.height()),this._originSize=i,this._originWidth=i.width,this._originHeight=i.height,this._measured=!0}else i=this._originSize;return i}_boundingBox(){return this.drawingElement.rawBBox()}}function le(t){return{x:t.x||0,y:t.y||0,width:t.width||0,height:t.height||0}}function ce(t){if(t){let e=t;return J(e)&&(e={color:e}),e.color&&(e.color=de(e.color)),e}}function de(t){let i;return i=t!==h?new e.C(t).toHex():t,i}function ue(t,i){return new e.S(new e.P(t,i))}function pe(t){if(t)return new e.R([t.x,t.y],[t.width,t.height])}const ge={stroke:{color:"gray",width:1},fill:{color:h}};class fe extends ae{constructor(t){super(t=Ft({},ge,t)),(t=this.options).fill=ce(t.fill),t.stroke=ce(t.stroke)}fill(t,e){this._fill({color:de(t),opacity:e})}stroke(t,e,i){this._stroke({color:de(t),width:e,opacity:i})}redraw(t){if(t){const e=t.stroke,i=t.fill;e&&this._stroke(ce(e)),i&&this._fill(ce(i)),super.redraw(t)}}_hover(t){const e=this.drawingElement,i=this.options,s=i.hover;if(s&&s.fill){const n=t?ce(s.fill):i.fill;e.fill(n.color,n.opacity)}}_stroke(t){const e=this.options;Ft(e,{stroke:t});let i=null;(t=e.stroke).width>0&&(i={color:t.color,width:t.width,opacity:t.opacity,dashType:t.dashType}),this.drawingElement.options.set("stroke",i)}_fill(t){const i=this.options;Ft(i,{fill:t||{}});const s=i.fill;if(s.gradient){const t=s.gradient,i="radial"===t.type?e.i:e.L;this.drawingElement.fill(new i(t))}else this.drawingElement.fill(s.color,s.opacity)}}const me={stroke:{color:h,width:0},fill:{color:"black"}};class _e extends fe{constructor(t){super(t=Ft({},me,t));const i=this.options.anchor||{};this.anchor=new e.P(i.x,i.y),this.createElement()}createElement(){}_transformToPath(t,e){const i=e.transform();return t&&i&&(t=t.transformCopy(i)),t}redraw(t){t&&(t.position&&(this.options.position=t.position),super.redraw(t))}}const ye={path:"M 0 0 L 10 5 L 0 10 L 3 5 z",anchor:{x:10,y:5}};class we extends _e{constructor(t){super(t=Ft({},ye,t))}createElement(){const t=this.options;this.drawingElement=e.b.parse(t.path,{fill:t.fill,stroke:t.stroke})}positionMarker(t){const i=this._linePoints(t),s=i.start,n=i.end,o=e.t();if(s&&o.rotate(function(t,i){const s=i.x-t.x,n=i.y-t.y;return e.v(Math.atan2(n,s))}(s,n),n),n){const t=this.anchor,e=n.clone().translate(-t.x,-t.y);o.translate(e.x,e.y)}this.drawingElement.transform(o)}_linePoints(t){const e=this.options,i=t.segments;let s,n,o;if(e.position===a){if(o=i[0],o){n=o.anchor(),s=o.controlOut();const t=i[1];!s&&t&&(s=t.anchor())}}else if(o=i[i.length-1],o){n=o.anchor(),s=o.controlIn();const t=i[i.length-2];!s&&t&&(s=t.anchor())}if(n)return{start:this._transformToPath(s,t),end:this._transformToPath(n,t)}}}let ve=class{constructor(t,i){this._translate=(t,e)=>{const i=this._viewBox;return K(t)&&K(e)&&(i.x=t,i.y=e,this.surface.translate({x:t,y:e})),{x:i.x,y:i.y}},i=i||{},this.element=t,this.surface=e.n.create(t,i),Y(this.surface.translate)&&(this.translate=this._translate),this.drawingElement=new e.G,this._viewBox=new Bt(0,0,i.width,i.height),this.size(this._viewBox)}bounds(){const t=this.drawingElement.clippedBBox();return new Bt(0,0,t.width(),t.height())}size(t){const e=this._viewBox;return K(t)&&(e.width=t.width,e.height=t.height,this.surface.setSize(t)),{width:e.width,height:e.height}}draw(){this.surface.draw(this.drawingElement)}append(t){return this.drawingElement.append(t.drawingContainer()),this}remove(t){this.drawingElement.remove(t.drawingContainer())}insertBefore(){}clear(){this.drawingElement.clear()}destroy(t){this.surface.destroy(),t&&(!function(t){for(;t.firstChild;)t.removeChild(t.firstChild)}(this.element),this.element.remove())}};const xe={_setScale:function(){const t=this.options,e=this._originWidth,i=this._originHeight;let s=t.width/e,n=t.height/i;Z(s)||(s=1),Z(n)||(n=1),this._transform.scale=new ne(s,n)},_setTranslate:function(){const t=this.options,e=t.x||0,i=t.y||0;this._transform.translate=new oe(e,i)},_initSize:function(){const t=this.options;let e=!1;!1!==t.autoSize&&(q(t.width)||q(t.height))&&(this._measure(!0),this._setScale(),e=!0),(q(t.x)||q(t.y))&&(this._setTranslate(),e=!0),e&&this._renderTransform()},_updateSize:function(t){let e=!1;return!1!==this.options.autoSize&&this._diffNumericOptions(t,[s,n])&&(e=!0,this._measure(!0),this._setScale()),this._diffNumericOptions(t,[o,r])&&(e=!0,this._setTranslate()),e&&this._renderTransform(),e}};class be extends fe{constructor(t){super(t),this._setScale=xe._setScale.bind(this),this._setTranslate=xe._setTranslate.bind(this),this._initSize=xe._initSize.bind(this),this._updateSize=xe._updateSize.bind(this),this._initCircle(),this._initSize()}redraw(t){if(t){const e=this.options;t.center&&(Ft(e,{center:t.center}),this._center.move(e.center.x,e.center.y)),this._diffNumericOptions(t,["radius"])&&this._circle.setRadius(e.radius),this._updateSize(t),super.redraw.call(this,t)}}_initCircle(){const t=this.options;let i=t.width,s=t.height,n=t.radius;K(n)||(K(i)||(i=s),K(s)||(s=i),t.radius=n=Math.min(i,s)/2);const o=t.center||{x:n,y:n};this._center=new e.P(o.x,o.y),this._circle=new e.g(this._center,n),this.drawingElement=new e.f(this._circle,{stroke:t.stroke}),this._fill()}}const Ce={radius:4,anchor:{x:0,y:0}};class Se extends _e{constructor(t){super(t=Ft({},Ce,t))}createElement(){const t=this.options;this.drawingElement=new e.f(new e.g(this.anchor,t.radius),{fill:t.fill,stroke:t.stroke})}positionMarker(t){const i=this.options.position,s=t.segments;let n,o;n=i===a?s[0]:s[s.length-1],n&&(o=this._transformToPath(n.anchor(),t),this.drawingElement.transform(e.t().translate(o.x,o.y)))}}class Me extends ae{constructor(t){super(t=Ft({autoSize:!1},t)),this.children=[],this._childrenChange=!1,this._setScale=xe._setScale.bind(this),this._setTranslate=xe._setTranslate.bind(this),this._initSize=xe._initSize.bind(this),this._updateSize=xe._updateSize.bind(this),this.drawingElement=new e.G,this._initSize()}append(t){this.drawingElement.append(t.drawingContainer()),this.children.push(t),this._childrenChange=!0}remove(t){this._remove(t)&&(this._childrenChange=!0)}_remove(t){const e=this.children.indexOf(t);if(e>=0)return this.drawingElement.removeAt(e),this.children.splice(e,1),!0}clear(){this.drawingElement.clear(),this.children=[],this._childrenChange=!0}toFront(t){let e;for(let i=0;i<t.length;i++)e=t[i],this._remove(e)&&this.append(e)}toBack(t){this._reorderChildren(t,0)}toIndex(t,e){this._reorderChildren(t,e)}_reorderChildren(t,e){const i=this.drawingElement,s=i.children.slice(0),n=this.children,o=Z(e);let r,h,a,l,c;for(r=0;r<t.length;r++)c=t[r],l=c.drawingContainer(),h=n.indexOf(c),h>=0&&(s.splice(h,1),n.splice(h,1),a=o?e:e[r],s.splice(a,0,l),n.splice(a,0,c));i.clear(),i.append(...s)}redraw(t){t&&(this._childrenChange?(this._childrenChange=!1,this._updateSize(t)||this._initSize()):this._updateSize(t),super.redraw(t))}_boundingBox(){const t=this.children;let i,s,n;for(let o=0;o<t.length;o++)s=t[o],s.visible()&&!1!==s._includeInBBox&&(n=s.drawingContainer().clippedBBox(null),n&&(i=i?e.R.union(i,n):n));return i}}class ke extends ae{constructor(t){super(t),this._initImage()}redraw(t){t&&(t.source&&this.drawingElement.src(t.source),this._diffNumericOptions(t,[s,n,o,r])&&this.drawingElement.rect(this._rect()),super.redraw(t))}_initImage(){const t=this.options,i=this._rect();this.drawingElement=new e.I(t.source,i)}_rect(){const t=le(this.options),i=new e.P(t.x,t.y),s=new e.q(t.width,t.height);return new e.R(i,s)}}const Te={_getPath:function(t){let i=this.drawingElement;if(i instanceof e.h&&(i=t===a?i.paths[0]:i.paths[i.paths.length-1]),i&&i.segments.length)return i},_normalizeMarkerOptions:function(t){const e=t.startCap,i=t.endCap;J(e)&&(t.startCap={type:e}),J(i)&&(t.endCap={type:i})},_removeMarker:function(t){const e=this._markers[t];e&&(this.drawingContainer().remove(e.drawingElement),delete this._markers[t])},_createMarkers:function(){const t=this.options;this._normalizeMarkerOptions(t),this._markers={},this._markers[a]=this._createMarker(t.startCap,a),this._markers[l]=this._createMarker(t.endCap,l)},_createMarker:function(t,e){const i=(t||{}).type,s=this._getPath(e);let n,o;if(s)return i===c.filledCircle?n=Se:i===c.arrowStart||i===c.arrowEnd?n=we:this._removeMarker(e),n?(o=new n(Ft({},t,{position:e})),o.positionMarker(s),this.drawingContainer().append(o.drawingElement),o):void 0;this._removeMarker(e)},_positionMarker:function(t){const e=this._markers[t];if(e){const i=this._getPath(t);i?e.positionMarker(i):this._removeMarker(t)}},_capMap:{start:"startCap",end:"endCap"},_redrawMarker:function(t,e,i){this._normalizeMarkerOptions(i);const s=this.options,n=this._capMap[e],o=(s[n]||{}).type,r=i[n];let h=!1;return r?(s[n]=Ft({},s[n],r),r.type&&o!==r.type?(this._removeMarker(e),this._markers[e]=this._createMarker(s[n],e),h=!0):this._markers[e]&&this._markers[e].redraw(r)):t&&!this._markers[e]&&s[n]&&(this._markers[e]=this._createMarker(s[n],e),h=!0),h},_redrawMarkers:function(t,e){!this._redrawMarker(t,a,e)&&t&&this._positionMarker(a),!this._redrawMarker(t,l,e)&&t&&this._positionMarker(l)}};class Ee extends fe{constructor(t){super(t=Ft({autoSize:!0},t)),this._capMap=Te._capMap,this.container=new e.G,this._setScale=xe._setScale.bind(this),this._setTranslate=xe._setTranslate.bind(this),this._initSize=xe._initSize.bind(this),this._updateSize=xe._updateSize.bind(this),this._getPath=Te._getPath.bind(this),this._normalizeMarkerOptions=Te._normalizeMarkerOptions.bind(this),this._removeMarker=Te._removeMarker.bind(this),this._createMarkers=Te._createMarkers.bind(this),this._createMarker=Te._createMarker.bind(this),this._positionMarker=Te._positionMarker.bind(this),this._redrawMarker=Te._redrawMarker.bind(this),this._redrawMarkers=Te._redrawMarkers.bind(this),this._createElements(),this._initSize()}drawingContainer(){return this.container}data(t){const e=this.options;if(!t)return e.data;e.data!==t&&(e.data=t,this._setData(t),this._initSize(),this._redrawMarkers(!0,{}))}redraw(t){if(t){super.redraw(t);const e=this.options,i=t.data;K(i)&&e.data!==i?(e.data=i,this._setData(i),this._updateSize(t)||this._initSize(),this._redrawMarkers(!0,t)):(this._updateSize(t),this._redrawMarkers(!1,t))}}_createElements(){const t=this.options;this.drawingElement=e.b.parse(t.data||"",{stroke:t.stroke}),this._fill(),this.container.append(this.drawingElement),this._createMarkers()}_setData(t){const i=this.drawingElement,s=e.b.parse(t||""),n=s.paths.slice(0);s.paths.elements([]),i.paths.elements(n)}}class Le extends fe{constructor(t){super(t=Ft({points:[]},t)),this._capMap=Te._capMap,this.container=new e.G,this._getPath=Te._getPath.bind(this),this._normalizeMarkerOptions=Te._normalizeMarkerOptions.bind(this),this._removeMarker=Te._removeMarker.bind(this),this._createMarkers=Te._createMarkers.bind(this),this._createMarker=Te._createMarker.bind(this),this._positionMarker=Te._positionMarker.bind(this),this._redrawMarker=Te._redrawMarker.bind(this),this._redrawMarkers=Te._redrawMarkers.bind(this),this._initPath(),this._createMarkers()}drawingContainer(){return this.container}points(t){const e=this.options;if(!t)return e.points;e.points=t,this._updatePath()}redraw(t){if(t){const e=t.points;super.redraw.call(this,t),e&&this._pointsDiffer(e)?(this.points(e),this._redrawMarkers(!0,t)):this._redrawMarkers(!1,t)}}_initPath(){const t=this.options;this.drawingElement=new e.b({stroke:t.stroke}),this._fill(),this.container.append(this.drawingElement),t.points&&this._updatePath()}_pointsDiffer(t){const e=this.options.points;let i=e.length!==t.length;if(!i)for(let s=0;s<t.length;s++)if(e[s].x!==t[s].x||e[s].y!==t[s].y){i=!0;break}return i}_updatePath(){const t=this.drawingElement,e=this.options.points,i=[];let s;for(let t=0;t<e.length;t++)s=e[t],i.push(ue(s.x,s.y));t.segments.elements(i)}}class Pe extends fe{constructor(t){super(t),this._initPath(),this._setPosition()}_setPosition(){const t=this.options,e=t.x,i=t.y;(K(e)||K(i))&&this.position(e||0,i||0)}redraw(t){t&&(super.redraw(t),this._diffNumericOptions(t,[s,n])&&this._drawPath(),this._diffNumericOptions(t,[o,r])&&this._setPosition())}_initPath(){const t=this.options;this.drawingElement=new e.b({stroke:t.stroke,closed:!0}),this._fill(),this._drawPath()}_drawPath(){const t=this.drawingElement,e=le(this.options),i=e.width,s=e.height;t.segments.elements([ue(0,0),ue(i,0),ue(i,s),ue(0,s)])}}const Ie=t=>(t&&t.color&&(t=Ft({},t,{fill:{color:t.color}})),t),ze={fontSize:15,fontFamily:"sans-serif",stroke:{width:0},fill:{color:"black"},autoSize:!0};class De extends fe{constructor(t){t=Ft({},ze,t),super(t=Ie(t)),this._setScale=xe._setScale.bind(this),this._setTranslate=xe._setTranslate.bind(this),this._initSize=xe._initSize.bind(this),this._updateSize=xe._updateSize.bind(this),this._font(),this._initText(),this._initSize()}_initText(){const t=this.options;this.drawingElement=new e.T(K(t.text)?t.text:"",new e.P,{font:t.font}),this._fill(),this._stroke()}_font(){const t=this.options;if(t.fontFamily&&K(t.fontSize)){const e=[];t.fontStyle&&e.push(t.fontStyle),t.fontWeight&&e.push(t.fontWeight),e.push(t.fontSize+(Z(t.fontSize)?"px":"")),e.push(t.fontFamily),t.font=e.join(" ")}else delete t.font}content(t){return this.drawingElement.content(t)}redraw(t){if(t){let e=!1;const i=this.options;t=Ie(t),super.redraw(t),(t.fontFamily||K(t.fontSize)||t.fontStyle||t.fontWeight)&&(Ft(i,{fontFamily:t.fontFamily,fontSize:t.fontSize,fontStyle:t.fontStyle,fontWeight:t.fontWeight}),this._font(),this.drawingElement.options.set("font",i.font),e=!0),t.text&&(this.content(t.text),e=!0),!this._updateSize(t)&&e&&this._initSize()}}}class Ne extends Wt{constructor(t){if(super(),j(t))throw new Error("Diagram is not specified.");this.diagram=t}layout(t){this.transferOptions(t);const e=new Xt(this.diagram).convert(t);if(e.isEmpty())return;const i=e.getConnectedComponents();if($(i))return;for(let e=0;e<i.length;e++){const s=i[e];this.layoutGraph(s,t)}const s=this.gridLayoutComponents(i);return new qt(this.diagram,s)}_initRuntimeProperties(){for(let t=0;t<this.graph.nodes.length;t++){const e=this.graph.nodes[t];e.layer=-1,e.downstreamLinkCount=0,e.upstreamLinkCount=0,e.isVirtual=!1,e.uBaryCenter=0,e.dBaryCenter=0,e.upstreamPriority=0,e.downstreamPriority=0,e.gridPosition=0}}_prepare(t){const e=[];let i,s,n;const o=new zt;let r,h,a,l=0;for(rt(t.nodes,(function(t){0===t.incoming.length&&(o.set(t,0),e.push(t))}));e.length>0;)for(h=e.shift(),i=0;i<h.outgoing.length;i++)n=h.outgoing[i],a=n.target,r=o.containsKey(a)?Math.max(o.get(h)+1,o.get(a)):o.get(h)+1,o.set(a,r),r>l&&(l=r),lt(e,a)||e.push(a);const c=o.keys();c.sort((function(t,e){const i=o.get(t),s=o.get(e);return nt(s-i)}));for(let t=0;t<c.length;++t){const e=c[t];let i=Number.MAX_VALUE;if(0!==e.outgoing.length){for(s=0;s<e.outgoing.length;++s)n=e.outgoing[s],i=Math.min(i,o.get(n.target));i>1&&o.set(e,i-1)}}let d;for(this.layers=[],i=0;i<l+1;i++)d=[],d.linksTo={},this.layers.push(d);for(o.forEach((function(t,e){t.layer=e,this.layers[e].push(t)}),this),s=0;s<this.layers.length;s++)for(d=this.layers[s],i=0;i<d.length;i++)d[i].gridPosition=i}layoutGraph(t,e){if(j(t))throw new Error("No graph given or graph analysis of the diagram failed.");q(e)&&this.transferOptions(e),this.graph=t,t.setItemIndices();const i=t.makeAcyclic();this._initRuntimeProperties(),this._prepare(t),this._dummify(),this._optimizeCrossings(),this._swapPairs(),this.arrangeNodes(),this._moveThingsAround(),this._dedummify(),rt(i,(function(t){t.points&&t.points.reverse()}))}setMinDist(t,e,i){const s=t.layer,n=t.layerIndex;if(!Number.isInteger(s)||!Number.isInteger(n)||s<0||n<0)throw new Error("Invalid layer or index value.");this.minDistances[s][n]=i}getMinDist(t,e){let i=0;const s=t.layerIndex,n=e.layerIndex,o=t.layer,r=Math.min(s,n),h=Math.max(s,n);for(let t=r;t<h;++t)i+=this.minDistances[o][t];return i}placeLeftToRight(t){const e=new zt;let i,s;for(let n=0;n<this.layers.length;++n){const o=t[n];if(!o)continue;for(i=0;i<o.length;i++)s=o[i],e.containsKey(s)||this.placeLeft(s,e,n);let r=Number.POSITIVE_INFINITY;for(i=0;i<o.length;i++){s=o[i];const t=this.rightSibling(s);t&&this.nodeLeftClass.get(t)!==n&&(r=Math.min(r,e.get(t)-e.get(s)-this.getMinDist(s,t)))}if(r===Number.POSITIVE_INFINITY){const t=[];for(i=0;i<o.length;i++){s=o[i];const r=[];vt(r,this.upNodes.get(s)),vt(r,this.downNodes.get(s));for(let i=0;i<r.length;i++){const o=r[i];this.nodeLeftClass.get(o)<n&&t.push(e.get(o)-e.get(s))}}t.sort(),r=0===t.length?0:t.length%2==1?t[this.intDiv(t.length,2)]:(t[this.intDiv(t.length,2)-1]+t[this.intDiv(t.length,2)])/2}for(i=0;i<o.length;i++)s=o[i],e.set(s,e.get(s)+r)}return e}placeRightToLeft(t){const e=new zt;let i,s;for(let n=0;n<this.layers.length;++n){const o=t[n];if(!o)continue;for(i=0;i<o.length;i++)s=o[i],e.containsKey(s)||this.placeRight(s,e,n);let r=Number.NEGATIVE_INFINITY;for(i=0;i<o.length;i++){s=o[i];const t=this.leftSibling(s);t&&this.nodeRightClass.get(t)!==n&&(r=Math.max(r,e.get(t)-e.get(s)+this.getMinDist(t,s)))}if(r===Number.NEGATIVE_INFINITY){const t=[];for(i=0;i<o.length;i++){s=o[i];const r=[];vt(r,this.upNodes.get(s)),vt(r,this.downNodes.get(s));for(let i=0;i<r.length;i++){const o=r[i];this.nodeRightClass.get(o)<n&&t.push(e.get(s)-e.get(o))}}t.sort(),r=0===t.length?0:t.length%2==1?t[this.intDiv(t.length,2)]:(t[this.intDiv(t.length,2)-1]+t[this.intDiv(t.length,2)])/2}for(i=0;i<o.length;i++)s=o[i],e.set(s,e.get(s)+r)}return e}_getLeftWing(){const t={value:null},e=this.computeClasses(t,1);return this.nodeLeftClass=t.value,e}_getRightWing(){const t={value:null},e=this.computeClasses(t,-1);return this.nodeRightClass=t.value,e}computeClasses(t,e){let i=0;const s=t.value=new zt;for(let t=0;t<this.layers.length;++t){i=t;const n=this.layers[t];for(let t=1===e?0:n.length-1;t>=0&&t<n.length;t+=e){const e=n[t];if(s.containsKey(e))i=s.get(e);else if(s.set(e,i),e.isVirtual){const t=this._nodesInLink(e);for(let e=0;e<t.length;e++){const n=t[e];s.set(n,i)}}}}const n=[];for(let t=0;t<this.layers.length;t++)n.push(null);return s.forEach((function(t,e){null===n[e]&&(n[e]=[]),n[e].push(t)})),n}_isVerticalLayout(){return"up"===this.options.subtype.toLowerCase()||"down"===this.options.subtype.toLowerCase()||"vertical"===this.options.subtype.toLowerCase()}_isHorizontalLayout(){return"right"===this.options.subtype.toLowerCase()||"left"===this.options.subtype.toLowerCase()||"horizontal"===this.options.subtype.toLowerCase()}_isIncreasingLayout(){return"right"===this.options.subtype.toLowerCase()||"down"===this.options.subtype.toLowerCase()}_moveThingsAround(){let t,e,i,s,n,o;for(e=0;e<this.layers.length;++e)s=this.layers[e],s.sort(this._gridPositionComparer.bind(this));for(this.minDistances=[],e=0;e<this.layers.length;++e)for(s=this.layers[e],this.minDistances[e]=[],n=0;n<s.length;++n)i=s[n],i.layerIndex=n,this.minDistances[e][n]=this.options.nodeDistance,n<s.length-1&&(this._isVerticalLayout()?this.minDistances[e][n]+=(i.width+s[n+1].width)/2:this.minDistances[e][n]+=(i.height+s[n+1].height)/2);for(this.downNodes=new zt,this.upNodes=new zt,rt(this.graph.nodes,(function(t){this.downNodes.set(t,[]),this.upNodes.set(t,[])}),this),rt(this.graph.links,(function(t){const e=t.source,i=t.target;let s=null,n=null;e.layer>i.layer?(s=t.source,n=t.target):(n=t.source,s=t.target),this.downNodes.get(n).push(s),this.upNodes.get(s).push(n)}),this),this.downNodes.forEachValue((function(t){t.sort(this._gridPositionComparer)}),this),this.upNodes.forEachValue((function(t){t.sort(this._gridPositionComparer)}),this),e=0;e<this.layers.length-1;++e)for(s=this.layers[e],o=0;o<s.length-1;o++){const t=s[o];if(!t.isVirtual)continue;const r=this.downNodes.get(t)[0];if(r.isVirtual)for(n=o+1;n<s.length;++n){if(i=s[n],!i.isVirtual)continue;const t=this.downNodes.get(i)[0];if(t.isVirtual&&r.gridPosition>t.gridPosition){const i=r.gridPosition;r.gridPosition=t.gridPosition,t.gridPosition=i;const s=r.layerIndex,n=t.layerIndex;this.layers[e+1][s]=t,this.layers[e+1][n]=r,r.layerIndex=n,t.layerIndex=s}}}const r=this._getLeftWing(),h=this._getRightWing(),a=this.placeLeftToRight(r),l=this.placeRightToLeft(h),c=new zt;rt(this.graph.nodes,(function(t){c.set(t,(a.get(t)+l.get(t))/2)}));const d=new zt,u=new zt;for(e=0;e<this.layers.length;++e){s=this.layers[e];let t=-1;for(n=0;n<s.length;++n)i=s[n],d.set(i,0),u.set(i,!1),i.isVirtual&&(-1===t||t===n-1||(d.set(s[t],0),c.get(i)-c.get(s[t])===this.getMinDist(s[t],i)?u.set(s[t],!0):u.set(s[t],!1)),t=n)}rt([1,-1],(function(e){for(let i=1===e?0:this.layers.length-1;i>=0&&i<this.layers.length;i+=e){const s=this.layers[i];let n=this._firstVirtualNode(s),o=null,r=null;if(-1!==n)for(o=s[n],r=[],t=0;t<n;t++)r.push(s[t]);else o=null,r=s;if(r.length>0){for(this._sequencer(c,null,o,e,r),t=0;t<r.length-1;++t)this.setMinDist(r[t],r[t+1],c.get(r[t+1])-c.get(r[t]));o&&this.setMinDist(r[r.length-1],o,c.get(o)-c.get(r[r.length-1]))}for(;o;){const i=this.nextVirtualNode(s,o);if(i){if(d.get(o)===e){n=o.layerIndex;const h=i.layerIndex;for(r=[],t=n+1;t<h;t++)r.push(s[t]);r.length>0&&this._sequencer(c,o,i,e,r),u.set(o,!0)}}else{for(n=o.layerIndex,r=[],t=n+1;t<s.length;t++)r.push(s[t]);if(r.length>0){for(this._sequencer(c,o,null,e,r),t=0;t<r.length-1;++t)this.setMinDist(r[t],r[t+1],c.get(r[t+1])-c.get(r[t]));this.setMinDist(o,r[0],c.get(r[0])-c.get(o))}}o=i}this.adjustDirections(i,e,d,u)}}),this);const p=this._isIncreasingLayout()?0:this.layers.length-1,g=this._isIncreasingLayout()?1:-1;let f=0;function m(t,e){let i=Number.MIN_VALUE;for(let s=0;s<t.length;++s){const n=t[s];i=e._isVerticalLayout()?Math.max(i,n.height):Math.max(i,n.width)}return i}for(t=p;_=t,(y=this)._isIncreasingLayout()?_<y.layers.length:_>=0;t+=g){s=this.layers[t];const e=m(s,this);for(n=0;n<s.length;++n)i=s[n],this._isVerticalLayout()?(i.x=c.get(i),i.y=f+e/2):(i.x=f+e/2,i.y=c.get(i));f+=this.options.layerSeparation+e}var _,y}adjustDirections(t,e,i,s){if(t+e<0||t+e>=this.layers.length)return;let n=null,o=null;const r=this.layers[t+e];for(let h=0;h<r.length;++h){const a=r[h];if(a.isVirtual){const h=this.getNeighborOnLayer(a,t);if(h.isVirtual){if(n){let l=s.get(o);const c=this.layers[t],d=o.layerIndex,u=h.layerIndex;for(let t=d+1;t<u;++t)c[t].isVirtual&&(l=l&&s.get(c[t]));if(l){i.set(n,e);const t=n.layerIndex,s=a.layerIndex;for(let n=t+1;n<s;++n)r[n].isVirtual&&i.set(r[n],e)}}n=a,o=h}}}}getNeighborOnLayer(t,e){let i=this.upNodes.get(t)[0];return i.layer===e?i:(i=this.downNodes.get(t)[0],i.layer===e?i:null)}_sequencer(t,e,i,s,n){if(1===n.length&&this._sequenceSingle(t,e,i,s,n[0]),n.length>1){const o=n.length,r=this.intDiv(o,2);this._sequencer(t,e,i,s,n.slice(0,r)),this._sequencer(t,e,i,s,n.slice(r)),this.combineSequences(t,e,i,s,n)}}_sequenceSingle(t,e,i,s,n){const o=-1===s?this.downNodes.get(n):this.upNodes.get(n),r=o.length;0!==r&&(r%2==1?t.set(n,t.get(o[this.intDiv(r,2)])):t.set(n,(t.get(o[this.intDiv(r,2)-1])+t.get(o[this.intDiv(r,2)]))/2),e&&t.set(n,Math.max(t.get(n),t.get(e)+this.getMinDist(e,n))),i&&t.set(n,Math.min(t.get(n),t.get(i)-this.getMinDist(n,i))))}combineSequences(t,e,i,s,n){const o=n.length,r=this.intDiv(o,2),h=[];let a,l,c,d,u,p;for(a=0;a<r;++a){for(l=0,d=-1===s?this.downNodes.get(n[a]):this.upNodes.get(n[a]),c=0;c<d.length;++c)u=d[c],t.get(u)>=t.get(n[a])?l++:(l--,h.push({k:t.get(u)+this.getMinDist(n[a],n[r-1]),v:2}));h.push({k:t.get(n[a])+this.getMinDist(n[a],n[r-1]),v:l})}e&&h.push({k:t.get(e)+this.getMinDist(e,n[r-1]),v:Number.MAX_VALUE}),h.sort(this._positionDescendingComparer.bind(this));const g=[];for(a=r;a<o;++a){for(l=0,d=-1===s?this.downNodes.get(n[a]):this.upNodes.get(n[a]),c=0;c<d.length;++c)u=d[c],t.get(u)<=t.get(n[a])?l++:(l--,g.push({k:t.get(u)-this.getMinDist(n[a],n[r]),v:2}));g.push({k:t.get(n[a])-this.getMinDist(n[a],n[r]),v:l})}i&&g.push({k:t.get(i)-this.getMinDist(i,n[r]),v:Number.MAX_VALUE}),g.sort(this._positionAscendingComparer.bind(this));let f=0,m=0;const _=this.getMinDist(n[r-1],n[r]);for(;t.get(n[r])-t.get(n[r-1])<_;)if(f<m){if(0===h.length){t.set(n[r-1],t.get(n[r])-_);break}p=h.shift(),f+=p.v,t.set(n[r-1],p.k),t.set(n[r-1],Math.max(t.get(n[r-1]),t.get(n[r])-_))}else{if(0===g.length){t.set(n[r],t.get(n[r-1])+_);break}p=g.shift(),m+=p.v,t.set(n[r],p.k),t.set(n[r],Math.min(t.get(n[r]),t.get(n[r-1])+_))}for(a=r-2;a>=0;a--)t.set(n[a],Math.min(t.get(n[a]),t.get(n[r-1])-this.getMinDist(n[a],n[r-1])));for(a=r+1;a<o;a++)t.set(n[a],Math.max(t.get(n[a]),t.get(n[r])+this.getMinDist(n[a],n[r])))}placeLeft(t,e,i){let s=Number.NEGATIVE_INFINITY;rt(this._getComposite(t),(function(t){const n=this.leftSibling(t);n&&this.nodeLeftClass.get(n)===this.nodeLeftClass.get(t)&&(e.containsKey(n)||this.placeLeft(n,e,i),s=Math.max(s,e.get(n)+this.getMinDist(n,t)))}),this),s===Number.NEGATIVE_INFINITY&&(s=0),rt(this._getComposite(t),(function(t){e.set(t,s)}))}placeRight(t,e,i){let s=Number.POSITIVE_INFINITY;rt(this._getComposite(t),(function(t){const n=this.rightSibling(t);n&&this.nodeRightClass.get(n)===this.nodeRightClass.get(t)&&(e.containsKey(n)||this.placeRight(n,e,i),s=Math.min(s,e.get(n)-this.getMinDist(t,n)))}),this),s===Number.POSITIVE_INFINITY&&(s=0),rt(this._getComposite(t),(function(t){e.set(t,s)}))}leftSibling(t){const e=this.layers[t.layer],i=t.layerIndex;return 0===i?null:e[i-1]}rightSibling(t){const e=this.layers[t.layer],i=t.layerIndex;return i===e.length-1?null:e[i+1]}_getComposite(t){return t.isVirtual?this._nodesInLink(t):[t]}arrangeNodes(){let t,e,i,s,n;for(e=0;e<this.layers.length;e++)for(s=this.layers[e],i=0;i<s.length;i++)n=s[i],n.upstreamPriority=n.upstreamLinkCount,n.downstreamPriority=n.downstreamLinkCount;for(let e=0;e<2;e++){for(t=this.layers.length-1;t>=1;t--)this.layoutLayer(!1,t);for(t=0;t<this.layers.length-1;t++)this.layoutLayer(!0,t)}let o=Number.MAX_VALUE;for(e=0;e<this.layers.length;e++)for(s=this.layers[e],i=0;i<s.length;i++)n=s[i],o=Math.min(o,n.gridPosition);if(o<0)for(e=0;e<this.layers.length;e++)for(s=this.layers[e],i=0;i<s.length;i++)n=s[i],n.gridPosition=n.gridPosition-o}layoutLayer(t,e){let i,s;s=t?this.layers[i=e+1]:this.layers[i=e-1];const n=[];for(let t=0;t<s.length;t++)n.push(s[t]);n.sort((function(t,e){const i=(t.upstreamPriority+t.downstreamPriority)/2,s=(e.upstreamPriority+e.downstreamPriority)/2;return Math.abs(i-s)<1e-4?0:i<s?1:-1})),rt(n,(function(t){let e=t.gridPosition;const i=this.calcBaryCenter(t),n=(t.upstreamPriority+t.downstreamPriority)/2;if(!(Math.abs(e-i)<1e-4||Math.abs(e-i)<.2501))if(e<i)for(;e<i&&this.moveRight(t,s,n);)e=t.gridPosition;else for(;e>i&&this.moveLeft(t,s,n);)e=t.gridPosition}),this),i>0&&this.calcDownData(i-1),i<this.layers.length-1&&this.calcUpData(i+1)}moveRight(t,e,i){const s=ct(e,t);if(s===e.length-1)return t.gridPosition=t.gridPosition+.5,!0;const n=e[s+1],o=(n.upstreamPriority+n.downstreamPriority)/2;return n.gridPosition>t.gridPosition+1?(t.gridPosition=t.gridPosition+.5,!0):!(o>i||Math.abs(o-i)<1e-4)&&(!!this.moveRight(n,e,i)&&(t.gridPosition=t.gridPosition+.5,!0))}moveLeft(t,e,i){const s=ct(e,t);if(0===s)return t.gridPosition=t.gridPosition-.5,!0;const n=e[s-1],o=(n.upstreamPriority+n.downstreamPriority)/2;return n.gridPosition<t.gridPosition-1?(t.gridPosition=t.gridPosition-.5,!0):!(o>i||Math.abs(o-i)<1e-4)&&(!!this.moveLeft(n,e,i)&&(t.gridPosition=t.gridPosition-.5,!0))}mapVirtualNode(t,e){this.nodeToLinkMap.set(t,e),this.linkToNodeMap.containsKey(e)||this.linkToNodeMap.set(e,[]),this.linkToNodeMap.get(e).push(t)}_nodesInLink(t){return this.linkToNodeMap.get(this.nodeToLinkMap.get(t))}_dummify(){this.linkToNodeMap=new zt,this.nodeToLinkMap=new zt;const t=this.graph.links.slice(0),e=this.layers;let i,s,n,o,r,h,a,l;const c=function(t,i,s){e[t].linksTo[i]=e[t].linksTo[i]||[],e[t].linksTo[i].push(s)};for(l=0;l<t.length;l++){const d=t[l],u=d.source,p=d.target,g=u.layer,f=p.layer,m=u.gridPosition,_=p.gridPosition,y=(_-m)/Math.abs(f-g);let w=u;if(g-f>1){for(a=g-1;a>f;a--){for(n=new Node,n.x=u.x,n.y=u.y,n.width=u.width/100,n.height=u.height/100,i=e[a],s=(a-f)*y+m,s>i.length&&(s=i.length),m>=e[g].length-1&&_>=e[f].length-1?s=i.length:0===m&&0===_&&(s=0),n.layer=a,n.uBaryCenter=0,n.dBaryCenter=0,n.upstreamLinkCount=0,n.downstreamLinkCount=0,n.gridPosition=s,n.isVirtual=!0,mt(i,n,s),r=s+1;r<i.length;r++)o=i[r],o.gridPosition=o.gridPosition+1;h=new Yt(w,n),h.depthOfDumminess=0,c(a-1,a,h),w=n,this.graph._addNode(n),this.graph.addLink(h),n.index=this.graph.nodes.length-1,this.mapVirtualNode(n,d)}c(f-1,f,h),d.changeSource(w),d.depthOfDumminess=g-f-1}else if(g-f<-1){for(a=g+1;a<f;a++){for(n=new Node,n.x=u.x,n.y=u.y,n.width=u.width/100,n.height=u.height/100,i=e[a],s=(a-g)*y+m,s>i.length&&(s=i.length),m>=e[g].length-1&&_>=e[f].length-1?s=i.length:0===m&&0===_&&(s=0),n.layer=a,n.uBaryCenter=0,n.dBaryCenter=0,n.upstreamLinkCount=0,n.downstreamLinkCount=0,n.gridPosition=s,n.isVirtual=!0,s=Math.floor(s),mt(i,n,s),r=s+1;r<i.length;r++)o=i[r],o.gridPosition=o.gridPosition+1;h=new Yt(w,n),h.depthOfDumminess=0,c(a-1,a,h),w=n,this.graph._addNode(n),this.graph.addLink(h),n.index=this.graph.nodes.length-1,this.mapVirtualNode(n,d)}c(f-1,f,d),d.changeSource(w),d.depthOfDumminess=f-g-1}else c(g,f,d)}}_dedummify(){let t=!0;for(;t;){t=!1;for(let e=0;e<this.graph.links.length;e++){const i=this.graph.links[e];if(!i.depthOfDumminess)continue;const s=[];s.unshift({x:i.target.x,y:i.target.y}),s.unshift({x:i.source.x,y:i.source.y});let n=i;const o=i.depthOfDumminess;for(let t=0;t<o;t++){const t=n.source.incoming[0];s.unshift({x:t.source.x,y:t.source.y}),n=t}i.changeSource(n.source),i.depthOfDumminess=0,s.length>2?(s.splice(0,1),s.splice(s.length-1),i.points=s):i.points=[],t=!0;break}}}_optimizeCrossings(){let t,e=-1;let i=0;for(;0!==e&&!(i++>3);){for(e=0,t=this.layers.length-1;t>=1;t--)e+=this.optimizeLayerCrossings(!1,t);for(t=0;t<this.layers.length-1;t++)e+=this.optimizeLayerCrossings(!0,t)}}calcUpData(t){if(0===t)return;const e=this.layers[t];let i,s,n;const o=new Set,r=this.layers[t-1];for(i=0;i<r.length;i++)o.add(r[i]);for(i=0;i<e.length;i++){const t=e[i];let r=0,h=0;for(s=0;s<t.incoming.length;s++)n=t.incoming[s],o.has(n.source)&&(h++,r+=n.source.gridPosition);for(s=0;s<t.outgoing.length;s++)n=t.outgoing[s],o.has(n.target)&&(h++,r+=n.target.gridPosition);h>0?(t.uBaryCenter=r/h,t.upstreamLinkCount=h):(t.uBaryCenter=i,t.upstreamLinkCount=0)}}calcDownData(t){if(t===this.layers.length-1)return;const e=this.layers[t];let i,s,n;const o=new Set,r=this.layers[t+1];for(i=0;i<r.length;i++)o.add(r[i]);for(i=0;i<e.length;i++){const t=e[i];let r=0,h=0;for(s=0;s<t.incoming.length;s++)n=t.incoming[s],o.has(n.source)&&(h++,r+=n.source.gridPosition);for(s=0;s<t.outgoing.length;s++)n=t.outgoing[s],o.has(n.target)&&(h++,r+=n.target.gridPosition);h>0?(t.dBaryCenter=r/h,t.downstreamLinkCount=h):(t.dBaryCenter=i,t.downstreamLinkCount=0)}}optimizeLayerCrossings(t,e){let i,s;s=t?this.layers[i=e+1]:this.layers[i=e-1];const n=s.slice(0);t?this.calcUpData(i):this.calcDownData(i),s.sort(((t,e)=>{const i=this.calcBaryCenter(t),s=this.calcBaryCenter(e);if(Math.abs(i-s)<1e-4)return t.degree()===e.degree()?this.compareByIndex(t,e):t.degree()<e.degree()?1:-1;const n=1e3*(s-i);return n>0?-1:n<0?1:this.compareByIndex(t,e)}));let o,r=0;for(o=0;o<s.length;o++)s[o]!==n[o]&&r++;if(r>0){let t=0;for(o=0;o<s.length;o++){s[o].gridPosition=t++}}return r}_swapPairs(){const t=this.options.layeredIterations;let e=0;for(;!(e++>t);){const t=e%4<=1,i=e%4==1;for(let e=t?0:this.layers.length-1;t?e<=this.layers.length-1:e>=0;e+=t?1:-1){const s=this.layers[e];let n=!1,o=!0,r=0;for(let h=0;h<s.length-1;h++){let a=0,l=0,c=0;if(o?(0!==e&&(a=this.countLinksCrossingBetweenTwoLayers(e-1,e)),e!==this.layers.length-1&&(l=this.countLinksCrossingBetweenTwoLayers(e,e+1)),t?a*=2:l*=2,c=a+l):c=r,0===c)continue;let d=s[h],u=s[h+1],p=d.gridPosition,g=u.gridPosition;s[h]=u,s[h+1]=d,d.gridPosition=g,u.gridPosition=p,a=0,0!==e&&(a=this.countLinksCrossingBetweenTwoLayers(e-1,e)),l=0,e!==this.layers.length-1&&(l=this.countLinksCrossingBetweenTwoLayers(e,e+1)),t?a*=2:l*=2;const f=a+l;let m=!1;m=i?f>=c:f>c,m?(d=s[h],u=s[h+1],p=d.gridPosition,g=u.gridPosition,s[h]=u,s[h+1]=d,d.gridPosition=g,u.gridPosition=p,r=c,o=!1):(n=!0,o=!0)}n&&(e!==this.layers.length-1&&this.calcUpData(e+1),0!==e&&this.calcDownData(e-1))}}}countLinksCrossingBetweenTwoLayers(t,e){const i=this.layers[t].linksTo[e];let s,n,o,r,h,a,l,c,d=0;const u=i.length;for(l=0;l<u;l++)for(s=i[l],c=l+1;c<u;c++){n=i[c],s.target.layer===e?(o=s.source,r=s.target):(o=s.target,r=s.source),n.target.layer===e?(h=n.source,a=n.target):(h=n.target,a=n.source);const t=o.gridPosition,l=r.gridPosition;(t-h.gridPosition)*(l-a.gridPosition)<0&&d++}return d}calcBaryCenter(t){const e=t.upstreamLinkCount,i=t.downstreamLinkCount,s=t.uBaryCenter,n=t.dBaryCenter;return e>0&&i>0?(s+n)/2:e>0?s:i>0?n:0}_gridPositionComparer(t,e){return t.gridPosition<e.gridPosition?-1:t.gridPosition>e.gridPosition?1:0}_positionAscendingComparer(t,e){return t.k<e.k?-1:t.k>e.k?1:0}_positionDescendingComparer(t,e){return t.k<e.k?1:t.k>e.k?-1:0}_firstVirtualNode(t){for(let e=0;e<t.length;e++)if(t[e].isVirtual)return e;return-1}compareByIndex(t,e){const i=t.index,s=e.index;return i<s?1:i>s?-1:0}intDiv(t,e){return(t-t%e)/e}nextVirtualNode(t,e){for(let i=e.layerIndex+1;i<t.length;++i)if(t[i].isVirtual)return t[i];return null}}class Oe{constructor(t){this.center=null,this.options=t}layout(t,e){if(this.graph=t,this.graph.nodes&&0!==this.graph.nodes.length){if(!lt(this.graph.nodes,e))throw new Error("The given root is not in the graph.");this.center=e,this.graph.cacheRelationships(),this.layoutSwitch()}}layoutLeft(t){this.setChildrenDirection(this.center,"Left",!1),this.setChildrenLayout(this.center,"Default",!1);let e,i,s,n=0,o=0;for(i=0;i<t.length;i++){s=t[i],s.TreeDirection="Left";const e=this.measure(s,ie.Empty.bind(this));o=Math.max(o,e.width),n+=e.height+this.options.verticalSeparation}n-=this.options.verticalSeparation;const r=this.center.x-this.options.horizontalSeparation;for(e=this.center.y+(this.center.height-n)/2,i=0;i<t.length;i++){s=t[i];const n=new Ot(r-s.Size.width,e);this.arrange(s,n),e+=s.Size.height+this.options.verticalSeparation}}layoutRight(t){this.setChildrenDirection(this.center,"Right",!1),this.setChildrenLayout(this.center,"Default",!1);let e,i,s,n=0,o=0;for(i=0;i<t.length;i++){s=t[i],s.TreeDirection="Right";const e=this.measure(s,ie.Empty.bind(this));o=Math.max(o,e.width),n+=e.height+this.options.verticalSeparation}n-=this.options.verticalSeparation;const r=this.center.x+this.options.horizontalSeparation+this.center.width;for(e=this.center.y+(this.center.height-n)/2,i=0;i<t.length;i++){s=t[i];const n=new Ot(r,e);this.arrange(s,n),e+=s.Size.height+this.options.verticalSeparation}}layoutUp(t){this.setChildrenDirection(this.center,"Up",!1),this.setChildrenLayout(this.center,"Default",!1);let e,i,s,n=0;for(s=0;s<t.length;s++){i=t[s],i.TreeDirection="Up";n+=this.measure(i,ie.Empty.bind(this)).width+this.options.horizontalSeparation}n-=this.options.horizontalSeparation;let o=this.center.x+this.center.width/2-n/2;for(s=0;s<t.length;s++){i=t[s],e=this.center.y-this.options.verticalSeparation-i.Size.height;const n=new Ot(o,e);this.arrange(i,n),o+=i.Size.width+this.options.horizontalSeparation}}layoutDown(t){let e,i;this.setChildrenDirection(this.center,"Down",!1),this.setChildrenLayout(this.center,"Default",!1);let s=0;for(i=0;i<t.length;i++){e=t[i],e.treeDirection="Down";s+=this.measure(e,ie.Empty.bind(this)).width+this.options.horizontalSeparation}s-=this.options.horizontalSeparation;let n=this.center.x+this.center.width/2-s/2;const o=this.center.y+this.options.verticalSeparation+this.center.height;for(i=0;i<t.length;i++){e=t[i];const s=new Ot(n,o);this.arrange(e,s),n+=e.Size.width+this.options.horizontalSeparation}}layoutRadialTree(){this.setChildrenDirection(this.center,"Radial",!1),this.setChildrenLayout(this.center,"Default",!1),this.previousRoot=null;const t=this.options.startRadialAngle*d,e=this.options.endRadialAngle*d;if(e<=t)throw new Error("Final angle should not be less than the start angle.");this.maxDepth=0,this.origin=new Ot(this.center.x,this.center.y),this.calculateAngularWidth(this.center,0),this.maxDepth>0&&this.radialLayout(this.center,this.options.radialFirstLevelSeparation,t,e),this.center.Angle=e-t}tipOverTree(t,e){j(e)&&(e=0),this.setChildrenDirection(this.center,"Down",!1),this.setChildrenLayout(this.center,"Default",!1),this.setChildrenLayout(this.center,"Underneath",!1,e);let i,s,n=0;for(s=0;s<t.length;s++){i=t[s],i.TreeDirection="Down";n+=this.measure(i,ie.Empty.bind(this)).width+this.options.horizontalSeparation}n-=this.options.horizontalSeparation,n-=t[t.length-1].width,n+=t[t.length-1].associatedShape.bounds().width;let o=this.center.x+this.center.width/2-n/2;const r=this.center.y+this.options.verticalSeparation+this.center.height;for(s=0;s<t.length;s++){i=t[s];const e=new Ot(o,r);this.arrange(i,e),o+=i.Size.width+this.options.horizontalSeparation}}calculateAngularWidth(t,e){e>this.maxDepth&&(this.maxDepth=e);const i=0===e?0:Math.sqrt(2e6)/e;let s=0;if(t.children.length>0){for(let i=0,n=t.children.length;i<n;i++){const n=t.children[i];s+=this.calculateAngularWidth(n,e+1)}s=Math.max(i,s)}else s=i;return t.sectorAngle=s,s}sortChildren(t){let e,i=0;if(t.parents.length>1)throw new Error("Node is not part of a tree.");const s=t.parents[0];if(s){const e=new Ot(s.x,s.y),n=new Ot(t.x,t.y);i=this.normalizeAngle(Math.atan2(e.y-n.y,e.x-n.x))}const n=t.children.length;if(0===n)return null;const o=[],r=[];for(e=0;e<n;++e){const s=t.children[e],n=new Ot(s.x,s.y);r[e]=e,o[e]=this.normalizeAngle(-i+Math.atan2(n.y-n.y,n.x-n.x))}wt(o,r);const h=[],a=t.children;for(e=0;e<n;++e)h.push(a[r[e]]);return h}normalizeAngle(t){for(;t>2*Math.PI;)t-=2*Math.PI;for(;t<0;)t+=2*Math.PI;return t}radialLayout(t,e,i,s){const n=s-i,o=n/2,r=t.sectorAngle;let h=0;const a=this.sortChildren(t);for(let t=0,s=a.length;t<s;t++){const s=a[t],l=s,c=l.sectorAngle/r;s.children.length>0&&this.radialLayout(s,e+this.options.radialSeparation,i+h*n,i+(h+c)*n),this.setPolarLocation(s,e,i+h*n+c*o),l.angle=c*n,h+=c}}setPolarLocation(t,e,i){t.x=this.origin.x+e*Math.cos(i),t.y=this.origin.y+e*Math.sin(i),t.BoundingRectangle=new Bt(t.x,t.y,t.width,t.height)}setChildrenDirection(t,e,i){const s=t.treeDirection;this.graph.depthFirstTraversal(t,(t=>{t.treeDirection=e})),i||(t.treeDirection=s)}setChildrenLayout(t,e,i,s){j(s)&&(s=0);const n=t.childrenLayout;s>0?(this.graph.assignLevels(t),this.graph.depthFirstTraversal(t,(t=>{t.level>=s+1&&(t.childrenLayout=e)}))):(this.graph.depthFirstTraversal(t,(t=>{t.childrenLayout=e})),i||(t.childrenLayout=n))}measure(t,e){let i,s=0,n=0,o=new ie(0,0);if(!t)throw new Error("Node is not defined.");const r=t.associatedShape.bounds(),h=r.width,a=r.height;if(1!==t.parents.length)throw new Error("Node not in a spanning tree.");const l=t.parents[0];if("Undefined"===t.treeDirection&&(t.treeDirection=l.treeDirection),$(t.children))o=new ie(Math.abs(h)<u?50:h,Math.abs(a)<u?25:a);else if(1===t.children.length){switch(t.treeDirection){case"Radial":i=this.measure(t.children[0],e),s=h+this.options.radialSeparation*Math.cos(t.AngleToParent)+i.width,n=a+Math.abs(this.options.radialSeparation*Math.sin(t.AngleToParent))+i.height;break;case"Left":case"Right":switch(t.childrenLayout){case"TopAlignedWithParent":case"BottomAlignedWithParent":break;case"Underneath":i=this.measure(t.children[0],e),s=h+i.width+this.options.underneathHorizontalOffset,n=a+this.options.underneathVerticalTopOffset+i.height;break;case"Default":i=this.measure(t.children[0],e),s=h+this.options.horizontalSeparation+i.width,n=Math.max(a,i.height);break;default:throw new Error("Unhandled TreeDirection in the Radial layout measuring.")}break;case"Up":case"Down":switch(t.childrenLayout){case"TopAlignedWithParent":case"BottomAlignedWithParent":break;case"Underneath":i=this.measure(t.children[0],e),s=Math.max(h,i.width+this.options.underneathHorizontalOffset),n=a+this.options.underneathVerticalTopOffset+i.height;break;case"Default":i=this.measure(t.children[0],e),n=a+this.options.verticalSeparation+i.height,s=Math.max(h,i.width);break;default:throw new Error("Unhandled TreeDirection in the Down layout measuring.")}break;default:throw new Error("Unhandled TreeDirection in the layout measuring.")}o=new ie(s,n)}else{let r,l;switch(t.treeDirection){case"Left":case"Right":switch(t.childrenLayout){case"TopAlignedWithParent":case"BottomAlignedWithParent":break;case"Underneath":for(s=h,n=a+this.options.underneathVerticalTopOffset,r=0;r<t.children.length;r++)l=t.children[r],i=this.measure(l,e),s=Math.max(s,i.width+this.options.underneathHorizontalOffset),n+=i.height+this.options.underneathVerticalSeparation;n-=this.options.underneathVerticalSeparation;break;case"Default":for(s=h,n=0,r=0;r<t.children.length;r++)l=t.children[r],i=this.measure(l,e),s=Math.max(s,h+this.options.horizontalSeparation+i.width),n+=i.height+this.options.verticalSeparation;n-=this.options.verticalSeparation;break;default:throw new Error("Unhandled TreeDirection in the Right layout measuring.")}break;case"Up":case"Down":switch(t.childrenLayout){case"TopAlignedWithParent":case"BottomAlignedWithParent":break;case"Underneath":for(s=h,n=a+this.options.underneathVerticalTopOffset,r=0;r<t.children.length;r++)l=t.children[r],i=this.measure(l,e),s=Math.max(s,i.width+this.options.underneathHorizontalOffset),n+=i.height+this.options.underneathVerticalSeparation;n-=this.options.underneathVerticalSeparation;break;case"Default":for(s=0,n=0,r=0;r<t.children.length;r++)l=t.children[r],i=this.measure(l,e),s+=i.width+this.options.horizontalSeparation,n=Math.max(n,i.height+this.options.verticalSeparation+a);s-=this.options.horizontalSeparation;break;default:throw new Error("Unhandled TreeDirection in the Down layout measuring.")}break;default:throw new Error("Unhandled TreeDirection in the layout measuring.")}o=new ie(s,n)}return t.SectorAngle=Math.sqrt(s*s/4+n*n/4),t.Size=o,o}arrange(t,e){const i=t.associatedShape.bounds();let s,n,o,r,h;const a=i.width,l=i.height;if($(t.children))t.x=e.x,t.y=e.y,t.BoundingRectangle=new Bt(e.x,e.y,a,l);else{let i,c,d;switch(t.treeDirection){case"Left":switch(t.childrenLayout){case"TopAlignedWithParent":case"BottomAlignedWithParent":break;case"Underneath":for(d=e,t.x=d.x,t.y=d.y,t.BoundingRectangle=new Bt(t.x,t.y,t.width,t.height),c=e.y+l+this.options.underneathVerticalTopOffset,s=0;s<r.children.length;s++)r=r.children[s],i=d.x-r.associatedShape.width-this.options.underneathHorizontalOffset,n=new Ot(i,c),this.arrange(r,n),c+=r.Size.height+this.options.underneathVerticalSeparation;break;case"Default":for(d=new Ot(e.x+t.Size.width-a,e.y+(t.Size.height-l)/2),t.x=d.x,t.y=d.y,t.BoundingRectangle=new Bt(t.x,t.y,t.width,t.height),i=d.x-this.options.horizontalSeparation,c=e.y,s=0;s<t.children.length;s++)r=t.children[s],n=new Ot(i-r.Size.width,c),this.arrange(r,n),c+=r.Size.height+this.options.verticalSeparation;break;default:throw new Error("Unsupported TreeDirection")}break;case"Right":switch(t.childrenLayout){case"TopAlignedWithParent":case"BottomAlignedWithParent":break;case"Underneath":for(d=e,t.x=d.x,t.y=d.y,t.BoundingRectangle=new Bt(t.x,t.y,t.width,t.height),i=e.x+a+this.options.underneathHorizontalOffset,c=e.y+l+this.options.underneathVerticalTopOffset,s=0;s<t.children.length;s++)r=t.children[s],n=new Ot(i,c),this.arrange(r,n),c+=r.Size.height+this.options.underneathVerticalSeparation;break;case"Default":for(d=new Ot(e.x,e.y+(t.Size.height-l)/2),t.x=d.x,t.y=d.y,t.BoundingRectangle=new Bt(t.x,t.y,t.width,t.height),i=e.x+a+this.options.horizontalSeparation,c=e.y,s=0;s<t.children.length;s++)r=t.children[s],n=new Ot(i,c),this.arrange(r,n),c+=r.Size.height+this.options.verticalSeparation;break;default:throw new Error("Unsupported TreeDirection")}break;case"Up":if(d=new Ot(e.x+(t.Size.width-a)/2,e.y+t.Size.height-l),t.x=d.x,t.y=d.y,t.BoundingRectangle=new Bt(t.x,t.y,t.width,t.height),Math.abs(d.x-e.x)<u){for(h=0,s=0;s<t.children.length;s++)o=t.children[s],h+=o.Size.width+this.options.horizontalSeparation;h-=this.options.horizontalSeparation,i=e.x+(a-h)/2}else i=e.x;for(s=0;s<t.children.length;s++)r=t.children[s],c=d.y-this.options.verticalSeparation-r.Size.height,n=new Ot(i,c),this.arrange(r,n),i+=r.Size.width+this.options.horizontalSeparation;break;case"Down":switch(t.childrenLayout){case"TopAlignedWithParent":case"BottomAlignedWithParent":break;case"Underneath":for(d=e,t.x=d.x,t.y=d.y,t.BoundingRectangle=new Bt(t.x,t.y,t.width,t.height),i=e.x+this.options.underneathHorizontalOffset,c=e.y+l+this.options.underneathVerticalTopOffset,s=0;s<t.children.length;s++)r=t.children[s],n=new Ot(i,c),this.arrange(r,n),c+=r.Size.height+this.options.underneathVerticalSeparation;break;case"Default":if(d=new Ot(e.x+(t.Size.width-a)/2,e.y),t.x=d.x,t.y=d.y,t.BoundingRectangle=new Bt(t.x,t.y,t.width,t.height),Math.abs(d.x-e.x)<u){for(h=0,s=0;s<t.children.length;s++)o=t.children[s],h+=o.Size.width+this.options.horizontalSeparation;h-=this.options.horizontalSeparation,i=e.x+(a-h)/2}else i=e.x;for(s=0;s<t.children.length;s++)r=t.children[s],c=d.y+this.options.verticalSeparation+l,n=new Ot(i,c),this.arrange(r,n),i+=r.Size.width+this.options.horizontalSeparation;break;default:throw new Error("Unsupported TreeDirection")}break;case"None":break;default:throw new Error("Unsupported TreeDirection")}}}layoutSwitch(){if(!this.center)return;if($(this.center.children))return;let t,e,i,s,n=this.options.subtype;j(n)&&(n="Down");const o=this.center.children;switch(n.toLowerCase()){case"radial":case"radialtree":this.layoutRadialTree();break;case"mindmaphorizontal":case"mindmap":t=this.center.children,1===this.center.children.length?this.layoutRight(t):(s=o.length/2,e=ut(this.center.children,(function(t){return ct(o,t)<s})),i=ut(this.center.children,(function(t){return ct(o,t)>=s})),this.layoutLeft(e),this.layoutRight(i));break;case"mindmapvertical":t=this.center.children,1===this.center.children.length?this.layoutDown(t):(s=o.length/2,e=ut(this.center.children,(function(t){return ct(o,t)<s})),i=ut(this.center.children,(function(t){return ct(o,t)>=s})),this.layoutUp(e),this.layoutDown(i));break;case"right":this.layoutRight(this.center.children);break;case"left":this.layoutLeft(this.center.children);break;case"up":case"bottom":this.layoutUp(this.center.children);break;case"down":case"top":this.layoutDown(this.center.children);break;case"tipover":case"tipovertree":if(this.options.tipOverTreeStartLevel<0)throw new Error("The tip-over level should be a positive integer.");this.tipOverTree(this.center.children,this.options.tipOverTreeStartLevel)}}}class Be extends Wt{constructor(t){if(super(),j(t))throw new Error("No diagram specified.");this.diagram=t}layout(t){this.transferOptions(t);const e=new Xt(this.diagram);this.graph=e.convert();const i=this.layoutComponents();return new qt(this.diagram,i)}layoutComponents(){if(this.graph.isEmpty())return;const t=this.graph.getConnectedComponents();if($(t))return;const e=new Oe(this.options),i=[];for(let s=0;s<t.length;s++){const n=t[s],o=this.getTree(n);if(!o)throw new Error("Failed to find a spanning tree for the component.");const r=o.root,h=o.tree;e.layout(h,r),i.push(h)}return this.gridLayoutComponents(i)}getTree(t){let e=null;if(this.options.roots&&this.options.roots.length>0)for(let i=0,s=t.nodes.length;i<s;i++){const s=t.nodes[i];for(let t=0;t<this.options.roots.length;t++){if(this.options.roots[t]===s.associatedShape){e=s;break}}}if(!e&&(e=t.root(),!e))throw new Error("Unable to find a root for the tree.");return this.getTreeForRoot(t,e)}getTreeForRoot(t,e){const i=t.getSpanningTree(e);return j(i)||i.isEmpty()?null:{tree:i,root:i.root()}}}class Re{constructor(t,e){this.diagram=t,this.options=Ft({},this.options,e),this.visual=new Me,this.diagram._adorners.push(this)}refresh(){}}class Ae{constructor(t,e,i){this.item=t,this._undoSource=e,this._undoTarget=i,this._redoSource=t.source(),this._redoTarget=t.target(),this.title=O}undo(){this.item._updateConnector(this._undoSource,z),this.item._updateConnector(this._undoTarget,D),this.item.updateModel()}redo(){this.item._updateConnector(this._redoSource,z),this.item._updateConnector(this._redoTarget,D),this.item.updateModel()}}function Ve(t){return t.options.name.toLowerCase()===m.toLowerCase()}function He(t,e){let i,s,n=R;for(let o=0;o<e.length;o++)if(s=e[o],!Ve(s)){const e=t.distanceTo(s.position());e<n&&(n=e,i=s)}return i}function Fe(t,e){const i=[];let s,n;const o=t.drawingContainer().children,r=o.length;for(s=0;s<e.length;s++){n=e[s];for(let t=0;t<r;t++)if(o[t]===n.drawingContainer()){i.push(t);break}}return i}function Ue(t){const e={};return K((t=t||{}).text)&&null!==t.text&&(e.text=t.text),K(t.x)&&null!==t.x&&(e.x=t.x),K(t.y)&&null!==t.y&&(e.y=t.y),K(t.width)&&null!==t.width&&(e.width=t.width),K(t.height)&&null!==t.height&&(e.height=t.height),K(t.type)&&null!==t.type&&(e.type=t.type),e}class We{constructor(t,e,i){this.shapes=e,this.undoRotates=i,this.title="Rotation",this.redoRotates=[],this.redoAngle=t._angle,this.adorner=t,this.center=t._innerBounds.center();for(let t=0;t<this.shapes.length;t++){const e=this.shapes[t];this.redoRotates.push(e.rotate().angle)}}undo(){let t,e;for(t=0;t<this.shapes.length;t++)e=this.shapes[t],e.rotate(this.undoRotates[t],this.center,!1),"layout"in e&&e.layout(e),e.updateModel();this.adorner&&(this.adorner._initialize(),this.adorner.refresh())}redo(){let t,e;for(t=0;t<this.shapes.length;t++)e=this.shapes[t],e.rotate(this.redoRotates[t],this.center,!1),"layout"in e&&e.layout(e),e.updateModel();this.adorner&&(this.adorner._initialize(),this.adorner.refresh())}}const qe={width:7,height:7,fill:{color:"Yellow"},hover:{}};class Ke{constructor(t,e){this.options=Ft({},qe,e),this.connections=[],this.shape=t}position(){return this.options.position?this.options.position(this.shape):this.shape.getPosition(this.options.name)}toJSON(){return{shapeId:this.shape.toString(),connector:this.options.name}}static parse(t,e){const i=e.split(":"),s=i[0],n=i[1]||m;for(let e=0;e<t.shapes.length;e++){const i=t.shapes[e];if(i.options.id===s)return i.getConnector(n.trim())}}}const Ye=[{name:_},{name:v},{name:w},{name:y},{name:m,position:function(t){return t.getPosition("center")}}],je=function(t){const e={type:"rectangle",path:"",autoSize:!0,visual:null,x:0,y:0,minWidth:20,minHeight:20,width:100,height:100,hover:{},editable:{connect:!0,tools:[]},connectors:Ye,rotation:{angle:0}};return Q(e,t),e},Ge={hover:{},cursor:g.grip,content:{align:"center middle"},selectable:!0,serializable:!0,enable:!0};class Xe extends kt{constructor(t){super(),this.dataItem=(t||{}).dataItem,this.options=Ft({id:Pt()},Ge,t),this.isSelected=!1,this.visual=new Me({id:this.options.id,autoSize:this.options.autoSize}),this.id=this.options.id,this._template()}_getCursor(t){return this.adorner?this.adorner._getCursor(t):this.options.cursor}visible(t){if(j(t))return this.visual.visible();this.visual.visible(t)}bounds(t){return j(t),null}refresh(){this.visual.redraw()}position(t){this.options.x=t.x,this.options.y=t.y,this.visual.position(t)}toString(){return this.options.id}serialize(){const t=Ft({},{options:this.options});return this.dataItem&&(t.dataItem=this.dataItem.toString()),t}_content(t){if(void 0!==t){const e=this.options;J(t)?e.content.text=t:Ft(e.content,t);const i=e.content;this._contentVisual?this._updateContentVisual(i):this._createContentVisual(i)}return this.options.content.text}_createContentVisual(t){t.text&&(this._contentVisual=new De(t),this._contentVisual._includeInBBox=!1,this.visual.append(this._contentVisual))}_updateContentVisual(t){this._contentVisual.redraw(t)}_hitTest(t){const e=this.bounds();return this.visible()&&e.contains(t)&&this.options.enable}_template(){if(this.options.content.template){const t=this.dataItem||{},e=this.options.kendoTemplate(this.options.content.template,{paramName:"dataItem"});this.options.content.text=e(t)}}_canSelect(){return!1!==this.options.selectable}toJSON(){return{id:this.options.id}}}class Je extends Xe{constructor(t,e){super(t),this.options=Ft({},this.options,je(),t),this.diagram=e,this.updateOptionsFromModel(),t=this.options,this.connectors=[],this.type=t.type,this.createShapeVisual(),this.updateBounds(),this.content(this.content()),this._createConnectors()}_setOptionsFromModel(t){const e=Ue(t||this.dataItem);this.options=Ft({},this.options,e),this.redrawVisual()}updateOptionsFromModel(t,e){if(this.diagram&&this.diagram._isEditable){const i=Ue(t||this.dataItem);if(t&&e)if(lt(["x","y","width","height"],e)){const i=this.bounds();i[e]=t[e],this.bounds(i)}else this.options.visual?this._redrawVisual():i.type&&(this.options=Ft({},this.options,i),this._redrawVisual()),this.options.content&&(this._template(),this.content(this.options.content));else this.options=Ft({},this.options,i)}}_redrawVisual(){this.visual.clear(),this._contentVisual=null,this.options.dataItem=this.dataItem,this.createShapeVisual(),this.updateBounds()}redrawVisual(){this._redrawVisual(),this.options.content&&(this._template(),this.content(this.options.content))}updateModel(t){const e=this.diagram;e&&e._isEditable&&e.updateShapeModel(this,t)}updateBounds(){const t=this.visual._measure(!0),e=this.options;this.bounds(new Bt(e.x,e.y,t.width,t.height)),this._rotate(),this._alignContent()}content(t){const e=this._content(t);return this._alignContent(),e}_alignContent(){const t=this.options.content||{},e=this._contentVisual;if(e&&t.align){const i=this.visual._measure(),s=new Rt(i),n=e.drawingElement.bbox(null),o=new Bt(0,0,n.width(),n.height()),r=s.align(o,t.align);e.position(r.topLeft())}}_createConnectors(){const t=this.options,e=t.connectors.length,i=t.connectorDefaults;let s,n;for(n=0;n<e;n++)s=new Ke(this,Ft({},i,t.connectors[n])),this.connectors.push(s)}bounds(t){let e;if(t)if(J(t))switch(t){case U:e=this._transformedBounds();break;case"absolute":{e=this._transformedBounds();const t=this.diagram._pan;e.x+=t.x,e.y+=t.y;break}case I:e=this._rotatedBounds();break;default:e=this._bounds}else this._setBounds(t),this._triggerBoundsChange(),this.diagram&&this.diagram._layouting||this.refreshConnections();else e=this._bounds;return e}_setBounds(t){const e=this.options,i=t.topLeft(),s=e.x=i.x,n=e.y=i.y,o=e.width=Math.max(t.width,e.minWidth),r=e.height=Math.max(t.height,e.minHeight);this._bounds=new Bt(s,n,o,r),this.visual.redraw({x:s,y:n,width:o,height:r})}position(t){if(!t)return this._bounds.topLeft();this.bounds(new Bt(t.x,t.y,this._bounds.width,this._bounds.height))}clone(){const t=this.serialize();return t.options.id=Pt(),this.diagram&&this.diagram._isEditable&&K(this.dataItem)&&(t.options.dataItem=this.diagram.options.cloneDataItem(this.dataItem)),new Je(t.options,void 0)}select(t){const e=this.diagram;let i,s;if(j(t)&&(t=!0),this._canSelect()&&this.isSelected!==t)return i=[],s=[],this.isSelected=t,this.isSelected?(e._selectedItems.push(this),i.push(this)):(at(e._selectedItems,this),s.push(this)),e._internalSelection||e._selectionChanged(i,s),!0}rotate(t,e,i){const s=this.visual.rotate();if(void 0!==t){!1!==i&&this.diagram&&this.diagram.undoRedoService&&t!==s.angle&&this.diagram.undoRedoService.add(new We(this.diagram._resizingAdorner,[this],[s.angle]),!1);const n=this.bounds(),o=new Ot(n.width/2,n.height/2);let r,h;e&&(r=t-s.angle,h=n.center().rotate(r,e).minus(o),this._rotationOffset=this._rotationOffset.plus(h.minus(n.topLeft())),this.position(h)),this.visual.rotate(t,o),this.options.rotation.angle=t,this.diagram&&this.diagram._connectorsAdorner&&this.diagram._connectorsAdorner.refresh(),this.refreshConnections(),this.diagram&&this.diagram.trigger(S,{item:this})}return s}connections(t){const e=[];let i,s,n,o,r;for(i=0;i<this.connectors.length;i++)for(r=this.connectors[i],o=r.connections,s=0;s<o.length;s++)if(n=o[s],"out"===t){const t=n.source();t.shape&&t.shape===this&&e.push(n)}else if("in"===t){const t=n.target();t.shape&&t.shape===this&&e.push(n)}else e.push(n);return e}refreshConnections(){this.connections().forEach((function(t){t.refresh()}))}getConnector(t){let e,i;if(!J(t))return t instanceof Ot?He(t,this.connectors):this.connectors.length?this.connectors[0]:null;for(t=t.toLocaleLowerCase(),e=0;e<this.connectors.length;e++)if(i=this.connectors[e],i.options.name.toLocaleLowerCase()===t)return i}getPosition(t){const e=this.bounds(),i=t.charAt(0).toLowerCase()+t.slice(1);return Y(e[i])?this._transformPoint(e[i]()):e.center()}redraw(t){if(t){let e,i=this.options;this.shapeVisual.redraw(this._visualOptions(t)),this._diffNumericOptions(t,[s,n,o,r])&&(this.bounds(new Bt(i.x,i.y,i.width,i.height)),e=!0),t.connectors&&(i.connectors=t.connectors,this._updateConnectors()),i=Ft(i,t),(t.rotation||e)&&this._rotate(),i.content&&this.content(i.content)}}_updateConnectors(){const t=this.connections();let e,i,s;this.connectors=[],this._createConnectors();for(let n=0;n<t.length;n++)e=t[n],i=e.source(),s=e.target(),i.shape&&i.shape===this?e.source(this.getConnector(i.options.name)||null):s.shape&&s.shape===this&&e.target(this.getConnector(s.options.name)||null),e.updateModel()}_diffNumericOptions(t,e){return he.call(this,t,e)}_visualOptions(t){return{data:t.path,source:t.source,hover:t.hover,fill:t.fill,stroke:t.stroke}}_triggerBoundsChange(){this.diagram&&this.diagram.trigger(M,{item:this,bounds:this._bounds.clone()})}_transformPoint(t){const e=this.rotate(),i=this.bounds().topLeft();return e.angle&&t.rotate(e.angle,e.center().plus(i)),t}_transformedBounds(){const t=this.bounds(),e=t.topLeft(),i=t.bottomRight();return Bt.fromPoints(this.diagram.modelToView(e),this.diagram.modelToView(i))}_rotatedBounds(){const t=this.bounds().rotatedBounds(this.rotate().angle),e=t.topLeft(),i=t.bottomRight();return Bt.fromPoints(e,i)}_rotate(){const t=this.options.rotation;t&&t.angle&&this.rotate(t.angle),this._rotationOffset=new Ot}_hover(t){const e=this.options,i=e.hover;let s=e.stroke,n=e.fill;t&&q(i.stroke)&&(s=Ft({},s,i.stroke)),t&&q(i.fill)&&(n=i.fill),this.shapeVisual.redraw({stroke:s,fill:n}),e.editable&&e.editable.connect&&this.diagram._showConnectors(this,t)}_hitTest(t){if(this.visible()){const e=this.bounds(),i=this.rotate().angle;let s;if(t.isEmpty&&!t.isEmpty())return Zt.rects(t,e,i||0);if(s=t.clone().rotate(i,e.center()),e.contains(s))return this}}toJSON(){return{shapeId:this.options.id}}createShapeVisual(){const t=this.options,e=this._visualOptions(t),i=t.visual,s=(t.type+"").toLocaleLowerCase();let n;e.width=t.width,e.height=t.height,Y(i)?n=i.call(this,t):e.data?(n=new Ee(e),function(t){const e=t.drawingContainer().clippedBBox(null);0===e.origin.x&&0===e.origin.y||t.position(-e.origin.x,-e.origin.y)}(n)):n="rectangle"===s?new Pe(e):"circle"===s?new be(e):"text"===s?new De(e):"image"===s?new ke(e):new Ee(e),this.shapeVisual=n,this.visual.append(this.shapeVisual)}}class Ze extends Re{constructor(t,e){e=Ft({handles:{}},e),super(t.diagram,e),this.connection=t;const i=this.connection.diagram;this._ts=i.toolService;const s=this.connection.sourcePoint(),n=this.connection.targetPoint();this.spVisual=new be(Ft(this.options.handles,{center:s})),this.epVisual=new be(Ft(this.options.handles,{center:n})),this.visual.append(this.spVisual),this.visual.append(this.epVisual)}_getCursor(){return g.move}start(t){switch(this.handle=this._hitTest(t),this.startPoint=t,this._initialSource=this.connection.source(),this._initialTarget=this.connection.target(),this.handle){case-1:this.connection.targetConnector&&this._ts._connectionManipulation(this.connection,this.connection.targetConnector.shape);break;case 1:this.connection.sourceConnector&&this._ts._connectionManipulation(this.connection,this.connection.sourceConnector.shape)}}move(t,e){switch(t){case-1:this.connection.source(e);break;case 1:this.connection.target(e);break;default:{const t=e.minus(this.startPoint);this.startPoint=e,this.connection.sourceConnector||this.connection.source(this.connection.sourcePoint().plus(t)),this.connection.targetConnector||this.connection.target(this.connection.targetPoint().plus(t));break}}return this.refresh(),!0}stop(t){const e=this.diagram.toolService,i=e.hoveredItem;let s;return s=e._hoveredConnector?e._hoveredConnector._c:i&&i instanceof Je?i.getConnector(m)||i.getConnector(t):t,-1===this.handle?this.connection.source(s):1===this.handle&&this.connection.target(s),this.handle=void 0,this._ts._connectionManipulation(),new Ae(this.connection,this._initialSource,this._initialTarget)}_hitTest(t){const e=this.connection.sourcePoint(),i=this.connection.targetPoint(),s=this.options.handles.width/2+f,n=this.options.handles.height/2+f,o=e.distanceTo(t),r=i.distanceTo(t),h=new Bt(e.x,e.y).inflate(s,n).contains(t),a=new Bt(i.x,i.y).inflate(s,n).contains(t);let l=0;return h&&(!a||o<r)?l=-1:a&&(!h||r<o)&&(l=1),l}refresh(){this.spVisual.redraw({center:this.diagram.modelToLayer(this.connection.sourcePoint())}),this.epVisual.redraw({center:this.diagram.modelToLayer(this.connection.targetPoint())})}}class $e{constructor(t){this.options=Ft({},t.options),this._c=t,this.visual=new be(this.options),this.refresh()}_hover(t){const e=this.options,i=e.hover;let s=e.stroke,n=e.fill;t&&q(i.stroke)&&(s=Ft({},s,i.stroke)),t&&q(i.fill)&&(n=i.fill),this.visual.redraw({stroke:s,fill:n})}refresh(){const t=this._c.shape.diagram.modelToView(this._c.position()),e=t.minus(this._c.shape.bounds("transformed").topLeft()),i=new Bt(t.x,t.y,0,0);i.inflate(this.options.width/2,this.options.height/2),this._visualBounds=i,this.visual.redraw({center:new Ot(e.x,e.y)})}_hitTest(t){const e=this._c.shape.diagram.modelToView(t);return this._visualBounds.contains(e)}}class Qe extends Re{constructor(t,e){super(t,e),this._refreshHandler=t=>{t.item===this.shape&&this.refresh()}}show(t){this._visible=!0,this.shape=t,this.diagram.bind(M,this._refreshHandler),this.connectors=[],this._clearVisual();const e=t.connectors.length;for(let i=0;i<e;i++){const e=new $e(t.connectors[i]);this.connectors.push(e),this.visual.append(e.visual)}this.visual.visible(!0),this.refresh()}_clearVisual(){this.diagram._cachedTouchTarget?this._keepCachedTouchTarget():this.visual.clear()}_keepCachedTouchTarget(){const t=this.visual.children,e=t.length,i=dt(this.diagram._cachedTouchTarget,t);for(let s=e-1;s>=0;s--)s!==i&&this.visual.remove(t[s])}destroy(){this.diagram.unbind(M,this._refreshHandler),this.shape=void 0,this._visible=void 0,this.visual.visible(!1)}_hitTest(t){let e,i;for(i=0;i<this.connectors.length;i++)if(e=this.connectors[i],e._hitTest(t)){e._hover(!0),this.diagram.toolService._hoveredConnector=e;break}}refresh(){if(this.shape){let t=this.shape.bounds();t=this.diagram.modelToLayer(t),this.visual.position(t.topLeft()),this.connectors.forEach((function(t){t.refresh()}))}}}function ti(t){const e=t.options.editable;return e&&!1!==e.drag}class ei{constructor(t,e,i){this.shapes=t,this.undoStates=e,this.title="Transformation",this.redoStates=[],this.adorner=i;for(let t=0;t<this.shapes.length;t++){const e=this.shapes[t];this.redoStates.push(e.bounds())}}undo(){for(let t=0;t<this.shapes.length;t++){const e=this.shapes[t];e.bounds(this.undoStates[t]),"layout"in e&&e.layout(e,this.redoStates[t],this.undoStates[t]),e.updateModel()}this.adorner&&(this.adorner.refreshBounds(),this.adorner.refresh())}redo(){for(let t=0;t<this.shapes.length;t++){const e=this.shapes[t];e.bounds(this.redoStates[t]),"layout"in e&&e.layout(e,this.undoStates[t],this.redoStates[t]),e.updateModel()}this.adorner&&(this.adorner.refreshBounds(),this.adorner.refresh())}}const ii={handles:{fill:{color:"#fff"},stroke:{color:"#282828"},height:7,width:7,hover:{fill:{color:"#282828"},stroke:{color:"#282828"}}},selectable:{stroke:{color:"#778899",width:1,dashType:"dash"},fill:{color:h}},offset:10};class si extends Re{constructor(t,e){super(t,e=Ft({},ii,e)),this._manipulating=!1,this.map=[],this.shapes=[],this._initSelection(),this._createHandles(),this.redraw(),this.diagram.bind("select",(()=>{this._initialize()})),this._refreshHandler=()=>{this._internalChange||(this.refreshBounds(),this.refresh())},this._rotatedHandler=()=>{1===this.shapes.length&&(this._angle=this.shapes[0].rotate().angle),this._refreshHandler()},this.diagram.bind(M,this._refreshHandler).bind(S,this._rotatedHandler),this.refreshBounds(),this.refresh()}_initSelection(){const t=this.diagram.options.selectable,e=Ft({},this.options.selectable,t);this.rect=new Pe(e),this.visual.append(this.rect)}_resizable(){return this.options.editable&&!1!==this.options.editable.resize}_handleOptions(){return(this.options.editable.resize||{}).handles||this.options.handles}_createHandles(){let t,e,i,s;if(this._resizable())for(t=this._handleOptions(),s=-1;s<=1;s++)for(i=-1;i<=1;i++)0===s&&0===i||(e=new Pe(t),e.drawingElement._hover=this._hover.bind(this),this.map.push({x:s,y:i,visual:e}),this.visual.append(e))}bounds(t){if(!t)return this._bounds;this._innerBounds=t.clone(),this._bounds=this.diagram.modelToLayer(t).inflate(this.options.offset,this.options.offset)}_hitTest(t){const e=this.map.length;let i,s,n,o,r=this.diagram.modelToLayer(t);if(this._angle&&(r=r.clone().rotate(this._angle,this._bounds.center())),this._resizable())for(i=0;i<e;i++)if(o=this.map[i],s=new Ot(o.x,o.y),n=this._getHandleBounds(s),n.offset(this._bounds.x,this._bounds.y),n.contains(r))return s;if(this._bounds.contains(r))return new Ot(0,0)}_getHandleBounds(t){if(this._resizable()){const e=this._handleOptions(),i=e.width,s=e.height,n=new Bt(0,0,i,s);return t.x<0?n.x=-i/2:0===t.x?n.x=Math.floor(this._bounds.width/2)-i/2:t.x>0&&(n.x=this._bounds.width+1-i/2),t.y<0?n.y=-s/2:0===t.y?n.y=Math.floor(this._bounds.height/2)-s/2:t.y>0&&(n.y=this._bounds.height+1-s/2),n}}_getCursor(t){let e=this._hitTest(t);if(e&&e.x>=-1&&e.x<=1&&e.y>=-1&&e.y<=1&&this._resizable()){const t=this._angle;if(t&&(e.rotate(t,new Ot(0,0)),e=new Ot(Math.round(e.x),Math.round(e.y))),-1===e.x&&-1===e.y)return"nw-resize";if(1===e.x&&1===e.y)return"se-resize";if(-1===e.x&&1===e.y)return"sw-resize";if(1===e.x&&-1===e.y)return"ne-resize";if(0===e.x&&-1===e.y)return"n-resize";if(0===e.x&&1===e.y)return"s-resize";if(1===e.x&&0===e.y)return"e-resize";if(-1===e.x&&0===e.y)return"w-resize"}return this._manipulating?g.move:g.select}_initialize(){let t,e;const i=this.diagram.select();for(this.shapes=[],t=0;t<i.length;t++)e=i[t],e instanceof Je&&(this.shapes.push(e),e._rotationOffset=new Ot);this._angle=1===this.shapes.length?this.shapes[0].rotate().angle:0,this._startAngle=this._angle,this._rotates(),this._positions(),this.refreshBounds(),this.refresh(),this.redraw()}_rotates(){let t,e;for(this.initialRotates=[],t=0;t<this.shapes.length;t++)e=this.shapes[t],this.initialRotates.push(e.rotate().angle)}_positions(){let t,e;for(this.initialStates=[],t=0;t<this.shapes.length;t++)e=this.shapes[t],this.initialStates.push(e.bounds())}_hover(t,e){if(this._resizable()){const i=this._handleOptions(),s=i.hover;let n=i.stroke,o=i.fill;t&&q(s.stroke)&&(n=Ft({},n,s.stroke)),t&&q(s.fill)&&(o=s.fill),e.stroke(n.color,n.width,n.opacity),e.fill(o.color,o.opacity)}}start(t){this._sp=t,this._cp=t,this._lp=t,this._manipulating=!0,this._internalChange=!0,this.shapeStates=[];for(let t=0;t<this.shapes.length;t++){const e=this.shapes[t];this.shapeStates.push(e.bounds())}}redraw(){let t,e;const i=this._resizable();for(t=0;t<this.map.length;t++)e=this.map[t],e.visual.visible(i)}angle(t){return K(t)&&(this._angle=t),this._angle}rotate(){const t=this._innerBounds.center();let e=this.angle();this._internalChange=!0;for(let i=0;i<this.shapes.length;i++){const s=this.shapes[i];e=(e+this.initialRotates[i]-this._startAngle)%360,s.rotate(e,t)}this.refresh()}move(t,e){let i,s,n,o,r,h,a,l,c,d,u,p=new Ot,g=new Ot,f=0;if(-2===t.y&&-1===t.x){for(o=this._innerBounds.center(),this._angle=this._truncateAngle(ot(o,e)),h=0;h<this.shapes.length;h++)r=this.shapes[h],a=(this._angle+this.initialRotates[h]-this._startAngle)%360,r.rotate(a,o),Object.prototype.hasOwnProperty.call(r,"layout")&&r.layout(r),this._rotating=!0;this.refresh()}else{if(this.shouldSnap()){const t=this._truncateDistance(e.minus(this._lp));if(0===t.x&&0===t.y)return void(this._cp=e);i=t,this._lp=new Ot(this._lp.x+t.x,this._lp.y+t.y)}else i=e.minus(this._cp);for(this.isDragHandle(t)?(g=p=i,s=!0):(this._angle&&i.rotate(this._angle,new Ot(0,0)),-1===t.x?p.x=i.x:1===t.x&&(g.x=i.x),-1===t.y?p.y=i.y:1===t.y&&(g.y=i.y)),s||(c=function(t,e){let i;return-1===t.x&&-1===t.y?i=e.bottomRight():1===t.x&&1===t.y?i=e.topLeft():-1===t.x&&1===t.y?i=e.topRight():1===t.x&&-1===t.y?i=e.bottomLeft():0===t.x&&-1===t.y?i=e.bottom():0===t.x&&1===t.y?i=e.top():1===t.x&&0===t.y?i=e.left():-1===t.x&&0===t.y&&(i=e.right()),i}(t,this._innerBounds),d=(this._innerBounds.width+i.x*t.x)/this._innerBounds.width,u=(this._innerBounds.height+i.y*t.y)/this._innerBounds.height),h=0;h<this.shapes.length;h++){if(r=this.shapes[h],n=r.bounds(),s){if(!ti(r))continue;l=this._displaceBounds(n,p,g,s)}else{l=n.clone(),l.scale(d,u,c,this._innerBounds.center(),r.rotate().angle);const t=l.center();t.rotate(-this._angle,n.center()),l=new Bt(t.x-l.width/2,t.y-l.height/2,l.width,l.height)}if(l.width>=r.options.minWidth&&l.height>=r.options.minHeight){const t=n;r.bounds(l),Object.prototype.hasOwnProperty.call(r,"layout")&&r.layout(r,t,l),t.width===l.width&&t.height===l.height||r.rotate(r.rotate().angle),f+=1}}f&&(f===h?(l=this._displaceBounds(this._innerBounds,p,g,s),this.bounds(l)):this.refreshBounds(),this.refresh()),this._positions()}this._cp=e}isDragHandle(t){return 0===t.x&&0===t.y}cancel(){const t=this.shapes,e=this.shapeStates;for(let i=0;i<t.length;i++)t[i].bounds(e[i]);this.refreshBounds(),this.refresh(),this._manipulating=void 0,this._internalChange=void 0,this._rotating=void 0}_truncatePositionToGuides(t){return this.diagram.ruler?this.diagram.ruler.truncatePositionToGuides(t):t}_truncateSizeToGuides(t){return this.diagram.ruler?this.diagram.ruler.truncateSizeToGuides(t):t}_truncateAngle(t){const e=this.snapOptions(),i=Math.max(e.angle||10,5);return e?Math.floor(t%360/i)*i:t%360}_truncateDistance(t){if(t instanceof Ot)return new Ot(this._truncateDistance(t.x),this._truncateDistance(t.y));{const e=this.snapOptions()||{},i=Math.max(e.size||10,5);return e?Math.floor(t/i)*i:t}}snapOptions(){return((this.diagram.options.editable||{}).drag||{}).snap||{}}shouldSnap(){const t=this.diagram.options.editable,e=(t||{}).drag,i=(e||{}).snap;return!1!==t&&!1!==e&&!1!==i}_displaceBounds(t,e,i,s){const n=t.topLeft().plus(e),o=t.bottomRight().plus(i);let r,h=Bt.fromPoints(n,o);return s||(r=h.center(),r.rotate(-this._angle,t.center()),h=new Bt(r.x-h.width/2,r.y-h.height/2,h.width,h.height)),h}stop(){let t,e,i;if(this._cp!==this._sp)if(this._rotating)t=new We(this,this.shapes,this.initialRotates),this._rotating=!1;else if(this._diffStates()){if(this.diagram.ruler)for(e=0;e<this.shapes.length;e++){i=this.shapes[e];let t=i.bounds();t=this._truncateSizeToGuides(this._truncatePositionToGuides(t)),i.bounds(t),this.refreshBounds(),this.refresh()}for(e=0;e<this.shapes.length;e++)i=this.shapes[e],i.updateModel();t=new ei(this.shapes,this.shapeStates,this),this.diagram._syncShapeChanges()}return this._manipulating=void 0,this._internalChange=void 0,this._rotating=void 0,t}_diffStates(){const t=this.shapes,e=this.shapeStates;for(let i=0;i<t.length;i++)if(!t[i].bounds().equals(e[i]))return!0;return!1}refreshBounds(){const t=1===this.shapes.length?this.shapes[0].bounds().clone():this.diagram.boundingBox(this.shapes,!0);this.bounds(t)}refresh(){let t,e;if(this.shapes.length>0){e=this.bounds(),this.visual.visible(!0),this.visual.position(e.topLeft()),this.map.forEach((e=>{t=this._getHandleBounds(new Ot(e.x,e.y)),e.visual.position(t.topLeft())})),this.visual.position(e.topLeft());const i=new Ot(e.width/2,e.height/2);if(this.visual.rotate(this._angle,i),this.rect.redraw({width:e.width,height:e.height}),this.rotationThumb){const t=this.options.editable.rotate.thumb;this._rotationThumbBounds=new Bt(e.center().x,e.y+t.y,0,0).inflate(t.width),this.rotationThumb.redraw({x:e.width/2-t.width/2})}}else this.visual.visible(!1)}}const ni={stroke:{color:"#778899",width:1,dashType:"dash"},fill:{color:h}};class oi{constructor(t){const e=t.options.selectable;this.options=Ft({},ni,e),this.visual=new Pe(this.options),this.diagram=t}start(t){this._sp=this._ep=t,this.refresh(),this.diagram._adorn(this,!0)}end(){this._sp=this._ep=void 0,this.diagram._adorn(this,!1)}bounds(t){return t&&(this._bounds=t),this._bounds}move(t){this._ep=t,this.refresh()}refresh(){if(this._sp){const t=Bt.fromPoints(this.diagram.modelToLayer(this._sp),this.diagram.modelToLayer(this._ep));this.bounds(Bt.fromPoints(this._sp,this._ep)),this.visual.position(t.topLeft()),this.visual.redraw({height:t.height+1,width:t.width+1})}}}class ri{constructor(){}}class hi extends ri{constructor(t){super(),this.connection=t}hitTest(t){return!!this.getBounds().inflate(f).contains(t)&&Dt.distanceToPolyline(t,this.connection.allPoints())<f}getBounds(){const t=this.connection.allPoints(),e=t[0],i=t[t.length-1];let s=Math.max(e.x,i.x),n=Math.min(e.x,i.x),o=Math.min(e.y,i.y),r=Math.max(e.y,i.y);for(let e=1;e<t.length-1;++e)s=Math.max(s,t[e].x),n=Math.min(n,t[e].x),o=Math.min(o,t[e].y),r=Math.max(r,t[e].y);return new Bt(n,o,s-n,r-o)}}const ai="topLeft",li="bottomRight";class ci extends hi{constructor(t){super(t),this.SAME_SIDE_DISTANCE_RATIO=5,this._connectorSides=[{name:_,axis:r,boundsPoint:ai,secondarySign:1},{name:w,axis:o,boundsPoint:ai,secondarySign:1},{name:v,axis:r,boundsPoint:li,secondarySign:-1},{name:y,axis:o,boundsPoint:li,secondarySign:-1}],this.connection=t}routePoints(t,e,i,s){let n;return n=i&&s?this._connectorPoints(t,e,i,s):this._floatingPoints(t,e,i),n}route(){const t=this.connection._resolvedSourceConnector,e=this.connection._resolvedTargetConnector,i=this.connection.sourcePoint(),s=this.connection.targetPoint(),n=this.routePoints(i,s,t,e);this.connection.points(n)}_connectorSide(t,e){const i=t.position(),s=t.shape.bounds(I),n={topLeft:s.topLeft(),bottomRight:s.bottomRight()},o=this._connectorSides;let r,h,a,l,c=Number.MAX_VALUE;for(let t=0;t<o.length;t++)l=o[t],a=l.axis,r=Math.round(Math.abs(i[a]-n[l.boundsPoint][a])),r<c?(c=r,h=l):r===c&&(i[a]-e[a])*l.secondarySign>(i[h.axis]-e[h.axis])*h.secondarySign&&(h=l);return h.name}_sameSideDistance(t){const e=t.shape.bounds(I);return Math.min(e.width,e.height)/this.SAME_SIDE_DISTANCE_RATIO}_connectorPoints(t,e,i,s){const n=this._connectorSide(i,e),o=this._connectorSide(s,t),r=e.x-t.x,h=e.y-t.y,a=this._sameSideDistance(i);let l,c,d=[];return n===_||n===v?o===_||o===v?n===o?(c=n===_?Math.min(t.y,e.y)-a:Math.max(t.y,e.y)+a,d=[new Ot(t.x,c),new Ot(e.x,c)]):d=[new Ot(t.x,t.y+h/2),new Ot(e.x,t.y+h/2)]:d=[new Ot(t.x,e.y)]:o===w||o===y?n===o?(l=n===w?Math.min(t.x,e.x)-a:Math.max(t.x,e.x)+a,d=[new Ot(l,t.y),new Ot(l,e.y)]):d=[new Ot(t.x+r/2,t.y),new Ot(t.x+r/2,t.y+h)]:d=[new Ot(e.x,t.y)],d}_floatingPoints(t,e,i){const s=i?this._connectorSide(i,e):null,n=this._startHorizontal(t,e,s),o=[t,t,e,e],r=e.x-t.x,h=e.y-t.y,a=o.length;let l,c,d=1;for(;d<a-1;++d)n?d%2!=0?(l=r/(a/2),c=0):(l=0,c=h/((a-1)/2)):d%2!=0?(l=0,c=h/(a/2)):(l=r/((a-1)/2),c=0),o[d]=new Ot(o[d-1].x+l,o[d-1].y+c);return d--,o[a-2]=n&&d%2!=0||!n&&d%2==0?new Ot(o[a-1].x,o[a-2].y):new Ot(o[a-2].x,o[a-1].y),[o[1],o[2]]}_startHorizontal(t,e,i){let s;return s=null!==i&&(i===y||i===w)||Math.abs(t.x-e.x)>Math.abs(t.y-e.y),s}}class di extends hi{constructor(t){super(t),this.connection=t}route(){}}class ui{constructor(t){this.toolService=t,this.type="ConnectionTool"}tryActivate(t,e){const i=this.toolService,s=i.diagram.options.selectable,n=i.hoveredItem,o=!1!==s&&n&&n.path&&!(n.isSelected&&e.ctrlKey);return o&&(this._c=n),o}start(t,e){const i=this.toolService,s=this._c;i.selectSingle(s,e);const n=s.adorner;let o,r;n&&(o=n._hitTest(t),r=N[o]),ti(s)&&n&&!i.diagram.trigger(x,{shapes:[],connections:[s],connectionHandle:r})?(this.handle=o,this.handleName=r,n.start(t)):(i.startPoint=t,i.end(t))}move(t){const e=this._c.adorner;if(ti(this._c)&&e)return e.move(this.handle,t),this.toolService.diagram.trigger(b,{shapes:[],connections:[this._c],connectionHandle:this.handleName}),!0}end(t){const e=this._c,i=e.adorner,s=this.toolService.diagram;if(i&&ti(e)){const n=i.stop(t);s.trigger(C,{shapes:[],connections:[e],connectionHandle:this.handleName})?n.undo():(s.undoRedoService.add(n,!1),e.updateModel(),s._syncConnectionChanges())}}getCursor(){return g.move}}class pi{constructor(t){this.toolService=t,this.type="ConnectionTool"}tryActivate(){return this.toolService._hoveredConnector}start(t,e){const i=this.toolService,s=i.diagram,n=i._hoveredConnector,o=s._createConnection({},n._c,t);ti(o)&&!s.trigger(x,{shapes:[],connections:[o],connectionHandle:D})&&s._addConnection(o)?(i._connectionManipulation(o,n._c.shape,!0),i._removeHover(),i.selectSingle(i.activeConnection,e),"touchmove"===e.type&&(s._cachedTouchTarget=n.visual)):(o.source(null),i.end(t))}move(t){const e=this.toolService,i=e.activeConnection;return i.target(t),e.diagram.trigger(b,{shapes:[],connections:[i],connectionHandle:D}),!0}end(t){const e=this.toolService,i=e.diagram,s=e.activeConnection,n=e.hoveredItem,o=e._hoveredConnector,r=i._cachedTouchTarget;let h;s&&(h=o&&o._c!==s.sourceConnector?o._c:n&&n instanceof Je?n.getConnector(m)||n.getConnector(t):t,s.target(h),i.trigger(C,{shapes:[],connections:[s],connectionHandle:D})?(i.remove(s,!1),i.undoRedoService.pop()):(s.updateModel(),i._syncConnectionChanges()),e._connectionManipulation(),r&&(i._connectorsAdorner.visual.remove(r),i._cachedTouchTarget=null))}getCursor(){return g.arrow}}class gi{constructor(t){this.toolService=t}start(){}move(){}end(){}tryActivate(){return!1}getCursor(){return g.arrow}}function fi(t){return!1===t.ctrlKey&&!1===t.altKey&&!1===t.shiftKey}class mi{constructor(t){this.toolService=t}tryActivate(){return!0}start(t,e){const i=this.toolService,s=i.diagram,n=i.hoveredItem;n&&(i.selectSingle(n,e),n.adorner&&(this.adorner=n.adorner,this.handle=this.adorner._hitTest(t))),this.handle||(this.handle=s._resizingAdorner._hitTest(t),this.handle&&(this.adorner=s._resizingAdorner)),this.adorner&&(this.adorner.isDragHandle(this.handle)&&s.trigger(x,{shapes:this.adorner.shapes,connections:[]})?(i.startPoint=t,i.end(t)):this.adorner.start(t))}move(t){this.adorner&&(this.adorner.move(this.handle,t),this.adorner.isDragHandle(this.handle)&&this.toolService.diagram.trigger(b,{shapes:this.adorner.shapes,connections:[]}))}end(){const t=this.toolService.diagram,e=this.adorner;let i;e&&(e.isDragHandle(this.handle)&&t.trigger(C,{shapes:e.shapes,connections:[]})?e.cancel():(i=e.stop(),i&&t.undoRedoService.add(i,!1))),this.adorner=void 0,this.handle=void 0}getCursor(t){return this.toolService.hoveredItem?this.toolService.hoveredItem._getCursor(t):g.arrow}}const _i={down:"pointerdown",move:"pointermove",up:"pointerup",cancel:"pointercancel pointerleave"};function yi(t){return _i[t]||t}const wi=t=>t.replace(/([^ ]+)/g,yi);function vi(){const t=function(t){let e=!1;const i={wp:/(Windows Phone(?: OS)?)\s(\d+)\.(\d+(\.\d+)?)/,fire:/(Silk)\/(\d+)\.(\d+(\.\d+)?)/,android:/(Android|Android.*(?:Opera|Firefox).*?\/)\s*(\d+)\.?(\d+(\.\d+)?)?/,iphone:/(iPhone|iPod).*OS\s+(\d+)[._]([\d._]+)/,ipad:/(iPad).*OS\s+(\d+)[._]([\d_]+)/,playbook:/(PlayBook).*?Tablet\s*OS\s*(\d+)\.(\d+(\.\d+)?)/,windows:/(MSIE)\s+(\d+)\.(\d+(\.\d+)?)/,tizen:/(tizen).*?Version\/(\d+)\.(\d+(\.\d+)?)/i,sailfish:/(sailfish).*rv:(\d+)\.(\d+(\.\d+)?).*firefox/i},s={ios:/^i(phone|pad|pod)$/i,android:/^android|fire$/i,windows:/windows/,wp:/wp/,flat:/sailfish|ffos|tizen/i};for(const n in i){if(!Object.prototype.hasOwnProperty.call(i,n))continue;if(t.match(i[n])){if("windows"===n&&"plugins"in navigator)return!1;e={},e.device=n,e.name=xi(n,s),e[e.name]=!0;break}}return e}(navigator.userAgent),e={};return e.mobileOS=t,e}function xi(t,e,i){for(const i in e)if(e[i].test(t))return i;return void 0!==i?i:t}const bi=Object.assign,Ci=()=>(new Date).getTime(),Si=(t,e)=>{t.classList.add(e)},Mi=t=>{const e=document.createElement("div");return e.innerHTML=t,e.firstChild},ki=(t,e)=>{e.insertBefore(t,e.firstChild)},Ti=e.w,Ei=function(t,e,i){return"translate3d("+t+"px,"+e+"px,0) scale("+i+")"};class Li extends kt{constructor(t,e){super();const i=t[0]||t;this.element=i,this.capture=!1,this._pressHandler=this._press.bind(this),this._releaseHandler=this._release.bind(this),_i.down.split(" ").forEach((t=>{i.addEventListener(t,this._pressHandler,!0)})),_i.up.split(" ").forEach((t=>{i.addEventListener(t,this._releaseHandler,!0)})),this.bind(["press","release"],e||{})}captureNext(){this.capture=!0}cancelCapture(){this.capture=!1}_press(t){this.trigger("press"),this.capture&&t.preventDefault()}_release(t){this.trigger("release"),this.capture&&(t.preventDefault(),this.cancelCapture())}destroy(){const t=this.element;_i.down.split(" ").forEach((e=>{t.removeEventListener(e,this._pressHandler,!0)})),_i.up.split(" ").forEach((e=>{t.removeEventListener(e,this._releaseHandler,!0)}))}}class Pi extends kt{constructor(t){super(),this.forcedEnabled=!1,bi(this,t),this.scale=1,this.horizontal?(this.measure="offsetWidth",this.scrollSize="scrollWidth",this.axis="x"):(this.measure="offsetHeight",this.scrollSize="scrollHeight",this.axis="y")}makeVirtual(){bi(this,{virtual:!0,forcedEnabled:!0,_virtualMin:0,_virtualMax:0})}virtualSize(t,e){this._virtualMin===t&&this._virtualMax===e||(this._virtualMin=t,this._virtualMax=e,this.update())}outOfBounds(t){return t>this.max||t<this.min}forceEnabled(){this.forcedEnabled=!0}getSize(){return this.container[this.measure]}getTotal(){return this.element[this.scrollSize]}rescale(t){this.scale=t}update(t){const e=this.virtual?this._virtualMax:this.getTotal(),i=e*this.scale,s=this.getSize();(0!==e||this.forcedEnabled)&&(this.max=this.virtual?-this._virtualMin:0,this.size=s,this.total=i,this.min=Math.min(this.max,s-i),this.minScale=s/e,this.centerOffset=(i-s)/2,this.enabled=this.forcedEnabled||i>s,t||this.trigger(p,this))}}class Ii extends kt{constructor(t){super(),this.x=new Pi(bi({horizontal:!0},t)),this.y=new Pi(bi({horizontal:!1},t)),this.container=t.container,this.forcedMinScale=t.minScale,this.maxScale=t.maxScale||100,this.bind(p,t)}rescale(t){this.x.rescale(t),this.y.rescale(t),this.refresh()}centerCoordinates(){return{x:Math.min(0,-this.x.centerOffset),y:Math.min(0,-this.y.centerOffset)}}refresh(){this.x.update(),this.y.update(),this.enabled=this.x.enabled||this.y.enabled,this.minScale=this.forcedMinScale||Math.min(this.x.minScale,this.y.minScale),this.fitScale=Math.max(this.x.minScale,this.y.minScale),this.trigger(p)}}class zi extends kt{constructor(t){super(),bi(this,t)}outOfBounds(){return this.dimension.outOfBounds(this.movable[this.axis])}dragMove(t){const e=this.dimension,i=this.axis,s=this.movable,n=s[i]+t;if(!e.enabled)return;let o=t;(n<e.min&&t<0||n>e.max&&t>0)&&(o*=this.resistance),s.translateAxis(i,o),this.trigger(p,this)}}class Di{constructor(t){let e,i;bi(this,{elastic:!0},t);const s=this.elastic?.5:0,n=this.movable;this.x=e=new zi({axis:"x",dimension:this.dimensions.x,resistance:s,movable:n}),this.y=i=new zi({axis:"y",dimension:this.dimensions.y,resistance:s,movable:n}),this.userEvents.bind(["press","move","end","gesturestart","gesturechange"],{gesturestart(t){this.gesture=t,this.offset=Ti(this.dimensions.container)},press(t){const e=t.event.target.closest("a");e&&e.matches("[data-navigate-on-press=true]")&&t.sender.cancel()},gesturechange(t){const s=this.gesture,o=s.center,r=t.center,h=this.dimensions.minScale,a=this.dimensions.maxScale;let l=t.distance/s.distance;n.scale<=h&&l<1&&(l+=.8*(1-l)),n.scale*l>=a&&(l=a/n.scale);const c=n.x+this.offset.left,d=n.y+this.offset.top,u={x:(c-o.x)*l+r.x-c,y:(d-o.y)*l+r.y-d};n.scaleWith(l),e.dragMove(u.x),i.dragMove(u.y),this.dimensions.rescale(n.scale),this.gesture=t,t.preventDefault()},move(t){t.event.target.tagName.match(/textarea|input/i)||(e.dimension.enabled||i.dimension.enabled?(e.dragMove(t.x.delta),i.dragMove(t.y.delta),t.preventDefault()):t.touch.skip())},end(t){t.preventDefault()}})}}class Ni extends kt{constructor(t){super(),this.element=t,this.element.style.transformOrigin="left top",this.x=0,this.y=0,this.scale=1;const e=Ei(this.x,this.y,this.scale);this.element.style.transform=e,this._saveCoordinates(e)}translateAxis(t,e){this[t]+=e,this.refresh()}scaleTo(t){this.scale=t,this.refresh()}scaleWith(t){this.scale*=t,this.refresh()}translate(t){this.x+=t.x,this.y+=t.y,this.refresh()}moveAxis(t,e){this[t]=e,this.refresh()}moveTo(t){bi(this,t),this.refresh()}refresh(){let t=this.x,e=this.y;this.round&&(t=Math.round(t),e=Math.round(e));const i=Ei(t,e,this.scale);i!==this.coordinates&&(this.element.style.transform=i,this._saveCoordinates(i),this.trigger(p))}_saveCoordinates(t){this.coordinates=t}}function Oi(t){window.requestAnimationFrame(t)}class Bi{constructor(){this._tickProxy=()=>this._tick(),this._started=!1}tick(){}done(){return!1}onEnd(){}onCancel(){}start(){this.enabled()&&(this.done()?this.onEnd():(this._started=!0,Oi(this._tickProxy)))}enabled(){return!0}cancel(){this._started=!1,this.onCancel()}_tick(){this._started&&(this.tick(),this.done()?(this._started=!1,this.onEnd()):Oi(this._tickProxy))}}class Ri extends Bi{constructor(t){super(),bi(this,t)}done(){return this.timePassed()>=this.duration}timePassed(){return Math.min(this.duration,Ci()-this.startDate)}moveTo(t){const e=this.movable;this.initial=e[this.axis],this.delta=t.location-this.initial,this.duration="number"==typeof t.duration?t.duration:300,this.tick=this._easeProxy(t.ease),this.startDate=Ci(),this.start()}_easeProxy(t){return function(){this.movable.moveAxis(this.axis,t(this.timePassed(),this.initial,this.delta,this.duration))}}static easeOutExpo(t,e,i,s){return t===s?e+i:i*(1-Math.pow(2,-10*t/s))+e}}const Ai=new WeakMap,Vi=Symbol("id");function Hi(t,e,i,s,n){!function(t,e,i,s,n){const o=Array.isArray(e)?e:(e||"").split(" ");o.forEach((function(e){!function(t,e,i,s,n){let o,r=s;i&&Y(i)&&!s?r=i:i&&(h=i,"string"==typeof h)&&Y(r)&&(o=i);var h;const a=function(e){const i=e.target?e.target.closest(o):null;if(!o||o&&e.target&&i){const s=o?i:e.currentTarget;Object.defineProperty(e,"currentTarget",{value:s}),Object.defineProperty(e,"delegateTarget",{value:t}),r(e)}};r[Vi]||(r[Vi]=function(){let t,e,i="";for(t=0;t<32;t++)e=Math.floor(16*Math.random()),8!==t&&12!==t&&16!==t&&20!==t||(i+="-"),i+=(12===t?4:16===t?e%4+8:e).toString(16);return i}());let l=Ai.get(t);l||(l=new Map,Ai.set(t,l));l.set(e+r[Vi],a),t.addEventListener(e,a,Boolean(n))}(t,e,i,s,n)}))}(t,e,i,s,n)}function Fi(t,e,i,s){!function(t,e,i,s){const n=Array.isArray(e)?e:(e||"").split(" ");n.forEach((function(e){!function(t,e,i,s){const n=Ai.get(t);if(n&&i&&i[Vi]){const o=e+i[Vi],r=n.get(o);n.delete(o),r&&t.removeEventListener(e,r,Boolean(s))}}(t,e,i,s)}))}(t,e,i,s)}const Ui=t=>{t.preventDefault()},Wi=()=>{},qi="press",Ki="hold",Yi="select",ji="start",Gi="move",Xi="end",Ji="cancel",Zi="tap",$i="doubleTap",Qi="release",ts="gesturechange",es="gestureend",is="gesturetap",ss={api:0,touch:0,mouse:9,pointer:9};let ns=800,os=0;function rs(t){const e=[],i=t.originalEvent||t,s=t.currentTarget;return t.api?e.push({id:2,event:t,target:t.target,currentTarget:t.target,location:t,type:"api"}):e.push({location:i,event:t,target:t.target,currentTarget:s,id:i.pointerId,type:"pointer"}),e}class hs{constructor(t,e){this.support=vi(),this.invalidZeroEvents=this.support.mobileOS&&this.support.mobileOS.android,this.axis=t,this._updateLocationData(e),this.startLocation=this.location,this.velocity=this.delta=0,this.timeStamp=Ci()}move(t){const e=t["page"+this.axis],i=Ci(),s=i-this.timeStamp||1;!e&&this.invalidZeroEvents||(this.delta=e-this.location,this._updateLocationData(t),this.initialDelta=e-this.startLocation,this.velocity=this.delta/s,this.timeStamp=i)}_updateLocationData(t){const e=this.axis;this.location=t["page"+e],this.client=t["client"+e],this.screen=t["screen"+e]}}class as{constructor(t,e,i){bi(this,{x:new hs("X",i.location),y:new hs("Y",i.location),type:i.type,threshold:t.threshold||ss[i.type],userEvents:t,target:e,currentTarget:i.currentTarget,initialTouch:i.target,id:i.id,pressEvent:i,_clicks:t._clicks,supportDoubleTap:t.supportDoubleTap,_moved:!1,_finished:!1})}press(){this._holdTimeout=setTimeout((()=>this._hold()),this.userEvents.minHold),this._trigger(qi,this.pressEvent)}_tap(t){this.userEvents._clicks++,1===this.userEvents._clicks&&(this._clickTimeout=setTimeout((()=>{1===this.userEvents._clicks?this._trigger(Zi,t):this._trigger($i,t),this.userEvents._clicks=0}),300))}_hold(){this._trigger(Ki,this.pressEvent)}move(t){const e="api"!==t.type&&this.userEvents._shouldNotMove;if(!this._finished&&!e){if(this.x.move(t.location),this.y.move(t.location),!this._moved){if(this._withinIgnoreThreshold())return;if(cs.current&&cs.current!==this.userEvents)return this.dispose();this._start(t)}this._finished||this._trigger(Gi,t)}}end(t){this.endTime=Ci(),this._finished||(this._finished=!0,this._trigger(Qi,t),this._moved?this._trigger(Xi,t):this.supportDoubleTap?this._tap(t):this._trigger(Zi,t),clearTimeout(this._holdTimeout),this.dispose())}dispose(){const t=this.userEvents.touches||[];this._finished=!0,this.pressEvent=null,clearTimeout(this._holdTimeout);const e=t.indexOf(this);t.splice(e,1)}skip(){this.dispose()}cancel(){this.dispose()}isMoved(){return this._moved}_start(t){clearTimeout(this._holdTimeout),this.startTime=Ci(),this._moved=!0,this._trigger(ji,t)}_trigger(t,e){const i=e.event,s={touch:this,x:this.x,y:this.y,target:this.target,event:i};this.userEvents.notify(t,s)&&i.preventDefault()}_withinIgnoreThreshold(){const t=this.x.initialDelta,e=this.y.initialDelta;return Math.sqrt(t*t+e*e)<=this.threshold}}function ls(t){const e=_i.up.split(" "),i=e.length;for(let s=0;s<i;s++)t(e[s])}class cs extends kt{constructor(t,e){super();const i=vi();this.support=i,e=e||{},this.options=e;const s=this.filter=e.filter;if(this.threshold=e.threshold||os,this.minHold=e.minHold||ns,this.touches=[],this._maxTouches=e.multiTouch?2:1,this.allowSelection=e.allowSelection,this.captureUpIfMoved=e.captureUpIfMoved,this._clicks=0,this.supportDoubleTap=e.supportDoubleTap,bi(this,{element:t,surface:e.surface||t,stopPropagation:e.stopPropagation,pressed:!1}),this._surfaceMoveHandler=this._move.bind(this),Hi(this.surface,wi("move"),this._surfaceMoveHandler),this._surfaceEndHandler=this._end.bind(this),Hi(this.surface,wi("up cancel"),this._surfaceEndHandler),this._elementStartHandler=this._start.bind(this),Hi(t,wi("down"),s,this._elementStartHandler),t.style["touch-action"]=e.touchAction||"none",e.preventDragEvent&&(this._elementDragStartHandler=Ui,Hi(t,wi("dragstart"),this._elementDragStartHandler)),this._elementSelectHandler=this._select.bind(this),Hi(t,wi("mousedown"),s,this._elementSelectHandler),this.captureUpIfMoved){const t=this.surface;this.preventIfMovingProxy=this.preventIfMoving.bind(this),ls((e=>{t.addEventListener(e,this.preventIfMovingProxy,!0)}))}this.bind([qi,Ki,Zi,$i,ji,Gi,Xi,Qi,Ji,"gesturestart",ts,es,is,Yi],e)}preventIfMoving(t){this._isMoved()&&t.preventDefault()}destroy(){const t=this.options,e=this.element;if(!this._destroyed){if(this._destroyed=!0,this.captureUpIfMoved){const t=this.surface;ls((e=>{t.removeEventListener(e,this.preventIfMovingProxy,!0)}))}Fi(this.surface,wi("move"),this._surfaceMoveHandler),Fi(this.surface,wi("up cancel"),this._surfaceEndHandler),Fi(e,wi("down"),this._elementStartHandler),t.preventDragEvent&&Fi(e,wi("dragstart"),this._elementDragStartHandler),Fi(e,wi("mousedown"),this._elementSelectHandler),this._disposeAll(),this.unbind(),delete this.surface,delete this.element,delete this.currentTarget}}capture(){cs.current=this}cancel(){this._disposeAll(),this.trigger(Ji)}notify(t,e){const i=this.touches;let s=t;if(this._isMultiTouch()){switch(s){case Gi:s=ts;break;case Xi:s=es;break;case Zi:s=is}bi(e,{touches:i},function(t,e){const i=t.x.location,s=t.y.location,n=e.x.location,o=e.y.location,r=i-n,h=s-o;return{center:{x:(i+n)/2,y:(s+o)/2},distance:Math.sqrt(r*r+h*h)}}(i[0],i[1]))}return this.trigger(s,bi(e,{type:s}))}press(t,e,i){this._apiCall("_start",t,e,i)}move(t,e){this._apiCall("_move",t,e)}end(t,e){this._apiCall("_end",t,e)}_isMultiTouch(){return this.touches.length>1}_maxTouchesReached(){return this.touches.length>=this._maxTouches}_disposeAll(){const t=this.touches;for(;t.length>0;)t.pop().dispose()}_isMoved(){return function(t,e){const i=t.length,s=[];for(let n=0;n<i;n++)e(t[n])&&s.push(t[n]);return s}(this.touches,(function(t){return t.isMoved()})).length}_select(t){this.allowSelection&&!this.trigger(Yi,{event:t})||t.preventDefault()}_start(t){if(t.which&&t.which>1||this._maxTouchesReached())return;let e;cs.current=null,this.currentTarget=t.currentTarget,this.stopPropagation&&t.stopPropagation();const i=rs(t);for(let t=0;t<i.length&&!this._maxTouchesReached();t++){const s=i[t];if(e=this.filter?s.currentTarget:this.element,e&&0===e.length)continue;const n=new as(this,e,s);this.touches.push(n),n.press(),this._isMultiTouch()&&this.notify("gesturestart",{})}}_move(t){this._eachTouch("move",t)}_end(t){this._eachTouch("end",t)}_eachTouch(t,e){const i={},s=rs(e),n=this.touches;let o,r,h,a;for(o=0;o<n.length;o++)r=n[o],i[r.id]=r;for(o=0;o<s.length;o++)if(h=s[o],a=i[h.id],a){"move"===t&&"pointer"===h.type&&!this.surface.hasPointerCapture(h.id)&&this.surface.setPointerCapture(h.id),a[t](h)}}_apiCall(t,e,i,s){this[t]({api:!0,pageX:e,pageY:i,clientX:e,clientY:i,target:s||this.element,stopPropagation:Wi,preventDefault:Wi})}static defaultThreshold(t){os=t}static minHold(t){ns=t}}const ds=Object.assign,us=Math.abs,ps="change",gs="scroll";class fs extends Bi{constructor(t){super(),ds(this,t),this.userEvents.bind("gestureend",this.start.bind(this)),this.tapCapture.bind("press",this.cancel.bind(this))}enabled(){return this.movable.scale<this.dimensions.minScale}done(){return this.dimensions.minScale-this.movable.scale<.01}tick(){const t=this.movable;t.scaleWith(1.1),this.dimensions.rescale(t.scale)}onEnd(){const t=this.movable;t.scaleTo(this.dimensions.minScale),this.dimensions.rescale(t.scale)}}class ms extends Bi{constructor(t){super(),ds(this,t,{transition:new Ri({axis:t.axis,movable:t.movable,onEnd:()=>{this._end()}})}),this.tapCapture.bind("press",(()=>{this.cancel()})),this.userEvents.bind("end",(()=>this.start())),this.userEvents.bind("gestureend",(()=>this.start())),this.userEvents.bind("tap",(()=>this.onEnd()))}onCancel(){this.transition.cancel()}freeze(t){this.cancel(),this._moveTo(t)}onEnd(){this.paneAxis.outOfBounds()?this._snapBack():this._end()}done(){return us(this.velocity)<1}start(t){let e;this.dimension.enabled&&(this.paneAxis.outOfBounds()?this.transition._started?(this.transition.cancel(),this.velocity=Math.min(t.touch[this.axis].velocity*this.velocityMultiplier,55),super.start()):this._snapBack():(e=t?2===t.touch.id?0:t.touch[this.axis].velocity:0,this.velocity=Math.max(Math.min(e*this.velocityMultiplier,55),-55),this.tapCapture.captureNext(),super.start()))}tick(){const t=this.dimension,e=this.paneAxis.outOfBounds()?.5:this.friction,i=this.velocity*=e;let s=this.movable[this.axis]+i;!this.elastic&&t.outOfBounds(s)&&(s=Math.max(Math.min(s,t.max),t.min),this.velocity=0),this.movable.moveAxis(this.axis,s)}_end(){this.tapCapture.cancelCapture(),this.end()}end(){}_snapBack(){const t=this.dimension,e=this.movable[this.axis]>t.max?t.max:t.min;this._moveTo(e)}_moveTo(t){this.transition.moveTo({location:t,duration:500,ease:(...t)=>{Ri.easeOutExpo.apply(null,t)}})}}class _s extends Bi{constructor(t){super(),ds(this,t,{origin:{},destination:{},offset:{}})}moveTo(t){}tick(){this._updateCoordinates(),this.moveTo(this.origin)}done(){return us(this.offset.y)<5&&us(this.offset.x)<5}onEnd(){this.moveTo(this.destination),this.callback&&this.callback.call()}setCoordinates(t,e){this.offset={},this.origin=t,this.destination=e}setCallback(t){t&&Y(t)?this.callback=t:t=void 0}_updateCoordinates(){this.offset={x:(this.destination.x-this.origin.x)/4,y:(this.destination.y-this.origin.y)/4},this.origin={y:this.origin.y+this.offset.y,x:this.origin.x+this.offset.x}}}class ys{constructor(t){const e="x"===t.axis,i=Mi('<div class="km-touch-scrollbar km-'+(e?"horizontal":"vertical")+'-scrollbar" />');ds(this,t,{element:i,elementSize:0,movable:new Ni(i),scrollMovable:t.movable,alwaysVisible:t.alwaysVisible,size:e?"width":"height"}),this.scrollMovable.bind(ps,this.refresh.bind(this)),this.container.appendChild(i),t.alwaysVisible&&this.show()}refresh(){const t=this.axis,e=this.dimension,i=e.size,s=this.scrollMovable,n=i/e.total;let o=Math.round(i*n),r=Math.round(-s[t]*n);this.element.style.display=n>=1?"none":"",r+o>i?o=i-r:r<0&&(o+=r,r=0),this.elementSize!==o&&(this.element.style[this.size]=o+"px",this.elementSize=o),this.movable.moveAxis(t,r)}show(){this.element.style.opacity=.7,this.element.style.visibility="visible"}hide(){this.alwaysVisible||(this.element.style.opacity=0)}}const ws={name:"Scroller",zoom:!1,pullOffset:140,visibleScrollHints:!1,elastic:!0,useNative:!1,mousewheelScrolling:!0,avoidScrolling:()=>!1,pullToRefresh:!1,messages:{pullTemplate:"Pull to refresh",releaseTemplate:"Release to refresh",refreshTemplate:"Refreshing"}};class vs extends kt{constructor(t,e){super(),this.element=t=t[0]||t,this._initOptions(e),this.events.push("pull",gs,"resize");const i=(()=>{const{mobileOS:t}=vi();return t.ios||t.android})();this._native=this.options.useNative&&i;const s=Mi('<div class="km-scroll-header"/>');if(this._native)return Si(t,"km-native-scroller"),ki(s,t),void ds(this,{scrollElement:t,fixedContainer:t.children[0]});t.style.overflow="hidden",Si(t,"km-scroll-wrapper");((t,e)=>{for(t.appendChild(e);t.firstChild!==e;)e.appendChild(t.firstChild)})(t,Mi('<div class="km-scroll-container"/>')),ki(s,t);const n=t.children[1],o=new Li(t),r=new Ni(n),h=new Ii({element:n,container:t,forcedEnabled:this.options.zoom}),a=this.options.avoidScrolling,l=new cs(t,{touchAction:"none",allowSelection:!0,preventDragEvent:!0,captureUpIfMoved:!0,multiTouch:this.options.zoom,supportDoubleTap:this.options.supportDoubleTap,start:t=>{h.refresh();const e=us(t.x.velocity),i=us(t.y.velocity),s=2*e>=i,n=2*i>=e;!this.fixedContainer.contains(t.event.target)&&!a(t)&&this.enabled&&(h.x.enabled&&s||h.y.enabled&&n)?l.capture():l.cancel()}}),c=new Di({movable:r,dimensions:h,userEvents:l,elastic:this.options.elastic}),d=new fs({movable:r,dimensions:h,userEvents:l,tapCapture:o}),u=new _s({moveTo:t=>{this.scrollTo(t.x,t.y)}});r.bind(ps,(()=>{this.scrollTop=-r.y,this.scrollLeft=-r.x,this.trigger(gs,{scrollTop:this.scrollTop,scrollLeft:this.scrollLeft})})),this.options.mousewheelScrolling&&(this._wheelScrollHandler=this._wheelScroll.bind(this),Hi(t,"wheel",this._wheelScrollHandler)),ds(this,{movable:r,dimensions:h,zoomSnapBack:d,animatedScroller:u,userEvents:l,pane:c,tapCapture:o,pulled:!1,enabled:!0,scrollElement:n,scrollTop:0,scrollLeft:0,fixedContainer:t.children[0]}),this._initAxis("x"),this._initAxis("y"),this._wheelEnd=()=>{this._wheel=!1,this.userEvents.end(0,this._wheelY)},h.refresh(),this.options.pullToRefresh&&this._initPullToRefresh(),this.bind(this.events,this.options)}_initOptions(t){this.options=Ft({},this.options,ws,t)}_wheelScroll(t){if(t.ctrlKey)return;this._wheel||(this._wheel=!0,this._wheelY=0,this.userEvents.press(0,this._wheelY)),clearTimeout(this._wheelTimeout),this._wheelTimeout=setTimeout((()=>this._wheelEnd()),50);const e=(t=>{const e=t.wheelDeltaY;let i;return t.wheelDelta?(void 0===e||e)&&(i=t.wheelDelta):t.detail&&t.axis===t.VERTICAL_AXIS&&(i=10*-t.detail),i})(t);e&&(this._wheelY+=e,this.userEvents.move(0,this._wheelY)),t.preventDefault()}makeVirtual(){this.dimensions.y.makeVirtual()}virtualSize(t,e){this.dimensions.y.virtualSize(t,e)}height(){return this.dimensions.y.size}scrollHeight(){return this.scrollElement.scrollHeight}scrollWidth(){return this.scrollElement.scrollWidth}_resize(){this._native||this.contentResized()}setOptions(t){this._initOptions(t),t.pullToRefresh&&this._initPullToRefresh()}reset(){this._native?this.scrollElement.scrollTop(0):(this.movable.moveTo({x:0,y:0}),this._scale(1))}contentResized(){this.dimensions.refresh(),this.pane.x.outOfBounds()&&this.movable.moveAxis("x",this.dimensions.x.min),this.pane.y.outOfBounds()&&this.movable.moveAxis("y",this.dimensions.y.min)}zoomOut(){const t=this.dimensions;t.refresh(),this._scale(t.fitScale),this.movable.moveTo(t.centerCoordinates())}enable(){this.enabled=!0}disable(){this.enabled=!1}scrollTo(t,e){this._native?(this.scrollElement.scrollLeft(us(t)),this.scrollElement.scrollTop(us(e))):(this.dimensions.refresh(),this.movable.moveTo({x:t,y:e}))}animatedScrollTo(t,e,i){let s,n;this._native?this.scrollTo(t,e):(s={x:this.movable.x,y:this.movable.y},n={x:t,y:e},this.animatedScroller.setCoordinates(s,n),this.animatedScroller.setCallback(i),this.animatedScroller.start())}pullHandled(){}destroy(){Fi(this.element,"wheel",this._wheelScrollHandler),this.userEvents&&this.userEvents.destroy(),this.tapCapture&&this.tapCapture.destroy()}_scale(t){this.dimensions.rescale(t),this.movable.scaleTo(t)}_initPullToRefresh(){}_dragEnd(){}_paneChange(){}_initAxis(t){const e=this.movable,i=this.dimensions[t],s=this.tapCapture,n=this.pane[t],o=new ys({axis:t,movable:e,dimension:i,container:this.element,alwaysVisible:this.options.visibleScrollHints});i.bind(ps,(()=>{o.refresh()})),n.bind(ps,(()=>{o.show()})),this[t+"inertia"]=new ms({axis:t,paneAxis:n,movable:e,tapCapture:s,userEvents:this.userEvents,dimension:i,elastic:this.options.elastic,friction:this.options.friction||.96,velocityMultiplier:this.options.velocityMultiplier||10,end:()=>{o.hide(),this.trigger("scrollEnd",{axis:t,scrollTop:this.scrollTop,scrollLeft:this.scrollLeft})}})}}class xs extends gi{constructor(t){super(t);const e=this.toolService.diagram,i=e.canvas,s=e._mobileOS()?.93:.9,n=e.scroller=this.scroller=new vs(e.scrollable,{friction:s,velocityMultiplier:5,mousewheelScrolling:!1,zoom:!1,scroll:this._move.bind(this)});i.translate&&(this.movableCanvas=new Ni(i.element));const o=function(t,e,i){t.makeVirtual(),t.virtualSize(e||-2e4,i||2e4)};o(n.dimensions.x),o(n.dimensions.y),n.disable()}tryActivate(t,e){const i=this.toolService,s=i.diagram.options.pannable;let n=e.ctrlKey;return K(s.key)&&(n=s.key&&"none"!==s.key?e[s.key+"Key"]:fi(e)&&!K(i.hoveredItem)),!1!==s&&n&&!K(i.hoveredAdorner)&&!K(i._hoveredConnector)}start(){this.scroller.enable()}move(){}_move(t){const e=this.toolService.diagram,i=e.canvas;let s=new Ot(t.scrollLeft,t.scrollTop);i.translate?(e._storePan(s.times(-1)),this.movableCanvas.moveTo(s),i.translate(s.x,s.y)):s=s.plus(e._pan.times(-1)),e.trigger(P,{pan:s})}end(){this.scroller.disable()}getCursor(){return g.move}}class bs{constructor(t){this.toolService=t}tryActivate(t,e){const i=this.toolService,s=i.diagram.options.selectable;let n=s&&!1!==s.multiple;return n&&(n=s.key&&"none"!==s.key?e[s.key+"Key"]:fi(e)),n&&!K(i.hoveredItem)&&!K(i.hoveredAdorner)}start(t){const e=this.toolService.diagram;e.deselect(),e.selector.start(t)}move(t){this.toolService.diagram.selector.move(t)}end(t,e){const i=this.toolService.diagram,s=this.toolService.hoveredItem,n=i.selector.bounds();s&&s.isSelected||e.ctrlKey||i.deselect(),n.isEmpty()||i.selectArea(n),i.selector.end()}getCursor(){return g.arrow}}function Cs(t,e){return e.charCodeAt(0)===t||e.toUpperCase().charCodeAt(0)===t}class Ss{constructor(t,e,i){this.item=t,this._redoSource=e,this._redoTarget=i,K(e)&&(this._undoSource=t.source()),K(i)&&(this._undoTarget=t.target()),this.title=O}undo(){void 0!==this._undoSource&&this.item._updateConnector(this._undoSource,z),void 0!==this._undoTarget&&this.item._updateConnector(this._undoTarget,D),this.item.updateModel()}redo(){void 0!==this._redoSource&&this.item._updateConnector(this._redoSource,z),void 0!==this._redoTarget&&this.item._updateConnector(this._redoTarget,D),this.item.updateModel()}}const Ms={hover:{stroke:{}},startCap:V,endCap:V,points:[],selectable:!0,fromConnector:m,toConnector:m};class ks extends Xe{constructor(t,e,i){super(i=Ft({},Ms,i)),this.updateOptionsFromModel(),this._initRouter(),this.path=new Le(this.options),this.path.fill(h),this.visual.append(this.path),this._sourcePoint=this._targetPoint=new Ot,this._setSource(t),this._setTarget(e),this.content(this.options.content),this.definers=[],K(i)&&i.points&&this.points(i.points)}_setOptionsFromModel(t){this.updateOptionsFromModel(t||this.dataItem)}updateOptionsFromModel(t){if(this.diagram&&this.diagram._isEditable){const e=this.diagram._dataMap,i=function(t){const e={};return K((t=t||{}).text)&&null!==t.text&&(e.content=t.text),K(t.type)&&null!==t.type&&(e.type=t.type),K(t.from)&&null!==t.from&&(e.from=t.from),K(t.fromConnector)&&null!==t.fromConnector&&(e.fromConnector=t.fromConnector),K(t.fromX)&&null!==t.fromX&&(e.fromX=t.fromX),K(t.fromY)&&null!==t.fromY&&(e.fromY=t.fromY),K(t.to)&&null!==t.to&&(e.to=t.to),K(t.toConnector)&&null!==t.toConnector&&(e.toConnector=t.toConnector),K(t.toX)&&null!==t.toX&&(e.toX=t.toX),K(t.toY)&&null!==t.toY&&(e.toY=t.toY),e}(t||this.dataItem);if(t){if(K(i.from)){let t=e[i.from];t&&K(i.fromConnector)&&(t=t.getConnector(i.fromConnector)),this.source(t)}else K(i.fromX)&&K(i.fromY)&&this.source(new Ot(i.fromX,i.fromY));if(K(i.to)){let t=e[i.to];t&&K(i.toConnector)&&(t=t.getConnector(i.toConnector)),this.target(t)}else K(i.toX)&&K(i.toY)&&this.target(new Ot(i.toX,i.toY));K(i.type)&&this.type()!==i.type&&(this.points([]),this.type(i.type)),this.dataItem=t,this._template(),this.redraw(this.options)}else this.options=Ft({},i,this.options)}}updateModel(t){this.diagram&&this.diagram._isEditable&&this.diagram.updateConnectionModel(this,t)}sourcePoint(){return this._resolvedSourceConnector?this._resolvedSourceConnector.position():this._sourcePoint}_setSource(t){const e=t instanceof Je,i=this.options.fromConnector||m;let s;e&&!t.getConnector(i)||(void 0!==t&&(this.from=t),this._removeFromSourceConnector(),null===t?this.sourceConnector&&(this._sourcePoint=(this._resolvedSourceConnector||this.sourceConnector).position(),this._clearSourceConnector(),this._setFromOptions(null,this._sourcePoint)):t instanceof Ke?(s=t.shape.dataItem,s&&this._setFromOptions(s.id),this.sourceConnector=t,this.sourceConnector.connections.push(this)):t instanceof Ot?(this._setFromOptions(null,t),this._sourcePoint=t,this.sourceConnector&&this._clearSourceConnector()):e&&(s=t.dataItem,s&&this._setFromOptions(s.id),this.sourceConnector=t.getConnector(i),this.sourceConnector.connections.push(this)))}source(t,e){return q(t)&&(e&&this.diagram&&this.diagram.undoRedoService.addCompositeItem(new Ss(this,t)),this._setSource(t),this.refresh()),this.sourceConnector?this.sourceConnector:this._sourcePoint}_setFromOptions(t,e){this.options.from=t,e?(this.options.fromX=e.x,this.options.fromY=e.y):(this.options.fromX=null,this.options.fromY=null)}sourceDefiner(t){if(!t)return this._sourceDefiner||(this._sourceDefiner=new ee(this.sourcePoint(),null,null)),this._sourceDefiner;if(!(t instanceof ee))throw new Error("The sourceDefiner needs to be a PathDefiner.");t.left=null,this._sourceDefiner=t,this.source(t.point)}targetPoint(){return this._resolvedTargetConnector?this._resolvedTargetConnector.position():this._targetPoint}_setTarget(t){const e=t instanceof Je,i=this.options.toConnector||m;let s;e&&!t.getConnector(i)||(void 0!==t&&(this.to=t),this._removeFromTargetConnector(),null===t?this.targetConnector&&(this._targetPoint=(this._resolvedTargetConnector||this.targetConnector).position(),this._clearTargetConnector(),this._setToOptions(null,this._targetPoint)):t instanceof Ke?(s=t.shape.dataItem,s&&this._setToOptions(s.id),this.targetConnector=t,this.targetConnector.connections.push(this)):t instanceof Ot?(this._setToOptions(null,t),this._targetPoint=t,this.targetConnector&&this._clearTargetConnector()):e&&(s=t.dataItem,s&&this._setToOptions(s.id),this.targetConnector=t.getConnector(i),this.targetConnector.connections.push(this)))}target(t,e){return q(t)&&(e&&this.diagram&&this.diagram.undoRedoService.addCompositeItem(new Ss(this,void 0,t)),this._setTarget(t),this.refresh()),this.targetConnector?this.targetConnector:this._targetPoint}_setToOptions(t,e){this.options.to=t,e?(this.options.toX=e.x,this.options.toY=e.y):(this.options.toX=null,this.options.toY=null)}targetDefiner(t){if(!t)return this._targetDefiner||(this._targetDefiner=new ee(this.targetPoint(),null,null)),this._targetDefiner;if(!(t instanceof ee))throw new Error("The sourceDefiner needs to be a PathDefiner.");t.right=null,this._targetDefiner=t,this.target(t.point)}_updateConnectors(){this._updateConnector(this.source(),"source"),this._updateConnector(this.target(),"target")}_updateConnector(t,e){const i=this.diagram;if(t instanceof Ke&&!i.getShapeById(t.shape.id)){const s=t.shape.dataItem,n=t.options.name,o=()=>{const o=i._dataMap[s.id];t=o.getConnector(n),this[e](t,!1),this.updateModel()};if(i._dataMap[s.id])o();else{const t=i._inactiveShapeItems.getByUid(s.uid);t&&i._deferredConnectionUpdates.push(t.onActivate(o))}}else this[e](t,!1)}content(t){const e=this._content(t);return K(t)&&this._alignContent(),e}_createContentVisual(t){let e;return Y(t.visual)?e=t.visual.call(this,t):t.text&&(e=new De(t)),e&&(this._contentVisual=e,e._includeInBBox=!1,this.visual.append(e)),e}_updateContentVisual(t){Y(t.visual)?(this.visual.remove(this._contentVisual),this._createContentVisual(t)):this._contentVisual.redraw(t)}_alignContent(){if(this._contentVisual){let t=5;const i=this.allPoints();let s=Math.floor(i.length/2),n=s-1;for(;n>0&&i[n].equals(i[s]);)n--,s++;let o=i[s],r=i[n];const h=this._contentVisual._measure(),a=h.width,l=h.height;let c=i.length%2==0;const d=r.distanceTo(o);let u;if(c&&i.length>2&&d>0&&(r.y===o.y&&d<a||r.x===o.x&&d<l)&&(c=!1,t=0),c){const i=e.v(Math.atan2(o.y-r.y,o.x-r.x));u=new Ot((o.x-r.x)/2+r.x,(o.y-r.y)/2+r.y),90===Math.abs(i)?(u.x+=t,u.y-=l/2):i%180==0?(u.x-=a/2,u.y-=l+t):i<-90||0<i&&i<90?u.y-=l:(i<0||i>90)&&(u.x-=a,u.y-=l)}else{const e=Math.floor(i.length/2);u=i[e].clone(),r=i[e-1],o=i[e+1];const s=r.x<=u.x&&o.x<=u.x?t:-h.width-t,n=r.y<=u.y&&o.y<=u.y?t:-h.height-t;u.x+=s,u.y+=n}this._contentVisual.position(u)}}select(t){const e=this.diagram;let i,s;if(this._canSelect()&&this.isSelected!==t)return this.isSelected=t,i=[],s=[],this.isSelected?(this.adorner=new Ze(this,this.options.selection),e._adorn(this.adorner,!0),e._selectedItems.push(this),i.push(this)):this.adorner&&(e._adorn(this.adorner,!1),at(e._selectedItems,this),this.adorner=void 0,s.push(this)),this.adorner&&this.adorner.refresh(),e._internalSelection||e._selectionChanged(i,s),!0}bounds(t){if(!t||J(t))return this._bounds;this._bounds=t}type(t){const e=this.options;if(!t)return e.type;t!==e.type&&(e.type=t,this._initRouter(),this.refresh())}_initRouter(){const t=(this.options.type||"").toLowerCase();this._router=t===B?new ci(this):new di(this)}points(t){if(!t){const t=[];if(q(this.definers))for(let e=0;e<this.definers.length;e++)t.push(this.definers[e].point);return t}this.definers=[];for(let e=0;e<t.length;e++){const i=t[e];if(i instanceof Ot)this.definers.push(new ee(i));else{if(!Object.prototype.hasOwnProperty.call(i,"x")||!Object.prototype.hasOwnProperty.call(i,"y"))throw new Error("A Connection point needs to be a Point or an object with x and y properties.");this.definers.push(new ee(new Ot(i.x,i.y)))}}}allPoints(){const t=[this.sourcePoint()];if(this.definers)for(let e=0;e<this.definers.length;e++)t.push(this.definers[e].point);return t.push(this.targetPoint()),t}refresh(){this._resolveConnectors(),this._refreshPath(),this._alignContent(),this.adorner&&this.adorner.refresh()}_resolveConnectors(){let t,e,i,s;const n=this.source(),o=this.target();n instanceof Ot?t=n:n instanceof Ke&&(i=Ve(n)?n.shape.connectors:[n]),o instanceof Ot?e=o:o instanceof Ke&&(s=Ve(o)?o.shape.connectors:[o]),t?s&&(this._resolvedTargetConnector=He(t,s)):i&&(e?this._resolvedSourceConnector=He(e,i):s&&this._resolveAutoConnectors(i,s))}_resolveAutoConnectors(t,e){let i,s,n,o,r,h,a,l,c,d,u,p=R,g=R;for(c=0;c<t.length;c++)if(a=t[c],!Ve(a))for(n=a.position(),d=0;d<e.length;d++)l=e[d],Ve(l)||(o=l.position(),u=Math.round(n.distanceTo(o)),u<p&&this.diagram&&this._testRoutePoints(n,o,a,l)&&(p=u,i=a,s=l),u<g&&(r=a,h=l,g=u));i&&(r=i,h=s),this._resolvedSourceConnector=r,this._resolvedTargetConnector=h}_testRoutePoints(t,e,i,s){const n=this._router;let o=!0;if(n instanceof ci){const r=n.routePoints(t,e,i,s),h=this._getRouteExclude(t,e,i.shape,s.shape);let a,l,c;r.unshift(t),r.push(e);for(let t=1;t<r.length;t++)if(a=r[t-1],l=r[t],c=new Bt(Math.min(a.x,l.x),Math.min(a.y,l.y),Math.abs(a.x-l.x),Math.abs(a.y-l.y)),c.width>0&&(c.x++,c.width-=2),c.height>0&&(c.y++,c.height-=2),!c.isEmpty()&&this.diagram._shapesQuadTree.hitTestRect(c,h)){o=!1;break}}return o}_getRouteExclude(t,e,i,s){const n=[];return this._isPointInsideShape(t,i)&&n.push(i),this._isPointInsideShape(e,s)&&n.push(s),n}_isPointInsideShape(t,e){const i=e.bounds(),s=e.rotate().angle,n=i.x,o=i.y,r=t.clone().rotate(s,i.center()),h=r.x,a=r.y;return h>n&&h<n+i.width&&a>o&&a<o+i.height}redraw(t){if(t){this.options=Ft({},this.options,t);const e=this.options.points;K(e)&&e.length>0&&(this.points(e),this._refreshPath()),(t&&t.content||t.text)&&this.content(t.content),this.path.redraw({fill:t.fill,stroke:t.stroke,startCap:t.startCap,endCap:t.endCap})}}clone(){const t=this.serialize();return this.diagram&&this.diagram._isEditable&&K(this.dataItem)&&(t.options.dataItem=this.diagram.options.cloneDataItem(this.dataItem)),new ks(this.from,this.to,t.options)}serialize(){const t=this.from.toJSON?this.from.toJSON:this.from.toString(),e=this.to.toJSON?this.to.toJSON:this.to.toString(),i=Ft({},{options:this.options,from:t,to:e});return K(this.dataItem)&&(i.dataItem=this.dataItem.toString()),i.options.points=this.points(),i}_hitTest(t){if(this.visible()){const e=new Ot(t.x,t.y),i=this.sourcePoint(),s=this.targetPoint();if(t.isEmpty&&!t.isEmpty()&&t.contains(i)&&t.contains(s))return this;if(this._router.hitTest(e))return this}}_hover(t){let e=(this.options.stroke||{}).color;t&&q(this.options.hover.stroke.color)&&(e=this.options.hover.stroke.color),this.path.redraw({stroke:{color:e}})}_refreshPath(){K(this.path)&&(this._drawPath(),this.bounds(this._router.getBounds()))}_drawPath(){this._router&&this._router.route();const t=this.sourcePoint(),e=this.targetPoint(),i=this.points();this.path.redraw({points:[t].concat(i,[e])})}_clearSourceConnector(){this.sourceConnector=void 0,this._resolvedSourceConnector=void 0}_clearTargetConnector(){this.targetConnector=void 0,this._resolvedTargetConnector=void 0}_removeFromSourceConnector(){this.sourceConnector&&at(this.sourceConnector.connections,this)}_removeFromTargetConnector(){this.targetConnector&&at(this.targetConnector.connections,this)}toJSON(){let t,e,i;return this.from&&this.from.toJSON?t=this.from.toJSON():(i=this._sourcePoint,t={x:i.x,y:i.y}),this.to&&this.to.toJSON?e=this.to.toJSON():(i=this._targetPoint,e={x:i.x,y:i.y}),{from:t,to:e}}}const Ts=e.r;class Es{constructor(t){this.diagram=t,this.tools=[new xs(this),new ui(this),new pi(this),new bs(this),new mi(this)],this.activeTool=void 0}start(t,e){return e=Ft({},e),this.activeTool&&this.activeTool.end(t,e),this._updateHoveredItem(t),this._activateTool(t,e),this.activeTool.start(t,e),this._updateCursor(t),this.diagram.focus(),this.diagram.canvas.surface.suspendTracking(),this.startPoint=t,!0}move(t,e){e=Ft({},e);let i=!0;return this.activeTool&&(i=this.activeTool.move(t,e)),i&&this._updateHoveredItem(t),this._updateCursor(t),!0}end(t,e){return e=Ft({},e),this.activeTool&&this.activeTool.end(t,e),this.diagram.canvas.surface.resumeTracking(),this.activeTool=void 0,this._updateCursor(t),!0}keyDown(t,e){const i=this.diagram;if(!(e=Ft({ctrlKey:!1,metaKey:!1,altKey:!1},e)).ctrlKey&&!e.metaKey||e.altKey){if(46===t||8===t){const t=this.diagram._triggerRemove(i.select());return t.length&&(this.diagram.remove(t,!0),this.diagram._syncChanges(),this.diagram._destroyToolBar()),!0}if(27===t)return this._discardNewConnection(),i.deselect(),i._destroyToolBar(),!0}else{if(Cs(t,"a"))return i.selectAll(),i._destroyToolBar(),!0;if(Cs(t,"z"))return i.undo(),i._destroyToolBar(),!0;if(Cs(t,"y"))return i.redo(),i._destroyToolBar(),!0;Cs(t,"c")?(i.copy(),i._destroyToolBar()):Cs(t,"x")?(i.cut(),i._destroyToolBar()):Cs(t,"v")?(i.paste(),i._destroyToolBar()):Cs(t,"l")?(i.layout(),i._destroyToolBar()):Cs(t,"d")&&(i._destroyToolBar(),i.copy(),i.paste())}}wheel(t,e){const i=this.diagram;let s=i.zoom();const n=e.delta,o=i.options,r=o.zoomRate,h={point:t,meta:e,zoom:s};if(!i.trigger(E,h))return n<0?s+=r:s-=r,s=Ts(Math.max(o.zoomMin,Math.min(o.zoomMax,s)),2),h.zoom=s,i.zoom(s,h),i.trigger(L,h),!0}setTool(t,e){t.toolService=this,this.tools[e]=t}selectSingle(t,e){const i=this.diagram,s=i.options.selectable;if(s&&!t.isSelected&&!1!==t.options.selectable){const n=e.ctrlKey&&!1!==s.multiple;i.select(t,{addToSelection:n})}}_discardNewConnection(){this.newConnection&&(this.diagram.remove(this.newConnection),this.newConnection=void 0)}_activateTool(t,e){for(let i=0;i<this.tools.length;i++){const s=this.tools[i];if(s.tryActivate(t,e)){this.activeTool=s;break}}}_updateCursor(t){const e=this.diagram.element,i=this.activeTool?this.activeTool.getCursor(t):this.hoveredAdorner?this.hoveredAdorner._getCursor(t):this.hoveredItem?this.hoveredItem._getCursor(t):g.arrow;e.style.cursor=i}_connectionManipulation(t,e,i){this.activeConnection=t,this.disabledShape=e,this.newConnection=i?this.activeConnection:void 0}_updateHoveredItem(t){const e=this._hitTest(t),i=this.diagram;e===this.hoveredItem||this.disabledShape&&e===this.disabledShape||(this.hoveredItem&&(i.trigger(T,{item:this.hoveredItem}),this.hoveredItem._hover(!1)),e&&e.options.enable?(i.trigger(k,{item:e}),this.hoveredItem=e,this.hoveredItem._hover(!0)):this.hoveredItem=void 0)}_removeHover(){this.hoveredItem&&(this.hoveredItem._hover(!1),this.hoveredItem=void 0)}_hitTest(t){const e=this.diagram;let i,s,n;if(this._hoveredConnector&&(this._hoveredConnector._hover(!1),this._hoveredConnector=void 0),e._connectorsAdorner._visible&&(i=e._connectorsAdorner._hitTest(t),i))return i;if(i=this.diagram._resizingAdorner._hitTest(t),i){if(this.hoveredAdorner=e._resizingAdorner,0!==i.x||0!==i.y)return;i=void 0}else this.hoveredAdorner=void 0;if(!this.activeTool||"ConnectionTool"!==this.activeTool.type){const o=[];for(n=0;n<e._selectedItems.length;n++)s=e._selectedItems[n],s instanceof ks&&o.push(s);i=this._hitTestItems(o,t)}return i||this._hitTestElements(t)}_hitTestElements(t){const e=this.diagram,i=this._hitTestItems(e.shapes,t),s=this._hitTestItems(e.connections,t);let n;if((!this.activeTool||"ConnectionTool"!==this.activeTool.type)&&i&&s&&!function(t,e){let i,s,n;for(let o=0;o<t.connectors.length;o++)if(i=t.connectors[o],s=i.position(),n=new Bt(s.x,s.y),n.inflate(f,f),n.contains(e))return i}(i,t)){const t=e.mainLayer;n=dt(i.visual,t.children)>dt(s.visual,t.children)?i:s}return n||i||s}_hitTestItems(t,e){let i,s,n;for(i=t.length-1;i>=0;i--)if(s=t[i],n=s._hitTest(e),n)return n}}class Ls{constructor(t,e){this.connection=t,this.diagram=e,this.title="New connection"}undo(){this.diagram.remove(this.connection,!1)}redo(){this.diagram._addConnection(this.connection,!1)}}class Ps{constructor(t,e){this.shape=t,this.diagram=e,this.title="New shape"}undo(){this.diagram.deselect(),this.diagram.remove(this.shape,!1)}redo(){this.diagram._addShape(this.shape,!1)}}class Is{constructor(t){this.units=[],this.title="Composite unit",void 0!==t&&this.units.push(t)}add(t){this.units.push(t)}undo(){for(let t=0;t<this.units.length;t++)this.units[t].undo()}redo(){for(let t=0;t<this.units.length;t++)this.units[t].redo()}}class zs{constructor(t){this.connection=t,this.diagram=t.diagram,this.targetConnector=t.targetConnector,this.title="Delete connection"}undo(){this.diagram._addConnection(this.connection,!1)}redo(){this.diagram.remove(this.connection,!1)}}class Ds{constructor(t){this.shape=t,this.diagram=t.diagram,this.title="Deletion"}undo(){this.diagram._addShape(this.shape,!1),this.shape.select(!1)}redo(){this.shape.select(!1),this.diagram.remove(this.shape,!1)}}class Ns{constructor(t){this.layoutState=t,this.diagram=t.diagram}initState(){this.froms=[],this.tos=[],this.subjects=[];this.layoutState.nodeMap.forEach(((t,e)=>{const i=this.diagram.getShapeById(t);i&&(this.subjects.push(i),this.froms.push(i.bounds().topLeft()),this.tos.push(e.topLeft()))}),this)}update(t){if(!(this.subjects.length<=0))for(let e=0;e<this.subjects.length;e++)this.subjects[e].position(new Ot(this.froms[e].x+(this.tos[e].x-this.froms[e].x)*t,this.froms[e].y+(this.tos[e].y-this.froms[e].y)*t))}}class Os{constructor(t,e,i){j(i)?this.animate=!1:this.animate=Boolean(i),this._initialState=t,this._finalState=e,this.title="Diagram layout"}undo(){this.setState(this._initialState)}redo(){this.setState(this._finalState)}setState(t){const e=t.diagram;if(this.animate){t.linkMap.forEach((function(t,i){const s=e.getShapeById(t);s.visible(!1),s&&s.points(i)}));const i=new Lt;i.addAdapter(new Ns(t)),i.onComplete((function(){t.linkMap.forEach((function(t){e.getShapeById(t).visible(!0)}))})),i.play()}else t.nodeMap.forEach((function(t,i){const s=e.getShapeById(t);s&&s.position(i.topLeft())})),t.linkMap.forEach((function(t,i){const s=e.getShapeById(t);s&&s.points(i)}))}}class Bs{constructor(t,e,i){this.diagram=t,this.indices=i,this.items=e,this.title="Rotate Unit"}undo(){this.diagram._toIndex(this.items,this.indices)}redo(){this.diagram.toBack(this.items,!1)}}class Rs{constructor(t,e,i){this.diagram=t,this.indices=i,this.items=e,this.title="Rotate Unit"}undo(){this.diagram._toIndex(this.items,this.indices)}redo(){this.diagram.toFront(this.items,!1)}}class As extends kt{constructor(t={}){super(),this.events=["undone","redone"],this.bind(this.events,t),this.stack=[],this.index=0,this.capacity=100}begin(){this.composite=new Is}cancel(){this.composite=void 0}commit(t){this.composite.units.length>0&&this._restart(this.composite,t),this.composite=void 0}addCompositeItem(t){this.composite?this.composite.add(t):this.add(t)}add(t,e){this._restart(t,e)}pop(){this.index>0&&(this.stack.pop(),this.index--)}count(){return this.stack.length}undo(){this.index>0&&(this.index--,this.stack[this.index].undo(),this.trigger("undone"))}redo(){this.stack.length>0&&this.index<this.stack.length&&(this.stack[this.index].redo(),this.index++,this.trigger("redone"))}_restart(t,e){this.stack.splice(this.index,this.stack.length-this.index),this.stack.push(t),!1!==e?this.redo():this.index++,this.stack.length>this.capacity&&(this.stack.splice(0,this.stack.length-this.capacity),this.index=this.capacity)}clear(){this.stack=[],this.index=0}}class Vs{constructor(t){this.dataItem=t,this.callbacks=[]}onActivate(t){return new Promise((e=>{this.callbacks.push({callback:t,resolve:e})}))}activate(){const t=this.callbacks;let e;for(let i=0;i<t.length;i++)e=this.callbacks[i],e.callback(this.dataItem),e.resolve();this.callbacks=[]}}class Hs{constructor(){this.items={}}add(t){for(let e=0;e<t.length;e++)this.items[t[e].uid]=new Vs(t[e])}forEach(t){for(const e in this.items)Object.prototype.hasOwnProperty.call(this.items,e)&&t(this.items[e])}getByUid(t){return this.items[t]}remove(t){delete this.items[t.uid]}destroy(){this.items={}}}class Fs{constructor(){this.shapes=[]}_add(t,e){this.shapes.push({bounds:e,shape:t}),t._quadNode=this}insert(t,e){this._add(t,e)}remove(t){const e=this.shapes,i=e.length;for(let s=0;s<i;s++)if(e[s].shape===t){e.splice(s,1);break}}hitTestRect(t,e){const i=this.shapes,s=i.length;for(let n=0;n<s;n++)if(this._testRect(i[n].shape,t)&&!lt(e,i[n].shape))return!0}_testRect(t,e){const i=t.rotate().angle,s=t.bounds();let n;return n=i?Zt.rects(e,s,-i):s.overlaps(e),n}}class Us extends Fs{constructor(t){super(),this.children=[],this.rect=t}inBounds(t){const e=this.rect,i=e.bottomRight(),s=t.bottomRight();return e.x<=t.x&&e.y<=t.y&&s.x<=i.x&&s.y<=i.y}overlapsBounds(t){return this.rect.overlaps(t)}insert(t,e){let i=!1;const s=this.children,n=s.length;if(this.inBounds(e)){if(!n&&this.shapes.length<4)this._add(t,e);else{n||this._initChildren();for(let n=0;n<s.length;n++)if(s[n].insert(t,e)){i=!0;break}i||this._add(t,e)}i=!0}return i}_initChildren(){const t=this.rect,e=this.children,i=this.shapes,s=t.center(),n=t.width/2,o=t.height/2;let r,h;for(e.push(new Us(new Bt(t.x,t.y,n,o)),new Us(new Bt(s.x,t.y,n,o)),new Us(new Bt(t.x,s.y,n,o)),new Us(new Bt(s.x,s.y,n,o))),h=i.length-1;h>=0;h--)for(r=0;r<e.length;r++)if(e[r].insert(i[h].shape,i[h].bounds)){i.splice(h,1);break}}hitTestRect(t,e){let i;const s=this.children,n=s.length;let o=!1;if(this.overlapsBounds(t))if(super.hitTestRect(t,e))o=!0;else for(i=0;i<n;i++)if(s[i].hitTestRect(t,e)){o=!0;break}return o}}class Ws{constructor(t){this.ROOT_SIZE=1e3;const e=this._boundsChange.bind(this);t.bind(M,e),t.bind(S,e),this.initRoots()}initRoots(){this.rootMap={},this.root=new Fs}clear(){this.initRoots()}_boundsChange(t){t.item._quadNode&&t.item._quadNode.remove(t.item),this.insert(t.item)}insert(t){const e=t.bounds(I),i=this.ROOT_SIZE,s=this.getSectors(e),n=s[0][0],o=s[1][0];this.inRoot(s)?this.root.insert(t,e):(this.rootMap[n]||(this.rootMap[n]={}),this.rootMap[n][o]||(this.rootMap[n][o]=new Us(new Bt(n*i,o*i,i,i))),this.rootMap[n][o].insert(t,e))}remove(t){t._quadNode&&t._quadNode.remove(t)}inRoot(t){return t[0].length>1||t[1].length>1}getSectors(t){const e=this.ROOT_SIZE,i=t.bottomRight(),s=Math.floor(i.x/e),n=Math.floor(i.y/e),o=[[],[]];for(let i=Math.floor(t.x/e);i<=s;i++)o[0].push(i);for(let i=Math.floor(t.y/e);i<=n;i++)o[1].push(i);return o}hitTestRect(t,e){const i=this.getSectors(t);let s,n,o,r,h;if(this.root.hitTestRect(t,e))return!0;for(s=0;s<i[0].length;s++)for(o=i[0][s],n=0;n<i[1].length;n++)if(r=i[1][n],h=(this.rootMap[o]||{})[r],h&&h.hitTestRect(t,e))return!0;return!1}}function qs(t,e,i){let s;for(let n=0;n<i.length;n++)s=i[n],e&&!K(e[s])&&(e[s]=t[s])}const Ks={name:"Diagram",theme:"sass",layout:"",zoomRate:.1,zoom:1,zoomMin:0,zoomMax:2,dataSource:{},draggable:!0,template:"",autoBind:!0,editable:{rotate:{},resize:{},text:!0,tools:[],drag:{snap:{size:10,angle:10}},remove:!0},pannable:{},selectable:{key:"none"},tooltip:{enabled:!0,format:"{0}"},copy:{enabled:!0,offsetX:20,offsetY:20},shapeDefaults:je({undoable:!0}),connectionDefaults:{editable:{tools:[]},type:B},shapes:[],connections:[]},Ys=[L,E,P,A,S,M,p,"click",k,T,"toolBarClick","save","cancel","edit","remove","add","dataBound",x,b,C];function js(t){const e=[],i=[];let s,n;for(n=0;n<t.length;n++)s=t[n],s instanceof Je?i.push(s):e.push(s);return{shapes:i,connections:e}}function Gs(t,e=!1){let i=t.offsetHeight;if(e){const e=getComputedStyle(t);i+=parseFloat(e.marginTop)+parseFloat(e.marginBottom)}return i}t.$=Ss,t.A=we,t.B=We,t.C=ve,t.D=zt,t.E=ae,t.F=ui,t.G=jt,t.H=It,t.I=Zt,t.J=mi,t.K=xs,t.L=Yt,t.M=Qt,t.N=Kt,t.O=bs,t.P=ee,t.Q=At,t.R=function(t,e,i){if(void 0===t||void 0===e)return[];if(i&&nt(e-t)!==nt(i))throw new Error("The sign of the increment should allow to reach the stop-value.");if(t=t||0,((e=e||t)-t)/(i=i||1)==1/0)throw new Error("Infinite range defined.");const s=[];let n,o=-1;const r=function(t){let e=1;for(;t*e%1;)e*=10;return e}(Math.abs(i));if(i*=r,(t*=r)>(e*=r)&&i>0&&(i=-i),i<0)for(;(n=t+i*++o)>=e;)s.push(n/r);else for(;(n=t+i*++o)<=e;)s.push(n/r);return s},t.S=class extends kt{constructor(t){super(),this._hashTable=new It,this.length=0,q(t)&&(t instanceof It?t.forEach((function(t){this.add(t)})):t instanceof zt&&t.forEach((function(t,e){this.add({key:t,value:e})}),this))}contains(t){return this._hashTable.containsKey(t)}add(t){this._hashTable.get(t)||(this._hashTable.add(t,t),this.length++,this.trigger("changed"))}get(t){return this.contains(t)?this._hashTable.get(t).value:null}hash(t){return this._hashTable._hash(t)}remove(t){this.contains(t)&&(this._hashTable.remove(t),this.length--,this.trigger("changed"))}forEach(t,e){const i=e?t.bind(e):t;this._hashTable.forEach((function(t){i(t.value)}))}toArray(){const t=[];return this.forEach((function(e){t.push(e)})),t}},t.T=Lt,t.U=Tt,t.V=fe,t.W=ci,t.X=di,t.Y=ri,t.Z=Bs,t._=Rs,t.__meta__={id:"diagram-common.cmn.chunk",name:"DiagramCommonCmnChunk",category:"web",description:"A reusable outputed chunk of code",depends:["drawing.cmn.chunk","common.cmn.chunk"],hidden:!0,chunk:!0},t.a=te,t.a0=Os,t.a1=Qe,t.a2=Es,t.a3=oi,t.a4=si,t.a5=As,t.a6=$e,t.a7=pi,t.a8=Ze,t.a9=zs,t.aa=Ds,t.ab=Ls,t.ac=Ps,t.ad=class{constructor(t,e,i){this.initial=t,this.finalPos=e,this.diagram=i,this.title="Pan Unit"}undo(){this.diagram.pan(this.initial)}redo(){this.diagram.pan(this.finalPos)}},t.ae=ei,t.af=Is,t.ag=qt,t.ah=Wt,t.ai=Ne,t.aj=Xt,t.ak=Be,t.al=Gt,t.am=Ye,t.an=je,t.ao=K,t.ap=Je,t.aq=Ys,t.ar=ks,t.as=ft,t.at=Ks,t.au=class extends kt{constructor(t,e,i){super(),this._clipboard=[],this._connectionsDataMap={},this._dataMap={},this._inactiveShapeItems=new Hs,this._selectedItems=[],this.shapes=[],this.connections=[],this._deferredConnectionUpdates=[],this.element=t,this.options=Ft({createToolBar:xt,destroyToolBar:xt},Ks,e),this.events=Ys,this._initTheme(i),this._initElements(),this._extendLayoutOptions(this.options),this._initDefaults(e),this._interactionDefaults(),this._initCanvas(),this.mainLayer=new Me({id:"main-layer"}),this.canvas.append(this.mainLayer),this._shapesQuadTree=new Ws(this),this._pan=new Ot,this._adorners=[],this.adornerLayer=new Me({id:"adorner-layer"}),this.canvas.append(this.adornerLayer),this._createHandlers(),this._initialize(),this._resizingAdorner=new si(this,{editable:this.options.editable}),this._connectorsAdorner=new Qe(this),this._adorn(this._resizingAdorner,!0),this._adorn(this._connectorsAdorner,!0),this.selector=new oi(this),this._clipboard.length=0,this.pauseMouseHandlers=!1}_createShape(t,e){(e=Ft({},this.options.shapeDefaults,e)).dataItem=t;return new Je(e,this)}_createConnection(t,e,i){const s=Ft({},this.options.connectionDefaults);s.dataItem=t;return new ks(e||new Ot,i||new Ot,s)}_initElements(){this.element.innerHTML="",this.element.style.position="relative",this.element.setAttribute("tabindex","0"),this.element.classList.add("k-widget","k-diagram"),this.scrollable=document.createElement("div"),this.element.appendChild(this.scrollable),this.wrapper=this.element}_initDefaults(t){const e=this.options,i=e.editable,s=e.shapeDefaults,n=e.connectionDefaults,o=(t||{}).shapeDefaults;!1===i?(s.editable=!1,n.editable=!1):(qs(i,s.editable,["drag","remove","connect"]),qs(i,n.editable,["drag","remove"])),o&&o.connectors&&(e.shapeDefaults.connectors=o.connectors)}_interactionDefaults(){const t=this.options,e=t.selectable,i=t.pannable,s=this._mobileOS();e&&!K(e.multiple)&&(t.selectable=Ft({multiple:!s},t.selectable)),i&&!K(i.key)&&(t.pannable=Ft({key:s?"none":"ctrl"},t.pannable))}_initCanvas(){const t=document.createElement("div");t.classList.add("k-layer"),this.scrollable.appendChild(t);const e=this.viewport();this.canvas=new(this.options.Canvas||ve)(t,{width:e.width||600,height:e.height||600})}_createHandlers(){const t=this.element;this._wheelHandler=this._wheelHandler||this._wheel.bind(this),this._keydownHandler=this._keydownHandler||this._keydown.bind(this),this._mobileOS()&&this._mobileOS().browser.mobilesafari?t.addEventListener("mousewheel",this._wheelHandler):t.addEventListener("wheel",this._wheelHandler),t.addEventListener("keydown",this._keydownHandler),this._userEvents=new cs(this.scrollable,{multiTouch:!0,fastTap:!0,tap:this._tap.bind(this),start:this._dragStart.bind(this),move:this._drag.bind(this),end:this._dragEnd.bind(this),gesturestart:this._gestureStart.bind(this),gesturechange:this._gestureChange.bind(this),gestureend:this._gestureEnd.bind(this),doubleTap:this._doubleTap.bind(this),supportDoubleTap:!0}),this.toolService=new Es(this),this._mouseoverHandler=this._mouseoverHandler||this._mouseover.bind(this),this._mouseoutHandler=this._mouseoutHandler||this._mouseout.bind(this),this._mouseMoveHandler=this._mouseMoveHandler||this._mouseMove.bind(this),this._mouseDownHandler=this._mouseDownHandler||this._mouseDown.bind(this),this._mouseUpHandler=this._mouseUpHandler||this._mouseUp.bind(this),this.scrollable.addEventListener("mouseover",this._mouseoverHandler),this.scrollable.addEventListener("mouseout",this._mouseoutHandler),this.scrollable.addEventListener("mousemove",this._mouseMoveHandler),this.scrollable.addEventListener("mousedown",this._mouseDownHandler),this.scrollable.addEventListener("mouseup",this._mouseUpHandler),this._initResizeObserver(),this.bind(E,this._destroyToolBar.bind(this)),this.bind(P,this._destroyToolBar.bind(this))}_initResizeObserver(){const t=new ResizeObserver((t=>{t.forEach((t=>{const{width:e,height:i}=t.contentRect;t.target!==this.element||this.size&&this.size.width===e&&this.size.height===i||(this.size={width:e,height:i},this._resize(),this.trigger("resize",this.size))}))}));this._resizeObserver=t,t.observe(this.element)}_destroyResizeObserver(){this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null)}_dragStart(t){this._pauseMouseHandlers=!0;const e=this._eventPositions(t,!0);this.toolService.start(e,this._meta(t))&&(this._destroyToolBar(),t.preventDefault())}_drag(t){const e=this._eventPositions(t);this.toolService.move(e,this._meta(t))&&t.preventDefault()}_dragEnd(t){this._pauseMouseHandlers=!1;const e=this._eventPositions(t);this.toolService.end(e,this._meta(t))&&(this.options.createToolBar(),t.preventDefault())}_mouseMove(t){if(!this._pauseMouseHandlers){const e=this._eventPositions(t);this.toolService._updateHoveredItem(e),this.toolService._updateCursor(e)}}_mouseDown(){this._pauseMouseHandlers=!0}_mouseUp(){this._pauseMouseHandlers=!1}_tap(t){const e=this.toolService,s=this.options.selectable,n=this._eventPositions(t),o=this.focus();if(e._updateHoveredItem(n),e.hoveredItem){const r=e.hoveredItem;if(this.trigger("click",{item:r,point:n,meta:this._meta(t)}),s&&!1!==r.options.selectable){const e=!1!==s.multiple,n=i.m||this._meta(t).ctrlKey;r.isSelected?n?(this._destroyToolBar(),r.select(!1)):this.options.createToolBar(o):(this._destroyToolBar(),this.select(r,{addToSelection:e&&n}),this.options.createToolBar(o))}}else s&&(this._destroyToolBar(),this.deselect())}_keydown(t){this.toolService.keyDown(t.keyCode,this._meta(t))&&t.preventDefault()}_wheel(t){const e=function(t){let e=0;return t.wheelDelta?(e=-t.wheelDelta/40,e=e>0?Math.ceil(e):Math.floor(e)):t.detail&&(e=t.detail),e}(t),i=this._eventPositions(t),s=Ft(this._meta(t),{delta:e});this.toolService.wheel(i,s)&&t.preventDefault()}_meta(t){return{ctrlKey:(t=t.event||t).ctrlKey,metaKey:t.metaKey,altKey:t.altKey,shiftKey:t.shiftKey,type:t.type}}_eventPositions(t,e){let i;if(t.touch){const s=e?"startLocation":"location";i=new Ot(t.x[s],t.y[s])}else i=new Ot(t.pageX,t.pageY);return this.documentToModel(i)}_gestureStart(t){this._destroyToolBar(),this.scroller.disable();const e=this.documentToModel(new Ot(t.center.x,t.center.y)),i={point:e,zoom:this.zoom()};this.trigger(E,i)||(this._gesture=t,this._initialCenter=e)}_gestureChange(t){const e=this._gesture,i=this._initialCenter,s=this.documentToView(new Ot(t.center.x,t.center.y)),n=t.distance/e.distance;let o=this._zoom,r=!1;Math.abs(n-1)>=.05&&(this._zoom=o=this._getValidZoom(o*n),this.options.zoom=o,this._gesture=t,r=!0);const h=i.times(o),a=s.minus(h);(r||this._pan.distanceTo(a)>=5)&&(this._panTransform(a),this._updateAdorners()),t.preventDefault()}_doubleTap(t){const i=this._eventPositions(t),s=this.options,n=s.zoomRate;let o=this.zoom()+n;const r={point:i,meta:this._meta(t),zoom:o};this.trigger(E,r)||(o=e.r(Math.max(s.zoomMin,Math.min(s.zoomMax,o)),2),r.zoom=o,this.zoom(o,r),this.trigger(L,r))}_gestureEnd(){!1!==this.options.pannable&&this.scroller.enable(),this.trigger(L,{point:this._initialCenter,zoom:this.zoom()})}_resize(){const t=this.viewport();this.canvas&&this.canvas.size(t),this.scrollable&&this.toolBar&&(this.scrollable.style.height=t.height+"px")}_mouseover(t){const e=t.target._kendoNode;e&&e.srcElement._hover&&e.srcElement._hover(!0,e.srcElement)}_mouseout(t){const e=t.target._kendoNode;e&&e.srcElement._hover&&e.srcElement._hover(!1,e.srcElement)}_initTheme(t){this.options=Ft({},t,this.options),!0===this.options.editable&&(this.options.editable=(t||{}).editable)}_createOptionElements(){const t=this.options,e=t.shapes.length;e&&this._createShapes(),t.connections.length&&this._createConnections(),e&&t.layout&&this.layout(t.layout)}_createShapes(){const t=this.options.shapes;let e,i;for(i=0;i<t.length;i++)e=t[i],this.addShape(e)}_createConnections(){const t=this.options,e=t.connectionDefaults,i=t.connections;let s,n,o,r;for(r=0;r<i.length;r++)s=i[r],n=this._findConnectionTarget(s.from),o=this._findConnectionTarget(s.to),this.options.connect?this.options.connect(n,o,Ft({},e,s)):this.connect(n,o,Ft({},e,s))}_findConnectionTarget(t){const e=J(t=t||{})?t:t.shapeId||t.id;let i;return e?(i=this.getShapeById(e),t.connector&&(i=i.getConnector(t.connector))):i=new Ot(t.x||0,t.y||0),i}destroy(){super.destroy(),this._destroyResizeObserver(),this._userEvents&&this._userEvents.destroy(),this.clear(),this.element.removeEventListener("mousewheel",this._wheelHandler),this.element.removeEventListener("wheel",this._wheelHandler),this.element.removeEventListener("keydown",this._keydownHandler),this.scrollable.removeEventListener("mouseover",this._mouseoverHandler),this.scrollable.removeEventListener("mouseout",this._mouseoutHandler),this.scrollable.removeEventListener("mousemove",this._mouseMoveHandler),this.scrollable.removeEventListener("mousedown",this._mouseDownHandler),this.scrollable.removeEventListener("mouseup",this._mouseUpHandler),this.canvas.destroy(!0),this.canvas=void 0,this.destroyScroller(),this._destroyGlobalToolBar(),this._destroyToolBar(),this._inactiveShapeItems.destroy()}destroyScroller(){const t=this.scroller;t&&(t.destroy(),t.element.remove(),this.scroller=null)}save(){const t={shapes:[],connections:[]};let e,i,s;for(e=0;e<this.shapes.length;e++)s=this.shapes[e],s.options.serializable&&t.shapes.push(s.options);for(e=0;e<this.connections.length;e++)i=this.connections[e],t.connections.push(Ft({},i.options,i.toJSON()));return t}focus(){if(this.element!==this.element.ownerDocument.activeElement){const t=this.element,e=[],i=[],s=t.ownerDocument.documentElement;let n,o=t;do{o=o.parentNode,o.scrollHeight>o.clientHeight&&(e.push(o),i.push(o.scrollTop))}while(o!==s);for(t.focus({preventScroll:!0}),n=0;n<e.length;n++)e[n].scrollTop=i[n];return!0}}load(t){this.clear(),this.setOptions(t),this._createShapes(),this._createConnections()}setOptions(t){Ft(this.options,t)}clear(){this.select(!1),this.mainLayer.clear(),this._shapesQuadTree.clear(),this._initialize()}connected(t,e){for(let i=0;i<this.connections.length;i++){const s=this.connections[i];if(s.from===t&&s.to===e)return!0}return!1}addConnection(t,e){return!1!==e&&this.undoRedoService.add(new Ls(t,this),!1),t.diagram=this,t._setOptionsFromModel(),t.refresh(),this.mainLayer.append(t.visual),this.connections.push(t),this.trigger(p,{added:[t],removed:[]}),t}addShape(t,e){let i,s=this.options.shapeDefaults;if(t instanceof Je)i=t,this._parseBounds(i.bounds());else{if(t.prototype)return;s=Ft({},s,t||{}),i=new Je(s,this),this._parseBounds(i.bounds())}return!1!==e&&this.undoRedoService.add(new Ps(i,this),!1),this.shapes.push(i),i.diagram!==this&&(this._shapesQuadTree.insert(i),i.diagram=this),this.mainLayer.append(i.visual),this.trigger(p,{added:[i],removed:[]}),i}remove(t,e){const i=js(t=Array.isArray(t)?t.slice(0):[t]),s=i.shapes,n=i.connections;let o;for(K(e)||(e=!0),e&&this.undoRedoService.begin(),this._suspendModelRefresh(),o=s.length-1;o>=0;o--)this._removeItem(s[o],e,n);for(o=n.length-1;o>=0;o--)this._removeItem(n[o],e);this._resumeModelRefresh(),e&&this.undoRedoService.commit(!1),this.trigger(p,{added:[],removed:t})}_addConnection(t,e){return this.options._addConnection?this.options._addConnection(t,e):this.trigger("add",{connection:t})?void 0:(this.addConnection(t,e),t._updateConnectors(),t)}_addShape(t,e){return this.options._addShape?this.options._addShape(t,e):this.trigger("add",{shape:t})?void 0:this.addShape(t,e)}_parseBounds(t){t.x="string"==typeof t.x?parseFloat(t.x):t.x,t.y="string"==typeof t.y?parseFloat(t.y):t.y}_shouldRefresh(){return!this._suspended}_suspendModelRefresh(){this._suspended=(this._suspended||0)+1}_resumeModelRefresh(){this._suspended=Math.max((this._suspended||0)-1,0)}_triggerRemove(t){const e=[];let i,s,n;for(let o=0;o<t.length;o++)i=t[o],n=i.options.editable,s=i instanceof Je?{shape:i}:{connection:i},n&&!1!==n.remove&&!this.trigger("remove",s)&&e.push(i);return e}_addConnections(t,e){const i=t.length;for(let s=0;s<i;s++){const i=t[s];this._addConnectionDataItem(i,e)}}_addConnectionDataItem(t,e){if(!this._connectionsDataMap[t.uid]){let i=this._validateConnector(t.from);K(i)&&null!==i||(i=new Ot(t.fromX,t.fromY));let s=this._validateConnector(t.to);if(K(s)&&null!==s||(s=new Ot(t.toX,t.toY)),K(i)&&K(s)){const n=Ft({},this.options.connectionDefaults);n.dataItem=t;const o=new ks(i,s,n);this._connectionsDataMap[t.uid]=o,this.addConnection(o,e)}}}_validateConnector(t){let e;return K(t)&&null!==t&&(e=this._dataMap[t]),e}_addDataItems(t,e){let i,s,n,o;for(s=0;s<t.length;s++)i=t[s],n=this._addDataItemByUid(i),o=this._addDataItemByUid(e),o&&!this.connected(o,n)&&this.connect(o,n)}connect(t,e,i){const s=Ft({},this.options.connectionDefaults,i),n=new ks(t,e,s);return this.addConnection(n)}undo(){this.undoRedoService.undo()}redo(){this.undoRedoService.redo()}select(t,e){if(!q(t))return this._selectedItems;{const i=[];let s,n,o=[];for((e=Ft({addToSelection:!1},e)).addToSelection||this.deselect(),this._internalSelection=!0,t instanceof Array?o=t:t instanceof Xe&&(o=[t]),s=0;s<o.length;s++)n=o[s],n.select(!0)&&i.push(n);this._selectionChanged(i,[]),this._internalSelection=!1}}selectAll(){this.select(this.shapes.concat(this.connections))}selectArea(t){let e,i,s;this._internalSelection=!0;const n=[];if(t instanceof Bt)for(i=this.shapes.concat(this.connections),e=0;e<i.length;e++)s=i[e],t&&!s._hitTest(t)||!s.options.enable||s.select(!0)&&n.push(s);this._selectionChanged(n,[]),this._internalSelection=!1}deselect(t){this._internalSelection=!0;const e=[];let i,s,n=[];for(t instanceof Array?n=t:t instanceof Xe?n.push(t):q(t)||(n=this._selectedItems.slice(0)),s=0;s<n.length;s++)i=n[s],i.select(!1)&&e.push(i);this._selectionChanged([],e),this._internalSelection=!1}toFront(t,e){t||(t=this._selectedItems.slice());const i=this._getDiagramItems(t);let s;if(!K(e)||e){s=Fe(this.mainLayer,i.visuals);const e=new Rs(this,t,s);this.undoRedoService.add(e)}else this.mainLayer.toFront(i.visuals),this._fixOrdering(i,!0)}toBack(t,e){t||(t=this._selectedItems.slice());const i=this._getDiagramItems(t);let s;if(!K(e)||e){s=Fe(this.mainLayer,i.visuals);const e=new Bs(this,t,s);this.undoRedoService.add(e)}else this.mainLayer.toBack(i.visuals),this._fixOrdering(i,!1)}bringIntoView(t,e){const i=this.viewport(),s=new Rt(i);let n;if(0===i.width||0===i.height)return;"none"===(e=Ft({animate:!1,align:"center middle"},e)).align&&(e.align="center middle"),t instanceof Xe?n=t.bounds(U):Array.isArray(t)?n=this.boundingBox(t):t instanceof Bt&&(n=t.clone());const o=n.clone();n.zoom(this._zoom),(n.width>i.width||n.height>i.height)&&(this._zoom=this._getValidZoom(Math.min(i.width/o.width,i.height/o.height)),n=o.clone().zoom(this._zoom)),this._zoomMainLayer();const r=n.clone();s.align(n,e.align);const h=n.topLeft().minus(r.topLeft());this.pan(h.times(-1),e.animate)}alignShapes(t){let e,i,s;j(t)&&(t="Left");const n=this.select();if(0===n.length)return;switch(t.toLowerCase()){case"left":case"top":e=H;break;case"right":case"bottom":e=F}for(s=0;s<n.length;s++)if(i=n[s],i instanceof Je)switch(t.toLowerCase()){case"left":e=Math.min(e,i.options.x);break;case"top":e=Math.min(e,i.options.y);break;case"right":e=Math.max(e,i.options.x);break;case"bottom":e=Math.max(e,i.options.y)}const o=[],r=[];for(s=0;s<n.length;s++)if(i=n[s],i instanceof Je)switch(r.push(i),o.push(i.bounds()),t.toLowerCase()){case"left":case"right":i.position(new Ot(e,i.options.y));break;case"top":case"bottom":i.position(new Ot(i.options.x,e))}const h=new ei(r,o);this.undoRedoService.add(h,!1)}zoom(t,e){if(t){let i=e?e.point:new Ot(0,0);if(t=this._zoom=this._getValidZoom(t),!j(i)){i=new Ot(Math.round(i.x),Math.round(i.y));const e=i.times(t),s=this.modelToView(i).minus(e);this._storePan(new Ot(Math.round(s.x),Math.round(s.y)))}e&&(e.zoom=t),this._panTransform(),this.canvas.surface.hideTooltip&&this.canvas.surface.hideTooltip(),this._updateAdorners()}return this._zoom}_getPan(t){return this.canvas.translate||(t=t.plus(this._pan)),t}pan(t,e){if(!(t instanceof Ot))return this._pan.times(-1);{const i=this.scroller;t=(t=this._getPan(t)).times(-1),e?i.animatedScrollTo(t.x,t.y,(()=>{this._updateAdorners()})):(i.scrollTo(t.x,t.y),this._updateAdorners())}}viewport(){const t=this.element,e=function(t){const e=getComputedStyle(t);return t.clientWidth-parseFloat(e.paddingLeft)-parseFloat(e.paddingRight)}(t);let i=function(t){const e=getComputedStyle(t);return t.clientHeight-parseFloat(e.paddingTop)-parseFloat(e.paddingBottom)}(t);return this.toolBar&&(i-=Gs(this.toolBar.element)),new Bt(0,0,e,i)}copy(){if(this.options.copy.enabled){this._clipboard.length=0,this._copyOffset=1;for(let t=0;t<this._selectedItems.length;t++){const e=this._selectedItems[t];this._clipboard.push(e)}}}cut(){if(this.options.copy.enabled){this._clipboard.length=0,this._copyOffset=0;for(let t=0;t<this._selectedItems.length;t++){const e=this._selectedItems[t];this._clipboard.push(e)}this.remove(this._clipboard,!0)}}paste(){if(this._clipboard.length>0){let t,e,i;const s={},n=js(this._clipboard),o=n.connections,r=n.shapes,h={x:this._copyOffset*this.options.copy.offsetX,y:this._copyOffset*this.options.copy.offsetY};for(this.deselect(),i=0;i<r.length;i++)t=r[i],e=t.clone(),s[t.id]=e,e.position(new Ot(t.options.x+h.x,t.options.y+h.y)),e.diagram=this,e=this._addShape(e),e&&e.select();for(i=0;i<o.length;i++)t=o[i],e=this._addConnection(t.clone()),e&&(this._updateCopiedConnection(e,t,"source",s,h),this._updateCopiedConnection(e,t,"target",s,h),e.select(!0),e.updateModel());this._syncChanges(),this._copyOffset+=1}}_syncChanges(){this.options._syncChanges&&this.options._syncChanges()}_syncConnectionChanges(){this.options._syncConnectionChanges&&this.options._syncConnectionChanges()}_syncShapeChanges(){this.options._syncShapeChanges&&this.options._syncShapeChanges()}_updateCopiedConnection(t,e,i,s,n){let o,r,h;const a=e[i]();a instanceof Ke&&s[a.shape.id]?(h=s[a.shape.id],this.getShapeById(h.id)?t[i](h.getConnector(a.options.name)):(r=this._inactiveShapeItems.getByUid(h.dataItem.uid),r&&(o=e=>{h=this._dataMap[e.id],t[i](h.getConnector(a.options.name)),t.updateModel()},this._deferredConnectionUpdates.push(r.onActivate(o))))):t[i](new Ot(e[i+"Point"]().x+n.x,e[i+"Point"]().y+n.y))}boundingBox(t,e){let i,s=Bt.empty();const n=q(t)?this._getDiagramItems(t):{shapes:this.shapes};if(n.shapes.length>0){let t=n.shapes[0];s=t.bounds(I);for(let o=1;o<n.shapes.length;o++)t=n.shapes[o],i=t.bounds(I),!0===e&&(i.x-=t._rotationOffset.x,i.y-=t._rotationOffset.y),s=s.union(i)}return s}_containerOffset(){const t=function(t){const e=t.getBoundingClientRect(),i=t.ownerDocument,s=i.defaultView.scrollX||i.documentElement.scrollLeft||0,n=i.defaultView.scrollY||i.documentElement.scrollTop||0;return{top:e.top+n,left:e.left+s}}(this.element);return this.toolBar&&(t.top+=Gs(this.toolBar.element)),t}documentToView(t){const e=this._containerOffset();return new Ot(t.x-e.left,t.y-e.top)}viewToDocument(t){const e=this._containerOffset();return new Ot(t.x+e.left,t.y+e.top)}viewToModel(t){return this._transformWithMatrix(t,this._matrixInvert)}modelToView(t){return this._transformWithMatrix(t,this._matrix)}modelToLayer(t){return this._transformWithMatrix(t,this._layerMatrix)}layerToModel(t){return this._transformWithMatrix(t,this._layerMatrixInvert)}documentToModel(t){const e=this.documentToView(t);return this.canvas.translate||(e.x=e.x+this.scroller.scrollLeft,e.y=e.y+this.scroller.scrollTop),this.viewToModel(e)}modelToDocument(t){return this.viewToDocument(this.modelToView(t))}_transformWithMatrix(t,e){let i=t;if(t instanceof Ot)e&&(i=e.apply(t));else{const s=this._transformWithMatrix(t.topLeft(),e),n=this._transformWithMatrix(t.bottomRight(),e);i=Bt.fromPoints(s,n)}return i}layout(t){let e,i;switch(this._layouting=!0,j(t)&&(t=this.options.layout),e=j(t)||j(t.type)?"Tree":t.type,e.toLowerCase()){case"tree":i=new Be(this);break;case"layered":i=new Ne(this);break;case"forcedirected":case"force":case"spring":case"springembedder":i=new Gt(this);break;default:throw new Error("Layout algorithm '"+e+"' is not supported.")}const s=new qt(this),n=i.layout(t);if(n){const e=new Os(s,n,t?t.animate:null);this.undoRedoService.add(e)}this._layouting=!1,this._redrawConnections()}getShapeById(t){let e;return e=ft(this.shapes,(function(e){return e.visual.id===t})),e||(e=ft(this.connections,(function(e){return e.visual.id===t})),e)}getShapeByModelId(t){let e;return e=this._isEditable?this._dataMap[t]:ft(this.shapes,(function(e){return(e.dataItem||{}).id===t})),e}getShapeByModelUid(t){let e;return e=this._isEditable?ft(this.shapes,(function(e){return(e.dataItem||{}).uid===t})):this._dataMap[t],e}_extendLayoutOptions(t){t.layout&&(t.layout=Ft({},Ut,t.layout))}_selectionChanged(t,e){(t.length||e.length)&&this.trigger(A,{selected:t,deselected:e})}_getValidZoom(t){return Math.min(Math.max(t,this.options.zoomMin),this.options.zoomMax)}_panTransform(t){const e=t||this._pan;this.canvas.translate?(this.scroller.scrollTo(e.x,e.y),this._zoomMainLayer()):(this._storePan(e),this._transformMainLayer())}_finishPan(){this.trigger(P,{total:this._pan,delta:Number.NaN})}_storePan(t){this._pan=t,this._storeViewMatrix()}_zoomMainLayer(){const t=this._zoom,e=new re(0,0,t,t);e.render(this.mainLayer),this._storeLayerMatrix(e),this._storeViewMatrix()}_transformMainLayer(){const t=this._pan,e=this._zoom,i=new re(t.x,t.y,e,e);i.render(this.mainLayer),this._storeLayerMatrix(i),this._storeViewMatrix()}_storeLayerMatrix(t){this._layerMatrix=t.toMatrix(),this._layerMatrixInvert=t.invert().toMatrix()}_storeViewMatrix(){const t=this._pan,e=this._zoom,i=new re(t.x,t.y,e,e);this._matrix=i.toMatrix(),this._matrixInvert=i.invert().toMatrix()}_toIndex(t,e){const i=this._getDiagramItems(t);this.mainLayer.toIndex(i.visuals,e),this._fixOrdering(i,!1)}_fixOrdering(t,e){const i=e?this.shapes.length-1:0,s=e?this.connections.length-1:0;let n,o;for(n=0;n<t.shapes.length;n++)o=t.shapes[n],at(this.shapes,o),mt(this.shapes,o,i);for(n=0;n<t.cons.length;n++)o=t.cons[n],at(this.connections,o),mt(this.connections,o,s)}_getDiagramItems(t){let e,i=t;const s={visuals:[],shapes:[],cons:[]};for(t?Array.isArray(t)||(i=[t]):i=this._selectedItems.slice(),e=0;e<i.length;e++){const t=i[e];t instanceof Je?(s.shapes.push(t),s.visuals.push(t.visual)):t instanceof ks&&(s.cons.push(t),s.visuals.push(t.visual))}return s}_addDataItemByUid(t){if(!K(t))return;let e=this._dataMap[t.uid];if(e)return e;const i=Ft({},this.options.shapeDefaults);return i.dataItem=t,e=new Je(i,this),this.addShape(e),this._dataMap[t.uid]=e,e}_addItem(t){t instanceof Je?this.addShape(t):t instanceof ks&&this.addConnection(t)}_toolBarClick(t){this.trigger("toolBarClick",t),this._destroyToolBar()}_normalizePointZoom(t){return t.times(1/this.zoom())}_initialize(){this.shapes.length=0,this.connections.length=0,this._selectedItems.length=0,Object.keys(this._dataMap).forEach((t=>{delete this._dataMap[t]})),Object.keys(this._connectionsDataMap).forEach((t=>{delete this._connectionsDataMap[t]})),this._deferredConnectionUpdates.length=0,this.undoRedoService=new As({undone:this._syncChanges.bind(this),redone:this._syncChanges.bind(this)}),this.id=Pt()}_redrawConnections(){const t=this.connections;for(let e=0;e<t.length;e++)t[e].refresh()}_adorn(t,e){void 0!==e&&t&&(e?(this._adorners.push(t),this.adornerLayer.append(t.visual)):(at(this._adorners,t),this.adornerLayer.remove(t.visual)))}_showConnectors(t,e){e?this._connectorsAdorner.show(t):this._connectorsAdorner.destroy()}_updateAdorners(){const t=this._adorners;for(let e=0;e<t.length;e++){const i=t[e];i.refreshBounds&&i.refreshBounds(),i.refresh()}}_refresh(){for(let t=0;t<this.connections.length;t++)this.connections[t].refresh()}_removeItem(t,e,i){t.select(!1),t instanceof Je?(this._removeShapeDataItem(t),this._removeShape(t,e,i)):t instanceof ks&&(this._removeConnectionDataItem(t),this._removeConnection(t,e)),this.mainLayer.remove(t.visual)}_removeConnectionDataItem(t){this._isEditable&&(this.options._removeConnectionDataItem(t.dataItem),delete this._connectionsDataMap[t.dataItem.uid])}_removeShapeDataItem(t){this._isEditable&&(this.options._removeShapeDataItem(t.dataItem),delete this._dataMap[t.dataItem.id])}_removeShape(t,e,i){let s,n,o;const r=[],h=[];for(this.toolService._removeHover(),e&&this.undoRedoService.addCompositeItem(new Ds(t)),at(this.shapes,t),this._shapesQuadTree.remove(t),s=0;s<t.connectors.length;s++){o=t.connectors[s];for(let t=0;t<o.connections.length;t++)n=o.connections[t],i&<(i,n)||(n.sourceConnector===o?r.push(n):n.targetConnector===o&&h.push(n))}for(s=0;s<r.length;s++)r[s].source(null,e),r[s].updateModel();for(s=0;s<h.length;s++)h[s].target(null,e),h[s].updateModel()}_removeConnection(t,e){t.sourceConnector&&at(t.sourceConnector.connections,t),t.targetConnector&&at(t.targetConnector.connections,t),e&&this.undoRedoService.addCompositeItem(new zs(t)),at(this.connections,t)}_removeShapeConnections(t){const e=t.connections();let i;if(e)for(i=0;i<e.length;i++)this._removeItem(e[i],!1)}_destroyToolBar(){this.options.destroyToolBar()}_destroyGlobalToolBar(){this.toolBar&&(this.toolBar=null)}_mobileOS(){return i.m}exportDOMVisual(){const t=this.canvas._viewBox,i=e.t().translate(-t.x,-t.y),s=new e.R([0,0],[t.width,t.height]),n=e.b.fromRect(s),o=new e.G({transform:i}),r=new e.G({clip:n}),h=this.canvas.drawingElement.children[0];return r.append(o),o.children.push(h),r}exportVisual(){const t=1/this._zoom,i=e.t().scale(t,t),s=new e.G({transform:i}),n=this.mainLayer.drawingElement;return s.children.push(n),s}updateConnectionModel(t,e){if(this.options.updateConnectionModel)return this.options.updateConnectionModel(t,e)}updateShapeModel(t,e){if(this.options.updateShapeModel)return this.options.updateShapeModel(t,e)}},t.av=Ws,t.aw=Fs,t.ax=Us,t.ay=Ke,t.b=Rt,t.c=ie,t.d=Bt,t.e=Dt,t.f=Ot,t.g=ke,t.h=De,t.i=re,t.j=Le,t.k=Se,t.l=_e,t.m=class extends fe{constructor(t){super(t),this._capMap=Te._capMap,this.container=new e.G,this._getPath=Te._getPath.bind(this),this._normalizeMarkerOptions=Te._normalizeMarkerOptions.bind(this),this._removeMarker=Te._removeMarker.bind(this),this._createMarkers=Te._createMarkers.bind(this),this._createMarker=Te._createMarker.bind(this),this._positionMarker=Te._positionMarker.bind(this),this._redrawMarker=Te._redrawMarker.bind(this),this._redrawMarkers=Te._redrawMarkers.bind(this),this._initPath(),this._createMarkers()}drawingContainer(){return this.container}redraw(t){if(t){const e=(t=t||{}).from,i=t.to;e&&(this.options.from=e),i&&(this.options.to=i),e||i?(this._drawPath(),this._redrawMarkers(!0,t)):this._redrawMarkers(!1,t),super.redraw(t)}}_initPath(){const t=this.options,i=this.drawingElement=new e.b({stroke:t.stroke});this._fill(),this._drawPath(),this.container.append(i)}_drawPath(){const t=this.options,e=this.drawingElement,i=t.from||new Ot,s=t.to||new Ot;e.segments.elements([ue(i.x,i.y),ue(s.x,s.y)])}},t.n=function(t,e){let i,s,n;do{i=2*Math.random()-1,s=2*Math.random()-1,n=i*i+s*s}while(!n||n>1);return t+e*i*Math.sqrt(-2*Math.log(n)/n)},t.o=class extends Me{constructor(t,i){super(i),this.drawingElement=new e.k(pe(t),i),this._initSize()}rect(t){if(t)this.drawingElement.rect(pe(t));else{const t=this.drawingElement.rect();if(t)return new Bt(t.origin.x,t.origin.y,t.size.width,t.size.height)}}reflow(){this.drawingElement.reflow()}redraw(t){Ft(this.drawingElement.options,t),super.redraw.call(this,t)}},t.p=Ee,t.q=Pe,t.r=Pt,t.s=Me,t.t=be,t.u=se,t.v=oe,t.w=ne,t.x=c,t.y=he,t.z=g}));
//# sourceMappingURL=kendo.diagram-common.cmn.chunk.min.js.map