/* * GoJS v3.0.26 JavaScript Library for HTML Diagrams, https://gojs.net * GoJS and Northwoods Software are registered trademarks of Northwoods Software Corporation, https://nwoods.com. * Copyright 1998-2025 by Northwoods Software Corporation. All Rights Reserved. * THIS SOFTWARE IS LICENSED. THE LICENSE AGREEMENT IS AT: https://gojs.net/3.0.26/license.html. * DO NOT MODIFY THIS FILE. DO NOT DISTRIBUTE A MODIFIED COPY OF THE CONTENTS OF THIS FILE. */ (function() {const root=typeof globalThis=="object"&&globalThis||typeof global=="object"&&global.global===global&&global||typeof self=="object"&&self.self===self&&self||{};root.requestAnimationFrame===void 0&&(root.setImmediate===void 0?root.requestAnimationFrame=y=>root.setTimeout(y,0):root.requestAnimationFrame=root.setImmediate);class U{static tr=root.navigator!==void 0&&root.navigator.platform!==void 0&&root.navigator.platform.match(/(iPhone|iPod|iPad|Mac)/i)!==null;static Rk(t,i,e){let s=-1;return function(){const n=this,o=arguments;s!==-1&&U.Tg(s),s=U.ir(()=>{s=-1,e||t.apply(n,o)},i),e&&!s&&t.apply(n,o)}}static ir(t,i){return root.setTimeout(t,i)}static Tg(t){root.clearTimeout(t)}static hs(t){return root.document.createElement(t)}static o(t){throw new Error(t)}static L(t,i){let e="The object is frozen, so its properties cannot be set: "+t.toString();i!==void 0&&(e+=" to value: "+i),U.o(e)}static dE(t,i,e,s){}static s(t,i,e,s){}static gE(t,i,e){}static ec(t,i,e){if(t===null||typeof t!="object"){let s=U.fC(i);e!==void 0&&(s+="."+e),U.Zi(t,"object",s)}}static k(t,i,e){U.s(t,"function",i,e)}static mE(t,i,e){}static Zi(t,i,e,s){}static W(t,i,e,s){let n=U.fC(e);s!==void 0&&(n+="."+s),U.o(n+" is not in the range "+i+": "+t)}static Re(t){}static er(t,i){}static ni(t){root.console&&root.console.log(t)}static G(t){return t!==null&&typeof t=="object"}static it(t){return typeof t=="function"}static vk=[];static et(){const t=U.vk.pop();return t===void 0?[]:t}static J(t){t.length=0,U.vk.push(t)}static pE=Object.freeze([]);static fC(t){return t===null?"*":typeof t=="string"?t:U.it(t)?t.name:""}static Dn(t){return U.it(t)?t.className?t.className:t.name:U.G(t)&&t.constructor?U.Dn(t.constructor):typeof t}static Uh(t,i){return i==null||i===""?null:U.G(t)&&i in t||t[i]?t[i]:null}static toString(t){let i=t;return U.G(t)&&(t.text?i=t.text:t.name?i=t.name:t.key!==void 0?i=t.key:t.id!==void 0?i=t.id:t.constructor===Object&&(t.Text?i=t.Text:t.Name?i=t.Name:t.Key!==void 0?i=t.Key:t.Id!==void 0?i=t.Id:t.ID!==void 0&&(i=t.ID))),i===void 0?"undefined":i===null?"null":i.toString()}static gw(t,i){if(t.hasOwnProperty(i))return!0;let e=Object.getPrototypeOf(t);for(;e&&e!==Function;){if(e.hasOwnProperty(i))return!0;const s=e.yE;if(s&&s[i])return!0;e=Object.getPrototypeOf(e)}return!1}static WD(t){const i=[];let e=0;for(e=0;e<256;e++)i[e]=e;let s=0,n=0;for(e=0;e<256;e++)s=(s+i[e]+119)%256,n=i[e],i[e]=i[s],i[s]=n;e=0,s=0;let o="";for(let r=0;r>4)+i.charAt(r&15)]=String.fromCharCode(r);t.length%2&&(t="0"+t);const s=[];let n=0;for(let r=0;r0){const n=i[0];return this.key=0,this.value=n,n}else return null}any(t){const i=this.qt;i.sr=null;const e=i.nt;this.At=-1;const s=i.r,n=s.length,o=this.Ds;for(let r=0;r=0?(this.key=i,this.value=t.r[i],!0):(this.ul(),!1)}hasNext(){return this.next()}first(){const t=this.qt;this.Gt=t.nt;const i=t.r,e=i.length-1;if(this.At=e,e>=0){const s=i[e];return this.key=e,this.value=s,s}else return null}any(t){const i=this.qt;i.nr=null;const e=i.nt,s=i.r,n=s.length;this.At=n;for(let o=n-1;o>=0;o--){const r=s[o];if(t(r))return!0;i.nt!==e&&U.Re(i)}return!1}all(t){const i=this.qt;i.nr=null;const e=i.nt,s=i.r,n=s.length;this.At=n;for(let o=n-1;o>=0;o--){const r=s[o];if(!t(r))return!1;i.nt!==e&&U.Re(i)}return!0}each(t){const i=this.qt;i.nr=null;const e=i.nt,s=i.r,n=s.length;this.At=n;for(let o=n-1;o>=0;o--){const r=s[o];t(r),i.nt!==e&&U.Re(i)}return this}map(t){const i=this.qt;i.nr=null;const e=i.nt,s=[],n=i.r,o=n.length;this.At=o;for(let l=o-1;l>=0;l--){const h=n[l];s.push(t(h)),i.nt!==e&&U.Re(i)}const r=new List;return r.r=s,r.ve(),r.iterator}filter(t){const i=this.qt;i.nr=null;const e=i.nt,s=[],n=i.r,o=n.length;this.At=o;for(let l=o-1;l>=0;l--){const h=n[l];t(h)&&s.push(h),i.nt!==e&&U.Re(i)}const r=new List;return r.r=s,r.ve(),r.iterator}get count(){return this.qt.r.length}ul(){this.key=-1,this.value=null,this.Gt=-1,this.qt.nr=this}toString(){return"ListIteratorBackwards("+this.At+"/"+this.qt.count+")"}}class List{h;r;nt;sr;nr;constructor(t){GSet.Ki(this),this.h=!1,this.r=[],this.nt=0,this.sr=null,this.nr=null,t!==void 0&&this.addAll(t)}[Symbol.iterator](){return this.r.values()}ve(){let t=this.nt;t++,t>999999999&&(t=0),this.nt=t}u(){return this.h=!0,this}Pt(){return this.h=!1,this}toString(){return"List()#"+GSet.as(this)}add(t){return this.h&&U.L(this,t),this.r.push(t),this.ve(),this}push(t){this.add(t)}addAll(t){if(t===null)return this;this.h&&U.L(this);const i=this.r;if(Array.isArray(t)){const e=t.length;for(let s=0;s=i.length)&&U.W(t,"0 <= i < length",List,"elt:i"),i[t]}get(t){return this.elt(t)}setElt(t,i){const e=this.r;(t<0||t>=e.length)&&U.W(t,"0 <= i < length",List,"setElt:i"),this.h&&U.L(this,t),e[t]=i}set(t,i){this.setElt(t,i)}first(){const t=this.r;return t.length===0?null:t[0]}last(){const t=this.r,i=t.length;return i>0?t[i-1]:null}pop(){this.h&&U.L(this);const t=this.r;return t.length>0?t.pop():null}any(t){const i=this.r,e=this.nt,s=i.length;for(let n=0;n= 0",List,"insertAt:i"),this.h&&U.L(this,t);const e=this.r;t>=e.length?e.push(i):e.splice(t,0,i),this.ve()}remove(t){return this.delete(t)}delete(t){if(t===null)return!1;this.h&&U.L(this,t);const i=this.r,e=i.indexOf(t);return e===-1?!1:(e===i.length-1?i.pop():i.splice(e,1),this.ve(),!0)}removeAt(t){const i=this.r;(t<0||t>=i.length)&&U.W(t,"0 <= i < length",List,"removeAt:i"),this.h&&U.L(this,t),t===i.length-1?i.pop():i.splice(t,1),this.ve()}removeRange(t,i){const e=this.r,s=e.length;if(t<0)t=0;else if(t>=s)return this;if(i<0)return this;if(i>=s&&(i=s-1),t>i)return this;this.h&&U.L(this);let n=t,o=i+1;for(;o0&&(t.r=Array.prototype.slice.call(i)),t}toArray(){const t=this.r,i=this.count,e=new Array(i);for(let s=0;s=n-1)&&U.W(i,"0 <= from < length",List,"sortRange:from"),o===2){const r=s[i],l=s[i+1];return t(r,l)>0&&(s[i]=l,s[i+1]=r,this.ve()),this}if(i===0)if(e>=n)s.sort(t);else{const r=s.slice(0,e);r.sort(t);for(let l=0;l=n){const r=s.slice(i);r.sort(t);for(let l=i;li.add(t(e))),i.iterator}filter(t){const i=new List;return this.wo.g.forEach(e=>{t(e)&&i.add(e)}),i.iterator}get count(){return this.wo.count}ul(){this.key=null,this.value=null,this.ii=null}toString(){return"SetIterator"}}class GSet{h;g;constructor(t){this.h=!1,this.g=new Set,t!==void 0&&this.addAll(t)}[Symbol.iterator](){return this.g.values()}values(){return this.g.values()}u(){return this.h=!0,this}Pt(){return this.h=!1,this}toString(){return"Set()#"+GSet.as(this)}add(t){return t===null?this:(this.g.add(t),this)}addAll(t){if(t===null)return this;if(Array.isArray(t)){const i=t.length;for(let e=0;et.add(i)),t}toArray(){return Array.from(this.g)}toList(){const t=new List;return this.g.forEach(i=>t.add(i)),t}get count(){return this.g.size}get size(){return this.g.size}get iterator(){return this.g.size<=0?EmptyIterator.instance:new SetIterator(this)}entries(){return this.g.entries()}keys(){return this.g.keys()}forEach(t,i){return this.g.forEach(t,i)}static pw=1;static Ki(t){t.__gohashid=GSet.pw++}static as(t){return t.__gohashid}}class MapKeySetIterator{q;ii;constructor(t){this.q=t,this.ii=t.g.keys()}[Symbol.iterator](){return this.q.g.keys()}key;value;get iterator(){return this}reset(){const t=this.q;this.ii=t.g.keys()}next(){const t=this.ii.next();return this.value=t.value,this.key=t.value,!t.done}hasNext(){return this.next()}first(){return this.q.g.size===0?null:(this.ii=this.q.g.keys(),this.ii.next().value)}any(t){for(const i of this.q.g)if(t(i[0]))return!0;return!1}all(t){for(const i of this.q.g)if(!t(i[0]))return!1;return!0}each(t){for(const i of this.q.g)t(i[0]);return this}map(t){const i=this.q,e=new List;for(const s of i.g)e.add(t(s[0]));return e.iterator}filter(t){const i=this.q,e=new List;for(const s of i.g){const n=s[0];t(n)&&e.add(n)}return e.iterator}get count(){return this.q.size}ul(){this.key=null,this.value=null,this.ii=null}toString(){return"MapKeySetIterator"}}class MapKeySet extends GSet{q;constructor(t){super(),GSet.Ki(this),this.h=!0,this.q=t}[Symbol.iterator](){return this.g.keys()}values(){return this.g.keys()}u(){return this}Pt(){return this}toString(){return"MapKeySet("+this.q.toString()+")"}add(t){U.o("This Set is read-only: "+this.toString())}has(t){return this.q.has(t)}contains(t){return this.has(t)}delete(t){U.o("This Set is read-only: "+this.toString())}remove(t){return this.delete(t)}clear(){U.o("This Set is read-only: "+this.toString())}first(){return this.q.g.size===0?null:this.q.g.keys().next().value}any(t){for(const i of this.q.g)if(t(i[0]))return!0;return!1}all(t){for(const i of this.q.g)if(!t(i[0]))return!1;return!0}each(t){for(const i of this.q.g)t(i[0]);return this}map(t){const i=new GSet;for(const e of this.q.g)i.add(t(e[0]));return i}filter(t){const i=new GSet;for(const e of this.q.g){const s=e[0];t(s)&&i.add(s)}return i}copy(){return new MapKeySet(this.q)}toSet(){const t=new GSet,i=this.q.g;for(const e of i)t.add(e[0]);return t}toArray(){const t=this.q.g,i=new Array(t.size);let e=0;for(const s of t)i[e]=s[0],e++;return i}toList(){const t=new List,i=this.q.g;for(const e of i)t.add(e[0]);return t}get count(){return this.q.size}get size(){return this.q.size}get iterator(){return this.q.size<=0?EmptyIterator.instance:new MapKeySetIterator(this.q)}}class MapValueSetIterator{q;ii;constructor(t){this.q=t,this.ii=t.g.values()}[Symbol.iterator](){return this.q.g.values()}key;value;get iterator(){return this}reset(){const t=this.q;this.ii=t.g.values()}next(){const t=this.ii.next();return this.value=t.value,this.key=t.value,!t.done}hasNext(){return this.next()}first(){return this.q.g.size===0?null:(this.ii=this.q.g.values(),this.ii.next().value)}any(t){for(const i of this.q.g)if(t(i[1]))return!0;return!1}all(t){for(const i of this.q.g)if(!t(i[1]))return!1;return!0}each(t){for(const i of this.q.g)t(i[1]);return this}map(t){const i=this.q,e=new List;for(const s of i.g)e.add(t(s[1]));return e.iterator}filter(t){const i=this.q,e=new List;for(const s of i.g){const n=s[1];t(n)&&e.add(n)}return e.iterator}get count(){return this.q.size}ul(){this.key=null,this.value=null,this.ii=null}toString(){return"MapValueSetIterator"}}class KeyValuePair{constructor(t,i){this.key=t,this.value=i}toString(){return"{"+this.key+":"+this.value+"}"}key;value}class MapIterator{q;ii;constructor(t){this.q=t,this.ii=t.g.entries()}[Symbol.iterator](){return this.q.g.entries()}key;value;get iterator(){return this}reset(){const t=this.q;this.ii=t.g.entries()}next(){const t=this.ii.next();return t.done?(this.key=null,this.value=null,!1):(this.key=t.value[0],this.value=t.value[1],!0)}hasNext(){return this.next()}first(){if(this.q.g.size===0)return null;this.ii=this.q.g.entries();const t=this.ii.next().value;return this.key=t[0],this.value=t[1],new KeyValuePair(t[0],t[1])}any(t){return this.q.any(t)}all(t){return this.q.all(t)}each(t){return this.q.each(t),this}map(t){const i=new List;let e=null;return this.q.g.forEach((s,n)=>{e===null?e=new KeyValuePair(n,s):(e.key=n,e.value=s),i.add(t(e))}),i.iterator}filter(t){const i=new List;let e=null;return this.q.g.forEach((s,n)=>{e===null?e=new KeyValuePair(n,s):(e.key=n,e.value=s),t(e)&&(i.add(e),e=null)}),i.iterator}get count(){return this.q.size}ul(){this.key=null,this.value=null,this.ii=null}toString(){return"MapIterator"}}class GMap{h;g;constructor(t){GSet.Ki(this),this.h=!1,this.g=new Map,t!==void 0&&this.addAll(t)}[Symbol.iterator](){return this.g.entries()}entries(){return this.g.entries()}u(){return this.h=!0,this}Pt(){return this.h=!1,this}toString(){return"Map()#"+GSet.as(this)}set(t,i){return this.h&&U.L(this,t),this.g.set(t,i),this}add(t,i){return this.set(t,i)}addAll(t){if(t===null)return this;if(this.h&&U.L(this),Array.isArray(t)){const i=t.length;for(let e=0;ei.x.toFixed(t)+" "+i.y.toFixed(t)}toString(){return"Point("+this.x+","+this.y+")"}equals(t){return t instanceof Point?this.px===t.x&&this.py===t.y:!1}equalTo(t,i){return this.px===t&&this.py===i}equalsApprox(t){return Geo.f(this.px,t.x)&&Geo.f(this.py,t.y)}add(t){return this.px+=t.x,this.py+=t.y,this}subtract(t){return this.px-=t.x,this.py-=t.y,this}offset(t,i){return this.px+=t,this.py+=i,this}rotate(t){if(t===0)return this;const i=this.px,e=this.py;if(i===0&&e===0)return this;let s=0,n=0;if(t>=360?t-=360:t<0&&(t+=360),t===90)s=0,n=1;else if(t===180)s=-1,n=0;else if(t===270)s=0,n=-1;else{const o=t*Math.PI/180;s=Math.cos(o),n=Math.sin(o)}return this.px=s*i-n*e,this.py=n*i+s*e,this}scale(t,i){return this.px*=t,this.py*=i,this}distanceSquaredPoint(t){const i=t.x-this.px,e=t.y-this.py;return i*i+e*e}distanceSquared(t,i){const e=t-this.px,s=i-this.py;return e*e+s*s}normalize(){const t=this.px,i=this.py,e=Math.sqrt(t*t+i*i);return e>0&&(this.px=t/e,this.py=i/e),this}directionPoint(t){return this.dC(t.x-this.px,t.y-this.py)}direction(t,i){return this.dC(t-this.px,i-this.py)}dC(t,i){if(t===0)return i>0?90:i<0?270:0;if(i===0)return t>0?0:180;{if(isNaN(t)||isNaN(i))return 0;let e=Math.atan(Math.abs(i/t))*180/Math.PI;return t<0?i<0?e+=180:e=180-e:i<0&&(e=360-e),e}}static compareWithLineSegment(t,i,e,s,n,o){return Geo.eu(t,i,e,s,n,o)}compareWithLineSegmentPoint(t,i){return Geo.eu(t.x,t.y,i.x,i.y,this.x,this.y)}static intersectingLineSegments(t,i,e,s,n,o,r,l){return Geo.su(t,i,e,s,n,o,r,l)}projectOntoLineSegment(t,i,e,s){return Geo.dl(t,i,e,s,this.px,this.py,this),this}projectOntoLineSegmentPoint(t,i){return Geo.dl(t.x,t.y,i.x,i.y,this.px,this.py,this),this}snapToGrid(t,i,e,s){return Geo.Dg(this.px,this.py,t,i,e,s,this),this}snapToGridPoint(t,i){return Geo.Dg(this.px,this.py,t.x,t.y,i.width,i.height,this),this}setRectSpot(t,i){return this.px=t.x+i.x*t.width+i.offsetX,this.py=t.y+i.y*t.height+i.offsetY,this}setSpot(t,i,e,s,n){return this.px=t+n.x*e+n.offsetX,this.py=i+n.y*s+n.offsetY,this}T(t){return t.gt(this),this}Oe(t){return t.$e(this),this}static distanceLineSegmentSquared(t,i,e,s,n,o){let r=n-e,l=o-s;const h=r*r+l*l,c=e-t,a=s-i,f=-c*r-a*l;if(f<=0||f>=h)return r=n-t,l=o-i,Math.min(c*c+a*a,r*r+l*l);{const u=r*a-l*c;return u*u/h}}static distanceSquared(t,i,e,s){const n=e-t,o=s-i;return n*n+o*o}static direction(t,i,e,s){const n=e-t,o=s-i;if(n===0)return o>0?90:o<0?270:0;if(o===0)return n>0?0:180;{if(isNaN(n)||isNaN(o))return 0;let r=Math.atan(Math.abs(o/n))*180/Math.PI;return n<0?o<0?r+=180:r=180-r:o<0&&(r=360-r),r}}get x(){return this.px}set x(t){this.px=t}get y(){return this.py}set y(t){this.py=t}isReal(){return isFinite(this.x)&&isFinite(this.y)}static xo=new Point(0,0).$();static gC=new Point(-1/0,-1/0).$();static mC=new Point(1/0,1/0).$();static pC=new Point(6,6).$();static Ik=new Point(NaN,NaN).$();static Ek=[];static l(){const t=Point.Ek.pop();return t===void 0?new Point:t}static V(t,i){const e=Point.Ek.pop();return e===void 0?new Point(t,i):(e.x=t,e.y=i,e)}static e(t){Point.Ek.push(t)}}class Size{sw;sh;h;constructor(t,i){t===void 0?(this.sw=0,this.sh=0):typeof t=="number"&&(t>=0||isNaN(t))&&typeof i=="number"&&(i>=0||isNaN(i))?(this.sw=t,this.sh=i):U.o("Invalid arguments to Size constructor: "+t+", "+i),this.h=!1}a(t){return this.sw=t.sw,this.sh=t.sh,this}i(t,i){return this.sw=t,this.sh=i,this}setTo(t,i){return this.sw=t,this.sh=i,this}set(t){return this.sw=t.sw,this.sh=t.sh,this}copy(){const t=new Size;return t.sw=this.sw,t.sh=this.sh,t}$(){return this.h=!0,Object.freeze(this),this}P(){return this.h||Object.isFrozen(this)?this:this.copy().u()}u(){return this.h||(this.h=!0),this}Pt(){return this.h&&(Object.isFrozen(this)&&U.o("cannot thaw constant: "+this),this.h=!1),this}yw(t){}static parse(t){if(typeof t=="string"){const i=t.split(" ");let e=0,s=0;for(;i[e]==="";)e++;let n=i[e++];n&&(s=parseFloat(n));let o=0;for(;i[e]==="";)e++;return n=i[e++],n&&(o=parseFloat(n)),new Size(s,o)}else return new Size}static stringify(t){return t.width.toString()+" "+t.height.toString()}static stringifyFixed(t){return U.s(t,"number",Size,"stringifyFixed:digits"),i=>i.width.toFixed(t)+" "+i.height.toFixed(t)}toString(){return"Size("+this.width+","+this.height+")"}equals(t){return t instanceof Size?this.sw===t.width&&this.sh===t.height:!1}equalTo(t,i){return this.sw===t&&this.sh===i}equalsApprox(t){return Geo.f(this.sw,t.width)&&Geo.f(this.sh,t.height)}inflate(t,i){const e=this.width+t;this.sw=e>=0?e:0;const s=this.height+i;return this.sh=s>=0?s:0,this}get width(){return this.sw}set width(t){t<0&&U.W(t,">= 0",Size,"width"),this.sw=t}get height(){return this.sh}set height(t){t<0&&U.W(t,">= 0",Size,"height"),this.sh=t}isReal(){return isFinite(this.width)&&isFinite(this.height)}static sc=new Size(0,0).$();static Uk=new Size(1,1).$();static yC=new Size(6,6).$();static nu=new Size(8,8).$();static wC=new Size(10,10).$();static Bk=new Size(1/0,1/0).$();static ww=new Size(NaN,NaN).$();static xC=[];static l(){const t=Size.xC.pop();return t===void 0?new Size:t}static e(t){Size.xC.push(t)}}class Rect{rx;ry;rw;rh;h;constructor(t,i,e,s){if(t===void 0)this.rx=0,this.ry=0,this.rw=0,this.rh=0;else if(typeof t=="number"&&typeof i=="number"&&typeof e=="number"&&(e>=0||isNaN(e))&&typeof s=="number"&&(s>=0||isNaN(s)))this.rx=t,this.ry=i,this.rw=e,this.rh=s;else if(t instanceof Point){const n=t.x,o=t.y;if(i instanceof Point){const r=i.x,l=i.y;this.rx=Math.min(n,r),this.ry=Math.min(o,l),this.rw=Math.abs(n-r),this.rh=Math.abs(o-l)}else i instanceof Size?(this.rx=n,this.ry=o,this.rw=i.width,this.rh=i.height):U.o("Incorrect second argument supplied to Rect constructor "+i)}else U.o("Invalid arguments to Rect constructor: "+t+", "+i+", "+e+", "+s);this.h=!1}a(t){return this.rx=t.rx,this.ry=t.ry,this.rw=t.rw,this.rh=t.rh,this}i(t,i,e,s){return this.rx=t,this.ry=i,this.rw=e,this.rh=s,this}Fn(t,i){return this.rw=t,this.rh=i,this}setTo(t,i,e,s){return this.rx=t,this.ry=i,this.rw=e,this.rh=s,this}set(t){return this.rx=t.rx,this.ry=t.ry,this.rw=t.rw,this.rh=t.rh,this}setPoint(t){return this.rx=t.x,this.ry=t.y,this}setSize(t){return this.rw=t.width,this.rh=t.height,this}copy(){const t=new Rect;return t.rx=this.rx,t.ry=this.ry,t.rw=this.rw,t.rh=this.rh,t}$(){return this.h=!0,Object.freeze(this),this}P(){return this.h||Object.isFrozen(this)?this:this.copy().u()}u(){return this.h||(this.h=!0),this}Pt(){return this.h&&(Object.isFrozen(this)&&U.o("cannot thaw constant: "+this),this.h=!1),this}yw(t){}static parse(t){if(typeof t=="string"){const i=t.split(" ");let e=0,s=0;for(;i[e]==="";)e++;let n=i[e++];n&&(s=parseFloat(n));let o=0;for(;i[e]==="";)e++;n=i[e++],n&&(o=parseFloat(n));let r=0;for(;i[e]==="";)e++;n=i[e++],n&&(r=parseFloat(n));let l=0;for(;i[e]==="";)e++;return n=i[e++],n&&(l=parseFloat(n)),new Rect(s,o,r,l)}else return new Rect}static stringify(t){return t.x.toString()+" "+t.y.toString()+" "+t.width.toString()+" "+t.height.toString()}static stringifyFixed(t){return U.s(t,"number",Rect,"stringifyFixed:digits"),i=>i.x.toFixed(t)+" "+i.y.toFixed(t)+" "+i.width.toFixed(t)+" "+i.height.toFixed(t)}toString(){return"Rect("+this.x+","+this.y+","+this.width+","+this.height+")"}equals(t){return t instanceof Rect?this.rx===t.x&&this.ry===t.y&&this.rw===t.width&&this.rh===t.height:!1}equalTo(t,i,e,s){return this.rx===t&&this.ry===i&&this.rw===e&&this.rh===s}equalsApprox(t){return Geo.f(this.rx,t.x)&&Geo.f(this.ry,t.y)&&Geo.f(this.rw,t.width)&&Geo.f(this.rh,t.height)}equalsApproxTo(t,i,e,s){return Geo.f(this.rx,t)&&Geo.f(this.ry,i)&&Geo.f(this.rw,e)&&Geo.f(this.rh,s)}equalsApproxClose(t){return Geo.z(this.rx,t.x)&&Geo.z(this.ry,t.y)&&Geo.z(this.rw,t.width)&&Geo.z(this.rh,t.height)}containsPoint(t){return this.rx<=t.x&&this.rx+this.rw>=t.x&&this.ry<=t.y&&this.ry+this.rh>=t.y}containsRect(t){return this.rx<=t.x&&t.x+t.width<=this.rx+this.rw&&this.ry<=t.y&&t.y+t.height<=this.ry+this.rh}contains(t,i,e,s){return e===void 0&&(e=0),s===void 0&&(s=0),this.rx<=t&&t+e<=this.rx+this.rw&&this.ry<=i&&i+s<=this.ry+this.rh}offset(t,i){return this.rx+=t,this.ry+=i,this}inflate(t,i){return this.xw(i,t,i,t)}addMargin(t){return this.xw(t.top,t.right,t.bottom,t.left)}subtractMargin(t){return this.xw(-t.top,-t.right,-t.bottom,-t.left)}grow(t,i,e,s){return this.xw(t,i,e,s)}xw(t,i,e,s){const n=this.rw;i+s<=-n?(this.rx+=n/2,this.rw=0):(this.rx-=s,this.rw+=i+s);const o=this.rh;return t+e<=-o?(this.ry+=o/2,this.rh=0):(this.ry-=t,this.rh+=t+e),this}intersectRect(t){return this.bC(t.x,t.y,t.width,t.height)}intersect(t,i,e,s){return this.bC(t,i,e,s)}bC(t,i,e,s){const n=Math.max(this.rx,t),o=Math.max(this.ry,i),r=Math.min(this.rx+this.rw,t+e),l=Math.min(this.ry+this.rh,i+s);return this.rx=n,this.ry=o,this.rw=Math.max(0,r-n),this.rh=Math.max(0,l-o),this}intersectsRect(t){return this.intersects(t.x,t.y,t.width,t.height)}intersects(t,i,e,s){let n=this.rw;const o=this.rx;if(n!==1/0&&e!==1/0&&(n+=o,e+=t,isNaN(e)||isNaN(n)||o>e||t>n))return!1;let r=this.rh;const l=this.ry;return!(r!==1/0&&s!==1/0&&(r+=l,s+=i,isNaN(s)||isNaN(r)||l>s||i>r))}intersectsRectPlus(t,i){let e=this.rw,s=t.width+i+i;const n=this.rx,o=t.x-i;if(e+=n,s+=o,n>s||o>e)return!1;let r=this.rh,l=t.height+i+i;const h=this.ry,c=t.y-i;return r+=h,l+=c,!(h>l||c>r)}unionPoint(t){return this.unionNoCheck(t.x,t.y,0,0)}unionRect(t){return this.unionNoCheck(t.rx,t.ry,t.rw,t.rh)}union(t,i,e,s){return e===void 0&&(e=0),s===void 0&&(s=0),this.unionNoCheck(t,i,e,s)}unionNoCheck(t,i,e,s){const n=Math.min(this.rx,t),o=Math.min(this.ry,i),r=Math.max(this.rx+this.rw,t+e),l=Math.max(this.ry+this.rh,i+s);return this.rx=n,this.ry=o,this.rw=r-n,this.rh=l-o,this}setSpot(t,i,e){return this.rx=t-e.offsetX-e.x*this.rw,this.ry=i-e.offsetY-e.y*this.rh,this}static contains(t,i,e,s,n,o,r,l){return r===void 0&&(r=0),l===void 0&&(l=0),t<=n&&n+r<=t+e&&i<=o&&o+l<=i+s}static intersects(t,i,e,s,n,o,r,l){let h=e,c=r;const a=t,f=n;if(h+=a,c+=f,a>c||f>h)return!1;let u=s,d=l;const m=i,g=o;return u+=m,d+=g,!(m>d||g>u)}static intersectsLineSegment(t,i,e,s,n,o,r,l){return Geo.kC(t,i,e,s,n,o,r,l)}get x(){return this.rx}set x(t){this.rx=t}get y(){return this.ry}set y(t){this.ry=t}get width(){return this.rw}set width(t){t<0&&U.W(t,">= 0",Rect,"width"),this.rw=t}get height(){return this.rh}set height(t){t<0&&U.W(t,">= 0",Rect,"height"),this.rh=t}get left(){return this.rx}set left(t){this.rx=t}get top(){return this.ry}set top(t){this.ry=t}get right(){return this.rx+this.rw}set right(t){this.rx+=t-(this.rx+this.rw)}get bottom(){return this.ry+this.rh}set bottom(t){this.ry+=t-(this.ry+this.rh)}get position(){return new Point(this.rx,this.ry)}set position(t){this.rx=t.x,this.ry=t.y}get size(){return new Size(this.rw,this.rh)}set size(t){this.rw=t.width,this.rh=t.height}get center(){return new Point(this.rx+this.rw/2,this.ry+this.rh/2)}set center(t){this.rx=t.x-this.rw/2,this.ry=t.y-this.rh/2}get centerX(){return this.rx+this.rw/2}set centerX(t){this.rx=t-this.rw/2}get centerY(){return this.ry+this.rh/2}set centerY(t){this.ry=t-this.rh/2}isReal(){return isFinite(this.x)&&isFinite(this.y)&&isFinite(this.width)&&isFinite(this.height)}isEmpty(){return this.width===0&&this.height===0}static Fg=new Rect(0,0,0,0).$();static $D=new Rect(NaN,NaN,NaN,NaN).$();static Vk=[];static l(){const t=Rect.Vk.pop();return t===void 0?new Rect:t}static V(t,i,e,s){const n=Rect.Vk.pop();return n===void 0?new Rect(t,i,e,s):n.i(t,i,e,s)}static e(t){Rect.Vk.push(t)}}class Margin{mt;mr;mb;ml;h;constructor(t,i,e,s){t===void 0?(this.mt=0,this.mr=0,this.mb=0,this.ml=0):i===void 0?(i=t,e=t,s=t,this.mt=t,this.mr=i,this.mb=e,this.ml=s):e===void 0?(e=t,s=i,this.mt=t,this.mr=i,this.mb=e,this.ml=s):s!==void 0?(this.mt=t,this.mr=i,this.mb=e,this.ml=s):U.o("Invalid arguments to Margin constructor: "+t+", "+i+", "+e+", "+s),this.h=!1}a(t){return this.mt=t.mt,this.mr=t.mr,this.mb=t.mb,this.ml=t.ml,this}setTo(t,i,e,s){return this.mt=t,this.mr=i,this.mb=e,this.ml=s,this}set(t){return this.mt=t.mt,this.mr=t.mr,this.mb=t.mb,this.ml=t.ml,this}copy(){const t=new Margin;return t.mt=this.mt,t.mr=this.mr,t.mb=this.mb,t.ml=this.ml,t}$(){return this.h=!0,Object.freeze(this),this}P(){return this.h||Object.isFrozen(this)?this:this.copy().u()}u(){return this.h||(this.h=!0),this}Pt(){return this.h&&(Object.isFrozen(this)&&U.o("cannot thaw constant: "+this),this.h=!1),this}yw(t){}static parse(t){if(typeof t=="string"){const i=t.split(" ");let e=0,s=NaN;for(;i[e]==="";)e++;let n=i[e++];if(n&&(s=parseFloat(n)),isNaN(s))return new Margin;let o=NaN;for(;i[e]==="";)e++;if(n=i[e++],n&&(o=parseFloat(n)),isNaN(o))return new Margin(s);let r=NaN;for(;i[e]==="";)e++;if(n=i[e++],n&&(r=parseFloat(n)),isNaN(r))return new Margin(s,o);let l=NaN;for(;i[e]==="";)e++;return n=i[e++],n&&(l=parseFloat(n)),isNaN(l)?new Margin(s,o):new Margin(s,o,r,l)}else return new Margin}static stringify(t){return t.top.toString()+" "+t.right.toString()+" "+t.bottom.toString()+" "+t.left.toString()}static stringifyFixed(t){return U.s(t,"number",Margin,"stringifyFixed:digits"),i=>i.top.toFixed(t)+" "+i.right.toFixed(t)+" "+i.bottom.toFixed(t)+" "+i.left.toFixed(t)}toString(){return"Margin("+this.top+","+this.right+","+this.bottom+","+this.left+")"}equals(t){return t instanceof Margin?this.mt===t.top&&this.mr===t.right&&this.mb===t.bottom&&this.ml===t.left:!1}equalTo(t,i,e,s){return this.mt===t&&this.mr===i&&this.mb===e&&this.ml===s}equalsApprox(t){return Geo.f(this.mt,t.top)&&Geo.f(this.mr,t.right)&&Geo.f(this.mb,t.bottom)&&Geo.f(this.ml,t.left)}get top(){return this.mt}set top(t){this.mt=t}get right(){return this.mr}set right(t){this.mr=t}get bottom(){return this.mb}set bottom(t){this.mb=t}get left(){return this.ml}set left(t){this.ml=t}isReal(){return isFinite(this.top)&&isFinite(this.right)&&isFinite(this.bottom)&&isFinite(this.left)}static Rg=new Margin(0,0,0,0).$();static PC=new Margin(2,2,2,2).$();static SC=[];static l(){const t=Margin.SC.pop();return t===void 0?new Margin:t}static e(t){Margin.SC.push(t)}}class Spot{sx;sy;ox;oy;h;constructor(t,i,e,s){t===void 0?(this.sx=0,this.sy=0,this.ox=0,this.oy=0):(i===void 0&&(i=0),e===void 0&&(e=0),s===void 0&&(s=0),this.sx=t,this.sy=i,this.ox=e,this.oy=s),this.h=!1}a(t){return this.sx=t.sx,this.sy=t.sy,this.ox=t.ox,this.oy=t.oy,this}setTo(t,i,e,s){return this.sx=t,this.sy=i,this.ox=e,this.oy=s,this}set(t){return this.sx=t.sx,this.sy=t.sy,this.ox=t.ox,this.oy=t.oy,this}copy(){const t=new Spot;return t.sx=this.sx,t.sy=this.sy,t.ox=this.ox,t.oy=this.oy,t}$(){return this.h=!0,Object.freeze(this),this}P(){return this.h||Object.isFrozen(this)?this:this.copy().u()}u(){return this.h||(this.h=!0),this}Pt(){return this.h&&(Object.isFrozen(this)&&U.o("cannot thaw constant: "+this),this.h=!1),this}yw(t){}Ie(t){return this.sx=NaN,this.sy=NaN,this.ox=t,this}wE(t,i){(isNaN(t)||t>1||t<0)&&U.W(t,"0 <= "+i+" <= 1",Spot,i)}xE(t,i){(isNaN(t)||t===1/0||t===-1/0)&&U.W(t,"real number, not NaN or Infinity",Spot,i)}static parse(t){if(typeof t=="string"){if(t=t.trim(),t==="None")return Spot.None;if(t==="TopLeft")return Spot.TopLeft;if(t==="Top"||t==="TopCenter"||t==="MiddleTop")return Spot.TopCenter;if(t==="TopRight")return Spot.TopRight;if(t==="Left"||t==="LeftCenter"||t==="MiddleLeft")return Spot.LeftCenter;if(t==="Center")return Spot.Center;if(t==="Right"||t==="RightCenter"||t==="MiddleRight")return Spot.RightCenter;if(t==="BottomLeft")return Spot.BottomLeft;if(t==="Bottom"||t==="BottomCenter"||t==="MiddleBottom")return Spot.BottomCenter;if(t==="BottomRight")return Spot.BottomRight;if(t==="TopSide")return Spot.TopSide;if(t==="LeftSide")return Spot.LeftSide;if(t==="RightSide")return Spot.RightSide;if(t==="BottomSide")return Spot.BottomSide;if(t==="TopBottomSides")return Spot.TopBottomSides;if(t==="LeftRightSides")return Spot.LeftRightSides;if(t==="TopLeftSides")return Spot.TopLeftSides;if(t==="TopRightSides")return Spot.TopRightSides;if(t==="BottomLeftSides")return Spot.BottomLeftSides;if(t==="BottomRightSides")return Spot.BottomRightSides;if(t==="NotTopSide")return Spot.NotTopSide;if(t==="NotLeftSide")return Spot.NotLeftSide;if(t==="NotRightSide")return Spot.NotRightSide;if(t==="NotBottomSide")return Spot.NotBottomSide;if(t==="AllSides")return Spot.AllSides;if(t==="Default")return Spot.Default;const i=t.split(" ");let e=0,s=0;for(;i[e]==="";)e++;let n=i[e++];n!==void 0&&n.length>0&&(s=parseFloat(n));let o=0;for(;i[e]==="";)e++;n=i[e++],n!==void 0&&n.length>0&&(o=parseFloat(n));let r=0;for(;i[e]==="";)e++;n=i[e++],n!==void 0&&n.length>0&&(r=parseFloat(n));let l=0;for(;i[e]==="";)e++;return n=i[e++],n!==void 0&&n.length>0&&(l=parseFloat(n)),new Spot(s,o,r,l)}else return new Spot}static stringify(t){return t.isSpot()?t.x.toString()+" "+t.y.toString()+" "+t.offsetX.toString()+" "+t.offsetY.toString():t.toString()}static stringifyFixed(t){return U.s(t,"number",Spot,"stringifyFixed:digits"),i=>i.x.toFixed(t)+" "+i.y.toFixed(t)+" "+i.offsetX.toFixed(t)+" "+i.offsetY.toFixed(t)}toString(){return this.isSpot()?this.ox===0&&this.oy===0?"Spot("+this.x+","+this.y+")":"Spot("+this.x+","+this.y+","+this.offsetX+","+this.offsetY+")":this.equals(Spot.None)?"None":this.equals(Spot.TopLeft)?"TopLeft":this.equals(Spot.TopCenter)?"Top":this.equals(Spot.TopRight)?"TopRight":this.equals(Spot.LeftCenter)?"Left":this.equals(Spot.Center)?"Center":this.equals(Spot.RightCenter)?"Right":this.equals(Spot.BottomLeft)?"BottomLeft":this.equals(Spot.BottomCenter)?"Bottom":this.equals(Spot.BottomRight)?"BottomRight":this.equals(Spot.TopSide)?"TopSide":this.equals(Spot.LeftSide)?"LeftSide":this.equals(Spot.RightSide)?"RightSide":this.equals(Spot.BottomSide)?"BottomSide":this.equals(Spot.TopBottomSides)?"TopBottomSides":this.equals(Spot.LeftRightSides)?"LeftRightSides":this.equals(Spot.TopLeftSides)?"TopLeftSides":this.equals(Spot.TopRightSides)?"TopRightSides":this.equals(Spot.BottomLeftSides)?"BottomLeftSides":this.equals(Spot.BottomRightSides)?"BottomRightSides":this.equals(Spot.NotTopSide)?"NotTopSide":this.equals(Spot.NotLeftSide)?"NotLeftSide":this.equals(Spot.NotRightSide)?"NotRightSide":this.equals(Spot.NotBottomSide)?"NotBottomSide":this.equals(Spot.AllSides)?"AllSides":this.equals(Spot.Default)?"Default":"None"}equals(t){return t instanceof Spot?(this.sx===t.x||isNaN(this.sx)&&isNaN(t.x))&&(this.sy===t.y||isNaN(this.sy)&&isNaN(t.y))&&this.ox===t.offsetX&&this.oy===t.offsetY:!1}opposite(){return new Spot(.5-(this.sx-.5),.5-(this.sy-.5),-this.ox,-this.oy)}includesSide(t){if(!this.isSide())return!1;if(!t.isSide())if(t.equals(Spot.Left))t=Spot.LeftSide;else if(t.equals(Spot.Right))t=Spot.RightSide;else if(t.equals(Spot.Top))t=Spot.TopSide;else if(t.equals(Spot.Bottom))t=Spot.BottomSide;else return!1;const i=this.oy,e=t.offsetY;return(i&e)===e}get x(){return this.sx}set x(t){this.sx=t}get y(){return this.sy}set y(t){this.sy=t}get offsetX(){return this.ox}set offsetX(t){this.ox=t}get offsetY(){return this.oy}set offsetY(t){this.oy=t}isSpot(){return!isNaN(this.x)&&!isNaN(this.y)}isNoSpot(){return isNaN(this.x)||isNaN(this.y)}isSide(){return isNaN(this.x)&&isNaN(this.y)&&this.offsetX===1&&this.offsetY!==0}isNone(){return isNaN(this.x)&&isNaN(this.y)&&this.offsetX===0&&this.offsetY===0}isDefault(){return isNaN(this.x)&&isNaN(this.y)&&this.offsetX===-1&&this.offsetY===0}static None=new Spot(0,0,0,0).Ie(0).$();static Default=new Spot(0,0,-1,0).Ie(-1).$();static TopLeft=new Spot(0,0,0,0).$();static TopCenter=new Spot(.5,0,0,0).$();static TopRight=new Spot(1,0,0,0).$();static LeftCenter=new Spot(0,.5,0,0).$();static Center=new Spot(.5,.5,0,0).$();static RightCenter=new Spot(1,.5,0,0).$();static BottomLeft=new Spot(0,1,0,0).$();static BottomCenter=new Spot(.5,1,0,0).$();static BottomRight=new Spot(1,1,0,0).$();static MiddleTop=Spot.TopCenter;static MiddleLeft=Spot.LeftCenter;static MiddleRight=Spot.RightCenter;static MiddleBottom=Spot.BottomCenter;static Top=Spot.TopCenter;static Left=Spot.LeftCenter;static Right=Spot.RightCenter;static Bottom=Spot.BottomCenter;static TopSide=new Spot(0,0,1,1).Ie(1).$();static LeftSide=new Spot(0,0,1,2).Ie(1).$();static RightSide=new Spot(0,0,1,4).Ie(1).$();static BottomSide=new Spot(0,0,1,8).Ie(1).$();static TopBottomSides=new Spot(0,0,1,9).Ie(1).$();static LeftRightSides=new Spot(0,0,1,6).Ie(1).$();static TopLeftSides=new Spot(0,0,1,3).Ie(1).$();static TopRightSides=new Spot(0,0,1,5).Ie(1).$();static BottomLeftSides=new Spot(0,0,1,10).Ie(1).$();static BottomRightSides=new Spot(0,0,1,12).Ie(1).$();static NotTopSide=new Spot(0,0,1,14).Ie(1).$();static NotLeftSide=new Spot(0,0,1,13).Ie(1).$();static NotRightSide=new Spot(0,0,1,11).Ie(1).$();static NotBottomSide=new Spot(0,0,1,7).Ie(1).$();static AllSides=new Spot(0,0,1,15).Ie(1).$();static zk=new Spot(.156,.156).$();static Xk=new Spot(.844,.844).$();static MC=[];static l(){const t=Spot.MC.pop();return t===void 0?new Spot:t}static e(t){Spot.MC.push(t)}}class Transform{m11;m12;m21;m22;dx;dy;constructor(){this.m11=1,this.m12=0,this.m21=0,this.m22=1,this.dx=0,this.dy=0}set(t){return this.m11=t.m11,this.m12=t.m12,this.m21=t.m21,this.m22=t.m22,this.dx=t.dx,this.dy=t.dy,this}setTo(t,i,e,s,n,o){return this.m11=t,this.m12=i,this.m21=e,this.m22=s,this.dx=n,this.dy=o,this}copy(){const t=new Transform;return t.m11=this.m11,t.m12=this.m12,t.m21=this.m21,t.m22=this.m22,t.dx=this.dx,t.dy=this.dy,t}toString(){return"Transform("+this.m11+","+this.m12+","+this.m21+","+this.m22+","+this.dx+","+this.dy+")"}equals(t){return this.m11===t.m11&&this.m12===t.m12&&this.m21===t.m21&&this.m22===t.m22&&this.dx===t.dx&&this.dy===t.dy}Yk(){return this.dx===0&&this.dy===0&&this.m11===1&&this.m12===0&&this.m21===0&&this.m22===1}Ri(){return this.m11=1,this.m12=0,this.m21=0,this.m22=1,this.dx=0,this.dy=0,this}nc(t){const i=this.m11*t.m11+this.m21*t.m12,e=this.m12*t.m11+this.m22*t.m12,s=this.m11*t.m21+this.m21*t.m22,n=this.m12*t.m21+this.m22*t.m22;return this.dx=this.m11*t.dx+this.m21*t.dy+this.dx,this.dy=this.m12*t.dx+this.m22*t.dy+this.dy,this.m11=i,this.m12=e,this.m21=s,this.m22=n,this}NC(t){const i=1/(t.m11*t.m22-t.m12*t.m21),e=t.m22*i,s=-t.m12*i,n=-t.m21*i,o=t.m11*i,r=i*(t.m21*t.dy-t.m22*t.dx),l=i*(t.m12*t.dx-t.m11*t.dy),h=this.m11*e+this.m21*s,c=this.m12*e+this.m22*s,a=this.m11*n+this.m21*o,f=this.m12*n+this.m22*o;return this.dx=this.m11*r+this.m21*l+this.dx,this.dy=this.m12*r+this.m22*l+this.dy,this.m11=h,this.m12=c,this.m21=a,this.m22=f,this}bw(){const t=1/(this.m11*this.m22-this.m12*this.m21),i=this.m22*t,e=-this.m12*t,s=-this.m21*t,n=this.m11*t,o=t*(this.m21*this.dy-this.m22*this.dx),r=t*(this.m12*this.dx-this.m11*this.dy);return this.m11=i,this.m12=e,this.m21=s,this.m22=n,this.dx=o,this.dy=r,this}cs(t,i,e){if(t>=360?t-=360:t<0&&(t+=360),t===0)return this;this.Fs(i,e);let s=0,n=0;if(t===90)s=0,n=1;else if(t===180)s=-1,n=0;else if(t===270)s=0,n=-1;else{const c=t*Math.PI/180;s=Math.cos(c),n=Math.sin(c)}const o=this.m11*s+this.m21*n,r=this.m12*s+this.m22*n,l=this.m11*-n+this.m21*s,h=this.m12*-n+this.m22*s;return this.m11=o,this.m12=r,this.m21=l,this.m22=h,this.Fs(-i,-e),this}Fs(t,i){return this.dx+=this.m11*t+this.m21*i,this.dy+=this.m12*t+this.m22*i,this}tt(t,i){return i===void 0&&(i=t),this.m11*=t,this.m12*=t,this.m21*=i,this.m22*=i,this}ZD(){if(this.m11===1&&this.m12===0)return 0;let t=Math.atan2(this.m12,this.m11)*180/Math.PI;return t<0&&(t+=360),t}gt(t){const i=t.x,e=t.y;return t.i(i*this.m11+e*this.m21+this.dx,i*this.m12+e*this.m22+this.dy)}$e(t){const i=1/(this.m11*this.m22-this.m12*this.m21),e=this.m22*i,s=-this.m12*i,n=-this.m21*i,o=this.m11*i,r=t.x-this.dx,l=t.y-this.dy;return t.i(r*e+l*n,r*s+l*o)}kw(t){const i=1/(this.m11*this.m22-this.m12*this.m21),e=this.m22*i,s=-this.m12*i,n=-this.m21*i,o=this.m11*i,r=i*(this.m21*this.dy-this.m22*this.dx),l=i*(this.m12*this.dx-this.m11*this.dy),h=t.x*1.25,c=t.y*1.2;return t.i(h*e+c*n+r,h*s+c*o+l)}vg(t){const i=t.x,e=t.y,s=i+t.width,n=e+t.height,o=this.m11,r=this.m12,l=this.m21,h=this.m22,c=this.dx,a=this.dy,f=i*o+e*l+c,u=i*r+e*h+a,d=s*o+e*l+c,m=s*r+e*h+a,g=i*o+n*l+c,p=i*r+n*h+a,w=s*o+n*l+c,x=s*r+n*h+a;let k=f,b=f,P=u,S=u;return k=Math.min(k,d),b=Math.max(b,d),P=Math.min(P,m),S=Math.max(S,m),k=Math.min(k,g),b=Math.max(b,g),P=Math.min(P,p),S=Math.max(S,p),k=Math.min(k,w),b=Math.max(b,w),P=Math.min(P,x),S=Math.max(S,x),t.i(k,P,b-k,S-P),t}static CC=[];static l(){const t=Transform.CC.pop();return t===void 0?new Transform:t}static e(t){Transform.CC.push(t)}static Gk="54a702f3e53909c447824c6706603faf4c"}const Geo={QD:"7da71ca0ad381e90",Rn:4*((Math.sqrt(2)-1)/3),LC:null,Pw:y=>{if(y<=0)return 0;let t=Geo.LC;if(t===null){t=[];for(let i=0;i<=2e3;i++)t[i]=Math.sqrt(i);Geo.LC=t}if(y<1){const i=1/y;return i<=2e3?1/t[i|0]:Math.sqrt(y)}else return y<=2e3?t[y|0]:Math.sqrt(y)},f:(y,t)=>{const i=y-t;return i<.5&&i>-.5},z:(y,t)=>{const i=y-t;return i<5e-8&&i>-5e-8},vi:(y,t,i,e,s,n,o)=>{s<=0&&(s=1e-6);let r=0,l=0,h=0,c=0;if(yu-d)if(y-i>s||i-y>s){const g=(e-t)/(i-y)*(n-y)+t;if(g-s<=o&&o<=g+s)return!0}else return!0;else if(t-e>s||e-t>s){const g=(i-y)/(e-t)*(o-t)+y;if(g-s<=n&&n<=g+s)return!0}else return!0}return!1},Sw:(y,t,i,e,s,n,o,r,l,h,c,a)=>{if(!Geo.vi(y,t,o,r,a,i,e)||!Geo.vi(y,t,o,r,a,s,n)){const f=(y+i)/2,u=(t+e)/2,d=(i+s)/2,m=(e+n)/2,g=(s+o)/2,p=(n+r)/2,w=(f+d)/2,x=(u+m)/2,k=(d+g)/2,b=(m+p)/2,P=(w+k)/2,S=(x+b)/2;return Geo.Sw(y,t,f,u,w,x,P,S,l,h,c,a)||Geo.Sw(P,S,k,b,g,p,o,r,l,h,c,a)}else return Geo.vi(y,t,o,r,a,h,c)},AC:(y,t,i,e,s,n,o,r,l)=>{const h=(y+i)/2,c=(t+e)/2,a=(i+s)/2,f=(e+n)/2,u=(s+o)/2,d=(n+r)/2,m=(h+a)/2,g=(c+f)/2,p=(a+u)/2,w=(f+d)/2;return l.i((m+p)/2,(g+w)/2),l},_D:(y,t,i,e,s,n,o,r)=>{const l=(y+i)/2,h=(t+e)/2,c=(i+s)/2,a=(e+n)/2,f=(s+o)/2,u=(n+r)/2,d=(l+c)/2,m=(h+a)/2,g=(c+f)/2,p=(a+u)/2;return Point.direction(d,m,g,p)},ou:(y,t,i,e,s,n,o,r,l,h)=>{if(!Geo.vi(y,t,o,r,l,i,e)||!Geo.vi(y,t,o,r,l,s,n)){const c=(y+i)/2,a=(t+e)/2,f=(i+s)/2,u=(e+n)/2,d=(s+o)/2,m=(n+r)/2,g=(c+f)/2,p=(a+u)/2,w=(f+d)/2,x=(u+m)/2,k=(g+w)/2,b=(p+x)/2;Geo.ou(y,t,c,a,g,p,k,b,l,h),Geo.ou(k,b,w,x,d,m,o,r,l,h)}else h.unionNoCheck(y,t,0,0),h.unionNoCheck(o,r,0,0);return h},vn:(y,t,i,e,s,n,o,r,l,h)=>{if(!Geo.vi(y,t,o,r,l,i,e)||!Geo.vi(y,t,o,r,l,s,n)){const c=(y+i)/2,a=(t+e)/2,f=(i+s)/2,u=(e+n)/2,d=(s+o)/2,m=(n+r)/2,g=(c+f)/2,p=(a+u)/2,w=(f+d)/2,x=(u+m)/2,k=(g+w)/2,b=(p+x)/2;Geo.vn(y,t,c,a,g,p,k,b,l,h),Geo.vn(k,b,w,x,d,m,o,r,l,h)}else h.length===0&&(h.push(y),h.push(t)),h.push(o),h.push(r);return h},Kk:(y,t,i,e,s,n,o,r,l,h)=>{if(Geo.vi(y,t,s,n,h,i,e))return Geo.vi(y,t,s,n,h,r,l);{const c=(y+i)/2,a=(t+e)/2,f=(i+s)/2,u=(e+n)/2,d=(c+f)/2,m=(a+u)/2;return Geo.Kk(y,t,c,a,d,m,o,r,l,h)||Geo.Kk(d,m,f,u,s,n,o,r,l,h)}},bE:(y,t,i,e,s,n,o)=>{const r=(y+i)/2,l=(t+e)/2,h=(i+s)/2,c=(e+n)/2;return o.i((r+h)/2,(l+c)/2),o},jk:(y,t,i,e,s,n,o,r)=>{if(Geo.vi(y,t,s,n,o,i,e))r.unionNoCheck(y,t,0,0),r.unionNoCheck(s,n,0,0);else{const l=(y+i)/2,h=(t+e)/2,c=(i+s)/2,a=(e+n)/2,f=(l+c)/2,u=(h+a)/2;Geo.jk(y,t,l,h,f,u,o,r),Geo.jk(f,u,c,a,s,n,o,r)}return r},Og:(y,t,i,e,s,n,o,r)=>{if(Geo.vi(y,t,s,n,o,i,e))r.length===0&&(r.push(y),r.push(t)),r.push(s),r.push(n);else{const l=(y+i)/2,h=(t+e)/2,c=(i+s)/2,a=(e+n)/2,f=(l+c)/2,u=(h+a)/2;Geo.Og(y,t,l,h,f,u,o,r),Geo.Og(f,u,c,a,s,n,o,r)}return r},Ig:(y,t,i,e,s,n,o,r,l,h,c,a,f,u)=>{if(!Geo.vi(y,t,o,r,f,i,e)||!Geo.vi(y,t,o,r,f,s,n)){const d=(y+i)/2,m=(t+e)/2,g=(i+s)/2,p=(e+n)/2,w=(s+o)/2,x=(n+r)/2,k=(d+g)/2,b=(m+p)/2,P=(g+w)/2,S=(p+x)/2,L=(k+P)/2,C=(b+S)/2;let M=1/0,N=!1,T=0,A=0;if(Geo.Ig(y,t,d,m,k,b,L,C,l,h,c,a,f,u)){const D=(u.x-l)**2+(u.y-h)**2;D{let u=0;if(!Geo.vi(y,t,o,r,f,i,e)||!Geo.vi(y,t,o,r,f,s,n)){const d=(y+i)/2,m=(t+e)/2,g=(i+s)/2,p=(e+n)/2,w=(s+o)/2,x=(n+r)/2,k=(d+g)/2,b=(m+p)/2,P=(g+w)/2,S=(p+x)/2,L=(k+P)/2,C=(b+S)/2;u+=Geo.Eg(y,t,d,m,k,b,L,C,l,h,c,a,f),u+=Geo.Eg(L,C,P,S,w,x,o,r,l,h,c,a,f)}else{const d=(y-o)*(h-a)-(t-r)*(l-c);if(d===0)return u;const m=((y*r-t*o)*(l-c)-(y-o)*(l*a-h*c))/d,g=((y*r-t*o)*(h-a)-(t-r)*(l*a-h*c))/d;if(m>=c)return u;let p=0,w=0;if((l>c?l-c:c-l)<(h>a?h-a:a-h)){if(tw)return u}else if(yw)return u;d>0?u++:d<0&&u--}return u},dl:(y,t,i,e,s,n,o)=>{if(Geo.z(y,i)){let r=0,l=0;tl?(o.i(y,l),!1):(o.i(y,h),!0)}else if(Geo.z(t,e)){let r=0,l=0;yl?(o.i(l,t),!1):(o.i(h,t),!0)}else{const r=(i-y)**2+(e-t)**2,l=((y-s)*(y-i)+(t-n)*(t-e))/r;if(l<-5e-6)return o.i(y,t),!1;if(l>1.000005)return o.i(i,e),!1;{const h=y+l*(i-y),c=t+l*(e-t);return o.i(h,c),!0}}},On:(y,t,i,e,s,n,o,r,l)=>{if(Geo.f(y,i)&&Geo.f(t,e))return l.i(y,t),!1;if(Geo.z(s,o)){if(Geo.z(y,i))return Geo.dl(y,t,i,e,s,n,l),!1;{const c=(e-t)/(i-y)*(s-y)+t;return Geo.dl(y,t,i,e,s,c,l)}}else{const h=(r-n)/(o-s);if(Geo.z(y,i)){const c=h*(y-s)+n;let a=0,f=0;return tf?(l.i(y,f),!1):(l.i(y,c),!0)}else{const c=(e-t)/(i-y);if(Geo.z(h,c))return Geo.dl(y,t,i,e,s,n,l),!1;{const a=(c*y-h*s+n-t)/(c-h);if(Geo.z(c,0)){let f=0,u=0;return yu?(l.i(u,t),!1):(l.i(a,t),!0)}else{const f=c*(a-y)+t;return Geo.dl(y,t,i,e,a,f,l)}}}}},kE:(y,t,i,e,s)=>Geo.On(i.x,i.y,e.x,e.y,y.x,y.y,t.x,t.y,s),PE:(y,t,i,e,s,n,o,r,l,h)=>{let c=1/0;function a(P,S){const L=(P-y)**2+(S-t)**2;L{let h=1e21,c=y,a=t;if(Geo.On(y,t,y,e,s,n,o,r,l)){const f=(l.x-s)**2+(l.y-n)**2;fGeo.kC(y.x,y.y,y.width,y.height,t.x,t.y,i.x,i.y),kC:(y,t,i,e,s,n,o,r)=>{const l=y,h=y+i,c=t,a=t+e;if(s===o){let f=0,u=0;return n=c}if(n===r){let f=0,u=0;return s=l}return!!(Rect.contains(y,t,i,e,s,n)||Rect.contains(y,t,i,e,o,r)||Geo.su(l,c,h,c,s,n,o,r)||Geo.su(h,c,h,a,s,n,o,r)||Geo.su(h,a,l,a,s,n,o,r)||Geo.su(l,a,l,c,s,n,o,r))},su:(y,t,i,e,s,n,o,r)=>y===i&&t===e&&s===o&&n===r?y===s&&t===n:Geo.eu(y,t,i,e,s,n)*Geo.eu(y,t,i,e,o,r)<=0&&Geo.eu(s,n,o,r,y,t)*Geo.eu(s,n,o,r,i,e)<=0,eu:(y,t,i,e,s,n)=>{const o=i-y,r=e-t;let l=s-y,h=n-t,c=l*r-h*o;return c===0&&(c=l*o+h*r,c>0&&(l-=o,h-=r,c=l*o+h*r,c<0&&(c=0))),c},Ug:y=>(y<0&&(y+=360),y>=360&&(y-=360),y),TC:(y,t,i,e,s,n)=>{const o=Math.PI;n||(e=e*(o/180),s=s*(o/180));const r=e>s?-1:1,l=1e-5,h=o*2,c=[],a=o/2;let f=e,u=Math.min(h,Math.abs(s-e));if(ul;){const d=f+r*Math.min(u,a);c.push(Geo.tF(i,f,d,y,t)),u-=Math.abs(d-f),f=d}return c},tF:(y,t,i,e,s)=>{const n=(i-t)/2,o=y*Math.cos(n),r=y*Math.sin(n),l=o,h=-r,c=l*l+h*h,a=c+l*o+h*r,f=4/3*(Math.sqrt(2*c*a)-a)/(l*r-h*o),u=l-f*h,d=h+f*l,m=u,g=-d,p=n+t,w=Math.cos(p),x=Math.sin(p);return[e+y*Math.cos(t),s+y*Math.sin(t),e+u*w-d*x,s+u*x+d*w,e+m*w-g*x,s+m*x+g*w,e+y*Math.cos(i),s+y*Math.sin(i)]},Dg:(y,t,i,e,s,n,o)=>{const r=s,l=n,h=Math.floor((y-i)/r)*r+i,c=Math.floor((t-e)/l)*l+e;let a=h;h+r-y{let i=Math.max(y,t),e=Math.min(y,t),s=1,n=1;do s=i%e,n=e,i=e,e=s;while(s>0);return n},iF:(y,t,i,e)=>{const s=i<0,n=e<0;let o=0,r=0,l=0;y{let o=0;if(e>0)if(i>0){const r=y*y,l=t*t,h=y*i,c=t*e;let a=-l+c,f=-l+Math.sqrt(h*h+c*c),u=a;const d=9999999999;for(let p=0;p0)a=u;else if(k<0)f=u;else break}s=r*i/(u+r),n=l*e/(u+l);const m=s-i,g=n-e;o=Math.sqrt(m*m+g*g)}else s=0,n=t,o=Math.abs(e-t);else{const r=y*y-t*t,l=y*i;if(l(y[y.Line=1]="Line",y[y.Rectangle=2]="Rectangle",y[y.Ellipse=3]="Ellipse",y[y.Path=4]="Path",y))(GeometryType||{}),GeometryStretch=(y=>(y[y.None=0]="None",y[y.Default=1]="Default",y[y.Fill=2]="Fill",y[y.Uniform=6]="Uniform",y))(GeometryStretch||{});class Geometry{n;zg;Xg;oc;ru;lu;En;Un;Bn;H;we;xe;Qi;_i;Rs;rc;lc;constructor(t){GSet.Ki(this),this.n=2,t===void 0&&(t=4),this.H=t,this.we=0,this.xe=0,this.Qi=0,this._i=0,t===4?this.Rs=new List:this.Rs=Geometry.Nw,this.zg=this.Rs.nt,this.Xg=new Rect().u(),this.oc=null,this.ru=null,this.lu=NaN,this.En=Spot.TopLeft,this.Un=Spot.BottomRight,this.rc=NaN,this.lc=NaN,this.Bn=2}copy(){const t=new Geometry;if(t.n=this.n&-2,t.H=this.H,t.we=this.we,t.xe=this.xe,t.Qi=this.Qi,t._i=this._i,this.H===4){const i=this.Rs.r,e=t.Rs;for(let s=0;si.toString(t)}oi(t){t in GeometryType?this.type=t:U.er(this,t)}toString(t){t===void 0&&(t=-1);const i=s=>s===0?"0":s.toFixed(t);let e;switch(this.type){case 1:return t<0?"M"+this.startX.toString()+" "+this.startY.toString()+"L"+this.endX.toString()+" "+this.endY.toString():"M"+i(this.startX)+" "+i(this.startY)+"L"+i(this.endX)+" "+i(this.endY);case 2:return e=new Rect(this.startX,this.startY,0,0),e.union(this.endX,this.endY,0,0),t<0?"M"+e.x.toString()+" "+e.y.toString()+"H"+e.right.toString()+"V"+e.bottom.toString()+"H"+e.left.toString()+"z":"M"+i(e.x)+" "+i(e.y)+"H"+i(e.right)+"V"+i(e.bottom)+"H"+i(e.left)+"z";case 3:if(e=new Rect(this.startX,this.startY,0,0),e.union(this.endX,this.endY,0,0),t<0){const r=e.left.toString()+" "+(e.y+e.height/2).toString(),l=e.right.toString()+" "+(e.y+e.height/2).toString();return"M"+r+"A"+(e.width/2).toString()+" "+(e.height/2).toString()+" 0 0 1 "+l+"A"+(e.width/2).toString()+" "+(e.height/2).toString()+" 0 0 1 "+r}else{const r=i(e.left)+" "+i(e.y+e.height/2),l=i(e.right)+" "+i(e.y+e.height/2);return"M"+r+"A"+i(e.width/2)+" "+i(e.height/2)+" 0 0 1 "+l+"A"+i(e.width/2)+" "+i(e.height/2)+" 0 0 1 "+r}case 4:let s="";const n=this.figures.r,o=n.length;for(let r=0;r0&&(s+=" x "),l.isFilled&&(s+="F "),s+=l.toString(t)}return s;default:return GeometryType[this.type]}}static fillPath(t){typeof t!="string"&&U.Zi(t,"string",Geometry,"fillPath:str");const i=t.split(/[Xx]/),e=i.length;let s="";for(let n=0;n=k-1||o[r+1].match(M)!==null?!0:(u=!1,!1)}function m(){return r++,o[r]}function g(T){let A=parseFloat(m()),D=parseFloat(m());l===l.toLowerCase()&&(A=f.x+A,D=f.y+D),T.i(A,D)}function p(){return g(f),f}function w(){return g(a),a}function x(){const T=h.toLowerCase();return T==="c"||T==="s"||T==="q"||T==="t"?new Point(2*f.x-a.x,2*f.y-a.y):new Point(f.x,f.y)}const k=o.length,b=GeoStream.RC(null);let P=!1,S=!1,L=!1,C=!0;const M=new RegExp("["+Geometry.Yg+"]");for(;!(r>=k-1);){if(h=l,l=m(),l==="")continue;u=!0;let T=!1;switch(l.toUpperCase()){case"X":C=!0,P=!1,S=!1;break;case"M":const A=p();for(b.bi===null||C===!0?(b.hu(A.x,A.y,P,!1,!S,L),C=!1):b.sF(A.x,A.y),c.a(f);!d();){const D=p();b.lr(D.x,D.y)}break;case"L":for(;!d();){const D=p();b.lr(D.x,D.y)}u&&(T=!0);break;case"H":for(;!d();)f.i((l===l.toLowerCase()?f.x:0)+parseFloat(m()),f.y),b.lr(f.x,f.y);break;case"V":for(;!d();)f.i(f.x,(l===l.toLowerCase()?f.y:0)+parseFloat(m())),b.lr(f.x,f.y);u&&(T=!0);break;case"C":for(;!d();){const D=new Point;g(D);const F=w(),v=p();b.hr(D.x,D.y,F.x,F.y,v.x,v.y)}u&&(T=!0);break;case"S":for(;!d();){const D=x(),F=w(),v=p();b.hr(D.x,D.y,F.x,F.y,v.x,v.y)}u&&(T=!0);break;case"Q":for(;!d();){const D=w(),F=p();b.Cw(D.x,D.y,F.x,F.y)}u&&(T=!0);break;case"T":for(;!d();){const D=x();a.a(D);const F=p();b.Cw(D.x,D.y,F.x,F.y),a.a(F)}u&&(T=!0);break;case"B":for(;!d();){const D=parseFloat(m()),F=parseFloat(m());let v=parseFloat(m()),R=parseFloat(m());const O=parseFloat(m());let X=O,Y=!1;d()||(X=parseFloat(m()),d()||(Y=parseFloat(m())!==0)),l===l.toLowerCase()&&(v+=f.x,R+=f.y),b.nF(D,F,v,R,O,X,Y)}u&&(T=!0);break;case"A":for(;!d();){const D=Math.abs(parseFloat(m())),F=Math.abs(parseFloat(m())),v=parseFloat(m());let R=!1,O=!1,X=0,Y=0;const E=m();E.length===1?(R=!!parseFloat(E),O=!!parseFloat(m()),X=parseFloat(m()),Y=parseFloat(m())):E.length===2?(R=!!parseFloat(E[0]),O=!!parseFloat(E[1]),X=parseFloat(m()),Y=parseFloat(m())):(R=!!parseFloat(E[0]),O=!!parseFloat(E[1]),X=parseFloat(E.slice(2)),Y=parseFloat(m())),l===l.toLowerCase()&&(X=f.x+X,Y=f.y+Y),f.i(X,Y),b.oF(D,F,v,R,O,X,Y)}u&&(T=!0);break;case"Z":b.rF(),f.a(c);break;case"F":{let D="",F=1;for(;o[r+F];){if(o[r+F]==="0"){L=!0,F++;continue}if(o[r+F].match(/[Uu]/)!==null){F++;continue}if(o[r+F].match(M)===null){F++;continue}D=o[r+F];break}D.match(/[Mm]/)?P=!0:b.lF();break}case"U":{let D="",F=1;for(;o[r+F];){if(o[r+F].match(/[Ff]/)!==null){F++;continue}if(o[r+F].match(M)===null){F++;continue}D=o[r+F];break}D.match(/[Mm]/)?S=!0:b.hF(!1);break}default:if(l==="0"||l==="1")break;U.ni("Unknown geometry command: "+l);break}if(T){U.ni(`Bad geometry command: ${l}, next token: ${m()}, string: ${t}`);break}}const N=b.Gg;if(GeoStream.vC(b),i){const T=N.figures.iterator;for(;T.next();){const A=T.value;A.isFilled=!0}}return N}static OC(t,i){const e=t.length,s=Point.l();for(let n=0;n=t)return 0;if((n>r?n-r:r-n)<(o>l?o-l:l-o)){if(ol)return 0}else if(ao)return 0}else if(nr)return 0}else if(cn)return 0;return h>0?1:-1}EC(t,i,e){const s=this.figures.r,n=s.length;for(let o=0;o1&&(t=1),i===void 0&&(i=new Point),this.type===1)return i.i(this.startX+t*(this.endX-this.startX),this.startY+t*(this.endY-this.startY)),i;const e=this.flattenedSegments,s=this.flattenedLengths,n=this.flattenedTotalLength,o=e.length,r=n*t;let l=0;for(let h=0;h=r){const d=r-l,m=u===0?0:d/u,g=e[h],p=g[f*2],w=g[f*2+1],x=g[f*2+2],k=g[f*2+3];return i.i(p+(x-p)*m,w+(k-w)*m),i}l+=u}}return i}getAngleAlongPath(t){if(t<0?t=0:t>1&&(t=1),this.type===1)return Math.atan2(this.endY-this.startY,this.endX-this.startX)*180/Math.PI;const i=this.flattenedSegments,e=this.flattenedLengths,s=this.flattenedTotalLength,n=i.length,o=s*t;let r=0;for(let l=0;l=o){const u=i[l],d=u[a*2],m=u[a*2+1],g=u[a*2+2],p=u[a*2+3];return Math.abs(g-d)<1&&Math.abs(p-m)<1?0:Math.abs(g-d)<1?p-m>=0?90:270:Math.abs(p-m)<1?g-d>=0?0:180:Math.atan2(p-m,g-d)*180/Math.PI}r+=f}}return NaN}getPointAndAngleAlongPath(t,i){if(t<0?t=0:t>1&&(t=1),i===void 0&&(i=[]),i.length=3,this.type===1)return i[0]=this.startX+t*(this.endX-this.startX),i[1]=this.startY+t*(this.endY-this.startY),i[2]=Math.atan2(this.endY-this.startY,this.endX-this.startX)*180/Math.PI,i;const e=this.flattenedSegments,s=this.flattenedLengths,n=this.flattenedTotalLength,o=e.length,r=n*t;let l=0;for(let h=0;h=r){const d=r-l,m=u===0?0:d/u,g=e[h],p=g[f*2],w=g[f*2+1],x=g[f*2+2],k=g[f*2+3];i[0]=p+(x-p)*m,i[1]=w+(k-w)*m;let b;return Math.abs(x-p)<1&&Math.abs(k-w)<1?b=0:Math.abs(x-p)<1?b=k-w>=0?90:270:Math.abs(k-w)<1?b=x-p>=0?0:180:b=Math.atan2(k-w,x-p)*180/Math.PI,i[2]=b,i}l+=u}}return i}getFractionForPoint(t){if(this.type===1){const i=this.startX,e=this.startY,s=this.endX,n=this.endY;if(i===s&&e===n)return 0;{const o=t.x,r=t.y;let l=0,h=0;if(i===s)return e=h?h===e?0:1:Math.abs(r-e)/(h-l);if(e===n)return i=h?h===i?0:1:Math.abs(o-i)/(h-l);{const c=(s-i)**2+(n-e)**2,a=Point.l();Geo.dl(i,e,s,n,o,r,a);const f=a.x,u=a.y;return Point.e(a),Math.sqrt(((f-i)**2+(u-e)**2)/c)}}}else if(this.type===2){const i=this.startX,e=this.startY,s=this.endX,n=this.endY;if(i===s&&e===n)return 0;{const o=s-i,r=n-e,l=o*2+r*2;let h=t.x,c=t.y;h=Math.min(Math.max(h,i),s),c=Math.min(Math.max(c,e),n);const a=Math.abs(h-i),f=Math.abs(h-s),u=Math.abs(c-e),d=Math.abs(c-n),m=Math.min(a,f,u,d);if(m===u)return h/l;if(m===f)return(o+c)/l;if(m===d)return(o*2+r-h)/l;if(m===a)return(o*2+r*2-c)/l}}else{const i=this.flattenedSegments,e=this.flattenedLengths,s=this.flattenedTotalLength,n=Point.l();let o=1/0,r=0,l=0;const h=i.length;let c=0,a=0;for(let u=0;u1?1:f}return 0}get flattenedSegments(){return this.UC(),this.oc}UC(){if(this.oc===null){const t=this.oc=[],i=this.ru=[];this.fF(t,i)}}get flattenedLengths(){return this.UC(),this.ru}get flattenedTotalLength(){let t=this.lu;if(isNaN(t)){if(this.type===1){const i=Math.abs(this.endX-this.startX),e=Math.abs(this.endY-this.startY);t=Math.sqrt(i*i+e*e)}else if(this.type===2){const i=Math.abs(this.endX-this.startX),e=Math.abs(this.endY-this.startY);t=i*2+e*2}else{const i=this.flattenedLengths,e=i.length;t=0;for(let s=0;s=4&&(t.push(e),i.push(this.Jk(e))),e=[],e.push(d.endX),e.push(d.endY),r=d.endX,l=d.endY,h=r,c=l;break;case 2:e.push(d.endX),e.push(d.endY),r=d.endX,l=d.endY;break;case 3:Geo.vn(r,l,d.point1X,d.point1Y,d.point2X,d.point2Y,d.endX,d.endY,.5,e),r=d.endX,l=d.endY;break;case 4:Geo.Og(r,l,d.point1X,d.point1Y,d.endX,d.endY,.5,e),r=d.endX,l=d.endY;break;case 5:{const m=d.bo(o),g=m.length;if(g===0){e.push(d.centerX),e.push(d.centerY),r=d.centerX,l=d.centerY;break}for(let p=0;p=4&&(t.push(e),i.push(this.Jk(e)))}}}get type(){return this.H}set type(t){this.H!==t&&(this.h&&U.L(this,t),this.H=t,t===4?this.Rs=new List:(Geometry.Nw===null&&(Geometry.Nw=new List().u()),this.Rs=Geometry.Nw),this.wt=!0)}get startX(){return this.we}set startX(t){this.we!==t&&(this.h&&U.L(this,t),this.we=t,this.wt=!0)}get startY(){return this.xe}set startY(t){this.xe!==t&&(this.h&&U.L(this,t),this.xe=t,this.wt=!0)}get endX(){return this.Qi}set endX(t){this.Qi!==t&&(this.h&&U.L(this,t),this.Qi=t,this.wt=!0)}get endY(){return this._i}set endY(t){this._i!==t&&(this.h&&U.L(this,t),this._i=t,this.wt=!0)}get figures(){return this.Rs}set figures(t){this.Rs!==t&&(this.h&&U.L(this,t),this.Rs=t,this.wt=!0)}add(t){return this.Rs.add(t),this}setSpots(t,i,e,s,n,o,r,l){return this.h&&U.L(this),this.En=new Spot(t,i,n,o).u(),this.Un=new Spot(e,s,r,l).u(),this}get spot1(){return this.En}set spot1(t){this.h&&U.L(this,t),this.En=t.P()}get spot2(){return this.Un}set spot2(t){this.h&&U.L(this,t),this.Un=t.P()}get defaultStretch(){return this.Bn}set defaultStretch(t){this.Bn=t}get bounds(){return this.Hk()&&this.Lw(),this.Xg}}Geometry.stringify=Geometry.stringify;Geometry.stringifyFixed=Geometry.stringifyFixed;Geometry.fillPath=Geometry.fillPath;Geometry.parse=Geometry.parse;class PathFigure{n;we;xe;hc;Kg;Ee;constructor(t,i,e,s,n){e===void 0&&(e=!0),s===void 0&&(s=!0),n===void 0&&(n=!1),this.n=2|(e?4:0)|(s?8:0)|(n?16:0),t!==void 0?this.we=t:this.we=0,i!==void 0?this.xe=i:this.xe=0,this.hc=new List,this.Kg=this.hc.nt,this.Ee=null}copy(){const t=new PathFigure;t.n=this.n&-2,t.we=this.we,t.xe=this.xe;const i=this.hc.r,e=i.length,s=t.hc;for(let n=0;no===0?"0":o.toFixed(t);i="M"+n(this.startX)+" "+n(this.startY)}const e=this.segments.r,s=e.length;for(let n=0;n(y[y.Move=1]="Move",y[y.Line=2]="Line",y[y.Bezier=3]="Bezier",y[y.QuadraticBezier=4]="QuadraticBezier",y[y.Arc=5]="Arc",y[y.SvgArc=6]="SvgArc",y))(SegmentType||{});class PathSegment{H;n;Qi;_i;tn;pl;yl;ar;vs;constructor(t,i,e,s,n,o,r,l){if(GSet.Ki(this),t===void 0&&(t=2),this.H=t,this.n=2,i!==void 0?this.Qi=i:this.Qi=0,e!==void 0?this._i=e:this._i=0,s===void 0&&(s=0),n===void 0&&(n=0),o===void 0&&(o=0),r===void 0&&(r=0),t===6){let h=o;h=h%360,h<0&&(h+=360),this.tn=h,this.pl=0,this.yl=Math.max(s,0),this.ar=Math.max(n,0),typeof r=="boolean"?r&&(this.isLargeArc=!0):typeof r=="number"&&r&&(this.isLargeArc=!0),l&&(this.isClockwiseArc=!0)}else this.tn=s,this.pl=n,t===5&&(o=Math.max(o,0)),this.yl=o,typeof r=="number"?(t===5&&(r=Math.max(r,0)),this.ar=r):this.ar=0;this.vs=null}copy(){const t=new PathSegment;return t.H=this.H,t.n=this.n&-2,t.Qi=this.Qi,t._i=this._i,t.tn=this.tn,t.pl=this.pl,t.yl=this.yl,t.ar=this.ar,t}equalsApprox(t){if(!(t instanceof PathSegment)||this.type!==t.type||this.isClosed!==t.isClosed)return!1;switch(this.type){case 1:case 2:return Geo.f(this.endX,t.endX)&&Geo.f(this.endY,t.endY);case 3:return Geo.f(this.endX,t.endX)&&Geo.f(this.endY,t.endY)&&Geo.f(this.point1X,t.point1X)&&Geo.f(this.point1Y,t.point1Y)&&Geo.f(this.point2X,t.point2X)&&Geo.f(this.point2Y,t.point2Y);case 4:return Geo.f(this.endX,t.endX)&&Geo.f(this.endY,t.endY)&&Geo.f(this.point1X,t.point1X)&&Geo.f(this.point1Y,t.point1Y);case 5:return Geo.f(this.startAngle,t.startAngle)&&Geo.f(this.sweepAngle,t.sweepAngle)&&Geo.f(this.centerX,t.centerX)&&Geo.f(this.centerY,t.centerY)&&Geo.f(this.radiusX,t.radiusX)&&Geo.f(this.radiusY,t.radiusY);case 6:return this.isClockwiseArc===t.isClockwiseArc&&this.isLargeArc===t.isLargeArc&&Geo.f(this.xAxisRotation,t.xAxisRotation)&&Geo.f(this.endX,t.endX)&&Geo.f(this.endY,t.endY)&&Geo.f(this.radiusX,t.radiusX)&&Geo.f(this.radiusY,t.radiusY);default:return!1}}oi(t){t in SegmentType?this.type=t:U.er(this,t)}toString(t){t===void 0&&(t=-1);const i=s=>s===0?"0":s.toFixed(t);let e="";switch(this.type){case 1:t<0?e="M"+this.endX.toString()+" "+this.endY.toString():e="M"+i(this.endX)+" "+i(this.endY);break;case 2:t<0?e="L"+this.endX.toString()+" "+this.endY.toString():e="L"+i(this.endX)+" "+i(this.endY);break;case 3:t<0?e="C"+this.point1X.toString()+" "+this.point1Y.toString()+" "+this.point2X.toString()+" "+this.point2Y.toString()+" "+this.endX.toString()+" "+this.endY.toString():e="C"+i(this.point1X)+" "+i(this.point1Y)+" "+i(this.point2X)+" "+i(this.point2Y)+" "+i(this.endX)+" "+i(this.endY);break;case 4:t<0?e="Q"+this.point1X.toString()+" "+this.point1Y.toString()+" "+this.endX.toString()+" "+this.endY.toString():e="Q"+i(this.point1X)+" "+i(this.point1Y)+" "+i(this.endX)+" "+i(this.endY);break;case 5:t<0?e="B"+this.startAngle.toString()+" "+this.sweepAngle.toString()+" "+this.centerX.toString()+" "+this.centerY.toString()+" "+this.radiusX.toString()+" "+this.radiusY.toString():e="B"+i(this.startAngle)+" "+i(this.sweepAngle)+" "+i(this.centerX)+" "+i(this.centerY)+" "+i(this.radiusX)+" "+i(this.radiusY);break;case 6:t<0?e="A"+this.radiusX.toString()+" "+this.radiusY.toString()+" "+this.xAxisRotation.toString()+" "+(this.isLargeArc?1:0)+" "+(this.isClockwiseArc?1:0)+" "+this.endX.toString()+" "+this.endY.toString():e="A"+i(this.radiusX)+" "+i(this.radiusY)+" "+i(this.xAxisRotation)+" "+(this.isLargeArc?1:0)+" "+(this.isClockwiseArc?1:0)+" "+i(this.endX)+" "+i(this.endY);break;default:e=SegmentType[this.type]}return e+(this.isClosed?"z":"")}static Move=1;static Line=2;static Bezier=3;static QuadraticBezier=4;static Arc=5;static SvgArc=6;get h(){return(this.n&1)!==0}set h(t){t?this.n|=1:this.n&=-2}get wt(){return(this.n&2)!==0}set wt(t){t?this.n|=2:this.n&=-3}u(){return this.h=!0,this}close(){return this.isClosed=!0,this}bo(t){if(this.vs!==null&&t.wt===!1)return this.vs;const i=this.radiusX;let e=this.radiusY;if(e===void 0&&(e=i),i===0||e===0)return this.vs=[],this.vs;const s=this.tn,n=this.pl,o=Geo.TC(0,0,i1&&(o*=Math.sqrt(p),r*=Math.sqrt(p));let w=(h===c?-1:1)*Math.sqrt((o*o*r*r-o*o*g*g-r*r*m*m)/(o*o*g*g+r*r*m*m));isNaN(w)&&(w=0);let x=w*o*g/r,k=w*-r*m/o;isNaN(x)&&(x=0),isNaN(k)&&(k=0);const b=(s+a)/2+u*x-d*k,P=(n+f)/2+d*x+u*k,S=(V,B)=>Math.sqrt(V*V+B*B),L=(V,B,K,j)=>(V*K+B*j)/(S(V,B)*S(K,j)),C=(V,B,K,j)=>(V*j=1&&(F=0),!c&&F>0&&(F=F-2*Math.PI),c&&F<0&&(F=F+2*Math.PI);const R=o>r?o:r,O=o>r?1:o/r,X=o>r?r/o:1,Y=Geo.TC(0,0,R,M,M+F,!0),E=Transform.l();return E.Ri(),E.Fs(b,P),E.cs(this.tn,0,0),E.tt(O,X),Geometry.OC(Y,E),Transform.e(E),this.vs=Y,this.vs}get isClosed(){return(this.n&8)!==0}set isClosed(t){this.isClosed!==t&&(t?this.n|=8:this.n&=-9,this.wt=!0)}get type(){return this.H}set type(t){this.h&&U.L(this,t),this.H=t,this.wt=!0}get endX(){return this.Qi}set endX(t){this.h&&U.L(this,t),this.Qi=t,this.wt=!0}get endY(){return this._i}set endY(t){this.h&&U.L(this,t),this._i=t,this.wt=!0}get point1X(){return this.tn}set point1X(t){this.h&&U.L(this,t),this.tn=t,this.wt=!0}get point1Y(){return this.pl}set point1Y(t){this.h&&U.L(this,t),this.pl=t,this.wt=!0}get point2X(){return this.yl}set point2X(t){this.h&&U.L(this,t),this.yl=t,this.wt=!0}get point2Y(){return this.ar}set point2Y(t){this.h&&U.L(this,t),this.ar=t,this.wt=!0}get centerX(){return this.tn}set centerX(t){this.h&&U.L(this,t),this.tn=t,this.wt=!0}get centerY(){return this.pl}set centerY(t){this.h&&U.L(this,t),this.pl=t,this.wt=!0}get radiusX(){return this.yl}set radiusX(t){t<0&&U.W(t,">= zero",PathSegment,"radiusX"),this.h&&U.L(this,t),this.yl=t,this.wt=!0}get radiusY(){return this.ar}set radiusY(t){t<0&&U.W(t,">= zero",PathSegment,"radiusY"),this.h&&U.L(this,t),this.ar=t,this.wt=!0}get startAngle(){return this.Qi}set startAngle(t){this.h&&U.L(this,t),t=t%360,t<0&&(t+=360),this.Qi=t,this.wt=!0}get sweepAngle(){return this._i}set sweepAngle(t){this.h&&U.L(this,t),t>360&&(t=360),t<-360&&(t=-360),this._i=t,this.wt=!0}get isClockwiseArc(){return(this.n&4)!==0}set isClockwiseArc(t){this.h&&U.L(this,t),t?this.n|=4:this.n&=-5,this.wt=!0}get isLargeArc(){return(this.n&16)!==0}set isLargeArc(t){this.h&&U.L(this,t),t?this.n|=16:this.n&=-17,this.wt=!0}get xAxisRotation(){return this.tn}set xAxisRotation(t){this.h&&U.L(this,t),t=t%360,t<0&&(t+=360),this.tn=t,this.wt=!0}}class InputEvent{N;Tw;Dw;jg;Hg;qg;Wg;Jg;$g;Zg;Qg;_g;tm;im;ko;em;sm;nm;be;constructor(){this.N=null,this.Tw=new Point(0,0).u(),this.Dw=new Point(0,0).u(),this.jg=0,this.Hg=0,this.qg=1,this.Wg="",this.Jg="",this.$g=!1,this.Zg=!1,this.Qg=0,this._g=0,this.tm=!1,this.im=!1,this.ko=!1,this.em=null,this.sm=0,this.nm=null,this.be=null}copy(){const t=new InputEvent;return this.clone(t)}clone(t){return t.N=this.N,t.Tw.a(this.viewPoint),t.Dw.a(this.documentPoint),t.jg=this.jg,t.Hg=this.Hg,t.qg=this.qg,t.Wg=this.Wg,t.Jg=this.Jg,t.$g=this.$g,t.Zg=this.Zg,t.Qg=this.Qg,t._g=this._g,t.tm=this.tm,t.im=this.im,t.ko=this.ko,t.em=this.em,t.sm=this.sm,t.nm=this.nm,t.be=this.be,t}toString(){let t="^";return this.modifiers!==0&&(t+="M:"+this.modifiers),this.button!==0&&(t+="B:"+this.button),this.key!==""&&(t+="K:"+this.key),this.clickCount!==0&&(t+="C:"+this.clickCount),this.delta!==0&&(t+="D:"+this.delta),this.handled&&(t+="h"),this.bubbles&&(t+="b"),this.documentPoint!==null&&(t+="@"+this.documentPoint.toString()),t}get diagram(){return this.N}set diagram(t){this.N=t}get viewPoint(){return this.Tw}set viewPoint(t){this.Tw.a(t)}get documentPoint(){return this.Dw}set documentPoint(t){this.Dw.a(t)}getMultiTouchViewPoint(t,i){const e=this.diagram;return e===null||e.BC(this.event,t,i),i}getMultiTouchDocumentPoint(t,i){const e=this.diagram;return e===null||(e.BC(this.event,t,i),i.a(e.transformViewToDoc(i))),i}get modifiers(){return this.jg}set modifiers(t){this.jg=t}get button(){return this.Hg}set button(t){if(this.Hg=t,this.event===null)switch(t){case 0:this.buttons=1;return;case 1:this.buttons=4;return;case 2:this.buttons=2;return}}get buttons(){return this.qg}set buttons(t){this.qg=t}get key(){return this.Wg}set key(t){this.Wg=t}get code(){return this.Jg}set code(t){this.Jg=t}get down(){return this.$g}set down(t){this.$g=t}get up(){return this.Zg}set up(t){this.Zg=t}get clickCount(){return this.Qg}set clickCount(t){this.Qg=t}get delta(){return this._g}set delta(t){this._g=t}get isMultiTouch(){return this.tm}set isMultiTouch(t){this.tm=t}get handled(){return this.im}set handled(t){this.im=t}get bubbles(){return this.ko}set bubbles(t){this.ko=t}get event(){return this.em}set event(t){this.em=t}get isTouchEvent(){const t=this.event;return t===null?!1:t.pointerType==="touch"||t.pointerType==="pen"}get timestamp(){return this.sm}set timestamp(t){this.sm=t}get targetDiagram(){return this.nm}set targetDiagram(t){this.nm=t}get targetObject(){return this.be}set targetObject(t){this.be=t}get control(){return(this.modifiers&1)!==0}set control(t){this.modifiers=t?this.modifiers|1:this.modifiers&-2}get shift(){return(this.modifiers&4)!==0}set shift(t){this.modifiers=t?this.modifiers|4:this.modifiers&-5}get alt(){return(this.modifiers&2)!==0}set alt(t){this.modifiers=t?this.modifiers|2:this.modifiers&-3}get meta(){return(this.modifiers&8)!==0}set meta(t){this.modifiers=t?this.modifiers|8:this.modifiers&-9}get left(){const t=this.event;return t!==null&&(t.type==="mousedown"||t.type==="mouseup"||t.type==="pointerdown"||t.type==="pointerup")?this.button===0:(this.buttons&1)!==0}set left(t){t?this.buttons|=1:this.buttons&=-2}get right(){const t=this.event;return t!==null&&(t.type==="mousedown"||t.type==="mouseup"||t.type==="pointerdown"||t.type==="pointerup")?this.button===2:(this.buttons&2)!==0}set right(t){t?this.buttons|=2:this.buttons&=-3}get middle(){const t=this.event;return t!==null&&(t.type==="mousedown"||t.type==="mouseup"||t.type==="pointerdown"||t.type==="pointerup")?this.button===1:(this.buttons&4)!==0}set middle(t){t?this.buttons|=4:this.buttons&=-5}get commandKey(){const t=this.code,i=this.key;return"cxvyzagCXVYZAG".includes(i)?i.toLowerCase():t==="KeyC"?"c":t==="KeyX"?"x":t==="KeyV"?"v":t==="KeyY"?"y":t==="KeyZ"?"z":t==="KeyA"?"a":t==="KeyG"?"g":t!==""?t:i}}class DiagramEvent{N;St;om;rm;constructor(){this.N=null,this.St="",this.om=null,this.rm=null}copy(){const t=new DiagramEvent;return t.N=this.N,t.St=this.St,t.om=this.om,t.rm=this.rm,t}toString(){let t="*"+this.name;return this.subject!==null&&(t+=":"+this.subject.toString()),this.parameter!==null&&(t+="("+this.parameter.toString()+")"),t}get diagram(){return this.N}set diagram(t){this.N=t}get name(){return this.St}set name(t){this.St=t}get subject(){return this.om}set subject(t){this.om=t}get parameter(){return this.rm}set parameter(t){this.rm=t}}var ChangeType=(y=>(y[y.Transaction=1]="Transaction",y[y.Property=2]="Property",y[y.Insert=3]="Insert",y[y.Remove=4]="Remove",y))(ChangeType||{});class ChangedEvent{au;lm;en;ki;N;cu;ac;cc;fc;uc;constructor(){this.au=2,this.lm="",this.en="",this.ki=null,this.N=null,this.cu=null,this.ac=null,this.cc=null,this.fc=null,this.uc=null}static Transaction=1;static Property=2;static Insert=3;static Remove=4;clear(){this.ki=null,this.N=null,this.cu=null,this.ac=null,this.cc=null,this.fc=null,this.uc=null}copy(){const t=new ChangedEvent;t.au=this.au,t.lm=this.lm,t.en=this.en,t.ki=this.ki,t.N=this.N,t.cu=this.cu;let i=this.ac;return U.G(i)&&U.it(i.copyFrozen)?t.ac=i.copyFrozen():t.ac=i,i=this.cc,U.G(i)&&U.it(i.copyFrozen)?t.cc=i.copyFrozen():t.cc=i,i=this.fc,U.G(i)&&U.it(i.copyFrozen)?t.fc=i.copyFrozen():t.fc=i,i=this.uc,U.G(i)&&U.it(i.copyFrozen)?t.uc=i.copyFrozen():t.uc=i,t}oi(t){t in ChangeType?this.change=t:U.er(this,t)}toString(){let t="";return this.change===1?t+="* ":this.change===2?t+=this.model!==null?"!m":"!d":t+=(this.model!==null?"!m":"!d")+this.change,this.propertyName&&typeof this.propertyName=="string"&&(t+=" "+this.propertyName),this.modelChange&&this.modelChange!==this.propertyName&&(t+=" "+this.modelChange),t+=": ",this.change===1?this.oldValue!==null&&(t+=" "+this.oldValue):(this.object!==null&&(t+=U.toString(this.object)),this.oldValue!==null&&(t+=" old: "+U.toString(this.oldValue)),this.oldParam!==null&&(t+=" "+this.oldParam),this.newValue!==null&&(t+=" new: "+U.toString(this.newValue)),this.newParam!==null&&(t+=" "+this.newParam)),t}getValue(t){return t?this.oldValue:this.newValue}getParam(t){return t?this.oldParam:this.newParam}canUndo(){return this.model!==null||this.diagram!==null}undo(){this.canUndo()&&(this.model!==null?this.model.changeState(this,!0):this.diagram!==null&&this.diagram.VC(this,!0))}canRedo(){return this.model!==null||this.diagram!==null}redo(){this.canRedo()&&(this.model!==null?this.model.changeState(this,!1):this.diagram!==null&&this.diagram.VC(this,!1))}get model(){return this.ki}set model(t){this.ki=t}get diagram(){return this.N}set diagram(t){this.N=t}get change(){return this.au}set change(t){this.au=t}get modelChange(){return this.lm}set modelChange(t){this.lm=t}get propertyName(){return this.en}set propertyName(t){this.en=t}get isTransactionFinished(){return this.au===1&&(this.en==="CommittedTransaction"||this.en==="FinishedUndo"||this.en==="FinishedRedo")}get object(){return this.cu}set object(t){this.cu=t}get oldValue(){return this.ac}set oldValue(t){this.ac=t}get oldParam(){return this.cc}set oldParam(t){this.cc=t}get newValue(){return this.fc}set newValue(t){this.fc=t}get newParam(){return this.uc}set newParam(t){this.uc=t}}class Transaction{zC;St;$k;constructor(){this.zC=new List().u(),this.St="",this.$k=!1}toString(t){let i="Transaction: "+this.name+" "+this.changes.count.toString()+(this.isComplete?"":", incomplete");if(t!==void 0&&t>0){const e=this.changes.count;for(let s=0;s=0;i--){const e=t.elt(i);e!==null&&e.clear()}t.clear(),t.u()}canUndo(){return this.isComplete}undo(){if(this.canUndo())for(let t=this.changes.count-1;t>=0;t--){const i=this.changes.elt(t);i!==null&&i.undo()}}canRedo(){return this.isComplete}redo(){if(!this.canRedo())return;const t=this.changes.count;for(let i=0;i=t;e--){const s=i.elt(e);s!==null&&s.undo(),i.Pt(),i.removeAt(e)}i.u()}thaw(){this.changes.Pt()}optimize(){if(!this.isComplete)return;const t=this.changes;t.Pt();const i=new GMap;for(let s=0;s0&&t.setElt(r,null),o.set(n.propertyName,s))}let e=0;for(let s=0;se&&t.setElt(e,n),e++)}for(;t.length>e;)t.pop();t.u()}get changes(){return this.zC}get name(){return this.St}set name(t){this.St=t}get isComplete(){return this.$k}set isComplete(t){this.$k=t}}class UndoManager{Fw;Oi;XC;Os;Zk;hm;Vn;Qk;_k;sn;dc;Rw;Is;vw;Ow;am;Iw;constructor(t){this.Fw=new GSet,this.Oi=!1,this.XC=new List().u(),this.Os=-1,this.Zk=999,this.Is=!1,this.hm=null,this.Vn=0,this.Qk=!1,this._k=23,this.sn=new List().u(),this.dc=new List,this.Rw=!0,this.vw=!1,this.Ow=!1,this.am=!1,this.Iw=!1,t&&Object.assign(this,t)}toString(t){let i="UndoManager "+this.historyIndex+"<"+this.history.count+"<="+this.maxHistoryLength;i+="[";let e=this.nestedTransactionNames.count;for(let s=0;s0&&(i+=" "),i+=this.nestedTransactionNames.elt(s);if(i+="]",t!==void 0&&t>0){e=this.history.count;for(let s=0;s=0;i--){const e=t.elt(i);e!==null&&e.clear()}t.clear(),this.Os=-1,t.u(),this.Is=!1,this.hm=null,this.Vn=0,this.sn.Pt(),this.sn.clear(),this.sn.u(),this.dc.clear(),this.vw=!1,this.Ow=!1,this.am=!1,this.Iw=!1}copyProperties(t){this.isEnabled=t.isEnabled,this.maxHistoryLength=t.maxHistoryLength,this.cm=t.cm}addModel(t){this.Fw.add(t)}removeModel(t){this.Fw.delete(t)}startTransaction(t){if(t===void 0&&(t=""),t===null&&(t=""),this.isUndoingRedoing)return!1;this.Rw===!0&&(this.Rw=!1,this.Vn++,this.wl||this.xl("StartingFirstTransaction",t,this.currentTransaction),this.Vn>0&&this.Vn--),this.isEnabled&&(this.sn.Pt(),this.sn.add(t),this.sn.u(),this.currentTransaction===null?this.dc.add(0):this.dc.add(this.currentTransaction.changes.count)),this.Vn++;const i=this.transactionLevel===1;return i&&(this.wl||this.xl("StartedTransaction",t,this.currentTransaction)),i}commitTransaction(t){return t===void 0&&(t=""),this.YC(!0,t)}rollbackTransaction(){return this.YC(!1,"")}YC(t,i){if(this.isUndoingRedoing)return!1;this.cm&&this.transactionLevel<1&&U.ni("Ending transaction without having started a transaction: "+i);const e=this.transactionLevel===1;let s=this.currentTransaction;e&&t&&(this.wl||this.xl("CommittingTransaction",i,s));let n=0;if(this.transactionLevel>0&&(this.Vn--,this.isEnabled)){const o=this.sn.count;o>0&&(i===""&&(i=this.sn.elt(0)),this.sn.Pt(),this.sn.removeAt(o-1),this.sn.u());const r=this.dc.count;r>0&&(n=this.dc.elt(r-1),this.dc.removeAt(r-1))}if(e){if(t){if(this.am=!1,s===null&&i!==""&&(s=this.currentTransaction),this.isEnabled&&s!==null){const o=s;o.isComplete||(o.isComplete=!0,o.name=i),this.discardHistoryAfterIndex();const r=this.history;r.Pt();const l=this.maxHistoryLength;if(l>=0){if(l===0)r.clear();else if(r.count>=l){const h=r.elt(0);h!==null&&h.clear(),r.removeAt(0),this.Os--}}l!==0&&(r.count===0||r.get(r.count-1)!==o)&&(r.add(o),this.Os++),r.u(),s=o}this.wl||this.xl("CommittedTransaction",i,s)}else{this.Is=!0;try{this.isEnabled&&s!==null&&(s.isComplete=!0,s.undo())}finally{this.wl||this.xl("RolledBackTransaction",i,s),this.Is=!1}s!==null&&s.clear()}return this.hm=null,this.Ew&&this.clear(),this.Ew=!1,this.Uw=!1,!0}else return this.isEnabled&&!t&&s!==null&&s.uF(n),!1}discardHistoryAfterIndex(){if(this.isUndoingRedoing||!this.canRedo())return;const t=this.history;t.Pt();for(let i=t.count-1;i>this.historyIndex;i--){const e=t.elt(i);e!==null&&e.clear(),t.removeAt(i),this.am=!0}t.u()}thaw(){this.history.Pt()}SE(t){this.Vn+=t,this.Vn<0&&(this.Vn=0)}canUndo(){if(!this.isEnabled||this.transactionLevel>0)return!1;const t=this.transactionToUndo;return!!(t!==null&&t.canUndo())}undo(){if(!this.canUndo())return;const t=this.transactionToUndo;try{this.Is=!0,this.xl("StartingUndo","Undo",t),this.Os--,t.undo()}catch(i){U.ni("undo error: "+i.toString())}finally{this.xl("FinishedUndo","Undo",t),this.Is=!1}}canRedo(){if(!this.isEnabled||this.transactionLevel>0)return!1;const t=this.transactionToRedo;return!!(t!==null&&t.canRedo())}redo(){if(!this.canRedo())return;const t=this.transactionToRedo;try{this.Is=!0,this.xl("StartingRedo","Redo",t),this.Os++,t.redo()}catch(i){U.ni("redo error: "+i.toString())}finally{this.xl("FinishedRedo","Redo",t),this.Is=!1}}xl(t,i,e){e===void 0&&(e=null);const s=new ChangedEvent;s.change=1,s.propertyName=t,s.object=e,s.oldValue=i;const n=this.models;for(;n.next();){const o=n.value;s.model=o,o.dF(s)}}handleChanged(t){if(this.isEnabled&&!this.isUndoingRedoing&&!this.skipsEvent(t)){let i=this.currentTransaction;i===null&&(i=new Transaction,this.hm=i);const e=t.copy(),s=i.changes;if(s.Pt(),s.add(e),s.u(),this.cm&&this._k>0&&this.transactionLevel<=0&&!this.Rw){const n=t.diagram;if(n!==null&&n.Vh===!1)return;U.ni("Change not within a transaction: "+e.toString()),this._k--}}}skipsEvent(t){if(t===null||t.change===1)return!0;const i=t.object;if(i===null)return!1;if(i.layer!==void 0){const e=i.layer;if(e!==null&&e.isTemporary)return!0}else if(i.isTemporary)return!0;return!1}get models(){return this.Fw.iterator}get isEnabled(){return this.Oi}set isEnabled(t){this.Oi=t}get transactionToUndo(){return this.historyIndex>=0&&this.historyIndex<=this.history.count-1?this.history.elt(this.historyIndex):null}get transactionToRedo(){return this.historyIndex0}get cm(){return this.Qk}set cm(t){this.Qk=t}get nestedTransactionNames(){return this.sn}get Ew(){return this.vw}set Ew(t){this.vw=t}get Uw(){return this.Ow}set Uw(t){this.Ow=t}get wl(){return this.Iw}set wl(t){this.Iw=t}get isJustDiscarded(){return this.am}}class Tool{N;St;Oi;tP;iP;fm;GC;constructor(){GSet.Ki(this),this.N=Diagram.um(),this.St="",this.Oi=!0,this.tP=!1,this.iP=null,this.GC=new InputEvent,this.fm=-1}get diagram(){return this.N}set diagram(t){t instanceof Diagram&&(this.N=t)}toString(){return this.name!==""?this.name+" Tool":U.Dn(this.constructor)}updateAdornments(t){}canStart(){return this.isEnabled}doStart(){}doActivate(){this.isActive=!0}doDeactivate(){this.isActive=!1}doStop(){}doCancel(){this.transactionResult=null,this.stopTool()}stopTool(){const t=this.diagram;t.currentTool===this&&(t.currentTool=null,t.currentCursor="")}doMouseDown(){!this.isActive&&this.canStart()&&this.doActivate()}doMouseMove(){}doMouseUp(){this.stopTool()}doMouseWheel(){}canStartMultiTouch(){return!0}standardPinchZoomStart(){const t=this.diagram,i=t.lastInput,e=i.getMultiTouchViewPoint(0,Point.V(NaN,NaN)),s=i.getMultiTouchViewPoint(1,Point.V(NaN,NaN));if(!e.isReal()||!s.isReal()){Point.e(e),Point.e(s);return}if(this.doCancel(),t.getInputOption("hasGestureZoom")){t.eP=t.scale;const n=s.x-e.x,o=s.y-e.y,r=Math.sqrt(n*n+o*o);t.sP=r,i.bubbles=!1}Point.e(e),Point.e(s)}standardPinchZoomMove(){const t=this.diagram,i=t.lastInput,e=i.getMultiTouchViewPoint(0,Point.V(NaN,NaN)),s=i.getMultiTouchViewPoint(1,Point.V(NaN,NaN));if(!e.isReal()||!s.isReal()){Point.e(e),Point.e(s);return}if(this.doCancel(),t.getInputOption("hasGestureZoom")){const n=s.x-e.x,o=s.y-e.y,l=Math.sqrt(n*n+o*o)/t.sP,h=new Point((Math.min(s.x,e.x)+Math.max(s.x,e.x))/2,(Math.min(s.y,e.y)+Math.max(s.y,e.y))/2),c=t.eP*l,a=t.commandHandler;if(c!==t.scale&&a.canResetZoom(c)){const f=t.zoomPoint;t.zoomPoint=h,a.resetZoom(c),t.zoomPoint=f}i.bubbles=!1}Point.e(e),Point.e(s)}doKeyDown(){this.diagram.lastInput.code==="Escape"&&this.doCancel()}doKeyUp(){}startTransaction(t){return t===void 0&&(t=this.name),this.transactionResult=null,this.diagram.startTransaction(t)}stopTransaction(){const t=this.diagram;return this.transactionResult===null?t.rollbackTransaction():t.commitTransaction(this.transactionResult)}standardMouseSelect(){const t=this.diagram;if(!t.allowSelect)return;const i=t.lastInput,e=t.findPartAt(i.documentPoint,!1);if(e!==null){if(U.tr?i.meta:i.control){t.D("ChangingSelection",t.selection);let s=e;for(;s!==null&&!s.canSelect();)s=s.containingGroup;s!==null&&(s.isSelected=!s.isSelected),t.D("ChangedSelection",t.selection)}else if(i.shift){if(!e.isSelected){t.D("ChangingSelection",t.selection);let s=e;for(;s!==null&&!s.canSelect();)s=s.containingGroup;s!==null&&(s.isSelected=!0),t.D("ChangedSelection",t.selection)}}else if(!e.isSelected){let s=e;for(;s!==null&&!s.canSelect();)s=s.containingGroup;s!==null&&t.select(s)}}else i.left&&!(U.tr?i.meta:i.control)&&!i.shift&&t.clearSelection()}standardMouseClick(t,i){t===void 0&&(t=null),i===void 0&&(i=o=>!o.layer?.isTemporary);const e=this.diagram,s=e.lastInput,n=e.findObjectAt(s.documentPoint,t,i);return s.targetObject=n,this.gF(n,s,e),s.handled}gF(t,i,e){if(i.handled=!1,t!==null&&!t.isEnabledObject())return;let s=0;i.left?i.clickCount===1?s=1:i.clickCount===2?s=2:s=1:i.right&&i.clickCount===1&&(s=3);let n="ObjectSingleClicked";if(t!==null){switch(s){case 1:n="ObjectSingleClicked";break;case 2:n="ObjectDoubleClicked";break;case 3:n="ObjectContextClicked";break}s!==0&&e.D(n,t)}else{switch(s){case 1:n="BackgroundSingleClicked";break;case 2:n="BackgroundDoubleClicked";break;case 3:n="BackgroundContextClicked";break}s!==0&&e.D(n)}if(t!==null)for(;t!==null;){let o=null;switch(s){case 1:o=t.click;break;case 2:o=t.doubleClick?t.doubleClick:t.click;break;case 3:o=t.contextClick;break}if(o!==null&&(o(i,t),i.handled))break;t=t.panel}else{let o=null;switch(s){case 1:o=e.click;break;case 2:o=e.doubleClick?e.doubleClick:e.click;break;case 3:o=e.contextClick;break}o!==null&&o(i)}}standardMouseOver(){const t=this.diagram,i=t.lastInput;if(t.animationManager.pi===!0)return;const e=t.skipsUndoManager;t.skipsUndoManager=!0;let s=t.viewportBounds.containsPoint(i.documentPoint)?t.findObjectAt(i.documentPoint,null,null):null;i.event&&(i.event.type==="pointercancel"||i.event.type==="pointerout")&&(s=null),i.targetObject=s;let n=!1;if(s!==t.gc){let o=t.gc;const r=o;for(t.gc=s,this.doCurrentObjectChanged(o,s),i.handled=!1;o!==null;){const l=o.mouseLeave;if(l!==null&&(s===o||s!==null&&s.isContainedBy(o)||(l(i,o,s),n=!0,i.handled)))break;o=o.panel}for(o=r,i.handled=!1;s!==null;){const l=s.mouseEnter;if(l!==null&&(o===s||o!==null&&o.isContainedBy(s)||(l(i,s,o),n=!0,i.handled)))break;s=s.panel}s=t.gc}if(s!==null){let o=s,r="";for(;o!==null&&(r=o.cursor,r==="");)o=o.panel;for(t.currentCursor=r,i.handled=!1,o=s;o!==null;){const l=o.mouseOver;if(l!==null&&(l(i,o),n=!0,i.handled))break;o=o.panel}}else{this.doUpdateCursor(null);const o=t.mouseOver;o!==null&&(o(i),n=!0)}n&&t.requestUpdate(),t.skipsUndoManager=e}doUpdateCursor(t){const i=this.diagram;i&&(i.currentCursor="")}doCurrentObjectChanged(t,i){}standardMouseWheel(){const t=this.diagram,i=t.lastInput;let e=i.delta;if(e===0||!t.documentBounds.isReal())return;const s=t.commandHandler,n=t.toolManager.mouseWheelBehavior;if(s!==null&&(n===2&&!i.shift||n===1&&i.control)){if(e>0?s.canIncreaseZoom():s.canDecreaseZoom()){const o=t.zoomPoint;t.zoomPoint=i.viewPoint,e>0?s.increaseZoom():s.decreaseZoom(),t.zoomPoint=o}i.bubbles=!1}else if(n===2&&i.shift||n===1&&!i.control){const o=t.position.copy(),r=i.event,l=r.deltaMode;let h=r.deltaX,c=r.deltaY,a="pixel";if((h!==0||c!==0)&&!i.shift){switch(l){case 0:a="pixel";break;case 1:a="line";break;case 2:a="page";break}if(h!==0&&t.allowHorizontalScroll){const f=t.scrollHorizontalLineChange;h=h*(f/16),t.scroll(a,h>0?"right":"left",Math.abs(h))}if(c!==0&&t.allowVerticalScroll){const f=t.scrollVerticalLineChange;c=c*(f/16),t.scroll(a,c>0?"down":"up",Math.abs(c))}}else!i.shift&&t.allowVerticalScroll?(e=e*3*t.scrollVerticalLineChange,t.scroll(a,e>0?"up":"down",Math.abs(e))):i.shift&&t.allowHorizontalScroll&&(e=e*3*t.scrollHorizontalLineChange,t.scroll(a,e>0?"left":"right",Math.abs(e)));this.doWheelChange(t,o,i)}}doWheelChange(t,i,e){(!t.position.equals(i)||e.event.wheelDeltaX!==0)&&(e.bubbles=!1)}standardWaitAfter(t,i){i===void 0&&(i=this.diagram.lastInput),this.cancelWaitAfter();const e=this,s=i.clone(this.GC);this.fm=U.ir(()=>e.doWaitAfter(s),t)}cancelWaitAfter(){this.fm!==-1&&U.Tg(this.fm),this.fm=-1}doWaitAfter(t){}findToolHandleAt(t,i){const s=this.diagram.findObjectAt(t,n=>{for(;n!==null&&!(n.panel instanceof Adornment);)n=n.panel;return n});return s===null?null:s.part.category===i?s:null}isBeyondDragSize(t,i){const e=this.diagram;t===void 0&&(t=e.firstInput.viewPoint),i===void 0&&(i=e.lastInput.viewPoint);const s=e.toolManager.dragSize;let n=s.width,o=s.height;return e.firstInput.isTouchEvent&&(n+=6,o+=6),Math.abs(i.x-t.x)>n||Math.abs(i.y-t.y)>o}get name(){return this.St}set name(t){U.s(t,"string",Tool,"name"),this.St=t}get isEnabled(){return this.Oi}set isEnabled(t){U.s(t,"boolean",Tool,"isEnabled"),this.Oi=t}get isActive(){return this.tP}set isActive(t){U.s(t,"boolean",Tool,"isActive"),this.tP=t}get transactionResult(){return this.iP}set transactionResult(t){t!==null&&U.s(t,"string",Tool,"transactionResult"),this.iP=t}}var WheelMode=(y=>(y[y.Scroll=1]="Scroll",y[y.Zoom=2]="Zoom",y[y.None=3]="None",y))(WheelMode||{}),GestureMode=(y=>(y[y.Zoom=1]="Zoom",y[y.Cancel=2]="Cancel",y[y.None=3]="None",y))(GestureMode||{});class ToolManager extends Tool{KC;jC;HC;nP;oP;rP;lP;hP;aP;cP;dm;zh;constructor(t){super(),this.name="ToolManager",this.KC=new List,this.jC=new List,this.HC=new List,this.nP=850,this.oP=850,this.rP=new Size(2,2).$(),this.lP=5e3,this.hP=1,this.aP=1,this.cP=null,this.dm=null,this.zh=-1,t&&Object.assign(this,t)}static WheelScroll=1;static WheelZoom=2;static WheelNone=3;static GestureZoom=1;static GestureCancel=2;static GestureNone=3;get mouseWheelBehavior(){return this.hP}set mouseWheelBehavior(t){this.hP=t}get gestureBehavior(){return this.aP}set gestureBehavior(t){this.aP=t}initializeStandardTools(){}updateAdornments(t){const i=this.currentToolTip;if(i instanceof Adornment&&this.dm===t){const e=i.adornedObject;(t!==null?e!==null&&e.part===t:e===null)?this.showToolTip(i,e):this.hideToolTip()}}doMouseDown(){const t=this.diagram,i=t.lastInput;if(i.isTouchEvent&&this.gestureBehavior===2&&(i.bubbles=!1),i.isMultiTouch){if(this.cancelWaitAfter(),this.gestureBehavior===3){i.bubbles=!0;return}if(this.gestureBehavior===2)return;if(t.currentTool.canStartMultiTouch()){t.currentTool.standardPinchZoomStart();return}}const e=t.undoManager,s=this.mouseDownTools.length;for(let n=0;n0&&s!==1/0){const n=this;this.zh=U.ir(()=>n.hideToolTip(),s)}}positionToolTip(t,i){if(t.hasPlaceholder())return;const e=t,s=this.diagram,n=s.lastInput.documentPoint.copy(),o=e.measuredBounds,r=s.viewportBounds;s.lastInput.isTouchEvent&&(n.x-=o.width),n.x+o.width>r.right&&(n.x-=o.width+5/s.scale),n.xr.bottom?n.y-=o.height+5/s.scale:n.y+=20/s.scale,n.y30&&t.Vw(),t.WC(this.draggedParts),t.gu=!0,this.startTransaction("Drag"),this.startPoint=t.firstInput.documentPoint,t.isMouseCaptured=!0,t.allowDragOut&&this.pF()}SP(t){if(!this.dragsLink)return;const i=this.diagram,e=i.model.mm(),s=t.first();e&&t.count===1&&s instanceof Link&&this.mayDragLink(s)?(this.draggedLink=s,this.draggedLink.canRelinkFrom()&&this.draggedLink.canRelinkTo()&&this.draggedLink.clearAdornments(),this.nn=i.toolManager.findTool("Relinking"),this.nn===null&&(this.nn=new RelinkingTool,this.nn.diagram=i),this.nn.originalLink=this.draggedLink):(this.draggedLink=null,this.nn=null)}mayDragLink(t){const i=this.diagram;return i!==null&&i.allowRelink}computeEffectiveCollection(t,i){return this.diagram.commandHandler.computeEffectiveCollection(t,i)}Es(t){return t===void 0?new DraggingInfo(Point.xo):this.isGridSnapEnabled?new DraggingInfo(new Point(Math.round(t.x*1e3)/1e3,Math.round(t.y*1e3)/1e3)):new DraggingInfo(t.copy())}doDeactivate(){this.isActive=!1;const t=this.diagram;this.diagram.layout.isRealtime=this.PP,t.gu=!1,t.bl=!0,t.cacheGroupExternalLinks(!1),t.stopAutoScroll(),this.MP(),t.NP(this.draggedParts),this.uu=null,this.currentPart=null,this.draggedParts=null,this.isDragOutStarted=!1,this.fu=!1,DraggingTool.yF(),this.JC(),this.mc.i(NaN,NaN),DraggingTool.Yh!==null&&(DraggingTool.Yh.currentCursor=""),DraggingTool.Yh=null,DraggingTool.dt=null,this.kl(),t.isMouseCaptured=!1,t.currentCursor="",t.du=!1,this.stopTransaction(),t.CP(!0)}stopTransaction(){const t=this.diagram,i=super.stopTransaction();return i&&t.undoManager.transactionToUndo!==null&&t.undoManager.transactionToUndo.optimize(),i}MP(){const t=this.diagram,i=t.skipsUndoManager;t.skipsUndoManager=!0;const e=t.lastInput;this.$C(e,null),t.skipsUndoManager=i,this.cr.length=0}ZC(){this.kl(),this.LP();const t=this.diagram;this.mc.isReal()&&(t.position=this.mc),t.stopAutoScroll()}doCancel(){this.kl(),this.LP();const t=this.diagram;this.mc.isReal()&&(t.position=this.mc),this.stopTool()}doKeyDown(){const t=this.diagram;if(!this.isActive)return;const i=t.lastInput,e=t.previousInput;i.code==="Escape"?this.doCancel():(i.code!==e.code||i.modifiers!==e.modifiers)&&this.doMouseMove()}doKeyUp(){this.isActive&&this.doMouseMove()}wF(t,i){let e=1/0,s=1/0,n=-1/0,o=-1/0;const r=t.iterator;for(;r.next();){const l=r.value;if(!l.isVisible())continue;const h=l.location,c=h.x,a=h.y;isNaN(c)||isNaN(a)||(cn&&(n=c),a>o&&(o=a))}return e===1/0?i.i(0,0,0,0):i.i(e,s,n-e,o-s),i}AP(t){if(this.copiedParts!==null)return;const i=this.diagram;if(t&&(i.isReadOnly||i.isModelReadOnly)||this.draggedParts===null)return;const e=i.undoManager;e.isEnabled&&e.isInTransaction?e.currentTransaction!==null&&e.currentTransaction.changes.count>0&&(i.undoManager.rollbackTransaction(),i.startTransaction("Drag")):this.LP(),i.skipsUndoManager=!t,i.partManager.addsToTemporaryLayer=!t,this.startPoint=i.firstInput.documentPoint;const s=this.copiesEffectiveCollection?this.draggedParts.toKeySet():i.selection,n=i.copyParts(s,i,!0),o=new GMap,r=this.draggedParts.iterator;for(;r.next();){const h=r.key;if(h.ke()&&h.canCopy()){const c=n.get(h);if(c===null)continue;c.location=h.location,c.ensureBounds(),o.set(c,this.Es(c.location))}}const l=n.iterator;for(;l.next();){const h=l.value;h instanceof Link&&h.canCopy()&&o.set(h,this.Es())}if(this.copiedParts=o,this.SP(o.toKeySet()),this.draggedLink!==null){const h=this.draggedLink,c=h.routeBounds;h.fr(this.startPoint.x-(c.x+c.width/2),this.startPoint.y-(c.y+c.height/2))}this.doUpdateCursor(null)}kl(){const t=this.diagram;if(this.copiedParts!==null){if(t.removeParts(this.copiedParts.toKeySet(),!1),this.copiedParts=null,this.draggedParts!==null){const i=this.draggedParts.iterator;for(;i.next();)if(i.key instanceof Link){const s=i.value;s.point=new Point(0,0)}}this.doUpdateCursor(null)}t.skipsUndoManager=!1,t.partManager.addsToTemporaryLayer=!1,this.startPoint=t.firstInput.documentPoint}JC(){this.draggedLink!==null&&(this.dragsLink&&this.nn!==null&&(this.nn.stopDraggingMouseMove(),this.nn.originalLink=null),this.draggedLink=null,this.nn=null)}pc(t,i){if(t===null)return;const e=this.diagram,s=this.startPoint,n=Point.l();n.a(e.lastInput.documentPoint),this.moveParts(t,n.subtract(s),i),Point.e(n),e.getRenderingHint("temporaryPixelRatio")===!0&&e.Pl===null&&e.avgSpf>30&&(e.Vw(),e.mu())}moveParts(t,i,e){e===void 0&&(e=!1);const s=this.diagram;s!==null&&s.TP(t,i,this.dragOptions,e)}LP(){if(this.draggedParts===null)return;const t=this.diagram;let i=this.draggedParts.iterator;for(;i.next();){const e=i.key;e.ke()&&(e.location=i.value.point)}for(i=this.draggedParts.iterator;i.next();){const e=i.key;if(e instanceof Link&&e.suspendsRouting){const s=i.value.point;this.draggedParts.set(e,this.Es()),e.fr(-s.x,-s.y)}}t.maybeUpdate()}xF(t){if(t===null)return!0;const i=t.part;return!!(i===null||i instanceof Adornment||i.layer?.isTemporary||this.draggedParts&&this.draggedParts.has(i)||this.copiedParts&&this.copiedParts.has(i))}DP(t){const i=this.diagram;this.dragsLink&&(this.draggedLink!==null&&(this.draggedLink.fromNode=null,this.draggedLink.toNode=null),this.QC(!1));const e=this.findDragOverObject(t),s=i.lastInput;s.targetObject=e,this.doUpdateCursor(e);const n=i.skipsUndoManager;let o=!1;try{if(i.skipsUndoManager=!0,o=this.$C(s,e),!this.isActive&&DraggingTool.dt===null)return;const r=e!==null?e.part:null;if(r===null||i.handlesDragDropForTopLevelParts&&r.isTopLevel&&!(r instanceof Group)){const l=i.mouseDragOver;l!==null&&(l(s),o=!0)}if(!this.isActive&&DraggingTool.dt===null||(this.doDragOver(t,e),!this.isActive&&DraggingTool.dt===null))return}finally{i.skipsUndoManager=n,o&&i.maybeUpdate()}this.uu=e,!i.isReadOnly&&(i.allowMove||i.allowCopy)&&(i.allowHorizontalScroll||i.allowVerticalScroll)&&i.doAutoScroll(s.viewPoint)}findDragOverObject(t){return this.diagram.FP(t,null,i=>!this.xF(i))}doUpdateCursor(t){const i=this.diagram;(t===null||this.uu!==t)&&(!this.diagram.currentTool.isActive||this.mayCopy()?i.currentCursor=this.copyCursor:this.mayMove()?i.currentCursor=this.moveCursor:this.mayDragOut()&&(i.currentCursor=this.nodropCursor))}$C(t,i){let e=!1,s=this.cr.length;const n=s>0?this.cr[0]:null;if(i===n)return!1;t.handled=!1;for(let r=0;rs.findValidLinkablePort(c,i)),r=Point.l();let l=1/0,h=null;for(const c=o.iterator;c.next();){const a=c.value;if(a.part===null)continue;const u=a.getDocumentPoint(Spot.Center,r),d=t.distanceSquaredPoint(u);dc.suspendsRouting=!1)}}if(this.doDropOnto(t,e),!this.isActive&&DraggingTool.dt===null)return;const o=Rect.l(),r=i.selection.iterator;for(;r.next();){const l=r.value;l instanceof Node&&this.kF(i,l,o)}Rect.e(o)}bF(t,i){const e=this.diagram,s=i.part;if(e.handlesDragDropForTopLevelParts&&s!==null&&s.isTopLevel&&!(s instanceof Group)){const n=e.mouseDrop;n!==null&&n(t)}}kF(t,i,e){if(!i.canAvoid())return;let s=!1;e=i.getAvoidableRect(e),t.viewportBounds.containsRect(e)&&(s=!0);const n=this.copiedParts||this.draggedParts;if(n===null)return;const o=t.OP(e,l=>l.part,l=>l instanceof Link,!0,l=>l instanceof Link,s);if(o.count===0)return;const r=o.iterator;for(;r.next();){const l=r.value;n.has(l)&&n.has(i)||!l.isMemberOf(i)&&l.isAvoiding&&l.invalidateRoute()}}doDropOnto(t,i){}doMouseMove(){if(!this.isActive)return;const t=this.diagram,i=t.lastInput;if(this.simulatedMouseMove(i.event,i.documentPoint,i.targetDiagram))return;this.currentPart!==null&&this.draggedParts!==null&&(this.mayCopy()?(this.AP(!1),this.pc(this.copiedParts,!1)):this.mayMove()?(this.kl(),this.pc(this.draggedParts,!0)):this.mayDragOut()?(this.AP(!1),this.pc(this.copiedParts,!1)):this.kl(),this.DP(t.lastInput.documentPoint))}doMouseUp(){if(!this.isActive)return;const t=this.diagram,i=t.lastInput;if(this.simulatedMouseUp(i.event,i.documentPoint,i.targetDiagram))return;let e=!1;const s=this.mayCopy();if(s&&this.copiedParts!==null?(this.kl(),this.AP(!0),this.pc(this.copiedParts,!1),this.copiedParts!==null&&(t.D("ChangingSelection",t.selection),t.clearSelection(!0),this.copiedParts.iteratorKeys.each(n=>{n.isSelected=!0}))):(e=!0,this.kl(),this.mayMove()&&(this.pc(this.draggedParts,!0),this.DP(t.lastInput.documentPoint))),this.fu=!0,this.iL(t.lastInput.documentPoint),this.isActive){const n=s&&this.copiedParts,o=n?this.copiedParts?.toKeySet():this.draggedParts?this.draggedParts.toKeySet():null;this.copiedParts=null,e&&this.PF(),t.invalidateDocumentBounds(),t.NP(this.draggedParts),this.transactionResult=n?"Copy":"Move",t.D(n?"SelectionCopied":"SelectionMoved",o)}this.stopTool(),s&&t.D("ChangedSelection",t.selection)}simulatedMouseMove(t,i,e){if(DraggingTool.dt===null)return!1;const s=DraggingTool.dt.diagram;e instanceof Diagram||(e=null);const n=DraggingTool.Yh;if(e!==n){if(n!==null&&n!==s){n.stopAutoScroll(),DraggingTool.dt.isDragOutStarted=!1;const r=n.toolManager.findTool("Dragging");r!==null&&r.doSimulatedDragLeave()}if(DraggingTool.Yh=e,e!==null&&e!==s){DraggingTool.dt.ZC();const r=e.toolManager.findTool("Dragging");r!==null&&(r.eL(),r.doSimulatedDragEnter())}this.doUpdateCursor(null)}if(e===null||e===s||!e.allowDrop||e.isReadOnly||!e.allowInsert)return!1;const o=e.toolManager.findTool("Dragging");if(o!==null){let r=i;t!==null&&(t.targetTouches!==void 0&&(t.targetTouches.length>0?t=t.targetTouches[0]:t.changedTouches.length>0&&(t=t.changedTouches[0])),r=e.getMouse(t)),e.lastInput.documentPoint=r,e.lastInput.viewPoint=e.transformDocToView(r),e.lastInput.down=!1,e.lastInput.up=!1,o.doSimulatedDragOver()}return!0}simulatedMouseUp(t,i,e){if(DraggingTool.dt===null)return!1;const s=DraggingTool.Yh,n=DraggingTool.dt.diagram;if(e===null)return DraggingTool.dt.doCancel(),!0;if(e!==s){if(s!==null){const r=s.toolManager.findTool("Dragging");if(s!==null&&s!==n&&r!==null)return s.stopAutoScroll(),DraggingTool.dt.isDragOutStarted=!1,r.doSimulatedDragLeave(),!1}DraggingTool.Yh=e;const o=e.toolManager.findTool("Dragging");o!==null&&(DraggingTool.dt.ZC(),o.eL(),o.doSimulatedDragEnter())}if(e!==this.diagram){let o=i;t!==null?(t.targetTouches!==void 0&&(t.targetTouches.length>0?t=t.targetTouches[0]:t.changedTouches.length>0&&(t=t.changedTouches[0])),o=e.getMouse(t)):o===null&&(o=new Point),e.lastInput.documentPoint=o,e.lastInput.viewPoint=e.transformDocToView(o),e.lastInput.down=!1,e.lastInput.up=!0;const r=e.toolManager.findTool("Dragging");r!==null&&r.doSimulatedDrop();const l=DraggingTool.dt;if(l!==null){const h=l.mayCopy();l.transactionResult=h?"Copy":"Move",l.stopTool()}return!0}return!1}PF(){if(this.draggedParts===null)return;const t=this.draggedParts.iterator;for(;t.next();){const i=t.key;if(i instanceof Node){const e=i.containingGroup;e!==null&&e.hasPlaceholder()&&!this.draggedParts.has(e)&&e.placeholder.c()}}}mayCopy(){if(!this.isCopyEnabled)return!1;const t=this.diagram;if(t.isReadOnly||t.isModelReadOnly||!t.allowInsert||!t.allowCopy||!(U.tr?t.lastInput.alt:t.lastInput.control))return!1;const i=t.selection.iterator;for(;i.next();)if(i.value.canCopy())return!0;return!!(this.draggedLink!==null&&this.dragsLink&&this.draggedLink.canCopy())}mayDragOut(){if(!this.isCopyEnabled)return!1;const t=this.diagram;if(!t.allowDragOut||!t.allowCopy||t.allowMove)return!1;const i=t.selection.iterator;for(;i.next();)if(i.value.canCopy())return!0;return!!(this.draggedLink!==null&&this.dragsLink&&this.draggedLink.canCopy())}mayMove(){const t=this.diagram;if(t.isReadOnly||!t.allowMove)return!1;const i=t.selection.iterator;for(;i.next();)if(i.value.canMove())return!0;return!!(this.draggedLink!==null&&this.dragsLink&&this.draggedLink.canMove())}eL(){DraggingTool.zw.has(this)||DraggingTool.zw.add(this)}static yF(){if(DraggingTool.zw.count>0){const t=DraggingTool.zw,i=t.length;for(let e=0;e{n.isSelected=!0,s.add(n)})),this.iL(t.lastInput.documentPoint),t.invalidateDocumentBounds(),this.copiedParts!==null&&(this.transactionResult="ExternalCopy"),this.copiedParts=null,t.doFocus(),t.du=!1,t.D("ExternalObjectsDropped",s,e),this.stopTransaction(),t.D("ChangedSelection",t.selection)}t.animationManager.pu=!1}sL(t,i,e){if(this.copiedParts!==null)return;const s=this.diagram;if(s.isReadOnly||s.isModelReadOnly)return;s.skipsUndoManager=!i,s.partManager.addsToTemporaryLayer=!i,this.startPoint=e.documentPoint;const n=s.copyParts(t,s,!0),o=Rect.l();this.wF(t,o);const r=o.x+o.width/2,l=o.y+o.height/2;Rect.e(o);const h=this.gm,c=new GMap,a=Point.l(),f=t.iterator;for(;f.next();){const d=f.value;if(d instanceof Link&&d.canCopy()){const m=n.get(d);if(m===null)continue;m.points=d.points,m.fr(h.x-r,h.y-l),m.suspendsRouting=!0,c.set(m,this.Es())}}const u=t.iterator;for(;u.next();){const d=u.value;if(d.ke()&&d.canCopy()){const m=n.get(d);if(m===null)continue;const g=d.location;a.i(h.x-(r-g.x),h.y-(l-g.y)),m.location=a,m.ensureBounds(),c.set(m,this.Es(a))}}if(Point.e(a),this.copiedParts=c,this.SP(c.toKeySet()),this.draggedLink!==null){const d=this.draggedLink,m=d.routeBounds;d.fr(this.startPoint.x-(m.x+m.width/2),this.startPoint.y-(m.y+m.height/2))}this.doUpdateCursor(null)}pF(){this.isDragOutStarted=!0,this.fu=!1,DraggingTool.dt=this,DraggingTool.Yh=this.diagram,this.doSimulatedDragOut()}doSimulatedDragOut(){const t=this.diagram;!this.mayCopy()&&!this.mayMove()?t.currentCursor=this.nodropCursor:t.currentCursor="",this.uu=null}computeMove(t,i,e,s){const n=this.diagram;return n!==null?n.computeMove(t,i,this.dragOptions,s):new Point}static zw=new List;static dt=null;static Yh=null}ToolManager.prototype.doCancel=function(){DraggingTool.dt!==null&&DraggingTool.dt.doCancel(),Tool.prototype.doCancel.call(this)};class LinkingBaseTool extends Tool{IP;EP;Sl;UP;BP;Gh;VP;Kh;zP;XP;YP;GP;KP;jP;nL;HP;Ml;qP;constructor(){super(),this.IP=100,this.EP=!1,this.Sl="pointer",this.UP=new Link({layerName:"Tool"}).add(new Shape({isPanelMain:!0,stroke:"blue"}).theme("stroke","tempLink"),new Shape({toArrow:"Standard",fill:"blue",stroke:"blue"}).theme("fill","tempLink").theme("stroke","tempLink")).Et(),this.Gh=new Shape("Rectangle",{portId:"",fill:null,stroke:"magenta",strokeWidth:2,desiredSize:Size.Uk}).theme("stroke","tempPort"),this.BP=new Node({selectable:!1,layerName:"Tool"}).add(this.Gh).Et(),this.Kh=new Shape("Rectangle",{portId:"",fill:null,stroke:"magenta",strokeWidth:2,desiredSize:Size.Uk}).theme("stroke","tempPort"),this.VP=new Node({selectable:!1,layerName:"Tool"}).add(this.Kh).Et(),this.zP=null,this.XP=null,this.YP=null,this.GP=null,this.KP=null,this.jP=!0,this.nL=new GMap,this.HP=null,this.Ml=null,this.qP=null}doStop(){this.diagram.stopAutoScroll(),this.originalLink=null,this.originalFromNode=null,this.originalFromPort=null,this.originalToNode=null,this.originalToPort=null,this.validPortsCache.clear(),this.targetPort=null}get portGravity(){return this.IP}set portGravity(t){U.s(t,"number",LinkingBaseTool,"portGravity"),t>=0&&(this.IP=t)}get isUnconnectedLinkValid(){return this.EP}set isUnconnectedLinkValid(t){U.s(t,"boolean",LinkingBaseTool,"isUnconnectedLinkValid"),this.EP=t}get linkingCursor(){return this.Sl}set linkingCursor(t){this.Sl=t}get temporaryLink(){return this.UP}set temporaryLink(t){t.Et(),this.UP=t}get temporaryFromNode(){return this.BP}set temporaryFromNode(t){t.Et(),this.BP=t,t&&(this.Gh=t.port)}get temporaryFromPort(){return this.Gh}set temporaryFromPort(t){if(this.Gh!==null){const i=this.Gh.panel;if(i!==null){const e=i.C.indexOf(this.Gh);i.removeAt(e),i.insertAt(e,t)}}this.Gh=t}get temporaryToNode(){return this.VP}set temporaryToNode(t){t.Et(),this.VP=t,t&&(this.Kh=t.port)}get temporaryToPort(){return this.Kh}set temporaryToPort(t){if(this.Kh!==null){const i=this.Kh.panel;if(i!==null){const e=i.C.indexOf(this.Kh);i.removeAt(e),i.insertAt(e,t)}}this.Kh=t}get originalLink(){return this.zP}set originalLink(t){this.zP=t}get originalFromNode(){return this.XP}set originalFromNode(t){this.XP=t}get originalFromPort(){return this.YP}set originalFromPort(t){this.YP=t}get originalToNode(){return this.GP}set originalToNode(t){this.GP=t}get originalToPort(){return this.KP}set originalToPort(t){this.KP=t}get isForwards(){return this.jP}set isForwards(t){this.jP=t}get validPortsCache(){return this.nL}get targetPort(){return this.HP}set targetPort(t){this.HP=t}copyPortProperties(t,i,e,s,n){if(t===null||i===null||e===null||s===null)return;const o=i.getDocumentScale(),r=Size.l();r.width=i.naturalBounds.width*o,r.height=i.naturalBounds.height*o,s.desiredSize=r,Size.e(r),n?(s.toSpot=i.toSpot,s.toEndSegmentLength=i.toEndSegmentLength):(s.fromSpot=i.fromSpot,s.fromEndSegmentLength=i.fromEndSegmentLength),e.locationSpot=Spot.Center;const l=Point.l();e.location=i.getDocumentPoint(Spot.Center,l),Point.e(l),s.angle=i.getDocumentAngle(),this.portTargeted!==null&&this.portTargeted(t,i,e,s,n)}setNoTargetPortProperties(t,i,e){i!==null&&(i.desiredSize=Size.Uk,i.fromSpot=Spot.None,i.toSpot=Spot.None),t!==null&&(t.location=this.diagram.lastInput.documentPoint),this.portTargeted!==null&&this.portTargeted(null,null,t,i,e)}doMouseDown(){this.isActive&&this.doMouseMove()}doMouseMove(){if(this.isActive){const t=this.diagram;if(this.targetPort=this.findTargetPort(this.isForwards),this.targetPort!==null&&this.targetPort.part instanceof Node){const i=this.targetPort.part;this.isForwards?this.copyPortProperties(i,this.targetPort,this.temporaryToNode,this.temporaryToPort,!0):this.copyPortProperties(i,this.targetPort,this.temporaryFromNode,this.temporaryFromPort,!1)}else this.isForwards?this.setNoTargetPortProperties(this.temporaryToNode,this.temporaryToPort,!0):this.setNoTargetPortProperties(this.temporaryFromNode,this.temporaryFromPort,!1);(t.allowHorizontalScroll||t.allowVerticalScroll)&&t.doAutoScroll(t.lastInput.viewPoint)}}findValidLinkablePort(t,i){if(t===null)return null;const e=t.part;if(!(e instanceof Node))return null;for(;t!==null;){const s=i?t.toLinkable:t.fromLinkable;if(s===!0&&(t.portId!==null||t instanceof Node)&&(i?this.isValidTo(e,t):this.isValidFrom(e,t)))return t;if(s===!1)return null;t=t.panel}return null}findTargetPort(t){const i=this.diagram,e=i.lastInput.documentPoint;let s=this.portGravity;const n=i.findObjectsNear(e,s,h=>this.findValidLinkablePort(h,t),null,!0);let o=1/0,r=null;const l=n.iterator;for(;l.next();){const h=l.value,c=h.part;if(!(c instanceof Node))continue;const a=h.getDocumentPoint(Spot.Center,Point.l()),f=e.x-a.x,u=e.y-a.y;Point.e(a);const d=f*f+u*u;if(d=e)return!1}return!0}isValidTo(t,i){if(t===null||i===null)return this.isUnconnectedLinkValid;if(this.diagram.currentTool===this&&(t.layer!==null&&!t.layer.allowLink||i.toLinkable!==!0))return!1;const e=i.toMaxLinks;if(e<1/0){if(this.originalLink!==null&&t===this.originalToNode&&i===this.originalToPort)return!0;let s=i.portId;if(s===null&&(s=""),t.findLinksInto(s).count>=e)return!1}return!0}isInSameNode(t,i){if(t===null||i===null)return!1;if(t===i)return!0;const e=t.part,s=i.part;return e!==null&&e===s}isLinked(t,i){if(t===null||i===null)return!1;const e=t.part;if(!(e instanceof Node))return!1;let s=t.portId;s===null&&(s="");const n=i.part;if(!(n instanceof Node))return!1;let o=i.portId;o===null&&(o="");const r=n.findLinksInto(o);for(;r.next();){const l=r.value;if(l.fromNode===e&&l.fromPortId===s)return!0}return!1}isValidLink(t,i,e,s){if(!this.isValidFrom(t,i)||!this.isValidTo(e,s)||i!==null&&s!==null&&(!(i.fromLinkableSelfNode&&s.toLinkableSelfNode)&&this.isInSameNode(i,s)||!(i.fromLinkableDuplicates&&s.toLinkableDuplicates)&&this.isLinked(i,s))||this.originalLink!==null&&(t!==null&&this.isLabelDependentOnLink(t,this.originalLink)||e!==null&&this.isLabelDependentOnLink(e,this.originalLink))||t!==null&&e!==null&&(t.data===null&&e.data!==null||t.data!==null&&e.data===null)||!this.isValidCycle(t,e,this.originalLink))return!1;let n;return t!==null&&i!==null&&(n=t.linkValidation,n!==null&&!n(t,i,e,s,this.originalLink))||e!==null&&s!==null&&(n=e.linkValidation,n!==null&&!n(t,i,e,s,this.originalLink))?!1:(n=this.linkValidation,n!==null?n(t,i,e,s,this.originalLink):!0)}isLabelDependentOnLink(t,i){if(t===null)return!1;const e=t.labeledLink;if(e===null)return!1;if(e===i)return!0;const s=new GSet;return s.add(t),this.WP(e,i,s)}WP(t,i,e){if(t===i)return!0;const s=t.fromNode;if(s!==null&&s.labeledLink&&(e.add(s),this.WP(s.labeledLink,i,e)))return!0;const n=t.toNode;return!!(n!==null&&n.labeledLink&&(e.add(n),this.WP(n.labeledLink,i,e)))}isValidCycle(t,i,e){if(e===void 0&&(e=null),t===null||i===null)return this.isUnconnectedLinkValid;const s=this.diagram;let n=1;if(s&&(s.model.pm()?n=s.isTreePathToChildren?5:6:n=s.validCycle),n===1)return!0;if(n===5){const o=e||this.temporaryLink;if(o!==null&&!o.isTreeLink)return!0;const r=i.linksConnected;for(;r.next();){const l=r.value;if(l!==e&&l.isTreeLink&&l.toNode===i)return!1}return!this.yu(t,i,e,!0)}else if(n===6){const o=e||this.temporaryLink;if(o!==null&&!o.isTreeLink)return!0;const r=t.linksConnected;for(;r.next();){const l=r.value;if(l!==e&&l.isTreeLink&&l.fromNode===t)return!1}return!this.yu(t,i,e,!0)}else{if(n===2)return!this.SF(t,i,e);if(n===3)return!this.yu(t,i,e,!1);if(n===4)return!this.MF(t,i,e)}return!0}yu(t,i,e,s){if(t===i)return!0;if(t===null||i===null)return!1;const n=t.linksConnected;for(;n.next();){const o=n.value;if(o===e||s&&!o.isTreeLink||o.toNode!==t)continue;const r=o.fromNode;if(!(r===t||r===null)&&this.yu(r,i,e,s))return!0}return!1}SF(t,i,e){if(t===i)return!0;const s=new GSet;return s.add(i),this.oL(s,t,i,e)}oL(t,i,e,s){if(i===e)return!0;if(i===null||e===null||t.has(i))return!1;t.add(i);const n=i.linksConnected;for(;n.next();){const o=n.value;if(o===s||o.toNode!==i)continue;const r=o.fromNode;if(!(r===i||r===null)&&this.oL(t,r,e,s))return!0}return!1}MF(t,i,e){if(t===i)return!0;const s=new GSet;return s.add(i),this.rL(s,t,i,e)}rL(t,i,e,s){if(i===e)return!0;if(i===null||e===null||t.has(i))return!1;t.add(i);const n=i.linksConnected;for(;n.next();){const o=n.value;if(o===s)continue;const r=o.fromNode,l=o.toNode,h=r===i?l:r;if(!(h===i||h===null)&&this.rL(t,h,e,s))return!0}return!1}get linkValidation(){return this.Ml}set linkValidation(t){t!==null&&U.k(t,LinkingBaseTool,"linkValidation"),this.Ml=t}get portTargeted(){return this.qP}set portTargeted(t){t!==null&&U.k(t,LinkingBaseTool,"portTargeted"),this.qP=t}}var LinkingDirection=(y=>(y[y.Either=1]="Either",y[y.ForwardsOnly=2]="ForwardsOnly",y[y.BackwardsOnly=3]="BackwardsOnly",y))(LinkingDirection||{});class LinkingTool extends LinkingBaseTool{JP;$P;b;ZP;constructor(t){super(),this.name="Linking",this.JP={},this.$P=null,this.b=1,this.ZP=null,t&&Object.assign(this,t)}static Either=1;static ForwardsOnly=2;static BackwardsOnly=3;get archetypeLinkData(){return this.JP}set archetypeLinkData(t){t!==null&&U.ec(t,LinkingTool,"archetypeLinkData"),this.JP=t}get archetypeLabelNodeData(){return this.$P}set archetypeLabelNodeData(t){t!==null&&U.ec(t,LinkingTool,"archetypeLabelNodeData"),this.$P=t}get direction(){return this.b}set direction(t){this.b=t}get startObject(){return this.ZP}set startObject(t){this.ZP=t}canStart(){if(!this.isEnabled)return!1;const t=this.diagram;return t.isReadOnly||t.isModelReadOnly||!t.allowLink||!t.model.Xw()||!t.lastInput.left||t.currentTool!==this&&!this.isBeyondDragSize()?!1:this.findLinkablePort()!==null}findLinkablePort(){const t=this.diagram;let i=this.startObject;if(i===null&&(i=t.findObjectAt(t.firstInput.documentPoint,null,null)),i===null)return null;const e=i.part;if(!(e instanceof Node))return null;const s=this.direction;if(s===1||s===2){const n=this.findValidLinkablePort(i,!1);if(n!==null)return this.isForwards=!0,n;if(this.startObject===e){const o=e.port;if(this.findValidLinkablePort(o,!1))return this.isForwards=!0,o}}if(s===1||s===3){const n=this.findValidLinkablePort(i,!0);if(n!==null)return this.isForwards=!1,n;if(this.startObject===e){const o=e.port;if(this.findValidLinkablePort(o,!0))return this.isForwards=!1,o}}return null}doActivate(){const t=this.diagram,i=this.findLinkablePort();if(i===null){this.stopTool();return}if(this.startTransaction(this.name),t.isMouseCaptured=!0,t.currentCursor=this.linkingCursor,this.isForwards){this.temporaryToNode!==null&&(this.temporaryToNode.location=t.lastInput.documentPoint),this.originalFromPort=i;const e=this.originalFromPort.part;e instanceof Node&&(this.originalFromNode=e),this.copyPortProperties(this.originalFromNode,this.originalFromPort,this.temporaryFromNode,this.temporaryFromPort,!1)}else{this.temporaryFromNode!==null&&(this.temporaryFromNode.location=t.lastInput.documentPoint),this.originalToPort=i;const e=this.originalToPort.part;e instanceof Node&&(this.originalToNode=e),this.copyPortProperties(this.originalToNode,this.originalToPort,this.temporaryToNode,this.temporaryToPort,!0)}t.add(this.temporaryFromNode),this.temporaryFromNode&&this.temporaryFromNode.ensureBounds(),t.add(this.temporaryToNode),this.temporaryToNode&&this.temporaryToNode.ensureBounds(),this.temporaryLink!==null&&(this.temporaryFromNode!==null&&(this.temporaryLink.fromNode=this.temporaryFromNode),this.temporaryToNode!==null&&(this.temporaryLink.toNode=this.temporaryToNode),this.temporaryLink.isTreeLink=this.isNewTreeLink(),this.temporaryLink.invalidateRoute(),t.add(this.temporaryLink)),this.isActive=!0}doDeactivate(){this.isActive=!1;const t=this.diagram;t.remove(this.temporaryLink),t.remove(this.temporaryFromNode),t.remove(this.temporaryToNode),t.isMouseCaptured=!1,t.currentCursor="",this.stopTransaction()}doStop(){super.doStop(),this.startObject=null}doMouseUp(){if(this.isActive){const t=this.diagram;this.transactionResult=null;let i=null,e=null,s=null,n=null,o=null;try{this.targetPort=this.findTargetPort(this.isForwards);const r=this.targetPort;if(r!==null){const l=r.part;l instanceof Node&&(this.isForwards?(this.originalFromNode!==null&&(i=this.originalFromNode,e=this.originalFromPort),s=l,n=r):(i=l,e=r,this.originalToNode!==null&&(s=this.originalToNode,n=this.originalToPort)))}else this.isForwards?this.originalFromNode!==null&&this.isUnconnectedLinkValid&&(i=this.originalFromNode,e=this.originalFromPort):this.originalToNode!==null&&this.isUnconnectedLinkValid&&(s=this.originalToNode,n=this.originalToPort);i!==null||s!==null?(o=this.insertLink(i,e,s,n),o!==null?(r===null&&(this.isForwards?o.defaultToPoint=t.lastInput.documentPoint:o.defaultFromPoint=t.lastInput.documentPoint),t.allowSelect&&(t.D("ChangingSelection",t.selection),t.clearSelection(!0),o.isSelected=!0),this.transactionResult=this.name,t.D("LinkDrawn",o)):this.doNoLink(i,e,s,n)):this.isForwards?this.doNoLink(this.originalFromNode,this.originalFromPort,null,null):this.doNoLink(null,null,this.originalToNode,this.originalToPort)}finally{this.stopTool(),o&&t.allowSelect&&t.D("ChangedSelection",t.selection)}}}isNewTreeLink(){const t=this.archetypeLinkData;if(t===null)return!0;if(t instanceof Link)return t.isTreeLink;const i=this.diagram;if(i===null)return!0;const e=i.partManager.getLinkCategoryForData(t),s=i.partManager.findLinkTemplateForCategory(e);return s!==null?s.isTreeLink:!0}insertLink(t,i,e,s){return this.diagram.partManager.insertLink(t,i,e,s)}doNoLink(t,i,e,s){}}class RelinkingTool extends LinkingBaseTool{lL=null;hL=null;QP=null;_P=null;fs;tS;constructor(t){super(),this.name="Relinking",this.fromHandleArchetype=new Shape("Diamond",{desiredSize:Size.nu,fill:"lightblue",stroke:"dodgerblue",cursor:this.linkingCursor,segmentIndex:0}).theme("fill","adornmentFill").theme("stroke","adornmentStroke"),this.toHandleArchetype=new Shape("Diamond",{desiredSize:Size.nu,fill:"lightblue",stroke:"dodgerblue",cursor:this.linkingCursor,segmentIndex:-1}).theme("fill","adornmentFill").theme("stroke","adornmentStroke"),this.fs=null,this.tS=new Rect,t&&Object.assign(this,t)}updateAdornments(t){if(t===null||!(t instanceof Link))return;let i="RelinkFrom",e=null;if(t.isSelected&&!this.diagram.isReadOnly){const s=t.selectionObject;s!==null&&t.canRelinkFrom()&&t.actualBounds.isReal()&&t.isVisible()&&s.actualBounds.isReal()&&s.isVisibleObject()&&(e=t.findAdornment(i),e===null&&(e=this.makeAdornment(s,!1),t.addAdornment(i,e)))}if(e===null&&t.removeAdornment(i),i="RelinkTo",e=null,t.isSelected&&!this.diagram.isReadOnly){const s=t.selectionObject;s!==null&&t.canRelinkTo()&&t.actualBounds.isReal()&&t.isVisible()&&s.actualBounds.isReal()&&s.isVisibleObject()&&(e=t.findAdornment(i),e===null?(e=this.makeAdornment(s,!0),t.addAdornment(i,e)):e.c())}e===null&&t.removeAdornment(i)}makeAdornment(t,i){let e=i?this._P:this.QP;return e&&(e=e.copy(),e.adornedObject=t),e}get fromHandleArchetype(){return this.lL}set fromHandleArchetype(t){this.lL=t,t!==null?this.QP=new Adornment(Panel.Link).add(t).Et():this.QP=null}get toHandleArchetype(){return this.hL}set toHandleArchetype(t){this.hL=t,t!==null?this._P=new Adornment(Panel.Link).add(t).Et():this._P=null}get handle(){return this.fs}set handle(t){t!==null&&(t.part instanceof Adornment||U.o("new handle is not in an Adornment: "+t)),this.fs=t}canStart(){if(!this.isEnabled)return!1;const t=this.diagram;if(t.isReadOnly||t.isModelReadOnly||!t.allowRelink||!t.model.Xw()||!t.lastInput.left)return!1;let e=this.findToolHandleAt(t.firstInput.documentPoint,"RelinkFrom");return e===null&&(e=this.findToolHandleAt(t.firstInput.documentPoint,"RelinkTo")),e!==null}doActivate(){const t=this.diagram;if(this.originalLink===null){let e=this.handle;if(e===null&&(e=this.findToolHandleAt(t.firstInput.documentPoint,"RelinkFrom"),e===null&&(e=this.findToolHandleAt(t.firstInput.documentPoint,"RelinkTo"))),e===null)return;const s=e.part;if(!(s instanceof Adornment)||!(s.adornedPart instanceof Link))return;this.handle=e,this.isForwards=s===null||s.category==="RelinkTo",this.originalLink=s.adornedPart}const i=this.originalLink;i!==null&&(this.startTransaction(this.name),t.isMouseCaptured=!0,t.currentCursor=this.linkingCursor,this.originalFromPort=i.fromPort,this.originalFromNode=i.fromNode,this.originalToPort=i.toPort,this.originalToNode=i.toNode,this.tS.set(i.actualBounds),i.pointsCount>0&&(i.fromNode===null&&(this.temporaryFromPort!==null&&(this.temporaryFromPort.desiredSize=Size.sc),this.temporaryFromNode!==null&&(this.temporaryFromNode.location=i.getPoint(0))),i.toNode===null&&(this.temporaryToPort!==null&&(this.temporaryToPort.desiredSize=Size.sc),this.temporaryToNode!==null&&(this.temporaryToNode.location=i.getPoint(i.pointsCount-1)))),this.copyPortProperties(this.originalFromNode,this.originalFromPort,this.temporaryFromNode,this.temporaryFromPort,!1),this.copyPortProperties(this.originalToNode,this.originalToPort,this.temporaryToNode,this.temporaryToPort,!0),t.add(this.temporaryFromNode),t.add(this.temporaryToNode),this.temporaryLink!==null&&(this.temporaryFromNode!==null&&(this.temporaryLink.fromNode=this.temporaryFromNode),this.temporaryToNode!==null&&(this.temporaryLink.toNode=this.temporaryToNode),this.copyLinkProperties(i,this.temporaryLink),this.temporaryLink.invalidateRoute(),t.add(this.temporaryLink)),this.isActive=!0)}copyLinkProperties(t,i){if(t===null||i===null)return;i.adjusting=t.adjusting,i.corner=t.corner;let e=t.curve;(e===11||e===10)&&(e=0),i.curve=e,i.curviness=t.curviness,i.isTreeLink=t.isTreeLink,i.points=t.points,i.routing=t.routing,i.smoothness=t.smoothness,i.fromSpot=t.fromSpot,i.fromEndSegmentLength=t.fromEndSegmentLength,i.fromShortLength=t.fromShortLength,i.toSpot=t.toSpot,i.toEndSegmentLength=t.toEndSegmentLength,i.toShortLength=t.toShortLength}doDeactivate(){this.isActive=!1;const t=this.diagram;t.remove(this.temporaryLink),t.remove(this.temporaryFromNode),t.remove(this.temporaryToNode),t.isMouseCaptured=!1,t.currentCursor="",this.stopTransaction()}doStop(){super.doStop(),this.handle=null}doMouseUp(){if(this.isActive){const t=this.diagram;this.transactionResult=null;let i=this.originalFromNode,e=this.originalFromPort,s=this.originalToNode,n=this.originalToPort,o=this.originalLink;try{if(this.targetPort=this.findTargetPort(this.isForwards),this.targetPort!==null){const r=this.targetPort.part;r instanceof Node&&(this.isForwards?(s=r,n=this.targetPort):(i=r,e=this.targetPort))}else this.isUnconnectedLinkValid?this.isForwards?(s=null,n=null):(i=null,e=null):o=null;o!==null?(this.reconnectLink(o,this.isForwards?s:i,this.isForwards?n:e,this.isForwards),this.targetPort===null&&(this.isForwards?o.defaultToPoint=t.lastInput.documentPoint:o.defaultFromPoint=t.lastInput.documentPoint,o.invalidateRoute()),this.transactionResult=this.name,t.D("LinkRelinked",o,this.isForwards?this.originalToPort:this.originalFromPort)):this.originalLink!==null&&this.doNoRelink(this.originalLink,this.isForwards),this.originalLink!==null&&this.originalLink.invalidateOtherJumpOvers(this.tS)}finally{this.stopTool()}}}reconnectLink(t,i,e,s){const n=e!==null&&e.portId!==null?e.portId:"";return s?(t.toNode=i,t.toPortId=n):(t.fromNode=i,t.fromPortId=n),!0}doNoRelink(t,i){}doDraggingMouseMove(t,i,e,s){t!==null?(this.copyPortProperties(t,i,this.temporaryFromNode,this.temporaryFromPort,!1),this.diagram.add(this.temporaryFromNode)):this.diagram.remove(this.temporaryFromNode),e!==null?(this.copyPortProperties(e,s,this.temporaryToNode,this.temporaryToPort,!0),this.diagram.add(this.temporaryToNode)):this.diagram.remove(this.temporaryToNode)}stopDraggingMouseMove(){this.diagram.remove(this.temporaryFromNode),this.diagram.remove(this.temporaryToNode)}}var ReshapingBehavior=(y=>(y[y.None=0]="None",y[y.Horizontal=1]="Horizontal",y[y.Vertical=2]="Vertical",y[y.All=3]="All",y))(ReshapingBehavior||{});class LinkReshapingTool extends Tool{dr;iS;eS;fs;Yw;sS;ym;constructor(t){super(),this.name="LinkReshaping",this.dr=new Shape("Rectangle",{desiredSize:Size.yC,fill:"lightblue",stroke:"dodgerblue"}).theme("fill","adornmentFill").theme("stroke","adornmentStroke"),this.iS=new Shape("Diamond",{desiredSize:Size.nu,fill:"lightblue",stroke:"dodgerblue",cursor:"move"}).theme("fill","adornmentFill").theme("stroke","adornmentStroke"),this.eS=3,this.fs=null,this.Yw=null,this.sS=new Point,this.ym=new List,t&&Object.assign(this,t)}static None=0;static Horizontal=1;static Vertical=2;static All=3;getReshapingBehavior(t){return t?t.gr:0}setReshapingBehavior(t,i){t.gr=i}updateAdornments(t){if(t===null||!(t instanceof Link))return;let i=null;if(t.isSelected&&!this.diagram.isReadOnly){const e=t.path;e!==null&&t.canReshape()&&t.actualBounds.isReal()&&t.isVisible()&&e.actualBounds.isReal()&&e.isVisibleObject()&&(i=t.findAdornment(this.name),(i===null||i.nS!==t.pointsCount||i.oS!==t.resegmentable)&&(i=this.makeAdornment(e),i!==null&&(i.nS=t.pointsCount,i.oS=t.resegmentable,t.addAdornment(this.name,i))))}i===null&&t.removeAdornment(this.name)}makeAdornment(t){const i=t.part,e=i.points,s=i.pointsCount,n=i.isOrthogonal;let o=null;if(e!==null&&s>1){o=new Adornment,o.type=Panel.Link;const r=i.firstPickIndex,l=i.lastPickIndex,h=n?1:0;if(i.resegmentable&&i.computeCurve()!==9)for(let c=r+h;ce.firstPickIndex+1&&s0))this.NF(t,i);else if(t instanceof Panel){const e=t.elements;for(;e.next();){const s=e.value;this.updateResizeHandles(s,i)}}}}NF(t,i){let e=t.alignment;e.isNoSpot()&&(e=Spot.Center);let s=i;if(e.x<=0)e.y<=0?s+=225:e.y>=1?s+=135:s+=180;else if(e.x>=1)e.y<=0?s+=315:e.y>=1&&(s+=45);else if(e.y<=0)s+=270;else if(e.y>=1)s+=90;else return;s<0?s+=360:s>=360&&(s-=360),s<22.5?t.cursor="e-resize":s<67.5?t.cursor="se-resize":s<112.5?t.cursor="s-resize":s<157.5?t.cursor="sw-resize":s<202.5?t.cursor="w-resize":s<247.5?t.cursor="nw-resize":s<292.5?t.cursor="n-resize":s<337.5?t.cursor="ne-resize":t.cursor="e-resize"}get handleArchetype(){return this.dr}set handleArchetype(t){this.dr=t}get handle(){return this.fs}set handle(t){t!==null&&(t.part instanceof Adornment||U.o("new handle is not in an Adornment: "+t)),this.fs=t}get adornedObject(){return this.us}set adornedObject(t){t!==null&&t.part instanceof Adornment&&U.o("new handle must not be in an Adornment: "+t),this.us=t}canStart(){if(!this.isEnabled)return!1;const t=this.diagram;return t.isReadOnly||!t.allowResize||!t.lastInput.left?!1:this.findToolHandleAt(t.firstInput.documentPoint,this.name)!==null}doActivate(){const t=this.diagram;this.handle===null&&(this.handle=this.findToolHandleAt(t.firstInput.documentPoint,this.name)),this.handle!==null&&(this.adornedObject=this.handle.part.adornedObject,this.adornedObject!==null&&this.adornedObject.part!==null&&(t.isMouseCaptured=!0,t.animationManager.stopAnimation(),t.gu=!0,this.startTransaction(this.name),this.wm.set(this.adornedObject.getDocumentPoint(this.handle.alignment.opposite())),this.wc.set(this.adornedObject.part.location),this.hS.set(this.adornedObject.desiredSize),this.jw=this.computeCellSize(),this.Gw=this.computeMinSize(),this.Kw=this.computeMaxSize(),this.isActive=!0))}doDeactivate(){const t=this.diagram;t.gu=!1,t.bl=!0,this.stopTransaction(),this.handle=null,this.us=null,t.isMouseCaptured=!1,this.isActive=!1}stopTransaction(){const t=this.diagram,i=super.stopTransaction();return i&&t.undoManager.transactionToUndo!==null&&t.undoManager.transactionToUndo.optimize(),i}doCancel(){this.adornedObject!==null&&this.adornedObject.part!==null&&(this.adornedObject.desiredSize=this.originalDesiredSize,this.adornedObject.part.location=this.originalLocation),this.stopTool()}doMouseMove(){const t=this.diagram;if(!this.isActive||this.adornedObject===null||this.handle===null)return;const i=this.Gw,e=this.Kw,s=this.jw,n=t.lastInput.documentPoint,o=this.adornedObject.getLocalPoint(n,Point.l()),r=this.computeReshape(),l=this.computeResize(o,this.handle.alignment,i,e,s,r);this.resize(l),t.maybeUpdate(),Point.e(o)}doMouseUp(){const t=this.diagram;if(this.isActive&&this.adornedObject!==null&&this.handle!==null){const i=this.Gw,e=this.Kw,s=this.jw,n=this.adornedObject.getLocalPoint(t.lastInput.documentPoint,Point.l()),o=this.computeReshape(),r=this.computeResize(n,this.handle.alignment,i,e,s,o);this.resize(r),Point.e(n),t.invalidateDocumentBounds(),this.transactionResult=this.name,t.D("PartResized",this.adornedObject,this.originalDesiredSize)}this.stopTool()}resize(t){const i=this.diagram,e=this.adornedObject;if(e===null)return;e.desiredSize=t.size;const s=e.part;if(s===null||this.handle===null)return;s.ensureBounds();const n=e.getDocumentPoint(this.handle.alignment.opposite());if(s instanceof Group){const o=new List;o.add(s);let r;!this.dragsMembers&&!s.hasPlaceholder()&&(r=new DraggingOptions,r.dragsMembers=!1),i.moveParts(o,this.oppositePoint.copy().subtract(n),!0,r)}else s.location=s.location.copy().subtract(n).add(this.oppositePoint);i.maybeUpdate()}computeResize(t,i,e,s,n,o){if(this.adornedObject===null)return Rect.Fg;i.isNoSpot()&&(i=Spot.Center);const r=this.adornedObject.naturalBounds,l=r.x,h=r.y,c=r.x+r.width,a=r.y+r.height;let f=1;if(!o){let m=r.width,g=r.height;m<=0&&(m=1),g<=0&&(g=1),f=g/m}const u=Point.l();Geo.Dg(t.x,t.y,l,h,n.width,n.height,u);const d=r.copy();return i.x<=0?i.y<=0?(d.x=Math.max(u.x,c-s.width),d.x=Math.min(d.x,c-e.width),d.width=Math.max(c-d.x,e.width),d.y=Math.max(u.y,a-s.height),d.y=Math.min(d.y,a-e.height),d.height=Math.max(a-d.y,e.height),o||(d.height/d.width>=1?(d.height=Math.max(Math.min(f*d.width,s.height),e.height),d.width=d.height/f):(d.width=Math.max(Math.min(d.height/f,s.width),e.width),d.height=f*d.width),d.x=c-d.width,d.y=a-d.height)):i.y>=1?(d.x=Math.max(u.x,c-s.width),d.x=Math.min(d.x,c-e.width),d.width=Math.max(c-d.x,e.width),d.height=Math.max(Math.min(u.y-h,s.height),e.height),o||(d.height/d.width>=1?(d.height=Math.max(Math.min(f*d.width,s.height),e.height),d.width=d.height/f):(d.width=Math.max(Math.min(d.height/f,s.width),e.width),d.height=f*d.width),d.x=c-d.width)):(d.x=Math.max(u.x,c-s.width),d.x=Math.min(d.x,c-e.width),d.width=c-d.x,o||(d.height=Math.max(Math.min(f*d.width,s.height),e.height),d.width=d.height/f,d.y=h+.5*(a-h-d.height))):i.x>=1?i.y<=0?(d.width=Math.max(Math.min(u.x-l,s.width),e.width),d.y=Math.max(u.y,a-s.height),d.y=Math.min(d.y,a-e.height),d.height=Math.max(a-d.y,e.height),o||(d.height/d.width>=1?(d.height=Math.max(Math.min(f*d.width,s.height),e.height),d.width=d.height/f):(d.width=Math.max(Math.min(d.height/f,s.width),e.width),d.height=f*d.width),d.y=a-d.height)):i.y>=1?(d.width=Math.max(Math.min(u.x-l,s.width),e.width),d.height=Math.max(Math.min(u.y-h,s.height),e.height),o||(d.height/d.width>=1?(d.height=Math.max(Math.min(f*d.width,s.height),e.height),d.width=d.height/f):(d.width=Math.max(Math.min(d.height/f,s.width),e.width),d.height=f*d.width))):(d.width=Math.max(Math.min(u.x-l,s.width),e.width),o||(d.height=Math.max(Math.min(f*d.width,s.height),e.height),d.width=d.height/f,d.y=h+.5*(a-h-d.height))):i.y<=0?(d.y=Math.max(u.y,a-s.height),d.y=Math.min(d.y,a-e.height),d.height=a-d.y,o||(d.width=Math.max(Math.min(d.height/f,s.width),e.width),d.height=f*d.width,d.x=l+.5*(c-l-d.width))):i.y>=1&&(d.height=Math.max(Math.min(u.y-h,s.height),e.height),o||(d.width=Math.max(Math.min(d.height/f,s.width),e.width),d.height=f*d.width,d.x=l+.5*(c-l-d.width))),Point.e(u),d}computeReshape(){let t=0;return this.adornedObject instanceof Shape&&(t=this.adornedObject.aS()),!(t===6||this.diagram.lastInput.shift)}computeMinSize(){if(this.adornedObject===null)return Size.sc;const t=this.adornedObject.minSize.copy(),i=this.minSize;return!isNaN(i.width)&&i.width>t.width&&(t.width=i.width),!isNaN(i.height)&&i.height>t.height&&(t.height=i.height),t}computeMaxSize(){if(this.adornedObject===null)return Size.Bk;const t=this.adornedObject.maxSize.copy(),i=this.maxSize;return!isNaN(i.width)&&i.width0&&(t.width=n.width),!isNaN(n.height)&&n.height>0&&(t.height=n.height)}let e=this.cellSize;isNaN(t.width)&&!isNaN(e.width)&&e.width>0&&(t.width=e.width),isNaN(t.height)&&!isNaN(e.height)&&e.height>0&&(t.height=e.height);const s=this.diagram;if((isNaN(t.width)||isNaN(t.height))&&s){const n=s.grid;n!==null&&n.visible&&this.isGridSnapEnabled&&(e=n.gridCellSize,isNaN(t.width)&&!isNaN(e.width)&&e.width>0&&(t.width=e.width),isNaN(t.height)&&!isNaN(e.height)&&e.height>0&&(t.height=e.height))}return(isNaN(t.width)||t.width===0||t.width===1/0)&&(t.width=1),(isNaN(t.height)||t.height===0||t.height===1/0)&&(t.height=1),t}get minSize(){return this.pr}set minSize(t){if(!this.pr.equals(t)){let e=t.width;isNaN(e)&&(e=0);let s=t.height;isNaN(s)&&(s=0),this.pr.i(e,s)}}get maxSize(){return this.yr}set maxSize(t){if(!this.yr.equals(t)){let e=t.width;isNaN(e)&&(e=1/0);let s=t.height;isNaN(s)&&(s=1/0),this.yr.i(e,s)}}get cellSize(){return this.Po}set cellSize(t){this.Po.equals(t)||this.Po.a(t)}get isGridSnapEnabled(){return this.yc}set isGridSnapEnabled(t){U.s(t,"boolean",ResizingTool,"isGridSnapEnabled"),this.yc=t}get dragsMembers(){return this.lS}set dragsMembers(t){U.s(t,"boolean",ResizingTool,"dragsMembers"),this.lS=t}get oppositePoint(){return this.wm}set oppositePoint(t){this.wm.equals(t)||this.wm.a(t)}get originalDesiredSize(){return this.hS}get originalLocation(){return this.wc}}class RotatingTool extends Tool{cS;fS;us=null;dr=null;Hw=null;fs=null;uS;xm;wc;dS;gS;constructor(t){super(),this.name="Rotating",this.cS=45,this.fS=2,this.wc=new Point,this.us=null,this.handleArchetype=new Shape("Ellipse",{desiredSize:Size.nu,fill:"lightblue",stroke:"dodgerblue",strokeWidth:1,cursor:"pointer"}).theme("fill","adornmentFill").theme("stroke","adornmentStroke"),this.fs=null,this.uS=0,this.xm=new Point(NaN,NaN),this.dS=0,this.gS=50,t&&Object.assign(this,t)}updateAdornments(t){if(t!==null){if(t.Cl()){const i=t.rotateObject;if(i===t||i===t.path||i.isPanelMain)return}if(t.isSelected&&!this.diagram.isReadOnly){const i=t.rotateObject;if(i!==null&&t.canRotate()&&t.actualBounds.isReal()&&t.isVisible()&&i.actualBounds.isReal()&&i.isVisibleObject()){let e=t.findAdornment(this.name);if((e===null||e.adornedObject!==i)&&(e=this.makeAdornment(i)),e!==null){e.angle=i.getDocumentAngle(),e.hasPlaceholder()||(e.location=this.computeAdornmentLocation(i)),t.addAdornment(this.name,e);return}}}t.removeAdornment(this.name)}}makeAdornment(t){let i=null;const e=t.part?.rotateAdornmentTemplate;return e?i=e.copy():this.Hw!==null&&(i=this.Hw.copy()),i===null?null:(i.adornedObject=t,i)}get handleArchetype(){return this.dr}set handleArchetype(t){this.dr=t,t!==null?this.Hw=new Adornment(Panel.Position,{locationSpot:Spot.Center}).add(t).Et():this.Hw=null}get handle(){return this.fs}set handle(t){t!==null&&(t.part instanceof Adornment||U.o("new handle is not in an Adornment: "+t)),this.fs=t}get adornedObject(){return this.us}set adornedObject(t){t!==null&&t.part instanceof Adornment&&U.o("new handle must not be in an Adornment: "+t),this.us=t}canStart(){if(!this.isEnabled)return!1;const t=this.diagram;return t.isReadOnly||!t.allowRotate||!t.lastInput.left?!1:this.findToolHandleAt(t.firstInput.documentPoint,this.name)!==null}doActivate(){const t=this.diagram;if(this.adornedObject===null){if(this.handle===null&&(this.handle=this.findToolHandleAt(t.firstInput.documentPoint,this.name)),this.handle===null)return;this.adornedObject=this.handle.part.adornedObject}this.adornedObject===null||this.adornedObject.part===null||(t.isMouseCaptured=!0,t.delaysLayout=!0,this.startTransaction(this.name),this.uS=this.adornedObject.angle,this.xm=this.computeRotationPoint(this.adornedObject),this.wc=this.adornedObject.part.location.copy(),this.isActive=!0)}computeRotationPoint(t){const i=t.part;if(i!==null){const e=i.locationObject;if(i.rotationSpot.isSpot())return t.getDocumentPoint(i.rotationSpot);if(t===i||t===e)return e.getDocumentPoint(i.locationSpot)}return t.getDocumentPoint(Spot.Center)}computeAdornmentLocation(t){let i=this.rotationPoint;i.isReal()||(i=this.computeRotationPoint(t));const e=t.getLocalPoint(i);let s=this.handleAngle;s<0?s+=360:s>=360&&(s-=360),s=Math.round(Math.round(s/45)*45);const n=this.handleDistance;return s===0?e.x=t.naturalBounds.width+n:s===45?(e.x=t.naturalBounds.width+n,e.y=t.naturalBounds.height+n):s===90?e.y=t.naturalBounds.height+n:s===135?(e.x=-n,e.y=t.naturalBounds.height+n):s===180?e.x=-n:s===225?(e.x=-n,e.y=-n):s===270?e.y=-n:s===315&&(e.x=t.naturalBounds.width+n,e.y=-n),t.getDocumentPoint(e)}doDeactivate(){const t=this.diagram;this.stopTransaction(),this.handle=null,this.us=null,this.xm=new Point(NaN,NaN),t.isMouseCaptured=!1,this.isActive=!1}stopTransaction(){const t=this.diagram,i=super.stopTransaction();return i&&t.undoManager.transactionToUndo!==null&&t.undoManager.transactionToUndo.optimize(),i}doCancel(){const t=this.diagram;t.delaysLayout=!1,this.rotate(this.originalAngle),this.stopTool()}doMouseMove(){const t=this.diagram;if(this.isActive){const i=this.computeRotate(t.lastInput.documentPoint);this.rotate(i)}}doMouseUp(){const t=this.diagram;if(this.isActive){t.delaysLayout=!1;const i=this.computeRotate(t.lastInput.documentPoint);this.rotate(i),t.invalidateDocumentBounds(),this.transactionResult=this.name,t.D("PartRotated",this.adornedObject,this.originalAngle)}this.stopTool()}rotate(t){const i=this.adornedObject;if(i===null||i.part===null)return;i.angle=t;const e=i.part;e.ensureBounds();const s=e.locationObject,n=e.rotateObject;if(s===n||s.isContainedBy(n)){const o=this.wc.copy();e.location=o.subtract(this.rotationPoint).rotate(t-this.originalAngle).add(this.rotationPoint)}this.diagram.maybeUpdate()}computeRotate(t){let i=this.rotationPoint.directionPoint(t)-this.handleAngle;const e=this.adornedObject?.panel;e&&(i-=e.getDocumentAngle()),i>=360?i-=360:i<0&&(i+=360);const s=Math.min(Math.abs(this.snapAngleMultiple),180),n=Math.min(Math.abs(this.snapAngleEpsilon),s/2);return!this.diagram.lastInput.shift&&s>0&&n>0&&(i%ss-n&&(i=(Math.floor(i/s)+1)*s)),i>=360?i-=360:i<0&&(i+=360),i}get snapAngleMultiple(){return this.cS}set snapAngleMultiple(t){U.s(t,"number",RotatingTool,"snapAngleMultiple"),this.cS=t}get snapAngleEpsilon(){return this.fS}set snapAngleEpsilon(t){U.s(t,"number",RotatingTool,"snapAngleEpsilon"),this.fS=t}get originalAngle(){return this.uS}get rotationPoint(){return this.xm}set rotationPoint(t){this.xm=t.copy()}get handleAngle(){return this.dS}set handleAngle(t){U.s(t,"number",RotatingTool,"handleAngle"),this.dS=t}get handleDistance(){return this.gS}set handleDistance(t){U.s(t,"number",RotatingTool,"handleDistance"),this.gS=t}}class ClickSelectingTool extends Tool{constructor(t){super(),this.name="ClickSelecting",t&&Object.assign(this,t)}canStart(){return!(!this.isEnabled||this.isBeyondDragSize())}doMouseUp(){this.isActive&&(this.standardMouseSelect(),this.standardMouseClick()||this.diagram.lastInput.isTouchEvent&&this.diagram.toolManager.doToolTip()),this.stopTool()}}class ActionTool extends Tool{xc;constructor(t){super(),this.name="Action",this.xc=null,t&&Object.assign(this,t)}canStart(){if(!this.isEnabled)return!1;const t=this.diagram,i=t.lastInput,e=t.findObjectAt(i.documentPoint,s=>{for(;s.panel!==null;){if(s.isActionable)return s;s=s.panel}return s});return e!==null&&e.isActionable?(this.xc=e,t.gc=t.findObjectAt(i.documentPoint,null,null),!0):!1}doMouseDown(){if(!this.isActive)this.canStart()&&this.doActivate();else{const i=this.diagram.lastInput,e=this.xc;if(e===null)return;i.targetObject=e,e.actionDown!==null&&e.actionDown(i,e)}}doMouseMove(){if(this.isActive){const i=this.diagram.lastInput,e=this.xc;if(e===null)return;i.targetObject=e,e.actionMove!==null&&e.actionMove(i,e)}}doMouseUp(){if(this.isActive){const i=this.diagram.lastInput,e=this.xc;if(e===null)return;i.targetObject=e,e.actionUp!==null&&e.actionUp(i,e),this.standardMouseClick(s=>{for(;s.panel!==null;){if(s.isActionable&&s===e)return s;s=s.panel}return s},s=>s===e)}this.stopTool()}doCancel(){const i=this.diagram.lastInput,e=this.xc;e!==null&&(i.targetObject=e,e.actionCancel!==null&&e.actionCancel(i,e),this.stopTool())}doStop(){this.xc=null}}class ClickCreatingTool extends Tool{Ll;mS;yc;pS;constructor(t){super(),this.name="ClickCreating",this.Ll=null,this.mS=!0,this.yc=!1,this.pS=new Point(0,0),t&&Object.assign(this,t)}canStart(){if(!this.isEnabled||this.archetypeNodeData===null)return!1;const t=this.diagram;if(t.isReadOnly||t.isModelReadOnly||!t.allowInsert||!t.lastInput.left||this.isBeyondDragSize())return!1;if(this.isDoubleClick){if(t.lastInput.clickCount===1&&(this.pS=t.lastInput.viewPoint.copy()),t.lastInput.clickCount!==2||this.isBeyondDragSize(this.pS))return!1}else if(t.lastInput.clickCount!==1)return!1;return!(t.currentTool!==this&&t.findPartAt(t.lastInput.documentPoint,!0)!==null)}doMouseUp(){const t=this.diagram;this.isActive&&this.insertPart(t.lastInput.documentPoint),this.stopTool()}insertPart(t){const i=this.diagram,e=this.archetypeNodeData;if(e===null)return null;let s=null;try{if(i.D("ChangingSelection",i.selection),this.startTransaction(this.name),e instanceof Part)e.ke()&&(e.Et(),s=e.copy(),s!==null&&i.add(s));else if(e!==null){const n=i.model.copyNodeData(e);U.G(n)&&(i.model.addNodeData(n),s=i.findPartForData(n))}if(s!==null){const n=Point.V(t.x,t.y);this.isGridSnapEnabled&&this.diagram.yS(s,t,n),s.location=n,i.allowSelect&&(i.clearSelection(!0),s.isSelected=!0),Point.e(n)}i.invalidateDocumentBounds(),this.transactionResult=this.name,i.D("PartCreated",s)}finally{this.stopTransaction(),i.D("ChangedSelection",i.selection)}return s}get archetypeNodeData(){return this.Ll}set archetypeNodeData(t){t!==null&&U.ec(t,ClickCreatingTool,"archetypeNodeData"),this.Ll=t}get isDoubleClick(){return this.mS}set isDoubleClick(t){U.s(t,"boolean",ClickCreatingTool,"isDoubleClick"),this.mS=t}get isGridSnapEnabled(){return this.yc}set isGridSnapEnabled(t){U.s(t,"boolean",ClickCreatingTool,"isGridSnapEnabled"),this.yc=t}}class DragSelectingTool extends Tool{Xh;wS;Al;constructor(t){super(),this.name="DragSelecting",this.Xh=175,this.wS=!1,this.Al=new Part({layerName:"Tool",selectable:!1}).add(new Shape("Rectangle",{name:"SHAPE",fill:null,stroke:"magenta"}).theme("stroke","dragSelect")).Et(),t&&Object.assign(this,t)}canStart(){if(!this.isEnabled)return!1;const t=this.diagram;if(!t.allowSelect)return!1;const i=t.lastInput;return!(!i.left||t.currentTool!==this&&(!this.isBeyondDragSize()||i.timestamp-t.firstInput.timestamp{const e=i.diagram;e!==null&&e.Pi(root.document,"scroll",i.xS,!1),i.stopTool()},t&&Object.assign(this,t)}canStart(){if(!this.isEnabled)return!1;const t=this.diagram;return!(!t.allowHorizontalScroll&&!t.allowVerticalScroll||!t.lastInput.left||t.currentTool!==this&&!this.isBeyondDragSize())}doActivate(){const t=this.diagram;this.ko?(t.lastInput.bubbles=!0,t.Ut(root.document,"scroll",this.xS,!1)):(t.currentCursor="move",t.isMouseCaptured=!0,this.qw.a(t.position)),this.isActive=!0}doDeactivate(){const t=this.diagram;t.currentCursor="",t.isMouseCaptured=!1,this.isActive=!1}doCancel(){const t=this.diagram;t.position=this.qw,t.isMouseCaptured=!1,this.stopTool()}doMouseMove(){this.cL()}doMouseUp(){this.cL(),this.stopTool()}cL(){const t=this.diagram;if(this.isActive&&t){if(this.ko){t.lastInput.bubbles=!0;return}const i=t.position,e=t.firstInput.documentPoint,s=t.lastInput.documentPoint;let n=i.x+e.x-s.x,o=i.y+e.y-s.y;t.allowHorizontalScroll||(n=i.x),t.allowVerticalScroll||(o=i.y),t.position=this.aL.i(n,o)}}get bubbles(){return this.ko}set bubbles(t){U.s(t,"boolean",PanningTool,"bubbles"),this.ko=t}get originalPosition(){return this.qw}}class HTMLInfo{Ww;Jw;bS;kS;constructor(t){this.Ww=null,this.Jw=null,this.bS=null,this.kS=null,t&&Object.assign(this,t)}get mainElement(){return this.bS}set mainElement(t){this.bS=t}get show(){return this.Ww}set show(t){this.Ww!==t&&(t!==null&&U.k(t,HTMLInfo,"show"),this.Ww=t)}get hide(){return this.Jw}set hide(t){this.Jw!==t&&(t!==null&&U.k(t,HTMLInfo,"hide"),this.Jw=t)}get valueFunction(){return this.kS}set valueFunction(t){this.kS=t}}class ContextMenuButtonInfo{ri;$w;kc;constructor(t,i,e){this.ri=t,this.$w=i,this.kc=e}}class ContextMenuTool extends Tool{PS;Zw;SS;MS;Qw;_w;bm;constructor(t){super(),this.name="ContextMenu",this.PS=null,this.Zw=null,this.SS=null,this.MS=new Point,this.Qw=null,this.bm=!1;const i=this;this._w=()=>i.stopTool(),t&&Object.assign(this,t)}CF(){const t=new HTMLInfo;t.show=(r,l,h)=>h.showDefaultContextMenu(),t.hide=(r,l)=>l.hideDefaultContextMenu(),ContextMenuTool.wu=t;const i=this;this._w=()=>i.stopTool();const e=U.hs("div"),s=U.hs("div");e.style.cssText="top: 0px;z-index:10002;position: fixed;display: none;text-align: center;left: 25%;width: 50%;background-color: #F5F5F5;padding: 16px;border: 16px solid #444;border-radius: 10px;margin-top: 10px",s.style.cssText="z-index:10001;position: fixed;display: none;top: 0;left: 0;width: 100%;height: 100%;background-color: black;opacity: 0.8;";const n=U.hs("style");root.document.getElementsByTagName("head")[0].appendChild(n),n.sheet.insertRule(".goCXul { list-style: none; }",0),n.sheet.insertRule(".goCXli {font:700 1.5em Helvetica, Arial, sans-serif;position: relative;min-width: 60px; }",0),n.sheet.insertRule(".goCXa {color: #444;display: inline-block;padding: 4px;text-decoration: none;margin: 2px;border: 1px solid gray;border-radius: 10px; }",0);const o=this.diagram;o!==null&&(o.Ut(e,"contextmenu",ContextMenuTool.jh,!1),o.Ut(e,"selectstart",ContextMenuTool.jh,!1),o.Ut(s,"contextmenu",ContextMenuTool.jh,!1)),e.className="goCXforeground",s.className="goCXbackground",root.document.body&&(root.document.body.appendChild(e),root.document.body.appendChild(s)),ContextMenuTool.km=e,ContextMenuTool.Pm=s,ContextMenuTool.NS=!0}static wu=null;static NS=!1;static Pm;static km;static jh(t){return t.preventDefault(),!1}canStart(){if(!this.isEnabled)return!1;const t=this.diagram;return this.isBeyondDragSize()||!t.lastInput.right||t.lastInput.clickCount>1?!1:!!(t.lastInput.isTouchEvent&&this.defaultTouchContextMenu!==null||this.findObjectWithContextMenu()!==null)}doStart(){const t=this.diagram;this.MS.set(t.firstInput.documentPoint)}doStop(){this.hideContextMenu(),this.currentObject=null,this.bm=!1}findObjectWithContextMenu(t){t===void 0&&(t=null);const i=this.diagram,e=i.lastInput;let s=null;if(t instanceof Diagram||(t instanceof GraphObject?s=t:s=i.findObjectAt(e.documentPoint,null,n=>!n.layer?.isTemporary)),s!==null){let n=s;for(;n!==null;){if(n.contextMenu!==null)return n;n=n.panel}if(i.lastInput.isTouchEvent&&this.defaultTouchContextMenu)return s.part}else if(i.contextMenu!==null)return i;return null}doActivate(){}doMouseDown(){if(super.doMouseDown(),this.isActive&&this.currentContextMenu instanceof Adornment){const t=this.diagram.toolManager.findTool("Action");t!==null&&t.canStart()&&(t.doActivate(),t.doMouseDown(),t.doDeactivate())}this.diagram.toolManager.mouseDownTools.has(this)&&this.doContextClick()}doMouseUp(){if(this.isActive&&this.currentContextMenu instanceof Adornment){const t=this.diagram.toolManager.findTool("Action");t!==null&&t.canStart()&&(t.doActivate(),t.doCancel(),t.doDeactivate())}this.doContextClick()}doContextClick(){const t=this.diagram;if(!this.isActive)this.canStart()&&(this.openMenu(!0),this.isActive||this.stopTool());else{const i=this.currentContextMenu;if(i===null)return;let e=null;i instanceof HTMLInfo||(e=t.findObjectAt(t.lastInput.documentPoint,null,null),e!==null&&e.isContainedBy(i)&&this.standardMouseClick(null,null)),this.maybeStopTool(e)}}maybeStopTool(t){this.stopTool(),this.canStart()&&(this.diagram.currentTool=this,this.doMouseUp())}openMenu(t,i){if(i===void 0&&(i=null),this.bm)return;this.bm=!0,t&&this.standardMouseSelect();const e=this.standardMouseClick();if(this.bm=!1,!e){this.isActive=!0;const s=ContextMenuTool.wu;if(i===null&&(i=this.findObjectWithContextMenu()),i!==null){const n=i.contextMenu;n!==null?(this.currentObject=i instanceof GraphObject?i:null,this.showContextMenu(n,this.currentObject)):s!==null&&this.showContextMenu(s,this.currentObject)}else s!==null&&this.showContextMenu(s,null);this.currentContextMenu instanceof Adornment&&!this.currentContextMenu.visible&&this.stopTool()}}doMouseMove(){const t=this.diagram.toolManager.findTool("Action");t!==null&&t.doMouseMove(),this.isActive&&this.diagram.toolManager.doMouseMove()}showContextMenu(t,i){const e=this.diagram;if(t!==this.currentContextMenu&&this.hideContextMenu(),t instanceof Adornment){const s=t;s.layerName="Tool",s.selectable=!1,s.scale=1/e.scale,s.category=this.name,s.hasPlaceholder()&&(s.placeholder.scale=e.scale);const n=s.diagram;n!==null&&n!==e&&n.remove(s),e.add(s),i!==null?s.adornedObject=i:s.data=e.model,s.ensureBounds(),this.positionContextMenu(s,i)}else t instanceof HTMLInfo&&t.show!==null&&t.show(i,e,this);this.currentContextMenu=t}positionContextMenu(t,i){if(t.hasPlaceholder())return;const e=t,s=this.diagram,n=s.lastInput.documentPoint.copy(),o=e.measuredBounds,r=s.viewportBounds;s.lastInput.isTouchEvent&&(n.x-=o.width),n.x+o.width>r.right&&(n.x-=o.width+5/s.scale),n.xr.bottom&&(n.y-=o.height+5/s.scale),n.ye.commandHandler.copySelection(),e=>e.commandHandler.canCopySelection())),i.add(new ContextMenuButtonInfo("Cut",e=>e.commandHandler.cutSelection(),e=>e.commandHandler.canCutSelection())),i.add(new ContextMenuButtonInfo("Delete",e=>e.commandHandler.deleteSelection(),e=>e.commandHandler.canDeleteSelection())),i.add(new ContextMenuButtonInfo("Paste",e=>e.commandHandler.pasteSelection(t.mouseDownPoint),e=>e.commandHandler.canPasteSelection(t.mouseDownPoint))),i.add(new ContextMenuButtonInfo("Select All",e=>e.commandHandler.selectAll(),e=>e.commandHandler.canSelectAll())),i.add(new ContextMenuButtonInfo("Undo",e=>e.commandHandler.undo(),e=>e.commandHandler.canUndo())),i.add(new ContextMenuButtonInfo("Redo",e=>e.commandHandler.redo(),e=>e.commandHandler.canRedo())),i.add(new ContextMenuButtonInfo("Scroll To Part",e=>e.commandHandler.scrollToPart(),e=>e.commandHandler.canScrollToPart())),i.add(new ContextMenuButtonInfo("Zoom To Fit",e=>e.commandHandler.zoomToFit(),e=>e.commandHandler.canZoomToFit())),i.add(new ContextMenuButtonInfo("Reset Zoom",e=>e.commandHandler.resetZoom(),e=>e.commandHandler.canResetZoom())),i.add(new ContextMenuButtonInfo("Group Selection",e=>e.commandHandler.groupSelection(),e=>e.commandHandler.canGroupSelection())),i.add(new ContextMenuButtonInfo("Ungroup Selection",e=>e.commandHandler.ungroupSelection(),e=>e.commandHandler.canUngroupSelection())),i.add(new ContextMenuButtonInfo("Edit Text",e=>e.commandHandler.editTextBlock(),e=>e.commandHandler.canEditTextBlock())),i}showDefaultContextMenu(){const t=this.diagram;this.Qw===null&&(this.Qw=this.LF()),ContextMenuTool.km.innerHTML="",ContextMenuTool.Pm.addEventListener("pointerdown",this._w,!1);const i=this,e=U.hs("ul");e.className="goCXul",ContextMenuTool.km.appendChild(e),e.innerHTML="";const s=this.Qw.iterator;for(;s.next();){const n=s.value,o=n.$w,r=n.kc;if(!U.it(o)||U.it(r)&&!r(t))continue;const l=U.hs("li");l.className="goCXli";const h=U.hs("a");h.className="goCXa",h.href="#",h.$w=o,h.addEventListener("pointerdown",function(c){return this.$w(t),i.stopTool(),c.preventDefault(),!1},!1),h.textContent=n.ri,l.appendChild(h),e.appendChild(l)}ContextMenuTool.km.style.display="block",ContextMenuTool.Pm.style.display="block"}hideDefaultContextMenu(){if(this.currentContextMenu===null||this.currentContextMenu!==ContextMenuTool.wu)return;ContextMenuTool.km.style.display="none",ContextMenuTool.Pm.style.display="none";const t=this.diagram;t!==null&&t.Pi(ContextMenuTool.Pm,"pointerdown",this._w,!1),this.currentContextMenu=null}get currentContextMenu(){return this.PS}set currentContextMenu(t){this.PS=t,this.Zw=t instanceof Adornment?t.adornedPart:null}get defaultTouchContextMenu(){return ContextMenuTool.NS===!1&&ContextMenuTool.wu===null&&Diagram.isUsingDOM()&&this.CF(),ContextMenuTool.wu}set defaultTouchContextMenu(t){t===null&&(ContextMenuTool.NS=!0),ContextMenuTool.wu=t}get currentObject(){return this.SS}set currentObject(t){this.SS=t}get mouseDownPoint(){return this.MS}}var TextEditingAccept=(y=>(y[y.LostFocus=1]="LostFocus",y[y.MouseDown=2]="MouseDown",y[y.Tab=3]="Tab",y[y.Enter=4]="Enter",y))(TextEditingAccept||{}),TextEditingStarting=(y=>(y[y.SingleClick=1]="SingleClick",y[y.SingleClickSelected=2]="SingleClickSelected",y[y.DoubleClick=3]="DoubleClick",y))(TextEditingStarting||{}),TextEditingState=(y=>(y[y.None=1]="None",y[y.Active=2]="Active",y[y.Editing=3]="Editing",y[y.Validating=4]="Validating",y[y.Invalid=5]="Invalid",y[y.Validated=6]="Validated",y))(TextEditingState||{});class TextEditingTool extends Tool{Pe;CS;LS;Tl;Gt;AS;TS;DS;tx;FS;constructor(t){super(),this.name="TextEditing",this.Pe=new TextBlock,this.CS=null,this.LS=2,this.Tl=null,this.Gt=1,this.AS=1,this.TS=!0,this.DS=null,this.tx=new HTMLInfo,this.AF(this.tx),t&&Object.assign(this,t)}static LostFocus=1;static MouseDown=2;static Tab=3;static Enter=4;static SingleClick=1;static SingleClickSelected=2;static DoubleClick=3;static StateNone=1;static StateActive=2;static StateEditing=3;static StateValidating=4;static StateInvalid=5;static StateValidated=6;AF(t){if(!Diagram.isUsingDOM())return;const i=U.hs("textarea");this.FS=i;const e=this;i.addEventListener("input",function(s){if(e.textBlock===null)return;const n=e.measureTemporaryTextBlock(this.value),o=this.textScale;this.style.width=20+Math.max(e.textBlock.measuredBounds.width,n.measuredBounds.width)*o+"px",this.rows=Math.max(e.textBlock.lineCount,n.lineCount)},!1),i.addEventListener("keydown",function(s){if(s.isComposing||e.textBlock===null)return;const n=s.key;if(n==="Enter"){e.textBlock.isMultiline===!1&&s.preventDefault(),e.acceptText(4);return}else if(n==="Tab"){e.acceptText(3),s.preventDefault();return}else n==="Escape"&&(e.doCancel(),e.diagram!==null&&e.diagram.doFocus())},!1),i.addEventListener("focus",function(s){e.TF(s)},!1),i.addEventListener("blur",function(s){e.DF(s)},!1),t.valueFunction=()=>i.value,t.mainElement=i,t.show=(s,n,o)=>{if(!(s instanceof TextBlock)||!n||!n.div||!(o instanceof TextEditingTool))return;if(o.state===5){i.style.border="3px solid red",i.focus();return}const r=s.getDocumentPoint(Spot.Center),l=n.position,h=n.scale;let c=s.getDocumentScale()*h;c{s.div&&s.div.removeChild(i)}}get textBlock(){return this.CS}set textBlock(t){this.CS=t}get currentTextEditor(){return this.DS}set currentTextEditor(t){this.DS=t}get defaultTextEditor(){return this.tx}set defaultTextEditor(t){this.tx=t}get starting(){return this.LS}set starting(t){this.LS=t}canStart(){if(!this.isEnabled)return!1;const t=this.diagram;if(t===null||t.isReadOnly||TextEditingTool.Pc&&TextEditingTool.Pc!==this&&(TextEditingTool.Pc.acceptText(2),TextEditingTool.Pc&&TextEditingTool.Pc!==this)||!t.lastInput.left||this.isBeyondDragSize())return!1;const i=t.lastInput.documentPoint,e=t.findObjectAt(i);if(e===null||!(e instanceof TextBlock)||!e.editable||e.part===null||!e.part.canEdit())return!1;const s=e.part;return!(s===null||this.starting===2&&!s.isSelected||this.starting===3&&t.lastInput.clickCount<2)}doStart(){TextEditingTool.Pc=this,this.textBlock!==null&&this.doActivate()}doActivate(){if(this.isActive)return;const t=this.diagram;if(t===null)return;let i=this.textBlock;if(i===null&&(i=t.findObjectAt(t.lastInput.documentPoint)),i===null||!(i instanceof TextBlock)||(this.textBlock=i,i.part===null))return;t.animationManager.stopAnimation(),this.isActive=!0,this.Gt=2;let s=this.defaultTextEditor;i.textEditor!==null&&(s=i.textEditor),this.Pe=this.textBlock.copy();const n=new Rect(this.textBlock.getDocumentPoint(Spot.TopLeft),this.textBlock.getDocumentPoint(Spot.BottomRight));t.scrollToRect(n),s!==null&&s.show!==null&&s.show(i,t,this),this.currentTextEditor=s}doCancel(){this.stopTool()}doMouseUp(){this.canStart()&&this.doActivate()}doMouseDown(){this.isActive&&this.acceptText(2)}acceptText(t){switch(t){case 2:this.Gt===6?this.currentTextEditor instanceof HTMLElement&&this.currentTextEditor.focus():(this.Gt===2||this.Gt===5||this.Gt===3)&&(this.Gt=4,this.fL());break;case 1:case 4:case 3:if(t===4&&this.textBlock!==null&&this.textBlock.isMultiline===!0)return;(this.Gt===2||this.Gt===5||this.Gt===3)&&(this.Gt=4,this.fL());break}}fL(){const t=this.textBlock,i=this.diagram,e=this.currentTextEditor;if(t!==null&&e!==null){const s=t.text;let n="";if(e.valueFunction!==null&&(n=e.valueFunction()),!this.isValidText(t,s,n)){this.Gt=5,this.doError(s,n);return}this.startTransaction(this.name),this.Gt=6,this.transactionResult=this.name,t.text=n,this.doSuccess(s,n),i!==null&&i.D("TextEdited",t,s),this.stopTransaction(),this.stopTool(),i!==null&&i.doFocus()}}doError(t,i){const e=this.textBlock;if(e===null)return;e.errorFunction!==null&&e.errorFunction(this,t,i);const s=this.currentTextEditor;s!==null&&s.show!==null&&s.show(e,this.diagram,this)}doSuccess(t,i){const e=this.textBlock;e!==null&&e.textEdited!==null&&e.textEdited(e,t,i)}doDeactivate(){const t=this.diagram;if(t!==null){if(this.Gt=1,this.currentTextEditor!==null){const i=this.currentTextEditor;i!==null&&i.hide!==null&&i.hide(t,this)}this.textBlock=null,this.isActive=!1}}doStop(){TextEditingTool.Pc=null}TF(t){if(this.currentTextEditor===null||this.state===1)return;const i=this.FS;this.Gt===2&&(this.Gt=3),U.it(i.select)&&this.selectsTextOnActivate&&(i.select(),i.setSelectionRange(0,9999))}DF(t){if(this.currentTextEditor===null||this.state===1)return;const i=this.FS;U.it(i.focus)&&i.focus(),U.it(i.select)&&this.selectsTextOnActivate&&(i.select(),i.setSelectionRange(0,9999))}isValidText(t,i,e){const s=this.textValidation;if(s!==null&&!s(t,i,e))return!1;const n=t.textValidation;return!(n!==null&&!n(t,i,e))}get textValidation(){return this.Tl}set textValidation(t){t!==null&&U.k(t,TextEditingTool,"textValidation"),this.Tl=t}get minimumEditorScale(){return this.AS}set minimumEditorScale(t){t!==null&&U.s(t,"number",TextEditingTool,"minimumEditorScale"),this.AS=t}get selectsTextOnActivate(){return this.TS}set selectsTextOnActivate(t){t!==null&&U.s(t,"boolean",TextEditingTool,"selectsTextOnActivate"),this.TS=t}get state(){return this.Gt}set state(t){this.Gt!==t&&(this.Gt=t)}measureTemporaryTextBlock(t){const i=this.Pe;return i.text=t,this.textBlock!==null&&i.ht(this.textBlock.Dl,1/0),i}static Pc=null}var AnimationStyle=(y=>(y[y.Default=1]="Default",y[y.AnimateLocations=2]="AnimateLocations",y[y.None=3]="None",y))(AnimationStyle||{});class AnimationManager{N;Si;Oi;wr;zn;So;RS;vS;Sm;pi;Sc;on;Mm;Hh;ix;Nm;ex;Mc;pu;Cm;constructor(t){this.N=Diagram.um(),this.Si=!1,this.Sm=!1,this.pi=!1,this.Sc=!1,this.ex=!0,this.Mc=1,this.pu=!1,this.Oi=!0,this.wr=!0,this.So=600,this.RS=!1,this.vS=!1,this.zn=new GSet,this.on=new Animation,this.Mm=new Animation,this.on.ds=this,this.Hh=new GSet,this.ix=new GSet,this.Nm=new GSet,this.Cm=new GSet,t&&Object.assign(this,t)}Mo(t){this.N=t}NE(){return this.N}canStart(t){return!0}Fl(t){return!this.Oi||!this.canStart(t)?!1:(this.zn.add(t),this.defaultAnimation.isAnimating&&this.stopAnimation(),this.N.Mi(),this.pi=!0,!0)}getBundleAnimation(){return this.Mm}OS(){if(!this.Oi||(this.Mm.ce.count>0&&this.Mm.start(),!this.pi))return;const t=this.on,i=this.N,e=this.zn.has("Model");if(e&&(this.Sc=!0,this.Mc===1?(t.isViewportUnconstrained=!0,t.ce.clear(),t.add(i,"position",i.position.copy().offset(0,-200),i.position),t.add(i,"opacity",0,1)):this.Mc===3&&t.ce.clear(),this.Mc===2&&i.nx.equals(i.at)?this.ex=!0:this.ex=!1,i.D("InitialAnimationStarting",this)),e&&!this.wr||t.ce.count===0){this.zn.clear(),this.pi=!1,t.ce.clear(),t.lx(i),this.Sc=!1,i.S();return}this.zn.clear(),i.xr=!1;const s=t.ce.get(i);i.autoScale!==1&&s!==null&&(delete s.ei.scale,delete s.gs.scale);const n=this;root.requestAnimationFrame(()=>{n.pi===!1||t.Si||(i.getRenderingHint("temporaryPixelRatio")&&i.Vw(),i.IS(),n.pi=!1,t.start(),t.Si&&(n.xu(),i.invalidateDocumentBounds(),t.uL(0),i.ur(!0),n.bu(),i.D("AnimationStarting",n)))})}ES(){return this.zn.has("Trigger")&&this.zn.count===1}dL(t,i,e,s){this.isTicking||this.ES()||t instanceof Link&&(t.fromNode!==null||t.toNode!==null)||this.on.add(t,"position",i,e,s)}hx(t){return this.on.hx(t)}US(t){return this.on.US(t)}FF(t){const i=this.Hh,e=this;function s(){if(e.Nm.count>0&&(i.addAll(e.Nm),e.Nm.clear(),e.Si=!0),e.Si===!1||i.count===0)return;e.ix.addAll(i);const n=e.ix.iterator;for(;n.next();){const o=n.value;o.Si!==!1&&(o.RF()?o.gL(!1):o.Nc=!0)}if(e.ix.clear(),e.Si===!1){root.requestAnimationFrame(s);return}e.xu(),e.N.ur(),e.bu(),root.requestAnimationFrame(s)}this.Si?this.vF(t):(this.Si=!0,i.add(t),root.requestAnimationFrame(()=>s()))}vF(t){this.Nm.add(t)}OF(){const t=this.Hh.iterator;for(;t.next();)t.value.Nc=!1}xu(){if(this.Sm)return;const t=this.N;this.RS=t.skipsUndoManager,this.vS=t.fe,t.skipsUndoManager=!0,t.fe=!0,this.Sm=!0}bu(){const t=this.N;t.skipsUndoManager=this.RS,t.fe=this.vS,this.Sm=!1}stopAnimation(t){const i=this.on;if(this.pi===!0&&(this.pi=!1,this.Sc=!1,this.zn.clear(),i.IF()&&this.N.requestUpdate()),!this.Si){i.ce.clear(),i.lx(this.N);return}if(i.ku(!0),i.lx(null),t===!0){const e=this.Hh.toArray();for(let s=0;s{!i.isAnimating&&i.runCount===1/0&&i.start()})}get duration(){return this.So}set duration(t){U.s(t,"number",AnimationManager,"duration"),t<1&&U.W(t,">= 1",AnimationManager,"duration"),this.So=t}get isAnimating(){return this.Si}get isTicking(){return this.Sm}get isInitial(){return this.wr}set isInitial(t){U.s(t,"boolean",AnimationManager,"isInitial"),this.wr=t}get defaultAnimation(){return this.on}get activeAnimations(){return this.Hh}get initialAnimationStyle(){return this.Mc}set initialAnimationStyle(t){this.Mc=t}static ax=new GMap;static defineAnimationEffect(t,i){AnimationManager.ax.set(t,i)}static zS(t,i,e,s,n){t===null&&(t=[0,0,0,0]),i===null&&(i=[0,0,0,0]);let o=t[0],r=t[1];const l=t[2],h=t[3];let c=i[0],a=i[1];const f=i[2],u=i[3];l===0||l===100?(o=c,r=a):(f===0||f===100)&&(c=o,a=r),Math.abs(c-o)>180&&(c>o?o+=360:c+=360);const d=n(e,o,c-o,s)%360,m=n(e,r,a-r,s),g=n(e,l,f-l,s),p=n(e,h,u-h,s);return"hsla("+d+", "+m+"%, "+g+"%, "+p+")"}static Default=1;static AnimateLocations=2;static None=3}{const y=AnimationManager.ax,t=(i,e,s,n,o,r)=>{i.position=new Point(n(o,e.x,s.x-e.x,r),n(o,e.y,s.y-e.y,r))};y.set("position:diagram",t),y.set("position",t),y.set("position:part",(i,e,s,n,o,r)=>{o{o{o{const l=i.actualBounds,h=s.actualBounds,c=h.x+h.width/2-l.width/2,a=h.y+h.height/2-l.height/2;o{i.desiredSize=new Size(n(o,e.width,s.width-e.width,r),n(o,e.height,s.height-e.height,r))}),y.set("width",(i,e,s,n,o,r)=>{i.width=n(o,e,s-e,r)}),y.set("height",(i,e,s,n,o,r)=>{i.height=n(o,e,s-e,r)}),y.set("fill",(i,e,s,n,o,r)=>{i.fill=AnimationManager.zS(e,s,o,r,n)}),y.set("stroke",(i,e,s,n,o,r)=>{i.stroke=AnimationManager.zS(e,s,o,r,n)}),y.set("strokeWidth",(i,e,s,n,o,r)=>{i.strokeWidth=n(o,e,s-e,r)}),y.set("strokeDashOffset",(i,e,s,n,o,r)=>{i.strokeDashOffset=n(o,e,s-e,r)}),y.set("background",(i,e,s,n,o,r)=>{i.background=AnimationManager.zS(e,s,o,r,n)}),y.set("opacity",(i,e,s,n,o,r)=>{i.opacity=n(o,e,s-e,r)}),y.set("scale",(i,e,s,n,o,r)=>{i.scale=n(o,e,s-e,r)}),y.set("angle",(i,e,s,n,o,r)=>{i.angle=n(o,e,s-e,r)})}class Animation{cx;Lm;Si;Pu;So;ms;wL;Ac;ce;fx;ei;Xn;Su;Tc;ux;gx;Nc;XS;mx;ds;N;YS;GS;KS;constructor(t){this.N=null,this.ds=null,this.XS=null,this.mx=null,this.YS=!1,this.Si=!1,this.Nc=!1,this.ei=0,this.Xn=0,this.cx=Animation.EaseInOutQuad,this.Lm=Animation.EaseInOutQuad,this.Su=!1,this.Tc=!1,this.ux=1,this.gx=0,this.So=NaN,this.ms=NaN,this.GS=0,this.Pu=null,this.wL=Point.xo,this.ce=new GMap,this.fx=new GMap,this.Ac=new GSet,this.KS=1,t&&Object.assign(this,t)}suspend(){this.Nc=!0}advanceTo(t,i){i&&(this.Nc=!1),this.Su&&t>=this.ms&&(this.Tc=!0,t=t-this.ms),this.GS=t,this.gL(!0),this.ds.xu(),this.N.ur(),this.ds.bu(),this.N.redraw()}lx(t){if(this.fx.clear(),this.Tc=!1,this.gx=0,this.ms=NaN,this.Ac.count>0&&this.Ac.clear(),t!==null){const i=t.links;for(;i.next();)i.value.br=null}}IF(){return this.ce.count>0}start(){if(this.ce.count===0)return this;if(this.Si)return this;let t=this.N;const i=this.ce.iterator;for(;i.next();){const s=i.key;t===null&&(s instanceof Diagram?t=s:s instanceof GraphObject&&(t=s.diagram))}if(t!==null)this.N=t,this.ds=t.animationManager;else return this;const e=this.ds;return e.isEnabled===!1?this:(this.ms=isNaN(this.So)?e.duration:this.So,this.Lm=this.cx,e.Sc&&e.Mc===1&&this===e.defaultAnimation&&(this.Lm=Animation.EaseOutExpo,this.ms=isNaN(this.So)?e.duration===600?900:e.duration:this.So),this.KS=t.scrollMode,this.isViewportUnconstrained&&(t.qh=2),e.xu(),this.Ac.each(s=>{s.data=null,t.add(s)}),e.bu(),this.Si=!0,this.ei=+new Date,this.Xn=this.ei+this.ms,e.FF(this),this)}addTemporaryPart(t,i){return t.ke()?(this.Ac.add(t),this.N=i,this):this}add(t,i,e,s,n){if(this.N===null&&(t instanceof Diagram?this.N=t:t instanceof GraphObject&&t.diagram!==null&&(this.N=t.diagram)),t instanceof Part){if(!t.isAnimated)return this;i==="position"&&(i="position:part")}return this.BS(t,i,e,s,n),this}BS(t,i,e,s,n){const o=this.ce;let r,l,h;if(t instanceof Diagram&&i==="position"&&(i="position:diagram"),(i==="fill"||i==="stroke"||i==="background")&&(Brush.No(e),Brush.jS(),e=[Brush.Ii.n0,Brush.Ii.n1,Brush.Ii.n2,Brush.Ii.n3],Brush.No(s),Brush.jS(),s=[Brush.Ii.n0,Brush.Ii.n1,Brush.Ii.n2,Brush.Ii.n3]),o.has(t))r=o.get(t),l=r.ei,h=r.gs,l[i]===void 0&&(l[i]=this.Mu(e)),h[i]=this.Mu(s);else{if(i==="position"&&e.equalsApprox(s))return;l={},h={},l[i]=this.Mu(e),h[i]=this.Mu(s),r=new AnimationState(l,h,n),o.set(t,r)}const c=l[i];c instanceof Point&&!c.isReal()&&c.a(this.wL),n&&i.indexOf("position:")===0&&t instanceof Part?r.yx.location=this.Mu(t.location):n&&(r.yx[i]=this.Mu(e))}Mu(t){return t instanceof Point||t instanceof Size?t.copy():t}EF(t){const i=this.ce;if(i.has(t)){const e=i.get(t);e.wx=!0}}hx(t){if(!this.Si)return!1;const i=this.ce.get(t);return i!==null&&i.wx}US(t){if(!this.Si)return!1;const i=this.ce.get(t);return i!==null&&!!(i.ei.position||i.ei["position:part"]||i.ei.location)}RF(){if(this.Ac.count>0)return!0;const t=this.ce.iterator;for(;t.next();){const i=t.key;if(i instanceof GraphObject&&i.diagram!==null||i instanceof Diagram)return!0}return!1}gL(t){if(this.Nc&&!t)return;const i=this.ds;if(this.Si===!1)return;const e=+new Date;let s=e>this.Xn?this.ms:e-this.ei;t&&(s=this.GS,sthis.Xn&&(this.Su&&!this.Tc?(this.ei=+new Date,this.Xn=this.ei+this.ms,this.Tc=!0):this.ku(!1))}uL(t){const i=this.ms,e=this.ce.iterator,s=this.Tc;for(;e.next();){const n=e.key;if(n instanceof GraphObject&&n.diagram===null)continue;const o=e.value,r=s?o.gs:o.ei,l=s?o.ei:o.gs,h=AnimationManager.ax;for(const c in l)c==="position"&&(l["position:placeholder"]||l["position:nodeCollapse"])||h.get(c)!==null&&h.get(c)(n,r[c],l[c],this.Lm,t,i,this)}}stop(){return this.Si?(this.ku(!0),this):this}ku(t){if(this.mx!==null&&this.mx.UF(this.XS),!this.Si)return;const i=this.N,e=this.ds;e.Sc=!1,this.Si=!1,this.Nc=!1,e.xu();const s=this.ce,n=this.Ac.iterator;for(;n.next();)i.remove(n.value);const o=this.Su,r=s.iterator,l=AnimationManager.ax;for(;r.next();){const c=r.key,a=r.value,f=o?a.gs:a.ei,u=o?a.ei:a.gs,d=a.yx;for(const m in u)if(l.get(m)!==null){let g=m;a.xx&&(g==="position:nodeCollapse"||g==="position:placeholder")&&(g="position"),l.get(g)(c,f[m],d[m]!==void 0?d[m]:a.xx?f[m]:u[m],this.Lm,this.ms,this.ms,this)}a.xx&&d.location!==void 0&&c instanceof Part&&(c.location=d.location),a.wx&&c instanceof Part&&c.Ei(!1)}this.gx++;const h=!t&&this.ux>this.gx;if(!h&&(this===e.Mm||this===e.defaultAnimation)&&this.ce.clear(),i.bx.clear(),i.CP(!1),i.invalidateDocumentBounds(),i.S(),i.ur(!0),e.defaultAnimation===this){const c=e.Cm.iterator;for(;c.next();)c.value.BF();e.Cm.clear()}if(i.ur(!0),this.isViewportUnconstrained&&(i.scrollMode=this.KS),e.bu(),h){this.Tc=!1,this.start();return}this.lx(null),i.xL(),e.ku(this),this.Pu&&this.Pu(this),i.requestUpdate()}Cc(t,i){const e=i.actualBounds;let s=null;if(i instanceof Group&&(s=i.placeholder),s!==null&&s.visible){const n=s.getDocumentPoint(Spot.TopLeft),o=s.padding;n.x+=o.left,n.y+=o.top,this.add(t,"position",n,t.position,!1)}else this.add(t,"position",new Point(e.x+e.width/2,e.y+e.height/2),t.position,!1);this.add(t,"scale",.01,t.scale,!1),t instanceof Group&&this.VF(t,i)}VF(t,i){const e=t.memberParts;for(;e.next();){const s=e.value;s instanceof Node&&this.Cc(s,i)}}Lc(t,i){if(!t.isVisible())return;let e=null;if(i instanceof Group&&(e=i.placeholder),e!==null&&e.visible){const s=e.getDocumentPoint(Spot.TopLeft),n=e.padding;s.x+=n.left,s.y+=n.top,this.add(t,"position:placeholder",t.position,s,!0)}else this.add(t,"position:nodeCollapse",t.position,i,!0);this.add(t,"scale",t.scale,.01,!0),this.EF(t),t instanceof Group&&this.zF(t,i)}zF(t,i){const e=t.memberParts;for(;e.next();){const s=e.value;s instanceof Node&&this.Lc(s,i)}}get duration(){return this.So}set duration(t){U.s(t,"number",Animation,"duration"),t<1&&U.W(t,">= 1",Animation,"duration"),this.So=t}get reversible(){return this.Su}set reversible(t){this.Su=t}get runCount(){return this.ux}set runCount(t){t>0?this.ux=t:U.o("Animation.runCount value must be a positive integer.")}get finished(){return this.Pu}set finished(t){this.Pu!==t&&(t!==null&&U.k(t,Animation,"finished"),this.Pu=t)}get easing(){return this.cx}set easing(t){this.cx=t}get isViewportUnconstrained(){return this.YS}set isViewportUnconstrained(t){this.YS=t}get isAnimating(){return this.Si}getTemporaryState(t){let i=this.fx.get(t);return i===null&&(i={},this.fx.set(t,i)),i}static EaseLinear=(t,i,e,s)=>e*t/s+i;static EaseInOutQuad=(t,i,e,s)=>(t/=s/2,t<1?e/2*t*t+i:-e/2*(--t*(t-2)-1)+i);static EaseInQuad=(t,i,e,s)=>e*(t/=s)*t+i;static EaseOutQuad=(t,i,e,s)=>-e*(t/=s)*(t-2)+i;static EaseInExpo=(t,i,e,s)=>t===0?i:e*Math.pow(2,10*(t/s-1))+i;static EaseOutExpo=(t,i,e,s)=>t===s?i+e:e*(-Math.pow(2,-10*t/s)+1)+i}class AnimationState{ei;gs;yx;xx;wx;constructor(t,i,e){this.ei=t,this.gs=i,this.yx={},this.xx=e,this.wx=!1}}var TriggerStart=(y=>(y[y.Default=1]="Default",y[y.Immediate=2]="Immediate",y[y.Bundled=3]="Bundled",y))(TriggerStart||{});class AnimationTrigger{be;en;Nu;Dc;constructor(t,i,e){this.be=null,this.en=t,this.Nu=e||1,this.Dc=null,i!==void 0&&(this.Dc=i,e===void 0&&(this.Nu=2))}copy(){const t=new AnimationTrigger(this.en);t.Nu=this.Nu;const i=this.Dc;if(i!==null){const e={};i.duration!==void 0&&(e.duration=i.duration),i.finished!==void 0&&(e.finished=i.finished),i.easing!==void 0&&(e.easing=i.easing),t.Dc=e}return t}get propertyName(){return this.en}set propertyName(t){this.en=t}get animationSettings(){return this.Dc}set animationSettings(t){this.Dc=t}XF(t){const i=this.Dc;i!==null&&(i.duration&&(t.duration=i.duration),i.finished&&(t.finished=i.finished),i.easing&&(t.easing=i.easing))}get startCondition(){return this.Nu}set startCondition(t){this.Nu=t}static Default=1;static Immediate=2;static Bundled=3}class Layer{N;St;$t;kr;Rl;vl;Ol;Il;El;Ul;Bl;Vl;zl;Xl;Yl;Gl;kc;Kl;kx;Am;Cu;Ct;constructor(t){GSet.Ki(this),this.N=null,this.Ct=new List,this.St="",this.$t=1,this.kr=!1,this.Rl=!0,this.vl=!0,this.Ol=!0,this.Il=!0,this.El=!0,this.Ul=!0,this.Bl=!0,this.Vl=!0,this.zl=!0,this.Xl=!0,this.Yl=!0,this.Gl=!0,this.kc=!0,this.Kl=!0,this.kx=!0,this.Am=!1,this.Cu=[],t&&Object.assign(this,t)}YF(){const t=this.Ct;for(let i=0;i0&&(h+=e+" Parts "),s>0&&(h+=s+" Nodes "),n>0&&(h+=n+" Groups "),o>0&&(h+=o+" Links "),r>0&&(h+=r+" Adornments "),t>1){const c=this.Ct.iterator;for(;c.next();){const a=c.value;h+=` `+a.toString();const f=a.data;f!==null&&GSet.as(f)&&(h+=" #"+GSet.as(f)),a instanceof Node?h+=" "+U.toString(f):a instanceof Link&&(h+=" "+U.toString(a.fromNode)+" "+U.toString(a.toNode))}}return i+" "+this.Ct.count+": "+h}findObjectAt(t,i,e){if(i===void 0&&(i=null),e===void 0&&(e=null),this.Kl===!1)return null;let s=!1;this.diagram!==null&&this.diagram.viewportBounds.containsPoint(t)&&(s=!0);const n=Point.l(),o=this.Ct.r,r=o.length;for(let l=r;l--;){const h=o[l];if(s===!0&&h.Nl()===!1||!h.isVisible())continue;n.a(t),n.Oe(h.Us);let c=h.bL(n,i,e);if(c!==null&&(i!==null&&(c=i(c)),c!==null&&(e===null||e(c))))return Point.e(n),c}return Point.e(n),null}findObjectsAt(t,i,e,s){if(i===void 0&&(i=null),e===void 0&&(e=null),!(s instanceof List)&&!(s instanceof GSet)&&(s=new GSet),this.Kl===!1)return s;let n=!1;this.diagram!==null&&this.diagram.viewportBounds.containsPoint(t)&&(n=!0);const o=Point.l(),r=this.Ct.r,l=r.length;for(let h=l;h--;){const c=r[h];if(n===!0&&c.Nl()===!1||!c.isVisible())continue;o.a(t),o.Oe(c.Us);let a=c;c.kL(o,i,e,s)&&(i!==null&&(a=i(a)),a!==null&&(e===null||e(a))&&s.add(a))}return Point.e(o),s}findObjectsIn(t,i,e,s,n){if(i===void 0&&(i=null),e===void 0&&(e=null),s===void 0&&(s=!1),!(n instanceof List)&&!(n instanceof GSet)&&(n=new GSet),this.Kl===!1)return n;let o=!1;this.diagram!==null&&this.diagram.viewportBounds.containsRect(t)&&(o=!0);const r=this.Ct.r,l=r.length;for(let h=l;h--;){const c=r[h];if(o===!0&&c.Nl()===!1||!c.isVisible())continue;let a=c;c.Tm(t,i,e,s,n)&&(i!==null&&(a=i(a)),a!==null&&(e===null||e(a))&&n.add(a))}return n}OP(t,i,e,s,n,o,r){if(this.Kl===!1)return n;const l=this.Ct.r,h=l.length;for(let c=h;c--;){const a=l[c];if(r===!0&&a.Nl()===!1||!o(a)||!a.isVisible())continue;let f=a;a.Tm(t,i,e,s,n)&&(i!==null&&(f=i(f)),f!==null&&(e===null||e(f))&&n.add(f))}return n}findObjectsNear(t,i,e,s,n,o){if(e===void 0&&(e=null),s===void 0&&(s=null),n===void 0&&(n=!0),n!==!1&&n!==!0&&((n instanceof List||n instanceof GSet)&&(o=n),n=!0),!(o instanceof List)&&!(o instanceof GSet)&&(o=new GSet),this.Kl===!1)return o;let r=!1;this.diagram!==null&&this.diagram.viewportBounds.containsPoint(t)&&(r=!0);const l=Point.l(),h=Point.l(),c=this.Ct.r,a=c.length;for(let f=a;f--;){const u=c[f];if(r===!0&&u.Nl()===!1||!u.isVisible())continue;l.a(t),l.Oe(u.Us),h.i(t.x+i,t.y),h.Oe(u.Us);let d=u;u.PL(l,h,e,s,n,o)&&(e!==null&&(d=e(d)),d!==null&&(s===null||s(d))&&o.add(d))}return Point.e(l),Point.e(h),o}qS(){return this.Ct.r}ps(t,i){if(!this.visible)return;const e=this.Ct.r,s=e.length;if(s===0)return;const n=U.et(),o=U.et();for(let r=0;r0&&o.push(l))}for(let r=0;re.Fm||c.height*n>e.Fm?i.Ui(t,e):this.HF(t,i,e),a&&(t.restore(),t.clearContextCache(!0))}HF(t,i,e){if(t instanceof SVGContext){i.Ui(t,e);return}const s=i.actualBounds,n=i.naturalBounds;if(s.width===0||s.height===0||isNaN(s.x)||isNaN(s.y)||!i.isVisible())return;const o=i.T;if(i.background===null){i.rn(t,"rgba(0,0,0,0.3)",!0,!1,n,s),t.fillRect(s.x,s.y,s.width,s.height);return}if(t.transform(o.m11,o.m12,o.m21,o.m22,o.dx,o.dy),i.rn(t,i.background,!0,!1,n,s),t.fillRect(0,0,n.width/2,n.height/2),!o.Yk()){const r=1/(o.m11*o.m22-o.m12*o.m21);t.transform(o.m22*r,-o.m12*r,-o.m21*r,o.m11*r,r*(o.m21*o.dy-o.m22*o.dx),r*(o.m12*o.dx-o.m11*o.dy))}}jF(t,i,e,s){const n=2/s,o=4/s;for(let r=0;r=s.count)t=s.count;else if(s.elt(t)===i)return-1;s.insertAt(t,i),i.Rm(e);const n=this.diagram;return n!==null&&(e?n.S():n.Jh(i)),this.Px(t,i),t}te(t,i,e){if(!e&&i.layer!==this&&i.layer!==null)return i.layer.te(t,i,e);const s=this.Ct;if(t<0||t>=s.length){if(t=s.indexOf(i),t<0)return-1}else if(s.elt(t)!==i&&(t=s.indexOf(i),t<0))return-1;i.vm(e),s.removeAt(t);const n=this.diagram;return n!==null&&(e?n.S():n.te(i)),i.HS(null),t}Px(t,i){t=this.qF(t,i),i instanceof Group&&this.WF(t,i),i.svg!==null&&i.svg.remove()}qF(t,i){const e=i.zOrder;if(isNaN(e))return t;const s=this.Ct,n=s.count;if(n<=1)return t;if(t<0&&(t=s.indexOf(i)),t<0)return-1;let o=t-1,r=NaN;for(;o>=0&&(r=s.elt(o).zOrder,!!isNaN(r));)o--;let l=t+1,h=NaN;for(;le)for(;;){if(o===-1||r<=e)return o++,o===t?t:(s.removeAt(t),s.insertAt(o,i),o);for(r=NaN;--o>=0&&(r=s.elt(o).zOrder,!!isNaN(r)););}else if(!isNaN(h)&&h=e)return l--,l===t?t:(s.removeAt(t),s.insertAt(l,i),l);for(h=NaN;++l=0)||e<0&&r.containingGroup===i&&(e=o,t>=0))break}if(!(e<0)&&e1)&&U.W(t,"0 <= value <= 1",Layer,"opacity"),this.$t=t;const e=this.diagram;e!==null&&e.S(),this.t("opacity",i,t)}}get isViewportAligned(){return this.Am}set isViewportAligned(t){const i=this.Am;i!==t&&(this.Am=t,this.diagram&&(this.ML(),this.diagram.S()),this.t("isViewportAligned",i,t),t&&(this.isInDocumentBounds=!1))}ML(){if(!this.Am)return;const t=this.diagram,i=this.Ct.r,e=i.length,s=t.xt,n=t.bt;for(let o=0;o(y[y.None=1]="None",y[y.Uniform=2]="Uniform",y[y.UniformToFill=3]="UniformToFill",y))(AutoScale||{}),CycleMode=(y=>(y[y.All=1]="All",y[y.NotDirected=2]="NotDirected",y[y.NotDirectedFast=3]="NotDirectedFast",y[y.NotUndirected=4]="NotUndirected",y[y.DestinationTree=5]="DestinationTree",y[y.SourceTree=6]="SourceTree",y))(CycleMode||{}),ScrollMode=(y=>(y[y.Document=1]="Document",y[y.Infinite=2]="Infinite",y))(ScrollMode||{}),CollapsePolicy=(y=>(y[y.TreeParent=1]="TreeParent",y[y.AllParents=2]="AllParents",y[y.AnyParents=3]="AnyParents",y))(CollapsePolicy||{});class Diagram{ds;Wt;$S;Sx;Pr;Tu;Mx;Nx;Cx;Lx;Ax;Tx;$h;qh;Dx;Fx;Rx;jl;Fc;Sr;Om;vx;Ox;Du;Yn;Mr;Zh;Co;Im;Rc;Em;vc;Fu;Nr;Gn;ZS;QS;Ix;Ex;_S;Ux;tM;iM;eM;Bx;Um;Cr;Lr;Ar;Tr;Dr;Fr;Vx;Rr;zx;vr;Or;Ir;Er;Xx;sM;Lo;nM;Yx;Gx;oM;ki;rM;lM;hM;Os;Ao;Oi;Kx;Rl;vl;jx;Hx;Ol;Il;El;qx;Ul;Bl;Vl;zl;Xl;Yl;Gl;Wx;Jx;aM;Ru;vu;$x;Zx;Qx;_x;Bm;tb;ib;eb;Zt;cM;sb;fM;Ou;ln;Kn;ie;jn;NL;Hl;uM;dM;Vm;nb;Iu;zm;ob;Ur;ql;Qh;gM;mM;Xm;rb;lb;Ze;Eu;Ym;Uu;Wl;Oc;Gm;Br;_h;pM;Km;Ht;T;Ue;xr;Bi;ys;yM;Jl;Vr;bl;zr;ta;Ic;wM;Bu;ia;Vu;Xt;$l;at;tt;zu;xt;bt;ft;Ec;Bw;hb;ea;Uc;ab;cb;fb;ZF;QF;Vi;Pl;Fm;jm;xM;bM;CL;Hm;_F;tR;iR;ub;eR;sR;nR;sa;LL;Zl;na;oa;ra;la;mu;jh;Qt;Mt;Bc;eP;sP;gc;$t;static db=null;static AL=new GMap;static kM;static PM=null;gu;gb;pb;yb;wb;xb;qm;SM;Wm;Jm;$m;nx;MM;NM;Vc;constructor(t,i){if(Diagram.mw||(Diagram.Gk(),Diagram.mw=!0),GSet.Ki(this),Diagram.TL(this),this.Ht=!0,this.Mt=null,this.xt=0,this.bt=0,this.ft=null,Diagram.isUsingDOM()){const s=this,n=()=>{s.Pi(root.document,"DOMContentLoaded",n,!1),s.setRTL()};root.document.body!==null?this.setRTL():s.Ut(root.document,"DOMContentLoaded",n,!1)}this.Ec=null,Diagram.CM("Model",PartManager);const e=this;return this.rM=s=>e.partManager.doModelDataChanged(s),this.lM=s=>e.partManager.doModelChanged(s),this.ab=null,this.cb=null,this.DL(),this.model=Model.LM(),this.themeManager=new ThemeManager,this.Lo=!0,this.FL(),this.layout=new Layout,this.Lo=!1,this._F=null,this.tR=null,this.iR=null,this.ub=null,this.eR=null,this.sR=null,this.nR=null,this.sa=null,this.LL=null,this.Zl=null,this.na=null,this.oa=null,this.ra=null,this.la=null,this.mu=()=>{},this.jh=null,this.Uu=!1,this.Bc=new DiagramHelper(this),t!==void 0&&(typeof t=="string"||root.Element&&t instanceof Element?this.AM(t):i=t),i&&this.setProperties(i),this.Ht=!1,this.requestUpdate(),this}mF(){return this.ft!==null}get renderer(){return this.Oc}set renderer(t){if(this instanceof Overview)return;t===""&&(t="default");const i=t.toLowerCase(),e=this.Oc;if(i===e)return;this.Oc=i;let s=null;i==="default"||i==="canvas"?(s=this.Wl.get("svg"),s!==null&&s.Tt.remove(),this.ft&&(this.Qt=this.ft.li),this.Qt.clearContextCache(!0)):i==="svg"?(this.Wl.has("svg")?s=this.Wl.get("svg"):(s=new SVGSurface(this,root.document),this.addRenderer("svg",s)),this.div!==null&&this.div.appendChild(s.Tt),this.Qt=s.li,this.ft&&(this.ft.li.setTransform(this.Vi,0,0,this.Vi,0,0),this.ft.li.clearRect(0,0,this.xt,this.bt))):i==="debug"&&(this.Wl.has("SVG")||(s=new SVGSurface(this,root.document),this.addRenderer("SVG",s),s.Tt.style.backgroundColor="whitesmoke",this.div!==null&&this.div.after(s.Tt))),this.Ht||this.redraw()}DL(){this.Vc=new List,this.setupRouters(),this.ds=new AnimationManager,this.ds.Mo(this),this.Wt=17,this.$S=!1,this.zu=!1,this.Sx="default",this.Xt=new List,this.Wl=new GMap,this.Oc="default",this.resetRenderingHints(),this.oR(),this.$t=1,this.at=new Point(NaN,NaN).u(),this.nx=new Point(NaN,NaN),this.tt=1,this.Km=1,this.Mx=new Point(NaN,NaN).u(),this.Nx=NaN,this.Cx=1e-4,this.Lx=100,this.T=new Transform,this.Ax=new Point(NaN,NaN).u(),this.Tx=new Rect(NaN,NaN,NaN,NaN).u(),this.$h=new Margin(0,0,0,0).u(),this.qh=1,this.Dx=!1,this.Fx=null,this.Rx=null,this.jl=1,this.Fc=Spot.Default,this.Sr=1,this.Om=Spot.Default,this.vx=Spot.None,this.Ox=Spot.None,this.Ue=!0,this.Du=!1,this.Yn=new Set,this.Mr=new GSet,this.Zh=new GSet,this.Co=!1,this.$l=new GMap,this.Bu=!0,this.Im=250,this.Rc=-1,this.Em=new Margin(16,16,16,16).u(),this.xr=!1,this.vc=!1,this.Fu=!0,this.Gm=new InputEvent,this.Gm.diagram=this,this.Br=new InputEvent,this.Br.diagram=this,this._h=new InputEvent,this._h.diagram=this,this.Nr=null,this.Gn=null,this.Bw=!1,this.rR(),this.zr=new GSet,this.Ix=!0,this.Ex=1,this._S=!1,this.Ux=1,this.Bx="auto",this.Um="auto",this.Cr=null,this.Lr=null,this.Ar=null,this.Tr=null,this.Dr=null,this.Fr=null,this.Vx=null,this.Rr=null,this.zx=!1,this.vr=null,this.Or=null,this.Ir=null,this.Er=null,this.Xx=!1,this.hb={},this.ea=[null,null],this.Lo=!1,this.nM=!1,this.Yx=!1,this.Gx=!1,this.oM=!0,this.ys=!1,this.ia=!1,this.hM=!0,this.Os=-2,this.Jl=new GMap,this.Vu=new List,this.Ao=!1,this.Oi=!0,this.Kx=!0,this.Rl=!0,this.vl=!0,this.jx=!1,this.Hx=!0,this.Ol=!0,this.Il=!0,this.El=!0,this.qx=!0,this.Ul=!0,this.Bl=!0,this.Vl=!0,this.zl=!0,this.Xl=!0,this.Yl=!0,this.Gl=!0,this.Wx=!0,this.Jx=!0,this.aM=!1,this.Uc=!1,this.Ru=!0,this.vu=!0,this.$x=!0,this.Zx=!0,this.Qx=16,this._x=16,this.Bm=!1,this.tb=!1,this.ib=0,this.eb=0,this.Zt=new Margin(5).u(),this.cM=new GSet().u(),this.sb=999999999,this.fM=new GSet().u(),this.ta=!0,this.Ou=!0,this.Ic=!0,this.ln=!1,this.Kn=!1,this.Vr=!0,this.bl=!1,this.jn=!1,this.NL=new GSet,this.wM=new GSet,this.Hl=null,this.uM=new Size(8,8),this.dM=999,this.Vm=!1,this.eP=1,this.sP=0,this.Bi={scale:1,position:new Point,bounds:new Rect,canvasSize:new Size,newCanvasSize:new Size,isScroll:!1},this.Bi.canvasSize=this.Bi.canvasSize,this.Bi.newCanvasSize=this.Bi.newCanvasSize,this.Bi.isScroll=!1,this.nb=new Rect(NaN,NaN,NaN,NaN).u(),this.Iu=new Size(NaN,NaN).u(),this.zm=new Rect(NaN,NaN,NaN,NaN).u(),this.ob=!1,this.lR(),this.Ze=null,this.Eu=!1,this.gc=null,this.partManager=new PartManager,this.toolManager=new ToolManager,this.toolManager.initializeStandardTools(),this.defaultTool=this.toolManager,this.currentTool=this.defaultTool,this.pb=null,this.yb=new DraggingOptions,this.wb=null,this.xb=null,this.gb=!1,this.gu=!1,this.commandHandler=new CommandHandler,this.Jm=null,this.$m=Point.Ik,this.MM=!1,this.Vi=1,this.Pl=null,this.Fm=1,this.qm=0,this.SM=[0,0,0,0,0],this.Wm=0,this.jm=1,this.xM=0,this.bM=new Point,this.CL=500,this.Ym=new Point,this.Hm=!1}static RL=root.document!==void 0;static isUsingDOM(){return Diagram.RL}static useDOM(t){Diagram.RL=t?root.document!==void 0:!1}static Qe=new WeakMap;clear(){this.animationManager.stopAnimation(),this.model.clear(),Diagram.vL(),this.OL(!1),this.Vu.clear(),this.IL(),this.Hl=null,this.invalidateDocumentBounds(),this.ensureBounds(),this.S()}OL(t){this.animationManager.stopAnimation(!0),this.cM=new GSet().u(),this.fM=new GSet().u();const i=this.skipsUndoManager,e=this.ki!==null&&this.ki!==void 0;e&&(this.skipsUndoManager=!0);let s=null;this.Ze!==null&&(s=this.Ze.part,s!==null&&this.remove(s));const n=[],o=this.Xt.length;if(t){for(let r=0;rt?new Margin(t/2):1.5)),this.rb=this.Xm,this.lb=new Adornment(Panel.Link).add(new Shape({isPanelMain:!0,fill:null,stroke:"dodgerblue",strokeWidth:3}).theme("stroke","selection").theme("strokeWidth","selection"))}setRTL(t){let i=t===void 0?this.div:t;i===null&&(i=root.document.body);const e=U.hs("div");e.dir="rtl",e.style.cssText="font-size: 14px; width: 1px; height: 1px; position: absolute; top: -1000px; overflow: scroll;",e.textContent="A",i.appendChild(e);let s="reverse";e.scrollLeft>0?s="default":(e.scrollLeft=1,e.scrollLeft===0&&(s="negative")),i.removeChild(e),this.Sx=s}setScrollWidth(t){let i=t===void 0?this.div:t;i===null&&(i=root.document.body);let e=0;if(Diagram.isUsingDOM()){let s=Diagram.PM,n=Diagram.kM;s===null&&(Diagram.PM=U.hs("p"),s=Diagram.PM,s.style.width="100%",s.style.height="200px",s.style.boxSizing="content-box",Diagram.kM=U.hs("div"),n=Diagram.kM,n.style.position="absolute",n.style.visibility="hidden",n.style.width="200px",n.style.height="150px",n.style.boxSizing="content-box",n.appendChild(s)),n.style.overflow="hidden",i.appendChild(n);const o=s.offsetWidth;n.style.overflow="scroll";let r=s.offsetWidth;o===r&&(r=n.clientWidth),i.removeChild(n),e=o-r,e===0&&!U.tr&&(e=11)}this.Wt=e,this.$S=!0}oi(t){t in AutoScale?this.autoScale=t:U.er(this,t)}toString(t){t===void 0&&(t=0);let i="";this.div&&this.div.id&&(i=this.div.id);let e='Diagram "'+i+'"';if(t<=0)return e;const s=this.Xt.iterator;for(;s.next();){const n=s.value;e+=` `+n.toString(t-1)}return e}static TL(t){Diagram.db=t}static um(){return Diagram.db}static fromDiv(t){let i=t;if(typeof t=="string"&&(i=root.document.getElementById(t)),i instanceof HTMLDivElement){const e=Diagram.Qe.get(i);if(e)return e}return null}get div(){return this.Mt}set div(t){if(this.Mt!==t){const i=this.Mt;if(i!==null){if(Diagram.Qe.delete(i),i.goDiagram=void 0,i.go=void 0,i.innerHTML="",this.ft!==null){const s=this.ft.Tt;this.Pi(s,"pointermove",this.na,!1),this.Pi(s,"pointerdown",this.Zl,!1),this.Pi(s,"pointerup",this.oa,!1),this.Pi(s,"pointerout",this.ra,!1),this.Pi(s,"pointercancel",this.la,!1),this.ft.dispose()}this.Ec&&(this.Ec.disconnect(),this.Ec=null);const e=this.toolManager;e!==null&&(e.mouseDownTools.each(s=>s.cancelWaitAfter()),e.mouseMoveTools.each(s=>s.cancelWaitAfter()),e.mouseUpTools.each(s=>s.cancelWaitAfter())),e.cancelWaitAfter(),this.currentTool.doCancel(),this.ft=null,this.Pi(root,"resize",this.ub,!1),this.Pi(root,"wheel",this.sa,!0),Diagram.um()===this&&Diagram.TL(null)}else this.Zl===null&&(this.jn=!1);if(this.Mt=null,t!==null){const e=Diagram.Qe.get(t);e&&(e.div=null),this.AM(t),this.mu(),this.themeManager&&this.themeManager.hR()}else this.themeManager&&this.themeManager.aR()}}setupRouters(){this.Vc.push(new AvoidsNodesRouter)}AM(t){const i=this;if(!Diagram.isUsingDOM())return;t==null&&U.o("Diagram setup requires an argument DIV."),i.Mt!==null&&U.o("Diagram has already completed setup."),typeof t=="string"?i.Mt=root.document.getElementById(t):t instanceof HTMLDivElement?i.Mt=t:U.o("No DIV or DIV id supplied: "+t),i.Mt===null&&U.o("Invalid DIV id; could not get element with id: "+t);const e=Diagram.Qe.get(i.Mt);if(e&&e!==this&&U.o("Invalid div id; div already has a Diagram associated with it."),!i.Ec&&root.ResizeObserver){const a=root.ResizeObserver,f=U.Rk(()=>i.requestUpdate(),250,!1);i.Ec=new a(()=>f()),i.Ec.observe(i.Mt)}root.getComputedStyle(i.Mt,null).position==="static"&&(i.Mt.style.position="relative");let s=5;const n="rgba(2"+s+"5, 255, 255, 0)";s--,i.Mt.style["-webkit-tap-highlight-color"]=n,i.Mt.innerHTML="",Diagram.Qe.set(i.Mt,i),i.Mt.goDiagram=i,i.Mt.go=root.go;const o=new CanvasSurface(i);o.style!==void 0&&(o.style.position="absolute",o.style.top="0px",o.style.left="0px",root.getComputedStyle(i.Mt,null).getPropertyValue("direction")==="rtl"&&(i.zu=!0),o.style.zIndex="2",o.style.userSelect="none",o.style.MozUserSelect="none",o.style.touchAction="none",o.style.letterSpacing="normal !important",o.style.wordSpacing="normal !important",o.style.lang="unknown"),i.ft=o,i.Qt=o.li;const r=i.Qt;i.Vi=i.computePixelRatio(),i.viewSize.isReal()||(i.xt=i.Mt.clientWidth||1,i.bt=i.Mt.clientHeight||1),i.EL(i.xt,i.bt);const l=i;i.Mt.insertBefore(o.Tt,i.Mt.firstChild);const h=new CanvasSurface(null);if(h.width=1,h.height=1,i.ZF=h,i.QF=h.li,Diagram.isUsingDOM()){const a=U.hs("div"),f=U.hs("div");a.style.position="absolute",a.style.overflow="auto",a.style.width=i.xt+"px",a.style.height=i.bt+"px",a.style.zIndex="1",f.style.position="absolute",f.style.width="1px",f.style.height="1px",i.Mt.appendChild(a),a.appendChild(f),a.onscroll=Diagram.cR,a.addEventListener("pointerdown",Diagram.fR),a.N=i,a.uR=!0,a.dR=!0,i.ab=a,i.cb=f}i.mu=U.Rk(()=>{i.Pl=null,i.S()},300,!1),i.ub=U.Rk(()=>{i.IS()},250,!1),i.jh=a=>(a.preventDefault(),!1),i.sa=a=>{if(!l.isEnabled)return;const f=l.zc(a,!0);f.bubbles=!0;let u=0,d=0;f.delta=0,a.deltaX!==void 0?(a.deltaX!==0&&(u=a.deltaX>0?1:-1),a.deltaY!==0&&(d=a.deltaY>0?1:-1),f.delta=Math.abs(a.deltaX)>Math.abs(a.deltaY)?-u:-d):a.wheelDeltaX!==void 0?(a.wheelDeltaX!==0&&(u=a.wheelDeltaX>0?-1:1),a.wheelDeltaY!==0&&(d=a.wheelDeltaY>0?-1:1),f.delta=Math.abs(a.wheelDeltaX)>Math.abs(a.wheelDeltaY)?-u:-d):a.wheelDelta!==void 0&&a.wheelDelta!==0&&(f.delta=a.wheelDelta>0?1:-1),l.doMouseWheel(),l.ha(f,a)},i.LL=a=>{if(!l.isEnabled)return;i.Uc=!1,l.zc(a,!0);const f=l.currentTool;f.cancelWaitAfter(),f.standardMouseOver()},i.Zl=a=>{if(!l.isEnabled)return;i.Uc=!0;const f=l.hb;f[a.pointerId]===void 0&&(f[a.pointerId]=a);const u=l.ea;let d=!1;if(u[0]!==null&&(u[0].pointerId===a.pointerId||u[0].pointerType!==a.pointerType))u[0]=a;else if(u[1]!==null&&u[1].pointerId===a.pointerId)u[1]=a,d=!0;else if(u[0]===null)u[0]=a;else if(u[1]===null)u[1]=a,d=!0;else{a.preventDefault();return}const m=a.pointerType==="touch"||a.pointerType==="pen";m&&(l.Bw=!1,l.Hm=!0);const g=l.gR(a,a,d),p=l.bM,w=m?25:10;if(a.timeStamp-l.xMw||Math.abs(p.y-a.screenY)>w)?l.jm++:l.jm=1,g.clickCount=l.jm,l.xM=a.timeStamp,l.bM.setTo(a.screenX,a.screenY),l.doMouseDown(),a.button===1){a.preventDefault();return}l.ha(g,a)},i.na=a=>{if(!l.isEnabled)return;i.Uc=!0;const f=l.ea;if(f[0]!==null&&(f[0].pointerId===a.pointerId||f[0].pointerType!==a.pointerType))f[0]=a;else if(f[1]!==null&&f[1].pointerId===a.pointerId){f[1]=a;return}else if(f[0]===null)f[0]=a;else return;if(f[0].pointerId!==a.pointerId)return;const u=l.mR(a,a,f[1]!==null);l.doMouseMove(),l.ha(u,a)},i.oa=a=>{if(!l.isEnabled)return;i.Uc=!0;const f=a.pointerType==="touch"||a.pointerType==="pen",u=l.hb;if(f&&l.Bw){delete u[a.pointerId],a.preventDefault();return}const d=l.ea;if(d[0]!==null&&(d[0].pointerId===a.pointerId||d[0].pointerType!==a.pointerType))d[0]=null;else if(d[1]!==null&&d[1].pointerId===a.pointerId){d[1]=null;return}else return;const m=l.TM(a,!1,!0,!1,!0,!1);let g=root.document.elementFromPoint(a.clientX,a.clientY)||null;g!==null&&g.shadowRoot!==void 0&&g.shadowRoot!==null&&(g=g.shadowRoot.elementFromPoint(a.clientX,a.clientY)),g!==null&&g.N instanceof Diagram&&g.N!==l&&g.N.Qm(a,m),g===null&&(g=a.target),l.Qm(a,m),m.clickCount=l.jm,m.targetDiagram=l.kb(a,g),m.targetObject=null,l.doMouseUp(),l.ha(m,a),f&&(l.Hm=!1)},i.ra=a=>{if(!l.isEnabled)return;i.Uc=!1;const f=l.hb;f[a.pointerId]&&delete f[a.pointerId];const u=l.ea;if(u[0]!==null&&u[0].pointerId===a.pointerId&&(u[0]=null),u[1]!==null&&u[1].pointerId===a.pointerId&&(u[1]=null),a.pointerType==="touch"||a.pointerType==="pen")return;const d=l.currentTool;d.cancelWaitAfter(),d.standardMouseOver()},i.la=a=>{const f=l.ea;f[0]!==null&&f[0].pointerId===a.pointerId?(f[0]=null,l.Hm=!1):f[1]!==null&&f[1].pointerId===a.pointerId&&(f[1]=null)};const c=r;if(i.fb=c.E[U.Ts("7eba17a4ca3b1a8346")][U.Ts("78a118b7")](c.E,Diagram.Xu,s,s),r.clearContextCache(!0),i.pR(),this.Oc==="svg"){const a=this.Wl.get("svg");this.Mt&&this.Mt.appendChild(a.Tt),this.Qt=a.li}}addEventListener(t,i,e,s){t.addEventListener(i,e,{capture:s,passive:!1})}Ut(t,i,e,s){t.addEventListener(i,e,{capture:s,passive:!1})}removeEventListener(t,i,e,s){t.removeEventListener(i,e,{capture:s})}Pi(t,i,e,s){t.removeEventListener(i,e,{capture:s})}pR(){const t=this;let i=this.ft.Tt;i instanceof HTMLCanvasElement||(i=t.div),this.Ut(i,"pointerdown",t.Zl,!1),this.Ut(i,"pointermove",t.na,!1),this.Ut(i,"pointerup",t.oa,!1),this.Ut(i,"pointerout",t.ra,!1),this.Ut(i,"pointercancel",t.la,!1),this.Ut(i,"pointerenter",t.yR,!1),this.Ut(i,"pointerleave",t.wR,!1),this.Ut(i,"wheel",t.sa,!1),this.Ut(i,"keydown",t.xR,!1),this.Ut(i,"keyup",t.bR,!1),this.Ut(i,"blur",t.kR,!1),this.Ut(i,"focus",t.PR,!1),this.Ut(i,"selectstart",e=>(e.preventDefault(),!1),!1),this.Ut(i,"contextmenu",e=>(e.preventDefault(),!1),!1),this.Ut(root,"resize",t.ub,!1)}Vw(){this.qm>30&&(this.Pl=1)}CP(t){this.Pl!==null&&(this.Pl=null,t&&this.mu(),this.qm=0,this.SM=[0,0,0,0,0],this.Wm=0)}computePixelRatio(){return this.Pl!==null?this.Pl:root.devicePixelRatio||1}get avgSpf(){return this.qm}doMouseDown(){this.currentTool.doMouseDown()}doMouseMove(){this.currentTool.doMouseMove()}doMouseUp(){this.currentTool.doMouseUp()}doMouseWheel(){this.currentTool.doMouseWheel()}doKeyDown(){this.currentTool.doKeyDown()}doKeyUp(){this.currentTool.doKeyUp()}doFocus(){this.focus()}focus(){if(this.ft)if(this.scrollsPageOnFocus)this.ft.focus();else{const t=root.scrollX,i=root.scrollY;this.ft.focus(),root.scrollTo(t,i)}}PR(t){const i=Diagram.Qe.get(this);i&&i.D("GainedFocus")}kR(t){const i=Diagram.Qe.get(this);i&&i.D("LostFocus")}IS(){if(this.ft===null)return;const i=this.Mt;if(i===null||i.clientWidth===0||i.clientHeight===0)return;this.$S||this.setScrollWidth();const e=this.Kn?this.Wt:0,s=this.ln?this.Wt:0,n=this.Vi;if(this.Vi=this.computePixelRatio(),this.Vi!==n&&(this.Du=!0,this.requestUpdate()),i.clientWidth!==this.xt+e||i.clientHeight!==this.bt+s){this.aa(),this.Ue=!0;const o=this.layout;o!==null&&o.isViewportSized&&this.autoScale===1&&(this.vc=!0,o.invalidateLayout()),this.ys||this.requestUpdate()}}FL(){let t=0,i=new Layer;i.name="Grid",i.allowSelect=!1,i.pickable=!1,i.isTemporary=!0,i.isInDocumentBounds=!1,this.Xr(i,t++),i=new Layer,i.name="ViewportBackground",i.isViewportAligned=!0,i.isTemporary=!0,i.isInDocumentBounds=!1,this.Xr(i,t++),i=new Layer,i.name="Background",this.Xr(i,t++),i=new Layer,i.name="",this.Xr(i,t++),i=new Layer,i.name="Foreground",this.Xr(i,t++),i=new Layer,i.name="ViewportForeground",i.isViewportAligned=!0,i.isTemporary=!0,i.isInDocumentBounds=!1,this.Xr(i,t++),i=new Layer,i.name="Adornment",i.isTemporary=!0,i.isInDocumentBounds=!1,this.Xr(i,t++),i=new Layer,i.name="Tool",i.isTemporary=!0,i.isInDocumentBounds=!0,this.Xr(i,t++)}UL(){const t=new Panel(Panel.Grid,{name:"GRID"}).add(new Shape("LineH",{stroke:"lightgray",strokeWidth:.5,interval:1}).theme("stroke","gridMinor"),new Shape("LineV",{stroke:"lightgray",strokeWidth:.5,interval:1}).theme("stroke","gridMinor"),new Shape("LineH",{stroke:"gray",strokeWidth:.5,interval:5}).theme("stroke","gridMajor"),new Shape("LineV",{stroke:"gray",strokeWidth:.5,interval:5}).theme("stroke","gridMajor"),new Shape("LineH",{stroke:"gray",strokeWidth:1,interval:10}).theme("stroke","gridMajor"),new Shape("LineV",{stroke:"gray",strokeWidth:1,interval:10}).theme("stroke","gridMajor")),i=new Part({layerName:"Grid",zOrder:0,isInDocumentBounds:!1,isAnimated:!1,pickable:!1,locationObjectName:"GRID"}).add(t);return this.add(i),this.partManager.parts.delete(i),t.visible=!1,t}static cR(){const t=Diagram.Qe.get(this.parentElement||this);if(t){if(t.tb){t.tb=!1;return}if(!t.isEnabled){t.BL();return}t.diagramScroll(this)}}static fR(t){if(!this.N.isEnabled){this.N.updateScroll();return}this.N.ib=t.target.scrollTop,this.N.eb=t.target.scrollLeft}diagramScroll(t){if(this.ft===null)return;const i=this.ab,e=this.cb;this.Bm=!0;let s=this.documentBounds,n=this.viewportBounds;const o=this.$h;let r=s.x-o.left,l=s.y-o.top;const h=s.width+o.left+o.right,c=s.height+o.top+o.bottom;let a=s.right+o.right,f=s.bottom+o.bottom,u=n.x,d=n.y;const m=n.width,g=n.height;let p=n.right,w=n.bottom;const x=this.scale;let k,b=t.scrollLeft;if(this.zu)switch(this.Sx){case"negative":b=b+t.scrollWidth-t.clientWidth;break;case"reverse":b=t.scrollWidth-b-t.clientWidth;break}const P=b;if(mp)){const S=i.scrollWidth-this.xt;this.position=k.i(-S+P-this.xt/x+a,this.position.y)}if(t.dR&&this.allowVerticalScroll&&(lw)){const S=i.scrollHeight-this.bt;this.position=k.i(this.position.x,-S+t.scrollTop-this.bt/x+f)}Point.e(k),this._l(),this.Bm=!1,this.Ou=!1,s=this.documentBounds,n=this.viewportBounds,a=s.right,p=n.right,f=s.bottom,w=n.bottom,r=s.x,u=n.x,l=s.y,d=n.y,m>=h&&r>=u&&a<=p&&(e.style.width="1px"),g>=c&&l>=d&&f<=w&&(e.style.height="1px")}computeBounds(t){return t===void 0&&(t=new Rect),this.Mi(),this.VL(t)}VL(t){if(this.fixedBounds.isReal())return t.a(this.fixedBounds),t.addMargin(this.Zt),t;let i=!0;const e=this.Xt.r,s=e.length;for(let n=0;nl?h=(r-this.Wt)/n:l=(o-this.Wt)/s);let u=0;return t===2?u=Math.min(h,l):t===3&&(h>l?u=(r-this.Wt)/n:u=(o-this.Wt)/s),u>i&&(u=i),uthis.maxScale&&(u=this.maxScale),u}zoomToFit(){const t=this.qh;this.qh=1,this.scale=this.Yu(2),this.alignDocument(Spot.Center,Spot.Center),t!==1&&(this.Bs(!1),this.DM(this.documentBounds,this.xt/this.tt,this.bt/this.tt,this.Fc,!1)),this.qh=t}zoomToRect(t,i){i===void 0&&(i=2);const e=t.width,s=t.height;if(e===0||s===0||isNaN(e)&&isNaN(s))return;let n=1;if(i===2||i===3)if(isNaN(e))n=this.viewportBounds.height*this.scale/s;else if(isNaN(s))n=this.viewportBounds.width*this.scale/e;else{const o=this.xt,r=this.bt;i===3?r/s>o/e?n=(r-(this.ln?this.Wt:0))/s:n=(o-(this.Kn?this.Wt:0))/e:n=Math.min(r/s,o/e)}this.scale=n,this.position=new Point(t.x,t.y)}get SR(){return this.Ht}set SR(t){this.Ht=t}alignDocument(t,i){this.ensureBounds();const e=this.documentBounds,s=this.viewportBounds;this.position=new Point(e.x+(t.x*e.width+t.offsetX)-(i.x*s.width-i.offsetX),e.y+(t.y*e.height+t.offsetY)-(i.y*s.height-i.offsetY))}focusObject(t){if(t instanceof GraphObject){this.Jm=t;const i=Point.l();this.$m=this.transformDocToView(t.getDocumentPoint(Spot.TopLeft,i)),Point.e(i)}else this.Jm=null,this.$m=Point.Ik}DM(t,i,e,s,n){const o=Point.V(this.at.x,this.at.y);let r=o.x,l=o.y;if(this.Jm!==null){let h=Point.l();h=this.Jm.getDocumentPoint(Spot.TopLeft,h),r=h.x-this.$m.x/this.scale,l=h.y-this.$m.y/this.scale,s=Spot.None,Point.e(h)}if(n||this.scrollMode===1){s.isSpot()&&(i>t.width&&(r=t.x+(s.x*t.width+s.offsetX)-(s.x*i-s.offsetX)),e>t.height&&(l=t.y+(s.y*t.height+s.offsetY)-(s.y*e-s.offsetY)));const h=this.$h,c=i-t.width;if(it.left?r=t.left:rt.top?l=t.top:ls.part,s=>s.canSelect());if(e instanceof Part)return e}else{const e=this.FP(t,s=>s.part);if(e instanceof Part)return e}return null}findObjectAt(t,i,e){i===void 0&&(i=null),e===void 0&&(e=null),this.Mi();const s=this.Xt.iteratorBackwards;for(;s.next();){const n=s.value;if(!n.visible)continue;const o=n.findObjectAt(t,i,e);if(o!==null)return o}return null}FP(t,i,e){i===void 0&&(i=null),e===void 0&&(e=null),this.Mi();const s=this.Xt.iteratorBackwards;for(;s.next();){const n=s.value;if(!n.visible||n.isTemporary)continue;const o=n.findObjectAt(t,i,e);if(o!==null)return o}return null}findPartsAt(t,i,e){return i===void 0&&(i=!0),this.NR(t,s=>s.part,i?s=>s instanceof Part&&s.canSelect():null,e)}NR(t,i,e,s){i===void 0&&(i=null),e===void 0&&(e=null),!(s instanceof List)&&!(s instanceof GSet)&&(s=new GSet),this.Mi();const n=this.Xt.iteratorBackwards;for(;n.next();){const o=n.value;!o.visible||o.isTemporary||o.findObjectsAt(t,i,e,s)}return s}findObjectsAt(t,i,e,s){i===void 0&&(i=null),e===void 0&&(e=null),!(s instanceof List)&&!(s instanceof GSet)&&(s=new GSet),this.Mi();const n=this.Xt.iteratorBackwards;for(;n.next();){const o=n.value;o.visible&&o.findObjectsAt(t,i,e,s)}return s}findPartsIn(t,i,e,s){return i===void 0&&(i=!1),e===void 0&&(e=!0),this.CR(t,null,n=>n instanceof Part&&(!e||n.canSelect()),i,s)}findObjectsIn(t,i,e,s,n){i===void 0&&(i=null),e===void 0&&(e=null),s===void 0&&(s=!1),!(n instanceof List)&&!(n instanceof GSet)&&(n=new GSet),this.Mi();const o=this.Xt.iteratorBackwards;for(;o.next();){const r=o.value;r.visible&&r.findObjectsIn(t,i,e,s,n)}return n}OP(t,i,e,s,n,o){const r=new GSet;this.Mi();const l=this.Xt.iteratorBackwards;for(;l.next();){const h=l.value;h.visible&&h.OP(t,i,e,s,r,n,o)}return r}CR(t,i,e,s,n){i===void 0&&(i=null),e===void 0&&(e=null),s===void 0&&(s=!1),!(n instanceof List)&&!(n instanceof GSet)&&(n=new GSet),this.Mi();const o=this.Xt.iteratorBackwards;for(;o.next();){const r=o.value;!r.visible||r.isTemporary||r.findObjectsIn(t,i,e,s,n)}return n}findPartsNear(t,i,e,s,n){return e===void 0&&(e=!0),s===void 0&&(s=!0),this.LR(t,i,null,o=>o instanceof Part&&(!s||o.canSelect()),e,n)}findObjectsNear(t,i,e,s,n,o){e===void 0&&(e=null),s===void 0&&(s=null),n===void 0&&(n=!0),n!==!1&&n!==!0&&((n instanceof List||n instanceof GSet)&&(o=n),n=!0),!(o instanceof List)&&!(o instanceof GSet)&&(o=new GSet),this.Mi();const r=this.Xt.iteratorBackwards;for(;r.next();){const l=r.value;l.visible&&l.findObjectsNear(t,i,e,s,n,o)}return o}LR(t,i,e,s,n,o){e===void 0&&(e=null),s===void 0&&(s=null),n===void 0&&(n=!0),n!==!1&&n!==!0&&((n instanceof List||n instanceof GSet)&&(o=n),n=!0),!(o instanceof List)&&!(o instanceof GSet)&&(o=new GSet),this.Mi();const r=this.Xt.iteratorBackwards;for(;r.next();){const l=r.value;!l.visible||l.isTemporary||l.findObjectsNear(t,i,e,s,n,o)}return o}acceptEvent(t){return this.zc(t,t instanceof MouseEvent)}zc(t,i){const e=this.Br;this.Br=this._h,this._h=e,e.diagram=this,e.event=t,i?this.Qm(t,e):(e.viewPoint=this.Br.viewPoint,e.documentPoint=this.Br.documentPoint);let s=0;const n=t;return n.ctrlKey&&(s+=1),n.altKey&&(s+=2),n.shiftKey&&(s+=4),n.metaKey&&(s+=8),e.modifiers=s,e.button=n.button,n.buttons!==void 0&&(e.buttons=n.buttons),U.tr&&n.button===0&&n.ctrlKey&&(e.button=2),e.down=!1,e.up=!1,e.clickCount=1,e.delta=0,e.handled=!1,e.bubbles=!1,e.timestamp=t.timeStamp,e.isMultiTouch=!1,e.targetDiagram=this.kb(t,t.target),e.targetObject=null,e}kb(t,i){if(i===null)return null;const e=Diagram.Qe.get(i);if(e)return e;let s=t.path;if(!s&&U.it(t.composedPath)&&(s=t.composedPath()),s&&s[0]){const n=Diagram.Qe.get(s[0]);if(n)return n}return null}gR(t,i,e){const s=this.TM(t,!0,!1,!1,!0,e);return this.Qm(i,s),s.targetDiagram=this.kb(t,t.target),s.targetObject=null,e||s.clone(this.Gm),s}mR(t,i,e){const s=this.TM(t,!1,!1,!1,!1,e);let n=root.document.elementFromPoint(i.clientX,i.clientY)||null;n!==null&&n.shadowRoot!==void 0&&n.shadowRoot!==null&&(n=n.shadowRoot.elementFromPoint(i.clientX,i.clientY));let o=this,r=t;if(n){const l=this.kb(t,n);l&&(r=i,o=l)}return s.targetDiagram=o,this.Qm(r,s),s.targetObject=null,s}TM(t,i,e,s,n,o){const r=this.Br;this.Br=this._h,this._h=r,r.diagram=this,r.clickCount=1,r.delta=0;let l=0;return t.ctrlKey&&(l+=1),t.altKey&&(l+=2),t.shiftKey&&(l+=4),t.metaKey&&(l+=8),r.modifiers=l,r.event=t,r.timestamp=t.timeStamp,r.button=e?this.firstInput.button:t.button,r.buttons=t.buttons,U.tr&&t.button===0&&t.ctrlKey&&(r.button=2),r.down=i,r.up=e,r.handled=s,r.bubbles=n,r.isMultiTouch=o,r}ha(t,i){return t.bubbles?!0:(i.stopPropagation!==void 0&&i.stopPropagation(),i.cancelable!==!1&&i.preventDefault(),i.cancelBubble=!0,!1)}xR(t){const i=Diagram.Qe.get(this);if(!i||!i.isEnabled)return!1;const e=i.zc(t,!1);return e.key=t.key,e.code=t.code,e.down=!0,i.doKeyDown(),i.ha(e,t)}bR(t){const i=Diagram.Qe.get(this);if(!i||!i.isEnabled)return!1;const e=i.zc(t,!1);return e.key=t.key,e.code=t.code,e.up=!0,i.doKeyUp(),i.ha(e,t)}yR(t){const i=Diagram.Qe.get(this);if(!i||!i.isEnabled)return!1;const e=i.zc(t,!0);return i.mouseEnter!==null&&i.mouseEnter(e),i.currentTool.standardMouseOver(),i.ha(e,t)}wR(t){const i=Diagram.Qe.get(this);if(!i||!i.isEnabled)return!1;const e=i.zc(t,!0);return i.mouseLeave!==null&&i.mouseLeave(e),i.ha(e,t)}getMouse(t){const i=this.ft;if(i===null)return new Point(0,0);const e=i.getBoundingClientRect(),s=(t.clientX-e.left)*(this.xt/e.width),n=(t.clientY-e.top)*(this.bt/e.height);return new Point(s,n).Oe(this.T)}Qm(t,i){const e=this.ft;let s=0,n=0;if(e!==null){const r=e.getBoundingClientRect();s=(t.clientX-r.left)*(this.xt/r.width),n=(t.clientY-r.top)*(this.bt/r.height)}i.viewPoint.i(s,n);const o=Point.V(s,n);this.T.$e(o),i.documentPoint.a(o),Point.e(o)}BC(t,i,e){let s;if(this.ea[0]!==null)s=this.ea[i];else return;const n=this.ft;if(n!==null){const o=n.getBoundingClientRect();e.i((s.clientX-o.left)*(this.xt/o.width),(s.clientY-o.top)*(this.bt/o.height))}}invalidateDocumentBounds(){this.ta||(this.ta=!0,this.requestUpdate(!1))}AR(){this.ys||this.Mi(),this.ensureBounds()}redraw(){this.Ht||this.ys||(this.S(),this.maybeUpdate())}isUpdateRequested(){return this.xr}delayInitialization(t){t===void 0&&(t=null);const i=this.animationManager,e=i.isEnabled;i.stopAnimation(),i.isEnabled=!1,this.ur(),this.jn=!1,this.nx=new Point(NaN,NaN),i.isEnabled=e,this.ys=!0;const s=this;t!==null&&U.ir(()=>{s.ys=!1,i.Fl("Model"),t(s)},1)}requestUpdate(t){if(t===void 0&&(t=!1),this.xr===!0||this.Ht||t===!1&&this.ys)return;this.xr=!0;const i=this;root.requestAnimationFrame(()=>{i.xr&&i.maybeUpdate()})}maybeUpdate(){this.Fu&&!this.xr||(this.Fu&&(this.Fu=!1),this.ur())}FM(t,i){!this.Ou||this.Ht||this.animationManager.defaultAnimation.isAnimating||this.BL()||(t&&this.Mi(),i&&this.Bs(!1))}ur(t){if(this.ys||(this.xr=!1,this.Mt===null&&!this.Iu.isReal()))return;this.ys=!0;const i=this.animationManager,e=this.Vu;if(!i.isAnimating&&e.length!==0){const a=e.r,f=a.length;for(let u=0;u0&&(s.each(a=>a.RM()),s.clear());let n=!1,o=!1;i.defaultAnimation.isAnimating&&(o=!0,n=this.skipsUndoManager,this.skipsUndoManager=!0),i.pi||this.IS(),t||this.FM(!1,!0);const r=!this.undoManager.isUndoingRedoing&&(this.bl||this.Vc.count!==0&&this.Mr.size!==0),l=!this.jn||this.Vr;this.Mi(!0);let h=!1;(l||r)&&(this.jn?this.vM(!this.vc,r):(this.startTransaction("Initial Layout"),i.isEnabled===!1&&i.stopAnimation(),this.vM(!1,r)),h=l),this.vc=!1,this.bl=!1,this.Mi(),this.Ze!==null&&(this.Ze.visible&&!this.Eu&&(this.th(),this.Eu=!0),!this.Ze.visible&&this.Eu&&(this.Eu=!1)),this.Yx||this.AR(),t||this.FM(!0,!1);let c=!1;if(h){const a=Rect.l();a.a(this.viewportBounds),this.jn||(this.jn=!0,c=!0,this.skipsUndoManager||(this.undoManager.Ew=!0),this.undoManager.Uw=!0,this.TR()),this.DR(),this.Mi(!1),t||this.FM(!0,!0),Rect.e(a)}else if(i.Sc&&i.ex){if(this.Sr!==1)this.scale=this.Yu(this.Sr);else if(this.jl!==1)this.scale=this.Yu(this.jl);else{const a=this.initialScale;isFinite(a)&&a>0&&(this.scale=a)}this.Bs(!0)}h&&c&&this.commitTransaction("Initial Layout"),t||this.Ui(this.Qt),o&&(this.skipsUndoManager=n),this.ys=!1}get Vh(){return this.jn}TR(){if(this.Sr!==1)this.scale=this.Yu(this.Sr);else if(this.jl!==1)this.scale=this.Yu(this.jl);else{const i=this.initialScale;isFinite(i)&&i>0&&(this.scale=i)}this.Bs(!0);const t=this.Xt.r;this.ps(t,t.length,this,this.viewportBounds),this.D("InitialLayoutCompleted"),this.nx.a(this.at),this.th()}DR(){this.D("LayoutCompleted")}t0(t){this.Yn.add(t)}addInvalidRoute(t){this.Co?this.Zh.add(t):this.Mr.add(t)}Mi(t){if(this.Yn.size!==0&&!(!this.ys&&this.animationManager.isTicking)){if(this.ys||(this.bl=!0),t){this.zL(this.Yn);return}for(let i=0;i<23&&this.Yn.size!==0;i++){const e=new Set(this.Yn);this.Yn.clear(),this.RM(e,this.Yn)}this.nodes.each(i=>{i instanceof Group&&i.XL(!1)})}}zL(t,i){for(const e of t)!e.ke()||e instanceof Group||(e.Yr()?(e.ht(1/0,1/0),e.Bt()):i&&i.add(e));for(const e of t)if(e instanceof Group){if(!e.isVisible())continue;this.Pb(e)}}RM(t,i){this.zL(t,i);for(const e of t){if(!(e instanceof Link))continue;const s=e;s.isVisible()&&(s.Yr()?(s.ht(1/0,1/0),s.Bt()):i.add(s))}for(const e of t)e instanceof Adornment&&e.isVisible()&&(e.Yr()?(e.ht(1/0,1/0),e.Bt()):i.add(e))}i0(t){const i=t instanceof Diagram,e=i?t.links:t.memberParts,s=this.Yn;if(i)this.Mi(!0);else{for(;e.next();){const n=e.value;s.has(n)&&(!n.ke()||n instanceof Group||n.Yr()&&(n.ht(1/0,1/0),n.Bt()))}for(e.reset();e.next();){const n=e.value;if(s.has(n)&&n instanceof Group){if(!n.isVisible())continue;this.Pb(n)}}e.reset()}for(;e.next();){const n=e.value;n instanceof Link&&s.has(n)&&n.isVisible()&&n.Yr()&&(n.ht(1/0,1/0),n.Bt())}}Pb(t){const i=U.et(),e=U.et(),s=t.memberParts;for(;s.next();){const o=s.value;o.isVisible()&&(o instanceof Group?(o.To()||o._e()||o.ih())&&this.Pb(o):o instanceof Link?o.fromNode===t||o.toNode===t?e.push(o):i.push(o):(o.ht(1/0,1/0),o.Bt()))}let n=i.length;for(let o=0;ob.Au())}else for(let x=0;x0){const c=n.substring(0,h);e?o=t.findObject(c):(o=t[c],o==null&&(o=t.toolManager[c])),U.G(o)?r=n.substring(h+1):U.o("Unable to find object named: "+c+" in "+t.toString()+" when trying to set property: "+n)}}if(r[0]!=="_"&&!U.gw(o,r))if(s&&r==="ModelChanged"){t.addModelChangedListener(i[r]);continue}else if(s&&r==="Changed"){t.addChangedListener(i[r]);continue}else if(s&&U.gw(t.toolManager,r))o=t.toolManager;else if(s&&t.YL(r)){t.addDiagramListener(r,i[r]);continue}else if(t instanceof Model&&r==="Changed"){t.addChangedListener(i[r]);continue}else U.o('Trying to set undefined property "'+r+'" on object: '+o.toString());const l=i[n];o[r]=l,r[0]==="_"&&o instanceof GraphObject&&o.addCopyProperty(r)}}xL(){if(this.$l.count!==0&&!(this.undoManager.transactionLevel>1)){for(;this.$l.count>0;){const t=this.$l;this.$l=new GMap;const i=t.iterator;for(;i.next();){const e=i.key;e.invalidateOtherJumpOvers(i.value),e.ee()}}this.S()}}S(t){if(t===void 0)this.Ue=!0,this.requestUpdate();else{const i=this.viewportBounds;t.isReal()&&i.intersectsRect(t)&&(this.Ue=!0,this.requestUpdate())}this.D("InvalidateDraw")}invalidateViewport(t,i){if(this.Ue===!0)return;if(this.Ue=!0,this.Oc==="svg"){this.maybeUpdate();return}this.getRenderingHint("temporaryPixelRatio")===!0?(this.Vw(),this.maybeUpdate(),this.CP(!0)):this.maybeUpdate()}aa(){this.Ou=!0}_l(){this.Ic=!0}e0(){this.Du!==!1&&(this.Du=!1,this.EL(this.xt,this.bt))}EL(t,i){this.Ql();const e=this.Vi,s=t*e,n=i*e;this.ft.resize(s,n,t,i)&&(this.Ue=!0,this.Qt.clearContextCache(!0))}BL(){const t=this.ft;if(t===null||this.Iu.isReal())return!0;const i=this.xt,e=this.bt,s=this.Mt;let n=!1,o=this.Kn?this.Wt:0,r=this.ln?this.Wt:0,l=s.clientWidth||i+o,h=s.clientHeight||e+r;const c=this.viewportBounds,a=c.x,f=c.y,u=c.width,d=c.height;if((l!==i+o||h!==e+r)&&(this.Kn=!1,this.ln=!1,o=0,r=0,this.xt=l,this.bt=h,this.Du=!0,n=!0,this.Ql()),!this.jn||!this.viewportBounds.isReal())return!0;const m=this.ab,g=this.cb;if(this.Ou=!1,!n&&!this.Kn&&!this.ln&&!this.Ru&&!this.vu)return!0;const p=this.documentBounds;let w=0,x=0,k=0,b=0;const P=c.width,S=c.height,L=this.$h;this.contentAlignment.isSpot()?(p.width>P&&(w=L.left,x=L.right),p.height>S&&(k=L.top,b=L.bottom)):(w=L.left,x=L.right,k=L.top,b=L.bottom);const C=p.width+w+x,M=p.height+k+b,N=this.scale,T=N;let A=C>l/N,D=M>h/N;if(!n&&!this.Kn&&!this.ln&&!A&&!D)return!0;const F=p.x-w,v=c.x,R=p.right+x;let O=c.right+o;const X=p.y-k,Y=c.y,E=p.bottom+b;let V=c.bottom+r,B="1px",K="1px";if(this.scrollMode===1&&(A||D)){if(A&&this.hasHorizontalScrollbar&&this.allowHorizontalScroll){let z=1;F+1O+1&&(z=Math.max((R-O)*N+this.xt,z)),P+o+1V+1&&(z=Math.max((E-V)*N+this.bt,z)),S+r+1O+1&&(J=Math.max((R-O)*N+this.xt,J)),P+1V+1&&(J=Math.max((E-V)*N+z,J)),S+1O+1&&($=this.position.x*N)),this.zu)switch(this.Sx){case"negative":$=-(m.scrollWidth-$-m.clientWidth);break;case"reverse":$=m.scrollWidth-$-m.clientWidth;break}if(m.scrollLeft=$,this.hasVerticalScrollbar&&this.allowVerticalScroll&&(S+1V+1&&(m.scrollTop=this.position.y*N)),l=this.xt,h=this.bt,m.style.width=l+(this.Kn?this.Wt:0)+"px",m.style.height=h+(this.ln?this.Wt:0)+"px",i!==l||e!==h||this.animationManager.pi){const z=Rect.V(a,f,u,d);return this.onViewportBoundsChanged(z,this.viewportBounds,T,n),Rect.e(z),!1}return!0}add(t){const i=t.diagram;if(i===this)return;i!==null&&U.o("Cannot add part "+t.toString()+" to "+this.toString()+". It is already a part of "+i.toString());let e=this.findLayer(t.layerName);if(e===null&&(e=this.findLayer("")),e===null&&U.o('Cannot add a Part when unable find a Layer named "'+t.layerName+'" and there is no default Layer'),t.layer===e)return;const s=e.Jh(99999999,t,t.diagram===this);s>=0&&this.raiseChangedEvent(3,"parts",e,null,t,null,s),e.isTemporary||this.invalidateDocumentBounds(),t.invalidateLayout(1);const n=t.layerChanged;n!==null&&n(t,null,e)}Jh(t){this.partManager.Jh(t);const i=this;t.Gr(s=>i.GL(s)),t.data||t.Do(),t.hasPlaceholder()&&t.c(),t.data!==null&&t.Gr(s=>i.partManager.IM(s,null)),(t._e()===!0||t.ih()===!0)&&this.t0(t),t.KL(!0,this),t.jL()?(t.actualBounds.isReal()&&this.S(t.Wh(t.actualBounds)),this.invalidateDocumentBounds()):t.isVisible()&&t.actualBounds.isReal()&&this.S(t.Wh(t.actualBounds)),this.requestUpdate()}te(t){t.clearAdornments(),this.partManager.te(t);const i=this;t.data!==null&&t.Gr(s=>i.partManager.EM(s,i)),this.Yn.delete(t),t instanceof Link&&this.Mr.delete(t),t.jL()?(t.actualBounds.isReal()&&this.S(t.Wh(t.actualBounds)),this.invalidateDocumentBounds()):t.isVisible()&&t.actualBounds.isReal()&&this.S(t.Wh(t.actualBounds)),this.requestUpdate()}remove(t){this.UM(t,!0)}UM(t,i){const e=t.layer;if(e===null||e.diagram!==this)return;t.isSelected=!1,t.isHighlighted=!1,t.invalidateLayout(2),i&&t.Xc();const s=e.te(-1,t,!1);s>=0&&this.raiseChangedEvent(4,"parts",e,t,null,s,null);const n=t.layerChanged;n!==null&&n(t,e,null)}removeParts(t,i){if(i===void 0&&(i=!1),Array.isArray(t)){const e=t.length;for(let s=0;s=0&&i.elt(e).isTemporary;)e--;return i.insertAt(e+1,t),this.ki!==null&&this.raiseChangedEvent(3,"layers",this,null,t,null,e+1),this.S(),this.invalidateDocumentBounds(),this}addLayerBefore(t,i){this.BM(t,i),t.Mo(this);const e=this.Xt,s=e.indexOf(t);s>=0&&(e.delete(t),this.ki!==null&&this.raiseChangedEvent(4,"layers",this,t,null,s,null));const n=e.count;let o;for(o=0;o=0&&(e.delete(t),this.ki!==null&&this.raiseChangedEvent(4,"layers",this,t,null,s,null));const n=e.count;let o;for(o=0;othis.maxScale&&(i=this.maxScale);const a=Point.V(this.at.x+l/t-l/i,this.at.y+h/t-h/i);this.position=a,Point.e(a),this.tt=i,this._m(),this.Ql(),this.Ht=!1,this.onViewportBoundsChanged(n,this.viewportBounds,t,!1),this.Bs(!1),e.yL(t,this.tt),this.S()}MR(){const t=this.Xt.r;for(let i=0;i{r.isAvoiding&&r.actualBounds.intersectsRect(i)&&r.invalidateRoute()})}th(t){const i=this.Ze;if(i===null||!i.visible||i.part===null||i.layer===null)return;const e=t!==void 0?t:this.nb;if(!e.isReal())return;const s=e.width,n=e.height;if(i.scale=1,i.angle=0,i.layer.isViewportAligned)i.width=s*this.scale,i.height=n*this.scale,i.part.alignment=Spot.TopLeft;else{i.yi===null&&(i.yi=new GridPanelSettings);const o=i.yi.Yc;if(!o.isReal())return;i.width=s+o.width*2,i.height=n+o.height*2;const r=Point.l();Geo.Dg(e.x,e.y,0,0,o.width,o.height,r),r.offset(-o.width,-o.height),i.part.location=r,Point.e(r)}}clearSelection(t){t===void 0&&(t=!1);const i=this.selection;if(i.count===0)return;t||this.D("ChangingSelection",i);const e=i.toArray(),s=e.length;for(let n=0;n1)&&(this.D("ChangingSelection",this.selection),this.clearSelection(!0),t.isSelected=!0,this.D("ChangedSelection",this.selection))}selectCollection(t){if(this.D("ChangingSelection",this.selection),this.clearSelection(!0),Array.isArray(t)){const i=t.length;for(let e=0;e0){const i=t.toArray(),e=i.length;for(let s=0;s1)&&(this.clearHighlighteds(),t.isHighlighted=!0)}highlightCollection(t){const i=new GSet().addAll(t),s=this.highlighteds.copy().removeAll(i).iterator;for(;s.next();){const o=s.value;o.isHighlighted=!1}const n=i.iterator;for(;n.next();){const o=n.value;o instanceof Part||U.o("Diagram.highlightCollection given something that is not a Part: "+o),o.isHighlighted=!0}}scroll(t,i,e){e===void 0&&(e=1);const s=i==="up"||i==="down";let n=0;const o=Point.l();if(t==="pixel")n=e;else if(t==="line")n=e*(s?this.scrollVerticalLineChange:this.scrollHorizontalLineChange);else if(t==="page"){let l=s?this.viewportBounds.height:this.viewportBounds.width;if(l*=this.scale,l!==0){const h=Math.max(l-(s?this.scrollVerticalLineChange:this.scrollHorizontalLineChange),0);n=e*h}}else if(t==="document"){const l=this.documentBounds,h=this.viewportBounds;i==="up"?this.position=o.i(h.x,l.y):i==="left"?this.position=o.i(l.x,h.y):i==="down"?this.position=o.i(h.x,l.bottom-h.height):i==="right"&&(this.position=o.i(l.right-h.width,h.y)),Point.e(o);return}else U.o("scrolling unit must be 'pixel', 'line', 'page', or 'document', not: "+t);n/=this.scale;const r=this.position;i==="up"?this.position=o.i(r.x,r.y-n):i==="down"?this.position=o.i(r.x,r.y+n):i==="left"?this.position=o.i(r.x-n,r.y):i==="right"?this.position=o.i(r.x+n,r.y):U.o("scrolling direction must be 'up', 'down', 'left', or 'right', not: "+i),Point.e(o)}scrollToRect(t){const i=this.viewportBounds;if(i.containsRect(t))return;const e=t.center;e.x-=i.width/2,e.y-=i.height/2,this.position=e}centerRect(t){const i=this.viewportBounds,e=t.center;e.x-=i.width/2,e.y-=i.height/2,this.position=e}transformDocToView(t){return t.copy().T(this.T)}transformViewToDoc(t){return t.copy().Oe(this.T)}$F(t){return t.Oe(this.T)}static None=1;static Uniform=2;static UniformToFill=3;static CycleAll=1;static CycleNotDirected=2;static CycleNotDirectedFast=3;static CycleNotUndirected=4;static CycleDestinationTree=5;static CycleSourceTree=6;static DocumentScroll=1;static InfiniteScroll=2;static TreeParentCollapsed=1;static AllParentsCollapsed=2;static AnyParentsCollapsed=3;get opacity(){return this.$t}set opacity(t){const i=this.$t;i!==t&&(U.s(t,"number",Diagram,"opacity"),(t<0||t>1)&&U.W(t,"0 <= value <= 1",Diagram,"opacity"),this.$t=t,this.t("opacity",i,t),this.S())}get validCycle(){return this.Ux}set validCycle(t){const i=this.Ux;i!==t&&(this.Ux=t,this.t("validCycle",i,t))}get layers(){return this.Xt.iterator}get isModelReadOnly(){const t=this.ki;return t===null?!1:t.isReadOnly}set isModelReadOnly(t){const i=this.ki;i!==null&&(i.isReadOnly=t)}get isReadOnly(){return this.Ao}set isReadOnly(t){const i=this.Ao;i!==t&&(U.s(t,"boolean",Diagram,"isReadOnly"),this.Ao=t,this.t("isReadOnly",i,t))}get isEnabled(){return this.Oi}set isEnabled(t){const i=this.Oi;i!==t&&(U.s(t,"boolean",Diagram,"isEnabled"),this.Oi=t,this.t("isEnabled",i,t))}get allowClipboard(){return this.Kx}set allowClipboard(t){const i=this.Kx;i!==t&&(U.s(t,"boolean",Diagram,"allowClipboard"),this.Kx=t,this.t("allowClipboard",i,t))}get allowCopy(){return this.Rl}set allowCopy(t){const i=this.Rl;i!==t&&(U.s(t,"boolean",Diagram,"allowCopy"),this.Rl=t,this.t("allowCopy",i,t))}get allowDelete(){return this.vl}set allowDelete(t){const i=this.vl;i!==t&&(U.s(t,"boolean",Diagram,"allowDelete"),this.vl=t,this.t("allowDelete",i,t))}get allowDragOut(){return this.jx}set allowDragOut(t){const i=this.jx;i!==t&&(U.s(t,"boolean",Diagram,"allowDragOut"),this.jx=t,this.t("allowDragOut",i,t))}get allowDrop(){return this.Hx}set allowDrop(t){const i=this.Hx;i!==t&&(U.s(t,"boolean",Diagram,"allowDrop"),this.Hx=t,this.t("allowDrop",i,t))}get allowTextEdit(){return this.Ol}set allowTextEdit(t){const i=this.Ol;i!==t&&(U.s(t,"boolean",Diagram,"allowTextEdit"),this.Ol=t,this.t("allowTextEdit",i,t))}get allowGroup(){return this.Il}set allowGroup(t){const i=this.Il;i!==t&&(U.s(t,"boolean",Diagram,"allowGroup"),this.Il=t,this.t("allowGroup",i,t))}get allowUngroup(){return this.El}set allowUngroup(t){const i=this.El;i!==t&&(U.s(t,"boolean",Diagram,"allowUngroup"),this.El=t,this.t("allowUngroup",i,t))}get allowInsert(){return this.qx}set allowInsert(t){const i=this.qx;i!==t&&(U.s(t,"boolean",Diagram,"allowInsert"),this.qx=t,this.t("allowInsert",i,t))}get allowLink(){return this.Ul}set allowLink(t){const i=this.Ul;i!==t&&(U.s(t,"boolean",Diagram,"allowLink"),this.Ul=t,this.t("allowLink",i,t))}get allowRelink(){return this.Bl}set allowRelink(t){const i=this.Bl;i!==t&&(U.s(t,"boolean",Diagram,"allowRelink"),this.Bl=t,this.t("allowRelink",i,t))}get allowMove(){return this.Vl}set allowMove(t){const i=this.Vl;i!==t&&(U.s(t,"boolean",Diagram,"allowMove"),this.Vl=t,this.t("allowMove",i,t))}get allowReshape(){return this.zl}set allowReshape(t){const i=this.zl;i!==t&&(U.s(t,"boolean",Diagram,"allowReshape"),this.zl=t,this.t("allowReshape",i,t))}get allowResize(){return this.Xl}set allowResize(t){const i=this.Xl;i!==t&&(U.s(t,"boolean",Diagram,"allowResize"),this.Xl=t,this.t("allowResize",i,t))}get allowRotate(){return this.Yl}set allowRotate(t){const i=this.Yl;i!==t&&(U.s(t,"boolean",Diagram,"allowRotate"),this.Yl=t,this.t("allowRotate",i,t))}get allowSelect(){return this.Gl}set allowSelect(t){const i=this.Gl;i!==t&&(U.s(t,"boolean",Diagram,"allowSelect"),this.Gl=t,this.t("allowSelect",i,t))}get allowUndo(){return this.Wx}set allowUndo(t){const i=this.Wx;i!==t&&(U.s(t,"boolean",Diagram,"allowUndo"),this.Wx=t,this.t("allowUndo",i,t))}get allowZoom(){return this.Jx}set allowZoom(t){const i=this.Jx;i!==t&&(U.s(t,"boolean",Diagram,"allowZoom"),this.Jx=t,this.t("allowZoom",i,t))}get hasVerticalScrollbar(){return this.vu}set hasVerticalScrollbar(t){const i=this.vu;i!==t&&(U.s(t,"boolean",Diagram,"hasVerticalScrollbar"),this.vu=t,this.aa(),this.S(),this.t("hasVerticalScrollbar",i,t),this.Bs(!1))}get hasHorizontalScrollbar(){return this.Ru}set hasHorizontalScrollbar(t){const i=this.Ru;i!==t&&(U.s(t,"boolean",Diagram,"hasHorizontalScrollbar"),this.Ru=t,this.aa(),this.S(),this.t("hasHorizontalScrollbar",i,t),this.Bs(!1))}get allowHorizontalScroll(){return this.$x}set allowHorizontalScroll(t){const i=this.$x;i!==t&&(U.s(t,"boolean",Diagram,"allowHorizontalScroll"),this.$x=t,this.t("allowHorizontalScroll",i,t),this.Bs(!1))}get allowVerticalScroll(){return this.Zx}set allowVerticalScroll(t){const i=this.Zx;i!==t&&(U.s(t,"boolean",Diagram,"allowVerticalScroll"),this.Zx=t,this.t("allowVerticalScroll",i,t),this.Bs(!1))}get scrollHorizontalLineChange(){return this.Qx}set scrollHorizontalLineChange(t){const i=this.Qx;i!==t&&(U.s(t,"number",Diagram,"scrollHorizontalLineChange"),t<0&&U.W(t,">= 0",Diagram,"scrollHorizontalLineChange"),this.Qx=t,this.t("scrollHorizontalLineChange",i,t))}get scrollVerticalLineChange(){return this._x}set scrollVerticalLineChange(t){const i=this._x;i!==t&&(U.s(t,"number",Diagram,"scrollVerticalLineChange"),t<0&&U.W(t,">= 0",Diagram,"scrollVerticalLineChange"),this._x=t,this.t("scrollVerticalLineChange",i,t))}get lastInput(){return this._h}set lastInput(t){this._h=t}get previousInput(){return this.Br}set previousInput(t){this.Br=t}get firstInput(){return this.Gm}set firstInput(t){this.Gm=t}get currentCursor(){return this.Bx}set currentCursor(t){if(t===""&&(t=this.Um),this.Bx!==t){U.s(t,"string",Diagram,"currentCursor");const e=this.ft,s=this.Mt;if(e===null||s===null)return;this.Bx=t;const n=e.style.cursor;e.style.cursor=t,s.style.cursor=t,e.style.cursor===n&&(e.style.cursor="-webkit-"+t,s.style.cursor="-webkit-"+t,e.style.cursor===n&&(e.style.cursor="-moz-"+t,s.style.cursor="-moz-"+t,e.style.cursor===n&&(e.style.cursor=t,s.style.cursor=t)))}}get defaultCursor(){return this.Um}set defaultCursor(t){t===""&&(t="auto");const i=this.Um;i!==t&&(U.s(t,"string",Diagram,"defaultCursor"),this.Um=t,this.t("defaultCursor",i,t))}get click(){return this.Cr}set click(t){const i=this.Cr;i!==t&&(t!==null&&U.k(t,Diagram,"click"),this.Cr=t,this.t("click",i,t))}get doubleClick(){return this.Lr}set doubleClick(t){const i=this.Lr;i!==t&&(t!==null&&U.k(t,Diagram,"doubleClick"),this.Lr=t,this.t("doubleClick",i,t))}get contextClick(){return this.Ar}set contextClick(t){const i=this.Ar;i!==t&&(t!==null&&U.k(t,Diagram,"contextClick"),this.Ar=t,this.t("contextClick",i,t))}get mouseOver(){return this.Tr}set mouseOver(t){const i=this.Tr;i!==t&&(t!==null&&U.k(t,Diagram,"mouseOver"),this.Tr=t,this.t("mouseOver",i,t))}get mouseHover(){return this.Dr}set mouseHover(t){const i=this.Dr;i!==t&&(t!==null&&U.k(t,Diagram,"mouseHover"),this.Dr=t,this.t("mouseHover",i,t))}get mouseHold(){return this.Fr}set mouseHold(t){const i=this.Fr;i!==t&&(t!==null&&U.k(t,Diagram,"mouseHold"),this.Fr=t,this.t("mouseHold",i,t))}get mouseDragOver(){return this.Vx}set mouseDragOver(t){const i=this.Vx;i!==t&&(t!==null&&U.k(t,Diagram,"mouseDragOver"),this.Vx=t,this.t("mouseDragOver",i,t))}get mouseDrop(){return this.Rr}set mouseDrop(t){const i=this.Rr;i!==t&&(this.Rr=t,this.t("mouseDrop",i,t))}get handlesDragDropForTopLevelParts(){return this.zx}set handlesDragDropForTopLevelParts(t){const i=this.zx;i!==t&&(U.s(t,"boolean",Diagram,"handlesDragDropForTopLevelParts"),this.zx=t,this.t("handlesDragDropForTopLevelParts",i,t))}get mouseEnter(){return this.vr}set mouseEnter(t){const i=this.vr;i!==t&&(t!==null&&U.k(t,Diagram,"mouseEnter"),this.vr=t,this.t("mouseEnter",i,t))}get mouseLeave(){return this.Or}set mouseLeave(t){const i=this.Or;i!==t&&(t!==null&&U.k(t,Diagram,"mouseLeave"),this.Or=t,this.t("mouseLeave",i,t))}get toolTip(){return this.Ir}set toolTip(t){const i=this.Ir;i!==t&&(this.Ir=t,this.t("toolTip",i,t))}get contextMenu(){return this.Er}set contextMenu(t){const i=this.Er;i!==t&&(this.Er=t,this.t("contextMenu",i,t))}get commandHandler(){return this.sM}set commandHandler(t){const i=this.sM;i!==t&&(i&&i.doStop(),this.sM=t,t.Mo(this),t.doStart())}get toolManager(){return this.tM}set toolManager(t){this.tM!==t&&(this.tM=t,t.diagram=this)}get defaultTool(){return this.iM}set defaultTool(t){const i=this.iM;i!==t&&(this.iM=t,t.diagram=this,this.currentTool===i&&(this.currentTool=t))}get currentTool(){return this.eM}set currentTool(t){const i=this.eM;i&&(i.isActive&&i.doDeactivate(),i.cancelWaitAfter(),i.doStop()),t===null&&(t=this.defaultTool),t!==null&&(this.eM=t,t.diagram=this,t.doStart())}get selection(){return this.cM}get maxSelectionCount(){return this.sb}set maxSelectionCount(t){const i=this.sb;if(i!==t)if(U.s(t,"number",Diagram,"maxSelectionCount"),t>=0&&!isNaN(t)){if(this.sb=t,this.t("maxSelectionCount",i,t),!this.undoManager.isUndoingRedoing){const e=this.selection.count-t;if(e>0){this.D("ChangingSelection",this.selection);const s=this.selection.toArray();for(let n=0;n= 0",Diagram,"maxSelectionCount")}get nodeSelectionAdornmentTemplate(){return this.Xm}set nodeSelectionAdornmentTemplate(t){const i=this.Xm;i!==t&&(this.Xm=t.Et(),this.t("nodeSelectionAdornmentTemplate",i,t))}get groupSelectionAdornmentTemplate(){return this.rb}set groupSelectionAdornmentTemplate(t){const i=this.rb;i!==t&&(this.rb=t.Et(),this.t("groupSelectionAdornmentTemplate",i,t))}get linkSelectionAdornmentTemplate(){return this.lb}set linkSelectionAdornmentTemplate(t){const i=this.lb;i!==t&&(this.lb=t.Et(),this.t("linkSelectionAdornmentTemplate",i,t))}get highlighteds(){return this.fM}get isModified(){const t=this.undoManager;return t.isEnabled?t.currentTransaction!==null?!0:this.Uu&&this.Os!==t.historyIndex:this.Uu}set isModified(t){if(this.Uu!==t){U.s(t,"boolean",Diagram,"isModified"),this.Uu=t;const e=this.undoManager;!t&&e.isEnabled&&(this.Os=e.historyIndex),t||this._L()}}_L(){const t=this.isModified;this.hM!==t&&(this.hM=t,this.D("Modified"))}get model(){return this.ki}set model(t){const i=this.ki;if(i!==t){this.currentTool.doCancel(),i&&i.undoManager!==t.undoManager&&i.undoManager.isInTransaction&&U.o("Do not replace a Diagram.model while a transaction is in progress."),this.animationManager.stopAnimation(!0);const e=this.OL(!0);this.jn=!1,this.Fu=!0,this.Os=-2,this.xr=!1;const s=this.Ht;this.Ht=!0,this.animationManager.Fl("Model"),i&&(this.Gn!==null&&this.Gn.each(n=>i.removeChangedListener(n)),i.removeChangedListener(this.lM)),this.ki=t,this.partManager=this.vR(this.ki.type),this.initializePartManager(this.partManager);for(let n=0;nt.addChangedListener(n)),this.Ht=s,this.invalidateDocumentBounds(),this.Ht||this.S(),i&&t.undoManager.copyProperties(i.undoManager)}}get themeManager(){return this.NM}set themeManager(t){const i=this.NM;i!==t&&(i&&i.removeDiagram(this),this.NM=t,t!==null&&t.addDiagram(this))}initializePartManager(t){}static CM(t,i){Diagram.AL.set(t,i)}static get licenseKey(){return Diagram.XM.last()}static set licenseKey(t){Diagram.XM.add(t.replace(/\s/g,""))}static get version(){return Diagram.OR}static XM=new List;static OR="3.0.26";vR(t){const i=Diagram.AL.get(t);return i!==null?new i:new PartManager}get X(){return this.oM}set X(t){this.oM=t}get bx(){return this.NL}IR(t){if(t.model!==this.model)return;const i=t.change,e=t.propertyName;if(i===1&&e[0]==="S"){if(e==="StartingFirstTransaction"){const s=this,n=this.toolManager;n.mouseDownTools.each(o=>o.diagram=s),n.mouseMoveTools.each(o=>o.diagram=s),n.mouseUpTools.each(o=>o.diagram=s),this.routers.each(o=>o.diagram=s),!this.ys&&!this.jn&&(this.vc=!0,this.Fu&&(this.xr=!0))}else if(e==="StartingUndo"||e==="StartingRedo"){const s=this.animationManager;this.skipsUndoManager||(s.defaultAnimation.isAnimating&&s.stopAnimation(),s.getBundleAnimation().isAnimating&&s.getBundleAnimation().stop()),this.D("ChangingSelection",this.selection)}else if(e==="StartedTransaction"){const s=this.animationManager;s.defaultAnimation.isAnimating&&!this.skipsUndoManager&&s.stopAnimation()}return}if(this.X){this.X=!1;try{if(t.modelChange===""&&i===1){(e==="FinishedUndo"||e==="FinishedRedo")&&(this.D("ChangedSelection",this.selection),this.Mi());const s=this.animationManager;e==="RolledBackTransaction"&&s.stopAnimation(),this.xL(),this.vc=!0,this.maybeUpdate(),(this.undoManager.transactionLevel===0||this.undoManager.transactionLevel===1)&&s.OS(),e==="CommittedTransaction"&&this.undoManager.isJustDiscarded&&(this.Os=Math.min(this.Os,this.undoManager.historyIndex-1)),(e==="CommittedTransaction"||e==="RolledBackTransaction")&&this.undoManager.Uw&&U.ir(()=>{this.isModified=!1},1);const n=t.isTransactionFinished;if(n&&(this._L(),this.bx.clear(),this.animationManager.OF()),!this.Xx&&n&&this.lastInput.targetDiagram){this.Xx=!0;const o=this;U.ir(()=>{o.currentTool.standardMouseOver(),o.Xx=!1},10)}}}finally{this.X=!0}}}get fe(){return this.nM}set fe(t){this.nM=t}get du(){return this.Yx}set du(t){this.Yx=t}GL(t){const i=t.C.r;for(const e of i)e instanceof Picture&&this.YM(e)}YM(t){const i=t.element;if(i===null||!(i instanceof HTMLImageElement)||(i.ts instanceof GSet&&i.ts.add(this),t.ER(),!i.r0))return;const e=i.getAttribute("src")||"",s=this.Jl.get(e);if(s===null){Picture.tA(t,i);const n=[];n.push(t),this.Jl.set(e,n)}else{for(let n=0;n0?(this.Cx=t,this.t("minScale",i,t),t>this.scale&&(this.scale=t)):U.W(t,"> 0",Diagram,"minScale"))}get maxScale(){return this.Lx}set maxScale(t){const i=this.Lx;i!==t&&(t>0?(this.Lx=t,this.t("maxScale",i,t),t 0",Diagram,"maxScale"))}get zoomPoint(){return this.Ax}set zoomPoint(t){this.Ax.equals(t)||(t=t.P(),this.Ax=t)}get contentAlignment(){return this.Fc}set contentAlignment(t){const i=this.Fc;i.equals(t)||(t=t.P(),this.Fc=t,this.t("contentAlignment",i,t),this.Bs(!1))}get initialContentAlignment(){return this.Om}set initialContentAlignment(t){const i=this.Om;i.equals(t)||(t=t.P(),this.Om=t,this.t("initialContentAlignment",i,t))}get padding(){return this.Zt}set padding(t){typeof t=="number"&&(t=new Margin(t));const i=this.Zt;i.equals(t)||(t=t.P(),this.Zt=t,this.invalidateDocumentBounds(),this.t("padding",i,t))}get partManager(){return this.pM}set partManager(t){const i=this.pM;i!==t&&(t.diagram!==null&&U.o("Cannot share PartManagers between Diagrams: "+t.toString()),i&&i.Mo(null),this.pM=t,t.Mo(this))}get nodes(){return this.partManager.nodes.iterator}get links(){return this.partManager.links.iterator}get parts(){return this.partManager.parts.iterator}findTopLevelNodesAndLinks(){const t=new GSet,i=this.nodes;for(;i.next();){const s=i.value;s.isTopLevel&&t.add(s)}const e=this.links;for(;e.next();){const s=e.value;s.isTopLevel&&t.add(s)}return t.iterator}findTopLevelGroups(){return this.zr.iterator}get routers(){return this.Vc}doLinkRouting(t){this.Co=!0;const i=this.Vc.r;for(let e=0;e0){const l=this.computePartsBounds(n.memberParts,!1);l.inflate(20,20),s.Lb(l)}const o=Rect.l(),r=n.memberParts;for(;r.next();){const l=r.value;l instanceof Node&&this.WM(l,e,o)}Rect.e(o)}s.ua=n,s.jM=e,s.Fo=!1}else t&&s.rA();return s}get avoidanceCellSize(){return this.uM}set avoidanceCellSize(t){this.Hl=null,this.uM=new Size(Math.max(1,t.width),Math.max(1,t.height))}get avoidanceLimit(){return this.dM}set avoidanceLimit(t){this.dM=Math.max(1,t)}oA(t){return t.canAvoid()?t:t.containingGroup!==null?this.oA(t.containingGroup):null}WM(t,i,e){if(t===i||!t.isVisible())return;const s=t.canAvoid();if(s){const n=t.getAvoidableRect(e);this.Hl.VR(n.x,n.y,n.width,n.height)}if(t instanceof Group&&(!s||t.avoidableMembers)){const n=t.memberParts;for(;n.next();){const o=n.value;o instanceof Node&&this.WM(o,i,e)}}}JM(t){this.Hl!==null&&!this.Hl.Fo&&(t===void 0||t.canAvoid())&&(this.Hl.Fo=!0)}get autoScrollInterval(){return this.Im}set autoScrollInterval(t){const i=this.Im;i!==t&&(this.Im=t,this.t("autoScrollInterval",i,t))}get autoScrollRegion(){return this.Em}set autoScrollRegion(t){typeof t=="number"&&(t=new Margin(t));const i=this.Em;i.equals(t)||(t=t.P(),this.Em=t,this.invalidateDocumentBounds(),this.t("autoScrollRegion",i,t))}doAutoScroll(t){this.Ym.a(t),this.computeAutoScrollPosition(this.Ym).equalsApprox(this.position)?this.stopAutoScroll():this.lA()}lA(){if(this.Rc!==-1)return;const t=this.Im,i=this;this.Rc=U.ir(()=>{if(i.Rc===-1||(i.stopAutoScroll(),i.lastInput.event===null))return;const s=i.computeAutoScrollPosition(i.Ym);if(s.equalsApprox(i.position))return;i.position=s,i.lastInput.documentPoint=i.transformViewToDoc(i.Ym),i.doMouseMove(),i.ta=!0;const n=Rect.l();i.computeBounds(n),n.unionRect(i.documentBounds),i.iA(n),Rect.e(n),i.Ue=!0,i.maybeUpdate(),i.lA()},t)}stopAutoScroll(){this.Rc!==-1&&(U.Tg(this.Rc),this.Rc=-1)}computeAutoScrollPosition(t){let i=this.position;const e=this.Em;if(e.top<=0&&e.left<=0&&e.right<=0&&e.bottom<=0)return i;const s=this.viewportBounds,n=this.scale,o=Rect.V(0,0,s.width*n,s.height*n),r=Point.V(0,0);if(t.x>=o.x&&t.xo.x+o.width-e.right&&this.allowHorizontalScroll){let l=Math.max(this.scrollHorizontalLineChange,1);l=l|0,r.x+=l,t.x>o.x+o.width-e.right/2&&(r.x+=l),t.x>o.x+o.width-e.right/4&&(r.x+=4*l)}if(t.y>=o.y&&t.yo.y+o.height-e.bottom&&this.allowVerticalScroll){let l=Math.max(this.scrollVerticalLineChange,1);l=l|0,r.y+=l,t.y>o.y+o.height-e.bottom/2&&(r.y+=l),t.y>o.y+o.height-e.bottom/4&&(r.y+=4*l)}return r.equalsApprox(Point.xo)||(i=new Point(i.x+r.x/n,i.y+r.y/n)),Rect.e(o),Point.e(r),i}makeSvg(t){this.Wl.has("SVG")||this.addRenderer("SVG",new SVGSurface(this,root.document));const i=new SVGSurface(this,root.document,!0);t===void 0&&(t={});const e=this;function s(n,o){const r=e.hA(n,"SVG",i),l=r!==null?r.svg:null;return U.it(o)?(o(l),null):l}return this.aA(s,t)}makeSVG(t){return this.makeSvg(t)}addRenderer(t,i){this.Wl.set(t,i)}removeRenderer(t){this.Wl.delete(t)}cacheGroupExternalLinks(t){this.MM=t,t||this.nodes.each(i=>{i instanceof Group&&(i.h0=null)})}aA(t,i){const e=i.callback;let s=!0;const o=this.Jl.iterator;for(;o.next();)if(!o.value[0].hn){s=!1;break}if(!U.it(e)||s)return t(i,e,this);const r=this;function l(){const a=+new Date;for(s=!0,o.reset();o.next();)if(!o.value[0].hn){s=!1;break}if(s||a-c>h){t(i,e,r);return}root.requestAnimationFrame(l)}const h=i.callbackTimeout||300,c=+new Date;return root.requestAnimationFrame(()=>l()),null}makeImage(t){return Diagram.isUsingDOM()?(t===void 0&&(t={}),t.returnType="Image",this.makeImageData(t)):null}makeImageData(t){return t===void 0&&(t={}),this.aA(this.zR,t)}static img="image";zR(t,i,e){const s=e.hA(t,"canvas",null);if(s===null)return null;const n=s.E.canvas;let o=null;if(n!==null){let r=t.returnType;switch(r===void 0?r="string":r=r.toLowerCase(),r){case Diagram.img+"data":o=s.getImageData(0,0,n.width,n.height);break;case Diagram.img:const h=(t.document||document).createElement("img");h.src=n.toDataURL(t.type,t.details),o=h;break;case"blob":{const c=n;return U.it(i)||(o="",U.o('Error: Diagram.makeImageData called with "returnType: toBlob", but no required "callback" function property defined.')),U.it(c.toBlob)?(c.toBlob(i,t.type,t.details),"toBlob"):(i(null),null)}case"string":default:o=n.toDataURL(t.type,t.details)}}return U.it(i)?(i(o),null):o}static XR=!1;hA(t,i,e){if(this.animationManager.stopAnimation(),this.maybeUpdate(),this.ft===null)return null;U.G(t)||U.o("properties argument must be an Object.");let n=!1,o=t.size||null,r=t.scale||null;t.scale!==void 0&&isNaN(t.scale)&&(r="NaN");let l=t.maxSize;t.maxSize===void 0&&(n=!0,i==="SVG"?l=new Size(1/0,1/0):l=new Size(2e3,2e3));const h=t.position||null;let c=t.parts||null;Array.isArray(c)&&(c=new List(c));let a=t.padding===void 0?1:t.padding;const f=t.background||null;let u=t.omitTemporary;u===void 0&&(u=!0);const d=t.document||document,m=t.elementFinished||null;let g=t.showTemporary;g===void 0&&(g=!u);let p=t.showGrid;p===void 0&&(p=g),o!==null&&isNaN(o.width)&&isNaN(o.height)&&(o=null),typeof a=="number"?a=new Margin(a):a instanceof Margin||U.o("MakeImage padding must be a Margin or a number."),a.left=Math.max(a.left,0),a.right=Math.max(a.right,0),a.top=Math.max(a.top,0),a.bottom=Math.max(a.bottom,0),this.Qt.clearContextCache(!0);const w=new CanvasSurface(null,d,void 0,!0),x=w.li;if(!(o||r||c||h))return w.width=this.xt+Math.ceil(a.left+a.right),w.height=this.bt+Math.ceil(a.top+a.bottom),i==="SVG"?e===null?null:(e.resize(w.width,w.height,w.width,w.height),e.jr=d,e.Gu=m,this.Sb(e.li,a,new Size(w.width,w.height),this.tt,this.at,c,f,g,p),e.li):(this.Bu=!1,this.Sb(x,a,new Size(w.width,w.height),this.tt,this.at,c,f,g,p),this.Bu=!0,w.li);const k=this.Km,b=this.documentBounds.copy();if(b.subtractMargin(this.Zt),g){const A=this.Xt.r,D=A.length;for(let F=0;Fk?(r=k,N=b.width,T=b.height):(N=l.width,T=l.height)):(N=b.width*r,T=b.height*r):(r=k,N=b.width,T=b.height),a!==null?(N+=S,T+=L):a=new Margin(0),l!==null){let A=l.width,D=l.height;i!=="SVG"&&n&&Diagram.XR,isNaN(A)&&(A=2e3),isNaN(D)&&(D=2e3),isFinite(A)&&(N=Math.min(N,A)),isFinite(D)&&(T=Math.min(T,D))}return w.width=Math.ceil(N),w.height=Math.ceil(T),i==="SVG"?e===null?null:(e.resize(w.width,w.height,w.width,w.height),e.jr=d,e.Gu=m,this.Sb(e.li,a,new Size(Math.ceil(N),Math.ceil(T)),r,P,c,f,g,p),e.li):(this.Bu=!1,this.Sb(x,a,new Size(Math.ceil(N),Math.ceil(T)),r,P,c,f,g,p),this.Bu=!0,w.li)}static Xu=null;static cA="5da73c80a36555d4038e4972187c3cae51fd22";static mw=!1;static Gk=()=>{if(Diagram.cA[5]===void 0&&(Transform.prototype.$e=Transform.prototype.kw),!Diagram.isUsingDOM())return;const t=U.hs("canvas"),i=t.getContext("2d"),e=U.Ts("7ca11abfd022028846");i[e]=U.Ts("398c3597c01238");const s="7ca11abfd7330390",n=[Diagram.cA,U.mw+"4ae6247590da4bb21c324ba3a84e385776",Transform.Gk+"fb236cdfda5de14c134ba1a95a2d4c7cc6f93c1387",Geo.za],o=10,r=0;for(let l=1;l<5;l++)i[U.Ts(s)](U.Ts(n[l-1]),o,l*15+r);i[e]=U.Ts("39f046ebb36e4b");for(let l=1;l<5;l++)i[U.Ts(s)](U.Ts(n[l-1]),o,l*15+r);(n.length!==4||n[0][0]!=="5"||n[3][0]!=="7")&&(Transform.prototype.$e=Transform.prototype.kw),Diagram.Xu=t}}class DiagramHelper{fA;uA;$M;Ne;constructor(t){if(this.fA=null,this.uA="63ad05bbe23a1786468a4c741b6d2",this.$M="@onz",this.uA===this._tk){this.$M=!0,this.Ne=this.$M;return}this.Ne=null}YR(t,i){let e="f";const s=root[U.Ts("76a715b2f73f148a")][U.Ts("72ba13b5")]||"",n=U.Ts;if(this.Ne=!0,!Diagram.isUsingDOM())return;let o=Diagram[n("76a115b6ed251eaf4692")];if(!o){const l=s[n("76ad18b4f73e")];for(let c=s[n("73a612b6fb191d")](n("35e7"))+2;c=0&&hc[0]||h[0]===c[0]&&h[1]>=c[1]))continue;const a="73a612b6fb191d",f=root[n("74a900bae4370f8b51")][n("6fbb13a1c2311e8a57")].toLowerCase(),u=f[n(a)](n("3aad1ab6e022098b4dc4")),d=n(l[2]);if(u>-1){const M=f[n(a)](d.toLowerCase()+"/");if(this.Ne=!(M>-1&&M=0&&g-1),!this.Ne))return;const p=root[U.Ts("76a715b2f73f148a")][U.Ts("69ad17a1e03e")],w=p[n(a)](n("7fb002b6ed25128b4da25b2e"));if(w>-1&&(this.Ne=!(p[n(a)](d)>w),!this.Ne))return;const x=d;if(x[0]!=="#")continue;const k=U.hs("div");let b=l[0].replace(/[A-Za-z]/g,"");for(;b.length<4;)b+="9";const P=b;b=b.substring(b.length-4);let S="";const L=["gsh","gsf"],C=["Header","Background","Display","Feedback"];if(S+=L[parseInt(b.substring(0,1),10)%2],S+=C[parseInt(b.substring(0,1),10)%4],k[n("79a417a0f0181a8946")]=S,root.document[n("78a712aa")]){root.document[n("78a712aa")][n("7bb806b6ed32388c4a875b")](k);const M=root.getComputedStyle(k).getPropertyValue(n("78a704b7e62456904c9b12701b6532a8")),N=root.getComputedStyle(k).getPropertyValue(n("75b817b0ea2202"));if(root.document[n("78a712aa")][n("68ad1bbcf533388c4a875b")](k),!M)continue;const T=root[n("77a902b0eb1b1e804a8a")],A="0."+parseInt(P,10)%100;if(N===A||M.indexOf(parseInt(x[1]+x[2],16))!==-1&&M.indexOf(parseInt(x[3]+x[4],16))!==-1){this.Ne=!1;return}else if(T&&T(n("32ae19a1e0331fc94084537c067a67fa59f1386b89d006")).matches){S="."+S;for(let D=0;D{const s=this.observed;if(s===null)return;const n=s.viewportBounds,o=this.lastInput.documentPoint;s.position=new Point(o.x-n.width/2,o.y-n.height/2)},this._M=s=>{this.invalidateDocumentBounds(),this.c0()},this.t2=s=>{this.observed!==null&&(this.invalidateDocumentBounds(),this.S())},this.Rb=s=>{this.updateDelay<1?this.S():this.a0||(this.a0=!0,U.ir(()=>this.redraw(),this.updateDelay))},this.i2=s=>{this.observed!==null&&this.c0()},this.autoScale=2,this.Ht=!1,i&&Object.assign(this,i),this}setupRouters(){}computePixelRatio(){return 1}redraw(){this.a0&&this.updateDelay>=1&&(this.a0=!1,this.GR()),super.redraw()}Ui(){if(this.Mt===null&&U.o("No div specified"),this.ft===null&&U.o("No canvas specified"),this.ft instanceof SVGSurface||(this.box.JS(),!this.Ue))return;const t=this.observed;if(t===null||t.animationManager.defaultAnimation.isAnimating||!t.Vh)return;this.e0();const i=this.ft,e=this.Qt;if(e.clearContextCache(!0),e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,i.width,i.height),this.updateDelay<1)this.gA();else if(this.Kc!==null){e.drawImage(this.Kc.Tt,0,0);const o=this.T;e.scale(this.Vi,this.Vi),e.transform(o.m11,o.m12,o.m21,o.m22,o.dx,o.dy),e.commitTransform()}const s=this.Xt.r,n=s.length;for(let o=0;on.canDelete())}t.removeParts(i,!0),t.D("SelectionDeleted",i)}finally{t.commitTransaction("Delete"),t.D("ChangedSelection",t.selection),t.currentCursor=""}}canDeleteSelection(){const t=this.diagram;return!(t.isReadOnly||t.isModelReadOnly||!t.allowDelete||t.selection.count===0)}copySelection(){const t=this.diagram;try{const i=new GSet,e=t.selection.iterator;for(;e.next();){const s=e.value;Part.oh(i,s,!0,this.copiesTree?1/0:0,this.copiesConnectedLinks,n=>n.canCopy())}this.copyToClipboard(i)}finally{}}canCopySelection(){const t=this.diagram;return!(!t.allowCopy||!t.allowClipboard||t.selection.count===0)}cutSelection(){this.copySelection(),this.deleteSelection()}canCutSelection(){const t=this.diagram;return!(t.isReadOnly||t.isModelReadOnly||!t.allowCopy||!t.allowDelete||!t.allowClipboard||t.selection.count===0)}copyToClipboard(t){const i=this.diagram;let e=null;if(t===null)Diagram.vL();else{let s=null;try{s=i.copyParts(t,null,!0)}finally{e=new List,s!==null&&e.addAll(s.iteratorValues),Diagram.Zm=e,Diagram.bb=i.model.dataFormat}}i.D("ClipboardChanged",e)}pasteFromClipboard(){const t=new GSet,i=Diagram.Zm;if(i===null)return t;const e=this.diagram;if(Diagram.bb!==e.model.dataFormat)return t;let s=null;try{s=e.copyParts(i,e,!1)}finally{if(s!==null){const n=s.iterator;for(;n.next();){const o=n.value,r=n.key;o.location.isReal()||(r.location.isReal()?o.location=r.location:!o.position.isReal()&&r.position.isReal()&&(o.position=r.position)),t.add(o)}}}return t}pasteSelection(t){t===void 0&&(t=null);const i=this.diagram;try{i.currentCursor="wait",i.D("ChangingSelection",i.selection),i.startTransaction("Paste");const e=this.pasteFromClipboard();e.count>0&&i.clearSelection(!0);const s=e.iterator;for(;s.next();){const n=s.value;n.isSelected=!0}if(t!==null){const n=i.computePartsBounds(i.selection);if(n.isReal()){const o=this.computeEffectiveCollection(i.selection,i.yb);i.TP(o,new Point(t.x-n.centerX,t.y-n.centerY),i.yb,!1)}}i.D("ClipboardPasted",e)}finally{i.commitTransaction("Paste"),i.D("ChangedSelection",i.selection),i.currentCursor=""}}canPasteSelection(t){const i=this.diagram;return!(i.isReadOnly||i.isModelReadOnly||!i.allowInsert||!i.allowClipboard||Diagram.Zm===null||Diagram.Zm.count===0||Diagram.bb!==i.model.dataFormat)}undo(){this.diagram.undoManager.undo()}canUndo(){const t=this.diagram;return t.isReadOnly||t.isModelReadOnly?!1:t.allowUndo&&t.undoManager.canUndo()}redo(){this.diagram.undoManager.redo()}canRedo(){const t=this.diagram;return t.isReadOnly||t.isModelReadOnly?!1:t.allowUndo&&t.undoManager.canRedo()}decreaseZoom(t){t===void 0&&(t=1/this.zoomFactor);const i=this.diagram;if(i.autoScale!==1)return;const e=i.scale*t;ei.maxScale||(i.scale=e)}canDecreaseZoom(t){t===void 0&&(t=1/this.zoomFactor);const i=this.diagram;if(i.autoScale!==1)return!1;const e=i.scale*t;return ei.maxScale?!1:i.allowZoom}increaseZoom(t){t===void 0&&(t=this.zoomFactor);const i=this.diagram;if(i.autoScale!==1)return;const e=i.scale*t;ei.maxScale||(i.scale=e)}canIncreaseZoom(t){t===void 0&&(t=this.zoomFactor);const i=this.diagram;if(i.autoScale!==1)return!1;const e=i.scale*t;return ei.maxScale?!1:i.allowZoom}resetZoom(t){t===void 0&&(t=this.defaultScale);const i=this.diagram;ti.maxScale||(i.scale=t)}canResetZoom(t){t===void 0&&(t=this.defaultScale);const i=this.diagram;return ti.maxScale?!1:i.allowZoom}zoomToFit(){const t=this.diagram,i=t.animationManager;i.stopAnimation(),t.redraw();const e=t.position,s=t.scale;i.Fl("Zoom To Fit"),this.isZoomToFitRestoreEnabled&&s===this.Ib&&!isNaN(this.vb)&&this.Ob!==null&&t.documentBounds.equals(this.Eb)?(t.scale=this.vb,t.position=this.Ob,this.Ib=NaN,this.Eb=Rect.Fg):(this.vb=s,this.Ob=e.copy(),t.zoomToFit(),this.Ib=t.scale,this.Eb=t.documentBounds.copy()),i.OS()}canZoomToFit(){return this.diagram.allowZoom}scrollToPart(t){t===void 0&&(t=null);const i=this.diagram;if(i.ensureBounds(),t===null){try{this.Ro!==null&&(this.Ro.next()?t=this.Ro.value:this.Ro=null)}catch{this.Ro=null}t===null&&(i.highlighteds.count>0?this.Ro=i.highlighteds.iterator:i.selection.count>0&&(this.Ro=i.selection.iterator),this.Ro!==null&&this.Ro.next()&&(t=this.Ro.value))}if(t!==null){const e=i.animationManager;e.Fl("Scroll To Part");const s=this.scrollToPartPause;if(s>0){const n=this.jc(t,[t]);if(n.length===1)i.startTransaction(),i.centerRect(t.actualBounds),i.commitTransaction("Scroll To Part");else{const o=()=>{i.startTransaction();let l=n.pop();for(;n.length>0&&l instanceof Node&&l.isTreeExpanded&&(!(l instanceof Group)||l.isSubGraphExpanded);)l=n.pop();n.length>0?(l instanceof Part&&i.scrollToRect(l.actualBounds),l instanceof Node&&!l.isTreeExpanded&&(l.isTreeExpanded=!0),l instanceof Group&&!l.isSubGraphExpanded&&(l.isSubGraphExpanded=!0)):(l instanceof Part&&i.centerRect(l.actualBounds),i.removeDiagramListener("LayoutCompleted",r)),i.commitTransaction("Scroll To Part")},r=()=>{U.ir(o,(e.isEnabled?e.duration:0)+s)};i.addDiagramListener("LayoutCompleted",r),o()}}else{const n=i.position.copy();i.centerRect(t.actualBounds),n.equalsApprox(i.position)&&e.stopAnimation()}}}jc(t,i){if(t.isVisible())return i;if(t instanceof Adornment){const e=t.adornedPart;e!==null&&this.jc(e,i)}else if(t instanceof Link){const e=t.fromNode;e!==null&&this.jc(e,i);const s=t.toNode;s!==null&&this.jc(s,i)}else{if(t instanceof Node){const s=t.labeledLink;s!==null&&this.jc(s,i);const n=t.findTreeParentNode();n!==null&&(!n.isTreeExpanded&&!n.wasTreeExpanded&&i.push(n),this.jc(n,i))}const e=t.containingGroup;e!==null&&(!e.isSubGraphExpanded&&!e.wasSubGraphExpanded&&i.push(e),this.jc(e,i))}return i}canScrollToPart(t){if(t===void 0&&(t=null),t!==null&&!(t instanceof Part))return!1;const i=this.diagram;return i.selection.count===0&&i.highlighteds.count===0?!1:i.allowHorizontalScroll&&i.allowVerticalScroll}collapseTree(t){t===void 0&&(t=null);const i=this.diagram,e="Collapse Tree";try{i.startTransaction(e),i.animationManager.Fl(e);const n=new List;if(t!==null&&t.isTreeExpanded)t.collapseTree(),n.add(t);else if(t===null){const o=i.selection.iterator;for(;o.next();){const r=o.value;r instanceof Node&&r.isTreeExpanded&&(r.collapseTree(),n.add(r))}}i.D("TreeCollapsed",n)}finally{i.commitTransaction(e)}}canCollapseTree(t){t===void 0&&(t=null);const i=this.diagram;if(i.isReadOnly)return!1;if(t!==null){if(!(t instanceof Node)||!t.isTreeExpanded)return!1;if(t.findTreeChildrenLinks().count>0)return!0}else{const e=i.selection.iterator;for(;e.next();){const s=e.value;if(s instanceof Node){if(!s.isTreeExpanded)continue;if(s.findTreeChildrenLinks().count>0)return!0}}}return!1}expandTree(t){t===void 0&&(t=null);const i=this.diagram,e="Expand Tree";try{i.startTransaction(e),i.animationManager.Fl(e);const n=new List;if(t!==null&&!t.isTreeExpanded)t.expandTree(),n.add(t);else if(t===null){const o=i.selection.iterator;for(;o.next();){const r=o.value;r instanceof Node&&(r.isTreeExpanded||(r.expandTree(),n.add(r)))}}i.D("TreeExpanded",n)}finally{i.commitTransaction(e)}}canExpandTree(t){t===void 0&&(t=null);const i=this.diagram;if(i.isReadOnly)return!1;if(t!==null){if(!(t instanceof Node)||t.isTreeExpanded)return!1;if(t.findTreeChildrenLinks().count>0)return!0}else{const e=i.selection.iterator;for(;e.next();){const s=e.value;if(s instanceof Node){if(s.isTreeExpanded)continue;if(s.findTreeChildrenLinks().count>0)return!0}}}return!1}groupSelection(){const t=this.diagram,i=t.model;if(!i.Hc())return;const e=this.archetypeGroupData;if(e===null)return;let s=null;try{t.currentCursor="wait",t.D("ChangingSelection",t.selection),t.startTransaction("Group");const n=new List,o=t.selection.iterator;for(;o.next();){const c=o.value;c.ke()&&c.canGroup()&&n.add(c)}const r=new List,l=n.iterator;for(;l.next();){const c=l.value;let a=!1;const f=n.iterator;for(;f.next();){const u=f.value;if(c.isMemberOf(u)){a=!0;break}}a||r.add(c)}const h=r.first();if(h!==null){let c=h.containingGroup;if(c!==null)for(;c!==null;){let a=!1;const f=r.iterator;for(;f.next();)if(!f.value.isMemberOf(c)){a=!0;break}if(a)c=c.containingGroup;else break}if(e instanceof Group)e.Et(),s=e.copy(),s!==null&&t.add(s);else if(i.isGroupForData(e)){const a=i.copyNodeData(e);U.G(a)&&(i.addNodeData(a),s=t.findNodeForData(a))}if(s!==null){c!==null&&this.isValidMember(c,s)&&(s.containingGroup=c);const a=r.iterator;for(;a.next();){const f=a.value;this.isValidMember(s,f)&&(f.containingGroup=s)}t.clearSelection(!0),s.isSelected=!0}}t.D("SelectionGrouped",s)}finally{t.commitTransaction("Group"),t.D("ChangedSelection",t.selection),t.currentCursor=""}}canGroupSelection(){const t=this.diagram;if(t.isReadOnly||t.isModelReadOnly||!t.allowInsert||!t.allowGroup||!t.model.Hc()||this.archetypeGroupData===null)return!1;const e=t.selection.iterator;for(;e.next();){const s=e.value;if(s.ke()&&s.canGroup())return!0}return!1}m2(t){const i=U.et();if(Array.isArray(t))t.forEach(n=>{n instanceof Link||n instanceof Part&&i.push(n)});else{const n=t.iterator;for(;n.next();){const o=n.value;o instanceof Link||o instanceof Part&&i.push(o)}}const e=new GSet,s=i.length;for(let n=0;n0){i.clearSelection(!0);const o=s.iterator;for(;o.next();){const r=o.value;r.expandSubGraph();const l=r.containingGroup,h=l!==null&&l.data!==null?e.getKeyForNodeData(l.data):void 0;n.addAll(r.memberParts);const c=n.iterator;for(;c.next();){const a=c.value;if(a.isSelected=!0,a instanceof Link)continue;const f=a.data;f!==null?e.setGroupForData(f,h):a.containingGroup=l}i.remove(r)}}i.D("SelectionUngrouped",s,n)}finally{i.commitTransaction("Ungroup"),i.D("ChangedSelection",i.selection),i.currentCursor=""}}canUngroupSelection(t){t===void 0&&(t=null);const i=this.diagram;if(i.isReadOnly||i.isModelReadOnly||!i.allowDelete||!i.allowUngroup||!i.model.Hc())return!1;if(t!==null){if(!(t instanceof Group))return!1;if(t.canUngroup())return!0}else{const s=i.selection.iterator;for(;s.next();){const n=s.value;if(n instanceof Group&&n.canUngroup())return!0}}return!1}addTopLevelParts(t,i){const e=this.m2(t);let s=!0;const n=e.iterator;for(;n.next();){const o=n.value;o.containingGroup!==null&&(!i||this.isValidMember(null,o)?o.containingGroup=null:s=!1)}return s}collapseSubGraph(t){t===void 0&&(t=null);const i=this.diagram,e="Collapse SubGraph";try{i.startTransaction(e),i.animationManager.Fl(e);const n=new List;if(t!==null&&t.isSubGraphExpanded)t.collapseSubGraph(),n.add(t);else if(t===null){const o=i.selection.iterator;for(;o.next();){const r=o.value;r instanceof Group&&r.isSubGraphExpanded&&(r.collapseSubGraph(),n.add(r))}}i.D("SubGraphCollapsed",n)}finally{i.commitTransaction(e)}}canCollapseSubGraph(t){t===void 0&&(t=null);const i=this.diagram;if(i.isReadOnly)return!1;if(t!==null)return!(!(t instanceof Group)||!t.isSubGraphExpanded);{const e=i.selection.iterator;for(;e.next();){const s=e.value;if(s instanceof Group&&s.isSubGraphExpanded)return!0}}return!1}expandSubGraph(t){t===void 0&&(t=null);const i=this.diagram,e="Expand SubGraph",s=new List;try{if(i.startTransaction(e),i.animationManager.Fl(e),t!==null&&!t.isSubGraphExpanded)t.expandSubGraph(),s.add(t);else if(t===null){const o=i.selection.iterator;for(;o.next();){const r=o.value;r instanceof Group&&(r.isSubGraphExpanded||(r.expandSubGraph(),s.add(r)))}}i.D("SubGraphExpanded",s)}finally{for(const n of s)this.mA(i,n);t&&this.mA(i,t),i.commitTransaction(e)}}mA(t,i){for(const e of i.memberParts)e instanceof Node&&t.Cc(e,i)}canExpandSubGraph(t){t===void 0&&(t=null);const i=this.diagram;if(i.isReadOnly)return!1;if(t!==null)return!(!(t instanceof Group)||t.isSubGraphExpanded);{const e=i.selection.iterator;for(;e.next();){const s=e.value;if(s instanceof Group&&!s.isSubGraphExpanded)return!0}}return!1}editTextBlock(t){t===void 0&&(t=null);const i=this.diagram,e=i.toolManager.findTool("TextEditing");if(e!==null){if(t===null){let s=null;const n=i.selection.iterator;for(;n.next();){const o=n.value;if(o.canEdit()){s=o;break}}if(s===null)return;t=s.findInVisualTree(o=>o instanceof TextBlock&&o.editable)}t!==null&&(i.currentTool=null,e.textBlock=t,i.currentTool=e)}}canEditTextBlock(t){t===void 0&&(t=null);const i=this.diagram;if(i.isReadOnly||i.isModelReadOnly||!i.allowTextEdit||i.toolManager.findTool("TextEditing")===null)return!1;if(t!==null){if(!(t instanceof TextBlock))return!1;const e=t.part;if(e!==null&&e.canEdit())return!0}else{const e=i.selection.iterator;for(;e.next();){const s=e.value;if(s.canEdit()&&(t=s.findInVisualTree(n=>n instanceof TextBlock&&n.editable),t!==null))return!0}}return!1}showContextMenu(t){const i=this.diagram,e=i.toolManager.findTool("ContextMenu");if(e===null)return;t===void 0&&(t=null),t===null&&(i.selection.count>0?t=i.selection.first():t=i);const s=e.findObjectWithContextMenu(t);if(s!==null){const n=i.lastInput;let o=null;if(s instanceof GraphObject)o=s.getDocumentPoint(Spot.Center);else if(!i.viewportBounds.containsPoint(n.documentPoint)){const r=i.viewportBounds;o=new Point(r.x+r.width/2,r.y+r.height/2)}if(o!==null){const r=new InputEvent;r.diagram=i,r.viewPoint=i.transformDocToView(o),r.documentPoint=o,r.button=2,r.up=!0,i.lastInput=r}i.currentTool=e,e.openMenu(!1,s)}}canShowContextMenu(t){const i=this.diagram,e=i.toolManager.findTool("ContextMenu");return!(e===null||(t===void 0&&(t=null),t===null&&(i.selection.count>0?t=i.selection.first():t=i),e.findObjectWithContextMenu(t)===null))}get copiesClipboardData(){return this.e2}set copiesClipboardData(t){U.s(t,"boolean",CommandHandler,"copiesClipboardData"),this.e2=t}get copiesConnectedLinks(){return this.s2}set copiesConnectedLinks(t){U.s(t,"boolean",CommandHandler,"copiesConnectedLinks"),this.s2=t}get deletesConnectedLinks(){return this.o2}set deletesConnectedLinks(t){U.s(t,"boolean",CommandHandler,"deletesConnectedLinks"),this.o2=t}get copiesTree(){return this.l2}set copiesTree(t){U.s(t,"boolean",CommandHandler,"copiesTree"),this.l2=t}get deletesTree(){return this.h2}set deletesTree(t){U.s(t,"boolean",CommandHandler,"deletesTree"),this.h2=t}get copiesParentKey(){return this.a2}set copiesParentKey(t){U.s(t,"boolean",CommandHandler,"copiesParentKey"),this.a2=t}get copiesGroupKey(){return this.c2}set copiesGroupKey(t){U.s(t,"boolean",CommandHandler,"copiesGroupKey"),this.c2=t}get archetypeGroupData(){return this.f2}set archetypeGroupData(t){t!==null&&U.ec(t,CommandHandler,"archetypeGroupData");const i=this.diagram;this.f2=t}get memberValidation(){return this.nh}set memberValidation(t){t!==null&&U.k(t,CommandHandler,"memberValidation"),this.nh=t}get defaultScale(){return this.diagram.defaultScale}set defaultScale(t){this.diagram.defaultScale=t}get zoomFactor(){return this.u2}set zoomFactor(t){t>1||U.o("zoomFactor must be larger than 1.0, not: "+t),this.u2=t}get isZoomToFitRestoreEnabled(){return this.d2}set isZoomToFitRestoreEnabled(t){U.s(t,"boolean",CommandHandler,"isZoomToFitRestoreEnabled"),this.d2=t}get scrollToPartPause(){return this.g2}set scrollToPartPause(t){this.g2=t}computeEffectiveCollection(t,i){const e=this.diagram,s=e.toolManager.findTool("Dragging"),n=e.currentTool===s;i===void 0&&(i=e.o0());const o=new GMap;if(t===null)return o;let r=t.iterator;for(;r.next();){const l=r.value;e.Kr(o,l,n,i)}if(e.draggedLink!==null&&i.dragsLink)return o;for(r=t.iterator;r.next();){const l=r.value;if(l instanceof Link){const h=l.fromNode;if(h!==null&&!o.has(h))o.delete(l);else{const c=l.toNode;c!==null&&!o.has(c)&&o.delete(l)}}}return o}}var Stretch=(y=>(y[y.None=0]="None",y[y.Default=1]="Default",y[y.Vertical=4]="Vertical",y[y.Horizontal=5]="Horizontal",y[y.Fill=2]="Fill",y))(Stretch||{}),Orientation=(y=>(y[y.None=0]="None",y[y.Along=21]="Along",y[y.Plus90=22]="Plus90",y[y.Minus90=23]="Minus90",y[y.Opposite=24]="Opposite",y[y.Upright=25]="Upright",y[y.Plus90Upright=26]="Plus90Upright",y[y.Minus90Upright=27]="Minus90Upright",y[y.Upright45=28]="Upright45",y))(Orientation||{}),Flip=(y=>(y[y.None=0]="None",y[y.Vertical=1]="Vertical",y[y.Horizontal=2]="Horizontal",y[y.Both=3]="Both",y))(Flip||{});class GraphObject{n;f0;u0;Hr;p;lh;ct;at;se;$t;d0;Vs;Lt;is;qr;hh;wi;da;tt;Yt;Wr;Ni;zi;Ku;hi;ju;Ot;si;Jr;Ub;ah;Hu;constructor(){GSet.Ki(this),this.n=30723,this.$t=1,this.d0="",this.Vs=null,this.Lt=null,this.at=new Point(NaN,NaN).u(),this.is=Size.ww,this.qr=new Transform,this.hh=new Transform,this.wi=null,this.da=1,this.tt=1,this.Yt=0,this.Wr=Margin.Rg,this.se=new Rect(NaN,NaN,NaN,NaN).u(),this.Ni=new Rect(NaN,NaN,NaN,NaN).u(),this.zi=new Rect(0,0,NaN,NaN).u(),this.Ku=null,this.f0=null,this.ct=null,this.hi=Spot.Default,this.ju=Spot.Default,this.u0=0,this.Hr=0,this.Ot=null,this.p=null,this.lh=null,this.si=null,this.Ub=null,this.ah=null,this.Jr=null,this.Hu=null}cloneProtected(t){t.n=(this.n|2048|4096)&-32769,t.$t=this.$t,t.d0=this.d0,t.Lt=this.Lt,t.at.a(this.at),t.is=this.is.P(),this.wi!==null?t.wi=this.wi.copy():t.wi=null,t.tt=this.tt,t.Yt=this.Yt,t.Wr=this.Wr.P(),t.se.a(this.se),t.Ni.a(this.Ni),t.zi.a(this.zi),t.f0=this.f0,this.ct!==null&&(t.ct=this.ct.copy()),t.hi=this.hi.P(),t.ju=this.ju.P(),t.u0=this.u0,t.Hr=this.Hr,this.Ot!==null&&(t.Ot=this.Ot.copy()),this.p!==null&&(this.p.fi?t.p=this.p:t.p=this.p.copy()),this.lh!==null&&(t.lh=this.lh.slice()),this.si!==null&&(t.si=this.si.copy())}addCopyProperty(t){let i=this.lh;if(!Array.isArray(i))i=[],this.lh=i;else for(let e=0;e{d.data!==null&&d.p2()&&d.updateTargetBindings(i)})}}}}UF(t){this.Hu.delete(t)}Do(){if(this.diagram===null)return;if(this.findBindingPanel()===null&&this.Ci!==null){const i=this.diagram.model,e=this.Ci.iterator;for(;e.next();){const s=e.value;if(!s.isToTheme)continue;let n=null;const o=s.sourceName;s.isToObject&&(n=this.pA(o));let r=this;const l=s.targetId;l!==-1&&(r=this.g0(l),r===null)||(o==="/"?n=r.part:o==="."?n=r:o===".."&&(n=r.panel),s.updateTarget(r,n,void 0,i))}}}ba(t,i){const e=this.findBindingPanel();if(e!==null){const s=t.diagram,n=this.Ci.iterator;for(;n.next();){const o=n.value;let r=null;if(o.isToObject){if(r=o.yA(e,this),r===null)continue;o.updateSource(this,r,i,null)}else if(o.isToModel)s!==null&&!s.fe&&o.updateSource(this,s.model.modelData,i,e);else if(!o.isToTheme){const l=e.data;if(l===null)continue;s!==null&&!s.fe&&o.updateSource(this,l,i,e)}if(r===this){const l=o.targetId,h=e.g0(l);h!==null&&o.updateTarget(h,r,i,s?.model)}}}}g0(t){return this.Hn===t?this:null}pA(t){let i;return t===""?i=this:t==="/"?i=this:t==="."?i=this:t===".."?i=this:i=this.part.findObject(t),i}get Hn(){return this.p!==null?this.p.Hn:-1}set Hn(t){this.Hn!==t&&(this.p===null&&(this.p=new GraphObjectTemplateSettings),this.p.Hn=t)}get Ci(){return this.p!==null?this.p.Ci:null}set Ci(t){this.Ci!==t&&(this.p===null&&(this.p=new GraphObjectTemplateSettings),this.p.Ci=t)}get qn(){return this.p!==null?this.p.qn:null}set qn(t){this.qn!==t&&(this.p===null&&(this.p=new GraphObjectTemplateSettings),this.p.qn=t)}raiseChanged(t,i,e){this.raiseChangedEvent(2,t,this,i,e)}t(t,i,e){this.raiseChangedEvent(2,t,this,i,e)}Wn(t,i,e,s){const n=this.se;if(n.i(t,i,e,s),this.tt!==1||this.Yt!==0){this.wi===null&&(this.wi=new Transform);const o=this.wi;o.Ri(),this.m0(o,t,i,e,s),o.vg(n)}}wA(t,i,e){return this.pickable===!1?!1:(e.nc(this.T),i?this.intersectsRect(t,e):this.containedInRect(t,e))}xA(t,i,e){if(this.pickable===!1)return!1;const s=this.naturalBounds,n=t.distanceSquaredPoint(i);return e?Point.distanceLineSegmentSquared(t.x,t.y,0,0,0,s.height)<=n||Point.distanceLineSegmentSquared(t.x,t.y,0,s.height,s.width,s.height)<=n||Point.distanceLineSegmentSquared(t.x,t.y,s.width,s.height,s.width,0)<=n||Point.distanceLineSegmentSquared(t.x,t.y,s.width,0,0,0)<=n:t.distanceSquared(0,0)<=n&&t.distanceSquared(0,s.height)<=n&&t.distanceSquared(s.width,0)<=n&&t.distanceSquared(s.width,s.height)<=n}an(){return!0}containsPoint(t){const i=Point.l();i.a(t),this.T.gt(i);const e=this.actualBounds;if(!e.isReal())return Point.e(i),!1;const s=this.diagram;if(s!==null&&s.Hm){const o=s.getInputOption("extraTouchThreshold"),r=s.getInputOption("extraTouchArea"),l=r/2,h=this.naturalBounds,c=this.getDocumentScale()*s.scale,a=1/c;if(h.width*ce&&(f=t),isFinite(i)&&i>s&&(u=i);break;case 5:isFinite(t)&&t>e&&(f=t),u=0,d&&(i=1/0);break;case 4:isFinite(i)&&i>s&&(u=i),f=0,d&&(t=1/0);break}const g=this.maxSize,p=this.minSize;f>g.width&&p.widthg.height&&p.heightu.height||this.ui>u.width)&&(r=!0)}}}r?this.n|=256:this.n&=-257,this.Ni.isReal()||U.o("Non-real actualBounds has been set. Object "+this+", actualBounds: "+this.Ni.toString()),this.Ju(o,this.Ni),this.Jn(!1),Rect.e(o)}uh(t,i,e,s){}commonArrange(t,i,e,s){if(this.Ni.i(t,i,e,s),this.desiredSize.isReal())return;const n=this.se,o=this.Wr,r=o.right+o.left,l=o.top+o.bottom,h=n.width+r,c=n.height+l;e+=r,s+=l;let a=this.zs(!0);switch(h===e&&c===s&&(a=0),a){case 0:(h>e||c>s)&&(this.ue(!0),this.ht(h>e?e:h,c>s?s:c,0,0));break;case 2:this.ue(!0),this.ht(e,s,0,0);break;case 5:this.ue(!0),this.ht(e,c,0,0);break;case 4:this.ue(!0),this.ht(h,s,0,0);break}}Ju(t,i){const e=this.part;e!==null&&e.diagram!==null&&((e.selectionObject===this||e.resizeObject===this||e.rotateObject===this)&&e.w2(!0),this.S(),!t.equalsApproxClose(i)&&(e.dh(),this.x0(e)))}x0(t){this.portId!==null&&(t.w2(!0),t instanceof Node&&t.bA(this))}get shadowVisible(){return this.p!==null?this.p.b0:null}set shadowVisible(t){const i=this.shadowVisible;i!==t&&(this.Kt().b0=t,this.Ve(!0),this.S(),this.t("shadowVisible",i,t))}HR(t,i){const e=this.naturalBounds,s=this.hh,n=s.m11,o=s.m21,r=s.dx,l=s.m12,h=s.m22,c=s.dy;let a=0,f=0,u=a,d=f;a=u*n+d*o+r,f=u*l+d*h+c;let m=a,g=f,p=0,w=0;u=e.width+i,d=0,a=u*n+d*o+r,f=u*l+d*h+c;let x=Math.min(m,a),k=Math.min(g,f);p=Math.max(m+p,a)-x,w=Math.max(g+w,f)-k,m=x,g=k,u=e.width+i,d=e.height+i,a=u*n+d*o+r,f=u*l+d*h+c,x=Math.min(m,a),k=Math.min(g,f),p=Math.max(m+p,a)-x,w=Math.max(g+w,f)-k,m=x,g=k,u=0,d=e.height+i,a=u*n+d*o+r,f=u*l+d*h+c,x=Math.min(m,a),k=Math.min(g,f),p=Math.max(m+p,a)-x,w=Math.max(g+w,f)-k,m=x,g=k;const b=t.viewportBounds,P=b.x,S=b.y,L=b.width,C=b.height;return m>L+P||P>p+m||g>C+S||S>w+g}Ui(t,i){if(this.qR(t,i)||!this.visible)return;const e=this.opacity;if(e===0)return;let s=1;e!==1&&(s=t.globalAlpha,t.globalAlpha=s*e);let n="";this.filter!==""&&(n=t.filter,t.filter=this.filter);const o=this.T,r=this.panel;this.p0()===!0&&this.Bb();const l=this.part;let h=!1,c=0;if(l&&i.getRenderingHint("drawShadows")&&(h=l.isShadowed,h)){const g=l.shadowOffset;c=Math.max(g.y,g.x)*i.scale*i.Vi}const a=this instanceof Panel&&this.$r(),f=this.Ni;if(a&&(this.kA(h,t,!1,r),this.WR(t,i),this.PA(h,t,!1,r),this.SA(h,t,!1)),a||!a&&(f.width===0||f.height===0||isNaN(f.x)||isNaN(f.y))){e!==1&&(t.globalAlpha=s),this.filter!==""&&(t.filter=n);return}const u=this.Xs();if(!i.ia&&u&&this.HR(i,c)){e!==1&&(t.globalAlpha=s),this.filter!==""&&(t.filter=n);return}let d=(this.n&256)!==0;if(t.clipInsteadOfFill&&(d=!1),this instanceof TextBlock&&(t.font=this.font),d){const g=r.an()?r.naturalBounds:r.actualBounds;let p=Math.max(f.x,g.x),w=Math.max(f.y,g.y),x=Math.min(f.right,g.right)-p,k=Math.min(f.bottom,g.bottom)-w;const b=this.si;if(b!==null&&(p=b.x,w=b.y,x=b.width,k=b.height),p>f.width+f.x||f.x>g.width+g.x){e!==1&&(t.globalAlpha=s),this.filter!==""&&(t.filter=n);return}t.save(),t.beginPath(),t.rect(p,w,x,k),t.clip()}if(u){if(!l.isVisible()){e!==1&&(t.globalAlpha=s),this.filter!==""&&(t.filter=n);return}if(h){const g=l.shadowOffset;t.shadowsSet(g.x*i.scale*this.scale*i.Vi,g.y*i.scale*this.scale*i.Vi,l.shadowBlur),t.shadowsOn(),t.shadowColor=l.shadowColor}}const m=this.naturalBounds;if(t.transform(o.m11,o.m12,o.m21,o.m22,o.dx,o.dy),this.kA(h,t,u,r),this.Lt!==null&&(t.commitTransform(),this.Vb(t,m,f)),this.PA(h,t,u,r),this.gh(t,i),this.SA(h,t,u),d&&(t.restore(),t.clearContextCache(this instanceof Panel)),!o.Yk()){const g=1/(o.m11*o.m22-o.m12*o.m21);t.transform(o.m22*g,-o.m12*g,-o.m21*g,o.m11*g,g*(o.m21*o.dy-o.m22*o.dx),g*(o.m12*o.dx-o.m11*o.dy))}e!==1&&(t.globalAlpha=s),this.filter!==""&&(t.filter=n)}kA(t,i,e,s){t&&this.shadowVisible===!0?i.shadowsOn():t&&this.shadowVisible===!1&&i.shadowsOff(),t&&this.zb(s)&&this.shadowVisible===null&&i.shadowsOff()}PA(t,i,e,s){t&&(this.Lt!==null||this.zb(s))?(this.Xb(!0),this.shadowVisible===null&&i.shadowsOff()):this.Xb(!1)}SA(t,i,e){t&&this.b2()===!0&&i.shadowsOn(),e&&t&&i.shadowsOff()}JR(t,i,e){const s=this.part;let n=!1;s&&t.getRenderingHint("drawShadows")&&(n=s.isShadowed),i.clipInsteadOfFill&&(n=!1),this.Xs()&&n&&i.shadowsOn(),n&&this.shadowVisible===!0?i.shadowsOn():n&&this.shadowVisible===!1&&i.shadowsOff();const o=this.panel;if(n&&this.zb(o)&&this.shadowVisible===null&&i.shadowsOff(),i.Zr){const r=t.computePixelRatio(),l=`drop-shadow(${i.shadowOffsetX/r}px ${i.shadowOffsetY/r}px ${i.shadowBlur/r/2}px ${i.shadowColor})`;this.background!==null&&e.Lt.setAttributeNS(null,"filter",l)}return n&&(this.Lt!==null||this.zb(o))?(this.Xb(!0),this.shadowVisible===null&&i.shadowsOff()):this.Xb(!1),n}$R(t,i,e,s){if(e.Zr){const n=i.computePixelRatio(),o=`drop-shadow(${e.shadowOffsetX/n}px ${e.shadowOffsetY/n}px ${e.shadowBlur/n/2}px ${e.shadowColor})`;this.k2(t,o)}s&&this.b2()===!0&&e.shadowsOn(),this.Xs()&&e.shadowsOff()}zb(t){return t===null?!1:(t.$r()&&(t=t.panel),t.b2()||(t.type===Panel.Auto||t.type===Panel.Spot)&&t.findMainElement()!==this)}k2(t,i){}Vb(t,i,e){const s=this.y0(),n=i.x,o=i.y,r=i.width+s,l=i.height+s;this.rn(t,this.Lt,!0,!1,i,e),this.Lt instanceof Brush&&this.Lt.type===3?(t.beginPath(),t.rect(n-s/2,o-s/2,r,l),t.fillContext(this.Lt,!1,null)):t.fillRect(n-s/2,o-s/2,r,l)}MA(t,i){let e=t.ZR(this);const s=t.ah!==null?t.ah:t.svg;if(e!==-1)if(e===0)if(s.Lt)s.Lt.after(i);else if(t.type===Panel.Table){const n=s.getElementsByClassName("gojs-ts"),o=n.length!==0?n[0]:null;o!==null&&o.after(i)}else s.prepend(i);else{for(;e!==0&&!t.elt(e-1).isVisibleObject();)e--;if(e===0)s.prepend(i);else{const n=t.elt(e-1).svg;n!==null?n.after(i):s.appendChild(i)}}}qR(t,i){if(!(t instanceof SVGContext))return!1;if(!this.visible||this.opacity===0)return this.svg!==null&&this.svg.parentNode!==null&&this.svg.remove(),!0;const e=this.Ni;if(this.Xs()&&(!this.isVisible()||e.width===0||e.height===0||isNaN(e.x)||isNaN(e.y)))return this.svg!==null&&this.svg.parentNode!==null&&this.svg.remove(),!0;const s=this.panel,n=this.$u(t);if(this.Zc(t,i,n))return this.NA(this.svg),this.svg.parentElement!==null?(this.Xs()&&(t.lastDrawnPart=this.svg),!0):(this.Xs()?(t.lastDrawnPart!==null?t.lastDrawnPart.after(this.svg):t.diagramGroup.prepend(this.svg),t.lastDrawnPart=this.svg):s&&this.MA(s,this.svg),!0);if(this.Ve(!1),this.Xs()&&this.isShadowed){const m=this.shadowOffset;t.shadowsSet(m.x*i.scale*this.scale*i.Vi,m.y*i.scale*this.scale*i.Vi,this.shadowBlur),t.shadowsOn(),t.shadowColor=this.shadowColor}this instanceof TextBlock&&(t.font=this.font),t.currentElement=null;const o=this.T,r=this instanceof Panel,l=this instanceof Panel?this.$r():!1,h=this.svg;if(this.p0()===!0&&this.Bb(),t.setCurrentTransform(1,0,0,1,0,0),t.outerGroup=!1,n)if(t.outerGroup=!0,r&&l)t.newGroup(1,0,0,1,0,0),this.svg=t.lastCreatedElement;else if(r&&this.isClipping){const m=this.findMainElement();let g=0,p=0;m!==null&&(g=m.actualBounds.x,p=m.actualBounds.y),t.newGroup(o.m11,o.m12,o.m21,o.m22,o.dx+g,o.dy+p),this.svg=t.lastCreatedElement,m!==null&&t.createOrUpdateClipGroup(this,m.actualBounds),t.currentElement=t.lastCreatedElement}else r?(t.newGroup(o.m11,o.m12,o.m21,o.m22,o.dx,o.dy),this.svg=t.lastCreatedElement):t.newGroup(1,0,0,1,0,0);const c=this.naturalBounds;r||t.setCurrentTransform(o.m11,o.m12,o.m21,o.m22,o.dx,o.dy),this.background!==null&&(r?(l&&t.setCurrentTransform(o.m11,o.m12,o.m21,o.m22,o.dx,o.dy),this.Vb(t,c,e),l&&t.setCurrentTransform(1,0,0,1,0,0)):(t.setCurrentTransform(o.m11,o.m12,o.m21,o.m22,o.dx,o.dy),this.Vb(t,c,e)),t.currentElement.Lt=t.lastCreatedElement,t.currentElement.prepend(t.lastCreatedElement));const a=this.JR(i,t,t.currentElement);this.gh(t,i),r&&t.endGroup(),t.outerGroup&&t.endGroup();const f=t.surface.Gu,u=r?this.svg:t.currentElement;if(h!==null&&h.parentNode!==null&&u!==h&&h.parentNode===this.panel.svg){const m=this.svg.getAttribute("filter");return m!==null&&u.setAttribute("filter",m),this.filter!==""&&u.setAttributeNS(null,"filter",this.filter),h.replaceWith(u),this.svg=u,u!==null&&this.k0(t,s,e,u),!0}if(this.svg=u,f!==null&&u===null&&t.dummyGroup(),u===null)return!0;this.k0(t,s,e,u),this.$R(u,i,t,a);const d=this.Xs()?this.opacity*t.globalAlpha:this.opacity;if(d!==1&&u.setAttributeNS(null,"opacity",d.toString()),this.filter!==""&&u.setAttributeNS(null,"filter",this.filter),this.Xs()){if(h!==null&&u!==h&&h.parentNode===t.diagramGroup){const m=h.getAttribute("filter");m!==null&&u.setAttribute("filter",m),h.replaceWith(u)}else t.lastDrawnPart?t.lastDrawnPart.after(u):t.diagramGroup.prepend(u);t.lastDrawnPart=u}else s!==null&&this.MA(s,u);return f!==null&&f(this,u),this.NA(u),!0}NA(t){const i=this,e=t.dataset;i instanceof GraphObject&&(i.portId!==null&&(e.portId=i.portId),i instanceof Panel&&(isNaN(i.itemIndex)||(e.itemIndex=i.itemIndex.toString()),i instanceof Part&&(e.className=U.Dn(i),i.key!==void 0&&(e.key=i.key.toString()),i.containingGroup!==null&&(e.group=i.containingGroup.key.toString()),i instanceof Link&&(i.fromNode!==null&&i.fromNode.key!==void 0&&(e.fromKey=i.fromNode.key.toString()),i.fromPortId!==""&&(e.fromPortId=i.fromPortId),i.toNode!==null&&i.toNode.key!==void 0&&(e.toKey=i.toNode.key.toString()),i.toPortId!==""&&(e.toPortId=i.toPortId)))))}k0(t,i,e,s){let n=(this.n&256)!==0;if(t.clipInsteadOfFill&&(n=!1),!n){s.removeAttributeNS(null,"clip-path");return}const o=i.an()?i.naturalBounds:i.actualBounds;let r=Math.max(e.x,o.x),l=Math.max(e.y,o.y),h=Math.min(e.right,o.right)-r,c=Math.min(e.bottom,o.bottom)-l;const a=this.si;a!==null&&(r=a.x,l=a.y,h=a.width,c=a.height);const f=new Rect(r,l,Math.max(h,0),Math.max(c,0));this instanceof Panel&&this.T.copy().bw().vg(f),s.setAttributeNS(null,"clip-path",`path(' M ${f.x},${f.y} L ${f.width+f.x} ${f.y} L ${f.width+f.x} ${f.height+f.y} L ${f.x} ${f.height+f.y} z') view-box`)}QR(){if(this.svg===null)return;const t=this.svg.innerHTML.match(/url\(#((CLIP|GRAD).+?)\)/g),i=this.svg.ownerDocument;if(t!==null)for(const e of t){const s=i.getElementById(e.split("#")[1].slice(0,-1));s!==null&&s.remove()}this.svg.remove()}WR(t,i){const e=this.Ni,s=this.zi,n=this.Lt;n!==null&&t.commitTransform(),n!==null&&(this.rn(t,n,!0,!1,s,e),n instanceof Brush&&n.type===3?(t.beginPath(),t.rect(e.x,e.y,e.width,e.height),t.fillContext(n,!1,null)):t.fillRect(e.x,e.y,e.width,e.height)),this.gh(t,i)}gh(t,i){}Qc(){this.Ve(!0)}Zc(t,i,e){const s=this.svg;if(this._R()){if(this.Qc(),this.Ve(!1),s===null)return!1;const a=s.getAttribute("clip-path");if(a!==null&&a.includes("url")){const u=t.svg.getElementById(a.split("#")[1].slice(0,-1));u!==null&&u.remove()}return s.getAttribute("filter")&&s.removeAttribute("filter"),!1}if(s===null)return!1;if(!this.visible)return s.remove(),!1;if(s.nodeName!=="g"&&e||s.nodeName==="g"&&!e)return!1;const n=this.T,o="matrix("+n.m11+", "+n.m12+", "+n.m21+", "+n.m22+", "+n.dx+", "+n.dy+")",r=this instanceof Panel,l=r?this.$r():!1;if(!(r&&l))if(this instanceof Picture){const a=this.Yb;t.setCurrentTransform(n.m11,n.m12,n.m21,n.m22,n.dx,n.dy),a!==null&&t.amendImageTransform(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]),e?s.lastElementChild.setAttributeNS(null,"transform",t.getCurrentTransform()):s.setAttributeNS(null,"transform",t.getCurrentTransform())}else if(e&&!r)if(this instanceof Shape){const a=s.getElementsByTagName("path");for(let f=0;f=.1;){if(g){for(l=o[d++%h],l-=r;l<0;)l+=o[d++%h],m=!m;g=!1}else l=o[d++%h];l>u&&(l=u);let p=Math.sqrt(l*l/(1+f*f));c<0&&(p=-p),i+=p,e+=f*p,m?t.lineTo(i,e):t.moveTo(i,e),u-=l,m=!m}}rn(t,i,e,s,n,o){let r=1,l=1;if(typeof i=="string"){e?t.fillStyle=i:t.strokeStyle=i;return}else if(i.type===1){e?t.fillStyle=i.color:t.strokeStyle=i.color;return}let h;const c=this.y0();r=n.width,l=n.height,s?(r=o.width,l=o.height):e||(r+=c,l+=c);const a=t instanceof CanvasSurfaceContext;if(a&&i.cn&&(i.type===4||i._c===r&&i.Gb===l))h=i.cn;else{let f=0,u=0,d=0,m=0,g=0,p=0,w=0,x=0;if(s?(w=o.x,x=o.y):e||(w-=c/2,x-=c/2),f=i.start.x*r+i.start.offsetX+w,u=i.start.y*l+i.start.offsetY+x,d=i.end.x*r+i.end.offsetX+w,m=i.end.y*l+i.end.offsetY+x,i.type===2)h=t.createLinearGradient(f,u,d,m);else if(i.type===3)p=isNaN(i.endRadius)?Math.max(r,l)/2:i.endRadius,isNaN(i.startRadius)?(g=0,p=Math.max(r,l)/2):g=i.startRadius,h=t.createRadialGradient(f,u,g,d,m,p);else if(i.type===4)try{h=t.createPattern(i.pattern,"repeat")}catch{h=null}else U.Zi(i.type,"Brush type");if(i.type!==4){const k=i.colorStops;if(k!==null){const b=k.iterator;for(;b.next();)h.addColorStop(b.key,b.value)}}if(a&&(i.cn=h,h!==null&&(i._c=r,i.Gb=l),h===null&&i.type===4&&i._c!==-1)){i._c=-1;const k=this.diagram;k!==null&&i._c===-1&&U.ir(()=>{k.redraw()},600)}}e?t.fillStyle=h:t.strokeStyle=h}isContainedBy(t){return t instanceof Panel?this.tv(this,t):!1}tv(t,i){if(t===i||i===null)return!1;let e=t.panel;for(;e!==null;){if(e===i)return!0;e=e.panel}return!1}isVisibleObject(){if(!this.visible)return!1;const t=this.panel;return t!==null?t.isVisibleObject():!0}isEnabledObject(){let t=this instanceof Panel?this:this.panel;for(;t!==null&&t.isEnabled;)t=t.panel;return t===null}get enabledChanged(){return this.p!==null?this.p.P0:null}set enabledChanged(t){const i=this.enabledChanged;i!==t&&(t!==null&&U.k(t,GraphObject,"enabledChanged"),this.Kt().P0=t,this.t("enabledChanged",i,t))}Bb(){if(this.Kb()===!0){const t=this.qr;if(t.Ri(),!this.Ni.isReal()||!this.se.isReal()){this.Zu(!1);return}if(t.Fs(this.Ni.x-this.se.x,this.Ni.y-this.se.y),this.scale!==1||this.angle!==0){const i=this.naturalBounds;this.m0(t,i.x,i.y,i.width,i.height)}this.Zu(!1),this.ka(!0)}if(this.p0()===!0){const t=this.panel;if(t===null)this.hh.set(this.qr),this.da=this.scale;else if(t.Us!==null){const i=this.hh;i.Ri(),t.an()?i.nc(t.hh):t.panel!==null&&i.nc(t.panel.hh),i.nc(this.qr),this.da=this.scale*t.da}this.ka(!1)}}m0(t,i,e,s,n){if(this.tt!==1&&t.tt(this.tt),this.Yt===0)return;const o=Point.l();o.setSpot(i,e,s,n,Spot.Center),t.cs(this.Yt,o.x,o.y),Point.e(o)}c(t){if(this.To())return;t===void 0&&(t=!1),this.ue(!0),this.Jn(!0);const i=this.panel;i!==null&&!t&&i.c()}tf(){this.To()||(this.ue(!0),this.Jn(!0))}ef(t){if(this._e())return;const i=this.panel;!t&&i!==null&&i.c(),this.Jn(!0)}$c(){this.Kb()===!1&&(this.Zu(!0),this.ka(!0))}P2(){this.ka(!0)}S(){const t=this.part;t!==null&&t.S()}zs(t){const i=this.stretch,e=this.panel;if(e===null)return this.Oo(i===1?0:i,t);if(e.type===Panel.Table)return this.S0(e.getRowDefinition(this.row),e.getColumnDefinition(this.column),t);if(e.type===Panel.Auto&&e.findMainElement()===this)return this.Oo(2,t);if(i===1){if(e.type===Panel.Spot&&e.findMainElement()===this)return this.Oo(2,t);const s=e.defaultStretch;return s===1?this.Oo(0,t):this.Oo(s,t)}return this.Oo(i,t)}S0(t,i,e){const s=this.stretch;if(s!==1)return this.Oo(s,e);let n=null,o=null;switch(t.stretch){case 1:case 5:break;case 4:o=!0;break;case 2:o=!0;break}switch(i.stretch){case 1:case 4:break;case 5:n=!0;break;case 2:n=!0;break}const r=this.panel.defaultStretch;return n===null&&(n=r===5||r===2),o===null&&(o=r===4||r===2),n===!0&&o===!0?this.Oo(2,e):n===!0?this.Oo(5,e):o===!0?this.Oo(4,e):this.Oo(0,e)}Oo(t,i){if(i)return t;if(t===0)return 0;const e=this.desiredSize;if(e.isReal())return 0;const s=!isNaN(e.width),n=!isNaN(e.height),o=this.angle;if(s)if(o!==90&&o!==270){if(t===5)return 0;if(t===2)return 4}else{if(t===4)return 0;if(t===2)return 5}if(n)if(o!==90&&o!==270){if(t===4)return 0;if(t===2)return 5}else{if(t===5)return 0;if(t===2)return 4}return t}get segmentOrientation(){return this.Ot!==null?this.Ot.M0:0}set segmentOrientation(t){const i=this.segmentOrientation;i!==t&&(this.Ot===null&&(this.Ot=new LinkElementSettings),this.Ot.M0=t,this.c(),this.t("segmentOrientation",i,t),t===0&&(this.angle=0))}iv(){this.segmentOrientation=21}get segmentIndex(){return this.Ot!==null?this.Ot.N0:-1/0}set segmentIndex(t){t=Math.round(t);const i=this.segmentIndex;i!==t&&(this.Ot===null&&(this.Ot=new LinkElementSettings),this.Ot.N0=t,this.c(),this.t("segmentIndex",i,t))}get segmentFraction(){return this.Ot!==null?this.Ot.C0:0}set segmentFraction(t){t<0?t=0:t>1&&(t=1);const i=this.segmentFraction;i!==t&&(this.Ot===null&&(this.Ot=new LinkElementSettings),this.Ot.C0=t,this.c(),this.t("segmentFraction",i,t))}get segmentOffset(){return this.Ot!==null?this.Ot.L0:Point.xo}set segmentOffset(t){const i=this.segmentOffset;i.equals(t)||(t=t.P(),this.Ot===null&&(this.Ot=new LinkElementSettings),this.Ot.L0=t,this.c(),this.t("segmentOffset",i,t))}get stretch(){return this.p!==null?this.p.$n:1}set stretch(t){const i=this.stretch;i!==t&&(this.Kt().$n=t,this.c(),this.t("stretch",i,t))}get name(){return this.p!==null?this.p.St:""}set name(t){const i=this.name;i!==t&&(this.Kt().St=t,this.part!==null&&this.part.A0(),this.t("name",i,t))}get opacity(){return this.$t}set opacity(t){t<0?t=0:t>1&&(t=1);const i=this.opacity;if(i!==t){this.$t=t,this.t("opacity",i,t);const e=this.diagram,s=this.part;e!==null&&s!==null&&e.S(s.Wh(s.actualBounds))}}get filter(){return this.d0}set filter(t){const i=this.filter;if(i!==t){this.d0=t,this.Ve(!0),this.t("filter",i,t);const e=this.diagram,s=this.part;e!==null&&s!==null&&e.S(s.Wh(s.actualBounds))}}get visible(){return(this.n&1)!==0}set visible(t){const i=(this.n&1)!==0;if(i!==t){this.n=this.n^1,this.Qc(),this.t("visible",i,t);const e=this.panel;e!==null?e.c():this.Xs()&&this.Ei(t),this.S(),this.CA()}}get pickable(){return(this.n&2)!==0}set pickable(t){const i=(this.n&2)!==0;i!==t&&(this.n=this.n^2,this.t("pickable",i,t))}get fromLinkableDuplicates(){return(this.n&4)!==0}set fromLinkableDuplicates(t){const i=(this.n&4)!==0;i!==t&&(this.n=this.n^4,this.t("fromLinkableDuplicates",i,t))}get fromLinkableSelfNode(){return(this.n&8)!==0}set fromLinkableSelfNode(t){const i=(this.n&8)!==0;i!==t&&(this.n=this.n^8,this.t("fromLinkableSelfNode",i,t))}get toLinkableDuplicates(){return(this.n&16)!==0}set toLinkableDuplicates(t){const i=(this.n&16)!==0;i!==t&&(this.n=this.n^16,this.t("toLinkableDuplicates",i,t))}get toLinkableSelfNode(){return(this.n&32)!==0}set toLinkableSelfNode(t){const i=(this.n&32)!==0;i!==t&&(this.n=this.n^32,this.t("toLinkableSelfNode",i,t))}get isPanelMain(){return(this.n&64)!==0}set isPanelMain(t){const i=(this.n&64)!==0;i!==t&&(this.n=this.n^64,this.c(),this.t("isPanelMain",i,t))}get isActionable(){return(this.n&128)!==0}set isActionable(t){const i=(this.n&128)!==0;i!==t&&(this.n=this.n^128,this.t("isActionable",i,t))}get background(){return this.Lt}set background(t){const i=this.background;i!==t&&(t!==null&&Brush.Qu(t,"GraphObject.background"),t instanceof Brush&&t.u(),this.Lt=t,this.S(),this.t("background",i,t))}b2(){return(this.n&512)!==0}Xb(t){t?this.n|=512:this.n&=-513}Wc(){return(this.n&1024)!==0}S2(t){t?this.n|=1024:this.n&=-1025}Kb(){return(this.n&2048)!==0}Zu(t){t?this.n|=2048:this.n&=-2049}p0(){return(this.n&4096)!==0}ka(t){t?this.n|=4096:this.n&=-4097}To(){return(this.n&8192)!==0}ue(t){t?this.n|=8192:this.n&=-8193}_e(){return(this.n&16384)!==0}Jn(t){t?this.n|=16384:this.n&=-16385}_R(){return(this.n&32768)!==0}Ve(t){t?this.n|=32768:this.n&=-32769}get part(){if(this.Xs())return this;if(this.Jr!==null)return this.Jr;let t=this;for(t=t.panel;t;){if(t instanceof Part)return this.Jr=t,t;t=t.panel}return null}get svg(){return this.Ub}set svg(t){this.Ub=t}Au(){this.svg=null}get panel(){return this.Vs}Pa(t){this.Vs=t,this.svg!==null&&this.svg.remove()}get layer(){const t=this.part;return t!==null?t.layer:null}get diagram(){const t=this.part;return t!==null?t.diagram:null}get position(){return this.at}set position(t){const i=t.x,e=t.y,s=this.position,n=s.x,o=s.y;n!==i&&(!isNaN(n)||!isNaN(i))||o!==e&&(!isNaN(o)||!isNaN(e))?(t=t.copy(),this.M2(t,n,o)&&this.t("position",new Point(n,o),t.copy())):this.N2()}N2(){}M2(t,i,e){return this.at=t,this.ef(),!0}bc(t,i,e){this.at.x===t&&this.at.y===i||(this.at.i(t,i),this.$c())}get actualBounds(){return this.Ni}get scale(){return this.tt}set scale(t){const i=this.scale;i!==t&&(t<=0&&U.o("GraphObject.scale for "+this+" must be greater than zero, not: "+t),this.tt=t,this.c(),this.t("scale",i,t))}get angle(){return this.Yt}set angle(t){const i=this.angle;if(i!==t){if(t=t%360,t<0&&(t+=360),i===t)return;this.Yt=t,this.CA(),this.c(),this.t("angle",i,t)}}get desiredSize(){return this.is}set desiredSize(t){const i=t.width,e=t.height,s=this.desiredSize,n=s.width,o=s.height;if((n!==i&&(!isNaN(n)||!isNaN(i))||o!==e&&(!isNaN(o)||!isNaN(e)))&&(t=t.P(),this.is=t,this.c(),this instanceof Shape&&this.ee(),this.t("desiredSize",s,t),this.Wc())){const r=this.part;r!==null&&(this.ba(r,"width"),this.ba(r,"height"))}}get width(){return this.is.width}set width(t){const i=this.is.width;if(i!==t&&(!isNaN(i)||!isNaN(t))){const e=this.is,s=new Size(t,this.is.height).u();if(this.is=s,this.c(),this instanceof Shape&&this.ee(),this.t("desiredSize",e,s),this.Wc()){const n=this.part;n!==null&&this.ba(n,"width")}}}get height(){return this.is.height}set height(t){const i=this.is.height;if(i!==t&&(!isNaN(i)||!isNaN(t))){const e=this.is,s=new Size(this.is.width,t).u();if(this.is=s,this.c(),this instanceof Shape&&this.ee(),this.t("desiredSize",e,s),this.Wc()){const n=this.part;n!==null&&this.ba(n,"height")}}}get minSize(){return this.p!==null?this.p.pr:Size.sc}set minSize(t){const i=this.minSize;i.equals(t)||(t=t.copy(),isNaN(t.width)&&(t.width=0),isNaN(t.height)&&(t.height=0),t.u(),this.Kt().pr=t,this.c(),this.t("minSize",i,t))}get maxSize(){return this.p!==null?this.p.yr:Size.Bk}set maxSize(t){const i=this.maxSize;i.equals(t)||(t=t.copy(),isNaN(t.width)&&(t.width=1/0),isNaN(t.height)&&(t.height=1/0),t.u(),this.Kt().yr=t,this.c(),this.t("maxSize",i,t))}get measuredBounds(){return this.se}get naturalBounds(){return this.zi}y0(){return 0}get margin(){return this.Wr}set margin(t){typeof t=="number"&&(t=new Margin(t));const i=this.Wr;i.equals(t)||(t=t.P(),this.Wr=t,this.c(),this.t("margin",i,t))}get T(){return this.Kb()===!0&&this.Bb(),this.qr}get Us(){return this.p0()===!0&&this.Bb(),this.hh}trigger(t,i,e){let s=null;return typeof t=="string"?s=new AnimationTrigger(t,i,e):s=t,s.be=this,this.ws===null&&(this.ws=new GMap),this.ws.set(s.propertyName,s),this}get ws(){return this.p!==null?this.p.ws:null}set ws(t){this.ws!==t&&(this.Kt().ws=t)}get gr(){return this.p!==null?this.p.gr:0}set gr(t){this.gr!==t&&(this.Kt().gr=t)}get alignment(){return this.hi}set alignment(t){const i=this.alignment;i.equals(t)||(t.isNoSpot()&&!t.isDefault()&&U.o("GraphObject.alignment for "+this+" must be a real Spot or Spot.Default, not: "+t),t=t.P(),this.hi=t,this.ef(),this.t("alignment",i,t))}get column(){return this.Hr}set column(t){t=Math.round(t);const i=this.column;i!==t&&(t<0&&U.W(t,">= 0",GraphObject,"column"),this.Hr=t,this.c(),this.t("column",i,t),this.svg!==null&&this.svg.remove())}get columnSpan(){return this.p!==null?this.p.T0:1}set columnSpan(t){t=Math.round(t);const i=this.columnSpan;i!==t&&(t<1&&U.W(t,">= 1",GraphObject,"columnSpan"),this.Kt().T0=t,this.c(),this.t("columnSpan",i,t))}get row(){return this.u0}set row(t){t=Math.round(t);const i=this.row;i!==t&&(t<0&&U.W(t,">= 0",GraphObject,"row"),this.u0=t,this.c(),this.t("row",i,t),this.svg!==null&&this.svg.remove())}get rowSpan(){return this.p!==null?this.p.D0:1}set rowSpan(t){t=Math.round(t);const i=this.rowSpan;i!==t&&(t<1&&U.W(t,">= 1",GraphObject,"rowSpan"),this.Kt().D0=t,this.c(),this.t("rowSpan",i,t))}get spanAllocation(){return this.p!==null?this.p.F0:null}set spanAllocation(t){const i=this.spanAllocation;i!==t&&(t!==null&&U.k(t,GraphObject,"spanAllocation"),this.Kt().F0=t,this.c(),this.t("spanAllocation",i,t))}get alignmentFocus(){return this.ju}set alignmentFocus(t){const i=this.alignmentFocus;i.equals(t)||(t=t.P(),this.ju=t,this.c(),this.t("alignmentFocus",i,t))}get portId(){return this.f0}set portId(t){const i=this.portId;if(i!==t){const e=this.part;e!==null&&!(e instanceof Node)&&U.o("Cannot set portID on a Link: "+t);const s=e;i!==null&&s!==null&&s.C2(this),this.f0=t,t!==null&&s!==null&&(s.fn=!0,s.LA(this)),this.t("portId",i,t)}}Sa(){const t=this.part;if(t instanceof Node&&(this.portId!==null||this===t.port)){const i=t.diagram;i!==null&&!i.undoManager.isUndoingRedoing&&t.bA(this)}}CA(){const t=this.diagram;t===null||t.undoManager.isUndoingRedoing||(this instanceof Panel?this instanceof Node?this.invalidateConnectedLinks():this.walkVisualTreeFrom(this,i=>{i.Sa()}):this.Sa())}get toSpot(){return this.ct!==null?this.ct.ma:Spot.None}set toSpot(t){const i=this.toSpot;i.equals(t)||(t=t.P(),this.Be().ma=t,this.t("toSpot",i,t),this.Sa())}get toEndSegmentLength(){return this.ct!==null?this.ct.ya:10}set toEndSegmentLength(t){const i=this.toEndSegmentLength;i!==t&&(t<0&&U.W(t,">= 0",GraphObject,"toEndSegmentLength"),this.Be().ya=t,this.t("toEndSegmentLength",i,t),this.Sa())}get toShortLength(){return this.ct!==null?this.ct.xa:0}set toShortLength(t){const i=this.toShortLength;i!==t&&(this.Be().xa=t,this.t("toShortLength",i,t),this.Sa())}get toLinkable(){return this.ct!==null?this.ct.R0:null}set toLinkable(t){const i=this.toLinkable;i!==t&&(this.Be().R0=t,this.t("toLinkable",i,t))}get toMaxLinks(){return this.ct!==null?this.ct.v0:1/0}set toMaxLinks(t){const i=this.toMaxLinks;i!==t&&(t<0&&U.W(t,">= 0",GraphObject,"toMaxLinks"),this.Be().v0=t,this.t("toMaxLinks",i,t))}get fromSpot(){return this.ct!==null?this.ct.ga:Spot.None}set fromSpot(t){const i=this.fromSpot;i.equals(t)||(t=t.P(),this.Be().ga=t,this.t("fromSpot",i,t),this.Sa())}get fromEndSegmentLength(){return this.ct!==null?this.ct.pa:10}set fromEndSegmentLength(t){const i=this.fromEndSegmentLength;i!==t&&(t<0&&U.W(t,">= 0",GraphObject,"fromEndSegmentLength"),this.Be().pa=t,this.t("fromEndSegmentLength",i,t),this.Sa())}get fromShortLength(){return this.ct!==null?this.ct.wa:0}set fromShortLength(t){const i=this.fromShortLength;i!==t&&(this.Be().wa=t,this.t("fromShortLength",i,t),this.Sa())}get fromLinkable(){return this.ct!==null?this.ct.O0:null}set fromLinkable(t){const i=this.fromLinkable;i!==t&&(this.Be().O0=t,this.t("fromLinkable",i,t))}get fromMaxLinks(){return this.ct!==null?this.ct.I0:1/0}set fromMaxLinks(t){const i=this.fromMaxLinks;i!==t&&(t<0&&U.W(t,">= 0",GraphObject,"fromMaxLinks"),this.Be().I0=t,this.t("fromMaxLinks",i,t))}get cursor(){return this.p!==null?this.p.Sl:""}set cursor(t){const i=this.cursor;i!==t&&(U.s(t,"string",GraphObject,"cursor"),this.Kt().Sl=t,this.t("cursor",i,t))}get click(){return this.p!==null?this.p.Cr:null}set click(t){const i=this.click;i!==t&&(t!==null&&U.k(t,GraphObject,"click"),this.Kt().Cr=t,this.t("click",i,t))}get doubleClick(){return this.p!==null?this.p.Lr:null}set doubleClick(t){const i=this.doubleClick;i!==t&&(t!==null&&U.k(t,GraphObject,"doubleClick"),this.Kt().Lr=t,this.t("doubleClick",i,t))}get contextClick(){return this.p!==null?this.p.Ar:null}set contextClick(t){const i=this.contextClick;i!==t&&(t!==null&&U.k(t,GraphObject,"contextClick"),this.Kt().Ar=t,this.t("contextClick",i,t))}get mouseEnter(){return this.p!==null?this.p.vr:null}set mouseEnter(t){const i=this.mouseEnter;i!==t&&(t!==null&&U.k(t,GraphObject,"mouseEnter"),this.Kt().vr=t,this.t("mouseEnter",i,t))}get mouseLeave(){return this.p!==null?this.p.Or:null}set mouseLeave(t){const i=this.mouseLeave;i!==t&&(t!==null&&U.k(t,GraphObject,"mouseLeave"),this.Kt().Or=t,this.t("mouseLeave",i,t))}get mouseOver(){return this.p!==null?this.p.Tr:null}set mouseOver(t){const i=this.mouseOver;i!==t&&(t!==null&&U.k(t,GraphObject,"mouseOver"),this.Kt().Tr=t,this.t("mouseOver",i,t))}get mouseHover(){return this.p!==null?this.p.Dr:null}set mouseHover(t){const i=this.mouseHover;i!==t&&(t!==null&&U.k(t,GraphObject,"mouseHover"),this.Kt().Dr=t,this.t("mouseHover",i,t))}get mouseHold(){return this.p!==null?this.p.Fr:null}set mouseHold(t){const i=this.mouseHold;i!==t&&(t!==null&&U.k(t,GraphObject,"mouseHold"),this.Kt().Fr=t,this.t("mouseHold",i,t))}get mouseDragEnter(){return this.p!==null?this.p.E0:null}set mouseDragEnter(t){const i=this.mouseDragEnter;i!==t&&(t!==null&&U.k(t,GraphObject,"mouseDragEnter"),this.Kt().E0=t,this.t("mouseDragEnter",i,t))}get mouseDragLeave(){return this.p!==null?this.p.U0:null}set mouseDragLeave(t){const i=this.mouseDragLeave;i!==t&&(t!==null&&U.k(t,GraphObject,"mouseDragLeave"),this.Kt().U0=t,this.t("mouseDragLeave",i,t))}get mouseDrop(){return this.p!==null?this.p.Rr:null}set mouseDrop(t){const i=this.mouseDrop;i!==t&&(t!==null&&U.k(t,GraphObject,"mouseDrop"),this.Kt().Rr=t,this.t("mouseDrop",i,t))}get actionDown(){return this.p!==null?this.p.B0:null}set actionDown(t){const i=this.actionDown;i!==t&&(t!==null&&U.k(t,GraphObject,"actionDown"),this.Kt().B0=t,this.t("actionDown",i,t))}get actionMove(){return this.p!==null?this.p.V0:null}set actionMove(t){const i=this.actionMove;i!==t&&(t!==null&&U.k(t,GraphObject,"actionMove"),this.Kt().V0=t,this.t("actionMove",i,t))}get actionUp(){return this.p!==null?this.p.z0:null}set actionUp(t){const i=this.actionUp;i!==t&&(t!==null&&U.k(t,GraphObject,"actionUp"),this.Kt().z0=t,this.t("actionUp",i,t))}get actionCancel(){return this.p!==null?this.p.X0:null}set actionCancel(t){const i=this.actionCancel;i!==t&&(t!==null&&U.k(t,GraphObject,"actionCancel"),this.Kt().X0=t,this.t("actionCancel",i,t))}get toolTip(){return this.p!==null?this.p.Ir:null}set toolTip(t){const i=this.toolTip;i!==t&&(this.Kt().Ir=t,this.t("toolTip",i,t))}get contextMenu(){return this.p!==null?this.p.Er:null}set contextMenu(t){const i=this.contextMenu;i!==t&&(this.Kt().Er=t,this.t("contextMenu",i,t))}findBindingPanel(){let t=this instanceof Panel?this:this.panel;for(;t!==null;){if(t.L2())return t;t=t.panel}return null}bind(t,i,e,s){return this.sf(t,i,e,s),this}bindTwoWay(t,i,e,s){return this.sf(t,i,e,s).makeTwoWay(),this}bindModel(t,i,e,s){return this.sf(t,i,e,s).ofModel(),this}bindObject(t,i,e,s,n){return this.sf(t,i,e,s).ofObject(n),this}theme(t,i,e,s,n){return this.mh(t,i,e,s,n),this}themeData(t,i,e,s,n){return this.mh(t,i,e,s,n).ofData(),this}themeObject(t,i,e,s,n,o){return this.mh(t,i,e,s,n).ofObject(o),this}themeModel(t,i,e,s,n){return this.mh(t,i,e,s,n).ofModel(),this}sf(t,i,e,s){let n=null;return typeof t=="string"?n=new Binding(t,i,e,s):n=t,this.Y0(n),n}mh(t,i,e,s,n){let o=null;return typeof t=="string"?o=new ThemeBinding(t,i,e,s,n):o=t,this.Y0(o),o}Y0(t){t.be=this;const i=this.findBindingPanel();i!==null&&i.AA()&&U.o("Cannot add a Binding to a template that has already been copied: "+t),this.Ci===null&&(this.Ci=new List),this.Ci.add(t)}set(t){return Object.assign(this,t),this}attach(t){return GraphObject.A2(this,t),this}apply(t){return t(this),this}setProperties(t){return Diagram.s0(this,t),this}static make(t,...i){let e=arguments,s=null,n=null;if(U.it(t))n=t;else if(typeof t=="string"){const r=GraphObject.jb.get(t);U.it(r)?(e=Array.prototype.slice.call(e),s=r(e),U.G(s)||U.o('GraphObject.make invoked object builder "'+t+'", but it did not return an Object')):n=root.go[t]}s===null&&((n==null||!n.constructor)&&U.o("GraphObject.make requires a class function or GoJS class name or name of an object builder, not: "+t),s=new n);let o=1;if(s instanceof Diagram&&e.length>1){const r=s,l=e[1];(typeof l=="string"||l instanceof HTMLDivElement)&&(r.AM(l),o++)}for(let r=o;r{const t="#f5f5f5",i="#737373",e="#d4d4d4",s="#737373",n="#a3a3a3",o=2.76142374915397,r=2.761423749153969,l=new Panel(Panel.Auto,{isActionable:!0,enabledChanged:(h,c)=>{if(h instanceof Panel){const a=h.findObject("ButtonBorder");if(a!==null)if(h._buttonFillNormal===void 0&&(h._buttonFillNormal=a.fill),c){let f=null;h.layer!==null&&h.diagram!==null&&h.isVisibleObject()&&(f=h.layer.findObjectAt(h.diagram.lastInput.documentPoint)),f===h||f!==null&&f.isContainedBy(h)?a.fill=h._buttonFillOver:a.fill=h._buttonFillNormal}else a.fill=h._buttonFillDisabled}},cursor:"pointer"}).attach({_buttonFillNormal:void 0,_buttonStrokeNormal:void 0,_buttonFillOver:e,_buttonStrokeOver:s,_buttonFillDisabled:n}).add(new Shape("RoundedRectangle",{name:"ButtonBorder",spot1:new Spot(0,0,o,r),spot2:new Spot(1,1,-o,-r),parameter1:2,fill:t,stroke:i}));return l.mouseEnter=(h,c,a)=>{if(!c.isEnabledObject()||!(c instanceof Panel))return;const f=c.findObject("ButtonBorder");f instanceof Shape&&(c._buttonFillNormal===void 0&&(c._buttonFillNormal=f.fill),f.fill=c._buttonFillOver,c._buttonStrokeNormal===void 0&&(c._buttonStrokeNormal=f.stroke),f.stroke=c._buttonStrokeOver)},l.mouseLeave=(h,c,a)=>{if(!c.isEnabledObject()||!(c instanceof Panel))return;const f=c.findObject("ButtonBorder");f instanceof Shape&&(c._buttonFillNormal!==void 0&&(f.fill=c._buttonFillNormal),c._buttonStrokeNormal!==void 0&&(f.stroke=c._buttonStrokeNormal))},l}),GraphObject.defineBuilder("TreeExpanderButton",y=>{const t=GraphObject.build("Button");return t.attach({_treeExpandedFigure:"MinusLine",_treeCollapsedFigure:"PlusLine",visible:!1}),t.add(new Shape("MinusLine",{name:"ButtonIcon",stroke:"#0a0a0a",strokeWidth:2,desiredSize:Size.nu}).bindObject("figure","isTreeExpanded",(i,e)=>{const s=e.panel;return i?s._treeExpandedFigure:s._treeCollapsedFigure})),t.bindObject("visible","isTreeLeaf",i=>!i),t.click=(i,e)=>{let s=e.part;if(s instanceof Adornment&&(s=s.adornedPart),!(s instanceof Node))return;const n=s.diagram;if(n===null)return;const o=n.commandHandler;if(s.isTreeExpanded){if(!o.canCollapseTree(s))return}else if(!o.canExpandTree(s))return;i.handled=!0,s.isTreeExpanded?o.collapseTree(s):o.expandTree(s)},t}),GraphObject.defineBuilder("SubGraphExpanderButton",y=>{const t=GraphObject.build("Button");return t.attach({_subGraphExpandedFigure:"MinusLine",_subGraphCollapsedFigure:"PlusLine"}),t.add(new Shape("MinusLine",{name:"ButtonIcon",stroke:"#0a0a0a",strokeWidth:2,desiredSize:Size.nu}).bindObject("figure","isSubGraphExpanded",(i,e)=>{const s=e.panel;return i?s._subGraphExpandedFigure:s._subGraphCollapsedFigure})),t.click=(i,e)=>{let s=e.part;if(s instanceof Adornment&&(s=s.adornedPart),!(s instanceof Group))return;const n=s.diagram;if(n===null)return;const o=n.commandHandler;if(s.isSubGraphExpanded){if(!o.canCollapseSubGraph(s))return}else if(!o.canExpandSubGraph(s))return;i.handled=!0,s.isSubGraphExpanded?o.collapseSubGraph(s):o.expandSubGraph(s)},t}),GraphObject.defineBuilder("ToolTip",y=>new Adornment(Panel.Auto,{isShadowed:!0,shadowColor:"rgba(0, 0, 0, .4)",shadowOffset:new Point(0,2)}).add(new Shape("RoundedRectangle",{name:"Border",parameter1:1,fill:"#f5f5f5",strokeWidth:0,spot1:new Spot(0,0,4,6),spot2:new Spot(1,1,-4,-4)}))),GraphObject.defineBuilder("ContextMenu",y=>new Adornment(Panel.Vertical,{background:"#f5f5f5",isShadowed:!0,shadowColor:"rgba(0, 0, 0, .4)",shadowOffset:new Point(0,2)}).bindObject("background","",t=>t.adornedPart!==null&&t.hasPlaceholder()?null:"#f5f5f5")),GraphObject.defineBuilder("ContextMenuButton",y=>{const t=GraphObject.build("Button");t.stretch=5;const i=t.findObject("ButtonBorder");return i instanceof Shape&&(i.figure="Rectangle",i.strokeWidth=0,i.spot1=new Spot(0,0,4,6),i.spot2=new Spot(1,1,-4,-4)),t}),GraphObject.defineBuilder("PanelExpanderButton",y=>{const t=GraphObject.takeBuilderArgument(y,"COLLAPSIBLE"),i=GraphObject.build("Button");i.attach({_buttonExpandedFigure:"M0 0 M0 6 L4 2 8 6 M8 8",_buttonCollapsedFigure:"M0 0 M0 2 L4 6 8 2 M8 8","ButtonBorder.fill":"rgba(0, 0, 0, 0)",_buttonFillNormal:"rgba(0, 0, 0, 0)","ButtonBorder.stroke":null,_buttonStrokeNormal:null,_buttonFillOver:"rgba(0, 0, 0, .2)",_buttonStrokeOver:null}),i.add(new Shape({name:"ButtonIcon",strokeWidth:2}).bindObject("geometryString","visible",s=>s?i._buttonExpandedFigure:i._buttonCollapsedFigure,void 0,t));const e=i.findObject("ButtonBorder");return e instanceof Shape&&(e.stroke=null,e.fill="rgba(0, 0, 0, 0)"),i.click=(s,n)=>{if(!(n instanceof Panel))return;const o=n.diagram;if(o===null||o.isReadOnly)return;let r=n.findBindingPanel();if(r===null&&(r=n.part),r!==null){const l=r.findObject(t);l!==null&&(s.handled=!0,o.startTransaction("Collapse/Expand Panel"),l.visible=!l.visible,o.commitTransaction("Collapse/Expand Panel"))}},i}),GraphObject.defineBuilder("CheckBoxButton",y=>{const t=GraphObject.takeBuilderArgument(y),i=GraphObject.build("Button",{desiredSize:new Size(14,14)});i.attach({"ButtonBorder.spot1":new Spot(0,0,1,1),"ButtonBorder.spot2":new Spot(1,1,-1,-1)});const e=new Shape({name:"ButtonIcon",geometryString:"M0 0 M0 8.85 L4.9 13.75 16.2 2.45 M16.2 16.2",strokeWidth:2,stretch:2,geometryStretch:6,visible:!1});return t!==""&&e.bindTwoWay("visible",t),i.add(e),i.click=(s,n)=>{if(!(n instanceof Panel))return;const o=s.diagram;if(o===null||o.isReadOnly||t!==""&&o.model.isReadOnly)return;s.handled=!0;const r=n.findObject("ButtonIcon");o.startTransaction("checkbox"),r!==null&&(r.visible=!r.visible),U.it(n._doClick)&&n._doClick(s,n),o.commitTransaction("checkbox")},i}),GraphObject.defineBuilder("CheckBox",y=>{const t=GraphObject.takeBuilderArgument(y),i=GraphObject.build("CheckBoxButton",{name:"Button",isActionable:!1,margin:new Margin(0,1,0,0)},t),e=new Panel("Horizontal",{isActionable:!0,cursor:i.cursor,margin:new Margin(1),mouseEnter:i.mouseEnter,mouseLeave:i.mouseLeave,click:i.click}).attach({_buttonFillNormal:i._buttonFillNormal,_buttonStrokeNormal:i._buttonStrokeNormal,_buttonFillOver:i._buttonFillOver,_buttonStrokeOver:i._buttonStrokeOver,_buttonFillDisabled:i._buttonFillDisabled,_buttonClick:i.click});return e.add(i),i.mouseEnter=null,i.mouseLeave=null,i.click=null,e});class GraphObjectTemplateSettings{fi;St;Hn;Ci;qn;Ys;Sl;Cr;Lr;Ar;vr;Or;Tr;Dr;Fr;E0;U0;Rr;B0;V0;z0;X0;Ir;Er;P0;F0;ws;pr;yr;$n;D0;T0;gr;b0;G0;K0;constructor(){this.fi=!1,this.St="",this.Hn=-1,this.Ci=null,this.qn=null,this.Ys=null,this.Sl="",this.Cr=null,this.Lr=null,this.Ar=null,this.vr=null,this.Or=null,this.Tr=null,this.Dr=null,this.Fr=null,this.E0=null,this.U0=null,this.Rr=null,this.B0=null,this.V0=null,this.z0=null,this.X0=null,this.Ir=null,this.Er=null,this.P0=null,this.F0=null,this.ws=null,this.pr=Size.sc,this.yr=Size.Bk,this.$n=1,this.D0=1,this.T0=1,this.gr=0,this.b0=null,this.G0=null,this.K0="category"}copy(){const t=new GraphObjectTemplateSettings;return t.St=this.St,t.Hn=this.Hn,t.Ci=this.Ci,t.Ys=this.Ys,t.Sl=this.Sl,t.Cr=this.Cr,t.Lr=this.Lr,t.Ar=this.Ar,t.vr=this.vr,t.Or=this.Or,t.Tr=this.Tr,t.Dr=this.Dr,t.Fr=this.Fr,t.E0=this.E0,t.U0=this.U0,t.Rr=this.Rr,t.B0=this.B0,t.V0=this.V0,t.z0=this.z0,t.X0=this.X0,t.Ir=this.Ir,t.Er=this.Er,t.P0=this.P0,t.F0=this.F0,t.ws=this.ws,t.pr=this.pr.P(),t.yr=this.yr.P(),t.$n=this.$n,t.D0=this.D0,t.T0=this.T0,t.gr=this.gr,t.b0=this.b0,t.G0=this.G0,t.K0=this.K0,t}}class STransform{m;constructor(){this.m=[1,0,0,1,0,0]}copy(){const t=new STransform;return t.m[0]=this.m[0],t.m[1]=this.m[1],t.m[2]=this.m[2],t.m[3]=this.m[3],t.m[4]=this.m[4],t.m[5]=this.m[5],t}translate(t,i){this.m[4]+=this.m[0]*t+this.m[2]*i,this.m[5]+=this.m[1]*t+this.m[3]*i}scale(t,i){this.m[0]*=t,this.m[1]*=t,this.m[2]*=i,this.m[3]*=i}rotate(t,i,e){if(t>=360?t-=360:t<0&&(t+=360),t===0)return;this.translate(i,e);let s=0,n=0;if(t===90)s=0,n=1;else if(t===180)s=-1,n=0;else if(t===270)s=0,n=-1;else{const c=t*Math.PI/180;s=Math.cos(c),n=Math.sin(c)}const o=this.m[0]*s+this.m[2]*n,r=this.m[1]*s+this.m[3]*n,l=this.m[0]*-n+this.m[2]*s,h=this.m[1]*-n+this.m[3]*s;this.m[0]=o,this.m[1]=r,this.m[2]=l,this.m[3]=h,this.translate(-i,-e)}}class SGradient{type;x1;y1;r1;x2;y2;r2;colors;pattern;constructor(t){this.type=t,this.x1=0,this.y1=0,this.r1=0,this.x2=0,this.y2=0,this.r2=0,this.colors=[],this.pattern=null}addColorStop(t,i){this.colors.push({offset:t,color:i})}}class SVGSurface{Tt;li;jr;Gu;T2;constructor(t,i,e){const s=i===void 0?root.document:i;this.jr=s,this.T2="http://www.w3.org/2000/svg";const n="http://www.w3.org/2000/xmlns/";s!==void 0&&(this.Tt=this.makeElement("svg",{width:"1px",height:"1px",viewBox:"0 0 1 1"}),this.style.display="block",this.style.letterSpacing="normal",this.style.wordSpacing="normal",e||(this.style.position="absolute"),this.Tt.setAttributeNS(n,"xmlns",this.T2),this.Tt.setAttributeNS(n,"xmlns:xlink","http://www.w3.org/1999/xlink")),this.Gu=null,this.li=new SVGContext(this,e)}resize(t,i,e,s){return this.width!==t||this.height!==i?(this.width=t,this.height=i,this.style.width=e+"px",this.style.height=s+"px",this.Tt.setAttributeNS(null,"width",e+"px"),this.Tt.setAttributeNS(null,"height",s+"px"),this.Tt.setAttributeNS(null,"viewBox","0 0 "+e+" "+s),this.li.D2.firstElementChild.setAttributeNS(null,"width",e+"px"),this.li.D2.firstElementChild.setAttributeNS(null,"height",s+"px"),!0):!1}makeElement(t,i,e){const s=this.jr.createElementNS(this.T2,t);if(U.G(i))for(const n in i)s.setAttributeNS(n==="href"?"http://www.w3.org/1999/xlink":"",n,i[n]);return e!==void 0&&(s.textContent=e),s}getBoundingClientRect(){return this.Tt.getBoundingClientRect()}focus(){this.Tt.focus()}get width(){return this.Tt.width.baseVal.value}set width(t){this.Tt.setAttribute("width",t+"px")}get height(){return this.Tt.height.baseVal.value}set height(t){this.Tt.setAttribute("height",t+"px")}dispose(){this.jr=null}get style(){return this.Tt.style}}class SVGContext{nf;of;un;Li;ze;fillStyle;font;globalAlpha;lineCap;lineDashOffset;lineJoin;lineWidth;miterLimit;shadowBlur;shadowColor;shadowOffsetX;shadowOffsetY;strokeStyle;textAlign;imageSmoothingEnabled;clipInsteadOfFill;lastCreatedElement;rf;lf;surface;svg;D2;TA;qb;Io;ph;Ma;currentElement;clipPathGroup;diagramGroup;lastDrawnPart;currentPath;outerGroup;pathAttributes;Zr;kr;filter;partClipRect;constructor(t,i){if(this.surface=t,this.svg=t.Tt,this.rf=[],this.lf=[],this.fillStyle="#000000",this.font="10px sans-serif",this.globalAlpha=1,this.lineCap="butt",this.lineDashOffset=0,this.lineJoin="miter",this.lineWidth=1,this.miterLimit=10,this.shadowBlur=0,this.shadowColor="rgba(0, 0, 0, 0)",this.shadowOffsetX=0,this.shadowOffsetY=0,this.Zr=!1,this.strokeStyle="#000000",this.textAlign="start",this.clipInsteadOfFill=!1,this.nf=0,this.of=0,this.un=0,this.lastCreatedElement=null,this.currentElement=null,this.Li=[],this.pathAttributes={},this.qb=!1,this.Io=null,this.ph=0,this.ze=new STransform,t.jr===null||t.jr===void 0)return;this.clipPathGroup=this.newGroup2(),this.diagramGroup=this.newGroup2("gojs-diagram"),this.lastDrawnPart=null,this.currentPath=null;const e=GSet.pw++,s=this.makeElement("clipPath",{id:"mainClip"+e}),n={x:0,y:0,width:t.width,height:t.height};s.appendChild(this.makeElement("rect",n)),this.D2=s,this.svg.appendChild(this.clipPathGroup),this.clipPathGroup.appendChild(this.diagramGroup),this.svg.appendChild(s),this.clipPathGroup.setAttributeNS(null,"clip-path","url(#mainClip"+e+")"),this.TA={},this.kr=!!i,this.filter="",this.partClipRect=null}setDiagramPosScale(t,i,e,s,n,o){this.diagramGroup===void 0?this.newGroup(t,i,e,s,n,o):this.diagramGroup.setAttribute("transform","matrix("+t+", "+i+", "+e+", "+s+", "+n+", "+o+")")}resetInnerSVG(){this.diagramGroup!==null&&(this.diagramGroup.innerHTML="")}arc(t,i,e,s,n,o,r,l){const h=2*Math.PI,c=1e-6,a=h-c,f=e*Math.cos(s),u=e*Math.sin(s),d=t+f,m=i+u,g=o?0:1;let p=o?s-n:n-s;(Math.abs(r-d)>c||Math.abs(l-m)>c)&&this.Li.push(["L",d,+m]),p<0&&(p=p%h+h),p>a?(this.Li.push(["A",e,e,0,1,g,t-f,i-u]),this.Li.push(["A",e,e,0,1,g,d,m])):p>c&&this.Li.push(["A",e,e,0,+(p>=Math.PI),g,t+e*Math.cos(n),i+e*Math.sin(n)])}beginPath(){this.Li=[],this.pathAttributes={stroke:"none",fill:"none"}}endPath(t){this.ov(this.Li,this.ze,t||0)}bezierCurveTo(t,i,e,s,n,o){this.Li.push(["C",t,i,e,s,n,o])}clearRect(t,i,e,s){}clip(){this.pathAttributes.clipPath=!0}closePath(){this.Li.push(["z"])}createLinearGradient(t,i,e,s){const n=new SGradient("linear");return n.x1=t,n.y1=i,n.x2=e,n.y2=s,n}createPattern(t,i){let e="";t instanceof HTMLCanvasElement&&(e=t.toDataURL()),t instanceof HTMLImageElement&&(e=t.getAttribute("src"));const s=this.TA;if(s[e])return"url(#"+s[e]+")";const n="PATTERN"+GSet.pw++,o={width:t.width,height:t.height,id:n,patternUnits:"userSpaceOnUse"},r={x:0,y:0,width:t.width,height:t.height,href:e},l=this.makeElement("pattern",o);return l.appendChild(this.makeElement(Diagram.img,r)),this.svg.appendChild(l),s[e]=n,"url(#"+n+")"}createRadialGradient(t,i,e,s,n,o){const r=new SGradient("radial");return r.x1=t,r.y1=i,r.r1=e,r.x2=s,r.y2=n,r.r2=o,r}amendImageTransform(t,i,e,s,n,o,r,l){const h=r/e,c=l/s;(n!==0||o!==0)&&this.ze.translate(n,o),(h!==1||c!==1)&&this.ze.scale(h,c),(t!==0||i!==0)&&this.ze.translate(-t,-i)}drawImage(t,i,e,s,n,o,r,l,h){let c="";t instanceof HTMLCanvasElement&&(c=t.toDataURL()),t instanceof HTMLImageElement&&(c=t.getAttribute("src"));const a=t instanceof HTMLImageElement?t.naturalWidth:t.width,f=t instanceof HTMLImageElement?t.naturalHeight:t.height;s===void 0&&(o=i,r=e,l=s=a,h=n=f),s=s||0,n=n||0,o=o||0,r=r||0,l=l||0,h=h||0,this.amendImageTransform(i,e,s,n,o,r,l,h);const u={x:0,y:0,width:a||s,height:f||n,href:c};!Geo.z(s,l)||!Geo.z(n,h)?u.preserveAspectRatio="none":c.toLowerCase().indexOf(".svg")===-1&&c.toLowerCase().indexOf("data:image/svg")===-1&&(u.preserveAspectRatio="xMidYMid slice"),(i!==0||e!==0||s!==a||n!==f)&&(s+=i,n+=e,u["clip-path"]=`path('M ${i},${e} L ${s} ${e} L ${s} ${n} L ${i} ${n} z')`),this.processCommon(Diagram.img,u,this.ze),this._u(Diagram.img,u)}fill(t,i){t&&(this.pathAttributes["fill-rule"]="evenodd"),this.setFill(this.pathAttributes)}fillContext(t,i,e){this.clipInsteadOfFill?this.clip():this.fill(i,e)}createOrUpdateClipGroup(t,i){const e=this.newGroup(1,0,0,1,-i.x,-i.y);e.setAttributeNS(null,"class","spotClip"),t.ah=e}fillRect(t,i,e,s){this.addRect("fill",[t,i,e,s],this.ze)}fillBackground(t,i,e,s){const n={x:t,y:i,width:e,height:s};this.processCommon("fill",n,this.ze),this.setFill(n),this.svg.prepend(this.makeElement("rect",n))}fillText(t,i,e){this.addText("fill",[t,i,e],this.ze)}lineTo(t,i){this.Li.push(["L",t,i])}moveTo(t,i){this.Li.push(["M",t,i])}quadraticCurveTo(t,i,e,s){this.Li.push(["Q",t,i,e,s])}rect(t,i,e,s){this.Li.push(["M",t,i],["L",t+e,i],["L",t+e,i+s],["L",t,i+s],["z"])}restore(){this.ze=this.rf.pop(),this.Li=this.rf.pop();const t=this.rf.pop();this.fillStyle=t.fillStyle,this.font=t.font,this.globalAlpha=t.globalAlpha,this.lineCap=t.lineCap,this.lineDashOffset=t.lineDashOffset,this.lineJoin=t.lineJoin,this.lineWidth=t.lineWidth,this.miterLimit=t.miterLimit,this.shadowBlur=t.shadowBlur,this.shadowColor=t.shadowColor,this.shadowOffsetX=t.shadowOffsetX,this.shadowOffsetY=t.shadowOffsetY,this.strokeStyle=t.strokeStyle,this.textAlign=t.textAlign,this.partClipRect=t.partClipRect}save(){const t={fillStyle:this.fillStyle,font:this.font,globalAlpha:this.globalAlpha,lineCap:this.lineCap,lineDashOffset:this.lineDashOffset,lineJoin:this.lineJoin,lineWidth:this.lineWidth,miterLimit:this.miterLimit,shadowBlur:this.shadowBlur,shadowColor:this.shadowColor,shadowOffsetX:this.shadowOffsetX,shadowOffsetY:this.shadowOffsetY,strokeStyle:this.strokeStyle,textAlign:this.textAlign,partClipRect:this.partClipRect};this.rf.push(t);const i=[];for(let e=0;eh.offset>c.offset?1:-1);for(let h=0;h1&&this.lf[this.lf.length-2].setAttributeNS(null,"clip-path",'path("'+s+'") view-box');return}if(n.d=s,this.processCommon("",n,i),this.currentPath!==null){const r=this.currentPath;if(r.nodeName!=="g")for(const l in n)l!=="transform"&&r.setAttributeNS(null,l,n[l]);else{const l=r.getElementsByTagName("path");for(const h in n)h!=="transform"&&l[e].setAttributeNS(null,h,n[h])}}else this._u("path",n)}rv(t){const i=[];for(let e=0;es?(this.scale(s/n,1),this.translate((n-s)/2,0)):s>n&&(this.scale(1,n/s),this.translate(0,(s-n)/2)),this.fillOrClip(i,e),n>s?(this.translate(-(n-s)/2,0),this.scale(1/(s/n),1)):s>n&&(this.translate(0,-(s-n)/2),this.scale(1,1/(n/s))),!0}strokeContext(){this.clipInsteadOfFill||this.stroke()}fillOrClip(t,i){this.clipInsteadOfFill?this.clip(i):this.fill(t,i)}shadowsSet(t,i,e){this.nf=t,this.of=i,this.un=e}shadowsOff(){this.Zr=!1,this.shadowOffsetX=0,this.shadowOffsetY=0,this.shadowBlur=0}shadowsOn(){this.Zr=!0,this.shadowOffsetX=this.nf,this.shadowOffsetY=this.of,this.shadowBlur=this.un}enableDash(t,i){const e=this.E;e.setLineDash!==void 0&&(e.setLineDash(t),e.lineDashOffset=i)}disableDash(){const t=this.E;t.setLineDash!==void 0&&(t.setLineDash(CanvasSurfaceContext.EmptyArray),t.lineDashOffset=0)}clearContextCache(t){t&&(this.Wb=""),this.Jb="",this.$b=""}removePartFromView(t){}static EmptyArray=Object.freeze([])}var BrushType=(y=>(y[y.Solid=1]="Solid",y[y.Linear=2]="Linear",y[y.Radial=3]="Radial",y[y.Pattern=4]="Pattern",y))(BrushType||{}),ColorSpace=(y=>(y[y.Lab=1]="Lab",y[y.HSL=2]="HSL",y[y.Oklch=3]="Oklch",y))(ColorSpace||{});class ColorNumbers{n0;n1;n2;n3;constructor(){this.n0=0,this.n1=0,this.n2=0,this.n3=0}}class Brush{h;H;Na;ei;gs;j0;H0;Eo;q0;cn;_c;Gb;constructor(t,i){if(GSet.Ki(this),this.h=!1,t===void 0)this.H=1,this.Na="black";else if(typeof t=="string"){const s=U.Uh(BrushType,t);s!==null?(this.H=s,this.Na="black"):(this.H=1,this.Na=t)}else Object.keys(BrushType).hasOwnProperty(t)?(this.H=t,this.Na="black"):typeof t=="object"&&(this.H=1,i=t);const e=this.H;if(e===2?(this.ei=Spot.TopCenter,this.gs=Spot.BottomCenter):e===3?(this.ei=Spot.Center,this.gs=Spot.Center):(this.ei=Spot.None,this.gs=Spot.None),this.j0=0,this.H0=NaN,this.Eo=null,this.q0=null,this.cn=null,this._c=0,this.Gb=0,i){const s={};for(const n in i)isFinite(parseFloat(n))?this.addColorStop(parseFloat(n),i[n]):s[n]=i[n];Object.assign(this,s)}}copy(){const t=new Brush;return t.H=this.H,t.Na=this.Na,t.ei=this.ei.P(),t.gs=this.gs.P(),t.j0=this.j0,t.H0=this.H0,this.Eo!==null&&(t.Eo=this.Eo.copy()),t.q0=this.q0,t}u(){return this.h=!0,this.Eo!==null&&this.Eo.u(),this}oi(t){t in BrushType?this.type=t:U.er(this,t)}toString(){let t="Brush(";if(this.type===1)t+=this.color;else if(this.type===2?t+="Linear ":this.type===3?t+="Radial ":this.type===4?t+="Pattern ":t+="(unknown) ",t+=this.start+" "+this.end,this.colorStops!==null){const i=this.colorStops.iterator;for(;i.next();){const e=i.key,s=i.value;t+=" "+e+":"+s}}return t+=")",t}addColorStop(t,i){return this.h&&U.L(this),(typeof t!="number"||!isFinite(t)||t>1||t<0)&&U.W(t,"0 <= loc <= 1",Brush,"addColorStop:loc"),U.s(i,"string",Brush,"addColorStop:color"),this.Eo===null&&(this.Eo=new GMap),this.Eo.set(t,i),this.H===1&&(this.type=2),this.cn=null,this}get type(){return this.H}set type(t){this.h&&U.L(this,t),this.H=t,this.start.isNoSpot()&&(t===2?this.start=Spot.TopCenter:t===3&&(this.start=Spot.Center)),this.end.isNoSpot()&&(t===2?this.end=Spot.BottomCenter:t===3&&(this.end=Spot.Center)),this.cn=null}get color(){return this.Na}set color(t){this.h&&U.L(this,t),this.Na=t,this.cn=null}get start(){return this.ei}set start(t){this.h&&U.L(this,t),this.ei=t.P(),this.cn=null}get end(){return this.gs}set end(t){this.h&&U.L(this,t),this.gs=t.P(),this.cn=null}get startRadius(){return this.j0}set startRadius(t){this.h&&U.L(this,t),t<0&&U.W(t,">= zero",Brush,"startRadius"),this.j0=t,this.cn=null}get endRadius(){return this.H0}set endRadius(t){this.h&&U.L(this,t),t<0&&U.W(t,">= zero",Brush,"endRadius"),this.H0=t,this.cn=null}get colorStops(){return this.Eo}set colorStops(t){this.h&&U.L(this,t),this.Eo=t,this.cn=null}get pattern(){return this.q0}set pattern(t){this.h&&U.L(this,t),this.q0=t,this.cn=null}static randomColor(t,i){t===void 0&&(t=128),i===void 0&&(i=Math.max(t,255));const e=Math.abs(i-t);let s=Math.floor(t+Math.random()*e).toString(16),n=Math.floor(t+Math.random()*e).toString(16),o=Math.floor(t+Math.random()*e).toString(16);return s.length<2&&(s="0"+s),n.length<2&&(n="0"+n),o.length<2&&(o="0"+o),"#"+s+n+o}static isValidColor(t){return root.CSS?root.CSS.supports("color",t):!0}static lighten(t){return Brush.lightenBy(t)}lightenBy(t,i){this.h&&U.L(this);const e=t===void 0||typeof t!="number"?.2:t,s=i===void 0?3:i;if(this.type===1)Brush.No(this.color),this.color=Brush.td(e,s);else if((this.type===2||this.type===3)&&this.colorStops!==null){const n=this.colorStops.iterator;for(;n.next();)Brush.No(n.value),this.addColorStop(n.key,Brush.td(e,s))}return this}static lightenBy(t,i,e){const s=i===void 0||typeof i!="number"?.2:i,n=e===void 0?3:e;return Brush.No(t),Brush.td(s,n)}static darken(t){return Brush.darkenBy(t)}darkenBy(t,i){this.h&&U.L(this);const e=t===void 0||typeof t!="number"?.2:t,s=i===void 0?3:i;if(this.type===1)Brush.No(this.color),this.color=Brush.td(-e,s);else if((this.type===2||this.type===3)&&this.colorStops!==null){const n=this.colorStops.iterator;for(;n.next();)Brush.No(n.value),this.addColorStop(n.key,Brush.td(-e,s))}return this}static darkenBy(t,i,e){const s=i===void 0||typeof i!="number"?.2:i,n=e===void 0?3:e;return Brush.No(t),Brush.td(-s,n)}static mix(t,i,e){Brush.No(t);const s=Brush.Y.n0,n=Brush.Y.n1,o=Brush.Y.n2,r=Brush.Y.n3;Brush.No(i),e===void 0&&(e=.5);const l=Math.round((Brush.Y.n0-s)*e+s),h=Math.round((Brush.Y.n1-n)*e+n),c=Math.round((Brush.Y.n2-o)*e+o),a=Math.round((Brush.Y.n3-r)*e+r);return`rgba(${l}, ${h}, ${c}, ${a})`}isDark(){if(this.type===1)return Brush.isDark(this.color);if((this.type===2||this.type===3)&&this.colorStops!==null){const t=this.colorStops;if(this.type===3)return Brush.isDark(t.first().value);if(t.get(.5)!==null)return Brush.isDark(t.get(.5));if(t.count===2){const l=t.toArray();return Brush.isDark(Brush.mix(l[0].value,l[1].value))}const i=t.iterator;let e=-1,s=-1,n=1,o=1;for(;i.next();){const l=i.key,h=Math.abs(.5-i.key);n>o&&h=n&&hs){let l=e;e=s,s=l,l=n,n=o,o=l}const r=s-e;return Brush.isDark(Brush.mix(t.get(e),t.get(s),1-o/r))}return!1}static isDark(t){return t?t instanceof Brush?t.isDark():(Brush.No(t),(299*Brush.Y.n0+587*Brush.Y.n1+114*Brush.Y.n2)/1e3<128):!1}static td(t,i){switch(i){case 1:return Brush.lv(),Brush.Zn.n0=Math.min(100,Math.max(0,Brush.Zn.n0+100*t)),Brush.hv(),"rgba("+Brush.Y.n0+", "+Brush.Y.n1+", "+Brush.Y.n2+", "+Brush.Y.n3+")";case 2:return Brush.jS(),Brush.Ii.n2=Math.min(100,Math.max(0,Brush.Ii.n2+100*t)),"hsla("+Brush.Ii.n0+", "+Brush.Ii.n1+"%, "+Brush.Ii.n2+"%, "+Brush.Ii.n3+")";case 3:return Brush.av(),Brush.Qn.n0=Math.min(100,Math.max(0,Brush.Qn.n0+100*t)),Brush.cv(),"rgba("+Brush.Y.n0+", "+Brush.Y.n1+", "+Brush.Y.n2+", "+Brush.Y.n3+")";default:U.o("Unknown color space: "+i)}}static No(t){Brush.W0===!1&&(Brush.W0=!0,Brush._n=Diagram.isUsingDOM()?new CanvasSurface(null,void 0,{willReadFrequently:!0}).li:null);const i=Brush._n;if(i===null)return;i.clearRect(0,0,1,1),i.fillStyle="#000000";const e=i.fillStyle;if(i.fillStyle=t,i.fillStyle!==e){i.fillRect(0,0,1,1);const s=i.getImageData(0,0,1,1).data;Brush.Y.n0=s[0],Brush.Y.n1=s[1],Brush.Y.n2=s[2],Brush.Y.n3=s[3]/255}else{i.fillStyle="#FFFFFF";const s=i.fillStyle;i.fillStyle=t,i.fillStyle,Brush.Y.n0=0,Brush.Y.n1=0,Brush.Y.n2=0,Brush.Y.n3=1}}static jS(){const t=Brush.Y.n0/255,i=Brush.Y.n1/255,e=Brush.Y.n2/255,s=Math.max(t,i,e),n=Math.min(t,i,e),o=s-n;let r,l;const h=(s+n)/2;if(o===0)r=l=0;else{switch(s){case t:r=(i-e)/o%6;break;case i:r=(e-t)/o+2;break;case e:r=(t-i)/o+4;break}r*=60,r<0&&(r+=360),l=o/(1-Math.abs(2*h-1))}Brush.Ii.n0=Math.round(r),Brush.Ii.n1=Math.round(l*100),Brush.Ii.n2=Math.round(h*100),Brush.Ii.n3=Brush.Y.n3}static DE(){const t=Brush.Ii.n0,i=Brush.Ii.n1/100,e=Brush.Ii.n2/100;let s,n,o;const r=(1-Math.abs(2*e-1))*i,l=t/60,h=r*(1-Math.abs(l%2-1));l>=0&&l<1?(s=r,n=h,o=0):l>=1&&l<2?(s=h,n=r,o=0):l>=2&&l<3?(s=0,n=r,o=h):l>=3&&l<4?(s=0,n=h,o=r):l>=4&&l<5?(s=h,n=0,o=r):l>=5&&l<6&&(s=r,n=0,o=h);const c=e-.5*r;s+=c,n+=c,o+=c,Brush.Y.n0=Math.round(s*255),Brush.Y.n1=Math.round(n*255),Brush.Y.n2=Math.round(o*255),Brush.Y.n3=Brush.Ii.n3}static lv(){Brush.DA(),Brush.fv()}static hv(){Brush.uv(),Brush.FA()}static F2(t){return t/=255,t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}static R2(t){return t<=.0031308?t*12.92:1.055*Math.pow(t,1/2.4)-.055}static DA(){const t=Brush.F2(Brush.Y.n0),i=Brush.F2(Brush.Y.n1),e=Brush.F2(Brush.Y.n2);Brush.Dt.n0=.4124564*t+.3575761*i+.1804375*e,Brush.Dt.n1=.2126729*t+.7151522*i+.072175*e,Brush.Dt.n2=.0193339*t+.119192*i+.9503041*e,Brush.Dt.n3=Brush.Y.n3}static FA(){const t=3.2404542*Brush.Dt.n0+-1.5371385*Brush.Dt.n1+-.4985314*Brush.Dt.n2,i=-.969266*Brush.Dt.n0+1.8760108*Brush.Dt.n1+.041556*Brush.Dt.n2,e=.0556434*Brush.Dt.n0+-.2040259*Brush.Dt.n1+1.0572252*Brush.Dt.n2;Brush.Y.n0=Brush.R2(t)*255,Brush.Y.n1=Brush.R2(i)*255,Brush.Y.n2=Brush.R2(e)*255,Brush.Y.n3=Brush.Dt.n3,Brush.Y.n0=Math.round(Brush.Y.n0),Brush.Y.n0>255?Brush.Y.n0=255:Brush.Y.n0<0&&(Brush.Y.n0=0),Brush.Y.n1=Math.round(Brush.Y.n1),Brush.Y.n1>255?Brush.Y.n1=255:Brush.Y.n1<0&&(Brush.Y.n1=0),Brush.Y.n2=Math.round(Brush.Y.n2),Brush.Y.n2>255?Brush.Y.n2=255:Brush.Y.n2<0&&(Brush.Y.n2=0)}static v2=216/24389;static Zb=24389/27;static ed=[95.047,100,108.883];static O2(t){return t>Brush.v2?Math.pow(t,1/3):(Brush.Zb*t+16)/116}static fv(){const t=Brush.O2(Brush.Dt.n0*100/Brush.ed[0]),i=Brush.O2(Brush.Dt.n1*100/Brush.ed[1]),e=Brush.O2(Brush.Dt.n2*100/Brush.ed[2]);Brush.Zn.n0=116*i-16,Brush.Zn.n1=500*(t-i),Brush.Zn.n2=200*(i-e),Brush.Zn.n3=Brush.Dt.n3}static RA(t){const i=t*t*t;return i>Brush.v2?i:(116*t-16)/Brush.Zb}static uv(){const t=(Brush.Zn.n0+16)/116,i=Brush.Zn.n1/500+t,e=t-Brush.Zn.n2/200;Brush.Dt.n0=Brush.ed[0]/100*Brush.RA(i),Brush.Dt.n1=Brush.ed[1]/100*(Brush.Zn.n0>Brush.Zb*Brush.v2?Math.pow(t,3):Brush.Zn.n0/Brush.Zb),Brush.Dt.n2=Brush.ed[2]/100*Brush.RA(e),Brush.Dt.n3=Brush.Zn.n3}static dv(){let t=.8190224*Brush.Dt.n0+.3619062*Brush.Dt.n1+-.1288737*Brush.Dt.n2,i=.03298366*Brush.Dt.n0+.9292868*Brush.Dt.n1+.03614466*Brush.Dt.n2,e=.04817719*Brush.Dt.n0+.2642395*Brush.Dt.n1+.6335478*Brush.Dt.n2;t=Math.cbrt(t),i=Math.cbrt(i),e=Math.cbrt(e),Brush.ai.n0=.2104542*t+.7936177*i+-.004072046*e,Brush.ai.n1=1.977998*t+-2.428592*i+.4505937*e,Brush.ai.n2=.02590403*t+.7827717*i+-.8086757*e,Brush.ai.n3=Brush.Dt.n3,Brush.ai.n0*=100}static gv(){Brush.ai.n0/=100;let t=.9999999*Brush.ai.n0+.3963377*Brush.ai.n1+.2158037*Brush.ai.n2,i=1.000000009*Brush.ai.n0+-.1055613*Brush.ai.n1+-.06385417*Brush.ai.n2,e=1.00000005*Brush.ai.n0+-.08948418*Brush.ai.n1+-1.291485*Brush.ai.n2;t=t**3,i=i**3,e=e**3,Brush.Dt.n0=1.2268798*t+-.5578149*i+.281391*e,Brush.Dt.n1=-.04057576*t+1.112286*i+-.07171106*e,Brush.Dt.n2=-.07637294*t+-.4214933*i+1.586924*e,Brush.Dt.n3=Brush.ai.n3}static mv(){const t=Math.atan2(Brush.ai.n2,Brush.ai.n1)*180/Math.PI;Brush.Qn.n0=Brush.ai.n0,Brush.Qn.n1=Math.sqrt(Brush.ai.n1**2+Brush.ai.n2**2),Brush.Qn.n2=t>=0?t:t+360,Brush.Qn.n3=Brush.ai.n3}static pv(){Brush.ai.n0=Brush.Qn.n0,Brush.ai.n1=Brush.Qn.n1*Math.cos(Brush.Qn.n2*Math.PI/180),Brush.ai.n2=Brush.Qn.n1*Math.sin(Brush.Qn.n2*Math.PI/180),Brush.ai.n3=Brush.Qn.n3}static av(){Brush.DA(),Brush.dv(),Brush.mv()}static cv(){Brush.pv(),Brush.gv(),Brush.FA()}static Qu(t,i){typeof t=="string"||t instanceof Brush||U.o("Value for "+i+" must be a color string or a Brush, not "+t)}static Solid=1;static Linear=2;static Radial=3;static Pattern=4;static Lab=1;static HSL=2;static _n=null;static W0=!1;static Y=new ColorNumbers;static Ii=new ColorNumbers;static Dt=new ColorNumbers;static Zn=new ColorNumbers;static ai=new ColorNumbers;static Qn=new ColorNumbers}class PanelLayout{St="Base";static es=new GMap;static dn(t,i){i.name=t,PanelLayout.es.set(t,i)}get name(){return this.St}set name(t){this.St=t}constructor(){}get classType(){return Panel}measure(t,i,e,s,n,o,r){}measureElement(t,i,e,s,n){t.ht(i,e,s,n)}arrange(t,i,e){}arrangeElement(t,i,e,s,n,o){t.Bt(i,e,s,n,o)}remeasureObject(t){t.tf()}Ui(t,i,e){}}class PanelLayoutPosition extends PanelLayout{constructor(){super()}measure(t,i,e,s,n,o,r){const l=s.length,h=t.Uo();for(let c=0;c0&&(M=Math.max(Math.abs(k.x*o+k.offsetX-(S.x*o+S.offsetX))-g,0)),r>0&&(N=Math.max(Math.abs(k.y*r+k.offsetY-(S.y*r+S.offsetY))-g,0));const T=Size.l();T.i(0,0);const A=t.Uo();for(let R=0;R1,rt=et.columnSpan>1;(ft||rt)&&!(Gw&&(M=Math.max(w-gt,0)),b.Ai=b.Ai+M,b.actual=b._+M,w=Math.max(w-(M+(pt?gt:0)),0)}if(et.columnSpan===1&&(N===0||N===4)){b=t.getColumnDefinition(H);const gt=b.computeEffectiveSpacing(),pt=b._===0;M=Math.max(dt-b.actual,0),M+(pt?gt:0)>p&&(M=Math.max(p-gt,0)),b.Ai=b.Ai+M,b.actual=b._+M,p=Math.max(p-(M+(pt?gt:0)),0)}(ft||rt)&&et.tf()}}}U.J(f);let A=0,D=0;l=t.columnCount;for(let G=0;G=t.rowCount);Q++)b=t.getRowDefinition(I.row+Q),M=0,N===2||N===4?M=Math.max(b.minimum,V[I.row+Q]===0?b.maximum:Math.min(V[I.row+Q],b.maximum)):M=Math.max(b.minimum,isNaN(b.de)?b.maximum:Math.min(b.de,b.maximum)),E.height+=M,tt+=b.minimum;for(let Q=1;Q=t.columnCount);Q++)b=t.getColumnDefinition(I.column+Q),M=0,N===2||N===5?M=Math.max(b.minimum,B[I.column+Q]===0?b.maximum:Math.min(B[I.column+Q],b.maximum)):M=Math.max(b.minimum,isNaN(b.de)?b.maximum:Math.min(b.de,b.maximum)),E.width+=M,st+=b.minimum;Y.width+=E.width,Y.height+=E.height;const it=I.margin,et=it.right+it.left,ft=it.top+it.bottom;I.ht(Y.width,Y.height,st,tt);const rt=I.measuredBounds,ht=Math.max(rt.width+et,0),nt=Math.max(rt.height+ft,0);let ot=0;for(let Q=0;Q=t.rowCount);Q++)b=t.getRowDefinition(I.row+Q),ot+=b.total||0;if(ot=t.rowCount);ct++){b=t.getRowDefinition(I.row+ct);const dt=b._||0,mt=lt(I,b,ut);b.actual=Math.min(b.maximum,dt+mt),b._!==dt&&(Q-=b._-dt)}}for(;Q>0;){const lt=b._||0;if(isNaN(b.height)&&b.maximum>lt&&(b.actual=Math.min(b.maximum,lt+Q),b._!==lt&&(Q-=b._-lt)),b.index===0)break;b=t.getRowDefinition(b.index-1)}}let at=0;for(let Q=0;Q=t.columnCount);Q++)b=t.getColumnDefinition(I.column+Q),at+=b.total||0;if(at=t.columnCount);ct++){b=t.getColumnDefinition(I.column+ct);const dt=b._||0,mt=lt(I,b,ut);b.actual=Math.min(b.maximum,dt+mt),b._!==dt&&(Q-=b._-dt)}}for(;Q>0;){const lt=b._||0;if(isNaN(b.width)&&b.maximum>lt&&(b.actual=Math.min(b.maximum,lt+Q),b._!==lt&&(Q-=b._-lt)),b.index===0)break;b=t.getColumnDefinition(b.index-1)}}}U.J(u),Size.e(E),Size.e(Y),V!==void 0&&U.J(V),B!==void 0&&U.J(B);let K=0,j=0;const q=t.desiredSize,$=t.maxSize;N=t.zs(!0),A=0,D=0;let z=0,J=0;l=t.columnCount;for(let G=0;G0){for(;p!==a&&(u[p]===void 0||u[p]._===0);)p++;p=Math.max(Math.min(p,a-1),0),m=-u[p].position}let w=Math.min(t.leftIndex,f-1);if(d.length>0){for(;w!==f&&(d[w]===void 0||d[w]._===0);)w++;w=Math.max(Math.min(w,f-1),0),g=-d[w].position}let x=0,k=0;for(;x!==a&&u[x]===void 0;)x++;for(;k!==a&&d[k]===void 0;)k++;const b=t.part;let P=t.getRowDefinition(x),S=t.getColumnDefinition(k);for(let C=0;C=t.rowCount);nt++){const ot=t.getRowDefinition(C+nt);ot._!==0&&(L.height+=ot.total)}for(let nt=1;nt=t.columnCount);nt++){const ot=t.getColumnDefinition(N+nt);ot._!==0&&(L.width+=ot.total)}const O=T._+L.width,X=M._+L.height;let Y=h,E=c;const V=O,B=X,K=h,j=c;let q=O,$=X;h+O>e.width&&(q=Math.max(e.width-h,0)),c+X>e.height&&($=Math.max(e.height-c,0));let z=v.alignment,J=0,W=0,_=0,G=0;if(z.isDefault()){z=t.defaultAlignment,z.isSpot()||(z=Spot.Center),J=z.x,W=z.y,_=z.offsetX,G=z.offsetY;const nt=T.alignment,ot=M.alignment;nt.isSpot()&&(J=nt.x,_=nt.offsetX),ot.isSpot()&&(W=ot.y,G=ot.offsetY)}else J=z.x,W=z.y,_=z.offsetX,G=z.offsetY;(isNaN(J)||isNaN(W))&&(J=.5,W=.5,_=0,G=0);let I=R.width,H=R.height;const Z=v.margin,st=Z.left+Z.right,tt=Z.top+Z.bottom,it=v.S0(M,T,!1);isNaN(v.desiredSize.width)&&(it===2||it===5)&&(I=Math.max(O-st,0)),isNaN(v.desiredSize.height)&&(it===2||it===4)&&(H=Math.max(X-tt,0));const et=v.maxSize,ft=v.minSize;I=Math.min(et.width,I),H=Math.min(et.height,H),I=Math.max(ft.width,I),H=Math.max(ft.height,H);const rt=I+st,ht=H+tt;Y+=V*J-rt*J+_+Z.left,E+=B*W-ht*W+G+Z.top,v.visible&&(Rect.contains(K,j,q,$,Y,E,R.width,R.height)?v.Bt(Y,E,I,H):v.Bt(Y,E,I,H,new Rect(K,j,q,$)))}}}Size.e(L);for(let C=0;C0&&(b.figure==="LineV"||b.figure==="LineH")){if(i.lineWidth=b.strokeWidth,t.rn(i,b.stroke,!1,!1,l,h),i.beginPath(),b.figure==="LineV"){const D=Math.floor((m-o)/o);for(let F=D;F<=D+f;F++){const v=F*o+m;0<=v&&v<=c&&this._b(F,P,L,N)&&(i.moveTo(v,0),i.lineTo(v,a))}}else if(b.figure==="LineH"){const D=Math.floor((g-r)/r);for(let F=D;F<=D+u;F++){const v=F*r+g;0<=v&&v<=a&&this._b(F,P,L,N)&&(i.moveTo(0,v),i.lineTo(c,v))}}i.stroke(),i.endPath()}else if(b.fill!==null){if(t.rn(i,b.fill,!0,!1,l,h),b.figure==="BarV"){let D=b.width;isNaN(D)&&(D=o);const F=Math.floor((m-o)/o);for(let v=F;v<=F+f;v++){const R=v*o+m;0<=R+D&&R<=c&&this._b(v,P,L,N)&&i.fillRect(R,0,D,a)}}else if(b.figure==="BarH"){let D=b.height;isNaN(D)&&(D=r);const F=Math.floor((g-r)/r);for(let v=F;v<=F+u;v++){const R=v*r+g;0<=R+D&&R<=a&&this._b(v,P,L,N)&&i.fillRect(0,R,c,D)}}}T&&i.disableDash(),C!==1&&(i.globalAlpha=M)}}_b(t,i,e,s){if(i<0)return t%i===e;if(t%i!==e)return!1;const n=s.length;for(let o=0;ol&&r.push(d)}}t.yi.J0=i}B2(t){return t==="LineV"||t==="BarV"}yv(t){let i=1,e=1;const s=t.C.r,n=s.length;for(let l=0;l=g){const z=Point.l();a.OA(z),O=a.midAngle,A!==0&&(R=a.computeAngle(L,A,O),L.Yt=R,L.ue(!0),L.Jn(!0)),F=z.x-u.x,v=z.y-u.y,Point.e(z)}else{let z,J,W=0;if(M>=0?(z=m.elt(M),J=M0?m.elt(W-1):z),O=0,z.equalsApprox(J)){let _,G;M>=0?(_=M>0?m.elt(M-1):z,G=M1?m.elt(W-2):J);const I=_.distanceSquaredPoint(z),H=J.distanceSquaredPoint(G);I>H+10?O=M>=0?_.directionPoint(z):z.directionPoint(_):H>I+10?O=M>=0?J.directionPoint(G):G.directionPoint(J):O=M>=0?_.directionPoint(G):G.directionPoint(_)}else O=M>=0?z.directionPoint(J):J.directionPoint(z);A!==0&&(R=a.computeAngle(L,A,O),L.Yt=R,L.ue(!0),L.Jn(!0)),F=z.x+(J.x-z.x)*N-u.x,v=z.y+(J.y-z.y)*N-u.y}L.ht(1/0,1/0,0,0),C=L.measuredBounds;const X=L.naturalBounds;let Y=0;L instanceof Shape&&(Y=L.strokeWidth);const E=X.width+Y,V=X.height+Y;k.Ri(),k.Fs(-C.x,-C.y),k.tt(L.scale,L.scale),k.cs(A===0?L.angle:O,E/2,V/2),(A===22||A===26)&&k.cs(90,E/2,V/2),(A===23||A===27)&&k.cs(-90,E/2,V/2),A===28&&(O>45&&O<135||O>225&&O<315)&&k.cs(-O,E/2,V/2);const B=new Rect(0,0,E,V);b.setRectSpot(B,T),k.gt(b);const K=-b.x+Y/2*L.scale,j=-b.y+Y/2*L.scale;P.a(D);const q=isNaN(D.x),$=isNaN(D.y);if(q||$){const z=E/2+3,J=V/2+3,W=O>=45&&O<=135,_=O>=225&&O<=315;A===0&&(W||_)?(P.x=$?z:D.y,P.y=q?J:D.x,W?M>=0||isNaN(M)&&N<.5||q&&(P.y=-J):_&&((M>=0||isNaN(M)&&N<.5)&&q&&(P.y=-J),$&&(P.x=-z))):(q&&(M>=0||isNaN(M)&&N<.5?P.x=z:P.x=-z),$&&(P.y=-J),P.rotate(O))}else P.rotate(O);F+=P.x,v+=P.y,B.i(F+K,v+j,C.width,C.height),x.push(B),d.unionRect(B)}if(h!==null){const S=h.labelNodes;for(;S.next();)S.value.ht(1/0,1/0)}t.Bo=d,t.position.i(u.x+d.x,u.y+d.y),n.Fn(d.width||0,d.height||0),Transform.e(k),Point.e(b),Point.e(P)}arrange(t,i,e){const s=i.length;if(!(t instanceof Adornment||t instanceof Link))return;let n=t,o=null;t instanceof Adornment&&(o=t,n=o.adornedPart);const r=t,l=t instanceof Adornment?null:n.path,h=t.hf;if(h.length!==0){let u=0;if(l!==null&&u=2&&r instanceof Link){const u=r.labelNodes;for(;u.next();){const d=u.value;r.bv(d,a,c)}}o!==null?o.sd(!1):n.sd(!1);const f=t.IA(Point.l());t.location.i(t.position.x+f.x,t.position.y+f.y),Point.e(f)}measureLinkPath(t,i,e,s){if(s.To()===!1)return;let n=s.strokeWidth;if(n===0&&t instanceof Adornment&&t.type===Panel.Link&&t.adornedObject instanceof Shape&&(n=t.adornedObject.strokeWidth),n=n*s.tt,t instanceof Link&&t.ot!==null){const o=t.geometry.bounds;s.Wn(o.x-n/2,o.y-n/2,o.width+n,o.height+n)}else if(t instanceof Adornment&&t.adornedPart.ot!==null){const o=t.adornedPart.ot.bounds;s.Wn(o.x-n/2,o.y-n/2,o.width+n,o.height+n)}else s.Wn(-(n/2),-(n/2),i+n,e+n);s.kv(),s.ue(!1)}}PanelLayout.dn("Link",new PanelLayoutLink);class PanelLayoutGraduated extends PanelLayout{constructor(){super()}measure(t,i,e,s,n,o,r){const l=t.findMainElement();t.Ge=[];const h=l.margin,c=h.right+h.left,a=h.top+h.bottom;l.ht(i,e,o,r);const f=l.measuredBounds,u=f.width,d=f.height,m=Math.max(u+c,0),g=Math.max(d+a,0),p=new Rect(-h.left,-h.top,m,g);t.Ge.push(p),n.a(p),this.determineGraduatedMarks(t,l);const w=t.xs;if(w===null)return;const x=s.length;for(let k=0;k45&&f<135||f>225&&f<315)&&P.cs(-f,k/2,b/2);const S=Rect.V(0,0,k,b),L=Point.l();L.setRectSpot(S,o),P.gt(L);const C=-L.x,M=-L.y,N=Point.l();N.a(l),isNaN(N.x)&&(N.x=k/2+3),isNaN(N.y)&&(N.y=-(b/2+3)),N.rotate(f),c+=N.x+C,a+=N.y+M;const T=new Rect(c,a,w.width,w.height),A=new Rect(w.x,w.y,w.width,w.height),D=new Rect(x.x,x.y,x.width,x.height);p.labelAngle=u,p.lineCount=n.lineCount,p.lines=n.getMetrics(),p.actualBounds=T,p.measuredBounds=A,p.naturalBounds=D,g===0?h.a(T):h.unionRect(T),Point.e(N),Point.e(L),Rect.e(S),Transform.e(P)}t.Ge!==null&&t.Ge.push(h),s.unionNoCheck(h.x,h.y,h.width,h.height)}determineGraduatedMarks(t,i){const e=i.geometry,s=i.strokeWidth,n=e.flattenedSegments,o=e.flattenedLengths,r=e.flattenedTotalLength,l=n.length;let h=0,c=0;const a=U.et();for(let x=0;xt.graduatedMin+M){const F=Math.floor((N-t.graduatedMin)/M);N-=F*M}const T=f[x],A=N,D=t.graduatedMax*1e-6;for(let F=1;N<=t.graduatedMax+D;F++){if(this.Sv(t,N-t.graduatedTickBase,T)&&(N>t.graduatedMax&&(N=t.graduatedMax),(k.graduatedSkip===null||k instanceof TextBlock&&!k.graduatedSkip(N,k)||k instanceof Shape&&!k.graduatedSkip(N,k))&&(m=(N-t.graduatedMin)*r/t.graduatedRange,m>r&&(m=r),g<=m&&m<=p))){let v=a[L][C],R=o[L][C];for(;LS&&C.4995)return t;let o=t;if(i<.5?n>0?o=s[n-1]:Geo.z(e[0],e[e.length-2])&&Geo.z(e[1],e[e.length-1])&&(o=s[s.length-1]):i>.5&&(n+1180&&(t.9995)return(t+o)/2%360;if(r<10){const l=1-Math.abs(.5-i);return(t*l+o*(1-l))%360}}return t}Pv(t){if(t.ss===null){const i=[],e=t.C.r,s=e.length;for(let n=0;nl&&r.push(a)}}t.ss=i}return t.ss}Sv(t,i,e){const s=e.length;for(let n=0;n-l)return!1}return!0}Ui(t,i,e){const s=e.ia;e.ia=!0;const n=t.naturalBounds,o=n.width,r=n.height,l=i instanceof SVGContext;i.save(),i.beginPath(),i.rect(-1,-1,o+1,r+1),i.clip(),i.endPath();const h=t.findMainElement();h.Ui(i,e);let c=t.getDocumentScale()*e.scale;c<=0&&(c=1);const a=h.actualBounds,f=t.C.r,u=t.xs,d=f.length;for(let m=0;m(y[y.Uniform=6]="Uniform",y[y.UniformToFill=7]="UniformToFill",y))(ViewboxStretch||{});class Panel extends GraphObject{H;C;Zt;nd;Bn;Qr;to;Bo;z2;F;od;st;yi;_t;rd;wh;Gs;constructor(t,i){if(super(),this.H=null,t===void 0)this.H=Panel.Position;else if(typeof t=="string"){const e=PanelLayout.es.get(t);e!==null&&(this.H=e)}else t instanceof PanelLayout?this.H=t:t&&(this.H=Panel.Position,i=t);this.H===null&&U.o("Panel type not specified or PanelLayout not loaded: "+t),this.n|=4194304|(this.H===Panel.Grid?1048576:0),this.C=new List,this.Zt=Margin.Rg,this.nd=Spot.Default,this.Bn=1,this.Qr=null,this.to="",this.Bo=new Rect(NaN,NaN,NaN,NaN),this.z2=null,this.F=null,this.od=6,this.yi=null,this.st=null,this._t=null,this.rd=NaN,this.wh=null,this.Gs=null,i&&Object.assign(this,i)}cloneProtected(t){super.cloneProtected(t),t.H=this.H,t.Zt=this.Zt.P(),t.nd=this.nd.P(),t.Bn=this.Bn,t.to=this.to,t.Bo.a(this.Bo),this.F!==null&&(t.F=this.F.copy(t)),t.od=this.od,this.st!==null&&(t.st=this.st.copy()),this.yi!==null&&(t.yi=this.yi.copy()),t._t=this._t,t.rd=this.rd,t.wh=this.wh}vo(t){super.vo(t),t.C=this.C;const i=t.C.r,e=i.length;for(let s=0;s= 0",Panel,"padding"),t=new Margin(t)):(t.left<0&&U.W(t.left,">= 0",Panel,"padding:value.left"),t.right<0&&U.W(t.right,">= 0",Panel,"padding:value.right"),t.top<0&&U.W(t.top,">= 0",Panel,"padding:value.top"),t.bottom<0&&U.W(t.bottom,">= 0",Panel,"padding:value.bottom"));const i=this.Zt;i.equals(t)||(t=t.P(),this.Zt=t,this.c(),this.t("padding",i,t))}get defaultAlignment(){return this.nd}set defaultAlignment(t){const i=this.nd;i.equals(t)||(t=t.P(),this.nd=t,this.c(),this.t("defaultAlignment",i,t))}get defaultStretch(){return this.Bn}set defaultStretch(t){const i=this.Bn;i!==t&&(this.Bn=t,this.c(),this.t("defaultStretch",i,t))}get defaultSeparatorPadding(){return this.F!==null?this.F.$0:Margin.Rg}set defaultSeparatorPadding(t){typeof t=="number"&&(t=new Margin(t));const i=this.defaultSeparatorPadding;i.equals(t)||(t=t.P(),this.F===null&&(this.F=new TablePanelSettings),this.F.$0=t,this.c(),this.t("defaultSeparatorPadding",i,t))}get defaultRowSeparatorStroke(){return this.F!==null?this.F.Z0:null}set defaultRowSeparatorStroke(t){const i=this.defaultRowSeparatorStroke;i!==t&&(t===null||typeof t=="string"||t instanceof Brush)&&(t instanceof Brush&&t.u(),this.F===null&&(this.F=new TablePanelSettings),this.F.Z0=t,this.S(),this.t("defaultRowSeparatorStroke",i,t))}get defaultRowSeparatorStrokeWidth(){return this.F!==null?this.F.Q0:1}set defaultRowSeparatorStrokeWidth(t){const i=this.defaultRowSeparatorStrokeWidth;i!==t&&isFinite(t)&&t>=0&&(this.F===null&&(this.F=new TablePanelSettings),this.F.Q0=t,this.c(),this.t("defaultRowSeparatorStrokeWidth",i,t))}get defaultRowSeparatorDashArray(){return this.F!==null?this.F._0:null}set defaultRowSeparatorDashArray(t){const i=this.defaultRowSeparatorDashArray;if(i!==t){if(t!==null&&!Array.isArray(t)&&U.Zi(t,"Array",Panel,"defaultRowSeparatorDashArray:value"),t!==null){const e=t.length;let s=0;for(let n=0;n=0)||!isFinite(o))&&U.o("defaultRowSeparatorDashArray value "+o+" at index "+n+" must be a positive number or zero."),s+=o}if(s===0){if(i===null)return;t=null}}this.F===null&&(this.F=new TablePanelSettings),this.F._0=t,this.S(),this.t("defaultRowSeparatorDashArray",i,t)}}get defaultColumnSeparatorStroke(){return this.F!==null?this.F.tp:null}set defaultColumnSeparatorStroke(t){const i=this.defaultColumnSeparatorStroke;i!==t&&(t===null||typeof t=="string"||t instanceof Brush)&&(t instanceof Brush&&t.u(),this.F===null&&(this.F=new TablePanelSettings),this.F.tp=t,this.S(),this.t("defaultColumnSeparatorStroke",i,t))}get defaultColumnSeparatorStrokeWidth(){return this.F!==null?this.F.ip:1}set defaultColumnSeparatorStrokeWidth(t){const i=this.defaultColumnSeparatorStrokeWidth;i!==t&&isFinite(t)&&t>=0&&(this.F===null&&(this.F=new TablePanelSettings),this.F.ip=t,this.c(),this.t("defaultColumnSeparatorStrokeWidth",i,t))}get defaultColumnSeparatorDashArray(){return this.F!==null?this.F.ep:null}set defaultColumnSeparatorDashArray(t){const i=this.defaultColumnSeparatorDashArray;if(i!==t){if(t!==null&&!Array.isArray(t)&&U.Zi(t,"Array",Panel,"defaultColumnSeparatorDashArray:value"),t!==null){const e=t.length;let s=0;for(let n=0;n=0)||!isFinite(o))&&U.o("defaultColumnSeparatorDashArray value "+o+" at index "+n+" must be a positive number or zero."),s+=o}if(s===0){if(i===null)return;t=null}}this.F===null&&(this.F=new TablePanelSettings),this.F.ep=t,this.S(),this.t("defaultColumnSeparatorDashArray",i,t)}}get yh(){return this.F!==null?this.F.yh:null}set yh(t){this.F===null&&(this.F=new TablePanelSettings),this.F.yh=t}get viewboxStretch(){return this.od}set viewboxStretch(t){const i=this.od;i!==t&&(this.od=t,this.c(),this.t("viewboxStretch",i,t))}get gridCellSize(){return this.yi!==null?this.yi.ld:Size.wC}set gridCellSize(t){this.yi===null&&(this.yi=new GridPanelSettings);const i=this.yi.ld;if(!i.equals(t)){(!t.isReal()||t.width===0||t.height===0)&&U.o("Invalid Panel.gridCellSize: "+t),this.yi.ld=t.P();const e=this.diagram;e!==null&&this===e.grid&&e.th(),this.S(),this.t("gridCellSize",i,t)}}get gridOrigin(){return this.yi!==null?this.yi.hd:Point.xo}set gridOrigin(t){this.yi===null&&(this.yi=new GridPanelSettings);const i=this.yi.hd;if(!i.equals(t)){t.isReal()||U.o("Invalid Panel.gridOrigin: "+t),this.yi.hd=t.P();const e=this.diagram;e!==null&&this===e.grid&&e.th(),this.S(),this.t("gridOrigin",i,t)}}get graduatedMin(){return this.st!==null?this.st.sp:0}set graduatedMin(t){const i=this.graduatedMin;if(i!==t&&(this.st===null&&(this.st=new GradPanelSettings),this.st.sp=t,this.c(),this.t("graduatedMin",i,t),this.Wc())){const e=this.part;e!==null&&this.ba(e,"graduatedRange")}}get graduatedMax(){return this.st!==null?this.st.np:100}set graduatedMax(t){const i=this.graduatedMax;if(i!==t&&(this.st===null&&(this.st=new GradPanelSettings),this.st.np=t,this.c(),this.t("graduatedMax",i,t),this.Wc())){const e=this.part;e!==null&&this.ba(e,"graduatedRange")}}get graduatedRange(){return this.graduatedMax-this.graduatedMin}get graduatedTickUnit(){return this.st!==null?this.st.op:10}set graduatedTickUnit(t){const i=this.graduatedTickUnit;i!==t&&t>0&&(this.st===null&&(this.st=new GradPanelSettings),this.st.op=t,this.c(),this.t("graduatedTickUnit",i,t))}get graduatedTickBase(){return this.st!==null?this.st.rp:0}set graduatedTickBase(t){const i=this.graduatedTickBase;i!==t&&(this.st===null&&(this.st=new GradPanelSettings),this.st.rp=t,this.c(),this.t("graduatedTickBase",i,t))}get xs(){return this.st!==null?this.st.xs:null}set xs(t){this.st!==null?this.st.xs=t:t!==null&&(this.st=new GradPanelSettings,this.st.xs=t)}get Ge(){return this.st!==null?this.st.Ge:null}set Ge(t){this.st!==null?this.st.Ge=t:t!==null&&(this.st=new GradPanelSettings,this.st.Ge=t)}get ss(){return this.st!==null?this.st.ss:null}set ss(t){this.st!==null?this.st.ss=t:t!==null&&(this.st=new GradPanelSettings,this.st.ss=t)}get Pe(){return this.st!==null?this.st.Pe:null}set Pe(t){this.st!==null?this.st.Pe=t:t!==null&&(this.st=new GradPanelSettings,this.st.Pe=t)}x0(t){super.x0(t);const i=this.C.r,e=i.length;for(let s=0;s0?this.Xe:null,s=this.columnCount>0?this.Ye:null;e!==null&&this.t1(t,i,!0,e,!0),s!==null&&this.t1(t,i,!1,s,!0),e!==null&&this.UA(t,!0,e),s!==null&&this.UA(t,!1,s),e!==null&&this.t1(t,i,!0,e,!1),s!==null&&this.t1(t,i,!1,s,!1)}UA(t,i,e){const s=e.length,n=this.actualBounds,o=this.naturalBounds;let r=!0;for(let l=0;lo.height)continue}else if(h.position>o.width)continue;let c=h.separatorStrokeWidth;isNaN(c)&&(c=i?this.defaultRowSeparatorStrokeWidth:this.defaultColumnSeparatorStrokeWidth);let a=h.separatorStroke;if(a===null&&(a=i?this.defaultRowSeparatorStroke:this.defaultColumnSeparatorStroke),c===0||a===null)continue;this.rn(t,a,!1,!1,o,n);let f=!1,u=h.separatorDashArray;u===null&&(u=i?this.defaultRowSeparatorDashArray:this.defaultColumnSeparatorDashArray),u!==null&&(f=!0,t.enableDash(u,0)),t.beginPath();const d=h.position+c;i?d>o.height&&(c-=d-o.height):d>o.width&&(c-=d-o.width);let m=h.position+c/2;t.lineWidth=c;const g=this.Zt;if(i){m+=g.top;const p=g.left,w=o.width-g.right;t.moveTo(p,m),t.lineTo(w,m)}else{m+=g.left;const p=g.top,w=o.height-g.bottom;t.moveTo(m,p),t.lineTo(m,w)}t.stroke(),t.endPath(),f&&t.disableDash()}}t1(t,i,e,s,n){const o=s.length,r=this.actualBounds,l=this.naturalBounds,h=this.BA(!0),c=this.BA(!1);for(let a=0;au)continue;let d=f.computeEffectiveSpacing(),m=f.separatorStrokeWidth;isNaN(m)&&(m=e?this.defaultRowSeparatorStrokeWidth:this.defaultColumnSeparatorStrokeWidth);let g=f.separatorStroke;g===null&&(g=e?this.defaultRowSeparatorStroke:this.defaultColumnSeparatorStroke),(g===null||f.index===(e?h:c))&&(m=0),d-=m;const p=f.position+m;let w=d+f.actual;if(p+w>u&&(w=u-p),w<=0)continue;const x=this.Zt;this.rn(t,f.background,!0,!1,l,r),e?t.fillRect(x.left,p+x.top,r.width-(x.left+x.right),w):t.fillRect(p+x.left,x.top,w,r.height-(x.top+x.bottom))}}BA(t){const i=t?this.rowCount:this.columnCount;for(let e=0;ex&&n.set(M),Point.e(M)),Point.e(S),o&&n.T(r),k}}Au(){const t=this.C.r,i=t.length;for(let e=0;ee||h>s)&&(this.c(),this.ht(l>e?e:l,h>s?s:h,0,0));break;case 2:this.c(!0),this.ht(e+a,s+f,0,0);break;case 5:this.c(!0),this.ht(e+a,h+f,0,0);break;case 4:this.c(!0),this.ht(l+a,s+f,0,0);break}}this.H.arrange(this,n,this.Bo)}fh(t){const i=this.naturalBounds,e=this.Uo();if(Rect.contains(0,0,i.width,i.height,t.x,t.y)){const s=this.C.r,n=s.length,o=Point.V(0,0);for(let r=n;r--;){const l=s[r];if(!(!l.visible&&l!==e)&&(o.set(t).Oe(l.T),l.containsPoint(o)))return Point.e(o),!0}return Point.e(o),this.Lt!==null}return!1}g0(t){if(this.Hn===t)return this;const i=this.C.r,e=i.length;for(let s=0;sd.width||u.y>d.height||u.x+u.width<0||u.y+u.height<0)continue;let m=f;const g=f instanceof Panel?f:null,p=Transform.l();p.set(r),(g!==null?g.Tm(t,i,e,s,n,p):m.wA(t,s,p))&&(i!==null&&(m=i(m)),m!==null&&(e===null||e(m))&&n.add(m)),Transform.e(p)}}return o===void 0&&Transform.e(r),s}return o===void 0&&Transform.e(r),!1}Y2(t,i,e){const s=this.C.r,n=s.length;for(let o=n;o--;){const r=s[o];if(!r.visible)continue;const l=r.actualBounds,h=this.naturalBounds;if(l.x>h.width||l.y>h.height||l.x+l.width<0||l.y+l.height<0)continue;r instanceof Panel&&r.Y2(t,i,e);let c=r;t!==null&&(c=t(c)),c!==null&&(i===null||i(c))&&e.add(c)}}PL(t,i,e,s,n,o){if(this.pickable===!1)return!1;e===void 0&&(e=null),s===void 0&&(s=null);const r=this.naturalBounds,l=this.an(),h=l?t:Point.V(t.x,t.y).Oe(this.T),c=l?i:Point.V(i.x,i.y).Oe(this.T),a=h.distanceSquaredPoint(c),f=h.x>0&&h.x0&&h.yP.width||b.y>P.height||b.x+b.width<0||b.y+b.height<0))continue;if(k.an()){const C=k.T;d.set(t).Oe(C),m.set(i).Oe(C)}else d.set(t),m.set(i);let S=k;const L=k instanceof Panel?k:null;(L!==null?L.PL(d,m,e,s,n,o):S.xA(d,m,n))&&(e!==null&&(S=e(S)),S!==null&&(s===null||s(S))&&o.add(S))}Point.e(d),Point.e(m)}return n?f:u}return!1}E2(t){let i=null;if(t instanceof Shape){i=t.spot1,i===Spot.Default&&(i=null);const e=t.geometry;e!==null&&i===null&&(i=e.spot1)}return i===null&&(i=Spot.TopLeft),i}U2(t){let i=null;if(t instanceof Shape){i=t.spot2,i===Spot.Default&&(i=null);const e=t.geometry;e!==null&&i===null&&(i=e.spot2)}return i===null&&(i=Spot.BottomRight),i}add(...t){for(let i=0;i=s.count&&t>=s.count)return;s.removeAt(r),n=r}else U.o("element "+i.toString()+" has panel "+e.toString()+" but is not contained by it.")}(t<0||t>s.count)&&(t=s.count),s.insertAt(t,i),(t===0||i.isPanelMain)&&(this.Qr=null),this.To()||this.c(),i.c(!1),i.portId!==null?this.fn=!0:i instanceof Panel&&i.fn===!0&&(this.fn=!0),this.ss=null,this.isEnabledObject()||this.i1(i,!1);const o=this.part;if(o!==null){o.A0(),o.cf(),this.fn&&o instanceof Node&&(o.fn=!0),o.fn&&o instanceof Node&&(o.ne=null);const r=this.diagram;if(r!==null&&r.undoManager.isUndoingRedoing)return;n!==-1&&o.raiseChangedEvent(4,"elements",this,i,null,n,null),o.raiseChangedEvent(3,"elements",this,null,i,null,t)}}get fn(){return(this.n&8388608)!==0}set fn(t){(this.n&8388608)!==0!==t&&(this.n=this.n^8388608)}p2(){return(this.n&16777216)!==0}G2(t){t?this.n|=16777216:this.n&=-16777217}Tv(t){t.Pa(this),t.Jr=null;const i=this.C,e=i.count;i.insertAt(e,t);const s=this.part;if(s!==null){s.A0(),t.portId!==null&&s instanceof Node&&(s.fn=!0);const n=this.diagram;if(n!==null&&n.undoManager.isUndoingRedoing)return;s.raiseChangedEvent(3,"elements",this,null,t,null,e)}}ZR(t){const i=this.C.r,e=i.length;let s=-1;for(let n=0;n=0&&this.te(t,!0)}te(t,i){const e=this.C,s=e.elt(t);if(s.Jr=null,s.Pa(null),this.Gs!==null){const o=s.data;U.G(o)&&this.Gs.delete(o)}e.removeAt(t),this.ue(!1),this.c(),this.Qr===s&&(this.Qr=null),this.ss=null;const n=this.part;if(n!==null){n.A0(),n.cf(),n.invalidateAdornments(),n instanceof Node&&(s instanceof Panel?s.walkVisualTreeFrom(s,(r,l)=>n.C2(l,i)):n.C2(s,i));const o=this.diagram;if(o!==null&&o.undoManager.isUndoingRedoing)return;n.raiseChangedEvent(4,"elements",this,s,null,t,null)}}get Xe(){return this.F===null&&(this.F=new TablePanelSettings),this.F.Xe}get rowCount(){return this.F===null?0:this.Xe.length}getRowDefinition(t){t<0&&U.W(t,">= 0",Panel,"getRowDefinition:idx"),t=Math.round(t);const i=this.Xe;if(i[t]===void 0){const e=new RowColumnDefinition;e.Pa(this),e.isRow=!0,e.index=t,i[t]=e,this.raiseChangedEvent(3,"rowdefs",this,null,e,null,t)}return i[t]}removeRowDefinition(t){if(t<0&&U.W(t,">= 0",Panel,"removeRowDefinition:idx"),this.rowCount===0)return;t=Math.round(t);const i=this.Xe,e=i[t];if(e){i[t]=void 0;let s=i.length-1;for(;s>=0&&i[s--]===void 0;)i.length--;this.raiseChangedEvent(4,"rowdefs",this,e,null,t,null),this.c()}}$L(t,i){const e=this.Xe;if(!(t<0)){if(e[t]=i instanceof RowColumnDefinition?i:void 0,!i){let s=e.length-1;for(;s>=0&&e[s--]===void 0;)e.length--}this.c()}}get Ye(){return this.F===null&&(this.F=new TablePanelSettings),this.F.Ye}get columnCount(){return this.F===null?0:this.Ye.length}getColumnDefinition(t){t<0&&U.W(t,">= 0",Panel,"getColumnDefinition:idx"),t=Math.round(t);const i=this.Ye;if(i[t]===void 0){const e=new RowColumnDefinition;e.Pa(this),e.isRow=!1,e.index=t,i[t]=e,this.raiseChangedEvent(3,"coldefs",this,null,e,null,t)}return i[t]}removeColumnDefinition(t){if(t<0&&U.W(t,">= 0",Panel,"removeColumnDefinition:idx"),this.columnCount===0)return;t=Math.round(t);const i=this.Ye,e=i[t];if(e){i[t]=void 0;let s=i.length-1;for(;s>=0&&i[s--]===void 0;)i.length--;this.raiseChangedEvent(4,"coldefs",this,e,null,t,null),this.c()}}ZL(t,i){const e=this.Ye;if(!(t<0)){if(e[t]=i instanceof RowColumnDefinition?i:void 0,!i){let s=e.length-1;for(;s>=0&&e[s--]===void 0;)e.length--}this.c()}}addRowColumnDefinition(t){let i=null;return t.isRow?i=this.getRowDefinition(t.index):t.isRow||(i=this.getColumnDefinition(t.index)),i&&i.Hb(t),this}addRowDefinition(t,i){const e=this.getRowDefinition(t);return e&&e.Hb(new RowColumnDefinition(i)),this}addColumnDefinition(t,i){const e=this.getColumnDefinition(t);return e&&e.Hb(new RowColumnDefinition(i)),this}get rowSizing(){return this.F!==null?this.F.hp:3}set rowSizing(t){const i=this.rowSizing;i!==t&&(this.F===null&&(this.F=new TablePanelSettings),this.F.hp=t,this.c(),this.t("rowSizing",i,t))}get columnSizing(){return this.F!==null?this.F.ap:3}set columnSizing(t){const i=this.columnSizing;i!==t&&(this.F===null&&(this.F=new TablePanelSettings),this.F.ap=t,this.c(),this.t("columnSizing",i,t))}get topIndex(){return this.F!==null?this.F.cp:0}set topIndex(t){const i=this.topIndex;i!==t&&((!isFinite(t)||t<0)&&U.o("Panel.topIndex must be greater than zero and a real number, not: "+t),this.F===null&&(this.F=new TablePanelSettings),this.F.cp=t,this.c(),this.t("topIndex",i,t))}get leftIndex(){return this.F!==null?this.F.fp:0}set leftIndex(t){const i=this.leftIndex;i!==t&&((!isFinite(t)||t<0)&&U.o("Panel.leftIndex must be greater than zero and a real number, not: "+t),this.F===null&&(this.F=new TablePanelSettings),this.F.fp=t,this.c(),this.t("leftIndex",i,t))}findRowForLocalY(t){if(t<0||this.type!==Panel.Table||this.rowCount===0)return-1;let i=0;const e=this.Xe,s=e.length;let n=this.topIndex;for(;n{o.ch();const r=o.Ci;if(r!==null){o.S2(!1);const l=r.iterator;for(;l.next();){const h=l.value;h.mode===2&&o.S2(!0);const c=h.sourceName;if(h.isToObject){c==="/"&&n.G2(!0);const a=h.yA(n,o);a!==null&&(i.add(a),a.qn===null&&(a.qn=new List),a.qn.add(h))}t.add(h)}}if(o instanceof Panel&&o.type===Panel.Table){if(o.rowCount>0){const l=o.Xe,h=l.length;for(let c=0;c0){const l=o.Ye,h=l.length;for(let c=0;c0&&o instanceof Panel){const h=r.substring(0,l),c=r.substring(l+1),a=o.findObject(h);a!==null?(o=a,n.targetProperty=c):(U.ni('Warning: unable to find GraphObject named "'+h+'" for Binding: '+n.toString()),o=null)}if(o instanceof RowColumnDefinition){const h=GSet.as(o.panel);n.targetId=h===void 0?-1:h,o.panel.Hn=n.targetId}else if(o instanceof GraphObject){const h=GSet.as(o);n.targetId=h===void 0?-1:h,o.Hn=n.targetId}else U.o("Unknown type of binding target: "+o);n.check(o)}}return t.u(),this instanceof Part&&this.ke()&&this.ensureBounds(),this}static FE=!1;copyTemplate(t){t===void 0&&(t=!1);const i=this.copy();return i.Dv(e=>{e instanceof Panel&&(e.Ys=null,e._t=null);const s=e.Ci;s!==null&&(e.Ci=null,s.each(o=>e.bind(o.copy())));const n=e.ws;n!==null&&(e.ws=null,n.each(o=>e.trigger(o.value.copy())))}),t&&i.Et(),i}updateTargetBindings(t){const i=this.Ys;if(i===null)return;t===void 0&&(t="");const e=this.diagram?.model,s=i.iterator;for(;s.next();){const n=s.value,o=this.GA(n,t);if(o===null)continue;const{data:r,elt:l}=o;n.isToTheme&&this.diagram===null||l!==void 0&&n.updateTarget(l,r,void 0,e)}}Do(){if(this.diagram!==null)if(this.L2()){const t=this.diagram.model,i=this.Ys.iterator;for(;i.next();){const e=i.value;if(!e.isToTheme)continue;const s=this.GA(e);if(s===null)continue;const{data:n,elt:o}=s;o!==void 0&&e.updateTarget(o,n,void 0,t)}}else{const t=this.C.r,i=t.length;for(let e=0;e0;let r=0;for(;n0){const i=this.C.elt(0);if(i.isPanelMain&&i instanceof Panel&&i.$r())return 1}return 0}rebuildItemElements(){const t=this.lp();for(;this.C.length>t;)this.te(this.C.length-1,!1);this.KA(null,this.itemArray)}KA(t,i){const e=this.lp(),s=i;if(s===null||s.length===0){for(;this.C.length>e;)this.te(this.C.length-1,!1);return}if(this.C.length<=e){const n=s.length;for(let o=0;o(y[y.Default=1]="Default",y[y.None=2]="None",y[y.ProportionalExtra=3]="ProportionalExtra",y))(Sizing||{});class RowColumnDefinition{Vs;dp;At;Ca;La;hi;at;cd;$n;_r;fd;ud;Aa;Lt;dd;bs;_;Ai;de;constructor(t){GSet.Ki(this),this.Vs=null,this.dp=!0,this.At=0,this.de=NaN,this.Ca=0,this.La=1/0,this.hi=Spot.Default,this._=0,this.Ai=0,this.at=0,this.bs=null,this.cd=1,this.$n=1,this._r=null,this.fd=null,this.ud=NaN,this.Aa=null,this.Lt=null,this.dd=!1,t&&(Object.assign(this,t),t.column!==void 0?(this.isRow=!1,this.index=t.column):t.row!==void 0&&(this.isRow=!0,this.index=t.row))}copy(){const t=new RowColumnDefinition;return t.dp=this.dp,t.At=this.At,t.de=this.de,t.Ca=this.Ca,t.La=this.La,t.hi=this.hi,t._=this._,t.Ai=this.Ai,t.at=this.at,t.$n=this.$n,t.cd=this.cd,this._r===null?t._r=null:t._r=this._r.P(),t.fd=this.fd,t.ud=this.ud,t.Aa=null,this.Aa!==null&&(t.separatorDashArray=this.Aa.slice()),t.Lt=this.Lt,t.dd=this.dd,t.bs=this.bs,t}Hb(t){t.isRow?t.height!==void 0&&(this.height=t.height):t.width!==void 0&&(this.width=t.width),t.minimum!==void 0&&(this.minimum=t.minimum),t.maximum!==void 0&&(this.maximum=t.maximum),t.alignment!==void 0&&(this.alignment=t.alignment),t.stretch!==void 0&&(this.stretch=t.stretch),t.sizing!==void 0&&(this.sizing=t.sizing),t.separatorPadding!==void 0&&(this.separatorPadding=t.separatorPadding),t.separatorStroke!==void 0&&(this.separatorStroke=t.separatorStroke),t.separatorStrokeWidth!==void 0&&(this.separatorStrokeWidth=t.separatorStrokeWidth),t.separatorDashArray!==void 0&&(this.Aa=t.separatorDashArray),t.background!==void 0&&(this.background=t.background),t.coversSeparators!==void 0&&(this.coversSeparators=t.coversSeparators),t.bs!==void 0&&(this.bs=t.bs)}oi(t){t in Sizing?this.sizing=t:U.er(this,t)}toString(){return"RowColumnDefinition "+(this.isRow?"(Row ":"(Column ")+this.index+") #"+GSet.as(this)}static Default=1;static None=2;static ProportionalExtra=3;Pa(t){this.Vs=t}computeEffectiveSpacingTop(t){let i=0;const e=this.Vs;if(this.index!==t){let n=this.separatorStroke;n===null&&e!==null&&(n=this.isRow?e.defaultRowSeparatorStroke:e.defaultColumnSeparatorStroke),n!==null&&(i=this.separatorStrokeWidth,isNaN(i)&&(e!==null?i=this.isRow?e.defaultRowSeparatorStrokeWidth:e.defaultColumnSeparatorStrokeWidth:i=0))}let s=this._r;if(s===null)if(e!==null)s=e.defaultSeparatorPadding;else return i;return i+(this.isRow?s.top:s.left)}computeEffectiveSpacing(){let t=0;const i=this.Vs;let e=0;const s=this.isRow;if(i!==null&&i.type===Panel.Table){const o=s?i.Xe.length:i.Ye.length;for(let r=0;r= 0",RowColumnDefinition,"height"),this.de=t,this.actual=this._,this.panel!==null&&this.panel.c(),this.t("height",i,t))}get width(){return this.de}set width(t){const i=this.de;i!==t&&(t<0&&U.W(t,">= 0",RowColumnDefinition,"width"),this.de=t,this.actual=this._,this.panel!==null&&this.panel.c(),this.t("width",i,t))}get minimum(){return this.Ca}set minimum(t){const i=this.Ca;i!==t&&((t<0||!isFinite(t))&&U.W(t,">= 0",RowColumnDefinition,"minimum"),this.Ca=t,this.actual=this._,this.panel!==null&&this.panel.c(),this.t("minimum",i,t))}get maximum(){return this.La}set maximum(t){const i=this.La;i!==t&&(t<0&&U.W(t,">= 0",RowColumnDefinition,"maximum"),this.La=t,this.actual=this._,this.panel!==null&&this.panel.c(),this.t("maximum",i,t))}get alignment(){return this.hi}set alignment(t){const i=this.hi;i.equals(t)||(this.hi=t.P(),this.panel!==null&&this.panel.c(),this.t("alignment",i,t))}get stretch(){return this.$n}set stretch(t){const i=this.$n;i!==t&&(this.$n=t,this.panel!==null&&this.panel.c(),this.t("stretch",i,t))}get separatorPadding(){return this._r}set separatorPadding(t){typeof t=="number"&&(t=new Margin(t));const i=this._r;(t===null||i===null||!i.equals(t))&&(t!==null&&(t=t.P()),this._r=t,this.panel!==null&&this.panel.c(),this.t("separatorPadding",i,t))}get separatorStroke(){return this.fd}set separatorStroke(t){const i=this.fd;i!==t&&(t!==null&&Brush.Qu(t,"RowColumnDefinition.separatorStroke"),t instanceof Brush&&t.u(),this.fd=t,this.panel!==null&&this.panel.c(),this.t("separatorStroke",i,t))}get separatorStrokeWidth(){return this.ud}set separatorStrokeWidth(t){const i=this.ud;i!==t&&(this.ud=t,this.panel!==null&&this.panel.c(),this.t("separatorStrokeWidth",i,t))}get separatorDashArray(){return this.Aa}set separatorDashArray(t){const i=this.Aa;if(i!==t){if(t!==null&&!Array.isArray(t)&&U.Zi(t,"Array",RowColumnDefinition,"separatorDashArray:value"),t!==null){const e=t.length;let s=0;for(let n=0;n=0)||!isFinite(o))&&U.o("separatorDashArray value "+o+" at index "+n+" must be a positive number or zero."),s+=o}if(s===0){if(i===null)return;t=null}}this.Aa=t,this.panel!==null&&this.panel.S(),this.t("separatorDashArray",i,t)}}get background(){return this.Lt}set background(t){const i=this.Lt;i!==t&&(t!==null&&Brush.Qu(t,"RowColumnDefinition.background"),t instanceof Brush&&t.u(),this.Lt=t,this.panel!==null&&this.panel.S(),this.t("background",i,t))}get coversSeparators(){return this.dd}set coversSeparators(t){const i=this.dd;i!==t&&(U.s(t,"boolean",RowColumnDefinition,"coversSeparators"),this.dd=t,this.panel!==null&&this.panel.S(),this.t("coversSeparators",i,t))}get sizing(){return this.cd}set sizing(t){const i=this.cd;i!==t&&(this.cd=t,this.panel!==null&&this.panel.c(),this.t("sizing",i,t))}Qb(){if(this.sizing===1){const t=this.Vs;return this.isRow?t.rowSizing:t.columnSizing}return this.sizing}get actual(){return this._}set actual(t){isNaN(this.de)?this._=Math.max(Math.min(this.La,t),this.Ca):this._=Math.max(Math.min(this.La,this.de),this.Ca)}get measured(){return this.Ai}set measured(t){this.Ai=t}get total(){return this._+this.computeEffectiveSpacing()}get position(){return this.at}set position(t){this.at=t}bind(t,i,e,s){return this.sf(t,i,e,s),this}bindTwoWay(t,i,e,s){const n=this.sf(t,i,e,s);return s===void 0&&n.makeTwoWay(),this}theme(t,i,e,s,n){return this.mh(t,i,e,s,n),this}themeData(t,i,e,s,n){return this.mh(t,i,e,s,n).ofData(),this}themeObject(t,i,e,s,n,o){return this.mh(t,i,e,s,n).ofObject(o),this}themeModel(t,i,e,s,n){return this.mh(t,i,e,s,n).ofModel(),this}sf(t,i,e,s){let n;return typeof t=="string"?n=new Binding(t,i,e,s):n=t,this.Y0(n),n}mh(t,i,e,s,n){let o;return typeof t=="string"?o=new ThemeBinding(t,i,e,s,n):o=t,this.Y0(o),o}Y0(t){t.be=this;const i=this.panel;if(i!==null){const e=i.findBindingPanel();e!==null&&e.AA()&&U.o("Cannot add a Binding to a RowColumnDefinition that is already frozen: "+t+" on "+i)}this.bs===null&&(this.bs=new List),this.bs.add(t)}}class Shape extends GraphObject{ot;ks;gd;Ta;ji;Vo;Io;jt;md;pd;K;constructor(t,i){super(),this.ot=null,this.ks=null,this.gd="None",this.Ta="black",this.ji="black",this.Vo=1,this.Io=null,this.jt=null,this.md=NaN,this.pd=NaN,this.K=null,typeof t=="string"?this.figure=t:t&&Object.assign(this,t),i&&Object.assign(this,i)}cloneProtected(t){super.cloneProtected(t),t.ot=this.ot,t.ks=this.ks,t.gd=this.gd,t.Ta=this.Ta,t.ji=this.ji,t.Vo=this.Vo,this.Io!==null&&(t.Io=this.Io.slice()),this.jt!==null&&(this.jt.fi?t.jt=this.jt:t.jt=this.jt.copy()),t.md=this.md,t.pd=this.pd,this.K!==null&&(t.K=this.K.copy())}Da(){return this.jt===null?this.jt=new ShapeTemplateSettings:this.jt.fi&&(this.jt=this.jt.copy()),this.jt}ch(){super.ch(),this.jt!==null&&(this.jt.fi=!0)}oi(t){t in GeometryStretch?this.geometryStretch=t:super.oi(t)}toString(){return"Shape("+(this.figure!=="None"?this.figure:this.toArrow!=="None"?this.toArrow:this.fromArrow)+")#"+GSet.as(this)}Uv(t,i){const e=this.pathPattern;e.ht(1/0,1/0);const s=e.measuredBounds;e.Bt(0,0,s.width,s.height);const n=this.geometry;t.save(),t.beginPath();const o=U.et();if(n.type===1)o.push(n.startX),o.push(n.startY),o.push(n.endX),o.push(n.endY),this.yd(t,i,o,e);else if(n.type===4){const r=n.figures.iterator;for(;r.next();){const l=r.value;o.length=0,o.push(l.startX),o.push(l.startY);let h=l.startX,c=l.startY,a=h,f=c;const u=l.segments.r,d=u.length;for(let m=0;m=.1;){if(M===0&&(S?(b=k,b-=P,w-=P,S=!1):b=k,b===0&&(b=1)),b>w){b=w,U.J(x);return}b>p?(M=b-p,b=p):M=0;let N=Math.sqrt(b*b/(1+m*m));if(u<0&&(N=-N),h+=N,c+=m*N,t.translate(h,c),t.rotate(g),t.translate(-(r/2),-(l/2)),M===0&&s.gh(t,i),t.translate(r/2,l/2),t.rotate(-g),t.translate(-h,-c),w-=b,p-=b,M!==0){if(L++,L===x.length){U.J(x);return}C=x[L],u=C[0],g=C[1],m=C[2],p=C[3],b=M}}U.J(x)}gh(t,i){const e=t instanceof SVGContext;let s=this.ji;const n=this.Ta;if(s===null&&n===null)return;const o=this.ot;if(o===null)return;t.commitTransform();const r=this.actualBounds,l=this.naturalBounds;n!==null&&this.rn(t,n,!0,!1,l,r);const h=this.part;let c=this.Vo;s!==null&&c===0&&h!==null&&(this.isPanelMain||h.findMainElement()===this)&&(c=h.Vv()),c===0&&(s=null),s!==null&&c!==0&&(this.rn(t,s,!1,!1,l,r),t.lineWidth=c,t.lineJoin=this.strokeJoin,t.lineCap=this.strokeCap,t.miterLimit=this.strokeMiterLimit);let a=!1;h&&i.getRenderingHint("drawShadows")&&(a=h.isShadowed),t.Zr===!1&&(a=!1);let f=!0;s!==null&&(n===null||n==="transparent")&&(f=!1);let u=!1;const d=this.strokeDashArray;if(d!==null&&(u=!0,t.enableDash(d,this.strokeDashOffset)),o.type===1)t.beginPath(),t.moveTo(o.startX,o.startY),t.lineTo(o.endX,o.endY),s!==null&&t.strokeContext(),t.endPath();else if(o.type===2){const m=o.startX,g=o.startY,p=o.endX,w=o.endY,x=Math.min(m,p),k=Math.min(g,w),b=Math.abs(p-m),P=Math.abs(w-g);t.beginPath(),t.rect(x,k,b,P),n!==null&&t.fillContext(n,!1,null),s!==null&&(f&&a&&t.shadowsOff(),t.strokeContext(),f&&a&&t.shadowsOn()),t.endPath()}else if(o.type===3){const m=o.startX,g=o.startY,p=o.endX,w=o.endY,x=Math.abs(p-m)/2,k=Math.abs(w-g)/2,b=Math.min(m,p)+x,P=Math.min(g,w)+k;t.beginPath(),t.moveTo(b,P-k),t.bezierCurveTo(b+Geo.Rn*x,P-k,b+x,P-Geo.Rn*k,b+x,P),t.bezierCurveTo(b+x,P+Geo.Rn*k,b+Geo.Rn*x,P+k,b,P+k),t.bezierCurveTo(b-Geo.Rn*x,P+k,b-x,P+Geo.Rn*k,b-x,P),t.bezierCurveTo(b-x,P-Geo.Rn*k,b-Geo.Rn*x,P-k,b,P-k),t.closePath(),n!==null&&t.fillContext(n,!1,null),s!==null&&(f&&a&&t.shadowsOff(),t.strokeContext(),f&&a&&t.shadowsOn()),t.endPath()}else if(o.type===4){const m=o.figures,g=m.length;for(let p=0;p1||this.pathPattern!==null?!0:super.$u(t)}k2(t,i){if(t.nodeName!=="g")t.setAttributeNS(null,"filter",i);else{const e=t.getElementsByTagName("path");for(let s=0;s1,i);U.o("Unknown Geometry type: "+e.type)}}Wu(t,i,e,s){const n=this.desiredSize,o=this.Vo;t=Math.max(t,0),i=Math.max(i,0);let r;if(this.ks!==null)r=this.geometry.bounds;else{const g=this.figure;let p=Shape.q2[g];if(p===void 0){let w=Geo.In[g];typeof w=="string"&&(w=Geo.In[w]),U.it(w)?(p=w(null,100,100),Shape.q2[g]=p):U.o("Unsupported Figure: "+g)}r=p.bounds}let l=r.width,h=r.height,c=r.width,a=r.height;switch(this.zs(!0)){case 0:e=0,s=0;break;case 2:c=Math.max(t-o,0),a=Math.max(i-o,0);break;case 5:c=Math.max(t-o,0),s=0;break;case 4:e=0,a=Math.max(i-o,0);break}isFinite(n.width)&&(c=n.width),isFinite(n.height)&&(a=n.height);const u=this.maxSize,d=this.minSize;e=Math.max(e-o,d.width),s=Math.max(s-o,d.height),c=Math.min(u.width,c),a=Math.min(u.height,a),c=isFinite(c)?Math.max(e,c):Math.max(l,e),a=isFinite(a)?Math.max(s,a):Math.max(h,s);const m=this.aS();switch(m){case 0:break;case 2:l=c,h=a;break;case 6:{let g=Math.min(c/l,a/h);isFinite(g)||(g=1),l=l*g,h=h*g;break}default:U.o(m+" is not a valid geometryStretch.")}if(this.ks!==null){l===0&&(l=.001),h===0&&(h=.001);const p=(this.ks!==null?this.ks:this.ot).cF(l,h);this.ot=p}else(this.ot===null||!Geo.z(this.ot.rc,t-o)||!Geo.z(this.ot.lc,i-o))&&(this.ot=Shape.zv(this,l,h));r=this.ot.bounds,t===1/0||i===1/0?this.Wn(r.x-o/2,r.y-o/2,t===0&&l===0?0:r.width+o,i===0&&h===0?0:r.height+o):this.Wn(-(o/2),-(o/2),c+o,a+o),n.isReal()?(c=n.width,a=n.height,c=Math.min(u.width,c),a=Math.min(u.height,a),c=Math.max(d.width,c),a=Math.max(d.height,a),this.zi.i(0,0,c,a)):this.zi.a(r)}aS(){const t=this.geometryStretch;return this.ks!==null?t===1?2:t:t===1?Shape.q2[this.figure].defaultStretch:t}uh(t,i,e,s){this.commonArrange(t,i,e,s)}getNearestIntersectionPoint(t,i,e){return this.Jc(t.x,t.y,i.x,i.y,e)}Jc(t,i,e,s,n){const o=this.T,r=1/(o.m11*o.m22-o.m12*o.m21),l=o.m22*r,h=-o.m12*r,c=-o.m21*r,a=o.m11*r,f=r*(o.m21*o.dy-o.m22*o.dx),u=r*(o.m12*o.dx-o.m11*o.dy),d=t*l+i*c+f,m=t*h+i*a+u,g=e*l+s*c+f,p=e*h+s*a+u,w=this.Vo/2;let x=this.ot;x===null&&(this.ht(1/0,1/0),x=this.ot);const k=x.bounds;let b=!1;if(x.type===1)if(this.strokeWidth<=1.5)b=Geo.On(x.startX,x.startY,x.endX,x.endY,d,m,g,p,n);else{let P=0,S=0;if(x.startX===x.endX)P=w,S=0;else{const T=(x.endY-x.startY)/(x.endX-x.startX);S=w/Math.sqrt(1+T*T),P=S*T}const L=U.et();let C=new Point;Geo.On(x.startX+P,x.startY+S,x.endX+P,x.endY+S,d,m,g,p,C)&&L.push(C),C=new Point,Geo.On(x.startX-P,x.startY-S,x.endX-P,x.endY-S,d,m,g,p,C)&&L.push(C),C=new Point,Geo.On(x.startX+P,x.startY+S,x.startX-P,x.startY-S,d,m,g,p,C)&&L.push(C),C=new Point,Geo.On(x.endX+P,x.endY+S,x.endX-P,x.endY-S,d,m,g,p,C)&&L.push(C);const M=L.length;if(M===0)return U.J(L),!1;b=!0;let N=1/0;for(let T=0;T0&&k.contains(D,F)&&(M.x=D,M.y=F,this.containsPoint(M)))for(N!==0&&Math.abs(N)<.5?(T*=.5/N,N=.5):T!==0&&Math.abs(T)<.5&&(N*=.5/T,T=.5),D-=N,F-=T;k.contains(D,F);)D-=N,F-=T;const v=.6;n.x=g,n.y=p;for(let Y=0;Ye?t-e:e-t)<(i>s?i-s:s-i)){const f=if||Geo.z(h.y,f))&&(h.yf||Geo.z(h.x,f))&&(h.x=c&&h<=a}else{let c=0,a=0;return s=c&&l<=a}}Gv(t,i){if(this.containedInRect(t,i)||i===void 0&&(i=this.T,t.containsRect(this.actualBounds)))return!0;const e=t.left,s=t.right,n=t.top,o=t.bottom,r=Point.l(),l=Point.l(),h=Point.l(),c=Transform.l();c.set(i),c.NC(this.T),c.bw(),l.x=s,l.y=n,l.T(c),r.x=e,r.y=n,r.T(c);let a=!1;return this.Fa(r,l,h)?a=!0:(r.x=s,r.y=o,r.T(c),this.Fa(r,l,h)?a=!0:(l.x=e,l.y=o,l.T(c),this.Fa(r,l,h)?a=!0:(r.x=e,r.y=n,r.T(c),this.Fa(r,l,h)&&(a=!0)))),Transform.e(c),Point.e(r),Point.e(l),Point.e(h),a}xA(t,i,e){if(e&&this.fill!==null&&this.fh(t,!0))return!0;let s=t.distanceSquaredPoint(i);const n=s;this.strokeWidth>1.5&&(s=this.strokeWidth/2+Math.sqrt(s),s*=s);let o=this.ot;if(o===null&&(this.ht(1/0,1/0),o=this.ot,o===null))return!1;if(!e){const f=o.bounds,u=f.x,d=f.y,m=f.x+f.width,g=f.y+f.height;if(Point.distanceSquared(t.x,t.y,u,d)<=s&&Point.distanceSquared(t.x,t.y,m,d)<=s&&Point.distanceSquared(t.x,t.y,u,g)<=s&&Point.distanceSquared(t.x,t.y,m,g)<=s)return!0}function r(f,u){const d=f.length;for(let m=0;ms)return!0;return!1}const l=o.startX,h=o.startY,c=o.endX,a=o.endY;if(o.type===1){const f=Point.distanceLineSegmentSquared(t.x,t.y,l,h,c,a),u=(c-l)*(t.x-l)+(a-h)*(t.y-h),d=(l-c)*(t.x-c)+(h-a)*(t.y-a),m=u>=0&&d>=0?s:n;return f<=m}else if(o.type===2){let f=!1;return e&&(f=Point.distanceLineSegmentSquared(t.x,t.y,l,h,l,a)<=s||Point.distanceLineSegmentSquared(t.x,t.y,l,h,c,h)<=s||Point.distanceLineSegmentSquared(t.x,t.y,c,h,c,a)<=s||Point.distanceLineSegmentSquared(t.x,t.y,l,a,c,a)<=s),f}else if(o.type===3){const f=(l+c)/2,u=(h+a)/2,d=t.x-f,m=t.y-u,g=Math.abs(c-l)/2,p=Math.abs(a-h)/2;if(g===0||p===0)return Point.distanceLineSegmentSquared(t.x,t.y,l,h,c,a)<=s;if(e){const w=Geo.iF(g,p,d,m);return w*w<=s}else return!(Point.distanceSquared(d,m,-g,0)>=s||Point.distanceSquared(d,m,0,-p)>=s||Point.distanceSquared(d,m,0,p)>=s||Point.distanceSquared(d,m,g,0)>=s)}else if(o.type===4){const f=o.bounds,u=f.x,d=f.y,m=f.x+f.width,g=f.y+f.height;if(t.x>m&&t.xg&&t.ys&&Point.distanceLineSegmentSquared(t.x,t.y,u,d,m,d)>s&&Point.distanceLineSegmentSquared(t.x,t.y,m,g,u,g)>s&&Point.distanceLineSegmentSquared(t.x,t.y,m,g,m,d)>s)return!1;const p=Math.sqrt(s);if(e){if(this.fill===null?o.EC(t.x,t.y,p):o.qk(t,p,!0,!1))return!0}else{const w=o.figures;for(let x=0;xs)return!1;const S=k.segments.r,L=S.length;for(let C=0;Cs)return!1;break;case 3:{const N=U.et();Geo.vn(b,P,M.point1X,M.point1Y,M.point2X,M.point2Y,M.endX,M.endY,.8,N);const T=r(N,t);if(U.J(N),T||(b=M.endX,P=M.endY,t.distanceSquared(b,P)>s))return!1;break}case 4:{const N=U.et();Geo.Og(b,P,M.point1X,M.point1Y,M.endX,M.endY,.8,N);const T=r(N,t);if(U.J(N),T||(b=M.endX,P=M.endY,t.distanceSquared(b,P)>s))return!1;break}case 5:case 6:{const N=M.type===5?M.bo(k):M.Bh(k,b,P),T=N.length;if(T===0){if(b=M.type===5?M.centerX:M.endX,P=M.type===5?M.centerY:M.endY,t.distanceSquared(b,P)>s)return!1;break}let A=null;const D=U.et();for(let F=0;F=0){this.Vo=t,this.c();const e=this.part;e!==null&&e.cf(),this.t("strokeWidth",i,t)}else U.W(t,"value >= 0",Shape,"strokeWidth:value")}y0(){return this.Vo}get strokeCap(){return this.jt!==null?this.jt.gp:"butt"}set strokeCap(t){const i=this.strokeCap;i!==t&&(typeof t=="string"&&(t==="butt"||t==="round"||t==="square")?(this.Da().gp=t,this.S(),this.t("strokeCap",i,t)):U.W(t,'"butt", "round", or "square"',Shape,"strokeCap"))}get strokeJoin(){return this.jt!==null?this.jt.mp:"miter"}set strokeJoin(t){const i=this.strokeJoin;i!==t&&(typeof t=="string"&&(t==="miter"||t==="bevel"||t==="round")?(this.Da().mp=t,this.S(),this.t("strokeJoin",i,t)):U.W(t,'"miter", "bevel", or "round"',Shape,"strokeJoin"))}get strokeMiterLimit(){return this.jt!==null?this.jt.pp:10}set strokeMiterLimit(t){const i=this.strokeMiterLimit;if(i!==t&&t>=1){this.Da().pp=t,this.S();const e=this.part;e!==null&&e.cf(),this.t("strokeMiterLimit",i,t)}}get strokeDashArray(){return this.Io}set strokeDashArray(t){const i=this.Io;if(i!==t){if(t!==null&&!Array.isArray(t)&&U.Zi(t,"Array",Shape,"strokeDashArray:value"),t!==null){const e=t.length;let s=0;for(let n=0;n=0)||!isFinite(o))&&U.o("strokeDashArray:value "+o+" at index "+n+" must be a positive number or zero."),s+=o}if(s===0){if(i===null)return;t=null}}this.Io=t,this.S(),this.t("strokeDashArray",i,t)}}get strokeDashOffset(){return this.jt!==null?this.jt.ph:0}set strokeDashOffset(t){const i=this.strokeDashOffset;i!==t&&t>=0&&(this.Da().ph=t,this.S(),this.t("strokeDashOffset",i,t))}get figure(){return this.gd}set figure(t){const i=this.gd;if(i!==t){let e=Geo.In[t];if(U.it(e)?e=t:(e=Geo.In[t.toLowerCase()],e||U.o("Unknown Shape.figure: "+t)),i!==e){const s=this.part;s!==null&&s.cf(),this.gd=e,this.ks=null,this.ee(),this.c(),this.t("figure",i,e)}}}get toArrow(){return this.Ot!==null?this.Ot.yp:"None"}set toArrow(t){const i=this.toArrow;if(t===!0?t="Standard":t===!1&&(t=""),i!==t){const e=Shape.qA(t);e===null?U.o("Unknown Shape.toArrow: "+t):i!==e&&(this.Ot===null&&(this.Ot=new LinkElementSettings),this.Ot.yp=e,this.ks=null,this.ee(),this.c(),this.WA(e),this.t("toArrow",i,e))}}get fromArrow(){return this.Ot!==null?this.Ot.wp:"None"}set fromArrow(t){const i=this.fromArrow;if(t===!0?t="Standard":t===!1&&(t=""),i!==t){const e=Shape.qA(t);e===null?U.o("Unknown Shape.fromArrow: "+t):i!==e&&(this.Ot===null&&(this.Ot=new LinkElementSettings),this.Ot.wp=e,this.ks=null,this.ee(),this.c(),this.WA(e),this.t("fromArrow",i,e))}}WA(t){const i=this.diagram;if(i!==null&&i.undoManager.isUndoingRedoing)return;this.iv();const e=Spot.MiddleRight;this.toArrow!=="None"?(this.segmentIndex=-1,this.alignmentFocus=e):this.fromArrow!=="None"&&(this.segmentIndex=0,this.alignmentFocus=new Spot(1-e.x,e.y))}get spot1(){return this.jt!==null?this.jt.En:Spot.Default}set spot1(t){const i=this.spot1;i.equals(t)||(t=t.P(),this.Da().En=t,this.c(),this.t("spot1",i,t))}get spot2(){return this.jt!==null?this.jt.Un:Spot.Default}set spot2(t){const i=this.spot2;i.equals(t)||(t=t.P(),this.Da().Un=t,this.c(),this.t("spot2",i,t))}get parameter1(){return this.md}set parameter1(t){const i=this.md;i!==t&&(this.md=t,this.ee(),this.c(),this.t("parameter1",i,t))}get parameter2(){return this.pd}set parameter2(t){const i=this.pd;i!==t&&(this.pd=t,this.ee(),this.c(),this.t("parameter2",i,t))}get naturalBounds(){return this.zi}kv(){const t=this.desiredSize;if(!t.isReal()&&this.ot!==null){const i=this.ot.bounds;this.zi.a(i)}else this.zi.i(0,0,t.width,t.height)}get pathPattern(){return this.jt!==null?this.jt.xp:null}set pathPattern(t){const i=this.pathPattern;i!==t&&(this.Da().xp=t,this.S(),this.t("pathPattern",i,t))}get geometryStretch(){return this.jt!==null?this.jt.bp:1}set geometryStretch(t){const i=this.geometryStretch;i!==t&&(this.Da().bp=t,this.c(),this.t("geometryStretch",i,t))}get interval(){return this.K!==null?this.K.uf:1}set interval(t){const i=this.interval;if(t=Math.round(t),i!==t&&t!==0&&isFinite(t)){this.K===null&&(this.K=new GradElementSettings),this.K.uf=t;const e=this.diagram;e!==null&&this.panel===e.grid&&e.th(),this.c();const s=this.panel;s!==null&&(s.ss=null),this.t("interval",i,t)}}get graduatedStart(){return this.K!==null?this.K.df:0}set graduatedStart(t){const i=this.graduatedStart;i!==t&&(t<0?t=0:t>1&&(t=1),this.K===null&&(this.K=new GradElementSettings),this.K.df=t,this.c(),this.t("graduatedStart",i,t))}get graduatedEnd(){return this.K!==null?this.K.gf:1}set graduatedEnd(t){const i=this.graduatedEnd;i!==t&&(t<0?t=0:t>1&&(t=1),this.K===null&&(this.K=new GradElementSettings),this.K.gf=t,this.c(),this.t("graduatedEnd",i,t))}get graduatedSkip(){return this.K!==null?this.K.mf:null}set graduatedSkip(t){const i=this.graduatedSkip;i!==t&&(t!==null&&U.k(t,Shape,"graduatedSkip"),this.K===null&&(this.K=new GradElementSettings),this.K.mf=t,this.c(),this.t("graduatedSkip",i,t))}static zv(t,i,e){let n=null;if(t.toArrow!=="None")n=Shape.gn[t.toArrow];else if(t.fromArrow!=="None")n=Shape.gn[t.fromArrow];else{let o=Geo.In[t.figure];typeof o=="string"&&(o=Geo.In[o]),o===void 0&&U.o("Unknown Shape.figure: "+t.figure),n=o(t,i,e),n.rc=i,n.lc=e}if(n===null){const o=Geo.In.Rectangle;U.it(o)&&(n=o(t,i,e))}return n}static getFigureGenerators(){const t=new GMap;for(const i in Geo.In){if(i===i.toLowerCase())continue;const e=Geo.In[i];t.set(i,e)}return t.u(),t}static defineFigureGenerator(t,i){U.s(t,"string",Shape,"defineFigureGenerator:name"),typeof i=="string"||U.k(i,Shape,"defineFigureGenerator:func");const e=t.toLowerCase(),s=Geo.In;s[t]=i,s[e]=t}static isFigureDefined(t){return Geo.In.has(t)}static getArrowheadGeometries(){const t=new GMap;for(const i in Geo.Bg)if(Shape.gn[i]===void 0){const e=Geometry.parse(Geo.Bg[i],!1);Shape.gn[i]=e;const s=i.toLowerCase();s!==i&&(Shape.gn[s]=i)}for(const i in Shape.gn){if(i===i.toLowerCase())continue;const e=Shape.gn[i];e instanceof Geometry&&t.set(i,e)}return t.u(),t}static defineArrowheadGeometry(t,i){U.s(t,"string",Shape,"defineArrowheadGeometry:name");let e=null;typeof i=="string"?(U.s(i,"string",Shape,"defineArrowheadGeometry:pathstr"),e=Geometry.parse(i,!1)):e=i;const s=t.toLowerCase();(s==="none"||t===s)&&U.o("Shape.defineArrowheadGeometry name must not be empty or None or all-lower-case: "+t);const n=Shape.gn;n[t]=e,n[s]=t}static isArrowheadDefined(t){return Shape.gn.has(t)}static gn=new PropertyCollection;static q2=new PropertyCollection;static qA(t){let i=Shape.gn[t];if(i===void 0){const e=t.toLowerCase();if(e==="none")return"None";if(i=Shape.gn[e],i===void 0){let s=null;for(const n in Geo.Bg)if(n.toLowerCase()===e){s=n;break}if(s!==null){const n=Geometry.parse(Geo.Bg[s],!1);return Shape.gn[s]=n,e!==s&&(Shape.gn[e]=s),s}}}return typeof i=="string"?i:i instanceof Geometry?t:null}}class ShapeTemplateSettings{fi;gp;mp;pp;ph;xp;bp;En;Un;constructor(){this.fi=!1,this.gp="butt",this.mp="miter",this.pp=10,this.ph=0,this.xp=null,this.bp=1,this.En=Spot.Default,this.Un=Spot.Default}copy(){const t=new ShapeTemplateSettings;return t.gp=this.gp,t.mp=this.mp,t.pp=this.pp,t.ph=this.ph,t.xp=this.xp,t.bp=this.bp,t.En=this.En.P(),t.Un=this.Un.P(),t}}var Wrap=(y=>(y[y.None=0]="None",y[y.Fit=1]="Fit",y[y.DesiredSize=2]="DesiredSize",y[y.BreakAll=3]="BreakAll",y))(Wrap||{}),TextOverflow=(y=>(y[y.Clip=0]="Clip",y[y.Ellipsis=1]="Ellipsis",y))(TextOverflow||{}),TextFormat=(y=>(y[y.Trim=0]="Trim",y[y.None=1]="None",y))(TextFormat||{});class TextBlock extends GraphObject{ri;ji;mn;ge;ui;w0;wd;K;rt;Dl;io;pn;Ce;Ti;yn;constructor(t,i){return super(),TextBlock.W0===!1&&(TextBlock.W0=!0,TextBlock._n=Diagram.isUsingDOM()?new CanvasSurface(null).li:null),this.n|=2097152,this.ri="",this.ji="black",this.mn="13px sans-serif",this.ge=0,this.ui=0,this.w0=0,this.wd=null,this.K=null,this.rt=null,this.Dl=0,this.io=null,this.pn=0,this.Ce=null,this.Ti=null,this.yn=null,typeof t=="string"?this.text=t:t&&Object.assign(this,t),i&&Object.assign(this,i),this}cloneProtected(t){super.cloneProtected(t),t.ri=this.ri,t.ji=this.ji,t.mn=this.mn,t.ge=this.ge,t.ui=this.ui,t.w0=this.w0,t.wd=this.wd,this.K!==null&&(t.K=this.K.copy()),this.rt!==null&&(this.rt.fi?t.rt=this.rt:t.rt=this.rt.copy()),t.Dl=this.Dl,t.io=this.io,t.pn=this.pn,t.Ce=this.Ce,t.Ti=this.Ti,t.yn=this.yn}wn(){return this.rt===null?this.rt=new TextBlockTemplateSettings:this.rt.fi&&(this.rt=this.rt.copy()),this.rt}ch(){super.ch(),this.rt!==null&&(this.rt.fi=!0)}Av(t){this.n=t.n|2048|4096,this.$t=t.opacity,this.Lt=t.background,this.is=t.desiredSize.P(),this.minSize=t.minSize.P(),this.maxSize=t.maxSize.P(),t.wi!==null?this.wi=t.wi.copy():this.wi=null,this.tt=t.scale,this.Yt=t.angle,this.stretch=t.stretch,this.Wr=t.margin.P(),this.hi=t.alignment.P(),this.ju=t.alignmentFocus.P(),this.segmentFraction=t.segmentFraction,this.segmentOffset=t.segmentOffset.P(),this.segmentOrientation=t.segmentOrientation,t.si!==null&&(this.si=t.si.copy()),this.shadowVisible=t.shadowVisible,this.ri=t.ri,this.ji=t.ji,this.mn=t.mn,this.K!==null&&(this.K=t.K.copy()),t.rt!==null&&(t.rt.fi?this.rt=t.rt:this.rt=t.rt.copy()),this.Dl=t.Dl}Cv(t){if(this.ri=t.text||"",this.Yt=t.labelAngle||0,this.ge=t.lineCount||0,this.Kv(t.lines),t.naturalBounds&&(this.zi=t.naturalBounds),t.actualBounds){const i=t.actualBounds;this.Bt(i.x,i.y,i.width,i.height)}}oi(t){t in Wrap?this.wrap=t:super.oi(t)}toString(){return this.ri.length>22?'TextBlock("'+this.ri.substring(0,20)+'"...)':'TextBlock("'+this.ri+'")'}static getEllipsis(){return TextBlock.kp}static setEllipsis(t){TextBlock.kp=t,TextBlock.l1=new PropertyCollection,TextBlock.W2=0}static getBaseline(){return TextBlock.h1}static setBaseline(t){TextBlock.h1=t}static h1=null;static getUnderline(){return TextBlock.a1}static setUnderline(t){TextBlock.a1=t}static a1=null;static None=0;static WrapFit=1;static WrapDesiredSize=2;static WrapBreakAll=3;static OverflowClip=0;static OverflowEllipsis=1;static FormatTrim=0;static FormatNone=1;c(){super.c(),this.Ve(!0)}get font(){return this.mn}set font(t){const i=this.mn;i!==t&&(this.mn=t,this.io=null,this.c(),this.t("font",i,t))}static isValidFont(t){return root.CSS?root.CSS.supports("font",t):!0}get text(){return this.ri}set text(t){const i=this.ri;t!=null?t=t.toString():t="",i!==t&&(this.ri=t,this.c(),this.t("text",i,t))}get textAlign(){return this.rt!==null?this.rt.Pp:"start"}set textAlign(t){const i=this.textAlign;i!==t&&(t==="start"||t==="end"||t==="left"||t==="right"||t==="center")&&(this.wn().Pp=t,this.S(),this.t("textAlign",i,t))}get flip(){return this.rt!==null?this.rt.eo:0}set flip(t){const i=this.flip;i!==t&&(this.wn().eo=t,this.S(),this.t("flip",i,t))}get verticalAlignment(){return this.rt!==null?this.rt.tl:Spot.Top}set verticalAlignment(t){const i=this.verticalAlignment;i.equals(t)||(t=t.P(),this.wn().tl=t,this.ef(),this.t("verticalAlignment",i,t))}get naturalBounds(){if(!this.zi.isReal()){const t=Size.l();this.J2(this.ri,999999,t);let i=t.width;Size.e(t);let e=this.JA(i);const s=this.desiredSize;isNaN(s.width)||(i=s.width),isNaN(s.height)||(e=s.height),this.zi.Fn(i,e)}return this.zi}get isMultiline(){return(this.n&2097152)!==0}set isMultiline(t){const i=(this.n&2097152)!==0;i!==t&&(this.n=this.n^2097152,this.c(),this.t("isMultiline",i,t))}get isUnderline(){return(this.n&4194304)!==0}set isUnderline(t){const i=(this.n&4194304)!==0;i!==t&&(this.n=this.n^4194304,this.Ve(!0),this.S(),this.t("isUnderline",i,t))}get isStrikethrough(){return(this.n&8388608)!==0}set isStrikethrough(t){const i=(this.n&8388608)!==0;i!==t&&(this.n=this.n^8388608,this.Ve(!0),this.S(),this.t("isStrikethrough",i,t))}get wrap(){return this.rt!==null?this.rt.Sp:2}set wrap(t){const i=this.wrap;i!==t&&(this.wn().Sp=t,this.c(),this.t("wrap",i,t))}get overflow(){return this.rt!==null?this.rt.Mp:0}set overflow(t){const i=this.overflow;i!==t&&(this.wn().Mp=t,this.c(),this.t("overflow",i,t))}get isOverflowed(){return(this.n&16777216)!==0}$2(t){t?this.n|=16777216:this.n&=-16777217}get stroke(){return this.ji}set stroke(t){const i=this.ji;i!==t&&(t!==null&&Brush.Qu(t,"TextBlock.stroke"),t instanceof Brush&&t.u(),this.ji=t,typeof t!="string"&&this.Qc(),this.S(),this.t("stroke",i,t))}get lineCount(){return this.ge}get lineHeight(){return this.Np()}get editable(){return(this.n&1048576)!==0}set editable(t){const i=(this.n&1048576)!==0;i!==t&&(this.n=this.n^1048576,this.t("editable",i,t))}get V2(){return(this.n&33554432)!==0}set V2(t){this.n=this.n^33554432}get textEditor(){return this.rt!==null?this.rt.Cp:null}set textEditor(t){const i=this.textEditor;i!==t&&(this.wn().Cp=t,this.t("textEditor",i,t))}get errorFunction(){return this.rt!==null?this.rt.ns:null}set errorFunction(t){const i=this.errorFunction;i!==t&&(t!==null&&U.k(t,TextBlock,"errorFunction"),this.wn().ns=t,this.t("errorFunction",i,t))}get interval(){return this.K!==null?this.K.uf:1}set interval(t){const i=this.interval;if(t=Math.round(t),i!==t&&t!==0&&isFinite(t)){this.K===null&&(this.K=new GradElementSettings),this.K.uf=t,this.c();const e=this.panel;e!==null&&(e.ss=null),this.t("interval",i,t)}}get graduatedStart(){return this.K!==null?this.K.df:0}set graduatedStart(t){const i=this.graduatedStart;i!==t&&(t<0?t=0:t>1&&(t=1),this.K===null&&(this.K=new GradElementSettings),this.K.df=t,this.c(),this.t("graduatedStart",i,t))}get graduatedEnd(){return this.K!==null?this.K.gf:1}set graduatedEnd(t){const i=this.graduatedEnd;i!==t&&(t<0?t=0:t>1&&(t=1),this.K===null&&(this.K=new GradElementSettings),this.K.gf=t,this.c(),this.t("graduatedEnd",i,t))}get graduatedFunction(){return this.K!==null?this.K.Lp:null}set graduatedFunction(t){const i=this.graduatedFunction;i!==t&&(t!==null&&U.k(t,TextBlock,"graduatedFunction"),this.K===null&&(this.K=new GradElementSettings),this.K.Lp=t,this.c(),this.t("graduatedFunction",i,t))}get graduatedSkip(){return this.K!==null?this.K.mf:null}set graduatedSkip(t){const i=this.graduatedSkip;i!==t&&(t!==null&&U.k(t,TextBlock,"graduatedSkip"),this.K===null&&(this.K=new GradElementSettings),this.K.mf=t,this.c(),this.t("graduatedSkip",i,t))}gh(t,i){if(this.ji===null||this.ri.length===0||this.mn===null)return;const e=this.naturalBounds,s=this.actualBounds,n=e.width,o=e.height,r=this.Np();let l=t.textAlign=this.textAlign;const h=i.zu;l==="start"?l=h?"right":"left":l==="end"&&(l=h?"left":"right");const c=this.isUnderline,a=this.isStrikethrough;this.rn(t,this.ji,!0,!1,e,s),(c||a)&&this.rn(t,this.ji,!1,!1,e,s);const f=0;let u=0;const d=n;let m=!1;i.Qt===t&&!(i.Qt instanceof SVGContext)&&!this.V2&&i.getRenderingHint("textGreeking")===!0&&r*this.da*i.scale<3&&(m=!0);const g=this.spacingAbove,p=this.spacingBelow;switch(this.flip){case 0:break;case 2:t.translate(n,0),t.scale(-1,1);break;case 1:t.translate(0,o),t.scale(1,-1);break;case 3:t.translate(n,o),t.scale(-1,-1);break}t.commitTransform();const w=this.ge,k=(g+r+p)*w;if(o>k){const b=this.verticalAlignment;u=b.y*o-b.y*k+b.offsetY}if(w===1&&this.yn!==null){let b=this.ui;b>d&&(b=d),u+=g,this.$A(this.yn,t,f,u,d,r,b,m,l,c,a)}else if(this.Ce!==null&&this.Ti!==null)for(let b=0;bd&&(P=d),u+=g,this.$A(this.Ti[b],t,f,u,d,r,P,m,l,c,a),u+=r+p}switch(this.flip){case 0:break;case 2:t.scale(-1,1),t.translate(-n,0);break;case 1:t.scale(1,-1),t.translate(0,-o);break;case 3:t.scale(-1,-1),t.translate(-n,-o);break}}$A(t,i,e,s,n,o,r,l,h,c,a){let f=0;if(l){h==="left"?f=0:h==="right"?f=n-r:h==="center"&&(f=(n-r)/2);const m=i.globalAlpha;i.globalAlpha=m/2,i.fillRect(e+f,s+o/4,r,o/2),i.globalAlpha=m;return}h==="left"?f=0:h==="right"?f=n:h==="center"&&(f=n/2);const u=TextBlock.h1!==null?TextBlock.h1(this,o):o*.75;i.fillText(t,e+f,s+u);let d=o/20|0;if(d===0&&(d=1),h==="right"?f-=r:h==="center"&&(f-=r/2),c){const m=TextBlock.a1!==null?TextBlock.a1(this,o):o*.8;this.ZA(e+f,s+m,e+f+r,s+m,d,i),i instanceof SVGContext&&i.lastCreatedElement.classList.add("gojs-td")}if(a){let m=s+o-o/2.2|0;d%2!==0&&(m+=.5),this.ZA(e+f,m,e+f+r,m,d,i),i instanceof SVGContext&&i.lastCreatedElement.classList.add("gojs-td")}}ZA(t,i,e,s,n,o){o.beginPath(),o.lineWidth=n,o.moveTo(t,i),o.lineTo(e,s),o.stroke(),o.endPath()}Zc(t,i,e){if(!super.Zc(t,i,e))return!1;if(this.rn(t,this.ji,!0,!1,this.naturalBounds,this.actualBounds),e){if(this.svg.getElementsByTagName("text").length===0)return!0;const n=this.svg.getElementsByClassName("gojs-td");for(let o=0;o1||this.isUnderline||this.isStrikethrough?!0:super.$u(t)}k2(t,i){if(t.nodeName!=="g")t.setAttributeNS(null,"filter",i);else{const e=t.getElementsByTagName("text");for(let s=0;sthis.maxLines&&(this.n|=16777216))}J2(t,i,e){const s=this.formatting===0;s&&(t=t.trim());let n=0,o=0,r=0;const l=this.mn,h=this.spacingAbove+this.spacingBelow,c=Math.max(0,this.Np()+h),a=this.overflow===1?this._A(l):0;if(this.ge>=this.maxLines){e!==null&&e.i(0,c);return}let f=t;if(this.wrap===0){if(this.pn=1,o=this.getStringWidth(t),a===0||o<=i){this.ui=Math.max(this.ui,o),this.xn(t,this.ui),e!==null&&e.i(o,c);return}let d=this.xd(f);f=f.substring(d.length);let m=this.xd(f);for(o=this.getStringWidth(d+m),r=0;m.length>0&&o<=i;){d+=m,f=f.substring(m.length),m=this.xd(f),r=o;let g=d+m;s&&(g=g.trim()),o=this.getStringWidth(g)}for(s&&(m=m.trim()),d+=m,i=Math.max(1,i-a);this.getStringWidth(d)>i&&d.length>1;)d=d.substring(0,d.length-1);this.$2(!0),d+=TextBlock.kp,r=this.getStringWidth(d),this.ui=r,this.xn(d,r),e!==null&&e.i(r,c);return}let u=0;for(f.length===0&&(u=1,this.xn(f,0));f.length>0;){let d=this.xd(f);for(f=f.substring(d.length);this.getStringWidth(d)>i;){let p=1;for(o=this.getStringWidth(d.substring(0,p)),r=0;o<=i;)p++,r=o,o=this.getStringWidth(d.substring(0,p));let w=0;p===1?(w=o,n=Math.max(n,o)):(w=r,n=Math.max(n,r)),p--,p<1&&(p=1);const x=d.substring(0,p);if(this.xn(x,w),u++,d=d.substring(p),this.ge+u>this.maxLines)break}let m=this.xd(f);for(o=this.getStringWidth(d+m),r=0;m.length>0&&o<=i;){d+=m,f=f.substring(m.length),m=this.xd(f),r=o;let p=d+m;s&&(p=p.trim()),o=this.getStringWidth(p)}if(s&&(d=d.trim()),d==="")continue;d[d.length-1]==="\xAD"&&(d=d.substring(0,d.length-1)+"\u2010");let g=0;if(m.length===0?(g=o,n=Math.max(n,o)):(r=this.getStringWidth(d),g=r,n=Math.max(n,r)),this.xn(d,g),u++,this.ge+u>this.maxLines)break}this.pn=Math.min(this.maxLines-this.ge,u),this.ui=Math.max(this.ui,n),e!==null&&e.i(this.ui,c*this.pn)}Wv(t,i){if(this.ui===0||this.Ce===null||this.Ti===null||this.overflow!==1)return;const e=this.mn,s=this.overflow===1?this._A(e):0,n=this.spacingAbove+this.spacingBelow,o=Math.max(0,this.Np()+n),r=Math.min(this.maxLines-1,Math.max(Math.floor(i/o+.01)-1,0));if(r+1>=this.Ti.length)return;this.$2(!0);let l=this.Ti[r];const h=Math.max(1,t-s);for(;this.getStringWidth(l)>h&&l.length>1;)l=l.substring(0,l.length-1);l+=TextBlock.kp;const c=this.getStringWidth(l);this.Ti[r]=l,this.Ti=this.Ti.slice(0,r+1),this.Ce[r]=c,this.Ce=this.Ce.slice(0,r+1),this.pn=this.Ti.length,this.ui=Math.max(this.ui,c),this.ge=this.pn,this.ge===1&&(this.yn=this.Ti[0])}xd(t){if(this.wrap===3)return t.substring(0,1);let i=t.length,e=0;const s=TextBlock.Jv;for(;e=t.length?t:t.substring(0,e)}getStringWidth(t){return TextBlock._n===null?t.length*8:TextBlock._n.measureText(t).width}Np(){if(this.io!==null)return this.io;const t=this.mn;let i=0;return TextBlock._n===null?(i=16,this.io=i,i):(TextBlock.Z2[t]!==void 0&&TextBlock.tT<5e3?i=TextBlock.Z2[t]:(i=TextBlock._n.measureText("M").width*1.3,TextBlock.Z2[t]=i,TextBlock.tT++),this.io=i,i)}_A(t){if(TextBlock._n===null)return 6;let i=0;return TextBlock.l1[t]!==void 0&&TextBlock.W2<5e3?i=TextBlock.l1[t]:(i=TextBlock._n.measureText(TextBlock.kp).width,TextBlock.l1[t]=i,TextBlock.W2++),i}c1(t,i){return t.indexOf(` `,i)}JA(t){let i=this.ri.replace(/\r\n/g,` `).replace(/\r/g,` `);const e=this.spacingAbove+this.spacingBelow,s=Math.max(0,this.Np()+e);if(i.length===0)return this.ui=0,this.ge=1,s;if(!this.isMultiline){const h=this.c1(i,0);h>=0&&(i=i.substring(0,h))}let n=0;this.ge=0;let o=0,r=-1,l=!1;for(;!l;){if(r=this.c1(i,o),r===-1&&(r=i.length,l=!0),o<=r){const h=i.substring(o,r);if(this.wrap!==0){this.pn=0;const c=Size.l();this.J2(h,t,c),n+=c.height,Size.e(c),this.ge+=this.pn}else this.J2(h,t,null),n+=s,this.ge++;this.ge===this.maxLines&&(l=!0)}o=r+1}return this.w0=n,n}qv(){let t=this.ri.replace(/\r\n/g,` `).replace(/\r/g,` `);if(t.length===0)return 8;if(this.isMultiline){let i=0,e=0,s=!1;for(;!s;){let n=this.c1(t,e);n===-1&&(n=t.length,s=!0);let o=t.substring(e,n);this.formatting===0&&(o=o.trim()),i=Math.max(i,this.getStringWidth(o)),e=n+1}return i}else{const i=this.c1(t,0);return i>=0&&(t=t.substring(0,i)),this.getStringWidth(t)}}get textValidation(){return this.rt!==null?this.rt.Tl:null}set textValidation(t){const i=this.textValidation;i!==t&&(t!==null&&U.k(t,TextBlock,"textValidation"),this.wn().Tl=t,this.t("textValidation",i,t))}get textEdited(){return this.rt!==null?this.rt.Ap:null}set textEdited(t){const i=this.textEdited;i!==t&&(t!==null&&U.k(t,TextBlock,"textEdited"),this.wn().Ap=t,this.t("textEdited",i,t))}get spacingAbove(){return this.rt!==null?this.rt.Tp:0}set spacingAbove(t){const i=this.spacingAbove;i!==t&&(this.wn().Tp=t,this.c(),this.t("spacingAbove",i,t))}get spacingBelow(){return this.rt!==null?this.rt.Dp:0}set spacingBelow(t){const i=this.spacingBelow;i!==t&&(this.wn().Dp=t,this.c(),this.t("spacingBelow",i,t))}get formatting(){return this.rt!==null?this.rt.Fp:0}set formatting(t){const i=this.formatting;i!==t&&(this.wn().Fp=t,this.c(),this.t("formatting",i,t))}get maxLines(){return this.rt!==null?this.rt.Rp:1/0}set maxLines(t){const i=this.maxLines;i!==t&&(t=Math.floor(t),t<=0&&U.W(t,"> 0",TextBlock,"maxLines"),this.wn().Rp=t,this.c(),this.t("maxLines",i,t))}getMetrics(){return[this.ui,this.Dl,this.io,this.pn,this.Ce,this.Ti,this.yn]}Kv(t){t!==void 0&&(this.ui=t[0],this.Dl=t[1],this.io=t[2],this.pn=t[3],this.Ce=t[4],this.Ti=t[5],this.yn=t[6])}get metrics(){return{arrSize:this.Ce!==null?this.Ce:[this.ui],arrText:this.Ti!==null?this.Ti:[this.yn],maxLineWidth:this.ui,fontHeight:this.io}}get choices(){return this.wd}set choices(t){const i=this.wd;i!==t&&(this.wd=t,this.t("choices",i,t))}static Jv=new RegExp("[ \u200B\xAD]");static Z2=new PropertyCollection;static tT=0;static l1=new PropertyCollection;static W2=0;static kp="...";static QA="";static _n=null;static W0=!1}class TextBlockTemplateSettings{fi;ns;eo;Fp;Rp;Mp;Tp;Dp;Pp;Ap;Cp;Tl;tl;Sp;constructor(){this.fi=!1,this.ns=null,this.eo=0,this.Fp=0,this.Rp=1/0,this.Mp=0,this.Tp=0,this.Dp=0,this.Pp="start",this.Ap=null,this.Cp=null,this.Tl=null,this.tl=Spot.Top,this.Sp=2}copy(){const t=new TextBlockTemplateSettings;return t.ns=this.ns,t.eo=this.eo,t.Fp=this.Fp,t.Rp=this.Rp,t.Mp=this.Mp,t.Tp=this.Tp,t.Dp=this.Dp,t.Pp=this.Pp,t.Ap=this.Ap,t.Cp=this.Cp,t.Tl=this.Tl,t.tl=this.tl,t.Sp=this.Sp,t}}class GradElementSettings{uf;df;gf;Lp;mf;constructor(){this.uf=1,this.df=0,this.gf=1,this.Lp=null,this.mf=null}copy(){const t=new GradElementSettings;return t.uf=this.uf,t.df=this.df,t.gf=this.gf,t.Lp=this.Lp,t.mf=this.mf,t}}var ImageStretch=(y=>(y[y.None=0]="None",y[y.Fill=2]="Fill",y[y.Uniform=6]="Uniform",y[y.UniformToFill=7]="UniformToFill",y))(ImageStretch||{});class Picture extends GraphObject{il;dt;el;pf;ns;sl;yf;eo;wf;xf;Yb;constructor(t,i){super(),this.n|=2097152,this.il=null,this.dt="",this.el=Rect.$D,this.pf=2,this.ns=null,this.sl=null,this.yf=Spot.Center,this.eo=0,this.wf=null,this.xf=null,this.Yb=null,typeof t=="string"?this.source=t:t&&Object.assign(this,t),i&&Object.assign(this,i)}cloneProtected(t){super.cloneProtected(t),t.dt=this.dt,t.element=this.il,t.el=this.el.P(),t.pf=this.pf,t.eo=this.eo,t.ns=this.ns,t.sl=this.sl,t.yf=this.yf.P(),t.xf=this.xf}oi(t){t in ImageStretch?this.imageStretch=t:super.oi(t)}toString(){return"Picture("+this.source+")#"+GSet.as(this)}get bf(){return(this.n&1048576)!==0}set bf(t){this.bf!==t&&(this.n=this.n^1048576)}get vp(){return(this.n&2097152)!==0}set vp(t){this.vp!==t&&(this.n=this.n^2097152)}get hn(){return(this.n&4194304)!==0}set hn(t){this.hn!==t&&(this.n=this.n^4194304)}static clearCache(t){t===void 0&&(t=""),U.s(t,"string",Picture,"clearCache:url"),t!==""?Picture.Op[t]&&(delete Picture.Op[t],Picture.f1--):(Picture.Op=new PropertyCollection,Picture.f1=0)}static tA(t,i){i.iT||(i.u1=e=>{Picture.$v(i,e),t.desiredSize.isReal()||(t.ue(!1),t.c())},i.d1=e=>Picture.Zv(i,e),i.addEventListener("load",i.u1),i.addEventListener("error",i.d1),i.iT=!0)}static BR(t){t.u1&&t.removeEventListener("load",t.u1),t.d1&&t.removeEventListener("error",t.d1),delete t.u1,delete t.d1,delete t.iT}get element(){return this.il}set element(t){const i=this.il;if(this.Ve(!0),i!==t){this.bf=t instanceof HTMLCanvasElement;const e=t instanceof HTMLImageElement;t!==null&&!(e||t instanceof HTMLVideoElement||this.bf)&&U.o("Picture.element must be an instance of Image, Canvas, or Video, not: "+t);const s=this.diagram;s!==null&&s.GM(this),this.il=t,t!==null&&e&&t.ts===void 0&&(t.ts=new GSet),s!==null&&e&&s.YM(this),this.t("element",i,t),this.S()}}ER(){const t=this.il;if(t===null)return;const i=this.desiredSize.isReal();(this.bf||t.complete===!0)&&(t.r0&&(t.Ip instanceof Event&&this.ns!==null?this.ns(this,t.Ip):t.hn===!0&&!t.Ip&&this.sl!==null&&t.Q2&&this.sl(this,t.Q2)),t.hn=!0),t.hn&&i&&this.diagram!==null&&this.diagram.Vu.add(this)}Qv(){if(this.il===null){this.wf=!1;return}const t=new CanvasSurface(null).li;try{t.drawImage(this.il,0,0)}catch{this.vp=!1}try{t.getImageData(0,0,1,1).data[3]&&(this.wf=!1),this.wf=!1}catch{this.wf=!0}}get source(){return this.dt}set source(t){const i=this.dt;if(i!==t){this.Ve(!0),U.s(t,"string",Picture,"source"),this.dt=t;let e=Picture.Op;if(!Diagram.isUsingDOM()){this.t("source",i,t);return}let s=null;if(e[t]!==void 0)s=e[t];else if(t!==""){Picture.f1>30&&(Picture.clearCache(),e=Picture.Op),s=U.hs("img"),s.r0=!0,Picture.tA(this,s);const n=this.xf;n!==null&&(s.crossOrigin=n(this)),s.src=t,e[t]=s,Picture.f1++}this.element=s,s!==null&&s.__goCache===void 0&&(s.__goCache=new PictureCacheArray),this.c(),this.S(),this.t("source",i,t)}}static $v(t,i){t.hn=!0,t.Ip=!1;let e;const s=t.ts.copy();if(s==null)return;const n=s.iterator;for(;n.next();){const o=n.value;o.S();const r=t.getAttribute("src")||"",l=o.Jl.get(r);if(l===null)continue;const h=l.length;for(let c=0;c=o.width&&(r=r+p.offsetX+(d*p.x-o.width*p.x)),m>=o.height&&(l=l+p.offsetY+(m*p.y-o.height*p.y)),c=Math.min(o.width,d),a=Math.min(o.height,m);break;case 2:d=o.width,m=o.height;break;case 6:case 7:let A=0;g===6?(A=Math.min(o.height/m,o.width/d),d*=A,m*=A):g===7&&(A=Math.max(o.height/m,o.width/d),d*=A,m*=A,d>=o.width&&(r=(r+p.offsetX+(d*p.x-o.width*p.x)/d)*c),m>=o.height&&(l=(l+p.offsetY+(m*p.y-o.height*p.y)/m)*a),c*=1/(d/o.width),a*=1/(m/o.height),d=o.width,m=o.height);break}const w=c*a,x=this.getDocumentScale()*i.scale,k=d*x,b=m*x,P=k*b,S=w/P,L=e.__goCache;let C=null;const M=Picture._v;if(!n){if(e.hn&&L!==void 0&&f<8e3&&u<8e3&&P>4&&S>M*M){L.Vt===null&&(L.eT(4,f,u,e),L.eT(16,f,u,e));const A=L.Vt,D=A.length;for(let F=0;F0){const a=this.Vt[this.Vt.length-1];h=a.dt,c=a.bd}o.setTransform(r*c,0,0,r*c,0,0),o.commitTransform(),o.drawImage(h,0,0),this.Vt.push(l)}}class PictureCacheInstance{dt;bd;constructor(t,i){this.dt=t,this.bd=i}}class GeoStream{bi;Gg;constructor(){this.Gg=new Geometry,this.bi=null}Ri(t){t!==null?(this.Gg=t,t.figures.clear()):this.Gg=new Geometry,this.bi=null}hu(t,i,e,s,n,o){if(s!==void 0&&s===!0){const r=new PathSegment(1);r.endX=t,r.endY=i,this.bi.segments.add(r)}else this.bi=new PathFigure,this.bi.startX=t,this.bi.startY=i,this.bi.isFilled=e,this.bi.isEvenOdd=o||!1,this.Gg.figures.add(this.bi);n!==void 0&&(this.bi.isShadowed=n)}rF(){const t=this.bi.segments.length;t>0&&this.bi.segments.elt(t-1).close()}lF(){this.bi.segments.length>0&&(this.bi.isFilled=!0)}hF(t){this.bi.isShadowed=t}RE(t){this.bi.isEvenOdd=t}sF(t,i,e){e===void 0&&(e=!1);const s=new PathSegment(1);s.endX=t,s.endY=i,e&&s.close(),this.bi.segments.add(s)}lr(t,i,e){e===void 0&&(e=!1);const s=new PathSegment(2);s.endX=t,s.endY=i,e&&s.close(),this.bi.segments.add(s)}hr(t,i,e,s,n,o,r){r===void 0&&(r=!1);const l=new PathSegment(3);l.point1X=t,l.point1Y=i,l.point2X=e,l.point2Y=s,l.endX=n,l.endY=o,r&&l.close(),this.bi.segments.add(l)}Cw(t,i,e,s,n){n===void 0&&(n=!1);const o=new PathSegment(4);o.point1X=t,o.point1Y=i,o.endX=e,o.endY=s,n&&o.close(),this.bi.segments.add(o)}nF(t,i,e,s,n,o,r){o===void 0&&(o=0),r===void 0&&(r=!1);const l=new PathSegment(5);l.startAngle=t,l.sweepAngle=i,l.centerX=e,l.centerY=s,l.radiusX=n,o!==0?l.radiusY=o:l.radiusY=n,r&&l.close(),this.bi.segments.add(l)}oF(t,i,e,s,n,o,r,l){l===void 0&&(l=!1);const h=new PathSegment(6,o,r,t,i,e,s,n);l&&h.close(),this.bi.segments.add(h)}static _2=null;static RC(t){const i=GeoStream._2;if(i!==null)return GeoStream._2=null,i.Ri(t),i;{const e=new GeoStream;return e.Ri(t),e}}static vC(t){GeoStream._2=t}}{const y=function(n,o){const r=n.toLowerCase(),l=Geo.In;l[n]=o,l[r]=n};y("Rectangle",(n,o,r)=>{const l="r"+o+","+r;let h=Geo.or[l];return h!==void 0||(h=new Geometry(2),h.endX=o,h.endY=r,Geo.rr{const l="s"+o+","+r;let h=Geo.or[l];return h!==void 0||(h=new Geometry(2),h.endX=o,h.endY=r,h.defaultStretch=6,Geo.rr{(isNaN(l)||l<0)&&(l=5),isNaN(h)&&(h=15);const c="rr"+o+","+r+","+l+","+h;let a=Geo.or[c];if(a!==void 0)return a;let f=l;(h&1)===1?(f=Math.min(f,(h&2)===2?o/3:o),f=Math.min(f,(h&8)===8?r/3:r)):f=0;const u=new PathFigure(f,0,!0);a=new Geometry().add(u);const d=Spot.TopLeft.copy(),m=Spot.BottomRight.copy();if((h&2)===2){let g=l;g=Math.min(g,(h&1)===1?o/3:o),g=Math.min(g,(h&4)===4?r/3:r);const p=g*Geo.Rn;u.add(new PathSegment(2,o-g,0)).add(new PathSegment(3,o,g,o-p,0,o,p)),d.offsetY=p,m.offsetX=-p}else u.add(new PathSegment(2,o,0));if((h&4)===4){let g=l;g=Math.min(g,(h&8)===8?o/3:o),g=Math.min(g,(h&2)===2?r/3:r);const p=g*Geo.Rn;u.add(new PathSegment(2,o,r-g)).add(new PathSegment(3,o-g,r,o,r-p,o-p,r)),m.offsetX=-p,m.offsetY=-p}else u.add(new PathSegment(2,o,r));if((h&8)===8){let g=l;g=Math.min(g,(h&4)===4?o/3:o),g=Math.min(g,(h&1)===1?r/3:r);const p=g*Geo.Rn;u.add(new PathSegment(2,g,r)).add(new PathSegment(3,0,r-g,p,r,0,r-p)),d.offsetX=p,m.offsetY=-p}else u.add(new PathSegment(2,0,r));if((h&1)===1){const g=f*Geo.Rn;u.add(new PathSegment(2,0,f)).add(new PathSegment(3,f,0,0,g,g,0).close()),d.offsetX=g,d.offsetY=g}else u.add(new PathSegment(2,0,0).close());return a.spot1=d,a.spot2=m,Geo.rr{const l=n?n.parameter1:NaN,h=n?n.parameter2:NaN;return t(n,o,r,l,h)}),y("Border","RoundedRectangle"),y("RoundedTopRectangle",(n,o,r)=>{const l=n?n.parameter1:NaN;return t(n,o,r,l,3)}),y("RoundedBottomRectangle",(n,o,r)=>{const l=n?n.parameter1:NaN;return t(n,o,r,l,12)}),y("RoundedLeftRectangle",(n,o,r)=>{const l=n?n.parameter1:NaN;return t(n,o,r,l,9)}),y("RoundedRightRectangle",(n,o,r)=>{const l=n?n.parameter1:NaN;return t(n,o,r,l,6)}),y("Ellipse",(n,o,r)=>{const l="e"+o+","+r;let h=Geo.or[l];return h!==void 0||(h=new Geometry(3),h.endX=o,h.endY=r,h.spot1=Spot.zk,h.spot2=Spot.Xk,Geo.rr{const l="c"+o+","+r;let h=Geo.or[l];return h!==void 0||(h=new Geometry(3),h.endX=o,h.endY=r,h.spot1=Spot.zk,h.spot2=Spot.Xk,h.defaultStretch=6,Geo.rrnew Geometry().add(new PathFigure(0,0).add(new PathSegment(2,o,.5*r)).add(new PathSegment(2,0,r).close())).setSpots(0,.25,.5,.75)),y("TriangleDown",(n,o,r)=>new Geometry().add(new PathFigure(0,0).add(new PathSegment(2,o,0)).add(new PathSegment(2,.5*o,r).close())).setSpots(.25,0,.75,.5)),y("TriangleLeft",(n,o,r)=>new Geometry().add(new PathFigure(o,r).add(new PathSegment(2,0,.5*r)).add(new PathSegment(2,o,0).close())).setSpots(.5,.25,1,.75)),y("TriangleUp",(n,o,r)=>new Geometry().add(new PathFigure(o,r).add(new PathSegment(2,0,r)).add(new PathSegment(2,.5*o,0).close())).setSpots(.25,.5,.75,1)),y("Triangle","TriangleUp"),y("Diamond",(n,o,r)=>new Geometry().add(new PathFigure(.5*o,0).add(new PathSegment(2,0,.5*r)).add(new PathSegment(2,.5*o,r)).add(new PathSegment(2,o,.5*r).close())).setSpots(.25,.25,.75,.75)),y("LineH",(n,o,r)=>{const l=new Geometry(1);return l.startX=0,l.startY=r/2,l.endX=o,l.endY=r/2,l}),y("LineV",(n,o,r)=>{const l=new Geometry(1);return l.startX=o/2,l.startY=0,l.endX=o/2,l.endY=r,l}),y("None","Rectangle"),y("BarH","Rectangle"),y("BarV","Rectangle"),y("MinusLine","LineH"),y("PlusLine",(n,o,r)=>new Geometry().add(new PathFigure(0,r/2,!1).add(new PathSegment(2,o,r/2)).add(new PathSegment(1,o/2,0)).add(new PathSegment(2,o/2,r)))),y("XLine",(n,o,r)=>new Geometry().add(new PathFigure(0,r,!1).add(new PathSegment(2,o,0)).add(new PathSegment(1,0,0)).add(new PathSegment(2,o,r)))),y("LineRight",(n,o,r)=>new Geometry().add(new PathFigure(.25*o,0,!1).add(new PathSegment(2,.75*o,.5*r)).add(new PathSegment(2,.25*o,r)))),y("LineDown",(n,o,r)=>new Geometry().add(new PathFigure(0,.25*r,!1).add(new PathSegment(2,.5*o,.75*r)).add(new PathSegment(2,o,.25*r)))),y("LineLeft",(n,o,r)=>new Geometry().add(new PathFigure(.75*o,0,!1).add(new PathSegment(2,.25*o,.5*r)).add(new PathSegment(2,.75*o,r)))),y("LineUp",(n,o,r)=>new Geometry().add(new PathFigure(0,.75*r,!1).add(new PathSegment(2,.5*o,.25*r)).add(new PathSegment(2,o,.75*r)))),y("Capsule",(n,o,r)=>{const l=new Geometry;if(or){const h=r/2,c=new PathFigure(h,0,!0);l.add(c),c.add(new PathSegment(2,o-h,0)),c.add(new PathSegment(5,270,180,o-h,h,h,h)),c.add(new PathSegment(2,h,r)),c.add(new PathSegment(5,90,180,h,h,h,h));const a=isFinite(n.parameter1)?n.parameter1:r*.156;return l.spot1=new Spot(0,0,a,0),l.spot2=new Spot(1,1,-a,0),l}else return l.type=3,l.endX=o,l.endY=r,l.spot1=Spot.zk,l.spot2=Spot.Xk,l});const i=(n,o)=>new PathFigure(n,o,!1,!1),e=(n,o,r)=>n.add(new PathSegment(2,o,r)),s=(n,o,r)=>n.add(new PathSegment(1,o,r));y("Borders",(n,o,r)=>{let l=n?n.parameter1:NaN;isNaN(l)?l=10:l=l&15;const h=new Geometry;let c;return l===10?(c=i(o,0),e(c,o,r),s(c,0,r),e(c,0,0)):l===5?(c=i(0,0),e(c,o,0),s(c,o,r),e(c,0,r)):l===1?(c=i(0,0),e(c,o,0),s(c,o,r)):l===2?(c=i(o,0),e(c,o,r)):l===4?(c=i(o,r),e(c,0,r)):l===8?(c=i(0,r),e(c,0,0),s(c,o,r)):l===3?(c=i(0,0),e(c,o,0),e(c,o,r)):l===6?(c=i(o,0),e(c,o,r),e(c,0,r)):l===12?(c=i(o,r),e(c,0,r),e(c,0,0)):l===9?(c=i(0,r),e(c,0,0),e(c,o,0)):l===7?(c=i(0,0),e(c,o,0),e(c,o,r),e(c,0,r)):l===14?(c=i(o,0),e(c,o,r),e(c,0,r),e(c,0,0)):l===13?(c=i(o,r),e(c,0,r),e(c,0,0),e(c,o,0)):l===11?(c=i(0,r),e(c,0,0),e(c,o,0),e(c,o,r)):l===15?(c=i(0,0),e(c,o,0),e(c,o,r),e(c,0,r),c.add(new PathSegment(2,0,0).close())):(c=i(0,0),s(c,o,r)),h.add(c),h})}Geo.Bg={"":"",Standard:"F1 m 0,0 l 8,4 -8,4 2,-4 z",Backward:"F1 m 8,0 l -2,4 2,4 -8,-4 z",Triangle:"F1 m 0,0 l 8,4.62 -8,4.62 z",BackwardTriangle:"F1 m 8,4 l 0,4 -8,-4 8,-4 0,4 z",Boomerang:"F1 m 0,0 l 8,4 -8,4 4,-4 -4,-4 z",BackwardBoomerang:"F1 m 8,0 l -8,4 8,4 -4,-4 4,-4 z",SidewaysV:"m 0,0 l 8,4 -8,4 0,-1 6,-3 -6,-3 0,-1 z",BackwardV:"m 8,0 l -8,4 8,4 0,-1 -6,-3 6,-3 0,-1 z",OpenTriangle:"m 0,0 l 8,4 -8,4",BackwardOpenTriangle:"m 8,0 l -8,4 8,4",OpenTriangleLine:"m 0,0 l 8,4 -8,4 m 8.5,0 l 0,-8",BackwardOpenTriangleLine:"m 8,0 l -8,4 8,4 m -8.5,0 l 0,-8",OpenTriangleTop:"m 0,0 l 8,4 m 0,4",BackwardOpenTriangleTop:"m 8,0 l -8,4 m 0,4",OpenTriangleBottom:"m 0,8 l 8,-4",BackwardOpenTriangleBottom:"m 0,4 l 8,4",HalfTriangleTop:"F1 m 0,0 l 0,4 8,0 z m 0,8",BackwardHalfTriangleTop:"F1 m 8,0 l 0,4 -8,0 z m 0,8",HalfTriangleBottom:"F1 m 0,4 l 0,4 8,-4 z",BackwardHalfTriangleBottom:"F1 m 8,4 l 0,4 -8,-4 z",ForwardSemiCircle:"m 4,0 b 270 180 0 4 4",BackwardSemiCircle:"m 4,8 b 90 180 0 -4 4",Feather:"m 0,0 l 3,4 -3,4",BackwardFeather:"m 3,0 l -3,4 3,4",DoubleFeathers:"m 0,0 l 3,4 -3,4 m 3,-8 l 3,4 -3,4",BackwardDoubleFeathers:"m 3,0 l -3,4 3,4 m 3,-8 l -3,4 3,4",TripleFeathers:"m 0,0 l 3,4 -3,4 m 3,-8 l 3,4 -3,4 m 3,-8 l 3,4 -3,4",BackwardTripleFeathers:"m 3,0 l -3,4 3,4 m 3,-8 l -3,4 3,4 m 3,-8 l -3,4 3,4",ForwardSlash:"m 0,8 l 5,-8",BackSlash:"m 0,0 l 5,8",DoubleForwardSlash:"m 0,8 l 4,-8 m -2,8 l 4,-8",DoubleBackSlash:"m 0,0 l 4,8 m -2,-8 l 4,8",TripleForwardSlash:"m 0,8 l 4,-8 m -2,8 l 4,-8 m -2,8 l 4,-8",TripleBackSlash:"m 0,0 l 4,8 m -2,-8 l 4,8 m -2,-8 l 4,8",Fork:"m 0,4 l 8,0 m -8,0 l 8,-4 m -8,4 l 8,4",BackwardFork:"m 8,4 l -8,0 m 8,0 l -8,-4 m 8,4 l -8,4",LineFork:"m 0,0 l 0,8 m 0,-4 l 8,0 m -8,0 l 8,-4 m -8,4 l 8,4",BackwardLineFork:"m 8,4 l -8,0 m 8,0 l -8,-4 m 8,4 l -8,4 m 8,-8 l 0,8",CircleFork:"F1 m 6,4 b 0 360 -3 0 3 z m 0,0 l 6,0 m -6,0 l 6,-4 m -6,4 l 6,4",BackwardCircleFork:"F1 m 0,4 l 6,0 m -6,-4 l 6,4 m -6,4 l 6,-4 m 6,0 b 0 360 -3 0 3",CircleLineFork:"F1 m 6,4 b 0 360 -3 0 3 z m 1,-4 l 0,8 m 0,-4 l 6,0 m -6,0 l 6,-4 m -6,4 l 6,4",BackwardCircleLineFork:"F1 m 0,4 l 6,0 m -6,-4 l 6,4 m -6,4 l 6,-4 m 0,-4 l 0,8 m 7,-4 b 0 360 -3 0 3",Circle:"F1 m 8,4 b 0 360 -4 0 4 z",Block:"F1 m 0,0 l 0,8 8,0 0,-8 z",StretchedDiamond:"F1 m 0,3 l 5,-3 5,3 -5,3 -5,-3 z",Diamond:"F1 m 0,4 l 4,-4 4,4 -4,4 -4,-4 z",Chevron:"F1 m 0,0 l 5,0 3,4 -3,4 -5,0 3,-4 -3,-4 z",StretchedChevron:"F1 m 0,0 l 8,0 3,4 -3,4 -8,0 3,-4 -3,-4 z",NormalArrow:"F1 m 0,2 l 4,0 0,-2 4,4 -4,4 0,-2 -4,0 z",X:"m 0,0 l 8,8 m 0,-8 l -8,8",TailedNormalArrow:"F1 m 0,0 l 2,0 1,2 3,0 0,-2 2,4 -2,4 0,-2 -3,0 -1,2 -2,0 1,-4 -1,-4 z",DoubleTriangle:"F1 m 0,0 l 4,4 -4,4 0,-8 z m 4,0 l 4,4 -4,4 0,-8 z",BigEndArrow:"F1 m 0,0 l 5,2 0,-2 3,4 -3,4 0,-2 -5,2 0,-8 z",ConcaveTailArrow:"F1 m 0,2 h 4 v -2 l 4,4 -4,4 v -2 h -4 l 2,-2 -2,-2 z",RoundedTriangle:"F1 m 0,1 a 1,1 0 0 1 1,-1 l 7,3 a 0.5,1 0 0 1 0,2 l -7,3 a 1,1 0 0 1 -1,-1 l 0,-6 z",SimpleArrow:"F1 m 1,2 l -1,-2 2,0 1,2 -1,2 -2,0 1,-2 5,0 0,-2 2,2 -2,2 0,-2 z",AccelerationArrow:"F1 m 0,0 l 0,8 0.2,0 0,-8 -0.2,0 z m 2,0 l 0,8 1,0 0,-8 -1,0 z m 3,0 l 2,0 2,4 -2,4 -2,0 0,-8 z",BoxArrow:"F1 m 0,0 l 4,0 0,2 2,0 0,-2 2,4 -2,4 0,-2 -2,0 0,2 -4,0 0,-8 z",TriangleLine:"F1 m 8,4 l -8,-4 0,8 8,-4 z m 0.5,4 l 0,-8",CircleEndedArrow:"F1 m 10,4 l -2,-3 0,2 -2,0 0,2 2,0 0,2 2,-3 z m -4,0 b 0 360 -3 0 3 z",DynamicWidthArrow:"F1 m 0,3 l 2,0 2,-1 2,-2 2,4 -2,4 -2,-2 -2,-1 -2,0 0,-2 z",EquilibriumArrow:"m 0,3 l 8,0 -3,-3 m 3,5 l -8,0 3,3",FastForward:"F1 m 0,0 l 3.5,4 0,-4 3.5,4 0,-4 1,0 0,8 -1,0 0,-4 -3.5,4 0,-4 -3.5,4 0,-8 z",Kite:"F1 m 0,4 l 2,-4 6,4 -6,4 -2,-4 z",HalfArrowTop:"F1 m 0,0 l 4,4 4,0 -8,-4 z m 0,8",HalfArrowBottom:"F1 m 0,8 l 4,-4 4,0 -8,4 z",OpposingDirectionDoubleArrow:"F1 m 0,4 l 2,-4 0,2 4,0 0,-2 2,4 -2,4 0,-2 -4,0 0,2 -2,-4 z",PartialDoubleTriangle:"F1 m 0,0 4,3 0,-3 4,4 -4,4 0,-3 -4,3 0,-8 z",LineCircle:"F1 m 0,0 l 0,8 m 7 -4 b 0 360 -3 0 3 z",DoubleLineCircle:"F1 m 0,0 l 0,8 m 2,-8 l 0,8 m 7 -4 b 0 360 -3 0 3 z",TripleLineCircle:"F1 m 0,0 l 0,8 m 2,-8 l 0,8 m 2,-8 l 0,8 m 7 -4 b 0 360 -3 0 3 z",CircleLine:"F1 m 6 4 b 0 360 -3 0 3 z m 1,-4 l 0,8",DiamondCircle:"F1 m 8,4 l -4,4 -4,-4 4,-4 4,4 m 8,0 b 0 360 -4 0 4 z",PlusCircle:"F1 m 8,4 b 0 360 -4 0 4 l -8 0 z m -4 -4 l 0 8",OpenRightTriangleTop:"m 8,0 l 0,4 -8,0 m 0,4",OpenRightTriangleBottom:"m 8,8 l 0,-4 -8,0",Line:"m 0,0 l 0,8",DoubleLine:"m 0,0 l 0,8 m 2,0 l 0,-8",TripleLine:"m 0,0 l 0,8 m 2,0 l 0,-8 m 2,0 l 0,8",PentagonArrow:"F1 m 8,4 l -4,-4 -4,0 0,8 4,0 4,-4 z"};var LayoutConditions=(y=>(y[y.None=0]="None",y[y.Added=1]="Added",y[y.Removed=2]="Removed",y[y.Shown=4]="Shown",y[y.Hidden=8]="Hidden",y[y.NodeSized=16]="NodeSized",y[y.GroupLayout=32]="GroupLayout",y[y.NodeReplaced=64]="NodeReplaced",y[y.Standard=127]="Standard",y[y.All=16777215]="All",y))(LayoutConditions||{});class Part extends Panel{w;zo;j;nl;ol;Xo;ri;Yo;xh;Ks;Go;kd;WS;sT;Ep;Up;constructor(t,i){let e;t===void 0||t instanceof PanelLayout||typeof t=="string"?e=t:t&&(i=t),super(e),this.w=2408959,this.zo="",this.j=null,this.nl="",this.ol=null,this.Xo=null,this.ri="",this.Yo=null,this.xh=null,this.Ks=new Point(NaN,NaN).u(),this.Go=null,this.kd=NaN,this.WS=-1,this.sT=new Rect,this.Ep=null,this.Up=NaN,i&&Object.assign(this,i)}cloneProtected(t){super.cloneProtected(t),t.w=this.w&-4097|16384|32768,t.zo=this.zo,this.j!==null&&(this.j.fi?t.j=this.j:t.j=this.j.copy()),t.nl=this.nl,t.Xo=null,t.ri=this.ri,t.Ks.a(this.Ks),t.kd=this.kd}vo(t){super.vo(t),t.dh(),t.ol=null,t.Go=null,t.Ep=null}toString(){let t=U.Dn(this.constructor)+"#"+GSet.as(this);return this.data!==null&&(t+="("+U.toString(this.data)+")"),t}static LayoutNone=0;static LayoutAdded=1;static LayoutRemoved=2;static LayoutShown=4;static LayoutHidden=8;static LayoutNodeSized=16;static LayoutGroupLayout=32;static LayoutNodeReplaced=64;static LayoutStandard=127;static LayoutAll=16777215;Hi(){return this.j===null?this.j=new PartTemplateSettings:this.j.fi&&(this.j=this.j.copy()),this.j}ch(){super.ch(),this.j!==null&&(this.j.fi=!0)}qc(t,i,e,s,n,o,r){const l=this.diagram;l!==null&&(t===3&&i==="elements"?n instanceof Panel?n.Gr(h=>{l.partManager.IM(h,l)}):n instanceof Picture&&l.YM(n):t===4&&i==="elements"&&(n instanceof Panel?n.Gr(h=>l.partManager.EM(h,l)):n instanceof Picture&&l.GM(n)),l.raiseChangedEvent(t,i,e,s,n,o,r))}updateTargetBindings(t){if(super.updateTargetBindings(t),this.data===null)return;const i=this.C.r,e=i.length;for(let n=0;n{r.data!==null&&r.updateTargetBindings()})}const s=this.adornments;for(;s.next();)s.value.updateTargetBindings(t)}Do(){if(super.Do(),this.L2()){const i=this.C.r,e=i.length;for(let s=0;so.Do())}}const t=this.adornments;for(;t.next();)t.value.Do()}updateRelationshipsFromData(){this.data!==null&&this.diagram?.partManager.updateRelationshipsFromData(this)}get key(){const t=this.diagram;if(t!==null)return t.model.getKeyForNodeData(this.data)}get adornments(){return this.Xo===null?EmptyIterator.instance:this.Xo.iteratorValues}findAdornment(t){const i=this.Xo;return i===null?null:i.get(t)}addAdornment(t,i){if(i===null)return;let e=null,s=this.Xo;if(s!==null&&(e=s.get(t)),e!==i){if(e!==null){const o=e.diagram;o!==null&&o.remove(e)}s===null&&(s=new GMap,this.Xo=s),i.zo!==t&&(i.category=t),s.set(t,i);const n=this.diagram;if(n!==null){n.add(i);const o=i.adornedObject;if(o!==null){const r=o.findBindingPanel();r!==null&&(i.data=r.data)}}}}removeAdornment(t){const i=this.Xo;if(i===null)return;const e=i.get(t);if(e!==null){const s=e.diagram;s!==null&&(s.remove(e),e.data=null)}i.delete(t),i.count===0&&(this.Xo=null)}clearAdornments(){const t=this.Xo;if(t===null)return;const i=U.et(),e=t.iterator;for(;e.next();){const n=e.key;i.push(n)}const s=i.length;for(let n=0;n{e.isEnabled&&e.updateAdornments(i)}),t.toolManager.updateAdornments(i)}HS(t){this.Yo=t,t===null&&this.QR()}get layer(){return this.Yo}get diagram(){const t=this.Yo;return t==null?null:t.diagram}get layerName(){return this.nl}set layerName(t){const i=this.nl;if(i===t)return;let e=this.diagram;if(e!==null&&(e.findLayer(t)===null||e.partManager.addsToTemporaryLayer))return;this.nl=t,e!==null&&e.invalidateDocumentBounds(),this.t("layerName",i,t);const s=this.layer;if(s===null||s.name===t||(e=s.diagram,e===null))return;const n=e.findLayer(t);if(n===null||n===s)return;let o=s.te(-1,this,!0);o>=0&&e.raiseChangedEvent(4,"parts",s,this,null,o,!0),o=n.Jh(99999999,this,!0),s.visible!==n.visible&&this.Ei(n.visible),o>=0&&e.raiseChangedEvent(3,"parts",n,null,this,!0,o);const r=this.layerChanged;if(r===null)return;const l=e.X;e.X=!0,r(this,s,n),e.X=l}get layerChanged(){return this.j!==null?this.j.Bp:null}set layerChanged(t){const i=this.layerChanged;i!==t&&(t!==null&&U.k(t,Part,"layerChanged"),this.Hi().Bp=t,this.t("layerChanged",i,t))}get zOrder(){return this.kd}set zOrder(t){const i=this.kd;if(i===t)return;this.kd=t;const e=this.layer;e!==null&&e.Px(-1,this),this.t("zOrder",i,t);const s=this.diagram;s!==null&&s.S()}eO(){const t=this.layer;t!==null&&t.Px(-1,this)}g1(){if(this.ih()!==!1)return;this.tN(!0),this.$c();const t=this.diagram;t!==null&&(t.t0(this),t.requestUpdate())}rT(){if(this.w|=2097152,this.ih()===!1)return;const t=this.position,i=this.location;(!i.isReal()||!t.isReal())&&this.lT(t,i);const e=this.Ni,s=Rect.l().a(e);e.Pt(),e.x=t.x,e.y=t.y,e.u(),this.Ju(s,e),Rect.e(s),this.tN(!1),this.$c()}Wn(t,i,e,s){const n=this.se;n.i(t,i,e,s),this.wi===null&&(this.wi=new Transform);const o=this.wi;o.Ri(),this.m0(o,t,i,e,s),this.wi=o,o.Yk()||o.vg(n)}m0(t,i,e,s,n){if(this.tt!==1&&t.tt(this.tt),this.Yt===0)return;let o=Spot.Center;this.locationSpot.isSpot()&&(o=this.locationSpot);const r=Point.l();if(this.locationObject!==this){const l=this.locationObject,h=l.naturalBounds;r.setSpot(h.x,h.y,h.width,h.height,o),l.wi!==null&&l.wi.gt(r),r.offset(-l.measuredBounds.x,-l.measuredBounds.y);let c=l.panel;for(;c!==null&&c!==this;)c.wi!==null&&c.wi.gt(r),r.offset(-c.measuredBounds.x,-c.measuredBounds.y),c=c.panel}else r.setSpot(i,e,s,n,o);t.cs(this.Yt,r.x,r.y),Point.e(r)}get locationObject(){if(this.Go===null)if(this instanceof Adornment&&this.type!==Panel.Link&&this.hasPlaceholder())this.Go=this.placeholder;else{const t=this.locationObjectName;if(t!==""){const i=this.findObject(t);i!==null?this.Go=i:this.Go=this}else this.Go=this}return this.Go?.visible?this.Go:this}get minLocation(){return this.j!==null?this.j.Vp:Point.gC}set minLocation(t){const i=this.minLocation;i.equals(t)||(t=t.P(),this.Hi().Vp=t,this.t("minLocation",i,t))}get maxLocation(){return this.j!==null?this.j.zp:Point.mC}set maxLocation(t){const i=this.maxLocation;i.equals(t)||(t=t.P(),this.Hi().zp=t,this.t("maxLocation",i,t))}get locationObjectName(){return this.j!==null?this.j.Xp:""}set locationObjectName(t){const i=this.locationObjectName;i!==t&&(this.Hi().Xp=t,this.Go=null,this.c(),this.t("locationObjectName",i,t))}get locationSpot(){return this.j!==null?this.j.Yp:Spot.TopLeft}set locationSpot(t){const i=this.locationSpot;i.equals(t)||(t=t.P(),this.Hi().Yp=t,this.c(),this.t("locationSpot",i,t))}move(t,i){i===!0?this.location=t:this.position=t}moveTo(t,i,e){const s=Point.V(t,i);this.move(s,e),Point.e(s)}isVisible(){if(!this.visible)return!1;const t=this.layer;if(t!==null){if(!t.visible)return!1;const e=t.diagram;if(e!==null&&e.animationManager.hx(this))return!0}const i=this.containingGroup;return!(i!==null&&(!i.isSubGraphExpanded||!i.isVisible()))}Ei(t){const i=this.diagram;t?(this.invalidateLayout(4),this.invalidateAdornments(),i!==null&&i.t0(this)):(this.invalidateLayout(8),this.clearAdornments()),this.dh(),i!==null&&(i.invalidateDocumentBounds(),i.S())}findObject(t){if(this.name===t)return this;let i=this.Ep;if(i===null&&(this.Ep=i=new GMap),i.get(t)!==null)return i.get(t);const e=super.findObject(t);return e!==null?(i.set(t,e),e):(i.set(t,null),null)}A0(){this.Ep=null}getRelativePoint(t,i,e){e===void 0&&(e=new Point);const s=i.isNoSpot()?Spot.Center:i,n=t.naturalBounds;if(e.i(n.width*s.x+s.offsetX,n.height*s.y+s.offsetY),t===null||t===this)return e;t.T.gt(e);let o=t.panel;for(;o!==null&&o!==this;)o.T.gt(e),o=o.panel;return this.wi!==null&&this.wi.gt(e),e.offset(-this.se.x,-this.se.y),e}getDocumentBounds(t){return t===void 0&&(t=new Rect),t.a(this.actualBounds)}ensureBounds(){this.ht(1/0,1/0),this.Bt()}IA(t){const i=this.locationSpot,e=this.locationObject;let s=e.naturalBounds;s.isReal()||(s=Rect.Fg);const n=e instanceof Shape?e.strokeWidth:0;if(t.setSpot(0,0,s.width+n,s.height+n,i),e!==this){t.offset(-n/2,-n/2),e.T.gt(t);let o=e.panel;for(;o!==null&&o!==this;)o.T.gt(t),o=o.panel}return this.wi!==null&&this.wi.gt(t),t.offset(-this.se.x,-this.se.y),t}Wh(t,i){const e=i===void 0?this.sT:i,s=this.sO(),n=s*2;if(!this.isShadowed)return e.i(t.x-1-s,t.y-1-s,t.width+2+n,t.height+2+n),e;let o=t.x,r=t.y,l=t.width,h=t.height;const c=this.shadowBlur,a=this.shadowOffset;return l+=c,h+=c,o-=c/2,r-=c/2,a.x>0?l+=a.x:(o+=a.x,l-=a.x),a.y>0?h+=a.y:(r+=a.y,h-=a.y),e.i(o-1,r-1,l+2,h+2),e}Vv(){return this.type===Panel.Link&&this instanceof Adornment&&this.category==="Selection"&&this.adornedObject instanceof Shape&&this.adornedPart.findMainElement()===this.adornedObject?this.adornedObject.strokeWidth:0}sO(){return isNaN(this.Up)&&(this.Up=this.YA()),this.Up}cf(){this.Up=NaN}Bt(){if(this._e()===!1){this.rT();return}this.Jn(!1);const t=this.Ni,i=Rect.l();i.a(t);const e=this.Nl();this.uh(0,0,this.se.width,this.se.height);const s=this.position;this.lT(s,this.location),t.Pt(),t.x=s.x,t.y=s.y,t.u(),this.Ju(i,t),i.equals(t)?this.ps(e):this.ke()&&(!Geo.f(i.width,t.width)||!Geo.f(i.height,t.height))&&this.WS>=0&&this.invalidateLayout(16),Rect.e(i),this.tN(!1)}Ju(t,i){const e=this.diagram;if(e===null)return;let s=!1;if(e.ta===!1&&t.isReal()){const n=Rect.l();n.a(e.documentBounds),n.subtractMargin(e.padding),t.x>n.x&&t.y>n.y&&t.rightn.x&&i.y>n.y&&i.right=o)return}}this.w=this.w^4096;let s=!1;if(e!==null){s=e.skipsUndoManager,e.skipsUndoManager=!0;const o=e.selection;o.Pt(),t?o.add(this):o.delete(this),o.u()}this.t("isSelected",i,t),this.invalidateAdornments();const n=this.selectionChanged;n!==null&&n(this),e!==null&&(e.requestUpdate(),e.skipsUndoManager=s)}}get isHighlighted(){return(this.w&524288)!==0}set isHighlighted(t){const i=(this.w&524288)!==0;if(i!==t){this.w=this.w^524288;const e=this.diagram;if(e!==null){const n=e.highlighteds;n.Pt(),t?n.add(this):n.delete(this),n.u()}this.t("isHighlighted",i,t),this.S();const s=this.highlightedChanged;s!==null&&s(this)}}get isShadowed(){return(this.w&8192)!==0}set isShadowed(t){const i=(this.w&8192)!==0;i!==t&&(this.w=this.w^8192,this.Ve(!0),this.t("isShadowed",i,t),this.S())}nT(){return(this.w&16384)!==0}oT(t){t?this.w|=16384:this.w&=-16385}ih(){return(this.w&32768)!==0}tN(t){t?this.w|=32768:this.w&=-32769}nO(){return(this.w&65536)!==0}w2(t){t?this.w|=65536:this.w&=-65537}Nl(){return(this.w&131072)!==0}ps(t){t?this.w|=131072:this.w&=-131073}uT(){return(this.w&1048576)!==0}m1(t){t?this.w|=1048576:this.w&=-1048577}get isAnimated(){return(this.w&262144)!==0}set isAnimated(t){const i=(this.w&262144)!==0;i!==t&&(this.w=this.w^262144,this.t("isAnimated",i,t))}get highlightedChanged(){return this.j!==null?this.j.Gp:null}set highlightedChanged(t){const i=this.highlightedChanged;i!==t&&(t!==null&&U.k(t,Part,"highlightedChanged"),this.Hi().Gp=t,this.t("highlightedChanged",i,t))}get selectionObjectName(){return this.j!==null?this.j.Kp:""}set selectionObjectName(t){const i=this.selectionObjectName;i!==t&&(this.Hi().Kp=t,this.ol=null,this.t("selectionObjectName",i,t))}get selectionAdornmentTemplate(){return this.j!==null?this.j.jp:null}set selectionAdornmentTemplate(t){const i=this.selectionAdornmentTemplate;i!==t&&(t!==null&&t.Et(),this.Hi().jp=t,this.t("selectionAdornmentTemplate",i,t))}get selectionObject(){if(this.ol===null){const t=this.selectionObjectName;if(t!==null&&t!==""){const i=this.findObject(t);i!==null?this.ol=i:this.ol=this}else if(this instanceof Link){const i=this.path;i!==null?this.ol=i:this.ol=this}else this.ol=this}return this.ol}get selectionChanged(){return this.j!==null?this.j.Hp:null}set selectionChanged(t){const i=this.selectionChanged;i!==t&&(t!==null&&U.k(t,Part,"selectionChanged"),this.Hi().Hp=t,this.t("selectionChanged",i,t))}get resizeAdornmentTemplate(){return this.j!==null?this.j.qp:null}set resizeAdornmentTemplate(t){const i=this.resizeAdornmentTemplate;i!==t&&(this.Hi().qp=t!==null?t.Et():null,this.t("resizeAdornmentTemplate",i,t))}get resizeObjectName(){return this.j!==null?this.j.Wp:""}set resizeObjectName(t){const i=this.resizeObjectName;i!==t&&(this.Hi().Wp=t,this.t("resizeObjectName",i,t))}get resizeObject(){const t=this.resizeObjectName;if(t!==""){const i=this.findObject(t);if(i!==null)return i}return this}get resizeCellSize(){return this.j!==null?this.j.Jp:Size.ww}set resizeCellSize(t){const i=this.resizeCellSize;i.equals(t)||(t=t.P(),this.Hi().Jp=t,this.t("resizeCellSize",i,t))}get rotateAdornmentTemplate(){return this.j!==null?this.j.$p:null}set rotateAdornmentTemplate(t){const i=this.rotateAdornmentTemplate;i!==t&&(this.Hi().$p=t!==null?t.Et():null,this.t("rotateAdornmentTemplate",i,t))}get rotateObjectName(){return this.j!==null?this.j.Zp:""}set rotateObjectName(t){const i=this.rotateObjectName;i!==t&&(this.Hi().Zp=t,this.t("rotateObjectName",i,t))}get rotateObject(){const t=this.rotateObjectName;if(t!==""){const i=this.findObject(t);if(i!==null)return i}return this}get rotationSpot(){return this.j!==null?this.j.Qp:Spot.Default}set rotationSpot(t){const i=this.rotationSpot;i.equals(t)||(t=t.P(),this.Hi().Qp=t,this.t("rotationSpot",i,t))}get text(){return this.ri}set text(t){const i=this.ri;i!==t&&(this.ri=t,this.t("text",i,t))}get containingGroup(){return this.xh}set containingGroup(t){if(this.ke()){const i=this.xh;if(i!==t){t!==null&&(this===t||t.isMemberOf(this))&&(this===t&&U.o("Cannot make a Group a member of itself: "+this.toString()),U.o("Cannot make a Group indirectly contain itself: "+this.toString()+" already contains "+t.toString())),this.invalidateLayout(2);const e=this.diagram;if(i!==null?i.eN(this):this instanceof Group&&e!==null&&e.zr.delete(this),this.xh=t,t!==null?t.sN(this):this instanceof Group&&e!==null&&e.zr.add(this),this.invalidateLayout(1),e!==null&&e.X){const n=this.data,o=e.model;if(n!==null&&o.Hc()){const r=t!==null?t.data:null;o.setGroupForData(n,o.getKeyForNodeData(r))}}const s=this.containingGroupChanged;if(s!==null){let n=!0;e!==null&&(n=e.X,e.X=!0),s(this,i,t),e!==null&&(e.X=n)}if(this instanceof Group){const n=new GSet;Part.oh(n,this,!0,0,!0);const o=n.iterator;for(;o.next();){const r=o.value;if(r instanceof Node){const l=r.linksConnected;for(;l.next();)l.value.Pd()}}}if(this instanceof Node){const n=this.linksConnected;for(;n.next();)n.value.Pd();const o=this.labeledLink;o!==null&&o.Pd()}this.t("containingGroup",i,t),t!==null&&t.eO()}}else U.o("cannot set the Part.containingGroup of a Link or Adornment")}dh(){const t=this.containingGroup;t!==null&&(t.hasPlaceholder()&&t.placeholder?.c(),t.c(),t.invalidateConnectedLinks())}S(){const t=this.diagram;t!==null&&!this._e()&&!this.ih()&&this.isVisible()&&this.Ni.isReal()&&t.S(this.Wh(this.Ni))}c(){if(this.To())return;super.c();const t=this.diagram;t!==null&&(t.t0(this),this instanceof Node&&this.labeledLink!==null&&this.labeledLink.ef(),t.requestUpdate(!0))}ef(t){if(this._e())return;const i=this.diagram;i!==null&&(i.t0(this),this instanceof Node&&this.invalidateConnectedLinks(),i.requestUpdate()),this.Jn(!0)}Rm(t){if(!t){const i=this.xh;i!==null&&i.sN(this)}}vm(t){if(!t){const i=this.xh;i!==null&&i.eN(this)}}Xc(){const t=this.data;if(t!==null){const i=this.diagram;if(i!==null){const e=i.model;e!==null&&e.removeNodeData(t)}}}get containingGroupChanged(){return this.j!==null?this.j._p:null}set containingGroupChanged(t){const i=this.containingGroupChanged;i!==t&&(t!==null&&U.k(t,Part,"containingGroupChanged"),this.Hi()._p=t,this.t("containingGroupChanged",i,t))}findSubGraphLevel(){return this.nN(this)}nN(t){const i=t.containingGroup;if(i!==null)return 1+this.nN(i);if(t instanceof Node){const e=t.labeledLink;if(e!==null)return this.nN(e)}return 0}findTopLevelPart(){return this.oN(this)}oN(t){const i=t.containingGroup;if(i!==null)return this.oN(i);if(t instanceof Node){const e=t.labeledLink;if(e!==null)return this.oN(e)}return t}get isTopLevel(){return!(this.containingGroup!==null||this instanceof Node&&this.labeledLink!==null)}isMemberOf(t){return t instanceof Group?this.rN(this,t):!1}rN(t,i){if(t===i||i===null)return!1;const e=t.containingGroup;if(e!==null&&(e===i||this.rN(e,i)))return!0;if(t instanceof Node){const s=t.labeledLink;if(s!==null)return this.rN(s,i)}return!1}findCommonContainingGroup(t){if(t===null)return null;if(this===t)return this.containingGroup;let i=this;for(;i!==null;){if(i instanceof Group&&i.m1(!0),i instanceof Node){const s=i.labeledLink;s!==null&&(i=s)}i=i.containingGroup}let e=null;for(i=t;i!==null;){if(i.uT()){e=i;break}if(i instanceof Node){const s=i.labeledLink;s!==null&&(i=s)}i=i.containingGroup}for(i=this;i!==null;){if(i instanceof Group&&i.m1(!1),i instanceof Node){const s=i.labeledLink;s!==null&&(i=s)}i=i.containingGroup}return e}get layoutConditions(){return this.j!==null?this.j.ty:127}set layoutConditions(t){const i=this.layoutConditions;i!==t&&(this.Hi().ty=t,this.t("layoutConditions",i,t))}canLayout(){if(!this.isLayoutPositioned||!this.isVisible())return!1;const t=this.layer;return!(t!==null&&t.isTemporary||this instanceof Node&&this.isLinkLabel)}rO(t){if(!this.isLayoutPositioned||!(t&this.layoutConditions))return!1;const i=this.layer;if(i!==null&&i.isTemporary||this instanceof Node&&this.isLinkLabel)return!1;const e=this.diagram;return!(e!==null&&e.undoManager.isUndoingRedoing)}invalidateLayout(t){if(t===void 0&&(t=16777215),!this.rO(t))return;const i=this.xh;if(i!==null){const e=i.layout;e!==null?e.invalidateLayout():i.invalidateLayout(t)}else{const e=this.diagram;if(e!==null){const s=e.layout;s!==null&&s.invalidateLayout()}}}jL(){if(!this.isVisible())return!1;const t=this.layer;return!(t!==null&&t.isTemporary)}static oh(t,i,e,s,n,o){if(o===void 0&&(o=null),!t.has(i)&&!(o!==null&&!o(i))&&!(i instanceof Adornment)){if(t.add(i),i instanceof Node){if(e&&i instanceof Group){const r=i.memberParts;for(;r.next();){const l=r.value;Part.oh(t,l,e,s,n,o)}}if(n!==!1){const r=i.linksConnected;for(;r.next();){const l=r.value;if(t.has(l))continue;const h=l.fromNode,c=l.toNode,a=h===null||t.has(h),f=c===null||t.has(c);(n?a&&f:a||f)&&Part.oh(t,l,e,s,n,o)}}if(s>1){const r=i.findTreeChildrenNodes();for(;r.next();){const l=r.value;Part.oh(t,l,e,s-1,n,o)}}}else if(i instanceof Link){const r=i.labelNodes;for(;r.next();){const l=r.value;Part.oh(t,l,e,s,n,o)}}}}get dragComputation(){return this.j!==null?this.j.iy:null}set dragComputation(t){const i=this.dragComputation;i!==t&&(t!==null&&U.k(t,Part,"dragComputation"),this.Hi().iy=t,this.t("dragComputation",i,t))}get shadowOffset(){return this.j!==null?this.j.ey:Point.pC}set shadowOffset(t){const i=this.shadowOffset;i.equals(t)||(t=t.P(),this.Hi().ey=t,this.S(),this.t("shadowOffset",i,t))}get shadowColor(){return this.j!==null?this.j.ny:"gray"}set shadowColor(t){const i=this.shadowColor;i!==t&&(this.Hi().ny=t,this.S(),this.t("shadowColor",i,t))}get shadowBlur(){return this.j!==null?this.j.un:4}set shadowBlur(t){const i=this.shadowBlur;i!==t&&(this.Hi().un=t,this.S(),this.t("shadowBlur",i,t))}}class PartTemplateSettings{fi;Bp;_p;jp;Kp;Hp;Gp;qp;Wp;Jp;$p;Zp;Qp;Xp;Yp;Vp;zp;iy;ty;ey;ny;un;constructor(){this.fi=!1,this.Bp=null,this._p=null,this.jp=null,this.Kp="",this.Hp=null,this.Gp=null,this.qp=null,this.Wp="",this.Jp=Size.ww,this.$p=null,this.Zp="",this.Qp=Spot.Default,this.Xp="",this.Yp=Spot.TopLeft,this.Vp=Point.gC,this.zp=Point.mC,this.iy=null,this.ty=127,this.ey=Point.pC,this.ny="gray",this.un=4}copy(){const t=new PartTemplateSettings;return t.Bp=this.Bp,t._p=this._p,t.jp=this.jp,t.Kp=this.Kp,t.Hp=this.Hp,t.Gp=this.Gp,t.qp=this.qp,t.Wp=this.Wp,t.Jp=this.Jp.P(),t.$p=this.$p,t.Zp=this.Zp,t.Qp=this.Qp.P(),t.Xp=this.Xp,t.Yp=this.Yp.P(),t.Vp=this.Vp.P(),t.zp=this.zp.P(),t.iy=this.iy,t.ty=this.ty,t.ey=this.ey.P(),t.ny=this.ny,t.un=this.un,t}}class Adornment extends Part{us;Ft;nS;oS;hf;constructor(t,i){let e;t===void 0||t instanceof PanelLayout||typeof t=="string"?e=t:t&&(i=t),super(e),this.w&=-257,this.nl="Adornment",this.us=null,this.nS=0,this.oS=!1,this.Ft=null,this.hf=null,i&&Object.assign(this,i)}toString(){const t=this.adornedPart;return"Adornment("+this.category+")"+(t!==null?t.toString():"")}updateRelationshipsFromData(){}sd(t){const i=this.adornedObject;if(!(i instanceof Shape))return;const e=i.part;if(!(e instanceof Link))return;const s=e.path;let n=s.geometry;e.sd(t),n=s.geometry;const o=this.C.r,r=o.length;for(let l=0;lh instanceof Placeholder);l instanceof Placeholder&&this.Ft===null&&(this.Ft=l)}}else t===4&&i==="elements"&&this.Ft!==null&&(s===this.Ft?this.Ft=null:s instanceof Panel&&this.Ft.isContainedBy(s)&&(this.Ft=null));super.qc(t,i,e,s,n,o,r)}updateAdornments(){}Xc(){}}var PortSpreading=(y=>(y[y.None=0]="None",y[y.Evenly=1]="Evenly",y[y.Packed=2]="Packed",y))(PortSpreading||{});class Node extends Part{v;Rt;kf;rl;bh;ne;ti;constructor(t,i){let e;t===void 0||t instanceof PanelLayout||typeof t=="string"?e=t:t&&(i=t),super(e),this.v=13,this.Rt=null,this.ti=new List,this.kf=null,this.rl=null,this.ne=null,this.bh=!1,i&&Object.assign(this,i)}cloneProtected(t){super.cloneProtected(t),t.v=this.v,this.Rt!==null&&(this.Rt.fi?t.Rt=this.Rt:t.Rt=this.Rt.copy())}vo(t){super.vo(t),t.invalidateConnectedLinks(),t.rl=this.rl,t.ne=null}static SpreadingNone=0;static SpreadingEvenly=1;static SpreadingPacked=2;ll(){return this.Rt===null?this.Rt=new NodeTemplateSettings:this.Rt.fi&&(this.Rt=this.Rt.copy()),this.Rt}ch(){super.ch(),this.Rt!==null&&(this.Rt.fi=!0)}dT(t){t!==null&&(this.rl===null&&(this.rl=new GSet),this.rl.add(t))}gT(t){t!==null&&this.rl!==null&&this.rl.delete(t)}mT(t,i,e){if(t===null||this.rl===null)return null;const s=this.rl.iterator;for(;s.next();){const n=s.value;if(n.ly===this&&n.p1===t&&n.lN===i&&n.hN===e||n.ly===t&&n.p1===this&&n.lN===e&&n.hN===i)return n}return null}invalidateLinkBundle(t,i,e){i==null&&(i=""),e==null&&(e="");const s=this.mT(t,i,e);s!==null&&s.Sd()}qc(t,i,e,s,n,o,r){t===3&&i==="elements"?this.ne=null:t===4&&i==="elements"&&(this.ne=null),super.qc(t,i,e,s,n,o,r)}invalidateConnectedLinks(t){const i=this.linksConnected;for(;i.next();){const e=i.value;t!==void 0&&t.has(e)||(this.qi(e.fromPort),this.qi(e.toPort),e.invalidateRoute())}}bA(t){const i=this.linksConnected;for(;i.next();){const e=i.value;e.fromPort!==t&&e.toPort!==t||(this.qi(e.fromPort),this.qi(e.toPort),e.invalidateRoute())}}qi(t){if(t===null)return;const i=t.Ku;i!==null&&i.Sd();const e=t.part,s=e.containingGroup;s!==null&&!e.isVisible()&&s.qi(s.port)}Yr(){return!0}get portSpreading(){return this.Rt!==null?this.Rt.hy:1}set portSpreading(t){const i=this.portSpreading;if(i!==t){this.ll().hy=t,this.t("portSpreading",i,t);const e=this.diagram;if(e!==null&&e.undoManager.isUndoingRedoing)return;this.invalidateConnectedLinks()}}get avoidable(){return(this.v&8)!==0}set avoidable(t){const i=(this.v&8)!==0;if(i!==t){this.v=this.v^8;const e=this.diagram;e!==null&&e.JM(this),this.t("avoidable",i,t)}}get avoidableMargin(){return this.Rt!==null?this.Rt.ay:Margin.PC}set avoidableMargin(t){typeof t=="number"&&(t=new Margin(t));const i=this.avoidableMargin;if(!i.equals(t)){t=t.P(),this.ll().ay=t;const e=this.diagram;e!==null&&e.JM(this),this.t("avoidableMargin",i,t)}}canAvoid(){return this.avoidable&&!this.isLinkLabel}getAvoidableRect(t){return t.set(this.actualBounds),t.addMargin(this.avoidableMargin),t}findVisibleNode(){let t=this;for(;t!==null&&!t.isVisible();)t=t.containingGroup;return t}isVisible(){if(!super.isVisible())return!1;let t=!0,i=1;const e=this.diagram;if(e!==null){if(e.animationManager.hx(this))return!0;t=e.isTreePathToChildren,i=e.treeCollapsePolicy}if(i===1){const n=this.findTreeParentNode();if(n!==null&&!n.isTreeExpanded)return!1}else if(i===2){const n=t?this.findLinksInto():this.findLinksOutOf();let o=!1,r=!1;for(;n.next();){const l=n.value;if(l.isTreeLink){o=!0;const h=t?l.fromNode:l.toNode;if(h&&h.isTreeExpanded){r=!0;break}}}if(o&&!r)return!1}else if(i===3){const n=t?this.findLinksInto():this.findLinksOutOf();let o=!1,r=!1;for(;n.next();){const l=n.value;if(l.isTreeLink){o=!0;const h=t?l.fromNode:l.toNode;if(h&&!h.isTreeExpanded){r=!0;break}}}if(o&&r)return!1}const s=this.labeledLink;return s!==null?s.isVisible():!0}Ei(t){super.Ei(t);const i=this.linksConnected;for(;i.next();){const e=i.value;if(t&&this.containingGroup!==null){const s=e.getOtherNode(this);s!==null&&!s.isMemberOf(this.containingGroup)&&e.invalidateRoute()}e.Ei(t)}}get linksConnected(){return this.ti.iterator}findExternalTreeLinksConnected(){const t=new GSet,i=new GSet;return this.pT(this,t,i),i.iterator}pT(t,i,e){if(t===null||i.has(t))return;i.add(t);let s=!0;const n=this.diagram;n!==null&&(s=n.isTreePathToChildren),t.linksConnected.each(o=>{o.isTreeLink?(s?o.fromNode===t:o.toNode===t)&&this.pT(s?o.toNode:o.fromNode,i,e):e.add(o)})}findLinksConnected(t){if(t===void 0&&(t=null),t===null)return this.ti.iterator;const i=new ListIterator(this.ti),e=this;return i.predicate=s=>s.fromNode===e&&s.fromPortId===t||s.toNode===e&&s.toPortId===t,i}findLinksOutOf(t){t===void 0&&(t=null);const i=new ListIterator(this.ti),e=this;return i.predicate=s=>s.fromNode!==e?!1:t===null?!0:s.fromPortId===t,i}findLinksInto(t){t===void 0&&(t=null);const i=new ListIterator(this.ti),e=this;return i.predicate=s=>s.toNode!==e?!1:t===null?!0:s.toPortId===t,i}findNodesConnected(t){t===void 0&&(t=null);let i=null,e=null;const s=this.ti.iterator;for(;s.next();){const n=s.value;if(n.fromNode===this){if(t===null||n.fromPortId===t){const o=n.toNode;i!==null?i.add(o):e!==null&&e!==o?(i=new GSet,i.add(e),i.add(o)):e=o}}else if(n.toNode===this&&(t===null||n.toPortId===t)){const o=n.fromNode;i!==null?i.add(o):e!==null&&e!==o?(i=new GSet,i.add(e),i.add(o)):e=o}}return i!==null?i.iterator:e!==null?new SingletonIterator(e):EmptyIterator.instance}findNodesOutOf(t){t===void 0&&(t=null);let i=null,e=null;const s=this.ti.iterator;for(;s.next();){const n=s.value;if(n.fromNode===this&&(t===null||n.fromPortId===t)){const o=n.toNode;i!==null?i.add(o):e!==null&&e!==o?(i=new GSet,i.add(e),i.add(o)):e=o}}return i!==null?i.iterator:e!==null?new SingletonIterator(e):EmptyIterator.instance}findNodesInto(t){t===void 0&&(t=null);let i=null,e=null;const s=this.ti.iterator;for(;s.next();){const n=s.value;if(n.toNode===this&&(t===null||n.toPortId===t)){const o=n.fromNode;i!==null?i.add(o):e!==null&&e!==o?(i=new GSet,i.add(e),i.add(o)):e=o}}return i!==null?i.iterator:e!==null?new SingletonIterator(e):EmptyIterator.instance}findLinksBetween(t,i,e){i===void 0&&(i=null),e===void 0&&(e=null);const s=new ListIterator(this.ti),n=this;return s.predicate=o=>o.fromNode===n&&o.toNode===t&&(i===null||o.fromPortId===i)&&(e===null||o.toPortId===e)||o.fromNode===t&&o.toNode===n&&(e===null||o.fromPortId===e)&&(i===null||o.toPortId===i),s}findLinksTo(t,i,e){i===void 0&&(i=null),e===void 0&&(e=null);const s=new ListIterator(this.ti),n=this;return s.predicate=o=>!(o.fromNode!==n||o.toNode!==t||i!==null&&o.fromPortId!==i||e!==null&&o.toPortId!==e),s}get linkConnected(){return this.Rt!==null?this.Rt.cy:null}set linkConnected(t){const i=this.linkConnected;i!==t&&(t!==null&&U.k(t,Node,"linkConnected"),this.ll().cy=t,this.t("linkConnected",i,t))}get linkDisconnected(){return this.Rt!==null?this.Rt.fy:null}set linkDisconnected(t){const i=this.linkDisconnected;i!==t&&(t!==null&&U.k(t,Node,"linkDisconnected"),this.ll().fy=t,this.t("linkDisconnected",i,t))}get linkValidation(){return this.Rt!==null?this.Rt.Ml:null}set linkValidation(t){const i=this.linkValidation;i!==t&&(t!==null&&U.k(t,Node,"linkValidation"),this.ll().Ml=t,this.t("linkValidation",i,t))}w1(t,i){this.qi(i);const e=this.ti.has(t);if(e||this.ti.add(t),!e||t.fromNode===t.toNode){const s=this.linkConnected;if(s!==null){let n=!0;const o=this.diagram;o!==null&&(n=o.X,o.X=!0),s(this,t,i),o!==null&&(o.X=n)}}if(!e){if(!t.isTreeLink)return;const s=t.fromNode,n=t.toNode;if(s!==null&&n!==null&&s!==n){let o=!0;const r=this.diagram;r!==null&&(o=r.isTreePathToChildren);const l=o?n:s,h=o?s:n;if(l.bh||(l.bh=h),h.isTreeLeaf){if(r!==null&&r.undoManager.isUndoingRedoing)return;o?s===h&&(h.isTreeLeaf=!1):n===h&&(h.isTreeLeaf=!1)}}}}b1(t,i){this.qi(i);const e=this.ti.delete(t);let s=null;if(e||t.toNode===t.fromNode){const n=this.linkDisconnected;if(s=this.diagram,n!==null){let o=!0;s!==null&&(o=s.X,s.X=!0),n(this,t,i),s!==null&&(s.X=o)}}if(e){if(!t.isTreeLink)return;let n=!0;s!==null&&(n=s.isTreePathToChildren);const o=n?t.toNode:t.fromNode,r=n?t.fromNode:t.toNode;if(o!==null&&(o.bh=!1),r!==null&&!r.isTreeLeaf)if(r.ti.count===0){if(r.bh=null,s!==null&&s.undoManager.isUndoingRedoing)return;r.isTreeLeaf=!0}else r.l0()}}l0(){if(this.bh=!1,this.ti.count===0)return;let t=!0;const i=this.diagram;if(i!==null&&i.undoManager.isUndoingRedoing)return;i!==null&&(t=i.isTreePathToChildren);const e=this.ti.iterator;for(;e.next();){const s=e.value;if(s.isTreeLink){if(t){if(s.fromNode===this){this.isTreeLeaf=!1;return}}else if(s.toNode===this){this.isTreeLeaf=!1;return}}}this.isTreeLeaf=!0}updateRelationshipsFromData(){const t=this.diagram;t!==null&&t.partManager.updateRelationshipsFromData(this)}Rm(t){if(super.Rm(t),!t){this.l0();const i=this.kf;i!==null&&i.yT(this)}}vm(t){if(super.vm(t),!t){const i=this.kf;i!==null&&i.wT(this)}}Xc(){if(this.ti.count>0){const t=this.diagram;if(t!==null){const i=t.commandHandler!==null?t.commandHandler.deletesConnectedLinks:!0,s=this.ti.copy().iterator;for(;s.next();){const n=s.value;i?t.remove(n):(n.fromNode===this&&(n.fromNode=null),n.toNode===this&&(n.toNode=null))}}}this.labeledLink=null,super.Xc()}get isLinkLabel(){return this.kf!==null}get labeledLink(){return this.kf}set labeledLink(t){const i=this.kf;if(i!==t){const e=this.diagram,s=this.data;if(i!==null){if(i.wT(this),e!==null&&s!==null&&!e.undoManager.isUndoingRedoing){const n=i.data,o=e.model;if(n!==null&&o.Ra()){const r=o.getKeyForNodeData(s);r!==void 0&&o.removeLabelKeyForLinkData(n,r)}}this.containingGroup=null}if(this.kf=t,t!==null){if(t.yT(this),e!==null&&s!==null&&!e.undoManager.isUndoingRedoing){const n=t.data,o=e.model;if(n!==null&&o.Ra()){const r=o.getKeyForNodeData(s);r!==void 0&&o.addLabelKeyForLinkData(n,r)}}this.containingGroup=t.containingGroup}this.ef(),this.t("labeledLink",i,t)}}findVisiblePort(t){let i=t;for(;i!==null&&(!i.actualBounds.isReal()||!i.isVisibleObject());)i=i.panel;return i===null?this.port:i}findPort(t){if(this.ne===null){if(t===""&&this.fn===!1)return this;this.xT()}let i=this.ne.get(t);return i!==null||t!==""&&(i=this.ne.get(""),i!==null)?i:this}get port(){return this.findPort("")}get ports(){return this.ne===null&&this.xT(),this.ne.iteratorValues}xT(){this.ne===null?this.ne=new GMap:this.ne.clear(),this.walkVisualTreeFrom(this,(t,i)=>t.LA(i)),this.ne.count===0&&this.ne.set("",this)}LA(t){const i=t.portId;i!==null&&this.ne!==null&&this.ne.set(i,t)}C2(t,i){const e=t.portId;if(e!==null){this.ne!==null&&this.ne.delete(e);const s=this.diagram;if(s!==null&&i){let n=null;const o=this.findLinksConnected(e);for(;o.next();){const r=o.value;n===null&&(n=U.et()),n.push(r)}if(n!==null){for(let r=0;r!(!n.isTreeLink||n.fromNode!==s):e.predicate=n=>!(!n.isTreeLink||n.toNode!==s),e}findTreeChildrenNodes(){let t=!0;const i=this.diagram;i!==null&&(t=i.isTreePathToChildren);let e=null,s=null;const n=this.ti.iterator;if(t)for(;n.next();){const o=n.value;if(o.isTreeLink&&o.fromNode===this){const r=o.toNode;e!==null?e.add(r):s!==null&&s!==r?(e=new List,e.add(s),e.add(r)):s=r}}else for(;n.next();){const o=n.value;if(o.isTreeLink&&o.toNode===this){const r=o.fromNode;e!==null?e.add(r):s!==null&&s!==r?(e=new List,e.add(s),e.add(r)):s=r}}return e!==null?e.iterator:s!==null?new SingletonIterator(s):EmptyIterator.instance}findTreeParts(t){t===void 0&&(t=1/0),U.s(t,"number",Node,"findTreeParts:level");const i=new GSet;return Part.oh(i,this,!1,t,!0),i}collapseTree(t){t===void 0&&(t=1),t<1&&(t=1);const i=this.diagram;if(i===null||i.isCollapsingExpanding)return;i.isCollapsingExpanding=!0;const e=new GSet;e.add(this),this.bT(e,i.isTreePathToChildren,t,i,this,i.treeCollapsePolicy===1),i.isCollapsingExpanding=!1}bT(t,i,e,s,n,o){if(e>1){const r=i?this.findLinksOutOf():this.findLinksInto();for(;r.next();){const l=r.value;if(!l.isTreeLink)continue;const h=l.getOtherNode(this);h!==null&&h!==this&&!t.has(h)&&(t.add(h),h.bT(t,i,e-1,s,n,o))}}else this.kT(t,i,s,n,o)}kT(t,i,e,s,n){const o=s===this?!0:this.isTreeExpanded,r=i?this.findLinksOutOf():this.findLinksInto();for(;r.next();){const l=r.value;if(!l.isTreeLink)continue;const h=l.getOtherNode(this);if(h!==null&&h!==this){const c=t.has(h);if(c||t.add(h),o){const a=i?h.findNodesInto():h.findNodesOutOf(),f=this;a.all(u=>u===f||!u.isTreeExpanded)&&e.Lc(h,s),h.dh(),h.Ei(!1)}h.isTreeExpanded&&(h.wasTreeExpanded=h.isTreeExpanded,c||h.kT(t,i,e,s,n))}}this.isTreeExpanded=!1}expandTree(t){t===void 0&&(t=2),t<2&&(t=2);const i=this.diagram;if(i===null||i.isCollapsingExpanding)return;i.isCollapsingExpanding=!0;const e=new GSet;e.add(this),this.PT(e,i.isTreePathToChildren,t,i,this,i.treeCollapsePolicy===1),i.isCollapsingExpanding=!1}PT(t,i,e,s,n,o){const r=n===this?!1:this.isTreeExpanded,l=i?this.findLinksOutOf():this.findLinksInto();for(;l.next();){const h=l.value;if(!h.isTreeLink)continue;r||h.Se||h.invalidateRoute();const c=h.getOtherNode(this);if(c!==null&&c!==this&&!t.has(c)){if(t.add(c),!r){c.Ei(!0),c.dh();const a=i?c.findNodesInto():c.findNodesOutOf(),f=this;a.all(u=>u===f||!u.isTreeExpanded)&&s.Cc(c,n)}(e>2||c.wasTreeExpanded)&&(c.wasTreeExpanded=!1,c.PT(t,i,e-1,s,n,o))}}this.isTreeExpanded=!0}get isTreeExpanded(){return(this.v&1)!==0}set isTreeExpanded(t){const i=(this.v&1)!==0;if(i!==t){this.v=this.v^1;const e=this.diagram;this.t("isTreeExpanded",i,t);const s=this.treeExpandedChanged;if(s!==null){let n=!0;e!==null&&(n=e.X,e.X=!0),s(this),e!==null&&(e.X=n)}if(e!==null&&e.undoManager.isUndoingRedoing){this.Ei(t);return}t?this.expandTree():this.collapseTree()}}get wasTreeExpanded(){return(this.v&2)!==0}set wasTreeExpanded(t){const i=(this.v&2)!==0;i!==t&&(this.v=this.v^2,this.t("wasTreeExpanded",i,t))}get treeExpandedChanged(){return this.Rt!==null?this.Rt.uy:null}set treeExpandedChanged(t){const i=this.treeExpandedChanged;i!==t&&(t!==null&&U.k(t,Node,"treeExpandedChanged"),this.ll().uy=t,this.t("treeExpandedChanged",i,t))}get isTreeLeaf(){return(this.v&4)!==0}set isTreeLeaf(t){const i=(this.v&4)!==0;i!==t&&(this.v=this.v^4,this.t("isTreeLeaf",i,t))}get isTreeRoot(){return this.findTreeParentLink()===null}}class NodeTemplateSettings{fi;cy;fy;Ml;uy;ay;hy;gy;my;nh;yy;constructor(){this.fi=!1,this.cy=null,this.fy=null,this.Ml=null,this.uy=null,this.ay=Margin.PC,this.hy=1,this.gy=null,this.my=null,this.nh=null,this.yy=null}copy(){const t=new NodeTemplateSettings;return t.cy=this.cy,t.fy=this.fy,t.Ml=this.Ml,t.uy=this.uy,t.ay=this.ay.P(),t.hy=this.hy,t.gy=this.gy,t.my=this.my,t.nh=this.nh,t.yy=this.yy,t}}var LinkAdjusting=(y=>(y[y.None=0]="None",y[y.End=17]="End",y[y.Scale=18]="Scale",y[y.Stretch=19]="Stretch",y))(LinkAdjusting||{}),Routing=(y=>(y[y.Normal=1]="Normal",y[y.Orthogonal=2]="Orthogonal",y[y.AvoidsNodes=6]="AvoidsNodes",y[y.AvoidsNodesStraight=7]="AvoidsNodesStraight",y))(Routing||{}),Curve=(y=>(y[y.None=0]="None",y[y.Bezier=9]="Bezier",y[y.JumpGap=10]="JumpGap",y[y.JumpOver=11]="JumpOver",y))(Curve||{});class Link extends Part{Nt;so;no;Md;oo;ro;Nd;Pf;Cd;Ld;Ad;va;Td;js;xi;hl;br;Sf;Ko;aN;cN;k1;fN;uN;Oa;P1;ot;jo;static Ia=null;static Ea=null;hf;dN;gN;constructor(t){super(Panel.Link),this.Nt=8,this.so=null,this.no="",this.Md=null,this.oo=null,this.ro="",this.Nd=null,this.Pf=0,this.Cd=0,this.Ld=0,this.Ad=NaN,this.va=1,this.Td=.5,this.js=null,this.xi=new List().u(),this.hl=null,this.br=null,this.Sf=new Rect,this.ot=new Geometry,this.Ko=null,this.jo=null,this.aN=null,this.cN=null,this.dN=0,this.gN=0,this.k1=new Point,this.fN=null,this.uN=null,this.Oa=null,this.P1=NaN,this.ct=null,this.hf=[],t&&Object.assign(this,t)}cloneProtected(t){super.cloneProtected(t),t.Nt=this.Nt&-113,t.no=this.no,t.Md=this.Md,t.ro=this.ro,t.Nd=this.Nd,t.Pf=this.Pf,t.Cd=this.Cd,t.Ld=this.Ld,t.Ad=this.Ad,t.va=this.va,t.Td=this.Td,this.ct!==null&&(t.ct=this.ct.copy())}vo(t){super.vo(t),this.no=t.no,this.ro=t.ro,t.hl=null,t.invalidateRoute(),t.jo=this.jo;const i=t.fromPort;i!==null&&t.fromNode.qi(i);const e=t.toPort;e!==null&&t.toNode.qi(e)}oi(t){t in Routing||t in Curve||t in LinkAdjusting?Link.mN(t)?this.routing=t:t===9||t===10||t===11?this.curve=t:t===17||t===18||t===19?this.adjusting=t:t===1||t===0||U.o("Unknown Link enum value for a Link property: "+t):super.oi(t)}static Normal=1;static Orthogonal=2;static AvoidsNodes=6;static AvoidsNodesStraight=7;static None=0;static Bezier=9;static JumpGap=10;static JumpOver=11;static End=17;static Scale=18;static Stretch=19;static OrientAlong=21;static OrientPlus90=22;static OrientMinus90=23;static OrientOpposite=24;static OrientUpright=25;static OrientPlus90Upright=26;static OrientMinus90Upright=27;static OrientUpright45=28;static hO=8;static aO=16;static cO=14;static Ua=8;Be(){return this.ct===null&&(this.ct=new LinkSettings),this.ct}bv(t,i,e){const s=t.segmentIndex,n=t.segmentFraction;let o=t.alignmentFocus;const r=t.segmentOrientation,l=t.segmentOffset;let h=0,c=0,a=0,f=0;if(isNaN(s)){const C=this.ot,M=U.et();C.getPointAndAngleAlongPath(n,M);const N=Point.V(M[0],M[1]);if(N.add(this.getPoint(0)),C.type===1)N.offset(-C.startX,-C.startY);else{const T=C.figures.first();N.offset(-T.startX,-T.startY)}f=M[2],r!==0&&(a=this.computeAngle(t,r,f),t.angle=a),h=N.x,c=N.y,Point.e(N),U.J(M)}else if(s<-i||s>=i){const C=Point.l();this.OA(C),f=this.midAngle,r!==0&&(a=this.computeAngle(t,r,f),t.angle=a),h=C.x,c=C.y,Point.e(C)}else{let C,M,N=0;if(s>=0?(C=e.r[s],M=s0?e.r[N-1]:C),C.equalsApprox(M)){let T,A;s>=0?(T=s>0?e.r[s-1]:C,A=s1?e.r[N-2]:M);const D=T.distanceSquaredPoint(C),F=M.distanceSquaredPoint(A);D>F+10?f=s>=0?T.directionPoint(C):C.directionPoint(T):F>D+10?f=s>=0?M.directionPoint(A):A.directionPoint(M):f=s>=0?T.directionPoint(A):A.directionPoint(T)}else f=s>=0?C.directionPoint(M):M.directionPoint(C);r!==0&&(a=this.computeAngle(t,r,f),t.angle=a),h=C.x+(M.x-C.x)*n,c=C.y+(M.y-C.y)*n}if(o.isNone()){t.location=new Point(h,c);return}else o.isNoSpot()&&(o=Spot.Center);const u=Transform.l();u.Ri(),u.tt(t.scale,t.scale),u.cs(t.angle,0,0);const d=t.naturalBounds,m=Rect.V(0,0,d.width,d.height),g=Point.l();g.setRectSpot(m,o),u.gt(g);let p=-g.x,w=-g.y;const x=d.width,k=d.height,b=Point.l();b.a(l);const P=isNaN(l.x),S=isNaN(l.y);if(P||S){const C=x/2+3,M=k/2+3,N=f>=45&&f<=135,T=f>=225&&f<=315;r===0&&(N||T)?(b.x=S?C:l.y,b.y=P?M:l.x,N?s>=0||isNaN(s)&&n<.5||P&&(b.y=-M):T&&((s>=0||isNaN(s)&&n<.5)&&P&&(b.y=-M),S&&(b.x=-C))):(P&&(s>=0||isNaN(s)&&n<.5?b.x=C:b.x=-C),S&&(b.y=-M),b.rotate(f))}else b.rotate(f);h+=b.x,c+=b.y,u.vg(m),p+=m.x,w+=m.y;const L=Point.V(h+p,c+w);t.move(L),Point.e(L),Point.e(b),Point.e(g),Rect.e(m),Transform.e(u)}Yr(){let t=this.fromNode;if(t!==null){const e=t.findVisibleNode();if(e!==null&&(t=e),t._e()||t.ih())return!1}let i=this.toNode;if(i!==null){const e=i.findVisibleNode();if(e!==null&&(i=e),i._e()||i.ih())return!1}return!0}M2(t,i,e){return!1}N2(){}ke(){return!1}computeAngle(t,i,e){return Link.computeAngle(i,e)}static computeAngle(t,i){let e=0;switch(t){default:case 0:e=0;break;case 21:e=i;break;case 22:e=i+90;break;case 23:e=i-90;break;case 24:e=i+180;break;case 25:e=Geo.Ug(i),e>90&&e<270&&(e-=180);break;case 26:e=Geo.Ug(i+90),e>90&&e<270&&(e-=180);break;case 27:e=Geo.Ug(i-90),e>90&&e<270&&(e-=180);break;case 28:if(e=Geo.Ug(i),e>45&&e<135||e>225&&e<315)return 0;e>90&&e<270&&(e-=180);break}return Geo.Ug(e)}get fromNode(){return this.so}set fromNode(t){const i=this.so;if(i!==t){const e=this.fromPort;i!==null&&(this.oo!==i&&i.b1(this,e),this.wy(),this.invalidateLayout(2)),this.so=t,t!==null&&this.Ei(t.isVisible()),this.Ko=null,this.invalidateRoute();const s=this.diagram;s!==null&&s.X&&s.partManager.setFromNodeForLink(this,t,i);const n=this.fromPort,o=this.fromPortChanged;if(o!==null){let r=!0;s!==null&&(r=s.X,s.X=!0),o(this,e,n),s!==null&&(s.X=r)}t!==null&&(this.oo!==t&&t.w1(this,n),this.xy(),this.invalidateLayout(1)),this.t("fromNode",i,t),this.Pd()}}get fromPortId(){return this.no}set fromPortId(t){const i=this.no;if(i!==t){const e=this.fromPort;e!==null&&this.fromNode?.qi(e),this.wy(),this.no=t;const s=this.fromPort;s!==null&&this.fromNode?.qi(s);const n=this.diagram;if(n!==null){const o=this.data,r=n.model;o!==null&&r.Ra()&&r.setFromPortIdForLinkData(o,t)}if(e!==s){this.Ko=null,this.invalidateRoute();const o=this.fromPortChanged;if(o!==null){let r=!0;n!==null&&(r=n.X,n.X=!0),o(this,e,s),n!==null&&(n.X=r)}}this.xy(),this.t("fromPortId",i,t)}}get fromPort(){const t=this.so;if(t===null)return null;const i=this.no;return t.findPort(i)}get fromPortChanged(){return this.Md}set fromPortChanged(t){const i=this.Md;i!==t&&(t!==null&&U.k(t,Link,"fromPortChanged"),this.Md=t,this.t("fromPortChanged",i,t))}get toNode(){return this.oo}set toNode(t){const i=this.oo;if(i!==t){const e=this.toPort;i!==null&&(this.so!==i&&i.b1(this,e),this.wy(),this.invalidateLayout(2)),this.oo=t,t!==null&&this.Ei(t.isVisible()),this.Ko=null,this.invalidateRoute();const s=this.diagram;s!==null&&s.X&&s.partManager.setToNodeForLink(this,t,i);const n=this.toPort,o=this.toPortChanged;if(o!==null){let r=!0;s!==null&&(r=s.X,s.X=!0),o(this,e,n),s!==null&&(s.X=r)}t!==null&&(this.so!==t&&t.w1(this,n),this.xy(),this.invalidateLayout(1)),this.t("toNode",i,t),this.Pd()}}get toPortId(){return this.ro}set toPortId(t){const i=this.ro;if(i!==t){const e=this.toPort;e!==null&&this.toNode?.qi(e),this.wy(),this.ro=t;const s=this.toPort;s!==null&&this.toNode?.qi(s);const n=this.diagram;if(n!==null){const o=this.data,r=n.model;o!==null&&r.Ra()&&r.setToPortIdForLinkData(o,t)}if(e!==s){this.Ko=null,this.invalidateRoute();const o=this.toPortChanged;if(o!==null){let r=!0;n!==null&&(r=n.X,n.X=!0),o(this,e,s),n!==null&&(n.X=r)}}this.xy(),this.t("toPortId",i,t)}}get toPort(){const t=this.oo;if(t===null)return null;const i=this.ro;return t.findPort(i)}get toPortChanged(){return this.Nd}set toPortChanged(t){const i=this.Nd;i!==t&&(t!==null&&U.k(t,Link,"toPortChanged"),this.Nd=t,this.t("toPortChanged",i,t))}get fromSpot(){return this.ct!==null?this.ct.ga:Spot.Default}set fromSpot(t){const i=this.fromSpot;if(!i.equals(t)){if(t=t.P(),this.Be().ga=t,this.t("fromSpot",i,t),i.isSide()||t.isSide()){const e=this.fromNode;e!==null&&e.qi(this.fromPort)}this.invalidateRoute()}}get fromEndSegmentLength(){return this.ct!==null?this.ct.pa:NaN}set fromEndSegmentLength(t){const i=this.fromEndSegmentLength;if(i!==t){if(t<0&&U.W(t,">= 0",Link,"fromEndSegmentLength"),this.Be().pa=t,this.t("fromEndSegmentLength",i,t),this.computeSpot(!0,this.fromPort).isSide()){const e=this.fromNode;e!==null&&e.qi(this.fromPort)}this.invalidateRoute()}}get fromShortLength(){return this.ct!==null?this.ct.wa:NaN}set fromShortLength(t){const i=this.fromShortLength;i!==t&&(this.Be().wa=t,this.ee(),this.t("fromShortLength",i,t))}get toSpot(){return this.ct!==null?this.ct.ma:Spot.Default}set toSpot(t){const i=this.toSpot;if(!i.equals(t)){if(t=t.P(),this.Be().ma=t,this.t("toSpot",i,t),i.isSide()||t.isSide()){const e=this.toNode;e!==null&&e.qi(this.toPort)}this.invalidateRoute()}}get toEndSegmentLength(){return this.ct!==null?this.ct.ya:NaN}set toEndSegmentLength(t){const i=this.toEndSegmentLength;if(i!==t){if(t<0&&U.W(t,">= 0",Link,"toEndSegmentLength"),this.Be().ya=t,this.t("toEndSegmentLength",i,t),this.computeSpot(!1,this.toPort).isSide()){const e=this.toNode;e!==null&&e.qi(this.toPort)}this.invalidateRoute()}}get toShortLength(){return this.ct!==null?this.ct.xa:NaN}set toShortLength(t){const i=this.toShortLength;i!==t&&(this.Be().xa=t,this.ee(),this.t("toShortLength",i,t))}Pd(){const t=this.fromNode,i=this.toNode;let e=null;if(t!==null?i!==null?e=t.findCommonContainingGroup(i):e=t.containingGroup:i!==null?e=i.containingGroup:e=null,this.fO(e),this.isLabeledLink){const s=this.labelNodes;for(;s.next();){const n=s.value;n.containingGroup=e}}}fO(t){const i=this.xh;if(i!==t){i!==null&&i.eN(this),this.xh=t,t!==null&&t.sN(this);const e=this.containingGroupChanged;if(e!==null){let s=!0;const n=this.diagram;n!==null&&(s=n.X,n.X=!0),e(this,i,t),n!==null&&(n.X=s)}this.Se&&(this.fN===i||this.uN===i)&&this.invalidateRoute()}}dh(){const t=this.containingGroup;t!==null&&this.fromNode!==t&&this.toNode!==t&&t.computesBoundsIncludingLinks&&super.dh()}getOtherNode(t){const i=this.fromNode;return t===i?this.toNode:i}getOtherPort(t){const i=this.fromPort;return t===i?this.toPort:i}get isLabeledLink(){return this.js===null?!1:this.js.count>0}get labelNodes(){return this.js===null?EmptyIterator.instance:this.js.iterator}yT(t){this.js===null&&(this.js=new GSet),this.js.add(t),this.c()}wT(t){this.js!==null&&(this.js.delete(t),this.c())}Rm(t){if(super.Rm(t),this.Ba()&&this.invalidateOtherJumpOvers(this.actualBounds),!t){const i=this.so;let e=null;i!==null&&(e=this.fromPort,i.w1(this,e));const s=this.oo;let n=null;s!==null&&(n=this.toPort,(s!==i||n!==e)&&s.w1(this,n)),this.xy()}}vm(t){if(super.vm(t),this.Ba()&&this.invalidateOtherJumpOvers(this.actualBounds),!t){const i=this.so;let e=null;i!==null&&(e=this.fromPort,i.b1(this,e));const s=this.oo;let n=null;s!==null&&(n=this.toPort,(s!==i||n!==e)&&s.b1(this,n)),this.wy()}}Xc(){if(this.Se=!0,this.js!==null){const i=this.diagram;if(i!==null){const s=this.js.copy().iterator;for(;s.next();){const n=s.value;i.remove(n)}}}if(this.data!==null){const i=this.diagram;i!==null&&i.partManager.pN(this)}}updateRelationshipsFromData(){if(this.data===null)return;const i=this.diagram;i!==null&&i.partManager.updateRelationshipsFromData(this)}move(t,i){const e=i?this.location:this.position;let s=e.x;isNaN(s)&&(s=0);let n=e.y;isNaN(n)&&(n=0);const o=t.x-s,r=t.y-n;if(i===!0)super.move(t,!1);else{const h=Point.V(e.x+o,e.y+r);super.move(h,!1),Point.e(h)}this.fr(o,r);const l=this.labelNodes;for(;l.next();){const h=l.value,c=h.position;h.moveTo(c.x+o,c.y+r)}}get relinkableFrom(){return(this.Nt&1)!==0}set relinkableFrom(t){const i=(this.Nt&1)!==0;i!==t&&(this.Nt=this.Nt^1,this.t("relinkableFrom",i,t),this.invalidateAdornments())}get relinkableTo(){return(this.Nt&2)!==0}set relinkableTo(t){const i=(this.Nt&2)!==0;i!==t&&(this.Nt=this.Nt^2,this.t("relinkableTo",i,t),this.invalidateAdornments())}canRelinkFrom(){if(!this.relinkableFrom)return!1;const t=this.layer;if(t===null)return!0;if(!t.allowRelink)return!1;const i=t.diagram;return!(i!==null&&!i.allowRelink)}canRelinkTo(){if(!this.relinkableTo)return!1;const t=this.layer;if(t===null)return!0;if(!t.allowRelink)return!1;const i=t.diagram;return!(i!==null&&!i.allowRelink)}get resegmentable(){return(this.Nt&4)!==0}set resegmentable(t){const i=(this.Nt&4)!==0;i!==t&&(this.Nt=this.Nt^4,this.t("resegmentable",i,t),this.invalidateAdornments())}get isTreeLink(){return(this.Nt&8)!==0}set isTreeLink(t){const i=(this.Nt&8)!==0;i!==t&&(this.Nt=this.Nt^8,this.t("isTreeLink",i,t),this.fromNode!==null&&this.fromNode.l0(),this.toNode!==null&&this.toNode.l0())}get path(){const t=this.findMainElement();return t instanceof Shape?t:null}get routeBounds(){return this.updateRoute(),this.uO(this.Sf)}uO(t){let i=1/0,e=1/0;const s=this.pointsCount;if(s===0)return t.i(NaN,NaN,0,0),t;if(s===1){const n=this.getPoint(0);i=Math.min(n.x,i),e=Math.min(n.y,e),t.i(n.x,n.y,0,0)}else if(s===2){const n=this.getPoint(0),o=this.getPoint(1);i=Math.min(n.x,o.x),e=Math.min(n.y,o.y),t.i(n.x,n.y,0,0),t.unionPoint(o)}else if(this.computeCurve()===9&&s>=3&&!this.isOrthogonal){let n=this.getPoint(0);if(i=n.x,e=n.y,t.i(i,e,0,0),s===3){const o=this.getPoint(1);i=Math.min(o.x,i),e=Math.min(o.y,e);const r=this.getPoint(2);i=Math.min(r.x,i),e=Math.min(r.y,e),Geo.ou(n.x,n.y,o.x,o.y,o.x,o.y,r.x,r.y,.5,t)}else for(let o=3;o=s&&(o=s-1);const l=this.getPoint(o-1),h=this.getPoint(o);Geo.ou(n.x,n.y,r.x,r.y,l.x,l.y,h.x,h.y,.5,t),i=Math.min(h.x,i),e=Math.min(h.y,e),n=h}}else{const n=this.getPoint(0),o=this.getPoint(1);i=Math.min(n.x,o.x),e=Math.min(n.y,o.y),t.i(n.x,n.y,0,0),t.unionPoint(o);for(let r=2;r=15||this.computeCurve()===9)){this.ot.getPointAlongPath(.5,t),t.add(this.getPoint(0));const c=this.ot.figures.first();return t.offset(-c.startX,-c.startY),t}if(this.computeCurve()===9){if(i===3){const f=this.getPoint(0),u=this.getPoint(1),d=this.getPoint(2);return Geo.AC(f.x,f.y,u.x,u.y,u.x,u.y,d.x,d.y,t),t}const c=(i-1)/3|0,a=(c/2|0)*3;if(c%2===1){const f=this.getPoint(a),u=this.getPoint(a+1),d=this.getPoint(a+2),m=this.getPoint(a+3);return Geo.AC(f.x,f.y,u.x,u.y,d.x,d.y,m.x,m.y,t),t}else return t.a(this.getPoint(a)),t}const e=this.flattenedLengths,s=this.flattenedTotalLength;let n=0,o=0,r=0;for(;ns/2));)n+=r,o++;const l=this.getPoint(o),h=this.getPoint(o+1);if(Math.abs(l.x-h.x)<1)l.y>h.y?t.i(l.x,l.y-(s/2-n)):t.i(l.x,l.y+(s/2-n));else if(Math.abs(l.y-h.y)<1)l.x>h.x?t.i(l.x-(s/2-n),l.y):t.i(l.x+(s/2-n),l.y);else{const c=(s/2-n)/r,a=c*(h.x-l.x),f=c*(h.y-l.y);t.i(l.x+a,l.y+f)}return t}get midAngle(){return this.updateRoute(),this.computeMidAngle()}computeMidAngle(){const t=this.pointsCount;if(t<2)return NaN;if(t===2){const h=this.getPoint(0),c=this.getPoint(1);return h.directionPoint(c)}if(this.isOrthogonal&&(this.computeCorner()>=15||this.computeCurve()===9))return this.ot.getAngleAlongPath(.5);if(this.computeCurve()===9&&t>=4){const h=(t-1)/3|0;let c=(h/2|0)*3;if(h%2===1){c=Math.floor(c);const a=this.getPoint(c),f=this.getPoint(c+1),u=this.getPoint(c+2),d=this.getPoint(c+3);return Geo._D(a.x,a.y,f.x,f.y,u.x,u.y,d.x,d.y)}else if(c>0&&c+1e/2));)s+=o,n++;const r=this.getPoint(n),l=this.getPoint(n+1);if(Math.abs(r.x-l.x)<1&&Math.abs(r.y-l.y)<1){if(n>0&&n+2l.y?270:90;if(Math.abs(r.y-l.y)<1)return r.x>l.x?180:0}return r.directionPoint(l)}get flattenedLengths(){return this.Oa!==null?this.Oa:(this.Se||this.S1(),this.dO())}get flattenedTotalLength(){let t=this.P1;if(isNaN(t)){const i=this.flattenedLengths,e=i.length;t=0;for(let s=0;s=3){let g=this.getLinkPoint(i,e,r,!0,!1,s,n),p=this.getLinkPoint(s,n,l,!1,!1,i,e);m=this.adjustPoints(0,g,o-1,p),m&&(g=this.getLinkPoint(i,e,r,!0,!1,s,n),p=this.getLinkPoint(s,n,l,!1,!1,i,e),this.adjustPoints(0,g,o-1,p))}m||(this.clearPoints(),u?this.gO(i,e,r,s,n,l):this.mO(i,e,r,s,n,l))}else{const m=this.isAvoiding;d&&(f&&m||a)&&this.clearPoints();const g=a?this.computeCurviness():0,p=this.getLinkPoint(i,e,r,!0,f,s,n);let w=0,x=0,k=0;if(f||!h||a){let N=this.computeEndSegmentLength(i,e,r,!0);if(k=this.getLinkDirection(i,e,p,r,!0,f,s,n),a&&(h||r.equals(l)||!f&&r.x+l.x===1&&r.y+l.y===1)&&(k-=f?90:30,g<0&&(k-=180)),k<0?k+=360:k>=360&&(k-=360),a&&(N+=Math.abs(g)*(f?1:2)),k===0?w=N:k===90?x=N:k===180?w=-N:k===270?x=-N:(w=N*Math.cos(k*Math.PI/180),x=N*Math.sin(k*Math.PI/180)),r.isNoSpot()&&a){const T=e.getDocumentPoint(Spot.Center,Point.l()),A=Point.V(T.x+w*1e3,T.y+x*1e3);this.getLinkPointFromPoint(i,e,T,A,!0,p),Point.e(T),Point.e(A)}}const b=this.getLinkPoint(s,n,l,!1,f,i,e);let P=0,S=0,L=0;if(f||!c||a){let N=this.computeEndSegmentLength(s,n,l,!1);if(L=this.getLinkDirection(s,n,b,l,!1,f,i,e),a&&(c||r.equals(l)||!f&&r.x+l.x===1&&r.y+l.y===1)&&(L+=f?0:30,g<0&&(L+=180)),L<0?L+=360:L>=360&&(L-=360),a&&(N+=Math.abs(g)*(f?1:2)),L===0?P=N:L===90?S=N:L===180?P=-N:L===270?S=-N:(P=N*Math.cos(L*Math.PI/180),S=N*Math.sin(L*Math.PI/180)),l.isNoSpot()&&a){const T=n.getDocumentPoint(Spot.Center,Point.l()),A=Point.V(T.x+P*1e3,T.y+S*1e3);this.getLinkPointFromPoint(s,n,T,A,!1,b),Point.e(T),Point.e(A)}}let C=p;(f||!h||a)&&(C=new Point(p.x+w,p.y+x));let M=b;(f||!c||a)&&(M=new Point(b.x+P,b.y+S)),!d&&!f&&h&&o>3&&this.adjustPoints(0,p,o-2,M)?this.setPoint(o-1,b):!d&&!f&&c&&o>3&&this.adjustPoints(1,C,o-1,b)?this.setPoint(0,p):!d&&(f?o>=6:o>4)&&this.adjustPoints(1,C,o-2,M)?(this.setPoint(0,p),this.setPoint(o-1,b)):(this.clearPoints(),this.addPoint(p),(f||!h||a)&&this.addPoint(C),f&&this.addOrthoPoints(C,k,M,L,i,s),(f||!c||a)&&this.addPoint(M),this.addPoint(b))}return t.addInvalidRoute(this),!0}wN(t,i){return Math.abs(i.x-t.x)>Math.abs(i.y-t.y)?(i.x>=t.x?i.x=t.x+9e9:i.x=t.x-9e9,i.y=t.y):(i.y>=t.y?i.y=t.y+9e9:i.y=t.y-9e9,i.x=t.x),i}getLinkPointFromPoint(t,i,e,s,n,o){if(o===void 0&&(o=new Point),t===null||i===null)return o.a(e),o;if(!t.isVisible()){const u=t.findVisibleNode();u!==null&&u!==t&&(t=u,i=t.port)}let r=0,l=0,h=0,c=0,a=null,f=i.panel;if(f!==null&&!f.an()&&(f=f.panel),f===null)r=s.x,l=s.y,h=e.x,c=e.y;else{a=f.Us;const u=1/(a.m11*a.m22-a.m12*a.m21),d=a.m22*u,m=-a.m12*u,g=-a.m21*u,p=a.m11*u,w=u*(a.m21*a.dy-a.m22*a.dx),x=u*(a.m12*a.dx-a.m11*a.dy);r=s.x*d+s.y*g+w,l=s.x*m+s.y*p+x,h=e.x*d+e.y*g+w,c=e.x*m+e.y*p+x}return i.Jc(r,l,h,c,o),a!==null&&o.T(a),o}pO(t,i){const e=t.Ku;return e!==null?e.ST(i):null}N1(t){if(t===null)return null;let i=t.Ku;return i===null&&(i=new Knot(t.part,t),t.Ku=i),i.ST(this)}getLinkPoint(t,i,e,s,n,o,r,l){if(l===void 0&&(l=new Point),e.isSpot()&&!this.Dd(e))return i.getDocumentPoint(e,l),l;if(e.isSide()){const a=this.N1(i);if(a!==null){const f=a.Fd;if(l.a(f),n&&this.routing===7){const u=this.N1(r);if(u!==null&&a.Mf=g.y&&w.y<=g.y+g.height?l.y=w.y:(e.includesSide(Spot.TopSide)||e.includesSide(Spot.BottomSide))&&w.x>=g.x&&w.x<=g.x+g.width&&(l.x=w.x),Point.e(d),Point.e(m)}}return l}}const h=i.getDocumentPoint(this.C1(e,s),Point.l());let c=null;if(this.pointsCount>(n?6:2))c=s?this.getPoint(1):this.getPoint(this.pointsCount-2),n&&(c=this.wN(h,c.copy()));else{const a=this.computeSpot(!s,r),f=Point.l();c=r.getDocumentPoint(this.C1(a,!s),f),n&&(c=this.wN(h,c)),Point.e(f)}return this.getLinkPointFromPoint(t,i,h,c,s,l),Point.e(h),l}getLinkDirection(t,i,e,s,n,o,r,l){let h=this.yO(t,i,e,s,n,o,r,l);if(r&&s.isNoSpot()&&r.isMemberOf(t)&&(h+=180,h>=360&&(h-=360)),this.Dd(s)||i===null)return h;const c=i.getDocumentAngle();return c===0||(45<=c&&c<135?h+=90:135<=c&&c<225?h+=180:225<=c&&c<315&&(h+=270),h>=360&&(h-=360)),h}yO(t,i,e,s,n,o,r,l){if(s.isSpot())return s.x>s.y?s.x>1-s.y?0:s.x<1-s.y?270:315:s.x1-s.y?90:s.x<1-s.y?180:135:s.x<.5?225:s.x>.5?45:0;if(s.isSide()){const f=this.N1(i);if(f!==null)switch(f.me){case 1:return 270;case 2:return 180;default:case 4:return 0;case 8:return 90}else return s.includesSide(Spot.TopSide)?270:s.includesSide(Spot.BottomSide)?90:s.includesSide(Spot.LeftSide)?180:0}if(i===null||l===null)return 0;const h=i.getDocumentPoint(Spot.Center,Point.l());let c=null;if(this.pointsCount>(o?6:2))c=n?this.getPoint(1):this.getPoint(this.pointsCount-2),o?c=this.wN(h,c.copy()):c=e;else{const f=Point.l();c=l.getDocumentPoint(Spot.Center,f),Point.e(f)}let a=0;return Math.abs(c.x-h.x)>Math.abs(c.y-h.y)?c.x>=h.x?a=0:a=180:c.y>=h.y?a=90:a=270,Point.e(h),a}computeEndSegmentLength(t,i,e,s){if(i!==null&&e.isSide()){const o=this.N1(i);if(o!==null)return o.L1}let n=NaN;return s?n=this.fromEndSegmentLength:n=this.toEndSegmentLength,i!==null&&isNaN(n)&&(s?n=i.fromEndSegmentLength:n=i.toEndSegmentLength),isNaN(n)&&(n=10),n}computeSpot(t,i){return i===void 0&&(i=null),t?this.wO(i||this.fromPort):this.xO(i||this.toPort)}wO(t){if(t===null)return Spot.Center;let i=this.fromSpot;return i.isDefault()&&(i=t.fromSpot),i===Spot.Default?Spot.None:i}xO(t){if(t===null)return Spot.Center;let i=this.toSpot;return i.isDefault()&&(i=t.toSpot),i===Spot.Default?Spot.None:i}Dd(t){return t===Spot.None||t.x===.5&&t.y===.5}C1(t,i){return t.x===.5&&t.y===.5?t:Spot.Center}computeOtherPoint(t,i){if(this.computeAdjusting()!==0&&this.pointsCount>4)return this.computeMidPoint(new Point);{const e=this.pO(i,this);return e!==null?e.Fd:i.getDocumentPoint(Spot.Center)}}computeShortLength(t){if(t){let i=this.fromShortLength;if(isNaN(i)){const e=this.fromPort;e!==null&&(i=e.fromShortLength)}return isNaN(i)?0:i}else{let i=this.toShortLength;if(isNaN(i)){const e=this.toPort;e!==null&&(i=e.toShortLength)}return isNaN(i)?0:i}}Tm(t,i,e,s,n,o){if(this.pickable===!1)return!1;i===void 0&&(i=null),e===void 0&&(e=null);let r;if(o===void 0?(r=Transform.l(),r.Ri()):r=o,r.nc(this.T),this.containedInRect(t,r))return this.Y2(i,e,n),o===void 0&&Transform.e(r),!0;if(this.intersectsRect(t,r)){let l=!1;if(!this.af){const h=this.C.r,c=h.length;for(let a=c;a--;){const f=h[a];if(!f.visible&&f!==this.locationObject)continue;const u=f.actualBounds,d=this.naturalBounds;if(u.x>d.width||u.y>d.height||u.x+u.width<0||u.y+u.height<0)continue;const m=f,g=Transform.l();if(g.set(r),m instanceof Panel?l=m.Tm(t,i,e,s,n,g):this.path===m?m instanceof Shape&&(l=m.Yv(t,s,g)):l=m.wA(t,s,g),l){let p=m;i!==null&&(p=i(m)),p&&(e===null||e(p))&&n.add(p)}Transform.e(g)}}return o===void 0&&Transform.e(r),l||this.background!==null}return o===void 0&&Transform.e(r),!1}get isOrthogonal(){return(this.va&2)===2}static mN(t){return(t&2)===2}get isAvoiding(){return(this.va&4)===4}computeCurve(){if(this.Ko===null){const t=this.fromPort,i=t!==null&&t===this.toPort,e=this.isOrthogonal;this.Ko=i&&!e}return this.Ko?9:this.curve}computeCorner(){if(this.curve===9)return 0;let t=this.corner;return(isNaN(t)||t<0)&&(t=10),t}findMidLabel(){const t=this.path,i=this.C.r,e=i.length;for(let n=0;n0?g-=f:g+=f;else{const p=-h/c;let w=Math.sqrt(f*f/(p*p+1));a<0&&(w=-w),m=(c<0?-1:1)*w+u,g=p*(m-u)+d}this.addPoint(r),this.addPointAt(m,g),this.addPoint(l)}else{this.addPoint(r),this.addPoint(l);const h=Rect.l();i.getDocumentBounds(h);const c=h.containsPoint(l);n.getDocumentBounds(h);const a=h.containsPoint(r);if(c||a){const f=i.getDocumentPoint(this.C1(e,!0),new Point);this.setPoint(0,this.getLinkPointFromPoint(t,i,f,l,!0,f));const u=n.getDocumentPoint(this.C1(o,!1),new Point);this.setPoint(1,this.getLinkPointFromPoint(s,n,u,r,!1,u))}Rect.e(h)}}gO(t,i,e,s,n,o){const r=this.getLinkPoint(t,i,e,!0,!1,s,n),l=this.getLinkPoint(s,n,o,!1,!1,t,i),h=l.x-r.x,c=l.y-r.y,a=this.computeCurviness();let f=0,u=0,d=r.x+h/3,m=r.y+c/3,g=d,p=m;Geo.f(c,0)?h>0?p-=a:p+=a:(f=-h/c,u=Math.sqrt(a*a/(f*f+1)),a<0&&(u=-u),g=(c<0?-1:1)*u+d,p=f*(g-d)+m),d=r.x+2*h/3,m=r.y+2*c/3;let w=d,x=m;Geo.f(c,0)?h>0?x-=a:x+=a:(w=(c<0?-1:1)*u+d,x=f*(w-d)+m),this.clearPoints(),this.addPoint(r),this.addPointAt(g,p),this.addPointAt(w,x),this.addPoint(l),this.setPoint(0,this.getLinkPoint(t,i,e,!0,!1,s,n)),this.setPoint(3,this.getLinkPoint(s,n,o,!1,!1,t,i))}adjustPoints(t,i,e,s){let n=this.computeAdjusting();if(this.isOrthogonal){if(n===18)return!1;n===19&&(n=17)}switch(n){case 18:return this.bO(t,i,e,s);case 19:return this.kO(t,i,e,s);case 17:return this.PO(t,i,e,s);default:return!1}}bO(t,i,e,s){const n=this.getPoint(t),o=this.getPoint(e);if(n.equalsApprox(i)&&o.equalsApprox(s))return!0;const r=n.x,l=n.y,h=o.x,c=o.y;let a=h-r,f=c-l;const u=Math.sqrt(a*a+f*f);if(Geo.z(u,0))return!0;let d=0;Geo.z(a,0)?f<0?d=-Math.PI/2:d=Math.PI/2:(d=Math.atan(f/Math.abs(a)),a<0&&(d=Math.PI-d));const m=i.x,g=i.y,p=s.x,w=s.y,x=p-m,k=w-g,b=Math.sqrt(x*x+k*k);let P=0;Geo.z(x,0)?k<0?P=-Math.PI/2:P=Math.PI/2:(P=Math.atan(k/Math.abs(x)),x<0&&(P=Math.PI-P));const S=b/u,L=P-d;this.setPoint(t,i);for(let C=t+1;C0&&(C=-C);const M=f+P*(d-f),N=u+P*(m-u);if(g!==0){const T=M+C/p,A=N-(T-M)/g;this.setPointAt(w,T,A)}else this.setPointAt(w,M,N+C)}return this.setPoint(e,s),!0}PO(t,i,e,s){if(this.isOrthogonal){let n=this.getPoint(t),o=this.getPoint(t+1),r=this.getPoint(t+2),l=o.x,h=o.y;const c=l,a=h;Geo.f(n.y,o.y)?Geo.f(o.x,r.x)?h=i.y:Geo.f(o.y,r.y)&&(l=i.x):Geo.f(n.x,o.x)&&(Geo.f(o.y,r.y)?l=i.x:Geo.f(o.x,r.x)&&(h=i.y)),this.setPointAt(t+1,l,h),n=this.getPoint(e),o=this.getPoint(e-1),r=this.getPoint(e-2);let f=o.x,u=o.y;const d=f,m=u;if(Geo.f(n.y,o.y)?Geo.f(o.x,r.x)?u=s.y:Geo.f(o.y,r.y)&&(f=s.x):Geo.f(n.x,o.x)&&(Geo.f(o.y,r.y)?f=s.x:Geo.f(o.x,r.x)&&(u=s.y)),this.setPointAt(e-1,f,u),this.WL())return this.setPointAt(t+1,c,a),this.setPointAt(e-1,d,m),!1}return this.setPoint(t,i),this.setPoint(e,s),!0}addOrthoPoints(t,i,e,s,n,o){i<0?i+=360:i>=360&&(i-=360),s<0?s+=360:s>=360&&(s-=360);const a=s;i>=315||i<45?i=0:45<=i&&i<135?i=90:135<=i&&i<225?i=180:i=270,s>=315||s<45?s=0:45<=s&&s<135?s=90:135<=s&&s<225?s=180:s=270;const f=t,u=e,d=n.actualBounds.copy(),m=o.actualBounds.copy();if(!d.isReal()||!m.isReal())return;d.inflate(Link.Ua,Link.Ua),m.inflate(Link.Ua,Link.Ua),d.unionPoint(t),m.unionPoint(e);const g=Point.l(),p=Point.l();i===0?u.x>f.x||s===270&&u.yf.x||s===90&&u.y>f.y&&m.right>f.x?(g.i(u.x,f.y),p.i(u.x,(f.y+u.y)/2),s===180?(g.x=this.computeMidOrthoPosition(f.x,f.y,u.x,u.y,!1),p.x=g.x,p.y=u.y):s===270&&u.yf.y?(f.xm.bottom)?g.x=this.computeMidOrthoPosition(f.x,f.y,u.x,u.y,!1):g.x=m.right,p.x=g.x,p.y=u.y):s===0&&f.xm.top&&f.yd.bottom)&&(s===180&&(m.containsPoint(f)||d.containsPoint(u))?g.y=this.computeMidOrthoPosition(f.x,f.y,u.x,u.y,!0):u.yf.y&&(s===180||s===270)&&(g.y=this.computeMidOrthoPosition(f.x,d.bottom,u.x,Math.min(u.y,m.top),!0)),p.x=u.x,p.y=g.y),g.y>d.top&&g.y=d.left&&u.x<=f.x||f.x<=m.right&&f.x>=u.x?(s===90||s===270)&&(g.i(Math.max((f.x+u.x)/2,f.x),f.y),p.i(g.x,u.y)):(s===270||(s===0||s===180)&&u.yf.y&&m.leftf.y?(f.x>m.right?g.x=this.computeMidOrthoPosition(f.x,f.y,m.right,u.y,!1):f.x>m.left&&(s===270&&f.ym.bottom)?g.x=this.computeMidOrthoPosition(f.x,f.y,u.x,u.y,!1):g.x=m.left,p.x=g.x,p.y=u.y):s===180&&f.x>m.right&&f.y>m.top&&f.yd.bottom)&&(s===0&&(m.containsPoint(f)||d.containsPoint(u))?g.y=this.computeMidOrthoPosition(f.x,f.y,u.x,u.y,!0):u.yf.y&&(s===0||s===270)&&(g.y=this.computeMidOrthoPosition(f.x,d.bottom,u.x,Math.min(u.y,m.top),!0)),p.x=u.x,p.y=g.y),g.y>d.top&&g.y=f.x||f.x>=m.left&&f.x<=u.x?(s===90||s===270)&&(g.i(Math.min((f.x+u.x)/2,f.x),f.y),p.i(g.x,u.y)):(s===270||(s===0||s===180)&&u.yf.y||s===180&&u.xf.y||s===0&&u.x>f.x&&m.bottom>f.y?(g.i(f.x,u.y),p.i((f.x+u.x)/2,u.y),s===270?(g.y=this.computeMidOrthoPosition(f.x,f.y,u.x,u.y,!0),p.x=u.x,p.y=g.y):s===180&&u.xf.x?(f.ym.right)?g.y=this.computeMidOrthoPosition(f.x,f.y,u.x,u.y,!0):g.y=m.bottom,p.x=u.x,p.y=g.y):s===90&&f.ym.left&&f.xd.right)&&(s===270&&(m.containsPoint(f)||d.containsPoint(u))?g.x=this.computeMidOrthoPosition(f.x,f.y,u.x,u.y,!1):u.xf.x&&(s===270||s===180)&&(g.x=this.computeMidOrthoPosition(d.right,f.y,Math.min(u.x,m.left),u.y,!1)),p.x=g.x,p.y=u.y),g.x>d.left&&g.x=d.top&&u.y<=f.y||f.y<=m.bottom&&f.y>=u.y?(s===0||s===180)&&(g.i(f.x,Math.max((f.y+u.y)/2,f.y)),p.i(u.x,g.y)):(s===180||(s===90||s===270)&&u.xf.x&&m.top=f.x?(f.y>m.bottom?g.y=this.computeMidOrthoPosition(f.x,f.y,u.x,m.bottom,!0):f.y>m.top&&(s===180&&f.xm.right)?g.y=this.computeMidOrthoPosition(f.x,f.y,u.x,u.y,!0):g.y=m.top,p.x=u.x,p.y=g.y):s===270&&f.y>m.bottom&&f.x>m.left&&f.xd.right)&&(s===90&&(m.containsPoint(f)||d.containsPoint(u))?g.x=this.computeMidOrthoPosition(f.x,f.y,u.x,u.y,!1):u.xf.x&&(s===90||s===180)&&(g.x=this.computeMidOrthoPosition(d.right,f.y,Math.min(u.x,m.left),u.y,!1)),p.x=g.x,p.y=u.y),g.x>d.left&&g.x=f.y||f.y>=m.top&&f.y<=u.y?(s===0||s===180)&&(g.i(f.x,Math.min((f.y+u.y)/2,f.y)),p.i(u.x,g.y)):(s===180||(s===90||s===270)&&u.x=3&&!Geo.z(this.smoothness,0))if(i===3){let a=this.getPoint(1);n=Math.min(r.x,a.x),o=Math.min(r.y,a.y),a=this.getPoint(2),n=Math.min(n,a.x),o=Math.min(o,a.y)}else if(this.isOrthogonal){for(let a=0;a=i&&(a=i-1);const f=this.getPoint(a);l.x=Math.min(f.x,l.x),l.y=Math.min(f.y,l.y)}n=l.x,o=l.y}else{for(let a=0;a=3&&!Geo.z(this.smoothness,0))if(i===3){const f=this.getPoint(1),u=f.x-n,d=f.y-o;let m=this.getPoint(2).copy();m.x-=n,m.y-=o,this.computeShortLength(!1)!==0&&(m=this.Nf(m,!1,l)),a.hr(u,d,u,d,m.x,m.y)}else if(this.isOrthogonal){const f=Point.V(n,o),u=Point.l();u.a(this.getPoint(1));const d=Point.V(n,o),m=Point.V(n,o);let g=this.getPoint(0),p=null;const w=this.smoothness/3;for(let P=1;P=i&&(f=i-1);const d=this.getPoint(f-1);let m=this.getPoint(f);f===i-1&&this.computeShortLength(!1)!==0&&(m=this.Nf(m.copy(),!1,Point.xo)),a.hr(u.x-n,u.y-o,d.x-n,d.y-o,m.x-n,m.y-o)}else{const f=Point.l();f.a(this.getPoint(0));const u=Point.l();u.a(f);const d=this.computeCorner();let m=1,g=0;for(;m1);let p=this.getPoint(m);if(m>=i-1){if(!f.equals(p))this.computeShortLength(!1)!==0&&(p=this.Nf(p.copy(),!1,Point.xo)),this.xn(a,-n,-o,f,p,e);else if(g===0)for(m=1;mr?f>c?(n.x=h-u,n.y=c-u,o.x=h+d,o.y=c+d):(n.x=h-u,n.y=c+u,o.x=h+d,o.y=c-d):f>c?(n.x=h+u,n.y=c-u,o.x=h-d,o.y=c+d):(n.x=h+u,n.y=c+u,o.x=h-d,o.y=c-d)),Geo.z(r,h)&&Geo.z(c,f)&&(c>l?a>h?(n.x=h-u,n.y=c-u,o.x=h+d,o.y=c+d):(n.x=h+u,n.y=c-u,o.x=h-d,o.y=c+d):a>h?(n.x=h-u,n.y=c+u,o.x=h+d,o.y=c-d):(n.x=h+u,n.y=c+u,o.x=h-d,o.y=c-d)),Geo.z(r,h)&&Geo.z(h,a)||Geo.z(l,c)&&Geo.z(c,f)){const m=.5*(r+a),g=.5*(l+f);n.x=m,n.y=g,o.x=m,o.y=g}}Nf(t,i,e){const s=this.pointsCount;if(s<2)return t;if(i){const n=this.getPoint(1),o=n.x-e.x,r=n.y-e.y,l=this.A1(t.x,t.y,o,r);if(l===0)return t;const h=s===2?l*.5:l;let c=this.computeShortLength(!0);c>h&&(c=h);const a=c*(o-t.x)/l,f=c*(r-t.y)/l;t.x+=a,t.y+=f}else{const n=this.getPoint(s-2),o=n.x-e.x,r=n.y-e.y,l=this.A1(t.x,t.y,o,r);if(l===0)return t;const h=s===2?l*.5:l;let c=this.computeShortLength(!1);c>h&&(c=h);const a=c*(t.x-o)/l,f=c*(t.y-r)/l;t.x-=a,t.y-=f}return t}xN(t,i,e){const s=this.pointsCount;let n=t;for(;Geo.z(t.x,n.x)&&Geo.z(t.y,n.y);){if(i>=s)return s-1;n=this.getPoint(i++)}if(!Geo.z(t.x,n.x)&&!Geo.z(t.y,n.y))return i-1;let o=n;for(;Geo.z(t.x,n.x)&&Geo.z(n.x,o.x)&&(!e||(t.y>=n.y?n.y>=o.y:n.y<=o.y))||Geo.z(t.y,n.y)&&Geo.z(n.y,o.y)&&(!e||(t.x>=n.x?n.x>=o.x:n.x<=o.x));){if(i>=s)return s-1;o=this.getPoint(i++)}return i-2}NO(t,i,e,s,n,o,r,l,h,c){if(Geo.f(s.y,n.y)&&Geo.f(n.x,o.x)){let a=Math.min(h,Math.abs(n.x-l.x)/2);const f=Math.min(a,Math.abs(o.y-n.y)/2);if(a=f,Geo.f(a,0)){this.xn(t,i,e,s,n,c),r.a(n);return}let u=n.x;const d=n.y,m=u;let g=d;n.x>s.x?(u=n.x-a,o.y>n.y?g=n.y+f:g=n.y-f):(u=n.x+a,o.y>n.y?g=n.y+f:g=n.y-f);const p=Point.V(u,d);this.xn(t,i,e,s,p,c),Point.e(p),t.Cw(n.x+i,n.y+e,m+i,g+e),r.i(m,g)}else if(Geo.f(s.x,n.x)&&Geo.f(n.y,o.y)){let a=Math.min(h,Math.abs(n.y-l.y)/2);const f=Math.min(a,Math.abs(o.x-n.x)/2);if(a=f,Geo.f(f,0)){this.xn(t,i,e,s,n,c),r.a(n);return}const u=n.x;let d=n.y,m=u;const g=d;n.y>s.y?(d=n.y-a,o.x>n.x?m=n.x+f:m=n.x-f):(d=n.y+a,o.x>n.x?m=n.x+f:m=n.x-f);const p=Point.V(u,d);this.xn(t,i,e,s,p,c),Point.e(p),t.Cw(n.x+i,n.y+e,m+i,g+e),r.i(m,g)}else this.xn(t,i,e,s,n,c),r.a(n)}computeJumpLength(){return 10}xn(t,i,e,s,n,o){if(o||!this.Ba())t.lr(n.x+i,n.y+e);else{const r=this.computeJumpLength(),l=r/2,h=[];let c=0;this.isVisible()&&(c=this.CO(s,n,h));let a=s.x,f=s.y;if(c>0){if(Geo.f(s.y,n.y))if(s.x=0;){const d=Math.min(s.x,Math.max(h[u--]+l,n.x+r));t.lr(d+i,n.y+e),a=d+i,f=n.y+e;let m=Math.max(d-r,n.x);for(;u>=0;){const x=h[u];if(x>m-r)u--,m=Math.max(x-l,n.x);else break}const g=n.y-r+e,p=m+i,w=n.y+e;this.curve===10?t.hu(p,w,!1,!1):t.hr(a,g,p,g,p,w),a=p,f=w}}else if(Geo.f(s.x,n.x))if(s.y=0;){const d=Math.min(s.y,Math.max(h[u--]+l,n.y+r));t.lr(n.x+i,d+e),a=n.x+i,f=d+e;let m=Math.max(d-r,n.y);for(;u>=0;){const x=h[u];if(x>m-r)u--,m=Math.max(x-l,n.y);else break}const g=n.x-r+i,p=n.x+i,w=m+e;this.curve===10?t.hu(p,w,!1,!1):t.hr(g,f,g,w,p,w),a=p,f=w}}}t.lr(n.x+i,n.y+e)}}CO(t,i,e){const s=this.diagram;if(s===null||t.equals(i))return 0;const n=s.layers;for(;n.next();){const o=n.value;if(o!==null&&o.visible){const r=o.qS(),l=r.length;for(let h=0;h0&&e.sort((u,d)=>u-d),e.length;if(!c.isVisible()||!c.Ba())continue;const a=c.routeBounds;if(!a.isReal()||!this.routeBounds.intersectsRect(a)||this.usesSamePort(c))continue;const f=c.path;f!==null&&f.isVisibleObject()&&this.LO(t,i,e,c)}}}return e.length>0&&e.sort((o,r)=>o-r),e.length}LO(t,i,e,s){const n=Geo.f(t.y,i.y),o=s.pointsCount;let r=s.getPoint(0);const l=Point.l();for(let h=1;hr.x&&a.x>=c.x||c.xr.y&&a.y>=c.y||c.ya&&Math.min(c,f)o&&!Geo.f(c,f))return n.x=o,n.y=a,!0}else if(Geo.f(r,h)&&Geo.f(c,f)&&Math.min(o,l)c&&Math.min(a,u)r&&!Geo.f(a,u))return n.x=c,n.y=r,!0;return n.x=0,n.y=0,!1}get firstPickIndex(){return this.pointsCount<=2?0:this.isOrthogonal||!this.Dd(this.computeSpot(!0))?1:0}get lastPickIndex(){const t=this.pointsCount;return t===0?0:t<=2?t-1:this.isOrthogonal||!this.Dd(this.computeSpot(!1))?t-2:t-1}Ba(){const t=this.curve;return t===11||t===10}M1(t){if(t||this.Ba()){const i=this.diagram;i!==null&&!i.animationManager.isTicking&&!i.$l.has(this)&&(this.Sf.width!==0||this.Sf.height!==0)&&i.$l.set(this,this.Sf.copy())}}invalidateOtherJumpOvers(t){const i=this.layer;if(i===null||!i.visible||i.isTemporary)return;const e=i.diagram;if(e===null||e.animationManager.isTicking)return;let s=!1;const n=e.layers;for(;n.next();){const o=n.value;if(o.visible){if(o===i){s=!0;let r=!1;const l=o.qS(),h=l.length;for(let c=0;c0&&e>0){const s=this.getPoint(0),n=t.getPoint(0);if(s.equalsApprox(n))return!0;const o=this.getPoint(i-1),r=t.getPoint(e-1);if(o.equalsApprox(r)||s.equalsApprox(r)||o.equalsApprox(n))return!0}else if(this.fromNode===t.fromNode||this.toNode===t.toNode||this.fromNode===t.toNode||this.toNode===t.fromNode)return!0;return!1}isVisible(){if(!super.isVisible())return!1;const t=this.containingGroup;let i=!0;const e=this.diagram;e!==null&&(i=e.isTreePathToChildren);const s=this.fromNode;if(s!==null){if(this.isTreeLink&&i&&!s.isTreeExpanded)return!1;if(s===t)return!0;let o=s;for(;o!==null;){if(o.labeledLink===this)return!0;o=o.containingGroup}const r=s.findVisibleNode();if(r===null||r===t)return!1}const n=this.toNode;if(n!==null){if(this.isTreeLink&&!i&&!n.isTreeExpanded)return!1;if(n===t)return!0;let o=n;for(;o!==null;){if(o.labeledLink===this)return!0;o=o.containingGroup}const r=n.findVisibleNode();if(r===null||r===t)return!1}return!0}Ei(t){if(super.Ei(t),t&&this.M1(!1),this.jo!==null&&this.jo.Sd(),this.js!==null){const e=this.js.iterator;for(;e.next();)e.value.Ei(t)}}get adjusting(){return this.Pf}set adjusting(t){const i=this.Pf;i!==t&&(this.Pf=t,this.t("adjusting",i,t))}computeAdjusting(){return this.isAvoiding&&this.diagram!==null&&this.diagram.animationManager.defaultAnimation.isAnimating?17:this.Pf}get corner(){return this.Cd}set corner(t){const i=this.Cd;i!==t&&(this.Cd=t,this.ee(),this.t("corner",i,t))}get curve(){return this.Ld}set curve(t){const i=this.Ld;i!==t&&(this.Ld=t,this.invalidateRoute(),this.ee(),this.M1(i===10||i===11||t===10||t===11),this.t("curve",i,t))}get curviness(){return this.Ad}set curviness(t){const i=this.Ad;i!==t&&(this.Ad=t,this.invalidateRoute(),this.ee(),this.t("curviness",i,t))}get routing(){return this.va}set routing(t){const i=this.va;i!==t&&(this.va=t,this.isAvoiding&&this.diagram!==null&&(this.diagram.Vm=!0),this.Ko=null,this.invalidateRoute(),this.M1(Link.mN(i)||Link.mN(t)),this.t("routing",i,t))}get smoothness(){return this.Td}set smoothness(t){const i=this.Td;i!==t&&(this.Td=t,this.ee(),this.t("smoothness",i,t))}xy(){const t=this.so;if(t===null)return;const i=this.oo;if(i===null||!isNaN(this.curviness))return;const e=this.no,s=this.ro;let n=null,o=null;const r=t.ti.r,l=r.length;for(let h=0;h=0&&(t.Hs.splice(i,1),t.Sd())}}Cl(){return!0}get key(){const t=this.diagram;if(!(t===null||!t.model.Ra()))return t.model.getKeyForLinkData(this.data)}}class LinkBundle{Fo;Is;ly;lN;p1;hN;Hs;constructor(t,i,e,s){GSet.Ki(this),this.Fo=!1,this.Is=!1,this.ly=t,this.lN=i,this.p1=e,this.hN=s,this.Hs=[]}Sd(){if(!this.Fo){const t=this.Hs;if(t.length>0){const i=t[0].diagram;i!==null&&(i.wM.add(this),this.Is=i.undoManager.isUndoingRedoing)}}this.Fo=!0}RM(){if(this.Fo){this.Fo=!1;const t=this.Hs;if(t.length>0){const i=t[0],e=i.diagram,s=e===null||e.Vh&&!this.Is;this.Is=!1,i.arrangeBundledLinks(t,s),t.length===1&&(i.jo=null,t.length=0)}t.length===0&&(this.ly.gT(this),this.p1.gT(this))}}}class PositionArray{oe;re;Va;za;di;gi;Vt;Ph;Sh;ua;jM;Fo;ky;Gc;HM;qM;constructor(t){GSet.Ki(this),this.ua=null,this.jM=null,this.Fo=!0,this.ky=!1,this.oe=1,this.re=1,this.Va=-1,this.za=-1,this.di=t.width,this.gi=t.height,this.Vt=[],this.Ph=0,this.Sh=0,this.Gc=11,this.HM=this.Gc*2,this.qM=this.Gc*2}static qs=0;static Xa=1;static Rd=999999;static bN=PositionArray.Rd+1;static kN=PositionArray.Rd+2;Lb(t){if(t.width<=0||t.height<=0)return;const i=t.x,e=t.y,s=t.x+t.width,n=t.y+t.height;this.oe=Math.floor((i-this.di)/this.di)*this.di,this.re=Math.floor((e-this.gi)/this.gi)*this.gi,this.Va=Math.ceil((s+2*this.di)/this.di)*this.di,this.za=Math.ceil((n+2*this.gi)/this.gi)*this.gi;const o=1+(Math.ceil((this.Va-this.oe)/this.di)|0),r=1+(Math.ceil((this.za-this.re)/this.gi)|0);if(this.Vt.length===0||this.Ph0&&t!==this.di&&(this.di=t,this.Lb(this.bounds))}get cellHeight(){return this.gi}set cellHeight(t){t>0&&t!==this.gi&&(this.gi=t,this.Lb(this.bounds))}vd(t,i){return this.oe<=t&&t<=this.Va&&this.re<=i&&i<=this.za}lo(t,i){if(!this.vd(t,i))return PositionArray.bN;t-=this.oe,t/=this.di,i-=this.re,i/=this.gi;const e=t|0,s=i|0;return this.Vt[e][s]}VR(t,i,e,s){if(!this.vd(t,i))return;const n=(t-this.oe)/this.di|0,o=(i-this.re)/this.gi|0,r=(t+e-this.oe)/this.di|0,l=(i+s-this.re)/this.gi|0,h=Math.min(r,this.Ph),c=Math.min(l,this.Sh);for(let a=n;a<=h;a++){const f=this.Vt[a];if(f.fill)f.fill(PositionArray.qs,o,c+1);else for(let u=o;u<=c;u++)f[u]=PositionArray.qs}}TO(t){for(let i=0;i<=this.Ph;i++){const e=this.Vt[i];if(e.fill)e.fill(t);else for(let s=0;s<=this.Sh;s++)e[s]=t}}rA(){for(let t=0;t<=this.Ph;t++){const i=this.Vt[t];for(let e=0;e<=this.Sh;e++)i[e]>=PositionArray.Xa&&(i[e]=PositionArray.bN)}}DO(t,i){return this.lo(t,i)===PositionArray.qs}isUnoccupied(t,i,e,s){if(t>this.Va||t+ethis.za||i+sthis.Va||ithis.za||ethis.za||ithis.Va||e=PositionArray.Xa&&h=c)break;this.Vt[t][i]=h,h+=1,s?i+=e:t+=e}return s?i:t}ho(t,i,e,s,n,o,r,l){if(to||il)return;const h=this.FO(t,i,e,s,n,o,r,l);if(s)if(e>0)for(let c=i+e;ch;c+=e)this.ho(t,c,1,!s,n,o,r,l),this.ho(t,c,-1,!s,n,o,r,l);else if(e>0)for(let c=t+e;ch;c+=e)this.ho(c,i,1,!s,n,o,r,l),this.ho(c,i,-1,!s,n,o,r,l)}T1(t,i,e,s,n,o,r,l,h,c){let a=t|0,f=i|0,u=PositionArray.qs,d=PositionArray.Xa;for(this.Vt[a][f]=d;u===PositionArray.qs&&a>r&&ah&&fr&&ah&&f=0;R-=2){F=A[R+2],v=A[R+3];const O=A[R],X=A[R+1];for(;O>F?F++:Ov?v++:Xs)d--;else break;else if(m>n)m--;else break;const g=a[d][m];if(g===0||g===PositionArray.kN)break;f=d,u=m}for(;;){let d=e,m=f,g=u;e===0?gn&&(d=270,g--):e===90?ms&&(d=180,m--):e===180?gn&&(d=270,g--):ms&&(d=180,m--);const p=a[m][g];if(d!==e&&p!==0&&p!==PositionArray.kN){if(o.push(f),o.push(u),this.CT(f,u,d,s,n,o))return!0;o.pop(),o.pop()}if(a[f][u]=PositionArray.kN,e===0){if(f===t)return!1;f--}else if(e===90){if(u===i)return!1;u--}else if(e===180){if(f===t)return!1;f++}else{if(u===i)return!1;u++}}}}class Knot{Me;al;os;Od;constructor(t,i){GSet.Ki(this),this.Me=t,this.al=i,this.os=[],this.Od=!1}toString(){const t=this.os;let i=this.Me.toString()+" "+t.length.toString()+":";for(let e=0;e180?270:90;case 6:return o>90&&o<=270?180:0}const r=Math.atan2(t.height,t.width)*180/Math.PI;switch(n){case 3:return o>r&&o<=180+r?180:270;case 5:return o>180-r&&o<=360-r?270:0;case 12:return o>r&&o<=180+r?90:0;case 10:return o>180-r&&o<=360-r?180:90;case 7:return o>90&&o<=180+r?180:o>180+r&&o<=360-r?270:0;case 13:return o>180&&o<=360-r?270:o>r&&o<=180?90:0;case 14:return o>r&&o<=180-r?90:o>180-r&&o<=270?180:0;case 11:return o>180-r&&o<=180+r?180:o>180+r?270:90}return s&&n!==15&&(o-=15,o<0&&(o+=360)),o>r&&o<180-r?90:o>=180-r&&o<=180+r?180:o>180+r&&o<360-r?270:0}Sd(){this.os.length=0}ST(t){let i=this.os;i.length===0&&(this.vO(),i=this.os);for(let e=0;e=360&&(S-=360);const L=this.RO(h,w,S,g.isOrthogonal);let C=0;L===0?(C=4,S>180&&(S-=360)):L===90?(C=8,S>270&&(S-=360)):L===180?C=2:(C=1,S<90&&(S+=360));let M=this.os[o];M===void 0?(M=new LinkInfo(g,S,C),this.os[o]=M):(M.Ke=g,M.Yt=S,M.me=C),M.F1.set(P),o++}Point.e(c),this.OO();const u=this.os.length;let d=-1,m=0;for(o=0;o=0;o--){const g=this.os[o];g!==void 0&&(g.me!==d&&(d=g.me,m=g.Id+1),g.Mf=m)}this.IO(this.os),this.EO(this.os),this.Od=t,Rect.e(h)}return this.os}UO(t,i){return t===i?0:t===null?-1:i===null?1:t.mei.me?1:t.Yti.Yt?1:0}OO(){this.os.sort(Knot.prototype.UO)}IO(t){const i=this.al,e=this.Me.portSpreading,s=Point.l(),n=Point.l(),o=Point.l(),r=Point.l();i.getDocumentPoint(Spot.TopLeft,s),i.getDocumentPoint(Spot.TopRight,n),i.getDocumentPoint(Spot.BottomRight,o),i.getDocumentPoint(Spot.BottomLeft,r);let l=0,h=0,c=0,a=0;if(e===2)for(let x=0;xMath.abs(p)?(d=Math.abs(p)/c,c=Math.abs(p)):d=1;break;case 2:a>Math.abs(w)?(d=Math.abs(w)/a,a=Math.abs(w)):d=1;break;case 1:l>Math.abs(p)?(d=Math.abs(p)/l,l=Math.abs(p)):d=1;break;default:case 4:h>Math.abs(w)?(d=Math.abs(w)/h,h=Math.abs(w)):d=1;break}u=0}const b=k.Fd;if(e===2){let P=k.Ke.computeThickness();switch(P*=d,b.set(m),f){case 8:b.x=m.x+p/2+c/2-u-P/2;break;case 2:b.y=m.y+w/2+a/2-u-P/2;break;case 1:b.x=m.x+p/2-l/2+u+P/2;break;default:case 4:b.y=m.y+w/2-h/2+u+P/2;break}u+=P}else{let P=.5;e===1&&(P=(k.Id+1)/(k.Mf+1)),b.x=m.x+p*P,b.y=m.y+w*P}}Point.e(s),Point.e(n),Point.e(o),Point.e(r)}EO(t){for(let i=0;ie instanceof Placeholder);i instanceof Placeholder?t.Ft=i:t.Ft=null,this.ie!==null?(t.ie=this.ie.copy(),t.ie.group=t):(t.ie!==null&&(t.ie.group=null),t.ie=null),this.si!==null&&(t.si=this.si.copy())}vo(t){super.vo(t);const i=t.findSubGraphParts(),e=t.memberParts;for(;e.next();){const s=e.value;if(s.c(),s.invalidateLayout(8),s.clearAdornments(),s instanceof Node)s.invalidateConnectedLinks(i);else if(s instanceof Link){const n=s.labelNodes;for(;n.next();)n.value.invalidateConnectedLinks(i)}}}qc(t,i,e,s,n,o,r){if(t===3&&i==="elements"){if(n instanceof Placeholder)this.Ft===null?this.Ft=n:this.Ft!==n&&U.o("Cannot insert a second Placeholder into the visual tree of a Group.");else if(n instanceof Panel){const l=n.findInVisualTree(h=>h instanceof Placeholder);l instanceof Placeholder&&(this.Ft===null?this.Ft=l:this.Ft!==l&&U.o("Cannot insert a second Placeholder into the visual tree of a Group."))}}else t===4&&i==="elements"&&this.Ft!==null&&(s===this.Ft?this.Ft=null:s instanceof Panel&&this.Ft.isContainedBy(s)&&(this.Ft=null));super.qc(t,i,e,s,n,o,r)}Ju(t,i){if(super.Ju(t,i),this.isClipping&&this.type!==Panel.Spot&&this.isSubGraphExpanded){let e=this.resizeObject;e instanceof Panel&&(e=e.findMainElement()),this.si===null&&(this.si=new Rect),e.getDocumentBounds(this.si),e instanceof Shape&&this.si.inflate(-e.strokeWidth,-e.strokeWidth)}}uh(t,i,e,s){this.hasPlaceholder()&&(this.Go=this.placeholder),super.uh(t,i,e,s)}ensureBounds(){this.isSubGraphExpanded&&this.memberParts.each(i=>{i.ensureBounds()}),super.ensureBounds()}Yr(){if(!super.Yr())return!1;const t=this.memberParts;for(;t.next();){const i=t.value;if(i instanceof Node){if(!i.isVisible())continue;if(i._e())return!1}else if(i instanceof Link){if(!i.isVisible())continue;if(i._e()&&i.fromNode!==this&&i.toNode!==this)return!1}}return!0}hasPlaceholder(){return this.Ft!==null&&this.Ft.isVisibleObject()&&this.isSubGraphExpanded}get placeholder(){return this.Ft}get computesBoundsAfterDrag(){return(this.v&2048)!==0}set computesBoundsAfterDrag(t){const i=(this.v&2048)!==0;i!==t&&(this.v=this.v^2048,this.t("computesBoundsAfterDrag",i,t))}get computesBoundsIncludingLinks(){return(this.v&4096)!==0}set computesBoundsIncludingLinks(t){const i=(this.v&4096)!==0;i!==t&&(this.v=this.v^4096,this.t("computesBoundsIncludingLinks",i,t))}get computesBoundsIncludingLocation(){return(this.v&8192)!==0}set computesBoundsIncludingLocation(t){const i=(this.v&8192)!==0;i!==t&&(this.v=this.v^8192,this.t("computesBoundsIncludingLocation",i,t))}get handlesDragDropForMembers(){return(this.v&16384)!==0}set handlesDragDropForMembers(t){const i=(this.v&16384)!==0;i!==t&&(this.v=this.v^16384,this.t("handlesDragDropForMembers",i,t))}get avoidableMembers(){return(this.v&131072)!==0}set avoidableMembers(t){const i=(this.v&131072)!==0;i!==t&&(this.v=this.v^131072,this.t("avoidableMembers",i,t))}get memberParts(){return this.Ed.iterator}sN(t){if(this.Ed.add(t)){t instanceof Group&&this.ca.add(t);const e=this.memberAdded;if(e!==null){let s=!0;const n=this.diagram;n!==null&&(s=n.X,n.X=!0),e(this,t),n!==null&&(n.X=s)}(!this.isVisible()||!this.isSubGraphExpanded)&&t.Ei(!1)}if(t instanceof Link&&!this.computesBoundsIncludingLinks)return;let i=this.Ft;i===null&&(i=this),i.c()}eN(t){if(this.Ed.delete(t)){t instanceof Group&&this.ca.delete(t);const e=this.memberRemoved;if(e!==null){let s=!0;const n=this.diagram;n!==null&&(s=n.X,n.X=!0),e(this,t),n!==null&&(n.X=s)}(!this.isVisible()||!this.isSubGraphExpanded)&&t.Ei(!0)}if(t instanceof Link&&!this.computesBoundsIncludingLinks)return;let i=this.Ft;i===null&&(i=this),i.c()}Xc(){if(this.Ed.count>0){const t=this.diagram;if(t!==null){const e=this.Ed.copy().iterator;for(;e.next();){const s=e.value;t.remove(s)}}}super.Xc()}get layout(){return this.ie}set layout(t){const i=this.ie;if(i!==t){t!==null&&t.diagram!==null&&t.diagram.layout===t&&U.o("A layout cannot be both the Diagram.layout and a Group.layout: "+t),i!==null&&(i.diagram=null,i.group=null),this.ie=t;const e=this.diagram;t!==null&&(t.diagram=e,t.group=this),e!==null&&(e.Vr=!0),this.t("layout",i,t),e!==null&&e.requestUpdate()}}get memberAdded(){return this.Rt!==null?this.Rt.gy:null}set memberAdded(t){const i=this.memberAdded;i!==t&&(t!==null&&U.k(t,Group,"memberAdded"),this.ll().gy=t,this.t("memberAdded",i,t))}get memberRemoved(){return this.Rt!==null?this.Rt.my:null}set memberRemoved(t){const i=this.memberRemoved;i!==t&&(t!==null&&U.k(t,Group,"memberRemoved"),this.ll().my=t,this.t("memberRemoved",i,t))}get memberValidation(){return this.Rt!==null?this.Rt.nh:null}set memberValidation(t){const i=this.memberValidation;i!==t&&(t!==null&&U.k(t,Group,"memberValidation"),this.ll().nh=t,this.t("memberValidation",i,t))}canAddMembers(t){const i=this.diagram;if(i===null)return!1;const e=i.commandHandler,n=e.m2(t).iterator;for(;n.next();){const o=n.value;if(!e.isValidMember(this,o))return!1}return!0}addMembers(t,i){const e=this.diagram;if(e===null)return!1;const s=e.commandHandler,n=s.m2(t);let o=!0;const r=n.iterator;for(;r.next();){const l=r.value;!i||s.isValidMember(this,l)?l.containingGroup=this:o=!1}return o}get ungroupable(){return(this.v&256)!==0}set ungroupable(t){const i=(this.v&256)!==0;i!==t&&(this.v=this.v^256,this.t("ungroupable",i,t))}canUngroup(){if(!this.ungroupable)return!1;const t=this.layer;if(t===null||!t.allowUngroup)return!1;const i=t.diagram;return!(i!==null&&!i.allowUngroup)}invalidateConnectedLinks(t){const i=this.VO();if(super.invalidateConnectedLinks(t),i)return;this.XL(!0);const e=this.findExternalLinksConnected();for(;e.next();){const s=e.value;if(t!==void 0&&t.has(s))continue;const n=s.fromNode;if(n!==null&&n!==this&&n.isMemberOf(this)&&!n.isVisible())n.qi(s.fromPort),n.qi(s.toPort),s.invalidateRoute();else{const o=s.toNode;o!==null&&o!==this&&o.isMemberOf(this)&&!o.isVisible()&&(o.qi(s.fromPort),o.qi(s.toPort),s.invalidateRoute())}}}findExternalLinksConnected(){const t=this.diagram!==null&&this.diagram.MM;if(t&&this.h0!==null)return this.h0.iterator;const i=this.findSubGraphParts();i.add(this);const e=new GSet,s=i.iterator;for(;s.next();){const n=s.value;if(!(n instanceof Node))continue;const o=n.linksConnected;for(;o.next();){const r=o.value;i.has(r)||e.add(r)}}return t&&(this.h0=e),e.iterator}findExternalNodesConnected(){const t=this.findSubGraphParts();t.add(this);const i=new GSet,e=t.iterator;for(;e.next();){const s=e.value;if(!(s instanceof Node))continue;const n=s.linksConnected;for(;n.next();){const o=n.value,r=o.fromNode;r!==null&&(!t.has(r)||r===this)&&i.add(r);const l=o.toNode;l!==null&&(!t.has(l)||l===this)&&i.add(l)}}return i.iterator}vE(){function t(e,s){e!==null&&(s.add(e),t(e.containingGroup,s))}const i=new GSet;return t(this,i),i}findSubGraphParts(){const t=new GSet;return Part.oh(t,this,!0,0,!0),t.delete(this),t}Ei(t){super.Ei(t);const i=this.memberParts;for(;i.next();)i.value.Ei(t)}collapseSubGraph(){const t=this.diagram;if(t===null||t.isCollapsingExpanding)return;t.isCollapsingExpanding=!0;const i=this.findSubGraphParts();this.LT(i,t,this),t.isCollapsingExpanding=!1}LT(t,i,e){const s=this.memberParts;for(;s.next();){const n=s.value;if(n.Ei(!1),n instanceof Group&&n.isSubGraphExpanded&&(n.wasSubGraphExpanded=n.isSubGraphExpanded,n.LT(t,i,e)),n instanceof Node)n.invalidateConnectedLinks(t),i.Lc(n,e);else if(n instanceof Link){const o=n.labelNodes;for(;o.next();)o.value.invalidateConnectedLinks(t)}}this.isSubGraphExpanded=!1}expandSubGraph(){const t=this.diagram;if(t===null||t.isCollapsingExpanding)return;t.isCollapsingExpanding=!0;const i=this.findSubGraphParts();this.AT(i,t,this),t.isCollapsingExpanding=!1}AT(t,i,e){const s=this.memberParts;for(;s.next();){const n=s.value;if(n.Ei(!0),n instanceof Group&&n.wasSubGraphExpanded&&(n.wasSubGraphExpanded=!1,n.AT(t,i,e)),n instanceof Node)n.invalidateConnectedLinks(t);else if(n instanceof Link){const o=n.labelNodes;for(;o.next();)o.value.invalidateConnectedLinks(t)}}this.isSubGraphExpanded=!0}get isSubGraphExpanded(){return(this.v&512)!==0}set isSubGraphExpanded(t){const i=(this.v&512)!==0;if(i!==t){this.v=this.v^512;const e=this.diagram;this.t("isSubGraphExpanded",i,t);const s=this.subGraphExpandedChanged;if(s!==null){let n=!0;e!==null&&(n=e.X,e.X=!0),s(this),e!==null&&(e.X=n)}if(e!==null&&e.undoManager.isUndoingRedoing){this.Ft!==null&&this.Ft.c(),this.memberParts.each(n=>n.updateAdornments());return}t?this.expandSubGraph():this.collapseSubGraph()}}get wasSubGraphExpanded(){return(this.v&1024)!==0}set wasSubGraphExpanded(t){const i=(this.v&1024)!==0;i!==t&&(this.v=this.v^1024,this.t("wasSubGraphExpanded",i,t))}get subGraphExpandedChanged(){return this.Rt!==null?this.Rt.yy:null}set subGraphExpandedChanged(t){const i=this.subGraphExpandedChanged;i!==t&&(t!==null&&U.k(t,Group,"subGraphExpandedChanged"),this.ll().yy=t,this.t("subGraphExpandedChanged",i,t))}move(t,i){i===void 0&&(i=!1);const e=i?this.location:this.position,s=e.x,n=e.y,o=t.x,r=t.y;if((s===o||isNaN(s)&&isNaN(o))&&(n===r||isNaN(n)&&isNaN(r)))return;const l=o-(isNaN(s)?0:s),h=r-(isNaN(n)?0:n),c=Point.l();super.move(t,i);const a=new GSet,u=this.findSubGraphParts().iterator;for(;u.next();){const d=u.value;d instanceof Link&&(d.suspendsRouting&&a.add(d),!(!d.Se&&(d.fromNode===this||d.toNode===this))&&(d.suspendsRouting=!0))}for(u.reset();u.next();){const d=u.value;if(d.Cl()||d instanceof Node&&d.isLinkLabel)continue;const m=d.position,g=d.location;m.isReal()?(c.x=m.x+l,c.y=m.y+h,d.position=c):g.isReal()&&(c.x=g.x+l,c.y=g.y+h,d.location=c)}for(u.reset();u.next();){const d=u.value;if(!(d instanceof Link)||(d.suspendsRouting=a.has(d),!d.Se&&(d.fromNode===this||d.toNode===this)))continue;const m=d.position;c.x=m.x+l,c.y=m.y+h,c.isReal()?d.move(c):d.invalidateRoute()}Point.e(c)}VO(){return(this.v&65536)!==0}XL(t){(this.v&65536)!==0!==t&&(this.v=this.v^65536)}get fa(){return(this.v&32768)!==0}set fa(t){(this.v&32768)!==0!==t&&(this.v=this.v^32768)}}class Placeholder extends GraphObject{Zt;Ud;constructor(t){super(),this.Zt=Margin.Rg,this.Ud=new Rect(NaN,NaN,NaN,NaN),t&&Object.assign(this,t)}cloneProtected(t){super.cloneProtected(t),t.Zt=this.Zt.P(),t.Ud=this.Ud.copy()}fh(t){if(this.background===null)return!1;const i=this.naturalBounds;return Rect.contains(0,0,i.width,i.height,t.x,t.y)}Wu(t,i,e,s){const n=this.part;if((n===null||!(n instanceof Group)&&!(n instanceof Adornment))&&U.o("Placeholder is not inside a Group or Adornment."),n instanceof Group){const o=this.computeBorder(this.Ud),r=this.minSize,l=isFinite(r.width)?Math.max(r.width,o.width):o.width,h=isFinite(r.height)?Math.max(r.height,o.height):o.height,c=this.zi;c.Fn(l||0,h||0),this.Wn(0,0,c.width,c.height);const a=n.memberParts;let f=!1;for(;a.next();)if(a.value.isVisible()){f=!0;break}const u=n.diagram;if(f&&u!==null&&!u.animationManager.US(n)&&!isNaN(o.x)&&!isNaN(o.y)){const d=Point.l();d.setRectSpot(o,n.locationSpot),n.location=d,Point.e(d)}}else{const o=n,r=this.zi,l=this.Zt,h=l.left+l.right,c=l.top+l.bottom,a=o.adornedObject,f=a.getDocumentAngle();o.angle=f;let u=0;a instanceof Shape&&(u=a.strokeWidth);const d=a.getDocumentScale(),m=a.naturalBounds,g=(m.width+u)*d,p=(m.height+u)*d;if(o.type!==Panel.Link){const w=o.category==="Selection"?Spot.TopLeft:o.locationSpot,x=a.getDocumentPoint(w,Point.l());o.location=x,Point.e(x)}if(!isNaN(g)&&!isNaN(p))r.Fn(g+h||0,p+c||0),this.Wn(-l.left,-l.top,r.width,r.height);else{const w=a.getDocumentPoint(Spot.TopLeft,Point.l()),x=Rect.V(w.x,w.y,0,0);x.unionPoint(a.getDocumentPoint(Spot.BottomRight,w)),x.unionPoint(a.getDocumentPoint(Spot.TopRight,w)),x.unionPoint(a.getDocumentPoint(Spot.BottomLeft,w)),r.Fn(x.width+h||0,x.height+c||0),this.Wn(-l.left,-l.top,r.width,r.height),Point.e(w),Rect.e(x)}}}uh(t,i,e,s){this.actualBounds.i(t,i,e,s)}computeBorder(t){const i=this.part,e=i.diagram,s=e===null||!e.animationManager.isAnimating;if(e!==null&&i instanceof Group&&!i.layer.isTemporary&&i.computesBoundsAfterDrag&&this.Ud.isReal()){const l=e.toolManager.findTool("Dragging");if(l===e.currentTool){const h=l.computeBorder(i,this.Ud,t);if(h!==null)return h}}const n=Rect.l(),o=this.computeMemberBounds(n),r=this.Zt;return i instanceof Group&&!i.isSubGraphExpanded?t.i(o.x-r.left,o.y-r.top,0,0):t.i(o.x-r.left,o.y-r.top,Math.max(o.width+r.left+r.right,0),Math.max(o.height+r.top+r.bottom,0)),Rect.e(n),s&&i instanceof Group&&i.computesBoundsIncludingLocation&&i.location.isReal()&&t.unionPoint(i.location),t}computeMemberBounds(t){if(!(this.part instanceof Group))return t.i(0,0,0,0),t;const i=this.part;let e=1/0,s=1/0,n=-1/0,o=-1/0;const r=i.memberParts;for(;r.next();){const l=r.value;if(!l.isVisible()||l instanceof Link&&(!i.computesBoundsIncludingLinks||l.To()||l.fromNode===i||l.toNode===i))continue;const h=l.actualBounds;h.leftn&&(n=h.right),h.bottom>o&&(o=h.bottom)}if(!isFinite(e)||!isFinite(s)){const l=i.location;t.i(l.x,l.y,0,0)}else t.i(e,s,n-e,o-s);return t}get padding(){return this.Zt}set padding(t){typeof t=="number"&&(t=new Margin(t));const i=this.Zt;i.equals(t)||(t=t.P(),this.Zt=t,this.t("padding",i,t),this.c())}}class Layout{N;ua;Bd;wr;Vd;zd;Co;cl;Xd;Yd;ao;constructor(t){GSet.Ki(this),this.N=null,this.ua=null,this.Bd=!0,this.wr=!0,this.Vd=!1,this.zd=new Point(0,0).u(),this.Co=!0,this.cl=null,this.Xd=null,this.Yd=!1,this.ao=null,t&&Object.assign(this,t)}cloneProtected(t){t.Bd=this.Bd,t.wr=this.wr,t.Vd=this.Vd,t.zd.a(this.zd),t.Co=this.Co,t.cl=this.cl,t.Xd=this.Xd,t.Yd=!0}copy(){const t=new this.constructor;return this.cloneProtected(t),t}oi(t){U.er(this,t)}toString(){let t=U.Dn(this.constructor);return t+="(",this.group!==null&&(t+=" in "+this.group),this.diagram!==null&&(t+=" for "+this.diagram),t+=")",t}get diagram(){return this.N}set diagram(t){this.N=t}get group(){return this.ua}set group(t){this.ua!==t&&(this.ua=t,t!==null&&(this.N=t.diagram))}get isOngoing(){return this.Bd}set isOngoing(t){this.Bd!==t&&(U.s(t,"boolean",Layout,"isOngoing"),this.Bd=t)}get isInitial(){return this.wr}set isInitial(t){U.s(t,"boolean",Layout,"isInitial"),this.wr=t,t||(this.Yd=!0)}get isViewportSized(){return this.Vd}set isViewportSized(t){this.Vd!==t&&(U.s(t,"boolean",Layout,"isViewportSized"),this.Vd=t,t&&this.invalidateLayout())}get isRouting(){return this.Co}set isRouting(t){this.Co!==t&&(U.s(t,"boolean",Layout,"isRouting"),this.Co=t)}get isRealtime(){return this.cl}set isRealtime(t){this.cl!==t&&(t!==null&&U.s(t,"boolean",Layout,"isRealtime"),this.cl=t)}get isValidLayout(){return this.Yd}set isValidLayout(t){if(this.Yd!==t&&(U.s(t,"boolean",Layout,"isValidLayout"),this.Yd=t,!t)){const i=this.diagram;i!==null&&(i.Vr=!0)}}invalidateLayout(){if(this.isValidLayout){const t=this.diagram;if(t===null||t.undoManager.isUndoingRedoing)return;const i=t.animationManager;if(i.isTicking)return;i.defaultAnimation.isAnimating&&i.stopAnimation(),(this.isOngoing&&t.Vh||this.isInitial&&!t.Vh)&&(this.isValidLayout=!1,t.requestUpdate())}}get network(){return this.ao}set network(t){this.ao!==t&&(this.ao=t,t!==null&&(t.layout=this))}createNetwork(){return new LayoutNetwork(this)}makeNetwork(t){const i=this.createNetwork();return t instanceof Diagram?(i.addParts(t.nodes,!0),i.addParts(t.links,!0)):t instanceof Group?i.addParts(t.memberParts):i.addParts(t.iterator),i}updateParts(){this.isValidLayout=!0;let t=this.diagram;if(t===null&&this.network!==null){const i=this.network.vertexes.iterator;for(;i.next();){const s=i.value.node;if(s!==null&&(t=s.diagram,t!==null))break}}try{t!==null&&t.startTransaction("Layout"),this.commitLayout()}finally{t!==null&&t.commitTransaction("Layout")}}commitLayout(){if(this.network===null)return;const t=this.network.vertexes.iterator;for(;t.next();)t.value.commit();if(this.isRouting){const i=this.network.edges.iterator;for(;i.next();)i.value.commit()}}doLayout(t){const i=new GSet;if(t instanceof Diagram?(this.Mh(i,t.nodes,!0,this.fa,!0,!1,!0),this.Mh(i,t.parts,!0,this.fa,!0,!1,!0)):t instanceof Group?this.Mh(i,t.memberParts,!1,this.fa,!0,!1,!0):i.addAll(t.iterator),i.count>0){const s=this.diagram;s!==null&&s.startTransaction("Layout"),this.doMinimalNoNetworkLayout(i),s!==null&&s.commitTransaction("Layout")}this.isValidLayout=!0}doMinimalNoNetworkLayout(t){const i=t.count,e=Math.ceil(Math.sqrt(i));this.arrangementOrigin=this.initialOrigin(this.arrangementOrigin);const s=this.arrangementOrigin.x,n=this.arrangementOrigin.y;let o=s,r=n,l=0,h=0;const c=t.iterator;for(;c.next();){const a=c.value;a.ensureBounds();const f=a.measuredBounds,u=f.width,d=f.height;a.moveTo(o,r),a instanceof Group&&(a.fa=!1),o+=Math.max(u,50)+20,h=Math.max(h,Math.max(d,50)),l>=e-1?(l=0,o=s,r+=h+20,h=0):l++}}fa(t){return!!(!t.location.isReal()&&!t.position.isReal()||t instanceof Group&&t.fa)}Mh(t,i,e,s,n,o,r){const l=i.iterator;for(;l.next();){const h=l.value;if(!(e&&!h.isTopLevel)&&!(s!==null&&!s(h))&&h.canLayout())if(n&&h instanceof Node){if(h.isLinkLabel)continue;h instanceof Group&&h.layout===null?this.Mh(t,h.memberParts,!1,s,n,o,r):(h.ensureBounds(),t.add(h))}else o&&h instanceof Link?t.add(h):r&&h.ke()&&!(h instanceof Node)&&(h.ensureBounds(),t.add(h))}}getLayoutBounds(t,i){const e=this.boundsComputation;return e!==null?(i||(i=new Rect),e(t,this,i)):!i&&t.margin.equalTo(0,0,0,0)?t.actualBounds:(i||(i=new Rect),i.set(t.actualBounds),i.addMargin(t.margin),i)}get boundsComputation(){return this.Xd}set boundsComputation(t){this.Xd!==t&&(t!==null&&U.k(t,Layout,"boundsComputation"),this.Xd=t,this.invalidateLayout())}collectParts(t){const i=new GSet;return t instanceof Diagram?(this.Mh(i,t.nodes,!0,null,!0,!0,!0),this.Mh(i,t.links,!0,null,!0,!0,!0),this.Mh(i,t.parts,!0,null,!0,!0,!0)):t instanceof Group?this.Mh(i,t.memberParts,!1,null,!0,!0,!0):this.Mh(i,t.iterator,!1,null,!0,!0,!0),i}get arrangementOrigin(){return this.zd}set arrangementOrigin(t){this.zd.equals(t)||(this.zd.a(t),this.invalidateLayout())}initialOrigin(t){const i=this.group;if(i!==null)if(i.hasPlaceholder()){const e=i.placeholder,s=e.getDocumentPoint(Spot.TopLeft);(isNaN(s.x)||isNaN(s.y))&&s.set(t);const n=e.padding;return s.x+=n.left,s.y+=n.top,s}else{const e=i.position.copy();return(isNaN(e.x)||isNaN(e.y))&&e.set(t),e}return t}}class LayoutNetwork{ie;co;bn;Py;Sy;constructor(t){GSet.Ki(this),this.ie=t,this.co=new GSet,this.bn=new GSet,this.Py=new GMap,this.Sy=new GMap}clear(){if(this.co){const t=this.co.iterator;for(;t.next();)t.value.clear()}if(this.bn){const t=this.bn.iterator;for(;t.next();)t.value.clear()}this.co=new GSet,this.bn=new GSet,this.Py=new GMap,this.Sy=new GMap}toString(t){t===void 0&&(t=0);let i="LayoutNetwork"+(this.layout!==null?"("+this.layout.toString()+")":"");if(t<=0)return i;if(i+=" vertexes: "+this.co.count+" edges: "+this.bn.count,t>1){const e=this.co.iterator;for(;e.next();){const n=e.value;i+=` `+n.toString(t-1)}const s=this.bn.iterator;for(;s.next();){const n=s.value;i+=` `+n.toString(t-1)}}return i}get layout(){return this.ie}set layout(t){t!==null&&(this.ie=t)}get vertexes(){return this.co}get edges(){return this.bn}createVertex(){return new LayoutVertex(this)}createEdge(){return new LayoutEdge(this)}addParts(t,i,e){if(t===null)return;i===void 0&&(i=!1),U.s(i,"boolean",LayoutNetwork,"addParts:toplevelonly"),e===void 0&&(e=null),e===null&&(e=n=>{if(n instanceof Node)return!n.isLinkLabel;if(n instanceof Link){const o=n.fromNode;if(o===null||o.isLinkLabel)return!1;const r=n.toNode;return!(r===null||r.isLinkLabel)}return!1});const s=t.iterator;for(;s.next();){const n=s.value;if(n instanceof Node&&!(i&&!n.isTopLevel)&&n.canLayout()&&e(n))if(n instanceof Group&&n.layout===null)this.addParts(n.memberParts,!1);else{if(this.findVertex(n)!==null)continue;const o=this.createVertex();o.node=n,this.addVertex(o)}}for(s.reset();s.next();){const n=s.value;if(!(n instanceof Link)||i&&!n.isTopLevel||!n.canLayout()||!e(n)||this.findEdge(n)!==null)continue;const o=n.fromNode,r=n.toNode;if(o===null||r===null||o===r)continue;const l=this.findGroupVertex(o),h=this.findGroupVertex(r);this.linkVertexes(l,h,n)}}findGroupVertex(t){const i=t.findVisibleNode();if(i===null)return null;let e=this.findVertex(i);if(e!==null)return e;let s=i.containingGroup;for(;s!==null;){if(e=this.findVertex(s),e!==null)return e;s=s.containingGroup}return null}addVertex(t){this.co.add(t);const i=t.node;i!==null&&this.Py.set(i,t),t.network=this}addNode(t){let i=this.findVertex(t);return i===null&&(i=this.createVertex(),i.node=t,this.addVertex(i)),i}deleteVertex(t){if(this.TT(t)){let i=t.Ho;for(let e=i.count-1;e>=0;e--){const s=i.elt(e);this.deleteEdge(s)}i=t.qo;for(let e=i.count-1;e>=0;e--){const s=i.elt(e);this.deleteEdge(s)}}}TT(t){const i=this.co.delete(t);if(i){const e=t.node;e!==null&&this.Py.delete(e)}return i}deleteNode(t){const i=this.findVertex(t);i!==null&&this.deleteVertex(i)}findVertex(t){return this.Py.get(t)}addEdge(t){this.PN(t);const i=t.toVertex;i!==null&&i.addSourceEdge(t);const e=t.fromVertex;e!==null&&e.addDestinationEdge(t)}PN(t){this.bn.add(t);const i=t.link;i!==null&&this.findEdge(i)===null&&this.Sy.set(i,t),t.network=this}addLink(t){const i=t.fromNode,e=t.toNode;let s=this.findEdge(t);return s===null?(s=this.createEdge(),s.link=t,i!==null&&(s.fromVertex=this.addNode(i)),e!==null&&(s.toVertex=this.addNode(e)),this.addEdge(s)):(i!==null?s.fromVertex=this.addNode(i):s.fromVertex=null,e!==null?s.toVertex=this.addNode(e):s.toVertex=null),s}deleteEdge(t){const i=t.toVertex;i!==null&&i.deleteSourceEdge(t);const e=t.fromVertex;e!==null&&e.deleteDestinationEdge(t),this.SN(t)}SN(t){const i=this.bn.delete(t);if(i){const e=t.link;e!==null&&this.Sy.delete(e)}return i}deleteLink(t){const i=this.findEdge(t);i!==null&&this.deleteEdge(i)}findEdge(t){return this.Sy.get(t)}linkVertexes(t,i,e){if(t===null||i===null)return null;if(t.network===this&&i.network===this){const s=this.createEdge();return s.link=e,s.fromVertex=t,s.toVertex=i,this.addEdge(s),s}return null}reverseEdge(t){const i=t.fromVertex,e=t.toVertex;i===null||e===null||(i.deleteDestinationEdge(t),e.deleteSourceEdge(t),t.reverseEdge(),i.addSourceEdge(t),e.addDestinationEdge(t))}deleteSelfEdges(){const t=U.et(),i=this.bn.iterator;for(;i.next();){const s=i.value;s.fromVertex===s.toVertex&&t.push(s)}const e=t.length;for(let s=0;s0||t.qo.count>0)}splitIntoSubNetworks(t){t===void 0&&(t=!0),t&&(this.deleteArtificialVertexes(),this.deleteUselessEdges(),this.deleteSelfEdges());const i=new List;let e=!0;for(;e;){e=!1;const s=this.co.iterator;for(;s.next();){const n=s.value;if(this.isSingleton(n))continue;const o=this.layout.createNetwork();i.add(o),this.zO(o,n),e=!0;break}}return i.sort((s,n)=>s===null||n===null||s===n?0:n.vertexes.count-s.vertexes.count),i}zO(t,i){if(i===null)return;const e=new List;for(e.add(i);e.count>0;){const s=e.first();if(e.removeAt(0),!s||s.network===t)continue;this.TT(s),t.addVertex(s);let n=s.sourceEdges;for(;n.next();){const o=n.value;o.network!==t&&(this.SN(o),t.PN(o),o.fromVertex&&e.add(o.fromVertex))}for(n=s.destinationEdges;n.next();){const o=n.value;o.network!==t&&(this.SN(o),t.PN(o),o.toVertex&&e.add(o.toVertex))}}}findAllParts(){const t=new GSet,i=this.co.iterator;for(;i.next();){const s=i.value;s.node&&t.add(s.node)}const e=this.bn.iterator;for(;e.next();){const s=e.value;s.link&&t.add(s.link)}return t}}class LayoutVertex{ao;_t;Me;Le;je;Ho;qo;constructor(t){GSet.Ki(this),this.ao=t,this.Le=new Rect(0,0,10,10).u(),this.je=new Point(5,5).u(),this._t=null,this.Me=null,this.Ho=new List,this.qo=new List}clear(){this._t=null,this.Me=null,this.Ho=new List,this.qo=new List}toString(t){t===void 0&&(t=0);let i="LayoutVertex#"+GSet.as(this);if(t>0&&(i+=this.node!==null?"("+this.node.toString()+")":"",t>1)){let e="",s=!0,n=this.Ho.iterator;for(;n.next();){const r=n.value;s?s=!1:e+=",",e+=r.toString(0)}let o="";for(s=!0,n=this.qo.iterator;n.next();){const r=n.value;s?s=!1:o+=",",o+=r.toString(0)}i+=" sources: "+e+" destinations: "+o}return i}get fo(){return this.Ho.uC}get Wo(){return this.qo.uC}get data(){return this._t}set data(t){if(this._t=t,t!==null&&t.bounds){const i=t.bounds,e=i.x,s=i.y,n=i.width,o=i.height;this.je.i(n/2,o/2),this.Le.i(e,s,n,o)}}get node(){return this.Me}set node(t){if(this.Me!==t){if(this.Me=t,t===null)return;t.ensureBounds();const i=this.network.layout,e=Rect.l(),s=i.getLayoutBounds(t,e);let n=s.x,o=s.y;const r=s.width,l=s.height;if(isNaN(n)&&(n=0),isNaN(o)&&(o=0),this.Le.i(n,o,r,l),Rect.e(e),!(t instanceof Group)){const h=t.locationObject.getDocumentPoint(Spot.Center);if(h.isReal()){this.je.i(h.x-n,h.y-o);return}}this.je.i(r/2,l/2)}}get bounds(){return this.Le}set bounds(t){this.Le.equals(t)||this.Le.a(t)}get focus(){return this.je}set focus(t){this.je.equals(t)||this.je.a(t)}get centerX(){return this.Le.x+this.je.x}set centerX(t){const i=this.Le;i.x+this.je.x!==t&&(i.Pt(),i.x=t-this.je.x,i.u())}get centerY(){return this.Le.y+this.je.y}set centerY(t){const i=this.Le;i.y+this.je.y!==t&&(i.Pt(),i.y=t-this.je.y,i.u())}get focusX(){return this.je.x}set focusX(t){const i=this.je;i.x!==t&&(i.Pt(),i.x=t,i.u())}get focusY(){return this.je.y}set focusY(t){const i=this.je;i.y!==t&&(i.Pt(),i.y=t,i.u())}get x(){return this.Le.x}set x(t){const i=this.Le;i.x!==t&&(i.Pt(),i.x=t,i.u())}get y(){return this.Le.y}set y(t){const i=this.Le;i.y!==t&&(i.Pt(),i.y=t,i.u())}get width(){return this.Le.width}set width(t){const i=this.Le;i.width!==t&&(i.Pt(),i.width=t,i.u())}get height(){return this.Le.height}set height(t){const i=this.Le;i.height!==t&&(i.Pt(),i.height=t,i.u())}commit(){const t=this._t;if(t!==null){const e=this.bounds,s=t.bounds;U.G(s)?(s.x=e.x,s.y=e.y,s.width=e.width,s.height=e.height):t.bounds=e.copy();return}const i=this.node;if(i!==null){const e=this.bounds;if(!(i instanceof Group)){const s=Rect.l();i.ensureBounds();const n=this.network.layout.getLayoutBounds(i,s),o=i.locationObject.getDocumentPoint(Spot.Center);if(n.isReal()&&o.isReal()){i.moveTo(e.x+this.focusX-(o.x-n.x)+i.margin.left,e.y+this.focusY-(o.y-n.y+i.margin.top)),Rect.e(s);return}Rect.e(s)}i.moveTo(e.x+i.margin.left,e.y+i.margin.top)}}addSourceEdge(t){t!==null&&(this.Ho.has(t)||this.Ho.add(t))}deleteSourceEdge(t){t!==null&&this.Ho.delete(t)}addDestinationEdge(t){t!==null&&(this.qo.has(t)||this.qo.add(t))}deleteDestinationEdge(t){t!==null&&this.qo.delete(t)}get network(){return this.ao}set network(t){this.ao=t}get sourceVertexes(){const t=new GSet,i=this.sourceEdges;for(;i.next();){const e=i.value;e.fromVertex&&t.add(e.fromVertex)}return t.iterator}get destinationVertexes(){const t=new GSet,i=this.destinationEdges;for(;i.next();){const e=i.value;e.toVertex&&t.add(e.toVertex)}return t.iterator}get vertexes(){const t=new GSet;let i=this.sourceEdges;for(;i.next();){const e=i.value;e.fromVertex&&t.add(e.fromVertex)}for(i=this.destinationEdges;i.next();){const e=i.value;e.toVertex&&t.add(e.toVertex)}return t.iterator}get sourceEdges(){return this.Ho.iterator}get destinationEdges(){return this.qo.iterator}get edges(){const t=new List;let i=this.sourceEdges;for(;i.next();){const e=i.value;t.add(e)}for(i=this.destinationEdges;i.next();){const e=i.value;t.add(e)}return t.iterator}get edgesCount(){return this.Ho.count+this.qo.count}static standardComparer(t,i){const e=t.Me,s=i.Me;if(e)if(s){const n=e.text,o=s.text;return no?1:0}else return 1;else return s!==null?-1:0}static smartComparer(t,i){if(t!==null)if(i!==null){const e=t.Me,s=i.Me;if(e!==null)if(s!==null){const n=e.text.toLocaleLowerCase(),o=s.text.toLocaleLowerCase(),r=n.split(/([+-]?[.]?\d+(?:\.\d*)?(?:e[+-]?\d+)?)/),l=o.split(/([+-]?[.]?\d+(?:\.\d*)?(?:e[+-]?\d+)?)/);let h=0;for(;h0&&(i+=this.Ke!==null?"("+this.Ke.toString()+")":"",t>1&&(i+=" "+(this.He?this.He.toString():"null")+" --> "+(this.qe?this.qe.toString():"null"))),i}reverseEdge(){const t=this.He;this.He=this.qe,this.qe=t}commit(){}getOtherVertex(t){return this.qe===t?this.He:this.He===t?this.qe:null}get network(){return this.ao}set network(t){this.ao=t}get data(){return this._t}set data(t){this._t!==t&&(this._t=t)}get link(){return this.Ke}set link(t){this.Ke!==t&&(this.Ke=t)}get fromVertex(){return this.He}set fromVertex(t){this.He!==t&&(this.He=t)}get toVertex(){return this.qe}set toVertex(t){this.qe!==t&&(this.qe=t)}}var GridAlignment=(y=>(y[y.Position=0]="Position",y[y.Location=1]="Location",y))(GridAlignment||{}),GridArrangement=(y=>(y[y.LeftToRight=10]="LeftToRight",y[y.RightToLeft=11]="RightToLeft",y))(GridArrangement||{}),GridSorting=(y=>(y[y.Forwards=20]="Forwards",y[y.Reverse=21]="Reverse",y[y.Ascending=22]="Ascending",y[y.Descending=23]="Descending",y))(GridSorting||{});class GridLayout extends Layout{Gd;Kd;Po;kn;hi;Xi;pe;ye;constructor(t){super(),this.isViewportSized=!0,this.Gd=NaN,this.Kd=NaN,this.Po=new Size(NaN,NaN).u(),this.kn=new Size(10,10).u(),this.hi=1,this.Xi=10,this.pe=22,this.ye=GridLayout.standardComparer,t&&Object.assign(this,t)}cloneProtected(t){super.cloneProtected(t),t.Gd=this.Gd,t.Kd=this.Kd,t.Po.a(this.Po),t.kn.a(this.kn),t.hi=this.hi,t.Xi=this.Xi,t.pe=this.pe,t.ye=this.ye}oi(t){t in GridSorting?this.sorting=t:t in GridArrangement?this.arrangement=t:t in GridAlignment?this.alignment=t:super.oi(t)}doLayout(t){this.arrangementOrigin=this.initialOrigin(this.arrangementOrigin);const i=this.collectParts(t),e=this.diagram,n=i.copy().iterator;for(;n.next();){const m=n.value;if(m.Cl()&&(m.fromNode!==null||m.toNode!==null)){i.delete(m);continue}if(m.ensureBounds(),m instanceof Group){const g=m.memberParts;for(;g.next();){const p=g.value;i.delete(p)}}}const o=i.toArray();if(o.length===0)return;switch(this.sorting){case 20:break;case 21:o.reverse();break;case 22:o.sort(this.comparer);break;case 23:o.sort(this.comparer),o.reverse();break}let r=this.wrappingColumn;isNaN(r)&&(r=0);let l=this.wrappingWidth;if(isNaN(l)&&e!==null){const m=e.viewportBounds,g=e.padding;l=Math.max(m.width-g.left-g.right,0)}else l=Math.max(this.wrappingWidth,0);r<=0&&l<=0&&(r=1);let h=this.spacing.width;isFinite(h)||(h=0);let c=this.spacing.height;isFinite(c)||(c=0),e!==null&&e.startTransaction("Layout");const a=[];switch(this.alignment){case 0:this.XO(o,l,r,h,c,a);break;case 1:this.YO(o,l,r,h,c,a);break}let f=0,u=0,d=0;for(let m=0;m0&&m>e-1||i>0&&m>0&&L-a>i)&&(o.push(new Rect(0,d,i+s,g)),m=0,u=a,d+=g,g=0),g=Math.max(g,S);let C=0;switch(c){case 11:C=-x.width;break;default:C=0;break}switch(w.moveTo(u+C+w.margin.left,d+w.margin.top),c){case 11:u-=P;break;default:u+=P;break}m++}o.push(new Rect(0,d,i+s,g)),Rect.e(r)}YO(t,i,e,s,n,o){const r=Rect.l();let l=Math.max(this.cellSize.width,1),h=0,c=0,a=0;const f=Point.l();for(let C=0;C=h&&(i-=h);let x=0,k=0;const b=Math.max(this.cellSize.height,1);a=0;let P=0,S=!0;const L=Point.l();for(let C=0;C0)switch(u){case 11:{let D=(g-d-(N.width-T.x))/l;Geo.z(Math.round(D),D)?D=Math.round(D):D=Math.floor(D),g=D*l+d;break}default:{let D=(g-d+T.x)/l;Geo.z(Math.round(D),D)?D=Math.round(D):D=Math.ceil(D),g=D*l+d;break}}else switch(u){case 11:x=g+T.x+N.width;break;default:x=g-T.x;break}let A=0;switch(u){case 11:A=-(g+T.x)+x;break;default:A=g+N.width-T.x-x;break}if(e>0&&w>e-1||i>0&&w>0&&A>i){o.push(new Rect(0,S?p-a:p,i+s,P+a+n));for(let D=0;Dk&&(M.width+=M.x-k,M.x=k)}Rect.e(r)}commitLayers(t,i){}get wrappingWidth(){return this.Gd}set wrappingWidth(t){this.Gd!==t&&(U.s(t,"number",GridLayout,"wrappingWidth"),(t>0||isNaN(t))&&(this.Gd=t,this.isViewportSized=isNaN(t),this.invalidateLayout()))}get wrappingColumn(){return this.Kd}set wrappingColumn(t){this.Kd!==t&&(U.s(t,"number",GridLayout,"wrappingColumn"),(t>0||isNaN(t))&&(this.Kd=t,this.invalidateLayout()))}get cellSize(){return this.Po}set cellSize(t){this.Po.equals(t)||(this.Po.a(t),this.invalidateLayout())}get spacing(){return this.kn}set spacing(t){this.kn.equals(t)||(this.kn.a(t),this.invalidateLayout())}get alignment(){return this.hi}set alignment(t){this.hi!==t&&(t===1||t===0)&&(this.hi=t,this.invalidateLayout())}get arrangement(){return this.Xi}set arrangement(t){this.Xi!==t&&(t===10||t===11)&&(this.Xi=t,this.invalidateLayout())}get sorting(){return this.pe}set sorting(t){this.pe!==t&&(t===20||t===21||t===22||t===23)&&(this.pe=t,this.invalidateLayout())}get comparer(){return this.ye}set comparer(t){this.ye!==t&&(U.k(t,GridLayout,"comparer"),this.ye=t,this.invalidateLayout())}static standardComparer(t,i){const e=t.text,s=i.text;return es?1:0}static smartComparer(t,i){if(t!==null)if(i!==null){const e=t.text.toLocaleLowerCase(),s=i.text.toLocaleLowerCase(),n=e.split(/([+-]?[.]?\d+(?:\.\d*)?(?:e[+-]?\d+)?)/),o=s.split(/([+-]?[.]?\d+(?:\.\d*)?(?:e[+-]?\d+)?)/);let r=0;for(;r{e.containsNodeData(s)&&this.vT(s,!1)}),t.forEach(s=>{e.containsNodeData(s)&&this.R1(s)}),i!==!1&&this.diagram.Cb(!1)}vT(t,i){if(t==null||this.diagram.undoManager.isUndoingRedoing||this.uo.has(t))return null;i===void 0&&(i=!0);const e=this.GO(t);return e!==null&&i&&this.R1(t),e}GO(t){if(t==null||this.diagram.undoManager.isUndoingRedoing||this.uo.has(t))return null;const i=this.KO(t),e=this.findTemplateForNodeData(t,i);if(e!==null){e.Et();const s=e.copy();if(s!==null){const n=this.diagram.fe;return this.diagram.fe=!0,s.zo=i,s._t=t,this.addsToTemporaryLayer&&(s.nl="Tool"),this.diagram.add(s),s._t=null,s.data=t,this.diagram.fe=n,s}}return null}insertLink(t,i,e,s){return null}R1(t){}KO(t){return this.diagram.model.getCategoryForNodeData(t)}static OT=!1;static IT=!1;findTemplateForNodeData(t,i){const e=this.diagram,s=e.model,n=s.Hc()&&s.isGroupForData(t);let o=null;return n?(o=e.groupTemplateMap.get(i),o===null&&(o=e.groupTemplateMap.get(""),o===null&&(PartManager.IT||(PartManager.IT=!0,U.ni('No Group template found for category "'+i+'"'),U.ni(" Using default group template")),o=e.yM))):(o=e.nodeTemplateMap.get(i),o===null&&(o=e.nodeTemplateMap.get(""),o===null&&(PartManager.OT||(PartManager.OT=!0,U.ni('No Node template found for category "'+i+'"'),U.ni(" Using default node template")),o=e.gM))),o}getLinkCategoryForData(t){return""}setLinkCategoryForData(t,i){}setFromNodeForLink(t,i,e){}setToNodeForLink(t,i,e){}static ET=!1;findLinkTemplateForCategory(t){const i=this.diagram;let e=i.linkTemplateMap.get(t);return e===null&&(e=i.linkTemplateMap.get(""),e===null&&(PartManager.ET||(PartManager.ET=!0,U.ni('No Link template found for category "'+t+'"'),U.ni(" Using default link template")),e=i.mM)),e}vv(t,i,e){t instanceof Link?(i!==null&&this.FT(i,t),e!==null&&this.DT(e,t)):t instanceof Part&&(i!==null&&this.uo.delete(i),e!==null&&this.uo.set(e,t))}RT(){const t=this.diagram.model;this.NN(t.nodeDataArray)}NN(t){t.forEach(i=>{this.v1(i)})}v1(t){const i=this.findPartForData(t);i!==null&&(this.diagram.UM(i,!1),this.CN(i))}CN(t){}pN(t){}findPartForKey(t){if(t==null)return null;const e=this.diagram.model.findNodeDataForKey(t);return e!==null?this.uo.get(e):null}findNodeForKey(t){if(t==null)return null;const e=this.diagram.model.findNodeDataForKey(t);if(e===null)return null;const s=this.uo.get(e);return s instanceof Node?s:null}findLinkForKey(t){return null}findPartForData(t){if(t===null)return null;let i=this.uo.get(t);return i!==null||(i=this.Hd.get(t)),i}findNodeForData(t){if(t===null)return null;const i=this.uo.get(t);return i instanceof Node?i:null}findLinkForData(t,i){return t===null?null:this.Hd.get(t)}findNodesByExample(...t){const i=new GSet,e=this.jd.iterator;for(;e.next();){const s=e.value,n=s.data;if(n!==null)for(let o=0;o{o.data!==null&&!i.has(o.data)&&s.push(o.data)}),this.parts.each(o=>{o.data!==null&&!i.has(o.data)&&s.push(o.data)}),s.forEach(o=>t.BT(o,!1));for(let o=0;o0){for(let o=0;oi.GL(s));const e=t.wh;if(Array.isArray(e)){const s=this.AN(e);if(s===null)this.qd.set(e,[t]);else{for(let n=0;ni.UR(s));const e=t.wh;if(Array.isArray(e)){const s=this.AN(e);if(s!==null){for(let n=0;n0&&i.removeParts(l,!1),h.count>0){const a=h.iterator;for(;a.next();){const f=a.key,u=a.value;s.set(f,u)}}}if(i!==null&&this.diagram!==null){const o=i.model,r=o.afterCopyFunction;if(r!==null){const l=new GMap;s.each(c=>{c.key.data!==null&&l.set(c.key.data,c.value.data)});const h=this.diagram.model;r(l,o,h)}}const n=s.iterator;for(;n.next();)n.value.updateTargetBindings();return s}O1(t,i,e,s){if(t===null||s&&!t.canCopy())return null;if(e.has(t))return e.get(t);const n=this.TN(t,i);if(!(n instanceof Part))return null;if(n.isSelected=!1,n.isHighlighted=!1,e.set(t,n),t instanceof Node){const o=t.linksConnected;for(;o.next();){const r=o.value;if(r.fromNode===t){const l=e.get(r);l!==null&&(l.fromNode=n)}if(r.toNode===t){const l=e.get(r);l!==null&&(l.toNode=n)}}if(t instanceof Group&&n instanceof Group){const r=t.memberParts;for(;r.next();){const l=r.value,h=this.O1(l,i,e,s);h instanceof Link||h!==null&&(h.containingGroup=n)}}}else if(t instanceof Link&&n instanceof Link){const o=t.fromNode;if(o!==null){const h=e.get(o);h!==null&&(n.fromNode=h)}const r=t.toNode;if(r!==null){const h=e.get(r);h!==null&&(n.toNode=h)}const l=t.labelNodes;for(;l.next();){const h=l.value,c=this.O1(h,i,e,s);c!==null&&c instanceof Node&&(c.labeledLink=n)}}return n}TN(t,i){let e=null;const s=t.data;if(s!==null&&i!==null){const n=i.model;if(!(t instanceof Link)){const o=n.copyNodeData(s);U.G(o)&&(n.addNodeData(o),e=i.findPartForData(o))}}else if(t.Et(),e=t.copy(),e!==null){const n=this.diagram;if(i!==null)i.add(e);else if(s!==null&&n!==null&&n.commandHandler!==null&&n.commandHandler.copiesClipboardData){const o=n.model;let r=null;e instanceof Link||(r=o.copyNodeData(s)),U.G(r)&&(e.data=r)}}return e}get nodes(){return this.jd}get links(){return this.Hs}get parts(){return this.Ct}get diagram(){return this.N}get addsToTemporaryLayer(){return this.MN}set addsToTemporaryLayer(t){this.MN=t}}class GraphLinksPartManager extends PartManager{zM(){const t=this.diagram.model;this.My(t.nodeDataArray),this.XT(t.linkDataArray)}My(t){super.My(t,!1);const i=this.links.iterator;for(;i.next();)i.value.Pd();this.diagram.Cb(!1)}XT(t){t.forEach(i=>{this.YT(i)}),this.diagram.Cb(!1)}YT(t){if(t==null||this.diagram.undoManager.isUndoingRedoing||this.findLinkForData(t))return null;const i=this.getLinkCategoryForData(t),e=this.findLinkTemplateForCategory(i);if(e!==null){e.Et();const s=e.copy();if(s!==null){const n=this.diagram.fe;this.diagram.fe=!0,s.zo=i,s._t=t;const o=this.diagram.model,r=o.I1(t,!0);r!==""&&(s.fromPortId=r);const l=o.Ae(t,!0);if(l!==void 0){const f=this.findNodeForKey(l);f instanceof Node&&(s.fromNode=f)}const h=o.I1(t,!1);h!==""&&(s.toPortId=h);const c=o.Ae(t,!1);if(c!==void 0){const f=this.findNodeForKey(c);f instanceof Node&&(s.toNode=f)}const a=o.getLabelKeysForLinkData(t);return Array.isArray(a)&&a.forEach(f=>{const u=this.findNodeForKey(f);u!==null&&(u.labeledLink=s)}),this.addsToTemporaryLayer&&(s.nl="Tool"),this.diagram.add(s),s._t=null,s.data=t,this.diagram.fe=n,s}}return null}RT(){const t=this.diagram.model;this.GT(t.linkDataArray),this.NN(t.nodeDataArray)}GT(t){t.forEach(i=>{this.v1(i)})}getLinkCategoryForData(t){return this.diagram.model.getCategoryForLinkData(t)}setLinkCategoryForData(t,i){return this.diagram.model.setCategoryForLinkData(t,i)}setFromNodeForLink(t,i){const e=this.diagram.model,s=i!==null?i.data:null;e.setFromKeyForLinkData(t.data,e.getKeyForNodeData(s))}setToNodeForLink(t,i){const e=this.diagram.model,s=i!==null?i.data:null;e.setToKeyForLinkData(t.data,e.getKeyForNodeData(s))}pN(t){this.diagram.model.removeLinkData(t.data)}findPartForKey(t){const i=super.findPartForKey(t);if(i===null){const s=this.diagram.model.findLinkDataForKey(t);if(s!==null)return this.findLinkForData(s)}return i}findLinkForKey(t){if(t==null)return null;const e=this.diagram.model.findLinkDataForKey(t);return e!==null?this.findLinkForData(e):null}doModelChanged(t){if(super.doModelChanged(t),!this.diagram)return;const i=this.diagram;if(t.model!==i.model)return;const e=t.change;if(i.X){i.X=!1;try{const s=t.modelChange;if(s!==""){if(e===2){if(s==="linkFromKey"){const n=t.object,o=this.findLinkForData(n);if(o!==null){const r=t.newValue,l=this.findNodeForKey(r);o.fromNode=l}}else if(s==="linkToKey"){const n=t.object,o=this.findLinkForData(n);if(o!==null){const r=t.newValue,l=this.findNodeForKey(r);o.toNode=l}}else if(s==="linkFromPortId"){const n=t.object,o=this.findLinkForData(n);if(o!==null){const r=t.newValue;typeof r=="string"&&(o.fromPortId=r)}}else if(s==="linkToPortId"){const n=t.object,o=this.findLinkForData(n);if(o!==null){const r=t.newValue;typeof r=="string"&&(o.toPortId=r)}}else if(s==="nodeGroupKey"){const n=t.object,o=this.findPartForData(n);if(o!==null){const r=t.newValue;if(r!==void 0){const l=this.findNodeForKey(r);l instanceof Group?o.containingGroup=l:o.containingGroup=null}else o.containingGroup=null}}else if(s==="linkLabelKeys"){const n=t.object,o=this.findLinkForData(n);if(o!==null){const r=t.oldValue,l=t.newValue;Array.isArray(r)&&r.forEach(h=>{if(l.indexOf(h)>=0)return;const c=this.findNodeForKey(h);c!==null&&(c.labeledLink=null)}),Array.isArray(l)&&l.forEach(h=>{const c=this.findNodeForKey(h);c!==null&&(c.labeledLink=o)})}}else if(s==="linkCategory"){const n=t.object,o=this.findLinkForData(n),r=t.newValue;o!==null&&typeof r=="string"&&(o.category=r)}else if(s==="linkDataArray"){const n=t.oldValue;this.GT(n);const o=t.newValue;this.XT(o)}i.isModified=!0}else if(e===3){const n=t.newValue;if(s==="linkDataArray"&&U.G(n))this.YT(n);else if(s==="linkLabelKeys"&&t.model.isKeyType(n)){const o=t.object,r=this.findLinkForData(o),l=this.findNodeForKey(n);r!==null&&l!==null&&(l.labeledLink=r)}i.isModified=!0}else if(e===4){const n=t.oldValue;if(s==="linkDataArray"&&U.G(n))this.v1(n);else if(s==="linkLabelKeys"&&t.model.isKeyType(n)){const o=this.findNodeForKey(n);o!==null&&(o.labeledLink=null)}i.isModified=!0}}else if(e===2){const n=t.propertyName,o=t.object,r=i.model;o===r&&(n==="linkFromKeyProperty"||n==="linkToKeyProperty"||n==="linkFromPortIdProperty"||n==="linkToPortIdProperty"||n==="linkLabelKeysProperty"||n==="nodeIsGroupProperty"||n==="nodeGroupKeyProperty"||n==="linkCategoryProperty")&&(i.undoManager.isUndoingRedoing||this.rebuildParts()),i.isModified=!0}}finally{i.X=!0}}}zT(){const t=this.diagram.model,i=new GSet,e=t.linkDataArray;e.forEach(n=>{i.add(n)});const s=[];this.links.each(n=>{n.data!==null&&!i.has(n.data)&&s.push(n.data)}),s.forEach(n=>{t.KT(n,!1)}),e.forEach(n=>{this.findLinkForData(n)===null&&t.jT(n,!1)})}updateRelationshipsFromData(t){const i=t.data;if(i===null)return;const e=t.diagram;if(e===null)return;const s=e.model;if(t instanceof Link){let n=s.Ae(i,!0),o=e.findNodeForKey(n);t.fromNode=o,n=s.Ae(i,!1),o=e.findNodeForKey(n),t.toNode=o;const r=s.getLabelKeysForLinkData(i);if(r.length>0||t.labelNodes.count>0){if(r.length===1&&t.labelNodes.count===1){const f=r[0],u=t.labelNodes.first();if(s.getKeyForNodeData(u.data)===f)return}const l=new GSet().addAll(r),h=new GSet;t.labelNodes.each(f=>{if(f.data!==null){const u=s.getKeyForNodeData(f.data);u!==void 0&&h.add(u)}});const c=h.copy();c.removeAll(l);const a=l.copy();if(a.removeAll(h),c.count>0||a.count>0){const f=t;c.each(u=>{const d=e.findNodeForKey(u);d!==null&&d.labeledLink===f&&(d.labeledLink=null)}),a.each(u=>{const d=e.findNodeForKey(u);d!==null&&d.labeledLink!==f&&(d.labeledLink=f)})}}}else if(!(t instanceof Adornment)){const n=s.getGroupKeyForNodeData(i),o=e.findPartForKey(n);(o===null||o instanceof Group)&&(t.containingGroup=o)}}R1(t){const i=this.diagram.model,e=i.getKeyForNodeData(t);if(e!==void 0){const s=i.Cy(e),n=this.findPartForData(t);if(s!==null&&n!==null){const r=s.iterator;for(;r.next();){const l=r.value;if(i.containsNodeData(l)){if(n instanceof Group&&i.getGroupKeyForNodeData(l)===e){const h=this.findPartForData(l);h!==null&&(h.containingGroup=n)}}else{const h=this.findLinkForData(l);if(h!==null&&n instanceof Node){i.Ae(l,!0)===e&&(h.fromNode=n),i.Ae(l,!1)===e&&(h.toNode=n);const c=i.getLabelKeysForLinkData(l);Array.isArray(c)&&c.some(a=>a===e?(n.labeledLink=h,!0):!1)}}}i.Ws(e)}const o=i.getGroupKeyForNodeData(t);if(o!==void 0){const r=this.findNodeForKey(o);r instanceof Group&&(n.containingGroup=r)}}}CN(t){const i=this.diagram.model;if(t instanceof Node){const e=i.getKeyForNodeData(t.data);if(e!==void 0){const s=t.linksConnected;for(;s.next();){const n=s.value;i.Js(e,n.data)}if(t.isLinkLabel){const n=t.labeledLink;n!==null&&i.Js(e,n.data)}if(t instanceof Group){const n=t.memberParts;for(;n.next();){const r=n.value.data;i.containsNodeData(r)&&i.Js(e,r)}}}}}TN(t,i){let e=super.TN(t,i);if(t instanceof Link){const s=t.data;if(s!==null&&i!==null){const n=i.model,o=n.copyLinkData(s);U.G(o)&&(n.addLinkData(o),e=i.findLinkForData(o))}else if(e!==null){const n=this.diagram;if(s!==null&&n!==null&&n.commandHandler!==null&&n.commandHandler.copiesClipboardData){const r=n.model.copyLinkData(s);U.G(r)&&(e.data=r)}}}return e}insertLink(t,i,e,s){const n=this.diagram,o=n.model,r=n.toolManager.findTool("Linking");let l="";t!==null&&(i===null&&(i=t),l=i.portId,l===null&&(l=""));let h="";e!==null&&(s===null&&(s=e),h=s.portId,h===null&&(h=""));const c=r.archetypeLinkData;if(c instanceof Link){c.Et();const a=c.copy();if(a!==null){a.fromNode=t,a.fromPortId=l,a.toNode=e,a.toPortId=h,n.add(a);const f=r.archetypeLabelNodeData;if(f instanceof Node){f.Et();const u=f.copy();u!==null&&(u.labeledLink=a,n.add(u))}return a}}else if(c!==null){const a=o.copyLinkData(c);if(U.G(a)){t!==null&&o.Wd(a,o.getKeyForNodeData(t.data),!0),o.Jd(a,l,!0),e!==null&&o.Wd(a,o.getKeyForNodeData(e.data),!1),o.Jd(a,h,!1),o.addLinkData(a);const f=r.archetypeLabelNodeData;if(f!==null&&!(f instanceof Node)){const d=o.copyNodeData(f);if(U.G(d)){o.addNodeData(d);const m=o.getKeyForNodeData(d);m!==void 0&&o.addLabelKeyForLinkData(a,m)}}return n.findLinkForData(a)}}return null}}class TreePartManager extends PartManager{Nh=null;E1(t,i){if(t===null||i===null||i.findTreeParentLink()!==null)return null;const e=this.diagram.toolManager.findTool("Linking");let s=t,n=i;if(this.diagram.isTreePathToChildren){if(e!==null&&e.yu(s,n,null,!0))return null}else if(s=i,n=t,e!==null&&e.yu(s,n,null,!0))return null;const o=this.getLinkCategoryForData(i.data),r=this.findLinkTemplateForCategory(o);if(r!==null){r.Et();const l=r.copy();if(l!==null){const h=this.diagram.fe;return this.diagram.fe=!0,l.zo=o,l._t=i.data,l.fromNode=s,l.toNode=n,this.diagram.add(l),l._t=null,l.data=i.data,this.diagram.fe=h,l}}return null}getLinkCategoryForData(t){return this.diagram.model.getParentLinkCategoryForNodeData(t)}setLinkCategoryForData(t,i){this.diagram.model.setParentLinkCategoryForNodeData(t,i)}setFromNodeForLink(t,i,e){const s=this.diagram.model;e===void 0&&(e=null);const n=i!==null?i.data:null;if(this.diagram.isTreePathToChildren)s.setParentKeyForNodeData(t.data,s.getKeyForNodeData(n));else{const o=this.Nh;this.Nh=t,e!==null&&s.setParentKeyForNodeData(e.data,void 0);const r=t.toNode!==null?t.toNode.data:null;s.setParentKeyForNodeData(n,s.getKeyForNodeData(r)),this.Nh=o}}setToNodeForLink(t,i,e){const s=this.diagram.model;e===void 0&&(e=null);const n=i!==null?i.data:null;if(this.diagram.isTreePathToChildren){const o=this.Nh;this.Nh=t,e!==null&&s.setParentKeyForNodeData(e.data,void 0);const r=t.fromNode!==null?t.fromNode.data:null;s.setParentKeyForNodeData(n,s.getKeyForNodeData(r)),this.Nh=o}else s.setParentKeyForNodeData(t.data,s.getKeyForNodeData(n))}pN(t){this.diagram.model.setParentKeyForNodeData(t.data,void 0)}findLinkForKey(t){if(t==null)return null;const e=this.diagram.model.findNodeDataForKey(t);return e!==null?this.findLinkForData(e):null}doModelChanged(t){if(super.doModelChanged(t),!this.diagram)return;const i=this.diagram;if(t.model!==i.model)return;const e=t.change;if(i.X){i.X=!1;try{const s=t.modelChange;if(s!==""){if(e===2){if(s==="nodeParentKey"){const n=t.object,o=t.newValue,r=this.findNodeForKey(o),l=this.findNodeForData(n);if(this.Nh!==null)r!==null&&(this.Nh.data=n,this.Nh.category=this.getLinkCategoryForData(n));else if(l!==null){const h=l.findTreeParentLink();h!==null?r===null?i.remove(h):i.isTreePathToChildren?h.fromNode=r:h.toNode=r:this.E1(r,l)}}else if(s==="parentLinkCategory"){const n=t.object,o=this.findNodeForData(n),r=t.newValue;if(o!==null&&typeof r=="string"){const l=o.findTreeParentLink();l!==null&&(l.category=r)}}i.isModified=!0}}else if(e===2){const n=t.propertyName,o=t.object,r=i.model;o===r&&n==="nodeParentKeyProperty"&&(i.undoManager.isUndoingRedoing||this.rebuildParts()),i.isModified=!0}}finally{i.X=!0}}}updateRelationshipsFromData(t){const i=t.data;if(i===null)return;const e=t.diagram;if(e===null)return;const s=e.model;if(t instanceof Node){const n=s.getParentKeyForNodeData(i),o=e.findNodeForKey(n),r=t.findTreeParentNode();if(o!==r){const l=t.findTreeParentLink();o!==null?l!==null?e.isTreePathToChildren?l.fromNode=o:l.toNode=o:this.E1(o,t):l!==null&&e.UM(l,!1)}}}Ny(t,i){if(super.Ny(t,i),typeof i=="string"&&this.findPartForData(t)!==null){const s=this.findLinkForData(t);s!==null&&s.updateTargetBindings(i)}}R1(t){const i=this.diagram.model,e=i.getKeyForNodeData(t);if(e!==void 0){const s=i.Cy(e),n=this.findPartForData(t);if(s!==null&&n!==null){const r=s.iterator;for(;r.next();){const l=r.value;if(i.containsNodeData(l)&&n instanceof Node&&i.getParentKeyForNodeData(l)===e){const h=this.findNodeForData(l);this.E1(n,h)}}i.Ws(e)}const o=i.getParentKeyForNodeData(t);if(o!==void 0&&n instanceof Node){const r=this.findNodeForKey(o);this.E1(r,n)}}}CN(t){const i=this.diagram.model;if(t instanceof Node){const e=i.getKeyForNodeData(t.data),s=this.findLinkForData(t.data);if(s!==null){s.isSelected=!1,s.isHighlighted=!1;const r=s.layer;if(r!==null){const l=r.te(-1,s,!1);l>=0&&this.diagram.raiseChangedEvent(4,"parts",r,s,null,l,null);const h=s.layerChanged;h!==null&&h(s,r,null)}}const n=this.diagram.isTreePathToChildren,o=t.linksConnected;for(;o.next();){const r=o.value,h=(n?r.toNode:r.fromNode).data;i.containsNodeData(h)&&i.Js(e,h)}}}insertLink(t,i,e,s){const n=this.diagram.model;let o=t,r=e;if(this.diagram.isTreePathToChildren||(o=e,r=t),o!==null&&r!==null){const l=o.data,h=r.data;return n.setParentKeyForNodeData(h,n.getKeyForNodeData(l)),r.findTreeParentLink()}return null}}var BindingMode=(y=>(y[y.OneWay=1]="OneWay",y[y.TwoWay=2]="TwoWay",y))(BindingMode||{});class Binding{n;DN;Ya;Cf;Ch;Lf;Af;Tf;U1;be;ad;ff;constructor(t,i,e,s){GSet.Ki(this),t===void 0?t="":U.s(t,"string",Binding,"constructor:targetprop"),i===void 0?i=t:U.s(i,"string",Binding,"constructor:sourceprop"),e===void 0?e=null:e!==null&&U.k(e,Binding,"constructor:conv"),this.DN=-1,this.be=null,this.Ya=t,this.ad=0,this.ff=0,this.Cf=null,this.Ch=i,this.Lf=e,s===void 0?(this.Af=1,this.Tf=null):(this.Af=2,this.Tf=s),this.U1=new GSet,this.n=2}copy(){const t=new this.constructor;return this.cloneProtected(t),t}cloneProtected(t){t.Ya=this.Ya,t.ad=this.ad,t.ff=this.ff,t.Cf=this.Cf,t.Ch=this.Ch,t.Lf=this.Lf,t.Af=this.Af,t.Tf=this.Tf,t.n=this.n&-2}static OneWay=1;static TwoWay=2;static parseEnum(t,i){return U.k(t,Binding,"parseEnum:ctor"),e=>{let s=parseInt(e);return isNaN(s)&&(s=U.Uh(t,e),s===null)?i:s}}oi(t){t in BindingMode?this.mode=t:U.er(this,t)}static toString(t){return U.toString(t)}toString(){return"Binding("+this.targetProperty+":"+this.sourceProperty+(this.targetId!==-1?" "+this.targetId:"")+" "+BindingMode[this.mode]+")"}u(){return this.n=this.n|1,this}get targetId(){return this.DN}set targetId(t){this.h&&U.L(this),this.DN=t}get targetProperty(){return this.Ya}set targetProperty(t){this.h&&U.L(this),U.s(t,"string",Binding,"targetProperty"),this.Ya=t}get sourceProperty(){return this.Ch}set sourceProperty(t){this.h&&U.L(this),U.s(t,"string",Binding,"sourceProperty"),this.Ch=t}get h(){return(this.n&1)!==0}get isToData(){return(this.n&2)!==0}get isToObject(){return(this.n&4)!==0}get isToModel(){return(this.n&8)!==0}get isToTheme(){return(this.n&16)!==0}get FN(){return this.isToTheme&&!(this.isToData||this.isToObject||this.isToModel)}qu(){return!1}get sourceName(){return this.Cf}set sourceName(t){this.h&&U.L(this),t!==null&&U.s(t,"string",Binding,"sourceName"),this.Cf=t,t!==null?this.n=this.n&-3|4:this.n=this.n|2}get converter(){return this.Lf}set converter(t){this.h&&U.L(this),t!==null&&U.k(t,Binding,"converter"),this.Lf=t}get backConverter(){return this.Tf}set backConverter(t){this.h&&U.L(this),t!==null&&U.k(t,Binding,"backConverter"),this.Tf=t}get mode(){return this.Af}set mode(t){this.h&&U.L(this),this.isToTheme&&t===2&&U.o("Theme Bindings cannot be TwoWay."),this.Af=t}makeTwoWay(t){return this.isToTheme&&U.o("Theme Bindings cannot be TwoWay."),this.mode=2,t&&(U.k(t,Binding,"makeTwoWay"),this.backConverter=t),this}ofObject(t){return this.h&&U.L(this),t===void 0&&(t=""),this.sourceName=t,this}ofModel(){return this.h&&U.L(this),this.n=this.n&-3&-5|8,this.Cf=null,this}yA(t,i){const e=this.sourceName;let s=null;return e===null||e===""?s=t:e==="/"?s=i.part:e==="."?s=i:e===".."?s=i.panel:s=t.findObject(e),s}check(t){const i=this.Ya,e=this.Ch,s=this.Lf;(this.qu()&&s===null&&this.Lh===null&&i===""||s===null&&i==="")&&U.ni("Binding error: target property is the empty string: "+this.toString()),this.qu()&&this.FN&&e===""&&s===null&&this.Lh===null&&U.ni("Binding error: theme bindings require a source property when not using a converter: "+this.toString()),t&&typeof i=="string"&&(!U.it(["setAttribute"])&&i.length>0&&i[0]!=="_"&&!U.gw(t,i)?U.ni("Binding error: undefined target property: "+i+" on "+t.toString()):i==="name"&&t instanceof GraphObject&&U.ni("Binding error: cannot modify GraphObject.name on "+t.toString()))}updateTarget(t,i,e,s){const n=this.Ch;if(e!==void 0&&n!==""&&n!==e)return;const o=this.Ya,r=this.Lf;let l=i;if(n!==""&&!this.FN&&(s?l=s.yt(i,n):l=Model.yt(i,n)),l===void 0)return;const h=t.diagram?.themeManager;if(r===null){if(o!==""){if(this.qu()&&(l=this.HT(h,l,t,o),l===void 0))return;s?s.Z(t,o,l):(i instanceof GraphObject||i instanceof RowColumnDefinition)&&Model.Z(t,o,l)}}else try{if(o!==""){let c=r(l,t);if(this.qu()&&(c=this.HT(h,c,t,o),c===void 0))return;s?s.Z(t,o,c):(i instanceof GraphObject||i instanceof RowColumnDefinition)&&Model.Z(t,o,c)}else r(l,t)}catch{}}updateSource(t,i,e,s){if(this.Af!==2)return;const n=this.Ya;if(e!==void 0&&n!==e)return;const o=this.Ch,r=this.Tf,l=s!==null?s.diagram:null,h=l!==null?l.model:null;let c=t;if(n!==""&&(h?c=h.yt(t,n):c=Model.yt(t,n)),c!==void 0&&!this.U1.has(t))try{if(this.U1.add(t),r===null){if(o!=="")h!==null?h.setDataProperty(i,o,c):(i instanceof GraphObject||i instanceof RowColumnDefinition)&&(i[o]=c);else if(h!==null&&s!==null&&s.itemIndex>=0&&s.panel!==null&&Array.isArray(s.panel.itemArray)){const a=s.itemIndex,f=s.panel.itemArray;h.removeArrayItem(f,a),h.insertArrayItem(f,a,c)}}else try{if(o!==""){const a=r(c,i,h);h!==null?h.setDataProperty(i,o,a):(i instanceof GraphObject||i instanceof RowColumnDefinition)&&(i[o]=a)}else{const a=r(c,i,h);if(a!==void 0&&h!==null&&s!==null&&s.itemIndex>=0&&s.panel!==null&&Array.isArray(s.panel.itemArray)){const f=s.itemIndex,u=s.panel.itemArray;h.removeArrayItem(u,f),h.insertArrayItem(u,f,a)}}}catch{}}finally{this.U1.delete(t)}}}class ThemeBinding extends Binding{Ly;Lh;Ga;constructor(t,i,e,s,n){super(t,i,s),e==null&&(e=""),n===void 0&&(n=null),this.Ly=e,this.Lh=n,this.Ga=null,this.n=16}cloneProtected(t){super.cloneProtected(t),t.Ly=this.Ly,t.Lh=this.Lh,t.Ga=this.Ga}qu(){return!0}get themeSource(){return this.Ly}set themeSource(t){this.h&&U.L(this),t!==null&&U.s(t,"string",ThemeBinding,"themeSource"),this.Ly=t,this.Ga=null,t!==null?this.n=this.n|16:this.n=this.n&-17}get themeConverter(){return this.Lh}set themeConverter(t){this.h&&U.L(this),t!==null&&U.k(t,ThemeBinding,"themeConverter"),this.Lh=t}ofData(){return this.h&&U.L(this),this.n=this.n|2,this.Cf=null,this}HT(t,i,e,s){if(!t||(this.FN&&(i=this.Ch),!i&&i!==0))return;let n=this.themeSource;this.Ga!==null?n=this.Ga:typeof n=="string"&&n.includes(".")&&(this.Ga=n.split("."),n=this.Ga);let o=t.findValue(i,n,s);return o===void 0&&U.ni(`Theme warning: ${i} could not be found when setting target property ${s}.`),U.it(this.Lh)&&(o=this.Lh(o,e)),o}}class Model{St;$d;Ao;RN;Te;mi;Ah;Df;Ff;Zd;Qd;_d;tg;Ay;Ka;Jo;Ty;Lo;B1;constructor(t,i){if(GSet.Ki(this),this.St="",this.$d="",this.Ao=!1,this.RN={},this.Te=[],this.mi=new GMap,this.Ah="key",this.Df=null,this.Ff=null,this.Zd=!1,this.Qd=!1,this._d=!1,this.tg=null,this.Ay=100,this.Ka="category",this.Jo=new GMap,this.Ty=[],this.Lo=!1,this.B1=null,this.undoManager=new UndoManager,t!==void 0&&(Array.isArray(t)?this.nodeDataArray=t:i=t),i){Object.assign(this,i);const e=i.Changed;e&&(delete this.Changed,this.addChangedListener(e))}}cloneProtected(t){t.St=this.St,t.$d=this.$d,t.Ao=this.Ao,t.Ah=this.Ah,t.Df=this.Df,t.Ff=this.Ff,t.Zd=this.Zd,t.Qd=this.Qd,t._d=this._d,t.tg=this.tg,t.Ay=this.Ay,t.Ka=this.Ka}copy(){const t=new this.constructor;return this.cloneProtected(t),t}clear(){this.Te=[],this.mi.clear(),this.Jo.clear(),this.undoManager.clear()}toString(t){if(t===void 0&&(t=0),t>1)return this.toJson();{let i=(this.name!==""?this.name:"")+" Model";if(t>0){i+=` node data:`;const e=this.nodeDataArray,s=e.length;for(let n=0;n{if(u.model===s){if(u.modelChange==="nodeDataArray")u.change===3?o.add(u.newValue):u.change===4&&l.add(u.oldValue);else if(s.containsNodeData(u.object))r.add(u.object);else if(u.change===2&&(s.modelData===u.object||u.propertyName==="modelData"))n=!0;else if(u.object!==null)if(e.has(u.object))e.get(u.object).each(m=>{s.containsNodeData(m)&&r.add(m)});else{if(u.object instanceof Model||s.Ra()&&s.containsLinkData(u.object))return;s.WT(u.object).each(m=>{r.add(m)})}}});const h=new GSet;o.each(u=>{h.add(s.getKeyForNodeData(u)),i||r.add(u)});const c=new GSet;l.each(u=>{c.add(s.getKeyForNodeData(u)),i&&r.add(u)});const a=s.cloneDeep(r.toArray());let f=null;return n&&(f===null&&(f={}),f.modelData=this.cloneDeep(this.modelData)),h.count>0&&(f===null&&(f={}),i?f.removedNodeKeys=h.toArray():f.insertedNodeKeys=h.toArray()),a.length>0&&(f===null&&(f={}),f.modifiedNodeData=a),c.count>0&&(f===null&&(f={}),i?f.insertedNodeKeys=c.toArray():f.removedNodeKeys=c.toArray()),f}cloneDeep(t){return this.ig(t,!0)}ig(t,i,e,s){if(!U.G(t))return t;e||(e=new GMap);const n=e.get(t);if(n)return n;let o;if(Array.isArray(t)){o=[],e.set(t,o);for(let r=0;r{const s="0000"+e.charCodeAt(0).toString(16);return"\\u"+s.substring(s.length-4)})}eg(){let t="";return this.name!==""&&(t+=`, "name": `+this.De(this.name)),this.dataFormat!==""&&(t+=`, "dataFormat": `+this.De(this.dataFormat)),this.isReadOnly&&(t+=`, "isReadOnly": `+this.isReadOnly),this.nodeKeyProperty!=="key"&&typeof this.nodeKeyProperty=="string"&&(t+=`, "nodeKeyProperty": `+this.De(this.nodeKeyProperty)),this.copiesArrays&&(t+=`, "copiesArrays": true`),this.copiesArrayObjects&&(t+=`, "copiesArrayObjects": true`),this.copiesKey&&(t+=`, "copiesKey": true`),this.pointsDigits!==100&&(t+=`, "pointsDigits": `+this.pointsDigits.toString()),this.nodeCategoryProperty!=="category"&&typeof this.nodeCategoryProperty=="string"&&(t+=`, "nodeCategoryProperty": `+this.De(this.nodeCategoryProperty)),t}Dy(t){t.name&&(this.name=t.name),t.dataFormat&&(this.dataFormat=t.dataFormat),t.isReadOnly&&(this.isReadOnly=!0),t.nodeKeyProperty&&(this.nodeKeyProperty=t.nodeKeyProperty),t.copiesArrays&&(this.copiesArrays=!0),t.copiesArrayObjects&&(this.copiesArrayObjects=!0),t.copiesKey!==void 0&&(this.copiesKey=t.copiesKey),t.pointsDigits!==void 0&&(this.pointsDigits=parseInt(t.pointsDigits)),t.nodeCategoryProperty&&(this.nodeCategoryProperty=t.nodeCategoryProperty)}JT(){const t=this.modelData;return`, "modelData": `+this.$T(t)}ZT(t){const i=t.modelData;U.G(i)&&(this.replaceJsonObjects(i),this.modelData=i)}IN(){const t=this.modelData;let i=!1;for(const s in t)if(!this.V1(t,s,t[s])){i=!0;break}let e="";return i&&(e=this.JT()),e+`, "nodeDataArray": `+this.Th(this.nodeDataArray,!0)}EN(t){this.ZT(t);const i=t.nodeDataArray;Array.isArray(i)&&(this.replaceJsonObjects(i),this.nodeDataArray=i)}UN(t,i,e){if(t===i)return!0;if(typeof t!=typeof i||U.it(t)||U.it(i))return!1;if(Array.isArray(t)&&Array.isArray(i)){if(e.get(t)===i)return!0;if(e.set(t,i),t.length!==i.length)return!1;for(let s=0;s{const o=n.part;if(!o)return;const r=o.data;if(s===r)return;let l=i.get(s);l===null?(l=new GSet,l.add(r),i.set(s,l)):l.add(r)};return t.changes.each(s=>{if(s.diagram!==null){const n=s.change;if(n===2){const o=s.object.panel;if(o){const r=o.data;r&&e(r,o)}}else if(n===3||n===4){const o=s.object,r=o.itemArray;r&&e(r,o)}}}),i}WT(t){const i=new GSet;for(let e=0;e{if(f.model===s){if(f.modelChange==="nodeDataArray")f.change===3?o.add(f.newValue):f.change===4&&l.add(f.oldValue);else if(s.containsNodeData(f.object))r.add(f.object);else if(f.change===2&&(s.modelData===f.object||f.propertyName==="modelData"))n=!0;else if(f.object!==null)if(e.has(f.object))e.get(f.object).each(d=>{s.containsNodeData(d)&&r.add(d)});else{if(f.object instanceof Model||s.Ra()&&s.containsLinkData(f.object))return;s.WT(f.object).each(d=>{r.add(d)})}}});const h=new GSet;o.each(f=>{h.add(s.getKeyForNodeData(f)),i||r.add(f)});const c=new GSet;l.each(f=>{c.add(s.getKeyForNodeData(f)),i&&r.add(f)});let a="";return n&&(a+=this.JT()),h.count>0&&(a+=(i?Model._T:Model.QT)+this.Th(h.toArray(),!0)),r.count>0&&(a+=Model.qO+this.Th(r.toArray(),!0)),c.count>0&&(a+=(i?Model.QT:Model._T)+this.Th(c.toArray(),!0)),a}Fy(t){(t.name!==void 0&&t.name!==this.name||t.dataFormat!==void 0&&t.dataFormat!==this.dataFormat||t.isReadOnly!==void 0&&t.isReadOnly!==this.isReadOnly||t.nodeKeyProperty!==void 0&&t.nodeKeyProperty!==this.nodeKeyProperty||t.copiesArrays!==void 0&&t.copiesArrays!==this.copiesArrays||t.copiesArrayObjects!==void 0&&t.copiesArrayObjects!==this.copiesArrayObjects||t.copiesKey!==void 0&&t.copiesKey!==this.copiesKey||t.nodeCategoryProperty!==void 0&&t.nodeCategoryProperty!==this.nodeCategoryProperty)&&U.o("applyIncrementalJson cannot change Model properties"),this.ZT(t);const i=t.insertedNodeKeys,e=t.modifiedNodeData,s=new GMap;if(Array.isArray(e))for(let o=0;o1&&s.add(` `);for(let n=0;n0&&(s.add(","),i&&s.add(` `)),s.add(this.writeJsonValue(o)))}return i&&e>1&&s.add(` `),s.add("]"),s.toString()}V1(t,i,e){return!!(e===void 0||i==="__gohashid"||i[0]==="_"||U.it(e))}Yi(t){return isNaN(t)?"NaN":t===1/0?"9e9999":t===-1/0?"-9e9999":t}$T(t){const i=t;if(i instanceof Point)t={class:"go.Point",x:this.Yi(i.x),y:this.Yi(i.y)};else if(i instanceof Size)t={class:"go.Size",width:this.Yi(i.width),height:this.Yi(i.height)};else if(i instanceof Rect)t={class:"go.Rect",x:this.Yi(i.x),y:this.Yi(i.y),width:this.Yi(i.width),height:this.Yi(i.height)};else if(i instanceof Margin)t={class:"go.Margin",top:this.Yi(i.top),right:this.Yi(i.right),bottom:this.Yi(i.bottom),left:this.Yi(i.left)};else if(i instanceof Spot)i.isSpot()?t={class:"go.Spot",x:this.Yi(i.x),y:this.Yi(i.y),offsetX:this.Yi(i.offsetX),offsetY:this.Yi(i.offsetY)}:t={class:"go.Spot",enum:i.toString()};else if(i instanceof Brush){if(t={class:"go.Brush",type:BrushType[i.type]},i.type===1?t.color=i.color:(i.type===2||i.type===3)&&(t.start=i.start,t.end=i.end,i.type===3&&(i.startRadius!==0&&(t.startRadius=this.Yi(i.startRadius)),isNaN(i.endRadius)||(t.endRadius=this.Yi(i.endRadius)))),i.colorStops!==null){const n={},o=i.colorStops.iterator;for(;o.next();){const r=o.key,l=o.value;n[r]=l}t.colorStops=n}}else if(i instanceof Geometry)t={class:"go.Geometry",type:GeometryType[i.type]},i.startX!==0&&(t.startX=this.Yi(i.startX)),i.startY!==0&&(t.startY=this.Yi(i.startY)),i.endX!==0&&(t.endX=this.Yi(i.endX)),i.endY!==0&&(t.endY=this.Yi(i.endY)),i.spot1.equals(Spot.TopLeft)||(t.spot1=i.spot1),i.spot2.equals(Spot.BottomRight)||(t.spot2=i.spot2),i.type===4&&(t.path=Geometry.stringify(i));else if(Model.ON(null,"",i))return"{}";let e="{",s=!0;for(const n in t){const o=this.yt(t,n);if(!this.V1(t,n,o))if(s?s=!1:e+=",",e+=this.De(n)+":",n==="points"&&o instanceof List){const r=o;let l="[";const h=r.iterator;for(;h.next();){const c=h.value;l.length>1&&(l+=","),l+=this.eD(c.x),l+=",",l+=this.eD(c.y)}l+="]",e+=l}else e+=this.writeJsonValue(o)}return e+="}",e}eD(t){if(t===1/0)return"9e9999";if(t===-1/0)return"-9e9999";if(isNaN(t))return"0";const i=this.pointsDigits;return i>16?t.toString():t.toFixed(i)}get pointsDigits(){return this.Ay}set pointsDigits(t){t<0?t=0:t>100&&(t=100),this.Ay=t}Gi(t){return typeof t=="number"?t:t==="NaN"?NaN:t==="9e9999"?1/0:t==="-9e9999"?-1/0:parseFloat(t)}JO(t){if(!U.G(t))return t;let i=t.class||"";if(typeof i!="string"||i==="")return t;if(i==="NaN")return NaN;if(i==="Date")return new Date(t.value);if(i.indexOf("go.")!==0)return t;i=i.substring(3);let e=t;if(i==="Point")e=new Point(this.Gi(t.x),this.Gi(t.y));else if(i==="Size")e=new Size(this.Gi(t.width),this.Gi(t.height));else if(i==="Rect")e=new Rect(this.Gi(t.x),this.Gi(t.y),this.Gi(t.width),this.Gi(t.height));else if(i==="Margin")e=new Margin(this.Gi(t.top),this.Gi(t.right),this.Gi(t.bottom),this.Gi(t.left));else if(i==="Spot")typeof t.enum=="string"?e=Spot.parse(t.enum):e=new Spot(this.Gi(t.x),this.Gi(t.y),this.Gi(t.offsetX),this.Gi(t.offsetY));else if(i==="Brush"){const s=new Brush;s.type=U.Uh(BrushType,t.type)??1,typeof t.color=="string"&&(s.color=t.color),t.start instanceof Spot&&(s.start=t.start),t.end instanceof Spot&&(s.end=t.end),typeof t.startRadius=="number"&&(s.startRadius=this.Gi(t.startRadius)),typeof t.endRadius=="number"&&(s.endRadius=this.Gi(t.endRadius));const n=t.colorStops;if(U.G(n))for(const o in n){const r=parseFloat(o);s.addColorStop(r,n[o])}e=s}else if(i==="Geometry"){let s=null;typeof t.path=="string"?s=Geometry.parse(t.path):s=new Geometry,s.type=U.Uh(GeometryType,t.type)??1,typeof t.startX=="number"&&(s.startX=this.Gi(t.startX)),typeof t.startY=="number"&&(s.startY=this.Gi(t.startY)),typeof t.endX=="number"&&(s.endX=this.Gi(t.endX)),typeof t.endY=="number"&&(s.endY=this.Gi(t.endY)),t.spot1 instanceof Spot&&(s.spot1=t.spot1),t.spot2 instanceof Spot&&(s.spot2=t.spot2),e=s}else if(i==="EnumValue"){let s=t.classType;s.indexOf("go.")===0&&(s=s.substring(3));const n=Model.VN(s);U.it(n)&&(e=U.Uh(n,t.name))}return e}get name(){return this.St}set name(t){const i=this.St;i!==t&&(U.s(t,"string",Model,"name"),this.St=t,this.t("name",i,t))}get dataFormat(){return this.$d}set dataFormat(t){const i=this.$d;i!==t&&(U.s(t,"string",Model,"dataFormat"),this.$d=t,this.t("dataFormat",i,t))}get isReadOnly(){return this.Ao}set isReadOnly(t){const i=this.Ao;i!==t&&(U.s(t,"boolean",Model,"isReadOnly"),this.Ao=t,this.t("isReadOnly",i,t))}get modelData(){return this.RN}set modelData(t){const i=this.modelData;i!==t&&(U.ec(t,Model,"modelData"),this.containsNodeData(t)&&U.o("Model.modelData Object must not be used by the rest of the model: "+t),this.RN=t,this.t("modelData",i,t),this.updateTargetBindings(t))}addChangedListener(t){return U.k(t,Model,"addChangedListener:listener"),this.Ty.push(t),this}removeChangedListener(t){U.k(t,Model,"removeChangedListener:listener");const i=this.Ty.indexOf(t);i>=0&&this.Ty.splice(i,1)}VM(t){this.skipsUndoManager||this.undoManager.handleChanged(t),this.sD(t)}sD(t){this.Ty.forEach(i=>i(t))}dF(t){this.sD(t)}raiseChangedEvent(t,i,e,s,n,o,r){this.vt("",t,i,e,s,n,o,r)}raiseChanged(t,i,e,s,n){this.vt("",2,t,this,i,e,s,n)}t(t,i,e,s,n){this.vt("",2,t,this,i,e,s,n)}raiseDataChanged(t,i,e,s,n,o){this.vt("",2,i,t,e,s,n,o)}vt(t,i,e,s,n,o,r,l){r===void 0&&(r=null),l===void 0&&(l=null);const h=new ChangedEvent;h.model=this,h.change=i,h.modelChange=t,h.propertyName=e,h.object=s,h.oldValue=n,h.oldParam=r,h.newValue=o,h.newParam=l,this.VM(h)}get undoManager(){return this.B1}set undoManager(t){const i=this.B1;i!==t&&(i!==null&&i.removeModel(this),this.B1=t,t!==null&&t.addModel(this))}get skipsUndoManager(){return this.Lo}set skipsUndoManager(t){U.s(t,"boolean",Model,"skipsUndoManager"),this.Lo=t}changeState(t,i){if(t!==null&&t.model===this)if(t.change===2){const e=t.object,s=t.propertyName,n=t.getValue(i);if(s===this.nodeKeyProperty&&this.containsNodeData(e)){const o=t.getValue(!i);o!==void 0&&this.mi.delete(o),n!==void 0&&this.mi.set(n,e)}this.Z(e,s,n)}else if(t.change===3){const e=t.newParam;if(t.modelChange==="nodeDataArray"){const s=t.newValue;if(U.G(s)&&typeof e=="number"){const n=this.getKeyForNodeData(s);i?(this.Te[e]===s&&this.go(this.Te,e),n!==void 0&&this.mi.delete(n)):(this.Te[e]!==s&&this.$o(this.Te,e,s),n!==void 0&&this.mi.set(n,s))}}else if(t.modelChange===""){let s=t.object;if(s&&!Array.isArray(s)&&t.propertyName&&(s=this.yt(s,t.propertyName)),Array.isArray(s)&&typeof e=="number"){const n=t.newValue;i?this.go(s,e):this.$o(s,e,n)}}else U.o("unknown ChangeType.Insert modelChange: "+t.toString())}else if(t.change===4){const e=t.oldParam;if(t.modelChange==="nodeDataArray"){const s=t.oldValue;if(U.G(s)&&typeof e=="number"){const n=this.getKeyForNodeData(s);i?(this.Te[e]!==s&&this.$o(this.Te,e,s),n!==void 0&&this.mi.set(n,s)):(this.Te[e]===s&&this.go(this.Te,e),n!==void 0&&this.mi.delete(n))}}else if(t.modelChange===""){let s=t.object;if(s&&!Array.isArray(s)&&t.propertyName&&(s=this.yt(s,t.propertyName)),Array.isArray(s)&&typeof e=="number"){const n=t.oldValue;i?this.$o(s,e,n):this.go(s,e)}}else U.o("unknown ChangeType.Remove modelChange: "+t.toString())}else t.change===1||U.o("unknown ChangedEvent: "+t.toString())}startTransaction(t){return this.undoManager.startTransaction(t)}commitTransaction(t){return this.undoManager.commitTransaction(t)}rollbackTransaction(){return this.undoManager.rollbackTransaction()}commit(t,i){let e=i;e===void 0&&(e="");const s=this.skipsUndoManager;e===null&&(this.skipsUndoManager=!0,e=""),this.undoManager.startTransaction(e);let n=!1;try{t(this),n=!0}finally{n?this.undoManager.commitTransaction(e):this.undoManager.rollbackTransaction(),this.skipsUndoManager=s}}updateTargetBindings(t,i){i===void 0&&(i=""),this.vt("SourceChanged",1,i,t,null,null)}get nodeKeyProperty(){return this.Ah}set nodeKeyProperty(t){const i=this.Ah;i!==t&&(this.Pn(t,Model,"nodeKeyProperty"),t===""&&U.o("Model.nodeKeyProperty may not be the empty string"),this.mi.count>0&&U.o("Cannot set Model.nodeKeyProperty when there is existing node data"),this.Ah=t,this.t("nodeKeyProperty",i,t))}Pn(t,i,e){typeof t!="string"&&!U.it(t)&&U.Zi(t,"string or function",i,e)}getKeyForNodeData(t){if(t===null)return;const i=this.Ah;if(i==="")return;const e=this.yt(t,i);if(e!==void 0){if(this.isKeyType(e))return e;U.o("Key value for node data "+t+" is not a number or a string: "+e)}}setKeyForNodeData(t,i){if((i==null||!this.isKeyType(i))&&U.Zi(i,"number or string",Model,"setKeyForNodeData:key"),t===null)return;const e=this.Ah;if(e==="")return;if(!this.containsNodeData(t)){this.Z(t,e,i);return}const s=this.yt(t,e);if(s!==i){if(this.findNodeDataForKey(i)!==null)return;this.Z(t,e,i),s!==void 0&&this.mi.delete(s),this.mi.set(i,t),this.vt("nodeKey",2,e,t,s,i),typeof e=="string"&&this.updateTargetBindings(t,e),this.Ry(s,i)}}get makeUniqueKeyFunction(){return this.Df}set makeUniqueKeyFunction(t){const i=this.Df;i!==t&&(t!==null&&U.k(t,Model,"makeUniqueKeyFunction"),this.Df=t,this.t("makeUniqueKeyFunction",i,t))}isKeyType(t){return typeof t=="number"||typeof t=="string"}containsNodeData(t){if(t===null)return!1;const i=this.getKeyForNodeData(t);return i===void 0?!1:this.mi.get(i)===t}findNodeDataForKey(t){return t===null&&U.o("Model.findNodeDataForKey:key must not be null"),t===void 0||!this.isKeyType(t)?null:this.mi.get(t)}get nodeDataArray(){return this.Te}set nodeDataArray(t){const i=this.Te;if(i!==t){this.zN(t,Model,"nodeDataArray"),this.mi.clear(),this.XN();const e=t.length;for(let o=0;o=0||s.indexOf("Tool")>=0||s.indexOf("CommandHandler")>=0||s.indexOf("Layout")>=0}static nD=!1;setDataProperty(t,i,e){if(this.containsNodeData(t)){if(i===this.nodeKeyProperty){this.setKeyForNodeData(t,e);return}else if(i===this.nodeCategoryProperty){this.setCategoryForNodeData(t,e);return}}else!Model.nD&&t instanceof GraphObject&&(Model.nD=!0,U.ni('Model.setDataProperty is modifying a GraphObject, "'+t.toString()+'"'),U.ni(" Is that really your intent?"));const s=this.yt(t,i);s!==e&&(this.Z(t,i,e),this.raiseDataChanged(t,i,s,e))}set(t,i,e){this.setDataProperty(t,i,e)}assignAllDataProperties(t,i){if(!i)return;const e=this.containsNodeData(t);for(const s in i)s!=="__gohashid"&&(e&&s===this.nodeKeyProperty||this.setDataProperty(t,s,i[s]))}addArrayItem(t,i){this.insertArrayItem(t,-1,i)}insertArrayItem(t,i,e){i<0&&(i=t.length),t=this.$o(t,i,e),this.vt("",3,"",t,null,e,null,i)}removeArrayItem(t,i){i===void 0&&(i=-1),t===this.Te&&U.o("Model.removeArrayItem should not be called on the Model.nodeDataArray"),i===-1&&(i=t.length-1);const e=t[i];t=this.go(t,i),this.vt("",4,"",t,e,null,i,null)}get nodeCategoryProperty(){return this.Ka}set nodeCategoryProperty(t){const i=this.Ka;i!==t&&(this.Pn(t,Model,"nodeCategoryProperty"),this.Ka=t,this.t("nodeCategoryProperty",i,t))}getCategoryForNodeData(t){if(t===null)return"";const i=this.Ka;if(i==="")return"";const e=this.yt(t,i);if(e===void 0)return"";if(typeof e=="string")return e;U.o("getCategoryForNodeData found a non-string category for "+t+": "+e)}setCategoryForNodeData(t,i){if(U.s(i,"string",Model,"setCategoryForNodeData:cat"),t===null)return;const e=this.Ka;if(e==="")return;if(!this.containsNodeData(t)){this.Z(t,e,i);return}let s=this.yt(t,e);s===void 0&&(s=""),s!==i&&(this.Z(t,e,i),this.vt("nodeCategory",2,e,t,s,i))}sg(t,i){this.setCategoryForNodeData(i,this.getCategoryForNodeData(t))}get type(){return"Model"}pm(){return!1}mm(){return!1}Mb(){return!1}Ra(){return!1}Xw(){return!1}Hc(){return!1}static LM(){return new Model}yt(t,i){return Model.yt(t,i)}static yt(t,i){if(!t||!i)return null;let e;try{U.it(i)?e=i(t):U.it(t.getAttribute)?(e=t.getAttribute(i),e===null&&(e=void 0)):e=t[i]}catch{}return e}Z(t,i,e){Model.Z(t,i,e)}static Z(t,i,e){if(!(!t||!i)){try{U.it(i)?i(t,e):U.it(t.setAttribute)?t.setAttribute(i,e):t[i]=e}catch{}return t}}zN(t,i,e){Array.isArray(t)||U.Zi(t,"Array",i,e)}iD(t,i,e){return t[i]=e,t}$o(t,i,e){return i>=t.length?t.push(e):t.splice(i,0,e),t}go(t,i){return i>=t.length?t.pop():t.splice(i,1),t}static VN(t){return Model.YN[t]?Model.YN[t]:root.go!==void 0&&root.go[t]?root.go[t]:null}static fl(t,i){Model.YN[i]=t}static YN={}}Model.fromJSON=Model.fromJson=Model.fromJson;Model.fl(Brush,"Brush"),Model.fl(Geometry,"Geometry"),Model.fl(Margin,"Margin"),Model.fl(Point,"Point"),Model.fl(Rect,"Rect"),Model.fl(Size,"Size"),Model.fl(Spot,"Spot"),Model.fl(Model,"Model");class GraphLinksModel extends Model{Ps;Zo;Di;Dh;Rf;vf;Ll;mo;po;ja;Ha;qa;$s;Of;Sn;rg;constructor(t,i,e){if(super(),this.Ps=[],this.Zo=new GSet,this.Di=new GMap,this.Dh="",this.Rf=null,this.vf=null,this.Ll=null,this.mo="from",this.po="to",this.ja="",this.Ha="",this.qa="category",this.$s="",this.Of="isGroup",this.Sn="group",this.rg=!1,i!==void 0&&(this.linkDataArray=i),t!==void 0&&(Array.isArray(t)?this.nodeDataArray=t:e=t),e){Object.assign(this,e);const s=e.Changed;s&&(delete this.Changed,this.addChangedListener(s))}}cloneProtected(t){super.cloneProtected(t),t.Dh=this.Dh,t.Rf=this.Rf,t.vf=this.vf,t.mo=this.mo,t.po=this.po,t.ja=this.ja,t.Ha=this.Ha,t.qa=this.qa,t.$s=this.$s,t.Of=this.Of,t.Sn=this.Sn,t.rg=this.rg}clear(){this.Ps=[],this.Di.clear(),this.Zo.clear(),super.clear()}toString(t){if(t===void 0&&(t=0),t>=2)return this.toJson();{let i=(this.name!==""?this.name:"")+" GraphLinksModel";if(t>0){i+=` node data:`;let e=this.nodeDataArray,s=e.length,n=0;for(n=0;n"+this.Ae(o,!1)}}return i}}vN(t,i,e){if(this.linkKeyProperty===""){const f=this.skipsUndoManager;this.skipsUndoManager=!0,this.linkKeyProperty="key",this.skipsUndoManager=f}let s=super.vN(t,i,e);const n=this,o=new GSet,r=new GSet,l=new GSet;t.changes.each(f=>{if(f.model===n){if(f.modelChange==="linkDataArray")f.change===3?o.add(f.newValue):f.change===4&&l.add(f.oldValue);else if(n.containsLinkData(f.object))r.add(f.object);else if(f.object!==null)if(f.object!==null&&e.has(f.object))e.get(f.object).each(d=>{n.containsLinkData(d)&&r.add(d)});else{if(f.object instanceof Model||n.containsNodeData(f.object))return;n.oD(f.object).each(d=>r.add(d))}}});const h=new GSet;o.each(f=>{h.add(n.getKeyForLinkData(f)),i||r.add(f)});const c=new GSet;l.each(f=>{c.add(n.getKeyForLinkData(f)),i&&r.add(f)});const a=n.cloneDeep(r.toArray());return h.count>0&&(s===null&&(s={}),i?s.removedLinkKeys=h.toArray():s.insertedLinkKeys=h.toArray()),a.length>0&&(s===null&&(s={}),s.modifiedLinkData=a),c.count>0&&(s===null&&(s={}),i?s.insertedLinkKeys=c.toArray():s.removedLinkKeys=c.toArray()),s}eg(){const t=super.eg();let i="";return this.linkCategoryProperty!=="category"&&typeof this.linkCategoryProperty=="string"&&(i+=`, "linkCategoryProperty": `+this.De(this.linkCategoryProperty)),this.linkKeyProperty!==""&&typeof this.linkKeyProperty=="string"&&(i+=`, "linkKeyProperty": `+this.De(this.linkKeyProperty)),this.linkFromKeyProperty!=="from"&&typeof this.linkFromKeyProperty=="string"&&(i+=`, "linkFromKeyProperty": `+this.De(this.linkFromKeyProperty)),this.linkToKeyProperty!=="to"&&typeof this.linkToKeyProperty=="string"&&(i+=`, "linkToKeyProperty": `+this.De(this.linkToKeyProperty)),this.linkFromPortIdProperty!==""&&typeof this.linkFromPortIdProperty=="string"&&(i+=`, "linkFromPortIdProperty": `+this.De(this.linkFromPortIdProperty)),this.linkToPortIdProperty!==""&&typeof this.linkToPortIdProperty=="string"&&(i+=`, "linkToPortIdProperty": `+this.De(this.linkToPortIdProperty)),this.linkLabelKeysProperty!==""&&typeof this.linkLabelKeysProperty=="string"&&(i+=`, "linkLabelKeysProperty": `+this.De(this.linkLabelKeysProperty)),this.nodeIsGroupProperty!=="isGroup"&&typeof this.nodeIsGroupProperty=="string"&&(i+=`, "nodeIsGroupProperty": `+this.De(this.nodeIsGroupProperty)),this.nodeGroupKeyProperty!=="group"&&typeof this.nodeGroupKeyProperty=="string"&&(i+=`, "nodeGroupKeyProperty": `+this.De(this.nodeGroupKeyProperty)),t+i}Dy(t){super.Dy(t),t.linkKeyProperty&&(this.linkKeyProperty=t.linkKeyProperty),t.linkFromKeyProperty&&(this.linkFromKeyProperty=t.linkFromKeyProperty),t.linkToKeyProperty&&(this.linkToKeyProperty=t.linkToKeyProperty),t.linkFromPortIdProperty&&(this.linkFromPortIdProperty=t.linkFromPortIdProperty),t.linkToPortIdProperty&&(this.linkToPortIdProperty=t.linkToPortIdProperty),t.linkCategoryProperty&&(this.linkCategoryProperty=t.linkCategoryProperty),t.linkLabelKeysProperty&&(this.linkLabelKeysProperty=t.linkLabelKeysProperty),t.nodeIsGroupProperty&&(this.nodeIsGroupProperty=t.nodeIsGroupProperty),t.nodeGroupKeyProperty&&(this.nodeGroupKeyProperty=t.nodeGroupKeyProperty)}IN(){const t=super.IN(),i=`, "linkDataArray": `+this.Th(this.linkDataArray,!0);return t+i}EN(t){super.EN(t);const i=t.linkDataArray;Array.isArray(i)&&(this.replaceJsonObjects(i),this.linkDataArray=i)}rD=`, "insertedLinkKeys": `;$O=`, "modifiedLinkData": `;lD=`, "removedLinkKeys": `;oD(t){const i=new GSet;for(let e=0;e{if(f.model===n){if(f.modelChange==="linkDataArray")f.change===3?o.add(f.newValue):f.change===4&&l.add(f.oldValue);else if(n.containsLinkData(f.object))r.add(f.object);else if(f.object!==null)if(f.object!==null&&e.has(f.object))e.get(f.object).each(d=>{n.containsLinkData(d)&&r.add(d)});else{if(f.object instanceof Model||n.containsNodeData(f.object))return;n.oD(f.object).each(d=>r.add(d))}}});const h=new GSet;o.each(f=>{h.add(n.getKeyForLinkData(f)),i||r.add(f)});const c=new GSet;l.each(f=>{c.add(n.getKeyForLinkData(f)),i&&r.add(f)});let a=s;return h.count>0&&(a+=(i?this.lD:this.rD)+this.Th(h.toArray(),!0)),r.count>0&&(a+=this.$O+this.Th(r.toArray(),!0)),c.count>0&&(a+=(i?this.rD:this.lD)+this.Th(c.toArray(),!0)),a}Fy(t){(t.linkCategoryProperty!==void 0&&t.linkCategoryProperty!==this.linkCategoryProperty||t.linkKeyProperty!==void 0&&t.linkKeyProperty!==this.linkKeyProperty||t.linkFromKeyProperty!==void 0&&t.linkFromKeyProperty!==this.linkFromKeyProperty||t.linkToKeyProperty!==void 0&&t.linkToKeyProperty!==this.linkToKeyProperty||t.linkFromPortIdProperty!==void 0&&t.linkFromPortIdProperty!==this.linkFromPortIdProperty||t.linkToPortIdProperty!==void 0&&t.linkToPortIdProperty!==this.linkToPortIdProperty||t.linkLabelKeysProperty!==void 0&&t.linkLabelKeysProperty!==this.linkLabelKeysProperty||t.nodeIsGroupProperty!==void 0&&t.nodeIsGroupProperty!==this.nodeIsGroupProperty||t.nodeGroupKeyProperty!==void 0&&t.nodeGroupKeyProperty!==this.nodeGroupKeyProperty)&&U.o("applyIncrementalJson cannot change Model properties"),super.Fy(t);const i=t.insertedLinkKeys;if(Array.isArray(i)){const n=i.length;for(let o=0;o=0&&this.go(n,e)):n.indexOf(t.newValue)<0&&this.$o(n,e,t.newValue));return}}else if(t.change===4){let e=t.oldParam;if(t.modelChange==="linkDataArray"){const s=t.oldValue;if(U.G(s)&&typeof e=="number"){const n=this.getKeyForLinkData(s);i?(this.Zo.add(s),this.Ps[e]!==s&&this.$o(this.Ps,e,s),n!==void 0&&this.Di.set(n,s)):(this.Zo.delete(s),this.Ps[e]===s&&this.go(this.linkDataArray,e),n!==void 0&&this.Di.delete(n))}return}else if(t.modelChange==="linkLabelKeys"){const s=t.object,n=this.getLabelKeysForLinkData(s);Array.isArray(n)&&typeof e=="number"&&(i?n.indexOf(t.oldValue)<0&&this.$o(n,e,t.oldValue):(e=n.indexOf(t.oldValue),e>=0&&this.go(n,e)));return}}super.changeState(t,i)}}get archetypeNodeData(){return this.Ll}set archetypeNodeData(t){const i=this.Ll;i!==t&&(t!==null&&U.ec(t,GraphLinksModel,"archetypeNodeData"),this.Ll=t,this.t("archetypeNodeData",i,t))}GN(t){if(t===void 0)return;const i=this.Ll;if(i!==null){let e=this.findNodeDataForKey(t);e===null&&(e=this.copyNodeData(i),this.Z(e,this.nodeKeyProperty,t),this.addNodeData(e))}return t}get linkFromKeyProperty(){return this.mo}set linkFromKeyProperty(t){const i=this.mo;i!==t&&(this.Pn(t,GraphLinksModel,"linkFromKeyProperty"),this.mo=t,this.t("linkFromKeyProperty",i,t))}getFromKeyForLinkData(t){return this.Ae(t,!0)}setFromKeyForLinkData(t,i){this.Wd(t,i,!0)}get linkToKeyProperty(){return this.po}set linkToKeyProperty(t){const i=this.po;i!==t&&(this.Pn(t,GraphLinksModel,"linkToKeyProperty"),this.po=t,this.t("linkToKeyProperty",i,t))}getToKeyForLinkData(t){return this.Ae(t,!1)}setToKeyForLinkData(t,i){this.Wd(t,i,!1)}Ae(t,i){if(t===null)return;const e=i?this.mo:this.po;if(e==="")return;const s=this.yt(t,e);if(s!==void 0){if(this.isKeyType(s))return s;U.o((i?"FromKey":"ToKey")+" value for link data "+t+" is not a number or a string: "+s)}}Wd(t,i,e){if(i===null&&(i=void 0),i!==void 0&&!this.isKeyType(i)&&U.Zi(i,"number or string",GraphLinksModel,e?"setFromKeyForLinkData:key":"setToKeyForLinkData:key"),t===null)return;const s=e?this.mo:this.po;if(s==="")return;if(i=this.GN(i),!this.containsLinkData(t)){this.Z(t,s,i);return}const n=this.yt(t,s);n!==i&&(this.Ws(n,t),this.Z(t,s,i),this.findNodeDataForKey(i)===null&&this.Js(i,t),this.vt(e?"linkFromKey":"linkToKey",2,s,t,n,i),typeof s=="string"&&this.updateTargetBindings(t,s))}get linkFromPortIdProperty(){return this.ja}set linkFromPortIdProperty(t){const i=this.ja;i!==t&&(this.Pn(t,GraphLinksModel,"linkFromPortIdProperty"),this.ja=t,this.t("linkFromPortIdProperty",i,t))}getFromPortIdForLinkData(t){return this.I1(t,!0)}setFromPortIdForLinkData(t,i){this.Jd(t,i,!0)}get linkToPortIdProperty(){return this.Ha}set linkToPortIdProperty(t){const i=this.Ha;i!==t&&(this.Pn(t,GraphLinksModel,"linkToPortIdProperty"),this.Ha=t,this.t("linkToPortIdProperty",i,t))}getToPortIdForLinkData(t){return this.I1(t,!1)}setToPortIdForLinkData(t,i){this.Jd(t,i,!1)}I1(t,i){if(t===null)return"";const e=i?this.ja:this.Ha;if(e==="")return"";const s=this.yt(t,e);return s===void 0?"":s}Jd(t,i,e){if(U.s(i,"string",GraphLinksModel,e?"setFromPortIdForLinkData:portname":"setToPortIdForLinkData:portname"),t===null)return;const s=e?this.ja:this.Ha;if(s==="")return;if(!this.containsLinkData(t)){this.Z(t,s,i);return}let n=this.yt(t,s);n===void 0&&(n=""),n!==i&&(this.Z(t,s,i),this.vt(e?"linkFromPortId":"linkToPortId",2,s,t,n,i),typeof s=="string"&&this.updateTargetBindings(t,s))}get linkLabelKeysProperty(){return this.$s}set linkLabelKeysProperty(t){const i=this.$s;i!==t&&(this.Pn(t,GraphLinksModel,"linkLabelKeysProperty"),this.$s=t,this.t("linkLabelKeysProperty",i,t))}getLabelKeysForLinkData(t){if(t===null)return GraphLinksModel.EmptyArray;const i=this.$s;if(i==="")return GraphLinksModel.EmptyArray;const e=this.yt(t,i);return e===void 0?GraphLinksModel.EmptyArray:e}setLabelKeysForLinkData(t,i){if(this.zN(i,GraphLinksModel,"setLabelKeysForLinkData:arr"),t===null)return;const e=this.$s;if(e==="")return;if(!this.containsLinkData(t)){this.Z(t,e,i);return}let s=this.yt(t,e);if(s===void 0&&(s=GraphLinksModel.EmptyArray),s!==i){if(Array.isArray(s)){const o=s.length;for(let r=0;r=0)return;n=s.length,s.push(i),this.containsLinkData(t)&&(this.findNodeDataForKey(i)===null&&this.Js(i,t),this.vt("linkLabelKeys",3,e,t,null,i,null,n))}else U.o(e+" property is not an Array; cannot addLabelKeyForLinkData: "+t)}removeLabelKeyForLinkData(t,i){if(i==null||(this.isKeyType(i)||U.Zi(i,"number or string",GraphLinksModel,"removeLabelKeyForLinkData:key"),t===null))return;const e=this.$s;if(e==="")return;const s=this.yt(t,e);if(Array.isArray(s)){const n=s.indexOf(i);if(n<0)return;this.go(s,n),this.containsLinkData(t)&&(this.Ws(i,t),this.vt("linkLabelKeys",4,e,t,i,null,n,null))}else s!==void 0&&U.o(e+" property is not an Array; cannot removeLabelKeyforLinkData: "+t)}get linkDataArray(){return this.Ps}set linkDataArray(t){const i=this.Ps;if(i!==t){this.zN(t,GraphLinksModel,"linkDataArray"),this.Di.clear();const e=t.length;for(let n=0;nnew GraphLinksModel;Model.LM=()=>new GraphLinksModel;class TreeModel extends Model{Mn;lg;Wa;constructor(t,i){if(super(),this.Mn="parent",this.lg=!1,this.Wa="parentLinkCategory",t!==void 0&&(Array.isArray(t)?this.nodeDataArray=t:i=t),i){Object.assign(this,i);const e=i.Changed;e&&(delete this.Changed,this.addChangedListener(e))}}cloneProtected(t){super.cloneProtected(t),t.Mn=this.Mn,t.lg=this.lg,t.Wa=this.Wa}toString(t){if(t===void 0&&(t=0),t>=2)return this.toJson();{let i=(this.name!==""?this.name:"")+" TreeModel";if(t>0){i+=` node data:`;const e=this.nodeDataArray,s=e.length;for(let n=0;n(y[y.ConstantSpacing=0]="ConstantSpacing",y[y.ConstantDistance=1]="ConstantDistance",y[y.ConstantAngle=2]="ConstantAngle",y[y.Packed=3]="Packed",y))(CircularArrangement||{}),CircularDirection=(y=>(y[y.Clockwise=10]="Clockwise",y[y.Counterclockwise=11]="Counterclockwise",y[y.BidirectionalLeft=12]="BidirectionalLeft",y[y.BidirectionalRight=13]="BidirectionalRight",y))(CircularDirection||{}),CircularSorting=(y=>(y[y.Forwards=20]="Forwards",y[y.Reverse=21]="Reverse",y[y.Ascending=22]="Ascending",y[y.Descending=23]="Descending",y[y.Optimized=24]="Optimized",y))(CircularSorting||{}),CircularNodeDiameterFormula=(y=>(y[y.Pythagorean=30]="Pythagorean",y[y.Circular=31]="Circular",y))(CircularNodeDiameterFormula||{});class CircularLayout extends Layout{le;If;K1;hg;j1;Fh;HN;qN;WN;Ss;Oy;Iy;Ja;Ey;aD;ag;cg;fg;Ef;Xi;b;pe;ye;kn;ug;constructor(t){super(),this.le=0,this.If=0,this.K1=0,this.hg=360,this.j1=0,this.Fh=0,this.HN=new Point,this.qN=30,this.WN=0,this.Ss=0,this.Oy=0,this.Iy=new VertexArrangement,this.Ja=0,this.Ey=0,this.aD=600,this.ag=NaN,this.cg=1,this.fg=0,this.Ef=360,this.Xi=0,this.b=10,this.pe=24,this.ye=LayoutVertex.standardComparer,this.kn=6,this.ug=30,t&&Object.assign(this,t)}cloneProtected(t){super.cloneProtected(t),t.ag=this.ag,t.cg=this.cg,t.fg=this.fg,t.Ef=this.Ef,t.Xi=this.Xi,t.b=this.b,t.pe=this.pe,t.ye=this.ye,t.kn=this.kn,t.ug=this.ug}oi(t){t in CircularSorting?this.sorting=t:t in CircularDirection?this.direction=t:t in CircularArrangement?this.arrangement=t:t in CircularNodeDiameterFormula?this.nodeDiameterFormula=t:super.oi(t)}createNetwork(){return new CircularNetwork(this)}_O(t,i,e){t=this.tI(t);let s=this.j1,n=this.qN,o=this.le,r=this.If,l=this.K1,h=this.hg,c=this.Fh,a=this.WN,f=this.Ss,u=this.Oy;if(s=this.arrangement,n=this.nodeDiameterFormula,o=this.radius,(!isFinite(o)||o<=0)&&(o=NaN),r=this.aspectRatio,(!isFinite(r)||r<=0)&&(r=1),l=this.startAngle,isFinite(l)||(l=0),h=this.sweepAngle,(!isFinite(h)||h>360||h<1)&&(h=360),c=this.spacing,isFinite(c)||(c=NaN),s===3&&n===31?s=0:s===3&&n!==31&&(n=31,s=this.arrangement),(this.direction===12||this.direction===13)&&this.sorting!==24){for(let g=0;!(g>=t.length||(i.add(t.elt(g)),g+1>=t.length));g+=2)e.add(t.elt(g+1));this.direction===12?(this.arrangement===3&&i.reverse(),t=new List,t.addAll(i),t.addAll(e)):(this.arrangement===3&&e.reverse(),t=new List,t.addAll(e),t.addAll(i))}const d=t.length;a=0;let m=0;for(let g=0;g1?(o=w,f=o*r):(f=w,o=f)}else o=this.H1(u*(h>=360?d:d-1),r,l*Math.PI/180,h*Math.PI/180)}else o=this.H1(a+(h>=360?d:d-1)*(s!==3?c:c*1.6),r,l*Math.PI/180,h*Math.PI/180);f=o*r}else{f=o*r;const g=this.JN(o,f,l*Math.PI/180,h*Math.PI/180);if(isNaN(c))s===0&&(c=(g-a)/(h>=360?d:d-1));else if(s===0){const p=(g-a)/(h>=360?d:d-1);p=360?d:d-1),r,l*Math.PI/180,h*Math.PI/180),f=o*r):c=p}else{let p=-1/0;for(let k=0;k=360?d:d-1),r,l*Math.PI/180,h*Math.PI/180);x>o?(o=x,f=o*r,u=w):u=g/(h>=360?d:d-1)}}return this.j1=s,this.qN=n,this.le=o,this.If=r,this.K1=l,this.hg=h,this.Fh=c,this.WN=a,this.Ss=f,this.Oy=u,t}doLayout(t){this.network===null&&(this.network=this.makeNetwork(t)),this.arrangementOrigin=this.initialOrigin(this.arrangementOrigin);const i=this.network.vertexes;if(i.count<=1){if(i.count===1){const u=i.first();u.centerX=0,u.centerY=0}this.updateParts(),this.network=null,this.isValidLayout=!0;return}let e=new List;e.addAll(i.iterator);const s=new List,n=new List;e=this._O(e,s,n);const o=this.j1,r=this.le,l=this.K1,h=this.hg,c=this.Fh,a=this.Ss,f=this.Oy;if((this.direction===12||this.direction===13)&&o===3)this.cD(e,h,l-h/2,10);else if(this.direction===12||this.direction===13){let u=0;switch(o){case 1:u=this.q1(r,a,l,f)*180/Math.PI;break;case 0:{let d=0,m=0;const g=s.first();g!==null&&(d=g.Rh(Math.PI/2));const p=n.first();p!==null&&(m=p.Rh(Math.PI/2)),u=this.q1(r,a,l,c+(d+m)/2)*180/Math.PI;break}case 2:u=h/e.length;break}if(this.direction===12){switch(o){case 1:this.Uy(s,h/2,l,11);break;case 0:this.By(s,h/2,l,11);break;case 2:this.Vy(s,h/2,l,11);break}switch(o){case 1:this.Uy(n,h/2,l+u,10);break;case 0:this.By(n,h/2,l+u,10);break;case 2:this.Vy(n,h/2,l+u,10);break}}else{switch(o){case 1:this.Uy(n,h/2,l,11);break;case 0:this.By(n,h/2,l,11);break;case 2:this.Vy(n,h/2,l,11);break}switch(o){case 1:this.Uy(s,h/2,l+u,10);break;case 0:this.By(s,h/2,l+u,10);break;case 2:this.Vy(s,h/2,l+u,10);break}}}else switch(o){case 1:this.Uy(e,h,l,this.direction);break;case 0:this.By(e,h,l,this.direction);break;case 2:this.Vy(e,h,l,this.direction);break;case 3:this.cD(e,h,l,this.direction);break}this.updateParts(),this.network=null,this.isValidLayout=!0}Vy(t,i,e,s){const n=this.hg,o=this.le,r=this.Ss,l=e*Math.PI/180,h=i*Math.PI/180,c=t.length;for(let a=0;a=360?c:c-1):-(a*h)/c),u=t.elt(a),d=o*Math.tan(f)/r,m=Math.sqrt((o*o+r*r*d*d)/(1+d*d));u.centerX=m*Math.cos(f),u.centerY=m*Math.sin(f),u.actualAngle=f*180/Math.PI}}By(t,i,e,s){const n=this.le,o=this.Ss,r=this.Fh;let l=e*Math.PI/180;const h=t.length;for(let c=0;c180&&(n-=360),n*=Math.PI/180,this.Ey=n,this.fD(t,i,e,s)}else this.uD(t,i,e,s);this.Iy.commit(t)}uD(t,i,e,s){const n=this.le,o=this.Ss,r=this.Fh,l=this.If;let h=n*Math.cos(e*Math.PI/180),c=o*Math.sin(e*Math.PI/180);const a=t.toArray();if(a.length===3){a[0].centerX=n,a[0].centerY=0,a[1].centerX=a[0].centerX-a[0].width/2-a[1].width/2-r,a[1].y=a[0].y,a[2].centerX=(a[0].centerX+a[1].centerX)/2,a[2].y=a[0].y-a[2].height-r;return}else if(a.length===4){a[0].centerX=n,a[0].centerY=0,a[2].centerX=-a[0].centerX,a[2].centerY=a[0].centerY,a[1].centerX=0,a[1].y=Math.min(a[0].y,a[2].y)-a[1].height-r,a[3].centerX=0,a[3].y=Math.max(a[0].y+a[0].height+r,a[2].y+a[2].height+r);return}const f=Point.l();for(let b=0;b=a.length-1));b++)this.dD(h,c,a,b,s,f)||this.gD(h,c,a,b,s,f),h=f.x,c=f.y;if(Point.e(f),this.Ja++,this.Ja>23)return;const u=a[0].centerX,d=a[0].centerY,m=a[a.length-1].centerX,g=a[a.length-1].centerY;let p=Math.abs(u-m)-((a[0].width+a[a.length-1].width)/2+r);const w=Math.abs(d-g)-((a[0].height+a[a.length-1].height)/2+r);let x=0;if(Math.abs(w)<1){const b=Math.abs(u-m),P=(a[0].width+a[a.length-1].width)/2;b0?x=w:Math.abs(p)<1?x=0:x=p;let k=!1;Math.abs(m)>Math.abs(g)?k=m>0!=d>g:k=g>0!=u1&&(this.Ja<8?this.le-=x/(2*Math.PI):a.length<5&&x>10?this.le/=2:this.le-=x>0?1.7:-2.3,this.Ss=this.le*l,this.uD(t,i,e,s))}fD(t,i,e,s){const n=this.le,o=this.Ss,r=this.If;let l=n*Math.cos(e*Math.PI/180),h=o*Math.sin(e*Math.PI/180);const c=Point.l(),a=t.toArray();for(let m=0;m=a.length-1));m++)this.dD(l,h,a,m,s,c)||this.gD(l,h,a,m,s,c),l=c.x,h=c.y;if(Point.e(c),this.Ja++,this.Ja>23)return;const f=Math.atan2(h,l);let u=s===10?this.Ey-f:f-this.Ey;u=Math.abs(u)1&&(this.Ja<8?this.le-=d/(2*Math.PI):this.le-=d>0?1.7:-2.3,this.Ss=this.le*r,this.fD(t,i,e,s))}dD(t,i,e,s,n,o){const r=this.Fh,l=this.le,h=this.Ss;let c=0,a=0;const f=(e[s].width+e[s+1].width)/2+r;let u=!1;if(i>=0!=(n===10)){if(c=t+f,c>l){if(c=t-f,c<-l)return o.x=c,o.y=a,!1;u=!0}}else if(c=t-f,c<-l){if(c=t+f,c>l)return o.x=c,o.y=a,!1;u=!0}return a=Math.sqrt(1-Math.min(1,c*c/(l*l)))*h,i<0!==u&&(a=-a),Math.abs(i-a)>(e[s].height+e[s+1].height)/2?(o.x=c,o.y=a,!1):(o.x=c,o.y=a,!0)}gD(t,i,e,s,n,o){const r=this.Fh,l=this.le,h=this.Ss;let c=0,a=0;const f=(e[s].height+e[s+1].height)/2+r;let u=!1;if(t>=0!=(n===10)){if(a=i-f,a<-h){if(a=i+f,a>h)return o.x=c,o.y=a,!1;u=!0}}else if(a=i+f,a>h){if(a=i-f,a<-h)return o.x=c,o.y=a,!1;u=!0}return c=Math.sqrt(1-Math.min(1,a*a/(h*h)))*l,t<0!==u&&(c=-c),Math.abs(t-c)>(e[s].width+e[s+1].width)/2?(o.x=c,o.y=a,!1):(o.x=c,o.y=a,!0)}commitLayout(){this.commitNodes(),this.isRouting&&this.commitLinks()}commitNodes(){const t=this.group!==null&&this.group.hasPlaceholder(),i=t?this.group.location.copy():null;let e=this.actualCenter;t?e=new Point(0,0):(e.x=this.arrangementOrigin.x+this.le,e.y=this.arrangementOrigin.y+this.Ss);const s=this.network.vertexes.iterator;for(;s.next();){const n=s.value;n.x+=e.x,n.y+=e.y,n.commit()}if(t){this.group.ensureBounds();const n=this.group.position.copy(),o=this.group.location.copy(),r=i.subtract(o.subtract(n));this.group.move(r),this.HN=r.subtract(n)}}commitLinks(){const t=this.network.edges.iterator;for(;t.next();)t.value.commit()}JN(t,i,e,s){const n=this.aD;if(Math.abs(this.If-1)<.001)return e!==void 0&&s!==void 0?s*t:2*Math.PI*t;const o=t>i?Math.sqrt(t*t-i*i)/t:Math.sqrt(i*i-t*t)/i;let r=0,l=0;e!==void 0&&s!==void 0?l=s/(n+1):l=Math.PI/(2*(n+1));let h=0;for(let c=0;c<=n;c++){e!==void 0&&s!==void 0?h=e+c*s/n:h=c*Math.PI/(2*n);const a=Math.sin(h);r+=Math.sqrt(1-o*o*a*a)*l}return e!==void 0&&s!==void 0?(t>i?t:i)*r:4*(t>i?t:i)*r}H1(t,i,e,s){let n=0;return e!==void 0&&s!==void 0?n=this.JN(1,i,e,s):n=this.JN(1,i),t/n}q1(t,i,e,s){if(Math.abs(this.If-1)<.001)return s/t;const n=t>i?Math.sqrt(t*t-i*i)/t:Math.sqrt(i*i-t*t)/i;let o=0;const r=2*Math.PI/(this.network.vertexes.count*700);t>i&&(e+=Math.PI/2);for(let l=0;;l++){const h=e+l*r,c=Math.sin(h);if(o+=(t>i?t:i)*Math.sqrt(1-n*n*c*c)*r,o>=s)return l*r}}tI(t){switch(this.sorting){case 20:break;case 21:t.reverse();break;case 22:t.sort(this.comparer);break;case 23:t.sort(this.comparer),t.reverse();break;case 24:return this.sI(this.nI(t));default:U.o("Invalid sorting type.")}return t}nI(t){const i=[];for(let s=0;sn&&(n=u,o=a)}else for(let a=0;an&&(n=f,o=a)}e.add(t.elt(o)),i[o]=-1;const r=t.elt(o);let l=0;const h=r.sourceEdges;for(;h.next();){const f=h.value.fromVertex;l=t.indexOf(f),!(l<0)&&i[l]>=0&&i[l]++}const c=r.destinationEdges;for(;c.next();){const f=c.value.toVertex;l=t.indexOf(f),!(l<0)&&i[l]>=0&&i[l]++}}return e}sI(t){const i=[];for(let f=0;f=0){const C=Math.abs(x-(L>=x?L+1:L));b+=C=x&&S++,L>=x&&L++,S>L){const C=L;L=S,S=C}L-S<(s.length+2)/2==(S=0&&(n.push(f),o.push(x))}h++}let c=!1;const a=s.length;for(;;){c=!0;for(let f=0;f=0){let g=0;for(let p=0;pm?x-m:m-x,b=a-k;g+=xb?1:-1}s.splice(g<0?m:m+1,0,u),r.splice(f,1),f--}else c=!1}if(c)break;s.push(r[0]),r.splice(0,1)}for(let f=0;f0||isNaN(t))&&(this.ag=t,this.invalidateLayout()))}get aspectRatio(){return this.cg}set aspectRatio(t){this.cg!==t&&(U.s(t,"number",CircularLayout,"aspectRatio"),t>0&&(this.cg=t,this.invalidateLayout()))}get startAngle(){return this.fg}set startAngle(t){this.fg!==t&&(U.s(t,"number",CircularLayout,"startAngle"),this.fg=t,this.invalidateLayout())}get sweepAngle(){return this.Ef}set sweepAngle(t){this.Ef!==t&&(U.s(t,"number",CircularLayout,"sweepAngle"),t>0&&t<=360?this.Ef=t:this.Ef=360,this.invalidateLayout())}get arrangement(){return this.Xi}set arrangement(t){this.Xi!==t&&(t===3||t===0||t===1||t===2)&&(this.Xi=t,this.invalidateLayout())}get direction(){return this.b}set direction(t){this.b!==t&&(t===10||t===11||t===12||t===13)&&(this.b=t,this.invalidateLayout())}get sorting(){return this.pe}set sorting(t){this.pe!==t&&(this.pe=t,this.invalidateLayout())}get comparer(){return this.ye}set comparer(t){this.ye!==t&&(U.k(t,CircularLayout,"comparer"),this.ye=t,this.invalidateLayout())}get spacing(){return this.kn}set spacing(t){this.kn!==t&&(U.s(t,"number",CircularLayout,"spacing"),this.kn=t,this.invalidateLayout())}get nodeDiameterFormula(){return this.ug}set nodeDiameterFormula(t){this.ug!==t&&(t===30||t===31)&&(this.ug=t,this.invalidateLayout())}get actualXRadius(){return this.le}get actualYRadius(){return this.Ss}get actualSpacing(){return this.Fh}get actualCenter(){return this.HN}static ConstantSpacing=0;static ConstantDistance=1;static ConstantAngle=2;static Packed=3;static Clockwise=10;static Counterclockwise=11;static BidirectionalLeft=12;static BidirectionalRight=13;static Forwards=20;static Reverse=21;static Ascending=22;static Descending=23;static Optimized=24;static Pythagorean=30;static Circular=31}class VertexArrangement{Uf;$a;Bf;constructor(){this.Uf=-1/0,this.$a=null,this.Bf=null}iI(t,i){if(t>0&&this.Uf<0||Math.abs(t)0)){this.Uf=t,this.$a=[],this.Bf=[];for(let e=0;e0){for(this.network.deleteSelfEdges(),i=this.network.vertexes.iterator;i.next();){const o=i.value;o.charge=this.electricalCharge(o),o.mass=this.gravitationalMass(o)}const s=this.network.edges.iterator;for(;s.next();){const o=s.value;o.stiffness=this.springStiffness(o),o.length=this.springLength(o)}if(this.$N(),this.vh=0,this.needsPrelayout()){const o=this.network,r=o.splitIntoSubNetworks(!1);let l=r.iterator;for(;l.next();){const h=l.value;this.doConnectedSubnetLayout(h)}for(l=r.iterator,this.rI(l,o),l=r.iterator;l.next();){const h=l.value,c=h.vertexes.iterator;for(;c.next();){const f=c.value;o.addVertex(f)}const a=h.edges.iterator;for(;a.next();){const f=a.value;o.addEdge(f)}}}else this.mD(this.network,this.maxIterations);this.updateParts()}this.maxIterations=e,this.isValidLayout=!0}needsPrelayout(){if(this.network===null||this.network.vertexes.count<3)return!1;let t=0,i=0;const e=this.network.vertexes.first().bounds,s=this.network.vertexes.iterator;for(;s.next();){const n=s.value,o=n.bounds;if(isNaN(n.x)||isNaN(n.y)||o.intersectsRect(e)&&(t++,t>2))return!0;if(i>10)return!1;i++}return!1}doConnectedSubnetLayout(t){let i=t.vertexes.iterator;for(;i.next();){const l=i.value;l.hierarchicalVertexes.add(l)}let e=t,s=this.Kf;if(isNaN(s)&&(s=t.edges.count/t.vertexes.count),sMath.max(100,Math.sqrt(s*t.vertexes.count));)e=this.coarsenNetwork(e);let n=0;i=e.vertexes.iterator;let o=this.randomNumberGenerator;for(o===null&&(this.randomNumberGenerator=o=new RandomNumberGenerator(0));i.next();){i.value.idInCluster=n++;const l=10*(o.random()-.5),h=10*(o.random()-.5);this.isFixed(i.value)||(i.value.x=l,i.value.y=h);const c=i.value.hierarchicalVertexes.iterator;for(;c.next();)this.isFixed(c.value)||(c.value.x=l,c.value.y=h)}const r=this.computePairwiseDistances(e);this.lI(e,r,this.maxPrelayoutIterations,t.vertexes.count),this.mD(t,this.maxIterations)}computePairwiseDistances(t){const i=t.vertexes.count,e=new Array(i);for(let r=0;r0;){const l=o.shift(),h=l.vertexes.iterator;for(;h.next();){const c=h.value;n.has(c.idInCluster)||(n.set(c.idInCluster,n.get(l.idInCluster)+1),o.push(c))}}for(let l=0;l=0;m--)if(t[m].y>a.y&&t[m].x-a.xa.x&&t[m].y-a.yc+f){const u=s+o-h,d=n-c-f;return Geo.Pw(u*u+d*d)}else if(n+rh+a)if(n>c+f){const u=s-h-a,d=n-c-f;return Geo.Pw(u*u+d*d)}else if(n+rc+f?n-(c+f):n+rr-o;l?i.sort((m,g)=>m===null||g===null||m===g?0:m.centerX-g.centerX):i.sort((m,g)=>m===null||g===null||m===g?0:m.centerY-g.centerY);const h=this.Vf;let c=0,a=0,f=0;for(let m=0;mh||C-x>h){if(l)break;continue}if(k-M>h||M-k>h){if(!l)break;continue}const N=this.yD(g,P),T=2*g.charge,A=2*P.charge;if(N>1)c=T*A/(N*N),a=c*(x-C)/N,f=c*(k-M)/N;else{let D=this.randomNumberGenerator;D===null&&(this.randomNumberGenerator=D=new RandomNumberGenerator(0));const F=D.random(),v=D.random();if(x>C)a=Math.abs(P.bounds.right-g.bounds.x),a=T*A*(1+a)*F;else if(xM)f=Math.abs(P.bounds.bottom-g.bounds.y),f=T*A*(1+f)*v;else if(x1&&(c=.1*m.stiffness*(M-m.length),a=c*.5*(g.width+p.height)*(k-L)/M,f=c*.5*(g.width+p.height)*(b-C)/M),g.forceX-=a,g.forceY-=f,p.forceX+=a,p.forceY+=f}let d=0;for(let m=0;mthis.epsilonDistance*this.epsilonDistance}lI(t,i,e,s){const n=this.vh+e,o=Math.sqrt(s);this.zy=this.Za*t.vertexes.count;const r=t.vertexes.toArray();let l=0,h=0,c=0;for(;this.vh0){r[a].forceX=this.zy*r[a].forceX/f,r[a].forceY=this.zy*r[a].forceY/f,this.isFixed(r[a])||(r[a].x+=r[a].forceX,r[a].y+=r[a].forceY);const u=r[a].hierarchicalVertexes.iterator;for(;u.next();){const d=u.value;this.isFixed(d)||(d.centerX+=r[a].forceX,d.centerY+=r[a].forceY)}}l+=f*f}if(l>=h){if(c++,c>=5)break}else c=0;this.zy*=.95}}moveVertex(t){let i=t.forceX,e=t.forceY;const s=this.moveLimit;return i<-s?i=-s:i>s&&(i=s),e<-s?e=-s:e>s&&(e=s),t.centerX+=i,t.centerY+=e,i*i+e*e}shouldInteract(t,i){return!0}moveFixedVertex(t){}commitLayout(){this.Xy(),this.commitNodes(),this.isRouting&&this.commitLinks()}Xy(){if(!this.setsPortSpots)return;const t=this.network.edges.iterator;for(;t.next();){const e=t.value.link;e!==null&&(e.fromSpot=Spot.Default,e.toSpot=Spot.Default)}}commitNodes(){let t=0,i=0;if(this.arrangesToOrigin){const n=Rect.l();this.Lw(this.network,n);const o=this.arrangementOrigin;t=o.x-n.x,i=o.y-n.y,Rect.e(n)}const e=Rect.l(),s=this.network.vertexes.iterator;for(;s.next();){const n=s.value;(t!==0||i!==0)&&(e.a(n.bounds),e.x+=t,e.y+=i,n.bounds=e),n.commit()}Rect.e(e)}commitLinks(){const t=this.network.edges.iterator;for(;t.next();)t.value.commit()}springStiffness(t){const i=t.stiffness;return isNaN(i)?this.zf:i}springLength(t){const i=t.length;return isNaN(i)?this.Xf:i}electricalCharge(t){const i=t.charge;return isNaN(i)?this.Yf:i}electricalFieldX(t,i){return 0}electricalFieldY(t,i){return 0}gravitationalMass(t){const i=t.mass;return isNaN(i)?this.Gf:i}gravitationalFieldX(t,i){return 0}gravitationalFieldY(t,i){return 0}isFixed(t){return t.isFixed}get currentIteration(){return this.vh}get arrangementSpacing(){return this.Ms}set arrangementSpacing(t){this.Ms.equals(t)||(this.Ms.a(t),this.invalidateLayout())}get arrangesToOrigin(){return this.dg}set arrangesToOrigin(t){this.dg!==t&&(U.s(t,"boolean",ForceDirectedLayout,"arrangesToOrigin"),this.dg=t,this.invalidateLayout())}get setsPortSpots(){return this.Nn}set setsPortSpots(t){this.Nn!==t&&(U.s(t,"boolean",ForceDirectedLayout,"setsPortSpots"),this.Nn=t,this.invalidateLayout())}get comments(){return this.Fe}set comments(t){this.Fe!==t&&(U.s(t,"boolean",ForceDirectedLayout,"comments"),this.Fe=t,this.invalidateLayout())}get maxPrelayoutIterations(){return this.gg}set maxPrelayoutIterations(t){this.gg!==t&&(U.s(t,"number",ForceDirectedLayout,"maxPrelayoutIterations"),t>=0&&(this.gg=t,this.invalidateLayout()))}get maxIterations(){return this.mg}set maxIterations(t){this.mg!==t&&(U.s(t,"number",ForceDirectedLayout,"maxIterations"),t>=0&&(this.mg=t,this.invalidateLayout()))}get epsilonDistance(){return this.pg}set epsilonDistance(t){this.pg!==t&&(U.s(t,"number",ForceDirectedLayout,"epsilonDistance"),t>0&&(this.pg=t,this.invalidateLayout()))}get infinityDistance(){return this.Vf}set infinityDistance(t){this.Vf!==t&&(U.s(t,"number",ForceDirectedLayout,"infinityDistance"),t>1&&(this.Vf=t,this.invalidateLayout()))}get moveLimit(){return this.yg}set moveLimit(t){this.yg!==t&&(U.s(t,"number",ForceDirectedLayout,"moveLimit"),this.yg=t,this.invalidateLayout())}get randomNumberGenerator(){return this.wg}set randomNumberGenerator(t){this.wg!==t&&(t!==null&&!U.it(t.random)&&U.o('ForceDirectedLayout.randomNumberGenerator must have a "random()" function on it: '+t),this.wg=t)}get defaultSpringStiffness(){return this.zf}set defaultSpringStiffness(t){this.zf!==t&&(U.s(t,"number",ForceDirectedLayout,"defaultSpringStiffness"),this.zf=t,this.invalidateLayout())}get defaultSpringLength(){return this.Xf}set defaultSpringLength(t){this.Xf!==t&&(U.s(t,"number",ForceDirectedLayout,"defaultSpringLength"),this.Xf=t,this.invalidateLayout())}get defaultElectricalCharge(){return this.Yf}set defaultElectricalCharge(t){this.Yf!==t&&(U.s(t,"number",ForceDirectedLayout,"defaultElectricalCharge"),this.Yf=t,this.invalidateLayout())}get defaultGravitationalMass(){return this.Gf}set defaultGravitationalMass(t){this.Gf!==t&&(U.s(t,"number",ForceDirectedLayout,"defaultGravitationalMass"),this.Gf=t,this.invalidateLayout())}get defaultCommentSpringLength(){return this.xg}set defaultCommentSpringLength(t){this.xg!==t&&(U.s(t,"number",ForceDirectedLayout,"defaultCommentSpringLength"),this.xg=t,this.invalidateLayout())}get defaultCommentElectricalCharge(){return this.bg}set defaultCommentElectricalCharge(t){this.bg!==t&&(U.s(t,"number",ForceDirectedLayout,"defaultCommentElectricalCharge"),this.bg=t,this.invalidateLayout())}get prelayoutQuality(){return this.Kf}set prelayoutQuality(t){this.Kf!==t&&(U.s(t,"number",ForceDirectedLayout,"prelayoutQuality"),this.Kf=t,this.invalidateLayout())}get prelayoutSpread(){return this.Za}set prelayoutSpread(t){this.Za!==t&&(U.s(t,"number",ForceDirectedLayout,"prelayoutSpread"),this.Za=t,this.invalidateLayout())}}class ForceDirectedNetwork extends LayoutNetwork{constructor(t){super(t)}createVertex(){return new ForceDirectedVertex(this)}createEdge(){return new ForceDirectedEdge(this)}}class ForceDirectedVertex extends LayoutVertex{J1;$1;Z1;Q1;_1;hierarchicalVertexes;idInCluster;constructor(t){super(t),this.J1=!1,this.$1=NaN,this.Z1=NaN,this.Q1=0,this._1=0,this.hierarchicalVertexes=new List,this.idInCluster=-1}get isFixed(){return this.J1}set isFixed(t){this.J1!==t&&(U.s(t,"boolean",ForceDirectedVertex,"isFixed"),this.J1=t)}get charge(){return this.$1}set charge(t){this.$1!==t&&(U.s(t,"number",ForceDirectedVertex,"charge"),this.$1=t)}get mass(){return this.Z1}set mass(t){this.Z1!==t&&(U.s(t,"number",ForceDirectedVertex,"mass"),this.Z1=t)}get forceX(){return this.Q1}set forceX(t){this.Q1!==t&&(U.s(t,"number",ForceDirectedVertex,"forceX"),this.Q1=t)}get forceY(){return this._1}set forceY(t){this._1!==t&&(U.s(t,"number",ForceDirectedVertex,"forceY"),this._1=t)}}class ForceDirectedEdge extends LayoutEdge{tk;ik;constructor(t){super(t),this.tk=NaN,this.ik=NaN}get stiffness(){return this.tk}set stiffness(t){this.tk!==t&&(U.s(t,"number",ForceDirectedEdge,"stiffness"),this.tk=t)}get length(){return this.ik}set length(t){this.ik!==t&&(U.s(t,"number",ForceDirectedEdge,"length"),this.ik=t)}}class RandomNumberGenerator{I;R;Q;M;A;seed;constructor(t){t===void 0&&(t=42),this.seed=t,this.A=48271,this.M=2147483647,this.Q=this.M/this.A,this.R=this.M%this.A,this.I=1/this.M,this.random()}random(){const t=this.seed/this.Q,i=this.seed%this.Q,e=this.A*i-this.R*t;return e>0?this.seed=e:this.seed=e+this.M,this.seed*this.I}}var LayeredDigraphCycleRemove=(y=>(y[y.DepthFirst=0]="DepthFirst",y[y.Greedy=1]="Greedy",y[y.FromLayers=2]="FromLayers",y))(LayeredDigraphCycleRemove||{}),LayeredDigraphLayering=(y=>(y[y.OptimalLinkLength=10]="OptimalLinkLength",y[y.LongestPathSink=11]="LongestPathSink",y[y.LongestPathSource=12]="LongestPathSource",y))(LayeredDigraphLayering||{}),LayeredDigraphInit=(y=>(y[y.DepthFirstOut=20]="DepthFirstOut",y[y.DepthFirstIn=21]="DepthFirstIn",y[y.Naive=22]="Naive",y))(LayeredDigraphInit||{}),LayeredDigraphAggressive=(y=>(y[y.None=30]="None",y[y.Less=31]="Less",y[y.More=32]="More",y))(LayeredDigraphAggressive||{}),LayeredDigraphPack=(y=>(y[y.None=0]="None",y[y.Expand=1]="Expand",y[y.Straighten=2]="Straighten",y[y.Median=4]="Median",y[y.MaybeExpand=8]="MaybeExpand",y[y.All=15]="All",y))(LayeredDigraphPack||{}),LayeredDigraphAlign=(y=>(y[y.None=0]="None",y[y.UpperLeft=1]="UpperLeft",y[y.UpperRight=2]="UpperRight",y[y.LowerLeft=4]="LowerLeft",y[y.LowerRight=8]="LowerRight",y[y.All=15]="All",y))(LayeredDigraphAlign||{});class LayeredDigraphLayout extends Layout{Ns;Wi;b;jf;Hf;qf;Qa;Wf;Qo;Jf;Nn;kt;Yy;zt;kg;Cs;ci;Zs;Ls;As;It;Pg;_a;Sg;Qs;$f;_o;Cn;Ln;ZN;constructor(t){super(),this.Ns=25,this.Wi=25,this.b=0,this.jf=0,this.Hf=10,this.qf=20,this.Qa=4,this.Wf=31,this.Qo=15,this.Jf=10,this.Nn=!0,this.kt=-1,this.Yy=-1,this.zt=-1,this.kg=0,this.Cs=0,this.ci=null,this.Zs=null,this.Ls=null,this.As=null,this.It=null,this.Pg=0,this._a=null,this.Sg=null,this.Qs=0,this.$f=null,this._o=new Point,this.Cn=[],this.Cn.length=100,this.Ln=15,this.ZN=0,t&&Object.assign(this,t)}cloneProtected(t){super.cloneProtected(t),t.Ns=this.Ns,t.Wi=this.Wi,t.b=this.b,t.jf=this.jf,t.Hf=this.Hf,t.qf=this.qf,t.Qa=this.Qa,t.Wf=this.Wf,t.Qo=this.Qo,t.Jf=this.Jf,t.Nn=this.Nn,t.Ln=this.Ln}oi(t){t in LayeredDigraphAggressive?this.aggressiveOption=t:t in LayeredDigraphCycleRemove?this.cycleRemoveOption=t:t in LayeredDigraphInit?this.initializeOption=t:t in LayeredDigraphLayering?this.layeringOption=t:super.oi(t)}createNetwork(){return new LayeredDigraphNetwork(this)}doLayout(t){this.network===null&&(this.network=this.makeNetwork(t)),this.arrangementOrigin=this.initialOrigin(this.arrangementOrigin),this.aI(),this.network.vertexes.count>0&&(this.network.deleteSelfEdges(),this.cycleRemoveOption!==2&&this.removeCycles(),this.cI(),this.cycleRemoveOption===2&&this.removeCycles(),this.fI(),this.uI(),this.dI(),this.reduceCrossings(),this.straightenAndPack(),this.updateParts()),this.network=null,this.isValidLayout=!0}linkMinLength(t){return 1}linkLengthWeight(t){return 1}linkStraightenWeight(t){const i=t.fromVertex.node||t.fromVertex.data,e=t.toVertex.node||t.toVertex.data;return i===null&&e===null?8:i===null||e===null?4:1}nodeMinLayerSpace(t,i){return t.node===null&&t.data===null?0:this.b===90||this.b===270?i?t.focus.y+10:t.bounds.height-t.focus.y+10:i?t.focus.x+10:t.bounds.width-t.focus.x+10}nodeMinColumnSpace(t,i){if(t.node===null&&t.data===null)return 0;const e=i?t.ek:t.sk;if(e!==null)return e;const s=this.b;return s===90||s===270?i?t.ek=t.focus.x/this.Wi+1|0:t.sk=(t.bounds.width-t.focus.x)/this.Wi+1|0:i?t.ek=t.focus.y/this.Wi+1|0:t.sk=(t.bounds.height-t.focus.y)/this.Wi+1|0}Ji(){this._a===null&&(this._a=[]);let t=0;const i=this.network.vertexes.iterator;for(;i.next();){const e=i.value;this._a[t]=e.layer,t++,this._a[t]=e.column,t++,this._a[t]=e.index,t++}return this._a}We(t){let i=0;const e=this.network.vertexes.iterator;for(;e.next();){const s=e.value;s.layer=t[i],i++,s.column=t[i],i++,s.index=t[i],i++}}wD(t,i){const e=this.Oh(t),s=this.ci[t];(this.Sg===null||this.Sg.length=0){for(a=e[o].fo,f=0;fk||d===k&&g>P)&&r++,bd||k===d&&P>g)&&r++)}if(i<=0){for(a=e[o].Wo,f=0;fk||d===k&&m>b)&&r++,Pd||k===d&&b>m)&&r++)}for(n[o*s+o]=r,c=o+1;c=0){for(p=e[o].fo,S=e[c].fo,f=0;f=0&&(h=s[r].Wo);let c,a=0,f=0;if(l!==null)for(let u=0;u=0&&(h=r.Wo);let c=0,a=0;const f=r.near;f!==null&&f.layer===r.layer&&(c+=f.column-1,a++);let u;if(l!==null)for(let d=0;d=0&&(h=r.Wo);let c=0;const a=[],f=r.near;f!==null&&f.layer===r.layer&&(a[c]=f.column-1,c++);let u;if(l!==null)for(let d=0;dm-g);const d=c>>1;c&1?n[o]=a[d]:n[o]=a[d-1]+a[d]>>1}}return this.Ih(t,e),n}jy(t,i,e,s,n){if(t.component===e){t.component=i;let o=0,r=0;if(s){const l=t.destinationEdges;for(;l.next();){const h=l.value,c=h.toVertex;o=t.layer-c.layer,r=this.linkMinLength(h),o===r&&this.jy(c,i,e,s,n)}}if(n){const l=t.sourceEdges;for(;l.next();){const h=l.value,c=h.fromVertex;o=c.layer-t.layer,r=this.linkMinLength(h),o===r&&this.jy(c,i,e,s,n)}}}}QN(t,i,e,s,n){if(t.component===e){if(t.component=i,s){const o=t.destinationEdges;for(;o.next();){const l=o.value.toVertex;this.QN(l,i,e,s,n)}}if(n){const o=t.sourceEdges;for(;o.next();){const l=o.value.fromVertex;this.QN(l,i,e,s,n)}}}}removeCycles(){const t=this.network.edges.iterator;for(;t.next();){const i=t.value;i.rev=!1}switch(this.jf){default:case 1:this.mI();break;case 0:this.pI();break;case 2:this.yI();break}}yI(){const t=this.network,i=t.vertexes.iterator;let e=1/0;for(;i.next();){const s=i.value;e=Math.min(e,s.layer)}if(e<1/0){if(e<0)for(i.reset();i.next();){const r=i.value;r.layer-=e}const s=[];for(i.reset();i.next();){const r=i.value,l=s[r.layer];l===void 0?s[r.layer]=[r]:l.push(r)}let n=0;for(let r=0;r0)for(let h=0;hh.index&&(t.reverseEdge(r),r.rev=!0)}}wI(t){const i=t.vertexes.iterator;for(;i.next();){const e=i.value;if(e.$i)return e}return null}bD(t){const i=t.vertexes.iterator;for(;i.next();){const e=i.value;if(e.$i){let s=!0;const n=e.destinationEdges;for(;n.next();)if(n.value.toVertex.$i){s=!1;break}if(s)return e}}return null}kD(t){const i=t.vertexes.iterator;for(;i.next();){const e=i.value;if(e.$i){let s=!0;const n=e.sourceEdges;for(;n.next();)if(n.value.fromVertex.$i){s=!1;break}if(s)return e}}return null}xI(t){let i=null,e=0;const s=this.network.vertexes.iterator;for(;s.next();){const n=s.value;if(n.$i){let o=0;const r=n.destinationEdges;for(;r.next();)r.value.toVertex.$i&&o++;let l=0;const h=n.sourceEdges;for(;h.next();)h.value.fromVertex.$i&&l++;(i===null||ea&&this.jy(h,e,-1,!0,!1)}for(this.jy(t,s,-1,!0,!0);t.component!==e;){let r=0,l=1/0,h=0,c=null;const a=this.network.vertexes.iterator;for(;a.next();){const f=a.value;if(f.component===s){let u=0,d=!1;const m=f.fo;o=m.length;for(let p=0;p0){for(i.reset();i.next();){const f=i.value;f.component===s&&(f.layer+=l)}t.component=e}else c.component=e}}MI(t){const i=this.network.vertexes.iterator;for(;i.next();){const n=i.value;n.component=-1}const e=0,s=1;for(this.jy(t,s,-1,!0,!1);t.component!==e;){let n=0,o=1/0,r=0,l=null;const h=this.network.vertexes.iterator;for(;h.next();){const c=h.value;if(c.component===s){let a=0,f=!1;const u=c.fo;let d=u.length;for(let g=0;gr)&&!f&&(l=c,r=a)}}if(n<0){for(i.reset();i.next();){const c=i.value;c.component===s&&(c.layer-=o)}t.component=e}else l.component=e}}fI(){const t=this.network,i=[],e=t.edges.iterator;for(;e.next();){const s=e.value;s.valid=!1,i.push(s)}for(let s=0;sb&&f>0){for(n.valid=!1,w=t.createVertex(),w.node=null,w.ok=2,w.layer=f-1,x&&kb&&f>0;)w=t.createVertex(),w.node=null,w.ok=3,w.layer=f-1,x&&kt[this.Cs]&&(this.Yy=t[e]-1,this.Cs=e),t[e]{o.index=this.ci[s],this.ci[s]++})}}AI(){let t=null;const i=this.network.vertexes.iterator;for(;i.next();){const e=i.value;if(e.near&&(t===null&&(t=new Map),e.layer===e.near.layer)){const s=t.get(e.near)||[];s.push(e),t.set(e.near,s)}}for(let e=this.kt;e>=0;e--)for(i.reset();i.next();){const s=i.value;s.layer===e&&s.index===-1&&this.AD(s,t)}}AD(t,i){if(t.near)return;const e=t.layer;if(t.index=this.ci[e],this.ci[e]++,i){const o=i.get(t);Array.isArray(o)&&o.forEach(r=>{r.index=this.ci[e],this.ci[e]++})}const s=t.Wo;let n=!0;for(;n;){n=!1;for(let o=0;ol.portFromColOffset&&(n=!0,s[o]=l,s[o+1]=r)}}for(let o=0;o{c.index=this.ci[e],this.ci[e]++})}const s=t.fo;let n=!0,o=0;for(;n;)for(n=!1,o=0;oc.portToColOffset&&(n=!0,s[o]=c,s[o+1]=h)}let r,l;for(o=0;o=0;s--)this.lk(s,-1),this.rs(s,-1,!1,-1);n=this.countCrossings(),n=0;s--)this.lk(s,0),this.rs(s,0,!1,0);n=this.countCrossings(),n=0;r--)for(l=0;l<=r;l++){for(o=!0;o;)for(o=!1,s=r;s>=l;s--)o=this.rs(s,-1,!1,-1)||o;for(n=this.countCrossings(),n>=t?this.We(i):(t=n,i=this.Ji()),o=!0;o;)for(o=!1,s=r;s>=l;s--)o=this.rs(s,1,!1,1)||o;for(n=this.countCrossings(),n>=t?this.We(i):(t=n,i=this.Ji()),o=!0;o;)for(o=!1,s=l;s<=r;s++)o=this.rs(s,1,!1,1)||o;for(n>=t?this.We(i):(t=n,i=this.Ji()),o=!0;o;)for(o=!1,s=l;s<=r;s++)o=this.rs(s,-1,!1,-1)||o;for(n>=t?this.We(i):(t=n,i=this.Ji()),o=!0;o;)for(o=!1,s=r;s>=l;s--)o=this.rs(s,0,!1,0)||o;for(n>=t?this.We(i):(t=n,i=this.Ji()),o=!0;o;)for(o=!1,s=l;s<=r;s++)o=this.rs(s,0,!1,0)||o;n>=t?this.We(i):(t=n,i=this.Ji())}break;default:case 31:for(r=this.kt,l=0,h=t+1;(c=this.countCrossings())=l;s--)o=this.rs(s,-1,!1,-1)||o;for(n=this.countCrossings(),n>=t?this.We(i):(t=n,i=this.Ji()),o=!0;o;)for(o=!1,s=r;s>=l;s--)o=this.rs(s,1,!1,1)||o;for(n=this.countCrossings(),n>=t?this.We(i):(t=n,i=this.Ji()),o=!0;o;)for(o=!1,s=l;s<=r;s++)o=this.rs(s,1,!1,1)||o;for(n>=t?this.We(i):(t=n,i=this.Ji()),o=!0;o;)for(o=!1,s=l;s<=r;s++)o=this.rs(s,-1,!1,-1)||o;for(n>=t?this.We(i):(t=n,i=this.Ji()),o=!0;o;)for(o=!1,s=r;s>=l;s--)o=this.rs(s,0,!1,0)||o;for(n>=t?this.We(i):(t=n,i=this.Ji()),o=!0;o;)for(o=!1,s=l;s<=r;s++)o=this.rs(s,0,!1,0)||o;n>=t?this.We(i):(t=n,i=this.Ji())}break}this.We(i)}lk(t,i){let e=0,s=!1;const n=this.Oh(t),o=this.ci[t],r=this.xD(t,i),l=this.Ky(t,i);for(e=0;e0)for(h=[],l=0;ll+1&&(m+=4*(R-l),g+=4*(R-(l+1)))}}const E=n[l].destinationEdges.iterator;if(e&&s>=0)for(;E.next();){const W=E.value;O=W.toVertex,W.valid&&O.layer!==t&&(N=this.linkStraightenWeight(W),T=W.portFromColOffset,A=W.portToColOffset,F=O.column,C+=(Math.abs(p+T-(F+A))+1)*N,M+=(Math.abs(L+T-(F+A))+1)*N)}for(E.reset();E.next();){const W=E.value;if(O=W.toVertex,W.valid&&O.layer===t){for(X=0;Xl+1&&(m+=4*(R-(l+1)),g+=4*(R-l))}}const B=n[l+1].destinationEdges.iterator;if(e&&s>=0)for(;B.next();){const W=B.value;O=W.toVertex,W.valid&&O.layer!==t&&(N=this.linkStraightenWeight(W),T=W.portFromColOffset,A=W.portToColOffset,F=O.column,C+=(Math.abs(w+T-(F+A))+1)*N,M+=(Math.abs(S+T-(F+A))+1)*N)}for(B.reset();B.next();){const W=B.value;if(O=W.toVertex,W.valid&&O.layer===t){for(X=0;X1e3&&s&&(e=!1),e){const n=[];let o=0;for(o=0;o<=this.kt;o++)n[o]=0;let r=0;const l=this.network.vertexes.iterator;for(;l.next();){const c=l.value;t=c.layer,r=c.column;const a=this.nodeMinColumnSpace(c,!1);n[t]=Math.max(n[t],r+a)}const h=8;for(l.reset();l.next();){const c=l.value;t=c.layer,r=c.column,c.column=((this.zt-n[t])*h>>1)+r*h}this.zt*=h}if(this.Qo&2){i=!0;let n=0;for(;i&&n=0;t--)i=this.Mg(t,-1)||i;i=this.Mg(this.Cs,0)||i,n++}}if(this.Qo&4){for(t=this.Cs+1;t<=this.kt;t++)this.tC(t,1);for(t=this.Cs-1;t>=0;t--)this.tC(t,-1);this.tC(this.Cs,0)}if(e&&(this.DD(-1),this.DD(1)),this.Qo&2){i=!0;let n=0;for(;i&&n=0;t--)i=this.Mg(t,0)||i;n++}}}Mg(t,i){let e=!1;for(;this.FI(t,i);)e=!0;return e}FI(t,i){let e=0;const s=this.Oh(t),n=this.ci[t],o=this.Ky(t,-1);if(i>0)for(e=0;ea+this.nodeMinColumnSpace(s[e-1],!1)?u=c-1:u=c;let d=0;e+1>=n||s[e+1].column-c-1>f+this.nodeMinColumnSpace(s[e+1],!0)?d=c+1:d=c;let m=0,g=0,p=0,w=0,x=0,k=0;if(i<=0){const M=s[e].sourceEdges.iterator;for(;M.next();){const N=M.value,T=N.fromVertex;if(N.valid&&T.layer!==t){w=this.linkStraightenWeight(N),x=N.portFromColOffset,k=N.portToColOffset;const A=T.column;m+=(Math.abs(c+k-(A+x))+1)*w,g+=(Math.abs(u+k-(A+x))+1)*w,p+=(Math.abs(d+k-(A+x))+1)*w}}}if(i>=0){const M=s[e].destinationEdges.iterator;for(;M.next();){const N=M.value,T=N.toVertex;if(N.valid&&T.layer!==t){w=this.linkStraightenWeight(N),x=N.portFromColOffset,k=N.portToColOffset;const A=T.column;m+=(Math.abs(c+x-(A+k))+1)*w,g+=(Math.abs(u+x-(A+k))+1)*w,p+=(Math.abs(d+x-(A+k))+1)*w}}}let b=0,P=0,S=0;const L=o[s[e].index],C=r[s[e].index];L!==-1&&(b+=Math.abs(L-c),P+=Math.abs(L-u),S+=Math.abs(L-d)),C!==-1&&(b+=Math.abs(C-c),P+=Math.abs(C-u),S+=Math.abs(C-d)),g=r[e]?u=p:g<=r[e]&&(u=g)),u!==c&&(l=!0,h=!0,s[e].column=u)}return this.Ih(t,s),this.Gy(),l}RI(){for(let t=0;t<=this.zt;t++)for(;this.vI(t,1););this.Gy()}vI(t,i){let e=!0;const s=this.network.vertexes.iterator;for(;s.next();){const o=s.value,r=this.nodeMinColumnSpace(o,!0),l=this.nodeMinColumnSpace(o,!1);if(o.column-r<=t&&o.column+l>=t){e=!1;break}}let n=!1;if(e){if(i>0)for(s.reset();s.next();){const o=s.value;o.column>t&&(o.column-=1,n=!0)}if(i<0)for(s.reset();s.next();){const o=s.value;o.column0&&(e=t+1),i<0&&(e=t-1);let s=0;const n=[],o=[];for(s=0;s<=this.kt;s++)n[s]=!1,o[s]=!1;const r=this.network.vertexes.iterator;for(;r.next();){const c=r.value,a=c.column-this.nodeMinColumnSpace(c,!0),f=c.column+this.nodeMinColumnSpace(c,!1);a<=t&&f>=t&&(n[c.layer]=!0),a<=e&&f>=e&&(o[c.layer]=!0)}let l=!0,h=!1;for(s=0;s<=this.kt;s++)l=l&&!(n[s]&&o[s]);if(l){if(i>0)for(r.reset();r.next();){const c=r.value;c.column>t&&(c.column-=1,h=!0)}if(i<0)for(r.reset();r.next();){const c=r.value;c.column0)for(i=0;i<=this.zt;i++)for(e=this.Ji(),s=this.nk(!0),n=s+1;ss?this.We(e):o=0;i--)for(e=this.Ji(),s=this.nk(!0),n=s+1;ss?this.We(e):o0)for(e.reset();e.next();){const a=e.value;a.column-this.nodeMinColumnSpace(a,!0)<=t&&(a.component=this.Qs)}if(i<0)for(e.reset();e.next();){const a=e.value;a.column+this.nodeMinColumnSpace(a,!1)>=t&&(a.component=this.Qs)}for(this.Qs++,e.reset();e.next();){const a=e.value;a.component===-1&&(this.QN(a,this.Qs,-1,!0,!0),this.Qs++)}let s=0;const n=[];for(s=0;s0)for(let f=0;f0;f--)o[a*(this.zt+1)+f]!==-1&&o[a*(this.zt+1)+f-1]!==-1&&o[a*(this.zt+1)+f]!==o[a*(this.zt+1)+f-1]&&(n[o[a*(this.zt+1)+f]*this.Qs+o[a*(this.zt+1)+f-1]]=!0)}const r=[];for(s=0;s0)for(e.reset();e.next();){const a=e.value;r[a.component]&&(a.column-=1,c=!0)}if(i<0)for(e.reset();e.next();){const a=e.value;r[a.component]&&(a.column+=1,c=!0)}return c}DI(){const t=U.et(),i=this.$f.length;for(let u=0;u<=i;u++)t[u]=[];const e=this.network.vertexes.iterator;for(;e.next();){const u=e.value,d=i-u.layer,m=t[d];m[u.index]=u}const s=new GSet;this.EI(t,s);let n=null,o=null,r=null,l=null;const h=(this.Ln&1)!==0,c=(this.Ln&2)!==0,a=(this.Ln&4)!==0,f=(this.Ln&8)!==0;h&&(this.tl(t,s,!0),n=this.hk(t,!0,!1)),t.reverse(),a&&(this.tl(t,s,!1),r=this.hk(t,!1,!1));for(const u of t)u.reverse();f&&(this.tl(t,s,!1),l=this.hk(t,!1,!0)),t.reverse(),c&&(this.tl(t,s,!0),o=this.hk(t,!0,!0)),U.J(t),this.UI(n,o,r,l),this.network.vertexes.each(u=>{const d=u,m=U.et();h&&m.push(n.get(d)),c&&m.push(o.get(d)),a&&m.push(r.get(d)),f&&m.push(l.get(d)),m.sort((k,b)=>k-b);const g=m.length,p=Math.floor((g-1)/2),w=Math.ceil((g-1)/2),x=(m[p]+m[w])/2;U.J(m),d.he=x})}EI(t,i){const e=t.length;for(let s=1;sf)&&i.add(m)}o++}n=f}}}}BI(t){if(t.node===null){const i=t.getProperSourceVertexes();if(i.length>0)return i[0].node===null}return!1}tl(t,i,e){this.VI(t);for(const s of t){let n=-1;for(const o of s){const r=e?o.getProperSourceVertexes():o.getProperDestinationVertexes(),l=r.length;if(l>0){r.sort((c,a)=>c.Eh-a.Eh);const h=(l-1)/2;for(let c=Math.floor(h),a=Math.ceil(h);c<=a;c++)if(o.An===o){const f=r[c];let u;e?u=f.getDestinationEdge(o):u=o.getDestinationEdge(f),!i.has(u)&&n0){const a=this.OD(c,t),f=s?a.width:a.height,u=c.Je.Qf+c.he+c.Tn-(a.he+a.Tn+f+this.columnSpacing);a.Je.Qf=Math.min(a.Je.Qf,u)}h=c.Eh+1}while(l0){const s=this.OD(e,i),n=s.tc;this.vD(n,i),t.Je===t&&(t.Je=n.Je);const o=this.b===90||this.b===270?s.width:s.height;if(t.Je===n.Je){const r=n.he+s.Tn+o-e.Tn+this.columnSpacing;t.he=Math.max(t.he,r)}}e=e.An}while(e!==t);for(;e.An!==t;)e=e.An,e.he=t.he,e.Je=t.Je}OD(t,i){const e=t.RD,s=t.Eh;return s<1&&U.o("Could not determine previous vertex in layer"),i[e][s-1]}UI(...t){let i=-1;const e=U.et(),s=U.et();let n=1/0;for(let o=0;o<4;o++){if(!t[o])continue;const r=this.XI(t[o],e,s,o);r{r.set(h.key,h.value+l)})}U.J(e),U.J(s)}XI(t,i,e,s){if(!t||t.count===0)return i[s]=0,e[s]=0,1/0;let n=1/0,o=-1/0;return t.each(r=>{const l=r.key,h=r.value,c=this.b===90||this.b===270?l.width:l.height;ho&&(o=h+c)}),i[s]=n,e[s]=o,o-n}commitLayout(){this.Xy(),this.commitNodes(),this.iC(),this.isRouting&&this.commitLinks()}Xy(){if(!this.setsPortSpots)return;const t=this.rk(!0),i=this.rk(!1),e=this.network.edges.iterator;for(;e.next();){const n=e.value.link;n!==null&&(n.fromSpot=t,n.toSpot=i)}}rk(t){return this.b===270?t?Spot.MiddleTop:Spot.MiddleBottom:this.b===90?t?Spot.MiddleBottom:Spot.MiddleTop:this.b===180?t?Spot.MiddleLeft:Spot.MiddleRight:t?Spot.MiddleRight:Spot.MiddleLeft}commitNodes(){this.Zs=[],this.Ls=[],this.As=[],this.It=[];for(let d=0;d<=this.kt;d++)this.Zs[d]=0,this.Ls[d]=0,this.As[d]=0,this.It[d]=0;const t=this.network.vertexes.iterator;for(;t.next();){const d=t.value,m=d.layer;this.Zs[m]=Math.max(this.Zs[m],this.nodeMinLayerSpace(d,!0)),this.Ls[m]=Math.max(this.Ls[m],this.nodeMinLayerSpace(d,!1))}let i=0;const e=this.Ns;for(let d=0;d<=this.kt;d++){let m=e;this.Zs[d]+this.Ls[d]<=0&&(m=0),d>0&&(i+=m/2),this.b===90||this.b===0?(i+=this.Ls[d],this.As[d]=i,i+=this.Zs[d]):(i+=this.Zs[d],this.As[d]=i,i+=this.Ls[d]),d=0;n--)this.b===270?n===0?e.push(new Rect(0,0,s,Math.abs(this.It[0]))):e.push(new Rect(0,this.It[n-1],s,Math.abs(this.It[n-1]-this.It[n]))):this.b===90?n===0?e.push(new Rect(0,this.It[0],s,Math.abs(this.It[0]-t))):e.push(new Rect(0,this.It[n],s,Math.abs(this.It[n-1]-this.It[n]))):this.b===180?n===0?e.push(new Rect(0,0,Math.abs(this.It[0]),s)):e.push(new Rect(this.It[n-1],0,Math.abs(this.It[n-1]-this.It[n]),s)):n===0?e.push(new Rect(this.It[0],0,Math.abs(this.It[0]-t),s)):e.push(new Rect(this.It[n],0,Math.abs(this.It[n-1]-this.It[n]),s));this.commitLayers(e,this._o)}commitLayers(t,i){}commitLinks(){const t=this.network.edges.iterator;let i;for(;t.next();)i=t.value.link,i!==null&&(i.startRoute(),i.clearPoints(),i.commitRoute());for(t.reset();t.next();)i=t.value.link,i!==null&&i.updateRoute();for(t.reset();t.next();){const e=t.value;if(i=e.link,i===null||i.pointsCount===0)continue;i.startRoute();const s=i;let n=s.fromNode,o=s.toNode,r=s.fromPort,l=s.toPort;if(n!==null){const N=n.findVisibleNode();N!==null&&N!==n&&(n=N,r=N.port)}if(o!==null){const N=o.findVisibleNode();N!==null&&N!==o&&(o=N,l=N.port)}const h=i.computeSpot(!0,r),c=i.computeSpot(!1,l);let a=e.fromVertex,f=e.toVertex;if(e.valid){if(i.curve===9&&i.pointsCount===4)if(a.column===f.column&&this.alignOption===0){const N=i.getLinkPoint(n,r,h,!0,!1,o,l),T=i.getLinkPoint(o,l,c,!1,!1,n,r);N.isReal()||N.set(n.actualBounds.center),T.isReal()||T.set(o.actualBounds.center),i.clearPoints(),i.addPointAt(N.x,N.y),i.addPointAt((2*N.x+T.x)/3,(2*N.y+T.y)/3),i.addPointAt((N.x+2*T.x)/3,(N.y+2*T.y)/3),i.addPointAt(T.x,T.y)}else{let N=!1,T=!1;if(r!==null&&h===Spot.None&&(N=!0),l!==null&&c===Spot.None&&(T=!0),N||T){let A=null;N&&(A=i.getLinkPointFromPoint(n,r,r.getDocumentPoint(Spot.Center),i.getPoint(3),!0),A.isReal()||A.set(n.actualBounds.center),i.setPointAt(0,A.x,A.y));let D=null;if(T&&(D=i.getLinkPointFromPoint(o,l,l.getDocumentPoint(Spot.Center),i.getPoint(0),!1),D.isReal()||D.set(o.actualBounds.center),i.setPointAt(3,D.x,D.y)),A){const F=i.getPoint(2);i.setPointAt(1,(A.x*2+F.x)/3,(A.y*2+F.y)/3)}if(D){const F=i.getPoint(1);i.setPointAt(2,(D.x*2+F.x)/3,(D.y*2+F.y)/3)}}}i.commitRoute();continue}if(a.layer===f.layer){i.commitRoute();continue}let u=!1,d=!1;const m=this.Ns;let g=0,p=i.firstPickIndex+1;if(i.isOrthogonal)d=!0,g=i.pointsCount,g>4&&i.points.removeRange(2,g-3);else if(i.curve===9)u=!0,g=i.pointsCount,g>4&&i.points.removeRange(2,g-3),g===4&&(p=2);else{g=i.pointsCount;const N=h===Spot.None,T=c===Spot.None;g>2&&N&&T?i.points.removeRange(1,g-2):g>3&&N&&!T?i.points.removeRange(1,g-3):g>3&&!N&&T?i.points.removeRange(2,g-2):g>4&&!N&&!T&&i.points.removeRange(2,g-3)}let w,x,k=0,b=0,P=0,S=0,L=0,C=0,M=0;if(e.rev){let N=0;for(;f!==null&&a!==f;){w=null,x=null;const T=f.sourceEdges.iterator;for(;T.next();){const A=T.value;if(A.link===e.link&&(w=A.fromVertex,x=A.toVertex,w.node===null))break}if(w===null)break;if(w!==a)if(k=i.getPoint(p-1).x,b=i.getPoint(p-1).y,P=w.centerX,S=w.centerY,d)this.b===180||this.b===0?p===i.firstPickIndex+1?(i.insertPointAt(p++,k,b),i.insertPointAt(p++,k,S)):(x!==null?x.centerY:b)!==S&&(L=this.It[w.layer-1]+this._o.x,i.insertPointAt(p++,L,b),i.insertPointAt(p++,L,S)):p===i.firstPickIndex+1?(i.insertPointAt(p++,k,b),i.insertPointAt(p++,P,b)):(x!==null?x.centerX:k)!==P&&(L=this.It[w.layer-1]+this._o.y,i.insertPointAt(p++,k,L),i.insertPointAt(p++,P,L));else if(p===i.firstPickIndex+1)if(C=Math.max(10,this.Zs[f.layer]),M=Math.max(10,this.Ls[f.layer]),u)this.b===180?P<=f.bounds.x?(N=f.bounds.x,i.insertPointAt(p++,N-C,S),i.insertPointAt(p++,N,S),i.insertPointAt(p++,N+M,S)):(i.insertPointAt(p++,P-C,S),i.insertPointAt(p++,P,S),i.insertPointAt(p++,P+M,S)):this.b===90?S>=f.bounds.bottom?(N=f.bounds.y+f.bounds.height,i.insertPointAt(p++,P,N+M),i.insertPointAt(p++,P,N),i.insertPointAt(p++,P,N-C)):(i.insertPointAt(p++,P,S+M),i.insertPointAt(p++,P,S),i.insertPointAt(p++,P,S-C)):this.b===270?S<=f.bounds.y?(N=f.bounds.y,i.insertPointAt(p++,P,N-C),i.insertPointAt(p++,P,N),i.insertPointAt(p++,P,N+M)):(i.insertPointAt(p++,P,S-C),i.insertPointAt(p++,P,S),i.insertPointAt(p++,P,S+M)):this.b===0&&(P>=f.bounds.right?(N=f.bounds.x+f.bounds.width,i.insertPointAt(p++,N+M,S),i.insertPointAt(p++,N,S),i.insertPointAt(p++,N-C,S)):(i.insertPointAt(p++,P+M,S),i.insertPointAt(p++,P,S),i.insertPointAt(p++,P-C,S)));else{i.insertPointAt(p++,k,b);let A=0;this.b===180||this.b===0?((this.b===180?P>=f.bounds.right:P<=f.bounds.x)&&(A=(this.b===0?-C:M)/2),i.insertPointAt(p++,k+A,S)):((this.b===270?S>=f.bounds.bottom:S<=f.bounds.y)&&(A=(this.b===90?-C:M)/2),i.insertPointAt(p++,P,b+A)),i.insertPointAt(p++,P,S)}else C=Math.max(10,this.Zs[w.layer]),M=Math.max(10,this.Ls[w.layer]),u?this.b===180?(i.insertPointAt(p++,P-C-m,S),i.insertPointAt(p++,Math.min(P-C+m/2,P),S),i.insertPointAt(p++,P,S),i.insertPointAt(p++,P,S),i.insertPointAt(p++,Math.max(P+M-m/2,P),S),i.insertPointAt(p++,P+M+m,S)):this.b===90?(i.insertPointAt(p++,P,S+M+m),i.insertPointAt(p++,P,Math.max(S+M-m/2,S)),i.insertPointAt(p++,P,S),i.insertPointAt(p++,P,S),i.insertPointAt(p++,P,Math.min(S-C+m/2,S)),i.insertPointAt(p++,P,S-C-m)):this.b===270?(i.insertPointAt(p++,P,S-C-m),i.insertPointAt(p++,P,Math.min(S-C+m/2,S)),i.insertPointAt(p++,P,S),i.insertPointAt(p++,P,S),i.insertPointAt(p++,P,Math.max(S+M-m/2,S)),i.insertPointAt(p++,P,S+M+m)):(i.insertPointAt(p++,P+M+m,S),i.insertPointAt(p++,Math.max(P+M-m/2,P),S),i.insertPointAt(p++,P,S),i.insertPointAt(p++,P,S),i.insertPointAt(p++,Math.min(P-C+m/2,P),S),i.insertPointAt(p++,P-C-m,S)):(this.b===180||this.b===90||this.b,i.insertPointAt(p++,P,S));f=w}if(l===null||h!==Spot.None||d)if(k=i.getPoint(p-1).x,b=i.getPoint(p-1).y,P=i.getPoint(p).x,S=i.getPoint(p).y,d){const T=this.Ls[a.layer];let A=0;this.b===180||this.b===0?(A=b,A>=a.bounds.y&&A<=a.bounds.bottom&&(this.b===180?P>=a.bounds.x:P<=a.bounds.right)&&(N=a.centerX+(this.b===180?-T:T),A=a.bounds.x&&A<=a.bounds.right&&(this.b===270?S>=a.bounds.y:S<=a.bounds.bottom)&&(N=a.centerY+(this.b===270?-T:T),A=a.bounds.x?(N=a.bounds.x+a.bounds.width,i.setPointAt(p-2,N,b),i.setPointAt(p-1,N+M,b)):this.b===90&&S<=a.bounds.bottom?(N=a.bounds.y,i.setPointAt(p-2,k,N),i.setPointAt(p-1,k,N-C)):this.b===270&&S>=a.bounds.y?(N=a.bounds.y+a.bounds.height,i.setPointAt(p-2,k,N),i.setPointAt(p-1,k,N+M)):this.b===0&&P<=a.bounds.right&&(N=a.bounds.x,i.setPointAt(p-2,N,b),i.setPointAt(p-1,N-C,b));else{C=Math.max(10,this.Zs[a.layer]),M=Math.max(10,this.Ls[a.layer]);let T=0;this.b===180||this.b===0?((this.b===180?P<=a.bounds.x:P>=a.bounds.right)&&(T=(this.b===0?M:-C)/2),i.insertPointAt(p++,P+T,b)):((this.b===270?S<=a.bounds.y:S>=a.bounds.bottom)&&(T=(this.b===90?M:-C)/2),i.insertPointAt(p++,k,S+T)),i.insertPointAt(p++,P,S)}}else{for(;a!==null&&a!==f;){w=null,x=null;const N=a.destinationEdges.iterator;for(;N.next();){const T=N.value;if(T.link===e.link&&(w=T.toVertex,x=T.fromVertex,x.node!==null&&(x=null),w.node===null))break}if(w===null)break;w!==f&&(k=i.getPoint(p-1).x,b=i.getPoint(p-1).y,P=w.centerX,S=w.centerY,d?this.b===180||this.b===0?(x!==null?x.centerY:b)!==S&&(L=this.It[w.layer]+this._o.x,p===i.firstPickIndex+1&&(this.b===0?L=Math.max(L,k):L=Math.min(L,k)),i.insertPointAt(p++,L,b),i.insertPointAt(p++,L,S)):(x!==null?x.centerX:k)!==P&&(L=this.It[w.layer]+this._o.y,p===i.firstPickIndex+1&&(this.b===90?L=Math.max(L,b):L=Math.min(L,b)),i.insertPointAt(p++,k,L),i.insertPointAt(p++,P,L)):(C=Math.max(10,this.Zs[w.layer]),M=Math.max(10,this.Ls[w.layer]),u?this.b===180?(i.insertPointAt(p++,P+M+m,S),i.insertPointAt(p++,Math.max(P+M-m/2,P),S),i.insertPointAt(p++,P,S),i.insertPointAt(p++,P,S),i.insertPointAt(p++,Math.min(P-C+m/2,P),S),i.insertPointAt(p++,P-C-m,S)):this.b===90?(i.insertPointAt(p++,P,S-C-m),i.insertPointAt(p++,P,Math.min(S-C+m/2,S)),i.insertPointAt(p++,P,S),i.insertPointAt(p++,P,S),i.insertPointAt(p++,P,Math.max(S+M-m/2,S)),i.insertPointAt(p++,P,S+M+m)):this.b===270?(i.insertPointAt(p++,P,S+M+m),i.insertPointAt(p++,P,Math.max(S+M-m/2,S)),i.insertPointAt(p++,P,S),i.insertPointAt(p++,P,S),i.insertPointAt(p++,P,Math.min(S-C+m/2,S)),i.insertPointAt(p++,P,S-C-m)):(i.insertPointAt(p++,P-C-m,S),i.insertPointAt(p++,Math.min(P-C+m/2,P),S),i.insertPointAt(p++,P,S),i.insertPointAt(p++,P,S),i.insertPointAt(p++,Math.max(P+M-m/2,P),S),i.insertPointAt(p++,P+M+m,S)):this.b===180?(i.insertPointAt(p++,P+M,S),i.insertPointAt(p++,P-C,S)):this.b===90?(i.insertPointAt(p++,P,S-C),i.insertPointAt(p++,P,S+M)):this.b===270?(i.insertPointAt(p++,P,S+M),i.insertPointAt(p++,P,S-C)):(i.insertPointAt(p++,P-C,S),i.insertPointAt(p++,P+M,S)))),a=w}d&&(k=i.getPoint(p-1).x,b=i.getPoint(p-1).y,P=i.getPoint(p).x,S=i.getPoint(p).y,this.b===180||this.b===0?b!==S&&(this.b===0?L=Math.min(Math.max((P+k)/2,this.It[f.layer]+this._o.x),P):L=Math.max(Math.min((P+k)/2,this.It[f.layer]+this._o.x),P),i.insertPointAt(p++,L,b),i.insertPointAt(p++,L,S)):k!==P&&(this.b===90?L=Math.min(Math.max((S+b)/2,this.It[f.layer]+this._o.y),S):L=Math.max(Math.min((S+b)/2,this.It[f.layer]+this._o.y),S),i.insertPointAt(p++,k,L),i.insertPointAt(p++,P,L)))}if(s!==null&&u&&i.pointsCount>=4){if(r!==null){const N=h===Spot.None?i.getLinkPointFromPoint(n,r,r.getDocumentPoint(Spot.Center),i.getPoint(3),!0):i.getPoint(0);if(h===Spot.None){const T=i.getPoint(2),A=i.getPoint(3);this.direction===90||this.direction===270?(i.setPointAt(1,(N.x+T.x)/2,T.y),i.setPointAt(2,A.x,(T.y+A.y)/2)):(i.setPointAt(1,T.x,(N.y+T.y)/2),i.setPointAt(2,(T.x+A.x)/2,A.y))}N.isReal()||N.set(n.actualBounds.center),i.setPointAt(0,N.x,N.y)}if(l!==null){const N=c===Spot.None?i.getLinkPointFromPoint(o,l,l.getDocumentPoint(Spot.Center),i.getPoint(i.pointsCount-4),!1):i.getPoint(i.pointsCount-1);if(c===Spot.None){const T=i.getPoint(i.pointsCount-3),A=i.getPoint(i.pointsCount-4);this.direction===90||this.direction===270?(i.setPointAt(i.pointsCount-2,(N.x+T.x)/2,T.y),i.setPointAt(i.pointsCount-2,A.x,(T.y+A.y)/2)):(i.setPointAt(i.pointsCount-2,T.x,(N.y+T.y)/2),i.setPointAt(i.pointsCount-3,(T.x+A.x)/2,A.y))}N.isReal()||N.set(o.actualBounds.center),i.setPointAt(i.pointsCount-1,N.x,N.y)}}i.commitRoute(),e.commit()}}aI(){this.Yy=-1,this.kg=0,this.Cs=0,this._a=null,this.Sg=null,this.$f=null;for(let t=0;t=this.Cn.length){const n=[];for(let o=0;o=0&&(this.Ns=t,this.invalidateLayout()))}get columnSpacing(){return this.Wi}set columnSpacing(t){this.Wi!==t&&(U.s(t,"number",LayeredDigraphLayout,"columnSpacing"),t>0&&(this.Wi=t,this.invalidateLayout()))}get direction(){return this.b}set direction(t){this.b!==t&&(U.s(t,"number",LayeredDigraphLayout,"direction"),t===0||t===90||t===180||t===270?(this.b=t,this.invalidateLayout()):U.o("LayeredDigraphLayout.direction must be 0, 90, 180, or 270"))}get cycleRemoveOption(){return this.jf}set cycleRemoveOption(t){this.jf!==t&&(t===1||t===0||t===2)&&(this.jf=t,this.invalidateLayout())}get layeringOption(){return this.Hf}set layeringOption(t){this.Hf!==t&&(t===10||t===11||t===12)&&(this.Hf=t,this.invalidateLayout())}get initializeOption(){return this.qf}set initializeOption(t){this.qf!==t&&(t===20||t===21||t===22)&&(this.qf=t,this.invalidateLayout())}get iterations(){return this.Qa}set iterations(t){this.Qa!==t&&t>=0&&(this.Qa=t,this.invalidateLayout())}get aggressiveOption(){return this.Wf}set aggressiveOption(t){this.Wf!==t&&(t===30||t===31||t===32)&&(this.Wf=t,this.invalidateLayout())}get packOption(){return this.Qo}set packOption(t){this.Qo!==t&&(U.s(t,"number",LayeredDigraphLayout,"packOption"),t>=0&&t<8&&(this.Qo=t,this.invalidateLayout()))}get packIterations(){return this.Jf}set packIterations(t){this.Jf=t}get alignOption(){return this.Ln}set alignOption(t){this.Ln!==t&&(U.s(t,"number",LayeredDigraphLayout,"align"),t>=0&&t<16&&(this.Ln=t,this.invalidateLayout()))}get setsPortSpots(){return this.Nn}set setsPortSpots(t){this.Nn!==t&&(U.s(t,"boolean",LayeredDigraphLayout,"setsPortSpots"),this.Nn=t,this.invalidateLayout())}get maxLayer(){return this.kt}get maxIndex(){return this.Yy}get maxColumn(){return this.zt}get minIndexLayer(){return this.kg}get maxIndexLayer(){return this.Cs}static CycleDepthFirst=0;static CycleGreedy=1;static CycleFromLayers=2;static LayerOptimalLinkLength=10;static LayerLongestPathSink=11;static LayerLongestPathSource=12;static InitDepthFirstOut=20;static InitDepthFirstIn=21;static InitNaive=22;static AggressiveNone=30;static AggressiveLess=31;static AggressiveMore=32;static PackNone=0;static PackExpand=1;static PackStraighten=2;static PackMedian=4;static PackAll=15;static AlignNone=0;static AlignUpperLeft=1;static AlignUpperRight=2;static AlignLowerLeft=4;static AlignLowerRight=8;static AlignAll=15}class LayeredDigraphNetwork extends LayoutNetwork{constructor(t){super(t)}createVertex(){return new LayeredDigraphVertex(this)}createEdge(){return new LayeredDigraphEdge(this)}}class LayeredDigraphVertex extends LayoutVertex{Yo;Hr;At;ak;ck;$i;Zf;Xn;ok;ek;sk;tc;An;RD;Eh;Je;Qf;he;Tn;Hy=null;qy=null;Wy=null;Jy=null;constructor(t){super(t),this.Yo=-1,this.Hr=-1,this.At=-1,this.ak=NaN,this.ck=null,this.$i=!1,this.Zf=NaN,this.Xn=NaN,this.ok=0,this.ek=null,this.sk=null}static ID(t,i){return t.index-i.index}getProperSourceEdges(){if(!this.Wy){const t=[];for(const i of this.fo){const e=i;e.valid&&t.push(e)}this.Wy=t}return this.Wy}getProperDestinationEdges(){if(!this.Jy){const t=[];for(const i of this.Wo){const e=i;e.valid&&t.push(e)}this.Jy=t}return this.Jy}getDestinationEdge(t){const i=this.getProperDestinationEdges();for(const e of i)if(e.toVertex===t)return e;U.o("Unable to find destination edge to given vertex")}getProperSourceVertexes(){if(!this.Hy){const t=[];for(const i of this.fo){const e=i;!e.valid||e.fromVertex.layer<=e.toVertex.layer||t.push(e.fromVertex)}t.sort(LayeredDigraphVertex.ID),this.Hy=t}return this.Hy}getProperDestinationVertexes(){if(!this.qy){const t=[];for(const i of this.Wo){const e=i;!e.valid||e.fromVertex.layer<=e.toVertex.layer||t.push(e.toVertex)}t.sort(LayeredDigraphVertex.ID),this.qy=t}return this.qy}addSourceEdge(t){super.addSourceEdge(t),this.Hy=null,this.Wy=null}deleteSourceEdge(t){super.deleteSourceEdge(t),this.Hy=null,this.Wy=null}addDestinationEdge(t){super.addDestinationEdge(t),this.qy=null,this.Jy=null}deleteDestinationEdge(t){super.deleteDestinationEdge(t),this.qy=null,this.Jy=null}get layer(){return this.Yo}set layer(t){this.Yo!==t&&(U.s(t,"number",LayeredDigraphVertex,"layer"),this.Yo=t)}get column(){return this.Hr}set column(t){this.Hr!==t&&(U.s(t,"number",LayeredDigraphVertex,"column"),this.Hr=t)}get index(){return this.At}set index(t){this.At!==t&&(U.s(t,"number",LayeredDigraphVertex,"index"),this.At=t)}get component(){return this.ak}set component(t){this.ak!==t&&(U.s(t,"number",LayeredDigraphVertex,"component"),this.ak=t)}get near(){return this.ck}set near(t){this.ck!==t&&(this.ck=t)}}class LayeredDigraphEdge extends LayoutEdge{$i;fk;uk;dk;gk;mk;pk;constructor(t){super(t),this.$i=!1,this.fk=!1,this.uk=!1,this.dk=NaN,this.gk=NaN,this.mk=0,this.pk=0}get fromVertex(){return this.He}set fromVertex(t){this.He!==t&&(this.He=t)}get toVertex(){return this.qe}set toVertex(t){this.qe!==t&&(this.qe=t)}get valid(){return this.$i}set valid(t){this.$i!==t&&(U.s(t,"boolean",LayeredDigraphEdge,"valid"),this.$i=t)}get rev(){return this.fk}set rev(t){this.fk!==t&&(U.s(t,"boolean",LayeredDigraphEdge,"rev"),this.fk=t)}get forest(){return this.uk}set forest(t){this.uk!==t&&(U.s(t,"boolean",LayeredDigraphEdge,"forest"),this.uk=t)}get portFromPos(){return this.dk}set portFromPos(t){this.dk!==t&&(U.s(t,"number",LayeredDigraphEdge,"portFromPos"),this.dk=t)}get portToPos(){return this.gk}set portToPos(t){this.gk!==t&&(U.s(t,"number",LayeredDigraphEdge,"portToPos"),this.gk=t)}get portFromColOffset(){return this.mk}set portFromColOffset(t){this.mk!==t&&(U.s(t,"number",LayeredDigraphEdge,"portFromColOffset"),this.mk=t)}get portToColOffset(){return this.pk}set portToColOffset(t){this.pk!==t&&(U.s(t,"number",LayeredDigraphEdge,"portToColOffset"),this.pk=t)}}var TreePath=(y=>(y[y.Default=0]="Default",y[y.Destination=1]="Destination",y[y.Source=2]="Source",y))(TreePath||{}),TreeSorting=(y=>(y[y.Forwards=10]="Forwards",y[y.Reverse=11]="Reverse",y[y.Ascending=12]="Ascending",y[y.Descending=13]="Descending",y))(TreeSorting||{}),TreeAlignment=(y=>(y[y.CenterSubtrees=20]="CenterSubtrees",y[y.CenterChildren=21]="CenterChildren",y[y.Start=22]="Start",y[y.End=23]="End",y[y.Bus=24]="Bus",y[y.BusBranching=25]="BusBranching",y[y.TopLeftBus=26]="TopLeftBus",y[y.BottomRightBus=27]="BottomRightBus",y[y.Custom=28]="Custom",y))(TreeAlignment||{}),TreeCompaction=(y=>(y[y.None=30]="None",y[y.Block=31]="Block",y))(TreeCompaction||{}),TreeStyle=(y=>(y[y.Layered=40]="Layered",y[y.LastParents=41]="LastParents",y[y.Alternating=42]="Alternating",y[y.RootOnly=43]="RootOnly",y))(TreeStyle||{}),TreeArrangement=(y=>(y[y.Vertical=50]="Vertical",y[y.Horizontal=51]="Horizontal",y[y.FixedRoots=52]="FixedRoots",y))(TreeArrangement||{}),TreeLayerStyle=(y=>(y[y.Individual=60]="Individual",y[y.Siblings=61]="Siblings",y[y.Uniform=62]="Uniform",y))(TreeLayerStyle||{});class TreeLayout extends Layout{Fi;Li;_f;Ng;eC;Fe;Xi;Ms;U;B;yk;ls;constructor(t){super(),this.Fi=new GSet,this.Li=0,this.ls=1,this._f=40,this.Ng=60,this.eC=[],this.Fe=!0,this.Xi=50,this.Ms=new Size(10,10).u();const i=new TreeNetwork(this);this.U=new TreeVertex(i),this.B=new TreeVertex(i),this.yk=[],t&&Object.assign(this,t)}cloneProtected(t){super.cloneProtected(t),t.Li=this.Li,t._f=this._f,t.Ng=this.Ng,t.Fe=this.Fe,t.Xi=this.Xi,t.Ms.a(this.Ms),t.U.copyInheritedPropertiesFrom(this.U),t.B.copyInheritedPropertiesFrom(this.B)}oi(t){t in TreeAlignment?this.alignment=t:t in TreeArrangement?this.arrangement=t:t in TreeCompaction?this.compaction=t:t in TreePath?this.path=t:t in TreeSorting?this.sorting=t:t in TreeStyle?this.treeStyle=t:super.oi(t)}createNetwork(){return new TreeNetwork(this)}makeNetwork(t){const i=this.createNetwork(),e=s=>{if(s instanceof Node)return!s.isLinkLabel&&s.category!=="Comment";if(s instanceof Link){const n=s.fromNode;if(n===null||n.isLinkLabel||n.category==="Comment")return!1;const o=s.toNode;return!(o===null||o.isLinkLabel||o.category==="Comment")}return!1};return t instanceof Diagram?(i.addParts(t.nodes,!0,e),i.addParts(t.links,!0,e)):t instanceof Group?i.addParts(t.memberParts,!1,e):i.addParts(t.iterator,!1,e),i}doLayout(t){this.network===null&&(this.network=this.makeNetwork(t)),this.arrangement!==52&&(this.arrangementOrigin=this.initialOrigin(this.arrangementOrigin));let i=this.diagram;i===null&&t instanceof Diagram&&(i=t),this.path===0&&i!==null?this.ls=i.isTreePathToChildren?1:2:this.ls=this.path===0?1:this.path,this.network.vertexes.count>0&&(this.HI(),this.qI(),this.WI(),this.JI(),this.$N(),this.$I(),this.arrangeTrees(),this.updateParts()),this.network=null,this.Fi=new GSet,this.isValidLayout=!0}HI(){this.network.deleteSelfEdges();const t=this.network.vertexes.iterator;for(;t.next();){const n=t.value;n.initialized=!1,n.level=0,n.parent=null,n.children=[]}if(this.Fi.count>0){const n=new GSet,o=this.Fi.iterator;for(;o.next();){const r=o.value;if(r instanceof Node){const l=this.network.findVertex(r);l!==null&&n.add(l)}else r instanceof TreeVertex&&n.add(r)}this.Fi=n}this.Fi.count===0&&this.findRoots();const i=this.Fi.copy().iterator;for(;i.next();){const n=i.value;n.initialized||(n.initialized=!0,this.sC(n))}let e=this.network.vertexes,s=null;for(;s=this.ZI(e),s.count>0;){const n=this.ED(s);n!==null&&this.Fi.add(n),n.initialized=!0,this.sC(n),e=s}}ZI(t){const i=new GSet,e=t.iterator;for(;e.next();){const s=e.value;s.initialized||i.add(s)}return i}findRoots(){const t=this.network.vertexes,i=t.iterator;for(;i.next();){const e=i.value;switch(this.ls){case 1:e.sourceEdges.count===0&&this.Fi.add(e);break;case 2:e.destinationEdges.count===0&&this.Fi.add(e);break;default:U.o("Unhandled path value "+this.ls.toString())}}if(this.Fi.count===0){const e=this.ED(t);e!==null&&this.Fi.add(e)}}ED(t){let i=999999,e=null;const s=t.iterator;for(;s.next();){const n=s.value;switch(this.ls){case 1:n.sourceEdges.count0){const s=new List,n=t.destinationVertexes;for(;n.next();){const o=n.value;this.UD(t,o)&&s.add(o)}s.count>0&&(t.children=s.toArray())}break;case 2:if(t.sourceEdges.count>0){const s=new List,n=t.sourceVertexes;for(;n.next();){const o=n.value;this.UD(t,o)&&s.add(o)}s.count>0&&(t.children=s.toArray())}break;default:U.o("Unhandled path value"+this.ls.toString())}const i=t.children,e=i.length;for(let s=0;st.level?!1:(this._I(i.parent,i),!0):!0}QI(t,i){if(i===null)return!1;let e=i.parent;for(;e!==null&&e!==t;)e=e.parent;return e===t}_I(t,i){if(t===null||i===null)return;const e=t.children;let s=0;for(let n=0;n0){const n=new Array(e.length-s);let o=0;for(let r=0;r0?s+1:0}tE(t){switch(this._f){default:case 40:return t.parent!==null?t.parent:this.U;case 43:return t.parent===null?this.U:t.parent.parent===null?this.B:t.parent;case 42:return t.parent!==null?t.parent.parent!==null?t.parent.parent:this.B:this.U;case 41:{let i=!0;if(t.childrenCount===0)i=!1;else{const e=t.children,s=e.length;for(let n=0;n0){i=!1;break}}return i&&t.parent!==null?this.B:t.parent!==null?t.parent:this.U}}}initializeTreeVertexValues(t){const i=this.tE(t);if(t.copyInheritedPropertiesFrom(i),t.parent!==null&&t.parent.alignment===25){let e=t.angle;const s=t.parent.children;let n=0;for(;n135&&!l||c&&f)if(t.commentMargin>=0){g.i(t.bounds.x-t.commentMargin-k.width,t.bounds.y+u),x.move(g);const b=x.findLinksInto();for(;b.next();){const P=b.value;P.fromSpot=Spot.MiddleLeft,P.toSpot=Spot.MiddleRight}}else{g.i(t.bounds.x+t.focus.x*2-t.commentMargin,t.bounds.y+u),x.move(g);const b=x.findLinksInto();for(;b.next();){const P=b.value;P.fromSpot=Spot.MiddleRight,P.toSpot=Spot.MiddleLeft}}else if(t.commentMargin>=0){g.i(t.bounds.x+t.focus.x*2+t.commentMargin,t.bounds.y+u),x.move(g);const b=x.findLinksInto();for(;b.next();){const P=b.value;P.fromSpot=Spot.MiddleRight,P.toSpot=Spot.MiddleLeft}}else{g.i(t.bounds.x+t.commentMargin-k.width,t.bounds.y+u),x.move(g);const b=x.findLinksInto();for(;b.next();){const P=b.value;P.fromSpot=Spot.MiddleLeft,P.toSpot=Spot.MiddleRight}}t.commentSpacing>=0?u+=k.height+t.commentSpacing:u+=t.commentSpacing-k.height}else{if(o>135&&!l||!c&&f)if(t.commentMargin>=0){g.i(t.bounds.x+u,t.bounds.y-t.commentMargin-k.height),x.move(g);const b=x.findLinksInto();for(;b.next();){const P=b.value;P.fromSpot=Spot.MiddleTop,P.toSpot=Spot.MiddleBottom}}else{g.i(t.bounds.x+u,t.bounds.y+t.focus.y*2-t.commentMargin),x.move(g);const b=x.findLinksInto();for(;b.next();){const P=b.value;P.fromSpot=Spot.MiddleBottom,P.toSpot=Spot.MiddleTop}}else if(t.commentMargin>=0){g.i(t.bounds.x+u,t.bounds.y+t.focus.y*2+t.commentMargin),x.move(g);const b=x.findLinksInto();for(;b.next();){const P=b.value;P.fromSpot=Spot.MiddleBottom,P.toSpot=Spot.MiddleTop}}else{g.i(t.bounds.x+u,t.bounds.y+t.commentMargin-k.height),x.move(g);const b=x.findLinksInto();for(;b.next();){const P=b.value;P.fromSpot=Spot.MiddleTop,P.toSpot=Spot.MiddleBottom}}t.commentSpacing>=0?u+=k.width+t.commentSpacing:u+=t.commentSpacing-k.width}}Point.e(g);const p=u-t.commentSpacing-(h?e.height:e.width);if(this.ls===1){const w=t.destinationEdges;for(;w.next();){const k=w.value.link;k!==null&&!k.isAvoiding&&(k.fromEndSegmentLength=p>0?p:NaN)}}else{const w=t.sourceEdges;for(;w.next();){const k=w.value.link;k!==null&&!k.isAvoiding&&(k.toEndSegmentLength=p>0?p:NaN)}}}}$I(){if(this.layerStyle===62){const i=[];let e=this.network.vertexes.iterator;for(;e.next();){const s=e.value;let n=s.parent;n===null&&(n=s);const o=n.angle===0||n.angle===180;let r=i[s.level];r===void 0&&(r=0),i[s.level]=Math.max(r,o?s.width:s.height)}for(let s=0;s=0)for(let o=0;o135&&n.reverse(),this.$y(r))if(o>1)for(let v=0;v0&&M>0&&S+u+O.width>a&&(S135?-b-g:b+g);const X=M===0?m:u;this.wk(R,0,L),R.O.i(S+X,L),k=Math.max(k,S+X+O.width),b=Math.max(b,P+(C===0?0:g)+O.height),S+=X+O.width}else{a>0&&M>0&&L+u+O.height>a&&(L135?-k-g:k+g);const X=M===0?m:u;this.wk(R,S,0),R.O.i(S,L+X),b=Math.max(b,L+X+O.height),k=Math.max(k,P+(C===0?0:g)+O.width),L+=X+O.height}M++}C>0&&(e?(b+=Math.max(0,f),S0&&(h||this.tu(t,p,0,0,o-1),k+=p)):(k+=Math.max(0,f),L0&&(h||this.tu(t,0,p,0,o-1),b+=p)));let D=0,F=0;switch(r){case 20:e?D+=k/2-t.focus.x-d/2:F+=b/2-t.focus.y-d/2;break;default:case 21:if(C>0)e?D+=k/2-t.focus.x-d/2:F+=b/2-t.focus.y-d/2;else{const R=o;if(e){const O=n[0].O.x+n[0].lt.x,X=n[R-1].O.x+n[R-1].lt.x+n[R-1].focus.x*2;D+=O+(X-O)/2-t.focus.x-d/2}else{const O=n[0].O.y+n[0].lt.y,X=n[R-1].O.y+n[R-1].lt.y+n[R-1].focus.y*2;F+=O+(X-O)/2-t.focus.y-d/2}}break;case 22:e?(D-=d,k+=d):(F-=d,b+=d);break;case 23:e?(D+=k-t.width+d,k+=d):(F+=b-t.height+d,b+=d);break;case 24:case 25:e?o>1?D+=T+u/2-t.focus.x:D+=n[0].focus.x-t.focus.x+n[0].lt.x:o>1?F+=T+u/2-t.focus.y:F+=n[0].focus.y-t.focus.y+n[0].lt.y;break;case 26:e?D+=k+u/2-t.focus.x:F+=b+u/2-t.focus.y;break;case 27:break;case 28:const v=this.customAlignment(t,D,F,k,b);D=v[0],F=v[1],k=v[2],b=v[3];break}for(let v=0;v135?(c?-b:-R.ut.height)+R.lt.y-f:x+f+R.lt.y)):R.O.i(R.O.x+(i>135?(c?-k:-R.ut.width)+R.lt.x-f:w+f+R.lt.x),R.O.y+R.lt.y-F)}e?(k=this.oC(t,k,D),D<0&&(D=0),i>135&&(F+=b+f),b=Math.max(Math.max(b,x),b+x+f)):(i>135&&(D+=k+f),k=Math.max(Math.max(k,w),k+w+f),b=this.rC(t,b,F),F<0&&(F=0)),t.lt.i(D,F),t.ut.i(k,b)}customAlignment(t,i,e,s,n){return[i,e,s,n]}YD(t,i,e,s,n,o){const r=i.length;if(r===0)return new Rect(e,0,n,o);if(r===1){const p=i[0];return n=p.ut.width,o=p.ut.height,new Rect(e,0,n,o)}const l=t.nodeSpacing,h=t.rowSpacing,a=this.orthoAngle(t)===90;let f=0,u=0,d=0;for(let p=0;p1&&p===r-1)continue;const w=i[p],x=w.ut,k=f===0?0:h;if(a){const b=this.computeBusNodeSpacing(w)-l;w.O.i(e-(x.width+b),d+k),n=Math.max(n,x.width+b),o=Math.max(o,d+k+x.height),d+=k+x.height}else{const b=this.computeBusNodeSpacing(w)-l;w.O.i(u+k,e-(x.height+b)),o=Math.max(o,x.height+b),n=Math.max(n,u+k+x.width),u+=k+x.width}f++}f=0;const m=u,g=d;a?(u=e+l,d=0):(u=0,d=e+l);for(let p=0;p1&&r%2===1){const p=i[r-1],w=p.ut,x=this.computeBusLastRowSpacing(p,a?Math.max(Math.abs(g),Math.abs(d)):Math.max(Math.abs(m),Math.abs(u)));if(a){p.O.i(e+l/2-p.focus.x-p.lt.x,o+x);const k=e+l/2-p.focus.x-p.lt.x;n=Math.max(n,k+w.width),k<0&&(n-=k),o=Math.max(o,Math.max(g,d)+x+w.height),p.O.x<0&&(e=this.xk(t,p.O.x,!1,e,l))}else{p.O.i(n+x,e+l/2-p.focus.y-p.lt.y),n=Math.max(n,Math.max(m,u)+x+w.width);const k=e+l/2-p.focus.y-p.lt.y;o=Math.max(o,k+w.height),k<0&&(o-=k),p.O.y<0&&(e=this.xk(t,p.O.y,!0,e,l))}}return new Rect(e,0,n,o)}GD(t,i,e,s,n,o){const r=i.length;if(r===0)return new Rect(e,0,n,o);if(r===1){const p=i[0];return n=p.ut.width,o=p.ut.height,new Rect(e,0,n,o)}const l=t.nodeSpacing,h=t.rowSpacing,a=this.orthoAngle(t)===270;let f=0,u=0,d=0;for(let p=0;p1&&p===r-1)continue;const w=i[p],x=w.ut,k=f===0?0:h;if(a){const b=this.computeBusNodeSpacing(w)-l;d-=k+x.height,w.O.i(e-(x.width+b),d),n=Math.max(n,x.width+b),o=Math.max(o,Math.abs(d))}else{const b=this.computeBusNodeSpacing(w)-l;u-=k+x.width,w.O.i(u,e-(x.height+b)),o=Math.max(o,x.height+b),n=Math.max(n,Math.abs(u))}f++}f=0;const m=u,g=d;a?(u=e+l,d=0):(u=0,d=e+l);for(let p=0;p1&&r%2===1){const p=i[r-1],w=p.ut,x=this.computeBusLastRowSpacing(p,a?Math.max(Math.abs(g),Math.abs(d)):Math.max(Math.abs(m),Math.abs(u)));if(a){p.O.i(e+l/2-p.focus.x-p.lt.x,-o-w.height-x);const k=e+l/2-p.focus.x-p.lt.x;n=Math.max(n,k+w.width),k<0&&(n-=k),o=Math.max(o,Math.abs(Math.min(g,d))+x+w.height),p.O.x<0&&(e=this.xk(t,p.O.x,!1,e,l))}else{p.O.i(-n-w.width-x,e+l/2-p.focus.y-p.lt.y),n=Math.max(n,Math.abs(Math.min(m,u))+x+w.width);const k=e+l/2-p.focus.y-p.lt.y;o=Math.max(o,k+w.height),k<0&&(o-=k),p.O.y<0&&(e=this.xk(t,p.O.y,!0,e,l))}}for(let p=0;ps&&(s=e+t.width),e<0&&(s-=e),s;case 22:return t.width>i?t.width:i;case 23:return t.focus.x*2>i?t.width:i+t.width-t.focus.x*2;case 24:case 25:const n=Math.min(0,e),o=Math.max(i,e+t.width);return Math.max(t.width,o-n);case 26:return t.width-t.focus.x+t.nodeSpacing/2+i;case 27:return Math.max(t.width,t.focus.x+t.nodeSpacing/2+i);default:return i}}rC(t,i,e){switch(t.alignment){case 21:case 20:let s=i;return e+t.height>s&&(s=e+t.height),e<0&&(s-=e),s;case 22:return t.height>i?t.height:i;case 23:return t.focus.y*2>i?t.height:i+t.height-t.focus.y*2;case 24:case 25:const n=Math.min(0,e),o=Math.max(i,e+t.height);return Math.max(t.height,o-n);case 26:return t.height-t.focus.y+t.nodeSpacing/2+i;case 27:return Math.max(t.height,t.focus.y+t.nodeSpacing/2+i);default:return i}}lC(t,i,e){switch(t){case 20:i/=2,e/=2;break;case 21:i/=2,e/=2;break;case 22:i=0,e=0;break;case 23:break;default:U.o("Unhandled alignment value "+t.toString())}return new Point(i,e)}ic(t,i,e,s,n,o){const r=this.lC(i,e,s);this.tu(t,r.x,r.y,n,o)}tu(t,i,e,s,n){if(i===0&&e===0)return;const o=t.children;for(let r=s;r<=n;r++){const h=o[r].O;h.x+=i,h.y+=e}}wk(t,i,e){const s=t.parent;switch(this.ls){case 1:{const n=t.sourceEdges;for(;n.next();){const o=n.value;o.fromVertex===s&&o.relativePoint.i(i,e)}break}case 2:{const n=t.destinationEdges;for(;n.next();){const o=n.value;o.toVertex===s&&o.relativePoint.i(i,e)}break}default:U.o("Unhandled path value "+this.ls.toString())}}iE(t){if(t.childrenCount===0){const B=t.parent;let K=!1,j=0,q=21;B!==null&&(j=B.angle,q=B.alignment,K=this.isBusAlignment(q));const $=this.nC(t);t.O.i(0,0),t.ut.i(t.width,t.height),t.parent!==null&&t.comments!==null&&((j===180||j===270)&&!K||$)?j===180&&!K||(j===90||j===270)&&$?t.lt.i(t.width-t.focus.x*2,0):t.lt.i(0,t.height-t.focus.y*2):t.lt.i(0,0),t.Cg=null,t.Lg=null;return}const i=this.orthoAngle(t),e=i===90||i===270;let s=0;const n=t.children,o=n.length;for(let B=0;B135&&n.reverse(),this.$y(r))if(o>1)for(let B=0;B0&&A>0&&M+u+j.width>a&&(M135?-k-m:k+m),this.wk(K,0,N);let q=0;if(A===0)P=K.Cg,S=K.Lg,L=j.width,C=j.height,(P===null||S===null||i!==this.orthoAngle(K))&&(P=this.ae(2),S=this.ae(2),P[0].i(0,0),P[1].i(0,C),S[0].i(L,0),S[1].i(L,C));else{const $=U.et(),z=this.KD(t,K,P,S,L,C,$);q=z.x,P=$[0],S=$[1],L=z.width,C=z.height,U.J($),M0&&A>0&&N+u+j.height>a&&(N135?-x-m:x+m),this.wk(K,M,0);let q=0;if(A===0)P=K.Cg,S=K.Lg,L=j.width,C=j.height,(P===null||S===null||i!==this.orthoAngle(K))&&(P=this.ae(2),S=this.ae(2),P[0].i(0,0),P[1].i(L,0),S[0].i(0,C),S[1].i(L,C));else{const $=U.et(),z=this.KD(t,K,P,S,L,C,$);q=z.x,P=$[0],S=$[1],L=z.width,C=z.height,U.J($),N0&&(e?(k+=Math.max(0,f),M0&&(h||this.tu(t,g,0,0,o-1),x+=g)):(x+=Math.max(0,f),N0&&(h||this.tu(t,0,g,0,o-1),k+=g)));let R=0,O=0;switch(r){case 20:e?R+=x/2-t.focus.x-d/2:O+=k/2-t.focus.y-d/2;break;default:case 21:if(T>0)e?R+=x/2-t.focus.x-d/2:O+=k/2-t.focus.y-d/2;else{const K=o;if(e){const j=n[0].O.x+n[0].lt.x,q=n[K-1].O.x+n[K-1].lt.x+n[K-1].focus.x*2;R+=j+(q-j)/2-t.focus.x-d/2}else{const j=n[0].O.y+n[0].lt.y,q=n[K-1].O.y+n[K-1].lt.y+n[K-1].focus.y*2;O+=j+(q-j)/2-t.focus.y-d/2}}break;case 22:e?(R-=d,x+=d):(O-=d,k+=d);break;case 23:e?(R+=x-t.width+d,x+=d):(O+=k-t.height+d,k+=d);break;case 24:e?o>1?R+=F+u/2-t.focus.x:R+=n[0].focus.x-t.focus.x+n[0].lt.x:o>1?O+=F+u/2-t.focus.y:O+=n[0].focus.y-t.focus.y+n[0].lt.y;break;case 26:e?R+=x+u/2-t.focus.x:O+=k+u/2-t.focus.y;break;case 27:break;case 28:const B=this.customAlignment(t,R,O,x,k);R=B[0],O=B[1],x=B[2],k=B[3];break}for(let B=0;B135?(c?-k:-K.ut.height)+K.lt.y-f:w+f+K.lt.y)):K.O.i(K.O.x+(i>135?(c?-x:-K.ut.width)+K.lt.x-f:p+f+K.lt.x),K.O.y+K.lt.y-O)}let X=0,Y=0;if(c)e?(x=this.oC(t,x,R),R<0&&(R=0),i>135&&(O+=k+f),k+=w+f,r===27&&(X+=u/2+t.focus.x),Y+=w+f):(i>135&&(R+=x+f),x+=p+f,k=this.rC(t,k,O),O<0&&(O=0),r===27&&(Y+=u/2+t.focus.y),X+=p+f);else if(e){if(t.comments===null){if(p>x){const B=this.lC(r,p-x,0);X=B.x,Y=B.y,x=p,R=0}}else x=this.oC(t,x,R);R<0&&(X-=R,R=0),i>135&&(O+=k+f),k=Math.max(Math.max(k,w),k+w+f),Y+=w+f}else{if(i>135&&(R+=x+f),x=Math.max(Math.max(x,p),x+p+f),t.comments===null){if(w>k){const B=this.lC(r,0,w-k);X=B.x,Y=B.y,k=w,O=0}}else k=this.rC(t,k,O);O<0&&(Y-=O,O=0),X+=p+f}let E,V;if(T>0)E=this.ae(4),V=this.ae(4),e?(E[2].i(0,w+f),E[3].i(E[2].x,k),V[2].i(x,E[2].y),V[3].i(V[2].x,E[3].y)):(E[2].i(p+f,0),E[3].i(x,E[2].y),V[2].i(E[2].x,k),V[3].i(E[3].x,V[2].y));else{E=this.ae(P.length+2),V=this.ae(S.length+2);for(let B=0;BE[0].x?E[2].a(E[1]):E[1].a(E[2])),E[3].yE[0].x?E[3].a(E[2]):E[2].a(E[3])),V[0].i(R+p,0),V[1].i(V[0].x,w),V[2].yE[0].y?E[2].a(E[1]):E[1].a(E[2])),E[3].xE[0].y?E[3].a(E[2]):E[2].a(E[3])),V[0].i(0,O+w),V[1].i(p,V[0].y),V[2].xl;){const c=i[o++];s[r++].i(c.x,c.y+e)}const h=this.ae(r);for(n=0;nl;){const c=i[o++];s[r++].i(c.x+e,c.y)}const h=this.ae(r);for(n=0;nl;){const c=t[n++];s[r++].i(c.x,c.y)}const h=this.ae(r);for(n=0;nl;){const c=t[n++];s[r++].i(c.x,c.y)}const h=this.ae(r);for(n=0;nh&&r.xr.x&&hc&&r.yr.y&&c0){const n=Math.min(1,t.layerSpacingParentOverlap);s-=e?t.height*n:t.width*n}return s<(e?-t.height:-t.width)&&(s=e?-t.height:-t.width),s}computeNodeIndent(t){const i=this.orthoAngle(t),e=i===90||i===270;let s=t.nodeIndent;if(t.nodeIndentPastParent>0){const n=Math.min(1,t.nodeIndentPastParent);s+=e?t.width*n:t.height*n}return s=Math.max(0,s),s}get roots(){return this.Fi}set roots(t){this.Fi!==t&&(this.Fi=t,this.invalidateLayout())}get path(){return this.Li}set path(t){this.Li!==t&&(this.Li=t,this.invalidateLayout())}get treeStyle(){return this._f}set treeStyle(t){this._f!==t&&(t===40||t===42||t===41||t===43)&&(this._f=t,this.invalidateLayout())}get layerStyle(){return this.Ng}set layerStyle(t){this.Ng!==t&&(t===60||t===61||t===62)&&(this.Ng=t,this.invalidateLayout())}get comments(){return this.Fe}set comments(t){this.Fe!==t&&(U.s(t,"boolean",TreeLayout,"comments"),this.Fe=t,this.invalidateLayout())}get arrangement(){return this.Xi}set arrangement(t){this.Xi!==t&&(t===50||t===51||t===52)&&(this.Xi=t,this.invalidateLayout())}get arrangementSpacing(){return this.Ms}set arrangementSpacing(t){this.Ms.equals(t)||(this.Ms.a(t),this.invalidateLayout())}get rootDefaults(){return this.U}set rootDefaults(t){this.U!==t&&(this.U=t,this.invalidateLayout())}get alternateDefaults(){return this.B}set alternateDefaults(t){this.B!==t&&(this.B=t,this.invalidateLayout())}get sorting(){return this.U.sorting}set sorting(t){this.U.sorting!==t&&(this.U.sorting=t,this.invalidateLayout())}get comparer(){return this.U.comparer}set comparer(t){this.U.comparer!==t&&(U.k(t,TreeLayout,"comparer"),this.U.comparer=t,this.invalidateLayout())}get angle(){return this.U.angle}set angle(t){this.U.angle!==t&&(U.s(t,"number",TreeLayout,"angle"),t===0||t===90||t===180||t===270?(this.U.angle=t,this.invalidateLayout()):U.o("TreeLayout.angle must be 0, 90, 180, or 270"))}get alignment(){return this.U.alignment}set alignment(t){this.U.alignment!==t&&(this.U.alignment=t,this.invalidateLayout())}get nodeIndent(){return this.U.nodeIndent}set nodeIndent(t){this.U.nodeIndent!==t&&(U.s(t,"number",TreeLayout,"nodeIndent"),t>=0&&(this.U.nodeIndent=t,this.invalidateLayout()))}get nodeIndentPastParent(){return this.U.nodeIndentPastParent}set nodeIndentPastParent(t){this.U.nodeIndentPastParent!==t&&(U.s(t,"number",TreeLayout,"nodeIndentPastParent"),t>=0&&t<=1&&(this.U.nodeIndentPastParent=t,this.invalidateLayout()))}get nodeSpacing(){return this.U.nodeSpacing}set nodeSpacing(t){this.U.nodeSpacing!==t&&(U.s(t,"number",TreeLayout,"nodeSpacing"),this.U.nodeSpacing=t,this.invalidateLayout())}get layerSpacing(){return this.U.layerSpacing}set layerSpacing(t){this.U.layerSpacing!==t&&(U.s(t,"number",TreeLayout,"layerSpacing"),this.U.layerSpacing=t,this.invalidateLayout())}get layerSpacingParentOverlap(){return this.U.layerSpacingParentOverlap}set layerSpacingParentOverlap(t){this.U.layerSpacingParentOverlap!==t&&(U.s(t,"number",TreeLayout,"layerSpacingParentOverlap"),t>=0&&t<=1&&(this.U.layerSpacingParentOverlap=t,this.invalidateLayout()))}get compaction(){return this.U.compaction}set compaction(t){this.U.compaction!==t&&(t===30||t===31)&&(this.U.compaction=t,this.invalidateLayout())}get breadthLimit(){return this.U.breadthLimit}set breadthLimit(t){this.U.breadthLimit!==t&&(U.s(t,"number",TreeLayout,"breadthLimit"),t>=0&&(this.U.breadthLimit=t,this.invalidateLayout()))}get rowSpacing(){return this.U.rowSpacing}set rowSpacing(t){this.U.rowSpacing!==t&&(U.s(t,"number",TreeLayout,"rowSpacing"),this.U.rowSpacing=t,this.invalidateLayout())}get rowIndent(){return this.U.rowIndent}set rowIndent(t){this.U.rowIndent!==t&&(U.s(t,"number",TreeLayout,"rowIndent"),t>=0&&(this.U.rowIndent=t,this.invalidateLayout()))}get commentSpacing(){return this.U.commentSpacing}set commentSpacing(t){this.U.commentSpacing!==t&&(U.s(t,"number",TreeLayout,"commentSpacing"),this.U.commentSpacing=t,this.invalidateLayout())}get commentMargin(){return this.U.commentMargin}set commentMargin(t){this.U.commentMargin!==t&&(U.s(t,"number",TreeLayout,"commentMargin"),this.U.commentMargin=t,this.invalidateLayout())}get setsPortSpot(){return this.U.setsPortSpot}set setsPortSpot(t){this.U.setsPortSpot!==t&&(U.s(t,"boolean",TreeLayout,"setsPortSpot"),this.U.setsPortSpot=t,this.invalidateLayout())}get portSpot(){return this.U.portSpot}set portSpot(t){this.U.portSpot.equals(t)||(this.U.portSpot=t,this.invalidateLayout())}get setsChildPortSpot(){return this.U.setsChildPortSpot}set setsChildPortSpot(t){this.U.setsChildPortSpot!==t&&(U.s(t,"boolean",TreeLayout,"setsChildPortSpot"),this.U.setsChildPortSpot=t,this.invalidateLayout())}get childPortSpot(){return this.U.childPortSpot}set childPortSpot(t){this.U.childPortSpot.equals(t)||(this.U.childPortSpot=t,this.invalidateLayout())}get alternateSorting(){return this.B.sorting}set alternateSorting(t){this.B.sorting!==t&&(this.B.sorting=t,this.invalidateLayout())}get alternateComparer(){return this.B.comparer}set alternateComparer(t){this.B.comparer!==t&&(U.k(t,TreeLayout,"alternateComparer"),this.B.comparer=t,this.invalidateLayout())}get alternateAngle(){return this.B.angle}set alternateAngle(t){this.B.angle!==t&&(U.s(t,"number",TreeLayout,"alternateAngle"),(t===0||t===90||t===180||t===270)&&(this.B.angle=t,this.invalidateLayout()))}get alternateAlignment(){return this.B.alignment}set alternateAlignment(t){this.B.alignment!==t&&(this.B.alignment=t,this.invalidateLayout())}get alternateNodeIndent(){return this.B.nodeIndent}set alternateNodeIndent(t){this.B.nodeIndent!==t&&(U.s(t,"number",TreeLayout,"alternateNodeIndent"),t>=0&&(this.B.nodeIndent=t,this.invalidateLayout()))}get alternateNodeIndentPastParent(){return this.B.nodeIndentPastParent}set alternateNodeIndentPastParent(t){this.B.nodeIndentPastParent!==t&&(U.s(t,"number",TreeLayout,"alternateNodeIndentPastParent"),t>=0&&t<=1&&(this.B.nodeIndentPastParent=t,this.invalidateLayout()))}get alternateNodeSpacing(){return this.B.nodeSpacing}set alternateNodeSpacing(t){this.B.nodeSpacing!==t&&(U.s(t,"number",TreeLayout,"alternateNodeSpacing"),this.B.nodeSpacing=t,this.invalidateLayout())}get alternateLayerSpacing(){return this.B.layerSpacing}set alternateLayerSpacing(t){this.B.layerSpacing!==t&&(U.s(t,"number",TreeLayout,"alternateLayerSpacing"),this.B.layerSpacing=t,this.invalidateLayout())}get alternateLayerSpacingParentOverlap(){return this.B.layerSpacingParentOverlap}set alternateLayerSpacingParentOverlap(t){this.B.layerSpacingParentOverlap!==t&&(U.s(t,"number",TreeLayout,"alternateLayerSpacingParentOverlap"),t>=0&&t<=1&&(this.B.layerSpacingParentOverlap=t,this.invalidateLayout()))}get alternateCompaction(){return this.B.compaction}set alternateCompaction(t){this.B.compaction!==t&&(t===30||t===31)&&(this.B.compaction=t,this.invalidateLayout())}get alternateBreadthLimit(){return this.B.breadthLimit}set alternateBreadthLimit(t){this.B.breadthLimit!==t&&(U.s(t,"number",TreeLayout,"alternateBreadthLimit"),t>=0&&(this.B.breadthLimit=t,this.invalidateLayout()))}get alternateRowSpacing(){return this.B.rowSpacing}set alternateRowSpacing(t){this.B.rowSpacing!==t&&(U.s(t,"number",TreeLayout,"alternateRowSpacing"),this.B.rowSpacing=t,this.invalidateLayout())}get alternateRowIndent(){return this.B.rowIndent}set alternateRowIndent(t){this.B.rowIndent!==t&&(U.s(t,"number",TreeLayout,"alternateRowIndent"),t>=0&&(this.B.rowIndent=t,this.invalidateLayout()))}get alternateCommentSpacing(){return this.B.commentSpacing}set alternateCommentSpacing(t){this.B.commentSpacing!==t&&(U.s(t,"number",TreeLayout,"alternateCommentSpacing"),this.B.commentSpacing=t,this.invalidateLayout())}get alternateCommentMargin(){return this.B.commentMargin}set alternateCommentMargin(t){this.B.commentMargin!==t&&(U.s(t,"number",TreeLayout,"alternateCommentMargin"),this.B.commentMargin=t,this.invalidateLayout())}get alternateSetsPortSpot(){return this.B.setsPortSpot}set alternateSetsPortSpot(t){this.B.setsPortSpot!==t&&(U.s(t,"boolean",TreeLayout,"alternateSetsPortSpot"),this.B.setsPortSpot=t,this.invalidateLayout())}get alternatePortSpot(){return this.B.portSpot}set alternatePortSpot(t){this.B.portSpot.equals(t)||(this.B.portSpot=t,this.invalidateLayout())}get alternateSetsChildPortSpot(){return this.B.setsChildPortSpot}set alternateSetsChildPortSpot(t){this.B.setsChildPortSpot!==t&&(U.s(t,"boolean",TreeLayout,"alternateSetsChildPortSpot"),this.B.setsChildPortSpot=t,this.invalidateLayout())}get alternateChildPortSpot(){return this.B.childPortSpot}set alternateChildPortSpot(t){this.B.childPortSpot.equals(t)||(this.B.childPortSpot=t,this.invalidateLayout())}static PathDefault=0;static PathDestination=1;static PathSource=2;static SortingForwards=10;static SortingReverse=11;static SortingAscending=12;static SortingDescending=13;static AlignmentCenterSubtrees=20;static AlignmentCenterChildren=21;static AlignmentStart=22;static AlignmentEnd=23;static AlignmentBus=24;static AlignmentBusBranching=25;static AlignmentTopLeftBus=26;static AlignmentBottomRightBus=27;static CompactionNone=30;static CompactionBlock=31;static StyleLayered=40;static StyleLastParents=41;static StyleAlternating=42;static StyleRootOnly=43;static ArrangementVertical=50;static ArrangementHorizontal=51;static ArrangementFixedRoots=52;static LayerIndividual=60;static LayerSiblings=61;static LayerUniform=62}class TreeNetwork extends LayoutNetwork{constructor(t){super(t)}createVertex(){return new TreeVertex(this)}createEdge(){return new TreeEdge(this)}}class TreeVertex extends LayoutVertex{O;ut;lt;kk;Pk;Sk;Mk;Nk;Ck;Lk;Fe;Cg;Lg;pe;ye;Yt;hi;Zy;Qy;_y;Ns;tw;iw;ew;nw;ow;lw;hw;aw;cw;fw;uw;constructor(t){super(t),this.kk=!1,this.Pk=null,this.Sk=[],this.Mk=0,this.Nk=0,this.Ck=0,this.Lk=0,this.Fe=null,this.O=new Point(0,0),this.ut=new Size(0,0),this.lt=new Point(0,0),this.Cg=null,this.Lg=null,this.pe=10,this.ye=LayoutVertex.standardComparer,this.Yt=0,this.hi=21,this.Zy=0,this.Qy=0,this._y=20,this.Ns=50,this.tw=0,this.iw=31,this.ew=0,this.nw=25,this.ow=10,this.lw=10,this.hw=20,this.aw=!0,this.cw=Spot.Default,this.fw=!0,this.uw=Spot.Default}copyInheritedPropertiesFrom(t){t!==null&&(this.pe=t.sorting,this.ye=t.comparer,this.Yt=t.angle,this.hi=t.alignment,this.Zy=t.nodeIndent,this.Qy=t.nodeIndentPastParent,this._y=t.nodeSpacing,this.Ns=t.layerSpacing,this.tw=t.layerSpacingParentOverlap,this.iw=t.compaction,this.ew=t.breadthLimit,this.nw=t.rowSpacing,this.ow=t.rowIndent,this.lw=t.commentSpacing,this.hw=t.commentMargin,this.aw=t.setsPortSpot,this.cw=t.portSpot,this.fw=t.setsChildPortSpot,this.uw=t.childPortSpot)}get initialized(){return this.kk}set initialized(t){this.kk!==t&&(U.s(t,"boolean",TreeVertex,"initialized"),this.kk=t)}get parent(){return this.Pk}set parent(t){this.Pk!==t&&(this.Pk=t)}get children(){return this.Sk}set children(t){if(this.Sk!==t){if(t!==null&&!Array.isArray(t)&&U.Zi(t,"Array",TreeVertex,"children:value"),t!==null){const i=t.length;for(let e=0;e4;)t.removePoint(2);u=t.getPoint(1),d=t.getPoint(2)}else{for(f=1;t.pointsCount>3;)t.removePoint(1);u=t.getPoint(0),d=t.getPoint(t.pointsCount-1)}const m=t.getPoint(t.pointsCount-1);let g=0;r===0?(e.alignment===23?(g=o.bottom+n.y,n.y===0&&u.y>m.y+e.rowIndent&&(g=Math.min(g,Math.max(u.y,g-i.computeNodeIndent(e))))):e.alignment===22?(g=o.top+n.y,n.y===0&&u.ym.x+e.rowIndent&&(g=Math.min(g,Math.max(u.x,g-i.computeNodeIndent(e))))):e.alignment===22?(g=o.left+n.x,n.x===0&&u.xm.y+e.rowIndent&&(g=Math.min(g,Math.max(u.y,g-i.computeNodeIndent(e))))):e.alignment===22?(g=o.top+n.y,n.y===0&&u.ym.x+e.rowIndent&&(g=Math.min(g,Math.max(u.x,g-i.computeNodeIndent(e))))):e.alignment===22?(g=o.left+n.x,n.x===0&&u.x{const i=t.matches?"dark":"light";i!==this.Ag&&(this.Ag=i,this.Dk==="system"&&this.dw())};constructor(t){t&&Object.assign(this,t),t?.themeMap||(this.iu.set("light",{colors:{...Themes.Light.colors},fonts:{...Themes.Light.fonts},numbers:{...Themes.Light.numbers},margins:{...Themes.Light.margins},arrowheads:{...Themes.Light.arrowheads}}),this.iu.set("dark",{colors:{...Themes.Dark.colors},fonts:{...Themes.Dark.fonts},numbers:{...Themes.Dark.numbers},margins:{...Themes.Dark.margins},arrowheads:{...Themes.Dark.arrowheads}})),root.matchMedia&&(this.Ag=root.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light")}get themeMap(){return this.iu}set themeMap(t){this.iu!==t&&(this.iu=t,this.dw())}get defaultTheme(){return this.Tk}set defaultTheme(t){this.Tk!==t&&(U.s(t,"string",ThemeManager,"defaultTheme"),this.Tk=t,this.dw())}get currentTheme(){return this.Dk}set currentTheme(t){this.Dk!==t&&(U.s(t,"string",ThemeManager,"currentTheme"),this.Dk=t,this.dw())}get changesDivBackground(){return this.Fk}set changesDivBackground(t){if(this.Fk!==t&&(this.Fk=t,t))for(const e of this.ts)e.setDivBackground(this.findValue("div","","fill")),e.D("ThemeChanged",this)}get preferredColorScheme(){return this.Ag}addDiagram(t){return this.ts.add(t),this.aC(t),this}removeDiagram(t){return this.ts.delete(t),this.aC(t),this}hR(){this.ts.size===0&&root.matchMedia&&root.matchMedia("(prefers-color-scheme: dark)")?.addEventListener("change",this.HD)}aR(){this.ts.size===0&&root.matchMedia&&root.matchMedia("(prefers-color-scheme: dark)")?.removeEventListener("change",this.HD)}set(t,i){t===""&&(t=this.Tk),t==="system"&&(t=this.Ag);let e=this.iu.get(t);return e?e=this.qD(e,i):e=i,this.iu.set(t,e),this.dw(),this}findValue(t,i,e){return this.getValue(this.findTheme(this.currentTheme),t,i,e)||this.getValue(this.findTheme(this.defaultTheme),t,i,e)}getValue(t,i,e,s){if(!t)return;e==null&&(e="");let n=t;const o=l=>{if(n===void 0||l==="")return;if(typeof l=="number"||!(Array.isArray(l)||l.includes(".")))return n[l];const h=Array.isArray(l)?l:l.split(".");for(let c=0;c{if(!(e!==""&&(n=o(e),n===void 0)))return Array.isArray(n)&&typeof i=="number"?n=n[i%n.length]:n=o(i),n};if(n=r(),n===void 0&&typeof s=="string"&&s.length>0){let l=t.targetPropertyMap?.get(s);if(l?n=t[l]:(l=ThemeManager.cE.get(s),n=l?t[l]:t.colors),n=r(),n!==void 0)return n}return n}findTheme(t){return this.themeMap.get(t==="system"?this.Ag:t)}aC(t){const i=t.skipsUndoManager;t.skipsUndoManager=!0,t.updateAllThemeBindings(),this.Fk&&t.setDivBackground(this.findValue("div","","fill")),t.skipsUndoManager=i,t.D("ThemeChanged",this)}dw(){for(const t of this.ts)this.aC(t)}qD(t,i){for(const e in i)if(U.gw(i,e))try{i[e].constructor===Object?t[e]=this.qD(t[e]??{},i[e]):t[e]=i[e]}catch{delete t[e]}return t}static cE=new Map([["background","colors"],["defaultColumnSeparatorStroke","colors"],["defaultRowSeparatorStroke","colors"],["shadowColor","colors"],["fill","colors"],["stroke","colors"],["font","fonts"],["angle","numbers"],["fromEndSegmentLength","numbers"],["fromShortLength","numbers"],["height","numbers"],["opacity","numbers"],["scale","numbers"],["toEndSegmentLength","numbers"],["toShortLength","numbers"],["width","numbers"],["defaultColumnSeparatorStrokeWidth","numbers"],["defaultRowSeparatorStrokeWidth","numbers"],["shadowBlur","numbers"],["corner","numbers"],["curviness","numbers"],["smoothness","numbers"],["parameter1","numbers"],["parameter2","numbers"],["strokeWidth","numbers"],["strokeDashOffset","numbers"],["maxLines","numbers"],["spacingAbove","numbers"],["spacingBelow","numbers"],["position","points"],["shadowOffset","points"],["desiredSize","sizes"],["maxSize","sizes"],["minSize","sizes"],["margin","margins"],["defaultSeparatorPadding","margins"],["padding","margins"],["alignment","spots"],["alignmentFocus","spots"],["fromSpot","spots"],["toSpot","spots"],["defaultAlignment","spots"],["spot1","spots"],["spot2","spots"],["verticalAlignment","spots"],["imageAlignment","spots"],["fromArrow","arrowheads"],["toArrow","arrowheads"]])}class Router{St;N;Oi;cl;constructor(){this.N=Diagram.um(),this.St="",this.Oi=!0,this.cl=!0}get name(){return this.St}set name(t){this.St=t}get isEnabled(){return this.Oi}set isEnabled(t){this.Oi=t}get isRealtime(){return this.cl}set isRealtime(t){this.cl=t}get diagram(){return this.N}set diagram(t){this.N!==t&&(this.N=t,t.bl=!0,t.requestUpdate())}invalidateRouter(){this.N!==null&&(this.N.bl=!0,this.N.requestUpdate())}canRoute(t){if(!this.isEnabled)return!1;const i=this.diagram;return!(i&&(!this.isRealtime&&i.gu||i.animationManager.isTicking))}routeLinks(t,i){}toString(){return this.name!==""?this.name+" Router":U.Dn(this.constructor)}}class AvoidsNodesRouter extends Router{constructor(t){super(),this.name="AvoidsNodes",t&&Object.assign(this,t)}canRoute(t){return(t instanceof Diagram?t.Vm:t.diagram.Vm)?super.canRoute(t):!1}routeLinks(t,i){const e=i instanceof Diagram?null:i,s=t.iterator,n=this.diagram.getPositions(!0,e,null);for(;s.next();){const o=s.value;if(!o.isAvoiding||o.containingGroup!==e||o.toNode===null||o.fromNode===null||o.pointsCount<4)continue;o.startRoute();const r=o.pointsCount,l=o.getPoint(1),h=o.getPoint(r-2),c=o.fromNode.actualBounds.copy();c.inflate(Link.Ua,Link.Ua),c.unionPoint(o.getPoint(0));const a=o.toNode.actualBounds.copy();a.inflate(Link.Ua,Link.Ua),a.unionPoint(o.getPoint(r-1)),this.fE(o,c,a,n)&&this.uE(o,l,o.dN,h,o.gN,c,a,n),o.commitRoute()}}fE(t,i,e,s){const n=t.diagram,o=t.pointsCount;if(n===null||t.fromNode===t.toNode||t.layer.isTemporary||i.containsPoint(t.getPoint(o-1))&&!t.toNode.isMemberOf(t.fromNode)||e.containsPoint(t.getPoint(0))&&!t.fromNode.isMemberOf(t.toNode)||!t.isOrthogonal)return!1;if(t.segmentIndex===17)return!0;const r=t.getPoint(1),l=t.getPoint(o-2),h=t.getPoint(2);if(!s.isUnoccupied(Math.min(r.x,h.x),Math.min(r.y,h.y),Math.abs(r.x-h.x),Math.abs(r.y-h.y)))return!0;for(let a=2;a=PositionArray.Rd&&(l.rA(),d.inflate(l.cellWidth*l.HM,l.cellHeight*l.qM),l.NT(i,e,s,n,d,!1),m=l.lo(s.x,s.y)),!l.ky&&mPositionArray.Xa&&i.lo(g,p)!==u-1&&(i.lo(d-a,m)===u-1?(n=180,g=d-a,p=m):i.lo(d+a,m)===u-1?(n=0,g=d+a,p=m):i.lo(d,m-f)===u-1?(n=270,g=d,p=m-f):i.lo(d,m+f)===u-1&&(n=90,g=d,p=m+f));u>PositionArray.Xa&&i.lo(g,p)===u-1;)d=g,m=p,n===0?g+=a:n===90?p+=f:n===180?g-=a:p-=f,u-=1;if(o?u>PositionArray.Xa&&(n===180||n===0?d=Math.floor(d/a)*a+a/2:(n===90||n===270)&&(m=Math.floor(m/f)*f+f/2)):(d=Math.floor(d/a)*a+a/2,m=Math.floor(m/f)*f+f/2),u>PositionArray.Xa){let w=n,x=d,k=m;if(n===0?(w=90,k+=f):n===90?(w=180,x-=a):n===180?(w=270,k-=f):n===270&&(w=0,x+=a),i.lo(x,k)===u-1)this.cC(t,i,x,k,w,!1);else{let P=d,S=m;n===0?(w=270,S-=f):n===90?(w=0,P+=a):n===180?(w=90,S+=f):n===270&&(w=180,P-=a),i.lo(P,S)===u-1&&this.cC(t,i,P,S,w,!1)}}t.insertPointAt(t.pointsCount-2,d,m)}}ToolManager.prototype.initializeStandardTools=function(){this.Jt("Action",new ActionTool,this.mouseDownTools),this.Jt("Relinking",new RelinkingTool,this.mouseDownTools),this.Jt("LinkReshaping",new LinkReshapingTool,this.mouseDownTools),this.Jt("Rotating",new RotatingTool,this.mouseDownTools),this.Jt("Resizing",new ResizingTool,this.mouseDownTools),this.Jt("Linking",new LinkingTool,this.mouseMoveTools),this.Jt("Dragging",new DraggingTool,this.mouseMoveTools),this.Jt("DragSelecting",new DragSelectingTool,this.mouseMoveTools),this.Jt("Panning",new PanningTool,this.mouseMoveTools),this.Jt("ContextMenu",new ContextMenuTool,this.mouseUpTools),this.Jt("TextEditing",new TextEditingTool,this.mouseUpTools),this.Jt("ClickCreating",new ClickCreatingTool,this.mouseUpTools),this.Jt("ClickSelecting",new ClickSelectingTool,this.mouseUpTools)};Diagram.CM("GraphLinksModel",GraphLinksPartManager);Diagram.CM("TreeModel",TreePartManager);const oldGo=root.go,go={get version(){return Diagram.version},Group,List,Set:GSet,Map:GMap,Point,Size,Rect,Margin,Spot,Geometry,PathFigure,PathSegment,InputEvent,DiagramEvent,ChangedEvent,Model,GraphLinksModel,TreeModel,Binding,ThemeBinding,Transaction,UndoManager,CommandHandler,Tool,DraggingTool,DraggingInfo,DraggingOptions,LinkingBaseTool,LinkingTool,RelinkingTool,LinkReshapingTool,ResizingTool,RotatingTool,ClickSelectingTool,ActionTool,ClickCreatingTool,HTMLInfo,ContextMenuTool,DragSelectingTool,PanningTool,TextEditingTool,ToolManager,Animation,AnimationManager,AnimationTrigger,Layer,Diagram,Palette,Overview,Brush,GraphObject,Panel,RowColumnDefinition,Shape,TextBlock,Picture,Part,Adornment,Node,Link,Placeholder,Layout,LayoutNetwork,LayoutVertex,LayoutEdge,GridLayout,PanelLayout,CircularLayout,CircularNetwork,CircularVertex,CircularEdge,ForceDirectedLayout,ForceDirectedNetwork,ForceDirectedVertex,ForceDirectedEdge,LayeredDigraphLayout,LayeredDigraphNetwork,LayeredDigraphVertex,LayeredDigraphEdge,TreeLayout,TreeNetwork,TreeVertex,TreeEdge,Themes,ThemeManager,Router,AnimationStyle,AutoScale,CycleMode,Flip,TextFormat,ImageStretch,LayoutConditions,LinkAdjusting,Curve,Routing,Orientation,TextOverflow,PortSpreading,ScrollMode,CollapsePolicy,Sizing,TriggerStart,Stretch,ViewboxStretch,Wrap,BrushType,ColorSpace,GeometryStretch,GeometryType,SegmentType,BindingMode,ChangeType,CircularArrangement,CircularDirection,CircularNodeDiameterFormula,CircularSorting,GridAlignment,GridArrangement,GridSorting,LayeredDigraphAggressive,LayeredDigraphAlign,LayeredDigraphCycleRemove,LayeredDigraphInit,LayeredDigraphLayering,LayeredDigraphPack,TreeAlignment,TreeArrangement,TreeCompaction,TreeLayerStyle,TreePath,TreeSorting,TreeStyle,GestureMode,LinkingDirection,ReshapingBehavior,TextEditingAccept,TextEditingStarting,TextEditingState,WheelMode};for(const y in go){const t=go[y];U.it(t)&&t!==TextFormat&&(t.className=y)}U.G(oldGo)&&oldGo.version&&U.ni("WARNING: a `go` object on the root object is already defined. "+("Debug"in oldGo?"debug ":"")+"version: "+oldGo.version+", replaced with version: "+go.version);Diagram.prototype.go=go;root.go=go; })(); "function"===typeof define&&define.amd&&define("undefined"!==typeof global?global.go:self.go); 'undefined'!==typeof module&&'object'===typeof module.exports&&(module.exports='undefined'!==typeof global?global.go:self.go);