ruru
Version:
Grafast-flavoured GraphiQL distribution
2 lines • 118 kB
JavaScript
export const __webpack_esm_id__=6869;export const __webpack_esm_ids__=[6869];export const __webpack_esm_modules__={86869(t,e,n){n.r(e),n.d(e,{render:()=>Gn});var o=n(79528),r=(n(75972),n(41298)),s=(n(6342),n(51752),n(48550),n(77948),n(56350),n(70848),n(39989),n(27166)),a=n(79456),i=1e-5,c=1e-6;function f(t){const e=[];for(let n=0;n<t.length-1;n++)e.push({a:t[n],b:t[n+1]});return e}function d(t,e,n,o){const r=e.x-t.x,s=e.y-t.y,a=o.x-n.x,i=o.y-n.y,f=r*i-s*a;if(0===f)return null;const d=n.x-t.x,l=n.y-t.y,u=(d*i-l*a)/f,h=(d*s-l*r)/f;return u<=c||u>=.999999||h<=c||h>=.999999?null:{point:{x:t.x+u*r,y:t.y+u*s},tA:u,tB:h}}function l(t){return Math.abs(t.b.x-t.a.x)>=Math.abs(t.b.y-t.a.y)}function u(t){const e=[];for(let n=0;n<t.length;n++){const o=t[n],r=f(o.points);for(let s=n+1;s<t.length;s++){const n=t[s],a=f(n.points);for(const[t,s]of r.entries())for(const[r,i]of a.entries()){const a=d(s.a,s.b,i.a,i.b);if(!a)continue;const c=l(s);c!==l(i)&&c?e.push({jumpEdgeId:o.id,otherEdgeId:n.id,segIndex:t,t:a.tA,point:a.point}):e.push({jumpEdgeId:n.id,otherEdgeId:o.id,segIndex:r,t:a.tB,point:a.point})}}}return e}function h(t){const e=Math.round(1e3*t)/1e3;return Number.isInteger(e),`${e}`}function m(t){return`${h(t.x)},${h(t.y)}`}function g(t){const e=t.b.x-t.a.x,n=t.b.y-t.a.y;return Math.abs(e)>=Math.abs(n)?e>=0?1:0:n>=0?1:0}function p(t,e){if(t.length<2)return t.map(t=>({...t}));const n=t.map(t=>({...t})),o=e.arrowTypeStart&&r.markerOffsets[e.arrowTypeStart];if(o){const e=t[0],r=t[1],s=Math.atan2(r.y-e.y,r.x-e.x);n[0].x=e.x+o*Math.cos(s),n[0].y=e.y+o*Math.sin(s)}const s=e.arrowTypeEnd&&r.markerOffsets[e.arrowTypeEnd];if(s){const e=t.length,o=t[e-2],r=t[e-1],a=Math.atan2(r.y-o.y,r.x-o.x);n[e-1].x=r.x-s*Math.cos(a),n[e-1].y=r.y-s*Math.sin(a)}return n}function x(t,e,n,o,r){const s=t.point.x,a=t.point.y,i={x:s-e*t.r,y:a-n*t.r},c={x:s+e*t.r,y:a+n*t.r},f=[`L${m(i)}`];return"arc"===r?f.push(`A${h(t.r)},${h(t.r)} 0 0 ${o} ${m(c)}`):f.push(`M${m(c)}`),f}function y(t,e,n,o){const r=e.x-t.x,s=e.y-t.y,a=n.x-e.x,c=n.y-e.y,f=Math.hypot(r,s),d=Math.hypot(a,c);if(f<i||d<i)return null;const l=r/f,u=s/f,h=a/d,m=c/d,g=l*h+u*m,p=Math.max(-1,Math.min(1,g)),x=Math.acos(p);if(x<i||Math.abs(Math.PI-x)<i)return null;const y=Math.min(o/Math.sin(x/2),f/2,d/2);return{startX:e.x-l*y,startY:e.y-u*y,endX:e.x+h*y,endY:e.y+m*y,ctrlX:e.x,ctrlY:e.y,cutLen:y}}function _(t,e,n){const o=t.points;if(o.length<2)return"";const r=p(o,t),s="rounded"===t.curve,a=f(r),i=new Map;for(const t of e){const e=a[t.segIndex];if(!e)continue;const o=Math.hypot(e.b.x-e.a.x,e.b.y-e.a.y),r=i.get(t.segIndex)??[];r.push({t:t.t,point:t.point,d:t.t*o,r:n.jumpRadius}),i.set(t.segIndex,r)}const c=[`M${m(r[0])}`];for(let t=0;t<a.length;t++){const e=a[t],o=Math.hypot(e.b.x-e.a.x,e.b.y-e.a.y),f=0===o?0:(e.b.x-e.a.x)/o,d=0===o?0:(e.b.y-e.a.y)/o,l=g(e);let u=0;if(s&&t>0){const e=y(r[t-1],r[t],r[t+1]??r[t],5);e&&(u=e.cutLen)}let p=o,_=null;s&&t<a.length-1&&(_=y(r[t],r[t+1],r[t+2]??r[t+1],5),_&&(p=o-_.cutLen));const b=[...i.get(t)??[]].sort((t,e)=>t.t-e.t);for(const t of b)t.r=Math.min(t.r,t.d-u,p-t.d);for(let t=0;t<b.length-1;t++){const e=b[t+1].d-b[t].d;if(b[t].r+b[t+1].r>e){const n=e/2;b[t].r=Math.min(b[t].r,n),b[t+1].r=Math.min(b[t+1].r,n)}}for(const t of b)t.r<.001||c.push(...x(t,f,d,l,n.jumpStyle));s&&_?(c.push(`L${h(_.startX)},${h(_.startY)}`),c.push(`Q${h(_.ctrlX)},${h(_.ctrlY)} ${h(_.endX)},${h(_.endY)}`)):c.push(`L${m(e.b)}`)}return c.join(" ")}function b(t){return/^[\d\s+,.LMelm-]*$/.test(t)}function M(t){return!t||"linear"===t||"rounded"===t||"step"===t||"stepBefore"===t||"stepAfter"===t}function I(t){if(!t)return null;try{const e="function"==typeof atob?atob(t):Buffer.from(t,"base64").toString(),n=JSON.parse(e);if(!Array.isArray(n))return null;const o=[];for(const t of n)t&&"number"==typeof t.x&&"number"==typeof t.y&&o.push({x:t.x,y:t.y});return o.length>=2?o:null}catch{return null}}function S(t,e,n){if(!n.enabled)return;const o=t.node();if(!o)return;const r=new Map;for(const t of e)r.set(t.id,t);const s=[],a=new Map;for(const t of e){const e="undefined"!=typeof CSS&&CSS.escape?CSS.escape(t.id):t.id,n=o.querySelector(`path[data-id="${e}"]`);if(!n)continue;a.set(t.id,n);const r=I(n.getAttribute("data-points"))??t.points;s.push({...t,points:r})}const i=u(s);if(0===i.length)return;const c=new Map;for(const t of i){const e=c.get(t.jumpEdgeId)??[];e.push(t),c.set(t.jumpEdgeId,e)}for(const t of s){const e=c.get(t.id);if(!e||0===e.length)continue;const o=r.get(t.id),s=o?.curve;if(void 0!==s&&!M(s))continue;const i=a.get(t.id);if(!i)continue;if(void 0===s&&!b(i.getAttribute("d")??""))continue;const f=i.getAttribute("style")??"",d=/stroke-dasharray\s*:\s*0\s+([\d.]+)\s+[\d.]+\s+([\d.]+)/.exec(f),l=d?Number.parseFloat(d[1]):null,u=d?Number.parseFloat(d[2]):null,h=_(t,e,n);if(i.setAttribute("d",h),null!==l&&null!==u&&"function"==typeof i.getTotalLength){const t=i.getTotalLength(),e=`0 ${l} ${Math.max(0,t-l-u)} ${u}`,n=f.replace(/stroke-dasharray\s*:[^;]*;?/g,`stroke-dasharray: ${e};`).replace(/;\s*;+/g,";");i.setAttribute("style",n)}}}function w(t,{measure:e}){const n=t.config?.swimlane?.lineHops;if(!1===n)return;const o="gap"===n?"gap":"arc",r=t.edges.filter(t=>Array.isArray(t.points)&&t.points.length>=2).map(t=>({id:t.id,points:t.points,curve:t.curve,arrowTypeStart:t.arrowTypeStart,arrowTypeEnd:t.arrowTypeEnd}));S(e.groups.edgePaths,r,{enabled:!0,jumpRadius:6,jumpStyle:o})}(0,a.__name)(f,"buildSegmentList"),(0,a.__name)(d,"segmentIntersection"),(0,a.__name)(l,"isHorizontalSeg"),(0,a.__name)(u,"findEdgeIntersections"),(0,a.__name)(h,"fmt"),(0,a.__name)(m,"pointToString"),(0,a.__name)(g,"getArcSweepFlag"),(0,a.__name)(p,"applyMarkerOffsets"),(0,a.__name)(x,"emitJump"),(0,a.__name)(y,"computeRoundedCorner"),(0,a.__name)(_,"rewriteEdgePath"),(0,a.__name)(b,"isStraightPath"),(0,a.__name)(M,"curveSupportsLineHops"),(0,a.__name)(I,"decodeDataPoints"),(0,a.__name)(S,"applyLineJumpsToSvg"),(0,a.__name)(w,"applySwimlaneLineJumps");var v="__swimlane_default__";function C(t){return Math.max(t.padding??20,20)}function L(t){const{x:e,y:n,width:o,height:r}=t,s=t.swimlaneContentTop;if("number"!=typeof e||"number"!=typeof n||"number"!=typeof o||"number"!=typeof r||"number"!=typeof s||!Number.isFinite(e)||!Number.isFinite(n)||!Number.isFinite(o)||!Number.isFinite(r)||!Number.isFinite(s)||o<=0||r<=0)return void delete t.groupTitleRect;const a=n-r/2,i=Math.min(s,n+r/2),c=a+Math.min(21,Math.max(0,i-a));c<=a?delete t.groupTitleRect:t.groupTitleRect={left:e-o/2,right:e+o/2,top:a,bottom:c}}function k(t){const e=t.direction,n=t.nodes??=[];for(const n of t.nodes??[])n.isGroup&&!n.parentId&&(n.shape="swimlane",e&&(n.direction=e));const o=n.filter(t=>!t.isGroup&&!t.parentId);if(0===o.length)return;let r=n.find(t=>t.id===v);r?r.isGroup&&(r.shape="swimlane",e&&(r.direction=e)):(r={id:v,label:"",isGroup:!0,shape:"swimlane",padding:20,...e?{direction:e}:{}},n.push(r));for(const t of o)t.parentId=v}function O(t){const e=new Map;for(const n of t.nodes??[])e.set(n.id,n);const n=[];for(const e of t.edges??[]){const t="string"==typeof e.start?e.start:void 0,o="string"==typeof e.end?e.end:void 0;t&&o&&(e.labelNodeId||n.push({id:e.id,src:t,dst:o,ref:e}))}const o=t.nodes??[],r=o.filter(t=>t.isGroup),s=o.filter(t=>!t.isGroup);return{nodes:[...[...r].reverse(),...s].map(t=>t.id),edges:n,layout:t,nodeById:e}}function R(t,e,n,o){const{layout:r}=t,s=t.nodeById,a=o?.layerGap??100,i=o?.nodeGap??40;let c=0;for(const t of e.layers){let e=0;for(const o of t){const t=s.get(o);if(!t){e++;continue}t.layer=c,t.order=e;const r=n.x[o]??e*i,f=n.y[o]??c*a;t.x=r,t.y=f,e++}c++}const f=r.nodes??[],d=new Map,l=[];for(const t of f){if(!t?.isGroup)continue;t.parentId||l.push(t);const e=f.filter(e=>e.parentId===t.id);let o=1/0,r=-1/0,s=1/0,a=-1/0;for(const t of e){const e=t.x??n.x[t.id],i=t.y??n.y[t.id],c=t.width??0,f=t.height??0;null!=e&&null!=i&&(o=Math.min(o,e-c/2),r=Math.max(r,e+c/2),s=Math.min(s,i-f/2),a=Math.max(a,i+f/2))}if(o===1/0||s===1/0)t.x=t.x??0,t.y=t.y??0,t.width=t.width??0,t.height=t.height??0;else{const e=t.padding??20,n=t.parentId?e:2*C(t),i=e,c=Math.max(0,r-o)+n,f=Math.max(0,a-s)+i,l=(o+r)/2,u=(s+a)/2;t.x=l,t.y=u,t.width=c,t.height=f,d.set(t.id,{minX:o,maxX:r,minY:s,maxY:a})}}if(l.length>0&&d.size>0){let t=1/0,e=-1/0,n=0;for(const o of l){const r=o.padding??20;r>n&&(n=r);const s=d.get(o.id);s&&(t=Math.min(t,s.minY),e=Math.max(e,s.maxY))}if(t!==1/0&&e!==-1/0){const o=36,r=Math.max(0,e-t)+2*Math.max(n,o),s=(t+e)/2;for(const e of l)e.y=s,e.height=r,e.swimlaneContentTop=t;const a=[...l].sort((t,e)=>(t.x??0)-(e.x??0)),i=[],c=[],f=[];for(const t of a){const e=d.get(t.id);if(!e)continue;const n=Math.max(0,e.maxX-e.minX)+2*C(t),o=(e.minX+e.maxX)/2;i.push(t.id),c.push(o),f.push(n)}const u=i.length;if(u>0){const t=new Map;if(1===u)t.set(i[0],f[0]);else{const e=[];for(let t=0;t<u-1;t++)e.push(c[t+1]-c[t]);const n=new Array(u);n[0]=0;for(let t=0;t<u-1;t++)n[t+1]=2*e[t]-n[t];let o=0,r=Number.POSITIVE_INFINITY;for(let t=0;t<u;t++){const e=f[t];t%2==0?o=Math.max(o,e-n[t]):r=Math.min(r,n[t]-e)}let s=o;s=o<=r?(o+r)/2:o;for(let e=0;e<u;e++){const o=n[e]+(e%2==0?s:-s),r=Math.max(f[e],o);t.set(i[e],r)}}for(const e of l){const n=t.get(e.id);null!=n&&(e.width=n),L(e)}}}}}function T(t){const e=[],n=[],o=new Map;for(const e of t.nodes)o.set(e.id,e);for(const r of t.edges){if(!r.label||0===r.label.length)continue;if(r.isLayoutOnly)continue;if(r.labelNodeId)continue;const t=r.start?o.get(r.start):void 0,a=r.end?o.get(r.end):void 0;if(!t||!a){s.log.warn("[EdgeLabelNodes]",`Edge ${r.id} has missing source or target node`);continue}const i=`edge-label-${r.start}-${r.end}-${r.id}`,c=t.parentId!==a.parentId?a.parentId:t.parentId,f={id:i,label:r.label,edgeStart:r.start??"",edgeEnd:r.end??"",shape:"labelRect",width:0,height:0,isEdgeLabel:!0,isDummy:!0,parentId:c,isGroup:!1,labelStyle:Array.isArray(r.labelStyle)?r.labelStyle[0]:r.labelStyle??"",...t.dir?{dir:t.dir}:{}};e.push(f),r.labelNodeId=i,r.label=void 0,r.text=void 0;const d={id:`${r.id}-to-label`,start:r.start,end:i,type:"normal",isLayoutOnly:!0},l={id:`${r.id}-from-label`,start:i,end:r.end,type:"normal",isLayoutOnly:!0};n.push(d,l)}const r=[...t.nodes,...e],a=[...t.edges,...n];return{...t,nodes:r,edges:a}}(0,a.__name)(C,"topLaneHorizontalPadding"),(0,a.__name)(L,"assignTopLaneTitleRect"),(0,a.__name)(k,"prepareLayoutForSwimlanes"),(0,a.__name)(O,"toGraphView"),(0,a.__name)(R,"writeBackToLayoutData"),(0,a.__name)(T,"createEdgeLabelNodes");var $=.001;function N(t){const e=t.x??0,n=t.y??0,o=t.width??0,r=t.height??0;return o>0&&r>0?{cx:e,cy:n,rect:Q(e,n,o,r)}:void 0}function B(t){if(t.isGroup)return;const e=N(t);return e?{id:String(t.id??""),cx:e.cx,cy:e.cy,rect:e.rect}:void 0}function F(t,e,n=$){return Math.abs(t.x-e.x)<n&&Math.abs(t.y-e.y)<n}function E(t,e,n=$){return Math.abs(t.x-e.x)<n}function Y(t,e,n=$){return Math.abs(t.y-e.y)<n}function X(t,e,n=$){return Y(t,e,n)&&Math.abs(t.x-e.x)>n}function z(t,e,n=$){return E(t,e,n)&&Math.abs(t.y-e.y)>n}function A(t,e,n,o){return Math.max(0,Math.min(Math.max(t,e),Math.max(n,o))-Math.max(Math.min(t,e),Math.min(n,o)))}function P(t,e,n=$){return t.horizontal&&e.horizontal&&Y(t.a,e.a,n)?A(t.a.x,t.b.x,e.a.x,e.b.x):t.vertical&&e.vertical&&E(t.a,e.a,n)?A(t.a.y,t.b.y,e.a.y,e.b.y):0}function D(t,e=$){const n=[];for(let o=0;o<t.length-1;o++){const r=t[o],s=t[o+1],a=X(r,s,e),i=z(r,s,e);(a||i)&&n.push({index:o,a:r,b:s,horizontal:a,vertical:i})}return n}function G(t,e=$){const n=D(t,e);let o=0;for(let t=1;t<n.length;t++)n[t-1].horizontal!==n[t].horizontal&&o++;return o}function H(t,e=$){const n=[];for(const o of t){const t=n.length>0?n[n.length-1]:void 0;t&&F(t,o,e)||n.push({x:o.x,y:o.y})}return n}function j(t,e=$){if(!t||4!==t.length)return;const[n,o,r,s]=t;return X(n,o,e)&&z(o,r,e)&&X(r,s,e)?{kind:"HVH",p0:n,p1:o,p2:r,p3:s}:z(n,o,e)&&X(o,r,e)&&z(r,s,e)?{kind:"VHV",p0:n,p1:o,p2:r,p3:s}:void 0}function V(t,e,n,o=0){const r=Math.min(t.x,e.x),s=Math.max(t.x,e.x),a=Math.min(t.y,e.y),i=Math.max(t.y,e.y);return s>n.left-o&&r<n.right+o&&i>n.top-o&&a<n.bottom+o}function W(t,e,n=0){return t.x>e.left+n&&t.x<e.right-n&&t.y>e.top+n&&t.y<e.bottom-n}function J(t,e){return t.left<=e.left&&t.right>=e.right&&t.top<=e.top&&t.bottom>=e.bottom}function q(t,e){return t.left<e.right&&t.right>e.left&&t.top<e.bottom&&t.bottom>e.top}function K(t,e){return{left:t.left-e,right:t.right+e,top:t.top-e,bottom:t.bottom+e}}function Q(t,e,n,o){return{left:t-n/2,right:t+n/2,top:e-o/2,bottom:e+o/2}}function U(t){return N(t)?.rect}function Z(t,e){switch(e){case"top":return{x:t.cx,y:t.rect.top};case"bottom":return{x:t.cx,y:t.rect.bottom};case"left":return{x:t.rect.left,y:t.cy};case"right":return{x:t.rect.right,y:t.cy}}}function tt(t,e,n,o,r,s=$){const a="left"===e||"right"===e,i="left"===o||"right"===o;if(a&&i){if("right"===e&&"left"===o&&t.x<n.x||"left"===e&&"right"===o&&t.x>n.x){if(Y(t,n,s))return[t,n];const e=(t.x+n.x)/2;return[t,{x:e,y:t.y},{x:e,y:n.y},n]}if(e===o){if(Y(t,n,s))return;const o="left"===e?Math.min(t.x,n.x)-r:Math.max(t.x,n.x)+r;return[t,{x:o,y:t.y},{x:o,y:n.y},n]}return}if(!a&&!i){if(e===o){if(E(t,n,s))return;const o="top"===e?Math.min(t.y,n.y)-r:Math.max(t.y,n.y)+r;return[t,{x:t.x,y:o},{x:n.x,y:o},n]}if(!("bottom"===e&&"top"===o&&t.y<n.y||"top"===e&&"bottom"===o&&t.y>n.y))return;if(E(t,n,s))return[t,n];const a=(t.y+n.y)/2;return[t,{x:t.x,y:a},{x:n.x,y:a},n]}if(a&&!i){const r="right"===e&&n.x>t.x||"left"===e&&n.x<t.x,s="top"===o&&t.y<n.y||"bottom"===o&&t.y>n.y;return r&&s?[t,{x:n.x,y:t.y},n]:void 0}const c="bottom"===e&&n.y>t.y||"top"===e&&n.y<t.y,f="left"===o&&t.x<n.x||"right"===o&&t.x>n.x;return c&&f?[t,{x:t.x,y:n.y},n]:void 0}function et(t,e,n,o){return"left"===e||"right"===e?[t,{x:o,y:t.y},{x:o,y:n.y},n]:[t,{x:t.x,y:o},{x:n.x,y:o},n]}function nt(t){const e=new Map,n=[];for(const o of t){if(o.isEdgeLabel)continue;const t=B(o);t&&(e.set(t.id,t),n.push({id:t.id,rect:t.rect}))}return{nodeInfoById:e,realNodeRects:n}}function ot(t){const e=[],n=[];for(const o of t){const t=B(o);if(!t)continue;const r={id:t.id,rect:t.rect};o.isEdgeLabel?n.push(r):e.push(r)}return{realNodeRects:e,labelNodeRects:n}}function rt(t,{includeEdgeLabels:e=!0}={}){const n=[];for(const o of t){if(o.isGroup||!e&&o.isEdgeLabel)continue;const t=o.x??0,r=o.y??0,s=o.width??0,a=o.height??0;n.push({nodeId:o.id,...Q(t,r,s,a)})}return n}function st(t,e,n=$){const o=t.start,r=t.end;if(!o||!r)return;const s=e.get(o),a=e.get(r);return s&&a?{srcId:o,dstId:r,srcInfo:s,dstInfo:a,collinearX:Math.abs(s.cx-a.cx)<n,collinearY:Math.abs(s.cy-a.cy)<n}:void 0}function at(t,e,n,o=[],r=0){for(const s of n)if(!o.includes(s.id)&&V(t,e,s.rect,-r))return!0;return!1}function it(t,e,n,o,r=$,s=1e-6){const a=Y(t,e,r),i=E(t,e,r),c=Y(n,o,r),f=E(n,o,r);if(a&&c||i&&f)return!1;if(!a&&!i||!c&&!f)return!1;const d=a?{a:t,b:e}:{a:n,b:o},l=i?{a:t,b:e}:{a:n,b:o},u=d.a.y,h=Math.min(d.a.x,d.b.x),m=Math.max(d.a.x,d.b.x),g=l.a.x,p=Math.min(l.a.y,l.b.y),x=Math.max(l.a.y,l.b.y);if(g<h||g>m||u<p||u>x)return!1;const y=Math.abs(g-d.a.x)<s&&Math.abs(u-d.a.y)<s||Math.abs(g-d.b.x)<s&&Math.abs(u-d.b.y)<s,_=Math.abs(g-l.a.x)<s&&Math.abs(u-l.a.y)<s||Math.abs(g-l.b.x)<s&&Math.abs(u-l.b.y)<s;return!(y&&_)}function ct(t,e,n,o,r=$){const s=Y(t,e,r),a=E(t,e,r),i=Y(n,o,r),c=E(n,o,r);return a&&c&&E(t,n,r)?A(t.y,e.y,n.y,o.y)>r:!!(s&&i&&Y(t,n,r))&&A(t.x,e.x,n.x,o.x)>r}function ft(t,e,n,o,{epsilon:r=$,skipDegenerateOther:s=!1}={}){for(const a of n){if(a===o||a.isLayoutOnly)continue;const n=a.points;if(n&&!(n.length<2))for(let o=0;o<n.length-1;o++){const a=n[o],i=n[o+1];if((!s||!F(a,i,r))&&(it(t,e,a,i,r)||ct(t,e,a,i,r)))return!0}}return!1}function dt(t,e,n,o,r=$){const s=Y(t,e,r),a=E(t,e,r),i=Y(n,o,r),c=E(n,o,r);if(!(s&&c||a&&i))return!1;const f=s?{a:t,b:e}:{a:n,b:o},d=s?{a:n,b:o}:{a:t,b:e},l=f.a.y,u=Math.min(f.a.x,f.b.x),h=Math.max(f.a.x,f.b.x),m=d.a.x,g=Math.min(d.a.y,d.b.y),p=Math.max(d.a.y,d.b.y);return m>u+r&&m<h-r&&l>g+r&&l<p-r}function lt(t,e,n){const o=Math.min(e,n),r=Math.max(e,n);return t>o+$&&t<r-$}function ut(t,e,n){return E(t,e)&&E(e,n)?lt(e.y,t.y,n.y):!(!Y(t,e)||!Y(e,n))&<(e.x,t.x,n.x)}function ht(t){let e=!1;const n=[];for(let o=0;o<t.length;o++){const r=n[n.length-1],s=t[o],a=o+1<t.length?t[o+1]:void 0;if(r&&a){if(F(r,a)){o++,e=!0;continue}if(ut(r,s,a)){e=!0;continue}}n.push(s)}return{points:n,changed:e}}function mt(t){const e=[t[0]];for(let n=1;n<t.length;n++){const o=e[e.length-1],r=t[n];if(!E(o,r)&&!Y(o,r)){const t=e.length>=2?e[e.length-2]:void 0,n=t&&E(t,o)?{x:o.x,y:r.y}:{x:r.x,y:o.y};e.push(n)}e.push(r)}const n=[];for(const t of e){const e=n[n.length-1];e&&F(e,t)||n.push(t)}return n}function gt(t){if(t.length<3)return t;let e=[...t];for(let t=0;t<32;t++){const t=ht(e);if(e=t.points,!t.changed)break}return e}(0,a.__name)(N,"measuredNodeRect"),(0,a.__name)(B,"nodeBoundsInfoFor"),(0,a.__name)(F,"samePoint"),(0,a.__name)(E,"sameX"),(0,a.__name)(Y,"sameY"),(0,a.__name)(X,"isHorizontalSegment"),(0,a.__name)(z,"isVerticalSegment"),(0,a.__name)(A,"overlapLength"),(0,a.__name)(P,"sameAxisSegmentOverlapLength"),(0,a.__name)(D,"orthogonalSegmentsForPoints"),(0,a.__name)(G,"countOrthogonalBends"),(0,a.__name)(H,"dedupeConsecutivePoints"),(0,a.__name)(j,"classifyThreeSegmentRoute"),(0,a.__name)(V,"segmentBoundsOverlapRect"),(0,a.__name)(W,"pointInsideRect"),(0,a.__name)(J,"rectContainsRect"),(0,a.__name)(q,"rectsOverlap"),(0,a.__name)(K,"inflateRect"),(0,a.__name)(Q,"rectFromCenterSize"),(0,a.__name)(U,"rectOfNodeBounds"),(0,a.__name)(Z,"portForRectSide"),(0,a.__name)(tt,"buildOrthogonalPortPath"),(0,a.__name)(et,"buildSameSideTrackPath"),(0,a.__name)(nt,"collectRealNodeBounds"),(0,a.__name)(ot,"collectNodeRectEntries"),(0,a.__name)(rt,"collectLayoutNodeRects"),(0,a.__name)(st,"getNodePairGeometry"),(0,a.__name)(at,"segmentHitsAnyRect"),(0,a.__name)(it,"orthogonalSegmentsCross"),(0,a.__name)(ct,"sameAxisSegmentsOverlap"),(0,a.__name)(ft,"segmentConflictsWithAnyEdge"),(0,a.__name)(dt,"orthogonalSegmentsStrictlyCross"),(0,a.__name)(lt,"strictlyBetween"),(0,a.__name)(ut,"isCollinearIntermediate"),(0,a.__name)(ht,"simplifyPolylineOnce"),(0,a.__name)(mt,"orthogonalizePolyline"),(0,a.__name)(gt,"simplifyPolyline");var pt=.001;function xt(t,e,n){const o=t;if(o.isLayoutOnly||!o.points||o.points.length<n)return;const r=o.start?e.get(o.start):void 0,s=o.end?e.get(o.end):void 0;return{edge:o,points:o.points,srcRect:r?U(r):void 0,dstRect:s?U(s):void 0}}function yt(t,e,n){if(Y(t,e,pt))return{x:t.x<n.left?n.left:n.right,y:t.y};if(E(t,e,pt)){const e=t.y<n.top?n.top:n.bottom;return{x:t.x,y:e}}return{x:Math.min(n.right,Math.max(n.left,t.x)),y:Math.min(n.bottom,Math.max(n.top,t.y))}}function _t(t,e,n){const o=n?1:-1;let r=n?0:t.length-1;for(;r>=0&&r<t.length&&W(t[r],e,.5);)r+=o;if(r<0||r>=t.length)return t;const s=r-o;if(s<0||s>=t.length)return t;const a=yt(t[r],t[s],e);return n?[a,...t.slice(r)]:[...t.slice(0,r+1),a]}function bt(t,e){for(const n of t){const t=xt(n,e,2);if(!t)continue;let o=[...t.points];t.srcRect&&(o=_t(o,t.srcRect,!0)),t.dstRect&&(o=_t(o,t.dstRect,!1)),o=gt(mt(o)),o=Tt(o,t.srcRect,t.dstRect),t.edge.points=gt(mt(o))}}function Mt(t,e,n,o=!1){if(Y(t,e,pt)){if(e.y<n.top-pt||e.y>n.bottom+pt)return e;if(o){if(t.x<n.left-pt)return{x:n.left,y:t.y};if(t.x>n.right+pt)return{x:n.right,y:t.y}}return{x:Math.abs(e.x-n.left)<=Math.abs(e.x-n.right)?n.left:n.right,y:t.y}}if(E(t,e,pt)){if(e.x<n.left-pt||e.x>n.right+pt)return e;if(o){if(t.y<n.top-pt)return{x:t.x,y:n.top};if(t.y>n.bottom+pt)return{x:t.x,y:n.bottom}}const r=Math.abs(e.y-n.top)<=Math.abs(e.y-n.bottom);return{x:t.x,y:r?n.top:n.bottom}}return e}function It(t,e,n){const o=t[e];for(let r=e+n;r>=0&&r<t.length;r+=n){const e=t[r];if(!F(e,o,pt))return e}return t[e+n]}function St(t,e){const n=t+4,o=e-4;return n<=o?{lo:n,hi:o}:{lo:(t+e)/2,hi:(t+e)/2}}function wt(t,e,n){const{lo:o,hi:r}=St(e,n);return Math.min(r,Math.max(o,t))}function vt(t){const e=Math.max(...t.map(t=>t.lo)),n=Math.min(...t.map(t=>t.hi));if(!(e>n))return{lo:e,hi:n}}function Ct(t,e){return"left"===e||"right"===e?St(t.top,t.bottom):St(t.left,t.right)}function Lt(t,e,n){const o=t.y>=n.top-pt&&t.y<=n.bottom+pt,r=t.x>=n.left-pt&&t.x<=n.right+pt;if(Y(t,e,pt)&&o){if(Math.abs(t.x-n.left)<pt)return"left";if(Math.abs(t.x-n.right)<pt)return"right"}if(E(t,e,pt)&&r){if(Math.abs(t.y-n.top)<pt)return"top";if(Math.abs(t.y-n.bottom)<pt)return"bottom"}}function kt(t){return"left"===t||"right"===t}function Ot(t,e,n,o,r){const s=[],a=n?Lt(t,e,n):void 0,i=o?Lt(e,t,o):void 0;return n&&a&&kt(a)===r&&s.push(Ct(n,a)),o&&i&&kt(i)===r&&s.push(Ct(o,i)),s.length>0?vt(s):void 0}function Rt(t,e,n,o,r){const s=Ot(t,e,n,o,r);if(!s)return;const a=r?t.y:t.x,i=Math.min(s.hi,Math.max(s.lo,a));return Math.abs(i-a)<pt?void 0:r?[{x:t.x,y:i},{x:e.x,y:i}]:[{x:i,y:t.y},{x:i,y:e.y}]}function Tt(t,e,n){if(2!==t.length)return t;const[o,r]=t;return Y(o,r,pt)?Rt(o,r,e,n,!0)??t:E(o,r,pt)?Rt(o,r,e,n,!1)??t:t}function $t(t,e,n){return kt(n)?{x:t.x,y:wt(t.y,e.top,e.bottom)}:{x:wt(t.x,e.left,e.right),y:t.y}}function Nt(t,e,n,o,r,s){const a=t.map(t=>({...t}));for(let i=e;i>=0&&i<t.length;i+=n){const e=t[i];if(s&&!Y(e,o,pt))break;if(!s&&!E(e,o,pt))break;s?a[i].y=r.y:a[i].x=r.x}return a}function Bt(t,e,n){if(t.length<2)return t;const o=n?0:t.length-1,r=n?1:-1,s=t[o],a=It(t,o,r);if(!a)return t;const i=Lt(s,a,e);if(!i)return t;const c=kt(i),f=$t(s,e,i);return F(s,f,pt)?t:Nt(t,o,r,s,f,c)}function Ft(t,e,n){const o=Math.min(t.x,e.x)>=n.left-pt&&Math.max(t.x,e.x)<=n.right+pt,r=Math.min(t.y,e.y)>=n.top-pt&&Math.max(t.y,e.y)<=n.bottom+pt;return Math.abs(t.y-n.top)<pt&&Math.abs(e.y-n.top)<pt&&o?"top":Math.abs(t.y-n.bottom)<pt&&Math.abs(e.y-n.bottom)<pt&&o?"bottom":Math.abs(t.x-n.left)<pt&&Math.abs(e.x-n.left)<pt&&r?"left":Math.abs(t.x-n.right)<pt&&Math.abs(e.x-n.right)<pt&&r?"right":void 0}function Et(t,e,n,o){switch(t){case"top":return E(e,n,pt)&&n.y<o.top-pt;case"bottom":return E(e,n,pt)&&n.y>o.bottom+pt;case"left":return Y(e,n,pt)&&n.x<o.left-pt;case"right":return Y(e,n,pt)&&n.x>o.right+pt}}function Yt(t,e,n){if(t.length<3)return t;if(n){const n=Ft(t[0],t[1],e);return n&&Et(n,t[1],t[2],e)?t.slice(1):t}const o=t.length-1,r=Ft(t[o-1],t[o],e);return r&&Et(r,t[o-1],t[o-2],e)?t.slice(0,o):t}function Xt(t,e,n){let o=t;if(e){const t=It(o,0,1);if(t){const n=Mt(t,o[0],e);n!==o[0]&&(o=[n,...o.slice(1)])}o=Yt(o,e,!0)}if(n){const t=o.length-1,e=It(o,t,-1);if(e){const r=Mt(e,o[t],n,!0);r!==o[t]&&(o=[...o.slice(0,t),r])}o=Yt(o,n,!1)}const r=Tt(o,e,n);return r!==o||2===o.length?r:(e&&(o=Bt(o,e,!0)),n&&(o=Bt(o,n,!1)),o)}function zt(t,e){for(const n of t){const t=xt(n,e,2);if(!t)continue;const o=Xt(H(t.points,pt),t.srcRect,t.dstRect);if(o.length<3){t.edge.points=o;continue}const r=[o[0],{...o[0]},...o.slice(1,-1),o[o.length-1],{...o[o.length-1]}];t.edge.points=r}}function At(t){return new Map(t.map(t=>[t.id,t]))}function Pt(t,e){let n=t.parentId,o=null;for(;n;){const t=e.get(n);if(!t?.isGroup)break;o=t.id,n=t.parentId}return o}function Dt(t,e){let n=0,o=t.parentId;for(;o;){const t=e.get(o);if(!t?.isGroup)break;n++,o=t.parentId}return n}function Gt(t){let e=1/0,n=-1/0,o=1/0,r=-1/0;for(const s of t){const t=s.x,a=s.y;if("number"!=typeof t||"number"!=typeof a)continue;const i=s.width??0,c=s.height??0;e=Math.min(e,t-i/2),n=Math.max(n,t+i/2),o=Math.min(o,a-c/2),r=Math.max(r,a+c/2)}return e===1/0||o===1/0?null:{minX:e,maxX:n,minY:o,maxY:r}}function Ht(t,e){const n=t.padding??20;t.x=(e.minX+e.maxX)/2,t.y=(e.minY+e.maxY)/2,t.width=Math.max(0,e.maxX-e.minX)+n,t.height=Math.max(0,e.maxY-e.minY)+n}function jt(t){const e=At(t),n=t.filter(t=>t.isGroup&&t.parentId).sort((t,n)=>Dt(n,e)-Dt(t,e));for(const e of n){const n=Gt(t.filter(t=>t.parentId===e.id));n&&Ht(e,n)}}function Vt(t,e){const n=t.nodes??[],o=t.edges??[],r=n.filter(t=>!t.isGroup);let s=1/0,i=-1/0;for(const t of r){const n=t[e];"number"==typeof n&&(s=Math.min(s,n),i=Math.max(i,n))}if(!Number.isFinite(s)||!Number.isFinite(i))return!1;const c=(0,a.__name)(t=>s+i-t,"mirror");for(const t of n){const n=t[e];"number"==typeof n&&(t[e]=c(n));const o=t.groupTitleRect;o&&(t.groupTitleRect="x"===e?{...o,left:c(o.right),right:c(o.left)}:{...o,top:c(o.bottom),bottom:c(o.top)})}for(const t of o)for(const n of t.points??[])n[e]=c(n[e]);return!0}function Wt(t){return!(t.nodes??[]).some(t=>!t.isGroup)||Vt(t,"y")}function Jt(t,e="LR"){const n=t.nodes??[],o=t.edges??[],r=n.filter(t=>!t.isGroup);let s=1/0,a=1/0;for(const t of r){const e=t.x??0,n=t.y??0;e<s&&(s=e),n<a&&(a=n)}if(!Number.isFinite(s)||!Number.isFinite(a))return!1;const i=36;let c=0,f=0;for(const t of r)c+=t.width??0,f+=t.height??0;const d=c/r.length,l=f/r.length,u=l>0?Math.max(1,d/l):1;for(const t of r){const e=t.x??0,n=((t.y??0)-a)*u+i,o=e-s;t.x=n,t.y=o}for(const t of o)if(t.points)for(const e of t.points){const t=e.x,n=(e.y-a)*u+i,o=t-s;e.x=n,e.y=o}jt(n);const h=n.filter(t=>t.isGroup&&!t.parentId);if(0===h.length)return"RL"===e&&Vt(t,"x"),!0;const m=At(n),g=new Map;for(const t of n){if(t.isGroup)continue;const e=Pt(t,m);if(!e)continue;const n=g.get(e)??[];n.push(t),g.set(e,n)}let p=0;for(const t of h){const e=t.padding??0;e>p&&(p=e)}const x=[];let y=1/0,_=-1/0;for(const t of h){const e=Gt(g.get(t.id)??[]);e&&(y=Math.min(y,e.minX),_=Math.max(_,e.maxX),x.push({lane:t,contentTop:e.minY,contentBottom:e.maxY,centerY:(e.minY+e.maxY)/2}))}if(y===1/0||_===-1/0)return!0;const b=Math.max(0,_-y)+2*Math.max(p,10),M=i+b,I=(y+_)/2-b/2-i,S=I+M/2,w=Math.max(p,i);x.sort((t,e)=>t.centerY-e.centerY);for(let t=0;t<x.length;t++){const e=x[t];let n,o;if(n=0===t?e.contentTop-w:(x[t-1].contentBottom+e.contentTop)/2,t===x.length-1)o=e.contentBottom+w;else{const n=x[t+1];o=(e.contentBottom+n.contentTop)/2}const r=Math.max(0,o-n),s=(n+o)/2;e.lane.x=S,e.lane.y=s,e.lane.width=M,e.lane.height=r,e.lane.swimlaneContentTop=e.contentTop,e.lane.groupTitleRect={left:I,right:I+i,top:n,bottom:o}}return"RL"===e&&Vt(t,"x"),!0}(0,a.__name)(xt,"endpointContextFor"),(0,a.__name)(yt,"segmentEnterPoint"),(0,a.__name)(_t,"clipEndpoint"),(0,a.__name)(bt,"clipEdgeEndpointsToNodeBoundaries"),(0,a.__name)(Mt,"snapEndpointToBoundary"),(0,a.__name)(It,"firstDistinctAdjacent"),(0,a.__name)(St,"cornerClearanceRange"),(0,a.__name)(wt,"clampToCornerClearance"),(0,a.__name)(vt,"intersectRanges"),(0,a.__name)(Ct,"clearanceRangeForSide"),(0,a.__name)(Lt,"terminalSideForSegment"),(0,a.__name)(kt,"isHorizontalSide"),(0,a.__name)(Ot,"straightClearanceRange"),(0,a.__name)(Rt,"clearStraightEndpointCornerAxis"),(0,a.__name)(Tt,"clearStraightEndpointCornerConnections"),(0,a.__name)($t,"cornerClearedEndpoint"),(0,a.__name)(Nt,"moveCollinearEndpointRun"),(0,a.__name)(Bt,"clearEndpointCornerConnection"),(0,a.__name)(Ft,"borderSideForSegment"),(0,a.__name)(Et,"leavesOutward"),(0,a.__name)(Yt,"collapseOwnBorderStub"),(0,a.__name)(Xt,"snapAndCollapseEndpoints"),(0,a.__name)(zt,"prepareEdgeEndpointsForRenderer"),(0,a.__name)(At,"buildNodeMap"),(0,a.__name)(Pt,"resolveTopLevelGroupId"),(0,a.__name)(Dt,"groupDepth"),(0,a.__name)(Gt,"boundsForChildren"),(0,a.__name)(Ht,"applyGroupBounds"),(0,a.__name)(jt,"recomputeNestedGroupBounds"),(0,a.__name)(Vt,"mirrorAxis"),(0,a.__name)(Wt,"applyBtDirectionTransform"),(0,a.__name)(Jt,"applyLrDirectionTransform");var qt=1e-6,Kt=[0,8,-8,16,-16];function Qt(t,e){const{nodeInfoById:n,realNodeRects:o}=nt(e);for(const e of t){if(e.isLayoutOnly)continue;const r=e.points;if(!r||r.length<4)continue;const s=j(H(r,qt),qt);if(!s)continue;const{p3:a}=s,i="HVH"===s.kind,c=st(e,n,qt);if(!c)continue;const{srcId:f,dstId:d,srcInfo:l,dstInfo:u,collinearX:h,collinearY:m}=c;if(h||m)continue;let g;const p=l.rect;for(const n of Kt){let r,s,c;if(i){const t=u.cy>l.cy?p.bottom:p.top,e=l.cx+n;if(e<=p.left+qt||e>=p.right-qt)continue;r={x:e,y:t},s={x:e,y:a.y},c={x:a.x,y:a.y}}else{const t=u.cx>l.cx?p.right:p.left,e=l.cy+n;if(e<=p.top+qt||e>=p.bottom-qt)continue;r={x:t,y:e},s={x:a.x,y:e},c={x:a.x,y:a.y}}const h=F(r,s,qt),m=F(s,c,qt);if(h&&m)continue;if(!h&&at(r,s,o,[f],1))continue;if(!m&&at(s,c,o,[d],1))continue;const x=!h&&ft(r,s,t,e,{epsilon:qt,skipDegenerateOther:!0}),y=!m&&ft(s,c,t,e,{epsilon:qt,skipDegenerateOther:!0});if(!x&&!y){g=h?[s,c]:m?[r,s]:[r,s,c];break}}g&&(e.points=g)}}function Ut(t,e){const n=.001,{realNodeRects:o,labelNodeRects:r}=ot(e.values());for(const s of t){if(s.isLayoutOnly)continue;const i=s.points;if(!i||i.length<4)continue;const c=H(i,n);if(c.length<4)continue;const f=c.length-1,d=c[f],l=c[f-1],u=c[f-2],h=d.x-l.x,m=d.y-l.y,g=Math.hypot(h,m);if(g>=10||g<n)continue;const p=l.x-u.x,x=l.y-u.y;if(Math.hypot(p,x)<n)continue;const y=X(l,d,n),_=z(l,d,n),b=X(u,l,n),M=z(u,l,n);if(!(y&&M||_&&b))continue;const I=s.end,S=s.start,w=I?e.get(I):void 0;if(!w)continue;const v=w.x??0,C=w.y??0,L=U(w);if(!L)continue;let k,O;if(M){const t=x<0;k={x:v,y:u.y},O={x:v,y:t?L.bottom:L.top}}else{const t=p>0;k={x:u.x,y:C},O={x:t?L.right:L.left,y:C}}if(at(k,O,o,I?[I]:[],-2))continue;if(at(k,O,r,[],-2))continue;if(S){const t=e.get(S),n=t?U(t):void 0;if(n&&W(k,n,2))continue}const R=(0,a.__name)((t,e)=>`${t.x.toFixed(3)},${t.y.toFixed(3)}|${e.x.toFixed(3)},${e.y.toFixed(3)}`,"ownSegmentKey"),T=new Set;for(let t=0;t<c.length-1;t++)T.add(R(c[t],c[t+1]));const $=(0,a.__name)((e,o)=>{for(const r of t){if(r===s)continue;if(r.isLayoutOnly)continue;const t=r.points;if(t&&!(t.length<2))for(let r=0;r<t.length-1;r++){const s=t[r],a=t[r+1];if(!T.has(R(s,a))&&dt(e,o,s,a,n))return!0}}return!1},"segmentCrossesOtherEdge");if($(k,O))continue;if(f-3>=0){const t=c[f-3];if(at(t,k,o,[S,I].filter(t=>Boolean(t)),-2))continue;if($(t,k))continue}const N=[...c.slice(0,f-2),k,O];s.points=N;const B=s.labelNodeId;if(B){const t=e.get(B);if(t){const e=t.width??0,o=t.height??0;if(e>0&&o>0){let r,s,a=-1;for(let t=0;t<N.length-1;t++){const i=N[t],c=N[t+1],f=Math.hypot(c.x-i.x,c.y-i.y),d=Y(i,c,n),l=E(i,c,n);(d&&f>=e+2||l&&f>=o+2)&&f>a&&(a=f,r=(i.x+c.x)/2,s=(i.y+c.y)/2)}void 0!==r&&void 0!==s&&(t.x=r,t.y=s)}}}}}(0,a.__name)(Qt,"portSwapToLShape"),(0,a.__name)(Ut,"collapseShortTerminalStub");var Zt=.001,te=D,ee=(0,a.__name)((t,e)=>E(t,e,Zt)||Y(t,e,Zt),"orthogonallyAligned");function ne(t,e){const n=(0,a.__name)((t,e)=>{const n=t.x??0,o=t.y??0,r=e.x-n,s=e.y-o;let a=(t.width??0)/2,i=(t.height??0)/2;return Math.abs(s)*a>Math.abs(r)*i?(s<0&&(i=-i),{x:n+(0===s?0:i*r/s),y:o+i}):(r<0&&(a=-a),{x:n+a,y:o+(0===r?0:a*s/r)})},"rectIntersect"),o=(0,a.__name)((t,o)=>{const r=H(t.points??[]);if(r.length<2)return;const s=o?t.start:t.end,a=s?e.get(s):void 0,i=a?U(a):void 0;if(!a||!s||!i)return;const c=o?r[0]:r[r.length-1],f=o?r[1]:r[r.length-2],d=n(a,c);let l=c;return ee(f,d)&&(l=f),E(d,l,Zt)?{edge:t,edgeId:String(t.id??""),nodeId:s,atStart:o,orientation:"V",coord:d.x,min:Math.min(d.y,l.y),max:Math.max(d.y,l.y),boundary:d,railEnd:l,rect:i}:Y(d,l,Zt)?{edge:t,edgeId:String(t.id??""),nodeId:s,atStart:o,orientation:"H",coord:d.y,min:Math.min(d.x,l.x),max:Math.max(d.x,l.x),boundary:d,railEnd:l,rect:i}:void 0},"terminalLaneFor"),r=(0,a.__name)((t,e)=>Math.max(0,Math.min(t.max,e.max)-Math.max(t.min,e.min)),"projectedOverlapLength"),s=(0,a.__name)((t,e)=>t.nodeId===e.nodeId&&t.orientation===e.orientation&&("H"===t.orientation?(Math.abs(t.boundary.x-t.rect.left)<1||Math.abs(t.boundary.x-t.rect.right)<1)&&E(t.boundary,e.boundary,1):(Math.abs(t.boundary.y-t.rect.top)<1||Math.abs(t.boundary.y-t.rect.bottom)<1)&&Y(t.boundary,e.boundary,1)),"sameTerminalFace"),i=(0,a.__name)((t,e)=>t.nodeId===e.nodeId&&t.orientation===e.orientation&&(r(t,e)>=8&&Math.abs(t.coord-e.coord)<.5),"exactTerminalLaneConflict"),c=(0,a.__name)((t,e)=>{if(t.nodeId!==e.nodeId||t.orientation!==e.orientation||"H"!==t.orientation||t.atStart===e.atStart)return!1;const n=r(t,e);if(n<8)return!1;const o=t.rect.bottom-t.rect.top;return!(n<o||n>2*o)&&s(t,e)&&Math.abs(t.coord-e.coord)<16},"nearTerminalLaneConflict"),f=(0,a.__name)((t,e)=>{const n=H(t.edge.points??[]);if(n.length<2)return;const o="V"===t.orientation?{x:t.boundary.x+e,y:t.boundary.y}:{x:t.boundary.x,y:t.boundary.y+e},r="V"===t.orientation?{x:t.railEnd.x+e,y:t.railEnd.y}:{x:t.railEnd.x,y:t.railEnd.y+e};if(!(0,a.__name)(()=>Math.abs(t.boundary.y-t.rect.top)<1||Math.abs(t.boundary.y-t.rect.bottom)<1?Y(o,t.boundary,Zt)&&o.x>=t.rect.left+1&&o.x<=t.rect.right-1:(Math.abs(t.boundary.x-t.rect.left)<1||Math.abs(t.boundary.x-t.rect.right)<1)&&E(o,t.boundary,Zt)&&o.y>=t.rect.top+1&&o.y<=t.rect.bottom-1,"boundaryStaysOnSameFace")())return;if(t.atStart){const e=n.length>1&&F(n[1],t.railEnd,Zt),s=n.slice(e?2:1),a=s[0];if(a&&!ee(a,r))return;return[o,r,...s]}const s=n.length>1&&F(n[n.length-2],t.railEnd,Zt),i=n.slice(0,s?-2:-1),c=i[i.length-1];return!c||ee(c,r)?[...i,r,o]:void 0},"shiftedCandidate"),d=(0,a.__name)(t=>{const n=t.edge,o=H(n.points??[]);if(2!==o.length)return!1;const r=n.start,s=n.end,a=r?e.get(r):void 0,i=s?e.get(s):void 0;if(!a||!i)return!1;const c=a.x??0,f=a.y??0,d=i.x??0,l=i.y??0,[u,h]=o;return Y(u,h,Zt)&&Math.abs(f-l)<1&&Math.abs(c-d)>1||E(u,h,Zt)&&Math.abs(c-d)<1&&Math.abs(f-l)>1},"laneIsStraightCollinearConnector"),l=[-7,7,-14,14,-21,21];for(let e=0;e<8;e++){const e=t.filter(t=>!t.isLayoutOnly).flatMap(t=>[o(t,!0),o(t,!1)]).filter(t=>Boolean(t));let n=!1;for(let t=0;t<e.length&&!n;t++)for(let r=t+1;r<e.length&&!n;r++){const s=e[t],a=e[r];if(s.edge===a.edge||!i(s,a)&&!c(s,a))continue;const u=!i(s,a),h=[s,a].sort((t,e)=>{const n=d(t),o=d(e);return n!==o?Number(n)-Number(o):Number(!e.atStart)-Number(!t.atStart)});for(const t of h){for(const r of l){const s=f(t,r);if(!s)continue;const a=o({...t.edge,points:s},t.atStart);if(a&&!e.some(e=>e.edge!==t.edge&&(i(a,e)||u&&c(a,e)))){t.edge.points=s,n=!0;break}}if(n)break}}if(!n)return}}function oe(t,e){const{realNodeRects:n,labelNodeRects:o}=ot(e.values()),r=(0,a.__name)((e,r)=>{const s=e.start,a=e.end,i=te(r);if(i.length!==r.length-1)return!1;const c=[s,a].filter(t=>Boolean(t));for(const t of i){if(at(t.a,t.b,n,c,-2))return!1;if(at(t.a,t.b,o,[],-2))return!1}for(const n of t){if(n===e||n.isLayoutOnly)continue;const t=n.points;if(t&&!(t.length<2))for(const e of i)for(const n of te(H(t))){if(P(e,n,.5)>=8)return!1;if(dt(e.a,e.b,n.a,n.b,Zt))return!1}}return!0},"candidateIsSafe"),s=(0,a.__name)((t,e)=>{if(e+4>=t.length)return;const n=t[e],o=t[e+1],r=t[e+2],s=t[e+3],a=t[e+4],i=X(n,o)&&z(o,r)&&X(r,s)&&z(s,a)&&E(n,s,Zt)&&E(n,a,Zt)&&E(o,r,Zt)&&(o.x-n.x)*(s.x-r.x)<0,c=z(n,o)&&X(o,r)&&z(r,s)&&X(s,a)&&Y(n,s,Zt)&&Y(n,a,Zt)&&Y(o,r,Zt)&&(o.y-n.y)*(s.y-r.y)<0;if(i||c)return H([...t.slice(0,e+1),a,...t.slice(e+5)]);if(e+5>=t.length)return;const f=t[e+5],d=z(n,o)&&X(o,r)&&z(r,s)&&X(s,a)&&z(a,f)&&E(n,a,Zt)&&E(n,f,Zt)&&E(r,s,Zt)&&(r.x-o.x)*(a.x-s.x)<0,l=X(n,o)&&z(o,r)&&X(r,s)&&z(s,a)&&X(a,f)&&Y(n,a,Zt)&&Y(n,f,Zt)&&Y(r,s,Zt)&&(r.y-o.y)*(a.y-s.y)<0;return d||l?H([...t.slice(0,e+1),f,...t.slice(e+6)]):void 0},"withoutDogleg");for(let e=0;e<8;e++){let e=!1;for(const n of t){if(n.isLayoutOnly)continue;const t=H(n.points??[]);for(let o=0;o<=t.length-5;o++){const a=s(t,o);if(a&&r(n,a)){n.points=a,e=!0;break}}if(e)break}if(!e)return}}function re(t,e){const{realNodeRects:n,labelNodeRects:o}=ot(e.values()),r=t.filter(t=>!t.isLayoutOnly),s=(0,a.__name)((t,e,n)=>H(t===e?n??[]:t.points??[]),"pointsFor"),i=(0,a.__name)((t,e)=>{let n=0;for(let o=0;o<r.length;o++){const a=te(s(r[o],t,e));for(let i=o+1;i<r.length;i++){const o=te(s(r[i],t,e));for(const t of a)for(const e of o)dt(t.a,t.b,e.a,e.b,Zt)&&n++}}return n},"strictCrossingCount"),c=(0,a.__name)(t=>{const e=te(t);if(3!==e.length)return;const n=e[1];return e[0].horizontal!==n.horizontal&&e[2].horizontal!==n.horizontal?{index:n.index,horizontal:n.horizontal,vertical:n.vertical,segment:n}:void 0},"middleRail"),f=(0,a.__name)((t,e)=>{const o=[t.start,t.end].filter(t=>Boolean(t));return n.filter(t=>{if(o.includes(t.id))return!1;const n=t.rect;return e.horizontal?A(e.a.x,e.b.x,n.left,n.right)>=8&&e.a.y>=n.top-2&&e.a.y<=n.bottom+2:A(e.a.y,e.b.y,n.top,n.bottom)>=8&&e.a.x>=n.left-2&&e.a.x<=n.right+2})},"blockingRectsFor"),d=(0,a.__name)((t,e,n)=>{const o=t.map(t=>({...t}));if(e.horizontal)o[e.index].y=n,o[e.index+1].y=n;else{if(!e.vertical)return;o[e.index].x=n,o[e.index+1].x=n}const r=gt(H(o));return te(r).length===r.length-1?r:void 0},"candidateByMovingRail"),l=(0,a.__name)((t,e,a)=>{const c=[t.start,t.end].filter(t=>Boolean(t)),f=te(e);if(f.length!==e.length-1)return!1;for(const t of f){if(at(t.a,t.b,n,c,-2))return!1;if(at(t.a,t.b,o,[],-2))return!1}for(const e of r)if(e!==t)for(const t of f)for(const n of te(s(e)))if(P(t,n,.5)>=8)return!1;return i(t,e)<=a},"candidateIsSafe");for(let t=0;t<8;t++){const t=i();let e=!1;for(const n of r){const o=s(n),r=c(o);if(!r)continue;const a=f(n,r.segment);if(0===a.length)continue;const i=r.horizontal?[Math.min(...a.map(t=>t.rect.top))-20,Math.max(...a.map(t=>t.rect.bottom))+20]:[Math.min(...a.map(t=>t.rect.left))-20,Math.max(...a.map(t=>t.rect.right))+20];for(const s of i){const a=d(o,r.segment,s);if(a&&l(n,a,t)){n.points=a,e=!0;break}}if(e)break}if(!e)return}}function se(t,e){const n=(0,a.__name)(t=>{const e=t.groupTitleRect;if(e&&"number"==typeof e.left&&"number"==typeof e.right&&"number"==typeof e.top&&"number"==typeof e.bottom&&Number.isFinite(e.left)&&Number.isFinite(e.right)&&Number.isFinite(e.top)&&Number.isFinite(e.bottom)&&!(e.right<=e.left)&&!(e.bottom<=e.top))return{left:e.left,right:e.right,top:e.top,bottom:e.bottom}},"validTitleRect"),o=(0,a.__name)(t=>{if(!t.isGroup||t.parentId)return;const e=t.direction,o="string"==typeof e?e.toUpperCase():"";if("LR"===o||"RL"===o||"BT"===o)return;const r=n(t),s=t.y,a=t.height;if(!r||"number"!=typeof s||"number"!=typeof a||!Number.isFinite(s)||!Number.isFinite(a)||a<=0)return;const i=r.right-r.left,c=r.bottom-r.top;return c<=0||i<c?void 0:{node:t,rect:r}},"topLaneTitleFor"),r=(0,a.__name)((t,e)=>{if(!t.horizontal)return!1;const n=t.a.y;return!(n<=e.top+Zt||n>=e.bottom-Zt)&&A(t.a.x,t.b.x,e.left,e.right)>=8},"horizontalSegmentIntersectsTitle"),s=[...e.values()].map(o).filter(t=>Boolean(t));if(0===s.length)return;let i=0;for(const e of t){if(e.isLayoutOnly)continue;const t=H(e.points??[]);for(const e of te(t))for(const t of s)r(e,t.rect)&&(i=Math.max(i,t.rect.bottom-e.a.y+4))}if(!(i<=Zt))for(const t of s){const e=t.node.y,n=t.node.height;"number"!=typeof e||"number"!=typeof n||!Number.isFinite(e)||!Number.isFinite(n)||n<=0||(t.node.y=e-i/2,t.node.height=n+i,t.node.groupTitleRect={...t.rect,top:t.rect.top-i,bottom:t.rect.bottom-i})}}function ae(t,e){const n=(0,a.__name)(t=>{const e=t.groupTitleRect;if(e&&"number"==typeof e.left&&"number"==typeof e.right&&"number"==typeof e.top&&"number"==typeof e.bottom&&Number.isFinite(e.left)&&Number.isFinite(e.right)&&Number.isFinite(e.top)&&Number.isFinite(e.bottom)&&!(e.right<=e.left)&&!(e.bottom<=e.top))return{left:e.left,right:e.right,top:e.top,bottom:e.bottom}},"validTitleRect"),o=(0,a.__name)(t=>{if(!t.isGroup||t.parentId)return;if("LR"!==t.direction)return;const e=n(t),o=t.x,r=t.width;if(!e||"number"!=typeof o||"number"!=typeof r||!Number.isFinite(o)||!Number.isFinite(r)||r<=0)return;const s=e.right-e.left,a=e.bottom-e.top;return s<=0||a<s?void 0:{node:t,rect:e}},"leftLaneTitleFor"),r=(0,a.__name)((t,e)=>{if(!t.vertical)return!1;const n=t.a.x;return!(n<=e.left+Zt||n>=e.right-Zt)&&A(t.a.y,t.b.y,e.top,e.bottom)>=8},"verticalSegmentIntersectsTitle"),s=(0,a.__name)((t,e)=>{if(!t.horizontal)return!1;const n=t.a.y;return!(n<=e.top+Zt||n>=e.bottom-Zt)&&A(t.a.x,t.b.x,e.left,e.right)>=8},"horizontalSegmentIntersectsTitle"),i=[...e.values()].map(o).filter(t=>Boolean(t));if(0===i.length)return;let c=0;for(const e of t){if(e.isLayoutOnly)continue;const t=H(e.points??[]);for(const e of te(t))for(const t of i)if(r(e,t.rect))c=Math.max(c,t.rect.right-e.a.x+4);else if(s(e,t.rect)){const n=Math.min(e.a.x,e.b.x);c=Math.max(c,t.rect.right-n+4)}}if(!(c<=Zt))for(const t of i){const e=t.node.x,n=t.node.width;"number"!=typeof e||"number"!=typeof n||!Number.isFinite(e)||!Number.isFinite(n)||n<=0||(t.node.x=e-c/2,t.node.width=n+c,t.node.groupTitleRect={...t.rect,left:t.rect.left-c,right:t.rect.right-c})}}function ie(t,e){const{realNodeRects:n}=ot(e.values()),o=t.filter(t=>!t.isLayoutOnly),r=(0,a.__name)((t,e=new Map)=>H(e.get(t)??t.points??[]),"replacementPointsFor"),s=(0,a.__name)((t=new Map)=>{let e=0;for(let n=0;n<o.length;n++){const s=te(r(o[n],t));for(let a=n+1;a<o.length;a++){const n=te(r(o[a],t));for(const t of s)for(const o of n)dt(t.a,t.b,o.a,o.b,Zt)&&e++}}return e},"crossingCount"),i=(0,a.__name)((t=new Map)=>o.reduce((e,n)=>e+G(r(n,t)),0),"totalBends"),c=(0,a.__name)(t=>{const e=r(t);if(e.length<4)return;const n=e[e.length-2],o=e[e.length-1];return X(n,o,Zt)||z(n,o,Zt)?{tailStart:n,terminal:o}:void 0},"terminalTailFor"),f=(0,a.__name)((t,e)=>{const n=r(t);if(n.length<3)return;const o=n[0],s=n[1];let a;if(X(o,s,Zt))a={x:s.x,y:e.tailStart.y};else{if(!z(o,s,Zt))return;a={x:e.tailStart.x,y:s.y}}const i=gt(H([o,s,a,e.tailStart,e.terminal]));return te(i).length===i.length-1?i:void 0},"candidateWithDestinationTail"),d=(0,a.__name)((t,e)=>{const o=[t.start,t.end].filter(t=>Boolean(t));for(const t of te(e))if(at(t.a,t.b,n,o,-2))return!0;return!1},"pathHasNodeHit"),l=(0,a.__name)((t,e,n)=>{for(const s of o)if(s!==t)for(const t of te(e))for(const e of te(r(s,n)))if(P(t,e,.5)>=8)return!0;return!1},"pathHasSharedTrack"),u=(0,a.__name)((t,e,n)=>!d(t,e)&&!l(t,e,n),"candidateIsSafe"),h=(0,a.__name)(()=>{const t=new Map;for(const n of o){const o=n.end;if(!o||!e.has(o))continue;if(r(n).length<4)continue;const s=t.get(o)??[];s.push(n),t.set(o,s)}return t},"edgesByDestination");for(let t=0;t<4;t++){const t=s();if(0===t)return;let e,n=t,o=i();for(const r of h().values())for(let a=0;a<r.length;a++)for(let d=a+1;d<r.length;d++){const l=r[a],h=r[d],m=c(l),g=c(h);if(!m||!g)continue;const p=f(l,g),x=f(h,m);if(!p||!x)continue;const y=new Map([[l,p],[h,x]]);if(!u(l,p,y)||!u(h,x,y))continue;const _=s(y),b=i(y);_>=t||_>n||_===n&&b>=o||(e=y,n=_,o=b)}if(!e)return;for(const[t,n]of e)t.points=n}}function ce(t,e){const{realNodeRects:n,labelNodeRects:o}=ot(e.values()),r=t.filter(t=>!t.isLayoutOnly),s=(0,a.__name)((t,e=new Map)=>H(e.get(t)??t.points??[]),"replacementPointsFor"),i=(0,a.__name)((t=new Map)=>{let e=0;for(let n=0;n<r.length;n++){const o=te(s(r[n],t));for(let a=n+1;a<r.length;a++){const n=te(s(r[a],t));for(const t of o)for(const o of n)dt(t.a,t.b,o.a,o.b,Zt)&&e++}}return e},"strictCrossingCount"),c=(0,a.__name)((t=new Map)=>r.reduce((e,n)=>e+G(s(n,t)),0),"totalBends"),f=(0,a.__name)(t=>{const n=t.start,o=t.end,r=n?e.get(n):void 0,s=o?e.get(o):void 0,a=r?U(r):void 0,i=s?U(s):void 0;return a&&i?{src:a,dst:i}:void 0},"endpointRectsFor"),d=(0,a.__name)((t,e,n)=>{if(n.index<=0||n.index+1>=e.length-1)return;const o=f(t);if(o){if(n.vertical){const r=n.a.x,s=Math.min(o.src.left,o.dst.left),a=Math.max(o.src.right,o.dst.right),i=r<s-Zt?"left":r>a+Zt?"right":void 0;if(!i)return;return{edge:t,points:e,segmentIndex:n.index,axis:"vertical",side:i,coord:r,min:Math.min(n.a.y,n.b.y),max:Math.max(n.a.y,n.b.y)}}if(n.horizontal){const r=n.a.y,s=Math.min(o.src.top,o.dst.top),a=Math.max(o.src.bottom,o.dst.bottom),i=r<s-Zt?"top":r>a+Zt?"bottom":void 0;if(!i)return;return{edge:t,points:e,segmentIndex:n.index,axis:"horizontal",side:i,coord:r,min:Math.min(n.a.x,n.b.x),max:Math.max(n.a.x,n.b.x)}}}},"externalRailForSegment"),l=(0,a.__name)(()=>{const t=[];for(const e of r){const n=s(e);for(const o of te(n)){const r=d(e,n,o);r&&t.push(r)}}return t},"collectExternalRails"),u=(0,a.__name)((t,e)=>t.edge!==e.edge&&t.axis===e.axis&&t.side===e.side&&A(t.min,t.max,e.min,e.max)>=8,"railsInteract"),h=(0,a.__name)(t=>{const e=[],n=new Set;for(const o of t){if(n.has(o))continue;const r=[o],s=[];for(n.add(o);r.length>0;){const e=r.pop();s.push(e);for(const o of t)!n.has(o)&&u(e,o)&&(n.add(o),r.push(o))}s.length>1&&e.push(s)}return e},"connectedComponents"),m=(0,a.__name)(t=>{const e=[];for(const n of t)e.some(t=>Math.abs(t-n.coord)<Zt)||e.push(n.coord);for(;e.length<t.length;){const n=Math.min(...e),o=Math.max(...e),r=t[0].side;e.push("left"===r||"top"===r?n-12*(t.length-e.length):o+12*(t.length-e.length))}return e},"uniqueCoordsFor"),g=(0,a.__name)(t=>{const e=t.map(t=>t.coord),n=m(t),o=[];if(t.length<=6){const r=new Array(n.length).fill(!1),s=[],i=(0,a.__name)(()=>{if(s.length!==t.length)for(const[t,e]of n.entries())r[t]||(r[t]=!0,s.push(e),i(),s.pop(),r[t]=!1);else s.some((t,n)=>Math.abs(t-e[n])>=Zt)&&o.push([...s])},"visit");return i(),o}for(let t=0;t<e.length;t++)for(let n=t+1;n<e.length;n++){const r=[...e];[r[t],r[n]]=[r[n],r[t]],o.push(r)}return o},"coordinateAssignmentsFor"),p=(0,a.__name)((t,e)=>{const n=new Map;for(const[o,r]of t.entries()){const t=e[o],s=n.get(r.edge)??r.points.map(t=>({x:t.x,y:t.y}));"vertical"===r.axis?(s[r.segmentIndex].x=t,s[r.segmentIndex+1].x=t):(s[r.segmentIndex].y=t,s[r.segmentIndex+1].y=t),n.set(r.edge,s)}const o=new Map;for(const[t,e]of n){const n=gt(H(e));if(te(n).length!==n.length-1)return;o.set(t,n)}return o},"replacementsForAssignment"),x=(0,a.__name)(t=>{for(const[e,r]of t){const t=[e.start,e.end].filter(t=>Boolean(t));for(const e of te(r)){if(at(e.a,e.b,n,t,-2))return!1;if(at(e.a,e.b,o,[],-2))return!1}}for(let e=0;e<r.length;e++){const n=r[e],o=t.has(n),a=te(s(n,t));for(let n=e+1;n<r.length;n++){const e=r[n];if(!o&&!t.has(e))continue;const i=te(s(e,t));for(const t of a)for(const e of i)if(P(t,e,.5)>=8)return!1}}return!0},"candidateIsSafe");for(let t=0;t<4;t++){const t=i();if(0===t)return;let e,n=t,o=c(),r=Number.POSITIVE_INFINITY;for(const s of h(l()))for(const a of g(s)){const f=p(s,a);if(!f||!x(f))continue;const d=i(f);if(d>=t)continue;const l=c(f),u=s.reduce((t,e,n)=>t+Math.abs(a[n]-e.coord),0);d>n||d===n&&(l>o||l===o&&u>=r)||(e=f,n=d,o=l,r=u)}if(!e)return;for(const[t,n]of e)t.points=n}}function fe(t,e){const{realNodeRects:n,labelNodeRects:o}=ot(e.values()),r=t.filter(t=>!t.isLayoutOnly),s=(0,a.__name)((t,e,n)=>H(t===e?n??[]:t.points??[]),"pointsFor"),i=(0,a.__name)(t=>te(t).reduce((t,e)=>{const n=e.a.x-e.b.x,o=e.a.y-e.b.y;return t+Math.hypot(n,o)},0),"pathLength"),c=(0,a.__name)((t,e)=>{let n=0;for(let o=0;o<r.length;o++){const a=te(s(r[o],t,e));for(let i=o+1;i<r.length;i++){const o=te(s(r[i],t,e));for(const t of a)for(const e of o)dt(t.a,t.b,e.a,e.b,Zt)&&n++}}return n},"strictCrossingCount"),f=(0,a.__name)((t,e)=>{if(t.horizontal){const n=t.a.y;return(Math.abs(n-e.top)<1||Math.abs(n-e.bottom)<1)&&A(t.a.x,t.b.x,e.left,e.right)>=8}if(t.vertical){const n=t.a.x;return(Math.abs(n-e.left)<1||Math.abs(n-e.right)<1)&&A(t.a.y,t.b.y,e.top,e.bottom)>=8}return!1},"segmentRunsAlongRectBorder"),d=(0,a.__name)(t=>{const n=[t.start,t.end].filter(t=>Boolean(t)),o=[];for(const t of n){const n=e.get(t),r=n?U(n):void 0;r&&o.push(r)}return o},"endpointRectsFor"),l=(0,a.__name)((t,e)=>{if(e+3>=t.length)return[];const n=t[e],o=t[e+1],r=t[e+2],s=t[e+3],a=X(n,o,Zt)&&z(o,r,Zt)&&X(r,s,Zt),i=z(n,o,Zt)&&X(o,r,Zt)&&z(r,s,Zt);if(!a&&!i)return[];if(!(a?Math.sign(o.x-n.x)!==Math.sign(s.x-r.x):Math.sign(o.y-n.y)!==Math.sign(s.y-r.y)))return[];const c=E(n,s,Zt)||Y(n,s,Zt)?[]:[{x:n.x,y:s.y},{x:s.x,y:n.y}],f=0===c.length?[[...t.slice(0,e+1),...t.slice(e+3)]]:c.map(n=>[...t.slice(0,e+1),n,...t.slice(e+3)]),d=new Set;return f.map(t=>gt(H(t))).filter(t=>{if(te(t).length!==t.length-1)return!1;if(!t.some(t=>F(t,s,Zt)))return!1;const e=t.map(t=>`${t.x.toFixed(3)},${t.y.toFixed(3)}`).join("|");return!d.has(e)&&(d.add(e),!0)})},"shortcutCandidatesAt"),u=(0,a.__name)((t,e,a)=>{const i=[t.start,t.end].filter(t=>Boolean(t)),l=d(t);for(const t of te(e)){if(at(t.a,t.b,n,i,-2))return!1;if(at(t.a,t.b,o,[],-2))return!1;if(l.some(e=>f(t,e)))return!1}for(const n of r)if(n!==t)for(const t of te(e))for(const e of te(s(n)))if(P(t,e,.5)>=8)return!1;return c(t,e)<=a},"candidateIsSafe");for(let t=0;t<8;t++){const t=c();let e,n,o=t,a=Number.POSITIVE_INFINITY,f=Number.POSITIVE_INFINITY;for(const d of r){const r=s(d),h=G(r,Zt),m=i(r);for(let s=0;s<=r.length-4;s++)for(const g of l(r,s)){const r=G(g,Zt),s=i(g);if(!(r<h||r===h&&s<m-Zt)||!u(d,g,t))continue;const l=c(d,g);l>o||l===o&&(r>a||r===a&&s>=f)||(e=d,n=g,o=l,a=r,f=s)}}if(!e||!n)return;e.points=n}}function de(t,e){const n=20,o=[];for(const t of e.values()){if(t.isGroup||t.isEdgeLabel)continue;const e=t.x??0,n=t.y??0,r=U(t);r&&o.push({id:String(t.id??""),cx:e,cy:n,rect:r})}if(0===o.length)return;const r=new Map(o.map(t=>[t.id,t])),s=o.map(t=>({id:t.id,rect:t.rect})),i=["top","bottom","left","right"],c={top:Math.min(...o.map(t=>t.rect.top))-n,bottom:Math.max(...o.map(t=>t.rect.bottom))+n,left:Math.min(...o.map(t=>t.rect.left))-n,right:Math.max(...o.map(t=>t.rect.right))+n},f=t.filter(t=>!t.isLayoutOnly),d=new Map(f.map((t,e)=>[t,e])),l=(0,a.__name)(t=>{const e="left"===t||"top"===t?-1:1,o=[];for(let r=0;r<=2;r++)o.push(c[t]+e*n*r);return o},"outwardTracksForSide"),u=(0,a.__name)((t,e=new Map)=>H(e.get(t)??t.points??[]),"replacementPointsFor"),h=(0,a.__name)((t,e)=>{let n=0;for(const o of t)for(const t of e)dt(o.a,o.b,t.a,t.b,Zt)&&n++;return n},"crossingCountBetweenSegments"),m=(0,a.__name)((t,e)=>h(te(t),te(e)),"crossingCountBetweenPaths"),g=(0,a.__name)((t=new Map)=>{let e=0;const n=[],o=new Set,r=[],s=(0,a.__name)(t=>{o.has(t)||(o.add(t),r.push(t))},"addEdge");for(let o=0;o<f.length;o++){const r=f[o],a=u(r,t);for(let i=o+1;i<f.length;i++){const o=f[i],c=m(a,u(o,t));c>0&&(e+=c,n.push({first:r,second:o,count:c}),s(r),s(o))}}return r.sort((t,e)=>(d.get(t)??0)-(d.get(e)??0)),{count:e,pairs:n,edgeSet:o,edges:r}},"crossingSnapshot"),p=(0,a.__name)((t,e)=>{const n=new Set(e.keys());if(0===n.size)return t.count;let o=0;for(const e of t.pairs)(n.has(e.first)||n.has(e.second))&&(o+=e.count);let r=0;for(let t=0;t<f.length;t++){const o=f[t],s=n.has(o),a=u(o,e);for(let o=t+1;o<f.length;o++){const t=f[o];(s||n.has(t))&&(r+=m(a,u(t,e)))}}return t.count-o+r},"crossingCountWithReplacements"),x=(0,a.__name)(t=>{const e=new Map;for(const n of t.pairs){const t=e.get(n.first)??new Set;t.add(n.second),e.set(n.first,t);const o=e.get(n.second)??new Set;o.add(n.first),e.set(n.second,o)}const n=[],o=new Set;for(const r of t.edges){if(o.has(r))continue;const t=[r],s=[];for(o.add(r);t.length>0;){const n=t.pop();s.push(n);for(const r of e.get(n)??[])o.has(r)||(o.add(r),t.push(r))}s.sort((t,e)=>(d.get(t)??0)-(d.get(e)??0)),s.length>1&&n.push(s)}return n},"crossingComponents"),y=(0,a.__name)(t=>[t.start,t.end].filter(t=>Boolean(t)),"endpointIdsFor"),_=(0,a.__name)(t=>{const e=[];for(const n of x(t)){const t=new Set(n),o=new Set(n.flatMap(t=>y(t))),r=[...n];for(const e of f)t.has(e)||y(e).some(t=>o.has(t))&&r.push(e);r.sort((t,e)=>(d.get(t)??0)-(d.get(e)??0)),e.push(r)}return e},"pairSearchGroups"),b=(0,a.__name)((t,e,n)=>p(t,new Map([[e,n]])),"crossingCountWithSingleReplacement"),M=(0,a.__name)(t=>{const e=new Map;for(const n of t.pairs)e.set(n.first,(e.get(n.first)??0)+n.count),e.set(n.second,(e.get(n.second)??0)+n.count);return e},"currentCrossingsByEdge"),I=(0,a.__name)(t=>t.slice(1).reduce((e,n,o)=>{const r=t[o];return e+Math.abs(n.x-r.x)+Math.abs(n.y-r.y)},0),"pathLength"),S=(0,a.__name)((t=new Map)=>f.reduce((e,n)=>e+G(u(n,t)),0),"totalBends"),w=(0,a.__name)((t=new Map)=>f.reduce((e,n)=>e+I(u(n,t)),0),"totalLength"),v=(0,a.__name)((t,e,n=new Map)=>{const o=te(e);for(const e of f)if(e!==t)for(const t of o)for(const o of te(u(e,n)))if(P(t,o,.5)>=8)return!0;return!1},"pathHasSegmentConflict"),C=(0,a.__name)((t,e)=>{const n=[t.start,t.end].filter(t=>Boolean(t));for(const t of te(e))if(at(t.a,t.b,s,n,-2))return!0;return!1},"pathHitsNode"),L=(0,a.__name)((t,e)=>{const n=gt(H(e));te(n).length===n.length-1&&t.push(n)},"pushOrthogonalCandidate"),k=(0,a.__name)(t=>"left"===t||"right"===t,"sideIsHorizontal"),O=(0,a.__name)((t,e,o)=>{switch(e){case"left":return Math.min(t.x,o.x)-n;case"right":return Math.max(t.x,o.x)+n;case"top":return Math.min(t.y,o.y)-n;case"bottom":return Math.max(t.y,o.y)+n}},"localTrackForSameSide"),R=(0,a.__name)((t,e,o,r)=>{const s="left"===o||"top"===o?-1:1,a=[O(e,o,r),c[o]];for(const i of a)for(let a=0;a<=2;a++)L(t,et(e,o,r,i+s*n*a))},"addSameSideCandidates"),T=(0,a.__name)((t,e,n,o,r)=>{for(const s of l(n))for(const n of l(r))L(t,[e,{x:s,y:e.y},{x:s,y:n},{x:o.x,y:n},o])},"addHorizontalToVerticalCandidates"),$=(0,a.__name)((t,e,n,o,r)=>{for(const s of l(n))for(const n of l(r))L(t,[e,{x:e.x,y:s},{x:n,y:s},{x:n,y:o.y},o])},"addVerticalToHorizontalCandidates"),N=(0,a.__name)((t,e,n,o,r)=>{const s=[...l("top"),...l("bottom")];for(const a of l(n))for(const n of l(r))for(const r of s)L(t,[e,{x:a,y:e.y},{x:a,y:r},{x:n,y:r},{x:n,y:o.y},o])},"addHorizontalPairCandidates"),B=(0,a.__name)((t,e,n,o,r)=>{const s=[...l("left"),...l("right")];for(const a of l(n))for(const n of l(r))for(const r of s)L(t,[e,{x:e.x,y:a},{x:r,y:a},{x:r,y:n},{x:o.x,y:n},o])},"addVerticalPairCandidates"),F=(0,a.__name)(t=>{const e=new Set;return t.map(t=>H(t)).filter(t=>{const n=t.map(t=>`${t.x.toFixed(3)},${t.y.toFixed(3)}`).join("|");return!(e.has(n)||t.length<2||(e.add(n),0))})},"dedupeCandidatePaths"),E=(0,a.__name)((t,e,o,r)=>{const s=[],a=tt(t,e,o,r,n,Zt);a&&L(s,a),e===r&&R(s,t,e,o);const i=k(e),c=k(r);return i&&!c?T(s,t,e,o,r):!i&&c?$(s,t,e,o,r):i?N(s,t,e,o,r):B(s,t,e,o,r),F(s)},"buildCandidatesForSides"),Y=(0,a.__name)((t,e,n,o)=>{const r=[...l("left"),...l("right")],s=[...l("top"),...l("bottom")];for(const a of i){const i=Z(o,a),c="top"===a||"bottom"===a?l(a):s;for(const o of r){L(t,[e,n,{x:o,y:n.y},{x:o,y:i.y},i]);for(const r of c)L(t,[e,n,{x:o,y:n.y},{x:o,y:r},{x:i.x,y:r},i])}}},"addVerticalDepartureOuterTrackCandidates"),A=(0,a.__name)((t,e,n,o)=>{const r=[...l("left"),...l("right")],s=[...l("top"),...l("bottom")];for(const a of i){const i=Z(o,a),c="left"===a||"right"===a?l(a):r;for(const o of s){L(t,[e,n,{x:n.x,y:o},{x:i.x,y:o},i]);for(const r of c)L(t,[e,n,{x:n.x,y:o},{x:r,y:o},{x:r,y:i.y},i])}}},"addHorizontalDepartureOuterTrackCandidates"),D=(0,a.__name)(t=>{const e=t.start,n=t.end,o=n?r.get(n):void 0;if(!e||!o)return[];const s=H(t.points??[]);if(s.length<4)return[];const a=s[0],i=s[1],c=[];return z(a,i,Zt)?Y(c,a,i,o):X(a,i,Zt)&&A(c,a,i,o),c},"terminalPreservingOuterTrackCandidates"),j=(0,a.__name)(t=>{const e=t.start,n=t.end,o=e?r.get(e):void 0,s=n?r.get(n):void 0;if(!o||!s)return[];const a=[];for(const t of i){const e=Z(o,t);for(const n of i)a.push(...E(e,t,Z(s,n),n))}return a.push(...D(t)),a},"candidatePathsFor"),V=(0,a.__name)(()=>new Map(f.map(t=>[t,te(u(t))])),"currentSegmentsByEdge"),W=(0,a.__name)((t,e,n)=>{const o=new Set;for(const r of f){if(r===t)continue;const s=n.get(r)??te(u(r));e.some(t=>s.some(e=>P(t,e,.5)>=8))&&o.add(r)}return o},"sharedTrackConflictsFor"),J=(0,a.__name)((t,e,n,o)=>{const r=new Set;return j(t).map(t=>gt(H(t))).filter(e=>{if(C(t,e))return!1;const n=e.map(t=>`${t.x.toFixed(3)},${t.y.toFixed(3)}`).join("|");return!(r.has(n)||e.length<2||(r.add(n),0))}).map(r=>{const s=te(r);let a=0;for(const e of f)e!==t&&(a+=h(s,n.get(e)??te(u(e))));return{candidate:r,candidateSegments:s,crossings:e.count-(o.get(t)??0)+a,bends:G(r,Zt),totalBends:G(r),length:I(r)}}).filter(({crossings:t})=>t<=e.count).sort((t,e)=>t.crossings-e.crossings||t.bends-e.bends||t.length-e.length).slice(0,48).map(e=>({path:e.candidate,segments:e.candidateSegments,sharedTrackConflicts:W(t,e.candidateSegments,n),totalBends:e.totalBends,length:e.length}))},"pairCandidatesFor"),q=(0,a.__name)((t,e,n,o,r,s)=>{let a=0;for(const n of t.pairs)n.first!==e&&n.second!==e&&n.first!==o&&n.second!==o||(a+=n.count);let i=h(n.segments,r.segments);for(const t of f){if(t===e||t===o)continue;const a=s.get(t)??te(u(t));i+=h(n.segments,a)+h(r.segments,a)}return t.count-a+i},"pairCrossingCount"),K=(0,a.__name)((t,e)=>{for(const n of t.sharedTrackConflicts)if(n!==e)return!1;return!0},"conflictsOnlyWith"),Q=(0,a.__name)((t,e)=>t.segments.some(t=>e.segments.some(e=>P(t,e,.5)>=8)),"candidatesShareTrack"),nt=(0,a.__name)((t,e,n,o)=>K(e,n.edge)&&K(o,t.edge)&&!Q(e,o),"pairCandidatesAreCompatible"),ot=(0,a.__name)((t,e,n,o,r)=>{const s=q(t.current,e.edge,n,o.edge,r,t.baseSegments);if(!(s>=t.current.count))return{replacements:new Map([[e.edge,n.path],[o.edge,r.path]]),crossings:s,bends:t.currentBends-(t.baseBendsByEdge.get(e.edge)??0)-(t.baseBendsByEdge.get(o.edge)??0)+n.totalBends+r.totalBends,length:t.currentLength-(t.baseLengthByEdge.get(e.edge)??0)-(t.baseLengthByEdge.get(o.edge)??0)+n.length+r.length}},"scorePairReplacement"),rt=(0,a.__name)((t,e)=>t.crossings<e.crossings||t.crossings===e.crossings&&(t.bends<e.bends||t.bends===e.bends&&t.length<e.length),"pairScoreIsBetter"),st=(0,a.__name)((t,e,n,o)=>{let r=o;for(const o of e.candidates)for(const s of n.candidates){if(!nt(e,o,n,s))continue;const a=ot(t,e,o,n,s);a&&rt(a,r)&&(r=a)}return r},"bestScoreForOptionPair"),it=(0,a.__name)(t=>{const e=S(),n=w(),o=V(),r=M(t),s=new Map(f.map(t=>[t,G(u(t))])),a=new Map(f.map(t=>[t,I(u(t))])),i=new Map,c=_(t);for(const e of c)for(const n of e){if(i.has(n))continue;const e=J(n,t,o,r);e.length>0&&i.set(n,{edge:n,candidates:e})}let d={replacements:new Map,crossings:t.count,bends:e,length:n};const l={current:t,currentBends:e,currentLength:n,baseBendsByEdge:s,baseLengthByEdge:a,baseSegments:o};for(const e of c){const n=new Set(e.filter(e=>t.edgeSet.has(e))),o=e.map(t=>i.get(t)).filter(t=>Boolean(t));for(let t=0;t<o.length;t++){const e=o[t];for(let r=t+1;r<o.length;r++){const t=o[r];(n.has(e.edge)||n.has(t.edge))&&(d=st(l,e,t,d))}}}return d.replacements.size>0?d.replacements:void 0},"bestPairedReplacement");for(let t=0;t<4;t++){const t=g(),e=t.count;if(0===e)return;let n,o,r=e,s=Number.POSITIVE_INFINITY;for(const a of t.edges){const i=G(u(a),Zt);for(const c of j(a)){const f=C(a,c),d=!f&&v(a,c),l=b(t,a,c),u=G(c,Zt);f||d||(l<e||l===e&&u<i)&&(l>r||l===r&&u>=s||(n=a,o=c,r=l,s=u))}}if(n&&o){n.points=o;continue}const a=it(t);if(!a)return;for(const[t,e]of a)t.points=e}}(0,a.__name)(ne,"separateSharedRenderedTerminalLanes"),(0,a.__name)(oe,"collapseRedundantRectangularDoglegs"),(0,a.__name)(re,"liftObstacleHuggingSameSideRails"),(0,a.__name)(se,"liftTopLaneTitleBandsAboveRails"),(0,a.__name)(ae,"shiftLeftLaneTitleBandsLeftOfRails"),(0,a.__name)(ie,"swapDestinationTerminalTailsToReduceCrossings"),(0,a.__name)(ce,"reassignCrossingExternalRailChannels"),(0,a.__name)(fe,"shortcutRedundantOrthogonalJogs"),(0,a.__name)(de,"resolveRenderedOrthogonalCrossings");var le=.001;function ue(t,e){const{nodeInfoById:n,realNodeRects:o}=nt(e),r=["top","bottom","left","right"],s={top:Math.min(...o.map(t=>t.rect.top))-20,bottom:Math.max(...o.map(t=>t.rect.bottom))+20,left:Math.min(...o.map(t=>t.rect.left))-20,right:Math.max(...o.map(t=>t.rect.right))+20},i=(0,a.__name)((t,e,n,o)=>{const r=[],a=tt(t,e,n,o,20,le);return a&&r.push(a),e===o&&r.push(et(t,e,n,s[e])),r},"buildOrthogonalPathCandidates"),c=(0,a.__name)((t,e)=>{for(let n=0;n<t.length-1;n++)if(at(t[n],t[n+1],o,e,1))return!0;return!1},"pathHitsNode"),f=(0,a.__name)((e,n,o=!1)=>{let r=0;const s=D(e,le),a=n.start,i=n.end;for(const e of t){if(e===n||e.isLayoutOnly)continue;const t=e.start,c=e.end;if(!o&&a&&i&&(t===a||t===i||c===a||c===i))continue;const f=e.points;if(f&&!(f.length<2))for(const t of s)for(const e of D(f,le))(it(t.a,t.b,e.a,e.b,le,le)||P(t,e,le)>=8)&&r++}return r},"pathConflictCount"),d=(0,a.__name)((t,e)=>{const n=Math.abs(t.y-e.rect.top),o=Math.abs(t.y-e.rect.bottom),r=Math.abs(t.x-e.rect.left),s=Math.abs(t.x-e.rect.right);let a="top",i=n;return o<i&&(a="bottom",i=o),r<i&&(a="left",i=r),s<i&&(a="right",i=s),a},"nearestSideOfRect"),l=new Map,u=(0,a.__name)((t,e,n)=>{const o=l.get(t)??[];o.push({side:e,edgeId:n}),l.set(t,o)},"addFaceClaim");for(const e of t){if(e.isLayoutOnly)continue;const t=e.points??[];if(t.length<1)continue;const o=e.id??"",r=e.start,s=e.end;if(r){const e=n.get(r);e&&u(r,d(t[0],e),o)}if(s){const e=n.get(s);e&&u(s,d(t[t.length-1],e),o)}}const h=(0,a.__name)((t,e,n)=>l.get(t)?.some(t=>t.edgeId!==n&&t.side===e)??!1,"faceIsClaimed");for(const e of t){if(e.isLayoutOnly)continue;const t=e.points;if(!t||t.length<2)continue;const o=G(t,le);if(o<4)continue;const s=e.start,a=e.end;if(!s||!a)continue;const m=n.get(s),g=n.get(a);if(!m||!g)continue;const p=e.id??"",x=f(t,e,!0),y=f(t,e);let _,b=x,M=o;for(const t of r){if(h(s,t,p))continue;const n=Z(m,t);for(const o of r){if(h(a,o,p))continue;const r=Z(g,o);for(const d of i(n,t,r,o)){if(c(d,[s,a]))continue;const t=G(d,le);if(x>0){const n=f(d,e,!0);if(n>b||n===b&&t>=M)continue;b=n,M=t,_=d;continue}f(d,e)>y||t<M&&(M=t,_=d)}}}if(_){e.points=_;const t=l.get(s);t&&l.set(s,t.filter(t=>t.edgeId!==p));const n=l.get(a);n&&l.set(a,n.filter(t=>t.edgeId!==p)),u(s,d(_[0],m),p),u(a,d(_[_.length-1],g),p)}}}(0,a.__name)(ue,"simplifyDetouredEdges");var he=.001;function me(t,e){const n=e?0:t.length-1,o=e?1:-1,r=t[n],s=t[n+o];if(!r||!s)return;const a=s.x-r.x,i=s.y-r.y;if(!(Math.abs(a)+Math.abs(i)<he)){if(Math.abs(i)<=he){const t=r.x+10*Math.sign(a);return{left:Math.min(r.x,t),right:Math.max(r.x,t),top:r.y-7,bottom:r.y+7}}if(Math.abs(a)<=he){const t=r.y+10*Math.sign(i);return{left:r.x-7,right:r.x+7,top:Math.min(r.y,t),bottom:Math.max(r.y,t)}}return{left:Math.min(r.x,s.x),right:Math.max(r.x,s.x),top:Math.min(r.y,s.y),bottom:Math.max(r.y,s.y)}}}function ge(t){return{left:Math.min(t.left,t.right),right:Math.max(t.left,t.right),top:Math.min(t.top,t.bottom),bottom:Math.max(t.top,t.bottom)}}function pe(t,e){const n=H(e);return[me(n,!0),me(n,!1)].some(e=>e&&q(t,ge(e)))}function xe(t,e){const n=[];for(const e of t){if(e.isLayoutOnly)continue;const t=e.points;if(t&&!(t.length<2))for(let o=0;o<t.length-1;o++)n.push({edgeId:e.id,p1:t[o],p2:t[o+1]})}const o=[],r=[];for(const t of e.values()){const e=t.isGroup,n=t.parentId;if(e&&!n){const e=U(t);e&&r.push({id:t.id,rect:e});continue}if(e)continue;if(t.isEdgeLabel)continue;const s=U(t);s&&o.push({nodeId:t.id,rect:s})}const s=(0,a.__name)((t,e)=>{const n=K(e,3);for(const{nodeId:e,rect:r}of o)if(e!==t&&q(n,r))return!0;return!1},"labelOverlapsForeignNode"),i=(0,a.__name)((t,e)=>{const o=K(e,3);for(const e of n)if(e.edgeId!==t&&V(e.p1,e.p2,o))return!0;return!1},"labelOverlapsForeignEdge"),c=(0,a.__name)((t,e,n)=>s(t,n)||i(e,n),"labelOverlapsAnything"),f=[],d=(0,a.__name)(t=>{for(const{id:e,rect:n}of r)if(J(n,t))return e},"findContainingLane"),l=(0,a.__name)((t,e)=>f.some(n=>n.labelId!==t&&q(e,n.rect)),"overlapsPlacedLabel");for(const n of t){if(n.isLayoutOnly)continue;const t=n.labelNodeId;if(!t)continue;const o=e.get(t);if(!o)continue;const u=n.points;if(!u||u.length<2)continue;const h=o.width??0,m=o.height??0;if(h<=0||m<=0)continue;const g=[];for(let t=0;t<u.length-1;t++){const e=u[t],n=u[t+1],o=Math.abs(e.x-n.x),r=Math.abs(e.y-n.y);o<he&&r<he||o>=he&&r>=he||g.push({idx:t,length:o+r,orientation:o>=he?"horizontal":"vertical",midX:(e.x+n.x)/2,midY:(e.y+n.y)/2})}if(0===g.length)continue;const p=g.length>=3?g.filter(t=>t.idx>0&&t.idx<g.length-1):g,x=p.length>0?p:g,y=h>=m?"horizontal":"vertical",_=(0,a.__name)(t=>[...t].sort((t,e)=>{const n=t.orientation===y;if(n!==(e.orientation===y))return n?-1:1;const o=t.length>=("horizontal"===t.orientation?h:m)+2;return o!==e.length>=("horizontal"===e.orientation?h:m)+2?o?-1:1:e.length-t.length}),"rankSegments"),b=g[0],M=g[g.length-1],I=[.5,.25,.75,.05,.95,.15,.85,.1,.9],S=(0,a.__name)((t,e)=>{const n=u[t.idx],o=u[t.idx+1];return{midX:n.x+(o.x-n.x)*e,midY:n.y+(o.y-n.y)*e}},"anchorAtT"),w=(0,a.__name)((t,e,n)=>Math.min(n,Math.max(e,t)),"clamp"),v=(0,a.__name)((t,e)=>t.midX>=e.left-he&&t.midX<=e.right+he&&t.midY>=e.top-he&&t.midY<=e.bottom+he,"pointInsideRectInclusive"),C=(0,a.__name)(t=>{const e=Q(t.midX,t.midY,h,m),n=d(e);if(n)return{laneId:n,anchor:t,rect:e};const o=r.find(({rect:e})=>v(t,e));if(!o)return;const s=o.rect.left+h/2+1,a=o.rect.right-h/2-1,i=o.rect.top+m/2+1,c=o.rect.bottom-m/2-1;if(s>a||i>c)return;const f={midX:w(t.midX,s,a),midY:w(t.midY,i,c)},l=Q(f.midX,f.midY,h,m);return v(t,l)?{laneId:o.id,anchor:f,rect:l}:void 0},"placementForAnchor"),L=(0,a.__name)((t,e,n)=>"horizontal"===t.orientation?Math.abs(e.midX-n.x):Math.abs(e.midY-n.y),"distanceAlongSegment"),k=(0,a.__name)((t,e)=>{const n=12+("horizontal"===t.orientation?h/2:m/2);if(t===b){const o=u[t.idx];if(L(t,e,o)+he<n)return!1}if(t===M){const o=u[t.idx+1];if(L(t,e,o)+he<n)return!1}return!0},"labelClearsTerminalEndpoints"),O=(0,a.__name)(e=>{const o=_(e);for(const e of o)for(const o of I){const r=S(e,o);if(!k(e,r))continue;const s=C(r);if(s&&!pe(s.rect,u)&&!l(t,s.rect)&&!c(t,n.id,s.rect))return{laneId:s.laneId,anchor:s.anchor}}},"tryPool"),R=(0,a.__name)((e,o,r=!1)=>{const a=_(e);for(const e of a){const a={midX:e.midX,midY:e.midY};if(o&&!k(e,a))continue;const c=C(a);if(c&&!pe(c.rect,u)&&!l(t,c.rect)&&!s(t,c.rect)&&(r||!i(n.id,c.rect)))return{laneId:c.laneId,anchor:c.anchor}}},"findLaneContainingFallback"),T=O(x)??(x.length<g.length?O(g):void 0)??R(g,!0)??R(g,!1)??R(g,!1,!0);if(T){o.x=T.anchor.midX,o.y=T.anchor.midY,o.parentId=T.laneId;const e=Q(T.anchor.midX,T.anchor.midY,h,m),n=f.findIndex(e=>e.labelId===t);n>=0?f[n]={labelId:t,rect:e}:f.push({labelId:t,rect:e})}}}(0,a.__name)(me,"markerClearanceRectFor"),(0,a.__name)(ge,"normalizeRect"),(0,a.__name)(pe,"labelOverlapsOwnMarker"),(0,a.__name)(xe,"anchorLabelsToPolyline");var ye=1e-6;function _e(t,e){return t<e?`${t}::${e}`:`${e}::${t}`}function be(t,e){const{nodeInfoById:n,realNodeRects:o}=nt(e),r=new Map;for(const t of e){const e=t.id;t.isGroup||t.isEdgeLabel&&r.set(e,{w:t.width??0,h:t.height??0})}const s=(0,a.__name)((e,n,o,s)=>{const i=_e(n,o);let c=0;const f=(0,a.__name)(t=>{if(!t)return;const e=r.get(t);if(!e)return;const n="x"===s?e.w/2:e.h/2;n>c&&(c=n)},"consider");f(e.labelNodeId);for(const n of t){if(n===e)continue;if(n.isLayoutOnly)continue;const t=n.start,o=n.end;t&&o&&_e(t,o)===i&&f(n.labelNodeId)}return c>0?c+3:0},"labelClearanceFor");for(const e of t){if(e.isLayoutOnly)continue;if(!j(e.points,ye))continue;const r=st(e,n,ye);if(!r)continue;const{srcId:a,dstId:i,srcInfo:c,dstInfo:f,collinearX:d,collinearY:l}=r;if(d===l)continue;let u,h;if(d){const t=f.cy>c.cy;u={x:c.cx,y:t?c.rect.bottom:c.rect.top},h={x:f.cx,y:t?f.rect.top:f.rect.bottom}}else{const t=f.cx>c.cx;u={x:t?c.rect.right:c.rect.left,y:c.cy},h={x:t?f.rect.left:f.rect.right,y:f.cy}}if(at(u,h,o,[a,i],1))continue;const m=s(e,a,i,d?"x":"y"),g=m>4?m:4,p=[0,g,-g];for(const n of p){const r={...u},s={...h};if(d){if(r.x+=n,s.x+=n,r.x<=c.rect.left||r.x>=c.rect.right)continue;if(s.x<=f.rect.left||s.x>=f.rect.right)continue}else{if(r.y+=n,s.y+=n,r.y<=c.rect.top||r.y>=c.rect.bottom)continue;if(s.y<=f.rect.top||s.y>=f.rect.bottom)continue}if(!at(r,s,o,[a,i],1)&&!ft(r,s,t,e,{epsilon:ye})){e.points=[r,s];break}}}}function Me(t,e){const n=.001,{realNodeRects:o,labelNodeRects:r}=ot(e.values()),s=(0,a.__name)((t,e)=>D(e,n).map(n=>({...n,edge:t,interior:n.index>=1&&n.index<=e.length-3})),"segmentsFor"),i=(0,a.__name)(()=>{const e=[];for(const n of t){if(n.isLayoutOnly)continue;const t=n.points;!t||t.length<2||e.push(...s(n,H(t)))}return e},"allSegments"),c=(0,a.__name)((t,e)=>t.horizontal&&e.horizontal?A(t.a.x,t.b.x,e.a.x,e.b.x)>=8&&Math.abs(t.a.y-e.a.y)<7:!(!t.vertical||!e.vertical)&&A(t.a.y,t.b.y,e.a.y,e.b.y)>=8&&Math.abs(t.a.x-e.a.x)<7,"hasCrowdedParallelTrack"),f=(0,a.__name)((e,a)=>{const i=e.start,f=e.end,d=s(e,a);if(d.length!==a.length-1)return!1;const l=[i,f].filter(t=>Boolean(t)),u=e.labelNodeId?[e.labelNodeId]:[];for(const t of d){if(at(t.a,t.b,o,l,-2))return!1;if(at(t.a,t.b,r,u,-2))return!1}for(const o of t){if(o===e||o.isLayoutOnly)continue;const t=o.points;if(t&&!(t.length<2))for(const e of d)for(const r of s(o,H(t))){if(c(e,r))return!1;if(dt(e.a,e.b,r.a,r.b,n))return!1}}return!0},"candidateIsSafe"),d=(0,a.__name)((t,e)=>{const n=H(t.edge.points??[]);if(n.length<4||t.index>=n.length-1)return;const o=n.map(t=>({...t}));if(t.horizontal)o[t.index].y+=e,o[t.index+1].y+=e;else{if(!t.vertical)return;o[t.index].x+=e,o[t.index+1].x+=e}return s(t.edge,o).length===o.length-1?o:void 0},"shiftedCandidate"),l=(0,a.__name)((t,e)=>({x:t.x??(e.left+e.right)/2,y:t.y??(e.top+e.bottom)/2}),"nodeCenter"),u=(0,a.__name)(t=>{const n=t.edge,o=H(n.points??[]);if(4!==o.length||1!==t.index)return;const r=n.start?e.get(n.start):void 0,s=n.end?e.get(n.end):void 0,a=r?U(r):void 0,i=s?U(s):void 0,c=o.slice(t.index+2);return r&&s&&a&&i&&0!==c.length?{sourceCenter:l(r,a),targetCenter:l(s,i),sourceRect:a,tail:c}:void 0},"sourceDetourContextFor"),h=(0,a.__name)((t,e,o,r,s,a)=>{const i=r.y>=o.y,c=i?s.bottom:s.top,f=c+(i?20:-20);if(i&&t.b.y<=f+n||!i&&t.b.y>=f-n)return;const d=t.a.x+e;return H([{x:o.x,y:c},{x:o.x,y:f},{x:d,y:f},{x:d,y:t.b.y},...a],n)},"verticalSourceDetour"),m=(0,a.__name)((t,e,o,r,s,a)=>{const i=r.x>=o.x,c=i?s.right:s.left,f=c+(i?20:-20);if(i&&t.b.x<=f+n||!i&&t.b.x>=f-n)return;const d=t.a.y+e;return H([{x:c,y:o.y},{x:f,y:o.y},{x:f,y:d},{x:t.b.x,y:d},...a],n)},"horizontalSourceDetour"),g=(0,a.__name)((t,e)=>{const n=u(t);if(n)return t.vertical?h(t,e,n.sourceCenter,n.targetCenter,n.sourceRect,n.tail):t.horizontal?m(t,e,n.sourceCenter,n.targetCenter,n.sourceRect,n.tail):void 0},"sourceDetourCandidate"),p=[-7,7,-14,14,-21,21];for(let t=0;t<12;t++){const t=i();let e=!1;for(let n=0;n<t.length&&!e;n++)for(let o=n+1;o<t.length&&!e;o++){const r=t[n],s=t[o];if(r.edge===s.edge||!c(r,s))continue;const a=[r,s].filter(t=>t.interior);for(const t of a){for(const n of p){const o=d(t,n);if(o&&f(t.edge,o)){t.edge.points=o,e=!0;break}const r=g(t,n);if(r&&f(t.edge,r)){t.edge.points=r,e=!0;break}}if(e)break}}if(!e)return}}function Ie(t,e,n,o){const r=e.x-t.x,s=e.y-t.y,a=o.x-n.x,i=o.y-n.y,c=r*i-s*a;if(Math.abs(c)<1e-10)return!1;const f=n.x-t.x,d=n.y-t.y,l=(f*i-d*a)/c,u=(f*s-d*r)/c;return l>.01&&l<.99&&u>.01&&u<.99}function Se(t){const e=t.nodes??[],n=t.edges??[],o=[];if(!n.length||!e.length)return o;const r=rt(e),a=[];for(const t of n){if(t.isLayoutOnly)continue;const e=t.points;if(!e||e.length<2)continue;const n=t.start,s=t.end,i=t.labelNodeId,c=t.id??`${n}->${s}`;for(const t of r)if(t.nodeId!==n&&t.nodeId!==s&&(!i||t.nodeId!==i))for(let n=0;n<e.length-1;n++)if(V(e[n],e[n+1],t,-1)){o.push({type:"edge-node-overlap",edgeId:c,targetId:t.nodeId,detail:`segment ${n} passes through node "${t.nodeId}"`});break}for(let t=0;t<e.length-1;t++)a.push({edgeId:c,start:n,end:s,p1:e[t],p2:e[t+1]})}const i=new Set;for(let t=0;t<a.length;t++)for(let e=t+1;e<a.length;e++){const n=a[t],r=a[e];if(n.edgeId!==r.edgeId&&n.start!==r.start&&n.start!==r.end&&n.end!==r.start&&n.end!==r.end&&Ie(n.p1,n.p2,r.p1,r.p2)){const t=n.edgeId<r.edgeId?`${n.edgeId}|${r.edgeId}`:`${r.edgeId}|${n.edgeId}`;i.has(t)||(i.add(t),o.push({type:"edge-edge-crossing",edgeId:n.edgeId,targetId:r.edgeId,detail:`edges "${n.edgeId}" and "${r.edgeId}" cross`}))}}if(o.length>0){const t=o.filter(t=>"edge-node-overlap"===t.type).length,e=o.filter(t=>"edge-edge-crossing"===t.type).length;s.log.warn(`[SWIMLANE_VALIDATE] ${o.length} issue(s) detected: ${t} edge-node overlap(s), ${e} edge crossing(s)`);for(const t of o)s.log.warn(`[SWIMLANE_VALIDATE] ${t.type}: ${t.detail}`)}return o}function we(t,e){const n=t.nodes??[],o=t.edges??[],r=n.filter(t=>!t.isGroup);if(("LR"===e||"RL"===e)&&r.length>0&&!Jt(t,e))return;if("BT"===e&&r.length>0&&!Wt(t))return;for(const t of o){if(t.isLayoutOnly)continue;const e=t.points;!e||e.length<2||(t.points=gt(mt(e)))}ue(o,n),be(o,n),Qt(o,n);const s=new Map;for(const t of n)s.set(String(t.id),t);xe(o,s),bt(o,s),Ut(o,s),Me(o,s),ne(o,s),oe(o,s),re(o,s),ie(o,s);const i=(0,a.__name)(()=>{de(o,s),ce(o,s),fe(o,s),xe(o,s),zt(o,s),re(o,s),xe(o,s),zt(o,s)},"finalizeRenderedEdges");i(),Me(o,s),i(),se(o,s),ae(o,s),se(o,s),ae(o,s)}function ve(t){const e=new Map(t.nodeById),n=new Set,o=[];for(const r of t.edges){if(!e.has(r.src)||!e.has(r.dst))continue;const t=`${r.id}:${r.src}->${r.dst}`;n.has(t)||(n.add(t),o.push(r))}return{nodes:[...e.keys()],edges:o,layout:t.layout,nodeById:e}}function Ce(t,e){return t.edges.filter(t=>t.dst===e)}function Le(t){const e=new Map;for(const n of t.nodes)e.set(n,[]);for(const n of t.edges)e.get(n.src).push(n.dst);return e}function ke(t){const e=Le(t);for(const t of e.values())t.sort((t,e)=>t.localeCompare(e));return e}function Oe(t){const e=new Map;for(const n of t.nodes)e.set(n,0);for(const n of t.edges)e.set(n.dst,(e.get(n.dst)??0)+1);return e}function Re(t){return[...t.entries()].filter(([,t])=>0===t).map(([t])=>t).sort((t,e)=>t.localeCompare(e))}function Te(t,e=()=>!0){const n=new Map,o=new Map;for(const e of t.nodes)n.set(e,[]),o.set(e,[]);for(const r of t.edges)e(r)&&(o.get(r.src).push(r.dst),n.get(r.dst).push(r.src));return{preds:n,succs:o}}function $e(t,e,n,o){let r=0;for(const e of t.nodes)o?.skipGroups&&t.nodeById.get(e)?.isGroup||(r=Math.max(r,n[e]??0));const s=Array.from({length:r+1},()=>[]);for(const r of e)o?.skipGroups&&t.nodeById.get(r)?.isGroup||s[Math.max(0,n[r]??0)].push(r);return s}function Ne(t){const e=Oe(t),n=Re(e),o=[],r=ke(t);for(;n.length;){const t=n.shift();o.push(t);for(const o of r.get(t)??[])if(e.set(o,(e.get(o)??0)-1),0===(e.get(o)??0)){let t=0;for(;t<n.length&&n[t]<o;)t++;n.splice(t,0,o)}}return o.length===t.nodes.length?o:null}function Be(t){const e=new Map;let n=0;for(const o of t)e.set(o,n),n++;return e}function Fe(t){const e=new Array(t.length),n=(0,a.__name)((o,r)=>{if(r-o<=1)return 0;const s=o+r>>1;let a=n(o,s)+n(s,r),i=o,c=s,f=o;for(;i<s||c<r;)c>=r||i<s&&t[i]<=t[c]?e[f++]=t[i++]:(e[f++]=t[c++],a+=s-i);for(let n=o;n<r;n++)t[n]=e[n];return a},"count");return n(0,t.length)}function Ee(t){const e=ve(t),n=new Map;for(const t of e.nodes)n.set(t,[]);for(const t of e.edges)n.get(t.src).push(t);for(const t of n.values())t.sort((t,e)=>t.dst===e.dst?t.id.localeCompare(e.id):t.dst.localeCompare(e.dst));const o=Object.create(null);for(const t of e.nodes)o[t]=0;const r=[],s=(0,a.__name)(t=>{o[t]=1;for(const e of n.get(t)??[]){const t=e.dst;0===o[t]?s(t):1===o[t]&&r.push(e)}o[t]=2},"dfs"),i=[...e.nodes].sort((t,e)=>t.localeCompare(e));for(const t of i)0===o[t]&&s(t);const c=new Set(r.map(t=>`${t.id}:${t.src}->${t.dst}`)),f=e.edges.map(t=>c.has(`${t.id}:${t.src}->${t.dst}`)?{id:t.id,src:t.dst,dst:t.src,weight:t.weight,ref:t.ref}:t);return{acyclic:{nodes:[...e.nodes],edges:f,layout:e.layout,nodeById:new Map(e.nodeById)},reversed:r}}function Ye(t){const e=new Map,n=(0,a.__name)(o=>{if(e.has(o))return e.get(o);const r=t.nodeById.get(o);if(!r)return e.set(o,null),null;const s=r.parentId;if(!s)return e.set(o,null),null;const a=n(s)??s;return e.set(o,a),a},"resolve");for(const e of t.nodes)n(e);return e}function Xe(t){const e=Ye(t);return t=>e.get(t)??null}function ze(t){const e=[];for(const n of t.layout.nodes??[])n.isGroup&&!n.parentId&&e.push(n.id);return[...new Set(e)].reverse()}function Ae(t,e){const n=ze(t);if(!e||0===e.length)return n;const o=new Set(n),r=new Set,s=[];for(const t of e)o.has(t)&&!r.has(t)&&(r.add(t),s.push(t));for(const t of n)r.has(t)||s.push(t);return s}(0,a.__name)(_e,"pairKey"),(0,a.__name)(be,"straightenCollinearSiblingDetours"),(0,a.__name)(Me,"nudgeSharedInteriorSubpaths"),(0,a.__name)(Ie,"segmentsIntersect"),(0,a.__name)(Se,"validateSwimlanesLayout"),(0,a.__name)(we,"postProcessSwimlaneLayout"),(0,a.__name)(ve,"normalizeGraph"),(0,a.__name)(Ce,"incoming"),(0,a.__name)(Le,"buildSuccessorMap"),(0,a.__name)(ke,"buildSortedSuccessorMap"),(0,a.__name)(Oe,"buildInDegreeMap"),(0,a.__name)(Re,"sortedZeroInDegreeNodes"),(0,a.__name)(Te,"buildPredecessorSuccessorMaps"),(0,a.__name)($e,"buildLayersFromRanks"),(0,a.__name)(Ne,"topoSortIfAcyclic"),(0,a.__name)(Be,"buildLayerIndex"),(0,a.__name)(Fe,"countInversions"),(0,a.__name)(Ee,"removeCycles_DFS"),(0,a.__name)(Ye,"buildTopLaneMap"),(0,a.__name)(Xe,"createTopLaneResolver"),(0,a.__name)(ze,"buildTopLaneOrder"),(0,a.__name)(Ae,"resolveTopLaneOrder");var Pe=!0;function De(t,e){const n=ve(t),o=e?.laneOf??(()=>null),r=e?.rankHint,{preds:s}=Te(n);for(const t of s.values())t.sort((t,e)=>t.localeCompare(e));const i=Ne(n)??[...n.nodes].sort((t,e)=>t.localeCompare(e)),c=new Map;for(const[t,e]of i.entries())c.set(e,t);const f=new Map,d=new Map;for(const t of n.nodes)d.set(t,[]);for(const t of i){const e=(s.get(t)??[]).filter(t=>f.has(t));if(e.length>0){const n=Ge(t,e,{laneOf:o,rankHint:r,topoIndex:c});f.set(t,n),d.get(n).push(t)}else f.has(t)||f.set(t,null)}for(const t of n.nodes)f.has(t)||f.set(t,null);const l=new Set;for(const t of n.nodes)null===(f.get(t)??null)&&l.add(t);const u=[...l].sort((t,e)=>{const n=c.get(t)??0,o=c.get(e)??0;return n===o?t.localeCompare(e):n-o}),h=He(n),m=new Map;for(const[t,e]of h.entries())m.set(t,[...e].sort((t,e)=>t.localeCompare(e)));const g=je(m),p=Ve(m),x=new Map;for(const t of n.nodes)x.set(t,[]);for(const t of p)for(const e of t.nodes){const n=x.get(e);n?n.push(t.id):x.set(e,[t.id])}const y=[],_=[],b=new Set,M=(0,a.__name)(t=>{if(!b.has(t)){b.add(t),y.push(t);for(const e of d.get(t)??[])M(e);_.push(t)}},"walk");for(const t of u)M(t);for(const t of i)M(t);return{parent:f,children:d,roots:u,componentOf:g,blocks:p,nodeBlocks:x,adjacency:m,preorder:y,postorder:_,topologicalOrder:i}}function Ge(t,e,n){const o=n.laneOf(t);return[...e].sort((t,e)=>{const r=n.laneOf(t),s=n.laneOf(e),a=null!=r&&r===o;if(a!==(null!=s&&s===o))return a?-1:1;const i=n.rankHint?.[t],c=n.rankHint?.[e];if(null!=i&&null!=c&&i!==c)return c-i;const f=n.topoIndex.get(t)??0,d=n.topoIndex.get(e)??0;return f!==d?f-d:t.localeCompare(e)})[0]}function He(t){const e=new Map;for(const n of t.nodes)e.set(n,new Set);for(const n of t.edges)e.get(n.src).add(n.dst),e.get(n.dst).add(n.src);return e}function je(t){const e=new Map;let n=0;for(const o of t.keys()){if(e.has(o))continue;const r=[o];for(;r.length>0;){const o=r.pop();if(!e.has(o)){e.set(o,n);for(const n of t.get(o)??[])e.has(n)||r.push(n)}}n++}return e}function Ve(t){const e=new Map,n=new Map,o=[],r=[];let s=0;const i=(0,a.__name)((a,c)=>{e.set(a,++s),n.set(a,s);for(const f of t.get(a)??[])f!==c&&(e.has(f)?(e.get(f)??0)<(e.get(a)??0)&&(o.push([a,f]),n.set(a,Math.min(n.get(a)??s,e.get(f)??s))):(o.push([a,f]),i(f,a),n.set(a,Math.min(n.get(a)??s,n.get(f)??s)),(n.get(f)??0)>=(e.get(a)??0)&&r.push(We(a,f,o,r.length))))},"visit");for(const n of t.keys())e.has(n)||i(n,null);return r}function We(t,e,n,o){const r=[],s=new Set;for(;n.length>0;){const o=n.pop();if(r.push(o),s.add(o[0]),s.add(o[1]),o[0]===t&&o[1]===e||o[0]===e&&o[1]===t)break}return{id:o,edges:r,nodes:[...s]}}function Je(t,e,n){const o=[...t.nodes],r=new Map;for(const[t,e]of o.entries())r.set(e,t);const s=o.length,i=new Array(s).fill(-1),c=new Array(s).fill(0),f=[],d=new Set;for(const t of o){const e=n.parent.get(t)??null,o=r.get(t);null!=o&&null==e&&(i[o]=-1,c[o]=0,d.has(t)||(d.add(t),f.push(t)))}for(;f.length>0;){const t=f.shift(),e=r.get(t);if(null==e)continue;const o=n.children.get(t)??[];for(const t of o){if(d.has(t))continue;const n=r.get(t);null!=n&&(i[n]=e,c[n]=c[e]+1,d.add(t),f.push(t))}}for(const t of o){if(d.has(t))continue;const e=r.get(t);null!=e&&(i[e]=-1,c[e]=0,d.add(t))}const l=Math.max(1,Math.ceil(Math.log2(Math.max(1,s)))+1),u=Array.from({length:l},()=>new Array(s).fill(-1));for(let t=0;t<s;t++)u[0][t]=i[t];for(let t=1;t<l;t++)for(let e=0;e<s;e++){const n=u[t-1][e];u[t][e]=-1===n?-1:u[t-1][n]}const h=(0,a.__name)((t,e)=>{if(-1===t||-1===e)return-1;c[t]<c[e]&&([t,e]=[e,t]);const n=c[t]-c[e];for(let e=0;e<l;e++)if(n>>e&1&&-1===(t=u[e][t]))return-1;if(t===e)return t;for(let n=l-1;n>=0;n--){const o=u[n][t],r=u[n][e];-1!==o&&-1!==r&&o!==r&&(t=o,e=r)}return u[0][t]},"lcaIndex"),m=Array.from({length:s},()=>new Map);for(const n of t.edges){let t=n.src,o=n.dst,s=e[t],a=e[o];if(null==s||null==a)continue;if(s>a&&([t,o]=[o,t],[s,a]=[a,s]),null==s||null==a||s===a)continue;const i=r.get(t),c=r.get(o);if(null==i||null==c)continue;const f=h(i,c);if(-1===f)continue;const d=m[f];for(let t=s;t<a;t++)d.set(t,(d.get(t)??0)+1)}const g=new Map,p=(0,a.__name)((t,e)=>{if(0!==e.size)for(const[n,o]of e)t.set(n,(t.get(n)??0)+o)},"mergeInto"),x=new Set,y=(0,a.__name)(t=>{const o=r.get(t);x.add(t);const s=null==o?void 0:m[o],a=s?new Map(s):new Map,i=n.children.get(t)??[];for(const n of i){const o=y(n),r=e[t];if(null!=r){let s=g.get(t);s||(s=new Map,g.set(t,s));let a=o.get(r)??0;const i=e[n];null!=i&&i>r&&(a+=1),s.set(n,a)}p(a,o)}return a},"dfs");for(const t of n.roots)x.has(t)||y(t);for(const t of o)x.has(t)||y(t);return g}function qe(t,e,n){const o=new Map,r=(0,a.__name)(t=>{let s=n[t]??0;const a=[...e.get(t)??[]];a.sort(Ke(n));for(const t of a){r(t);const e=o.get(t);null!=e&&(s=Math.min(s,e))}o.set(t,s)},"annotate");for(const e of t)r(e);return o}function Ke(t){return(e,n)=>{const o=t[e]??0,r=t[n]??0;return o===r?e.localeCompare(n):o-r}}function Qe(t,e,n,o){let r=0;for(const t of e){const e=n[t]??0;e>r&&(r=e)}const s=Array.from({length:r+1},()=>[]),i=new Set,c=(0,a.__name)(t=>{if(i.has(t))return;i.add(t);const e=n[t]??0;s[e]||(s[e]=[]),s[e].push(t);for(const e of o(t))c(e)},"emit");for(const e of t)c(e);for(const t of e)if(!i.has(t)){const e=n[t]??0;s[e]||(s[e]=[]),s[e].push(t),i.add(t)}return s}function Ue(t){const e=[];for(const n of t){const t=new Set,o=[];for(const e of n)t.has(e)||(t.add(e),o.push(e));e.push(o)}return e}function Ze(t,e,n,o){return r=>{const s=t.get(r)??[];if(0===s.length)return[];const a=e[r]??0,i=[],c=[],f=n.get(r);for(const t of s){const e=o.get(t)??a;e>a?i.push({child:t,min:e}):c.push(t)}return i.sort((t,e)=>t.min===e.min?t.child.localeCompare(e.child):t.min-e.min),c.sort((t,e)=>{const n=f?.get(t)??0,r=f?.get(e)??0;if(n!==r)return n-r;const s=o.get(t)??a,i=o.get(e)??a;return s!==i?s-i:t.localeCompare(e)}),[...i.map(t=>t.child),...c]}}function tn(t,e,n){const o=De(t,{rankHint:e,laneOf:n}),{children:r,roots:s}=o;for(const e of t.nodes)r.has(e)||r.set(e,[]);const a=Je(t,e,o),i=[...s].sort(Ke(e)),c=Ze(r,e,a,qe(i,r,e));let f=Qe(i,t.nodes,e,c);return f=Ue(f),f}function en(t,e,n){const o=new Set(t),r=new Set(e),s=Be(e),a=[];for(const t of n)o.has(t.src)&&r.has(t.dst)&&a.push(s.get(t.dst));return Fe(a)}function nn(t,e,n){const o=[];for(const t of e){const e=n[t.src],r=n[t.dst];if(null==e||null==r||e===r)continue;let s=t.src,a=t.dst,i=e,c=r;e>r&&(s=t.dst,a=t.src,i=r,c=e);for(let e=i;e<c;e++)o.push({id:`${t.id}@${e}`,src:s,dst:a,ref:t.ref})}let r=0;for(let e=0;e+1<t.length;e++)r+=en(t[e],t[e+1],o);return r}function on(t,e){const n={...e},{preds:o}=Te(t),r=Xe(t);let s=nn(tn(t,n,r),t.edges,n);for(let e=0;e<4;e++){let e=!1;const a=[...t.nodes].sort((t,e)=>(n[e]??0)-(n[t]??0));for(const i of a){const a=n[i]??0;if(0===a)continue;let c=0;for(const t of o.get(i)??[])c=Math.max(c,(n[t]??0)+1);if(c>=a)continue;const f=a;n[i]=c;const d=nn(tn(t,n,r),t.edges,n);d<s?(s=d,e=!0):n[i]=f}if(!e)break}return n}function rn(t,e){const n=Xe(t),o=[...t.nodes].sort((t,n)=>(e[t]??0)-(e[n]??0)||t.localeCompare(n));for(const r of o){const o=n(r);if(!o)continue;const s=t.edges.filter(t=>t.src===r);if(0===s.length)continue;let a=!1,i=0;for(const t of s){const e=n(t.dst);null==e||e===o?a=!0:i++}if(0===i||a)continue;let c=0,f=!1;for(const e of t.edges){if(e.dst!==r)continue;const t=n(e.src);t&&(t===o?f=!0:c++)}if(c>0||!f)continue;const d=e[r]??0,l=d+i;let u=0;for(const n of t.edges)n.dst===r&&(u=Math.max(u,(e[n.src]??0)+1));const h=Math.max(d,u,l);h!==d&&(e[r]=h)}}function sn(t,e){const n=ve(t),o=Ne(n)??[...n.nodes].sort(),r=e?.compactSingleInput??!1,s=Xe(n);let a=Object.create(null);for(const t of o){const o=Ce(n,t),i=e?.ignoreCrossLaneEdges?o.filter(e=>{const n=s(e.src),o=s(t);return!n||!o||n===o}):o;if(0===i.length)a[t]=0;else if(r&&1===i.length){const e=i[0].src,n=s(e),o=s(t);a[t]=n!==o?a[e]??0:(a[e]??0)+1}else{let e=-1/0;for(const t of i)e=Math.max(e,(a[t.src]??0)+1);a[t]=e===-1/0?0:e}}return e?.optimizeRanksByCrossings&&(a=on(n,a)),e?.ignoreCrossLaneEdges&&rn(n,a),{layers:tn(n,a,s),rankOf:a,dummy:new Set}}function an(t,e){const n=ve(t),o={...sn(n,{compactSingleInput:e?.compactSingleInput,ignoreCrossLaneEdges:e?.ignoreCrossLaneEdges,optimizeRanksByCrossings:e?.optimizeRanksByCrossings}).rankOf},r=Xe(n),{preds:s,succs:i}=Te(n,t=>{if(e?.ignoreCrossLaneEdges){const e=r(t.src),n=r(t.dst);if(e&&n&&e!==n)return!1}return!0}),c=Ne(n)??[...n.nodes],f=[...c].reverse(),d=(0,a.__name)((t,e)=>{let n=0;for(const e of s.get(t)??[])n=Math.max(n,(o[e]??0)+1);let r=Number.POSITIVE_INFINITY;const a=i.get(t)??[];return a.length>0&&(r=Math.min(...a.map(t=>(o[t]??0)-1))),Number.isFinite(r)||(r=Math.max(n,e)),Math.min(Math.max(e,n),r)},"clampFeasible"),l=(0,a.__name)(t=>{let e=!1;for(const n of t){const t=s.get(n)??[],r=i.get(n)??[];if(0===t.length&&0===r.length)continue;const a=t.length>0?t.reduce((t,e)=>t+(o[e]??0)+1,0)/t.length:o[n]??0,c=r.length>0?r.reduce((t,e)=>t+(o[e]??0)-1,0)/r.length:o[n]??0,f=Math.round((a+c)/2),l=d(n,f);l!==o[n]&&(o[n]=l,e=!0)}return e},"relaxOrder");for(let t=0;t<8;t++){const t=l(c),e=l(f);if(!t&&!e)break}for(const t of c){let e=0;for(const n of s.get(t)??[])e=Math.max(e,(o[n]??0)+1);(o[t]??0)<e&&(o[t]=e)}for(const t of f){const e=i.get(t)??[];if(e.length>0){const n=Math.min(...e.map(t=>(o[t]??0)-1));(o[t]??0)>n&&(o[t]=n)}}return{layers:$e(n,c,o),rankOf:o,dummy:new Set}}function cn(t){const e=Oe(t),n=ke(t);let o=Re(e);const r=[];for(;o.length>0;){const t=[];for(const s of o){r.push(s);for(const o of n.get(s)??[])e.set(o,(e.get(o)??0)-1),0===(e.get(o)??0)&&t.push(o)}o=t.sort((t,e)=>t.localeCompare(e))}return r.length===t.nodes.length?r:null}function fn(t,e){const n=ve(t),o="LR"===e?.direction?cn(n)??[...n.nodes].sort():Ne(n)??[...n.nodes].sort(),r=Xe(n),s=(0,a.__name)(t=>r(t)??t,"laneOf"),i=Object.create(null),c=new Map,f=(0,a.__name)((t,n)=>e?.ignoreCrossLaneEdges??1?s(t)===s(n)?1:0:1,"edgeWeight");for(const t of o){const e=n.nodeById.get(t);if(e?.isGroup)continue;const o=Ce(n,t);let r=0;if(o.length>0)for(const e of o){const n=e.src,o=i[n]??0;r=Math.max(r,o+f(n,t))}const a=s(t),d=c.get(a)??0,l=Math.max(r,d);i[t]=l,c.set(a,l+1)}return{layers:$e(n,o,i,{skipGroups:!0}),rankOf:i,dummy:new Set}}function dn(t,e){const n=ve(e),{rankOf:o}=t,r=t.layers.map(t=>[...t]),s=new Set(t.dummy?[...t.dummy]:[]);let i=0;const c=new Map(n.nodeById),f=(0,a.__name)(t=>{const e="placeholder-"+i++,n={id:e,isGroup:!1,isDummy:!0,width:0,height:0};for(c.set(e,n),s.add(e);r.length<=t;)r.push([]);return r[t].push(e),o[e]=t,e},"addDummyAt"),d=[...n.edges].sort((t,e)=>t.id===e.id?t.src===e.src?t.dst.localeCompare(e.dst):t.src.localeCompare(e.src):t.id.localeCompare(e.id)),l=[];for(const t of d){const e=o[t.src]??0,n=o[t.dst]??0;if(n-e<=1){l.push(t);continue}let r=t.src;for(let o=e+1,s=0;o<n;o++,s++){const e=f(o);l.push({id:`${t.id}#${s}`,src:r,dst:e,weight:t.weight,ref:t.ref}),r=e}const s=n-e-2;l.push({id:`${t.id}#${Math.max(s+1,0)}`,src:r,dst:t.dst,weight:t.weight,ref:t.ref})}const u={nodes:[...n.nodes,...[...s].filter(t=>!n.nodes.includes(t))],edges:l,layout:n.layout,nodeById:c};return{layering:{layers:r,rankOf:o,dummy:s},graphWithDummies:u}}function ln(t){const e=t.length;if(0===e)return Number.POSITIVE_INFINITY;const n=[...t].sort((t,e)=>t-e);return e%2==1?n[(e-1)/2]:.5*(n[e/2-1]+n[e/2])}function un(t){return 0===t.length?Number.POSITIVE_INFINITY:t.reduce((t,e)=>t+e,0)/t.length}function hn(t,e,n,o){const r=new Map;for(const e of t)r.set(e,[]);for(const t of n)"down"===o?e.has(t.src)&&r.has(t.dst)&&r.get(t.dst).push(e.get(t.src)):e.has(t.dst)&&r.has(t.src)&&r.get(t.src).push(e.get(t.dst));return r}function mn(t,e,n){const o=n.get(t)??0,r=n.get(e)??0;return o!==r?o-r:t.localeCompare(e)}function gn(t,e,n){const o=new Set(t),r=new Set(e),s=Be(t),a=Be(e),i=[];for(const t of n)o.has(t.src)&&r.has(t.dst)&&i.push({u:s.get(t.src),v:a.get(t.dst)});return i.sort((t,e)=>t.u===e.u?t.v-e.v:t.u-e.u),Fe(i.map(t=>t.v))}function pn(t,e,n){return[...t].sort((t,o)=>{const r=ln(e.get(t)??[]),s=ln(e.get(o)??[]);return r===s?mn(t,o,n):isFinite(r)?isFinite(s)?r-s:-1:1})}function xn(t,e,n,o,r,s){const a=Be(t),i=Be(e),c=hn(e,a,n,o);if(!r||!s||0===s.length)return pn(e,c,i);const f=new Map;for(const t of e){const e=r(t),n=f.get(e)??[];n.push(t),f.set(e,n)}const d=[];for(const t of s){const e=f.get(t);if(!e||0===e.length)continue;const n=pn(e,c,i);d.push(...n)}const l=f.get(null);if(l&&l.length>0){const t=pn(l,c,i);for(const e of t){const t=un(c.get(e)??[]);let n=d.length;if(isFinite(t))for(const[e,o]of d.entries())if(t<un(c.get(o)??[])){n=e;break}d.splice(n,0,e)}}return d}function yn(t,e,n,o,r){const s=[...e],i=new Set(t),c=new Set(e),f=o?new Set(o):null,d=n.filter(t=>i.has(t.src)&&c.has(t.dst)),l=f?n.filter(t=>c.has(t.src)&&f.has(t.dst)):void 0,u=(0,a.__name)(e=>{let n=gn(t,e,d);return l&&o&&(n+=gn(e,o,l)),n},"crossingScore"),h=r?new Map:null;if(r&&h)for(const t of e)h.set(t,r(t));let m=!0,g=u(s);for(;m;){m=!1;for(let t=0;t+1<s.length;t++){if(h&&h.get(s[t])!==h.get(s[t+1]))continue;const e=g;[s[t],s[t+1]]=[s[t+1],s[t]];const n=u(s);n<e?(g=n,m=!0):[s[t],s[t+1]]=[s[t+1],s[t]]}}return s}function _n(t,e,n){const o=t.layers.map(t=>[...t]),r=e.edges,s=Xe(e),a=Ae(e,n?.laneOrder);for(let t=0;t<3;t++){for(let t=1;t<o.length;t++)o[t]=xn(o[t-1],o[t],r,"down",s,a),o[t]=yn(o[t-1],o[t],r,o[t+1],s);for(let t=o.length-2;t>=0;t--)o[t]=xn(o[t+1],o[t],r,"up",s,a),o[t]=yn(o[t+1],o[t],r,o[t-1],s)}return{layers:o}}function bn(t,e,n){const o=n?.layerGap??100,r=n?.nodeGap??40,s=n?.laneGap??2*r,i=n?.direction??"TB",c="LR"===i||"RL"===i,f=t.layers,d=Object.create(null),l=Object.create(null),u=(0,a.__name)(t=>e.nodeById.get(t),"getNode"),h=(0,a.__name)(t=>u(t)?.width??0,"getWidth"),m=(0,a.__name)(t=>u(t)?.height??0,"getHeight"),g=Xe(e),p=Ae(e,n?.laneOrder),x=f.map(t=>t.reduce((t,e)=>Math.max(t,m(e)),0)),y=[];if(c)for(let t=0;t+1<f.length;t++){const e=f[t].reduce((t,e)=>Math.max(t,h(e)),0),n=f[t+1].reduce((t,e)=>Math.max(t,h(e)),0),r=x[t]/2+x[t+1]/2,s=(e+n)/2,a=Math.max(0,s-r-o);y.push(a)}const _=new Set;for(const t of f)for(const e of t)_.add(g(e));const b=_.has(null),M=p.filter(t=>_.has(t)),I=[...b?[null]:[],...M],S=Object.create(null);for(const t of M)S[t]=0;b&&(S.null=0);for(const t of f){const e=Object.create(null),n=[];for(const o of t){const t=g(o);null===t?n.push(o):(e[t]||=[]).push(o)}for(const[t,n]of Object.entries(e)){const e=n.reduce((t,e)=>t+h(e),0)+r*Math.max(0,n.length-1);S[t]=Math.max(S[t]??0,e)}if(b&&n.length){const t=n.reduce((t,e)=>t+h(e),0)+r*Math.max(0,n.length-1);S.null=Math.max(S.null??0,t)}}const w=new Map;{const t=I.map(t=>(null===t?S.null:S[t])??0);let e=-(t.reduce((t,e)=>t+e,0)+s*Math.max(0,I.length-1))/2;for(let n=0;n<I.length;n++){const o=I[n],r=t[n]??0,a=e+r/2;w.set(o,a),e+=r,n<I.length-1&&(e+=s)}}let v=0;for(const[t,e]of f.entries()){const n=x[t]??0,s=new Map;for(const t of e){const e=g(t),n=s.get(e)??[];n.push(t),s.set(e,n)}for(const t of I){const e=s.get(t)??[];if(0===e.length)continue;const o=w.get(t);if(1===e.length){const t=e[0];d[t]=o,l[t]=v+n/2}else{const t=e.map(t=>h(t));let s=o-(t.reduce((t,e)=>t+e,0)+r*(e.length-1))/2;for(const[o,a]of e.entries()){const e=t[o];d[a]=s+e/2,l[a]=v+n/2,s+=e+r}}}v+=n+o+(y[t]??0)}const C=new Map;for(const t of e.edges){const e=t.ref.id;C.has(e)||C.set(e,[]),C.get(e).push(t)}for(const[,t]of C){if(0===t.length)continue;const n=t[0].ref,o=n.start,r=n.end;if(null==o||null==r)continue;const s=Math.round(((d[o]??0)+(d[r]??0))/2),a=new Set;for(const e of t)a.add(e.src),a.add(e.dst);for(const t of a){if(t===o||t===r)continue;const n=e.nodeById.get(t);n?.isDummy&&(d[t]=s)}}return{x:d,y:l}}function Mn(t){let e=2166136261;for(let n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return e>>>0}function In(t){let e=t>>>0;return()=>{e+=1831565813;let t=e;return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296}}function Sn(t,e){const n=[...t],o=In(e);for(let t=n.length-1;t>0;t--){const e=Math.floor(o()*(t+1));[n[t],n[e]]=[n[e],n[t]]}return n}function wn(t,e){let n=0;for(const[o,r]of t.entries())n+=Math.abs(o-(e.get(r)??o));return n}function vn(t,e){const n=new Map;for(const[e,o]of t.entries())n.set(o,e);let o=0;for(const{a:t,b:r,weight:s}of e){const e=n.get(t),a=n.get(r);null!=e&&null!=a&&(o+=s*Math.abs(e-a))}return o}function Cn(t){const e=ze(t);if(e.length<2)return[];const n=new Map(e.map((t,e)=>[t,e])),o=Xe(t),r=new Map;for(const e of t.layout.edges??[]){if(e.isLayoutOnly)continue;const s="string"==typeof e.start?e.start:void 0,a="string"==typeof e.end?e.end:void 0;if(!(s&&a&&t.nodeById.has(s)&&t.nodeById.has(a)))continue;const i=o(s),c=o(a);if(!i||!c||i===c)continue;const f=n.get(i),d=n.get(c);if(null==f||null==d)continue;const[l,u]=f<=d?[i,c]:[c,i],h=`${l}\0${u}`,m=r.get(h);m?m.weight++:r.set(h,{a:l,b:u,weight:1})}return[...r.values()]}function Ln(t,e,n){const o=[...t];let r=vn(o,e),s=!0,a=0;const i=Math.max(1,o.length);for(;s&&a<i;){s=!1,a++;for(let t=0;t+1<o.length;t++){[o[t],o[t+1]]=[o[t+1],o[t]];const n=vn(o,e);n<r?(r=n,s=!0):[o[t],o[t+1]]=[o[t+1],o[t]]}}return{order:o,cost:r,sourceDistance:wn(o,n)}}function kn(t,e){return t.cost!==e.cost?t.cost<e.cost:t.sourceDistance<e.sourceDistance}function On(t,e,n){const o=[...e].sort((t,e)=>t.a===e.a?t.b.localeCompare(e.b):t.a.localeCompare(e.a)).map(({a:t,b:e,weight:n})=>`${t}:${e}:${n}`).join("|");return Mn(`${t.join("|")}#${o}#${n}`)}function Rn(t,e={}){const n=ze(t);if(n.length<2)return n;const o=Cn(t);if(0===o.length)return n;const r=new Map(n.map((t,e)=>[t,e]));let s=Ln(n,o,r);const a=Math.max(0,e.restarts??8);for(let t=0;t<a;t++){const e=Ln(Sn(n,On(n,o,t)),o,r);kn(e,s)&&(s=e)}return s.order}function Tn(t,e){const n=e?.ignoreCrossLaneEdges??!0,o=e?.optimizeRanksByCrossings??!0,r=ve(t),s=e?.automaticLaneOrdering?Rn(r,{restarts:8}):void 0,a=Ee(r),i=a.acyclic,c=n?fn(i,{compactSingleInput:e?.compactSingleInput??Pe,ignoreCrossLaneEdges:!0,direction:e?.direction}):an(i,{compactSingleInput:e?.compactSingleInput??Pe,ignoreCrossLaneEdges:!1,optimizeRanksByCrossings:o}),{layering:f,graphWithDummies:d}=dn(c,i),l=_n(f,d,{laneOrder:s}),u=bn(l,d,{layerGap:e?.layerGap,nodeGap:e?.nodeGap,direction:e?.direction,laneOrder:s});return{acyclic:i,reversed:a.reversed,layering:f,ordered:l,coordinates:u}}(0,a.__name)(De,"buildDrivingTree"),(0,a.__name)(Ge,"chooseParent"),(0,a.__name)(He,"buildAdjacency"),(0,a.__name)(je,"assignComponents"),(0,a.__name)(Ve,"computeBlocks"),(0,a.__name)(We,"popBlock"),(0,a.__name)(Je,"computeSubtreeCrossCounts"),(0,a.__name)(qe,"annotateMinimumLayers"),(0,a.__name)(Ke,"compareByRankThenId"),(0,a.__name)(Qe,"emitNodesInTreeOrder"),(0,a.__name)(Ue,"deduplicateLayers"),(0,a.__name)(Ze,"createChildOrderer"),(0,a.__name)(tn,"buildMultitreeLayerOrder"),(0,a.__name)(en,"countCrossingsBetweenAdjacent"),(0,a.__name)(nn,"totalCrossings"),(0,a.__name)(on,"optimizeRanksByCrossings"),(0,a.__name)(rn,"adjustCrossLaneSources"),(0,a.__name)(sn,"assignLayers_LongestPath"),(0,a.__name)(an,"assignLayers_Gravity"),(0,a.__name)(cn,"topoSortByGenerationIfAcyclic"),(0,a.__name)(fn,"assignLayers_LaneAwareCompact"),(0,a.__name)(dn,"makeProperLayering"),(0,a.__name)(ln,"median"),(0,a.__name)(un,"barycenter"),(0,a.__name)(hn,"neighborPositionsFor"),(0,a.__name)(mn,"currentOrderTieBreak"),(0,a.__name)(gn,"countCrossingsBetweenAdjacent"),(0,a.__name)(pn,"sortByHeuristic"),(0,a.__name)(xn,"reorderLayer"),(0,a.__name)(yn,"transposeImprove"),(0,a.__name)(_n,"orderLayers"),(0,a.__name)(bn,"assignCoordinates"),(0,a.__name)(Mn,"hashString"),(0,a.__name)(In,"mulberry32"),(0,a.__name)(Sn,"deterministicShuffle"),(0,a.__name)(wn,"sourceDistance"),(0,a.__name)(vn,"laneArrangementCost"),(0,a.__name)(Cn,"buildWeightedLaneEdges"),(0,a.__name)(Ln,"greedySwitch"),(0,a.__name)(kn,"isBetterCandidate"),(0,a.__name)(On,"seedForRestart"),(0,a.__name)(Rn,"optimizeTopLaneOrder"),(0,a.__name)(Tn,"sugiyamaLayout");var $n=1e-6,Nn=15,Bn=15,Fn=20;function En(t,e,n){const o=t.x??0,r=t.y??0,s=e.x-o,a=e.y-r,i=Math.abs(s),c=Math.abs(a);return i<$n&&c<$n?n:c>$n&&3*c>=i?a>0?"bottom":"top":i>$n?s>0?"right":"left":n}function Yn(t,e){return Math.abs(t.to-e.from)<$n||Math.abs(t.to-e.to)<$n?t.to:t.from}function Xn(t,e){return"vertical"===t.orient?{x:t.coord,y:e}:{x:e,y:t.coord}}function zn(t,e){const n=t.nodes??[],o=t.edges??[],r=[];for(const t of o)t.isLayoutOnly||r.push({...t,__originalEdge:t});const s=new Map,i=new Map,c=[],f="LR"===e;for(const t of n)s.set(t.id,t);const d=n.filter(t=>t.isGroup&&!t.parentId);for(const t of d){const e={id:t.id},o=(0,a.__name)(t=>{i.set(t.id,e),n.filter(e=>e.parentId===t.id).forEach(o)},"assignLane");o(t)}const l=n.filter(t=>!t.isGroup&&!t.isEdgeLabel).map(t=>{const e=t.width??10,n=t.height??10,o=t.x??0,r=t.y??0;return{nodeId:t.id,minX:o-e/2-8,maxX:o+e/2+8,minY:r-n/2-8,maxY:r+n/2+8,visualXHalfExtent:f?n/2+8:e/2+8}}),u=(0,a.__name)((t,e,n,o)=>{let r=c.find(n=>n.orientation===t&&Math.abs(n.coord-e)<1);return r||(r={id:`pipe-${t}-${e.toFixed(0)}`,orientation:t,coord:e,spanMin:n,spanMax:o,tracks:[]},c.push(r)),r.spanMin=Math.min(r.spanMin,n),r.spanMax=Math.max(r.spanMax,o),r},"getOrAddPipe"),h=(0,a.__name)((t,e)=>{const n=t.width??10,o=t.height??10,r=t.x??0,s=t.y??0;switch(e){case"top":return{x:r,y:s-o/2};case"bottom":return{x:r,y:s+o/2};case"left":return{x:r-n/2,y:s};case"right":return{x:r+n/2,y:s}}},"portForSide"),m=(0,a.__name)((t,e,n)=>h(t,En(t,e,n?"bottom":"top")),"getOrthogonalPort"),g=[],p=[],x=new Set,y=(0,a.__name)((t,e,n)=>{if(0===g.length)return 0;const o=Math.abs(e.y-n.y)<$n,r=Math.abs(e.x-n.x)<$n;if(!o&&!r)return 0;let s=0;if(o){const o=e.y,r=Math.min(e.x,n.x)-$n,a=Math.max(e.x,n.x)+$n;if(a<=r)return 0;for(const e of g)e.edgeIndex!==t&&"vertical"===e.orientation&&(e.pipe.coord<r||e.pipe.coord>a||e.from-$n<=o&&e.to+$n>=o&&(s+=1e3))}else if(r){const o=e.x,r=Math.min(e.y,n.y)-$n,a=Math.max(e.y,n.y)+$n;if(a<=r)return 0;for(const e of g)e.edgeIndex!==t&&"horizontal"===e.orientation&&(e.pipe.coord<r||e.pipe.coord>a||e.from-$n<=o&&e.to+$n>=o&&(s+=1e3))}return s},"crossingPenalty"),_=r.map((t,e)=>{if(!t.start||!t.end)return{idx:e,crossLane:0,dx:0,dy:0};const n=s.get(t.start),o=s.get(t.end),r=i.get(t.start),a=i.get(t.end);return{idx:e,crossLane:r&&a&&r.id!==a.id?1:0,dx:n&&o?Math.abs((o.x??0)-(n.x??0)):0,dy:n&&o?Math.abs((o.y??0)-(n.y??0)):0}}).sort((t,e)=>{if(t.crossLane!==e.crossLane)return e.crossLane-t.crossLane;const n=t.dx+t.dy,o=e.dx+e.dy;return Math.abs(n-o)>1?n-o:t.idx-e.idx}).map(t=>t.idx),b=(0,a.__name)((t,e,n,o)=>{const r=Math.min(t.x,e.x),s=Math.max(t.x,e.x),a=Math.min(t.y,e.y),i=Math.max(t.y,e.y);return!!l.find(c=>!(n&&c.nodeId===n||o&&c.nodeId===o||!(Math.abs(t.x-e.x)>$n?c.minY<t.y&&c.maxY>t.y&&c.maxX>r&&c.minX<s:c.minX<t.x&&c.maxX>t.x&&c.maxY>a&&c.minY<i)))},"isSegmentBlocked"),M=new Map,I=new Map;for(const t of r)t.start&&t.end&&t.start!==t.end&&(I.set(t.start,(I.get(t.start)??0)+1),I.set(t.end,(I.get(t.end)??0)+1));const S=(0,a.__name)((t,e)=>En(t,e,"bottom"),"determineSide"),w=new Map;for(const[t,e]of r.entries()){if(!e.start||!e.end||e.start===e.end)continue;if(e.points&&e.points.length>0)continue;const n=s.get(e.start),o=s.get(e.end);if(!n||!o)continue;const r=(o.x??0)-(n.x??0),a=(o.y??0)-(n.y??0);w.set(t,{edgeIdx:t,srcId:e.start,dstId:e.end,srcSide:S(n,{x:o.x??0,y:o.y??0}),dstSide:S(o,{x:n.x??0,y:n.y??0}),absDx:Math.abs(r),absDy:Math.abs(a),dxSign:Math.sign(r),dySign:Math.sign(a)})}const v=(0,a.__name)(t=>"top"===t.srcSide||"bottom"===t.srcSide?0===t.absDx?1/0:t.absDy/t.absDx:0===t.absDy?1/0:t.absDx/t.absDy,"preferenceStrength"),C=(0,a.__name)(t=>"top"===t.srcSide||"bottom"===t.srcSide?t.dxSign>=0?"right":"left":t.dySign>=0?"bottom":"top","secondarySide"),L=new Map;for(const t of w.values()){const e=`${t.srcId}:${t.srcSide}`;L.has(e)||L.set(e,[]),L.get(e).push(t)}const k=new Map,O=(0,a.__name)((t,e)=>`${t}:${e}`,"loadKey");for(const t of w.values())k.set(O(t.srcId,t.srcSide),(k.get(O(t.srcId,t.srcSide))??0)+1),k.set(O(t.dstId,t.dstSide),(k.get(O(t.dstId,t.dstSide))??0)+1);for(const t of L.values())if(!(t.length<2)){t.sort((t,e)=>{const n=v(t),o=v(e);return Math.abs(n-o)>1e-9?o-n:t.edgeIdx-e.edgeIdx});for(let e=1;e<t.length;e++){const n=t[e],o=C(n),r=k.get(O(n.srcId,n.srcSide))??0,s=k.get(O(n.srcId,o))??0;s>=r||(k.set(O(n.srcId,n.srcSide),r-1),k.set(O(n.srcId,o),s+1),n.srcSide=o)}}const R=(0,a.__name)(t=>{const e=t?.shape;return"question"===e||"diamond"===e},"isDiamondNode"),T=new Map;for(const t of w.values())T.has(t.dstId)||T.set(t.dstId,new Set),T.get(t.dstId).add(t.dstSide);for(const t of w.values()){if(!R(s.get(t.srcId)))continue;const e=T.get(t.srcId);if(!e?.has(t.srcSide))continue;const n=C(t);if(e.has(n)||(k.get(O(t.srcId,n))??0)>0)continue;const o=k.get(O(t.srcId,t.srcSide))??0;k.set(O(t.srcId,t.srcSide),Math.max(0,o-1)),k.set(O(t.srcId,n),1),t.srcSide=n}for(const t of w.values()){const{edgeIdx:e,srcId:n,dstId:o,srcSide:r,dstSide:a}=t,i=s.get(n),c=s.get(o),f=`${n}:${r}:src`,d="top"===r||"bottom"===r?c.x??0:c.y??0;M.has(f)||M.set(f,[]),M.get(f).push({edgeIdx:e,oppositeCoord:d});const l=`${o}:${a}:dst`,u="top"===a||"bottom"===a?i.x??0:i.y??0;M.has(l)||M.set(l,[]),M.get(l).push({edgeIdx:e,oppositeCoord:u})}const $=new Map;for(const[t,e]of M){if(e.length<2)continue;e.sort((t,e)=>t.oppositeCoord-e.oppositeCoord);const n=t.split(":"),o=n.slice(0,-2).join(":"),r=n[n.length-2],a=n[n.length-1],i=s.get(o);if(!i)continue;const c="left"===r||"right"===r?i.height??10:i.width??10,f=i.shape,d="question"===f||"diamond"===f?.3*c:c,l=20,u=Math.min(l,Math.max(8,d/(e.length+1))),h=-u*(e.length-1)/2;for(const[t,n]of e.entries()){const e=h+t*u,o=`${n.edgeIdx}:${a}`;$.set(o,e)}}const N=(0,a.__name)(t=>Boolean(r[t]?.labelNodeId),"edgeHasLabelNode"),B=(0,a.__name)((t,e)=>!!t&&((M.get(`${t}:${e}:src`)??[]).some(({edgeIdx:t})=>N(t))||(M.get(`${t}:${e}:dst`)??[]).some(({edgeIdx:t})=>N(t))),"faceHasLabelNode"),F=(0,a.__name)((t,e,n)=>"top"===e||"bottom"===e?{x:t.x+n,y:t.y}:{x:t.x,y:t.y+n},"applyPortOffset"),E=(0,a.__name)((t,e,n)=>{const o=w.get(t),r={x:n.x??0,y:n.y??0},s={x:e.x??0,y:e.y??0},a=o?.srcSide??S(e,r),i=o?.dstSide??S(n,s);let c=o?h(e,o.srcSide):m(e,r,!0),f=o?h(n,o.dstSide):m(n,s,!1);const d=$.get(`${t}:src`),l=$.get(`${t}:dst`);return void 0!==d&&(c=F(c,a,d)),void 0!==l&&(f=F(f,i,l)),{pSrcPort:c,pDstPort:f,srcSide:a,dstSide:i}},"portsForEdge");for(const t of _){const e=r[t];if(p[t]=[],!e.start||!e.end)continue;if(e.points&&e.points.length>0)continue;if(e.start===e.end)continue;const n=s.get(e.start),o=s.get(e.end);if(!n||!o)continue;const{pSrcPort:i,pDstPort:d,srcSide:h,dstSide:m}=E(t,n,o),_={...i},S={...d},w="top"===h||"bottom"===h,v="top"===m||"bottom"===m;if(w){const t=i.y>(n.y??0);_.y=t?i.y+Fn:i.y-Fn}else{const t=i.x>(n.x??0);_.x=t?i.x+Fn:i.x-Fn}if(v){const t=d.y>(o.y??0);S.y=t?d.y+Fn:d.y-Fn}else{const t=d.x>(o.x??0);S.x=t?d.x+Fn:d.x-Fn}const C=(0,a.__name)((t,e)=>{for(const n of l)if(!e.includes(n.nodeId)&&t.x>n.minX&&t.x<n.maxX&&t.y>n.minY&&t.y<n.maxY)return{inside:!0,obstacle:n};return{inside:!1}},"isPointInObstacle"),L=(0,a.__name)((t,e,n,o,r)=>{if(r){const r=t.y>(e.y??0);return{x:(n.x??0)>=t.x?o.maxX+Nn:o.minX-Nn,y:r?o.maxY+Bn:o.minY-Bn,leavesPositiveSide:r}}const s=t.x>(e.x??0),a=(n.y??0)>=t.y;return{x:s?o.maxX+Nn:o.minX-Nn,y:a?o.maxY+Bn:o.minY-Bn,leavesPositiveSide:s}},"obstacleDetour");let k=[];const O=[e.start,e.end],R=C(_,O);if(R.inside&&R.obstacle){const t=R.obstacle;if(w){const e=L(i,n,o,t,!0);_.x=e.x,_.y=e.y;const r=e.leavesPositiveSide?Math.min(t.minY-2,i.y+Fn):Math.max(t.maxY+2,i.y-Fn);k=[{x:i.x,y:r},{x:e.x,y:r},{x:e.x,y:e.y}]}else{const e=L(i,n,o,t,!1),r=e.leavesPositiveSide?Math.min(t.minX-2,i.x+Fn):Math.max(t.maxX+2,i.x-Fn);_.x=e.x,_.y=e.y,k=[{x:r,y:i.y},{x:r,y:e.y},{x:e.x,y:e.y}]}}let T=[];const N=C(S,O);if(N.inside&&N.obstacle){const t=N.obstacle;if(v){const e=L(d,o,n,t,!0);S.x=e.x,S.y=e.y,T=[{x:e.x,y:e.y},{x:d.x,y:e.y}]}else{const e=L(d,o,n,t,!1);S.x=e.x,S.y=e.y,T=[{x:e.x,y:e.y},{x:e.x,y:d.y}]}}if(0===k.length&&0===T.length){const n=Nn,o=Math.abs(_.x-S.x)<n,r=Math.abs(_.y-S.y)<n,s=void 0!==$.get(`${t}:src`)||void 0!==$.get(`${t}:dst`),a=(M.get(`${e.start??""}:${h}:src`)?.length??0)+(M.get(`${e.start??""}:${h}:dst`)?.length??0),c=(M.get(`${e.end??""}:${m}:src`)?.length??0)+(M.get(`${e.end??""}:${m}:dst`)?.length??0),f=a>1||c>1,l=I.get(e.start??"")??0,u=I.get(e.end??"")??0,p=a>1&&B(e.start,h)||c>1&&B(e.end,m);if((o||r)&&!s&&(!f||f&&!p&&(a<=1||l<=2)&&(c<=1||u<=2))&&!b(i,d,e.start,e.end)){e.points=[{...i},{..._},{...S},{...d}],x.add(t);const n=r?"horizontal":"vertical",o=r?i.y:i.x,s=r?Math.min(i.x,d.x):Math.min(i.y,d.y),a=r?Math.max(i.x,d.x):Math.max(i.y,d.y),c={id:`fast-path-${n}-${o.toFixed(0)}-${t}`,orientation:n,coord:o,spanMin:s,spanMax:a,tracks:[]};g.push({edgeIndex:t,segmentIndex:0,orientation:n,pipe:c,trackIndex:0,from:s,to:a});continue}}const F=u("vertical",_.x,_.y,_.y);_.x=F.coord;const Y=u("vertical",S.x,S.y,S.y);S.x=Y.coord;let X=Math.min(_.x,S.x)-50,z=Math.max(_.x,S.x)+50,A=Math.min(_.y,S.y)-50,P=Math.max(_.y,S.y)+50;for(const t of l){const e=Math.min(_.x,S.x),n=Math.max(_.x,S.x),o=Math.min(_.y,S.y),r=Math.max(_.y,S.y);t.minX<n&&t.maxX>e&&t.minY<r&&t.maxY>o&&(X=Math.min(X,t.minX-25),z=Math.max(z,t.maxX+25),A=Math.min(A,t.minY-25),P=Math.max(P,t.maxY+25))}for(const t of l){if(t.maxX<X||t.minX>z||t.maxY<A||t.minY>P)continue;const e=Nn;u("horizontal",t.minY-e,X,z),u("horizontal",t.maxY+e,X,z);const n=Bn;u("vertical",t.minX-n,A,P),u("vertical",t.maxX+n,A,P)}u("horizontal",_.y,X,z),u("horizontal",S.y,X,z);const D=c.filter(t=>"horizontal"===t.orientation&&t.coord>=A&&t.coord<=P),G=c.filter(t=>"vertical"===t.orientation&&t.coord>=X&&t.coord<=z),H=(0,a.__name)((t,e)=>`${t.toFixed(1)},${e.toFixed(1)}`,"getKey"),j=H(_.x,_.y),V=H(S.x,S.y),W=new Map,J=new Map,q=new Map,K=new Set,Q=[];W.set(j,0),q.set(j,"n"),Q.push({key:j,f:Math.hypot(S.x-_.x,S.y-_.y),pt:_}),K.add(j);let U=[];const Z=(0,a.__name)((t,n)=>b(t,n,e.start,e.end),"checkSegmentBlocked"),tt={x:S.x,y:_.y},et=Z(_,tt),nt=Z(tt,S),ot=et||nt,rt={x:_.x,y:S.y},st=Z(_,rt),at=Z(rt,S);if(ot?st||at||(U=Math.abs(_.x-S.x)<$n?[_,S]:[_,rt,S]):U=Math.abs(_.y-S.y)<$n||Math.abs(_.x-S.x)<$n?[_,S]:[_,tt,S],0===U.length)for(;Q.length>0;){Q.sort((t,e)=>t.f-e.f);const n=Q.shift();if(K.delete(n.key),n.key===V){let t=V,e=S;for(U=[e];J.has(t);){const n=J.get(t);U.unshift(n),e=n,t=H(n.x,n.y)}break}const o=n.pt.x,r=n.pt.y,s=G.sort((t,e)=>t.coord-e.coord),a=s.findIndex(t=>Math.abs(t.coord-o)<1),i=D.sort((t,e)=>t.coord-e.coord),c=i.findIndex(t=>Math.abs(t.coord-r)<1),f=[];a>0&&f.push({x:s[a-1].coord,y:r}),a>=0&&a<s.length-1&&f.push({x:s[a+1].coord,y:r}),c>0&&f.push({x:o,y:i[c-1].coord}),c>=0&&c<i.length-1&&f.push({x:o,y:i[c+1].coord});for(const s of f){const a=Math.min(o,s.x),i=Math.max(o,s.x),c=Math.min(r,s.y),f=Math.max(r,s.y);if(l.some(t=>t.nodeId!==e.start&&t.nodeId!==e.end&&(a!==i?t.minY<r&&t.maxY>r&&t.maxX>a&&t.minX<i:t.minX<o&&t.maxX>o&&t.maxY>c&&t.minY<f)))continue;const d=H(s.x,s.y),u=Math.abs(s.x-o)+Math.abs(s.y-r),h=y(t,n.pt,s);let m=0;const g=S.x-_.x,p=S.y-_.y,x=s.x-o,b=s.y-r;(p>10&&b<-5||p<-10&&b>5)&&(m=100*Math.abs(b)),(g>10&&x<-5||g<-10&&x>5)&&(m+=50*Math.abs(x));let M=0;const I=q.get(n.key)??"n",w=Math.abs(x)>$n?"h":"v";"n"!==I&&I!==w&&(M=50);const v=u+h+m+M,C=(W.get(n.key)??1/0)+v,L=Math.abs(S.x-s.x)+Math.abs(S.y-s.y);if(C<(W.get(d)??1/0))if(J.set(d,n.pt),W.set(d,C),q.set(d,w),K.has(d)){const t=Q.findIndex(t=>t.key===d);-1!==t&&(Q[t].f=C+L)}else Q.push({key:d,f:C+L,pt:s}),K.add(d)}}if(0===U.length&&(U=[_,{x:_.x,y:S.y},S]),U.length>4){const t=U[0],e=U[U.length-1];let n=Math.min(t.x,e.x),o=Math.max(t.x,e.x),r=Math.min(t.y,e.y),s=Math.max(t.y,e.y);for(const t of U)n=Math.min(n,t.x),o=Math.max(o,t.x),r=Math.min(r,t.y),s=Math.max(s,t.y);const i=o>Math.max(t.x,e.x),c=n<Math.min(t.x,e.x);if(f){const r=Bn;if(i){const n=Math.max(t.x,e.x),s=Math.min(t.y,e.y),a=Math.max(t.y,e.y),i=l.filter(t=>t.minX<n&&t.maxX>n&&t.minY<a&&t.maxY>s);if(i.length>0){let n=Math.max(t.x,e.x);for(const t of i){const e=(t.minX+t.maxX)/2;if(void 0===t.visualXHalfExtent||isNaN(t.visualXHalfExtent))continue;const o=e+t.visualXHalfExtent+r;n=Math.max(n,o)}isNaN(n)||(o=n)}}if(c){const o=l.filter(n=>n.minX<Math.min(t.x,e.x)+r&&n.minY<Math.max(t.y,e.y)&&n.maxY>Math.min(t.y,e.y));if(o.length>0){let s=Math.min(t.x,e.x);for(const t of o){const e=(t.minX+t.maxX)/2-t.visualXHalfExtent-r;s=Math.min(s,e)}n=s}}}const d=(0,a.__name)(n=>{const o=e.y>t.y,r=l.filter(n=>{const o=Math.min(t.x,e.x)<n.maxX&&Math.max(t.x,e.x)>n.minX,r=Math.min(t.y,e.y)<n.maxY&&Math.max(t.y,e.y)>n.minY;return o&&r});let s=r;if(f&&r.length>0){const t=r.filter(t=>t.minX<n&&t.maxX>n);t.length>0&&(s=t)}if(0===s.length)return e.y;if(o){const t=Math.max(...s.map(t=>t.maxY))+15;if(t<e.y-$n)return t}else{const t=Math.min(...s.map(t=>t.minY))-15;if(t>e.y+$n)return t}return e.y},"findBestReturnY"),u=(0,a.__name)(n=>{const o=d(n),r={x:n,y:t.y},s={x:n,y:o},a={x:e.x,y:o},i=Z(t,r),c=Z(r,s),f=Z(s,a),l=o!==e.y&&Z(a,e);return i||c||f||l?null:Math.abs(o-e.y)<$n?[t,r,s,e]:[t,r,s,a,e]},"trySimplifyWithDetourX"),h=i&&!c?u(o):c&&!i?u(n):null;h&&(U=h)}const it=[i,...k,...U,...T.reverse(),d];if(it.length>=3){const t=it[it.length-1],e=it[it.length-2],n=it[it.length-3],o=Math.abs(n.y-e.y)<$n&&Math.abs(e.y-t.y)<$n,r=Math.abs(n.x-e.x)<$n&&Math.abs(e.x-t.x)<$n;if(o){const o=Math.sign(e.x-n.x),r=Math.sign(t.x-n.x);0!==o&&o===r&&Math.abs(e.x-n.x)>Math.abs(t.x-n.x)&&it.splice(-2,1)}else if(r){const o=Math.sign(e.y-n.y),r=Math.sign(t.y-n.y);0!==o&&o===r&&Math.abs(e.y-n.y)>Math.abs(t.y-n.y)&&it.splice(-2,1)}}const ct=[it[0]];for(let t=1;t<it.length-1;t++){if(1===t){ct.push(it[t]);continue}const e=ct[ct.length-1],n=it[t],o=it[t+1];if(Math.abs(e.y-n.y)<$n&&Math.abs(n.y-o.y)<$n){if(n.x>e.x!=o.x>n.x){ct.push(n);continue}}else if(Math.abs(e.x-n.x)<$n&&Math.abs(n.x-o.x)<$n){if(n.y>e.y!=o.y>n.y){ct.push(n);continue}}else ct.push(n)}ct.push(it[it.length-1]);for(let e=0;e<ct.length-1;e++){const n=ct[e],o=ct[e+1],r=Math.abs(n.x-o.x)<$n?"vertical":"horizontal",s="vertical"===r?n.x:n.y,a="vertical"===r?Math.min(n.y,o.y):Math.min(n.x,o.x),i="vertical"===r?Math.max(n.y,o.y):Math.max(n.x,o.x),c=u(r,s,a,i),f={edgeIndex:t,segmentIndex:e,orientation:r,pipe:c,trackIndex:0,from:a,to:i};g.push(f),p[t].push(g.length-1),c.tracks[0]||(c.tracks[0]={index:0,coord:c.coord,segments:[]}),c.tracks[0].segments.push({edgeIndex:t,segmentIndex:e,from:a,to:i})}}const Y=(0,a.__name)((t,e)=>t.from<e.to&&e.from<t.to,"segmentsOverlap"),X=(0,a.__name)((t,e,n,o)=>{const r=!o.segments.some(n=>(n.edgeIndex!==e.edgeIndex||n.segmentIndex!==e.segmentIndex)&&Y(n,t)),s=!n.segments.some(n=>(n.edgeIndex!==t.edgeIndex||n.segmentIndex!==t.segmentIndex)&&Y(n,e));return!(!r||!s||(t.trackIndex=o.index,e.trackIndex=n.index,n.segments=[...n.segments.filter(e=>e.edgeIndex!==t.edgeIndex||e.segmentIndex!==t.segmentIndex),{edgeIndex:e.edgeIndex,segmentIndex:e.segmentIndex,from:e.from,to:e.to}],o.segments=[...o.segments.filter(t=>t.edgeIndex!==e.edgeIndex||t.segmentIndex!==e.segmentIndex),{edgeIndex:t.edgeIndex,segmentIndex:t.segmentIndex,from:t.from,to:t.to}],0))},"trySwapSegmentsAcrossTracks"),z=(0,a.__name)(t=>{const e=t.tracks.length;return t.tracks[e]={index:e,coord:t.coord,segments:[]},e},"createNewTrack"),A=(0,a.__name)((t,e)=>{const n=t.pipe.tracks[t.trackIndex];n.segments=n.segments.filter(e=>e.edgeIndex!==t.edgeIndex||e.segmentIndex!==t.segmentIndex),t.trackIndex=e,t.pipe.tracks[e].segments.push({edgeIndex:t.edgeIndex,segmentIndex:t.segmentIndex,from:t.from,to:t.to})},"moveSegmentToTrack"),P=(0,a.__name)((t,e)=>{const n=p[t.edgeIndex];for(const o of n){const n=g[o];n.pipe===t.pipe&&A(n,e)}},"moveSegmentChainToTrack"),D=(0,a.__name)(t=>{const e=p[t.edgeIndex],n=e.indexOf(g.indexOf(t)),o=[];return n>0&&o.push(g[e[n-1]]),n<e.length-1&&o.push(g[e[n+1]]),o},"getAdjacentSegmentsAlongEdge"),G=(0,a.__name)((t,e)=>{if(t.orientation===e.orientation)return!1;const n="horizontal"===t.orientation?t:e,o="horizontal"===t.orientation?e:t;return o.pipe.coord>n.from&&o.pipe.coord<n.to&&n.pipe.coord>o.from&&n.pipe.coord<o.to},"haveAnyCrossing"),H=(0,a.__name)((t,e)=>{for(const n of t.tracks)if(!n.segments.some(t=>(t.edgeIndex!==e.edgeIndex||t.segmentIndex!==e.segmentIndex)&&Y(t,e)))return n.index;return-1},"findAvailableTrack"),j=(0,a.__name)((t,e)=>{if(t.trackIndex===e.trackIndex)return Y(t,e);const n=D(t),o=D(e);return n.some(t=>o.some(e=>G(t,e)))},"segmentsConflict"),V=(0,a.__name)((t,e,n)=>{if(X(t,e,t.pipe.tracks[t.trackIndex],e.pipe.tracks[e.trackIndex]))return;const o=H(t.pipe,e);n(e,-1!==o?o:z(t.pipe))},"resolveTrackConflict"),W=(0,a.__name)(t=>{let e=0;for(let n=0;n<t.length;n++)for(let o=n+1;o<t.length;o++){const r=t[n],s=t[o];r.pipe===s.pipe&&j(r,s)&&(e++,V(r,s,P))}return e},"resolveHandleConflicts"),J=new Map,q=(0,a.__name)(t=>{if(J.has(t))return J.get(t);const e=p[t];if(0===e.length){const e={dest:0,deviation:0,base:0,delta:0};return J.set(t,e),e}const n=g[e[0]].pipe.coord;let o=n;for(let t=1;t<e.length;t++){const r=g[e[t]];if("horizontal"===r.orientation){const t=r.from,e=r.to;o=Math.abs(t-n)>Math.abs(e-n)?t:e;break}}const r={dest:o,deviation:Math.abs(o-n),base:n,delta:o-n};return J.set(t,r),r},"getDestInfo"),K=(0,a.__name)(()=>{let t=0;const e=new Map;for(const[t,n]of r.entries())0!==p[t].length&&n.start&&(e.has(n.start)||e.set(n.start,[]),e.get(n.start).push(t));const n=(0,a.__name)(t=>{const e=r[t];if(!e.start||!e.end)return 0;const n=s.get(e.start),o=s.get(e.end);if(!n||!o)return 0;const a=(o.x??0)-(n.x??0),i=(o.y??0)-(n.y??0);return Math.abs(a)+Math.abs(i)},"getEdgeDistance");for(const o of e.values()){o.sort((t,e)=>{const o=q(t),r=q(e);if(Math.abs(o.deviation-r.deviation)>1)return o.deviation-r.deviation;if(Math.abs(o.dest-r.dest)>1)return o.dest-r.dest;const s=n(t),a=n(e);if(Math.abs(s-a)>1)return a-s;const i=p[t].length,c=p[e].length;if(i!==c)return i-c;if(1===i){const n=p[t][0],o=p[e][0];if(g[n]&&g[o]){const t=g[n],e=g[o],r=Math.abs(t.to-t.from),s=Math.abs(e.to-e.from);if(Math.abs(r-s)>1)return r-s}}return 0});const e=o.map(t=>g[p[t][0]]);t+=W(e)}return t},"fixSourceHandleCrossings"),Q=(0,a.__name)(()=>{let t=0;const e=new Map;for(const[t,n]of r.entries())0!==p[t].length&&n.end&&(e.has(n.end)||e.set(n.end,[]),e.get(n.end).push(t));for(const n of e.values()){n.sort((t,e)=>{const n=(0,a.__name)(t=>{const e=p[t];if(e.length<2)return 0;const n=g[e[e.length-2]];return Math.abs(n.to-n.from)},"getDist"),o=n(t),r=n(e);return Math.abs(o-r)>.1?o-r:t-e});const e=n.map(t=>g[p[t][p[t].length-1]]);t+=W(e)}return t},"fixTargetHandleCrossings"),U=(0,a.__name)(()=>{let t=0;for(const e of c){const n=[];for(const t of e.tracks)for(const e of t.segments){const t=p[e.edgeIndex].find(t=>g[t].segmentIndex===e.segmentIndex);void 0!==t&&n.push(g[t])}n.sort((t,e)=>t.edgeIndex-e.edgeIndex||t.segmentIndex-e.segmentIndex);for(let e=0;e<n.length;e++)for(let o=e+1;o<n.length;o++){const r=n[e],s=n[o];j(r,s)&&(t++,V(r,s,A))}}return t},"fixPipeCrossings");let Z=0;for(;Z<10;){let t=0;if(t+=K(),t+=Q(),t+=U(),0===t)break;Z++}const tt=new Map;for(const t of c){const e=[];t.tracks.forEach(t=>{t.segments.forEach(n=>{e.push({edgeIndex:n.edgeIndex,segmentIndex:n.segmentIndex,trackIndex:t.index,from:n.from,to:n.to})})}),e.sort((t,e)=>t.from-e.from);const n=[];if(e.length>0){let t=[e[0]],o=e[0].to;for(let r=1;r<e.length;r++){const s=e[r];s.from<o?(t.push(s),o=Math.max(o,s.to)):(n.push(t),t=[s],o=s.to)}n.push(t)}for(const e of n){const n=new Set;e.forEach(t=>n.add(t.trackIndex));const o=new Map;e.forEach(t=>{const e=q(t.edgeIndex);o.set(t.trackIndex,(o.get(t.trackIndex)??0)+e.delta)});const r=[...n].filter(t=>(o.get(t)??0)<-1),s=[...n].filter(t=>(o.get(t)??0)>1),i=[...n].filter(t=>Math.abs(o.get(t)??0)<=1);r.sort((t,e)=>(o.get(e)??0)-(o.get(t)??0)),s.sort((t,e)=>(o.get(t)??0)-(o.get(e)??0));const c=(0,a.__name)((n,o)=>{e.filter(t=>t.trackIndex===n).forEach(e=>{const n=x.has(e.edgeIndex)?t.coord:o;tt.set(`${e.edgeIndex}-${e.segmentIndex}`,n)})},"assignCoord");let f=0;for(const e of r)f++,c(e,t.coord-10*f);if(0===i.length&&n.size>0){const t=[...n].sort((t,e)=>Math.abs(o.get(t)??0)-Math.abs(o.get(e)??0))[0],e=r.indexOf(t);-1!==e&&r.splice(e,1);const a=s.indexOf(t);-1!==a&&s.splice(a,1),i.push(t)}let d=0;for(const e of i){if(0===d)c(e,t.coord);else{const n=d%2==1?1:-1,o=Math.ceil(d/2);c(e,t.coord+n*o*10*.5)}d++}let l=0;for(const e of s)l++,c(e,t.coord+10*l)}}for(const[t,e]of r.entries()){const n=p[t]??[];if(0===n.length)continue;const o=[],r=s.get(e.start),a=s.get(e.end),{pSrcPort:i,pDstPort:c}=E(t,r,a),f=n.map(t=>{const e=g[t],n=tt.get(`${e.edgeIndex}-${e.segmentIndex}`)??e.pipe.coord;return{orient:e.orientation,coord:n,from:e.from,to:e.to}});o.push(i);for(let t=0;t<f.length;t++){const e=f[t],n=o[o.length-1],r="vertical"===e.orient?n.y:n.x,s="vertical"===e.orient?n.x:n.y,a=f[t+1],i=t<f.length-1;if(Math.abs(s-e.coord)>$n&&o.push(Xn(e,r)),i&&a.orient===e.orient)if(Math.abs(e.coord-a.coord)>$n){const t="vertical"===e.orient?(r+a.from)/2:Yn(e,a);o.push(Xn(e,t),Xn(a,t))}else 0!==t&&t!==f.length-2||o.push(Xn(e,Yn(e,a)));else if(i)o.push(Xn(e,a.coord));else{const t=Math.abs(e.from-r)<Math.abs(e.to-r)?e.to:e.from;o.push(Xn(e,t))}}const d=o[o.length-1];(Math.abs(d.x-c.x)>$n||Math.abs(d.y-c.y)>$n)&&o.push(c);const l=[];o.length>0&&l.push(o[0]);for(let t=1;t<o.length;t++){const e=o[t],n=l[l.length-1];(Math.abs(e.x-n.x)>$n||Math.abs(e.y-n.y)>$n)&&l.push(e)}e.points=l}for(const t of r){const e=t.__originalEdge;e&&t.points&&(e.points=t.points)}t.edges=(t.edges??[]).filter(t=>!t.isLayoutOnly);const et=(0,a.__name)((t,e)=>{const n=e.x??0,o=e.y??0,r=e.width??0,s=e.height??0;if(r<=0||s<=0)return t;const a=n-r/2,i=n+r/2,c=o-s/2,f=o+s/2;if(t.x<a||t.x>i||t.y<c||t.y>f)return t;const d=t.x-a,l=i-t.x,u=t.y-c,h=f-t.y,m=Math.min(d,l,u,h);return m===d?{x:a,y:t.y}:m===l?{x:i,y:t.y}:m===u?{x:t.x,y:c}:{x:t.x,y:f}},"nodeBoundaryClamp");for(const e of t.edges){const t=e.points;if(!t||t.length<2)continue;const n=e.start,o=e.end,r=n?s.get(n):void 0,a=o?s.get(o):void 0;r&&(t[0]=et(t[0],r)),a&&(t[t.length-1]=et(t[t.length-1],a))}return t}function An(t){return t.direction??"TB"}function Pn(t){const e=O(t),n=t.config.flowchart?.nodeSpacing??40,o=t.config.flowchart?.rankSpacing??100,r=t.config.swimlane?.ignoreCrossLaneEdges??!0,s=t.config.swimlane?.optimizeRanksByCrossings??!0,a=t.config.swimlane?.automaticLaneOrdering??!1,i=An(t),{ordered:c,coordinates:f}=Tn(e,{nodeGap:n,layerGap:o,ignoreCrossLaneEdges:r,optimizeRanksByCrossings:s,automaticLaneOrdering:a,direction:i});R(e,c,f,{nodeGap:n,layerGap:o});for(const e of t.edges??[])delete e.points;zn(t,i);for(const e of t.edges??[])e.curve&&"basis"!==e.curve||(e.curve="rounded");return we(t,i),Se(t),i}function Dn(t){k(t);const e=T(t);t.nodes=e.nodes,t.edges=e.edges}(0,a.__name)(En,"chooseOrthogonalSide"),(0,a.__name)(Yn,"sharedLineEndpointCoord"),(0,a.__name)(Xn,"pointOnLine"),(0,a.__name)(zn,"routeEdgesOrthogonal"),(0,a.__name)(An,"getSwimlaneDirection"),(0,a.__name)(Pn,"runSwimlaneLayoutCore"),(0,a.__name)(Dn,"prepareSwimlaneLayout");var Gn=(0,o.createCommonLayoutRenderer)({prepareLayout:Dn,runLayoutCore:Pn,afterPaint:w})}};
//# sourceMappingURL=6869.js.map