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