import{_ as l,l as m,d as k}from"./App-BpvJr136.js";import{c as P,a as q}from"./graph-BqpC5g-G.js";import"./mobile-DAxPPzok.js";import"./index-DCkbHzW2.js";P.use(q);function D(t,o){t.forEach(e=>{const n={id:e.id,labelText:e.label,height:e.height,width:e.width,padding:e.padding??0};Object.keys(e).forEach(r=>{["id","label","height","width","padding","x","y"].includes(r)||(n[r]=e[r])}),o.add({group:"nodes",data:n,position:{x:e.x??0,y:e.y??0}})})}l(D,"addNodes");function I(t,o){t.forEach(e=>{const n={id:e.id,source:e.start,target:e.end};Object.keys(e).forEach(r=>{["id","start","end"].includes(r)||(n[r]=e[r])}),o.add({group:"edges",data:n})})}l(I,"addEdges");function $(t){return new Promise(o=>{const e=k("body").append("div").attr("id","cy").attr("style","display:none"),n=P({container:document.getElementById("cy"),style:[{selector:"edge",style:{"curve-style":"bezier"}}]});e.remove(),D(t.nodes,n),I(t.edges,n),n.nodes().forEach(function(a){a.layoutDimensions=()=>{const y=a.data();return{w:y.width,h:y.height}}});const r={name:"cose-bilkent",quality:"proof",styleEnabled:!1,animate:!1};n.layout(r).run(),n.ready(a=>{m.info("Cytoscape ready",a),o(n)})})}l($,"createCytoscapeInstance");function X(t){return t.nodes().map(o=>{const e=o.data(),n=o.position(),r={id:e.id,x:n.x,y:n.y};return Object.keys(e).forEach(a=>{a!=="id"&&(r[a]=e[a])}),r})}l(X,"extractPositionedNodes");function Y(t){return t.edges().map(o=>{const e=o.data(),n=o._private.rscratch,r={id:e.id,source:e.source,target:e.target,startX:n.startX,startY:n.startY,midX:n.midX,midY:n.midY,endX:n.endX,endY:n.endY};return Object.keys(e).forEach(a=>{["id","source","target"].includes(a)||(r[a]=e[a])}),r})}l(Y,"extractPositionedEdges");async function v(t,o){m.debug("Starting cose-bilkent layout algorithm");try{B(t);const e=await $(t),n=X(e),r=Y(e);return m.debug(`Layout completed: ${n.length} nodes, ${r.length} edges`),{nodes:n,edges:r}}catch(e){throw m.error("Error in cose-bilkent layout algorithm:",e),e}}l(v,"executeCoseBilkentLayout");function B(t){if(!t)throw new Error("Layout data is required");if(!t.config)throw new Error("Configuration is required in layout data");if(!t.rootNode)throw new Error("Root node is required");if(!t.nodes||!Array.isArray(t.nodes))throw new Error("No nodes found in layout data");if(!Array.isArray(t.edges))throw new Error("Edges array is required in layout data");return!0}l(B,"validateLayoutData");var O=l(async(t,o,{insertCluster:e,insertEdge:n,insertEdgeLabel:r,insertMarkers:a,insertNode:y,log:c,positionEdgeLabel:x},{algorithm:j})=>{const u={},p={},f=o.select("g");a(f,t.markers,t.type,t.diagramId);const C=f.insert("g").attr("class","subgraphs"),E=f.insert("g").attr("class","edgePaths"),A=f.insert("g").attr("class","edgeLabels"),N=f.insert("g").attr("class","nodes");c.debug("Inserting nodes into DOM for dimension calculation"),await Promise.all(t.nodes.map(async s=>{if(s.isGroup){const i={...s};p[s.id]=i,u[s.id]=i,await e(C,s)}else{const i={...s};u[s.id]=i;const d=await y(N,s,{config:t.config,dir:t.direction||"TB"}),g=d.node().getBBox();i.width=g.width,i.height=g.height,i.domId=d,c.debug(`Node ${s.id} dimensions: ${g.width}x${g.height}`)}})),c.debug("Running cose-bilkent layout algorithm");const _={...t,nodes:t.nodes.map(s=>{const i=u[s.id];return{...s,width:i.width,height:i.height}})},b=await v(_,t.config);c.debug("Positioning nodes based on layout results"),b.nodes.forEach(s=>{const i=u[s.id];i!=null&&i.domId&&(i.domId.attr("transform",`translate(${s.x}, ${s.y})`),i.x=s.x,i.y=s.y,c.debug(`Positioned node ${i.id} at center (${s.x}, ${s.y})`))}),b.edges.forEach(s=>{const i=t.edges.find(d=>d.id===s.id);i&&(i.points=[{x:s.startX,y:s.startY},{x:s.midX,y:s.midY},{x:s.endX,y:s.endY}])}),c.debug("Inserting and positioning edges"),await Promise.all(t.edges.map(async s=>{await r(A,s);const i=u[s.start??""],d=u[s.end??""];if(i&&d){const g=b.edges.find(h=>h.id===s.id);if(g){c.debug("APA01 positionedEdge",g);const h={...s},w=n(E,h,p,t.type,i,d,t.diagramId);x(h,w)}else{const h={...s,points:[{x:i.x||0,y:i.y||0},{x:d.x||0,y:d.y||0}]},w=n(E,h,p,t.type,i,d,t.diagramId);x(h,w)}}})),c.debug("Cose-bilkent rendering completed")},"render"),z=O;export{z as render};
