/** * @license GoJS * GoJS v3.1.5 JavaScript Library for Interactive Diagrams, https://gojs.net * GoJS and Northwoods Software are registered trademarks of Northwoods Software Corporation, https://nwoods.com. * Copyright 1998-2026 by Northwoods Software Corporation. All Rights Reserved. * THIS SOFTWARE IS LICENSED. THE LICENSE AGREEMENT IS AT: https://gojs.net/3.1.5/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=w=>root.setTimeout(w,0):root.requestAnimationFrame=root.setImmediate);const Debug={boundsInfoEnabled:!1,drawLocationsEnabled:!1,drawClipEnabled:!1,drawLinkpointsEnabled:!1,nodeInspector:!1,handleMessages:!1,drawFrames:!1,defaultDiagram:null,trace:function(w){root.console&&root.console.log(w)},drawDiagramBounds(w,t,i,e){w.strokeStyle="red",w.fillStyle="red",w.font="8px sans-serif",w.beginPath(),w.moveTo(-10,0),w.lineTo(10,0),w.moveTo(0,-10),w.lineTo(0,10),w.stroke(),w.setTransform(1,0,0,1,0,0),w.scale(i,i),w.transform(t.m11,t.m12,t.m21,t.m22,t.dx,t.dy),w.lineWidth=2,w.beginPath(),w.moveTo(e.left,e.top+20),w.lineTo(e.left,e.top),w.lineTo(e.left+20,e.top),w.moveTo(e.right,e.bottom-20),w.lineTo(e.right,e.bottom),w.lineTo(e.right-20,e.bottom),w.stroke(),w.fillText("DB: "+Math.round(e.x)+", "+Math.round(e.y)+", "+Math.round(e.width)+", "+Math.round(e.height),e.left,e.top-5)},attachReadonlyWarnings:function(w){for(const t in w){if(t==="licenseKey")continue;const i=w[t];if(i.prototype===void 0)continue;const e=Object.getOwnPropertyNames(i.prototype);for(let s=0;s{s=-1,e||t.apply(n,o)},i),e&&!s&&t.apply(n,o)}}static pn(t,i){return root.setTimeout(t,i)}static Nf(t){root.clearTimeout(t)}static Le(t){return root.document.createElement(t)}static n(t){throw new Error(t)}static D(t,i){let e="The object is frozen, so its properties cannot be set: "+t.toString();i!==void 0&&(e+=" to value: "+i),U.n(e)}static s(t,i,e,s){if(!(t instanceof i)){let n=U.Cf(e);s!==void 0&&(n+="."+s),U.Ti(t,i,n)}}static i(t,i,e,s){if(typeof t!==i){let n=U.Cf(e);s!==void 0&&(n+="."+s),U.Ti(t,i,n)}}static r(t,i,e){if(typeof t!="number"||!isFinite(t)){let s=U.Cf(i);e!==void 0&&(s+="."+e),U.n(s+" must be a real number type, and not NaN or Infinity: "+t)}}static Ro(t,i,e){if(t===null||typeof t!="object"){let s=U.Cf(i);e!==void 0&&(s+="."+e),U.Ti(t,"object",s)}}static C(t,i,e){U.i(t,"function",i,e)}static W(t,i,e){t in i||U.n(`${t} is not a valid value in enumeration: ${e}`)}static Ti(t,i,e,s){const n=" value is not an instance of "+U.Cf(i)+": ";let o=U.Cf(e);s!==void 0&&(o+="."+s),typeof t=="string"&&(t='"'+t+'"'),U.n(o+n+t)}static G(t,i,e,s){let n=U.Cf(e);s!==void 0&&(n+="."+s),U.n(n+" is not in the range "+i+": "+t)}static He(t){U.n("Collection was modified during iteration: "+t.toString()+` Perhaps you should iterate over a copy of the collection, or you could collect items to be removed from the collection after the iteration.`)}static wr(t,i){U.n("No property to set for this enum value: "+i+" on "+t.toString())}static ot(t){root.console&&root.console.log(t)}static it(t){return t!==null&&typeof t=="object"}static ht(t){return typeof t=="function"}static Ek=[];static at(){const t=U.Ek.pop();return t===void 0?[]:t}static et(t){t.length=0,U.Ek.push(t)}static FB=Object.freeze([]);static Cf(t){return t===null?"*":typeof t=="string"?t:U.ht(t)?t.name:""}static Jn(t){return U.ht(t)?t.className?t.className:t.name:U.it(t)&&t.constructor?U.Jn(t.constructor):typeof t}static ea(t,i){return i==null||i===""?null:U.it(t)&&i in t||t[i]?t[i]:null}static toString(t){let i=t;return U.it(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 Zw(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.IB;if(s&&s[i])return!0;e=Object.getPrototypeOf(e)}return!1}static jI(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.Zt;i.xr=null;const e=i.ct;this.Et=-1;const s=i.h,n=s.length,o=this.qs;for(let r=0;r=0?(this.key=i,this.value=t.h[i],!0):(this.Tl(),!1)}hasNext(){return this.next()}first(){const t=this.Zt;this.Wt=t.ct;const i=t.h,e=i.length-1;if(this.Et=e,e>=0){const s=i[e];return this.key=e,this.value=s,s}else return null}any(t){const i=this.Zt;i.br=null;const e=i.ct,s=i.h,n=s.length;this.Et=n;for(let o=n-1;o>=0;o--){const r=s[o];if(t(r))return!0;i.ct!==e&&U.He(i)}return!1}all(t){const i=this.Zt;i.br=null;const e=i.ct,s=i.h,n=s.length;this.Et=n;for(let o=n-1;o>=0;o--){const r=s[o];if(!t(r))return!1;i.ct!==e&&U.He(i)}return!0}each(t){const i=this.Zt;i.br=null;const e=i.ct,s=i.h,n=s.length;this.Et=n;for(let o=n-1;o>=0;o--){const r=s[o];t(r),i.ct!==e&&U.He(i)}return this}map(t){const i=this.Zt;i.br=null;const e=i.ct,s=[],n=i.h,o=n.length;this.Et=o;for(let l=o-1;l>=0;l--){const h=n[l];s.push(t(h)),i.ct!==e&&U.He(i)}const r=new List;return r.h=s,r.ve(),r.iterator}filter(t){const i=this.Zt;i.br=null;const e=i.ct,s=[],n=i.h,o=n.length;this.Et=o;for(let l=o-1;l>=0;l--){const h=n[l];t(h)&&s.push(h),i.ct!==e&&U.He(i)}const r=new List;return r.h=s,r.ve(),r.iterator}get count(){return this.Zt.h.length}Tl(){this.key=-1,this.value=null,this.Wt=-1,this.Zt.br=this}toString(){return"ListIteratorBackwards("+this.Et+"/"+this.Zt.count+")"}}class List{p;h;ct;xr;br;constructor(t){GSet._i(this),this.p=!1,this.h=[],this.ct=0,this.xr=null,this.br=null,t!==void 0&&this.addAll(t)}[Symbol.iterator](){return this.h.values()}ve(){let t=this.ct;t++,t>999999999&&(t=0),this.ct=t}k(){return this.p=!0,this}di(){return this.p=!1,this}toString(){return"List()#"+GSet.Ps(this)}add(t){return this.p&&U.D(this,t),this.h.push(t),this.ve(),this}push(t){this.add(t)}addAll(t){if(t===null)return this;this.p&&U.D(this);const i=this.h;if(t.first){const e=t.iterator;for(;e.next();)i.push(e.value)}else for(const e of t)i.push(e);return this.ve(),this}clear(){this.p&&U.D(this),this.h.length=0,this.ve()}contains(t){return this.has(t)}has(t){return t===null?!1:this.h.indexOf(t)!==-1}indexOf(t){return t===null?-1:this.h.indexOf(t)}elt(t){Debug&&U.r(t,List,"elt:i");const i=this.h;return(t<0||t>=i.length)&&U.G(t,"0 <= i < length",List,"elt:i"),i[t]}get(t){return this.elt(t)}setElt(t,i){Debug&&U.r(t,List,"setElt:i");const e=this.h;(t<0||t>=e.length)&&U.G(t,"0 <= i < length",List,"setElt:i"),this.p&&U.D(this,t),e[t]=i}set(t,i){this.setElt(t,i)}first(){const t=this.h;return t.length===0?null:t[0]}last(){const t=this.h,i=t.length;return i>0?t[i-1]:null}pop(){this.p&&U.D(this);const t=this.h;if(t.length>0){const i=t.pop();return i===void 0?null:i}return null}any(t){const i=this.h,e=this.ct,s=i.length;for(let n=0;n= 0",List,"insertAt:i"),this.p&&U.D(this,t);const e=this.h;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.p&&U.D(this,t);const i=this.h,e=i.indexOf(t);return e===-1?!1:(e===i.length-1?i.pop():i.splice(e,1),this.ve(),!0)}removeAt(t){Debug&&U.r(t,List,"removeAt:i");const i=this.h;(t<0||t>=i.length)&&U.G(t,"0 <= i < length",List,"removeAt:i"),this.p&&U.D(this,t),t===i.length-1?i.pop():i.splice(t,1),this.ve()}removeRange(t,i){Debug&&(U.r(t,List,"removeRange:from"),U.r(i,List,"removeRange:to"));const e=this.h,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.p&&U.D(this);let n=t,o=i+1;for(;o0&&(t.h=Array.prototype.slice.call(i)),t}toArray(){const t=this.h,i=this.count,e=new Array(i);for(let s=0;s=n-1)&&U.G(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.Oo.w.forEach(e=>{t(e)&&i.add(e)}),i.iterator}get count(){return this.Oo.count}Tl(){this.key=null,this.value=null,this.hi=null}toString(){return"SetIterator"}}class GSet{p;w;constructor(t){this.p=!1,this.w=new Set,t!==void 0&&this.addAll(t)}[Symbol.iterator](){return this.w.values()}values(){return this.w.values()}k(){return this.p=!0,this}di(){return this.p=!1,this}toString(){return"Set()#"+GSet.Ps(this)}add(t){return t===null?this:(this.w.add(t),this)}addAll(t){if(t===null)return this;if(this.p&&U.D(this),t.first){const i=t.iterator;for(;i.next();)this.w.add(i.value)}else for(const i of t)this.w.add(i);return this}has(t){return this.w.has(t)}contains(t){return this.has(t)}containsAll(t){if(t===null)return!0;if(t.first){const i=t.iterator;for(;i.next();)if(!this.has(i.value))return!1}else for(const i of t)if(!this.has(i))return!1;return!0}containsAny(t){if(t===null)return!0;if(t.first){const i=t.iterator;for(;i.next();)if(this.has(i.value))return!0}else for(const i of t)if(this.has(i))return!0;return!1}first(){return this.w.size===0?null:this.w.values().next().value}any(t){for(const i of this.w)if(t(i))return!0;return!1}all(t){for(const i of this.w)if(!t(i))return!1;return!0}each(t){for(const i of this.w)t(i);return this}map(t){const i=new GSet;for(const e of this.w)i.add(t(e));return i}filter(t){const i=new GSet;for(const e of this.w)t(e)&&i.add(e);return i}delete(t){return this.p&&U.D(this),this.w.delete(t)}remove(t){return this.delete(t)}removeAll(t){if(t===null)return this;if(this.p&&U.D(this),t.first){const i=t.iterator;for(;i.next();)this.delete(i.value)}else for(const i of t)this.delete(i);return this}retainAll(t){if(t===null)return this;if(this.count===0)return this;this.p&&U.D(this);const i=new GSet;i.addAll(t);const e=[];if(t.first){const s=t.iterator;for(;s.next();){const n=s.value;i.has(n)||e.push(n)}}else for(const s of t)i.has(s)||e.push(s);return this.removeAll(e),this}clear(){this.p&&U.D(this),this.w.clear()}copy(){const t=new GSet;return this.w.forEach(i=>t.add(i)),t}toArray(){return Array.from(this.w)}toList(){const t=new List;return this.w.forEach(i=>t.add(i)),t}get count(){return this.w.size}get size(){return this.w.size}get iterator(){return this.w.size<=0?EmptyIterator.instance:new SetIterator(this)}entries(){return this.w.entries()}keys(){return this.w.keys()}forEach(t,i){return this.w.forEach(t,i)}static _w=1;static _i(t){t.__gohashid=GSet._w++}static Ps(t){return t.__gohashid}}class MapKeySetIterator{Z;hi;constructor(t){this.Z=t,this.hi=t.w.keys()}[Symbol.iterator](){return this.Z.w.keys()}key;value;get iterator(){return this}reset(){const t=this.Z;this.hi=t.w.keys()}next(){const t=this.hi.next();return this.value=t.value,this.key=t.value,!t.done}hasNext(){return this.next()}first(){return this.Z.w.size===0?null:(this.hi=this.Z.w.keys(),this.hi.next().value)}any(t){for(const i of this.Z.w)if(t(i[0]))return!0;return!1}all(t){for(const i of this.Z.w)if(!t(i[0]))return!1;return!0}each(t){for(const i of this.Z.w)t(i[0]);return this}map(t){const i=this.Z,e=new List;for(const s of i.w)e.add(t(s[0]));return e.iterator}filter(t){const i=this.Z,e=new List;for(const s of i.w){const n=s[0];t(n)&&e.add(n)}return e.iterator}get count(){return this.Z.size}Tl(){this.key=null,this.value=null,this.hi=null}toString(){return"MapKeySetIterator"}}class MapKeySet extends GSet{Z;constructor(t){super(),GSet._i(this),this.p=!0,this.Z=t}[Symbol.iterator](){return this.w.keys()}values(){return this.w.keys()}k(){return this}di(){return this}toString(){return"MapKeySet("+this.Z.toString()+")"}add(t){U.n("This Set is read-only: "+this.toString())}has(t){return this.Z.has(t)}contains(t){return this.has(t)}delete(t){U.n("This Set is read-only: "+this.toString())}remove(t){return this.delete(t)}clear(){U.n("This Set is read-only: "+this.toString())}first(){return this.Z.w.size===0?null:this.Z.w.keys().next().value}any(t){for(const i of this.Z.w)if(t(i[0]))return!0;return!1}all(t){for(const i of this.Z.w)if(!t(i[0]))return!1;return!0}each(t){for(const i of this.Z.w)t(i[0]);return this}map(t){const i=new GSet;for(const e of this.Z.w)i.add(t(e[0]));return i}filter(t){const i=new GSet;for(const e of this.Z.w){const s=e[0];t(s)&&i.add(s)}return i}copy(){return new MapKeySet(this.Z)}toSet(){const t=new GSet,i=this.Z.w;for(const e of i)t.add(e[0]);return t}toArray(){const t=this.Z.w,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.Z.w;for(const e of i)t.add(e[0]);return t}get count(){return this.Z.size}get size(){return this.Z.size}get iterator(){return this.Z.size<=0?EmptyIterator.instance:new MapKeySetIterator(this.Z)}}class MapValueSetIterator{Z;hi;constructor(t){this.Z=t,this.hi=t.w.values()}[Symbol.iterator](){return this.Z.w.values()}key;value;get iterator(){return this}reset(){const t=this.Z;this.hi=t.w.values()}next(){const t=this.hi.next();return this.value=t.value,this.key=t.value,!t.done}hasNext(){return this.next()}first(){return this.Z.w.size===0?null:(this.hi=this.Z.w.values(),this.hi.next().value)}any(t){for(const i of this.Z.w)if(t(i[1]))return!0;return!1}all(t){for(const i of this.Z.w)if(!t(i[1]))return!1;return!0}each(t){for(const i of this.Z.w)t(i[1]);return this}map(t){const i=this.Z,e=new List;for(const s of i.w)e.add(t(s[1]));return e.iterator}filter(t){const i=this.Z,e=new List;for(const s of i.w){const n=s[1];t(n)&&e.add(n)}return e.iterator}get count(){return this.Z.size}Tl(){this.key=null,this.value=null,this.hi=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{Z;hi;constructor(t){this.Z=t,this.hi=t.w.entries()}[Symbol.iterator](){return this.Z.w.entries()}key;value;get iterator(){return this}reset(){const t=this.Z;this.hi=t.w.entries()}next(){const t=this.hi.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.Z.w.size===0)return null;this.hi=this.Z.w.entries();const t=this.hi.next().value;return this.key=t[0],this.value=t[1],new KeyValuePair(t[0],t[1])}any(t){return this.Z.any(t)}all(t){return this.Z.all(t)}each(t){return this.Z.each(t),this}map(t){const i=new List;let e=null;return this.Z.w.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.Z.w.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.Z.size}Tl(){this.key=null,this.value=null,this.hi=null}toString(){return"MapIterator"}}class GMap{p;w;constructor(t){GSet._i(this),this.p=!1,this.w=new Map,t!==void 0&&this.addAll(t)}[Symbol.iterator](){return this.w.entries()}entries(){return this.w.entries()}k(){return this.p=!0,this}di(){return this.p=!1,this}toString(){return"Map()#"+GSet.Ps(this)}set(t,i){return this.p&&U.D(this,t),this.w.set(t,i),this}add(t,i){return this.set(t,i)}addAll(t){if(t===null)return this;if(this.p&&U.D(this),t instanceof GMap){const i=t.iterator;for(;i.next();)this.w.set(i.key,i.value)}else if(t.first){const i=t.iterator;for(;i.next();){const e=i.value;this.w.set(e.key,e.value)}}else for(const i of t){const e=i;Array.isArray(e)?this.w.set(e[0],e[1]):this.w.set(e.key,e.value)}return this}first(){if(this.w.size===0)return null;const t=this.w.entries().next().value;return t?new KeyValuePair(t[0],t[1]):null}any(t){let i=null;for(const[e,s]of this.w)if(i===null?i=new KeyValuePair(e,s):(i.key=e,i.value=s),t(i))return!0;return!1}all(t){let i=null;for(const[e,s]of this.w)if(i===null?i=new KeyValuePair(e,s):(i.key=e,i.value=s),!t(i))return!1;return!0}each(t){let i=null;for(const[e,s]of this.w)i===null?i=new KeyValuePair(e,s):(i.key=e,i.value=s),t(i);return this}map(t){const i=new GMap;let e=null;for(const[s,n]of this.w)e===null?e=new KeyValuePair(s,n):(e.key=s,e.value=n),i.set(s,t(e));return i}filter(t){const i=new GMap;let e=null;for(const[s,n]of this.w)e===null?e=new KeyValuePair(s,n):(e.key=s,e.value=n),t(e)&&i.set(s,n);return i}has(t){return this.w.has(t)}contains(t){return this.has(t)}get(t){const i=this.w.get(t);return i===void 0?null:i}getValue(t){return this.get(t)}delete(t){return t===null?!1:(this.p&&U.D(this,t),this.w.delete(t))}remove(t){return this.delete(t)}clear(){this.p&&U.D(this),this.w.clear()}copy(){const t=new GMap;return t.w=new Map(this.w),t}toArray(){const t=this.w,i=new Array(t.size);let e=0;for(const s of t)i[e]=new KeyValuePair(s[0],s[1]),e++;return i}toKeySet(){return new MapKeySet(this)}get count(){return this.w.size}get size(){return this.w.size}get iterator(){return this.w.size<=0?EmptyIterator.instance:new MapIterator(this)}get iteratorKeys(){return this.count<=0?EmptyIterator.instance:new MapKeySetIterator(this)}keys(){return this.w.keys()}get iteratorValues(){return this.count<=0?EmptyIterator.instance:new MapValueSetIterator(this)}values(){return this.w.values()}forEach(t,i){return this.w.forEach(t,i)}}class Point{px;py;p;constructor(t,i){t===void 0?(this.px=0,this.py=0):typeof t=="number"&&typeof i=="number"?(this.px=t,this.py=i):U.n("Invalid arguments to Point constructor: "+t+", "+i),this.p=!1}c(t){return this.px=t.px,this.py=t.py,this}e(t,i){return this.px=t,this.py=i,this}setTo(t,i){return Debug&&(U.i(t,"number",Point,"setTo:x"),U.i(i,"number",Point,"setTo:y"),this._()),this.px=t,this.py=i,this}set(t){return Debug&&(U.s(t,Point,Point,"set:p"),this._()),this.px=t.px,this.py=t.py,this}copy(){const t=new Point;return t.px=this.px,t.py=this.py,t}Ct(){return this.p=!0,Object.freeze(this),this}T(){return this.p||Object.isFrozen(this)?this:this.copy().k()}k(){return this.p||(this.p=!0),this}_(t){if(Debug&&this.p){let i="The Point is frozen, so its properties cannot be set: "+this.toString();t!==void 0&&(i+=" to value: "+t),U.n(i)}}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 Point(s,o)}else return new Point}static stringify(t){return Debug&&U.s(t,Point),t.x.toString()+" "+t.y.toString()}static stringifyFixed(t){return U.i(t,"number",Point,"stringifyFixed:digits"),i=>i.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 G.u(this.px,t.x)&&G.u(this.py,t.y)}add(t){return Debug&&(U.s(t,Point,Point,"add:p"),this._()),this.px+=t.x,this.py+=t.y,this}subtract(t){return Debug&&(U.s(t,Point,Point,"subtract:p"),this._()),this.px-=t.x,this.py-=t.y,this}offset(t,i){return Debug&&(U.r(t,Point,"offset:dx"),U.r(i,Point,"offset:dy"),this._()),this.px+=t,this.py+=i,this}rotate(t){if(Debug&&(U.r(t,Point,"rotate:angle"),this._()),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=G.Yi(t),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 Debug&&(U.r(t,Point,"scale:sx"),U.r(i,Point,"scale:sy"),this._()),this.px*=t,this.py*=i,this}distanceSquaredPoint(t){Debug&&U.s(t,Point,Point,"distanceSquaredPoint:p");const i=t.x-this.px,e=t.y-this.py;return i*i+e*e}distanceSquared(t,i){Debug&&(U.r(t,Point,"distanceSquared:px"),U.r(i,Point,"distanceSquared:py"));const e=t-this.px,s=i-this.py;return e*e+s*s}normalize(){Debug&&this._();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 Debug&&U.s(t,Point,Point,"directionPoint:p"),this.EA(t.x-this.px,t.y-this.py)}direction(t,i){return Debug&&(U.r(t,Point,"direction:px"),U.r(i,Point,"direction:py")),this.EA(t-this.px,i-this.py)}EA(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 Debug&&(U.r(t,Point,"compareWithLineSegment:a1x"),U.r(i,Point,"compareWithLineSegment:a1y"),U.r(e,Point,"compareWithLineSegment:a2x"),U.r(s,Point,"compareWithLineSegment:a2y"),U.r(n,Point,"compareWithLineSegment:b1x"),U.r(o,Point,"compareWithLineSegment:b1y")),G.Nu(t,i,e,s,n,o)}compareWithLineSegmentPoint(t,i){return Debug&&(U.s(t,Point,Point,"compareWithLineSegmentPoint:p"),U.s(i,Point,Point,"compareWithLineSegmentPoint:q")),G.Nu(t.x,t.y,i.x,i.y,this.x,this.y)}static intersectingLineSegments(t,i,e,s,n,o,r,l){return Debug&&(U.r(t,Point,"intersectingLineSegments:a1x"),U.r(i,Point,"intersectingLineSegments:a1y"),U.r(e,Point,"intersectingLineSegments:a2x"),U.r(s,Point,"intersectingLineSegments:a2y"),U.r(n,Point,"intersectingLineSegments:b1x"),U.r(o,Point,"intersectingLineSegments:b1y"),U.r(r,Point,"intersectingLineSegments:b2x"),U.r(l,Point,"intersectingLineSegments:b2y")),G.Cu(t,i,e,s,n,o,r,l)}projectOntoLineSegment(t,i,e,s){return Debug&&(U.r(t,Point,"projectOntoLineSegment:px"),U.r(i,Point,"projectOntoLineSegment:py"),U.r(e,Point,"projectOntoLineSegment:qx"),U.r(s,Point,"projectOntoLineSegment:qy")),G.Ll(t,i,e,s,this.px,this.py,this),this}projectOntoLineSegmentPoint(t,i){return Debug&&(U.s(t,Point,Point,"projectOntoLineSegmentPoint:p"),U.s(i,Point,Point,"projectOntoLineSegmentPoint:q")),G.Ll(t.x,t.y,i.x,i.y,this.px,this.py,this),this}snapToGrid(t,i,e,s){return Debug&&(U.r(t,Point,"snapToGrid:originx"),U.r(i,Point,"snapToGrid:originy"),U.r(e,Point,"snapToGrid:cellwidth"),U.r(s,Point,"snapToGrid:cellheight")),G.rm(this.px,this.py,t,i,e,s,this),this}snapToGridPoint(t,i){return Debug&&(U.s(t,Point,Point,"snapToGridPoint:p"),U.s(i,Size,Point,"snapToGridPoint:q")),G.rm(this.px,this.py,t.x,t.y,i.width,i.height,this),this}setRectSpot(t,i){return Debug&&(U.s(t,Rect,Point,"setRectSpot:r"),U.s(i,Spot,Point,"setRectSpot:spot"),this._()),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 Debug&&(U.r(t,Point,"setSpot:x"),U.r(i,Point,"setSpot:y"),U.r(e,Point,"setSpot:w"),U.r(s,Point,"setSpot:h"),(e<0||s<0)&&U.n("Point.setSpot:Width and height cannot be negative"),U.s(n,Spot,Point,"setSpot:spot"),this._()),this.px=t+n.x*e+n.offsetX,this.py=i+n.y*s+n.offsetY,this}E(t){return t.St(this),this}We(t){return t.De(this),this}static distanceLineSegmentSquared(t,i,e,s,n,o){Debug&&(U.r(t,Point,"distanceLineSegmentSquared:px"),U.r(i,Point,"distanceLineSegmentSquared:py"),U.r(e,Point,"distanceLineSegmentSquared:ax"),U.r(s,Point,"distanceLineSegmentSquared:ay"),U.r(n,Point,"distanceLineSegmentSquared:bx"),U.r(o,Point,"distanceLineSegmentSquared:by"));let r=n-e,l=o-s;const h=r*r+l*l,a=e-t,f=s-i,c=-a*r-f*l;if(c<=0||c>=h)return r=n-t,l=o-i,Math.min(a*a+f*f,r*r+l*l);{const u=r*f-l*a;return u*u/h}}static distanceSquared(t,i,e,s){Debug&&(U.r(t,Point,"distanceSquared:px"),U.r(i,Point,"distanceSquared:py"),U.r(e,Point,"distanceSquared:qx"),U.r(s,Point,"distanceSquared:qy"));const n=e-t,o=s-i;return n*n+o*o}static direction(t,i,e,s){Debug&&(U.r(t,Point,"direction:px"),U.r(i,Point,"direction:py"),U.r(e,Point,"direction:qx"),U.r(s,Point,"direction:qy"));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){Debug&&(U.i(t,"number",Point,"x"),this._(t)),this.px=t}get y(){return this.py}set y(t){Debug&&(U.i(t,"number",Point,"y"),this._(t)),this.py=t}isReal(){return isFinite(this.x)&&isFinite(this.y)}static yn=new Point(0,0).Ct();static BA=new Point(-1/0,-1/0).Ct();static VA=new Point(1/0,1/0).Ct();static zA=new Point(6,6).Ct();static wn=new Point(NaN,NaN).Ct();static tx=[];static a(){const t=Point.tx.pop();return t===void 0?new Point:t}static Ms(t){const i=Point.tx.pop();return i===void 0?t.copy():i.c(t)}static U(t,i){const e=Point.tx.pop();return e===void 0?new Point(t,i):(e.x=t,e.y=i,e)}static o(t){Point.tx.push(t)}}class Size{sw;sh;p;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.n("Invalid arguments to Size constructor: "+t+", "+i),this.p=!1}c(t){return this.sw=t.sw,this.sh=t.sh,this}e(t,i){return this.sw=t,this.sh=i,this}setTo(t,i){return Debug&&(U.i(t,"number",Size,"setTo:w"),U.i(i,"number",Size,"setTo:h"),t<0&&U.G(t,">= 0",Size,"setTo:w"),i<0&&U.G(i,">= 0",Size,"setTo:h"),this._()),this.sw=t,this.sh=i,this}set(t){return Debug&&(U.s(t,Size,Size,"set:s"),this._()),this.sw=t.sw,this.sh=t.sh,this}copy(){const t=new Size;return t.sw=this.sw,t.sh=this.sh,t}Ct(){return this.p=!0,Object.freeze(this),this}T(){return this.p||Object.isFrozen(this)?this:this.copy().k()}k(){return this.p||(this.p=!0),this}_(t){if(Debug&&this.p){let i="The Size is frozen, so its properties cannot be set: "+this.toString();t!==void 0&&(i+=" to value: "+t),U.n(i)}}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 Debug&&U.s(t,Size),t.width.toString()+" "+t.height.toString()}static stringifyFixed(t){return U.i(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 G.u(this.sw,t.width)&&G.u(this.sh,t.height)}inflate(t,i){Debug&&(U.r(t,Size,"inflate:w"),U.r(i,Size,"inflate:h"));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){Debug&&(U.i(t,"number",Size,"width"),this._(t)),t<0&&U.G(t,">= 0",Size,"width"),this.sw=t}get height(){return this.sh}set height(t){Debug&&(U.i(t,"number",Size,"height"),this._(t)),t<0&&U.G(t,">= 0",Size,"height"),this.sh=t}isReal(){return isFinite(this.width)&&isFinite(this.height)}static sa=new Size(0,0).Ct();static Vk=new Size(1,1).Ct();static XA=new Size(6,6).Ct();static Au=new Size(8,8).Ct();static YA=new Size(10,10).Ct();static ix=new Size(1/0,1/0).Ct();static ex=new Size(NaN,NaN).Ct();static KA=[];static a(){const t=Size.KA.pop();return t===void 0?new Size:t}static o(t){Size.KA.push(t)}}class Rect{rx;ry;rw;rh;p;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.n("Incorrect second argument supplied to Rect constructor "+i)}else U.n("Invalid arguments to Rect constructor: "+t+", "+i+", "+e+", "+s);this.p=!1}c(t){return this.rx=t.rx,this.ry=t.ry,this.rw=t.rw,this.rh=t.rh,this}e(t,i,e,s){return this.rx=t,this.ry=i,this.rw=e,this.rh=s,this}$n(t,i){return this.rw=t,this.rh=i,this}setTo(t,i,e,s){return Debug&&(U.i(t,"number",Rect,"setTo:x"),U.i(i,"number",Rect,"setTo:y"),U.i(e,"number",Rect,"setTo:w"),U.i(s,"number",Rect,"setTo:h"),e<0&&U.G(e,">= 0",Rect,"setTo:w"),s<0&&U.G(s,">= 0",Rect,"setTo:h"),this._()),this.rx=t,this.ry=i,this.rw=e,this.rh=s,this}set(t){return Debug&&(U.s(t,Rect,Rect,"set:r"),this._()),this.rx=t.rx,this.ry=t.ry,this.rw=t.rw,this.rh=t.rh,this}setPoint(t){return Debug&&(U.s(t,Point,Rect,"setPoint:p"),this._()),this.rx=t.x,this.ry=t.y,this}setSize(t){return Debug&&(U.s(t,Size,Rect,"setSize:s"),this._()),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}Ct(){return this.p=!0,Object.freeze(this),this}T(){return this.p||Object.isFrozen(this)?this:this.copy().k()}k(){return this.p||(this.p=!0),this}di(){return this.p&&(Object.isFrozen(this)&&U.n("cannot thaw constant: "+this),this.p=!1),this}_(t){if(Debug&&this.p){let i="The Rect is frozen, so its properties cannot be set: "+this.toString();t!==void 0&&(i+=" to value: "+t),U.n(i)}}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 Debug&&U.s(t,Rect),t.x.toString()+" "+t.y.toString()+" "+t.width.toString()+" "+t.height.toString()}static stringifyFixed(t){return U.i(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 G.u(this.rx,t.x)&&G.u(this.ry,t.y)&&G.u(this.rw,t.width)&&G.u(this.rh,t.height)}equalsApproxTo(t,i,e,s){return G.u(this.rx,t)&&G.u(this.ry,i)&&G.u(this.rw,e)&&G.u(this.rh,s)}equalsApproxClose(t){return G.q(this.rx,t.x)&&G.q(this.ry,t.y)&&G.q(this.rw,t.width)&&G.q(this.rh,t.height)}containsPoint(t){return Debug&&U.s(t,Point,Rect,"containsPoint:p"),this.rx<=t.x&&this.rx+this.rw>=t.x&&this.ry<=t.y&&this.ry+this.rh>=t.y}containsRect(t){return Debug&&U.s(t,Rect,Rect,"containsRect:r"),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 Debug?(U.r(t,Rect,"contains:x"),U.r(i,Rect,"contains:y"),e===void 0?e=0:U.r(e,Rect,"contains:w"),s===void 0?s=0:U.r(s,Rect,"contains:h"),(e<0||s<0)&&U.n("Rect.contains:Width and height cannot be negative")):(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 Debug&&(U.r(t,Rect,"offset:dx"),U.r(i,Rect,"offset:dy"),this._()),this.rx+=t,this.ry+=i,this}inflate(t,i){return Debug&&(U.r(t,Rect,"inflate:w"),U.r(i,Rect,"inflate:h")),this.nx(i,t,i,t)}addMargin(t){return Debug&&U.s(t,Margin,Rect,"addMargin:m"),this.nx(t.top,t.right,t.bottom,t.left)}subtractMargin(t){return Debug&&U.s(t,Margin,Rect,"subtractMargin:m"),this.nx(-t.top,-t.right,-t.bottom,-t.left)}grow(t,i,e,s){return Debug&&(U.r(t,Rect,"grow:t"),U.r(i,Rect,"grow:r"),U.r(e,Rect,"grow:b"),U.r(s,Rect,"grow:l")),this.nx(t,i,e,s)}nx(t,i,e,s){Debug&&this._();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 Debug&&U.s(t,Rect,Rect,"intersectRect:r"),this.UA(t.x,t.y,t.width,t.height)}intersect(t,i,e,s){return Debug&&(U.r(t,Rect,"intersect:x"),U.r(i,Rect,"intersect:y"),U.r(e,Rect,"intersect:w"),U.r(s,Rect,"intersect:h"),(e<0||s<0)&&U.n("Rect.intersect:Width and height cannot be negative")),this.UA(t,i,e,s)}UA(t,i,e,s){Debug&&this._();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 Debug&&U.s(t,Rect,Rect,"intersectsRect:r"),this.intersects(t.x,t.y,t.width,t.height)}intersects(t,i,e,s){Debug&&(U.r(t,Rect,"intersects:x"),U.r(i,Rect,"intersects:y"),U.r(t,Rect,"intersects:w"),U.r(i,Rect,"intersects:h"),(e<0||s<0)&&U.n("Rect.intersects:Width and height cannot be negative"));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))}GA(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,a=t.y-i;return r+=h,l+=a,!(h>l||a>r)}unionPoint(t){return Debug&&U.s(t,Point,Rect,"unionPoint:p"),this.ai(t.x,t.y,0,0)}unionRect(t){return Debug&&U.s(t,Rect,Rect,"unionRect:r"),this.ai(t.rx,t.ry,t.rw,t.rh)}union(t,i,e,s){return Debug?(U.r(t,Rect,"union:x"),U.r(i,Rect,"union:y"),e===void 0?e=0:U.r(e,Rect,"union:w"),s===void 0?s=0:U.r(s,Rect,"union:h"),(e<0||s<0)&&U.n("Rect.union:Width and height cannot be negative"),this._()):(e===void 0&&(e=0),s===void 0&&(s=0)),this.ai(t,i,e,s)}ai(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 Debug&&(U.r(t,Rect,"setSpot:x"),U.r(i,Rect,"setSpot:y"),U.s(e,Spot,Rect,"setSpot:spot"),this._()),this.rx=t-e.offsetX-e.x*this.rw,this.ry=i-e.offsetY-e.y*this.rh,this}nearestSideDirection(t,i){return Debug&&(U.r(t,Rect,"nearestSideDirection:x"),U.r(i,Rect,"nearestSideDirection:y")),G.lx(this,t,i,!0)}nearestSideDirectionPoint(t){return Debug&&U.s(t,Point,Rect,"unionPoint:p"),G.lx(this,t.x,t.y,!0)}static contains(t,i,e,s,n,o,r,l){return Debug?(U.r(t,Rect,"contains:rx"),U.r(i,Rect,"contains:ry"),U.r(e,Rect,"contains:rw"),U.r(s,Rect,"contains:rh"),U.r(n,Rect,"contains:x"),U.r(o,Rect,"contains:y"),r===void 0?r=0:U.r(r,Rect,"contains:w"),l===void 0?l=0:U.r(l,Rect,"contains:h"),(e<0||s<0||r<0||l<0)&&U.n("Rect.contains:Width and height cannot be negative")):(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){Debug&&(U.r(t,Rect,"intersects:rx"),U.r(i,Rect,"intersects:ry"),U.r(e,Rect,"intersects:rw"),U.r(s,Rect,"intersects:rh"),U.r(n,Rect,"intersects:x"),U.r(o,Rect,"intersects:y"),U.r(r,Rect,"intersects:w"),U.r(l,Rect,"intersects:h"),(e<0||s<0||r<0||l<0)&&U.n("Rect.intersects:Width and height cannot be negative"));let h=e,a=r;const f=t,c=n;if(h+=f,a+=c,f>a||c>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 Debug&&(U.r(t,Rect,"intersectsLineSegment:x"),U.r(i,Rect,"intersectsLineSegment:y"),U.r(e,Rect,"intersectsLineSegment:w"),U.r(s,Rect,"intersectsLineSegment:h"),U.r(n,Rect,"intersectsLineSegment:p1x"),U.r(o,Rect,"intersectsLineSegment:p1y"),U.r(r,Rect,"intersectsLineSegment:p2x"),U.r(l,Rect,"intersectsLineSegment:p2y"),(e<0||s<0)&&U.n("Rect.intersectsLineSegment: width and height cannot be negative")),G.qA(t,i,e,s,n,o,r,l)}get x(){return this.rx}set x(t){Debug&&(U.i(t,"number",Rect,"x"),this._(t)),this.rx=t}get y(){return this.ry}set y(t){Debug&&(U.i(t,"number",Rect,"y"),this._(t)),this.ry=t}get width(){return this.rw}set width(t){Debug&&(U.i(t,"number",Rect,"width"),this._(t)),t<0&&U.G(t,">= 0",Rect,"width"),this.rw=t}get height(){return this.rh}set height(t){Debug&&(U.i(t,"number",Rect,"height"),this._(t)),t<0&&U.G(t,">= 0",Rect,"height"),this.rh=t}get left(){return this.rx}set left(t){Debug&&(U.i(t,"number",Rect,"left"),this._(t)),this.rx=t}get top(){return this.ry}set top(t){Debug&&(U.i(t,"number",Rect,"top"),this._(t)),this.ry=t}get right(){return this.rx+this.rw}set right(t){Debug&&(U.r(t,Rect,"right"),this._(t)),this.rx+=t-(this.rx+this.rw)}get bottom(){return this.ry+this.rh}set bottom(t){Debug&&(U.r(t,Rect,"top"),this._(t)),this.ry+=t-(this.ry+this.rh)}get position(){return new Point(this.rx,this.ry)}set position(t){Debug&&(U.s(t,Point,Rect,"position"),this._(t)),this.rx=t.x,this.ry=t.y}get size(){return new Size(this.rw,this.rh)}set size(t){Debug&&(U.s(t,Size,Rect,"size"),this._(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){Debug&&(U.s(t,Point,Rect,"center"),this._(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){Debug&&(U.r(t,Rect,"centerX"),this._(t)),this.rx=t-this.rw/2}get centerY(){return this.ry+this.rh/2}set centerY(t){Debug&&(U.r(t,Rect,"centerY"),this._(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 lm=new Rect(0,0,0,0).Ct();static $I=new Rect(NaN,NaN,NaN,NaN).Ct();static hx=[];static a(){const t=Rect.hx.pop();return t===void 0?new Rect:t}static Ms(t){const i=Rect.hx.pop();return i===void 0?t.copy():i.c(t)}static U(t,i,e,s){const n=Rect.hx.pop();return n===void 0?new Rect(t,i,e,s):n.e(t,i,e,s)}static o(t){Rect.hx.push(t)}}class Margin{mt;mr;mb;ml;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.n("Invalid arguments to Margin constructor: "+t+", "+i+", "+e+", "+s)}setTo(t,i,e,s){return Debug&&(U.i(t,"number",Margin,"setTo:t"),U.i(i,"number",Margin,"setTo:r"),U.i(e,"number",Margin,"setTo:b"),U.i(s,"number",Margin,"setTo:l"),this._()),this.mt=t,this.mr=i,this.mb=e,this.ml=s,this}set(t){return Debug&&(U.s(t,Margin,Margin,"assign:m"),this._()),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}Ct(){return Object.freeze(this),this}T(){return Object.isFrozen(this)?this:this.copy().Ct()}_(t){if(Debug&&Object.isFrozen(this)){let i="The Margin is frozen, so its properties cannot be set: "+this.toString();t!==void 0&&(i+=" to value: "+t),U.n(i)}}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 Debug&&U.s(t,Margin),t.top.toString()+" "+t.right.toString()+" "+t.bottom.toString()+" "+t.left.toString()}static stringifyFixed(t){return U.i(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 G.u(this.mt,t.top)&&G.u(this.mr,t.right)&&G.u(this.mb,t.bottom)&&G.u(this.ml,t.left)}get top(){return this.mt}set top(t){Debug&&(U.r(t,Margin,"top"),this._(t)),this.mt=t}get right(){return this.mr}set right(t){Debug&&(U.r(t,Margin,"right"),this._(t)),this.mr=t}get bottom(){return this.mb}set bottom(t){Debug&&(U.r(t,Margin,"bottom"),this._(t)),this.mb=t}get left(){return this.ml}set left(t){Debug&&(U.r(t,Margin,"left"),this._(t)),this.ml=t}isReal(){return isFinite(this.top)&&isFinite(this.right)&&isFinite(this.bottom)&&isFinite(this.left)}static hm=new Margin(0,0,0,0).Ct();static HA=new Margin(2,2,2,2).Ct()}class Spot{sx;sy;ox;oy;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)}setTo(t,i,e,s){return Debug&&(this.fx(t,"setTo:x"),this.fx(i,"setTo:y"),this.cx(e,"setTo:offx"),this.cx(s,"setTo:offy"),this._()),this.sx=t,this.sy=i,this.ox=e,this.oy=s,this}set(t){return Debug&&(U.s(t,Spot,Spot,"set:s"),this._()),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}Ct(){return Object.freeze(this),this}T(){return Object.isFrozen(this)?this:this.copy().Ct()}_(t){if(Debug&&Object.isFrozen(this)){let i="The Spot is frozen, so its properties cannot be set: "+this.toString();t!==void 0&&(i+=" to value: "+t),U.n(i)}}je(t){return this.sx=NaN,this.sy=NaN,this.ox=t,this.Ct()}fx(t,i){(isNaN(t)||t>1||t<0)&&U.G(t,"0 <= "+i+" <= 1",Spot,i)}cx(t,i){(isNaN(t)||t===1/0||t===-1/0)&&U.G(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 Debug&&U.s(t,Spot),t.isSpot()?t.x.toString()+" "+t.y.toString()+" "+t.offsetX.toString()+" "+t.offsetY.toString():t.toString()}static stringifyFixed(t){return U.i(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){Debug&&(this.fx(t,"x"),this._(t)),this.sx=t}get y(){return this.sy}set y(t){Debug&&(this.fx(t,"y"),this._(t)),this.sy=t}get offsetX(){return this.ox}set offsetX(t){Debug&&(this.cx(t,"offsetX"),this._(t)),this.ox=t}get offsetY(){return this.oy}set offsetY(t){Debug&&(this.cx(t,"offsetY"),this._(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).je(0);static Default=new Spot(0,0,-1,0).je(-1);static TopLeft=new Spot(0,0,0,0).Ct();static TopCenter=new Spot(.5,0,0,0).Ct();static TopRight=new Spot(1,0,0,0).Ct();static LeftCenter=new Spot(0,.5,0,0).Ct();static Center=new Spot(.5,.5,0,0).Ct();static RightCenter=new Spot(1,.5,0,0).Ct();static BottomLeft=new Spot(0,1,0,0).Ct();static BottomCenter=new Spot(.5,1,0,0).Ct();static BottomRight=new Spot(1,1,0,0).Ct();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).je(1);static LeftSide=new Spot(0,0,1,2).je(1);static RightSide=new Spot(0,0,1,4).je(1);static BottomSide=new Spot(0,0,1,8).je(1);static TopBottomSides=new Spot(0,0,1,9).je(1);static LeftRightSides=new Spot(0,0,1,6).je(1);static TopLeftSides=new Spot(0,0,1,3).je(1);static TopRightSides=new Spot(0,0,1,5).je(1);static BottomLeftSides=new Spot(0,0,1,10).je(1);static BottomRightSides=new Spot(0,0,1,12).je(1);static NotTopSide=new Spot(0,0,1,14).je(1);static NotLeftSide=new Spot(0,0,1,13).je(1);static NotRightSide=new Spot(0,0,1,11).je(1);static NotBottomSide=new Spot(0,0,1,7).je(1);static AllSides=new Spot(0,0,1,15).je(1);static zk=new Spot(.156,.156).Ct();static Xk=new Spot(.844,.844).Ct()}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}Ki(){return this.m11=1,this.m12=0,this.m21=0,this.m22=1,this.dx=0,this.dy=0,this}Af(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}vA(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,a=this.m12*e+this.m22*s,f=this.m11*n+this.m21*o,c=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=a,this.m21=f,this.m22=c,this}ux(){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}Ns(t,i,e){if(t=G.Yi(t),t===0)return this;this.Hs(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 a=t*Math.PI/180;s=Math.cos(a),n=Math.sin(a)}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.Hs(-i,-e),this}Hs(t,i){return this.dx+=this.m11*t+this.m21*i,this.dy+=this.m12*t+this.m22*i,this}lt(t,i){return i===void 0&&(i=t),this.m11*=t,this.m12*=t,this.m21*=i,this.m22*=i,this}ZI(){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}St(t){const i=t.x,e=t.y;return t.e(i*this.m11+e*this.m21+this.dx,i*this.m12+e*this.m22+this.dy)}De(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.e(r*e+l*n,r*s+l*o)}Tu(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,a=t.y*1.2;return t.e(h*e+a*n+r,h*s+a*o+l)}am(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,a=this.dx,f=this.dy,c=i*o+e*l+a,u=i*r+e*h+f,d=s*o+e*l+a,m=s*r+e*h+f,g=i*o+n*l+a,p=i*r+n*h+f,y=s*o+n*l+a,x=s*r+n*h+f;let b=c,S=c,k=u,P=u;return b=Math.min(b,d),S=Math.max(S,d),k=Math.min(k,m),P=Math.max(P,m),b=Math.min(b,g),S=Math.max(S,g),k=Math.min(k,p),P=Math.max(P,p),b=Math.min(b,y),S=Math.max(S,y),k=Math.min(k,x),P=Math.max(P,x),t.e(b,k,S-b,P-k),t}static WA=[];static a(){const t=Transform.WA.pop();return t===void 0?new Transform:t}static o(t){Transform.WA.push(t)}static Kk="54a702f3e53909c447824c6706603faf4c"}const G={QI:"7da71ca0ad381e90",Zn:4*((Math.sqrt(2)-1)/3),jA:[],gx:w=>{if(w<=0)return 0;let t=G.jA;if(t===null){t=[];for(let i=0;i<=2e3;i++)t[i]=Math.sqrt(i);G.jA=t}if(w<1){const i=1/w;return i<=2e3?1/t[i|0]:Math.sqrt(w)}else return w<=2e3?t[w|0]:Math.sqrt(w)},u:(w,t)=>{const i=w-t;return i<.5&&i>-.5},q:(w,t)=>{const i=w-t;return i<5e-8&&i>-5e-8},Ui:(w,t,i,e,s,n,o)=>{s<=0&&(s=1e-6);let r=0,l=0,h=0,a=0;if(wu-d)if(w-i>s||i-w>s){const g=(e-t)/(i-w)*(n-w)+t;if(g-s<=o&&o<=g+s)return!0}else return!0;else if(t-e>s||e-t>s){const g=(i-w)/(e-t)*(o-t)+w;if(g-s<=n&&n<=g+s)return!0}else return!0}return!1},mx:(w,t,i,e,s,n,o,r,l,h,a,f)=>{if(!G.Ui(w,t,o,r,f,i,e)||!G.Ui(w,t,o,r,f,s,n)){const c=(w+i)/2,u=(t+e)/2,d=(i+s)/2,m=(e+n)/2,g=(s+o)/2,p=(n+r)/2,y=(c+d)/2,x=(u+m)/2,b=(d+g)/2,S=(m+p)/2,k=(y+b)/2,P=(x+S)/2;return G.mx(w,t,c,u,y,x,k,P,l,h,a,f)||G.mx(k,P,b,S,g,p,o,r,l,h,a,f)}else return G.Ui(w,t,o,r,f,h,a)},JA:(w,t,i,e,s,n,o,r,l)=>{const h=(w+i)/2,a=(t+e)/2,f=(i+s)/2,c=(e+n)/2,u=(s+o)/2,d=(n+r)/2,m=(h+f)/2,g=(a+c)/2,p=(f+u)/2,y=(c+d)/2;return l.e((m+p)/2,(g+y)/2),l},_I:(w,t,i,e,s,n,o,r)=>{const l=(w+i)/2,h=(t+e)/2,a=(i+s)/2,f=(e+n)/2,c=(s+o)/2,u=(n+r)/2,d=(l+a)/2,m=(h+f)/2,g=(a+c)/2,p=(f+u)/2;return Point.direction(d,m,g,p)},Lu:(w,t,i,e,s,n,o,r,l,h)=>{if(!G.Ui(w,t,o,r,l,i,e)||!G.Ui(w,t,o,r,l,s,n)){const a=(w+i)/2,f=(t+e)/2,c=(i+s)/2,u=(e+n)/2,d=(s+o)/2,m=(n+r)/2,g=(a+c)/2,p=(f+u)/2,y=(c+d)/2,x=(u+m)/2,b=(g+y)/2,S=(p+x)/2;G.Lu(w,t,a,f,g,p,b,S,l,h),G.Lu(b,S,y,x,d,m,o,r,l,h)}else h.ai(w,t,0,0),h.ai(o,r,0,0);return h},Qn:(w,t,i,e,s,n,o,r,l,h)=>{if(!G.Ui(w,t,o,r,l,i,e)||!G.Ui(w,t,o,r,l,s,n)){const a=(w+i)/2,f=(t+e)/2,c=(i+s)/2,u=(e+n)/2,d=(s+o)/2,m=(n+r)/2,g=(a+c)/2,p=(f+u)/2,y=(c+d)/2,x=(u+m)/2,b=(g+y)/2,S=(p+x)/2;G.Qn(w,t,a,f,g,p,b,S,l,h),G.Qn(b,S,y,x,d,m,o,r,l,h)}else h.length===0&&(h.push(w),h.push(t)),h.push(o),h.push(r);return h},Uk:(w,t,i,e,s,n,o,r,l,h)=>{if(G.Ui(w,t,s,n,h,i,e))return G.Ui(w,t,s,n,h,r,l);{const a=(w+i)/2,f=(t+e)/2,c=(i+s)/2,u=(e+n)/2,d=(a+c)/2,m=(f+u)/2;return G.Uk(w,t,a,f,d,m,o,r,l,h)||G.Uk(d,m,c,u,s,n,o,r,l,h)}},Gk:(w,t,i,e,s,n,o,r)=>{if(G.Ui(w,t,s,n,o,i,e))r.ai(w,t,0,0),r.ai(s,n,0,0);else{const l=(w+i)/2,h=(t+e)/2,a=(i+s)/2,f=(e+n)/2,c=(l+a)/2,u=(h+f)/2;G.Gk(w,t,l,h,c,u,o,r),G.Gk(c,u,a,f,s,n,o,r)}return r},fm:(w,t,i,e,s,n,o,r)=>{if(G.Ui(w,t,s,n,o,i,e))r.length===0&&(r.push(w),r.push(t)),r.push(s),r.push(n);else{const l=(w+i)/2,h=(t+e)/2,a=(i+s)/2,f=(e+n)/2,c=(l+a)/2,u=(h+f)/2;G.fm(w,t,l,h,c,u,o,r),G.fm(c,u,a,f,s,n,o,r)}return r},cm:(w,t,i,e,s,n,o,r,l,h,a,f,c,u)=>{if(!G.Ui(w,t,o,r,c,i,e)||!G.Ui(w,t,o,r,c,s,n)){const d=(w+i)/2,m=(t+e)/2,g=(i+s)/2,p=(e+n)/2,y=(s+o)/2,x=(n+r)/2,b=(d+g)/2,S=(m+p)/2,k=(g+y)/2,P=(p+x)/2,A=(b+k)/2,C=(S+P)/2;let M=1/0,N=!1,T=0,L=0;if(G.cm(w,t,d,m,b,S,A,C,l,h,a,f,c,u)){const D=(u.x-l)**2+(u.y-h)**2;D{let u=0;if(!G.Ui(w,t,o,r,c,i,e)||!G.Ui(w,t,o,r,c,s,n)){const d=(w+i)/2,m=(t+e)/2,g=(i+s)/2,p=(e+n)/2,y=(s+o)/2,x=(n+r)/2,b=(d+g)/2,S=(m+p)/2,k=(g+y)/2,P=(p+x)/2,A=(b+k)/2,C=(S+P)/2;u+=G.um(w,t,d,m,b,S,A,C,l,h,a,f,c),u+=G.um(A,C,k,P,y,x,o,r,l,h,a,f,c)}else{const d=(w-o)*(h-f)-(t-r)*(l-a);if(d===0)return u;const m=((w*r-t*o)*(l-a)-(w-o)*(l*f-h*a))/d,g=((w*r-t*o)*(h-f)-(t-r)*(l*f-h*a))/d;if(m>=a)return u;let p=0,y=0;if((l>a?l-a:a-l)<(h>f?h-f:f-h)){if(ty)return u}else if(wy)return u;d>0?u++:d<0&&u--}return u},Ll:(w,t,i,e,s,n,o)=>{if(G.q(w,i)){let r=0,l=0;tl?(o.e(w,l),!1):(o.e(w,h),!0)}else if(G.q(t,e)){let r=0,l=0;wl?(o.e(l,t),!1):(o.e(h,t),!0)}else{const r=(i-w)**2+(e-t)**2,l=((w-s)*(w-i)+(t-n)*(t-e))/r;if(l<-5e-6)return o.e(w,t),!1;if(l>1.000005)return o.e(i,e),!1;{const h=w+l*(i-w),a=t+l*(e-t);return o.e(h,a),!0}}},Eo:(w,t,i,e,s,n,o,r,l)=>{if(G.u(w,i)&&G.u(t,e))return l.e(w,t),!1;if(G.q(s,o)){if(G.q(w,i))return G.Ll(w,t,i,e,s,n,l),!1;{const a=(e-t)/(i-w)*(s-w)+t;return G.Ll(w,t,i,e,s,a,l)}}else{const h=(r-n)/(o-s);if(G.q(w,i)){const a=h*(w-s)+n;let f=0,c=0;return tc?(l.e(w,c),!1):(l.e(w,a),!0)}else{const a=(e-t)/(i-w);if(G.q(h,a))return G.Ll(w,t,i,e,s,n,l),!1;{const f=(a*w-h*s+n-t)/(a-h);if(G.q(a,0)){let c=0,u=0;return wu?(l.e(u,t),!1):(l.e(f,t),!0)}else{const c=a*(f-w)+t;return G.Ll(w,t,i,e,f,c,l)}}}}},Dl:(w,t,i,e,s,n,o,r,l)=>{let h=1e21,a=w,f=t;if(G.Eo(w,t,w,e,s,n,o,r,l)){const c=(l.x-s)**2+(l.y-n)**2;cG.qA(w.x,w.y,w.width,w.height,t.x,t.y,i.x,i.y),qA:(w,t,i,e,s,n,o,r)=>{const l=w,h=w+i,a=t,f=t+e;if(s===o){let c=0,u=0;return n=a}if(n===r){let c=0,u=0;return s=l}return!!(Rect.contains(w,t,i,e,s,n)||Rect.contains(w,t,i,e,o,r)||G.Cu(l,a,h,a,s,n,o,r)||G.Cu(h,a,h,f,s,n,o,r)||G.Cu(h,f,l,f,s,n,o,r)||G.Cu(l,f,l,a,s,n,o,r))},Cu:(w,t,i,e,s,n,o,r)=>w===i&&t===e&&s===o&&n===r?w===s&&t===n:G.Nu(w,t,i,e,s,n)*G.Nu(w,t,i,e,o,r)<=0&&G.Nu(s,n,o,r,w,t)*G.Nu(s,n,o,r,i,e)<=0,Nu:(w,t,i,e,s,n)=>{const o=i-w,r=e-t;let l=s-w,h=n-t,a=l*r-h*o;return a===0&&(a=l*o+h*r,a>0&&(l-=o,h-=r,a=l*o+h*r,a<0&&(a=0))),a},lx(w,t,i,e){e===void 0&&(e=!1);let s=0;const n=w===null?t:(t-w.x)/(w.width>0?w.width:1),o=w===null?i:(i-w.y)/(w.height>0?w.height:1);return n>o?n>1-o||(e||n<1-o?s=270:s=315):e||n1-o?s=90:e||n<1-o?s=180:s=135:n<.5?s=225:n>.5&&(s=45),s},Yi:w=>(w>=360?w-=360:w<0&&(w+=360),w),tR:(w,t)=>w>t?Math.min(w-t,Math.abs(w-360-t)):t>w?Math.min(t-w,Math.abs(w-(t-360))):0,$A:(w,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,a=[],f=o/2;let c=e,u=Math.min(h,Math.abs(s-e));if(ul;){const d=c+r*Math.min(u,f);a.push(G.iR(i,c,d,w,t)),u-=Math.abs(d-c),c=d}return a},iR:(w,t,i,e,s)=>{const n=(i-t)/2,o=w*Math.cos(n),r=w*Math.sin(n),l=o,h=-r,a=l*l+h*h,f=a+l*o+h*r,c=4/3*(Math.sqrt(2*a*f)-f)/(l*r-h*o),u=l-c*h,d=h+c*l,m=u,g=-d,p=n+t,y=Math.cos(p),x=Math.sin(p);return[e+w*Math.cos(t),s+w*Math.sin(t),e+u*y-d*x,s+u*x+d*y,e+m*y-g*x,s+m*x+g*y,e+w*Math.cos(i),s+w*Math.sin(i)]},rm:(w,t,i,e,s,n,o)=>{const r=s,l=n,h=Math.floor((w-i)/r)*r+i,a=Math.floor((t-e)/l)*l+e;let f=h;h+r-w{let i=Math.max(w,t),e=Math.min(w,t),s=1,n=1;do s=i%e,n=e,i=e,e=s;while(s>0);return n},eR:(w,t,i,e)=>{const s=i<0,n=e<0;let o=0,r=0,l=0;w{let o=0;if(e>0)if(i>0){const r=w*w,l=t*t,h=w*i,a=t*e;let f=-l+a,c=-l+Math.sqrt(h*h+a*a),u=f;const d=9999999999;for(let p=0;p0)f=u;else if(b<0)c=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=w*w-t*t,l=w*i;if(l(w[w.Line=1]="Line",w[w.Rectangle=2]="Rectangle",w[w.Ellipse=3]="Ellipse",w[w.Path=4]="Path",w))(GeometryType||{}),GeometryStretch=(w=>(w[w.None=0]="None",w[w.Default=1]="Default",w[w.Fill=2]="Fill",w[w.Uniform=6]="Uniform",w))(GeometryStretch||{});class Geometry{l;mm;pm;Tf;Du;Fu;_n;to;io;tt;Fe;Ie;le;he;vs;Lf;Df;constructor(t,i){Debug&&arguments.length>2&&U.n("Geometry constructor can take at most two optional arguments, the Geometry type and an initialization Object"),GSet._i(this),this.l=2,t===void 0?t=4:Debug&&U.W(t,GeometryType,"GeometryType"),this.tt=t,this.Fe=0,this.Ie=0,this.le=0,this.he=0,t===4?this.vs=new List:this.vs=Geometry.wx,this.mm=this.vs.ct,this.pm=new Rect,this.Tf=null,this.Du=null,this.Fu=NaN,this._n=Spot.TopLeft,this.to=Spot.BottomRight,this.Lf=NaN,this.Df=NaN,this.io=2,i&&Object.assign(this,i)}copy(){const t=new Geometry;if(t.l=this.l&-2,t.tt=this.tt,t.Fe=this.Fe,t.Ie=this.Ie,t.le=this.le,t.he=this.he,this.tt===4){const i=this.vs.h,e=t.vs;for(let s=0;si.toString(t)}gi(t){t in GeometryType?this.type=t:U.wr(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.h,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.Ti(t,"string",Geometry,"fillPath:str");const i=t.split(/[Xx]/),e=i.length;let s="";for(let n=0;n=b-1||o[r+1].match(M)!==null?!0:(u=!1,!1)}function m(){return r++,o[r]}function g(T){let L=parseFloat(m()),D=parseFloat(m());l===l.toLowerCase()&&(L=c.x+L,D=c.y+D),T.e(L,D)}function p(){return g(c),c}function y(){return g(f),f}function x(){const T=h.toLowerCase();return T==="c"||T==="s"||T==="q"||T==="t"?new Point(2*c.x-f.x,2*c.y-f.y):new Point(c.x,c.y)}const b=o.length,S=GeoStream._A(null);let k=!1,P=!1,A=!1,C=!0;const M=new RegExp("["+Geometry.ym+"]");for(;!(r>=b-1);){if(h=l,l=m(),l==="")continue;u=!0;let T=!1;switch(l.toUpperCase()){case"X":C=!0,k=!1,P=!1;break;case"M":const L=p();for(S.Li===null||C===!0?(S.Iu(L.x,L.y,k,!1,!P,A),C=!1):S.nR(L.x,L.y),a.c(c);!d();){const D=p();S.Ws(D.x,D.y)}break;case"L":for(;!d();){const D=p();S.Ws(D.x,D.y)}u&&(T=!0);break;case"H":for(;!d();)c.e((l===l.toLowerCase()?c.x:0)+parseFloat(m()),c.y),S.Ws(c.x,c.y);break;case"V":for(;!d();)c.e(c.x,(l===l.toLowerCase()?c.y:0)+parseFloat(m())),S.Ws(c.x,c.y);u&&(T=!0);break;case"C":for(;!d();){const D=new Point;g(D);const F=y(),R=p();S.Pr(D.x,D.y,F.x,F.y,R.x,R.y)}u&&(T=!0);break;case"S":for(;!d();){const D=x(),F=y(),R=p();S.Pr(D.x,D.y,F.x,F.y,R.x,R.y)}u&&(T=!0);break;case"Q":for(;!d();){const D=y(),F=p();S.Ru(D.x,D.y,F.x,F.y)}u&&(T=!0);break;case"T":for(;!d();){const D=x();f.c(D);const F=p();S.Ru(D.x,D.y,F.x,F.y),f.c(F)}u&&(T=!0);break;case"B":for(;!d();){const D=parseFloat(m()),F=parseFloat(m());let R=parseFloat(m()),I=parseFloat(m());const O=parseFloat(m());let X=O,K=!1;d()||(X=parseFloat(m()),d()||(K=parseFloat(m())!==0)),l===l.toLowerCase()&&(R+=c.x,I+=c.y),S.oR(D,F,R,I,O,X,K)}u&&(T=!0);break;case"A":for(;!d();){const D=Math.abs(parseFloat(m())),F=Math.abs(parseFloat(m())),R=parseFloat(m());let I=!1,O=!1,X=0,K=0;const B=m();B.length===1?(I=!!parseFloat(B),O=!!parseFloat(m()),X=parseFloat(m()),K=parseFloat(m())):B.length===2?(I=!!parseFloat(B[0]),O=!!parseFloat(B[1]),X=parseFloat(m()),K=parseFloat(m())):(I=!!parseFloat(B[0]),O=!!parseFloat(B[1]),X=parseFloat(B.slice(2)),K=parseFloat(m())),l===l.toLowerCase()&&(X=c.x+X,K=c.y+K),c.e(X,K),S.rR(D,F,R,I,O,X,K)}u&&(T=!0);break;case"Z":S.lR(),c.c(a);break;case"F":{let D="",F=1;for(;o[r+F];){if(o[r+F]==="0"){A=!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]/)?k=!0:S.hR();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]/)?P=!0:S.aR(!1);break}default:if(l==="0"||l==="1")break;U.ot("Unknown geometry command: "+l);break}if(T){U.ot(`Bad geometry command: ${l}, next token: ${m()}, string: ${t}`);break}}const N=S.wm;if(GeoStream.tT(S),i){const T=N.figures.iterator;for(;T.next();){const L=T.value;L.isFilled=!0}}return N}static iT(t,i){const e=t.length,s=Point.a();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(fo)return 0}else if(nr)return 0}else if(an)return 0;return h>0?1:-1}sT(t,i,e){const s=this.figures.h,n=s.length;for(let o=0;o1&&(t=1),i===void 0&&(i=new Point),this.type===1)return i.e(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[c*2],y=g[c*2+1],x=g[c*2+2],b=g[c*2+3];return i.e(p+(x-p)*m,y+(b-y)*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[f*2],m=u[f*2+1],g=u[f*2+2],p=u[f*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+=c}}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[c*2],y=g[c*2+1],x=g[c*2+2],b=g[c*2+3];i[0]=p+(x-p)*m,i[1]=y+(b-y)*m;let S;return Math.abs(x-p)<1&&Math.abs(b-y)<1?S=0:Math.abs(x-p)<1?S=b-y>=0?90:270:Math.abs(b-y)<1?S=x-p>=0?0:180:S=Math.atan2(b-y,x-p)*180/Math.PI,i[2]=S,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 a=(s-i)**2+(n-e)**2,f=Point.a();G.Ll(i,e,s,n,o,r,f);const c=f.x,u=f.y;return Point.o(f),Math.sqrt(((c-i)**2+(u-e)**2)/a)}}}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,a=t.y;h=Math.min(Math.max(h,i),s),a=Math.min(Math.max(a,e),n);const f=Math.abs(h-i),c=Math.abs(h-s),u=Math.abs(a-e),d=Math.abs(a-n),m=Math.min(f,c,u,d);if(m===u)return h/l;if(m===c)return(o+a)/l;if(m===d)return(o*2+r-h)/l;if(m===f)return(o*2+r*2-a)/l}}else{const i=this.flattenedSegments,e=this.flattenedLengths,s=this.flattenedTotalLength,n=Point.a();let o=1/0,r=0,l=0;const h=i.length;let a=0,f=0;for(let u=0;u1?1:c}return 0}get flattenedSegments(){return this.nT(),this.Tf}nT(){if(this.Tf===null){const t=this.Tf=[],i=this.Du=[];this.uR(t,i)}}get flattenedLengths(){return this.nT(),this.Du}get flattenedTotalLength(){let t=this.Fu;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.Wk(e))),e=[],e.push(d.endX),e.push(d.endY),r=d.endX,l=d.endY,h=r,a=l;break;case 2:e.push(d.endX),e.push(d.endY),r=d.endX,l=d.endY;break;case 3:G.Qn(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:G.fm(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.Wk(e)))}}}get type(){return this.tt}set type(t){this.tt!==t&&(Debug&&U.W(t,GeometryType,"GeometryType"),this.p&&U.D(this,t),this.tt=t,t===4?this.vs=new List:(Geometry.wx===null&&(Geometry.wx=new List().k()),this.vs=Geometry.wx),this.kt=!0)}get startX(){return this.Fe}set startX(t){this.Fe!==t&&(Debug&&U.r(t,Geometry,"startX"),this.p&&U.D(this,t),this.Fe=t,this.kt=!0)}get startY(){return this.Ie}set startY(t){this.Ie!==t&&(Debug&&U.r(t,Geometry,"startY"),this.p&&U.D(this,t),this.Ie=t,this.kt=!0)}get endX(){return this.le}set endX(t){this.le!==t&&(Debug&&U.r(t,Geometry,"endX"),this.p&&U.D(this,t),this.le=t,this.kt=!0)}get endY(){return this.he}set endY(t){this.he!==t&&(Debug&&U.r(t,Geometry,"endY"),this.p&&U.D(this,t),this.he=t,this.kt=!0)}get figures(){return this.vs}set figures(t){this.vs!==t&&(Debug&&U.s(t,List,Geometry,"figures"),this.p&&U.D(this,t),this.vs=t,this.kt=!0)}add(t){return Debug&&U.s(t,PathFigure,Geometry,"add"),this.vs.add(t),this}setSpots(t,i,e,s,n,o,r,l){return this.p&&U.D(this),this._n=new Spot(t,i,n,o),this.to=new Spot(e,s,r,l),this}get spot1(){return this._n}set spot1(t){Debug&&U.s(t,Spot,Geometry,"spot1"),this.p&&U.D(this,t),this._n=t.T()}get spot2(){return this.to}set spot2(t){Debug&&U.s(t,Spot,Geometry,"spot2"),this.p&&U.D(this,t),this.to=t.T()}get defaultStretch(){return this.io}set defaultStretch(t){this.io=t}get bounds(){return this.qk()&&this.xx(),this.pm}polygonClosestSegment(t,i){if(i===void 0&&(i=10),this.type!==4)return null;const e=t.x,s=t.y;let n=1/0,o=0,r=0,l=0,h=0,a=0,f=0,c=0,u=0;return this.figures.each(d=>{let m=d.startX,g=d.startY;d.segments.each(p=>{let y=p.endX,x=p.endY,b=0;if(p.type===2)b=Point.distanceLineSegmentSquared(e,s,m,g,y,x);else{m=p.endX,g=p.endY;return}bs.x===n.x?n.y-s.y:n.x-s.x);const i=[];for(let s=0;s=2&&t[s].compareWithLineSegmentPoint(i[i.length-2],i[i.length-1])>=0;)i.pop();i.push(t[s])}i.pop();const e=[];for(let s=t.length-1;s>=0;s--){for(;e.length>=2&&t[s].compareWithLineSegmentPoint(e[e.length-2],e[e.length-1])>=0;)e.pop();e.push(t[s])}return e.pop(),i.concat(e)}static generatePolygon(t,i,e){i===void 0&&(i=0),e===void 0&&(e=!0);const s=new Geometry;if(t.length>1)if(i>0)if(e){t.push(t[0]),t.push(t[1]);let n=!0;const o=new PathFigure(0,0,e,!1);for(let l=1;l1){const u=t[o-1].x+(t[o].x-t[o-1].x)*a,d=t[o-1].y+(t[o].y-t[o-1].y)*a;n.add(new PathSegment(3,u,d,t[o-1].x,t[o-1].y,t[o-1].x,t[o-1].y))}const f=t[o].x+(t[o-1].x-t[o].x)*a,c=t[o].y+(t[o-1].y-t[o].y)*a;n.add(new PathSegment(2,f,c))}else o>1&&n.add(new PathSegment(3,r,l,t[o-1].x,t[o-1].y,t[o-1].x,t[o-1].y));o===t.length-1&&n.add(new PathSegment(2,t[o].x,t[o].y))}s.add(n)}else{const n=new PathFigure(t[0].x,t[0].y,e,!1);for(let o=1;oo===0?"0":o.toFixed(t);i="M"+n(this.startX)+" "+n(this.startY)}const e=this.segments.h,s=e.length;for(let n=0;n(w[w.Move=1]="Move",w[w.Line=2]="Line",w[w.Bezier=3]="Bezier",w[w.QuadraticBezier=4]="QuadraticBezier",w[w.Arc=5]="Arc",w[w.SvgArc=6]="SvgArc",w))(SegmentType||{});class PathSegment{tt;l;le;he;bn;Fl;Il;Mr;js;constructor(t,i,e,s,n,o,r,l){if(GSet._i(this),t===void 0?t=2:Debug&&U.W(t,SegmentType,"SegmentType"),this.tt=t,this.l=2,i!==void 0?(Debug&&U.r(i,PathSegment,"ex"),this.le=i):this.le=0,e!==void 0?(Debug&&U.r(e,PathSegment,"ey"),this.he=e):this.he=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.bn=h,this.Fl=0,Debug&&U.r(s,PathSegment,"x1"),this.Il=Math.max(s,0),Debug&&U.r(n,PathSegment,"y1"),this.Mr=Math.max(n,0),typeof r=="boolean"?r&&(this.isLargeArc=!0):typeof r=="number"&&r&&(this.isLargeArc=!0),l&&(this.isClockwiseArc=!0)}else Debug&&U.r(s,PathSegment,"x1"),this.bn=s,Debug&&U.r(n,PathSegment,"y1"),this.Fl=n,Debug&&U.r(o,PathSegment,"x2"),t===5&&(o=Math.max(o,0)),this.Il=o,typeof r=="number"?(t===5&&(r=Math.max(r,0)),this.Mr=r):this.Mr=0;this.js=null}copy(){const t=new PathSegment;return t.tt=this.tt,t.l=this.l&-2,t.le=this.le,t.he=this.he,t.bn=this.bn,t.Fl=this.Fl,t.Il=this.Il,t.Mr=this.Mr,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 G.u(this.endX,t.endX)&&G.u(this.endY,t.endY);case 3:return G.u(this.endX,t.endX)&&G.u(this.endY,t.endY)&&G.u(this.point1X,t.point1X)&&G.u(this.point1Y,t.point1Y)&&G.u(this.point2X,t.point2X)&&G.u(this.point2Y,t.point2Y);case 4:return G.u(this.endX,t.endX)&&G.u(this.endY,t.endY)&&G.u(this.point1X,t.point1X)&&G.u(this.point1Y,t.point1Y);case 5:return G.u(this.startAngle,t.startAngle)&&G.u(this.sweepAngle,t.sweepAngle)&&G.u(this.centerX,t.centerX)&&G.u(this.centerY,t.centerY)&&G.u(this.radiusX,t.radiusX)&&G.u(this.radiusY,t.radiusY);case 6:return this.isClockwiseArc===t.isClockwiseArc&&this.isLargeArc===t.isLargeArc&&G.u(this.xAxisRotation,t.xAxisRotation)&&G.u(this.endX,t.endX)&&G.u(this.endY,t.endY)&&G.u(this.radiusX,t.radiusX)&&G.u(this.radiusY,t.radiusY);default:return!1}}gi(t){t in SegmentType?this.type=t:U.wr(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 p(){return(this.l&1)!==0}set p(t){t?this.l|=1:this.l&=-2}get kt(){return(this.l&2)!==0}set kt(t){t?this.l|=2:this.l&=-3}k(){return this.p=!0,this}close(){return this.isClosed=!0,this}Bo(t){if(this.js!==null&&t.kt===!1)return this.js;const i=this.radiusX;let e=this.radiusY;if(e===void 0&&(e=i),i===0||e===0)return this.js=[],this.js;const s=this.bn,n=this.Fl,o=G.$A(0,0,i1&&(o*=Math.sqrt(p),r*=Math.sqrt(p));let y=(h===a?-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(y)&&(y=0);let x=y*o*g/r,b=y*-r*m/o;isNaN(x)&&(x=0),isNaN(b)&&(b=0);const S=(s+f)/2+u*x-d*b,k=(n+c)/2+d*x+u*b,P=(Y,z)=>Math.sqrt(Y*Y+z*z),A=(Y,z,H,W)=>(Y*H+z*W)/(P(Y,z)*P(H,W)),C=(Y,z,H,W)=>(Y*W=1&&(F=0),!a&&F>0&&(F=F-2*Math.PI),a&&F<0&&(F=F+2*Math.PI);const I=o>r?o:r,O=o>r?1:o/r,X=o>r?r/o:1,K=G.$A(0,0,I,M,M+F,!0),B=Transform.a();return B.Ki(),B.Hs(S,k),B.Ns(this.bn,0,0),B.lt(O,X),Geometry.iT(K,B),Transform.o(B),this.js=K,this.js}get isClosed(){return(this.l&8)!==0}set isClosed(t){this.isClosed!==t&&(t?this.l|=8:this.l&=-9,this.kt=!0)}get type(){return this.tt}set type(t){Debug&&U.W(t,SegmentType,"SegmentType"),this.p&&U.D(this,t),this.tt=t,this.kt=!0}get endX(){return this.le}set endX(t){Debug&&U.r(t,PathSegment,"endX"),this.p&&U.D(this,t),this.le=t,this.kt=!0}get endY(){return this.he}set endY(t){Debug&&U.r(t,PathSegment,"endY"),this.p&&U.D(this,t),this.he=t,this.kt=!0}get point1X(){return this.bn}set point1X(t){Debug&&U.r(t,PathSegment,"point1X"),this.p&&U.D(this,t),this.bn=t,this.kt=!0}get point1Y(){return this.Fl}set point1Y(t){Debug&&U.r(t,PathSegment,"point1Y"),this.p&&U.D(this,t),this.Fl=t,this.kt=!0}get point2X(){return this.Il}set point2X(t){Debug&&U.r(t,PathSegment,"point2X"),this.p&&U.D(this,t),this.Il=t,this.kt=!0}get point2Y(){return this.Mr}set point2Y(t){Debug&&U.r(t,PathSegment,"point2Y"),this.p&&U.D(this,t),this.Mr=t,this.kt=!0}get centerX(){return this.bn}set centerX(t){Debug&&U.r(t,PathSegment,"centerX"),this.p&&U.D(this,t),this.bn=t,this.kt=!0}get centerY(){return this.Fl}set centerY(t){Debug&&U.r(t,PathSegment,"centerY"),this.p&&U.D(this,t),this.Fl=t,this.kt=!0}get radiusX(){return this.Il}set radiusX(t){Debug&&U.r(t,PathSegment,"radiusX"),t<0&&U.G(t,">= zero",PathSegment,"radiusX"),this.p&&U.D(this,t),this.Il=t,this.kt=!0}get radiusY(){return this.Mr}set radiusY(t){Debug&&U.r(t,PathSegment,"radiusY"),t<0&&U.G(t,">= zero",PathSegment,"radiusY"),this.p&&U.D(this,t),this.Mr=t,this.kt=!0}get startAngle(){return this.le}set startAngle(t){Debug&&U.r(t,PathSegment,"startAngle"),this.p&&U.D(this,t),t=t%360,t<0&&(t+=360),this.le=t,this.kt=!0}get sweepAngle(){return this.he}set sweepAngle(t){Debug&&U.r(t,PathSegment,"sweepAngle"),this.p&&U.D(this,t),t>360&&(t=360),t<-360&&(t=-360),this.he=t,this.kt=!0}get isClockwiseArc(){return(this.l&4)!==0}set isClockwiseArc(t){this.p&&U.D(this,t),t?this.l|=4:this.l&=-5,this.kt=!0}get isLargeArc(){return(this.l&16)!==0}set isLargeArc(t){this.p&&U.D(this,t),t?this.l|=16:this.l&=-17,this.kt=!0}get xAxisRotation(){return this.bn}set xAxisRotation(t){Debug&&U.r(t,PathSegment,"xAxisRotation"),this.p&&U.D(this,t),t=t%360,t<0&&(t+=360),this.bn=t,this.kt=!0}}class InputEvent{f;kx;Px;bm;Sm;km;Pm;Mm;Nm;Cm;Am;Tm;Lm;Dm;Vo;Fm;Im;Cs;Re;constructor(){this.f=null,this.kx=new Point(0,0).k(),this.Px=new Point(0,0).k(),this.bm=0,this.Sm=0,this.km=1,this.Pm="",this.Mm="",this.Nm=!1,this.Cm=!1,this.Am=0,this.Tm=0,this.Lm=!1,this.Dm=!1,this.Vo=!1,this.Fm=null,this.Im=0,this.Cs=null,this.Re=null}copy(){const t=new InputEvent;return this.clone(t)}clone(t){return t.f=this.f,t.kx.c(this.viewPoint),t.Px.c(this.documentPoint),t.bm=this.bm,t.Sm=this.Sm,t.km=this.km,t.Pm=this.Pm,t.Mm=this.Mm,t.Nm=this.Nm,t.Cm=this.Cm,t.Am=this.Am,t.Tm=this.Tm,t.Lm=this.Lm,t.Dm=this.Dm,t.Vo=this.Vo,t.Fm=this.Fm,t.Im=this.Im,t.Cs=this.Cs,t.Re=this.Re,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.f}set diagram(t){this.f=t}get viewPoint(){return this.kx}set viewPoint(t){Debug&&U.s(t,Point,InputEvent,"viewPoint"),this.kx.c(t)}get documentPoint(){return this.Px}set documentPoint(t){Debug&&U.s(t,Point,InputEvent,"documentPoint"),this.Px.c(t)}getMultiTouchViewPoint(t,i){const e=this.diagram;return e===null||e.oT(this.event,t,i),i}getMultiTouchDocumentPoint(t,i){const e=this.diagram;return e===null||(e.oT(this.event,t,i),i.c(e.transformViewToDoc(i))),i}get modifiers(){return this.bm}set modifiers(t){this.bm=t}get button(){return this.Sm}set button(t){if(this.Sm=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.km}set buttons(t){this.km=t}get key(){return this.Pm}set key(t){this.Pm=t}get code(){return this.Mm}set code(t){this.Mm=t}get down(){return this.Nm}set down(t){this.Nm=t}get up(){return this.Cm}set up(t){this.Cm=t}get clickCount(){return this.Am}set clickCount(t){this.Am=t}get delta(){return this.Tm}set delta(t){this.Tm=t}get isMultiTouch(){return this.Lm}set isMultiTouch(t){this.Lm=t}get handled(){return this.Dm}set handled(t){this.Dm=t}get bubbles(){return this.Vo}set bubbles(t){this.Vo=t}get event(){return this.Fm}set event(t){this.Fm=t}get isTouchEvent(){const t=this.event;return t===null?!1:t.pointerType==="touch"||t.pointerType==="pen"}get timestamp(){return this.Im}set timestamp(t){this.Im=t}get targetDiagram(){return this.Cs}set targetDiagram(t){this.Cs=t}get targetObject(){return this.Re}set targetObject(t){this.Re=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{f;At;Rm;Om;constructor(){this.f=null,this.At="",this.Rm=null,this.Om=null}copy(){const t=new DiagramEvent;return t.f=this.f,t.At=this.At,t.Rm=this.Rm,t.Om=this.Om,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.f}set diagram(t){this.f=t}get name(){return this.At}set name(t){this.At=t}get subject(){return this.Rm}set subject(t){this.Rm=t}get parameter(){return this.Om}set parameter(t){this.Om=t}}var ChangeType=(w=>(w[w.Transaction=1]="Transaction",w[w.Property=2]="Property",w[w.Insert=3]="Insert",w[w.Remove=4]="Remove",w))(ChangeType||{});class ChangedEvent{Ou;Em;Sn;Di;f;Eu;If;Rf;Of;Ef;constructor(){this.Ou=2,this.Em="",this.Sn="",this.Di=null,this.f=null,this.Eu=null,this.If=null,this.Rf=null,this.Of=null,this.Ef=null}static Transaction=1;static Property=2;static Insert=3;static Remove=4;clear(){this.Di=null,this.f=null,this.Eu=null,this.If=null,this.Rf=null,this.Of=null,this.Ef=null}copy(){const t=new ChangedEvent;t.Ou=this.Ou,t.Em=this.Em,t.Sn=this.Sn,t.Di=this.Di,t.f=this.f,t.Eu=this.Eu;let i=this.If;return U.it(i)&&U.ht(i.copyFrozen)?t.If=i.copyFrozen():t.If=i,i=this.Rf,U.it(i)&&U.ht(i.copyFrozen)?t.Rf=i.copyFrozen():t.Rf=i,i=this.Of,U.it(i)&&U.ht(i.copyFrozen)?t.Of=i.copyFrozen():t.Of=i,i=this.Ef,U.it(i)&&U.ht(i.copyFrozen)?t.Ef=i.copyFrozen():t.Ef=i,t}gi(t){t in ChangeType?this.change=t:U.wr(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.rT(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.rT(this,!1))}get model(){return this.Di}set model(t){this.Di=t}get diagram(){return this.f}set diagram(t){this.f=t}get change(){return this.Ou}set change(t){this.Ou=t}get modelChange(){return this.Em}set modelChange(t){Debug&&U.i(t,"string",ChangedEvent,"modelChange"),this.Em=t}get propertyName(){return this.Sn}set propertyName(t){Debug&&typeof t!="string"&&U.C(t,ChangedEvent,"propertyName"),this.Sn=t}get isTransactionFinished(){return this.Ou===1&&(this.Sn==="CommittedTransaction"||this.Sn==="FinishedUndo"||this.Sn==="FinishedRedo")}get object(){return this.Eu}set object(t){this.Eu=t}get oldValue(){return this.If}set oldValue(t){this.If=t}get oldParam(){return this.Rf}set oldParam(t){this.Rf=t}get newValue(){return this.Of}set newValue(t){this.Of=t}get newParam(){return this.Ef}set newParam(t){this.Ef=t}}class Transaction{lT;At;jk;constructor(){this.lT=new List().k(),this.At="",this.jk=!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.k()}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.di(),i.removeAt(e)}i.k()}thaw(){this.changes.di()}optimize(){if(!this.isComplete)return;const t=this.changes;t.di();const i=new Map;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.k()}get changes(){return this.lT}get name(){return this.At}set name(t){this.At=t}get isComplete(){return this.jk}set isComplete(t){this.jk=t}}class UndoManager{Mx;Gi;hT;Js;Jk;Bm;Rl;Nx;$k;kn;Bf;Cx;$s;Ax;Tx;Vm;Lx;constructor(t){this.Mx=new GSet,this.Gi=!1,this.hT=new List().k(),this.Js=-1,this.Jk=999,this.$s=!1,this.Bm=null,this.Rl=0,this.Nx=!1,Debug&&(this.Nx=!0),this.$k=23,this.kn=new List().k(),this.Bf=new List,this.Cx=!0,this.Ax=!1,this.Tx=!1,this.Vm=!1,this.Lx=!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.Js=-1,t.k(),this.$s=!1,this.Bm=null,this.Rl=0,this.kn.di(),this.kn.clear(),this.kn.k(),this.Bf.clear(),this.Ax=!1,this.Tx=!1,this.Vm=!1,this.Lx=!1}copyProperties(t){this.isEnabled=t.isEnabled,this.maxHistoryLength=t.maxHistoryLength,this.Bu=t.Bu}addModel(t){this.Mx.add(t)}removeModel(t){this.Mx.delete(t)}startTransaction(t){if(t===void 0&&(t=""),t===null&&(t=""),this.isUndoingRedoing)return!1;this.Cx===!0&&(this.Cx=!1,this.Rl++,this.Ol||this.El("StartingFirstTransaction",t,this.currentTransaction),this.Rl>0&&this.Rl--),this.isEnabled&&(this.kn.di(),this.kn.add(t),this.kn.k(),this.currentTransaction===null?this.Bf.add(0):this.Bf.add(this.currentTransaction.changes.count)),this.Rl++;const i=this.transactionLevel===1;return i&&(this.Ol||this.El("StartedTransaction",t,this.currentTransaction)),i}commitTransaction(t){return t===void 0&&(t=""),this.aT(!0,t)}rollbackTransaction(){return this.aT(!1,"")}aT(t,i){if(this.isUndoingRedoing)return!1;this.Bu&&this.transactionLevel<1&&U.ot("Ending transaction without having started a transaction: "+i);const e=this.transactionLevel===1;let s=this.currentTransaction;e&&t&&(this.Ol||this.El("CommittingTransaction",i,s));let n=0;if(this.transactionLevel>0&&(this.Rl--,this.isEnabled)){const o=this.kn.count;o>0&&(i===""&&(i=this.kn.elt(0)),this.kn.di(),this.kn.removeAt(o-1),this.kn.k());const r=this.Bf.count;r>0&&(n=this.Bf.elt(r-1),this.Bf.removeAt(r-1))}if(e){if(t){if(this.Vm=!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.di();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.Js--}}l!==0&&(r.count===0||r.get(r.count-1)!==o)&&(r.add(o),this.Js++),r.k(),s=o}this.Ol||this.El("CommittedTransaction",i,s)}else{this.$s=!0;try{this.isEnabled&&s!==null&&(s.isComplete=!0,s.undo())}finally{this.Ol||this.El("RolledBackTransaction",i,s),this.$s=!1}s!==null&&s.clear()}return this.Bm=null,this.Dx&&this.clear(),this.Dx=!1,this.Fx=!1,!0}else return this.isEnabled&&!t&&s!==null&&s.dR(n),!1}discardHistoryAfterIndex(){if(this.isUndoingRedoing||!this.canRedo())return;const t=this.history;t.di();for(let i=t.count-1;i>this.historyIndex;i--){const e=t.elt(i);e!==null&&e.clear(),t.removeAt(i),this.Vm=!0}t.k()}thaw(){this.history.di()}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;if(t!==null)try{this.$s=!0,this.El("StartingUndo","Undo",t),this.Js--,t.undo()}catch(i){U.ot("undo error: "+i.toString())}finally{this.El("FinishedUndo","Undo",t),this.$s=!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;if(t!==null)try{this.$s=!0,this.El("StartingRedo","Redo",t),this.Js++,t.redo()}catch(i){U.ot("redo error: "+i.toString())}finally{this.El("FinishedRedo","Redo",t),this.$s=!1}}El(t,i,e){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.gR(s)}}handleChanged(t){if(this.isEnabled&&!this.isUndoingRedoing&&!this.skipsEvent(t)){let i=this.currentTransaction;i===null&&(i=new Transaction,this.Bm=i);const e=t.copy(),s=i.changes;if(s.di(),s.add(e),s.k(),this.Bu&&this.$k>0&&this.transactionLevel<=0&&!this.Cx){const n=t.diagram;if(n!==null&&n.oa===!1)return;U.ot("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.Mx.iterator}get isEnabled(){return this.Gi}set isEnabled(t){this.Gi=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 Bu(){return this.Nx}set Bu(t){this.Nx=t}get nestedTransactionNames(){return this.kn}get Dx(){return this.Ax}set Dx(t){this.Ax=t}get Fx(){return this.Tx}set Fx(t){this.Tx=t}get Ol(){return this.Lx}set Ol(t){this.Lx=t}get isJustDiscarded(){return this.Vm}}class Tool{f;At;Gi;Zk;Qk;zm;fT;constructor(){GSet._i(this),this.f=Diagram.Xm(),this.At="",this.Gi=!0,this.Zk=!1,this.Qk=null,this.fT=new InputEvent,this.zm=-1}get diagram(){return this.f}set diagram(t){t instanceof Diagram&&(this.f=t)}toString(){return this.name!==""?this.name+" Tool":U.Jn(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.U(NaN,NaN)),s=i.getMultiTouchViewPoint(1,Point.U(NaN,NaN));if(!e.isReal()||!s.isReal()){Point.o(e),Point.o(s);return}if(this.doCancel(),t.getInputOption("hasGestureZoom")){t._k=t.scale;const n=s.x-e.x,o=s.y-e.y,r=Math.sqrt(n*n+o*o);t.tP=r,i.bubbles=!1}Point.o(e),Point.o(s)}standardPinchZoomMove(){const t=this.diagram,i=t.lastInput,e=i.getMultiTouchViewPoint(0,Point.U(NaN,NaN)),s=i.getMultiTouchViewPoint(1,Point.U(NaN,NaN));if(!e.isReal()||!s.isReal()){Point.o(e),Point.o(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.tP,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),a=t._k*l,f=t.commandHandler;if(a!==t.scale&&f.canResetZoom(a)){const c=t.zoomPoint;t.zoomPoint=h,f.resetZoom(a),t.zoomPoint=c}i.bubbles=!1}Point.o(e),Point.o(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.yr?i.meta:i.control){t.F("ChangingSelection",t.selection);let s=e;for(;s!==null&&!s.canSelect();)s=s.containingGroup;s!==null&&(s.isSelected=!s.isSelected),t.F("ChangedSelection",t.selection)}else if(i.shift){if(!e.isSelected){t.F("ChangingSelection",t.selection);let s=e;for(;s!==null&&!s.canSelect();)s=s.containingGroup;s!==null&&(s.isSelected=!0),t.F("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.yr?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.cT(n,s,e)}cT(t,i,e){if(i.handled=!1,t!==null&&!t.isEnabledObject())return!1;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.F(n,t)}else{switch(s){case 1:n="BackgroundSingleClicked";break;case 2:n="BackgroundDoubleClicked";break;case 3:n="BackgroundContextClicked";break}s!==0&&e.F(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)}return i.handled}standardMouseOver(){const t=this.diagram,i=t.lastInput;if(t.animationManager.Mi===!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.Vf){let o=t.Vf;const r=o;for(t.Vf=s,this.uT(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.Vf}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="")}uT(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,a=r.deltaY,f="pixel";if((h!==0||a!==0)&&!i.shift){switch(l){case 0:f="pixel";break;case 1:f="line";break;case 2:f="page";break}if(h!==0&&t.allowHorizontalScroll){const c=t.scrollHorizontalLineChange;h=h*(c/16),t.scroll(f,h>0?"right":"left",Math.abs(h))}if(a!==0&&t.allowVerticalScroll){const c=t.scrollVerticalLineChange;a=a*(c/16),t.scroll(f,a>0?"down":"up",Math.abs(a))}}else!i.shift&&t.allowVerticalScroll?(e=e*3*t.scrollVerticalLineChange,t.scroll(f,e>0?"up":"down",Math.abs(e))):i.shift&&t.allowHorizontalScroll&&(e=e*3*t.scrollHorizontalLineChange,t.scroll(f,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){Debug&&U.i(t,"number",Tool,"standardWaitAfter:delay"),i===void 0&&(i=this.diagram.lastInput),this.cancelWaitAfter();const e=this,s=i.clone(this.fT);this.zm=U.pn(()=>e.doWaitAfter(s),t)}cancelWaitAfter(){this.zm!==-1&&U.Nf(this.zm),this.zm=-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.At}set name(t){U.i(t,"string",Tool,"name"),this.At=t}get isEnabled(){return this.Gi}set isEnabled(t){U.i(t,"boolean",Tool,"isEnabled"),this.Gi=t}get isActive(){return this.Zk}set isActive(t){U.i(t,"boolean",Tool,"isActive"),this.Zk=t}get transactionResult(){return this.Qk}set transactionResult(t){t!==null&&U.i(t,"string",Tool,"transactionResult"),this.Qk=t}}var WheelMode=(w=>(w[w.Scroll=1]="Scroll",w[w.Zoom=2]="Zoom",w[w.None=3]="None",w))(WheelMode||{}),GestureMode=(w=>(w[w.Zoom=1]="Zoom",w[w.Cancel=2]="Cancel",w[w.None=3]="None",w))(GestureMode||{});class ToolManager extends Tool{dT;gT;mT;iP;eP;sP;nP;oP;rP;lP;Ym;ra;constructor(t){super(),this.name="ToolManager",this.dT=new List,this.gT=new List,this.mT=new List,this.iP=850,this.eP=850,this.sP=new Size(2,2).Ct(),this.nP=5e3,this.oP=1,this.rP=1,this.lP=null,this.Ym=null,this.ra=-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.oP}set mouseWheelBehavior(t){U.W(t,WheelMode,"WheelMode"),this.oP=t}get gestureBehavior(){return this.rP}set gestureBehavior(t){U.W(t,GestureMode,"GestureMode"),this.rP=t}initializeStandardTools(){return this}updateAdornments(t){const i=this.currentToolTip;if(i instanceof Adornment&&this.Ym===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;Debug&&e.Bu&&e.transactionLevel!==0&&U.ot("WARNING: In ToolManager.doMouseDown: UndoManager.transactionLevel is not zero");const s=this.mouseDownTools.length;for(let n=0;nr.right&&(n.x-=o.width+5/s.scale),n.xr.bottom?n.y-=o.height+5/s.scale:n.y+=20/s.scale,n.y0&&t!==1/0&&(this.ra=U.pn(()=>this.hideToolTip(),t)))}hideToolTip(){this.ra!==-1&&(U.Nf(this.ra),this.ra=-1);const t=this.diagram,i=this.currentToolTip;i!==null&&(i instanceof Adornment?(t.remove(i),this.Ym!==null&&this.Ym.removeAdornment(i.category),i.data=null,i.adornedObject=null):i instanceof HTMLInfo&&i.hide!==null&&i.hide(t,this),this.currentToolTip=null)}get currentToolTip(){return this.lP}set currentToolTip(t){Debug&&t!==null&&!(t instanceof Adornment||t instanceof HTMLInfo)&&U.n("ToolManager.currentToolTip must be an Adornment or HTMLInfo."),this.lP=t,this.Ym=t!==null&&t instanceof Adornment?t.adornedPart:null}doMouseUp(){this.cancelWaitAfter();const t=this.diagram;if(this.isActive){const i=this.mouseUpTools.length;for(let e=0;e30&&t.Ox(),t.wT(this.draggedParts),t.Yu=!0,this.startTransaction("Drag"),this.startPoint=t.firstInput.documentPoint,t.isMouseCaptured=!0,t.allowDragOut&&this.pR()}bP(t){if(!this.dragsLink)return;const i=this.diagram,e=i.model.Um(),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.Pn=i.toolManager.findTool("Relinking"),this.Pn===null&&(this.Pn=new RelinkingTool,this.Pn.diagram=i),this.Pn.originalLink=this.draggedLink):(this.draggedLink=null,this.Pn=null)}mayDragLink(t){const i=this.diagram;return i!==null&&i.allowRelink}computeEffectiveCollection(t,i){return this.diagram.commandHandler.computeEffectiveCollection(t,i)}Zs(t){return t===void 0?new DraggingInfo(Point.yn):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.xP,t.Yu=!1,t.Bl=!0,t.cacheGroupExternalLinks(!1),t.stopAutoScroll(),this.SP(),t.kP(this.draggedParts),this.zu=null,this.currentPart=null,this.draggedParts=null,this.isDragOutStarted=!1,this.Vu=!1,DraggingTool.yR(),this.xT(),this.zf.e(NaN,NaN),DraggingTool.ha!==null&&(DraggingTool.ha.currentCursor=""),DraggingTool.ha=null,DraggingTool.fi=null,this.Vl(),t.isMouseCaptured=!1,t.currentCursor="",t.Xu=!1,this.stopTransaction(),t.PP(!0)}stopTransaction(){const t=this.diagram,i=super.stopTransaction();return i&&t.undoManager.transactionToUndo!==null&&t.undoManager.transactionToUndo.optimize(),i}SP(){const t=this.diagram,i=t.skipsUndoManager;t.skipsUndoManager=!0;const e=t.lastInput;this.bT(e,null),t.skipsUndoManager=i,this.Nr.length=0}ST(){this.Vl(),this.MP();const t=this.diagram;this.zf.isReal()&&(t.position=this.zf),t.stopAutoScroll()}doCancel(){this.Vl(),this.MP();const t=this.diagram;this.zf.isReal()&&(t.position=this.zf),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()}wR(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,a=h.x,f=h.y;isNaN(a)||isNaN(f)||(an&&(n=a),f>o&&(o=f))}return e===1/0?i.e(0,0,0,0):i.e(e,s,n-e,o-s),i}NP(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.MP(),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.Oe()&&h.canCopy()){const a=n.get(h);if(a===null)continue;a.location=h.location,a.ensureBounds(),o.set(a,this.Zs(a.location))}}const l=n.iterator;for(;l.next();){const h=l.value;h instanceof Link&&h.canCopy()&&o.set(h,this.Zs())}if(this.copiedParts=o,this.bP(o.toKeySet()),this.draggedLink!==null){const h=this.draggedLink,a=h.routeBounds;h.Cr(this.startPoint.x-(a.x+a.width/2),this.startPoint.y-(a.y+a.height/2))}this.doUpdateCursor(null)}Vl(){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}xT(){this.draggedLink!==null&&(this.dragsLink&&this.Pn!==null&&(this.Pn.stopDraggingMouseMove(),this.Pn.originalLink=null),this.draggedLink=null,this.Pn=null)}Xf(t,i){if(t===null)return;const e=this.diagram,s=this.startPoint,n=Point.a();n.c(e.lastInput.documentPoint),this.moveParts(t,n.subtract(s),i),Point.o(n),e.getRenderingHint("temporaryPixelRatio")===!0&&e.zl===null&&e.avgSpf>30&&(e.Ox(),e.Ku())}moveParts(t,i,e){e===void 0&&(e=!1);const s=this.diagram;s!==null&&s.Ex(t,i,this.dragOptions,e)}MP(){if(this.draggedParts===null)return;const t=this.diagram;let i=this.draggedParts.iterator;for(;i.next();){const e=i.key;e.Oe()&&(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.Zs()),e.Cr(-s.x,-s.y)}}t.maybeUpdate()}xR(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))}CP(t){const i=this.diagram;this.dragsLink&&(this.draggedLink!==null&&(this.draggedLink.fromNode=null,this.draggedLink.toNode=null),this.kT(!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.bT(s,e),!this.isActive&&DraggingTool.fi===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.fi===null||(this.doDragOver(t,e),!this.isActive&&DraggingTool.fi===null))return}finally{i.skipsUndoManager=n,o&&i.maybeUpdate()}this.zu=e,!i.isReadOnly&&(i.allowMove||i.allowCopy)&&(i.allowHorizontalScroll||i.allowVerticalScroll)&&i.doAutoScroll(s.viewPoint)}findDragOverObject(t){return this.diagram.AP(t,null,i=>!this.xR(i))}doUpdateCursor(t){const i=this.diagram;(t===null||this.zu!==t)&&(!this.diagram.currentTool.isActive||this.mayCopy()?i.currentCursor=this.copyCursor:this.mayMove()?i.currentCursor=this.moveCursor:this.mayDragOut()&&(i.currentCursor=this.nodropCursor))}bT(t,i){let e=!1,s=this.Nr.length;const n=s>0?this.Nr[0]:null;if(i===n)return!1;t.handled=!1;for(let r=0;rs.findValidLinkablePort(a,i)),r=Point.a();let l=1/0,h=null;for(const a=o.iterator;a.next();){const f=a.value;if(f.part===null)continue;const u=f.getDocumentPoint(Spot.Center,r),d=t.distanceSquaredPoint(u);da.suspendsRouting=!1)}}if(this.doDropOnto(t,e),!this.isActive&&DraggingTool.fi===null)return;const o=Rect.a(),r=i.selection.iterator;for(;r.next();){const l=r.value;l instanceof Node&&this.SR(i,l,o)}Rect.o(o)}bR(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)}}SR(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.DP(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.ii()}}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.NP(!1),this.Xf(this.copiedParts,!1)):this.mayMove()?(this.Vl(),this.Xf(this.draggedParts,!0)):this.mayDragOut()?(this.NP(!1),this.Xf(this.copiedParts,!1)):this.Vl(),this.CP(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.Vl(),this.NP(!0),this.Xf(this.copiedParts,!1),this.copiedParts!==null&&(t.F("ChangingSelection",t.selection),t.clearSelection(!0),this.copiedParts.iteratorKeys.each(n=>{n.isSelected=!0}))):(e=!0,this.Vl(),this.mayMove()&&(this.Xf(this.draggedParts,!0),this.CP(t.lastInput.documentPoint))),this.Vu=!0,this.NT(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.kR(),t.invalidateDocumentBounds(),t.kP(this.draggedParts),this.transactionResult=n?"Copy":"Move",t.F(n?"SelectionCopied":"SelectionMoved",o)}this.stopTool(),s&&t.F("ChangedSelection",t.selection)}simulatedMouseMove(t,i,e){if(DraggingTool.fi===null)return!1;const s=DraggingTool.fi.diagram;e instanceof Diagram||(e=null);const n=DraggingTool.ha;if(e!==n){if(n!==null&&n!==s){n.stopAutoScroll(),DraggingTool.fi.isDragOutStarted=!1;const r=n.toolManager.findTool("Dragging");r!==null&&r.doSimulatedDragLeave()}if(DraggingTool.ha=e,e!==null&&e!==s){DraggingTool.fi.ST();const r=e.toolManager.findTool("Dragging");r!==null&&(r.CT(),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.fi===null)return!1;const s=DraggingTool.ha,n=DraggingTool.fi.diagram;if(e===null)return DraggingTool.fi.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.fi.isDragOutStarted=!1,r.doSimulatedDragLeave(),!1}DraggingTool.ha=e;const o=e.toolManager.findTool("Dragging");o!==null&&(DraggingTool.fi.ST(),o.CT(),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.fi;if(l!==null){const h=l.mayCopy();l.transactionResult=h?"Copy":"Move",l.stopTool()}return!0}return!1}kR(){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.g()}}}mayCopy(){if(!this.isCopyEnabled)return!1;const t=this.diagram;if(t.isReadOnly||t.isModelReadOnly||!t.allowInsert||!t.allowCopy||!(U.yr?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())}CT(){DraggingTool.Rx.has(this)||DraggingTool.Rx.add(this)}static yR(){if(DraggingTool.Rx.count>0){const t=DraggingTool.Rx,i=t.length;for(let e=0;e{n.isSelected=!0,s.add(n)})),this.NT(t.lastInput.documentPoint),t.invalidateDocumentBounds(),this.copiedParts!==null&&(this.transactionResult="ExternalCopy"),this.copiedParts=null,t.doFocus(),t.Xu=!1,t.F("ExternalObjectsDropped",s,e),this.stopTransaction(),t.F("ChangedSelection",t.selection)}t.animationManager.Uu=!1}AT(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.a();this.wR(t,o);const r=o.x+o.width/2,l=o.y+o.height/2;Rect.o(o);const h=this.Km,a=new GMap,f=Point.a(),c=t.iterator;for(;c.next();){const d=c.value;if(d instanceof Link&&d.canCopy()){const m=n.get(d);if(m===null)continue;m.points=d.points,m.Cr(h.x-r,h.y-l),m.suspendsRouting=!0,a.set(m,this.Zs())}}const u=t.iterator;for(;u.next();){const d=u.value;if(d.Oe()&&d.canCopy()){const m=n.get(d);if(m===null)continue;const g=d.location;f.e(h.x-(r-g.x),h.y-(l-g.y)),m.location=f,m.ensureBounds(),a.set(m,this.Zs(f))}}if(Point.o(f),this.copiedParts=a,this.bP(a.toKeySet()),this.draggedLink!==null){const d=this.draggedLink,m=d.routeBounds;d.Cr(this.startPoint.x-(m.x+m.width/2),this.startPoint.y-(m.y+m.height/2))}this.doUpdateCursor(null)}pR(){this.isDragOutStarted=!0,this.Vu=!1,DraggingTool.fi=this,DraggingTool.ha=this.diagram,this.doSimulatedDragOut()}doSimulatedDragOut(){const t=this.diagram;!this.mayCopy()&&!this.mayMove()?t.currentCursor=this.nodropCursor:t.currentCursor="",this.zu=null}computeMove(t,i,e,s){const n=this.diagram;return n!==null?n.computeMove(t,i,this.dragOptions,s):new Point}}ToolManager.prototype.doCancel=function(){DraggingTool.fi!==null&&DraggingTool.fi.doCancel(),Tool.prototype.doCancel.call(this)};class LinkingBaseTool extends Tool{FP;IP;Xl;RP;OP;aa;EP;fa;BP;VP;zP;XP;YP;KP;TT;UP;Yl;GP;constructor(){super(),this.FP=100,this.IP=!1,this.Xl="pointer",this.RP=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")).Yt(),this.aa=new Shape("Rectangle",{portId:"",fill:null,stroke:"magenta",strokeWidth:2,desiredSize:Size.Vk}).theme("stroke","tempPort"),this.OP=new Node({selectable:!1,layerName:"Tool"}).add(this.aa).Yt(),this.fa=new Shape("Rectangle",{portId:"",fill:null,stroke:"magenta",strokeWidth:2,desiredSize:Size.Vk}).theme("stroke","tempPort"),this.EP=new Node({selectable:!1,layerName:"Tool"}).add(this.fa).Yt(),this.BP=null,this.VP=null,this.zP=null,this.XP=null,this.YP=null,this.KP=!0,this.TT=new GMap,this.UP=null,this.Yl=null,this.GP=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.FP}set portGravity(t){U.i(t,"number",LinkingBaseTool,"portGravity"),t>=0&&(this.FP=t)}get isUnconnectedLinkValid(){return this.IP}set isUnconnectedLinkValid(t){U.i(t,"boolean",LinkingBaseTool,"isUnconnectedLinkValid"),this.IP=t}get linkingCursor(){return this.Xl}set linkingCursor(t){this.Xl=t}get temporaryLink(){return this.RP}set temporaryLink(t){U.s(t,Link,LinkingBaseTool,"temporaryLink"),t.Yt(),this.RP=t}get temporaryFromNode(){return this.OP}set temporaryFromNode(t){U.s(t,Node,LinkingBaseTool,"temporaryFromNode"),t.Yt(),this.OP=t,t&&(this.aa=t.port)}get temporaryFromPort(){return this.aa}set temporaryFromPort(t){if(U.s(t,GraphObject,LinkingBaseTool,"temporaryFromPort"),this.aa!==null){const i=this.aa.panel;if(i!==null){const e=i.O.indexOf(this.aa);i.removeAt(e),i.insertAt(e,t)}}this.aa=t}get temporaryToNode(){return this.EP}set temporaryToNode(t){U.s(t,Node,LinkingBaseTool,"temporaryToNode"),t.Yt(),this.EP=t,t&&(this.fa=t.port)}get temporaryToPort(){return this.fa}set temporaryToPort(t){if(U.s(t,GraphObject,LinkingBaseTool,"temporaryToPort"),this.fa!==null){const i=this.fa.panel;if(i!==null){const e=i.O.indexOf(this.fa);i.removeAt(e),i.insertAt(e,t)}}this.fa=t}get originalLink(){return this.BP}set originalLink(t){t!==null&&U.s(t,Link,LinkingBaseTool,"originalLink"),this.BP=t}get originalFromNode(){return this.VP}set originalFromNode(t){t!==null&&U.s(t,Node,LinkingBaseTool,"originalFromNode"),this.VP=t}get originalFromPort(){return this.zP}set originalFromPort(t){t!==null&&U.s(t,GraphObject,LinkingBaseTool,"originalFromPort"),this.zP=t}get originalToNode(){return this.XP}set originalToNode(t){t!==null&&U.s(t,Node,LinkingBaseTool,"originalToNode"),this.XP=t}get originalToPort(){return this.YP}set originalToPort(t){t!==null&&U.s(t,GraphObject,LinkingBaseTool,"originalToPort"),this.YP=t}get isForwards(){return this.KP}set isForwards(t){this.KP=t}get validPortsCache(){return this.TT}get targetPort(){return this.UP}set targetPort(t){t!==null&&U.s(t,GraphObject,LinkingBaseTool,"targetPort"),this.UP=t}copyPortProperties(t,i,e,s,n){if(t===null||i===null||e===null||s===null)return;const o=i.getDocumentScale(),r=Size.a();r.width=i.naturalBounds.width*o,r.height=i.naturalBounds.height*o,s.desiredSize=r,Size.o(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.a();e.location=i.getDocumentPoint(Spot.Center,l),Point.o(l),s.angle=i.getDocumentAngle(),this.portTargeted!==null&&this.portTargeted(t,i,e,s,n)}setNoTargetPortProperties(t,i,e){i!==null&&(i.desiredSize=Size.Vk,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,a=h.part;if(!(a instanceof Node))continue;const f=h.getDocumentPoint(Spot.Center,Point.a()),c=e.x-f.x,u=e.y-f.y;Point.o(f);const d=c*c+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.qP(e,i,s)}qP(t,i,e){if(t===i)return!0;const s=t.fromNode;if(s!==null&&s.labeledLink&&(e.add(s),this.qP(s.labeledLink,i,e)))return!0;const n=t.toNode;return!!(n!==null&&n.labeledLink&&(e.add(n),this.qP(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.Gm()?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.Gu(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.Gu(t,i,e,!0)}else{if(n===2)return!this.MR(t,i,e);if(n===3)return!this.Gu(t,i,e,!1);if(n===4)return!this.NR(t,i,e)}return!0}Gu(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.Gu(r,i,e,s))return!0}return!1}MR(t,i,e){if(t===i)return!0;const s=new Set;return s.add(i),this.LT(s,t,i,e)}LT(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.LT(t,r,e,s))return!0}return!1}NR(t,i,e){if(t===i)return!0;const s=new Set;return s.add(i),this.DT(s,t,i,e)}DT(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.DT(t,h,e,s))return!0}return!1}get linkValidation(){return this.Yl}set linkValidation(t){t!==null&&U.C(t,LinkingBaseTool,"linkValidation"),this.Yl=t}get portTargeted(){return this.GP}set portTargeted(t){t!==null&&U.C(t,LinkingBaseTool,"portTargeted"),this.GP=t}}var LinkingDirection=(w=>(w[w.Either=1]="Either",w[w.ForwardsOnly=2]="ForwardsOnly",w[w.BackwardsOnly=3]="BackwardsOnly",w))(LinkingDirection||{});class LinkingTool extends LinkingBaseTool{HP;vP;N;WP;constructor(t){super(),this.name="Linking",this.HP={},this.vP=null,this.N=1,this.WP=null,t&&Object.assign(this,t)}static Either=1;static ForwardsOnly=2;static BackwardsOnly=3;get archetypeLinkData(){return this.HP}set archetypeLinkData(t){t!==null&&U.Ro(t,LinkingTool,"archetypeLinkData"),t instanceof GraphObject&&U.s(t,Link,LinkingTool,"archetypeLinkData"),this.HP=t}get archetypeLabelNodeData(){return this.vP}set archetypeLabelNodeData(t){t!==null&&U.Ro(t,LinkingTool,"archetypeLabelNodeData"),t instanceof GraphObject&&U.s(t,Node,LinkingTool,"archetypeLabelNodeData"),this.vP=t}get direction(){return this.N}set direction(t){U.W(t,LinkingDirection,"LinkingDirection"),this.N=t}get startObject(){return this.WP}set startObject(t){t!==null&&U.s(t,GraphObject,LinkingTool,"startObject"),this.WP=t}canStart(){if(!this.isEnabled)return!1;const t=this.diagram;return t.isReadOnly||t.isModelReadOnly||!t.allowLink||!t.model.Bx()||!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.ii(),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.F("ChangingSelection",t.selection),t.clearSelection(!0),o.isSelected=!0),this.transactionResult=this.name,t.F("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.F("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{FT=null;IT=null;jP=null;JP=null;As;$P;constructor(t){super(),this.name="Relinking",this.fromHandleArchetype=new Shape("Diamond",{desiredSize:Size.Au,fill:"lightblue",stroke:"dodgerblue",cursor:this.linkingCursor,segmentIndex:0}).theme("fill","adornmentFill").theme("stroke","adornmentStroke"),this.toHandleArchetype=new Shape("Diamond",{desiredSize:Size.Au,fill:"lightblue",stroke:"dodgerblue",cursor:this.linkingCursor,segmentIndex:-1}).theme("fill","adornmentFill").theme("stroke","adornmentStroke"),this.As=null,this.$P=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.g())}e===null&&t.removeAdornment(i)}makeAdornment(t,i){let e=i?this.JP:this.jP;return e&&(e=e.copy(),e.adornedObject=t),e}get fromHandleArchetype(){return this.FT}set fromHandleArchetype(t){t!==null&&U.s(t,GraphObject,RelinkingTool,"fromHandleArchetype"),this.FT=t,t!==null?this.jP=new Adornment(Panel.Link).add(t).Yt():this.jP=null}get toHandleArchetype(){return this.IT}set toHandleArchetype(t){t!==null&&U.s(t,GraphObject,RelinkingTool,"toHandleArchetype"),this.IT=t,t!==null?this.JP=new Adornment(Panel.Link).add(t).Yt():this.JP=null}get handle(){return this.As}set handle(t){t!==null&&(U.s(t,GraphObject,RelinkingTool,"handle"),t.part instanceof Adornment||U.n("new handle is not in an Adornment: "+t)),this.As=t}canStart(){if(!this.isEnabled)return!1;const t=this.diagram;if(t.isReadOnly||t.isModelReadOnly||!t.allowRelink||!t.model.Bx()||!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.$P.set(i.actualBounds),i.pointsCount>0&&(i.fromNode===null&&(this.temporaryFromPort!==null&&(this.temporaryFromPort.desiredSize=Size.sa),this.temporaryFromNode!==null&&(this.temporaryFromNode.location=i.getPoint(0))),i.toNode===null&&(this.temporaryToPort!==null&&(this.temporaryToPort.desiredSize=Size.sa),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.ii(),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.ii()),this.transactionResult=this.name,t.F("LinkRelinked",o,this.isForwards?this.originalToPort:this.originalFromPort)):this.originalLink!==null&&this.doNoRelink(this.originalLink,this.isForwards),this.originalLink!==null&&this.originalLink.invalidateOtherJumpOvers(this.$P)}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=(w=>(w[w.None=0]="None",w[w.Horizontal=1]="Horizontal",w[w.Vertical=2]="Vertical",w[w.All=3]="All",w))(ReshapingBehavior||{});class LinkReshapingTool extends Tool{Tr;ZP;QP;As;Vx;_P;qm;constructor(t){super(),this.name="LinkReshaping",this.Tr=new Shape("Rectangle",{desiredSize:Size.XA,fill:"lightblue",stroke:"dodgerblue"}).theme("fill","adornmentFill").theme("stroke","adornmentStroke"),this.ZP=new Shape("Diamond",{desiredSize:Size.Au,fill:"lightblue",stroke:"dodgerblue",cursor:"move"}).theme("fill","adornmentFill").theme("stroke","adornmentStroke"),this.QP=3,this.As=null,this.Vx=null,this._P=new Point,this.qm=new List,t&&Object.assign(this,t)}static None=0;static Horizontal=1;static Vertical=2;static All=3;getReshapingBehavior(t){return t?t.Lr:0}setReshapingBehavior(t,i){t.Lr=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.tM!==t.pointsCount||i.iM!==t.resegmentable)&&(i=this.makeAdornment(e),i!==null&&(i.tM=t.pointsCount,i.iM=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||i.isOrthogonal))for(let c=r+h;ce.firstPickIndex+1&&s0))this.CR(t,i);else if(t instanceof Panel){const e=t.elements;for(;e.next();){const s=e.value;this.updateResizeHandles(s,i)}}}}CR(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=G.Yi(s),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.Tr}set handleArchetype(t){t!==null&&U.s(t,GraphObject,ResizingTool,"handleArchetype"),this.Tr=t}get handle(){return this.As}set handle(t){t!==null&&(U.s(t,GraphObject,ResizingTool,"handle"),t.part instanceof Adornment||U.n("new handle is not in an Adornment: "+t)),this.As=t}get adornedObject(){return this.Ts}set adornedObject(t){t!==null&&(U.s(t,GraphObject,ResizingTool,"handle"),t.part instanceof Adornment&&U.n("new handle must not be in an Adornment: "+t)),this.Ts=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.Yu=!0,this.startTransaction(this.name),this.Hm.set(this.adornedObject.getDocumentPoint(this.handle.alignment.opposite())),this.Kf.set(this.adornedObject.part.location),this.oM.set(this.adornedObject.desiredSize),this.Yx=this.computeCellSize(),this.zx=this.computeMinSize(),this.Xx=this.computeMaxSize(),this.isActive=!0))}doDeactivate(){const t=this.diagram;t.Yu=!1,t.Bl=!0,this.stopTransaction(),this.handle=null,this.Ts=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.zx,e=this.Xx,s=this.Yx,n=t.lastInput.documentPoint,o=this.adornedObject.getLocalPoint(n,Point.a()),r=this.computeReshape(),l=this.computeResize(o,this.handle.alignment,i,e,s,r);this.resize(l),t.maybeUpdate(),Point.o(o)}doMouseUp(){const t=this.diagram;if(this.isActive&&this.adornedObject!==null&&this.handle!==null){const i=this.zx,e=this.Xx,s=this.Yx,n=this.adornedObject.getLocalPoint(t.lastInput.documentPoint,Point.a()),o=this.computeReshape(),r=this.computeResize(n,this.handle.alignment,i,e,s,o);this.resize(r),Point.o(n),t.invalidateDocumentBounds(),this.transactionResult=this.name,t.F("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.lm;i.isNoSpot()&&(i=Spot.Center);const r=this.adornedObject.naturalBounds,l=r.x,h=r.y,a=r.x+r.width,f=r.y+r.height;let c=1;if(!o){let m=r.width,g=r.height;m<=0&&(m=1),g<=0&&(g=1),c=g/m}const u=Point.a();G.rm(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,a-s.width),d.x=Math.min(d.x,a-e.width),d.width=Math.max(a-d.x,e.width),d.y=Math.max(u.y,f-s.height),d.y=Math.min(d.y,f-e.height),d.height=Math.max(f-d.y,e.height),o||(d.height/d.width>=1?(d.height=Math.max(Math.min(c*d.width,s.height),e.height),d.width=d.height/c):(d.width=Math.max(Math.min(d.height/c,s.width),e.width),d.height=c*d.width),d.x=a-d.width,d.y=f-d.height)):i.y>=1?(d.x=Math.max(u.x,a-s.width),d.x=Math.min(d.x,a-e.width),d.width=Math.max(a-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(c*d.width,s.height),e.height),d.width=d.height/c):(d.width=Math.max(Math.min(d.height/c,s.width),e.width),d.height=c*d.width),d.x=a-d.width)):(d.x=Math.max(u.x,a-s.width),d.x=Math.min(d.x,a-e.width),d.width=a-d.x,o||(d.height=Math.max(Math.min(c*d.width,s.height),e.height),d.width=d.height/c,d.y=h+.5*(f-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,f-s.height),d.y=Math.min(d.y,f-e.height),d.height=Math.max(f-d.y,e.height),o||(d.height/d.width>=1?(d.height=Math.max(Math.min(c*d.width,s.height),e.height),d.width=d.height/c):(d.width=Math.max(Math.min(d.height/c,s.width),e.width),d.height=c*d.width),d.y=f-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(c*d.width,s.height),e.height),d.width=d.height/c):(d.width=Math.max(Math.min(d.height/c,s.width),e.width),d.height=c*d.width))):(d.width=Math.max(Math.min(u.x-l,s.width),e.width),o||(d.height=Math.max(Math.min(c*d.width,s.height),e.height),d.width=d.height/c,d.y=h+.5*(f-h-d.height))):i.y<=0?(d.y=Math.max(u.y,f-s.height),d.y=Math.min(d.y,f-e.height),d.height=f-d.y,o||(d.width=Math.max(Math.min(d.height/c,s.width),e.width),d.height=c*d.width,d.x=l+.5*(a-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/c,s.width),e.width),d.height=c*d.width,d.x=l+.5*(a-l-d.width))),Point.o(u),d}computeReshape(){let t=0;return this.adornedObject instanceof Shape&&(t=this.adornedObject.rM()),!(t===6||this.diagram.lastInput.shift)}computeMinSize(){if(this.adornedObject===null)return Size.sa;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.ix;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.Dr}set minSize(t){if(U.s(t,Size,ResizingTool,"minSize"),!this.Dr.equals(t)){let e=t.width;isNaN(e)&&(e=0);let s=t.height;isNaN(s)&&(s=0),this.Dr.e(e,s)}}get maxSize(){return this.Fr}set maxSize(t){if(U.s(t,Size,ResizingTool,"maxSize"),!this.Fr.equals(t)){let e=t.width;isNaN(e)&&(e=1/0);let s=t.height;isNaN(s)&&(s=1/0),this.Fr.e(e,s)}}get cellSize(){return this.zo}set cellSize(t){U.s(t,Size,ResizingTool,"cellSize"),this.zo.equals(t)||this.zo.c(t)}get isGridSnapEnabled(){return this.Yf}set isGridSnapEnabled(t){U.i(t,"boolean",ResizingTool,"isGridSnapEnabled"),this.Yf=t}get dragsMembers(){return this.nM}set dragsMembers(t){U.i(t,"boolean",ResizingTool,"dragsMembers"),this.nM=t}get oppositePoint(){return this.Hm}set oppositePoint(t){U.s(t,Point,ResizingTool,"oppositePoint"),this.Hm.equals(t)||this.Hm.c(t)}get originalDesiredSize(){return this.oM}get originalLocation(){return this.Kf}}class RotatingTool extends Tool{lM;hM;Ts=null;Tr=null;Kx=null;As=null;aM;vm;Kf;fM;cM;constructor(t){super(),this.name="Rotating",this.lM=45,this.hM=2,this.Kf=new Point,this.Ts=null,this.handleArchetype=new Shape("Ellipse",{desiredSize:Size.Au,fill:"lightblue",stroke:"dodgerblue",strokeWidth:1,cursor:"pointer"}).theme("fill","adornmentFill").theme("stroke","adornmentStroke"),this.As=null,this.aM=0,this.vm=new Point(NaN,NaN),this.fM=0,this.cM=50,t&&Object.assign(this,t)}updateAdornments(t){if(t!==null){if(t.Ir()){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.Kx!==null&&(i=this.Kx.copy()),i===null?null:(i.adornedObject=t,i)}get handleArchetype(){return this.Tr}set handleArchetype(t){t!==null&&U.s(t,GraphObject,RotatingTool,"handleArchetype"),this.Tr=t,t!==null?this.Kx=new Adornment(Panel.Position,{locationSpot:Spot.Center}).add(t).Yt():this.Kx=null}get handle(){return this.As}set handle(t){t!==null&&(U.s(t,GraphObject,RotatingTool,"handle"),t.part instanceof Adornment||U.n("new handle is not in an Adornment: "+t)),this.As=t}get adornedObject(){return this.Ts}set adornedObject(t){t!==null&&(U.s(t,GraphObject,RotatingTool,"handle"),t.part instanceof Adornment&&U.n("new handle must not be in an Adornment: "+t)),this.Ts=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.aM=this.adornedObject.angle,this.vm=this.computeRotationPoint(this.adornedObject),this.Kf=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=G.Yi(s),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.Ts=null,this.vm=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.F("PartRotated",this.adornedObject,this.originalAngle)}this.stopTool()}rotate(t){Debug&&U.r(t,RotatingTool,"rotate:newangle");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.Kf.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=G.Yi(i);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)),G.Yi(i)}get snapAngleMultiple(){return this.lM}set snapAngleMultiple(t){U.i(t,"number",RotatingTool,"snapAngleMultiple"),this.lM=t}get snapAngleEpsilon(){return this.hM}set snapAngleEpsilon(t){U.i(t,"number",RotatingTool,"snapAngleEpsilon"),this.hM=t}get originalAngle(){return this.aM}get rotationPoint(){return this.vm}set rotationPoint(t){this.vm=t.copy()}get handleAngle(){return this.fM}set handleAngle(t){U.i(t,"number",RotatingTool,"handleAngle"),this.fM=t}get handleDistance(){return this.cM}set handleDistance(t){U.i(t,"number",RotatingTool,"handleDistance"),this.cM=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{Uf;constructor(t){super(),this.name="Action",this.Uf=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.Uf=e,t.Vf=t.findObjectAt(i.documentPoint,null,null),!0):!1}doMouseDown(){if(!this.isActive)this.canStart()&&this.doActivate();else{const i=this.diagram.lastInput,e=this.Uf;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.Uf;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.Uf;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.Uf;e!==null&&(i.targetObject=e,e.actionCancel!==null&&e.actionCancel(i,e),this.stopTool())}doStop(){this.Uf=null}}class ClickCreatingTool extends Tool{Ul;uM;Yf;dM;constructor(t){super(),this.name="ClickCreating",this.Ul=null,this.uM=!0,this.Yf=!1,this.dM=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.dM=t.lastInput.viewPoint.copy()),t.lastInput.clickCount!==2||this.isBeyondDragSize(this.dM))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.F("ChangingSelection",i.selection),this.startTransaction(this.name),e instanceof Part)e.Oe()&&(e.Yt(),s=e.copy(),s!==null&&i.add(s));else if(e!==null){const n=i.model.copyNodeData(e);i.model.addNodeData(n),s=i.findPartForData(n)}if(s!==null){const n=Point.U(t.x,t.y);this.isGridSnapEnabled&&this.diagram.gM(s,t,n),s.location=n,i.allowSelect&&(i.clearSelection(!0),s.isSelected=!0),Point.o(n)}i.invalidateDocumentBounds(),this.transactionResult=this.name,i.F("PartCreated",s)}finally{this.stopTransaction(),i.F("ChangedSelection",i.selection)}return s}get archetypeNodeData(){return this.Ul}set archetypeNodeData(t){t!==null&&U.Ro(t,ClickCreatingTool,"archetypeNodeData"),this.Ul=t}get isDoubleClick(){return this.uM}set isDoubleClick(t){U.i(t,"boolean",ClickCreatingTool,"isDoubleClick"),this.uM=t}get isGridSnapEnabled(){return this.Yf}set isGridSnapEnabled(t){U.i(t,"boolean",ClickCreatingTool,"isGridSnapEnabled"),this.Yf=t}}class DragSelectingTool extends Tool{la;mM;Gl;constructor(t){super(),this.name="DragSelecting",this.la=175,this.mM=!1,this.Gl=new Part({layerName:"Tool",selectable:!1}).add(new Shape("Rectangle",{name:"SHAPE",fill:null,stroke:"magenta"}).theme("stroke","dragSelect")).Yt(),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.Fi(root.document,"scroll",i.pM,!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.Vo?(t.lastInput.bubbles=!0,t.Kt(root.document,"scroll",this.pM,!1)):(t.currentCursor="move",t.isMouseCaptured=!0,this.Ux.c(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.Ux,t.isMouseCaptured=!1,this.stopTool()}doMouseMove(){this.OT()}doMouseUp(){this.OT(),this.stopTool()}OT(){const t=this.diagram;if(this.isActive&&t){if(this.Vo){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.RT.e(n,o)}}get bubbles(){return this.Vo}set bubbles(t){U.i(t,"boolean",PanningTool,"bubbles"),this.Vo=t}get originalPosition(){return this.Ux}}class HTMLInfo{Gx;qx;yM;wM;constructor(t){this.Gx=null,this.qx=null,this.yM=null,this.wM=null,t&&Object.assign(this,t)}get mainElement(){return this.yM}set mainElement(t){t!==null&&U.s(t,HTMLElement,HTMLInfo,"mainElement"),this.yM=t}get show(){return this.Gx}set show(t){this.Gx!==t&&(t!==null&&U.C(t,HTMLInfo,"show"),this.Gx=t)}get hide(){return this.qx}set hide(t){this.qx!==t&&(t!==null&&U.C(t,HTMLInfo,"hide"),this.qx=t)}get valueFunction(){return this.wM}set valueFunction(t){this.wM=t}}class ContextMenuButtonInfo{mi;Hx;qf;constructor(t,i,e){this.mi=t,this.Hx=i,this.qf=e}}class ContextMenuTool extends Tool{xM;vx;bM;SM;Wx;jx;Wm;constructor(t){super(),this.name="ContextMenu",this.xM=null,this.vx=null,this.bM=null,this.SM=new Point,this.Wx=null,this.Wm=!1;const i=this;this.jx=()=>i.stopTool(),t&&Object.assign(this,t)}AR(){const t=new HTMLInfo;t.show=(r,l,h)=>h.showDefaultContextMenu(),t.hide=(r,l)=>l.hideDefaultContextMenu(),ContextMenuTool.qu=t;const i=this;this.jx=()=>i.stopTool();const e=U.Le("div"),s=U.Le("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.Le("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.Kt(e,"contextmenu",ContextMenuTool.ca,!1),o.Kt(e,"selectstart",ContextMenuTool.ca,!1),o.Kt(s,"contextmenu",ContextMenuTool.ca,!1)),e.className="goCXforeground",s.className="goCXbackground",root.document.body&&(root.document.body.appendChild(e),root.document.body.appendChild(s)),ContextMenuTool.jm=e,ContextMenuTool.Jm=s,ContextMenuTool.kM=!0}static qu=null;static kM=!1;static Jm;static jm;static ca(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.SM.set(t.firstInput.documentPoint)}doStop(){this.hideContextMenu(),this.currentObject=null,this.Wm=!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.Wm)return;this.Wm=!0;let e=!1;if(i instanceof Diagram){const s=this.diagram.lastInput;s.targetObject=null,e=this.cT(null,s,this.diagram)}else t&&this.standardMouseSelect(),e=this.standardMouseClick();if(this.Wm=!1,!e){this.isActive=!0;const s=ContextMenuTool.qu;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){Debug&&!(t instanceof Adornment||t instanceof HTMLInfo)&&U.n("showContextMenu:contextMenu must be an Adornment or HTMLInfo."),i!==null&&U.s(i,GraphObject,ContextMenuTool,"showContextMenu:obj");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.Wx===null&&(this.Wx=this.TR()),ContextMenuTool.jm.innerHTML="",ContextMenuTool.Jm.addEventListener("pointerdown",this.jx,!1);const i=this,e=U.Le("ul");e.className="goCXul",ContextMenuTool.jm.appendChild(e),e.innerHTML="";const s=this.Wx.iterator;for(;s.next();){const n=s.value,o=n.Hx,r=n.qf;if(!U.ht(o)||U.ht(r)&&!r(t))continue;const l=U.Le("li");l.className="goCXli";const h=U.Le("a");h.className="goCXa",h.href="#",h.Hx=o,h.addEventListener("pointerdown",function(a){return this.Hx(t),i.stopTool(),a.preventDefault(),!1},!1),h.textContent=n.mi,l.appendChild(h),e.appendChild(l)}ContextMenuTool.jm.style.display="block",ContextMenuTool.Jm.style.display="block"}hideDefaultContextMenu(){if(this.currentContextMenu===null||this.currentContextMenu!==ContextMenuTool.qu)return;ContextMenuTool.jm.style.display="none",ContextMenuTool.Jm.style.display="none";const t=this.diagram;t!==null&&t.Fi(ContextMenuTool.Jm,"pointerdown",this.jx,!1),this.currentContextMenu=null}doMouseWheel(){this.standardMouseWheel()}get currentContextMenu(){return this.xM}set currentContextMenu(t){Debug&&t!==null&&!(t instanceof Adornment||t instanceof HTMLInfo)&&U.n("ContextMenuTool.currentContextMenu must be an Adornment or HTMLInfo."),this.xM=t,this.vx=t instanceof Adornment?t.adornedPart:null}get defaultTouchContextMenu(){return ContextMenuTool.kM===!1&&ContextMenuTool.qu===null&&Diagram.isUsingDOM()&&this.AR(),ContextMenuTool.qu}set defaultTouchContextMenu(t){Debug&&t!==null&&!(t instanceof Adornment||t instanceof HTMLInfo)&&U.n("ContextMenuTool.defaultTouchContextMenu must be an Adornment or HTMLInfo."),t===null&&(ContextMenuTool.kM=!0),ContextMenuTool.qu=t}get currentObject(){return this.bM}set currentObject(t){t!==null&&U.s(t,GraphObject,ContextMenuTool,"currentObject"),this.bM=t}get mouseDownPoint(){return this.SM}}var TextEditingAccept=(w=>(w[w.LostFocus=1]="LostFocus",w[w.MouseDown=2]="MouseDown",w[w.Tab=3]="Tab",w[w.Enter=4]="Enter",w))(TextEditingAccept||{}),TextEditingStarting=(w=>(w[w.SingleClick=1]="SingleClick",w[w.SingleClickSelected=2]="SingleClickSelected",w[w.DoubleClick=3]="DoubleClick",w))(TextEditingStarting||{}),TextEditingState=(w=>(w[w.None=1]="None",w[w.Active=2]="Active",w[w.Editing=3]="Editing",w[w.Validating=4]="Validating",w[w.Invalid=5]="Invalid",w[w.Validated=6]="Validated",w))(TextEditingState||{});class TextEditingTool extends Tool{Ee;PM;MM;ql;Wt;NM;CM;AM;Jx;$x;constructor(t){super(),this.name="TextEditing",this.Ee=new TextBlock,this.PM=null,this.MM=2,this.ql=null,this.Wt=1,this.NM=1,this.CM=!0,this.AM=null,this.Jx=new HTMLInfo,this.$x=null,this.LR(this.Jx),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;LR(t){if(!Diagram.isUsingDOM())return;const i=U.Le("textarea");this.$x=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.DR(s)},!1),i.addEventListener("blur",function(s){e.FR(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 a=s.getDocumentScale()*h;a{s.div&&s.div.removeChild(i)}}get textBlock(){return this.PM}set textBlock(t){t!==null&&U.s(t,TextBlock,TextEditingTool,"textBlock"),this.PM=t}get currentTextEditor(){return this.AM}set currentTextEditor(t){this.AM=t}get defaultTextEditor(){return this.Jx}set defaultTextEditor(t){Debug&&!(t instanceof HTMLInfo)&&U.n("TextEditingTool.defaultTextEditor must be an HTMLInfo."),this.Jx=t}get starting(){return this.MM}set starting(t){U.W(t,TextEditingStarting,"TextEditingStarting"),this.MM=t}canStart(){if(!this.isEnabled)return!1;const t=this.diagram;if(t===null||t.isReadOnly||TextEditingTool.Hf&&TextEditingTool.Hf!==this&&(TextEditingTool.Hf.acceptText(2),TextEditingTool.Hf&&TextEditingTool.Hf!==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.Hf=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.Wt=2;let s=this.defaultTextEditor;i.textEditor!==null&&(s=i.textEditor),this.Ee=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.Wt===6?this.currentTextEditor instanceof HTMLElement&&this.currentTextEditor.focus():(this.Wt===2||this.Wt===5||this.Wt===3)&&(this.Wt=4,this.ET());break;case 1:case 4:case 3:if(t===4&&this.textBlock!==null&&this.textBlock.isMultiline===!0)return;(this.Wt===2||this.Wt===5||this.Wt===3)&&(this.Wt=4,this.ET());break}}ET(){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.Wt=5,this.doError(s,n);return}this.startTransaction(this.name),this.Wt=6,this.transactionResult=this.name,t.text=n,this.doSuccess(s,n),i!==null&&i.F("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.Wt=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.Hf=null}DR(t){if(this.currentTextEditor===null||this.state===1)return;const i=this.$x;this.Wt===2&&(this.Wt=3),U.ht(i.select)&&this.selectsTextOnActivate&&(i.select(),i.setSelectionRange(0,9999))}FR(t){if(this.currentTextEditor===null||this.state===1)return;const i=this.$x;U.ht(i.focus)&&i.focus(),U.ht(i.select)&&this.selectsTextOnActivate&&(i.select(),i.setSelectionRange(0,9999))}isValidText(t,i,e){U.s(t,TextBlock,TextEditingTool,"isValidText:textblock");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.ql}set textValidation(t){t!==null&&U.C(t,TextEditingTool,"textValidation"),this.ql=t}get minimumEditorScale(){return this.NM}set minimumEditorScale(t){t!==null&&U.i(t,"number",TextEditingTool,"minimumEditorScale"),this.NM=t}get selectsTextOnActivate(){return this.CM}set selectsTextOnActivate(t){t!==null&&U.i(t,"boolean",TextEditingTool,"selectsTextOnActivate"),this.CM=t}get state(){return this.Wt}set state(t){this.Wt!==t&&(U.W(t,TextEditingState,"TextEditingState"),this.Wt=t)}measureTemporaryTextBlock(t){const i=this.Ee;return i.text=t,this.textBlock!==null&&i.gt(this.textBlock.Hl,1/0),i}static Hf=null}var AnimationStyle=(w=>(w[w.Default=1]="Default",w[w.AnimateLocations=2]="AnimateLocations",w[w.None=3]="None",w))(AnimationStyle||{});class AnimationManager{f;Ii;Gi;Rr;eo;Xo;TM;LM;$m;Zx;Mi;vf;Mn;Zm;ua;Qx;Qm;_x;Wf;Uu;_m;constructor(t){this.f=Diagram.Xm(),this.Ii=!1,this.$m=!1,this.Zx=!1,this.Mi=!1,this.vf=!1,this._x=!0,this.Wf=1,this.Uu=!1,this.Gi=!0,this.Rr=!0,this.Xo=600,this.TM=!1,this.LM=!1,this.eo=new GSet,this.Mn=new Animation,this.Zm=new Animation,this.Mn.Ls=this,this.ua=new GSet,this.Qx=new GSet,this.Qm=new GSet,this._m=new GSet,t&&Object.assign(this,t)}Yo(t){this.f=t}OB(){return this.f}canStart(t){return!0}vl(t){return!this.Gi||!this.canStart(t)?!1:(this.eo.add(t),this.defaultAnimation.isAnimating&&this.stopAnimation(),this.f.Ri(),this.Mi=!0,!0)}getBundleAnimation(){return this.Zm}DM(){if(!this.Gi||(this.Zm.be.count>0&&this.Zm.start(),!this.Mi))return;const t=this.Mn,i=this.f,e=this.eo.has("Model");if(e&&(this.vf=!0,this.Wf===1?(t.isViewportUnconstrained=!0,t.be.clear(),t.add(i,"position",i.position.copy().offset(0,-200),i.position),t.add(i,"opacity",0,1)):this.Wf===3&&t.be.clear(),this.Wf===2&&i.t1.equals(i.yt)?this._x=!0:this._x=!1,i.F("InitialAnimationStarting",this)),e&&!this.Rr||t.be.count===0){this.eo.clear(),this.Mi=!1,t.be.clear(),t.i1(i),this.vf=!1,i.L();return}this.eo.clear(),i.Or=!1;const s=t.be.get(i);i.autoScale!==1&&s!==null&&(delete s.ci.scale,delete s.Ds.scale);const n=this;root.requestAnimationFrame(()=>{n.Mi===!1||t.Ii||(i.getRenderingHint("temporaryPixelRatio")&&i.Ox(),i.FM(),n.Mi=!1,t.start(),t.Ii&&(n.Hu(),i.invalidateDocumentBounds(),t.BT(0),i.Ar(!0),n.vu(),i.F("AnimationStarting",n)))})}IM(){return this.eo.has("Trigger")&&this.eo.count===1}VT(t,i,e,s){this.isTicking||this.IM()||t instanceof Link&&(t.fromNode!==null||t.toNode!==null)||this.Mn.add(t,"position",i,e,s)}e1(t){return this.Mn.e1(t)}RM(t){return this.Mn.RM(t)}IR(t){const i=this.ua,e=this;function s(){if(e.Qm.count>0&&(i.addAll(e.Qm),e.Qm.clear(),e.Ii=!0),e.Ii===!1||i.count===0){e.Zx=!1;return}e.Qx.addAll(i);const n=e.Qx.iterator;for(;n.next();){const o=n.value;o.Ii!==!1&&(o.RR()?o.zT(!1):o.jf=!0)}if(e.Qx.clear(),e.Ii===!1){root.requestAnimationFrame(s);return}e.Hu(),e.f.Ar(),e.vu(),root.requestAnimationFrame(s)}this.Ii?this.XT(t):(this.Ii=!0,this.Zx?this.XT(t):(this.Zx=!0,i.add(t),root.requestAnimationFrame(()=>s())))}XT(t){this.Qm.add(t)}OR(){const t=this.ua.iterator;for(;t.next();)t.value.jf=!1}Hu(){if(this.$m)return;const t=this.f;this.TM=t.skipsUndoManager,this.LM=t.Se,t.skipsUndoManager=!0,t.Se=!0,this.$m=!0}vu(){const t=this.f;t.skipsUndoManager=this.TM,t.Se=this.LM,this.$m=!1}stopAnimation(t){const i=this.Mn;if(this.Mi===!0&&(this.Mi=!1,this.vf=!1,this.eo.clear(),i.ER()&&this.f.requestUpdate()),!this.Ii){i.be.clear(),i.i1(this.f);return}if(i.Wu(!0),i.i1(null),t===!0){const e=this.ua.toArray();for(let s=0;s{!i.isAnimating&&i.runCount===1/0&&i.start()})}get duration(){return this.Xo}set duration(t){U.i(t,"number",AnimationManager,"duration"),t<1&&U.G(t,">= 1",AnimationManager,"duration"),this.Xo=t}get isAnimating(){return this.Ii}get isTicking(){return this.$m}get isInitial(){return this.Rr}set isInitial(t){U.i(t,"boolean",AnimationManager,"isInitial"),this.Rr=t}get defaultAnimation(){return this.Mn}get activeAnimations(){return this.ua}get initialAnimationStyle(){return this.Wf}set initialAnimationStyle(t){Debug&&U.W(t,AnimationStyle,"AnimationStyle"),this.Wf=t}static s1=new GMap;static defineAnimationEffect(t,i){AnimationManager.s1.set(t,i)}static BM(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 a=i[0],f=i[1];const c=i[2],u=i[3];l===0||l===100?(o=a,r=f):(c===0||c===100)&&(a=o,f=r),Math.abs(a-o)>180&&(a>o?o+=360:a+=360);const d=n(e,o,a-o,s)%360,m=n(e,r,f-r,s),g=n(e,l,c-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 w=AnimationManager.s1,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))};w.set("position:diagram",t),w.set("position",t),w.set("position:part",(i,e,s,n,o,r)=>{o{o{o{const l=i.actualBounds,h=s.actualBounds,a=h.x+h.width/2-l.width/2,f=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))}),w.set("width",(i,e,s,n,o,r)=>{i.width=n(o,e,s-e,r)}),w.set("height",(i,e,s,n,o,r)=>{i.height=n(o,e,s-e,r)}),w.set("fill",(i,e,s,n,o,r)=>{i.fill=AnimationManager.BM(e,s,o,r,n)}),w.set("stroke",(i,e,s,n,o,r)=>{i.stroke=AnimationManager.BM(e,s,o,r,n)}),w.set("strokeWidth",(i,e,s,n,o,r)=>{i.strokeWidth=n(o,e,s-e,r)}),w.set("strokeDashOffset",(i,e,s,n,o,r)=>{i.strokeDashOffset=n(o,e,s-e,r)}),w.set("background",(i,e,s,n,o,r)=>{i.background=AnimationManager.BM(e,s,o,r,n)}),w.set("opacity",(i,e,s,n,o,r)=>{i.opacity=n(o,e,s-e,r)}),w.set("scale",(i,e,s,n,o,r)=>{i.scale=n(o,e,s-e,r)}),w.set("angle",(i,e,s,n,o,r)=>{i.angle=n(o,e,s-e,r)})}class Animation{o1;t0;Ii;ju;Xo;Fs;GT;Zf;be;l1;ci;so;Ju;Qf;h1;a1;jf;VM;f1;Ls;f;zM;XM;YM;constructor(t){this.f=null,this.Ls=null,this.VM=null,this.f1=null,this.zM=!1,this.Ii=!1,this.jf=!1,this.ci=0,this.so=0,this.o1=Animation.EaseInOutQuad,this.t0=Animation.EaseInOutQuad,this.Ju=!1,this.Qf=!1,this.h1=1,this.a1=0,this.Xo=NaN,this.Fs=NaN,this.XM=0,this.ju=null,this.GT=Point.yn,this.be=new GMap,this.l1=new GMap,this.Zf=new GSet,this.YM=1,t&&Object.assign(this,t)}suspend(){this.jf=!0}advanceTo(t,i){i&&(this.jf=!1),this.Ju&&t>=this.Fs&&(this.Qf=!0,t=t-this.Fs),this.XM=t,this.zT(!0),this.Ls.Hu(),this.f.Ar(),this.Ls.vu(),this.f.redraw()}i1(t){if(this.l1.clear(),this.Qf=!1,this.a1=0,this.Fs=NaN,this.Zf.count>0&&this.Zf.clear(),t!==null){const i=t.links;for(;i.next();)i.value.Er=null}}ER(){return this.be.count>0}start(){if(this.be.count===0)return this;if(this.Ii)return this;let t=this.f;const i=this.be.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.f=t,this.Ls=t.animationManager;else return this;const e=this.Ls;return e.isEnabled===!1?this:(this.Fs=isNaN(this.Xo)?e.duration:this.Xo,this.t0=this.o1,e.vf&&e.Wf===1&&this===e.defaultAnimation&&(this.t0=Animation.EaseOutExpo,this.Fs=isNaN(this.Xo)?e.duration===600?900:e.duration:this.Xo),this.YM=t.scrollMode,this.isViewportUnconstrained&&(t.da=2),e.Hu(),this.Zf.each(s=>{s.data=null,t.add(s)}),e.vu(),this.Ii=!0,this.ci=+new Date,this.so=this.ci+this.Fs,e.IR(this),this)}addTemporaryPart(t,i){return t.Oe()?(Debug&&(i===void 0&&U.n("addTemporaryPart: Required Diagram argument missing"),t.diagram===i&&U.n("addTemporaryPart: Part already in Diagram, did you mean to pass in a copy?"),this.f!==null&&this.f!==i&&U.n("addTemporaryPart: A different Diagram is already associated with this Animation: "+this.f.toString())),this.Zf.add(t),this.f=i,this):this}add(t,i,e,s,n){if(this.f===null&&(t instanceof Diagram?this.f=t:t instanceof GraphObject&&t.diagram!==null&&(this.f=t.diagram)),t instanceof Part){if(!t.isAnimated)return this;i==="position"&&(i="position:part")}return this.OM(t,i,e,s,n),this}OM(t,i,e,s,n){const o=this.be;let r,l,h;if(t instanceof Diagram&&i==="position"&&(i="position:diagram"),(i==="fill"||i==="stroke"||i==="background")&&(Brush.Ko(e),Brush.KM(),e=[Brush.qi.n0,Brush.qi.n1,Brush.qi.n2,Brush.qi.n3],Brush.Ko(s),Brush.KM(),s=[Brush.qi.n0,Brush.qi.n1,Brush.qi.n2,Brush.qi.n3]),o.has(t))r=o.get(t),l=r.ci,h=r.Ds,l[i]===void 0&&(l[i]=this.$u(e)),h[i]=this.$u(s);else{if(i==="position"&&e.equalsApprox(s))return;l={},h={},l[i]=this.$u(e),h[i]=this.$u(s),r=new AnimationState(l,h,n),o.set(t,r)}const a=l[i];a instanceof Point&&!a.isReal()&&a.c(this.GT),n&&i.indexOf("position:")===0&&t instanceof Part?r.c1.location=this.$u(t.location):n&&(r.c1[i]=this.$u(e))}$u(t){return t instanceof Point||t instanceof Size?t.copy():t}BR(t){const i=this.be;if(i.has(t)){const e=i.get(t);e.u1=!0}}e1(t){if(!this.Ii)return!1;const i=this.be.get(t);return i!==null&&i.u1}RM(t){if(!this.Ii)return!1;const i=this.be.get(t);return i!==null&&!!(i.ci.position||i.ci["position:part"]||i.ci.location)}RR(){if(this.Zf.count>0)return!0;const t=this.be.iterator;for(;t.next();){const i=t.key;if(i instanceof GraphObject&&i.diagram!==null||i instanceof Diagram)return!0}return!1}zT(t){if(this.jf&&!t)return;const i=this.Ls;if(this.Ii===!1)return;const e=+new Date;let s=e>this.so?this.Fs:e-this.ci;t&&(s=this.XM,sthis.so&&(this.Ju&&!this.Qf?(this.ci=+new Date,this.so=this.ci+this.Fs,this.Qf=!0):this.Wu(!1))}BT(t){const i=this.Fs,e=this.be.iterator,s=this.Qf;for(;e.next();){const n=e.key;if(n instanceof GraphObject&&n.diagram===null)continue;const o=e.value,r=s?o.Ds:o.ci,l=s?o.ci:o.Ds,h=AnimationManager.s1;for(const a in l)a==="position"&&(l["position:placeholder"]||l["position:nodeCollapse"])||h.get(a)!==null&&h.get(a)(n,r[a],l[a],this.t0,t,i,this)}}stop(){return this.Ii?(this.Wu(!0),this):this}Wu(t){if(this.f1!==null&&this.f1.VR(this.VM),!this.Ii)return;const i=this.f,e=this.Ls;e.vf=!1,this.Ii=!1,this.jf=!1,e.Hu();const s=this.be,n=this.Zf.iterator;for(;n.next();)i.remove(n.value);const o=this.Ju,r=s.iterator,l=AnimationManager.s1;for(;r.next();){const a=r.key,f=r.value,c=o?f.Ds:f.ci,u=o?f.ci:f.Ds,d=f.c1;for(const m in u)if(l.get(m)!==null){let g=m;f.d1&&(g==="position:nodeCollapse"||g==="position:placeholder")&&(g="position"),l.get(g)(a,c[m],d[m]!==void 0?d[m]:f.d1?c[m]:u[m],this.t0,this.Fs,this.Fs,this)}f.d1&&d.location!==void 0&&a instanceof Part&&(a.location=d.location),f.u1&&a instanceof Part&&a.Hi(!1)}this.a1++;const h=!t&&this.h1>this.a1;if(!h&&(this===e.Zm||this===e.defaultAnimation)&&this.be.clear(),i.g1.clear(),i.PP(!1),i.invalidateDocumentBounds(),i.L(),i.Ar(!0),e.defaultAnimation===this){const a=e._m.iterator;for(;a.next();)a.value.zR();e._m.clear()}if(i.Ar(!0),this.isViewportUnconstrained&&(i.scrollMode=this.YM),e.vu(),h){this.Qf=!1,this.start();return}this.i1(null),i.qT(),e.Wu(this),this.ju&&this.ju(this),i.requestUpdate()}Jf(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.XR(t,i)}XR(t,i){const e=t.memberParts;for(;e.next();){const s=e.value;s instanceof Node&&this.Jf(s,i)}}$f(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.BR(t),t instanceof Group&&this.YR(t,i)}YR(t,i){const e=t.memberParts;for(;e.next();){const s=e.value;s instanceof Node&&this.$f(s,i)}}get duration(){return this.Xo}set duration(t){U.i(t,"number",Animation,"duration"),t<1&&U.G(t,">= 1",Animation,"duration"),this.Xo=t}get reversible(){return this.Ju}set reversible(t){this.Ju=t}get runCount(){return this.h1}set runCount(t){t>0?this.h1=t:U.n("Animation.runCount value must be a positive integer.")}get finished(){return this.ju}set finished(t){this.ju!==t&&(t!==null&&U.C(t,Animation,"finished"),this.ju=t)}get easing(){return this.o1}set easing(t){this.o1=t}get isViewportUnconstrained(){return this.zM}set isViewportUnconstrained(t){this.zM=t}get isAnimating(){return this.Ii}getTemporaryState(t){let i=this.l1.get(t);return i===null&&(i={},this.l1.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{ci;Ds;c1;d1;u1;constructor(t,i,e){this.ci=t,this.Ds=i,this.c1={},this.d1=e,this.u1=!1}}var TriggerStart=(w=>(w[w.Default=1]="Default",w[w.Immediate=2]="Immediate",w[w.Bundled=3]="Bundled",w))(TriggerStart||{});class AnimationTrigger{Re;Sn;Zu;_f;constructor(t,i,e){e&&Debug&&U.W(e,TriggerStart,"TriggerStart"),this.Re=null,this.Sn=t,this.Zu=e||1,this._f=null,i!==void 0&&(this._f=i,e===void 0&&(this.Zu=2))}copy(){const t=new AnimationTrigger(this.Sn);t.Zu=this.Zu;const i=this._f;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._f=e}return t}get propertyName(){return this.Sn}set propertyName(t){this.Sn=t}get animationSettings(){return this._f}set animationSettings(t){this._f=t}KR(t){const i=this._f;i!==null&&(i.duration&&(t.duration=i.duration),i.finished&&(t.finished=i.finished),i.easing&&(t.easing=i.easing))}get startCondition(){return this.Zu}set startCondition(t){Debug&&U.W(t,TriggerStart,"TriggerStart"),this.Zu=t}static Default=1;static Immediate=2;static Bundled=3}class Layer{f;At;ei;Br;Wl;jl;Jl;$l;Zl;Ql;_l;th;ih;eh;nh;oh;qf;lh;m1;i0;Qu;Ft;constructor(t){GSet._i(this),this.f=null,this.Ft=new List,this.At="",this.ei=1,this.Br=!1,this.Wl=!0,this.jl=!0,this.Jl=!0,this.$l=!0,this.Zl=!0,this.Ql=!0,this._l=!0,this.th=!0,this.ih=!0,this.eh=!0,this.nh=!0,this.oh=!0,this.qf=!0,this.lh=!0,this.m1=!0,this.i0=!1,this.Qu=[],t&&Object.assign(this,t)}UR(){const t=this.Ft;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 a=this.Ft.iterator;for(;a.next();){const f=a.value;h+=` `+f.toString();const c=f.data;c!==null&&GSet.Ps(c)&&(h+=" #"+GSet.Ps(c)),f instanceof Node?h+=" "+U.toString(c):f instanceof Link&&(h+=" "+U.toString(f.fromNode)+" "+U.toString(f.toNode))}}return i+" "+this.Ft.count+": "+h}findObjectAt(t,i,e){if(i===void 0&&(i=null),e===void 0&&(e=null),this.lh===!1)return null;Debug&&!t.isReal()&&U.n("findObjectAt: Point must have a real value, not: "+t.toString());let s=!1;this.diagram!==null&&this.diagram.viewportBounds.containsPoint(t)&&(s=!0);const n=Point.a(),o=this.Ft.h,r=o.length;for(let l=r;l--;){const h=o[l];if(s===!0&&h.Kl()===!1||!h.isVisible())continue;n.c(t),n.We(h.Qs);let a=h.HT(n,i,e);if(a!==null&&(i!==null&&(a=i(a)),a!==null&&(e===null||e(a))))return Point.o(n),a}return Point.o(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.lh===!1)return s;Debug&&!t.isReal()&&U.n("findObjectsAt: Point must have a real value, not: "+t.toString());let n=!1;this.diagram!==null&&this.diagram.viewportBounds.containsPoint(t)&&(n=!0);const o=Point.a(),r=this.Ft.h,l=r.length;for(let h=l;h--;){const a=r[h];if(n===!0&&a.Kl()===!1||!a.isVisible())continue;o.c(t),o.We(a.Qs);let f=a;a.vT(o,i,e,s)&&(i!==null&&(f=i(f)),f!==null&&(e===null||e(f))&&s.add(f))}return Point.o(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.lh===!1)return n;Debug&&!t.isReal()&&U.n("findObjectsIn: Rect must have a real value, not: "+t.toString());let o=!1;this.diagram!==null&&this.diagram.viewportBounds.containsRect(t)&&(o=!0);const r=this.Ft.h,l=r.length;for(let h=l;h--;){const a=r[h];if(o===!0&&a.Kl()===!1||!a.isVisible())continue;let f=a;a.e0(t,i,e,s,n)&&(i!==null&&(f=i(f)),f!==null&&(e===null||e(f))&&n.add(f))}return n}DP(t,i,e,s,n,o,r){if(this.lh===!1)return n;const l=this.Ft.h,h=l.length;for(let a=h;a--;){const f=l[a];if(r===!0&&f.Kl()===!1||!o(f)||!f.isVisible())continue;let c=f;f.e0(t,i,e,s,n)&&(i!==null&&(c=i(c)),c!==null&&(e===null||e(c))&&n.add(c))}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.lh===!1)return o;Debug&&!t.isReal()&&U.n("findObjectsNear: Point must have a real value, not: "+t.toString());let r=!1;this.diagram!==null&&this.diagram.viewportBounds.containsPoint(t)&&(r=!0);const l=Point.a(),h=Point.a(),a=this.Ft.h,f=a.length;for(let c=f;c--;){const u=a[c];if(r===!0&&u.Kl()===!1||!u.isVisible())continue;l.c(t),l.We(u.Qs),h.e(t.x+i,t.y),h.We(u.Qs);let d=u;u.WT(l,h,e,s,n,o)&&(e!==null&&(d=e(d)),d!==null&&(s===null||s(d))&&o.add(d))}return Point.o(l),Point.o(h),o}GM(){return this.Ft.h}fs(t,i){if(!this.visible)return;const e=this.Ft.h,s=e.length;if(s===0)return;const n=U.at(),o=U.at();for(let r=0;r0&&o.push(l))}for(let r=0;re.o0||a.height*n>e.o0?i.vi(t,e):this.vR(t,i,e),f&&(t.restore(),t.clearContextCache(!0))}vR(t,i,e){if(t instanceof SVGContext){i.vi(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.E;if(i.background===null){i.Nn(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.Nn(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))}}HR(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.r0(e);const n=this.diagram;return n!==null&&(e?n.L():n.ma(i)),this.p1(t,i),t}ae(t,i,e){if(!e&&i.layer!==this&&i.layer!==null)return i.layer.ae(t,i,e);const s=this.Ft;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.l0(e),s.removeAt(t);const n=this.diagram;return n!==null&&(e?n.L():n.ae(i)),i.UM(null),t}p1(t,i){t=this.WR(t,i),i instanceof Group&&this.jR(t,i),i.svg!==null&&i.svg.remove()}WR(t,i){const e=i.zOrder;if(isNaN(e))return t;const s=this.Ft,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.G(t,"0 <= value <= 1",Layer,"opacity"),this.ei=t;const e=this.diagram;e!==null&&e.L(),this.t("opacity",i,t)}}get isViewportAligned(){return this.i0}set isViewportAligned(t){const i=this.i0;i!==t&&(this.i0=t,this.diagram&&(this.JT(),this.diagram.L()),this.t("isViewportAligned",i,t),t&&(this.isInDocumentBounds=!1))}JT(){if(!this.i0)return;const t=this.diagram;if(t===null)return;const i=this.Ft.h,e=i.length,s=t.Pt,n=t.Mt;for(let o=0;o(w[w.None=1]="None",w[w.Uniform=2]="Uniform",w[w.UniformToFill=3]="UniformToFill",w))(AutoScale||{}),CycleMode=(w=>(w[w.All=1]="All",w[w.NotDirected=2]="NotDirected",w[w.NotDirectedFast=3]="NotDirectedFast",w[w.NotUndirected=4]="NotUndirected",w[w.DestinationTree=5]="DestinationTree",w[w.SourceTree=6]="SourceTree",w))(CycleMode||{}),ScrollMode=(w=>(w[w.Document=1]="Document",w[w.Infinite=2]="Infinite",w))(ScrollMode||{}),CollapsePolicy=(w=>(w[w.TreeParent=1]="TreeParent",w[w.AllParents=2]="AllParents",w[w.AnyParents=3]="AnyParents",w))(CollapsePolicy||{});class Diagram{Ls;Qt;vM;w1;Vr;td;b1;S1;k1;P1;M1;N1;pa;da;C1;A1;T1;hh;ic;zr;h0;L1;D1;ed;no;Xr;ya;Uo;a0;ec;f0;sc;sd;Yr;oo;WM;jM;F1;I1;JM;R1;$M;ZM;QM;O1;c0;Kr;Ur;Gr;qr;Hr;vr;E1;Wr;B1;jr;Jr;$r;Zr;V1;_M;Go;t2;z1;X1;i2;Di;e2;nc;s2;Js;qo;Gi;Y1;Wl;jl;K1;U1;Jl;$l;Zl;G1;Ql;_l;th;ih;eh;nh;oh;q1;H1;o2;nd;od;v1;W1;j1;J1;u0;$1;Z1;Q1;si;$T;_1;ZT;rd;Cn;ro;fe;lo;QT;ah;l2;h2;d0;tb;ld;g0;ib;Qr;fh;wa;a2;f2;m0;eb;sb;cs;hd;p0;ad;Ho;oc;y0;_r;xa;c2;w0;$t;E;$e;Or;Wi;Is;u2;ch;tl;Bl;il;ba;rc;d2;fd;Sa;cd;Gt;uh;yt;lt;ud;Pt;Mt;ut;lc;Ix;nb;ka;hc;ob;rb;x0;ZR;QR;te;zl;o0;b0;g2;m2;_T;S0;_R;tO;iO;lb;eO;sO;nO;Pa;tL;dh;Ma;Na;Ca;Aa;Ku;ca;_t;Dt;ac;_k;tP;Vf;ei;static hb=null;static iL=new GMap;static p2;static w2=null;Yu;ab;fb;dd;cb;ub;k0;b2;P0;M0;N0;t1;S2;k2;fc;C0;A0;constructor(t,i){if(Diagram.Qw||(Diagram.Kk(),Diagram.Qw=!0),GSet._i(this),Diagram.eL(this),this.$t=!0,this.Dt=null,this.Pt=0,this.Mt=0,this.ut=null,Diagram.isUsingDOM()){const s=this,n=()=>{s.Fi(root.document,"DOMContentLoaded",n,!1),s.setRTL()};root.document.body!==null?this.setRTL():s.Kt(root.document,"DOMContentLoaded",n,!1)}this.lc=null,Diagram.P2("Model",PartManager);const e=this;return this.e2=s=>e.partManager.doModelDataChanged(s),this.nc=s=>e.partManager.doModelChanged(s),this.ob=null,this.rb=null,this.sL(),this.model=Model.M2(),this.themeManager=new ThemeManager,this.Go=!0,this.nL(),this.layout=new Layout,this.Go=!1,this._R=null,this.tO=null,this.iO=null,this.lb=null,this.eO=null,this.sO=null,this.nO=null,this.Pa=null,this.tL=null,this.dh=null,this.Ma=null,this.Na=null,this.Ca=null,this.Aa=null,this.Ku=()=>{},this.ca=null,this.ad=!1,this.ac=new DiagramHelper(this),t!==void 0&&(typeof t=="string"||root.Element&&t instanceof Element?this.N2(t):i=t),i&&this.setProperties(i),this.$t=!1,this.requestUpdate(),this}mR(){return this.ut!==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.Ho.get("svg"),s!==null&&s.Nt.remove(),this.ut&&(this._t=this.ut.ni,this._t.clearContextCache(!0))):i==="svg"?(this.Ho.has("svg")?s=this.Ho.get("svg"):(s=new SVGSurface(this,root.document),this.addRenderer("svg",s)),this.div!==null&&(s.Nt.role="img",this.div.appendChild(s.Nt)),this.ut&&(this._t=s.ni,this.ut.ni.setTransform(this.te,0,0,this.te,0,0),this.ut.ni.clearRect(0,0,this.Pt,this.Mt))):i==="debug"&&(this.Ho.has("SVG")||(s=new SVGSurface(this,root.document),this.addRenderer("SVG",s),s.Nt.style.backgroundColor="whitesmoke",this.div!==null&&this.div.after(s.Nt))),this.$t||this.redraw()}sL(){if(this.fc=new List,this.setupRouters(),this.Ls=new AnimationManager,this.Ls.Yo(this),this.Qt=17,this.vM=!1,this.ud=!1,this.w1="default",this.Gt=new List,this.Ho){const t=this.Ho.get("svg");t!==null&&t.Nt.remove(),this.ut&&(this._t=this.ut.ni,this._t.clearContextCache(!0))}this.Ho=new GMap,this.oc="default",this.resetRenderingHints(),this.oO(),this.ei=1,this.yt=new Point(NaN,NaN).k(),this.t1=new Point(NaN,NaN),this.lt=1,this.w0=1,this.b1=new Point(NaN,NaN).k(),this.S1=NaN,this.k1=1e-4,this.P1=100,this.E=new Transform,this.M1=new Point(NaN,NaN).k(),this.N1=new Rect(NaN,NaN,NaN,NaN).k(),this.pa=new Margin(0,0,0,0).Ct(),this.da=1,this.C1=!1,this.A1=null,this.T1=null,this.hh=1,this.ic=Spot.Default,this.zr=1,this.h0=Spot.Default,this.L1=Spot.None,this.D1=Spot.None,this.$e=!0,this.ed=!1,this.no=new Set,this.Xr=new GSet,this.ya=new GSet,this.Uo=!1,this.uh=new GMap,this.fd=!0,this.a0=250,this.ec=-1,this.f0=new Margin(16,16,16,16).Ct(),this.Or=!1,this.sc=!1,this.sd=!0,this.y0=new InputEvent,this.y0.diagram=this,this._r=new InputEvent,this._r.diagram=this,this.xa=new InputEvent,this.xa.diagram=this,this.Yr=null,this.oo=null,this.Ix=!1,this.rO(),this.il=new GSet,this.F1=!0,this.I1=1,this.JM=!1,this.R1=1,this.O1="auto",this.c0="auto",this.Kr=null,this.Ur=null,this.Gr=null,this.qr=null,this.Hr=null,this.vr=null,this.E1=null,this.Wr=null,this.B1=!1,this.jr=null,this.Jr=null,this.$r=null,this.Zr=null,this.V1=!1,this.nb={},this.ka=[null,null],this.Go=!1,this.t2=!1,this.z1=!1,this.X1=!1,this.i2=!0,this.Is=!1,this.Sa=!1,this.s2=!0,this.Js=-2,this.ch=new GMap,this.cd=new List,this.qo=!1,this.Gi=!0,this.Y1=!0,this.Wl=!0,this.jl=!0,this.K1=!1,this.U1=!0,this.Jl=!0,this.$l=!0,this.Zl=!0,this.G1=!0,this.Ql=!0,this._l=!0,this.th=!0,this.ih=!0,this.eh=!0,this.nh=!0,this.oh=!0,this.q1=!0,this.H1=!0,this.o2=!1,this.hc=!1,this.nd=!0,this.od=!0,this.v1=!0,this.W1=!0,this.j1=16,this.J1=16,this.u0=!1,this.$1=!1,this.Z1=0,this.Q1=0,this.si=new Margin(5).Ct(),this.$T=new GSet().k(),this._1=999999999,this.ZT=new GSet().k(),this.ba=!0,this.rd=!0,this.rc=!0,this.Cn=!1,this.ro=!1,this.tl=!0,this.Bl=!1,this.lo=!1,this.QT=new GSet,this.d2=new GSet,this.ah=null,this.l2=new Size(Link.oL,Link.rL),this.h2=999,this.d0=!1,this._k=1,this.tP=0,this.Wi={scale:1,position:new Point,bounds:new Rect,canvasSize:new Size,newCanvasSize:new Size,isScroll:!1},this.Wi.canvasSize=this.Wi.canvasSize,this.Wi.newCanvasSize=this.Wi.newCanvasSize,this.Wi.isScroll=!1,this.tb=new Rect(NaN,NaN,NaN,NaN).k(),this.ld=new Size(NaN,NaN).k(),this.g0=new Rect(NaN,NaN,NaN,NaN).k(),this.ib=!1,this.C0=null,this.A0=null,this.lO(),this.cs=null,this.hd=!1,this.Vf=null,this.partManager=new PartManager,this.toolManager=new ToolManager,this.toolManager.initializeStandardTools(),this.defaultTool=this.toolManager,this.currentTool=this.defaultTool,this.fb=null,this.dd=new DraggingOptions,this.cb=null,this.ub=null,this.ab=!1,this.Yu=!1,this.commandHandler=new CommandHandler,this.M0=null,this.N0=Point.wn,this.S2=!1,this.te=1,this.zl=null,this.o0=1,this.k0=0,this.b2=[0,0,0,0,0],this.P0=0,this.b0=1,this.g2=0,this.m2=new Point,this._T=500,this.p0=new Point,this.S0=!1}static lL=root.document!==void 0;static isUsingDOM(){return Diagram.lL}static setDocument(t){root.document=t}static useDOM(t){Diagram.lL=t?root.document!==void 0:!1}static Ze=new WeakMap;clear(){this.animationManager.stopAnimation(),this.model.clear(),Diagram.hL(),this.aL(!1),this.cd.clear(),this.fL(),this.ah=null,this.invalidateDocumentBounds(),this.ensureBounds(),this.L()}aL(t){this.animationManager.stopAnimation(!0),this.clearSelection(),this.clearHighlighteds();const i=this.skipsUndoManager,e=this.Di!==null&&this.Di!==void 0;e&&(this.skipsUndoManager=!0);let s=null;this.cs!==null&&(s=this.cs.part,s!==null&&this.remove(s));const n=[],o=this.Gt.length;if(t){for(let r=0;rt?new Margin(t/2):1.5)).freezeBindings(),this.eb=this.m0,this.sb=new Adornment(Panel.Link).add(new Shape({isPanelMain:!0,fill:null,stroke:"dodgerblue",strokeWidth:3}).theme("stroke","selection").theme("strokeWidth","selection")).freezeBindings()}setRTL(t){let i=t===void 0?this.div:t;i===null&&(i=root.document.body);const e=U.Le("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.w1=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.w2,n=Diagram.p2;s===null&&(Diagram.w2=U.Le("p"),s=Diagram.w2,s.style.width="100%",s.style.height="200px",s.style.boxSizing="content-box",Diagram.p2=U.Le("div"),n=Diagram.p2,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.yr&&(e=11)}this.Qt=e,this.vM=!0}gi(t){t in AutoScale?this.autoScale=t:U.wr(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.Gt.iterator;for(;s.next();){const n=s.value;e+=` `+n.toString(t-1)}return e}static eL(t){Diagram.hb=t}static Xm(){return Diagram.hb}static fromDiv(t){let i=t;if(typeof t=="string"&&(i=root.document.getElementById(t)),i instanceof HTMLDivElement){const e=Diagram.Ze.get(i);if(e)return e}return null}get div(){return this.Dt}set div(t){if(t!==null&&U.s(t,HTMLDivElement,Diagram,"div"),this.Dt!==t){const i=this.Dt;if(i!==null){if(Diagram.Ze.delete(i),i.goDiagram=void 0,i.go=void 0,i.innerHTML="",this.ut!==null){const s=this.ut.Nt;this.Fi(s,"pointermove",this.Ma,!1),this.Fi(s,"pointerdown",this.dh,!1),this.Fi(s,"pointerup",this.Na,!1),this.Fi(s,"pointerout",this.Ca,!1),this.Fi(s,"pointercancel",this.Aa,!1),this.ut.dispose()}this.lc&&(this.lc.disconnect(),this.lc=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.ut=null,this.Fi(root,"resize",this.lb,!1),this.Fi(root,"wheel",this.Pa,!0),Diagram.Xm()===this&&Diagram.eL(null)}else this.dh===null&&(this.lo=!1);if(this.Dt=null,t!==null){const e=Diagram.Ze.get(t);e&&(e.div=null),this.N2(t),this.Ku(),this.themeManager&&this.themeManager.hO()}else this.themeManager&&this.themeManager.aO()}}setupRouters(){this.fc.push(new AvoidsNodesRouter)}N2(t){const i=this;if(!Diagram.isUsingDOM())return;t==null&&U.n("Diagram setup requires an argument DIV."),i.Dt!==null&&U.n("Diagram has already completed setup."),typeof t=="string"?i.Dt=root.document.getElementById(t):t instanceof HTMLDivElement?i.Dt=t:U.n("No DIV or DIV id supplied: "+t),i.Dt===null&&U.n("Invalid DIV id; could not get element with id: "+t);const e=Diagram.Ze.get(i.Dt);if(e&&e!==this&&U.n("Invalid div id; div already has a Diagram associated with it."),!i.lc&&root.ResizeObserver){const f=root.ResizeObserver,c=U.Ok(()=>i.requestUpdate(),250,!1);i.lc=new f(()=>c()),i.lc.observe(i.Dt)}root.getComputedStyle(i.Dt,null).position==="static"&&(i.Dt.style.position="relative");let s=5;const n="rgba(2"+s+"5, 255, 255, 0)";s--,i.Dt.style["-webkit-tap-highlight-color"]=n,i.Dt.innerHTML="",Diagram.Ze.set(i.Dt,i),i.Dt.goDiagram=i,i.Dt.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.Dt,null).getPropertyValue("direction")==="rtl"&&(i.ud=!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"),o.Nt.setAttribute("role","application"),i.ut=o,i._t=o.ni;const r=i._t;i.te=i.computePixelRatio(),i.viewSize.isReal()||(i.Pt=i.Dt.clientWidth||1,i.Mt=i.Dt.clientHeight||1),i.cL(i.Pt,i.Mt);const l=i;i.Dt.insertBefore(o.Nt,i.Dt.firstChild);const h=new CanvasSurface(null);if(h.width=1,h.height=1,i.ZR=h,i.QR=h.ni,Diagram.isUsingDOM()){const f=U.Le("div"),c=U.Le("div");f.style.position="absolute",f.style.overflow="auto",f.style.width=i.Pt+"px",f.style.height=i.Mt+"px",f.style.zIndex="1",c.style.position="absolute",c.style.width="1px",c.style.height="1px",i.Dt.appendChild(f),f.appendChild(c),f.onscroll=Diagram.fO,f.addEventListener("pointerdown",Diagram.cO),f.f=i,f.uO=!0,f.dO=!0,i.ob=f,i.rb=c}i.Ku=U.Ok(()=>{i.zl=null,i.L()},300,!1),i.lb=U.Ok(()=>{i.FM()},250,!1),i.ca=f=>(f.preventDefault(),!1),i.Pa=f=>{if(!l.isEnabled)return;const c=l.cc(f,!0);c.bubbles=!0;let u=0,d=0;c.delta=0,f.deltaX!==void 0?(f.deltaX!==0&&(u=f.deltaX>0?1:-1),f.deltaY!==0&&(d=f.deltaY>0?1:-1),c.delta=Math.abs(f.deltaX)>Math.abs(f.deltaY)?-u:-d):f.wheelDeltaX!==void 0?(f.wheelDeltaX!==0&&(u=f.wheelDeltaX>0?-1:1),f.wheelDeltaY!==0&&(d=f.wheelDeltaY>0?-1:1),c.delta=Math.abs(f.wheelDeltaX)>Math.abs(f.wheelDeltaY)?-u:-d):f.wheelDelta!==void 0&&f.wheelDelta!==0&&(c.delta=f.wheelDelta>0?1:-1),l.doMouseWheel(),l.Ta(c,f)},i.tL=f=>{if(!l.isEnabled)return;i.hc=!1,l.cc(f,!0);const c=l.currentTool;c.cancelWaitAfter(),c.standardMouseOver()},i.dh=f=>{if(!l.isEnabled)return;i.hc=!0;const c=l.nb;c[f.pointerId]===void 0&&(c[f.pointerId]=f);const u=l.ka;let d=!1;if(u[0]!==null&&(u[0].pointerId===f.pointerId||u[0].pointerType!==f.pointerType))u[0]=f;else if(u[1]!==null&&u[1].pointerId===f.pointerId)u[1]=f,d=!0;else if(u[0]===null)u[0]=f;else if(u[1]===null)u[1]=f,d=!0;else{f.preventDefault();return}const m=f.pointerType==="touch"||f.pointerType==="pen";m&&(l.Ix=!1,l.S0=!0);const g=l.gO(f,f,d),p=l.m2,y=m?25:10;if(f.timeStamp-l.g2y||Math.abs(p.y-f.screenY)>y)?l.b0++:l.b0=1,g.clickCount=l.b0,l.g2=f.timeStamp,l.m2.setTo(f.screenX,f.screenY),l.doMouseDown(),f.button===1){f.preventDefault();return}l.Ta(g,f)},i.Ma=f=>{if(!l.isEnabled)return;i.hc=!0;const c=l.ka;if(c[0]!==null&&(c[0].pointerId===f.pointerId||c[0].pointerType!==f.pointerType))c[0]=f;else if(c[1]!==null&&c[1].pointerId===f.pointerId){c[1]=f;return}else if(c[0]===null)c[0]=f;else return;if(c[0].pointerId!==f.pointerId)return;const u=l.mO(f,f,c[1]!==null);l.doMouseMove(),l.Ta(u,f)},i.Na=f=>{if(!l.isEnabled)return;i.hc=!0;const c=f.pointerType==="touch"||f.pointerType==="pen",u=l.nb;if(c&&l.Ix){delete u[f.pointerId],f.preventDefault();return}const d=l.ka;if(d[0]!==null&&(d[0].pointerId===f.pointerId||d[0].pointerType!==f.pointerType))d[0]=null;else if(d[1]!==null&&d[1].pointerId===f.pointerId){d[1]=null;return}else return;const m=l.C2(f,!1,!0,!1,!0,!1);let g=root.document.elementFromPoint(f.clientX,f.clientY)||null;g!==null&&g.shadowRoot&&(g=g.shadowRoot.elementFromPoint(f.clientX,f.clientY)||null),g!==null&&g.f instanceof Diagram&&g.f!==l&&g.f.L0(f,m),g===null&&(g=f.target),l.L0(f,m),m.clickCount=l.b0,m.targetDiagram=l.gb(f,g),m.targetObject=null,l.doMouseUp(),l.Ta(m,f),c&&(l.S0=!1)},i.Ca=f=>{if(!l.isEnabled)return;i.hc=!1;const c=l.nb;c[f.pointerId]&&delete c[f.pointerId];const u=l.ka;if(u[0]!==null&&u[0].pointerId===f.pointerId&&(u[0]=null),u[1]!==null&&u[1].pointerId===f.pointerId&&(u[1]=null),f.pointerType==="touch"||f.pointerType==="pen")return;const d=l.currentTool;d.cancelWaitAfter(),d.standardMouseOver()},i.Aa=f=>{const c=l.ka;c[0]!==null&&c[0].pointerId===f.pointerId?(c[0]=null,l.S0=!1):c[1]!==null&&c[1].pointerId===f.pointerId&&(c[1]=null)};const a=r;if(i.x0=a.B[U.Qi("7eba17a4ca3b1a8346")][U.Qi("78a118b7")](a.B,Diagram.La,s,s),r.clearContextCache(!0),i.pO(),this.oc==="svg"){const f=this.Ho.get("svg");this.Dt&&this.Dt.appendChild(f.Nt),this._t=f.ni}}addEventListener(t,i,e,s){t.addEventListener(i,e,{capture:s,passive:!1})}Kt(t,i,e,s){t.addEventListener(i,e,{capture:s,passive:!1})}removeEventListener(t,i,e,s){t.removeEventListener(i,e,{capture:s})}Fi(t,i,e,s){t.removeEventListener(i,e,{capture:s})}pO(){const t=this;let i=this.ut.Nt;i instanceof HTMLCanvasElement||(i=t.div),this.Kt(i,"pointerdown",t.dh,!1),this.Kt(i,"pointermove",t.Ma,!1),this.Kt(i,"pointerup",t.Na,!1),this.Kt(i,"pointerout",t.Ca,!1),this.Kt(i,"pointercancel",t.Aa,!1),this.Kt(i,"pointerenter",t.yO,!1),this.Kt(i,"pointerleave",t.wO,!1),this.Kt(i,"wheel",t.Pa,!1),this.Kt(i,"keydown",t.xO,!1),this.Kt(i,"keyup",t.bO,!1),this.Kt(i,"blur",t.SO,!1),this.Kt(i,"focus",t.kO,!1),this.Kt(i,"selectstart",e=>(e.preventDefault(),!1),!1),this.Kt(i,"contextmenu",e=>(e.preventDefault(),!1),!1),this.Kt(root,"resize",t.lb,!1)}Ox(){this.k0>30&&(this.zl=1)}PP(t){this.zl!==null&&(this.zl=null,t&&this.Ku(),Debug&&Debug.drawFrames||(this.k0=0,this.b2=[0,0,0,0,0],this.P0=0))}computePixelRatio(){return this.zl!==null?this.zl:root.devicePixelRatio||1}get avgSpf(){return this.k0}doMouseDown(){this.currentTool.doMouseDown()}doMouseMove(){this.currentTool.doMouseMove()}doMouseUp(){this.currentTool.doMouseUp()}doMouseWheel(){this.currentTool.doMouseWheel()}doKeyDown(){const t=this.commandHandler;if(!this.toggleKeyboardControl()){if((t.isFocusEnabled||t.isVirtualPointerEnabled)&&t.doVirtualFocusKeyDown()){const i=this.lastInput;i.bubbles=!1;const e=i.event;e&&(e.stopPropagation&&e.stopPropagation(),e.cancelable!==!1&&e.preventDefault());return}this.currentTool.doKeyDown()}}toggleKeyboardControl(){const t=this.lastInput,i=t.commandKey;if((t.control||t.meta)&&t.alt&&(i==="Enter"||i==="NumpadEnter")){const e=this.commandHandler,s=e.isFocusEnabled||e.isVirtualPointerEnabled;return e.isFocusEnabled=!s,e.isVirtualPointerEnabled=!s,e.focus=e.findFirstFocus(),this.F("FocusOrVirtualPointerEnabledChanged"),!0}return!1}doKeyUp(){const t=this.commandHandler;if((t.isFocusEnabled||t.isVirtualPointerEnabled)&&t.doVirtualFocusKeyUp()){const i=this.lastInput;i.bubbles=!1;const e=i.event;e&&(e.stopPropagation&&e.stopPropagation(),e.cancelable!==!1&&e.preventDefault());return}this.currentTool.doKeyUp()}gd(t,i){if(i)for(const e in i)e!=="sourceDiagram"&&(t[e]=i[e])}emitMouseDown(t,i,e,s){if(typeof t!="number"||typeof i!="number")throw new Error("Robot.mouseDown first two args must be X,Y numbers");e===void 0&&(e=0);let n=this;if(s&&s.sourceDiagram&&(n=s.sourceDiagram),!n.isEnabled)return this;const o=new InputEvent;return o.diagram=n,o.documentPoint=new Point(t,i),o.viewPoint=n.transformDocToView(o.documentPoint),o.timestamp=e,o.down=!0,this.gd(o,s),n.lastInput=o,n.firstInput=o.copy(),n.doMouseDown(),this}emitMouseMove(t,i,e,s){if(typeof t!="number"||typeof i!="number")throw new Error("Robot.mouseMove first two args must be X,Y numbers");e===void 0&&(e=0);let n=this;if(s&&s.sourceDiagram&&(n=s.sourceDiagram),!n.isEnabled)return this;const o=new InputEvent;return o.diagram=n,o.documentPoint=new Point(t,i),o.viewPoint=n.transformDocToView(o.documentPoint),o.timestamp=e,this.gd(o,s),n.lastInput=o,n.doMouseMove(),this}emitMouseUp(t,i,e,s){if(typeof t!="number"||typeof i!="number")throw new Error("Robot.mouseUp first two args must be X,Y numbers");e===void 0&&(e=0);let n=this;if(s&&s.sourceDiagram&&(n=s.sourceDiagram),!n.isEnabled)return this;const o=new InputEvent;return o.diagram=n,o.documentPoint=new Point(t,i),o.viewPoint=n.transformDocToView(o.documentPoint),o.timestamp=e,o.up=!0,n.firstInput.documentPoint.equals(o.documentPoint)&&(o.clickCount=1),this.gd(o,s),n.lastInput=o,n.doMouseUp(),this}emitMouseWheel(t,i,e){if(typeof t!="number")throw new Error("Robot.mouseWheel first arg must be DELTA number");i===void 0&&(i=0);const s=this;if(!s.isEnabled)return this;const n=new InputEvent;return n.diagram=s,n.documentPoint=s.lastInput.documentPoint,n.viewPoint=s.lastInput.viewPoint,n.delta=t,n.timestamp=i,this.gd(n,e),s.lastInput=n,s.doMouseWheel(),this}emitKeyDown(t,i,e){if(typeof t!="string"&&typeof t!="number")throw new Error("Robot.keyDown first arg must be a string or a number");i===void 0&&(i=0);const s=this;if(!s.isEnabled)return this;const n=new InputEvent;return n.diagram=s,n.documentPoint=s.lastInput.documentPoint,n.viewPoint=s.lastInput.viewPoint,typeof t=="string"?n.key=t:typeof t=="number"&&(n.key=String.fromCharCode(t)),n.timestamp=i,n.down=!0,this.gd(n,e),s.lastInput=n,s.doKeyDown(),this}emitKeyUp(t,i,e){if(typeof t!="string"&&typeof t!="number")throw new Error("Robot.keyUp first arg must be a string or a number");i===void 0&&(i=0);const s=this;if(!s.isEnabled)return this;const n=new InputEvent;return n.diagram=s,n.documentPoint=s.lastInput.documentPoint,n.viewPoint=s.lastInput.viewPoint,typeof t=="string"?n.key=t:typeof t=="number"&&(n.key=String.fromCharCode(t)),n.timestamp=i,n.up=!0,this.gd(n,e),s.lastInput=n,s.doKeyUp(),this}doFocus(){this.focus()}focus(){if(this.ut)if(this.scrollsPageOnFocus)this.ut.focus();else{const t=root.scrollX,i=root.scrollY;this.ut.focus(),root.scrollTo(t,i)}}kO(t){const i=Diagram.Ze.get(this);i&&i.F("GainedFocus")}SO(t){const i=Diagram.Ze.get(this);i&&i.F("LostFocus")}FM(){if(this.ut===null)return;const i=this.Dt;if(i===null||i.clientWidth===0||i.clientHeight===0)return;this.vM||this.setScrollWidth();const e=this.ro?this.Qt:0,s=this.Cn?this.Qt:0,n=this.te;if(this.te=this.computePixelRatio(),this.te!==n&&(this.ed=!0,this.requestUpdate()),i.clientWidth!==this.Pt+e||i.clientHeight!==this.Mt+s){this.Da(),this.$e=!0;const o=this.layout;o!==null&&o.isViewportSized&&this.autoScale===1&&(this.sc=!0,o.b()),this.Is||this.requestUpdate()}}nL(){let t=0,i=new Layer;i.name="Grid",i.allowSelect=!1,i.pickable=!1,i.isTemporary=!0,i.isInDocumentBounds=!1,this.el(i,t++),i=new Layer,i.name="ViewportBackground",i.isViewportAligned=!0,i.isTemporary=!0,i.isInDocumentBounds=!1,this.el(i,t++),i=new Layer,i.name="Background",this.el(i,t++),i=new Layer,i.name="",this.el(i,t++),i=new Layer,i.name="Foreground",this.el(i,t++),i=new Layer,i.name="ViewportForeground",i.isViewportAligned=!0,i.isTemporary=!0,i.isInDocumentBounds=!1,this.el(i,t++),i=new Layer,i.name="Adornment",i.isTemporary=!0,i.isInDocumentBounds=!1,this.el(i,t++),i=new Layer,i.name="Tool",i.isTemporary=!0,i.isInDocumentBounds=!0,this.el(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 fO(){const t=Diagram.Ze.get(this.parentElement||this);if(t){if(t.$1){t.$1=!1;return}if(!t.isEnabled){t.dL();return}t.diagramScroll(this)}}static cO(t){if(!this.f.isEnabled){this.f.updateScroll();return}this.f.Z1=t.target.scrollTop,this.f.Q1=t.target.scrollLeft}diagramScroll(t){if(this.ut===null)return;const i=this.ob,e=this.rb;this.u0=!0;let s=this.documentBounds,n=this.viewportBounds;const o=this.pa;let r=s.x-o.left,l=s.y-o.top;const h=s.width+o.left+o.right,a=s.height+o.top+o.bottom;let f=s.right+o.right,c=s.bottom+o.bottom,u=n.x,d=n.y;const m=n.width,g=n.height;let p=n.right,y=n.bottom;const x=this.scale;let b,S=t.scrollLeft;if(this.ud)switch(this.w1){case"negative":S=S+t.scrollWidth-t.clientWidth;break;case"reverse":S=t.scrollWidth-S-t.clientWidth;break}const k=S;if(mp)){const P=i.scrollWidth-this.Pt;this.position=b.e(-P+k-this.Pt/x+f,this.position.y)}if(t.dO&&this.allowVerticalScroll&&(ly)){const P=i.scrollHeight-this.Mt;this.position=b.e(this.position.x,-P+t.scrollTop-this.Mt/x+c)}Point.o(b),this.mh(),this.u0=!1,this.rd=!1,s=this.documentBounds,n=this.viewportBounds,f=s.right,p=n.right,c=s.bottom,y=n.bottom,r=s.x,u=n.x,l=s.y,d=n.y,m>=h&&r>=u&&f<=p&&(e.style.width="1px"),g>=a&&l>=d&&c<=y&&(e.style.height="1px")}computeBounds(t){return t===void 0&&(t=new Rect),this.Ri(),this.gL(t)}gL(t){if(this.fixedBounds.isReal())return t.c(this.fixedBounds),t.addMargin(this.si),t;let i=!0;const e=this.Gt.h,s=e.length;for(let n=0;nl?h=(r-this.Qt)/n:l=(o-this.Qt)/s);let u=0;return t===2?u=Math.min(h,l):t===3&&(h>l?u=(r-this.Qt)/n:u=(o-this.Qt)/s),u>i&&(u=i),uthis.maxScale&&(u=this.maxScale),u}zoomToFit(){const t=this.da;this.da=1,this.scale=this.md(2),this.alignDocument(Spot.Center,Spot.Center),t!==1&&(this._s(!1),this.A2(this.documentBounds,this.Pt/this.lt,this.Mt/this.lt,this.ic,!1)),this.da=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.Pt,r=this.Mt;i===3?r/s>o/e?n=(r-(this.Cn?this.Qt:0))/s:n=(o-(this.ro?this.Qt:0))/e:n=Math.min(r/s,o/e)}this.scale=n,this.position=new Point(t.x,t.y)}get PO(){return this.$t}set PO(t){this.$t=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.M0=t;const i=Point.a();this.N0=this.transformDocToView(t.getDocumentPoint(Spot.TopLeft,i)),Point.o(i)}else this.M0=null,this.N0=Point.wn}A2(t,i,e,s,n){const o=Point.U(this.yt.x,this.yt.y);let r=o.x,l=o.y;if(this.M0!==null){let h=Point.a();h=this.M0.getDocumentPoint(Spot.TopLeft,h),r=h.x-this.N0.x/this.scale,l=h.y-this.N0.y/this.scale,s=Spot.None,Point.o(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.pa,a=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.AP(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.Ri();const s=this.Gt.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}AP(t,i,e){i===void 0&&(i=null),e===void 0&&(e=null),this.Ri();const s=this.Gt.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.NO(t,s=>s.part,i?s=>s instanceof Part&&s.canSelect():null,e)}NO(t,i,e,s){i===void 0&&(i=null),e===void 0&&(e=null),!(s instanceof List)&&!(s instanceof GSet)&&(s=new GSet),this.Ri();const n=this.Gt.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.Ri();const n=this.Gt.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.CO(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.Ri();const o=this.Gt.iteratorBackwards;for(;o.next();){const r=o.value;r.visible&&r.findObjectsIn(t,i,e,s,n)}return n}DP(t,i,e,s,n,o){const r=new GSet;this.Ri();const l=this.Gt.iteratorBackwards;for(;l.next();){const h=l.value;h.visible&&h.DP(t,i,e,s,r,n,o)}return r}CO(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.Ri();const o=this.Gt.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.AO(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.Ri();const r=this.Gt.iteratorBackwards;for(;r.next();){const l=r.value;l.visible&&l.findObjectsNear(t,i,e,s,n,o)}return o}AO(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.Ri();const r=this.Gt.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.cc(t,t instanceof MouseEvent)}cc(t,i){const e=this._r;this._r=this.xa,this.xa=e,e.diagram=this,e.event=t,i?this.L0(t,e):(e.viewPoint=this._r.viewPoint,e.documentPoint=this._r.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.yr&&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.gb(t,t.target),e.targetObject=null,e}gb(t,i){if(i===null)return null;const e=Diagram.Ze.get(i);if(e)return e;let s=t.path;if(!s&&U.ht(t.composedPath)&&(s=t.composedPath()),s&&s[0]){const n=Diagram.Ze.get(s[0]);if(n)return n}return null}gO(t,i,e){const s=this.C2(t,!0,!1,!1,!0,e);return this.L0(i,s),s.targetDiagram=this.gb(t,t.target),s.targetObject=null,e||s.clone(this.y0),s}mO(t,i,e){const s=this.C2(t,!1,!1,!1,!1,e);let n=root.document.elementFromPoint(i.clientX,i.clientY)||null;n!==null&&n.shadowRoot&&(n=n.shadowRoot.elementFromPoint(i.clientX,i.clientY)||null);let o=this,r=t;if(n){const l=this.gb(t,n);l&&(r=i,o=l)}return s.targetDiagram=o,this.L0(r,s),s.targetObject=null,s}C2(t,i,e,s,n,o){const r=this._r;this._r=this.xa,this.xa=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.yr&&t.button===0&&t.ctrlKey&&(r.button=2),r.down=i,r.up=e,r.handled=s,r.bubbles=n,r.isMultiTouch=o,r}Ta(t,i){return t.bubbles?(Debug&&Debug.handleMessages&&U.ot("NOT handled "+i.type+" "+t.toString()),!0):(Debug&&Debug.handleMessages&&U.ot("handled "+i.type+" "+this.currentTool.name+" "+t.toString()),i.stopPropagation!==void 0&&i.stopPropagation(),i.cancelable!==!1&&i.preventDefault(),i.cancelBubble=!0,!1)}xO(t){const i=Diagram.Ze.get(this);if(!i||!i.isEnabled)return!1;const e=i.cc(t,!1);return e.key=t.key,e.code=t.code,e.down=!0,i.doKeyDown(),i.Ta(e,t)}bO(t){const i=Diagram.Ze.get(this);if(!i||!i.isEnabled)return!1;const e=i.cc(t,!1);return e.key=t.key,e.code=t.code,e.up=!0,i.doKeyUp(),i.Ta(e,t)}yO(t){const i=Diagram.Ze.get(this);if(!i||!i.isEnabled)return!1;const e=i.cc(t,!0);return i.mouseEnter!==null&&i.mouseEnter(e),i.currentTool.standardMouseOver(),i.Ta(e,t)}wO(t){const i=Diagram.Ze.get(this);if(!i||!i.isEnabled)return!1;const e=i.cc(t,!0);return i.mouseLeave!==null&&i.mouseLeave(e),i.Ta(e,t)}getMouse(t){const i=this.ut;if(i===null)return new Point(0,0);const e=i.getBoundingClientRect(),s=(t.clientX-e.left)*(this.Pt/e.width),n=(t.clientY-e.top)*(this.Mt/e.height);return new Point(s,n).We(this.E)}L0(t,i){const e=this.ut;let s=0,n=0;if(e!==null){const r=e.getBoundingClientRect();s=(t.clientX-r.left)*(this.Pt/r.width),n=(t.clientY-r.top)*(this.Mt/r.height)}i.viewPoint.e(s,n);const o=Point.U(s,n);this.E.De(o),i.documentPoint.c(o),Point.o(o)}oT(t,i,e){let s;if(this.ka[0]!==null)s=this.ka[i];else return;const n=this.ut;if(n!==null){const o=n.getBoundingClientRect();e.e((s.clientX-o.left)*(this.Pt/o.width),(s.clientY-o.top)*(this.Mt/o.height))}}invalidateDocumentBounds(){this.ba||(this.ba=!0,this.requestUpdate(!1))}TO(){this.Is||this.Ri(),this.ensureBounds()}redraw(){this.$t||this.Is||(this.L(),this.maybeUpdate())}isUpdateRequested(){return this.Or}delayInitialization(t){t===void 0&&(t=null);const i=this.animationManager,e=i.isEnabled;i.stopAnimation(),i.isEnabled=!1,this.Ar(),this.lo=!1,this.t1=new Point(NaN,NaN),i.isEnabled=e,this.Is=!0;const s=this;t!==null&&U.pn(()=>{s.Is=!1,i.vl("Model"),t(s)},1)}requestUpdate(t){if(t===void 0&&(t=!1),this.Or===!0||this.$t||t===!1&&this.Is)return;this.Or=!0;const i=this;root.requestAnimationFrame(()=>{i.Or&&i.maybeUpdate()})}maybeUpdate(){this.sd&&!this.Or||(this.sd&&(this.sd=!1),this.Ar())}T2(t,i){!this.rd||this.$t||this.animationManager.defaultAnimation.isAnimating||this.dL()||(t&&this.Ri(),i&&this._s(!1))}Ar(t){if(this.Is||(this.Or=!1,this.Dt===null&&!this.ld.isReal()))return;this.Is=!0;const i=this.animationManager,e=this.cd;if(!i.isAnimating&&e.length!==0){const f=e.h,c=f.length;for(let u=0;u0&&(s.each(f=>f.L2()),s.clear());let n=!1,o=!1;i.defaultAnimation.isAnimating&&(o=!0,n=this.skipsUndoManager,this.skipsUndoManager=!0),i.Mi||this.FM(),t||this.T2(!1,!0);const r=!this.undoManager.isUndoingRedoing&&(this.Bl||this.fc.count!==0&&this.Xr.size!==0),l=!this.lo||this.tl;this.Ri(!0);let h=!1;(l||r)&&(this.lo?this.D2(!this.sc,r):(this.startTransaction("Initial Layout"),i.isEnabled===!1&&i.stopAnimation(),this.D2(!1,r)),h=l),this.sc=!1,this.Bl=!1,this.Ri(),this.cs!==null&&(this.cs.visible&&!this.hd&&(this.ph(),this.hd=!0),!this.cs.visible&&this.hd&&(this.hd=!1)),this.z1||this.TO(),t||this.T2(!0,!1);let a=!1;if(h){const f=Rect.a();f.c(this.viewportBounds),this.lo||(this.lo=!0,a=!0,this.skipsUndoManager||(this.undoManager.Dx=!0),this.undoManager.Fx=!0,this.LO()),this.DO(),this.Ri(!1),t||this.T2(!0,!0),Rect.o(f)}else if(i.vf&&i._x){if(this.zr!==1)this.scale=this.md(this.zr);else if(this.hh!==1)this.scale=this.md(this.hh);else{const f=this.initialScale;isFinite(f)&&f>0&&(this.scale=f)}this._s(!0)}h&&a&&this.commitTransaction("Initial Layout"),t||this.vi(this._t),o&&(this.skipsUndoManager=n),this.Is=!1}get oa(){return this.lo}LO(){if(this.zr!==1)this.scale=this.md(this.zr);else if(this.hh!==1)this.scale=this.md(this.hh);else{const i=this.initialScale;isFinite(i)&&i>0&&(this.scale=i)}this._s(!0);const t=this.Gt.h;this.fs(t,t.length,this,this.viewportBounds),this.F("InitialLayoutCompleted"),this.t1.c(this.yt),this.ph()}DO(){this.F("LayoutCompleted")}F0(t){this.no.add(t)}addInvalidRoute(t){this.Uo?this.ya.add(t):this.Xr.add(t)}Ri(t){if(this.no.size!==0&&!(!this.Is&&this.animationManager.isTicking)){if(this.Is||(this.Bl=!0),t){this.mL(this.no);return}for(let i=0;i<23&&this.no.size!==0;i++){const e=new Set(this.no);this.no.clear(),this.L2(e,this.no),Debug&&i===22&&U.ot("failure to validate parts")}this.nodes.each(i=>{i instanceof Group&&i.pL(!1)})}}mL(t,i){for(const e of t)!e.Oe()||e instanceof Group||(e.sl()?(e.gt(1/0,1/0),e.Ut()):i&&i.add(e));for(const e of t)if(e instanceof Group){if(!e.isVisible())continue;this.pb(e)}}L2(t,i){this.mL(t,i);for(const e of t){if(!(e instanceof Link))continue;const s=e;s.isVisible()&&(s.sl()?(s.gt(1/0,1/0),s.Ut()):i.add(s))}for(const e of t)e instanceof Adornment&&e.isVisible()&&(e.sl()?(e.gt(1/0,1/0),e.Ut()):i.add(e))}pd(t){const i=t instanceof Diagram,e=i?t.links:t.memberParts,s=this.no;if(i)this.Ri(!0);else{for(;e.next();){const n=e.value;s.has(n)&&(!n.Oe()||n instanceof Group||n.sl()&&(n.gt(1/0,1/0),n.Ut()))}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.sl()&&(n.gt(1/0,1/0),n.Ut())}}pb(t){const i=U.at(),e=U.at(),s=t.memberParts;for(;s.next();){const o=s.value;o.isVisible()&&(o instanceof Group?(o.vo()||o.us()||o.yh())&&this.pb(o):o instanceof Link?o.fromNode===t||o.toNode===t?e.push(o):i.push(o):(o.gt(1/0,1/0),o.Ut()))}let n=i.length;for(let o=0;ob.tc())}else for(let y=0;y0){const a=n.substring(0,h);e?o=t.findObject(a):(o=t[a],o==null&&(o=t.toolManager[a])),U.it(o)?r=n.substring(h+1):U.n("Unable to find object named: "+a+" in "+t.toString()+" when trying to set property: "+n)}}if(r[0]!=="_"&&!U.Zw(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.Zw(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.n('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)}}qT(){if(this.uh.count!==0&&!(this.undoManager.transactionLevel>1)){for(;this.uh.count>0;){const t=this.uh;this.uh=new GMap;const i=t.iterator;for(;i.next();){const e=i.key;e.invalidateOtherJumpOvers(i.value),e.ce()}}this.L()}}L(t){if(t===void 0)this.$e=!0,this.requestUpdate();else{const i=this.viewportBounds;t.isReal()&&i.intersectsRect(t)&&(this.$e=!0,this.requestUpdate())}this.F("InvalidateDraw")}invalidateViewport(t,i){if(this.$e===!0)return;if(this.$e=!0,this.oc==="svg"){this.maybeUpdate();return}this.getRenderingHint("temporaryPixelRatio")===!0?(this.Ox(),this.maybeUpdate(),this.PP(!0)):this.maybeUpdate()}Da(){this.rd=!0}mh(){this.rc=!0}I0(){this.ed!==!1&&(this.ed=!1,this.cL(this.Pt,this.Mt))}cL(t,i){this.gh();const e=this.te,s=t*e,n=i*e;this.ut.resize(s,n,t,i)&&(this.$e=!0,this._t.clearContextCache(!0))}dL(){const t=this.ut;if(t===null||this.ld.isReal())return!0;const i=this.Pt,e=this.Mt,s=this.Dt;let n=!1,o=this.ro?this.Qt:0,r=this.Cn?this.Qt:0,l=s.clientWidth||i+o,h=s.clientHeight||e+r;const a=this.viewportBounds,f=a.x,c=a.y,u=a.width,d=a.height;if((l!==i+o||h!==e+r)&&(this.ro=!1,this.Cn=!1,o=0,r=0,this.Pt=l,this.Mt=h,this.ed=!0,n=!0,this.gh()),!this.lo||!this.viewportBounds.isReal())return!0;const m=this.ob,g=this.rb;if(this.rd=!1,!n&&!this.ro&&!this.Cn&&!this.nd&&!this.od)return!0;const p=this.documentBounds;let y=0,x=0,b=0,S=0;const k=a.width,P=a.height,A=this.pa;this.contentAlignment.isSpot()?(p.width>k&&(y=A.left,x=A.right),p.height>P&&(b=A.top,S=A.bottom)):(y=A.left,x=A.right,b=A.top,S=A.bottom);const C=p.width+y+x,M=p.height+b+S,N=this.scale,T=N;let L=C>l/N,D=M>h/N;if(!n&&!this.ro&&!this.Cn&&!L&&!D)return!0;const F=p.x-y,R=a.x,I=p.right+x;let O=a.right+o;const X=p.y-b,K=a.y,B=p.bottom+S;let Y=a.bottom+r,z="1px",H="1px";if(this.scrollMode===1&&(L||D)){if(L&&this.hasHorizontalScrollbar&&this.allowHorizontalScroll){let V=1;F+1O+1&&(V=Math.max((I-O)*N+this.Pt,V)),k+o+1Y+1&&(V=Math.max((B-Y)*N+this.Mt,V)),P+r+1O+1&&($=Math.max((I-O)*N+this.Pt,$)),k+1Y+1&&($=Math.max((B-Y)*N+V,$)),P+1O+1&&(Z=this.position.x*N)),this.ud)switch(this.w1){case"negative":Z=-(m.scrollWidth-Z-m.clientWidth);break;case"reverse":Z=m.scrollWidth-Z-m.clientWidth;break}if(m.scrollLeft=Z,this.hasVerticalScrollbar&&this.allowVerticalScroll&&(P+1Y+1&&(m.scrollTop=this.position.y*N)),l=this.Pt,h=this.Mt,m.style.width=l+(this.ro?this.Qt:0)+"px",m.style.height=h+(this.Cn?this.Qt:0)+"px",i!==l||e!==h||this.animationManager.Mi){const V=Rect.U(f,c,u,d);return this.onViewportBoundsChanged(V,this.viewportBounds,T,n),Rect.o(V),!1}return!0}add(t){U.s(t,Part,Diagram,"add:part");const i=t.diagram;if(i===this)return;i!==null&&U.n("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.n('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.ma(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)}ma(t){this.partManager.ma(t);const i=this;Diagram.isUsingDOM()&&t.An(s=>i.wL(s)),t.data||t.Wo(),t.hasPlaceholder()&&t.g(),t.data!==null&&t.An(s=>i.partManager.I2(s,null)),(t.us()===!0||t.yh()===!0)&&this.F0(t),t.xL(!0,this),t instanceof Node&&t.canAvoid()&&this.yd(t),t.bL()?(t.actualBounds.isReal()&&this.L(t.ga(t.actualBounds)),this.invalidateDocumentBounds()):t.isVisible()&&t.actualBounds.isReal()&&this.L(t.ga(t.actualBounds)),this.C0!==null&&this.C0(this,t),this.requestUpdate()}ae(t){t.clearAdornments(),this.partManager.ae(t);const i=this;t.data!==null&&t.An(s=>i.partManager.R2(s,i)),this.no.delete(t),t instanceof Link?this.Xr.delete(t):t instanceof Node&&t.canAvoid()&&this.yd(t),t.bL()?(t.actualBounds.isReal()&&this.L(t.ga(t.actualBounds)),this.invalidateDocumentBounds()):t.isVisible()&&t.actualBounds.isReal()&&this.L(t.ga(t.actualBounds)),this.A0!==null&&this.A0(this,t),this.requestUpdate()}remove(t){U.s(t,Part,Diagram,"remove:part"),this.O2(t,!0)}O2(t,i){const e=t.layer;if(e===null||e.diagram!==this)return;t.isSelected=!1,t.isHighlighted=!1,t.invalidateLayout(2),i&&t.uc();const s=e.ae(-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.Di!==null&&this.raiseChangedEvent(3,"layers",this,null,t,null,e+1),this.L(),this.invalidateDocumentBounds(),this}addLayerBefore(t,i){this.E2(t,i),t.Yo(this);const e=this.Gt,s=e.indexOf(t);s>=0&&(e.delete(t),this.Di!==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.Di!==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 f=Point.U(this.yt.x+l/t-l/i,this.yt.y+h/t-h/i);this.position=f,Point.o(f),this.lt=i,this.D0(),this.gh(),this.$t=!1,this.onViewportBoundsChanged(n,this.viewportBounds,t,!1),this._s(!1),e.UT(t,this.lt),this.L()}MO(){const t=this.Gt.h;for(let i=0;i{l.isAvoiding&&l.actualBounds.intersectsRect(i)&&l.ii()})}ph(t){const i=this.cs;if(i===null||!i.visible||i.part===null||i.layer===null)return;const e=t!==void 0?t:this.tb;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.Ni===null&&(i.Ni=new GridPanelSettings);const o=i.Ni.dc;if(!o.isReal())return;i.width=s+o.width*2,i.height=n+o.height*2;const r=Point.a();G.rm(e.x,e.y,0,0,o.width,o.height,r),r.offset(-o.width,-o.height),i.part.location=r,Point.o(r)}}clearSelection(t){t===void 0&&(t=!1);const i=this.selection;if(i.count===0)return;t||this.F("ChangingSelection",i);const e=i.toArray(),s=e.length;for(let n=0;n1)&&(this.F("ChangingSelection",this.selection),this.clearSelection(!0),t.isSelected=!0,this.F("ChangedSelection",this.selection)))}selectCollection(t){if(this.F("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.n("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.a();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.e(h.x,l.y):i==="left"?this.position=o.e(l.x,h.y):i==="down"?this.position=o.e(h.x,l.bottom-h.height):i==="right"&&(this.position=o.e(l.right-h.width,h.y)),Point.o(o);return}else U.n("scrolling unit must be 'pixel', 'line', 'page', or 'document', not: "+t);n/=this.scale;const r=this.position;i==="up"?this.position=o.e(r.x,r.y-n):i==="down"?this.position=o.e(r.x,r.y+n):i==="left"?this.position=o.e(r.x-n,r.y):i==="right"?this.position=o.e(r.x+n,r.y):U.n("scrolling direction must be 'up', 'down', 'left', or 'right', not: "+i),Point.o(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().E(this.E)}transformViewToDoc(t){return t.copy().We(this.E)}$R(t){return t.We(this.E)}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.ei}set opacity(t){const i=this.ei;i!==t&&(U.i(t,"number",Diagram,"opacity"),(t<0||t>1)&&U.G(t,"0 <= value <= 1",Diagram,"opacity"),this.ei=t,this.t("opacity",i,t),this.L())}get validCycle(){return this.R1}set validCycle(t){const i=this.R1;i!==t&&(U.W(t,CycleMode,"CycleMode"),this.R1=t,this.t("validCycle",i,t))}get layers(){return this.Gt.iterator}get isModelReadOnly(){const t=this.Di;return t===null?!1:t.isReadOnly}set isModelReadOnly(t){const i=this.Di;i!==null&&(i.isReadOnly=t)}get isReadOnly(){return this.qo}set isReadOnly(t){const i=this.qo;i!==t&&(U.i(t,"boolean",Diagram,"isReadOnly"),this.qo=t,this.t("isReadOnly",i,t))}get isEnabled(){return this.Gi}set isEnabled(t){const i=this.Gi;i!==t&&(U.i(t,"boolean",Diagram,"isEnabled"),this.Gi=t,this.t("isEnabled",i,t))}get allowClipboard(){return this.Y1}set allowClipboard(t){const i=this.Y1;i!==t&&(U.i(t,"boolean",Diagram,"allowClipboard"),this.Y1=t,this.t("allowClipboard",i,t))}get allowCopy(){return this.Wl}set allowCopy(t){const i=this.Wl;i!==t&&(U.i(t,"boolean",Diagram,"allowCopy"),this.Wl=t,this.t("allowCopy",i,t))}get allowDelete(){return this.jl}set allowDelete(t){const i=this.jl;i!==t&&(U.i(t,"boolean",Diagram,"allowDelete"),this.jl=t,this.t("allowDelete",i,t))}get allowDragOut(){return this.K1}set allowDragOut(t){const i=this.K1;i!==t&&(U.i(t,"boolean",Diagram,"allowDragOut"),this.K1=t,this.t("allowDragOut",i,t))}get allowDrop(){return this.U1}set allowDrop(t){const i=this.U1;i!==t&&(U.i(t,"boolean",Diagram,"allowDrop"),this.U1=t,this.t("allowDrop",i,t))}get allowTextEdit(){return this.Jl}set allowTextEdit(t){const i=this.Jl;i!==t&&(U.i(t,"boolean",Diagram,"allowTextEdit"),this.Jl=t,this.t("allowTextEdit",i,t))}get allowGroup(){return this.$l}set allowGroup(t){const i=this.$l;i!==t&&(U.i(t,"boolean",Diagram,"allowGroup"),this.$l=t,this.t("allowGroup",i,t))}get allowUngroup(){return this.Zl}set allowUngroup(t){const i=this.Zl;i!==t&&(U.i(t,"boolean",Diagram,"allowUngroup"),this.Zl=t,this.t("allowUngroup",i,t))}get allowInsert(){return this.G1}set allowInsert(t){const i=this.G1;i!==t&&(U.i(t,"boolean",Diagram,"allowInsert"),this.G1=t,this.t("allowInsert",i,t))}get allowLink(){return this.Ql}set allowLink(t){const i=this.Ql;i!==t&&(U.i(t,"boolean",Diagram,"allowLink"),this.Ql=t,this.t("allowLink",i,t))}get allowRelink(){return this._l}set allowRelink(t){const i=this._l;i!==t&&(U.i(t,"boolean",Diagram,"allowRelink"),this._l=t,this.t("allowRelink",i,t))}get allowMove(){return this.th}set allowMove(t){const i=this.th;i!==t&&(U.i(t,"boolean",Diagram,"allowMove"),this.th=t,this.t("allowMove",i,t))}get allowReshape(){return this.ih}set allowReshape(t){const i=this.ih;i!==t&&(U.i(t,"boolean",Diagram,"allowReshape"),this.ih=t,this.t("allowReshape",i,t))}get allowResize(){return this.eh}set allowResize(t){const i=this.eh;i!==t&&(U.i(t,"boolean",Diagram,"allowResize"),this.eh=t,this.t("allowResize",i,t))}get allowRotate(){return this.nh}set allowRotate(t){const i=this.nh;i!==t&&(U.i(t,"boolean",Diagram,"allowRotate"),this.nh=t,this.t("allowRotate",i,t))}get allowSelect(){return this.oh}set allowSelect(t){const i=this.oh;i!==t&&(U.i(t,"boolean",Diagram,"allowSelect"),this.oh=t,this.t("allowSelect",i,t))}get allowUndo(){return this.q1}set allowUndo(t){const i=this.q1;i!==t&&(U.i(t,"boolean",Diagram,"allowUndo"),this.q1=t,this.t("allowUndo",i,t))}get allowZoom(){return this.H1}set allowZoom(t){const i=this.H1;i!==t&&(U.i(t,"boolean",Diagram,"allowZoom"),this.H1=t,this.t("allowZoom",i,t))}get hasVerticalScrollbar(){return this.od}set hasVerticalScrollbar(t){const i=this.od;i!==t&&(U.i(t,"boolean",Diagram,"hasVerticalScrollbar"),this.od=t,this.Da(),this.L(),this.t("hasVerticalScrollbar",i,t),this._s(!1))}get hasHorizontalScrollbar(){return this.nd}set hasHorizontalScrollbar(t){const i=this.nd;i!==t&&(U.i(t,"boolean",Diagram,"hasHorizontalScrollbar"),this.nd=t,this.Da(),this.L(),this.t("hasHorizontalScrollbar",i,t),this._s(!1))}get allowHorizontalScroll(){return this.v1}set allowHorizontalScroll(t){const i=this.v1;i!==t&&(U.i(t,"boolean",Diagram,"allowHorizontalScroll"),this.v1=t,this.t("allowHorizontalScroll",i,t),this._s(!1))}get allowVerticalScroll(){return this.W1}set allowVerticalScroll(t){const i=this.W1;i!==t&&(U.i(t,"boolean",Diagram,"allowVerticalScroll"),this.W1=t,this.t("allowVerticalScroll",i,t),this._s(!1))}get scrollHorizontalLineChange(){return this.j1}set scrollHorizontalLineChange(t){const i=this.j1;i!==t&&(U.i(t,"number",Diagram,"scrollHorizontalLineChange"),t<0&&U.G(t,">= 0",Diagram,"scrollHorizontalLineChange"),this.j1=t,this.t("scrollHorizontalLineChange",i,t))}get scrollVerticalLineChange(){return this.J1}set scrollVerticalLineChange(t){const i=this.J1;i!==t&&(U.i(t,"number",Diagram,"scrollVerticalLineChange"),t<0&&U.G(t,">= 0",Diagram,"scrollVerticalLineChange"),this.J1=t,this.t("scrollVerticalLineChange",i,t))}get lastInput(){return this.xa}set lastInput(t){Debug&&U.s(t,InputEvent,Diagram,"lastInput"),this.xa=t}get previousInput(){return this._r}set previousInput(t){Debug&&U.s(t,InputEvent,Diagram,"previousInput"),this._r=t}get firstInput(){return this.y0}set firstInput(t){Debug&&U.s(t,InputEvent,Diagram,"firstInput"),this.y0=t}get currentCursor(){return this.O1}set currentCursor(t){if(t===""&&(t=this.c0),this.O1!==t){U.i(t,"string",Diagram,"currentCursor");const e=this.ut,s=this.Dt;if(e===null||s===null)return;this.O1=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.c0}set defaultCursor(t){t===""&&(t="auto");const i=this.c0;i!==t&&(U.i(t,"string",Diagram,"defaultCursor"),this.c0=t,this.t("defaultCursor",i,t))}get click(){return this.Kr}set click(t){const i=this.Kr;i!==t&&(t!==null&&U.C(t,Diagram,"click"),this.Kr=t,this.t("click",i,t))}get doubleClick(){return this.Ur}set doubleClick(t){const i=this.Ur;i!==t&&(t!==null&&U.C(t,Diagram,"doubleClick"),this.Ur=t,this.t("doubleClick",i,t))}get contextClick(){return this.Gr}set contextClick(t){const i=this.Gr;i!==t&&(t!==null&&U.C(t,Diagram,"contextClick"),this.Gr=t,this.t("contextClick",i,t))}get mouseOver(){return this.qr}set mouseOver(t){const i=this.qr;i!==t&&(t!==null&&U.C(t,Diagram,"mouseOver"),this.qr=t,this.t("mouseOver",i,t))}get mouseHover(){return this.Hr}set mouseHover(t){const i=this.Hr;i!==t&&(t!==null&&U.C(t,Diagram,"mouseHover"),this.Hr=t,this.t("mouseHover",i,t))}get mouseHold(){return this.vr}set mouseHold(t){const i=this.vr;i!==t&&(t!==null&&U.C(t,Diagram,"mouseHold"),this.vr=t,this.t("mouseHold",i,t))}get mouseDragOver(){return this.E1}set mouseDragOver(t){const i=this.E1;i!==t&&(t!==null&&U.C(t,Diagram,"mouseDragOver"),this.E1=t,this.t("mouseDragOver",i,t))}get mouseDrop(){return this.Wr}set mouseDrop(t){const i=this.Wr;i!==t&&(Debug&&t!==null&&U.C(t,Diagram,"mouseDrop"),this.Wr=t,this.t("mouseDrop",i,t))}get handlesDragDropForTopLevelParts(){return this.B1}set handlesDragDropForTopLevelParts(t){const i=this.B1;i!==t&&(U.i(t,"boolean",Diagram,"handlesDragDropForTopLevelParts"),this.B1=t,this.t("handlesDragDropForTopLevelParts",i,t))}get mouseEnter(){return this.jr}set mouseEnter(t){const i=this.jr;i!==t&&(t!==null&&U.C(t,Diagram,"mouseEnter"),this.jr=t,this.t("mouseEnter",i,t))}get mouseLeave(){return this.Jr}set mouseLeave(t){const i=this.Jr;i!==t&&(t!==null&&U.C(t,Diagram,"mouseLeave"),this.Jr=t,this.t("mouseLeave",i,t))}get toolTip(){return this.$r}set toolTip(t){const i=this.$r;i!==t&&(Debug&&t!==null&&!(t instanceof Adornment||t instanceof HTMLInfo)&&U.n("Diagram.toolTip must be an Adornment or HTMLInfo."),this.$r=t,this.t("toolTip",i,t))}get contextMenu(){return this.Zr}set contextMenu(t){const i=this.Zr;i!==t&&(Debug&&!(t instanceof Adornment||t instanceof HTMLInfo)&&U.n("Diagram.contextMenu must be an Adornment or HTMLInfo."),this.Zr=t,this.t("contextMenu",i,t))}get commandHandler(){return this._M}set commandHandler(t){const i=this._M;i!==t&&(U.s(t,CommandHandler,Diagram,"commandHandler"),i&&i.doStop(),this._M=t,t.Yo(this),t.doStart())}get toolManager(){return this.$M}set toolManager(t){this.$M!==t&&(U.s(t,ToolManager,Diagram,"toolManager"),this.$M=t,t.diagram=this)}get defaultTool(){return this.ZM}set defaultTool(t){const i=this.ZM;i!==t&&(U.s(t,Tool,Diagram,"defaultTool"),this.ZM=t,t.diagram=this,this.currentTool===i&&(this.currentTool=t))}get currentTool(){return this.QM}set currentTool(t){const i=this.QM;i&&(i.isActive&&i.doDeactivate(),i.cancelWaitAfter(),i.doStop()),t===null&&(t=this.defaultTool),t!==null&&(U.s(t,Tool,Diagram,"currentTool"),this.QM=t,t.diagram=this,t.doStart())}get selection(){return this.$T}get maxSelectionCount(){return this._1}set maxSelectionCount(t){const i=this._1;if(i!==t)if(U.i(t,"number",Diagram,"maxSelectionCount"),t>=0&&!isNaN(t)){if(this._1=t,this.t("maxSelectionCount",i,t),!this.undoManager.isUndoingRedoing){const e=this.selection.count-t;if(e>0){this.F("ChangingSelection",this.selection);const s=this.selection.toArray();for(let n=0;n= 0",Diagram,"maxSelectionCount")}get nodeSelectionAdornmentTemplate(){return this.m0}set nodeSelectionAdornmentTemplate(t){const i=this.m0;i!==t&&(U.s(t,Adornment,Diagram,"nodeSelectionAdornmentTemplate"),this.m0=t.Yt(),this.t("nodeSelectionAdornmentTemplate",i,t))}get groupSelectionAdornmentTemplate(){return this.eb}set groupSelectionAdornmentTemplate(t){const i=this.eb;i!==t&&(U.s(t,Adornment,Diagram,"groupSelectionAdornmentTemplate"),this.eb=t.Yt(),this.t("groupSelectionAdornmentTemplate",i,t))}get linkSelectionAdornmentTemplate(){return this.sb}set linkSelectionAdornmentTemplate(t){const i=this.sb;i!==t&&(U.s(t,Adornment,Diagram,"linkSelectionAdornmentTemplate"),this.sb=t.Yt(),this.t("linkSelectionAdornmentTemplate",i,t))}get highlighteds(){return this.ZT}get isModified(){const t=this.undoManager;return t.isEnabled?t.currentTransaction!==null?!0:this.ad&&this.Js!==t.historyIndex:this.ad}set isModified(t){if(this.ad!==t){U.i(t,"boolean",Diagram,"isModified"),this.ad=t;const e=this.undoManager;!t&&e.isEnabled&&(this.Js=e.historyIndex),t||this.TL()}}TL(){const t=this.isModified;this.s2!==t&&(this.s2=t,this.F("Modified"))}get model(){return this.Di}set model(t){const i=this.Di;if(i!==t){U.s(t,Model,Diagram,"model"),this.currentTool.doCancel(),i&&i.undoManager!==t.undoManager&&i.undoManager.isInTransaction&&U.n("Do not replace a Diagram.model while a transaction is in progress.");const e=this.aL(!0);this.lo=!1,this.sd=!0,this.Js=-2,this.Or=!1;const s=this.$t;this.$t=!0,this.animationManager.vl("Model"),i&&(this.oo!==null&&this.oo.each(n=>i.removeChangedListener(n)),i.removeChangedListener(this.nc)),this.Di=t,this.partManager=this.RO(this.Di.type),this.initializePartManager(this.partManager);for(let n=0;nt.addChangedListener(n)),this.$t=s,this.invalidateDocumentBounds(),this.$t||this.L(),i&&t.undoManager.copyProperties(i.undoManager)}}get themeManager(){return this.k2}set themeManager(t){const i=this.k2;i!==t&&(U.s(t,ThemeManager,Model,"themeManager"),i&&i.removeDiagram(this),this.k2=t,t!==null&&t.addDiagram(this))}initializePartManager(t){}static P2(t,i){Diagram.iL.set(t,i)}static get licenseKey(){return Diagram.z2.last()}static set licenseKey(t){Diagram.z2.add(t.replace(/\s/g,""))}static get version(){return Diagram.OO}static z2=new List;static OO="3.1.5";RO(t){const i=Diagram.iL.get(t);return i!==null?new i:new PartManager}get H(){return this.i2}set H(t){this.i2=t}get g1(){return this.QT}EO(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.Is&&!this.lo&&(this.sc=!0,this.sd&&(this.Or=!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.F("ChangingSelection",this.selection)}else if(e==="StartedTransaction"){const s=this.animationManager;s.defaultAnimation.isAnimating&&!this.skipsUndoManager&&s.stopAnimation()}return}if(this.H){this.H=!1;try{if(t.modelChange===""&&i===1){(e==="FinishedUndo"||e==="FinishedRedo")&&(this.F("ChangedSelection",this.selection),this.Ri());const s=this.animationManager;e==="RolledBackTransaction"&&s.stopAnimation(),this.qT(),this.sc=!0,this.maybeUpdate(),(this.undoManager.transactionLevel===0||this.undoManager.transactionLevel===1)&&s.DM(),e==="CommittedTransaction"&&this.undoManager.isJustDiscarded&&(this.Js=Math.min(this.Js,this.undoManager.historyIndex-1)),(e==="CommittedTransaction"||e==="RolledBackTransaction")&&this.undoManager.Fx&&U.pn(()=>{this.isModified=!1},1);const n=t.isTransactionFinished;if(n&&(this.TL(),this.g1.clear(),this.animationManager.OR()),!this.V1&&n&&this.lastInput.targetDiagram){this.V1=!0;const o=this;U.pn(()=>{o.currentTool.standardMouseOver(),o.V1=!1},10)}}}finally{this.H=!0}}}get Se(){return this.t2}set Se(t){this.t2=t}get Xu(){return this.z1}set Xu(t){this.z1=t}wL(t){const i=t.O.h;for(const e of i)e instanceof Picture&&this.X2(e)}X2(t){const i=t.element;if(i===null||!root.HTMLImageElement||!(i instanceof HTMLImageElement)||(i.ds instanceof GSet&&i.ds.add(this),t.BO(),!i.E0))return;const e=i.getAttribute("src")||"",s=this.ch.get(e);if(s===null){Picture.LL(t,i);const n=[];n.push(t),this.ch.set(e,n)}else{for(let n=0;n0)&&U.n("defaultScale must be larger than zero, not: "+t),this.w0=t}get autoScale(){return this.hh}set autoScale(t){const i=this.hh;i!==t&&(U.W(t,AutoScale,"AutoScale"),this.hh=t,this.t("autoScale",i,t),t!==1&&this._s(!1))}get initialAutoScale(){return this.zr}set initialAutoScale(t){const i=this.zr;i!==t&&(U.W(t,AutoScale,"AutoScale"),this.zr=t,this.t("initialAutoScale",i,t))}get initialViewportSpot(){return this.D1}set initialViewportSpot(t){const i=this.D1;i!==t&&(U.s(t,Spot,Diagram,"initialViewportSpot"),t.isSpot()||U.n("initialViewportSpot must be a specific Spot: "+t),this.D1=t,this.t("initialViewportSpot",i,t))}get initialDocumentSpot(){return this.L1}set initialDocumentSpot(t){const i=this.L1;i!==t&&(U.s(t,Spot,Diagram,"initialDocumentSpot"),t.isSpot()||U.n("initialViewportSpot must be a specific Spot: "+t),this.L1=t,this.t("initialDocumentSpot",i,t))}get minScale(){return this.k1}set minScale(t){U.r(t,Diagram,"minScale");const i=this.k1;i!==t&&(t>0?(this.k1=t,this.t("minScale",i,t),t>this.scale&&(this.scale=t)):U.G(t,"> 0",Diagram,"minScale"))}get maxScale(){return this.P1}set maxScale(t){U.r(t,Diagram,"maxScale");const i=this.P1;i!==t&&(t>0?(this.P1=t,this.t("maxScale",i,t),t 0",Diagram,"maxScale"))}get zoomPoint(){return this.M1}set zoomPoint(t){this.M1.equals(t)||(U.s(t,Point,Diagram,"zoomPoint"),t=t.T(),this.M1=t)}get contentAlignment(){return this.ic}set contentAlignment(t){const i=this.ic;i.equals(t)||(U.s(t,Spot,Diagram,"contentAlignment"),t=t.T(),this.ic=t,this.t("contentAlignment",i,t),this._s(!1))}get initialContentAlignment(){return this.h0}set initialContentAlignment(t){const i=this.h0;i.equals(t)||(U.s(t,Spot,Diagram,"initialContentAlignment"),t=t.T(),this.h0=t,this.t("initialContentAlignment",i,t))}get padding(){return this.si}set padding(t){typeof t=="number"?t=new Margin(t):U.s(t,Margin,Diagram,"padding");const i=this.si;i.equals(t)||(t=t.T(),this.si=t,this.invalidateDocumentBounds(),this.t("padding",i,t))}get partManager(){return this.c2}set partManager(t){const i=this.c2;i!==t&&(U.s(t,PartManager,Diagram,"partManager"),t.diagram!==null&&U.n("Cannot share PartManagers between Diagrams: "+t.toString()),i&&i.Yo(null),this.c2=t,t.Yo(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.il.iterator}get routers(){return this.fc}doLinkRouting(t){this.Uo=!0;const i=this.fc.h;for(let e=0;e0){const l=this.computePartsBounds(n.memberParts,!1);l.inflate(20,20),s.Sb(l)}const o=Rect.a(),r=n.memberParts;for(;r.next();){const l=r.value;l instanceof Node&&this.H2(l,e,o)}Rect.o(o)}s.Ra=n,s.U2=e,s.jo=!1}else t&&s.EL();return s}get avoidanceCellSize(){return this.l2}set avoidanceCellSize(t){this.ah=null,this.l2=new Size(Math.max(1,t.width),Math.max(1,t.height))}get avoidanceLimit(){return this.h2}set avoidanceLimit(t){this.h2=Math.max(1,t)}OL(t){return t.canAvoid()?t:t.containingGroup!==null?this.OL(t.containingGroup):null}H2(t,i,e){if(t===i||!t.isVisible())return;const s=t.canAvoid();if(s){const n=t.getAvoidableRect(e);this.ah.XO(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.H2(o,i,e)}}}yd(t){this.ah!==null&&!this.ah.jo&&(t===void 0||t.canAvoid())&&(this.ah.jo=!0)}get autoScrollInterval(){return this.a0}set autoScrollInterval(t){const i=this.a0;U.r(t,Diagram,"autoScrollInterval"),i!==t&&(this.a0=t,this.t("autoScrollInterval",i,t))}get autoScrollRegion(){return this.f0}set autoScrollRegion(t){typeof t=="number"?t=new Margin(t):U.s(t,Margin,Diagram,"autoScrollRegion");const i=this.f0;i.equals(t)||(t=t.T(),this.f0=t,this.invalidateDocumentBounds(),this.t("autoScrollRegion",i,t))}doAutoScroll(t){this.p0.c(t);const i=Point.a();this.computeAutoScrollPosition(this.p0,i).equalsApprox(this.position)?this.stopAutoScroll():this.BL(),Point.o(i)}BL(){if(this.ec!==-1)return;const t=this.a0,i=this;this.ec=U.pn(()=>{if(i.ec===-1||(i.stopAutoScroll(),i.lastInput.event===null))return;const s=Point.a(),n=i.computeAutoScrollPosition(i.p0,s);if(!n.equalsApprox(i.position)){i.position=n,i.lastInput.documentPoint=i.transformViewToDoc(i.p0),i.doMouseMove(),i.ba=!0;const o=Rect.a();i.computeBounds(o),o.unionRect(i.documentBounds),i.DL(o),Rect.o(o),i.$e=!0,i.maybeUpdate(),i.BL()}Point.o(s)},t)}stopAutoScroll(){this.ec!==-1&&(U.Nf(this.ec),this.ec=-1)}computeAutoScrollPosition(t,i){let e=this.position;i===void 0&&(i=new Point),i.c(e);const s=this.f0;if(s.top<=0&&s.left<=0&&s.right<=0&&s.bottom<=0)return i;const n=this.viewportBounds,o=this.scale,r=Rect.U(0,0,n.width*o,n.height*o),l=Point.U(0,0);if(t.x>=r.x&&t.xr.x+r.width-s.right&&this.allowHorizontalScroll){let h=Math.max(this.scrollHorizontalLineChange,1);h=h|0,l.x+=h,t.x>r.x+r.width-s.right/2&&(l.x+=h),t.x>r.x+r.width-s.right/4&&(l.x+=4*h)}if(t.y>=r.y&&t.yr.y+r.height-s.bottom&&this.allowVerticalScroll){let h=Math.max(this.scrollVerticalLineChange,1);h=h|0,l.y+=h,t.y>r.y+r.height-s.bottom/2&&(l.y+=h),t.y>r.y+r.height-s.bottom/4&&(l.y+=4*h)}return l.equalsApprox(Point.yn)||(i.x=e.x+l.x/o,i.y=e.y+l.y/o),Rect.o(r),Point.o(l),i}makeSvg(t){this.Ho.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.VL(n,"SVG",i),l=r!==null?r.svg:null,h=n.svgFinished;return l&&h&&h(l),U.ht(o)?(o(l),null):l}return this.zL(s,t)}makeSVG(t){return this.makeSvg(t)}addRenderer(t,i){this.Ho.set(t,i)}removeRenderer(t){this.Ho.delete(t)}cacheGroupExternalLinks(t){this.S2=t,t||this.nodes.each(i=>{i instanceof Group&&(i.V0=null)})}zL(t,i){const e=i.callback;let s=!0;const o=this.ch.iterator;for(;o.next();)if(!o.value[0].Tn){s=!1;break}if(!U.ht(e)||s)return t(i,e,this);const r=this;function l(){const f=+new Date;for(s=!0,o.reset();o.next();)if(!o.value[0].Tn){s=!1;break}if(s||f-a>h){t(i,e,r);return}root.requestAnimationFrame(l)}const h=i.callbackTimeout||300,a=+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.zL(this.YO,t)}static img="image";YO(t,i,e){const s=e.VL(t,"canvas",null);if(s===null)return null;const n=s.B.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 a=n;return U.ht(i)||(o="",U.n('Error: Diagram.makeImageData called with "returnType: toBlob", but no required "callback" function property defined.')),U.ht(a.toBlob)?(a.toBlob(i,t.type,t.details),"toBlob"):(i(null),null)}case"string":default:o=n.toDataURL(t.type,t.details)}}return U.ht(i)?(i(o),null):o}static XL=!1;VL(t,i,e){this.animationManager.stopAnimation(),this.maybeUpdate(),U.it(t)||U.n("properties argument must be an Object.");let s=!1,n=t.size||null,o=t.scale||null;t.scale!==void 0&&isNaN(t.scale)&&(o="NaN");let r=t.maxSize;t.maxSize===void 0&&(s=!0,i==="SVG"?r=new Size(1/0,1/0):r=new Size(2e3,2e3));const l=t.position||null;let h=t.parts||null;Array.isArray(h)&&(h=new List(h));let a=t.padding===void 0?1:t.padding;const f=t.background||null;let c=t.omitTemporary;c===void 0&&(c=!0);const u=t.document||root.document,d=t.elementFinished||null;let m=t.showTemporary;m===void 0&&(m=!c);let g=t.showGrid;g===void 0&&(g=m),n!==null&&isNaN(n.width)&&isNaN(n.height)&&(n=null),typeof a=="number"?a=new Margin(a):a instanceof Margin||U.n("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._t&&this._t.clearContextCache(!0);const p=new CanvasSurface(null,u,void 0,!0),y=p.ni;if(!(n||o||h||l))return p.width=this.Pt+Math.ceil(a.left+a.right),p.height=this.Mt+Math.ceil(a.top+a.bottom),i==="SVG"?e===null?null:(e.resize(p.width,p.height,p.width,p.height),e.ol=u,e.wd=d,this.yb(e.ni,a,new Size(p.width,p.height),this.lt,this.yt,h,f,m,g),e.ni):(this.fd=!1,this.yb(y,a,new Size(p.width,p.height),this.lt,this.yt,h,f,m,g),this.fd=!0,p.ni);const x=this.w0,b=this.documentBounds.copy();if(b.subtractMargin(this.si),m){const T=this.Gt.h,L=T.length;for(let D=0;Dx?(o=x,M=b.width,N=b.height):(M=r.width,N=r.height)):(M=b.width*o,N=b.height*o):(o=x,M=b.width,N=b.height),a!==null?(M+=k,N+=P):a=new Margin(0),r!==null){let T=r.width,L=r.height;i!=="SVG"&&s&&!Diagram.XL&&Debug&&(M>T||N>L)&&(U.ot("Diagram.makeImage(data): Diagram width or height is larger than the default max size. ("+Math.ceil(M)+"x"+Math.ceil(N)+" vs 2000x2000) Consider increasing the max size."),Diagram.XL=!0),isNaN(T)&&(T=2e3),isNaN(L)&&(L=2e3),isFinite(T)&&(M=Math.min(M,T)),isFinite(L)&&(N=Math.min(N,L))}return p.width=Math.ceil(M),p.height=Math.ceil(N),i==="SVG"?e===null?null:(e.resize(p.width,p.height,p.width,p.height),e.ol=u,e.wd=d,this.yb(e.ni,a,new Size(Math.ceil(M),Math.ceil(N)),o,S,h,f,m,g),e.ni):(this.fd=!1,this.yb(y,a,new Size(Math.ceil(M),Math.ceil(N)),o,S,h,f,m,g),this.fd=!0,p.ni)}static La=null;static v2="5da73c80a36555d5038e4972187c3cae51fd22";static KO="5da73c80a36555d503aa5c72106c30b35bb2006b9cd041b259";static Qw=!1;static Kk=()=>{if(Diagram.v2[5]===void 0&&(Transform.prototype.De=Transform.prototype.Tu),!Diagram.isUsingDOM())return;const t=U.Le("canvas");t.width=350;const i=t.getContext("2d"),e=U.Qi("7ca11abfd022028846"),s="7ca11abfd7330390",n=[Diagram.v2,U.Qw+"4ae6247590da4bb21c324ba3a84e385776",Transform.Kk+"fb236cdfda5de14c134ba1a95a2d4c7cc6f93c1387",G.za];i.scale(2,2);const o=8;for(let r=1;r<5;r++)i[U.Qi(s)](U.Qi(n[r-1]),o,r*15);i[e]=U.Qi("39f046ebb36e4b");for(let r=1;r<5;r++)i[U.Qi(s)](U.Qi(n[r-1]),o,r*15);(n.length!==4||n[0][0]!=="5"||n[3][0]!=="7")&&(Transform.prototype.De=Transform.prototype.Tu),Diagram.La=t};static UO=()=>{if(Diagram.v2[5]===void 0&&(Transform.prototype.De=Transform.prototype.Tu),!Diagram.isUsingDOM())return;const t=U.Le("canvas"),i=t.getContext("2d"),e=U.Qi("7ca11abfd022028846"),s="7ca11abfd7330390",n=[Diagram.KO,G.za],o=5;i.scale(2,2);for(let r=1;r<3;r++)i[U.Qi(s)](U.Qi(n[r-1]),o,r*11);i[e]=U.Qi("39f046ebb36e4b");for(let r=1;r<3;r++)i[U.Qi(s)](U.Qi(n[r-1]),o,r*11);(n.length!==2||n[0][0]!=="5")&&(Transform.prototype.De=Transform.prototype.Tu),Diagram.La=t}}class DiagramHelper{YL;KL;W2;Pe;constructor(t){if(this.YL=null,this.KL="63ad05bbe23a1786468a4c741b6d2",this.W2="@onz",this.KL===this._tk){this.W2=!0,this.Pe=this.W2;return}this.Pe=null}GO(t,i){let e="f";const s=root[U.Qi("76a715b2f73f148a")][U.Qi("72ba13b5")]||"",n=U.Qi;if(this.Pe=!0,!Diagram.isUsingDOM())return;let o=Diagram[n("76a115b6ed251eaf4692")];if(!o){const l=s[n("76ad18b4f73e")];for(let a=s[n("73a612b6fb191d")](n("35e7"))+2;a=0&&hf[0]||a[0]===f[0]&&a[1]>=f[1]))continue;const c="73a612b6fb191d",u=root[n("74a900bae4370f8b51")][n("6fbb13a1c2311e8a57")].toLowerCase(),d=u[n(c)](n("3aad1ab6e022098b4dc4")),m=n(l[2+h]);if(d>-1){const M=u[n(c)](m.toLowerCase()+"/");if(this.Pe=!(M>-1&&M=0&&p-1),!this.Pe))return;const y=root[U.Qi("76a715b2f73f148a")][U.Qi("69ad17a1e03e")],x=y[n(c)](n("7fb002b6ed25128b4da25b2e"));if(x>-1&&(this.Pe=!(y[n(c)](m)>x),!this.Pe))return;const b=m;if(b[0]!=="#")continue;const S=U.Le("div");let k=l[0+h].replace(/[A-Za-z]/g,"");for(;k.length<4;)k+="9";const P=k;k=k.substring(k.length-4);const A=parseInt(f[0]),C=parseInt(f[1]);if(A>3||A===3&&C>=1){const M=parseInt(P)%40+30,N=parseInt(b.substring(1,5),16);if(Link.UL===M+N){this.Pe=!1;return}}else{let M="";const N=["gsh","gsf"],T=["Header","Background","Display","Feedback"];if(M+=N[parseInt(k.substring(0,1),10)%2],M+=T[parseInt(k.substring(0,1),10)%4],S[n("79a417a0f0181a8946")]=M,root.document[n("78a712aa")]){root.document[n("78a712aa")][n("7bb806b6ed32388c4a875b")](S);const L=root.getComputedStyle(S).getPropertyValue(n("78a704b7e62456904c9b12701b6532a8")),D=root.getComputedStyle(S).getPropertyValue(n("75b817b0ea2202"));if(root.document[n("78a712aa")][n("68ad1bbcf533388c4a875b")](S),!L)continue;const F=root[n("77a902b0eb1b1e804a8a")],R="0."+parseInt(P,10)%100;if(D===R||L.indexOf(parseInt(b[1]+b[2],16).toString())!==-1&&L.indexOf(parseInt(b[3]+b[4],16).toString())!==-1){this.Pe=!1;return}else if(F&&F(n("32ae19a1e0331fc94084537c067a67fa59f1386b89d006")).matches){M="."+M;for(let I=0;I{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.$2=s=>{this.invalidateDocumentBounds(),this.X0()},this.Z2=s=>{this.observed!==null&&(this.invalidateDocumentBounds(),this.L())},this.Cb=s=>{this.updateDelay<1?this.L():this.z0||(this.z0=!0,U.pn(()=>this.redraw(),this.updateDelay))},this.Q2=s=>{this.observed!==null&&this.X0()},this.autoScale=2,this.$t=!1,i&&this.setProperties(i),this}setupRouters(){}computePixelRatio(){return 1}redraw(){this.z0&&this.updateDelay>=1&&(this.z0=!1,this.qO()),super.redraw()}vi(){if(this.Dt===null&&U.n("No div specified"),this.ut===null&&U.n("No canvas specified"),this.ut instanceof SVGSurface||(this.box.HM(),!this.$e))return;const t=this.observed;if(t===null||t.animationManager.defaultAnimation.isAnimating||!t.oa)return;this.I0();const i=this.ut,e=this._t;if(e.clearContextCache(!0),e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,i.width,i.height),this.updateDelay<1)this.qL();else if(this.mc!==null){e.drawImage(this.mc.Nt,0,0);const o=this.E;e.scale(this.te,this.te),e.transform(o.m11,o.m12,o.m21,o.m22,o.dx,o.dy),e.commitTransform()}const s=this.Gt.h,n=s.length;for(let o=0;oi.isSelected?"darkcyan":"lime"),new Shape({name:"SHAPE2",stretch:2,fill:null,stroke:"magenta",strokeWidth:4,strokeDashArray:[4,4]})),new Placeholder({padding:4})),this.uN=null,this.Rb="",this.dN="",this.Ob=U.yr,this.gN=!1,this.mN=!1,this.xd=new Part({layerName:"Tool",isInDocumentBounds:!1,locationObjectName:"CIRCLE",locationSpot:Spot.Center,pickable:!1,selectable:!1}).add(new Shape("Circle",{isGeometryPositioned:!0,width:30,height:30,fill:null,stroke:"darkcyan",strokeWidth:6,visible:!1}).bind("visible","down"),new Shape({isGeometryPositioned:!0,geometryString:"M15 0L15 30",stroke:"magenta"}),new Shape({isGeometryPositioned:!0,geometryString:"M0 15L30 15",stroke:"magenta"}),new Shape("Circle",{name:"CIRCLE",isGeometryPositioned:!0,width:20,height:20,fill:null,stroke:"magenta",position:new Point(5,5)}),new Shape({isGeometryPositioned:!0,geometry:CommandHandler.HL,fill:null,stroke:"cyan",strokeWidth:4}).bind("geometry","button",CommandHandler.JO),new TextBlock({position:new Point(12,0),font:"bold 10pt sans-serif"}).bind("text","clickCount",i=>i>1?i.toString():""),new TextBlock({position:new Point(0,16)}).bind("text","modifiers",CommandHandler.$O)).freezeBindings(),this.K0=10,this.U0=1,this.pN=null,this.nc=i=>this.ZO(i),this.yN=i=>this.QO(i),this.wN=i=>this._O(i),this.xN=i=>this.tE(i),this.bN=null,this.SN="distance",this.bd=null,this.kN=0,this.ze={},this.Cs=null,this.Eb=!1,this.G0=null,this.MN(),this.xd.data=this.ze,t&&Object.assign(this,t)}toString(){return"CommandHandler"}get diagram(){return this.f}Yo(t){this.f=t}doStart(){const t=this.f;t&&(t.addModelChangedListener(this.nc),t.addDiagramListener("ViewportBoundsChanged",this.yN),t.addDiagramListener("GainedFocus",this.wN),t.addDiagramListener("LostFocus",this.xN))}doStop(){const t=this.f;t&&(t.removeDiagramListener("ViewportBoundsChanged",this.yN),t.removeDiagramListener("GainedFocus",this.wN),t.removeDiagramListener("LostFocus",this.xN),t.removeModelChangedListener(this.nc))}doKeyDown(){const t=this.f,i=t.lastInput,e=i.control||i.meta,s=i.shift,n=i.alt,o=i.commandKey;e&&(o==="Insert"||o==="c")?this.canCopySelection()&&this.copySelection():e&&o==="x"||s&&o==="Delete"?this.canCutSelection()&&this.cutSelection():e&&o==="v"||s&&o==="Insert"?this.canPasteSelection()&&this.pasteSelection():e&&o==="y"||e&&s&&o==="z"||n&&s&&o==="Backspace"?this.canRedo()&&this.redo():e&&o==="z"||n&&o==="Backspace"?this.canUndo()&&this.undo():o==="Delete"||o==="Backspace"?this.canDeleteSelection()&&this.deleteSelection():e&&o==="a"?this.canSelectAll()&&this.selectAll():o==="Escape"?this.canStopCommand()&&this.stopCommand():this.vL.indexOf(o)>=0?this.iE(o,e,s):o==="PageUp"?s&&t.allowHorizontalScroll?t.scroll("page","left"):t.allowVerticalScroll&&t.scroll("page","up"):o==="PageDown"?s&&t.allowHorizontalScroll?t.scroll("page","right"):t.allowVerticalScroll&&t.scroll("page","down"):o==="Home"?e&&t.allowVerticalScroll?t.scroll("document","up"):!e&&t.allowHorizontalScroll&&t.scroll("document","left"):o==="End"?e&&t.allowVerticalScroll?t.scroll("document","down"):!e&&t.allowHorizontalScroll&&t.scroll("document","right"):o==="Space"?this.canScrollToPart()&&this.scrollToPart():o==="Minus"||o==="NumpadSubtract"?this.canDecreaseZoom()&&this.decreaseZoom():o==="Equal"||o==="NumpadAdd"?this.canIncreaseZoom()&&this.increaseZoom():e&&o==="Digit0"?this.canResetZoom()&&this.resetZoom():s&&o==="z"?this.canZoomToFit()&&this.zoomToFit():e&&!s&&o==="g"?this.canGroupSelection()&&this.groupSelection():e&&s&&o==="g"?this.canUngroupSelection()&&this.ungroupSelection():o==="F2"?this.canEditTextBlock()&&this.editTextBlock():o==="ContextMenu"||s&&o==="F10"||e&&s&&o==="Backslash"?this.canShowContextMenu()&&this.showContextMenu():i.bubbles=!0}doKeyUp(){const i=this.f.lastInput;i.bubbles=!0}stopCommand(){const t=this.f,i=t.currentTool;if(i instanceof ToolManager){if(i.currentToolTip!==null){i.hideToolTip();return}t.allowSelect&&t.clearSelection()}i!==null&&i.doCancel()}canStopCommand(){return!0}selectAll(){const t=this.f;t.L();try{t.currentCursor="wait",t.F("ChangingSelection",t.selection);const i=t.parts;for(;i.next();){const n=i.value;n.canSelect()&&!n.layer.isTemporary&&(n.isSelected=!0)}const e=t.nodes;for(;e.next();){const n=e.value;n.canSelect()&&!n.layer.isTemporary&&(n.isSelected=!0)}const s=t.links;for(;s.next();){const n=s.value;n.canSelect()&&!n.layer.isTemporary&&(n.isSelected=!0)}}finally{t.F("ChangedSelection",t.selection),t.currentCursor=""}}canSelectAll(){return this.f.allowSelect}deleteSelection(){const t=this.f;try{t.currentCursor="wait",t.F("ChangingSelection",t.selection),t.startTransaction("Delete"),t.F("SelectionDeleting",t.selection);const i=new GSet,e=t.selection.iterator;for(;e.next();){const s=e.value;Part.bh(i,s,!0,this.deletesTree?1/0:0,this.deletesConnectedLinks?null:!1,n=>n.canDelete())}t.removeParts(i,!0),t.F("SelectionDeleted",i)}finally{t.commitTransaction("Delete"),t.F("ChangedSelection",t.selection),t.currentCursor=""}}canDeleteSelection(){const t=this.f;return!(t.isReadOnly||t.isModelReadOnly||!t.allowDelete||t.selection.count===0)}copySelection(){const t=this.f;try{const i=new GSet,e=t.selection.iterator;for(;e.next();){const s=e.value;Part.bh(i,s,!0,this.copiesTree?1/0:0,this.copiesConnectedLinks,n=>n.canCopy())}this.copyToClipboard(i)}finally{}}canCopySelection(){const t=this.f;return!(!t.allowCopy||!t.allowClipboard||t.selection.count===0)}cutSelection(){this.copySelection(),this.deleteSelection()}canCutSelection(){const t=this.f;return!(t.isReadOnly||t.isModelReadOnly||!t.allowCopy||!t.allowDelete||!t.allowClipboard||t.selection.count===0)}copyToClipboard(t){const i=this.f,e=this.storageLocation==="systemClipboard";if(e||this.storageLocation!=="memory")try{if(t===null)if(e&&root.navigator.clipboard)root.navigator.clipboard.writeText("");else{const n=root[this.storageLocation];if(!n)return;n.setItem(this.Ab,""),n.setItem(this.Tb,"")}else{const n=new Diagram;if(n.isTreePathToChildren=i.isTreePathToChildren,n.toolManager.draggingTool.dragsLink=i.toolManager.draggingTool.dragsLink,n.model=i.model.copy(),i.copyParts(t,n,!1),e&&root.navigator.clipboard)root.navigator.clipboard.writeText(n.model.toJson());else{const o=root[this.storageLocation];if(!o)return;o.setItem(this.Ab,n.model.toJson()),o.setItem(this.Tb,n.model.dataFormat)}}i.F("ClipboardChanged",t);return}catch{return}let s=null;if(t===null)Diagram.hL();else{let n=null;try{n=i.copyParts(t,null,!0)}finally{s=new List,n!==null&&s.addAll(n.iteratorValues),Diagram.T0=s,Diagram.db=i.model.dataFormat}}i.F("ClipboardChanged",s)}pasteFromClipboard(){const t=this.f;if(this.storageLocation!=="memory"){const n=new GSet;try{const o=root[this.storageLocation];if(!o)return n;const r=o.getItem(this.Ab),l=o.getItem(this.Tb);if(r===null||r===""||l!==t.model.dataFormat)return n;{const h=new Diagram;h.model=Model.fromJson(r);const a=new GSet;a.addAll(h.parts).addAll(h.nodes).addAll(h.links);const f=t.copyParts(a,t,!1);return new GSet().addAll(f.iteratorValues)}}catch{return n}}const i=new GSet,e=Diagram.T0;if(e===null||Diagram.db!==t.model.dataFormat)return i;let s=null;try{s=t.copyParts(e,t,!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)),i.add(o)}}}return i}async pasteSelectionAsync(t){const i=this.f;if(root.navigator.clipboard===void 0){U.ot('Cannot paste with storageLocation "clipboard", window.isSecureContext may be false.');return}try{i.currentCursor="wait",i.F("ChangingSelection",i.selection),i.startTransaction("Paste");let e=null;const s=await root.navigator.clipboard.readText();try{const o=s;if(!(o===null||o==="")){const r=new Diagram;r.model=Model.fromJson(o);const l=new GSet;l.addAll(r.parts).addAll(r.nodes).addAll(r.links);const h=i.copyParts(l,i,!1);e=new GSet().addAll(h.iteratorValues)}}catch{}if(e===null)return;e.count>0&&i.clearSelection(!0);const n=e.iterator;for(;n.next();){const o=n.value;o.isSelected=!0}if(t){const o=i.computePartsBounds(i.selection);if(o.isReal()){const r=this.computeEffectiveCollection(i.selection,i.dd);i.Ex(r,new Point(t.x-o.centerX,t.y-o.centerY),i.dd,!1)}}i.F("ClipboardPasted",e)}finally{i.commitTransaction("Paste"),i.F("ChangedSelection",i.selection),i.currentCursor=""}}pasteSelection(t){if(this.storageLocation==="systemClipboard"){this.pasteSelectionAsync(t);return}const i=this.f;try{i.currentCursor="wait",i.F("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){const n=i.computePartsBounds(i.selection);if(n.isReal()){const o=this.computeEffectiveCollection(i.selection,i.dd);i.Ex(o,new Point(t.x-n.centerX,t.y-n.centerY),i.dd,!1)}}i.F("ClipboardPasted",e)}finally{i.commitTransaction("Paste"),i.F("ChangedSelection",i.selection),i.currentCursor=""}}canPasteSelection(t){const i=this.f;if(i.isReadOnly||i.isModelReadOnly||!i.allowInsert||!i.allowClipboard)return!1;if(this.storageLocation==="systemClipboard")return!0;if(this.storageLocation!=="memory")try{const e=root[this.storageLocation];if(!e)return!1;const s=e.getItem(this.Ab),n=e.getItem(this.Tb);return!(s===null||s===""||n!==i.model.dataFormat)}catch{return!1}return!(Diagram.T0===null||Diagram.T0.count===0||Diagram.db!==i.model.dataFormat)}undo(){this.f.undoManager.undo()}canUndo(){const t=this.f;return t.isReadOnly||t.isModelReadOnly?!1:t.allowUndo&&t.undoManager.canUndo()}redo(){this.f.undoManager.redo()}canRedo(){const t=this.f;return t.isReadOnly||t.isModelReadOnly?!1:t.allowUndo&&t.undoManager.canRedo()}decreaseZoom(t){t===void 0&&(t=1/this.zoomFactor),U.r(t,CommandHandler,"decreaseZoom:factor");const i=this.f;if(i.autoScale!==1)return;const e=i.scale*t;ei.maxScale||(i.scale=e)}canDecreaseZoom(t){t===void 0&&(t=1/this.zoomFactor),U.r(t,CommandHandler,"canDecreaseZoom:factor");const i=this.f;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),U.r(t,CommandHandler,"increaseZoom:factor");const i=this.f;if(i.autoScale!==1)return;const e=i.scale*t;ei.maxScale||(i.scale=e)}canIncreaseZoom(t){t===void 0&&(t=this.zoomFactor),U.r(t,CommandHandler,"canIncreaseZoom:factor");const i=this.f;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),U.r(t,CommandHandler,"resetZoom:newscale");const i=this.f;ti.maxScale||(i.scale=t)}canResetZoom(t){t===void 0&&(t=this.defaultScale),U.r(t,CommandHandler,"canResetZoom:newscale");const i=this.f;return ti.maxScale?!1:i.allowZoom}zoomToFit(t){const i=this.f,e=i.animationManager;e.stopAnimation(),i.redraw();const s=i.position.copy(),n=i.scale;if(e.vl("Zoom To Fit"),!t&&this.isZoomToFitRestoreEnabled&&n===this.Fb&&!isNaN(this.Lb)&&this.Db.isReal()&&i.documentBounds.equals(this.Ib))i.scale=this.Lb,i.position=this.Db,this.Fb=NaN,this.Ib=Rect.lm;else{if(this.Lb=n,this.Db=s,t){const o=t.copy();if(o.width>0&&o.height>0){const r=i.viewportBounds,l=r.width*n,h=r.height*n,a=Math.min(l/o.width,h/o.height),f=l/a,c=h/a;o.width0?this.Jo=i.highlighteds.iterator:i.selection.count>0&&(this.Jo=i.selection.iterator),this.Jo!==null&&this.Jo.next()&&(t=this.Jo.value))}if(t!==null){const e=i.animationManager;e.vl("Scroll To Part");const s=this.scrollToPartPause;if(s>0){const n=this.pc(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.pn(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()}}}pc(t,i){if(t.isVisible())return i;if(t instanceof Adornment){const e=t.adornedPart;e!==null&&this.pc(e,i)}else if(t instanceof Link){const e=t.fromNode;e!==null&&this.pc(e,i);const s=t.toNode;s!==null&&this.pc(s,i)}else{if(t instanceof Node){const s=t.labeledLink;s!==null&&this.pc(s,i);const n=t.findTreeParentNode();n!==null&&(!n.isTreeExpanded&&!n.wasTreeExpanded&&i.push(n),this.pc(n,i))}const e=t.containingGroup;e!==null&&(!e.isSubGraphExpanded&&!e.wasSubGraphExpanded&&i.push(e),this.pc(e,i))}return i}canScrollToPart(t){if(t===void 0&&(t=null),t!==null&&!(t instanceof Part))return!1;const i=this.f;return i.selection.count===0&&i.highlighteds.count===0?!1:i.allowHorizontalScroll&&i.allowVerticalScroll}collapseTree(t){t===void 0&&(t=null);const i=this.f,e="Collapse Tree";try{i.startTransaction(e),i.animationManager.vl(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.F("TreeCollapsed",n)}finally{i.commitTransaction(e)}}canCollapseTree(t){t===void 0&&(t=null);const i=this.f;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.f,e="Expand Tree";try{i.startTransaction(e),i.animationManager.vl(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.F("TreeExpanded",n)}finally{i.commitTransaction(e)}}canExpandTree(t){t===void 0&&(t=null);const i=this.f;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.f,i=t.model;if(!i.Oa())return;const e=this.archetypeGroupData;if(e===null)return;let s=null;try{t.currentCursor="wait",t.F("ChangingSelection",t.selection),t.startTransaction("Group");const n=new List,o=t.selection.iterator;for(;o.next();){const a=o.value;a.Oe()&&a.canGroup()&&n.add(a)}const r=new List,l=n.iterator;for(;l.next();){const a=l.value;let f=!1;const c=n.iterator;for(;c.next();){const u=c.value;if(a.isMemberOf(u)){f=!0;break}}f||r.add(a)}const h=r.first();if(h!==null){let a=h.containingGroup;if(a!==null)for(;a!==null;){let f=!1;const c=r.iterator;for(;c.next();)if(!c.value.isMemberOf(a)){f=!0;break}if(f)a=a.containingGroup;else break}if(e instanceof Group)e.Yt(),s=e.copy(),s!==null&&t.add(s);else if(i.isGroupForData(e)){const f=i.copyNodeData(e);i.addNodeData(f),s=t.findNodeForData(f)}if(s!==null){a!==null&&this.isValidMember(a,s)&&(s.containingGroup=a);const f=r.iterator;for(;f.next();){const c=f.value;this.isValidMember(s,c)&&(c.containingGroup=s)}t.clearSelection(!0),s.isSelected=!0}}t.F("SelectionGrouped",s)}finally{t.commitTransaction("Group"),t.F("ChangedSelection",t.selection),t.currentCursor=""}}canGroupSelection(){const t=this.f;if(t.isReadOnly||t.isModelReadOnly||!t.allowInsert||!t.allowGroup||!t.model.Oa()||this.archetypeGroupData===null)return!1;const e=t.selection.iterator;for(;e.next();){const s=e.value;if(s.Oe()&&s.canGroup())return!0}return!1}NN(t){const i=U.at();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 a=n.iterator;for(;a.next();){const f=a.value;if(f.isSelected=!0,f instanceof Link)continue;const c=f.data;c!==null?e.setGroupForData(c,h):f.containingGroup=l}i.remove(r)}}i.F("SelectionUngrouped",s,n)}finally{i.commitTransaction("Ungroup"),i.F("ChangedSelection",i.selection),i.currentCursor=""}}canUngroupSelection(t){t===void 0&&(t=null);const i=this.f;if(i.isReadOnly||i.isModelReadOnly||!i.allowDelete||!i.allowUngroup||!i.model.Oa())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.NN(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.f,e="Collapse SubGraph";try{i.startTransaction(e),i.animationManager.vl(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.F("SubGraphCollapsed",n)}finally{i.commitTransaction(e)}}canCollapseSubGraph(t){t===void 0&&(t=null);const i=this.f;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.f,e="Expand SubGraph",s=new List;try{if(i.startTransaction(e),i.animationManager.vl(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.F("SubGraphExpanded",s)}finally{for(const n of s)this.WL(i,n);t&&this.WL(i,t),i.commitTransaction(e)}}WL(t,i){for(const e of i.memberParts)e instanceof Node&&t.Jf(e,i)}canExpandSubGraph(t){t===void 0&&(t=null);const i=this.f;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),t!==null&&U.s(t,TextBlock,CommandHandler,"editTextBlock");const i=this.f,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.f;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.f,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;if(s instanceof GraphObject?o=s.getDocumentPoint(Spot.Center):i.viewportBounds.containsPoint(n.documentPoint)?o=Point.wn:o=i.viewportBounds.center,o.isReal()){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.f,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))}downloadSvg(t){const i=this.f,e={scale:1,background:i.div?i.div.style.backgroundColor:"white",name:this.eE("svg")};t&&Object.assign(e,t);const s=i.makeSvg(e);if(s!==null){const n=new XMLSerializer().serializeToString(s);this.sE(e.name,"image/svg+xml",n)}}downloadSVG(t){this.downloadSvg(t)}canDownloadSvg(t){return this.f!==null}sE(t,i,e){let s=null,n=null;try{const o=new Blob([e],{type:i});s=root.URL.createObjectURL(o),n=U.Le("a"),n.style.display="none",n.href=s,n.download=t,root.document.body.appendChild(n),requestAnimationFrame(()=>{try{n!==null&&n.click()}finally{s!==null&&root.URL.revokeObjectURL(s),n!==null&&root.document.body.removeChild(n)}})}catch{s!==null&&root.URL.revokeObjectURL(s),n!==null&&root.document.body.removeChild(n)}}eE(t){const i="."+t;let e=this.diagram.model.name;return e?e.endsWith(i)&&(e=e.substring(0,e.length-i.length)):e="diagram",e+=i,e}get copiesClipboardData(){return this._2}set copiesClipboardData(t){this._2=!!t}get copiesConnectedLinks(){return this.tN}set copiesConnectedLinks(t){this.tN=!!t}get deletesConnectedLinks(){return this.iN}set deletesConnectedLinks(t){this.iN=!!t}get copiesTree(){return this.eN}set copiesTree(t){this.eN=!!t}get deletesTree(){return this.sN}set deletesTree(t){this.sN=!!t}get copiesParentKey(){return this.nN}set copiesParentKey(t){this.nN=!!t}get copiesGroupKey(){return this.oN}set copiesGroupKey(t){this.oN=!!t}get storageLocation(){return this.rN}set storageLocation(t){t||(t="memory"),t!=="memory"&&t!=="sessionStorage"&&t!=="localStorage"&&t!=="systemClipboard"&&U.n("Invalid new value for CommandHandler.storageLocation: "+t),this.rN=t}get archetypeGroupData(){return this.lN}set archetypeGroupData(t){t!==null&&U.Ro(t,CommandHandler,"archetypeGroupData");const i=this.f;if(Debug&&t!==null&&i){const e=i.model;e.Oa()&&!(t instanceof Group)&&!e.isGroupForData(t)&&U.n("CommandHandler.archetypeGroupData must be either a Group or a data object for which GraphLinksModel.isGroupForNodeData is true: "+t)}this.lN=t}get memberValidation(){return this.xh}set memberValidation(t){t!==null&&U.C(t,CommandHandler,"memberValidation"),this.xh=t}get defaultScale(){return this.diagram.defaultScale}set defaultScale(t){this.diagram.defaultScale=t}get zoomFactor(){return this.hN}set zoomFactor(t){U.r(t,CommandHandler,"zoomFactor"),t>1||U.n("zoomFactor must be larger than 1.0, not: "+t),this.hN=t}get isZoomToFitRestoreEnabled(){return this.aN}set isZoomToFitRestoreEnabled(t){this.aN=!!t}get scrollToPartPause(){return this.fN}set scrollToPartPause(t){this.fN=t}computeEffectiveCollection(t,i){const e=this.f,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.nl(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 a=l.toNode;a!==null&&!o.has(a)&&o.delete(l)}}}return o}static getModifierNames(){return CommandHandler.Sd}static setModifierNames(t){CommandHandler.Sd=t}static $O(t){let i="";return t&1&&(i+=CommandHandler.Sd[0]||""),t&4&&(i+=CommandHandler.Sd[1]||""),t&2&&(i+=CommandHandler.Sd[2]||""),t&8&&(i+=CommandHandler.Sd[3]||""),i}static JO(t){return t===1?CommandHandler.WO:t===2?CommandHandler.jO:CommandHandler.HL}static PN(t,i,e){var s=new Point(e,0).rotate(t-i/2),n=new Geometry().add(new PathFigure(-e,-e)).add(new PathFigure(e,e)).add(new PathFigure(s.x,s.y).add(new PathSegment(5,t-i/2,i,0,0,e,e)));return n.offset(e,e),n}ZO(t){t.isTransactionFinished&&this.updateFocusBox()}QO(t){if(t.subject.scale===this.diagram.scale)return;const i=4/this.diagram.scale,e=this.focusBox.findObject("SHAPE");e!==null&&(e.strokeWidth=i);const s=this.focusBox.findObject("SHAPE2");s!==null&&(s.strokeWidth=i,s.strokeDashArray=[i,i]);const n=this.focusBox.placeholder;n!==null&&(n.padding=i)}_O(t){this.focus===null?U.pn(()=>{this.focus=this.findFirstFocus()},500):this.onFocusChanged(this.focus,this.focus)}tE(t){this.isVirtualPointerShown=!1}get isFocusEnabled(){return this.cN}set isFocusEnabled(t){t=!!t;const i=this.isFocusEnabled;t!==i&&(t||(this.isVirtualPointerShown=!1,this.bN=this.focus,this.focus=null),this.cN=t,t&&(this.focus=this.bN,this.updateFocusBox()))}get focusBox(){return this.Y0}set focusBox(t){if(!(t instanceof Adornment))return;const i=this.Y0;if(t!==i&&(this.Y0=t,i.adornedObject!==null)){const e=i.adornedPart;e!==null&&e.removeAdornment("Focus"),t.adornedObject=i.adornedObject,e!==null&&e.addAdornment("Focus",t)}}get focus(){return this.Y0.adornedObject}set focus(t){const i=this.focus;if(t!==i){const e=this.f;if(!e||!this.isFocusEnabled||t!==null&&t.diagram!==e)return;e.currentTool instanceof ContextMenuTool||this.cancelVirtualPointer();const s=this.focusBox.adornedPart;s&&s.removeAdornment("Focus"),t===null?(this.bd=null,this.virtualPointerLocation=e.viewportBounds.center,this.focusBox.adornedObject=null):(this.virtualPointerLocation=t.getDocumentPoint(Spot.Center),this.focusBox.adornedObject=t,this.updateFocusBox()),this.onFocusChanged(i,t)}}onFocusChanged(t,i){const e=this.f;if(e&&(this.focusChanged!==null?this.focusChanged(t,i,this):this.nE(this.describe(t,i)),i!==null&&i.part!==null)){const s=i.getDocumentBounds();e.viewportBounds.containsRect(s)||(i instanceof Part?e.commandHandler.scrollToPart(i):e.scrollToRect(s))}}get focusChanged(){return this.uN}set focusChanged(t){t!==null&&U.C(t,CommandHandler,"focusChanged"),this.uN=t}get liveElementId(){return this.Rb||this.dN}set liveElementId(t){const i=this.Rb;t!==i&&(this.Rb=t,this.CN())}CN(){const t=this.diagram;if(!t||!Diagram.isUsingDOM())return;const i=t.ut?.Nt;if(!i)return;const e=this.liveElementId,s=root.document.getElementById(e);this.isUsingAriaLive?(i.removeAttribute("aria-labelledby"),s&&s.setAttribute("aria-live","polite")):(e&&i.setAttribute("aria-labelledby",e),s&&s.removeAttribute("aria-live"))}get isUsingAriaLive(){return this.Ob}set isUsingAriaLive(t){const i=this.Ob;t!==i&&(this.Ob=t,this.CN())}nE(t){const i=this.diagram;if(!i||!Diagram.isUsingDOM()||!i.div)return;let e=this.liveElementId;if(!e){const n=U.Le("span"),o=n.style;for(o.opacity="0",o.position="absolute",o.right="-9999px",o.bottom="-9999px",o.width="0px",o.height="0px",o.overflow="hidden",o.border="0",e=(i.div.id||"diagram")+"_aria";root.document.getElementById(e);)e+=Math.floor(Math.random()*10);n.id=e,this.dN=e,i.div.appendChild(n),this.CN()}const s=root.document.getElementById(e);s&&(s.textContent=t)}describe(t,i){let e="";i instanceof Node?i instanceof Group?e="Group":e="Node":i instanceof Link?e="Link":i instanceof Part?e="Part":i&&(i.click?e="button":i instanceof TextBlock&&i.editable&&(e="editable"),i.portId!==null&&(e&&(e+=" "),e+="port",i.portId&&(e+=" "+i.portId)));const s=this.AN(i);s&&(e+=" "+s);const n=i;if(t&&n instanceof Link&&n.fromNode&&n.toNode){if(t instanceof Node&&t.part===n.fromNode||t instanceof Link&&t.fromNode===n.fromNode){e+=" to "+this.AN(n.toNode,!0);const o=n.toPort?.portId;o&&(e+=" port "+o)}else if(t instanceof Node&&t.part===n.toNode||t instanceof Link&&t.toNode===n.toNode){e+=" from "+this.AN(n.fromNode,!0);const o=n.fromPort?.portId;o&&(e+=" port "+o)}}return e}AN(t,i){if(i===void 0&&(i=!1),!t)return"";if(t instanceof TextBlock&&t.text)return t.text;if(t instanceof Panel){let e="";return t instanceof Part&&t.text&&(e=t.text),i&&e||t.walkVisualTreeFrom(t,(s,n)=>{n.isVisibleObject()&&n instanceof TextBlock&&n.text&&(!i||!e)&&e!==n.text&&(e+=" "+n.text)}),e}return""}updateFocusBox(){const t=this.focus;if(t===null)return;if(t.diagram!==null&&(t instanceof Part?t.isVisible():t.isVisibleObject()&&t.part?.isVisible()))this.focusBox.adornedObject=t,t.part?.addAdornment("Focus",this.focusBox);else{let e=null;if(t instanceof Part||(e=t.part),e instanceof Part&&e.isVisible())this.focus=e;else{if(e instanceof Node&&!e.isVisible()){const s=e.findTreeParentNode();if(s!==null)e=s;else{const n=e.labeledLink;n!==null&&(e=n)}}for(;e instanceof Part&&!e.isVisible();)e=e.containingGroup;e instanceof Part&&e.isVisible()?this.focus=e:this.focus=null}}}findFirstFocus(){const t=this.f;if(t===null||!t.isEnabled)return null;if(this.focus!==null)return this.focus;if(this.isFocusEnabled)if(t.selection.count>0)this.focus=t.selection.first();else{const i=this.jL(t.isTreePathToChildren).first();if(i!==null)return i}return null}get isVirtualPointerEnabled(){return this.gN}set isVirtualPointerEnabled(t){t=!!t;const i=this.isVirtualPointerEnabled;if(t!==i&&(this.gN=t,t)){const e=this.G0;e&&(this.G0=null,e.commandHandler.Cs=null,e.commandHandler.cancelVirtualPointer())}}get isVirtualPointerShown(){return this.mN}set isVirtualPointerShown(t){t=!!t;const i=this.isVirtualPointerShown;if(t!==i){const e=this.f;if(!e||!this.isVirtualPointerEnabled)return;this.mN=t;const s=this.focus;t?this.virtualPointerBox.diagram===null&&(this.virtualPointerLocation.isReal()||(s!==null?this.virtualPointerLocation=s.getDocumentPoint(Spot.Center):this.virtualPointerLocation=e.viewportBounds.center),e.add(this.virtualPointerBox),this.Sh()):this.virtualPointerBox.diagram!==null&&(e.remove(this.virtualPointerBox),this.Sh())}}cancelVirtualPointer(){const t=this.f;t&&(this.MN(),this.isVirtualPointerShown=!1,t.currentTool.doCancel(),this.isVirtualPointerDown=!1,this.TN())}TN(){const t=this.Cs;if(t!==null){this.Cs=null;const i=t.commandHandler;i.Cs=null,i.G0=null,i.isVirtualPointerShown=!1,i.isVirtualPointerDown=!1,i.MN(),this.Eb&&(i.isVirtualPointerEnabled=!1),this.Eb=!1}}MN(){this.ze.button=0,this.ze.modifiers=0,this.ze.clickCount=1,this.ze.down=!1,this.Sh()}Sh(){this.virtualPointerChanged!==null&&this.virtualPointerChanged(this.virtualPointerBox,this),this.updateVirtualPointer()}updateVirtualPointer(){const t=this.virtualPointerBox.diagram;t&&(this.virtualPointerBox.scale=1/t.scale),this.virtualPointerBox.updateTargetBindings()}get virtualPointerBox(){return this.xd}set virtualPointerBox(t){if(!(t instanceof Part))return;const i=this.xd;t!==i&&(i!==null&&(t.location=i.location,i.diagram!==null&&i.diagram.remove(i)),this.xd=t,this.isVirtualPointerShown&&this.diagram&&(this.diagram.add(t),t.data=i.data),this.Sh())}get virtualPointerChanged(){return this.pN}set virtualPointerChanged(t){t!==null&&U.C(t,CommandHandler,"virtualPointerChanged"),this.pN=t}get virtualPointerLocation(){return this.virtualPointerBox.location}set virtualPointerLocation(t){this.virtualPointerLocation.equals(t)||this.JL(t.x,t.y)}get isVirtualPointerDown(){return this.virtualPointerBox.data?this.virtualPointerBox.data.down:!1}set isVirtualPointerDown(t){t=!!t;const i=this.isVirtualPointerDown;if(t!==i){const e=this.f;if(!e||!this.isVirtualPointerEnabled||(this.virtualPointerBox.data===null&&(this.xd.data=this.ze),this.virtualPointerBox.data.down=t,this.Sh(),!this.isVirtualPointerShown))return;const s=e.lastInput,n=new InputEvent;n.diagram=e,this.$L(n,t),t?n.down=!0:n.up=!0,n.clickCount=1,n.button=this.ze.button,n.modifiers=this.ze.modifiers,t&&(e.firstInput=n.copy()),this.kd(n,!0),t||this.ze.clickCount===2&&(n.clickCount=2,n.down=!0,n.up=!1,this.kd(n,!0),n.down=!1,n.up=!0,this.kd(n,!0),this.ZL(1)),e.lastInput=s}}get virtualPointerShiftMove(){return this.K0}set virtualPointerShiftMove(t){this.K0=t}get virtualPointerControlMove(){return this.U0}set virtualPointerControlMove(t){this.U0=t}q0(t,i){this.JL(this.virtualPointerLocation.x+t,this.virtualPointerLocation.y+i)}JL(t,i){this.virtualPointerBox.moveTo(t,i,!0);const e=this.f;if(!e||!this.isVirtualPointerEnabled||!this.isVirtualPointerShown)return;e.ensureBounds();const s=e.lastInput,n=new InputEvent;n.diagram=e,this.$L(n,this.isVirtualPointerDown),n.button=this.ze.button,n.modifiers=this.ze.modifiers,this.kd(n,!0),e.lastInput=s,this.isVirtualPointerDown&&(e.remove(this.virtualPointerBox),e.add(this.virtualPointerBox)),this.Sh()}$L(t,i){const e=this.f;if(e){if(t.targetDiagram=e,t.documentPoint=this.virtualPointerLocation,e.allowDragOut){const s=e.div.getBoundingClientRect(),n=e.transformDocToView(this.virtualPointerLocation),o=s.x+n.x,r=s.y+n.y;let l=root.document.elementFromPoint(o,r)||null;l instanceof HTMLCanvasElement&&(l=l.parentElement),l!==null&&l.shadowRoot&&(l=l.shadowRoot.elementFromPoint(o,r)||null,l instanceof HTMLCanvasElement&&(l=l.parentElement));let h=null;if(l instanceof HTMLElement&&(h=Diagram.Ze.get(l))&&h!==e&&h.div){const a=h.div.getBoundingClientRect(),f=new Point(n.x-(a.x-s.x),n.y-(a.y-s.y));this.Cs!==null&&this.Cs!==h&&this.TN(),t.targetDiagram=h,t.viewPoint=f,t.documentPoint=h.transformViewToDoc(f),t.viewPoint=h.transformDocToView(t.documentPoint),this.Cs=h;const c=h.commandHandler;this.Eb=!c.isVirtualPointerEnabled,c.isVirtualPointerEnabled=!0,c.isVirtualPointerDown=i,c.virtualPointerLocation=t.documentPoint,c.isVirtualPointerShown=!0,c.G0=e;return}}this.Cs!==null&&this.TN(),t.viewPoint=e.transformDocToView(t.documentPoint)}}kd(t,i){this.doVirtualPointerEvent(t,i)}doVirtualPointerEvent(t,i){const e=this.f;e&&(t.timestamp=Date.now(),e.lastInput=t,i&&(t.up?e.doMouseUp():t.down?e.doMouseDown():e.doMouseMove()),this.onVirtualPointerEvent(t,i))}onVirtualPointerEvent(t,i){const e=this.f;e&&(t.up?this.isVirtualPointerDown&&!e.viewportBounds.containsPoint(this.virtualPointerLocation)&&(this.virtualPointerLocation=this.focus instanceof GraphObject?this.focus.getDocumentPoint(Spot.Center):e.viewportBounds.center):t.down)}doVirtualFocusKeyDown(){const t=this.f;if(!t)return!1;const i=t.lastInput,e=i.commandKey;if(this.isVirtualPointerEnabled&&(e==="ShiftLeft"||e==="ShiftRight"))return this.isVirtualPointerShown=!0,!0;if(this.vL.indexOf(e)>=0)if(i.shift&&this.isVirtualPointerShown){const s=this.Bb(e),n=i.control||i.meta?this.U0:this.K0;s===270?this.q0(0,-n):s===90?this.q0(0,n):s===180?this.q0(-n,0):this.q0(n,0)}else this.oE();else if(i.shift&&this.isVirtualPointerShown&&(e==="Numpad1"||e==="Numpad2"||e==="Numpad3"||e==="Numpad4"||e==="Numpad6"||e==="Numpad7"||e==="Numpad8"||e==="Numpad9")){const s=i.control||i.meta?this.U0:this.K0;let n=0;e==="Numpad1"||e==="Numpad4"||e==="Numpad7"?n=-s:(e==="Numpad3"||e==="Numpad6"||e==="Numpad9")&&(n=s);let o=0;e==="Numpad7"||e==="Numpad8"||e==="Numpad9"?o=-s:(e==="Numpad1"||e==="Numpad2"||e==="Numpad3")&&(o=s),this.q0(n,o)}else if(e==="Enter"||e==="NumpadEnter"||e==="Numpad5")i.shift&&this.isVirtualPointerShown?this.isVirtualPointerDown=!this.isVirtualPointerDown:this.rE();else if(e==="Escape")this.lE();else if(e==="Space")this.hE();else if(e==="ContextMenu"||i.shift&&e==="F10"||(i.control||i.meta)&&i.shift&&e==="Backslash")this.aE();else if(i.shift&&e==="c")this.Vb(1);else if(i.shift&&e==="a")this.Vb(2);else if(i.shift&&e==="KeyS")this.Vb(4);else if(i.shift&&e==="KeyM")this.Vb(8);else if(i.shift&&e==="Digit1")this.zb(0);else if(i.shift&&e==="Digit2")this.zb(1);else if(i.shift&&e==="Digit3")this.zb(2);else if(i.shift&&e==="Numpad0"){const s=this.ze.button;this.zb(s===2?0:2)}else if(i.shift&&(e==="KeyD"||e==="NumpadDecimal")){const s=this.ze.clickCount;this.ZL(s===2?1:2)}else if(i.shift&&e==="KeyF"){const s=this.nextFocusFormula;this.nextFocusFormula=s==="distance"?"linear":"distance"}else if(i.shift&&e==="y")this.isUsingAriaLive=!this.isUsingAriaLive;else return!1;return!0}doVirtualFocusKeyUp(){const t=this.f;if(!t)return!1;const e=t.lastInput.commandKey;return this.isVirtualPointerEnabled&&(e==="ShiftLeft"||e==="ShiftRight")&&(this.isVirtualPointerShown=!1),!0}Bb(t){switch(t){case"ArrowDown":return 90;case"ArrowLeft":return 180;case"ArrowUp":return 270;default:return 0}}vL=["ArrowRight","ArrowDown","ArrowLeft","ArrowUp"];Vb(t){const i=this.ze.modifiers;this.ze.modifiers=i&t?i&~t:i|t,this.Sh()}ZL(t){this.ze.clickCount=t,this.Sh()}zb(t){this.ze.button=t,this.Sh()}oE(){const t=this.f;if(!t)return;const i=t.lastInput,e=this.focus;if(e===null){const s=this.jL(t.isTreePathToChildren).first();s!==null&&(this.focus=s)}else if(e instanceof Link)this.fE(e);else if(e instanceof Node)this.cE(e);else{e instanceof Part&&(this.bd=null);const s=this.Bb(i.commandKey);s===270?this.focus=this.findNextFocus(270):s===90?this.focus=this.findNextFocus(90):s===180?this.focus=this.findNextFocus(180):this.focus=this.findNextFocus(0)}}fE(t){const i=this.f;if(!i)return;const e=i.lastInput,s=this.Bb(e.commandKey);let n=null;const o=this.bd;if(o!==null){const r=this.kN;if(s===r)n=t.getOtherNode(o);else if(s===G.Yi(r+180))n=o;else{let l=r===0||r===180?90:0,h=r===0||r===180?270:180;if(s===l){const a=this.LN(o,r,!0),f=a.indexOf(t);f>=0&&f0&&(this.focus=a.elt(f-1))}}}else{const r=t.fromNode,l=t.toNode;if(!r||!l)return;s===270?n=r.location.yl.location.y?r:l:s===180?n=r.location.xl.location.x?r:l}for(;n!==null&&!n.isVisible();)n=n.containingGroup;n!==null&&(this.focus=n)}cE(t){const i=this.f;if(!i)return;const e=i.lastInput,s=this.Bb(e.commandKey);if(e.control||e.meta){const n=this.LN(t,s,!0).first();n&&(this.bd=t,this.kN=s,this.focus=n)}else this.bd=null,this.focus=this.findNextFocus(s)}LN(t,i,e){if(t===null)return new List;const s=t.actualBounds;if(!s.isReal())return new List;const n=new Set;(t instanceof Group?t.findExternalLinksConnected():t.findLinksConnected()).each(l=>{if(!l.isVisible())return;let h=null;if(l.fromNode===t?h=l.toNode:l.toNode===t?h=l.fromNode:t instanceof Group&&(l.fromNode?.isMemberOf(t)?h=l.toNode:l.toNode?.isMemberOf(t)&&(h=l.fromNode)),h===null||h.isMemberOf(t))return;for(;h!==null&&!h.isVisible();)h=h.containingGroup;if(h===null)return;const a=h.location;if(a.isReal()&&!(i===270&&(h!==t?a.y>=s.top:l.midPoint.y>=s.top))){{if(i===90&&(h!==t?a.y<=s.bottom:l.midPoint.y<=s.bottom))return;if(i===180&&(h!==t?a.x>=s.left:l.midPoint.x>=s.left))return;if(i===0&&(h!==t?a.x<=s.right:l.midPoint.x<=s.right))return}e&&l.actualBounds.isReal()?n.add(l):n.add(h)}});const r=new List(n);return i===90||i===270?r.sort((l,h)=>l.actualBounds.centerX-h.actualBounds.centerX):r.sort((l,h)=>l.actualBounds.centerY-h.actualBounds.centerY),r}findNextFocus(t){t=G.Yi(t);const i=this.focus,e=i instanceof Node?i.location:i.getDocumentPoint(Spot.Center);let s=1/0,n=i;const o=(r,l,h,a)=>{if(this.nextFocusFormula==="linear"){let f=1/0;t===0&&h>e.x||t===180&&he.y||t===270&&as))return;if(t===90&&(l.bottoms))return;if(t===180&&(l.x>e.x||(e.x-l.centerX)**2>s))return;if(t===270&&(l.y>e.y||(e.y-l.centerY)**2>s))return;const f=e.direction(h,a),c=G.tR(t,f);if(t===90||t===270?c<=45:c<45){const u=e.distanceSquared(h,a);u{l===i||l instanceof Link||!l.isVisible()||o(l,l.actualBounds,l.location.x,l.location.y)}):(i.diagram.nodes.each(l=>{l===i||!l.isTopLevel||!l.isVisible()||o(l,l.actualBounds,l.location.x,l.location.y)}),i.diagram.parts.each(l=>{l===i||!l.isTopLevel||!l.isVisible()||o(l,l.actualBounds,l.location.x,l.location.y)}))}else if(i.part!==null){const r=new Rect;this.DN(i.part).each(l=>{l!==i&&(l.getDocumentBounds(r),o(l,r,r.centerX,r.centerY))})}return n}get nextFocusFormula(){return this.SN}set nextFocusFormula(t){this.SN=t}rE(){const t=this.f;if(!t)return;const i=t.currentTool;if(i instanceof ContextMenuTool){const n=i.currentObject;this.Xb(this.focus),i.maybeStopTool(this.focus),t.currentTool instanceof ContextMenuTool||(this.focus=n);return}const e=this.focus,s=t.lastInput;if(e===null)s.control||s.meta?this.Xb(null):this.focus=this.findFirstFocus();else if(e instanceof Part)if(s.control||s.meta)this.Xb(e);else{const n=this.DN(e);if(n.count>0)this.focus=n.first();else if(e instanceof Link&&e.isLabeledLink){const o=e.labelNodes.first();o!==null&&o.isVisible()&&(this.focus=o)}else if(e instanceof Group&&e.isSubGraphExpanded){const o=e.memberParts.first();o!==null&&o.isVisible()&&(this.focus=o)}}else this.Xb(e)}jL(t){const i=new List,e=this.f;if(!e)return i;let s=0;for(;i.count===0&&s1)||t.toolTip)&&i.add(t),t instanceof Panel&&t.elements.each(e=>this.An(e,i)),i}Xb(t){const i=this.f;if(!i)return;const e=i.lastInput,s=t instanceof GraphObject?t:i;if(s.click){const n=new InputEvent;n.diagram=i,n.documentPoint=t instanceof GraphObject?t.getDocumentPoint(Spot.Center):i.viewportBounds.center,n.viewPoint=i.transformDocToView(n.documentPoint),n.button=0,n.clickCount=1,n.targetObject=t,this.kd(n,!1),s instanceof GraphObject?s.click(n,s):s.click(n),i.lastInput=e}else s instanceof TextBlock&&s.editable?this.editTextBlock(s):this.QL(t)}lE(){const t=this.f;if(!t)return;const i=t.currentTool;if(i instanceof ToolManager&&i.currentToolTip!==null){i.hideToolTip();return}else if(i instanceof ContextMenuTool){const e=i.currentObject;i.doKeyDown(),this.focus=e;return}if(this.focus instanceof Part){const e=this.focus;e instanceof Node&&e.labeledLink!==null?this.focus=e.labeledLink:e.containingGroup!==null?this.focus=e.containingGroup:this.focus=null}else if(this.focus instanceof GraphObject){const e=this.focus.part;if(e instanceof Link&&e.isLabeledLink){const s=e.labelNodes.first();if(s!==null&&s.isVisible()){this.focus=s;return}}else if(e instanceof Group&&e.isSubGraphExpanded){const s=e.memberParts.first();if(s!==null&&s.isVisible()){this.focus=s;return}}this.focus=e}else this.cancelVirtualPointer(),this.stopCommand()}hE(){const t=this.f;if(!t)return;if(t.lastInput.shift&&this.isVirtualPointerShown){const e=t.findPartAt(this.virtualPointerLocation);e!==null&&(e===this.focus?this._L():this.focus=e)}else this._L()}_L(){const t=this.f;if(!t)return;const i=t.lastInput,e=this.focus;if(e instanceof Part){let s=e.part;if(i.control||i.meta){for(t.raiseDiagramEvent("ChangingSelection",t.selection);s!==null&&!s.canSelect();)s=s.containingGroup;s!==null&&(s.isSelected=!s.isSelected),t.raiseDiagramEvent("ChangedSelection",t.selection)}else if(i.shift){if(s!==null&&!s.isSelected){for(t.raiseDiagramEvent("ChangingSelection",t.selection);s!==null&&!s.canSelect();)s=s.containingGroup;s!==null&&(s.isSelected=!0),t.raiseDiagramEvent("ChangedSelection",t.selection)}}else if(s!==null&&!s.isSelected){for(;s!==null&&!s.canSelect();)s=s.containingGroup;s!==null&&t.select(s)}}this.QL(e),this.onFocusChanged(e,e)}QL(t){const i=this.f;if(!i)return;i.toolManager.hideToolTip();const e=i.lastInput;let s=t instanceof GraphObject?t:i;for(;s instanceof GraphObject&&!s.toolTip;)s=s.panel;if(s&&s.toolTip){const n=new InputEvent;n.diagram=i,n.documentPoint=t!==null?t.getDocumentPoint(Spot.Center):i.viewportBounds.center,n.viewPoint=i.transformDocToView(n.documentPoint),n.targetObject=t,this.kd(n,!1),i.toolManager.showToolTip(s.toolTip,t),i.lastInput=e}}aE(){const t=this.f;if(!t)return;const i=this.focus;if(this.canShowContextMenu(i)){this.showContextMenu(i);const e=t.toolManager.contextMenuTool.currentContextMenu;if(e instanceof Adornment){const s=this.DN(e);s.count>0&&(this.focus=s.first())}}}}var Stretch=(w=>(w[w.None=0]="None",w[w.Default=1]="Default",w[w.Vertical=4]="Vertical",w[w.Horizontal=5]="Horizontal",w[w.Fill=2]="Fill",w))(Stretch||{}),Orientation=(w=>(w[w.None=0]="None",w[w.Along=21]="Along",w[w.Plus90=22]="Plus90",w[w.Minus90=23]="Minus90",w[w.Opposite=24]="Opposite",w[w.Upright=25]="Upright",w[w.Plus90Upright=26]="Plus90Upright",w[w.Minus90Upright=27]="Minus90Upright",w[w.Upright45=28]="Upright45",w))(Orientation||{}),Flip=(w=>(w[w.None=0]="None",w[w.Vertical=1]="Vertical",w[w.Horizontal=2]="Horizontal",w[w.Both=3]="Both",w))(Flip||{});class GraphObject{l;H0;v0;kh;S;Ph;wt;yt;ue;ei;W0;tn;It;gs;rl;Mh;Ci;Ea;lt;vt;ll;Oi;ji;Pd;pi;Md;Xt;ui;hl;Yb;Nh;yc;constructor(){GSet._i(this),this.l=30723,this.ei=1,this.W0="",this.tn=null,this.It=null,this.yt=new Point(NaN,NaN).k(),this.gs=Size.ex,this.rl=new Transform,this.Mh=new Transform,this.Ci=null,this.Ea=1,this.lt=1,this.vt=0,this.ll=Margin.hm,this.ue=new Rect(NaN,NaN,NaN,NaN).k(),this.Oi=new Rect(NaN,NaN,NaN,NaN).k(),this.ji=new Rect(0,0,NaN,NaN).k(),this.Pd=null,this.H0=null,this.wt=null,this.pi=Spot.Default,this.Md=Spot.Default,this.v0=0,this.kh=0,this.Xt=null,this.S=null,this.Ph=null,this.ui=null,this.Yb=null,this.Nh=null,this.hl=null,this.yc=null}cloneProtected(t){t.l=(this.l|2048|4096)&-32769,t.ei=this.ei,t.W0=this.W0,t.It=this.It,t.yt.c(this.yt),t.gs=this.gs.T(),this.Ci!==null?t.Ci=this.Ci.copy():t.Ci=null,t.lt=this.lt,t.vt=this.vt,t.ll=this.ll.T(),t.ue.c(this.ue),t.Oi.c(this.Oi),t.ji.c(this.ji),t.H0=this.H0,this.wt!==null&&(t.wt=this.wt.copy()),t.pi=this.pi.T(),t.Md=this.Md.T(),t.v0=this.v0,t.kh=this.kh,this.Xt!==null&&(t.Xt=this.Xt.copy()),this.S!==null&&(this.S.wi?t.S=this.S:t.S=this.S.copy()),this.Ph!==null&&(t.Ph=this.Ph.slice()),this.ui!==null&&(t.ui=this.ui.copy())}addCopyProperty(t){let i=this.Ph;if(!Array.isArray(i))i=[],this.Ph=i;else for(let e=0;e{d.data!==null&&d.FN()&&d.updateTargetBindings(i)})}}}}VR(t){this.yc&&this.yc.delete(t)}Wo(){if(this.diagram===null)return;if(this.findBindingPanel()===null&&this.Ei!==null){const i=this.diagram.model,e=this.Ei.iterator;for(;e.next();){const s=e.value;if(!s.isToTheme)continue;let n=null;const o=s.sourceName;s.isToObject&&(n=this.tD(o));let r=this;const l=s.targetId;l!==-1&&(r=this.j0(l),r===null)||(o==="/"?n=r.part:o==="."?n=r:o===".."&&(n=r.panel),s.updateTarget(r,n,void 0,i))}}}Ua(t,i){const e=this.findBindingPanel();if(e!==null){const s=t.diagram,n=this.Ei.iterator;for(;n.next();){const o=n.value;let r=null;if(o.isToObject){if(r=o.iD(e,this),r===null)continue;o.updateSource(this,r,i,null)}else if(o.isToModel)s!==null&&!s.Se&&o.updateSource(this,s.model.modelData,i,e);else if(!o.isToTheme){const l=e.data;if(l===null)continue;s!==null&&!s.Se&&o.updateSource(this,l,i,e)}if(r===this){const l=o.targetId,h=e.j0(l);h!==null&&o.updateTarget(h,r,i,s?.model)}}}}j0(t){return this.ho===t?this:null}tD(t){let i;return t===""?i=this:t==="/"?i=this:t==="."?i=this:t===".."?i=this:(i=this.part.findObject(t),i===null&&Debug&&U.ot("Binding error: missing GraphObject named "+t+" in "+this.part.toString())),i}get ho(){return this.S!==null?this.S.ho:-1}set ho(t){this.ho!==t&&(this.S===null&&(this.S=new GraphObjectTemplateSettings),this.S.ho=t)}get Ei(){return this.S!==null?this.S.Ei:null}set Ei(t){this.Ei!==t&&(this.S===null&&(this.S=new GraphObjectTemplateSettings),this.S.Ei=t)}get ao(){return this.S!==null?this.S.ao:null}set ao(t){this.ao!==t&&(this.S===null&&(this.S=new GraphObjectTemplateSettings),this.S.ao=t)}raiseChanged(t,i,e){this.raiseChangedEvent(2,t,this,i,e)}t(t,i,e){this.raiseChangedEvent(2,t,this,i,e)}fo(t,i,e,s){const n=this.ue;if(n.e(t,i,e,s),this.lt!==1||this.vt!==0){this.Ci===null&&(this.Ci=new Transform);const o=this.Ci;o.Ki(),this.J0(o,t,i,e,s),o.am(n)}}eD(t,i,e){return this.pickable===!1?!1:(e.Af(this.E),i?this.intersectsRect(t,e):this.containedInRect(t,e))}sD(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}Ln(){return!0}containsPoint(t){Debug&&U.s(t,Point,GraphObject,"containsPoint:p");const i=Point.a();i.c(t),this.E.St(i);const e=this.actualBounds;if(!e.isReal())return Point.o(i),!1;const s=this.diagram;if(s!==null&&s.S0){const o=s.getInputOption("extraTouchThreshold"),r=s.getInputOption("extraTouchArea"),l=r/2,h=this.naturalBounds,a=this.getDocumentScale()*s.scale,f=1/a;if(h.width*ae&&(c=t),isFinite(i)&&i>s&&(u=i);break;case 5:isFinite(t)&&t>e&&(c=t),u=0,d&&(i=1/0);break;case 4:isFinite(i)&&i>s&&(u=i),c=0,d&&(t=1/0);break}const g=this.maxSize,p=this.minSize;c>g.width&&p.widthg.height&&p.heightu.height||this.xi>u.width)&&(r=!0)}}}r?this.l|=256:this.l&=-257,this.Oi.isReal()||U.n("Non-real actualBounds has been set. Object "+this+", actualBounds: "+this.Oi.toString()),this.Ad(o,this.Oi),this.co(!1),Rect.o(o)}Th(t,i,e,s){}commonArrange(t,i,e,s){if(this.Oi.e(t,i,e,s),this.desiredSize.isReal())return;const n=this.ue,o=this.ll,r=o.right+o.left,l=o.top+o.bottom,h=n.width+r,a=n.height+l;e+=r,s+=l;let f=this.en(!0);switch(h===e&&a===s&&(f=0),f){case 0:(h>e||a>s)&&(this.ke(!0),this.gt(h>e?e:h,a>s?s:a,0,0));break;case 2:this.ke(!0),this.gt(e,s,0,0);break;case 5:this.ke(!0),this.gt(e,a,0,0);break;case 4:this.ke(!0),this.gt(h,s,0,0);break}}Ad(t,i){const e=this.part;e!==null&&e.diagram!==null&&((e.selectionObject===this||e.resizeObject===this||e.rotateObject===this)&&e.IN(!0),this.L(),!t.equalsApproxClose(i)&&(e.Lh(),this._0(e)))}_0(t){this.portId!==null&&(t.IN(!0),t instanceof Node&&t.invalidateConnectedLinks(void 0,this))}get shadowVisible(){return this.S!==null?this.S.tp:null}set shadowVisible(t){const i=this.shadowVisible;i!==t&&(Debug&&t!==null&&U.i(t,"boolean",GraphObject,"shadowVisible"),this.jt().tp=t,this._e(!0),this.L(),this.t("shadowVisible",i,t))}uE(t,i){const e=this.naturalBounds,s=this.Mh,n=s.m11,o=s.m21,r=s.dx,l=s.m12,h=s.m22,a=s.dy;let f=0,c=0,u=f,d=c;f=u*n+d*o+r,c=u*l+d*h+a;let m=f,g=c,p=0,y=0;u=e.width+i,d=0,f=u*n+d*o+r,c=u*l+d*h+a;let x=Math.min(m,f),b=Math.min(g,c);p=Math.max(m+p,f)-x,y=Math.max(g+y,c)-b,m=x,g=b,u=e.width+i,d=e.height+i,f=u*n+d*o+r,c=u*l+d*h+a,x=Math.min(m,f),b=Math.min(g,c),p=Math.max(m+p,f)-x,y=Math.max(g+y,c)-b,m=x,g=b,u=0,d=e.height+i,f=u*n+d*o+r,c=u*l+d*h+a,x=Math.min(m,f),b=Math.min(g,c),p=Math.max(m+p,f)-x,y=Math.max(g+y,c)-b,m=x,g=b;const S=t.viewportBounds,k=S.x,P=S.y,A=S.width,C=S.height;return m>A+k||k>p+m||g>C+P||P>y+g}vi(t,i){if(this.dE(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.E,r=this.panel;this.$0()===!0&&this.Kb();const l=this.part;let h=!1,a=0;if(l&&i.getRenderingHint("drawShadows")&&(h=l.isShadowed,h)){const g=l.shadowOffset;a=Math.max(g.y,g.x)*i.scale*i.te}const f=this instanceof Panel&&this.al(),c=this.Oi;if(f&&(this.nD(h,t,!1,r),this.gE(t,i),this.oD(h,t,!1,r),this.rD(h,t,!1)),f||!f&&(c.width===0||c.height===0||isNaN(c.x)||isNaN(c.y))){e!==1&&(t.globalAlpha=s),this.filter!==""&&(t.filter=n);return}const u=this.sn();if(!i.Sa&&u&&this.uE(i,a)){e!==1&&(t.globalAlpha=s),this.filter!==""&&(t.filter=n);return}let d=(this.l&256)!==0;if(t.clipInsteadOfFill&&(d=!1),this instanceof TextBlock&&(t.font=this.font),d){const g=r.Ln()?r.naturalBounds:r.actualBounds;let p=Math.max(c.x,g.x),y=Math.max(c.y,g.y),x=Math.min(c.right,g.right)-p,b=Math.min(c.bottom,g.bottom)-y;const S=this.ui;if(S!==null&&(p=S.x,y=S.y,x=S.width,b=S.height),p>c.width+c.x||c.x>g.width+g.x){e!==1&&(t.globalAlpha=s),this.filter!==""&&(t.filter=n);return}t.save(),t.beginPath(),t.rect(p,y,x,b),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.te,g.y*i.scale*this.scale*i.te,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.nD(h,t,u,r),this.It!==null&&(t.commitTransform(),this.Ub(t,m,c)),this.oD(h,t,u,r),this.Dh(t,i),this.rD(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)}nD(t,i,e,s){t&&this.shadowVisible===!0?i.shadowsOn():t&&this.shadowVisible===!1&&i.shadowsOff(),t&&this.Gb(s)&&this.shadowVisible===null&&i.shadowsOff()}oD(t,i,e,s){t&&(this.It!==null||this.Gb(s))?(this.qb(!0),this.shadowVisible===null&&i.shadowsOff()):this.qb(!1)}rD(t,i,e){t&&this.RN()===!0&&i.shadowsOn(),e&&t&&i.shadowsOff()}mE(t,i,e){const s=this.part;let n=!1;s&&t.getRenderingHint("drawShadows")&&(n=s.isShadowed),i.clipInsteadOfFill&&(n=!1),this.sn()&&n&&i.shadowsOn(),n&&this.shadowVisible===!0?i.shadowsOn():n&&this.shadowVisible===!1&&i.shadowsOff();const o=this.panel;if(n&&this.Gb(o)&&this.shadowVisible===null&&i.shadowsOff(),i.fl){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.It.setAttributeNS(null,"filter",l)}return n&&(this.It!==null||this.Gb(o))?(this.qb(!0),this.shadowVisible===null&&i.shadowsOff()):this.qb(!1),n}pE(t,i,e,s){if(e.fl){const n=i.computePixelRatio(),o=`drop-shadow(${e.shadowOffsetX/n}px ${e.shadowOffsetY/n}px ${e.shadowBlur/n/2}px ${e.shadowColor})`;this.ON(t,o)}s&&this.RN()===!0&&e.shadowsOn(),this.sn()&&e.shadowsOff()}Gb(t){return t===null?!1:(t.al()&&(t=t.panel),t.RN()||(t.type===Panel.Auto||t.type===Panel.Spot)&&t.findMainElement()!==this)}ON(t,i){}Ub(t,i,e){const s=this.Z0(),n=i.x,o=i.y,r=i.width+s,l=i.height+s;this.Nn(t,this.It,!0,!1,i,e),this.It instanceof Brush&&this.It.type===3?(t.beginPath(),t.rect(n-s/2,o-s/2,r,l),t.fillContext(this.It,!1,null)):t.fillRect(n-s/2,o-s/2,r,l)}lD(t,i){let e=t.yE(this);const s=t.Nh!==null?t.Nh:t.svg;if(s!==null&&e!==-1){for(;e!==0&&!t.elt(e-1).isVisibleObject();)e--;if(e===0)this.wE(t,i,s);else{const n=t.elt(e-1).svg;n!==null?n.after(i):s.appendChild(i)}}}wE(t,i,e){if(t.type===Panel.Table){const s=e.getElementsByClassName("gojs-ts"),n=s.length!==0?s[0]:null;n!==null&&n.after(i)}else e.It?e.It.after(i):e.prepend(i)}dE(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.Oi;if(this.sn()&&(!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;t.setCurrentTransform(1,0,0,1,0,0);const s=this.panel,n=this.Td(t);if(this.kc(t,i,n))return this.hD(this.svg),this.svg.parentElement!==null?(this.sn()&&(t.lastDrawnPart=this.svg),!0):(this.sn()?(t.lastDrawnPart!==null?t.lastDrawnPart.after(this.svg):t.diagramGroup.prepend(this.svg),t.lastDrawnPart=this.svg):s&&this.lD(s,this.svg),!0);if(this._e(!1),this.sn()&&this.isShadowed){const m=this.shadowOffset;t.shadowsSet(m.x*i.scale*this.scale*i.te,m.y*i.scale*this.scale*i.te,this.shadowBlur),t.shadowsOn(),t.shadowColor=this.shadowColor}this instanceof TextBlock&&(t.font=this.font),t.currentElement=null;const o=this.E,r=this instanceof Panel,l=this instanceof Panel?this.al():!1,h=this.svg;if(this.$0()===!0&&this.Kb(),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 a=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.Ub(t,a,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.Ub(t,a,e)),t.currentElement.It=t.lastCreatedElement,t.currentElement.prepend(t.lastCreatedElement));const f=this.mE(i,t,t.currentElement);this.Dh(t,i),r&&t.endGroup(),t.outerGroup&&t.endGroup();const c=t.surface.wd,u=r?this.svg:t.currentElement;if(h!==null&&h.parentNode!==null&&u!==h&&(this.panel===null||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.ip(t,s,e,u),!0}if(this.svg=u,c!==null&&u===null&&t.dummyGroup(),u===null)return!0;this.ip(t,s,e,u),this.pE(u,i,t,f);const d=this.sn()?this.opacity*t.globalAlpha:this.opacity;if(d!==1&&u.setAttributeNS(null,"opacity",d.toString()),this.filter!==""&&u.setAttributeNS(null,"filter",this.filter),this.sn()){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.lD(s,u);return c!==null&&c(this,u),this.hD(u),!0}hD(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.Jn(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)))))}ip(t,i,e,s){let n=(this.l&256)!==0;if(t.clipInsteadOfFill&&(n=!1),!n){s.removeAttributeNS(null,"clip-path");return}const o=i.Ln()?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,a=Math.min(e.bottom,o.bottom)-l;const f=this.ui;f!==null&&(r=f.x,l=f.y,h=f.width,a=f.height);const c=Rect.U(r,l,Math.max(h,0),Math.max(a,0));if(this instanceof Panel){const u=Transform.a();u.set(this.E),u.ux(),u.am(c),Transform.o(u)}s.setAttributeNS(null,"clip-path",`path(' M ${c.x},${c.y} L ${c.width+c.x} ${c.y} L ${c.width+c.x} ${c.height+c.y} L ${c.x} ${c.height+c.y} z') view-box`),Rect.o(c)}xE(){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()}gE(t,i){const e=this.Oi,s=this.ji,n=this.It;n!==null&&t.commitTransform(),n!==null&&(this.Nn(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.Dh(t,i)}Dh(t,i){}Pc(){this._e(!0)}kc(t,i,e){const s=this.svg;if(this.bE()){if(this.Pc(),this._e(!1),s===null)return!1;const f=s.getAttribute("clip-path");if(f!==null&&f.includes("url")){const u=t.svg.getElementById(f.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.E,o="matrix("+n.m11+", "+n.m12+", "+n.m21+", "+n.m22+", "+n.dx+", "+n.dy+")",r=this instanceof Panel,l=r?this.al():!1;if(!(r&&l))if(this instanceof Picture){const f=this.Hb;t.setCurrentTransform(n.m11,n.m12,n.m21,n.m22,n.dx,n.dy),f!==null&&t.amendImageTransform(f[0],f[1],f[2],f[3],f[4],f[5],f[6],f[7]),e?s.lastElementChild.setAttributeNS(null,"transform",t.getCurrentTransform()):s.setAttributeNS(null,"transform",t.getCurrentTransform())}else if(e&&!r)if(this instanceof Shape){const f=s.getElementsByTagName("path");for(let c=0;c=.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+c*c));a<0&&(p=-p),i+=p,e+=c*p,m?t.lineTo(i,e):t.moveTo(i,e),u-=l,m=!m}}Nn(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 a=this.Z0();r=n.width,l=n.height,s?(r=o.width,l=o.height):e||(r+=a,l+=a);const f=t instanceof CanvasSurfaceContext;if(f&&i.Dn&&(i.type===4||i.Mc===r&&i.vb===l))h=i.Dn;else{let c=0,u=0,d=0,m=0,g=0,p=0,y=0,x=0;if(s?(y=o.x,x=o.y):e||(y-=a/2,x-=a/2),c=i.start.x*r+i.start.offsetX+y,u=i.start.y*l+i.start.offsetY+x,d=i.end.x*r+i.end.offsetX+y,m=i.end.y*l+i.end.offsetY+x,i.type===2)h=t.createLinearGradient(c,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(c,u,g,d,m,p);else if(i.type===4)try{h=t.createPattern(i.pattern,"repeat")}catch{h=null}else U.Ti(i.type,"Brush type");if(i.type!==4){const b=i.colorStops;if(b!==null){const S=b.iterator;for(;S.next();)h.addColorStop(S.key,S.value)}}if(f&&(i.Dn=h,h!==null&&(i.Mc=r,i.vb=l),h===null&&i.type===4&&i.Mc!==-1)){i.Mc=-1;const b=this.diagram;b!==null&&i.Mc===-1&&U.pn(()=>{b.redraw()},600)}}e?t.fillStyle=h:t.strokeStyle=h}isContainedBy(t){return t instanceof Panel?this.SE(this,t):!1}SE(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.S!==null?this.S.ep:null}set enabledChanged(t){const i=this.enabledChanged;i!==t&&(t!==null&&U.C(t,GraphObject,"enabledChanged"),this.jt().ep=t,this.t("enabledChanged",i,t))}Kb(){if(this.Wb()===!0){const t=this.rl;if(t.Ki(),!this.Oi.isReal()||!this.ue.isReal()){this.Ld(!1),this.Fh(!1);return}if(t.Hs(this.Oi.x-this.ue.x,this.Oi.y-this.ue.y),this.scale!==1||this.angle!==0){const i=this.naturalBounds;this.J0(t,i.x,i.y,i.width,i.height)}this.Ld(!1),this.Fh(!0)}if(this.$0()===!0){const t=this.panel;if(t===null)this.Mh.set(this.rl),this.Ea=this.scale;else if(t.Qs!==null){const i=this.Mh;i.Ki(),t.Ln()?i.Af(t.Mh):t.panel!==null&&i.Af(t.panel.Mh),i.Af(this.rl),this.Ea=this.scale*t.Ea}this.Fh(!1)}}J0(t,i,e,s,n){if(this.lt!==1&&t.lt(this.lt),this.vt===0)return;const o=Point.a();o.setSpot(i,e,s,n,Spot.Center),t.Ns(this.vt,o.x,o.y),Point.o(o)}g(t){if(this.vo())return;t===void 0&&(t=!1),this.ke(!0),this.co(!0);const i=this.panel;i!==null&&!t&&i.g()}Nc(){this.vo()||(this.ke(!0),this.co(!0))}Cc(t){if(this.us())return;const i=this.panel;!t&&i!==null&&i.g(),this.co(!0)}Sc(){this.Wb()===!1&&(this.Ld(!0),this.Fh(!0))}EN(){this.Fh(!0)}L(){const t=this.part;t!==null&&t.L()}en(t){const i=this.stretch,e=this.panel;if(e===null)return this.Zo(i===1?0:i,t);if(e.type===Panel.Table)return this.sp(e.getRowDefinition(this.row),e.getColumnDefinition(this.column),t);if(e.type===Panel.Auto&&e.findMainElement()===this)return this.Zo(2,t);if(i===1){if(e.type===Panel.Spot&&e.findMainElement()===this)return this.Zo(2,t);const s=e.defaultStretch;return s===1?this.Zo(0,t):this.Zo(s,t)}return this.Zo(i,t)}sp(t,i,e){const s=this.stretch;if(s!==1)return this.Zo(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.Zo(2,e):n===!0?this.Zo(5,e):o===!0?this.Zo(4,e):this.Zo(0,e)}Zo(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.Xt!==null?this.Xt.np:0}set segmentOrientation(t){const i=this.segmentOrientation;i!==t&&(Debug&&U.W(t,Orientation,"Orientation"),this.Xt===null&&(this.Xt=new LinkElementSettings),this.Xt.np=t,this.g(),this.t("segmentOrientation",i,t),t===0&&(this.angle=0))}kE(){this.segmentOrientation=21}get segmentIndex(){return this.Xt!==null?this.Xt.op:-1/0}set segmentIndex(t){Debug&&U.i(t,"number",GraphObject,"segmentIndex"),t=Math.round(t);const i=this.segmentIndex;i!==t&&(this.Xt===null&&(this.Xt=new LinkElementSettings),this.Xt.op=t,this.g(),this.t("segmentIndex",i,t))}get segmentFraction(){return this.Xt!==null?this.Xt.rp:0}set segmentFraction(t){Debug&&U.r(t,GraphObject,"segmentFraction"),t<0?t=0:t>1&&(t=1);const i=this.segmentFraction;i!==t&&(this.Xt===null&&(this.Xt=new LinkElementSettings),this.Xt.rp=t,this.g(),this.t("segmentFraction",i,t))}get segmentOffset(){return this.Xt!==null?this.Xt.lp:Point.yn}set segmentOffset(t){const i=this.segmentOffset;i.equals(t)||(Debug&&U.s(t,Point,GraphObject,"segmentOffset"),t=t.T(),this.Xt===null&&(this.Xt=new LinkElementSettings),this.Xt.lp=t,this.g(),this.t("segmentOffset",i,t))}get stretch(){return this.S!==null?this.S.uo:1}set stretch(t){const i=this.stretch;i!==t&&(Debug&&U.W(t,Stretch,"Stretch"),this.jt().uo=t,this.g(),this.t("stretch",i,t))}get name(){return this.S!==null?this.S.At:""}set name(t){const i=this.name;i!==t&&(Debug&&U.i(t,"string",GraphObject,"name"),this.jt().At=t,this.part!==null&&this.part.hp(),this.t("name",i,t))}get opacity(){return this.ei}set opacity(t){Debug&&U.r(t,GraphObject,"opacity"),t<0?t=0:t>1&&(t=1);const i=this.opacity;if(i!==t){this.ei=t,this.t("opacity",i,t);const e=this.diagram,s=this.part;e!==null&&s!==null&&e.L(s.ga(s.actualBounds))}}get filter(){return this.W0}set filter(t){const i=this.filter;if(i!==t){Debug&&U.i(t,"string",GraphObject,"filter"),this.W0=t,this._e(!0),this.t("filter",i,t);const e=this.diagram,s=this.part;e!==null&&s!==null&&e.L(s.ga(s.actualBounds))}}get visible(){return(this.l&1)!==0}set visible(t){const i=(this.l&1)!==0;if(i!==t){Debug&&U.i(t,"boolean",GraphObject,"visible"),this.l=this.l^1,this.Pc(),this.t("visible",i,t);const e=this.panel;e!==null?e.g():this.sn()&&this.Hi(t),this.L(),this.aD()}}get pickable(){return(this.l&2)!==0}set pickable(t){const i=(this.l&2)!==0;i!==t&&(Debug&&U.i(t,"boolean",GraphObject,"pickable"),this.l=this.l^2,this.t("pickable",i,t))}get fromLinkableDuplicates(){return(this.l&4)!==0}set fromLinkableDuplicates(t){const i=(this.l&4)!==0;i!==t&&(Debug&&U.i(t,"boolean",GraphObject,"fromLinkableDuplicates"),this.l=this.l^4,this.t("fromLinkableDuplicates",i,t))}get fromLinkableSelfNode(){return(this.l&8)!==0}set fromLinkableSelfNode(t){const i=(this.l&8)!==0;i!==t&&(Debug&&U.i(t,"boolean",GraphObject,"fromLinkableSelfNode"),this.l=this.l^8,this.t("fromLinkableSelfNode",i,t))}get toLinkableDuplicates(){return(this.l&16)!==0}set toLinkableDuplicates(t){const i=(this.l&16)!==0;i!==t&&(Debug&&U.i(t,"boolean",GraphObject,"toLinkableDuplicates"),this.l=this.l^16,this.t("toLinkableDuplicates",i,t))}get toLinkableSelfNode(){return(this.l&32)!==0}set toLinkableSelfNode(t){const i=(this.l&32)!==0;i!==t&&(Debug&&U.i(t,"boolean",GraphObject,"toLinkableSelfNode"),this.l=this.l^32,this.t("toLinkableSelfNode",i,t))}get isPanelMain(){return(this.l&64)!==0}set isPanelMain(t){const i=(this.l&64)!==0;i!==t&&(Debug&&U.i(t,"boolean",GraphObject,"isPanelMain"),this.l=this.l^64,this.g(),this.t("isPanelMain",i,t))}get isActionable(){return(this.l&128)!==0}set isActionable(t){const i=(this.l&128)!==0;i!==t&&(Debug&&U.i(t,"boolean",GraphObject,"isActionable"),this.l=this.l^128,this.t("isActionable",i,t))}get background(){return this.It}set background(t){const i=this.background;i!==t&&(t!==null&&Brush.Dd(t,"GraphObject.background"),t instanceof Brush&&t.k(),this.It=t,this.L(),this.t("background",i,t))}RN(){return(this.l&512)!==0}qb(t){t?this.l|=512:this.l&=-513}xc(){return(this.l&1024)!==0}BN(t){t?this.l|=1024:this.l&=-1025}Wb(){return(this.l&2048)!==0}Ld(t){t?this.l|=2048:this.l&=-2049}$0(){return(this.l&4096)!==0}Fh(t){t?this.l|=4096:this.l&=-4097}vo(){return(this.l&8192)!==0}ke(t){t?this.l|=8192:this.l&=-8193}us(){return(this.l&16384)!==0}co(t){t?this.l|=16384:this.l&=-16385}bE(){return(this.l&32768)!==0}_e(t){t?this.l|=32768:this.l&=-32769}get part(){if(this.sn())return this;if(this.hl!==null)return this.hl;let t=this;for(t=t.panel;t;){if(t instanceof Part)return this.hl=t,t;t=t.panel}return null}get svg(){return this.Yb}set svg(t){this.Yb=t}tc(){this.svg=null}get panel(){return this.tn}Ga(t){this.tn=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.yt}set position(t){Debug&&U.s(t,Point,GraphObject,"position");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.VN(t,n,o)&&this.t("position",new Point(n,o),t.copy())):this.zN()}zN(){}VN(t,i,e){return this.yt=t,this.Cc(),!0}Gf(t,i,e){this.yt.x===t&&this.yt.y===i||(this.yt.e(t,i),this.Sc())}get actualBounds(){return this.Oi}get scale(){return this.lt}set scale(t){const i=this.scale;i!==t&&(Debug&&U.r(t,GraphObject,"scale"),t<=0&&U.n("GraphObject.scale for "+this+" must be greater than zero, not: "+t),this.lt=t,this.g(),this.t("scale",i,t))}get angle(){return this.vt}set angle(t){const i=this.angle;if(i!==t){if(Debug&&U.r(t,GraphObject,"angle"),t=t%360,t<0&&(t+=360),i===t)return;this.vt=t,this.aD(),this.g(),this.t("angle",i,t)}}get desiredSize(){return this.gs}set desiredSize(t){Debug&&U.s(t,Size,GraphObject,"desiredSize");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.T(),this.gs=t,this.g(),this instanceof Shape&&this.ce(),this.t("desiredSize",s,t),this.xc())){const r=this.part;r!==null&&(this.Ua(r,"width"),this.Ua(r,"height"))}}get width(){return this.gs.width}set width(t){const i=this.gs.width;if(i!==t&&(!isNaN(i)||!isNaN(t))){Debug&&U.i(t,"number",GraphObject,"width");const e=this.gs,s=new Size(t,this.gs.height).k();if(this.gs=s,this.g(),this instanceof Shape&&this.ce(),this.t("desiredSize",e,s),this.xc()){const n=this.part;n!==null&&this.Ua(n,"width")}}}get height(){return this.gs.height}set height(t){const i=this.gs.height;if(i!==t&&(!isNaN(i)||!isNaN(t))){Debug&&U.i(t,"number",GraphObject,"height");const e=this.gs,s=new Size(this.gs.width,t).k();if(this.gs=s,this.g(),this instanceof Shape&&this.ce(),this.t("desiredSize",e,s),this.xc()){const n=this.part;n!==null&&this.Ua(n,"height")}}}get minSize(){return this.S!==null?this.S.Dr:Size.sa}set minSize(t){const i=this.minSize;i.equals(t)||(Debug&&U.s(t,Size,GraphObject,"minSize"),t=t.copy(),isNaN(t.width)&&(t.width=0),isNaN(t.height)&&(t.height=0),t.k(),this.jt().Dr=t,this.g(),this.t("minSize",i,t))}get maxSize(){return this.S!==null?this.S.Fr:Size.ix}set maxSize(t){const i=this.maxSize;i.equals(t)||(Debug&&U.s(t,Size,GraphObject,"maxSize"),t=t.copy(),isNaN(t.width)&&(t.width=1/0),isNaN(t.height)&&(t.height=1/0),t.k(),this.jt().Fr=t,this.g(),this.t("maxSize",i,t))}get measuredBounds(){return this.ue}get naturalBounds(){return this.ji}Z0(){return 0}get margin(){return this.ll}set margin(t){typeof t=="number"?t=new Margin(t):Debug&&U.s(t,Margin,GraphObject,"margin");const i=this.ll;i.equals(t)||(t=t.T(),this.ll=t,this.g(),this.t("margin",i,t))}get E(){return this.Wb()===!0&&this.Kb(),this.rl}get Qs(){return this.$0()===!0&&this.Kb(),this.Mh}trigger(t,i,e){let s=null;return typeof t=="string"?s=new AnimationTrigger(t,i,e):s=t,s.Re=this,this.Rs===null&&(this.Rs=new GMap),this.Rs.set(s.propertyName,s),this}get Rs(){return this.S!==null?this.S.Rs:null}set Rs(t){this.Rs!==t&&(this.jt().Rs=t)}get Lr(){return this.S!==null?this.S.Lr:0}set Lr(t){this.Lr!==t&&(this.jt().Lr=t)}get alignment(){return this.pi}set alignment(t){const i=this.alignment;i.equals(t)||(Debug&&U.s(t,Spot,GraphObject,"alignment"),t.isNoSpot()&&!t.isDefault()&&U.n("GraphObject.alignment for "+this+" must be a real Spot or Spot.Default, not: "+t),t=t.T(),this.pi=t,this.Cc(),this.t("alignment",i,t))}get column(){return this.kh}set column(t){Debug&&U.r(t,GraphObject,"column"),t=Math.round(t);const i=this.column;i!==t&&(t<0&&U.G(t,">= 0",GraphObject,"column"),this.kh=t,this.g(),this.t("column",i,t),this.svg!==null&&this.svg.remove())}get columnSpan(){return this.S!==null?this.S.ap:1}set columnSpan(t){Debug&&U.i(t,"number",GraphObject,"columnSpan"),t=Math.round(t);const i=this.columnSpan;i!==t&&(t<1&&U.G(t,">= 1",GraphObject,"columnSpan"),this.jt().ap=t,this.g(),this.t("columnSpan",i,t))}get row(){return this.v0}set row(t){Debug&&U.r(t,GraphObject,"row"),t=Math.round(t);const i=this.row;i!==t&&(t<0&&U.G(t,">= 0",GraphObject,"row"),this.v0=t,this.g(),this.t("row",i,t),this.svg!==null&&this.svg.remove())}get rowSpan(){return this.S!==null?this.S.fp:1}set rowSpan(t){Debug&&U.i(t,"number",GraphObject,"rowSpan"),t=Math.round(t);const i=this.rowSpan;i!==t&&(t<1&&U.G(t,">= 1",GraphObject,"rowSpan"),this.jt().fp=t,this.g(),this.t("rowSpan",i,t))}get spanAllocation(){return this.S!==null?this.S.cp:null}set spanAllocation(t){const i=this.spanAllocation;i!==t&&(t!==null&&U.C(t,GraphObject,"spanAllocation"),this.jt().cp=t,this.g(),this.t("spanAllocation",i,t))}get alignmentFocus(){return this.Md}set alignmentFocus(t){const i=this.alignmentFocus;i.equals(t)||(Debug&&U.s(t,Spot,GraphObject,"alignmentFocus"),Debug&&t.isNoSpot()&&!t.isDefault()&&!(t.isNone()&&this instanceof Node)&&U.n("GraphObject.alignmentFocus must be a real Spot or Spot.Default, not: "+t),t=t.T(),this.Md=t,this.g(),this.t("alignmentFocus",i,t))}get portId(){return this.H0}set portId(t){const i=this.portId;if(i!==t){Debug&&t!==null&&U.i(t,"string",GraphObject,"portId");const e=this.part;e!==null&&!(e instanceof Node)&&U.n("Cannot set portID on a Link: "+t);const s=e;i!==null&&s!==null&&s.XN(this),this.H0=t,t!==null&&s!==null&&(s.Fn=!0,s.fD(this)),this.t("portId",i,t)}}qa(){const t=this.part;if(t instanceof Node&&(this.portId!==null||this===t.port)){const i=t.diagram;i!==null&&!i.undoManager.isUndoingRedoing&&t.invalidateConnectedLinks(void 0,this)}}aD(){const t=this.diagram;t===null||t.undoManager.isUndoingRedoing||(this instanceof Panel?this instanceof Node?this.invalidateConnectedLinks():this.walkVisualTreeFrom(this,i=>{i.qa()}):this.qa())}get toSpot(){return this.wt!==null?this.wt.Va:Spot.None}set toSpot(t){const i=this.toSpot;i.equals(t)||(Debug&&U.s(t,Spot,GraphObject,"toSpot"),t=t.T(),this.Qe().Va=t,this.t("toSpot",i,t),this.qa())}get toEndSegmentLength(){return this.wt!==null?this.wt.Xa:10}set toEndSegmentLength(t){const i=this.toEndSegmentLength;i!==t&&(Debug&&U.i(t,"number",GraphObject,"toEndSegmentLength"),t<0&&U.G(t,">= 0",GraphObject,"toEndSegmentLength"),this.Qe().Xa=t,this.t("toEndSegmentLength",i,t),this.qa())}get toShortLength(){return this.wt!==null?this.wt.Ka:0}set toShortLength(t){const i=this.toShortLength;i!==t&&(Debug&&U.i(t,"number",GraphObject,"toShortLength"),this.Qe().Ka=t,this.t("toShortLength",i,t),this.qa())}get toLinkable(){return this.wt!==null?this.wt.dp:null}set toLinkable(t){const i=this.toLinkable;i!==t&&(Debug&&t!==null&&U.i(t,"boolean",GraphObject,"toLinkable"),this.Qe().dp=t,this.t("toLinkable",i,t))}get toMaxLinks(){return this.wt!==null?this.wt.gp:1/0}set toMaxLinks(t){const i=this.toMaxLinks;i!==t&&(Debug&&U.i(t,"number",GraphObject,"toMaxLinks"),t<0&&U.G(t,">= 0",GraphObject,"toMaxLinks"),this.Qe().gp=t,this.t("toMaxLinks",i,t))}get fromSpot(){return this.wt!==null?this.wt.Ba:Spot.None}set fromSpot(t){const i=this.fromSpot;i.equals(t)||(Debug&&U.s(t,Spot,GraphObject,"fromSpot"),t=t.T(),this.Qe().Ba=t,this.t("fromSpot",i,t),this.qa())}get fromEndSegmentLength(){return this.wt!==null?this.wt.za:10}set fromEndSegmentLength(t){const i=this.fromEndSegmentLength;i!==t&&(Debug&&U.i(t,"number",GraphObject,"fromEndSegmentLength"),t<0&&U.G(t,">= 0",GraphObject,"fromEndSegmentLength"),this.Qe().za=t,this.t("fromEndSegmentLength",i,t),this.qa())}get fromShortLength(){return this.wt!==null?this.wt.Ya:0}set fromShortLength(t){const i=this.fromShortLength;i!==t&&(Debug&&U.i(t,"number",GraphObject,"fromShortLength"),this.Qe().Ya=t,this.t("fromShortLength",i,t),this.qa())}get fromLinkable(){return this.wt!==null?this.wt.mp:null}set fromLinkable(t){const i=this.fromLinkable;i!==t&&(Debug&&t!==null&&U.i(t,"boolean",GraphObject,"fromLinkable"),this.Qe().mp=t,this.t("fromLinkable",i,t))}get fromMaxLinks(){return this.wt!==null?this.wt.pp:1/0}set fromMaxLinks(t){const i=this.fromMaxLinks;i!==t&&(Debug&&U.i(t,"number",GraphObject,"fromMaxLinks"),t<0&&U.G(t,">= 0",GraphObject,"fromMaxLinks"),this.Qe().pp=t,this.t("fromMaxLinks",i,t))}get cursor(){return this.S!==null?this.S.Xl:""}set cursor(t){const i=this.cursor;i!==t&&(U.i(t,"string",GraphObject,"cursor"),this.jt().Xl=t,this.t("cursor",i,t))}get click(){return this.S!==null?this.S.Kr:null}set click(t){const i=this.click;i!==t&&(t!==null&&U.C(t,GraphObject,"click"),this.jt().Kr=t,this.t("click",i,t))}get doubleClick(){return this.S!==null?this.S.Ur:null}set doubleClick(t){const i=this.doubleClick;i!==t&&(t!==null&&U.C(t,GraphObject,"doubleClick"),this.jt().Ur=t,this.t("doubleClick",i,t))}get contextClick(){return this.S!==null?this.S.Gr:null}set contextClick(t){const i=this.contextClick;i!==t&&(t!==null&&U.C(t,GraphObject,"contextClick"),this.jt().Gr=t,this.t("contextClick",i,t))}get mouseEnter(){return this.S!==null?this.S.jr:null}set mouseEnter(t){const i=this.mouseEnter;i!==t&&(t!==null&&U.C(t,GraphObject,"mouseEnter"),this.jt().jr=t,this.t("mouseEnter",i,t))}get mouseLeave(){return this.S!==null?this.S.Jr:null}set mouseLeave(t){const i=this.mouseLeave;i!==t&&(t!==null&&U.C(t,GraphObject,"mouseLeave"),this.jt().Jr=t,this.t("mouseLeave",i,t))}get mouseOver(){return this.S!==null?this.S.qr:null}set mouseOver(t){const i=this.mouseOver;i!==t&&(t!==null&&U.C(t,GraphObject,"mouseOver"),this.jt().qr=t,this.t("mouseOver",i,t))}get mouseHover(){return this.S!==null?this.S.Hr:null}set mouseHover(t){const i=this.mouseHover;i!==t&&(t!==null&&U.C(t,GraphObject,"mouseHover"),this.jt().Hr=t,this.t("mouseHover",i,t))}get mouseHold(){return this.S!==null?this.S.vr:null}set mouseHold(t){const i=this.mouseHold;i!==t&&(t!==null&&U.C(t,GraphObject,"mouseHold"),this.jt().vr=t,this.t("mouseHold",i,t))}get mouseDragEnter(){return this.S!==null?this.S.yp:null}set mouseDragEnter(t){const i=this.mouseDragEnter;i!==t&&(t!==null&&U.C(t,GraphObject,"mouseDragEnter"),this.jt().yp=t,this.t("mouseDragEnter",i,t))}get mouseDragLeave(){return this.S!==null?this.S.wp:null}set mouseDragLeave(t){const i=this.mouseDragLeave;i!==t&&(t!==null&&U.C(t,GraphObject,"mouseDragLeave"),this.jt().wp=t,this.t("mouseDragLeave",i,t))}get mouseDrop(){return this.S!==null?this.S.Wr:null}set mouseDrop(t){const i=this.mouseDrop;i!==t&&(t!==null&&U.C(t,GraphObject,"mouseDrop"),this.jt().Wr=t,this.t("mouseDrop",i,t))}get actionDown(){return this.S!==null?this.S.xp:null}set actionDown(t){const i=this.actionDown;i!==t&&(t!==null&&U.C(t,GraphObject,"actionDown"),this.jt().xp=t,this.t("actionDown",i,t))}get actionMove(){return this.S!==null?this.S.bp:null}set actionMove(t){const i=this.actionMove;i!==t&&(t!==null&&U.C(t,GraphObject,"actionMove"),this.jt().bp=t,this.t("actionMove",i,t))}get actionUp(){return this.S!==null?this.S.Sp:null}set actionUp(t){const i=this.actionUp;i!==t&&(t!==null&&U.C(t,GraphObject,"actionUp"),this.jt().Sp=t,this.t("actionUp",i,t))}get actionCancel(){return this.S!==null?this.S.kp:null}set actionCancel(t){const i=this.actionCancel;i!==t&&(t!==null&&U.C(t,GraphObject,"actionCancel"),this.jt().kp=t,this.t("actionCancel",i,t))}get toolTip(){return this.S!==null?this.S.$r:null}set toolTip(t){const i=this.toolTip;i!==t&&(Debug&&t!==null&&!(t instanceof Adornment||t instanceof HTMLInfo)&&U.n("GraphObject.toolTip must be an Adornment or HTMLInfo."),this.jt().$r=t,this.t("toolTip",i,t))}get contextMenu(){return this.S!==null?this.S.Zr:null}set contextMenu(t){const i=this.contextMenu;i!==t&&(Debug&&!(t instanceof Adornment||t instanceof HTMLInfo)&&U.n("GraphObject.contextMenu must be an Adornment or HTMLInfo."),this.jt().Zr=t,this.t("contextMenu",i,t))}findBindingPanel(){let t=this instanceof Panel?this:this.panel;for(;t!==null;){if(t.YN())return t;t=t.panel}return null}bind(t,i,e,s){return this.Ac(t,i,e,s),this}bindTwoWay(t,i,e,s){return this.Ac(t,i,e,s).makeTwoWay(),this}bindModel(t,i,e,s){return this.Ac(t,i,e,s).ofModel(),this}bindObject(t,i,e,s,n){return this.Ac(t,i,e,s).ofObject(n),this}theme(t,i,e,s,n){return this.Ih(t,i,e,s,n),this}themeData(t,i,e,s,n){return this.Ih(t,i,e,s,n).ofData(),this}themeObject(t,i,e,s,n,o){return this.Ih(t,i,e,s,n).ofObject(o),this}themeModel(t,i,e,s,n){return this.Ih(t,i,e,s,n).ofModel(),this}Ac(t,i,e,s){let n=null;return typeof t=="string"?n=new Binding(t,i,e,s):n=t,this.Pp(n),n}Ih(t,i,e,s,n){let o=null;return typeof t=="string"?o=new ThemeBinding(t,i,e,s,n):o=t,this.Pp(o),o}Pp(t){t.Re=this;const i=this.findBindingPanel();i!==null&&i.cD()&&U.n("Cannot add a Binding to a template that has already been copied: "+t),this.Ei===null&&(this.Ei=new List),this.Ei.add(t)}set(t){if(!t)return this;if(Debug)for(const i in t)(i.startsWith("_")||i.indexOf(".")!==-1)&&U.n("Property with underscore or period passed to GraphObject.set. Did you mean to use GraphObject.attach?");return Object.assign(this,t),this}attach(t){return GraphObject.KN(this,t),this}apply(t,...i){return t.apply(this,[this,...i]),this}setProperties(t){return Diagram.R0(this,t),this}static make(t,...i){let e=arguments,s=null,n=null;if(U.ht(t))n=t;else if(typeof t=="string"){const r=GraphObject.jb.get(t);U.ht(r)?(e=Array.prototype.slice.call(e),s=r(e),U.it(s)||U.n('GraphObject.make invoked object builder "'+t+'", but it did not return an Object')):n=root.go[t]}s===null&&((n==null||!n.constructor)&&U.n("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.N2(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,a)=>{if(h instanceof Panel){const f=h.findObject("ButtonBorder");if(f!==null)if(h._buttonFillNormal===void 0&&(h._buttonFillNormal=f.fill),a){let c=null;h.layer!==null&&h.diagram!==null&&h.isVisibleObject()&&(c=h.layer.findObjectAt(h.diagram.lastInput.documentPoint)),c===h||c!==null&&c.isContainedBy(h)?f.fill=h._buttonFillOver:f.fill=h._buttonFillNormal}else f.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,a,f)=>{if(!a.isEnabledObject()||!(a instanceof Panel))return;const c=a.findObject("ButtonBorder");c instanceof Shape&&(a._buttonFillNormal===void 0&&(a._buttonFillNormal=c.fill),c.fill=a._buttonFillOver,a._buttonStrokeNormal===void 0&&(a._buttonStrokeNormal=c.stroke),c.stroke=a._buttonStrokeOver)},l.mouseLeave=(h,a,f)=>{if(!a.isEnabledObject()||!(a instanceof Panel))return;const c=a.findObject("ButtonBorder");c instanceof Shape&&(a._buttonFillNormal!==void 0&&(c.fill=a._buttonFillNormal),a._buttonStrokeNormal!==void 0&&(c.stroke=a._buttonStrokeNormal))},l}),GraphObject.defineBuilder("TreeExpanderButton",w=>{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.Au}).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",w=>{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.Au}).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",w=>new Adornment(Panel.Auto,{isShadowed:!0,shadowColor:"rgba(0, 0, 0, .4)",shadowOffset:new Point(0,2),mouseOver:(t,i)=>{const e=t.diagram.toolManager;e.extendToolTip(e.toolTipDuration)}}).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",w=>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",w=>{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",w=>{const t=GraphObject.takeBuilderArgument(w,"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",w=>{const t=GraphObject.takeBuilderArgument(w),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.ht(n._doClick)&&n._doClick(s,n),o.commitTransaction("checkbox")},i}),GraphObject.defineBuilder("CheckBox",w=>{const t=GraphObject.takeBuilderArgument(w),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}),GraphObject.defineBuilder("AutoRepeatButton",w=>{const t=GraphObject.takeBuilderArgument(w,50,r=>typeof r=="number"),i=GraphObject.takeBuilderArgument(w,500,r=>typeof r=="number");function e(r,l){n(r,l),l.click&&(l.Fd=U.pn(()=>s(r,l),i))}function s(r,l){l.Fd&&U.Nf(l.Fd),l.click&&(l.Fd=U.pn(()=>{l.click&&(l.click(r,l),s(r,l))},t))}function n(r,l){l.Fd&&(U.Nf(l.Fd),l.Fd=void 0)}const o=GraphObject.build("Button");return o.actionDown=(r,l)=>e(r,l),o.actionUp=(r,l)=>n(r,l),o.actionCancel=(r,l)=>n(r,l),o}),GraphObject.defineBuilder("ToggleSwitch",function(w){const t=GraphObject.takeBuilderArgument(w);t||U.n("ToggleSwitch must be data-bound to a property name, not: "+t);const i=GraphObject.takeBuilderArgument(w,!1,a=>typeof a=="boolean"),e="gray",s="transparent",n="white",h=new Panel("Auto",{width:i?15:28,height:i?28:15}).attach({_buttonFillOff:e,_buttonBorderOff:s,_buttonIconFillOff:n,_buttonFillOn:"green",_buttonBorderOn:"transparent",_buttonIconFillOn:"white"}).add(new Shape("Capsule",{name:"ButtonBorder",fill:e,stroke:s,strokeWidth:1}).bind("fill",t,(a,f)=>a?f.panel._buttonFillOn:f.panel._buttonFillOff).bind("stroke",t,(a,f)=>a?f.panel._buttonBorderOn:f.panel._buttonBorderOff)).add(new Shape("Circle",{name:"ButtonIcon",width:11,height:11,fill:n,stroke:null,alignment:i?Spot.Bottom:Spot.Left}).bind("fill",t,(a,f)=>a?f.panel._buttonIconFillOn:f.panel._buttonIconFillOff).bind("alignment",t,a=>a?i?Spot.Top:Spot.Right:i?Spot.Bottom:Spot.Left));return h.click=function(a,f){if(!f.isEnabledObject())return;const c=a.diagram;if(c===null||c.isReadOnly||t!==""&&c.model.isReadOnly)return;a.handled=!0;const u=f.findBindingPanel();u!==null&&(c.startTransaction("toggle switch"),c.model.set(u.data,t,!u.data[t]),typeof f._doClick=="function"&&f._doClick(a,f),c.commitTransaction("toggle switch"))},h}),GraphObject.defineBuilder("Toggle",function(w){const t=GraphObject.takeBuilderArgument(w),i=GraphObject.build("ToggleSwitch",{name:"Button"},t),e=new Panel("Horizontal",{cursor:i.cursor,margin:1,mouseEnter:i.mouseEnter,mouseLeave:i.mouseLeave,click:i.click}).attach({_buttonClick:i.click}).add(i);return i.mouseEnter=null,i.mouseLeave=null,i.click=null,e});class GraphObjectTemplateSettings{wi;At;ho;Ei;ao;Os;Xl;Kr;Ur;Gr;jr;Jr;qr;Hr;vr;yp;wp;Wr;xp;bp;Sp;kp;$r;Zr;ep;cp;Rs;Dr;Fr;uo;fp;ap;Lr;tp;Mp;Np;constructor(){this.wi=!1,this.At="",this.ho=-1,this.Ei=null,this.ao=null,this.Os=null,this.Xl="",this.Kr=null,this.Ur=null,this.Gr=null,this.jr=null,this.Jr=null,this.qr=null,this.Hr=null,this.vr=null,this.yp=null,this.wp=null,this.Wr=null,this.xp=null,this.bp=null,this.Sp=null,this.kp=null,this.$r=null,this.Zr=null,this.ep=null,this.cp=null,this.Rs=null,this.Dr=Size.sa,this.Fr=Size.ix,this.uo=1,this.fp=1,this.ap=1,this.Lr=0,this.tp=null,this.Mp=null,this.Np="category"}copy(){const t=new GraphObjectTemplateSettings;return t.At=this.At,t.ho=this.ho,t.Ei=this.Ei,t.Os=this.Os,t.Xl=this.Xl,t.Kr=this.Kr,t.Ur=this.Ur,t.Gr=this.Gr,t.jr=this.jr,t.Jr=this.Jr,t.qr=this.qr,t.Hr=this.Hr,t.vr=this.vr,t.yp=this.yp,t.wp=this.wp,t.Wr=this.Wr,t.xp=this.xp,t.bp=this.bp,t.Sp=this.Sp,t.kp=this.kp,t.$r=this.$r,t.Zr=this.Zr,t.ep=this.ep,t.cp=this.cp,t.Rs=this.Rs,t.Dr=this.Dr.T(),t.Fr=this.Fr.T(),t.uo=this.uo,t.fp=this.fp,t.ap=this.ap,t.Lr=this.Lr,t.tp=this.tp,t.Mp=this.Mp,t.Np=this.Np,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=G.Yi(t),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 a=t*Math.PI/180;s=Math.cos(a),n=Math.sin(a)}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{Nt;ni;ol;wd;UN;constructor(t,i,e){const s=i===void 0?root.document:i;this.ol=s,this.UN="http://www.w3.org/2000/svg";const n="http://www.w3.org/2000/xmlns/";s!==void 0&&(this.Nt=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.Nt.setAttributeNS(n,"xmlns",this.UN),this.Nt.setAttributeNS(n,"xmlns:xlink","http://www.w3.org/1999/xlink")),this.wd=null,this.ni=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.Nt.setAttributeNS(null,"width",e+"px"),this.Nt.setAttributeNS(null,"height",s+"px"),this.Nt.setAttributeNS(null,"viewBox","0 0 "+e+" "+s),this.ni.GN.firstElementChild.setAttributeNS(null,"width",e+"px"),this.ni.GN.firstElementChild.setAttributeNS(null,"height",s+"px"),!0):!1}makeElement(t,i,e){const s=this.ol.createElementNS(this.UN,t);if(U.it(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.Nt.getBoundingClientRect()}focus(){this.Nt.focus()}get width(){return parseInt(this.Nt.getAttribute("width")||"1")}set width(t){this.Nt.setAttribute("width",t+"px")}get height(){return parseInt(this.Nt.getAttribute("height")||"1")}set height(t){this.Nt.setAttribute("height",t+"px")}dispose(){this.ol=null}get style(){return this.Nt.style}}class SVGContext{Tc;Lc;In;Bi;ts;fillStyle;font;globalAlpha;lineCap;lineDashOffset;lineJoin;lineWidth;miterLimit;shadowBlur;shadowColor;shadowOffsetX;shadowOffsetY;strokeStyle;textAlign;imageSmoothingEnabled;clipInsteadOfFill;lastCreatedElement;Dc;Fc;surface;svg;GN;uD;$b;Qo;Rh;Ha;currentElement;clipPathGroup;diagramGroup;lastDrawnPart;currentPath;outerGroup;pathAttributes;fl;Br;filter;letterSpacing;wordSpacing;partClipRect;constructor(t,i){if(this.surface=t,this.svg=t.Nt,this.Dc=[],this.Fc=[],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.fl=!1,this.strokeStyle="#000000",this.textAlign="start",this.clipInsteadOfFill=!1,this.Tc=0,this.Lc=0,this.In=0,this.lastCreatedElement=null,this.currentElement=null,this.Bi=[],this.pathAttributes={},this.$b=!1,this.Qo=null,this.Rh=0,this.uD={},this.Br=!!i,this.filter="",this.partClipRect=null,this.ts=new STransform,this.letterSpacing="0px",this.wordSpacing="0px",t.ol===null||t.ol===void 0)return;this.clipPathGroup=this.newGroup2(),this.diagramGroup=this.newGroup2("gojs-diagram"),this.lastDrawnPart=null,this.currentPath=null;const e=GSet._w++,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.GN=s,this.svg.appendChild(this.clipPathGroup),this.clipPathGroup.appendChild(this.diagramGroup),this.svg.appendChild(s),this.clipPathGroup.setAttributeNS(null,"clip-path","url(#mainClip"+e+")")}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,a=1e-6,f=h-a,c=e*Math.cos(s),u=e*Math.sin(s),d=t+c,m=i+u,g=o?0:1;let p=o?s-n:n-s;(Math.abs(r-d)>a||Math.abs(l-m)>a)&&this.Bi.push(["L",d,+m]),p<0&&(p=p%h+h),p>f?(this.Bi.push(["A",e,e,0,1,g,t-c,i-u]),this.Bi.push(["A",e,e,0,1,g,d,m])):p>a&&this.Bi.push(["A",e,e,0,+(p>=Math.PI),g,t+e*Math.cos(n),i+e*Math.sin(n)])}beginPath(){this.Bi=[],this.pathAttributes={stroke:"none",fill:"none"}}endPath(t){this.CE(this.Bi,this.ts,t||0)}bezierCurveTo(t,i,e,s,n,o){this.Bi.push(["C",t,i,e,s,n,o])}clearRect(t,i,e,s){}clip(){this.pathAttributes.clipPath=!0}closePath(){this.Bi.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.uD;if(s[e])return"url(#"+s[e]+")";const n="PATTERN"+GSet._w++,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,a=l/s;(n!==0||o!==0)&&this.ts.translate(n,o),(h!==1||a!==1)&&this.ts.scale(h,a),(t!==0||i!==0)&&this.ts.translate(-t,-i)}drawImage(t,i,e,s,n,o,r,l,h){let a="",f=t.width,c=t.height;typeof t.toDataURL=="function"?t.toDataURL():(a=t.getAttribute("src"),f=t.naturalWidth,c=t.naturalHeight),s===void 0&&(o=i,r=e,l=s=f,h=n=c),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:f||s,height:c||n,href:a};!G.q(s,l)||!G.q(n,h)?u.preserveAspectRatio="none":a.toLowerCase().indexOf(".svg")===-1&&a.toLowerCase().indexOf("data:image/svg")===-1&&(u.preserveAspectRatio="xMidYMid slice"),(i!==0||e!==0||s!==f||n!==c)&&(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.ts),this.Id(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.Nh=e}fillRect(t,i,e,s){this.addRect("fill",[t,i,e,s],this.ts)}fillBackground(t,i,e,s){const n={x:t,y:i,width:e,height:s};this.processCommon("fill",n,this.ts),this.setFill(n),this.svg.prepend(this.makeElement("rect",n))}fillText(t,i,e){this.addText("fill",[t,i,e],this.ts)}lineTo(t,i){this.Bi.push(["L",t,i])}moveTo(t,i){this.Bi.push(["M",t,i])}quadraticCurveTo(t,i,e,s){this.Bi.push(["Q",t,i,e,s])}rect(t,i,e,s){this.Bi.push(["M",t,i],["L",t+e,i],["L",t+e,i+s],["L",t,i+s],["z"])}restore(){this.ts=this.Dc.pop(),this.Bi=this.Dc.pop();const t=this.Dc.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,this.letterSpacing=t.letterSpacing,this.wordSpacing=t.wordSpacing}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.Dc.push(t);const i=[];for(let e=0;el.offset>h.offset?1:-1),r=o.length;for(let l=0;l1&&this.Fc[this.Fc.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.Id("path",n)}AE(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.Tc=t,this.Lc=i,this.In=e}shadowsOff(){this.fl=!1,this.shadowOffsetX=0,this.shadowOffsetY=0,this.shadowBlur=0}shadowsOn(){this.fl=!0,this.shadowOffsetX=this.Tc,this.shadowOffsetY=this.Lc,this.shadowBlur=this.In}enableDash(t,i){const e=this.B;e.setLineDash!==void 0&&(e.setLineDash(t),e.lineDashOffset=i)}disableDash(){const t=this.B;t.setLineDash!==void 0&&(t.setLineDash(CanvasSurfaceContext.EmptyArray),t.lineDashOffset=0)}clearContextCache(t){t&&(this.Zb=""),this.Qb="",this._b=""}removePartFromView(t){}static EmptyArray=Object.freeze([])}var BrushType=(w=>(w[w.Solid=1]="Solid",w[w.Linear=2]="Linear",w[w.Radial=3]="Radial",w[w.Pattern=4]="Pattern",w))(BrushType||{}),ColorSpace=(w=>(w[w.Lab=1]="Lab",w[w.HSL=2]="HSL",w[w.Oklch=3]="Oklch",w))(ColorSpace||{});class ColorNumbers{n0;n1;n2;n3;constructor(){this.n0=0,this.n1=0,this.n2=0,this.n3=0}}class Brush{p;tt;va;ci;Ds;Cp;Ap;_o;Tp;Dn;Mc;vb;constructor(t,i){if(GSet._i(this),this.p=!1,t===void 0)this.tt=1,this.va="black";else if(typeof t=="string"){const s=U.ea(BrushType,t);s!==null?(this.tt=s,this.va="black"):(this.tt=1,Debug&&!Brush.isValidColor(t)&&U.n('Color "'+t+'" is not a valid color string for Brush constructor'),this.va=t)}else Object.keys(BrushType).hasOwnProperty(t)?(Debug&&U.W(t,BrushType,"BrushType"),this.tt=t,this.va="black"):typeof t=="object"&&(this.tt=1,i=t);const e=this.tt;if(e===2?(this.ci=Spot.TopCenter,this.Ds=Spot.BottomCenter):e===3?(this.ci=Spot.Center,this.Ds=Spot.Center):(this.ci=Spot.None,this.Ds=Spot.None),this.Cp=0,this.Ap=NaN,this._o=null,this.Tp=null,this.Dn=null,this.Mc=0,this.vb=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.tt=this.tt,t.va=this.va,t.ci=this.ci.T(),t.Ds=this.Ds.T(),t.Cp=this.Cp,t.Ap=this.Ap,this._o!==null&&(t._o=this._o.copy()),t.Tp=this.Tp,t}k(){return this.p=!0,this._o!==null&&this._o.k(),this}gi(t){t in BrushType?this.type=t:U.wr(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.p&&U.D(this),(typeof t!="number"||!isFinite(t)||t>1||t<0)&&U.G(t,"0 <= loc <= 1",Brush,"addColorStop:loc"),U.i(i,"string",Brush,"addColorStop:color"),Debug&&!Brush.isValidColor(i)&&U.n('Color "'+i+'" is not a valid color string for Brush.addColorStop'),this._o===null&&(this._o=new GMap),this._o.set(t,i),this.tt===1&&(this.type=2),this.Dn=null,this}get type(){return this.tt}set type(t){this.p&&U.D(this,t),Debug&&U.W(t,BrushType,"BrushType"),this.tt=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.Dn=null}get color(){return this.va}set color(t){this.p&&U.D(this,t),Debug&&!Brush.isValidColor(t)&&U.n('Color "'+t+'" is not a valid color string for Brush.color'),this.va=t,this.Dn=null}get start(){return this.ci}set start(t){this.p&&U.D(this,t),Debug&&U.s(t,Spot,Brush,"start"),this.ci=t.T(),this.Dn=null}get end(){return this.Ds}set end(t){this.p&&U.D(this,t),Debug&&U.s(t,Spot,Brush,"end"),this.Ds=t.T(),this.Dn=null}get startRadius(){return this.Cp}set startRadius(t){this.p&&U.D(this,t),Debug&&U.r(t,Brush,"startRadius"),t<0&&U.G(t,">= zero",Brush,"startRadius"),this.Cp=t,this.Dn=null}get endRadius(){return this.Ap}set endRadius(t){this.p&&U.D(this,t),Debug&&U.r(t,Brush,"endRadius"),t<0&&U.G(t,">= zero",Brush,"endRadius"),this.Ap=t,this.Dn=null}get colorStops(){return this._o}set colorStops(t){this.p&&U.D(this,t),Debug&&U.s(t,GMap,Brush,"colorStops"),this._o=t,this.Dn=null}get pattern(){return this.Tp}set pattern(t){this.p&&U.D(this,t),this.Tp=t,this.Dn=null}static randomColor(t,i){t===void 0&&(t=128),Debug&&(U.r(t,Brush,"randomColor:min"),(t<0||t>255)&&U.G(t,"0 <= min <= 255",Brush,"randomColor:min")),i===void 0&&(i=Math.max(t,255)),Debug&&(U.r(i,Brush,"randomColor:max"),(i255)&&U.G(i,"min <= max <= 255",Brush,"randomColor:max"));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.p&&U.D(this);const e=t===void 0||typeof t!="number"?.2:t,s=i===void 0?3:i;if(this.type===1)Brush.Ko(this.color),this.color=Brush.Rd(e,s);else if((this.type===2||this.type===3)&&this.colorStops!==null){const n=this.colorStops.iterator;for(;n.next();)Brush.Ko(n.value),this.addColorStop(n.key,Brush.Rd(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.Ko(t),Brush.Rd(s,n)}static darken(t){return Brush.darkenBy(t)}darkenBy(t,i){this.p&&U.D(this);const e=t===void 0||typeof t!="number"?.2:t,s=i===void 0?3:i;if(this.type===1)Brush.Ko(this.color),this.color=Brush.Rd(-e,s);else if((this.type===2||this.type===3)&&this.colorStops!==null){const n=this.colorStops.iterator;for(;n.next();)Brush.Ko(n.value),this.addColorStop(n.key,Brush.Rd(-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.Ko(t),Brush.Rd(-s,n)}static mix(t,i,e){Brush.Ko(t);const s=Brush.v.n0,n=Brush.v.n1,o=Brush.v.n2,r=Brush.v.n3;Brush.Ko(i),e===void 0&&(e=.5);const l=Math.round((Brush.v.n0-s)*e+s),h=Math.round((Brush.v.n1-n)*e+n),a=Math.round((Brush.v.n2-o)*e+o),f=Math.round((Brush.v.n3-r)*e+r);return`rgba(${l}, ${h}, ${a}, ${f})`}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){const l=t.first();return l?Brush.isDark(l.value):!1}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.Ko(t),(299*Brush.v.n0+587*Brush.v.n1+114*Brush.v.n2)/1e3<128):!1}static Rd(t,i){switch(i){case 1:return Brush.TE(),Brush.go.n0=Math.min(100,Math.max(0,Brush.go.n0+100*t)),Brush.LE(),"rgba("+Brush.v.n0+", "+Brush.v.n1+", "+Brush.v.n2+", "+Brush.v.n3+")";case 2:return Brush.KM(),Brush.qi.n2=Math.min(100,Math.max(0,Brush.qi.n2+100*t)),"hsla("+Brush.qi.n0+", "+Brush.qi.n1+"%, "+Brush.qi.n2+"%, "+Brush.qi.n3+")";case 3:return Brush.DE(),Brush.mo.n0=Math.min(100,Math.max(0,Brush.mo.n0+100*t)),Brush.FE(),"rgba("+Brush.v.n0+", "+Brush.v.n1+", "+Brush.v.n2+", "+Brush.v.n3+")";default:U.n("Unknown color space: "+i)}}static Ko(t){Brush.Lp===!1&&(Brush.Lp=!0,Brush.ps=Diagram.isUsingDOM()?new CanvasSurface(null,void 0,{willReadFrequently:!0}).ni:null);const i=Brush.ps;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.v.n0=s[0],Brush.v.n1=s[1],Brush.v.n2=s[2],Brush.v.n3=s[3]/255}else{i.fillStyle="#FFFFFF";const s=i.fillStyle;i.fillStyle=t,i.fillStyle===s&&Debug&&U.n('Color "'+t+'" is not a valid color string for RGBA color conversion'),Brush.v.n0=0,Brush.v.n1=0,Brush.v.n2=0,Brush.v.n3=1}}static KM(){const t=Brush.v.n0/255,i=Brush.v.n1/255,e=Brush.v.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;default:r=0;break}r*=60,r<0&&(r+=360),l=o/(1-Math.abs(2*h-1))}Brush.qi.n0=Math.round(r),Brush.qi.n1=Math.round(l*100),Brush.qi.n2=Math.round(h*100),Brush.qi.n3=Brush.v.n3}static XB(){const t=Brush.qi.n0,i=Brush.qi.n1/100,e=Brush.qi.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):(s=r,n=0,o=h);const a=e-.5*r;s+=a,n+=a,o+=a,Brush.v.n0=Math.round(s*255),Brush.v.n1=Math.round(n*255),Brush.v.n2=Math.round(o*255),Brush.v.n3=Brush.qi.n3}static TE(){Brush.dD(),Brush.IE()}static LE(){Brush.RE(),Brush.gD()}static qN(t){return t/=255,t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}static HN(t){return t<=.0031308?t*12.92:1.055*Math.pow(t,1/2.4)-.055}static dD(){const t=Brush.qN(Brush.v.n0),i=Brush.qN(Brush.v.n1),e=Brush.qN(Brush.v.n2);Brush.Ot.n0=.4124564*t+.3575761*i+.1804375*e,Brush.Ot.n1=.2126729*t+.7151522*i+.072175*e,Brush.Ot.n2=.0193339*t+.119192*i+.9503041*e,Brush.Ot.n3=Brush.v.n3}static gD(){const t=3.2404542*Brush.Ot.n0+-1.5371385*Brush.Ot.n1+-.4985314*Brush.Ot.n2,i=-.969266*Brush.Ot.n0+1.8760108*Brush.Ot.n1+.041556*Brush.Ot.n2,e=.0556434*Brush.Ot.n0+-.2040259*Brush.Ot.n1+1.0572252*Brush.Ot.n2;Brush.v.n0=Brush.HN(t)*255,Brush.v.n1=Brush.HN(i)*255,Brush.v.n2=Brush.HN(e)*255,Brush.v.n3=Brush.Ot.n3,Brush.v.n0=Math.round(Brush.v.n0),Brush.v.n0>255?Brush.v.n0=255:Brush.v.n0<0&&(Brush.v.n0=0),Brush.v.n1=Math.round(Brush.v.n1),Brush.v.n1>255?Brush.v.n1=255:Brush.v.n1<0&&(Brush.v.n1=0),Brush.v.n2=Math.round(Brush.v.n2),Brush.v.n2>255?Brush.v.n2=255:Brush.v.n2<0&&(Brush.v.n2=0)}static vN=216/24389;static tS=24389/27;static Od=[95.047,100,108.883];static WN(t){return t>Brush.vN?Math.pow(t,1/3):(Brush.tS*t+16)/116}static IE(){const t=Brush.WN(Brush.Ot.n0*100/Brush.Od[0]),i=Brush.WN(Brush.Ot.n1*100/Brush.Od[1]),e=Brush.WN(Brush.Ot.n2*100/Brush.Od[2]);Brush.go.n0=116*i-16,Brush.go.n1=500*(t-i),Brush.go.n2=200*(i-e),Brush.go.n3=Brush.Ot.n3}static mD(t){const i=t*t*t;return i>Brush.vN?i:(116*t-16)/Brush.tS}static RE(){const t=(Brush.go.n0+16)/116,i=Brush.go.n1/500+t,e=t-Brush.go.n2/200;Brush.Ot.n0=Brush.Od[0]/100*Brush.mD(i),Brush.Ot.n1=Brush.Od[1]/100*(Brush.go.n0>Brush.tS*Brush.vN?Math.pow(t,3):Brush.go.n0/Brush.tS),Brush.Ot.n2=Brush.Od[2]/100*Brush.mD(e),Brush.Ot.n3=Brush.go.n3}static OE(){let t=.8190224*Brush.Ot.n0+.3619062*Brush.Ot.n1+-.1288737*Brush.Ot.n2,i=.03298366*Brush.Ot.n0+.9292868*Brush.Ot.n1+.03614466*Brush.Ot.n2,e=.04817719*Brush.Ot.n0+.2642395*Brush.Ot.n1+.6335478*Brush.Ot.n2;t=Math.cbrt(t),i=Math.cbrt(i),e=Math.cbrt(e),Brush.yi.n0=.2104542*t+.7936177*i+-.004072046*e,Brush.yi.n1=1.977998*t+-2.428592*i+.4505937*e,Brush.yi.n2=.02590403*t+.7827717*i+-.8086757*e,Brush.yi.n3=Brush.Ot.n3,Brush.yi.n0*=100}static EE(){Brush.yi.n0/=100;let t=.9999999*Brush.yi.n0+.3963377*Brush.yi.n1+.2158037*Brush.yi.n2,i=1.000000009*Brush.yi.n0+-.1055613*Brush.yi.n1+-.06385417*Brush.yi.n2,e=1.00000005*Brush.yi.n0+-.08948418*Brush.yi.n1+-1.291485*Brush.yi.n2;t=t**3,i=i**3,e=e**3,Brush.Ot.n0=1.2268798*t+-.5578149*i+.281391*e,Brush.Ot.n1=-.04057576*t+1.112286*i+-.07171106*e,Brush.Ot.n2=-.07637294*t+-.4214933*i+1.586924*e,Brush.Ot.n3=Brush.yi.n3}static BE(){const t=Math.atan2(Brush.yi.n2,Brush.yi.n1)*180/Math.PI;Brush.mo.n0=Brush.yi.n0,Brush.mo.n1=Math.sqrt(Brush.yi.n1**2+Brush.yi.n2**2),Brush.mo.n2=t>=0?t:t+360,Brush.mo.n3=Brush.yi.n3}static VE(){Brush.yi.n0=Brush.mo.n0,Brush.yi.n1=Brush.mo.n1*Math.cos(Brush.mo.n2*Math.PI/180),Brush.yi.n2=Brush.mo.n1*Math.sin(Brush.mo.n2*Math.PI/180),Brush.yi.n3=Brush.mo.n3}static DE(){Brush.dD(),Brush.OE(),Brush.BE()}static FE(){Brush.VE(),Brush.EE(),Brush.gD()}static Dd(t,i){typeof t=="string"?Debug&&!Brush.isValidColor(t)&&U.n('Color "'+t+'" is not a valid color string for '+i):t instanceof Brush||U.n("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 ps=null;static Lp=!1;static v=new ColorNumbers;static qi=new ColorNumbers;static Ot=new ColorNumbers;static go=new ColorNumbers;static yi=new ColorNumbers;static mo=new ColorNumbers}class PanelLayout{At="Base";static ms=new GMap;static Rn(t,i){i.name=t,PanelLayout.ms.set(t,i)}get name(){return this.At}set name(t){this.At=t}constructor(){}get classType(){return Panel}measure(t,i,e,s,n,o,r){}measureElement(t,i,e,s,n){t.gt(i,e,s,n)}arrange(t,i,e){}arrangeElement(t,i,e,s,n,o){t.Ut(i,e,s,n,o)}remeasureObject(t){t.Nc()}vi(t,i,e){}}class PanelLayoutPosition extends PanelLayout{constructor(){super()}measure(t,i,e,s,n,o,r){const l=s.length,h=t.tr();for(let a=0;a0&&(M=Math.max(Math.abs(b.x*o+b.offsetX-(P.x*o+P.offsetX))-g,0)),r>0&&(N=Math.max(Math.abs(b.y*r+b.offsetY-(P.y*r+P.offsetY))-g,0));const T=Size.a();T.e(0,0);const L=t.tr();for(let I=0;I1,lt=st.columnSpan>1;(ut||lt)&&!(qy&&(M=Math.max(y-pt,0)),S.Vi=S.Vi+M,S.actual=S.$+M,y=Math.max(y-(M+(yt?pt:0)),0)}if(st.columnSpan===1&&(N===0||N===4)){S=t.getColumnDefinition(v);const pt=S.computeEffectiveSpacing(),yt=S.$===0;M=Math.max(gt-S.actual,0),M+(yt?pt:0)>p&&(M=Math.max(p-pt,0)),S.Vi=S.Vi+M,S.actual=S.$+M,p=Math.max(p-(M+(yt?pt:0)),0)}(ut||lt)&&st.Nc()}}}U.et(c);let L=0,D=0;l=t.columnCount;for(let q=0;q=t.rowCount);_++){if(S=t.getRowDefinition(E.row+_),M=0,N===2||N===4){if(S.$===0)continue;M=Math.max(S.minimum,S.$===0?S.maximum:Math.min(S.$,S.maximum))}else M=Math.max(S.minimum,isNaN(S.Me)?S.maximum:Math.min(S.Me,S.maximum));B.height+=M,it+=S.minimum}for(let _=1;_=t.columnCount);_++){if(S=t.getColumnDefinition(E.column+_),M=0,N===2||N===5){if(S.$===0)continue;M=Math.max(S.minimum,S.$===0?S.maximum:Math.min(S.$,S.maximum))}else M=Math.max(S.minimum,isNaN(S.Me)?S.maximum:Math.min(S.Me,S.maximum));B.width+=M,nt+=S.minimum}K.width+=B.width,K.height+=B.height;const et=E.margin,st=et.right+et.left,ut=et.top+et.bottom;E.gt(K.width,K.height,nt,it);const lt=E.measuredBounds,at=Math.max(lt.width+st,0),ot=Math.max(lt.height+ut,0);let rt=0;for(let _=0;_=t.rowCount);_++)S=t.getRowDefinition(E.row+_),rt+=S.total||0;if(rt=t.rowCount);ct++){S=t.getRowDefinition(E.row+ct);const gt=S.$||0,mt=ht(E,S,dt);Debug&&typeof mt!="number"&&U.n(E+" spanAllocation does not return a number: "+mt),S.actual=Math.min(S.maximum,gt+mt),S.$!==gt&&(_-=S.$-gt)}}for(;_>0&&S!==void 0;){const ht=S.$||0;if(isNaN(S.height)&&S.maximum>ht&&(S.actual=Math.min(S.maximum,ht+_),S.$!==ht&&(_-=S.$-ht)),S.index===0)break;S=t.getRowDefinition(S.index-1)}}let ft=0;for(let _=0;_=t.columnCount);_++)S=t.getColumnDefinition(E.column+_),ft+=S.total||0;if(ft=t.columnCount);ct++){S=t.getColumnDefinition(E.column+ct);const gt=S.$||0,mt=ht(E,S,dt);Debug&&typeof mt!="number"&&U.n(E+" spanAllocation does not return a number: "+mt),S.actual=Math.min(S.maximum,gt+mt),S.$!==gt&&(_-=S.$-gt)}}for(;_>0&&S!==void 0;){const ht=S.$||0;if(isNaN(S.width)&&S.maximum>ht&&(S.actual=Math.min(S.maximum,ht+_),S.$!==ht&&(_-=S.$-ht)),S.index===0)break;S=t.getColumnDefinition(S.index-1)}}}U.et(u),Size.o(B),Size.o(K),Y!==void 0&&U.et(Y),z!==void 0&&U.et(z);let H=0,W=0;const j=t.desiredSize,Z=t.maxSize;N=t.en(!0),L=0,D=0;let V=0,$=0;l=t.columnCount;for(let q=0;q0){for(;p!==f&&(u[p]===void 0||u[p].$===0);)p++;p=Math.max(Math.min(p,f-1),0),m=-u[p].position}let y=Math.min(t.leftIndex,c-1);if(d.length>0){for(;y!==c&&(d[y]===void 0||d[y].$===0);)y++;y=Math.max(Math.min(y,c-1),0),g=-d[y].position}let x=0,b=0;for(;x!==f&&u[x]===void 0;)x++;for(;b!==f&&d[b]===void 0;)b++;const S=t.part;let k=t.getRowDefinition(x),P=t.getColumnDefinition(b);for(let C=0;C=t.rowCount);ot++){const rt=t.getRowDefinition(C+ot);rt.$!==0&&(A.height+=rt.total)}for(let ot=1;ot=t.columnCount);ot++){const rt=t.getColumnDefinition(N+ot);rt.$!==0&&(A.width+=rt.total)}const O=T.$+A.width,X=M.$+A.height;let K=h,B=a;const Y=O,z=X,H=h,W=a;let j=O,Z=X;h+O>e.width&&(j=Math.max(e.width-h,0)),a+X>e.height&&(Z=Math.max(e.height-a,0));let V=R.alignment,$=0,J=0,tt=0,q=0;if(V.isDefault()){V=t.defaultAlignment,V.isSpot()||(V=Spot.Center),$=V.x,J=V.y,tt=V.offsetX,q=V.offsetY;const ot=T.alignment,rt=M.alignment;ot.isSpot()&&($=ot.x,tt=ot.offsetX),rt.isSpot()&&(J=rt.y,q=rt.offsetY)}else $=V.x,J=V.y,tt=V.offsetX,q=V.offsetY;(isNaN($)||isNaN(J))&&($=.5,J=.5,tt=0,q=0);let E=I.width,v=I.height;const Q=R.margin,nt=Q.left+Q.right,it=Q.top+Q.bottom,et=R.sp(M,T,!1);isNaN(R.desiredSize.width)&&(et===2||et===5)&&(E=Math.max(O-nt,0)),isNaN(R.desiredSize.height)&&(et===2||et===4)&&(v=Math.max(X-it,0));const st=R.maxSize,ut=R.minSize;E=Math.min(st.width,E),v=Math.min(st.height,v),E=Math.max(ut.width,E),v=Math.max(ut.height,v);const lt=E+nt,at=v+it;K+=Y*$-lt*$+tt+Q.left,B+=z*J-at*J+q+Q.top,R.visible&&(Rect.contains(H,W,j,Z,K,B,I.width,I.height)?R.Ut(K,B,E,v):R.Ut(K,B,E,v,new Rect(H,W,j,Z)))}}}Size.o(A);for(let C=0;C0&&(S.figure==="LineV"||S.figure==="LineH")){if(i.lineWidth=S.strokeWidth,t.Nn(i,S.stroke,!1,!1,l,h),i.beginPath(),S.figure==="LineV"){const D=Math.floor((m-o)/o);for(let F=D;F<=D+c;F++){const R=F*o+m;0<=R&&R<=a&&this.eS(F,k,A,N)&&(i.moveTo(R,0),i.lineTo(R,f))}}else if(S.figure==="LineH"){const D=Math.floor((g-r)/r);for(let F=D;F<=D+u;F++){const R=F*r+g;0<=R&&R<=f&&this.eS(F,k,A,N)&&(i.moveTo(0,R),i.lineTo(a,R))}}i.stroke(),i.endPath()}else if(S.fill!==null){if(t.Nn(i,S.fill,!0,!1,l,h),S.figure==="BarV"){let D=S.width;isNaN(D)&&(D=o);const F=Math.floor((m-o)/o);for(let R=F;R<=F+c;R++){const I=R*o+m;0<=I+D&&I<=a&&this.eS(R,k,A,N)&&i.fillRect(I,0,D,f)}}else if(S.figure==="BarH"){let D=S.height;isNaN(D)&&(D=r);const F=Math.floor((g-r)/r);for(let R=F;R<=F+u;R++){const I=R*r+g;0<=I+D&&I<=f&&this.eS(R,k,A,N)&&i.fillRect(0,I,a,D)}}}T&&i.disableDash(),C!==1&&(i.globalAlpha=M)}}eS(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.Ni.Dp=i}ZN(t){return t==="LineV"||t==="BarV"}zE(t){let i=1,e=1;const s=t.O.h,n=s.length;for(let l=0;l=g){const V=Point.a();f.QN(V),O=f.midAngle,L!==0&&(I=f.computeAngle(A,L,O),A.vt=I,A.ke(!0),A.co(!0)),F=V.x-u.x,R=V.y-u.y,Point.o(V)}else{let V,$,J=0;if(M>=0?(V=m.elt(M),$=M0?m.elt(J-1):V),V.equalsApprox($)){let tt,q;M>=0?(tt=M>0?m.elt(M-1):V,q=M1?m.elt(J-2):$);const E=tt.distanceSquaredPoint(V),v=$.distanceSquaredPoint(q);E>v+10?O=M>=0?tt.directionPoint(V):V.directionPoint(tt):v>E+10?O=M>=0?$.directionPoint(q):q.directionPoint($):O=M>=0?tt.directionPoint(q):q.directionPoint(tt)}else O=M>=0?V.directionPoint($):$.directionPoint(V);L!==0&&(I=f.computeAngle(A,L,O),A.vt=I,A.ke(!0),A.co(!0)),F=V.x+($.x-V.x)*N-u.x,R=V.y+($.y-V.y)*N-u.y}A.gt(1/0,1/0,0,0),C=A.measuredBounds;const X=A.naturalBounds;let K=0;A instanceof Shape&&(K=A.strokeWidth);const B=X.width+K,Y=X.height+K;b.Ki(),b.Hs(-C.x,-C.y),b.lt(A.scale,A.scale),b.Ns(L===0?A.angle:O,B/2,Y/2),(L===22||L===26)&&b.Ns(90,B/2,Y/2),(L===23||L===27)&&b.Ns(-90,B/2,Y/2),L===28&&(O>45&&O<135||O>225&&O<315)&&b.Ns(-O,B/2,Y/2);const z=new Rect(0,0,B,Y);S.setRectSpot(z,T),b.St(S);const H=-S.x+K/2*A.scale,W=-S.y+K/2*A.scale;k.c(D);const j=isNaN(D.x),Z=isNaN(D.y);if(j||Z){const V=B/2+Link.sS,$=Y/2+Link.sS,J=O>=45&&O<=135,tt=O>=225&&O<=315;L===0&&(J||tt)?(k.x=Z?V:D.y,k.y=j?$:D.x,J?M>=0||isNaN(M)&&N<.5||j&&(k.y=-$):tt&&((M>=0||isNaN(M)&&N<.5)&&j&&(k.y=-$),Z&&(k.x=-V))):(j&&(M>=0||isNaN(M)&&N<.5?k.x=V:k.x=-V),Z&&(k.y=-$),k.rotate(O))}else k.rotate(O);F+=k.x,R+=k.y,z.e(F+H,R+W,C.width,C.height),x.push(z),d.unionRect(z)}if(h!==null){const P=h.labelNodes;for(;P.next();)P.value.gt(1/0,1/0)}t.ir=d,t.position.e(u.x+d.x,u.y+d.y),n.$n(d.width||0,d.height||0),Transform.o(b),Point.o(S),Point.o(k)}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.Ic;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.KE(d,f,a)}}o!==null?o.Ed(!1):n.Ed(!1);const c=t.yD(Point.a());t.location.e(t.position.x+c.x,t.position.y+c.y),Point.o(c)}measureLinkPath(t,i,e,s){if(s.vo()===!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.lt,t instanceof Link&&t.xt!==null){const o=t.geometry.bounds;s.fo(o.x-n/2,o.y-n/2,o.width+n,o.height+n)}else if(t instanceof Adornment&&t.adornedPart.xt!==null){const o=t.adornedPart.xt.bounds;s.fo(o.x-n/2,o.y-n/2,o.width+n,o.height+n)}else s.fo(-(n/2),-(n/2),i+n,e+n);s.UE(),s.ke(!1)}}PanelLayout.Rn("Link",new PanelLayoutLink);class PanelLayoutGraduated extends PanelLayout{constructor(){super()}measure(t,i,e,s,n,o,r){const l=t.findMainElement();if(!(l instanceof Shape))return;t.ss=[];const h=l.margin,a=h.right+h.left,f=h.top+h.bottom;l.gt(i,e,o,r);const c=l.measuredBounds,u=c.width,d=c.height,m=Math.max(u+a,0),g=Math.max(d+f,0),p=new Rect(-h.left,-h.top,m,g);t.ss.push(p),n.c(p),this.determineGraduatedMarks(t,l);const y=t.Es;if(y===null)return;const x=s.length;for(let b=0;b45&&c<135||c>225&&c<315)&&k.Ns(-c,b/2,S/2);const P=Rect.U(0,0,b,S),A=Point.a();A.setRectSpot(P,o),k.St(A);const C=-A.x,M=-A.y,N=Point.a();N.c(l),isNaN(N.x)&&(N.x=b/2+3),isNaN(N.y)&&(N.y=-(S/2+3)),N.rotate(c),a+=N.x+C,f+=N.y+M;const T=new Rect(a,f,y.width,y.height),L=new Rect(y.x,y.y,y.width,y.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=L,p.naturalBounds=D,g===0?h.c(T):h.unionRect(T),Point.o(N),Point.o(A),Rect.o(P),Transform.o(k)}t.ss!==null&&t.ss.push(h),s.ai(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,a=0;const f=U.at();for(let x=0;xt.graduatedMin+M){const F=Math.floor((N-t.graduatedMin)/M);N-=F*M}const T=c[x],L=N,D=t.graduatedMax*1e-6;for(let F=1;N<=t.graduatedMax+D;F++){if(this.qE(t,N-t.graduatedTickBase,T)&&(N>t.graduatedMax&&(N=t.graduatedMax),(b.graduatedSkip===null||b instanceof TextBlock&&!b.graduatedSkip(N,b)||b instanceof Shape&&!b.graduatedSkip(N,b))&&(m=(N-t.graduatedMin)*r/t.graduatedRange,m>r&&(m=r),g<=m&&m<=p))){let R=f[A][C],I=o[A][C];for(;AP&&C.4995)return t;let o=t;if(i<.5?n>0?o=s[n-1]:G.q(e[0],e[e.length-2])&&G.q(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}GE(t){if(t.ys===null){const i=[],e=t.O.h,s=e.length;for(let n=0;nl&&r.push(f)}}t.ys=i}return t.ys}qE(t,i,e){const s=e.length;for(let n=0;n-l)return!1}return!0}vi(t,i,e){const s=e.Sa;e.Sa=!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.vi(i,e);let a=t.getDocumentScale()*e.scale;a<=0&&(a=1);const f=h.actualBounds,c=t.O.h,u=t.Es,d=c.length;for(let m=0;m(w[w.Uniform=6]="Uniform",w[w.UniformToFill=7]="UniformToFill",w))(ViewboxStretch||{});class Panel extends GraphObject{tt;O;si;Bd;io;cl;po;ir;tC;V;Vd;ft;Ni;oi;zd;Eh;nn;constructor(t,i){if(super(),t===void 0)this.tt=Panel.Position;else if(typeof t=="string"){const e=PanelLayout.ms.get(t);e!==null?this.tt=e:U.n("PanelLayout not loaded: "+t)}else t instanceof PanelLayout?this.tt=t:(this.tt=Panel.Position,t&&(i=t));this.l|=4194304|(this.tt===Panel.Grid?1048576:0),this.O=new List,this.si=Margin.hm,this.Bd=Spot.Default,this.io=1,this.cl=null,this.po="",this.ir=new Rect(NaN,NaN,NaN,NaN),this.tC=null,this.V=null,this.Vd=6,this.Ni=null,this.ft=null,this.oi=null,this.zd=NaN,this.Eh=null,this.nn=null,i&&Object.assign(this,i)}cloneProtected(t){super.cloneProtected(t),t.tt=this.tt,t.si=this.si.T(),t.Bd=this.Bd.T(),t.io=this.io,t.po=this.po,t.ir.c(this.ir),this.V!==null&&(t.V=this.V.copy(t)),t.Vd=this.Vd,this.ft!==null&&(t.ft=this.ft.copy()),this.Ni!==null&&(t.Ni=this.Ni.copy()),t.oi=this.oi,t.zd=this.zd,t.Eh=this.Eh}$o(t){super.$o(t),t.O=this.O;const i=t.O.h,e=i.length;for(let s=0;s= 0",Panel,"padding"),t=new Margin(t)):(U.s(t,Margin,Panel,"padding"),t.left<0&&U.G(t.left,">= 0",Panel,"padding:value.left"),t.right<0&&U.G(t.right,">= 0",Panel,"padding:value.right"),t.top<0&&U.G(t.top,">= 0",Panel,"padding:value.top"),t.bottom<0&&U.G(t.bottom,">= 0",Panel,"padding:value.bottom"));const i=this.si;i.equals(t)||(t=t.T(),this.si=t,this.g(),this.t("padding",i,t))}get defaultAlignment(){return this.Bd}set defaultAlignment(t){const i=this.Bd;i.equals(t)||(Debug&&U.s(t,Spot,Panel,"defaultAlignment"),t=t.T(),this.Bd=t,this.g(),this.t("defaultAlignment",i,t))}get defaultStretch(){return this.io}set defaultStretch(t){const i=this.io;i!==t&&(Debug&&U.W(t,Stretch,"Stretch"),this.io=t,this.g(),this.t("defaultStretch",i,t))}get defaultSeparatorPadding(){return this.V!==null?this.V.Fp:Margin.hm}set defaultSeparatorPadding(t){typeof t=="number"?t=new Margin(t):Debug&&U.s(t,Margin,Panel,"defaultSeparatorPadding");const i=this.defaultSeparatorPadding;i.equals(t)||(t=t.T(),this.V===null&&(this.V=new TablePanelSettings),this.V.Fp=t,this.g(),this.t("defaultSeparatorPadding",i,t))}get defaultRowSeparatorStroke(){return this.V!==null?this.V.Ip:null}set defaultRowSeparatorStroke(t){const i=this.defaultRowSeparatorStroke;i!==t&&(t===null||typeof t=="string"||t instanceof Brush)&&(t instanceof Brush&&t.k(),this.V===null&&(this.V=new TablePanelSettings),this.V.Ip=t,this.L(),this.t("defaultRowSeparatorStroke",i,t))}get defaultRowSeparatorStrokeWidth(){return this.V!==null?this.V.Rp:1}set defaultRowSeparatorStrokeWidth(t){const i=this.defaultRowSeparatorStrokeWidth;i!==t&&isFinite(t)&&t>=0&&(this.V===null&&(this.V=new TablePanelSettings),this.V.Rp=t,this.g(),this.t("defaultRowSeparatorStrokeWidth",i,t))}get defaultRowSeparatorDashArray(){return this.V!==null?this.V.Op:null}set defaultRowSeparatorDashArray(t){const i=this.defaultRowSeparatorDashArray;if(i!==t){if(t!==null&&!Array.isArray(t)&&U.Ti(t,"Array",Panel,"defaultRowSeparatorDashArray:value"),t!==null){const e=t.length;let s=0;for(let n=0;n=0)||!isFinite(o))&&U.n("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.V===null&&(this.V=new TablePanelSettings),this.V.Op=t,this.L(),this.t("defaultRowSeparatorDashArray",i,t)}}get defaultColumnSeparatorStroke(){return this.V!==null?this.V.Ep:null}set defaultColumnSeparatorStroke(t){const i=this.defaultColumnSeparatorStroke;i!==t&&(t===null||typeof t=="string"||t instanceof Brush)&&(t instanceof Brush&&t.k(),this.V===null&&(this.V=new TablePanelSettings),this.V.Ep=t,this.L(),this.t("defaultColumnSeparatorStroke",i,t))}get defaultColumnSeparatorStrokeWidth(){return this.V!==null?this.V.Bp:1}set defaultColumnSeparatorStrokeWidth(t){const i=this.defaultColumnSeparatorStrokeWidth;i!==t&&isFinite(t)&&t>=0&&(this.V===null&&(this.V=new TablePanelSettings),this.V.Bp=t,this.g(),this.t("defaultColumnSeparatorStrokeWidth",i,t))}get defaultColumnSeparatorDashArray(){return this.V!==null?this.V.Vp:null}set defaultColumnSeparatorDashArray(t){const i=this.defaultColumnSeparatorDashArray;if(i!==t){if(t!==null&&!Array.isArray(t)&&U.Ti(t,"Array",Panel,"defaultColumnSeparatorDashArray:value"),t!==null){const e=t.length;let s=0;for(let n=0;n=0)||!isFinite(o))&&U.n("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.V===null&&(this.V=new TablePanelSettings),this.V.Vp=t,this.L(),this.t("defaultColumnSeparatorDashArray",i,t)}}get Oh(){return this.V!==null?this.V.Oh:null}set Oh(t){this.V===null&&(this.V=new TablePanelSettings),this.V.Oh=t}get viewboxStretch(){return this.Vd}set viewboxStretch(t){const i=this.Vd;i!==t&&(Debug&&U.W(t,ViewboxStretch,"ViewboxStretch"),this.Vd=t,this.g(),this.t("viewboxStretch",i,t))}get gridCellSize(){return this.Ni!==null?this.Ni.Xd:Size.YA}set gridCellSize(t){this.Ni===null&&(this.Ni=new GridPanelSettings);const i=this.Ni.Xd;if(!i.equals(t)){(!t.isReal()||t.width===0||t.height===0)&&U.n("Invalid Panel.gridCellSize: "+t),this.Ni.Xd=t.T();const e=this.diagram;e!==null&&this===e.grid&&e.ph(),this.L(),this.t("gridCellSize",i,t)}}get gridOrigin(){return this.Ni!==null?this.Ni.Yd:Point.yn}set gridOrigin(t){this.Ni===null&&(this.Ni=new GridPanelSettings);const i=this.Ni.Yd;if(!i.equals(t)){t.isReal()||U.n("Invalid Panel.gridOrigin: "+t),this.Ni.Yd=t.T();const e=this.diagram;e!==null&&this===e.grid&&e.ph(),this.L(),this.t("gridOrigin",i,t)}}get graduatedMin(){return this.ft!==null?this.ft.zp:0}set graduatedMin(t){const i=this.graduatedMin;if(i!==t&&(Debug&&U.r(t,Panel,"graduatedMin"),this.ft===null&&(this.ft=new GradPanelSettings),this.ft.zp=t,this.g(),this.t("graduatedMin",i,t),this.xc())){const e=this.part;e!==null&&this.Ua(e,"graduatedRange")}}get graduatedMax(){return this.ft!==null?this.ft.Xp:100}set graduatedMax(t){const i=this.graduatedMax;if(i!==t&&(Debug&&U.r(t,Panel,"graduatedMax"),this.ft===null&&(this.ft=new GradPanelSettings),this.ft.Xp=t,this.g(),this.t("graduatedMax",i,t),this.xc())){const e=this.part;e!==null&&this.Ua(e,"graduatedRange")}}get graduatedRange(){return this.graduatedMax-this.graduatedMin}get graduatedTickUnit(){return this.ft!==null?this.ft.Yp:10}set graduatedTickUnit(t){const i=this.graduatedTickUnit;i!==t&&t>0&&(Debug&&U.r(t,Panel,"graduatedTickUnit"),this.ft===null&&(this.ft=new GradPanelSettings),this.ft.Yp=t,this.g(),this.t("graduatedTickUnit",i,t))}get graduatedTickBase(){return this.ft!==null?this.ft.Kp:0}set graduatedTickBase(t){const i=this.graduatedTickBase;i!==t&&(Debug&&U.r(t,Panel,"graduatedTickBase"),this.ft===null&&(this.ft=new GradPanelSettings),this.ft.Kp=t,this.g(),this.t("graduatedTickBase",i,t))}get Es(){return this.ft!==null?this.ft.Es:null}set Es(t){this.ft!==null?this.ft.Es=t:t!==null&&(this.ft=new GradPanelSettings,this.ft.Es=t)}get ss(){return this.ft!==null?this.ft.ss:null}set ss(t){this.ft!==null?this.ft.ss=t:t!==null&&(this.ft=new GradPanelSettings,this.ft.ss=t)}get ys(){return this.ft!==null?this.ft.ys:null}set ys(t){this.ft!==null?this.ft.ys=t:t!==null&&(this.ft=new GradPanelSettings,this.ft.ys=t)}get Ee(){return this.ft!==null?this.ft.Ee:null}set Ee(t){this.ft!==null?this.ft.Ee=t:t!==null&&(this.ft=new GradPanelSettings,this.ft.Ee=t)}_0(t){super._0(t);const i=this.O.h,e=i.length;for(let s=0;s0?this.is:null,s=this.columnCount>0?this.es:null;e!==null&&this.nS(t,i,!0,e,!0),s!==null&&this.nS(t,i,!1,s,!0),e!==null&&this.xD(t,!0,e),s!==null&&this.xD(t,!1,s),e!==null&&this.nS(t,i,!0,e,!1),s!==null&&this.nS(t,i,!1,s,!1)}xD(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 a=h.separatorStrokeWidth;isNaN(a)&&(a=i?this.defaultRowSeparatorStrokeWidth:this.defaultColumnSeparatorStrokeWidth);let f=h.separatorStroke;if(f===null&&(f=i?this.defaultRowSeparatorStroke:this.defaultColumnSeparatorStroke),a===0||f===null)continue;this.Nn(t,f,!1,!1,o,n);let c=!1,u=h.separatorDashArray;u===null&&(u=i?this.defaultRowSeparatorDashArray:this.defaultColumnSeparatorDashArray),u!==null&&(c=!0,t.enableDash(u,0)),t.beginPath();const d=h.position+a;i?d>o.height&&(a-=d-o.height):d>o.width&&(a-=d-o.width);let m=h.position+a/2;t.lineWidth=a;const g=this.si;if(i){m+=g.top;const p=g.left,y=o.width-g.right;t.moveTo(p,m),t.lineTo(y,m)}else{m+=g.left;const p=g.top,y=o.height-g.bottom;t.moveTo(m,p),t.lineTo(m,y)}t.stroke(),t.endPath(),c&&t.disableDash()}}nS(t,i,e,s,n){const o=s.length,r=this.actualBounds,l=this.naturalBounds,h=this.bD(!0),a=this.bD(!1);for(let f=0;fu)continue;let d=c.computeEffectiveSpacing(),m=c.separatorStrokeWidth;isNaN(m)&&(m=e?this.defaultRowSeparatorStrokeWidth:this.defaultColumnSeparatorStrokeWidth);let g=c.separatorStroke;g===null&&(g=e?this.defaultRowSeparatorStroke:this.defaultColumnSeparatorStroke),(g===null||c.index===(e?h:a))&&(m=0),d-=m;const p=c.position+m;let y=d+c.actual;if(p+y>u&&(y=u-p),y<=0)continue;const x=this.si;this.Nn(t,c.background,!0,!1,l,r),e?t.fillRect(x.left,p+x.top,r.width-(x.left+x.right),y):t.fillRect(p+x.left,x.top,y,r.height-(x.top+x.bottom))}}bD(t){const i=t?this.rowCount:this.columnCount;for(let e=0;ex&&n.set(M),Point.o(M)),Point.o(P),o&&n.E(r),b}}tc(){const t=this.O.h,i=t.length;for(let e=0;ee||h>s)&&(this.g(),this.gt(l>e?e:l,h>s?s:h,0,0));break;case 2:this.g(!0),this.gt(e+f,s+c,0,0);break;case 5:this.g(!0),this.gt(e+f,h+c,0,0);break;case 4:this.g(!0),this.gt(l+f,s+c,0,0);break}}this.tt.arrange(this,n,this.ir)}Ah(t){const i=this.naturalBounds,e=this.tr();if(Rect.contains(0,0,i.width,i.height,t.x,t.y)){const s=this.O.h,n=s.length,o=Point.U(0,0);for(let r=n;r--;){const l=s[r];if(!(!l.visible&&l!==e)&&(o.set(t).We(l.E),l.containsPoint(o)))return Point.o(o),!0}return Point.o(o),this.It!==null}return!1}j0(t){if(this.ho===t)return this;const i=this.O.h,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=c;const g=c instanceof Panel?c:null,p=Transform.a();p.set(r),(g!==null?g.e0(t,i,e,s,n,p):m.eD(t,s,p))&&(i!==null&&(m=i(m)),m!==null&&(e===null||e(m))&&n.add(m)),Transform.o(p)}}return o===void 0&&Transform.o(r),s}return o===void 0&&Transform.o(r),!1}eC(t,i,e){const s=this.O.h,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.eC(t,i,e);let a=r;t!==null&&(a=t(a)),a!==null&&(i===null||i(a))&&e.add(a)}}WT(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.Ln(),h=l?t:Point.U(t.x,t.y).We(this.E),a=l?i:Point.U(i.x,i.y).We(this.E),f=h.distanceSquaredPoint(a),c=h.x>0&&h.x0&&h.yk.width||S.y>k.height||S.x+S.width<0||S.y+S.height<0))continue;if(b.Ln()){const C=b.E;d.set(t).We(C),m.set(i).We(C)}else d.set(t),m.set(i);let P=b;const A=b instanceof Panel?b:null;(A!==null?A.WT(d,m,e,s,n,o):P.sD(d,m,n))&&(e!==null&&(P=e(P)),P!==null&&(s===null||s(P))&&o.add(P))}Point.o(d),Point.o(m)}return n?c:u}return!1}JN(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}$N(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.n("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.cl=null),this.vo()||this.g(),i.g(!1),i.portId!==null?this.Fn=!0:i instanceof Panel&&i.Fn===!0&&(this.Fn=!0),this.ys=null,this.isEnabledObject()||this.oS(i,!1);const o=this.part;if(o!==null){o.hp(),o.Oc(),this.Fn&&o instanceof Node&&(o.Fn=!0),o.Fn&&o instanceof Node&&(o.de=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.l&8388608)!==0}set Fn(t){(this.l&8388608)!==0!==t&&(this.l=this.l^8388608)}FN(){return(this.l&16777216)!==0}sC(t){t?this.l|=16777216:this.l&=-16777217}$E(t){t.Ga(this),t.hl=null;const i=this.O,e=i.count;i.insertAt(e,t);const s=this.part;if(s!==null){s.hp(),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)}}yE(t){const i=this.O.h,e=i.length;let s=-1;for(let n=0;n=0&&this.ae(t,!0)}ae(t,i){const e=this.O,s=e.elt(t);if(s.hl=null,s.Ga(null),this.nn!==null){const o=s.data;U.it(o)&&this.nn.delete(o)}e.removeAt(t),this.ke(!1),this.g(),this.cl===s&&(this.cl=null),this.ys=null;const n=this.part;if(n!==null){n.hp(),n.Oc(),n.invalidateAdornments(),n instanceof Node&&(s instanceof Panel?s.walkVisualTreeFrom(s,(r,l)=>n.XN(l,i)):n.XN(s,i));const o=this.diagram;if(o!==null&&o.undoManager.isUndoingRedoing)return;n.raiseChangedEvent(4,"elements",this,s,null,t,null)}}get is(){return this.V===null&&(this.V=new TablePanelSettings),this.V.is}get rowCount(){return this.V===null?0:this.is.length}getRowDefinition(t){Debug&&U.r(t,Panel,"getRowDefinition:idx"),t<0&&U.G(t,">= 0",Panel,"getRowDefinition:idx"),t=Math.round(t);const i=this.is;if(i[t]===void 0){const e=new RowColumnDefinition;e.Ga(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(Debug&&U.r(t,Panel,"removeRowDefinition:idx"),t<0&&U.G(t,">= 0",Panel,"removeRowDefinition:idx"),this.rowCount===0)return;t=Math.round(t);const i=this.is,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.g()}}NL(t,i){const e=this.is;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.g()}}get es(){return this.V===null&&(this.V=new TablePanelSettings),this.V.es}get columnCount(){return this.V===null?0:this.es.length}getColumnDefinition(t){Debug&&U.r(t,Panel,"getColumnDefinition:idx"),t<0&&U.G(t,">= 0",Panel,"getColumnDefinition:idx"),t=Math.round(t);const i=this.es;if(i[t]===void 0){const e=new RowColumnDefinition;e.Ga(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(Debug&&U.r(t,Panel,"removeColumnDefinition:idx"),t<0&&U.G(t,">= 0",Panel,"removeColumnDefinition:idx"),this.columnCount===0)return;t=Math.round(t);const i=this.es,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.g()}}CL(t,i){const e=this.es;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.g()}}addRowColumnDefinition(t){let i=null;return t.isRow?i=this.getRowDefinition(t.index):t.isRow||(i=this.getColumnDefinition(t.index)),i&&i.Jb(t),this}addRowDefinition(t,i){const e=this.getRowDefinition(t);return e&&e.Jb(new RowColumnDefinition(i)),this}addColumnDefinition(t,i){const e=this.getColumnDefinition(t);return e&&e.Jb(new RowColumnDefinition(i)),this}get rowSizing(){return this.V!==null?this.V.Gp:3}set rowSizing(t){const i=this.rowSizing;i!==t&&(Debug&&t!==3&&t!==2&&U.n("Panel.rowSizing must be ProportionalExtra or None, not: "+t),this.V===null&&(this.V=new TablePanelSettings),this.V.Gp=t,this.g(),this.t("rowSizing",i,t))}get columnSizing(){return this.V!==null?this.V.qp:3}set columnSizing(t){const i=this.columnSizing;i!==t&&(Debug&&t!==3&&t!==2&&U.n("Panel.columnSizing must be ProportionalExtra or None, not: "+t),this.V===null&&(this.V=new TablePanelSettings),this.V.qp=t,this.g(),this.t("columnSizing",i,t))}get topIndex(){return this.V!==null?this.V.Hp:0}set topIndex(t){const i=this.topIndex;i!==t&&((!isFinite(t)||t<0)&&U.n("Panel.topIndex must be greater than zero and a real number, not: "+t),this.V===null&&(this.V=new TablePanelSettings),this.V.Hp=t,this.g(),this.t("topIndex",i,t))}get leftIndex(){return this.V!==null?this.V.vp:0}set leftIndex(t){const i=this.leftIndex;i!==t&&((!isFinite(t)||t<0)&&U.n("Panel.leftIndex must be greater than zero and a real number, not: "+t),this.V===null&&(this.V=new TablePanelSettings),this.V.vp=t,this.g(),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.is,s=e.length;let n=this.topIndex;for(;n{o.Ch();const r=o.Ei;if(r!==null){o.BN(!1);const l=r.iterator;for(;l.next();){const h=l.value;h.mode===2&&o.BN(!0);const a=h.sourceName;if(h.isToObject){a==="/"&&n.sC(!0);const f=h.iD(n,o);f!==null&&(i.add(f),f.ao===null&&(f.ao=new List),f.ao.add(h))}t.add(h)}}if(o instanceof Panel&&o.type===Panel.Table){if(o.rowCount>0){const l=o.is,h=l.length;for(let a=0;a0){const l=o.es,h=l.length;for(let a=0;a0&&o instanceof Panel){const h=r.substring(0,l),a=r.substring(l+1),f=o.findObject(h);f!==null?(o=f,n.targetProperty=a):(U.ot('Warning: unable to find GraphObject named "'+h+'" for Binding: '+n.toString()),o=null)}if(o instanceof RowColumnDefinition){const h=GSet.Ps(o.panel);n.targetId=h===void 0?-1:h,o.panel.ho=n.targetId}else if(o instanceof GraphObject){const h=GSet.Ps(o);n.targetId=h===void 0?-1:h,o.ho=n.targetId}else U.n("Unknown type of binding target: "+o);n.check(o)}}return t.k(),this instanceof Part&&(this.Oe()&&this.ensureBounds(),Debug&&!Panel.ND&&this.walkVisualTreeFrom(this,(n,o)=>{if(o instanceof Panel&&(o.type===Panel.Auto||o.type===Panel.Spot||o.type===Panel.Graduated)&&o.elements.count<=1&&!(o instanceof Part)){let r=!1;if(o.elements.count===1&&(r=o.itemArray!==null,!r)){for(s=t.iterator;s.next();)if(s.value.targetProperty==="itemArray"){r=!0;break}}r||(U.ot("Auto, Spot, or Graduated Panel should not have zero or one elements: "+o.toString()+" in "+n.toString()),Panel.ND=!0)}})),this}static ND=!1;copyTemplate(t){t===void 0&&(t=!1);const i=this.copy();return i.ZE(e=>{e instanceof Panel&&(e.Os=null,e.oi=null);const s=e.Ei;s!==null&&(e.Ei=null,s.each(o=>e.bind(o.copy())));const n=e.Rs;n!==null&&(e.Rs=null,n.each(o=>e.trigger(o.value.copy())))}),t&&i.Yt(),i}updateTargetBindings(t){const i=this.Os;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.nC(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)}}t3(t){if(t===""){this.updateTargetBindings(t);return}const i=this.Os;if(i===null)return;const e=this.diagram?.model,s=i.iterator;for(;s.next();){const n=s.value;if(n.isToData&&n.sourceProperty!=="")continue;const o=this.nC(n,"");if(o===null)continue;const{data:r,elt:l}=o;l!==void 0&&n.updateTarget(l,r,void 0,e)}}Wo(){if(this.diagram!==null)if(this.YN()){const t=this.diagram.model,i=this.Os.iterator;for(;i.next();){const e=i.value;if(!e.isToTheme)continue;const s=this.nC(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.O.h,i=t.length;for(let e=0;e0;let r=0;for(;n0){const i=this.O.elt(0);if(i.isPanelMain&&i instanceof Panel&&i.al())return 1}return 0}rebuildItemElements(){const t=this.Up();for(;this.O.length>t;)this.ae(this.O.length-1,!1);this.CD(null,this.itemArray)}CD(t,i){const e=this.Up(),s=i;if(s===null||s.length===0){for(;this.O.length>e;)this.ae(this.O.length-1,!1);return}if(this.O.length<=e){const n=s.length;for(let o=0;o(w[w.Default=1]="Default",w[w.None=2]="None",w[w.ProportionalExtra=3]="ProportionalExtra",w))(Sizing||{});class RowColumnDefinition{tn;Wp;Et;Wa;ja;pi;yt;Ud;uo;ul;Gd;qd;Ja;It;Hd;Bs;$;Vi;Me;constructor(t){GSet._i(this),this.tn=null,this.Wp=!0,this.Et=0,this.Me=NaN,this.Wa=0,this.ja=1/0,this.pi=Spot.Default,this.$=0,this.Vi=0,this.yt=0,this.Bs=null,this.Ud=1,this.uo=1,this.ul=null,this.Gd=null,this.qd=NaN,this.Ja=null,this.It=null,this.Hd=!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.Wp=this.Wp,t.Et=this.Et,t.Me=this.Me,t.Wa=this.Wa,t.ja=this.ja,t.pi=this.pi,t.$=this.$,t.Vi=this.Vi,t.yt=this.yt,t.uo=this.uo,t.Ud=this.Ud,this.ul===null?t.ul=null:t.ul=this.ul.T(),t.Gd=this.Gd,t.qd=this.qd,t.Ja=null,this.Ja!==null&&(t.separatorDashArray=this.Ja.slice()),t.It=this.It,t.Hd=this.Hd,t.Bs=this.Bs,t}Jb(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.Ja=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)}gi(t){t in Sizing?this.sizing=t:U.wr(this,t)}toString(){return"RowColumnDefinition "+(this.isRow?"(Row ":"(Column ")+this.index+") #"+GSet.Ps(this)}static Default=1;static None=2;static ProportionalExtra=3;Ga(t){this.tn=t}computeEffectiveSpacingTop(t){let i=0;const e=this.tn;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.ul;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.tn;let e=0;const s=this.isRow;if(i!==null&&i.type===Panel.Table){const o=s?i.is.length:i.es.length;for(let r=0;r= 0",RowColumnDefinition,"height"),this.Me=t,this.actual=this.$,this.panel!==null&&this.panel.g(),this.t("height",i,t))}get width(){return this.Me}set width(t){const i=this.Me;i!==t&&(Debug&&U.i(t,"number",RowColumnDefinition,"width"),t<0&&U.G(t,">= 0",RowColumnDefinition,"width"),this.Me=t,this.actual=this.$,this.panel!==null&&this.panel.g(),this.t("width",i,t))}get minimum(){return this.Wa}set minimum(t){const i=this.Wa;i!==t&&(Debug&&U.i(t,"number",RowColumnDefinition,"minimum"),(t<0||!isFinite(t))&&U.G(t,">= 0",RowColumnDefinition,"minimum"),this.Wa=t,this.actual=this.$,this.panel!==null&&this.panel.g(),this.t("minimum",i,t))}get maximum(){return this.ja}set maximum(t){const i=this.ja;i!==t&&(Debug&&U.i(t,"number",RowColumnDefinition,"maximum"),t<0&&U.G(t,">= 0",RowColumnDefinition,"maximum"),this.ja=t,this.actual=this.$,this.panel!==null&&this.panel.g(),this.t("maximum",i,t))}get alignment(){return this.pi}set alignment(t){const i=this.pi;i.equals(t)||(Debug&&U.s(t,Spot,RowColumnDefinition,"alignment"),this.pi=t.T(),this.panel!==null&&this.panel.g(),this.t("alignment",i,t))}get stretch(){return this.uo}set stretch(t){const i=this.uo;i!==t&&(this.uo=t,this.panel!==null&&this.panel.g(),this.t("stretch",i,t))}get separatorPadding(){return this.ul}set separatorPadding(t){typeof t=="number"?t=new Margin(t):t!==null&&Debug&&U.s(t,Margin,RowColumnDefinition,"separatorPadding");const i=this.ul;(t===null||i===null||!i.equals(t))&&(t!==null&&(t=t.T()),this.ul=t,this.panel!==null&&this.panel.g(),this.t("separatorPadding",i,t))}get separatorStroke(){return this.Gd}set separatorStroke(t){const i=this.Gd;i!==t&&(t!==null&&Brush.Dd(t,"RowColumnDefinition.separatorStroke"),t instanceof Brush&&t.k(),this.Gd=t,this.panel!==null&&this.panel.g(),this.t("separatorStroke",i,t))}get separatorStrokeWidth(){return this.qd}set separatorStrokeWidth(t){const i=this.qd;i!==t&&(this.qd=t,this.panel!==null&&this.panel.g(),this.t("separatorStrokeWidth",i,t))}get separatorDashArray(){return this.Ja}set separatorDashArray(t){const i=this.Ja;if(i!==t){if(t!==null&&!Array.isArray(t)&&U.Ti(t,"Array",RowColumnDefinition,"separatorDashArray:value"),t!==null){const e=t.length;let s=0;for(let n=0;n=0)||!isFinite(o))&&U.n("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.Ja=t,this.panel!==null&&this.panel.L(),this.t("separatorDashArray",i,t)}}get background(){return this.It}set background(t){const i=this.It;i!==t&&(t!==null&&Brush.Dd(t,"RowColumnDefinition.background"),t instanceof Brush&&t.k(),this.It=t,this.panel!==null&&this.panel.L(),this.t("background",i,t))}get coversSeparators(){return this.Hd}set coversSeparators(t){const i=this.Hd;i!==t&&(U.i(t,"boolean",RowColumnDefinition,"coversSeparators"),this.Hd=t,this.panel!==null&&this.panel.L(),this.t("coversSeparators",i,t))}get sizing(){return this.Ud}set sizing(t){const i=this.Ud;i!==t&&(Debug&&U.W(t,Sizing,"Sizing"),this.Ud=t,this.panel!==null&&this.panel.g(),this.t("sizing",i,t))}iS(){if(this.sizing===1){const t=this.tn;return t===null?2:this.isRow?t.rowSizing:t.columnSizing}return this.sizing}get actual(){return this.$}set actual(t){isNaN(this.Me)?this.$=Math.max(Math.min(this.ja,t),this.Wa):this.$=Math.max(Math.min(this.ja,this.Me),this.Wa)}get measured(){return this.Vi}set measured(t){this.Vi=t}get total(){return this.$+this.computeEffectiveSpacing()}get position(){return this.yt}set position(t){this.yt=t}bind(t,i,e,s){return this.Ac(t,i,e,s),this}bindTwoWay(t,i,e,s){const n=this.Ac(t,i,e,s);return s===void 0&&n.makeTwoWay(),this}theme(t,i,e,s,n){return this.Ih(t,i,e,s,n),this}themeData(t,i,e,s,n){return this.Ih(t,i,e,s,n).ofData(),this}themeObject(t,i,e,s,n,o){return this.Ih(t,i,e,s,n).ofObject(o),this}themeModel(t,i,e,s,n){return this.Ih(t,i,e,s,n).ofModel(),this}Ac(t,i,e,s){let n;return typeof t=="string"?n=new Binding(t,i,e,s):n=t,this.Pp(n),n}Ih(t,i,e,s,n){let o;return typeof t=="string"?o=new ThemeBinding(t,i,e,s,n):o=t,this.Pp(o),o}Pp(t){t.Re=this;const i=this.panel;if(i!==null){const e=i.findBindingPanel();e!==null&&e.cD()&&U.n("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{xt;on;vd;$a;ee;er;Qo;Jt;Wd;jd;j;constructor(t,i){super(),this.xt=null,this.on=null,this.vd="None",this.$a="black",this.ee="black",this.er=1,this.Qo=null,this.Jt=null,this.Wd=NaN,this.jd=NaN,this.j=null,typeof t=="string"?this.figure=t:t&&Object.assign(this,t),i&&Object.assign(this,i)}cloneProtected(t){super.cloneProtected(t),t.xt=this.xt,t.on=this.on,t.vd=this.vd,t.$a=this.$a,t.ee=this.ee,t.er=this.er,this.Qo!==null&&(t.Qo=this.Qo.slice()),this.Jt!==null&&(this.Jt.wi?t.Jt=this.Jt:t.Jt=this.Jt.copy()),t.Wd=this.Wd,t.jd=this.jd,this.j!==null&&(t.j=this.j.copy())}Za(){return this.Jt===null?this.Jt=new ShapeTemplateSettings:this.Jt.wi&&(this.Jt=this.Jt.copy()),this.Jt}Ch(){super.Ch(),this.Jt!==null&&(this.Jt.wi=!0)}gi(t){t in GeometryStretch?this.geometryStretch=t:super.gi(t)}toString(){return"Shape("+(this.figure!=="None"?this.figure:this.toArrow!=="None"?this.toArrow:this.fromArrow)+")#"+GSet.Ps(this)}o3(t,i){const e=this.pathPattern;if(e===null)return;e.gt(1/0,1/0);const s=e.measuredBounds;e.Ut(0,0,s.width,s.height);const n=this.geometry;if(n===null)return;t.save(),t.beginPath();const o=U.at();if(n.type===1)o.push(n.startX),o.push(n.startY),o.push(n.endX),o.push(n.endY),this.Jd(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,a=l.startY,f=h,c=a;const u=l.segments.h,d=u.length;for(let m=0;m=.1;){if(M===0&&(P?(S=b,S-=k,y-=k,P=!1):S=b,S===0&&(S=1)),S>y){S=y,U.et(x);return}S>p?(M=S-p,S=p):M=0;let N=Math.sqrt(S*S/(1+m*m));if(u<0&&(N=-N),h+=N,a+=m*N,t.translate(h,a),t.rotate(g),t.translate(-(r/2),-(l/2)),M===0&&s.Dh(t,i),t.translate(r/2,l/2),t.rotate(-g),t.translate(-h,-a),y-=S,p-=S,M!==0){if(A++,A===x.length){U.et(x);return}C=x[A],u=C[0],g=C[1],m=C[2],p=C[3],S=M}}U.et(x)}Dh(t,i){const e=t instanceof SVGContext;let s=this.ee;const n=this.$a;if(s===null&&n===null)return;const o=this.xt;if(o===null)return;t.commitTransform();const r=this.actualBounds,l=this.naturalBounds;n!==null&&this.Nn(t,n,!0,!1,l,r);const h=this.part;let a=this.er;s!==null&&a===0&&h!==null&&(this.isPanelMain||h.findMainElement()===this)&&(a=h.l3()),a===0&&(s=null),s!==null&&a!==0&&(this.Nn(t,s,!1,!1,l,r),t.lineWidth=a,t.lineJoin=this.strokeJoin,t.lineCap=this.strokeCap,t.miterLimit=this.strokeMiterLimit);let f=!1;h&&i.getRenderingHint("drawShadows")&&(f=h.isShadowed),t.fl===!1&&(f=!1);let c=!0;s!==null&&(n===null||n==="transparent")&&(c=!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,y=o.endY,x=Math.min(m,p),b=Math.min(g,y),S=Math.abs(p-m),k=Math.abs(y-g);t.beginPath(),t.rect(x,b,S,k),n!==null&&t.fillContext(n,!1,null),s!==null&&(c&&f&&t.shadowsOff(),t.strokeContext(),c&&f&&t.shadowsOn()),t.endPath()}else if(o.type===3){const m=o.startX,g=o.startY,p=o.endX,y=o.endY,x=Math.abs(p-m)/2,b=Math.abs(y-g)/2,S=Math.min(m,p)+x,k=Math.min(g,y)+b;t.beginPath(),t.moveTo(S,k-b),t.bezierCurveTo(S+G.Zn*x,k-b,S+x,k-G.Zn*b,S+x,k),t.bezierCurveTo(S+x,k+G.Zn*b,S+G.Zn*x,k+b,S,k+b),t.bezierCurveTo(S-G.Zn*x,k+b,S-x,k+G.Zn*b,S-x,k),t.bezierCurveTo(S-x,k-G.Zn*b,S-G.Zn*x,k-b,S,k-b),t.closePath(),n!==null&&t.fillContext(n,!1,null),s!==null&&(c&&f&&t.shadowsOff(),t.strokeContext(),c&&f&&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.Td(t)}ON(t,i){if(t.nodeName!=="g")t.setAttributeNS(null,"filter",i);else{const e=t.getElementsByTagName("path");for(let s=0;s1,i);U.n("Unknown Geometry type: "+e.type)}}Cd(t,i,e,s){const n=this.desiredSize,o=this.er;t=Math.max(t,0),i=Math.max(i,0);let r;if(this.on!==null)r=this.geometry.bounds;else{const g=this.figure;let p=Shape.aC[g];if(p===void 0){let y=G.xn[g];typeof y=="string"&&(y=G.xn[y]),U.ht(y)?(p=y(null,100,100),Shape.aC[g]=p):U.n("Unsupported Figure: "+g)}r=p.bounds}let l=r.width,h=r.height,a=r.width,f=r.height;switch(this.en(!0)){case 0:e=0,s=0;break;case 2:a=Math.max(t-o,0),f=Math.max(i-o,0);break;case 5:a=Math.max(t-o,0),s=0;break;case 4:e=0,f=Math.max(i-o,0);break}isFinite(n.width)&&(a=n.width),isFinite(n.height)&&(f=n.height);const u=this.maxSize,d=this.minSize;e=Math.max(e-o,d.width),s=Math.max(s-o,d.height),a=Math.min(u.width,a),f=Math.min(u.height,f),a=isFinite(a)?Math.max(e,a):Math.max(l,e),f=isFinite(f)?Math.max(s,f):Math.max(h,s);const m=this.rM();switch(m){case 0:break;case 2:l=a,h=f;break;case 6:{let g=Math.min(a/l,f/h);isFinite(g)||(g=1),l=l*g,h=h*g;break}default:U.n(m+" is not a valid geometryStretch.")}if(this.on!==null){l===0&&(l=.001),h===0&&(h=.001);const g=this.on.cR(l,h);Debug&&g.k(),this.xt=g}else(this.xt===null||!G.q(this.xt.Lf,t-o)||!G.q(this.xt.Df,i-o))&&(this.xt=Shape.h3(this,l,h));r=this.xt.bounds,t===1/0||i===1/0?this.fo(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.fo(-(o/2),-(o/2),a+o,f+o),n.isReal()?(a=n.width,f=n.height,a=Math.min(u.width,a),f=Math.min(u.height,f),a=Math.max(d.width,a),f=Math.max(d.height,f),this.ji.e(0,0,a,f)):this.ji.c(r)}rM(){const t=this.geometryStretch;return this.on!==null?t===1?2:t:t===1?Shape.aC[this.figure].defaultStretch:t}Th(t,i,e,s){this.commonArrange(t,i,e,s)}getNearestIntersectionPoint(t,i,e){return this.bc(t.x,t.y,i.x,i.y,e)}bc(t,i,e,s,n){const o=this.E,r=1/(o.m11*o.m22-o.m12*o.m21),l=o.m22*r,h=-o.m12*r,a=-o.m21*r,f=o.m11*r,c=r*(o.m21*o.dy-o.m22*o.dx),u=r*(o.m12*o.dx-o.m11*o.dy),d=t*l+i*a+c,m=t*h+i*f+u,g=e*l+s*a+c,p=e*h+s*f+u,y=this.er/2;let x=this.xt;x===null&&(this.gt(1/0,1/0),x=this.xt);const b=x.bounds;let S=!1;if(x.type===1)if(this.strokeWidth<=1.5)S=G.Eo(x.startX,x.startY,x.endX,x.endY,d,m,g,p,n);else{let k=0,P=0;if(x.startX===x.endX)k=y,P=0;else{const T=(x.endY-x.startY)/(x.endX-x.startX);P=y/Math.sqrt(1+T*T),k=P*T}const A=U.at();let C=new Point;G.Eo(x.startX+k,x.startY+P,x.endX+k,x.endY+P,d,m,g,p,C)&&A.push(C),C=new Point,G.Eo(x.startX-k,x.startY-P,x.endX-k,x.endY-P,d,m,g,p,C)&&A.push(C),C=new Point,G.Eo(x.startX+k,x.startY+P,x.startX-k,x.startY-P,d,m,g,p,C)&&A.push(C),C=new Point,G.Eo(x.endX+k,x.endY+P,x.endX-k,x.endY-P,d,m,g,p,C)&&A.push(C);const M=A.length;if(M===0)return U.et(A),!1;S=!0;let N=1/0;for(let T=0;T0&&b.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;b.contains(D,F);)D-=N,F-=T;const R=.6;n.x=g,n.y=p;for(let K=0;Ke?t-e:e-t)<(i>s?i-s:s-i)){const c=ic||G.q(h.y,c))&&(h.yc||G.q(h.x,c))&&(h.x=a&&h<=f}else{let a=0,f=0;return s=a&&l<=f}}c3(t,i){if(this.containedInRect(t,i)||i===void 0&&(i=this.E,t.containsRect(this.actualBounds)))return!0;const e=t.left,s=t.right,n=t.top,o=t.bottom,r=Point.a(),l=Point.a(),h=Point.a(),a=Transform.a();a.set(i),a.vA(this.E),a.ux(),l.x=s,l.y=n,l.E(a),r.x=e,r.y=n,r.E(a);let f=!1;return this.Qa(r,l,h)?f=!0:(r.x=s,r.y=o,r.E(a),this.Qa(r,l,h)?f=!0:(l.x=e,l.y=o,l.E(a),this.Qa(r,l,h)?f=!0:(r.x=e,r.y=n,r.E(a),this.Qa(r,l,h)&&(f=!0)))),Transform.o(a),Point.o(r),Point.o(l),Point.o(h),f}sD(t,i,e){if(e&&this.fill!==null&&this.Ah(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.xt;if(o===null&&(this.gt(1/0,1/0),o=this.xt,o===null))return!1;if(!e){const c=o.bounds,u=c.x,d=c.y,m=c.x+c.width,g=c.y+c.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(c,u){const d=c.length;for(let m=0;ms)return!0;return!1}const l=o.startX,h=o.startY,a=o.endX,f=o.endY;if(o.type===1){const c=Point.distanceLineSegmentSquared(t.x,t.y,l,h,a,f),u=(a-l)*(t.x-l)+(f-h)*(t.y-h),d=(l-a)*(t.x-a)+(h-f)*(t.y-f),m=u>=0&&d>=0?s:n;return c<=m}else if(o.type===2){let c=!1;return e&&(c=Point.distanceLineSegmentSquared(t.x,t.y,l,h,l,f)<=s||Point.distanceLineSegmentSquared(t.x,t.y,l,h,a,h)<=s||Point.distanceLineSegmentSquared(t.x,t.y,a,h,a,f)<=s||Point.distanceLineSegmentSquared(t.x,t.y,l,f,a,f)<=s),c}else if(o.type===3){const c=(l+a)/2,u=(h+f)/2,d=t.x-c,m=t.y-u,g=Math.abs(a-l)/2,p=Math.abs(f-h)/2;if(g===0||p===0)return Point.distanceLineSegmentSquared(t.x,t.y,l,h,a,f)<=s;if(e){const y=G.eR(g,p,d,m);return y*y<=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 c=o.bounds,u=c.x,d=c.y,m=c.x+c.width,g=c.y+c.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.sT(t.x,t.y,p):o.Hk(t,p,!0,!1))return!0}else{const y=o.figures;for(let x=0;xs)return!1;const P=b.segments.h,A=P.length;for(let C=0;Cs)return!1;break;case 3:{const N=U.at();G.Qn(S,k,M.point1X,M.point1Y,M.point2X,M.point2Y,M.endX,M.endY,.8,N);const T=r(N,t);if(U.et(N),T||(S=M.endX,k=M.endY,t.distanceSquared(S,k)>s))return!1;break}case 4:{const N=U.at();G.fm(S,k,M.point1X,M.point1Y,M.endX,M.endY,.8,N);const T=r(N,t);if(U.et(N),T||(S=M.endX,k=M.endY,t.distanceSquared(S,k)>s))return!1;break}case 5:case 6:{const N=M.type===5?M.Bo(b):M.na(b,S,k),T=N.length;if(T===0){if(S=M.type===5?M.centerX:M.endX,k=M.type===5?M.centerY:M.endY,t.distanceSquared(S,k)>s)return!1;break}let L=null;const D=U.at();for(let F=0;F=0){this.er=t,this.g();const e=this.part;e!==null&&e.Oc(),this.t("strokeWidth",i,t)}else U.G(t,"value >= 0",Shape,"strokeWidth:value")}Z0(){return this.er}get strokeCap(){return this.Jt!==null?this.Jt.jp:"butt"}set strokeCap(t){const i=this.strokeCap;i!==t&&(typeof t=="string"&&(t==="butt"||t==="round"||t==="square")?(this.Za().jp=t,this.L(),this.t("strokeCap",i,t)):U.G(t,'"butt", "round", or "square"',Shape,"strokeCap"))}get strokeJoin(){return this.Jt!==null?this.Jt.Jp:"miter"}set strokeJoin(t){const i=this.strokeJoin;i!==t&&(typeof t=="string"&&(t==="miter"||t==="bevel"||t==="round")?(this.Za().Jp=t,this.L(),this.t("strokeJoin",i,t)):U.G(t,'"miter", "bevel", or "round"',Shape,"strokeJoin"))}get strokeMiterLimit(){return this.Jt!==null?this.Jt.$p:10}set strokeMiterLimit(t){const i=this.strokeMiterLimit;if(i!==t)if(Debug&&U.r(t,Shape,"strokeMiterLimit"),t>=1){this.Za().$p=t,this.L();const e=this.part;e!==null&&e.Oc(),this.t("strokeMiterLimit",i,t)}else Debug&&U.G(t,"value >= 1",Shape,"strokeWidth:value")}get strokeDashArray(){return this.Qo}set strokeDashArray(t){const i=this.Qo;if(i!==t){if(t!==null&&!Array.isArray(t)&&U.Ti(t,"Array",Shape,"strokeDashArray:value"),t!==null){const e=t.length;let s=0;for(let n=0;n=0)||!isFinite(o))&&U.n("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.Qo=t,this.L(),this.t("strokeDashArray",i,t)}}get strokeDashOffset(){return this.Jt!==null?this.Jt.Rh:0}set strokeDashOffset(t){const i=this.strokeDashOffset;i!==t&&(Debug&&U.r(t,Shape,"strokeDashOffset"),t>=0&&(this.Za().Rh=t,this.L(),this.t("strokeDashOffset",i,t)))}get figure(){return this.vd}set figure(t){const i=this.vd;if(i!==t){Debug&&U.i(t,"string",Shape,"figure");let e=G.xn[t];if(U.ht(e)?e=t:(e=G.xn[t.toLowerCase()],(!e||typeof e=="function")&&U.n("Unknown Shape.figure: "+t)),i!==e){const s=this.part;s!==null&&s.Oc(),this.vd=e,this.on=null,this.ce(),this.g(),this.t("figure",i,e)}}}get toArrow(){return this.Xt!==null?this.Xt.Zp:"None"}set toArrow(t){const i=this.toArrow;if(t===!0?t="Standard":t===!1&&(t=""),i!==t){Debug&&U.i(t,"string",Shape,"toArrow");const e=Shape.DD(t);e===null?U.n("Unknown Shape.toArrow: "+t):i!==e&&(this.Xt===null&&(this.Xt=new LinkElementSettings),this.Xt.Zp=e,this.on=null,this.ce(),this.g(),this.FD(e),this.t("toArrow",i,e))}}get fromArrow(){return this.Xt!==null?this.Xt.Qp:"None"}set fromArrow(t){const i=this.fromArrow;if(t===!0?t="Standard":t===!1&&(t=""),i!==t){Debug&&U.i(t,"string",Shape,"fromArrow");const e=Shape.DD(t);e===null?U.n("Unknown Shape.fromArrow: "+t):i!==e&&(this.Xt===null&&(this.Xt=new LinkElementSettings),this.Xt.Qp=e,this.on=null,this.ce(),this.g(),this.FD(e),this.t("fromArrow",i,e))}}FD(t){const i=this.diagram;i!==null&&i.undoManager.isUndoingRedoing||(this.kE(),this.toArrow!=="None"?(this.segmentIndex=-1,this.alignmentFocus=Spot.Right):this.fromArrow!=="None"&&(this.segmentIndex=0,this.alignmentFocus=Spot.Left))}get spot1(){return this.Jt!==null?this.Jt._n:Spot.Default}set spot1(t){const i=this.spot1;i.equals(t)||(Debug&&U.s(t,Spot,Shape,"spot1"),t=t.T(),this.Za()._n=t,this.g(),this.t("spot1",i,t))}get spot2(){return this.Jt!==null?this.Jt.to:Spot.Default}set spot2(t){const i=this.spot2;i.equals(t)||(Debug&&U.s(t,Spot,Shape,"spot2"),t=t.T(),this.Za().to=t,this.g(),this.t("spot2",i,t))}get parameter1(){return this.Wd}set parameter1(t){const i=this.Wd;i!==t&&(this.Wd=t,this.ce(),this.g(),this.t("parameter1",i,t))}get parameter2(){return this.jd}set parameter2(t){const i=this.jd;i!==t&&(this.jd=t,this.ce(),this.g(),this.t("parameter2",i,t))}get naturalBounds(){return this.ji}UE(){const t=this.desiredSize;if(!t.isReal()&&this.xt!==null){const i=this.xt.bounds;this.ji.c(i)}else this.ji.e(0,0,t.width,t.height)}get pathPattern(){return this.Jt!==null?this.Jt._p:null}set pathPattern(t){const i=this.pathPattern;i!==t&&(Debug&&t!==null&&U.s(t,GraphObject,Shape,"pathPattern"),this.Za()._p=t,this.L(),this.t("pathPattern",i,t))}get geometryStretch(){return this.Jt!==null?this.Jt.ty:1}set geometryStretch(t){const i=this.geometryStretch;i!==t&&(U.W(t,GeometryStretch,"GeometryStretch"),this.Za().ty=t,this.g(),this.t("geometryStretch",i,t))}get interval(){return this.j!==null?this.j.Bc:1}set interval(t){const i=this.interval;if(Debug&&U.r(t,Shape,"interval"),t=Math.round(t),i!==t&&t!==0&&isFinite(t)){this.j===null&&(this.j=new GradElementSettings),this.j.Bc=t;const e=this.diagram;e!==null&&this.panel===e.grid&&e.ph(),this.g();const s=this.panel;s!==null&&(s.ys=null),this.t("interval",i,t)}}get graduatedStart(){return this.j!==null?this.j.Vc:0}set graduatedStart(t){const i=this.graduatedStart;Debug&&U.r(t,Shape,"graduatedStart"),i!==t&&(t<0?t=0:t>1&&(t=1),this.j===null&&(this.j=new GradElementSettings),this.j.Vc=t,this.g(),this.t("graduatedStart",i,t))}get graduatedEnd(){return this.j!==null?this.j.zc:1}set graduatedEnd(t){const i=this.graduatedEnd;Debug&&U.r(t,Shape,"graduatedEnd"),i!==t&&(t<0?t=0:t>1&&(t=1),this.j===null&&(this.j=new GradElementSettings),this.j.zc=t,this.g(),this.t("graduatedEnd",i,t))}get graduatedSkip(){return this.j!==null?this.j.Xc:null}set graduatedSkip(t){const i=this.graduatedSkip;i!==t&&(t!==null&&U.C(t,Shape,"graduatedSkip"),this.j===null&&(this.j=new GradElementSettings),this.j.Xc=t,this.g(),this.t("graduatedSkip",i,t))}polygonContainsRect(t){const i=this;if(!i.part||!i.part.actualBounds.containsRect(t))return!1;const e=i.geometry;if(!e)return!1;const s=t.x,n=t.y,o=t.width,r=t.height,l=Point.a();if(l.x=s,l.y=n,i.getLocalPoint(l,l),!e.containsPoint(l)||o>0&&r>0&&(l.x=s+o,l.y=n+r,i.getLocalPoint(l,l),!e.containsPoint(l))||o>0&&(l.x=s+o,l.y=n,i.getLocalPoint(l,l),!e.containsPoint(l))||r>0&&(l.x=s,l.y=n+r,i.getLocalPoint(l,l),!e.containsPoint(l))||e.type===1)return!1;if(e.type===4){const h=e.figures.iterator;for(;h.next();){const a=h.value;if(!a.isFilled)continue;l.x=a.startX,l.y=a.startY,i.getDocumentPoint(l,l);let f=l.x,c=l.y,u=f,d=c,m=f,g=c;const p=a.segments.iterator;for(;p.next();){const y=p.value;if(l.x=y.endX,l.y=y.endY,i.getDocumentPoint(l,l),m=l.x,g=l.y,y.type===1)f=m,c=g;else if(y.type!==5&&(Rect.intersectsLineSegment(s,n,o,r,u,d,m,g)||y.isClosed&&Rect.intersectsLineSegment(s,n,o,r,m,g,f,c)))return!1;u=m,d=g}}}return Point.o(l),!0}static h3(t,i,e){let n=null;if(t.toArrow!=="None")n=Shape.On[t.toArrow];else if(t.fromArrow!=="None")n=Shape.On[t.fromArrow];else{let o=G.xn[t.figure];typeof o=="string"&&(o=G.xn[o]),o===void 0&&U.n("Unknown Shape.figure: "+t.figure),n=o(t,i,e),n.Lf=i,n.Df=e}if(n===null){const o=G.xn.Rectangle;U.ht(o)&&(n=o(t,i,e))}return Debug&&(n.bounds.width>i+1e-5||n.bounds.height>e+1e-5)&&U.n('Geometry made with figure "'+t.figure+'" has bounds '+n.bounds.toString()+" that are too large for the given size ("+i+","+e+"). See documentation for Shape.defineFigureGenerator."),n}static getFigureGenerators(){const t=new GMap;for(const i in G.xn){if(i===i.toLowerCase())continue;const e=G.xn[i];t.set(i,e)}return t.k(),t}static defineFigureGenerator(t,i){U.i(t,"string",Shape,"defineFigureGenerator:name"),typeof i=="string"?Debug&&(i===""||!G.xn[i])&&U.n("Shape.defineFigureGenerator synonym must not be empty or None or not a defined figure name: "+i):U.C(i,Shape,"defineFigureGenerator:func");const e=t.toLowerCase();Debug&&(t===""||t===e)&&U.n("Shape.defineFigureGenerator name must not be empty or all-lower-case: "+t);const s=G.xn;s[t]=i,s[e]=t}static isFigureDefined(t){return t in G.xn}static getArrowheadGeometries(){const t=new GMap;for(const i in G.dm)if(Shape.On[i]===void 0){const e=Geometry.parse(G.dm[i],!1);Shape.On[i]=e;const s=i.toLowerCase();s!==i&&(Shape.On[s]=i)}for(const i in Shape.On){if(i===i.toLowerCase())continue;const e=Shape.On[i];e instanceof Geometry&&t.set(i,e)}return t.k(),t}static defineArrowheadGeometry(t,i){U.i(t,"string",Shape,"defineArrowheadGeometry:name");let e=null;typeof i=="string"?(U.i(i,"string",Shape,"defineArrowheadGeometry:pathstr"),e=Geometry.parse(i,!1)):(U.s(i,Geometry,Shape,"defineArrowheadGeometry:pathstr"),e=i);const s=t.toLowerCase();(Debug&&t===""||s==="none"||t===s)&&U.n("Shape.defineArrowheadGeometry name must not be empty or None or all-lower-case: "+t);const n=Shape.On;n[t]=e,n[s]=t}static isArrowheadDefined(t){return Shape.On.has(t)}static On=new PropertyCollection;static aC=new PropertyCollection;static DD(t){let i=Shape.On[t];if(i===void 0){const e=t.toLowerCase();if(e==="none")return"None";if(i=Shape.On[e],i===void 0){let s=null;for(const n in G.dm)if(n.toLowerCase()===e){s=n;break}if(s!==null){const n=Geometry.parse(G.dm[s],!1);return Shape.On[s]=n,e!==s&&(Shape.On[e]=s),s}}}return typeof i=="string"?i:i instanceof Geometry?t:null}}class ShapeTemplateSettings{wi;jp;Jp;$p;Rh;_p;ty;_n;to;constructor(){this.wi=!1,this.jp="butt",this.Jp="miter",this.$p=10,this.Rh=0,this._p=null,this.ty=1,this._n=Spot.Default,this.to=Spot.Default}copy(){const t=new ShapeTemplateSettings;return t.jp=this.jp,t.Jp=this.Jp,t.$p=this.$p,t.Rh=this.Rh,t._p=this._p,t.ty=this.ty,t._n=this._n.T(),t.to=this.to.T(),t}}var Wrap=(w=>(w[w.None=0]="None",w[w.Fit=1]="Fit",w[w.DesiredSize=2]="DesiredSize",w[w.BreakAll=3]="BreakAll",w))(Wrap||{}),TextOverflow=(w=>(w[w.Clip=0]="Clip",w[w.Ellipsis=1]="Ellipsis",w))(TextOverflow||{}),TextFormat=(w=>(w[w.Trim=0]="Trim",w[w.None=1]="None",w))(TextFormat||{});class TextBlock extends GraphObject{mi;ee;En;Ne;xi;Q0;$d;j;nt;Hl;yo;Bn;Xe;bi;Vn;constructor(t,i){return super(),TextBlock.Lp===!1&&(TextBlock.Lp=!0,TextBlock.ps=Diagram.isUsingDOM()?new CanvasSurface(null).ni:null),this.l|=2097152,this.mi="",this.ee="black",this.En="13px sans-serif",this.Ne=0,this.xi=0,this.Q0=0,this.$d=null,this.j=null,this.nt=null,this.Hl=0,this.yo=null,this.Bn=0,this.Xe=null,this.bi=null,this.Vn=null,typeof t=="string"?this.text=t:t&&Object.assign(this,t),i&&Object.assign(this,i),this}cloneProtected(t){super.cloneProtected(t),t.mi=this.mi,t.ee=this.ee,t.En=this.En,t.Ne=this.Ne,t.xi=this.xi,t.Q0=this.Q0,t.$d=this.$d,this.j!==null&&(t.j=this.j.copy()),this.nt!==null&&(this.nt.wi?t.nt=this.nt:t.nt=this.nt.copy()),t.Hl=this.Hl,t.yo=this.yo,t.Bn=this.Bn,t.Xe=this.Xe,t.bi=this.bi,t.Vn=this.Vn}Vs(){return this.nt===null?this.nt=new TextBlockTemplateSettings:this.nt.wi&&(this.nt=this.nt.copy()),this.nt}Ch(){super.Ch(),this.nt!==null&&(this.nt.wi=!0)}JE(t){this.l=t.l|2048|4096,this.ei=t.opacity,this.It=t.background,this.gs=t.desiredSize.T(),this.minSize=t.minSize.T(),this.maxSize=t.maxSize.T(),t.Ci!==null?this.Ci=t.Ci.copy():this.Ci=null,this.lt=t.scale,this.vt=t.angle,this.stretch=t.stretch,this.ll=t.margin.T(),this.pi=t.alignment.T(),this.Md=t.alignmentFocus.T(),this.segmentFraction=t.segmentFraction,this.segmentOffset=t.segmentOffset.T(),this.segmentOrientation=t.segmentOrientation,t.ui!==null&&(this.ui=t.ui.copy()),this.shadowVisible=t.shadowVisible,this.mi=t.mi,this.ee=t.ee,this.En=t.En,this.j!==null&&(this.j=t.j.copy()),t.nt!==null&&(t.nt.wi?this.nt=t.nt:this.nt=t.nt.copy()),this.Hl=t.Hl}WE(t){if(this.mi=t.text||"",this.vt=t.labelAngle||0,this.Ne=t.lineCount||0,this.u3(t.lines),t.naturalBounds&&(this.ji=t.naturalBounds),t.actualBounds){const i=t.actualBounds;this.Ut(i.x,i.y,i.width,i.height)}}gi(t){t in Wrap?this.wrap=t:super.gi(t)}toString(){return this.mi.length>22?'TextBlock("'+this.mi.substring(0,20)+'"...)':'TextBlock("'+this.mi+'")'}static getEllipsis(){return TextBlock.iy}static setEllipsis(t){TextBlock.iy=t,TextBlock.aS=new PropertyCollection,TextBlock.fC=0}static getBaseline(){return TextBlock.fS}static setBaseline(t){TextBlock.fS=t}static fS=null;static getUnderline(){return TextBlock.cS}static setUnderline(t){TextBlock.cS=t}static cS=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;g(){super.g(),this._e(!0)}get font(){return this.En}set font(t){const i=this.En;i!==t&&(Debug&&(U.i(t,"string",TextBlock,"font"),TextBlock.isValidFont(t)||U.n('Not a valid font: "'+t+'"')),this.En=t,this.yo=null,this.g(),this.t("font",i,t))}static isValidFont(t){return root.CSS?root.CSS.supports("font",t):!0}get text(){return this.mi}set text(t){const i=this.mi;t!=null?t=t.toString():t="",i!==t&&(this.mi=t,this.g(),this.t("text",i,t))}get textAlign(){return this.nt!==null?this.nt.ey:"start"}set textAlign(t){const i=this.textAlign;i!==t&&(Debug&&U.i(t,"string",TextBlock,"textAlign"),t==="start"||t==="end"||t==="left"||t==="right"||t==="center"?(this.Vs().ey=t,this.L(),this.t("textAlign",i,t)):Debug&&U.G(t,'"start", "end", "left", "right", or "center"',TextBlock,"textAlign"))}get flip(){return this.nt!==null?this.nt.wo:0}set flip(t){const i=this.flip;i!==t&&(U.W(t,Flip,"Flip"),this.Vs().wo=t,this.L(),this.t("flip",i,t))}get verticalAlignment(){return this.nt!==null?this.nt.dl:Spot.Top}set verticalAlignment(t){const i=this.verticalAlignment;i.equals(t)||(Debug&&(U.s(t,Spot,TextBlock,"verticalAlignment"),t.isNoSpot()&&U.n("TextBlock.verticalAlignment for "+this+" must be a real Spot, not:"+t)),t=t.T(),this.Vs().dl=t,this.Cc(),this.t("verticalAlignment",i,t))}get naturalBounds(){if(!this.ji.isReal()){const t=Size.a();this.cC(this.mi,999999,t);let i=t.width;Size.o(t);let e=this.ID(i);const s=this.desiredSize;isNaN(s.width)||(i=s.width),isNaN(s.height)||(e=s.height),this.ji.$n(i,e)}return this.ji}get isMultiline(){return(this.l&2097152)!==0}set isMultiline(t){const i=(this.l&2097152)!==0;i!==t&&(Debug&&U.i(t,"boolean",TextBlock,"isMultiline"),this.l=this.l^2097152,this.g(),this.t("isMultiline",i,t))}get isUnderline(){return(this.l&4194304)!==0}set isUnderline(t){const i=(this.l&4194304)!==0;i!==t&&(Debug&&U.i(t,"boolean",TextBlock,"isUnderline"),this.l=this.l^4194304,this._e(!0),this.L(),this.t("isUnderline",i,t))}get isStrikethrough(){return(this.l&8388608)!==0}set isStrikethrough(t){const i=(this.l&8388608)!==0;i!==t&&(Debug&&U.i(t,"boolean",TextBlock,"isStrikethrough"),this.l=this.l^8388608,this._e(!0),this.L(),this.t("isStrikethrough",i,t))}get wrap(){return this.nt!==null?this.nt.ny:2}set wrap(t){const i=this.wrap;i!==t&&(Debug&&U.W(t,Wrap,"Wrap"),this.Vs().ny=t,this.g(),this.t("wrap",i,t))}get overflow(){return this.nt!==null?this.nt.ly:0}set overflow(t){const i=this.overflow;i!==t&&(Debug&&U.W(t,TextOverflow,"Overflow"),this.Vs().ly=t,this.g(),this.t("overflow",i,t))}get isOverflowed(){return(this.l&16777216)!==0}uC(t){t?this.l|=16777216:this.l&=-16777217}get stroke(){return this.ee}set stroke(t){const i=this.ee;i!==t&&(t!==null&&Brush.Dd(t,"TextBlock.stroke"),t instanceof Brush&&t.k(),this.ee=t,typeof t!="string"&&this.Pc(),this.L(),this.t("stroke",i,t))}get lineCount(){return this.Ne}get lineHeight(){return this.hy()}get editable(){return(this.l&1048576)!==0}set editable(t){const i=(this.l&1048576)!==0;i!==t&&(Debug&&U.i(t,"boolean",TextBlock,"editable"),this.l=this.l^1048576,this.t("editable",i,t))}get _N(){return(this.l&33554432)!==0}set _N(t){this.l=this.l^33554432}get textEditor(){return this.nt!==null?this.nt.fy:null}set textEditor(t){const i=this.textEditor;i!==t&&(Debug&&!(t instanceof HTMLInfo)&&U.n("TextBlock.textEditor must be an HTMLInfo."),this.Vs().fy=t,this.t("textEditor",i,t))}get errorFunction(){return this.nt!==null?this.nt.ws:null}set errorFunction(t){const i=this.errorFunction;i!==t&&(t!==null&&U.C(t,TextBlock,"errorFunction"),this.Vs().ws=t,this.t("errorFunction",i,t))}get interval(){return this.j!==null?this.j.Bc:1}set interval(t){const i=this.interval;if(Debug&&U.r(t,TextBlock,"interval"),t=Math.round(t),i!==t&&t!==0&&isFinite(t)){this.j===null&&(this.j=new GradElementSettings),this.j.Bc=t,this.g();const e=this.panel;e!==null&&(e.ys=null),this.t("interval",i,t)}}get graduatedStart(){return this.j!==null?this.j.Vc:0}set graduatedStart(t){const i=this.graduatedStart;Debug&&U.r(t,TextBlock,"graduatedStart"),i!==t&&(t<0?t=0:t>1&&(t=1),this.j===null&&(this.j=new GradElementSettings),this.j.Vc=t,this.g(),this.t("graduatedStart",i,t))}get graduatedEnd(){return this.j!==null?this.j.zc:1}set graduatedEnd(t){const i=this.graduatedEnd;Debug&&U.r(t,TextBlock,"graduatedEnd"),i!==t&&(t<0?t=0:t>1&&(t=1),this.j===null&&(this.j=new GradElementSettings),this.j.zc=t,this.g(),this.t("graduatedEnd",i,t))}get graduatedFunction(){return this.j!==null?this.j.cy:null}set graduatedFunction(t){const i=this.graduatedFunction;i!==t&&(t!==null&&U.C(t,TextBlock,"graduatedFunction"),this.j===null&&(this.j=new GradElementSettings),this.j.cy=t,this.g(),this.t("graduatedFunction",i,t))}get graduatedSkip(){return this.j!==null?this.j.Xc:null}set graduatedSkip(t){const i=this.graduatedSkip;i!==t&&(t!==null&&U.C(t,TextBlock,"graduatedSkip"),this.j===null&&(this.j=new GradElementSettings),this.j.Xc=t,this.g(),this.t("graduatedSkip",i,t))}Dh(t,i){if(this.ee===null||this.mi.length===0||this.En===null)return;const e=this.naturalBounds,s=this.actualBounds,n=e.width,o=e.height,r=this.hy();let l=t.textAlign=this.textAlign;const h=i.ud;l==="start"?l=h?"right":"left":l==="end"&&(l=h?"left":"right");const a=this.isUnderline,f=this.isStrikethrough;this.Nn(t,this.ee,!0,!1,e,s),(a||f)&&this.Nn(t,this.ee,!1,!1,e,s);const c=0;let u=0;const d=n;let m=!1;i._t===t&&!(i._t instanceof SVGContext)&&!this._N&&i.getRenderingHint("textGreeking")===!0&&r*this.Ea*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 y=this.Ne,b=(g+r+p)*y;if(o>b){const S=this.verticalAlignment;u=S.y*o-S.y*b+S.offsetY}if(TextBlock.uS&&(t.letterSpacing=this.letterSpacing,t.wordSpacing=this.wordSpacing),y===1&&this.Vn!==null){let S=this.xi;S>d&&(S=d),u+=g,this.RD(this.Vn,t,c,u,d,r,S,m,l,a,f)}else if(this.Xe!==null&&this.bi!==null)for(let S=0;Sd&&(k=d),u+=g,this.RD(this.bi[S],t,c,u,d,r,k,m,l,a,f),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}}RD(t,i,e,s,n,o,r,l,h,a,f){let c=0;if(l){h==="left"?c=0:h==="right"?c=n-r:h==="center"&&(c=(n-r)/2);const m=i.globalAlpha;i.globalAlpha=m/2,i.fillRect(e+c,s+o/4,r,o/2),i.globalAlpha=m;return}h==="left"?c=0:h==="right"?c=n:h==="center"&&(c=n/2);const u=TextBlock.fS!==null?TextBlock.fS(this,o):o*.75;i.fillText(t,e+c,s+u);let d=o/20|0;if(d===0&&(d=1),h==="right"?c-=r:h==="center"&&(c-=r/2),a){const m=TextBlock.cS!==null?TextBlock.cS(this,o):o*.8;this.OD(e+c,s+m,e+c+r,s+m,d,i),i instanceof SVGContext&&i.lastCreatedElement.classList.add("gojs-td")}if(f){let m=s+o-o/2.2|0;d%2!==0&&(m+=.5),this.OD(e+c,m,e+c+r,m,d,i),i instanceof SVGContext&&i.lastCreatedElement.classList.add("gojs-td")}}OD(t,i,e,s,n,o){o.beginPath(),o.lineWidth=n,o.moveTo(t,i),o.lineTo(e,s),o.stroke(),o.endPath()}kc(t,i,e){if(!super.kc(t,i,e))return!1;if(this.Nn(t,this.ee,!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.Td(t)}ON(t,i){if(t.nodeName!=="g")t.setAttributeNS(null,"filter",i);else{const e=t.getElementsByTagName("text");for(let s=0;sthis.maxLines&&(this.l|=16777216))}cC(t,i,e){const s=this.formatting===0;s&&(t=t.trim());let n=0,o=0,r=0;const l=this.En,h=this.spacingAbove+this.spacingBelow,a=Math.max(0,this.hy()+h),f=this.overflow===1?this.BD(l):0;if(this.Ne>=this.maxLines){e!==void 0&&e.e(0,a);return}let c=t;if(this.wrap===0){if(this.Bn=1,o=this.getStringWidth(t),f===0||o<=i){this.xi=Math.max(this.xi,o),this.zn(t,this.xi),e!==void 0&&e.e(o,a);return}let d=this.Zd(c);c=c.substring(d.length);let m=this.Zd(c);for(o=this.getStringWidth(d+m),r=0;m.length>0&&o<=i;){d+=m,c=c.substring(m.length),m=this.Zd(c),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-f);this.getStringWidth(d)>i&&d.length>1;)d=d.substring(0,d.length-1);this.uC(!0),d+=TextBlock.iy,r=this.getStringWidth(d),this.xi=r,this.zn(d,r),e!==void 0&&e.e(r,a);return}let u=0;for(c.length===0&&(u=1,this.zn(c,0));c.length>0;){let d=this.Zd(c);for(c=c.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 y=0;p===1?(y=o,n=Math.max(n,o)):(y=r,n=Math.max(n,r)),p--,p<1&&(p=1);const x=d.substring(0,p);if(this.zn(x,y),u++,d=d.substring(p),this.Ne+u>this.maxLines)break}let m=this.Zd(c);for(o=this.getStringWidth(d+m),r=0;m.length>0&&o<=i;){d+=m,c=c.substring(m.length),m=this.Zd(c),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.zn(d,g),u++,this.Ne+u>this.maxLines)break}this.Bn=Math.min(this.maxLines-this.Ne,u),this.xi=Math.max(this.xi,n),e!==void 0&&e.e(this.xi,a*this.Bn)}p3(t,i){if(this.xi===0||this.Xe===null||this.bi===null||this.overflow!==1)return;const e=this.En,s=this.overflow===1?this.BD(e):0,n=this.spacingAbove+this.spacingBelow,o=Math.max(0,this.hy()+n),r=Math.min(this.maxLines-1,Math.max(Math.floor(i/o+.01)-1,0));if(r+1>=this.bi.length)return;this.uC(!0);let l=this.bi[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.iy;const a=this.getStringWidth(l);this.bi[r]=l,this.bi=this.bi.slice(0,r+1),this.Xe[r]=a,this.Xe=this.Xe.slice(0,r+1),this.Bn=this.bi.length,this.xi=Math.max(this.xi,a),this.Ne=this.Bn,this.Ne===1&&(this.Vn=this.bi[0])}Zd(t){if(this.wrap===3)return t.substring(0,1);let i=t.length,e=0;const s=TextBlock.y3;for(;e=t.length?t:t.substring(0,e)}getStringWidth(t){return TextBlock.ps===null?t.length*8:TextBlock.ps.measureText(t).width}hy(){if(this.yo!==null)return this.yo;const t=this.En;let i=0;if(TextBlock.ps===null)return i=16,this.yo=i,i;if(TextBlock.dC[t]!==void 0&&TextBlock.VD<5e3)i=TextBlock.dC[t];else{TextBlock.ps.letterSpacing="0px";const e=TextBlock.ps.measureText("M");TextBlock.ps.letterSpacing=this.letterSpacing,i=e.width*1.3,TextBlock.dC[t]=i,TextBlock.VD++}return this.yo=i,i}BD(t){if(TextBlock.ps===null)return 6;let i=0;return TextBlock.aS[t]!==void 0&&TextBlock.fC<5e3?i=TextBlock.aS[t]:(i=TextBlock.ps.measureText(TextBlock.iy).width,TextBlock.aS[t]=i,TextBlock.fC++),i}dS(t,i){return t.indexOf(` `,i)}ID(t){let i=this.mi.replace(/\r\n/g,` `).replace(/\r/g,` `);const e=this.spacingAbove+this.spacingBelow,s=Math.max(0,this.hy()+e);if(i.length===0)return this.xi=0,this.Ne=1,s;if(!this.isMultiline){const h=this.dS(i,0);h>=0&&(i=i.substring(0,h))}let n=0;this.Ne=0;let o=0,r=-1,l=!1;for(;!l;){if(r=this.dS(i,o),r===-1&&(r=i.length,l=!0),o<=r){const h=i.substring(o,r);if(this.wrap!==0){this.Bn=0;const a=Size.a();this.cC(h,t,a),n+=a.height,Size.o(a),this.Ne+=this.Bn}else this.cC(h,t),n+=s,this.Ne++;this.Ne===this.maxLines&&(l=!0)}o=r+1}return this.Q0=n,n}m3(){let t=this.mi.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.dS(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.dS(t,0);return i>=0&&(t=t.substring(0,i)),this.getStringWidth(t)}}get textValidation(){return this.nt!==null?this.nt.ql:null}set textValidation(t){const i=this.textValidation;i!==t&&(t!==null&&U.C(t,TextBlock,"textValidation"),this.Vs().ql=t,this.t("textValidation",i,t))}get textEdited(){return this.nt!==null?this.nt.uy:null}set textEdited(t){const i=this.textEdited;i!==t&&(t!==null&&U.C(t,TextBlock,"textEdited"),this.Vs().uy=t,this.t("textEdited",i,t))}get spacingAbove(){return this.nt!==null?this.nt.gy:0}set spacingAbove(t){const i=this.spacingAbove;i!==t&&(Debug&&U.i(t,"number",TextBlock,"spacingAbove"),this.Vs().gy=t,this.g(),this.t("spacingAbove",i,t))}get spacingBelow(){return this.nt!==null?this.nt.my:0}set spacingBelow(t){const i=this.spacingBelow;i!==t&&(Debug&&U.i(t,"number",TextBlock,"spacingBelow"),this.Vs().my=t,this.g(),this.t("spacingBelow",i,t))}get letterSpacing(){return this.nt!==null?this.nt.yy:"0px"}set letterSpacing(t){const i=this.letterSpacing;i!==t&&(TextBlock.uS=!0,Debug&&U.i(t,"string",TextBlock,"letterSpacing"),this.Vs().yy=t,this.g(),this.t("letterSpacing",i,t))}get wordSpacing(){return this.nt!==null?this.nt.wy:"0px"}set wordSpacing(t){const i=this.wordSpacing;i!==t&&(TextBlock.uS=!0,Debug&&U.i(t,"string",TextBlock,"wordSpacing"),this.Vs().wy=t,this.g(),this.t("wordSpacing",i,t))}get formatting(){return this.nt!==null?this.nt.xy:0}set formatting(t){const i=this.formatting;i!==t&&(U.W(t,TextFormat,"formatting"),this.Vs().xy=t,this.g(),this.t("formatting",i,t))}get maxLines(){return this.nt!==null?this.nt.Sy:1/0}set maxLines(t){const i=this.maxLines;i!==t&&(Debug&&U.i(t,"number",TextBlock,"maxLines"),t=Math.floor(t),t<=0&&U.G(t,"> 0",TextBlock,"maxLines"),this.Vs().Sy=t,this.g(),this.t("maxLines",i,t))}getMetrics(){return[this.xi,this.Hl,this.yo,this.Bn,this.Xe,this.bi,this.Vn||""]}u3(t){t!==void 0&&(this.xi=t[0],this.Hl=t[1],this.yo=t[2],this.Bn=t[3],this.Xe=t[4],this.bi=t[5],this.Vn=t[6])}get metrics(){return{arrSize:this.Xe!==null?this.Xe:[this.xi],arrText:this.bi!==null?this.bi:[this.Vn],maxLineWidth:this.xi,fontHeight:this.yo}}get choices(){return this.$d}set choices(t){const i=this.$d;i!==t&&(Debug&&t!==null&&!Array.isArray(t)&&U.Ti(t,"Array",TextBlock,"choices:value"),this.$d=t,this.t("choices",i,t))}static y3=new RegExp("[ \u200B\xAD]");static dC=new PropertyCollection;static VD=0;static aS=new PropertyCollection;static fC=0;static iy="...";static ED="";static ps=null;static Lp=!1;static uS=!1}class TextBlockTemplateSettings{wi;ws;wo;xy;Sy;ly;gy;my;ey;uy;fy;ql;dl;ny;yy;wy;constructor(){this.wi=!1,this.ws=null,this.wo=0,this.xy=0,this.Sy=1/0,this.ly=0,this.gy=0,this.my=0,this.ey="start",this.uy=null,this.fy=null,this.ql=null,this.dl=Spot.Top,this.ny=2,this.yy="0px",this.wy="0px"}copy(){const t=new TextBlockTemplateSettings;return t.ws=this.ws,t.wo=this.wo,t.xy=this.xy,t.Sy=this.Sy,t.ly=this.ly,t.gy=this.gy,t.my=this.my,t.ey=this.ey,t.uy=this.uy,t.fy=this.fy,t.ql=this.ql,t.dl=this.dl,t.ny=this.ny,t.yy=this.yy,t.wy=this.wy,t}}class GradElementSettings{Bc;Vc;zc;cy;Xc;constructor(){this.Bc=1,this.Vc=0,this.zc=1,this.cy=null,this.Xc=null}copy(){const t=new GradElementSettings;return t.Bc=this.Bc,t.Vc=this.Vc,t.zc=this.zc,t.cy=this.cy,t.Xc=this.Xc,t}}var ImageStretch=(w=>(w[w.None=0]="None",w[w.Fill=2]="Fill",w[w.Uniform=6]="Uniform",w[w.UniformToFill=7]="UniformToFill",w))(ImageStretch||{});class Picture extends GraphObject{gl;rn;pl;Yc;ws;yl;Kc;wo;Uc;Gc;Hb;constructor(t,i){super(),this.l|=2097152,this.gl=null,this.rn="",this.pl=Rect.$I,this.Yc=2,this.ws=null,this.yl=null,this.Kc=Spot.Center,this.wo=0,this.Uc=null,this.Gc=null,this.Hb=null,typeof t=="string"?this.source=t:t&&Object.assign(this,t),i&&Object.assign(this,i)}cloneProtected(t){super.cloneProtected(t),t.rn=this.rn,t.element=this.gl,t.pl=this.pl.T(),t.Yc=this.Yc,t.wo=this.wo,t.ws=this.ws,t.yl=this.yl,t.Kc=this.Kc.T(),t.Gc=this.Gc}gi(t){t in ImageStretch?this.imageStretch=t:super.gi(t)}toString(){return"Picture("+this.source+")#"+GSet.Ps(this)}get qc(){return(this.l&1048576)!==0}set qc(t){this.qc!==t&&(this.l=this.l^1048576)}get _a(){return(this.l&2097152)!==0}set _a(t){this._a!==t&&(this.l=this.l^2097152)}get Tn(){return(this.l&4194304)!==0}set Tn(t){this.Tn!==t&&(this.l=this.l^4194304)}static clearCache(t){t===void 0&&(t=""),U.i(t,"string",Picture,"clearCache:url"),t!==""?Picture.ky[t]&&(delete Picture.ky[t],Picture.gS--):(Picture.ky=new PropertyCollection,Picture.gS=0)}static LL(t,i){i.zD||(i.mS=e=>{Picture.w3(i,e),t.desiredSize.isReal()||(t.ke(!1),t.g())},i.pS=e=>Picture.x3(i,e),i.addEventListener("load",i.mS),i.addEventListener("error",i.pS),i.zD=!0)}static zO(t){t.mS&&t.removeEventListener("load",t.mS),t.pS&&t.removeEventListener("error",t.pS),delete t.mS,delete t.pS,t.zD=!1}get element(){return this.gl}set element(t){const i=this.gl;if(this._e(!0),i!==t){const e=Diagram.isUsingDOM();let s=!1;e&&(this.qc=t instanceof HTMLCanvasElement,s=t instanceof HTMLImageElement,t!==null&&!(s||t instanceof HTMLVideoElement||this.qc)&&U.n("Picture.element must be an instance of Image, Canvas, or Video, not: "+t));const n=this.diagram;n!==null&&n.Y2(this),this.gl=t,t!==null&&s&&t.ds===void 0&&(t.ds=new GSet),n!==null&&s&&n.X2(this),this.t("element",i,t),this.L()}}BO(){const t=this.gl;if(t===null)return;const i=this.desiredSize.isReal();(this.qc||t.complete===!0)&&(t.E0&&(t.Py instanceof Event&&this.ws!==null?this.ws(this,t.Py):t.Tn===!0&&!t.Py&&this.yl!==null&&t.gC&&this.yl(this,t.gC)),t.Tn=!0),t.Tn&&i&&this.diagram!==null&&this.diagram.cd.add(this)}b3(){if(this.gl===null){this.Uc=!1;return}const t=new CanvasSurface(null).ni;try{t.drawImage(this.gl,0,0)}catch(i){Debug&&this._a&&U.ot(i.toString()),this._a=!1}try{t.getImageData(0,0,1,1).data[3]&&(this.Uc=!1),this.Uc=!1}catch{this.Uc=!0}}get source(){return this.rn}set source(t){const i=this.rn;if(i!==t){this._e(!0),U.i(t,"string",Picture,"source"),this.rn=t;let e=Picture.ky,s=null;if(e[t]!==void 0)s=e[t];else if(t!==""){Picture.gS>30&&(Picture.clearCache(),e=Picture.ky),s=U.Le("img"),s.E0=!0,Picture.LL(this,s);const n=this.Gc;n!==null&&(s.crossOrigin=n(this)),s.src=t,e[t]=s,Picture.gS++}this.element=s,s!==null&&s.__goCache===void 0&&(s.__goCache=new PictureCacheArray),this.g(),this.L(),this.t("source",i,t)}}static w3(t,i){t.Tn=!0,t.Py=!1;let e;const s=t.ds.copy();if(s==null)return;const n=s.iterator;for(;n.next();){const o=n.value;o.L();const r=t.getAttribute("src")||"",l=o.ch.get(r);if(l===null)continue;const h=l.length;for(let a=0;a=r.width&&(l=l+y.offsetX+(m*y.x-r.width*y.x)),g>=r.height&&(h=h+y.offsetY+(g*y.y-r.height*y.y)),f=Math.min(r.width,m),c=Math.min(r.height,g);break;case 2:m=r.width,g=r.height;break;case 6:case 7:let D=0;p===6?(D=Math.min(r.height/g,r.width/m),m*=D,g*=D):p===7&&(D=Math.max(r.height/g,r.width/m),m*=D,g*=D,m>=r.width&&(l=(l+y.offsetX+(m*y.x-r.width*y.x)/m)*f),g>=r.height&&(h=(h+y.offsetY+(g*y.y-r.height*y.y)/g)*c),f*=1/(m/r.width),c*=1/(g/r.height),m=r.width,g=r.height);break}const x=f*c,b=this.getDocumentScale()*i.scale,S=m*b,k=g*b,P=S*k,A=x/P,C=e.__goCache;let M=null;const N=Picture.S3;if(!o){if(e.Tn&&C!==void 0&&u<8e3&&d<8e3&&P>4&&A>N*N){C.qt===null&&(C.XD(4,u,d,e),C.XD(16,u,d,e));const D=C.qt,F=D.length;for(let R=0;R0){const f=this.qt[this.qt.length-1];h=f.rn,a=f.Qd}o.setTransform(r*a,0,0,r*a,0,0),o.commitTransform(),o.drawImage(h,0,0),this.qt.push(l)}}class PictureCacheInstance{rn;Qd;constructor(t,i){this.rn=t,this.Qd=i}}class GeoStream{Li;wm;constructor(){this.wm=new Geometry,this.Li=null}Ki(t){t!==null?(this.wm=t,t.figures.clear()):this.wm=new Geometry,this.Li=null}Iu(t,i,e,s,n,o){if(s!==void 0&&s===!0){const r=new PathSegment(1);r.endX=t,r.endY=i,this.Li.segments.add(r)}else this.Li=new PathFigure,this.Li.startX=t,this.Li.startY=i,this.Li.isFilled=e,this.Li.isEvenOdd=o||!1,this.wm.figures.add(this.Li);n!==void 0&&(this.Li.isShadowed=n)}lR(){const t=this.Li.segments.length;t>0&&this.Li.segments.elt(t-1).close()}hR(){this.Li.segments.length>0&&(this.Li.isFilled=!0)}aR(t){this.Li.isShadowed=t}YB(t){this.Li.isEvenOdd=t}nR(t,i,e){e===void 0&&(e=!1);const s=new PathSegment(1);s.endX=t,s.endY=i,e&&s.close(),this.Li.segments.add(s)}Ws(t,i,e){e===void 0&&(e=!1);const s=new PathSegment(2);s.endX=t,s.endY=i,e&&s.close(),this.Li.segments.add(s)}Pr(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.Li.segments.add(l)}Ru(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.Li.segments.add(o)}oR(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.Li.segments.add(l)}rR(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.Li.segments.add(h)}static mC=null;static _A(t){const i=GeoStream.mC;if(i!==null)return GeoStream.mC=null,i.Ki(t),i;{const e=new GeoStream;return e.Ki(t),e}}static tT(t){GeoStream.mC=t}}{const w=function(n,o){const r=n.toLowerCase(),l=G.xn;l[n]=o,l[r]=n};w("Rectangle",(n,o,r)=>{const l="r"+o+","+r;let h=G.Sr[l];return h!==void 0||(h=new Geometry(2),h.endX=o,h.endY=r,G.kr{const l="s"+o+","+r;let h=G.Sr[l];return h!==void 0||(h=new Geometry(2),h.endX=o,h.endY=r,h.defaultStretch=6,G.kr{(isNaN(l)||l<0)&&(l=5),isNaN(h)&&(h=15);const a="rr"+o+","+r+","+l+","+h;let f=G.Sr[a];if(f!==void 0)return f;let c=l;(h&1)===1?(c=Math.min(c,(h&2)===2?o/3:o),c=Math.min(c,(h&8)===8?r/3:r)):c=0;const u=new PathFigure(c,0,!0);f=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*G.Zn;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*G.Zn;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*G.Zn;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=c*G.Zn;u.add(new PathSegment(2,0,c)).add(new PathSegment(3,c,0,0,g,g,0).close()),d.offsetX=g,d.offsetY=g}else u.add(new PathSegment(2,0,0).close());return f.spot1=d,f.spot2=m,G.kr{const l=n?n.parameter1:NaN,h=n?n.parameter2:NaN;return t(n,o,r,l,h)}),w("Border","RoundedRectangle"),w("RoundedTopRectangle",(n,o,r)=>{const l=n?n.parameter1:NaN;return t(n,o,r,l,3)}),w("RoundedBottomRectangle",(n,o,r)=>{const l=n?n.parameter1:NaN;return t(n,o,r,l,12)}),w("RoundedLeftRectangle",(n,o,r)=>{const l=n?n.parameter1:NaN;return t(n,o,r,l,9)}),w("RoundedRightRectangle",(n,o,r)=>{const l=n?n.parameter1:NaN;return t(n,o,r,l,6)}),w("Ellipse",(n,o,r)=>{const l="e"+o+","+r;let h=G.Sr[l];return h!==void 0||(h=new Geometry(3),h.endX=o,h.endY=r,h.spot1=Spot.zk,h.spot2=Spot.Xk,G.kr{const l="c"+o+","+r;let h=G.Sr[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,G.krnew 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)),w("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)),w("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)),w("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)),w("Triangle","TriangleUp"),w("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)),w("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}),w("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}),w("None","Rectangle"),w("BarH","Rectangle"),w("BarV","Rectangle"),w("MinusLine","LineH"),w("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)))),w("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)))),w("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)))),w("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)))),w("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)))),w("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)))),w("Capsule",(n,o,r)=>{const l=new Geometry;if(or){const h=r/2,a=new PathFigure(h,0,!0);l.add(a),a.add(new PathSegment(2,o-h,0)),a.add(new PathSegment(5,270,180,o-h,h,h,h)),a.add(new PathSegment(2,h,r)),a.add(new PathSegment(5,90,180,h,h,h,h));const f=isFinite(n.parameter1)?n.parameter1:r*.156;return l.setSpots(0,0,1,1,f,0,-f,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));w("Borders",(n,o,r)=>{let l=n?n.parameter1:NaN;isNaN(l)?l=10:l=l&15;const h=new Geometry;let a;return l===10?(a=i(o,0),e(a,o,r),s(a,0,r),e(a,0,0)):l===5?(a=i(0,0),e(a,o,0),s(a,o,r),e(a,0,r)):l===1?(a=i(0,0),e(a,o,0),s(a,o,r)):l===2?(a=i(o,0),e(a,o,r)):l===4?(a=i(o,r),e(a,0,r)):l===8?(a=i(0,r),e(a,0,0),s(a,o,r)):l===3?(a=i(0,0),e(a,o,0),e(a,o,r)):l===6?(a=i(o,0),e(a,o,r),e(a,0,r)):l===12?(a=i(o,r),e(a,0,r),e(a,0,0)):l===9?(a=i(0,r),e(a,0,0),e(a,o,0)):l===7?(a=i(0,0),e(a,o,0),e(a,o,r),e(a,0,r)):l===14?(a=i(o,0),e(a,o,r),e(a,0,r),e(a,0,0)):l===13?(a=i(o,r),e(a,0,r),e(a,0,0),e(a,o,0)):l===11?(a=i(0,r),e(a,0,0),e(a,o,0),e(a,o,r)):l===15?(a=i(0,0),e(a,o,0),e(a,o,r),e(a,0,r),a.add(new PathSegment(2,0,0).close())):(a=i(0,0),s(a,o,r)),h.add(a),h})}G.dm={"":"",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=(w=>(w[w.None=0]="None",w[w.Added=1]="Added",w[w.Removed=2]="Removed",w[w.Shown=4]="Shown",w[w.Hidden=8]="Hidden",w[w.NodeSized=16]="NodeSized",w[w.GroupLayout=32]="GroupLayout",w[w.NodeReplaced=64]="NodeReplaced",w[w.Standard=127]="Standard",w[w.All=16777215]="All",w))(LayoutConditions||{});class Part extends Panel{P;sr;J;wl;xl;nr;mi;bl;Bh;ln;or;_d;qM;YD;My;Ny;constructor(t,i){let e;t===void 0||t instanceof PanelLayout||typeof t=="string"?e=t:t&&(i=t),super(e),this.P=2408959,this.sr="",this.J=null,this.wl="",this.xl=null,this.nr=null,this.mi="",this.bl=null,this.Bh=null,this.ln=new Point(NaN,NaN).k(),this.or=null,this._d=NaN,this.qM=-1,this.YD=new Rect,this.My=null,this.Ny=NaN,i&&Object.assign(this,i)}cloneProtected(t){super.cloneProtected(t),t.P=this.P&-4097|16384|32768,t.sr=this.sr,this.J!==null&&(this.J.wi?t.J=this.J:t.J=this.J.copy()),t.wl=this.wl,t.nr=null,t.mi=this.mi,t.ln.c(this.ln),t._d=this._d}$o(t){super.$o(t),t.Lh(),t.xl=null,t.or=null,t.My=null}toString(){let t=U.Jn(this.constructor)+"#"+GSet.Ps(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;se(){return this.J===null?this.J=new PartTemplateSettings:this.J.wi&&(this.J=this.J.copy()),this.J}Ch(){super.Ch(),this.J!==null&&(this.J.wi=!0)}wc(t,i,e,s,n,o,r){const l=this.diagram;l!==null&&(t===3&&i==="elements"?n instanceof Panel?n.An(h=>{l.partManager.I2(h,l)}):n instanceof Picture&&l.X2(n):t===4&&i==="elements"&&(n instanceof Panel?n.An(h=>l.partManager.R2(h,l)):n instanceof Picture&&l.Y2(n)),l.raiseChangedEvent(t,i,e,s,n,o,r))}updateTargetBindings(t){if(super.updateTargetBindings(t),this.data===null)return;const i=this.O.h,e=i.length;for(let n=0;n{r.data!==null&&r.t3(t)})}const s=this.adornments;for(;s.next();)s.value.updateTargetBindings(t)}Wo(){if(super.Wo(),this.YN()){const i=this.O.h,e=i.length;for(let s=0;so.Wo())}}const t=this.adornments;for(;t.next();)t.value.Wo()}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.nr===null?EmptyIterator.instance:this.nr.iteratorValues}findAdornment(t){Debug&&U.i(t,"string",Part,"findAdornment:category");const i=this.nr;return i===null?null:i.get(t)}addAdornment(t,i){if(i===null)return;Debug&&(U.i(t,"string",Part,"addAdornment:category"),U.s(i,Adornment,Part,"addAdornment:ad"));let e=null,s=this.nr;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.nr=s),i.sr!==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){Debug&&U.i(t,"string",Part,"removeAdornment:category");const i=this.nr;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.nr=null)}clearAdornments(){const t=this.nr;if(t===null)return;const i=U.at(),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)}UM(t){this.bl=t,t===null&&this.xE()}get layer(){return this.bl}get diagram(){const t=this.bl;return t==null?null:t.diagram}get layerName(){return this.wl}set layerName(t){const i=this.wl;if(i===t)return;Debug&&U.i(t,"string",Part,"layerName");let e=this.diagram;if(e!==null&&(e.findLayer(t)===null||e.partManager.addsToTemporaryLayer))return;this.wl=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.ae(-1,this,!0);o>=0&&e.raiseChangedEvent(4,"parts",s,this,null,o,!0),o=n.ma(99999999,this,!0),s.visible!==n.visible&&this.Hi(n.visible),o>=0&&e.raiseChangedEvent(3,"parts",n,null,this,!0,o);const r=this.layerChanged;if(r===null)return;const l=e.H;e.H=!0,r(this,s,n),e.H=l}get layerChanged(){return this.J!==null?this.J.Cy:null}set layerChanged(t){const i=this.layerChanged;i!==t&&(t!==null&&U.C(t,Part,"layerChanged"),this.se().Cy=t,this.t("layerChanged",i,t))}get zOrder(){return this._d}set zOrder(t){const i=this._d;if(i===t)return;Debug&&U.i(t,"number",Part,"zOrder"),this._d=t;const e=this.layer;e!==null&&e.p1(-1,this),this.t("zOrder",i,t);const s=this.diagram;s!==null&&s.L()}M3(){const t=this.layer;t!==null&&t.p1(-1,this)}yS(){if(this.yh()!==!1)return;this.pC(!0),this.Sc();const t=this.diagram;t!==null&&(t.F0(this),t.requestUpdate())}GD(){if(this.P|=2097152,this.yh()===!1)return;const t=this.position,i=this.location;(!i.isReal()||!t.isReal())&&this.qD(t,i);const e=this.Oi,s=Rect.a().c(e);e.di(),e.x=t.x,e.y=t.y,e.k(),this.Ad(s,e),Rect.o(s),this.pC(!1),this.Sc()}fo(t,i,e,s){const n=this.ue;n.e(t,i,e,s),this.Ci===null&&(this.Ci=new Transform);const o=this.Ci;o.Ki(),this.J0(o,t,i,e,s),this.Ci=o,o.Yk()||o.am(n)}J0(t,i,e,s,n){if(this.lt!==1&&t.lt(this.lt),this.vt===0)return;let o=Spot.Center;this.locationSpot.isSpot()&&(o=this.locationSpot);const r=Point.a();if(this.locationObject!==this){const l=this.locationObject,h=l.naturalBounds;r.setSpot(h.x,h.y,h.width,h.height,o),l.Ci!==null&&l.Ci.St(r),r.offset(-l.measuredBounds.x,-l.measuredBounds.y);let a=l.panel;for(;a!==null&&a!==this;)a.Ci!==null&&a.Ci.St(r),r.offset(-a.measuredBounds.x,-a.measuredBounds.y),a=a.panel}else r.setSpot(i,e,s,n,o);t.Ns(this.vt,r.x,r.y),Point.o(r)}get locationObject(){if(this.or===null)if(this instanceof Adornment&&this.type!==Panel.Link&&this.hasPlaceholder())this.or=this.placeholder;else{const t=this.locationObjectName;if(t!==""){const i=this.findObject(t);i!==null?this.or=i:this.or=this}else this.or=this}return this.or?.visible?this.or:this}get minLocation(){return this.J!==null?this.J.Ay:Point.BA}set minLocation(t){const i=this.minLocation;i.equals(t)||(Debug&&U.s(t,Point,Part,"minLocation"),t=t.T(),this.se().Ay=t,this.t("minLocation",i,t))}get maxLocation(){return this.J!==null?this.J.Ty:Point.VA}set maxLocation(t){const i=this.maxLocation;i.equals(t)||(Debug&&U.s(t,Point,Part,"maxLocation"),t=t.T(),this.se().Ty=t,this.t("maxLocation",i,t))}get locationObjectName(){return this.J!==null?this.J.Ly:""}set locationObjectName(t){const i=this.locationObjectName;i!==t&&(Debug&&U.i(t,"string",Part,"locationObjectName"),this.se().Ly=t,this.or=null,this.g(),this.t("locationObjectName",i,t))}get locationSpot(){return this.J!==null?this.J.Dy:Spot.TopLeft}set locationSpot(t){const i=this.locationSpot;i.equals(t)||(Debug&&(U.s(t,Spot,Part,"locationSpot"),t.isSpot()||U.n("Part.locationSpot must be a specific Spot value, not: "+t)),t=t.T(),this.se().Dy=t,this.g(),this.t("locationSpot",i,t))}move(t,i){i===!0?this.location=t:this.position=t}moveTo(t,i,e){const s=Point.U(t,i);this.move(s,e),Point.o(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.e1(this))return!0}const i=this.containingGroup;return!(i!==null&&(!i.isSubGraphExpanded||!i.isVisible()))}Hi(t){const i=this.diagram;t?(this.invalidateLayout(4),this.invalidateAdornments(),i!==null&&i.F0(this)):(this.invalidateLayout(8),this.clearAdornments()),this.Lh(),i!==null&&(i.invalidateDocumentBounds(),this instanceof Node&&this.canAvoid()&&i.yd(this),i.L())}findObject(t){if(this.name===t)return this;let i=this.My;if(i===null&&(this.My=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)}hp(){this.My=null}getRelativePoint(t,i,e){e===void 0&&(e=new Point);const s=i.isNoSpot()?Spot.Center:i,n=t.naturalBounds;if(e.e(n.width*s.x+s.offsetX,n.height*s.y+s.offsetY),t===null||t===this)return e;t.E.St(e);let o=t.panel;for(;o!==null&&o!==this;)o.E.St(e),o=o.panel;return this.Ci!==null&&this.Ci.St(e),e.offset(-this.ue.x,-this.ue.y),e}getDocumentBounds(t){return t===void 0&&(t=new Rect),t.c(this.actualBounds)}ensureBounds(){this.gt(1/0,1/0),this.Ut()}yD(t){const i=this.locationSpot,e=this.locationObject;let s=e.naturalBounds;s.isReal()||(s=Rect.lm);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.E.St(t);let o=e.panel;for(;o!==null&&o!==this;)o.E.St(t),o=o.panel}return this.Ci!==null&&this.Ci.St(t),t.offset(-this.ue.x,-this.ue.y),t}ga(t,i){const e=i===void 0?this.YD:i,s=this.N3(),n=s*2;if(!this.isShadowed)return e.e(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 a=this.shadowBlur,f=this.shadowOffset;return l+=a,h+=a,o-=a/2,r-=a/2,f.x>0?l+=f.x:(o+=f.x,l-=f.x),f.y>0?h+=f.y:(r+=f.y,h-=f.y),e.e(o-1,r-1,l+2,h+2),e}l3(){return this.type===Panel.Link&&this instanceof Adornment&&this.category==="Selection"&&this.adornedObject instanceof Shape&&this.adornedPart.findMainElement()===this.adornedObject?this.adornedObject.strokeWidth:0}N3(){return isNaN(this.Ny)&&(this.Ny=this.MD()),this.Ny}Oc(){this.Ny=NaN}Ut(){if(this.us()===!1){this.GD();return}this.co(!1);const t=this.Oi,i=Rect.a();i.c(t);const e=this.Kl();this.Th(0,0,this.ue.width,this.ue.height);const s=this.position;this.qD(s,this.location),t.di(),t.x=s.x,t.y=s.y,t.k(),this.Ad(i,t),i.equals(t)?this.fs(e):this.Oe()&&(!G.u(i.width,t.width)||!G.u(i.height,t.height))&&this.qM>=0&&this.invalidateLayout(16),Rect.o(i),this.pC(!1)}Ad(t,i){const e=this.diagram;if(e===null)return;let s=!1;if(e.ba===!1&&t.isReal()){const n=Rect.a();n.c(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.P=this.P^4096;let s=!1;if(e!==null){s=e.skipsUndoManager,e.skipsUndoManager=!0;const o=e.selection;o.di(),t?o.add(this):o.delete(this),o.k()}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.P&524288)!==0}set isHighlighted(t){const i=(this.P&524288)!==0;if(i!==t){Debug&&U.i(t,"boolean",Part,"isHighlighted"),this.P=this.P^524288;const e=this.diagram;if(e!==null){const n=e.highlighteds;n.di(),t?n.add(this):n.delete(this),n.k()}this.t("isHighlighted",i,t),this.L();const s=this.highlightedChanged;s!==null&&s(this)}}get isShadowed(){return(this.P&8192)!==0}set isShadowed(t){const i=(this.P&8192)!==0;i!==t&&(Debug&&U.i(t,"boolean",Part,"isShadowed"),this.P=this.P^8192,this._e(!0),this.t("isShadowed",i,t),this.L())}KD(){return(this.P&16384)!==0}UD(t){t?this.P|=16384:this.P&=-16385}yh(){return(this.P&32768)!==0}pC(t){t?this.P|=32768:this.P&=-32769}C3(){return(this.P&65536)!==0}IN(t){t?this.P|=65536:this.P&=-65537}Kl(){return(this.P&131072)!==0}fs(t){t?this.P|=131072:this.P&=-131073}JD(){return(this.P&1048576)!==0}wS(t){t?this.P|=1048576:this.P&=-1048577}get isAnimated(){return(this.P&262144)!==0}set isAnimated(t){const i=(this.P&262144)!==0;i!==t&&(Debug&&U.i(t,"boolean",Part,"isAnimated"),this.P=this.P^262144,this.t("isAnimated",i,t))}get highlightedChanged(){return this.J!==null?this.J.Fy:null}set highlightedChanged(t){const i=this.highlightedChanged;i!==t&&(t!==null&&U.C(t,Part,"highlightedChanged"),this.se().Fy=t,this.t("highlightedChanged",i,t))}get selectionObjectName(){return this.J!==null?this.J.Iy:""}set selectionObjectName(t){const i=this.selectionObjectName;i!==t&&(Debug&&U.i(t,"string",Part,"selectionObjectName"),this.se().Iy=t,this.xl=null,this.t("selectionObjectName",i,t))}get selectionAdornmentTemplate(){return this.J!==null?this.J.Ry:null}set selectionAdornmentTemplate(t){const i=this.selectionAdornmentTemplate;i!==t&&(t!==null&&(U.s(t,Adornment,Part,"selectionAdornmentTemplate"),t.Yt()),this.se().Ry=t,this.t("selectionAdornmentTemplate",i,t))}get selectionObject(){if(this.xl===null){const t=this.selectionObjectName;if(t!==null&&t!==""){const i=this.findObject(t);i!==null?this.xl=i:this.xl=this}else if(this instanceof Link){const i=this.path;i!==null?this.xl=i:this.xl=this}else this.xl=this}return this.xl}get selectionChanged(){return this.J!==null?this.J.Oy:null}set selectionChanged(t){const i=this.selectionChanged;i!==t&&(t!==null&&U.C(t,Part,"selectionChanged"),this.se().Oy=t,this.t("selectionChanged",i,t))}get resizeAdornmentTemplate(){return this.J!==null?this.J.Ey:null}set resizeAdornmentTemplate(t){const i=this.resizeAdornmentTemplate;i!==t&&(Debug&&U.s(t,Adornment,Part,"resizeAdornmentTemplate"),this.se().Ey=t!==null?t.Yt():null,this.t("resizeAdornmentTemplate",i,t))}get resizeObjectName(){return this.J!==null?this.J.By:""}set resizeObjectName(t){const i=this.resizeObjectName;i!==t&&(Debug&&U.i(t,"string",Part,"resizeObjectName"),this.se().By=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.Vy:Size.ex}set resizeCellSize(t){const i=this.resizeCellSize;i.equals(t)||(Debug&&U.s(t,Size,Part,"resizeCellSize"),t=t.T(),this.se().Vy=t,this.t("resizeCellSize",i,t))}get rotateAdornmentTemplate(){return this.J!==null?this.J.zy:null}set rotateAdornmentTemplate(t){const i=this.rotateAdornmentTemplate;i!==t&&(Debug&&U.s(t,Adornment,Part,"rotateAdornmentTemplate"),this.se().zy=t!==null?t.Yt():null,this.t("rotateAdornmentTemplate",i,t))}get rotateObjectName(){return this.J!==null?this.J.Xy:""}set rotateObjectName(t){const i=this.rotateObjectName;i!==t&&(Debug&&U.i(t,"string",Part,"rotateObjectName"),this.se().Xy=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.Yy:Spot.Default}set rotationSpot(t){const i=this.rotationSpot;i.equals(t)||(Debug&&(U.s(t,Spot,Part,"rotationSpot"),t!==Spot.Default&&!t.isSpot()&&U.n("Part.rotationSpot must be a specific Spot value or Spot.Default, not: "+t)),t=t.T(),this.se().Yy=t,this.t("rotationSpot",i,t))}get text(){return this.mi}set text(t){const i=this.mi;i!==t&&(Debug&&U.i(t,"string",Part,"text"),this.mi=t,this.t("text",i,t))}get containingGroup(){return this.Bh}set containingGroup(t){if(this.Oe()){const i=this.Bh;if(i!==t){Debug&&t!==null&&U.s(t,Group,Part,"containingGroup"),t!==null&&(this===t||t.isMemberOf(this))&&(this===t&&U.n("Cannot make a Group a member of itself: "+this.toString()),U.n("Cannot make a Group indirectly contain itself: "+this.toString()+" already contains "+t.toString())),this.invalidateLayout(2);const e=this.diagram;if(i!==null?i.wC(this):this instanceof Group&&e!==null&&e.il.delete(this),this.Bh=t,t!==null?t.xC(this):this instanceof Group&&e!==null&&e.il.add(this),this.invalidateLayout(1),e!==null&&e.H){const n=this.data,o=e.model;if(n!==null&&o.Oa()){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.H,e.H=!0),s(this,i,t),e!==null&&(e.H=n)}if(this instanceof Group){const n=new GSet;Part.bh(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.tg()}}}if(this instanceof Node){const n=this.linksConnected;for(;n.next();)n.value.tg();const o=this.labeledLink;o!==null&&o.tg()}this.t("containingGroup",i,t),t!==null&&t.M3()}}else U.n("cannot set the Part.containingGroup of a Link or Adornment")}Lh(){const t=this.containingGroup;t!==null&&(t.hasPlaceholder()&&t.placeholder.g(),t.g(),t.invalidateConnectedLinks())}L(){const t=this.diagram;t!==null&&!this.us()&&!this.yh()&&this.isVisible()&&this.Oi.isReal()&&t.L(this.ga(this.Oi))}g(){if(this.vo())return;super.g();const t=this.diagram;t!==null&&(t.F0(this),this instanceof Node&&this.labeledLink!==null&&this.labeledLink.Cc(),t.requestUpdate(!0))}Cc(t){if(this.us())return;const i=this.diagram;i!==null&&(i.F0(this),this instanceof Node&&this.invalidateConnectedLinks(),i.requestUpdate()),this.co(!0)}r0(t){if(!t){const i=this.Bh;i!==null&&i.xC(this)}}l0(t){if(!t){const i=this.Bh;i!==null&&i.wC(this)}}uc(){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.Ky:null}set containingGroupChanged(t){const i=this.containingGroupChanged;i!==t&&(t!==null&&U.C(t,Part,"containingGroupChanged"),this.se().Ky=t,this.t("containingGroupChanged",i,t))}findSubGraphLevel(){return this.bC(this)}bC(t){const i=t.containingGroup;if(i!==null)return 1+this.bC(i);if(t instanceof Node){const e=t.labeledLink;if(e!==null)return this.bC(e)}return 0}findTopLevelPart(){return this.SC(this)}SC(t){const i=t.containingGroup;if(i!==null)return this.SC(i);if(t instanceof Node){const e=t.labeledLink;if(e!==null)return this.SC(e)}return t}get isTopLevel(){return!(this.containingGroup!==null||this instanceof Node&&this.labeledLink!==null)}isMemberOf(t){return t instanceof Group?this.kC(this,t):!1}kC(t,i){if(t===i||i===null)return!1;const e=t.containingGroup;if(e!==null&&(e===i||this.kC(e,i)))return!0;if(t instanceof Node){const s=t.labeledLink;if(s!==null)return this.kC(s,i)}return!1}findCommonContainingGroup(t){if(t===null)return null;if(Debug&&U.s(t,Part,Part,"findCommonContainingGroup:other"),this===t)return this.containingGroup;let i=this;for(;i!==null;){if(i instanceof Group&&i.wS(!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.JD()){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.wS(!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.Uy:127}set layoutConditions(t){const i=this.layoutConditions;i!==t&&(Debug&&U.i(t,"number",Part,"layoutConditions"),this.se().Uy=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)}T3(t){if(!this.isLayoutPositioned||(t&this.layoutConditions)===0)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.T3(t))return;const i=this.Bh;if(i!==null){const e=i.layout;e!==null?e.b():i.invalidateLayout(t)}else{const e=this.diagram;if(e!==null){const s=e.layout;s!==null&&s.b()}}}bL(){if(!this.isVisible())return!1;const t=this.layer;return!(t!==null&&t.isTemporary)}static bh(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.bh(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,a=l.toNode,f=h===null||t.has(h),c=a===null||t.has(a);(n?f&&c:f||c)&&Part.bh(t,l,e,s,n,o)}}if(s>1){const r=i.findTreeChildrenNodes();for(;r.next();){const l=r.value;Part.bh(t,l,e,s-1,n,o)}}}else if(i instanceof Link){const r=i.labelNodes;for(;r.next();){const l=r.value;Part.bh(t,l,e,s,n,o)}}}}get dragComputation(){return this.J!==null?this.J.Gy:null}set dragComputation(t){const i=this.dragComputation;i!==t&&(t!==null&&U.C(t,Part,"dragComputation"),this.se().Gy=t,this.t("dragComputation",i,t))}get shadowOffset(){return this.J!==null?this.J.qy:Point.zA}set shadowOffset(t){const i=this.shadowOffset;i.equals(t)||(Debug&&U.s(t,Point,Part,"shadowOffset"),t=t.T(),this.se().qy=t,this.L(),this.t("shadowOffset",i,t))}get shadowColor(){return this.J!==null?this.J.Hy:"gray"}set shadowColor(t){const i=this.shadowColor;i!==t&&(Debug&&U.i(t,"string",Part,"shadowColor"),this.se().Hy=t,this.L(),this.t("shadowColor",i,t))}get shadowBlur(){return this.J!==null?this.J.In:4}set shadowBlur(t){const i=this.shadowBlur;i!==t&&(Debug&&U.i(t,"number",Part,"shadowBlur"),this.se().In=t,this.L(),this.t("shadowBlur",i,t))}}class PartTemplateSettings{wi;Cy;Ky;Ry;Iy;Oy;Fy;Ey;By;Vy;zy;Xy;Yy;Ly;Dy;Ay;Ty;Gy;Uy;qy;Hy;In;constructor(){this.wi=!1,this.Cy=null,this.Ky=null,this.Ry=null,this.Iy="",this.Oy=null,this.Fy=null,this.Ey=null,this.By="",this.Vy=Size.ex,this.zy=null,this.Xy="",this.Yy=Spot.Default,this.Ly="",this.Dy=Spot.TopLeft,this.Ay=Point.BA,this.Ty=Point.VA,this.Gy=null,this.Uy=127,this.qy=Point.zA,this.Hy="gray",this.In=4}copy(){const t=new PartTemplateSettings;return t.Cy=this.Cy,t.Ky=this.Ky,t.Ry=this.Ry,t.Iy=this.Iy,t.Oy=this.Oy,t.Fy=this.Fy,t.Ey=this.Ey,t.By=this.By,t.Vy=this.Vy.T(),t.zy=this.zy,t.Xy=this.Xy,t.Yy=this.Yy.T(),t.Ly=this.Ly,t.Dy=this.Dy.T(),t.Ay=this.Ay.T(),t.Ty=this.Ty.T(),t.Gy=this.Gy,t.Uy=this.Uy,t.qy=this.qy.T(),t.Hy=this.Hy,t.In=this.In,t}}class Adornment extends Part{Ts;Rt;tM;iM;Ic;constructor(t,i){let e;t===void 0||t instanceof PanelLayout||typeof t=="string"?e=t:t&&(i=t),super(e),this.P&=-257,this.wl="Adornment",this.Ts=null,this.tM=0,this.iM=!1,this.Rt=null,this.Ic=null,i&&Object.assign(this,i)}toString(){const t=this.adornedPart;return"Adornment("+this.category+")"+(t!==null?t.toString():"")}updateRelationshipsFromData(){}Ed(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.Ed(t),n=s.geometry;const o=this.O.h,r=o.length;for(let l=0;lh instanceof Placeholder);l instanceof Placeholder&&(this.Rt===null?this.Rt=l:Debug&&this.Rt!==l&&U.n("Cannot insert a second Placeholder into the visual tree of an Adornment."))}}else t===4&&i==="elements"&&this.Rt!==null&&(s===this.Rt?this.Rt=null:s instanceof Panel&&this.Rt.isContainedBy(s)&&(this.Rt=null));super.wc(t,i,e,s,n,o,r)}updateAdornments(){}uc(){}}var PortSpreading=(w=>(w[w.None=0]="None",w[w.Evenly=1]="Evenly",w[w.Packed=2]="Packed",w))(PortSpreading||{});class Node extends Part{z;Bt;Hc;Sl;Vh;de;ri;constructor(t,i){let e;t===void 0||t instanceof PanelLayout||typeof t=="string"?e=t:t&&(i=t),super(e),this.z=13,this.Bt=null,this.ri=new List,this.Hc=null,this.Sl=null,this.de=null,this.Vh=!1,i&&Object.assign(this,i)}cloneProtected(t){super.cloneProtected(t),t.z=this.z,this.Bt!==null&&(this.Bt.wi?t.Bt=this.Bt:t.Bt=this.Bt.copy())}$o(t){super.$o(t),t.invalidateConnectedLinks(),t.Sl=this.Sl,t.de=null}static SpreadingNone=0;static SpreadingEvenly=1;static SpreadingPacked=2;kl(){return this.Bt===null?this.Bt=new NodeTemplateSettings:this.Bt.wi&&(this.Bt=this.Bt.copy()),this.Bt}Ch(){super.Ch(),this.Bt!==null&&(this.Bt.wi=!0)}$D(t){t!==null&&(this.Sl===null&&(this.Sl=new GSet),this.Sl.add(t))}ZD(t){t!==null&&this.Sl!==null&&this.Sl.delete(t)}QD(t,i,e){if(t===null||this.Sl===null)return null;const s=this.Sl.iterator;for(;s.next();){const n=s.value;if(n.vy===this&&n.xS===t&&n.PC===i&&n.MC===e||n.vy===t&&n.xS===this&&n.PC===e&&n.MC===i)return n}return null}invalidateLinkBundle(t,i,e){i==null&&(i=""),e==null&&(e="");const s=this.QD(t,i,e);s!==null&&s.ig()}wc(t,i,e,s,n,o,r){t===3&&i==="elements"?this.de=null:t===4&&i==="elements"&&(this.de=null),super.wc(t,i,e,s,n,o,r)}invalidateConnectedLinks(t,i){const e=this.linksConnected;for(;e.next();){const s=e.value;t&&t.has(s)||i&&s.fromPort!==i&&s.toPort!==i||(this.ie(s.fromPort),this.ie(s.toPort),s.ii())}}ie(t){if(t===null)return;const i=t.Pd;i!==null&&i.ig();const e=t.part,s=e.containingGroup;s!==null&&!e.isVisible()&&s.ie(s.port)}sl(){return!0}get portSpreading(){return this.Bt!==null?this.Bt.Wy:1}set portSpreading(t){const i=this.portSpreading;if(i!==t){Debug&&t!==0&&t!==1&&t!==2&&U.n("Node.portSpreading can only be set to PortSpreading.None, PortSpreading.Evenly, or PortSpreading.Packed, not: "+t),this.kl().Wy=t,this.t("portSpreading",i,t);const e=this.diagram;if(e!==null&&e.undoManager.isUndoingRedoing)return;this.invalidateConnectedLinks()}}get avoidable(){return(this.z&8)!==0}set avoidable(t){const i=(this.z&8)!==0;if(i!==t){Debug&&U.i(t,"boolean",Node,"avoidable"),this.z=this.z^8;const e=this.diagram;e!==null&&e.yd(this),this.t("avoidable",i,t)}}get avoidableMargin(){return this.Bt!==null?this.Bt.jy:Margin.HA}set avoidableMargin(t){typeof t=="number"?t=new Margin(t):U.s(t,Margin,Node,"avoidableMargin");const i=this.avoidableMargin;if(!i.equals(t)){t=t.T(),this.kl().jy=t;const e=this.diagram;e!==null&&e.yd(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.e1(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}Hi(t){super.Hi(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.ii()}e.Hi(t)}}get linksConnected(){return this.ri.iterator}findExternalTreeLinksConnected(){const t=new GSet,i=new GSet;return this._D(this,t,i),i.iterator}_D(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._D(s?o.toNode:o.fromNode,i,e):e.add(o)})}findLinksConnected(t){if(t===void 0&&(t=null),t===null)return this.ri.iterator;Debug&&U.i(t,"string",Node,"findLinksConnected:pid");const i=new ListIterator(this.ri),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),Debug&&t!==null&&U.i(t,"string",Node,"findLinksOutOf:pid");const i=new ListIterator(this.ri),e=this;return i.predicate=s=>s.fromNode!==e?!1:t===null?!0:s.fromPortId===t,i}findLinksInto(t){t===void 0&&(t=null),Debug&&t!==null&&U.i(t,"string",Node,"findLinksInto:pid");const i=new ListIterator(this.ri),e=this;return i.predicate=s=>s.toNode!==e?!1:t===null?!0:s.toPortId===t,i}findNodesConnected(t){t===void 0&&(t=null),Debug&&t!==null&&U.i(t,"string",Node,"findNodesConnected:pid");let i=null,e=null;const s=this.ri.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),Debug&&t!==null&&U.i(t,"string",Node,"findNodesOutOf:pid");let i=null,e=null;const s=this.ri.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),Debug&&t!==null&&U.i(t,"string",Node,"findNodesInto:pid");let i=null,e=null;const s=this.ri.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),Debug&&(U.s(t,Node,Node,"findLinksBetween:othernode"),i!==null&&U.i(i,"string",Node,"findLinksBetween:pid"),e!==null&&U.i(e,"string",Node,"findLinksBetween:otherpid"));const s=new ListIterator(this.ri),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),Debug&&(U.s(t,Node,Node,"findLinksTo:othernode"),i!==null&&U.i(i,"string",Node,"findLinksTo:pid"),e!==null&&U.i(e,"string",Node,"findLinksTo:otherpid"));const s=new ListIterator(this.ri),n=this;return s.predicate=o=>!(o.fromNode!==n||o.toNode!==t||i!==null&&o.fromPortId!==i||e!==null&&o.toPortId!==e),s}findSuccessorParts(t){return t===void 0&&(t=new GSet),this.tF(this,t),t.remove(this),t}tF(t,i){t!==null&&(i.has(t)||(i.add(t),t.findLinksOutOf().each(e=>{if(i.has(e))return;i.add(e);const s=e.toNode;s!==null&&this.tF(s,i)})))}findPredecessorParts(t){return t===void 0&&(t=new GSet),this.iF(this,t),t.remove(this),t}iF(t,i){t!==null&&(i.has(t)||(i.add(t),t.findLinksInto().each(e=>{if(i.has(e))return;i.add(e);const s=e.fromNode;s!==null&&this.iF(s,i)})))}get linkConnected(){return this.Bt!==null?this.Bt.Jy:null}set linkConnected(t){const i=this.linkConnected;i!==t&&(t!==null&&U.C(t,Node,"linkConnected"),this.kl().Jy=t,this.t("linkConnected",i,t))}get linkDisconnected(){return this.Bt!==null?this.Bt.$y:null}set linkDisconnected(t){const i=this.linkDisconnected;i!==t&&(t!==null&&U.C(t,Node,"linkDisconnected"),this.kl().$y=t,this.t("linkDisconnected",i,t))}get linkValidation(){return this.Bt!==null?this.Bt.Yl:null}set linkValidation(t){const i=this.linkValidation;i!==t&&(t!==null&&U.C(t,Node,"linkValidation"),this.kl().Yl=t,this.t("linkValidation",i,t))}bS(t,i){this.ie(i);const e=this.ri.has(t);if(e||this.ri.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.H,o.H=!0),s(this,t,i),o!==null&&(o.H=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.Vh||(l.Vh=h),h.isTreeLeaf){if(r!==null&&r.undoManager.isUndoingRedoing)return;o?s===h&&(h.isTreeLeaf=!1):n===h&&(h.isTreeLeaf=!1)}}}}SS(t,i){this.ie(i);const e=this.ri.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.H,s.H=!0),n(this,t,i),s!==null&&(s.H=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.Vh=!1),r!==null&&!r.isTreeLeaf)if(r.ri.count===0){if(r.Vh=null,s!==null&&s.undoManager.isUndoingRedoing)return;r.isTreeLeaf=!0}else r.B0()}}B0(){if(this.Vh=!1,this.ri.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.ri.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)}r0(t){if(super.r0(t),!t){this.B0();const i=this.Hc;i!==null&&i.eF(this)}}l0(t){if(super.l0(t),!t){const i=this.Hc;i!==null&&i.sF(this)}}uc(){if(this.ri.count>0){const t=this.diagram;if(t!==null){const i=t.commandHandler!==null?t.commandHandler.deletesConnectedLinks:!0,s=this.ri.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.uc()}get isLinkLabel(){return this.Hc!==null}get labeledLink(){return this.Hc}set labeledLink(t){const i=this.Hc;if(i!==t){Debug&&t!==null&&U.s(t,Link,Node,"labeledLink");const e=this.diagram,s=this.data;if(i!==null){if(i.sF(this),e!==null&&s!==null&&!e.undoManager.isUndoingRedoing){const n=i.data,o=e.model;if(n!==null&&o.tf()){const r=o.getKeyForNodeData(s);r!==void 0&&o.removeLabelKeyForLinkData(n,r)}}this.containingGroup=null}if(this.Hc=t,t!==null){if(t.eF(this),e!==null&&s!==null&&!e.undoManager.isUndoingRedoing){const n=t.data,o=e.model;if(n!==null&&o.tf()){const r=o.getKeyForNodeData(s);r!==void 0&&o.addLabelKeyForLinkData(n,r)}}this.containingGroup=t.containingGroup}this.Cc(),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(Debug&&U.i(t,"string",Node,"findPort:pid"),this.de===null){if(t===""&&this.Fn===!1)return this;this.nF()}let i=this.de.get(t);return i!==null||t!==""&&(i=this.de.get(""),i!==null)?i:this}get port(){return this.findPort("")}get ports(){return this.de===null&&this.nF(),this.de.iteratorValues}nF(){this.de===null?this.de=new GMap:this.de.clear(),this.walkVisualTreeFrom(this,(t,i)=>t.fD(i)),this.de.count===0&&this.de.set("",this)}fD(t){const i=t.portId;i!==null&&this.de!==null&&this.de.set(i,t)}XN(t,i){const e=t.portId;if(e!==null){this.de!==null&&this.de.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.at()),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.ri.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,i){return t===void 0&&(t=1/0),U.i(t,"number",Node,"findTreeParts:level"),i===void 0&&(i=new GSet),Part.bh(i,this,!1,t,!0),i}collapseTree(t){t===void 0&&(t=1),U.r(t,Node,"collapseTree:level"),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.oF(e,i.isTreePathToChildren,t,i,this,i.treeCollapsePolicy===1),i.isCollapsingExpanding=!1}oF(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.oF(t,i,e-1,s,n,o))}}else this.rF(t,i,s,n,o)}rF(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 a=t.has(h);if(a||t.add(h),o){const f=i?h.findNodesInto():h.findNodesOutOf(),c=this;f.all(u=>u===c||!u.isTreeExpanded)&&e.$f(h,s),h.Lh(),h.Hi(!1)}h.isTreeExpanded&&(h.wasTreeExpanded=h.isTreeExpanded,a||h.rF(t,i,e,s,n))}}this.isTreeExpanded=!1}expandTree(t){t===void 0&&(t=2),U.r(t,Node,"expandTree:level"),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.lF(e,i.isTreePathToChildren,t,i,this,i.treeCollapsePolicy===1),i.isCollapsingExpanding=!1}lF(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.Be||h.ii();const a=h.getOtherNode(this);if(a!==null&&a!==this&&!t.has(a)){if(t.add(a),!r){a.Hi(!0),a.Lh();const f=i?a.findNodesInto():a.findNodesOutOf(),c=this;f.all(u=>u===c||!u.isTreeExpanded)&&s.Jf(a,n)}(e>2||a.wasTreeExpanded)&&(a.wasTreeExpanded=!1,a.lF(t,i,e-1,s,n,o))}}this.isTreeExpanded=!0}get isTreeExpanded(){return(this.z&1)!==0}set isTreeExpanded(t){const i=(this.z&1)!==0;if(i!==t){Debug&&U.i(t,"boolean",Node,"isTreeExpanded"),this.z=this.z^1;const e=this.diagram;this.t("isTreeExpanded",i,t);const s=this.treeExpandedChanged;if(s!==null){let n=!0;e!==null&&(n=e.H,e.H=!0),s(this),e!==null&&(e.H=n)}if(e!==null&&e.undoManager.isUndoingRedoing){this.Hi(t);return}t?this.expandTree():this.collapseTree()}}get wasTreeExpanded(){return(this.z&2)!==0}set wasTreeExpanded(t){const i=(this.z&2)!==0;i!==t&&(Debug&&U.i(t,"boolean",Node,"wasTreeExpanded"),this.z=this.z^2,this.t("wasTreeExpanded",i,t))}get treeExpandedChanged(){return this.Bt!==null?this.Bt.Zy:null}set treeExpandedChanged(t){const i=this.treeExpandedChanged;i!==t&&(t!==null&&U.C(t,Node,"treeExpandedChanged"),this.kl().Zy=t,this.t("treeExpandedChanged",i,t))}get isTreeLeaf(){return(this.z&4)!==0}set isTreeLeaf(t){const i=(this.z&4)!==0;i!==t&&(Debug&&U.i(t,"boolean",Node,"isTreeLeaf"),this.z=this.z^4,this.t("isTreeLeaf",i,t))}get isTreeRoot(){return this.findTreeParentLink()===null}}class NodeTemplateSettings{wi;Jy;$y;Yl;Zy;jy;Wy;Qy;_y;xh;tw;constructor(){this.wi=!1,this.Jy=null,this.$y=null,this.Yl=null,this.Zy=null,this.jy=Margin.HA,this.Wy=1,this.Qy=null,this._y=null,this.xh=null,this.tw=null}copy(){const t=new NodeTemplateSettings;return t.Jy=this.Jy,t.$y=this.$y,t.Yl=this.Yl,t.Zy=this.Zy,t.jy=this.jy.T(),t.Wy=this.Wy,t.Qy=this.Qy,t._y=this._y,t.xh=this.xh,t.tw=this.tw,t}}var LinkAdjusting=(w=>(w[w.None=0]="None",w[w.End=17]="End",w[w.Scale=18]="Scale",w[w.Stretch=19]="Stretch",w))(LinkAdjusting||{}),Routing=(w=>(w[w.Normal=1]="Normal",w[w.Orthogonal=2]="Orthogonal",w[w.AvoidsNodes=6]="AvoidsNodes",w[w.AvoidsNodesStraight=7]="AvoidsNodesStraight",w))(Routing||{}),Curve=(w=>(w[w.None=0]="None",w[w.Bezier=9]="Bezier",w[w.JumpGap=10]="JumpGap",w[w.JumpOver=11]="JumpOver",w))(Curve||{});class Link extends Part{Lt;xo;bo;eg;So;ko;sg;vc;ng;og;rg;ef;lg;hn;Ai;Ye;Er;Pl;rr;NC;CC;kS;AC;TC;sf;PS;xt;lr;static nf=null;static of=null;Ic;LC;DC;constructor(t){super(Panel.Link),this.Lt=8,this.xo=null,this.bo="",this.eg=null,this.So=null,this.ko="",this.sg=null,this.vc=0,this.ng=0,this.og=0,this.rg=NaN,this.ef=1,this.lg=.5,this.hn=null,this.Ai=new List().k(),this.Ye=null,this.Er=null,this.Pl=new Rect,this.xt=new Geometry,this.rr=null,this.lr=null,this.NC=Point.wn,this.CC=Point.wn,this.LC=0,this.DC=0,this.kS=new Point,this.AC=null,this.TC=null,this.sf=null,this.PS=NaN,this.wt=null,this.Ic=[],t&&Object.assign(this,t)}cloneProtected(t){super.cloneProtected(t),t.Lt=this.Lt&-113,t.bo=this.bo,t.eg=this.eg,t.ko=this.ko,t.sg=this.sg,t.vc=this.vc,t.ng=this.ng,t.og=this.og,t.rg=this.rg,t.ef=this.ef,t.lg=this.lg,this.wt!==null&&(t.wt=this.wt.copy())}$o(t){super.$o(t),this.bo=t.bo,this.ko=t.ko,t.Ye=null,t.ii(),t.lr=this.lr;const i=t.fromPort;i!==null&&t.fromNode.ie(i);const e=t.toPort;e!==null&&t.toNode.ie(e)}gi(t){t in Routing||t in Curve||t in LinkAdjusting?Link.FC(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.n("Unknown Link enum value for a Link property: "+t):super.gi(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 hF=8;static aF=16;static zh=8;static sS=3;static fF=3;static cF=1.333;static IC=1;static RC=0;static uF=10;static Wc=9999;static dF=30;static gF=30;static OC=10;static mF=10;static pF=14;static yF=30;static wF=14;static oL=8;static rL=8;static xF=11;static setRoutingParameter(t,i){switch(t){case 1:Link.hF=i;break;case 2:Link.aF=i;break;case 3:Link.zh=i;break;case 4:Link.sS=i;break;case 5:Link.fF=i;break;case 6:Link.cF=i;break;case 7:Link.IC=i;break;case 8:Link.RC=i;break;case 9:Link.uF=i;break;case 10:Link.Wc=i;break;case 11:Link.dF=i;break;case 12:Link.gF=i;break;case 13:Link.OC=i;break;case 14:Link.mF=i;break;case 15:Link.pF=i;break;case 16:Link.yF=i;break;case 17:Link.wF=i;break;case 18:Link.oL=i;break;case 19:Link.rL=i;break;case 20:Link.xF=i;break}t>29&&t<71&&(Link.UL=t+parseInt(i.toString().slice(0,-1)))}static UL;Qe(){return this.wt===null&&(this.wt=new LinkSettings),this.wt}KE(t,i,e){const s=t.segmentIndex,n=t.segmentFraction;let o=t.alignmentFocus;const r=t.segmentOrientation,l=t.segmentOffset;let h=0,a=0,f=0,c=0;if(isNaN(s)){const C=this.xt,M=U.at();C.getPointAndAngleAlongPath(n,M);const N=Point.U(M[0],M[1]);if(c=M[2],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)}r!==0&&(f=this.computeAngle(t,r,c),t.angle=f),h=N.x,a=N.y,Point.o(N),U.et(M)}else if(s<-i||s>=i){const C=Point.a();this.QN(C),c=this.midAngle,r!==0&&(f=this.computeAngle(t,r,c),t.angle=f),h=C.x,a=C.y,Point.o(C)}else{let C,M,N=0;if(s>=0?(C=e.h[s],M=s0?e.h[N-1]:C),C.equalsApprox(M)){let T,L;s>=0?(T=s>0?e.h[s-1]:C,L=s1?e.h[N-2]:M);const D=T.distanceSquaredPoint(C),F=M.distanceSquaredPoint(L);D>F+10?c=s>=0?T.directionPoint(C):C.directionPoint(T):F>D+10?c=s>=0?M.directionPoint(L):L.directionPoint(M):c=s>=0?T.directionPoint(L):L.directionPoint(T)}else c=s>=0?C.directionPoint(M):M.directionPoint(C);r!==0&&(f=this.computeAngle(t,r,c),t.angle=f),h=C.x+(M.x-C.x)*n,a=C.y+(M.y-C.y)*n}if(o.isNone()){t.moveTo(h,a,!0);return}else o.isNoSpot()&&(o=Spot.Center);const u=Transform.a();u.Ki(),u.lt(t.scale,t.scale),u.Ns(t.angle,0,0);const d=t.naturalBounds,m=Rect.U(0,0,d.width,d.height),g=Point.a();g.setRectSpot(m,o),u.St(g);let p=-g.x,y=-g.y;const x=d.width,b=d.height,S=Point.Ms(l),k=isNaN(l.x),P=isNaN(l.y);if(k||P){const C=x/2+Link.sS,M=b/2+Link.fF,N=c>=45&&c<=135,T=c>=225&&c<=315;r===0&&(N||T)?(S.x=P?C:l.y,S.y=k?M:l.x,N?s>=0||isNaN(s)&&n<.5||k&&(S.y=-M):T&&((s>=0||isNaN(s)&&n<.5)&&k&&(S.y=-M),P&&(S.x=-C))):(k&&(s>=0||isNaN(s)&&n<.5?S.x=C:S.x=-C),P&&(S.y=-M),S.rotate(c))}else S.rotate(c);h+=S.x,a+=S.y,u.am(m),p+=m.x,y+=m.y;const A=Point.U(h+p,a+y);t.move(A),Point.o(A),Point.o(S),Point.o(g),Rect.o(m),Transform.o(u)}sl(){let t=this.fromNode;if(t!==null){const e=t.findVisibleNode();if(e!==null&&(t=e),t.us()||t.yh())return!1}let i=this.toNode;if(i!==null){const e=i.findVisibleNode();if(e!==null&&(i=e),i.us()||i.yh())return!1}return!0}VN(t,i,e){return!1}zN(){}Oe(){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=G.Yi(i),e>90&&e<270&&(e-=180);break;case 26:e=G.Yi(i+90),e>90&&e<270&&(e-=180);break;case 27:e=G.Yi(i-90),e>90&&e<270&&(e-=180);break;case 28:if(e=G.Yi(i),e>45&&e<135||e>225&&e<315)return 0;e>90&&e<270&&(e-=180);break}return G.Yi(e)}get fromNode(){return this.xo}set fromNode(t){const i=this.xo;if(i!==t){Debug&&t!==null&&U.s(t,Node,Link,"fromNode");const e=this.fromPort;i!==null&&(this.So!==i&&i.SS(this,e),this.iw(),this.invalidateLayout(2)),this.xo=t,t!==null&&this.Hi(t.isVisible()),this.rr=null,this.ii();const s=this.diagram;s!==null&&s.H&&s.partManager.setFromNodeForLink(this,t,i);const n=this.fromPort,o=this.fromPortChanged;if(o!==null){let r=!0;s!==null&&(r=s.H,s.H=!0),o(this,e,n),s!==null&&(s.H=r)}t!==null&&(this.So!==t&&t.bS(this,n),this.ew(),this.invalidateLayout(1)),this.t("fromNode",i,t),this.tg()}}get fromPortId(){return this.bo}set fromPortId(t){const i=this.bo;if(i!==t){Debug&&U.i(t,"string",Link,"fromPortId");const e=this.fromPort;e!==null&&this.fromNode?.ie(e),this.iw(),this.bo=t;const s=this.fromPort;s!==null&&this.fromNode?.ie(s);const n=this.diagram;if(n!==null){const o=this.data,r=n.model;o!==null&&r.tf()&&r.setFromPortIdForLinkData(o,t)}if(e!==s){this.rr=null,this.ii();const o=this.fromPortChanged;if(o!==null){let r=!0;n!==null&&(r=n.H,n.H=!0),o(this,e,s),n!==null&&(n.H=r)}}this.ew(),this.t("fromPortId",i,t)}}get fromPort(){const t=this.xo;if(t===null)return null;const i=this.bo;return t.findPort(i)}get fromPortChanged(){return this.eg}set fromPortChanged(t){const i=this.eg;i!==t&&(t!==null&&U.C(t,Link,"fromPortChanged"),this.eg=t,this.t("fromPortChanged",i,t))}get toNode(){return this.So}set toNode(t){const i=this.So;if(i!==t){Debug&&t!==null&&U.s(t,Node,Link,"toNode");const e=this.toPort;i!==null&&(this.xo!==i&&i.SS(this,e),this.iw(),this.invalidateLayout(2)),this.So=t,t!==null&&this.Hi(t.isVisible()),this.rr=null,this.ii();const s=this.diagram;s!==null&&s.H&&s.partManager.setToNodeForLink(this,t,i);const n=this.toPort,o=this.toPortChanged;if(o!==null){let r=!0;s!==null&&(r=s.H,s.H=!0),o(this,e,n),s!==null&&(s.H=r)}t!==null&&(this.xo!==t&&t.bS(this,n),this.ew(),this.invalidateLayout(1)),this.t("toNode",i,t),this.tg()}}get toPortId(){return this.ko}set toPortId(t){const i=this.ko;if(i!==t){Debug&&U.i(t,"string",Link,"toPortId");const e=this.toPort;e!==null&&this.toNode?.ie(e),this.iw(),this.ko=t;const s=this.toPort;s!==null&&this.toNode?.ie(s);const n=this.diagram;if(n!==null){const o=this.data,r=n.model;o!==null&&r.tf()&&r.setToPortIdForLinkData(o,t)}if(e!==s){this.rr=null,this.ii();const o=this.toPortChanged;if(o!==null){let r=!0;n!==null&&(r=n.H,n.H=!0),o(this,e,s),n!==null&&(n.H=r)}}this.ew(),this.t("toPortId",i,t)}}get toPort(){const t=this.So;if(t===null)return null;const i=this.ko;return t.findPort(i)}get toPortChanged(){return this.sg}set toPortChanged(t){const i=this.sg;i!==t&&(t!==null&&U.C(t,Link,"toPortChanged"),this.sg=t,this.t("toPortChanged",i,t))}get fromSpot(){return this.wt!==null?this.wt.Ba:Spot.Default}set fromSpot(t){const i=this.fromSpot;if(!i.equals(t)){if(Debug&&U.s(t,Spot,Link,"fromSpot"),t=t.T(),this.Qe().Ba=t,this.t("fromSpot",i,t),i.isSide()||t.isSide()){const e=this.fromNode;e!==null&&e.ie(this.fromPort)}this.ii()}}get fromEndSegmentLength(){return this.wt!==null?this.wt.za:NaN}set fromEndSegmentLength(t){const i=this.fromEndSegmentLength;if(i!==t){if(Debug&&U.i(t,"number",Link,"fromEndSegmentLength"),t<0&&U.G(t,">= 0",Link,"fromEndSegmentLength"),this.Qe().za=t,this.t("fromEndSegmentLength",i,t),this.computeSpot(!0,this.fromPort).isSide()){const e=this.fromNode;e!==null&&e.ie(this.fromPort)}this.ii()}}get fromShortLength(){return this.wt!==null?this.wt.Ya:NaN}set fromShortLength(t){const i=this.fromShortLength;i!==t&&(Debug&&U.i(t,"number",Link,"fromShortLength"),this.Qe().Ya=t,this.ce(),this.t("fromShortLength",i,t))}get toSpot(){return this.wt!==null?this.wt.Va:Spot.Default}set toSpot(t){const i=this.toSpot;if(!i.equals(t)){if(Debug&&U.s(t,Spot,Link,"toSpot"),t=t.T(),this.Qe().Va=t,this.t("toSpot",i,t),i.isSide()||t.isSide()){const e=this.toNode;e!==null&&e.ie(this.toPort)}this.ii()}}get toEndSegmentLength(){return this.wt!==null?this.wt.Xa:NaN}set toEndSegmentLength(t){const i=this.toEndSegmentLength;if(i!==t){if(Debug&&U.i(t,"number",Link,"toEndSegmentLength"),t<0&&U.G(t,">= 0",Link,"toEndSegmentLength"),this.Qe().Xa=t,this.t("toEndSegmentLength",i,t),this.computeSpot(!1,this.toPort).isSide()){const e=this.toNode;e!==null&&e.ie(this.toPort)}this.ii()}}get toShortLength(){return this.wt!==null?this.wt.Ka:NaN}set toShortLength(t){const i=this.toShortLength;i!==t&&(Debug&&U.i(t,"number",Link,"toShortLength"),this.Qe().Ka=t,this.ce(),this.t("toShortLength",i,t))}tg(){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.D3(e),this.isLabeledLink){const s=this.labelNodes;for(;s.next();){const n=s.value;n.containingGroup=e}}}D3(t){const i=this.Bh;if(i!==t){i!==null&&i.wC(this),this.Bh=t,t!==null&&t.xC(this);const e=this.containingGroupChanged;if(e!==null){let s=!0;const n=this.diagram;n!==null&&(s=n.H,n.H=!0),e(this,i,t),n!==null&&(n.H=s)}this.Be&&(this.AC===i||this.TC===i)&&this.ii()}}Lh(){const t=this.containingGroup;t!==null&&this.fromNode!==t&&this.toNode!==t&&t.computesBoundsIncludingLinks&&super.Lh()}getOtherNode(t){Debug&&U.s(t,Node,Link,"getOtherNode:node");const i=this.fromNode;return t===i?this.toNode:i}getOtherPort(t){Debug&&U.s(t,GraphObject,Link,"getOtherPort:port");const i=this.fromPort;return t===i?this.toPort:i}get isLabeledLink(){return this.hn===null?!1:this.hn.count>0}get labelNodes(){return this.hn===null?EmptyIterator.instance:this.hn.iterator}eF(t){this.hn===null&&(this.hn=new GSet),this.hn.add(t),this.g()}sF(t){this.hn!==null&&(this.hn.delete(t),this.g())}r0(t){if(super.r0(t),this.rf()&&this.invalidateOtherJumpOvers(this.actualBounds),!t){const i=this.xo;let e=null;i!==null&&(e=this.fromPort,i.bS(this,e));const s=this.So;let n=null;s!==null&&(n=this.toPort,(s!==i||n!==e)&&s.bS(this,n)),this.ew()}}l0(t){if(super.l0(t),this.rf()&&this.invalidateOtherJumpOvers(this.actualBounds),!t){const i=this.xo;let e=null;i!==null&&(e=this.fromPort,i.SS(this,e));const s=this.So;let n=null;s!==null&&(n=this.toPort,(s!==i||n!==e)&&s.SS(this,n)),this.iw()}}uc(){if(this.Be=!0,this.hn!==null){const i=this.diagram;if(i!==null){const s=this.hn.copy().iterator;for(;s.next();){const n=s.value;i.remove(n)}}}if(this.data!==null){const i=this.diagram;i!==null&&i.partManager.EC(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.U(e.x+o,e.y+r);super.move(h,!1),Point.o(h)}this.Cr(o,r);const l=this.labelNodes;for(;l.next();){const h=l.value,a=h.position;h.moveTo(a.x+o,a.y+r)}}get relinkableFrom(){return(this.Lt&1)!==0}set relinkableFrom(t){const i=(this.Lt&1)!==0;i!==t&&(Debug&&U.i(t,"boolean",Link,"relinkableFrom"),this.Lt=this.Lt^1,this.t("relinkableFrom",i,t),this.invalidateAdornments())}get relinkableTo(){return(this.Lt&2)!==0}set relinkableTo(t){const i=(this.Lt&2)!==0;i!==t&&(Debug&&U.i(t,"boolean",Link,"relinkableTo"),this.Lt=this.Lt^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.Lt&4)!==0}set resegmentable(t){const i=(this.Lt&4)!==0;i!==t&&(Debug&&U.i(t,"boolean",Link,"resegmentable"),this.Lt=this.Lt^4,this.t("resegmentable",i,t),this.invalidateAdornments())}get isTreeLink(){return(this.Lt&8)!==0}set isTreeLink(t){const i=(this.Lt&8)!==0;i!==t&&(Debug&&U.i(t,"boolean",Link,"isTreeLink"),this.Lt=this.Lt^8,this.t("isTreeLink",i,t),this.fromNode!==null&&this.fromNode.B0(),this.toNode!==null&&this.toNode.B0())}get path(){const t=this.findMainElement();return t instanceof Shape?t:null}get routeBounds(){return this.updateRoute(),this.Pl}BC(t){let i=1/0,e=1/0;const s=this.pointsCount;if(s===0)return t.e(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.e(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.e(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.e(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),G.Lu(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);G.Lu(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.e(n.x,n.y,0,0),t.unionPoint(o);for(let r=2;r=15||this.computeCurve()===9)){this.xt.getPointAlongPath(.5,t),t.add(this.getPoint(0));const a=this.xt.figures.first();return t.offset(-a.startX,-a.startY),t}if(this.computeCurve()===9){if(i===3){const c=this.getPoint(0),u=this.getPoint(1),d=this.getPoint(2);return G.JA(c.x,c.y,u.x,u.y,u.x,u.y,d.x,d.y,t),t}const a=(i-1)/3|0,f=(a/2|0)*3;if(a%2===1){const c=this.getPoint(f),u=this.getPoint(f+1),d=this.getPoint(f+2),m=this.getPoint(f+3);return G.JA(c.x,c.y,u.x,u.y,d.x,d.y,m.x,m.y,t),t}else return t.c(this.getPoint(f)),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.e(l.x,l.y-(s/2-n)):t.e(l.x,l.y+(s/2-n));else if(Math.abs(l.y-h.y)<1)l.x>h.x?t.e(l.x-(s/2-n),l.y):t.e(l.x+(s/2-n),l.y);else{const a=(s/2-n)/r,f=a*(h.x-l.x),c=a*(h.y-l.y);t.e(l.x+f,l.y+c)}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),a=this.getPoint(1);return h.directionPoint(a)}if(this.isOrthogonal&&(this.computeCorner()>=15||this.computeCurve()===9))return this.xt.getAngleAlongPath(.5);if(this.computeCurve()===9&&t>=4){const h=(t-1)/3|0;let a=(h/2|0)*3;if(h%2===1){a=Math.floor(a);const f=this.getPoint(a),c=this.getPoint(a+1),u=this.getPoint(a+2),d=this.getPoint(a+3);return G._I(f.x,f.y,c.x,c.y,u.x,u.y,d.x,d.y)}else if(a>0&&a+1e/2));)s+=o,n++;const r=this.getPoint(n),l=this.getPoint(n+1);if(Math.abs(r.x-l.x)<.5&&Math.abs(r.y-l.y)0&&na.x?180:h.y0&&na.y?270:h.x=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.I3(i,e,r,s,n,l):this.R3(i,e,r,s,n,l))}else{const m=f?this.computeCurviness():0;d&&(c&&this.isAvoiding||f)&&this.clearPoints();const g=this.getLinkPoint(i,e,r,!0,c,s,n),p=this.getLinkPoint(s,n,l,!1,c,i,e);let y=0,x=0,b=0;if(c||!h||f){b=this.getLinkDirection(i,e,g,r,!0,c,s,n);let M=this.CS(i,e,r,!0,b);if(f&&(h||r.equals(l)||!c&&r.x+l.x===1&&r.y+l.y===1)&&(b-=c?90:Link.dF,m<0&&(b-=180)),b=G.Yi(b),f&&(M+=Math.abs(m)*(c?1:2)),b===0?y=M:b===90?x=M:b===180?y=-M:b===270?x=-M:(y=M*Math.cos(b*Math.PI/180),x=M*Math.sin(b*Math.PI/180)),r.isNoSpot()&&f){const N=e.getDocumentPoint(Spot.Center,Point.a()),T=Point.U(N.x+y*Link.Wc,N.y+x*Link.Wc);this.getLinkPointFromPoint(i,e,N,T,!0,g),Point.o(N),Point.o(T)}}let S=0,k=0,P=0;if(c||!a||f){P=this.getLinkDirection(s,n,p,l,!1,c,i,e);let M=this.CS(s,n,l,!1,P);if(f&&(a||r.equals(l)||!c&&r.x+l.x===1&&r.y+l.y===1)&&(P+=c?0:Link.gF,m<0&&(P+=180)),P=G.Yi(P),f&&(M+=Math.abs(m)*(c?1:2)),P===0?S=M:P===90?k=M:P===180?S=-M:P===270?k=-M:(S=M*Math.cos(P*Math.PI/180),k=M*Math.sin(P*Math.PI/180)),l.isNoSpot()&&f){const N=n.getDocumentPoint(Spot.Center,Point.a()),T=Point.U(N.x+S*Link.Wc,N.y+k*Link.Wc);this.getLinkPointFromPoint(s,n,N,T,!1,p),Point.o(N),Point.o(T)}}let A=g;(c||!h||f)&&(A=new Point(g.x+y,g.y+x));let C=p;(c||!a||f)&&(C=new Point(p.x+S,p.y+k)),!d&&!c&&h&&o>3&&this.adjustPoints(0,g,o-2,C)?this.setPoint(o-1,p):!d&&!c&&a&&o>3&&this.adjustPoints(1,A,o-1,p)?this.setPoint(0,g):!d&&(c?o>=6:o>4)&&this.adjustPoints(1,A,o-2,C)?(this.setPoint(0,g),this.setPoint(o-1,p)):(this.clearPoints(),this.addPoint(g),(c||!h||f)&&this.addPoint(A),c&&this.addOrthoPoints(A,b,C,P,i,s),(c||!a||f)&&this.addPoint(C),this.addPoint(p))}return t.addInvalidRoute(this),!0}zC(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.c(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,a=0,f=null,c=i.panel;if(c!==null&&!c.Ln()&&(c=c.panel),c===null)r=s.x,l=s.y,h=e.x,a=e.y;else{f=c.Qs;const u=1/(f.m11*f.m22-f.m12*f.m21),d=f.m22*u,m=-f.m12*u,g=-f.m21*u,p=f.m11*u,y=u*(f.m21*f.dy-f.m22*f.dx),x=u*(f.m12*f.dx-f.m11*f.dy);r=s.x*d+s.y*g+y,l=s.x*m+s.y*p+x,h=e.x*d+e.y*g+y,a=e.x*m+e.y*p+x}return i.bc(r,l,h,a,o),f!==null&&o.E(f),o}O3(t,i){const e=t.Pd;return e!==null?e.bF(i):null}AS(t){if(t===null)return null;let i=t.Pd;return i===null&&(i=new Knot(t.part,t),t.Pd=i),i.bF(this)}getLinkPoint(t,i,e,s,n,o,r,l){if(l===void 0&&(l=new Point),e.isSpot()&&!this.Ml(e))return i.getDocumentPoint(e,l),l;if(e.isSide()){const f=this.AS(i);if(f!==null){const c=f.lf;if(l.c(c),n&&this.routing===7){const u=this.AS(r);if(u!==null&&f.jc=g.y&&k.y<=g.y+g.height?l.y=k.y:(e.includesSide(Spot.TopSide)||e.includesSide(Spot.BottomSide))&&k.x>=g.x&&k.x<=g.x+g.width&&(l.x=k.x),Rect.o(g),Point.o(d),Point.o(m)}}return l}}const h=i.getDocumentPoint(this.hg(e,s),Point.a()),a=Point.a();if(this.pointsCount>(n?6:2))a.c(s?this.getPoint(1):this.getPoint(this.pointsCount-2)),n&&this.zC(h,a);else if(t?.isMemberOf(o)||o?.isMemberOf(t)){const f=i.getDocumentBounds(Rect.a()),c=r.getDocumentBounds(Rect.a());f.isReal()&&c.isReal()?c.containsRect(f)?(a.c(h),this.XC(c,h.x,h.y,0,this.computeSpot(r===this.toPort,r),a)):f.containsRect(c)?(r.getDocumentPoint(Spot.Center,a),this.XC(f,a.x,a.y,0,this.computeSpot(i===this.toPort,i),a)):this.YC(r,h,s,n,a):this.YC(r,h,s,n,a),Rect.o(f),Rect.o(c)}else this.YC(r,h,s,n,a);return this.getLinkPointFromPoint(t,i,h,a,s,l),Point.o(a),Point.o(h),l}YC(t,i,e,s,n){const o=this.computeSpot(!e,t);t.getDocumentPoint(this.hg(o,!e),n),s&&this.zC(i,n)}getLinkDirection(t,i,e,s,n,o,r,l){let h=this.E3(t,i,e,s,n,o,r,l);if(t&&r){const f=Rect.a(),c=Rect.a();if(s.isNone()&&t.isMemberOf(r)&&i&&l){if(i.getDocumentBounds(f),l.getDocumentBounds(c),f.isReal()&&c.isReal()&&c.containsRect(f)){const u=this.computeSpot(l===this.toPort,l);u.equals(Spot.Left)||u.equals(Spot.LeftSide)?h=180:u.equals(Spot.Right)||u.equals(Spot.RightSide)?h=0:u.equals(Spot.Top)||u.equals(Spot.TopSide)?h=270:u.equals(Spot.Bottom)||u.equals(Spot.BottomSide)?h=90:h=G.Yi(h+180)}}else r?.isMemberOf(t)&&i&&l&&(i.getDocumentBounds(f),l.getDocumentBounds(c),f.isReal()&&c.isReal()&&f.containsRect(c)&&(h=G.Yi(h+180)));Rect.o(f),Rect.o(c)}if(this.Ml(s)||i===null)return h;const a=i.getDocumentAngle();return a===0?h:(45<=a&&a<135?h+=90:135<=a&&a<225?h+=180:225<=a&&a<315&&(h+=270),G.Yi(h))}E3(t,i,e,s,n,o,r,l){if(s.isSpot())return G.lx(null,s.x,s.y);if(s.isSide()){const c=this.AS(i);if(c!==null)switch(c.ge){case 1:return 270;case 8:return 90;case 2:return 180;default:return 0}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.a()),a=Point.a();this.pointsCount>(o?6:2)?o?(a.c(n?this.getPoint(1):this.getPoint(this.pointsCount-2)),this.zC(h,a)):a.c(e):l.getDocumentPoint(Spot.Center,a);let f=0;return Math.abs(a.x-h.x)>Math.abs(a.y-h.y)?a.x>=h.x?f=0:f=180:a.y>=h.y?f=90:f=270,Point.o(a),Point.o(h),f}computeEndSegmentLength(t,i,e,s){return this.CS(t,i,e,s,NaN)}CS(t,i,e,s,n){if(i!==null&&e.isSide()){const r=this.AS(i);if(r!==null)return r.TS}let o=NaN;if(s?o=this.fromEndSegmentLength:o=this.toEndSegmentLength,i!==null&&isNaN(o))if(n===void 0&&(n=NaN),Link.RC>0&&this.computeCurve()===9&&!isNaN(n)&&e.isSpot()){const r=this.getOtherPort(i);if(r){const l=Point.a(),h=Point.a(),a=i.getDocumentPoint(e,l),f=r.getDocumentPoint(e.opposite(),h),c=n>=315||n<=45||n>=135&&n<=225;let u=Math.abs(c?a.x-f.x:a.y-f.y)/Link.RC;return u=Math.max(u,Link.OC),Point.o(l),Point.o(h),u}}else s?o=i.fromEndSegmentLength:o=i.toEndSegmentLength;return isNaN(o)&&(o=Link.OC),o}computeSpot(t,i){return i===void 0&&(i=null),t?this.B3(i||this.fromPort):this.V3(i||this.toPort)}B3(t){if(t===null)return Spot.Center;let i=this.fromSpot;return i.isDefault()&&(i=t.fromSpot),i===Spot.Default?Spot.None:i}V3(t){if(t===null)return Spot.Center;let i=this.toSpot;return i.isDefault()&&(i=t.toSpot),i===Spot.Default?Spot.None:i}Ml(t){return t===Spot.None||t.x===.5&&t.y===.5}hg(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.O3(i,this);if(e!==null)return e.lf;if(t instanceof Group){let s=this.fromNode,n=this.fromPort;n===i&&(s=this.toNode,n=this.toPort);const o=Rect.a(),r=Rect.a();if(n&&s?.isMemberOf(t)){const l=this.computeSpot(n===i,i);if(i.getDocumentBounds(o),n.getDocumentBounds(r),o.isReal()&&r.isReal()&&o.containsRect(r)){const h=n.getDocumentPoint(Spot.Center);return this.XC(o,h.x,h.y,0,l,h),Rect.o(o),Rect.o(r),h}}Rect.o(o),Rect.o(r)}return 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}}e0(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.a(),r.Ki()):r=o,r.Af(this.E),this.containedInRect(t,r))return this.eC(i,e,n),o===void 0&&Transform.o(r),!0;if(this.intersectsRect(t,r)){let l=!1;if(!this.Rc){const h=this.O.h,a=h.length;for(let f=a;f--;){const c=h[f];if(!c.visible&&c!==this.locationObject)continue;const u=c.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=c,g=Transform.a();if(g.set(r),m instanceof Panel?l=m.e0(t,i,e,s,n,g):this.path===m?m instanceof Shape&&(l=m.f3(t,s,g)):l=m.eD(t,s,g),l){let p=m;i!==null&&(p=i(m)),p&&(e===null||e(p))&&n.add(p)}Transform.o(g)}}return o===void 0&&Transform.o(r),l||this.background!==null}return o===void 0&&Transform.o(r),!1}get isOrthogonal(){return(this.ef&2)===2}static FC(t){return(t&2)===2}get isAvoiding(){return(this.ef&4)===4}computeCurve(){if(this.rr===null){const t=this.fromPort,i=t!==null&&t===this.toPort,e=this.isOrthogonal;this.rr=i&&!e}return this.rr?9:this.curve}computeCorner(){if(this.curve===9)return 0;let t=this.corner;return(isNaN(t)||t<0)&&(t=Link.mF),t}findMidLabel(){const t=this.path,i=this.O.h,e=i.length;for(let n=0;n0?g-=c:g+=c;else{const p=-h/a;let y=Math.sqrt(c*c/(p*p+1));f<0&&(y=-y),m=(a<0?-1:1)*y+u,g=p*(m-u)+d}this.insertPointAt(1,m,g)}}SF(t,i,e,s,n,o,r,l){const h=o.getDocumentBounds(Rect.a()),a=i.getDocumentBounds(Rect.a());if(h.intersectsRect(a)&&!h.containsRect(a)&&!a.containsRect(h)){const f=Point.a();i.getDocumentPoint(this.hg(e,!0),f);const c=Point.a();o.getDocumentPoint(this.hg(r,!1),c);const u=a.width*a.height,d=h.width*h.height;u>d?(s.c(f),this.getLinkPointFromPoint(n,o,c,f,!1,c),l.c(c)):u0?p-=f:p+=f:(c=-h/a,u=Math.sqrt(f*f/(c*c+1)),f<0&&(u=-u),g=(a<0?-1:1)*u+d,p=c*(g-d)+m),d=r.x+2*h/3,m=r.y+2*a/3;let y=d,x=m;G.u(a,0)?h>0?x-=f:x+=f:(y=(a<0?-1:1)*u+d,x=c*(y-d)+m),this.insertPointAt(1,g,p),this.insertPointAt(2,y,x),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.z3(t,i,e,s);case 19:return this.X3(t,i,e,s);case 17:return this.Y3(t,i,e,s);default:return!1}}z3(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,a=o.y;let f=h-r,c=a-l;const u=Math.sqrt(f*f+c*c);if(G.q(u,0))return!0;let d=0;G.q(f,0)?c<0?d=-Math.PI/2:d=Math.PI/2:(d=Math.atan(c/Math.abs(f)),f<0&&(d=Math.PI-d));const m=i.x,g=i.y,p=s.x,y=s.y,x=p-m,b=y-g,S=Math.sqrt(x*x+b*b);let k=0;G.q(x,0)?b<0?k=-Math.PI/2:k=Math.PI/2:(k=Math.atan(b/Math.abs(x)),x<0&&(k=Math.PI-k));const P=S/u,A=k-d;this.setPoint(t,i);for(let C=t+1;C0&&(C=-C);const M=c+k*(d-c),N=u+k*(m-u);if(g!==0){const T=M+C/p,L=N-(T-M)/g;this.setPointAt(y,T,L)}else this.setPointAt(y,M,N+C)}return this.setPoint(e,s),!0}Y3(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 a=l,f=h;G.u(n.y,o.y)?G.u(o.x,r.x)?h=i.y:G.u(o.y,r.y)&&(l=i.x):G.u(n.x,o.x)&&(G.u(o.y,r.y)?l=i.x:G.u(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 c=o.x,u=o.y;const d=c,m=u;if(G.u(n.y,o.y)?G.u(o.x,r.x)?u=s.y:G.u(o.y,r.y)&&(c=s.x):G.u(n.x,o.x)&&(G.u(o.y,r.y)?c=s.x:G.u(o.x,r.x)&&(u=s.y)),this.setPointAt(e-1,c,u),this.PL())return this.setPointAt(t+1,a,f),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=G.Yi(i),s=G.Yi(s);const f=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 c=t,u=e,d=Rect.Ms(n.actualBounds),m=Rect.Ms(o.actualBounds);d.inflate(Link.zh,Link.zh),m.inflate(Link.zh,Link.zh),d.unionPoint(t),m.unionPoint(e);const g=Point.a(),p=Point.a();i===0?u.x>c.x||s===270&&u.yc.x||s===90&&u.y>c.y&&m.right>c.x?(g.e(u.x,c.y),p.e(u.x,(c.y+u.y)/2),s===180?(g.x=this.computeMidOrthoPosition(c.x,c.y,u.x,u.y,!1),p.x=g.x,p.y=u.y):s===270&&u.yc.y?(c.xm.bottom)?g.x=this.computeMidOrthoPosition(c.x,c.y,u.x,u.y,!1):g.x=m.right,p.x=g.x,p.y=u.y):s===0&&c.xm.top&&c.yd.bottom)&&(s===180&&(m.containsPoint(c)||d.containsPoint(u))?g.y=this.computeMidOrthoPosition(c.x,c.y,u.x,u.y,!0):u.yc.y&&(s===180||s===270)&&(g.y=this.computeMidOrthoPosition(c.x,d.bottom,u.x,Math.max(u.y,m.top),!0)),p.x=u.x,p.y=g.y),g.y>d.top&&g.y=d.left&&u.x<=c.x||c.x<=m.right&&c.x>=u.x?(s===90||s===270)&&(g.e(Math.max((c.x+u.x)/2,c.x),c.y),p.e(g.x,u.y)):(s===270||(s===0||s===180)&&u.yc.y&&m.leftc.y?(c.x>m.right?g.x=this.computeMidOrthoPosition(c.x,c.y,m.right,u.y,!1):c.x>m.left&&(s===270&&c.ym.bottom)?g.x=this.computeMidOrthoPosition(c.x,c.y,u.x,u.y,!1):g.x=m.left,p.x=g.x,p.y=u.y):s===180&&c.x>m.right&&c.y>m.top&&c.yd.bottom)&&(s===0&&(m.containsPoint(c)||d.containsPoint(u))?g.y=this.computeMidOrthoPosition(c.x,c.y,u.x,u.y,!0):u.yc.y&&(s===0||s===270)&&(g.y=this.computeMidOrthoPosition(c.x,d.bottom,u.x,Math.max(u.y,m.top),!0)),p.x=u.x,p.y=g.y),g.y>d.top&&g.y=c.x||c.x>=m.left&&c.x<=u.x?(s===90||s===270)&&(g.e(Math.min((c.x+u.x)/2,c.x),c.y),p.e(g.x,u.y)):(s===270||(s===0||s===180)&&u.yc.y||s===180&&u.xc.y||s===0&&u.x>c.x&&m.bottom>c.y?(g.e(c.x,u.y),p.e((c.x+u.x)/2,u.y),s===270?(g.y=this.computeMidOrthoPosition(c.x,c.y,u.x,u.y,!0),p.x=u.x,p.y=g.y):s===180&&u.xc.x?(c.ym.right)?g.y=this.computeMidOrthoPosition(c.x,c.y,u.x,u.y,!0):g.y=m.bottom,p.x=u.x,p.y=g.y):s===90&&c.ym.left&&c.xd.right)&&(s===270&&(m.containsPoint(c)||d.containsPoint(u))?g.x=this.computeMidOrthoPosition(c.x,c.y,u.x,u.y,!1):u.xc.x&&(s===270||s===180)&&(g.x=this.computeMidOrthoPosition(d.right,c.y,Math.max(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<=c.y||c.y<=m.bottom&&c.y>=u.y?(s===0||s===180)&&(g.e(c.x,Math.max((c.y+u.y)/2,c.y)),p.e(u.x,g.y)):(s===180||(s===90||s===270)&&u.xc.x&&m.top=c.x?(c.y>m.bottom?g.y=this.computeMidOrthoPosition(c.x,c.y,u.x,m.bottom,!0):c.y>m.top&&(s===180&&c.xm.right)?g.y=this.computeMidOrthoPosition(c.x,c.y,u.x,u.y,!0):g.y=m.top,p.x=u.x,p.y=g.y):s===270&&c.y>m.bottom&&c.x>m.left&&c.xd.right)&&(s===90&&(m.containsPoint(c)||d.containsPoint(u))?g.x=this.computeMidOrthoPosition(c.x,c.y,u.x,u.y,!1):u.xc.x&&(s===90||s===180)&&(g.x=this.computeMidOrthoPosition(d.right,c.y,Math.max(u.x,m.left),u.y,!1)),p.x=g.x,p.y=u.y),g.x>d.left&&g.x=c.y||c.y>=m.top&&c.y<=u.y?(s===0||s===180)&&(g.e(c.x,Math.min((c.y+u.y)/2,c.y)),p.e(u.x,g.y)):(s===180||(s===90||s===270)&&u.x=2&&(this.xt=this.makeGeometry()),this.Xh=!0;const i=this.path;if(i===null)return;i.xt=this.xt;const e=this.O.h,s=e.length;for(let n=0;n=3&&!G.q(this.smoothness,0))if(i===3){let f=this.getPoint(1);n=Math.min(r.x,f.x),o=Math.min(r.y,f.y),f=this.getPoint(2),n=Math.min(n,f.x),o=Math.min(o,f.y)}else if(this.isOrthogonal){for(let f=0;f=i&&(f=i-1);const c=this.getPoint(f);l.x=Math.min(c.x,l.x),l.y=Math.min(c.y,l.y)}n=l.x,o=l.y}else{for(let f=0;f=3&&!G.q(this.smoothness,0))if(i===3){const c=this.getPoint(1),u=c.x-n,d=c.y-o,m=Point.Ms(this.getPoint(2));m.x-=n,m.y-=o,this.computeShortLength(!1)!==0&&this.hf(m,!1,l),f.Pr(u,d,u,d,m.x,m.y),Point.o(m)}else if(this.isOrthogonal){const c=Point.U(n,o),u=Point.Ms(this.getPoint(1)),d=Point.U(n,o),m=Point.U(n,o);let g=this.getPoint(0),p;const y=this.smoothness/3;for(let k=1;k=i&&(c=i-1);const d=this.getPoint(c-1),m=Point.Ms(this.getPoint(c));c===i-1&&this.computeShortLength(!1)!==0&&this.hf(m,!1,Point.yn),f.Pr(u.x-n,u.y-o,d.x-n,d.y-o,m.x-n,m.y-o),Point.o(m)}else if(this.isOrthogonal||i===2){const c=Point.Ms(this.getPoint(0)),u=Point.a(),d=Point.Ms(c),m=this.computeCorner();let g=1,p=0;for(;g1),u.c(this.getPoint(g)),g>=i-1){if(!c.equals(u))this.computeShortLength(!1)!==0&&this.hf(u,!1,Point.yn),this.zn(f,-n,-o,c,u,e);else if(p===0)for(g=1;g2&&c>=.5){const u=Point.Ms(h[i-1]);this.computeShortLength(!1)!==0&&this.hf(u,!1,Point.yn),r.x+=n,r.y+=o;for(let d=1;d1){const x=m.x+(g.x-m.x)*y,b=m.y+(g.y-m.y)*y;f.Ru(m.x-n,m.y-o,x-n,b-o)}f.Ws(g.x+(m.x-g.x)*y-n,g.y+(m.y-g.y)*y-o)}else d>1&&f.Ru(m.x-n,m.y-o,(m.x+g.x)/2-n,(m.y+g.y)/2-o);d===i-1&&f.Ws(u.x-n,u.y-o)}Point.o(u)}else if(i>=2){const u=Point.Ms(h[i-1]);this.computeShortLength(!1)!==0&&this.hf(u,!1,Point.yn);for(let d=1;dr?c>a?(n.x=h-u,n.y=a-u,o.x=h+d,o.y=a+d):(n.x=h-u,n.y=a+u,o.x=h+d,o.y=a-d):c>a?(n.x=h+u,n.y=a-u,o.x=h-d,o.y=a+d):(n.x=h+u,n.y=a+u,o.x=h-d,o.y=a-d)),G.q(r,h)&&G.q(a,c)&&(a>l?f>h?(n.x=h-u,n.y=a-u,o.x=h+d,o.y=a+d):(n.x=h+u,n.y=a-u,o.x=h-d,o.y=a+d):f>h?(n.x=h-u,n.y=a+u,o.x=h+d,o.y=a-d):(n.x=h+u,n.y=a+u,o.x=h-d,o.y=a-d)),G.q(r,h)&&G.q(h,f)||G.q(l,a)&&G.q(a,c)){const m=.5*(r+f),g=.5*(l+c);n.x=m,n.y=g,o.x=m,o.y=g}}hf(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.LS(t.x,t.y,o,r);if(l===0)return t;const h=s===2?l*.5:l;let a=this.computeShortLength(!0);a>h&&(a=h);const f=a*(o-t.x)/l,c=a*(r-t.y)/l;t.x+=f,t.y+=c}else{const n=this.getPoint(s-2),o=n.x-e.x,r=n.y-e.y,l=this.LS(t.x,t.y,o,r);if(l===0)return t;const h=s===2?l*.5:l;let a=this.computeShortLength(!1);a>h&&(a=h);const f=a*(t.x-o)/l,c=a*(t.y-r)/l;t.x-=f,t.y-=c}return t}UC(t,i,e){const s=this.pointsCount;let n=t;for(;G.q(t.x,n.x)&&G.q(t.y,n.y);){if(i>=s)return s-1;n=this.getPoint(i++)}if(!G.q(t.x,n.x)&&!G.q(t.y,n.y))return i-1;let o=n;for(;G.q(t.x,n.x)&&G.q(n.x,o.x)&&(!e||(t.y>=n.y?n.y>=o.y:n.y<=o.y))||G.q(t.y,n.y)&&G.q(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}G3(t,i,e,s,n,o,r,l,h,a){if(G.u(s.y,n.y)&&G.u(n.x,o.x)){let f=Math.min(h,Math.abs(n.x-l.x)/2);const c=Math.min(f,Math.abs(o.y-n.y)/2);if(f=c,G.u(f,0)){this.zn(t,i,e,s,n,a),r.c(n);return}let u=n.x;const d=n.y,m=u;let g=d;n.x>s.x?(u=n.x-f,o.y>n.y?g=n.y+c:g=n.y-c):(u=n.x+f,o.y>n.y?g=n.y+c:g=n.y-c);const p=Point.U(u,d);this.zn(t,i,e,s,p,a),Point.o(p),t.Ru(n.x+i,n.y+e,m+i,g+e),r.e(m,g)}else if(G.u(s.x,n.x)&&G.u(n.y,o.y)){let f=Math.min(h,Math.abs(n.y-l.y)/2);const c=Math.min(f,Math.abs(o.x-n.x)/2);if(f=c,G.u(c,0)){this.zn(t,i,e,s,n,a),r.c(n);return}const u=n.x;let d=n.y,m=u;const g=d;n.y>s.y?(d=n.y-f,o.x>n.x?m=n.x+c:m=n.x-c):(d=n.y+f,o.x>n.x?m=n.x+c:m=n.x-c);const p=Point.U(u,d);this.zn(t,i,e,s,p,a),Point.o(p),t.Ru(n.x+i,n.y+e,m+i,g+e),r.e(m,g)}else this.zn(t,i,e,s,n,a),r.c(n)}zn(t,i,e,s,n,o){if(o||!this.rf())t.Ws(n.x+i,n.y+e);else{const r=Link.uF,l=r/2,h=[];let a=0;this.isVisible()&&(a=this.q3(s,n,h));let f=s.x,c=s.y;if(a>0){if(G.u(s.y,n.y))if(s.x=0;){const d=Math.min(s.x,Math.max(h[u--]+l,n.x+r));t.Ws(d+i,n.y+e),f=d+i,c=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,y=n.y+e;this.curve===10?t.Iu(p,y,!1,!1):t.Pr(f,g,p,g,p,y),f=p,c=y}}else if(G.u(s.x,n.x))if(s.y=0;){const d=Math.min(s.y,Math.max(h[u--]+l,n.y+r));t.Ws(n.x+i,d+e),f=n.x+i,c=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,y=m+e;this.curve===10?t.Iu(p,y,!1,!1):t.Pr(g,c,g,y,p,y),f=p,c=y}}}t.Ws(n.x+i,n.y+e)}}q3(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.GM(),l=r.length;for(let h=0;h0&&e.sort((u,d)=>u-d),e.length;if(!a.isVisible()||!a.rf())continue;const f=a.routeBounds;if(!f.isReal()||!this.routeBounds.intersectsRect(f)||this.usesSamePort(a))continue;const c=a.path;c!==null&&c.isVisibleObject()&&this.H3(t,i,e,a)}}}return e.length>0&&e.sort((o,r)=>o-r),e.length}H3(t,i,e,s){const n=G.u(t.y,i.y),o=s.pointsCount;let r=s.getPoint(0);const l=Point.a();for(let h=1;hr.x&&f.x>=a.x||a.xr.y&&f.y>=a.y||a.yf&&Math.min(a,c)o&&!G.u(a,c))return n.x=o,n.y=f,!0}else if(G.u(r,h)&&G.u(a,c)&&Math.min(o,l)a&&Math.min(f,u)r&&!G.u(f,u))return n.x=a,n.y=r,!0;return n.x=0,n.y=0,!1}get firstPickIndex(){return this.pointsCount<=2?0:this.isOrthogonal||!this.Ml(this.computeSpot(!0))?1:0}get lastPickIndex(){const t=this.pointsCount;return t===0?0:t<=2?t-1:this.isOrthogonal||!this.Ml(this.computeSpot(!1))?t-2:t-1}rf(){const t=this.curve;return t===11||t===10}NS(t){if(t||this.rf()){const i=this.diagram;i!==null&&!i.animationManager.isTicking&&!i.uh.has(this)&&(this.Pl.width!==0||this.Pl.height!==0)&&i.uh.set(this,this.Pl.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.GM(),h=l.length;for(let a=0;a0&&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}Hi(t){if(super.Hi(t),t&&this.NS(!1),this.lr!==null&&this.lr.ig(),this.hn!==null){const e=this.hn.iterator;for(;e.next();)e.value.Hi(t)}}get adjusting(){return this.vc}set adjusting(t){const i=this.vc;i!==t&&(Debug&&t!==0&&t!==17&&t!==18&&t!==19&&U.n("Link.adjusting can only be set to None, End, Scale, or Stretch, not: "+t),this.vc=t,this.t("adjusting",i,t))}computeAdjusting(){return this.isAvoiding&&this.diagram!==null&&this.diagram.animationManager.defaultAnimation.isAnimating?17:this.vc}get corner(){return this.ng}set corner(t){const i=this.ng;i!==t&&(Debug&&U.i(t,"number",Link,"corner"),this.ng=t,this.ce(),this.t("corner",i,t))}get curve(){return this.og}set curve(t){const i=this.og;i!==t&&(Debug&&t!==0&&t!==9&&t!==10&&t!==11&&U.n("Link.curve can only be set to None, Bezier, JumpGap, or JumpOver, not: "+t),this.og=t,(i===9||t===9)&&this.BC(this.Pl),this.ii(),this.ce(),this.NS(i===10||i===11||t===10||t===11),this.t("curve",i,t))}get curviness(){return this.rg}set curviness(t){const i=this.rg;i!==t&&(Debug&&U.i(t,"number",Link,"curviness"),this.rg=t,this.ii(),this.ce(),this.t("curviness",i,t))}get routing(){return this.ef}set routing(t){const i=this.ef;i!==t&&(Debug&&t!==1&&t!==2&&t!==6&&t!==7&&U.n("Link.routing can only be set to Normal, Orthogonal, AvoidsNodes, not: "+t),this.ef=t,this.isAvoiding&&this.diagram!==null&&(this.diagram.d0=!0),this.rr=null,this.ii(),this.NS(Link.FC(i)||Link.FC(t)),this.t("routing",i,t))}get smoothness(){return this.lg}set smoothness(t){const i=this.lg;i!==t&&(Debug&&U.i(t,"number",Link,"smoothness"),this.lg=t,this.ce(),this.t("smoothness",i,t))}ew(){const t=this.xo;if(t===null)return;const i=this.So;if(i===null||!isNaN(this.curviness))return;const e=this.bo,s=this.ko;let n=null,o=null;const r=t.ri.h,l=r.length;for(let h=0;h=0&&(t.an.splice(i,1),t.ig())}}Ir(){return!0}get key(){const t=this.diagram;if(!(t===null||!t.model.tf()))return t.model.getKeyForLinkData(this.data)}}class LinkBundle{jo;$s;vy;PC;xS;MC;an;constructor(t,i,e,s){GSet._i(this),this.jo=!1,this.$s=!1,this.vy=t,this.PC=i,this.xS=e,this.MC=s,this.an=[]}ig(){if(!this.jo){const t=this.an;if(t.length>0){const i=t[0].diagram;i!==null&&(i.d2.add(this),this.$s=i.undoManager.isUndoingRedoing)}}this.jo=!0}L2(){if(this.jo){this.jo=!1;const t=this.an;if(t.length>0){const i=t[0],e=i.diagram,s=e===null||e.oa&&!this.$s;this.$s=!1,i.arrangeBundledLinks(t,s),t.length===1&&(i.lr=null,t.length=0)}t.length===0&&(this.vy.ZD(this),this.xS.ZD(this))}}}class PositionArray{me;pe;af;ff;Si;ki;qt;Yh;Kh;Ra;U2;jo;ow;gc;G2;q2;constructor(t){GSet._i(this),this.Ra=null,this.U2=null,this.jo=!0,this.ow=!1,this.me=1,this.pe=1,this.af=-1,this.ff=-1,this.Si=t.width,this.ki=t.height,this.qt=[],this.Yh=0,this.Kh=0,this.gc=Link.xF,this.G2=this.gc*2,this.q2=this.gc*2}static fn=0;static cf=1;static ag=999999;static GC=PositionArray.ag+1;static qC=PositionArray.ag+2;Sb(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.me=Math.floor((i-this.Si)/this.Si)*this.Si,this.pe=Math.floor((e-this.ki)/this.ki)*this.ki,this.af=Math.ceil((s+2*this.Si)/this.Si)*this.Si,this.ff=Math.ceil((n+2*this.ki)/this.ki)*this.ki;const o=1+(Math.ceil((this.af-this.me)/this.Si)|0),r=1+(Math.ceil((this.ff-this.pe)/this.ki)|0);if(this.qt.length===0||this.Yh0&&t!==this.Si&&(this.Si=t,this.Sb(this.bounds))}get cellHeight(){return this.ki}set cellHeight(t){t>0&&t!==this.ki&&(this.ki=t,this.Sb(this.bounds))}fg(t,i){return this.me<=t&&t<=this.af&&this.pe<=i&&i<=this.ff}Po(t,i){if(!this.fg(t,i))return PositionArray.GC;t-=this.me,t/=this.Si,i-=this.pe,i/=this.ki;const e=t|0,s=i|0;return this.qt[e][s]}XO(t,i,e,s){if(!this.fg(t,i))return;const n=(t-this.me)/this.Si|0,o=(i-this.pe)/this.ki|0,r=(t+e-this.me)/this.Si|0,l=(i+s-this.pe)/this.ki|0,h=Math.min(r,this.Yh),a=Math.min(l,this.Kh);for(let f=n;f<=h;f++){const c=this.qt[f];if(c.fill)c.fill(PositionArray.fn,o,a+1);else for(let u=o;u<=a;u++)c[u]=PositionArray.fn}}W3(t){for(let i=0;i<=this.Yh;i++){const e=this.qt[i];if(e.fill)e.fill(t);else for(let s=0;s<=this.Kh;s++)e[s]=t}}EL(){for(let t=0;t<=this.Yh;t++){const i=this.qt[t];for(let e=0;e<=this.Kh;e++)i[e]>=PositionArray.cf&&(i[e]=PositionArray.GC)}}j3(t,i){return this.Po(t,i)===PositionArray.fn}isUnoccupied(t,i,e,s){if(t>this.af||t+ethis.ff||i+sthis.af||ithis.ff||ethis.ff||ithis.af||e=PositionArray.cf&&h=a)break;this.qt[t][i]=h,h+=1,s?i+=e:t+=e}return s?i:t}Mo(t,i,e,s,n,o,r,l){if(to||il)return;const h=this.J3(t,i,e,s,n,o,r,l);if(s)if(e>0)for(let a=i+e;ah;a+=e)this.Mo(t,a,1,!s,n,o,r,l),this.Mo(t,a,-1,!s,n,o,r,l);else if(e>0)for(let a=t+e;ah;a+=e)this.Mo(a,i,1,!s,n,o,r,l),this.Mo(a,i,-1,!s,n,o,r,l)}DS(t,i,e,s,n,o,r,l,h,a){let f=t|0,c=i|0,u=PositionArray.fn,d=PositionArray.cf;for(this.qt[f][c]=d;u===PositionArray.fn&&f>r&&fh&&cr&&fh&&c=0;I-=2){F=L[I+2],R=L[I+3];const O=L[I],X=L[I+1];for(;O>F?F++:OR?R++:Xs)d--;else break;else if(m>n)m--;else break;const g=f[d][m];if(g===0||g===PositionArray.qC)break;c=d,u=m}for(;;){let d=e,m=c,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=f[m][g];if(d!==e&&p!==0&&p!==PositionArray.qC){if(o.push(c),o.push(u),this.NF(c,u,d,s,n,o))return!0;o.pop(),o.pop()}if(f[c][u]=PositionArray.qC,e===0){if(c===t)return!1;c--}else if(e===90){if(u===i)return!1;u--}else if(e===180){if(c===t)return!1;c++}else{if(u===i)return!1;u++}}}}class Knot{Ve;Nl;Ke;cg;constructor(t,i){GSet._i(this),this.Ve=t,this.Nl=i,this.Ke=[],this.cg=!1}toString(){const t=this.Ke;let i=this.Ve.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}ig(){this.Ke.length=0}bF(t){let i=this.Ke;i.length===0&&(this.Z3(),i=this.Ke);for(let e=0;e180&&(P-=360)):A===90?(C=8,P>270&&(P-=360)):A===180?C=2:(C=1,P<90&&(P+=360));let M=this.Ke[o];M===void 0?(M=new LinkInfo(g,P,C),this.Ke[o]=M):(M.ns=g,M.vt=P,M.ge=C),M.IS.c(k),o++}Point.o(a),this.Q3();const u=this.Ke.length;let d=-1,m=0;for(o=0;o=0;o--){const g=this.Ke[o];g!==void 0&&(g.ge!==d&&(d=g.ge,m=g.ug+1),g.jc=m)}this._3(this.Ke),this.t4(this.Ke),this.cg=t,Rect.o(h)}return this.Ke}i4(t,i){return t===i?0:t===null?-1:i===null?1:t.gei.ge?1:t.vti.vt?1:0}Q3(){this.Ke.sort(Knot.prototype.i4)}_3(t){const i=this.Nl,e=this.Ve.portSpreading,s=Point.a(),n=Point.a(),o=Point.a(),r=Point.a();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,a=0,f=0;if(e===2)for(let x=0;xMath.abs(p)?(d=Math.abs(p)/a,a=Math.abs(p)):d=1;break;case 2:f>Math.abs(y)?(d=Math.abs(y)/f,f=Math.abs(y)):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(y)?(d=Math.abs(y)/h,h=Math.abs(y)):d=1;break}u=0}const S=b.lf;if(e===2){let k=b.ns.computeThickness();switch(k*=d,S.c(m),c){case 8:S.x=m.x+p/2+a/2-u-k/2;break;case 2:S.y=m.y+y/2+f/2-u-k/2;break;case 1:S.x=m.x+p/2-l/2+u+k/2;break;default:case 4:S.y=m.y+y/2-h/2+u+k/2;break}u+=k}else{let k=.5;e===1&&(k=(b.ug+1)/(b.jc+1)),S.x=m.x+p*k,S.y=m.y+y*k}}Point.o(s),Point.o(n),Point.o(o),Point.o(r)}t4(t){for(let i=0;i=l-1?f:this.Ke[c?i-1:i+1].lf;return(d?a.y>=m.y&&a.y<=g.y:a.x>=m.x&&a.x<=g.x)?o:(d?a.ye instanceof Placeholder);i instanceof Placeholder?t.Rt=i:t.Rt=null,this.fe!==null?(t.fe=this.fe.copy(),t.fe.group=t):(t.fe!==null&&(t.fe.group=null),t.fe=null),this.ui!==null&&(t.ui=this.ui.copy())}$o(t){super.$o(t);const i=t.findSubGraphParts(),e=t.memberParts;for(;e.next();){const s=e.value;if(s.g(),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)}}}wc(t,i,e,s,n,o,r){if(t===3&&i==="elements"){if(n instanceof Placeholder)this.Rt===null?this.Rt=n:this.Rt!==n&&U.n("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.Rt===null?this.Rt=l:this.Rt!==l&&U.n("Cannot insert a second Placeholder into the visual tree of a Group."))}}else t===4&&i==="elements"&&this.Rt!==null&&(s===this.Rt?this.Rt=null:s instanceof Panel&&this.Rt.isContainedBy(s)&&(this.Rt=null));super.wc(t,i,e,s,n,o,r)}Ad(t,i){if(super.Ad(t,i),this.isClipping&&this.type!==Panel.Spot&&this.isSubGraphExpanded){let e=this.resizeObject;e instanceof Panel&&(e=e.findMainElement()),this.ui===null&&(this.ui=new Rect),e.getDocumentBounds(this.ui),e instanceof Shape&&this.ui.inflate(-e.strokeWidth,-e.strokeWidth)}}Th(t,i,e,s){this.hasPlaceholder()&&(this.or=this.placeholder),super.Th(t,i,e,s)}ensureBounds(){this.isSubGraphExpanded&&this.memberParts.each(i=>{i.ensureBounds()}),super.ensureBounds()}sl(){if(!super.sl())return!1;const t=this.memberParts;for(;t.next();){const i=t.value;if(i instanceof Node){if(!i.isVisible())continue;if(i.us())return!1}else if(i instanceof Link){if(!i.isVisible())continue;if(i.us()&&i.fromNode!==this&&i.toNode!==this)return!1}}return!0}hasPlaceholder(){return this.Rt!==null&&this.Rt.isVisibleObject()&&this.isSubGraphExpanded}get placeholder(){return this.Rt}get computesBoundsAfterDrag(){return(this.z&2048)!==0}set computesBoundsAfterDrag(t){const i=(this.z&2048)!==0;i!==t&&(Debug&&U.i(t,"boolean",Group,"computesBoundsAfterDrag"),this.z=this.z^2048,this.t("computesBoundsAfterDrag",i,t))}get computesBoundsIncludingLinks(){return(this.z&4096)!==0}set computesBoundsIncludingLinks(t){const i=(this.z&4096)!==0;i!==t&&(Debug&&U.i(t,"boolean",Group,"computesBoundsIncludingLinks"),this.z=this.z^4096,this.t("computesBoundsIncludingLinks",i,t))}get computesBoundsIncludingLocation(){return(this.z&8192)!==0}set computesBoundsIncludingLocation(t){const i=(this.z&8192)!==0;i!==t&&(Debug&&U.i(t,"boolean",Group,"computesBoundsIncludingLocation"),this.z=this.z^8192,this.t("computesBoundsIncludingLocation",i,t))}get handlesDragDropForMembers(){return(this.z&16384)!==0}set handlesDragDropForMembers(t){const i=(this.z&16384)!==0;i!==t&&(Debug&&U.i(t,"boolean",Group,"handlesDragDropForMembers"),this.z=this.z^16384,this.t("handlesDragDropForMembers",i,t))}get avoidableMembers(){return(this.z&131072)!==0}set avoidableMembers(t){const i=(this.z&131072)!==0;i!==t&&(Debug&&U.i(t,"boolean",Group,"avoidableMembers"),this.z=this.z^131072,this.t("avoidableMembers",i,t))}get memberParts(){return this.dg.iterator}xC(t){if(this.dg.add(t)){t instanceof Group&&this.Fa.add(t);const e=this.memberAdded;if(e!==null){let s=!0;const n=this.diagram;n!==null&&(s=n.H,n.H=!0),e(this,t),n!==null&&(n.H=s)}(!this.isVisible()||!this.isSubGraphExpanded)&&t.Hi(!1)}if(t instanceof Link&&!this.computesBoundsIncludingLinks)return;let i=this.Rt;i===null&&(i=this),i.g()}wC(t){if(this.dg.delete(t)){t instanceof Group&&this.Fa.delete(t);const e=this.memberRemoved;if(e!==null){let s=!0;const n=this.diagram;n!==null&&(s=n.H,n.H=!0),e(this,t),n!==null&&(n.H=s)}(!this.isVisible()||!this.isSubGraphExpanded)&&t.Hi(!0)}if(t instanceof Link&&!this.computesBoundsIncludingLinks)return;let i=this.Rt;i===null&&(i=this),i.g()}uc(){if(this.dg.count>0){const t=this.diagram;if(t!==null){const e=this.dg.copy().iterator;for(;e.next();){const s=e.value;t.remove(s)}}}super.uc()}get layout(){return this.fe}set layout(t){const i=this.fe;if(i!==t){t!==null&&(U.s(t,Layout,Group,"layout"),t.diagram!==null&&t.diagram.layout===t&&U.n("A layout cannot be both the Diagram.layout and a Group.layout: "+t)),i!==null&&(i.diagram=null,i.group=null),this.fe=t;const e=this.diagram;t!==null&&(t.diagram=e,t.group=this),e!==null&&(e.tl=!0),this.t("layout",i,t),e!==null&&e.requestUpdate()}}get memberAdded(){return this.Bt!==null?this.Bt.Qy:null}set memberAdded(t){const i=this.memberAdded;i!==t&&(t!==null&&U.C(t,Group,"memberAdded"),this.kl().Qy=t,this.t("memberAdded",i,t))}get memberRemoved(){return this.Bt!==null?this.Bt._y:null}set memberRemoved(t){const i=this.memberRemoved;i!==t&&(t!==null&&U.C(t,Group,"memberRemoved"),this.kl()._y=t,this.t("memberRemoved",i,t))}get memberValidation(){return this.Bt!==null?this.Bt.xh:null}set memberValidation(t){const i=this.memberValidation;i!==t&&(t!==null&&U.C(t,Group,"memberValidation"),this.kl().xh=t,this.t("memberValidation",i,t))}canAddMembers(t){const i=this.diagram;if(i===null)return!1;const e=i.commandHandler,n=e.NN(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.NN(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.z&256)!==0}set ungroupable(t){const i=(this.z&256)!==0;i!==t&&(Debug&&U.i(t,"boolean",Group,"ungroupable"),this.z=this.z^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.s4();if(super.invalidateConnectedLinks(t),i)return;this.pL(!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.ie(s.fromPort),n.ie(s.toPort),s.ii();else{const o=s.toNode;o!==null&&o!==this&&o.isMemberOf(this)&&!o.isVisible()&&(o.ie(s.fromPort),o.ie(s.toPort),s.ii())}}}findExternalLinksConnected(){const t=this.diagram!==null&&this.diagram.S2;if(t&&this.V0!==null)return this.V0.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.V0=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}KB(){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.bh(t,this,!0,0,!0),t.delete(this),t}Hi(t){super.Hi(t);const i=this.memberParts;for(;i.next();)i.value.Hi(t)}collapseSubGraph(){const t=this.diagram;if(t===null||t.isCollapsingExpanding)return;t.isCollapsingExpanding=!0;const i=this.findSubGraphParts();this.CF(i,t,this),t.isCollapsingExpanding=!1}CF(t,i,e){const s=this.memberParts;for(;s.next();){const n=s.value;if(n.Hi(!1),n instanceof Group&&n.isSubGraphExpanded&&(n.wasSubGraphExpanded=n.isSubGraphExpanded,n.CF(t,i,e)),n instanceof Node)n.invalidateConnectedLinks(t),i.$f(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.AF(i,t,this),t.isCollapsingExpanding=!1}AF(t,i,e){const s=this.memberParts;for(;s.next();){const n=s.value;if(n.Hi(!0),n instanceof Group&&n.wasSubGraphExpanded&&(n.wasSubGraphExpanded=!1,n.AF(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.z&512)!==0}set isSubGraphExpanded(t){const i=(this.z&512)!==0;if(i!==t){Debug&&U.i(t,"boolean",Group,"isSubGraphExpanded"),this.z=this.z^512;const e=this.diagram;this.t("isSubGraphExpanded",i,t);const s=this.subGraphExpandedChanged;if(s!==null){let n=!0;e!==null&&(n=e.H,e.H=!0),s(this),e!==null&&(e.H=n)}if(e!==null&&e.undoManager.isUndoingRedoing){this.Rt!==null&&this.Rt.g(),this.memberParts.each(n=>n.updateAdornments());return}t?this.expandSubGraph():this.collapseSubGraph()}}get wasSubGraphExpanded(){return(this.z&1024)!==0}set wasSubGraphExpanded(t){const i=(this.z&1024)!==0;i!==t&&(Debug&&U.i(t,"boolean",Group,"wasSubGraphExpanded"),this.z=this.z^1024,this.t("wasSubGraphExpanded",i,t))}get subGraphExpandedChanged(){return this.Bt!==null?this.Bt.tw:null}set subGraphExpandedChanged(t){const i=this.subGraphExpandedChanged;i!==t&&(t!==null&&U.C(t,Group,"subGraphExpandedChanged"),this.kl().tw=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),a=Point.a();super.move(t,i);const f=new GSet,u=this.findSubGraphParts().iterator;for(;u.next();){const d=u.value;d instanceof Link&&(d.suspendsRouting&&f.add(d),!(!d.Be&&(d.fromNode===this||d.toNode===this))&&(d.suspendsRouting=!0))}for(u.reset();u.next();){const d=u.value;if(d.Ir()||d instanceof Node&&d.isLinkLabel)continue;const m=d.position,g=d.location;m.isReal()?(a.x=m.x+l,a.y=m.y+h,d.position=a):g.isReal()&&(a.x=g.x+l,a.y=g.y+h,d.location=a)}for(u.reset();u.next();){const d=u.value;if(!(d instanceof Link)||(d.suspendsRouting=f.has(d),!d.Be&&(d.fromNode===this||d.toNode===this)))continue;const m=d.position;a.x=m.x+l,a.y=m.y+h,a.isReal()?d.move(a):d.ii()}Point.o(a)}s4(){return(this.z&65536)!==0}pL(t){(this.z&65536)!==0!==t&&(this.z=this.z^65536)}get Ia(){return(this.z&32768)!==0}set Ia(t){(this.z&32768)!==0!==t&&(this.z=this.z^32768)}}class Placeholder extends GraphObject{si;gg;constructor(t){super(),this.si=Margin.hm,this.gg=new Rect(NaN,NaN,NaN,NaN),t&&Object.assign(this,t)}cloneProtected(t){super.cloneProtected(t),t.si=this.si.T(),t.gg=this.gg.copy()}Ah(t){if(this.background===null)return!1;const i=this.naturalBounds;return Rect.contains(0,0,i.width,i.height,t.x,t.y)}Cd(t,i,e,s){const n=this.part;if((n===null||!(n instanceof Group)&&!(n instanceof Adornment))&&U.n("Placeholder is not inside a Group or Adornment."),n instanceof Group){const o=this.computeBorder(this.gg),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,a=this.ji;a.$n(l||0,h||0),this.fo(0,0,a.width,a.height);const f=n.memberParts;let c=!1;for(;f.next();)if(f.value.isVisible()){c=!0;break}const u=n.diagram;if(c&&u!==null&&!u.animationManager.RM(n)&&!isNaN(o.x)&&!isNaN(o.y)){const d=Point.a();d.setRectSpot(o,n.locationSpot),n.location=d,Point.o(d)}}else{const o=n,r=this.ji,l=this.si,h=l.left+l.right,a=l.top+l.bottom,f=o.adornedObject,c=f.getDocumentAngle();o.angle=c;let u=0;f instanceof Shape&&(u=f.strokeWidth);const d=f.getDocumentScale(),m=f.naturalBounds,g=(m.width+u)*d,p=(m.height+u)*d;if(o.type!==Panel.Link){const y=o.category==="Selection"?Spot.TopLeft:o.locationSpot,x=f.getDocumentPoint(y,Point.a());o.location=x,Point.o(x)}if(!isNaN(g)&&!isNaN(p))r.$n(g+h||0,p+a||0),this.fo(-l.left,-l.top,r.width,r.height);else{const y=f.getDocumentPoint(Spot.TopLeft,Point.a()),x=Rect.U(y.x,y.y,0,0);x.unionPoint(f.getDocumentPoint(Spot.BottomRight,y)),x.unionPoint(f.getDocumentPoint(Spot.TopRight,y)),x.unionPoint(f.getDocumentPoint(Spot.BottomLeft,y)),r.$n(x.width+h||0,x.height+a||0),this.fo(-l.left,-l.top,r.width,r.height),Point.o(y),Rect.o(x)}}}Th(t,i,e,s){this.actualBounds.e(t,i,e,s)}computeBorder(t){const i=this.part,e=i.diagram;if(e===null||e.animationManager.isAnimating)return t;if(i instanceof Group&&!i.layer.isTemporary&&i.computesBoundsAfterDrag&&this.gg.isReal()){const r=e.toolManager.findTool("Dragging");if(r===e.currentTool&&r.PR(i,this.gg,t))return t}const s=Rect.a(),n=this.computeMemberBounds(s),o=this.si;return i instanceof Group&&!i.isSubGraphExpanded?t.e(n.x-o.left,n.y-o.top,0,0):t.e(n.x-o.left,n.y-o.top,Math.max(n.width+o.left+o.right,0),Math.max(n.height+o.top+o.bottom,0)),Rect.o(s),i instanceof Group&&i.computesBoundsIncludingLocation&&i.location.isReal()&&t.unionPoint(i.location),t}computeMemberBounds(t){if(!(this.part instanceof Group))return t.e(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.vo()||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.e(l.x,l.y,0,0)}else t.e(e,s,n-e,o-s);return t}get padding(){return this.si}set padding(t){typeof t=="number"?t=new Margin(t):U.s(t,Margin,Placeholder,"padding");const i=this.si;i.equals(t)||(t=t.T(),this.si=t,this.t("padding",i,t),this.g())}}class Layout{f;Ra;mg;Rr;pg;yg;Uo;Cl;wg;xg;No;constructor(t){GSet._i(this),this.f=null,this.Ra=null,this.mg=!0,this.Rr=!0,this.pg=!1,this.yg=new Point(0,0),this.Uo=!0,this.Cl=null,this.wg=null,this.xg=!1,this.No=null,t&&Object.assign(this,t)}cloneProtected(t){t.mg=this.mg,t.Rr=this.Rr,t.pg=this.pg,t.yg.c(this.yg),t.Uo=this.Uo,t.Cl=this.Cl,t.wg=this.wg,t.xg=!0}copy(){const t=new this.constructor;return this.cloneProtected(t),t}gi(t){U.wr(this,t)}toString(){let t=U.Jn(this.constructor);return t+="(",this.group!==null&&(t+=" in "+this.group),this.diagram!==null&&(t+=" for "+this.diagram),t+=")",t}get diagram(){return this.f}set diagram(t){Debug&&t!==null&&U.s(t,Diagram,Layout,"diagram"),this.f=t}get group(){return this.Ra}set group(t){this.Ra!==t&&(Debug&&t!==null&&U.s(t,Group,Layout,"group"),this.Ra=t,t!==null&&(this.f=t.diagram))}get isOngoing(){return this.mg}set isOngoing(t){this.mg!==t&&(U.i(t,"boolean",Layout,"isOngoing"),this.mg=t)}get isInitial(){return this.Rr}set isInitial(t){U.i(t,"boolean",Layout,"isInitial"),this.Rr=t,t||(this.xg=!0)}get isViewportSized(){return this.pg}set isViewportSized(t){this.pg!==t&&(U.i(t,"boolean",Layout,"isViewportSized"),this.pg=t,t&&this.b())}get isRouting(){return this.Uo}set isRouting(t){this.Uo!==t&&(U.i(t,"boolean",Layout,"isRouting"),this.Uo=t)}get isRealtime(){return this.Cl}set isRealtime(t){this.Cl!==t&&(t!==null&&U.i(t,"boolean",Layout,"isRealtime"),this.Cl=t)}get isValidLayout(){return this.xg}set isValidLayout(t){if(this.xg!==t&&(U.i(t,"boolean",Layout,"isValidLayout"),this.xg=t,!t)){const i=this.diagram;i!==null&&(i.tl=!0)}}invalidateLayout(){if(!this.isValidLayout)return;const t=this.diagram;if(t===null||t.undoManager.isUndoingRedoing)return;const i=t.animationManager;i.isTicking||(i.defaultAnimation.isAnimating&&i.stopAnimation(),(this.isOngoing&&t.oa||this.isInitial&&!t.oa)&&(this.isValidLayout=!1,t.requestUpdate()))}b(){this.invalidateLayout()}get network(){return this.No}set network(t){this.No!==t&&(Debug&&t!==null&&U.s(t,LayoutNetwork,Layout,"network"),this.No=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){Debug&&t===null&&U.n("Layout.doLayout(collection) argument must not be null but a Diagram, a Group, or an Iterable of Parts");const i=new GSet;if(t instanceof Diagram?(this.Uh(i,t.nodes,!0,this.Ia,!0,!1,!0),this.Uh(i,t.parts,!0,this.Ia,!0,!1,!0)):t instanceof Group?this.Uh(i,t.memberParts,!1,this.Ia,!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 a=t.iterator;for(;a.next();){const f=a.value;f.ensureBounds();const c=f.measuredBounds,u=c.width,d=c.height;f.moveTo(o,r),f instanceof Group&&(f.Ia=!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++}}Ia(t){return!!(!t.location.isReal()&&!t.position.isReal()||t instanceof Group&&t.Ia)}Uh(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.Uh(t,h.memberParts,!1,s,n,o,r):(h.ensureBounds(),t.add(h))}else o&&h instanceof Link?t.add(h):r&&h.Oe()&&!(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.wg}set boundsComputation(t){this.wg!==t&&(t!==null&&U.C(t,Layout,"boundsComputation"),this.wg=t,this.b())}collectParts(t){const i=new GSet;return t instanceof Diagram?(this.Uh(i,t.nodes,!0,null,!0,!0,!0),this.Uh(i,t.links,!0,null,!0,!0,!0),this.Uh(i,t.parts,!0,null,!0,!0,!0)):t instanceof Group?this.Uh(i,t.memberParts,!1,null,!0,!0,!0):this.Uh(i,t.iterator,!1,null,!0,!0,!0),i}get arrangementOrigin(){return this.yg}set arrangementOrigin(t){Debug&&U.s(t,Point,Layout,"arrangementOrigin"),this.yg.equals(t)||(this.yg.c(t),this.b())}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{fe;Co;Xn;lw;hw;constructor(t){GSet._i(this),Debug&&!t&&U.n("LayoutNetwork constructor requires non-null Layout argument"),this.fe=t,this.Co=new GSet,this.Xn=new GSet,this.lw=new GMap,this.hw=new GMap}clear(){if(this.Co){const t=this.Co.iterator;for(;t.next();)t.value.clear()}if(this.Xn){const t=this.Xn.iterator;for(;t.next();)t.value.clear()}this.Co=new GSet,this.Xn=new GSet,this.lw=new GMap,this.hw=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.Xn.count,t>1){const e=this.Co.iterator;for(;e.next();){const n=e.value;i+=` `+n.toString(t-1)}const s=this.Xn.iterator;for(;s.next();){const n=s.value;i+=` `+n.toString(t-1)}}return i}get layout(){return this.fe}set layout(t){t!==null&&(this.fe=t)}get vertexes(){return this.Co}get edges(){return this.Xn}createVertex(){return new LayoutVertex(this)}createEdge(){return new LayoutEdge(this)}addParts(t,i,e){if(t===null)return;i===void 0&&(i=!1),U.i(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){Debug&&U.s(t,LayoutVertex,LayoutNetwork,"addVertex:vertex"),this.Co.add(t);const i=t.node;i!==null&&this.lw.set(i,t),t.network=this}addNode(t){Debug&&U.s(t,Node,LayoutNetwork,"addNode:node");let i=this.findVertex(t);return i===null&&(i=this.createVertex(),i.node=t,this.addVertex(i)),i}deleteVertex(t){if(Debug&&U.s(t,LayoutVertex,LayoutNetwork,"deleteVertex:vertex"),this.TF(t)){let i=t.hr;for(let e=i.count-1;e>=0;e--){const s=i.elt(e);this.deleteEdge(s)}i=t.ar;for(let e=i.count-1;e>=0;e--){const s=i.elt(e);this.deleteEdge(s)}}}TF(t){const i=this.Co.delete(t);if(i){const e=t.node;e!==null&&this.lw.delete(e)}return i}deleteNode(t){Debug&&U.s(t,Node,LayoutNetwork,"deleteNode:node");const i=this.findVertex(t);i!==null&&this.deleteVertex(i)}findVertex(t){return Debug&&U.s(t,Node,LayoutNetwork,"findVertex:node"),this.lw.get(t)}addEdge(t){Debug&&U.s(t,LayoutEdge,LayoutNetwork,"addEdge:edge"),this.HC(t);const i=t.toVertex;i!==null&&i.addSourceEdge(t);const e=t.fromVertex;e!==null&&e.addDestinationEdge(t)}HC(t){this.Xn.add(t);const i=t.link;i!==null&&this.findEdge(i)===null&&this.hw.set(i,t),t.network=this}addLink(t){Debug&&U.s(t,Link,LayoutNetwork,"addLink:link");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){Debug&&U.s(t,LayoutEdge,LayoutNetwork,"deleteEdge:edge");const i=t.toVertex;i!==null&&i.deleteSourceEdge(t);const e=t.fromVertex;e!==null&&e.deleteDestinationEdge(t),this.vC(t)}vC(t){const i=this.Xn.delete(t);if(i){const e=t.link;e!==null&&this.hw.delete(e)}return i}deleteLink(t){Debug&&U.s(t,Link,LayoutNetwork,"deleteLink:link");const i=this.findEdge(t);i!==null&&this.deleteEdge(i)}findEdge(t){return Debug&&U.s(t,Link,LayoutNetwork,"findEdge:link"),this.hw.get(t)}linkVertexes(t,i,e){if(t===null||i===null)return null;if(Debug&&(U.s(t,LayoutVertex,LayoutNetwork,"linkVertexes:fromVertex"),U.s(i,LayoutVertex,LayoutNetwork,"linkVertexes:toVertex"),e!==null&&U.s(e,Link,LayoutNetwork,"linkVertexes:link")),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){Debug&&U.s(t,LayoutEdge,LayoutNetwork,"reverseEdge:edge");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.at(),i=this.Xn.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.ar.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.n4(o,n),e=!0;break}}return i.sort((s,n)=>s===null||n===null||s===n?0:n.vertexes.count-s.vertexes.count),i}n4(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.TF(s),t.addVertex(s);let n=s.sourceEdges;for(;n.next();){const o=n.value;o.network!==t&&(this.vC(o),t.HC(o),o.fromVertex&&e.add(o.fromVertex))}for(n=s.destinationEdges;n.next();){const o=n.value;o.network!==t&&(this.vC(o),t.HC(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.Xn.iterator;for(;e.next();){const s=e.value;s.link&&t.add(s.link)}return t}}class LayoutVertex{No;oi;Ve;Ue;os;hr;ar;constructor(t){GSet._i(this),Debug&&!t&&U.n("LayoutVertex constructor requires non-null LayoutNetwork argument"),this.No=t,this.Ue=new Rect(0,0,10,10),this.os=new Point(5,5),this.oi=null,this.Ve=null,this.hr=new List,this.ar=new List}clear(){this.oi=null,this.Ve=null,this.hr=new List,this.ar=new List}toString(t){t===void 0&&(t=0);let i="LayoutVertex#"+GSet.Ps(this);if(t>0&&(i+=this.node!==null?"("+this.node.toString()+")":"",t>1)){let e="",s=!0,n=this.hr.iterator;for(;n.next();){const r=n.value;s?s=!1:e+=",",e+=r.toString(0)}let o="";for(s=!0,n=this.ar.iterator;n.next();){const r=n.value;s?s=!1:o+=",",o+=r.toString(0)}i+=" sources: "+e+" destinations: "+o}return i}get Ao(){return this.hr.OA}get fr(){return this.ar.OA}get data(){return this.oi}set data(t){if(this.oi=t,t!==null&&t.bounds){const i=t.bounds,e=i.x,s=i.y,n=i.width,o=i.height;this.os.e(n/2,o/2),this.Ue.e(e,s,n,o)}}get node(){return this.Ve}set node(t){if(this.Ve!==t){if(Debug&&t!==null&&U.s(t,Node,LayoutVertex,"node"),this.Ve=t,t===null)return;t.ensureBounds();const i=this.network.layout,e=Rect.a(),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.Ue.e(n,o,r,l),Rect.o(e),!(t instanceof Group)){const h=t.locationObject.getDocumentPoint(Spot.Center);if(h.isReal()){this.os.e(h.x-n,h.y-o);return}}this.os.e(r/2,l/2)}}get bounds(){return this.Ue}set bounds(t){this.Ue.equals(t)||(Debug&&U.s(t,Rect,LayoutVertex,"bounds"),this.Ue.c(t))}get focus(){return this.os}set focus(t){this.os.equals(t)||(Debug&&U.s(t,Point,LayoutVertex,"focus"),this.os.c(t))}get centerX(){return this.Ue.x+this.os.x}set centerX(t){const i=this.Ue;i.x+this.os.x!==t&&(Debug&&U.r(t,LayoutVertex,"centerX"),i.x=t-this.os.x)}get centerY(){return this.Ue.y+this.os.y}set centerY(t){const i=this.Ue;i.y+this.os.y!==t&&(Debug&&U.r(t,LayoutVertex,"centerY"),i.y=t-this.os.y)}get focusX(){return this.os.x}set focusX(t){const i=this.os;i.x!==t&&(i.x=t)}get focusY(){return this.os.y}set focusY(t){const i=this.os;i.y!==t&&(i.y=t)}get x(){return this.Ue.x}set x(t){const i=this.Ue;i.x!==t&&(i.x=t)}get y(){return this.Ue.y}set y(t){const i=this.Ue;i.y!==t&&(i.y=t)}get width(){return this.Ue.width}set width(t){const i=this.Ue;i.width!==t&&(i.width=t)}get height(){return this.Ue.height}set height(t){const i=this.Ue;i.height!==t&&(i.height=t)}commit(){const t=this.oi;if(t!==null){const e=this.bounds,s=t.bounds;U.it(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.a();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.o(s);return}Rect.o(s)}i.moveTo(e.x+i.margin.left,e.y+i.margin.top)}}addSourceEdge(t){t!==null&&(Debug&&U.s(t,LayoutEdge,LayoutVertex,"addSourceEdge:edge"),this.hr.has(t)||this.hr.add(t))}deleteSourceEdge(t){t!==null&&(Debug&&U.s(t,LayoutEdge,LayoutVertex,"deleteSourceEdge:edge"),this.hr.delete(t))}addDestinationEdge(t){t!==null&&(Debug&&U.s(t,LayoutEdge,LayoutVertex,"addDestinationEdge:edge"),this.ar.has(t)||this.ar.add(t))}deleteDestinationEdge(t){t!==null&&(Debug&&U.s(t,LayoutEdge,LayoutVertex,"deleteDestinationEdge:edge"),this.ar.delete(t))}get network(){return this.No}set network(t){Debug&&U.s(t,LayoutNetwork,LayoutVertex,"network"),this.No=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.hr.iterator}get destinationEdges(){return this.ar.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.hr.count+this.ar.count}static standardComparer(t,i){Debug&&U.s(t,LayoutVertex,LayoutVertex,"standardComparer:m"),Debug&&U.s(i,LayoutVertex,LayoutVertex,"standardComparer:n");const e=t.Ve,s=i.Ve;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(Debug&&U.s(t,LayoutVertex,LayoutVertex,"smartComparer:m"),Debug&&U.s(i,LayoutVertex,LayoutVertex,"smartComparer:n"),t!==null)if(i!==null){const e=t.Ve,s=i.Ve;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.ns!==null?"("+this.ns.toString()+")":"",t>1&&(i+=" "+(this.rs?this.rs.toString():"null")+" --> "+(this.ls?this.ls.toString():"null"))),i}reverseEdge(){const t=this.rs;this.rs=this.ls,this.ls=t}commit(){}getOtherVertex(t){return Debug&&U.s(t,LayoutVertex,LayoutEdge,"getOtherVertex:v"),this.ls===t?this.rs:this.rs===t?this.ls:null}get network(){return this.No}set network(t){Debug&&U.s(t,LayoutNetwork,LayoutEdge,"network"),this.No=t}get data(){return this.oi}set data(t){this.oi!==t&&(Debug&&t!==null&&U.Ro(t,LayoutEdge,"data"),this.oi=t)}get link(){return this.ns}set link(t){this.ns!==t&&(Debug&&t!==null&&U.s(t,Link,LayoutEdge,"link"),this.ns=t)}get fromVertex(){return this.rs}set fromVertex(t){this.rs!==t&&(Debug&&t!==null&&U.s(t,LayoutVertex,LayoutEdge,"fromVertex"),this.rs=t)}get toVertex(){return this.ls}set toVertex(t){this.ls!==t&&(Debug&&t!==null&&U.s(t,LayoutVertex,LayoutEdge,"toVertex"),this.ls=t)}}var GridAlignment=(w=>(w[w.Position=0]="Position",w[w.Location=1]="Location",w))(GridAlignment||{}),GridArrangement=(w=>(w[w.LeftToRight=10]="LeftToRight",w[w.RightToLeft=11]="RightToLeft",w))(GridArrangement||{}),GridSorting=(w=>(w[w.Forwards=20]="Forwards",w[w.Reverse=21]="Reverse",w[w.Ascending=22]="Ascending",w[w.Descending=23]="Descending",w))(GridSorting||{});class GridLayout extends Layout{bg;Sg;zo;Yn;pi;Ji;Ce;Ae;constructor(t){super(),this.isViewportSized=!0,this.bg=NaN,this.Sg=NaN,this.zo=new Size(NaN,NaN).k(),this.Yn=new Size(10,10).k(),this.pi=1,this.Ji=10,this.Ce=22,this.Ae=GridLayout.standardComparer,t&&Object.assign(this,t)}cloneProtected(t){super.cloneProtected(t),t.bg=this.bg,t.Sg=this.Sg,t.zo.c(this.zo),t.Yn.c(this.Yn),t.pi=this.pi,t.Ji=this.Ji,t.Ce=this.Ce,t.Ae=this.Ae}gi(t){t in GridSorting?this.sorting=t:t in GridArrangement?this.arrangement=t:t in GridAlignment?this.alignment=t:super.gi(t)}doLayout(t){Debug&&t===null&&U.n("Layout.doLayout(collection) argument must not be null but a Diagram, a Group, or an Iterable of Parts"),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.Ir()&&(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 a=this.spacing.height;isFinite(a)||(a=0),e!==null&&e.startTransaction("Layout");const f=[];switch(this.alignment){case 0:this.o4(o,l,r,h,a,f);break;case 1:this.r4(o,l,r,h,a,f);break}let c=0,u=0,d=0;for(let m=0;m0&&m>e-1||i>0&&m>0&&A-f>i)&&(o.push(new Rect(0,d,i+s,g)),m=0,u=f,d+=g,g=0),g=Math.max(g,P);let C=0;switch(a){case 11:C=-x.width;break;default:C=0;break}switch(y.moveTo(u+C+y.margin.left,d+y.margin.top),a){case 11:u-=k;break;default:u+=k;break}m++}o.push(new Rect(0,d,i+s,g)),Rect.o(r)}r4(t,i,e,s,n,o){const r=Rect.a();let l=Math.max(this.cellSize.width,1),h=0,a=0,f=0;const c=Point.a();for(let C=0;C=h&&(i-=h);let x=0,b=0;const S=Math.max(this.cellSize.height,1);f=0;let k=0,P=!0;const A=Point.a();for(let C=0;C0)switch(u){case 11:{let D=(g-d-(N.width-T.x))/l;G.q(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;G.q(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 L=0;switch(u){case 11:L=-(g+T.x)+x;break;default:L=g+N.width-T.x-x;break}if(e>0&&y>e-1||i>0&&y>0&&L>i){o.push(new Rect(0,P?p-f:p,i+s,k+f+n));for(let D=0;Db&&(M.width+=M.x-b,M.x=b)}Rect.o(r)}commitLayers(t,i){}get wrappingWidth(){return this.bg}set wrappingWidth(t){this.bg!==t&&(U.i(t,"number",GridLayout,"wrappingWidth"),(t>0||isNaN(t))&&(this.bg=t,this.isViewportSized=isNaN(t),this.b()))}get wrappingColumn(){return this.Sg}set wrappingColumn(t){this.Sg!==t&&(U.i(t,"number",GridLayout,"wrappingColumn"),(t>0||isNaN(t))&&(this.Sg=t,this.b()))}get cellSize(){return this.zo}set cellSize(t){U.s(t,Size,GridLayout,"cellSize"),this.zo.equals(t)||(this.zo.c(t),this.b())}get spacing(){return this.Yn}set spacing(t){U.s(t,Size,GridLayout,"spacing"),this.Yn.equals(t)||(this.Yn.c(t),this.b())}get alignment(){return this.pi}set alignment(t){this.pi!==t&&(U.W(t,GridAlignment,"GridAlignment"),(t===1||t===0)&&(this.pi=t,this.b()))}get arrangement(){return this.Ji}set arrangement(t){this.Ji!==t&&(U.W(t,GridArrangement,"GridArrangement"),(t===10||t===11)&&(this.Ji=t,this.b()))}get sorting(){return this.Ce}set sorting(t){this.Ce!==t&&(U.W(t,GridSorting,"GridSorting"),(t===20||t===21||t===22||t===23)&&(this.Ce=t,this.b()))}get comparer(){return this.Ae}set comparer(t){this.Ae!==t&&(U.C(t,GridLayout,"comparer"),this.Ae=t,this.b())}static standardComparer(t,i){Debug&&U.s(t,Part,GridLayout,"standardComparer:a"),Debug&&U.s(i,Part,GridLayout,"standardComparer:b");const e=t.text,s=i.text;return es?1:0}static smartComparer(t,i){if(Debug&&U.s(t,Part,GridLayout,"standardComparer:a"),Debug&&U.s(i,Part,GridLayout,"standardComparer:b"),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.IF(s,!1)}),t.forEach(s=>{e.containsNodeData(s)&&this.RS(s)}),i!==!1&&this.diagram.bb(!1)}IF(t,i){if(t==null||this.diagram.undoManager.isUndoingRedoing||this.To.has(t))return null;i===void 0&&(i=!0);const e=this.l4(t);return e!==null&&i&&this.RS(t),e}l4(t){if(t==null||this.diagram.undoManager.isUndoingRedoing||this.To.has(t))return null;const i=this.h4(t),e=this.findTemplateForNodeData(t,i);if(e!==null){e.Yt();const s=e.copy();if(s!==null){const n=this.diagram.Se;return this.diagram.Se=!0,s.sr=i,s.oi=t,this.addsToTemporaryLayer&&(s.wl="Tool"),this.diagram.add(s),s.oi=null,s.data=t,this.diagram.Se=n,s}}return null}insertLink(t,i,e,s){return null}RS(t){}h4(t){return this.diagram.model.getCategoryForNodeData(t)}static RF=!1;static OF=!1;findTemplateForNodeData(t,i){const e=this.diagram,s=e.model,n=s.Oa()&&s.isGroupForData(t);let o=null;return n?(o=e.groupTemplateMap.get(i),o===null&&(o=e.groupTemplateMap.get(""),o===null&&(PartManager.OF||(PartManager.OF=!0,U.ot('No Group template found for category "'+i+'"'),U.ot(" Using default group template")),o=e.u2))):(o=e.nodeTemplateMap.get(i),o===null&&(o=e.nodeTemplateMap.get(""),o===null&&(PartManager.RF||(PartManager.RF=!0,U.ot('No Node template found for category "'+i+'"'),U.ot(" Using default node template")),o=e.a2))),o}getLinkCategoryForData(t){return""}setLinkCategoryForData(t,i){}setFromNodeForLink(t,i,e){}setToNodeForLink(t,i,e){}static EF=!1;findLinkTemplateForCategory(t){const i=this.diagram;let e=i.linkTemplateMap.get(t);return e===null&&(e=i.linkTemplateMap.get(""),e===null&&(PartManager.EF||(PartManager.EF=!0,U.ot('No Link template found for category "'+t+'"'),U.ot(" Using default link template")),e=i.f2)),e}_E(t,i,e){t instanceof Link?(i!==null&&this.DF(i,t),e!==null&&this.LF(e,t)):t instanceof Part&&(i!==null&&this.To.delete(i),e!==null&&this.To.set(e,t))}FF(){const t=this.diagram.model;this.jC(t.nodeDataArray)}jC(t){t.forEach(i=>{this.OS(i)})}OS(t){const i=this.findPartForData(t);i!==null&&(this.diagram.O2(i,!1),this.JC(i))}JC(t){}EC(t){}findPartForKey(t){if(t==null)return null;const e=this.diagram.model.findNodeDataForKey(t);return e!==null?this.To.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.To.get(e);return s instanceof Node?s:null}findLinkForKey(t){return null}findPartForData(t){if(t===null)return null;let i=this.To.get(t);return i!==null||(i=this.Pg.get(t)),i}findNodeForData(t){if(t===null)return null;const i=this.To.get(t);return i instanceof Node?i:null}findLinkForData(t,i){return t===null?null:this.Pg.get(t)}findNodesByExample(...t){const i=new GSet,e=this.kg.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.VF(o,!1));for(let o=0;o0){for(let o=0;oi.wL(s));const e=t.Eh;if(Array.isArray(e)){const s=this.ZC(e);if(s===null)this.Mg.set(e,[t]);else{for(let n=0;ni.VO(s));const e=t.Eh;if(Array.isArray(e)){const s=this.ZC(e);if(s!==null){for(let n=0;n0&&i.removeParts(l,!1),h.count>0){const f=h.iterator;for(;f.next();){const c=f.key,u=f.value;s.set(c,u)}}}if(i!==null&&this.diagram!==null){const o=i.model,r=o.afterCopyFunction;if(r!==null){const l=new GMap;s.each(a=>{a.key.data!==null&&l.set(a.key.data,a.value.data)});const h=this.diagram.model;r(l,o,h)}}const n=s.iterator;for(;n.next();)n.value.updateTargetBindings();return s}ES(t,i,e,s){if(t===null||s&&!t.canCopy())return null;if(e.has(t))return e.get(t);const n=this.QC(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.ES(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,a=this.ES(h,i,e,s);a!==null&&a instanceof Node&&(a.labeledLink=n)}}return n}QC(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);n.addNodeData(o),e=i.findPartForData(o)}}else if(t.Yt(),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)),e.data=r}}return e}get nodes(){return this.kg}get links(){return this.an}get parts(){return this.Ft}get diagram(){return this.f}get addsToTemporaryLayer(){return this.WC}set addsToTemporaryLayer(t){this.WC=t}}class GraphLinksPartManager extends PartManager{V2(){const t=this.diagram.model;this.aw(t.nodeDataArray),this.YF(t.linkDataArray)}aw(t){super.aw(t,!1);const i=this.links.iterator;for(;i.next();)i.value.tg();this.diagram.bb(!1)}YF(t){t.forEach(i=>{this.KF(i)}),this.diagram.bb(!1)}KF(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.Yt();const s=e.copy();if(s!==null){const n=this.diagram.Se;this.diagram.Se=!0,s.sr=i,s.oi=t;const o=this.diagram.model,r=o.BS(t,!0);r!==""&&(s.fromPortId=r);const l=o.Ge(t,!0);if(l!==void 0){const c=this.findNodeForKey(l);c instanceof Node&&(s.fromNode=c)}const h=o.BS(t,!1);h!==""&&(s.toPortId=h);const a=o.Ge(t,!1);if(a!==void 0){const c=this.findNodeForKey(a);c instanceof Node&&(s.toNode=c)}const f=o.getLabelKeysForLinkData(t);return Array.isArray(f)&&f.forEach(c=>{const u=this.findNodeForKey(c);u!==null&&(u.labeledLink=s)}),this.addsToTemporaryLayer&&(s.wl="Tool"),this.diagram.add(s),s.oi=null,s.data=t,this.diagram.Se=n,s}}return null}FF(){const t=this.diagram.model;this.UF(t.linkDataArray),this.jC(t.nodeDataArray)}UF(t){t.forEach(i=>{this.OS(i)})}getLinkCategoryForData(t){return this.diagram.model.getCategoryForLinkData(t)}setLinkCategoryForData(t,i){return this.diagram.model.setCategoryForLinkData(t,i)}setFromNodeForLink(t,i,e){const s=this.diagram.model,n=i!==null?i.data:null;s.setFromKeyForLinkData(t.data,s.getKeyForNodeData(n))}setToNodeForLink(t,i,e){const s=this.diagram.model,n=i!==null?i.data:null;s.setToKeyForLinkData(t.data,s.getKeyForNodeData(n))}EC(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.H){i.H=!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 a=this.findNodeForKey(h);a!==null&&(a.labeledLink=null)}),Array.isArray(l)&&l.forEach(h=>{const a=this.findNodeForKey(h);a!==null&&(a.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.UF(n);const o=t.newValue;this.YF(o)}i.isModified=!0}else if(e===3){const n=t.newValue;if(s==="linkDataArray"&&U.it(n))this.KF(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.it(n))this.OS(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.H=!0}}}XF(){const t=this.diagram.model,i=new Set,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.GF(n,!1)}),e.forEach(n=>{this.findLinkForData(n)===null&&t.qF(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.Ge(i,!0),o=e.findNodeForKey(n);t.fromNode=o,n=s.Ge(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 c=r[0],u=t.labelNodes.first();if(u!==null&&s.getKeyForNodeData(u.data)===c)return}const l=new GSet().addAll(r),h=new GSet;t.labelNodes.each(c=>{if(c.data!==null){const u=s.getKeyForNodeData(c.data);u!==void 0&&h.add(u)}});const a=h.copy();a.removeAll(l);const f=l.copy();if(f.removeAll(h),a.count>0||f.count>0){const c=t;a.each(u=>{const d=e.findNodeForKey(u);d!==null&&d.labeledLink===c&&(d.labeledLink=null)}),f.each(u=>{const d=e.findNodeForKey(u);d!==null&&d.labeledLink!==c&&(d.labeledLink=c)})}}}else if(!(t instanceof Adornment)){const n=s.getGroupKeyForNodeData(i),o=e.findPartForKey(n);(o===null||o instanceof Group)&&(t.containingGroup=o)}}RS(t){const i=this.diagram.model,e=i.getKeyForNodeData(t);if(e!==void 0){const s=i.cw(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.Ge(l,!0)===e&&(h.fromNode=n),i.Ge(l,!1)===e&&(h.toNode=n);const a=i.getLabelKeysForLinkData(l);Array.isArray(a)&&a.some(f=>f===e?(n.labeledLink=h,!0):!1)}}}i.cn(e)}const o=i.getGroupKeyForNodeData(t);if(o!==void 0){const r=this.findNodeForKey(o);n!==null&&r instanceof Group&&(n.containingGroup=r)}}}JC(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.un(e,n.data)}if(t.isLinkLabel){const n=t.labeledLink;n!==null&&i.un(e,n.data)}if(t instanceof Group){const n=t.memberParts;for(;n.next();){const r=n.value.data;i.containsNodeData(r)&&i.un(e,r)}}}}}QC(t,i){let e=super.QC(t,i);if(t instanceof Link){const s=t.data;if(s!==null&&i!==null){const n=i.model,o=n.copyLinkData(s);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);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 a=r.archetypeLinkData;if(a instanceof Link){a.Yt();const f=a.copy();if(f!==null){f.fromNode=t,f.fromPortId=l,f.toNode=e,f.toPortId=h,n.add(f);const c=r.archetypeLabelNodeData;if(c instanceof Node){c.Yt();const u=c.copy();u!==null&&(u.labeledLink=f,n.add(u))}return f}}else if(a!==null){const f=o.copyLinkData(a);if(U.it(f)){t!==null&&o.Ng(f,o.getKeyForNodeData(t.data),!0),o.Cg(f,l,!0),e!==null&&o.Ng(f,o.getKeyForNodeData(e.data),!1),o.Cg(f,h,!1),o.addLinkData(f);const c=r.archetypeLabelNodeData;if(c!==null&&!(c instanceof Node)){const d=o.copyNodeData(c);o.addNodeData(d);const m=o.getKeyForNodeData(d);m!==void 0&&o.addLabelKeyForLinkData(f,m)}return n.findLinkForData(f)}}return null}}class TreePartManager extends PartManager{Gh=null;VS(t,i){if(t===null||i===null||i.findTreeParentLink()!==null)return;const e=this.diagram.toolManager.findTool("Linking");let s=t,n=i;if(this.diagram.isTreePathToChildren){if(e!==null&&e.Gu(s,n,null,!0))return}else if(s=i,n=t,e!==null&&e.Gu(s,n,null,!0))return;const o=this.getLinkCategoryForData(i.data),r=this.findLinkTemplateForCategory(o);if(r!==null){r.Yt();const l=r.copy();if(l!==null){const h=this.diagram.Se;this.diagram.Se=!0,l.sr=o,l.oi=i.data,l.fromNode=s,l.toNode=n,this.diagram.add(l),l.oi=null,l.data=i.data,this.diagram.Se=h}}}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.Gh;this.Gh=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.Gh=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.Gh;this.Gh=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.Gh=o}else s.setParentKeyForNodeData(t.data,s.getKeyForNodeData(n))}EC(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.H){i.H=!1;try{const s=t.modelChange;if(s!==""){if(e===2){if(s==="nodeParentKey"){const n=t.object,o=n?this.findNodeForData(n):null,r=t.newValue,l=this.findNodeForKey(r);if(n&&this.Gh!==null)l!==null&&(this.Gh.data=n,this.Gh.category=this.getLinkCategoryForData(n));else if(o!==null){const h=o.findTreeParentLink();h!==null?l===null?i.remove(h):i.isTreePathToChildren?h.fromNode=l:h.toNode=l:this.VS(l,o)}}else if(s==="parentLinkCategory"){const n=t.object,o=n?this.findNodeForData(n):null,r=t.newValue;if(o!==null&&typeof r=="string"){const l=o.findTreeParentLink();l!==null&&(l.category=r)}}i.isModified=!0}}else e===2&&(t.object===i.model&&t.propertyName==="nodeParentKeyProperty"&&(i.undoManager.isUndoingRedoing||this.rebuildParts()),i.isModified=!0)}finally{i.H=!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.VS(o,t):l!==null&&e.O2(l,!1)}}}fw(t,i){if(super.fw(t,i),typeof i=="string"&&this.findPartForData(t)!==null){const s=this.findLinkForData(t);s!==null&&s.updateTargetBindings(i)}}RS(t){const i=this.diagram.model,e=i.getKeyForNodeData(t);if(e!==void 0){const s=i.cw(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.VS(n,h)}}i.cn(e)}const o=i.getParentKeyForNodeData(t);if(o!==void 0&&n instanceof Node){const r=this.findNodeForKey(o);this.VS(r,n)}}}JC(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.ae(-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,l=n?r.toNode:r.fromNode;if(l!==null){const h=l.data;i.containsNodeData(h)&&i.un(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=(w=>(w[w.OneWay=1]="OneWay",w[w.TwoWay=2]="TwoWay",w))(BindingMode||{});class Binding{l;_C;uf;Jc;qh;$c;Zc;Qc;zS;Re;Kd;Ec;constructor(t,i,e,s){GSet._i(this),t===void 0?t="":U.i(t,"string",Binding,"constructor:targetprop"),i===void 0?i=t:U.i(i,"string",Binding,"constructor:sourceprop"),e===void 0?e=null:e!==null&&U.C(e,Binding,"constructor:conv"),this._C=-1,this.Re=null,this.uf=t,this.Kd=0,this.Ec=0,this.Jc=null,this.qh=i,this.$c=e,s===void 0?(this.Zc=1,this.Qc=null):(this.Zc=2,this.Qc=s),this.zS=new GSet,this.l=2}copy(){const t=new this.constructor;return this.cloneProtected(t),t}cloneProtected(t){t.uf=this.uf,t.Kd=this.Kd,t.Ec=this.Ec,t.Jc=this.Jc,t.qh=this.qh,t.$c=this.$c,t.Zc=this.Zc,t.Qc=this.Qc,t.l=this.l&-2}static OneWay=1;static TwoWay=2;static parseEnum(t,i){return U.C(t,Binding,"parseEnum:ctor"),e=>{let s=parseInt(e);return isNaN(s)&&(s=U.ea(t,e),s===null)?i:s}}gi(t){t in BindingMode?this.mode=t:U.wr(this,t)}static toString(t){return U.toString(t)}toString(){return"Binding("+this.targetProperty+":"+this.sourceProperty+(this.targetId!==-1?" "+this.targetId:"")+" "+BindingMode[this.mode]+")"}k(){return this.l=this.l|1,this}get targetId(){return this._C}set targetId(t){this.p&&U.D(this),this._C=t}get targetProperty(){return this.uf}set targetProperty(t){this.p&&U.D(this),U.i(t,"string",Binding,"targetProperty"),this.uf=t}get sourceProperty(){return this.qh}set sourceProperty(t){this.p&&U.D(this),U.i(t,"string",Binding,"sourceProperty"),this.qh=t}get p(){return(this.l&1)!==0}get isToData(){return(this.l&2)!==0}get isToObject(){return(this.l&4)!==0}get isToModel(){return(this.l&8)!==0}get isToTheme(){return(this.l&16)!==0}get tA(){return this.isToTheme&&!(this.isToData||this.isToObject||this.isToModel)}Nd(){return!1}get sourceName(){return this.Jc}set sourceName(t){this.p&&U.D(this),t!==null&&U.i(t,"string",Binding,"sourceName"),this.Jc=t,t!==null?this.l=this.l&-3|4:this.l=this.l|2}get converter(){return this.$c}set converter(t){this.p&&U.D(this),t!==null&&U.C(t,Binding,"converter"),this.$c=t}get backConverter(){return this.Qc}set backConverter(t){this.p&&U.D(this),t!==null&&U.C(t,Binding,"backConverter"),this.Qc=t}get mode(){return this.Zc}set mode(t){this.p&&U.D(this),this.isToTheme&&t===2&&U.n("Theme Bindings cannot be TwoWay."),U.W(t,BindingMode,"BindingMode"),this.Zc=t}makeTwoWay(t){return this.isToTheme&&U.n("Theme Bindings cannot be TwoWay."),this.mode=2,t&&(U.C(t,Binding,"makeTwoWay"),this.backConverter=t),this}ofObject(t){return this.p&&U.D(this),t===void 0&&(t=""),Debug&&U.i(t,"string",Binding,"ofObject:srcname"),this.sourceName=t,this}ofModel(){return this.p&&U.D(this),this.l=this.l&-3&-5|8,this.Jc=null,this}iD(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.uf,e=this.qh,s=this.$c;(this.Nd()&&s===null&&this.Hh===null&&i===""||s===null&&i==="")&&U.ot("Binding error: target property is the empty string: "+this.toString()),this.Nd()&&this.tA&&e===""&&s===null&&this.Hh===null&&U.ot("Binding error: theme bindings require a source property when not using a converter: "+this.toString()),t&&typeof i=="string"&&(!U.ht(["setAttribute"])&&i.length>0&&i[0]!=="_"&&!U.Zw(t,i)?U.ot("Binding error: undefined target property: "+i+" on "+t.toString()):i==="name"&&t instanceof GraphObject&&U.ot("Binding error: cannot modify GraphObject.name on "+t.toString()))}updateTarget(t,i,e,s){const n=this.qh;if(e!==void 0&&n!==""&&n!==e||this.isToTheme&&t.diagram===null)return;const o=this.uf,r=this.$c;let l=i;if(n!==""&&!this.tA&&(l=Model.Tt(i,n)),l!==void 0)if(r===null){if(o!==""){if(this.Nd()){const h=t.diagram?.themeManager;if(l=this.HF(h,l,t,o),l===void 0)return}s?s.rt(t,o,l):(i instanceof GraphObject||i instanceof RowColumnDefinition)&&Model.rt(t,o,l)}}else try{if(o!==""){let h=r(l,t);if(Debug&&h===void 0&&U.ot('Binding warning: conversion function returned undefined when setting target property "'+o+'" on '+t.toString()+", function is: "+r),this.Nd()){const a=t.diagram?.themeManager;if(h=this.HF(a,h,t,o),h===void 0)return}s?s.rt(t,o,h):(i instanceof GraphObject||i instanceof RowColumnDefinition)&&Model.rt(t,o,h)}else r(l,t)}catch(h){Debug&&U.ot("Binding error: "+h.toString()+' setting target property "'+o+'" on '+t.toString()+" with conversion function: "+r)}}updateSource(t,i,e,s){if(this.Zc!==2)return;const n=this.uf;if(e!==void 0&&n!==e)return;const o=this.qh,r=this.Qc,l=s!==null?s.diagram:null,h=l!==null?l.model:null;let a=t;if(n!==""&&(a=Model.Tt(t,n)),a!==void 0&&!this.zS.has(t))try{if(this.zS.add(t),r===null){if(o!=="")h!==null?(Debug&&h.nodeKeyProperty===o&&h.containsNodeData(i)&&U.ot("Binding error: cannot have TwoWay Binding on node data key property: "+this.toString()),h.setDataProperty(i,o,a)):(i instanceof GraphObject||i instanceof RowColumnDefinition)&&(i[o]=a);else if(h!==null&&s!==null&&s.itemIndex>=0&&s.panel!==null&&Array.isArray(s.panel.itemArray)){const f=s.itemIndex,c=s.panel.itemArray;h.removeArrayItem(c,f),h.insertArrayItem(c,f,a)}}else try{if(o!==""){const f=r(a,i,h);h!==null?(Debug&&(h.nodeKeyProperty===o&&h.containsNodeData(i)&&U.ot("Binding error: cannot have TwoWay Binding on node data key property: "+this.toString()),f===void 0&&U.ot(`Binding warning: conversion function returned undefined when setting source property "${o}" on ${i.toString()}, function is: ${r}`)),h.setDataProperty(i,o,f)):(i instanceof GraphObject||i instanceof RowColumnDefinition)&&(i[o]=f)}else{const f=r(a,i,h);if(f!==void 0&&h!==null&&s!==null&&s.itemIndex>=0&&s.panel!==null&&Array.isArray(s.panel.itemArray)){const c=s.itemIndex,u=s.panel.itemArray;h.removeArrayItem(u,c),h.insertArrayItem(u,c,f)}}}catch(f){Debug&&U.ot("Binding error: "+f.toString()+' setting source property "'+o+'" on '+i.toString()+" with conversion function: "+r)}}finally{this.zS.delete(t)}}}class ThemeBinding extends Binding{uw;Hh;df;constructor(t,i,e,s,n){super(t,i,s),e==null&&(e=""),n===void 0&&(n=null),this.uw=e,this.Hh=n,this.df=null,this.l=16}cloneProtected(t){super.cloneProtected(t),t.uw=this.uw,t.Hh=this.Hh,t.df=this.df}Nd(){return!0}get themeSource(){return this.uw}set themeSource(t){this.p&&U.D(this),t!==null&&U.i(t,"string",ThemeBinding,"themeSource"),this.uw=t,this.df=null,t!==null?this.l=this.l|16:this.l=this.l&-17}get themeConverter(){return this.Hh}set themeConverter(t){this.p&&U.D(this),t!==null&&U.C(t,ThemeBinding,"themeConverter"),this.Hh=t}ofData(){return this.p&&U.D(this),this.l=this.l|2,this.Jc=null,this}HF(t,i,e,s){if(!t||(this.tA&&(i=this.qh),!i&&i!==0))return;let n=this.themeSource;this.df!==null?n=this.df:typeof n=="string"&&n.includes(".")&&(this.df=n.split("."),n=this.df);let o=t.findValue(i,n,s);if(o===void 0&&U.ot(`Theme warning: ${i} could not be found when setting target property ${s}.`),t.readsCssVariables&&typeof o=="string"&&o.startsWith("var(")){const r=o.match(this.c4);r&&(o=getComputedStyle(root.document.documentElement).getPropertyValue(r[1]))}return U.ht(this.Hh)&&(o=this.Hh(o,e)),o}c4=/var\((.*)\)/}class Model{At;Ag;qo;iA;Te;Pi;vh;_c;tu;Tg;Lg;Dg;Fg;dw;gf;cr;gw;Go;XS;constructor(t,i){if(GSet._i(this),this.At="",this.Ag="",this.qo=!1,this.iA={},this.Te=[],this.Pi=new GMap,this.vh="key",this._c=null,this.tu=null,this.Tg=!1,this.Lg=!1,this.Dg=!1,this.Fg=null,this.dw=100,this.gf="category",this.cr=new GMap,this.gw=[],this.Go=!1,this.XS=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.At=this.At,t.Ag=this.Ag,t.qo=this.qo,t.vh=this.vh,t._c=this._c,t.tu=this.tu,t.Tg=this.Tg,t.Lg=this.Lg,t.Dg=this.Dg,t.Fg=this.Fg,t.dw=this.dw,t.gf=this.gf}copy(){const t=new this.constructor;return this.cloneProtected(t),t}clear(){this.Te=[],this.Pi.clear(),this.cr.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))u.object!==null&&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)){const d=e.get(u.object);d&&d.each(m=>{s.containsNodeData(m)&&r.add(m)})}else{if(u.object instanceof Model||s.tf()&&s.containsLinkData(u.object))return;s.WF(u.object).each(m=>{r.add(m)})}}});const h=new GSet;o.each(u=>{const d=s.getKeyForNodeData(u);d!==void 0&&h.add(d),i||r.add(u)});const a=new GSet;l.each(u=>{const d=s.getKeyForNodeData(u);d!==void 0&&a.add(d),i&&r.add(u)});const f=s.cloneDeep(r.toArray());let c=null;return n&&(c===null&&(c={}),c.modelData=this.cloneDeep(this.modelData)),h.count>0&&(c===null&&(c={}),i?c.removedNodeKeys=h.toArray():c.insertedNodeKeys=h.toArray()),f.length>0&&(c===null&&(c={}),c.modifiedNodeData=f),a.count>0&&(c===null&&(c={}),i?c.insertedNodeKeys=a.toArray():c.removedNodeKeys=a.toArray()),c}cloneDeep(t){return this.Ig(t,!0)}Ig(t,i,e,s){if(!U.it(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)})}Rg(){let t="";return this.name!==""&&(t+=`, "name": `+this.quote(this.name)),this.dataFormat!==""&&(t+=`, "dataFormat": `+this.quote(this.dataFormat)),this.isReadOnly&&(t+=`, "isReadOnly": `+this.isReadOnly),this.nodeKeyProperty!=="key"&&typeof this.nodeKeyProperty=="string"&&(t+=`, "nodeKeyProperty": `+this.quote(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.quote(this.nodeCategoryProperty)),t}mw(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)}jF(){const t=this.modelData;return`, "modelData": `+this.JF(t)}$F(t){const i=t.modelData;U.it(i)&&(this.replaceJsonObjects(i),this.modelData=i)}nA(){const t=this.modelData;let i=!1;for(const s in t)if(!this.YS(t,s,t[s])){i=!0;break}let e="";return i&&(e=this.jF()),e+`, "nodeDataArray": `+this.Wh(this.nodeDataArray,!0)}oA(t){this.$F(t);const i=t.nodeDataArray;Array.isArray(i)&&(this.replaceJsonObjects(i),this.nodeDataArray=i)}rA(t,i,e){if(t===i)return!0;if(typeof t!=typeof i||U.ht(t)||U.ht(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){if(s.object!==null){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}WF(t){const i=new GSet;for(let e=0;e{if(c.model===s){if(c.modelChange==="nodeDataArray")c.change===3?o.add(c.newValue):c.change===4&&l.add(c.oldValue);else if(s.containsNodeData(c.object))c.object!==null&&r.add(c.object);else if(c.change===2&&(s.modelData===c.object||c.propertyName==="modelData"))n=!0;else if(c.object!==null)if(e.has(c.object)){const u=e.get(c.object);u&&u.each(d=>{s.containsNodeData(d)&&r.add(d)})}else{if(c.object instanceof Model||s.tf()&&s.containsLinkData(c.object))return;s.WF(c.object).each(d=>{r.add(d)})}}});const h=new GSet;o.each(c=>{const u=s.getKeyForNodeData(c);u!==void 0&&h.add(u),i||r.add(c)});const a=new GSet;l.each(c=>{const u=s.getKeyForNodeData(c);u!==void 0&&a.add(u),i&&r.add(c)});let f="";return n&&(f+=this.jF()),h.count>0&&(f+=(i?Model.QF:Model.ZF)+this.Wh(h.toArray(),!0)),r.count>0&&(f+=Model.u4+this.Wh(r.toArray(),!0)),a.count>0&&(f+=(i?Model.ZF:Model.QF)+this.Wh(a.toArray(),!0)),f}pw(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.n("applyIncrementalJson cannot change Model properties"),this.$F(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()}YS(t,i,e){return!!(e===void 0||i==="__gohashid"||i[0]==="_"||U.ht(e))}$i(t){return isNaN(t)?"NaN":t===1/0?"9e9999":t===-1/0?"-9e9999":t}JF(t){const i=t;if(i instanceof Point)t={class:"go.Point",x:this.$i(i.x),y:this.$i(i.y)};else if(i instanceof Size)t={class:"go.Size",width:this.$i(i.width),height:this.$i(i.height)};else if(i instanceof Rect)t={class:"go.Rect",x:this.$i(i.x),y:this.$i(i.y),width:this.$i(i.width),height:this.$i(i.height)};else if(i instanceof Margin)t={class:"go.Margin",top:this.$i(i.top),right:this.$i(i.right),bottom:this.$i(i.bottom),left:this.$i(i.left)};else if(i instanceof Spot)i.isSpot()?t={class:"go.Spot",x:this.$i(i.x),y:this.$i(i.y),offsetX:this.$i(i.offsetX),offsetY:this.$i(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.$i(i.startRadius)),isNaN(i.endRadius)||(t.endRadius=this.$i(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.$i(i.startX)),i.startY!==0&&(t.startY=this.$i(i.startY)),i.endX!==0&&(t.endX=this.$i(i.endX)),i.endY!==0&&(t.endY=this.$i(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.sA(null,"",i))return"{}";let e="{",s=!0;for(const n in t){const o=this.Tt(t,n);this.YS(t,n,o)||(s?s=!1:e+=",",e+=this.quote(n)+":"+this.writeJsonPropertyValue(n,o))}return e+="}",e}writeJsonPropertyValue(t,i){if(t==="points"&&i instanceof List){const e=i;let s="[";const n=e.iterator;for(;n.next();){const o=n.value;s.length>1&&(s+=","),s+=this.iI(o.x),s+=",",s+=this.iI(o.y)}return s+="]",s}else return this.writeJsonValue(i)}iI(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.dw}set pointsDigits(t){t<0?t=0:t>100&&(t=100),this.dw=t}Zi(t){return typeof t=="number"?t:t==="NaN"?NaN:t==="9e9999"?1/0:t==="-9e9999"?-1/0:parseFloat(t)}g4(t){if(!U.it(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.Zi(t.x),this.Zi(t.y));else if(i==="Size")e=new Size(this.Zi(t.width),this.Zi(t.height));else if(i==="Rect")e=new Rect(this.Zi(t.x),this.Zi(t.y),this.Zi(t.width),this.Zi(t.height));else if(i==="Margin")e=new Margin(this.Zi(t.top),this.Zi(t.right),this.Zi(t.bottom),this.Zi(t.left));else if(i==="Spot")typeof t.enum=="string"?e=Spot.parse(t.enum):e=new Spot(this.Zi(t.x),this.Zi(t.y),this.Zi(t.offsetX),this.Zi(t.offsetY));else if(i==="Brush"){const s=new Brush;s.type=U.ea(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.Zi(t.startRadius)),typeof t.endRadius=="number"&&(s.endRadius=this.Zi(t.endRadius));const n=t.colorStops;if(U.it(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.ea(GeometryType,t.type)??1,typeof t.startX=="number"&&(s.startX=this.Zi(t.startX)),typeof t.startY=="number"&&(s.startY=this.Zi(t.startY)),typeof t.endX=="number"&&(s.endX=this.Zi(t.endX)),typeof t.endY=="number"&&(s.endY=this.Zi(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.hA(s);U.ht(n)&&(e=U.ea(n,t.name))}return e}get name(){return this.At}set name(t){const i=this.At;i!==t&&(U.i(t,"string",Model,"name"),this.At=t,this.t("name",i,t))}get dataFormat(){return this.Ag}set dataFormat(t){const i=this.Ag;i!==t&&(U.i(t,"string",Model,"dataFormat"),this.Ag=t,this.t("dataFormat",i,t))}get isReadOnly(){return this.qo}set isReadOnly(t){const i=this.qo;i!==t&&(U.i(t,"boolean",Model,"isReadOnly"),this.qo=t,this.t("isReadOnly",i,t))}get modelData(){return this.iA}set modelData(t){const i=this.modelData;i!==t&&(U.Ro(t,Model,"modelData"),this.containsNodeData(t)&&U.n("Model.modelData Object must not be used by the rest of the model: "+t),this.iA=t,this.t("modelData",i,t),this.updateTargetBindings(t))}addChangedListener(t){return U.C(t,Model,"addChangedListener:listener"),this.gw.push(t),this}removeChangedListener(t){U.C(t,Model,"removeChangedListener:listener");const i=this.gw.indexOf(t);i>=0&&this.gw.splice(i,1)}B2(t){this.skipsUndoManager||this.undoManager.handleChanged(t),this.eI(t)}eI(t){this.gw.forEach(i=>i(t))}gR(t){this.eI(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.B2(h)}get undoManager(){return this.XS}set undoManager(t){const i=this.XS;i!==t&&(U.s(t,UndoManager,Model,"undoManager"),i&&i.removeModel(this),this.XS=t,t.addModel(this))}get skipsUndoManager(){return this.Go}set skipsUndoManager(t){U.i(t,"boolean",Model,"skipsUndoManager"),this.Go=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(e!==null&&s===this.nodeKeyProperty&&this.containsNodeData(e)){const o=t.getValue(!i);o!==void 0&&this.Pi.delete(o),n!==void 0&&this.Pi.set(n,e)}this.rt(e,s,n)}else if(t.change===3){const e=t.newParam;if(t.modelChange==="nodeDataArray"){const s=t.newValue;if(U.it(s)&&typeof e=="number"){const n=this.getKeyForNodeData(s);i?(this.Te[e]===s&&this.Lo(this.Te,e),n!==void 0&&this.Pi.delete(n)):(this.Te[e]!==s&&this.ur(this.Te,e,s),n!==void 0&&this.Pi.set(n,s))}}else if(t.modelChange===""){let s=t.object;if(s&&!Array.isArray(s)&&t.propertyName&&(s=this.Tt(s,t.propertyName)),Array.isArray(s)&&typeof e=="number"){const n=t.newValue;i?this.Lo(s,e):this.ur(s,e,n)}}else U.n("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.it(s)&&typeof e=="number"){const n=this.getKeyForNodeData(s);i?(this.Te[e]!==s&&this.ur(this.Te,e,s),n!==void 0&&this.Pi.set(n,s)):(this.Te[e]===s&&this.Lo(this.Te,e),n!==void 0&&this.Pi.delete(n))}}else if(t.modelChange===""){let s=t.object;if(s&&!Array.isArray(s)&&t.propertyName&&(s=this.Tt(s,t.propertyName)),Array.isArray(s)&&typeof e=="number"){const n=t.oldValue;i?this.ur(s,e,n):this.Lo(s,e)}}else U.n("unknown ChangeType.Remove modelChange: "+t.toString())}else t.change===1||U.n("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.vh}set nodeKeyProperty(t){const i=this.vh;i!==t&&(this.Kn(t,Model,"nodeKeyProperty"),t===""&&U.n("Model.nodeKeyProperty may not be the empty string"),this.Pi.count>0&&U.n("Cannot set Model.nodeKeyProperty when there is existing node data"),this.vh=t,this.t("nodeKeyProperty",i,t))}Kn(t,i,e){typeof t!="string"&&!U.ht(t)&&U.Ti(t,"string or function",i,e)}getKeyForNodeData(t){if(t===null)return;const i=this.vh;if(i==="")return;const e=this.Tt(t,i);if(e!==void 0){if(this.isKeyType(e))return e;U.n("Key value for node data "+t+" is not a number or a string: "+e)}}setKeyForNodeData(t,i){if((i==null||!this.isKeyType(i))&&U.Ti(i,"number or string",Model,"setKeyForNodeData:key"),t===null)return;const e=this.vh;if(e==="")return;if(!this.containsNodeData(t)){this.rt(t,e,i);return}const s=this.Tt(t,e);if(s!==i){if(this.findNodeDataForKey(i)!==null)return;this.rt(t,e,i),s!==void 0&&this.Pi.delete(s),this.Pi.set(i,t),this.Vt("nodeKey",2,e,t,s,i),typeof e=="string"&&this.updateTargetBindings(t,e),this.yw(s,i)}}get makeUniqueKeyFunction(){return this._c}set makeUniqueKeyFunction(t){const i=this._c;i!==t&&(t!==null&&U.C(t,Model,"makeUniqueKeyFunction"),this._c=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.Pi.get(i)===t}findNodeDataForKey(t){return t===null&&U.n("Model.findNodeDataForKey:key must not be null"),t===void 0||!this.isKeyType(t)?null:this.Pi.get(t)}get nodeDataArray(){return this.Te}set nodeDataArray(t){const i=this.Te;if(i!==t){this.ww(t,Model,"nodeDataArray"),this.Pi.clear(),this.aA();const e=t.length;for(let o=0;o=0||s.indexOf("Tool")>=0||s.indexOf("CommandHandler")>=0||s.indexOf("Layout")>=0?(Debug&&i[0]!=="_"&&(t&&i&&U.ot('Warning: found GraphObject or Diagram or HTML DOM reference when copying model data on property "'+i+'" of data object: '+t.toString()),U.ot(` Model data should not have any references to a Diagram or any part of a diagram, such as: `+e.toString())),!0):!1}static sI=!1;setDataProperty(t,i,e){if(Debug&&(U.Ro(t,Model,"setDataProperty:data"),U.i(i,"string",Model,"setDataProperty:propname"),i===""&&U.n("Model.setDataProperty: property name must not be an empty string when setting "+t+" to "+e)),this.containsNodeData(t)){if(i===this.nodeKeyProperty){this.setKeyForNodeData(t,e);return}else if(i===this.nodeCategoryProperty){this.setCategoryForNodeData(t,e);return}}else!Model.sI&&t instanceof GraphObject&&(Model.sI=!0,U.ot('Model.setDataProperty is modifying a GraphObject, "'+t.toString()+'"'),U.ot(" Is that really your intent?"));const s=this.Tt(t,i);s!==e&&(this.rt(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){Debug&&(this.ww(t,Model,"insertArrayItem:arr"),U.r(i,Model,"insertArrayItem:idx"),t===this.Te&&U.n("Model.insertArrayItem or Model.addArrayItem should not be called on the Model.nodeDataArray")),i<0&&(i=t.length),t=this.ur(t,i,e),this.Vt("",3,"",t,null,e,null,i)}removeArrayItem(t,i){i===void 0&&(i=-1),Debug&&(this.ww(t,Model,"removeArrayItem:arr"),U.r(i,Model,"removeArrayItem:idx")),t===this.Te&&U.n("Model.removeArrayItem should not be called on the Model.nodeDataArray"),i===-1&&(i=t.length-1);const e=t[i];t=this.Lo(t,i),this.Vt("",4,"",t,e,null,i,null)}get nodeCategoryProperty(){return this.gf}set nodeCategoryProperty(t){const i=this.gf;i!==t&&(this.Kn(t,Model,"nodeCategoryProperty"),this.gf=t,this.t("nodeCategoryProperty",i,t))}getCategoryForNodeData(t){if(t===null)return"";const i=this.gf;if(i==="")return"";const e=this.Tt(t,i);if(e===void 0)return"";if(typeof e=="string")return e;U.n("getCategoryForNodeData found a non-string category for "+t+": "+e)}setCategoryForNodeData(t,i){if(U.i(i,"string",Model,"setCategoryForNodeData:cat"),t===null)return;const e=this.gf;if(e==="")return;if(!this.containsNodeData(t)){this.rt(t,e,i);return}let s=this.Tt(t,e);s===void 0&&(s=""),s!==i&&(this.rt(t,e,i),this.Vt("nodeCategory",2,e,t,s,i))}Og(t,i){this.setCategoryForNodeData(i,this.getCategoryForNodeData(t))}get type(){return"Model"}Gm(){return!1}Um(){return!1}wb(){return!1}tf(){return!1}Bx(){return!1}Oa(){return!1}static M2(){return new Model}Tt(t,i){return Model.Tt(t,i)}static Tt(t,i){if(!t||!i)return null;let e;try{U.ht(i)?e=i(t):U.ht(t.getAttribute)?(e=t.getAttribute(i),e===null&&(e=void 0)):e=t[i]}catch(s){Debug&&U.ot("property get error: "+s.toString())}return e}rt(t,i,e){Model.rt(t,i,e)}static rt(t,i,e){if(!(!t||!i)){try{U.ht(i)?i(t,e):U.ht(t.setAttribute)?t.setAttribute(i,e):t[i]=e}catch(s){Debug&&U.ot("property set error: "+s.toString())}return t}}ww(t,i,e){Array.isArray(t)||U.Ti(t,"Array",i,e)}tI(t,i,e){return t[i]=e,t}ur(t,i,e){return i>=t.length?t.push(e):t.splice(i,0,e),t}Lo(t,i){return i>=t.length?t.pop():t.splice(i,1),t}static hA(t){return Model.fA[t]?Model.fA[t]:root.go!==void 0&&root.go[t]?root.go[t]:null}static Al(t,i){Model.fA[i]=t}static fA={}}Model.fromJSON=Model.fromJson=Model.fromJson,Model.Al(Brush,"Brush"),Model.Al(Geometry,"Geometry"),Model.Al(Margin,"Margin"),Model.Al(Point,"Point"),Model.Al(Rect,"Rect"),Model.Al(Size,"Size"),Model.Al(Spot,"Spot"),Model.Al(Model,"Model");class GraphLinksModel extends Model{zs;dr;zi;jh;iu;eu;Ul;Do;Fo;mf;pf;yf;dn;su;Un;Vg;constructor(t,i,e){if(super(),this.zs=[],this.dr=new GSet,this.zi=new GMap,this.jh="",this.iu=null,this.eu=null,this.Ul=null,this.Do="from",this.Fo="to",this.mf="",this.pf="",this.yf="category",this.dn="",this.su="isGroup",this.Un="group",this.Vg=!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.jh=this.jh,t.iu=this.iu,t.eu=this.eu,t.Do=this.Do,t.Fo=this.Fo,t.mf=this.mf,t.pf=this.pf,t.yf=this.yf,t.dn=this.dn,t.su=this.su,t.Un=this.Un,t.Vg=this.Vg}clear(){this.zs=[],this.zi.clear(),this.dr.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.Ge(o,!1)}}return i}}eA(t,i,e){if(this.linkKeyProperty===""){const c=this.skipsUndoManager;this.skipsUndoManager=!0,this.linkKeyProperty="key",this.skipsUndoManager=c}let s=super.eA(t,i,e);const n=this,o=new GSet,r=new GSet,l=new GSet;t.changes.each(c=>{if(c.model===n){if(c.modelChange==="linkDataArray")c.change===3?o.add(c.newValue):c.change===4&&l.add(c.oldValue);else if(n.containsLinkData(c.object))c.object!==null&&r.add(c.object);else if(c.object!==null)if(c.object!==null&&e.has(c.object)){const u=e.get(c.object);u&&u.each(d=>{n.containsLinkData(d)&&r.add(d)})}else{if(c.object instanceof Model||n.containsNodeData(c.object))return;n.nI(c.object).each(d=>r.add(d))}}});const h=new GSet;o.each(c=>{const u=n.getKeyForLinkData(c);u!==void 0&&h.add(u),i||r.add(c)});const a=new GSet;l.each(c=>{const u=n.getKeyForLinkData(c);u!==void 0&&a.add(u),i&&r.add(c)});const f=n.cloneDeep(r.toArray());return h.count>0&&(s===null&&(s={}),i?s.removedLinkKeys=h.toArray():s.insertedLinkKeys=h.toArray()),f.length>0&&(s===null&&(s={}),s.modifiedLinkData=f),a.count>0&&(s===null&&(s={}),i?s.insertedLinkKeys=a.toArray():s.removedLinkKeys=a.toArray()),s}Rg(){const t=super.Rg();let i="";return this.linkCategoryProperty!=="category"&&typeof this.linkCategoryProperty=="string"&&(i+=`, "linkCategoryProperty": `+this.quote(this.linkCategoryProperty)),this.linkKeyProperty!==""&&typeof this.linkKeyProperty=="string"&&(i+=`, "linkKeyProperty": `+this.quote(this.linkKeyProperty)),this.linkFromKeyProperty!=="from"&&typeof this.linkFromKeyProperty=="string"&&(i+=`, "linkFromKeyProperty": `+this.quote(this.linkFromKeyProperty)),this.linkToKeyProperty!=="to"&&typeof this.linkToKeyProperty=="string"&&(i+=`, "linkToKeyProperty": `+this.quote(this.linkToKeyProperty)),this.linkFromPortIdProperty!==""&&typeof this.linkFromPortIdProperty=="string"&&(i+=`, "linkFromPortIdProperty": `+this.quote(this.linkFromPortIdProperty)),this.linkToPortIdProperty!==""&&typeof this.linkToPortIdProperty=="string"&&(i+=`, "linkToPortIdProperty": `+this.quote(this.linkToPortIdProperty)),this.linkLabelKeysProperty!==""&&typeof this.linkLabelKeysProperty=="string"&&(i+=`, "linkLabelKeysProperty": `+this.quote(this.linkLabelKeysProperty)),this.nodeIsGroupProperty!=="isGroup"&&typeof this.nodeIsGroupProperty=="string"&&(i+=`, "nodeIsGroupProperty": `+this.quote(this.nodeIsGroupProperty)),this.nodeGroupKeyProperty!=="group"&&typeof this.nodeGroupKeyProperty=="string"&&(i+=`, "nodeGroupKeyProperty": `+this.quote(this.nodeGroupKeyProperty)),t+i}mw(t){super.mw(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)}nA(){const t=super.nA(),i=`, "linkDataArray": `+this.Wh(this.linkDataArray,!0);return t+i}oA(t){super.oA(t);const i=t.linkDataArray;Array.isArray(i)&&(this.replaceJsonObjects(i),this.linkDataArray=i)}oI=`, "insertedLinkKeys": `;m4=`, "modifiedLinkData": `;rI=`, "removedLinkKeys": `;nI(t){const i=new GSet;for(let e=0;e{if(c.model===n){if(c.modelChange==="linkDataArray")c.change===3?o.add(c.newValue):c.change===4&&l.add(c.oldValue);else if(n.containsLinkData(c.object))c.object!==null&&r.add(c.object);else if(c.object!==null)if(c.object!==null&&e.has(c.object)){const u=e.get(c.object);u&&u.each(d=>{n.containsLinkData(d)&&r.add(d)})}else{if(c.object instanceof Model||n.containsNodeData(c.object))return;n.nI(c.object).each(d=>r.add(d))}}});const h=new GSet;o.each(c=>{const u=n.getKeyForLinkData(c);u!==void 0&&h.add(u),i||r.add(c)});const a=new GSet;l.each(c=>{const u=n.getKeyForLinkData(c);u!==void 0&&a.add(u),i&&r.add(c)});let f=s;return h.count>0&&(f+=(i?this.rI:this.oI)+this.Wh(h.toArray(),!0)),r.count>0&&(f+=this.m4+this.Wh(r.toArray(),!0)),a.count>0&&(f+=(i?this.oI:this.rI)+this.Wh(a.toArray(),!0)),f}pw(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.n("applyIncrementalJson cannot change Model properties"),super.pw(t);const i=t.insertedLinkKeys;if(Array.isArray(i)){const n=i.length;for(let o=0;o=0&&this.Lo(n,e)):n.indexOf(t.newValue)<0&&this.ur(n,e,t.newValue));return}}else if(t.change===4){let e=t.oldParam;if(t.modelChange==="linkDataArray"){const s=t.oldValue;if(U.it(s)&&typeof e=="number"){const n=this.getKeyForLinkData(s);i?(this.dr.add(s),this.zs[e]!==s&&this.ur(this.zs,e,s),n!==void 0&&this.zi.set(n,s)):(this.dr.delete(s),this.zs[e]===s&&this.Lo(this.linkDataArray,e),n!==void 0&&this.zi.delete(n))}return}else if(t.modelChange==="linkLabelKeys"){const s=t.object,n=s!==null?this.getLabelKeysForLinkData(s):null;Array.isArray(n)&&typeof e=="number"&&(i?n.indexOf(t.oldValue)<0&&this.ur(n,e,t.oldValue):(e=n.indexOf(t.oldValue),e>=0&&this.Lo(n,e)));return}}super.changeState(t,i)}}get archetypeNodeData(){return this.Ul}set archetypeNodeData(t){const i=this.Ul;i!==t&&(t!==null&&U.Ro(t,GraphLinksModel,"archetypeNodeData"),this.Ul=t,this.t("archetypeNodeData",i,t))}cA(t){if(t===void 0)return;const i=this.Ul;if(i!==null){let e=this.findNodeDataForKey(t);e===null&&(e=this.copyNodeData(i),this.rt(e,this.nodeKeyProperty,t),this.addNodeData(e))}return t}get linkFromKeyProperty(){return this.Do}set linkFromKeyProperty(t){const i=this.Do;i!==t&&(this.Kn(t,GraphLinksModel,"linkFromKeyProperty"),this.Do=t,this.t("linkFromKeyProperty",i,t))}getFromKeyForLinkData(t){return this.Ge(t,!0)}setFromKeyForLinkData(t,i){this.Ng(t,i,!0)}get linkToKeyProperty(){return this.Fo}set linkToKeyProperty(t){const i=this.Fo;i!==t&&(this.Kn(t,GraphLinksModel,"linkToKeyProperty"),this.Fo=t,this.t("linkToKeyProperty",i,t))}getToKeyForLinkData(t){return this.Ge(t,!1)}setToKeyForLinkData(t,i){this.Ng(t,i,!1)}Ge(t,i){if(t===null)return;const e=i?this.Do:this.Fo;if(e==="")return;const s=this.Tt(t,e);if(s!==void 0){if(this.isKeyType(s))return s;U.n((i?"FromKey":"ToKey")+" value for link data "+t+" is not a number or a string: "+s)}}Ng(t,i,e){if(i===null&&(i=void 0),i!==void 0&&!this.isKeyType(i)&&U.Ti(i,"number or string",GraphLinksModel,e?"setFromKeyForLinkData:key":"setToKeyForLinkData:key"),t===null)return;const s=e?this.Do:this.Fo;if(s==="")return;if(i=this.cA(i),!this.containsLinkData(t)){this.rt(t,s,i);return}const n=this.Tt(t,s);n!==i&&(this.cn(n,t),this.rt(t,s,i),this.findNodeDataForKey(i)===null&&this.un(i,t),this.Vt(e?"linkFromKey":"linkToKey",2,s,t,n,i),typeof s=="string"&&this.updateTargetBindings(t,s))}get linkFromPortIdProperty(){return this.mf}set linkFromPortIdProperty(t){const i=this.mf;i!==t&&(this.Kn(t,GraphLinksModel,"linkFromPortIdProperty"),Debug&&(t===this.linkFromKeyProperty||t===this.linkToKeyProperty)&&U.n("linkFromPortIdProperty name must not be the same as the GraphLinksModel.linkFromKeyProperty or linkToKeyProperty: "+t),this.mf=t,this.t("linkFromPortIdProperty",i,t))}getFromPortIdForLinkData(t){return this.BS(t,!0)}setFromPortIdForLinkData(t,i){this.Cg(t,i,!0)}get linkToPortIdProperty(){return this.pf}set linkToPortIdProperty(t){const i=this.pf;i!==t&&(this.Kn(t,GraphLinksModel,"linkToPortIdProperty"),Debug&&(t===this.linkFromKeyProperty||t===this.linkToKeyProperty)&&U.n("linkFromPortIdProperty name must not be the same as the GraphLinksModel.linkFromKeyProperty or linkToKeyProperty: "+t),this.pf=t,this.t("linkToPortIdProperty",i,t))}getToPortIdForLinkData(t){return this.BS(t,!1)}setToPortIdForLinkData(t,i){this.Cg(t,i,!1)}BS(t,i){if(t===null)return"";const e=i?this.mf:this.pf;if(e==="")return"";const s=this.Tt(t,e);return s===void 0?"":s}Cg(t,i,e){if(U.i(i,"string",GraphLinksModel,e?"setFromPortIdForLinkData:portname":"setToPortIdForLinkData:portname"),t===null)return;const s=e?this.mf:this.pf;if(s==="")return;if(!this.containsLinkData(t)){this.rt(t,s,i);return}let n=this.Tt(t,s);n===void 0&&(n=""),n!==i&&(this.rt(t,s,i),this.Vt(e?"linkFromPortId":"linkToPortId",2,s,t,n,i),typeof s=="string"&&this.updateTargetBindings(t,s))}get linkLabelKeysProperty(){return this.dn}set linkLabelKeysProperty(t){const i=this.dn;i!==t&&(this.Kn(t,GraphLinksModel,"linkLabelKeysProperty"),this.dn=t,this.t("linkLabelKeysProperty",i,t))}getLabelKeysForLinkData(t){if(t===null)return GraphLinksModel.EmptyArray;const i=this.dn;if(i==="")return GraphLinksModel.EmptyArray;const e=this.Tt(t,i);return e===void 0?GraphLinksModel.EmptyArray:e}setLabelKeysForLinkData(t,i){if(this.ww(i,GraphLinksModel,"setLabelKeysForLinkData:arr"),t===null)return;const e=this.dn;if(e==="")return;if(!this.containsLinkData(t)){this.rt(t,e,i);return}let s=this.Tt(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.un(i,t),this.Vt("linkLabelKeys",3,e,t,null,i,null,n))}else U.n(e+" property is not an Array; cannot addLabelKeyForLinkData: "+t)}removeLabelKeyForLinkData(t,i){if(i==null||(this.isKeyType(i)||U.Ti(i,"number or string",GraphLinksModel,"removeLabelKeyForLinkData:key"),t===null))return;const e=this.dn;if(e==="")return;const s=this.Tt(t,e);if(Array.isArray(s)){const n=s.indexOf(i);if(n<0)return;this.Lo(s,n),this.containsLinkData(t)&&(this.cn(i,t),this.Vt("linkLabelKeys",4,e,t,i,null,n,null))}else s!==void 0&&U.n(e+" property is not an Array; cannot removeLabelKeyforLinkData: "+t)}get linkDataArray(){return this.zs}set linkDataArray(t){const i=this.zs;if(i!==t){this.ww(t,GraphLinksModel,"linkDataArray"),this.zi.clear();const e=t.length;for(let n=0;nnew GraphLinksModel,Model.M2=()=>new GraphLinksModel;class TreeModel extends Model{Gn;zg;wf;constructor(t,i){if(super(),this.Gn="parent",this.zg=!1,this.wf="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.Gn=this.Gn,t.zg=this.zg,t.wf=this.wf}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(w[w.ConstantSpacing=0]="ConstantSpacing",w[w.ConstantDistance=1]="ConstantDistance",w[w.ConstantAngle=2]="ConstantAngle",w[w.Packed=3]="Packed",w))(CircularArrangement||{}),CircularDirection=(w=>(w[w.Clockwise=10]="Clockwise",w[w.Counterclockwise=11]="Counterclockwise",w[w.BidirectionalLeft=12]="BidirectionalLeft",w[w.BidirectionalRight=13]="BidirectionalRight",w))(CircularDirection||{}),CircularSorting=(w=>(w[w.Forwards=20]="Forwards",w[w.Reverse=21]="Reverse",w[w.Ascending=22]="Ascending",w[w.Descending=23]="Descending",w[w.Optimized=24]="Optimized",w))(CircularSorting||{}),CircularNodeDiameterFormula=(w=>(w[w.Pythagorean=30]="Pythagorean",w[w.Circular=31]="Circular",w))(CircularNodeDiameterFormula||{});class CircularLayout extends Layout{ye;nu;HS;Xg;vS;Jh;gA;mA;pA;Xs;bw;Sw;xf;kw;hI;Yg;Kg;Ug;ou;Ji;N;Ce;Ae;Yn;Gg;constructor(t){super(),this.ye=0,this.nu=0,this.HS=0,this.Xg=360,this.vS=0,this.Jh=0,this.gA=new Point,this.mA=30,this.pA=0,this.Xs=0,this.bw=0,this.Sw=new VertexArrangement,this.xf=0,this.kw=0,this.hI=600,this.Yg=NaN,this.Kg=1,this.Ug=0,this.ou=360,this.Ji=0,this.N=10,this.Ce=24,this.Ae=LayoutVertex.standardComparer,this.Yn=6,this.Gg=30,t&&Object.assign(this,t)}cloneProtected(t){super.cloneProtected(t),t.Yg=this.Yg,t.Kg=this.Kg,t.Ug=this.Ug,t.ou=this.ou,t.Ji=this.Ji,t.N=this.N,t.Ce=this.Ce,t.Ae=this.Ae,t.Yn=this.Yn,t.Gg=this.Gg}gi(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.gi(t)}createNetwork(){return new CircularNetwork(this)}w4(t,i,e){t=this.x4(t);let s=this.vS,n=this.mA,o=this.ye,r=this.nu,l=this.HS,h=this.Xg,a=this.Jh,f=this.pA,c=this.Xs,u=this.bw;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),a=this.spacing,isFinite(a)||(a=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;f=0;let m=0;for(let g=0;g1?(o=y,c=o*r):(c=y,o=c)}else o=this.WS(u*(h>=360?d:d-1),r,l*Math.PI/180,h*Math.PI/180)}else o=this.WS(f+(h>=360?d:d-1)*(s!==3?a:a*1.6),r,l*Math.PI/180,h*Math.PI/180);c=o*r}else{c=o*r;const g=this.yA(o,c,l*Math.PI/180,h*Math.PI/180);if(isNaN(a))s===0&&(a=(g-f)/(h>=360?d:d-1));else if(s===0){const p=(g-f)/(h>=360?d:d-1);p=360?d:d-1),r,l*Math.PI/180,h*Math.PI/180),c=o*r):a=p}else{let p=-1/0;for(let b=0;b=360?d:d-1),r,l*Math.PI/180,h*Math.PI/180);x>o?(o=x,c=o*r,u=y):u=g/(h>=360?d:d-1)}}return this.vS=s,this.mA=n,this.ye=o,this.nu=r,this.HS=l,this.Xg=h,this.Jh=a,this.pA=f,this.Xs=c,this.bw=u,t}doLayout(t){Debug&&t===null&&U.n("Layout.doLayout(collection) argument must not be null but a Diagram, a Group, or an Iterable of Parts"),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.w4(e,s,n);const o=this.vS,r=this.ye,l=this.HS,h=this.Xg,a=this.Jh,f=this.Xs,c=this.bw;if((this.direction===12||this.direction===13)&&o===3)this.aI(e,h,l-h/2,10);else if(this.direction===12||this.direction===13){let u=0;switch(o){case 1:u=this.jS(r,f,l,c)*180/Math.PI;break;case 0:{let d=0,m=0;const g=s.first();g!==null&&(d=g.$h(Math.PI/2));const p=n.first();p!==null&&(m=p.$h(Math.PI/2)),u=this.jS(r,f,l,a+(d+m)/2)*180/Math.PI;break}case 2:u=h/e.length;break}if(this.direction===12){switch(o){case 1:this.Pw(s,h/2,l,11);break;case 0:this.Mw(s,h/2,l,11);break;case 2:this.Nw(s,h/2,l,11);break}switch(o){case 1:this.Pw(n,h/2,l+u,10);break;case 0:this.Mw(n,h/2,l+u,10);break;case 2:this.Nw(n,h/2,l+u,10);break}}else{switch(o){case 1:this.Pw(n,h/2,l,11);break;case 0:this.Mw(n,h/2,l,11);break;case 2:this.Nw(n,h/2,l,11);break}switch(o){case 1:this.Pw(s,h/2,l+u,10);break;case 0:this.Mw(s,h/2,l+u,10);break;case 2:this.Nw(s,h/2,l+u,10);break}}}else switch(o){case 1:this.Pw(e,h,l,this.direction);break;case 0:this.Mw(e,h,l,this.direction);break;case 2:this.Nw(e,h,l,this.direction);break;case 3:this.aI(e,h,l,this.direction);break}this.updateParts(),this.network=null,this.isValidLayout=!0}Nw(t,i,e,s){const n=this.Xg,o=this.ye,r=this.Xs,l=e*Math.PI/180,h=i*Math.PI/180,a=t.length;for(let f=0;f=360?a:a-1):-(f*h)/a),u=t.elt(f),d=o*Math.tan(c)/r,m=Math.sqrt((o*o+r*r*d*d)/(1+d*d));u.centerX=m*Math.cos(c),u.centerY=m*Math.sin(c),u.actualAngle=c*180/Math.PI}}Mw(t,i,e,s){const n=this.ye,o=this.Xs,r=this.Jh;let l=e*Math.PI/180;const h=t.length;for(let a=0;a180&&(n-=360),n*=Math.PI/180,this.kw=n,this.fI(t,i,e,s)}else this.cI(t,i,e,s);this.Sw.commit(t)}cI(t,i,e,s){const n=this.ye,o=this.Xs,r=this.Jh,l=this.nu;let h=n*Math.cos(e*Math.PI/180),a=o*Math.sin(e*Math.PI/180);const f=t.toArray();if(f.length===3){f[0].centerX=n,f[0].centerY=0,f[1].centerX=f[0].centerX-f[0].width/2-f[1].width/2-r,f[1].y=f[0].y,f[2].centerX=(f[0].centerX+f[1].centerX)/2,f[2].y=f[0].y-f[2].height-r;return}else if(f.length===4){f[0].centerX=n,f[0].centerY=0,f[2].centerX=-f[0].centerX,f[2].centerY=f[0].centerY,f[1].centerX=0,f[1].y=Math.min(f[0].y,f[2].y)-f[1].height-r,f[3].centerX=0,f[3].y=Math.max(f[0].y+f[0].height+r,f[2].y+f[2].height+r);return}const c=Point.a();for(let S=0;S=f.length-1));S++)this.uI(h,a,f,S,s,c)||this.dI(h,a,f,S,s,c),h=c.x,a=c.y;if(Point.o(c),this.xf++,this.xf>23)return;const u=f[0].centerX,d=f[0].centerY,m=f[f.length-1].centerX,g=f[f.length-1].centerY;let p=Math.abs(u-m)-((f[0].width+f[f.length-1].width)/2+r);const y=Math.abs(d-g)-((f[0].height+f[f.length-1].height)/2+r);let x=0;if(Math.abs(y)<1){const S=Math.abs(u-m),k=(f[0].width+f[f.length-1].width)/2;S0?x=y:Math.abs(p)<1?x=0:x=p;let b=!1;Math.abs(m)>Math.abs(g)?b=m>0!=d>g:b=g>0!=u1&&(this.xf<8?this.ye-=x/(2*Math.PI):f.length<5&&x>10?this.ye/=2:this.ye-=x>0?1.7:-2.3,this.Xs=this.ye*l,this.cI(t,i,e,s))}fI(t,i,e,s){const n=this.ye,o=this.Xs,r=this.nu;let l=n*Math.cos(e*Math.PI/180),h=o*Math.sin(e*Math.PI/180);const a=Point.a(),f=t.toArray();for(let m=0;m=f.length-1));m++)this.uI(l,h,f,m,s,a)||this.dI(l,h,f,m,s,a),l=a.x,h=a.y;if(Point.o(a),this.xf++,this.xf>23)return;const c=Math.atan2(h,l);let u=s===10?this.kw-c:c-this.kw;u=Math.abs(u)1&&(this.xf<8?this.ye-=d/(2*Math.PI):this.ye-=d>0?1.7:-2.3,this.Xs=this.ye*r,this.fI(t,i,e,s))}uI(t,i,e,s,n,o){const r=this.Jh,l=this.ye,h=this.Xs;let a=0,f=0;const c=(e[s].width+e[s+1].width)/2+r;let u=!1;if(i>=0!=(n===10)){if(a=t+c,a>l){if(a=t-c,a<-l)return o.x=a,o.y=f,!1;u=!0}}else if(a=t-c,a<-l){if(a=t+c,a>l)return o.x=a,o.y=f,!1;u=!0}return f=Math.sqrt(1-Math.min(1,a*a/(l*l)))*h,i<0!==u&&(f=-f),Math.abs(i-f)>(e[s].height+e[s+1].height)/2?(o.x=a,o.y=f,!1):(o.x=a,o.y=f,!0)}dI(t,i,e,s,n,o){const r=this.Jh,l=this.ye,h=this.Xs;let a=0,f=0;const c=(e[s].height+e[s+1].height)/2+r;let u=!1;if(t>=0!=(n===10)){if(f=i-c,f<-h){if(f=i+c,f>h)return o.x=a,o.y=f,!1;u=!0}}else if(f=i+c,f>h){if(f=i-c,f<-h)return o.x=a,o.y=f,!1;u=!0}return a=Math.sqrt(1-Math.min(1,f*f/(h*h)))*l,t<0!==u&&(a=-a),Math.abs(t-a)>(e[s].width+e[s+1].width)/2?(o.x=a,o.y=f,!1):(o.x=a,o.y=f,!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;if(t?e=new Point(0,0):(e.x=this.arrangementOrigin.x+this.ye,e.y=this.arrangementOrigin.y+this.Xs),this.network!==null){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&&i){this.group.ensureBounds();const s=this.group.position.copy(),n=this.group.location.copy(),o=i.subtract(n.subtract(s));this.group.move(o),this.gA=o.subtract(s)}}commitLinks(){if(this.network!==null){const t=this.network.edges.iterator;for(;t.next();)t.value.commit()}}yA(t,i,e,s){const n=this.hI;if(Math.abs(this.nu-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 a=0;a<=n;a++){e!==void 0&&s!==void 0?h=e+a*s/n:h=a*Math.PI/(2*n);const f=Math.sin(h);r+=Math.sqrt(1-o*o*f*f)*l}return e!==void 0&&s!==void 0?(t>i?t:i)*r:4*(t>i?t:i)*r}WS(t,i,e,s){let n=0;return e!==void 0&&s!==void 0?n=this.yA(1,i,e,s):n=this.yA(1,i),t/n}jS(t,i,e,s){if(Math.abs(this.nu-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,a=Math.sin(h);if(o+=(t>i?t:i)*Math.sqrt(1-n*n*a*a)*r,o>=s)return l*r}}x4(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.k4(this.P4(t));default:U.n("Invalid sorting type.")}return t}P4(t){const i=[];for(let s=0;sn&&(n=u,o=f)}else for(let f=0;fn&&(n=c,o=f)}e.add(t.elt(o)),i[o]=-1;const r=t.elt(o);let l=0;const h=r.sourceEdges;for(;h.next();){const c=h.value.fromVertex;l=t.indexOf(c),!(l<0)&&i[l]>=0&&i[l]++}const a=r.destinationEdges;for(;a.next();){const c=a.value.toVertex;l=t.indexOf(c),!(l<0)&&i[l]>=0&&i[l]++}}return e}k4(t){const i=[];for(let c=0;c=0){const C=Math.abs(x-(A>=x?A+1:A));S+=C=x&&P++,A>=x&&A++,P>A){const C=A;A=P,P=C}A-P<(s.length+2)/2==(P=0&&(n.push(c),o.push(x))}h++}let a=!1;const f=s.length;for(;;){a=!0;for(let c=0;c=0){let g=0;for(let p=0;pm?x-m:m-x,S=f-b;g+=xS?1:-1}s.splice(g<0?m:m+1,0,u),r.splice(c,1),c--}else a=!1}if(a)break;s.push(r[0]),r.splice(0,1)}for(let c=0;c0||isNaN(t))&&(this.Yg=t,this.b()))}get aspectRatio(){return this.Kg}set aspectRatio(t){this.Kg!==t&&(U.i(t,"number",CircularLayout,"aspectRatio"),t>0&&(this.Kg=t,this.b()))}get startAngle(){return this.Ug}set startAngle(t){this.Ug!==t&&(U.i(t,"number",CircularLayout,"startAngle"),this.Ug=t,this.b())}get sweepAngle(){return this.ou}set sweepAngle(t){this.ou!==t&&(U.i(t,"number",CircularLayout,"sweepAngle"),t>0&&t<=360?this.ou=t:this.ou=360,this.b())}get arrangement(){return this.Ji}set arrangement(t){this.Ji!==t&&(U.W(t,CircularArrangement,"CircularArrangement"),(t===3||t===0||t===1||t===2)&&(this.Ji=t,this.b()))}get direction(){return this.N}set direction(t){this.N!==t&&(U.W(t,CircularDirection,"CircularDirection"),(t===10||t===11||t===12||t===13)&&(this.N=t,this.b()))}get sorting(){return this.Ce}set sorting(t){this.Ce!==t&&(U.W(t,CircularSorting,"CircularSorting"),this.Ce=t,this.b())}get comparer(){return this.Ae}set comparer(t){this.Ae!==t&&(U.C(t,CircularLayout,"comparer"),this.Ae=t,this.b())}get spacing(){return this.Yn}set spacing(t){this.Yn!==t&&(U.i(t,"number",CircularLayout,"spacing"),this.Yn=t,this.b())}get nodeDiameterFormula(){return this.Gg}set nodeDiameterFormula(t){this.Gg!==t&&(U.W(t,CircularNodeDiameterFormula,"CircularNodeDiameterFormula"),(t===30||t===31)&&(this.Gg=t,this.b()))}get actualXRadius(){return this.ye}get actualYRadius(){return this.Xs}get actualSpacing(){return this.Jh}get actualCenter(){return this.gA}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{ru;bf;lu;constructor(){this.ru=-1/0,this.bf=null,this.lu=null}b4(t,i){if(t>0&&this.ru<0||Math.abs(t)0)){this.ru=t,this.bf=[],this.lu=[];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.wA(),this.Zh=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.N4(l,o),l=r.iterator;l.next();){const h=l.value,a=h.vertexes.iterator;for(;a.next();){const c=a.value;o.addVertex(c)}const f=h.edges.iterator;for(;f.next();){const c=f.value;o.addEdge(c)}}}else this.gI(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.du;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 a=i.value.hierarchicalVertexes.iterator;for(;a.next();)this.isFixed(a.value)||(a.value.x=l,a.value.y=h)}const r=this.computePairwiseDistances(e);this.C4(e,r,this.maxPrelayoutIterations,t.vertexes.count),this.gI(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 a=h.value;n.has(a.idInCluster)||(n.set(a.idInCluster,n.get(l.idInCluster)+1),o.push(a))}}for(let l=0;l=0;m--)if(t[m].y>f.y&&t[m].x-f.xf.x&&t[m].y-f.ya+c){const u=s+o-h,d=n-a-c;return G.gx(u*u+d*d)}else if(n+rh+f)if(n>a+c){const u=s-h-f,d=n-a-c;return G.gx(u*u+d*d)}else if(n+ra+c?n-(a+c):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.hu;let a=0,f=0,c=0;for(let m=0;mh||C-x>h){if(l)break;continue}if(b-M>h||M-b>h){if(!l)break;continue}const N=this.pI(g,k),T=2*g.charge,L=2*k.charge;if(N>1)a=T*L/(N*N),f=a*(x-C)/N,c=a*(b-M)/N;else{let D=this.randomNumberGenerator;D===null&&(this.randomNumberGenerator=D=new RandomNumberGenerator(0));const F=D.random(),R=D.random();if(x>C)f=Math.abs(k.bounds.right-g.bounds.x),f=T*L*(1+f)*F;else if(xM)c=Math.abs(k.bounds.bottom-g.bounds.y),c=T*L*(1+c)*R;else if(x1&&(a=.1*m.stiffness*(M-m.length),f=a*.5*(g.width+p.height)*(b-A)/M,c=a*.5*(g.width+p.height)*(S-C)/M),g.forceX-=f,g.forceY-=c,p.forceX+=f,p.forceY+=c}let d=0;for(let m=0;mthis.epsilonDistance*this.epsilonDistance}C4(t,i,e,s){Debug&&U.r(e,ForceDirectedLayout,"performIterations:num");const n=this.Zh+e,o=Math.sqrt(s);this.Cw=this.Sf*t.vertexes.count;const r=t.vertexes.toArray();let l=0,h=0,a=0;for(;this.Zh0){r[f].forceX=this.Cw*r[f].forceX/c,r[f].forceY=this.Cw*r[f].forceY/c,this.isFixed(r[f])||(r[f].x+=r[f].forceX,r[f].y+=r[f].forceY);const u=r[f].hierarchicalVertexes.iterator;for(;u.next();){const d=u.value;this.isFixed(d)||(d.centerX+=r[f].forceX,d.centerY+=r[f].forceY)}}l+=c*c}if(l>=h){if(a++,a>=5)break}else a=0;this.Cw*=.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.Aw(),this.commitNodes(),this.isRouting&&this.commitLinks()}Aw(){if(this.network===null||!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(){if(!this.network)return;let t=0,i=0;if(this.arrangesToOrigin){const n=Rect.a();this.xx(this.network,n);const o=this.arrangementOrigin;t=o.x-n.x,i=o.y-n.y,Rect.o(n)}const e=Rect.a(),s=this.network.vertexes.iterator;for(;s.next();){const n=s.value;(t!==0||i!==0)&&(e.c(n.bounds),e.x+=t,e.y+=i,n.bounds=e),n.commit()}Rect.o(e)}commitLinks(){if(!this.network)return;const t=this.network.edges.iterator;for(;t.next();)t.value.commit()}springStiffness(t){const i=t.stiffness;return isNaN(i)?this.au:i}springLength(t){const i=t.length;return isNaN(i)?this.fu:i}electricalCharge(t){const i=t.charge;return isNaN(i)?this.cu:i}electricalFieldX(t,i){return 0}electricalFieldY(t,i){return 0}gravitationalMass(t){const i=t.mass;return isNaN(i)?this.uu:i}gravitationalFieldX(t,i){return 0}gravitationalFieldY(t,i){return 0}isFixed(t){return t.isFixed}get currentIteration(){return this.Zh}get arrangementSpacing(){return this.Ys}set arrangementSpacing(t){U.s(t,Size,ForceDirectedLayout,"arrangementSpacing"),this.Ys.equals(t)||(this.Ys.c(t),this.b())}get arrangesToOrigin(){return this.qg}set arrangesToOrigin(t){this.qg!==t&&(U.i(t,"boolean",ForceDirectedLayout,"arrangesToOrigin"),this.qg=t,this.b())}get setsPortSpots(){return this.qn}set setsPortSpots(t){this.qn!==t&&(U.i(t,"boolean",ForceDirectedLayout,"setsPortSpots"),this.qn=t,this.b())}get comments(){return this.qe}set comments(t){this.qe!==t&&(U.i(t,"boolean",ForceDirectedLayout,"comments"),this.qe=t,this.b())}get maxPrelayoutIterations(){return this.Hg}set maxPrelayoutIterations(t){this.Hg!==t&&(U.i(t,"number",ForceDirectedLayout,"maxPrelayoutIterations"),t>=0&&(this.Hg=t,this.b()))}get maxIterations(){return this.vg}set maxIterations(t){this.vg!==t&&(U.i(t,"number",ForceDirectedLayout,"maxIterations"),t>=0&&(this.vg=t,this.b()))}get epsilonDistance(){return this.Wg}set epsilonDistance(t){this.Wg!==t&&(U.i(t,"number",ForceDirectedLayout,"epsilonDistance"),t>0&&(this.Wg=t,this.b()))}get infinityDistance(){return this.hu}set infinityDistance(t){this.hu!==t&&(U.i(t,"number",ForceDirectedLayout,"infinityDistance"),t>1&&(this.hu=t,this.b()))}get moveLimit(){return this.jg}set moveLimit(t){this.jg!==t&&(U.i(t,"number",ForceDirectedLayout,"moveLimit"),this.jg=t,this.b())}get randomNumberGenerator(){return this.Jg}set randomNumberGenerator(t){this.Jg!==t&&(t!==null&&!U.ht(t.random)&&U.n('ForceDirectedLayout.randomNumberGenerator must have a "random()" function on it: '+t),this.Jg=t)}get defaultSpringStiffness(){return this.au}set defaultSpringStiffness(t){this.au!==t&&(U.i(t,"number",ForceDirectedLayout,"defaultSpringStiffness"),this.au=t,this.b())}get defaultSpringLength(){return this.fu}set defaultSpringLength(t){this.fu!==t&&(U.i(t,"number",ForceDirectedLayout,"defaultSpringLength"),this.fu=t,this.b())}get defaultElectricalCharge(){return this.cu}set defaultElectricalCharge(t){this.cu!==t&&(U.i(t,"number",ForceDirectedLayout,"defaultElectricalCharge"),this.cu=t,this.b())}get defaultGravitationalMass(){return this.uu}set defaultGravitationalMass(t){this.uu!==t&&(U.i(t,"number",ForceDirectedLayout,"defaultGravitationalMass"),this.uu=t,this.b())}get defaultCommentSpringLength(){return this.$g}set defaultCommentSpringLength(t){this.$g!==t&&(U.i(t,"number",ForceDirectedLayout,"defaultCommentSpringLength"),this.$g=t,this.b())}get defaultCommentElectricalCharge(){return this.Zg}set defaultCommentElectricalCharge(t){this.Zg!==t&&(U.i(t,"number",ForceDirectedLayout,"defaultCommentElectricalCharge"),this.Zg=t,this.b())}get prelayoutQuality(){return this.du}set prelayoutQuality(t){this.du!==t&&(U.i(t,"number",ForceDirectedLayout,"prelayoutQuality"),this.du=t,this.b())}get prelayoutSpread(){return this.Sf}set prelayoutSpread(t){this.Sf!==t&&(U.i(t,"number",ForceDirectedLayout,"prelayoutSpread"),this.Sf=t,this.b())}}class ForceDirectedNetwork extends LayoutNetwork{constructor(t){super(t)}createVertex(){return new ForceDirectedVertex(this)}createEdge(){return new ForceDirectedEdge(this)}}class ForceDirectedVertex extends LayoutVertex{$S;ZS;QS;_S;tk;hierarchicalVertexes;idInCluster;constructor(t){super(t),this.$S=!1,this.ZS=NaN,this.QS=NaN,this._S=0,this.tk=0,this.hierarchicalVertexes=new List,this.idInCluster=-1}get isFixed(){return this.$S}set isFixed(t){this.$S!==t&&(U.i(t,"boolean",ForceDirectedVertex,"isFixed"),this.$S=t)}get charge(){return this.ZS}set charge(t){this.ZS!==t&&(U.i(t,"number",ForceDirectedVertex,"charge"),this.ZS=t)}get mass(){return this.QS}set mass(t){this.QS!==t&&(U.i(t,"number",ForceDirectedVertex,"mass"),this.QS=t)}get forceX(){return this._S}set forceX(t){this._S!==t&&(U.i(t,"number",ForceDirectedVertex,"forceX"),this._S=t)}get forceY(){return this.tk}set forceY(t){this.tk!==t&&(U.i(t,"number",ForceDirectedVertex,"forceY"),this.tk=t)}}class ForceDirectedEdge extends LayoutEdge{ik;ek;constructor(t){super(t),this.ik=NaN,this.ek=NaN}get stiffness(){return this.ik}set stiffness(t){this.ik!==t&&(U.i(t,"number",ForceDirectedEdge,"stiffness"),this.ik=t)}get length(){return this.ek}set length(t){this.ek!==t&&(U.i(t,"number",ForceDirectedEdge,"length"),this.ek=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=(w=>(w[w.DepthFirst=0]="DepthFirst",w[w.Greedy=1]="Greedy",w[w.FromLayers=2]="FromLayers",w))(LayeredDigraphCycleRemove||{}),LayeredDigraphLayering=(w=>(w[w.OptimalLinkLength=10]="OptimalLinkLength",w[w.LongestPathSink=11]="LongestPathSink",w[w.LongestPathSource=12]="LongestPathSource",w))(LayeredDigraphLayering||{}),LayeredDigraphInit=(w=>(w[w.DepthFirstOut=20]="DepthFirstOut",w[w.DepthFirstIn=21]="DepthFirstIn",w[w.Naive=22]="Naive",w))(LayeredDigraphInit||{}),LayeredDigraphAggressive=(w=>(w[w.None=30]="None",w[w.Less=31]="Less",w[w.More=32]="More",w))(LayeredDigraphAggressive||{}),LayeredDigraphPack=(w=>(w[w.None=0]="None",w[w.Expand=1]="Expand",w[w.Straighten=2]="Straighten",w[w.Median=4]="Median",w[w.MaybeExpand=8]="MaybeExpand",w[w.All=15]="All",w))(LayeredDigraphPack||{}),LayeredDigraphAlign=(w=>(w[w.None=0]="None",w[w.UpperLeft=1]="UpperLeft",w[w.UpperRight=2]="UpperRight",w[w.LowerLeft=4]="LowerLeft",w[w.LowerRight=8]="LowerRight",w[w.All=15]="All",w))(LayeredDigraphAlign||{});class LayeredDigraphLayout extends Layout{Ks;ne;N;gu;mu;pu;kf;yu;gr;wu;qn;st;Tw;Ht;Qg;Us;li;Gs;xs;bs;zt;_g;tm;sk;gn;xu;pr;Hn;vn;xA;Qh;constructor(t){super(),this.Ks=25,this.ne=25,this.N=0,this.gu=0,this.mu=10,this.pu=20,this.kf=4,this.yu=31,this.gr=15,this.wu=10,this.qn=!0,this.st=-1,this.Tw=-1,this.Ht=-1,this.Qg=0,this.Us=0,this.li=new Int16Array(0),this.Gs=new Float32Array(0),this.xs=new Float32Array(0),this.bs=new Float32Array(0),this.zt=new Float32Array(0),this._g=0,this.tm=new Int16Array(0),this.sk=new Int16Array(0),this.gn=0,this.xu=null,this.pr=new Point,this.Hn=[],this.Hn.length=100,this.vn=15,this.xA=0,this.Qh=!0,t&&Object.assign(this,t)}cloneProtected(t){super.cloneProtected(t),t.Ks=this.Ks,t.ne=this.ne,t.N=this.N,t.gu=this.gu,t.mu=this.mu,t.pu=this.pu,t.kf=this.kf,t.yu=this.yu,t.gr=this.gr,t.wu=this.wu,t.qn=this.qn,t.vn=this.vn,t.Qh=this.Qh}gi(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.gi(t)}createNetwork(){return new LayeredDigraphNetwork(this)}doLayout(t){Debug&&t===null&&U.n("Layout.doLayout(collection) argument must not be null but a Diagram, a Group, or an Iterable of Parts"),this.network===null&&(this.network=this.makeNetwork(t)),this.arrangementOrigin=this.initialOrigin(this.arrangementOrigin),this.T4(),this.network.vertexes.count>0&&(this.network.deleteSelfEdges(),this.cycleRemoveOption!==2&&this.removeCycles(),this.L4(),this.cycleRemoveOption===2&&this.removeCycles(),this.D4(),this.F4(),this.I4(),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.N===90||this.N===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.nk:t.ok;if(e!==null)return e;const s=this.N;return s===90||s===270?i?t.nk=t.focus.x/this.ne+1|0:t.ok=(t.bounds.width-t.focus.x)/this.ne+1|0:i?t.nk=t.focus.y/this.ne+1|0:t.ok=(t.bounds.height-t.focus.y)/this.ne+1|0}oe(){const t=this.network.vertexes.count;this.tm.length=0){for(f=e[o].Ao,c=0;cb||d===b&&g>k)&&r++,Sd||b===d&&k>g)&&r++)}if(i<=0){for(f=e[o].fr,c=0;cb||d===b&&m>S)&&r++,kd||b===d&&S>m)&&r++)}for(n[o*s+o]=r,a=o+1;a=0){for(p=e[o].Ao,P=e[a].Ao,c=0;c=0&&(h=s[r].fr);let a,f=0,c=0;if(l!==null)for(let u=0;u=0&&(h=r.fr);let a=0,f=0;const c=r.near;c!==null&&c.layer===r.layer&&(a+=c.column-1,f++);let u;if(l!==null)for(let d=0;d=0&&(h=r.fr);let a=0;const f=[],c=r.near;c!==null&&c.layer===r.layer&&(f[a]=c.column-1,a++);let u;if(l!==null)for(let d=0;dm-g);const d=a>>1;(a&1)!==0?n[o]=f[d]:n[o]=f[d-1]+f[d]>>1}}return this.ta(t,e),n}Fw(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,a=h.toVertex;o=t.layer-a.layer,r=this.linkMinLength(h),o===r&&this.Fw(a,i,e,s,n)}}if(n){const l=t.sourceEdges;for(;l.next();){const h=l.value,a=h.fromVertex;o=a.layer-t.layer,r=this.linkMinLength(h),o===r&&this.Fw(a,i,e,s,n)}}}}bA(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.bA(l,i,e,s,n)}}if(n){const o=t.sourceEdges;for(;o.next();){const l=o.value.fromVertex;this.bA(l,i,e,s,n)}}}}removeCycles(){const t=this.network.edges.iterator;for(;t.next();){const i=t.value;i.rev=!1}switch(this.gu){default:case 1:this.O4();break;case 0:this.E4();break;case 2:this.B4();break}}B4(){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)}}V4(t){const i=t.vertexes.iterator;for(;i.next();){const e=i.value;if(e.re)return e}return null}xI(t){const i=t.vertexes.iterator;for(;i.next();){const e=i.value;if(e.re){let s=!0;const n=e.destinationEdges;for(;n.next();)if(n.value.toVertex.re){s=!1;break}if(s)return e}}return null}bI(t){const i=t.vertexes.iterator;for(;i.next();){const e=i.value;if(e.re){let s=!0;const n=e.sourceEdges;for(;n.next();)if(n.value.fromVertex.re){s=!1;break}if(s)return e}}return null}z4(t){let i=null,e=0;const s=this.network.vertexes.iterator;for(;s.next();){const n=s.value;if(n.re){let o=0;const r=n.destinationEdges;for(;r.next();)r.value.toVertex.re&&o++;let l=0;const h=n.sourceEdges;for(;h.next();)h.value.fromVertex.re&&l++;(i===null||e=9999&&U.n("LayeredDigraphLayout, too many layers: "+this.st);const i=this.direction==0||this.direction==180,e=[];for(const s=this.network.vertexes.iterator;s.next();){const n=s.value;if(n.node===null||n.centered)continue;const o=n.layer;let r=e[o];r===void 0&&(r=0);const l=i?n.width:n.height;l>r&&(e[o]=l)}for(const s=this.network.vertexes.iterator;s.next();){const n=s.value;if(n.node===null||n.centered)continue;const o=e[n.layer];i?(n.focusX=o/2,n.focusY=n.focus.y,n.width=o):(n.focusX=n.focus.x,n.focusY=o/2,n.height=o)}}assignLayers(){switch(this.mu){case 11:this.SI();break;case 12:this.X4();break;default:case 10:this.Y4();break}}SI(){const t=this.network.vertexes.iterator;for(;t.next();){const i=t.value,e=this.kI(i);this.st=Math.max(e,this.st)}}kI(t){let i=0;if(t.layer===-1){const e=t.destinationEdges;for(;e.next();){const s=e.value,n=s.toVertex,o=this.linkMinLength(s);i=Math.max(i,this.kI(n)+o)}t.layer=i}else i=t.layer;return i}X4(){let t=0;const i=this.network.vertexes.iterator;for(;i.next();){const e=i.value;t=this.MI(e),this.st=Math.max(t,this.st)}for(i.reset();i.next();){const e=i.value;e.layer=this.st-e.layer}}MI(t){let i=0;if(t.layer===-1){const e=t.sourceEdges;for(;e.next();){const s=e.value,n=s.fromVertex,o=this.linkMinLength(s);i=Math.max(i,this.MI(n)+o)}t.layer=i}else i=t.layer;return i}Y4(){this.SI();const t=this.network.vertexes.iterator;for(;t.next();){const e=t.value;e.re=!1}for(t.reset();t.next();){const e=t.value;e.sourceEdges.count===0&&this.NI(e)}let i=1/0;for(t.reset();t.next();){const e=t.value;i=Math.min(i,e.layer)}for(this.st=-1,t.reset();t.next();){const e=t.value;e.layer-=i,this.st=Math.max(this.st,e.layer)}}NI(t){if(!t.re){t.re=!0;const i=t.destinationEdges;for(;i.next();){const s=i.value.toVertex;this.NI(s)}this.K4(t),this.U4(t)}}K4(t){const i=this.network.vertexes.iterator;for(;i.next();){const r=i.value;r.component=-1}const e=0,s=1,n=t.Ao;let o=n.length;for(let r=0;rf&&this.Fw(h,e,-1,!0,!1)}for(this.Fw(t,s,-1,!0,!0);t.component!==e;){let r=0,l=1/0,h=0,a=null;const f=this.network.vertexes.iterator;for(;f.next();){const c=f.value;if(c.component===s){let u=0,d=!1;const m=c.Ao;o=m.length;for(let p=0;p0){for(i.reset();i.next();){const c=i.value;c.component===s&&(c.layer+=l)}t.component=e}else a.component=e}}U4(t){const i=this.network.vertexes.iterator;for(;i.next();){const n=i.value;n.component=-1}const e=0,s=1;for(this.Fw(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 a=h.value;if(a.component===s){let f=0,c=!1;const u=a.Ao;let d=u.length;for(let g=0;gr)&&!c&&(l=a,r=f)}}if(n<0){for(i.reset();i.next();){const a=i.value;a.component===s&&(a.layer-=o)}t.component=e}else l.component=e}}D4(){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;sS&&c>0){for(n.valid=!1,y=t.createVertex(),y.node=null,y.lk=2,y.layer=c-1,x&&bS&&c>0;)y=t.createVertex(),y.node=null,y.lk=3,y.layer=c-1,x&&bt[this.Us]&&(this.Tw=t[e]-1,this.Us=e),t[e]{o.index=this.li[s],this.li[s]++})}}v4(){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.st;e>=0;e--)for(i.reset();i.next();){const s=i.value;s.layer===e&&s.index===-1&&this.TI(s,t)}}TI(t,i){if(t.near)return;const e=t.layer;if(t.index=this.li[e],this.li[e]++,i){const o=i.get(t);Array.isArray(o)&&o.forEach(r=>{r.index=this.li[e],this.li[e]++})}const s=t.fr;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{a.index=this.li[e],this.li[e]++})}const s=t.Ao;let n=!0,o=0;for(;n;)for(n=!1,o=0;oa.portToColOffset&&(n=!0,s[o]=a,s[o+1]=h)}let r,l;for(o=0;o=0;s--)this.ak(s,-1),this.Ss(s,-1,!1,-1);n=this.countCrossings(),n=0;s--)this.ak(s,0),this.Ss(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.Ss(s,-1,!1,-1)||o;for(n=this.countCrossings(),n>=t?this.hs(i):(t=n,i=this.oe()),o=!0;o;)for(o=!1,s=r;s>=l;s--)o=this.Ss(s,1,!1,1)||o;for(n=this.countCrossings(),n>=t?this.hs(i):(t=n,i=this.oe()),o=!0;o;)for(o=!1,s=l;s<=r;s++)o=this.Ss(s,1,!1,1)||o;for(n>=t?this.hs(i):(t=n,i=this.oe()),o=!0;o;)for(o=!1,s=l;s<=r;s++)o=this.Ss(s,-1,!1,-1)||o;for(n>=t?this.hs(i):(t=n,i=this.oe()),o=!0;o;)for(o=!1,s=r;s>=l;s--)o=this.Ss(s,0,!1,0)||o;for(n>=t?this.hs(i):(t=n,i=this.oe()),o=!0;o;)for(o=!1,s=l;s<=r;s++)o=this.Ss(s,0,!1,0)||o;n>=t?this.hs(i):(t=n,i=this.oe())}break;default:case 31:for(r=this.st,l=0,h=t+1;(a=this.countCrossings())=l;s--)o=this.Ss(s,-1,!1,-1)||o;for(n=this.countCrossings(),n>=t?this.hs(i):(t=n,i=this.oe()),o=!0;o;)for(o=!1,s=r;s>=l;s--)o=this.Ss(s,1,!1,1)||o;for(n=this.countCrossings(),n>=t?this.hs(i):(t=n,i=this.oe()),o=!0;o;)for(o=!1,s=l;s<=r;s++)o=this.Ss(s,1,!1,1)||o;for(n>=t?this.hs(i):(t=n,i=this.oe()),o=!0;o;)for(o=!1,s=l;s<=r;s++)o=this.Ss(s,-1,!1,-1)||o;for(n>=t?this.hs(i):(t=n,i=this.oe()),o=!0;o;)for(o=!1,s=r;s>=l;s--)o=this.Ss(s,0,!1,0)||o;for(n>=t?this.hs(i):(t=n,i=this.oe()),o=!0;o;)for(o=!1,s=l;s<=r;s++)o=this.Ss(s,0,!1,0)||o;n>=t?this.hs(i):(t=n,i=this.oe())}break}this.hs(i)}ak(t,i){Debug&&(U.r(t,LayeredDigraphLayout,"medianBarycenterCrossingReduction:unfixedLayer"),U.r(i,LayeredDigraphLayout,"medianBarycenterCrossingReduction:direction"));let e=0,s=!1;const n=this._h(t),o=this.li[t],r=this.wI(t,i),l=this.Dw(t,i);for(e=0;e0)for(h=new Float32Array(o),l=0;ll+1&&(m+=4*(I-l),g+=4*(I-(l+1)))}}const B=n[l].destinationEdges.iterator;if(e&&s>=0)for(;B.next();){const J=B.value;O=J.toVertex,J.valid&&O.layer!==t&&(N=this.linkStraightenWeight(J),T=J.portFromColOffset,L=J.portToColOffset,F=O.column,C+=(Math.abs(p+T-(F+L))+1)*N,M+=(Math.abs(A+T-(F+L))+1)*N)}for(B.reset();B.next();){const J=B.value;if(O=J.toVertex,J.valid&&O.layer===t){for(X=0;Xl+1&&(m+=4*(I-(l+1)),g+=4*(I-l))}}const z=n[l+1].destinationEdges.iterator;if(e&&s>=0)for(;z.next();){const J=z.value;O=J.toVertex,J.valid&&O.layer!==t&&(N=this.linkStraightenWeight(J),T=J.portFromColOffset,L=J.portToColOffset,F=O.column,C+=(Math.abs(y+T-(F+L))+1)*N,M+=(Math.abs(P+T-(F+L))+1)*N)}for(z.reset();z.next();){const J=z.value;if(O=J.toVertex,J.valid&&O.layer===t){for(X=0;X1e3&&s&&(e=!1),e){const n=[];let o=0;for(o=0;o<=this.st;o++)n[o]=0;let r=0;const l=this.network.vertexes.iterator;for(;l.next();){const a=l.value;t=a.layer,r=a.column;const f=this.nodeMinColumnSpace(a,!1);n[t]=Math.max(n[t],r+f)}const h=8;for(l.reset();l.next();){const a=l.value;t=a.layer,r=a.column,a.column=((this.Ht-n[t])*h>>1)+r*h}this.Ht*=h}if((this.gr&2)!==0){i=!0;let n=0;for(;i&&n=0;t--)i=this.im(t,-1)||i;i=this.im(this.Us,0)||i,n++}}if((this.gr&4)!==0){for(t=this.Us+1;t<=this.st;t++)this.kA(t,1);for(t=this.Us-1;t>=0;t--)this.kA(t,-1);this.kA(this.Us,0)}if(e&&(this.DI(-1),this.DI(1)),(this.gr&2)!==0){i=!0;let n=0;for(;i&&n=0;t--)i=this.im(t,0)||i;n++}}}im(t,i){Debug&&(U.r(t,LayeredDigraphLayout,"bendStraighten:unfixedLayer"),U.r(i,LayeredDigraphLayout,"bendStraighten:direction"));let e=!1;for(;this.J4(t,i);)e=!0;return e}J4(t,i){Debug&&(U.r(t,LayeredDigraphLayout,"shiftbendStraighten:unfixedLayer"),U.r(i,LayeredDigraphLayout,"shiftbendStraighten:direction"));let e=0;const s=this._h(t),n=this.li[t],o=this.Dw(t,-1);if(i>0)for(e=0;ef+this.nodeMinColumnSpace(s[e-1],!1)?u=a-1:u=a;let d=0;e+1>=n||s[e+1].column-a-1>c+this.nodeMinColumnSpace(s[e+1],!0)?d=a+1:d=a;let m=0,g=0,p=0,y=0,x=0,b=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){y=this.linkStraightenWeight(N),x=N.portFromColOffset,b=N.portToColOffset;const L=T.column;m+=(Math.abs(a+b-(L+x))+1)*y,g+=(Math.abs(u+b-(L+x))+1)*y,p+=(Math.abs(d+b-(L+x))+1)*y}}}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){y=this.linkStraightenWeight(N),x=N.portFromColOffset,b=N.portToColOffset;const L=T.column;m+=(Math.abs(a+x-(L+b))+1)*y,g+=(Math.abs(u+x-(L+b))+1)*y,p+=(Math.abs(d+x-(L+b))+1)*y}}}let S=0,k=0,P=0;const A=o[s[e].index],C=r[s[e].index];A!==-1&&(S+=Math.abs(A-a),k+=Math.abs(A-u),P+=Math.abs(A-d)),C!==-1&&(S+=Math.abs(C-a),k+=Math.abs(C-u),P+=Math.abs(C-d)),g=r[e]?u=p:g<=r[e]&&(u=g)),u!==a&&(l=!0,h=!0,s[e].column=u)}return this.ta(t,s),this.Lw(),l}$4(){for(let t=0;t<=this.Ht;t++)for(;this.Z4(t,1););this.Lw()}Z4(t,i){Debug&&(U.r(t,LayeredDigraphLayout,"packAux:column"),U.r(i,LayeredDigraphLayout,"packAux:direction"));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.st;s++)n[s]=!1,o[s]=!1;const r=this.network.vertexes.iterator;for(;r.next();){const a=r.value,f=a.column-this.nodeMinColumnSpace(a,!0),c=a.column+this.nodeMinColumnSpace(a,!1);f<=t&&c>=t&&(n[a.layer]=!0),f<=e&&c>=e&&(o[a.layer]=!0)}let l=!0,h=!1;for(s=0;s<=this.st;s++)l=l&&!(n[s]&&o[s]);if(l){if(i>0)for(r.reset();r.next();){const a=r.value;a.column>t&&(a.column-=1,h=!0)}if(i<0)for(r.reset();r.next();){const a=r.value;a.column0)for(i=0;i<=this.Ht;i++)for(e=this.oe(),s=this.rk(!0),n=s+1;ss?this.hs(e):o=0;i--)for(e=this.oe(),s=this.rk(!0),n=s+1;ss?this.hs(e):o0)for(e.reset();e.next();){const f=e.value;f.column-this.nodeMinColumnSpace(f,!0)<=t&&(f.component=this.gn)}if(i<0)for(e.reset();e.next();){const f=e.value;f.column+this.nodeMinColumnSpace(f,!1)>=t&&(f.component=this.gn)}for(this.gn++,e.reset();e.next();){const f=e.value;f.component===-1&&(this.bA(f,this.gn,-1,!0,!0),this.gn++)}let s=0;const n=[];for(s=0;s0)for(let c=0;c0;c--)o[f*(this.Ht+1)+c]!==-1&&o[f*(this.Ht+1)+c-1]!==-1&&o[f*(this.Ht+1)+c]!==o[f*(this.Ht+1)+c-1]&&(n[o[f*(this.Ht+1)+c]*this.gn+o[f*(this.Ht+1)+c-1]]=!0)}const r=[];for(s=0;s0)for(e.reset();e.next();){const f=e.value;r[f.component]&&(f.column-=1,a=!0)}if(i<0)for(e.reset();e.next();){const f=e.value;r[f.component]&&(f.column+=1,a=!0)}return a}j4(){const t=U.at(),i=this.xu.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.tB(t,s);let n=null,o=null,r=null,l=null;const h=(this.vn&1)!==0,a=(this.vn&2)!==0,f=(this.vn&4)!==0,c=(this.vn&8)!==0;h&&(this.dl(t,s,!0),n=this.fk(t,!0,!1)),t.reverse(),f&&(this.dl(t,s,!1),r=this.fk(t,!1,!1));for(const u of t)u.reverse();c&&(this.dl(t,s,!1),l=this.fk(t,!1,!0)),t.reverse(),a&&(this.dl(t,s,!0),o=this.fk(t,!0,!0)),U.et(t),this.iB(n,o,r,l),this.network.vertexes.each(u=>{const d=u,m=U.at();h&&m.push(n.get(d)),a&&m.push(o.get(d)),f&&m.push(r.get(d)),c&&m.push(l.get(d)),m.sort((b,S)=>b-S);const g=m.length,p=Math.floor((g-1)/2),y=Math.ceil((g-1)/2),x=(m[p]+m[y])/2;U.et(m),d.we=x})}tB(t,i){const e=t.length;for(let s=1;sc)&&i.add(m)}o++}n=c}}}}eB(t){if(t.node===null){const i=t.getProperSourceVertexes();if(i.length>0)return i[0].node===null}return!1}dl(t,i,e){this.sB(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((a,f)=>a.ia-f.ia);const h=(l-1)/2;for(let a=Math.floor(h),f=Math.ceil(h);a<=f;a++)if(o.Wn===o){const c=r[a];let u;e?u=c.getDestinationEdge(o):u=o.getDestinationEdge(c),!i.has(u)&&n0){const f=this.OI(a,t),c=s?f.width:f.height,u=a.as.Su+a.we+a.jn-(f.we+f.jn+c+this.columnSpacing);f.as.Su=Math.min(f.as.Su,u)}h=a.ia+1}while(l0){const s=this.OI(e,i),n=s.Pf;this.RI(n,i),t.as===t&&(t.as=n.as);const o=this.N===90||this.N===270?s.width:s.height;if(t.as===n.as){const r=n.we+s.jn+o-e.jn+this.columnSpacing;t.we=Math.max(t.we,r)}}e=e.Wn}while(e!==t);for(;e.Wn!==t;)e=e.Wn,e.we=t.we,e.as=t.as}OI(t,i){const e=t.II,s=t.ia;return s<1&&U.n("Could not determine previous vertex in layer"),i[e][s-1]}iB(...t){let i=-1;const e=U.at(),s=U.at();let n=1/0;for(let o=0;o<4;o++){if(!t[o])continue;const r=this.oB(t[o],e,s,o);r{r.set(h.key,h.value+l)})}U.et(e),U.et(s)}oB(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,a=this.N===90||this.N===270?l.width:l.height;ho&&(o=h+a)}),i[s]=n,e[s]=o,o-n}commitLayout(){this.Aw(),this.commitNodes(),this.PA(),this.isRouting&&this.commitLinks()}Aw(){if(!this.setsPortSpots)return;const t=this.hk(!0),i=this.hk(!1),e=this.network.edges.iterator;for(;e.next();){const n=e.value.link;n!==null&&(n.fromSpot=t,n.toSpot=i)}}hk(t){return this.N===270?t?Spot.MiddleTop:Spot.MiddleBottom:this.N===90?t?Spot.MiddleBottom:Spot.MiddleTop:this.N===180?t?Spot.MiddleLeft:Spot.MiddleRight:t?Spot.MiddleRight:Spot.MiddleLeft}commitNodes(){this.Gs.length!==this.st+1&&(this.Gs=new Float32Array(this.st+1)),this.xs.length!==this.st+1&&(this.xs=new Float32Array(this.st+1)),this.bs.length!==this.st+1&&(this.bs=new Float32Array(this.st+1)),this.zt.length!==this.st+1&&(this.zt=new Float32Array(this.st+1));for(let d=0;d<=this.st;d++)this.Gs[d]=0,this.xs[d]=0,this.bs[d]=0,this.zt[d]=0;const t=this.network.vertexes.iterator;for(;t.next();){const d=t.value,m=d.layer;this.Gs[m]=Math.max(this.Gs[m],this.nodeMinLayerSpace(d,!0)),this.xs[m]=Math.max(this.xs[m],this.nodeMinLayerSpace(d,!1))}let i=0;const e=this.Ks;for(let d=0;d<=this.st;d++){let m=e;this.Gs[d]+this.xs[d]<=0&&(m=0),d>0&&(i+=m/2),this.N===90||this.N===0?(i+=this.xs[d],this.bs[d]=i,i+=this.Gs[d]):(i+=this.Gs[d],this.bs[d]=i,i+=this.xs[d]),d=0;n--)this.N===270?n===0?e.push(new Rect(0,0,s,Math.abs(this.zt[0]))):e.push(new Rect(0,this.zt[n-1],s,Math.abs(this.zt[n-1]-this.zt[n]))):this.N===90?n===0?e.push(new Rect(0,this.zt[0],s,Math.abs(this.zt[0]-t))):e.push(new Rect(0,this.zt[n],s,Math.abs(this.zt[n-1]-this.zt[n]))):this.N===180?n===0?e.push(new Rect(0,0,Math.abs(this.zt[0]),s)):e.push(new Rect(this.zt[n-1],0,Math.abs(this.zt[n-1]-this.zt[n]),s)):n===0?e.push(new Rect(this.zt[0],0,Math.abs(this.zt[0]-t),s)):e.push(new Rect(this.zt[n],0,Math.abs(this.zt[n-1]-this.zt[n]),s));this.commitLayers(e,this.pr)}commitLayers(t,i){}commitLinks(){const t=this.network.edges.iterator;let i=null;for(;t.next();)i=t.value.link,i!==null&&i.pointsCount>0&&(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),a=i.computeSpot(!1,l);let f=e.fromVertex,c=e.toVertex;if(e.valid){if(i.curve===9&&i.pointsCount===4)if(f.column===c.column&&this.alignOption===0){const N=i.getLinkPoint(n,r,h,!0,!1,o,l),T=i.getLinkPoint(o,l,a,!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&&i.Ml(h)&&(N=!0),l!==null&&i.Ml(a)&&(T=!0),N||T){let L=null;N&&(L=i.getLinkPointFromPoint(n,r,r.getDocumentPoint(Spot.Center),i.getPoint(3),!0),L.isReal()||L.set(n.actualBounds.center),i.setPointAt(0,L.x,L.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)),L){const F=i.getPoint(2);i.setPointAt(1,(L.x*2+F.x)/3,(L.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(f.layer===c.layer){i.commitRoute();continue}let u=!1,d=!1;const m=this.Ks;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=a===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 y,x,b=0,S=0,k=0,P=0,A=0,C=0,M=0;if(e.rev){let N=0;for(;c!==null&&f!==c;){y=null,x=null;const T=c.sourceEdges.iterator;for(;T.next();){const L=T.value;if(L.link===e.link&&(y=L.fromVertex,x=L.toVertex,y.node===null))break}if(y===null)break;if(y!==f)if(b=i.getPoint(p-1).x,S=i.getPoint(p-1).y,k=y.centerX,P=y.centerY,d)this.N===180||this.N===0?p===i.firstPickIndex+1?(i.insertPointAt(p++,b,S),i.insertPointAt(p++,b,P)):(x!==null?x.centerY:S)!==P&&(A=this.zt[y.layer-1]+this.pr.x,i.insertPointAt(p++,A,S),i.insertPointAt(p++,A,P)):p===i.firstPickIndex+1?(i.insertPointAt(p++,b,S),i.insertPointAt(p++,k,S)):(x!==null?x.centerX:b)!==k&&(A=this.zt[y.layer-1]+this.pr.y,i.insertPointAt(p++,b,A),i.insertPointAt(p++,k,A));else if(p===i.firstPickIndex+1)if(C=Math.max(10,this.Gs[c.layer]),M=Math.max(10,this.xs[c.layer]),u)this.N===180?k<=c.bounds.x?(N=c.bounds.x,i.insertPointAt(p++,N-C,P),i.insertPointAt(p++,N,P),i.insertPointAt(p++,N+M,P)):(i.insertPointAt(p++,k-C,P),i.insertPointAt(p++,k,P),i.insertPointAt(p++,k+M,P)):this.N===90?P>=c.bounds.bottom?(N=c.bounds.y+c.bounds.height,i.insertPointAt(p++,k,N+M),i.insertPointAt(p++,k,N),i.insertPointAt(p++,k,N-C)):(i.insertPointAt(p++,k,P+M),i.insertPointAt(p++,k,P),i.insertPointAt(p++,k,P-C)):this.N===270?P<=c.bounds.y?(N=c.bounds.y,i.insertPointAt(p++,k,N-C),i.insertPointAt(p++,k,N),i.insertPointAt(p++,k,N+M)):(i.insertPointAt(p++,k,P-C),i.insertPointAt(p++,k,P),i.insertPointAt(p++,k,P+M)):this.N===0&&(k>=c.bounds.right?(N=c.bounds.x+c.bounds.width,i.insertPointAt(p++,N+M,P),i.insertPointAt(p++,N,P),i.insertPointAt(p++,N-C,P)):(i.insertPointAt(p++,k+M,P),i.insertPointAt(p++,k,P),i.insertPointAt(p++,k-C,P)));else{i.insertPointAt(p++,b,S);let L=0;this.N===180||this.N===0?((this.N===180?k>=c.bounds.right:k<=c.bounds.x)&&(L=(this.N===0?-C:M)/2),i.insertPointAt(p++,b+L,P)):((this.N===270?P>=c.bounds.bottom:P<=c.bounds.y)&&(L=(this.N===90?-C:M)/2),i.insertPointAt(p++,k,S+L)),i.insertPointAt(p++,k,P)}else C=Math.max(10,this.Gs[y.layer]),M=Math.max(10,this.xs[y.layer]),u?this.N===180?(i.insertPointAt(p++,k-C-Math.max(10,m),P),i.insertPointAt(p++,Math.min(k-C+m/2,k),P),i.insertPointAt(p++,k,P),i.insertPointAt(p++,k,P),i.insertPointAt(p++,Math.max(k+M-m/2,k),P),i.insertPointAt(p++,k+M+m,P)):this.N===90?(i.insertPointAt(p++,k,P+M+Math.max(10,m)),i.insertPointAt(p++,k,Math.max(P+M-m/2,P)),i.insertPointAt(p++,k,P),i.insertPointAt(p++,k,P),i.insertPointAt(p++,k,Math.min(P-C+m/2,P)),i.insertPointAt(p++,k,P-C-m)):this.N===270?(i.insertPointAt(p++,k,P-C-Math.max(10,m)),i.insertPointAt(p++,k,Math.min(P-C+m/2,P)),i.insertPointAt(p++,k,P),i.insertPointAt(p++,k,P),i.insertPointAt(p++,k,Math.max(P+M-m/2,P)),i.insertPointAt(p++,k,P+M+m)):(i.insertPointAt(p++,k+M+Math.max(10,m),P),i.insertPointAt(p++,Math.max(k+M-m/2,k),P),i.insertPointAt(p++,k,P),i.insertPointAt(p++,k,P),i.insertPointAt(p++,Math.min(k-C+m/2,k),P),i.insertPointAt(p++,k-C-m,P)):(this.N===180||this.N===90||this.N,i.insertPointAt(p++,k,P));c=y}if(l===null||h!==Spot.None||d)if(b=i.getPoint(p-1).x,S=i.getPoint(p-1).y,k=i.getPoint(p).x,P=i.getPoint(p).y,d){const T=this.xs[f.layer];let L=0;this.N===180||this.N===0?(L=S,L>=f.bounds.y&&L<=f.bounds.bottom&&(this.N===180?k>=f.bounds.x:k<=f.bounds.right)&&(N=f.centerX+(this.N===180?-T:T),L=f.bounds.x&&L<=f.bounds.right&&(this.N===270?P>=f.bounds.y:P<=f.bounds.bottom)&&(N=f.centerY+(this.N===270?-T:T),L=f.bounds.x?(N=f.bounds.x+f.bounds.width,i.setPointAt(p-2,N,S),i.setPointAt(p-1,N+M,S)):this.N===90&&P<=f.bounds.bottom?(N=f.bounds.y,i.setPointAt(p-2,b,N),i.setPointAt(p-1,b,N-C)):this.N===270&&P>=f.bounds.y?(N=f.bounds.y+f.bounds.height,i.setPointAt(p-2,b,N),i.setPointAt(p-1,b,N+M)):this.N===0&&k<=f.bounds.right&&(N=f.bounds.x,i.setPointAt(p-2,N,S),i.setPointAt(p-1,N-C,S));else{C=Math.max(10,this.Gs[f.layer]),M=Math.max(10,this.xs[f.layer]);let T=0;this.N===180||this.N===0?((this.N===180?k<=f.bounds.x:k>=f.bounds.right)&&(T=(this.N===0?M:-C)/2),i.insertPointAt(p++,k+T,S)):((this.N===270?P<=f.bounds.y:P>=f.bounds.bottom)&&(T=(this.N===90?M:-C)/2),i.insertPointAt(p++,b,P+T)),i.insertPointAt(p++,k,P)}}else{for(;f!==null&&f!==c;){y=null,x=null;const N=f.destinationEdges.iterator;for(;N.next();){const T=N.value;if(T.link===e.link&&(y=T.toVertex,x=T.fromVertex,x.node!==null&&(x=null),y.node===null))break}if(y===null)break;y!==c&&(b=i.getPoint(p-1).x,S=i.getPoint(p-1).y,k=y.centerX,P=y.centerY,d?this.N===180||this.N===0?(x!==null?x.centerY:S)!==P&&(A=this.zt[y.layer]+this.pr.x,p===i.firstPickIndex+1&&(this.N===0?A=Math.max(A,b):A=Math.min(A,b)),i.insertPointAt(p++,A,S),i.insertPointAt(p++,A,P)):(x!==null?x.centerX:b)!==k&&(A=this.zt[y.layer]+this.pr.y,p===i.firstPickIndex+1&&(this.N===90?A=Math.max(A,S):A=Math.min(A,S)),i.insertPointAt(p++,b,A),i.insertPointAt(p++,k,A)):(C=Math.max(10,this.Gs[y.layer]),M=Math.max(10,this.xs[y.layer]),u?this.N===180?(i.insertPointAt(p++,k+M+Math.max(10,m),P),i.insertPointAt(p++,Math.max(k+M-m/2,k),P),i.insertPointAt(p++,k,P),i.insertPointAt(p++,k,P),i.insertPointAt(p++,Math.min(k-C+m/2,k),P),i.insertPointAt(p++,k-C-m,P)):this.N===90?(i.insertPointAt(p++,k,P-C-Math.max(10,m)),i.insertPointAt(p++,k,Math.min(P-C+m/2,P)),i.insertPointAt(p++,k,P),i.insertPointAt(p++,k,P),i.insertPointAt(p++,k,Math.max(P+M-m/2,P)),i.insertPointAt(p++,k,P+M+m)):this.N===270?(i.insertPointAt(p++,k,P+M+Math.max(10,m)),i.insertPointAt(p++,k,Math.max(P+M-m/2,P)),i.insertPointAt(p++,k,P),i.insertPointAt(p++,k,P),i.insertPointAt(p++,k,Math.min(P-C+m/2,P)),i.insertPointAt(p++,k,P-C-m)):(i.insertPointAt(p++,k-C-Math.max(10,m),P),i.insertPointAt(p++,Math.min(k-C+m/2,k),P),i.insertPointAt(p++,k,P),i.insertPointAt(p++,k,P),i.insertPointAt(p++,Math.max(k+M-m/2,k),P),i.insertPointAt(p++,k+M+m,P)):this.N===180?(i.insertPointAt(p++,k+M,P),i.insertPointAt(p++,k-C,P)):this.N===90?(i.insertPointAt(p++,k,P-C),i.insertPointAt(p++,k,P+M)):this.N===270?(i.insertPointAt(p++,k,P+M),i.insertPointAt(p++,k,P-C)):(i.insertPointAt(p++,k-C,P),i.insertPointAt(p++,k+M,P)))),f=y}d&&(b=i.getPoint(p-1).x,S=i.getPoint(p-1).y,k=i.getPoint(p).x,P=i.getPoint(p).y,this.N===180||this.N===0?S!==P&&(this.N===0?A=Math.min(Math.max((k+b)/2,this.zt[c.layer]+this.pr.x),k):A=Math.max(Math.min((k+b)/2,this.zt[c.layer]+this.pr.x),k),i.insertPointAt(p++,A,S),i.insertPointAt(p++,A,P)):b!==k&&(this.N===90?A=Math.min(Math.max((P+S)/2,this.zt[c.layer]+this.pr.y),P):A=Math.max(Math.min((P+S)/2,this.zt[c.layer]+this.pr.y),P),i.insertPointAt(p++,b,A),i.insertPointAt(p++,k,A)))}if(s!==null&&u&&i.pointsCount>=4){if(n!==null&&r!==null&&s.Ml(h)){const N=r.getDocumentPoint(Spot.Center);N.isReal()||N.setTo(n.actualBounds.centerX,n.actualBounds.centerY);const T=i.getPoint(3),L=i.getPoint(2);this.direction===90||this.direction===270?(i.setPointAt(1,T.x,(L.y+T.y)/2),i.setPointAt(2,T.x,(L.y+T.y)/2)):(i.setPointAt(1,(L.x+T.x)/2,T.y),i.setPointAt(2,(L.x+T.x)/2,T.y));const D=i.getLinkPointFromPoint(n,r,N,i.getPoint(1),!0);i.setPointAt(0,D.x,D.y)}if(o!==null&&l!==null&&s.Ml(a)){const N=l.getDocumentPoint(Spot.Center);N.isReal()||N.setTo(o.actualBounds.centerX,o.actualBounds.centerY);const T=i.getPoint(i.pointsCount-4),L=i.getLinkPointFromPoint(o,l,N,T,!1),D=i.getPoint(i.pointsCount-3);this.direction===90||this.direction===270?(i.setPointAt(i.pointsCount-2,T.x,(D.y+L.y)/2),i.setPointAt(i.pointsCount-3,T.x,(D.y+L.y)/2)):(i.setPointAt(i.pointsCount-2,(D.x+L.x)/2,T.y),i.setPointAt(i.pointsCount-3,(D.x+L.x)/2,T.y));const F=i.getLinkPointFromPoint(o,l,N,i.getPoint(i.pointsCount-2),!1);i.setPointAt(i.pointsCount-1,F.x,F.y)}}i.commitRoute(),e.commit()}}T4(){this.Tw=-1,this.Qg=0,this.Us=0,this.xu=null;for(let t=0;t=this.Hn.length){const n=[];for(let o=0;o=0&&(this.Ks=t,this.b()))}get columnSpacing(){return this.ne}set columnSpacing(t){this.ne!==t&&(U.i(t,"number",LayeredDigraphLayout,"columnSpacing"),t>0&&(this.ne=t,this.b()))}get direction(){return this.N}set direction(t){this.N!==t&&(U.i(t,"number",LayeredDigraphLayout,"direction"),t===0||t===90||t===180||t===270?(this.N=t,this.b()):U.n("LayeredDigraphLayout.direction must be 0, 90, 180, or 270"))}get cycleRemoveOption(){return this.gu}set cycleRemoveOption(t){this.gu!==t&&(U.W(t,LayeredDigraphCycleRemove,"LayeredDigraphCycleRemove"),(t===1||t===0||t===2)&&(this.gu=t,this.b()))}get layeringOption(){return this.mu}set layeringOption(t){this.mu!==t&&(U.W(t,LayeredDigraphLayering,"LayeredDigraphLayering"),(t===10||t===11||t===12)&&(this.mu=t,this.b()))}get initializeOption(){return this.pu}set initializeOption(t){this.pu!==t&&(U.W(t,LayeredDigraphInit,"LayeredDigraphInit"),(t===20||t===21||t===22)&&(this.pu=t,this.b()))}get iterations(){return this.kf}set iterations(t){this.kf!==t&&(U.r(t,LayeredDigraphNetwork,"iterations"),t>=0&&(this.kf=t,this.b()))}get aggressiveOption(){return this.yu}set aggressiveOption(t){this.yu!==t&&(U.W(t,LayeredDigraphAggressive,"LayeredDigraphAggressive"),(t===30||t===31||t===32)&&(this.yu=t,this.b()))}get packOption(){return this.gr}set packOption(t){this.gr!==t&&(U.i(t,"number",LayeredDigraphLayout,"packOption"),t>=0&&t<8&&(this.gr=t,this.b()))}get packIterations(){return this.wu}set packIterations(t){this.wu=t}get alignOption(){return this.vn}set alignOption(t){this.vn!==t&&(U.i(t,"number",LayeredDigraphLayout,"align"),t>=0&&t<16&&(this.vn=t,this.b()))}get centered(){return this.Qh}set centered(t){this.centered!==t&&(U.i(t,"boolean",LayeredDigraphLayout,"centered"),this.Qh=t,this.b())}get setsPortSpots(){return this.qn}set setsPortSpots(t){this.qn!==t&&(U.i(t,"boolean",LayeredDigraphLayout,"setsPortSpots"),this.qn=t,this.b())}get maxLayer(){return this.st}get maxIndex(){return this.Tw}get maxColumn(){return this.Ht}get minIndexLayer(){return this.Qg}get maxIndexLayer(){return this.Us}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 SegInfo{bl;rB;hb;lB;hB;Et;ns;aB;constructor(){this.bl=0,this.rB=0,this.hb=0,this.lB=0,this.hB=0,this.Et=0,this.ns=null,this.aB=0}}class LayeredDigraphNetwork extends LayoutNetwork{constructor(t){super(t)}createVertex(){const t=new LayeredDigraphVertex(this);return t.centered=this.layout.centered,t}createEdge(){return new LayeredDigraphEdge(this)}}class LayeredDigraphVertex extends LayoutVertex{bl;kh;Et;ck;uk;Qh;re;bu;so;lk;nk;ok;Pf;Wn;II;ia;as;Su;we;jn;Iw=null;Rw=null;Ow=null;Ew=null;constructor(t){super(t),this.bl=-1,this.kh=-1,this.Et=-1,this.ck=NaN,this.uk=null,this.Qh=!0,this.re=!1,this.bu=NaN,this.so=NaN,this.lk=0,this.nk=null,this.ok=null}static EI(t,i){return t.index-i.index}getProperSourceEdges(){if(!this.Ow){const t=[];for(const i of this.Ao){const e=i;e.valid&&t.push(e)}this.Ow=t}return this.Ow}getProperDestinationEdges(){if(!this.Ew){const t=[];for(const i of this.fr){const e=i;e.valid&&t.push(e)}this.Ew=t}return this.Ew}getDestinationEdge(t){const i=this.getProperDestinationEdges();for(const e of i)if(e.toVertex===t)return e;U.n("Unable to find destination edge to given vertex")}getProperSourceVertexes(){if(!this.Iw){const t=[];for(const i of this.Ao){const e=i;!e.valid||e.fromVertex.layer<=e.toVertex.layer||t.push(e.fromVertex)}t.sort(LayeredDigraphVertex.EI),this.Iw=t}return this.Iw}getProperDestinationVertexes(){if(!this.Rw){const t=[];for(const i of this.fr){const e=i;!e.valid||e.fromVertex.layer<=e.toVertex.layer||t.push(e.toVertex)}t.sort(LayeredDigraphVertex.EI),this.Rw=t}return this.Rw}addSourceEdge(t){super.addSourceEdge(t),this.Iw=null,this.Ow=null}deleteSourceEdge(t){super.deleteSourceEdge(t),this.Iw=null,this.Ow=null}addDestinationEdge(t){super.addDestinationEdge(t),this.Rw=null,this.Ew=null}deleteDestinationEdge(t){super.deleteDestinationEdge(t),this.Rw=null,this.Ew=null}commit(){if(this.centered)super.commit();else{const t=this.node;if(t!==null){const i=this.network.layout;if(!i)return;i.direction===180||i.direction===270?t.moveTo(this.bounds.right-t.actualBounds.width,this.bounds.bottom-t.actualBounds.height):t.moveTo(this.bounds.x,this.bounds.y)}}}get layer(){return this.bl}set layer(t){this.bl=t}get column(){return this.kh}set column(t){this.kh=t}get index(){return this.Et}set index(t){this.Et=t}get component(){return this.ck}set component(t){this.ck!==t&&(U.i(t,"number",LayeredDigraphVertex,"component"),this.ck=t)}get near(){return this.uk}set near(t){this.uk!==t&&(Debug&&t!==null&&U.s(t,LayeredDigraphVertex,LayeredDigraphVertex,"near"),this.uk=t)}get centered(){return this.Qh}set centered(t){this.Qh=t}}class LayeredDigraphEdge extends LayoutEdge{re;dk;gk;mk;pk;yk;wk;constructor(t){super(t),this.re=!1,this.dk=!1,this.gk=!1,this.mk=NaN,this.pk=NaN,this.yk=0,this.wk=0}get fromVertex(){return this.rs}set fromVertex(t){this.rs!==t&&(Debug&&t!==null&&U.s(t,LayeredDigraphVertex,LayeredDigraphEdge,"fromVertex"),this.rs=t)}get toVertex(){return this.ls}set toVertex(t){this.ls!==t&&(Debug&&t!==null&&U.s(t,LayeredDigraphVertex,LayeredDigraphEdge,"toVertex"),this.ls=t)}get valid(){return this.re}set valid(t){this.re!==t&&(U.i(t,"boolean",LayeredDigraphEdge,"valid"),this.re=t)}get rev(){return this.dk}set rev(t){this.dk!==t&&(U.i(t,"boolean",LayeredDigraphEdge,"rev"),this.dk=t)}get forest(){return this.gk}set forest(t){this.gk!==t&&(U.i(t,"boolean",LayeredDigraphEdge,"forest"),this.gk=t)}get portFromPos(){return this.mk}set portFromPos(t){this.mk!==t&&(U.i(t,"number",LayeredDigraphEdge,"portFromPos"),this.mk=t)}get portToPos(){return this.pk}set portToPos(t){this.pk!==t&&(U.i(t,"number",LayeredDigraphEdge,"portToPos"),this.pk=t)}get portFromColOffset(){return this.yk}set portFromColOffset(t){this.yk!==t&&(U.i(t,"number",LayeredDigraphEdge,"portFromColOffset"),this.yk=t)}get portToColOffset(){return this.wk}set portToColOffset(t){this.wk!==t&&(U.i(t,"number",LayeredDigraphEdge,"portToColOffset"),this.wk=t)}}var TreePath=(w=>(w[w.Default=0]="Default",w[w.Destination=1]="Destination",w[w.Source=2]="Source",w))(TreePath||{}),TreeSorting=(w=>(w[w.Forwards=10]="Forwards",w[w.Reverse=11]="Reverse",w[w.Ascending=12]="Ascending",w[w.Descending=13]="Descending",w))(TreeSorting||{}),TreeAlignment=(w=>(w[w.CenterSubtrees=20]="CenterSubtrees",w[w.CenterChildren=21]="CenterChildren",w[w.Start=22]="Start",w[w.End=23]="End",w[w.Bus=24]="Bus",w[w.BusBranching=25]="BusBranching",w[w.TopLeftBus=26]="TopLeftBus",w[w.BottomRightBus=27]="BottomRightBus",w[w.Custom=28]="Custom",w))(TreeAlignment||{}),TreeCompaction=(w=>(w[w.None=30]="None",w[w.Block=31]="Block",w))(TreeCompaction||{}),TreeStyle=(w=>(w[w.Layered=40]="Layered",w[w.LastParents=41]="LastParents",w[w.Alternating=42]="Alternating",w[w.RootOnly=43]="RootOnly",w))(TreeStyle||{}),TreeArrangement=(w=>(w[w.Vertical=50]="Vertical",w[w.Horizontal=51]="Horizontal",w[w.FixedRoots=52]="FixedRoots",w))(TreeArrangement||{}),TreeLayerStyle=(w=>(w[w.Individual=60]="Individual",w[w.Siblings=61]="Siblings",w[w.Uniform=62]="Uniform",w))(TreeLayerStyle||{});class TreeLayout extends Layout{Xi;Bi;ku;em;MA;qe;Ji;Ys;Y;K;xk;ks;constructor(t){super(),this.Xi=new GSet,this.Bi=0,this.ks=1,this.ku=40,this.em=60,this.MA=[],this.qe=!0,this.Ji=50,this.Ys=new Size(10,10).k();const i=new TreeNetwork(this);this.Y=new TreeVertex(i),this.K=new TreeVertex(i),this.xk=[],t&&Object.assign(this,t)}cloneProtected(t){super.cloneProtected(t),t.Bi=this.Bi,t.ku=this.ku,t.em=this.em,t.qe=this.qe,t.Ji=this.Ji,t.Ys.c(this.Ys),t.Y.copyInheritedPropertiesFrom(this.Y),t.K.copyInheritedPropertiesFrom(this.K)}gi(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.gi(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){Debug&&t===null&&U.n("Layout.doLayout(collection) argument must not be null but a Diagram, a Group, or an Iterable of Parts"),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.ks=i.isTreePathToChildren?1:2:this.ks=this.path===0?1:this.path,this.network.vertexes.count>0&&(this.fB(),this.cB(),this.uB(),this.dB(),this.wA(),this.gB(),this.arrangeTrees(),this.updateParts()),this.network=null,this.Xi=new GSet,this.isValidLayout=!0}fB(){if(this.network===null)return;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.Xi.count>0){const n=new GSet,o=this.Xi.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.Xi=n}this.Xi.count===0&&this.findRoots();const i=this.Xi.copy().iterator;for(;i.next();){const n=i.value;n.initialized||(n.initialized=!0,this.NA(n))}let e=this.network.vertexes,s=null;for(;s=this.mB(e),s.count>0;){const n=this.BI(s);n!==null&&(this.Xi.add(n),n.initialized=!0,this.NA(n)),e=s}}mB(t){const i=new GSet,e=t.iterator;for(;e.next();){const s=e.value;s.initialized||i.add(s)}return i}findRoots(){if(this.network===null)return;const t=this.network.vertexes,i=t.iterator;for(;i.next();){const e=i.value;switch(this.ks){case 1:e.sourceEdges.count===0&&this.Xi.add(e);break;case 2:e.destinationEdges.count===0&&this.Xi.add(e);break;default:U.n("Unhandled path value "+this.ks.toString())}}if(this.Xi.count===0){const e=this.BI(t);e!==null&&this.Xi.add(e)}}BI(t){let i=999999,e=null;const s=t.iterator;for(;s.next();){const n=s.value;switch(this.ks){case 1:n.sourceEdges.count0){const s=new List,n=t.destinationVertexes;for(;n.next();){const o=n.value;this.VI(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.VI(t,o)&&s.add(o)}s.count>0&&(t.children=s.toArray())}break;default:U.n("Unhandled path value"+this.ks.toString())}const i=t.children,e=i.length;for(let s=0;st.level?!1:(this.yB(i.parent,i),!0):!0}pB(t,i){if(i===null)return!1;Debug&&U.s(t,TreeVertex,TreeLayout,"isAncestor:a"),Debug&&U.s(i,TreeVertex,TreeLayout,"isAncestor:b");let e=i.parent;for(;e!==null&&e!==t;)e=e.parent;return e===t}yB(t,i){if(t===null||i===null)return;Debug&&U.s(t,TreeVertex,TreeLayout,"removeChild:p"),Debug&&U.s(i,TreeVertex,TreeLayout,"removeChild:c");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}wB(t){switch(Debug&&U.s(t,TreeVertex,TreeLayout,"mom:v"),this.ku){default:case 40:return t.parent!==null?t.parent:this.Y;case 43:return t.parent===null?this.Y:t.parent.parent===null?this.K:t.parent;case 42:return t.parent!==null?t.parent.parent!==null?t.parent.parent:this.K:this.Y;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.K:t.parent!==null?t.parent:this.Y}}}initializeTreeVertexValues(t){Debug&&U.s(t,TreeVertex,TreeLayout,"initializeTreeVertexValues:v");const i=this.wB(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||a&&c)if(t.commentMargin>=0){g.e(t.bounds.x-t.commentMargin-b.width,t.bounds.y+u),x.move(g);const S=x.findLinksInto();for(;S.next();){const k=S.value;k.fromSpot=Spot.MiddleLeft,k.toSpot=Spot.MiddleRight}}else{g.e(t.bounds.x+t.focus.x*2-t.commentMargin,t.bounds.y+u),x.move(g);const S=x.findLinksInto();for(;S.next();){const k=S.value;k.fromSpot=Spot.MiddleRight,k.toSpot=Spot.MiddleLeft}}else if(t.commentMargin>=0){g.e(t.bounds.x+t.focus.x*2+t.commentMargin,t.bounds.y+u),x.move(g);const S=x.findLinksInto();for(;S.next();){const k=S.value;k.fromSpot=Spot.MiddleRight,k.toSpot=Spot.MiddleLeft}}else{g.e(t.bounds.x+t.commentMargin-b.width,t.bounds.y+u),x.move(g);const S=x.findLinksInto();for(;S.next();){const k=S.value;k.fromSpot=Spot.MiddleLeft,k.toSpot=Spot.MiddleRight}}t.commentSpacing>=0?u+=b.height+t.commentSpacing:u+=t.commentSpacing-b.height}else{if(o>135&&!l||!a&&c)if(t.commentMargin>=0){g.e(t.bounds.x+u,t.bounds.y-t.commentMargin-b.height),x.move(g);const S=x.findLinksInto();for(;S.next();){const k=S.value;k.fromSpot=Spot.MiddleTop,k.toSpot=Spot.MiddleBottom}}else{g.e(t.bounds.x+u,t.bounds.y+t.focus.y*2-t.commentMargin),x.move(g);const S=x.findLinksInto();for(;S.next();){const k=S.value;k.fromSpot=Spot.MiddleBottom,k.toSpot=Spot.MiddleTop}}else if(t.commentMargin>=0){g.e(t.bounds.x+u,t.bounds.y+t.focus.y*2+t.commentMargin),x.move(g);const S=x.findLinksInto();for(;S.next();){const k=S.value;k.fromSpot=Spot.MiddleBottom,k.toSpot=Spot.MiddleTop}}else{g.e(t.bounds.x+u,t.bounds.y+t.commentMargin-b.height),x.move(g);const S=x.findLinksInto();for(;S.next();){const k=S.value;k.fromSpot=Spot.MiddleTop,k.toSpot=Spot.MiddleBottom}}t.commentSpacing>=0?u+=b.width+t.commentSpacing:u+=t.commentSpacing-b.width}}Point.o(g);const p=u-t.commentSpacing-(h?e.height:e.width);if(this.ks===1){const y=t.destinationEdges;for(;y.next();){const b=y.value.link;b!==null&&!b.isAvoiding&&(b.fromEndSegmentLength=p>0?p:NaN)}}else{const y=t.sourceEdges;for(;y.next();){const b=y.value.link;b!==null&&!b.isAvoiding&&(b.toEndSegmentLength=p>0?p:NaN)}}}}gB(){if(this.network===null)return;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.Bw(r))if(o>1)for(let R=0;R0&&M>0&&P+u+O.width>f&&(P135?-S-g:S+g);const X=M===0?m:u;this.bk(I,0,A),I.X.e(P+X,A),b=Math.max(b,P+X+O.width),S=Math.max(S,k+(C===0?0:g)+O.height),P+=X+O.width}else{f>0&&M>0&&A+u+O.height>f&&(A135?-b-g:b+g);const X=M===0?m:u;this.bk(I,P,0),I.X.e(P,A+X),S=Math.max(S,A+X+O.height),b=Math.max(b,k+(C===0?0:g)+O.width),A+=X+O.height}M++}C>0&&(e?(S+=Math.max(0,c),P0&&(h||this.Pu(t,p,0,0,o-1),b+=p)):(b+=Math.max(0,c),A0&&(h||this.Pu(t,0,p,0,o-1),S+=p)));let D=0,F=0;switch(r){case 20:e?D+=b/2-t.focus.x-d/2:F+=S/2-t.focus.y-d/2;break;default:case 21:if(C>0)e?D+=b/2-t.focus.x-d/2:F+=S/2-t.focus.y-d/2;else{const I=o;if(e){const O=n[0].X.x+n[0].dt.x,X=n[I-1].X.x+n[I-1].dt.x+n[I-1].focus.x*2;D+=O+(X-O)/2-t.focus.x-d/2}else{const O=n[0].X.y+n[0].dt.y,X=n[I-1].X.y+n[I-1].dt.y+n[I-1].focus.y*2;F+=O+(X-O)/2-t.focus.y-d/2}}break;case 22:e?(D-=d,b+=d):(F-=d,S+=d);break;case 23:e?(D+=b-t.width+d,b+=d):(F+=S-t.height+d,S+=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].dt.x:o>1?F+=T+u/2-t.focus.y:F+=n[0].focus.y-t.focus.y+n[0].dt.y;break;case 26:e?D+=b+u/2-t.focus.x:F+=S+u/2-t.focus.y;break;case 27:break;case 28:const R=this.customAlignment(t,D,F,b,S);D=R[0],F=R[1],b=R[2],S=R[3];break}for(let R=0;R135?(a?-S:-I.bt.height)+I.dt.y-c:x+c+I.dt.y)):I.X.e(I.X.x+(i>135?(a?-b:-I.bt.width)+I.dt.x-c:y+c+I.dt.x),I.X.y+I.dt.y-F)}e?(b=this.AA(t,b,D),D<0&&(D=0),i>135&&(F+=S+c),S=Math.max(Math.max(S,x),S+x+c)):(i>135&&(D+=b+c),b=Math.max(Math.max(b,y),b+y+c),S=this.TA(t,S,F),F<0&&(F=0)),t.dt.e(D,F),t.bt.e(b,S)}customAlignment(t,i,e,s,n){return[i,e,s,n]}UI(t,i,e,s,n,o,r){Debug&&U.s(t,TreeVertex,TreeLayout,"layoutBusChildrenPosDir:v");const l=i.length;if(l===0)return r.e(e,0,n,o),r;if(l===1){const y=i[0];return n=y.bt.width,o=y.bt.height,r.e(e,0,n,o),r}const h=t.nodeSpacing,a=t.rowSpacing,c=this.orthoAngle(t)===90;let u=0,d=0,m=0;for(let y=0;y1&&y===l-1)continue;const x=i[y],b=x.bt,S=u===0?0:a;if(c){const k=this.computeBusNodeSpacing(x)-h;x.X.e(e-(b.width+k),m+S),n=Math.max(n,b.width+k),o=Math.max(o,m+S+b.height),m+=S+b.height}else{const k=this.computeBusNodeSpacing(x)-h;x.X.e(d+S,e-(b.height+k)),o=Math.max(o,b.height+k),n=Math.max(n,d+S+b.width),d+=S+b.width}u++}u=0;const g=d,p=m;c?(d=e+h,m=0):(d=0,m=e+h);for(let y=0;y1&&l%2===1){const y=i[l-1],x=y.bt,b=this.computeBusLastRowSpacing(y,c?Math.max(Math.abs(p),Math.abs(m)):Math.max(Math.abs(g),Math.abs(d)));if(c){y.X.e(e+h/2-y.focus.x-y.dt.x,o+b);const S=e+h/2-y.focus.x-y.dt.x;n=Math.max(n,S+x.width),S<0&&(n-=S),o=Math.max(o,Math.max(p,m)+b+x.height),y.X.x<0&&(e=this.Sk(t,y.X.x,!1,e,h))}else{y.X.e(n+b,e+h/2-y.focus.y-y.dt.y),n=Math.max(n,Math.max(g,d)+b+x.width);const S=e+h/2-y.focus.y-y.dt.y;o=Math.max(o,S+x.height),S<0&&(o-=S),y.X.y<0&&(e=this.Sk(t,y.X.y,!0,e,h))}}return r.e(e,0,n,o),r}GI(t,i,e,s,n,o,r){Debug&&U.s(t,TreeVertex,TreeLayout,"layoutBusChildrenNegDir:v");const l=i.length;if(l===0)return r.e(e,0,n,o),r;if(l===1){const y=i[0];return n=y.bt.width,o=y.bt.height,r.e(e,0,n,o),r}const h=t.nodeSpacing,a=t.rowSpacing,c=this.orthoAngle(t)===270;let u=0,d=0,m=0;for(let y=0;y1&&y===l-1)continue;const x=i[y],b=x.bt,S=u===0?0:a;if(c){const k=this.computeBusNodeSpacing(x)-h;m-=S+b.height,x.X.e(e-(b.width+k),m),n=Math.max(n,b.width+k),o=Math.max(o,Math.abs(m))}else{const k=this.computeBusNodeSpacing(x)-h;d-=S+b.width,x.X.e(d,e-(b.height+k)),o=Math.max(o,b.height+k),n=Math.max(n,Math.abs(d))}u++}u=0;const g=d,p=m;c?(d=e+h,m=0):(d=0,m=e+h);for(let y=0;y1&&l%2===1){const y=i[l-1],x=y.bt,b=this.computeBusLastRowSpacing(y,c?Math.max(Math.abs(p),Math.abs(m)):Math.max(Math.abs(g),Math.abs(d)));if(c){y.X.e(e+h/2-y.focus.x-y.dt.x,-o-x.height-b);const S=e+h/2-y.focus.x-y.dt.x;n=Math.max(n,S+x.width),S<0&&(n-=S),o=Math.max(o,Math.abs(Math.min(p,m))+b+x.height),y.X.x<0&&(e=this.Sk(t,y.X.x,!1,e,h))}else{y.X.e(-n-x.width-b,e+h/2-y.focus.y-y.dt.y),n=Math.max(n,Math.abs(Math.min(g,d))+b+x.width);const S=e+h/2-y.focus.y-y.dt.y;o=Math.max(o,S+x.height),S<0&&(o-=S),y.X.y<0&&(e=this.Sk(t,y.X.y,!0,e,h))}}for(let y=0;ys&&(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}}TA(t,i,e){switch(Debug&&U.s(t,TreeVertex,TreeLayout,"calculateSubheight:v"),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}}LA(t,i,e){switch(Debug&&U.W(t,TreeAlignment,"TreeAlignment"),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.n("Unhandled alignment value "+t.toString())}return new Point(i,e)}Mf(t,i,e,s,n,o){Debug&&U.s(t,TreeVertex,TreeLayout,"shiftRelPosAlign:v"),Debug&&U.W(i,TreeAlignment,"TreeAlignment");const r=this.LA(i,e,s);this.Pu(t,r.x,r.y,n,o)}Pu(t,i,e,s,n){if(Debug&&U.s(t,TreeVertex,TreeLayout,"shiftRelPos:v"),i===0&&e===0)return;const o=t.children;for(let r=s;r<=n;r++){const h=o[r].X;h.x+=i,h.y+=e}}bk(t,i,e){Debug&&(U.s(t,TreeVertex,TreeLayout,"recordMidPoints:v"),U.i(i,"number",TreeLayout,"recordMidPoints:x"),U.i(e,"number",TreeLayout,"recordMidPoints:y"));const s=t.parent;switch(this.ks){case 1:{const n=t.sourceEdges;for(;n.next();){const o=n.value;o.fromVertex===s&&o.relativePoint.e(i,e)}break}case 2:{const n=t.destinationEdges;for(;n.next();){const o=n.value;o.toVertex===s&&o.relativePoint.e(i,e)}break}default:U.n("Unhandled path value "+this.ks.toString())}}xB(t){if(Debug&&U.s(t,TreeVertex,TreeLayout,"layoutTreeBlock:v"),t.childrenCount===0){const z=t.parent;let H=!1,W=0,j=21;z!==null&&(W=z.angle,j=z.alignment,H=this.isBusAlignment(j));const Z=this.CA(t);t.X.e(0,0),t.bt.e(t.width,t.height),t.parent!==null&&t.comments!==null&&((W===180||W===270)&&!H||Z)?W===180&&!H||(W===90||W===270)&&Z?t.dt.e(t.width-t.focus.x*2,0):t.dt.e(0,t.height-t.focus.y*2):t.dt.e(0,0),t.sm=null,t.nm=null;return}const i=this.orthoAngle(t),e=i===90||i===270;let s=0;const n=t.children,o=n.length;for(let z=0;z135&&n.reverse(),this.Bw(r))if(o>1)for(let z=0;z0&&L>0&&M+u+W.width>f&&(M135?-b-m:b+m),this.bk(H,0,N);let j=0;if(L===0)k=H.sm,P=H.nm,A=W.width,C=W.height,(k===null||P===null||i!==this.orthoAngle(H))&&(k=this.xe(2),P=this.xe(2),k[0].e(0,0),k[1].e(0,C),P[0].e(A,0),P[1].e(A,C));else{const Z=U.at(),V=Rect.a();this.qI(t,H,k,P,A,C,Z,V),j=V.x,k=Z[0],P=Z[1],A=V.width,C=V.height,U.et(Z),M0&&L>0&&N+u+W.height>f&&(N135?-x-m:x+m),this.bk(H,M,0);let j=0;if(L===0)k=H.sm,P=H.nm,A=W.width,C=W.height,(k===null||P===null||i!==this.orthoAngle(H))&&(k=this.xe(2),P=this.xe(2),k[0].e(0,0),k[1].e(A,0),P[0].e(0,C),P[1].e(A,C));else{const Z=U.at(),V=Rect.a();this.qI(t,H,k,P,A,C,Z,V),j=V.x,k=Z[0],P=Z[1],A=V.width,C=V.height,U.et(Z),N0&&(e?(b+=Math.max(0,c),M0&&(h||this.Pu(t,g,0,0,o-1),x+=g)):(x+=Math.max(0,c),N0&&(h||this.Pu(t,0,g,0,o-1),b+=g)));let I=0,O=0;switch(r){case 20:e?I+=x/2-t.focus.x-d/2:O+=b/2-t.focus.y-d/2;break;default:case 21:if(T>0)e?I+=x/2-t.focus.x-d/2:O+=b/2-t.focus.y-d/2;else{const H=o;if(e){const W=n[0].X.x+n[0].dt.x,j=n[H-1].X.x+n[H-1].dt.x+n[H-1].focus.x*2;I+=W+(j-W)/2-t.focus.x-d/2}else{const W=n[0].X.y+n[0].dt.y,j=n[H-1].X.y+n[H-1].dt.y+n[H-1].focus.y*2;O+=W+(j-W)/2-t.focus.y-d/2}}break;case 22:e?(I-=d,x+=d):(O-=d,b+=d);break;case 23:e?(I+=x-t.width+d,x+=d):(O+=b-t.height+d,b+=d);break;case 24:e?o>1?I+=F+u/2-t.focus.x:I+=n[0].focus.x-t.focus.x+n[0].dt.x:o>1?O+=F+u/2-t.focus.y:O+=n[0].focus.y-t.focus.y+n[0].dt.y;break;case 26:e?I+=x+u/2-t.focus.x:O+=b+u/2-t.focus.y;break;case 27:break;case 28:const z=this.customAlignment(t,I,O,x,b);I=z[0],O=z[1],x=z[2],b=z[3];break}for(let z=0;z135?(a?-b:-H.bt.height)+H.dt.y-c:y+c+H.dt.y)):H.X.e(H.X.x+(i>135?(a?-x:-H.bt.width)+H.dt.x-c:p+c+H.dt.x),H.X.y+H.dt.y-O)}let X=0,K=0;if(a)e?(x=this.AA(t,x,I),I<0&&(I=0),i>135&&(O+=b+c),b+=y+c,r===27&&(X+=u/2+t.focus.x),K+=y+c):(i>135&&(I+=x+c),x+=p+c,b=this.TA(t,b,O),O<0&&(O=0),r===27&&(K+=u/2+t.focus.y),X+=p+c);else if(e){if(t.comments===null){if(p>x){const z=this.LA(r,p-x,0);X=z.x,K=z.y,x=p,I=0}}else x=this.AA(t,x,I);I<0&&(X-=I,I=0),i>135&&(O+=b+c),b=Math.max(Math.max(b,y),b+y+c),K+=y+c}else{if(i>135&&(I+=x+c),x=Math.max(Math.max(x,p),x+p+c),t.comments===null){if(y>b){const z=this.LA(r,0,y-b);X=z.x,K=z.y,b=y,O=0}}else b=this.TA(t,b,O);O<0&&(K-=O,O=0),X+=p+c}let B,Y;if(T>0)B=this.xe(4),Y=this.xe(4),e?(B[2].e(0,y+c),B[3].e(B[2].x,b),Y[2].e(x,B[2].y),Y[3].e(Y[2].x,B[3].y)):(B[2].e(p+c,0),B[3].e(x,B[2].y),Y[2].e(B[2].x,b),Y[3].e(B[3].x,Y[2].y));else{B=this.xe(k.length+2),Y=this.xe(P.length+2);for(let z=0;zB[0].x?B[2].c(B[1]):B[1].c(B[2])),B[3].yB[0].x?B[3].c(B[2]):B[2].c(B[3])),Y[0].e(I+p,0),Y[1].e(Y[0].x,y),Y[2].yB[0].y?B[2].c(B[1]):B[1].c(B[2])),B[3].xB[0].y?B[3].c(B[2]):B[2].c(B[3])),Y[0].e(0,O+y),Y[1].e(p,Y[0].y),Y[2].xl;){const a=i[o++];s[r++].e(a.x,a.y+e)}const h=this.xe(r);for(n=0;nl;){const a=i[o++];s[r++].e(a.x+e,a.y)}const h=this.xe(r);for(n=0;nl;){const a=t[n++];s[r++].e(a.x,a.y)}const h=this.xe(r);for(n=0;nl;){const a=t[n++];s[r++].e(a.x,a.y)}const h=this.xe(r);for(n=0;nh&&r.xr.x&&ha&&r.yr.y&&a0){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){Debug&&U.s(t,TreeVertex,TreeLayout,"computeNodeIndent:v");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.Xi}set roots(t){this.Xi!==t&&(U.s(t,GSet,TreeLayout,"roots"),this.Xi=t,this.b())}get path(){return this.Bi}set path(t){this.Bi!==t&&(U.W(t,TreePath,"TreePath"),this.Bi=t,this.b())}get treeStyle(){return this.ku}set treeStyle(t){this.ku!==t&&(U.W(t,TreeStyle,"TreeStyle"),(t===40||t===42||t===41||t===43)&&(this.ku=t,this.b()))}get layerStyle(){return this.em}set layerStyle(t){this.em!==t&&(U.W(t,TreeLayerStyle,"TreeLayerStyle"),(t===60||t===61||t===62)&&(this.em=t,this.b()))}get comments(){return this.qe}set comments(t){this.qe!==t&&(U.i(t,"boolean",TreeLayout,"comments"),this.qe=t,this.b())}get arrangement(){return this.Ji}set arrangement(t){this.Ji!==t&&(U.W(t,TreeArrangement,"TreeArrangement"),(t===50||t===51||t===52)&&(this.Ji=t,this.b()))}get arrangementSpacing(){return this.Ys}set arrangementSpacing(t){U.s(t,Size,TreeLayout,"arrangementSpacing"),this.Ys.equals(t)||(this.Ys.c(t),this.b())}get rootDefaults(){return this.Y}set rootDefaults(t){this.Y!==t&&(U.s(t,TreeVertex,TreeLayout,"rootDefaults"),this.Y=t,this.b())}get alternateDefaults(){return this.K}set alternateDefaults(t){this.K!==t&&(U.s(t,TreeVertex,TreeLayout,"alternateDefaults"),this.K=t,this.b())}get sorting(){return this.Y.sorting}set sorting(t){this.Y.sorting!==t&&(U.W(t,TreeSorting,"TreeSorting"),this.Y.sorting=t,this.b())}get comparer(){return this.Y.comparer}set comparer(t){this.Y.comparer!==t&&(U.C(t,TreeLayout,"comparer"),this.Y.comparer=t,this.b())}get angle(){return this.Y.angle}set angle(t){this.Y.angle!==t&&(U.i(t,"number",TreeLayout,"angle"),t===0||t===90||t===180||t===270?(this.Y.angle=t,this.b()):U.n("TreeLayout.angle must be 0, 90, 180, or 270"))}get alignment(){return this.Y.alignment}set alignment(t){this.Y.alignment!==t&&(U.W(t,TreeAlignment,"TreeAlignment"),this.Y.alignment=t,this.b())}get nodeIndent(){return this.Y.nodeIndent}set nodeIndent(t){this.Y.nodeIndent!==t&&(U.i(t,"number",TreeLayout,"nodeIndent"),t>=0&&(this.Y.nodeIndent=t,this.b()))}get nodeIndentPastParent(){return this.Y.nodeIndentPastParent}set nodeIndentPastParent(t){this.Y.nodeIndentPastParent!==t&&(U.i(t,"number",TreeLayout,"nodeIndentPastParent"),t>=0&&t<=1&&(this.Y.nodeIndentPastParent=t,this.b()))}get nodeSpacing(){return this.Y.nodeSpacing}set nodeSpacing(t){this.Y.nodeSpacing!==t&&(U.i(t,"number",TreeLayout,"nodeSpacing"),this.Y.nodeSpacing=t,this.b())}get layerSpacing(){return this.Y.layerSpacing}set layerSpacing(t){this.Y.layerSpacing!==t&&(U.i(t,"number",TreeLayout,"layerSpacing"),this.Y.layerSpacing=t,this.b())}get layerSpacingParentOverlap(){return this.Y.layerSpacingParentOverlap}set layerSpacingParentOverlap(t){this.Y.layerSpacingParentOverlap!==t&&(U.i(t,"number",TreeLayout,"layerSpacingParentOverlap"),t>=0&&t<=1&&(this.Y.layerSpacingParentOverlap=t,this.b()))}get compaction(){return this.Y.compaction}set compaction(t){this.Y.compaction!==t&&(U.W(t,TreeCompaction,"TreeCompaction"),(t===30||t===31)&&(this.Y.compaction=t,this.b()))}get breadthLimit(){return this.Y.breadthLimit}set breadthLimit(t){this.Y.breadthLimit!==t&&(U.i(t,"number",TreeLayout,"breadthLimit"),t>=0&&(this.Y.breadthLimit=t,this.b()))}get rowSpacing(){return this.Y.rowSpacing}set rowSpacing(t){this.Y.rowSpacing!==t&&(U.i(t,"number",TreeLayout,"rowSpacing"),this.Y.rowSpacing=t,this.b())}get rowIndent(){return this.Y.rowIndent}set rowIndent(t){this.Y.rowIndent!==t&&(U.i(t,"number",TreeLayout,"rowIndent"),t>=0&&(this.Y.rowIndent=t,this.b()))}get commentSpacing(){return this.Y.commentSpacing}set commentSpacing(t){this.Y.commentSpacing!==t&&(U.i(t,"number",TreeLayout,"commentSpacing"),this.Y.commentSpacing=t,this.b())}get commentMargin(){return this.Y.commentMargin}set commentMargin(t){this.Y.commentMargin!==t&&(U.i(t,"number",TreeLayout,"commentMargin"),this.Y.commentMargin=t,this.b())}get setsPortSpot(){return this.Y.setsPortSpot}set setsPortSpot(t){this.Y.setsPortSpot!==t&&(U.i(t,"boolean",TreeLayout,"setsPortSpot"),this.Y.setsPortSpot=t,this.b())}get portSpot(){return this.Y.portSpot}set portSpot(t){U.s(t,Spot,TreeLayout,"portSpot"),this.Y.portSpot.equals(t)||(this.Y.portSpot=t,this.b())}get setsChildPortSpot(){return this.Y.setsChildPortSpot}set setsChildPortSpot(t){this.Y.setsChildPortSpot!==t&&(U.i(t,"boolean",TreeLayout,"setsChildPortSpot"),this.Y.setsChildPortSpot=t,this.b())}get childPortSpot(){return this.Y.childPortSpot}set childPortSpot(t){U.s(t,Spot,TreeLayout,"childPortSpot"),this.Y.childPortSpot.equals(t)||(this.Y.childPortSpot=t,this.b())}get alternateSorting(){return this.K.sorting}set alternateSorting(t){this.K.sorting!==t&&(U.W(t,TreeSorting,"TreeSorting"),this.K.sorting=t,this.b())}get alternateComparer(){return this.K.comparer}set alternateComparer(t){this.K.comparer!==t&&(U.C(t,TreeLayout,"alternateComparer"),this.K.comparer=t,this.b())}get alternateAngle(){return this.K.angle}set alternateAngle(t){this.K.angle!==t&&(U.i(t,"number",TreeLayout,"alternateAngle"),(t===0||t===90||t===180||t===270)&&(this.K.angle=t,this.b()))}get alternateAlignment(){return this.K.alignment}set alternateAlignment(t){this.K.alignment!==t&&(U.W(t,TreeAlignment,"TreeAlignment"),this.K.alignment=t,this.b())}get alternateNodeIndent(){return this.K.nodeIndent}set alternateNodeIndent(t){this.K.nodeIndent!==t&&(U.i(t,"number",TreeLayout,"alternateNodeIndent"),t>=0&&(this.K.nodeIndent=t,this.b()))}get alternateNodeIndentPastParent(){return this.K.nodeIndentPastParent}set alternateNodeIndentPastParent(t){this.K.nodeIndentPastParent!==t&&(U.i(t,"number",TreeLayout,"alternateNodeIndentPastParent"),t>=0&&t<=1&&(this.K.nodeIndentPastParent=t,this.b()))}get alternateNodeSpacing(){return this.K.nodeSpacing}set alternateNodeSpacing(t){this.K.nodeSpacing!==t&&(U.i(t,"number",TreeLayout,"alternateNodeSpacing"),this.K.nodeSpacing=t,this.b())}get alternateLayerSpacing(){return this.K.layerSpacing}set alternateLayerSpacing(t){this.K.layerSpacing!==t&&(U.i(t,"number",TreeLayout,"alternateLayerSpacing"),this.K.layerSpacing=t,this.b())}get alternateLayerSpacingParentOverlap(){return this.K.layerSpacingParentOverlap}set alternateLayerSpacingParentOverlap(t){this.K.layerSpacingParentOverlap!==t&&(U.i(t,"number",TreeLayout,"alternateLayerSpacingParentOverlap"),t>=0&&t<=1&&(this.K.layerSpacingParentOverlap=t,this.b()))}get alternateCompaction(){return this.K.compaction}set alternateCompaction(t){this.K.compaction!==t&&(U.W(t,TreeCompaction,"TreeCompaction"),(t===30||t===31)&&(this.K.compaction=t,this.b()))}get alternateBreadthLimit(){return this.K.breadthLimit}set alternateBreadthLimit(t){this.K.breadthLimit!==t&&(U.i(t,"number",TreeLayout,"alternateBreadthLimit"),t>=0&&(this.K.breadthLimit=t,this.b()))}get alternateRowSpacing(){return this.K.rowSpacing}set alternateRowSpacing(t){this.K.rowSpacing!==t&&(U.i(t,"number",TreeLayout,"alternateRowSpacing"),this.K.rowSpacing=t,this.b())}get alternateRowIndent(){return this.K.rowIndent}set alternateRowIndent(t){this.K.rowIndent!==t&&(U.i(t,"number",TreeLayout,"alternateRowIndent"),t>=0&&(this.K.rowIndent=t,this.b()))}get alternateCommentSpacing(){return this.K.commentSpacing}set alternateCommentSpacing(t){this.K.commentSpacing!==t&&(U.i(t,"number",TreeLayout,"alternateCommentSpacing"),this.K.commentSpacing=t,this.b())}get alternateCommentMargin(){return this.K.commentMargin}set alternateCommentMargin(t){this.K.commentMargin!==t&&(U.i(t,"number",TreeLayout,"alternateCommentMargin"),this.K.commentMargin=t,this.b())}get alternateSetsPortSpot(){return this.K.setsPortSpot}set alternateSetsPortSpot(t){this.K.setsPortSpot!==t&&(U.i(t,"boolean",TreeLayout,"alternateSetsPortSpot"),this.K.setsPortSpot=t,this.b())}get alternatePortSpot(){return this.K.portSpot}set alternatePortSpot(t){U.s(t,Spot,TreeLayout,"alternatePortSpot"),this.K.portSpot.equals(t)||(this.K.portSpot=t,this.b())}get alternateSetsChildPortSpot(){return this.K.setsChildPortSpot}set alternateSetsChildPortSpot(t){this.K.setsChildPortSpot!==t&&(U.i(t,"boolean",TreeLayout,"alternateSetsChildPortSpot"),this.K.setsChildPortSpot=t,this.b())}get alternateChildPortSpot(){return this.K.childPortSpot}set alternateChildPortSpot(t){U.s(t,Spot,TreeLayout,"alternateChildPortSpot"),this.K.childPortSpot.equals(t)||(this.K.childPortSpot=t,this.b())}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{X;bt;dt;Pk;Mk;Nk;Ck;Ak;Tk;Lk;qe;sm;nm;Ce;Ae;vt;pi;Vw;zw;Xw;Ks;Yw;Kw;Uw;Gw;qw;Hw;vw;Ww;jw;Jw;$w;constructor(t){super(t),this.Pk=!1,this.Mk=null,this.Nk=[],this.Ck=0,this.Ak=0,this.Tk=0,this.Lk=0,this.qe=null,this.X=new Point(0,0),this.bt=new Size(0,0),this.dt=new Point(0,0),this.sm=null,this.nm=null,this.Ce=10,this.Ae=LayoutVertex.standardComparer,this.vt=0,this.pi=21,this.Vw=0,this.zw=0,this.Xw=20,this.Ks=50,this.Yw=0,this.Kw=31,this.Uw=0,this.Gw=25,this.qw=10,this.Hw=10,this.vw=20,this.Ww=!0,this.jw=Spot.Default,this.Jw=!0,this.$w=Spot.Default}copyInheritedPropertiesFrom(t){t!==null&&(this.Ce=t.sorting,this.Ae=t.comparer,this.vt=t.angle,this.pi=t.alignment,this.Vw=t.nodeIndent,this.zw=t.nodeIndentPastParent,this.Xw=t.nodeSpacing,this.Ks=t.layerSpacing,this.Yw=t.layerSpacingParentOverlap,this.Kw=t.compaction,this.Uw=t.breadthLimit,this.Gw=t.rowSpacing,this.qw=t.rowIndent,this.Hw=t.commentSpacing,this.vw=t.commentMargin,this.Ww=t.setsPortSpot,this.jw=t.portSpot,this.Jw=t.setsChildPortSpot,this.$w=t.childPortSpot)}get initialized(){return this.Pk}set initialized(t){this.Pk!==t&&(U.i(t,"boolean",TreeVertex,"initialized"),this.Pk=t)}get parent(){return this.Mk}set parent(t){this.Mk!==t&&(Debug&&t!==null&&U.s(t,TreeVertex,TreeVertex,"parent"),this.Mk=t)}get children(){return this.Nk}set children(t){if(this.Nk!==t){if(t!==null&&!Array.isArray(t)&&U.Ti(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(c=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.om&&(this.om=i,this.Ik==="system"&&this.updateDiagrams())};constructor(t){t&&Object.assign(this,t),t?.themeMap||(this.Mu.set("light",{colors:{...Themes.Light.colors},fonts:{...Themes.Light.fonts},numbers:{...Themes.Light.numbers},margins:{...Themes.Light.margins},arrowheads:{...Themes.Light.arrowheads}}),this.Mu.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.om=root.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light")}get themeMap(){return this.Mu}set themeMap(t){this.Mu!==t&&(this.Mu=t,this.updateDiagrams())}get defaultTheme(){return this.Fk}set defaultTheme(t){this.Fk!==t&&(U.i(t,"string",ThemeManager,"defaultTheme"),this.Fk=t,this.updateDiagrams())}get currentTheme(){return this.Ik}set currentTheme(t){this.Ik!==t&&(U.i(t,"string",ThemeManager,"currentTheme"),this.Ik=t,this.updateDiagrams())}get changesDivBackground(){return this.Rk}set changesDivBackground(t){if(this.Rk!==t&&(this.Rk=t,t))for(const e of this.ds)e.setDivBackground(this.findValue("div","","fill")),e.F("ThemeChanged",this)}get readsCssVariables(){return this.FA}set readsCssVariables(t){this.FA!==t&&(this.FA=t,this.updateDiagrams())}get preferredColorScheme(){return this.om}addDiagram(t){return this.ds.add(t),this.IA(t),this}removeDiagram(t){return this.ds.delete(t),this.IA(t),this}hO(){this.ds.size===0&&root.matchMedia&&root.matchMedia("(prefers-color-scheme: dark)")?.addEventListener("change",this.vI)}aO(){this.ds.size===0&&root.matchMedia&&root.matchMedia("(prefers-color-scheme: dark)")?.removeEventListener("change",this.vI)}set(t,i){t===""&&(t=this.Fk),t==="system"&&(t=this.om);let e=this.Mu.get(t);return e?e=this.WI(e,i):e=i,this.Mu.set(t,e),this.updateDiagrams(),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 a=0;a{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.TB.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.om:t)}updateDiagrams(){for(const t of this.ds)this.IA(t)}IA(t){const i=t.skipsUndoManager;t.skipsUndoManager=!0,t.updateAllThemeBindings(),this.Rk&&t.setDivBackground(this.findValue("div","","fill")),t.skipsUndoManager=i,t.F("ThemeChanged",this)}WI(t,i){for(const e in i)if(U.Zw(i,e))try{i[e]?.constructor===Object?t[e]=this.WI(t[e]??{},i[e]):t[e]=i[e]}catch{delete t[e]}return t}static TB=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{At;f;Gi;Cl;constructor(){this.f=Diagram.Xm(),this.At="",this.Gi=!0,this.Cl=!0}get name(){return this.At}set name(t){this.At=t}get isEnabled(){return this.Gi}set isEnabled(t){this.Gi=t}get isRealtime(){return this.Cl}set isRealtime(t){this.Cl=t}get diagram(){return this.f}set diagram(t){this.f!==t&&(this.f=t,t.Bl=!0,t.requestUpdate())}invalidateRouter(){this.f!==null&&(this.f.Bl=!0,this.f.requestUpdate())}canRoute(t){if(!this.isEnabled)return!1;const i=this.diagram;return!(i&&(!this.isRealtime&&i.Yu||i.animationManager.isTicking))}isRoutable(t,i){return!0}routeLinks(t,i){}toString(){return this.name!==""?this.name+" Router":U.Jn(this.constructor)}}class AvoidsNodesRouter extends Router{constructor(t){super(),this.name="AvoidsNodes",t&&Object.assign(this,t)}canRoute(t){return(t instanceof Diagram?t.d0:t.diagram?.d0)?super.canRoute(t):!1}isRoutable(t,i){return!(!t.isAvoiding||t.containingGroup!==(i instanceof Group?i:null)||t.toNode===null||t.fromNode===null||t.pointsCount<4)}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(!this.isRoutable(o,i))continue;o.startRoute();const r=o.pointsCount,l=o.getPoint(1),h=o.getPoint(r-2),a=o.fromNode.actualBounds.copy();a.inflate(Link.zh,Link.zh),a.unionPoint(o.getPoint(0));const f=o.toNode.actualBounds.copy();f.inflate(Link.zh,Link.zh),f.unionPoint(o.getPoint(r-1)),this.LB(o,a,f,n)&&this.DB(o,l,o.LC,h,o.DC,a,f,n),o.commitRoute()}}LB(t,i,e,s){const n=t.diagram,o=t.pointsCount;if(n===null||!t.fromNode||!t.toNode||t.fromNode===t.toNode||!t.layer||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 f=2;f=PositionArray.ag&&(l.EL(),d.inflate(l.cellWidth*l.G2,l.cellHeight*l.q2),l.MF(i,e,s,n,d,!1),m=l.Po(s.x,s.y)),!l.ow&&mPositionArray.cf&&i.Po(g,p)!==u-1&&(i.Po(d-f,m)===u-1?(n=180,g=d-f,p=m):i.Po(d+f,m)===u-1?(n=0,g=d+f,p=m):i.Po(d,m-c)===u-1?(n=270,g=d,p=m-c):i.Po(d,m+c)===u-1&&(n=90,g=d,p=m+c));u>PositionArray.cf&&i.Po(g,p)===u-1;)d=g,m=p,n===0?g+=f:n===90?p+=c:n===180?g-=f:p-=c,u-=1;if(o?u>PositionArray.cf&&(n===180||n===0?d=Math.floor(d/f)*f+f/2:(n===90||n===270)&&(m=Math.floor(m/c)*c+c/2)):(d=Math.floor(d/f)*f+f/2,m=Math.floor(m/c)*c+c/2),u>PositionArray.cf){let y=n,x=d,b=m;if(n===0?(y=90,b+=c):n===90?(y=180,x-=f):n===180?(y=270,b-=c):n===270&&(y=0,x+=f),i.Po(x,b)===u-1)this.RA(t,i,x,b,y,!1);else{let k=d,P=m;n===0?(y=270,P-=c):n===90?(y=0,k+=f):n===180?(y=90,P+=c):n===270&&(y=180,k-=f),i.Po(k,P)===u-1&&this.RA(t,i,k,P,y,!1)}}t.insertPointAt(t.pointsCount-2,d,m)}}ToolManager.prototype.initializeStandardTools=function(){return this.ti("Action",new ActionTool,this.mouseDownTools),this.ti("Relinking",new RelinkingTool,this.mouseDownTools),this.ti("LinkReshaping",new LinkReshapingTool,this.mouseDownTools),this.ti("Rotating",new RotatingTool,this.mouseDownTools),this.ti("Resizing",new ResizingTool,this.mouseDownTools),this.ti("Linking",new LinkingTool,this.mouseMoveTools),this.ti("Dragging",new DraggingTool,this.mouseMoveTools),this.ti("DragSelecting",new DragSelectingTool,this.mouseMoveTools),this.ti("Panning",new PanningTool,this.mouseMoveTools),this.ti("ContextMenu",new ContextMenuTool,this.mouseUpTools),this.ti("TextEditing",new TextEditingTool,this.mouseUpTools),this.ti("ClickCreating",new ClickCreatingTool,this.mouseUpTools),this.ti("ClickSelecting",new ClickSelectingTool,this.mouseUpTools),this},Diagram.P2("GraphLinksModel",GraphLinksPartManager),Diagram.P2("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 w in go){const t=go[w];U.ht(t)&&t!==TextFormat&&(t.className=w)}U.it(oldGo)&&oldGo.version&&U.ot("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,go.Debug=Debug,Debug.attachReadonlyWarnings(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);