@juki-team/base-ui 1.5.11 → 1.5.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/ArrowForwardIcon-DelUFdaJ.js +1 -0
- package/dist/esm/{BarChart-D6_BRhr2.js → BarChart-D2X8Qu4u.js} +1 -1
- package/dist/esm/{CartesianChart-CWujTVm7.js → CartesianChart-DYpkf6Ou.js} +1 -1
- package/dist/esm/{ChangePasswordModal-Ds3TqD5C.js → ChangePasswordModal-yc4D7RMs.js} +1 -1
- package/dist/esm/{CodeEditor-CTnPGIiF.js → CodeEditor-Dxp5QnTB.js} +1 -1
- package/dist/esm/{CodeViewer-DKaZetL7.js → CodeViewer-BSZXIngC.js} +1 -1
- package/dist/esm/{Collapse-cx1sfcdL.js → Collapse-D-w5SKss.js} +1 -1
- package/dist/esm/{DataGrid-bZJxnNpn.js → DataGrid-BdFgb8IP.js} +1 -1
- package/dist/esm/DataViewer-DVVGkDSK.js +1 -0
- package/dist/esm/{DrawerView-uqDkkfN3.js → DrawerView-DCRvckZd.js} +1 -1
- package/dist/esm/{ExcalidrawButton-DP7IRqig.js → ExcalidrawButton-_a-eNbyb.js} +1 -1
- package/dist/esm/{GraphvizViewer-BGX2Z8KP.js → GraphvizViewer-B2-JVx0t.js} +1 -1
- package/dist/esm/{ImageLoaderCropper-BfIfmEdE.js → ImageLoaderCropper-wV-hPOjq.js} +1 -1
- package/dist/esm/{InputCellPhoneNumber-qovO8IT4.js → InputCellPhoneNumber-Bcl22QsC.js} +1 -1
- package/dist/esm/{InputColor-8DJM_wZR.js → InputColor-CHgGjI3f.js} +1 -1
- package/dist/esm/{LineChart-vXWysFNq.js → LineChart-ByKPkVhP.js} +1 -1
- package/dist/esm/{LoaderLayer-Cv80UCdL.js → LoaderLayer-ECtsj85k.js} +1 -1
- package/dist/esm/{MdMath-D4p_cWv8.js → MdMath-DljkRDxR.js} +1 -1
- package/dist/esm/{MdMathEditor-BC4QqqY5.js → MdMathEditor-Dvq5oODw.js} +1 -1
- package/dist/esm/{Popover-KQx_QYJY.js → Popover-CX8YffOd.js} +1 -1
- package/dist/esm/ReplyIcon-BNYBKbgb.js +1 -0
- package/dist/esm/{SettingsIcon-C3sN1TNw.js → SettingsIcon-B9nmP4lD.js} +1 -1
- package/dist/esm/{SlideDeck-BP-CNUhS.js → SlideDeck-C0n93gz0.js} +1 -1
- package/dist/esm/{TableEyeIcon-BFfTLgKU.js → TableEyeIcon-Mb5aFvN0.js} +1 -1
- package/dist/esm/{TableOfContents-Cg9pymLO.js → TableOfContents-BBAEZx6Z.js} +1 -1
- package/dist/esm/{Tooltip-k62JJg5n.js → Tooltip-DB0S1ErV.js} +1 -1
- package/dist/esm/{UserCodeEditor-LaT3CJvU.js → UserCodeEditor-B1d5gyVE.js} +2 -2
- package/dist/esm/{VirtualizedRowsFixed-CN-1w7u1.js → VirtualizedRowsFixed-ChX4ON0l.js} +1 -1
- package/dist/esm/{WorksheetAsSlides-DmGLDXtL.js → WorksheetAsSlides-CpiXbUML.js} +1 -1
- package/dist/esm/{WorksheetBodies-BYISk5yC.js → WorksheetBodies-CO67-rEz.js} +1 -1
- package/dist/esm/{WorksheetContents-IzJ6Cw_g.js → WorksheetContents-ClZpiXB-.js} +1 -1
- package/dist/esm/{WorksheetEditor-Dacb3EOk.js → WorksheetEditor-CjAvgOx6.js} +1 -1
- package/dist/esm/WorksheetNode-BgNNzY8I.js +1 -0
- package/dist/esm/{WorksheetViewer-BLFZouvt.js → WorksheetViewer-DVQitUzi.js} +1 -1
- package/dist/esm/{abnfDiagram-WEYOIA3C-BEp-BJ00.js → abnfDiagram-WEYOIA3C-CwJ1V2U1.js} +1 -1
- package/dist/esm/{arc-B4ps4Bee.js → arc-COK0VEkT.js} +1 -1
- package/dist/esm/{architectureDiagram-ZHVYKT53-BDbBQNmT.js → architectureDiagram-ZHVYKT53-CM6AQFKG.js} +1 -1
- package/dist/esm/{blockDiagram-RJAE7QA3-CYciK31K.js → blockDiagram-RJAE7QA3-CdSNo9Pe.js} +1 -1
- package/dist/esm/{c4Diagram-XDPPPE54-dye_nDtJ.js → c4Diagram-XDPPPE54-BhfYKASq.js} +1 -1
- package/dist/esm/channel-DWjyymG_.js +1 -0
- package/dist/esm/{chunk-2E7WHVMD-fBpaf8Ph.js → chunk-2E7WHVMD-CVBqw5fR.js} +1 -1
- package/dist/esm/{chunk-2Q5K7J3B-B1dv6ovr.js → chunk-2Q5K7J3B-CyZYeWxE.js} +1 -1
- package/dist/esm/{chunk-4EMNKR2T-B10soxeX.js → chunk-4EMNKR2T-D1yHHif8.js} +1 -1
- package/dist/esm/{chunk-55XCU76K-BhN5PLeC.js → chunk-55XCU76K-CvYWAV_o.js} +1 -1
- package/dist/esm/{chunk-5VM5RSS4-DEKr6tsK.js → chunk-5VM5RSS4-CS0kZLYA.js} +1 -1
- package/dist/esm/{chunk-JWPE2WC7-lyHCgozd.js → chunk-JWPE2WC7-Ct5OBLCL.js} +1 -1
- package/dist/esm/{chunk-NQOKRVIF-CLuzP2Xi.js → chunk-NQOKRVIF-D0-2mmH4.js} +1 -1
- package/dist/esm/{chunk-VQ5W62QI-MGNBKNlF.js → chunk-VQ5W62QI-CsGo0PTx.js} +1 -1
- package/dist/esm/{chunk-XXDRQBXY-CIB-Pv6R.js → chunk-XXDRQBXY-DPPGTM3w.js} +1 -1
- package/dist/esm/{chunk-ZCHMQSOR--e_zi_XA.js → chunk-ZCHMQSOR-Bvjutmxm.js} +1 -1
- package/dist/esm/{classDiagram-v2-4MYWR3UA-BU3oZLY5.js → classDiagram-v2-4MYWR3UA-J_cOAAHS.js} +1 -1
- package/dist/esm/{commons-BHuDJzTw.js → commons-iref2pEJ.js} +1 -1
- package/dist/esm/constants.js +1 -1
- package/dist/esm/{cose-bilkent-JH36ORCC-DdSzxxt0.js → cose-bilkent-JH36ORCC-BHzp2aV0.js} +1 -1
- package/dist/esm/{cynefinDiagram-WF24UDRP-BbPVqiW_.js → cynefinDiagram-WF24UDRP-B3Y9mCh3.js} +1 -1
- package/dist/esm/{dagre-NK4GIZVX-DLhklBxm.js → dagre-NK4GIZVX-BSfh-C_i.js} +1 -1
- package/dist/esm/{diagram-CBK3MWTC-C2Pa6CcJ.js → diagram-CBK3MWTC-w-BT1S7I.js} +1 -1
- package/dist/esm/{diagram-I5XIIV2D-D-qVVyv1.js → diagram-I5XIIV2D-wMqo87b_.js} +1 -1
- package/dist/esm/{diagram-ODIL2UCW-QFqiGLCP.js → diagram-ODIL2UCW-DQhUXqDu.js} +1 -1
- package/dist/esm/{diagram-PFBEJUXE-UHmEOsHi.js → diagram-PFBEJUXE-BlCntZMJ.js} +1 -1
- package/dist/esm/{diagram-RJA3I4VV-CcSCqRS4.js → diagram-RJA3I4VV-Cev21A9i.js} +1 -1
- package/dist/esm/{diagram-TYUNFSNR-DcSxaQx8.js → diagram-TYUNFSNR-BiiLNoPs.js} +1 -1
- package/dist/esm/{ebnfDiagram-V4P3TTPT-DRA2NTIs.js → ebnfDiagram-V4P3TTPT-BWNnHl88.js} +1 -1
- package/dist/esm/{elk-QONTBCTQ-Bkv5Sf8G.js → elk-QONTBCTQ-DhvgoeNg.js} +1 -1
- package/dist/esm/{erDiagram-KYQIGQAA-Blb_MksM.js → erDiagram-KYQIGQAA-DkFGw08p.js} +1 -1
- package/dist/esm/flowDiagram-IUGLLWBU-B-Bxdnen.js +1 -0
- package/dist/esm/{ganttDiagram-R7GPNTJY-Do8IYgX5.js → ganttDiagram-R7GPNTJY-Bvr90Acy.js} +1 -1
- package/dist/esm/{gitGraphDiagram-PDYL7XHY-CAvv6VXj.js → gitGraphDiagram-PDYL7XHY-DHszoB7b.js} +1 -1
- package/dist/esm/helpers.js +1 -1
- package/dist/esm/{index-_kF3_0-k.js → index-2PTQqTnK.js} +1 -1
- package/dist/esm/{index-JPCp_Z3V.js → index-70SVfF-m.js} +1 -1
- package/dist/esm/{index-Dz8ISdDG.js → index-B5Soolr4.js} +1 -1
- package/dist/esm/index-BpcqEzEG.js +1 -0
- package/dist/esm/{index-L4hkrldv.js → index-DkZReaeM.js} +1 -1
- package/dist/esm/{infoDiagram-MVDRKAX5-CcsrNbMy.js → infoDiagram-MVDRKAX5-D05SjyVf.js} +1 -1
- package/dist/esm/{ishikawaDiagram-HPEHV2GE-BSefVZjI.js → ishikawaDiagram-HPEHV2GE-50RQ8Owd.js} +1 -1
- package/dist/esm/{journeyDiagram-BOSHW7O7-C3Y3fTW5.js → journeyDiagram-BOSHW7O7-DnHu8DYt.js} +1 -1
- package/dist/esm/{kanban-definition-FNSA4HC5-DqDHeqOc.js → kanban-definition-FNSA4HC5-BF3y0Q5O.js} +1 -1
- package/dist/esm/main.js +1 -1
- package/dist/esm/{mermaid.core-DKkN0L2R.js → mermaid.core-DRk6tt5W.js} +2 -2
- package/dist/esm/{mindmap-definition-6OY57UG3-BaT97m0e.js → mindmap-definition-6OY57UG3-D2VvQCn5.js} +1 -1
- package/dist/esm/{pegDiagram-ECIUJNBX-BHWXjV1h.js → pegDiagram-ECIUJNBX-LCa_e2vp.js} +1 -1
- package/dist/esm/{pieDiagram-GNMPY74T-tMRQX3HS.js → pieDiagram-GNMPY74T-BFxRc695.js} +1 -1
- package/dist/esm/{quadrantDiagram-D57K4MC3-CfbxRwkB.js → quadrantDiagram-D57K4MC3-m-v5Oved.js} +1 -1
- package/dist/esm/{railroadDiagram-Y72NRBL7-QMN2Zgh0.js → railroadDiagram-Y72NRBL7-CGhQNkt2.js} +1 -1
- package/dist/esm/{requirementDiagram-EQYSW5RA-5SA2oZMo.js → requirementDiagram-EQYSW5RA-D4TUJX2j.js} +1 -1
- package/dist/esm/{sankeyDiagram-SY24JHO5-BXdQgEr6.js → sankeyDiagram-SY24JHO5-qeunG13D.js} +1 -1
- package/dist/esm/{sequenceDiagram-BLEHNHQU-BvWgv_Hq.js → sequenceDiagram-BLEHNHQU-Bf8dSGiP.js} +1 -1
- package/dist/esm/server.js +1 -1
- package/dist/esm/settings-CBGV-lz3.js +1 -0
- package/dist/esm/settings.js +1 -1
- package/dist/esm/{sizeCapture-INFHLROL-CRBg4FIP.js → sizeCapture-INFHLROL-B0tQoQkY.js} +1 -1
- package/dist/esm/{stateDiagram-v2-A6IESKWZ-DOTqWcFT.js → stateDiagram-v2-A6IESKWZ-D-bM5qVN.js} +1 -1
- package/dist/esm/{swimlanes-B3ENRKFQ-Dt3HxqOR.js → swimlanes-B3ENRKFQ-DR9euVhL.js} +1 -1
- package/dist/esm/swimlanesDiagram-AYQRV4AK-D0-BBYnj.js +1 -0
- package/dist/esm/{timeline-definition-JXYKGLGB-ChogrVVw.js → timeline-definition-JXYKGLGB-ChsOD2es.js} +1 -1
- package/dist/esm/{types-BqWpd51k.js → types-DsZvEANP.js} +1 -1
- package/dist/esm/{usecaseDiagram-WPOLBNNX-DAMNLFuf.js → usecaseDiagram-WPOLBNNX-DZFg1Zof.js} +1 -1
- package/dist/esm/{vennDiagram-Q3Y3IDCW--qCUcJOu.js → vennDiagram-Q3Y3IDCW-DAW-dDy7.js} +1 -1
- package/dist/esm/{wardleyDiagram-IVAIDKWA-D0f1LOLT.js → wardleyDiagram-IVAIDKWA-B-gsebc8.js} +1 -1
- package/dist/esm/websocket-CdeP8N_S.js +1 -0
- package/dist/esm/{xychartDiagram-4URNHDU4-Bkx4mxlH.js → xychartDiagram-4URNHDU4-DS3Qm0VA.js} +1 -1
- package/dist/module-types/src/components/organisms/_layz_/DataViewer/CardList/DataViewerCard.d.ts +6 -2
- package/dist/module-types/src/components/organisms/_layz_/DataViewer/CardList/types.d.ts +9 -6
- package/dist/module-types/src/components/organisms/_layz_/DataViewer/RowList/TableHead/index.d.ts +2 -2
- package/dist/module-types/src/components/organisms/_layz_/DataViewer/RowList/TableRow.d.ts +21 -0
- package/dist/module-types/src/components/organisms/_layz_/DataViewer/RowList/ViewContainerRows.d.ts +0 -2
- package/dist/module-types/src/components/organisms/_layz_/DataViewer/RowList/columnLayout.d.ts +23 -0
- package/dist/module-types/src/components/organisms/_layz_/DataViewer/RowList/useScrollEdges.d.ts +13 -0
- package/dist/module-types/src/components/organisms/_layz_/DataViewer/types.d.ts +12 -8
- package/dist/module-types/src/stores/websocket/topicChannels.d.ts +37 -0
- package/package.json +2 -2
- package/src/styles/components/atoms/_data-viewer.scss +34 -16
- package/dist/esm/ArrowForwardIcon-1RdVdC78.js +0 -1
- package/dist/esm/DataViewer-DpQqmjva.js +0 -1
- package/dist/esm/ReplyIcon-BlBLARCH.js +0 -1
- package/dist/esm/WorksheetNode-2B7Rld9L.js +0 -1
- package/dist/esm/channel-DdQBbu1U.js +0 -1
- package/dist/esm/flowDiagram-IUGLLWBU-CQaJ12bg.js +0 -1
- package/dist/esm/index-DTAG4nDF.js +0 -1
- package/dist/esm/settings-BONQQsPx.js +0 -1
- package/dist/esm/swimlanesDiagram-AYQRV4AK-cNbShXsw.js +0 -1
- package/dist/esm/websocket-B2hJys_Q.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as t}from"./chunk-4EMNKR2T-B10soxeX.js";import{c as e}from"./chunk-ZCHMQSOR--e_zi_XA.js";import{_ as n,l as o}from"./mermaid.core-DKkN0L2R.js";import"./graph-rGqC_56m.js";import"./isSymbol-D2gNAbOe.js";import"./isUndefined--MLpwE__.js";import"./index-DTAG4nDF.js";import"react/jsx-runtime";import"react";import"./enums.js";import"./commons-BHuDJzTw.js";import"./settings-BONQQsPx.js";import"./constants.js";import"./LoaderLayer-Cv80UCdL.js";import"./websocket-B2hJys_Q.js";import"./index-_kF3_0-k.js";import"motion/react";import"react-dom";import"swr";import"@ably/spaces";import"@ably/spaces/react";import"ably";import"ably/liveobjects";import"ably/react";import"@ably/spaces/dist/mjs/react";import"./string-DPJhNSkw.js";function r(e,{measure:n}){const o=e.config?.swimlane?.lineHops;if(!1===o)return;const r="gap"===o?"gap":"arc",s=e.edges.filter(t=>Array.isArray(t.points)&&t.points.length>=2).map(t=>({id:t.id,points:t.points,curve:t.curve,arrowTypeStart:t.arrowTypeStart,arrowTypeEnd:t.arrowTypeEnd}));t(n.groups.edgePaths,s,{enabled:!0,jumpRadius:6,jumpStyle:r})}n(r,"applySwimlaneLineJumps");var s="__swimlane_default__";function i(t){return Math.max(t.padding??20,20)}function a(t){const{x:e,y:n,width:o,height:r}=t,s=t.swimlaneContentTop;if("number"!=typeof e||"number"!=typeof n||"number"!=typeof o||"number"!=typeof r||"number"!=typeof s||!Number.isFinite(e)||!Number.isFinite(n)||!Number.isFinite(o)||!Number.isFinite(r)||!Number.isFinite(s)||o<=0||r<=0)return void delete t.groupTitleRect;const i=n-r/2,a=Math.min(s,n+r/2),c=i+Math.min(21,Math.max(0,a-i));c<=i?delete t.groupTitleRect:t.groupTitleRect={left:e-o/2,right:e+o/2,top:i,bottom:c}}function c(t){const e=t.direction,n=t.nodes??=[];for(const n of t.nodes??[])n.isGroup&&!n.parentId&&(n.shape="swimlane",e&&(n.direction=e));const o=n.filter(t=>!t.isGroup&&!t.parentId);if(0===o.length)return;let r=n.find(t=>t.id===s);r?r.isGroup&&(r.shape="swimlane",e&&(r.direction=e)):(r={id:s,label:"",isGroup:!0,shape:"swimlane",padding:20,look:t.config?.look,colorIndex:n.reduce((t,e)=>Math.max(t,e.colorIndex??-1),-1)+1,...e?{direction:e}:{}},n.push(r));for(const t of o)t.parentId=s}function f(t){const e=new Map;for(const n of t.nodes??[])e.set(n.id,n);const n=[];for(const e of t.edges??[]){const t="string"==typeof e.start?e.start:void 0,o="string"==typeof e.end?e.end:void 0;t&&o&&(e.labelNodeId||n.push({id:e.id,src:t,dst:o,ref:e}))}const o=t.nodes??[],r=o.filter(t=>t.isGroup),s=o.filter(t=>!t.isGroup);return{nodes:[...[...r].reverse(),...s].map(t=>t.id),edges:n,layout:t,nodeById:e}}function d(t,e,n,o){const{layout:r}=t,s=t.nodeById,c=o?.layerGap??100,f=o?.nodeGap??40;let d=0;for(const t of e.layers){let e=0;for(const o of t){const t=s.get(o);if(!t){e++;continue}t.layer=d,t.order=e;const r=n.x[o]??e*f,i=n.y[o]??d*c;t.x=r,t.y=i,e++}d++}const l=r.nodes??[],u=new Map,h=[];for(const t of l){if(!t?.isGroup)continue;t.parentId||h.push(t);const e=l.filter(e=>e.parentId===t.id);let o=1/0,r=-1/0,s=1/0,a=-1/0;for(const t of e){const e=t.x??n.x[t.id],i=t.y??n.y[t.id],c=t.width??0,f=t.height??0;null!=e&&null!=i&&(o=Math.min(o,e-c/2),r=Math.max(r,e+c/2),s=Math.min(s,i-f/2),a=Math.max(a,i+f/2))}if(o===1/0||s===1/0)t.x=t.x??0,t.y=t.y??0,t.width=t.width??0,t.height=t.height??0;else{const e=t.padding??20,n=t.parentId?e:2*i(t),c=e,f=Math.max(0,r-o)+n,d=Math.max(0,a-s)+c,l=(o+r)/2,h=(s+a)/2;t.x=l,t.y=h,t.width=f,t.height=d,u.set(t.id,{minX:o,maxX:r,minY:s,maxY:a})}}if(h.length>0&&u.size>0){let t=1/0,e=-1/0,n=0;for(const o of h){const r=o.padding??20;r>n&&(n=r);const s=u.get(o.id);s&&(t=Math.min(t,s.minY),e=Math.max(e,s.maxY))}if(t!==1/0&&e!==-1/0){const o=36,r=Math.max(0,e-t)+2*Math.max(n,o),s=(t+e)/2;for(const e of h)e.y=s,e.height=r,e.swimlaneContentTop=t;const c=[...h].sort((t,e)=>(t.x??0)-(e.x??0)),f=[],d=[],l=[];for(const t of c){const e=u.get(t.id);if(!e)continue;const n=Math.max(0,e.maxX-e.minX)+2*i(t),o=(e.minX+e.maxX)/2;f.push(t.id),d.push(o),l.push(n)}const g=f.length;if(g>0){const t=new Map;if(1===g)t.set(f[0],l[0]);else{const e=[];for(let t=0;t<g-1;t++)e.push(d[t+1]-d[t]);const n=new Array(g);n[0]=0;for(let t=0;t<g-1;t++)n[t+1]=2*e[t]-n[t];let o=0,r=Number.POSITIVE_INFINITY;for(let t=0;t<g;t++){const e=l[t];t%2==0?o=Math.max(o,e-n[t]):r=Math.min(r,n[t]-e)}let s=o;s=o<=r?(o+r)/2:o;for(let e=0;e<g;e++){const o=n[e]+(e%2==0?s:-s),r=Math.max(l[e],o);t.set(f[e],r)}}for(const e of h){const n=t.get(e.id);null!=n&&(e.width=n),a(e)}}}}}n(i,"topLaneHorizontalPadding"),n(a,"assignTopLaneTitleRect"),n(c,"prepareLayoutForSwimlanes"),n(f,"toGraphView"),n(d,"writeBackToLayoutData");function l(t){const e=[],n=[],r=new Map;for(const e of t.nodes)r.set(e.id,e);for(const s of t.edges){if(!s.label||0===s.label.length)continue;if(s.isLayoutOnly)continue;if(s.labelNodeId)continue;const t=s.start?r.get(s.start):void 0,i=s.end?r.get(s.end):void 0;if(!t||!i){o.warn("[EdgeLabelNodes]",`Edge ${s.id} has missing source or target node`);continue}const a=`edge-label-${s.start}-${s.end}-${s.id}`,c=t.parentId!==i.parentId?i.parentId:t.parentId,f={id:a,label:s.label,edgeStart:s.start??"",edgeEnd:s.end??"",shape:"labelRect",width:0,height:0,isEdgeLabel:!0,isDummy:!0,parentId:c,isGroup:!1,labelStyle:Array.isArray(s.labelStyle)?s.labelStyle[0]:s.labelStyle??"",...t.dir?{dir:t.dir}:{}};e.push(f),s.labelNodeId=a,s.label=void 0,s.text=void 0;const d={id:`${s.id}-to-label`,start:s.start,end:a,type:"normal",isLayoutOnly:!0},l={id:`${s.id}-from-label`,start:a,end:s.end,type:"normal",isLayoutOnly:!0};n.push(d,l)}const s=[...t.nodes,...e],i=[...t.edges,...n];return{...t,nodes:s,edges:i}}n(l,"createEdgeLabelNodes");var u=.001;function h(t){const e=t.x??0,n=t.y??0,o=t.width??0,r=t.height??0;return o>0&&r>0?{cx:e,cy:n,rect:T(e,n,o,r)}:void 0}function g(t){if(t.isGroup)return;const e=h(t);if(!e)return;return{id:String(t.id??""),cx:e.cx,cy:e.cy,rect:e.rect}}function p(t,e,n=u){return Math.abs(t.x-e.x)<n&&Math.abs(t.y-e.y)<n}function m(t,e,n=u){return Math.abs(t.x-e.x)<n}function x(t,e,n=u){return Math.abs(t.y-e.y)<n}function y(t,e,n=u){return x(t,e,n)&&Math.abs(t.x-e.x)>n}function b(t,e,n=u){return m(t,e,n)&&Math.abs(t.y-e.y)>n}function M(t,e,n,o){return Math.max(0,Math.min(Math.max(t,e),Math.max(n,o))-Math.max(Math.min(t,e),Math.min(n,o)))}function I(t,e,n=u){return t.horizontal&&e.horizontal&&x(t.a,e.a,n)?M(t.a.x,t.b.x,e.a.x,e.b.x):t.vertical&&e.vertical&&m(t.a,e.a,n)?M(t.a.y,t.b.y,e.a.y,e.b.y):0}function S(t,e=u){const n=[];for(let o=0;o<t.length-1;o++){const r=t[o],s=t[o+1],i=y(r,s,e),a=b(r,s,e);(i||a)&&n.push({index:o,a:r,b:s,horizontal:i,vertical:a})}return n}function w(t,e=u){const n=S(t,e);let o=0;for(let t=1;t<n.length;t++)n[t-1].horizontal!==n[t].horizontal&&o++;return o}function v(t,e=u){const n=[];for(const o of t){const t=n.length>0?n[n.length-1]:void 0;t&&p(t,o,e)||n.push({x:o.x,y:o.y})}return n}function C(t,e=u){if(!t||4!==t.length)return;const[n,o,r,s]=t;if(y(n,o,e)&&b(o,r,e)&&y(r,s,e))return{kind:"HVH",p0:n,p1:o,p2:r,p3:s};return b(n,o,e)&&y(o,r,e)&&b(r,s,e)?{kind:"VHV",p0:n,p1:o,p2:r,p3:s}:void 0}function L(t,e,n,o=0){const r=Math.min(t.x,e.x),s=Math.max(t.x,e.x),i=Math.min(t.y,e.y),a=Math.max(t.y,e.y);return s>n.left-o&&r<n.right+o&&a>n.top-o&&i<n.bottom+o}function k(t,e,n=0){return t.x>e.left+n&&t.x<e.right-n&&t.y>e.top+n&&t.y<e.bottom-n}function O(t,e){return t.left<=e.left&&t.right>=e.right&&t.top<=e.top&&t.bottom>=e.bottom}function R(t,e){return t.left<e.right&&t.right>e.left&&t.top<e.bottom&&t.bottom>e.top}function N(t,e){return{left:t.left-e,right:t.right+e,top:t.top-e,bottom:t.bottom+e}}function T(t,e,n,o){return{left:t-n/2,right:t+n/2,top:e-o/2,bottom:e+o/2}}function B(t){return h(t)?.rect}function F(t,e){switch(e){case"top":return{x:t.cx,y:t.rect.top};case"bottom":return{x:t.cx,y:t.rect.bottom};case"left":return{x:t.rect.left,y:t.cy};case"right":return{x:t.rect.right,y:t.cy}}}function E(t,e,n,o,r,s=u){const i="left"===e||"right"===e,a="left"===o||"right"===o;if(i&&a){if("right"===e&&"left"===o&&t.x<n.x||"left"===e&&"right"===o&&t.x>n.x){if(x(t,n,s))return[t,n];const e=(t.x+n.x)/2;return[t,{x:e,y:t.y},{x:e,y:n.y},n]}if(e===o){if(x(t,n,s))return;const o="left"===e?Math.min(t.x,n.x)-r:Math.max(t.x,n.x)+r;return[t,{x:o,y:t.y},{x:o,y:n.y},n]}return}if(!i&&!a){if(e===o){if(m(t,n,s))return;const o="top"===e?Math.min(t.y,n.y)-r:Math.max(t.y,n.y)+r;return[t,{x:t.x,y:o},{x:n.x,y:o},n]}if(!("bottom"===e&&"top"===o&&t.y<n.y||"top"===e&&"bottom"===o&&t.y>n.y))return;if(m(t,n,s))return[t,n];const i=(t.y+n.y)/2;return[t,{x:t.x,y:i},{x:n.x,y:i},n]}if(i&&!a){const r="right"===e&&n.x>t.x||"left"===e&&n.x<t.x,s="top"===o&&t.y<n.y||"bottom"===o&&t.y>n.y;return r&&s?[t,{x:n.x,y:t.y},n]:void 0}const c="bottom"===e&&n.y>t.y||"top"===e&&n.y<t.y,f="left"===o&&t.x<n.x||"right"===o&&t.x>n.x;return c&&f?[t,{x:t.x,y:n.y},n]:void 0}function $(t,e,n,o){return"left"===e||"right"===e?[t,{x:o,y:t.y},{x:o,y:n.y},n]:[t,{x:t.x,y:o},{x:n.x,y:o},n]}function Y(t){const e=new Map,n=[];for(const o of t){if(o.isEdgeLabel)continue;const t=g(o);t&&(e.set(t.id,t),n.push({id:t.id,rect:t.rect}))}return{nodeInfoById:e,realNodeRects:n}}function X(t){const e=[],n=[];for(const o of t){const t=g(o);if(!t)continue;const r={id:t.id,rect:t.rect};o.isEdgeLabel?n.push(r):e.push(r)}return{realNodeRects:e,labelNodeRects:n}}function z(t,{includeEdgeLabels:e=!0}={}){const n=[];for(const o of t){if(o.isGroup||!e&&o.isEdgeLabel)continue;const t=o.x??0,r=o.y??0,s=o.width??0,i=o.height??0;n.push({nodeId:o.id,...T(t,r,s,i)})}return n}function P(t,e,n=u){const o=t.start,r=t.end;if(!o||!r)return;const s=e.get(o),i=e.get(r);return s&&i?{srcId:o,dstId:r,srcInfo:s,dstInfo:i,collinearX:Math.abs(s.cx-i.cx)<n,collinearY:Math.abs(s.cy-i.cy)<n}:void 0}function G(t,e,n,o=[],r=0){for(const s of n)if(!o.includes(s.id)&&L(t,e,s.rect,-r))return!0;return!1}function D(t,e,n,o,r=u,s=1e-6){const i=x(t,e,r),a=m(t,e,r),c=x(n,o,r),f=m(n,o,r);if(i&&c||a&&f)return!1;if(!i&&!a||!c&&!f)return!1;const d=i?{a:t,b:e}:{a:n,b:o},l=a?{a:t,b:e}:{a:n,b:o},h=d.a.y,g=Math.min(d.a.x,d.b.x),p=Math.max(d.a.x,d.b.x),y=l.a.x,b=Math.min(l.a.y,l.b.y),M=Math.max(l.a.y,l.b.y);if(y<g||y>p||h<b||h>M)return!1;const I=Math.abs(y-d.a.x)<s&&Math.abs(h-d.a.y)<s||Math.abs(y-d.b.x)<s&&Math.abs(h-d.b.y)<s,S=Math.abs(y-l.a.x)<s&&Math.abs(h-l.a.y)<s||Math.abs(y-l.b.x)<s&&Math.abs(h-l.b.y)<s;return!(I&&S)}function A(t,e,n,o,r=u){const s=x(t,e,r),i=m(t,e,r),a=x(n,o,r),c=m(n,o,r);return i&&c&&m(t,n,r)?M(t.y,e.y,n.y,o.y)>r:!!(s&&a&&x(t,n,r))&&M(t.x,e.x,n.x,o.x)>r}function H(t,e,n,o,{epsilon:r=u,skipDegenerateOther:s=!1}={}){for(const i of n){if(i===o||i.isLayoutOnly)continue;const n=i.points;if(n&&!(n.length<2))for(let o=0;o<n.length-1;o++){const i=n[o],a=n[o+1];if((!s||!p(i,a,r))&&(D(t,e,i,a,r)||A(t,e,i,a,r)))return!0}}return!1}function j(t,e,n,o,r=u){const s=x(t,e,r),i=m(t,e,r),a=x(n,o,r),c=m(n,o,r);if(!(s&&c||i&&a))return!1;const f=s?{a:t,b:e}:{a:n,b:o},d=s?{a:n,b:o}:{a:t,b:e},l=f.a.y,h=Math.min(f.a.x,f.b.x),g=Math.max(f.a.x,f.b.x),p=d.a.x,y=Math.min(d.a.y,d.b.y),b=Math.max(d.a.y,d.b.y);return p>h+r&&p<g-r&&l>y+r&&l<b-r}function _(t,e,n){const o=Math.min(e,n),r=Math.max(e,n);return t>o+u&&t<r-u}function V(t,e,n){return m(t,e)&&m(e,n)?_(e.y,t.y,n.y):!(!x(t,e)||!x(e,n))&&_(e.x,t.x,n.x)}function W(t){let e=!1;const n=[];for(let o=0;o<t.length;o++){const r=n[n.length-1],s=t[o],i=o+1<t.length?t[o+1]:void 0;if(r&&i){if(p(r,i)){o++,e=!0;continue}if(V(r,s,i)){e=!0;continue}}n.push(s)}return{points:n,changed:e}}function K(t){const e=[t[0]];for(let n=1;n<t.length;n++){const o=e[e.length-1],r=t[n];if(!m(o,r)&&!x(o,r)){const t=e.length>=2?e[e.length-2]:void 0,n=!!t&&m(t,o)?{x:o.x,y:r.y}:{x:r.x,y:o.y};e.push(n)}e.push(r)}const n=[];for(const t of e){const e=n[n.length-1];e&&p(e,t)||n.push(t)}return n}function q(t){if(t.length<3)return t;let e=[...t];for(let t=0;t<32;t++){const t=W(e);if(e=t.points,!t.changed)break}return e}n(h,"measuredNodeRect"),n(g,"nodeBoundsInfoFor"),n(p,"samePoint"),n(m,"sameX"),n(x,"sameY"),n(y,"isHorizontalSegment"),n(b,"isVerticalSegment"),n(M,"overlapLength"),n(I,"sameAxisSegmentOverlapLength"),n(S,"orthogonalSegmentsForPoints"),n(w,"countOrthogonalBends"),n(v,"dedupeConsecutivePoints"),n(C,"classifyThreeSegmentRoute"),n(L,"segmentBoundsOverlapRect"),n(k,"pointInsideRect"),n(O,"rectContainsRect"),n(R,"rectsOverlap"),n(N,"inflateRect"),n(T,"rectFromCenterSize"),n(B,"rectOfNodeBounds"),n(F,"portForRectSide"),n(E,"buildOrthogonalPortPath"),n($,"buildSameSideTrackPath"),n(Y,"collectRealNodeBounds"),n(X,"collectNodeRectEntries"),n(z,"collectLayoutNodeRects"),n(P,"getNodePairGeometry"),n(G,"segmentHitsAnyRect"),n(D,"orthogonalSegmentsCross"),n(A,"sameAxisSegmentsOverlap"),n(H,"segmentConflictsWithAnyEdge"),n(j,"orthogonalSegmentsStrictlyCross"),n(_,"strictlyBetween"),n(V,"isCollinearIntermediate"),n(W,"simplifyPolylineOnce"),n(K,"orthogonalizePolyline"),n(q,"simplifyPolyline");var U=.001;function J(t,e,n){const o=t;if(o.isLayoutOnly||!o.points||o.points.length<n)return;const r=o.start?e.get(o.start):void 0,s=o.end?e.get(o.end):void 0;return{edge:o,points:o.points,srcRect:r?B(r):void 0,dstRect:s?B(s):void 0}}function Z(t,e,n){if(x(t,e,U)){return{x:t.x<n.left?n.left:n.right,y:t.y}}if(m(t,e,U)){const e=t.y<n.top?n.top:n.bottom;return{x:t.x,y:e}}return{x:Math.min(n.right,Math.max(n.left,t.x)),y:Math.min(n.bottom,Math.max(n.top,t.y))}}function Q(t,e,n){const o=n?1:-1;let r=n?0:t.length-1;for(;r>=0&&r<t.length&&k(t[r],e,.5);)r+=o;if(r<0||r>=t.length)return t;const s=r-o;if(s<0||s>=t.length)return t;const i=Z(t[r],t[s],e);return n?[i,...t.slice(r)]:[...t.slice(0,r+1),i]}function tt(t,e){for(const n of t){const t=J(n,e,2);if(!t)continue;let o=[...t.points];t.srcRect&&(o=Q(o,t.srcRect,!0)),t.dstRect&&(o=Q(o,t.dstRect,!1)),o=q(K(o)),o=lt(o,t.srcRect,t.dstRect),t.edge.points=q(K(o))}}function et(t,e,n,o=!1){if(x(t,e,U)){if(e.y<n.top-U||e.y>n.bottom+U)return e;if(o){if(t.x<n.left-U)return{x:n.left,y:t.y};if(t.x>n.right+U)return{x:n.right,y:t.y}}return{x:Math.abs(e.x-n.left)<=Math.abs(e.x-n.right)?n.left:n.right,y:t.y}}if(m(t,e,U)){if(e.x<n.left-U||e.x>n.right+U)return e;if(o){if(t.y<n.top-U)return{x:t.x,y:n.top};if(t.y>n.bottom+U)return{x:t.x,y:n.bottom}}const r=Math.abs(e.y-n.top)<=Math.abs(e.y-n.bottom);return{x:t.x,y:r?n.top:n.bottom}}return e}function nt(t,e,n){const o=t[e];for(let r=e+n;r>=0&&r<t.length;r+=n){const e=t[r];if(!p(e,o,U))return e}return t[e+n]}function ot(t,e){const n=t+4,o=e-4;return n<=o?{lo:n,hi:o}:{lo:(t+e)/2,hi:(t+e)/2}}function rt(t,e,n){const{lo:o,hi:r}=ot(e,n);return Math.min(r,Math.max(o,t))}function st(t){const e=Math.max(...t.map(t=>t.lo)),n=Math.min(...t.map(t=>t.hi));if(!(e>n))return{lo:e,hi:n}}function it(t,e){return"left"===e||"right"===e?ot(t.top,t.bottom):ot(t.left,t.right)}function at(t,e,n){const o=t.y>=n.top-U&&t.y<=n.bottom+U,r=t.x>=n.left-U&&t.x<=n.right+U;if(x(t,e,U)&&o){if(Math.abs(t.x-n.left)<U)return"left";if(Math.abs(t.x-n.right)<U)return"right"}if(m(t,e,U)&&r){if(Math.abs(t.y-n.top)<U)return"top";if(Math.abs(t.y-n.bottom)<U)return"bottom"}}function ct(t){return"left"===t||"right"===t}function ft(t,e,n,o,r){const s=[],i=n?at(t,e,n):void 0,a=o?at(e,t,o):void 0;return n&&i&&ct(i)===r&&s.push(it(n,i)),o&&a&&ct(a)===r&&s.push(it(o,a)),s.length>0?st(s):void 0}function dt(t,e,n,o,r){const s=ft(t,e,n,o,r);if(!s)return;const i=r?t.y:t.x,a=Math.min(s.hi,Math.max(s.lo,i));return Math.abs(a-i)<U?void 0:r?[{x:t.x,y:a},{x:e.x,y:a}]:[{x:a,y:t.y},{x:a,y:e.y}]}function lt(t,e,n){if(2!==t.length)return t;const[o,r]=t;return x(o,r,U)?dt(o,r,e,n,!0)??t:m(o,r,U)?dt(o,r,e,n,!1)??t:t}function ut(t,e,n){return ct(n)?{x:t.x,y:rt(t.y,e.top,e.bottom)}:{x:rt(t.x,e.left,e.right),y:t.y}}function ht(t,e,n,o,r,s){const i=t.map(t=>({...t}));for(let a=e;a>=0&&a<t.length;a+=n){const e=t[a];if(s&&!x(e,o,U))break;if(!s&&!m(e,o,U))break;s?i[a].y=r.y:i[a].x=r.x}return i}function gt(t,e,n){if(t.length<2)return t;const o=n?0:t.length-1,r=n?1:-1,s=t[o],i=nt(t,o,r);if(!i)return t;const a=at(s,i,e);if(!a)return t;const c=ct(a),f=ut(s,e,a);return p(s,f,U)?t:ht(t,o,r,s,f,c)}function pt(t,e,n){const o=Math.min(t.x,e.x)>=n.left-U&&Math.max(t.x,e.x)<=n.right+U,r=Math.min(t.y,e.y)>=n.top-U&&Math.max(t.y,e.y)<=n.bottom+U;return Math.abs(t.y-n.top)<U&&Math.abs(e.y-n.top)<U&&o?"top":Math.abs(t.y-n.bottom)<U&&Math.abs(e.y-n.bottom)<U&&o?"bottom":Math.abs(t.x-n.left)<U&&Math.abs(e.x-n.left)<U&&r?"left":Math.abs(t.x-n.right)<U&&Math.abs(e.x-n.right)<U&&r?"right":void 0}function mt(t,e,n,o){switch(t){case"top":return m(e,n,U)&&n.y<o.top-U;case"bottom":return m(e,n,U)&&n.y>o.bottom+U;case"left":return x(e,n,U)&&n.x<o.left-U;case"right":return x(e,n,U)&&n.x>o.right+U}}function xt(t,e,n){if(t.length<3)return t;if(n){const n=pt(t[0],t[1],e);return n&&mt(n,t[1],t[2],e)?t.slice(1):t}const o=t.length-1,r=pt(t[o-1],t[o],e);return r&&mt(r,t[o-1],t[o-2],e)?t.slice(0,o):t}function yt(t,e,n){let o=t;if(e){const t=nt(o,0,1);if(t){const n=et(t,o[0],e);n!==o[0]&&(o=[n,...o.slice(1)])}o=xt(o,e,!0)}if(n){const t=o.length-1,e=nt(o,t,-1);if(e){const r=et(e,o[t],n,!0);r!==o[t]&&(o=[...o.slice(0,t),r])}o=xt(o,n,!1)}const r=lt(o,e,n);return r!==o||2===o.length?r:(e&&(o=gt(o,e,!0)),n&&(o=gt(o,n,!1)),o)}function bt(t,e){for(const n of t){const t=J(n,e,2);if(!t)continue;const o=yt(v(t.points,U),t.srcRect,t.dstRect);if(o.length<3){t.edge.points=o;continue}const r=[o[0],{...o[0]},...o.slice(1,-1),o[o.length-1],{...o[o.length-1]}];t.edge.points=r}}function Mt(t){return new Map(t.map(t=>[t.id,t]))}function It(t,e){let n=t.parentId,o=null;for(;n;){const t=e.get(n);if(!t?.isGroup)break;o=t.id,n=t.parentId}return o}function St(t,e){let n=0,o=t.parentId;for(;o;){const t=e.get(o);if(!t?.isGroup)break;n++,o=t.parentId}return n}function wt(t){let e=1/0,n=-1/0,o=1/0,r=-1/0;for(const s of t){const t=s.x,i=s.y;if("number"!=typeof t||"number"!=typeof i)continue;const a=s.width??0,c=s.height??0;e=Math.min(e,t-a/2),n=Math.max(n,t+a/2),o=Math.min(o,i-c/2),r=Math.max(r,i+c/2)}return e===1/0||o===1/0?null:{minX:e,maxX:n,minY:o,maxY:r}}function vt(t,e){const n=t.padding??20;t.x=(e.minX+e.maxX)/2,t.y=(e.minY+e.maxY)/2,t.width=Math.max(0,e.maxX-e.minX)+n,t.height=Math.max(0,e.maxY-e.minY)+n}function Ct(t){const e=Mt(t),n=t.filter(t=>t.isGroup&&t.parentId).sort((t,n)=>St(n,e)-St(t,e));for(const e of n){const n=wt(t.filter(t=>t.parentId===e.id));n&&vt(e,n)}}function Lt(t,e){const o=t.nodes??[],r=t.edges??[],s=o.filter(t=>!t.isGroup);let i=1/0,a=-1/0;for(const t of s){const n=t[e];"number"==typeof n&&(i=Math.min(i,n),a=Math.max(a,n))}if(!Number.isFinite(i)||!Number.isFinite(a))return!1;const c=n(t=>i+a-t,"mirror");for(const t of o){const n=t[e];"number"==typeof n&&(t[e]=c(n));const o=t.groupTitleRect;o&&(t.groupTitleRect="x"===e?{...o,left:c(o.right),right:c(o.left)}:{...o,top:c(o.bottom),bottom:c(o.top)})}for(const t of r)for(const n of t.points??[])n[e]=c(n[e]);return!0}function kt(t){return!(t.nodes??[]).some(t=>!t.isGroup)||Lt(t,"y")}function Ot(t,e="LR"){const n=t.nodes??[],o=t.edges??[],r=n.filter(t=>!t.isGroup);let s=1/0,i=1/0;for(const t of r){const e=t.x??0,n=t.y??0;e<s&&(s=e),n<i&&(i=n)}if(!Number.isFinite(s)||!Number.isFinite(i))return!1;const a=36;let c=0,f=0;for(const t of r)c+=t.width??0,f+=t.height??0;const d=c/r.length,l=f/r.length,u=l>0?Math.max(1,d/l):1;for(const t of r){const e=t.x??0,n=((t.y??0)-i)*u+a,o=e-s;t.x=n,t.y=o}for(const t of o)if(t.points)for(const e of t.points){const t=e.x,n=(e.y-i)*u+a,o=t-s;e.x=n,e.y=o}Ct(n);const h=n.filter(t=>t.isGroup&&!t.parentId);if(0===h.length)return"RL"===e&&Lt(t,"x"),!0;const g=Mt(n),p=new Map;for(const t of n){if(t.isGroup)continue;const e=It(t,g);if(!e)continue;const n=p.get(e)??[];n.push(t),p.set(e,n)}let m=0;for(const t of h){const e=t.padding??0;e>m&&(m=e)}const x=[];let y=1/0,b=-1/0;for(const t of h){const e=wt(p.get(t.id)??[]);e&&(y=Math.min(y,e.minX),b=Math.max(b,e.maxX),x.push({lane:t,contentTop:e.minY,contentBottom:e.maxY,centerY:(e.minY+e.maxY)/2}))}if(y===1/0||b===-1/0)return!0;const M=Math.max(0,b-y)+2*Math.max(m,10),I=a+M,S=(y+b)/2-M/2-a,w=S+I/2,v=Math.max(m,a);x.sort((t,e)=>t.centerY-e.centerY);for(let t=0;t<x.length;t++){const e=x[t];let n,o;if(0===t)n=e.contentTop-v;else{n=(x[t-1].contentBottom+e.contentTop)/2}if(t===x.length-1)o=e.contentBottom+v;else{const n=x[t+1];o=(e.contentBottom+n.contentTop)/2}const r=Math.max(0,o-n),s=(n+o)/2;e.lane.x=w,e.lane.y=s,e.lane.width=I,e.lane.height=r,e.lane.swimlaneContentTop=e.contentTop,e.lane.groupTitleRect={left:S,right:S+a,top:n,bottom:o}}return"RL"===e&&Lt(t,"x"),!0}n(J,"endpointContextFor"),n(Z,"segmentEnterPoint"),n(Q,"clipEndpoint"),n(tt,"clipEdgeEndpointsToNodeBoundaries"),n(et,"snapEndpointToBoundary"),n(nt,"firstDistinctAdjacent"),n(ot,"cornerClearanceRange"),n(rt,"clampToCornerClearance"),n(st,"intersectRanges"),n(it,"clearanceRangeForSide"),n(at,"terminalSideForSegment"),n(ct,"isHorizontalSide"),n(ft,"straightClearanceRange"),n(dt,"clearStraightEndpointCornerAxis"),n(lt,"clearStraightEndpointCornerConnections"),n(ut,"cornerClearedEndpoint"),n(ht,"moveCollinearEndpointRun"),n(gt,"clearEndpointCornerConnection"),n(pt,"borderSideForSegment"),n(mt,"leavesOutward"),n(xt,"collapseOwnBorderStub"),n(yt,"snapAndCollapseEndpoints"),n(bt,"prepareEdgeEndpointsForRenderer"),n(Mt,"buildNodeMap"),n(It,"resolveTopLevelGroupId"),n(St,"groupDepth"),n(wt,"boundsForChildren"),n(vt,"applyGroupBounds"),n(Ct,"recomputeNestedGroupBounds"),n(Lt,"mirrorAxis"),n(kt,"applyBtDirectionTransform"),n(Ot,"applyLrDirectionTransform");var Rt=1e-6,Nt=[0,8,-8,16,-16];function Tt(t,e){const{nodeInfoById:n,realNodeRects:o}=Y(e);for(const e of t){if(e.isLayoutOnly)continue;const r=e.points;if(!r||r.length<4)continue;const s=C(v(r,Rt),Rt);if(!s)continue;const{p3:i}=s,a="HVH"===s.kind,c=P(e,n,Rt);if(!c)continue;const{srcId:f,dstId:d,srcInfo:l,dstInfo:u,collinearX:h,collinearY:g}=c;if(h||g)continue;let m;const x=l.rect;for(const n of Nt){let r,s,c;if(a){const t=u.cy>l.cy?x.bottom:x.top,e=l.cx+n;if(e<=x.left+Rt||e>=x.right-Rt)continue;r={x:e,y:t},s={x:e,y:i.y},c={x:i.x,y:i.y}}else{const t=u.cx>l.cx?x.right:x.left,e=l.cy+n;if(e<=x.top+Rt||e>=x.bottom-Rt)continue;r={x:t,y:e},s={x:i.x,y:e},c={x:i.x,y:i.y}}const h=p(r,s,Rt),g=p(s,c,Rt);if(h&&g)continue;if(!h&&G(r,s,o,[f],1))continue;if(!g&&G(s,c,o,[d],1))continue;const y=!h&&H(r,s,t,e,{epsilon:Rt,skipDegenerateOther:!0}),b=!g&&H(s,c,t,e,{epsilon:Rt,skipDegenerateOther:!0});if(!y&&!b){m=h?[s,c]:g?[r,s]:[r,s,c];break}}m&&(e.points=m)}}function Bt(t,e){const o=.001,{realNodeRects:r,labelNodeRects:s}=X(e.values());for(const i of t){if(i.isLayoutOnly)continue;const a=i.points;if(!a||a.length<4)continue;const c=v(a,o);if(c.length<4)continue;const f=c.length-1,d=c[f],l=c[f-1],u=c[f-2],h=d.x-l.x,g=d.y-l.y,p=Math.hypot(h,g);if(p>=10||p<o)continue;const M=l.x-u.x,I=l.y-u.y;if(Math.hypot(M,I)<o)continue;const S=y(l,d,o),w=b(l,d,o),C=y(u,l,o),L=b(u,l,o);if(!(S&&L||w&&C))continue;const O=i.end,R=i.start,N=O?e.get(O):void 0;if(!N)continue;const T=N.x??0,F=N.y??0,E=B(N);if(!E)continue;let $,Y;if(L){const t=I<0;$={x:T,y:u.y},Y={x:T,y:t?E.bottom:E.top}}else{const t=M>0;$={x:u.x,y:F},Y={x:t?E.right:E.left,y:F}}if(G($,Y,r,O?[O]:[],-2))continue;if(G($,Y,s,[],-2))continue;if(R){const t=e.get(R),n=t?B(t):void 0;if(n&&k($,n,2))continue}const X=n((t,e)=>`${t.x.toFixed(3)},${t.y.toFixed(3)}|${e.x.toFixed(3)},${e.y.toFixed(3)}`,"ownSegmentKey"),z=new Set;for(let t=0;t<c.length-1;t++)z.add(X(c[t],c[t+1]));const P=n((e,n)=>{for(const r of t){if(r===i)continue;if(r.isLayoutOnly)continue;const t=r.points;if(t&&!(t.length<2))for(let r=0;r<t.length-1;r++){const s=t[r],i=t[r+1];if(!z.has(X(s,i))&&j(e,n,s,i,o))return!0}}return!1},"segmentCrossesOtherEdge");if(P($,Y))continue;if(f-3>=0){const t=c[f-3];if(G(t,$,r,[R,O].filter(t=>Boolean(t)),-2))continue;if(P(t,$))continue}const D=[...c.slice(0,f-2),$,Y];i.points=D;const A=i.labelNodeId;if(A){const t=e.get(A);if(t){const e=t.width??0,n=t.height??0;if(e>0&&n>0){let r,s,i=-1;for(let t=0;t<D.length-1;t++){const a=D[t],c=D[t+1],f=Math.hypot(c.x-a.x,c.y-a.y),d=x(a,c,o),l=m(a,c,o);(d&&f>=e+2||l&&f>=n+2)&&(f>i&&(i=f,r=(a.x+c.x)/2,s=(a.y+c.y)/2))}void 0!==r&&void 0!==s&&(t.x=r,t.y=s)}}}}}n(Tt,"portSwapToLShape"),n(Bt,"collapseShortTerminalStub");var Ft=.001,Et=n(t=>"string"==typeof t?t.toUpperCase():"","upperCaseDirection"),$t=S,Yt=n((t,e)=>m(t,e,Ft)||x(t,e,Ft),"orthogonallyAligned");function Xt(t,e){const o=n((t,e)=>{const n=t.x??0,o=t.y??0,r=e.x-n,s=e.y-o;let i=(t.width??0)/2,a=(t.height??0)/2;return Math.abs(s)*i>Math.abs(r)*a?(s<0&&(a=-a),{x:n+(0===s?0:a*r/s),y:o+a}):(r<0&&(i=-i),{x:n+i,y:o+(0===r?0:i*s/r)})},"rectIntersect"),r=n((t,n)=>{const r=v(t.points??[]);if(r.length<2)return;const s=n?t.start:t.end,i=s?e.get(s):void 0,a=i?B(i):void 0;if(!i||!s||!a)return;const c=n?r[0]:r[r.length-1],f=n?r[1]:r[r.length-2],d=o(i,c);let l=c;return Yt(f,d)&&(l=f),m(d,l,Ft)?{edge:t,edgeId:String(t.id??""),nodeId:s,atStart:n,orientation:"V",coord:d.x,min:Math.min(d.y,l.y),max:Math.max(d.y,l.y),boundary:d,railEnd:l,rect:a}:x(d,l,Ft)?{edge:t,edgeId:String(t.id??""),nodeId:s,atStart:n,orientation:"H",coord:d.y,min:Math.min(d.x,l.x),max:Math.max(d.x,l.x),boundary:d,railEnd:l,rect:a}:void 0},"terminalLaneFor"),s=n((t,e)=>Math.max(0,Math.min(t.max,e.max)-Math.max(t.min,e.min)),"projectedOverlapLength"),i=n((t,e)=>{if(t.nodeId!==e.nodeId||t.orientation!==e.orientation)return!1;if("H"===t.orientation){return(Math.abs(t.boundary.x-t.rect.left)<1||Math.abs(t.boundary.x-t.rect.right)<1)&&m(t.boundary,e.boundary,1)}return(Math.abs(t.boundary.y-t.rect.top)<1||Math.abs(t.boundary.y-t.rect.bottom)<1)&&x(t.boundary,e.boundary,1)},"sameTerminalFace"),a=n((t,e)=>{if(t.nodeId!==e.nodeId||t.orientation!==e.orientation)return!1;return s(t,e)>=8&&Math.abs(t.coord-e.coord)<.5},"exactTerminalLaneConflict"),c=n((t,e)=>{if(t.nodeId!==e.nodeId||t.orientation!==e.orientation||"H"!==t.orientation||t.atStart===e.atStart)return!1;const n=s(t,e);if(n<8)return!1;const o=t.rect.bottom-t.rect.top;return!(n<o||n>2*o)&&(i(t,e)&&Math.abs(t.coord-e.coord)<16)},"nearTerminalLaneConflict"),f=n((t,e)=>{const o=v(t.edge.points??[]);if(o.length<2)return;const r="V"===t.orientation?{x:t.boundary.x+e,y:t.boundary.y}:{x:t.boundary.x,y:t.boundary.y+e},s="V"===t.orientation?{x:t.railEnd.x+e,y:t.railEnd.y}:{x:t.railEnd.x,y:t.railEnd.y+e};if(!n(()=>Math.abs(t.boundary.y-t.rect.top)<1||Math.abs(t.boundary.y-t.rect.bottom)<1?x(r,t.boundary,Ft)&&r.x>=t.rect.left+1&&r.x<=t.rect.right-1:(Math.abs(t.boundary.x-t.rect.left)<1||Math.abs(t.boundary.x-t.rect.right)<1)&&(m(r,t.boundary,Ft)&&r.y>=t.rect.top+1&&r.y<=t.rect.bottom-1),"boundaryStaysOnSameFace")())return;if(t.atStart){const e=o.length>1&&p(o[1],t.railEnd,Ft),n=o.slice(e?2:1),i=n[0];if(i&&!Yt(i,s))return;return[r,s,...n]}const i=o.length>1&&p(o[o.length-2],t.railEnd,Ft),a=o.slice(0,i?-2:-1),c=a[a.length-1];return!c||Yt(c,s)?[...a,s,r]:void 0},"shiftedCandidate"),d=n(t=>{const n=t.edge,o=v(n.points??[]);if(2!==o.length)return!1;const r=n.start,s=n.end,i=r?e.get(r):void 0,a=s?e.get(s):void 0;if(!i||!a)return!1;const c=i.x??0,f=i.y??0,d=a.x??0,l=a.y??0,[u,h]=o;return x(u,h,Ft)&&Math.abs(f-l)<1&&Math.abs(c-d)>1||m(u,h,Ft)&&Math.abs(c-d)<1&&Math.abs(f-l)>1},"laneIsStraightCollinearConnector"),l=[-7,7,-14,14,-21,21];for(let e=0;e<8;e++){const e=t.filter(t=>!t.isLayoutOnly).flatMap(t=>[r(t,!0),r(t,!1)]).filter(t=>Boolean(t));let n=!1;for(let t=0;t<e.length&&!n;t++)for(let o=t+1;o<e.length&&!n;o++){const s=e[t],i=e[o];if(s.edge===i.edge||!a(s,i)&&!c(s,i))continue;const u=!a(s,i),h=[s,i].sort((t,e)=>{const n=d(t),o=d(e);return n!==o?Number(n)-Number(o):Number(!e.atStart)-Number(!t.atStart)});for(const t of h){for(const o of l){const s=f(t,o);if(!s)continue;const i=r({...t.edge,points:s},t.atStart);if(i&&!e.some(e=>e.edge!==t.edge&&(a(i,e)||u&&c(i,e)))){t.edge.points=s,n=!0;break}}if(n)break}}if(!n)return}}function zt(t,e){const{realNodeRects:o,labelNodeRects:r}=X(e.values()),s=n((e,n)=>{const s=e.start,i=e.end,a=$t(n);if(a.length!==n.length-1)return!1;const c=[s,i].filter(t=>Boolean(t));for(const t of a){if(G(t.a,t.b,o,c,-2))return!1;if(G(t.a,t.b,r,[],-2))return!1}for(const n of t){if(n===e||n.isLayoutOnly)continue;const t=n.points;if(t&&!(t.length<2))for(const e of a)for(const n of $t(v(t))){if(I(e,n,.5)>=8)return!1;if(j(e.a,e.b,n.a,n.b,Ft))return!1}}return!0},"candidateIsSafe"),i=n((t,e)=>{if(e+4>=t.length)return;const n=t[e],o=t[e+1],r=t[e+2],s=t[e+3],i=t[e+4],a=y(n,o)&&b(o,r)&&y(r,s)&&b(s,i)&&m(n,s,Ft)&&m(n,i,Ft)&&m(o,r,Ft)&&(o.x-n.x)*(s.x-r.x)<0,c=b(n,o)&&y(o,r)&&b(r,s)&&y(s,i)&&x(n,s,Ft)&&x(n,i,Ft)&&x(o,r,Ft)&&(o.y-n.y)*(s.y-r.y)<0;if(a||c)return v([...t.slice(0,e+1),i,...t.slice(e+5)]);if(e+5>=t.length)return;const f=t[e+5],d=b(n,o)&&y(o,r)&&b(r,s)&&y(s,i)&&b(i,f)&&m(n,i,Ft)&&m(n,f,Ft)&&m(r,s,Ft)&&(r.x-o.x)*(i.x-s.x)<0,l=y(n,o)&&b(o,r)&&y(r,s)&&b(s,i)&&y(i,f)&&x(n,i,Ft)&&x(n,f,Ft)&&x(r,s,Ft)&&(r.y-o.y)*(i.y-s.y)<0;return d||l?v([...t.slice(0,e+1),f,...t.slice(e+6)]):void 0},"withoutDogleg");for(let e=0;e<8;e++){let e=!1;for(const n of t){if(n.isLayoutOnly)continue;const t=v(n.points??[]);for(let o=0;o<=t.length-5;o++){const r=i(t,o);if(r&&s(n,r)){n.points=r,e=!0;break}}if(e)break}if(!e)return}}function Pt(t,e){const{realNodeRects:o,labelNodeRects:r}=X(e.values()),s=t.filter(t=>!t.isLayoutOnly),i=n((t,e,n)=>v(t===e?n??[]:t.points??[]),"pointsFor"),a=n((t,e)=>{let n=0;for(let o=0;o<s.length;o++){const r=$t(i(s[o],t,e));for(let a=o+1;a<s.length;a++){const o=$t(i(s[a],t,e));for(const t of r)for(const e of o)j(t.a,t.b,e.a,e.b,Ft)&&n++}}return n},"strictCrossingCount"),c=n(t=>{const e=$t(t);if(3!==e.length)return;const n=e[1];return e[0].horizontal!==n.horizontal&&e[2].horizontal!==n.horizontal?{index:n.index,horizontal:n.horizontal,vertical:n.vertical,segment:n}:void 0},"middleRail"),f=n((t,e)=>{const n=[t.start,t.end].filter(t=>Boolean(t));return o.filter(t=>{if(n.includes(t.id))return!1;const o=t.rect;if(e.horizontal){return M(e.a.x,e.b.x,o.left,o.right)>=8&&e.a.y>=o.top-2&&e.a.y<=o.bottom+2}return M(e.a.y,e.b.y,o.top,o.bottom)>=8&&e.a.x>=o.left-2&&e.a.x<=o.right+2})},"blockingRectsFor"),d=n((t,e,n)=>{const o=t.map(t=>({...t}));if(e.horizontal)o[e.index].y=n,o[e.index+1].y=n;else{if(!e.vertical)return;o[e.index].x=n,o[e.index+1].x=n}const r=q(v(o));return $t(r).length===r.length-1?r:void 0},"candidateByMovingRail"),l=n((t,e,n)=>{const c=[t.start,t.end].filter(t=>Boolean(t)),f=$t(e);if(f.length!==e.length-1)return!1;for(const t of f){if(G(t.a,t.b,o,c,-2))return!1;if(G(t.a,t.b,r,[],-2))return!1}for(const e of s)if(e!==t)for(const t of f)for(const n of $t(i(e)))if(I(t,n,.5)>=8)return!1;return a(t,e)<=n},"candidateIsSafe");for(let t=0;t<8;t++){const t=a();let e=!1;for(const n of s){const o=i(n),r=c(o);if(!r)continue;const s=f(n,r.segment);if(0===s.length)continue;const a=r.horizontal?[Math.min(...s.map(t=>t.rect.top))-20,Math.max(...s.map(t=>t.rect.bottom))+20]:[Math.min(...s.map(t=>t.rect.left))-20,Math.max(...s.map(t=>t.rect.right))+20];for(const s of a){const i=d(o,r.segment,s);if(i&&l(n,i,t)){n.points=i,e=!0;break}}if(e)break}if(!e)return}}function Gt(t,e,o){const r=n(t=>{const e=t.groupTitleRect;if(e&&"number"==typeof e.left&&"number"==typeof e.right&&"number"==typeof e.top&&"number"==typeof e.bottom&&Number.isFinite(e.left)&&Number.isFinite(e.right)&&Number.isFinite(e.top)&&Number.isFinite(e.bottom)&&!(e.right<=e.left)&&!(e.bottom<=e.top))return{left:e.left,right:e.right,top:e.top,bottom:e.bottom}},"validTitleRect"),s=n(t=>{if(!t.isGroup||t.parentId)return;const e=Et(t.direction??o);if("LR"===e||"RL"===e||"BT"===e)return;const n=r(t),s=t.y,i=t.height;if(!n||"number"!=typeof s||"number"!=typeof i||!Number.isFinite(s)||!Number.isFinite(i)||i<=0)return;const a=n.right-n.left,c=n.bottom-n.top;return c<=0||a<c?void 0:{node:t,rect:n}},"topLaneTitleFor"),i=n((t,e)=>{if(!t.horizontal)return!1;const n=t.a.y;return!(n<e.top-Ft||n>e.bottom+Ft)&&M(t.a.x,t.b.x,e.left,e.right)>=8},"horizontalSegmentIntersectsTitle"),a=[...e.values()].map(s).filter(t=>Boolean(t));if(0===a.length)return;let c=0;for(const e of t){if(e.isLayoutOnly)continue;const t=v(e.points??[]);for(const e of $t(t))for(const t of a)i(e,t.rect)&&(c=Math.max(c,t.rect.bottom-e.a.y+4))}if(!(c<=Ft))for(const t of a){const e=t.node.y,n=t.node.height;"number"!=typeof e||"number"!=typeof n||!Number.isFinite(e)||!Number.isFinite(n)||n<=0||(t.node.y=e-c/2,t.node.height=n+c,t.node.groupTitleRect={...t.rect,top:t.rect.top-c,bottom:t.rect.bottom-c})}}function Dt(t,e,o){const r=n(t=>{const e=t.groupTitleRect;if(e&&"number"==typeof e.left&&"number"==typeof e.right&&"number"==typeof e.top&&"number"==typeof e.bottom&&Number.isFinite(e.left)&&Number.isFinite(e.right)&&Number.isFinite(e.top)&&Number.isFinite(e.bottom)&&!(e.right<=e.left)&&!(e.bottom<=e.top))return{left:e.left,right:e.right,top:e.top,bottom:e.bottom}},"validTitleRect"),s=n(t=>{if(!t.isGroup||t.parentId)return;if("LR"!==Et(t.direction??o))return;const e=r(t),n=t.x,s=t.width;if(!e||"number"!=typeof n||"number"!=typeof s||!Number.isFinite(n)||!Number.isFinite(s)||s<=0)return;const i=e.right-e.left,a=e.bottom-e.top;return i<=0||a<i?void 0:{node:t,rect:e}},"leftLaneTitleFor"),i=n((t,e)=>{if(!t.vertical)return!1;const n=t.a.x;return!(n<e.left-Ft||n>e.right+Ft)&&M(t.a.y,t.b.y,e.top,e.bottom)>=8},"verticalSegmentIntersectsTitle"),a=n((t,e)=>{if(!t.horizontal)return!1;const n=t.a.y;return!(n<e.top-Ft||n>e.bottom+Ft)&&M(t.a.x,t.b.x,e.left,e.right)>=8},"horizontalSegmentIntersectsTitle"),c=[...e.values()].map(s).filter(t=>Boolean(t));if(0===c.length)return;let f=0;for(const e of t){if(e.isLayoutOnly)continue;const t=v(e.points??[]);for(const e of $t(t))for(const t of c)if(i(e,t.rect))f=Math.max(f,t.rect.right-e.a.x+4);else if(a(e,t.rect)){const n=Math.min(e.a.x,e.b.x);f=Math.max(f,t.rect.right-n+4)}}if(!(f<=Ft))for(const t of c){const e=t.node.x,n=t.node.width;"number"!=typeof e||"number"!=typeof n||!Number.isFinite(e)||!Number.isFinite(n)||n<=0||(t.node.x=e-f/2,t.node.width=n+f,t.node.groupTitleRect={...t.rect,left:t.rect.left-f,right:t.rect.right-f})}}function At(t,e){const{realNodeRects:o}=X(e.values()),r=t.filter(t=>!t.isLayoutOnly),s=n((t,e=new Map)=>v(e.get(t)??t.points??[]),"replacementPointsFor"),i=n((t=new Map)=>{let e=0;for(let n=0;n<r.length;n++){const o=$t(s(r[n],t));for(let i=n+1;i<r.length;i++){const n=$t(s(r[i],t));for(const t of o)for(const o of n)j(t.a,t.b,o.a,o.b,Ft)&&e++}}return e},"crossingCount"),a=n((t=new Map)=>r.reduce((e,n)=>e+w(s(n,t)),0),"totalBends"),c=n(t=>{const e=s(t);if(e.length<4)return;const n=e[e.length-2],o=e[e.length-1];return y(n,o,Ft)||b(n,o,Ft)?{tailStart:n,terminal:o}:void 0},"terminalTailFor"),f=n((t,e)=>{const n=s(t);if(n.length<3)return;const o=n[0],r=n[1];let i;if(y(o,r,Ft))i={x:r.x,y:e.tailStart.y};else{if(!b(o,r,Ft))return;i={x:e.tailStart.x,y:r.y}}const a=q(v([o,r,i,e.tailStart,e.terminal]));return $t(a).length===a.length-1?a:void 0},"candidateWithDestinationTail"),d=n((t,e)=>{const n=[t.start,t.end].filter(t=>Boolean(t));for(const t of $t(e))if(G(t.a,t.b,o,n,-2))return!0;return!1},"pathHasNodeHit"),l=n((t,e,n)=>{for(const o of r)if(o!==t)for(const t of $t(e))for(const e of $t(s(o,n)))if(I(t,e,.5)>=8)return!0;return!1},"pathHasSharedTrack"),u=n((t,e,n)=>!d(t,e)&&!l(t,e,n),"candidateIsSafe"),h=n(()=>{const t=new Map;for(const n of r){const o=n.end;if(!o||!e.has(o))continue;if(s(n).length<4)continue;const r=t.get(o)??[];r.push(n),t.set(o,r)}return t},"edgesByDestination");for(let t=0;t<4;t++){const t=i();if(0===t)return;let e,n=t,o=a();for(const r of h().values())for(let s=0;s<r.length;s++)for(let d=s+1;d<r.length;d++){const l=r[s],h=r[d],g=c(l),p=c(h);if(!g||!p)continue;const m=f(l,p),x=f(h,g);if(!m||!x)continue;const y=new Map([[l,m],[h,x]]);if(!u(l,m,y)||!u(h,x,y))continue;const b=i(y),M=a(y);b>=t||(b>n||b===n&&M>=o||(e=y,n=b,o=M))}if(!e)return;for(const[t,n]of e)t.points=n}}function Ht(t,e){const{realNodeRects:o,labelNodeRects:r}=X(e.values()),s=t.filter(t=>!t.isLayoutOnly),i=n((t,e=new Map)=>v(e.get(t)??t.points??[]),"replacementPointsFor"),a=n((t=new Map)=>{let e=0;for(let n=0;n<s.length;n++){const o=$t(i(s[n],t));for(let r=n+1;r<s.length;r++){const n=$t(i(s[r],t));for(const t of o)for(const o of n)j(t.a,t.b,o.a,o.b,Ft)&&e++}}return e},"strictCrossingCount"),c=n((t=new Map)=>s.reduce((e,n)=>e+w(i(n,t)),0),"totalBends"),f=n(t=>{const n=t.start,o=t.end,r=n?e.get(n):void 0,s=o?e.get(o):void 0,i=r?B(r):void 0,a=s?B(s):void 0;return i&&a?{src:i,dst:a}:void 0},"endpointRectsFor"),d=n((t,e,n)=>{if(n.index<=0||n.index+1>=e.length-1)return;const o=f(t);if(o){if(n.vertical){const r=n.a.x,s=Math.min(o.src.left,o.dst.left),i=Math.max(o.src.right,o.dst.right),a=r<s-Ft?"left":r>i+Ft?"right":void 0;if(!a)return;return{edge:t,points:e,segmentIndex:n.index,axis:"vertical",side:a,coord:r,min:Math.min(n.a.y,n.b.y),max:Math.max(n.a.y,n.b.y)}}if(n.horizontal){const r=n.a.y,s=Math.min(o.src.top,o.dst.top),i=Math.max(o.src.bottom,o.dst.bottom),a=r<s-Ft?"top":r>i+Ft?"bottom":void 0;if(!a)return;return{edge:t,points:e,segmentIndex:n.index,axis:"horizontal",side:a,coord:r,min:Math.min(n.a.x,n.b.x),max:Math.max(n.a.x,n.b.x)}}}},"externalRailForSegment"),l=n(()=>{const t=[];for(const e of s){const n=i(e);for(const o of $t(n)){const r=d(e,n,o);r&&t.push(r)}}return t},"collectExternalRails"),u=n((t,e)=>t.edge!==e.edge&&t.axis===e.axis&&t.side===e.side&&M(t.min,t.max,e.min,e.max)>=8,"railsInteract"),h=n(t=>{const e=[],n=new Set;for(const o of t){if(n.has(o))continue;const r=[o],s=[];for(n.add(o);r.length>0;){const e=r.pop();s.push(e);for(const o of t)!n.has(o)&&u(e,o)&&(n.add(o),r.push(o))}s.length>1&&e.push(s)}return e},"connectedComponents"),g=n(t=>{const e=[];for(const n of t)e.some(t=>Math.abs(t-n.coord)<Ft)||e.push(n.coord);for(;e.length<t.length;){const n=Math.min(...e),o=Math.max(...e),r=t[0].side;e.push("left"===r||"top"===r?n-12*(t.length-e.length):o+12*(t.length-e.length))}return e},"uniqueCoordsFor"),p=n(t=>{const e=t.map(t=>t.coord),o=g(t),r=[];if(t.length<=6){const s=new Array(o.length).fill(!1),i=[],a=n(()=>{if(i.length!==t.length)for(const[t,e]of o.entries())s[t]||(s[t]=!0,i.push(e),a(),i.pop(),s[t]=!1);else i.some((t,n)=>Math.abs(t-e[n])>=Ft)&&r.push([...i])},"visit");return a(),r}for(let t=0;t<e.length;t++)for(let n=t+1;n<e.length;n++){const o=[...e];[o[t],o[n]]=[o[n],o[t]],r.push(o)}return r},"coordinateAssignmentsFor"),m=n((t,e)=>{const n=new Map;for(const[o,r]of t.entries()){const t=e[o],s=n.get(r.edge)??r.points.map(t=>({x:t.x,y:t.y}));"vertical"===r.axis?(s[r.segmentIndex].x=t,s[r.segmentIndex+1].x=t):(s[r.segmentIndex].y=t,s[r.segmentIndex+1].y=t),n.set(r.edge,s)}const o=new Map;for(const[t,e]of n){const n=q(v(e));if($t(n).length!==n.length-1)return;o.set(t,n)}return o},"replacementsForAssignment"),x=n(t=>{for(const[e,n]of t){const t=[e.start,e.end].filter(t=>Boolean(t));for(const e of $t(n)){if(G(e.a,e.b,o,t,-2))return!1;if(G(e.a,e.b,r,[],-2))return!1}}for(let e=0;e<s.length;e++){const n=s[e],o=t.has(n),r=$t(i(n,t));for(let n=e+1;n<s.length;n++){const e=s[n];if(!o&&!t.has(e))continue;const a=$t(i(e,t));for(const t of r)for(const e of a)if(I(t,e,.5)>=8)return!1}}return!0},"candidateIsSafe");for(let t=0;t<4;t++){const t=a();if(0===t)return;let e,n=t,o=c(),r=Number.POSITIVE_INFINITY;for(const s of h(l()))for(const i of p(s)){const f=m(s,i);if(!f||!x(f))continue;const d=a(f);if(d>=t)continue;const l=c(f),u=s.reduce((t,e,n)=>t+Math.abs(i[n]-e.coord),0);d>n||d===n&&(l>o||l===o&&u>=r)||(e=f,n=d,o=l,r=u)}if(!e)return;for(const[t,n]of e)t.points=n}}function jt(t,e){const{realNodeRects:o,labelNodeRects:r}=X(e.values()),s=t.filter(t=>!t.isLayoutOnly),i=n((t,e,n)=>v(t===e?n??[]:t.points??[]),"pointsFor"),a=n(t=>$t(t).reduce((t,e)=>{const n=e.a.x-e.b.x,o=e.a.y-e.b.y;return t+Math.hypot(n,o)},0),"pathLength"),c=n((t,e)=>{let n=0;for(let o=0;o<s.length;o++){const r=$t(i(s[o],t,e));for(let a=o+1;a<s.length;a++){const o=$t(i(s[a],t,e));for(const t of r)for(const e of o)j(t.a,t.b,e.a,e.b,Ft)&&n++}}return n},"strictCrossingCount"),f=n((t,e)=>{if(t.horizontal){const n=t.a.y;return(Math.abs(n-e.top)<1||Math.abs(n-e.bottom)<1)&&M(t.a.x,t.b.x,e.left,e.right)>=8}if(t.vertical){const n=t.a.x;return(Math.abs(n-e.left)<1||Math.abs(n-e.right)<1)&&M(t.a.y,t.b.y,e.top,e.bottom)>=8}return!1},"segmentRunsAlongRectBorder"),d=n(t=>{const n=[t.start,t.end].filter(t=>Boolean(t)),o=[];for(const t of n){const n=e.get(t),r=n?B(n):void 0;r&&o.push(r)}return o},"endpointRectsFor"),l=n((t,e)=>{if(e+3>=t.length)return[];const n=t[e],o=t[e+1],r=t[e+2],s=t[e+3],i=y(n,o,Ft)&&b(o,r,Ft)&&y(r,s,Ft),a=b(n,o,Ft)&&y(o,r,Ft)&&b(r,s,Ft);if(!i&&!a)return[];if(!(i?Math.sign(o.x-n.x)!==Math.sign(s.x-r.x):Math.sign(o.y-n.y)!==Math.sign(s.y-r.y)))return[];const c=m(n,s,Ft)||x(n,s,Ft)?[]:[{x:n.x,y:s.y},{x:s.x,y:n.y}],f=0===c.length?[[...t.slice(0,e+1),...t.slice(e+3)]]:c.map(n=>[...t.slice(0,e+1),n,...t.slice(e+3)]),d=new Set;return f.map(t=>q(v(t))).filter(t=>{if($t(t).length!==t.length-1)return!1;if(!t.some(t=>p(t,s,Ft)))return!1;const e=t.map(t=>`${t.x.toFixed(3)},${t.y.toFixed(3)}`).join("|");return!d.has(e)&&(d.add(e),!0)})},"shortcutCandidatesAt"),u=n((t,e,n)=>{const a=[t.start,t.end].filter(t=>Boolean(t)),l=d(t);for(const t of $t(e)){if(G(t.a,t.b,o,a,-2))return!1;if(G(t.a,t.b,r,[],-2))return!1;if(l.some(e=>f(t,e)))return!1}for(const n of s)if(n!==t)for(const t of $t(e))for(const e of $t(i(n)))if(I(t,e,.5)>=8)return!1;return c(t,e)<=n},"candidateIsSafe");for(let t=0;t<8;t++){const t=c();let e,n,o=t,r=Number.POSITIVE_INFINITY,f=Number.POSITIVE_INFINITY;for(const d of s){const s=i(d),h=w(s,Ft),g=a(s);for(let i=0;i<=s.length-4;i++)for(const p of l(s,i)){const s=w(p,Ft),i=a(p);if(!(s<h||s===h&&i<g-Ft)||!u(d,p,t))continue;const l=c(d,p);l>o||l===o&&(s>r||s===r&&i>=f)||(e=d,n=p,o=l,r=s,f=i)}}if(!e||!n)return;e.points=n}}function _t(t,e){const o=20,r=[];for(const t of e.values()){if(t.isGroup||t.isEdgeLabel)continue;const e=t.x??0,n=t.y??0,o=B(t);o&&r.push({id:String(t.id??""),cx:e,cy:n,rect:o})}if(0===r.length)return;const s=new Map(r.map(t=>[t.id,t])),i=r.map(t=>({id:t.id,rect:t.rect})),a=["top","bottom","left","right"],c={top:Math.min(...r.map(t=>t.rect.top))-o,bottom:Math.max(...r.map(t=>t.rect.bottom))+o,left:Math.min(...r.map(t=>t.rect.left))-o,right:Math.max(...r.map(t=>t.rect.right))+o},f=t.filter(t=>!t.isLayoutOnly),d=new Map(f.map((t,e)=>[t,e])),l=n(t=>{const e="left"===t||"top"===t?-1:1,n=[];for(let r=0;r<=2;r++)n.push(c[t]+e*o*r);return n},"outwardTracksForSide"),u=n((t,e=new Map)=>v(e.get(t)??t.points??[]),"replacementPointsFor"),h=n((t,e)=>{let n=0;for(const o of t)for(const t of e)j(o.a,o.b,t.a,t.b,Ft)&&n++;return n},"crossingCountBetweenSegments"),g=n((t,e)=>h($t(t),$t(e)),"crossingCountBetweenPaths"),p=n((t=new Map)=>{let e=0;const o=[],r=new Set,s=[],i=n(t=>{r.has(t)||(r.add(t),s.push(t))},"addEdge");for(let n=0;n<f.length;n++){const r=f[n],s=u(r,t);for(let a=n+1;a<f.length;a++){const n=f[a],c=g(s,u(n,t));c>0&&(e+=c,o.push({first:r,second:n,count:c}),i(r),i(n))}}return s.sort((t,e)=>(d.get(t)??0)-(d.get(e)??0)),{count:e,pairs:o,edgeSet:r,edges:s}},"crossingSnapshot"),m=n((t,e)=>{const n=new Set(e.keys());if(0===n.size)return t.count;let o=0;for(const e of t.pairs)(n.has(e.first)||n.has(e.second))&&(o+=e.count);let r=0;for(let t=0;t<f.length;t++){const o=f[t],s=n.has(o),i=u(o,e);for(let o=t+1;o<f.length;o++){const t=f[o];(s||n.has(t))&&(r+=g(i,u(t,e)))}}return t.count-o+r},"crossingCountWithReplacements"),x=n(t=>{const e=new Map;for(const n of t.pairs){const t=e.get(n.first)??new Set;t.add(n.second),e.set(n.first,t);const o=e.get(n.second)??new Set;o.add(n.first),e.set(n.second,o)}const n=[],o=new Set;for(const r of t.edges){if(o.has(r))continue;const t=[r],s=[];for(o.add(r);t.length>0;){const n=t.pop();s.push(n);for(const r of e.get(n)??[])o.has(r)||(o.add(r),t.push(r))}s.sort((t,e)=>(d.get(t)??0)-(d.get(e)??0)),s.length>1&&n.push(s)}return n},"crossingComponents"),M=n(t=>[t.start,t.end].filter(t=>Boolean(t)),"endpointIdsFor"),S=n(t=>{const e=[];for(const n of x(t)){const t=new Set(n),o=new Set(n.flatMap(t=>M(t))),r=[...n];for(const e of f)t.has(e)||M(e).some(t=>o.has(t))&&r.push(e);r.sort((t,e)=>(d.get(t)??0)-(d.get(e)??0)),e.push(r)}return e},"pairSearchGroups"),C=n((t,e,n)=>m(t,new Map([[e,n]])),"crossingCountWithSingleReplacement"),L=n(t=>{const e=new Map;for(const n of t.pairs)e.set(n.first,(e.get(n.first)??0)+n.count),e.set(n.second,(e.get(n.second)??0)+n.count);return e},"currentCrossingsByEdge"),k=n(t=>t.slice(1).reduce((e,n,o)=>{const r=t[o];return e+Math.abs(n.x-r.x)+Math.abs(n.y-r.y)},0),"pathLength"),O=n((t=new Map)=>f.reduce((e,n)=>e+w(u(n,t)),0),"totalBends"),R=n((t=new Map)=>f.reduce((e,n)=>e+k(u(n,t)),0),"totalLength"),N=n((t,e,n=new Map)=>{const o=$t(e);for(const e of f)if(e!==t)for(const t of o)for(const o of $t(u(e,n)))if(I(t,o,.5)>=8)return!0;return!1},"pathHasSegmentConflict"),T=n((t,e)=>{const n=[t.start,t.end].filter(t=>Boolean(t));for(const t of $t(e))if(G(t.a,t.b,i,n,-2))return!0;return!1},"pathHitsNode"),Y=n((t,e)=>{const n=q(v(e));$t(n).length===n.length-1&&t.push(n)},"pushOrthogonalCandidate"),X=n(t=>"left"===t||"right"===t,"sideIsHorizontal"),z=n((t,e,n)=>{switch(e){case"left":return Math.min(t.x,n.x)-o;case"right":return Math.max(t.x,n.x)+o;case"top":return Math.min(t.y,n.y)-o;case"bottom":return Math.max(t.y,n.y)+o}},"localTrackForSameSide"),P=n((t,e,n,r)=>{const s="left"===n||"top"===n?-1:1,i=[z(e,n,r),c[n]];for(const a of i)for(let i=0;i<=2;i++)Y(t,$(e,n,r,a+s*o*i))},"addSameSideCandidates"),D=n((t,e,n,o,r)=>{for(const s of l(n))for(const n of l(r))Y(t,[e,{x:s,y:e.y},{x:s,y:n},{x:o.x,y:n},o])},"addHorizontalToVerticalCandidates"),A=n((t,e,n,o,r)=>{for(const s of l(n))for(const n of l(r))Y(t,[e,{x:e.x,y:s},{x:n,y:s},{x:n,y:o.y},o])},"addVerticalToHorizontalCandidates"),H=n((t,e,n,o,r)=>{const s=[...l("top"),...l("bottom")];for(const i of l(n))for(const n of l(r))for(const r of s)Y(t,[e,{x:i,y:e.y},{x:i,y:r},{x:n,y:r},{x:n,y:o.y},o])},"addHorizontalPairCandidates"),_=n((t,e,n,o,r)=>{const s=[...l("left"),...l("right")];for(const i of l(n))for(const n of l(r))for(const r of s)Y(t,[e,{x:e.x,y:i},{x:r,y:i},{x:r,y:n},{x:o.x,y:n},o])},"addVerticalPairCandidates"),V=n(t=>{const e=new Set;return t.map(t=>v(t)).filter(t=>{const n=t.map(t=>`${t.x.toFixed(3)},${t.y.toFixed(3)}`).join("|");return!(e.has(n)||t.length<2)&&(e.add(n),!0)})},"dedupeCandidatePaths"),W=n((t,e,n,r)=>{const s=[],i=E(t,e,n,r,o,Ft);i&&Y(s,i),e===r&&P(s,t,e,n);const a=X(e),c=X(r);return a&&!c?D(s,t,e,n,r):!a&&c?A(s,t,e,n,r):a?H(s,t,e,n,r):_(s,t,e,n,r),V(s)},"buildCandidatesForSides"),K=n((t,e,n,o)=>{const r=[...l("left"),...l("right")],s=[...l("top"),...l("bottom")];for(const i of a){const a=F(o,i),c="top"===i||"bottom"===i?l(i):s;for(const o of r){Y(t,[e,n,{x:o,y:n.y},{x:o,y:a.y},a]);for(const r of c)Y(t,[e,n,{x:o,y:n.y},{x:o,y:r},{x:a.x,y:r},a])}}},"addVerticalDepartureOuterTrackCandidates"),U=n((t,e,n,o)=>{const r=[...l("left"),...l("right")],s=[...l("top"),...l("bottom")];for(const i of a){const a=F(o,i),c="left"===i||"right"===i?l(i):r;for(const o of s){Y(t,[e,n,{x:n.x,y:o},{x:a.x,y:o},a]);for(const r of c)Y(t,[e,n,{x:n.x,y:o},{x:r,y:o},{x:r,y:a.y},a])}}},"addHorizontalDepartureOuterTrackCandidates"),J=n(t=>{const e=t.start,n=t.end,o=n?s.get(n):void 0;if(!e||!o)return[];const r=v(t.points??[]);if(r.length<4)return[];const i=r[0],a=r[1],c=[];return b(i,a,Ft)?K(c,i,a,o):y(i,a,Ft)&&U(c,i,a,o),c},"terminalPreservingOuterTrackCandidates"),Z=n(t=>{const e=t.start,n=t.end,o=e?s.get(e):void 0,r=n?s.get(n):void 0;if(!o||!r)return[];const i=[];for(const t of a){const e=F(o,t);for(const n of a)i.push(...W(e,t,F(r,n),n))}return i.push(...J(t)),i},"candidatePathsFor"),Q=n(()=>new Map(f.map(t=>[t,$t(u(t))])),"currentSegmentsByEdge"),tt=n((t,e,n)=>{const o=new Set;for(const r of f){if(r===t)continue;const s=n.get(r)??$t(u(r));e.some(t=>s.some(e=>I(t,e,.5)>=8))&&o.add(r)}return o},"sharedTrackConflictsFor"),et=n((t,e,n,o)=>{const r=new Set;return Z(t).map(t=>q(v(t))).filter(e=>{if(T(t,e))return!1;const n=e.map(t=>`${t.x.toFixed(3)},${t.y.toFixed(3)}`).join("|");return!(r.has(n)||e.length<2)&&(r.add(n),!0)}).map(r=>{const s=$t(r);let i=0;for(const e of f)e!==t&&(i+=h(s,n.get(e)??$t(u(e))));return{candidate:r,candidateSegments:s,crossings:e.count-(o.get(t)??0)+i,bends:w(r,Ft),totalBends:w(r),length:k(r)}}).filter(({crossings:t})=>t<=e.count).sort((t,e)=>t.crossings-e.crossings||t.bends-e.bends||t.length-e.length).slice(0,48).map(e=>({path:e.candidate,segments:e.candidateSegments,sharedTrackConflicts:tt(t,e.candidateSegments,n),totalBends:e.totalBends,length:e.length}))},"pairCandidatesFor"),nt=n((t,e,n,o,r,s)=>{let i=0;for(const n of t.pairs)n.first!==e&&n.second!==e&&n.first!==o&&n.second!==o||(i+=n.count);let a=h(n.segments,r.segments);for(const t of f){if(t===e||t===o)continue;const i=s.get(t)??$t(u(t));a+=h(n.segments,i)+h(r.segments,i)}return t.count-i+a},"pairCrossingCount"),ot=n((t,e)=>{for(const n of t.sharedTrackConflicts)if(n!==e)return!1;return!0},"conflictsOnlyWith"),rt=n((t,e)=>t.segments.some(t=>e.segments.some(e=>I(t,e,.5)>=8)),"candidatesShareTrack"),st=n((t,e,n,o)=>ot(e,n.edge)&&ot(o,t.edge)&&!rt(e,o),"pairCandidatesAreCompatible"),it=n((t,e,n,o,r)=>{const s=nt(t.current,e.edge,n,o.edge,r,t.baseSegments);if(!(s>=t.current.count))return{replacements:new Map([[e.edge,n.path],[o.edge,r.path]]),crossings:s,bends:t.currentBends-(t.baseBendsByEdge.get(e.edge)??0)-(t.baseBendsByEdge.get(o.edge)??0)+n.totalBends+r.totalBends,length:t.currentLength-(t.baseLengthByEdge.get(e.edge)??0)-(t.baseLengthByEdge.get(o.edge)??0)+n.length+r.length}},"scorePairReplacement"),at=n((t,e)=>t.crossings<e.crossings||t.crossings===e.crossings&&(t.bends<e.bends||t.bends===e.bends&&t.length<e.length),"pairScoreIsBetter"),ct=n((t,e,n,o)=>{let r=o;for(const o of e.candidates)for(const s of n.candidates){if(!st(e,o,n,s))continue;const i=it(t,e,o,n,s);i&&at(i,r)&&(r=i)}return r},"bestScoreForOptionPair"),ft=n(t=>{const e=O(),n=R(),o=Q(),r=L(t),s=new Map(f.map(t=>[t,w(u(t))])),i=new Map(f.map(t=>[t,k(u(t))])),a=new Map,c=S(t);for(const e of c)for(const n of e){if(a.has(n))continue;const e=et(n,t,o,r);e.length>0&&a.set(n,{edge:n,candidates:e})}let d={replacements:new Map,crossings:t.count,bends:e,length:n};const l={current:t,currentBends:e,currentLength:n,baseBendsByEdge:s,baseLengthByEdge:i,baseSegments:o};for(const e of c){const n=new Set(e.filter(e=>t.edgeSet.has(e))),o=e.map(t=>a.get(t)).filter(t=>Boolean(t));for(let t=0;t<o.length;t++){const e=o[t];for(let r=t+1;r<o.length;r++){const t=o[r];(n.has(e.edge)||n.has(t.edge))&&(d=ct(l,e,t,d))}}}return d.replacements.size>0?d.replacements:void 0},"bestPairedReplacement");for(let t=0;t<4;t++){const t=p(),e=t.count;if(0===e)return;let n,o,r=e,s=Number.POSITIVE_INFINITY;for(const i of t.edges){const a=w(u(i),Ft);for(const c of Z(i)){const f=T(i,c),d=!f&&N(i,c),l=C(t,i,c),u=w(c,Ft);if(f||d)continue;(l<e||l===e&&u<a)&&(l>r||l===r&&u>=s||(n=i,o=c,r=l,s=u))}}if(n&&o){n.points=o;continue}const i=ft(t);if(!i)return;for(const[t,e]of i)t.points=e}}n(Xt,"separateSharedRenderedTerminalLanes"),n(zt,"collapseRedundantRectangularDoglegs"),n(Pt,"liftObstacleHuggingSameSideRails"),n(Gt,"liftTopLaneTitleBandsAboveRails"),n(Dt,"shiftLeftLaneTitleBandsLeftOfRails"),n(At,"swapDestinationTerminalTailsToReduceCrossings"),n(Ht,"reassignCrossingExternalRailChannels"),n(jt,"shortcutRedundantOrthogonalJogs"),n(_t,"resolveRenderedOrthogonalCrossings");var Vt=.001;function Wt(t,e){const{nodeInfoById:o,realNodeRects:r}=Y(e),s=["top","bottom","left","right"],i={top:Math.min(...r.map(t=>t.rect.top))-20,bottom:Math.max(...r.map(t=>t.rect.bottom))+20,left:Math.min(...r.map(t=>t.rect.left))-20,right:Math.max(...r.map(t=>t.rect.right))+20},a=n((t,e,n,o)=>{const r=[],s=E(t,e,n,o,20,Vt);return s&&r.push(s),e===o&&r.push($(t,e,n,i[e])),r},"buildOrthogonalPathCandidates"),c=n((t,e)=>{for(let n=0;n<t.length-1;n++){if(G(t[n],t[n+1],r,e,1))return!0}return!1},"pathHitsNode"),f=n((e,n,o=!1)=>{let r=0;const s=S(e,Vt),i=n.start,a=n.end;for(const e of t){if(e===n||e.isLayoutOnly)continue;const t=e.start,c=e.end;if(!o&&i&&a&&(t===i||t===a||c===i||c===a))continue;const f=e.points;if(f&&!(f.length<2))for(const t of s)for(const e of S(f,Vt))(D(t.a,t.b,e.a,e.b,Vt,Vt)||I(t,e,Vt)>=8)&&r++}return r},"pathConflictCount"),d=n((t,e)=>{const n=Math.abs(t.y-e.rect.top),o=Math.abs(t.y-e.rect.bottom),r=Math.abs(t.x-e.rect.left),s=Math.abs(t.x-e.rect.right);let i="top",a=n;return o<a&&(i="bottom",a=o),r<a&&(i="left",a=r),s<a&&(i="right",a=s),i},"nearestSideOfRect"),l=new Map,u=n((t,e,n)=>{const o=l.get(t)??[];o.push({side:e,edgeId:n}),l.set(t,o)},"addFaceClaim");for(const e of t){if(e.isLayoutOnly)continue;const t=e.points??[];if(t.length<1)continue;const n=e.id??"",r=e.start,s=e.end;if(r){const e=o.get(r);e&&u(r,d(t[0],e),n)}if(s){const e=o.get(s);e&&u(s,d(t[t.length-1],e),n)}}const h=n((t,e,n)=>l.get(t)?.some(t=>t.edgeId!==n&&t.side===e)??!1,"faceIsClaimed");for(const e of t){if(e.isLayoutOnly)continue;const t=e.points;if(!t||t.length<2)continue;const n=w(t,Vt);if(n<4)continue;const r=e.start,i=e.end;if(!r||!i)continue;const g=o.get(r),p=o.get(i);if(!g||!p)continue;const m=e.id??"",x=f(t,e,!0),y=f(t,e);let b,M=x,I=n;for(const t of s){if(h(r,t,m))continue;const n=F(g,t);for(const o of s){if(h(i,o,m))continue;const s=F(p,o);for(const d of a(n,t,s,o)){if(c(d,[r,i]))continue;const t=w(d,Vt);if(x>0){const n=f(d,e,!0);if(n>M||n===M&&t>=I)continue;M=n,I=t,b=d;continue}f(d,e)>y||t<I&&(I=t,b=d)}}}if(b){e.points=b;const t=l.get(r);t&&l.set(r,t.filter(t=>t.edgeId!==m));const n=l.get(i);n&&l.set(i,n.filter(t=>t.edgeId!==m)),u(r,d(b[0],g),m),u(i,d(b[b.length-1],p),m)}}}n(Wt,"simplifyDetouredEdges");var Kt=.001;function qt(t,e){const n=e?0:t.length-1,o=e?1:-1,r=t[n],s=t[n+o];if(!r||!s)return;const i=s.x-r.x,a=s.y-r.y;if(!(Math.abs(i)+Math.abs(a)<Kt)){if(Math.abs(a)<=Kt){const t=r.x+10*Math.sign(i);return{left:Math.min(r.x,t),right:Math.max(r.x,t),top:r.y-7,bottom:r.y+7}}if(Math.abs(i)<=Kt){const t=r.y+10*Math.sign(a);return{left:r.x-7,right:r.x+7,top:Math.min(r.y,t),bottom:Math.max(r.y,t)}}return{left:Math.min(r.x,s.x),right:Math.max(r.x,s.x),top:Math.min(r.y,s.y),bottom:Math.max(r.y,s.y)}}}function Ut(t){return{left:Math.min(t.left,t.right),right:Math.max(t.left,t.right),top:Math.min(t.top,t.bottom),bottom:Math.max(t.top,t.bottom)}}function Jt(t,e){const n=v(e);return[qt(n,!0),qt(n,!1)].some(e=>e&&R(t,Ut(e)))}function Zt(t,e){const o=[];for(const e of t){if(e.isLayoutOnly)continue;const t=e.points;if(t&&!(t.length<2))for(let n=0;n<t.length-1;n++)o.push({edgeId:e.id,p1:t[n],p2:t[n+1]})}const r=[],s=[];for(const t of e.values()){const e=t.isGroup,n=t.parentId;if(e&&!n){const e=B(t);e&&s.push({id:t.id,rect:e});continue}if(e)continue;if(t.isEdgeLabel)continue;const o=B(t);o&&r.push({nodeId:t.id,rect:o})}const i=n((t,e)=>{const n=N(e,3);for(const{nodeId:e,rect:o}of r)if(e!==t&&R(n,o))return!0;return!1},"labelOverlapsForeignNode"),a=n((t,e)=>{const n=N(e,3);for(const e of o)if(e.edgeId!==t&&L(e.p1,e.p2,n))return!0;return!1},"labelOverlapsForeignEdge"),c=n((t,e,n)=>i(t,n)||a(e,n),"labelOverlapsAnything"),f=[],d=n(t=>{for(const{id:e,rect:n}of s)if(O(n,t))return e},"findContainingLane"),l=n((t,e)=>f.some(n=>n.labelId!==t&&R(e,n.rect)),"overlapsPlacedLabel");for(const o of t){if(o.isLayoutOnly)continue;const t=o.labelNodeId;if(!t)continue;const r=e.get(t);if(!r)continue;const u=o.points;if(!u||u.length<2)continue;const h=r.width??0,g=r.height??0;if(h<=0||g<=0)continue;const p=[];for(let t=0;t<u.length-1;t++){const e=u[t],n=u[t+1],o=Math.abs(e.x-n.x),r=Math.abs(e.y-n.y);o<Kt&&r<Kt||(o>=Kt&&r>=Kt||p.push({idx:t,length:o+r,orientation:o>=Kt?"horizontal":"vertical",midX:(e.x+n.x)/2,midY:(e.y+n.y)/2}))}if(0===p.length)continue;const m=p.length>=3?p.filter(t=>t.idx>0&&t.idx<p.length-1):p,x=m.length>0?m:p,y=h>=g?"horizontal":"vertical",b=n(t=>[...t].sort((t,e)=>{const n=t.orientation===y;if(n!==(e.orientation===y))return n?-1:1;const o=t.length>=("horizontal"===t.orientation?h:g)+2;return o!==e.length>=("horizontal"===e.orientation?h:g)+2?o?-1:1:e.length-t.length}),"rankSegments"),M=p[0],I=p[p.length-1],S=[.5,.25,.75,.05,.95,.15,.85,.1,.9],w=n((t,e)=>{const n=u[t.idx],o=u[t.idx+1];return{midX:n.x+(o.x-n.x)*e,midY:n.y+(o.y-n.y)*e}},"anchorAtT"),v=n((t,e,n)=>Math.min(n,Math.max(e,t)),"clamp"),C=n((t,e)=>t.midX>=e.left-Kt&&t.midX<=e.right+Kt&&t.midY>=e.top-Kt&&t.midY<=e.bottom+Kt,"pointInsideRectInclusive"),L=n(t=>{const e=T(t.midX,t.midY,h,g),n=d(e);if(n)return{laneId:n,anchor:t,rect:e};const o=s.find(({rect:e})=>C(t,e));if(!o)return;const r=o.rect.left+h/2+1,i=o.rect.right-h/2-1,a=o.rect.top+g/2+1,c=o.rect.bottom-g/2-1;if(r>i||a>c)return;const f={midX:v(t.midX,r,i),midY:v(t.midY,a,c)},l=T(f.midX,f.midY,h,g);return C(t,l)?{laneId:o.id,anchor:f,rect:l}:void 0},"placementForAnchor"),k=n((t,e,n)=>"horizontal"===t.orientation?Math.abs(e.midX-n.x):Math.abs(e.midY-n.y),"distanceAlongSegment"),O=n((t,e)=>{const n=("horizontal"===t.orientation?h/2:g/2)+12;if(t===M){const o=u[t.idx];if(k(t,e,o)+Kt<n)return!1}if(t===I){const o=u[t.idx+1];if(k(t,e,o)+Kt<n)return!1}return!0},"labelClearsTerminalEndpoints"),R=n(e=>{const n=b(e);for(const e of n)for(const n of S){const r=w(e,n);if(!O(e,r))continue;const s=L(r);if(s&&(!Jt(s.rect,u)&&!l(t,s.rect)&&!c(t,o.id,s.rect)))return{laneId:s.laneId,anchor:s.anchor}}},"tryPool"),N=n((e,n,r=!1)=>{const s=b(e);for(const e of s){const s={midX:e.midX,midY:e.midY};if(n&&!O(e,s))continue;const c=L(s);if(c&&!Jt(c.rect,u)&&!l(t,c.rect)&&!i(t,c.rect)&&(r||!a(o.id,c.rect)))return{laneId:c.laneId,anchor:c.anchor}}},"findLaneContainingFallback"),B=R(x)??(x.length<p.length?R(p):void 0)??N(p,!0)??N(p,!1)??N(p,!1,!0);if(B){r.x=B.anchor.midX,r.y=B.anchor.midY,r.parentId=B.laneId;const e=T(B.anchor.midX,B.anchor.midY,h,g),n=f.findIndex(e=>e.labelId===t);n>=0?f[n]={labelId:t,rect:e}:f.push({labelId:t,rect:e})}}}n(qt,"markerClearanceRectFor"),n(Ut,"normalizeRect"),n(Jt,"labelOverlapsOwnMarker"),n(Zt,"anchorLabelsToPolyline");var Qt=1e-6;function te(t,e){return t<e?`${t}::${e}`:`${e}::${t}`}function ee(t,e){const{nodeInfoById:o,realNodeRects:r}=Y(e),s=new Map;for(const t of e){const e=t.id;t.isGroup||t.isEdgeLabel&&s.set(e,{w:t.width??0,h:t.height??0})}const i=n((e,o,r,i)=>{const a=te(o,r);let c=0;const f=n(t=>{if(!t)return;const e=s.get(t);if(!e)return;const n="x"===i?e.w/2:e.h/2;n>c&&(c=n)},"consider");f(e.labelNodeId);for(const n of t){if(n===e)continue;if(n.isLayoutOnly)continue;const t=n.start,o=n.end;t&&o&&(te(t,o)===a&&f(n.labelNodeId))}return c>0?c+3:0},"labelClearanceFor");for(const e of t){if(e.isLayoutOnly)continue;if(!C(e.points,Qt))continue;const n=P(e,o,Qt);if(!n)continue;const{srcId:s,dstId:a,srcInfo:c,dstInfo:f,collinearX:d,collinearY:l}=n;if(d===l)continue;let u,h;if(d){const t=f.cy>c.cy;u={x:c.cx,y:t?c.rect.bottom:c.rect.top},h={x:f.cx,y:t?f.rect.top:f.rect.bottom}}else{const t=f.cx>c.cx;u={x:t?c.rect.right:c.rect.left,y:c.cy},h={x:t?f.rect.left:f.rect.right,y:f.cy}}if(G(u,h,r,[s,a],1))continue;const g=i(e,s,a,d?"x":"y"),p=g>4?g:4,m=[0,p,-p];for(const n of m){const o={...u},i={...h};if(d){if(o.x+=n,i.x+=n,o.x<=c.rect.left||o.x>=c.rect.right)continue;if(i.x<=f.rect.left||i.x>=f.rect.right)continue}else{if(o.y+=n,i.y+=n,o.y<=c.rect.top||o.y>=c.rect.bottom)continue;if(i.y<=f.rect.top||i.y>=f.rect.bottom)continue}if(!G(o,i,r,[s,a],1)&&!H(o,i,t,e,{epsilon:Qt})){e.points=[o,i];break}}}}function ne(t,e){const o=.001,{realNodeRects:r,labelNodeRects:s}=X(e.values()),i=n((t,e)=>S(e,o).map(n=>({...n,edge:t,interior:n.index>=1&&n.index<=e.length-3})),"segmentsFor"),a=n(()=>{const e=[];for(const n of t){if(n.isLayoutOnly)continue;const t=n.points;!t||t.length<2||e.push(...i(n,v(t)))}return e},"allSegments"),c=n((t,e)=>t.horizontal&&e.horizontal?M(t.a.x,t.b.x,e.a.x,e.b.x)>=8&&Math.abs(t.a.y-e.a.y)<7:!(!t.vertical||!e.vertical)&&(M(t.a.y,t.b.y,e.a.y,e.b.y)>=8&&Math.abs(t.a.x-e.a.x)<7),"hasCrowdedParallelTrack"),f=n((e,n)=>{const a=e.start,f=e.end,d=i(e,n);if(d.length!==n.length-1)return!1;const l=[a,f].filter(t=>Boolean(t)),u=e.labelNodeId?[e.labelNodeId]:[];for(const t of d){if(G(t.a,t.b,r,l,-2))return!1;if(G(t.a,t.b,s,u,-2))return!1}for(const n of t){if(n===e||n.isLayoutOnly)continue;const t=n.points;if(t&&!(t.length<2))for(const e of d)for(const r of i(n,v(t))){if(c(e,r))return!1;if(j(e.a,e.b,r.a,r.b,o))return!1}}return!0},"candidateIsSafe"),d=n((t,e)=>{const n=v(t.edge.points??[]);if(n.length<4||t.index>=n.length-1)return;const o=n.map(t=>({...t}));if(t.horizontal)o[t.index].y+=e,o[t.index+1].y+=e;else{if(!t.vertical)return;o[t.index].x+=e,o[t.index+1].x+=e}return i(t.edge,o).length===o.length-1?o:void 0},"shiftedCandidate"),l=n((t,e)=>({x:t.x??(e.left+e.right)/2,y:t.y??(e.top+e.bottom)/2}),"nodeCenter"),u=n(t=>{const n=t.edge,o=v(n.points??[]);if(4!==o.length||1!==t.index)return;const r=n.start?e.get(n.start):void 0,s=n.end?e.get(n.end):void 0,i=r?B(r):void 0,a=s?B(s):void 0,c=o.slice(t.index+2);return r&&s&&i&&a&&0!==c.length?{sourceCenter:l(r,i),targetCenter:l(s,a),sourceRect:i,tail:c}:void 0},"sourceDetourContextFor"),h=n((t,e,n,r,s,i)=>{const a=r.y>=n.y,c=a?s.bottom:s.top,f=c+(a?20:-20);if(a&&t.b.y<=f+o||!a&&t.b.y>=f-o)return;const d=t.a.x+e;return v([{x:n.x,y:c},{x:n.x,y:f},{x:d,y:f},{x:d,y:t.b.y},...i],o)},"verticalSourceDetour"),g=n((t,e,n,r,s,i)=>{const a=r.x>=n.x,c=a?s.right:s.left,f=c+(a?20:-20);if(a&&t.b.x<=f+o||!a&&t.b.x>=f-o)return;const d=t.a.y+e;return v([{x:c,y:n.y},{x:f,y:n.y},{x:f,y:d},{x:t.b.x,y:d},...i],o)},"horizontalSourceDetour"),p=n((t,e)=>{const n=u(t);if(n)return t.vertical?h(t,e,n.sourceCenter,n.targetCenter,n.sourceRect,n.tail):t.horizontal?g(t,e,n.sourceCenter,n.targetCenter,n.sourceRect,n.tail):void 0},"sourceDetourCandidate"),m=[-7,7,-14,14,-21,21];for(let t=0;t<12;t++){const t=a();let e=!1;for(let n=0;n<t.length&&!e;n++)for(let o=n+1;o<t.length&&!e;o++){const r=t[n],s=t[o];if(r.edge===s.edge||!c(r,s))continue;const i=[r,s].filter(t=>t.interior);for(const t of i){for(const n of m){const o=d(t,n);if(o&&f(t.edge,o)){t.edge.points=o,e=!0;break}const r=p(t,n);if(r&&f(t.edge,r)){t.edge.points=r,e=!0;break}}if(e)break}}if(!e)return}}function oe(t,e,n,o){const r=e.x-t.x,s=e.y-t.y,i=o.x-n.x,a=o.y-n.y,c=r*a-s*i;if(Math.abs(c)<1e-10)return!1;const f=n.x-t.x,d=n.y-t.y,l=(f*a-d*i)/c,u=(f*s-d*r)/c,h=.01;return l>h&&l<.99&&u>h&&u<.99}function re(t){const e=t.nodes??[],n=t.edges??[],r=[];if(!n.length||!e.length)return r;const s=z(e),i=[];for(const t of n){if(t.isLayoutOnly)continue;const e=t.points;if(!e||e.length<2)continue;const n=t.start,o=t.end,a=t.labelNodeId,c=t.id??`${n}->${o}`;for(const t of s)if(t.nodeId!==n&&t.nodeId!==o&&(!a||t.nodeId!==a))for(let n=0;n<e.length-1;n++)if(L(e[n],e[n+1],t,-1)){r.push({type:"edge-node-overlap",edgeId:c,targetId:t.nodeId,detail:`segment ${n} passes through node "${t.nodeId}"`});break}for(let t=0;t<e.length-1;t++)i.push({edgeId:c,start:n,end:o,p1:e[t],p2:e[t+1]})}const a=new Set;for(let t=0;t<i.length;t++)for(let e=t+1;e<i.length;e++){const n=i[t],o=i[e];if(n.edgeId!==o.edgeId&&(n.start!==o.start&&n.start!==o.end&&n.end!==o.start&&n.end!==o.end&&oe(n.p1,n.p2,o.p1,o.p2))){const t=n.edgeId<o.edgeId?`${n.edgeId}|${o.edgeId}`:`${o.edgeId}|${n.edgeId}`;a.has(t)||(a.add(t),r.push({type:"edge-edge-crossing",edgeId:n.edgeId,targetId:o.edgeId,detail:`edges "${n.edgeId}" and "${o.edgeId}" cross`}))}}if(r.length>0){const t=r.filter(t=>"edge-node-overlap"===t.type).length,e=r.filter(t=>"edge-edge-crossing"===t.type).length;o.warn(`[SWIMLANE_VALIDATE] ${r.length} issue(s) detected: ${t} edge-node overlap(s), ${e} edge crossing(s)`);for(const t of r)o.warn(`[SWIMLANE_VALIDATE] ${t.type}: ${t.detail}`)}return r}function se(t,e){const o=t.nodes??[],r=t.edges??[],s=o.filter(t=>!t.isGroup);if(("LR"===e||"RL"===e)&&s.length>0&&!Ot(t,e))return;if("BT"===e&&s.length>0&&!kt(t))return;for(const t of r){if(t.isLayoutOnly)continue;const e=t.points;!e||e.length<2||(t.points=q(K(e)))}Wt(r,o),ee(r,o),Tt(r,o);const i=new Map;for(const t of o)i.set(String(t.id),t);Zt(r,i),tt(r,i),Bt(r,i),ne(r,i),Xt(r,i),zt(r,i),Pt(r,i),At(r,i);const a=n(()=>{_t(r,i),Xt(r,i),Ht(r,i),jt(r,i),Zt(r,i),bt(r,i),Pt(r,i),Zt(r,i),bt(r,i)},"finalizeRenderedEdges");a(),ne(r,i),a(),Gt(r,i,e),Dt(r,i,e),Gt(r,i,e),Dt(r,i,e)}function ie(t){const e=new Map(t.nodeById),n=new Set,o=[];for(const r of t.edges){if(!e.has(r.src)||!e.has(r.dst))continue;const t=`${r.id}:${r.src}->${r.dst}`;n.has(t)||(n.add(t),o.push(r))}return{nodes:[...e.keys()],edges:o,layout:t.layout,nodeById:e}}function ae(t,e){return t.edges.filter(t=>t.dst===e)}function ce(t){const e=new Map;for(const n of t.nodes)e.set(n,[]);for(const n of t.edges)e.get(n.src).push(n.dst);return e}function fe(t){const e=ce(t);for(const t of e.values())t.sort((t,e)=>t.localeCompare(e));return e}function de(t){const e=new Map;for(const n of t.nodes)e.set(n,0);for(const n of t.edges)e.set(n.dst,(e.get(n.dst)??0)+1);return e}function le(t,e){const o=[...e.entries()].filter(([,t])=>0===t).map(([t])=>t).sort((t,e)=>t.localeCompare(e)),r=new Set(t.edges.flatMap(t=>[t.src,t.dst])),s=n(e=>!r.has(e)&&!t.nodeById.get(e)?.isGroup,"isUnconnected"),i=[...e.keys()].filter(t=>0===e.get(t)&&s(t));let a=0;return o.map(t=>s(t)?i[a++]:t)}function ue(t,e=()=>!0){const n=new Map,o=new Map;for(const e of t.nodes)n.set(e,[]),o.set(e,[]);for(const r of t.edges)e(r)&&(o.get(r.src).push(r.dst),n.get(r.dst).push(r.src));return{preds:n,succs:o}}function he(t,e,n,o){let r=0;for(const e of t.nodes)o?.skipGroups&&t.nodeById.get(e)?.isGroup||(r=Math.max(r,n[e]??0));const s=Array.from({length:r+1},()=>[]);for(const r of e)o?.skipGroups&&t.nodeById.get(r)?.isGroup||s[Math.max(0,n[r]??0)].push(r);return s}function ge(t){const e=de(t),n=le(t,e),o=[],r=fe(t);for(;n.length;){const t=n.shift();o.push(t);for(const o of r.get(t)??[])if(e.set(o,(e.get(o)??0)-1),0===(e.get(o)??0)){let t=0;for(;t<n.length&&n[t]<o;)t++;n.splice(t,0,o)}}return o.length===t.nodes.length?o:null}function pe(t){const e=new Map;let n=0;for(const o of t)e.set(o,n),n++;return e}function me(t){const e=new Array(t.length),o=n((n,r)=>{if(r-n<=1)return 0;const s=n+r>>1;let i=o(n,s)+o(s,r),a=n,c=s,f=n;for(;a<s||c<r;)c>=r||a<s&&t[a]<=t[c]?e[f++]=t[a++]:(e[f++]=t[c++],i+=s-a);for(let o=n;o<r;o++)t[o]=e[o];return i},"count");return o(0,t.length)}function xe(t){const e=ie(t),o=new Map;for(const t of e.nodes)o.set(t,[]);for(const t of e.edges)o.get(t.src).push(t);for(const t of o.values())t.sort((t,e)=>t.dst===e.dst?t.id.localeCompare(e.id):t.dst.localeCompare(e.dst));const r=Object.create(null);for(const t of e.nodes)r[t]=0;const s=[],i=n(t=>{r[t]=1;for(const e of o.get(t)??[]){const t=e.dst;0===r[t]?i(t):1===r[t]&&s.push(e)}r[t]=2},"dfs"),a=de(e),c=[...e.nodes.filter(t=>0===(a.get(t)??0)),...e.nodes.filter(t=>0!==(a.get(t)??0))];for(const t of c)0===r[t]&&i(t);const f=new Set(s.map(t=>`${t.id}:${t.src}->${t.dst}`)),d=e.edges.map(t=>f.has(`${t.id}:${t.src}->${t.dst}`)?{id:t.id,src:t.dst,dst:t.src,weight:t.weight,ref:t.ref}:t);return{acyclic:{nodes:[...e.nodes],edges:d,layout:e.layout,nodeById:new Map(e.nodeById)},reversed:s}}function ye(t){const e=new Map,o=n(n=>{if(e.has(n))return e.get(n);const r=t.nodeById.get(n);if(!r)return e.set(n,null),null;const s=r.parentId;if(!s)return e.set(n,null),null;const i=o(s)??s;return e.set(n,i),i},"resolve");for(const e of t.nodes)o(e);return e}function be(t){const e=ye(t);return t=>e.get(t)??null}function Me(t){const e=[];for(const n of t.layout.nodes??[])n.isGroup&&!n.parentId&&e.push(n.id);return[...new Set(e)].reverse()}function Ie(t,e){const n=Me(t);if(!e||0===e.length)return n;const o=new Set(n),r=new Set,s=[];for(const t of e)o.has(t)&&!r.has(t)&&(r.add(t),s.push(t));for(const t of n)r.has(t)||s.push(t);return s}n(te,"pairKey"),n(ee,"straightenCollinearSiblingDetours"),n(ne,"nudgeSharedInteriorSubpaths"),n(oe,"segmentsIntersect"),n(re,"validateSwimlanesLayout"),n(se,"postProcessSwimlaneLayout"),n(ie,"normalizeGraph"),n(ae,"incoming"),n(ce,"buildSuccessorMap"),n(fe,"buildSortedSuccessorMap"),n(de,"buildInDegreeMap"),n(le,"sortedZeroInDegreeNodes"),n(ue,"buildPredecessorSuccessorMaps"),n(he,"buildLayersFromRanks"),n(ge,"topoSortIfAcyclic"),n(pe,"buildLayerIndex"),n(me,"countInversions"),n(xe,"removeCycles_DFS"),n(ye,"buildTopLaneMap"),n(be,"createTopLaneResolver"),n(Me,"buildTopLaneOrder"),n(Ie,"resolveTopLaneOrder");var Se=8,we=4,ve=!0,Ce=100,Le=40;function ke(t,e){const o=ie(t),r=e?.laneOf??(()=>null),s=e?.rankHint,{preds:i}=ue(o);for(const t of i.values())t.sort((t,e)=>t.localeCompare(e));const a=ge(o)??[...o.nodes].sort((t,e)=>t.localeCompare(e)),c=new Map;for(const[t,e]of a.entries())c.set(e,t);const f=new Map,d=new Map;for(const t of o.nodes)d.set(t,[]);for(const t of a){const e=(i.get(t)??[]).filter(t=>f.has(t));if(e.length>0){const n=Oe(t,e,{laneOf:r,rankHint:s,topoIndex:c});f.set(t,n),d.get(n).push(t)}else f.has(t)||f.set(t,null)}for(const t of o.nodes)f.has(t)||f.set(t,null);const l=new Set;for(const t of o.nodes)null===(f.get(t)??null)&&l.add(t);const u=[...l].sort((t,e)=>{const n=c.get(t)??0,o=c.get(e)??0;return n===o?t.localeCompare(e):n-o}),h=Re(o),g=new Map;for(const[t,e]of h.entries())g.set(t,[...e].sort((t,e)=>t.localeCompare(e)));const p=Ne(g),m=Te(g),x=new Map;for(const t of o.nodes)x.set(t,[]);for(const t of m)for(const e of t.nodes){const n=x.get(e);n?n.push(t.id):x.set(e,[t.id])}const y=[],b=[],M=new Set,I=n(t=>{if(!M.has(t)){M.add(t),y.push(t);for(const e of d.get(t)??[])I(e);b.push(t)}},"walk");for(const t of u)I(t);for(const t of a)I(t);return{parent:f,children:d,roots:u,componentOf:p,blocks:m,nodeBlocks:x,adjacency:g,preorder:y,postorder:b,topologicalOrder:a}}function Oe(t,e,n){const o=n.laneOf(t);return[...e].sort((t,e)=>{const r=n.laneOf(t),s=n.laneOf(e),i=null!=r&&r===o;if(i!==(null!=s&&s===o))return i?-1:1;const a=n.rankHint?.[t],c=n.rankHint?.[e];if(null!=a&&null!=c&&a!==c)return c-a;const f=n.topoIndex.get(t)??0,d=n.topoIndex.get(e)??0;return f!==d?f-d:t.localeCompare(e)})[0]}function Re(t){const e=new Map;for(const n of t.nodes)e.set(n,new Set);for(const n of t.edges)e.get(n.src).add(n.dst),e.get(n.dst).add(n.src);return e}function Ne(t){const e=new Map;let n=0;for(const o of t.keys()){if(e.has(o))continue;const r=[o];for(;r.length>0;){const o=r.pop();if(!e.has(o)){e.set(o,n);for(const n of t.get(o)??[])e.has(n)||r.push(n)}}n++}return e}function Te(t){const e=new Map,o=new Map,r=[],s=[];let i=0;const a=n((n,c)=>{e.set(n,++i),o.set(n,i);for(const f of t.get(n)??[])f!==c&&(e.has(f)?(e.get(f)??0)<(e.get(n)??0)&&(r.push([n,f]),o.set(n,Math.min(o.get(n)??i,e.get(f)??i))):(r.push([n,f]),a(f,n),o.set(n,Math.min(o.get(n)??i,o.get(f)??i)),(o.get(f)??0)>=(e.get(n)??0)&&s.push(Be(n,f,r,s.length))))},"visit");for(const n of t.keys())e.has(n)||a(n,null);return s}function Be(t,e,n,o){const r=[],s=new Set;for(;n.length>0;){const o=n.pop();if(r.push(o),s.add(o[0]),s.add(o[1]),o[0]===t&&o[1]===e||o[0]===e&&o[1]===t)break}return{id:o,edges:r,nodes:[...s]}}function Fe(t,e,o){const r=[...t.nodes],s=new Map;for(const[t,e]of r.entries())s.set(e,t);const i=r.length,a=new Array(i).fill(-1),c=new Array(i).fill(0),f=[],d=new Set;for(const t of r){const e=o.parent.get(t)??null,n=s.get(t);null!=n&&(null==e&&(a[n]=-1,c[n]=0,d.has(t)||(d.add(t),f.push(t))))}for(;f.length>0;){const t=f.shift(),e=s.get(t);if(null==e)continue;const n=o.children.get(t)??[];for(const t of n){if(d.has(t))continue;const n=s.get(t);null!=n&&(a[n]=e,c[n]=c[e]+1,d.add(t),f.push(t))}}for(const t of r){if(d.has(t))continue;const e=s.get(t);null!=e&&(a[e]=-1,c[e]=0,d.add(t))}const l=Math.max(1,Math.ceil(Math.log2(Math.max(1,i)))+1),u=Array.from({length:l},()=>new Array(i).fill(-1));for(let t=0;t<i;t++)u[0][t]=a[t];for(let t=1;t<l;t++)for(let e=0;e<i;e++){const n=u[t-1][e];u[t][e]=-1===n?-1:u[t-1][n]}const h=n((t,e)=>{if(-1===t||-1===e)return-1;c[t]<c[e]&&([t,e]=[e,t]);const n=c[t]-c[e];for(let e=0;e<l;e++)if(n>>e&1&&-1===(t=u[e][t]))return-1;if(t===e)return t;for(let n=l-1;n>=0;n--){const o=u[n][t],r=u[n][e];-1!==o&&-1!==r&&(o!==r&&(t=o,e=r))}return u[0][t]},"lcaIndex"),g=Array.from({length:i},()=>new Map);for(const n of t.edges){let t=n.src,o=n.dst,r=e[t],i=e[o];if(null==r||null==i)continue;if(r>i&&([t,o]=[o,t],[r,i]=[i,r]),null==r||null==i||r===i)continue;const a=s.get(t),c=s.get(o);if(null==a||null==c)continue;const f=h(a,c);if(-1===f)continue;const d=g[f];for(let t=r;t<i;t++)d.set(t,(d.get(t)??0)+1)}const p=new Map,m=n((t,e)=>{if(0!==e.size)for(const[n,o]of e)t.set(n,(t.get(n)??0)+o)},"mergeInto"),x=new Set,y=n(t=>{const n=s.get(t);x.add(t);const r=null==n?void 0:g[n],i=r?new Map(r):new Map,a=o.children.get(t)??[];for(const n of a){const o=y(n),r=e[t];if(null!=r){let s=p.get(t);s||(s=new Map,p.set(t,s));let i=o.get(r)??0;const a=e[n];null!=a&&a>r&&(i+=1),s.set(n,i)}m(i,o)}return i},"dfs");for(const t of o.roots)x.has(t)||y(t);for(const t of r)x.has(t)||y(t);return p}function Ee(t,e,o){const r=new Map,s=n(t=>{let n=o[t]??0;const i=[...e.get(t)??[]];i.sort($e(o));for(const t of i){s(t);const e=r.get(t);null!=e&&(n=Math.min(n,e))}r.set(t,n)},"annotate");for(const e of t)s(e);return r}function $e(t){return(e,n)=>{const o=t[e]??0,r=t[n]??0;return o===r?e.localeCompare(n):o-r}}function Ye(t,e,o,r){let s=0;for(const t of e){const e=o[t]??0;e>s&&(s=e)}const i=Array.from({length:s+1},()=>[]),a=new Set,c=n(t=>{if(a.has(t))return;a.add(t);const e=o[t]??0;i[e]||(i[e]=[]),i[e].push(t);for(const e of r(t))c(e)},"emit");for(const e of t)c(e);for(const t of e)if(!a.has(t)){const e=o[t]??0;i[e]||(i[e]=[]),i[e].push(t),a.add(t)}return i}function Xe(t){const e=[];for(const n of t){const t=new Set,o=[];for(const e of n)t.has(e)||(t.add(e),o.push(e));e.push(o)}return e}function ze(t,e,n,o){return r=>{const s=t.get(r)??[];if(0===s.length)return[];const i=e[r]??0,a=[],c=[],f=n.get(r);for(const t of s){const e=o.get(t)??i;e>i?a.push({child:t,min:e}):c.push(t)}return a.sort((t,e)=>t.min===e.min?t.child.localeCompare(e.child):t.min-e.min),c.sort((t,e)=>{const n=f?.get(t)??0,r=f?.get(e)??0;if(n!==r)return n-r;const s=o.get(t)??i,a=o.get(e)??i;return s!==a?s-a:t.localeCompare(e)}),[...a.map(t=>t.child),...c]}}function Pe(t,e,n){const o=ke(t,{rankHint:e,laneOf:n}),{children:r,roots:s}=o;for(const e of t.nodes)r.has(e)||r.set(e,[]);const i=Fe(t,e,o),a=[...s].sort($e(e)),c=ze(r,e,i,Ee(a,r,e));let f=Ye(a,t.nodes,e,c);return f=Xe(f),f}function Ge(t,e,n){const o=new Set(t),r=new Set(e),s=pe(e),i=[];for(const t of n)o.has(t.src)&&r.has(t.dst)&&i.push(s.get(t.dst));return me(i)}function De(t,e,n){const o=[];for(const t of e){const e=n[t.src],r=n[t.dst];if(null==e||null==r||e===r)continue;let s=t.src,i=t.dst,a=e,c=r;e>r&&(s=t.dst,i=t.src,a=r,c=e);for(let e=a;e<c;e++)o.push({id:`${t.id}@${e}`,src:s,dst:i,ref:t.ref})}let r=0;for(let e=0;e+1<t.length;e++)r+=Ge(t[e],t[e+1],o);return r}function Ae(t,e){const n={...e},{preds:o}=ue(t),r=be(t);let s=De(Pe(t,n,r),t.edges,n);const i=we;for(let e=0;e<i;e++){let e=!1;const i=[...t.nodes].sort((t,e)=>(n[e]??0)-(n[t]??0));for(const a of i){const i=n[a]??0;if(0===i)continue;let c=0;for(const t of o.get(a)??[])c=Math.max(c,(n[t]??0)+1);if(c>=i)continue;const f=i;n[a]=c;const d=De(Pe(t,n,r),t.edges,n);d<s?(s=d,e=!0):n[a]=f}if(!e)break}return n}function He(t,e){const n=be(t),o=[...t.nodes].sort((t,n)=>(e[t]??0)-(e[n]??0)||t.localeCompare(n));for(const r of o){const o=n(r);if(!o)continue;const s=t.edges.filter(t=>t.src===r);if(0===s.length)continue;let i=!1,a=0;for(const t of s){const e=n(t.dst);null==e||e===o?i=!0:a++}if(0===a||i)continue;let c=0,f=!1;for(const e of t.edges){if(e.dst!==r)continue;const t=n(e.src);t&&(t===o?f=!0:c++)}if(c>0||!f)continue;const d=e[r]??0,l=d+a;let u=0;for(const n of t.edges)n.dst===r&&(u=Math.max(u,(e[n.src]??0)+1));const h=Math.max(d,u,l);h!==d&&(e[r]=h)}}function je(t,e){const n=ie(t),o=ge(n)??[...n.nodes].sort(),r=e?.compactSingleInput??!1,s=be(n);let i=Object.create(null);for(const t of o){const o=ae(n,t),a=e?.ignoreCrossLaneEdges?o.filter(e=>{const n=s(e.src),o=s(t);return!n||!o||n===o}):o;if(0===a.length)i[t]=0;else if(r&&1===a.length){const e=a[0].src,n=s(e),o=s(t);i[t]=n!==o?i[e]??0:(i[e]??0)+1}else{let e=-1/0;for(const t of a)e=Math.max(e,(i[t.src]??0)+1);i[t]=e===-1/0?0:e}}e?.optimizeRanksByCrossings&&(i=Ae(n,i)),e?.ignoreCrossLaneEdges&&He(n,i);return{layers:Pe(n,i,s),rankOf:i,dummy:new Set}}function _e(t,e){const o=ie(t),r={...je(o,{compactSingleInput:e?.compactSingleInput,ignoreCrossLaneEdges:e?.ignoreCrossLaneEdges,optimizeRanksByCrossings:e?.optimizeRanksByCrossings}).rankOf},s=be(o),{preds:i,succs:a}=ue(o,t=>{if(e?.ignoreCrossLaneEdges){const e=s(t.src),n=s(t.dst);if(e&&n&&e!==n)return!1}return!0}),c=ge(o)??[...o.nodes],f=[...c].reverse(),d=n((t,e)=>{let n=0;for(const e of i.get(t)??[])n=Math.max(n,(r[e]??0)+1);let o=Number.POSITIVE_INFINITY;const s=a.get(t)??[];return s.length>0&&(o=Math.min(...s.map(t=>(r[t]??0)-1))),Number.isFinite(o)||(o=Math.max(n,e)),Math.min(Math.max(e,n),o)},"clampFeasible"),l=Se,u=n(t=>{let e=!1;for(const n of t){const t=i.get(n)??[],o=a.get(n)??[];if(0===t.length&&0===o.length)continue;const s=t.length>0?t.reduce((t,e)=>t+(r[e]??0)+1,0)/t.length:r[n]??0,c=o.length>0?o.reduce((t,e)=>t+(r[e]??0)-1,0)/o.length:r[n]??0,f=Math.round((s+c)/2),l=d(n,f);l!==r[n]&&(r[n]=l,e=!0)}return e},"relaxOrder");for(let t=0;t<l;t++){const t=u(c),e=u(f);if(!t&&!e)break}for(const t of c){let e=0;for(const n of i.get(t)??[])e=Math.max(e,(r[n]??0)+1);(r[t]??0)<e&&(r[t]=e)}for(const t of f){const e=a.get(t)??[];if(e.length>0){const n=Math.min(...e.map(t=>(r[t]??0)-1));(r[t]??0)>n&&(r[t]=n)}}return{layers:he(o,c,r),rankOf:r,dummy:new Set}}function Ve(t){const e=de(t),n=fe(t);let o=le(t,e);const r=[];for(;o.length>0;){const t=[];for(const s of o){r.push(s);for(const o of n.get(s)??[])e.set(o,(e.get(o)??0)-1),0===(e.get(o)??0)&&t.push(o)}o=t.sort((t,e)=>t.localeCompare(e))}return r.length===t.nodes.length?r:null}function We(t,e){const o=ie(t),r="LR"===e?.direction?Ve(o)??[...o.nodes].sort():ge(o)??[...o.nodes].sort(),s=be(o),i=n(t=>s(t)??t,"laneOf"),a=Object.create(null),c=new Map,f=n((t,n)=>e?.ignoreCrossLaneEdges??!0?i(t)===i(n)?1:0:1,"edgeWeight");for(const t of r){const e=o.nodeById.get(t);if(e?.isGroup)continue;const n=ae(o,t);let r=0;if(n.length>0)for(const e of n){const n=e.src,o=a[n]??0;r=Math.max(r,o+f(n,t))}const s=i(t),d=c.get(s)??0,l=Math.max(r,d);a[t]=l,c.set(s,l+1)}return{layers:he(o,r,a,{skipGroups:!0}),rankOf:a,dummy:new Set}}function Ke(t,e){const o=ie(e),{rankOf:r}=t,s=t.layers.map(t=>[...t]),i=new Set(t.dummy?[...t.dummy]:[]);let a=0;const c=new Map(o.nodeById),f=n(t=>{const e="placeholder-"+a++,n={id:e,isGroup:!1,isDummy:!0,width:0,height:0};for(c.set(e,n),i.add(e);s.length<=t;)s.push([]);return s[t].push(e),r[e]=t,e},"addDummyAt"),d=[...o.edges].sort((t,e)=>t.id===e.id?t.src===e.src?t.dst.localeCompare(e.dst):t.src.localeCompare(e.src):t.id.localeCompare(e.id)),l=[];for(const t of d){const e=r[t.src]??0,n=r[t.dst]??0;if(n-e<=1){l.push(t);continue}let o=t.src;for(let r=e+1,s=0;r<n;r++,s++){const e=f(r);l.push({id:`${t.id}#${s}`,src:o,dst:e,weight:t.weight,ref:t.ref}),o=e}const s=n-e-2;l.push({id:`${t.id}#${Math.max(s+1,0)}`,src:o,dst:t.dst,weight:t.weight,ref:t.ref})}const u={nodes:[...o.nodes,...[...i].filter(t=>!o.nodes.includes(t))],edges:l,layout:o.layout,nodeById:c};return{layering:{layers:s,rankOf:r,dummy:i},graphWithDummies:u}}function qe(t){const e=t.length;if(0===e)return Number.POSITIVE_INFINITY;const n=[...t].sort((t,e)=>t-e);return e%2==1?n[(e-1)/2]:.5*(n[e/2-1]+n[e/2])}function Ue(t){if(0===t.length)return Number.POSITIVE_INFINITY;return t.reduce((t,e)=>t+e,0)/t.length}function Je(t,e,n,o){const r=new Map;for(const e of t)r.set(e,[]);for(const t of n)"down"===o?e.has(t.src)&&r.has(t.dst)&&r.get(t.dst).push(e.get(t.src)):e.has(t.dst)&&r.has(t.src)&&r.get(t.src).push(e.get(t.dst));return r}function Ze(t,e,n){const o=n.get(t)??0,r=n.get(e)??0;return o!==r?o-r:t.localeCompare(e)}function Qe(t,e,n){const o=new Set(t),r=new Set(e),s=pe(t),i=pe(e),a=[];for(const t of n)o.has(t.src)&&r.has(t.dst)&&a.push({u:s.get(t.src),v:i.get(t.dst)});a.sort((t,e)=>t.u===e.u?t.v-e.v:t.u-e.u);return me(a.map(t=>t.v))}function tn(t,e,n){return[...t].sort((t,o)=>{const r=qe(e.get(t)??[]),s=qe(e.get(o)??[]);return r===s?Ze(t,o,n):isFinite(r)?isFinite(s)?r-s:-1:1})}function en(t,e,n,o,r,s){const i=pe(t),a=pe(e),c=Je(e,i,n,o);if(!r||!s||0===s.length)return tn(e,c,a);const f=new Map;for(const t of e){const e=r(t),n=f.get(e)??[];n.push(t),f.set(e,n)}const d=[];for(const t of s){const e=f.get(t);if(!e||0===e.length)continue;const n=tn(e,c,a);d.push(...n)}const l=f.get(null);if(l&&l.length>0){const t=tn(l,c,a);for(const e of t){const t=Ue(c.get(e)??[]);let n=d.length;if(isFinite(t))for(const[e,o]of d.entries()){if(t<Ue(c.get(o)??[])){n=e;break}}d.splice(n,0,e)}}return d}function nn(t,e,o,r,s){const i=[...e],a=new Set(t),c=new Set(e),f=r?new Set(r):null,d=o.filter(t=>a.has(t.src)&&c.has(t.dst)),l=f?o.filter(t=>c.has(t.src)&&f.has(t.dst)):void 0,u=n(e=>{let n=Qe(t,e,d);return l&&r&&(n+=Qe(e,r,l)),n},"crossingScore"),h=s?new Map:null;if(s&&h)for(const t of e)h.set(t,s(t));let g=!0,p=u(i);for(;g;){g=!1;for(let t=0;t+1<i.length;t++){if(h){if(h.get(i[t])!==h.get(i[t+1]))continue}const e=p;[i[t],i[t+1]]=[i[t+1],i[t]];const n=u(i);n<e?(p=n,g=!0):[i[t],i[t+1]]=[i[t+1],i[t]]}}return i}function on(t,e,n){const o=t.layers.map(t=>[...t]),r=e.edges,s=be(e),i=Ie(e,n?.laneOrder);for(let t=0;t<3;t++){for(let t=1;t<o.length;t++)o[t]=en(o[t-1],o[t],r,"down",s,i),o[t]=nn(o[t-1],o[t],r,o[t+1],s);for(let t=o.length-2;t>=0;t--)o[t]=en(o[t+1],o[t],r,"up",s,i),o[t]=nn(o[t+1],o[t],r,o[t-1],s)}return{layers:o}}function rn(t,e,o){const r=o?.layerGap??Ce,s=o?.nodeGap??Le,i=o?.laneGap??2*s,a=o?.direction??"TB",c="LR"===a||"RL"===a,f=t.layers,d=Object.create(null),l=Object.create(null),u=n(t=>e.nodeById.get(t),"getNode"),h=n(t=>u(t)?.width??0,"getWidth"),g=n(t=>u(t)?.height??0,"getHeight"),p=be(e),m=Ie(e,o?.laneOrder),x=f.map(t=>t.reduce((t,e)=>Math.max(t,g(e)),0)),y=[];if(c)for(let t=0;t+1<f.length;t++){const e=f[t].reduce((t,e)=>Math.max(t,h(e)),0),n=f[t+1].reduce((t,e)=>Math.max(t,h(e)),0),o=x[t]/2+x[t+1]/2,s=(e+n)/2,i=Math.max(0,s-o-r);y.push(i)}const b=new Set;for(const t of f)for(const e of t)b.add(p(e));const M=b.has(null),I=m.filter(t=>b.has(t)),S=[...M?[null]:[],...I],w=Object.create(null);for(const t of I)w[t]=0;M&&(w.null=0);for(const t of f){const e=Object.create(null),n=[];for(const o of t){const t=p(o);null===t?n.push(o):(e[t]||=[]).push(o)}for(const[t,n]of Object.entries(e)){const e=n.reduce((t,e)=>t+h(e),0)+s*Math.max(0,n.length-1);w[t]=Math.max(w[t]??0,e)}if(M&&n.length){const t=n.reduce((t,e)=>t+h(e),0)+s*Math.max(0,n.length-1);w.null=Math.max(w.null??0,t)}}const v=new Map;{const t=S.map(t=>(null===t?w.null:w[t])??0);let e=-(t.reduce((t,e)=>t+e,0)+i*Math.max(0,S.length-1))/2;for(let n=0;n<S.length;n++){const o=S[n],r=t[n]??0,s=e+r/2;v.set(o,s),e+=r,n<S.length-1&&(e+=i)}}let C=0;for(const[t,e]of f.entries()){const n=x[t]??0,o=new Map;for(const t of e){const e=p(t),n=o.get(e)??[];n.push(t),o.set(e,n)}for(const t of S){const e=o.get(t)??[];if(0===e.length)continue;const r=v.get(t);if(1===e.length){const t=e[0];d[t]=r,l[t]=C+n/2}else{const t=e.map(t=>h(t));let o=r-(t.reduce((t,e)=>t+e,0)+s*(e.length-1))/2;for(const[r,i]of e.entries()){const e=t[r];d[i]=o+e/2,l[i]=C+n/2,o+=e+s}}}C+=n+r+(y[t]??0)}const L=new Map;for(const t of e.edges){const e=t.ref.id;L.has(e)||L.set(e,[]),L.get(e).push(t)}for(const[,t]of L){if(0===t.length)continue;const n=t[0].ref,o=n.start,r=n.end;if(null==o||null==r)continue;const s=Math.round(((d[o]??0)+(d[r]??0))/2),i=new Set;for(const e of t)i.add(e.src),i.add(e.dst);for(const t of i){if(t===o||t===r)continue;const n=e.nodeById.get(t);n?.isDummy&&(d[t]=s)}}return{x:d,y:l}}n(ke,"buildDrivingTree"),n(Oe,"chooseParent"),n(Re,"buildAdjacency"),n(Ne,"assignComponents"),n(Te,"computeBlocks"),n(Be,"popBlock"),n(Fe,"computeSubtreeCrossCounts"),n(Ee,"annotateMinimumLayers"),n($e,"compareByRankThenId"),n(Ye,"emitNodesInTreeOrder"),n(Xe,"deduplicateLayers"),n(ze,"createChildOrderer"),n(Pe,"buildMultitreeLayerOrder"),n(Ge,"countCrossingsBetweenAdjacent"),n(De,"totalCrossings"),n(Ae,"optimizeRanksByCrossings"),n(He,"adjustCrossLaneSources"),n(je,"assignLayers_LongestPath"),n(_e,"assignLayers_Gravity"),n(Ve,"topoSortByGenerationIfAcyclic"),n(We,"assignLayers_LaneAwareCompact"),n(Ke,"makeProperLayering"),n(qe,"median"),n(Ue,"barycenter"),n(Je,"neighborPositionsFor"),n(Ze,"currentOrderTieBreak"),n(Qe,"countCrossingsBetweenAdjacent"),n(tn,"sortByHeuristic"),n(en,"reorderLayer"),n(nn,"transposeImprove"),n(on,"orderLayers"),n(rn,"assignCoordinates");function sn(t){let e=2166136261;for(let n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return e>>>0}function an(t){let e=t>>>0;return()=>{e+=1831565813;let t=e;return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296}}function cn(t,e){const n=[...t],o=an(e);for(let t=n.length-1;t>0;t--){const e=Math.floor(o()*(t+1));[n[t],n[e]]=[n[e],n[t]]}return n}function fn(t,e){let n=0;for(const[o,r]of t.entries())n+=Math.abs(o-(e.get(r)??o));return n}function dn(t,e){const n=new Map;for(const[e,o]of t.entries())n.set(o,e);let o=0;for(const{a:t,b:r,weight:s}of e){const e=n.get(t),i=n.get(r);null!=e&&null!=i&&(o+=s*Math.abs(e-i))}return o}function ln(t){const e=Me(t);if(e.length<2)return[];const n=new Map(e.map((t,e)=>[t,e])),o=be(t),r=new Map;for(const e of t.layout.edges??[]){if(e.isLayoutOnly)continue;const s="string"==typeof e.start?e.start:void 0,i="string"==typeof e.end?e.end:void 0;if(!(s&&i&&t.nodeById.has(s)&&t.nodeById.has(i)))continue;const a=o(s),c=o(i);if(!a||!c||a===c)continue;const f=n.get(a),d=n.get(c);if(null==f||null==d)continue;const[l,u]=f<=d?[a,c]:[c,a],h=`${l}\0${u}`,g=r.get(h);g?g.weight++:r.set(h,{a:l,b:u,weight:1})}return[...r.values()]}function un(t,e,n){const o=[...t];let r=dn(o,e),s=!0,i=0;const a=Math.max(1,o.length);for(;s&&i<a;){s=!1,i++;for(let t=0;t+1<o.length;t++){[o[t],o[t+1]]=[o[t+1],o[t]];const n=dn(o,e);n<r?(r=n,s=!0):[o[t],o[t+1]]=[o[t+1],o[t]]}}return{order:o,cost:r,sourceDistance:fn(o,n)}}function hn(t,e){return t.cost!==e.cost?t.cost<e.cost:t.sourceDistance<e.sourceDistance}function gn(t,e,n){const o=[...e].sort((t,e)=>t.a===e.a?t.b.localeCompare(e.b):t.a.localeCompare(e.a)).map(({a:t,b:e,weight:n})=>`${t}:${e}:${n}`).join("|");return sn(`${t.join("|")}#${o}#${n}`)}function pn(t,e={}){const n=Me(t);if(n.length<2)return n;const o=ln(t);if(0===o.length)return n;const r=new Map(n.map((t,e)=>[t,e]));let s=un(n,o,r);const i=Math.max(0,e.restarts??8);for(let t=0;t<i;t++){const e=un(cn(n,gn(n,o,t)),o,r);hn(e,s)&&(s=e)}return s.order}function mn(t,e){const n=e?.ignoreCrossLaneEdges??!0,o=e?.optimizeRanksByCrossings??!0,r=ie(t),s=e?.automaticLaneOrdering?pn(r,{restarts:8}):void 0,i=xe(r),a=i.acyclic,c=n?We(a,{compactSingleInput:e?.compactSingleInput??ve,ignoreCrossLaneEdges:!0,direction:e?.direction}):_e(a,{compactSingleInput:e?.compactSingleInput??ve,ignoreCrossLaneEdges:!1,optimizeRanksByCrossings:o}),{layering:f,graphWithDummies:d}=Ke(c,a),l=on(f,d,{laneOrder:s}),u=rn(l,d,{layerGap:e?.layerGap,nodeGap:e?.nodeGap,direction:e?.direction,laneOrder:s});return{acyclic:a,reversed:i.reversed,layering:f,ordered:l,coordinates:u}}n(sn,"hashString"),n(an,"mulberry32"),n(cn,"deterministicShuffle"),n(fn,"sourceDistance"),n(dn,"laneArrangementCost"),n(ln,"buildWeightedLaneEdges"),n(un,"greedySwitch"),n(hn,"isBetterCandidate"),n(gn,"seedForRestart"),n(pn,"optimizeTopLaneOrder"),n(mn,"sugiyamaLayout");var xn=1e-6,yn=15,bn=15,Mn=20;function In(t,e,n){const o=t.x??0,r=t.y??0,s=e.x-o,i=e.y-r,a=Math.abs(s),c=Math.abs(i);if(a<xn&&c<xn)return n;return c>xn&&3*c>=a?i>0?"bottom":"top":a>xn?s>0?"right":"left":n}function Sn(t,e){return Math.abs(t.to-e.from)<xn||Math.abs(t.to-e.to)<xn?t.to:t.from}function wn(t,e){return"vertical"===t.orient?{x:t.coord,y:e}:{x:e,y:t.coord}}function vn(t,e){const o=t.nodes??[],r=t.edges??[],s=[];for(const t of r)t.isLayoutOnly||s.push({...t,__originalEdge:t});const i=new Map,a=new Map,c=[],f="LR"===e;for(const t of o)i.set(t.id,t);const d=o.filter(t=>t.isGroup&&!t.parentId);for(const t of d){const e={id:t.id},r=n(t=>{a.set(t.id,e),o.filter(e=>e.parentId===t.id).forEach(r)},"assignLane");r(t)}const l=o.filter(t=>!t.isGroup&&!t.isEdgeLabel).map(t=>{const e=t.width??10,n=t.height??10,o=t.x??0,r=t.y??0;return{nodeId:t.id,minX:o-e/2-8,maxX:o+e/2+8,minY:r-n/2-8,maxY:r+n/2+8,visualXHalfExtent:f?n/2+8:e/2+8}}),u=n((t,e,n,o)=>{let r=c.find(n=>n.orientation===t&&Math.abs(n.coord-e)<1);return r||(r={id:`pipe-${t}-${e.toFixed(0)}`,orientation:t,coord:e,spanMin:n,spanMax:o,tracks:[]},c.push(r)),r.spanMin=Math.min(r.spanMin,n),r.spanMax=Math.max(r.spanMax,o),r},"getOrAddPipe"),h=n((t,e)=>{const n=t.width??10,o=t.height??10,r=t.x??0,s=t.y??0;switch(e){case"top":return{x:r,y:s-o/2};case"bottom":return{x:r,y:s+o/2};case"left":return{x:r-n/2,y:s};case"right":return{x:r+n/2,y:s}}},"portForSide"),g=n((t,e,n)=>h(t,In(t,e,n?"bottom":"top")),"getOrthogonalPort"),p=[],m=[],x=new Set,y=n((t,e,n)=>{if(0===p.length)return 0;const o=Math.abs(e.y-n.y)<xn,r=Math.abs(e.x-n.x)<xn;if(!o&&!r)return 0;let s=0;if(o){const o=e.y,r=Math.min(e.x,n.x)-xn,i=Math.max(e.x,n.x)+xn;if(i<=r)return 0;for(const e of p)e.edgeIndex!==t&&"vertical"===e.orientation&&(e.pipe.coord<r||e.pipe.coord>i||e.from-xn<=o&&e.to+xn>=o&&(s+=1e3))}else if(r){const o=e.x,r=Math.min(e.y,n.y)-xn,i=Math.max(e.y,n.y)+xn;if(i<=r)return 0;for(const e of p)e.edgeIndex!==t&&"horizontal"===e.orientation&&(e.pipe.coord<r||e.pipe.coord>i||e.from-xn<=o&&e.to+xn>=o&&(s+=1e3))}return s},"crossingPenalty"),b=s.map((t,e)=>{if(!t.start||!t.end)return{idx:e,crossLane:0,dx:0,dy:0};const n=i.get(t.start),o=i.get(t.end),r=a.get(t.start),s=a.get(t.end);return{idx:e,crossLane:r&&s&&r.id!==s.id?1:0,dx:n&&o?Math.abs((o.x??0)-(n.x??0)):0,dy:n&&o?Math.abs((o.y??0)-(n.y??0)):0}}).sort((t,e)=>{if(t.crossLane!==e.crossLane)return e.crossLane-t.crossLane;const n=t.dx+t.dy,o=e.dx+e.dy;return Math.abs(n-o)>1?n-o:t.idx-e.idx}).map(t=>t.idx),M=n((t,e,n,o)=>{const r=Math.min(t.x,e.x),s=Math.max(t.x,e.x),i=Math.min(t.y,e.y),a=Math.max(t.y,e.y);return!!l.find(c=>(!n||c.nodeId!==n)&&((!o||c.nodeId!==o)&&(Math.abs(t.x-e.x)>xn?c.minY<t.y&&c.maxY>t.y&&c.maxX>r&&c.minX<s:c.minX<t.x&&c.maxX>t.x&&c.maxY>i&&c.minY<a)))},"isSegmentBlocked"),I=new Map,S=new Map;for(const t of s)t.start&&t.end&&t.start!==t.end&&(S.set(t.start,(S.get(t.start)??0)+1),S.set(t.end,(S.get(t.end)??0)+1));const w=n((t,e)=>In(t,e,"bottom"),"determineSide"),v=new Map;for(const[t,e]of s.entries()){if(!e.start||!e.end||e.start===e.end)continue;if(e.points&&e.points.length>0)continue;const n=i.get(e.start),o=i.get(e.end);if(!n||!o)continue;const r=(o.x??0)-(n.x??0),s=(o.y??0)-(n.y??0);v.set(t,{edgeIdx:t,srcId:e.start,dstId:e.end,srcSide:w(n,{x:o.x??0,y:o.y??0}),dstSide:w(o,{x:n.x??0,y:n.y??0}),absDx:Math.abs(r),absDy:Math.abs(s),dxSign:Math.sign(r),dySign:Math.sign(s)})}const C=n(t=>"top"===t.srcSide||"bottom"===t.srcSide?0===t.absDx?1/0:t.absDy/t.absDx:0===t.absDy?1/0:t.absDx/t.absDy,"preferenceStrength"),L=n(t=>"top"===t.srcSide||"bottom"===t.srcSide?t.dxSign>=0?"right":"left":t.dySign>=0?"bottom":"top","secondarySide"),k=new Map;for(const t of v.values()){const e=`${t.srcId}:${t.srcSide}`;k.has(e)||k.set(e,[]),k.get(e).push(t)}const O=new Map,R=n((t,e)=>`${t}:${e}`,"loadKey");for(const t of v.values())O.set(R(t.srcId,t.srcSide),(O.get(R(t.srcId,t.srcSide))??0)+1),O.set(R(t.dstId,t.dstSide),(O.get(R(t.dstId,t.dstSide))??0)+1);for(const t of k.values())if(!(t.length<2)){t.sort((t,e)=>{const n=C(t),o=C(e);return Math.abs(n-o)>1e-9?o-n:t.edgeIdx-e.edgeIdx});for(let e=1;e<t.length;e++){const n=t[e],o=L(n),r=O.get(R(n.srcId,n.srcSide))??0,s=O.get(R(n.srcId,o))??0;s>=r||(O.set(R(n.srcId,n.srcSide),r-1),O.set(R(n.srcId,o),s+1),n.srcSide=o)}}const N=n(t=>{const e=t?.shape;return"question"===e||"diamond"===e},"isDiamondNode"),T=new Map;for(const t of v.values())T.has(t.dstId)||T.set(t.dstId,new Set),T.get(t.dstId).add(t.dstSide);for(const t of v.values()){if(!N(i.get(t.srcId)))continue;const e=T.get(t.srcId);if(!e?.has(t.srcSide))continue;const n=L(t);if(e.has(n)||(O.get(R(t.srcId,n))??0)>0)continue;const o=O.get(R(t.srcId,t.srcSide))??0;O.set(R(t.srcId,t.srcSide),Math.max(0,o-1)),O.set(R(t.srcId,n),1),t.srcSide=n}for(const t of v.values()){const{edgeIdx:e,srcId:n,dstId:o,srcSide:r,dstSide:s}=t,a=i.get(n),c=i.get(o),f=`${n}:${r}:src`,d="top"===r||"bottom"===r?c.x??0:c.y??0;I.has(f)||I.set(f,[]),I.get(f).push({edgeIdx:e,oppositeCoord:d});const l=`${o}:${s}:dst`,u="top"===s||"bottom"===s?a.x??0:a.y??0;I.has(l)||I.set(l,[]),I.get(l).push({edgeIdx:e,oppositeCoord:u})}const B=new Map;for(const[t,e]of I){if(e.length<2)continue;e.sort((t,e)=>t.oppositeCoord-e.oppositeCoord);const n=t.split(":"),o=n.slice(0,-2).join(":"),r=n[n.length-2],s=n[n.length-1],a=i.get(o);if(!a)continue;const c="left"===r||"right"===r?a.height??10:a.width??10,f=a.shape,d="question"===f||"diamond"===f?.3*c:c,l=20,u=Math.min(l,Math.max(8,d/(e.length+1))),h=-(u*(e.length-1))/2;for(const[t,n]of e.entries()){const e=h+t*u,o=`${n.edgeIdx}:${s}`;B.set(o,e)}}const F=n(t=>Boolean(s[t]?.labelNodeId),"edgeHasLabelNode"),E=n((t,e)=>!!t&&((I.get(`${t}:${e}:src`)??[]).some(({edgeIdx:t})=>F(t))||(I.get(`${t}:${e}:dst`)??[]).some(({edgeIdx:t})=>F(t))),"faceHasLabelNode"),$=n((t,e,n)=>"top"===e||"bottom"===e?{x:t.x+n,y:t.y}:{x:t.x,y:t.y+n},"applyPortOffset"),Y=n((t,e,n)=>{const o=v.get(t),r={x:n.x??0,y:n.y??0},s={x:e.x??0,y:e.y??0},i=o?.srcSide??w(e,r),a=o?.dstSide??w(n,s);let c=o?h(e,o.srcSide):g(e,r,!0),f=o?h(n,o.dstSide):g(n,s,!1);const d=B.get(`${t}:src`),l=B.get(`${t}:dst`);return void 0!==d&&(c=$(c,i,d)),void 0!==l&&(f=$(f,a,l)),{pSrcPort:c,pDstPort:f,srcSide:i,dstSide:a}},"portsForEdge");for(const t of b){const e=s[t];if(m[t]=[],!e.start||!e.end)continue;if(e.points&&e.points.length>0)continue;if(e.start===e.end)continue;const o=i.get(e.start),r=i.get(e.end);if(!o||!r)continue;const{pSrcPort:a,pDstPort:d,srcSide:h,dstSide:g}=Y(t,o,r),b={...a},w={...d},v="top"===h||"bottom"===h,C="top"===g||"bottom"===g;if(v){const t=a.y>(o.y??0);b.y=t?a.y+Mn:a.y-Mn}else{const t=a.x>(o.x??0);b.x=t?a.x+Mn:a.x-Mn}if(C){const t=d.y>(r.y??0);w.y=t?d.y+Mn:d.y-Mn}else{const t=d.x>(r.x??0);w.x=t?d.x+Mn:d.x-Mn}const L=n((t,e)=>{for(const n of l)if(!e.includes(n.nodeId)&&t.x>n.minX&&t.x<n.maxX&&t.y>n.minY&&t.y<n.maxY)return{inside:!0,obstacle:n};return{inside:!1}},"isPointInObstacle"),k=n((t,e,n,o,r)=>{if(r){const r=t.y>(e.y??0);return{x:(n.x??0)>=t.x?o.maxX+yn:o.minX-yn,y:r?o.maxY+bn:o.minY-bn,leavesPositiveSide:r}}const s=t.x>(e.x??0),i=(n.y??0)>=t.y;return{x:s?o.maxX+yn:o.minX-yn,y:i?o.maxY+bn:o.minY-bn,leavesPositiveSide:s}},"obstacleDetour");let O=[];const R=[e.start,e.end],N=L(b,R);if(N.inside&&N.obstacle){const t=N.obstacle;if(v){const e=k(a,o,r,t,!0);b.x=e.x,b.y=e.y;const n=e.leavesPositiveSide?Math.min(t.minY-2,a.y+Mn):Math.max(t.maxY+2,a.y-Mn);O=[{x:a.x,y:n},{x:e.x,y:n},{x:e.x,y:e.y}]}else{const e=k(a,o,r,t,!1),n=e.leavesPositiveSide?Math.min(t.minX-2,a.x+Mn):Math.max(t.maxX+2,a.x-Mn);b.x=e.x,b.y=e.y,O=[{x:n,y:a.y},{x:n,y:e.y},{x:e.x,y:e.y}]}}let T=[];const F=L(w,R);if(F.inside&&F.obstacle){const t=F.obstacle;if(C){const e=k(d,r,o,t,!0);w.x=e.x,w.y=e.y,T=[{x:e.x,y:e.y},{x:d.x,y:e.y}]}else{const e=k(d,r,o,t,!1);w.x=e.x,w.y=e.y,T=[{x:e.x,y:e.y},{x:e.x,y:d.y}]}}if(0===O.length&&0===T.length){const n=yn,o=Math.abs(b.x-w.x)<n,r=Math.abs(b.y-w.y)<n,s=void 0!==B.get(`${t}:src`)||void 0!==B.get(`${t}:dst`),i=(I.get(`${e.start??""}:${h}:src`)?.length??0)+(I.get(`${e.start??""}:${h}:dst`)?.length??0),c=(I.get(`${e.end??""}:${g}:src`)?.length??0)+(I.get(`${e.end??""}:${g}:dst`)?.length??0),f=i>1||c>1,l=S.get(e.start??"")??0,u=S.get(e.end??"")??0,m=i>1&&E(e.start,h)||c>1&&E(e.end,g);if((o||r)&&!s&&(!f||f&&!m&&(i<=1||l<=2)&&(c<=1||u<=2))){if(!M(a,d,e.start,e.end)){e.points=[{...a},{...b},{...w},{...d}],x.add(t);const n=r?"horizontal":"vertical",o=r?a.y:a.x,s=r?Math.min(a.x,d.x):Math.min(a.y,d.y),i=r?Math.max(a.x,d.x):Math.max(a.y,d.y),c={id:`fast-path-${n}-${o.toFixed(0)}-${t}`,orientation:n,coord:o,spanMin:s,spanMax:i,tracks:[]};p.push({edgeIndex:t,segmentIndex:0,orientation:n,pipe:c,trackIndex:0,from:s,to:i});continue}}}const $=u("vertical",b.x,b.y,b.y);b.x=$.coord;const X=u("vertical",w.x,w.y,w.y);w.x=X.coord;let z=Math.min(b.x,w.x)-50,P=Math.max(b.x,w.x)+50,G=Math.min(b.y,w.y)-50,D=Math.max(b.y,w.y)+50;for(const t of l){const e=Math.min(b.x,w.x),n=Math.max(b.x,w.x),o=Math.min(b.y,w.y),r=Math.max(b.y,w.y);t.minX<n&&t.maxX>e&&t.minY<r&&t.maxY>o&&(z=Math.min(z,t.minX-25),P=Math.max(P,t.maxX+25),G=Math.min(G,t.minY-25),D=Math.max(D,t.maxY+25))}for(const t of l){if(t.maxX<z||t.minX>P||t.maxY<G||t.minY>D)continue;const e=yn;u("horizontal",t.minY-e,z,P),u("horizontal",t.maxY+e,z,P);const n=bn;u("vertical",t.minX-n,G,D),u("vertical",t.maxX+n,G,D)}u("horizontal",b.y,z,P),u("horizontal",w.y,z,P);const A=c.filter(t=>"horizontal"===t.orientation&&t.coord>=G&&t.coord<=D),H=c.filter(t=>"vertical"===t.orientation&&t.coord>=z&&t.coord<=P),j=n((t,e)=>`${t.toFixed(1)},${e.toFixed(1)}`,"getKey"),_=j(b.x,b.y),V=j(w.x,w.y),W=new Map,K=new Map,q=new Map,U=new Set,J=[];W.set(_,0),q.set(_,"n"),J.push({key:_,f:Math.hypot(w.x-b.x,w.y-b.y),pt:b}),U.add(_);let Z=[];const Q=n((t,n)=>M(t,n,e.start,e.end),"checkSegmentBlocked"),tt={x:w.x,y:b.y},et=Q(b,tt),nt=Q(tt,w),ot=et||nt,rt={x:b.x,y:w.y},st=Q(b,rt),it=Q(rt,w);if(ot?st||it||(Z=Math.abs(b.x-w.x)<xn?[b,w]:[b,rt,w]):Z=Math.abs(b.y-w.y)<xn||Math.abs(b.x-w.x)<xn?[b,w]:[b,tt,w],0===Z.length)for(;J.length>0;){J.sort((t,e)=>t.f-e.f);const n=J.shift();if(U.delete(n.key),n.key===V){let t=V,e=w;for(Z=[e];K.has(t);){const n=K.get(t);Z.unshift(n),e=n,t=j(n.x,n.y)}break}const o=n.pt.x,r=n.pt.y,s=H.sort((t,e)=>t.coord-e.coord),i=s.findIndex(t=>Math.abs(t.coord-o)<1),a=A.sort((t,e)=>t.coord-e.coord),c=a.findIndex(t=>Math.abs(t.coord-r)<1),f=[];i>0&&f.push({x:s[i-1].coord,y:r}),i>=0&&i<s.length-1&&f.push({x:s[i+1].coord,y:r}),c>0&&f.push({x:o,y:a[c-1].coord}),c>=0&&c<a.length-1&&f.push({x:o,y:a[c+1].coord});for(const s of f){const i=Math.min(o,s.x),a=Math.max(o,s.x),c=Math.min(r,s.y),f=Math.max(r,s.y);if(l.some(t=>t.nodeId!==e.start&&t.nodeId!==e.end&&(i!==a?t.minY<r&&t.maxY>r&&t.maxX>i&&t.minX<a:t.minX<o&&t.maxX>o&&t.maxY>c&&t.minY<f)))continue;const d=j(s.x,s.y),u=Math.abs(s.x-o)+Math.abs(s.y-r),h=y(t,n.pt,s);let g=0;const p=w.x-b.x,m=w.y-b.y,x=s.x-o,M=s.y-r;(m>10&&M<-5||m<-10&&M>5)&&(g=100*Math.abs(M)),(p>10&&x<-5||p<-10&&x>5)&&(g+=50*Math.abs(x));let I=0;const S=q.get(n.key)??"n",v=Math.abs(x)>xn?"h":"v";"n"!==S&&S!==v&&(I=50);const C=u+h+g+I,L=(W.get(n.key)??1/0)+C,k=Math.abs(w.x-s.x)+Math.abs(w.y-s.y);if(L<(W.get(d)??1/0))if(K.set(d,n.pt),W.set(d,L),q.set(d,v),U.has(d)){const t=J.findIndex(t=>t.key===d);-1!==t&&(J[t].f=L+k)}else J.push({key:d,f:L+k,pt:s}),U.add(d)}}if(0===Z.length&&(Z=[b,{x:b.x,y:w.y},w]),Z.length>4){const t=Z[0],e=Z[Z.length-1];let o=Math.min(t.x,e.x),r=Math.max(t.x,e.x),s=Math.min(t.y,e.y),i=Math.max(t.y,e.y);for(const t of Z)o=Math.min(o,t.x),r=Math.max(r,t.x),s=Math.min(s,t.y),i=Math.max(i,t.y);const a=r>Math.max(t.x,e.x),c=o<Math.min(t.x,e.x);if(f){const n=bn;if(a){const o=Math.max(t.x,e.x),s=Math.min(t.y,e.y),i=Math.max(t.y,e.y),a=l.filter(t=>t.minX<o&&t.maxX>o&&t.minY<i&&t.maxY>s);if(a.length>0){let o=Math.max(t.x,e.x);for(const t of a){const e=(t.minX+t.maxX)/2;if(void 0===t.visualXHalfExtent||isNaN(t.visualXHalfExtent))continue;const r=e+t.visualXHalfExtent+n;o=Math.max(o,r)}isNaN(o)||(r=o)}}if(c){const r=l.filter(o=>o.minX<Math.min(t.x,e.x)+n&&o.minY<Math.max(t.y,e.y)&&o.maxY>Math.min(t.y,e.y));if(r.length>0){let s=Math.min(t.x,e.x);for(const t of r){const e=(t.minX+t.maxX)/2-t.visualXHalfExtent-n;s=Math.min(s,e)}o=s}}}const d=n(n=>{const o=e.y>t.y,r=l.filter(n=>{const o=Math.min(t.x,e.x)<n.maxX&&Math.max(t.x,e.x)>n.minX,r=Math.min(t.y,e.y)<n.maxY&&Math.max(t.y,e.y)>n.minY;return o&&r});let s=r;if(f&&r.length>0){const t=r.filter(t=>t.minX<n&&t.maxX>n);t.length>0&&(s=t)}if(0===s.length)return e.y;if(o){const t=Math.max(...s.map(t=>t.maxY))+15;if(t<e.y-xn)return t}else{const t=Math.min(...s.map(t=>t.minY))-15;if(t>e.y+xn)return t}return e.y},"findBestReturnY"),u=n(n=>{const o=d(n),r={x:n,y:t.y},s={x:n,y:o},i={x:e.x,y:o},a=Q(t,r),c=Q(r,s),f=Q(s,i),l=o!==e.y&&Q(i,e);return a||c||f||l?null:Math.abs(o-e.y)<xn?[t,r,s,e]:[t,r,s,i,e]},"trySimplifyWithDetourX"),h=a&&!c?u(r):c&&!a?u(o):null;h&&(Z=h)}const at=[a,...O,...Z,...T.reverse(),d];if(at.length>=3){const t=at[at.length-1],e=at[at.length-2],n=at[at.length-3],o=Math.abs(n.y-e.y)<xn&&Math.abs(e.y-t.y)<xn,r=Math.abs(n.x-e.x)<xn&&Math.abs(e.x-t.x)<xn;if(o){const o=Math.sign(e.x-n.x),r=Math.sign(t.x-n.x);0!==o&&o===r&&Math.abs(e.x-n.x)>Math.abs(t.x-n.x)&&at.splice(-2,1)}else if(r){const o=Math.sign(e.y-n.y),r=Math.sign(t.y-n.y);0!==o&&o===r&&Math.abs(e.y-n.y)>Math.abs(t.y-n.y)&&at.splice(-2,1)}}const ct=[at[0]];for(let t=1;t<at.length-1;t++){if(1===t){ct.push(at[t]);continue}const e=ct[ct.length-1],n=at[t],o=at[t+1];if(Math.abs(e.y-n.y)<xn&&Math.abs(n.y-o.y)<xn){if(n.x>e.x!==o.x>n.x){ct.push(n);continue}continue}if(Math.abs(e.x-n.x)<xn&&Math.abs(n.x-o.x)<xn){if(n.y>e.y!==o.y>n.y){ct.push(n);continue}continue}ct.push(n)}ct.push(at[at.length-1]);for(let e=0;e<ct.length-1;e++){const n=ct[e],o=ct[e+1],r=Math.abs(n.x-o.x)<xn?"vertical":"horizontal",s="vertical"===r?n.x:n.y,i="vertical"===r?Math.min(n.y,o.y):Math.min(n.x,o.x),a="vertical"===r?Math.max(n.y,o.y):Math.max(n.x,o.x),c=u(r,s,i,a),f={edgeIndex:t,segmentIndex:e,orientation:r,pipe:c,trackIndex:0,from:i,to:a};p.push(f),m[t].push(p.length-1),c.tracks[0]||(c.tracks[0]={index:0,coord:c.coord,segments:[]}),c.tracks[0].segments.push({edgeIndex:t,segmentIndex:e,from:i,to:a})}}const X=n((t,e)=>t.from<e.to&&e.from<t.to,"segmentsOverlap"),z=n((t,e,n,o)=>{const r=!o.segments.some(n=>(n.edgeIndex!==e.edgeIndex||n.segmentIndex!==e.segmentIndex)&&X(n,t)),s=!n.segments.some(n=>(n.edgeIndex!==t.edgeIndex||n.segmentIndex!==t.segmentIndex)&&X(n,e));return!(!r||!s)&&(t.trackIndex=o.index,e.trackIndex=n.index,n.segments=[...n.segments.filter(e=>e.edgeIndex!==t.edgeIndex||e.segmentIndex!==t.segmentIndex),{edgeIndex:e.edgeIndex,segmentIndex:e.segmentIndex,from:e.from,to:e.to}],o.segments=[...o.segments.filter(t=>t.edgeIndex!==e.edgeIndex||t.segmentIndex!==e.segmentIndex),{edgeIndex:t.edgeIndex,segmentIndex:t.segmentIndex,from:t.from,to:t.to}],!0)},"trySwapSegmentsAcrossTracks"),P=n(t=>{const e=t.tracks.length;return t.tracks[e]={index:e,coord:t.coord,segments:[]},e},"createNewTrack"),G=n((t,e)=>{const n=t.pipe.tracks[t.trackIndex];n.segments=n.segments.filter(e=>e.edgeIndex!==t.edgeIndex||e.segmentIndex!==t.segmentIndex),t.trackIndex=e;t.pipe.tracks[e].segments.push({edgeIndex:t.edgeIndex,segmentIndex:t.segmentIndex,from:t.from,to:t.to})},"moveSegmentToTrack"),D=n((t,e)=>{const n=m[t.edgeIndex];for(const o of n){const n=p[o];n.pipe===t.pipe&&G(n,e)}},"moveSegmentChainToTrack"),A=n(t=>{const e=m[t.edgeIndex],n=e.indexOf(p.indexOf(t)),o=[];return n>0&&o.push(p[e[n-1]]),n<e.length-1&&o.push(p[e[n+1]]),o},"getAdjacentSegmentsAlongEdge"),H=n((t,e)=>{if(t.orientation===e.orientation)return!1;const n="horizontal"===t.orientation?t:e,o="horizontal"===t.orientation?e:t;return o.pipe.coord>n.from&&o.pipe.coord<n.to&&n.pipe.coord>o.from&&n.pipe.coord<o.to},"haveAnyCrossing"),j=n((t,e)=>{for(const n of t.tracks){if(!n.segments.some(t=>(t.edgeIndex!==e.edgeIndex||t.segmentIndex!==e.segmentIndex)&&X(t,e)))return n.index}return-1},"findAvailableTrack"),_=n((t,e)=>{if(t.trackIndex===e.trackIndex)return X(t,e);const n=A(t),o=A(e);return n.some(t=>o.some(e=>H(t,e)))},"segmentsConflict"),V=n((t,e,n)=>{if(z(t,e,t.pipe.tracks[t.trackIndex],e.pipe.tracks[e.trackIndex]))return;const o=j(t.pipe,e);n(e,-1!==o?o:P(t.pipe))},"resolveTrackConflict"),W=n(t=>{let e=0;for(let n=0;n<t.length;n++)for(let o=n+1;o<t.length;o++){const r=t[n],s=t[o];r.pipe===s.pipe&&(_(r,s)&&(e++,V(r,s,D)))}return e},"resolveHandleConflicts"),K=new Map,q=n(t=>{if(K.has(t))return K.get(t);const e=m[t];if(0===e.length){const e={dest:0,deviation:0,base:0,delta:0};return K.set(t,e),e}const n=p[e[0]].pipe.coord;let o=n;for(let t=1;t<e.length;t++){const r=p[e[t]];if("horizontal"===r.orientation){const t=r.from,e=r.to;o=Math.abs(t-n)>Math.abs(e-n)?t:e;break}}const r={dest:o,deviation:Math.abs(o-n),base:n,delta:o-n};return K.set(t,r),r},"getDestInfo"),U=n(()=>{let t=0;const e=new Map;for(const[t,n]of s.entries())0!==m[t].length&&n.start&&(e.has(n.start)||e.set(n.start,[]),e.get(n.start).push(t));const o=n(t=>{const e=s[t];if(!e.start||!e.end)return 0;const n=i.get(e.start),o=i.get(e.end);if(!n||!o)return 0;const r=(o.x??0)-(n.x??0),a=(o.y??0)-(n.y??0);return Math.abs(r)+Math.abs(a)},"getEdgeDistance");for(const n of e.values()){n.sort((t,e)=>{const n=q(t),r=q(e);if(Math.abs(n.deviation-r.deviation)>1)return n.deviation-r.deviation;if(Math.abs(n.dest-r.dest)>1)return n.dest-r.dest;const s=o(t),i=o(e);if(Math.abs(s-i)>1)return i-s;const a=m[t].length,c=m[e].length;if(a!==c)return a-c;if(1===a){const n=m[t][0],o=m[e][0];if(p[n]&&p[o]){const t=p[n],e=p[o],r=Math.abs(t.to-t.from),s=Math.abs(e.to-e.from);if(Math.abs(r-s)>1)return r-s}}return 0});const e=n.map(t=>p[m[t][0]]);t+=W(e)}return t},"fixSourceHandleCrossings"),J=n(()=>{let t=0;const e=new Map;for(const[t,n]of s.entries()){0!==m[t].length&&(n.end&&(e.has(n.end)||e.set(n.end,[]),e.get(n.end).push(t)))}for(const o of e.values()){o.sort((t,e)=>{const o=n(t=>{const e=m[t];if(e.length<2)return 0;const n=p[e[e.length-2]];return Math.abs(n.to-n.from)},"getDist"),r=o(t),s=o(e);return Math.abs(r-s)>.1?r-s:t-e});const e=o.map(t=>p[m[t][m[t].length-1]]);t+=W(e)}return t},"fixTargetHandleCrossings"),Z=n(()=>{let t=0;for(const e of c){const n=[];for(const t of e.tracks)for(const e of t.segments){const t=m[e.edgeIndex].find(t=>p[t].segmentIndex===e.segmentIndex);void 0!==t&&n.push(p[t])}n.sort((t,e)=>t.edgeIndex-e.edgeIndex||t.segmentIndex-e.segmentIndex);for(let e=0;e<n.length;e++)for(let o=e+1;o<n.length;o++){const r=n[e],s=n[o];_(r,s)&&(t++,V(r,s,G))}}return t},"fixPipeCrossings");let Q=0;for(;Q<10;){let t=0;if(t+=U(),t+=J(),t+=Z(),0===t)break;Q++}const tt=new Map;for(const t of c){const e=[];t.tracks.forEach(t=>{t.segments.forEach(n=>{e.push({edgeIndex:n.edgeIndex,segmentIndex:n.segmentIndex,trackIndex:t.index,from:n.from,to:n.to})})}),e.sort((t,e)=>t.from-e.from);const o=[];if(e.length>0){let t=[e[0]],n=e[0].to;for(let r=1;r<e.length;r++){const s=e[r];s.from<n?(t.push(s),n=Math.max(n,s.to)):(o.push(t),t=[s],n=s.to)}o.push(t)}for(const e of o){const o=new Set;e.forEach(t=>o.add(t.trackIndex));const r=new Map;e.forEach(t=>{const e=q(t.edgeIndex);r.set(t.trackIndex,(r.get(t.trackIndex)??0)+e.delta)});const s=[...o].filter(t=>(r.get(t)??0)<-1),i=[...o].filter(t=>(r.get(t)??0)>1),a=[...o].filter(t=>Math.abs(r.get(t)??0)<=1);s.sort((t,e)=>(r.get(e)??0)-(r.get(t)??0)),i.sort((t,e)=>(r.get(t)??0)-(r.get(e)??0));const c=n((n,o)=>{e.filter(t=>t.trackIndex===n).forEach(e=>{const n=x.has(e.edgeIndex)?t.coord:o;tt.set(`${e.edgeIndex}-${e.segmentIndex}`,n)})},"assignCoord");let f=0;for(const e of s)f++,c(e,t.coord-10*f);if(0===a.length&&o.size>0){const t=[...o].sort((t,e)=>Math.abs(r.get(t)??0)-Math.abs(r.get(e)??0))[0],e=s.indexOf(t);-1!==e&&s.splice(e,1);const n=i.indexOf(t);-1!==n&&i.splice(n,1),a.push(t)}let d=0;for(const e of a){if(0===d)c(e,t.coord);else{const n=d%2==1?1:-1,o=Math.ceil(d/2);c(e,t.coord+n*o*10*.5)}d++}let l=0;for(const e of i)l++,c(e,t.coord+10*l)}}for(const[t,e]of s.entries()){const n=m[t]??[];if(0===n.length)continue;const o=[],r=i.get(e.start),s=i.get(e.end),{pSrcPort:a,pDstPort:c}=Y(t,r,s),f=n.map(t=>{const e=p[t],n=tt.get(`${e.edgeIndex}-${e.segmentIndex}`)??e.pipe.coord;return{orient:e.orientation,coord:n,from:e.from,to:e.to}});o.push(a);for(let t=0;t<f.length;t++){const e=f[t],n=o[o.length-1],r="vertical"===e.orient?n.y:n.x,s="vertical"===e.orient?n.x:n.y,i=f[t+1],a=t<f.length-1;if(Math.abs(s-e.coord)>xn&&o.push(wn(e,r)),a&&i.orient===e.orient)if(Math.abs(e.coord-i.coord)>xn){const t="vertical"===e.orient?(r+i.from)/2:Sn(e,i);o.push(wn(e,t),wn(i,t))}else 0!==t&&t!==f.length-2||o.push(wn(e,Sn(e,i)));else if(a)o.push(wn(e,i.coord));else{const t=Math.abs(e.from-r)<Math.abs(e.to-r)?e.to:e.from;o.push(wn(e,t))}}const d=o[o.length-1];(Math.abs(d.x-c.x)>xn||Math.abs(d.y-c.y)>xn)&&o.push(c);const l=[];o.length>0&&l.push(o[0]);for(let t=1;t<o.length;t++){const e=o[t],n=l[l.length-1];(Math.abs(e.x-n.x)>xn||Math.abs(e.y-n.y)>xn)&&l.push(e)}e.points=l}for(const t of s){const e=t.__originalEdge;e&&t.points&&(e.points=t.points)}t.edges=(t.edges??[]).filter(t=>!t.isLayoutOnly);const et=n((t,e)=>{const n=e.x??0,o=e.y??0,r=e.width??0,s=e.height??0;if(r<=0||s<=0)return t;const i=n-r/2,a=n+r/2,c=o-s/2,f=o+s/2;if(t.x<i||t.x>a||t.y<c||t.y>f)return t;const d=t.x-i,l=a-t.x,u=t.y-c,h=f-t.y,g=Math.min(d,l,u,h);return g===d?{x:i,y:t.y}:g===l?{x:a,y:t.y}:g===u?{x:t.x,y:c}:{x:t.x,y:f}},"nodeBoundaryClamp");for(const e of t.edges){const t=e.points;if(!t||t.length<2)continue;const n=e.start,o=e.end,r=n?i.get(n):void 0,s=o?i.get(o):void 0;r&&(t[0]=et(t[0],r)),s&&(t[t.length-1]=et(t[t.length-1],s))}return t}function Cn(t){return t.direction??"TB"}function Ln(t){const e=f(t),n=t.config.flowchart?.nodeSpacing??40,o=t.config.flowchart?.rankSpacing??100,r=t.config.swimlane?.ignoreCrossLaneEdges??!0,s=t.config.swimlane?.optimizeRanksByCrossings??!0,i=t.config.swimlane?.automaticLaneOrdering??!1,a=Cn(t),{ordered:c,coordinates:l}=mn(e,{nodeGap:n,layerGap:o,ignoreCrossLaneEdges:r,optimizeRanksByCrossings:s,automaticLaneOrdering:i,direction:a});d(e,c,l,{nodeGap:n,layerGap:o});for(const e of t.edges??[])delete e.points;vn(t,a);for(const e of t.edges??[])e.curve&&"basis"!==e.curve||(e.curve="rounded");return se(t,a),re(t),a}function kn(t){c(t);const e=l(t);t.nodes=e.nodes,t.edges=e.edges}n(In,"chooseOrthogonalSide"),n(Sn,"sharedLineEndpointCoord"),n(wn,"pointOnLine"),n(vn,"routeEdgesOrthogonal"),n(Cn,"getSwimlaneDirection"),n(Ln,"runSwimlaneLayoutCore"),n(kn,"prepareSwimlaneLayout");var On=e({prepareLayout:kn,runLayoutCore:Ln,afterPaint:r});export{On as render};
|
|
1
|
+
import{a as t}from"./chunk-4EMNKR2T-D1yHHif8.js";import{c as e}from"./chunk-ZCHMQSOR-Bvjutmxm.js";import{_ as n,l as o}from"./mermaid.core-DRk6tt5W.js";import"./graph-rGqC_56m.js";import"./isSymbol-D2gNAbOe.js";import"./isUndefined--MLpwE__.js";import"./index-BpcqEzEG.js";import"react/jsx-runtime";import"react";import"./enums.js";import"./commons-iref2pEJ.js";import"./settings-CBGV-lz3.js";import"./constants.js";import"./LoaderLayer-ECtsj85k.js";import"./websocket-CdeP8N_S.js";import"./index-2PTQqTnK.js";import"motion/react";import"react-dom";import"swr";import"@ably/spaces";import"@ably/spaces/react";import"ably";import"ably/liveobjects";import"ably/react";import"@ably/spaces/dist/mjs/react";import"./string-DPJhNSkw.js";function r(e,{measure:n}){const o=e.config?.swimlane?.lineHops;if(!1===o)return;const r="gap"===o?"gap":"arc",s=e.edges.filter(t=>Array.isArray(t.points)&&t.points.length>=2).map(t=>({id:t.id,points:t.points,curve:t.curve,arrowTypeStart:t.arrowTypeStart,arrowTypeEnd:t.arrowTypeEnd}));t(n.groups.edgePaths,s,{enabled:!0,jumpRadius:6,jumpStyle:r})}n(r,"applySwimlaneLineJumps");var s="__swimlane_default__";function i(t){return Math.max(t.padding??20,20)}function a(t){const{x:e,y:n,width:o,height:r}=t,s=t.swimlaneContentTop;if("number"!=typeof e||"number"!=typeof n||"number"!=typeof o||"number"!=typeof r||"number"!=typeof s||!Number.isFinite(e)||!Number.isFinite(n)||!Number.isFinite(o)||!Number.isFinite(r)||!Number.isFinite(s)||o<=0||r<=0)return void delete t.groupTitleRect;const i=n-r/2,a=Math.min(s,n+r/2),c=i+Math.min(21,Math.max(0,a-i));c<=i?delete t.groupTitleRect:t.groupTitleRect={left:e-o/2,right:e+o/2,top:i,bottom:c}}function c(t){const e=t.direction,n=t.nodes??=[];for(const n of t.nodes??[])n.isGroup&&!n.parentId&&(n.shape="swimlane",e&&(n.direction=e));const o=n.filter(t=>!t.isGroup&&!t.parentId);if(0===o.length)return;let r=n.find(t=>t.id===s);r?r.isGroup&&(r.shape="swimlane",e&&(r.direction=e)):(r={id:s,label:"",isGroup:!0,shape:"swimlane",padding:20,look:t.config?.look,colorIndex:n.reduce((t,e)=>Math.max(t,e.colorIndex??-1),-1)+1,...e?{direction:e}:{}},n.push(r));for(const t of o)t.parentId=s}function f(t){const e=new Map;for(const n of t.nodes??[])e.set(n.id,n);const n=[];for(const e of t.edges??[]){const t="string"==typeof e.start?e.start:void 0,o="string"==typeof e.end?e.end:void 0;t&&o&&(e.labelNodeId||n.push({id:e.id,src:t,dst:o,ref:e}))}const o=t.nodes??[],r=o.filter(t=>t.isGroup),s=o.filter(t=>!t.isGroup);return{nodes:[...[...r].reverse(),...s].map(t=>t.id),edges:n,layout:t,nodeById:e}}function d(t,e,n,o){const{layout:r}=t,s=t.nodeById,c=o?.layerGap??100,f=o?.nodeGap??40;let d=0;for(const t of e.layers){let e=0;for(const o of t){const t=s.get(o);if(!t){e++;continue}t.layer=d,t.order=e;const r=n.x[o]??e*f,i=n.y[o]??d*c;t.x=r,t.y=i,e++}d++}const l=r.nodes??[],u=new Map,h=[];for(const t of l){if(!t?.isGroup)continue;t.parentId||h.push(t);const e=l.filter(e=>e.parentId===t.id);let o=1/0,r=-1/0,s=1/0,a=-1/0;for(const t of e){const e=t.x??n.x[t.id],i=t.y??n.y[t.id],c=t.width??0,f=t.height??0;null!=e&&null!=i&&(o=Math.min(o,e-c/2),r=Math.max(r,e+c/2),s=Math.min(s,i-f/2),a=Math.max(a,i+f/2))}if(o===1/0||s===1/0)t.x=t.x??0,t.y=t.y??0,t.width=t.width??0,t.height=t.height??0;else{const e=t.padding??20,n=t.parentId?e:2*i(t),c=e,f=Math.max(0,r-o)+n,d=Math.max(0,a-s)+c,l=(o+r)/2,h=(s+a)/2;t.x=l,t.y=h,t.width=f,t.height=d,u.set(t.id,{minX:o,maxX:r,minY:s,maxY:a})}}if(h.length>0&&u.size>0){let t=1/0,e=-1/0,n=0;for(const o of h){const r=o.padding??20;r>n&&(n=r);const s=u.get(o.id);s&&(t=Math.min(t,s.minY),e=Math.max(e,s.maxY))}if(t!==1/0&&e!==-1/0){const o=36,r=Math.max(0,e-t)+2*Math.max(n,o),s=(t+e)/2;for(const e of h)e.y=s,e.height=r,e.swimlaneContentTop=t;const c=[...h].sort((t,e)=>(t.x??0)-(e.x??0)),f=[],d=[],l=[];for(const t of c){const e=u.get(t.id);if(!e)continue;const n=Math.max(0,e.maxX-e.minX)+2*i(t),o=(e.minX+e.maxX)/2;f.push(t.id),d.push(o),l.push(n)}const g=f.length;if(g>0){const t=new Map;if(1===g)t.set(f[0],l[0]);else{const e=[];for(let t=0;t<g-1;t++)e.push(d[t+1]-d[t]);const n=new Array(g);n[0]=0;for(let t=0;t<g-1;t++)n[t+1]=2*e[t]-n[t];let o=0,r=Number.POSITIVE_INFINITY;for(let t=0;t<g;t++){const e=l[t];t%2==0?o=Math.max(o,e-n[t]):r=Math.min(r,n[t]-e)}let s=o;s=o<=r?(o+r)/2:o;for(let e=0;e<g;e++){const o=n[e]+(e%2==0?s:-s),r=Math.max(l[e],o);t.set(f[e],r)}}for(const e of h){const n=t.get(e.id);null!=n&&(e.width=n),a(e)}}}}}n(i,"topLaneHorizontalPadding"),n(a,"assignTopLaneTitleRect"),n(c,"prepareLayoutForSwimlanes"),n(f,"toGraphView"),n(d,"writeBackToLayoutData");function l(t){const e=[],n=[],r=new Map;for(const e of t.nodes)r.set(e.id,e);for(const s of t.edges){if(!s.label||0===s.label.length)continue;if(s.isLayoutOnly)continue;if(s.labelNodeId)continue;const t=s.start?r.get(s.start):void 0,i=s.end?r.get(s.end):void 0;if(!t||!i){o.warn("[EdgeLabelNodes]",`Edge ${s.id} has missing source or target node`);continue}const a=`edge-label-${s.start}-${s.end}-${s.id}`,c=t.parentId!==i.parentId?i.parentId:t.parentId,f={id:a,label:s.label,edgeStart:s.start??"",edgeEnd:s.end??"",shape:"labelRect",width:0,height:0,isEdgeLabel:!0,isDummy:!0,parentId:c,isGroup:!1,labelStyle:Array.isArray(s.labelStyle)?s.labelStyle[0]:s.labelStyle??"",...t.dir?{dir:t.dir}:{}};e.push(f),s.labelNodeId=a,s.label=void 0,s.text=void 0;const d={id:`${s.id}-to-label`,start:s.start,end:a,type:"normal",isLayoutOnly:!0},l={id:`${s.id}-from-label`,start:a,end:s.end,type:"normal",isLayoutOnly:!0};n.push(d,l)}const s=[...t.nodes,...e],i=[...t.edges,...n];return{...t,nodes:s,edges:i}}n(l,"createEdgeLabelNodes");var u=.001;function h(t){const e=t.x??0,n=t.y??0,o=t.width??0,r=t.height??0;return o>0&&r>0?{cx:e,cy:n,rect:T(e,n,o,r)}:void 0}function g(t){if(t.isGroup)return;const e=h(t);if(!e)return;return{id:String(t.id??""),cx:e.cx,cy:e.cy,rect:e.rect}}function p(t,e,n=u){return Math.abs(t.x-e.x)<n&&Math.abs(t.y-e.y)<n}function m(t,e,n=u){return Math.abs(t.x-e.x)<n}function x(t,e,n=u){return Math.abs(t.y-e.y)<n}function y(t,e,n=u){return x(t,e,n)&&Math.abs(t.x-e.x)>n}function b(t,e,n=u){return m(t,e,n)&&Math.abs(t.y-e.y)>n}function M(t,e,n,o){return Math.max(0,Math.min(Math.max(t,e),Math.max(n,o))-Math.max(Math.min(t,e),Math.min(n,o)))}function I(t,e,n=u){return t.horizontal&&e.horizontal&&x(t.a,e.a,n)?M(t.a.x,t.b.x,e.a.x,e.b.x):t.vertical&&e.vertical&&m(t.a,e.a,n)?M(t.a.y,t.b.y,e.a.y,e.b.y):0}function S(t,e=u){const n=[];for(let o=0;o<t.length-1;o++){const r=t[o],s=t[o+1],i=y(r,s,e),a=b(r,s,e);(i||a)&&n.push({index:o,a:r,b:s,horizontal:i,vertical:a})}return n}function w(t,e=u){const n=S(t,e);let o=0;for(let t=1;t<n.length;t++)n[t-1].horizontal!==n[t].horizontal&&o++;return o}function v(t,e=u){const n=[];for(const o of t){const t=n.length>0?n[n.length-1]:void 0;t&&p(t,o,e)||n.push({x:o.x,y:o.y})}return n}function C(t,e=u){if(!t||4!==t.length)return;const[n,o,r,s]=t;if(y(n,o,e)&&b(o,r,e)&&y(r,s,e))return{kind:"HVH",p0:n,p1:o,p2:r,p3:s};return b(n,o,e)&&y(o,r,e)&&b(r,s,e)?{kind:"VHV",p0:n,p1:o,p2:r,p3:s}:void 0}function L(t,e,n,o=0){const r=Math.min(t.x,e.x),s=Math.max(t.x,e.x),i=Math.min(t.y,e.y),a=Math.max(t.y,e.y);return s>n.left-o&&r<n.right+o&&a>n.top-o&&i<n.bottom+o}function k(t,e,n=0){return t.x>e.left+n&&t.x<e.right-n&&t.y>e.top+n&&t.y<e.bottom-n}function O(t,e){return t.left<=e.left&&t.right>=e.right&&t.top<=e.top&&t.bottom>=e.bottom}function R(t,e){return t.left<e.right&&t.right>e.left&&t.top<e.bottom&&t.bottom>e.top}function N(t,e){return{left:t.left-e,right:t.right+e,top:t.top-e,bottom:t.bottom+e}}function T(t,e,n,o){return{left:t-n/2,right:t+n/2,top:e-o/2,bottom:e+o/2}}function B(t){return h(t)?.rect}function F(t,e){switch(e){case"top":return{x:t.cx,y:t.rect.top};case"bottom":return{x:t.cx,y:t.rect.bottom};case"left":return{x:t.rect.left,y:t.cy};case"right":return{x:t.rect.right,y:t.cy}}}function E(t,e,n,o,r,s=u){const i="left"===e||"right"===e,a="left"===o||"right"===o;if(i&&a){if("right"===e&&"left"===o&&t.x<n.x||"left"===e&&"right"===o&&t.x>n.x){if(x(t,n,s))return[t,n];const e=(t.x+n.x)/2;return[t,{x:e,y:t.y},{x:e,y:n.y},n]}if(e===o){if(x(t,n,s))return;const o="left"===e?Math.min(t.x,n.x)-r:Math.max(t.x,n.x)+r;return[t,{x:o,y:t.y},{x:o,y:n.y},n]}return}if(!i&&!a){if(e===o){if(m(t,n,s))return;const o="top"===e?Math.min(t.y,n.y)-r:Math.max(t.y,n.y)+r;return[t,{x:t.x,y:o},{x:n.x,y:o},n]}if(!("bottom"===e&&"top"===o&&t.y<n.y||"top"===e&&"bottom"===o&&t.y>n.y))return;if(m(t,n,s))return[t,n];const i=(t.y+n.y)/2;return[t,{x:t.x,y:i},{x:n.x,y:i},n]}if(i&&!a){const r="right"===e&&n.x>t.x||"left"===e&&n.x<t.x,s="top"===o&&t.y<n.y||"bottom"===o&&t.y>n.y;return r&&s?[t,{x:n.x,y:t.y},n]:void 0}const c="bottom"===e&&n.y>t.y||"top"===e&&n.y<t.y,f="left"===o&&t.x<n.x||"right"===o&&t.x>n.x;return c&&f?[t,{x:t.x,y:n.y},n]:void 0}function $(t,e,n,o){return"left"===e||"right"===e?[t,{x:o,y:t.y},{x:o,y:n.y},n]:[t,{x:t.x,y:o},{x:n.x,y:o},n]}function Y(t){const e=new Map,n=[];for(const o of t){if(o.isEdgeLabel)continue;const t=g(o);t&&(e.set(t.id,t),n.push({id:t.id,rect:t.rect}))}return{nodeInfoById:e,realNodeRects:n}}function X(t){const e=[],n=[];for(const o of t){const t=g(o);if(!t)continue;const r={id:t.id,rect:t.rect};o.isEdgeLabel?n.push(r):e.push(r)}return{realNodeRects:e,labelNodeRects:n}}function z(t,{includeEdgeLabels:e=!0}={}){const n=[];for(const o of t){if(o.isGroup||!e&&o.isEdgeLabel)continue;const t=o.x??0,r=o.y??0,s=o.width??0,i=o.height??0;n.push({nodeId:o.id,...T(t,r,s,i)})}return n}function P(t,e,n=u){const o=t.start,r=t.end;if(!o||!r)return;const s=e.get(o),i=e.get(r);return s&&i?{srcId:o,dstId:r,srcInfo:s,dstInfo:i,collinearX:Math.abs(s.cx-i.cx)<n,collinearY:Math.abs(s.cy-i.cy)<n}:void 0}function G(t,e,n,o=[],r=0){for(const s of n)if(!o.includes(s.id)&&L(t,e,s.rect,-r))return!0;return!1}function D(t,e,n,o,r=u,s=1e-6){const i=x(t,e,r),a=m(t,e,r),c=x(n,o,r),f=m(n,o,r);if(i&&c||a&&f)return!1;if(!i&&!a||!c&&!f)return!1;const d=i?{a:t,b:e}:{a:n,b:o},l=a?{a:t,b:e}:{a:n,b:o},h=d.a.y,g=Math.min(d.a.x,d.b.x),p=Math.max(d.a.x,d.b.x),y=l.a.x,b=Math.min(l.a.y,l.b.y),M=Math.max(l.a.y,l.b.y);if(y<g||y>p||h<b||h>M)return!1;const I=Math.abs(y-d.a.x)<s&&Math.abs(h-d.a.y)<s||Math.abs(y-d.b.x)<s&&Math.abs(h-d.b.y)<s,S=Math.abs(y-l.a.x)<s&&Math.abs(h-l.a.y)<s||Math.abs(y-l.b.x)<s&&Math.abs(h-l.b.y)<s;return!(I&&S)}function A(t,e,n,o,r=u){const s=x(t,e,r),i=m(t,e,r),a=x(n,o,r),c=m(n,o,r);return i&&c&&m(t,n,r)?M(t.y,e.y,n.y,o.y)>r:!!(s&&a&&x(t,n,r))&&M(t.x,e.x,n.x,o.x)>r}function H(t,e,n,o,{epsilon:r=u,skipDegenerateOther:s=!1}={}){for(const i of n){if(i===o||i.isLayoutOnly)continue;const n=i.points;if(n&&!(n.length<2))for(let o=0;o<n.length-1;o++){const i=n[o],a=n[o+1];if((!s||!p(i,a,r))&&(D(t,e,i,a,r)||A(t,e,i,a,r)))return!0}}return!1}function j(t,e,n,o,r=u){const s=x(t,e,r),i=m(t,e,r),a=x(n,o,r),c=m(n,o,r);if(!(s&&c||i&&a))return!1;const f=s?{a:t,b:e}:{a:n,b:o},d=s?{a:n,b:o}:{a:t,b:e},l=f.a.y,h=Math.min(f.a.x,f.b.x),g=Math.max(f.a.x,f.b.x),p=d.a.x,y=Math.min(d.a.y,d.b.y),b=Math.max(d.a.y,d.b.y);return p>h+r&&p<g-r&&l>y+r&&l<b-r}function _(t,e,n){const o=Math.min(e,n),r=Math.max(e,n);return t>o+u&&t<r-u}function V(t,e,n){return m(t,e)&&m(e,n)?_(e.y,t.y,n.y):!(!x(t,e)||!x(e,n))&&_(e.x,t.x,n.x)}function W(t){let e=!1;const n=[];for(let o=0;o<t.length;o++){const r=n[n.length-1],s=t[o],i=o+1<t.length?t[o+1]:void 0;if(r&&i){if(p(r,i)){o++,e=!0;continue}if(V(r,s,i)){e=!0;continue}}n.push(s)}return{points:n,changed:e}}function K(t){const e=[t[0]];for(let n=1;n<t.length;n++){const o=e[e.length-1],r=t[n];if(!m(o,r)&&!x(o,r)){const t=e.length>=2?e[e.length-2]:void 0,n=!!t&&m(t,o)?{x:o.x,y:r.y}:{x:r.x,y:o.y};e.push(n)}e.push(r)}const n=[];for(const t of e){const e=n[n.length-1];e&&p(e,t)||n.push(t)}return n}function q(t){if(t.length<3)return t;let e=[...t];for(let t=0;t<32;t++){const t=W(e);if(e=t.points,!t.changed)break}return e}n(h,"measuredNodeRect"),n(g,"nodeBoundsInfoFor"),n(p,"samePoint"),n(m,"sameX"),n(x,"sameY"),n(y,"isHorizontalSegment"),n(b,"isVerticalSegment"),n(M,"overlapLength"),n(I,"sameAxisSegmentOverlapLength"),n(S,"orthogonalSegmentsForPoints"),n(w,"countOrthogonalBends"),n(v,"dedupeConsecutivePoints"),n(C,"classifyThreeSegmentRoute"),n(L,"segmentBoundsOverlapRect"),n(k,"pointInsideRect"),n(O,"rectContainsRect"),n(R,"rectsOverlap"),n(N,"inflateRect"),n(T,"rectFromCenterSize"),n(B,"rectOfNodeBounds"),n(F,"portForRectSide"),n(E,"buildOrthogonalPortPath"),n($,"buildSameSideTrackPath"),n(Y,"collectRealNodeBounds"),n(X,"collectNodeRectEntries"),n(z,"collectLayoutNodeRects"),n(P,"getNodePairGeometry"),n(G,"segmentHitsAnyRect"),n(D,"orthogonalSegmentsCross"),n(A,"sameAxisSegmentsOverlap"),n(H,"segmentConflictsWithAnyEdge"),n(j,"orthogonalSegmentsStrictlyCross"),n(_,"strictlyBetween"),n(V,"isCollinearIntermediate"),n(W,"simplifyPolylineOnce"),n(K,"orthogonalizePolyline"),n(q,"simplifyPolyline");var U=.001;function J(t,e,n){const o=t;if(o.isLayoutOnly||!o.points||o.points.length<n)return;const r=o.start?e.get(o.start):void 0,s=o.end?e.get(o.end):void 0;return{edge:o,points:o.points,srcRect:r?B(r):void 0,dstRect:s?B(s):void 0}}function Z(t,e,n){if(x(t,e,U)){return{x:t.x<n.left?n.left:n.right,y:t.y}}if(m(t,e,U)){const e=t.y<n.top?n.top:n.bottom;return{x:t.x,y:e}}return{x:Math.min(n.right,Math.max(n.left,t.x)),y:Math.min(n.bottom,Math.max(n.top,t.y))}}function Q(t,e,n){const o=n?1:-1;let r=n?0:t.length-1;for(;r>=0&&r<t.length&&k(t[r],e,.5);)r+=o;if(r<0||r>=t.length)return t;const s=r-o;if(s<0||s>=t.length)return t;const i=Z(t[r],t[s],e);return n?[i,...t.slice(r)]:[...t.slice(0,r+1),i]}function tt(t,e){for(const n of t){const t=J(n,e,2);if(!t)continue;let o=[...t.points];t.srcRect&&(o=Q(o,t.srcRect,!0)),t.dstRect&&(o=Q(o,t.dstRect,!1)),o=q(K(o)),o=lt(o,t.srcRect,t.dstRect),t.edge.points=q(K(o))}}function et(t,e,n,o=!1){if(x(t,e,U)){if(e.y<n.top-U||e.y>n.bottom+U)return e;if(o){if(t.x<n.left-U)return{x:n.left,y:t.y};if(t.x>n.right+U)return{x:n.right,y:t.y}}return{x:Math.abs(e.x-n.left)<=Math.abs(e.x-n.right)?n.left:n.right,y:t.y}}if(m(t,e,U)){if(e.x<n.left-U||e.x>n.right+U)return e;if(o){if(t.y<n.top-U)return{x:t.x,y:n.top};if(t.y>n.bottom+U)return{x:t.x,y:n.bottom}}const r=Math.abs(e.y-n.top)<=Math.abs(e.y-n.bottom);return{x:t.x,y:r?n.top:n.bottom}}return e}function nt(t,e,n){const o=t[e];for(let r=e+n;r>=0&&r<t.length;r+=n){const e=t[r];if(!p(e,o,U))return e}return t[e+n]}function ot(t,e){const n=t+4,o=e-4;return n<=o?{lo:n,hi:o}:{lo:(t+e)/2,hi:(t+e)/2}}function rt(t,e,n){const{lo:o,hi:r}=ot(e,n);return Math.min(r,Math.max(o,t))}function st(t){const e=Math.max(...t.map(t=>t.lo)),n=Math.min(...t.map(t=>t.hi));if(!(e>n))return{lo:e,hi:n}}function it(t,e){return"left"===e||"right"===e?ot(t.top,t.bottom):ot(t.left,t.right)}function at(t,e,n){const o=t.y>=n.top-U&&t.y<=n.bottom+U,r=t.x>=n.left-U&&t.x<=n.right+U;if(x(t,e,U)&&o){if(Math.abs(t.x-n.left)<U)return"left";if(Math.abs(t.x-n.right)<U)return"right"}if(m(t,e,U)&&r){if(Math.abs(t.y-n.top)<U)return"top";if(Math.abs(t.y-n.bottom)<U)return"bottom"}}function ct(t){return"left"===t||"right"===t}function ft(t,e,n,o,r){const s=[],i=n?at(t,e,n):void 0,a=o?at(e,t,o):void 0;return n&&i&&ct(i)===r&&s.push(it(n,i)),o&&a&&ct(a)===r&&s.push(it(o,a)),s.length>0?st(s):void 0}function dt(t,e,n,o,r){const s=ft(t,e,n,o,r);if(!s)return;const i=r?t.y:t.x,a=Math.min(s.hi,Math.max(s.lo,i));return Math.abs(a-i)<U?void 0:r?[{x:t.x,y:a},{x:e.x,y:a}]:[{x:a,y:t.y},{x:a,y:e.y}]}function lt(t,e,n){if(2!==t.length)return t;const[o,r]=t;return x(o,r,U)?dt(o,r,e,n,!0)??t:m(o,r,U)?dt(o,r,e,n,!1)??t:t}function ut(t,e,n){return ct(n)?{x:t.x,y:rt(t.y,e.top,e.bottom)}:{x:rt(t.x,e.left,e.right),y:t.y}}function ht(t,e,n,o,r,s){const i=t.map(t=>({...t}));for(let a=e;a>=0&&a<t.length;a+=n){const e=t[a];if(s&&!x(e,o,U))break;if(!s&&!m(e,o,U))break;s?i[a].y=r.y:i[a].x=r.x}return i}function gt(t,e,n){if(t.length<2)return t;const o=n?0:t.length-1,r=n?1:-1,s=t[o],i=nt(t,o,r);if(!i)return t;const a=at(s,i,e);if(!a)return t;const c=ct(a),f=ut(s,e,a);return p(s,f,U)?t:ht(t,o,r,s,f,c)}function pt(t,e,n){const o=Math.min(t.x,e.x)>=n.left-U&&Math.max(t.x,e.x)<=n.right+U,r=Math.min(t.y,e.y)>=n.top-U&&Math.max(t.y,e.y)<=n.bottom+U;return Math.abs(t.y-n.top)<U&&Math.abs(e.y-n.top)<U&&o?"top":Math.abs(t.y-n.bottom)<U&&Math.abs(e.y-n.bottom)<U&&o?"bottom":Math.abs(t.x-n.left)<U&&Math.abs(e.x-n.left)<U&&r?"left":Math.abs(t.x-n.right)<U&&Math.abs(e.x-n.right)<U&&r?"right":void 0}function mt(t,e,n,o){switch(t){case"top":return m(e,n,U)&&n.y<o.top-U;case"bottom":return m(e,n,U)&&n.y>o.bottom+U;case"left":return x(e,n,U)&&n.x<o.left-U;case"right":return x(e,n,U)&&n.x>o.right+U}}function xt(t,e,n){if(t.length<3)return t;if(n){const n=pt(t[0],t[1],e);return n&&mt(n,t[1],t[2],e)?t.slice(1):t}const o=t.length-1,r=pt(t[o-1],t[o],e);return r&&mt(r,t[o-1],t[o-2],e)?t.slice(0,o):t}function yt(t,e,n){let o=t;if(e){const t=nt(o,0,1);if(t){const n=et(t,o[0],e);n!==o[0]&&(o=[n,...o.slice(1)])}o=xt(o,e,!0)}if(n){const t=o.length-1,e=nt(o,t,-1);if(e){const r=et(e,o[t],n,!0);r!==o[t]&&(o=[...o.slice(0,t),r])}o=xt(o,n,!1)}const r=lt(o,e,n);return r!==o||2===o.length?r:(e&&(o=gt(o,e,!0)),n&&(o=gt(o,n,!1)),o)}function bt(t,e){for(const n of t){const t=J(n,e,2);if(!t)continue;const o=yt(v(t.points,U),t.srcRect,t.dstRect);if(o.length<3){t.edge.points=o;continue}const r=[o[0],{...o[0]},...o.slice(1,-1),o[o.length-1],{...o[o.length-1]}];t.edge.points=r}}function Mt(t){return new Map(t.map(t=>[t.id,t]))}function It(t,e){let n=t.parentId,o=null;for(;n;){const t=e.get(n);if(!t?.isGroup)break;o=t.id,n=t.parentId}return o}function St(t,e){let n=0,o=t.parentId;for(;o;){const t=e.get(o);if(!t?.isGroup)break;n++,o=t.parentId}return n}function wt(t){let e=1/0,n=-1/0,o=1/0,r=-1/0;for(const s of t){const t=s.x,i=s.y;if("number"!=typeof t||"number"!=typeof i)continue;const a=s.width??0,c=s.height??0;e=Math.min(e,t-a/2),n=Math.max(n,t+a/2),o=Math.min(o,i-c/2),r=Math.max(r,i+c/2)}return e===1/0||o===1/0?null:{minX:e,maxX:n,minY:o,maxY:r}}function vt(t,e){const n=t.padding??20;t.x=(e.minX+e.maxX)/2,t.y=(e.minY+e.maxY)/2,t.width=Math.max(0,e.maxX-e.minX)+n,t.height=Math.max(0,e.maxY-e.minY)+n}function Ct(t){const e=Mt(t),n=t.filter(t=>t.isGroup&&t.parentId).sort((t,n)=>St(n,e)-St(t,e));for(const e of n){const n=wt(t.filter(t=>t.parentId===e.id));n&&vt(e,n)}}function Lt(t,e){const o=t.nodes??[],r=t.edges??[],s=o.filter(t=>!t.isGroup);let i=1/0,a=-1/0;for(const t of s){const n=t[e];"number"==typeof n&&(i=Math.min(i,n),a=Math.max(a,n))}if(!Number.isFinite(i)||!Number.isFinite(a))return!1;const c=n(t=>i+a-t,"mirror");for(const t of o){const n=t[e];"number"==typeof n&&(t[e]=c(n));const o=t.groupTitleRect;o&&(t.groupTitleRect="x"===e?{...o,left:c(o.right),right:c(o.left)}:{...o,top:c(o.bottom),bottom:c(o.top)})}for(const t of r)for(const n of t.points??[])n[e]=c(n[e]);return!0}function kt(t){return!(t.nodes??[]).some(t=>!t.isGroup)||Lt(t,"y")}function Ot(t,e="LR"){const n=t.nodes??[],o=t.edges??[],r=n.filter(t=>!t.isGroup);let s=1/0,i=1/0;for(const t of r){const e=t.x??0,n=t.y??0;e<s&&(s=e),n<i&&(i=n)}if(!Number.isFinite(s)||!Number.isFinite(i))return!1;const a=36;let c=0,f=0;for(const t of r)c+=t.width??0,f+=t.height??0;const d=c/r.length,l=f/r.length,u=l>0?Math.max(1,d/l):1;for(const t of r){const e=t.x??0,n=((t.y??0)-i)*u+a,o=e-s;t.x=n,t.y=o}for(const t of o)if(t.points)for(const e of t.points){const t=e.x,n=(e.y-i)*u+a,o=t-s;e.x=n,e.y=o}Ct(n);const h=n.filter(t=>t.isGroup&&!t.parentId);if(0===h.length)return"RL"===e&&Lt(t,"x"),!0;const g=Mt(n),p=new Map;for(const t of n){if(t.isGroup)continue;const e=It(t,g);if(!e)continue;const n=p.get(e)??[];n.push(t),p.set(e,n)}let m=0;for(const t of h){const e=t.padding??0;e>m&&(m=e)}const x=[];let y=1/0,b=-1/0;for(const t of h){const e=wt(p.get(t.id)??[]);e&&(y=Math.min(y,e.minX),b=Math.max(b,e.maxX),x.push({lane:t,contentTop:e.minY,contentBottom:e.maxY,centerY:(e.minY+e.maxY)/2}))}if(y===1/0||b===-1/0)return!0;const M=Math.max(0,b-y)+2*Math.max(m,10),I=a+M,S=(y+b)/2-M/2-a,w=S+I/2,v=Math.max(m,a);x.sort((t,e)=>t.centerY-e.centerY);for(let t=0;t<x.length;t++){const e=x[t];let n,o;if(0===t)n=e.contentTop-v;else{n=(x[t-1].contentBottom+e.contentTop)/2}if(t===x.length-1)o=e.contentBottom+v;else{const n=x[t+1];o=(e.contentBottom+n.contentTop)/2}const r=Math.max(0,o-n),s=(n+o)/2;e.lane.x=w,e.lane.y=s,e.lane.width=I,e.lane.height=r,e.lane.swimlaneContentTop=e.contentTop,e.lane.groupTitleRect={left:S,right:S+a,top:n,bottom:o}}return"RL"===e&&Lt(t,"x"),!0}n(J,"endpointContextFor"),n(Z,"segmentEnterPoint"),n(Q,"clipEndpoint"),n(tt,"clipEdgeEndpointsToNodeBoundaries"),n(et,"snapEndpointToBoundary"),n(nt,"firstDistinctAdjacent"),n(ot,"cornerClearanceRange"),n(rt,"clampToCornerClearance"),n(st,"intersectRanges"),n(it,"clearanceRangeForSide"),n(at,"terminalSideForSegment"),n(ct,"isHorizontalSide"),n(ft,"straightClearanceRange"),n(dt,"clearStraightEndpointCornerAxis"),n(lt,"clearStraightEndpointCornerConnections"),n(ut,"cornerClearedEndpoint"),n(ht,"moveCollinearEndpointRun"),n(gt,"clearEndpointCornerConnection"),n(pt,"borderSideForSegment"),n(mt,"leavesOutward"),n(xt,"collapseOwnBorderStub"),n(yt,"snapAndCollapseEndpoints"),n(bt,"prepareEdgeEndpointsForRenderer"),n(Mt,"buildNodeMap"),n(It,"resolveTopLevelGroupId"),n(St,"groupDepth"),n(wt,"boundsForChildren"),n(vt,"applyGroupBounds"),n(Ct,"recomputeNestedGroupBounds"),n(Lt,"mirrorAxis"),n(kt,"applyBtDirectionTransform"),n(Ot,"applyLrDirectionTransform");var Rt=1e-6,Nt=[0,8,-8,16,-16];function Tt(t,e){const{nodeInfoById:n,realNodeRects:o}=Y(e);for(const e of t){if(e.isLayoutOnly)continue;const r=e.points;if(!r||r.length<4)continue;const s=C(v(r,Rt),Rt);if(!s)continue;const{p3:i}=s,a="HVH"===s.kind,c=P(e,n,Rt);if(!c)continue;const{srcId:f,dstId:d,srcInfo:l,dstInfo:u,collinearX:h,collinearY:g}=c;if(h||g)continue;let m;const x=l.rect;for(const n of Nt){let r,s,c;if(a){const t=u.cy>l.cy?x.bottom:x.top,e=l.cx+n;if(e<=x.left+Rt||e>=x.right-Rt)continue;r={x:e,y:t},s={x:e,y:i.y},c={x:i.x,y:i.y}}else{const t=u.cx>l.cx?x.right:x.left,e=l.cy+n;if(e<=x.top+Rt||e>=x.bottom-Rt)continue;r={x:t,y:e},s={x:i.x,y:e},c={x:i.x,y:i.y}}const h=p(r,s,Rt),g=p(s,c,Rt);if(h&&g)continue;if(!h&&G(r,s,o,[f],1))continue;if(!g&&G(s,c,o,[d],1))continue;const y=!h&&H(r,s,t,e,{epsilon:Rt,skipDegenerateOther:!0}),b=!g&&H(s,c,t,e,{epsilon:Rt,skipDegenerateOther:!0});if(!y&&!b){m=h?[s,c]:g?[r,s]:[r,s,c];break}}m&&(e.points=m)}}function Bt(t,e){const o=.001,{realNodeRects:r,labelNodeRects:s}=X(e.values());for(const i of t){if(i.isLayoutOnly)continue;const a=i.points;if(!a||a.length<4)continue;const c=v(a,o);if(c.length<4)continue;const f=c.length-1,d=c[f],l=c[f-1],u=c[f-2],h=d.x-l.x,g=d.y-l.y,p=Math.hypot(h,g);if(p>=10||p<o)continue;const M=l.x-u.x,I=l.y-u.y;if(Math.hypot(M,I)<o)continue;const S=y(l,d,o),w=b(l,d,o),C=y(u,l,o),L=b(u,l,o);if(!(S&&L||w&&C))continue;const O=i.end,R=i.start,N=O?e.get(O):void 0;if(!N)continue;const T=N.x??0,F=N.y??0,E=B(N);if(!E)continue;let $,Y;if(L){const t=I<0;$={x:T,y:u.y},Y={x:T,y:t?E.bottom:E.top}}else{const t=M>0;$={x:u.x,y:F},Y={x:t?E.right:E.left,y:F}}if(G($,Y,r,O?[O]:[],-2))continue;if(G($,Y,s,[],-2))continue;if(R){const t=e.get(R),n=t?B(t):void 0;if(n&&k($,n,2))continue}const X=n((t,e)=>`${t.x.toFixed(3)},${t.y.toFixed(3)}|${e.x.toFixed(3)},${e.y.toFixed(3)}`,"ownSegmentKey"),z=new Set;for(let t=0;t<c.length-1;t++)z.add(X(c[t],c[t+1]));const P=n((e,n)=>{for(const r of t){if(r===i)continue;if(r.isLayoutOnly)continue;const t=r.points;if(t&&!(t.length<2))for(let r=0;r<t.length-1;r++){const s=t[r],i=t[r+1];if(!z.has(X(s,i))&&j(e,n,s,i,o))return!0}}return!1},"segmentCrossesOtherEdge");if(P($,Y))continue;if(f-3>=0){const t=c[f-3];if(G(t,$,r,[R,O].filter(t=>Boolean(t)),-2))continue;if(P(t,$))continue}const D=[...c.slice(0,f-2),$,Y];i.points=D;const A=i.labelNodeId;if(A){const t=e.get(A);if(t){const e=t.width??0,n=t.height??0;if(e>0&&n>0){let r,s,i=-1;for(let t=0;t<D.length-1;t++){const a=D[t],c=D[t+1],f=Math.hypot(c.x-a.x,c.y-a.y),d=x(a,c,o),l=m(a,c,o);(d&&f>=e+2||l&&f>=n+2)&&(f>i&&(i=f,r=(a.x+c.x)/2,s=(a.y+c.y)/2))}void 0!==r&&void 0!==s&&(t.x=r,t.y=s)}}}}}n(Tt,"portSwapToLShape"),n(Bt,"collapseShortTerminalStub");var Ft=.001,Et=n(t=>"string"==typeof t?t.toUpperCase():"","upperCaseDirection"),$t=S,Yt=n((t,e)=>m(t,e,Ft)||x(t,e,Ft),"orthogonallyAligned");function Xt(t,e){const o=n((t,e)=>{const n=t.x??0,o=t.y??0,r=e.x-n,s=e.y-o;let i=(t.width??0)/2,a=(t.height??0)/2;return Math.abs(s)*i>Math.abs(r)*a?(s<0&&(a=-a),{x:n+(0===s?0:a*r/s),y:o+a}):(r<0&&(i=-i),{x:n+i,y:o+(0===r?0:i*s/r)})},"rectIntersect"),r=n((t,n)=>{const r=v(t.points??[]);if(r.length<2)return;const s=n?t.start:t.end,i=s?e.get(s):void 0,a=i?B(i):void 0;if(!i||!s||!a)return;const c=n?r[0]:r[r.length-1],f=n?r[1]:r[r.length-2],d=o(i,c);let l=c;return Yt(f,d)&&(l=f),m(d,l,Ft)?{edge:t,edgeId:String(t.id??""),nodeId:s,atStart:n,orientation:"V",coord:d.x,min:Math.min(d.y,l.y),max:Math.max(d.y,l.y),boundary:d,railEnd:l,rect:a}:x(d,l,Ft)?{edge:t,edgeId:String(t.id??""),nodeId:s,atStart:n,orientation:"H",coord:d.y,min:Math.min(d.x,l.x),max:Math.max(d.x,l.x),boundary:d,railEnd:l,rect:a}:void 0},"terminalLaneFor"),s=n((t,e)=>Math.max(0,Math.min(t.max,e.max)-Math.max(t.min,e.min)),"projectedOverlapLength"),i=n((t,e)=>{if(t.nodeId!==e.nodeId||t.orientation!==e.orientation)return!1;if("H"===t.orientation){return(Math.abs(t.boundary.x-t.rect.left)<1||Math.abs(t.boundary.x-t.rect.right)<1)&&m(t.boundary,e.boundary,1)}return(Math.abs(t.boundary.y-t.rect.top)<1||Math.abs(t.boundary.y-t.rect.bottom)<1)&&x(t.boundary,e.boundary,1)},"sameTerminalFace"),a=n((t,e)=>{if(t.nodeId!==e.nodeId||t.orientation!==e.orientation)return!1;return s(t,e)>=8&&Math.abs(t.coord-e.coord)<.5},"exactTerminalLaneConflict"),c=n((t,e)=>{if(t.nodeId!==e.nodeId||t.orientation!==e.orientation||"H"!==t.orientation||t.atStart===e.atStart)return!1;const n=s(t,e);if(n<8)return!1;const o=t.rect.bottom-t.rect.top;return!(n<o||n>2*o)&&(i(t,e)&&Math.abs(t.coord-e.coord)<16)},"nearTerminalLaneConflict"),f=n((t,e)=>{const o=v(t.edge.points??[]);if(o.length<2)return;const r="V"===t.orientation?{x:t.boundary.x+e,y:t.boundary.y}:{x:t.boundary.x,y:t.boundary.y+e},s="V"===t.orientation?{x:t.railEnd.x+e,y:t.railEnd.y}:{x:t.railEnd.x,y:t.railEnd.y+e};if(!n(()=>Math.abs(t.boundary.y-t.rect.top)<1||Math.abs(t.boundary.y-t.rect.bottom)<1?x(r,t.boundary,Ft)&&r.x>=t.rect.left+1&&r.x<=t.rect.right-1:(Math.abs(t.boundary.x-t.rect.left)<1||Math.abs(t.boundary.x-t.rect.right)<1)&&(m(r,t.boundary,Ft)&&r.y>=t.rect.top+1&&r.y<=t.rect.bottom-1),"boundaryStaysOnSameFace")())return;if(t.atStart){const e=o.length>1&&p(o[1],t.railEnd,Ft),n=o.slice(e?2:1),i=n[0];if(i&&!Yt(i,s))return;return[r,s,...n]}const i=o.length>1&&p(o[o.length-2],t.railEnd,Ft),a=o.slice(0,i?-2:-1),c=a[a.length-1];return!c||Yt(c,s)?[...a,s,r]:void 0},"shiftedCandidate"),d=n(t=>{const n=t.edge,o=v(n.points??[]);if(2!==o.length)return!1;const r=n.start,s=n.end,i=r?e.get(r):void 0,a=s?e.get(s):void 0;if(!i||!a)return!1;const c=i.x??0,f=i.y??0,d=a.x??0,l=a.y??0,[u,h]=o;return x(u,h,Ft)&&Math.abs(f-l)<1&&Math.abs(c-d)>1||m(u,h,Ft)&&Math.abs(c-d)<1&&Math.abs(f-l)>1},"laneIsStraightCollinearConnector"),l=[-7,7,-14,14,-21,21];for(let e=0;e<8;e++){const e=t.filter(t=>!t.isLayoutOnly).flatMap(t=>[r(t,!0),r(t,!1)]).filter(t=>Boolean(t));let n=!1;for(let t=0;t<e.length&&!n;t++)for(let o=t+1;o<e.length&&!n;o++){const s=e[t],i=e[o];if(s.edge===i.edge||!a(s,i)&&!c(s,i))continue;const u=!a(s,i),h=[s,i].sort((t,e)=>{const n=d(t),o=d(e);return n!==o?Number(n)-Number(o):Number(!e.atStart)-Number(!t.atStart)});for(const t of h){for(const o of l){const s=f(t,o);if(!s)continue;const i=r({...t.edge,points:s},t.atStart);if(i&&!e.some(e=>e.edge!==t.edge&&(a(i,e)||u&&c(i,e)))){t.edge.points=s,n=!0;break}}if(n)break}}if(!n)return}}function zt(t,e){const{realNodeRects:o,labelNodeRects:r}=X(e.values()),s=n((e,n)=>{const s=e.start,i=e.end,a=$t(n);if(a.length!==n.length-1)return!1;const c=[s,i].filter(t=>Boolean(t));for(const t of a){if(G(t.a,t.b,o,c,-2))return!1;if(G(t.a,t.b,r,[],-2))return!1}for(const n of t){if(n===e||n.isLayoutOnly)continue;const t=n.points;if(t&&!(t.length<2))for(const e of a)for(const n of $t(v(t))){if(I(e,n,.5)>=8)return!1;if(j(e.a,e.b,n.a,n.b,Ft))return!1}}return!0},"candidateIsSafe"),i=n((t,e)=>{if(e+4>=t.length)return;const n=t[e],o=t[e+1],r=t[e+2],s=t[e+3],i=t[e+4],a=y(n,o)&&b(o,r)&&y(r,s)&&b(s,i)&&m(n,s,Ft)&&m(n,i,Ft)&&m(o,r,Ft)&&(o.x-n.x)*(s.x-r.x)<0,c=b(n,o)&&y(o,r)&&b(r,s)&&y(s,i)&&x(n,s,Ft)&&x(n,i,Ft)&&x(o,r,Ft)&&(o.y-n.y)*(s.y-r.y)<0;if(a||c)return v([...t.slice(0,e+1),i,...t.slice(e+5)]);if(e+5>=t.length)return;const f=t[e+5],d=b(n,o)&&y(o,r)&&b(r,s)&&y(s,i)&&b(i,f)&&m(n,i,Ft)&&m(n,f,Ft)&&m(r,s,Ft)&&(r.x-o.x)*(i.x-s.x)<0,l=y(n,o)&&b(o,r)&&y(r,s)&&b(s,i)&&y(i,f)&&x(n,i,Ft)&&x(n,f,Ft)&&x(r,s,Ft)&&(r.y-o.y)*(i.y-s.y)<0;return d||l?v([...t.slice(0,e+1),f,...t.slice(e+6)]):void 0},"withoutDogleg");for(let e=0;e<8;e++){let e=!1;for(const n of t){if(n.isLayoutOnly)continue;const t=v(n.points??[]);for(let o=0;o<=t.length-5;o++){const r=i(t,o);if(r&&s(n,r)){n.points=r,e=!0;break}}if(e)break}if(!e)return}}function Pt(t,e){const{realNodeRects:o,labelNodeRects:r}=X(e.values()),s=t.filter(t=>!t.isLayoutOnly),i=n((t,e,n)=>v(t===e?n??[]:t.points??[]),"pointsFor"),a=n((t,e)=>{let n=0;for(let o=0;o<s.length;o++){const r=$t(i(s[o],t,e));for(let a=o+1;a<s.length;a++){const o=$t(i(s[a],t,e));for(const t of r)for(const e of o)j(t.a,t.b,e.a,e.b,Ft)&&n++}}return n},"strictCrossingCount"),c=n(t=>{const e=$t(t);if(3!==e.length)return;const n=e[1];return e[0].horizontal!==n.horizontal&&e[2].horizontal!==n.horizontal?{index:n.index,horizontal:n.horizontal,vertical:n.vertical,segment:n}:void 0},"middleRail"),f=n((t,e)=>{const n=[t.start,t.end].filter(t=>Boolean(t));return o.filter(t=>{if(n.includes(t.id))return!1;const o=t.rect;if(e.horizontal){return M(e.a.x,e.b.x,o.left,o.right)>=8&&e.a.y>=o.top-2&&e.a.y<=o.bottom+2}return M(e.a.y,e.b.y,o.top,o.bottom)>=8&&e.a.x>=o.left-2&&e.a.x<=o.right+2})},"blockingRectsFor"),d=n((t,e,n)=>{const o=t.map(t=>({...t}));if(e.horizontal)o[e.index].y=n,o[e.index+1].y=n;else{if(!e.vertical)return;o[e.index].x=n,o[e.index+1].x=n}const r=q(v(o));return $t(r).length===r.length-1?r:void 0},"candidateByMovingRail"),l=n((t,e,n)=>{const c=[t.start,t.end].filter(t=>Boolean(t)),f=$t(e);if(f.length!==e.length-1)return!1;for(const t of f){if(G(t.a,t.b,o,c,-2))return!1;if(G(t.a,t.b,r,[],-2))return!1}for(const e of s)if(e!==t)for(const t of f)for(const n of $t(i(e)))if(I(t,n,.5)>=8)return!1;return a(t,e)<=n},"candidateIsSafe");for(let t=0;t<8;t++){const t=a();let e=!1;for(const n of s){const o=i(n),r=c(o);if(!r)continue;const s=f(n,r.segment);if(0===s.length)continue;const a=r.horizontal?[Math.min(...s.map(t=>t.rect.top))-20,Math.max(...s.map(t=>t.rect.bottom))+20]:[Math.min(...s.map(t=>t.rect.left))-20,Math.max(...s.map(t=>t.rect.right))+20];for(const s of a){const i=d(o,r.segment,s);if(i&&l(n,i,t)){n.points=i,e=!0;break}}if(e)break}if(!e)return}}function Gt(t,e,o){const r=n(t=>{const e=t.groupTitleRect;if(e&&"number"==typeof e.left&&"number"==typeof e.right&&"number"==typeof e.top&&"number"==typeof e.bottom&&Number.isFinite(e.left)&&Number.isFinite(e.right)&&Number.isFinite(e.top)&&Number.isFinite(e.bottom)&&!(e.right<=e.left)&&!(e.bottom<=e.top))return{left:e.left,right:e.right,top:e.top,bottom:e.bottom}},"validTitleRect"),s=n(t=>{if(!t.isGroup||t.parentId)return;const e=Et(t.direction??o);if("LR"===e||"RL"===e||"BT"===e)return;const n=r(t),s=t.y,i=t.height;if(!n||"number"!=typeof s||"number"!=typeof i||!Number.isFinite(s)||!Number.isFinite(i)||i<=0)return;const a=n.right-n.left,c=n.bottom-n.top;return c<=0||a<c?void 0:{node:t,rect:n}},"topLaneTitleFor"),i=n((t,e)=>{if(!t.horizontal)return!1;const n=t.a.y;return!(n<e.top-Ft||n>e.bottom+Ft)&&M(t.a.x,t.b.x,e.left,e.right)>=8},"horizontalSegmentIntersectsTitle"),a=[...e.values()].map(s).filter(t=>Boolean(t));if(0===a.length)return;let c=0;for(const e of t){if(e.isLayoutOnly)continue;const t=v(e.points??[]);for(const e of $t(t))for(const t of a)i(e,t.rect)&&(c=Math.max(c,t.rect.bottom-e.a.y+4))}if(!(c<=Ft))for(const t of a){const e=t.node.y,n=t.node.height;"number"!=typeof e||"number"!=typeof n||!Number.isFinite(e)||!Number.isFinite(n)||n<=0||(t.node.y=e-c/2,t.node.height=n+c,t.node.groupTitleRect={...t.rect,top:t.rect.top-c,bottom:t.rect.bottom-c})}}function Dt(t,e,o){const r=n(t=>{const e=t.groupTitleRect;if(e&&"number"==typeof e.left&&"number"==typeof e.right&&"number"==typeof e.top&&"number"==typeof e.bottom&&Number.isFinite(e.left)&&Number.isFinite(e.right)&&Number.isFinite(e.top)&&Number.isFinite(e.bottom)&&!(e.right<=e.left)&&!(e.bottom<=e.top))return{left:e.left,right:e.right,top:e.top,bottom:e.bottom}},"validTitleRect"),s=n(t=>{if(!t.isGroup||t.parentId)return;if("LR"!==Et(t.direction??o))return;const e=r(t),n=t.x,s=t.width;if(!e||"number"!=typeof n||"number"!=typeof s||!Number.isFinite(n)||!Number.isFinite(s)||s<=0)return;const i=e.right-e.left,a=e.bottom-e.top;return i<=0||a<i?void 0:{node:t,rect:e}},"leftLaneTitleFor"),i=n((t,e)=>{if(!t.vertical)return!1;const n=t.a.x;return!(n<e.left-Ft||n>e.right+Ft)&&M(t.a.y,t.b.y,e.top,e.bottom)>=8},"verticalSegmentIntersectsTitle"),a=n((t,e)=>{if(!t.horizontal)return!1;const n=t.a.y;return!(n<e.top-Ft||n>e.bottom+Ft)&&M(t.a.x,t.b.x,e.left,e.right)>=8},"horizontalSegmentIntersectsTitle"),c=[...e.values()].map(s).filter(t=>Boolean(t));if(0===c.length)return;let f=0;for(const e of t){if(e.isLayoutOnly)continue;const t=v(e.points??[]);for(const e of $t(t))for(const t of c)if(i(e,t.rect))f=Math.max(f,t.rect.right-e.a.x+4);else if(a(e,t.rect)){const n=Math.min(e.a.x,e.b.x);f=Math.max(f,t.rect.right-n+4)}}if(!(f<=Ft))for(const t of c){const e=t.node.x,n=t.node.width;"number"!=typeof e||"number"!=typeof n||!Number.isFinite(e)||!Number.isFinite(n)||n<=0||(t.node.x=e-f/2,t.node.width=n+f,t.node.groupTitleRect={...t.rect,left:t.rect.left-f,right:t.rect.right-f})}}function At(t,e){const{realNodeRects:o}=X(e.values()),r=t.filter(t=>!t.isLayoutOnly),s=n((t,e=new Map)=>v(e.get(t)??t.points??[]),"replacementPointsFor"),i=n((t=new Map)=>{let e=0;for(let n=0;n<r.length;n++){const o=$t(s(r[n],t));for(let i=n+1;i<r.length;i++){const n=$t(s(r[i],t));for(const t of o)for(const o of n)j(t.a,t.b,o.a,o.b,Ft)&&e++}}return e},"crossingCount"),a=n((t=new Map)=>r.reduce((e,n)=>e+w(s(n,t)),0),"totalBends"),c=n(t=>{const e=s(t);if(e.length<4)return;const n=e[e.length-2],o=e[e.length-1];return y(n,o,Ft)||b(n,o,Ft)?{tailStart:n,terminal:o}:void 0},"terminalTailFor"),f=n((t,e)=>{const n=s(t);if(n.length<3)return;const o=n[0],r=n[1];let i;if(y(o,r,Ft))i={x:r.x,y:e.tailStart.y};else{if(!b(o,r,Ft))return;i={x:e.tailStart.x,y:r.y}}const a=q(v([o,r,i,e.tailStart,e.terminal]));return $t(a).length===a.length-1?a:void 0},"candidateWithDestinationTail"),d=n((t,e)=>{const n=[t.start,t.end].filter(t=>Boolean(t));for(const t of $t(e))if(G(t.a,t.b,o,n,-2))return!0;return!1},"pathHasNodeHit"),l=n((t,e,n)=>{for(const o of r)if(o!==t)for(const t of $t(e))for(const e of $t(s(o,n)))if(I(t,e,.5)>=8)return!0;return!1},"pathHasSharedTrack"),u=n((t,e,n)=>!d(t,e)&&!l(t,e,n),"candidateIsSafe"),h=n(()=>{const t=new Map;for(const n of r){const o=n.end;if(!o||!e.has(o))continue;if(s(n).length<4)continue;const r=t.get(o)??[];r.push(n),t.set(o,r)}return t},"edgesByDestination");for(let t=0;t<4;t++){const t=i();if(0===t)return;let e,n=t,o=a();for(const r of h().values())for(let s=0;s<r.length;s++)for(let d=s+1;d<r.length;d++){const l=r[s],h=r[d],g=c(l),p=c(h);if(!g||!p)continue;const m=f(l,p),x=f(h,g);if(!m||!x)continue;const y=new Map([[l,m],[h,x]]);if(!u(l,m,y)||!u(h,x,y))continue;const b=i(y),M=a(y);b>=t||(b>n||b===n&&M>=o||(e=y,n=b,o=M))}if(!e)return;for(const[t,n]of e)t.points=n}}function Ht(t,e){const{realNodeRects:o,labelNodeRects:r}=X(e.values()),s=t.filter(t=>!t.isLayoutOnly),i=n((t,e=new Map)=>v(e.get(t)??t.points??[]),"replacementPointsFor"),a=n((t=new Map)=>{let e=0;for(let n=0;n<s.length;n++){const o=$t(i(s[n],t));for(let r=n+1;r<s.length;r++){const n=$t(i(s[r],t));for(const t of o)for(const o of n)j(t.a,t.b,o.a,o.b,Ft)&&e++}}return e},"strictCrossingCount"),c=n((t=new Map)=>s.reduce((e,n)=>e+w(i(n,t)),0),"totalBends"),f=n(t=>{const n=t.start,o=t.end,r=n?e.get(n):void 0,s=o?e.get(o):void 0,i=r?B(r):void 0,a=s?B(s):void 0;return i&&a?{src:i,dst:a}:void 0},"endpointRectsFor"),d=n((t,e,n)=>{if(n.index<=0||n.index+1>=e.length-1)return;const o=f(t);if(o){if(n.vertical){const r=n.a.x,s=Math.min(o.src.left,o.dst.left),i=Math.max(o.src.right,o.dst.right),a=r<s-Ft?"left":r>i+Ft?"right":void 0;if(!a)return;return{edge:t,points:e,segmentIndex:n.index,axis:"vertical",side:a,coord:r,min:Math.min(n.a.y,n.b.y),max:Math.max(n.a.y,n.b.y)}}if(n.horizontal){const r=n.a.y,s=Math.min(o.src.top,o.dst.top),i=Math.max(o.src.bottom,o.dst.bottom),a=r<s-Ft?"top":r>i+Ft?"bottom":void 0;if(!a)return;return{edge:t,points:e,segmentIndex:n.index,axis:"horizontal",side:a,coord:r,min:Math.min(n.a.x,n.b.x),max:Math.max(n.a.x,n.b.x)}}}},"externalRailForSegment"),l=n(()=>{const t=[];for(const e of s){const n=i(e);for(const o of $t(n)){const r=d(e,n,o);r&&t.push(r)}}return t},"collectExternalRails"),u=n((t,e)=>t.edge!==e.edge&&t.axis===e.axis&&t.side===e.side&&M(t.min,t.max,e.min,e.max)>=8,"railsInteract"),h=n(t=>{const e=[],n=new Set;for(const o of t){if(n.has(o))continue;const r=[o],s=[];for(n.add(o);r.length>0;){const e=r.pop();s.push(e);for(const o of t)!n.has(o)&&u(e,o)&&(n.add(o),r.push(o))}s.length>1&&e.push(s)}return e},"connectedComponents"),g=n(t=>{const e=[];for(const n of t)e.some(t=>Math.abs(t-n.coord)<Ft)||e.push(n.coord);for(;e.length<t.length;){const n=Math.min(...e),o=Math.max(...e),r=t[0].side;e.push("left"===r||"top"===r?n-12*(t.length-e.length):o+12*(t.length-e.length))}return e},"uniqueCoordsFor"),p=n(t=>{const e=t.map(t=>t.coord),o=g(t),r=[];if(t.length<=6){const s=new Array(o.length).fill(!1),i=[],a=n(()=>{if(i.length!==t.length)for(const[t,e]of o.entries())s[t]||(s[t]=!0,i.push(e),a(),i.pop(),s[t]=!1);else i.some((t,n)=>Math.abs(t-e[n])>=Ft)&&r.push([...i])},"visit");return a(),r}for(let t=0;t<e.length;t++)for(let n=t+1;n<e.length;n++){const o=[...e];[o[t],o[n]]=[o[n],o[t]],r.push(o)}return r},"coordinateAssignmentsFor"),m=n((t,e)=>{const n=new Map;for(const[o,r]of t.entries()){const t=e[o],s=n.get(r.edge)??r.points.map(t=>({x:t.x,y:t.y}));"vertical"===r.axis?(s[r.segmentIndex].x=t,s[r.segmentIndex+1].x=t):(s[r.segmentIndex].y=t,s[r.segmentIndex+1].y=t),n.set(r.edge,s)}const o=new Map;for(const[t,e]of n){const n=q(v(e));if($t(n).length!==n.length-1)return;o.set(t,n)}return o},"replacementsForAssignment"),x=n(t=>{for(const[e,n]of t){const t=[e.start,e.end].filter(t=>Boolean(t));for(const e of $t(n)){if(G(e.a,e.b,o,t,-2))return!1;if(G(e.a,e.b,r,[],-2))return!1}}for(let e=0;e<s.length;e++){const n=s[e],o=t.has(n),r=$t(i(n,t));for(let n=e+1;n<s.length;n++){const e=s[n];if(!o&&!t.has(e))continue;const a=$t(i(e,t));for(const t of r)for(const e of a)if(I(t,e,.5)>=8)return!1}}return!0},"candidateIsSafe");for(let t=0;t<4;t++){const t=a();if(0===t)return;let e,n=t,o=c(),r=Number.POSITIVE_INFINITY;for(const s of h(l()))for(const i of p(s)){const f=m(s,i);if(!f||!x(f))continue;const d=a(f);if(d>=t)continue;const l=c(f),u=s.reduce((t,e,n)=>t+Math.abs(i[n]-e.coord),0);d>n||d===n&&(l>o||l===o&&u>=r)||(e=f,n=d,o=l,r=u)}if(!e)return;for(const[t,n]of e)t.points=n}}function jt(t,e){const{realNodeRects:o,labelNodeRects:r}=X(e.values()),s=t.filter(t=>!t.isLayoutOnly),i=n((t,e,n)=>v(t===e?n??[]:t.points??[]),"pointsFor"),a=n(t=>$t(t).reduce((t,e)=>{const n=e.a.x-e.b.x,o=e.a.y-e.b.y;return t+Math.hypot(n,o)},0),"pathLength"),c=n((t,e)=>{let n=0;for(let o=0;o<s.length;o++){const r=$t(i(s[o],t,e));for(let a=o+1;a<s.length;a++){const o=$t(i(s[a],t,e));for(const t of r)for(const e of o)j(t.a,t.b,e.a,e.b,Ft)&&n++}}return n},"strictCrossingCount"),f=n((t,e)=>{if(t.horizontal){const n=t.a.y;return(Math.abs(n-e.top)<1||Math.abs(n-e.bottom)<1)&&M(t.a.x,t.b.x,e.left,e.right)>=8}if(t.vertical){const n=t.a.x;return(Math.abs(n-e.left)<1||Math.abs(n-e.right)<1)&&M(t.a.y,t.b.y,e.top,e.bottom)>=8}return!1},"segmentRunsAlongRectBorder"),d=n(t=>{const n=[t.start,t.end].filter(t=>Boolean(t)),o=[];for(const t of n){const n=e.get(t),r=n?B(n):void 0;r&&o.push(r)}return o},"endpointRectsFor"),l=n((t,e)=>{if(e+3>=t.length)return[];const n=t[e],o=t[e+1],r=t[e+2],s=t[e+3],i=y(n,o,Ft)&&b(o,r,Ft)&&y(r,s,Ft),a=b(n,o,Ft)&&y(o,r,Ft)&&b(r,s,Ft);if(!i&&!a)return[];if(!(i?Math.sign(o.x-n.x)!==Math.sign(s.x-r.x):Math.sign(o.y-n.y)!==Math.sign(s.y-r.y)))return[];const c=m(n,s,Ft)||x(n,s,Ft)?[]:[{x:n.x,y:s.y},{x:s.x,y:n.y}],f=0===c.length?[[...t.slice(0,e+1),...t.slice(e+3)]]:c.map(n=>[...t.slice(0,e+1),n,...t.slice(e+3)]),d=new Set;return f.map(t=>q(v(t))).filter(t=>{if($t(t).length!==t.length-1)return!1;if(!t.some(t=>p(t,s,Ft)))return!1;const e=t.map(t=>`${t.x.toFixed(3)},${t.y.toFixed(3)}`).join("|");return!d.has(e)&&(d.add(e),!0)})},"shortcutCandidatesAt"),u=n((t,e,n)=>{const a=[t.start,t.end].filter(t=>Boolean(t)),l=d(t);for(const t of $t(e)){if(G(t.a,t.b,o,a,-2))return!1;if(G(t.a,t.b,r,[],-2))return!1;if(l.some(e=>f(t,e)))return!1}for(const n of s)if(n!==t)for(const t of $t(e))for(const e of $t(i(n)))if(I(t,e,.5)>=8)return!1;return c(t,e)<=n},"candidateIsSafe");for(let t=0;t<8;t++){const t=c();let e,n,o=t,r=Number.POSITIVE_INFINITY,f=Number.POSITIVE_INFINITY;for(const d of s){const s=i(d),h=w(s,Ft),g=a(s);for(let i=0;i<=s.length-4;i++)for(const p of l(s,i)){const s=w(p,Ft),i=a(p);if(!(s<h||s===h&&i<g-Ft)||!u(d,p,t))continue;const l=c(d,p);l>o||l===o&&(s>r||s===r&&i>=f)||(e=d,n=p,o=l,r=s,f=i)}}if(!e||!n)return;e.points=n}}function _t(t,e){const o=20,r=[];for(const t of e.values()){if(t.isGroup||t.isEdgeLabel)continue;const e=t.x??0,n=t.y??0,o=B(t);o&&r.push({id:String(t.id??""),cx:e,cy:n,rect:o})}if(0===r.length)return;const s=new Map(r.map(t=>[t.id,t])),i=r.map(t=>({id:t.id,rect:t.rect})),a=["top","bottom","left","right"],c={top:Math.min(...r.map(t=>t.rect.top))-o,bottom:Math.max(...r.map(t=>t.rect.bottom))+o,left:Math.min(...r.map(t=>t.rect.left))-o,right:Math.max(...r.map(t=>t.rect.right))+o},f=t.filter(t=>!t.isLayoutOnly),d=new Map(f.map((t,e)=>[t,e])),l=n(t=>{const e="left"===t||"top"===t?-1:1,n=[];for(let r=0;r<=2;r++)n.push(c[t]+e*o*r);return n},"outwardTracksForSide"),u=n((t,e=new Map)=>v(e.get(t)??t.points??[]),"replacementPointsFor"),h=n((t,e)=>{let n=0;for(const o of t)for(const t of e)j(o.a,o.b,t.a,t.b,Ft)&&n++;return n},"crossingCountBetweenSegments"),g=n((t,e)=>h($t(t),$t(e)),"crossingCountBetweenPaths"),p=n((t=new Map)=>{let e=0;const o=[],r=new Set,s=[],i=n(t=>{r.has(t)||(r.add(t),s.push(t))},"addEdge");for(let n=0;n<f.length;n++){const r=f[n],s=u(r,t);for(let a=n+1;a<f.length;a++){const n=f[a],c=g(s,u(n,t));c>0&&(e+=c,o.push({first:r,second:n,count:c}),i(r),i(n))}}return s.sort((t,e)=>(d.get(t)??0)-(d.get(e)??0)),{count:e,pairs:o,edgeSet:r,edges:s}},"crossingSnapshot"),m=n((t,e)=>{const n=new Set(e.keys());if(0===n.size)return t.count;let o=0;for(const e of t.pairs)(n.has(e.first)||n.has(e.second))&&(o+=e.count);let r=0;for(let t=0;t<f.length;t++){const o=f[t],s=n.has(o),i=u(o,e);for(let o=t+1;o<f.length;o++){const t=f[o];(s||n.has(t))&&(r+=g(i,u(t,e)))}}return t.count-o+r},"crossingCountWithReplacements"),x=n(t=>{const e=new Map;for(const n of t.pairs){const t=e.get(n.first)??new Set;t.add(n.second),e.set(n.first,t);const o=e.get(n.second)??new Set;o.add(n.first),e.set(n.second,o)}const n=[],o=new Set;for(const r of t.edges){if(o.has(r))continue;const t=[r],s=[];for(o.add(r);t.length>0;){const n=t.pop();s.push(n);for(const r of e.get(n)??[])o.has(r)||(o.add(r),t.push(r))}s.sort((t,e)=>(d.get(t)??0)-(d.get(e)??0)),s.length>1&&n.push(s)}return n},"crossingComponents"),M=n(t=>[t.start,t.end].filter(t=>Boolean(t)),"endpointIdsFor"),S=n(t=>{const e=[];for(const n of x(t)){const t=new Set(n),o=new Set(n.flatMap(t=>M(t))),r=[...n];for(const e of f)t.has(e)||M(e).some(t=>o.has(t))&&r.push(e);r.sort((t,e)=>(d.get(t)??0)-(d.get(e)??0)),e.push(r)}return e},"pairSearchGroups"),C=n((t,e,n)=>m(t,new Map([[e,n]])),"crossingCountWithSingleReplacement"),L=n(t=>{const e=new Map;for(const n of t.pairs)e.set(n.first,(e.get(n.first)??0)+n.count),e.set(n.second,(e.get(n.second)??0)+n.count);return e},"currentCrossingsByEdge"),k=n(t=>t.slice(1).reduce((e,n,o)=>{const r=t[o];return e+Math.abs(n.x-r.x)+Math.abs(n.y-r.y)},0),"pathLength"),O=n((t=new Map)=>f.reduce((e,n)=>e+w(u(n,t)),0),"totalBends"),R=n((t=new Map)=>f.reduce((e,n)=>e+k(u(n,t)),0),"totalLength"),N=n((t,e,n=new Map)=>{const o=$t(e);for(const e of f)if(e!==t)for(const t of o)for(const o of $t(u(e,n)))if(I(t,o,.5)>=8)return!0;return!1},"pathHasSegmentConflict"),T=n((t,e)=>{const n=[t.start,t.end].filter(t=>Boolean(t));for(const t of $t(e))if(G(t.a,t.b,i,n,-2))return!0;return!1},"pathHitsNode"),Y=n((t,e)=>{const n=q(v(e));$t(n).length===n.length-1&&t.push(n)},"pushOrthogonalCandidate"),X=n(t=>"left"===t||"right"===t,"sideIsHorizontal"),z=n((t,e,n)=>{switch(e){case"left":return Math.min(t.x,n.x)-o;case"right":return Math.max(t.x,n.x)+o;case"top":return Math.min(t.y,n.y)-o;case"bottom":return Math.max(t.y,n.y)+o}},"localTrackForSameSide"),P=n((t,e,n,r)=>{const s="left"===n||"top"===n?-1:1,i=[z(e,n,r),c[n]];for(const a of i)for(let i=0;i<=2;i++)Y(t,$(e,n,r,a+s*o*i))},"addSameSideCandidates"),D=n((t,e,n,o,r)=>{for(const s of l(n))for(const n of l(r))Y(t,[e,{x:s,y:e.y},{x:s,y:n},{x:o.x,y:n},o])},"addHorizontalToVerticalCandidates"),A=n((t,e,n,o,r)=>{for(const s of l(n))for(const n of l(r))Y(t,[e,{x:e.x,y:s},{x:n,y:s},{x:n,y:o.y},o])},"addVerticalToHorizontalCandidates"),H=n((t,e,n,o,r)=>{const s=[...l("top"),...l("bottom")];for(const i of l(n))for(const n of l(r))for(const r of s)Y(t,[e,{x:i,y:e.y},{x:i,y:r},{x:n,y:r},{x:n,y:o.y},o])},"addHorizontalPairCandidates"),_=n((t,e,n,o,r)=>{const s=[...l("left"),...l("right")];for(const i of l(n))for(const n of l(r))for(const r of s)Y(t,[e,{x:e.x,y:i},{x:r,y:i},{x:r,y:n},{x:o.x,y:n},o])},"addVerticalPairCandidates"),V=n(t=>{const e=new Set;return t.map(t=>v(t)).filter(t=>{const n=t.map(t=>`${t.x.toFixed(3)},${t.y.toFixed(3)}`).join("|");return!(e.has(n)||t.length<2)&&(e.add(n),!0)})},"dedupeCandidatePaths"),W=n((t,e,n,r)=>{const s=[],i=E(t,e,n,r,o,Ft);i&&Y(s,i),e===r&&P(s,t,e,n);const a=X(e),c=X(r);return a&&!c?D(s,t,e,n,r):!a&&c?A(s,t,e,n,r):a?H(s,t,e,n,r):_(s,t,e,n,r),V(s)},"buildCandidatesForSides"),K=n((t,e,n,o)=>{const r=[...l("left"),...l("right")],s=[...l("top"),...l("bottom")];for(const i of a){const a=F(o,i),c="top"===i||"bottom"===i?l(i):s;for(const o of r){Y(t,[e,n,{x:o,y:n.y},{x:o,y:a.y},a]);for(const r of c)Y(t,[e,n,{x:o,y:n.y},{x:o,y:r},{x:a.x,y:r},a])}}},"addVerticalDepartureOuterTrackCandidates"),U=n((t,e,n,o)=>{const r=[...l("left"),...l("right")],s=[...l("top"),...l("bottom")];for(const i of a){const a=F(o,i),c="left"===i||"right"===i?l(i):r;for(const o of s){Y(t,[e,n,{x:n.x,y:o},{x:a.x,y:o},a]);for(const r of c)Y(t,[e,n,{x:n.x,y:o},{x:r,y:o},{x:r,y:a.y},a])}}},"addHorizontalDepartureOuterTrackCandidates"),J=n(t=>{const e=t.start,n=t.end,o=n?s.get(n):void 0;if(!e||!o)return[];const r=v(t.points??[]);if(r.length<4)return[];const i=r[0],a=r[1],c=[];return b(i,a,Ft)?K(c,i,a,o):y(i,a,Ft)&&U(c,i,a,o),c},"terminalPreservingOuterTrackCandidates"),Z=n(t=>{const e=t.start,n=t.end,o=e?s.get(e):void 0,r=n?s.get(n):void 0;if(!o||!r)return[];const i=[];for(const t of a){const e=F(o,t);for(const n of a)i.push(...W(e,t,F(r,n),n))}return i.push(...J(t)),i},"candidatePathsFor"),Q=n(()=>new Map(f.map(t=>[t,$t(u(t))])),"currentSegmentsByEdge"),tt=n((t,e,n)=>{const o=new Set;for(const r of f){if(r===t)continue;const s=n.get(r)??$t(u(r));e.some(t=>s.some(e=>I(t,e,.5)>=8))&&o.add(r)}return o},"sharedTrackConflictsFor"),et=n((t,e,n,o)=>{const r=new Set;return Z(t).map(t=>q(v(t))).filter(e=>{if(T(t,e))return!1;const n=e.map(t=>`${t.x.toFixed(3)},${t.y.toFixed(3)}`).join("|");return!(r.has(n)||e.length<2)&&(r.add(n),!0)}).map(r=>{const s=$t(r);let i=0;for(const e of f)e!==t&&(i+=h(s,n.get(e)??$t(u(e))));return{candidate:r,candidateSegments:s,crossings:e.count-(o.get(t)??0)+i,bends:w(r,Ft),totalBends:w(r),length:k(r)}}).filter(({crossings:t})=>t<=e.count).sort((t,e)=>t.crossings-e.crossings||t.bends-e.bends||t.length-e.length).slice(0,48).map(e=>({path:e.candidate,segments:e.candidateSegments,sharedTrackConflicts:tt(t,e.candidateSegments,n),totalBends:e.totalBends,length:e.length}))},"pairCandidatesFor"),nt=n((t,e,n,o,r,s)=>{let i=0;for(const n of t.pairs)n.first!==e&&n.second!==e&&n.first!==o&&n.second!==o||(i+=n.count);let a=h(n.segments,r.segments);for(const t of f){if(t===e||t===o)continue;const i=s.get(t)??$t(u(t));a+=h(n.segments,i)+h(r.segments,i)}return t.count-i+a},"pairCrossingCount"),ot=n((t,e)=>{for(const n of t.sharedTrackConflicts)if(n!==e)return!1;return!0},"conflictsOnlyWith"),rt=n((t,e)=>t.segments.some(t=>e.segments.some(e=>I(t,e,.5)>=8)),"candidatesShareTrack"),st=n((t,e,n,o)=>ot(e,n.edge)&&ot(o,t.edge)&&!rt(e,o),"pairCandidatesAreCompatible"),it=n((t,e,n,o,r)=>{const s=nt(t.current,e.edge,n,o.edge,r,t.baseSegments);if(!(s>=t.current.count))return{replacements:new Map([[e.edge,n.path],[o.edge,r.path]]),crossings:s,bends:t.currentBends-(t.baseBendsByEdge.get(e.edge)??0)-(t.baseBendsByEdge.get(o.edge)??0)+n.totalBends+r.totalBends,length:t.currentLength-(t.baseLengthByEdge.get(e.edge)??0)-(t.baseLengthByEdge.get(o.edge)??0)+n.length+r.length}},"scorePairReplacement"),at=n((t,e)=>t.crossings<e.crossings||t.crossings===e.crossings&&(t.bends<e.bends||t.bends===e.bends&&t.length<e.length),"pairScoreIsBetter"),ct=n((t,e,n,o)=>{let r=o;for(const o of e.candidates)for(const s of n.candidates){if(!st(e,o,n,s))continue;const i=it(t,e,o,n,s);i&&at(i,r)&&(r=i)}return r},"bestScoreForOptionPair"),ft=n(t=>{const e=O(),n=R(),o=Q(),r=L(t),s=new Map(f.map(t=>[t,w(u(t))])),i=new Map(f.map(t=>[t,k(u(t))])),a=new Map,c=S(t);for(const e of c)for(const n of e){if(a.has(n))continue;const e=et(n,t,o,r);e.length>0&&a.set(n,{edge:n,candidates:e})}let d={replacements:new Map,crossings:t.count,bends:e,length:n};const l={current:t,currentBends:e,currentLength:n,baseBendsByEdge:s,baseLengthByEdge:i,baseSegments:o};for(const e of c){const n=new Set(e.filter(e=>t.edgeSet.has(e))),o=e.map(t=>a.get(t)).filter(t=>Boolean(t));for(let t=0;t<o.length;t++){const e=o[t];for(let r=t+1;r<o.length;r++){const t=o[r];(n.has(e.edge)||n.has(t.edge))&&(d=ct(l,e,t,d))}}}return d.replacements.size>0?d.replacements:void 0},"bestPairedReplacement");for(let t=0;t<4;t++){const t=p(),e=t.count;if(0===e)return;let n,o,r=e,s=Number.POSITIVE_INFINITY;for(const i of t.edges){const a=w(u(i),Ft);for(const c of Z(i)){const f=T(i,c),d=!f&&N(i,c),l=C(t,i,c),u=w(c,Ft);if(f||d)continue;(l<e||l===e&&u<a)&&(l>r||l===r&&u>=s||(n=i,o=c,r=l,s=u))}}if(n&&o){n.points=o;continue}const i=ft(t);if(!i)return;for(const[t,e]of i)t.points=e}}n(Xt,"separateSharedRenderedTerminalLanes"),n(zt,"collapseRedundantRectangularDoglegs"),n(Pt,"liftObstacleHuggingSameSideRails"),n(Gt,"liftTopLaneTitleBandsAboveRails"),n(Dt,"shiftLeftLaneTitleBandsLeftOfRails"),n(At,"swapDestinationTerminalTailsToReduceCrossings"),n(Ht,"reassignCrossingExternalRailChannels"),n(jt,"shortcutRedundantOrthogonalJogs"),n(_t,"resolveRenderedOrthogonalCrossings");var Vt=.001;function Wt(t,e){const{nodeInfoById:o,realNodeRects:r}=Y(e),s=["top","bottom","left","right"],i={top:Math.min(...r.map(t=>t.rect.top))-20,bottom:Math.max(...r.map(t=>t.rect.bottom))+20,left:Math.min(...r.map(t=>t.rect.left))-20,right:Math.max(...r.map(t=>t.rect.right))+20},a=n((t,e,n,o)=>{const r=[],s=E(t,e,n,o,20,Vt);return s&&r.push(s),e===o&&r.push($(t,e,n,i[e])),r},"buildOrthogonalPathCandidates"),c=n((t,e)=>{for(let n=0;n<t.length-1;n++){if(G(t[n],t[n+1],r,e,1))return!0}return!1},"pathHitsNode"),f=n((e,n,o=!1)=>{let r=0;const s=S(e,Vt),i=n.start,a=n.end;for(const e of t){if(e===n||e.isLayoutOnly)continue;const t=e.start,c=e.end;if(!o&&i&&a&&(t===i||t===a||c===i||c===a))continue;const f=e.points;if(f&&!(f.length<2))for(const t of s)for(const e of S(f,Vt))(D(t.a,t.b,e.a,e.b,Vt,Vt)||I(t,e,Vt)>=8)&&r++}return r},"pathConflictCount"),d=n((t,e)=>{const n=Math.abs(t.y-e.rect.top),o=Math.abs(t.y-e.rect.bottom),r=Math.abs(t.x-e.rect.left),s=Math.abs(t.x-e.rect.right);let i="top",a=n;return o<a&&(i="bottom",a=o),r<a&&(i="left",a=r),s<a&&(i="right",a=s),i},"nearestSideOfRect"),l=new Map,u=n((t,e,n)=>{const o=l.get(t)??[];o.push({side:e,edgeId:n}),l.set(t,o)},"addFaceClaim");for(const e of t){if(e.isLayoutOnly)continue;const t=e.points??[];if(t.length<1)continue;const n=e.id??"",r=e.start,s=e.end;if(r){const e=o.get(r);e&&u(r,d(t[0],e),n)}if(s){const e=o.get(s);e&&u(s,d(t[t.length-1],e),n)}}const h=n((t,e,n)=>l.get(t)?.some(t=>t.edgeId!==n&&t.side===e)??!1,"faceIsClaimed");for(const e of t){if(e.isLayoutOnly)continue;const t=e.points;if(!t||t.length<2)continue;const n=w(t,Vt);if(n<4)continue;const r=e.start,i=e.end;if(!r||!i)continue;const g=o.get(r),p=o.get(i);if(!g||!p)continue;const m=e.id??"",x=f(t,e,!0),y=f(t,e);let b,M=x,I=n;for(const t of s){if(h(r,t,m))continue;const n=F(g,t);for(const o of s){if(h(i,o,m))continue;const s=F(p,o);for(const d of a(n,t,s,o)){if(c(d,[r,i]))continue;const t=w(d,Vt);if(x>0){const n=f(d,e,!0);if(n>M||n===M&&t>=I)continue;M=n,I=t,b=d;continue}f(d,e)>y||t<I&&(I=t,b=d)}}}if(b){e.points=b;const t=l.get(r);t&&l.set(r,t.filter(t=>t.edgeId!==m));const n=l.get(i);n&&l.set(i,n.filter(t=>t.edgeId!==m)),u(r,d(b[0],g),m),u(i,d(b[b.length-1],p),m)}}}n(Wt,"simplifyDetouredEdges");var Kt=.001;function qt(t,e){const n=e?0:t.length-1,o=e?1:-1,r=t[n],s=t[n+o];if(!r||!s)return;const i=s.x-r.x,a=s.y-r.y;if(!(Math.abs(i)+Math.abs(a)<Kt)){if(Math.abs(a)<=Kt){const t=r.x+10*Math.sign(i);return{left:Math.min(r.x,t),right:Math.max(r.x,t),top:r.y-7,bottom:r.y+7}}if(Math.abs(i)<=Kt){const t=r.y+10*Math.sign(a);return{left:r.x-7,right:r.x+7,top:Math.min(r.y,t),bottom:Math.max(r.y,t)}}return{left:Math.min(r.x,s.x),right:Math.max(r.x,s.x),top:Math.min(r.y,s.y),bottom:Math.max(r.y,s.y)}}}function Ut(t){return{left:Math.min(t.left,t.right),right:Math.max(t.left,t.right),top:Math.min(t.top,t.bottom),bottom:Math.max(t.top,t.bottom)}}function Jt(t,e){const n=v(e);return[qt(n,!0),qt(n,!1)].some(e=>e&&R(t,Ut(e)))}function Zt(t,e){const o=[];for(const e of t){if(e.isLayoutOnly)continue;const t=e.points;if(t&&!(t.length<2))for(let n=0;n<t.length-1;n++)o.push({edgeId:e.id,p1:t[n],p2:t[n+1]})}const r=[],s=[];for(const t of e.values()){const e=t.isGroup,n=t.parentId;if(e&&!n){const e=B(t);e&&s.push({id:t.id,rect:e});continue}if(e)continue;if(t.isEdgeLabel)continue;const o=B(t);o&&r.push({nodeId:t.id,rect:o})}const i=n((t,e)=>{const n=N(e,3);for(const{nodeId:e,rect:o}of r)if(e!==t&&R(n,o))return!0;return!1},"labelOverlapsForeignNode"),a=n((t,e)=>{const n=N(e,3);for(const e of o)if(e.edgeId!==t&&L(e.p1,e.p2,n))return!0;return!1},"labelOverlapsForeignEdge"),c=n((t,e,n)=>i(t,n)||a(e,n),"labelOverlapsAnything"),f=[],d=n(t=>{for(const{id:e,rect:n}of s)if(O(n,t))return e},"findContainingLane"),l=n((t,e)=>f.some(n=>n.labelId!==t&&R(e,n.rect)),"overlapsPlacedLabel");for(const o of t){if(o.isLayoutOnly)continue;const t=o.labelNodeId;if(!t)continue;const r=e.get(t);if(!r)continue;const u=o.points;if(!u||u.length<2)continue;const h=r.width??0,g=r.height??0;if(h<=0||g<=0)continue;const p=[];for(let t=0;t<u.length-1;t++){const e=u[t],n=u[t+1],o=Math.abs(e.x-n.x),r=Math.abs(e.y-n.y);o<Kt&&r<Kt||(o>=Kt&&r>=Kt||p.push({idx:t,length:o+r,orientation:o>=Kt?"horizontal":"vertical",midX:(e.x+n.x)/2,midY:(e.y+n.y)/2}))}if(0===p.length)continue;const m=p.length>=3?p.filter(t=>t.idx>0&&t.idx<p.length-1):p,x=m.length>0?m:p,y=h>=g?"horizontal":"vertical",b=n(t=>[...t].sort((t,e)=>{const n=t.orientation===y;if(n!==(e.orientation===y))return n?-1:1;const o=t.length>=("horizontal"===t.orientation?h:g)+2;return o!==e.length>=("horizontal"===e.orientation?h:g)+2?o?-1:1:e.length-t.length}),"rankSegments"),M=p[0],I=p[p.length-1],S=[.5,.25,.75,.05,.95,.15,.85,.1,.9],w=n((t,e)=>{const n=u[t.idx],o=u[t.idx+1];return{midX:n.x+(o.x-n.x)*e,midY:n.y+(o.y-n.y)*e}},"anchorAtT"),v=n((t,e,n)=>Math.min(n,Math.max(e,t)),"clamp"),C=n((t,e)=>t.midX>=e.left-Kt&&t.midX<=e.right+Kt&&t.midY>=e.top-Kt&&t.midY<=e.bottom+Kt,"pointInsideRectInclusive"),L=n(t=>{const e=T(t.midX,t.midY,h,g),n=d(e);if(n)return{laneId:n,anchor:t,rect:e};const o=s.find(({rect:e})=>C(t,e));if(!o)return;const r=o.rect.left+h/2+1,i=o.rect.right-h/2-1,a=o.rect.top+g/2+1,c=o.rect.bottom-g/2-1;if(r>i||a>c)return;const f={midX:v(t.midX,r,i),midY:v(t.midY,a,c)},l=T(f.midX,f.midY,h,g);return C(t,l)?{laneId:o.id,anchor:f,rect:l}:void 0},"placementForAnchor"),k=n((t,e,n)=>"horizontal"===t.orientation?Math.abs(e.midX-n.x):Math.abs(e.midY-n.y),"distanceAlongSegment"),O=n((t,e)=>{const n=("horizontal"===t.orientation?h/2:g/2)+12;if(t===M){const o=u[t.idx];if(k(t,e,o)+Kt<n)return!1}if(t===I){const o=u[t.idx+1];if(k(t,e,o)+Kt<n)return!1}return!0},"labelClearsTerminalEndpoints"),R=n(e=>{const n=b(e);for(const e of n)for(const n of S){const r=w(e,n);if(!O(e,r))continue;const s=L(r);if(s&&(!Jt(s.rect,u)&&!l(t,s.rect)&&!c(t,o.id,s.rect)))return{laneId:s.laneId,anchor:s.anchor}}},"tryPool"),N=n((e,n,r=!1)=>{const s=b(e);for(const e of s){const s={midX:e.midX,midY:e.midY};if(n&&!O(e,s))continue;const c=L(s);if(c&&!Jt(c.rect,u)&&!l(t,c.rect)&&!i(t,c.rect)&&(r||!a(o.id,c.rect)))return{laneId:c.laneId,anchor:c.anchor}}},"findLaneContainingFallback"),B=R(x)??(x.length<p.length?R(p):void 0)??N(p,!0)??N(p,!1)??N(p,!1,!0);if(B){r.x=B.anchor.midX,r.y=B.anchor.midY,r.parentId=B.laneId;const e=T(B.anchor.midX,B.anchor.midY,h,g),n=f.findIndex(e=>e.labelId===t);n>=0?f[n]={labelId:t,rect:e}:f.push({labelId:t,rect:e})}}}n(qt,"markerClearanceRectFor"),n(Ut,"normalizeRect"),n(Jt,"labelOverlapsOwnMarker"),n(Zt,"anchorLabelsToPolyline");var Qt=1e-6;function te(t,e){return t<e?`${t}::${e}`:`${e}::${t}`}function ee(t,e){const{nodeInfoById:o,realNodeRects:r}=Y(e),s=new Map;for(const t of e){const e=t.id;t.isGroup||t.isEdgeLabel&&s.set(e,{w:t.width??0,h:t.height??0})}const i=n((e,o,r,i)=>{const a=te(o,r);let c=0;const f=n(t=>{if(!t)return;const e=s.get(t);if(!e)return;const n="x"===i?e.w/2:e.h/2;n>c&&(c=n)},"consider");f(e.labelNodeId);for(const n of t){if(n===e)continue;if(n.isLayoutOnly)continue;const t=n.start,o=n.end;t&&o&&(te(t,o)===a&&f(n.labelNodeId))}return c>0?c+3:0},"labelClearanceFor");for(const e of t){if(e.isLayoutOnly)continue;if(!C(e.points,Qt))continue;const n=P(e,o,Qt);if(!n)continue;const{srcId:s,dstId:a,srcInfo:c,dstInfo:f,collinearX:d,collinearY:l}=n;if(d===l)continue;let u,h;if(d){const t=f.cy>c.cy;u={x:c.cx,y:t?c.rect.bottom:c.rect.top},h={x:f.cx,y:t?f.rect.top:f.rect.bottom}}else{const t=f.cx>c.cx;u={x:t?c.rect.right:c.rect.left,y:c.cy},h={x:t?f.rect.left:f.rect.right,y:f.cy}}if(G(u,h,r,[s,a],1))continue;const g=i(e,s,a,d?"x":"y"),p=g>4?g:4,m=[0,p,-p];for(const n of m){const o={...u},i={...h};if(d){if(o.x+=n,i.x+=n,o.x<=c.rect.left||o.x>=c.rect.right)continue;if(i.x<=f.rect.left||i.x>=f.rect.right)continue}else{if(o.y+=n,i.y+=n,o.y<=c.rect.top||o.y>=c.rect.bottom)continue;if(i.y<=f.rect.top||i.y>=f.rect.bottom)continue}if(!G(o,i,r,[s,a],1)&&!H(o,i,t,e,{epsilon:Qt})){e.points=[o,i];break}}}}function ne(t,e){const o=.001,{realNodeRects:r,labelNodeRects:s}=X(e.values()),i=n((t,e)=>S(e,o).map(n=>({...n,edge:t,interior:n.index>=1&&n.index<=e.length-3})),"segmentsFor"),a=n(()=>{const e=[];for(const n of t){if(n.isLayoutOnly)continue;const t=n.points;!t||t.length<2||e.push(...i(n,v(t)))}return e},"allSegments"),c=n((t,e)=>t.horizontal&&e.horizontal?M(t.a.x,t.b.x,e.a.x,e.b.x)>=8&&Math.abs(t.a.y-e.a.y)<7:!(!t.vertical||!e.vertical)&&(M(t.a.y,t.b.y,e.a.y,e.b.y)>=8&&Math.abs(t.a.x-e.a.x)<7),"hasCrowdedParallelTrack"),f=n((e,n)=>{const a=e.start,f=e.end,d=i(e,n);if(d.length!==n.length-1)return!1;const l=[a,f].filter(t=>Boolean(t)),u=e.labelNodeId?[e.labelNodeId]:[];for(const t of d){if(G(t.a,t.b,r,l,-2))return!1;if(G(t.a,t.b,s,u,-2))return!1}for(const n of t){if(n===e||n.isLayoutOnly)continue;const t=n.points;if(t&&!(t.length<2))for(const e of d)for(const r of i(n,v(t))){if(c(e,r))return!1;if(j(e.a,e.b,r.a,r.b,o))return!1}}return!0},"candidateIsSafe"),d=n((t,e)=>{const n=v(t.edge.points??[]);if(n.length<4||t.index>=n.length-1)return;const o=n.map(t=>({...t}));if(t.horizontal)o[t.index].y+=e,o[t.index+1].y+=e;else{if(!t.vertical)return;o[t.index].x+=e,o[t.index+1].x+=e}return i(t.edge,o).length===o.length-1?o:void 0},"shiftedCandidate"),l=n((t,e)=>({x:t.x??(e.left+e.right)/2,y:t.y??(e.top+e.bottom)/2}),"nodeCenter"),u=n(t=>{const n=t.edge,o=v(n.points??[]);if(4!==o.length||1!==t.index)return;const r=n.start?e.get(n.start):void 0,s=n.end?e.get(n.end):void 0,i=r?B(r):void 0,a=s?B(s):void 0,c=o.slice(t.index+2);return r&&s&&i&&a&&0!==c.length?{sourceCenter:l(r,i),targetCenter:l(s,a),sourceRect:i,tail:c}:void 0},"sourceDetourContextFor"),h=n((t,e,n,r,s,i)=>{const a=r.y>=n.y,c=a?s.bottom:s.top,f=c+(a?20:-20);if(a&&t.b.y<=f+o||!a&&t.b.y>=f-o)return;const d=t.a.x+e;return v([{x:n.x,y:c},{x:n.x,y:f},{x:d,y:f},{x:d,y:t.b.y},...i],o)},"verticalSourceDetour"),g=n((t,e,n,r,s,i)=>{const a=r.x>=n.x,c=a?s.right:s.left,f=c+(a?20:-20);if(a&&t.b.x<=f+o||!a&&t.b.x>=f-o)return;const d=t.a.y+e;return v([{x:c,y:n.y},{x:f,y:n.y},{x:f,y:d},{x:t.b.x,y:d},...i],o)},"horizontalSourceDetour"),p=n((t,e)=>{const n=u(t);if(n)return t.vertical?h(t,e,n.sourceCenter,n.targetCenter,n.sourceRect,n.tail):t.horizontal?g(t,e,n.sourceCenter,n.targetCenter,n.sourceRect,n.tail):void 0},"sourceDetourCandidate"),m=[-7,7,-14,14,-21,21];for(let t=0;t<12;t++){const t=a();let e=!1;for(let n=0;n<t.length&&!e;n++)for(let o=n+1;o<t.length&&!e;o++){const r=t[n],s=t[o];if(r.edge===s.edge||!c(r,s))continue;const i=[r,s].filter(t=>t.interior);for(const t of i){for(const n of m){const o=d(t,n);if(o&&f(t.edge,o)){t.edge.points=o,e=!0;break}const r=p(t,n);if(r&&f(t.edge,r)){t.edge.points=r,e=!0;break}}if(e)break}}if(!e)return}}function oe(t,e,n,o){const r=e.x-t.x,s=e.y-t.y,i=o.x-n.x,a=o.y-n.y,c=r*a-s*i;if(Math.abs(c)<1e-10)return!1;const f=n.x-t.x,d=n.y-t.y,l=(f*a-d*i)/c,u=(f*s-d*r)/c,h=.01;return l>h&&l<.99&&u>h&&u<.99}function re(t){const e=t.nodes??[],n=t.edges??[],r=[];if(!n.length||!e.length)return r;const s=z(e),i=[];for(const t of n){if(t.isLayoutOnly)continue;const e=t.points;if(!e||e.length<2)continue;const n=t.start,o=t.end,a=t.labelNodeId,c=t.id??`${n}->${o}`;for(const t of s)if(t.nodeId!==n&&t.nodeId!==o&&(!a||t.nodeId!==a))for(let n=0;n<e.length-1;n++)if(L(e[n],e[n+1],t,-1)){r.push({type:"edge-node-overlap",edgeId:c,targetId:t.nodeId,detail:`segment ${n} passes through node "${t.nodeId}"`});break}for(let t=0;t<e.length-1;t++)i.push({edgeId:c,start:n,end:o,p1:e[t],p2:e[t+1]})}const a=new Set;for(let t=0;t<i.length;t++)for(let e=t+1;e<i.length;e++){const n=i[t],o=i[e];if(n.edgeId!==o.edgeId&&(n.start!==o.start&&n.start!==o.end&&n.end!==o.start&&n.end!==o.end&&oe(n.p1,n.p2,o.p1,o.p2))){const t=n.edgeId<o.edgeId?`${n.edgeId}|${o.edgeId}`:`${o.edgeId}|${n.edgeId}`;a.has(t)||(a.add(t),r.push({type:"edge-edge-crossing",edgeId:n.edgeId,targetId:o.edgeId,detail:`edges "${n.edgeId}" and "${o.edgeId}" cross`}))}}if(r.length>0){const t=r.filter(t=>"edge-node-overlap"===t.type).length,e=r.filter(t=>"edge-edge-crossing"===t.type).length;o.warn(`[SWIMLANE_VALIDATE] ${r.length} issue(s) detected: ${t} edge-node overlap(s), ${e} edge crossing(s)`);for(const t of r)o.warn(`[SWIMLANE_VALIDATE] ${t.type}: ${t.detail}`)}return r}function se(t,e){const o=t.nodes??[],r=t.edges??[],s=o.filter(t=>!t.isGroup);if(("LR"===e||"RL"===e)&&s.length>0&&!Ot(t,e))return;if("BT"===e&&s.length>0&&!kt(t))return;for(const t of r){if(t.isLayoutOnly)continue;const e=t.points;!e||e.length<2||(t.points=q(K(e)))}Wt(r,o),ee(r,o),Tt(r,o);const i=new Map;for(const t of o)i.set(String(t.id),t);Zt(r,i),tt(r,i),Bt(r,i),ne(r,i),Xt(r,i),zt(r,i),Pt(r,i),At(r,i);const a=n(()=>{_t(r,i),Xt(r,i),Ht(r,i),jt(r,i),Zt(r,i),bt(r,i),Pt(r,i),Zt(r,i),bt(r,i)},"finalizeRenderedEdges");a(),ne(r,i),a(),Gt(r,i,e),Dt(r,i,e),Gt(r,i,e),Dt(r,i,e)}function ie(t){const e=new Map(t.nodeById),n=new Set,o=[];for(const r of t.edges){if(!e.has(r.src)||!e.has(r.dst))continue;const t=`${r.id}:${r.src}->${r.dst}`;n.has(t)||(n.add(t),o.push(r))}return{nodes:[...e.keys()],edges:o,layout:t.layout,nodeById:e}}function ae(t,e){return t.edges.filter(t=>t.dst===e)}function ce(t){const e=new Map;for(const n of t.nodes)e.set(n,[]);for(const n of t.edges)e.get(n.src).push(n.dst);return e}function fe(t){const e=ce(t);for(const t of e.values())t.sort((t,e)=>t.localeCompare(e));return e}function de(t){const e=new Map;for(const n of t.nodes)e.set(n,0);for(const n of t.edges)e.set(n.dst,(e.get(n.dst)??0)+1);return e}function le(t,e){const o=[...e.entries()].filter(([,t])=>0===t).map(([t])=>t).sort((t,e)=>t.localeCompare(e)),r=new Set(t.edges.flatMap(t=>[t.src,t.dst])),s=n(e=>!r.has(e)&&!t.nodeById.get(e)?.isGroup,"isUnconnected"),i=[...e.keys()].filter(t=>0===e.get(t)&&s(t));let a=0;return o.map(t=>s(t)?i[a++]:t)}function ue(t,e=()=>!0){const n=new Map,o=new Map;for(const e of t.nodes)n.set(e,[]),o.set(e,[]);for(const r of t.edges)e(r)&&(o.get(r.src).push(r.dst),n.get(r.dst).push(r.src));return{preds:n,succs:o}}function he(t,e,n,o){let r=0;for(const e of t.nodes)o?.skipGroups&&t.nodeById.get(e)?.isGroup||(r=Math.max(r,n[e]??0));const s=Array.from({length:r+1},()=>[]);for(const r of e)o?.skipGroups&&t.nodeById.get(r)?.isGroup||s[Math.max(0,n[r]??0)].push(r);return s}function ge(t){const e=de(t),n=le(t,e),o=[],r=fe(t);for(;n.length;){const t=n.shift();o.push(t);for(const o of r.get(t)??[])if(e.set(o,(e.get(o)??0)-1),0===(e.get(o)??0)){let t=0;for(;t<n.length&&n[t]<o;)t++;n.splice(t,0,o)}}return o.length===t.nodes.length?o:null}function pe(t){const e=new Map;let n=0;for(const o of t)e.set(o,n),n++;return e}function me(t){const e=new Array(t.length),o=n((n,r)=>{if(r-n<=1)return 0;const s=n+r>>1;let i=o(n,s)+o(s,r),a=n,c=s,f=n;for(;a<s||c<r;)c>=r||a<s&&t[a]<=t[c]?e[f++]=t[a++]:(e[f++]=t[c++],i+=s-a);for(let o=n;o<r;o++)t[o]=e[o];return i},"count");return o(0,t.length)}function xe(t){const e=ie(t),o=new Map;for(const t of e.nodes)o.set(t,[]);for(const t of e.edges)o.get(t.src).push(t);for(const t of o.values())t.sort((t,e)=>t.dst===e.dst?t.id.localeCompare(e.id):t.dst.localeCompare(e.dst));const r=Object.create(null);for(const t of e.nodes)r[t]=0;const s=[],i=n(t=>{r[t]=1;for(const e of o.get(t)??[]){const t=e.dst;0===r[t]?i(t):1===r[t]&&s.push(e)}r[t]=2},"dfs"),a=de(e),c=[...e.nodes.filter(t=>0===(a.get(t)??0)),...e.nodes.filter(t=>0!==(a.get(t)??0))];for(const t of c)0===r[t]&&i(t);const f=new Set(s.map(t=>`${t.id}:${t.src}->${t.dst}`)),d=e.edges.map(t=>f.has(`${t.id}:${t.src}->${t.dst}`)?{id:t.id,src:t.dst,dst:t.src,weight:t.weight,ref:t.ref}:t);return{acyclic:{nodes:[...e.nodes],edges:d,layout:e.layout,nodeById:new Map(e.nodeById)},reversed:s}}function ye(t){const e=new Map,o=n(n=>{if(e.has(n))return e.get(n);const r=t.nodeById.get(n);if(!r)return e.set(n,null),null;const s=r.parentId;if(!s)return e.set(n,null),null;const i=o(s)??s;return e.set(n,i),i},"resolve");for(const e of t.nodes)o(e);return e}function be(t){const e=ye(t);return t=>e.get(t)??null}function Me(t){const e=[];for(const n of t.layout.nodes??[])n.isGroup&&!n.parentId&&e.push(n.id);return[...new Set(e)].reverse()}function Ie(t,e){const n=Me(t);if(!e||0===e.length)return n;const o=new Set(n),r=new Set,s=[];for(const t of e)o.has(t)&&!r.has(t)&&(r.add(t),s.push(t));for(const t of n)r.has(t)||s.push(t);return s}n(te,"pairKey"),n(ee,"straightenCollinearSiblingDetours"),n(ne,"nudgeSharedInteriorSubpaths"),n(oe,"segmentsIntersect"),n(re,"validateSwimlanesLayout"),n(se,"postProcessSwimlaneLayout"),n(ie,"normalizeGraph"),n(ae,"incoming"),n(ce,"buildSuccessorMap"),n(fe,"buildSortedSuccessorMap"),n(de,"buildInDegreeMap"),n(le,"sortedZeroInDegreeNodes"),n(ue,"buildPredecessorSuccessorMaps"),n(he,"buildLayersFromRanks"),n(ge,"topoSortIfAcyclic"),n(pe,"buildLayerIndex"),n(me,"countInversions"),n(xe,"removeCycles_DFS"),n(ye,"buildTopLaneMap"),n(be,"createTopLaneResolver"),n(Me,"buildTopLaneOrder"),n(Ie,"resolveTopLaneOrder");var Se=8,we=4,ve=!0,Ce=100,Le=40;function ke(t,e){const o=ie(t),r=e?.laneOf??(()=>null),s=e?.rankHint,{preds:i}=ue(o);for(const t of i.values())t.sort((t,e)=>t.localeCompare(e));const a=ge(o)??[...o.nodes].sort((t,e)=>t.localeCompare(e)),c=new Map;for(const[t,e]of a.entries())c.set(e,t);const f=new Map,d=new Map;for(const t of o.nodes)d.set(t,[]);for(const t of a){const e=(i.get(t)??[]).filter(t=>f.has(t));if(e.length>0){const n=Oe(t,e,{laneOf:r,rankHint:s,topoIndex:c});f.set(t,n),d.get(n).push(t)}else f.has(t)||f.set(t,null)}for(const t of o.nodes)f.has(t)||f.set(t,null);const l=new Set;for(const t of o.nodes)null===(f.get(t)??null)&&l.add(t);const u=[...l].sort((t,e)=>{const n=c.get(t)??0,o=c.get(e)??0;return n===o?t.localeCompare(e):n-o}),h=Re(o),g=new Map;for(const[t,e]of h.entries())g.set(t,[...e].sort((t,e)=>t.localeCompare(e)));const p=Ne(g),m=Te(g),x=new Map;for(const t of o.nodes)x.set(t,[]);for(const t of m)for(const e of t.nodes){const n=x.get(e);n?n.push(t.id):x.set(e,[t.id])}const y=[],b=[],M=new Set,I=n(t=>{if(!M.has(t)){M.add(t),y.push(t);for(const e of d.get(t)??[])I(e);b.push(t)}},"walk");for(const t of u)I(t);for(const t of a)I(t);return{parent:f,children:d,roots:u,componentOf:p,blocks:m,nodeBlocks:x,adjacency:g,preorder:y,postorder:b,topologicalOrder:a}}function Oe(t,e,n){const o=n.laneOf(t);return[...e].sort((t,e)=>{const r=n.laneOf(t),s=n.laneOf(e),i=null!=r&&r===o;if(i!==(null!=s&&s===o))return i?-1:1;const a=n.rankHint?.[t],c=n.rankHint?.[e];if(null!=a&&null!=c&&a!==c)return c-a;const f=n.topoIndex.get(t)??0,d=n.topoIndex.get(e)??0;return f!==d?f-d:t.localeCompare(e)})[0]}function Re(t){const e=new Map;for(const n of t.nodes)e.set(n,new Set);for(const n of t.edges)e.get(n.src).add(n.dst),e.get(n.dst).add(n.src);return e}function Ne(t){const e=new Map;let n=0;for(const o of t.keys()){if(e.has(o))continue;const r=[o];for(;r.length>0;){const o=r.pop();if(!e.has(o)){e.set(o,n);for(const n of t.get(o)??[])e.has(n)||r.push(n)}}n++}return e}function Te(t){const e=new Map,o=new Map,r=[],s=[];let i=0;const a=n((n,c)=>{e.set(n,++i),o.set(n,i);for(const f of t.get(n)??[])f!==c&&(e.has(f)?(e.get(f)??0)<(e.get(n)??0)&&(r.push([n,f]),o.set(n,Math.min(o.get(n)??i,e.get(f)??i))):(r.push([n,f]),a(f,n),o.set(n,Math.min(o.get(n)??i,o.get(f)??i)),(o.get(f)??0)>=(e.get(n)??0)&&s.push(Be(n,f,r,s.length))))},"visit");for(const n of t.keys())e.has(n)||a(n,null);return s}function Be(t,e,n,o){const r=[],s=new Set;for(;n.length>0;){const o=n.pop();if(r.push(o),s.add(o[0]),s.add(o[1]),o[0]===t&&o[1]===e||o[0]===e&&o[1]===t)break}return{id:o,edges:r,nodes:[...s]}}function Fe(t,e,o){const r=[...t.nodes],s=new Map;for(const[t,e]of r.entries())s.set(e,t);const i=r.length,a=new Array(i).fill(-1),c=new Array(i).fill(0),f=[],d=new Set;for(const t of r){const e=o.parent.get(t)??null,n=s.get(t);null!=n&&(null==e&&(a[n]=-1,c[n]=0,d.has(t)||(d.add(t),f.push(t))))}for(;f.length>0;){const t=f.shift(),e=s.get(t);if(null==e)continue;const n=o.children.get(t)??[];for(const t of n){if(d.has(t))continue;const n=s.get(t);null!=n&&(a[n]=e,c[n]=c[e]+1,d.add(t),f.push(t))}}for(const t of r){if(d.has(t))continue;const e=s.get(t);null!=e&&(a[e]=-1,c[e]=0,d.add(t))}const l=Math.max(1,Math.ceil(Math.log2(Math.max(1,i)))+1),u=Array.from({length:l},()=>new Array(i).fill(-1));for(let t=0;t<i;t++)u[0][t]=a[t];for(let t=1;t<l;t++)for(let e=0;e<i;e++){const n=u[t-1][e];u[t][e]=-1===n?-1:u[t-1][n]}const h=n((t,e)=>{if(-1===t||-1===e)return-1;c[t]<c[e]&&([t,e]=[e,t]);const n=c[t]-c[e];for(let e=0;e<l;e++)if(n>>e&1&&-1===(t=u[e][t]))return-1;if(t===e)return t;for(let n=l-1;n>=0;n--){const o=u[n][t],r=u[n][e];-1!==o&&-1!==r&&(o!==r&&(t=o,e=r))}return u[0][t]},"lcaIndex"),g=Array.from({length:i},()=>new Map);for(const n of t.edges){let t=n.src,o=n.dst,r=e[t],i=e[o];if(null==r||null==i)continue;if(r>i&&([t,o]=[o,t],[r,i]=[i,r]),null==r||null==i||r===i)continue;const a=s.get(t),c=s.get(o);if(null==a||null==c)continue;const f=h(a,c);if(-1===f)continue;const d=g[f];for(let t=r;t<i;t++)d.set(t,(d.get(t)??0)+1)}const p=new Map,m=n((t,e)=>{if(0!==e.size)for(const[n,o]of e)t.set(n,(t.get(n)??0)+o)},"mergeInto"),x=new Set,y=n(t=>{const n=s.get(t);x.add(t);const r=null==n?void 0:g[n],i=r?new Map(r):new Map,a=o.children.get(t)??[];for(const n of a){const o=y(n),r=e[t];if(null!=r){let s=p.get(t);s||(s=new Map,p.set(t,s));let i=o.get(r)??0;const a=e[n];null!=a&&a>r&&(i+=1),s.set(n,i)}m(i,o)}return i},"dfs");for(const t of o.roots)x.has(t)||y(t);for(const t of r)x.has(t)||y(t);return p}function Ee(t,e,o){const r=new Map,s=n(t=>{let n=o[t]??0;const i=[...e.get(t)??[]];i.sort($e(o));for(const t of i){s(t);const e=r.get(t);null!=e&&(n=Math.min(n,e))}r.set(t,n)},"annotate");for(const e of t)s(e);return r}function $e(t){return(e,n)=>{const o=t[e]??0,r=t[n]??0;return o===r?e.localeCompare(n):o-r}}function Ye(t,e,o,r){let s=0;for(const t of e){const e=o[t]??0;e>s&&(s=e)}const i=Array.from({length:s+1},()=>[]),a=new Set,c=n(t=>{if(a.has(t))return;a.add(t);const e=o[t]??0;i[e]||(i[e]=[]),i[e].push(t);for(const e of r(t))c(e)},"emit");for(const e of t)c(e);for(const t of e)if(!a.has(t)){const e=o[t]??0;i[e]||(i[e]=[]),i[e].push(t),a.add(t)}return i}function Xe(t){const e=[];for(const n of t){const t=new Set,o=[];for(const e of n)t.has(e)||(t.add(e),o.push(e));e.push(o)}return e}function ze(t,e,n,o){return r=>{const s=t.get(r)??[];if(0===s.length)return[];const i=e[r]??0,a=[],c=[],f=n.get(r);for(const t of s){const e=o.get(t)??i;e>i?a.push({child:t,min:e}):c.push(t)}return a.sort((t,e)=>t.min===e.min?t.child.localeCompare(e.child):t.min-e.min),c.sort((t,e)=>{const n=f?.get(t)??0,r=f?.get(e)??0;if(n!==r)return n-r;const s=o.get(t)??i,a=o.get(e)??i;return s!==a?s-a:t.localeCompare(e)}),[...a.map(t=>t.child),...c]}}function Pe(t,e,n){const o=ke(t,{rankHint:e,laneOf:n}),{children:r,roots:s}=o;for(const e of t.nodes)r.has(e)||r.set(e,[]);const i=Fe(t,e,o),a=[...s].sort($e(e)),c=ze(r,e,i,Ee(a,r,e));let f=Ye(a,t.nodes,e,c);return f=Xe(f),f}function Ge(t,e,n){const o=new Set(t),r=new Set(e),s=pe(e),i=[];for(const t of n)o.has(t.src)&&r.has(t.dst)&&i.push(s.get(t.dst));return me(i)}function De(t,e,n){const o=[];for(const t of e){const e=n[t.src],r=n[t.dst];if(null==e||null==r||e===r)continue;let s=t.src,i=t.dst,a=e,c=r;e>r&&(s=t.dst,i=t.src,a=r,c=e);for(let e=a;e<c;e++)o.push({id:`${t.id}@${e}`,src:s,dst:i,ref:t.ref})}let r=0;for(let e=0;e+1<t.length;e++)r+=Ge(t[e],t[e+1],o);return r}function Ae(t,e){const n={...e},{preds:o}=ue(t),r=be(t);let s=De(Pe(t,n,r),t.edges,n);const i=we;for(let e=0;e<i;e++){let e=!1;const i=[...t.nodes].sort((t,e)=>(n[e]??0)-(n[t]??0));for(const a of i){const i=n[a]??0;if(0===i)continue;let c=0;for(const t of o.get(a)??[])c=Math.max(c,(n[t]??0)+1);if(c>=i)continue;const f=i;n[a]=c;const d=De(Pe(t,n,r),t.edges,n);d<s?(s=d,e=!0):n[a]=f}if(!e)break}return n}function He(t,e){const n=be(t),o=[...t.nodes].sort((t,n)=>(e[t]??0)-(e[n]??0)||t.localeCompare(n));for(const r of o){const o=n(r);if(!o)continue;const s=t.edges.filter(t=>t.src===r);if(0===s.length)continue;let i=!1,a=0;for(const t of s){const e=n(t.dst);null==e||e===o?i=!0:a++}if(0===a||i)continue;let c=0,f=!1;for(const e of t.edges){if(e.dst!==r)continue;const t=n(e.src);t&&(t===o?f=!0:c++)}if(c>0||!f)continue;const d=e[r]??0,l=d+a;let u=0;for(const n of t.edges)n.dst===r&&(u=Math.max(u,(e[n.src]??0)+1));const h=Math.max(d,u,l);h!==d&&(e[r]=h)}}function je(t,e){const n=ie(t),o=ge(n)??[...n.nodes].sort(),r=e?.compactSingleInput??!1,s=be(n);let i=Object.create(null);for(const t of o){const o=ae(n,t),a=e?.ignoreCrossLaneEdges?o.filter(e=>{const n=s(e.src),o=s(t);return!n||!o||n===o}):o;if(0===a.length)i[t]=0;else if(r&&1===a.length){const e=a[0].src,n=s(e),o=s(t);i[t]=n!==o?i[e]??0:(i[e]??0)+1}else{let e=-1/0;for(const t of a)e=Math.max(e,(i[t.src]??0)+1);i[t]=e===-1/0?0:e}}e?.optimizeRanksByCrossings&&(i=Ae(n,i)),e?.ignoreCrossLaneEdges&&He(n,i);return{layers:Pe(n,i,s),rankOf:i,dummy:new Set}}function _e(t,e){const o=ie(t),r={...je(o,{compactSingleInput:e?.compactSingleInput,ignoreCrossLaneEdges:e?.ignoreCrossLaneEdges,optimizeRanksByCrossings:e?.optimizeRanksByCrossings}).rankOf},s=be(o),{preds:i,succs:a}=ue(o,t=>{if(e?.ignoreCrossLaneEdges){const e=s(t.src),n=s(t.dst);if(e&&n&&e!==n)return!1}return!0}),c=ge(o)??[...o.nodes],f=[...c].reverse(),d=n((t,e)=>{let n=0;for(const e of i.get(t)??[])n=Math.max(n,(r[e]??0)+1);let o=Number.POSITIVE_INFINITY;const s=a.get(t)??[];return s.length>0&&(o=Math.min(...s.map(t=>(r[t]??0)-1))),Number.isFinite(o)||(o=Math.max(n,e)),Math.min(Math.max(e,n),o)},"clampFeasible"),l=Se,u=n(t=>{let e=!1;for(const n of t){const t=i.get(n)??[],o=a.get(n)??[];if(0===t.length&&0===o.length)continue;const s=t.length>0?t.reduce((t,e)=>t+(r[e]??0)+1,0)/t.length:r[n]??0,c=o.length>0?o.reduce((t,e)=>t+(r[e]??0)-1,0)/o.length:r[n]??0,f=Math.round((s+c)/2),l=d(n,f);l!==r[n]&&(r[n]=l,e=!0)}return e},"relaxOrder");for(let t=0;t<l;t++){const t=u(c),e=u(f);if(!t&&!e)break}for(const t of c){let e=0;for(const n of i.get(t)??[])e=Math.max(e,(r[n]??0)+1);(r[t]??0)<e&&(r[t]=e)}for(const t of f){const e=a.get(t)??[];if(e.length>0){const n=Math.min(...e.map(t=>(r[t]??0)-1));(r[t]??0)>n&&(r[t]=n)}}return{layers:he(o,c,r),rankOf:r,dummy:new Set}}function Ve(t){const e=de(t),n=fe(t);let o=le(t,e);const r=[];for(;o.length>0;){const t=[];for(const s of o){r.push(s);for(const o of n.get(s)??[])e.set(o,(e.get(o)??0)-1),0===(e.get(o)??0)&&t.push(o)}o=t.sort((t,e)=>t.localeCompare(e))}return r.length===t.nodes.length?r:null}function We(t,e){const o=ie(t),r="LR"===e?.direction?Ve(o)??[...o.nodes].sort():ge(o)??[...o.nodes].sort(),s=be(o),i=n(t=>s(t)??t,"laneOf"),a=Object.create(null),c=new Map,f=n((t,n)=>e?.ignoreCrossLaneEdges??!0?i(t)===i(n)?1:0:1,"edgeWeight");for(const t of r){const e=o.nodeById.get(t);if(e?.isGroup)continue;const n=ae(o,t);let r=0;if(n.length>0)for(const e of n){const n=e.src,o=a[n]??0;r=Math.max(r,o+f(n,t))}const s=i(t),d=c.get(s)??0,l=Math.max(r,d);a[t]=l,c.set(s,l+1)}return{layers:he(o,r,a,{skipGroups:!0}),rankOf:a,dummy:new Set}}function Ke(t,e){const o=ie(e),{rankOf:r}=t,s=t.layers.map(t=>[...t]),i=new Set(t.dummy?[...t.dummy]:[]);let a=0;const c=new Map(o.nodeById),f=n(t=>{const e="placeholder-"+a++,n={id:e,isGroup:!1,isDummy:!0,width:0,height:0};for(c.set(e,n),i.add(e);s.length<=t;)s.push([]);return s[t].push(e),r[e]=t,e},"addDummyAt"),d=[...o.edges].sort((t,e)=>t.id===e.id?t.src===e.src?t.dst.localeCompare(e.dst):t.src.localeCompare(e.src):t.id.localeCompare(e.id)),l=[];for(const t of d){const e=r[t.src]??0,n=r[t.dst]??0;if(n-e<=1){l.push(t);continue}let o=t.src;for(let r=e+1,s=0;r<n;r++,s++){const e=f(r);l.push({id:`${t.id}#${s}`,src:o,dst:e,weight:t.weight,ref:t.ref}),o=e}const s=n-e-2;l.push({id:`${t.id}#${Math.max(s+1,0)}`,src:o,dst:t.dst,weight:t.weight,ref:t.ref})}const u={nodes:[...o.nodes,...[...i].filter(t=>!o.nodes.includes(t))],edges:l,layout:o.layout,nodeById:c};return{layering:{layers:s,rankOf:r,dummy:i},graphWithDummies:u}}function qe(t){const e=t.length;if(0===e)return Number.POSITIVE_INFINITY;const n=[...t].sort((t,e)=>t-e);return e%2==1?n[(e-1)/2]:.5*(n[e/2-1]+n[e/2])}function Ue(t){if(0===t.length)return Number.POSITIVE_INFINITY;return t.reduce((t,e)=>t+e,0)/t.length}function Je(t,e,n,o){const r=new Map;for(const e of t)r.set(e,[]);for(const t of n)"down"===o?e.has(t.src)&&r.has(t.dst)&&r.get(t.dst).push(e.get(t.src)):e.has(t.dst)&&r.has(t.src)&&r.get(t.src).push(e.get(t.dst));return r}function Ze(t,e,n){const o=n.get(t)??0,r=n.get(e)??0;return o!==r?o-r:t.localeCompare(e)}function Qe(t,e,n){const o=new Set(t),r=new Set(e),s=pe(t),i=pe(e),a=[];for(const t of n)o.has(t.src)&&r.has(t.dst)&&a.push({u:s.get(t.src),v:i.get(t.dst)});a.sort((t,e)=>t.u===e.u?t.v-e.v:t.u-e.u);return me(a.map(t=>t.v))}function tn(t,e,n){return[...t].sort((t,o)=>{const r=qe(e.get(t)??[]),s=qe(e.get(o)??[]);return r===s?Ze(t,o,n):isFinite(r)?isFinite(s)?r-s:-1:1})}function en(t,e,n,o,r,s){const i=pe(t),a=pe(e),c=Je(e,i,n,o);if(!r||!s||0===s.length)return tn(e,c,a);const f=new Map;for(const t of e){const e=r(t),n=f.get(e)??[];n.push(t),f.set(e,n)}const d=[];for(const t of s){const e=f.get(t);if(!e||0===e.length)continue;const n=tn(e,c,a);d.push(...n)}const l=f.get(null);if(l&&l.length>0){const t=tn(l,c,a);for(const e of t){const t=Ue(c.get(e)??[]);let n=d.length;if(isFinite(t))for(const[e,o]of d.entries()){if(t<Ue(c.get(o)??[])){n=e;break}}d.splice(n,0,e)}}return d}function nn(t,e,o,r,s){const i=[...e],a=new Set(t),c=new Set(e),f=r?new Set(r):null,d=o.filter(t=>a.has(t.src)&&c.has(t.dst)),l=f?o.filter(t=>c.has(t.src)&&f.has(t.dst)):void 0,u=n(e=>{let n=Qe(t,e,d);return l&&r&&(n+=Qe(e,r,l)),n},"crossingScore"),h=s?new Map:null;if(s&&h)for(const t of e)h.set(t,s(t));let g=!0,p=u(i);for(;g;){g=!1;for(let t=0;t+1<i.length;t++){if(h){if(h.get(i[t])!==h.get(i[t+1]))continue}const e=p;[i[t],i[t+1]]=[i[t+1],i[t]];const n=u(i);n<e?(p=n,g=!0):[i[t],i[t+1]]=[i[t+1],i[t]]}}return i}function on(t,e,n){const o=t.layers.map(t=>[...t]),r=e.edges,s=be(e),i=Ie(e,n?.laneOrder);for(let t=0;t<3;t++){for(let t=1;t<o.length;t++)o[t]=en(o[t-1],o[t],r,"down",s,i),o[t]=nn(o[t-1],o[t],r,o[t+1],s);for(let t=o.length-2;t>=0;t--)o[t]=en(o[t+1],o[t],r,"up",s,i),o[t]=nn(o[t+1],o[t],r,o[t-1],s)}return{layers:o}}function rn(t,e,o){const r=o?.layerGap??Ce,s=o?.nodeGap??Le,i=o?.laneGap??2*s,a=o?.direction??"TB",c="LR"===a||"RL"===a,f=t.layers,d=Object.create(null),l=Object.create(null),u=n(t=>e.nodeById.get(t),"getNode"),h=n(t=>u(t)?.width??0,"getWidth"),g=n(t=>u(t)?.height??0,"getHeight"),p=be(e),m=Ie(e,o?.laneOrder),x=f.map(t=>t.reduce((t,e)=>Math.max(t,g(e)),0)),y=[];if(c)for(let t=0;t+1<f.length;t++){const e=f[t].reduce((t,e)=>Math.max(t,h(e)),0),n=f[t+1].reduce((t,e)=>Math.max(t,h(e)),0),o=x[t]/2+x[t+1]/2,s=(e+n)/2,i=Math.max(0,s-o-r);y.push(i)}const b=new Set;for(const t of f)for(const e of t)b.add(p(e));const M=b.has(null),I=m.filter(t=>b.has(t)),S=[...M?[null]:[],...I],w=Object.create(null);for(const t of I)w[t]=0;M&&(w.null=0);for(const t of f){const e=Object.create(null),n=[];for(const o of t){const t=p(o);null===t?n.push(o):(e[t]||=[]).push(o)}for(const[t,n]of Object.entries(e)){const e=n.reduce((t,e)=>t+h(e),0)+s*Math.max(0,n.length-1);w[t]=Math.max(w[t]??0,e)}if(M&&n.length){const t=n.reduce((t,e)=>t+h(e),0)+s*Math.max(0,n.length-1);w.null=Math.max(w.null??0,t)}}const v=new Map;{const t=S.map(t=>(null===t?w.null:w[t])??0);let e=-(t.reduce((t,e)=>t+e,0)+i*Math.max(0,S.length-1))/2;for(let n=0;n<S.length;n++){const o=S[n],r=t[n]??0,s=e+r/2;v.set(o,s),e+=r,n<S.length-1&&(e+=i)}}let C=0;for(const[t,e]of f.entries()){const n=x[t]??0,o=new Map;for(const t of e){const e=p(t),n=o.get(e)??[];n.push(t),o.set(e,n)}for(const t of S){const e=o.get(t)??[];if(0===e.length)continue;const r=v.get(t);if(1===e.length){const t=e[0];d[t]=r,l[t]=C+n/2}else{const t=e.map(t=>h(t));let o=r-(t.reduce((t,e)=>t+e,0)+s*(e.length-1))/2;for(const[r,i]of e.entries()){const e=t[r];d[i]=o+e/2,l[i]=C+n/2,o+=e+s}}}C+=n+r+(y[t]??0)}const L=new Map;for(const t of e.edges){const e=t.ref.id;L.has(e)||L.set(e,[]),L.get(e).push(t)}for(const[,t]of L){if(0===t.length)continue;const n=t[0].ref,o=n.start,r=n.end;if(null==o||null==r)continue;const s=Math.round(((d[o]??0)+(d[r]??0))/2),i=new Set;for(const e of t)i.add(e.src),i.add(e.dst);for(const t of i){if(t===o||t===r)continue;const n=e.nodeById.get(t);n?.isDummy&&(d[t]=s)}}return{x:d,y:l}}n(ke,"buildDrivingTree"),n(Oe,"chooseParent"),n(Re,"buildAdjacency"),n(Ne,"assignComponents"),n(Te,"computeBlocks"),n(Be,"popBlock"),n(Fe,"computeSubtreeCrossCounts"),n(Ee,"annotateMinimumLayers"),n($e,"compareByRankThenId"),n(Ye,"emitNodesInTreeOrder"),n(Xe,"deduplicateLayers"),n(ze,"createChildOrderer"),n(Pe,"buildMultitreeLayerOrder"),n(Ge,"countCrossingsBetweenAdjacent"),n(De,"totalCrossings"),n(Ae,"optimizeRanksByCrossings"),n(He,"adjustCrossLaneSources"),n(je,"assignLayers_LongestPath"),n(_e,"assignLayers_Gravity"),n(Ve,"topoSortByGenerationIfAcyclic"),n(We,"assignLayers_LaneAwareCompact"),n(Ke,"makeProperLayering"),n(qe,"median"),n(Ue,"barycenter"),n(Je,"neighborPositionsFor"),n(Ze,"currentOrderTieBreak"),n(Qe,"countCrossingsBetweenAdjacent"),n(tn,"sortByHeuristic"),n(en,"reorderLayer"),n(nn,"transposeImprove"),n(on,"orderLayers"),n(rn,"assignCoordinates");function sn(t){let e=2166136261;for(let n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return e>>>0}function an(t){let e=t>>>0;return()=>{e+=1831565813;let t=e;return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296}}function cn(t,e){const n=[...t],o=an(e);for(let t=n.length-1;t>0;t--){const e=Math.floor(o()*(t+1));[n[t],n[e]]=[n[e],n[t]]}return n}function fn(t,e){let n=0;for(const[o,r]of t.entries())n+=Math.abs(o-(e.get(r)??o));return n}function dn(t,e){const n=new Map;for(const[e,o]of t.entries())n.set(o,e);let o=0;for(const{a:t,b:r,weight:s}of e){const e=n.get(t),i=n.get(r);null!=e&&null!=i&&(o+=s*Math.abs(e-i))}return o}function ln(t){const e=Me(t);if(e.length<2)return[];const n=new Map(e.map((t,e)=>[t,e])),o=be(t),r=new Map;for(const e of t.layout.edges??[]){if(e.isLayoutOnly)continue;const s="string"==typeof e.start?e.start:void 0,i="string"==typeof e.end?e.end:void 0;if(!(s&&i&&t.nodeById.has(s)&&t.nodeById.has(i)))continue;const a=o(s),c=o(i);if(!a||!c||a===c)continue;const f=n.get(a),d=n.get(c);if(null==f||null==d)continue;const[l,u]=f<=d?[a,c]:[c,a],h=`${l}\0${u}`,g=r.get(h);g?g.weight++:r.set(h,{a:l,b:u,weight:1})}return[...r.values()]}function un(t,e,n){const o=[...t];let r=dn(o,e),s=!0,i=0;const a=Math.max(1,o.length);for(;s&&i<a;){s=!1,i++;for(let t=0;t+1<o.length;t++){[o[t],o[t+1]]=[o[t+1],o[t]];const n=dn(o,e);n<r?(r=n,s=!0):[o[t],o[t+1]]=[o[t+1],o[t]]}}return{order:o,cost:r,sourceDistance:fn(o,n)}}function hn(t,e){return t.cost!==e.cost?t.cost<e.cost:t.sourceDistance<e.sourceDistance}function gn(t,e,n){const o=[...e].sort((t,e)=>t.a===e.a?t.b.localeCompare(e.b):t.a.localeCompare(e.a)).map(({a:t,b:e,weight:n})=>`${t}:${e}:${n}`).join("|");return sn(`${t.join("|")}#${o}#${n}`)}function pn(t,e={}){const n=Me(t);if(n.length<2)return n;const o=ln(t);if(0===o.length)return n;const r=new Map(n.map((t,e)=>[t,e]));let s=un(n,o,r);const i=Math.max(0,e.restarts??8);for(let t=0;t<i;t++){const e=un(cn(n,gn(n,o,t)),o,r);hn(e,s)&&(s=e)}return s.order}function mn(t,e){const n=e?.ignoreCrossLaneEdges??!0,o=e?.optimizeRanksByCrossings??!0,r=ie(t),s=e?.automaticLaneOrdering?pn(r,{restarts:8}):void 0,i=xe(r),a=i.acyclic,c=n?We(a,{compactSingleInput:e?.compactSingleInput??ve,ignoreCrossLaneEdges:!0,direction:e?.direction}):_e(a,{compactSingleInput:e?.compactSingleInput??ve,ignoreCrossLaneEdges:!1,optimizeRanksByCrossings:o}),{layering:f,graphWithDummies:d}=Ke(c,a),l=on(f,d,{laneOrder:s}),u=rn(l,d,{layerGap:e?.layerGap,nodeGap:e?.nodeGap,direction:e?.direction,laneOrder:s});return{acyclic:a,reversed:i.reversed,layering:f,ordered:l,coordinates:u}}n(sn,"hashString"),n(an,"mulberry32"),n(cn,"deterministicShuffle"),n(fn,"sourceDistance"),n(dn,"laneArrangementCost"),n(ln,"buildWeightedLaneEdges"),n(un,"greedySwitch"),n(hn,"isBetterCandidate"),n(gn,"seedForRestart"),n(pn,"optimizeTopLaneOrder"),n(mn,"sugiyamaLayout");var xn=1e-6,yn=15,bn=15,Mn=20;function In(t,e,n){const o=t.x??0,r=t.y??0,s=e.x-o,i=e.y-r,a=Math.abs(s),c=Math.abs(i);if(a<xn&&c<xn)return n;return c>xn&&3*c>=a?i>0?"bottom":"top":a>xn?s>0?"right":"left":n}function Sn(t,e){return Math.abs(t.to-e.from)<xn||Math.abs(t.to-e.to)<xn?t.to:t.from}function wn(t,e){return"vertical"===t.orient?{x:t.coord,y:e}:{x:e,y:t.coord}}function vn(t,e){const o=t.nodes??[],r=t.edges??[],s=[];for(const t of r)t.isLayoutOnly||s.push({...t,__originalEdge:t});const i=new Map,a=new Map,c=[],f="LR"===e;for(const t of o)i.set(t.id,t);const d=o.filter(t=>t.isGroup&&!t.parentId);for(const t of d){const e={id:t.id},r=n(t=>{a.set(t.id,e),o.filter(e=>e.parentId===t.id).forEach(r)},"assignLane");r(t)}const l=o.filter(t=>!t.isGroup&&!t.isEdgeLabel).map(t=>{const e=t.width??10,n=t.height??10,o=t.x??0,r=t.y??0;return{nodeId:t.id,minX:o-e/2-8,maxX:o+e/2+8,minY:r-n/2-8,maxY:r+n/2+8,visualXHalfExtent:f?n/2+8:e/2+8}}),u=n((t,e,n,o)=>{let r=c.find(n=>n.orientation===t&&Math.abs(n.coord-e)<1);return r||(r={id:`pipe-${t}-${e.toFixed(0)}`,orientation:t,coord:e,spanMin:n,spanMax:o,tracks:[]},c.push(r)),r.spanMin=Math.min(r.spanMin,n),r.spanMax=Math.max(r.spanMax,o),r},"getOrAddPipe"),h=n((t,e)=>{const n=t.width??10,o=t.height??10,r=t.x??0,s=t.y??0;switch(e){case"top":return{x:r,y:s-o/2};case"bottom":return{x:r,y:s+o/2};case"left":return{x:r-n/2,y:s};case"right":return{x:r+n/2,y:s}}},"portForSide"),g=n((t,e,n)=>h(t,In(t,e,n?"bottom":"top")),"getOrthogonalPort"),p=[],m=[],x=new Set,y=n((t,e,n)=>{if(0===p.length)return 0;const o=Math.abs(e.y-n.y)<xn,r=Math.abs(e.x-n.x)<xn;if(!o&&!r)return 0;let s=0;if(o){const o=e.y,r=Math.min(e.x,n.x)-xn,i=Math.max(e.x,n.x)+xn;if(i<=r)return 0;for(const e of p)e.edgeIndex!==t&&"vertical"===e.orientation&&(e.pipe.coord<r||e.pipe.coord>i||e.from-xn<=o&&e.to+xn>=o&&(s+=1e3))}else if(r){const o=e.x,r=Math.min(e.y,n.y)-xn,i=Math.max(e.y,n.y)+xn;if(i<=r)return 0;for(const e of p)e.edgeIndex!==t&&"horizontal"===e.orientation&&(e.pipe.coord<r||e.pipe.coord>i||e.from-xn<=o&&e.to+xn>=o&&(s+=1e3))}return s},"crossingPenalty"),b=s.map((t,e)=>{if(!t.start||!t.end)return{idx:e,crossLane:0,dx:0,dy:0};const n=i.get(t.start),o=i.get(t.end),r=a.get(t.start),s=a.get(t.end);return{idx:e,crossLane:r&&s&&r.id!==s.id?1:0,dx:n&&o?Math.abs((o.x??0)-(n.x??0)):0,dy:n&&o?Math.abs((o.y??0)-(n.y??0)):0}}).sort((t,e)=>{if(t.crossLane!==e.crossLane)return e.crossLane-t.crossLane;const n=t.dx+t.dy,o=e.dx+e.dy;return Math.abs(n-o)>1?n-o:t.idx-e.idx}).map(t=>t.idx),M=n((t,e,n,o)=>{const r=Math.min(t.x,e.x),s=Math.max(t.x,e.x),i=Math.min(t.y,e.y),a=Math.max(t.y,e.y);return!!l.find(c=>(!n||c.nodeId!==n)&&((!o||c.nodeId!==o)&&(Math.abs(t.x-e.x)>xn?c.minY<t.y&&c.maxY>t.y&&c.maxX>r&&c.minX<s:c.minX<t.x&&c.maxX>t.x&&c.maxY>i&&c.minY<a)))},"isSegmentBlocked"),I=new Map,S=new Map;for(const t of s)t.start&&t.end&&t.start!==t.end&&(S.set(t.start,(S.get(t.start)??0)+1),S.set(t.end,(S.get(t.end)??0)+1));const w=n((t,e)=>In(t,e,"bottom"),"determineSide"),v=new Map;for(const[t,e]of s.entries()){if(!e.start||!e.end||e.start===e.end)continue;if(e.points&&e.points.length>0)continue;const n=i.get(e.start),o=i.get(e.end);if(!n||!o)continue;const r=(o.x??0)-(n.x??0),s=(o.y??0)-(n.y??0);v.set(t,{edgeIdx:t,srcId:e.start,dstId:e.end,srcSide:w(n,{x:o.x??0,y:o.y??0}),dstSide:w(o,{x:n.x??0,y:n.y??0}),absDx:Math.abs(r),absDy:Math.abs(s),dxSign:Math.sign(r),dySign:Math.sign(s)})}const C=n(t=>"top"===t.srcSide||"bottom"===t.srcSide?0===t.absDx?1/0:t.absDy/t.absDx:0===t.absDy?1/0:t.absDx/t.absDy,"preferenceStrength"),L=n(t=>"top"===t.srcSide||"bottom"===t.srcSide?t.dxSign>=0?"right":"left":t.dySign>=0?"bottom":"top","secondarySide"),k=new Map;for(const t of v.values()){const e=`${t.srcId}:${t.srcSide}`;k.has(e)||k.set(e,[]),k.get(e).push(t)}const O=new Map,R=n((t,e)=>`${t}:${e}`,"loadKey");for(const t of v.values())O.set(R(t.srcId,t.srcSide),(O.get(R(t.srcId,t.srcSide))??0)+1),O.set(R(t.dstId,t.dstSide),(O.get(R(t.dstId,t.dstSide))??0)+1);for(const t of k.values())if(!(t.length<2)){t.sort((t,e)=>{const n=C(t),o=C(e);return Math.abs(n-o)>1e-9?o-n:t.edgeIdx-e.edgeIdx});for(let e=1;e<t.length;e++){const n=t[e],o=L(n),r=O.get(R(n.srcId,n.srcSide))??0,s=O.get(R(n.srcId,o))??0;s>=r||(O.set(R(n.srcId,n.srcSide),r-1),O.set(R(n.srcId,o),s+1),n.srcSide=o)}}const N=n(t=>{const e=t?.shape;return"question"===e||"diamond"===e},"isDiamondNode"),T=new Map;for(const t of v.values())T.has(t.dstId)||T.set(t.dstId,new Set),T.get(t.dstId).add(t.dstSide);for(const t of v.values()){if(!N(i.get(t.srcId)))continue;const e=T.get(t.srcId);if(!e?.has(t.srcSide))continue;const n=L(t);if(e.has(n)||(O.get(R(t.srcId,n))??0)>0)continue;const o=O.get(R(t.srcId,t.srcSide))??0;O.set(R(t.srcId,t.srcSide),Math.max(0,o-1)),O.set(R(t.srcId,n),1),t.srcSide=n}for(const t of v.values()){const{edgeIdx:e,srcId:n,dstId:o,srcSide:r,dstSide:s}=t,a=i.get(n),c=i.get(o),f=`${n}:${r}:src`,d="top"===r||"bottom"===r?c.x??0:c.y??0;I.has(f)||I.set(f,[]),I.get(f).push({edgeIdx:e,oppositeCoord:d});const l=`${o}:${s}:dst`,u="top"===s||"bottom"===s?a.x??0:a.y??0;I.has(l)||I.set(l,[]),I.get(l).push({edgeIdx:e,oppositeCoord:u})}const B=new Map;for(const[t,e]of I){if(e.length<2)continue;e.sort((t,e)=>t.oppositeCoord-e.oppositeCoord);const n=t.split(":"),o=n.slice(0,-2).join(":"),r=n[n.length-2],s=n[n.length-1],a=i.get(o);if(!a)continue;const c="left"===r||"right"===r?a.height??10:a.width??10,f=a.shape,d="question"===f||"diamond"===f?.3*c:c,l=20,u=Math.min(l,Math.max(8,d/(e.length+1))),h=-(u*(e.length-1))/2;for(const[t,n]of e.entries()){const e=h+t*u,o=`${n.edgeIdx}:${s}`;B.set(o,e)}}const F=n(t=>Boolean(s[t]?.labelNodeId),"edgeHasLabelNode"),E=n((t,e)=>!!t&&((I.get(`${t}:${e}:src`)??[]).some(({edgeIdx:t})=>F(t))||(I.get(`${t}:${e}:dst`)??[]).some(({edgeIdx:t})=>F(t))),"faceHasLabelNode"),$=n((t,e,n)=>"top"===e||"bottom"===e?{x:t.x+n,y:t.y}:{x:t.x,y:t.y+n},"applyPortOffset"),Y=n((t,e,n)=>{const o=v.get(t),r={x:n.x??0,y:n.y??0},s={x:e.x??0,y:e.y??0},i=o?.srcSide??w(e,r),a=o?.dstSide??w(n,s);let c=o?h(e,o.srcSide):g(e,r,!0),f=o?h(n,o.dstSide):g(n,s,!1);const d=B.get(`${t}:src`),l=B.get(`${t}:dst`);return void 0!==d&&(c=$(c,i,d)),void 0!==l&&(f=$(f,a,l)),{pSrcPort:c,pDstPort:f,srcSide:i,dstSide:a}},"portsForEdge");for(const t of b){const e=s[t];if(m[t]=[],!e.start||!e.end)continue;if(e.points&&e.points.length>0)continue;if(e.start===e.end)continue;const o=i.get(e.start),r=i.get(e.end);if(!o||!r)continue;const{pSrcPort:a,pDstPort:d,srcSide:h,dstSide:g}=Y(t,o,r),b={...a},w={...d},v="top"===h||"bottom"===h,C="top"===g||"bottom"===g;if(v){const t=a.y>(o.y??0);b.y=t?a.y+Mn:a.y-Mn}else{const t=a.x>(o.x??0);b.x=t?a.x+Mn:a.x-Mn}if(C){const t=d.y>(r.y??0);w.y=t?d.y+Mn:d.y-Mn}else{const t=d.x>(r.x??0);w.x=t?d.x+Mn:d.x-Mn}const L=n((t,e)=>{for(const n of l)if(!e.includes(n.nodeId)&&t.x>n.minX&&t.x<n.maxX&&t.y>n.minY&&t.y<n.maxY)return{inside:!0,obstacle:n};return{inside:!1}},"isPointInObstacle"),k=n((t,e,n,o,r)=>{if(r){const r=t.y>(e.y??0);return{x:(n.x??0)>=t.x?o.maxX+yn:o.minX-yn,y:r?o.maxY+bn:o.minY-bn,leavesPositiveSide:r}}const s=t.x>(e.x??0),i=(n.y??0)>=t.y;return{x:s?o.maxX+yn:o.minX-yn,y:i?o.maxY+bn:o.minY-bn,leavesPositiveSide:s}},"obstacleDetour");let O=[];const R=[e.start,e.end],N=L(b,R);if(N.inside&&N.obstacle){const t=N.obstacle;if(v){const e=k(a,o,r,t,!0);b.x=e.x,b.y=e.y;const n=e.leavesPositiveSide?Math.min(t.minY-2,a.y+Mn):Math.max(t.maxY+2,a.y-Mn);O=[{x:a.x,y:n},{x:e.x,y:n},{x:e.x,y:e.y}]}else{const e=k(a,o,r,t,!1),n=e.leavesPositiveSide?Math.min(t.minX-2,a.x+Mn):Math.max(t.maxX+2,a.x-Mn);b.x=e.x,b.y=e.y,O=[{x:n,y:a.y},{x:n,y:e.y},{x:e.x,y:e.y}]}}let T=[];const F=L(w,R);if(F.inside&&F.obstacle){const t=F.obstacle;if(C){const e=k(d,r,o,t,!0);w.x=e.x,w.y=e.y,T=[{x:e.x,y:e.y},{x:d.x,y:e.y}]}else{const e=k(d,r,o,t,!1);w.x=e.x,w.y=e.y,T=[{x:e.x,y:e.y},{x:e.x,y:d.y}]}}if(0===O.length&&0===T.length){const n=yn,o=Math.abs(b.x-w.x)<n,r=Math.abs(b.y-w.y)<n,s=void 0!==B.get(`${t}:src`)||void 0!==B.get(`${t}:dst`),i=(I.get(`${e.start??""}:${h}:src`)?.length??0)+(I.get(`${e.start??""}:${h}:dst`)?.length??0),c=(I.get(`${e.end??""}:${g}:src`)?.length??0)+(I.get(`${e.end??""}:${g}:dst`)?.length??0),f=i>1||c>1,l=S.get(e.start??"")??0,u=S.get(e.end??"")??0,m=i>1&&E(e.start,h)||c>1&&E(e.end,g);if((o||r)&&!s&&(!f||f&&!m&&(i<=1||l<=2)&&(c<=1||u<=2))){if(!M(a,d,e.start,e.end)){e.points=[{...a},{...b},{...w},{...d}],x.add(t);const n=r?"horizontal":"vertical",o=r?a.y:a.x,s=r?Math.min(a.x,d.x):Math.min(a.y,d.y),i=r?Math.max(a.x,d.x):Math.max(a.y,d.y),c={id:`fast-path-${n}-${o.toFixed(0)}-${t}`,orientation:n,coord:o,spanMin:s,spanMax:i,tracks:[]};p.push({edgeIndex:t,segmentIndex:0,orientation:n,pipe:c,trackIndex:0,from:s,to:i});continue}}}const $=u("vertical",b.x,b.y,b.y);b.x=$.coord;const X=u("vertical",w.x,w.y,w.y);w.x=X.coord;let z=Math.min(b.x,w.x)-50,P=Math.max(b.x,w.x)+50,G=Math.min(b.y,w.y)-50,D=Math.max(b.y,w.y)+50;for(const t of l){const e=Math.min(b.x,w.x),n=Math.max(b.x,w.x),o=Math.min(b.y,w.y),r=Math.max(b.y,w.y);t.minX<n&&t.maxX>e&&t.minY<r&&t.maxY>o&&(z=Math.min(z,t.minX-25),P=Math.max(P,t.maxX+25),G=Math.min(G,t.minY-25),D=Math.max(D,t.maxY+25))}for(const t of l){if(t.maxX<z||t.minX>P||t.maxY<G||t.minY>D)continue;const e=yn;u("horizontal",t.minY-e,z,P),u("horizontal",t.maxY+e,z,P);const n=bn;u("vertical",t.minX-n,G,D),u("vertical",t.maxX+n,G,D)}u("horizontal",b.y,z,P),u("horizontal",w.y,z,P);const A=c.filter(t=>"horizontal"===t.orientation&&t.coord>=G&&t.coord<=D),H=c.filter(t=>"vertical"===t.orientation&&t.coord>=z&&t.coord<=P),j=n((t,e)=>`${t.toFixed(1)},${e.toFixed(1)}`,"getKey"),_=j(b.x,b.y),V=j(w.x,w.y),W=new Map,K=new Map,q=new Map,U=new Set,J=[];W.set(_,0),q.set(_,"n"),J.push({key:_,f:Math.hypot(w.x-b.x,w.y-b.y),pt:b}),U.add(_);let Z=[];const Q=n((t,n)=>M(t,n,e.start,e.end),"checkSegmentBlocked"),tt={x:w.x,y:b.y},et=Q(b,tt),nt=Q(tt,w),ot=et||nt,rt={x:b.x,y:w.y},st=Q(b,rt),it=Q(rt,w);if(ot?st||it||(Z=Math.abs(b.x-w.x)<xn?[b,w]:[b,rt,w]):Z=Math.abs(b.y-w.y)<xn||Math.abs(b.x-w.x)<xn?[b,w]:[b,tt,w],0===Z.length)for(;J.length>0;){J.sort((t,e)=>t.f-e.f);const n=J.shift();if(U.delete(n.key),n.key===V){let t=V,e=w;for(Z=[e];K.has(t);){const n=K.get(t);Z.unshift(n),e=n,t=j(n.x,n.y)}break}const o=n.pt.x,r=n.pt.y,s=H.sort((t,e)=>t.coord-e.coord),i=s.findIndex(t=>Math.abs(t.coord-o)<1),a=A.sort((t,e)=>t.coord-e.coord),c=a.findIndex(t=>Math.abs(t.coord-r)<1),f=[];i>0&&f.push({x:s[i-1].coord,y:r}),i>=0&&i<s.length-1&&f.push({x:s[i+1].coord,y:r}),c>0&&f.push({x:o,y:a[c-1].coord}),c>=0&&c<a.length-1&&f.push({x:o,y:a[c+1].coord});for(const s of f){const i=Math.min(o,s.x),a=Math.max(o,s.x),c=Math.min(r,s.y),f=Math.max(r,s.y);if(l.some(t=>t.nodeId!==e.start&&t.nodeId!==e.end&&(i!==a?t.minY<r&&t.maxY>r&&t.maxX>i&&t.minX<a:t.minX<o&&t.maxX>o&&t.maxY>c&&t.minY<f)))continue;const d=j(s.x,s.y),u=Math.abs(s.x-o)+Math.abs(s.y-r),h=y(t,n.pt,s);let g=0;const p=w.x-b.x,m=w.y-b.y,x=s.x-o,M=s.y-r;(m>10&&M<-5||m<-10&&M>5)&&(g=100*Math.abs(M)),(p>10&&x<-5||p<-10&&x>5)&&(g+=50*Math.abs(x));let I=0;const S=q.get(n.key)??"n",v=Math.abs(x)>xn?"h":"v";"n"!==S&&S!==v&&(I=50);const C=u+h+g+I,L=(W.get(n.key)??1/0)+C,k=Math.abs(w.x-s.x)+Math.abs(w.y-s.y);if(L<(W.get(d)??1/0))if(K.set(d,n.pt),W.set(d,L),q.set(d,v),U.has(d)){const t=J.findIndex(t=>t.key===d);-1!==t&&(J[t].f=L+k)}else J.push({key:d,f:L+k,pt:s}),U.add(d)}}if(0===Z.length&&(Z=[b,{x:b.x,y:w.y},w]),Z.length>4){const t=Z[0],e=Z[Z.length-1];let o=Math.min(t.x,e.x),r=Math.max(t.x,e.x),s=Math.min(t.y,e.y),i=Math.max(t.y,e.y);for(const t of Z)o=Math.min(o,t.x),r=Math.max(r,t.x),s=Math.min(s,t.y),i=Math.max(i,t.y);const a=r>Math.max(t.x,e.x),c=o<Math.min(t.x,e.x);if(f){const n=bn;if(a){const o=Math.max(t.x,e.x),s=Math.min(t.y,e.y),i=Math.max(t.y,e.y),a=l.filter(t=>t.minX<o&&t.maxX>o&&t.minY<i&&t.maxY>s);if(a.length>0){let o=Math.max(t.x,e.x);for(const t of a){const e=(t.minX+t.maxX)/2;if(void 0===t.visualXHalfExtent||isNaN(t.visualXHalfExtent))continue;const r=e+t.visualXHalfExtent+n;o=Math.max(o,r)}isNaN(o)||(r=o)}}if(c){const r=l.filter(o=>o.minX<Math.min(t.x,e.x)+n&&o.minY<Math.max(t.y,e.y)&&o.maxY>Math.min(t.y,e.y));if(r.length>0){let s=Math.min(t.x,e.x);for(const t of r){const e=(t.minX+t.maxX)/2-t.visualXHalfExtent-n;s=Math.min(s,e)}o=s}}}const d=n(n=>{const o=e.y>t.y,r=l.filter(n=>{const o=Math.min(t.x,e.x)<n.maxX&&Math.max(t.x,e.x)>n.minX,r=Math.min(t.y,e.y)<n.maxY&&Math.max(t.y,e.y)>n.minY;return o&&r});let s=r;if(f&&r.length>0){const t=r.filter(t=>t.minX<n&&t.maxX>n);t.length>0&&(s=t)}if(0===s.length)return e.y;if(o){const t=Math.max(...s.map(t=>t.maxY))+15;if(t<e.y-xn)return t}else{const t=Math.min(...s.map(t=>t.minY))-15;if(t>e.y+xn)return t}return e.y},"findBestReturnY"),u=n(n=>{const o=d(n),r={x:n,y:t.y},s={x:n,y:o},i={x:e.x,y:o},a=Q(t,r),c=Q(r,s),f=Q(s,i),l=o!==e.y&&Q(i,e);return a||c||f||l?null:Math.abs(o-e.y)<xn?[t,r,s,e]:[t,r,s,i,e]},"trySimplifyWithDetourX"),h=a&&!c?u(r):c&&!a?u(o):null;h&&(Z=h)}const at=[a,...O,...Z,...T.reverse(),d];if(at.length>=3){const t=at[at.length-1],e=at[at.length-2],n=at[at.length-3],o=Math.abs(n.y-e.y)<xn&&Math.abs(e.y-t.y)<xn,r=Math.abs(n.x-e.x)<xn&&Math.abs(e.x-t.x)<xn;if(o){const o=Math.sign(e.x-n.x),r=Math.sign(t.x-n.x);0!==o&&o===r&&Math.abs(e.x-n.x)>Math.abs(t.x-n.x)&&at.splice(-2,1)}else if(r){const o=Math.sign(e.y-n.y),r=Math.sign(t.y-n.y);0!==o&&o===r&&Math.abs(e.y-n.y)>Math.abs(t.y-n.y)&&at.splice(-2,1)}}const ct=[at[0]];for(let t=1;t<at.length-1;t++){if(1===t){ct.push(at[t]);continue}const e=ct[ct.length-1],n=at[t],o=at[t+1];if(Math.abs(e.y-n.y)<xn&&Math.abs(n.y-o.y)<xn){if(n.x>e.x!==o.x>n.x){ct.push(n);continue}continue}if(Math.abs(e.x-n.x)<xn&&Math.abs(n.x-o.x)<xn){if(n.y>e.y!==o.y>n.y){ct.push(n);continue}continue}ct.push(n)}ct.push(at[at.length-1]);for(let e=0;e<ct.length-1;e++){const n=ct[e],o=ct[e+1],r=Math.abs(n.x-o.x)<xn?"vertical":"horizontal",s="vertical"===r?n.x:n.y,i="vertical"===r?Math.min(n.y,o.y):Math.min(n.x,o.x),a="vertical"===r?Math.max(n.y,o.y):Math.max(n.x,o.x),c=u(r,s,i,a),f={edgeIndex:t,segmentIndex:e,orientation:r,pipe:c,trackIndex:0,from:i,to:a};p.push(f),m[t].push(p.length-1),c.tracks[0]||(c.tracks[0]={index:0,coord:c.coord,segments:[]}),c.tracks[0].segments.push({edgeIndex:t,segmentIndex:e,from:i,to:a})}}const X=n((t,e)=>t.from<e.to&&e.from<t.to,"segmentsOverlap"),z=n((t,e,n,o)=>{const r=!o.segments.some(n=>(n.edgeIndex!==e.edgeIndex||n.segmentIndex!==e.segmentIndex)&&X(n,t)),s=!n.segments.some(n=>(n.edgeIndex!==t.edgeIndex||n.segmentIndex!==t.segmentIndex)&&X(n,e));return!(!r||!s)&&(t.trackIndex=o.index,e.trackIndex=n.index,n.segments=[...n.segments.filter(e=>e.edgeIndex!==t.edgeIndex||e.segmentIndex!==t.segmentIndex),{edgeIndex:e.edgeIndex,segmentIndex:e.segmentIndex,from:e.from,to:e.to}],o.segments=[...o.segments.filter(t=>t.edgeIndex!==e.edgeIndex||t.segmentIndex!==e.segmentIndex),{edgeIndex:t.edgeIndex,segmentIndex:t.segmentIndex,from:t.from,to:t.to}],!0)},"trySwapSegmentsAcrossTracks"),P=n(t=>{const e=t.tracks.length;return t.tracks[e]={index:e,coord:t.coord,segments:[]},e},"createNewTrack"),G=n((t,e)=>{const n=t.pipe.tracks[t.trackIndex];n.segments=n.segments.filter(e=>e.edgeIndex!==t.edgeIndex||e.segmentIndex!==t.segmentIndex),t.trackIndex=e;t.pipe.tracks[e].segments.push({edgeIndex:t.edgeIndex,segmentIndex:t.segmentIndex,from:t.from,to:t.to})},"moveSegmentToTrack"),D=n((t,e)=>{const n=m[t.edgeIndex];for(const o of n){const n=p[o];n.pipe===t.pipe&&G(n,e)}},"moveSegmentChainToTrack"),A=n(t=>{const e=m[t.edgeIndex],n=e.indexOf(p.indexOf(t)),o=[];return n>0&&o.push(p[e[n-1]]),n<e.length-1&&o.push(p[e[n+1]]),o},"getAdjacentSegmentsAlongEdge"),H=n((t,e)=>{if(t.orientation===e.orientation)return!1;const n="horizontal"===t.orientation?t:e,o="horizontal"===t.orientation?e:t;return o.pipe.coord>n.from&&o.pipe.coord<n.to&&n.pipe.coord>o.from&&n.pipe.coord<o.to},"haveAnyCrossing"),j=n((t,e)=>{for(const n of t.tracks){if(!n.segments.some(t=>(t.edgeIndex!==e.edgeIndex||t.segmentIndex!==e.segmentIndex)&&X(t,e)))return n.index}return-1},"findAvailableTrack"),_=n((t,e)=>{if(t.trackIndex===e.trackIndex)return X(t,e);const n=A(t),o=A(e);return n.some(t=>o.some(e=>H(t,e)))},"segmentsConflict"),V=n((t,e,n)=>{if(z(t,e,t.pipe.tracks[t.trackIndex],e.pipe.tracks[e.trackIndex]))return;const o=j(t.pipe,e);n(e,-1!==o?o:P(t.pipe))},"resolveTrackConflict"),W=n(t=>{let e=0;for(let n=0;n<t.length;n++)for(let o=n+1;o<t.length;o++){const r=t[n],s=t[o];r.pipe===s.pipe&&(_(r,s)&&(e++,V(r,s,D)))}return e},"resolveHandleConflicts"),K=new Map,q=n(t=>{if(K.has(t))return K.get(t);const e=m[t];if(0===e.length){const e={dest:0,deviation:0,base:0,delta:0};return K.set(t,e),e}const n=p[e[0]].pipe.coord;let o=n;for(let t=1;t<e.length;t++){const r=p[e[t]];if("horizontal"===r.orientation){const t=r.from,e=r.to;o=Math.abs(t-n)>Math.abs(e-n)?t:e;break}}const r={dest:o,deviation:Math.abs(o-n),base:n,delta:o-n};return K.set(t,r),r},"getDestInfo"),U=n(()=>{let t=0;const e=new Map;for(const[t,n]of s.entries())0!==m[t].length&&n.start&&(e.has(n.start)||e.set(n.start,[]),e.get(n.start).push(t));const o=n(t=>{const e=s[t];if(!e.start||!e.end)return 0;const n=i.get(e.start),o=i.get(e.end);if(!n||!o)return 0;const r=(o.x??0)-(n.x??0),a=(o.y??0)-(n.y??0);return Math.abs(r)+Math.abs(a)},"getEdgeDistance");for(const n of e.values()){n.sort((t,e)=>{const n=q(t),r=q(e);if(Math.abs(n.deviation-r.deviation)>1)return n.deviation-r.deviation;if(Math.abs(n.dest-r.dest)>1)return n.dest-r.dest;const s=o(t),i=o(e);if(Math.abs(s-i)>1)return i-s;const a=m[t].length,c=m[e].length;if(a!==c)return a-c;if(1===a){const n=m[t][0],o=m[e][0];if(p[n]&&p[o]){const t=p[n],e=p[o],r=Math.abs(t.to-t.from),s=Math.abs(e.to-e.from);if(Math.abs(r-s)>1)return r-s}}return 0});const e=n.map(t=>p[m[t][0]]);t+=W(e)}return t},"fixSourceHandleCrossings"),J=n(()=>{let t=0;const e=new Map;for(const[t,n]of s.entries()){0!==m[t].length&&(n.end&&(e.has(n.end)||e.set(n.end,[]),e.get(n.end).push(t)))}for(const o of e.values()){o.sort((t,e)=>{const o=n(t=>{const e=m[t];if(e.length<2)return 0;const n=p[e[e.length-2]];return Math.abs(n.to-n.from)},"getDist"),r=o(t),s=o(e);return Math.abs(r-s)>.1?r-s:t-e});const e=o.map(t=>p[m[t][m[t].length-1]]);t+=W(e)}return t},"fixTargetHandleCrossings"),Z=n(()=>{let t=0;for(const e of c){const n=[];for(const t of e.tracks)for(const e of t.segments){const t=m[e.edgeIndex].find(t=>p[t].segmentIndex===e.segmentIndex);void 0!==t&&n.push(p[t])}n.sort((t,e)=>t.edgeIndex-e.edgeIndex||t.segmentIndex-e.segmentIndex);for(let e=0;e<n.length;e++)for(let o=e+1;o<n.length;o++){const r=n[e],s=n[o];_(r,s)&&(t++,V(r,s,G))}}return t},"fixPipeCrossings");let Q=0;for(;Q<10;){let t=0;if(t+=U(),t+=J(),t+=Z(),0===t)break;Q++}const tt=new Map;for(const t of c){const e=[];t.tracks.forEach(t=>{t.segments.forEach(n=>{e.push({edgeIndex:n.edgeIndex,segmentIndex:n.segmentIndex,trackIndex:t.index,from:n.from,to:n.to})})}),e.sort((t,e)=>t.from-e.from);const o=[];if(e.length>0){let t=[e[0]],n=e[0].to;for(let r=1;r<e.length;r++){const s=e[r];s.from<n?(t.push(s),n=Math.max(n,s.to)):(o.push(t),t=[s],n=s.to)}o.push(t)}for(const e of o){const o=new Set;e.forEach(t=>o.add(t.trackIndex));const r=new Map;e.forEach(t=>{const e=q(t.edgeIndex);r.set(t.trackIndex,(r.get(t.trackIndex)??0)+e.delta)});const s=[...o].filter(t=>(r.get(t)??0)<-1),i=[...o].filter(t=>(r.get(t)??0)>1),a=[...o].filter(t=>Math.abs(r.get(t)??0)<=1);s.sort((t,e)=>(r.get(e)??0)-(r.get(t)??0)),i.sort((t,e)=>(r.get(t)??0)-(r.get(e)??0));const c=n((n,o)=>{e.filter(t=>t.trackIndex===n).forEach(e=>{const n=x.has(e.edgeIndex)?t.coord:o;tt.set(`${e.edgeIndex}-${e.segmentIndex}`,n)})},"assignCoord");let f=0;for(const e of s)f++,c(e,t.coord-10*f);if(0===a.length&&o.size>0){const t=[...o].sort((t,e)=>Math.abs(r.get(t)??0)-Math.abs(r.get(e)??0))[0],e=s.indexOf(t);-1!==e&&s.splice(e,1);const n=i.indexOf(t);-1!==n&&i.splice(n,1),a.push(t)}let d=0;for(const e of a){if(0===d)c(e,t.coord);else{const n=d%2==1?1:-1,o=Math.ceil(d/2);c(e,t.coord+n*o*10*.5)}d++}let l=0;for(const e of i)l++,c(e,t.coord+10*l)}}for(const[t,e]of s.entries()){const n=m[t]??[];if(0===n.length)continue;const o=[],r=i.get(e.start),s=i.get(e.end),{pSrcPort:a,pDstPort:c}=Y(t,r,s),f=n.map(t=>{const e=p[t],n=tt.get(`${e.edgeIndex}-${e.segmentIndex}`)??e.pipe.coord;return{orient:e.orientation,coord:n,from:e.from,to:e.to}});o.push(a);for(let t=0;t<f.length;t++){const e=f[t],n=o[o.length-1],r="vertical"===e.orient?n.y:n.x,s="vertical"===e.orient?n.x:n.y,i=f[t+1],a=t<f.length-1;if(Math.abs(s-e.coord)>xn&&o.push(wn(e,r)),a&&i.orient===e.orient)if(Math.abs(e.coord-i.coord)>xn){const t="vertical"===e.orient?(r+i.from)/2:Sn(e,i);o.push(wn(e,t),wn(i,t))}else 0!==t&&t!==f.length-2||o.push(wn(e,Sn(e,i)));else if(a)o.push(wn(e,i.coord));else{const t=Math.abs(e.from-r)<Math.abs(e.to-r)?e.to:e.from;o.push(wn(e,t))}}const d=o[o.length-1];(Math.abs(d.x-c.x)>xn||Math.abs(d.y-c.y)>xn)&&o.push(c);const l=[];o.length>0&&l.push(o[0]);for(let t=1;t<o.length;t++){const e=o[t],n=l[l.length-1];(Math.abs(e.x-n.x)>xn||Math.abs(e.y-n.y)>xn)&&l.push(e)}e.points=l}for(const t of s){const e=t.__originalEdge;e&&t.points&&(e.points=t.points)}t.edges=(t.edges??[]).filter(t=>!t.isLayoutOnly);const et=n((t,e)=>{const n=e.x??0,o=e.y??0,r=e.width??0,s=e.height??0;if(r<=0||s<=0)return t;const i=n-r/2,a=n+r/2,c=o-s/2,f=o+s/2;if(t.x<i||t.x>a||t.y<c||t.y>f)return t;const d=t.x-i,l=a-t.x,u=t.y-c,h=f-t.y,g=Math.min(d,l,u,h);return g===d?{x:i,y:t.y}:g===l?{x:a,y:t.y}:g===u?{x:t.x,y:c}:{x:t.x,y:f}},"nodeBoundaryClamp");for(const e of t.edges){const t=e.points;if(!t||t.length<2)continue;const n=e.start,o=e.end,r=n?i.get(n):void 0,s=o?i.get(o):void 0;r&&(t[0]=et(t[0],r)),s&&(t[t.length-1]=et(t[t.length-1],s))}return t}function Cn(t){return t.direction??"TB"}function Ln(t){const e=f(t),n=t.config.flowchart?.nodeSpacing??40,o=t.config.flowchart?.rankSpacing??100,r=t.config.swimlane?.ignoreCrossLaneEdges??!0,s=t.config.swimlane?.optimizeRanksByCrossings??!0,i=t.config.swimlane?.automaticLaneOrdering??!1,a=Cn(t),{ordered:c,coordinates:l}=mn(e,{nodeGap:n,layerGap:o,ignoreCrossLaneEdges:r,optimizeRanksByCrossings:s,automaticLaneOrdering:i,direction:a});d(e,c,l,{nodeGap:n,layerGap:o});for(const e of t.edges??[])delete e.points;vn(t,a);for(const e of t.edges??[])e.curve&&"basis"!==e.curve||(e.curve="rounded");return se(t,a),re(t),a}function kn(t){c(t);const e=l(t);t.nodes=e.nodes,t.edges=e.edges}n(In,"chooseOrthogonalSide"),n(Sn,"sharedLineEndpointCoord"),n(wn,"pointOnLine"),n(vn,"routeEdgesOrthogonal"),n(Cn,"getSwimlaneDirection"),n(Ln,"runSwimlaneLayoutCore"),n(kn,"prepareSwimlaneLayout");var On=e({prepareLayout:kn,runLayoutCore:Ln,afterPaint:r});export{On as render};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as t,s as r}from"./chunk-NQOKRVIF-D0-2mmH4.js";import{_ as o}from"./mermaid.core-DRk6tt5W.js";import"./chunk-5VM5RSS4-CS0kZLYA.js";import"./chunk-XXDRQBXY-DPPGTM3w.js";import"./chunk-VQ5W62QI-CsGo0PTx.js";import"./chunk-55XCU76K-CvYWAV_o.js";import"./channel-DWjyymG_.js";import"./index-BpcqEzEG.js";import"react/jsx-runtime";import"react";import"./enums.js";import"./commons-iref2pEJ.js";import"./settings-CBGV-lz3.js";import"./constants.js";import"./LoaderLayer-ECtsj85k.js";import"./websocket-CdeP8N_S.js";import"./index-2PTQqTnK.js";import"motion/react";import"react-dom";import"swr";import"@ably/spaces";import"@ably/spaces/react";import"ably";import"ably/liveobjects";import"ably/react";import"@ably/spaces/dist/mjs/react";import"./string-DPJhNSkw.js";var s=t({styles:o(t=>`${r(t)}\n .swimlane.cluster:not([data-color-id]) rect {\n stroke: ${t.clusterBorder} !important;\n }\n [data-look="neo"].cluster rect {\n filter: none;\n }\n`,"getStyles")});export{s as diagram};
|