UNPKG

code-server

Version:

Run VS Code on a remote server.

5 lines (4 loc) • 11 kB
import{a as H}from"./chunk-JXCTOEX6.js";import{a as O,b as A,c as E,d as D,e as Y,f as x,g as _}from"./chunk-BC6FHEEV.js";import{C as k}from"./chunk-2KBWIZHB.js";import{a as I}from"./chunk-EZ2ZNYYD.js";import{f as N,g as M,h as G}from"./chunk-I5GW343B.js";import{a as v,c as B,e as S}from"./chunk-ES5HVIAH.js";import{b as P}from"./chunk-EW2Q7GE5.js";import"./chunk-EWILYK3H.js";import"./chunk-LWO52Q4K.js";import"./chunk-FX4LUBZ3.js";import"./chunk-EIVI6XHZ.js";import"./chunk-5FA4L7EO.js";import"./chunk-JBQZ5UCE.js";import{_ as R}from"./chunk-XL5YO2U3.js";import{b as p}from"./chunk-3CEAP2V5.js";import{a as m}from"./chunk-6LQNQPBM.js";import"./chunk-OOJM4CTU.js";var J=m((t,e,r)=>Math.max(e,Math.min(r,t)),"clamp"),T=m((t="TB")=>{switch(t){case"BT":return"bottom";case"LR":return"right";case"RL":return"left";default:return"top"}},"getDefaultSelfLoopSide"),U=m(t=>t==="flowchart"||t==="flowchart-v2"||t==="stateDiagram"||t==="er"||t==="classDiagram","shouldMergeSelfLoopSegments"),K=["x","y","width","height","labelBBox","intersect","calcIntersect","diff","clusterNode"],Q=m((t,e,r,d,n)=>{let f=[],h=new Set;if(r.forEach(({start:s,end:o})=>{s!==d&&h.add(s),o!==d&&h.add(o)}),h.forEach(s=>{let o=t.node(s);typeof o?.x=="number"&&typeof o?.y=="number"&&f.push(o)}),f.length===0&&r.forEach(({edge:s})=>{(s.points??[]).forEach(o=>{typeof o?.x=="number"&&typeof o?.y=="number"&&f.push(o)})}),f.length===0)return T(n);let g=f.reduce((s,o)=>({x:s.x+o.x/f.length,y:s.y+o.y/f.length}),{x:0,y:0}),l=g.x-e.x,i=g.y-e.y;return Math.abs(l)>Math.abs(i)?l>0?"right":"left":Math.abs(i)>0?i>0?"bottom":"top":T(n)},"getSelfLoopSide"),V=m((t,e="top",r=0,d=0)=>{let n=t.x,f=t.y-r,h=t.width/2,g=t.height/2,l=Math.max(36,Math.min(100,t.width*.8)),i=J(Math.max(d,t.width*.35),36,l),s=J(Math.min(t.width,t.height)*.45,24,48);switch(e){case"bottom":{let o=f+g;return[{x:n-i/2,y:o},{x:n-i/2,y:o+s},{x:n+i/2,y:o+s},{x:n+i/2,y:o}]}case"right":{let o=n+h;return[{x:o,y:f-i/2},{x:o+s,y:f-i/2},{x:o+s,y:f+i/2},{x:o,y:f+i/2}]}case"left":{let o=n-h;return[{x:o,y:f-i/2},{x:o-s,y:f-i/2},{x:o-s,y:f+i/2},{x:o,y:f+i/2}]}default:{let o=f-g;return[{x:n-i/2,y:o},{x:n-i/2,y:o-s},{x:n+i/2,y:o-s},{x:n+i/2,y:o}]}}},"getSelfLoopPoints"),Z=m((t,e,r="top",d=0,n={})=>{let h=t.x,g=t.y-d,l=n.width??0,i=n.height??0;switch(r){case"bottom":return{x:h,y:Math.max(...e.map(s=>s.y))+i/2+4};case"right":return{x:Math.max(...e.map(s=>s.x))+l/2+4,y:g};case"left":return{x:Math.min(...e.map(s=>s.x))-l/2-4,y:g};default:return{x:h,y:Math.min(...e.map(s=>s.y))-i/2-4}}},"getSelfLoopLabelPosition"),F=m((t,e=0,{mergeSelfLoops:r=!0}={})=>{let d=new Map,n=[],f=t.graph()?.rankdir;return t.edges().forEach(h=>{let g=t.edge(h);if(r&&g.selfLoop){let l=g.selfLoop.id;d.has(l)||d.set(l,[]),d.get(l).push({edge:g,start:h.v,end:h.w})}else n.push({edge:g,start:h.v,end:h.w})}),d.forEach(h=>{if(h.length!==3){h.forEach(u=>n.push(u));return}h.sort((u,w)=>u.edge.selfLoop.order-w.edge.selfLoop.order);let[g,l,i]=h,s=g.edge.originalEdge??l.edge.originalEdge??i.edge.originalEdge??l.edge,o=t.node(s.start);if(!o){h.forEach(u=>n.push(u));return}let a={width:l.edge.width,height:l.edge.height},L=Q(t,o,h,s.start,f),b=V(o,L,e,a.width??0),y=Z(o,b,L,e,a),c={...l.edge,...s,id:s.id,points:b,start:s.start,end:s.end,x:y.x,y:y.y,width:a.width,height:a.height,labelStyle:l.edge.labelStyle,fromCluster:g.edge.fromCluster??l.edge.fromCluster??i.edge.fromCluster,toCluster:g.edge.toCluster??l.edge.toCluster??i.edge.toCluster};delete c.selfLoop,delete c.originalEdge,n.push({edge:c,start:c.start,end:c.end})}),n},"getEdgesToRender"),W=m(async({element:t,graph:e,diagramType:r,id:d,parentCluster:n,siteConfig:f})=>{let h=e.graph().rankdir;p.trace("Dir in recursive render - dir:",h);let{clusters:g,edgePaths:l,edgeLabels:i,nodes:s,rootGroups:o}=O(t,{edgePathsClass:"edgePaths"});e.nodes()?p.info("Recursive render XXX",e.nodes()):p.info("No nodes found for",e),e.edges().length>0&&p.info("Recursive edges",e.edge(e.edges()[0]));let a=U(r);await Promise.all(e.nodes().map(async function(y){let c=e.node(y);if(n!==void 0){let u=JSON.parse(JSON.stringify(n.clusterData));p.trace(`Setting data for parent cluster XXX Node.id = `,y,` data=`,u.height,` Parent cluster`,n.height),e.setNode(n.id,u),e.parent(y)||(p.trace("Setting parent",y,n.id),e.setParent(y,n.id,u))}if(p.info("(Insert) Node XXX"+y+": "+JSON.stringify(e.node(y))),c?.clusterNode){p.info("Cluster identified XBX",y,c.width,e.node(y));let{ranksep:u,nodesep:w}=e.graph();c.graph.setGraph({...c.graph.graph(),ranksep:u+25,nodesep:w});let X=await oe({element:s,graph:c.graph,diagramType:r,id:d,parentCluster:e.node(y),siteConfig:f}),C=X.elem;P(c,C),c.diff=X.diff||0,p.info("New compound node after recursive render XAX",y,"width",c.width,"height",c.height),B(C,c)}else e.children(y).length>0?(p.trace("Cluster - the non recursive path XBX",y,c.id,c,c.width,"Graph:",e),p.trace(D(c.id,e)),E.set(c.id,{id:D(c.id,e),node:c})):(p.trace("Node - the non recursive path XAX",y,s,e.node(y),h),await A(s,e.node(y),{config:f,dir:h}))})),await m(async()=>{let y=e.edges().map(async function(c){let u=e.edge(c.v,c.w,c.name);if(p.info("Edge "+c.v+" -> "+c.w+": "+JSON.stringify(c)),p.info("Edge "+c.v+" -> "+c.w+": ",c," ",JSON.stringify(e.edge(c))),p.info("Fix",E,"ids:",c.v,c.w,"Translating: ",E.get(c.v),E.get(c.w)),a&&u.selfLoop){if(u.selfLoop.order!==1)return;let w={...u.originalEdge,...u,id:u.selfLoop.id,startLabelLeft:u.originalEdge?.startLabelLeft??u.startLabelLeft,startLabelRight:u.originalEdge?.startLabelRight??u.startLabelRight,endLabelLeft:u.originalEdge?.endLabelLeft??u.endLabelLeft,endLabelRight:u.originalEdge?.endLabelRight??u.endLabelRight};await N(i,w),u.width=w.width,u.height=w.height,u.labelStyle=w.labelStyle;return}await N(i,u)});await Promise.all(y)},"processEdges")();let{subGraphTitleTotalMargin:b}=v(f);return{elem:o,graph:e,groups:{clusters:g,edgePaths:l,edgeLabels:i,nodes:s,rootGroups:o},diagramType:r,id:d,mergeSelfLoops:a,subGraphTitleTotalMargin:b}},"measureDagreGraph"),j=m(t=>{p.info("############################################# XXX"),p.info("### Layout ### XXX"),p.info("############################################# XXX"),H(t)},"runDagreGraphLayout"),$=m((t,e,r)=>{let d=t.node(e);if(!d)return;let n={...d};return d?.clusterNode?n.y=(d.y??0)+r:t.children(e).length>0?n.height=(d.height??0)+r:n.y=(d.y??0)+r/2,n},"normalizeDagreNode"),z=m((t,e)=>{K.forEach(r=>{e[r]!==void 0&&(t[r]=e[r])})},"applyDagreNodeLayout"),ee=m((t,e,r,d)=>({...t,start:t.start??e,end:t.end??r,points:(t.points??[]).map(n=>({...n,y:typeof n.y=="number"?n.y+d:n.y}))}),"normalizeDagreEdge"),te=m((t,e)=>{let{graph:r,mergeSelfLoops:d,subGraphTitleTotalMargin:n=0}=e,f=new Map(t.nodes.map(g=>[g.id,g]));x(r).forEach(g=>{let l=$(r,g,n);if(!l)return;z(r.node(g),l);let i=f.get(g);i&&z(i,l)});let h=n/2;return t.edges=F(r,h,{mergeSelfLoops:d}).map(({edge:g,start:l,end:i})=>ee(g,l,i,h)),t},"applyDagreLayoutResult"),re=m(async({elem:t,graph:e,groups:{clusters:r,edgePaths:d},diagramType:n,id:f,mergeSelfLoops:h,subGraphTitleTotalMargin:g})=>{let l=0;await Promise.all(x(e).map(async function(o){let a=e.node(o);if(p.info("Position XBX => "+o+": ("+a.x,","+a.y,") width: ",a.width," height: ",a.height),a?.clusterNode)a.y+=g,p.info("A tainted cluster node XBX1",o,a.id,a.width,a.height,a.x,a.y,e.parent(o)),E.get(a.id).node=a,S(a);else if(e.children(o).length>0){p.info("A pure cluster node XBX1",o,a.id,a.x,a.y,a.width,a.height,e.parent(o)),a.height+=g,e.node(a.parentId);let L=a?.padding/2||0,b=a?.labelBBox?.height||0,y=b-L||0;p.debug("OffsetY",y,"labelHeight",b,"halfPadding",L),await I(r,a),E.get(a.id).node=a}else{let L=e.node(a.parentId);a.y+=g/2,p.info("A regular node XBX1 - using the padding",a.id,"parent",a.parentId,a.width,a.height,a.x,a.y,"offsetY",a.offsetY,"parent",L,L?.offsetY,a),S(a)}}));let i=g/2;return F(e,i,{mergeSelfLoops:h}).forEach(function({edge:o,start:a,end:L}){p.info("Edge "+a+" -> "+L+": "+JSON.stringify(o),o),o.points.forEach(u=>u.y+=i);let b=e.node(a),y=e.node(L),c=G(d,o,E,n,b,y,f);M(o,c)}),e.nodes().forEach(function(o){let a=e.node(o);p.info(o,a.type,a.diff),a.isGroup&&(l=a.diff)}),p.warn("Returning from recursive render XAX",t,l),{elem:t,diff:l}},"paintDagreLayoutCore"),oe=m(async t=>{let e=await W(t);return j(e.graph),await re(e)},"renderDagreSubgraph"),q=m(t=>{let e=new k({multigraph:!0,compound:!0}).setGraph({rankdir:t.direction,nodesep:t.config?.nodeSpacing||t.nodeSpacing||t.config?.flowchart?.nodeSpacing,ranksep:t.config?.rankSpacing||t.rankSpacing||t.config?.flowchart?.rankSpacing,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}});return t.nodes.forEach(r=>{e.setNode(r.id,{...r}),r.parentId&&e.setParent(r.id,r.parentId)}),p.debug("Edges:",t.edges),t.edges.forEach(r=>{if(r.start===r.end){let d=r.start,n=d+"---"+d+"---1",f=d+"---"+d+"---2",h=e.node(d);e.setNode(n,{domId:n,id:n,parentId:h.parentId,labelStyle:"",label:"",padding:0,shape:"labelRect",style:"",width:10,height:10}),e.setParent(n,h.parentId),e.setNode(f,{domId:f,id:f,parentId:h.parentId,labelStyle:"",padding:0,shape:"labelRect",label:"",style:"",width:10,height:10}),e.setParent(f,h.parentId);let g=structuredClone(r),l=structuredClone(r),i=structuredClone(r),s=structuredClone(r);l.originalEdge=g,l.selfLoop={id:g.id,order:0},i.originalEdge=g,i.selfLoop={id:g.id,order:1},s.originalEdge=g,s.selfLoop={id:g.id,order:2},l.label="",l.arrowTypeEnd="none",l.endLabelLeft="",l.endLabelRight="",l.startLabelLeft="",l.id=d+"-cyclic-special-1",i.startLabelRight="",i.startLabelLeft="",i.endLabelLeft="",i.endLabelRight="",i.arrowTypeStart="none",i.arrowTypeEnd="none",i.id=d+"-cyclic-special-mid",s.label="",s.startLabelRight="",s.startLabelLeft="",s.arrowTypeStart="none",h.isGroup&&(l.fromCluster=d,s.toCluster=d),s.id=d+"-cyclic-special-2",s.arrowTypeStart="none",e.setEdge(d,n,l,d+"-cyclic-special-0"),e.setEdge(n,f,i,d+"-cyclic-special-1"),e.setEdge(f,d,s,d+"-cyclic-special-2")}else e.setEdge(r.start,r.end,{...r},r.id)}),Y(e),{graph:e}},"prepareLayoutForDagre"),ne=m(async(t,{element:e,preparedLayout:r})=>{let d=r??q(t),n=R(),f=await W({element:e,graph:d.graph,diagramType:t.type,id:t.diagramId,parentCluster:void 0,siteConfig:n});return d.measuredLayout=f,f},"measureDagreLayout"),ae=m((t,e)=>{let r=e.preparedLayout?.measuredLayout;if(!r)throw new Error("runDagreLayoutCore requires measureDagreLayout to run first");return j(r.graph),te(t,r),r},"runDagreLayoutCore"),ie=m((t,{measure:e})=>x(e.graph).map(r=>e.graph.node(r)).filter(Boolean),"getDagrePaintNodes"),se=m((t,e,{measure:r})=>t?r.graph.node(t):void 0,"getDagreEdgeNode"),xe=_({prepareLayout:q,measureLayout:ne,runLayoutCore:ae,paintOptions:{clusterDb:E,getNodes:ie,getEdgeNode:se,skipNode:m((t,{measure:e})=>!e.graph.hasNode(t.id),"skipNode"),isCluster:m((t,{measure:e})=>e.graph.hasNode(t.id)&&(e.graph.children(t.id)??[]).length>0,"isCluster")}});export{te as applyDagreLayoutResult,F as getEdgesToRender,ne as measureDagreLayout,q as prepareLayoutForDagre,xe as render,ae as runDagreLayoutCore};