@agent-link/server 0.1.539 → 0.1.540

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.
Files changed (82) hide show
  1. package/package.json +4 -3
  2. package/web/dist/assets/{abnfDiagram-VRR7QNED-CYWjSLFB.js → abnfDiagram-VRR7QNED-D1hyJ-hn.js} +1 -1
  3. package/web/dist/assets/{arc-C5QqMw0D.js → arc-BuJJgjYt.js} +1 -1
  4. package/web/dist/assets/{architectureDiagram-ZJ3FMSHR-CiJkLkRK.js → architectureDiagram-ZJ3FMSHR-A9THC2Cc.js} +1 -1
  5. package/web/dist/assets/{blockDiagram-677ZJIJ3--rNn03K2.js → blockDiagram-677ZJIJ3-De9_CtWv.js} +1 -1
  6. package/web/dist/assets/{c4Diagram-LMCZKHZV-DFv38F5W.js → c4Diagram-LMCZKHZV-DeZVA52a.js} +1 -1
  7. package/web/dist/assets/channel-D0HU8H5o.js +1 -0
  8. package/web/dist/assets/{chunk-2Q5K7J3B-LcxWxL9X.js → chunk-2Q5K7J3B-DlDecKcs.js} +1 -1
  9. package/web/dist/assets/{chunk-32BRIVSS-L5rSd5kx.js → chunk-32BRIVSS-BhpTBz4U.js} +1 -1
  10. package/web/dist/assets/{chunk-5VM5RSS4-CqNmatdI.js → chunk-5VM5RSS4-DE8R6mLs.js} +1 -1
  11. package/web/dist/assets/{chunk-EX3LRPZG-2Wshn2od.js → chunk-EX3LRPZG-t_9lUdF-.js} +1 -1
  12. package/web/dist/assets/{chunk-JWPE2WC7-OIu2tm43.js → chunk-JWPE2WC7-D8olqveE.js} +1 -1
  13. package/web/dist/assets/{chunk-MOJQB5TN-GF0HoMD5.js → chunk-MOJQB5TN-qQmIJLhN.js} +1 -1
  14. package/web/dist/assets/{chunk-RYQCIY6F-esL_U6-9.js → chunk-RYQCIY6F-o8VHYTB2.js} +1 -1
  15. package/web/dist/assets/{chunk-V7JOEXUC-WNOLiPpt.js → chunk-V7JOEXUC-DGpoi6XB.js} +1 -1
  16. package/web/dist/assets/{chunk-VR4S4FIN-B-fO7gd6.js → chunk-VR4S4FIN-BjtiAe03.js} +1 -1
  17. package/web/dist/assets/{chunk-XXDRQBXY-D6g9o0gx.js → chunk-XXDRQBXY-Bf9B2FsN.js} +1 -1
  18. package/web/dist/assets/classDiagram-OUVF2IWQ-DQaRrb-b.js +1 -0
  19. package/web/dist/assets/classDiagram-v2-EOCWNBFH-DQaRrb-b.js +1 -0
  20. package/web/dist/assets/{cose-bilkent-JH36ORCC-CiWR02dm.js → cose-bilkent-JH36ORCC-CUu8D0Zk.js} +1 -1
  21. package/web/dist/assets/{cssMode-CdZ6WkPb.js → cssMode-BBGTtP8x.js} +1 -1
  22. package/web/dist/assets/{cynefin-VYW2F7L2-Cm5C7NQw.js → cynefin-VYW2F7L2-DVyQShfu.js} +1 -1
  23. package/web/dist/assets/{cynefinDiagram-TSTJHNR4-D4HWvIqR.js → cynefinDiagram-TSTJHNR4-5-G2jXgr.js} +1 -1
  24. package/web/dist/assets/{dagre-VKFMJZFB-Dydcg1Dj.js → dagre-VKFMJZFB-BVIWNamr.js} +1 -1
  25. package/web/dist/assets/{diagram-FQU43EPY-T1Gos5W9.js → diagram-FQU43EPY-DB_8HU4p.js} +1 -1
  26. package/web/dist/assets/{diagram-G47NLZAW-BiERNHwh.js → diagram-G47NLZAW-BuC9KdPo.js} +1 -1
  27. package/web/dist/assets/{diagram-NH7WQ7WH-Bp4PAleB.js → diagram-NH7WQ7WH-DEjdAGik.js} +1 -1
  28. package/web/dist/assets/{diagram-OA4YK3LP-gaknvItq.js → diagram-OA4YK3LP-CpUMGDrP.js} +1 -1
  29. package/web/dist/assets/{diagram-WEI45ONY-DrPuSW85.js → diagram-WEI45ONY-CD-UVma6.js} +1 -1
  30. package/web/dist/assets/{ebnfDiagram-CCIWWBDH-CAcdMMe7.js → ebnfDiagram-CCIWWBDH-Crk2X-Xr.js} +1 -1
  31. package/web/dist/assets/{editor.main-DGCQQuiO.js → editor.main-DX1kz8I2.js} +3 -3
  32. package/web/dist/assets/{erDiagram-Q63AITRT-DzyOSwU9.js → erDiagram-Q63AITRT-POwYozga.js} +1 -1
  33. package/web/dist/assets/{flowDiagram-23GEKE2U-DOe-9kuu.js → flowDiagram-23GEKE2U-5jmZ5k5e.js} +1 -1
  34. package/web/dist/assets/{freemarker2-1qw2nqEO.js → freemarker2-mDrCFxI5.js} +1 -1
  35. package/web/dist/assets/{ganttDiagram-NO4QXBWP-B2rh6MaY.js → ganttDiagram-NO4QXBWP-B9Mdj-u5.js} +1 -1
  36. package/web/dist/assets/{gitGraphDiagram-IHSO6WYX-DvnGb_NE.js → gitGraphDiagram-IHSO6WYX-CNPSE7ls.js} +1 -1
  37. package/web/dist/assets/{handlebars-BtUv9TxE.js → handlebars--G4a_6Oo.js} +1 -1
  38. package/web/dist/assets/{html-wKYvqrG5.js → html-tA32frga.js} +1 -1
  39. package/web/dist/assets/{htmlMode-BSafVEUS.js → htmlMode-CggNnIWF.js} +1 -1
  40. package/web/dist/assets/{index-DknoSkal.js → index-AdB8XHXv.js} +6 -6
  41. package/web/dist/assets/index-D5K63qug.css +32 -0
  42. package/web/dist/assets/{infoDiagram-FWYZ7A6U-DZimoK7P.js → infoDiagram-FWYZ7A6U-CyB7Vvcb.js} +1 -1
  43. package/web/dist/assets/{ishikawaDiagram-FXEZZL3T-DsvDmKxP.js → ishikawaDiagram-FXEZZL3T-DLMZ7H1X.js} +1 -1
  44. package/web/dist/assets/{javascript-h1g-Ucy8.js → javascript-DMkX6-SC.js} +1 -1
  45. package/web/dist/assets/{journeyDiagram-5HDEW3XC-CY8i7id_.js → journeyDiagram-5HDEW3XC-_nk1wTqH.js} +1 -1
  46. package/web/dist/assets/{jsonMode-DiNVkY3E.js → jsonMode-BatVhCGs.js} +1 -1
  47. package/web/dist/assets/{kanban-definition-HUTT4EX6-qsS7eTpB.js → kanban-definition-HUTT4EX6-Cz1JY0qx.js} +1 -1
  48. package/web/dist/assets/{linear-pxgzmzBW.js → linear-DkQS0EVl.js} +1 -1
  49. package/web/dist/assets/{liquid-BScuE6Li.js → liquid-JdcJe3Mn.js} +1 -1
  50. package/web/dist/assets/{lspLanguageFeatures-Bvg2J_jV.js → lspLanguageFeatures-BDC0ynk1.js} +1 -1
  51. package/web/dist/assets/{mdx-DEgin56d.js → mdx-C0s6E9Ya.js} +1 -1
  52. package/web/dist/assets/{mermaid.core-DkcKZax1.js → mermaid.core-DQSlETG7.js} +2 -2
  53. package/web/dist/assets/{mindmap-definition-LN4V7U3C-CdSHmqbA.js → mindmap-definition-LN4V7U3C-oNTOwQOU.js} +1 -1
  54. package/web/dist/assets/{pegDiagram-2B236MQR-B5lYNF_c.js → pegDiagram-2B236MQR-8BmSEVOy.js} +1 -1
  55. package/web/dist/assets/{pieDiagram-ENE6RG2P-C5XC449d.js → pieDiagram-ENE6RG2P-DRIltoVc.js} +1 -1
  56. package/web/dist/assets/{python-LiSQlk9W.js → python-DQKjtSgN.js} +1 -1
  57. package/web/dist/assets/{quadrantDiagram-ABIIQ3AL-B_lVz6fv.js → quadrantDiagram-ABIIQ3AL-BJfMAp1Q.js} +1 -1
  58. package/web/dist/assets/{railroadDiagram-RFXS5EU6-Cqyazggh.js → railroadDiagram-RFXS5EU6-Dj9-wyZY.js} +1 -1
  59. package/web/dist/assets/{razor-C-OT9rh_.js → razor-CL-fmDzS.js} +1 -1
  60. package/web/dist/assets/{requirementDiagram-TGXJPOKE-D1fFw8Za.js → requirementDiagram-TGXJPOKE-fPYOczdV.js} +1 -1
  61. package/web/dist/assets/{sankeyDiagram-HTMAVEWB-BmEnh6Zy.js → sankeyDiagram-HTMAVEWB-DyjpctG7.js} +1 -1
  62. package/web/dist/assets/{sequenceDiagram-DBY2YBRQ-D6IE-IG5.js → sequenceDiagram-DBY2YBRQ-RaZs5E3b.js} +1 -1
  63. package/web/dist/assets/{sizeCapture-X5ZJPWSS-BYkPr4jo.js → sizeCapture-X5ZJPWSS-BfOA5cbO.js} +1 -1
  64. package/web/dist/assets/{stateDiagram-2N3HPSRC-BUCTdtKV.js → stateDiagram-2N3HPSRC-CdxgHSfH.js} +1 -1
  65. package/web/dist/assets/stateDiagram-v2-6OUMAXLB-vTVKrqt9.js +1 -0
  66. package/web/dist/assets/{swimlanes-5IMT3BWC-DcMZ-6_P.js → swimlanes-5IMT3BWC-B19jLFc4.js} +2 -2
  67. package/web/dist/assets/swimlanesDiagram-G3AALYLV-CbIyNKp1.js +1 -0
  68. package/web/dist/assets/{timeline-definition-FHXFAJF6-CevcptDf.js → timeline-definition-FHXFAJF6-CYSSTJjP.js} +1 -1
  69. package/web/dist/assets/{tsMode-CQ3194z3.js → tsMode-I7W52vRp.js} +1 -1
  70. package/web/dist/assets/{typescript-D0PYBX18.js → typescript-BkUlxSfm.js} +1 -1
  71. package/web/dist/assets/{vennDiagram-L72KCM5P-C4E35ru2.js → vennDiagram-L72KCM5P-CJ5m4qeA.js} +1 -1
  72. package/web/dist/assets/{wardleyDiagram-EHGQE667-jZDfwkzC.js → wardleyDiagram-EHGQE667-CpaSYOZD.js} +1 -1
  73. package/web/dist/assets/{xml-BbyTLoF3.js → xml-B6uP1aJC.js} +1 -1
  74. package/web/dist/assets/{xychartDiagram-FW5EYKEG-CLEMD07_.js → xychartDiagram-FW5EYKEG-EqZ9r0f-.js} +1 -1
  75. package/web/dist/assets/{yaml-BQcG0ScU.js → yaml-BzfObSCH.js} +1 -1
  76. package/web/dist/index.html +2 -2
  77. package/web/dist/assets/channel-BUPHzg7D.js +0 -1
  78. package/web/dist/assets/classDiagram-OUVF2IWQ-CEHpjaOw.js +0 -1
  79. package/web/dist/assets/classDiagram-v2-EOCWNBFH-CEHpjaOw.js +0 -1
  80. package/web/dist/assets/index-DXanOGbR.css +0 -32
  81. package/web/dist/assets/stateDiagram-v2-6OUMAXLB-DvxjB9W-.js +0 -1
  82. package/web/dist/assets/swimlanesDiagram-G3AALYLV-u9Y7eEve.js +0 -1
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./sizeCapture-X5ZJPWSS-BYkPr4jo.js","./mermaid.core-DkcKZax1.js","./index-DknoSkal.js","./index-DXanOGbR.css"])))=>i.map(i=>d[i]);
2
- import{_ as t}from"./index-DknoSkal.js";import{c as e}from"./chunk-RYQCIY6F-esL_U6-9.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 l,as as d,au as u,z as h,ar as g,av as p,y as x,aw as m,_ as y,ax as b}from"./mermaid.core-DkcKZax1.js";import{G as M}from"./graph-DaY0Al7L.js";import"./map-CKQHuyK8.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"),l=i.insert("g").attr("class","edges edgePath"),d=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=>{var e;if(t.isGroup)o.setNode(t.id,{...t});else{if(g){const n=await c(u,t,{config:s,dir:t.dir}),o=(null==(e=n.node())?void 0:e.getBBox())??{width:0,height:0};h.set(t.id,n),t.width=o.width,t.height=o.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-BYkPr4jo.js");return{captureNodeSizes:t}},__vite__mapDeps([0,1,2,3]),import.meta.url);o(e,n)}return{graph:o,groups:{clusters:f,edgePaths:l,edgeLabels:d,nodes:u,rootGroups:i},nodeElements:h}}y(I,"createGraphWithElements");var v=1e-5,S=1e-6;function w(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,l=n.y-t.y,d=(f*a-l*i)/c,u=(f*s-l*r)/c;return d<=S||d>=.999999||u<=S||u>=.999999?null:{point:{x:t.x+d*r,y:t.y+d*s},tA:d,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=w(o.points);for(let s=n+1;s<t.length;s++){const n=t[s],i=w(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 $(t){return`${T(t.x)},${T(t.y)}`}function O(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}y(w,"buildSegmentList"),y(L,"segmentIntersection"),y(C,"isHorizontalSeg"),y(k,"findEdgeIntersections"),y(T,"fmt"),y($,"pointToString"),y(O,"getArcSweepFlag");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${$(a)}`];return"arc"===r?f.push(`A${T(t.r)},${T(t.r)} 0 0 ${o} ${$(c)}`):f.push(`M${$(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<v||f<v)return null;const l=r/c,d=s/c,u=i/f,h=a/f,g=l*u+d*h,p=Math.max(-1,Math.min(1,g)),x=Math.acos(p);if(x<v||Math.abs(Math.PI-x)<v)return null;const m=Math.min(o/Math.sin(x/2),c/2,f/2);return{startX:e.x-l*m,startY:e.y-d*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=w(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${$(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,l=0===e?0:(t.b.y-t.a.y)/e,d=O(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,l,d,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${$(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=null==e?void 0:e.curve;if(void 0!==o&&!Y(o))continue;const s=i.get(f.id);if(!s)continue;if(void 0===o){if(!F(s.getAttribute("d")??""))continue}const a=s.getAttribute("style")??"",l=/stroke-dasharray\s*:\s*0\s+([\d.]+)\s+[\d.]+\s+([\d.]+)/.exec(a),d=l?Number.parseFloat(l[1]):null,u=l?Number.parseFloat(l[2]):null,h=E(f,t,n);if(s.setAttribute("d",h),null!==d&&null!==u&&"function"==typeof s.getTotalLength){const t=s.getTotalLength(),e=`0 ${d} ${Math.max(0,t-d-u)} ${u}`,n=a.replace(/stroke-dasharray\s*:[^;]*;?/g,`stroke-dasharray: ${e};`).replace(/;\s*;+/g,";");s.setAttribute("style",n)}}}async function P(t,e){var n,o;for(const i of t.nodes)i.isGroup?await f(e.clusters,i):l(i);const r=new Map;for(const i of t.nodes)(null==i?void 0:i.id)&&r.set(i.id,i);for(const i of t.edges){const n=i.start?r.get(i.start)??{}:{},o=i.end?r.get(i.end)??{}:{},s=d(e.edgePaths,{...i},{},t.type,n,o,t.diagramId);i.label&&await u(e.rootGroups,i),i.label&&A(i,s)}const s=null==(o=null==(n=t.config)?void 0:n.swimlane)?void 0:o.lineHops;if(!1!==s){const n="gap"===s?"gap":"arc",o=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,o,{enabled:!0,jumpRadius:6,jumpStyle:n})}}function A(t,e){const n=(null==e?void 0:e.updatedPath)??(null==e?void 0:e.originalPath),o=h(),{subGraphTitleTotalMargin:r}=g({flowchart:o.flowchart??{}});if(t.label){const o=p.get(t.id);let s=t.x,a=t.y;if(n){const o=x.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(null==t?void 0:t.startLabelLeft){const e=m.get(t.id).startLeft;let o=null==t?void 0:t.x,r=null==t?void 0:t.y;if(n){const e=x.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=m.get(t.id).startRight;let o=t.x,r=t.y;if(n){const e=x.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=m.get(t.id).endLeft;let o=t.x,r=t.y;if(n){const e=x.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=m.get(t.id).endRight;let o=t.x,r=t.y;if(n){const e=x.calcTerminalLabelPosition(t.arrowTypeEnd?10:0,"end_right",n);o=e.x,r=e.y}e.attr("transform",`translate(${o}, ${r})`)}}y(R,"applyMarkerOffsets"),y(N,"emitJump"),y(B,"computeRoundedCorner"),y(E,"rewriteEdgePath"),y(F,"isStraightPath"),y(Y,"curveSupportsLineHops"),y(X,"decodeDataPoints"),y(z,"applyLineJumpsToSvg"),y(P,"adjustLayout"),y(A,"positionEdgeLabel");var G="__swimlane_default__";function D(t){return Math.max(t.padding??20,20)}function H(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 j(t){const e=t.direction,n=t.nodes??(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=(null==o?void 0:o.layerGap)??100,a=(null==o?void 0: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??[],l=new Map,d=[];for(const u of f){if(!(null==u?void 0:u.isGroup))continue;u.parentId||d.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,d=(r+s)/2;u.x=f,u.y=d,u.width=a,u.height=c,l.set(u.id,{minX:e,maxX:o,minY:r,maxY:s})}}if(d.length>0&&l.size>0){let t=1/0,e=-1/0,n=0;for(const o of d){const r=o.padding??20;r>n&&(n=r);const s=l.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 d)e.y=s,e.height=r,e.swimlaneContentTop=t;const i=[...d].sort((t,e)=>(t.x??0)-(e.x??0)),a=[],c=[],f=[];for(const t of i){const e=l.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 d){const n=t.get(e.id);null!=n&&(e.width=n),H(e)}}}}}y(D,"topLaneHorizontalPadding"),y(H,"assignTopLaneTitleRect"),y(j,"prepareLayoutForSwimlanes"),y(_,"toGraphView"),y(V,"writeBackToLayoutData");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 l={id:`${a.id}-to-label`,start:a.start,end:s,type:"normal",isLayoutOnly:!0},d={id:`${a.id}-from-label`,start:s,end:a.end,type:"normal",isLayoutOnly:!0};n.push(l,d)}const r=[...t.nodes,...e],s=[...t.edges,...n];return{...t,nodes:r,edges:s}}y(W,"createEdgeLabelNodes");var J=.001;function q(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=q(t);if(!e)return;return{id:String(t.id??""),cx:e.cx,cy:e.cy,rect:e.rect}}function Q(t,e,n=J){return Math.abs(t.x-e.x)<n&&Math.abs(t.y-e.y)<n}function Z(t,e,n=J){return Math.abs(t.x-e.x)<n}function U(t,e,n=J){return Math.abs(t.y-e.y)<n}function tt(t,e,n=J){return U(t,e,n)&&Math.abs(t.x-e.x)>n}function et(t,e,n=J){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=J){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=J){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=J){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=J){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=J){if(!t||4!==t.length)return;const[n,o,r,s]=t;if(tt(n,o,e)&&et(o,r,e)&&tt(r,s,e))return{kind:"HVH",p0:n,p1:o,p2:r,p3:s};return 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 lt(t,e){return t.left<=e.left&&t.right>=e.right&&t.top<=e.top&&t.bottom>=e.bottom}function dt(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){var e;return null==(e=q(t))?void 0:e.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=J){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=J){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 vt(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 St(t,e,n,o,r=J,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 l=i?{a:t,b:e}:{a:n,b:o},d=a?{a:t,b:e}:{a:n,b:o},u=l.a.y,h=Math.min(l.a.x,l.b.x),g=Math.max(l.a.x,l.b.x),p=d.a.x,x=Math.min(d.a.y,d.b.y),m=Math.max(d.a.y,d.b.y);if(p<h||p>g||u<x||u>m)return!1;const y=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,b=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;return!(y&&b)}function wt(t,e,n,o,r=J){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=J,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))&&(St(t,e,i,a,r)||wt(t,e,i,a,r)))return!0}}return!1}function Ct(t,e,n,o,r=J){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},l=s?{a:n,b:o}:{a:t,b:e},d=f.a.y,u=Math.min(f.a.x,f.b.x),h=Math.max(f.a.x,f.b.x),g=l.a.x,p=Math.min(l.a.y,l.b.y),x=Math.max(l.a.y,l.b.y);return g>u+r&&g<h-r&&d>p+r&&d<x-r}function kt(t,e,n){const o=Math.min(e,n),r=Math.max(e,n);return t>o+J&&t<r-J}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 $t(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 Ot(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=$t(e);if(e=t.points,!t.changed)break}return e}y(q,"measuredNodeRect"),y(K,"nodeBoundsInfoFor"),y(Q,"samePoint"),y(Z,"sameX"),y(U,"sameY"),y(tt,"isHorizontalSegment"),y(et,"isVerticalSegment"),y(nt,"overlapLength"),y(ot,"sameAxisSegmentOverlapLength"),y(rt,"orthogonalSegmentsForPoints"),y(st,"countOrthogonalBends"),y(it,"dedupeConsecutivePoints"),y(at,"classifyThreeSegmentRoute"),y(ct,"segmentBoundsOverlapRect"),y(ft,"pointInsideRect"),y(lt,"rectContainsRect"),y(dt,"rectsOverlap"),y(ut,"inflateRect"),y(ht,"rectFromCenterSize"),y(gt,"rectOfNodeBounds"),y(pt,"portForRectSide"),y(xt,"buildOrthogonalPortPath"),y(mt,"buildSameSideTrackPath"),y(yt,"collectRealNodeBounds"),y(bt,"collectNodeRectEntries"),y(Mt,"collectLayoutNodeRects"),y(It,"getNodePairGeometry"),y(vt,"segmentHitsAnyRect"),y(St,"orthogonalSegmentsCross"),y(wt,"sameAxisSegmentsOverlap"),y(Lt,"segmentConflictsWithAnyEdge"),y(Ct,"orthogonalSegmentsStrictlyCross"),y(kt,"strictlyBetween"),y(Tt,"isCollinearIntermediate"),y($t,"simplifyPolylineOnce"),y(Ot,"orthogonalizePolyline"),y(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(Ot(o)),o=Wt(o,t.srcRect,t.dstRect),t.edge.points=Rt(Ot(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 Ht(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 jt(t){return"left"===t||"right"===t}function _t(t,e,n,o,r){const s=[],i=n?Ht(t,e,n):void 0,a=o?Ht(e,t,o):void 0;return n&&i&&jt(i)===r&&s.push(Dt(n,i)),o&&a&&jt(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 Jt(t,e,n){return jt(n)?{x:t.x,y:At(t.y,e.top,e.bottom)}:{x:At(t.x,e.left,e.right),y:t.y}}function qt(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=Ht(s,i,e);if(!a)return t;const c=jt(a),f=Jt(s,e,a);return Q(s,f,Nt)?t:qt(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(!(null==t?void 0: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(!(null==t?void 0: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=y(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 le(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 l=c/r.length,d=f/r.length,u=d>0?Math.max(1,l/d):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,v=(y+b)/2-M/2-a,S=v+I/2,w=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(0===L)e=t.contentTop-w;else{e=(m[L-1].contentBottom+t.contentTop)/2}if(L===m.length-1)n=t.contentBottom+w;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=S,t.lane.y=r,t.lane.width=I,t.lane.height=o,t.lane.swimlaneContentTop=t.contentTop,t.lane.groupTitleRect={left:v,right:v+a,top:e,bottom:n}}return"RL"===e&&ce(t,"x"),!0}y(Bt,"endpointContextFor"),y(Et,"segmentEnterPoint"),y(Ft,"clipEndpoint"),y(Yt,"clipEdgeEndpointsToNodeBoundaries"),y(Xt,"snapEndpointToBoundary"),y(zt,"firstDistinctAdjacent"),y(Pt,"cornerClearanceRange"),y(At,"clampToCornerClearance"),y(Gt,"intersectRanges"),y(Dt,"clearanceRangeForSide"),y(Ht,"terminalSideForSegment"),y(jt,"isHorizontalSide"),y(_t,"straightClearanceRange"),y(Vt,"clearStraightEndpointCornerAxis"),y(Wt,"clearStraightEndpointCornerConnections"),y(Jt,"cornerClearedEndpoint"),y(qt,"moveCollinearEndpointRun"),y(Kt,"clearEndpointCornerConnection"),y(Qt,"borderSideForSegment"),y(Zt,"leavesOutward"),y(Ut,"collapseOwnBorderStub"),y(te,"snapAndCollapseEndpoints"),y(ee,"prepareEdgeEndpointsForRenderer"),y(ne,"buildNodeMap"),y(oe,"resolveTopLevelGroupId"),y(re,"groupDepth"),y(se,"boundsForChildren"),y(ie,"applyGroupBounds"),y(ae,"recomputeNestedGroupBounds"),y(ce,"mirrorAxis"),y(fe,"applyBtDirectionTransform"),y(le,"applyLrDirectionTransform");var de=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,de),de);if(!s)continue;const{p3:i}=s,a="HVH"===s.kind,c=It(r,n,de);if(!c)continue;const{srcId:f,dstId:l,srcInfo:d,dstInfo:u,collinearX:h,collinearY:g}=c;if(h||g)continue;let p;const x=d.rect;for(const n of ue){let e,s,c;if(a){const t=u.cy>d.cy?x.bottom:x.top,o=d.cx+n;if(o<=x.left+de||o>=x.right-de)continue;e={x:o,y:t},s={x:o,y:i.y},c={x:i.x,y:i.y}}else{const t=u.cx>d.cx?x.right:x.left,o=d.cy+n;if(o<=x.top+de||o>=x.bottom-de)continue;e={x:t,y:o},s={x:i.x,y:o},c={x:i.x,y:i.y}}const h=Q(e,s,de),g=Q(s,c,de);if(h&&g)continue;if(!h&&vt(e,s,o,[f],1))continue;if(!g&&vt(s,c,o,[l],1))continue;const m=!h&&Lt(e,s,t,r,{epsilon:de,skipDegenerateOther:!0}),y=!g&&Lt(s,c,t,r,{epsilon:de,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],l=a[c-1],d=a[c-2],u=f.x-l.x,h=f.y-l.y,g=Math.hypot(u,h);if(g>=10||g<n)continue;const p=l.x-d.x,x=l.y-d.y;if(Math.hypot(p,x)<n)continue;const m=tt(l,f,n),b=et(l,f,n),M=tt(d,l,n),I=et(d,l,n);if(!(m&&I||b&&M))continue;const v=s.end,S=s.start,w=v?e.get(v):void 0;if(!w)continue;const L=w.x??0,C=w.y??0,k=gt(w);if(!k)continue;let T,$;if(I){const t=x<0;T={x:L,y:d.y},$={x:L,y:t?k.bottom:k.top}}else{const t=p>0;T={x:d.x,y:C},$={x:t?k.right:k.left,y:C}}if(vt(T,$,o,v?[v]:[],-2))continue;if(vt(T,$,r,[],-2))continue;if(S){const t=e.get(S),n=t?gt(t):void 0;if(n&&ft(T,n,2))continue}const O=y((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(O(a[t],a[t+1]));const N=y((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(O(s,i))&&Ct(e,o,s,i,n))return!0}}return!1},"segmentCrossesOtherEdge");if(N(T,$))continue;if(c-3>=0){const t=a[c-3];if(vt(t,T,o,[S,v].filter(t=>Boolean(t)),-2))continue;if(N(t,T))continue}const B=[...a.slice(0,c-2),T,$];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),l=U(a,c,n),d=Z(a,c,n);(l&&f>=e+2||d&&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)}}}}}y(he,"portSwapToLShape"),y(ge,"collapseShortTerminalStub");var pe=.001,xe=rt,me=y((t,e)=>Z(t,e,pe)||U(t,e,pe),"orthogonallyAligned");function ye(t,e){const n=y((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=y((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],l=n(i,c);let d=c;return me(f,l)&&(d=f),Z(l,d,pe)?{edge:t,edgeId:String(t.id??""),nodeId:s,atStart:o,orientation:"V",coord:l.x,min:Math.min(l.y,d.y),max:Math.max(l.y,d.y),boundary:l,railEnd:d,rect:a}:U(l,d,pe)?{edge:t,edgeId:String(t.id??""),nodeId:s,atStart:o,orientation:"H",coord:l.y,min:Math.min(l.x,d.x),max:Math.max(l.x,d.x),boundary:l,railEnd:d,rect:a}:void 0},"terminalLaneFor"),r=y((t,e)=>Math.max(0,Math.min(t.max,e.max)-Math.max(t.min,e.min)),"projectedOverlapLength"),s=y((t,e)=>{if(t.nodeId!==e.nodeId||t.orientation!==e.orientation)return!1;if("H"===t.orientation){return(Math.abs(t.boundary.x-t.rect.left)<1||Math.abs(t.boundary.x-t.rect.right)<1)&&Z(t.boundary,e.boundary,1)}return(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=y((t,e)=>{if(t.nodeId!==e.nodeId||t.orientation!==e.orientation)return!1;return r(t,e)>=8&&Math.abs(t.coord-e.coord)<.5},"exactTerminalLaneConflict"),a=y((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=y((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(!y(()=>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=y(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,l=a.x??0,d=a.y??0,[u,h]=o;return U(u,h,pe)&&Math.abs(f-d)<1&&Math.abs(c-l)>1||Z(u,h,pe)&&Math.abs(c-l)<1&&Math.abs(f-d)>1},"laneIsStraightCollinearConnector"),l=[-7,7,-14,14,-21,21];for(let d=0;d<8;d++){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],d=e[r];if(s.edge===d.edge||!i(s,d)&&!a(s,d))continue;const u=!i(s,d),h=[s,d].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 l){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=y((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(vt(t.a,t.b,n,c,-2))return!1;if(vt(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=y((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],l=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,d=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 l||d?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=y((t,e,n)=>it(t===e?n??[]:t.points??[]),"pointsFor"),i=y((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=y(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=y((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;if(e.horizontal){return nt(e.a.x,e.b.x,n.left,n.right)>=8&&e.a.y>=n.top-2&&e.a.y<=n.bottom+2}return 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=y((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"),l=y((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(vt(r.a,r.b,n,c,-2))return!1;if(vt(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 d=0;d<8;d++){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 d=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 d){const i=f(o,r.segment,s);if(i&&l(n,i,t)){n.points=i,e=!0;break}}if(e)break}if(!e)return}}function Ie(t,e){const n=y(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=y(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=y((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 ve(t,e){const n=y(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=y(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=y((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=y((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 Se(t,e){const{realNodeRects:n}=bt(e.values()),o=t.filter(t=>!t.isLayoutOnly),r=y((t,e=new Map)=>it(e.get(t)??t.points??[]),"replacementPointsFor"),s=y((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=y((t=new Map)=>o.reduce((e,n)=>e+st(r(n,t)),0),"totalBends"),a=y(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=y((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=y((t,e)=>{const o=[t.start,t.end].filter(t=>Boolean(t));for(const r of xe(e))if(vt(r.a,r.b,n,o,-2))return!0;return!1},"pathHasNodeHit"),l=y((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"),d=y((t,e,n)=>!f(t,e)&&!l(t,e,n),"candidateIsSafe"),u=y(()=>{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 l=f+1;l<r.length;l++){const u=r[f],h=r[l],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(!d(u,x,y)||!d(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 we(t,e){const{realNodeRects:n,labelNodeRects:o}=bt(e.values()),r=t.filter(t=>!t.isLayoutOnly),s=y((t,e=new Map)=>it(e.get(t)??t.points??[]),"replacementPointsFor"),i=y((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=y((t=new Map)=>r.reduce((e,n)=>e+st(s(n,t)),0),"totalBends"),c=y(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=y((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"),l=y(()=>{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"),d=y((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=y(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)&&d(e,o)&&(n.add(o),r.push(o))}s.length>1&&e.push(s)}return e},"connectedComponents"),h=y(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"),g=y(t=>{const e=t.map(t=>t.coord),n=h(t),o=[];if(t.length<=6){const r=new Array(n.length).fill(!1),s=[],i=y(()=>{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"),p=y((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"),x=y(t=>{for(const[e,r]of t){const t=[e.start,e.end].filter(t=>Boolean(t));for(const e of xe(r)){if(vt(e.a,e.b,n,t,-2))return!1;if(vt(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 m=0;m<4;m++){const t=i();if(0===t)return;let e,n=t,o=a(),r=Number.POSITIVE_INFINITY;for(const s of u(l()))for(const c of g(s)){const f=p(s,c);if(!f||!x(f))continue;const l=i(f);if(l>=t)continue;const d=a(f),u=s.reduce((t,e,n)=>t+Math.abs(c[n]-e.coord),0);l>n||l===n&&(d>o||d===o&&u>=r)||(e=f,n=l,o=d,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=y((t,e,n)=>it(t===e?n??[]:t.points??[]),"pointsFor"),i=y(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=y((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=y((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=y(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"),l=y((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)]),l=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!l.has(e)&&(l.add(e),!0)})},"shortcutCandidatesAt"),d=y((t,e,i)=>{const l=[t.start,t.end].filter(t=>Boolean(t)),d=f(t);for(const r of xe(e)){if(vt(r.a,r.b,n,l,-2))return!1;if(vt(r.a,r.b,o,[],-2))return!1;if(d.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 l(r,s)){const r=st(p,pe),s=i(p);if(!(r<h||r===h&&s<g-pe)||!d(u,p,t))continue;const l=a(u,p);l>o||l===o&&(r>c||r===c&&s>=f)||(e=u,n=p,o=l,c=r,f=s)}}if(!e||!n)return;e.points=n}}function Ce(t,e){const n=20,o=[];for(const y of e.values()){if(y.isGroup||y.isEdgeLabel)continue;const t=y.x??0,e=y.y??0,n=gt(y);n&&o.push({id:String(y.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])),l=y(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"),d=y((t,e=new Map)=>it(e.get(t)??t.points??[]),"replacementPointsFor"),u=y((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"),h=y((t,e)=>u(xe(t),xe(e)),"crossingCountBetweenPaths"),g=y((t=new Map)=>{let e=0;const n=[],o=new Set,r=[],s=y(t=>{o.has(t)||(o.add(t),r.push(t))},"addEdge");for(let i=0;i<c.length;i++){const o=c[i],r=d(o,t);for(let a=i+1;a<c.length;a++){const i=c[a],f=h(r,d(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"),p=y((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=d(t,e);for(let a=s+1;a<c.length;a++){const t=c[a];(o||n.has(t))&&(r+=h(i,d(t,e)))}}return t.count-o+r},"crossingCountWithReplacements"),x=y(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"),m=y(t=>[t.start,t.end].filter(t=>Boolean(t)),"endpointIdsFor"),b=y(t=>{const e=[];for(const n of x(t)){const t=new Set(n),o=new Set(n.flatMap(t=>m(t))),r=[...n];for(const e of c)t.has(e)||m(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=y((t,e,n)=>p(t,new Map([[e,n]])),"crossingCountWithSingleReplacement"),I=y(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"),v=y(t=>t.slice(1).reduce((e,n,o)=>{const r=t[o];return e+Math.abs(n.x-r.x)+Math.abs(n.y-r.y)},0),"pathLength"),S=y((t=new Map)=>c.reduce((e,n)=>e+st(d(n,t)),0),"totalBends"),w=y((t=new Map)=>c.reduce((e,n)=>e+v(d(n,t)),0),"totalLength"),L=y((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(d(r,n)))if(ot(t,e,.5)>=8)return!0;return!1},"pathHasSegmentConflict"),C=y((t,e)=>{const n=[t.start,t.end].filter(t=>Boolean(t));for(const o of xe(e))if(vt(o.a,o.b,s,n,-2))return!0;return!1},"pathHitsNode"),k=y((t,e)=>{const n=Rt(it(e));xe(n).length===n.length-1&&t.push(n)},"pushOrthogonalCandidate"),T=y(t=>"left"===t||"right"===t,"sideIsHorizontal"),$=y((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"),O=y((t,e,o,r)=>{const s="left"===o||"top"===o?-1:1,i=[$(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=y((t,e,n,o,r)=>{for(const s of l(n))for(const n of l(r))k(t,[e,{x:s,y:e.y},{x:s,y:n},{x:o.x,y:n},o])},"addHorizontalToVerticalCandidates"),N=y((t,e,n,o,r)=>{for(const s of l(n))for(const n of l(r))k(t,[e,{x:e.x,y:s},{x:n,y:s},{x:n,y:o.y},o])},"addVerticalToHorizontalCandidates"),B=y((t,e,n,o,r)=>{const s=[...l("top"),...l("bottom")];for(const i of l(n))for(const n of l(r))for(const r of s)k(t,[e,{x:i,y:e.y},{x:i,y:r},{x:n,y:r},{x:n,y:o.y},o])},"addHorizontalPairCandidates"),E=y((t,e,n,o,r)=>{const s=[...l("left"),...l("right")];for(const i of l(n))for(const n of l(r))for(const r of s)k(t,[e,{x:e.x,y:i},{x:r,y:i},{x:r,y:n},{x:o.x,y:n},o])},"addVerticalPairCandidates"),F=y(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=y((t,e,o,r)=>{const s=[],i=xt(t,e,o,r,n,pe);i&&k(s,i),e===r&&O(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=y((t,e,n,o)=>{const r=[...l("left"),...l("right")],s=[...l("top"),...l("bottom")];for(const a of i){const i=pt(o,a),c="top"===a||"bottom"===a?l(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=y((t,e,n,o)=>{const r=[...l("left"),...l("right")],s=[...l("top"),...l("bottom")];for(const a of i){const i=pt(o,a),c="left"===a||"right"===a?l(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=y(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=y(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=y(()=>new Map(c.map(t=>[t,xe(d(t))])),"currentSegmentsByEdge"),D=y((t,e,n)=>{const o=new Set;for(const r of c){if(r===t)continue;const s=n.get(r)??xe(d(r));e.some(t=>s.some(e=>ot(t,e,.5)>=8))&&o.add(r)}return o},"sharedTrackConflictsFor"),H=y((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(d(e))));return{candidate:r,candidateSegments:s,crossings:e.count-(o.get(t)??0)+i,bends:st(r,pe),totalBends:st(r),length:v(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"),j=y((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(d(f));a+=u(n.segments,t)+u(r.segments,t)}return t.count-i+a},"pairCrossingCount"),_=y((t,e)=>{for(const n of t.sharedTrackConflicts)if(n!==e)return!1;return!0},"conflictsOnlyWith"),V=y((t,e)=>t.segments.some(t=>e.segments.some(e=>ot(t,e,.5)>=8)),"candidatesShareTrack"),W=y((t,e,n,o)=>_(e,n.edge)&&_(o,t.edge)&&!V(e,o),"pairCandidatesAreCompatible"),J=y((t,e,n,o,r)=>{const s=j(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"),q=y((t,e)=>t.crossings<e.crossings||t.crossings===e.crossings&&(t.bends<e.bends||t.bends===e.bends&&t.length<e.length),"pairScoreIsBetter"),K=y((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=J(t,e,s,n,o);i&&q(i,r)&&(r=i)}return r},"bestScoreForOptionPair"),Q=y(t=>{const e=S(),n=w(),o=G(),r=I(t),s=new Map(c.map(t=>[t,st(d(t))])),i=new Map(c.map(t=>[t,v(d(t))])),a=new Map,f=b(t);for(const c of f)for(const e of c){if(a.has(e))continue;const n=H(e,t,o,r);n.length>0&&a.set(e,{edge:e,candidates:n})}let l={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))&&(l=K(u,o,t,l))}}}return l.replacements.size>0?l.replacements:void 0},"bestPairedReplacement");for(let y=0;y<4;y++){const t=g(),e=t.count;if(0===e)return;let n,o,r=e,s=Number.POSITIVE_INFINITY;for(const a of t.edges){const i=st(d(a),pe);for(const c of A(a)){const f=C(a,c),l=!f&&L(a,c),d=M(t,a,c),u=st(c,pe);if(f||l)continue;(d<e||d===e&&u<i)&&(d>r||d===r&&u>=s||(n=a,o=c,r=d,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}}y(ye,"separateSharedRenderedTerminalLanes"),y(be,"collapseRedundantRectangularDoglegs"),y(Me,"liftObstacleHuggingSameSideRails"),y(Ie,"liftTopLaneTitleBandsAboveRails"),y(ve,"shiftLeftLaneTitleBandsLeftOfRails"),y(Se,"swapDestinationTerminalTailsToReduceCrossings"),y(we,"reassignCrossingExternalRailChannels"),y(Le,"shortcutRedundantOrthogonalJogs"),y(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=y((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=y((t,e)=>{for(let n=0;n<t.length-1;n++){if(vt(t[n],t[n+1],o,e,1))return!0}return!1},"pathHitsNode"),c=y((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))(St(n.a,n.b,t.a,t.b,ke,ke)||ot(n,t,ke)>=8)&&r++}return r},"pathConflictCount"),f=y((t,e)=>{const n=Math.abs(t.y-e.rect.top),o=Math.abs(t.y-e.rect.bottom),r=Math.abs(t.x-e.rect.left),s=Math.abs(t.x-e.rect.right);let i="top",a=n;return o<a&&(i="bottom",a=o),r<a&&(i="left",a=r),s<a&&(i="right",a=s),i},"nearestSideOfRect"),l=new Map,d=y((t,e,n)=>{const o=l.get(t)??[];o.push({side:e,edgeId:n}),l.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&&d(o,f(t[0],r),e)}if(r){const o=n.get(r);o&&d(r,f(t[t.length-1],o),e)}}const u=y((t,e,n)=>{var o;return(null==(o=l.get(t))?void 0:o.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=l.get(o);t&&l.set(o,t.filter(t=>t.edgeId!==x));const e=l.get(s);e&&l.set(s,e.filter(t=>t.edgeId!==x)),d(o,f(b[0],g),x),d(s,f(b[b.length-1],p),x)}}}y(Te,"simplifyDetouredEdges");var $e=.001;function Oe(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)<$e)){if(Math.abs(a)<=$e){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)<=$e){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[Oe(n,!0),Oe(n,!1)].some(e=>e&&dt(t,Re(e)))}function Be(t,e){const n=[];for(const d of t){if(d.isLayoutOnly)continue;const t=d.points;if(t&&!(t.length<2))for(let e=0;e<t.length-1;e++)n.push({edgeId:d.id,p1:t[e],p2:t[e+1]})}const o=[],r=[];for(const d of e.values()){const t=d.isGroup,e=d.parentId;if(t&&!e){const t=gt(d);t&&r.push({id:d.id,rect:t});continue}if(t)continue;if(d.isEdgeLabel)continue;const n=gt(d);n&&o.push({nodeId:d.id,rect:n})}const s=y((t,e)=>{const n=ut(e,3);for(const{nodeId:r,rect:s}of o)if(r!==t&&dt(n,s))return!0;return!1},"labelOverlapsForeignNode"),i=y((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=y((t,e,n)=>s(t,n)||i(e,n),"labelOverlapsAnything"),c=[],f=y(t=>{for(const{id:e,rect:n}of r)if(lt(n,t))return e},"findContainingLane"),l=y((t,e)=>c.some(n=>n.labelId!==t&&dt(e,n.rect)),"overlapsPlacedLabel");for(const d of t){if(d.isLayoutOnly)continue;const t=d.labelNodeId;if(!t)continue;const n=e.get(t);if(!n)continue;const o=d.points;if(!o||o.length<2)continue;const u=n.width??0,h=n.height??0;if(u<=0||h<=0)continue;const g=[];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<$e&&s<$e||(r>=$e&&s>=$e||g.push({idx:e,length:r+s,orientation:r>=$e?"horizontal":"vertical",midX:(t.x+n.x)/2,midY:(t.y+n.y)/2}))}if(0===g.length)continue;const p=g.length>=3?g.filter(t=>t.idx>0&&t.idx<g.length-1):g,x=p.length>0?p:g,m=u>=h?"horizontal":"vertical",b=y(t=>[...t].sort((t,e)=>{const n=t.orientation===m;if(n!==(e.orientation===m))return n?-1:1;const o=t.length>=("horizontal"===t.orientation?u:h)+2;return o!==e.length>=("horizontal"===e.orientation?u:h)+2?o?-1:1:e.length-t.length}),"rankSegments"),M=g[0],I=g[g.length-1],v=[.5,.25,.75,.05,.95,.15,.85,.1,.9],S=y((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"),w=y((t,e,n)=>Math.min(n,Math.max(e,t)),"clamp"),L=y((t,e)=>t.midX>=e.left-$e&&t.midX<=e.right+$e&&t.midY>=e.top-$e&&t.midY<=e.bottom+$e,"pointInsideRectInclusive"),C=y(t=>{const e=ht(t.midX,t.midY,u,h),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+h/2+1,c=o.rect.bottom-h/2-1;if(s>i||a>c)return;const l={midX:w(t.midX,s,i),midY:w(t.midY,a,c)},d=ht(l.midX,l.midY,u,h);return L(t,d)?{laneId:o.id,anchor:l,rect:d}:void 0},"placementForAnchor"),k=y((t,e,n)=>"horizontal"===t.orientation?Math.abs(e.midX-n.x):Math.abs(e.midY-n.y),"distanceAlongSegment"),T=y((t,e)=>{const n=("horizontal"===t.orientation?u/2:h/2)+12;if(t===M){const r=o[t.idx];if(k(t,e,r)+$e<n)return!1}if(t===I){const r=o[t.idx+1];if(k(t,e,r)+$e<n)return!1}return!0},"labelClearsTerminalEndpoints"),$=y(e=>{const n=b(e);for(const r of n)for(const e of v){const n=S(r,e);if(!T(r,n))continue;const s=C(n);if(s&&(!Ne(s.rect,o)&&!l(t,s.rect)&&!a(t,d.id,s.rect)))return{laneId:s.laneId,anchor:s.anchor}}},"tryPool"),O=y((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)&&!l(t,a.rect)&&!s(t,a.rect)&&(r||!i(d.id,a.rect)))return{laneId:a.laneId,anchor:a.anchor}}},"findLaneContainingFallback"),R=$(x)??(x.length<g.length?$(g):void 0)??O(g,!0)??O(g,!1)??O(g,!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,h),o=c.findIndex(e=>e.labelId===t);o>=0?c[o]={labelId:t,rect:e}:c.push({labelId:t,rect:e})}}}y(Oe,"markerClearanceRectFor"),y(Re,"normalizeRect"),y(Ne,"labelOverlapsOwnMarker"),y(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=y((e,n,o,s)=>{const i=Fe(n,o);let a=0;const c=y(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:l,collinearY:d}=e;if(l===d)continue;let u,h;if(l){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(vt(u,h,o,[r,a],1))continue;const g=s(i,r,a,l?"x":"y"),p=g>4?g:4,x=[0,p,-p];for(const n of x){const e={...u},s={...h};if(l){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(!vt(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=y((t,e)=>rt(e,n).map(n=>({...n,edge:t,interior:n.index>=1&&n.index<=e.length-3})),"segmentsFor"),i=y(()=>{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=y((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=y((e,i)=>{const c=e.start,f=e.end,l=s(e,i);if(l.length!==i.length-1)return!1;const d=[c,f].filter(t=>Boolean(t)),u=e.labelNodeId?[e.labelNodeId]:[];for(const t of l){if(vt(t.a,t.b,o,d,-2))return!1;if(vt(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 l)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=y((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"),l=y((t,e)=>({x:t.x??(e.left+e.right)/2,y:t.y??(e.top+e.bottom)/2}),"nodeCenter"),d=y(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:l(r,i),targetCenter:l(s,a),sourceRect:i,tail:c}:void 0},"sourceDetourContextFor"),u=y((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 l=t.a.x+e;return it([{x:o.x,y:c},{x:o.x,y:f},{x:l,y:f},{x:l,y:t.b.y},...i],n)},"verticalSourceDetour"),h=y((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 l=t.a.y+e;return it([{x:c,y:o.y},{x:f,y:o.y},{x:f,y:l},{x:t.b.x,y:l},...i],n)},"horizontalSourceDetour"),g=y((t,e)=>{const n=d(t);if(n)return t.vertical?u(t,e,n.sourceCenter,n.targetCenter,n.sourceRect,n.tail):t.horizontal?h(t,e,n.sourceCenter,n.targetCenter,n.sourceRect,n.tail):void 0},"sourceDetourCandidate"),p=[-7,7,-14,14,-21,21];for(let x=0;x<12;x++){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 p){const o=f(t,n);if(o&&c(t.edge,o)){t.edge.points=o,e=!0;break}const r=g(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,l=n.y-t.y,d=(f*a-l*i)/c,u=(f*s-l*r)/c,h=.01;return d>h&&d<.99&&u>h&&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&&!le(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(Ot(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),Se(o,s);const i=y(()=>{Ce(o,s),we(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),ve(o,s),Ie(o,s),ve(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 He(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 je(t){const e=He(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 Je(t,e,n,o){var r,s;let i=0;for(const c of t.nodes)(null==o?void 0:o.skipGroups)&&(null==(r=t.nodeById.get(c))?void 0:r.isGroup)||(i=Math.max(i,n[c]??0));const a=Array.from({length:i+1},()=>[]);for(const c of e)(null==o?void 0:o.skipGroups)&&(null==(s=t.nodeById.get(c))?void 0:s.isGroup)||a[Math.max(0,n[c]??0)].push(c);return a}function qe(t){const e=_e(t),n=Ve(e),o=[],r=je(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=y((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=y(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=y(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}y(Fe,"pairKey"),y(Ye,"straightenCollinearSiblingDetours"),y(Xe,"nudgeSharedInteriorSubpaths"),y(ze,"segmentsIntersect"),y(Pe,"validateSwimlanesLayout"),y(Ae,"postProcessSwimlaneLayout"),y(Ge,"normalizeGraph"),y(De,"incoming"),y(He,"buildSuccessorMap"),y(je,"buildSortedSuccessorMap"),y(_e,"buildInDegreeMap"),y(Ve,"sortedZeroInDegreeNodes"),y(We,"buildPredecessorSuccessorMaps"),y(Je,"buildLayersFromRanks"),y(qe,"topoSortIfAcyclic"),y(Ke,"buildLayerIndex"),y(Qe,"countInversions"),y(Ze,"removeCycles_DFS"),y(Ue,"buildTopLaneMap"),y(tn,"createTopLaneResolver"),y(en,"buildTopLaneOrder"),y(nn,"resolveTopLaneOrder");var on=8,rn=4,sn=!0,an=100,cn=40;function fn(t,e){const n=Ge(t),o=(null==e?void 0:e.laneOf)??(()=>null),r=null==e?void 0:e.rankHint,{preds:s}=We(n);for(const y of s.values())y.sort((t,e)=>t.localeCompare(e));const i=qe(n)??[...n.nodes].sort((t,e)=>t.localeCompare(e)),a=new Map;for(const[y,v]of i.entries())a.set(v,y);const c=new Map,f=new Map;for(const y of n.nodes)f.set(y,[]);for(const y of i){const t=(s.get(y)??[]).filter(t=>c.has(t));if(t.length>0){const e=ln(y,t,{laneOf:o,rankHint:r,topoIndex:a});c.set(y,e),f.get(e).push(y)}else c.has(y)||c.set(y,null)}for(const y of n.nodes)c.has(y)||c.set(y,null);const l=new Set;for(const y of n.nodes)null===(c.get(y)??null)&&l.add(y);const d=[...l].sort((t,e)=>{const n=a.get(t)??0,o=a.get(e)??0;return n===o?t.localeCompare(e):n-o}),u=dn(n),h=new Map;for(const[y,v]of u.entries())h.set(y,[...v].sort((t,e)=>t.localeCompare(e)));const g=un(h),p=hn(h),x=new Map;for(const y of n.nodes)x.set(y,[]);for(const y of p)for(const t of y.nodes){const e=x.get(t);e?e.push(y.id):x.set(t,[y.id])}const m=[],b=[],M=new Set,I=y(t=>{if(!M.has(t)){M.add(t),m.push(t);for(const e of f.get(t)??[])I(e);b.push(t)}},"walk");for(const y of d)I(y);for(const y of i)I(y);return{parent:c,children:f,roots:d,componentOf:g,blocks:p,nodeBlocks:x,adjacency:h,preorder:m,postorder:b,topologicalOrder:i}}function ln(t,e,n){const o=n.laneOf(t);return[...e].sort((t,e)=>{var r,s;const i=n.laneOf(t),a=n.laneOf(e),c=null!=i&&i===o;if(c!==(null!=a&&a===o))return c?-1:1;const f=null==(r=n.rankHint)?void 0:r[t],l=null==(s=n.rankHint)?void 0:s[e];if(null!=f&&null!=l&&f!==l)return l-f;const d=n.topoIndex.get(t)??0,u=n.topoIndex.get(e)??0;return d!==u?d-u:t.localeCompare(e)})[0]}function dn(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 un(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 hn(t){const e=new Map,n=new Map,o=[],r=[];let s=0;const i=y((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(gn(a,f,o,r.length))))},"visit");for(const a of t.keys())e.has(a)||i(a,null);return r}function gn(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 pn(t,e,n){const o=[...t.nodes],r=new Map;for(const[y,b]of o.entries())r.set(b,y);const s=o.length,i=new Array(s).fill(-1),a=new Array(s).fill(0),c=[],f=new Set;for(const y of o){const t=n.parent.get(y)??null,e=r.get(y);null!=e&&(null==t&&(i[e]=-1,a[e]=0,f.has(y)||(f.add(y),c.push(y))))}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 y of o){if(f.has(y))continue;const t=r.get(y);null!=t&&(i[t]=-1,a[t]=0,f.add(y))}const l=Math.max(1,Math.ceil(Math.log2(Math.max(1,s)))+1),d=Array.from({length:l},()=>new Array(s).fill(-1));for(let y=0;y<s;y++)d[0][y]=i[y];for(let y=1;y<l;y++)for(let t=0;t<s;t++){const e=d[y-1][t];d[y][t]=-1===e?-1:d[y-1][e]}const u=y((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<l;o++)if(n>>o&1&&-1===(t=d[o][t]))return-1;if(t===e)return t;for(let o=l-1;o>=0;o--){const n=d[o][t],r=d[o][e];-1!==n&&-1!==r&&(n!==r&&(t=n,e=r))}return d[0][t]},"lcaIndex"),h=Array.from({length:s},()=>new Map);for(const y of t.edges){let t=y.src,n=y.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=h[c];for(let e=o;e<s;e++)f.set(e,(f.get(e)??0)+1)}const g=new Map,p=y((t,e)=>{if(0!==e.size)for(const[n,o]of e)t.set(n,(t.get(n)??0)+o)},"mergeInto"),x=new Set,m=y(t=>{const o=r.get(t);x.add(t);const s=null==o?void 0:h[o],i=s?new Map(s):new Map,a=n.children.get(t)??[];for(const n of a){const o=m(n),r=e[t];if(null!=r){let s=g.get(t);s||(s=new Map,g.set(t,s));let i=o.get(r)??0;const a=e[n];null!=a&&a>r&&(i+=1),s.set(n,i)}p(i,o)}return i},"dfs");for(const y of n.roots)x.has(y)||m(y);for(const y of o)x.has(y)||m(y);return g}function xn(t,e,n){const o=new Map,r=y(t=>{let s=n[t]??0;const i=[...e.get(t)??[]];i.sort(mn(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 mn(t){return(e,n)=>{const o=t[e]??0,r=t[n]??0;return o===r?e.localeCompare(n):o-r}}function yn(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=y(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 bn(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 Mn(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=(null==f?void 0:f.get(t))??0,r=(null==f?void 0: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 In(t,e,n){const o=fn(t,{rankHint:e,laneOf:n}),{children:r,roots:s}=o;for(const l of t.nodes)r.has(l)||r.set(l,[]);const i=pn(t,e,o),a=[...s].sort(mn(e)),c=Mn(r,e,i,xn(a,r,e));let f=yn(a,t.nodes,e,c);return f=bn(f),f}function vn(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 Sn(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+=vn(t[s],t[s+1],o);return r}function wn(t,e){const n={...e},{preds:o}=We(t),r=tn(t);let s=Sn(In(t,n,r),t.edges,n);const i=rn;for(let a=0;a<i;a++){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 l=Sn(In(t,n,r),t.edges,n);l<s?(s=l,e=!0):n[a]=f}if(!e)break}return n}function Ln(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 l=e[r]??0,d=l+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(l,u,d);h!==l&&(e[r]=h)}}function Cn(t,e){const n=Ge(t),o=qe(n)??[...n.nodes].sort(),r=(null==e?void 0:e.compactSingleInput)??!1,s=tn(n);let i=Object.create(null);for(const a of o){const t=De(n,a),o=(null==e?void 0: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}}(null==e?void 0:e.optimizeRanksByCrossings)&&(i=wn(n,i)),(null==e?void 0:e.ignoreCrossLaneEdges)&&Ln(n,i);return{layers:In(n,i,s),rankOf:i,dummy:new Set}}function kn(t,e){const n=Ge(t),o={...Cn(n,{compactSingleInput:null==e?void 0:e.compactSingleInput,ignoreCrossLaneEdges:null==e?void 0:e.ignoreCrossLaneEdges,optimizeRanksByCrossings:null==e?void 0:e.optimizeRanksByCrossings}).rankOf},r=tn(n),{preds:s,succs:i}=We(n,t=>{if(null==e?void 0:e.ignoreCrossLaneEdges){const e=r(t.src),n=r(t.dst);if(e&&n&&e!==n)return!1}return!0}),a=qe(n)??[...n.nodes],c=[...a].reverse(),f=y((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"),l=on,d=y(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,l=Math.round((a+c)/2),d=f(n,l);d!==o[n]&&(o[n]=d,e=!0)}return e},"relaxOrder");for(let u=0;u<l;u++){const t=d(a),e=d(c);if(!t&&!e)break}for(const u of a){let t=0;for(const e of s.get(u)??[])t=Math.max(t,(o[e]??0)+1);(o[u]??0)<t&&(o[u]=t)}for(const u of c){const t=i.get(u)??[];if(t.length>0){const e=Math.min(...t.map(t=>(o[t]??0)-1));(o[u]??0)>e&&(o[u]=e)}}return{layers:Je(n,a,o),rankOf:o,dummy:new Set}}function Tn(t){const e=_e(t),n=je(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 $n(t,e){const n=Ge(t),o="LR"===(null==e?void 0:e.direction)?Tn(n)??[...n.nodes].sort():qe(n)??[...n.nodes].sort(),r=tn(n),s=y(t=>r(t)??t,"laneOf"),i=Object.create(null),a=new Map,c=y((t,n)=>(null==e?void 0:e.ignoreCrossLaneEdges)??!0?s(t)===s(n)?1:0:1,"edgeWeight");for(const f of o){const t=n.nodeById.get(f);if(null==t?void 0: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),l=a.get(r)??0,d=Math.max(o,l);i[f]=d,a.set(r,d+1)}return{layers:Je(n,o,i,{skipGroups:!0}),rankOf:i,dummy:new Set}}function On(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=y(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)),l=[];for(const u of f){const t=o[u.src]??0,e=o[u.dst]??0;if(e-t<=1){l.push(u);continue}let n=u.src;for(let o=t+1,s=0;o<e;o++,s++){const t=c(o);l.push({id:`${u.id}#${s}`,src:n,dst:t,weight:u.weight,ref:u.ref}),n=t}const r=e-t-2;l.push({id:`${u.id}#${Math.max(r+1,0)}`,src:n,dst:u.dst,weight:u.weight,ref:u.ref})}const d={nodes:[...n.nodes,...[...s].filter(t=>!n.nodes.includes(t))],edges:l,layout:n.layout,nodeById:a};return{layering:{layers:r,rankOf:o,dummy:s},graphWithDummies:d}}function Rn(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 Nn(t){if(0===t.length)return Number.POSITIVE_INFINITY;return t.reduce((t,e)=>t+e,0)/t.length}function Bn(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 En(t,e,n){const o=n.get(t)??0,r=n.get(e)??0;return o!==r?o-r:t.localeCompare(e)}function Fn(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)});a.sort((t,e)=>t.u===e.u?t.v-e.v:t.u-e.u);return Qe(a.map(t=>t.v))}function Yn(t,e,n){return[...t].sort((t,o)=>{const r=Rn(e.get(t)??[]),s=Rn(e.get(o)??[]);return r===s?En(t,o,n):isFinite(r)?isFinite(s)?r-s:-1:1})}function Xn(t,e,n,o,r,s){const i=Ke(t),a=Ke(e),c=Bn(e,i,n,o);if(!r||!s||0===s.length)return Yn(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 l=[];for(const u of s){const t=f.get(u);if(!t||0===t.length)continue;const e=Yn(t,c,a);l.push(...e)}const d=f.get(null);if(d&&d.length>0){const t=Yn(d,c,a);for(const e of t){const t=Nn(c.get(e)??[]);let n=l.length;if(isFinite(t))for(const[e,o]of l.entries()){if(t<Nn(c.get(o)??[])){n=e;break}}l.splice(n,0,e)}}return l}function zn(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)),l=c?n.filter(t=>a.has(t.src)&&c.has(t.dst)):void 0,d=y(e=>{let n=Fn(t,e,f);return l&&o&&(n+=Fn(e,o,l)),n},"crossingScore"),u=r?new Map:null;if(r&&u)for(const p of e)u.set(p,r(p));let h=!0,g=d(s);for(;h;){h=!1;for(let t=0;t+1<s.length;t++){if(u){if(u.get(s[t])!==u.get(s[t+1]))continue}const e=g;[s[t],s[t+1]]=[s[t+1],s[t]];const n=d(s);n<e?(g=n,h=!0):[s[t],s[t+1]]=[s[t+1],s[t]]}}return s}function Pn(t,e,n){const o=t.layers.map(t=>[...t]),r=e.edges,s=tn(e),i=nn(e,null==n?void 0:n.laneOrder);for(let a=0;a<3;a++){for(let t=1;t<o.length;t++)o[t]=Xn(o[t-1],o[t],r,"down",s,i),o[t]=zn(o[t-1],o[t],r,o[t+1],s);for(let t=o.length-2;t>=0;t--)o[t]=Xn(o[t+1],o[t],r,"up",s,i),o[t]=zn(o[t+1],o[t],r,o[t-1],s)}return{layers:o}}function An(t,e,n){const o=(null==n?void 0:n.layerGap)??an,r=(null==n?void 0:n.nodeGap)??cn,s=(null==n?void 0:n.laneGap)??2*r,i=(null==n?void 0:n.direction)??"TB",a="LR"===i||"RL"===i,c=t.layers,f=Object.create(null),l=Object.create(null),d=y(t=>e.nodeById.get(t),"getNode"),u=y(t=>{var e;return(null==(e=d(t))?void 0:e.width)??0},"getWidth"),h=y(t=>{var e;return(null==(e=d(t))?void 0:e.height)??0},"getHeight"),g=tn(e),p=nn(e,null==n?void 0:n.laneOrder),x=c.map(t=>t.reduce((t,e)=>Math.max(t,h(e)),0)),m=[];if(a)for(let y=0;y+1<c.length;y++){const t=c[y].reduce((t,e)=>Math.max(t,u(e)),0),e=c[y+1].reduce((t,e)=>Math.max(t,u(e)),0),n=x[y]/2+x[y+1]/2,r=(t+e)/2,s=Math.max(0,r-n-o);m.push(s)}const b=new Set;for(const y of c)for(const t of y)b.add(g(t));const M=b.has(null),I=p.filter(t=>b.has(t)),v=[...M?[null]:[],...I],S=Object.create(null);for(const y of I)S[y]=0;M&&(S.null=0);for(const y of c){const t=Object.create(null),e=[];for(const n of y){const o=g(n);null===o?e.push(n):(t[o]||(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);S[n]=Math.max(S[n]??0,t)}if(M&&e.length){const t=e.reduce((t,e)=>t+u(e),0)+r*Math.max(0,e.length-1);S.null=Math.max(S.null??0,t)}}const w=new Map;{const t=v.map(t=>(null===t?S.null:S[t])??0);let e=-(t.reduce((t,e)=>t+e,0)+s*Math.max(0,v.length-1))/2;for(let n=0;n<v.length;n++){const o=v[n],r=t[n]??0,i=e+r/2;w.set(o,i),e+=r,n<v.length-1&&(e+=s)}}let L=0;for(const[y,k]of c.entries()){const t=x[y]??0,e=new Map;for(const n of k){const t=g(n),o=e.get(t)??[];o.push(n),e.set(t,o)}for(const n of v){const o=e.get(n)??[];if(0===o.length)continue;const s=w.get(n);if(1===o.length){const e=o[0];f[e]=s,l[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,l[i]=L+t/2,n+=o+r}}}L+=t+o+(m[y]??0)}const C=new Map;for(const y of e.edges){const t=y.ref.id;C.has(t)||C.set(t,[]),C.get(t).push(y)}for(const[,y]of C){if(0===y.length)continue;const t=y[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 y)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);(null==t?void 0:t.isDummy)&&(f[i]=r)}}return{x:f,y:l}}y(fn,"buildDrivingTree"),y(ln,"chooseParent"),y(dn,"buildAdjacency"),y(un,"assignComponents"),y(hn,"computeBlocks"),y(gn,"popBlock"),y(pn,"computeSubtreeCrossCounts"),y(xn,"annotateMinimumLayers"),y(mn,"compareByRankThenId"),y(yn,"emitNodesInTreeOrder"),y(bn,"deduplicateLayers"),y(Mn,"createChildOrderer"),y(In,"buildMultitreeLayerOrder"),y(vn,"countCrossingsBetweenAdjacent"),y(Sn,"totalCrossings"),y(wn,"optimizeRanksByCrossings"),y(Ln,"adjustCrossLaneSources"),y(Cn,"assignLayers_LongestPath"),y(kn,"assignLayers_Gravity"),y(Tn,"topoSortByGenerationIfAcyclic"),y($n,"assignLayers_LaneAwareCompact"),y(On,"makeProperLayering"),y(Rn,"median"),y(Nn,"barycenter"),y(Bn,"neighborPositionsFor"),y(En,"currentOrderTieBreak"),y(Fn,"countCrossingsBetweenAdjacent"),y(Yn,"sortByHeuristic"),y(Xn,"reorderLayer"),y(zn,"transposeImprove"),y(Pn,"orderLayers"),y(An,"assignCoordinates");function Gn(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 Dn(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 Hn(t,e){const n=[...t],o=Dn(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 jn(t,e){let n=0;for(const[o,r]of t.entries())n+=Math.abs(o-(e.get(r)??o));return n}function _n(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 Vn(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),l=n.get(c);if(null==f||null==l)continue;const[d,u]=f<=l?[a,c]:[c,a],h=`${d}\0${u}`,g=r.get(h);g?g.weight++:r.set(h,{a:d,b:u,weight:1})}return[...r.values()]}function Wn(t,e,n){const o=[...t];let r=_n(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=_n(o,e);n<r?(r=n,s=!0):[o[t],o[t+1]]=[o[t+1],o[t]]}}return{order:o,cost:r,sourceDistance:jn(o,n)}}function Jn(t,e){return t.cost!==e.cost?t.cost<e.cost:t.sourceDistance<e.sourceDistance}function qn(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 Gn(`${t.join("|")}#${o}#${n}`)}function Kn(t,e={}){const n=en(t);if(n.length<2)return n;const o=Vn(t);if(0===o.length)return n;const r=new Map(n.map((t,e)=>[t,e]));let s=Wn(n,o,r);const i=Math.max(0,e.restarts??8);for(let a=0;a<i;a++){const t=Wn(Hn(n,qn(n,o,a)),o,r);Jn(t,s)&&(s=t)}return s.order}function Qn(t,e){const n=(null==e?void 0:e.ignoreCrossLaneEdges)??!0,o=(null==e?void 0:e.optimizeRanksByCrossings)??!0,r=Ge(t),s=(null==e?void 0:e.automaticLaneOrdering)?Kn(r,{restarts:8}):void 0,i=Ze(r),a=i.acyclic,c=n?$n(a,{compactSingleInput:(null==e?void 0:e.compactSingleInput)??sn,ignoreCrossLaneEdges:!0,direction:null==e?void 0:e.direction}):kn(a,{compactSingleInput:(null==e?void 0:e.compactSingleInput)??sn,ignoreCrossLaneEdges:!1,optimizeRanksByCrossings:o}),{layering:f,graphWithDummies:l}=On(c,a),d=Pn(f,l,{laneOrder:s}),u=An(d,l,{layerGap:null==e?void 0:e.layerGap,nodeGap:null==e?void 0:e.nodeGap,direction:null==e?void 0:e.direction,laneOrder:s});return{acyclic:a,reversed:i.reversed,layering:f,ordered:d,coordinates:u}}y(Gn,"hashString"),y(Dn,"mulberry32"),y(Hn,"deterministicShuffle"),y(jn,"sourceDistance"),y(_n,"laneArrangementCost"),y(Vn,"buildWeightedLaneEdges"),y(Wn,"greedySwitch"),y(Jn,"isBetterCandidate"),y(qn,"seedForRestart"),y(Kn,"optimizeTopLaneOrder"),y(Qn,"sugiyamaLayout");var Zn=1e-6,Un=15,to=15,eo=20;function no(t,e,n){const o=t.x??0,r=t.y??0,s=e.x-o,i=e.y-r,a=Math.abs(s),c=Math.abs(i);if(a<Zn&&c<Zn)return n;return c>Zn&&3*c>=a?i>0?"bottom":"top":a>Zn?s>0?"right":"left":n}function oo(t,e){return Math.abs(t.to-e.from)<Zn||Math.abs(t.to-e.to)<Zn?t.to:t.from}function ro(t,e){return"vertical"===t.orient?{x:t.coord,y:e}:{x:e,y:t.coord}}function so(t,e){var n,o,r,s;const i=t.nodes??[],a=t.edges??[],c=[];for(const y of a)y.isLayoutOnly||c.push({...y,__originalEdge:y});const f=new Map,l=new Map,d=[],u="LR"===e;for(const y of i)f.set(y.id,y);const h=i.filter(t=>t.isGroup&&!t.parentId);for(const it of h){const t={id:it.id},e=y(n=>{l.set(n.id,t),i.filter(t=>t.parentId===n.id).forEach(e)},"assignLane");e(it)}const g=i.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:u?n/2+8:e/2+8}}),p=y((t,e,n,o)=>{let r=d.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:[]},d.push(r)),r.spanMin=Math.min(r.spanMin,n),r.spanMax=Math.max(r.spanMax,o),r},"getOrAddPipe"),x=y((t,e)=>{const n=t.width??10,o=t.height??10,r=t.x??0,s=t.y??0;switch(e){case"top":return{x:r,y:s-o/2};case"bottom":return{x:r,y:s+o/2};case"left":return{x:r-n/2,y:s};case"right":return{x:r+n/2,y:s}}},"portForSide"),m=y((t,e,n)=>x(t,no(t,e,n?"bottom":"top")),"getOrthogonalPort"),b=[],M=[],I=new Set,v=y((t,e,n)=>{if(0===b.length)return 0;const o=Math.abs(e.y-n.y)<Zn,r=Math.abs(e.x-n.x)<Zn;if(!o&&!r)return 0;let s=0;if(o){const o=e.y,r=Math.min(e.x,n.x)-Zn,i=Math.max(e.x,n.x)+Zn;if(i<=r)return 0;for(const e of b)e.edgeIndex!==t&&"vertical"===e.orientation&&(e.pipe.coord<r||e.pipe.coord>i||e.from-Zn<=o&&e.to+Zn>=o&&(s+=1e3))}else if(r){const o=e.x,r=Math.min(e.y,n.y)-Zn,i=Math.max(e.y,n.y)+Zn;if(i<=r)return 0;for(const e of b)e.edgeIndex!==t&&"horizontal"===e.orientation&&(e.pipe.coord<r||e.pipe.coord>i||e.from-Zn<=o&&e.to+Zn>=o&&(s+=1e3))}return s},"crossingPenalty"),S=c.map((t,e)=>{if(!t.start||!t.end)return{idx:e,crossLane:0,dx:0,dy:0};const n=f.get(t.start),o=f.get(t.end),r=l.get(t.start),s=l.get(t.end);return{idx:e,crossLane:r&&s&&r.id!==s.id?1:0,dx:n&&o?Math.abs((o.x??0)-(n.x??0)):0,dy:n&&o?Math.abs((o.y??0)-(n.y??0)):0}}).sort((t,e)=>{if(t.crossLane!==e.crossLane)return e.crossLane-t.crossLane;const n=t.dx+t.dy,o=e.dx+e.dy;return Math.abs(n-o)>1?n-o:t.idx-e.idx}).map(t=>t.idx),w=y((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!!g.find(c=>(!n||c.nodeId!==n)&&((!o||c.nodeId!==o)&&(Math.abs(t.x-e.x)>Zn?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"),L=new Map,C=new Map;for(const y of c)y.start&&y.end&&y.start!==y.end&&(C.set(y.start,(C.get(y.start)??0)+1),C.set(y.end,(C.get(y.end)??0)+1));const k=y((t,e)=>no(t,e,"bottom"),"determineSide"),T=new Map;for(const[y,it]of c.entries()){if(!it.start||!it.end||it.start===it.end)continue;if(it.points&&it.points.length>0)continue;const t=f.get(it.start),e=f.get(it.end);if(!t||!e)continue;const n=(e.x??0)-(t.x??0),o=(e.y??0)-(t.y??0);T.set(y,{edgeIdx:y,srcId:it.start,dstId:it.end,srcSide:k(t,{x:e.x??0,y:e.y??0}),dstSide:k(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 $=y(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"),O=y(t=>"top"===t.srcSide||"bottom"===t.srcSide?t.dxSign>=0?"right":"left":t.dySign>=0?"bottom":"top","secondarySide"),R=new Map;for(const y of T.values()){const t=`${y.srcId}:${y.srcSide}`;R.has(t)||R.set(t,[]),R.get(t).push(y)}const N=new Map,B=y((t,e)=>`${t}:${e}`,"loadKey");for(const y of T.values())N.set(B(y.srcId,y.srcSide),(N.get(B(y.srcId,y.srcSide))??0)+1),N.set(B(y.dstId,y.dstSide),(N.get(B(y.dstId,y.dstSide))??0)+1);for(const y of R.values())if(!(y.length<2)){y.sort((t,e)=>{const n=$(t),o=$(e);return Math.abs(n-o)>1e-9?o-n:t.edgeIdx-e.edgeIdx});for(let t=1;t<y.length;t++){const e=y[t],n=O(e),o=N.get(B(e.srcId,e.srcSide))??0,r=N.get(B(e.srcId,n))??0;r>=o||(N.set(B(e.srcId,e.srcSide),o-1),N.set(B(e.srcId,n),r+1),e.srcSide=n)}}const E=y(t=>{const e=null==t?void 0:t.shape;return"question"===e||"diamond"===e},"isDiamondNode"),F=new Map;for(const y of T.values())F.has(y.dstId)||F.set(y.dstId,new Set),F.get(y.dstId).add(y.dstSide);for(const y of T.values()){if(!E(f.get(y.srcId)))continue;const t=F.get(y.srcId);if(!(null==t?void 0:t.has(y.srcSide)))continue;const e=O(y);if(t.has(e)||(N.get(B(y.srcId,e))??0)>0)continue;const n=N.get(B(y.srcId,y.srcSide))??0;N.set(B(y.srcId,y.srcSide),Math.max(0,n-1)),N.set(B(y.srcId,e),1),y.srcSide=e}for(const y of T.values()){const{edgeIdx:t,srcId:e,dstId:n,srcSide:o,dstSide:r}=y,s=f.get(e),i=f.get(n),a=`${e}:${o}:src`,c="top"===o||"bottom"===o?i.x??0:i.y??0;L.has(a)||L.set(a,[]),L.get(a).push({edgeIdx:t,oppositeCoord:c});const l=`${n}:${r}:dst`,d="top"===r||"bottom"===r?s.x??0:s.y??0;L.has(l)||L.set(l,[]),L.get(l).push({edgeIdx:t,oppositeCoord:d})}const Y=new Map;for(const[y,it]of L){if(it.length<2)continue;it.sort((t,e)=>t.oppositeCoord-e.oppositeCoord);const t=y.split(":"),e=t.slice(0,-2).join(":"),n=t[t.length-2],o=t[t.length-1],r=f.get(e);if(!r)continue;const s="left"===n||"right"===n?r.height??10:r.width??10,i=r.shape,a="question"===i||"diamond"===i?.3*s:s,c=20,l=Math.min(c,Math.max(8,a/(it.length+1))),d=-(l*(it.length-1))/2;for(const[f,u]of it.entries()){const t=d+f*l,e=`${u.edgeIdx}:${o}`;Y.set(e,t)}}const X=y(t=>{var e;return Boolean(null==(e=c[t])?void 0:e.labelNodeId)},"edgeHasLabelNode"),z=y((t,e)=>!!t&&((L.get(`${t}:${e}:src`)??[]).some(({edgeIdx:t})=>X(t))||(L.get(`${t}:${e}:dst`)??[]).some(({edgeIdx:t})=>X(t))),"faceHasLabelNode"),P=y((t,e,n)=>"top"===e||"bottom"===e?{x:t.x+n,y:t.y}:{x:t.x,y:t.y+n},"applyPortOffset"),A=y((t,e,n)=>{const o=T.get(t),r={x:n.x??0,y:n.y??0},s={x:e.x??0,y:e.y??0},i=(null==o?void 0:o.srcSide)??k(e,r),a=(null==o?void 0:o.dstSide)??k(n,s);let c=o?x(e,o.srcSide):m(e,r,!0),f=o?x(n,o.dstSide):m(n,s,!1);const l=Y.get(`${t}:src`),d=Y.get(`${t}:dst`);return void 0!==l&&(c=P(c,i,l)),void 0!==d&&(f=P(f,a,d)),{pSrcPort:c,pDstPort:f,srcSide:i,dstSide:a}},"portsForEdge");for(const it of S){const t=c[it];if(M[it]=[],!t.start||!t.end)continue;if(t.points&&t.points.length>0)continue;if(t.start===t.end)continue;const e=f.get(t.start),i=f.get(t.end);if(!e||!i)continue;const{pSrcPort:a,pDstPort:l,srcSide:h,dstSide:x}=A(it,e,i),m={...a},S={...l},k="top"===h||"bottom"===h,T="top"===x||"bottom"===x;if(k){const t=a.y>(e.y??0);m.y=t?a.y+eo:a.y-eo}else{const t=a.x>(e.x??0);m.x=t?a.x+eo:a.x-eo}if(T){const t=l.y>(i.y??0);S.y=t?l.y+eo:l.y-eo}else{const t=l.x>(i.x??0);S.x=t?l.x+eo:l.x-eo}const $=y((t,e)=>{for(const n of g)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"),O=y((t,e,n,o,r)=>{if(r){const r=t.y>(e.y??0);return{x:(n.x??0)>=t.x?o.maxX+Un:o.minX-Un,y:r?o.maxY+to:o.minY-to,leavesPositiveSide:r}}const s=t.x>(e.x??0),i=(n.y??0)>=t.y;return{x:s?o.maxX+Un:o.minX-Un,y:i?o.maxY+to:o.minY-to,leavesPositiveSide:s}},"obstacleDetour");let R=[];const N=[t.start,t.end],B=$(m,N);if(B.inside&&B.obstacle){const t=B.obstacle;if(k){const n=O(a,e,i,t,!0);m.x=n.x,m.y=n.y;const o=n.leavesPositiveSide?Math.min(t.minY-2,a.y+eo):Math.max(t.maxY+2,a.y-eo);R=[{x:a.x,y:o},{x:n.x,y:o},{x:n.x,y:n.y}]}else{const n=O(a,e,i,t,!1),o=n.leavesPositiveSide?Math.min(t.minX-2,a.x+eo):Math.max(t.maxX+2,a.x-eo);m.x=n.x,m.y=n.y,R=[{x:o,y:a.y},{x:o,y:n.y},{x:n.x,y:n.y}]}}let E=[];const F=$(S,N);if(F.inside&&F.obstacle){const t=F.obstacle;if(T){const n=O(l,i,e,t,!0);S.x=n.x,S.y=n.y,E=[{x:n.x,y:n.y},{x:l.x,y:n.y}]}else{const n=O(l,i,e,t,!1);S.x=n.x,S.y=n.y,E=[{x:n.x,y:n.y},{x:n.x,y:l.y}]}}if(0===R.length&&0===E.length){const e=Un,i=Math.abs(m.x-S.x)<e,c=Math.abs(m.y-S.y)<e,f=void 0!==Y.get(`${it}:src`)||void 0!==Y.get(`${it}:dst`),d=((null==(n=L.get(`${t.start??""}:${h}:src`))?void 0:n.length)??0)+((null==(o=L.get(`${t.start??""}:${h}:dst`))?void 0:o.length)??0),u=((null==(r=L.get(`${t.end??""}:${x}:src`))?void 0:r.length)??0)+((null==(s=L.get(`${t.end??""}:${x}:dst`))?void 0:s.length)??0),g=d>1||u>1,p=C.get(t.start??"")??0,y=C.get(t.end??"")??0,M=d>1&&z(t.start,h)||u>1&&z(t.end,x);if((i||c)&&!f&&(!g||g&&!M&&(d<=1||p<=2)&&(u<=1||y<=2))){if(!w(a,l,t.start,t.end)){t.points=[{...a},{...m},{...S},{...l}],I.add(it);const e=c?"horizontal":"vertical",n=c?a.y:a.x,o=c?Math.min(a.x,l.x):Math.min(a.y,l.y),r=c?Math.max(a.x,l.x):Math.max(a.y,l.y),s={id:`fast-path-${e}-${n.toFixed(0)}-${it}`,orientation:e,coord:n,spanMin:o,spanMax:r,tracks:[]};b.push({edgeIndex:it,segmentIndex:0,orientation:e,pipe:s,trackIndex:0,from:o,to:r});continue}}}const X=p("vertical",m.x,m.y,m.y);m.x=X.coord;const P=p("vertical",S.x,S.y,S.y);S.x=P.coord;let G=Math.min(m.x,S.x)-50,D=Math.max(m.x,S.x)+50,H=Math.min(m.y,S.y)-50,j=Math.max(m.y,S.y)+50;for(const n of g){const t=Math.min(m.x,S.x),e=Math.max(m.x,S.x),o=Math.min(m.y,S.y),r=Math.max(m.y,S.y);n.minX<e&&n.maxX>t&&n.minY<r&&n.maxY>o&&(G=Math.min(G,n.minX-25),D=Math.max(D,n.maxX+25),H=Math.min(H,n.minY-25),j=Math.max(j,n.maxY+25))}for(const n of g){if(n.maxX<G||n.minX>D||n.maxY<H||n.minY>j)continue;const t=Un;p("horizontal",n.minY-t,G,D),p("horizontal",n.maxY+t,G,D);const e=to;p("vertical",n.minX-e,H,j),p("vertical",n.maxX+e,H,j)}p("horizontal",m.y,G,D),p("horizontal",S.y,G,D);const _=d.filter(t=>"horizontal"===t.orientation&&t.coord>=H&&t.coord<=j),V=d.filter(t=>"vertical"===t.orientation&&t.coord>=G&&t.coord<=D),W=y((t,e)=>`${t.toFixed(1)},${e.toFixed(1)}`,"getKey"),J=W(m.x,m.y),q=W(S.x,S.y),K=new Map,Q=new Map,Z=new Map,U=new Set,tt=[];K.set(J,0),Z.set(J,"n"),tt.push({key:J,f:Math.hypot(S.x-m.x,S.y-m.y),pt:m}),U.add(J);let et=[];const nt=y((e,n)=>w(e,n,t.start,t.end),"checkSegmentBlocked"),ot={x:S.x,y:m.y},rt=nt(m,ot),st=nt(ot,S),at=rt||st,ct={x:m.x,y:S.y},ft=nt(m,ct),lt=nt(ct,S);if(at?ft||lt||(et=Math.abs(m.x-S.x)<Zn?[m,S]:[m,ct,S]):et=Math.abs(m.y-S.y)<Zn||Math.abs(m.x-S.x)<Zn?[m,S]:[m,ot,S],0===et.length)for(;tt.length>0;){tt.sort((t,e)=>t.f-e.f);const e=tt.shift();if(U.delete(e.key),e.key===q){let t=q,e=S;for(et=[e];Q.has(t);){const n=Q.get(t);et.unshift(n),e=n,t=W(n.x,n.y)}break}const n=e.pt.x,o=e.pt.y,r=V.sort((t,e)=>t.coord-e.coord),s=r.findIndex(t=>Math.abs(t.coord-n)<1),i=_.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(g.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=W(f.x,f.y),l=Math.abs(f.x-n)+Math.abs(f.y-o),d=v(it,e.pt,f);let u=0;const h=S.x-m.x,p=S.y-m.y,x=f.x-n,y=f.y-o;(p>10&&y<-5||p<-10&&y>5)&&(u=100*Math.abs(y)),(h>10&&x<-5||h<-10&&x>5)&&(u+=50*Math.abs(x));let b=0;const M=Z.get(e.key)??"n",I=Math.abs(x)>Zn?"h":"v";"n"!==M&&M!==I&&(b=50);const w=l+d+u+b,L=(K.get(e.key)??1/0)+w,C=Math.abs(S.x-f.x)+Math.abs(S.y-f.y);if(L<(K.get(c)??1/0))if(Q.set(c,e.pt),K.set(c,L),Z.set(c,I),U.has(c)){const t=tt.findIndex(t=>t.key===c);-1!==t&&(tt[t].f=L+C)}else tt.push({key:c,f:L+C,pt:f}),U.add(c)}}if(0===et.length&&(et=[m,{x:m.x,y:S.y},S]),et.length>4){const t=et[0],e=et[et.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 d of et)n=Math.min(n,d.x),o=Math.max(o,d.x),r=Math.min(r,d.y),s=Math.max(s,d.y);const i=o>Math.max(t.x,e.x),a=n<Math.min(t.x,e.x);if(u){const r=to;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=g.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=g.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 c=y(n=>{const o=e.y>t.y,r=g.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(u&&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-Zn)return t}else{const t=Math.min(...s.map(t=>t.minY))-15;if(t>e.y+Zn)return t}return e.y},"findBestReturnY"),f=y(n=>{const o=c(n),r={x:n,y:t.y},s={x:n,y:o},i={x:e.x,y:o},a=nt(t,r),f=nt(r,s),l=nt(s,i),d=o!==e.y&&nt(i,e);return a||f||l||d?null:Math.abs(o-e.y)<Zn?[t,r,s,e]:[t,r,s,i,e]},"trySimplifyWithDetourX"),l=i&&!a?f(o):a&&!i?f(n):null;l&&(et=l)}const dt=[a,...R,...et,...E.reverse(),l];if(dt.length>=3){const t=dt[dt.length-1],e=dt[dt.length-2],n=dt[dt.length-3],o=Math.abs(n.y-e.y)<Zn&&Math.abs(e.y-t.y)<Zn,r=Math.abs(n.x-e.x)<Zn&&Math.abs(e.x-t.x)<Zn;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)&&dt.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)&&dt.splice(-2,1)}}const ut=[dt[0]];for(let n=1;n<dt.length-1;n++){if(1===n){ut.push(dt[n]);continue}const t=ut[ut.length-1],e=dt[n],o=dt[n+1];if(Math.abs(t.y-e.y)<Zn&&Math.abs(e.y-o.y)<Zn){if(e.x>t.x!==o.x>e.x){ut.push(e);continue}continue}if(Math.abs(t.x-e.x)<Zn&&Math.abs(e.x-o.x)<Zn){if(e.y>t.y!==o.y>e.y){ut.push(e);continue}continue}ut.push(e)}ut.push(dt[dt.length-1]);for(let n=0;n<ut.length-1;n++){const t=ut[n],e=ut[n+1],o=Math.abs(t.x-e.x)<Zn?"vertical":"horizontal",r="vertical"===o?t.x:t.y,s="vertical"===o?Math.min(t.y,e.y):Math.min(t.x,e.x),i="vertical"===o?Math.max(t.y,e.y):Math.max(t.x,e.x),a=p(o,r,s,i),c={edgeIndex:it,segmentIndex:n,orientation:o,pipe:a,trackIndex:0,from:s,to:i};b.push(c),M[it].push(b.length-1),a.tracks[0]||(a.tracks[0]={index:0,coord:a.coord,segments:[]}),a.tracks[0].segments.push({edgeIndex:it,segmentIndex:n,from:s,to:i})}}const G=y((t,e)=>t.from<e.to&&e.from<t.to,"segmentsOverlap"),D=y((t,e,n,o)=>{const r=!o.segments.some(n=>(n.edgeIndex!==e.edgeIndex||n.segmentIndex!==e.segmentIndex)&&G(n,t)),s=!n.segments.some(n=>(n.edgeIndex!==t.edgeIndex||n.segmentIndex!==t.segmentIndex)&&G(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"),H=y(t=>{const e=t.tracks.length;return t.tracks[e]={index:e,coord:t.coord,segments:[]},e},"createNewTrack"),j=y((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"),_=y((t,e)=>{const n=M[t.edgeIndex];for(const o of n){const n=b[o];n.pipe===t.pipe&&j(n,e)}},"moveSegmentChainToTrack"),V=y(t=>{const e=M[t.edgeIndex],n=e.indexOf(b.indexOf(t)),o=[];return n>0&&o.push(b[e[n-1]]),n<e.length-1&&o.push(b[e[n+1]]),o},"getAdjacentSegmentsAlongEdge"),W=y((t,e)=>{if(t.orientation===e.orientation)return!1;const n="horizontal"===t.orientation?t:e,o="horizontal"===t.orientation?e:t;return o.pipe.coord>n.from&&o.pipe.coord<n.to&&n.pipe.coord>o.from&&n.pipe.coord<o.to},"haveAnyCrossing"),J=y((t,e)=>{for(const n of t.tracks){if(!n.segments.some(t=>(t.edgeIndex!==e.edgeIndex||t.segmentIndex!==e.segmentIndex)&&G(t,e)))return n.index}return-1},"findAvailableTrack"),q=y((t,e)=>{if(t.trackIndex===e.trackIndex)return G(t,e);const n=V(t),o=V(e);return n.some(t=>o.some(e=>W(t,e)))},"segmentsConflict"),K=y((t,e,n)=>{if(D(t,e,t.pipe.tracks[t.trackIndex],e.pipe.tracks[e.trackIndex]))return;const o=J(t.pipe,e);n(e,-1!==o?o:H(t.pipe))},"resolveTrackConflict"),Q=y(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&&(q(r,s)&&(e++,K(r,s,_)))}return e},"resolveHandleConflicts"),Z=new Map,U=y(t=>{if(Z.has(t))return Z.get(t);const e=M[t];if(0===e.length){const e={dest:0,deviation:0,base:0,delta:0};return Z.set(t,e),e}const n=b[e[0]].pipe.coord;let o=n;for(let s=1;s<e.length;s++){const t=b[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 Z.set(t,r),r},"getDestInfo"),tt=y(()=>{let t=0;const e=new Map;for(const[o,r]of c.entries())0!==M[o].length&&r.start&&(e.has(r.start)||e.set(r.start,[]),e.get(r.start).push(o));const n=y(t=>{const e=c[t];if(!e.start||!e.end)return 0;const n=f.get(e.start),o=f.get(e.end);if(!n||!o)return 0;const r=(o.x??0)-(n.x??0),s=(o.y??0)-(n.y??0);return Math.abs(r)+Math.abs(s)},"getEdgeDistance");for(const o of e.values()){o.sort((t,e)=>{const o=U(t),r=U(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=M[t].length,c=M[e].length;if(a!==c)return a-c;if(1===a){const n=M[t][0],o=M[e][0];if(b[n]&&b[o]){const t=b[n],e=b[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=>b[M[t][0]]);t+=Q(e)}return t},"fixSourceHandleCrossings"),et=y(()=>{let t=0;const e=new Map;for(const[n,o]of c.entries()){0!==M[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=y(t=>{const e=M[t];if(e.length<2)return 0;const n=b[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=>b[M[t][M[t].length-1]]);t+=Q(e)}return t},"fixTargetHandleCrossings"),nt=y(()=>{let t=0;for(const e of d){const n=[];for(const t of e.tracks)for(const e of t.segments){const t=M[e.edgeIndex].find(t=>b[t].segmentIndex===e.segmentIndex);void 0!==t&&n.push(b[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];q(r,s)&&(t++,K(r,s,j))}}return t},"fixPipeCrossings");let ot=0;for(;ot<10;){let t=0;if(t+=tt(),t+=et(),t+=nt(),0===t)break;ot++}const rt=new Map;for(const it of d){const t=[];it.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=U(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=y((t,e)=>{n.filter(e=>e.trackIndex===t).forEach(t=>{const n=I.has(t.edgeIndex)?it.coord:e;rt.set(`${t.edgeIndex}-${t.segmentIndex}`,n)})},"assignCoord");let a=0;for(const n of o)a++,i(n,it.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,it.coord);else{const t=c%2==1?1:-1,e=Math.ceil(c/2);i(n,it.coord+t*e*10*.5)}c++}let f=0;for(const n of r)f++,i(n,it.coord+10*f)}}for(const[y,it]of c.entries()){const t=M[y]??[];if(0===t.length)continue;const e=[],n=f.get(it.start),o=f.get(it.end),{pSrcPort:r,pDstPort:s}=A(y,n,o),i=t.map(t=>{const e=b[t],n=rt.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 f=0;f<i.length;f++){const t=i[f],n=e[e.length-1],o="vertical"===t.orient?n.y:n.x,r="vertical"===t.orient?n.x:n.y,s=i[f+1],a=f<i.length-1;if(Math.abs(r-t.coord)>Zn&&e.push(ro(t,o)),a&&s.orient===t.orient)if(Math.abs(t.coord-s.coord)>Zn){const n="vertical"===t.orient?(o+s.from)/2:oo(t,s);e.push(ro(t,n),ro(s,n))}else 0!==f&&f!==i.length-2||e.push(ro(t,oo(t,s)));else if(a)e.push(ro(t,s.coord));else{const n=Math.abs(t.from-o)<Math.abs(t.to-o)?t.to:t.from;e.push(ro(t,n))}}const a=e[e.length-1];(Math.abs(a.x-s.x)>Zn||Math.abs(a.y-s.y)>Zn)&&e.push(s);const c=[];e.length>0&&c.push(e[0]);for(let f=1;f<e.length;f++){const t=e[f],n=c[c.length-1];(Math.abs(t.x-n.x)>Zn||Math.abs(t.y-n.y)>Zn)&&c.push(t)}it.points=c}for(const y of c){const t=y.__originalEdge;t&&y.points&&(t.points=y.points)}t.edges=(t.edges??[]).filter(t=>!t.isLayoutOnly);const st=y((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 l=t.x-i,d=a-t.x,u=t.y-c,h=f-t.y,g=Math.min(l,d,u,h);return g===l?{x:i,y:t.y}:g===d?{x:a,y:t.y}:g===u?{x:t.x,y:c}:{x:t.x,y:f}},"nodeBoundaryClamp");for(const y of t.edges){const t=y.points;if(!t||t.length<2)continue;const e=y.start,n=y.end,o=e?f.get(e):void 0,r=n?f.get(n):void 0;o&&(t[0]=st(t[0],o)),r&&(t[t.length-1]=st(t[t.length-1],r))}return t}function io(t){return t.direction??"TB"}function ao(t){var e,n,o,r,s;const i=_(t),a=(null==(e=t.config.flowchart)?void 0:e.nodeSpacing)??40,c=(null==(n=t.config.flowchart)?void 0:n.rankSpacing)??100,f=(null==(o=t.config.swimlane)?void 0:o.ignoreCrossLaneEdges)??!0,l=(null==(r=t.config.swimlane)?void 0:r.optimizeRanksByCrossings)??!0,d=(null==(s=t.config.swimlane)?void 0:s.automaticLaneOrdering)??!1,u=io(t),{ordered:h,coordinates:g}=Qn(i,{nodeGap:a,layerGap:c,ignoreCrossLaneEdges:f,optimizeRanksByCrossings:l,automaticLaneOrdering:d,direction:u});V(i,h,g,{nodeGap:a,layerGap:c});for(const p of t.edges??[])delete p.points;so(t,u);for(const p of t.edges??[])p.curve&&"basis"!==p.curve||(p.curve="rounded");return Ae(t,u),Pe(t),u}async function co(t,i){const a=i.select("g");n(a,t.markers,t.type,t.diagramId),o(),r(),s(),e(),j(t);const c=W(t);t.nodes=c.nodes,t.edges=c.edges;const{groups:f}=await I(a,t);ao(t),await P(t,f)}y(no,"chooseOrthogonalSide"),y(oo,"sharedLineEndpointCoord"),y(ro,"pointOnLine"),y(so,"routeEdgesOrthogonal"),y(io,"getSwimlaneDirection"),y(ao,"runSwimlaneLayoutCore"),y(co,"render");export{co as render};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./sizeCapture-X5ZJPWSS-BfOA5cbO.js","./mermaid.core-DQSlETG7.js","./index-AdB8XHXv.js","./index-D5K63qug.css"])))=>i.map(i=>d[i]);
2
+ import{_ as t}from"./index-AdB8XHXv.js";import{c as e}from"./chunk-RYQCIY6F-o8VHYTB2.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 l,as as d,au as u,z as h,ar as g,av as p,y as x,aw as m,_ as y,ax as b}from"./mermaid.core-DQSlETG7.js";import{G as M}from"./graph-DaY0Al7L.js";import"./map-CKQHuyK8.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"),l=i.insert("g").attr("class","edges edgePath"),d=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=>{var e;if(t.isGroup)o.setNode(t.id,{...t});else{if(g){const n=await c(u,t,{config:s,dir:t.dir}),o=(null==(e=n.node())?void 0:e.getBBox())??{width:0,height:0};h.set(t.id,n),t.width=o.width,t.height=o.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-BfOA5cbO.js");return{captureNodeSizes:t}},__vite__mapDeps([0,1,2,3]),import.meta.url);o(e,n)}return{graph:o,groups:{clusters:f,edgePaths:l,edgeLabels:d,nodes:u,rootGroups:i},nodeElements:h}}y(I,"createGraphWithElements");var v=1e-5,S=1e-6;function w(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,l=n.y-t.y,d=(f*a-l*i)/c,u=(f*s-l*r)/c;return d<=S||d>=.999999||u<=S||u>=.999999?null:{point:{x:t.x+d*r,y:t.y+d*s},tA:d,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=w(o.points);for(let s=n+1;s<t.length;s++){const n=t[s],i=w(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 $(t){return`${T(t.x)},${T(t.y)}`}function O(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}y(w,"buildSegmentList"),y(L,"segmentIntersection"),y(C,"isHorizontalSeg"),y(k,"findEdgeIntersections"),y(T,"fmt"),y($,"pointToString"),y(O,"getArcSweepFlag");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${$(a)}`];return"arc"===r?f.push(`A${T(t.r)},${T(t.r)} 0 0 ${o} ${$(c)}`):f.push(`M${$(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<v||f<v)return null;const l=r/c,d=s/c,u=i/f,h=a/f,g=l*u+d*h,p=Math.max(-1,Math.min(1,g)),x=Math.acos(p);if(x<v||Math.abs(Math.PI-x)<v)return null;const m=Math.min(o/Math.sin(x/2),c/2,f/2);return{startX:e.x-l*m,startY:e.y-d*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=w(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${$(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,l=0===e?0:(t.b.y-t.a.y)/e,d=O(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,l,d,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${$(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=null==e?void 0:e.curve;if(void 0!==o&&!Y(o))continue;const s=i.get(f.id);if(!s)continue;if(void 0===o){if(!F(s.getAttribute("d")??""))continue}const a=s.getAttribute("style")??"",l=/stroke-dasharray\s*:\s*0\s+([\d.]+)\s+[\d.]+\s+([\d.]+)/.exec(a),d=l?Number.parseFloat(l[1]):null,u=l?Number.parseFloat(l[2]):null,h=E(f,t,n);if(s.setAttribute("d",h),null!==d&&null!==u&&"function"==typeof s.getTotalLength){const t=s.getTotalLength(),e=`0 ${d} ${Math.max(0,t-d-u)} ${u}`,n=a.replace(/stroke-dasharray\s*:[^;]*;?/g,`stroke-dasharray: ${e};`).replace(/;\s*;+/g,";");s.setAttribute("style",n)}}}async function P(t,e){var n,o;for(const i of t.nodes)i.isGroup?await f(e.clusters,i):l(i);const r=new Map;for(const i of t.nodes)(null==i?void 0:i.id)&&r.set(i.id,i);for(const i of t.edges){const n=i.start?r.get(i.start)??{}:{},o=i.end?r.get(i.end)??{}:{},s=d(e.edgePaths,{...i},{},t.type,n,o,t.diagramId);i.label&&await u(e.rootGroups,i),i.label&&A(i,s)}const s=null==(o=null==(n=t.config)?void 0:n.swimlane)?void 0:o.lineHops;if(!1!==s){const n="gap"===s?"gap":"arc",o=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,o,{enabled:!0,jumpRadius:6,jumpStyle:n})}}function A(t,e){const n=(null==e?void 0:e.updatedPath)??(null==e?void 0:e.originalPath),o=h(),{subGraphTitleTotalMargin:r}=g({flowchart:o.flowchart??{}});if(t.label){const o=p.get(t.id);let s=t.x,a=t.y;if(n){const o=x.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(null==t?void 0:t.startLabelLeft){const e=m.get(t.id).startLeft;let o=null==t?void 0:t.x,r=null==t?void 0:t.y;if(n){const e=x.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=m.get(t.id).startRight;let o=t.x,r=t.y;if(n){const e=x.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=m.get(t.id).endLeft;let o=t.x,r=t.y;if(n){const e=x.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=m.get(t.id).endRight;let o=t.x,r=t.y;if(n){const e=x.calcTerminalLabelPosition(t.arrowTypeEnd?10:0,"end_right",n);o=e.x,r=e.y}e.attr("transform",`translate(${o}, ${r})`)}}y(R,"applyMarkerOffsets"),y(N,"emitJump"),y(B,"computeRoundedCorner"),y(E,"rewriteEdgePath"),y(F,"isStraightPath"),y(Y,"curveSupportsLineHops"),y(X,"decodeDataPoints"),y(z,"applyLineJumpsToSvg"),y(P,"adjustLayout"),y(A,"positionEdgeLabel");var G="__swimlane_default__";function D(t){return Math.max(t.padding??20,20)}function H(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 j(t){const e=t.direction,n=t.nodes??(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=(null==o?void 0:o.layerGap)??100,a=(null==o?void 0: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??[],l=new Map,d=[];for(const u of f){if(!(null==u?void 0:u.isGroup))continue;u.parentId||d.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,d=(r+s)/2;u.x=f,u.y=d,u.width=a,u.height=c,l.set(u.id,{minX:e,maxX:o,minY:r,maxY:s})}}if(d.length>0&&l.size>0){let t=1/0,e=-1/0,n=0;for(const o of d){const r=o.padding??20;r>n&&(n=r);const s=l.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 d)e.y=s,e.height=r,e.swimlaneContentTop=t;const i=[...d].sort((t,e)=>(t.x??0)-(e.x??0)),a=[],c=[],f=[];for(const t of i){const e=l.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 d){const n=t.get(e.id);null!=n&&(e.width=n),H(e)}}}}}y(D,"topLaneHorizontalPadding"),y(H,"assignTopLaneTitleRect"),y(j,"prepareLayoutForSwimlanes"),y(_,"toGraphView"),y(V,"writeBackToLayoutData");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 l={id:`${a.id}-to-label`,start:a.start,end:s,type:"normal",isLayoutOnly:!0},d={id:`${a.id}-from-label`,start:s,end:a.end,type:"normal",isLayoutOnly:!0};n.push(l,d)}const r=[...t.nodes,...e],s=[...t.edges,...n];return{...t,nodes:r,edges:s}}y(W,"createEdgeLabelNodes");var J=.001;function q(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=q(t);if(!e)return;return{id:String(t.id??""),cx:e.cx,cy:e.cy,rect:e.rect}}function Q(t,e,n=J){return Math.abs(t.x-e.x)<n&&Math.abs(t.y-e.y)<n}function Z(t,e,n=J){return Math.abs(t.x-e.x)<n}function U(t,e,n=J){return Math.abs(t.y-e.y)<n}function tt(t,e,n=J){return U(t,e,n)&&Math.abs(t.x-e.x)>n}function et(t,e,n=J){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=J){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=J){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=J){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=J){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=J){if(!t||4!==t.length)return;const[n,o,r,s]=t;if(tt(n,o,e)&&et(o,r,e)&&tt(r,s,e))return{kind:"HVH",p0:n,p1:o,p2:r,p3:s};return 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 lt(t,e){return t.left<=e.left&&t.right>=e.right&&t.top<=e.top&&t.bottom>=e.bottom}function dt(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){var e;return null==(e=q(t))?void 0:e.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=J){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=J){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 vt(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 St(t,e,n,o,r=J,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 l=i?{a:t,b:e}:{a:n,b:o},d=a?{a:t,b:e}:{a:n,b:o},u=l.a.y,h=Math.min(l.a.x,l.b.x),g=Math.max(l.a.x,l.b.x),p=d.a.x,x=Math.min(d.a.y,d.b.y),m=Math.max(d.a.y,d.b.y);if(p<h||p>g||u<x||u>m)return!1;const y=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,b=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;return!(y&&b)}function wt(t,e,n,o,r=J){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=J,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))&&(St(t,e,i,a,r)||wt(t,e,i,a,r)))return!0}}return!1}function Ct(t,e,n,o,r=J){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},l=s?{a:n,b:o}:{a:t,b:e},d=f.a.y,u=Math.min(f.a.x,f.b.x),h=Math.max(f.a.x,f.b.x),g=l.a.x,p=Math.min(l.a.y,l.b.y),x=Math.max(l.a.y,l.b.y);return g>u+r&&g<h-r&&d>p+r&&d<x-r}function kt(t,e,n){const o=Math.min(e,n),r=Math.max(e,n);return t>o+J&&t<r-J}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 $t(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 Ot(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=$t(e);if(e=t.points,!t.changed)break}return e}y(q,"measuredNodeRect"),y(K,"nodeBoundsInfoFor"),y(Q,"samePoint"),y(Z,"sameX"),y(U,"sameY"),y(tt,"isHorizontalSegment"),y(et,"isVerticalSegment"),y(nt,"overlapLength"),y(ot,"sameAxisSegmentOverlapLength"),y(rt,"orthogonalSegmentsForPoints"),y(st,"countOrthogonalBends"),y(it,"dedupeConsecutivePoints"),y(at,"classifyThreeSegmentRoute"),y(ct,"segmentBoundsOverlapRect"),y(ft,"pointInsideRect"),y(lt,"rectContainsRect"),y(dt,"rectsOverlap"),y(ut,"inflateRect"),y(ht,"rectFromCenterSize"),y(gt,"rectOfNodeBounds"),y(pt,"portForRectSide"),y(xt,"buildOrthogonalPortPath"),y(mt,"buildSameSideTrackPath"),y(yt,"collectRealNodeBounds"),y(bt,"collectNodeRectEntries"),y(Mt,"collectLayoutNodeRects"),y(It,"getNodePairGeometry"),y(vt,"segmentHitsAnyRect"),y(St,"orthogonalSegmentsCross"),y(wt,"sameAxisSegmentsOverlap"),y(Lt,"segmentConflictsWithAnyEdge"),y(Ct,"orthogonalSegmentsStrictlyCross"),y(kt,"strictlyBetween"),y(Tt,"isCollinearIntermediate"),y($t,"simplifyPolylineOnce"),y(Ot,"orthogonalizePolyline"),y(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(Ot(o)),o=Wt(o,t.srcRect,t.dstRect),t.edge.points=Rt(Ot(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 Ht(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 jt(t){return"left"===t||"right"===t}function _t(t,e,n,o,r){const s=[],i=n?Ht(t,e,n):void 0,a=o?Ht(e,t,o):void 0;return n&&i&&jt(i)===r&&s.push(Dt(n,i)),o&&a&&jt(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 Jt(t,e,n){return jt(n)?{x:t.x,y:At(t.y,e.top,e.bottom)}:{x:At(t.x,e.left,e.right),y:t.y}}function qt(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=Ht(s,i,e);if(!a)return t;const c=jt(a),f=Jt(s,e,a);return Q(s,f,Nt)?t:qt(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(!(null==t?void 0: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(!(null==t?void 0: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=y(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 le(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 l=c/r.length,d=f/r.length,u=d>0?Math.max(1,l/d):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,v=(y+b)/2-M/2-a,S=v+I/2,w=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(0===L)e=t.contentTop-w;else{e=(m[L-1].contentBottom+t.contentTop)/2}if(L===m.length-1)n=t.contentBottom+w;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=S,t.lane.y=r,t.lane.width=I,t.lane.height=o,t.lane.swimlaneContentTop=t.contentTop,t.lane.groupTitleRect={left:v,right:v+a,top:e,bottom:n}}return"RL"===e&&ce(t,"x"),!0}y(Bt,"endpointContextFor"),y(Et,"segmentEnterPoint"),y(Ft,"clipEndpoint"),y(Yt,"clipEdgeEndpointsToNodeBoundaries"),y(Xt,"snapEndpointToBoundary"),y(zt,"firstDistinctAdjacent"),y(Pt,"cornerClearanceRange"),y(At,"clampToCornerClearance"),y(Gt,"intersectRanges"),y(Dt,"clearanceRangeForSide"),y(Ht,"terminalSideForSegment"),y(jt,"isHorizontalSide"),y(_t,"straightClearanceRange"),y(Vt,"clearStraightEndpointCornerAxis"),y(Wt,"clearStraightEndpointCornerConnections"),y(Jt,"cornerClearedEndpoint"),y(qt,"moveCollinearEndpointRun"),y(Kt,"clearEndpointCornerConnection"),y(Qt,"borderSideForSegment"),y(Zt,"leavesOutward"),y(Ut,"collapseOwnBorderStub"),y(te,"snapAndCollapseEndpoints"),y(ee,"prepareEdgeEndpointsForRenderer"),y(ne,"buildNodeMap"),y(oe,"resolveTopLevelGroupId"),y(re,"groupDepth"),y(se,"boundsForChildren"),y(ie,"applyGroupBounds"),y(ae,"recomputeNestedGroupBounds"),y(ce,"mirrorAxis"),y(fe,"applyBtDirectionTransform"),y(le,"applyLrDirectionTransform");var de=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,de),de);if(!s)continue;const{p3:i}=s,a="HVH"===s.kind,c=It(r,n,de);if(!c)continue;const{srcId:f,dstId:l,srcInfo:d,dstInfo:u,collinearX:h,collinearY:g}=c;if(h||g)continue;let p;const x=d.rect;for(const n of ue){let e,s,c;if(a){const t=u.cy>d.cy?x.bottom:x.top,o=d.cx+n;if(o<=x.left+de||o>=x.right-de)continue;e={x:o,y:t},s={x:o,y:i.y},c={x:i.x,y:i.y}}else{const t=u.cx>d.cx?x.right:x.left,o=d.cy+n;if(o<=x.top+de||o>=x.bottom-de)continue;e={x:t,y:o},s={x:i.x,y:o},c={x:i.x,y:i.y}}const h=Q(e,s,de),g=Q(s,c,de);if(h&&g)continue;if(!h&&vt(e,s,o,[f],1))continue;if(!g&&vt(s,c,o,[l],1))continue;const m=!h&&Lt(e,s,t,r,{epsilon:de,skipDegenerateOther:!0}),y=!g&&Lt(s,c,t,r,{epsilon:de,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],l=a[c-1],d=a[c-2],u=f.x-l.x,h=f.y-l.y,g=Math.hypot(u,h);if(g>=10||g<n)continue;const p=l.x-d.x,x=l.y-d.y;if(Math.hypot(p,x)<n)continue;const m=tt(l,f,n),b=et(l,f,n),M=tt(d,l,n),I=et(d,l,n);if(!(m&&I||b&&M))continue;const v=s.end,S=s.start,w=v?e.get(v):void 0;if(!w)continue;const L=w.x??0,C=w.y??0,k=gt(w);if(!k)continue;let T,$;if(I){const t=x<0;T={x:L,y:d.y},$={x:L,y:t?k.bottom:k.top}}else{const t=p>0;T={x:d.x,y:C},$={x:t?k.right:k.left,y:C}}if(vt(T,$,o,v?[v]:[],-2))continue;if(vt(T,$,r,[],-2))continue;if(S){const t=e.get(S),n=t?gt(t):void 0;if(n&&ft(T,n,2))continue}const O=y((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(O(a[t],a[t+1]));const N=y((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(O(s,i))&&Ct(e,o,s,i,n))return!0}}return!1},"segmentCrossesOtherEdge");if(N(T,$))continue;if(c-3>=0){const t=a[c-3];if(vt(t,T,o,[S,v].filter(t=>Boolean(t)),-2))continue;if(N(t,T))continue}const B=[...a.slice(0,c-2),T,$];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),l=U(a,c,n),d=Z(a,c,n);(l&&f>=e+2||d&&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)}}}}}y(he,"portSwapToLShape"),y(ge,"collapseShortTerminalStub");var pe=.001,xe=rt,me=y((t,e)=>Z(t,e,pe)||U(t,e,pe),"orthogonallyAligned");function ye(t,e){const n=y((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=y((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],l=n(i,c);let d=c;return me(f,l)&&(d=f),Z(l,d,pe)?{edge:t,edgeId:String(t.id??""),nodeId:s,atStart:o,orientation:"V",coord:l.x,min:Math.min(l.y,d.y),max:Math.max(l.y,d.y),boundary:l,railEnd:d,rect:a}:U(l,d,pe)?{edge:t,edgeId:String(t.id??""),nodeId:s,atStart:o,orientation:"H",coord:l.y,min:Math.min(l.x,d.x),max:Math.max(l.x,d.x),boundary:l,railEnd:d,rect:a}:void 0},"terminalLaneFor"),r=y((t,e)=>Math.max(0,Math.min(t.max,e.max)-Math.max(t.min,e.min)),"projectedOverlapLength"),s=y((t,e)=>{if(t.nodeId!==e.nodeId||t.orientation!==e.orientation)return!1;if("H"===t.orientation){return(Math.abs(t.boundary.x-t.rect.left)<1||Math.abs(t.boundary.x-t.rect.right)<1)&&Z(t.boundary,e.boundary,1)}return(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=y((t,e)=>{if(t.nodeId!==e.nodeId||t.orientation!==e.orientation)return!1;return r(t,e)>=8&&Math.abs(t.coord-e.coord)<.5},"exactTerminalLaneConflict"),a=y((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=y((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(!y(()=>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=y(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,l=a.x??0,d=a.y??0,[u,h]=o;return U(u,h,pe)&&Math.abs(f-d)<1&&Math.abs(c-l)>1||Z(u,h,pe)&&Math.abs(c-l)<1&&Math.abs(f-d)>1},"laneIsStraightCollinearConnector"),l=[-7,7,-14,14,-21,21];for(let d=0;d<8;d++){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],d=e[r];if(s.edge===d.edge||!i(s,d)&&!a(s,d))continue;const u=!i(s,d),h=[s,d].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 l){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=y((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(vt(t.a,t.b,n,c,-2))return!1;if(vt(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=y((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],l=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,d=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 l||d?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=y((t,e,n)=>it(t===e?n??[]:t.points??[]),"pointsFor"),i=y((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=y(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=y((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;if(e.horizontal){return nt(e.a.x,e.b.x,n.left,n.right)>=8&&e.a.y>=n.top-2&&e.a.y<=n.bottom+2}return 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=y((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"),l=y((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(vt(r.a,r.b,n,c,-2))return!1;if(vt(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 d=0;d<8;d++){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 d=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 d){const i=f(o,r.segment,s);if(i&&l(n,i,t)){n.points=i,e=!0;break}}if(e)break}if(!e)return}}function Ie(t,e){const n=y(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=y(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=y((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 ve(t,e){const n=y(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=y(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=y((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=y((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 Se(t,e){const{realNodeRects:n}=bt(e.values()),o=t.filter(t=>!t.isLayoutOnly),r=y((t,e=new Map)=>it(e.get(t)??t.points??[]),"replacementPointsFor"),s=y((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=y((t=new Map)=>o.reduce((e,n)=>e+st(r(n,t)),0),"totalBends"),a=y(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=y((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=y((t,e)=>{const o=[t.start,t.end].filter(t=>Boolean(t));for(const r of xe(e))if(vt(r.a,r.b,n,o,-2))return!0;return!1},"pathHasNodeHit"),l=y((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"),d=y((t,e,n)=>!f(t,e)&&!l(t,e,n),"candidateIsSafe"),u=y(()=>{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 l=f+1;l<r.length;l++){const u=r[f],h=r[l],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(!d(u,x,y)||!d(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 we(t,e){const{realNodeRects:n,labelNodeRects:o}=bt(e.values()),r=t.filter(t=>!t.isLayoutOnly),s=y((t,e=new Map)=>it(e.get(t)??t.points??[]),"replacementPointsFor"),i=y((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=y((t=new Map)=>r.reduce((e,n)=>e+st(s(n,t)),0),"totalBends"),c=y(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=y((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"),l=y(()=>{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"),d=y((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=y(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)&&d(e,o)&&(n.add(o),r.push(o))}s.length>1&&e.push(s)}return e},"connectedComponents"),h=y(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"),g=y(t=>{const e=t.map(t=>t.coord),n=h(t),o=[];if(t.length<=6){const r=new Array(n.length).fill(!1),s=[],i=y(()=>{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"),p=y((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"),x=y(t=>{for(const[e,r]of t){const t=[e.start,e.end].filter(t=>Boolean(t));for(const e of xe(r)){if(vt(e.a,e.b,n,t,-2))return!1;if(vt(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 m=0;m<4;m++){const t=i();if(0===t)return;let e,n=t,o=a(),r=Number.POSITIVE_INFINITY;for(const s of u(l()))for(const c of g(s)){const f=p(s,c);if(!f||!x(f))continue;const l=i(f);if(l>=t)continue;const d=a(f),u=s.reduce((t,e,n)=>t+Math.abs(c[n]-e.coord),0);l>n||l===n&&(d>o||d===o&&u>=r)||(e=f,n=l,o=d,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=y((t,e,n)=>it(t===e?n??[]:t.points??[]),"pointsFor"),i=y(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=y((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=y((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=y(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"),l=y((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)]),l=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!l.has(e)&&(l.add(e),!0)})},"shortcutCandidatesAt"),d=y((t,e,i)=>{const l=[t.start,t.end].filter(t=>Boolean(t)),d=f(t);for(const r of xe(e)){if(vt(r.a,r.b,n,l,-2))return!1;if(vt(r.a,r.b,o,[],-2))return!1;if(d.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 l(r,s)){const r=st(p,pe),s=i(p);if(!(r<h||r===h&&s<g-pe)||!d(u,p,t))continue;const l=a(u,p);l>o||l===o&&(r>c||r===c&&s>=f)||(e=u,n=p,o=l,c=r,f=s)}}if(!e||!n)return;e.points=n}}function Ce(t,e){const n=20,o=[];for(const y of e.values()){if(y.isGroup||y.isEdgeLabel)continue;const t=y.x??0,e=y.y??0,n=gt(y);n&&o.push({id:String(y.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])),l=y(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"),d=y((t,e=new Map)=>it(e.get(t)??t.points??[]),"replacementPointsFor"),u=y((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"),h=y((t,e)=>u(xe(t),xe(e)),"crossingCountBetweenPaths"),g=y((t=new Map)=>{let e=0;const n=[],o=new Set,r=[],s=y(t=>{o.has(t)||(o.add(t),r.push(t))},"addEdge");for(let i=0;i<c.length;i++){const o=c[i],r=d(o,t);for(let a=i+1;a<c.length;a++){const i=c[a],f=h(r,d(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"),p=y((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=d(t,e);for(let a=s+1;a<c.length;a++){const t=c[a];(o||n.has(t))&&(r+=h(i,d(t,e)))}}return t.count-o+r},"crossingCountWithReplacements"),x=y(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"),m=y(t=>[t.start,t.end].filter(t=>Boolean(t)),"endpointIdsFor"),b=y(t=>{const e=[];for(const n of x(t)){const t=new Set(n),o=new Set(n.flatMap(t=>m(t))),r=[...n];for(const e of c)t.has(e)||m(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=y((t,e,n)=>p(t,new Map([[e,n]])),"crossingCountWithSingleReplacement"),I=y(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"),v=y(t=>t.slice(1).reduce((e,n,o)=>{const r=t[o];return e+Math.abs(n.x-r.x)+Math.abs(n.y-r.y)},0),"pathLength"),S=y((t=new Map)=>c.reduce((e,n)=>e+st(d(n,t)),0),"totalBends"),w=y((t=new Map)=>c.reduce((e,n)=>e+v(d(n,t)),0),"totalLength"),L=y((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(d(r,n)))if(ot(t,e,.5)>=8)return!0;return!1},"pathHasSegmentConflict"),C=y((t,e)=>{const n=[t.start,t.end].filter(t=>Boolean(t));for(const o of xe(e))if(vt(o.a,o.b,s,n,-2))return!0;return!1},"pathHitsNode"),k=y((t,e)=>{const n=Rt(it(e));xe(n).length===n.length-1&&t.push(n)},"pushOrthogonalCandidate"),T=y(t=>"left"===t||"right"===t,"sideIsHorizontal"),$=y((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"),O=y((t,e,o,r)=>{const s="left"===o||"top"===o?-1:1,i=[$(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=y((t,e,n,o,r)=>{for(const s of l(n))for(const n of l(r))k(t,[e,{x:s,y:e.y},{x:s,y:n},{x:o.x,y:n},o])},"addHorizontalToVerticalCandidates"),N=y((t,e,n,o,r)=>{for(const s of l(n))for(const n of l(r))k(t,[e,{x:e.x,y:s},{x:n,y:s},{x:n,y:o.y},o])},"addVerticalToHorizontalCandidates"),B=y((t,e,n,o,r)=>{const s=[...l("top"),...l("bottom")];for(const i of l(n))for(const n of l(r))for(const r of s)k(t,[e,{x:i,y:e.y},{x:i,y:r},{x:n,y:r},{x:n,y:o.y},o])},"addHorizontalPairCandidates"),E=y((t,e,n,o,r)=>{const s=[...l("left"),...l("right")];for(const i of l(n))for(const n of l(r))for(const r of s)k(t,[e,{x:e.x,y:i},{x:r,y:i},{x:r,y:n},{x:o.x,y:n},o])},"addVerticalPairCandidates"),F=y(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=y((t,e,o,r)=>{const s=[],i=xt(t,e,o,r,n,pe);i&&k(s,i),e===r&&O(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=y((t,e,n,o)=>{const r=[...l("left"),...l("right")],s=[...l("top"),...l("bottom")];for(const a of i){const i=pt(o,a),c="top"===a||"bottom"===a?l(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=y((t,e,n,o)=>{const r=[...l("left"),...l("right")],s=[...l("top"),...l("bottom")];for(const a of i){const i=pt(o,a),c="left"===a||"right"===a?l(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=y(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=y(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=y(()=>new Map(c.map(t=>[t,xe(d(t))])),"currentSegmentsByEdge"),D=y((t,e,n)=>{const o=new Set;for(const r of c){if(r===t)continue;const s=n.get(r)??xe(d(r));e.some(t=>s.some(e=>ot(t,e,.5)>=8))&&o.add(r)}return o},"sharedTrackConflictsFor"),H=y((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(d(e))));return{candidate:r,candidateSegments:s,crossings:e.count-(o.get(t)??0)+i,bends:st(r,pe),totalBends:st(r),length:v(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"),j=y((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(d(f));a+=u(n.segments,t)+u(r.segments,t)}return t.count-i+a},"pairCrossingCount"),_=y((t,e)=>{for(const n of t.sharedTrackConflicts)if(n!==e)return!1;return!0},"conflictsOnlyWith"),V=y((t,e)=>t.segments.some(t=>e.segments.some(e=>ot(t,e,.5)>=8)),"candidatesShareTrack"),W=y((t,e,n,o)=>_(e,n.edge)&&_(o,t.edge)&&!V(e,o),"pairCandidatesAreCompatible"),J=y((t,e,n,o,r)=>{const s=j(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"),q=y((t,e)=>t.crossings<e.crossings||t.crossings===e.crossings&&(t.bends<e.bends||t.bends===e.bends&&t.length<e.length),"pairScoreIsBetter"),K=y((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=J(t,e,s,n,o);i&&q(i,r)&&(r=i)}return r},"bestScoreForOptionPair"),Q=y(t=>{const e=S(),n=w(),o=G(),r=I(t),s=new Map(c.map(t=>[t,st(d(t))])),i=new Map(c.map(t=>[t,v(d(t))])),a=new Map,f=b(t);for(const c of f)for(const e of c){if(a.has(e))continue;const n=H(e,t,o,r);n.length>0&&a.set(e,{edge:e,candidates:n})}let l={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))&&(l=K(u,o,t,l))}}}return l.replacements.size>0?l.replacements:void 0},"bestPairedReplacement");for(let y=0;y<4;y++){const t=g(),e=t.count;if(0===e)return;let n,o,r=e,s=Number.POSITIVE_INFINITY;for(const a of t.edges){const i=st(d(a),pe);for(const c of A(a)){const f=C(a,c),l=!f&&L(a,c),d=M(t,a,c),u=st(c,pe);if(f||l)continue;(d<e||d===e&&u<i)&&(d>r||d===r&&u>=s||(n=a,o=c,r=d,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}}y(ye,"separateSharedRenderedTerminalLanes"),y(be,"collapseRedundantRectangularDoglegs"),y(Me,"liftObstacleHuggingSameSideRails"),y(Ie,"liftTopLaneTitleBandsAboveRails"),y(ve,"shiftLeftLaneTitleBandsLeftOfRails"),y(Se,"swapDestinationTerminalTailsToReduceCrossings"),y(we,"reassignCrossingExternalRailChannels"),y(Le,"shortcutRedundantOrthogonalJogs"),y(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=y((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=y((t,e)=>{for(let n=0;n<t.length-1;n++){if(vt(t[n],t[n+1],o,e,1))return!0}return!1},"pathHitsNode"),c=y((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))(St(n.a,n.b,t.a,t.b,ke,ke)||ot(n,t,ke)>=8)&&r++}return r},"pathConflictCount"),f=y((t,e)=>{const n=Math.abs(t.y-e.rect.top),o=Math.abs(t.y-e.rect.bottom),r=Math.abs(t.x-e.rect.left),s=Math.abs(t.x-e.rect.right);let i="top",a=n;return o<a&&(i="bottom",a=o),r<a&&(i="left",a=r),s<a&&(i="right",a=s),i},"nearestSideOfRect"),l=new Map,d=y((t,e,n)=>{const o=l.get(t)??[];o.push({side:e,edgeId:n}),l.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&&d(o,f(t[0],r),e)}if(r){const o=n.get(r);o&&d(r,f(t[t.length-1],o),e)}}const u=y((t,e,n)=>{var o;return(null==(o=l.get(t))?void 0:o.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=l.get(o);t&&l.set(o,t.filter(t=>t.edgeId!==x));const e=l.get(s);e&&l.set(s,e.filter(t=>t.edgeId!==x)),d(o,f(b[0],g),x),d(s,f(b[b.length-1],p),x)}}}y(Te,"simplifyDetouredEdges");var $e=.001;function Oe(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)<$e)){if(Math.abs(a)<=$e){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)<=$e){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[Oe(n,!0),Oe(n,!1)].some(e=>e&&dt(t,Re(e)))}function Be(t,e){const n=[];for(const d of t){if(d.isLayoutOnly)continue;const t=d.points;if(t&&!(t.length<2))for(let e=0;e<t.length-1;e++)n.push({edgeId:d.id,p1:t[e],p2:t[e+1]})}const o=[],r=[];for(const d of e.values()){const t=d.isGroup,e=d.parentId;if(t&&!e){const t=gt(d);t&&r.push({id:d.id,rect:t});continue}if(t)continue;if(d.isEdgeLabel)continue;const n=gt(d);n&&o.push({nodeId:d.id,rect:n})}const s=y((t,e)=>{const n=ut(e,3);for(const{nodeId:r,rect:s}of o)if(r!==t&&dt(n,s))return!0;return!1},"labelOverlapsForeignNode"),i=y((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=y((t,e,n)=>s(t,n)||i(e,n),"labelOverlapsAnything"),c=[],f=y(t=>{for(const{id:e,rect:n}of r)if(lt(n,t))return e},"findContainingLane"),l=y((t,e)=>c.some(n=>n.labelId!==t&&dt(e,n.rect)),"overlapsPlacedLabel");for(const d of t){if(d.isLayoutOnly)continue;const t=d.labelNodeId;if(!t)continue;const n=e.get(t);if(!n)continue;const o=d.points;if(!o||o.length<2)continue;const u=n.width??0,h=n.height??0;if(u<=0||h<=0)continue;const g=[];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<$e&&s<$e||(r>=$e&&s>=$e||g.push({idx:e,length:r+s,orientation:r>=$e?"horizontal":"vertical",midX:(t.x+n.x)/2,midY:(t.y+n.y)/2}))}if(0===g.length)continue;const p=g.length>=3?g.filter(t=>t.idx>0&&t.idx<g.length-1):g,x=p.length>0?p:g,m=u>=h?"horizontal":"vertical",b=y(t=>[...t].sort((t,e)=>{const n=t.orientation===m;if(n!==(e.orientation===m))return n?-1:1;const o=t.length>=("horizontal"===t.orientation?u:h)+2;return o!==e.length>=("horizontal"===e.orientation?u:h)+2?o?-1:1:e.length-t.length}),"rankSegments"),M=g[0],I=g[g.length-1],v=[.5,.25,.75,.05,.95,.15,.85,.1,.9],S=y((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"),w=y((t,e,n)=>Math.min(n,Math.max(e,t)),"clamp"),L=y((t,e)=>t.midX>=e.left-$e&&t.midX<=e.right+$e&&t.midY>=e.top-$e&&t.midY<=e.bottom+$e,"pointInsideRectInclusive"),C=y(t=>{const e=ht(t.midX,t.midY,u,h),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+h/2+1,c=o.rect.bottom-h/2-1;if(s>i||a>c)return;const l={midX:w(t.midX,s,i),midY:w(t.midY,a,c)},d=ht(l.midX,l.midY,u,h);return L(t,d)?{laneId:o.id,anchor:l,rect:d}:void 0},"placementForAnchor"),k=y((t,e,n)=>"horizontal"===t.orientation?Math.abs(e.midX-n.x):Math.abs(e.midY-n.y),"distanceAlongSegment"),T=y((t,e)=>{const n=("horizontal"===t.orientation?u/2:h/2)+12;if(t===M){const r=o[t.idx];if(k(t,e,r)+$e<n)return!1}if(t===I){const r=o[t.idx+1];if(k(t,e,r)+$e<n)return!1}return!0},"labelClearsTerminalEndpoints"),$=y(e=>{const n=b(e);for(const r of n)for(const e of v){const n=S(r,e);if(!T(r,n))continue;const s=C(n);if(s&&(!Ne(s.rect,o)&&!l(t,s.rect)&&!a(t,d.id,s.rect)))return{laneId:s.laneId,anchor:s.anchor}}},"tryPool"),O=y((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)&&!l(t,a.rect)&&!s(t,a.rect)&&(r||!i(d.id,a.rect)))return{laneId:a.laneId,anchor:a.anchor}}},"findLaneContainingFallback"),R=$(x)??(x.length<g.length?$(g):void 0)??O(g,!0)??O(g,!1)??O(g,!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,h),o=c.findIndex(e=>e.labelId===t);o>=0?c[o]={labelId:t,rect:e}:c.push({labelId:t,rect:e})}}}y(Oe,"markerClearanceRectFor"),y(Re,"normalizeRect"),y(Ne,"labelOverlapsOwnMarker"),y(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=y((e,n,o,s)=>{const i=Fe(n,o);let a=0;const c=y(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:l,collinearY:d}=e;if(l===d)continue;let u,h;if(l){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(vt(u,h,o,[r,a],1))continue;const g=s(i,r,a,l?"x":"y"),p=g>4?g:4,x=[0,p,-p];for(const n of x){const e={...u},s={...h};if(l){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(!vt(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=y((t,e)=>rt(e,n).map(n=>({...n,edge:t,interior:n.index>=1&&n.index<=e.length-3})),"segmentsFor"),i=y(()=>{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=y((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=y((e,i)=>{const c=e.start,f=e.end,l=s(e,i);if(l.length!==i.length-1)return!1;const d=[c,f].filter(t=>Boolean(t)),u=e.labelNodeId?[e.labelNodeId]:[];for(const t of l){if(vt(t.a,t.b,o,d,-2))return!1;if(vt(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 l)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=y((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"),l=y((t,e)=>({x:t.x??(e.left+e.right)/2,y:t.y??(e.top+e.bottom)/2}),"nodeCenter"),d=y(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:l(r,i),targetCenter:l(s,a),sourceRect:i,tail:c}:void 0},"sourceDetourContextFor"),u=y((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 l=t.a.x+e;return it([{x:o.x,y:c},{x:o.x,y:f},{x:l,y:f},{x:l,y:t.b.y},...i],n)},"verticalSourceDetour"),h=y((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 l=t.a.y+e;return it([{x:c,y:o.y},{x:f,y:o.y},{x:f,y:l},{x:t.b.x,y:l},...i],n)},"horizontalSourceDetour"),g=y((t,e)=>{const n=d(t);if(n)return t.vertical?u(t,e,n.sourceCenter,n.targetCenter,n.sourceRect,n.tail):t.horizontal?h(t,e,n.sourceCenter,n.targetCenter,n.sourceRect,n.tail):void 0},"sourceDetourCandidate"),p=[-7,7,-14,14,-21,21];for(let x=0;x<12;x++){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 p){const o=f(t,n);if(o&&c(t.edge,o)){t.edge.points=o,e=!0;break}const r=g(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,l=n.y-t.y,d=(f*a-l*i)/c,u=(f*s-l*r)/c,h=.01;return d>h&&d<.99&&u>h&&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&&!le(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(Ot(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),Se(o,s);const i=y(()=>{Ce(o,s),we(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),ve(o,s),Ie(o,s),ve(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 He(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 je(t){const e=He(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 Je(t,e,n,o){var r,s;let i=0;for(const c of t.nodes)(null==o?void 0:o.skipGroups)&&(null==(r=t.nodeById.get(c))?void 0:r.isGroup)||(i=Math.max(i,n[c]??0));const a=Array.from({length:i+1},()=>[]);for(const c of e)(null==o?void 0:o.skipGroups)&&(null==(s=t.nodeById.get(c))?void 0:s.isGroup)||a[Math.max(0,n[c]??0)].push(c);return a}function qe(t){const e=_e(t),n=Ve(e),o=[],r=je(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=y((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=y(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=y(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}y(Fe,"pairKey"),y(Ye,"straightenCollinearSiblingDetours"),y(Xe,"nudgeSharedInteriorSubpaths"),y(ze,"segmentsIntersect"),y(Pe,"validateSwimlanesLayout"),y(Ae,"postProcessSwimlaneLayout"),y(Ge,"normalizeGraph"),y(De,"incoming"),y(He,"buildSuccessorMap"),y(je,"buildSortedSuccessorMap"),y(_e,"buildInDegreeMap"),y(Ve,"sortedZeroInDegreeNodes"),y(We,"buildPredecessorSuccessorMaps"),y(Je,"buildLayersFromRanks"),y(qe,"topoSortIfAcyclic"),y(Ke,"buildLayerIndex"),y(Qe,"countInversions"),y(Ze,"removeCycles_DFS"),y(Ue,"buildTopLaneMap"),y(tn,"createTopLaneResolver"),y(en,"buildTopLaneOrder"),y(nn,"resolveTopLaneOrder");var on=8,rn=4,sn=!0,an=100,cn=40;function fn(t,e){const n=Ge(t),o=(null==e?void 0:e.laneOf)??(()=>null),r=null==e?void 0:e.rankHint,{preds:s}=We(n);for(const y of s.values())y.sort((t,e)=>t.localeCompare(e));const i=qe(n)??[...n.nodes].sort((t,e)=>t.localeCompare(e)),a=new Map;for(const[y,v]of i.entries())a.set(v,y);const c=new Map,f=new Map;for(const y of n.nodes)f.set(y,[]);for(const y of i){const t=(s.get(y)??[]).filter(t=>c.has(t));if(t.length>0){const e=ln(y,t,{laneOf:o,rankHint:r,topoIndex:a});c.set(y,e),f.get(e).push(y)}else c.has(y)||c.set(y,null)}for(const y of n.nodes)c.has(y)||c.set(y,null);const l=new Set;for(const y of n.nodes)null===(c.get(y)??null)&&l.add(y);const d=[...l].sort((t,e)=>{const n=a.get(t)??0,o=a.get(e)??0;return n===o?t.localeCompare(e):n-o}),u=dn(n),h=new Map;for(const[y,v]of u.entries())h.set(y,[...v].sort((t,e)=>t.localeCompare(e)));const g=un(h),p=hn(h),x=new Map;for(const y of n.nodes)x.set(y,[]);for(const y of p)for(const t of y.nodes){const e=x.get(t);e?e.push(y.id):x.set(t,[y.id])}const m=[],b=[],M=new Set,I=y(t=>{if(!M.has(t)){M.add(t),m.push(t);for(const e of f.get(t)??[])I(e);b.push(t)}},"walk");for(const y of d)I(y);for(const y of i)I(y);return{parent:c,children:f,roots:d,componentOf:g,blocks:p,nodeBlocks:x,adjacency:h,preorder:m,postorder:b,topologicalOrder:i}}function ln(t,e,n){const o=n.laneOf(t);return[...e].sort((t,e)=>{var r,s;const i=n.laneOf(t),a=n.laneOf(e),c=null!=i&&i===o;if(c!==(null!=a&&a===o))return c?-1:1;const f=null==(r=n.rankHint)?void 0:r[t],l=null==(s=n.rankHint)?void 0:s[e];if(null!=f&&null!=l&&f!==l)return l-f;const d=n.topoIndex.get(t)??0,u=n.topoIndex.get(e)??0;return d!==u?d-u:t.localeCompare(e)})[0]}function dn(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 un(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 hn(t){const e=new Map,n=new Map,o=[],r=[];let s=0;const i=y((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(gn(a,f,o,r.length))))},"visit");for(const a of t.keys())e.has(a)||i(a,null);return r}function gn(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 pn(t,e,n){const o=[...t.nodes],r=new Map;for(const[y,b]of o.entries())r.set(b,y);const s=o.length,i=new Array(s).fill(-1),a=new Array(s).fill(0),c=[],f=new Set;for(const y of o){const t=n.parent.get(y)??null,e=r.get(y);null!=e&&(null==t&&(i[e]=-1,a[e]=0,f.has(y)||(f.add(y),c.push(y))))}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 y of o){if(f.has(y))continue;const t=r.get(y);null!=t&&(i[t]=-1,a[t]=0,f.add(y))}const l=Math.max(1,Math.ceil(Math.log2(Math.max(1,s)))+1),d=Array.from({length:l},()=>new Array(s).fill(-1));for(let y=0;y<s;y++)d[0][y]=i[y];for(let y=1;y<l;y++)for(let t=0;t<s;t++){const e=d[y-1][t];d[y][t]=-1===e?-1:d[y-1][e]}const u=y((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<l;o++)if(n>>o&1&&-1===(t=d[o][t]))return-1;if(t===e)return t;for(let o=l-1;o>=0;o--){const n=d[o][t],r=d[o][e];-1!==n&&-1!==r&&(n!==r&&(t=n,e=r))}return d[0][t]},"lcaIndex"),h=Array.from({length:s},()=>new Map);for(const y of t.edges){let t=y.src,n=y.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=h[c];for(let e=o;e<s;e++)f.set(e,(f.get(e)??0)+1)}const g=new Map,p=y((t,e)=>{if(0!==e.size)for(const[n,o]of e)t.set(n,(t.get(n)??0)+o)},"mergeInto"),x=new Set,m=y(t=>{const o=r.get(t);x.add(t);const s=null==o?void 0:h[o],i=s?new Map(s):new Map,a=n.children.get(t)??[];for(const n of a){const o=m(n),r=e[t];if(null!=r){let s=g.get(t);s||(s=new Map,g.set(t,s));let i=o.get(r)??0;const a=e[n];null!=a&&a>r&&(i+=1),s.set(n,i)}p(i,o)}return i},"dfs");for(const y of n.roots)x.has(y)||m(y);for(const y of o)x.has(y)||m(y);return g}function xn(t,e,n){const o=new Map,r=y(t=>{let s=n[t]??0;const i=[...e.get(t)??[]];i.sort(mn(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 mn(t){return(e,n)=>{const o=t[e]??0,r=t[n]??0;return o===r?e.localeCompare(n):o-r}}function yn(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=y(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 bn(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 Mn(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=(null==f?void 0:f.get(t))??0,r=(null==f?void 0: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 In(t,e,n){const o=fn(t,{rankHint:e,laneOf:n}),{children:r,roots:s}=o;for(const l of t.nodes)r.has(l)||r.set(l,[]);const i=pn(t,e,o),a=[...s].sort(mn(e)),c=Mn(r,e,i,xn(a,r,e));let f=yn(a,t.nodes,e,c);return f=bn(f),f}function vn(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 Sn(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+=vn(t[s],t[s+1],o);return r}function wn(t,e){const n={...e},{preds:o}=We(t),r=tn(t);let s=Sn(In(t,n,r),t.edges,n);const i=rn;for(let a=0;a<i;a++){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 l=Sn(In(t,n,r),t.edges,n);l<s?(s=l,e=!0):n[a]=f}if(!e)break}return n}function Ln(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 l=e[r]??0,d=l+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(l,u,d);h!==l&&(e[r]=h)}}function Cn(t,e){const n=Ge(t),o=qe(n)??[...n.nodes].sort(),r=(null==e?void 0:e.compactSingleInput)??!1,s=tn(n);let i=Object.create(null);for(const a of o){const t=De(n,a),o=(null==e?void 0: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}}(null==e?void 0:e.optimizeRanksByCrossings)&&(i=wn(n,i)),(null==e?void 0:e.ignoreCrossLaneEdges)&&Ln(n,i);return{layers:In(n,i,s),rankOf:i,dummy:new Set}}function kn(t,e){const n=Ge(t),o={...Cn(n,{compactSingleInput:null==e?void 0:e.compactSingleInput,ignoreCrossLaneEdges:null==e?void 0:e.ignoreCrossLaneEdges,optimizeRanksByCrossings:null==e?void 0:e.optimizeRanksByCrossings}).rankOf},r=tn(n),{preds:s,succs:i}=We(n,t=>{if(null==e?void 0:e.ignoreCrossLaneEdges){const e=r(t.src),n=r(t.dst);if(e&&n&&e!==n)return!1}return!0}),a=qe(n)??[...n.nodes],c=[...a].reverse(),f=y((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"),l=on,d=y(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,l=Math.round((a+c)/2),d=f(n,l);d!==o[n]&&(o[n]=d,e=!0)}return e},"relaxOrder");for(let u=0;u<l;u++){const t=d(a),e=d(c);if(!t&&!e)break}for(const u of a){let t=0;for(const e of s.get(u)??[])t=Math.max(t,(o[e]??0)+1);(o[u]??0)<t&&(o[u]=t)}for(const u of c){const t=i.get(u)??[];if(t.length>0){const e=Math.min(...t.map(t=>(o[t]??0)-1));(o[u]??0)>e&&(o[u]=e)}}return{layers:Je(n,a,o),rankOf:o,dummy:new Set}}function Tn(t){const e=_e(t),n=je(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 $n(t,e){const n=Ge(t),o="LR"===(null==e?void 0:e.direction)?Tn(n)??[...n.nodes].sort():qe(n)??[...n.nodes].sort(),r=tn(n),s=y(t=>r(t)??t,"laneOf"),i=Object.create(null),a=new Map,c=y((t,n)=>(null==e?void 0:e.ignoreCrossLaneEdges)??!0?s(t)===s(n)?1:0:1,"edgeWeight");for(const f of o){const t=n.nodeById.get(f);if(null==t?void 0: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),l=a.get(r)??0,d=Math.max(o,l);i[f]=d,a.set(r,d+1)}return{layers:Je(n,o,i,{skipGroups:!0}),rankOf:i,dummy:new Set}}function On(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=y(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)),l=[];for(const u of f){const t=o[u.src]??0,e=o[u.dst]??0;if(e-t<=1){l.push(u);continue}let n=u.src;for(let o=t+1,s=0;o<e;o++,s++){const t=c(o);l.push({id:`${u.id}#${s}`,src:n,dst:t,weight:u.weight,ref:u.ref}),n=t}const r=e-t-2;l.push({id:`${u.id}#${Math.max(r+1,0)}`,src:n,dst:u.dst,weight:u.weight,ref:u.ref})}const d={nodes:[...n.nodes,...[...s].filter(t=>!n.nodes.includes(t))],edges:l,layout:n.layout,nodeById:a};return{layering:{layers:r,rankOf:o,dummy:s},graphWithDummies:d}}function Rn(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 Nn(t){if(0===t.length)return Number.POSITIVE_INFINITY;return t.reduce((t,e)=>t+e,0)/t.length}function Bn(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 En(t,e,n){const o=n.get(t)??0,r=n.get(e)??0;return o!==r?o-r:t.localeCompare(e)}function Fn(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)});a.sort((t,e)=>t.u===e.u?t.v-e.v:t.u-e.u);return Qe(a.map(t=>t.v))}function Yn(t,e,n){return[...t].sort((t,o)=>{const r=Rn(e.get(t)??[]),s=Rn(e.get(o)??[]);return r===s?En(t,o,n):isFinite(r)?isFinite(s)?r-s:-1:1})}function Xn(t,e,n,o,r,s){const i=Ke(t),a=Ke(e),c=Bn(e,i,n,o);if(!r||!s||0===s.length)return Yn(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 l=[];for(const u of s){const t=f.get(u);if(!t||0===t.length)continue;const e=Yn(t,c,a);l.push(...e)}const d=f.get(null);if(d&&d.length>0){const t=Yn(d,c,a);for(const e of t){const t=Nn(c.get(e)??[]);let n=l.length;if(isFinite(t))for(const[e,o]of l.entries()){if(t<Nn(c.get(o)??[])){n=e;break}}l.splice(n,0,e)}}return l}function zn(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)),l=c?n.filter(t=>a.has(t.src)&&c.has(t.dst)):void 0,d=y(e=>{let n=Fn(t,e,f);return l&&o&&(n+=Fn(e,o,l)),n},"crossingScore"),u=r?new Map:null;if(r&&u)for(const p of e)u.set(p,r(p));let h=!0,g=d(s);for(;h;){h=!1;for(let t=0;t+1<s.length;t++){if(u){if(u.get(s[t])!==u.get(s[t+1]))continue}const e=g;[s[t],s[t+1]]=[s[t+1],s[t]];const n=d(s);n<e?(g=n,h=!0):[s[t],s[t+1]]=[s[t+1],s[t]]}}return s}function Pn(t,e,n){const o=t.layers.map(t=>[...t]),r=e.edges,s=tn(e),i=nn(e,null==n?void 0:n.laneOrder);for(let a=0;a<3;a++){for(let t=1;t<o.length;t++)o[t]=Xn(o[t-1],o[t],r,"down",s,i),o[t]=zn(o[t-1],o[t],r,o[t+1],s);for(let t=o.length-2;t>=0;t--)o[t]=Xn(o[t+1],o[t],r,"up",s,i),o[t]=zn(o[t+1],o[t],r,o[t-1],s)}return{layers:o}}function An(t,e,n){const o=(null==n?void 0:n.layerGap)??an,r=(null==n?void 0:n.nodeGap)??cn,s=(null==n?void 0:n.laneGap)??2*r,i=(null==n?void 0:n.direction)??"TB",a="LR"===i||"RL"===i,c=t.layers,f=Object.create(null),l=Object.create(null),d=y(t=>e.nodeById.get(t),"getNode"),u=y(t=>{var e;return(null==(e=d(t))?void 0:e.width)??0},"getWidth"),h=y(t=>{var e;return(null==(e=d(t))?void 0:e.height)??0},"getHeight"),g=tn(e),p=nn(e,null==n?void 0:n.laneOrder),x=c.map(t=>t.reduce((t,e)=>Math.max(t,h(e)),0)),m=[];if(a)for(let y=0;y+1<c.length;y++){const t=c[y].reduce((t,e)=>Math.max(t,u(e)),0),e=c[y+1].reduce((t,e)=>Math.max(t,u(e)),0),n=x[y]/2+x[y+1]/2,r=(t+e)/2,s=Math.max(0,r-n-o);m.push(s)}const b=new Set;for(const y of c)for(const t of y)b.add(g(t));const M=b.has(null),I=p.filter(t=>b.has(t)),v=[...M?[null]:[],...I],S=Object.create(null);for(const y of I)S[y]=0;M&&(S.null=0);for(const y of c){const t=Object.create(null),e=[];for(const n of y){const o=g(n);null===o?e.push(n):(t[o]||(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);S[n]=Math.max(S[n]??0,t)}if(M&&e.length){const t=e.reduce((t,e)=>t+u(e),0)+r*Math.max(0,e.length-1);S.null=Math.max(S.null??0,t)}}const w=new Map;{const t=v.map(t=>(null===t?S.null:S[t])??0);let e=-(t.reduce((t,e)=>t+e,0)+s*Math.max(0,v.length-1))/2;for(let n=0;n<v.length;n++){const o=v[n],r=t[n]??0,i=e+r/2;w.set(o,i),e+=r,n<v.length-1&&(e+=s)}}let L=0;for(const[y,k]of c.entries()){const t=x[y]??0,e=new Map;for(const n of k){const t=g(n),o=e.get(t)??[];o.push(n),e.set(t,o)}for(const n of v){const o=e.get(n)??[];if(0===o.length)continue;const s=w.get(n);if(1===o.length){const e=o[0];f[e]=s,l[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,l[i]=L+t/2,n+=o+r}}}L+=t+o+(m[y]??0)}const C=new Map;for(const y of e.edges){const t=y.ref.id;C.has(t)||C.set(t,[]),C.get(t).push(y)}for(const[,y]of C){if(0===y.length)continue;const t=y[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 y)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);(null==t?void 0:t.isDummy)&&(f[i]=r)}}return{x:f,y:l}}y(fn,"buildDrivingTree"),y(ln,"chooseParent"),y(dn,"buildAdjacency"),y(un,"assignComponents"),y(hn,"computeBlocks"),y(gn,"popBlock"),y(pn,"computeSubtreeCrossCounts"),y(xn,"annotateMinimumLayers"),y(mn,"compareByRankThenId"),y(yn,"emitNodesInTreeOrder"),y(bn,"deduplicateLayers"),y(Mn,"createChildOrderer"),y(In,"buildMultitreeLayerOrder"),y(vn,"countCrossingsBetweenAdjacent"),y(Sn,"totalCrossings"),y(wn,"optimizeRanksByCrossings"),y(Ln,"adjustCrossLaneSources"),y(Cn,"assignLayers_LongestPath"),y(kn,"assignLayers_Gravity"),y(Tn,"topoSortByGenerationIfAcyclic"),y($n,"assignLayers_LaneAwareCompact"),y(On,"makeProperLayering"),y(Rn,"median"),y(Nn,"barycenter"),y(Bn,"neighborPositionsFor"),y(En,"currentOrderTieBreak"),y(Fn,"countCrossingsBetweenAdjacent"),y(Yn,"sortByHeuristic"),y(Xn,"reorderLayer"),y(zn,"transposeImprove"),y(Pn,"orderLayers"),y(An,"assignCoordinates");function Gn(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 Dn(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 Hn(t,e){const n=[...t],o=Dn(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 jn(t,e){let n=0;for(const[o,r]of t.entries())n+=Math.abs(o-(e.get(r)??o));return n}function _n(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 Vn(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),l=n.get(c);if(null==f||null==l)continue;const[d,u]=f<=l?[a,c]:[c,a],h=`${d}\0${u}`,g=r.get(h);g?g.weight++:r.set(h,{a:d,b:u,weight:1})}return[...r.values()]}function Wn(t,e,n){const o=[...t];let r=_n(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=_n(o,e);n<r?(r=n,s=!0):[o[t],o[t+1]]=[o[t+1],o[t]]}}return{order:o,cost:r,sourceDistance:jn(o,n)}}function Jn(t,e){return t.cost!==e.cost?t.cost<e.cost:t.sourceDistance<e.sourceDistance}function qn(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 Gn(`${t.join("|")}#${o}#${n}`)}function Kn(t,e={}){const n=en(t);if(n.length<2)return n;const o=Vn(t);if(0===o.length)return n;const r=new Map(n.map((t,e)=>[t,e]));let s=Wn(n,o,r);const i=Math.max(0,e.restarts??8);for(let a=0;a<i;a++){const t=Wn(Hn(n,qn(n,o,a)),o,r);Jn(t,s)&&(s=t)}return s.order}function Qn(t,e){const n=(null==e?void 0:e.ignoreCrossLaneEdges)??!0,o=(null==e?void 0:e.optimizeRanksByCrossings)??!0,r=Ge(t),s=(null==e?void 0:e.automaticLaneOrdering)?Kn(r,{restarts:8}):void 0,i=Ze(r),a=i.acyclic,c=n?$n(a,{compactSingleInput:(null==e?void 0:e.compactSingleInput)??sn,ignoreCrossLaneEdges:!0,direction:null==e?void 0:e.direction}):kn(a,{compactSingleInput:(null==e?void 0:e.compactSingleInput)??sn,ignoreCrossLaneEdges:!1,optimizeRanksByCrossings:o}),{layering:f,graphWithDummies:l}=On(c,a),d=Pn(f,l,{laneOrder:s}),u=An(d,l,{layerGap:null==e?void 0:e.layerGap,nodeGap:null==e?void 0:e.nodeGap,direction:null==e?void 0:e.direction,laneOrder:s});return{acyclic:a,reversed:i.reversed,layering:f,ordered:d,coordinates:u}}y(Gn,"hashString"),y(Dn,"mulberry32"),y(Hn,"deterministicShuffle"),y(jn,"sourceDistance"),y(_n,"laneArrangementCost"),y(Vn,"buildWeightedLaneEdges"),y(Wn,"greedySwitch"),y(Jn,"isBetterCandidate"),y(qn,"seedForRestart"),y(Kn,"optimizeTopLaneOrder"),y(Qn,"sugiyamaLayout");var Zn=1e-6,Un=15,to=15,eo=20;function no(t,e,n){const o=t.x??0,r=t.y??0,s=e.x-o,i=e.y-r,a=Math.abs(s),c=Math.abs(i);if(a<Zn&&c<Zn)return n;return c>Zn&&3*c>=a?i>0?"bottom":"top":a>Zn?s>0?"right":"left":n}function oo(t,e){return Math.abs(t.to-e.from)<Zn||Math.abs(t.to-e.to)<Zn?t.to:t.from}function ro(t,e){return"vertical"===t.orient?{x:t.coord,y:e}:{x:e,y:t.coord}}function so(t,e){var n,o,r,s;const i=t.nodes??[],a=t.edges??[],c=[];for(const y of a)y.isLayoutOnly||c.push({...y,__originalEdge:y});const f=new Map,l=new Map,d=[],u="LR"===e;for(const y of i)f.set(y.id,y);const h=i.filter(t=>t.isGroup&&!t.parentId);for(const it of h){const t={id:it.id},e=y(n=>{l.set(n.id,t),i.filter(t=>t.parentId===n.id).forEach(e)},"assignLane");e(it)}const g=i.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:u?n/2+8:e/2+8}}),p=y((t,e,n,o)=>{let r=d.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:[]},d.push(r)),r.spanMin=Math.min(r.spanMin,n),r.spanMax=Math.max(r.spanMax,o),r},"getOrAddPipe"),x=y((t,e)=>{const n=t.width??10,o=t.height??10,r=t.x??0,s=t.y??0;switch(e){case"top":return{x:r,y:s-o/2};case"bottom":return{x:r,y:s+o/2};case"left":return{x:r-n/2,y:s};case"right":return{x:r+n/2,y:s}}},"portForSide"),m=y((t,e,n)=>x(t,no(t,e,n?"bottom":"top")),"getOrthogonalPort"),b=[],M=[],I=new Set,v=y((t,e,n)=>{if(0===b.length)return 0;const o=Math.abs(e.y-n.y)<Zn,r=Math.abs(e.x-n.x)<Zn;if(!o&&!r)return 0;let s=0;if(o){const o=e.y,r=Math.min(e.x,n.x)-Zn,i=Math.max(e.x,n.x)+Zn;if(i<=r)return 0;for(const e of b)e.edgeIndex!==t&&"vertical"===e.orientation&&(e.pipe.coord<r||e.pipe.coord>i||e.from-Zn<=o&&e.to+Zn>=o&&(s+=1e3))}else if(r){const o=e.x,r=Math.min(e.y,n.y)-Zn,i=Math.max(e.y,n.y)+Zn;if(i<=r)return 0;for(const e of b)e.edgeIndex!==t&&"horizontal"===e.orientation&&(e.pipe.coord<r||e.pipe.coord>i||e.from-Zn<=o&&e.to+Zn>=o&&(s+=1e3))}return s},"crossingPenalty"),S=c.map((t,e)=>{if(!t.start||!t.end)return{idx:e,crossLane:0,dx:0,dy:0};const n=f.get(t.start),o=f.get(t.end),r=l.get(t.start),s=l.get(t.end);return{idx:e,crossLane:r&&s&&r.id!==s.id?1:0,dx:n&&o?Math.abs((o.x??0)-(n.x??0)):0,dy:n&&o?Math.abs((o.y??0)-(n.y??0)):0}}).sort((t,e)=>{if(t.crossLane!==e.crossLane)return e.crossLane-t.crossLane;const n=t.dx+t.dy,o=e.dx+e.dy;return Math.abs(n-o)>1?n-o:t.idx-e.idx}).map(t=>t.idx),w=y((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!!g.find(c=>(!n||c.nodeId!==n)&&((!o||c.nodeId!==o)&&(Math.abs(t.x-e.x)>Zn?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"),L=new Map,C=new Map;for(const y of c)y.start&&y.end&&y.start!==y.end&&(C.set(y.start,(C.get(y.start)??0)+1),C.set(y.end,(C.get(y.end)??0)+1));const k=y((t,e)=>no(t,e,"bottom"),"determineSide"),T=new Map;for(const[y,it]of c.entries()){if(!it.start||!it.end||it.start===it.end)continue;if(it.points&&it.points.length>0)continue;const t=f.get(it.start),e=f.get(it.end);if(!t||!e)continue;const n=(e.x??0)-(t.x??0),o=(e.y??0)-(t.y??0);T.set(y,{edgeIdx:y,srcId:it.start,dstId:it.end,srcSide:k(t,{x:e.x??0,y:e.y??0}),dstSide:k(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 $=y(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"),O=y(t=>"top"===t.srcSide||"bottom"===t.srcSide?t.dxSign>=0?"right":"left":t.dySign>=0?"bottom":"top","secondarySide"),R=new Map;for(const y of T.values()){const t=`${y.srcId}:${y.srcSide}`;R.has(t)||R.set(t,[]),R.get(t).push(y)}const N=new Map,B=y((t,e)=>`${t}:${e}`,"loadKey");for(const y of T.values())N.set(B(y.srcId,y.srcSide),(N.get(B(y.srcId,y.srcSide))??0)+1),N.set(B(y.dstId,y.dstSide),(N.get(B(y.dstId,y.dstSide))??0)+1);for(const y of R.values())if(!(y.length<2)){y.sort((t,e)=>{const n=$(t),o=$(e);return Math.abs(n-o)>1e-9?o-n:t.edgeIdx-e.edgeIdx});for(let t=1;t<y.length;t++){const e=y[t],n=O(e),o=N.get(B(e.srcId,e.srcSide))??0,r=N.get(B(e.srcId,n))??0;r>=o||(N.set(B(e.srcId,e.srcSide),o-1),N.set(B(e.srcId,n),r+1),e.srcSide=n)}}const E=y(t=>{const e=null==t?void 0:t.shape;return"question"===e||"diamond"===e},"isDiamondNode"),F=new Map;for(const y of T.values())F.has(y.dstId)||F.set(y.dstId,new Set),F.get(y.dstId).add(y.dstSide);for(const y of T.values()){if(!E(f.get(y.srcId)))continue;const t=F.get(y.srcId);if(!(null==t?void 0:t.has(y.srcSide)))continue;const e=O(y);if(t.has(e)||(N.get(B(y.srcId,e))??0)>0)continue;const n=N.get(B(y.srcId,y.srcSide))??0;N.set(B(y.srcId,y.srcSide),Math.max(0,n-1)),N.set(B(y.srcId,e),1),y.srcSide=e}for(const y of T.values()){const{edgeIdx:t,srcId:e,dstId:n,srcSide:o,dstSide:r}=y,s=f.get(e),i=f.get(n),a=`${e}:${o}:src`,c="top"===o||"bottom"===o?i.x??0:i.y??0;L.has(a)||L.set(a,[]),L.get(a).push({edgeIdx:t,oppositeCoord:c});const l=`${n}:${r}:dst`,d="top"===r||"bottom"===r?s.x??0:s.y??0;L.has(l)||L.set(l,[]),L.get(l).push({edgeIdx:t,oppositeCoord:d})}const Y=new Map;for(const[y,it]of L){if(it.length<2)continue;it.sort((t,e)=>t.oppositeCoord-e.oppositeCoord);const t=y.split(":"),e=t.slice(0,-2).join(":"),n=t[t.length-2],o=t[t.length-1],r=f.get(e);if(!r)continue;const s="left"===n||"right"===n?r.height??10:r.width??10,i=r.shape,a="question"===i||"diamond"===i?.3*s:s,c=20,l=Math.min(c,Math.max(8,a/(it.length+1))),d=-(l*(it.length-1))/2;for(const[f,u]of it.entries()){const t=d+f*l,e=`${u.edgeIdx}:${o}`;Y.set(e,t)}}const X=y(t=>{var e;return Boolean(null==(e=c[t])?void 0:e.labelNodeId)},"edgeHasLabelNode"),z=y((t,e)=>!!t&&((L.get(`${t}:${e}:src`)??[]).some(({edgeIdx:t})=>X(t))||(L.get(`${t}:${e}:dst`)??[]).some(({edgeIdx:t})=>X(t))),"faceHasLabelNode"),P=y((t,e,n)=>"top"===e||"bottom"===e?{x:t.x+n,y:t.y}:{x:t.x,y:t.y+n},"applyPortOffset"),A=y((t,e,n)=>{const o=T.get(t),r={x:n.x??0,y:n.y??0},s={x:e.x??0,y:e.y??0},i=(null==o?void 0:o.srcSide)??k(e,r),a=(null==o?void 0:o.dstSide)??k(n,s);let c=o?x(e,o.srcSide):m(e,r,!0),f=o?x(n,o.dstSide):m(n,s,!1);const l=Y.get(`${t}:src`),d=Y.get(`${t}:dst`);return void 0!==l&&(c=P(c,i,l)),void 0!==d&&(f=P(f,a,d)),{pSrcPort:c,pDstPort:f,srcSide:i,dstSide:a}},"portsForEdge");for(const it of S){const t=c[it];if(M[it]=[],!t.start||!t.end)continue;if(t.points&&t.points.length>0)continue;if(t.start===t.end)continue;const e=f.get(t.start),i=f.get(t.end);if(!e||!i)continue;const{pSrcPort:a,pDstPort:l,srcSide:h,dstSide:x}=A(it,e,i),m={...a},S={...l},k="top"===h||"bottom"===h,T="top"===x||"bottom"===x;if(k){const t=a.y>(e.y??0);m.y=t?a.y+eo:a.y-eo}else{const t=a.x>(e.x??0);m.x=t?a.x+eo:a.x-eo}if(T){const t=l.y>(i.y??0);S.y=t?l.y+eo:l.y-eo}else{const t=l.x>(i.x??0);S.x=t?l.x+eo:l.x-eo}const $=y((t,e)=>{for(const n of g)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"),O=y((t,e,n,o,r)=>{if(r){const r=t.y>(e.y??0);return{x:(n.x??0)>=t.x?o.maxX+Un:o.minX-Un,y:r?o.maxY+to:o.minY-to,leavesPositiveSide:r}}const s=t.x>(e.x??0),i=(n.y??0)>=t.y;return{x:s?o.maxX+Un:o.minX-Un,y:i?o.maxY+to:o.minY-to,leavesPositiveSide:s}},"obstacleDetour");let R=[];const N=[t.start,t.end],B=$(m,N);if(B.inside&&B.obstacle){const t=B.obstacle;if(k){const n=O(a,e,i,t,!0);m.x=n.x,m.y=n.y;const o=n.leavesPositiveSide?Math.min(t.minY-2,a.y+eo):Math.max(t.maxY+2,a.y-eo);R=[{x:a.x,y:o},{x:n.x,y:o},{x:n.x,y:n.y}]}else{const n=O(a,e,i,t,!1),o=n.leavesPositiveSide?Math.min(t.minX-2,a.x+eo):Math.max(t.maxX+2,a.x-eo);m.x=n.x,m.y=n.y,R=[{x:o,y:a.y},{x:o,y:n.y},{x:n.x,y:n.y}]}}let E=[];const F=$(S,N);if(F.inside&&F.obstacle){const t=F.obstacle;if(T){const n=O(l,i,e,t,!0);S.x=n.x,S.y=n.y,E=[{x:n.x,y:n.y},{x:l.x,y:n.y}]}else{const n=O(l,i,e,t,!1);S.x=n.x,S.y=n.y,E=[{x:n.x,y:n.y},{x:n.x,y:l.y}]}}if(0===R.length&&0===E.length){const e=Un,i=Math.abs(m.x-S.x)<e,c=Math.abs(m.y-S.y)<e,f=void 0!==Y.get(`${it}:src`)||void 0!==Y.get(`${it}:dst`),d=((null==(n=L.get(`${t.start??""}:${h}:src`))?void 0:n.length)??0)+((null==(o=L.get(`${t.start??""}:${h}:dst`))?void 0:o.length)??0),u=((null==(r=L.get(`${t.end??""}:${x}:src`))?void 0:r.length)??0)+((null==(s=L.get(`${t.end??""}:${x}:dst`))?void 0:s.length)??0),g=d>1||u>1,p=C.get(t.start??"")??0,y=C.get(t.end??"")??0,M=d>1&&z(t.start,h)||u>1&&z(t.end,x);if((i||c)&&!f&&(!g||g&&!M&&(d<=1||p<=2)&&(u<=1||y<=2))){if(!w(a,l,t.start,t.end)){t.points=[{...a},{...m},{...S},{...l}],I.add(it);const e=c?"horizontal":"vertical",n=c?a.y:a.x,o=c?Math.min(a.x,l.x):Math.min(a.y,l.y),r=c?Math.max(a.x,l.x):Math.max(a.y,l.y),s={id:`fast-path-${e}-${n.toFixed(0)}-${it}`,orientation:e,coord:n,spanMin:o,spanMax:r,tracks:[]};b.push({edgeIndex:it,segmentIndex:0,orientation:e,pipe:s,trackIndex:0,from:o,to:r});continue}}}const X=p("vertical",m.x,m.y,m.y);m.x=X.coord;const P=p("vertical",S.x,S.y,S.y);S.x=P.coord;let G=Math.min(m.x,S.x)-50,D=Math.max(m.x,S.x)+50,H=Math.min(m.y,S.y)-50,j=Math.max(m.y,S.y)+50;for(const n of g){const t=Math.min(m.x,S.x),e=Math.max(m.x,S.x),o=Math.min(m.y,S.y),r=Math.max(m.y,S.y);n.minX<e&&n.maxX>t&&n.minY<r&&n.maxY>o&&(G=Math.min(G,n.minX-25),D=Math.max(D,n.maxX+25),H=Math.min(H,n.minY-25),j=Math.max(j,n.maxY+25))}for(const n of g){if(n.maxX<G||n.minX>D||n.maxY<H||n.minY>j)continue;const t=Un;p("horizontal",n.minY-t,G,D),p("horizontal",n.maxY+t,G,D);const e=to;p("vertical",n.minX-e,H,j),p("vertical",n.maxX+e,H,j)}p("horizontal",m.y,G,D),p("horizontal",S.y,G,D);const _=d.filter(t=>"horizontal"===t.orientation&&t.coord>=H&&t.coord<=j),V=d.filter(t=>"vertical"===t.orientation&&t.coord>=G&&t.coord<=D),W=y((t,e)=>`${t.toFixed(1)},${e.toFixed(1)}`,"getKey"),J=W(m.x,m.y),q=W(S.x,S.y),K=new Map,Q=new Map,Z=new Map,U=new Set,tt=[];K.set(J,0),Z.set(J,"n"),tt.push({key:J,f:Math.hypot(S.x-m.x,S.y-m.y),pt:m}),U.add(J);let et=[];const nt=y((e,n)=>w(e,n,t.start,t.end),"checkSegmentBlocked"),ot={x:S.x,y:m.y},rt=nt(m,ot),st=nt(ot,S),at=rt||st,ct={x:m.x,y:S.y},ft=nt(m,ct),lt=nt(ct,S);if(at?ft||lt||(et=Math.abs(m.x-S.x)<Zn?[m,S]:[m,ct,S]):et=Math.abs(m.y-S.y)<Zn||Math.abs(m.x-S.x)<Zn?[m,S]:[m,ot,S],0===et.length)for(;tt.length>0;){tt.sort((t,e)=>t.f-e.f);const e=tt.shift();if(U.delete(e.key),e.key===q){let t=q,e=S;for(et=[e];Q.has(t);){const n=Q.get(t);et.unshift(n),e=n,t=W(n.x,n.y)}break}const n=e.pt.x,o=e.pt.y,r=V.sort((t,e)=>t.coord-e.coord),s=r.findIndex(t=>Math.abs(t.coord-n)<1),i=_.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(g.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=W(f.x,f.y),l=Math.abs(f.x-n)+Math.abs(f.y-o),d=v(it,e.pt,f);let u=0;const h=S.x-m.x,p=S.y-m.y,x=f.x-n,y=f.y-o;(p>10&&y<-5||p<-10&&y>5)&&(u=100*Math.abs(y)),(h>10&&x<-5||h<-10&&x>5)&&(u+=50*Math.abs(x));let b=0;const M=Z.get(e.key)??"n",I=Math.abs(x)>Zn?"h":"v";"n"!==M&&M!==I&&(b=50);const w=l+d+u+b,L=(K.get(e.key)??1/0)+w,C=Math.abs(S.x-f.x)+Math.abs(S.y-f.y);if(L<(K.get(c)??1/0))if(Q.set(c,e.pt),K.set(c,L),Z.set(c,I),U.has(c)){const t=tt.findIndex(t=>t.key===c);-1!==t&&(tt[t].f=L+C)}else tt.push({key:c,f:L+C,pt:f}),U.add(c)}}if(0===et.length&&(et=[m,{x:m.x,y:S.y},S]),et.length>4){const t=et[0],e=et[et.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 d of et)n=Math.min(n,d.x),o=Math.max(o,d.x),r=Math.min(r,d.y),s=Math.max(s,d.y);const i=o>Math.max(t.x,e.x),a=n<Math.min(t.x,e.x);if(u){const r=to;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=g.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=g.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 c=y(n=>{const o=e.y>t.y,r=g.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(u&&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-Zn)return t}else{const t=Math.min(...s.map(t=>t.minY))-15;if(t>e.y+Zn)return t}return e.y},"findBestReturnY"),f=y(n=>{const o=c(n),r={x:n,y:t.y},s={x:n,y:o},i={x:e.x,y:o},a=nt(t,r),f=nt(r,s),l=nt(s,i),d=o!==e.y&&nt(i,e);return a||f||l||d?null:Math.abs(o-e.y)<Zn?[t,r,s,e]:[t,r,s,i,e]},"trySimplifyWithDetourX"),l=i&&!a?f(o):a&&!i?f(n):null;l&&(et=l)}const dt=[a,...R,...et,...E.reverse(),l];if(dt.length>=3){const t=dt[dt.length-1],e=dt[dt.length-2],n=dt[dt.length-3],o=Math.abs(n.y-e.y)<Zn&&Math.abs(e.y-t.y)<Zn,r=Math.abs(n.x-e.x)<Zn&&Math.abs(e.x-t.x)<Zn;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)&&dt.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)&&dt.splice(-2,1)}}const ut=[dt[0]];for(let n=1;n<dt.length-1;n++){if(1===n){ut.push(dt[n]);continue}const t=ut[ut.length-1],e=dt[n],o=dt[n+1];if(Math.abs(t.y-e.y)<Zn&&Math.abs(e.y-o.y)<Zn){if(e.x>t.x!==o.x>e.x){ut.push(e);continue}continue}if(Math.abs(t.x-e.x)<Zn&&Math.abs(e.x-o.x)<Zn){if(e.y>t.y!==o.y>e.y){ut.push(e);continue}continue}ut.push(e)}ut.push(dt[dt.length-1]);for(let n=0;n<ut.length-1;n++){const t=ut[n],e=ut[n+1],o=Math.abs(t.x-e.x)<Zn?"vertical":"horizontal",r="vertical"===o?t.x:t.y,s="vertical"===o?Math.min(t.y,e.y):Math.min(t.x,e.x),i="vertical"===o?Math.max(t.y,e.y):Math.max(t.x,e.x),a=p(o,r,s,i),c={edgeIndex:it,segmentIndex:n,orientation:o,pipe:a,trackIndex:0,from:s,to:i};b.push(c),M[it].push(b.length-1),a.tracks[0]||(a.tracks[0]={index:0,coord:a.coord,segments:[]}),a.tracks[0].segments.push({edgeIndex:it,segmentIndex:n,from:s,to:i})}}const G=y((t,e)=>t.from<e.to&&e.from<t.to,"segmentsOverlap"),D=y((t,e,n,o)=>{const r=!o.segments.some(n=>(n.edgeIndex!==e.edgeIndex||n.segmentIndex!==e.segmentIndex)&&G(n,t)),s=!n.segments.some(n=>(n.edgeIndex!==t.edgeIndex||n.segmentIndex!==t.segmentIndex)&&G(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"),H=y(t=>{const e=t.tracks.length;return t.tracks[e]={index:e,coord:t.coord,segments:[]},e},"createNewTrack"),j=y((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"),_=y((t,e)=>{const n=M[t.edgeIndex];for(const o of n){const n=b[o];n.pipe===t.pipe&&j(n,e)}},"moveSegmentChainToTrack"),V=y(t=>{const e=M[t.edgeIndex],n=e.indexOf(b.indexOf(t)),o=[];return n>0&&o.push(b[e[n-1]]),n<e.length-1&&o.push(b[e[n+1]]),o},"getAdjacentSegmentsAlongEdge"),W=y((t,e)=>{if(t.orientation===e.orientation)return!1;const n="horizontal"===t.orientation?t:e,o="horizontal"===t.orientation?e:t;return o.pipe.coord>n.from&&o.pipe.coord<n.to&&n.pipe.coord>o.from&&n.pipe.coord<o.to},"haveAnyCrossing"),J=y((t,e)=>{for(const n of t.tracks){if(!n.segments.some(t=>(t.edgeIndex!==e.edgeIndex||t.segmentIndex!==e.segmentIndex)&&G(t,e)))return n.index}return-1},"findAvailableTrack"),q=y((t,e)=>{if(t.trackIndex===e.trackIndex)return G(t,e);const n=V(t),o=V(e);return n.some(t=>o.some(e=>W(t,e)))},"segmentsConflict"),K=y((t,e,n)=>{if(D(t,e,t.pipe.tracks[t.trackIndex],e.pipe.tracks[e.trackIndex]))return;const o=J(t.pipe,e);n(e,-1!==o?o:H(t.pipe))},"resolveTrackConflict"),Q=y(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&&(q(r,s)&&(e++,K(r,s,_)))}return e},"resolveHandleConflicts"),Z=new Map,U=y(t=>{if(Z.has(t))return Z.get(t);const e=M[t];if(0===e.length){const e={dest:0,deviation:0,base:0,delta:0};return Z.set(t,e),e}const n=b[e[0]].pipe.coord;let o=n;for(let s=1;s<e.length;s++){const t=b[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 Z.set(t,r),r},"getDestInfo"),tt=y(()=>{let t=0;const e=new Map;for(const[o,r]of c.entries())0!==M[o].length&&r.start&&(e.has(r.start)||e.set(r.start,[]),e.get(r.start).push(o));const n=y(t=>{const e=c[t];if(!e.start||!e.end)return 0;const n=f.get(e.start),o=f.get(e.end);if(!n||!o)return 0;const r=(o.x??0)-(n.x??0),s=(o.y??0)-(n.y??0);return Math.abs(r)+Math.abs(s)},"getEdgeDistance");for(const o of e.values()){o.sort((t,e)=>{const o=U(t),r=U(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=M[t].length,c=M[e].length;if(a!==c)return a-c;if(1===a){const n=M[t][0],o=M[e][0];if(b[n]&&b[o]){const t=b[n],e=b[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=>b[M[t][0]]);t+=Q(e)}return t},"fixSourceHandleCrossings"),et=y(()=>{let t=0;const e=new Map;for(const[n,o]of c.entries()){0!==M[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=y(t=>{const e=M[t];if(e.length<2)return 0;const n=b[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=>b[M[t][M[t].length-1]]);t+=Q(e)}return t},"fixTargetHandleCrossings"),nt=y(()=>{let t=0;for(const e of d){const n=[];for(const t of e.tracks)for(const e of t.segments){const t=M[e.edgeIndex].find(t=>b[t].segmentIndex===e.segmentIndex);void 0!==t&&n.push(b[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];q(r,s)&&(t++,K(r,s,j))}}return t},"fixPipeCrossings");let ot=0;for(;ot<10;){let t=0;if(t+=tt(),t+=et(),t+=nt(),0===t)break;ot++}const rt=new Map;for(const it of d){const t=[];it.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=U(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=y((t,e)=>{n.filter(e=>e.trackIndex===t).forEach(t=>{const n=I.has(t.edgeIndex)?it.coord:e;rt.set(`${t.edgeIndex}-${t.segmentIndex}`,n)})},"assignCoord");let a=0;for(const n of o)a++,i(n,it.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,it.coord);else{const t=c%2==1?1:-1,e=Math.ceil(c/2);i(n,it.coord+t*e*10*.5)}c++}let f=0;for(const n of r)f++,i(n,it.coord+10*f)}}for(const[y,it]of c.entries()){const t=M[y]??[];if(0===t.length)continue;const e=[],n=f.get(it.start),o=f.get(it.end),{pSrcPort:r,pDstPort:s}=A(y,n,o),i=t.map(t=>{const e=b[t],n=rt.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 f=0;f<i.length;f++){const t=i[f],n=e[e.length-1],o="vertical"===t.orient?n.y:n.x,r="vertical"===t.orient?n.x:n.y,s=i[f+1],a=f<i.length-1;if(Math.abs(r-t.coord)>Zn&&e.push(ro(t,o)),a&&s.orient===t.orient)if(Math.abs(t.coord-s.coord)>Zn){const n="vertical"===t.orient?(o+s.from)/2:oo(t,s);e.push(ro(t,n),ro(s,n))}else 0!==f&&f!==i.length-2||e.push(ro(t,oo(t,s)));else if(a)e.push(ro(t,s.coord));else{const n=Math.abs(t.from-o)<Math.abs(t.to-o)?t.to:t.from;e.push(ro(t,n))}}const a=e[e.length-1];(Math.abs(a.x-s.x)>Zn||Math.abs(a.y-s.y)>Zn)&&e.push(s);const c=[];e.length>0&&c.push(e[0]);for(let f=1;f<e.length;f++){const t=e[f],n=c[c.length-1];(Math.abs(t.x-n.x)>Zn||Math.abs(t.y-n.y)>Zn)&&c.push(t)}it.points=c}for(const y of c){const t=y.__originalEdge;t&&y.points&&(t.points=y.points)}t.edges=(t.edges??[]).filter(t=>!t.isLayoutOnly);const st=y((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 l=t.x-i,d=a-t.x,u=t.y-c,h=f-t.y,g=Math.min(l,d,u,h);return g===l?{x:i,y:t.y}:g===d?{x:a,y:t.y}:g===u?{x:t.x,y:c}:{x:t.x,y:f}},"nodeBoundaryClamp");for(const y of t.edges){const t=y.points;if(!t||t.length<2)continue;const e=y.start,n=y.end,o=e?f.get(e):void 0,r=n?f.get(n):void 0;o&&(t[0]=st(t[0],o)),r&&(t[t.length-1]=st(t[t.length-1],r))}return t}function io(t){return t.direction??"TB"}function ao(t){var e,n,o,r,s;const i=_(t),a=(null==(e=t.config.flowchart)?void 0:e.nodeSpacing)??40,c=(null==(n=t.config.flowchart)?void 0:n.rankSpacing)??100,f=(null==(o=t.config.swimlane)?void 0:o.ignoreCrossLaneEdges)??!0,l=(null==(r=t.config.swimlane)?void 0:r.optimizeRanksByCrossings)??!0,d=(null==(s=t.config.swimlane)?void 0:s.automaticLaneOrdering)??!1,u=io(t),{ordered:h,coordinates:g}=Qn(i,{nodeGap:a,layerGap:c,ignoreCrossLaneEdges:f,optimizeRanksByCrossings:l,automaticLaneOrdering:d,direction:u});V(i,h,g,{nodeGap:a,layerGap:c});for(const p of t.edges??[])delete p.points;so(t,u);for(const p of t.edges??[])p.curve&&"basis"!==p.curve||(p.curve="rounded");return Ae(t,u),Pe(t),u}async function co(t,i){const a=i.select("g");n(a,t.markers,t.type,t.diagramId),o(),r(),s(),e(),j(t);const c=W(t);t.nodes=c.nodes,t.edges=c.edges;const{groups:f}=await I(a,t);ao(t),await P(t,f)}y(no,"chooseOrthogonalSide"),y(oo,"sharedLineEndpointCoord"),y(ro,"pointOnLine"),y(so,"routeEdgesOrthogonal"),y(io,"getSwimlaneDirection"),y(ao,"runSwimlaneLayoutCore"),y(co,"render");export{co as render};