UNPKG

mermaid

Version:

Markdown-ish syntax for generating flowcharts, mindmaps, sequence diagrams, class diagrams, gantt charts, git graphs and more.

2 lines • 121 kB
import{a as co}from"./chunk-DJPHBUKM.mjs";import{g as ao}from"./chunk-Q7AU6FSL.mjs";import"./chunk-H3Y7VZGV.mjs";import"./chunk-767MNKTJ.mjs";import"./chunk-3NO356PZ.mjs";import"./chunk-Z2IEFKAF.mjs";import"./chunk-3DCBE5TA.mjs";import"./chunk-JENJ2NYI.mjs";import"./chunk-FRYFDGAD.mjs";import"./chunk-KNGDTZMA.mjs";import"./chunk-UCIVM6JH.mjs";import"./chunk-PNVTB6QF.mjs";import"./chunk-EB7S5WDG.mjs";import"./chunk-VHEAKMU3.mjs";import"./chunk-VLFMOWSA.mjs";import{b as Et}from"./chunk-NXZFCOWJ.mjs";import{a as i}from"./chunk-V3YWWTDH.mjs";function lo(e,{measure:t}){let n=e.config?.swimlane?.lineHops;if(n===!1)return;let o=n==="gap"?"gap":"arc",r=e.edges.filter(s=>Array.isArray(s.points)&&s.points.length>=2).map(s=>({id:s.id,points:s.points,curve:s.curve,arrowTypeStart:s.arrowTypeStart,arrowTypeEnd:s.arrowTypeEnd}));co(t.groups.edgePaths,r,{enabled:!0,jumpRadius:6,jumpStyle:o})}i(lo,"applySwimlaneLineJumps");function Yr(e){let t=e?.metadata?.laneRole;return t==="pool"||t==="lane"?t:void 0}i(Yr,"readLaneRole");function on(e){let t=e?.metadata?.laneIndex;return typeof t=="number"&&Number.isFinite(t)?t:void 0}i(on,"readLaneIndex");function Ze(e){let t=new Map,n=new Map;for(let h of e)t.set(h.id,h),h.isGroup&&h.parentId&&n.set(h.parentId,(n.get(h.parentId)??0)+1);let o=new Set;for(let h of e)h.isGroup&&Yr(h)==="pool"&&(n.get(h.id)??0)>0&&o.add(h.id);let r=new Set,s=new Map;for(let h of e)if(!(!h.isGroup||o.has(h.id)))if(h.parentId&&o.has(h.parentId)){r.add(h.id);let y=s.get(h.parentId)??[];y.push(h.id),s.set(h.parentId,y)}else h.parentId||r.add(h.id);let a=i((h,y)=>{let c=new Set([h]),b=t.get(h)?.parentId;for(;b&&!c.has(b);){if(y.has(b))return b;c.add(b),b=t.get(b)?.parentId}return null},"walk"),l=new Map;return{isPool:i(h=>o.has(h),"isPool"),isLane:i(h=>r.has(h),"isLane"),laneIdOf:i(h=>{let y=l.get(h);if(y!==void 0)return y;let c=a(h,r);return l.set(h,c),c},"laneIdOf"),poolIdOf:i(h=>o.has(h)?h:a(h,o),"poolIdOf"),lanesByPool:s,hasPools:o.size>0}}i(Ze,"buildLaneModel");var $r=new Set(["top","right","bottom","left"]),Tn=8,jr=1e4;function rn(e){let t=e?.metadata?.anchorTo;if(!t||typeof t!="object")return;let{hostId:n,side:o,slot:r,gap:s}=t;if(!(typeof n!="string"||n.length===0||n===e?.id))return{hostId:n,...typeof o=="string"&&$r.has(o)?{side:o}:{},...typeof r=="number"&&Number.isFinite(r)?{slot:r}:{},...typeof s=="number"&&Number.isFinite(s)&&s>0?{gap:Math.min(s,jr)}:{}}}i(rn,"readAnchor");function sn(e,t){let n=new Set([e]),o=rn(t.get(e))?.hostId;for(;o&&!n.has(o);){let r=t.get(o);if(!r)return;let s=rn(r)?.hostId;if(!s)return o;n.add(o),o=s}}i(sn,"resolveAnchorHostId");function vt(e){let t=new Map(e.map(o=>[o.id,o])),n=new Set;for(let o of e)rn(o)&&sn(o.id,t)&&n.add(o.id);return n}i(vt,"collectAnchoredIds");function Vr(e,t){return e==="canonical"?"right":t==="LR"||t==="RL"?"bottom":"right"}i(Vr,"defaultAnchorSide");function Ur(e,t){let n=e.anchor.slot,o=t.anchor.slot;return n!==void 0&&o!==void 0&&n!==o?n-o:n!==void 0&&o===void 0?-1:n===void 0&&o!==void 0?1:e.index-t.index}i(Ur,"compareBucketEntries");function Wr(e){let t=e.reduce((r,s)=>r+s,0)+Tn*Math.max(0,e.length-1),n=[],o=-t/2;for(let r of e)n.push(o+r/2),o+=r+Tn;return{offsets:n,total:t}}i(Wr,"packAlongBorder");var Kr=i(e=>[e.width,e.height].every(t=>t===void 0||Number.isFinite(t)),"hasUsableSize");function qr(e,t){let n=new Map(e.map(r=>[r.id,r])),o=new Map;e.forEach((r,s)=>{let a=rn(r);if(!a||!Kr(r))return;let l=sn(r.id,n);if(!l)return;let u=t(a),h=`${u}:${l}`,y=o.get(h)??[];y.push({node:r,anchor:a,index:s,side:u,hostId:l}),o.set(h,y)});for(let r of o.values())r.sort(Ur);return o}i(qr,"bucketByHostAndSide");function Zr(e,t,n,o){let r=!t&&n>0?-(o+Tn):0;return e+r}i(Zr,"centreAlongBorder");function Jr(e,t){let n=t==="top"||t==="bottom",o=i(h=>n?h.width??0:h.height??0,"alongBorder"),r=i(h=>n?h.height??0:h.width??0,"reach"),{offsets:s}=Wr(e.map(h=>o(h.node))),a=0,l=0,u=0;return e.forEach((h,y)=>{let c=h.anchor.gap??0,b=o(h.node)/2,p=Zr(s[y],n,c,b);a=Math.max(a,b-p),l=Math.max(l,p+b),u=Math.max(u,c>0?c+r(h.node):0)}),{before:a,after:l,beyond:u}}i(Jr,"footprintOf");function fo(e,t){let n=Vr("final",t??"TB"),o=new Map;for(let r of qr(e,s=>s.side??n).values()){if(!r.some(l=>l.anchor.gap))continue;let{hostId:s,side:a}=r[0];o.set(s,{...o.get(s),[a]:Jr(r,a)})}return o}i(fo,"anchorFootprints");var On="__swimlane_default__",Qr=21,uo=20;function go(e){return Math.max(e.padding??uo,uo)}i(go,"topLaneHorizontalPadding");function es(e){let{x:t,y:n,width:o,height:r}=e,s=e.swimlaneContentTop;if(typeof t!="number"||typeof n!="number"||typeof o!="number"||typeof r!="number"||typeof s!="number"||!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(o)||!Number.isFinite(r)||!Number.isFinite(s)||o<=0||r<=0){delete e.groupTitleRect;return}let a=n-r/2,l=Math.min(s,n+r/2),u=Math.min(Qr,Math.max(0,l-a)),h=a+u;if(h<=a){delete e.groupTitleRect;return}e.groupTitleRect={left:t-o/2,right:t+o/2,top:a,bottom:h}}i(es,"assignTopLaneTitleRect");function ts(e){let t=e.other?.droppedSubGraphMembers;return Array.isArray(t)?t:[]}i(ts,"sharedMembers");var ns=i((e,t,n)=>!t.some(o=>o.parentId===n)&&!(e.edges??[]).some(o=>o.start===n||o.end===n),"isEmptyLane");function os(e,t){return e.isLane(t)?t:e.laneIdOf(t)??void 0}i(os,"laneIdOrSelf");function rs(e,t,n){for(let o of n){let r=t.findIndex(s=>s.id===o);r>=0&&ns(e,t,o)&&t.splice(r,1)}}i(rs,"removeEmptyLanes");function ss(e,t){let n=Ze(t),o=new Set(t.filter(s=>n.isLane(s.id)).map(s=>s.id)),r=new Set;for(let{node:s,keptBy:a,droppedFrom:l}of ts(e)){let u=os(n,a);u&&u!==l&&o.has(l)&&(Et.warn(`Swimlane node "${s}" is listed in lanes "${u}" and "${l}"; it is drawn in "${u}" only.`),r.add(l))}rs(e,t,r)}i(ss,"dropLanesEmptiedBySharedNodes");function is(e,t){for(let n of e)n.isGroup&&!t.isLane(n.id)&&!t.isPool(n.id)&&Et.warn(`Swimlane subgraph "${n.id}" is nested in "${n.parentId}"; only top-level subgraphs are lanes, so it is drawn as a plain box.`)}i(is,"warnAboutNestedGroups");function mo(e){let t=e.direction,n=e.nodes??=[];ss(e,n);let o=Ze(n);is(n,o);for(let a of n){let l=o.isLane(a.id);!l&&!o.isPool(a.id)||(a.shape=l?"swimlane":"pool",t&&(a.direction=t))}let r=n.filter(a=>!a.isGroup&&!a.parentId);if(r.length===0)return;let s=n.find(a=>a.id===On);s?s.isGroup&&(s.shape="swimlane",t&&(s.direction=t)):(s={id:On,label:"",isGroup:!0,shape:"swimlane",padding:20,look:e.config?.look,colorIndex:n.reduce((a,l)=>Math.max(a,l.colorIndex??-1),-1)+1,...t?{direction:t}:{}},n.push(s));for(let a of r)a.parentId=On}i(mo,"prepareLayoutForSwimlanes");function ho(e){let t=(e.nodes??[]).filter(c=>!c.isEdgeLabel),n=new Map(t.map(c=>[c.id,c])),o=vt(t),r=i(c=>o.has(c)?sn(c,n)??c:c,"hostOf"),s=new Map;for(let c of t)o.has(c.id)||s.set(c.id,c);let a=[];for(let c of e.edges??[]){let b=typeof c.start=="string"?c.start:void 0,p=typeof c.end=="string"?c.end:void 0;if(!b||!p||c.isLayoutOnly)continue;let g=r(b),d=r(p);g!==d&&a.push({id:c.id,src:g,dst:d,ref:c})}let l=t.filter(c=>c.isGroup&&!o.has(c.id)),u=t.filter(c=>!c.isGroup&&!o.has(c.id));return{nodes:[...[...l].reverse(),...u].map(c=>c.id),edges:a,layout:e,nodeById:s}}i(ho,"toGraphView");function as(e){let t=new Map(e.map(o=>[o.id,o])),n=i(o=>{let r=0,s=o.parentId,a=new Set([o.id]);for(;s!=null&&!a.has(s);)a.add(s),r++,s=t.get(s)?.parentId;return r},"depthOf");return e.filter(o=>o?.isGroup).map(o=>({node:o,depth:n(o)})).sort((o,r)=>r.depth-o.depth).map(o=>o.node)}i(as,"groupsDeepestFirst");function po(e,t,n,o){let{layout:r}=e,s=e.nodeById,a=o?.layerGap??100,l=o?.nodeGap??40,u=0;for(let g of t.layers){let d=0;for(let m of g){let M=s.get(m);if(!M){d++;continue}M.layer=u,M.order=d;let I=n.x[m]??d*l,N=n.y[m]??u*a;M.x=I,M.y=N,d++}u++}let h=r.nodes??[],y=vt(h);for(let g of h)g.isEdgeLabel&&n.x[g.id]!=null&&n.y[g.id]!=null&&(g.x=n.x[g.id],g.y=n.y[g.id]);let c=new Map,b=Ze(h),p=[];for(let g of as(h)){b.isLane(g.id)&&p.push(g);let d=h.filter(T=>T.parentId===g.id&&!y.has(T.id)),m=1/0,M=-1/0,I=1/0,N=-1/0;for(let T of d){let L=T.x??n.x[T.id],x=T.y??n.y[T.id],R=T.width??0,E=T.height??0;L!=null&&x!=null&&(T.isEdgeLabel||(m=Math.min(m,L-R/2),M=Math.max(M,L+R/2)),I=Math.min(I,x-E/2),N=Math.max(N,x+E/2))}if(m===1/0||I===1/0)g.x=g.x??0,g.y=g.y??0,g.width=g.width??0,g.height=g.height??0;else{let T=g.padding??20,L=g.parentId?T:2*go(g),x=T,R=Math.max(0,M-m)+L,E=Math.max(0,N-I)+x,v=(m+M)/2,k=(I+N)/2;g.x=v,g.y=k,g.width=R,g.height=E,c.set(g.id,{minX:m,maxX:M,minY:I,maxY:N})}}if(p.length>0&&c.size>0){let g=1/0,d=-1/0,m=0;for(let M of p){let I=M.padding??20;I>m&&(m=I);let N=c.get(M.id);N&&(g=Math.min(g,N.minY),d=Math.max(d,N.maxY))}if(g!==1/0&&d!==-1/0){let M=Math.max(0,d-g),N=Math.max(m,36),T=M+2*N,L=(g+d)/2;for(let O of p)O.y=L,O.height=T,O.swimlaneContentTop=g;let x=[...p].sort((O,B)=>{let j=O.x??0,X=B.x??0;return j-X}),R=[],E=[],v=[];for(let O of x){let B=c.get(O.id);if(!B)continue;let j=Math.max(0,B.maxX-B.minX)+2*go(O),X=(B.minX+B.maxX)/2;R.push(O.id),E.push(X),v.push(j)}let k=R.length;if(k>0){let O=new Map;if(k===1)O.set(R[0],v[0]);else{let B=[];for(let fe=0;fe<k-1;fe++)B.push(E[fe+1]-E[fe]);let j=new Array(k);j[0]=0;for(let fe=0;fe<k-1;fe++)j[fe+1]=2*B[fe]-j[fe];let X=0,J=Number.POSITIVE_INFINITY;for(let fe=0;fe<k;fe++){let Ce=v[fe];fe%2===0?X=Math.max(X,Ce-j[fe]):J=Math.min(J,j[fe]-Ce)}let ie=X;X<=J?ie=(X+J)/2:ie=X;for(let fe=0;fe<k;fe++){let Ce=j[fe]+(fe%2===0?ie:-ie),nt=Math.max(v[fe],Ce);O.set(R[fe],nt)}}for(let B of p){let j=O.get(B.id);j!=null&&(B.width=j),es(B)}}}}}i(po,"writeBackToLayoutData");var cs="[EdgeLabelNodes]";function yo(e){let t=[],n=[],o=new Map;for(let a of e.nodes)o.set(a.id,a);for(let a of e.edges){if(!a.label||a.label.length===0||a.isLayoutOnly||a.labelNodeId)continue;let l=a.start?o.get(a.start):void 0,u=a.end?o.get(a.end):void 0;if(!l||!u){Et.warn(cs,`Edge ${a.id} has missing source or target node`);continue}let h=`edge-label-${a.start}-${a.end}-${a.id}`,c=l.parentId!==u.parentId?u.parentId:l.parentId,b={id:h,label:a.label,edgeStart:a.start??"",edgeEnd:a.end??"",shape:"labelRect",width:0,height:0,isEdgeLabel:!0,isDummy:!0,parentId:c,isGroup:!1,labelStyle:Array.isArray(a.labelStyle)?a.labelStyle[0]:a.labelStyle??"",...l.dir?{dir:l.dir}:{}};t.push(b),a.labelNodeId=h,a.label=void 0,a.text=void 0;let p={id:`${a.id}-to-label`,start:a.start,end:h,type:"normal",isLayoutOnly:!0},g={id:`${a.id}-from-label`,start:h,end:a.end,type:"normal",isLayoutOnly:!0};n.push(p,g)}let r=[...e.nodes,...t],s=[...e.edges,...n];return{...e,nodes:r,edges:s}}i(yo,"createEdgeLabelNodes");function xo(e){let t=e.x??0,n=e.y??0,o=e.width??0,r=e.height??0;return o>0&&r>0?{cx:t,cy:n,rect:zt(t,n,o,r)}:void 0}i(xo,"measuredNodeRect");function Io(e){if(e.isGroup)return;let t=xo(e);return t?{id:String(e.id??""),cx:t.cx,cy:t.cy,rect:t.rect}:void 0}i(Io,"nodeBoundsInfoFor");function st(e,t,n=.001){return Math.abs(e.x-t.x)<n&&Math.abs(e.y-t.y)<n}i(st,"samePoint");function Ie(e,t,n=.001){return Math.abs(e.x-t.x)<n}i(Ie,"sameX");function Le(e,t,n=.001){return Math.abs(e.y-t.y)<n}i(Le,"sameY");function _e(e,t,n=.001){return Le(e,t,n)&&Math.abs(e.x-t.x)>n}i(_e,"isHorizontalSegment");function De(e,t,n=.001){return Ie(e,t,n)&&Math.abs(e.y-t.y)>n}i(De,"isVerticalSegment");function Je(e,t,n,o){return Math.max(0,Math.min(Math.max(e,t),Math.max(n,o))-Math.max(Math.min(e,t),Math.min(n,o)))}i(Je,"overlapLength");function mt(e,t,n=.001){return e.horizontal&&t.horizontal&&Le(e.a,t.a,n)?Je(e.a.x,e.b.x,t.a.x,t.b.x):e.vertical&&t.vertical&&Ie(e.a,t.a,n)?Je(e.a.y,e.b.y,t.a.y,t.b.y):0}i(mt,"sameAxisSegmentOverlapLength");function bt(e,t=.001){let n=[];for(let o=0;o<e.length-1;o++){let r=e[o],s=e[o+1],a=_e(r,s,t),l=De(r,s,t);(a||l)&&n.push({index:o,a:r,b:s,horizontal:a,vertical:l})}return n}i(bt,"orthogonalSegmentsForPoints");function it(e,t=.001){let n=bt(e,t),o=0;for(let r=1;r<n.length;r++)n[r-1].horizontal!==n[r].horizontal&&o++;return o}i(it,"countOrthogonalBends");function ds(e){let t=bt(xe(e));return t.slice(1).flatMap((n,o)=>t[o].horizontal===n.horizontal?[]:[n.a])}i(ds,"bendPoints");function ls(e,t){let n=Math.max(Math.min(t.a.x,t.b.x)-e.x,0,e.x-Math.max(t.a.x,t.b.x)),o=Math.max(Math.min(t.a.y,t.b.y)-e.y,0,e.y-Math.max(t.a.y,t.b.y));return Math.hypot(n,o)}i(ls,"distanceToSegment");function Mo(e,t,n){let o=i((r,s)=>{let a=bt(xe(s));return ds(r).some(l=>a.some(u=>ls(l,u)<n))},"touches");return o(e,t)||o(t,e)}i(Mo,"routesTouchAtBend");function xe(e,t=.001){let n=[];for(let o of e){let r=n.length>0?n[n.length-1]:void 0;(!r||!st(r,o,t))&&n.push({x:o.x,y:o.y})}return n}i(xe,"dedupeConsecutivePoints");function an(e,t=.001){if(!e||e.length!==4)return;let[n,o,r,s]=e;return _e(n,o,t)&&De(o,r,t)&&_e(r,s,t)?{kind:"HVH",p0:n,p1:o,p2:r,p3:s}:De(n,o,t)&&_e(o,r,t)&&De(r,s,t)?{kind:"VHV",p0:n,p1:o,p2:r,p3:s}:void 0}i(an,"classifyThreeSegmentRoute");function jt(e,t,n,o=0){let r=Math.min(e.x,t.x),s=Math.max(e.x,t.x),a=Math.min(e.y,t.y),l=Math.max(e.y,t.y);return s>n.left-o&&r<n.right+o&&l>n.top-o&&a<n.bottom+o}i(jt,"segmentBoundsOverlapRect");function cn(e,t,n=0){return e.x>t.left+n&&e.x<t.right-n&&e.y>t.top+n&&e.y<t.bottom-n}i(cn,"pointInsideRect");function Lo(e,t){return e.left<=t.left&&e.right>=t.right&&e.top<=t.top&&e.bottom>=t.bottom}i(Lo,"rectContainsRect");function dn(e,t){return e.left<t.right&&e.right>t.left&&e.top<t.bottom&&e.bottom>t.top}i(dn,"rectsOverlap");function vn(e,t){return{left:e.left-t,right:e.right+t,top:e.top-t,bottom:e.bottom+t}}i(vn,"inflateRect");function zt(e,t,n,o){return{left:e-n/2,right:e+n/2,top:t-o/2,bottom:t+o/2}}i(zt,"rectFromCenterSize");function Ve(e){return xo(e)?.rect}i(Ve,"rectOfNodeBounds");function Pt(e,t){switch(t){case"top":return{x:e.cx,y:e.rect.top};case"bottom":return{x:e.cx,y:e.rect.bottom};case"left":return{x:e.rect.left,y:e.cy};case"right":return{x:e.rect.right,y:e.cy}}}i(Pt,"portForRectSide");function ln(e,t,n,o,r,s=.001){let a=t==="left"||t==="right",l=o==="left"||o==="right";if(a&&l){if(t==="right"&&o==="left"&&e.x<n.x||t==="left"&&o==="right"&&e.x>n.x){if(Le(e,n,s))return[e,n];let c=(e.x+n.x)/2;return[e,{x:c,y:e.y},{x:c,y:n.y},n]}if(t===o){if(Le(e,n,s))return;let c=t==="left"?Math.min(e.x,n.x)-r:Math.max(e.x,n.x)+r;return[e,{x:c,y:e.y},{x:c,y:n.y},n]}return}if(!a&&!l){if(t===o){if(Ie(e,n,s))return;let b=t==="top"?Math.min(e.y,n.y)-r:Math.max(e.y,n.y)+r;return[e,{x:e.x,y:b},{x:n.x,y:b},n]}if(!(t==="bottom"&&o==="top"&&e.y<n.y||t==="top"&&o==="bottom"&&e.y>n.y))return;if(Ie(e,n,s))return[e,n];let c=(e.y+n.y)/2;return[e,{x:e.x,y:c},{x:n.x,y:c},n]}if(a&&!l){let y=t==="right"&&n.x>e.x||t==="left"&&n.x<e.x,c=o==="top"&&e.y<n.y||o==="bottom"&&e.y>n.y;return y&&c?[e,{x:n.x,y:e.y},n]:void 0}let u=t==="bottom"&&n.y>e.y||t==="top"&&n.y<e.y,h=o==="left"&&e.x<n.x||o==="right"&&e.x>n.x;return u&&h?[e,{x:e.x,y:n.y},n]:void 0}i(ln,"buildOrthogonalPortPath");function fn(e,t,n,o){return t==="left"||t==="right"?[e,{x:o,y:e.y},{x:o,y:n.y},n]:[e,{x:e.x,y:o},{x:n.x,y:o},n]}i(fn,"buildSameSideTrackPath");function Ht(e){let t=new Map,n=[];for(let o of e){if(o.isEdgeLabel)continue;let r=Io(o);r&&(t.set(r.id,r),n.push({id:r.id,rect:r.rect}))}return{nodeInfoById:t,realNodeRects:n}}i(Ht,"collectRealNodeBounds");function xt(e){let t=[],n=[];for(let o of e){let r=Io(o);if(!r)continue;let s={id:r.id,rect:r.rect};o.isEdgeLabel?n.push(s):t.push(s)}return{realNodeRects:t,labelNodeRects:n}}i(xt,"collectNodeRectEntries");function So(e,{includeEdgeLabels:t=!0}={}){let n=[];for(let o of e){if(o.isGroup||!t&&o.isEdgeLabel)continue;let r=o.x??0,s=o.y??0,a=o.width??0,l=o.height??0;n.push({nodeId:o.id,...zt(r,s,a,l)})}return n}i(So,"collectLayoutNodeRects");function un(e,t,n=.001){let o=e.start,r=e.end;if(!o||!r)return;let s=t.get(o),a=t.get(r);if(!(!s||!a))return{srcId:o,dstId:r,srcInfo:s,dstInfo:a,collinearX:Math.abs(s.cx-a.cx)<n,collinearY:Math.abs(s.cy-a.cy)<n}}i(un,"getNodePairGeometry");function Oe(e,t,n,o=[],r=0){for(let s of n)if(!o.includes(s.id)&&jt(e,t,s.rect,-r))return!0;return!1}i(Oe,"segmentHitsAnyRect");function Bn(e,t,n,o,r=.001,s=1e-6){let a=Le(e,t,r),l=Ie(e,t,r),u=Le(n,o,r),h=Ie(n,o,r);if(a&&u||l&&h||!(a||l)||!(u||h))return!1;let y=a?{a:e,b:t}:{a:n,b:o},c=l?{a:e,b:t}:{a:n,b:o},b=y.a.y,p=Math.min(y.a.x,y.b.x),g=Math.max(y.a.x,y.b.x),d=c.a.x,m=Math.min(c.a.y,c.b.y),M=Math.max(c.a.y,c.b.y);if(d<p||d>g||b<m||b>M)return!1;let I=Math.abs(d-y.a.x)<s&&Math.abs(b-y.a.y)<s||Math.abs(d-y.b.x)<s&&Math.abs(b-y.b.y)<s,N=Math.abs(d-c.a.x)<s&&Math.abs(b-c.a.y)<s||Math.abs(d-c.b.x)<s&&Math.abs(b-c.b.y)<s;return!(I&&N)}i(Bn,"orthogonalSegmentsCross");function fs(e,t,n,o,r=.001){let s=Le(e,t,r),a=Ie(e,t,r),l=Le(n,o,r),u=Ie(n,o,r);return a&&u&&Ie(e,n,r)?Je(e.y,t.y,n.y,o.y)>r:s&&l&&Le(e,n,r)?Je(e.x,t.x,n.x,o.x)>r:!1}i(fs,"sameAxisSegmentsOverlap");function Vt(e,t,n,o,{epsilon:r=.001,skipDegenerateOther:s=!1}={}){for(let a of n){if(a===o||a.isLayoutOnly)continue;let l=a.points;if(!(!l||l.length<2))for(let u=0;u<l.length-1;u++){let h=l[u],y=l[u+1];if(!(s&&st(h,y,r))&&(Bn(e,t,h,y,r)||fs(e,t,h,y,r)))return!0}}return!1}i(Vt,"segmentConflictsWithAnyEdge");function ht(e,t,n,o,r=.001){let s=Le(e,t,r),a=Ie(e,t,r),l=Le(n,o,r),u=Ie(n,o,r);if(!(s&&u||a&&l))return!1;let h=s?{a:e,b:t}:{a:n,b:o},y=s?{a:n,b:o}:{a:e,b:t},c=h.a.y,b=Math.min(h.a.x,h.b.x),p=Math.max(h.a.x,h.b.x),g=y.a.x,d=Math.min(y.a.y,y.b.y),m=Math.max(y.a.y,y.b.y);return g>b+r&&g<p-r&&c>d+r&&c<m-r}i(ht,"orthogonalSegmentsStrictlyCross");function bo(e,t,n){let o=Math.min(t,n),r=Math.max(t,n);return e>o+.001&&e<r-.001}i(bo,"strictlyBetween");function us(e,t,n){return Ie(e,t)&&Ie(t,n)?bo(t.y,e.y,n.y):Le(e,t)&&Le(t,n)?bo(t.x,e.x,n.x):!1}i(us,"isCollinearIntermediate");function gs(e){let t=!1,n=[];for(let o=0;o<e.length;o++){let r=n[n.length-1],s=e[o],a=o+1<e.length?e[o+1]:void 0;if(r&&a){if(st(r,a)){o++,t=!0;continue}if(us(r,s,a)){t=!0;continue}}n.push(s)}return{points:n,changed:t}}i(gs,"simplifyPolylineOnce");function Ut(e){let t=[e[0]];for(let o=1;o<e.length;o++){let r=t[t.length-1],s=e[o];if(!Ie(r,s)&&!Le(r,s)){let a=t.length>=2?t[t.length-2]:void 0,u=(a?Ie(a,r):!1)?{x:r.x,y:s.y}:{x:s.x,y:r.y};t.push(u)}t.push(s)}let n=[];for(let o of t){let r=n[n.length-1];(!r||!st(r,o))&&n.push(o)}return n}i(Ut,"orthogonalizePolyline");function ut(e){if(e.length<3)return e;let t=[...e];for(let n=0;n<32;n++){let o=gs(t);if(t=o.points,!o.changed)break}return t}i(ut,"simplifyPolyline");var ge=.001,ms=.5,No=4;function Bo(e,t,n){let o=e;if(o.isLayoutOnly||!o.points||o.points.length<n)return;let r=o.start?t.get(o.start):void 0,s=o.end?t.get(o.end):void 0;return{edge:o,points:o.points,srcRect:r?Ve(r):void 0,dstRect:s?Ve(s):void 0}}i(Bo,"endpointContextFor");function hs(e,t,n){if(Le(e,t,ge))return{x:e.x<n.left?n.left:n.right,y:e.y};if(Ie(e,t,ge)){let o=e.y<n.top?n.top:n.bottom;return{x:e.x,y:o}}return{x:Math.min(n.right,Math.max(n.left,e.x)),y:Math.min(n.bottom,Math.max(n.top,e.y))}}i(hs,"segmentEnterPoint");function Ro(e,t,n){let o=n?1:-1,r=n?0:e.length-1;for(;r>=0&&r<e.length&&cn(e[r],t,ms);)r+=o;if(r<0||r>=e.length)return e;let s=r-o;if(s<0||s>=e.length)return e;let a=hs(e[r],e[s],t);return n?[a,...e.slice(r)]:[...e.slice(0,r+1),a]}i(Ro,"clipEndpoint");function ko(e,t){for(let n of e){let o=Bo(n,t,2);if(!o)continue;let r=[...o.points];o.srcRect&&(r=Ro(r,o.srcRect,!0)),o.dstRect&&(r=Ro(r,o.dstRect,!1)),r=ut(Ut(r)),r=_o(r,o.srcRect,o.dstRect),o.edge.points=ut(Ut(r))}}i(ko,"clipEdgeEndpointsToNodeBoundaries");function Eo(e,t,n,o=!1){if(Le(e,t,ge)){if(t.y<n.top-ge||t.y>n.bottom+ge)return t;if(o){if(e.x<n.left-ge)return{x:n.left,y:e.y};if(e.x>n.right+ge)return{x:n.right,y:e.y}}return{x:Math.abs(t.x-n.left)<=Math.abs(t.x-n.right)?n.left:n.right,y:e.y}}if(Ie(e,t,ge)){if(t.x<n.left-ge||t.x>n.right+ge)return t;if(o){if(e.y<n.top-ge)return{x:e.x,y:n.top};if(e.y>n.bottom+ge)return{x:e.x,y:n.bottom}}let r=Math.abs(t.y-n.top)<=Math.abs(t.y-n.bottom);return{x:e.x,y:r?n.top:n.bottom}}return t}i(Eo,"snapEndpointToBoundary");function kn(e,t,n){let o=e[t];for(let r=t+n;r>=0&&r<e.length;r+=n){let s=e[r];if(!st(s,o,ge))return s}return e[t+n]}i(kn,"firstDistinctAdjacent");function _n(e,t){let n=e+No,o=t-No;return n<=o?{lo:n,hi:o}:{lo:(e+t)/2,hi:(e+t)/2}}i(_n,"cornerClearanceRange");function Po(e,t,n){let{lo:o,hi:r}=_n(t,n);return Math.min(r,Math.max(o,e))}i(Po,"clampToCornerClearance");function ps(e){let t=Math.max(...e.map(o=>o.lo)),n=Math.min(...e.map(o=>o.hi));if(!(t>n))return{lo:t,hi:n}}i(ps,"intersectRanges");function Co(e,t){return t==="left"||t==="right"?_n(e.top,e.bottom):_n(e.left,e.right)}i(Co,"clearanceRangeForSide");function Dn(e,t,n){let o=e.y>=n.top-ge&&e.y<=n.bottom+ge,r=e.x>=n.left-ge&&e.x<=n.right+ge;if(Le(e,t,ge)&&o){if(Math.abs(e.x-n.left)<ge)return"left";if(Math.abs(e.x-n.right)<ge)return"right"}if(Ie(e,t,ge)&&r){if(Math.abs(e.y-n.top)<ge)return"top";if(Math.abs(e.y-n.bottom)<ge)return"bottom"}}i(Dn,"terminalSideForSegment");function gn(e){return e==="left"||e==="right"}i(gn,"isHorizontalSide");function ys(e,t,n,o,r){let s=[],a=n?Dn(e,t,n):void 0,l=o?Dn(t,e,o):void 0;return n&&a&&gn(a)===r&&s.push(Co(n,a)),o&&l&&gn(l)===r&&s.push(Co(o,l)),s.length>0?ps(s):void 0}i(ys,"straightClearanceRange");function wo(e,t,n,o,r){let s=ys(e,t,n,o,r);if(!s)return;let a=r?e.y:e.x,l=Math.min(s.hi,Math.max(s.lo,a));if(!(Math.abs(l-a)<ge))return r?[{x:e.x,y:l},{x:t.x,y:l}]:[{x:l,y:e.y},{x:l,y:t.y}]}i(wo,"clearStraightEndpointCornerAxis");function _o(e,t,n){if(e.length!==2)return e;let[o,r]=e;return Le(o,r,ge)?wo(o,r,t,n,!0)??e:Ie(o,r,ge)?wo(o,r,t,n,!1)??e:e}i(_o,"clearStraightEndpointCornerConnections");function bs(e,t,n){return gn(n)?{x:e.x,y:Po(e.y,t.top,t.bottom)}:{x:Po(e.x,t.left,t.right),y:e.y}}i(bs,"cornerClearedEndpoint");function xs(e,t,n,o,r,s){let a=e.map(l=>({...l}));for(let l=t;l>=0&&l<e.length;l+=n){let u=e[l];if(s&&!Le(u,o,ge)||!s&&!Ie(u,o,ge))break;s?a[l].y=r.y:a[l].x=r.x}return a}i(xs,"moveCollinearEndpointRun");function Ao(e,t,n){if(e.length<2)return e;let o=n?0:e.length-1,r=n?1:-1,s=e[o],a=kn(e,o,r);if(!a)return e;let l=Dn(s,a,t);if(!l)return e;let u=gn(l),h=bs(s,t,l);return st(s,h,ge)?e:xs(e,o,r,s,h,u)}i(Ao,"clearEndpointCornerConnection");function To(e,t,n){let o=Math.min(e.x,t.x)>=n.left-ge&&Math.max(e.x,t.x)<=n.right+ge,r=Math.min(e.y,t.y)>=n.top-ge&&Math.max(e.y,t.y)<=n.bottom+ge;if(Math.abs(e.y-n.top)<ge&&Math.abs(t.y-n.top)<ge&&o)return"top";if(Math.abs(e.y-n.bottom)<ge&&Math.abs(t.y-n.bottom)<ge&&o)return"bottom";if(Math.abs(e.x-n.left)<ge&&Math.abs(t.x-n.left)<ge&&r)return"left";if(Math.abs(e.x-n.right)<ge&&Math.abs(t.x-n.right)<ge&&r)return"right"}i(To,"borderSideForSegment");function Oo(e,t,n,o){switch(e){case"top":return Ie(t,n,ge)&&n.y<o.top-ge;case"bottom":return Ie(t,n,ge)&&n.y>o.bottom+ge;case"left":return Le(t,n,ge)&&n.x<o.left-ge;case"right":return Le(t,n,ge)&&n.x>o.right+ge}}i(Oo,"leavesOutward");function vo(e,t,n){if(e.length<3)return e;if(n){let s=To(e[0],e[1],t);return s&&Oo(s,e[1],e[2],t)?e.slice(1):e}let o=e.length-1,r=To(e[o-1],e[o],t);return r&&Oo(r,e[o-1],e[o-2],t)?e.slice(0,o):e}i(vo,"collapseOwnBorderStub");function Is(e,t,n){let o=e;if(t){let s=kn(o,0,1);if(s){let a=Eo(s,o[0],t);a!==o[0]&&(o=[a,...o.slice(1)])}o=vo(o,t,!0)}if(n){let s=o.length-1,a=kn(o,s,-1);if(a){let l=Eo(a,o[s],n,!0);l!==o[s]&&(o=[...o.slice(0,s),l])}o=vo(o,n,!1)}let r=_o(o,t,n);return r!==o||o.length===2?r:(t&&(o=Ao(o,t,!0)),n&&(o=Ao(o,n,!1)),o)}i(Is,"snapAndCollapseEndpoints");function Fn(e,t){for(let n of e){let o=Bo(n,t,2);if(!o)continue;let r=xe(o.points,ge),s=Is(r,o.srcRect,o.dstRect);if(s.length<3){o.edge.points=s;continue}let a=[s[0],{...s[0]},...s.slice(1,-1),s[s.length-1],{...s[s.length-1]}];o.edge.points=a}}i(Fn,"prepareEdgeEndpointsForRenderer");function Ms(e){return new Map(e.map(t=>[t.id,t]))}i(Ms,"buildNodeMap");function Do(e,t){let n=new Set([e.id]),o=0,r=e.parentId;for(;r&&!n.has(r);){let s=t.get(r);if(!s?.isGroup)break;n.add(r),o++,r=s.parentId}return o}i(Do,"groupDepth");function Fo(e){let t=1/0,n=-1/0,o=1/0,r=-1/0;for(let s of e){let a=s.x,l=s.y;if(typeof a!="number"||typeof l!="number")continue;let u=s.width??0,h=s.height??0;t=Math.min(t,a-u/2),n=Math.max(n,a+u/2),o=Math.min(o,l-h/2),r=Math.max(r,l+h/2)}return t===1/0||o===1/0?null:{minX:t,maxX:n,minY:o,maxY:r}}i(Fo,"boundsForChildren");function Ls(e,t){let n=e.padding??20;e.x=(t.minX+t.maxX)/2,e.y=(t.minY+t.maxY)/2,e.width=Math.max(0,t.maxX-t.minX)+n,e.height=Math.max(0,t.maxY-t.minY)+n}i(Ls,"applyGroupBounds");function Ss(e){let t=Ms(e),n=e.filter(o=>o.isGroup&&o.parentId).sort((o,r)=>Do(r,t)-Do(o,t));for(let o of n){let r=e.filter(a=>a.parentId===o.id),s=Fo(r);s&&Ls(o,s)}}i(Ss,"recomputeNestedGroupBounds");function Gn(e,t){let n=e.nodes??[],o=e.edges??[],r=n.filter(u=>!u.isGroup),s=1/0,a=-1/0;for(let u of r){let h=u[t];typeof h=="number"&&(s=Math.min(s,h),a=Math.max(a,h))}if(!Number.isFinite(s)||!Number.isFinite(a))return!1;let l=i(u=>s+a-u,"mirror");for(let u of n){let h=u[t];typeof h=="number"&&(u[t]=l(h));let y=u.groupTitleRect;y&&(u.groupTitleRect=t==="x"?{...y,left:l(y.right),right:l(y.left)}:{...y,top:l(y.bottom),bottom:l(y.top)})}for(let u of o)for(let h of u.points??[])h[t]=l(h[t]);return!0}i(Gn,"mirrorAxis");function Go(e){return(e.nodes??[]).some(n=>!n.isGroup)?Gn(e,"y"):!0}i(Go,"applyBtDirectionTransform");function zn(e){let t=e.filter(a=>!a.isGroup&&!a.isEdgeLabel);if(t.length===0)return 1;let n=0,o=0;for(let a of t)n+=a.width??0,o+=a.height??0;let r=n/t.length,s=o/t.length;return s>0?Math.max(1,r/s):1}i(zn,"flowAxisStretch");var Ns=36,Rs=["top","right","bottom","left"];function Es(e){return e==="left"?"right":e==="right"?"left":e}i(Es,"mirroredSide");function Ps(e,t,n,o,r){if(n==="top"||n==="bottom"){let a=(t.left+t.right)/2,[l,u]=r?[o.after,o.before]:[o.before,o.after];e.left=Math.min(e.left,a-l),e.right=Math.max(e.right,a+u);return}let s=(t.top+t.bottom)/2;e.top=Math.min(e.top,s-o.before),e.bottom=Math.max(e.bottom,s+o.after)}i(Ps,"growAlongBorder");var Cs={top:i((e,t,n)=>{e.top=Math.min(e.top,t.top-n)},"top"),bottom:i((e,t,n)=>{e.bottom=Math.max(e.bottom,t.bottom+n)},"bottom"),left:i((e,t,n)=>{e.left=Math.min(e.left,t.left-n)},"left"),right:i((e,t,n)=>{e.right=Math.max(e.right,t.right+n)},"right")};function ws(e,t,n,o,r){Ps(e,t,n,o,r),Cs[n](e,t,o.beyond)}i(ws,"reserveOnSide");function As(e,t,n){let o=e.x??0,r=e.y??0,s=(e.width??0)/2,a=(e.height??0)/2,l={left:o-s,right:o+s,top:r-a,bottom:r+a},u={...l},h=n==="RL";for(let y of Rs){let c=t[y];c&&ws(u,l,h?Es(y):y,c,h)}return{...e,x:(u.left+u.right)/2,y:(u.top+u.bottom)/2,width:u.right-u.left,height:u.bottom-u.top}}i(As,"withAnchorFootprints");function zo(e,t="LR"){let n=e.nodes??[],o=e.edges??[],r=vt(n),s=n.filter(O=>!O.isGroup&&!r.has(O.id)),a=1/0,l=1/0;for(let O of s){let B=O.x??0,j=O.y??0;B<a&&(a=B),j<l&&(l=j)}if(!Number.isFinite(a)||!Number.isFinite(l))return!1;let u=Ns,h=zn(s);for(let O of s){let B=O.x??0,X=((O.y??0)-l)*h+u,J=B-a;O.x=X,O.y=J}for(let O of o)if(O.points)for(let B of O.points){let j=B.x,J=(B.y-l)*h+u,ie=j-a;B.x=J,B.y=ie}Ss(n);let y=Ze(n),c=n.filter(O=>y.isLane(O.id));if(c.length===0)return t==="RL"&&Gn(e,"x"),!0;let b=new Map,p=fo(n,t);for(let O of n){if(y.isLane(O.id)||y.isPool(O.id)||r.has(O.id))continue;let B=y.laneIdOf(O.id);if(!B)continue;let j=b.get(B)??[],X=p.get(O.id);j.push(X?As(O,X,t):O),b.set(B,j)}let g=0;for(let O of c){let B=O.padding??0;B>g&&(g=B)}let d=[],m=1/0,M=-1/0;for(let O of c){let B=b.get(O.id)??[],j=Fo(B);j&&(m=Math.min(m,j.minX),M=Math.max(M,j.maxX),d.push({lane:O,contentTop:j.minY,contentBottom:j.maxY,centerY:(j.minY+j.maxY)/2}))}if(m===1/0||M===-1/0)return!0;let I=Math.max(0,M-m),N=Math.max(g,10),T=I+2*N,L=u+T,E=(m+M)/2-T/2-u,v=E+L/2,k=Math.max(g,u);d.sort((O,B)=>O.centerY-B.centerY);for(let O=0;O<d.length;O++){let B=d[O],j,X;if(O===0?j=B.contentTop-k:j=(d[O-1].contentBottom+B.contentTop)/2,O===d.length-1)X=B.contentBottom+k;else{let fe=d[O+1];X=(B.contentBottom+fe.contentTop)/2}let J=Math.max(0,X-j),ie=(j+X)/2;B.lane.x=v,B.lane.y=ie,B.lane.width=L,B.lane.height=J,B.lane.swimlaneContentTop=B.contentTop,B.lane.groupTitleRect={left:E,right:E+u,top:j,bottom:X}}return t==="RL"&&Gn(e,"x"),!0}i(zo,"applyLrDirectionTransform");var pt=1e-6,Ts=8,mn=Ts,Os=[0,mn,-mn,2*mn,-2*mn];function Ho(e,t){let{nodeInfoById:n,realNodeRects:o}=Ht(t);for(let r of e){if(r.isLayoutOnly)continue;let s=r.points;if(!s||s.length<4)continue;let a=an(xe(s,pt),pt);if(!a)continue;let{p3:l}=a,u=a.kind==="HVH",h=un(r,n,pt);if(!h)continue;let{srcId:y,dstId:c,srcInfo:b,dstInfo:p,collinearX:g,collinearY:d}=h;if(g||d)continue;let m,M=b.rect;for(let I of Os){let N,T,L;if(u){let O=p.cy>b.cy?M.bottom:M.top,B=b.cx+I;if(B<=M.left+pt||B>=M.right-pt)continue;N={x:B,y:O},T={x:B,y:l.y},L={x:l.x,y:l.y}}else{let O=p.cx>b.cx?M.right:M.left,B=b.cy+I;if(B<=M.top+pt||B>=M.bottom-pt)continue;N={x:O,y:B},T={x:l.x,y:B},L={x:l.x,y:l.y}}let x=st(N,T,pt),R=st(T,L,pt);if(x&&R||!x&&Oe(N,T,o,[y],1)||!R&&Oe(T,L,o,[c],1))continue;let E=!x&&Vt(N,T,e,r,{epsilon:pt,skipDegenerateOther:!0}),v=!R&&Vt(T,L,e,r,{epsilon:pt,skipDegenerateOther:!0});if(!(E||v)){x?m=[T,L]:R?m=[N,T]:m=[N,T,L];break}}m&&(r.points=m)}}i(Ho,"portSwapToLShape");function Xo(e,t){let{realNodeRects:s,labelNodeRects:a}=xt(t.values());for(let l of e){if(l.isLayoutOnly)continue;let u=l.points;if(!u||u.length<4)continue;let h=xe(u,.001);if(h.length<4)continue;let y=h.length-1,c=h[y],b=h[y-1],p=h[y-2],g=c.x-b.x,d=c.y-b.y,m=Math.hypot(g,d);if(m>=10||m<.001)continue;let M=b.x-p.x,I=b.y-p.y;if(Math.hypot(M,I)<.001)continue;let T=_e(b,c,.001),L=De(b,c,.001),x=_e(p,b,.001),R=De(p,b,.001);if(!(T&&R||L&&x))continue;let E=l.end,v=l.start,k=E?t.get(E):void 0;if(!k)continue;let O=k.x??0,B=k.y??0,j=Ve(k);if(!j)continue;let X,J;if(R){let Q=I<0;X={x:O,y:p.y},J={x:O,y:Q?j.bottom:j.top}}else{let Q=M>0;X={x:p.x,y:B},J={x:Q?j.right:j.left,y:B}}if(Oe(X,J,s,E?[E]:[],-2)||Oe(X,J,a,[],-2))continue;if(v){let Q=t.get(v),de=Q?Ve(Q):void 0;if(de&&cn(X,de,2))continue}let ie=i((Q,de)=>`${Q.x.toFixed(3)},${Q.y.toFixed(3)}|${de.x.toFixed(3)},${de.y.toFixed(3)}`,"ownSegmentKey"),fe=new Set;for(let Q=0;Q<h.length-1;Q++)fe.add(ie(h[Q],h[Q+1]));let Ce=i((Q,de)=>{for(let D of e){if(D===l||D.isLayoutOnly)continue;let Y=D.points;if(!(!Y||Y.length<2))for(let ee=0;ee<Y.length-1;ee++){let q=Y[ee],re=Y[ee+1];if(!fe.has(ie(q,re))&&ht(Q,de,q,re,.001))return!0}}return!1},"segmentCrossesOtherEdge");if(Ce(X,J))continue;if(y-3>=0){let Q=h[y-3],de=[v,E].filter(D=>!!D);if(Oe(Q,X,s,de,-2)||Ce(Q,X))continue}let $e=[...h.slice(0,y-2),X,J];l.points=$e;let je=l.labelNodeId;if(je){let Q=t.get(je);if(Q){let de=Q.width??0,D=Q.height??0;if(de>0&&D>0){let Y,ee,q=-1;for(let re=0;re<$e.length-1;re++){let ue=$e[re],me=$e[re+1],he=Math.hypot(me.x-ue.x,me.y-ue.y),be=Le(ue,me,.001),ke=Ie(ue,me,.001);(be&&he>=de+2||ke&&he>=D+2)&&he>q&&(q=he,Y=(ue.x+me.x)/2,ee=(ue.y+me.y)/2)}Y!==void 0&&ee!==void 0&&(Q.x=Y,Q.y=ee)}}}}}i(Xo,"collapseShortTerminalStub");var hn={EDGE_GAP:12,LANE_MARGIN:20,ARROWHEAD_SIZE:8,ARROWHEAD_GAP:4,MIN_ARROWHEAD_SPACING:12,EDGE_STROKE_WIDTH:2,ROUTE_TOUCH_TOLERANCE:6},Yo={EPSILON:1e-6},Bt={GRAVITY_ITERATIONS:8,MAX_CROSSING_OPTIMIZATION_PASSES:4,DEFAULT_COMPACT_SINGLE_INPUT:!0},pn={DEFAULT_LAYER_GAP:100,DEFAULT_NODE_GAP:40,EDGE_LABEL_CLEARANCE:16};var ae=.001,Ue=8,$o=i(e=>typeof e=="string"?e.toUpperCase():"","upperCaseDirection"),pe=bt,Hn=i((e,t)=>Ie(e,t,ae)||Le(e,t,ae),"orthogonallyAligned");function Xn(e,t){let r=i((p,g)=>{let d=p.x??0,m=p.y??0,M=g.x-d,I=g.y-m,N=(p.width??0)/2,T=(p.height??0)/2;return Math.abs(I)*N>Math.abs(M)*T?(I<0&&(T=-T),{x:d+(I===0?0:T*M/I),y:m+T}):(M<0&&(N=-N),{x:d+N,y:m+(M===0?0:N*I/M)})},"rectIntersect"),s=i((p,g)=>{let d=xe(p.points??[]);if(d.length<2)return;let m=g?p.start:p.end,M=m?t.get(m):void 0,I=M?Ve(M):void 0;if(!M||!m||!I)return;let N=g?d[0]:d[d.length-1],T=g?d[1]:d[d.length-2],L=r(M,N),x=N;if(Hn(T,L)&&(x=T),Ie(L,x,ae))return{edge:p,edgeId:String(p.id??""),nodeId:m,atStart:g,orientation:"V",coord:L.x,min:Math.min(L.y,x.y),max:Math.max(L.y,x.y),boundary:L,railEnd:x,rect:I};if(Le(L,x,ae))return{edge:p,edgeId:String(p.id??""),nodeId:m,atStart:g,orientation:"H",coord:L.y,min:Math.min(L.x,x.x),max:Math.max(L.x,x.x),boundary:L,railEnd:x,rect:I}},"terminalLaneFor"),a=i((p,g)=>Math.max(0,Math.min(p.max,g.max)-Math.max(p.min,g.min)),"projectedOverlapLength"),l=i((p,g)=>p.nodeId!==g.nodeId||p.orientation!==g.orientation?!1:p.orientation==="H"?(Math.abs(p.boundary.x-p.rect.left)<1||Math.abs(p.boundary.x-p.rect.right)<1)&&Ie(p.boundary,g.boundary,1):(Math.abs(p.boundary.y-p.rect.top)<1||Math.abs(p.boundary.y-p.rect.bottom)<1)&&Le(p.boundary,g.boundary,1),"sameTerminalFace"),u=i((p,g)=>p.nodeId!==g.nodeId||p.orientation!==g.orientation?!1:a(p,g)>=Ue&&Math.abs(p.coord-g.coord)<.5,"exactTerminalLaneConflict"),h=i((p,g)=>{if(p.nodeId!==g.nodeId||p.orientation!==g.orientation||p.orientation!=="H"||p.atStart===g.atStart)return!1;let d=a(p,g);if(d<Ue)return!1;let m=p.rect.bottom-p.rect.top;return d<m||d>2*m?!1:l(p,g)&&Math.abs(p.coord-g.coord)<16},"nearTerminalLaneConflict"),y=i((p,g)=>{let d=xe(p.edge.points??[]);if(d.length<2)return;let m=p.orientation==="V"?{x:p.boundary.x+g,y:p.boundary.y}:{x:p.boundary.x,y:p.boundary.y+g},M=p.orientation==="V"?{x:p.railEnd.x+g,y:p.railEnd.y}:{x:p.railEnd.x,y:p.railEnd.y+g};if(!i(()=>Math.abs(p.boundary.y-p.rect.top)<1||Math.abs(p.boundary.y-p.rect.bottom)<1?Le(m,p.boundary,ae)&&m.x>=p.rect.left+1&&m.x<=p.rect.right-1:Math.abs(p.boundary.x-p.rect.left)<1||Math.abs(p.boundary.x-p.rect.right)<1?Ie(m,p.boundary,ae)&&m.y>=p.rect.top+1&&m.y<=p.rect.bottom-1:!1,"boundaryStaysOnSameFace")())return;if(p.atStart){let x=d.length>1&&st(d[1],p.railEnd,ae),R=d.slice(x?2:1),E=R[0];return E&&!Hn(E,M)?void 0:[m,M,...R]}let N=d.length>1&&st(d[d.length-2],p.railEnd,ae),T=d.slice(0,N?-2:-1),L=T[T.length-1];if(!(L&&!Hn(L,M)))return[...T,M,m]},"shiftedCandidate"),c=i(p=>{let g=p.edge,d=xe(g.points??[]);if(d.length!==2)return!1;let m=g.start,M=g.end,I=m?t.get(m):void 0,N=M?t.get(M):void 0;if(!I||!N)return!1;let T=I.x??0,L=I.y??0,x=N.x??0,R=N.y??0,[E,v]=d;return Le(E,v,ae)&&Math.abs(L-R)<1&&Math.abs(T-x)>1||Ie(E,v,ae)&&Math.abs(T-x)<1&&Math.abs(L-R)>1},"laneIsStraightCollinearConnector"),b=[-7,7,-14,14,-21,21];for(let p=0;p<8;p++){let g=e.filter(m=>!m.isLayoutOnly).flatMap(m=>[s(m,!0),s(m,!1)]).filter(m=>!!m),d=!1;for(let m=0;m<g.length&&!d;m++)for(let M=m+1;M<g.length&&!d;M++){let I=g[m],N=g[M];if(I.edge===N.edge||!(u(I,N)||h(I,N)))continue;let T=!u(I,N),L=[I,N].sort((x,R)=>{let E=c(x),v=c(R);return E!==v?Number(E)-Number(v):+!R.atStart-+!x.atStart});for(let x of L){for(let R of b){let E=y(x,R);if(!E)continue;let v=s({...x.edge,points:E},x.atStart);if(!(!v||g.some(k=>k.edge!==x.edge&&(u(v,k)||T&&h(v,k))))){x.edge.points=E,d=!0;break}}if(d)break}}if(!d)return}}i(Xn,"separateSharedRenderedTerminalLanes");function jo(e,t){let{realNodeRects:r,labelNodeRects:s}=xt(t.values()),a=i((u,h)=>{let y=u.start,c=u.end,b=pe(h);if(b.length!==h.length-1)return!1;let p=[y,c].filter(g=>!!g);for(let g of b)if(Oe(g.a,g.b,r,p,-2)||Oe(g.a,g.b,s,[],-2))return!1;for(let g of e){if(g===u||g.isLayoutOnly)continue;let d=g.points;if(!(!d||d.length<2)){for(let m of b)for(let M of pe(xe(d)))if(mt(m,M,.5)>=Ue||ht(m.a,m.b,M.a,M.b,ae))return!1}}return!0},"candidateIsSafe"),l=i((u,h)=>{if(h+4>=u.length)return;let y=u[h],c=u[h+1],b=u[h+2],p=u[h+3],g=u[h+4],d=_e(y,c)&&De(c,b)&&_e(b,p)&&De(p,g)&&Ie(y,p,ae)&&Ie(y,g,ae)&&Ie(c,b,ae)&&(c.x-y.x)*(p.x-b.x)<0,m=De(y,c)&&_e(c,b)&&De(b,p)&&_e(p,g)&&Le(y,p,ae)&&Le(y,g,ae)&&Le(c,b,ae)&&(c.y-y.y)*(p.y-b.y)<0;if(d||m)return xe([...u.slice(0,h+1),g,...u.slice(h+5)]);if(h+5>=u.length)return;let M=u[h+5],I=De(y,c)&&_e(c,b)&&De(b,p)&&_e(p,g)&&De(g,M)&&Ie(y,g,ae)&&Ie(y,M,ae)&&Ie(b,p,ae)&&(b.x-c.x)*(g.x-p.x)<0,N=_e(y,c)&&De(c,b)&&_e(b,p)&&De(p,g)&&_e(g,M)&&Le(y,g,ae)&&Le(y,M,ae)&&Le(b,p,ae)&&(b.y-c.y)*(g.y-p.y)<0;if(!(!I&&!N))return xe([...u.slice(0,h+1),M,...u.slice(h+6)])},"withoutDogleg");for(let u=0;u<8;u++){let h=!1;for(let y of e){if(y.isLayoutOnly)continue;let c=xe(y.points??[]);for(let b=0;b<=c.length-5;b++){let p=l(c,b);if(!(!p||!a(y,p))){y.points=p,h=!0;break}}if(h)break}if(!h)return}}i(jo,"collapseRedundantRectangularDoglegs");function Yn(e,t){let{realNodeRects:s,labelNodeRects:a}=xt(t.values()),l=e.filter(g=>!g.isLayoutOnly),u=i((g,d,m)=>xe(g===d?m??[]:g.points??[]),"pointsFor"),h=i((g,d)=>{let m=0;for(let M=0;M<l.length;M++){let I=pe(u(l[M],g,d));for(let N=M+1;N<l.length;N++){let T=pe(u(l[N],g,d));for(let L of I)for(let x of T)ht(L.a,L.b,x.a,x.b,ae)&&m++}}return m},"strictCrossingCount"),y=i(g=>{let d=pe(g);if(d.length!==3)return;let m=d[1];if(!(d[0].horizontal===m.horizontal||d[2].horizontal===m.horizontal))return{index:m.index,horizontal:m.horizontal,vertical:m.vertical,segment:m}},"middleRail"),c=i((g,d)=>{let m=[g.start,g.end].filter(M=>!!M);return s.filter(M=>{if(m.includes(M.id))return!1;let I=M.rect;return d.horizontal?Je(d.a.x,d.b.x,I.left,I.right)>=Ue&&d.a.y>=I.top-2&&d.a.y<=I.bottom+2:Je(d.a.y,d.b.y,I.top,I.bottom)>=Ue&&d.a.x>=I.left-2&&d.a.x<=I.right+2})},"blockingRectsFor"),b=i((g,d,m)=>{let M=g.map(N=>({...N}));if(d.horizontal)M[d.index].y=m,M[d.index+1].y=m;else if(d.vertical)M[d.index].x=m,M[d.index+1].x=m;else return;let I=ut(xe(M));return pe(I).length===I.length-1?I:void 0},"candidateByMovingRail"),p=i((g,d,m)=>{let M=[g.start,g.end].filter(N=>!!N),I=pe(d);if(I.length!==d.length-1)return!1;for(let N of I)if(Oe(N.a,N.b,s,M,-2)||Oe(N.a,N.b,a,[],-2))return!1;for(let N of l)if(N!==g){for(let T of I)for(let L of pe(u(N)))if(mt(T,L,.5)>=Ue)return!1}return h(g,d)<=m},"candidateIsSafe");for(let g=0;g<8;g++){let d=h(),m=!1;for(let M of l){let I=u(M),N=y(I);if(!N)continue;let T=c(M,N.segment);if(T.length===0)continue;let L=N.horizontal?[Math.min(...T.map(x=>x.rect.top))-20,Math.max(...T.map(x=>x.rect.bottom))+20]:[Math.min(...T.map(x=>x.rect.left))-20,Math.max(...T.map(x=>x.rect.right))+20];for(let x of L){let R=b(I,N.segment,x);if(!(!R||!p(M,R,d))){M.points=R,m=!0;break}}if(m)break}if(!m)return}}i(Yn,"liftObstacleHuggingSameSideRails");function $n(e,t,n){let r=i(y=>{let c=y.groupTitleRect;if(!(!c||typeof c.left!="number"||typeof c.right!="number"||typeof c.top!="number"||typeof c.bottom!="number"||!Number.isFinite(c.left)||!Number.isFinite(c.right)||!Number.isFinite(c.top)||!Number.isFinite(c.bottom)||c.right<=c.left||c.bottom<=c.top))return{left:c.left,right:c.right,top:c.top,bottom:c.bottom}},"validTitleRect"),s=Ze([...t.values()]),a=i(y=>{if(!s.isLane(y.id))return;let c=$o(y.direction??n);if(c==="LR"||c==="RL"||c==="BT")return;let b=r(y),p=y.y,g=y.height;if(!b||typeof p!="number"||typeof g!="number"||!Number.isFinite(p)||!Number.isFinite(g)||g<=0)return;let d=b.right-b.left,m=b.bottom-b.top;if(!(m<=0||d<m))return{node:y,rect:b}},"topLaneTitleFor"),l=i((y,c)=>{if(!y.horizontal)return!1;let b=y.a.y;return b<c.top-ae||b>c.bottom+ae?!1:Je(y.a.x,y.b.x,c.left,c.right)>=Ue},"horizontalSegmentIntersectsTitle"),u=[...t.values()].map(a).filter(y=>!!y);if(u.length===0)return;let h=0;for(let y of e){if(y.isLayoutOnly)continue;let c=xe(y.points??[]);for(let b of pe(c))for(let p of u)l(b,p.rect)&&(h=Math.max(h,p.rect.bottom-b.a.y+4))}if(!(h<=ae))for(let y of u){let c=y.node.y,b=y.node.height;typeof c!="number"||typeof b!="number"||!Number.isFinite(c)||!Number.isFinite(b)||b<=0||(y.node.y=c-h/2,y.node.height=b+h,y.node.groupTitleRect={...y.rect,top:y.rect.top-h,bottom:y.rect.bottom-h})}}i($n,"liftTopLaneTitleBandsAboveRails");function jn(e,t,n){let r=i(c=>{let b=c.groupTitleRect;if(!(!b||typeof b.left!="number"||typeof b.right!="number"||typeof b.top!="number"||typeof b.bottom!="number"||!Number.isFinite(b.left)||!Number.isFinite(b.right)||!Number.isFinite(b.top)||!Number.isFinite(b.bottom)||b.right<=b.left||b.bottom<=b.top))return{left:b.left,right:b.right,top:b.top,bottom:b.bottom}},"validTitleRect"),s=Ze([...t.values()]),a=i(c=>{if(!s.isLane(c.id)||$o(c.direction??n)!=="LR")return;let p=r(c),g=c.x,d=c.width;if(!p||typeof g!="number"||typeof d!="number"||!Number.isFinite(g)||!Number.isFinite(d)||d<=0)return;let m=p.right-p.left,M=p.bottom-p.top;if(!(m<=0||M<m))return{node:c,rect:p}},"leftLaneTitleFor"),l=i((c,b)=>{if(!c.vertical)return!1;let p=c.a.x;return p<b.left-ae||p>b.right+ae?!1:Je(c.a.y,c.b.y,b.top,b.bottom)>=Ue},"verticalSegmentIntersectsTitle"),u=i((c,b)=>{if(!c.horizontal)return!1;let p=c.a.y;return p<b.top-ae||p>b.bottom+ae?!1:Je(c.a.x,c.b.x,b.left,b.right)>=Ue},"horizontalSegmentIntersectsTitle"),h=[...t.values()].map(a).filter(c=>!!c);if(h.length===0)return;let y=0;for(let c of e){if(c.isLayoutOnly)continue;let b=xe(c.points??[]);for(let p of pe(b))for(let g of h)if(l(p,g.rect))y=Math.max(y,g.rect.right-p.a.x+4);else if(u(p,g.rect)){let d=Math.min(p.a.x,p.b.x);y=Math.max(y,g.rect.right-d+4)}}if(!(y<=ae))for(let c of h){let b=c.node.x,p=c.node.width;typeof b!="number"||typeof p!="number"||!Number.isFinite(b)||!Number.isFinite(p)||p<=0||(c.node.x=b-y/2,c.node.width=p+y,c.node.groupTitleRect={...c.rect,left:c.rect.left-y,right:c.rect.right-y})}}i(jn,"shiftLeftLaneTitleBandsLeftOfRails");function Vo(e,t){let{realNodeRects:r}=xt(t.values()),s=e.filter(d=>!d.isLayoutOnly),a=i((d,m=new Map)=>xe(m.get(d)??d.points??[]),"replacementPointsFor"),l=i((d=new Map)=>{let m=0;for(let M=0;M<s.length;M++){let I=pe(a(s[M],d));for(let N=M+1;N<s.length;N++){let T=pe(a(s[N],d));for(let L of I)for(let x of T)ht(L.a,L.b,x.a,x.b,ae)&&m++}}return m},"crossingCount"),u=i((d=new Map)=>s.reduce((m,M)=>m+it(a(M,d)),0),"totalBends"),h=i(d=>{let m=a(d);if(m.length<4)return;let M=m[m.length-2],I=m[m.length-1];if(!(!_e(M,I,ae)&&!De(M,I,ae)))return{tailStart:M,terminal:I}},"terminalTailFor"),y=i((d,m)=>{let M=a(d);if(M.length<3)return;let I=M[0],N=M[1],T;if(_e(I,N,ae))T={x:N.x,y:m.tailStart.y};else if(De(I,N,ae))T={x:m.tailStart.x,y:N.y};else return;let L=ut(xe([I,N,T,m.tailStart,m.terminal]));return pe(L).length===L.length-1?L:void 0},"candidateWithDestinationTail"),c=i((d,m)=>{let M=[d.start,d.end].filter(I=>!!I);for(let I of pe(m))if(Oe(I.a,I.b,r,M,-2))return!0;return!1},"pathHasNodeHit"),b=i((d,m,M)=>{for(let I of s)if(I!==d){for(let N of pe(m))for(let T of pe(a(I,M)))if(mt(N,T,.5)>=Ue)return!0}return!1},"pathHasSharedTrack"),p=i((d,m,M)=>!c(d,m)&&!b(d,m,M),"candidateIsSafe"),g=i(()=>{let d=new Map;for(let m of s){let M=m.end;if(!M||!t.has(M)||a(m).length<4)continue;let N=d.get(M)??[];N.push(m),d.set(M,N)}return d},"edgesByDestination");for(let d=0;d<4;d++){let m=l();if(m===0)return;let M=u(),I,N=m,T=M;for(let L of g().values())for(let x=0;x<L.length;x++)for(let R=x+1;R<L.length;R++){let E=L[x],v=L[R],k=h(E),O=h(v);if(!k||!O)continue;let B=y(E,O),j=y(v,k);if(!B||!j)continue;let X=new Map([[E,B],[v,j]]);if(!p(E,B,X)||!p(v,j,X))continue;let J=l(X),ie=u(X);J>=m||J>N||J===N&&ie>=T||(I=X,N=J,T=ie)}if(!I)return;for(let[L,x]of I)L.points=x}}i(Vo,"swapDestinationTerminalTailsToReduceCrossings");function Uo(e,t){let{realNodeRects:a,labelNodeRects:l}=xt(t.values()),u=e.filter(L=>!L.isLayoutOnly),h=i((L,x=new Map)=>xe(x.get(L)??L.points??[]),"replacementPointsFor"),y=i((L=new Map)=>{let x=0;for(let R=0;R<u.length;R++){let E=pe(h(u[R],L));for(let v=R+1;v<u.length;v++){let k=pe(h(u[v],L));for(let O of E)for(let B of k)ht(O.a,O.b,B.a,B.b,ae)&&x++}}return x},"strictCrossingCount"),c=i((L=new Map)=>u.reduce((x,R)=>x+it(h(R,L)),0),"totalBends"),b=i(L=>{let x=L.start,R=L.end,E=x?t.get(x):void 0,v=R?t.get(R):void 0,k=E?Ve(E):void 0,O=v?Ve(v):void 0;return k&&O?{src:k,dst:O}:void 0},"endpointRectsFor"),p=i((L,x,R)=>{if(R.index<=0||R.index+1>=x.length-1)return;let E=b(L);if(E){if(R.vertical){let v=R.a.x,k=Math.min(E.src.left,E.dst.left),O=Math.max(E.src.right,E.dst.right),B=v<k-ae?"left":v>O+ae?"right":void 0;return B?{edge:L,points:x,segmentIndex:R.index,axis:"vertical",side:B,coord:v,min:Math.min(R.a.y,R.b.y),max:Math.max(R.a.y,R.b.y)}:void 0}if(R.horizontal){let v=R.a.y,k=Math.min(E.src.top,E.dst.top),O=Math.max(E.src.bottom,E.dst.bottom),B=v<k-ae?"top":v>O+ae?"bottom":void 0;return B?{edge:L,points:x,segmentIndex:R.index,axis:"horizontal",side:B,coord:v,min:Math.min(R.a.x,R.b.x),max:Math.max(R.a.x,R.b.x)}:void 0}}},"externalRailForSegment"),g=i(()=>{let L=[];for(let x of u){let R=h(x);for(let E of pe(R)){let v=p(x,R,E);v&&L.push(v)}}return L},"collectExternalRails"),d=i((L,x)=>L.edge!==x.edge&&L.axis===x.axis&&L.side===x.side&&Je(L.min,L.max,x.min,x.max)>=Ue,"railsInteract"),m=i(L=>{let x=[],R=new Set;for(let E of L){if(R.has(E))continue;let v=[E],k=[];for(R.add(E);v.length>0;){let O=v.pop();k.push(O);for(let B of L)!R.has(B)&&d(O,B)&&(R.add(B),v.push(B))}k.length>1&&x.push(k)}return x},"connectedComponents"),M=i(L=>{let x=[];for(let R of L)x.some(E=>Math.abs(E-R.coord)<ae)||x.push(R.coord);for(;x.length<L.length;){let R=Math.min(...x),E=Math.max(...x),v=L[0].side;x.push(v==="left"||v==="top"?R-12*(L.length-x.length):E+12*(L.length-x.length))}return x},"uniqueCoordsFor"),I=i(L=>{let x=L.map(v=>v.coord),R=M(L),E=[];if(L.length<=6){let v=new Array(R.length).fill(!1),k=[],O=i(()=>{if(k.length===L.length){k.some((B,j)=>Math.abs(B-x[j])>=ae)&&E.push([...k]);return}for(let[B,j]of R.entries())v[B]||(v[B]=!0,k.push(j),O(),k.pop(),v[B]=!1)},"visit");return O(),E}for(let v=0;v<x.length;v++)for(let k=v+1;k<x.length;k++){let O=[...x];[O[v],O[k]]=[O[k],O[v]],E.push(O)}return E},"coordinateAssignmentsFor"),N=i((L,x)=>{let R=new Map;for(let[v,k]of L.entries()){let O=x[v],B=R.get(k.edge)??k.points.map(j=>({x:j.x,y:j.y}));k.axis==="vertical"?(B[k.segmentIndex].x=O,B[k.segmentIndex+1].x=O):(B[k.segmentIndex].y=O,B[k.segmentIndex+1].y=O),R.set(k.edge,B)}let E=new Map;for(let[v,k]of R){let O=ut(xe(k));if(pe(O).length!==O.length-1)return;E.set(v,O)}return E},"replacementsForAssignment"),T=i(L=>{for(let[x,R]of L){let E=[x.start,x.end].filter(v=>!!v);for(let v of pe(R))if(Oe(v.a,v.b,a,E,-2)||Oe(v.a,v.b,l,[],-2))return!1}for(let x=0;x<u.length;x++){let R=u[x],E=L.has(R),v=pe(h(R,L));for(let k=x+1;k<u.length;k++){let O=u[k];if(!E&&!L.has(O))continue;let B=pe(h(O,L));for(let j of v)for(let X of B)if(mt(j,X,.5)>=Ue)return!1}}return!0},"candidateIsSafe");for(let L=0;L<4;L++){let x=y();if(x===0)return;let R,E=x,v=c(),k=Number.POSITIVE_INFINITY;for(let O of m(g()))for(let B of I(O)){let j=N(O,B);if(!j||!T(j))continue;let X=y(j);if(X>=x)continue;let J=c(j),ie=O.reduce((fe,Ce,nt)=>fe+Math.abs(B[nt]-Ce.coord),0);X>E||X===E&&(J>v||J===v&&ie>=k)||(R=j,E=X,v=J,k=ie)}if(!R)return;for(let[O,B]of R)O.points=B}}i(Uo,"reassignCrossingExternalRailChannels");function Wo(e,t){let{realNodeRects:r,labelNodeRects:s}=xt(t.values()),a=e.filter(g=>!g.isLayoutOnly),l=i((g,d,m)=>xe(g===d?m??[]:g.points??[]),"pointsFor"),u=i(g=>pe(g).reduce((d,m)=>{let M=m.a.x-m.b.x,I=m.a.y-m.b.y;return d+Math.hypot(M,I)},0),"pathLength"),h=i((g,d)=>{let m=0;for(let M=0;M<a.length;M++){let I=pe(l(a[M],g,d));for(let N=M+1;N<a.length;N++){let T=pe(l(a[N],g,d));for(let L of I)for(let x of T)ht(L.a,L.b,x.a,x.b,ae)&&m++}}return m},"strictCrossingCount"),y=i((g,d)=>{if(g.horizontal){let m=g.a.y;return(Math.abs(m-d.top)<1||Math.abs(m-d.bottom)<1)&&Je(g.a.x,g.b.x,d.left,d.right)>=Ue}if(g.vertical){let m=g.a.x;return(Math.abs(m-d.left)<1||Math.abs(m-d.right)<1)&&Je(g.a.y,g.b.y,d.top,d.bottom)>=Ue}return!1},"segmentRunsAlongRectBorder"),c=i(g=>{let d=[g.start,g.end].filter(M=>!!M),m=[];for(let M of d){let I=t.get(M),N=I?Ve(I):void 0;N&&m.push(N)}return m},"endpointRectsFor"),b=i((g,d)=>{if(d+3>=g.length)return[];let m=g[d],M=g[d+1],I=g[d+2],N=g[d+3],T=_e(m,M,ae)&&De(M,I,ae)&&_e(I,N,ae),L=De(m,M,ae)&&_e(M,I,ae)&&De(I,N,ae);if(!T&&!L)return[];if(!(T?Math.sign(M.x-m.x)!==Math.sign(N.x-I.x):Math.sign(M.y-m.y)!==Math.sign(N.y-I.y)))return[];let R=Ie(m,N,ae)||Le(m,N,ae)?[]:[{x:m.x,y:N.y},{x:N.x,y:m.y}],E=R.length===0?[[...g.slice(0,d+1),...g.slice(d+3)]]:R.map(k=>[...g.slice(0,d+1),k,...g.slice(d+3)]),v=new Set;return E.map(k=>ut(xe(k))).filter(k=>{if(pe(k).length!==k.length-1||!k.some(B=>st(B,N,ae)))return!1;let O=k.map(B=>`${B.x.toFixed(3)},${B.y.toFixed(3)}`).join("|");return v.has(O)?!1:(v.add(O),!0)})},"shortcutCandidatesAt"),p=i((g,d,m)=>{let M=[g.start,g.end].filter(N=>!!N),I=c(g);for(let N of pe(d))if(Oe(N.a,N.b,r,M,-2)||Oe(N.a,N.b,s,[],-2)||I.some(T=>y(N,T)))return!1;for(let N of a)if(N!==g){for(let T of pe(d))for(let L of pe(l(N)))if(mt(T,L,.5)>=Ue)return!1}return h(g,d)<=m},"candidateIsSafe");for(let g=0;g<8;g++){let d=h(),m,M,I=d,N=Number.POSITIVE_INFINITY,T=Number.POSITIVE_INFINITY;for(let L of a){let x=l(L),R=it(x,ae),E=u(x);for(let v=0;v<=x.length-4;v++)for(let k of b(x,v)){let O=it(k,ae),B=u(k);if(!(O<R||O===R&&B<E-ae)||!p(L,k,d))continue;let X=h(L,k);X>I||X===I&&(O>N||O===N&&B>=T)||(m=L,M=k,I=X,N=O,T=B)}}if(!m||!M)return;m.points=M}}i(Wo,"shortcutRedundantOrthogonalJogs");function Ko(e,t){let a=[];for(let A of t.values()){if(A.isGroup||A.isEdgeLabel)continue;let _=A.x??0,G=A.y??0,U=Ve(A);U&&a.push({id:String(A.id??""),cx:_,cy:G,rect:U})}if(a.length===0)return;let l=new Map(a.map(A=>[A.id,A])),u=a.map(A=>({id:A.id,rect:A.rect})),h=["top","bottom","left","right"],y={top:Math.min(...a.map(A=>A.rect.top))-20,bottom:Math.max(...a.map(A=>A.rect.bottom))+20,left:Math.min(...a.map(A=>A.rect.left))-20,right:Math.max(...a.map(A=>A.rect.right))+20},c=e.filter(A=>!A.isLayoutOnly),b=new Map(c.map((A,_)=>[A,_])),p=i(A=>{let _=A==="left"||A==="top"?-1:1,G=[];for(let U=0;U<=2;U++)G.push(y[A]+_*20*U);return G},"outwardTracksForSide"),g=i((A,_=new Map)=>xe(_.get(A)??A.points??[]),"replacementPointsFor"),d=i((A,_)=>{let G=0;for(let U of A)for(let K of _)ht(U.a,U.b,K.a,K.b,ae)&&G++;return G},"crossingCountBetweenSegments"),m=i((A,_)=>d(pe(A),pe(_)),"crossingCountBetweenPaths"),M=i((A=new Map)=>{let _=0,G=[],U=new Set,K=[],te=i(H=>{U.has(H)||(U.add(H),K.push(H))},"addEdge");for(let H=0;H<c.length;H++){let ne=c[H],le=g(ne,A);for(let f=H+1;f<c.length;f++){let S=c[f],P=m(le,g(S,A));P>0&&(_+=P,G.push({first:ne,second:S,count:P}),te(ne),te(S))}}return K.sort((H,ne)=>(b.get(H)??0)-(b.get(ne)??0)),{count:_,pairs:G,edgeSet:U,edges:K}},"crossingSnapshot"),I=i((A,_)=>{let G=new Set(_.keys());if(G.size===0)return A.count;let U=0;for(let te of A.pairs)(G.has(te.first)||G.has(te.second))&&(U+=te.count);let K=0;for(let te=0;te<c.length;te++){let H=c[te],ne=G.has(H),le=g(H,_);for(let f=te+1;f<c.length;f++){let S=c[f];!ne&&!G.has(S)||(K+=m(le,g(S,_)))}}return A.count-U+K},"crossingCountWithReplacements"),N=i(A=>{let _=new Map;for(let K of A.pairs){let te=_.get(K.first)??new Set;te.add(K.second),_.set(K.first,te);let H=_.get(K.second)??new Set;H.add(K.first),_.set(K.second,H)}let G=[],U=new Set;for(let K of A.edges){if(U.has(K))continue;let te=[K],H=[];for(U.add(K);te.length>0;){let ne=te.pop();H.push(ne);for(let le of _.get(ne)??[])U.has(le)||(U.add(le),te.push(le))}H.sort((ne,le)=>(b.get(ne)??0)-(b.get(le)??0)),H.length>1&&G.push(H)}return G},"crossingComponents"),T=i(A=>[A.start,A.end].filter(_=>!!_),"endpointIdsFor"),L=i(A=>{let _=[];for(let G of N(A)){let U=new Set(G),K=new Set(G.flatMap(H=>T(H))),te=[...G];for(let H of c)U.has(H)||T(H).some(ne=>K.has(ne))&&te.push(H);te.sort((H,ne)=>(b.get(H)??0)-(b.get(ne)??0)),_.push(te)}return _},"pairSearchGroups"),x=i((A,_,G)=>I(A,new Map([[_,G]])),"crossingCountWithSingleReplacement"),R=i(A=>{let _=new Map;for(let G of A.pairs)_.set(G.first,(_.get(G.first)??0)+G.count),_.set(G.second,(_.get(G.second)??0)+G.count);return _},"currentCrossingsByEdge"),E=i(A=>A.slice(1).reduce((_,G,U)=>{let K=A[U];return _+Math.abs(G.x-K.x)+Math.abs(G.y-K.y)},0),"pathLength"),v=i((A=new Map)=>c.reduce((_,G)=>_+it(g(G,A)),0),"totalBends"),k=i((A=new Map)=>c.reduce((_,G)=>_+E(g(G,A)),0),"totalLength"),O=i((A,_)=>Mo(A,_,hn.ROUTE_TOUCH_TOLERANCE),"touchesAtBend"),B=i((A,_,G=new Map)=>{let U=pe(_);for(let K of c)if(K!==A){for(let te of U)for(let H of pe(g(K,G)))if(mt(te,H,.5)>=Ue)return!0;if(O(_,g(K,G)))return!0}return!1},"pathHasSegmentConflict"),j=i((A,_)=>{let G=[A.start,A.end].filter(U=>!!U);for(let U of pe(_))if(Oe(U.a,U.b,u,G,-2))return!0;return!1},"pathHitsNode"),X=i((A,_)=>{let G=ut(xe(_));pe(G).length===G.length-1&&A.push(G)},"pushOrthogonalCandidate"),J=i(A=>A==="left"||A==="right","sideIsHorizontal"),ie=i((A,_,G)=>{switch(_){case"left":return Math.min(A.x,G.x)-20;case"right":return Math.max(A.x,G.x)+20;case"top":return Math.min(A.y,G.y)-20;case"bottom":return Math.max(A.y,G.y)+20}},"localTrackForSameSide"),fe=i((A,_,G,U)=>{let K=G==="left"||G==="top"?-1:1,te=[ie(_,G,U),y[G]];for(let H of te)for(let ne=0;ne<=2;ne++)X(A,fn(_,G,U,H+K*20*ne))},"addSameSideCandidates"),Ce=i((A,_,G,U,K)=>{for(let te of p(G))for(let H of p(K))X(A,[_,{x:te,y:_.y},{x:te,y:H},{x:U.x,y:H},U])},"addHorizontalToVerticalCandidates"),nt=i((A,_,G,U,K)=>{for(let te of p(G))for(let H of p(K))X(A,[_,{x:_.x,y:te},{x:H,y:te},{x:H,y:U.y},U])},"addVerticalToHorizontalCandidates"),$e=i((A,_,G,U,K)=>{let te=[...p("top"),...p("bottom")];for(let H of p(G))for(let ne of p(K))for(let le of te)X(A,[_,{x:H,y:_.y},{x:H,y:le},{x:ne,y:le},{x:ne,y:U.y},U])},"addHorizontalPairCandidates"),je=i((A,_,G,U,K)=>{let te=[...p("left"),...p("right")];for(let H of p(G))for(let ne of p(K))for(let le of te)X(A,[_,{x:_.x,y:H},{x:le,y:H},{x:le,y:ne},{x:U.x,y:ne},U])},"addVerticalPairCandidates"),Q=i(A=>{let _=new Set;return A.map(G=>xe(G)).filter(G=>{let U=G.map(K=>`${K.x.toFixed(3)},${K.y.toFixed(3)}`).join("|");return _.has(U)||G.length<2?!1:(_.add(U),!0)})},"dedupeCandidatePaths"),de=i((A,_,G,U)=>{let K=[],te=ln(A,_,G,U,20,ae);te&&X(K,te),_===U&&fe(K,A,_,G);let H=J(_),ne=J(U);return H&&!ne?Ce(K,A,_,G,U):!H&&ne?nt(K,A,_,G,U):H?$e(K,A,_,G,U):je(K,A,_,G,U),Q(K)},"buildCandidatesForSides"),D=i((A,_,G,U)=>{let K=[...p("left"),...p("right")],te=[...p("top"),...p("bottom")];for(let H of h){let ne=Pt(U,H),le=H==="top"||H==="bottom"?p(H):te;for(let f of K){J(H)&&X(A,[_,G,{x:f,y:G.y},{x:f,y:ne.y},ne]);for(let S of le)X(A,[_,G,{x:f,y:G.y},{x:f,y:S},{x:ne.x,y:S},ne])}}},"addVerticalDepartureOuterTrackCandidates"),Y=i((A,_,G,U)=>{let K=[...p("left"),...p("right")],te=[...p("top"),...p("bottom")];for(let H of h){let ne=Pt(U,H),le=H==="left"||H==="right"?p(H):K;for(let f of te){J(H)||X(A,[_,G,{x:G.x,y:f},{x:ne.x,y:f},ne]);for(let S of le)X(A,[_,G,{x:G.x,y:f},{x:S,y:f},{x:S,y:ne.y},ne])}}},"addHorizontalDepartureOuterTrackCandidates"),ee=i(A=>{let _=A.start,G=A.end,U=G?l.get(G):void 0;if(!_||!U)return[];let K=xe(A.points??[]);if(K.length<4)return[];let te=K[0],H=K[1],ne=[];return De(te,H,ae)?D(ne,te,H,U):_e(te,H,ae)&&Y(ne,te,H,U),ne},"terminalPreservingOuterTrackCandidates"),q=i(A=>{let _=A.start,G=A.end,U=_?l.get(_):void 0,K=G?l.get(G):void 0;if(!U||!K)return[];let te=[];for(let H of h){let ne=Pt(U,H);for(let le of h)te.push(...de(ne,H,Pt(K,le),le))}return te.push(...ee(A)),te},"candidatePathsFor"),re=i(()=>new Map(c.map(A=>[A,pe(g(A))])),"currentSegmentsByEdge"),ue=i((A,_,G,U)=>{let K=new Set;for(let te of c){if(te===A)continue;let H=U.get(te)??pe(g(te));(G.some(ne=>H.some(le=>mt(ne,le,.5)>=Ue))||O(_,g(te)))&&K.add(te)}return K},"sharedTrackConflictsFor"),me=i((A,_,G,U)=>{let K=new Set;return q(A).map(H=>ut(xe(H))).filter(H=>{if(j(A,H))return!1;let ne=H.map(le=>`${le.x.toFixed(3)},${le.y.toFixed(3)}`).join("|");return K.has(ne)||H.length<2?!1:(K.add(ne),!0)}).map(H=>{let ne=pe(H),le=0;for(let f of c)f!==A&&(le+=d(ne,G.get(f)??pe(g(f))));return{candidate:H,candidateSegments:ne,crossings:_.count-(U.get(A)??0)+le,bends:it(H,ae),totalBends:it(H),length:E(H)}}).filter(({crossings:H})=>H<=_.count).sort((H,ne)=>H.crossings-ne.crossings||H.bends-ne.bends||H.length-ne.length).slice(0,48).map(H=>({path:H.candidate,segments:H.candidateSegments,sharedTrackConflicts:ue(A,H.candidate,H.candidateSegments,G),totalBends:H.totalBends,length:H.length}))},"pairCandidatesFor"),he=i((A,_,G,U,K,te)=>{let H=0;for(let le of A.pairs)(le.first===_||le.second===_||le.first===U||le.second===U)&&(H+=le.count);let ne=d(G.segments,K.segments);for(let le of c){if(le===_||le===U)continue;let f=te.get(le)??pe(g(le));ne+=d(G.segments,f)+d(K.segments,f)}return A.count-H+ne},"pairCrossingCount"),be=i((A,_)=>{for(let G of A.sharedTrackConflicts)if(G!==_)return!1;return!0},"conflictsOnlyWith"),ke=i((A,_)=>A.segments.some(G=>_.segments.some(U=>mt(G,U,.5)>=Ue))||O(A.path,_.path),"candidatesShareTrack"),At=i((A,_,G,U)=>be(_,G.edge)&&be(U,A.edge)&&!ke(_,U),"pairCandidatesAreCompatible"),It=i((A,_,G,U,K)=>{let te=he(A.current,_.edge,G,U.edge,K,A.baseSegments);if(!(te>=A.current.count))return{replacements:new Map([[_.edge,G.path],[U.edge,K.path]]),crossings:te,bends:A.currentBends-(A.baseBendsByEdge.get(_.edge)??0)-(A.baseBendsByEdge.get(U.edge)??0)+G.totalBends+K.totalBends,length:A.currentLength-(A.baseLengthByEdge.get(_.edge)??0)-(A.baseLengthByEdge.get(U.edge)??0)+G.length+K.length}},"scorePairReplacement"),Mt=i((A,_)=>A.crossings<_.crossings||A.crossings===_.crossings&&(A.bends<_.bends||A.bends===_.bends&&A.length<_.length),"pairScoreIsBetter"),Tt=i((A,_,G,U)=>{let K=U;for(let te of _.candidates)for(let H of G.candidates){if(!At(_,te,G,H))continue;let ne=It(A,_,te,G,H);ne&&Mt(ne,K)&&(K=ne)}return K},"bestScoreForOptionPair"),qt=i(A=>{let _=v(),G=k(),U=re(),K=R(A),te=new Map(c.map(P=>[P,it(g(P))])),H=new Map(c.map(P=>[P,E(g(P))])),ne=new Map,le=L(A);for(let P of le)for(let C of P){if(ne.has(C))continue;let w=me(C,A,U,K);w.length>0&&ne.set(C,{edge:C,candidates:w})}let f={replacements:new Map,crossings:A.count,bends:_,length:G},S={current:A,currentBends:_,currentLength:G,baseBendsByEdge:te,baseLengthByEdge:H,baseSegments:U};for(let P of le){let C=new Set(P.filter(F=>A.edgeSet.has(F))),w=P.map(F=>ne.get(F)).filter(F=>!!F);for(let F=0;F<w.length;F++){let Z=w[F];for(let ce=F+1;ce<w.length;ce++){let W=w[ce];!C.has(Z.edge)&&!C.has(W.edge)||(f=Tt(S,Z,W,f))}}}return f.replacements.size>0?f.replacements:void 0},"bestPairedReplacement");for(let A=0;A<4;A++){let _=M(),G=_.count;if(G===0)return;let U,K,te=G,H=Number.POSITIVE_INFINITY;for(let le of _.edges){let f=it(g(le),ae);for(let S of q(le)){let P=j(le,S),C=!P&&B(le,S),w=x(_,le,S),F=it(S,ae);P||C||!(w<G||w===G&&F<f)||w>te||w===te&&F>=H||(U=le,K=S,te=w,H=F)}}if(U&&K){U.points=K;continue}let ne=qt(_);if(!ne)return;for(let[le,f]of ne)le.points=f}}i(Ko,"resolveRenderedOrthogonalCrossings");var Ct=.001,vs=8;function qo(e,t){let{nodeInfoById:n,realNodeRects:o}=Ht(t),r=["top","bottom","left","right"],s=20,a={top:Math.min(...o.map(d=>d.rect.top))-s,bottom:Math.max(...o.map(d=>d.rect.bottom))+s,left:Math.min(...o.map(d=>d.rect.left))-s,right:Math.max(...o.map(d=>d.rect.right))+s},l=i((d,m,M,I)=>{let N=[],T=ln(d,m,M,I,s,Ct);return T&&N.push(T),m===I&&N.push(fn(d,m,M,a[m])),N},"buildOrthogonalPathCandidates"),u=i((d,m)=>{for(let M=0;M<d.length-1;M++){let I=d[M],N=d[M+1];if(Oe(I,N,o,m,1))return!0}return!1},"pathHitsNode"),h=i((d,m,M=!1)=>{let I=0,N=bt(d,Ct),T=m.start,L=m.end;for(let x of e){if(x===m||x.isLayoutOnly)continue;let R=x.start,E=x.end;if(!M&&T&&L&&(R===T||R===L||E===T||E===L))continue;let v=x.points;if(!(!v||v.length<2))for(let k of N)for(let O of bt(v,Ct)){if(Bn(k.a,k.b,O.a,O.b,Ct,Ct)){I++;continue}mt(k,O,Ct)>=vs&&I++}}return I},"pathConflictCount"),y=4,c=i((d,m)=>{let M=Math.abs(d.y-m.rect.top),I=Math.abs(d.y-m.rect.bottom),N=Math.abs(d.x-m.rect.left),T=Math.abs(d.x-m.rect.right),L="top",x=M;return I<x&&(L="bottom",x=I),N<x&&(L="left",x=N),T<x&&(L="right",x=T),L},"nearestSideOfRect"),b=new Map,p=i((d,m,M)=>{let I=b.get(d)??[];I.push({side:m,edgeId:M}),b.set(d,I)},"addFaceClaim");for(let d of e){if(d.isLayoutOnly)continue;let m=d.points??[];if(m.length<1)continue;let M=d.id??"",I=d.start,N=d.end;if(I){let T=n.get(I);T&&p(I,c(m[0],T),M)}if(N){let T=n.get(N);T&&p(N,c(m[m.length-1],T),M)}}let g=i((d,m,M)=>b.get(d)?.some(I=>I.edgeId!==M&&I.side===m)??!1,"faceIsClaimed");for(let d of e){if(d.isLayoutOnly)continue;let m=d.points;if(!m||m.length<2)continue;let M=it(m,Ct);if(M<y)continue;let I=d.start,N=d.end;if(!I||!N)continue;let T=n.get(I),L=n.get(N);if(!T||!L)continue;let x=d.id??"",R=h(m,d,!0),E=h(m,d),v,k=R,O=M;for(let B of r){if(g(I,B,x))continue;let j=Pt(T,B);for(let X of r){if(g(N,X,x))continue;let J=Pt(L,X);for(let ie of l(j,B,J,X)){if(u(ie,[I,N]))continue;let fe=it(ie,Ct);if(R>0){let Ce=h(ie,d,!0);if(Ce>k||Ce===k&&fe>=O)continue;k=Ce,O=fe,v=ie;continue}h(ie,d)>E||fe<O&&(O=fe,v=ie)}}}if(v){d.points=v;let B=b.get(I);B&&b.set(I,B.filter(X=>X.edgeId!==x));let j=b.get(N);j&&b.set(N,j.filter(X=>X.edgeId!==x)),p(I,c(v[0],T),x),p(N,c(v[v.length-1],L),x)}}}i(qo,"simplifyDetouredEdges");var at=.001,Zo=10,yn=7;function Jo(e,t){let n=t?0:e.length-1,o=t?1:-1,r=e[n],s=e[n+o];if(!r||!s)return;let a=s.x-r.x,l=s.y-r.y;if(!(Math.abs(a)+Math.abs(l)<at)){if(Math.abs(l)<=at){let h=r.x+Math.sign(a)*Zo;return{left:Math.min(r.x,h),right:Math.max(r.x,h),top:r.y-yn,bottom:r.y+yn}}if(Math.abs(a)<=at){let h=r.y+Math.sign(l)*Zo;return{left:r.x-yn,right:r.x+yn,top:Math.min(r.y,h),bottom:Math.max(r.y,h)}}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)}}}i(Jo,"markerClearanceRectFor");function Bs(e){return{left:Math.min(e.left,e.right),right:Math.max(e.left,e.right),top:Math.min(e.top,e.bottom),bottom:Math.max(e.top,e.bottom)}}i(Bs,"normalizeRect");function Qo(e,t){let n=xe(t),o=Jo(n,!0),r=Jo(n,!1);return[o,r].some(s=>s&&dn(e,Bs(s)))}i(Qo,"labelOverlapsOwnMarker");function bn(e,t){let n=[];for(let d of e){if(d.isLayoutOnly)continue;let m=d.points;if(!(!m||m.length<2))for(let M=0;M<m.length-1;M++)n.push({edgeId:d.id,p1:m[M],p2:m[M+1]})}let o=[],r=[],s=Ze([...t.values()]);for(let d of t.values()){let m=d.isGroup;if(s.isLane(d.id)){let I=Ve(d);I&&r.push({id:d.id,rect:I});continue}if(m||d.isEdgeLabel)continue;let M=Ve(d);M&&o.push({nodeId:d.id,rect:M})}let a=3,l=1,u=12,h=i((d,m)=>{let M=vn(m,a);for(let{nodeId:I,rect:N}of o)if(I!==d&&dn(M,N))return!0;return!1},"labelOverlapsForeignNode"),y=i((d,m)=>{let M=vn(m,a);for(let I of n)if(I.edgeId!==d&&jt(I.p1,I.p2,M))return!0;return!1},"labelOverlapsForeignEdge"),c=i((d,m,M)=>h(d,M)||y(m,M),"labelOverlapsAnything"),b=[],p=i(d=>{for(let{id:m,rect:M}of r)if(Lo(M,d))return m},"findContainingLane"),g=i((d,m)=>b.some(M=>M.labelId!==d&&dn(m,M.rect)),"overlapsPlacedLabel");for(let d of e){if(d.isLayoutOnly)continue;let m=d.labelNodeId;if(!m)continue;let M=t.get(m);if(!M)continue;let I=d.points;if(!I||I.length<2)continue;let N=M.width??0,T=M.height??0;if(N<=0||T<=0)continue;let L=[];for(let Q=0;Q<I.length-1;Q++){let de=I[Q],D=I[Q+1],Y=Math.abs(de.x-D.x),ee=Math.abs(de.y-D.y);Y<at&&ee<at||Y>=at&&ee>=at||L.push({idx:Q,length:Y+ee,orientation:Y>=at?"horizontal":"vertical",midX:(de.x+D.x)/2,midY:(de.y+D.y)/2})}if(L.length===0)continue;let x=L.length>=3?L.filter(Q=>Q.idx>0&&Q.idx<L.length-1):L,R=x.length>0?x:L,E=N>=T?"horizontal":"vertical",v=i(Q=>[...Q].sort((de,D)=>{let Y=de.orientation===E,ee=D.orientation===E;if(Y!==ee)return Y?-1:1;let q=de.length>=(de.orientation==="horizontal"?N:T)+2,re=D.length>=(D.orientation==="horizontal"?N:T)+2;return q!==re?q?-1:1:D.length-de.length}),"rankSegments"),k=L[0],O=L[L.length-1],B=[.5,.25,.75,.05,.95,.15,.85,.1,.9],j=i((Q,de)=>{let D=I[Q.idx],Y=I[Q.idx+1];return{midX:D.x+(Y.x-D.x)*de,midY:D.y+(Y.y-D.y)*de}},"anchorAtT"),X=i((Q,de,D)=>Math.min(D,Math.max(de,Q)),"clamp"),J=i((Q,de)=>Q.midX>=de.left-at&&Q.midX<=de.right+at&&Q.midY>=de.top-at&&Q.midY<=de.bottom+at,"pointInsideRectInclusive"),ie=i(Q=>{let de=zt(Q.midX,Q.midY,N,T),D=p(de);if(D)return{laneId:D,anchor:Q,rect:de};let Y=r.find(({rect:be})=>J(Q,be));if(!Y)return;let ee=Y.rect.left+N/2+l,q=Y.rect.right-N/2-l,re=Y.rect.top+T/2+l,ue=Y.rect.bottom-T/2-l;if(ee>q||re>ue)return;let me={midX:X(Q.midX,ee,q),midY:X(Q.midY,re,ue)},he=zt(me.midX,me.midY,N,T);return J(Q,he)?{laneId:Y.id,anchor:me,rect:he}:void 0},"placementForAnchor"),fe=i((Q,de,D)=>Q.orientation==="horizontal"?Math.abs(de.midX-D.x):Math.abs(de.midY-D.y),"distanceAlongSegment"),Ce=i((Q,de)=>{let Y=(Q.orientation==="horizontal"?N/2:T/2)+u;if(Q===k){let ee=I[Q.idx];if(fe(Q,de,ee)+at<Y)return!1}if(Q===O){let ee=I[Q.idx+1];if(fe(Q,de,ee)+at<Y)return!1}return!0},"labelClearsTerminalEndpoints"),nt=i(Q=>{let de=v(Q);for(let D of de)for(let Y of B){let ee=j(D,Y);if(!Ce(D,ee))continue;let q=ie(ee);if(q&&!Qo(q.rect,I)&&!g(m,q.rect)&&!c(m,d.id,q.rect))return{laneId:q.laneId,anchor:q.anchor}}},"tryPool"),$e=i((Q,de,D=!1)=>{let Y=v(Q);for(let ee of Y){let q={midX:ee.midX,midY:ee.midY};if(de&&!Ce(ee,q))continue;let re=ie(q);if(re&&!Qo(re.rect,I)&&!g(m,re.rect)&&!h(m,re.rect)&&(D||!y(d.id,re.rect)))return{laneId:re.laneId,anchor:re.anchor}}},"findLaneContainingFallback"),je=nt(R)??(R.length<L.length?nt(L):void 0)??$e(L,!0)??$e(L,!1)??$e(L,!1,!0);if(je){M.x=je.anchor.midX,M.y=je.anchor.midY,M.parentId=je.laneId;let Q=zt(je.anchor.midX,je.anchor.midY,N,T),de=b.findIndex(D=>D.labelId===m);de>=0?b[de]={labelId:m,rect:Q}:b.push({labelId:m,rect:Q})}}}i(bn,"anchorLabelsToPolyline");var Vn=1e-6,ks=8,er=ks/2,_s=3;function tr(e,t,n,{cx:o,cy:r},s,a){let l={x:o,y:r},u=a==="x"?"y":"x",h=Math.sign(s[u]-l[u]);for(let y of e){if(y===t||y.isLayoutOnly||!y.points?.length)continue;if([...y.end===n?[y.points.at(-1)]:[],...y.start===n?[y.points[0]]:[]].some(b=>Math.sign(b[u]-l[u])===h&&Math.abs(b[a]-s[a])<hn.MIN_ARROWHEAD_SPACING))return!0}return!1}i(tr,"crowdsFaceNeighbour");function nr(e,t){return e<t?`${e}::${t}`:`${t}::${e}`}i(nr,"pairKey");function or(e,t){let{nodeInfoById:n,realNodeRects:o}=Ht(t),r=new Map;for(let a of t){let l=a.id;if(!a.isGroup&&a.isEdgeLabel){r.set(l,{w:a.width??0,h:a.height??0});continue}}let s=i((a,l,u,h)=>{let y=nr(l,u),c=0,b=i(p=>{if(!p)return;let g=r.get(p);if(!g)return;let d=h==="x"?g.w/2:g.h/2;d>c&&(c=d)},"consider");b(a.labelNodeId);for(let p of e){if(p===a||p.isLayoutOnly)continue;let g=p.start,d=p.end;!g||!d||nr(g,d)===y&&b(p.labelNodeId)}return c>0?c+_s:0},"labelClearanceFor");for(let a of e){if(a.isLayoutOnly)continue;let l=a.points;if(!an(l,Vn))continue;let u=un(a,n,Vn);if(!u)continue;let{srcId:h,dstId:y,srcInfo:c,dstInfo:b,collinearX:p,collinearY:g}=u;if(p===g)continue;let d,m;if(p){let x=b.cy>c.cy;d={x:c.cx,y:x?c.rect.bottom:c.rect.top},m={x:b.cx,y:x?b.rect.top:b.rect.bottom}}else{let x=b.cx>c.cx;d={x:x?c.rect.right:c.rect.left,y:c.cy},m={x:x?b.rect.left:b.rect.right,y:b.cy}}if(Oe(d,m,o,[h,y],1))continue;let M=p?"x":"y",I=s(a,h,y,M),N=I>er?I:er,T=[0,N,-N],L;for(let x of T){let R={...d},E={...m};if(p){if(R.x+=x,E.x+=x,R.x<=c.rect.left||R.x>=c.rect.right||E.x<=b.rect.left||E.x>=b.rect.right)continue}else if(R.y+=x,E.y+=x,R.y<=c.rect.top||R.y>=c.rect.bottom||E.y<=b.rect.top||E.y>=b.rect.bottom)continue;if(Oe(R,E,o,[h,y],1)||Vt(R,E,e,a,{epsilon:Vn}))continue;let v=[R,E];if(tr(e,a,h,c,R,M)||tr(e,a,y,b,E,M)){L??=v;continue}a.points=v,L=void 0;break}L&&(a.points=L)}}i(or,"straightenCollinearSiblingDetours");function Un(e,t){let{realNodeRects:h,labelNodeRects:y}=xt(t.values()),c=i((x,R)=>bt(R,.001).map(E=>({...E,edge:x,interior:E.index>=1&&E.index<=R.length-3})),"segmentsFor"),b=i(()=>{let x=[];for(let R of e){if(R.isLayoutOnly)continue;let E=R.points;!E||E.length<2||x.push(...c(R,xe(E)))}return x},"allSegments"),p=i((x,R)=>x.horizontal&&R.horizontal?Je(x.a.x,x.b.x,R.a.x,R.b.x)>=8&&Math.abs(x.a.y-R.a.y)<7:x.vertical&&R.vertical?Je(x.a.y,x.b.y,R.a.y,R.b.y)>=8&&Math.abs(x.a.x-R.a.x)<7:!1,"hasCrowdedParallelTrack"),g=i((x,R)=>{let E=x.start,v=x.end,k=c(x,R);if(k.length!==R.length-1)return!1;let O=[E,v].filter(j=>!!j),B=x.labelNodeId?[x.labelNodeId]:[];for(let j of k)if(Oe(j.a,j.b,h,O,-2)||Oe(j.a,j.b,y,B,-2))return!1;for(let j of e){if(j===x||j.isLayoutOnly)continue;let X=j.points;if(!(!X||X.length<2)){for(let J of k)for(let ie of c(j,xe(X)))if(p(J,ie)||ht(J.a,J.b,ie.a,ie.b,.001))return!1}}return!0},"candidateIsSafe"),d=i((x,R)=>{let E=xe(x.edge.points??[]);if(E.length<4||x.index>=E.length-1)return;let v=E.map(k=>({...k}));if(x.horizontal)v[x.index].y+=R,v[x.index+1].y+=R;else if(x.vertical)v[x.index].x+=R,v[x.index+1].x+=R;else return;return c(x.edge,v).length===v.length-1?v:void 0},"shiftedCandidate"),m=i((x,R)=>({x:x.x??(R.left+R.right)/2,y:x.y??(R.top+R.bottom)/2}),"nodeCenter"),M=i(x=>{let R=x.edge,E=xe(R.points??[]);if(E.length!==4||x.index!==1)return;let v=R.start?t.get(R.start):void 0,k=R.end?t.get(R.end):void 0,O=v?Ve(v):void 0,B=k?Ve(k):void 0,j=E.slice(x.index+2);if(!(!v||!k||!O||!B||j.length===0))return{sourceCenter:m(v,O),targetCenter:m(k,B),sourceRect:O,tail:j}},"sourceDetourContextFor"),I=i((x,R,E,v,k,O)=>{let B=v.y>=E.y,j=B?k.bottom:k.top,X=j+(B?20:-20);if(B&&x.b.y<=X+.001||!B&&x.b.y>=X-.001)return;let J=x.a.x+R;return xe([{x:E.x,y:j},{x:E.x,y:X},{x:J,y:X},{x:J,y:x.b.y},...O],.001)},"verticalSourceDetour"),N=i((x,R,E,v,k,O)=>{let B=v.x>=E.x,j=B?k.right:k.left,X=j+(B?20:-20);if(B&&x.b.x<=X+.001||!B&&x.b.x>=X-.001)return;let J=x.a.y+R;return xe([{x:j,y:E.y},{x:X,y:E.y},{x:X,y:J},{x:x.b.x,y:J},...O],.001)},"horizontalSourceDetour"),T=i((x,R)=>{let E=M(x);if(E){if(x.vertical)return I(x,R,E.sourceCenter,E.targetCenter,E.sourceRect,E.tail);if(x.horizontal)return N(x,R,E.sourceCenter,E.targetCenter,E.sourceRect,E.tail)}},"sourceDetourCandidate"),L=[-7,7,-14,14,-21,21];for(let x=0;x<12;x++){let R=b(),E=!1;for(let v=0;v<R.length&&!E;v++)for(let k=v+1;k<R.length&&!E;k++){let O=R[v],B=R[k];if(O.edge===B.edge||!p(O,B))continue;let j=[O,B].filter(X=>X.interior);for(let X of j){for(let J of L){let ie=d(X,J);if(ie&&g(X.edge,ie)){X.edge.points=ie,E=!0;break}let fe=T(X,J);if(fe&&g(X.edge,fe)){X.edge.points=fe,E=!0;break}}if(E)break}}if(!E)return}}i(Un,"nudgeSharedInteriorSubpaths");function Ds(e,t,n,o){let r=t.x-e.x,s=t.y-e.y,a=o.x-n.x,l=o.y-n.y,u=r*l-s*a;if(Math.abs(u)<1e-10)return!1;let h=n.x-e.x,y=n.y-e.y,c=(h*l-y*a)/u,b=(h*s-y*r)/u,p=.01;return c>p&&c<1-p&&b>p&&b<1-p}i(Ds,"segmentsIntersect");function Wn(e){let t=e.nodes??[],n=e.edges??[],o=[];if(!n.length||!t.length)return o;let r=So(t),s=1,a=[];for(let u of n){if(u.isLayoutOnly)continue;let h=u.points;if(!h||h.length<2)continue;let y=u.start,c=u.end,b=u.labelNodeId,p=u.id??`${y}->${c}`;for(let g of r)if(!(g.nodeId===y||g.nodeId===c)&&!(b&&g.nodeId===b)){for(let d=0;d<h.length-1;d++)if(jt(h[d],h[d+1],g,-s)){o.push({type:"edge-node-overlap",edgeId:p,targetId:g.nodeId,detail:`segment ${d} passes through node "${g.nodeId}"`});break}}for(let g=0;g<h.length-1;g++)a.push({edgeId:p,start:y,end:c,p1:h[g],p2:h[g+1]})}let l=new Set;for(let u=0;u<a.length;u++)for(let h=u+1;h<a.length;h++){let y=a[u],c=a[h];if(y.edgeId!==c.edgeId&&!(y.start===c.start||y.start===c.end||y.end===c.start||y.end===c.end)&&Ds(y.p1,y.p2,c.p1,c.p2)){let b=y.edgeId<c.edgeId?`${y.edgeId}|${c.edgeId}`:`${c.edgeId}|${y.edgeId}`;l.has(b)||(l.add(b),o.push({type:"edge-edge-crossing",edgeId:y.edgeId,targetId:c.edgeId,detail:`edges "${y.edgeId}" and "${c.edgeId}" cross`}))}}if(o.length>0){let u=o.filter(y=>y.type==="edge-node-overlap").length,h=o.filter(y=>y.type==="edge-edge-crossing").length;Et.warn(`[SWIMLANE_VALIDATE] ${o.length} issue(s) detected: ${u} edge-node overlap(s), ${h} edge crossing(s)`);for(let y of o)Et.warn(`[SWIMLANE_VALIDATE]   ${y.type}: ${y.detail}`)}return o}i(Wn,"validateSwimlanesLayout");function rr(e,t){let n=e.nodes??[],o=e.edges??[],r=n.filter(l=>!l.isGroup);if((t==="LR"||t==="RL")&&r.length>0&&!zo(e,t)||t==="BT"&&r.length>0&&!Go(e))return;for(let l of o){if(l.isLayoutOnly)continue;let u=l.points;!u||u.length<2||(l.points=ut(Ut(u)))}qo(o,n),or(o,n),Ho(o,n);let s=new Map;for(let l of n)s.set(String(l.id),l);bn(o,s),ko(o,s),Xo(o,s),Un(o,s),Xn(o,s),jo(o,s),Yn(o,s),Vo(o,s);let a=i(()=>{Ko(o,s),Xn(o,s),Uo(o,s),Wo(o,s),bn(o,s),Fn(o,s),Yn(o,s),bn(o,s),Fn(o,s)},"finalizeRenderedEdges");a(),Un(o,s),a(),$n(o,s,t),jn(o,s,t),$n(o,s,t),jn(o,s,t)}i(rr,"postProcessSwimlaneLayout");function ct(e){let t=new Map(e.nodeById),n=new Set,o=[];for(let s of e.edges){if(!t.has(s.src)||!t.has(s.dst))continue;let a=`${s.id}:${s.src}->${s.dst}`;n.has(a)||(n.add(a),o.push(s))}return{nodes:[...t.keys()],edges:o,layout:e.layout,nodeById:t}}i(ct,"normalizeGraph");function xn(e,t){return e.edges.filter(n=>n.dst===t)}i(xn,"incoming");function Fs(e){let t=new Map;for(let n of e.nodes)t.set(n,[]);for(let n of e.edges)t.get(n.src).push(n.dst);return t}i(Fs,"buildSuccessorMap");function Kn(e){let t=Fs(e);for(let n of t.values())n.sort((o,r)=>o.localeCompare(r));return t}i(Kn,"buildSortedSuccessorMap");function Wt(e){let t=new Map;for(let n of e.nodes)t.set(n,0);for(let n of e.edges)t.set(n.dst,(t.get(n.dst)??0)+1);return t}i(Wt,"buildInDegreeMap");function qn(e,t){let n=[...t.entries()].filter(([,l])=>l===0).map(([l])=>l).sort((l,u)=>l.localeCompare(u)),o=new Set(e.edges.flatMap(l=>[l.src,l.dst])),r=i(l=>!o.has(l)&&!e.nodeById.get(l)?.isGroup,"isUnconnected"),s=[...t.keys()].filter(l=>t.get(l)===0&&r(l)),a=0;return n.map(l=>r(l)?s[a++]:l)}i(qn,"sortedZeroInDegreeNodes");function Xt(e,t=()=>!0){let n=new Map,o=new Map;for(let r of e.nodes)n.set(r,[]),o.set(r,[]);for(let r of e.edges)t(r)&&(o.get(r.src).push(r.dst),n.get(r.dst).push(r.src));return{preds:n,succs:o}}i(Xt,"buildPredecessorSuccessorMaps");function In(e,t,n,o){let r=0;for(let a of e.nodes)o?.skipGroups&&e.nodeById.get(a)?.isGroup||(r=Math.max(r,n[a]??0));let s=Array.from({length:r+1},()=>[]);for(let a of t)o?.skipGroups&&e.nodeById.get(a)?.isGroup||s[Math.max(0,n[a]??0)].push(a);return s}i(In,"buildLayersFromRanks");function wt(e){let t=Wt(e),n=qn(e,t),o=[],r=Kn(e);for(;n.length;){let s=n.shift();o.push(s);for(let a of r.get(s)??[])if(t.set(a,(t.get(a)??0)-1),(t.get(a)??0)===0){let l=0;for(;l<n.length&&n[l]<a;)l++;n.splice(l,0,a)}}return o.length===e.nodes.length?o:null}i(wt,"topoSortIfAcyclic");function kt(e){let t=new Map,n=0;for(let o of e)t.set(o,n),n++;return t}i(kt,"buildLayerIndex");function Mn(e){let t=new Array(e.length),n=i((o,r)=>{if(r-o<=1)return 0;let s=o+r>>1,a=n(o,s)+n(s,r),l=o,u=s,h=o;for(;l<s||u<r;)u>=r||l<s&&e[l]<=e[u]?t[h++]=e[l++]:(t[h++]=e[u++],a+=s-l);for(let y=o;y<r;y++)e[y]=t[y];return a},"count");return n(0,e.length)}i(Mn,"countInversions");function sr(e){let t=ct(e),n=new Map;for(let c of t.nodes)n.set(c,[]);for(let c of t.edges)n.get(c.src).push(c);for(let c of n.values())c.sort((b,p)=>b.dst===p.dst?b.id.localeCompare(p.id):b.dst.localeCompare(p.dst));let o=Object.create(null);for(let c of t.nodes)o[c]=0;let r=[],s=i(c=>{o[c]=1;for(let b of n.get(c)??[]){let p=b.dst;o[p]===0?s(p):o[p]===1&&r.push(b)}o[c]=2},"dfs"),a=Wt(t),l=[...t.nodes.filter(c=>(a.get(c)??0)===0),...t.nodes.filter(c=>(a.get(c)??0)!==0)];for(let c of l)o[c]===0&&s(c);let u=new Set(r.map(c=>`${c.id}:${c.src}->${c.dst}`)),h=t.edges.map(c=>u.has(`${c.id}:${c.src}->${c.dst}`)?{id:c.id,src:c.dst,dst:c.src,weight:c.weight,ref:c.ref}:c);return{acyclic:{nodes:[...t.nodes],edges:h,layout:t.layout,nodeById:new Map(t.nodeById)},reversed:r}}i(sr,"removeCycles_DFS");function Gs(e){let t=Ze(e.layout.nodes??[]),n=new Map;for(let o of e.nodes)n.set(o,t.laneIdOf(o));return n}i(Gs,"buildTopLaneMap");function Qe(e){let t=Gs(e);return n=>t.get(n)??null}i(Qe,"createTopLaneResolver");function Ln(e){let t=e.layout.nodes??[],n=Ze(t),o=t.filter(a=>n.isLane(a.id)),r=o.filter(a=>on(a)!==void 0);if(r.length>0&&r.length===o.length)return[...r].sort((a,l)=>(on(a)??0)-(on(l)??0)).map(a=>a.id);if(!n.hasPools)return[...new Set(o.map(a=>a.id))].reverse();let s=[];for(let a of t)a.parentId||(n.isPool(a.id)?s.push(...n.lanesByPool.get(a.id)??[]):n.isLane(a.id)&&s.push(a.id));return[...new Set(s)].reverse()}i(Ln,"buildTopLaneOrder");function Sn(e,t){let n=Ln(e);if(!t||t.length===0)return n;let o=new Set(n),r=new Set,s=[];for(let a of t)!o.has(a)||r.has(a)||(r.add(a),s.push(a));for(let a of n)r.has(a)||s.push(a);return s}i(Sn,"resolveTopLaneOrder");function ir(e,t){let n=ct(e),o=t?.laneOf??(()=>null),r=t?.rankHint,{preds:s}=Xt(n);for(let L of s.values())L.sort((x,R)=>x.localeCompare(R));let a=wt(n)??[...n.nodes].sort((L,x)=>L.localeCompare(x)),l=new Map;for(let[L,x]of a.entries())l.set(x,L);let u=new Map,h=new Map;for(let L of n.nodes)h.set(L,[]);for(let L of a){let x=(s.get(L)??[]).filter(R=>u.has(R));if(x.length>0){let R=zs(L,x,{laneOf:o,rankHint:r,topoIndex:l});u.set(L,R),h.get(R).push(L)}else u.has(L)||u.set(L,null)}for(let L of n.nodes)u.has(L)||u.set(L,null);let y=new Set;for(let L of n.nodes)(u.get(L)??null)===null&&y.add(L);let c=[...y].sort((L,x)=>{let R=l.get(L)??0,E=l.get(x)??0;return R===E?L.localeCompare(x):R-E}),b=Hs(n),p=new Map;for(let[L,x]of b.entries())p.set(L,[...x].sort((R,E)=>R.localeCompare(E)));let g=Xs(p),d=Ys(p),m=new Map;for(let L of n.nodes)m.set(L,[]);for(let L of d)for(let x of L.nodes){let R=m.get(x);R?R.push(L.id):m.set(x,[L.id])}let M=[],I=[],N=new Set,T=i(L=>{if(!N.has(L)){N.add(L),M.push(L);for(let x of h.get(L)??[])T(x);I.push(L)}},"walk");for(let L of c)T(L);for(let L of a)T(L);return{parent:u,children:h,roots:c,componentOf:g,blocks:d,nodeBlocks:m,adjacency:p,preorder:M,postorder:I,topologicalOrder:a}}i(ir,"buildDrivingTree");function zs(e,t,n){let o=n.laneOf(e);return[...t].sort((s,a)=>{let l=n.laneOf(s),u=n.laneOf(a),h=l!=null&&l===o,y=u!=null&&u===o;if(h!==y)return h?-1:1;let c=n.rankHint?.[s],b=n.rankHint?.[a];if(c!=null&&b!=null&&c!==b)return b-c;let p=n.topoIndex.get(s)??0,g=n.topoIndex.get(a)??0;return p!==g?p-g:s.localeCompare(a)})[0]}i(zs,"chooseParent");function Hs(e){let t=new Map;for(let n of e.nodes)t.set(n,new Set);for(let n of e.edges)t.get(n.src).add(n.dst),t.get(n.dst).add(n.src);return t}i(Hs,"buildAdjacency");function Xs(e){let t=new Map,n=0;for(let o of e.keys()){if(t.has(o))continue;let r=[o];for(;r.length>0;){let s=r.pop();if(!t.has(s)){t.set(s,n);for(let a of e.get(s)??[])t.has(a)||r.push(a)}}n++}return t}i(Xs,"assignComponents");function Ys(e){let t=new Map,n=new Map,o=[],r=[],s=0,a=i((l,u)=>{t.set(l,++s),n.set(l,s);for(let h of e.get(l)??[])h!==u&&(t.has(h)?(t.get(h)??0)<(t.get(l)??0)&&(o.push([l,h]),n.set(l,Math.min(n.get(l)??s,t.get(h)??s))):(o.push([l,h]),a(h,l),n.set(l,Math.min(n.get(l)??s,n.get(h)??s)),(n.get(h)??0)>=(t.get(l)??0)&&r.push($s(l,h,o,r.length))))},"visit");for(let l of e.keys())t.has(l)||a(l,null);return r}i(Ys,"computeBlocks");function $s(e,t,n,o){let r=[],s=new Set;for(;n.length>0;){let a=n.pop();if(r.push(a),s.add(a[0]),s.add(a[1]),a[0]===e&&a[1]===t||a[0]===t&&a[1]===e)break}return{id:o,edges:r,nodes:[...s]}}i($s,"popBlock");function ar(e,t,n){let o=[...e.nodes],r=new Map;for(let[I,N]of o.entries())r.set(N,I);let s=o.length,a=new Array(s).fill(-1),l=new Array(s).fill(0),u=[],h=new Set;for(let I of o){let N=n.parent.get(I)??null,T=r.get(I);T!=null&&N==null&&(a[T]=-1,l[T]=0,h.has(I)||(h.add(I),u.push(I)))}for(;u.length>0;){let I=u.shift(),N=r.get(I);if(N==null)continue;let T=n.children.get(I)??[];for(let L of T){if(h.has(L))continue;let x=r.get(L);x!=null&&(a[x]=N,l[x]=l[N]+1,h.add(L),u.push(L))}}for(let I of o){if(h.has(I))continue;let N=r.get(I);N!=null&&(a[N]=-1,l[N]=0,h.add(I))}let y=Math.max(1,Math.ceil(Math.log2(Math.max(1,s)))+1),c=Array.from({length:y},()=>new Array(s).fill(-1));for(let I=0;I<s;I++)c[0][I]=a[I];for(let I=1;I<y;I++)for(let N=0;N<s;N++){let T=c[I-1][N];c[I][N]=T===-1?-1:c[I-1][T]}let b=i((I,N)=>{if(I===-1||N===-1)return-1;l[I]<l[N]&&([I,N]=[N,I]);let T=l[I]-l[N];for(let L=0;L<y;L++)if(T>>L&1&&(I=c[L][I],I===-1))return-1;if(I===N)return I;for(let L=y-1;L>=0;L--){let x=c[L][I],R=c[L][N];x===-1||R===-1||x!==R&&(I=x,N=R)}return c[0][I]},"lcaIndex"),p=Array.from({length:s},()=>new Map);for(let I of e.edges){let N=I.src,T=I.dst,L=t[N],x=t[T];if(L==null||x==null||(L>x&&([N,T]=[T,N],[L,x]=[x,L]),L==null||x==null||L===x))continue;let R=r.get(N),E=r.get(T);if(R==null||E==null)continue;let v=b(R,E);if(v===-1)continue;let k=p[v];for(let O=L;O<x;O++)k.set(O,(k.get(O)??0)+1)}let g=new Map,d=i((I,N)=>{if(N.size!==0)for(let[T,L]of N)I.set(T,(I.get(T)??0)+L)},"mergeInto"),m=new Set,M=i(I=>{let N=r.get(I);m.add(I);let T=N==null?void 0:p[N],L=T?new Map(T):new Map,x=n.children.get(I)??[];for(let R of x){let E=M(R),v=t[I];if(v!=null){let k=g.get(I);k||(k=new Map,g.set(I,k));let O=E.get(v)??0,B=t[R];B!=null&&B>v&&(O+=1),k.set(R,O)}d(L,E)}return L},"dfs");for(let I of n.roots)m.has(I)||M(I);for(let I of o)m.has(I)||M(I);return g}i(ar,"computeSubtreeCrossCounts");function cr(e,t,n){let o=new Map,r=i(s=>{let a=n[s]??0,l=[...t.get(s)??[]];l.sort(Zn(n));for(let u of l){r(u);let h=o.get(u);h!=null&&(a=Math.min(a,h))}o.set(s,a)},"annotate");for(let s of e)r(s);return o}i(cr,"annotateMinimumLayers");function Zn(e){return(t,n)=>{let o=e[t]??0,r=e[n]??0;return o===r?t.localeCompare(n):o-r}}i(Zn,"compareByRankThenId");function dr(e,t,n,o){let r=0;for(let u of t){let h=n[u]??0;h>r&&(r=h)}let s=Array.from({length:r+1},()=>[]),a=new Set,l=i(u=>{if(a.has(u))return;a.add(u);let h=n[u]??0;s[h]||(s[h]=[]),s[h].push(u);for(let y of o(u))l(y)},"emit");for(let u of e)l(u);for(let u of t)if(!a.has(u)){let h=n[u]??0;s[h]||(s[h]=[]),s[h].push(u),a.add(u)}return s}i(dr,"emitNodesInTreeOrder");function lr(e){let t=[];for(let n of e){let o=new Set,r=[];for(let s of n)o.has(s)||(o.add(s),r.push(s));t.push(r)}return t}i(lr,"deduplicateLayers");function js(e,t,n,o){return r=>{let s=e.get(r)??[];if(s.length===0)return[];let a=t[r]??0,l=[],u=[],h=n.get(r);for(let y of s){let c=o.get(y)??a;c>a?l.push({child:y,min:c}):u.push(y)}return l.sort((y,c)=>y.min===c.min?y.child.localeCompare(c.child):y.min-c.min),u.sort((y,c)=>{let b=h?.get(y)??0,p=h?.get(c)??0;if(b!==p)return b-p;let g=o.get(y)??a,d=o.get(c)??a;return g!==d?g-d:y.localeCompare(c)}),[...l.map(y=>y.child),...u]}}i(js,"createChildOrderer");function Kt(e,t,n){let o=ir(e,{rankHint:t,laneOf:n}),{children:r,roots:s}=o;for(let c of e.nodes)r.has(c)||r.set(c,[]);let a=ar(e,t,o),l=[...s].sort(Zn(t)),u=cr(l,r,t),h=js(r,t,a,u),y=dr(l,e.nodes,t,h);return y=lr(y),y}i(Kt,"buildMultitreeLayerOrder");function Vs(e,t,n){let o=new Set(e),r=new Set(t),s=kt(t),a=[];for(let l of n)o.has(l.src)&&r.has(l.dst)&&a.push(s.get(l.dst));return Mn(a)}i(Vs,"countCrossingsBetweenAdjacent");function fr(e,t,n){let o=[];for(let s of t){let a=n[s.src],l=n[s.dst];if(a==null||l==null||a===l)continue;let u=s.src,h=s.dst,y=a,c=l;a>l&&(u=s.dst,h=s.src,y=l,c=a);for(let b=y;b<c;b++)o.push({id:`${s.id}@${b}`,src:u,dst:h,ref:s.ref})}let r=0;for(let s=0;s+1<e.length;s++)r+=Vs(e[s],e[s+1],o);return r}i(fr,"totalCrossings");function ur(e,t){let n={...t},{preds:o}=Xt(e),r=Qe(e),s=Kt(e,n,r),a=fr(s,e.edges,n),l=Bt.MAX_CROSSING_OPTIMIZATION_PASSES;for(let u=0;u<l;u++){let h=!1,y=[...e.nodes].sort((c,b)=>(n[b]??0)-(n[c]??0));for(let c of y){let b=n[c]??0;if(b===0)continue;let p=0;for(let M of o.get(c)??[])p=Math.max(p,(n[M]??0)+1);if(p>=b)continue;let g=b;n[c]=p;let d=Kt(e,n,r),m=fr(d,e.edges,n);m<a?(a=m,h=!0):n[c]=g}if(!h)break}return n}i(ur,"optimizeRanksByCrossings");function gr(e,t){let n=Qe(e),o=[...e.nodes].sort((r,s)=>(t[r]??0)-(t[s]??0)||r.localeCompare(s));for(let r of o){let s=n(r);if(!s)continue;let a=e.edges.filter(d=>d.src===r);if(a.length===0)continue;let l=!1,u=0;for(let d of a){let m=n(d.dst);m==null||m===s?l=!0:u++}if(u===0||l)continue;let h=0,y=!1;for(let d of e.edges){if(d.dst!==r)continue;let m=n(d.src);m&&(m===s?y=!0:h++)}if(h>0||!y)continue;let c=t[r]??0,b=c+u,p=0;for(let d of e.edges)d.dst===r&&(p=Math.max(p,(t[d.src]??0)+1));let g=Math.max(c,p,b);g!==c&&(t[r]=g)}}i(gr,"adjustCrossLaneSources");function mr(e,t){let n=ct(e),o=wt(n)??[...n.nodes].sort(),r=t?.compactSingleInput??!1,s=Qe(n),a=Object.create(null);for(let u of o){let h=xn(n,u),y=t?.ignoreCrossLaneEdges?h.filter(c=>{let b=s(c.src),p=s(u);return!b||!p?!0:b===p}):h;if(y.length===0)a[u]=0;else if(r&&y.length===1){let c=y[0].src,b=s(c),p=s(u);b!==p?a[u]=a[c]??0:a[u]=(a[c]??0)+1}else{let c=-1/0;for(let b of y)c=Math.max(c,(a[b.src]??0)+1);a[u]=c===-1/0?0:c}}return(t?.optimizeRanksByCrossings??!1)&&(a=ur(n,a)),t?.ignoreCrossLaneEdges&&gr(n,a),{layers:Kt(n,a,s),rankOf:a,dummy:new Set}}i(mr,"assignLayers_LongestPath");function hr(e,t){let n=ct(e),r={...mr(n,{compactSingleInput:t?.compactSingleInput,ignoreCrossLaneEdges:t?.ignoreCrossLaneEdges,optimizeRanksByCrossings:t?.optimizeRanksByCrossings}).rankOf},s=Qe(n),{preds:a,succs:l}=Xt(n,g=>{if(t?.ignoreCrossLaneEdges){let d=s(g.src),m=s(g.dst);if(d&&m&&d!==m)return!1}return!0}),u=wt(n)??[...n.nodes],h=[...u].reverse(),y=i((g,d)=>{let m=0;for(let N of a.get(g)??[])m=Math.max(m,(r[N]??0)+1);let M=Number.POSITIVE_INFINITY,I=l.get(g)??[];return I.length>0&&(M=Math.min(...I.map(N=>(r[N]??0)-1))),Number.isFinite(M)||(M=Math.max(m,d)),Math.min(Math.max(d,m),M)},"clampFeasible"),c=Bt.GRAVITY_ITERATIONS,b=i(g=>{let d=!1;for(let m of g){let M=a.get(m)??[],I=l.get(m)??[];if(M.length===0&&I.length===0)continue;let N=M.length>0?M.reduce((R,E)=>R+(r[E]??0)+1,0)/M.length:r[m]??0,T=I.length>0?I.reduce((R,E)=>R+(r[E]??0)-1,0)/I.length:r[m]??0,L=Math.round((N+T)/2),x=y(m,L);x!==r[m]&&(r[m]=x,d=!0)}return d},"relaxOrder");for(let g=0;g<c;g++){let d=b(u),m=b(h);if(!d&&!m)break}for(let g of u){let d=0;for(let m of a.get(g)??[])d=Math.max(d,(r[m]??0)+1);(r[g]??0)<d&&(r[g]=d)}for(let g of h){let d=l.get(g)??[];if(d.length>0){let m=Math.min(...d.map(M=>(r[M]??0)-1));(r[g]??0)>m&&(r[g]=m)}}return{layers:In(n,u,r),rankOf:r,dummy:new Set}}i(hr,"assignLayers_Gravity");function Us(e){let t=Wt(e),n=Kn(e),o=qn(e,t),r=[];for(;o.length>0;){let s=[];for(let a of o){r.push(a);for(let l of n.get(a)??[])t.set(l,(t.get(l)??0)-1),(t.get(l)??0)===0&&s.push(l)}o=s.sort((a,l)=>a.localeCompare(l))}return r.length===e.nodes.length?r:null}i(Us,"topoSortByGenerationIfAcyclic");function pr(e,t){let n=ct(e),o=t?.direction==="LR"?Us(n)??[...n.nodes].sort():wt(n)??[...n.nodes].sort(),r=Qe(n),s=i(y=>r(y)??y,"laneOf"),a=Object.create(null),l=new Map,u=i((y,c)=>t?.ignoreCrossLaneEdges??!0?s(y)===s(c)?1:0:1,"edgeWeight");for(let y of o){if(n.nodeById.get(y)?.isGroup)continue;let b=xn(n,y),p=0;if(b.length>0)for(let M of b){let I=M.src,N=a[I]??0;p=Math.max(p,N+u(I,y))}let g=s(y),d=l.get(g)??0,m=Math.max(p,d);a[y]=m,l.set(g,m+1)}return{layers:In(n,o,a,{skipGroups:!0}),rankOf:a,dummy:new Set}}i(pr,"assignLayers_LaneAwareCompact");function yr(e,t){let n=ct(t),{rankOf:o}=e,r=e.layers.map(p=>[...p]),s=new Set(e.dummy?[...e.dummy]:[]),a=0,l=new Map(n.nodeById),u=i(p=>{let g=`placeholder-${a++}`,d={id:g,isGroup:!1,isDummy:!0,width:0,height:0};for(l.set(g,d),s.add(g);r.length<=p;)r.push([]);return r[p].push(g),o[g]=p,g},"addDummyAt"),h=[...n.edges].sort((p,g)=>p.id===g.id?p.src===g.src?p.dst.localeCompare(g.dst):p.src.localeCompare(g.src):p.id.localeCompare(g.id)),y=[];for(let p of h){let g=o[p.src]??0,d=o[p.dst]??0;if(d-g<=1){y.push(p);continue}let m=p.src;for(let I=g+1,N=0;I<d;I++,N++){let T=u(I);y.push({id:`${p.id}#${N}`,src:m,dst:T,weight:p.weight,ref:p.ref}),m=T}let M=d-g-2;y.push({id:`${p.id}#${Math.max(M+1,0)}`,src:m,dst:p.dst,weight:p.weight,ref:p.ref})}let b={nodes:[...n.nodes,...[...s].filter(p=>!n.nodes.includes(p))],edges:y,layout:n.layout,nodeById:l};return{layering:{layers:r,rankOf:o,dummy:s},graphWithDummies:b}}i(yr,"makeProperLayering");function br(e){let t=e.length;if(t===0)return Number.POSITIVE_INFINITY;let n=[...e].sort((o,r)=>o-r);return t%2===1?n[(t-1)/2]:.5*(n[t/2-1]+n[t/2])}i(br,"median");function xr(e){return e.length===0?Number.POSITIVE_INFINITY:e.reduce((n,o)=>n+o,0)/e.length}i(xr,"barycenter");function Ws(e,t,n,o){let r=new Map;for(let s of e)r.set(s,[]);for(let s of n)o==="down"?t.has(s.src)&&r.has(s.dst)&&r.get(s.dst).push(t.get(s.src)):t.has(s.dst)&&r.has(s.src)&&r.get(s.src).push(t.get(s.dst));return r}i(Ws,"neighborPositionsFor");function Ks(e,t,n){let o=n.get(e)??0,r=n.get(t)??0;return o!==r?o-r:e.localeCompare(t)}i(Ks,"currentOrderTieBreak");function Ir(e,t,n){let o=new Set(e),r=new Set(t),s=kt(e),a=kt(t),l=[];for(let h of n)o.has(h.src)&&r.has(h.dst)&&l.push({u:s.get(h.src),v:a.get(h.dst)});l.sort((h,y)=>h.u===y.u?h.v-y.v:h.u-y.u);let u=l.map(h=>h.v);return Mn(u)}i(Ir,"countCrossingsBetweenAdjacent");function Jn(e,t,n){return[...e].sort((o,r)=>{let s=br(t.get(o)??[]),a=br(t.get(r)??[]);return s===a?Ks(o,r,n):isFinite(s)?isFinite(a)?s-a:-1:1})}i(Jn,"sortByHeuristic");function Mr(e,t,n,o,r,s){let a=kt(e),l=kt(t),u=Ws(t,a,n,o);if(!r||!s||s.length===0)return Jn(t,u,l);let h=new Map;for(let b of t){let p=r(b),g=h.get(p)??[];g.push(b),h.set(p,g)}let y=[];for(let b of s){let p=h.get(b);if(!p||p.length===0)continue;let g=Jn(p,u,l);y.push(...g)}let c=h.get(null);if(c&&c.length>0){let b=Jn(c,u,l);for(let p of b){let g=xr(u.get(p)??[]),d=y.length;if(isFinite(g))for(let[m,M]of y.entries()){let I=xr(u.get(M)??[]);if(g<I){d=m;break}}y.splice(d,0,p)}}return y}i(Mr,"reorderLayer");function Lr(e,t,n,o,r){let s=[...t],a=new Set(e),l=new Set(t),u=o?new Set(o):null,h=n.filter(d=>a.has(d.src)&&l.has(d.dst)),y=u?n.filter(d=>l.has(d.src)&&u.has(d.dst)):void 0,c=i(d=>{let m=Ir(e,d,h);return y&&o&&(m+=Ir(d,o,y)),m},"crossingScore"),b=r?new Map:null;if(r&&b)for(let d of t)b.set(d,r(d));let p=!0,g=c(s);for(;p;){p=!1;for(let d=0;d+1<s.length;d++){if(b){let I=b.get(s[d]),N=b.get(s[d+1]);if(I!==N)continue}let m=g;[s[d],s[d+1]]=[s[d+1],s[d]];let M=c(s);M<m?(g=M,p=!0):[s[d],s[d+1]]=[s[d+1],s[d]]}}return s}i(Lr,"transposeImprove");function Sr(e,t,n){let o=e.layers.map(l=>[...l]),r=t.edges,s=Qe(t),a=Sn(t,n?.laneOrder);for(let l=0;l<3;l++){for(let u=1;u<o.length;u++)o[u]=Mr(o[u-1],o[u],r,"down",s,a),o[u]=Lr(o[u-1],o[u],r,o[u+1],s);for(let u=o.length-2;u>=0;u--)o[u]=Mr(o[u+1],o[u],r,"up",s,a),o[u]=Lr(o[u+1],o[u],r,o[u-1],s)}return{layers:o}}i(Sr,"orderLayers");function Nr(e,t,n){let o=n?.layerGap??pn.DEFAULT_LAYER_GAP,r=n?.nodeGap??pn.DEFAULT_NODE_GAP,s=n?.laneGap??r*2,a=n?.direction??"TB",l=a==="LR"||a==="RL",u=Object.create(null),h=Object.create(null),y=new Map((t.layout?.nodes??[]).filter(D=>D.isEdgeLabel).map(D=>[D.id,D])),c=i(D=>y.get(D)??t.nodeById.get(D),"getNode"),b=i(D=>c(D)?.width??0,"getWidth"),p=i(D=>c(D)?.height??0,"getHeight"),g=Qe(t),d=new Map,m=i(D=>d.has(D)?d.get(D)??null:g(D),"topLaneOf"),M=Sn(t,n?.laneOrder),I=new Set;for(let D of e.layers)for(let Y of D)I.add(g(Y));let N=I.has(null),T=M.filter(D=>I.has(D)),L=[...N?[null]:[],...T],x=e.layers,R=new Map;for(let[D,Y]of x.entries())for(let ee of Y)R.set(ee,D);let E=[],v=[],k=[];for(let D of t.layout?.edges??[]){let Y=D.labelNodeId,ee=D.start,q=D.end;if(!Y||!y.has(Y)||ee==null||q==null)continue;let re=R.get(ee),ue=R.get(q);if(re==null||ue==null){k.push({labelId:Y,near:re==null?q:ee});continue}if(d.set(Y,g(q)),re===ue){let be=i(ke=>L.indexOf(g(ke)),"column");E.push({labelId:Y,rank:ue,lane:g(q),side:ee!==q&&be(ee)<be(q)?"before":"after"});continue}let me=Math.min(re,ue),he=Math.max(re,ue);v.push({labelId:Y,start:ee,end:q,gap:me+Math.floor((he-me-1)/2),crossesLanes:g(ee)!==g(q)})}let O=x.map(D=>D.reduce((Y,ee)=>Math.max(Y,p(ee)),0));for(let{labelId:D,rank:Y}of E)O[Y]=Math.max(O[Y],p(D));let B=x.map(()=>0);if(l)for(let D=0;D+1<x.length;D++){let Y=x[D].reduce((he,be)=>Math.max(he,b(be)),0),ee=x[D+1].reduce((he,be)=>Math.max(he,b(be)),0),q=O[D],re=O[D+1],ue=q/2+re/2,me=(Y+ee)/2;B[D]=Math.max(0,me-ue-o)}let j=l?zn(t.layout?.nodes??[]):1,X=x.map(()=>0);for(let{labelId:D,gap:Y}of v){let q=((l?b(D):p(D))+2*pn.EDGE_LABEL_CLEARANCE)/j;X[Y]=Math.max(X[Y],q)}for(let[D,Y]of X.entries())B[D]+=Y;let J=Object.create(null);for(let D of T)J[D]=0;N&&(J.null=0);for(let D of x){let Y=Object.create(null),ee=[];for(let q of D){let re=m(q);re===null?ee.push(q):(Y[re]||=[]).push(q)}for(let[q,re]of Object.entries(Y)){let ue=re.reduce((me,he)=>me+b(he),0)+r*Math.max(0,re.length-1);J[q]=Math.max(J[q]??0,ue)}if(N&&ee.length){let q=ee.reduce((re,ue)=>re+b(ue),0)+r*Math.max(0,ee.length-1);J.null=Math.max(J.null??0,q)}}let ie=new Map;for(let D of v){let Y=`${D.gap}:${m(D.labelId)}`,ee=ie.get(Y);ee?ee.push(D):ie.set(Y,[D])}for(let D of ie.values()){let Y=m(D[0].labelId);if(Y!==null){let ee=D.reduce((q,re,ue)=>q+b(re.labelId)+(ue>0?r:0),0);J[Y]=Math.max(J[Y]??0,ee)}}let fe=new Map;for(let{labelId:D,rank:Y,lane:ee,side:q}of E){let re=`${Y}:${ee}:${q}`;fe.set(re,(fe.get(re)??0)+r+b(D))}let Ce=i((D,Y,ee)=>fe.get(`${D}:${Y}:${ee}`)??0,"rowLabelSpan");for(let{rank:D,lane:Y}of E){let ee=x[D].filter(ue=>m(ue)===Y).reduce((ue,me,he)=>ue+b(me)+(he>0?r:0),0),q=Math.max(Ce(D,Y,"before"),Ce(D,Y,"after")),re=Y??"null";J[re]=Math.max(J[re]??0,ee+2*q)}let nt=new Map;{let D=L.map(q=>(q===null?J.null:J[q])??0),ee=-(D.reduce((q,re)=>q+re,0)+s*Math.max(0,L.length-1))/2;for(let q=0;q<L.length;q++){let re=L[q],ue=D[q]??0,me=ee+ue/2;nt.set(re,me),ee+=ue,q<L.length-1&&(ee+=s)}}let $e=[],je=0;for(let[D,Y]of x.entries()){let ee=O[D]??0,q=new Map;for(let ue of Y){let me=m(ue),he=q.get(me)??[];he.push(ue),q.set(me,he)}for(let ue of L){let me=q.get(ue)??[];if(me.length===0)continue;let he=nt.get(ue);if(me.length===1){let be=me[0];u[be]=he,h[be]=je+ee/2}else{let be=me.map(It=>b(It)),ke=be.reduce((It,Mt)=>It+Mt,0)+r*(me.length-1),At=he-ke/2;for(let[It,Mt]of me.entries()){let Tt=be[It];u[Mt]=At+Tt/2,h[Mt]=je+ee/2,At+=Tt+r}}}let re=o+(B[D]??0);$e[D]=je+ee+re/2,je+=ee+re}let Q=new Map;for(let{labelId:D,rank:Y,lane:ee,side:q}of E){let re=`${Y}:${ee}:${q}`;if(!Q.has(re)){let be=x[Y].filter(ke=>m(ke)===ee).map(ke=>q==="before"?u[ke]-b(ke)/2:u[ke]+b(ke)/2);Q.set(re,q==="before"?Math.min(...be):Math.max(...be))}let ue=b(D),me=Q.get(re)+(q==="before"?-1:1)*(r+ue/2);u[D]=me,h[D]=h[x[Y].find(he=>m(he)===ee)],Q.set(re,me+(q==="before"?-1:1)*(ue/2))}for(let D of ie.values()){let Y=D.map(({start:he,end:be,crossesLanes:ke})=>ke?u[be]:((u[he]??0)+(u[be]??0))/2),ee=D.map((he,be)=>be).sort((he,be)=>Y[he]-Y[be]||he-be),q=[],re=-1/0;for(let he of ee){let be=b(D[he].labelId);q[he]=Math.max(Y[he],re+r+be/2),re=q[he]+be/2}let ue=i(he=>he.reduce((be,ke)=>be+ke,0)/he.length,"mean"),me=ue(Y)-ue(q);for(let[he,{labelId:be,gap:ke}]of D.entries())u[be]=q[he]+me,h[be]=$e[ke]}for(let{labelId:D,near:Y}of k)u[D]=u[Y]??0,h[D]=h[Y]??0;let de=new Map;for(let D of t.edges){let Y=D.ref.id;de.has(Y)||de.set(Y,[]),de.get(Y).push(D)}for(let[,D]of de){if(D.length===0)continue;let Y=D[0].ref,ee=Y.start,q=Y.end;if(ee==null||q==null)continue;let re=Math.round(((u[ee]??0)+(u[q]??0))/2),ue=new Set;for(let me of D)ue.add(me.src),ue.add(me.dst);for(let me of ue){if(me===ee||me===q)continue;t.nodeById.get(me)?.isDummy&&(u[me]=re)}}return{x:u,y:h}}i(Nr,"assignCoordinates");var Qn=8;function qs(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}i(qs,"hashString");function Zs(e){let t=e>>>0;return()=>{t+=1831565813;let n=t;return n=Math.imul(n^n>>>15,n|1),n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296}}i(Zs,"mulberry32");function Js(e,t){let n=[...e],o=Zs(t);for(let r=n.length-1;r>0;r--){let s=Math.floor(o()*(r+1));[n[r],n[s]]=[n[s],n[r]]}return n}i(Js,"deterministicShuffle");function Qs(e,t){let n=0;for(let[o,r]of e.entries())n+=Math.abs(o-(t.get(r)??o));return n}i(Qs,"sourceDistance");function Rr(e,t){let n=new Map;for(let[r,s]of e.entries())n.set(s,r);let o=0;for(let{a:r,b:s,weight:a}of t){let l=n.get(r),u=n.get(s);l==null||u==null||(o+=a*Math.abs(l-u))}return o}i(Rr,"laneArrangementCost");function ei(e){let t=Ln(e);if(t.length<2)return[];let n=new Map(t.map((s,a)=>[s,a])),o=Qe(e),r=new Map;for(let s of e.layout.edges??[]){if(s.isLayoutOnly)continue;let a=typeof s.start=="string"?s.start:void 0,l=typeof s.end=="string"?s.end:void 0;if(!a||!l||!e.nodeById.has(a)||!e.nodeById.has(l))continue;let u=o(a),h=o(l);if(!u||!h||u===h)continue;let y=n.get(u),c=n.get(h);if(y==null||c==null)continue;let[b,p]=y<=c?[u,h]:[h,u],g=`${b}\0${p}`,d=r.get(g);d?d.weight++:r.set(g,{a:b,b:p,weight:1})}return[...r.values()]}i(ei,"buildWeightedLaneEdges");function Er(e,t,n){let o=[...e],r=Rr(o,t),s=!0,a=0,l=Math.max(1,o.length);for(;s&&a<l;){s=!1,a++;for(let u=0;u+1<o.length;u++){[o[u],o[u+1]]=[o[u+1],o[u]];let h=Rr(o,t);h<r?(r=h,s=!0):[o[u],o[u+1]]=[o[u+1],o[u]]}}return{order:o,cost:r,sourceDistance:Qs(o,n)}}i(Er,"greedySwitch");function ti(e,t){return e.cost!==t.cost?e.cost<t.cost:e.sourceDistance<t.sourceDistance}i(ti,"isBetterCandidate");function ni(e,t,n){let o=[...t].sort((r,s)=>r.a===s.a?r.b.localeCompare(s.b):r.a.localeCompare(s.a)).map(({a:r,b:s,weight:a})=>`${r}:${s}:${a}`).join("|");return qs(`${e.join("|")}#${o}#${n}`)}i(ni,"seedForRestart");function Pr(e,t={}){let n=Ln(e);if(n.length<2)return n;let o=ei(e);if(o.length===0)return n;let r=new Map(n.map((l,u)=>[l,u])),s=Er(n,o,r),a=Math.max(0,t.restarts??Qn);for(let l=0;l<a;l++){let u=ni(n,o,l),h=Js(n,u),y=Er(h,o,r);ti(y,s)&&(s=y)}return s.order}i(Pr,"optimizeTopLaneOrder");function Cr(e,t){let n=t?.ignoreCrossLaneEdges??!0,o=t?.optimizeRanksByCrossings??!0,r=ct(e),s=t?.automaticLaneOrdering?Pr(r,{restarts:Qn}):void 0,a=sr(r),l=a.acyclic,u=n?pr(l,{compactSingleInput:t?.compactSingleInput??Bt.DEFAULT_COMPACT_SINGLE_INPUT,ignoreCrossLaneEdges:!0,direction:t?.direction}):hr(l,{compactSingleInput:t?.compactSingleInput??Bt.DEFAULT_COMPACT_SINGLE_INPUT,ignoreCrossLaneEdges:!1,optimizeRanksByCrossings:o}),{layering:h,graphWithDummies:y}=yr(u,l),c=Sr(h,y,{laneOrder:s}),b=Nr(c,y,{layerGap:t?.layerGap,nodeGap:t?.nodeGap,direction:t?.direction,laneOrder:s});return{acyclic:l,reversed:a.reversed,layering:h,ordered:c,coordinates:b}}i(Cr,"sugiyamaLayout");var ye=Yo.EPSILON,oi=8,_t=15,Yt=15,Nn=25,gt=20,eo=10;function wr(e,t,n){let o=e.x??0,r=e.y??0,s=t.x-o,a=t.y-r,l=Math.abs(s),u=Math.abs(a);return l<ye&&u<ye?n:u>ye&&u*3>=l?a>0?"bottom":"top":l>ye?s>0?"right":"left":n}i(wr,"chooseOrthogonalSide");var Ar=i(e=>typeof e=="number"&&Number.isFinite(e)&&e>0,"isDrawableSize");function to(e,t){let n=e.metadata?.drawnExtent;return{w:Ar(n?.width)?n.width:e.width??t,h:Ar(n?.height)?n.height:e.height??t}}i(to,"drawnSize");function Tr(e,t){return Math.abs(e.to-t.from)<ye||Math.abs(e.to-t.to)<ye?e.to:e.from}i(Tr,"sharedLineEndpointCoord");function $t(e,t){return e.orient==="vertical"?{x:e.coord,y:t}:{x:t,y:e.coord}}i($t,"pointOnLine");function Or(e,t){let n=e.nodes??[],o=e.edges??[],r=[];for(let f of o)f.isLayoutOnly||r.push({...f,__originalEdge:f});let s=new Map,a=new Map,l=[],u=t==="LR";for(let f of n)s.set(f.id,f);let h=Ze(n),y=n.filter(f=>h.isLane(f.id));for(let f of y){let S={id:f.id},P=i(C=>{a.set(C.id,S),n.filter(w=>w.parentId===C.id).forEach(P)},"assignLane");P(f)}let c=vt(n),b=n.filter(f=>!f.isGroup&&!f.isEdgeLabel&&!c.has(f.id)).map(f=>{let S=f.width??10,P=f.height??10,C=f.x??0,w=f.y??0,F=oi;return{nodeId:f.id,minX:C-S/2-F,maxX:C+S/2+F,minY:w-P/2-F,maxY:w+P/2+F,visualXHalfExtent:u?P/2+F:S/2+F}}),p=i((f,S,P,C)=>{let w=l.find(F=>F.orientation===f&&Math.abs(F.coord-S)<1);return w||(w={id:`pipe-${f}-${S.toFixed(0)}`,orientation:f,coord:S,spanMin:P,spanMax:C,tracks:[]},l.push(w)),w.spanMin=Math.min(w.spanMin,P),w.spanMax=Math.max(w.spanMax,C),w},"getOrAddPipe"),g=i((f,S)=>{let{w:P,h:C}=to(f,10),w=f.x??0,F=f.y??0;switch(S){case"top":return{x:w,y:F-C/2};case"bottom":return{x:w,y:F+C/2};case"left":return{x:w-P/2,y:F};case"right":return{x:w+P/2,y:F}}},"portForSide"),d=i((f,S,P)=>g(f,wr(f,S,P?"bottom":"top")),"getOrthogonalPort"),m=[],M=[],I=new Set,N=1e3,T=i((f,S,P)=>{if(m.length===0)return 0;let C=Math.abs(S.y-P.y)<ye,w=Math.abs(S.x-P.x)<ye;if(!C&&!w)return 0;let F=0;if(C){let Z=S.y,ce=Math.min(S.x,P.x)-ye,W=Math.max(S.x,P.x)+ye;if(W<=ce)return 0;for(let V of m)V.edgeIndex===f||V.orientation!=="vertical"||V.pipe.coord<ce||V.pipe.coord>W||V.from-ye<=Z&&V.to+ye>=Z&&(F+=N)}else if(w){let Z=S.x,ce=Math.min(S.y,P.y)-ye,W=Math.max(S.y,P.y)+ye;if(W<=ce)return 0;for(let V of m)V.edgeIndex===f||V.orientation!=="horizontal"||V.pipe.coord<ce||V.pipe.coord>W||V.from-ye<=Z&&V.to+ye>=Z&&(F+=N)}return F},"crossingPenalty"),L=r.map((f,S)=>{if(!f.start||!f.end)return{idx:S,crossLane:0,dx:0,dy:0};let P=s.get(f.start),C=s.get(f.end),w=a.get(f.start),F=a.get(f.end),Z=w&&F&&w.id!==F.id?1:0,ce=P&&C?Math.abs((C.x??0)-(P.x??0)):0,W=P&&C?Math.abs((C.y??0)-(P.y??0)):0;return{idx:S,crossLane:Z,dx:ce,dy:W}}).sort((f,S)=>{if(f.crossLane!==S.crossLane)return S.crossLane-f.crossLane;let P=f.dx+f.dy,C=S.dx+S.dy;return Math.abs(P-C)>1?P-C:f.idx-S.idx}).map(f=>f.idx),x=i((f,S,P,C)=>{let w=Math.min(f.x,S.x),F=Math.max(f.x,S.x),Z=Math.min(f.y,S.y),ce=Math.max(f.y,S.y);return!!b.find(V=>P&&V.nodeId===P||C&&V.nodeId===C?!1:Math.abs(f.x-S.x)>ye?V.minY<f.y&&V.maxY>f.y&&V.maxX>w&&V.minX<F:V.minX<f.x&&V.maxX>f.x&&V.maxY>Z&&V.minY<ce)},"isSegmentBlocked"),R=new Map,E=new Map;for(let f of r)!f.start||!f.end||f.start===f.end||(E.set(f.start,(E.get(f.start)??0)+1),E.set(f.end,(E.get(f.end)??0)+1));let v=i((f,S)=>wr(f,S,"bottom"),"determineSide"),k=new Map;for(let[f,S]of r.entries()){if(!S.start||!S.end||S.start===S.end||S.points&&S.points.length>0)continue;let P=s.get(S.start),C=s.get(S.end);if(!P||!C)continue;let w=(C.x??0)-(P.x??0),F=(C.y??0)-(P.y??0);k.set(f,{edgeIdx:f,srcId:S.start,dstId:S.end,srcSide:v(P,{x:C.x??0,y:C.y??0}),dstSide:v(C,{x:P.x??0,y:P.y??0}),absDx:Math.abs(w),absDy:Math.abs(F),dxSign:Math.sign(w),dySign:Math.sign(F)})}let O=i(f=>f.srcSide==="top"||f.srcSide==="bottom"?f.absDx===0?1/0:f.absDy/f.absDx:f.absDy===0?1/0:f.absDx/f.absDy,"preferenceStrength"),B=i(f=>f.srcSide==="top"||f.srcSide==="bottom"?f.dxSign===0?["right","left"]:[f.dxSign>0?"right":"left"]:f.dySign===0?["bottom","top"]:[f.dySign>0?"bottom":"top"],"secondarySides"),j=i(f=>B(f)[0],"secondarySide"),X=new Map;for(let f of k.values()){let S=`${f.srcId}:${f.srcSide}`;X.has(S)||X.set(S,[]),X.get(S).push(f)}let J=new Map,ie=i((f,S)=>`${f}:${S}`,"loadKey");for(let f of k.values())J.set(ie(f.srcId,f.srcSide),(J.get(ie(f.srcId,f.srcSide))??0)+1),J.set(ie(f.dstId,f.dstSide),(J.get(ie(f.dstId,f.dstSide))??0)+1);for(let f of X.values())if(!(f.length<2)){f.sort((S,P)=>{let C=O(S),w=O(P);return Math.abs(C-w)>1e-9?w-C:S.edgeIdx-P.edgeIdx});for(let S=1;S<f.length;S++){let P=f[S],C=J.get(ie(P.srcId,P.srcSide))??0,w=B(P).reduce((Z,ce)=>(J.get(ie(P.srcId,ce))??0)<(J.get(ie(P.srcId,Z))??0)?ce:Z),F=J.get(ie(P.srcId,w))??0;F>=C||(J.set(ie(P.srcId,P.srcSide),C-1),J.set(ie(P.srcId,w),F+1),P.srcSide=w)}}let fe=i(f=>{let S=f?.shape;return S==="question"||S==="diamond"},"isDiamondNode"),Ce=new Map;for(let f of k.values())Ce.has(f.dstId)||Ce.set(f.dstId,new Set),Ce.get(f.dstId).add(f.dstSide);for(let f of k.values()){if(!fe(s.get(f.srcId)))continue;let S=Ce.get(f.srcId);if(!S?.has(f.srcSide))continue;let P=j(f);if(S.has(P)||(J.get(ie(f.srcId,P))??0)>0)continue;let C=J.get(ie(f.srcId,f.srcSide))??0;J.set(ie(f.srcId,f.srcSide),Math.max(0,C-1)),J.set(ie(f.srcId,P),1),f.srcSide=P}let nt=i(f=>{let S=f?.shape;return S==="hexagon"||S==="notch-pent"},"hasVertexFaces"),$e=new Map;for(let f of k.values())$e.has(f.srcId)||$e.set(f.srcId,new Set),$e.get(f.srcId).add(f.srcSide);let je=i(f=>f.dstSide==="top"||f.dstSide==="bottom"?f.dxSign>=0?"left":"right":f.dySign>=0?"top":"bottom","secondaryDstSide");for(let f of k.values()){if(!nt(s.get(f.dstId)))continue;let S=$e.get(f.dstId);if(!S?.has(f.dstSide))continue;let P=je(f);if(S.has(P)||(J.get(ie(f.dstId,P))??0)>0)continue;let C=J.get(ie(f.dstId,f.dstSide))??0;J.set(ie(f.dstId,f.dstSide),Math.max(0,C-1)),J.set(ie(f.dstId,P),1),f.dstSide=P;let w=f.dySign>=0?"bottom":"top";if((P==="top"||P==="bottom")&&Ce.get(f.srcId)?.has(f.srcSide)&&!Ce.get(f.srcId)?.has(w)&&(J.get(ie(f.srcId,w))??0)===0){let F=J.get(ie(f.srcId,f.srcSide))??0;J.set(ie(f.srcId,f.srcSide),Math.max(0,F-1)),J.set(ie(f.srcId,w),1),f.srcSide=w}}for(let f of k.values()){let{edgeIdx:S,srcId:P,dstId:C,srcSide:w,dstSide:F}=f,Z=s.get(P),ce=s.get(C),W=`${P}:${w}:src`,V=w==="top"||w==="bottom"?ce.x??0:ce.y??0;R.has(W)||R.set(W,[]),R.get(W).push({edgeIdx:S,oppositeCoord:V});let Re=`${C}:${F}:dst`,Ee=F==="top"||F==="bottom"?Z.x??0:Z.y??0;R.has(Re)||R.set(Re,[]),R.get(Re).push({edgeIdx:S,oppositeCoord:Ee})}let Q=new Map,de=8;for(let[f,S]of R){if(S.length<2)continue;S.sort((ze,dt)=>ze.oppositeCoord-dt.oppositeCoord);let P=f.split(":"),C=P.slice(0,-2).join(":"),w=P[P.length-2],F=P[P.length-1],Z=s.get(C);if(!Z)continue;let ce=w==="left"||w==="right",W=to(Z,10),V=ce?W.h:W.w,Re=Z.shape,we=Re==="question"||Re==="diamond"?V*.3:V,Me=Math.min(20,we/(S.length-1),Math.max(de,we/(S.length+1))),ot=-(Me*(S.length-1))/2;for(let[ze,dt]of S.entries()){let Lt=ot+ze*Me,Rn=`${dt.edgeIdx}:${F}`;Q.set(Rn,Lt)}}let D=i(f=>!!r[f]?.labelNodeId,"edgeHasLabelNode"),Y=i((f,S)=>f?(R.get(`${f}:${S}:src`)??[]).some(({edgeIdx:P})=>D(P))||(R.get(`${f}:${S}:dst`)??[]).some(({edgeIdx:P})=>D(P)):!1,"faceHasLabelNode"),ee=i((f,S,P)=>S==="top"||S==="bottom"?{x:f.x+P,y:f.y}:{x:f.x,y:f.y+P},"applyPortOffset"),q=i((f,S,P)=>{let C=k.get(f),w={x:P.x??0,y:P.y??0},F={x:S.x??0,y:S.y??0},Z=C?.srcSide??v(S,w),ce=C?.dstSide??v(P,F),W=C?g(S,C.srcSide):d(S,w,!0),V=C?g(P,C.dstSide):d(P,F,!1),Re=Q.get(`${f}:src`),Ee=Q.get(`${f}:dst`);return Re!==void 0&&(W=ee(W,Z,Re)),Ee!==void 0&&(V=ee(V,ce,Ee)),{pSrcPort:W,pDstPort:V,srcSide:Z,dstSide:ce}},"portsForEdge");for(let f of L){let S=r[f];if(M[f]=[],!S.start||!S.end||S.points&&S.points.length>0||S.start===S.end)continue;let P=s.get(S.start),C=s.get(S.end);if(!P||!C)continue;let{pSrcPort:w,pDstPort:F,srcSide:Z,dstSide:ce}=q(f,P,C),W={...w},V={...F},Re=Z==="top"||Z==="bottom",Ee=ce==="top"||ce==="bottom";if(Re){let z=w.y>(P.y??0);W.y=z?w.y+gt:w.y-gt}else{let z=w.x>(P.x??0);W.x=z?w.x+gt:w.x-gt}if(Ee){let z=F.y>(C.y??0);V.y=z?F.y+gt:F.y-gt}else{let z=F.x>(C.x??0);V.x=z?F.x+gt:F.x-gt}let we=i((z,$)=>{for(let oe of b)if(!$.includes(oe.nodeId)&&z.x>oe.minX&&z.x<oe.maxX&&z.y>oe.minY&&z.y<oe.maxY)return{inside:!0,obstacle:oe};return{inside:!1}},"isPointInObstacle"),se=i((z,$,oe,Se,Be)=>{if(Be){let He=z.y>($.y??0);return{x:(oe.x??0)>=z.x?Se.maxX+_t:Se.minX-_t,y:He?Se.maxY+Yt:Se.minY-Yt,leavesPositiveSide:He}}let Pe=z.x>($.x??0),Ge=(oe.y??0)>=z.y;return{x:Pe?Se.maxX+_t:Se.minX-_t,y:Ge?Se.maxY+Yt:Se.minY-Yt,leavesPositiveSide:Pe}},"obstacleDetour"),Me=[],Fe=[S.start,S.end],ot=we(W,Fe);if(ot.inside&&ot.obstacle){let z=ot.obstacle;if(Re){let $=se(w,P,C,z,!0);W.x=$.x,W.y=$.y;let oe=$.leavesPositiveSide?Math.min(z.minY-2,w.y+gt):Math.max(z.maxY+2,w.y-gt);Me=[{x:w.x,y:oe},{x:$.x,y:oe},{x:$.x,y:$.y}]}else{let $=se(w,P,C,z,!1),oe=$.leavesPositiveSide?Math.min(z.minX-2,w.x+gt):Math.max(z.maxX+2,w.x-gt);W.x=$.x,W.y=$.y,Me=[{x:oe,y:w.y},{x:oe,y:$.y},{x:$.x,y:$.y}]}}let ze=[],dt=we(V,Fe);if(dt.inside&&dt.obstacle){let z=dt.obstacle;if(Ee){let $=se(F,C,P,z,!0);V.x=$.x,V.y=$.y,ze=[{x:$.x,y:$.y},{x:F.x,y:$.y}]}else{let $=se(F,C,P,z,!1);V.x=$.x,V.y=$.y,ze=[{x:$.x,y:$.y},{x:$.x,y:F.y}]}}if(Me.length===0&&ze.length===0){let z=_t,$=Math.abs(W.x-V.x)<z,oe=Math.abs(W.y-V.y)<z,Se=Q.get(`${f}:src`)!==void 0||Q.get(`${f}:dst`)!==void 0,Be=(R.get(`${S.start??""}:${Z}:src`)?.length??0)+(R.get(`${S.start??""}:${Z}:dst`)?.length??0),Pe=(R.get(`${S.end??""}:${ce}:src`)?.length??0)+(R.get(`${S.end??""}:${ce}:dst`)?.length??0),Ge=Be>1||Pe>1,He=E.get(S.start??"")??0,Ne=E.get(S.end??"")??0,qe=Be>1&&Y(S.start,Z)||Pe>1&&Y(S.end,ce),ft=Be<=1||He<=2,Ye=Pe<=1||Ne<=2;if(($||oe)&&!Se&&(!Ge||Ge&&!qe&&ft&&Ye)&&!x(w,F,S.start,S.end)){S.points=[{...w},{...W},{...V},{...F}],I.add(f);let Ae=oe?"horizontal":"vertical",tt=oe?w.y:w.x,Te=oe?Math.min(w.x,F.x):Math.min(w.y,F.y),ve=oe?Math.max(w.x,F.x):Math.max(w.y,F.y),rt={id:`fast-path-${Ae}-${tt.toFixed(0)}-${f}`,orientation:Ae,coord:tt,spanMin:Te,spanMax:ve,tracks:[]};m.push({edgeIndex:f,segmentIndex:0,orientation:Ae,pipe:rt,trackIndex:0,from:Te,to:ve});continue}}let Lt=p("vertical",W.x,W.y,W.y);W.x=Lt.coord;let Rn=p("vertical",V.x,V.y,V.y);V.x=Rn.coord;let St=Math.min(W.x,V.x)-50,Nt=Math.max(W.x,V.x)+50,Dt=Math.min(W.y,V.y)-50,Ft=Math.max(W.y,V.y)+50;for(let z of b){let $=Math.min(W.x,V.x),oe=Math.max(W.x,V.x),Se=Math.min(W.y,V.y),Be=Math.max(W.y,V.y);z.minX<oe&&z.maxX>$&&z.minY<Be&&z.maxY>Se&&(St=Math.min(St,z.minX-Nn),Nt=Math.max(Nt,z.maxX+Nn),Dt=Math.min(Dt,z.minY-Nn),Ft=Math.max(Ft,z.maxY+Nn))}for(let z of b){if(z.maxX<St||z.minX>Nt||z.maxY<Dt||z.minY>Ft)continue;let $=_t;p("horizontal",z.minY-$,St,Nt),p("horizontal",z.maxY+$,St,Nt);let oe=Yt;p("vertical",z.minX-oe,Dt,Ft),p("vertical",z.maxX+oe,Dt,Ft)}p("horizontal",W.y,St,Nt),p("horizontal",V.y,St,Nt);let Br=l.filter(z=>z.orientation==="horizontal"&&z.coord>=Dt&&z.coord<=Ft),kr=l.filter(z=>z.orientation==="vertical"&&z.coord>=St&&z.coord<=Nt),Zt=i((z,$)=>`${z.toFixed(1)},${$.toFixed(1)}`,"getKey"),Jt=Zt(W.x,W.y),no=Zt(V.x,V.y),Qt=new Map,En=new Map,Pn=new Map,en=new Set,Ot=[];Qt.set(Jt,0),Pn.set(Jt,"n"),Ot.push({key:Jt,f:Math.hypot(V.x-W.x,V.y-W.y),pt:W}),en.add(Jt);let We=[],Rt=i((z,$)=>x(z,$,S.start,S.end),"checkSegmentBlocked"),Cn={x:V.x,y:W.y},_r=Rt(W,Cn),Dr=Rt(Cn,V),Fr=_r||Dr,wn={x:W.x,y:V.y},Gr=Rt(W,wn),zr=Rt(wn,V);if(Fr?Gr||zr||(Math.abs(W.x-V.x)<ye?We=[W,V]:We=[W,wn,V]):Math.abs(W.y-V.y)<ye||Math.abs(W.x-V.x)<ye?We=[W,V]:We=[W,Cn,V],We.length===0)for(;Ot.length>0;){Ot.sort((Ne,qe)=>Ne.f-qe.f);let z=Ot.shift();if(en.delete(z.key),z.key===no){let Ne=no,qe=V;for(We=[qe];En.has(Ne);){let ft=En.get(Ne);We.unshift(ft),qe=ft,Ne=Zt(ft.x,ft.y)}break}let $=z.pt.x,oe=z.pt.y,Se=kr.sort((Ne,qe)=>Ne.coord-qe.coord),Be=Se.findIndex(Ne=>Math.abs(Ne.coord-$)<1),Pe=Br.sort((Ne,qe)=>Ne.coord-qe.coord),Ge=Pe.findIndex(Ne=>Math.abs(Ne.coord-oe)<1),He=[];Be>0&&He.push({x:Se[Be-1].coord,y:oe}),Be>=0&&Be<Se.length-1&&He.push({x:Se[Be+1].coord,y:oe}),Ge>0&&He.push({x:$,y:Pe[Ge-1].coord}),Ge>=0&&Ge<Pe.length-1&&He.push({x:$,y:Pe[Ge+1].coord});for(let Ne of He){let qe=Math.min($,Ne.x),ft=Math.max($,Ne.x),Ye=Math.min(oe,Ne.y),et=Math.max(oe,Ne.y);if(b.some(lt=>lt.nodeId===S.start||lt.nodeId===S.end?!1:qe!==ft?lt.minY<oe&&lt.maxY>oe&&lt.maxX>qe&&lt.minX<ft:lt.minX<$&&lt.maxX>$&&lt.maxY>Ye&&lt.minY<et))continue;let Ae=Zt(Ne.x,Ne.y),tt=Math.abs(Ne.x-$)+Math.abs(Ne.y-oe),Te=T(f,z.pt,Ne),ve=0,rt=V.x-W.x,Gt=V.y-W.y,tn=Ne.x-$,An=Ne.y-oe;(Gt>10&&An<-5||Gt<-10&&An>5)&&(ve=Math.abs(An)*100),(rt>10&&tn<-5||rt<-10&&tn>5)&&(ve+=Math.abs(tn)*50);let oo=0,ro=Pn.get(z.key)??"n",so=Math.abs(tn)>ye?"h":"v";ro!=="n"&&ro!==so&&(oo=50);let Hr=tt+Te+ve+oo,nn=(Qt.get(z.key)??1/0)+Hr,io=Math.abs(V.x-Ne.x)+Math.abs(V.y-Ne.y);if(nn<(Qt.get(Ae)??1/0))if(En.set(Ae,z.pt),Qt.set(Ae,nn),Pn.set(Ae,so),!en.has(Ae))Ot.push({key:Ae,f:nn+io,pt:Ne}),en.add(Ae);else{let lt=Ot.findIndex(Xr=>Xr.key===Ae);lt!==-1&&(Ot[lt].f=nn+io)}}}if(We.length===0&&(We=[W,{x:W.x,y:V.y},V]),We.length>4){let z=We[0],$=We[We.length-1],oe=Math.min(z.x,$.x),Se=Math.max(z.x,$.x),Be=Math.min(z.y,$.y),Pe=Math.max(z.y,$.y);for(let Ye of We)oe=Math.min(oe,Ye.x),Se=Math.max(Se,Ye.x),Be=Math.min(Be,Ye.y),Pe=Math.max(Pe,Ye.y);let Ge=Se>Math.max(z.x,$.x),He=oe<Math.min(z.x,$.x);if(u){let Ye=Yt;if(Ge){let et=Math.max(z.x,$.x),Xe=Math.min(z.y,$.y),Ae=Math.max(z.y,$.y),tt=b.filter(Te=>Te.minX<et&&Te.maxX>et&&Te.minY<Ae&&Te.maxY>Xe);if(tt.length>0){let Te=Math.max(z.x,$.x);for(let ve of tt){let rt=(ve.minX+ve.maxX)/2;if(ve.visualXHalfExtent===void 0||isNaN(ve.visualXHalfExtent))continue;let Gt=rt+ve.visualXHalfExtent+Ye;Te=Math.max(Te,Gt)}isNaN(Te)||(Se=Te)}}if(He){let et=b.filter(Xe=>Xe.minX<Math.min(z.x,$.x)+Ye&&Xe.minY<Math.max(z.y,$.y)&&Xe.maxY>Math.min(z.y,$.y));if(et.length>0){let Xe=Math.min(z.x,$.x);for(let Ae of et){let Te=(Ae.minX+Ae.maxX)/2-Ae.visualXHalfExtent-Ye;Xe=Math.min(Xe,Te)}oe=Xe}}}let Ne=i(Ye=>{let et=$.y>z.y,Xe=b.filter(Te=>{let ve=Math.min(z.x,$.x)<Te.maxX&&Math.max(z.x,$.x)>Te.minX,rt=Math.min(z.y,$.y)<Te.maxY&&Math.max(z.y,$.y)>Te.minY;return ve&&rt}),Ae=Xe;if(u&&Xe.length>0){let Te=Xe.filter(ve=>ve.minX<Ye&&ve.maxX>Ye);Te.length>0&&(Ae=Te)}if(Ae.length===0)return $.y;let tt=_t;if(et){let ve=Math.max(...Ae.map(rt=>rt.maxY))+tt;if(ve<$.y-ye)return ve}else{let ve=Math.min(...Ae.map(rt=>rt.minY))-tt;if(ve>$.y+ye)return ve}return $.y},"findBestReturnY"),qe=i(Ye=>{let et=Ne(Ye),Xe={x:Ye,y:z.y},Ae={x:Ye,y:et},tt={x:$.x,y:et},Te=Rt(z,Xe),ve=Rt(Xe,Ae),rt=Rt(Ae,tt),Gt=et!==$.y?Rt(tt,$):!1;return!Te&&!ve&&!rt&&!Gt?Math.abs(et-$.y)<ye?[z,Xe,Ae,$]:[z,Xe,Ae,tt,$]:null},"trySimplifyWithDetourX"),ft=Ge&&!He?qe(Se):He&&!Ge?qe(oe):null;ft&&(We=ft)}let Ke=[w,...Me,...We,...ze.reverse(),F];if(Ke.length>=3){let z=Ke[Ke.length-1],$=Ke[Ke.length-2],oe=Ke[Ke.length-3],Se=Math.abs(oe.y-$.y)<ye&&Math.abs($.y-z.y)<ye,Be=Math.abs(oe.x-$.x)<ye&&Math.abs($.x-z.x)<ye;if(Se){let Pe=Math.sign($.x-oe.x),Ge=Math.sign(z.x-oe.x);Pe!==0&&Pe===Ge&&Math.abs($.x-oe.x)>Math.abs(z.x-oe.x)&&Ke.splice(-2,1)}else if(Be){let Pe=Math.sign($.y-oe.y),Ge=Math.sign(z.y-oe.y);Pe!==0&&Pe===Ge&&Math.abs($.y-oe.y)>Math.abs(z.y-oe.y)&&Ke.splice(-2,1)}}let yt=[Ke[0]];for(let z=1;z<Ke.length-1;z++){if(z===1){yt.push(Ke[z]);continue}let $=yt[yt.length-1],oe=Ke[z],Se=Ke[z+1];if(Math.abs($.y-oe.y)<ye&&Math.abs(oe.y-Se.y)<ye){let Be=oe.x>$.x,Pe=Se.x>oe.x;if(Be!==Pe){yt.push(oe);continue}continue}if(Math.abs($.x-oe.x)<ye&&Math.abs(oe.x-Se.x)<ye){let Be=oe.y>$.y,Pe=Se.y>oe.y;if(Be!==Pe){yt.push(oe);continue}continue}yt.push(oe)}yt.push(Ke[Ke.length-1]);for(let z=0;z<yt.length-1;z++){let $=yt[z],oe=yt[z+1],Se=Math.abs($.x-oe.x)<ye?"vertical":"horizontal",Be=Se==="vertical"?$.x:$.y,Pe=Se==="vertical"?Math.min($.y,oe.y):Math.min($.x,oe.x),Ge=Se==="vertical"?Math.max($.y,oe.y):Math.max($.x,oe.x),He=p(Se,Be,Pe,Ge),Ne={edgeIndex:f,segmentIndex:z,orientation:Se,pipe:He,trackIndex:0,from:Pe,to:Ge};m.push(Ne),M[f].push(m.length-1),He.tracks[0]||(He.tracks[0]={index:0,coord:He.coord,segments:[]}),He.tracks[0].segments.push({edgeIndex:f,segmentIndex:z,from:Pe,to:Ge})}}let re=i((f,S)=>f.from<S.to&&S.from<f.to,"segmentsOverlap"),ue=i((f,S,P,C)=>{let w=!C.segments.some(Z=>(Z.edgeIndex!==S.edgeIndex||Z.segmentIndex!==S.segmentIndex)&&re(Z,f)),F=!P.segments.some(Z=>(Z.edgeIndex!==f.edgeIndex||Z.segmentIndex!==f.segmentIndex)&&re(Z,S));return w&&F?(f.trackIndex=C.index,S.trackIndex=P.index,P.segments=[...P.segments.filter(Z=>Z.edgeIndex!==f.edgeIndex||Z.segmentIndex!==f.segmentIndex),{edgeIndex:S.edgeIndex,segmentIndex:S.segmentIndex,from:S.from,to:S.to}],C.segments=[...C.segments.filter(Z=>Z.edgeIndex!==S.edgeIndex||Z.segmentIndex!==S.segmentIndex),{edgeIndex:f.edgeIndex,segmentIndex:f.segmentIndex,from:f.from,to:f.to}],!0):!1},"trySwapSegmentsAcrossTracks"),me=i(f=>{let S=f.tracks.length;return f.tracks[S]={index:S,coord:f.coord,segments:[]},S},"createNewTrack"),he=i((f,S)=>{let P=f.pipe.tracks[f.trackIndex];P.segments=P.segments.filter(w=>w.edgeIndex!==f.edgeIndex||w.segmentIndex!==f.segmentIndex),f.trackIndex=S,f.pipe.tracks[S].segments.push({edgeIndex:f.edgeIndex,segmentIndex:f.segmentIndex,from:f.from,to:f.to})},"moveSegmentToTrack"),be=i((f,S)=>{let P=M[f.edgeIndex];for(let C of P){let w=m[C];w.pipe===f.pipe&&he(w,S)}},"moveSegmentChainToTrack"),ke=i(f=>{let S=M[f.edgeIndex],P=S.indexOf(m.indexOf(f)),C=[];return P>0&&C.push(m[S[P-1]]),P<S.length-1&&C.push(m[S[P+1]]),C},"getAdjacentSegmentsAlongEdge"),At=i((f,S)=>{if(f.orientation===S.orientation)return!1;let P=f.orientation==="horizontal"?f:S,C=f.orientation==="horizontal"?S:f;return C.pipe.coord>P.from&&C.pipe.coord<P.to&&P.pipe.coord>C.from&&P.pipe.coord<C.to},"haveAnyCrossing"),It=i((f,S)=>{for(let P of f.tracks)if(!P.segments.some(w=>(w.edgeIndex!==S.edgeIndex||w.segmentIndex!==S.segmentIndex)&&re(w,S)))return P.index;return-1},"findAvailableTrack"),Mt=i((f,S)=>{if(f.trackIndex===S.trackIndex)return re(f,S);let P=ke(f),C=ke(S);return P.some(w=>C.some(F=>At(w,F)))},"segmentsConflict"),Tt=i((f,S,P)=>{if(ue(f,S,f.pipe.tracks[f.trackIndex],S.pipe.tracks[S.trackIndex]))return;let C=It(f.pipe,S);P(S,C!==-1?C:me(f.pipe))},"resolveTrackConflict"),qt=i(f=>{let S=0;for(let P=0;P<f.length;P++)for(let C=P+1;C<f.length;C++){let w=f[P],F=f[C];w.pipe===F.pipe&&Mt(w,F)&&(S++,Tt(w,F,be))}return S},"resolveHandleConflicts"),A=new Map,_=i(f=>{if(A.has(f))return A.get(f);let S=M[f];if(S.length===0){let ce={dest:0,deviation:0,base:0,delta:0};return A.set(f,ce),ce}let C=m[S[0]].pipe.coord,w=C;for(let ce=1;ce<S.length;ce++){let W=m[S[ce]];if(W.orientation==="horizontal"){let V=W.from,Re=W.to;w=Math.abs(V-C)>Math.abs(Re-C)?V:Re;break}}let F=Math.abs(w-C),Z={dest:w,deviation:F,base:C,delta:w-C};return A.set(f,Z),Z},"getDestInfo"),G=i(()=>{let f=0,S=new Map;for(let[C,w]of r.entries())M[C].length!==0&&w.start&&(S.has(w.start)||S.set(w.start,[]),S.get(w.start).push(C));let P=i(C=>{let w=r[C];if(!w.start||!w.end)return 0;let F=s.get(w.start),Z=s.get(w.end);if(!F||!Z)return 0;let ce=(Z.x??0)-(F.x??0),W=(Z.y??0)-(F.y??0);return Math.abs(ce)+Math.abs(W)},"getEdgeDistance");for(let C of S.values()){C.sort((F,Z)=>{let ce=_(F),W=_(Z);if(Math.abs(ce.deviation-W.deviation)>1)return ce.deviation-W.deviation;if(Math.abs(ce.dest-W.dest)>1)return ce.dest-W.dest;let V=P(F),Re=P(Z);if(Math.abs(V-Re)>1)return Re-V;let Ee=M[F].length,we=M[Z].length;if(Ee!==we)return Ee-we;if(Ee===1){let se=M[F][0],Me=M[Z][0];if(m[se]&&m[Me]){let Fe=m[se],ot=m[Me],ze=Math.abs(Fe.to-Fe.from),dt=Math.abs(ot.to-ot.from);if(Math.abs(ze-dt)>1)return ze-dt}}return 0});let w=C.map(F=>m[M[F][0]]);f+=qt(w)}return f},"fixSourceHandleCrossings"),U=i(()=>{let f=0,S=new Map;for(let[P,C]of r.entries())M[P].length!==0&&C.end&&(S.has(C.end)||S.set(C.end,[]),S.get(C.end).push(P));for(let P of S.values()){P.sort((w,F)=>{let Z=i(V=>{let Re=M[V];if(Re.length<2)return 0;let Ee=m[Re[Re.length-2]];return Math.abs(Ee.to-Ee.from)},"getDist"),ce=Z(w),W=Z(F);return Math.abs(ce-W)>.1?ce-W:w-F});let C=P.map(w=>m[M[w][M[w].length-1]]);f+=qt(C)}return f},"fixTargetHandleCrossings"),K=i(()=>{let f=0;for(let S of l){let P=[];for(let C of S.tracks)for(let w of C.segments){let F=M[w.edgeIndex].find(Z=>m[Z].segmentIndex===w.segmentIndex);F!==void 0&&P.push(m[F])}P.sort((C,w)=>C.edgeIndex-w.edgeIndex||C.segmentIndex-w.segmentIndex);for(let C=0;C<P.length;C++)for(let w=C+1;w<P.length;w++){let F=P[C],Z=P[w];Mt(F,Z)&&(f++,Tt(F,Z,he))}}return f},"fixPipeCrossings"),te=0,H=10;for(;te<H;){let f=0;if(f+=G(),f+=U(),f+=K(),f===0)break;te++}let ne=new Map;for(let f of l){let S=[];f.tracks.forEach(C=>{C.segments.forEach(w=>{S.push({edgeIndex:w.edgeIndex,segmentIndex:w.segmentIndex,trackIndex:C.index,from:w.from,to:w.to})})}),S.sort((C,w)=>C.from-w.from);let P=[];if(S.length>0){let C=[S[0]],w=S[0].to;for(let F=1;F<S.length;F++){let Z=S[F];Z.from<w?(C.push(Z),w=Math.max(w,Z.to)):(P.push(C),C=[Z],w=Z.to)}P.push(C)}for(let C of P){let w=new Set;C.forEach(se=>w.add(se.trackIndex));let F=new Map;C.forEach(se=>{let Me=_(se.edgeIndex);F.set(se.trackIndex,(F.get(se.trackIndex)??0)+Me.delta)});let Z=[...w].filter(se=>(F.get(se)??0)<-1),ce=[...w].filter(se=>(F.get(se)??0)>1),W=[...w].filter(se=>Math.abs(F.get(se)??0)<=1);Z.sort((se,Me)=>(F.get(Me)??0)-(F.get(se)??0)),ce.sort((se,Me)=>(F.get(se)??0)-(F.get(Me)??0));let V=i((se,Me)=>{C.filter(Fe=>Fe.trackIndex===se).forEach(Fe=>{let ot=I.has(Fe.edgeIndex)?f.coord:Me;ne.set(`${Fe.edgeIndex}-${Fe.segmentIndex}`,ot)})},"assignCoord"),Re=0;for(let se of Z)Re++,V(se,f.coord-Re*eo);if(W.length===0&&w.size>0){let se=[...w].sort((ot,ze)=>Math.abs(F.get(ot)??0)-Math.abs(F.get(ze)??0))[0],Me=Z.indexOf(se);Me!==-1&&Z.splice(Me,1);let Fe=ce.indexOf(se);Fe!==-1&&ce.splice(Fe,1),W.push(se)}let Ee=0;for(let se of W){if(Ee===0)V(se,f.coord);else{let Me=Ee%2===1?1:-1,Fe=Math.ceil(Ee/2);V(se,f.coord+Me*Fe*eo*.5)}Ee++}let we=0;for(let se of ce)we++,V(se,f.coord+we*eo)}}for(let[f,S]of r.entries()){let P=M[f]??[];if(P.length===0)continue;let C=[],w=s.get(S.start),F=s.get(S.end),{pSrcPort:Z,pDstPort:ce}=q(f,w,F),W=P.map(we=>{let se=m[we],Me=ne.get(`${se.edgeIndex}-${se.segmentIndex}`)??se.pipe.coord;return{orient:se.orientation,coord:Me,from:se.from,to:se.to}});C.push(Z);for(let we=0;we<W.length;we++){let se=W[we],Me=C[C.length-1],Fe=se.orient==="vertical"?Me.y:Me.x,ot=se.orient==="vertical"?Me.x:Me.y,ze=W[we+1],dt=we<W.length-1;if(Math.abs(ot-se.coord)>ye&&C.push($t(se,Fe)),dt&&ze.orient===se.orient)if(Math.abs(se.coord-ze.coord)>ye){let Lt=se.orient==="vertical"?(Fe+ze.from)/2:Tr(se,ze);C.push($t(se,Lt),$t(ze,Lt))}else(we===0||we===W.length-2)&&C.push($t(se,Tr(se,ze)));else if(dt)C.push($t(se,ze.coord));else{let Lt=Math.abs(se.from-Fe)<Math.abs(se.to-Fe)?se.to:se.from;C.push($t(se,Lt))}}let V=C[C.length-1];(Math.abs(V.x-ce.x)>ye||Math.abs(V.y-ce.y)>ye)&&C.push(ce);let Re=C[0];Re&&(Math.abs(Re.x-Z.x)>ye||Math.abs(Re.y-Z.y)>ye)&&C.unshift(Z);let Ee=[];C.length>0&&Ee.push(C[0]);for(let we=1;we<C.length;we++){let se=C[we],Me=Ee[Ee.length-1];(Math.abs(se.x-Me.x)>ye||Math.abs(se.y-Me.y)>ye)&&Ee.push(se)}S.points=Ee}for(let f of r){let S=f.__originalEdge;S&&f.points&&(S.points=f.points)}e.edges=(e.edges??[]).filter(f=>!f.isLayoutOnly);let le=i((f,S)=>{let P=S.x??0,C=S.y??0,{w,h:F}=to(S,0);if(w<=0||F<=0)return f;let Z=P-w/2,ce=P+w/2,W=C-F/2,V=C+F/2;if(f.x<Z||f.x>ce||f.y<W||f.y>V)return f;let Re=f.x-Z,Ee=ce-f.x,we=f.y-W,se=V-f.y,Me=Math.min(Re,Ee,we,se);return Me===Re?{x:Z,y:f.y}:Me===Ee?{x:ce,y:f.y}:Me===we?{x:f.x,y:W}:{x:f.x,y:V}},"nodeBoundaryClamp");for(let f of e.edges){let S=f.points;if(!S||S.length<2)continue;let P=f.start,C=f.end,w=P?s.get(P):void 0,F=C?s.get(C):void 0;w&&(S[0]=le(S[0],w)),F&&(S[S.length-1]=le(S[S.length-1],F))}return e}i(Or,"routeEdgesOrthogonal");function ri(e){return e.direction??"TB"}i(ri,"getSwimlaneDirection");function vr(e){let t=ho(e),n=e.config.flowchart?.nodeSpacing??40,o=e.config.flowchart?.rankSpacing??100,r=e.config.swimlane?.ignoreCrossLaneEdges??!0,s=e.config.swimlane?.optimizeRanksByCrossings??!0,a=e.config.swimlane?.automaticLaneOrdering??!1,l=ri(e),{ordered:u,coordinates:h}=Cr(t,{nodeGap:n,layerGap:o,ignoreCrossLaneEdges:r,optimizeRanksByCrossings:s,automaticLaneOrdering:a,direction:l});po(t,u,h,{nodeGap:n,layerGap:o});for(let y of e.edges??[])delete y.points;Or(e,l);for(let y of e.edges??[])(!y.curve||y.curve==="basis")&&(y.curve="rounded");return rr(e,l),Wn(e),l}i(vr,"runSwimlaneLayoutCore");function si(e){mo(e);let t=yo(e);e.nodes=t.nodes,e.edges=t.edges}i(si,"prepareSwimlaneLayout");var ed=ao({prepareLayout:si,runLayoutCore:vr,afterPaint:lo});export{ed as render};