UNPKG

mermaid

Version:

Markdown-ish syntax for generating flowcharts, mindmaps, sequence diagrams, class diagrams, gantt charts, git graphs and more.

2 lines (1 loc) 10.5 kB
import{C as P}from"./chunk-D36F7FYG.mjs";import{b as V,c as T}from"./chunk-JCBDXJ5W.mjs";import{c as v,d as b,e as j,f as x,g as E,i as B,j as X}from"./chunk-OCMJQKYE.mjs";import{a as O,b as $,d as F,e as R}from"./chunk-MNT3HHAC.mjs";import{a as k}from"./chunk-TECWHJ6D.mjs";import{p as C}from"./chunk-QADHU5CF.mjs";import{$ as M,u as N}from"./chunk-FE53TMRB.mjs";import{b as u}from"./chunk-L2B47AAZ.mjs";import{a as l}from"./chunk-QVIEFLGF.mjs";function Z(e,{edgePathsClass:n="edges edgePaths"}={}){let t=e.insert("g").attr("class","root"),r=t.insert("g").attr("class","clusters"),o=t.insert("g").attr("class",n),a=t.insert("g").attr("class","edgeLabels"),i=t.insert("g").attr("class","nodes");return{clusters:r,edgePaths:o,edgeLabels:a,nodes:i,rootGroups:t}}l(Z,"createLayoutElementGroups");async function I(e,n,t){if(n.label){let{shapeSvg:r,bbox:o}=await k(e,t===void 0?n:{...n,width:t});n.labelBBox={width:o.width,height:o.height},r.remove()}else n.labelBBox={width:0,height:0}}l(I,"measureGroupLabel");async function ee(e,n,t){let r=await $(e,n,t),o=r.node()?.getBBox()??{width:0,height:0};return n.width=o.width,n.height=o.height,r}l(ee,"insertMeasuredNode");function te(e,n,t){let r=e,o=new Set;for(;r;){if(r.dir)return r.dir;if(!r.parentId||o.has(r.parentId))break;o.add(r.parentId),r=n.get(r.parentId)}return t}l(te,"resolveNodeDir");async function A(e,n,t={}){let r=new P({multigraph:!0,compound:!0}),o=[...n.edges],a=M(),i=Z(e),{edgeLabels:m,nodes:s}=i,f=new Map,y=new Map(n.nodes.map(d=>[d.id,d])),S=n.direction,g=e.node()!=null;await Promise.all(n.nodes.map(async d=>{if(d.isGroup){if(g){let L=t.unwrapGroupLabels&&d.labelType!=="markdown";await I(s,d,L?Number.POSITIVE_INFINITY:void 0)}r.setNode(d.id,{...d})}else{if(g){let L=await ee(s,d,{config:a,dir:te(d,y,S)});f.set(d.id,L)}r.setNode(d.id,{...d})}}));for(let d of o)g&&x(d)&&await E(m,d),r.setEdge(d.start,d.end,{...d},d.id),n.edges.some(w=>w.id===d.id)||n.edges.push(d);if(globalThis.mermaidCaptureSizes){let{captureNodeSizes:d}=await import("./sizeCapture-ERV5D3W5.mjs");d(e,n)}return{graph:r,groups:i,nodeElements:f}}l(A,"createGraphWithElements");var c=new Map,p=new Map,H=new Map,z=l(()=>{p.clear(),H.clear(),c.clear()},"clear"),h=l((e,n)=>{let t=p.get(n)||[];return u.trace("In isDescendant",n," ",e," = ",t.includes(e)),t.includes(e)},"isDescendant"),ne=l((e,n)=>{let t=p.get(n)||[];return u.info("Descendants of ",n," is ",t),u.info("Edge is ",e),e.v===n||e.w===n?!1:t?t.includes(e.v)||h(e.v,n)||h(e.w,n)||t.includes(e.w):(u.debug("Tilt, ",n,",not in descendants"),!1)},"edgeInCluster"),J=l((e,n,t,r)=>{u.debug("Copying children of ",e,"root",r,"data",n.node(e),r);let o=n.children(e)||[];e!==r&&o.push(e),u.debug("Copying (nodes) clusterId",e,"nodes",o),o.forEach(a=>{if(n.children(a).length>0)J(a,n,t,r);else{let i=n.node(a);u.info("cp ",a," to ",r," with parent ",e),t.setNode(a,i),r!==n.parent(a)&&(u.debug("Setting parent",a,n.parent(a)),t.setParent(a,n.parent(a))),e!==r&&a!==e?(u.debug("Setting parent",a,e),t.setParent(a,e)):(u.info("In copy ",e,"root",r,"data",n.node(e),r),u.debug("Not Setting parent for node=",a,"cluster!==rootId",e!==r,"node!==clusterId",a!==e));let m=n.edges(a);u.debug("Copying Edges",m),m.forEach(s=>{u.info("Edge",s);let f=n.edge(s.v,s.w,s.name);u.info("Edge data",f,r);try{ne(s,r)?(u.info("Copying as ",s.v,s.w,f,s.name),t.setEdge(s.v,s.w,f,s.name),u.info("newGraph edges ",t.edges(),t.edge(t.edges()[0]))):u.info("Skipping copy of edge ",s.v,"-->",s.w," rootId: ",r," clusterId:",e)}catch(y){u.error(y)}})}u.debug("Removing node",a),n.removeNode(a)})},"copy"),W=l((e,n)=>{let t=n.children(e),r=[...t];for(let o of t)H.set(o,e),r=[...r,...W(o,n)];return r},"extractDescendants");var oe=l((e,n,t)=>{let r=e.edges().filter(s=>s.v===n||s.w===n),o=e.edges().filter(s=>s.v===t||s.w===t),a=r.map(s=>({v:s.v===n?t:s.v,w:s.w===n?n:s.w})),i=o.map(s=>({v:s.v,w:s.w}));return a.filter(s=>i.some(f=>s.v===f.v&&s.w===f.w))},"findCommonEdges"),D=l((e,n,t)=>{let r=n.children(e);if(u.trace("Searching children of id ",e,r),r.length<1)return e;let o;for(let a of r){let i=D(a,n,t),m=oe(n,t,i);if(i)if(m.length>0)o=i;else return i}return o},"findNonClusterChild"),_=l(e=>!c.has(e)||!c.get(e).externalConnections?e:c.has(e)?c.get(e).id:e,"getAnchorId"),xe=l((e,n)=>{if(!e||n>10){u.debug("Opting out, no graph ");return}else u.debug("Opting in, graph ");e.nodes().forEach(function(t){e.children(t).length>0&&(u.debug("Cluster identified",t," Replacement id in edges: ",D(t,e,t)),p.set(t,W(t,e)),c.set(t,{id:D(t,e,t),clusterData:e.node(t)}))}),e.nodes().forEach(function(t){let r=e.children(t),o=e.edges();r.length>0?(u.debug("Cluster identified",t,p),o.forEach(a=>{let i=h(a.v,t),m=h(a.w,t);i^m&&(u.debug("Edge: ",a," leaves cluster ",t),u.debug("Descendants of XXX ",t,": ",p.get(t)),c.get(t).externalConnections=!0)})):u.debug("Not a cluster ",t,p)});for(let t of c.keys()){let r=c.get(t).id,o=e.parent(r);o!==t&&c.has(o)&&!c.get(o).externalConnections&&(c.get(t).id=o);let a=e.edges().some(i=>i.v===t);if(r&&c.get(t)?.externalConnections&&a&&K(e,r,t)){let i=re(e,t,e.parent(r));i&&(c.get(t).id=i)}}e.edges().forEach(function(t){let r=e.edge(t);u.debug("Edge "+t.v+" -> "+t.w+": "+JSON.stringify(t)),u.debug("Edge "+t.v+" -> "+t.w+": "+JSON.stringify(e.edge(t)));let o=t.v,a=t.w;if(u.debug("Fix XXX",c,"ids:",t.v,t.w,"Translating: ",c.get(t.v)," --- ",c.get(t.w)),c.get(t.v)||c.get(t.w)){if(u.debug("Fixing and trying - removing XXX",t.v,t.w,t.name),o=_(t.v),a=_(t.w),e.removeEdge(t.v,t.w,t.name),o!==t.v){let i=e.parent(o);c.get(i).externalConnections=!0,r.fromCluster=t.v}if(a!==t.w){let i=e.parent(a);c.get(i).externalConnections=!0,r.toCluster=t.w}u.debug("Fix Replacing with XXX",o,a,t.name),e.setEdge(o,a,r,t.name)}}),Y(e,0),u.trace(c)},"adjustClustersAndEdges"),Y=l((e,n)=>{if(n>10){u.error("Bailing out");return}let t=e.nodes(),r=!1;for(let o of t){let a=e.children(o);r=r||a.length>0}if(!r){u.debug("Done, no node has children",e.nodes());return}u.debug("Nodes = ",t,n);for(let o of t)if(u.debug("Extracting node",o,c,c.has(o)&&!c.get(o).externalConnections,!e.parent(o),e.node(o),e.children("D")," Depth ",n),!c.has(o))u.debug("Not a cluster",o,n);else if(!c.get(o).externalConnections&&e.children(o)&&e.children(o).length>0){u.debug("Cluster without external connections, without a parent and with children",o,n);let i=e.graph().rankdir==="TB"?"LR":"TB";c.get(o)?.clusterData?.dir&&(i=c.get(o).clusterData.dir,u.debug("Fixing dir",c.get(o).clusterData.dir,i));let m=new P({multigraph:!0,compound:!0}).setGraph({rankdir:i,nodesep:50,ranksep:50,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}});J(o,e,m,o),e.setNode(o,{clusterNode:!0,id:o,clusterData:c.get(o).clusterData,label:c.get(o).label,graph:m})}else u.debug("Cluster ** ",o," **not meeting the criteria !externalConnections:",!c.get(o).externalConnections," no parent: ",!e.parent(o)," children ",e.children(o)&&e.children(o).length>0,e.children("D"),n),u.debug(c);t=e.nodes(),u.debug("New list of nodes",t);for(let o of t){let a=e.node(o);u.debug(" Now next level",o,a),a?.clusterNode&&Y(a.graph,n+1)}},"extractor"),q=l((e,n)=>{if(n.length===0)return[];let t=Object.assign([],n);return n.forEach(r=>{let o=e.children(r),a=q(e,o);t=[...t,...a]}),t},"sorter"),Ee=l(e=>q(e,e.children()),"sortNodesByHierarchy"),K=l((e,n,t)=>{let r=e.parent(n);for(;r&&r!==t;){let o=c.get(r);if(o&&!o.externalConnections)return!0;r=e.parent(r)}return!1},"isNodeInExtractableCluster"),re=l((e,n,t)=>{let r=e.children(n)??[];for(let o of r){if(o===t||h(o,t))continue;let a=D(o,e,n);if(a&&!K(e,a,n))return a}return null},"findSafeAnchorNode");function Xe({prepareLayout:e,measureLayout:n,runLayoutCore:t,paintLayout:r,afterPaint:o,paintOptions:a}){let i=n??se;return l(async function(s,f,y,S){let g=f.select("g");(y?.insertMarkers??X)(g,s.markers,s.type,s.diagramId),ae();let d={element:g,helpers:y,options:S};d.preparedLayout=await e?.(s,d);let L=await i(s,d),w=await t(s,d),G={...d,measure:L};r?await r(s,G,w):await ie(s,G,a),await o?.(s,G,w)},"render")}l(Xe,"createCommonLayoutRenderer");function ae(){F(),j(),T(),z()}l(ae,"clearLayoutRenderState");async function se(e,{element:n},t){return await A(n,e,t)}l(se,"defaultMeasureLayout");async function ie(e,n,t={}){let{measure:r}=n,{groups:o}=r;for(let i of t.getNodes?.(e,n)??e.nodes)t.skipNode?.(i,n)||await ue(o,i,n,t);let a=ce(e.nodes);for(let i of e.edges)de(i,t)||await me(o,i,a,e,t,n)}l(ie,"paintLayoutData");async function ue(e,n,t,r){n.clusterNode?R(n):le(n,t,r)?await V(e.clusters,n):R(n)}l(ue,"paintLayoutNode");function le(e,n,t){return e.isGroup===!0&&(t.isCluster?.(e,n)??!0)}l(le,"shouldPaintAsCluster");function ce(e){let n=new Map;for(let t of e)t?.id&&n.set(t.id,t);return n}l(ce,"buildNodeLookup");function de(e,n){return e.isLayoutOnly||!!n.skipEdge?.(e)}l(de,"shouldSkipPaintEdge");async function me(e,n,t,r,o,a){let i=B(e.edgePaths,{...n},o.clusterDb??new Map,r.type,Q(n.start,n,t,a,o),Q(n.end,n,t,a,o),r.diagramId,fe(n,o));x(n)&&(v.has(n.id)||await E(e.edgeLabels,n),pe(n,i))}l(me,"paintLayoutEdge");function Q(e,n,t,r,o){return o.getEdgeNode?.(e,n,r)??(e?t.get(e)??{}:{})}l(Q,"getRenderedNode");function fe(e,n){return typeof n.skipIntersect=="function"?n.skipIntersect(e):n.skipIntersect??!1}l(fe,"shouldSkipIntersect");function pe(e,n){let t=n?.updatedPath??n?.originalPath,r=N(),{subGraphTitleTotalMargin:o}=O({flowchart:r.flowchart??{}});if(e.label){let a=v.get(e.id),i=e.x,m=e.y;if(t){let s=C.calcLabelPosition(t);u.debug("Moving label "+e.label+" from (",i,",",m,") to (",s.x,",",s.y,") abc88"),n?.updatedPath&&(i=s.x,m=s.y)}a.attr("transform",`translate(${i}, ${m+o/2})`)}if(e?.startLabelLeft){let a=b.get(e.id).startLeft,i=e?.x,m=e?.y;if(t){let s=C.calcTerminalLabelPosition(e.arrowTypeStart?10:0,"start_left",t);i=s.x,m=s.y}a.attr("transform",`translate(${i}, ${m})`)}if(e.startLabelRight){let a=b.get(e.id).startRight,i=e.x,m=e.y;if(t){let s=C.calcTerminalLabelPosition(e.arrowTypeStart?10:0,"start_right",t);i=s.x,m=s.y}a.attr("transform",`translate(${i}, ${m})`)}if(e.endLabelLeft){let a=b.get(e.id).endLeft,i=e.x,m=e.y;if(t){let s=C.calcTerminalLabelPosition(e.arrowTypeEnd?10:0,"end_left",t);i=s.x,m=s.y}a.attr("transform",`translate(${i}, ${m})`)}if(e.endLabelRight){let a=b.get(e.id).endRight,i=e.x,m=e.y;if(t){let s=C.calcTerminalLabelPosition(e.arrowTypeEnd?10:0,"end_right",t);i=s.x,m=s.y}a.attr("transform",`translate(${i}, ${m})`)}}l(pe,"positionRenderedEdgeLabel");export{Z as a,ee as b,c,D as d,xe as e,Ee as f,Xe as g,se as h};