vibelet 1.2.243 → 1.2.245
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/index.cjs +1 -1
- package/dist/inventory-scan-worker.cjs +1 -1
- package/dist/remoteDirect/manifest.json +12 -12
- package/dist/runtime-version.cjs +1 -1
- package/dist/web/assets/App-D4fBMWn7.js +2 -0
- package/dist/web/assets/{App-6Cciblyj.css → App-DHnygrdE.css} +1 -1
- package/dist/web/assets/BrowserControlPanel-CX9UdOEA.js +1 -0
- package/dist/web/assets/{ChatPane-Crhr0Lkx.js → ChatPane-wtVFANO0.js} +2 -2
- package/dist/web/assets/{ChipGroup-DAB6dZFc.js → ChipGroup-C16Et4Xc.js} +1 -1
- package/dist/web/assets/{ComposerMenus-D7iN4bup.js → ComposerMenus-B9EpF3L_.js} +1 -1
- package/dist/web/assets/{DiffDrawer-BR7NrEmt.js → DiffDrawer-DTg5YChv.js} +1 -1
- package/dist/web/assets/{FilesControlPanel-B8w2_BRT.js → FilesControlPanel-Bx9RohXk.js} +1 -1
- package/dist/web/assets/{GlobalPendingDialog-psYp4FyT.js → GlobalPendingDialog-p1vvgOHs.js} +1 -1
- package/dist/web/assets/{ImageViewer-CKqlB_9p.js → ImageViewer--pLWLE6p.js} +1 -1
- package/dist/web/assets/{LanguageSettingsPanel-eEfHrFPA.js → LanguageSettingsPanel-COinfVCx.js} +1 -1
- package/dist/web/assets/MarkdownModePanel-DGxuHxiO.js +1 -0
- package/dist/web/assets/{MessageImage-L_caj_Dp.js → MessageImage-DyqY_ZJd.js} +1 -1
- package/dist/web/assets/{NewSessionDialog-D6GYUsxw.js → NewSessionDialog-CGMida8H.js} +1 -1
- package/dist/web/assets/{NotificationSettingsPanel-8cC0qcjz.js → NotificationSettingsPanel-CrkHAKw9.js} +1 -1
- package/dist/web/assets/{PanelFind-CtB-fTaM.js → PanelFind-Cx5K--7K.js} +1 -1
- package/dist/web/assets/RemoteLifeOSBlock-CzC-ut2z.js +2 -0
- package/dist/web/assets/RemoteLifeOSBlock-D7P9Ftlh.css +1 -0
- package/dist/web/assets/{RemoteWorkspaceSettings-BLk7MUa8.js → RemoteWorkspaceSettings--n8qxL-O.js} +1 -1
- package/dist/web/assets/{SessionTerminalPanel-D_5c6lMk.js → SessionTerminalPanel-D59JkdsC.js} +2 -2
- package/dist/web/assets/{SpeechInputSettingsPanel-Bm1UPHiL.js → SpeechInputSettingsPanel-rrdMQRnO.js} +1 -1
- package/dist/web/assets/{ThemeSettingsPanel-Tym9Xy1v.js → ThemeSettingsPanel-JMc98Dpj.js} +1 -1
- package/dist/web/assets/{__vite-browser-external-2447137e-Ck9f6uYD.js → __vite-browser-external-2447137e-DYOQzEuf.js} +1 -1
- package/dist/web/assets/{abnfDiagram-VRR7QNED-BPSMtotk.js → abnfDiagram-VRR7QNED-CiGRuhk-.js} +1 -1
- package/dist/web/assets/{arc-CFHn4jAK.js → arc-Uf6y3fQG.js} +1 -1
- package/dist/web/assets/{architectureDiagram-ZJ3FMSHR-DoIyc6P-.js → architectureDiagram-ZJ3FMSHR-Cx57d0-g.js} +1 -1
- package/dist/web/assets/{arrow-left-B_J8dbJk.js → arrow-left-CTbegMaU.js} +1 -1
- package/dist/web/assets/{arrow-right-B0Zthy7B.js → arrow-right-BQXADod1.js} +1 -1
- package/dist/web/assets/{blockDiagram-677ZJIJ3-BOarVZs5.js → blockDiagram-677ZJIJ3-DfDpv9OM.js} +1 -1
- package/dist/web/assets/{c4Diagram-LMCZKHZV-CDoawQWV.js → c4Diagram-LMCZKHZV-_ILjwxFf.js} +1 -1
- package/dist/web/assets/channel-Dk15gdNy.js +1 -0
- package/dist/web/assets/chevron-up-GZB6oy0t.js +1 -0
- package/dist/web/assets/{chunk-2Q5K7J3B-CkVdI1_G.js → chunk-2Q5K7J3B-CY59UbU-.js} +1 -1
- package/dist/web/assets/{chunk-32BRIVSS-lfRflIJE.js → chunk-32BRIVSS-BSCYWxge.js} +1 -1
- package/dist/web/assets/{chunk-5VM5RSS4-ChvW640o.js → chunk-5VM5RSS4-DAMZXj9y.js} +1 -1
- package/dist/web/assets/{chunk-EX3LRPZG-LUlAwMu1.js → chunk-EX3LRPZG-D2G4irvr.js} +1 -1
- package/dist/web/assets/{chunk-JWPE2WC7-CZAbFhxm.js → chunk-JWPE2WC7-BcR5muoN.js} +1 -1
- package/dist/web/assets/{chunk-MOJQB5TN-zbABsF-T.js → chunk-MOJQB5TN-DBf8Vf6T.js} +1 -1
- package/dist/web/assets/{chunk-RYQCIY6F-DO7-HDJp.js → chunk-RYQCIY6F-C3X0k4Wk.js} +1 -1
- package/dist/web/assets/{chunk-V7JOEXUC-CZZpLt5o.js → chunk-V7JOEXUC-CPO1U4G8.js} +1 -1
- package/dist/web/assets/{chunk-VR4S4FIN-CPVLI9Cz.js → chunk-VR4S4FIN-D9BlrMdk.js} +1 -1
- package/dist/web/assets/{chunk-XXDRQBXY-dA96ajoY.js → chunk-XXDRQBXY-DUhbXvUs.js} +1 -1
- package/dist/web/assets/classDiagram-OUVF2IWQ-CN2WsgwT.js +1 -0
- package/dist/web/assets/classDiagram-v2-EOCWNBFH-CN2WsgwT.js +1 -0
- package/dist/web/assets/{collectMessageImages-BHZAEp7l.js → collectMessageImages-DdrSxaMf.js} +1 -1
- package/dist/web/assets/{cose-bilkent-JH36ORCC-DkTAw3T7.js → cose-bilkent-JH36ORCC-B3c5J7br.js} +1 -1
- package/dist/web/assets/{cynefin-VYW2F7L2-CPV5HP8b.js → cynefin-VYW2F7L2-DwrXi0XX.js} +1 -1
- package/dist/web/assets/{cynefinDiagram-TSTJHNR4-BjqGh-JY.js → cynefinDiagram-TSTJHNR4-5t6NkjVv.js} +1 -1
- package/dist/web/assets/{dagre-VKFMJZFB-CqPOtH9L.js → dagre-VKFMJZFB-CE6g1IOo.js} +1 -1
- package/dist/web/assets/{diagram-FQU43EPY-51RTvAnu.js → diagram-FQU43EPY-CN3Kybbf.js} +1 -1
- package/dist/web/assets/{diagram-G47NLZAW-B5GqRCH2.js → diagram-G47NLZAW-Djc-xY18.js} +1 -1
- package/dist/web/assets/{diagram-NH7WQ7WH-BYUwty2D.js → diagram-NH7WQ7WH-dgr5u2-y.js} +1 -1
- package/dist/web/assets/{diagram-OA4YK3LP-C6yJt9W8.js → diagram-OA4YK3LP-Bna9UWZO.js} +1 -1
- package/dist/web/assets/{diagram-WEI45ONY-Cc9-k4zE.js → diagram-WEI45ONY-MFmmaGwd.js} +1 -1
- package/dist/web/assets/{ebnfDiagram-CCIWWBDH-DCzmtavH.js → ebnfDiagram-CCIWWBDH-C4vnTICq.js} +1 -1
- package/dist/web/assets/{erDiagram-Q63AITRT-ZjDc6wjK.js → erDiagram-Q63AITRT-OHs8hKkP.js} +1 -1
- package/dist/web/assets/{file-editor-FileCodeEditor-ynS8wc-T.js → file-editor-FileCodeEditor-CjIOJIPi.js} +1 -1
- package/dist/web/assets/{file-editor-ObsidianCodeEditor-BGsVxYpf.js → file-editor-ObsidianCodeEditor-DqGk6x5n.js} +1 -1
- package/dist/web/assets/{file-editor-ObsidianFileEditor-DCya_kV_.js → file-editor-ObsidianFileEditor-Bw_Rpzie.js} +1 -1
- package/dist/web/assets/{flowDiagram-23GEKE2U-JOT3y9OZ.js → flowDiagram-23GEKE2U-CgkejrIU.js} +1 -1
- package/dist/web/assets/{folder-plus-Dv3mIoot.js → folder-plus-BBvp5bBk.js} +1 -1
- package/dist/web/assets/{ganttDiagram-NO4QXBWP-BwMM9lRV.js → ganttDiagram-NO4QXBWP-C93UiqA8.js} +1 -1
- package/dist/web/assets/{gitGraphDiagram-IHSO6WYX-Ca0Kjref.js → gitGraphDiagram-IHSO6WYX-dNRNMuEa.js} +1 -1
- package/dist/web/assets/highlighted-body-TPN3WLV5-DnHFC22F.js +1 -0
- package/dist/web/assets/{imageViewerCopy-BBW9Oggj.js → imageViewerCopy-CZ0PxllY.js} +1 -1
- package/dist/web/assets/index-C6NKSiG-.js +2 -0
- package/dist/web/assets/{index-CtwbNx5m.js → index-C_U23Las.js} +1 -1
- package/dist/web/assets/{index-B5px1ls4.js → index-CvmmrrPC.js} +1 -1
- package/dist/web/assets/{index-ofOCAr04.js → index-D5vqn_ed.js} +1 -1
- package/dist/web/assets/index-Df0b_mNb.css +1 -0
- package/dist/web/assets/infoDiagram-FWYZ7A6U-CW-qN7ME.js +1 -0
- package/dist/web/assets/{ishikawaDiagram-FXEZZL3T-DJix30qW.js → ishikawaDiagram-FXEZZL3T-B7qgG7qy.js} +1 -1
- package/dist/web/assets/{journeyDiagram-5HDEW3XC-CIDtc9NL.js → journeyDiagram-5HDEW3XC-fC2VOxfE.js} +1 -1
- package/dist/web/assets/{kanban-definition-HUTT4EX6-kNtL91_Y.js → kanban-definition-HUTT4EX6-CgRDoaWP.js} +1 -1
- package/dist/web/assets/{key-round-CBNFW_Qp.js → key-round-DZyIHeFg.js} +1 -1
- package/dist/web/assets/{linear-Pl-iycWx.js → linear-B_EbvSwc.js} +1 -1
- package/dist/web/assets/{mermaid-O7DHMXV3-Bq_tcKDI.js → mermaid-O7DHMXV3-B-4H0Z-Q.js} +2 -2
- package/dist/web/assets/{mermaid.core-DKLhQHMi.js → mermaid.core-CMBPtXgs.js} +2 -2
- package/dist/web/assets/{mic-BHRmNhFG.js → mic-DOgSBjqM.js} +1 -1
- package/dist/web/assets/{mindmap-definition-LN4V7U3C-EdtXTVq3.js → mindmap-definition-LN4V7U3C-XM1lxVqO.js} +1 -1
- package/dist/web/assets/{pegDiagram-2B236MQR-CcQiWdRU.js → pegDiagram-2B236MQR-DYUFpdXI.js} +1 -1
- package/dist/web/assets/{pieDiagram-ENE6RG2P-B9OftxL2.js → pieDiagram-ENE6RG2P-aBVH0JdT.js} +1 -1
- package/dist/web/assets/{quadrantDiagram-ABIIQ3AL-DNzteO4O.js → quadrantDiagram-ABIIQ3AL-Bry3howh.js} +1 -1
- package/dist/web/assets/{railroadDiagram-RFXS5EU6-DETkFxdL.js → railroadDiagram-RFXS5EU6-B_X-RKS6.js} +1 -1
- package/dist/web/assets/{requirementDiagram-TGXJPOKE-Bc2ygXJE.js → requirementDiagram-TGXJPOKE-DSYrODnH.js} +1 -1
- package/dist/web/assets/{sankeyDiagram-HTMAVEWB-ued5WJdO.js → sankeyDiagram-HTMAVEWB-DgTgUObg.js} +1 -1
- package/dist/web/assets/{sequenceDiagram-DBY2YBRQ-CB9W7GEK.js → sequenceDiagram-DBY2YBRQ-C0hrYifi.js} +1 -1
- package/dist/web/assets/{shield-check-BHYK9iHQ.js → shield-check-B5zclKcP.js} +1 -1
- package/dist/web/assets/{sizeCapture-X5ZJPWSS-BlYVWgJQ.js → sizeCapture-X5ZJPWSS-KnPlIyQA.js} +1 -1
- package/dist/web/assets/{stateDiagram-2N3HPSRC-BuBfZ-Ll.js → stateDiagram-2N3HPSRC-DP7NULIr.js} +1 -1
- package/dist/web/assets/stateDiagram-v2-6OUMAXLB-BhpeOEvI.js +1 -0
- package/dist/web/assets/{swimlanes-5IMT3BWC-DymXACYM.js → swimlanes-5IMT3BWC-Dg7S6oxH.js} +2 -2
- package/dist/web/assets/swimlanesDiagram-G3AALYLV-DPHGi19a.js +1 -0
- package/dist/web/assets/{timeline-definition-FHXFAJF6-Doqvtw8A.js → timeline-definition-FHXFAJF6-CLINYAku.js} +1 -1
- package/dist/web/assets/useComposerCompletion-vV_zliKO.js +1 -0
- package/dist/web/assets/{useMessageImage-CkBgO2_p.js → useMessageImage-Bxcjzr5o.js} +1 -1
- package/dist/web/assets/{vennDiagram-L72KCM5P-BTDdTQn0.js → vennDiagram-L72KCM5P-ysQvQnRc.js} +1 -1
- package/dist/web/assets/{wardleyDiagram-EHGQE667-DJVmxdj7.js → wardleyDiagram-EHGQE667-DjkDlqix.js} +1 -1
- package/dist/web/assets/{xychartDiagram-FW5EYKEG-D1C4pPp4.js → xychartDiagram-FW5EYKEG-DHT8vikr.js} +1 -1
- package/dist/web/assets/{zap-DsMffYum.js → zap-CGGziZzC.js} +1 -1
- package/dist/web/index.html +2 -2
- package/dist/web/obsidian-editor-assets.json +1 -1
- package/package.json +7 -7
- package/dist/web/assets/App-DHM2JpIe.js +0 -2
- package/dist/web/assets/BrowserControlPanel-CvtVx3Hr.js +0 -1
- package/dist/web/assets/MarkdownModePanel-R_z8H9hQ.js +0 -1
- package/dist/web/assets/RemoteLifeOSBlock-CwM5U04N.js +0 -2
- package/dist/web/assets/RemoteLifeOSBlock-DVhFsnY2.css +0 -1
- package/dist/web/assets/channel-bz5uCtjG.js +0 -1
- package/dist/web/assets/chevron-up-BvhbPeN2.js +0 -1
- package/dist/web/assets/classDiagram-OUVF2IWQ-DWTcdIri.js +0 -1
- package/dist/web/assets/classDiagram-v2-EOCWNBFH-DWTcdIri.js +0 -1
- package/dist/web/assets/highlighted-body-TPN3WLV5-VkAb1QUw.js +0 -1
- package/dist/web/assets/index-B0hzMPwQ.css +0 -1
- package/dist/web/assets/index-CTpWXHK5.js +0 -2
- package/dist/web/assets/infoDiagram-FWYZ7A6U-FmG41IWW.js +0 -1
- package/dist/web/assets/stateDiagram-v2-6OUMAXLB-BVWYwLt9.js +0 -1
- package/dist/web/assets/swimlanesDiagram-G3AALYLV-BxIeu7lf.js +0 -1
- package/dist/web/assets/useComposerCompletion-f1any5m7.js +0 -1
- package/dist/web/logo.svg +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/sizeCapture-X5ZJPWSS-
|
|
2
|
-
import{_ as t}from"./index-CTpWXHK5.js";import{c as e}from"./chunk-RYQCIY6F-DO7-HDJp.js";import{al as n,am as o,an as r,ao as s,l as i,c as a,af as c,ae as f,ag as d,as as l,au as u,_ as h,z as g,ar as p,av as x,y as m,aw as y,ax as b}from"./mermaid.core-DKLhQHMi.js";import{G as M}from"./graph-BD-RY4fR.js";import"./map-Dwt0FgOz.js";import"./isArrayLikeObject-C958pSF-.js";import"./_initCloneObject-BR1zWEqJ.js";import"./RemoteLifeOSBlock-CwM5U04N.js";import"./index-ofOCAr04.js";import"./index-B5px1ls4.js";import"./file-editor-index-C6CU7Fik.js";import"./App-DHM2JpIe.js";import"./chevron-up-BvhbPeN2.js";import"./__vite-browser-external-2447137e-Ck9f6uYD.js";import"./purify.es-BNLkGfTg.js";import"./marked.esm-BBjA1da9.js";async function I(e,n){const o=new M({multigraph:!0,compound:!0}),r=[...n.edges],s=a(),i=e.insert("g").attr("class","root"),f=i.insert("g").attr("class","clusters"),d=i.insert("g").attr("class","edges edgePath"),l=i.insert("g").attr("class","edgeLabels"),u=i.insert("g").attr("class","nodes"),h=new Map,g=null!=e.node();await Promise.all(n.nodes.map(async t=>{if(t.isGroup)o.setNode(t.id,{...t});else{if(g){const e=await c(u,t,{config:s,dir:t.dir}),n=e.node()?.getBBox()??{width:0,height:0};h.set(t.id,e),t.width=n.width,t.height=n.height}o.setNode(t.id,{...t})}}));for(const t of r)o.setEdge(t.start,t.end,{...t},t.id),n.edges.some(e=>e.id===t.id)||n.edges.push(t);if(globalThis.mermaidCaptureSizes){const{captureNodeSizes:o}=await t(async()=>{const{captureNodeSizes:t}=await import("./sizeCapture-X5ZJPWSS-BlYVWgJQ.js");return{captureNodeSizes:t}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]));o(e,n)}return{graph:o,groups:{clusters:f,edgePaths:d,edgeLabels:l,nodes:u,rootGroups:i},nodeElements:h}}h(I,"createGraphWithElements");var S=1e-5,w=1e-6;function v(t){const e=[];for(let n=0;n<t.length-1;n++)e.push({a:t[n],b:t[n+1]});return e}function L(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(0===c)return null;const f=n.x-t.x,d=n.y-t.y,l=(f*a-d*i)/c,u=(f*s-d*r)/c;return l<=w||l>=.999999||u<=w||u>=.999999?null:{point:{x:t.x+l*r,y:t.y+l*s},tA:l,tB:u}}function C(t){return Math.abs(t.b.x-t.a.x)>=Math.abs(t.b.y-t.a.y)}function k(t){const e=[];for(let n=0;n<t.length;n++){const o=t[n],r=v(o.points);for(let s=n+1;s<t.length;s++){const n=t[s],i=v(n.points);for(const[t,s]of r.entries())for(const[r,a]of i.entries()){const i=L(s.a,s.b,a.a,a.b);if(!i)continue;const c=C(s);c!==C(a)&&c?e.push({jumpEdgeId:o.id,otherEdgeId:n.id,segIndex:t,t:i.tA,point:i.point}):e.push({jumpEdgeId:n.id,otherEdgeId:o.id,segIndex:r,t:i.tB,point:i.point})}}}return e}function T(t){const e=Math.round(1e3*t)/1e3;return Number.isInteger(e),`${e}`}function O(t){return`${T(t.x)},${T(t.y)}`}function $(t){const e=t.b.x-t.a.x,n=t.b.y-t.a.y;return Math.abs(e)>=Math.abs(n)?e>=0?1:0:n>=0?1:0}function R(t,e){if(t.length<2)return t.map(t=>({...t}));const n=t.map(t=>({...t})),o=e.arrowTypeStart&&b[e.arrowTypeStart];if(o){const e=t[0],r=t[1],s=Math.atan2(r.y-e.y,r.x-e.x);n[0].x=e.x+o*Math.cos(s),n[0].y=e.y+o*Math.sin(s)}const r=e.arrowTypeEnd&&b[e.arrowTypeEnd];if(r){const e=t.length,o=t[e-2],s=t[e-1],i=Math.atan2(s.y-o.y,s.x-o.x);n[e-1].x=s.x-r*Math.cos(i),n[e-1].y=s.y-r*Math.sin(i)}return n}function N(t,e,n,o,r){const s=t.point.x,i=t.point.y,a={x:s-e*t.r,y:i-n*t.r},c={x:s+e*t.r,y:i+n*t.r},f=[`L${O(a)}`];return"arc"===r?f.push(`A${T(t.r)},${T(t.r)} 0 0 ${o} ${O(c)}`):f.push(`M${O(c)}`),f}function B(t,e,n,o){const r=e.x-t.x,s=e.y-t.y,i=n.x-e.x,a=n.y-e.y,c=Math.hypot(r,s),f=Math.hypot(i,a);if(c<S||f<S)return null;const d=r/c,l=s/c,u=i/f,h=a/f,g=d*u+l*h,p=Math.max(-1,Math.min(1,g)),x=Math.acos(p);if(x<S||Math.abs(Math.PI-x)<S)return null;const m=Math.min(o/Math.sin(x/2),c/2,f/2);return{startX:e.x-d*m,startY:e.y-l*m,endX:e.x+u*m,endY:e.y+h*m,ctrlX:e.x,ctrlY:e.y,cutLen:m}}function E(t,e,n){const o=t.points;if(o.length<2)return"";const r=R(o,t),s="rounded"===t.curve,i=v(r),a=new Map;for(const f of e){const t=i[f.segIndex];if(!t)continue;const e=Math.hypot(t.b.x-t.a.x,t.b.y-t.a.y),o=a.get(f.segIndex)??[];o.push({t:f.t,point:f.point,d:f.t*e,r:n.jumpRadius}),a.set(f.segIndex,o)}const c=[`M${O(r[0])}`];for(let f=0;f<i.length;f++){const t=i[f],e=Math.hypot(t.b.x-t.a.x,t.b.y-t.a.y),o=0===e?0:(t.b.x-t.a.x)/e,d=0===e?0:(t.b.y-t.a.y)/e,l=$(t);let u=0;if(s&&f>0){const t=B(r[f-1],r[f],r[f+1]??r[f],5);t&&(u=t.cutLen)}let h=e,g=null;s&&f<i.length-1&&(g=B(r[f],r[f+1],r[f+2]??r[f+1],5),g&&(h=e-g.cutLen));const p=[...a.get(f)??[]].sort((t,e)=>t.t-e.t);for(const n of p)n.r=Math.min(n.r,n.d-u,h-n.d);for(let n=0;n<p.length-1;n++){const t=p[n+1].d-p[n].d;if(p[n].r+p[n+1].r>t){const e=t/2;p[n].r=Math.min(p[n].r,e),p[n+1].r=Math.min(p[n+1].r,e)}}for(const r of p)r.r<.001||c.push(...N(r,o,d,l,n.jumpStyle));s&&g?(c.push(`L${T(g.startX)},${T(g.startY)}`),c.push(`Q${T(g.ctrlX)},${T(g.ctrlY)} ${T(g.endX)},${T(g.endY)}`)):c.push(`L${O(t.b)}`)}return c.join(" ")}function F(t){return/^[\d\s+,.LMelm-]*$/.test(t)}function Y(t){return!t||"linear"===t||"rounded"===t||"step"===t||"stepBefore"===t||"stepAfter"===t}function X(t){if(!t)return null;try{const e="function"==typeof atob?atob(t):Buffer.from(t,"base64").toString(),n=JSON.parse(e);if(!Array.isArray(n))return null;const o=[];for(const t of n)t&&"number"==typeof t.x&&"number"==typeof t.y&&o.push({x:t.x,y:t.y});return o.length>=2?o:null}catch{return null}}function z(t,e,n){if(!n.enabled)return;const o=t.node();if(!o)return;const r=new Map;for(const f of e)r.set(f.id,f);const s=[],i=new Map;for(const f of e){const t="undefined"!=typeof CSS&&CSS.escape?CSS.escape(f.id):f.id,e=o.querySelector(`path[data-id="${t}"]`);if(!e)continue;i.set(f.id,e);const n=X(e.getAttribute("data-points"))??f.points;s.push({...f,points:n})}const a=k(s);if(0===a.length)return;const c=new Map;for(const f of a){const t=c.get(f.jumpEdgeId)??[];t.push(f),c.set(f.jumpEdgeId,t)}for(const f of s){const t=c.get(f.id);if(!t||0===t.length)continue;const e=r.get(f.id),o=e?.curve;if(void 0!==o&&!Y(o))continue;const s=i.get(f.id);if(!s)continue;if(void 0===o&&!F(s.getAttribute("d")??""))continue;const a=s.getAttribute("style")??"",d=/stroke-dasharray\s*:\s*0\s+([\d.]+)\s+[\d.]+\s+([\d.]+)/.exec(a),l=d?Number.parseFloat(d[1]):null,u=d?Number.parseFloat(d[2]):null,h=E(f,t,n);if(s.setAttribute("d",h),null!==l&&null!==u&&"function"==typeof s.getTotalLength){const t=s.getTotalLength(),e=`0 ${l} ${Math.max(0,t-l-u)} ${u}`,n=a.replace(/stroke-dasharray\s*:[^;]*;?/g,`stroke-dasharray: ${e};`).replace(/;\s*;+/g,";");s.setAttribute("style",n)}}}async function P(t,e){for(const r of t.nodes)r.isGroup?await f(e.clusters,r):d(r);const n=new Map;for(const r of t.nodes)r?.id&&n.set(r.id,r);for(const r of t.edges){const o=r.start?n.get(r.start)??{}:{},s=r.end?n.get(r.end)??{}:{},i=l(e.edgePaths,{...r},{},t.type,o,s,t.diagramId);r.label&&await u(e.rootGroups,r),r.label&&A(r,i)}const o=t.config?.swimlane?.lineHops;if(!1!==o){const n="gap"===o?"gap":"arc",r=t.edges.filter(t=>Array.isArray(t.points)&&t.points.length>=2).map(t=>({id:t.id,points:t.points,curve:t.curve,arrowTypeStart:t.arrowTypeStart,arrowTypeEnd:t.arrowTypeEnd}));z(e.edgePaths,r,{enabled:!0,jumpRadius:6,jumpStyle:n})}}function A(t,e){const n=e?.updatedPath??e?.originalPath,o=g(),{subGraphTitleTotalMargin:r}=p({flowchart:o.flowchart??{}});if(t.label){const o=x.get(t.id);let s=t.x,a=t.y;if(n){const o=m.calcLabelPosition(n);i.debug("Moving label "+t.label+" from (",s,",",a,") to (",o.x,",",o.y,") abc88"),e&&(s=o.x,a=o.y)}o.attr("transform",`translate(${s}, ${a+r/2})`)}if(t?.startLabelLeft){const e=y.get(t.id).startLeft;let o=t?.x,r=t?.y;if(n){const e=m.calcTerminalLabelPosition(t.arrowTypeStart?10:0,"start_left",n);o=e.x,r=e.y}e.attr("transform",`translate(${o}, ${r})`)}if(t.startLabelRight){const e=y.get(t.id).startRight;let o=t.x,r=t.y;if(n){const e=m.calcTerminalLabelPosition(t.arrowTypeStart?10:0,"start_right",n);o=e.x,r=e.y}e.attr("transform",`translate(${o}, ${r})`)}if(t.endLabelLeft){const e=y.get(t.id).endLeft;let o=t.x,r=t.y;if(n){const e=m.calcTerminalLabelPosition(t.arrowTypeEnd?10:0,"end_left",n);o=e.x,r=e.y}e.attr("transform",`translate(${o}, ${r})`)}if(t.endLabelRight){const e=y.get(t.id).endRight;let o=t.x,r=t.y;if(n){const e=m.calcTerminalLabelPosition(t.arrowTypeEnd?10:0,"end_right",n);o=e.x,r=e.y}e.attr("transform",`translate(${o}, ${r})`)}}h(v,"buildSegmentList"),h(L,"segmentIntersection"),h(C,"isHorizontalSeg"),h(k,"findEdgeIntersections"),h(T,"fmt"),h(O,"pointToString"),h($,"getArcSweepFlag"),h(R,"applyMarkerOffsets"),h(N,"emitJump"),h(B,"computeRoundedCorner"),h(E,"rewriteEdgePath"),h(F,"isStraightPath"),h(Y,"curveSupportsLineHops"),h(X,"decodeDataPoints"),h(z,"applyLineJumpsToSvg"),h(P,"adjustLayout"),h(A,"positionEdgeLabel");var G="__swimlane_default__";function D(t){return Math.max(t.padding??20,20)}function j(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 H(t){const e=t.direction,n=t.nodes??=[];for(const s of t.nodes??[])s.isGroup&&!s.parentId&&(s.shape="swimlane",e&&(s.direction=e));const o=n.filter(t=>!t.isGroup&&!t.parentId);if(0===o.length)return;let r=n.find(t=>t.id===G);r?r.isGroup&&(r.shape="swimlane",e&&(r.direction=e)):(r={id:G,label:"",isGroup:!0,shape:"swimlane",padding:20,...e?{direction:e}:{}},n.push(r));for(const s of o)s.parentId=G}function _(t){const e=new Map;for(const i of t.nodes??[])e.set(i.id,i);const n=[];for(const i of t.edges??[]){const t="string"==typeof i.start?i.start:void 0,e="string"==typeof i.end?i.end:void 0;t&&e&&(i.labelNodeId||n.push({id:i.id,src:t,dst:e,ref:i}))}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 V(t,e,n,o){const{layout:r}=t,s=t.nodeById,i=o?.layerGap??100,a=o?.nodeGap??40;let c=0;for(const u of e.layers){let t=0;for(const e of u){const o=s.get(e);if(!o){t++;continue}o.layer=c,o.order=t;const r=n.x[e]??t*a,f=n.y[e]??c*i;o.x=r,o.y=f,t++}c++}const f=r.nodes??[],d=new Map,l=[];for(const u of f){if(!u?.isGroup)continue;u.parentId||l.push(u);const t=f.filter(t=>t.parentId===u.id);let e=1/0,o=-1/0,r=1/0,s=-1/0;for(const i of t){const t=i.x??n.x[i.id],a=i.y??n.y[i.id],c=i.width??0,f=i.height??0;null!=t&&null!=a&&(e=Math.min(e,t-c/2),o=Math.max(o,t+c/2),r=Math.min(r,a-f/2),s=Math.max(s,a+f/2))}if(e===1/0||r===1/0)u.x=u.x??0,u.y=u.y??0,u.width=u.width??0,u.height=u.height??0;else{const t=u.padding??20,n=u.parentId?t:2*D(u),i=t,a=Math.max(0,o-e)+n,c=Math.max(0,s-r)+i,f=(e+o)/2,l=(r+s)/2;u.x=f,u.y=l,u.width=a,u.height=c,d.set(u.id,{minX:e,maxX:o,minY:r,maxY:s})}}if(l.length>0&&d.size>0){let t=1/0,e=-1/0,n=0;for(const o of l){const r=o.padding??20;r>n&&(n=r);const s=d.get(o.id);s&&(t=Math.min(t,s.minY),e=Math.max(e,s.maxY))}if(t!==1/0&&e!==-1/0){const o=36,r=Math.max(0,e-t)+2*Math.max(n,o),s=(t+e)/2;for(const e of l)e.y=s,e.height=r,e.swimlaneContentTop=t;const i=[...l].sort((t,e)=>(t.x??0)-(e.x??0)),a=[],c=[],f=[];for(const t of i){const e=d.get(t.id);if(!e)continue;const n=Math.max(0,e.maxX-e.minX)+2*D(t),o=(e.minX+e.maxX)/2;a.push(t.id),c.push(o),f.push(n)}const u=a.length;if(u>0){const t=new Map;if(1===u)t.set(a[0],f[0]);else{const e=[];for(let t=0;t<u-1;t++)e.push(c[t+1]-c[t]);const n=new Array(u);n[0]=0;for(let t=0;t<u-1;t++)n[t+1]=2*e[t]-n[t];let o=0,r=Number.POSITIVE_INFINITY;for(let t=0;t<u;t++){const e=f[t];t%2==0?o=Math.max(o,e-n[t]):r=Math.min(r,n[t]-e)}let s=o;s=o<=r?(o+r)/2:o;for(let i=0;i<u;i++){const e=n[i]+(i%2==0?s:-s),o=Math.max(f[i],e);t.set(a[i],o)}}for(const e of l){const n=t.get(e.id);null!=n&&(e.width=n),j(e)}}}}}function W(t){const e=[],n=[],o=new Map;for(const i of t.nodes)o.set(i.id,i);for(const a of t.edges){if(!a.label||0===a.label.length)continue;if(a.isLayoutOnly)continue;if(a.labelNodeId)continue;const t=a.start?o.get(a.start):void 0,r=a.end?o.get(a.end):void 0;if(!t||!r){i.warn("[EdgeLabelNodes]",`Edge ${a.id} has missing source or target node`);continue}const s=`edge-label-${a.start}-${a.end}-${a.id}`,c=t.parentId!==r.parentId?r.parentId:t.parentId,f={id:s,label:a.label,edgeStart:a.start??"",edgeEnd:a.end??"",shape:"labelRect",width:0,height:0,isEdgeLabel:!0,isDummy:!0,parentId:c,isGroup:!1,labelStyle:Array.isArray(a.labelStyle)?a.labelStyle[0]:a.labelStyle??"",...t.dir?{dir:t.dir}:{}};e.push(f),a.labelNodeId=s,a.label=void 0,a.text=void 0;const d={id:`${a.id}-to-label`,start:a.start,end:s,type:"normal",isLayoutOnly:!0},l={id:`${a.id}-from-label`,start:s,end:a.end,type:"normal",isLayoutOnly:!0};n.push(d,l)}const r=[...t.nodes,...e],s=[...t.edges,...n];return{...t,nodes:r,edges:s}}h(D,"topLaneHorizontalPadding"),h(j,"assignTopLaneTitleRect"),h(H,"prepareLayoutForSwimlanes"),h(_,"toGraphView"),h(V,"writeBackToLayoutData"),h(W,"createEdgeLabelNodes");var q=.001;function J(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:ht(e,n,o,r)}:void 0}function K(t){if(t.isGroup)return;const e=J(t);return e?{id:String(t.id??""),cx:e.cx,cy:e.cy,rect:e.rect}:void 0}function Q(t,e,n=q){return Math.abs(t.x-e.x)<n&&Math.abs(t.y-e.y)<n}function Z(t,e,n=q){return Math.abs(t.x-e.x)<n}function U(t,e,n=q){return Math.abs(t.y-e.y)<n}function tt(t,e,n=q){return U(t,e,n)&&Math.abs(t.x-e.x)>n}function et(t,e,n=q){return Z(t,e,n)&&Math.abs(t.y-e.y)>n}function nt(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 ot(t,e,n=q){return t.horizontal&&e.horizontal&&U(t.a,e.a,n)?nt(t.a.x,t.b.x,e.a.x,e.b.x):t.vertical&&e.vertical&&Z(t.a,e.a,n)?nt(t.a.y,t.b.y,e.a.y,e.b.y):0}function rt(t,e=q){const n=[];for(let o=0;o<t.length-1;o++){const r=t[o],s=t[o+1],i=tt(r,s,e),a=et(r,s,e);(i||a)&&n.push({index:o,a:r,b:s,horizontal:i,vertical:a})}return n}function st(t,e=q){const n=rt(t,e);let o=0;for(let r=1;r<n.length;r++)n[r-1].horizontal!==n[r].horizontal&&o++;return o}function it(t,e=q){const n=[];for(const o of t){const t=n.length>0?n[n.length-1]:void 0;t&&Q(t,o,e)||n.push({x:o.x,y:o.y})}return n}function at(t,e=q){if(!t||4!==t.length)return;const[n,o,r,s]=t;return tt(n,o,e)&&et(o,r,e)&&tt(r,s,e)?{kind:"HVH",p0:n,p1:o,p2:r,p3:s}:et(n,o,e)&&tt(o,r,e)&&et(r,s,e)?{kind:"VHV",p0:n,p1:o,p2:r,p3:s}:void 0}function ct(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 ft(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 dt(t,e){return t.left<=e.left&&t.right>=e.right&&t.top<=e.top&&t.bottom>=e.bottom}function lt(t,e){return t.left<e.right&&t.right>e.left&&t.top<e.bottom&&t.bottom>e.top}function ut(t,e){return{left:t.left-e,right:t.right+e,top:t.top-e,bottom:t.bottom+e}}function ht(t,e,n,o){return{left:t-n/2,right:t+n/2,top:e-o/2,bottom:e+o/2}}function gt(t){return J(t)?.rect}function pt(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 xt(t,e,n,o,r,s=q){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(U(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(U(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(Z(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(Z(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 mt(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 yt(t){const e=new Map,n=[];for(const o of t){if(o.isEdgeLabel)continue;const t=K(o);t&&(e.set(t.id,t),n.push({id:t.id,rect:t.rect}))}return{nodeInfoById:e,realNodeRects:n}}function bt(t){const e=[],n=[];for(const o of t){const t=K(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 Mt(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,...ht(t,r,s,i)})}return n}function It(t,e,n=q){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 St(t,e,n,o=[],r=0){for(const s of n)if(!o.includes(s.id)&&ct(t,e,s.rect,-r))return!0;return!1}function wt(t,e,n,o,r=q,s=1e-6){const i=U(t,e,r),a=Z(t,e,r),c=U(n,o,r),f=Z(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},u=d.a.y,h=Math.min(d.a.x,d.b.x),g=Math.max(d.a.x,d.b.x),p=l.a.x,x=Math.min(l.a.y,l.b.y),m=Math.max(l.a.y,l.b.y);if(p<h||p>g||u<x||u>m)return!1;const y=Math.abs(p-d.a.x)<s&&Math.abs(u-d.a.y)<s||Math.abs(p-d.b.x)<s&&Math.abs(u-d.b.y)<s,b=Math.abs(p-l.a.x)<s&&Math.abs(u-l.a.y)<s||Math.abs(p-l.b.x)<s&&Math.abs(u-l.b.y)<s;return!(y&&b)}function vt(t,e,n,o,r=q){const s=U(t,e,r),i=Z(t,e,r),a=U(n,o,r),c=Z(n,o,r);return i&&c&&Z(t,n,r)?nt(t.y,e.y,n.y,o.y)>r:!!(s&&a&&U(t,n,r))&&nt(t.x,e.x,n.x,o.x)>r}function Lt(t,e,n,o,{epsilon:r=q,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||!Q(i,a,r))&&(wt(t,e,i,a,r)||vt(t,e,i,a,r)))return!0}}return!1}function Ct(t,e,n,o,r=q){const s=U(t,e,r),i=Z(t,e,r),a=U(n,o,r),c=Z(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,u=Math.min(f.a.x,f.b.x),h=Math.max(f.a.x,f.b.x),g=d.a.x,p=Math.min(d.a.y,d.b.y),x=Math.max(d.a.y,d.b.y);return g>u+r&&g<h-r&&l>p+r&&l<x-r}function kt(t,e,n){const o=Math.min(e,n),r=Math.max(e,n);return t>o+q&&t<r-q}function Tt(t,e,n){return Z(t,e)&&Z(e,n)?kt(e.y,t.y,n.y):!(!U(t,e)||!U(e,n))&&kt(e.x,t.x,n.x)}function Ot(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(Q(r,i)){o++,e=!0;continue}if(Tt(r,s,i)){e=!0;continue}}n.push(s)}return{points:n,changed:e}}function $t(t){const e=[t[0]];for(let o=1;o<t.length;o++){const n=e[e.length-1],r=t[o];if(!Z(n,r)&&!U(n,r)){const t=e.length>=2?e[e.length-2]:void 0,o=t&&Z(t,n)?{x:n.x,y:r.y}:{x:r.x,y:n.y};e.push(o)}e.push(r)}const n=[];for(const o of e){const t=n[n.length-1];t&&Q(t,o)||n.push(o)}return n}function Rt(t){if(t.length<3)return t;let e=[...t];for(let n=0;n<32;n++){const t=Ot(e);if(e=t.points,!t.changed)break}return e}h(J,"measuredNodeRect"),h(K,"nodeBoundsInfoFor"),h(Q,"samePoint"),h(Z,"sameX"),h(U,"sameY"),h(tt,"isHorizontalSegment"),h(et,"isVerticalSegment"),h(nt,"overlapLength"),h(ot,"sameAxisSegmentOverlapLength"),h(rt,"orthogonalSegmentsForPoints"),h(st,"countOrthogonalBends"),h(it,"dedupeConsecutivePoints"),h(at,"classifyThreeSegmentRoute"),h(ct,"segmentBoundsOverlapRect"),h(ft,"pointInsideRect"),h(dt,"rectContainsRect"),h(lt,"rectsOverlap"),h(ut,"inflateRect"),h(ht,"rectFromCenterSize"),h(gt,"rectOfNodeBounds"),h(pt,"portForRectSide"),h(xt,"buildOrthogonalPortPath"),h(mt,"buildSameSideTrackPath"),h(yt,"collectRealNodeBounds"),h(bt,"collectNodeRectEntries"),h(Mt,"collectLayoutNodeRects"),h(It,"getNodePairGeometry"),h(St,"segmentHitsAnyRect"),h(wt,"orthogonalSegmentsCross"),h(vt,"sameAxisSegmentsOverlap"),h(Lt,"segmentConflictsWithAnyEdge"),h(Ct,"orthogonalSegmentsStrictlyCross"),h(kt,"strictlyBetween"),h(Tt,"isCollinearIntermediate"),h(Ot,"simplifyPolylineOnce"),h($t,"orthogonalizePolyline"),h(Rt,"simplifyPolyline");var Nt=.001;function Bt(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?gt(r):void 0,dstRect:s?gt(s):void 0}}function Et(t,e,n){if(U(t,e,Nt))return{x:t.x<n.left?n.left:n.right,y:t.y};if(Z(t,e,Nt)){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 Ft(t,e,n){const o=n?1:-1;let r=n?0:t.length-1;for(;r>=0&&r<t.length&&ft(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=Et(t[r],t[s],e);return n?[i,...t.slice(r)]:[...t.slice(0,r+1),i]}function Yt(t,e){for(const n of t){const t=Bt(n,e,2);if(!t)continue;let o=[...t.points];t.srcRect&&(o=Ft(o,t.srcRect,!0)),t.dstRect&&(o=Ft(o,t.dstRect,!1)),o=Rt($t(o)),o=Wt(o,t.srcRect,t.dstRect),t.edge.points=Rt($t(o))}}function Xt(t,e,n,o=!1){if(U(t,e,Nt)){if(e.y<n.top-Nt||e.y>n.bottom+Nt)return e;if(o){if(t.x<n.left-Nt)return{x:n.left,y:t.y};if(t.x>n.right+Nt)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(Z(t,e,Nt)){if(e.x<n.left-Nt||e.x>n.right+Nt)return e;if(o){if(t.y<n.top-Nt)return{x:t.x,y:n.top};if(t.y>n.bottom+Nt)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 zt(t,e,n){const o=t[e];for(let r=e+n;r>=0&&r<t.length;r+=n){const e=t[r];if(!Q(e,o,Nt))return e}return t[e+n]}function Pt(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 At(t,e,n){const{lo:o,hi:r}=Pt(e,n);return Math.min(r,Math.max(o,t))}function Gt(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 Dt(t,e){return"left"===e||"right"===e?Pt(t.top,t.bottom):Pt(t.left,t.right)}function jt(t,e,n){const o=t.y>=n.top-Nt&&t.y<=n.bottom+Nt,r=t.x>=n.left-Nt&&t.x<=n.right+Nt;if(U(t,e,Nt)&&o){if(Math.abs(t.x-n.left)<Nt)return"left";if(Math.abs(t.x-n.right)<Nt)return"right"}if(Z(t,e,Nt)&&r){if(Math.abs(t.y-n.top)<Nt)return"top";if(Math.abs(t.y-n.bottom)<Nt)return"bottom"}}function Ht(t){return"left"===t||"right"===t}function _t(t,e,n,o,r){const s=[],i=n?jt(t,e,n):void 0,a=o?jt(e,t,o):void 0;return n&&i&&Ht(i)===r&&s.push(Dt(n,i)),o&&a&&Ht(a)===r&&s.push(Dt(o,a)),s.length>0?Gt(s):void 0}function Vt(t,e,n,o,r){const s=_t(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)<Nt?void 0:r?[{x:t.x,y:a},{x:e.x,y:a}]:[{x:a,y:t.y},{x:a,y:e.y}]}function Wt(t,e,n){if(2!==t.length)return t;const[o,r]=t;return U(o,r,Nt)?Vt(o,r,e,n,!0)??t:Z(o,r,Nt)?Vt(o,r,e,n,!1)??t:t}function qt(t,e,n){return Ht(n)?{x:t.x,y:At(t.y,e.top,e.bottom)}:{x:At(t.x,e.left,e.right),y:t.y}}function Jt(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&&!U(e,o,Nt))break;if(!s&&!Z(e,o,Nt))break;s?i[a].y=r.y:i[a].x=r.x}return i}function Kt(t,e,n){if(t.length<2)return t;const o=n?0:t.length-1,r=n?1:-1,s=t[o],i=zt(t,o,r);if(!i)return t;const a=jt(s,i,e);if(!a)return t;const c=Ht(a),f=qt(s,e,a);return Q(s,f,Nt)?t:Jt(t,o,r,s,f,c)}function Qt(t,e,n){const o=Math.min(t.x,e.x)>=n.left-Nt&&Math.max(t.x,e.x)<=n.right+Nt,r=Math.min(t.y,e.y)>=n.top-Nt&&Math.max(t.y,e.y)<=n.bottom+Nt;return Math.abs(t.y-n.top)<Nt&&Math.abs(e.y-n.top)<Nt&&o?"top":Math.abs(t.y-n.bottom)<Nt&&Math.abs(e.y-n.bottom)<Nt&&o?"bottom":Math.abs(t.x-n.left)<Nt&&Math.abs(e.x-n.left)<Nt&&r?"left":Math.abs(t.x-n.right)<Nt&&Math.abs(e.x-n.right)<Nt&&r?"right":void 0}function Zt(t,e,n,o){switch(t){case"top":return Z(e,n,Nt)&&n.y<o.top-Nt;case"bottom":return Z(e,n,Nt)&&n.y>o.bottom+Nt;case"left":return U(e,n,Nt)&&n.x<o.left-Nt;case"right":return U(e,n,Nt)&&n.x>o.right+Nt}}function Ut(t,e,n){if(t.length<3)return t;if(n){const n=Qt(t[0],t[1],e);return n&&Zt(n,t[1],t[2],e)?t.slice(1):t}const o=t.length-1,r=Qt(t[o-1],t[o],e);return r&&Zt(r,t[o-1],t[o-2],e)?t.slice(0,o):t}function te(t,e,n){let o=t;if(e){const t=zt(o,0,1);if(t){const n=Xt(t,o[0],e);n!==o[0]&&(o=[n,...o.slice(1)])}o=Ut(o,e,!0)}if(n){const t=o.length-1,e=zt(o,t,-1);if(e){const r=Xt(e,o[t],n,!0);r!==o[t]&&(o=[...o.slice(0,t),r])}o=Ut(o,n,!1)}const r=Wt(o,e,n);return r!==o||2===o.length?r:(e&&(o=Kt(o,e,!0)),n&&(o=Kt(o,n,!1)),o)}function ee(t,e){for(const n of t){const t=Bt(n,e,2);if(!t)continue;const o=te(it(t.points,Nt),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 ne(t){return new Map(t.map(t=>[t.id,t]))}function oe(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 re(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 se(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 ie(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 ae(t){const e=ne(t),n=t.filter(t=>t.isGroup&&t.parentId).sort((t,n)=>re(n,e)-re(t,e));for(const o of n){const e=se(t.filter(t=>t.parentId===o.id));e&&ie(o,e)}}function ce(t,e){const n=t.nodes??[],o=t.edges??[],r=n.filter(t=>!t.isGroup);let s=1/0,i=-1/0;for(const c of r){const t=c[e];"number"==typeof t&&(s=Math.min(s,t),i=Math.max(i,t))}if(!Number.isFinite(s)||!Number.isFinite(i))return!1;const a=h(t=>s+i-t,"mirror");for(const c of n){const t=c[e];"number"==typeof t&&(c[e]=a(t));const n=c.groupTitleRect;n&&(c.groupTitleRect="x"===e?{...n,left:a(n.right),right:a(n.left)}:{...n,top:a(n.bottom),bottom:a(n.top)})}for(const c of o)for(const t of c.points??[])t[e]=a(t[e]);return!0}function fe(t){return!(t.nodes??[]).some(t=>!t.isGroup)||ce(t,"y")}function de(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 L of r){const t=L.x??0,e=L.y??0;t<s&&(s=t),e<i&&(i=e)}if(!Number.isFinite(s)||!Number.isFinite(i))return!1;const a=36;let c=0,f=0;for(const L of r)c+=L.width??0,f+=L.height??0;const d=c/r.length,l=f/r.length,u=l>0?Math.max(1,d/l):1;for(const L of r){const t=L.x??0,e=((L.y??0)-i)*u+a,n=t-s;L.x=e,L.y=n}for(const L of o)if(L.points)for(const t of L.points){const e=t.x,n=(t.y-i)*u+a,o=e-s;t.x=n,t.y=o}ae(n);const h=n.filter(t=>t.isGroup&&!t.parentId);if(0===h.length)return"RL"===e&&ce(t,"x"),!0;const g=ne(n),p=new Map;for(const L of n){if(L.isGroup)continue;const t=oe(L,g);if(!t)continue;const e=p.get(t)??[];e.push(L),p.set(t,e)}let x=0;for(const L of h){const t=L.padding??0;t>x&&(x=t)}const m=[];let y=1/0,b=-1/0;for(const L of h){const t=se(p.get(L.id)??[]);t&&(y=Math.min(y,t.minX),b=Math.max(b,t.maxX),m.push({lane:L,contentTop:t.minY,contentBottom:t.maxY,centerY:(t.minY+t.maxY)/2}))}if(y===1/0||b===-1/0)return!0;const M=Math.max(0,b-y)+2*Math.max(x,10),I=a+M,S=(y+b)/2-M/2-a,w=S+I/2,v=Math.max(x,a);m.sort((t,e)=>t.centerY-e.centerY);for(let L=0;L<m.length;L++){const t=m[L];let e,n;if(e=0===L?t.contentTop-v:(m[L-1].contentBottom+t.contentTop)/2,L===m.length-1)n=t.contentBottom+v;else{const e=m[L+1];n=(t.contentBottom+e.contentTop)/2}const o=Math.max(0,n-e),r=(e+n)/2;t.lane.x=w,t.lane.y=r,t.lane.width=I,t.lane.height=o,t.lane.swimlaneContentTop=t.contentTop,t.lane.groupTitleRect={left:S,right:S+a,top:e,bottom:n}}return"RL"===e&&ce(t,"x"),!0}h(Bt,"endpointContextFor"),h(Et,"segmentEnterPoint"),h(Ft,"clipEndpoint"),h(Yt,"clipEdgeEndpointsToNodeBoundaries"),h(Xt,"snapEndpointToBoundary"),h(zt,"firstDistinctAdjacent"),h(Pt,"cornerClearanceRange"),h(At,"clampToCornerClearance"),h(Gt,"intersectRanges"),h(Dt,"clearanceRangeForSide"),h(jt,"terminalSideForSegment"),h(Ht,"isHorizontalSide"),h(_t,"straightClearanceRange"),h(Vt,"clearStraightEndpointCornerAxis"),h(Wt,"clearStraightEndpointCornerConnections"),h(qt,"cornerClearedEndpoint"),h(Jt,"moveCollinearEndpointRun"),h(Kt,"clearEndpointCornerConnection"),h(Qt,"borderSideForSegment"),h(Zt,"leavesOutward"),h(Ut,"collapseOwnBorderStub"),h(te,"snapAndCollapseEndpoints"),h(ee,"prepareEdgeEndpointsForRenderer"),h(ne,"buildNodeMap"),h(oe,"resolveTopLevelGroupId"),h(re,"groupDepth"),h(se,"boundsForChildren"),h(ie,"applyGroupBounds"),h(ae,"recomputeNestedGroupBounds"),h(ce,"mirrorAxis"),h(fe,"applyBtDirectionTransform"),h(de,"applyLrDirectionTransform");var le=1e-6,ue=[0,8,-8,16,-16];function he(t,e){const{nodeInfoById:n,realNodeRects:o}=yt(e);for(const r of t){if(r.isLayoutOnly)continue;const e=r.points;if(!e||e.length<4)continue;const s=at(it(e,le),le);if(!s)continue;const{p3:i}=s,a="HVH"===s.kind,c=It(r,n,le);if(!c)continue;const{srcId:f,dstId:d,srcInfo:l,dstInfo:u,collinearX:h,collinearY:g}=c;if(h||g)continue;let p;const x=l.rect;for(const n of ue){let e,s,c;if(a){const t=u.cy>l.cy?x.bottom:x.top,o=l.cx+n;if(o<=x.left+le||o>=x.right-le)continue;e={x:o,y:t},s={x:o,y:i.y},c={x:i.x,y:i.y}}else{const t=u.cx>l.cx?x.right:x.left,o=l.cy+n;if(o<=x.top+le||o>=x.bottom-le)continue;e={x:t,y:o},s={x:i.x,y:o},c={x:i.x,y:i.y}}const h=Q(e,s,le),g=Q(s,c,le);if(h&&g)continue;if(!h&&St(e,s,o,[f],1))continue;if(!g&&St(s,c,o,[d],1))continue;const m=!h&&Lt(e,s,t,r,{epsilon:le,skipDegenerateOther:!0}),y=!g&&Lt(s,c,t,r,{epsilon:le,skipDegenerateOther:!0});if(!m&&!y){p=h?[s,c]:g?[e,s]:[e,s,c];break}}p&&(r.points=p)}}function ge(t,e){const n=.001,{realNodeRects:o,labelNodeRects:r}=bt(e.values());for(const s of t){if(s.isLayoutOnly)continue;const i=s.points;if(!i||i.length<4)continue;const a=it(i,n);if(a.length<4)continue;const c=a.length-1,f=a[c],d=a[c-1],l=a[c-2],u=f.x-d.x,g=f.y-d.y,p=Math.hypot(u,g);if(p>=10||p<n)continue;const x=d.x-l.x,m=d.y-l.y;if(Math.hypot(x,m)<n)continue;const y=tt(d,f,n),b=et(d,f,n),M=tt(l,d,n),I=et(l,d,n);if(!(y&&I||b&&M))continue;const S=s.end,w=s.start,v=S?e.get(S):void 0;if(!v)continue;const L=v.x??0,C=v.y??0,k=gt(v);if(!k)continue;let T,O;if(I){const t=m<0;T={x:L,y:l.y},O={x:L,y:t?k.bottom:k.top}}else{const t=x>0;T={x:l.x,y:C},O={x:t?k.right:k.left,y:C}}if(St(T,O,o,S?[S]:[],-2))continue;if(St(T,O,r,[],-2))continue;if(w){const t=e.get(w),n=t?gt(t):void 0;if(n&&ft(T,n,2))continue}const $=h((t,e)=>`${t.x.toFixed(3)},${t.y.toFixed(3)}|${e.x.toFixed(3)},${e.y.toFixed(3)}`,"ownSegmentKey"),R=new Set;for(let t=0;t<a.length-1;t++)R.add($(a[t],a[t+1]));const N=h((e,o)=>{for(const r of t){if(r===s)continue;if(r.isLayoutOnly)continue;const t=r.points;if(t&&!(t.length<2))for(let r=0;r<t.length-1;r++){const s=t[r],i=t[r+1];if(!R.has($(s,i))&&Ct(e,o,s,i,n))return!0}}return!1},"segmentCrossesOtherEdge");if(N(T,O))continue;if(c-3>=0){const t=a[c-3];if(St(t,T,o,[w,S].filter(t=>Boolean(t)),-2))continue;if(N(t,T))continue}const B=[...a.slice(0,c-2),T,O];s.points=B;const E=s.labelNodeId;if(E){const t=e.get(E);if(t){const e=t.width??0,o=t.height??0;if(e>0&&o>0){let r,s,i=-1;for(let t=0;t<B.length-1;t++){const a=B[t],c=B[t+1],f=Math.hypot(c.x-a.x,c.y-a.y),d=U(a,c,n),l=Z(a,c,n);(d&&f>=e+2||l&&f>=o+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)}}}}}h(he,"portSwapToLShape"),h(ge,"collapseShortTerminalStub");var pe=.001,xe=rt,me=h((t,e)=>Z(t,e,pe)||U(t,e,pe),"orthogonallyAligned");function ye(t,e){const n=h((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"),o=h((t,o)=>{const r=it(t.points??[]);if(r.length<2)return;const s=o?t.start:t.end,i=s?e.get(s):void 0,a=i?gt(i):void 0;if(!i||!s||!a)return;const c=o?r[0]:r[r.length-1],f=o?r[1]:r[r.length-2],d=n(i,c);let l=c;return me(f,d)&&(l=f),Z(d,l,pe)?{edge:t,edgeId:String(t.id??""),nodeId:s,atStart:o,orientation:"V",coord:d.x,min:Math.min(d.y,l.y),max:Math.max(d.y,l.y),boundary:d,railEnd:l,rect:a}:U(d,l,pe)?{edge:t,edgeId:String(t.id??""),nodeId:s,atStart:o,orientation:"H",coord:d.y,min:Math.min(d.x,l.x),max:Math.max(d.x,l.x),boundary:d,railEnd:l,rect:a}:void 0},"terminalLaneFor"),r=h((t,e)=>Math.max(0,Math.min(t.max,e.max)-Math.max(t.min,e.min)),"projectedOverlapLength"),s=h((t,e)=>t.nodeId===e.nodeId&&t.orientation===e.orientation&&("H"===t.orientation?(Math.abs(t.boundary.x-t.rect.left)<1||Math.abs(t.boundary.x-t.rect.right)<1)&&Z(t.boundary,e.boundary,1):(Math.abs(t.boundary.y-t.rect.top)<1||Math.abs(t.boundary.y-t.rect.bottom)<1)&&U(t.boundary,e.boundary,1)),"sameTerminalFace"),i=h((t,e)=>t.nodeId===e.nodeId&&t.orientation===e.orientation&&r(t,e)>=8&&Math.abs(t.coord-e.coord)<.5,"exactTerminalLaneConflict"),a=h((t,e)=>{if(t.nodeId!==e.nodeId||t.orientation!==e.orientation||"H"!==t.orientation||t.atStart===e.atStart)return!1;const n=r(t,e);if(n<8)return!1;const o=t.rect.bottom-t.rect.top;return!(n<o||n>2*o)&&s(t,e)&&Math.abs(t.coord-e.coord)<16},"nearTerminalLaneConflict"),c=h((t,e)=>{const n=it(t.edge.points??[]);if(n.length<2)return;const o="V"===t.orientation?{x:t.boundary.x+e,y:t.boundary.y}:{x:t.boundary.x,y:t.boundary.y+e},r="V"===t.orientation?{x:t.railEnd.x+e,y:t.railEnd.y}:{x:t.railEnd.x,y:t.railEnd.y+e};if(!h(()=>Math.abs(t.boundary.y-t.rect.top)<1||Math.abs(t.boundary.y-t.rect.bottom)<1?U(o,t.boundary,pe)&&o.x>=t.rect.left+1&&o.x<=t.rect.right-1:(Math.abs(t.boundary.x-t.rect.left)<1||Math.abs(t.boundary.x-t.rect.right)<1)&&Z(o,t.boundary,pe)&&o.y>=t.rect.top+1&&o.y<=t.rect.bottom-1,"boundaryStaysOnSameFace")())return;if(t.atStart){const e=n.length>1&&Q(n[1],t.railEnd,pe),s=n.slice(e?2:1),i=s[0];if(i&&!me(i,r))return;return[o,r,...s]}const s=n.length>1&&Q(n[n.length-2],t.railEnd,pe),i=n.slice(0,s?-2:-1),a=i[i.length-1];return!a||me(a,r)?[...i,r,o]:void 0},"shiftedCandidate"),f=h(t=>{const n=t.edge,o=it(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 U(u,h,pe)&&Math.abs(f-l)<1&&Math.abs(c-d)>1||Z(u,h,pe)&&Math.abs(c-d)<1&&Math.abs(f-l)>1},"laneIsStraightCollinearConnector"),d=[-7,7,-14,14,-21,21];for(let l=0;l<8;l++){const e=t.filter(t=>!t.isLayoutOnly).flatMap(t=>[o(t,!0),o(t,!1)]).filter(t=>Boolean(t));let n=!1;for(let t=0;t<e.length&&!n;t++)for(let r=t+1;r<e.length&&!n;r++){const s=e[t],l=e[r];if(s.edge===l.edge||!i(s,l)&&!a(s,l))continue;const u=!i(s,l),h=[s,l].sort((t,e)=>{const n=f(t),o=f(e);return n!==o?Number(n)-Number(o):Number(!e.atStart)-Number(!t.atStart)});for(const t of h){for(const r of d){const s=c(t,r);if(!s)continue;const f=o({...t.edge,points:s},t.atStart);if(f&&!e.some(e=>e.edge!==t.edge&&(i(f,e)||u&&a(f,e)))){t.edge.points=s,n=!0;break}}if(n)break}}if(!n)return}}function be(t,e){const{realNodeRects:n,labelNodeRects:o}=bt(e.values()),r=h((e,r)=>{const s=e.start,i=e.end,a=xe(r);if(a.length!==r.length-1)return!1;const c=[s,i].filter(t=>Boolean(t));for(const t of a){if(St(t.a,t.b,n,c,-2))return!1;if(St(t.a,t.b,o,[],-2))return!1}for(const n of t){if(n===e||n.isLayoutOnly)continue;const t=n.points;if(t&&!(t.length<2))for(const e of a)for(const n of xe(it(t))){if(ot(e,n,.5)>=8)return!1;if(Ct(e.a,e.b,n.a,n.b,pe))return!1}}return!0},"candidateIsSafe"),s=h((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=tt(n,o)&&et(o,r)&&tt(r,s)&&et(s,i)&&Z(n,s,pe)&&Z(n,i,pe)&&Z(o,r,pe)&&(o.x-n.x)*(s.x-r.x)<0,c=et(n,o)&&tt(o,r)&&et(r,s)&&tt(s,i)&&U(n,s,pe)&&U(n,i,pe)&&U(o,r,pe)&&(o.y-n.y)*(s.y-r.y)<0;if(a||c)return it([...t.slice(0,e+1),i,...t.slice(e+5)]);if(e+5>=t.length)return;const f=t[e+5],d=et(n,o)&&tt(o,r)&&et(r,s)&&tt(s,i)&&et(i,f)&&Z(n,i,pe)&&Z(n,f,pe)&&Z(r,s,pe)&&(r.x-o.x)*(i.x-s.x)<0,l=tt(n,o)&&et(o,r)&&tt(r,s)&&et(s,i)&&tt(i,f)&&U(n,i,pe)&&U(n,f,pe)&&U(r,s,pe)&&(r.y-o.y)*(i.y-s.y)<0;return d||l?it([...t.slice(0,e+1),f,...t.slice(e+6)]):void 0},"withoutDogleg");for(let i=0;i<8;i++){let e=!1;for(const n of t){if(n.isLayoutOnly)continue;const t=it(n.points??[]);for(let o=0;o<=t.length-5;o++){const i=s(t,o);if(i&&r(n,i)){n.points=i,e=!0;break}}if(e)break}if(!e)return}}function Me(t,e){const{realNodeRects:n,labelNodeRects:o}=bt(e.values()),r=t.filter(t=>!t.isLayoutOnly),s=h((t,e,n)=>it(t===e?n??[]:t.points??[]),"pointsFor"),i=h((t,e)=>{let n=0;for(let o=0;o<r.length;o++){const i=xe(s(r[o],t,e));for(let a=o+1;a<r.length;a++){const o=xe(s(r[a],t,e));for(const t of i)for(const e of o)Ct(t.a,t.b,e.a,e.b,pe)&&n++}}return n},"strictCrossingCount"),a=h(t=>{const e=xe(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"),c=h((t,e)=>{const o=[t.start,t.end].filter(t=>Boolean(t));return n.filter(t=>{if(o.includes(t.id))return!1;const n=t.rect;return e.horizontal?nt(e.a.x,e.b.x,n.left,n.right)>=8&&e.a.y>=n.top-2&&e.a.y<=n.bottom+2:nt(e.a.y,e.b.y,n.top,n.bottom)>=8&&e.a.x>=n.left-2&&e.a.x<=n.right+2})},"blockingRectsFor"),f=h((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=Rt(it(o));return xe(r).length===r.length-1?r:void 0},"candidateByMovingRail"),d=h((t,e,a)=>{const c=[t.start,t.end].filter(t=>Boolean(t)),f=xe(e);if(f.length!==e.length-1)return!1;for(const r of f){if(St(r.a,r.b,n,c,-2))return!1;if(St(r.a,r.b,o,[],-2))return!1}for(const n of r)if(n!==t)for(const t of f)for(const e of xe(s(n)))if(ot(t,e,.5)>=8)return!1;return i(t,e)<=a},"candidateIsSafe");for(let l=0;l<8;l++){const t=i();let e=!1;for(const n of r){const o=s(n),r=a(o);if(!r)continue;const i=c(n,r.segment);if(0===i.length)continue;const l=r.horizontal?[Math.min(...i.map(t=>t.rect.top))-20,Math.max(...i.map(t=>t.rect.bottom))+20]:[Math.min(...i.map(t=>t.rect.left))-20,Math.max(...i.map(t=>t.rect.right))+20];for(const s of l){const i=f(o,r.segment,s);if(i&&d(n,i,t)){n.points=i,e=!0;break}}if(e)break}if(!e)return}}function Ie(t,e){const n=h(t=>{const e=t.groupTitleRect;if(e&&"number"==typeof e.left&&"number"==typeof e.right&&"number"==typeof e.top&&"number"==typeof e.bottom&&Number.isFinite(e.left)&&Number.isFinite(e.right)&&Number.isFinite(e.top)&&Number.isFinite(e.bottom)&&!(e.right<=e.left)&&!(e.bottom<=e.top))return{left:e.left,right:e.right,top:e.top,bottom:e.bottom}},"validTitleRect"),o=h(t=>{if(!t.isGroup||t.parentId)return;const e=t.direction,o="string"==typeof e?e.toUpperCase():"";if("LR"===o||"RL"===o||"BT"===o)return;const r=n(t),s=t.y,i=t.height;if(!r||"number"!=typeof s||"number"!=typeof i||!Number.isFinite(s)||!Number.isFinite(i)||i<=0)return;const a=r.right-r.left,c=r.bottom-r.top;return c<=0||a<c?void 0:{node:t,rect:r}},"topLaneTitleFor"),r=h((t,e)=>{if(!t.horizontal)return!1;const n=t.a.y;return!(n<=e.top+pe||n>=e.bottom-pe)&&nt(t.a.x,t.b.x,e.left,e.right)>=8},"horizontalSegmentIntersectsTitle"),s=[...e.values()].map(o).filter(t=>Boolean(t));if(0===s.length)return;let i=0;for(const a of t){if(a.isLayoutOnly)continue;const t=it(a.points??[]);for(const e of xe(t))for(const t of s)r(e,t.rect)&&(i=Math.max(i,t.rect.bottom-e.a.y+4))}if(!(i<=pe))for(const a of s){const t=a.node.y,e=a.node.height;"number"!=typeof t||"number"!=typeof e||!Number.isFinite(t)||!Number.isFinite(e)||e<=0||(a.node.y=t-i/2,a.node.height=e+i,a.node.groupTitleRect={...a.rect,top:a.rect.top-i,bottom:a.rect.bottom-i})}}function Se(t,e){const n=h(t=>{const e=t.groupTitleRect;if(e&&"number"==typeof e.left&&"number"==typeof e.right&&"number"==typeof e.top&&"number"==typeof e.bottom&&Number.isFinite(e.left)&&Number.isFinite(e.right)&&Number.isFinite(e.top)&&Number.isFinite(e.bottom)&&!(e.right<=e.left)&&!(e.bottom<=e.top))return{left:e.left,right:e.right,top:e.top,bottom:e.bottom}},"validTitleRect"),o=h(t=>{if(!t.isGroup||t.parentId)return;if("LR"!==t.direction)return;const e=n(t),o=t.x,r=t.width;if(!e||"number"!=typeof o||"number"!=typeof r||!Number.isFinite(o)||!Number.isFinite(r)||r<=0)return;const s=e.right-e.left,i=e.bottom-e.top;return s<=0||i<s?void 0:{node:t,rect:e}},"leftLaneTitleFor"),r=h((t,e)=>{if(!t.vertical)return!1;const n=t.a.x;return!(n<=e.left+pe||n>=e.right-pe)&&nt(t.a.y,t.b.y,e.top,e.bottom)>=8},"verticalSegmentIntersectsTitle"),s=h((t,e)=>{if(!t.horizontal)return!1;const n=t.a.y;return!(n<=e.top+pe||n>=e.bottom-pe)&&nt(t.a.x,t.b.x,e.left,e.right)>=8},"horizontalSegmentIntersectsTitle"),i=[...e.values()].map(o).filter(t=>Boolean(t));if(0===i.length)return;let a=0;for(const c of t){if(c.isLayoutOnly)continue;const t=it(c.points??[]);for(const e of xe(t))for(const t of i)if(r(e,t.rect))a=Math.max(a,t.rect.right-e.a.x+4);else if(s(e,t.rect)){const n=Math.min(e.a.x,e.b.x);a=Math.max(a,t.rect.right-n+4)}}if(!(a<=pe))for(const c of i){const t=c.node.x,e=c.node.width;"number"!=typeof t||"number"!=typeof e||!Number.isFinite(t)||!Number.isFinite(e)||e<=0||(c.node.x=t-a/2,c.node.width=e+a,c.node.groupTitleRect={...c.rect,left:c.rect.left-a,right:c.rect.right-a})}}function we(t,e){const{realNodeRects:n}=bt(e.values()),o=t.filter(t=>!t.isLayoutOnly),r=h((t,e=new Map)=>it(e.get(t)??t.points??[]),"replacementPointsFor"),s=h((t=new Map)=>{let e=0;for(let n=0;n<o.length;n++){const s=xe(r(o[n],t));for(let i=n+1;i<o.length;i++){const n=xe(r(o[i],t));for(const t of s)for(const o of n)Ct(t.a,t.b,o.a,o.b,pe)&&e++}}return e},"crossingCount"),i=h((t=new Map)=>o.reduce((e,n)=>e+st(r(n,t)),0),"totalBends"),a=h(t=>{const e=r(t);if(e.length<4)return;const n=e[e.length-2],o=e[e.length-1];return tt(n,o,pe)||et(n,o,pe)?{tailStart:n,terminal:o}:void 0},"terminalTailFor"),c=h((t,e)=>{const n=r(t);if(n.length<3)return;const o=n[0],s=n[1];let i;if(tt(o,s,pe))i={x:s.x,y:e.tailStart.y};else{if(!et(o,s,pe))return;i={x:e.tailStart.x,y:s.y}}const a=Rt(it([o,s,i,e.tailStart,e.terminal]));return xe(a).length===a.length-1?a:void 0},"candidateWithDestinationTail"),f=h((t,e)=>{const o=[t.start,t.end].filter(t=>Boolean(t));for(const r of xe(e))if(St(r.a,r.b,n,o,-2))return!0;return!1},"pathHasNodeHit"),d=h((t,e,n)=>{for(const s of o)if(s!==t)for(const t of xe(e))for(const e of xe(r(s,n)))if(ot(t,e,.5)>=8)return!0;return!1},"pathHasSharedTrack"),l=h((t,e,n)=>!f(t,e)&&!d(t,e,n),"candidateIsSafe"),u=h(()=>{const t=new Map;for(const n of o){const o=n.end;if(!o||!e.has(o))continue;if(r(n).length<4)continue;const s=t.get(o)??[];s.push(n),t.set(o,s)}return t},"edgesByDestination");for(let h=0;h<4;h++){const t=s();if(0===t)return;let e,n=t,o=i();for(const r of u().values())for(let f=0;f<r.length;f++)for(let d=f+1;d<r.length;d++){const u=r[f],h=r[d],g=a(u),p=a(h);if(!g||!p)continue;const x=c(u,p),m=c(h,g);if(!x||!m)continue;const y=new Map([[u,x],[h,m]]);if(!l(u,x,y)||!l(h,m,y))continue;const b=s(y),M=i(y);b>=t||b>n||b===n&&M>=o||(e=y,n=b,o=M)}if(!e)return;for(const[r,s]of e)r.points=s}}function ve(t,e){const{realNodeRects:n,labelNodeRects:o}=bt(e.values()),r=t.filter(t=>!t.isLayoutOnly),s=h((t,e=new Map)=>it(e.get(t)??t.points??[]),"replacementPointsFor"),i=h((t=new Map)=>{let e=0;for(let n=0;n<r.length;n++){const o=xe(s(r[n],t));for(let i=n+1;i<r.length;i++){const n=xe(s(r[i],t));for(const t of o)for(const o of n)Ct(t.a,t.b,o.a,o.b,pe)&&e++}}return e},"strictCrossingCount"),a=h((t=new Map)=>r.reduce((e,n)=>e+st(s(n,t)),0),"totalBends"),c=h(t=>{const n=t.start,o=t.end,r=n?e.get(n):void 0,s=o?e.get(o):void 0,i=r?gt(r):void 0,a=s?gt(s):void 0;return i&&a?{src:i,dst:a}:void 0},"endpointRectsFor"),f=h((t,e,n)=>{if(n.index<=0||n.index+1>=e.length-1)return;const o=c(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-pe?"left":r>i+pe?"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-pe?"top":r>i+pe?"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"),d=h(()=>{const t=[];for(const e of r){const n=s(e);for(const o of xe(n)){const r=f(e,n,o);r&&t.push(r)}}return t},"collectExternalRails"),l=h((t,e)=>t.edge!==e.edge&&t.axis===e.axis&&t.side===e.side&&nt(t.min,t.max,e.min,e.max)>=8,"railsInteract"),u=h(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)&&l(e,o)&&(n.add(o),r.push(o))}s.length>1&&e.push(s)}return e},"connectedComponents"),g=h(t=>{const e=[];for(const n of t)e.some(t=>Math.abs(t-n.coord)<pe)||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=h(t=>{const e=t.map(t=>t.coord),n=g(t),o=[];if(t.length<=6){const r=new Array(n.length).fill(!1),s=[],i=h(()=>{if(s.length!==t.length)for(const[t,e]of n.entries())r[t]||(r[t]=!0,s.push(e),i(),s.pop(),r[t]=!1);else s.some((t,n)=>Math.abs(t-e[n])>=pe)&&o.push([...s])},"visit");return i(),o}for(let r=0;r<e.length;r++)for(let t=r+1;t<e.length;t++){const n=[...e];[n[r],n[t]]=[n[t],n[r]],o.push(n)}return o},"coordinateAssignmentsFor"),x=h((t,e)=>{const n=new Map;for(const[r,s]of t.entries()){const t=e[r],o=n.get(s.edge)??s.points.map(t=>({x:t.x,y:t.y}));"vertical"===s.axis?(o[s.segmentIndex].x=t,o[s.segmentIndex+1].x=t):(o[s.segmentIndex].y=t,o[s.segmentIndex+1].y=t),n.set(s.edge,o)}const o=new Map;for(const[r,s]of n){const t=Rt(it(s));if(xe(t).length!==t.length-1)return;o.set(r,t)}return o},"replacementsForAssignment"),m=h(t=>{for(const[e,r]of t){const t=[e.start,e.end].filter(t=>Boolean(t));for(const e of xe(r)){if(St(e.a,e.b,n,t,-2))return!1;if(St(e.a,e.b,o,[],-2))return!1}}for(let e=0;e<r.length;e++){const n=r[e],o=t.has(n),i=xe(s(n,t));for(let a=e+1;a<r.length;a++){const e=r[a];if(!o&&!t.has(e))continue;const n=xe(s(e,t));for(const t of i)for(const e of n)if(ot(t,e,.5)>=8)return!1}}return!0},"candidateIsSafe");for(let h=0;h<4;h++){const t=i();if(0===t)return;let e,n=t,o=a(),r=Number.POSITIVE_INFINITY;for(const s of u(d()))for(const c of p(s)){const f=x(s,c);if(!f||!m(f))continue;const d=i(f);if(d>=t)continue;const l=a(f),u=s.reduce((t,e,n)=>t+Math.abs(c[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[s,i]of e)s.points=i}}function Le(t,e){const{realNodeRects:n,labelNodeRects:o}=bt(e.values()),r=t.filter(t=>!t.isLayoutOnly),s=h((t,e,n)=>it(t===e?n??[]:t.points??[]),"pointsFor"),i=h(t=>xe(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"),a=h((t,e)=>{let n=0;for(let o=0;o<r.length;o++){const i=xe(s(r[o],t,e));for(let a=o+1;a<r.length;a++){const o=xe(s(r[a],t,e));for(const t of i)for(const e of o)Ct(t.a,t.b,e.a,e.b,pe)&&n++}}return n},"strictCrossingCount"),c=h((t,e)=>{if(t.horizontal){const n=t.a.y;return(Math.abs(n-e.top)<1||Math.abs(n-e.bottom)<1)&&nt(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)&&nt(t.a.y,t.b.y,e.top,e.bottom)>=8}return!1},"segmentRunsAlongRectBorder"),f=h(t=>{const n=[t.start,t.end].filter(t=>Boolean(t)),o=[];for(const r of n){const t=e.get(r),n=t?gt(t):void 0;n&&o.push(n)}return o},"endpointRectsFor"),d=h((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=tt(n,o,pe)&&et(o,r,pe)&&tt(r,s,pe),a=et(n,o,pe)&&tt(o,r,pe)&&et(r,s,pe);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=Z(n,s,pe)||U(n,s,pe)?[]:[{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=>Rt(it(t))).filter(t=>{if(xe(t).length!==t.length-1)return!1;if(!t.some(t=>Q(t,s,pe)))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"),l=h((t,e,i)=>{const d=[t.start,t.end].filter(t=>Boolean(t)),l=f(t);for(const r of xe(e)){if(St(r.a,r.b,n,d,-2))return!1;if(St(r.a,r.b,o,[],-2))return!1;if(l.some(t=>c(r,t)))return!1}for(const n of r)if(n!==t)for(const t of xe(e))for(const e of xe(s(n)))if(ot(t,e,.5)>=8)return!1;return a(t,e)<=i},"candidateIsSafe");for(let u=0;u<8;u++){const t=a();let e,n,o=t,c=Number.POSITIVE_INFINITY,f=Number.POSITIVE_INFINITY;for(const u of r){const r=s(u),h=st(r,pe),g=i(r);for(let s=0;s<=r.length-4;s++)for(const p of d(r,s)){const r=st(p,pe),s=i(p);if(!(r<h||r===h&&s<g-pe)||!l(u,p,t))continue;const d=a(u,p);d>o||d===o&&(r>c||r===c&&s>=f)||(e=u,n=p,o=d,c=r,f=s)}}if(!e||!n)return;e.points=n}}function Ce(t,e){const n=20,o=[];for(const h of e.values()){if(h.isGroup||h.isEdgeLabel)continue;const t=h.x??0,e=h.y??0,n=gt(h);n&&o.push({id:String(h.id??""),cx:t,cy:e,rect:n})}if(0===o.length)return;const r=new Map(o.map(t=>[t.id,t])),s=o.map(t=>({id:t.id,rect:t.rect})),i=["top","bottom","left","right"],a={top:Math.min(...o.map(t=>t.rect.top))-n,bottom:Math.max(...o.map(t=>t.rect.bottom))+n,left:Math.min(...o.map(t=>t.rect.left))-n,right:Math.max(...o.map(t=>t.rect.right))+n},c=t.filter(t=>!t.isLayoutOnly),f=new Map(c.map((t,e)=>[t,e])),d=h(t=>{const e="left"===t||"top"===t?-1:1,o=[];for(let r=0;r<=2;r++)o.push(a[t]+e*n*r);return o},"outwardTracksForSide"),l=h((t,e=new Map)=>it(e.get(t)??t.points??[]),"replacementPointsFor"),u=h((t,e)=>{let n=0;for(const o of t)for(const t of e)Ct(o.a,o.b,t.a,t.b,pe)&&n++;return n},"crossingCountBetweenSegments"),g=h((t,e)=>u(xe(t),xe(e)),"crossingCountBetweenPaths"),p=h((t=new Map)=>{let e=0;const n=[],o=new Set,r=[],s=h(t=>{o.has(t)||(o.add(t),r.push(t))},"addEdge");for(let i=0;i<c.length;i++){const o=c[i],r=l(o,t);for(let a=i+1;a<c.length;a++){const i=c[a],f=g(r,l(i,t));f>0&&(e+=f,n.push({first:o,second:i,count:f}),s(o),s(i))}}return r.sort((t,e)=>(f.get(t)??0)-(f.get(e)??0)),{count:e,pairs:n,edgeSet:o,edges:r}},"crossingSnapshot"),x=h((t,e)=>{const n=new Set(e.keys());if(0===n.size)return t.count;let o=0;for(const s of t.pairs)(n.has(s.first)||n.has(s.second))&&(o+=s.count);let r=0;for(let s=0;s<c.length;s++){const t=c[s],o=n.has(t),i=l(t,e);for(let a=s+1;a<c.length;a++){const t=c[a];(o||n.has(t))&&(r+=g(i,l(t,e)))}}return t.count-o+r},"crossingCountWithReplacements"),m=h(t=>{const e=new Map;for(const r of t.pairs){const t=e.get(r.first)??new Set;t.add(r.second),e.set(r.first,t);const n=e.get(r.second)??new Set;n.add(r.first),e.set(r.second,n)}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)=>(f.get(t)??0)-(f.get(e)??0)),s.length>1&&n.push(s)}return n},"crossingComponents"),y=h(t=>[t.start,t.end].filter(t=>Boolean(t)),"endpointIdsFor"),b=h(t=>{const e=[];for(const n of m(t)){const t=new Set(n),o=new Set(n.flatMap(t=>y(t))),r=[...n];for(const e of c)t.has(e)||y(e).some(t=>o.has(t))&&r.push(e);r.sort((t,e)=>(f.get(t)??0)-(f.get(e)??0)),e.push(r)}return e},"pairSearchGroups"),M=h((t,e,n)=>x(t,new Map([[e,n]])),"crossingCountWithSingleReplacement"),I=h(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"),S=h(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"),w=h((t=new Map)=>c.reduce((e,n)=>e+st(l(n,t)),0),"totalBends"),v=h((t=new Map)=>c.reduce((e,n)=>e+S(l(n,t)),0),"totalLength"),L=h((t,e,n=new Map)=>{const o=xe(e);for(const r of c)if(r!==t)for(const t of o)for(const e of xe(l(r,n)))if(ot(t,e,.5)>=8)return!0;return!1},"pathHasSegmentConflict"),C=h((t,e)=>{const n=[t.start,t.end].filter(t=>Boolean(t));for(const o of xe(e))if(St(o.a,o.b,s,n,-2))return!0;return!1},"pathHitsNode"),k=h((t,e)=>{const n=Rt(it(e));xe(n).length===n.length-1&&t.push(n)},"pushOrthogonalCandidate"),T=h(t=>"left"===t||"right"===t,"sideIsHorizontal"),O=h((t,e,o)=>{switch(e){case"left":return Math.min(t.x,o.x)-n;case"right":return Math.max(t.x,o.x)+n;case"top":return Math.min(t.y,o.y)-n;case"bottom":return Math.max(t.y,o.y)+n}},"localTrackForSameSide"),$=h((t,e,o,r)=>{const s="left"===o||"top"===o?-1:1,i=[O(e,o,r),a[o]];for(const a of i)for(let i=0;i<=2;i++)k(t,mt(e,o,r,a+s*n*i))},"addSameSideCandidates"),R=h((t,e,n,o,r)=>{for(const s of d(n))for(const n of d(r))k(t,[e,{x:s,y:e.y},{x:s,y:n},{x:o.x,y:n},o])},"addHorizontalToVerticalCandidates"),N=h((t,e,n,o,r)=>{for(const s of d(n))for(const n of d(r))k(t,[e,{x:e.x,y:s},{x:n,y:s},{x:n,y:o.y},o])},"addVerticalToHorizontalCandidates"),B=h((t,e,n,o,r)=>{const s=[...d("top"),...d("bottom")];for(const i of d(n))for(const n of d(r))for(const r of s)k(t,[e,{x:i,y:e.y},{x:i,y:r},{x:n,y:r},{x:n,y:o.y},o])},"addHorizontalPairCandidates"),E=h((t,e,n,o,r)=>{const s=[...d("left"),...d("right")];for(const i of d(n))for(const n of d(r))for(const r of s)k(t,[e,{x:e.x,y:i},{x:r,y:i},{x:r,y:n},{x:o.x,y:n},o])},"addVerticalPairCandidates"),F=h(t=>{const e=new Set;return t.map(t=>it(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"),Y=h((t,e,o,r)=>{const s=[],i=xt(t,e,o,r,n,pe);i&&k(s,i),e===r&&$(s,t,e,o);const a=T(e),c=T(r);return a&&!c?R(s,t,e,o,r):!a&&c?N(s,t,e,o,r):a?B(s,t,e,o,r):E(s,t,e,o,r),F(s)},"buildCandidatesForSides"),X=h((t,e,n,o)=>{const r=[...d("left"),...d("right")],s=[...d("top"),...d("bottom")];for(const a of i){const i=pt(o,a),c="top"===a||"bottom"===a?d(a):s;for(const o of r){k(t,[e,n,{x:o,y:n.y},{x:o,y:i.y},i]);for(const r of c)k(t,[e,n,{x:o,y:n.y},{x:o,y:r},{x:i.x,y:r},i])}}},"addVerticalDepartureOuterTrackCandidates"),z=h((t,e,n,o)=>{const r=[...d("left"),...d("right")],s=[...d("top"),...d("bottom")];for(const a of i){const i=pt(o,a),c="left"===a||"right"===a?d(a):r;for(const o of s){k(t,[e,n,{x:n.x,y:o},{x:i.x,y:o},i]);for(const r of c)k(t,[e,n,{x:n.x,y:o},{x:r,y:o},{x:r,y:i.y},i])}}},"addHorizontalDepartureOuterTrackCandidates"),P=h(t=>{const e=t.start,n=t.end,o=n?r.get(n):void 0;if(!e||!o)return[];const s=it(t.points??[]);if(s.length<4)return[];const i=s[0],a=s[1],c=[];return et(i,a,pe)?X(c,i,a,o):tt(i,a,pe)&&z(c,i,a,o),c},"terminalPreservingOuterTrackCandidates"),A=h(t=>{const e=t.start,n=t.end,o=e?r.get(e):void 0,s=n?r.get(n):void 0;if(!o||!s)return[];const a=[];for(const r of i){const t=pt(o,r);for(const e of i)a.push(...Y(t,r,pt(s,e),e))}return a.push(...P(t)),a},"candidatePathsFor"),G=h(()=>new Map(c.map(t=>[t,xe(l(t))])),"currentSegmentsByEdge"),D=h((t,e,n)=>{const o=new Set;for(const r of c){if(r===t)continue;const s=n.get(r)??xe(l(r));e.some(t=>s.some(e=>ot(t,e,.5)>=8))&&o.add(r)}return o},"sharedTrackConflictsFor"),j=h((t,e,n,o)=>{const r=new Set;return A(t).map(t=>Rt(it(t))).filter(e=>{if(C(t,e))return!1;const n=e.map(t=>`${t.x.toFixed(3)},${t.y.toFixed(3)}`).join("|");return!(r.has(n)||e.length<2||(r.add(n),0))}).map(r=>{const s=xe(r);let i=0;for(const e of c)e!==t&&(i+=u(s,n.get(e)??xe(l(e))));return{candidate:r,candidateSegments:s,crossings:e.count-(o.get(t)??0)+i,bends:st(r,pe),totalBends:st(r),length:S(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:D(t,e.candidateSegments,n),totalBends:e.totalBends,length:e.length}))},"pairCandidatesFor"),H=h((t,e,n,o,r,s)=>{let i=0;for(const c of t.pairs)c.first!==e&&c.second!==e&&c.first!==o&&c.second!==o||(i+=c.count);let a=u(n.segments,r.segments);for(const f of c){if(f===e||f===o)continue;const t=s.get(f)??xe(l(f));a+=u(n.segments,t)+u(r.segments,t)}return t.count-i+a},"pairCrossingCount"),_=h((t,e)=>{for(const n of t.sharedTrackConflicts)if(n!==e)return!1;return!0},"conflictsOnlyWith"),V=h((t,e)=>t.segments.some(t=>e.segments.some(e=>ot(t,e,.5)>=8)),"candidatesShareTrack"),W=h((t,e,n,o)=>_(e,n.edge)&&_(o,t.edge)&&!V(e,o),"pairCandidatesAreCompatible"),q=h((t,e,n,o,r)=>{const s=H(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"),J=h((t,e)=>t.crossings<e.crossings||t.crossings===e.crossings&&(t.bends<e.bends||t.bends===e.bends&&t.length<e.length),"pairScoreIsBetter"),K=h((t,e,n,o)=>{let r=o;for(const s of e.candidates)for(const o of n.candidates){if(!W(e,s,n,o))continue;const i=q(t,e,s,n,o);i&&J(i,r)&&(r=i)}return r},"bestScoreForOptionPair"),Q=h(t=>{const e=w(),n=v(),o=G(),r=I(t),s=new Map(c.map(t=>[t,st(l(t))])),i=new Map(c.map(t=>[t,S(l(t))])),a=new Map,f=b(t);for(const c of f)for(const e of c){if(a.has(e))continue;const n=j(e,t,o,r);n.length>0&&a.set(e,{edge:e,candidates:n})}let d={replacements:new Map,crossings:t.count,bends:e,length:n};const u={current:t,currentBends:e,currentLength:n,baseBendsByEdge:s,baseLengthByEdge:i,baseSegments:o};for(const c of f){const e=new Set(c.filter(e=>t.edgeSet.has(e))),n=c.map(t=>a.get(t)).filter(t=>Boolean(t));for(let t=0;t<n.length;t++){const o=n[t];for(let r=t+1;r<n.length;r++){const t=n[r];(e.has(o.edge)||e.has(t.edge))&&(d=K(u,o,t,d))}}}return d.replacements.size>0?d.replacements:void 0},"bestPairedReplacement");for(let h=0;h<4;h++){const t=p(),e=t.count;if(0===e)return;let n,o,r=e,s=Number.POSITIVE_INFINITY;for(const a of t.edges){const i=st(l(a),pe);for(const c of A(a)){const f=C(a,c),d=!f&&L(a,c),l=M(t,a,c),u=st(c,pe);f||d||(l<e||l===e&&u<i)&&(l>r||l===r&&u>=s||(n=a,o=c,r=l,s=u))}}if(n&&o){n.points=o;continue}const i=Q(t);if(!i)return;for(const[a,c]of i)a.points=c}}h(ye,"separateSharedRenderedTerminalLanes"),h(be,"collapseRedundantRectangularDoglegs"),h(Me,"liftObstacleHuggingSameSideRails"),h(Ie,"liftTopLaneTitleBandsAboveRails"),h(Se,"shiftLeftLaneTitleBandsLeftOfRails"),h(we,"swapDestinationTerminalTailsToReduceCrossings"),h(ve,"reassignCrossingExternalRailChannels"),h(Le,"shortcutRedundantOrthogonalJogs"),h(Ce,"resolveRenderedOrthogonalCrossings");var ke=.001;function Te(t,e){const{nodeInfoById:n,realNodeRects:o}=yt(e),r=["top","bottom","left","right"],s={top:Math.min(...o.map(t=>t.rect.top))-20,bottom:Math.max(...o.map(t=>t.rect.bottom))+20,left:Math.min(...o.map(t=>t.rect.left))-20,right:Math.max(...o.map(t=>t.rect.right))+20},i=h((t,e,n,o)=>{const r=[],i=xt(t,e,n,o,20,ke);return i&&r.push(i),e===o&&r.push(mt(t,e,n,s[e])),r},"buildOrthogonalPathCandidates"),a=h((t,e)=>{for(let n=0;n<t.length-1;n++)if(St(t[n],t[n+1],o,e,1))return!0;return!1},"pathHitsNode"),c=h((e,n,o=!1)=>{let r=0;const s=rt(e,ke),i=n.start,a=n.end;for(const c of t){if(c===n||c.isLayoutOnly)continue;const t=c.start,e=c.end;if(!o&&i&&a&&(t===i||t===a||e===i||e===a))continue;const f=c.points;if(f&&!(f.length<2))for(const n of s)for(const t of rt(f,ke))(wt(n.a,n.b,t.a,t.b,ke,ke)||ot(n,t,ke)>=8)&&r++}return r},"pathConflictCount"),f=h((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"),d=new Map,l=h((t,e,n)=>{const o=d.get(t)??[];o.push({side:e,edgeId:n}),d.set(t,o)},"addFaceClaim");for(const h of t){if(h.isLayoutOnly)continue;const t=h.points??[];if(t.length<1)continue;const e=h.id??"",o=h.start,r=h.end;if(o){const r=n.get(o);r&&l(o,f(t[0],r),e)}if(r){const o=n.get(r);o&&l(r,f(t[t.length-1],o),e)}}const u=h((t,e,n)=>d.get(t)?.some(t=>t.edgeId!==n&&t.side===e)??!1,"faceIsClaimed");for(const h of t){if(h.isLayoutOnly)continue;const t=h.points;if(!t||t.length<2)continue;const e=st(t,ke);if(e<4)continue;const o=h.start,s=h.end;if(!o||!s)continue;const g=n.get(o),p=n.get(s);if(!g||!p)continue;const x=h.id??"",m=c(t,h,!0),y=c(t,h);let b,M=m,I=e;for(const n of r){if(u(o,n,x))continue;const t=pt(g,n);for(const e of r){if(u(s,e,x))continue;const r=pt(p,e);for(const f of i(t,n,r,e)){if(a(f,[o,s]))continue;const t=st(f,ke);if(m>0){const e=c(f,h,!0);if(e>M||e===M&&t>=I)continue;M=e,I=t,b=f;continue}c(f,h)>y||t<I&&(I=t,b=f)}}}if(b){h.points=b;const t=d.get(o);t&&d.set(o,t.filter(t=>t.edgeId!==x));const e=d.get(s);e&&d.set(s,e.filter(t=>t.edgeId!==x)),l(o,f(b[0],g),x),l(s,f(b[b.length-1],p),x)}}}h(Te,"simplifyDetouredEdges");var Oe=.001;function $e(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)<Oe)){if(Math.abs(a)<=Oe){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)<=Oe){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 Re(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 Ne(t,e){const n=it(e);return[$e(n,!0),$e(n,!1)].some(e=>e&<(t,Re(e)))}function Be(t,e){const n=[];for(const l of t){if(l.isLayoutOnly)continue;const t=l.points;if(t&&!(t.length<2))for(let e=0;e<t.length-1;e++)n.push({edgeId:l.id,p1:t[e],p2:t[e+1]})}const o=[],r=[];for(const l of e.values()){const t=l.isGroup,e=l.parentId;if(t&&!e){const t=gt(l);t&&r.push({id:l.id,rect:t});continue}if(t)continue;if(l.isEdgeLabel)continue;const n=gt(l);n&&o.push({nodeId:l.id,rect:n})}const s=h((t,e)=>{const n=ut(e,3);for(const{nodeId:r,rect:s}of o)if(r!==t&<(n,s))return!0;return!1},"labelOverlapsForeignNode"),i=h((t,e)=>{const o=ut(e,3);for(const r of n)if(r.edgeId!==t&&ct(r.p1,r.p2,o))return!0;return!1},"labelOverlapsForeignEdge"),a=h((t,e,n)=>s(t,n)||i(e,n),"labelOverlapsAnything"),c=[],f=h(t=>{for(const{id:e,rect:n}of r)if(dt(n,t))return e},"findContainingLane"),d=h((t,e)=>c.some(n=>n.labelId!==t&<(e,n.rect)),"overlapsPlacedLabel");for(const l of t){if(l.isLayoutOnly)continue;const t=l.labelNodeId;if(!t)continue;const n=e.get(t);if(!n)continue;const o=l.points;if(!o||o.length<2)continue;const u=n.width??0,g=n.height??0;if(u<=0||g<=0)continue;const p=[];for(let e=0;e<o.length-1;e++){const t=o[e],n=o[e+1],r=Math.abs(t.x-n.x),s=Math.abs(t.y-n.y);r<Oe&&s<Oe||r>=Oe&&s>=Oe||p.push({idx:e,length:r+s,orientation:r>=Oe?"horizontal":"vertical",midX:(t.x+n.x)/2,midY:(t.y+n.y)/2})}if(0===p.length)continue;const x=p.length>=3?p.filter(t=>t.idx>0&&t.idx<p.length-1):p,m=x.length>0?x:p,y=u>=g?"horizontal":"vertical",b=h(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?u:g)+2;return o!==e.length>=("horizontal"===e.orientation?u: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=h((t,e)=>{const n=o[t.idx],r=o[t.idx+1];return{midX:n.x+(r.x-n.x)*e,midY:n.y+(r.y-n.y)*e}},"anchorAtT"),v=h((t,e,n)=>Math.min(n,Math.max(e,t)),"clamp"),L=h((t,e)=>t.midX>=e.left-Oe&&t.midX<=e.right+Oe&&t.midY>=e.top-Oe&&t.midY<=e.bottom+Oe,"pointInsideRectInclusive"),C=h(t=>{const e=ht(t.midX,t.midY,u,g),n=f(e);if(n)return{laneId:n,anchor:t,rect:e};const o=r.find(({rect:e})=>L(t,e));if(!o)return;const s=o.rect.left+u/2+1,i=o.rect.right-u/2-1,a=o.rect.top+g/2+1,c=o.rect.bottom-g/2-1;if(s>i||a>c)return;const d={midX:v(t.midX,s,i),midY:v(t.midY,a,c)},l=ht(d.midX,d.midY,u,g);return L(t,l)?{laneId:o.id,anchor:d,rect:l}:void 0},"placementForAnchor"),k=h((t,e,n)=>"horizontal"===t.orientation?Math.abs(e.midX-n.x):Math.abs(e.midY-n.y),"distanceAlongSegment"),T=h((t,e)=>{const n=12+("horizontal"===t.orientation?u/2:g/2);if(t===M){const r=o[t.idx];if(k(t,e,r)+Oe<n)return!1}if(t===I){const r=o[t.idx+1];if(k(t,e,r)+Oe<n)return!1}return!0},"labelClearsTerminalEndpoints"),O=h(e=>{const n=b(e);for(const r of n)for(const e of S){const n=w(r,e);if(!T(r,n))continue;const s=C(n);if(s&&!Ne(s.rect,o)&&!d(t,s.rect)&&!a(t,l.id,s.rect))return{laneId:s.laneId,anchor:s.anchor}}},"tryPool"),$=h((e,n,r=!1)=>{const a=b(e);for(const c of a){const e={midX:c.midX,midY:c.midY};if(n&&!T(c,e))continue;const a=C(e);if(a&&!Ne(a.rect,o)&&!d(t,a.rect)&&!s(t,a.rect)&&(r||!i(l.id,a.rect)))return{laneId:a.laneId,anchor:a.anchor}}},"findLaneContainingFallback"),R=O(m)??(m.length<p.length?O(p):void 0)??$(p,!0)??$(p,!1)??$(p,!1,!0);if(R){n.x=R.anchor.midX,n.y=R.anchor.midY,n.parentId=R.laneId;const e=ht(R.anchor.midX,R.anchor.midY,u,g),o=c.findIndex(e=>e.labelId===t);o>=0?c[o]={labelId:t,rect:e}:c.push({labelId:t,rect:e})}}}h($e,"markerClearanceRectFor"),h(Re,"normalizeRect"),h(Ne,"labelOverlapsOwnMarker"),h(Be,"anchorLabelsToPolyline");var Ee=1e-6;function Fe(t,e){return t<e?`${t}::${e}`:`${e}::${t}`}function Ye(t,e){const{nodeInfoById:n,realNodeRects:o}=yt(e),r=new Map;for(const i of e){const t=i.id;i.isGroup||i.isEdgeLabel&&r.set(t,{w:i.width??0,h:i.height??0})}const s=h((e,n,o,s)=>{const i=Fe(n,o);let a=0;const c=h(t=>{if(!t)return;const e=r.get(t);if(!e)return;const n="x"===s?e.w/2:e.h/2;n>a&&(a=n)},"consider");c(e.labelNodeId);for(const r of t){if(r===e)continue;if(r.isLayoutOnly)continue;const t=r.start,n=r.end;t&&n&&Fe(t,n)===i&&c(r.labelNodeId)}return a>0?a+3:0},"labelClearanceFor");for(const i of t){if(i.isLayoutOnly)continue;if(!at(i.points,Ee))continue;const e=It(i,n,Ee);if(!e)continue;const{srcId:r,dstId:a,srcInfo:c,dstInfo:f,collinearX:d,collinearY:l}=e;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(St(u,h,o,[r,a],1))continue;const g=s(i,r,a,d?"x":"y"),p=g>4?g:4,x=[0,p,-p];for(const n of x){const e={...u},s={...h};if(d){if(e.x+=n,s.x+=n,e.x<=c.rect.left||e.x>=c.rect.right)continue;if(s.x<=f.rect.left||s.x>=f.rect.right)continue}else{if(e.y+=n,s.y+=n,e.y<=c.rect.top||e.y>=c.rect.bottom)continue;if(s.y<=f.rect.top||s.y>=f.rect.bottom)continue}if(!St(e,s,o,[r,a],1)&&!Lt(e,s,t,i,{epsilon:Ee})){i.points=[e,s];break}}}}function Xe(t,e){const n=.001,{realNodeRects:o,labelNodeRects:r}=bt(e.values()),s=h((t,e)=>rt(e,n).map(n=>({...n,edge:t,interior:n.index>=1&&n.index<=e.length-3})),"segmentsFor"),i=h(()=>{const e=[];for(const n of t){if(n.isLayoutOnly)continue;const t=n.points;!t||t.length<2||e.push(...s(n,it(t)))}return e},"allSegments"),a=h((t,e)=>t.horizontal&&e.horizontal?nt(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)&&nt(t.a.y,t.b.y,e.a.y,e.b.y)>=8&&Math.abs(t.a.x-e.a.x)<7,"hasCrowdedParallelTrack"),c=h((e,i)=>{const c=e.start,f=e.end,d=s(e,i);if(d.length!==i.length-1)return!1;const l=[c,f].filter(t=>Boolean(t)),u=e.labelNodeId?[e.labelNodeId]:[];for(const t of d){if(St(t.a,t.b,o,l,-2))return!1;if(St(t.a,t.b,r,u,-2))return!1}for(const o of t){if(o===e||o.isLayoutOnly)continue;const t=o.points;if(t&&!(t.length<2))for(const e of d)for(const r of s(o,it(t))){if(a(e,r))return!1;if(Ct(e.a,e.b,r.a,r.b,n))return!1}}return!0},"candidateIsSafe"),f=h((t,e)=>{const n=it(t.edge.points??[]);if(n.length<4||t.index>=n.length-1)return;const o=n.map(t=>({...t}));if(t.horizontal)o[t.index].y+=e,o[t.index+1].y+=e;else{if(!t.vertical)return;o[t.index].x+=e,o[t.index+1].x+=e}return s(t.edge,o).length===o.length-1?o:void 0},"shiftedCandidate"),d=h((t,e)=>({x:t.x??(e.left+e.right)/2,y:t.y??(e.top+e.bottom)/2}),"nodeCenter"),l=h(t=>{const n=t.edge,o=it(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?gt(r):void 0,a=s?gt(s):void 0,c=o.slice(t.index+2);return r&&s&&i&&a&&0!==c.length?{sourceCenter:d(r,i),targetCenter:d(s,a),sourceRect:i,tail:c}:void 0},"sourceDetourContextFor"),u=h((t,e,o,r,s,i)=>{const a=r.y>=o.y,c=a?s.bottom:s.top,f=c+(a?20:-20);if(a&&t.b.y<=f+n||!a&&t.b.y>=f-n)return;const d=t.a.x+e;return it([{x:o.x,y:c},{x:o.x,y:f},{x:d,y:f},{x:d,y:t.b.y},...i],n)},"verticalSourceDetour"),g=h((t,e,o,r,s,i)=>{const a=r.x>=o.x,c=a?s.right:s.left,f=c+(a?20:-20);if(a&&t.b.x<=f+n||!a&&t.b.x>=f-n)return;const d=t.a.y+e;return it([{x:c,y:o.y},{x:f,y:o.y},{x:f,y:d},{x:t.b.x,y:d},...i],n)},"horizontalSourceDetour"),p=h((t,e)=>{const n=l(t);if(n)return t.vertical?u(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"),x=[-7,7,-14,14,-21,21];for(let h=0;h<12;h++){const t=i();let e=!1;for(let n=0;n<t.length&&!e;n++)for(let o=n+1;o<t.length&&!e;o++){const r=t[n],s=t[o];if(r.edge===s.edge||!a(r,s))continue;const i=[r,s].filter(t=>t.interior);for(const t of i){for(const n of x){const o=f(t,n);if(o&&c(t.edge,o)){t.edge.points=o,e=!0;break}const r=p(t,n);if(r&&c(t.edge,r)){t.edge.points=r,e=!0;break}}if(e)break}}if(!e)return}}function ze(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;return l>.01&&l<.99&&u>.01&&u<.99}function Pe(t){const e=t.nodes??[],n=t.edges??[],o=[];if(!n.length||!e.length)return o;const r=Mt(e),s=[];for(const i of n){if(i.isLayoutOnly)continue;const t=i.points;if(!t||t.length<2)continue;const e=i.start,n=i.end,a=i.labelNodeId,c=i.id??`${e}->${n}`;for(const s of r)if(s.nodeId!==e&&s.nodeId!==n&&(!a||s.nodeId!==a))for(let e=0;e<t.length-1;e++)if(ct(t[e],t[e+1],s,-1)){o.push({type:"edge-node-overlap",edgeId:c,targetId:s.nodeId,detail:`segment ${e} passes through node "${s.nodeId}"`});break}for(let o=0;o<t.length-1;o++)s.push({edgeId:c,start:e,end:n,p1:t[o],p2:t[o+1]})}const a=new Set;for(let i=0;i<s.length;i++)for(let t=i+1;t<s.length;t++){const e=s[i],n=s[t];if(e.edgeId!==n.edgeId&&e.start!==n.start&&e.start!==n.end&&e.end!==n.start&&e.end!==n.end&&ze(e.p1,e.p2,n.p1,n.p2)){const t=e.edgeId<n.edgeId?`${e.edgeId}|${n.edgeId}`:`${n.edgeId}|${e.edgeId}`;a.has(t)||(a.add(t),o.push({type:"edge-edge-crossing",edgeId:e.edgeId,targetId:n.edgeId,detail:`edges "${e.edgeId}" and "${n.edgeId}" cross`}))}}if(o.length>0){const t=o.filter(t=>"edge-node-overlap"===t.type).length,e=o.filter(t=>"edge-edge-crossing"===t.type).length;i.warn(`[SWIMLANE_VALIDATE] ${o.length} issue(s) detected: ${t} edge-node overlap(s), ${e} edge crossing(s)`);for(const n of o)i.warn(`[SWIMLANE_VALIDATE] ${n.type}: ${n.detail}`)}return o}function Ae(t,e){const n=t.nodes??[],o=t.edges??[],r=n.filter(t=>!t.isGroup);if(("LR"===e||"RL"===e)&&r.length>0&&!de(t,e))return;if("BT"===e&&r.length>0&&!fe(t))return;for(const a of o){if(a.isLayoutOnly)continue;const t=a.points;!t||t.length<2||(a.points=Rt($t(t)))}Te(o,n),Ye(o,n),he(o,n);const s=new Map;for(const a of n)s.set(String(a.id),a);Be(o,s),Yt(o,s),ge(o,s),Xe(o,s),ye(o,s),be(o,s),Me(o,s),we(o,s);const i=h(()=>{Ce(o,s),ve(o,s),Le(o,s),Be(o,s),ee(o,s),Me(o,s),Be(o,s),ee(o,s)},"finalizeRenderedEdges");i(),Xe(o,s),i(),Ie(o,s),Se(o,s),Ie(o,s),Se(o,s)}function Ge(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 De(t,e){return t.edges.filter(t=>t.dst===e)}function je(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 He(t){const e=je(t);for(const n of e.values())n.sort((t,e)=>t.localeCompare(e));return e}function _e(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 Ve(t){return[...t.entries()].filter(([,t])=>0===t).map(([t])=>t).sort((t,e)=>t.localeCompare(e))}function We(t,e=()=>!0){const n=new Map,o=new Map;for(const r of t.nodes)n.set(r,[]),o.set(r,[]);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 qe(t,e,n,o){let r=0;for(const i of t.nodes)o?.skipGroups&&t.nodeById.get(i)?.isGroup||(r=Math.max(r,n[i]??0));const s=Array.from({length:r+1},()=>[]);for(const i of e)o?.skipGroups&&t.nodeById.get(i)?.isGroup||s[Math.max(0,n[i]??0)].push(i);return s}function Je(t){const e=_e(t),n=Ve(e),o=[],r=He(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 Ke(t){const e=new Map;let n=0;for(const o of t)e.set(o,n),n++;return e}function Qe(t){const e=new Array(t.length),n=h((o,r)=>{if(r-o<=1)return 0;const s=o+r>>1;let i=n(o,s)+n(s,r),a=o,c=s,f=o;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 n=o;n<r;n++)t[n]=e[n];return i},"count");return n(0,t.length)}function Ze(t){const e=Ge(t),n=new Map;for(const f of e.nodes)n.set(f,[]);for(const f of e.edges)n.get(f.src).push(f);for(const f of n.values())f.sort((t,e)=>t.dst===e.dst?t.id.localeCompare(e.id):t.dst.localeCompare(e.dst));const o=Object.create(null);for(const f of e.nodes)o[f]=0;const r=[],s=h(t=>{o[t]=1;for(const e of n.get(t)??[]){const t=e.dst;0===o[t]?s(t):1===o[t]&&r.push(e)}o[t]=2},"dfs"),i=[...e.nodes].sort((t,e)=>t.localeCompare(e));for(const f of i)0===o[f]&&s(f);const a=new Set(r.map(t=>`${t.id}:${t.src}->${t.dst}`)),c=e.edges.map(t=>a.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:c,layout:e.layout,nodeById:new Map(e.nodeById)},reversed:r}}function Ue(t){const e=new Map,n=h(o=>{if(e.has(o))return e.get(o);const r=t.nodeById.get(o);if(!r)return e.set(o,null),null;const s=r.parentId;if(!s)return e.set(o,null),null;const i=n(s)??s;return e.set(o,i),i},"resolve");for(const o of t.nodes)n(o);return e}function tn(t){const e=Ue(t);return t=>e.get(t)??null}function en(t){const e=[];for(const n of t.layout.nodes??[])n.isGroup&&!n.parentId&&e.push(n.id);return[...new Set(e)].reverse()}function nn(t,e){const n=en(t);if(!e||0===e.length)return n;const o=new Set(n),r=new Set,s=[];for(const i of e)o.has(i)&&!r.has(i)&&(r.add(i),s.push(i));for(const i of n)r.has(i)||s.push(i);return s}h(Fe,"pairKey"),h(Ye,"straightenCollinearSiblingDetours"),h(Xe,"nudgeSharedInteriorSubpaths"),h(ze,"segmentsIntersect"),h(Pe,"validateSwimlanesLayout"),h(Ae,"postProcessSwimlaneLayout"),h(Ge,"normalizeGraph"),h(De,"incoming"),h(je,"buildSuccessorMap"),h(He,"buildSortedSuccessorMap"),h(_e,"buildInDegreeMap"),h(Ve,"sortedZeroInDegreeNodes"),h(We,"buildPredecessorSuccessorMaps"),h(qe,"buildLayersFromRanks"),h(Je,"topoSortIfAcyclic"),h(Ke,"buildLayerIndex"),h(Qe,"countInversions"),h(Ze,"removeCycles_DFS"),h(Ue,"buildTopLaneMap"),h(tn,"createTopLaneResolver"),h(en,"buildTopLaneOrder"),h(nn,"resolveTopLaneOrder");var on=!0;function rn(t,e){const n=Ge(t),o=e?.laneOf??(()=>null),r=e?.rankHint,{preds:s}=We(n);for(const h of s.values())h.sort((t,e)=>t.localeCompare(e));const i=Je(n)??[...n.nodes].sort((t,e)=>t.localeCompare(e)),a=new Map;for(const[h,S]of i.entries())a.set(S,h);const c=new Map,f=new Map;for(const h of n.nodes)f.set(h,[]);for(const h of i){const t=(s.get(h)??[]).filter(t=>c.has(t));if(t.length>0){const e=sn(h,t,{laneOf:o,rankHint:r,topoIndex:a});c.set(h,e),f.get(e).push(h)}else c.has(h)||c.set(h,null)}for(const h of n.nodes)c.has(h)||c.set(h,null);const d=new Set;for(const h of n.nodes)null===(c.get(h)??null)&&d.add(h);const l=[...d].sort((t,e)=>{const n=a.get(t)??0,o=a.get(e)??0;return n===o?t.localeCompare(e):n-o}),u=an(n),g=new Map;for(const[h,S]of u.entries())g.set(h,[...S].sort((t,e)=>t.localeCompare(e)));const p=cn(g),x=fn(g),m=new Map;for(const h of n.nodes)m.set(h,[]);for(const h of x)for(const t of h.nodes){const e=m.get(t);e?e.push(h.id):m.set(t,[h.id])}const y=[],b=[],M=new Set,I=h(t=>{if(!M.has(t)){M.add(t),y.push(t);for(const e of f.get(t)??[])I(e);b.push(t)}},"walk");for(const h of l)I(h);for(const h of i)I(h);return{parent:c,children:f,roots:l,componentOf:p,blocks:x,nodeBlocks:m,adjacency:g,preorder:y,postorder:b,topologicalOrder:i}}function sn(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 an(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 cn(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 fn(t){const e=new Map,n=new Map,o=[],r=[];let s=0;const i=h((a,c)=>{e.set(a,++s),n.set(a,s);for(const f of t.get(a)??[])f!==c&&(e.has(f)?(e.get(f)??0)<(e.get(a)??0)&&(o.push([a,f]),n.set(a,Math.min(n.get(a)??s,e.get(f)??s))):(o.push([a,f]),i(f,a),n.set(a,Math.min(n.get(a)??s,n.get(f)??s)),(n.get(f)??0)>=(e.get(a)??0)&&r.push(dn(a,f,o,r.length))))},"visit");for(const a of t.keys())e.has(a)||i(a,null);return r}function dn(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 ln(t,e,n){const o=[...t.nodes],r=new Map;for(const[h,b]of o.entries())r.set(b,h);const s=o.length,i=new Array(s).fill(-1),a=new Array(s).fill(0),c=[],f=new Set;for(const h of o){const t=n.parent.get(h)??null,e=r.get(h);null!=e&&null==t&&(i[e]=-1,a[e]=0,f.has(h)||(f.add(h),c.push(h)))}for(;c.length>0;){const t=c.shift(),e=r.get(t);if(null==e)continue;const o=n.children.get(t)??[];for(const n of o){if(f.has(n))continue;const t=r.get(n);null!=t&&(i[t]=e,a[t]=a[e]+1,f.add(n),c.push(n))}}for(const h of o){if(f.has(h))continue;const t=r.get(h);null!=t&&(i[t]=-1,a[t]=0,f.add(h))}const d=Math.max(1,Math.ceil(Math.log2(Math.max(1,s)))+1),l=Array.from({length:d},()=>new Array(s).fill(-1));for(let h=0;h<s;h++)l[0][h]=i[h];for(let h=1;h<d;h++)for(let t=0;t<s;t++){const e=l[h-1][t];l[h][t]=-1===e?-1:l[h-1][e]}const u=h((t,e)=>{if(-1===t||-1===e)return-1;a[t]<a[e]&&([t,e]=[e,t]);const n=a[t]-a[e];for(let o=0;o<d;o++)if(n>>o&1&&-1===(t=l[o][t]))return-1;if(t===e)return t;for(let o=d-1;o>=0;o--){const n=l[o][t],r=l[o][e];-1!==n&&-1!==r&&n!==r&&(t=n,e=r)}return l[0][t]},"lcaIndex"),g=Array.from({length:s},()=>new Map);for(const h of t.edges){let t=h.src,n=h.dst,o=e[t],s=e[n];if(null==o||null==s)continue;if(o>s&&([t,n]=[n,t],[o,s]=[s,o]),null==o||null==s||o===s)continue;const i=r.get(t),a=r.get(n);if(null==i||null==a)continue;const c=u(i,a);if(-1===c)continue;const f=g[c];for(let e=o;e<s;e++)f.set(e,(f.get(e)??0)+1)}const p=new Map,x=h((t,e)=>{if(0!==e.size)for(const[n,o]of e)t.set(n,(t.get(n)??0)+o)},"mergeInto"),m=new Set,y=h(t=>{const o=r.get(t);m.add(t);const s=null==o?void 0:g[o],i=s?new Map(s):new Map,a=n.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)}x(i,o)}return i},"dfs");for(const h of n.roots)m.has(h)||y(h);for(const h of o)m.has(h)||y(h);return p}function un(t,e,n){const o=new Map,r=h(t=>{let s=n[t]??0;const i=[...e.get(t)??[]];i.sort(hn(n));for(const e of i){r(e);const t=o.get(e);null!=t&&(s=Math.min(s,t))}o.set(t,s)},"annotate");for(const s of t)r(s);return o}function hn(t){return(e,n)=>{const o=t[e]??0,r=t[n]??0;return o===r?e.localeCompare(n):o-r}}function gn(t,e,n,o){let r=0;for(const c of e){const t=n[c]??0;t>r&&(r=t)}const s=Array.from({length:r+1},()=>[]),i=new Set,a=h(t=>{if(i.has(t))return;i.add(t);const e=n[t]??0;s[e]||(s[e]=[]),s[e].push(t);for(const n of o(t))a(n)},"emit");for(const c of t)a(c);for(const c of e)if(!i.has(c)){const t=n[c]??0;s[t]||(s[t]=[]),s[t].push(c),i.add(c)}return s}function pn(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 xn(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 mn(t,e,n){const o=rn(t,{rankHint:e,laneOf:n}),{children:r,roots:s}=o;for(const d of t.nodes)r.has(d)||r.set(d,[]);const i=ln(t,e,o),a=[...s].sort(hn(e)),c=xn(r,e,i,un(a,r,e));let f=gn(a,t.nodes,e,c);return f=pn(f),f}function yn(t,e,n){const o=new Set(t),r=new Set(e),s=Ke(e),i=[];for(const a of n)o.has(a.src)&&r.has(a.dst)&&i.push(s.get(a.dst));return Qe(i)}function bn(t,e,n){const o=[];for(const s of e){const t=n[s.src],e=n[s.dst];if(null==t||null==e||t===e)continue;let r=s.src,i=s.dst,a=t,c=e;t>e&&(r=s.dst,i=s.src,a=e,c=t);for(let n=a;n<c;n++)o.push({id:`${s.id}@${n}`,src:r,dst:i,ref:s.ref})}let r=0;for(let s=0;s+1<t.length;s++)r+=yn(t[s],t[s+1],o);return r}function Mn(t,e){const n={...e},{preds:o}=We(t),r=tn(t);let s=bn(mn(t,n,r),t.edges,n);for(let i=0;i<4;i++){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=bn(mn(t,n,r),t.edges,n);d<s?(s=d,e=!0):n[a]=f}if(!e)break}return n}function In(t,e){const n=tn(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 Sn(t,e){const n=Ge(t),o=Je(n)??[...n.nodes].sort(),r=e?.compactSingleInput??!1,s=tn(n);let i=Object.create(null);for(const a of o){const t=De(n,a),o=e?.ignoreCrossLaneEdges?t.filter(t=>{const e=s(t.src),n=s(a);return!e||!n||e===n}):t;if(0===o.length)i[a]=0;else if(r&&1===o.length){const t=o[0].src,e=s(t),n=s(a);i[a]=e!==n?i[t]??0:(i[t]??0)+1}else{let t=-1/0;for(const e of o)t=Math.max(t,(i[e.src]??0)+1);i[a]=t===-1/0?0:t}}return e?.optimizeRanksByCrossings&&(i=Mn(n,i)),e?.ignoreCrossLaneEdges&&In(n,i),{layers:mn(n,i,s),rankOf:i,dummy:new Set}}function wn(t,e){const n=Ge(t),o={...Sn(n,{compactSingleInput:e?.compactSingleInput,ignoreCrossLaneEdges:e?.ignoreCrossLaneEdges,optimizeRanksByCrossings:e?.optimizeRanksByCrossings}).rankOf},r=tn(n),{preds:s,succs:i}=We(n,t=>{if(e?.ignoreCrossLaneEdges){const e=r(t.src),n=r(t.dst);if(e&&n&&e!==n)return!1}return!0}),a=Je(n)??[...n.nodes],c=[...a].reverse(),f=h((t,e)=>{let n=0;for(const i of s.get(t)??[])n=Math.max(n,(o[i]??0)+1);let r=Number.POSITIVE_INFINITY;const a=i.get(t)??[];return a.length>0&&(r=Math.min(...a.map(t=>(o[t]??0)-1))),Number.isFinite(r)||(r=Math.max(n,e)),Math.min(Math.max(e,n),r)},"clampFeasible"),d=h(t=>{let e=!1;for(const n of t){const t=s.get(n)??[],r=i.get(n)??[];if(0===t.length&&0===r.length)continue;const a=t.length>0?t.reduce((t,e)=>t+(o[e]??0)+1,0)/t.length:o[n]??0,c=r.length>0?r.reduce((t,e)=>t+(o[e]??0)-1,0)/r.length:o[n]??0,d=Math.round((a+c)/2),l=f(n,d);l!==o[n]&&(o[n]=l,e=!0)}return e},"relaxOrder");for(let l=0;l<8;l++){const t=d(a),e=d(c);if(!t&&!e)break}for(const l of a){let t=0;for(const e of s.get(l)??[])t=Math.max(t,(o[e]??0)+1);(o[l]??0)<t&&(o[l]=t)}for(const l of c){const t=i.get(l)??[];if(t.length>0){const e=Math.min(...t.map(t=>(o[t]??0)-1));(o[l]??0)>e&&(o[l]=e)}}return{layers:qe(n,a,o),rankOf:o,dummy:new Set}}function vn(t){const e=_e(t),n=He(t);let o=Ve(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 Ln(t,e){const n=Ge(t),o="LR"===e?.direction?vn(n)??[...n.nodes].sort():Je(n)??[...n.nodes].sort(),r=tn(n),s=h(t=>r(t)??t,"laneOf"),i=Object.create(null),a=new Map,c=h((t,n)=>e?.ignoreCrossLaneEdges??1?s(t)===s(n)?1:0:1,"edgeWeight");for(const f of o){const t=n.nodeById.get(f);if(t?.isGroup)continue;const e=De(n,f);let o=0;if(e.length>0)for(const n of e){const t=n.src,e=i[t]??0;o=Math.max(o,e+c(t,f))}const r=s(f),d=a.get(r)??0,l=Math.max(o,d);i[f]=l,a.set(r,l+1)}return{layers:qe(n,o,i,{skipGroups:!0}),rankOf:i,dummy:new Set}}function Cn(t,e){const n=Ge(e),{rankOf:o}=t,r=t.layers.map(t=>[...t]),s=new Set(t.dummy?[...t.dummy]:[]);let i=0;const a=new Map(n.nodeById),c=h(t=>{const e="placeholder-"+i++,n={id:e,isGroup:!1,isDummy:!0,width:0,height:0};for(a.set(e,n),s.add(e);r.length<=t;)r.push([]);return r[t].push(e),o[e]=t,e},"addDummyAt"),f=[...n.edges].sort((t,e)=>t.id===e.id?t.src===e.src?t.dst.localeCompare(e.dst):t.src.localeCompare(e.src):t.id.localeCompare(e.id)),d=[];for(const u of f){const t=o[u.src]??0,e=o[u.dst]??0;if(e-t<=1){d.push(u);continue}let n=u.src;for(let o=t+1,s=0;o<e;o++,s++){const t=c(o);d.push({id:`${u.id}#${s}`,src:n,dst:t,weight:u.weight,ref:u.ref}),n=t}const r=e-t-2;d.push({id:`${u.id}#${Math.max(r+1,0)}`,src:n,dst:u.dst,weight:u.weight,ref:u.ref})}const l={nodes:[...n.nodes,...[...s].filter(t=>!n.nodes.includes(t))],edges:d,layout:n.layout,nodeById:a};return{layering:{layers:r,rankOf:o,dummy:s},graphWithDummies:l}}function kn(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 Tn(t){return 0===t.length?Number.POSITIVE_INFINITY:t.reduce((t,e)=>t+e,0)/t.length}function On(t,e,n,o){const r=new Map;for(const s of t)r.set(s,[]);for(const s of n)"down"===o?e.has(s.src)&&r.has(s.dst)&&r.get(s.dst).push(e.get(s.src)):e.has(s.dst)&&r.has(s.src)&&r.get(s.src).push(e.get(s.dst));return r}function $n(t,e,n){const o=n.get(t)??0,r=n.get(e)??0;return o!==r?o-r:t.localeCompare(e)}function Rn(t,e,n){const o=new Set(t),r=new Set(e),s=Ke(t),i=Ke(e),a=[];for(const c of n)o.has(c.src)&&r.has(c.dst)&&a.push({u:s.get(c.src),v:i.get(c.dst)});return a.sort((t,e)=>t.u===e.u?t.v-e.v:t.u-e.u),Qe(a.map(t=>t.v))}function Nn(t,e,n){return[...t].sort((t,o)=>{const r=kn(e.get(t)??[]),s=kn(e.get(o)??[]);return r===s?$n(t,o,n):isFinite(r)?isFinite(s)?r-s:-1:1})}function Bn(t,e,n,o,r,s){const i=Ke(t),a=Ke(e),c=On(e,i,n,o);if(!r||!s||0===s.length)return Nn(e,c,a);const f=new Map;for(const u of e){const t=r(u),e=f.get(t)??[];e.push(u),f.set(t,e)}const d=[];for(const u of s){const t=f.get(u);if(!t||0===t.length)continue;const e=Nn(t,c,a);d.push(...e)}const l=f.get(null);if(l&&l.length>0){const t=Nn(l,c,a);for(const e of t){const t=Tn(c.get(e)??[]);let n=d.length;if(isFinite(t))for(const[e,o]of d.entries())if(t<Tn(c.get(o)??[])){n=e;break}d.splice(n,0,e)}}return d}function En(t,e,n,o,r){const s=[...e],i=new Set(t),a=new Set(e),c=o?new Set(o):null,f=n.filter(t=>i.has(t.src)&&a.has(t.dst)),d=c?n.filter(t=>a.has(t.src)&&c.has(t.dst)):void 0,l=h(e=>{let n=Rn(t,e,f);return d&&o&&(n+=Rn(e,o,d)),n},"crossingScore"),u=r?new Map:null;if(r&&u)for(const h of e)u.set(h,r(h));let g=!0,p=l(s);for(;g;){g=!1;for(let t=0;t+1<s.length;t++){if(u&&u.get(s[t])!==u.get(s[t+1]))continue;const e=p;[s[t],s[t+1]]=[s[t+1],s[t]];const n=l(s);n<e?(p=n,g=!0):[s[t],s[t+1]]=[s[t+1],s[t]]}}return s}function Fn(t,e,n){const o=t.layers.map(t=>[...t]),r=e.edges,s=tn(e),i=nn(e,n?.laneOrder);for(let a=0;a<3;a++){for(let t=1;t<o.length;t++)o[t]=Bn(o[t-1],o[t],r,"down",s,i),o[t]=En(o[t-1],o[t],r,o[t+1],s);for(let t=o.length-2;t>=0;t--)o[t]=Bn(o[t+1],o[t],r,"up",s,i),o[t]=En(o[t+1],o[t],r,o[t-1],s)}return{layers:o}}function Yn(t,e,n){const o=n?.layerGap??100,r=n?.nodeGap??40,s=n?.laneGap??2*r,i=n?.direction??"TB",a="LR"===i||"RL"===i,c=t.layers,f=Object.create(null),d=Object.create(null),l=h(t=>e.nodeById.get(t),"getNode"),u=h(t=>l(t)?.width??0,"getWidth"),g=h(t=>l(t)?.height??0,"getHeight"),p=tn(e),x=nn(e,n?.laneOrder),m=c.map(t=>t.reduce((t,e)=>Math.max(t,g(e)),0)),y=[];if(a)for(let h=0;h+1<c.length;h++){const t=c[h].reduce((t,e)=>Math.max(t,u(e)),0),e=c[h+1].reduce((t,e)=>Math.max(t,u(e)),0),n=m[h]/2+m[h+1]/2,r=(t+e)/2,s=Math.max(0,r-n-o);y.push(s)}const b=new Set;for(const h of c)for(const t of h)b.add(p(t));const M=b.has(null),I=x.filter(t=>b.has(t)),S=[...M?[null]:[],...I],w=Object.create(null);for(const h of I)w[h]=0;M&&(w.null=0);for(const h of c){const t=Object.create(null),e=[];for(const n of h){const o=p(n);null===o?e.push(n):(t[o]||=[]).push(n)}for(const[n,o]of Object.entries(t)){const t=o.reduce((t,e)=>t+u(e),0)+r*Math.max(0,o.length-1);w[n]=Math.max(w[n]??0,t)}if(M&&e.length){const t=e.reduce((t,e)=>t+u(e),0)+r*Math.max(0,e.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)+s*Math.max(0,S.length-1))/2;for(let n=0;n<S.length;n++){const o=S[n],r=t[n]??0,i=e+r/2;v.set(o,i),e+=r,n<S.length-1&&(e+=s)}}let L=0;for(const[h,k]of c.entries()){const t=m[h]??0,e=new Map;for(const n of k){const t=p(n),o=e.get(t)??[];o.push(n),e.set(t,o)}for(const n of S){const o=e.get(n)??[];if(0===o.length)continue;const s=v.get(n);if(1===o.length){const e=o[0];f[e]=s,d[e]=L+t/2}else{const e=o.map(t=>u(t));let n=s-(e.reduce((t,e)=>t+e,0)+r*(o.length-1))/2;for(const[s,i]of o.entries()){const o=e[s];f[i]=n+o/2,d[i]=L+t/2,n+=o+r}}}L+=t+o+(y[h]??0)}const C=new Map;for(const h of e.edges){const t=h.ref.id;C.has(t)||C.set(t,[]),C.get(t).push(h)}for(const[,h]of C){if(0===h.length)continue;const t=h[0].ref,n=t.start,o=t.end;if(null==n||null==o)continue;const r=Math.round(((f[n]??0)+(f[o]??0))/2),s=new Set;for(const e of h)s.add(e.src),s.add(e.dst);for(const i of s){if(i===n||i===o)continue;const t=e.nodeById.get(i);t?.isDummy&&(f[i]=r)}}return{x:f,y:d}}function Xn(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 zn(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 Pn(t,e){const n=[...t],o=zn(e);for(let r=n.length-1;r>0;r--){const t=Math.floor(o()*(r+1));[n[r],n[t]]=[n[t],n[r]]}return n}function An(t,e){let n=0;for(const[o,r]of t.entries())n+=Math.abs(o-(e.get(r)??o));return n}function Gn(t,e){const n=new Map;for(const[r,s]of t.entries())n.set(s,r);let o=0;for(const{a:r,b:s,weight:i}of e){const t=n.get(r),e=n.get(s);null!=t&&null!=e&&(o+=i*Math.abs(t-e))}return o}function Dn(t){const e=en(t);if(e.length<2)return[];const n=new Map(e.map((t,e)=>[t,e])),o=tn(t),r=new Map;for(const s of t.layout.edges??[]){if(s.isLayoutOnly)continue;const e="string"==typeof s.start?s.start:void 0,i="string"==typeof s.end?s.end:void 0;if(!(e&&i&&t.nodeById.has(e)&&t.nodeById.has(i)))continue;const a=o(e),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 jn(t,e,n){const o=[...t];let r=Gn(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=Gn(o,e);n<r?(r=n,s=!0):[o[t],o[t+1]]=[o[t+1],o[t]]}}return{order:o,cost:r,sourceDistance:An(o,n)}}function Hn(t,e){return t.cost!==e.cost?t.cost<e.cost:t.sourceDistance<e.sourceDistance}function _n(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 Xn(`${t.join("|")}#${o}#${n}`)}function Vn(t,e={}){const n=en(t);if(n.length<2)return n;const o=Dn(t);if(0===o.length)return n;const r=new Map(n.map((t,e)=>[t,e]));let s=jn(n,o,r);const i=Math.max(0,e.restarts??8);for(let a=0;a<i;a++){const t=jn(Pn(n,_n(n,o,a)),o,r);Hn(t,s)&&(s=t)}return s.order}function Wn(t,e){const n=e?.ignoreCrossLaneEdges??!0,o=e?.optimizeRanksByCrossings??!0,r=Ge(t),s=e?.automaticLaneOrdering?Vn(r,{restarts:8}):void 0,i=Ze(r),a=i.acyclic,c=n?Ln(a,{compactSingleInput:e?.compactSingleInput??on,ignoreCrossLaneEdges:!0,direction:e?.direction}):wn(a,{compactSingleInput:e?.compactSingleInput??on,ignoreCrossLaneEdges:!1,optimizeRanksByCrossings:o}),{layering:f,graphWithDummies:d}=Cn(c,a),l=Fn(f,d,{laneOrder:s}),u=Yn(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}}h(rn,"buildDrivingTree"),h(sn,"chooseParent"),h(an,"buildAdjacency"),h(cn,"assignComponents"),h(fn,"computeBlocks"),h(dn,"popBlock"),h(ln,"computeSubtreeCrossCounts"),h(un,"annotateMinimumLayers"),h(hn,"compareByRankThenId"),h(gn,"emitNodesInTreeOrder"),h(pn,"deduplicateLayers"),h(xn,"createChildOrderer"),h(mn,"buildMultitreeLayerOrder"),h(yn,"countCrossingsBetweenAdjacent"),h(bn,"totalCrossings"),h(Mn,"optimizeRanksByCrossings"),h(In,"adjustCrossLaneSources"),h(Sn,"assignLayers_LongestPath"),h(wn,"assignLayers_Gravity"),h(vn,"topoSortByGenerationIfAcyclic"),h(Ln,"assignLayers_LaneAwareCompact"),h(Cn,"makeProperLayering"),h(kn,"median"),h(Tn,"barycenter"),h(On,"neighborPositionsFor"),h($n,"currentOrderTieBreak"),h(Rn,"countCrossingsBetweenAdjacent"),h(Nn,"sortByHeuristic"),h(Bn,"reorderLayer"),h(En,"transposeImprove"),h(Fn,"orderLayers"),h(Yn,"assignCoordinates"),h(Xn,"hashString"),h(zn,"mulberry32"),h(Pn,"deterministicShuffle"),h(An,"sourceDistance"),h(Gn,"laneArrangementCost"),h(Dn,"buildWeightedLaneEdges"),h(jn,"greedySwitch"),h(Hn,"isBetterCandidate"),h(_n,"seedForRestart"),h(Vn,"optimizeTopLaneOrder"),h(Wn,"sugiyamaLayout");var qn=1e-6,Jn=15,Kn=15,Qn=20;function Zn(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);return a<qn&&c<qn?n:c>qn&&3*c>=a?i>0?"bottom":"top":a>qn?s>0?"right":"left":n}function Un(t,e){return Math.abs(t.to-e.from)<qn||Math.abs(t.to-e.to)<qn?t.to:t.from}function to(t,e){return"vertical"===t.orient?{x:t.coord,y:e}:{x:e,y:t.coord}}function eo(t,e){const n=t.nodes??[],o=t.edges??[],r=[];for(const h of o)h.isLayoutOnly||r.push({...h,__originalEdge:h});const s=new Map,i=new Map,a=[],c="LR"===e;for(const h of n)s.set(h.id,h);const f=n.filter(t=>t.isGroup&&!t.parentId);for(const nt of f){const t={id:nt.id},e=h(o=>{i.set(o.id,t),n.filter(t=>t.parentId===o.id).forEach(e)},"assignLane");e(nt)}const d=n.filter(t=>!t.isGroup&&!t.isEdgeLabel).map(t=>{const e=t.width??10,n=t.height??10,o=t.x??0,r=t.y??0;return{nodeId:t.id,minX:o-e/2-8,maxX:o+e/2+8,minY:r-n/2-8,maxY:r+n/2+8,visualXHalfExtent:c?n/2+8:e/2+8}}),l=h((t,e,n,o)=>{let r=a.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:[]},a.push(r)),r.spanMin=Math.min(r.spanMin,n),r.spanMax=Math.max(r.spanMax,o),r},"getOrAddPipe"),u=h((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=h((t,e,n)=>u(t,Zn(t,e,n?"bottom":"top")),"getOrthogonalPort"),p=[],x=[],m=new Set,y=h((t,e,n)=>{if(0===p.length)return 0;const o=Math.abs(e.y-n.y)<qn,r=Math.abs(e.x-n.x)<qn;if(!o&&!r)return 0;let s=0;if(o){const o=e.y,r=Math.min(e.x,n.x)-qn,i=Math.max(e.x,n.x)+qn;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-qn<=o&&e.to+qn>=o&&(s+=1e3))}else if(r){const o=e.x,r=Math.min(e.y,n.y)-qn,i=Math.max(e.y,n.y)+qn;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-qn<=o&&e.to+qn>=o&&(s+=1e3))}return s},"crossingPenalty"),b=r.map((t,e)=>{if(!t.start||!t.end)return{idx:e,crossLane:0,dx:0,dy:0};const n=s.get(t.start),o=s.get(t.end),r=i.get(t.start),a=i.get(t.end);return{idx:e,crossLane:r&&a&&r.id!==a.id?1:0,dx:n&&o?Math.abs((o.x??0)-(n.x??0)):0,dy:n&&o?Math.abs((o.y??0)-(n.y??0)):0}}).sort((t,e)=>{if(t.crossLane!==e.crossLane)return e.crossLane-t.crossLane;const n=t.dx+t.dy,o=e.dx+e.dy;return Math.abs(n-o)>1?n-o:t.idx-e.idx}).map(t=>t.idx),M=h((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!!d.find(c=>!(n&&c.nodeId===n||o&&c.nodeId===o||!(Math.abs(t.x-e.x)>qn?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 h of r)h.start&&h.end&&h.start!==h.end&&(S.set(h.start,(S.get(h.start)??0)+1),S.set(h.end,(S.get(h.end)??0)+1));const w=h((t,e)=>Zn(t,e,"bottom"),"determineSide"),v=new Map;for(const[h,nt]of r.entries()){if(!nt.start||!nt.end||nt.start===nt.end)continue;if(nt.points&&nt.points.length>0)continue;const t=s.get(nt.start),e=s.get(nt.end);if(!t||!e)continue;const n=(e.x??0)-(t.x??0),o=(e.y??0)-(t.y??0);v.set(h,{edgeIdx:h,srcId:nt.start,dstId:nt.end,srcSide:w(t,{x:e.x??0,y:e.y??0}),dstSide:w(e,{x:t.x??0,y:t.y??0}),absDx:Math.abs(n),absDy:Math.abs(o),dxSign:Math.sign(n),dySign:Math.sign(o)})}const L=h(t=>"top"===t.srcSide||"bottom"===t.srcSide?0===t.absDx?1/0:t.absDy/t.absDx:0===t.absDy?1/0:t.absDx/t.absDy,"preferenceStrength"),C=h(t=>"top"===t.srcSide||"bottom"===t.srcSide?t.dxSign>=0?"right":"left":t.dySign>=0?"bottom":"top","secondarySide"),k=new Map;for(const h of v.values()){const t=`${h.srcId}:${h.srcSide}`;k.has(t)||k.set(t,[]),k.get(t).push(h)}const T=new Map,O=h((t,e)=>`${t}:${e}`,"loadKey");for(const h of v.values())T.set(O(h.srcId,h.srcSide),(T.get(O(h.srcId,h.srcSide))??0)+1),T.set(O(h.dstId,h.dstSide),(T.get(O(h.dstId,h.dstSide))??0)+1);for(const h of k.values())if(!(h.length<2)){h.sort((t,e)=>{const n=L(t),o=L(e);return Math.abs(n-o)>1e-9?o-n:t.edgeIdx-e.edgeIdx});for(let t=1;t<h.length;t++){const e=h[t],n=C(e),o=T.get(O(e.srcId,e.srcSide))??0,r=T.get(O(e.srcId,n))??0;r>=o||(T.set(O(e.srcId,e.srcSide),o-1),T.set(O(e.srcId,n),r+1),e.srcSide=n)}}const $=h(t=>{const e=t?.shape;return"question"===e||"diamond"===e},"isDiamondNode"),R=new Map;for(const h of v.values())R.has(h.dstId)||R.set(h.dstId,new Set),R.get(h.dstId).add(h.dstSide);for(const h of v.values()){if(!$(s.get(h.srcId)))continue;const t=R.get(h.srcId);if(!t?.has(h.srcSide))continue;const e=C(h);if(t.has(e)||(T.get(O(h.srcId,e))??0)>0)continue;const n=T.get(O(h.srcId,h.srcSide))??0;T.set(O(h.srcId,h.srcSide),Math.max(0,n-1)),T.set(O(h.srcId,e),1),h.srcSide=e}for(const h of v.values()){const{edgeIdx:t,srcId:e,dstId:n,srcSide:o,dstSide:r}=h,i=s.get(e),a=s.get(n),c=`${e}:${o}:src`,f="top"===o||"bottom"===o?a.x??0:a.y??0;I.has(c)||I.set(c,[]),I.get(c).push({edgeIdx:t,oppositeCoord:f});const d=`${n}:${r}:dst`,l="top"===r||"bottom"===r?i.x??0:i.y??0;I.has(d)||I.set(d,[]),I.get(d).push({edgeIdx:t,oppositeCoord:l})}const N=new Map;for(const[h,nt]of I){if(nt.length<2)continue;nt.sort((t,e)=>t.oppositeCoord-e.oppositeCoord);const t=h.split(":"),e=t.slice(0,-2).join(":"),n=t[t.length-2],o=t[t.length-1],r=s.get(e);if(!r)continue;const i="left"===n||"right"===n?r.height??10:r.width??10,a=r.shape,c="question"===a||"diamond"===a?.3*i:i,f=20,d=Math.min(f,Math.max(8,c/(nt.length+1))),l=-d*(nt.length-1)/2;for(const[s,u]of nt.entries()){const t=l+s*d,e=`${u.edgeIdx}:${o}`;N.set(e,t)}}const B=h(t=>Boolean(r[t]?.labelNodeId),"edgeHasLabelNode"),E=h((t,e)=>!!t&&((I.get(`${t}:${e}:src`)??[]).some(({edgeIdx:t})=>B(t))||(I.get(`${t}:${e}:dst`)??[]).some(({edgeIdx:t})=>B(t))),"faceHasLabelNode"),F=h((t,e,n)=>"top"===e||"bottom"===e?{x:t.x+n,y:t.y}:{x:t.x,y:t.y+n},"applyPortOffset"),Y=h((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?u(e,o.srcSide):g(e,r,!0),f=o?u(n,o.dstSide):g(n,s,!1);const d=N.get(`${t}:src`),l=N.get(`${t}:dst`);return void 0!==d&&(c=F(c,i,d)),void 0!==l&&(f=F(f,a,l)),{pSrcPort:c,pDstPort:f,srcSide:i,dstSide:a}},"portsForEdge");for(const nt of b){const t=r[nt];if(x[nt]=[],!t.start||!t.end)continue;if(t.points&&t.points.length>0)continue;if(t.start===t.end)continue;const e=s.get(t.start),n=s.get(t.end);if(!e||!n)continue;const{pSrcPort:o,pDstPort:i,srcSide:f,dstSide:u}=Y(nt,e,n),g={...o},b={...i},w="top"===f||"bottom"===f,v="top"===u||"bottom"===u;if(w){const t=o.y>(e.y??0);g.y=t?o.y+Qn:o.y-Qn}else{const t=o.x>(e.x??0);g.x=t?o.x+Qn:o.x-Qn}if(v){const t=i.y>(n.y??0);b.y=t?i.y+Qn:i.y-Qn}else{const t=i.x>(n.x??0);b.x=t?i.x+Qn:i.x-Qn}const L=h((t,e)=>{for(const n of d)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"),C=h((t,e,n,o,r)=>{if(r){const r=t.y>(e.y??0);return{x:(n.x??0)>=t.x?o.maxX+Jn:o.minX-Jn,y:r?o.maxY+Kn:o.minY-Kn,leavesPositiveSide:r}}const s=t.x>(e.x??0),i=(n.y??0)>=t.y;return{x:s?o.maxX+Jn:o.minX-Jn,y:i?o.maxY+Kn:o.minY-Kn,leavesPositiveSide:s}},"obstacleDetour");let k=[];const T=[t.start,t.end],O=L(g,T);if(O.inside&&O.obstacle){const t=O.obstacle;if(w){const r=C(o,e,n,t,!0);g.x=r.x,g.y=r.y;const s=r.leavesPositiveSide?Math.min(t.minY-2,o.y+Qn):Math.max(t.maxY+2,o.y-Qn);k=[{x:o.x,y:s},{x:r.x,y:s},{x:r.x,y:r.y}]}else{const r=C(o,e,n,t,!1),s=r.leavesPositiveSide?Math.min(t.minX-2,o.x+Qn):Math.max(t.maxX+2,o.x-Qn);g.x=r.x,g.y=r.y,k=[{x:s,y:o.y},{x:s,y:r.y},{x:r.x,y:r.y}]}}let $=[];const R=L(b,T);if(R.inside&&R.obstacle){const t=R.obstacle;if(v){const o=C(i,n,e,t,!0);b.x=o.x,b.y=o.y,$=[{x:o.x,y:o.y},{x:i.x,y:o.y}]}else{const o=C(i,n,e,t,!1);b.x=o.x,b.y=o.y,$=[{x:o.x,y:o.y},{x:o.x,y:i.y}]}}if(0===k.length&&0===$.length){const e=Jn,n=Math.abs(g.x-b.x)<e,r=Math.abs(g.y-b.y)<e,s=void 0!==N.get(`${nt}:src`)||void 0!==N.get(`${nt}:dst`),a=(I.get(`${t.start??""}:${f}:src`)?.length??0)+(I.get(`${t.start??""}:${f}:dst`)?.length??0),c=(I.get(`${t.end??""}:${u}:src`)?.length??0)+(I.get(`${t.end??""}:${u}:dst`)?.length??0),d=a>1||c>1,l=S.get(t.start??"")??0,h=S.get(t.end??"")??0,x=a>1&&E(t.start,f)||c>1&&E(t.end,u);if((n||r)&&!s&&(!d||d&&!x&&(a<=1||l<=2)&&(c<=1||h<=2))&&!M(o,i,t.start,t.end)){t.points=[{...o},{...g},{...b},{...i}],m.add(nt);const e=r?"horizontal":"vertical",n=r?o.y:o.x,s=r?Math.min(o.x,i.x):Math.min(o.y,i.y),a=r?Math.max(o.x,i.x):Math.max(o.y,i.y),c={id:`fast-path-${e}-${n.toFixed(0)}-${nt}`,orientation:e,coord:n,spanMin:s,spanMax:a,tracks:[]};p.push({edgeIndex:nt,segmentIndex:0,orientation:e,pipe:c,trackIndex:0,from:s,to:a});continue}}const B=l("vertical",g.x,g.y,g.y);g.x=B.coord;const F=l("vertical",b.x,b.y,b.y);b.x=F.coord;let X=Math.min(g.x,b.x)-50,z=Math.max(g.x,b.x)+50,P=Math.min(g.y,b.y)-50,A=Math.max(g.y,b.y)+50;for(const r of d){const t=Math.min(g.x,b.x),e=Math.max(g.x,b.x),n=Math.min(g.y,b.y),o=Math.max(g.y,b.y);r.minX<e&&r.maxX>t&&r.minY<o&&r.maxY>n&&(X=Math.min(X,r.minX-25),z=Math.max(z,r.maxX+25),P=Math.min(P,r.minY-25),A=Math.max(A,r.maxY+25))}for(const r of d){if(r.maxX<X||r.minX>z||r.maxY<P||r.minY>A)continue;const t=Jn;l("horizontal",r.minY-t,X,z),l("horizontal",r.maxY+t,X,z);const e=Kn;l("vertical",r.minX-e,P,A),l("vertical",r.maxX+e,P,A)}l("horizontal",g.y,X,z),l("horizontal",b.y,X,z);const G=a.filter(t=>"horizontal"===t.orientation&&t.coord>=P&&t.coord<=A),D=a.filter(t=>"vertical"===t.orientation&&t.coord>=X&&t.coord<=z),j=h((t,e)=>`${t.toFixed(1)},${e.toFixed(1)}`,"getKey"),H=j(g.x,g.y),_=j(b.x,b.y),V=new Map,W=new Map,q=new Map,J=new Set,K=[];V.set(H,0),q.set(H,"n"),K.push({key:H,f:Math.hypot(b.x-g.x,b.y-g.y),pt:g}),J.add(H);let Q=[];const Z=h((e,n)=>M(e,n,t.start,t.end),"checkSegmentBlocked"),U={x:b.x,y:g.y},tt=Z(g,U),et=Z(U,b),ot=tt||et,rt={x:g.x,y:b.y},st=Z(g,rt),it=Z(rt,b);if(ot?st||it||(Q=Math.abs(g.x-b.x)<qn?[g,b]:[g,rt,b]):Q=Math.abs(g.y-b.y)<qn||Math.abs(g.x-b.x)<qn?[g,b]:[g,U,b],0===Q.length)for(;K.length>0;){K.sort((t,e)=>t.f-e.f);const e=K.shift();if(J.delete(e.key),e.key===_){let t=_,e=b;for(Q=[e];W.has(t);){const n=W.get(t);Q.unshift(n),e=n,t=j(n.x,n.y)}break}const n=e.pt.x,o=e.pt.y,r=D.sort((t,e)=>t.coord-e.coord),s=r.findIndex(t=>Math.abs(t.coord-n)<1),i=G.sort((t,e)=>t.coord-e.coord),a=i.findIndex(t=>Math.abs(t.coord-o)<1),c=[];s>0&&c.push({x:r[s-1].coord,y:o}),s>=0&&s<r.length-1&&c.push({x:r[s+1].coord,y:o}),a>0&&c.push({x:n,y:i[a-1].coord}),a>=0&&a<i.length-1&&c.push({x:n,y:i[a+1].coord});for(const f of c){const r=Math.min(n,f.x),s=Math.max(n,f.x),i=Math.min(o,f.y),a=Math.max(o,f.y);if(d.some(e=>e.nodeId!==t.start&&e.nodeId!==t.end&&(r!==s?e.minY<o&&e.maxY>o&&e.maxX>r&&e.minX<s:e.minX<n&&e.maxX>n&&e.maxY>i&&e.minY<a)))continue;const c=j(f.x,f.y),l=Math.abs(f.x-n)+Math.abs(f.y-o),u=y(nt,e.pt,f);let h=0;const p=b.x-g.x,x=b.y-g.y,m=f.x-n,M=f.y-o;(x>10&&M<-5||x<-10&&M>5)&&(h=100*Math.abs(M)),(p>10&&m<-5||p<-10&&m>5)&&(h+=50*Math.abs(m));let I=0;const S=q.get(e.key)??"n",w=Math.abs(m)>qn?"h":"v";"n"!==S&&S!==w&&(I=50);const v=l+u+h+I,L=(V.get(e.key)??1/0)+v,C=Math.abs(b.x-f.x)+Math.abs(b.y-f.y);if(L<(V.get(c)??1/0))if(W.set(c,e.pt),V.set(c,L),q.set(c,w),J.has(c)){const t=K.findIndex(t=>t.key===c);-1!==t&&(K[t].f=L+C)}else K.push({key:c,f:L+C,pt:f}),J.add(c)}}if(0===Q.length&&(Q=[g,{x:g.x,y:b.y},b]),Q.length>4){const t=Q[0],e=Q[Q.length-1];let n=Math.min(t.x,e.x),o=Math.max(t.x,e.x),r=Math.min(t.y,e.y),s=Math.max(t.y,e.y);for(const c of Q)n=Math.min(n,c.x),o=Math.max(o,c.x),r=Math.min(r,c.y),s=Math.max(s,c.y);const i=o>Math.max(t.x,e.x),a=n<Math.min(t.x,e.x);if(c){const r=Kn;if(i){const n=Math.max(t.x,e.x),s=Math.min(t.y,e.y),i=Math.max(t.y,e.y),a=d.filter(t=>t.minX<n&&t.maxX>n&&t.minY<i&&t.maxY>s);if(a.length>0){let n=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 o=e+t.visualXHalfExtent+r;n=Math.max(n,o)}isNaN(n)||(o=n)}}if(a){const o=d.filter(n=>n.minX<Math.min(t.x,e.x)+r&&n.minY<Math.max(t.y,e.y)&&n.maxY>Math.min(t.y,e.y));if(o.length>0){let s=Math.min(t.x,e.x);for(const t of o){const e=(t.minX+t.maxX)/2-t.visualXHalfExtent-r;s=Math.min(s,e)}n=s}}}const f=h(n=>{const o=e.y>t.y,r=d.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(c&&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-qn)return t}else{const t=Math.min(...s.map(t=>t.minY))-15;if(t>e.y+qn)return t}return e.y},"findBestReturnY"),l=h(n=>{const o=f(n),r={x:n,y:t.y},s={x:n,y:o},i={x:e.x,y:o},a=Z(t,r),c=Z(r,s),d=Z(s,i),l=o!==e.y&&Z(i,e);return a||c||d||l?null:Math.abs(o-e.y)<qn?[t,r,s,e]:[t,r,s,i,e]},"trySimplifyWithDetourX"),u=i&&!a?l(o):a&&!i?l(n):null;u&&(Q=u)}const at=[o,...k,...Q,...$.reverse(),i];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)<qn&&Math.abs(e.y-t.y)<qn,r=Math.abs(n.x-e.x)<qn&&Math.abs(e.x-t.x)<qn;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 r=1;r<at.length-1;r++){if(1===r){ct.push(at[r]);continue}const t=ct[ct.length-1],e=at[r],n=at[r+1];if(Math.abs(t.y-e.y)<qn&&Math.abs(e.y-n.y)<qn){if(e.x>t.x!=n.x>e.x){ct.push(e);continue}}else if(Math.abs(t.x-e.x)<qn&&Math.abs(e.x-n.x)<qn){if(e.y>t.y!=n.y>e.y){ct.push(e);continue}}else ct.push(e)}ct.push(at[at.length-1]);for(let r=0;r<ct.length-1;r++){const t=ct[r],e=ct[r+1],n=Math.abs(t.x-e.x)<qn?"vertical":"horizontal",o="vertical"===n?t.x:t.y,s="vertical"===n?Math.min(t.y,e.y):Math.min(t.x,e.x),i="vertical"===n?Math.max(t.y,e.y):Math.max(t.x,e.x),a=l(n,o,s,i),c={edgeIndex:nt,segmentIndex:r,orientation:n,pipe:a,trackIndex:0,from:s,to:i};p.push(c),x[nt].push(p.length-1),a.tracks[0]||(a.tracks[0]={index:0,coord:a.coord,segments:[]}),a.tracks[0].segments.push({edgeIndex:nt,segmentIndex:r,from:s,to:i})}}const X=h((t,e)=>t.from<e.to&&e.from<t.to,"segmentsOverlap"),z=h((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=h(t=>{const e=t.tracks.length;return t.tracks[e]={index:e,coord:t.coord,segments:[]},e},"createNewTrack"),A=h((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"),G=h((t,e)=>{const n=x[t.edgeIndex];for(const o of n){const n=p[o];n.pipe===t.pipe&&A(n,e)}},"moveSegmentChainToTrack"),D=h(t=>{const e=x[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"),j=h((t,e)=>{if(t.orientation===e.orientation)return!1;const n="horizontal"===t.orientation?t:e,o="horizontal"===t.orientation?e:t;return o.pipe.coord>n.from&&o.pipe.coord<n.to&&n.pipe.coord>o.from&&n.pipe.coord<o.to},"haveAnyCrossing"),H=h((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"),_=h((t,e)=>{if(t.trackIndex===e.trackIndex)return X(t,e);const n=D(t),o=D(e);return n.some(t=>o.some(e=>j(t,e)))},"segmentsConflict"),V=h((t,e,n)=>{if(z(t,e,t.pipe.tracks[t.trackIndex],e.pipe.tracks[e.trackIndex]))return;const o=H(t.pipe,e);n(e,-1!==o?o:P(t.pipe))},"resolveTrackConflict"),W=h(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,G))}return e},"resolveHandleConflicts"),q=new Map,J=h(t=>{if(q.has(t))return q.get(t);const e=x[t];if(0===e.length){const e={dest:0,deviation:0,base:0,delta:0};return q.set(t,e),e}const n=p[e[0]].pipe.coord;let o=n;for(let s=1;s<e.length;s++){const t=p[e[s]];if("horizontal"===t.orientation){const e=t.from,r=t.to;o=Math.abs(e-n)>Math.abs(r-n)?e:r;break}}const r={dest:o,deviation:Math.abs(o-n),base:n,delta:o-n};return q.set(t,r),r},"getDestInfo"),K=h(()=>{let t=0;const e=new Map;for(const[o,s]of r.entries())0!==x[o].length&&s.start&&(e.has(s.start)||e.set(s.start,[]),e.get(s.start).push(o));const n=h(t=>{const e=r[t];if(!e.start||!e.end)return 0;const n=s.get(e.start),o=s.get(e.end);if(!n||!o)return 0;const i=(o.x??0)-(n.x??0),a=(o.y??0)-(n.y??0);return Math.abs(i)+Math.abs(a)},"getEdgeDistance");for(const o of e.values()){o.sort((t,e)=>{const o=J(t),r=J(e);if(Math.abs(o.deviation-r.deviation)>1)return o.deviation-r.deviation;if(Math.abs(o.dest-r.dest)>1)return o.dest-r.dest;const s=n(t),i=n(e);if(Math.abs(s-i)>1)return i-s;const a=x[t].length,c=x[e].length;if(a!==c)return a-c;if(1===a){const n=x[t][0],o=x[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=o.map(t=>p[x[t][0]]);t+=W(e)}return t},"fixSourceHandleCrossings"),Q=h(()=>{let t=0;const e=new Map;for(const[n,o]of r.entries())0!==x[n].length&&o.end&&(e.has(o.end)||e.set(o.end,[]),e.get(o.end).push(n));for(const n of e.values()){n.sort((t,e)=>{const n=h(t=>{const e=x[t];if(e.length<2)return 0;const n=p[e[e.length-2]];return Math.abs(n.to-n.from)},"getDist"),o=n(t),r=n(e);return Math.abs(o-r)>.1?o-r:t-e});const e=n.map(t=>p[x[t][x[t].length-1]]);t+=W(e)}return t},"fixTargetHandleCrossings"),Z=h(()=>{let t=0;for(const e of a){const n=[];for(const t of e.tracks)for(const e of t.segments){const t=x[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,A))}}return t},"fixPipeCrossings");let U=0;for(;U<10;){let t=0;if(t+=K(),t+=Q(),t+=Z(),0===t)break;U++}const tt=new Map;for(const nt of a){const t=[];nt.tracks.forEach(e=>{e.segments.forEach(n=>{t.push({edgeIndex:n.edgeIndex,segmentIndex:n.segmentIndex,trackIndex:e.index,from:n.from,to:n.to})})}),t.sort((t,e)=>t.from-e.from);const e=[];if(t.length>0){let n=[t[0]],o=t[0].to;for(let r=1;r<t.length;r++){const s=t[r];s.from<o?(n.push(s),o=Math.max(o,s.to)):(e.push(n),n=[s],o=s.to)}e.push(n)}for(const n of e){const t=new Set;n.forEach(e=>t.add(e.trackIndex));const e=new Map;n.forEach(t=>{const n=J(t.edgeIndex);e.set(t.trackIndex,(e.get(t.trackIndex)??0)+n.delta)});const o=[...t].filter(t=>(e.get(t)??0)<-1),r=[...t].filter(t=>(e.get(t)??0)>1),s=[...t].filter(t=>Math.abs(e.get(t)??0)<=1);o.sort((t,n)=>(e.get(n)??0)-(e.get(t)??0)),r.sort((t,n)=>(e.get(t)??0)-(e.get(n)??0));const i=h((t,e)=>{n.filter(e=>e.trackIndex===t).forEach(t=>{const n=m.has(t.edgeIndex)?nt.coord:e;tt.set(`${t.edgeIndex}-${t.segmentIndex}`,n)})},"assignCoord");let a=0;for(const n of o)a++,i(n,nt.coord-10*a);if(0===s.length&&t.size>0){const n=[...t].sort((t,n)=>Math.abs(e.get(t)??0)-Math.abs(e.get(n)??0))[0],i=o.indexOf(n);-1!==i&&o.splice(i,1);const a=r.indexOf(n);-1!==a&&r.splice(a,1),s.push(n)}let c=0;for(const n of s){if(0===c)i(n,nt.coord);else{const t=c%2==1?1:-1,e=Math.ceil(c/2);i(n,nt.coord+t*e*10*.5)}c++}let f=0;for(const n of r)f++,i(n,nt.coord+10*f)}}for(const[h,nt]of r.entries()){const t=x[h]??[];if(0===t.length)continue;const e=[],n=s.get(nt.start),o=s.get(nt.end),{pSrcPort:r,pDstPort:i}=Y(h,n,o),a=t.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}});e.push(r);for(let s=0;s<a.length;s++){const t=a[s],n=e[e.length-1],o="vertical"===t.orient?n.y:n.x,r="vertical"===t.orient?n.x:n.y,i=a[s+1],c=s<a.length-1;if(Math.abs(r-t.coord)>qn&&e.push(to(t,o)),c&&i.orient===t.orient)if(Math.abs(t.coord-i.coord)>qn){const n="vertical"===t.orient?(o+i.from)/2:Un(t,i);e.push(to(t,n),to(i,n))}else 0!==s&&s!==a.length-2||e.push(to(t,Un(t,i)));else if(c)e.push(to(t,i.coord));else{const n=Math.abs(t.from-o)<Math.abs(t.to-o)?t.to:t.from;e.push(to(t,n))}}const c=e[e.length-1];(Math.abs(c.x-i.x)>qn||Math.abs(c.y-i.y)>qn)&&e.push(i);const f=[];e.length>0&&f.push(e[0]);for(let s=1;s<e.length;s++){const t=e[s],n=f[f.length-1];(Math.abs(t.x-n.x)>qn||Math.abs(t.y-n.y)>qn)&&f.push(t)}nt.points=f}for(const h of r){const t=h.__originalEdge;t&&h.points&&(t.points=h.points)}t.edges=(t.edges??[]).filter(t=>!t.isLayoutOnly);const et=h((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 h of t.edges){const t=h.points;if(!t||t.length<2)continue;const e=h.start,n=h.end,o=e?s.get(e):void 0,r=n?s.get(n):void 0;o&&(t[0]=et(t[0],o)),r&&(t[t.length-1]=et(t[t.length-1],r))}return t}function no(t){return t.direction??"TB"}function oo(t){const e=_(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=no(t),{ordered:c,coordinates:f}=Wn(e,{nodeGap:n,layerGap:o,ignoreCrossLaneEdges:r,optimizeRanksByCrossings:s,automaticLaneOrdering:i,direction:a});V(e,c,f,{nodeGap:n,layerGap:o});for(const d of t.edges??[])delete d.points;eo(t,a);for(const d of t.edges??[])d.curve&&"basis"!==d.curve||(d.curve="rounded");return Ae(t,a),Pe(t),a}async function ro(t,i){const a=i.select("g");n(a,t.markers,t.type,t.diagramId),o(),r(),s(),e(),H(t);const c=W(t);t.nodes=c.nodes,t.edges=c.edges;const{groups:f}=await I(a,t);oo(t),await P(t,f)}h(Zn,"chooseOrthogonalSide"),h(Un,"sharedLineEndpointCoord"),h(to,"pointOnLine"),h(eo,"routeEdgesOrthogonal"),h(no,"getSwimlaneDirection"),h(oo,"runSwimlaneLayoutCore"),h(ro,"render");export{ro as render};
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/sizeCapture-X5ZJPWSS-KnPlIyQA.js","assets/mermaid.core-CMBPtXgs.js","assets/index-C6NKSiG-.js","assets/index-Df0b_mNb.css","assets/RemoteLifeOSBlock-CzC-ut2z.js","assets/index-D5vqn_ed.js","assets/index-CvmmrrPC.js","assets/file-editor-index-C6CU7Fik.js","assets/App-D4fBMWn7.js","assets/App-DHnygrdE.css","assets/chevron-up-GZB6oy0t.js","assets/__vite-browser-external-2447137e-DYOQzEuf.js","assets/RemoteLifeOSBlock-D7P9Ftlh.css","assets/purify.es-BNLkGfTg.js","assets/marked.esm-BBjA1da9.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{_ as t}from"./index-C6NKSiG-.js";import{c as e}from"./chunk-RYQCIY6F-C3X0k4Wk.js";import{al as n,am as o,an as r,ao as s,l as i,c as a,af as c,ae as f,ag as d,as as l,au as u,_ as h,z as g,ar as p,av as x,y as m,aw as y,ax as b}from"./mermaid.core-CMBPtXgs.js";import{G as M}from"./graph-BD-RY4fR.js";import"./map-Dwt0FgOz.js";import"./isArrayLikeObject-C958pSF-.js";import"./_initCloneObject-BR1zWEqJ.js";import"./RemoteLifeOSBlock-CzC-ut2z.js";import"./index-D5vqn_ed.js";import"./index-CvmmrrPC.js";import"./file-editor-index-C6CU7Fik.js";import"./App-D4fBMWn7.js";import"./chevron-up-GZB6oy0t.js";import"./__vite-browser-external-2447137e-DYOQzEuf.js";import"./purify.es-BNLkGfTg.js";import"./marked.esm-BBjA1da9.js";async function I(e,n){const o=new M({multigraph:!0,compound:!0}),r=[...n.edges],s=a(),i=e.insert("g").attr("class","root"),f=i.insert("g").attr("class","clusters"),d=i.insert("g").attr("class","edges edgePath"),l=i.insert("g").attr("class","edgeLabels"),u=i.insert("g").attr("class","nodes"),h=new Map,g=null!=e.node();await Promise.all(n.nodes.map(async t=>{if(t.isGroup)o.setNode(t.id,{...t});else{if(g){const e=await c(u,t,{config:s,dir:t.dir}),n=e.node()?.getBBox()??{width:0,height:0};h.set(t.id,e),t.width=n.width,t.height=n.height}o.setNode(t.id,{...t})}}));for(const t of r)o.setEdge(t.start,t.end,{...t},t.id),n.edges.some(e=>e.id===t.id)||n.edges.push(t);if(globalThis.mermaidCaptureSizes){const{captureNodeSizes:o}=await t(async()=>{const{captureNodeSizes:t}=await import("./sizeCapture-X5ZJPWSS-KnPlIyQA.js");return{captureNodeSizes:t}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]));o(e,n)}return{graph:o,groups:{clusters:f,edgePaths:d,edgeLabels:l,nodes:u,rootGroups:i},nodeElements:h}}h(I,"createGraphWithElements");var S=1e-5,w=1e-6;function v(t){const e=[];for(let n=0;n<t.length-1;n++)e.push({a:t[n],b:t[n+1]});return e}function L(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(0===c)return null;const f=n.x-t.x,d=n.y-t.y,l=(f*a-d*i)/c,u=(f*s-d*r)/c;return l<=w||l>=.999999||u<=w||u>=.999999?null:{point:{x:t.x+l*r,y:t.y+l*s},tA:l,tB:u}}function C(t){return Math.abs(t.b.x-t.a.x)>=Math.abs(t.b.y-t.a.y)}function k(t){const e=[];for(let n=0;n<t.length;n++){const o=t[n],r=v(o.points);for(let s=n+1;s<t.length;s++){const n=t[s],i=v(n.points);for(const[t,s]of r.entries())for(const[r,a]of i.entries()){const i=L(s.a,s.b,a.a,a.b);if(!i)continue;const c=C(s);c!==C(a)&&c?e.push({jumpEdgeId:o.id,otherEdgeId:n.id,segIndex:t,t:i.tA,point:i.point}):e.push({jumpEdgeId:n.id,otherEdgeId:o.id,segIndex:r,t:i.tB,point:i.point})}}}return e}function T(t){const e=Math.round(1e3*t)/1e3;return Number.isInteger(e),`${e}`}function O(t){return`${T(t.x)},${T(t.y)}`}function $(t){const e=t.b.x-t.a.x,n=t.b.y-t.a.y;return Math.abs(e)>=Math.abs(n)?e>=0?1:0:n>=0?1:0}function R(t,e){if(t.length<2)return t.map(t=>({...t}));const n=t.map(t=>({...t})),o=e.arrowTypeStart&&b[e.arrowTypeStart];if(o){const e=t[0],r=t[1],s=Math.atan2(r.y-e.y,r.x-e.x);n[0].x=e.x+o*Math.cos(s),n[0].y=e.y+o*Math.sin(s)}const r=e.arrowTypeEnd&&b[e.arrowTypeEnd];if(r){const e=t.length,o=t[e-2],s=t[e-1],i=Math.atan2(s.y-o.y,s.x-o.x);n[e-1].x=s.x-r*Math.cos(i),n[e-1].y=s.y-r*Math.sin(i)}return n}function N(t,e,n,o,r){const s=t.point.x,i=t.point.y,a={x:s-e*t.r,y:i-n*t.r},c={x:s+e*t.r,y:i+n*t.r},f=[`L${O(a)}`];return"arc"===r?f.push(`A${T(t.r)},${T(t.r)} 0 0 ${o} ${O(c)}`):f.push(`M${O(c)}`),f}function B(t,e,n,o){const r=e.x-t.x,s=e.y-t.y,i=n.x-e.x,a=n.y-e.y,c=Math.hypot(r,s),f=Math.hypot(i,a);if(c<S||f<S)return null;const d=r/c,l=s/c,u=i/f,h=a/f,g=d*u+l*h,p=Math.max(-1,Math.min(1,g)),x=Math.acos(p);if(x<S||Math.abs(Math.PI-x)<S)return null;const m=Math.min(o/Math.sin(x/2),c/2,f/2);return{startX:e.x-d*m,startY:e.y-l*m,endX:e.x+u*m,endY:e.y+h*m,ctrlX:e.x,ctrlY:e.y,cutLen:m}}function E(t,e,n){const o=t.points;if(o.length<2)return"";const r=R(o,t),s="rounded"===t.curve,i=v(r),a=new Map;for(const f of e){const t=i[f.segIndex];if(!t)continue;const e=Math.hypot(t.b.x-t.a.x,t.b.y-t.a.y),o=a.get(f.segIndex)??[];o.push({t:f.t,point:f.point,d:f.t*e,r:n.jumpRadius}),a.set(f.segIndex,o)}const c=[`M${O(r[0])}`];for(let f=0;f<i.length;f++){const t=i[f],e=Math.hypot(t.b.x-t.a.x,t.b.y-t.a.y),o=0===e?0:(t.b.x-t.a.x)/e,d=0===e?0:(t.b.y-t.a.y)/e,l=$(t);let u=0;if(s&&f>0){const t=B(r[f-1],r[f],r[f+1]??r[f],5);t&&(u=t.cutLen)}let h=e,g=null;s&&f<i.length-1&&(g=B(r[f],r[f+1],r[f+2]??r[f+1],5),g&&(h=e-g.cutLen));const p=[...a.get(f)??[]].sort((t,e)=>t.t-e.t);for(const n of p)n.r=Math.min(n.r,n.d-u,h-n.d);for(let n=0;n<p.length-1;n++){const t=p[n+1].d-p[n].d;if(p[n].r+p[n+1].r>t){const e=t/2;p[n].r=Math.min(p[n].r,e),p[n+1].r=Math.min(p[n+1].r,e)}}for(const r of p)r.r<.001||c.push(...N(r,o,d,l,n.jumpStyle));s&&g?(c.push(`L${T(g.startX)},${T(g.startY)}`),c.push(`Q${T(g.ctrlX)},${T(g.ctrlY)} ${T(g.endX)},${T(g.endY)}`)):c.push(`L${O(t.b)}`)}return c.join(" ")}function F(t){return/^[\d\s+,.LMelm-]*$/.test(t)}function Y(t){return!t||"linear"===t||"rounded"===t||"step"===t||"stepBefore"===t||"stepAfter"===t}function X(t){if(!t)return null;try{const e="function"==typeof atob?atob(t):Buffer.from(t,"base64").toString(),n=JSON.parse(e);if(!Array.isArray(n))return null;const o=[];for(const t of n)t&&"number"==typeof t.x&&"number"==typeof t.y&&o.push({x:t.x,y:t.y});return o.length>=2?o:null}catch{return null}}function z(t,e,n){if(!n.enabled)return;const o=t.node();if(!o)return;const r=new Map;for(const f of e)r.set(f.id,f);const s=[],i=new Map;for(const f of e){const t="undefined"!=typeof CSS&&CSS.escape?CSS.escape(f.id):f.id,e=o.querySelector(`path[data-id="${t}"]`);if(!e)continue;i.set(f.id,e);const n=X(e.getAttribute("data-points"))??f.points;s.push({...f,points:n})}const a=k(s);if(0===a.length)return;const c=new Map;for(const f of a){const t=c.get(f.jumpEdgeId)??[];t.push(f),c.set(f.jumpEdgeId,t)}for(const f of s){const t=c.get(f.id);if(!t||0===t.length)continue;const e=r.get(f.id),o=e?.curve;if(void 0!==o&&!Y(o))continue;const s=i.get(f.id);if(!s)continue;if(void 0===o&&!F(s.getAttribute("d")??""))continue;const a=s.getAttribute("style")??"",d=/stroke-dasharray\s*:\s*0\s+([\d.]+)\s+[\d.]+\s+([\d.]+)/.exec(a),l=d?Number.parseFloat(d[1]):null,u=d?Number.parseFloat(d[2]):null,h=E(f,t,n);if(s.setAttribute("d",h),null!==l&&null!==u&&"function"==typeof s.getTotalLength){const t=s.getTotalLength(),e=`0 ${l} ${Math.max(0,t-l-u)} ${u}`,n=a.replace(/stroke-dasharray\s*:[^;]*;?/g,`stroke-dasharray: ${e};`).replace(/;\s*;+/g,";");s.setAttribute("style",n)}}}async function P(t,e){for(const r of t.nodes)r.isGroup?await f(e.clusters,r):d(r);const n=new Map;for(const r of t.nodes)r?.id&&n.set(r.id,r);for(const r of t.edges){const o=r.start?n.get(r.start)??{}:{},s=r.end?n.get(r.end)??{}:{},i=l(e.edgePaths,{...r},{},t.type,o,s,t.diagramId);r.label&&await u(e.rootGroups,r),r.label&&A(r,i)}const o=t.config?.swimlane?.lineHops;if(!1!==o){const n="gap"===o?"gap":"arc",r=t.edges.filter(t=>Array.isArray(t.points)&&t.points.length>=2).map(t=>({id:t.id,points:t.points,curve:t.curve,arrowTypeStart:t.arrowTypeStart,arrowTypeEnd:t.arrowTypeEnd}));z(e.edgePaths,r,{enabled:!0,jumpRadius:6,jumpStyle:n})}}function A(t,e){const n=e?.updatedPath??e?.originalPath,o=g(),{subGraphTitleTotalMargin:r}=p({flowchart:o.flowchart??{}});if(t.label){const o=x.get(t.id);let s=t.x,a=t.y;if(n){const o=m.calcLabelPosition(n);i.debug("Moving label "+t.label+" from (",s,",",a,") to (",o.x,",",o.y,") abc88"),e&&(s=o.x,a=o.y)}o.attr("transform",`translate(${s}, ${a+r/2})`)}if(t?.startLabelLeft){const e=y.get(t.id).startLeft;let o=t?.x,r=t?.y;if(n){const e=m.calcTerminalLabelPosition(t.arrowTypeStart?10:0,"start_left",n);o=e.x,r=e.y}e.attr("transform",`translate(${o}, ${r})`)}if(t.startLabelRight){const e=y.get(t.id).startRight;let o=t.x,r=t.y;if(n){const e=m.calcTerminalLabelPosition(t.arrowTypeStart?10:0,"start_right",n);o=e.x,r=e.y}e.attr("transform",`translate(${o}, ${r})`)}if(t.endLabelLeft){const e=y.get(t.id).endLeft;let o=t.x,r=t.y;if(n){const e=m.calcTerminalLabelPosition(t.arrowTypeEnd?10:0,"end_left",n);o=e.x,r=e.y}e.attr("transform",`translate(${o}, ${r})`)}if(t.endLabelRight){const e=y.get(t.id).endRight;let o=t.x,r=t.y;if(n){const e=m.calcTerminalLabelPosition(t.arrowTypeEnd?10:0,"end_right",n);o=e.x,r=e.y}e.attr("transform",`translate(${o}, ${r})`)}}h(v,"buildSegmentList"),h(L,"segmentIntersection"),h(C,"isHorizontalSeg"),h(k,"findEdgeIntersections"),h(T,"fmt"),h(O,"pointToString"),h($,"getArcSweepFlag"),h(R,"applyMarkerOffsets"),h(N,"emitJump"),h(B,"computeRoundedCorner"),h(E,"rewriteEdgePath"),h(F,"isStraightPath"),h(Y,"curveSupportsLineHops"),h(X,"decodeDataPoints"),h(z,"applyLineJumpsToSvg"),h(P,"adjustLayout"),h(A,"positionEdgeLabel");var G="__swimlane_default__";function D(t){return Math.max(t.padding??20,20)}function j(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 H(t){const e=t.direction,n=t.nodes??=[];for(const s of t.nodes??[])s.isGroup&&!s.parentId&&(s.shape="swimlane",e&&(s.direction=e));const o=n.filter(t=>!t.isGroup&&!t.parentId);if(0===o.length)return;let r=n.find(t=>t.id===G);r?r.isGroup&&(r.shape="swimlane",e&&(r.direction=e)):(r={id:G,label:"",isGroup:!0,shape:"swimlane",padding:20,...e?{direction:e}:{}},n.push(r));for(const s of o)s.parentId=G}function _(t){const e=new Map;for(const i of t.nodes??[])e.set(i.id,i);const n=[];for(const i of t.edges??[]){const t="string"==typeof i.start?i.start:void 0,e="string"==typeof i.end?i.end:void 0;t&&e&&(i.labelNodeId||n.push({id:i.id,src:t,dst:e,ref:i}))}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 V(t,e,n,o){const{layout:r}=t,s=t.nodeById,i=o?.layerGap??100,a=o?.nodeGap??40;let c=0;for(const u of e.layers){let t=0;for(const e of u){const o=s.get(e);if(!o){t++;continue}o.layer=c,o.order=t;const r=n.x[e]??t*a,f=n.y[e]??c*i;o.x=r,o.y=f,t++}c++}const f=r.nodes??[],d=new Map,l=[];for(const u of f){if(!u?.isGroup)continue;u.parentId||l.push(u);const t=f.filter(t=>t.parentId===u.id);let e=1/0,o=-1/0,r=1/0,s=-1/0;for(const i of t){const t=i.x??n.x[i.id],a=i.y??n.y[i.id],c=i.width??0,f=i.height??0;null!=t&&null!=a&&(e=Math.min(e,t-c/2),o=Math.max(o,t+c/2),r=Math.min(r,a-f/2),s=Math.max(s,a+f/2))}if(e===1/0||r===1/0)u.x=u.x??0,u.y=u.y??0,u.width=u.width??0,u.height=u.height??0;else{const t=u.padding??20,n=u.parentId?t:2*D(u),i=t,a=Math.max(0,o-e)+n,c=Math.max(0,s-r)+i,f=(e+o)/2,l=(r+s)/2;u.x=f,u.y=l,u.width=a,u.height=c,d.set(u.id,{minX:e,maxX:o,minY:r,maxY:s})}}if(l.length>0&&d.size>0){let t=1/0,e=-1/0,n=0;for(const o of l){const r=o.padding??20;r>n&&(n=r);const s=d.get(o.id);s&&(t=Math.min(t,s.minY),e=Math.max(e,s.maxY))}if(t!==1/0&&e!==-1/0){const o=36,r=Math.max(0,e-t)+2*Math.max(n,o),s=(t+e)/2;for(const e of l)e.y=s,e.height=r,e.swimlaneContentTop=t;const i=[...l].sort((t,e)=>(t.x??0)-(e.x??0)),a=[],c=[],f=[];for(const t of i){const e=d.get(t.id);if(!e)continue;const n=Math.max(0,e.maxX-e.minX)+2*D(t),o=(e.minX+e.maxX)/2;a.push(t.id),c.push(o),f.push(n)}const u=a.length;if(u>0){const t=new Map;if(1===u)t.set(a[0],f[0]);else{const e=[];for(let t=0;t<u-1;t++)e.push(c[t+1]-c[t]);const n=new Array(u);n[0]=0;for(let t=0;t<u-1;t++)n[t+1]=2*e[t]-n[t];let o=0,r=Number.POSITIVE_INFINITY;for(let t=0;t<u;t++){const e=f[t];t%2==0?o=Math.max(o,e-n[t]):r=Math.min(r,n[t]-e)}let s=o;s=o<=r?(o+r)/2:o;for(let i=0;i<u;i++){const e=n[i]+(i%2==0?s:-s),o=Math.max(f[i],e);t.set(a[i],o)}}for(const e of l){const n=t.get(e.id);null!=n&&(e.width=n),j(e)}}}}}function W(t){const e=[],n=[],o=new Map;for(const i of t.nodes)o.set(i.id,i);for(const a of t.edges){if(!a.label||0===a.label.length)continue;if(a.isLayoutOnly)continue;if(a.labelNodeId)continue;const t=a.start?o.get(a.start):void 0,r=a.end?o.get(a.end):void 0;if(!t||!r){i.warn("[EdgeLabelNodes]",`Edge ${a.id} has missing source or target node`);continue}const s=`edge-label-${a.start}-${a.end}-${a.id}`,c=t.parentId!==r.parentId?r.parentId:t.parentId,f={id:s,label:a.label,edgeStart:a.start??"",edgeEnd:a.end??"",shape:"labelRect",width:0,height:0,isEdgeLabel:!0,isDummy:!0,parentId:c,isGroup:!1,labelStyle:Array.isArray(a.labelStyle)?a.labelStyle[0]:a.labelStyle??"",...t.dir?{dir:t.dir}:{}};e.push(f),a.labelNodeId=s,a.label=void 0,a.text=void 0;const d={id:`${a.id}-to-label`,start:a.start,end:s,type:"normal",isLayoutOnly:!0},l={id:`${a.id}-from-label`,start:s,end:a.end,type:"normal",isLayoutOnly:!0};n.push(d,l)}const r=[...t.nodes,...e],s=[...t.edges,...n];return{...t,nodes:r,edges:s}}h(D,"topLaneHorizontalPadding"),h(j,"assignTopLaneTitleRect"),h(H,"prepareLayoutForSwimlanes"),h(_,"toGraphView"),h(V,"writeBackToLayoutData"),h(W,"createEdgeLabelNodes");var q=.001;function J(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:ht(e,n,o,r)}:void 0}function K(t){if(t.isGroup)return;const e=J(t);return e?{id:String(t.id??""),cx:e.cx,cy:e.cy,rect:e.rect}:void 0}function Q(t,e,n=q){return Math.abs(t.x-e.x)<n&&Math.abs(t.y-e.y)<n}function Z(t,e,n=q){return Math.abs(t.x-e.x)<n}function U(t,e,n=q){return Math.abs(t.y-e.y)<n}function tt(t,e,n=q){return U(t,e,n)&&Math.abs(t.x-e.x)>n}function et(t,e,n=q){return Z(t,e,n)&&Math.abs(t.y-e.y)>n}function nt(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 ot(t,e,n=q){return t.horizontal&&e.horizontal&&U(t.a,e.a,n)?nt(t.a.x,t.b.x,e.a.x,e.b.x):t.vertical&&e.vertical&&Z(t.a,e.a,n)?nt(t.a.y,t.b.y,e.a.y,e.b.y):0}function rt(t,e=q){const n=[];for(let o=0;o<t.length-1;o++){const r=t[o],s=t[o+1],i=tt(r,s,e),a=et(r,s,e);(i||a)&&n.push({index:o,a:r,b:s,horizontal:i,vertical:a})}return n}function st(t,e=q){const n=rt(t,e);let o=0;for(let r=1;r<n.length;r++)n[r-1].horizontal!==n[r].horizontal&&o++;return o}function it(t,e=q){const n=[];for(const o of t){const t=n.length>0?n[n.length-1]:void 0;t&&Q(t,o,e)||n.push({x:o.x,y:o.y})}return n}function at(t,e=q){if(!t||4!==t.length)return;const[n,o,r,s]=t;return tt(n,o,e)&&et(o,r,e)&&tt(r,s,e)?{kind:"HVH",p0:n,p1:o,p2:r,p3:s}:et(n,o,e)&&tt(o,r,e)&&et(r,s,e)?{kind:"VHV",p0:n,p1:o,p2:r,p3:s}:void 0}function ct(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 ft(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 dt(t,e){return t.left<=e.left&&t.right>=e.right&&t.top<=e.top&&t.bottom>=e.bottom}function lt(t,e){return t.left<e.right&&t.right>e.left&&t.top<e.bottom&&t.bottom>e.top}function ut(t,e){return{left:t.left-e,right:t.right+e,top:t.top-e,bottom:t.bottom+e}}function ht(t,e,n,o){return{left:t-n/2,right:t+n/2,top:e-o/2,bottom:e+o/2}}function gt(t){return J(t)?.rect}function pt(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 xt(t,e,n,o,r,s=q){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(U(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(U(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(Z(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(Z(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 mt(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 yt(t){const e=new Map,n=[];for(const o of t){if(o.isEdgeLabel)continue;const t=K(o);t&&(e.set(t.id,t),n.push({id:t.id,rect:t.rect}))}return{nodeInfoById:e,realNodeRects:n}}function bt(t){const e=[],n=[];for(const o of t){const t=K(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 Mt(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,...ht(t,r,s,i)})}return n}function It(t,e,n=q){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 St(t,e,n,o=[],r=0){for(const s of n)if(!o.includes(s.id)&&ct(t,e,s.rect,-r))return!0;return!1}function wt(t,e,n,o,r=q,s=1e-6){const i=U(t,e,r),a=Z(t,e,r),c=U(n,o,r),f=Z(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},u=d.a.y,h=Math.min(d.a.x,d.b.x),g=Math.max(d.a.x,d.b.x),p=l.a.x,x=Math.min(l.a.y,l.b.y),m=Math.max(l.a.y,l.b.y);if(p<h||p>g||u<x||u>m)return!1;const y=Math.abs(p-d.a.x)<s&&Math.abs(u-d.a.y)<s||Math.abs(p-d.b.x)<s&&Math.abs(u-d.b.y)<s,b=Math.abs(p-l.a.x)<s&&Math.abs(u-l.a.y)<s||Math.abs(p-l.b.x)<s&&Math.abs(u-l.b.y)<s;return!(y&&b)}function vt(t,e,n,o,r=q){const s=U(t,e,r),i=Z(t,e,r),a=U(n,o,r),c=Z(n,o,r);return i&&c&&Z(t,n,r)?nt(t.y,e.y,n.y,o.y)>r:!!(s&&a&&U(t,n,r))&&nt(t.x,e.x,n.x,o.x)>r}function Lt(t,e,n,o,{epsilon:r=q,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||!Q(i,a,r))&&(wt(t,e,i,a,r)||vt(t,e,i,a,r)))return!0}}return!1}function Ct(t,e,n,o,r=q){const s=U(t,e,r),i=Z(t,e,r),a=U(n,o,r),c=Z(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,u=Math.min(f.a.x,f.b.x),h=Math.max(f.a.x,f.b.x),g=d.a.x,p=Math.min(d.a.y,d.b.y),x=Math.max(d.a.y,d.b.y);return g>u+r&&g<h-r&&l>p+r&&l<x-r}function kt(t,e,n){const o=Math.min(e,n),r=Math.max(e,n);return t>o+q&&t<r-q}function Tt(t,e,n){return Z(t,e)&&Z(e,n)?kt(e.y,t.y,n.y):!(!U(t,e)||!U(e,n))&&kt(e.x,t.x,n.x)}function Ot(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(Q(r,i)){o++,e=!0;continue}if(Tt(r,s,i)){e=!0;continue}}n.push(s)}return{points:n,changed:e}}function $t(t){const e=[t[0]];for(let o=1;o<t.length;o++){const n=e[e.length-1],r=t[o];if(!Z(n,r)&&!U(n,r)){const t=e.length>=2?e[e.length-2]:void 0,o=t&&Z(t,n)?{x:n.x,y:r.y}:{x:r.x,y:n.y};e.push(o)}e.push(r)}const n=[];for(const o of e){const t=n[n.length-1];t&&Q(t,o)||n.push(o)}return n}function Rt(t){if(t.length<3)return t;let e=[...t];for(let n=0;n<32;n++){const t=Ot(e);if(e=t.points,!t.changed)break}return e}h(J,"measuredNodeRect"),h(K,"nodeBoundsInfoFor"),h(Q,"samePoint"),h(Z,"sameX"),h(U,"sameY"),h(tt,"isHorizontalSegment"),h(et,"isVerticalSegment"),h(nt,"overlapLength"),h(ot,"sameAxisSegmentOverlapLength"),h(rt,"orthogonalSegmentsForPoints"),h(st,"countOrthogonalBends"),h(it,"dedupeConsecutivePoints"),h(at,"classifyThreeSegmentRoute"),h(ct,"segmentBoundsOverlapRect"),h(ft,"pointInsideRect"),h(dt,"rectContainsRect"),h(lt,"rectsOverlap"),h(ut,"inflateRect"),h(ht,"rectFromCenterSize"),h(gt,"rectOfNodeBounds"),h(pt,"portForRectSide"),h(xt,"buildOrthogonalPortPath"),h(mt,"buildSameSideTrackPath"),h(yt,"collectRealNodeBounds"),h(bt,"collectNodeRectEntries"),h(Mt,"collectLayoutNodeRects"),h(It,"getNodePairGeometry"),h(St,"segmentHitsAnyRect"),h(wt,"orthogonalSegmentsCross"),h(vt,"sameAxisSegmentsOverlap"),h(Lt,"segmentConflictsWithAnyEdge"),h(Ct,"orthogonalSegmentsStrictlyCross"),h(kt,"strictlyBetween"),h(Tt,"isCollinearIntermediate"),h(Ot,"simplifyPolylineOnce"),h($t,"orthogonalizePolyline"),h(Rt,"simplifyPolyline");var Nt=.001;function Bt(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?gt(r):void 0,dstRect:s?gt(s):void 0}}function Et(t,e,n){if(U(t,e,Nt))return{x:t.x<n.left?n.left:n.right,y:t.y};if(Z(t,e,Nt)){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 Ft(t,e,n){const o=n?1:-1;let r=n?0:t.length-1;for(;r>=0&&r<t.length&&ft(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=Et(t[r],t[s],e);return n?[i,...t.slice(r)]:[...t.slice(0,r+1),i]}function Yt(t,e){for(const n of t){const t=Bt(n,e,2);if(!t)continue;let o=[...t.points];t.srcRect&&(o=Ft(o,t.srcRect,!0)),t.dstRect&&(o=Ft(o,t.dstRect,!1)),o=Rt($t(o)),o=Wt(o,t.srcRect,t.dstRect),t.edge.points=Rt($t(o))}}function Xt(t,e,n,o=!1){if(U(t,e,Nt)){if(e.y<n.top-Nt||e.y>n.bottom+Nt)return e;if(o){if(t.x<n.left-Nt)return{x:n.left,y:t.y};if(t.x>n.right+Nt)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(Z(t,e,Nt)){if(e.x<n.left-Nt||e.x>n.right+Nt)return e;if(o){if(t.y<n.top-Nt)return{x:t.x,y:n.top};if(t.y>n.bottom+Nt)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 zt(t,e,n){const o=t[e];for(let r=e+n;r>=0&&r<t.length;r+=n){const e=t[r];if(!Q(e,o,Nt))return e}return t[e+n]}function Pt(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 At(t,e,n){const{lo:o,hi:r}=Pt(e,n);return Math.min(r,Math.max(o,t))}function Gt(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 Dt(t,e){return"left"===e||"right"===e?Pt(t.top,t.bottom):Pt(t.left,t.right)}function jt(t,e,n){const o=t.y>=n.top-Nt&&t.y<=n.bottom+Nt,r=t.x>=n.left-Nt&&t.x<=n.right+Nt;if(U(t,e,Nt)&&o){if(Math.abs(t.x-n.left)<Nt)return"left";if(Math.abs(t.x-n.right)<Nt)return"right"}if(Z(t,e,Nt)&&r){if(Math.abs(t.y-n.top)<Nt)return"top";if(Math.abs(t.y-n.bottom)<Nt)return"bottom"}}function Ht(t){return"left"===t||"right"===t}function _t(t,e,n,o,r){const s=[],i=n?jt(t,e,n):void 0,a=o?jt(e,t,o):void 0;return n&&i&&Ht(i)===r&&s.push(Dt(n,i)),o&&a&&Ht(a)===r&&s.push(Dt(o,a)),s.length>0?Gt(s):void 0}function Vt(t,e,n,o,r){const s=_t(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)<Nt?void 0:r?[{x:t.x,y:a},{x:e.x,y:a}]:[{x:a,y:t.y},{x:a,y:e.y}]}function Wt(t,e,n){if(2!==t.length)return t;const[o,r]=t;return U(o,r,Nt)?Vt(o,r,e,n,!0)??t:Z(o,r,Nt)?Vt(o,r,e,n,!1)??t:t}function qt(t,e,n){return Ht(n)?{x:t.x,y:At(t.y,e.top,e.bottom)}:{x:At(t.x,e.left,e.right),y:t.y}}function Jt(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&&!U(e,o,Nt))break;if(!s&&!Z(e,o,Nt))break;s?i[a].y=r.y:i[a].x=r.x}return i}function Kt(t,e,n){if(t.length<2)return t;const o=n?0:t.length-1,r=n?1:-1,s=t[o],i=zt(t,o,r);if(!i)return t;const a=jt(s,i,e);if(!a)return t;const c=Ht(a),f=qt(s,e,a);return Q(s,f,Nt)?t:Jt(t,o,r,s,f,c)}function Qt(t,e,n){const o=Math.min(t.x,e.x)>=n.left-Nt&&Math.max(t.x,e.x)<=n.right+Nt,r=Math.min(t.y,e.y)>=n.top-Nt&&Math.max(t.y,e.y)<=n.bottom+Nt;return Math.abs(t.y-n.top)<Nt&&Math.abs(e.y-n.top)<Nt&&o?"top":Math.abs(t.y-n.bottom)<Nt&&Math.abs(e.y-n.bottom)<Nt&&o?"bottom":Math.abs(t.x-n.left)<Nt&&Math.abs(e.x-n.left)<Nt&&r?"left":Math.abs(t.x-n.right)<Nt&&Math.abs(e.x-n.right)<Nt&&r?"right":void 0}function Zt(t,e,n,o){switch(t){case"top":return Z(e,n,Nt)&&n.y<o.top-Nt;case"bottom":return Z(e,n,Nt)&&n.y>o.bottom+Nt;case"left":return U(e,n,Nt)&&n.x<o.left-Nt;case"right":return U(e,n,Nt)&&n.x>o.right+Nt}}function Ut(t,e,n){if(t.length<3)return t;if(n){const n=Qt(t[0],t[1],e);return n&&Zt(n,t[1],t[2],e)?t.slice(1):t}const o=t.length-1,r=Qt(t[o-1],t[o],e);return r&&Zt(r,t[o-1],t[o-2],e)?t.slice(0,o):t}function te(t,e,n){let o=t;if(e){const t=zt(o,0,1);if(t){const n=Xt(t,o[0],e);n!==o[0]&&(o=[n,...o.slice(1)])}o=Ut(o,e,!0)}if(n){const t=o.length-1,e=zt(o,t,-1);if(e){const r=Xt(e,o[t],n,!0);r!==o[t]&&(o=[...o.slice(0,t),r])}o=Ut(o,n,!1)}const r=Wt(o,e,n);return r!==o||2===o.length?r:(e&&(o=Kt(o,e,!0)),n&&(o=Kt(o,n,!1)),o)}function ee(t,e){for(const n of t){const t=Bt(n,e,2);if(!t)continue;const o=te(it(t.points,Nt),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 ne(t){return new Map(t.map(t=>[t.id,t]))}function oe(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 re(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 se(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 ie(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 ae(t){const e=ne(t),n=t.filter(t=>t.isGroup&&t.parentId).sort((t,n)=>re(n,e)-re(t,e));for(const o of n){const e=se(t.filter(t=>t.parentId===o.id));e&&ie(o,e)}}function ce(t,e){const n=t.nodes??[],o=t.edges??[],r=n.filter(t=>!t.isGroup);let s=1/0,i=-1/0;for(const c of r){const t=c[e];"number"==typeof t&&(s=Math.min(s,t),i=Math.max(i,t))}if(!Number.isFinite(s)||!Number.isFinite(i))return!1;const a=h(t=>s+i-t,"mirror");for(const c of n){const t=c[e];"number"==typeof t&&(c[e]=a(t));const n=c.groupTitleRect;n&&(c.groupTitleRect="x"===e?{...n,left:a(n.right),right:a(n.left)}:{...n,top:a(n.bottom),bottom:a(n.top)})}for(const c of o)for(const t of c.points??[])t[e]=a(t[e]);return!0}function fe(t){return!(t.nodes??[]).some(t=>!t.isGroup)||ce(t,"y")}function de(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 L of r){const t=L.x??0,e=L.y??0;t<s&&(s=t),e<i&&(i=e)}if(!Number.isFinite(s)||!Number.isFinite(i))return!1;const a=36;let c=0,f=0;for(const L of r)c+=L.width??0,f+=L.height??0;const d=c/r.length,l=f/r.length,u=l>0?Math.max(1,d/l):1;for(const L of r){const t=L.x??0,e=((L.y??0)-i)*u+a,n=t-s;L.x=e,L.y=n}for(const L of o)if(L.points)for(const t of L.points){const e=t.x,n=(t.y-i)*u+a,o=e-s;t.x=n,t.y=o}ae(n);const h=n.filter(t=>t.isGroup&&!t.parentId);if(0===h.length)return"RL"===e&&ce(t,"x"),!0;const g=ne(n),p=new Map;for(const L of n){if(L.isGroup)continue;const t=oe(L,g);if(!t)continue;const e=p.get(t)??[];e.push(L),p.set(t,e)}let x=0;for(const L of h){const t=L.padding??0;t>x&&(x=t)}const m=[];let y=1/0,b=-1/0;for(const L of h){const t=se(p.get(L.id)??[]);t&&(y=Math.min(y,t.minX),b=Math.max(b,t.maxX),m.push({lane:L,contentTop:t.minY,contentBottom:t.maxY,centerY:(t.minY+t.maxY)/2}))}if(y===1/0||b===-1/0)return!0;const M=Math.max(0,b-y)+2*Math.max(x,10),I=a+M,S=(y+b)/2-M/2-a,w=S+I/2,v=Math.max(x,a);m.sort((t,e)=>t.centerY-e.centerY);for(let L=0;L<m.length;L++){const t=m[L];let e,n;if(e=0===L?t.contentTop-v:(m[L-1].contentBottom+t.contentTop)/2,L===m.length-1)n=t.contentBottom+v;else{const e=m[L+1];n=(t.contentBottom+e.contentTop)/2}const o=Math.max(0,n-e),r=(e+n)/2;t.lane.x=w,t.lane.y=r,t.lane.width=I,t.lane.height=o,t.lane.swimlaneContentTop=t.contentTop,t.lane.groupTitleRect={left:S,right:S+a,top:e,bottom:n}}return"RL"===e&&ce(t,"x"),!0}h(Bt,"endpointContextFor"),h(Et,"segmentEnterPoint"),h(Ft,"clipEndpoint"),h(Yt,"clipEdgeEndpointsToNodeBoundaries"),h(Xt,"snapEndpointToBoundary"),h(zt,"firstDistinctAdjacent"),h(Pt,"cornerClearanceRange"),h(At,"clampToCornerClearance"),h(Gt,"intersectRanges"),h(Dt,"clearanceRangeForSide"),h(jt,"terminalSideForSegment"),h(Ht,"isHorizontalSide"),h(_t,"straightClearanceRange"),h(Vt,"clearStraightEndpointCornerAxis"),h(Wt,"clearStraightEndpointCornerConnections"),h(qt,"cornerClearedEndpoint"),h(Jt,"moveCollinearEndpointRun"),h(Kt,"clearEndpointCornerConnection"),h(Qt,"borderSideForSegment"),h(Zt,"leavesOutward"),h(Ut,"collapseOwnBorderStub"),h(te,"snapAndCollapseEndpoints"),h(ee,"prepareEdgeEndpointsForRenderer"),h(ne,"buildNodeMap"),h(oe,"resolveTopLevelGroupId"),h(re,"groupDepth"),h(se,"boundsForChildren"),h(ie,"applyGroupBounds"),h(ae,"recomputeNestedGroupBounds"),h(ce,"mirrorAxis"),h(fe,"applyBtDirectionTransform"),h(de,"applyLrDirectionTransform");var le=1e-6,ue=[0,8,-8,16,-16];function he(t,e){const{nodeInfoById:n,realNodeRects:o}=yt(e);for(const r of t){if(r.isLayoutOnly)continue;const e=r.points;if(!e||e.length<4)continue;const s=at(it(e,le),le);if(!s)continue;const{p3:i}=s,a="HVH"===s.kind,c=It(r,n,le);if(!c)continue;const{srcId:f,dstId:d,srcInfo:l,dstInfo:u,collinearX:h,collinearY:g}=c;if(h||g)continue;let p;const x=l.rect;for(const n of ue){let e,s,c;if(a){const t=u.cy>l.cy?x.bottom:x.top,o=l.cx+n;if(o<=x.left+le||o>=x.right-le)continue;e={x:o,y:t},s={x:o,y:i.y},c={x:i.x,y:i.y}}else{const t=u.cx>l.cx?x.right:x.left,o=l.cy+n;if(o<=x.top+le||o>=x.bottom-le)continue;e={x:t,y:o},s={x:i.x,y:o},c={x:i.x,y:i.y}}const h=Q(e,s,le),g=Q(s,c,le);if(h&&g)continue;if(!h&&St(e,s,o,[f],1))continue;if(!g&&St(s,c,o,[d],1))continue;const m=!h&&Lt(e,s,t,r,{epsilon:le,skipDegenerateOther:!0}),y=!g&&Lt(s,c,t,r,{epsilon:le,skipDegenerateOther:!0});if(!m&&!y){p=h?[s,c]:g?[e,s]:[e,s,c];break}}p&&(r.points=p)}}function ge(t,e){const n=.001,{realNodeRects:o,labelNodeRects:r}=bt(e.values());for(const s of t){if(s.isLayoutOnly)continue;const i=s.points;if(!i||i.length<4)continue;const a=it(i,n);if(a.length<4)continue;const c=a.length-1,f=a[c],d=a[c-1],l=a[c-2],u=f.x-d.x,g=f.y-d.y,p=Math.hypot(u,g);if(p>=10||p<n)continue;const x=d.x-l.x,m=d.y-l.y;if(Math.hypot(x,m)<n)continue;const y=tt(d,f,n),b=et(d,f,n),M=tt(l,d,n),I=et(l,d,n);if(!(y&&I||b&&M))continue;const S=s.end,w=s.start,v=S?e.get(S):void 0;if(!v)continue;const L=v.x??0,C=v.y??0,k=gt(v);if(!k)continue;let T,O;if(I){const t=m<0;T={x:L,y:l.y},O={x:L,y:t?k.bottom:k.top}}else{const t=x>0;T={x:l.x,y:C},O={x:t?k.right:k.left,y:C}}if(St(T,O,o,S?[S]:[],-2))continue;if(St(T,O,r,[],-2))continue;if(w){const t=e.get(w),n=t?gt(t):void 0;if(n&&ft(T,n,2))continue}const $=h((t,e)=>`${t.x.toFixed(3)},${t.y.toFixed(3)}|${e.x.toFixed(3)},${e.y.toFixed(3)}`,"ownSegmentKey"),R=new Set;for(let t=0;t<a.length-1;t++)R.add($(a[t],a[t+1]));const N=h((e,o)=>{for(const r of t){if(r===s)continue;if(r.isLayoutOnly)continue;const t=r.points;if(t&&!(t.length<2))for(let r=0;r<t.length-1;r++){const s=t[r],i=t[r+1];if(!R.has($(s,i))&&Ct(e,o,s,i,n))return!0}}return!1},"segmentCrossesOtherEdge");if(N(T,O))continue;if(c-3>=0){const t=a[c-3];if(St(t,T,o,[w,S].filter(t=>Boolean(t)),-2))continue;if(N(t,T))continue}const B=[...a.slice(0,c-2),T,O];s.points=B;const E=s.labelNodeId;if(E){const t=e.get(E);if(t){const e=t.width??0,o=t.height??0;if(e>0&&o>0){let r,s,i=-1;for(let t=0;t<B.length-1;t++){const a=B[t],c=B[t+1],f=Math.hypot(c.x-a.x,c.y-a.y),d=U(a,c,n),l=Z(a,c,n);(d&&f>=e+2||l&&f>=o+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)}}}}}h(he,"portSwapToLShape"),h(ge,"collapseShortTerminalStub");var pe=.001,xe=rt,me=h((t,e)=>Z(t,e,pe)||U(t,e,pe),"orthogonallyAligned");function ye(t,e){const n=h((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"),o=h((t,o)=>{const r=it(t.points??[]);if(r.length<2)return;const s=o?t.start:t.end,i=s?e.get(s):void 0,a=i?gt(i):void 0;if(!i||!s||!a)return;const c=o?r[0]:r[r.length-1],f=o?r[1]:r[r.length-2],d=n(i,c);let l=c;return me(f,d)&&(l=f),Z(d,l,pe)?{edge:t,edgeId:String(t.id??""),nodeId:s,atStart:o,orientation:"V",coord:d.x,min:Math.min(d.y,l.y),max:Math.max(d.y,l.y),boundary:d,railEnd:l,rect:a}:U(d,l,pe)?{edge:t,edgeId:String(t.id??""),nodeId:s,atStart:o,orientation:"H",coord:d.y,min:Math.min(d.x,l.x),max:Math.max(d.x,l.x),boundary:d,railEnd:l,rect:a}:void 0},"terminalLaneFor"),r=h((t,e)=>Math.max(0,Math.min(t.max,e.max)-Math.max(t.min,e.min)),"projectedOverlapLength"),s=h((t,e)=>t.nodeId===e.nodeId&&t.orientation===e.orientation&&("H"===t.orientation?(Math.abs(t.boundary.x-t.rect.left)<1||Math.abs(t.boundary.x-t.rect.right)<1)&&Z(t.boundary,e.boundary,1):(Math.abs(t.boundary.y-t.rect.top)<1||Math.abs(t.boundary.y-t.rect.bottom)<1)&&U(t.boundary,e.boundary,1)),"sameTerminalFace"),i=h((t,e)=>t.nodeId===e.nodeId&&t.orientation===e.orientation&&r(t,e)>=8&&Math.abs(t.coord-e.coord)<.5,"exactTerminalLaneConflict"),a=h((t,e)=>{if(t.nodeId!==e.nodeId||t.orientation!==e.orientation||"H"!==t.orientation||t.atStart===e.atStart)return!1;const n=r(t,e);if(n<8)return!1;const o=t.rect.bottom-t.rect.top;return!(n<o||n>2*o)&&s(t,e)&&Math.abs(t.coord-e.coord)<16},"nearTerminalLaneConflict"),c=h((t,e)=>{const n=it(t.edge.points??[]);if(n.length<2)return;const o="V"===t.orientation?{x:t.boundary.x+e,y:t.boundary.y}:{x:t.boundary.x,y:t.boundary.y+e},r="V"===t.orientation?{x:t.railEnd.x+e,y:t.railEnd.y}:{x:t.railEnd.x,y:t.railEnd.y+e};if(!h(()=>Math.abs(t.boundary.y-t.rect.top)<1||Math.abs(t.boundary.y-t.rect.bottom)<1?U(o,t.boundary,pe)&&o.x>=t.rect.left+1&&o.x<=t.rect.right-1:(Math.abs(t.boundary.x-t.rect.left)<1||Math.abs(t.boundary.x-t.rect.right)<1)&&Z(o,t.boundary,pe)&&o.y>=t.rect.top+1&&o.y<=t.rect.bottom-1,"boundaryStaysOnSameFace")())return;if(t.atStart){const e=n.length>1&&Q(n[1],t.railEnd,pe),s=n.slice(e?2:1),i=s[0];if(i&&!me(i,r))return;return[o,r,...s]}const s=n.length>1&&Q(n[n.length-2],t.railEnd,pe),i=n.slice(0,s?-2:-1),a=i[i.length-1];return!a||me(a,r)?[...i,r,o]:void 0},"shiftedCandidate"),f=h(t=>{const n=t.edge,o=it(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 U(u,h,pe)&&Math.abs(f-l)<1&&Math.abs(c-d)>1||Z(u,h,pe)&&Math.abs(c-d)<1&&Math.abs(f-l)>1},"laneIsStraightCollinearConnector"),d=[-7,7,-14,14,-21,21];for(let l=0;l<8;l++){const e=t.filter(t=>!t.isLayoutOnly).flatMap(t=>[o(t,!0),o(t,!1)]).filter(t=>Boolean(t));let n=!1;for(let t=0;t<e.length&&!n;t++)for(let r=t+1;r<e.length&&!n;r++){const s=e[t],l=e[r];if(s.edge===l.edge||!i(s,l)&&!a(s,l))continue;const u=!i(s,l),h=[s,l].sort((t,e)=>{const n=f(t),o=f(e);return n!==o?Number(n)-Number(o):Number(!e.atStart)-Number(!t.atStart)});for(const t of h){for(const r of d){const s=c(t,r);if(!s)continue;const f=o({...t.edge,points:s},t.atStart);if(f&&!e.some(e=>e.edge!==t.edge&&(i(f,e)||u&&a(f,e)))){t.edge.points=s,n=!0;break}}if(n)break}}if(!n)return}}function be(t,e){const{realNodeRects:n,labelNodeRects:o}=bt(e.values()),r=h((e,r)=>{const s=e.start,i=e.end,a=xe(r);if(a.length!==r.length-1)return!1;const c=[s,i].filter(t=>Boolean(t));for(const t of a){if(St(t.a,t.b,n,c,-2))return!1;if(St(t.a,t.b,o,[],-2))return!1}for(const n of t){if(n===e||n.isLayoutOnly)continue;const t=n.points;if(t&&!(t.length<2))for(const e of a)for(const n of xe(it(t))){if(ot(e,n,.5)>=8)return!1;if(Ct(e.a,e.b,n.a,n.b,pe))return!1}}return!0},"candidateIsSafe"),s=h((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=tt(n,o)&&et(o,r)&&tt(r,s)&&et(s,i)&&Z(n,s,pe)&&Z(n,i,pe)&&Z(o,r,pe)&&(o.x-n.x)*(s.x-r.x)<0,c=et(n,o)&&tt(o,r)&&et(r,s)&&tt(s,i)&&U(n,s,pe)&&U(n,i,pe)&&U(o,r,pe)&&(o.y-n.y)*(s.y-r.y)<0;if(a||c)return it([...t.slice(0,e+1),i,...t.slice(e+5)]);if(e+5>=t.length)return;const f=t[e+5],d=et(n,o)&&tt(o,r)&&et(r,s)&&tt(s,i)&&et(i,f)&&Z(n,i,pe)&&Z(n,f,pe)&&Z(r,s,pe)&&(r.x-o.x)*(i.x-s.x)<0,l=tt(n,o)&&et(o,r)&&tt(r,s)&&et(s,i)&&tt(i,f)&&U(n,i,pe)&&U(n,f,pe)&&U(r,s,pe)&&(r.y-o.y)*(i.y-s.y)<0;return d||l?it([...t.slice(0,e+1),f,...t.slice(e+6)]):void 0},"withoutDogleg");for(let i=0;i<8;i++){let e=!1;for(const n of t){if(n.isLayoutOnly)continue;const t=it(n.points??[]);for(let o=0;o<=t.length-5;o++){const i=s(t,o);if(i&&r(n,i)){n.points=i,e=!0;break}}if(e)break}if(!e)return}}function Me(t,e){const{realNodeRects:n,labelNodeRects:o}=bt(e.values()),r=t.filter(t=>!t.isLayoutOnly),s=h((t,e,n)=>it(t===e?n??[]:t.points??[]),"pointsFor"),i=h((t,e)=>{let n=0;for(let o=0;o<r.length;o++){const i=xe(s(r[o],t,e));for(let a=o+1;a<r.length;a++){const o=xe(s(r[a],t,e));for(const t of i)for(const e of o)Ct(t.a,t.b,e.a,e.b,pe)&&n++}}return n},"strictCrossingCount"),a=h(t=>{const e=xe(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"),c=h((t,e)=>{const o=[t.start,t.end].filter(t=>Boolean(t));return n.filter(t=>{if(o.includes(t.id))return!1;const n=t.rect;return e.horizontal?nt(e.a.x,e.b.x,n.left,n.right)>=8&&e.a.y>=n.top-2&&e.a.y<=n.bottom+2:nt(e.a.y,e.b.y,n.top,n.bottom)>=8&&e.a.x>=n.left-2&&e.a.x<=n.right+2})},"blockingRectsFor"),f=h((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=Rt(it(o));return xe(r).length===r.length-1?r:void 0},"candidateByMovingRail"),d=h((t,e,a)=>{const c=[t.start,t.end].filter(t=>Boolean(t)),f=xe(e);if(f.length!==e.length-1)return!1;for(const r of f){if(St(r.a,r.b,n,c,-2))return!1;if(St(r.a,r.b,o,[],-2))return!1}for(const n of r)if(n!==t)for(const t of f)for(const e of xe(s(n)))if(ot(t,e,.5)>=8)return!1;return i(t,e)<=a},"candidateIsSafe");for(let l=0;l<8;l++){const t=i();let e=!1;for(const n of r){const o=s(n),r=a(o);if(!r)continue;const i=c(n,r.segment);if(0===i.length)continue;const l=r.horizontal?[Math.min(...i.map(t=>t.rect.top))-20,Math.max(...i.map(t=>t.rect.bottom))+20]:[Math.min(...i.map(t=>t.rect.left))-20,Math.max(...i.map(t=>t.rect.right))+20];for(const s of l){const i=f(o,r.segment,s);if(i&&d(n,i,t)){n.points=i,e=!0;break}}if(e)break}if(!e)return}}function Ie(t,e){const n=h(t=>{const e=t.groupTitleRect;if(e&&"number"==typeof e.left&&"number"==typeof e.right&&"number"==typeof e.top&&"number"==typeof e.bottom&&Number.isFinite(e.left)&&Number.isFinite(e.right)&&Number.isFinite(e.top)&&Number.isFinite(e.bottom)&&!(e.right<=e.left)&&!(e.bottom<=e.top))return{left:e.left,right:e.right,top:e.top,bottom:e.bottom}},"validTitleRect"),o=h(t=>{if(!t.isGroup||t.parentId)return;const e=t.direction,o="string"==typeof e?e.toUpperCase():"";if("LR"===o||"RL"===o||"BT"===o)return;const r=n(t),s=t.y,i=t.height;if(!r||"number"!=typeof s||"number"!=typeof i||!Number.isFinite(s)||!Number.isFinite(i)||i<=0)return;const a=r.right-r.left,c=r.bottom-r.top;return c<=0||a<c?void 0:{node:t,rect:r}},"topLaneTitleFor"),r=h((t,e)=>{if(!t.horizontal)return!1;const n=t.a.y;return!(n<=e.top+pe||n>=e.bottom-pe)&&nt(t.a.x,t.b.x,e.left,e.right)>=8},"horizontalSegmentIntersectsTitle"),s=[...e.values()].map(o).filter(t=>Boolean(t));if(0===s.length)return;let i=0;for(const a of t){if(a.isLayoutOnly)continue;const t=it(a.points??[]);for(const e of xe(t))for(const t of s)r(e,t.rect)&&(i=Math.max(i,t.rect.bottom-e.a.y+4))}if(!(i<=pe))for(const a of s){const t=a.node.y,e=a.node.height;"number"!=typeof t||"number"!=typeof e||!Number.isFinite(t)||!Number.isFinite(e)||e<=0||(a.node.y=t-i/2,a.node.height=e+i,a.node.groupTitleRect={...a.rect,top:a.rect.top-i,bottom:a.rect.bottom-i})}}function Se(t,e){const n=h(t=>{const e=t.groupTitleRect;if(e&&"number"==typeof e.left&&"number"==typeof e.right&&"number"==typeof e.top&&"number"==typeof e.bottom&&Number.isFinite(e.left)&&Number.isFinite(e.right)&&Number.isFinite(e.top)&&Number.isFinite(e.bottom)&&!(e.right<=e.left)&&!(e.bottom<=e.top))return{left:e.left,right:e.right,top:e.top,bottom:e.bottom}},"validTitleRect"),o=h(t=>{if(!t.isGroup||t.parentId)return;if("LR"!==t.direction)return;const e=n(t),o=t.x,r=t.width;if(!e||"number"!=typeof o||"number"!=typeof r||!Number.isFinite(o)||!Number.isFinite(r)||r<=0)return;const s=e.right-e.left,i=e.bottom-e.top;return s<=0||i<s?void 0:{node:t,rect:e}},"leftLaneTitleFor"),r=h((t,e)=>{if(!t.vertical)return!1;const n=t.a.x;return!(n<=e.left+pe||n>=e.right-pe)&&nt(t.a.y,t.b.y,e.top,e.bottom)>=8},"verticalSegmentIntersectsTitle"),s=h((t,e)=>{if(!t.horizontal)return!1;const n=t.a.y;return!(n<=e.top+pe||n>=e.bottom-pe)&&nt(t.a.x,t.b.x,e.left,e.right)>=8},"horizontalSegmentIntersectsTitle"),i=[...e.values()].map(o).filter(t=>Boolean(t));if(0===i.length)return;let a=0;for(const c of t){if(c.isLayoutOnly)continue;const t=it(c.points??[]);for(const e of xe(t))for(const t of i)if(r(e,t.rect))a=Math.max(a,t.rect.right-e.a.x+4);else if(s(e,t.rect)){const n=Math.min(e.a.x,e.b.x);a=Math.max(a,t.rect.right-n+4)}}if(!(a<=pe))for(const c of i){const t=c.node.x,e=c.node.width;"number"!=typeof t||"number"!=typeof e||!Number.isFinite(t)||!Number.isFinite(e)||e<=0||(c.node.x=t-a/2,c.node.width=e+a,c.node.groupTitleRect={...c.rect,left:c.rect.left-a,right:c.rect.right-a})}}function we(t,e){const{realNodeRects:n}=bt(e.values()),o=t.filter(t=>!t.isLayoutOnly),r=h((t,e=new Map)=>it(e.get(t)??t.points??[]),"replacementPointsFor"),s=h((t=new Map)=>{let e=0;for(let n=0;n<o.length;n++){const s=xe(r(o[n],t));for(let i=n+1;i<o.length;i++){const n=xe(r(o[i],t));for(const t of s)for(const o of n)Ct(t.a,t.b,o.a,o.b,pe)&&e++}}return e},"crossingCount"),i=h((t=new Map)=>o.reduce((e,n)=>e+st(r(n,t)),0),"totalBends"),a=h(t=>{const e=r(t);if(e.length<4)return;const n=e[e.length-2],o=e[e.length-1];return tt(n,o,pe)||et(n,o,pe)?{tailStart:n,terminal:o}:void 0},"terminalTailFor"),c=h((t,e)=>{const n=r(t);if(n.length<3)return;const o=n[0],s=n[1];let i;if(tt(o,s,pe))i={x:s.x,y:e.tailStart.y};else{if(!et(o,s,pe))return;i={x:e.tailStart.x,y:s.y}}const a=Rt(it([o,s,i,e.tailStart,e.terminal]));return xe(a).length===a.length-1?a:void 0},"candidateWithDestinationTail"),f=h((t,e)=>{const o=[t.start,t.end].filter(t=>Boolean(t));for(const r of xe(e))if(St(r.a,r.b,n,o,-2))return!0;return!1},"pathHasNodeHit"),d=h((t,e,n)=>{for(const s of o)if(s!==t)for(const t of xe(e))for(const e of xe(r(s,n)))if(ot(t,e,.5)>=8)return!0;return!1},"pathHasSharedTrack"),l=h((t,e,n)=>!f(t,e)&&!d(t,e,n),"candidateIsSafe"),u=h(()=>{const t=new Map;for(const n of o){const o=n.end;if(!o||!e.has(o))continue;if(r(n).length<4)continue;const s=t.get(o)??[];s.push(n),t.set(o,s)}return t},"edgesByDestination");for(let h=0;h<4;h++){const t=s();if(0===t)return;let e,n=t,o=i();for(const r of u().values())for(let f=0;f<r.length;f++)for(let d=f+1;d<r.length;d++){const u=r[f],h=r[d],g=a(u),p=a(h);if(!g||!p)continue;const x=c(u,p),m=c(h,g);if(!x||!m)continue;const y=new Map([[u,x],[h,m]]);if(!l(u,x,y)||!l(h,m,y))continue;const b=s(y),M=i(y);b>=t||b>n||b===n&&M>=o||(e=y,n=b,o=M)}if(!e)return;for(const[r,s]of e)r.points=s}}function ve(t,e){const{realNodeRects:n,labelNodeRects:o}=bt(e.values()),r=t.filter(t=>!t.isLayoutOnly),s=h((t,e=new Map)=>it(e.get(t)??t.points??[]),"replacementPointsFor"),i=h((t=new Map)=>{let e=0;for(let n=0;n<r.length;n++){const o=xe(s(r[n],t));for(let i=n+1;i<r.length;i++){const n=xe(s(r[i],t));for(const t of o)for(const o of n)Ct(t.a,t.b,o.a,o.b,pe)&&e++}}return e},"strictCrossingCount"),a=h((t=new Map)=>r.reduce((e,n)=>e+st(s(n,t)),0),"totalBends"),c=h(t=>{const n=t.start,o=t.end,r=n?e.get(n):void 0,s=o?e.get(o):void 0,i=r?gt(r):void 0,a=s?gt(s):void 0;return i&&a?{src:i,dst:a}:void 0},"endpointRectsFor"),f=h((t,e,n)=>{if(n.index<=0||n.index+1>=e.length-1)return;const o=c(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-pe?"left":r>i+pe?"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-pe?"top":r>i+pe?"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"),d=h(()=>{const t=[];for(const e of r){const n=s(e);for(const o of xe(n)){const r=f(e,n,o);r&&t.push(r)}}return t},"collectExternalRails"),l=h((t,e)=>t.edge!==e.edge&&t.axis===e.axis&&t.side===e.side&&nt(t.min,t.max,e.min,e.max)>=8,"railsInteract"),u=h(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)&&l(e,o)&&(n.add(o),r.push(o))}s.length>1&&e.push(s)}return e},"connectedComponents"),g=h(t=>{const e=[];for(const n of t)e.some(t=>Math.abs(t-n.coord)<pe)||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=h(t=>{const e=t.map(t=>t.coord),n=g(t),o=[];if(t.length<=6){const r=new Array(n.length).fill(!1),s=[],i=h(()=>{if(s.length!==t.length)for(const[t,e]of n.entries())r[t]||(r[t]=!0,s.push(e),i(),s.pop(),r[t]=!1);else s.some((t,n)=>Math.abs(t-e[n])>=pe)&&o.push([...s])},"visit");return i(),o}for(let r=0;r<e.length;r++)for(let t=r+1;t<e.length;t++){const n=[...e];[n[r],n[t]]=[n[t],n[r]],o.push(n)}return o},"coordinateAssignmentsFor"),x=h((t,e)=>{const n=new Map;for(const[r,s]of t.entries()){const t=e[r],o=n.get(s.edge)??s.points.map(t=>({x:t.x,y:t.y}));"vertical"===s.axis?(o[s.segmentIndex].x=t,o[s.segmentIndex+1].x=t):(o[s.segmentIndex].y=t,o[s.segmentIndex+1].y=t),n.set(s.edge,o)}const o=new Map;for(const[r,s]of n){const t=Rt(it(s));if(xe(t).length!==t.length-1)return;o.set(r,t)}return o},"replacementsForAssignment"),m=h(t=>{for(const[e,r]of t){const t=[e.start,e.end].filter(t=>Boolean(t));for(const e of xe(r)){if(St(e.a,e.b,n,t,-2))return!1;if(St(e.a,e.b,o,[],-2))return!1}}for(let e=0;e<r.length;e++){const n=r[e],o=t.has(n),i=xe(s(n,t));for(let a=e+1;a<r.length;a++){const e=r[a];if(!o&&!t.has(e))continue;const n=xe(s(e,t));for(const t of i)for(const e of n)if(ot(t,e,.5)>=8)return!1}}return!0},"candidateIsSafe");for(let h=0;h<4;h++){const t=i();if(0===t)return;let e,n=t,o=a(),r=Number.POSITIVE_INFINITY;for(const s of u(d()))for(const c of p(s)){const f=x(s,c);if(!f||!m(f))continue;const d=i(f);if(d>=t)continue;const l=a(f),u=s.reduce((t,e,n)=>t+Math.abs(c[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[s,i]of e)s.points=i}}function Le(t,e){const{realNodeRects:n,labelNodeRects:o}=bt(e.values()),r=t.filter(t=>!t.isLayoutOnly),s=h((t,e,n)=>it(t===e?n??[]:t.points??[]),"pointsFor"),i=h(t=>xe(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"),a=h((t,e)=>{let n=0;for(let o=0;o<r.length;o++){const i=xe(s(r[o],t,e));for(let a=o+1;a<r.length;a++){const o=xe(s(r[a],t,e));for(const t of i)for(const e of o)Ct(t.a,t.b,e.a,e.b,pe)&&n++}}return n},"strictCrossingCount"),c=h((t,e)=>{if(t.horizontal){const n=t.a.y;return(Math.abs(n-e.top)<1||Math.abs(n-e.bottom)<1)&&nt(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)&&nt(t.a.y,t.b.y,e.top,e.bottom)>=8}return!1},"segmentRunsAlongRectBorder"),f=h(t=>{const n=[t.start,t.end].filter(t=>Boolean(t)),o=[];for(const r of n){const t=e.get(r),n=t?gt(t):void 0;n&&o.push(n)}return o},"endpointRectsFor"),d=h((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=tt(n,o,pe)&&et(o,r,pe)&&tt(r,s,pe),a=et(n,o,pe)&&tt(o,r,pe)&&et(r,s,pe);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=Z(n,s,pe)||U(n,s,pe)?[]:[{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=>Rt(it(t))).filter(t=>{if(xe(t).length!==t.length-1)return!1;if(!t.some(t=>Q(t,s,pe)))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"),l=h((t,e,i)=>{const d=[t.start,t.end].filter(t=>Boolean(t)),l=f(t);for(const r of xe(e)){if(St(r.a,r.b,n,d,-2))return!1;if(St(r.a,r.b,o,[],-2))return!1;if(l.some(t=>c(r,t)))return!1}for(const n of r)if(n!==t)for(const t of xe(e))for(const e of xe(s(n)))if(ot(t,e,.5)>=8)return!1;return a(t,e)<=i},"candidateIsSafe");for(let u=0;u<8;u++){const t=a();let e,n,o=t,c=Number.POSITIVE_INFINITY,f=Number.POSITIVE_INFINITY;for(const u of r){const r=s(u),h=st(r,pe),g=i(r);for(let s=0;s<=r.length-4;s++)for(const p of d(r,s)){const r=st(p,pe),s=i(p);if(!(r<h||r===h&&s<g-pe)||!l(u,p,t))continue;const d=a(u,p);d>o||d===o&&(r>c||r===c&&s>=f)||(e=u,n=p,o=d,c=r,f=s)}}if(!e||!n)return;e.points=n}}function Ce(t,e){const n=20,o=[];for(const h of e.values()){if(h.isGroup||h.isEdgeLabel)continue;const t=h.x??0,e=h.y??0,n=gt(h);n&&o.push({id:String(h.id??""),cx:t,cy:e,rect:n})}if(0===o.length)return;const r=new Map(o.map(t=>[t.id,t])),s=o.map(t=>({id:t.id,rect:t.rect})),i=["top","bottom","left","right"],a={top:Math.min(...o.map(t=>t.rect.top))-n,bottom:Math.max(...o.map(t=>t.rect.bottom))+n,left:Math.min(...o.map(t=>t.rect.left))-n,right:Math.max(...o.map(t=>t.rect.right))+n},c=t.filter(t=>!t.isLayoutOnly),f=new Map(c.map((t,e)=>[t,e])),d=h(t=>{const e="left"===t||"top"===t?-1:1,o=[];for(let r=0;r<=2;r++)o.push(a[t]+e*n*r);return o},"outwardTracksForSide"),l=h((t,e=new Map)=>it(e.get(t)??t.points??[]),"replacementPointsFor"),u=h((t,e)=>{let n=0;for(const o of t)for(const t of e)Ct(o.a,o.b,t.a,t.b,pe)&&n++;return n},"crossingCountBetweenSegments"),g=h((t,e)=>u(xe(t),xe(e)),"crossingCountBetweenPaths"),p=h((t=new Map)=>{let e=0;const n=[],o=new Set,r=[],s=h(t=>{o.has(t)||(o.add(t),r.push(t))},"addEdge");for(let i=0;i<c.length;i++){const o=c[i],r=l(o,t);for(let a=i+1;a<c.length;a++){const i=c[a],f=g(r,l(i,t));f>0&&(e+=f,n.push({first:o,second:i,count:f}),s(o),s(i))}}return r.sort((t,e)=>(f.get(t)??0)-(f.get(e)??0)),{count:e,pairs:n,edgeSet:o,edges:r}},"crossingSnapshot"),x=h((t,e)=>{const n=new Set(e.keys());if(0===n.size)return t.count;let o=0;for(const s of t.pairs)(n.has(s.first)||n.has(s.second))&&(o+=s.count);let r=0;for(let s=0;s<c.length;s++){const t=c[s],o=n.has(t),i=l(t,e);for(let a=s+1;a<c.length;a++){const t=c[a];(o||n.has(t))&&(r+=g(i,l(t,e)))}}return t.count-o+r},"crossingCountWithReplacements"),m=h(t=>{const e=new Map;for(const r of t.pairs){const t=e.get(r.first)??new Set;t.add(r.second),e.set(r.first,t);const n=e.get(r.second)??new Set;n.add(r.first),e.set(r.second,n)}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)=>(f.get(t)??0)-(f.get(e)??0)),s.length>1&&n.push(s)}return n},"crossingComponents"),y=h(t=>[t.start,t.end].filter(t=>Boolean(t)),"endpointIdsFor"),b=h(t=>{const e=[];for(const n of m(t)){const t=new Set(n),o=new Set(n.flatMap(t=>y(t))),r=[...n];for(const e of c)t.has(e)||y(e).some(t=>o.has(t))&&r.push(e);r.sort((t,e)=>(f.get(t)??0)-(f.get(e)??0)),e.push(r)}return e},"pairSearchGroups"),M=h((t,e,n)=>x(t,new Map([[e,n]])),"crossingCountWithSingleReplacement"),I=h(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"),S=h(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"),w=h((t=new Map)=>c.reduce((e,n)=>e+st(l(n,t)),0),"totalBends"),v=h((t=new Map)=>c.reduce((e,n)=>e+S(l(n,t)),0),"totalLength"),L=h((t,e,n=new Map)=>{const o=xe(e);for(const r of c)if(r!==t)for(const t of o)for(const e of xe(l(r,n)))if(ot(t,e,.5)>=8)return!0;return!1},"pathHasSegmentConflict"),C=h((t,e)=>{const n=[t.start,t.end].filter(t=>Boolean(t));for(const o of xe(e))if(St(o.a,o.b,s,n,-2))return!0;return!1},"pathHitsNode"),k=h((t,e)=>{const n=Rt(it(e));xe(n).length===n.length-1&&t.push(n)},"pushOrthogonalCandidate"),T=h(t=>"left"===t||"right"===t,"sideIsHorizontal"),O=h((t,e,o)=>{switch(e){case"left":return Math.min(t.x,o.x)-n;case"right":return Math.max(t.x,o.x)+n;case"top":return Math.min(t.y,o.y)-n;case"bottom":return Math.max(t.y,o.y)+n}},"localTrackForSameSide"),$=h((t,e,o,r)=>{const s="left"===o||"top"===o?-1:1,i=[O(e,o,r),a[o]];for(const a of i)for(let i=0;i<=2;i++)k(t,mt(e,o,r,a+s*n*i))},"addSameSideCandidates"),R=h((t,e,n,o,r)=>{for(const s of d(n))for(const n of d(r))k(t,[e,{x:s,y:e.y},{x:s,y:n},{x:o.x,y:n},o])},"addHorizontalToVerticalCandidates"),N=h((t,e,n,o,r)=>{for(const s of d(n))for(const n of d(r))k(t,[e,{x:e.x,y:s},{x:n,y:s},{x:n,y:o.y},o])},"addVerticalToHorizontalCandidates"),B=h((t,e,n,o,r)=>{const s=[...d("top"),...d("bottom")];for(const i of d(n))for(const n of d(r))for(const r of s)k(t,[e,{x:i,y:e.y},{x:i,y:r},{x:n,y:r},{x:n,y:o.y},o])},"addHorizontalPairCandidates"),E=h((t,e,n,o,r)=>{const s=[...d("left"),...d("right")];for(const i of d(n))for(const n of d(r))for(const r of s)k(t,[e,{x:e.x,y:i},{x:r,y:i},{x:r,y:n},{x:o.x,y:n},o])},"addVerticalPairCandidates"),F=h(t=>{const e=new Set;return t.map(t=>it(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"),Y=h((t,e,o,r)=>{const s=[],i=xt(t,e,o,r,n,pe);i&&k(s,i),e===r&&$(s,t,e,o);const a=T(e),c=T(r);return a&&!c?R(s,t,e,o,r):!a&&c?N(s,t,e,o,r):a?B(s,t,e,o,r):E(s,t,e,o,r),F(s)},"buildCandidatesForSides"),X=h((t,e,n,o)=>{const r=[...d("left"),...d("right")],s=[...d("top"),...d("bottom")];for(const a of i){const i=pt(o,a),c="top"===a||"bottom"===a?d(a):s;for(const o of r){k(t,[e,n,{x:o,y:n.y},{x:o,y:i.y},i]);for(const r of c)k(t,[e,n,{x:o,y:n.y},{x:o,y:r},{x:i.x,y:r},i])}}},"addVerticalDepartureOuterTrackCandidates"),z=h((t,e,n,o)=>{const r=[...d("left"),...d("right")],s=[...d("top"),...d("bottom")];for(const a of i){const i=pt(o,a),c="left"===a||"right"===a?d(a):r;for(const o of s){k(t,[e,n,{x:n.x,y:o},{x:i.x,y:o},i]);for(const r of c)k(t,[e,n,{x:n.x,y:o},{x:r,y:o},{x:r,y:i.y},i])}}},"addHorizontalDepartureOuterTrackCandidates"),P=h(t=>{const e=t.start,n=t.end,o=n?r.get(n):void 0;if(!e||!o)return[];const s=it(t.points??[]);if(s.length<4)return[];const i=s[0],a=s[1],c=[];return et(i,a,pe)?X(c,i,a,o):tt(i,a,pe)&&z(c,i,a,o),c},"terminalPreservingOuterTrackCandidates"),A=h(t=>{const e=t.start,n=t.end,o=e?r.get(e):void 0,s=n?r.get(n):void 0;if(!o||!s)return[];const a=[];for(const r of i){const t=pt(o,r);for(const e of i)a.push(...Y(t,r,pt(s,e),e))}return a.push(...P(t)),a},"candidatePathsFor"),G=h(()=>new Map(c.map(t=>[t,xe(l(t))])),"currentSegmentsByEdge"),D=h((t,e,n)=>{const o=new Set;for(const r of c){if(r===t)continue;const s=n.get(r)??xe(l(r));e.some(t=>s.some(e=>ot(t,e,.5)>=8))&&o.add(r)}return o},"sharedTrackConflictsFor"),j=h((t,e,n,o)=>{const r=new Set;return A(t).map(t=>Rt(it(t))).filter(e=>{if(C(t,e))return!1;const n=e.map(t=>`${t.x.toFixed(3)},${t.y.toFixed(3)}`).join("|");return!(r.has(n)||e.length<2||(r.add(n),0))}).map(r=>{const s=xe(r);let i=0;for(const e of c)e!==t&&(i+=u(s,n.get(e)??xe(l(e))));return{candidate:r,candidateSegments:s,crossings:e.count-(o.get(t)??0)+i,bends:st(r,pe),totalBends:st(r),length:S(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:D(t,e.candidateSegments,n),totalBends:e.totalBends,length:e.length}))},"pairCandidatesFor"),H=h((t,e,n,o,r,s)=>{let i=0;for(const c of t.pairs)c.first!==e&&c.second!==e&&c.first!==o&&c.second!==o||(i+=c.count);let a=u(n.segments,r.segments);for(const f of c){if(f===e||f===o)continue;const t=s.get(f)??xe(l(f));a+=u(n.segments,t)+u(r.segments,t)}return t.count-i+a},"pairCrossingCount"),_=h((t,e)=>{for(const n of t.sharedTrackConflicts)if(n!==e)return!1;return!0},"conflictsOnlyWith"),V=h((t,e)=>t.segments.some(t=>e.segments.some(e=>ot(t,e,.5)>=8)),"candidatesShareTrack"),W=h((t,e,n,o)=>_(e,n.edge)&&_(o,t.edge)&&!V(e,o),"pairCandidatesAreCompatible"),q=h((t,e,n,o,r)=>{const s=H(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"),J=h((t,e)=>t.crossings<e.crossings||t.crossings===e.crossings&&(t.bends<e.bends||t.bends===e.bends&&t.length<e.length),"pairScoreIsBetter"),K=h((t,e,n,o)=>{let r=o;for(const s of e.candidates)for(const o of n.candidates){if(!W(e,s,n,o))continue;const i=q(t,e,s,n,o);i&&J(i,r)&&(r=i)}return r},"bestScoreForOptionPair"),Q=h(t=>{const e=w(),n=v(),o=G(),r=I(t),s=new Map(c.map(t=>[t,st(l(t))])),i=new Map(c.map(t=>[t,S(l(t))])),a=new Map,f=b(t);for(const c of f)for(const e of c){if(a.has(e))continue;const n=j(e,t,o,r);n.length>0&&a.set(e,{edge:e,candidates:n})}let d={replacements:new Map,crossings:t.count,bends:e,length:n};const u={current:t,currentBends:e,currentLength:n,baseBendsByEdge:s,baseLengthByEdge:i,baseSegments:o};for(const c of f){const e=new Set(c.filter(e=>t.edgeSet.has(e))),n=c.map(t=>a.get(t)).filter(t=>Boolean(t));for(let t=0;t<n.length;t++){const o=n[t];for(let r=t+1;r<n.length;r++){const t=n[r];(e.has(o.edge)||e.has(t.edge))&&(d=K(u,o,t,d))}}}return d.replacements.size>0?d.replacements:void 0},"bestPairedReplacement");for(let h=0;h<4;h++){const t=p(),e=t.count;if(0===e)return;let n,o,r=e,s=Number.POSITIVE_INFINITY;for(const a of t.edges){const i=st(l(a),pe);for(const c of A(a)){const f=C(a,c),d=!f&&L(a,c),l=M(t,a,c),u=st(c,pe);f||d||(l<e||l===e&&u<i)&&(l>r||l===r&&u>=s||(n=a,o=c,r=l,s=u))}}if(n&&o){n.points=o;continue}const i=Q(t);if(!i)return;for(const[a,c]of i)a.points=c}}h(ye,"separateSharedRenderedTerminalLanes"),h(be,"collapseRedundantRectangularDoglegs"),h(Me,"liftObstacleHuggingSameSideRails"),h(Ie,"liftTopLaneTitleBandsAboveRails"),h(Se,"shiftLeftLaneTitleBandsLeftOfRails"),h(we,"swapDestinationTerminalTailsToReduceCrossings"),h(ve,"reassignCrossingExternalRailChannels"),h(Le,"shortcutRedundantOrthogonalJogs"),h(Ce,"resolveRenderedOrthogonalCrossings");var ke=.001;function Te(t,e){const{nodeInfoById:n,realNodeRects:o}=yt(e),r=["top","bottom","left","right"],s={top:Math.min(...o.map(t=>t.rect.top))-20,bottom:Math.max(...o.map(t=>t.rect.bottom))+20,left:Math.min(...o.map(t=>t.rect.left))-20,right:Math.max(...o.map(t=>t.rect.right))+20},i=h((t,e,n,o)=>{const r=[],i=xt(t,e,n,o,20,ke);return i&&r.push(i),e===o&&r.push(mt(t,e,n,s[e])),r},"buildOrthogonalPathCandidates"),a=h((t,e)=>{for(let n=0;n<t.length-1;n++)if(St(t[n],t[n+1],o,e,1))return!0;return!1},"pathHitsNode"),c=h((e,n,o=!1)=>{let r=0;const s=rt(e,ke),i=n.start,a=n.end;for(const c of t){if(c===n||c.isLayoutOnly)continue;const t=c.start,e=c.end;if(!o&&i&&a&&(t===i||t===a||e===i||e===a))continue;const f=c.points;if(f&&!(f.length<2))for(const n of s)for(const t of rt(f,ke))(wt(n.a,n.b,t.a,t.b,ke,ke)||ot(n,t,ke)>=8)&&r++}return r},"pathConflictCount"),f=h((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"),d=new Map,l=h((t,e,n)=>{const o=d.get(t)??[];o.push({side:e,edgeId:n}),d.set(t,o)},"addFaceClaim");for(const h of t){if(h.isLayoutOnly)continue;const t=h.points??[];if(t.length<1)continue;const e=h.id??"",o=h.start,r=h.end;if(o){const r=n.get(o);r&&l(o,f(t[0],r),e)}if(r){const o=n.get(r);o&&l(r,f(t[t.length-1],o),e)}}const u=h((t,e,n)=>d.get(t)?.some(t=>t.edgeId!==n&&t.side===e)??!1,"faceIsClaimed");for(const h of t){if(h.isLayoutOnly)continue;const t=h.points;if(!t||t.length<2)continue;const e=st(t,ke);if(e<4)continue;const o=h.start,s=h.end;if(!o||!s)continue;const g=n.get(o),p=n.get(s);if(!g||!p)continue;const x=h.id??"",m=c(t,h,!0),y=c(t,h);let b,M=m,I=e;for(const n of r){if(u(o,n,x))continue;const t=pt(g,n);for(const e of r){if(u(s,e,x))continue;const r=pt(p,e);for(const f of i(t,n,r,e)){if(a(f,[o,s]))continue;const t=st(f,ke);if(m>0){const e=c(f,h,!0);if(e>M||e===M&&t>=I)continue;M=e,I=t,b=f;continue}c(f,h)>y||t<I&&(I=t,b=f)}}}if(b){h.points=b;const t=d.get(o);t&&d.set(o,t.filter(t=>t.edgeId!==x));const e=d.get(s);e&&d.set(s,e.filter(t=>t.edgeId!==x)),l(o,f(b[0],g),x),l(s,f(b[b.length-1],p),x)}}}h(Te,"simplifyDetouredEdges");var Oe=.001;function $e(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)<Oe)){if(Math.abs(a)<=Oe){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)<=Oe){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 Re(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 Ne(t,e){const n=it(e);return[$e(n,!0),$e(n,!1)].some(e=>e&<(t,Re(e)))}function Be(t,e){const n=[];for(const l of t){if(l.isLayoutOnly)continue;const t=l.points;if(t&&!(t.length<2))for(let e=0;e<t.length-1;e++)n.push({edgeId:l.id,p1:t[e],p2:t[e+1]})}const o=[],r=[];for(const l of e.values()){const t=l.isGroup,e=l.parentId;if(t&&!e){const t=gt(l);t&&r.push({id:l.id,rect:t});continue}if(t)continue;if(l.isEdgeLabel)continue;const n=gt(l);n&&o.push({nodeId:l.id,rect:n})}const s=h((t,e)=>{const n=ut(e,3);for(const{nodeId:r,rect:s}of o)if(r!==t&<(n,s))return!0;return!1},"labelOverlapsForeignNode"),i=h((t,e)=>{const o=ut(e,3);for(const r of n)if(r.edgeId!==t&&ct(r.p1,r.p2,o))return!0;return!1},"labelOverlapsForeignEdge"),a=h((t,e,n)=>s(t,n)||i(e,n),"labelOverlapsAnything"),c=[],f=h(t=>{for(const{id:e,rect:n}of r)if(dt(n,t))return e},"findContainingLane"),d=h((t,e)=>c.some(n=>n.labelId!==t&<(e,n.rect)),"overlapsPlacedLabel");for(const l of t){if(l.isLayoutOnly)continue;const t=l.labelNodeId;if(!t)continue;const n=e.get(t);if(!n)continue;const o=l.points;if(!o||o.length<2)continue;const u=n.width??0,g=n.height??0;if(u<=0||g<=0)continue;const p=[];for(let e=0;e<o.length-1;e++){const t=o[e],n=o[e+1],r=Math.abs(t.x-n.x),s=Math.abs(t.y-n.y);r<Oe&&s<Oe||r>=Oe&&s>=Oe||p.push({idx:e,length:r+s,orientation:r>=Oe?"horizontal":"vertical",midX:(t.x+n.x)/2,midY:(t.y+n.y)/2})}if(0===p.length)continue;const x=p.length>=3?p.filter(t=>t.idx>0&&t.idx<p.length-1):p,m=x.length>0?x:p,y=u>=g?"horizontal":"vertical",b=h(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?u:g)+2;return o!==e.length>=("horizontal"===e.orientation?u: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=h((t,e)=>{const n=o[t.idx],r=o[t.idx+1];return{midX:n.x+(r.x-n.x)*e,midY:n.y+(r.y-n.y)*e}},"anchorAtT"),v=h((t,e,n)=>Math.min(n,Math.max(e,t)),"clamp"),L=h((t,e)=>t.midX>=e.left-Oe&&t.midX<=e.right+Oe&&t.midY>=e.top-Oe&&t.midY<=e.bottom+Oe,"pointInsideRectInclusive"),C=h(t=>{const e=ht(t.midX,t.midY,u,g),n=f(e);if(n)return{laneId:n,anchor:t,rect:e};const o=r.find(({rect:e})=>L(t,e));if(!o)return;const s=o.rect.left+u/2+1,i=o.rect.right-u/2-1,a=o.rect.top+g/2+1,c=o.rect.bottom-g/2-1;if(s>i||a>c)return;const d={midX:v(t.midX,s,i),midY:v(t.midY,a,c)},l=ht(d.midX,d.midY,u,g);return L(t,l)?{laneId:o.id,anchor:d,rect:l}:void 0},"placementForAnchor"),k=h((t,e,n)=>"horizontal"===t.orientation?Math.abs(e.midX-n.x):Math.abs(e.midY-n.y),"distanceAlongSegment"),T=h((t,e)=>{const n=12+("horizontal"===t.orientation?u/2:g/2);if(t===M){const r=o[t.idx];if(k(t,e,r)+Oe<n)return!1}if(t===I){const r=o[t.idx+1];if(k(t,e,r)+Oe<n)return!1}return!0},"labelClearsTerminalEndpoints"),O=h(e=>{const n=b(e);for(const r of n)for(const e of S){const n=w(r,e);if(!T(r,n))continue;const s=C(n);if(s&&!Ne(s.rect,o)&&!d(t,s.rect)&&!a(t,l.id,s.rect))return{laneId:s.laneId,anchor:s.anchor}}},"tryPool"),$=h((e,n,r=!1)=>{const a=b(e);for(const c of a){const e={midX:c.midX,midY:c.midY};if(n&&!T(c,e))continue;const a=C(e);if(a&&!Ne(a.rect,o)&&!d(t,a.rect)&&!s(t,a.rect)&&(r||!i(l.id,a.rect)))return{laneId:a.laneId,anchor:a.anchor}}},"findLaneContainingFallback"),R=O(m)??(m.length<p.length?O(p):void 0)??$(p,!0)??$(p,!1)??$(p,!1,!0);if(R){n.x=R.anchor.midX,n.y=R.anchor.midY,n.parentId=R.laneId;const e=ht(R.anchor.midX,R.anchor.midY,u,g),o=c.findIndex(e=>e.labelId===t);o>=0?c[o]={labelId:t,rect:e}:c.push({labelId:t,rect:e})}}}h($e,"markerClearanceRectFor"),h(Re,"normalizeRect"),h(Ne,"labelOverlapsOwnMarker"),h(Be,"anchorLabelsToPolyline");var Ee=1e-6;function Fe(t,e){return t<e?`${t}::${e}`:`${e}::${t}`}function Ye(t,e){const{nodeInfoById:n,realNodeRects:o}=yt(e),r=new Map;for(const i of e){const t=i.id;i.isGroup||i.isEdgeLabel&&r.set(t,{w:i.width??0,h:i.height??0})}const s=h((e,n,o,s)=>{const i=Fe(n,o);let a=0;const c=h(t=>{if(!t)return;const e=r.get(t);if(!e)return;const n="x"===s?e.w/2:e.h/2;n>a&&(a=n)},"consider");c(e.labelNodeId);for(const r of t){if(r===e)continue;if(r.isLayoutOnly)continue;const t=r.start,n=r.end;t&&n&&Fe(t,n)===i&&c(r.labelNodeId)}return a>0?a+3:0},"labelClearanceFor");for(const i of t){if(i.isLayoutOnly)continue;if(!at(i.points,Ee))continue;const e=It(i,n,Ee);if(!e)continue;const{srcId:r,dstId:a,srcInfo:c,dstInfo:f,collinearX:d,collinearY:l}=e;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(St(u,h,o,[r,a],1))continue;const g=s(i,r,a,d?"x":"y"),p=g>4?g:4,x=[0,p,-p];for(const n of x){const e={...u},s={...h};if(d){if(e.x+=n,s.x+=n,e.x<=c.rect.left||e.x>=c.rect.right)continue;if(s.x<=f.rect.left||s.x>=f.rect.right)continue}else{if(e.y+=n,s.y+=n,e.y<=c.rect.top||e.y>=c.rect.bottom)continue;if(s.y<=f.rect.top||s.y>=f.rect.bottom)continue}if(!St(e,s,o,[r,a],1)&&!Lt(e,s,t,i,{epsilon:Ee})){i.points=[e,s];break}}}}function Xe(t,e){const n=.001,{realNodeRects:o,labelNodeRects:r}=bt(e.values()),s=h((t,e)=>rt(e,n).map(n=>({...n,edge:t,interior:n.index>=1&&n.index<=e.length-3})),"segmentsFor"),i=h(()=>{const e=[];for(const n of t){if(n.isLayoutOnly)continue;const t=n.points;!t||t.length<2||e.push(...s(n,it(t)))}return e},"allSegments"),a=h((t,e)=>t.horizontal&&e.horizontal?nt(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)&&nt(t.a.y,t.b.y,e.a.y,e.b.y)>=8&&Math.abs(t.a.x-e.a.x)<7,"hasCrowdedParallelTrack"),c=h((e,i)=>{const c=e.start,f=e.end,d=s(e,i);if(d.length!==i.length-1)return!1;const l=[c,f].filter(t=>Boolean(t)),u=e.labelNodeId?[e.labelNodeId]:[];for(const t of d){if(St(t.a,t.b,o,l,-2))return!1;if(St(t.a,t.b,r,u,-2))return!1}for(const o of t){if(o===e||o.isLayoutOnly)continue;const t=o.points;if(t&&!(t.length<2))for(const e of d)for(const r of s(o,it(t))){if(a(e,r))return!1;if(Ct(e.a,e.b,r.a,r.b,n))return!1}}return!0},"candidateIsSafe"),f=h((t,e)=>{const n=it(t.edge.points??[]);if(n.length<4||t.index>=n.length-1)return;const o=n.map(t=>({...t}));if(t.horizontal)o[t.index].y+=e,o[t.index+1].y+=e;else{if(!t.vertical)return;o[t.index].x+=e,o[t.index+1].x+=e}return s(t.edge,o).length===o.length-1?o:void 0},"shiftedCandidate"),d=h((t,e)=>({x:t.x??(e.left+e.right)/2,y:t.y??(e.top+e.bottom)/2}),"nodeCenter"),l=h(t=>{const n=t.edge,o=it(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?gt(r):void 0,a=s?gt(s):void 0,c=o.slice(t.index+2);return r&&s&&i&&a&&0!==c.length?{sourceCenter:d(r,i),targetCenter:d(s,a),sourceRect:i,tail:c}:void 0},"sourceDetourContextFor"),u=h((t,e,o,r,s,i)=>{const a=r.y>=o.y,c=a?s.bottom:s.top,f=c+(a?20:-20);if(a&&t.b.y<=f+n||!a&&t.b.y>=f-n)return;const d=t.a.x+e;return it([{x:o.x,y:c},{x:o.x,y:f},{x:d,y:f},{x:d,y:t.b.y},...i],n)},"verticalSourceDetour"),g=h((t,e,o,r,s,i)=>{const a=r.x>=o.x,c=a?s.right:s.left,f=c+(a?20:-20);if(a&&t.b.x<=f+n||!a&&t.b.x>=f-n)return;const d=t.a.y+e;return it([{x:c,y:o.y},{x:f,y:o.y},{x:f,y:d},{x:t.b.x,y:d},...i],n)},"horizontalSourceDetour"),p=h((t,e)=>{const n=l(t);if(n)return t.vertical?u(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"),x=[-7,7,-14,14,-21,21];for(let h=0;h<12;h++){const t=i();let e=!1;for(let n=0;n<t.length&&!e;n++)for(let o=n+1;o<t.length&&!e;o++){const r=t[n],s=t[o];if(r.edge===s.edge||!a(r,s))continue;const i=[r,s].filter(t=>t.interior);for(const t of i){for(const n of x){const o=f(t,n);if(o&&c(t.edge,o)){t.edge.points=o,e=!0;break}const r=p(t,n);if(r&&c(t.edge,r)){t.edge.points=r,e=!0;break}}if(e)break}}if(!e)return}}function ze(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;return l>.01&&l<.99&&u>.01&&u<.99}function Pe(t){const e=t.nodes??[],n=t.edges??[],o=[];if(!n.length||!e.length)return o;const r=Mt(e),s=[];for(const i of n){if(i.isLayoutOnly)continue;const t=i.points;if(!t||t.length<2)continue;const e=i.start,n=i.end,a=i.labelNodeId,c=i.id??`${e}->${n}`;for(const s of r)if(s.nodeId!==e&&s.nodeId!==n&&(!a||s.nodeId!==a))for(let e=0;e<t.length-1;e++)if(ct(t[e],t[e+1],s,-1)){o.push({type:"edge-node-overlap",edgeId:c,targetId:s.nodeId,detail:`segment ${e} passes through node "${s.nodeId}"`});break}for(let o=0;o<t.length-1;o++)s.push({edgeId:c,start:e,end:n,p1:t[o],p2:t[o+1]})}const a=new Set;for(let i=0;i<s.length;i++)for(let t=i+1;t<s.length;t++){const e=s[i],n=s[t];if(e.edgeId!==n.edgeId&&e.start!==n.start&&e.start!==n.end&&e.end!==n.start&&e.end!==n.end&&ze(e.p1,e.p2,n.p1,n.p2)){const t=e.edgeId<n.edgeId?`${e.edgeId}|${n.edgeId}`:`${n.edgeId}|${e.edgeId}`;a.has(t)||(a.add(t),o.push({type:"edge-edge-crossing",edgeId:e.edgeId,targetId:n.edgeId,detail:`edges "${e.edgeId}" and "${n.edgeId}" cross`}))}}if(o.length>0){const t=o.filter(t=>"edge-node-overlap"===t.type).length,e=o.filter(t=>"edge-edge-crossing"===t.type).length;i.warn(`[SWIMLANE_VALIDATE] ${o.length} issue(s) detected: ${t} edge-node overlap(s), ${e} edge crossing(s)`);for(const n of o)i.warn(`[SWIMLANE_VALIDATE] ${n.type}: ${n.detail}`)}return o}function Ae(t,e){const n=t.nodes??[],o=t.edges??[],r=n.filter(t=>!t.isGroup);if(("LR"===e||"RL"===e)&&r.length>0&&!de(t,e))return;if("BT"===e&&r.length>0&&!fe(t))return;for(const a of o){if(a.isLayoutOnly)continue;const t=a.points;!t||t.length<2||(a.points=Rt($t(t)))}Te(o,n),Ye(o,n),he(o,n);const s=new Map;for(const a of n)s.set(String(a.id),a);Be(o,s),Yt(o,s),ge(o,s),Xe(o,s),ye(o,s),be(o,s),Me(o,s),we(o,s);const i=h(()=>{Ce(o,s),ve(o,s),Le(o,s),Be(o,s),ee(o,s),Me(o,s),Be(o,s),ee(o,s)},"finalizeRenderedEdges");i(),Xe(o,s),i(),Ie(o,s),Se(o,s),Ie(o,s),Se(o,s)}function Ge(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 De(t,e){return t.edges.filter(t=>t.dst===e)}function je(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 He(t){const e=je(t);for(const n of e.values())n.sort((t,e)=>t.localeCompare(e));return e}function _e(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 Ve(t){return[...t.entries()].filter(([,t])=>0===t).map(([t])=>t).sort((t,e)=>t.localeCompare(e))}function We(t,e=()=>!0){const n=new Map,o=new Map;for(const r of t.nodes)n.set(r,[]),o.set(r,[]);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 qe(t,e,n,o){let r=0;for(const i of t.nodes)o?.skipGroups&&t.nodeById.get(i)?.isGroup||(r=Math.max(r,n[i]??0));const s=Array.from({length:r+1},()=>[]);for(const i of e)o?.skipGroups&&t.nodeById.get(i)?.isGroup||s[Math.max(0,n[i]??0)].push(i);return s}function Je(t){const e=_e(t),n=Ve(e),o=[],r=He(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 Ke(t){const e=new Map;let n=0;for(const o of t)e.set(o,n),n++;return e}function Qe(t){const e=new Array(t.length),n=h((o,r)=>{if(r-o<=1)return 0;const s=o+r>>1;let i=n(o,s)+n(s,r),a=o,c=s,f=o;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 n=o;n<r;n++)t[n]=e[n];return i},"count");return n(0,t.length)}function Ze(t){const e=Ge(t),n=new Map;for(const f of e.nodes)n.set(f,[]);for(const f of e.edges)n.get(f.src).push(f);for(const f of n.values())f.sort((t,e)=>t.dst===e.dst?t.id.localeCompare(e.id):t.dst.localeCompare(e.dst));const o=Object.create(null);for(const f of e.nodes)o[f]=0;const r=[],s=h(t=>{o[t]=1;for(const e of n.get(t)??[]){const t=e.dst;0===o[t]?s(t):1===o[t]&&r.push(e)}o[t]=2},"dfs"),i=[...e.nodes].sort((t,e)=>t.localeCompare(e));for(const f of i)0===o[f]&&s(f);const a=new Set(r.map(t=>`${t.id}:${t.src}->${t.dst}`)),c=e.edges.map(t=>a.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:c,layout:e.layout,nodeById:new Map(e.nodeById)},reversed:r}}function Ue(t){const e=new Map,n=h(o=>{if(e.has(o))return e.get(o);const r=t.nodeById.get(o);if(!r)return e.set(o,null),null;const s=r.parentId;if(!s)return e.set(o,null),null;const i=n(s)??s;return e.set(o,i),i},"resolve");for(const o of t.nodes)n(o);return e}function tn(t){const e=Ue(t);return t=>e.get(t)??null}function en(t){const e=[];for(const n of t.layout.nodes??[])n.isGroup&&!n.parentId&&e.push(n.id);return[...new Set(e)].reverse()}function nn(t,e){const n=en(t);if(!e||0===e.length)return n;const o=new Set(n),r=new Set,s=[];for(const i of e)o.has(i)&&!r.has(i)&&(r.add(i),s.push(i));for(const i of n)r.has(i)||s.push(i);return s}h(Fe,"pairKey"),h(Ye,"straightenCollinearSiblingDetours"),h(Xe,"nudgeSharedInteriorSubpaths"),h(ze,"segmentsIntersect"),h(Pe,"validateSwimlanesLayout"),h(Ae,"postProcessSwimlaneLayout"),h(Ge,"normalizeGraph"),h(De,"incoming"),h(je,"buildSuccessorMap"),h(He,"buildSortedSuccessorMap"),h(_e,"buildInDegreeMap"),h(Ve,"sortedZeroInDegreeNodes"),h(We,"buildPredecessorSuccessorMaps"),h(qe,"buildLayersFromRanks"),h(Je,"topoSortIfAcyclic"),h(Ke,"buildLayerIndex"),h(Qe,"countInversions"),h(Ze,"removeCycles_DFS"),h(Ue,"buildTopLaneMap"),h(tn,"createTopLaneResolver"),h(en,"buildTopLaneOrder"),h(nn,"resolveTopLaneOrder");var on=!0;function rn(t,e){const n=Ge(t),o=e?.laneOf??(()=>null),r=e?.rankHint,{preds:s}=We(n);for(const h of s.values())h.sort((t,e)=>t.localeCompare(e));const i=Je(n)??[...n.nodes].sort((t,e)=>t.localeCompare(e)),a=new Map;for(const[h,S]of i.entries())a.set(S,h);const c=new Map,f=new Map;for(const h of n.nodes)f.set(h,[]);for(const h of i){const t=(s.get(h)??[]).filter(t=>c.has(t));if(t.length>0){const e=sn(h,t,{laneOf:o,rankHint:r,topoIndex:a});c.set(h,e),f.get(e).push(h)}else c.has(h)||c.set(h,null)}for(const h of n.nodes)c.has(h)||c.set(h,null);const d=new Set;for(const h of n.nodes)null===(c.get(h)??null)&&d.add(h);const l=[...d].sort((t,e)=>{const n=a.get(t)??0,o=a.get(e)??0;return n===o?t.localeCompare(e):n-o}),u=an(n),g=new Map;for(const[h,S]of u.entries())g.set(h,[...S].sort((t,e)=>t.localeCompare(e)));const p=cn(g),x=fn(g),m=new Map;for(const h of n.nodes)m.set(h,[]);for(const h of x)for(const t of h.nodes){const e=m.get(t);e?e.push(h.id):m.set(t,[h.id])}const y=[],b=[],M=new Set,I=h(t=>{if(!M.has(t)){M.add(t),y.push(t);for(const e of f.get(t)??[])I(e);b.push(t)}},"walk");for(const h of l)I(h);for(const h of i)I(h);return{parent:c,children:f,roots:l,componentOf:p,blocks:x,nodeBlocks:m,adjacency:g,preorder:y,postorder:b,topologicalOrder:i}}function sn(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 an(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 cn(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 fn(t){const e=new Map,n=new Map,o=[],r=[];let s=0;const i=h((a,c)=>{e.set(a,++s),n.set(a,s);for(const f of t.get(a)??[])f!==c&&(e.has(f)?(e.get(f)??0)<(e.get(a)??0)&&(o.push([a,f]),n.set(a,Math.min(n.get(a)??s,e.get(f)??s))):(o.push([a,f]),i(f,a),n.set(a,Math.min(n.get(a)??s,n.get(f)??s)),(n.get(f)??0)>=(e.get(a)??0)&&r.push(dn(a,f,o,r.length))))},"visit");for(const a of t.keys())e.has(a)||i(a,null);return r}function dn(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 ln(t,e,n){const o=[...t.nodes],r=new Map;for(const[h,b]of o.entries())r.set(b,h);const s=o.length,i=new Array(s).fill(-1),a=new Array(s).fill(0),c=[],f=new Set;for(const h of o){const t=n.parent.get(h)??null,e=r.get(h);null!=e&&null==t&&(i[e]=-1,a[e]=0,f.has(h)||(f.add(h),c.push(h)))}for(;c.length>0;){const t=c.shift(),e=r.get(t);if(null==e)continue;const o=n.children.get(t)??[];for(const n of o){if(f.has(n))continue;const t=r.get(n);null!=t&&(i[t]=e,a[t]=a[e]+1,f.add(n),c.push(n))}}for(const h of o){if(f.has(h))continue;const t=r.get(h);null!=t&&(i[t]=-1,a[t]=0,f.add(h))}const d=Math.max(1,Math.ceil(Math.log2(Math.max(1,s)))+1),l=Array.from({length:d},()=>new Array(s).fill(-1));for(let h=0;h<s;h++)l[0][h]=i[h];for(let h=1;h<d;h++)for(let t=0;t<s;t++){const e=l[h-1][t];l[h][t]=-1===e?-1:l[h-1][e]}const u=h((t,e)=>{if(-1===t||-1===e)return-1;a[t]<a[e]&&([t,e]=[e,t]);const n=a[t]-a[e];for(let o=0;o<d;o++)if(n>>o&1&&-1===(t=l[o][t]))return-1;if(t===e)return t;for(let o=d-1;o>=0;o--){const n=l[o][t],r=l[o][e];-1!==n&&-1!==r&&n!==r&&(t=n,e=r)}return l[0][t]},"lcaIndex"),g=Array.from({length:s},()=>new Map);for(const h of t.edges){let t=h.src,n=h.dst,o=e[t],s=e[n];if(null==o||null==s)continue;if(o>s&&([t,n]=[n,t],[o,s]=[s,o]),null==o||null==s||o===s)continue;const i=r.get(t),a=r.get(n);if(null==i||null==a)continue;const c=u(i,a);if(-1===c)continue;const f=g[c];for(let e=o;e<s;e++)f.set(e,(f.get(e)??0)+1)}const p=new Map,x=h((t,e)=>{if(0!==e.size)for(const[n,o]of e)t.set(n,(t.get(n)??0)+o)},"mergeInto"),m=new Set,y=h(t=>{const o=r.get(t);m.add(t);const s=null==o?void 0:g[o],i=s?new Map(s):new Map,a=n.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)}x(i,o)}return i},"dfs");for(const h of n.roots)m.has(h)||y(h);for(const h of o)m.has(h)||y(h);return p}function un(t,e,n){const o=new Map,r=h(t=>{let s=n[t]??0;const i=[...e.get(t)??[]];i.sort(hn(n));for(const e of i){r(e);const t=o.get(e);null!=t&&(s=Math.min(s,t))}o.set(t,s)},"annotate");for(const s of t)r(s);return o}function hn(t){return(e,n)=>{const o=t[e]??0,r=t[n]??0;return o===r?e.localeCompare(n):o-r}}function gn(t,e,n,o){let r=0;for(const c of e){const t=n[c]??0;t>r&&(r=t)}const s=Array.from({length:r+1},()=>[]),i=new Set,a=h(t=>{if(i.has(t))return;i.add(t);const e=n[t]??0;s[e]||(s[e]=[]),s[e].push(t);for(const n of o(t))a(n)},"emit");for(const c of t)a(c);for(const c of e)if(!i.has(c)){const t=n[c]??0;s[t]||(s[t]=[]),s[t].push(c),i.add(c)}return s}function pn(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 xn(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 mn(t,e,n){const o=rn(t,{rankHint:e,laneOf:n}),{children:r,roots:s}=o;for(const d of t.nodes)r.has(d)||r.set(d,[]);const i=ln(t,e,o),a=[...s].sort(hn(e)),c=xn(r,e,i,un(a,r,e));let f=gn(a,t.nodes,e,c);return f=pn(f),f}function yn(t,e,n){const o=new Set(t),r=new Set(e),s=Ke(e),i=[];for(const a of n)o.has(a.src)&&r.has(a.dst)&&i.push(s.get(a.dst));return Qe(i)}function bn(t,e,n){const o=[];for(const s of e){const t=n[s.src],e=n[s.dst];if(null==t||null==e||t===e)continue;let r=s.src,i=s.dst,a=t,c=e;t>e&&(r=s.dst,i=s.src,a=e,c=t);for(let n=a;n<c;n++)o.push({id:`${s.id}@${n}`,src:r,dst:i,ref:s.ref})}let r=0;for(let s=0;s+1<t.length;s++)r+=yn(t[s],t[s+1],o);return r}function Mn(t,e){const n={...e},{preds:o}=We(t),r=tn(t);let s=bn(mn(t,n,r),t.edges,n);for(let i=0;i<4;i++){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=bn(mn(t,n,r),t.edges,n);d<s?(s=d,e=!0):n[a]=f}if(!e)break}return n}function In(t,e){const n=tn(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 Sn(t,e){const n=Ge(t),o=Je(n)??[...n.nodes].sort(),r=e?.compactSingleInput??!1,s=tn(n);let i=Object.create(null);for(const a of o){const t=De(n,a),o=e?.ignoreCrossLaneEdges?t.filter(t=>{const e=s(t.src),n=s(a);return!e||!n||e===n}):t;if(0===o.length)i[a]=0;else if(r&&1===o.length){const t=o[0].src,e=s(t),n=s(a);i[a]=e!==n?i[t]??0:(i[t]??0)+1}else{let t=-1/0;for(const e of o)t=Math.max(t,(i[e.src]??0)+1);i[a]=t===-1/0?0:t}}return e?.optimizeRanksByCrossings&&(i=Mn(n,i)),e?.ignoreCrossLaneEdges&&In(n,i),{layers:mn(n,i,s),rankOf:i,dummy:new Set}}function wn(t,e){const n=Ge(t),o={...Sn(n,{compactSingleInput:e?.compactSingleInput,ignoreCrossLaneEdges:e?.ignoreCrossLaneEdges,optimizeRanksByCrossings:e?.optimizeRanksByCrossings}).rankOf},r=tn(n),{preds:s,succs:i}=We(n,t=>{if(e?.ignoreCrossLaneEdges){const e=r(t.src),n=r(t.dst);if(e&&n&&e!==n)return!1}return!0}),a=Je(n)??[...n.nodes],c=[...a].reverse(),f=h((t,e)=>{let n=0;for(const i of s.get(t)??[])n=Math.max(n,(o[i]??0)+1);let r=Number.POSITIVE_INFINITY;const a=i.get(t)??[];return a.length>0&&(r=Math.min(...a.map(t=>(o[t]??0)-1))),Number.isFinite(r)||(r=Math.max(n,e)),Math.min(Math.max(e,n),r)},"clampFeasible"),d=h(t=>{let e=!1;for(const n of t){const t=s.get(n)??[],r=i.get(n)??[];if(0===t.length&&0===r.length)continue;const a=t.length>0?t.reduce((t,e)=>t+(o[e]??0)+1,0)/t.length:o[n]??0,c=r.length>0?r.reduce((t,e)=>t+(o[e]??0)-1,0)/r.length:o[n]??0,d=Math.round((a+c)/2),l=f(n,d);l!==o[n]&&(o[n]=l,e=!0)}return e},"relaxOrder");for(let l=0;l<8;l++){const t=d(a),e=d(c);if(!t&&!e)break}for(const l of a){let t=0;for(const e of s.get(l)??[])t=Math.max(t,(o[e]??0)+1);(o[l]??0)<t&&(o[l]=t)}for(const l of c){const t=i.get(l)??[];if(t.length>0){const e=Math.min(...t.map(t=>(o[t]??0)-1));(o[l]??0)>e&&(o[l]=e)}}return{layers:qe(n,a,o),rankOf:o,dummy:new Set}}function vn(t){const e=_e(t),n=He(t);let o=Ve(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 Ln(t,e){const n=Ge(t),o="LR"===e?.direction?vn(n)??[...n.nodes].sort():Je(n)??[...n.nodes].sort(),r=tn(n),s=h(t=>r(t)??t,"laneOf"),i=Object.create(null),a=new Map,c=h((t,n)=>e?.ignoreCrossLaneEdges??1?s(t)===s(n)?1:0:1,"edgeWeight");for(const f of o){const t=n.nodeById.get(f);if(t?.isGroup)continue;const e=De(n,f);let o=0;if(e.length>0)for(const n of e){const t=n.src,e=i[t]??0;o=Math.max(o,e+c(t,f))}const r=s(f),d=a.get(r)??0,l=Math.max(o,d);i[f]=l,a.set(r,l+1)}return{layers:qe(n,o,i,{skipGroups:!0}),rankOf:i,dummy:new Set}}function Cn(t,e){const n=Ge(e),{rankOf:o}=t,r=t.layers.map(t=>[...t]),s=new Set(t.dummy?[...t.dummy]:[]);let i=0;const a=new Map(n.nodeById),c=h(t=>{const e="placeholder-"+i++,n={id:e,isGroup:!1,isDummy:!0,width:0,height:0};for(a.set(e,n),s.add(e);r.length<=t;)r.push([]);return r[t].push(e),o[e]=t,e},"addDummyAt"),f=[...n.edges].sort((t,e)=>t.id===e.id?t.src===e.src?t.dst.localeCompare(e.dst):t.src.localeCompare(e.src):t.id.localeCompare(e.id)),d=[];for(const u of f){const t=o[u.src]??0,e=o[u.dst]??0;if(e-t<=1){d.push(u);continue}let n=u.src;for(let o=t+1,s=0;o<e;o++,s++){const t=c(o);d.push({id:`${u.id}#${s}`,src:n,dst:t,weight:u.weight,ref:u.ref}),n=t}const r=e-t-2;d.push({id:`${u.id}#${Math.max(r+1,0)}`,src:n,dst:u.dst,weight:u.weight,ref:u.ref})}const l={nodes:[...n.nodes,...[...s].filter(t=>!n.nodes.includes(t))],edges:d,layout:n.layout,nodeById:a};return{layering:{layers:r,rankOf:o,dummy:s},graphWithDummies:l}}function kn(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 Tn(t){return 0===t.length?Number.POSITIVE_INFINITY:t.reduce((t,e)=>t+e,0)/t.length}function On(t,e,n,o){const r=new Map;for(const s of t)r.set(s,[]);for(const s of n)"down"===o?e.has(s.src)&&r.has(s.dst)&&r.get(s.dst).push(e.get(s.src)):e.has(s.dst)&&r.has(s.src)&&r.get(s.src).push(e.get(s.dst));return r}function $n(t,e,n){const o=n.get(t)??0,r=n.get(e)??0;return o!==r?o-r:t.localeCompare(e)}function Rn(t,e,n){const o=new Set(t),r=new Set(e),s=Ke(t),i=Ke(e),a=[];for(const c of n)o.has(c.src)&&r.has(c.dst)&&a.push({u:s.get(c.src),v:i.get(c.dst)});return a.sort((t,e)=>t.u===e.u?t.v-e.v:t.u-e.u),Qe(a.map(t=>t.v))}function Nn(t,e,n){return[...t].sort((t,o)=>{const r=kn(e.get(t)??[]),s=kn(e.get(o)??[]);return r===s?$n(t,o,n):isFinite(r)?isFinite(s)?r-s:-1:1})}function Bn(t,e,n,o,r,s){const i=Ke(t),a=Ke(e),c=On(e,i,n,o);if(!r||!s||0===s.length)return Nn(e,c,a);const f=new Map;for(const u of e){const t=r(u),e=f.get(t)??[];e.push(u),f.set(t,e)}const d=[];for(const u of s){const t=f.get(u);if(!t||0===t.length)continue;const e=Nn(t,c,a);d.push(...e)}const l=f.get(null);if(l&&l.length>0){const t=Nn(l,c,a);for(const e of t){const t=Tn(c.get(e)??[]);let n=d.length;if(isFinite(t))for(const[e,o]of d.entries())if(t<Tn(c.get(o)??[])){n=e;break}d.splice(n,0,e)}}return d}function En(t,e,n,o,r){const s=[...e],i=new Set(t),a=new Set(e),c=o?new Set(o):null,f=n.filter(t=>i.has(t.src)&&a.has(t.dst)),d=c?n.filter(t=>a.has(t.src)&&c.has(t.dst)):void 0,l=h(e=>{let n=Rn(t,e,f);return d&&o&&(n+=Rn(e,o,d)),n},"crossingScore"),u=r?new Map:null;if(r&&u)for(const h of e)u.set(h,r(h));let g=!0,p=l(s);for(;g;){g=!1;for(let t=0;t+1<s.length;t++){if(u&&u.get(s[t])!==u.get(s[t+1]))continue;const e=p;[s[t],s[t+1]]=[s[t+1],s[t]];const n=l(s);n<e?(p=n,g=!0):[s[t],s[t+1]]=[s[t+1],s[t]]}}return s}function Fn(t,e,n){const o=t.layers.map(t=>[...t]),r=e.edges,s=tn(e),i=nn(e,n?.laneOrder);for(let a=0;a<3;a++){for(let t=1;t<o.length;t++)o[t]=Bn(o[t-1],o[t],r,"down",s,i),o[t]=En(o[t-1],o[t],r,o[t+1],s);for(let t=o.length-2;t>=0;t--)o[t]=Bn(o[t+1],o[t],r,"up",s,i),o[t]=En(o[t+1],o[t],r,o[t-1],s)}return{layers:o}}function Yn(t,e,n){const o=n?.layerGap??100,r=n?.nodeGap??40,s=n?.laneGap??2*r,i=n?.direction??"TB",a="LR"===i||"RL"===i,c=t.layers,f=Object.create(null),d=Object.create(null),l=h(t=>e.nodeById.get(t),"getNode"),u=h(t=>l(t)?.width??0,"getWidth"),g=h(t=>l(t)?.height??0,"getHeight"),p=tn(e),x=nn(e,n?.laneOrder),m=c.map(t=>t.reduce((t,e)=>Math.max(t,g(e)),0)),y=[];if(a)for(let h=0;h+1<c.length;h++){const t=c[h].reduce((t,e)=>Math.max(t,u(e)),0),e=c[h+1].reduce((t,e)=>Math.max(t,u(e)),0),n=m[h]/2+m[h+1]/2,r=(t+e)/2,s=Math.max(0,r-n-o);y.push(s)}const b=new Set;for(const h of c)for(const t of h)b.add(p(t));const M=b.has(null),I=x.filter(t=>b.has(t)),S=[...M?[null]:[],...I],w=Object.create(null);for(const h of I)w[h]=0;M&&(w.null=0);for(const h of c){const t=Object.create(null),e=[];for(const n of h){const o=p(n);null===o?e.push(n):(t[o]||=[]).push(n)}for(const[n,o]of Object.entries(t)){const t=o.reduce((t,e)=>t+u(e),0)+r*Math.max(0,o.length-1);w[n]=Math.max(w[n]??0,t)}if(M&&e.length){const t=e.reduce((t,e)=>t+u(e),0)+r*Math.max(0,e.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)+s*Math.max(0,S.length-1))/2;for(let n=0;n<S.length;n++){const o=S[n],r=t[n]??0,i=e+r/2;v.set(o,i),e+=r,n<S.length-1&&(e+=s)}}let L=0;for(const[h,k]of c.entries()){const t=m[h]??0,e=new Map;for(const n of k){const t=p(n),o=e.get(t)??[];o.push(n),e.set(t,o)}for(const n of S){const o=e.get(n)??[];if(0===o.length)continue;const s=v.get(n);if(1===o.length){const e=o[0];f[e]=s,d[e]=L+t/2}else{const e=o.map(t=>u(t));let n=s-(e.reduce((t,e)=>t+e,0)+r*(o.length-1))/2;for(const[s,i]of o.entries()){const o=e[s];f[i]=n+o/2,d[i]=L+t/2,n+=o+r}}}L+=t+o+(y[h]??0)}const C=new Map;for(const h of e.edges){const t=h.ref.id;C.has(t)||C.set(t,[]),C.get(t).push(h)}for(const[,h]of C){if(0===h.length)continue;const t=h[0].ref,n=t.start,o=t.end;if(null==n||null==o)continue;const r=Math.round(((f[n]??0)+(f[o]??0))/2),s=new Set;for(const e of h)s.add(e.src),s.add(e.dst);for(const i of s){if(i===n||i===o)continue;const t=e.nodeById.get(i);t?.isDummy&&(f[i]=r)}}return{x:f,y:d}}function Xn(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 zn(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 Pn(t,e){const n=[...t],o=zn(e);for(let r=n.length-1;r>0;r--){const t=Math.floor(o()*(r+1));[n[r],n[t]]=[n[t],n[r]]}return n}function An(t,e){let n=0;for(const[o,r]of t.entries())n+=Math.abs(o-(e.get(r)??o));return n}function Gn(t,e){const n=new Map;for(const[r,s]of t.entries())n.set(s,r);let o=0;for(const{a:r,b:s,weight:i}of e){const t=n.get(r),e=n.get(s);null!=t&&null!=e&&(o+=i*Math.abs(t-e))}return o}function Dn(t){const e=en(t);if(e.length<2)return[];const n=new Map(e.map((t,e)=>[t,e])),o=tn(t),r=new Map;for(const s of t.layout.edges??[]){if(s.isLayoutOnly)continue;const e="string"==typeof s.start?s.start:void 0,i="string"==typeof s.end?s.end:void 0;if(!(e&&i&&t.nodeById.has(e)&&t.nodeById.has(i)))continue;const a=o(e),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 jn(t,e,n){const o=[...t];let r=Gn(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=Gn(o,e);n<r?(r=n,s=!0):[o[t],o[t+1]]=[o[t+1],o[t]]}}return{order:o,cost:r,sourceDistance:An(o,n)}}function Hn(t,e){return t.cost!==e.cost?t.cost<e.cost:t.sourceDistance<e.sourceDistance}function _n(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 Xn(`${t.join("|")}#${o}#${n}`)}function Vn(t,e={}){const n=en(t);if(n.length<2)return n;const o=Dn(t);if(0===o.length)return n;const r=new Map(n.map((t,e)=>[t,e]));let s=jn(n,o,r);const i=Math.max(0,e.restarts??8);for(let a=0;a<i;a++){const t=jn(Pn(n,_n(n,o,a)),o,r);Hn(t,s)&&(s=t)}return s.order}function Wn(t,e){const n=e?.ignoreCrossLaneEdges??!0,o=e?.optimizeRanksByCrossings??!0,r=Ge(t),s=e?.automaticLaneOrdering?Vn(r,{restarts:8}):void 0,i=Ze(r),a=i.acyclic,c=n?Ln(a,{compactSingleInput:e?.compactSingleInput??on,ignoreCrossLaneEdges:!0,direction:e?.direction}):wn(a,{compactSingleInput:e?.compactSingleInput??on,ignoreCrossLaneEdges:!1,optimizeRanksByCrossings:o}),{layering:f,graphWithDummies:d}=Cn(c,a),l=Fn(f,d,{laneOrder:s}),u=Yn(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}}h(rn,"buildDrivingTree"),h(sn,"chooseParent"),h(an,"buildAdjacency"),h(cn,"assignComponents"),h(fn,"computeBlocks"),h(dn,"popBlock"),h(ln,"computeSubtreeCrossCounts"),h(un,"annotateMinimumLayers"),h(hn,"compareByRankThenId"),h(gn,"emitNodesInTreeOrder"),h(pn,"deduplicateLayers"),h(xn,"createChildOrderer"),h(mn,"buildMultitreeLayerOrder"),h(yn,"countCrossingsBetweenAdjacent"),h(bn,"totalCrossings"),h(Mn,"optimizeRanksByCrossings"),h(In,"adjustCrossLaneSources"),h(Sn,"assignLayers_LongestPath"),h(wn,"assignLayers_Gravity"),h(vn,"topoSortByGenerationIfAcyclic"),h(Ln,"assignLayers_LaneAwareCompact"),h(Cn,"makeProperLayering"),h(kn,"median"),h(Tn,"barycenter"),h(On,"neighborPositionsFor"),h($n,"currentOrderTieBreak"),h(Rn,"countCrossingsBetweenAdjacent"),h(Nn,"sortByHeuristic"),h(Bn,"reorderLayer"),h(En,"transposeImprove"),h(Fn,"orderLayers"),h(Yn,"assignCoordinates"),h(Xn,"hashString"),h(zn,"mulberry32"),h(Pn,"deterministicShuffle"),h(An,"sourceDistance"),h(Gn,"laneArrangementCost"),h(Dn,"buildWeightedLaneEdges"),h(jn,"greedySwitch"),h(Hn,"isBetterCandidate"),h(_n,"seedForRestart"),h(Vn,"optimizeTopLaneOrder"),h(Wn,"sugiyamaLayout");var qn=1e-6,Jn=15,Kn=15,Qn=20;function Zn(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);return a<qn&&c<qn?n:c>qn&&3*c>=a?i>0?"bottom":"top":a>qn?s>0?"right":"left":n}function Un(t,e){return Math.abs(t.to-e.from)<qn||Math.abs(t.to-e.to)<qn?t.to:t.from}function to(t,e){return"vertical"===t.orient?{x:t.coord,y:e}:{x:e,y:t.coord}}function eo(t,e){const n=t.nodes??[],o=t.edges??[],r=[];for(const h of o)h.isLayoutOnly||r.push({...h,__originalEdge:h});const s=new Map,i=new Map,a=[],c="LR"===e;for(const h of n)s.set(h.id,h);const f=n.filter(t=>t.isGroup&&!t.parentId);for(const nt of f){const t={id:nt.id},e=h(o=>{i.set(o.id,t),n.filter(t=>t.parentId===o.id).forEach(e)},"assignLane");e(nt)}const d=n.filter(t=>!t.isGroup&&!t.isEdgeLabel).map(t=>{const e=t.width??10,n=t.height??10,o=t.x??0,r=t.y??0;return{nodeId:t.id,minX:o-e/2-8,maxX:o+e/2+8,minY:r-n/2-8,maxY:r+n/2+8,visualXHalfExtent:c?n/2+8:e/2+8}}),l=h((t,e,n,o)=>{let r=a.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:[]},a.push(r)),r.spanMin=Math.min(r.spanMin,n),r.spanMax=Math.max(r.spanMax,o),r},"getOrAddPipe"),u=h((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=h((t,e,n)=>u(t,Zn(t,e,n?"bottom":"top")),"getOrthogonalPort"),p=[],x=[],m=new Set,y=h((t,e,n)=>{if(0===p.length)return 0;const o=Math.abs(e.y-n.y)<qn,r=Math.abs(e.x-n.x)<qn;if(!o&&!r)return 0;let s=0;if(o){const o=e.y,r=Math.min(e.x,n.x)-qn,i=Math.max(e.x,n.x)+qn;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-qn<=o&&e.to+qn>=o&&(s+=1e3))}else if(r){const o=e.x,r=Math.min(e.y,n.y)-qn,i=Math.max(e.y,n.y)+qn;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-qn<=o&&e.to+qn>=o&&(s+=1e3))}return s},"crossingPenalty"),b=r.map((t,e)=>{if(!t.start||!t.end)return{idx:e,crossLane:0,dx:0,dy:0};const n=s.get(t.start),o=s.get(t.end),r=i.get(t.start),a=i.get(t.end);return{idx:e,crossLane:r&&a&&r.id!==a.id?1:0,dx:n&&o?Math.abs((o.x??0)-(n.x??0)):0,dy:n&&o?Math.abs((o.y??0)-(n.y??0)):0}}).sort((t,e)=>{if(t.crossLane!==e.crossLane)return e.crossLane-t.crossLane;const n=t.dx+t.dy,o=e.dx+e.dy;return Math.abs(n-o)>1?n-o:t.idx-e.idx}).map(t=>t.idx),M=h((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!!d.find(c=>!(n&&c.nodeId===n||o&&c.nodeId===o||!(Math.abs(t.x-e.x)>qn?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 h of r)h.start&&h.end&&h.start!==h.end&&(S.set(h.start,(S.get(h.start)??0)+1),S.set(h.end,(S.get(h.end)??0)+1));const w=h((t,e)=>Zn(t,e,"bottom"),"determineSide"),v=new Map;for(const[h,nt]of r.entries()){if(!nt.start||!nt.end||nt.start===nt.end)continue;if(nt.points&&nt.points.length>0)continue;const t=s.get(nt.start),e=s.get(nt.end);if(!t||!e)continue;const n=(e.x??0)-(t.x??0),o=(e.y??0)-(t.y??0);v.set(h,{edgeIdx:h,srcId:nt.start,dstId:nt.end,srcSide:w(t,{x:e.x??0,y:e.y??0}),dstSide:w(e,{x:t.x??0,y:t.y??0}),absDx:Math.abs(n),absDy:Math.abs(o),dxSign:Math.sign(n),dySign:Math.sign(o)})}const L=h(t=>"top"===t.srcSide||"bottom"===t.srcSide?0===t.absDx?1/0:t.absDy/t.absDx:0===t.absDy?1/0:t.absDx/t.absDy,"preferenceStrength"),C=h(t=>"top"===t.srcSide||"bottom"===t.srcSide?t.dxSign>=0?"right":"left":t.dySign>=0?"bottom":"top","secondarySide"),k=new Map;for(const h of v.values()){const t=`${h.srcId}:${h.srcSide}`;k.has(t)||k.set(t,[]),k.get(t).push(h)}const T=new Map,O=h((t,e)=>`${t}:${e}`,"loadKey");for(const h of v.values())T.set(O(h.srcId,h.srcSide),(T.get(O(h.srcId,h.srcSide))??0)+1),T.set(O(h.dstId,h.dstSide),(T.get(O(h.dstId,h.dstSide))??0)+1);for(const h of k.values())if(!(h.length<2)){h.sort((t,e)=>{const n=L(t),o=L(e);return Math.abs(n-o)>1e-9?o-n:t.edgeIdx-e.edgeIdx});for(let t=1;t<h.length;t++){const e=h[t],n=C(e),o=T.get(O(e.srcId,e.srcSide))??0,r=T.get(O(e.srcId,n))??0;r>=o||(T.set(O(e.srcId,e.srcSide),o-1),T.set(O(e.srcId,n),r+1),e.srcSide=n)}}const $=h(t=>{const e=t?.shape;return"question"===e||"diamond"===e},"isDiamondNode"),R=new Map;for(const h of v.values())R.has(h.dstId)||R.set(h.dstId,new Set),R.get(h.dstId).add(h.dstSide);for(const h of v.values()){if(!$(s.get(h.srcId)))continue;const t=R.get(h.srcId);if(!t?.has(h.srcSide))continue;const e=C(h);if(t.has(e)||(T.get(O(h.srcId,e))??0)>0)continue;const n=T.get(O(h.srcId,h.srcSide))??0;T.set(O(h.srcId,h.srcSide),Math.max(0,n-1)),T.set(O(h.srcId,e),1),h.srcSide=e}for(const h of v.values()){const{edgeIdx:t,srcId:e,dstId:n,srcSide:o,dstSide:r}=h,i=s.get(e),a=s.get(n),c=`${e}:${o}:src`,f="top"===o||"bottom"===o?a.x??0:a.y??0;I.has(c)||I.set(c,[]),I.get(c).push({edgeIdx:t,oppositeCoord:f});const d=`${n}:${r}:dst`,l="top"===r||"bottom"===r?i.x??0:i.y??0;I.has(d)||I.set(d,[]),I.get(d).push({edgeIdx:t,oppositeCoord:l})}const N=new Map;for(const[h,nt]of I){if(nt.length<2)continue;nt.sort((t,e)=>t.oppositeCoord-e.oppositeCoord);const t=h.split(":"),e=t.slice(0,-2).join(":"),n=t[t.length-2],o=t[t.length-1],r=s.get(e);if(!r)continue;const i="left"===n||"right"===n?r.height??10:r.width??10,a=r.shape,c="question"===a||"diamond"===a?.3*i:i,f=20,d=Math.min(f,Math.max(8,c/(nt.length+1))),l=-d*(nt.length-1)/2;for(const[s,u]of nt.entries()){const t=l+s*d,e=`${u.edgeIdx}:${o}`;N.set(e,t)}}const B=h(t=>Boolean(r[t]?.labelNodeId),"edgeHasLabelNode"),E=h((t,e)=>!!t&&((I.get(`${t}:${e}:src`)??[]).some(({edgeIdx:t})=>B(t))||(I.get(`${t}:${e}:dst`)??[]).some(({edgeIdx:t})=>B(t))),"faceHasLabelNode"),F=h((t,e,n)=>"top"===e||"bottom"===e?{x:t.x+n,y:t.y}:{x:t.x,y:t.y+n},"applyPortOffset"),Y=h((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?u(e,o.srcSide):g(e,r,!0),f=o?u(n,o.dstSide):g(n,s,!1);const d=N.get(`${t}:src`),l=N.get(`${t}:dst`);return void 0!==d&&(c=F(c,i,d)),void 0!==l&&(f=F(f,a,l)),{pSrcPort:c,pDstPort:f,srcSide:i,dstSide:a}},"portsForEdge");for(const nt of b){const t=r[nt];if(x[nt]=[],!t.start||!t.end)continue;if(t.points&&t.points.length>0)continue;if(t.start===t.end)continue;const e=s.get(t.start),n=s.get(t.end);if(!e||!n)continue;const{pSrcPort:o,pDstPort:i,srcSide:f,dstSide:u}=Y(nt,e,n),g={...o},b={...i},w="top"===f||"bottom"===f,v="top"===u||"bottom"===u;if(w){const t=o.y>(e.y??0);g.y=t?o.y+Qn:o.y-Qn}else{const t=o.x>(e.x??0);g.x=t?o.x+Qn:o.x-Qn}if(v){const t=i.y>(n.y??0);b.y=t?i.y+Qn:i.y-Qn}else{const t=i.x>(n.x??0);b.x=t?i.x+Qn:i.x-Qn}const L=h((t,e)=>{for(const n of d)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"),C=h((t,e,n,o,r)=>{if(r){const r=t.y>(e.y??0);return{x:(n.x??0)>=t.x?o.maxX+Jn:o.minX-Jn,y:r?o.maxY+Kn:o.minY-Kn,leavesPositiveSide:r}}const s=t.x>(e.x??0),i=(n.y??0)>=t.y;return{x:s?o.maxX+Jn:o.minX-Jn,y:i?o.maxY+Kn:o.minY-Kn,leavesPositiveSide:s}},"obstacleDetour");let k=[];const T=[t.start,t.end],O=L(g,T);if(O.inside&&O.obstacle){const t=O.obstacle;if(w){const r=C(o,e,n,t,!0);g.x=r.x,g.y=r.y;const s=r.leavesPositiveSide?Math.min(t.minY-2,o.y+Qn):Math.max(t.maxY+2,o.y-Qn);k=[{x:o.x,y:s},{x:r.x,y:s},{x:r.x,y:r.y}]}else{const r=C(o,e,n,t,!1),s=r.leavesPositiveSide?Math.min(t.minX-2,o.x+Qn):Math.max(t.maxX+2,o.x-Qn);g.x=r.x,g.y=r.y,k=[{x:s,y:o.y},{x:s,y:r.y},{x:r.x,y:r.y}]}}let $=[];const R=L(b,T);if(R.inside&&R.obstacle){const t=R.obstacle;if(v){const o=C(i,n,e,t,!0);b.x=o.x,b.y=o.y,$=[{x:o.x,y:o.y},{x:i.x,y:o.y}]}else{const o=C(i,n,e,t,!1);b.x=o.x,b.y=o.y,$=[{x:o.x,y:o.y},{x:o.x,y:i.y}]}}if(0===k.length&&0===$.length){const e=Jn,n=Math.abs(g.x-b.x)<e,r=Math.abs(g.y-b.y)<e,s=void 0!==N.get(`${nt}:src`)||void 0!==N.get(`${nt}:dst`),a=(I.get(`${t.start??""}:${f}:src`)?.length??0)+(I.get(`${t.start??""}:${f}:dst`)?.length??0),c=(I.get(`${t.end??""}:${u}:src`)?.length??0)+(I.get(`${t.end??""}:${u}:dst`)?.length??0),d=a>1||c>1,l=S.get(t.start??"")??0,h=S.get(t.end??"")??0,x=a>1&&E(t.start,f)||c>1&&E(t.end,u);if((n||r)&&!s&&(!d||d&&!x&&(a<=1||l<=2)&&(c<=1||h<=2))&&!M(o,i,t.start,t.end)){t.points=[{...o},{...g},{...b},{...i}],m.add(nt);const e=r?"horizontal":"vertical",n=r?o.y:o.x,s=r?Math.min(o.x,i.x):Math.min(o.y,i.y),a=r?Math.max(o.x,i.x):Math.max(o.y,i.y),c={id:`fast-path-${e}-${n.toFixed(0)}-${nt}`,orientation:e,coord:n,spanMin:s,spanMax:a,tracks:[]};p.push({edgeIndex:nt,segmentIndex:0,orientation:e,pipe:c,trackIndex:0,from:s,to:a});continue}}const B=l("vertical",g.x,g.y,g.y);g.x=B.coord;const F=l("vertical",b.x,b.y,b.y);b.x=F.coord;let X=Math.min(g.x,b.x)-50,z=Math.max(g.x,b.x)+50,P=Math.min(g.y,b.y)-50,A=Math.max(g.y,b.y)+50;for(const r of d){const t=Math.min(g.x,b.x),e=Math.max(g.x,b.x),n=Math.min(g.y,b.y),o=Math.max(g.y,b.y);r.minX<e&&r.maxX>t&&r.minY<o&&r.maxY>n&&(X=Math.min(X,r.minX-25),z=Math.max(z,r.maxX+25),P=Math.min(P,r.minY-25),A=Math.max(A,r.maxY+25))}for(const r of d){if(r.maxX<X||r.minX>z||r.maxY<P||r.minY>A)continue;const t=Jn;l("horizontal",r.minY-t,X,z),l("horizontal",r.maxY+t,X,z);const e=Kn;l("vertical",r.minX-e,P,A),l("vertical",r.maxX+e,P,A)}l("horizontal",g.y,X,z),l("horizontal",b.y,X,z);const G=a.filter(t=>"horizontal"===t.orientation&&t.coord>=P&&t.coord<=A),D=a.filter(t=>"vertical"===t.orientation&&t.coord>=X&&t.coord<=z),j=h((t,e)=>`${t.toFixed(1)},${e.toFixed(1)}`,"getKey"),H=j(g.x,g.y),_=j(b.x,b.y),V=new Map,W=new Map,q=new Map,J=new Set,K=[];V.set(H,0),q.set(H,"n"),K.push({key:H,f:Math.hypot(b.x-g.x,b.y-g.y),pt:g}),J.add(H);let Q=[];const Z=h((e,n)=>M(e,n,t.start,t.end),"checkSegmentBlocked"),U={x:b.x,y:g.y},tt=Z(g,U),et=Z(U,b),ot=tt||et,rt={x:g.x,y:b.y},st=Z(g,rt),it=Z(rt,b);if(ot?st||it||(Q=Math.abs(g.x-b.x)<qn?[g,b]:[g,rt,b]):Q=Math.abs(g.y-b.y)<qn||Math.abs(g.x-b.x)<qn?[g,b]:[g,U,b],0===Q.length)for(;K.length>0;){K.sort((t,e)=>t.f-e.f);const e=K.shift();if(J.delete(e.key),e.key===_){let t=_,e=b;for(Q=[e];W.has(t);){const n=W.get(t);Q.unshift(n),e=n,t=j(n.x,n.y)}break}const n=e.pt.x,o=e.pt.y,r=D.sort((t,e)=>t.coord-e.coord),s=r.findIndex(t=>Math.abs(t.coord-n)<1),i=G.sort((t,e)=>t.coord-e.coord),a=i.findIndex(t=>Math.abs(t.coord-o)<1),c=[];s>0&&c.push({x:r[s-1].coord,y:o}),s>=0&&s<r.length-1&&c.push({x:r[s+1].coord,y:o}),a>0&&c.push({x:n,y:i[a-1].coord}),a>=0&&a<i.length-1&&c.push({x:n,y:i[a+1].coord});for(const f of c){const r=Math.min(n,f.x),s=Math.max(n,f.x),i=Math.min(o,f.y),a=Math.max(o,f.y);if(d.some(e=>e.nodeId!==t.start&&e.nodeId!==t.end&&(r!==s?e.minY<o&&e.maxY>o&&e.maxX>r&&e.minX<s:e.minX<n&&e.maxX>n&&e.maxY>i&&e.minY<a)))continue;const c=j(f.x,f.y),l=Math.abs(f.x-n)+Math.abs(f.y-o),u=y(nt,e.pt,f);let h=0;const p=b.x-g.x,x=b.y-g.y,m=f.x-n,M=f.y-o;(x>10&&M<-5||x<-10&&M>5)&&(h=100*Math.abs(M)),(p>10&&m<-5||p<-10&&m>5)&&(h+=50*Math.abs(m));let I=0;const S=q.get(e.key)??"n",w=Math.abs(m)>qn?"h":"v";"n"!==S&&S!==w&&(I=50);const v=l+u+h+I,L=(V.get(e.key)??1/0)+v,C=Math.abs(b.x-f.x)+Math.abs(b.y-f.y);if(L<(V.get(c)??1/0))if(W.set(c,e.pt),V.set(c,L),q.set(c,w),J.has(c)){const t=K.findIndex(t=>t.key===c);-1!==t&&(K[t].f=L+C)}else K.push({key:c,f:L+C,pt:f}),J.add(c)}}if(0===Q.length&&(Q=[g,{x:g.x,y:b.y},b]),Q.length>4){const t=Q[0],e=Q[Q.length-1];let n=Math.min(t.x,e.x),o=Math.max(t.x,e.x),r=Math.min(t.y,e.y),s=Math.max(t.y,e.y);for(const c of Q)n=Math.min(n,c.x),o=Math.max(o,c.x),r=Math.min(r,c.y),s=Math.max(s,c.y);const i=o>Math.max(t.x,e.x),a=n<Math.min(t.x,e.x);if(c){const r=Kn;if(i){const n=Math.max(t.x,e.x),s=Math.min(t.y,e.y),i=Math.max(t.y,e.y),a=d.filter(t=>t.minX<n&&t.maxX>n&&t.minY<i&&t.maxY>s);if(a.length>0){let n=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 o=e+t.visualXHalfExtent+r;n=Math.max(n,o)}isNaN(n)||(o=n)}}if(a){const o=d.filter(n=>n.minX<Math.min(t.x,e.x)+r&&n.minY<Math.max(t.y,e.y)&&n.maxY>Math.min(t.y,e.y));if(o.length>0){let s=Math.min(t.x,e.x);for(const t of o){const e=(t.minX+t.maxX)/2-t.visualXHalfExtent-r;s=Math.min(s,e)}n=s}}}const f=h(n=>{const o=e.y>t.y,r=d.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(c&&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-qn)return t}else{const t=Math.min(...s.map(t=>t.minY))-15;if(t>e.y+qn)return t}return e.y},"findBestReturnY"),l=h(n=>{const o=f(n),r={x:n,y:t.y},s={x:n,y:o},i={x:e.x,y:o},a=Z(t,r),c=Z(r,s),d=Z(s,i),l=o!==e.y&&Z(i,e);return a||c||d||l?null:Math.abs(o-e.y)<qn?[t,r,s,e]:[t,r,s,i,e]},"trySimplifyWithDetourX"),u=i&&!a?l(o):a&&!i?l(n):null;u&&(Q=u)}const at=[o,...k,...Q,...$.reverse(),i];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)<qn&&Math.abs(e.y-t.y)<qn,r=Math.abs(n.x-e.x)<qn&&Math.abs(e.x-t.x)<qn;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 r=1;r<at.length-1;r++){if(1===r){ct.push(at[r]);continue}const t=ct[ct.length-1],e=at[r],n=at[r+1];if(Math.abs(t.y-e.y)<qn&&Math.abs(e.y-n.y)<qn){if(e.x>t.x!=n.x>e.x){ct.push(e);continue}}else if(Math.abs(t.x-e.x)<qn&&Math.abs(e.x-n.x)<qn){if(e.y>t.y!=n.y>e.y){ct.push(e);continue}}else ct.push(e)}ct.push(at[at.length-1]);for(let r=0;r<ct.length-1;r++){const t=ct[r],e=ct[r+1],n=Math.abs(t.x-e.x)<qn?"vertical":"horizontal",o="vertical"===n?t.x:t.y,s="vertical"===n?Math.min(t.y,e.y):Math.min(t.x,e.x),i="vertical"===n?Math.max(t.y,e.y):Math.max(t.x,e.x),a=l(n,o,s,i),c={edgeIndex:nt,segmentIndex:r,orientation:n,pipe:a,trackIndex:0,from:s,to:i};p.push(c),x[nt].push(p.length-1),a.tracks[0]||(a.tracks[0]={index:0,coord:a.coord,segments:[]}),a.tracks[0].segments.push({edgeIndex:nt,segmentIndex:r,from:s,to:i})}}const X=h((t,e)=>t.from<e.to&&e.from<t.to,"segmentsOverlap"),z=h((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=h(t=>{const e=t.tracks.length;return t.tracks[e]={index:e,coord:t.coord,segments:[]},e},"createNewTrack"),A=h((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"),G=h((t,e)=>{const n=x[t.edgeIndex];for(const o of n){const n=p[o];n.pipe===t.pipe&&A(n,e)}},"moveSegmentChainToTrack"),D=h(t=>{const e=x[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"),j=h((t,e)=>{if(t.orientation===e.orientation)return!1;const n="horizontal"===t.orientation?t:e,o="horizontal"===t.orientation?e:t;return o.pipe.coord>n.from&&o.pipe.coord<n.to&&n.pipe.coord>o.from&&n.pipe.coord<o.to},"haveAnyCrossing"),H=h((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"),_=h((t,e)=>{if(t.trackIndex===e.trackIndex)return X(t,e);const n=D(t),o=D(e);return n.some(t=>o.some(e=>j(t,e)))},"segmentsConflict"),V=h((t,e,n)=>{if(z(t,e,t.pipe.tracks[t.trackIndex],e.pipe.tracks[e.trackIndex]))return;const o=H(t.pipe,e);n(e,-1!==o?o:P(t.pipe))},"resolveTrackConflict"),W=h(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,G))}return e},"resolveHandleConflicts"),q=new Map,J=h(t=>{if(q.has(t))return q.get(t);const e=x[t];if(0===e.length){const e={dest:0,deviation:0,base:0,delta:0};return q.set(t,e),e}const n=p[e[0]].pipe.coord;let o=n;for(let s=1;s<e.length;s++){const t=p[e[s]];if("horizontal"===t.orientation){const e=t.from,r=t.to;o=Math.abs(e-n)>Math.abs(r-n)?e:r;break}}const r={dest:o,deviation:Math.abs(o-n),base:n,delta:o-n};return q.set(t,r),r},"getDestInfo"),K=h(()=>{let t=0;const e=new Map;for(const[o,s]of r.entries())0!==x[o].length&&s.start&&(e.has(s.start)||e.set(s.start,[]),e.get(s.start).push(o));const n=h(t=>{const e=r[t];if(!e.start||!e.end)return 0;const n=s.get(e.start),o=s.get(e.end);if(!n||!o)return 0;const i=(o.x??0)-(n.x??0),a=(o.y??0)-(n.y??0);return Math.abs(i)+Math.abs(a)},"getEdgeDistance");for(const o of e.values()){o.sort((t,e)=>{const o=J(t),r=J(e);if(Math.abs(o.deviation-r.deviation)>1)return o.deviation-r.deviation;if(Math.abs(o.dest-r.dest)>1)return o.dest-r.dest;const s=n(t),i=n(e);if(Math.abs(s-i)>1)return i-s;const a=x[t].length,c=x[e].length;if(a!==c)return a-c;if(1===a){const n=x[t][0],o=x[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=o.map(t=>p[x[t][0]]);t+=W(e)}return t},"fixSourceHandleCrossings"),Q=h(()=>{let t=0;const e=new Map;for(const[n,o]of r.entries())0!==x[n].length&&o.end&&(e.has(o.end)||e.set(o.end,[]),e.get(o.end).push(n));for(const n of e.values()){n.sort((t,e)=>{const n=h(t=>{const e=x[t];if(e.length<2)return 0;const n=p[e[e.length-2]];return Math.abs(n.to-n.from)},"getDist"),o=n(t),r=n(e);return Math.abs(o-r)>.1?o-r:t-e});const e=n.map(t=>p[x[t][x[t].length-1]]);t+=W(e)}return t},"fixTargetHandleCrossings"),Z=h(()=>{let t=0;for(const e of a){const n=[];for(const t of e.tracks)for(const e of t.segments){const t=x[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,A))}}return t},"fixPipeCrossings");let U=0;for(;U<10;){let t=0;if(t+=K(),t+=Q(),t+=Z(),0===t)break;U++}const tt=new Map;for(const nt of a){const t=[];nt.tracks.forEach(e=>{e.segments.forEach(n=>{t.push({edgeIndex:n.edgeIndex,segmentIndex:n.segmentIndex,trackIndex:e.index,from:n.from,to:n.to})})}),t.sort((t,e)=>t.from-e.from);const e=[];if(t.length>0){let n=[t[0]],o=t[0].to;for(let r=1;r<t.length;r++){const s=t[r];s.from<o?(n.push(s),o=Math.max(o,s.to)):(e.push(n),n=[s],o=s.to)}e.push(n)}for(const n of e){const t=new Set;n.forEach(e=>t.add(e.trackIndex));const e=new Map;n.forEach(t=>{const n=J(t.edgeIndex);e.set(t.trackIndex,(e.get(t.trackIndex)??0)+n.delta)});const o=[...t].filter(t=>(e.get(t)??0)<-1),r=[...t].filter(t=>(e.get(t)??0)>1),s=[...t].filter(t=>Math.abs(e.get(t)??0)<=1);o.sort((t,n)=>(e.get(n)??0)-(e.get(t)??0)),r.sort((t,n)=>(e.get(t)??0)-(e.get(n)??0));const i=h((t,e)=>{n.filter(e=>e.trackIndex===t).forEach(t=>{const n=m.has(t.edgeIndex)?nt.coord:e;tt.set(`${t.edgeIndex}-${t.segmentIndex}`,n)})},"assignCoord");let a=0;for(const n of o)a++,i(n,nt.coord-10*a);if(0===s.length&&t.size>0){const n=[...t].sort((t,n)=>Math.abs(e.get(t)??0)-Math.abs(e.get(n)??0))[0],i=o.indexOf(n);-1!==i&&o.splice(i,1);const a=r.indexOf(n);-1!==a&&r.splice(a,1),s.push(n)}let c=0;for(const n of s){if(0===c)i(n,nt.coord);else{const t=c%2==1?1:-1,e=Math.ceil(c/2);i(n,nt.coord+t*e*10*.5)}c++}let f=0;for(const n of r)f++,i(n,nt.coord+10*f)}}for(const[h,nt]of r.entries()){const t=x[h]??[];if(0===t.length)continue;const e=[],n=s.get(nt.start),o=s.get(nt.end),{pSrcPort:r,pDstPort:i}=Y(h,n,o),a=t.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}});e.push(r);for(let s=0;s<a.length;s++){const t=a[s],n=e[e.length-1],o="vertical"===t.orient?n.y:n.x,r="vertical"===t.orient?n.x:n.y,i=a[s+1],c=s<a.length-1;if(Math.abs(r-t.coord)>qn&&e.push(to(t,o)),c&&i.orient===t.orient)if(Math.abs(t.coord-i.coord)>qn){const n="vertical"===t.orient?(o+i.from)/2:Un(t,i);e.push(to(t,n),to(i,n))}else 0!==s&&s!==a.length-2||e.push(to(t,Un(t,i)));else if(c)e.push(to(t,i.coord));else{const n=Math.abs(t.from-o)<Math.abs(t.to-o)?t.to:t.from;e.push(to(t,n))}}const c=e[e.length-1];(Math.abs(c.x-i.x)>qn||Math.abs(c.y-i.y)>qn)&&e.push(i);const f=[];e.length>0&&f.push(e[0]);for(let s=1;s<e.length;s++){const t=e[s],n=f[f.length-1];(Math.abs(t.x-n.x)>qn||Math.abs(t.y-n.y)>qn)&&f.push(t)}nt.points=f}for(const h of r){const t=h.__originalEdge;t&&h.points&&(t.points=h.points)}t.edges=(t.edges??[]).filter(t=>!t.isLayoutOnly);const et=h((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 h of t.edges){const t=h.points;if(!t||t.length<2)continue;const e=h.start,n=h.end,o=e?s.get(e):void 0,r=n?s.get(n):void 0;o&&(t[0]=et(t[0],o)),r&&(t[t.length-1]=et(t[t.length-1],r))}return t}function no(t){return t.direction??"TB"}function oo(t){const e=_(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=no(t),{ordered:c,coordinates:f}=Wn(e,{nodeGap:n,layerGap:o,ignoreCrossLaneEdges:r,optimizeRanksByCrossings:s,automaticLaneOrdering:i,direction:a});V(e,c,f,{nodeGap:n,layerGap:o});for(const d of t.edges??[])delete d.points;eo(t,a);for(const d of t.edges??[])d.curve&&"basis"!==d.curve||(d.curve="rounded");return Ae(t,a),Pe(t),a}async function ro(t,i){const a=i.select("g");n(a,t.markers,t.type,t.diagramId),o(),r(),s(),e(),H(t);const c=W(t);t.nodes=c.nodes,t.edges=c.edges;const{groups:f}=await I(a,t);oo(t),await P(t,f)}h(Zn,"chooseOrthogonalSide"),h(Un,"sharedLineEndpointCoord"),h(to,"pointOnLine"),h(eo,"routeEdgesOrthogonal"),h(no,"getSwimlaneDirection"),h(oo,"runSwimlaneLayoutCore"),h(ro,"render");export{ro as render};
|