mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-11-10 06:01:44 +08:00
2 lines
17 KiB
JavaScript
2 lines
17 KiB
JavaScript
import{a as st,b as H,c as rt,d as X,e as at,f as lt,g as ot,h as z,i as ct,j as dt,k as ft,l as ht}from"./chunk-CUHU5CRX.js";import{a as it,b as $,c as nt}from"./chunk-2PAX6U2T.js";import{a as x}from"./chunk-OAJ6LBAA.js";import{a as J}from"./chunk-QMNP6MOC.js";import{d as tt}from"./chunk-QY4OGOKK.js";import{a as et}from"./chunk-GCWB44UQ.js";import{a as R}from"./chunk-ZIY7VF5V.js";import{c as M,d as F,m as j,p as I}from"./chunk-NQ4DUWMN.js";import"./chunk-XHGORZV2.js";import{Da as G,I as D,N as P,P as Z,Z as p,h as g,ha as E,j as s}from"./chunk-ZOEWSKT6.js";import"./chunk-UEXLG4I5.js";import"./chunk-SISR4MA5.js";import"./chunk-24JW6VB3.js";import{a as L,b as Y}from"./chunk-MGYUK2XN.js";var h={},S={},ut={},Et=g(()=>{S={},ut={},h={}},"clear"),A=g((e,t)=>(s.trace("In isDescendant",t," ",e," = ",S[t].includes(e)),!!S[t].includes(e)),"isDescendant"),Ct=g((e,t)=>(s.info("Descendants of ",t," is ",S[t]),s.info("Edge is ",e),e.v===t||e.w===t?!1:S[t]?S[t].includes(e.v)||A(e.v,t)||A(e.w,t)||S[t].includes(e.w):(s.debug("Tilt, ",t,",not in descendants"),!1)),"edgeInCluster"),gt=g((e,t,i,l)=>{s.warn("Copying children of ",e,"root",l,"data",t.node(e),l);let n=t.children(e)||[];e!==l&&n.push(e),s.warn("Copying (nodes) clusterId",e,"nodes",n),n.forEach(r=>{if(t.children(r).length>0)gt(r,t,i,l);else{let a=t.node(r);s.info("cp ",r," to ",l," with parent ",e),i.setNode(r,a),l!==t.parent(r)&&(s.warn("Setting parent",r,t.parent(r)),i.setParent(r,t.parent(r))),e!==l&&r!==e?(s.debug("Setting parent",r,e),i.setParent(r,e)):(s.info("In copy ",e,"root",l,"data",t.node(e),l),s.debug("Not Setting parent for node=",r,"cluster!==rootId",e!==l,"node!==clusterId",r!==e));let f=t.edges(r);s.debug("Copying Edges",f),f.forEach(d=>{s.info("Edge",d);let u=t.edge(d.v,d.w,d.name);s.info("Edge data",u,l);try{Ct(d,l)?(s.info("Copying as ",d.v,d.w,u,d.name),i.setEdge(d.v,d.w,u,d.name),s.info("newGraph edges ",i.edges(),i.edge(i.edges()[0]))):s.info("Skipping copy of edge ",d.v,"-->",d.w," rootId: ",l," clusterId:",e)}catch(b){s.error(b)}})}s.debug("Removing node",r),t.removeNode(r)})},"copy"),wt=g((e,t)=>{let i=t.children(e),l=[...i];for(let n of i)ut[n]=e,l=[...l,...wt(n,t)];return l},"extractDescendants"),B=g((e,t)=>{s.trace("Searching",e);let i=t.children(e);if(s.trace("Searching children of id ",e,i),i.length<1)return s.trace("This is a valid node",e),e;for(let l of i){let n=B(l,t);if(n)return s.trace("Found replacement for",e," => ",n),n}},"findNonClusterChild"),_=g(e=>!h[e]||!h[e].externalConnections?e:h[e]?h[e].id:e,"getAnchorId"),Tt=g((e,t)=>{if(!e||t>10){s.debug("Opting out, no graph ");return}else s.debug("Opting in, graph ");e.nodes().forEach(function(i){e.children(i).length>0&&(s.warn("Cluster identified",i," Replacement id in edges: ",B(i,e)),S[i]=wt(i,e),h[i]={id:B(i,e),clusterData:e.node(i)})}),e.nodes().forEach(function(i){let l=e.children(i),n=e.edges();l.length>0?(s.debug("Cluster identified",i,S),n.forEach(r=>{if(r.v!==i&&r.w!==i){let a=A(r.v,i),f=A(r.w,i);a^f&&(s.warn("Edge: ",r," leaves cluster ",i),s.warn("Descendants of XXX ",i,": ",S[i]),h[i].externalConnections=!0)}})):s.debug("Not a cluster ",i,S)});for(let i of Object.keys(h)){let l=h[i].id,n=e.parent(l);n!==i&&h[n]&&!h[n].externalConnections&&(h[i].id=n)}e.edges().forEach(function(i){let l=e.edge(i);s.warn("Edge "+i.v+" -> "+i.w+": "+JSON.stringify(i)),s.warn("Edge "+i.v+" -> "+i.w+": "+JSON.stringify(e.edge(i)));let n=i.v,r=i.w;if(s.warn("Fix XXX",h,"ids:",i.v,i.w,"Translating: ",h[i.v]," --- ",h[i.w]),h[i.v]&&h[i.w]&&h[i.v]===h[i.w]){s.warn("Fixing and trixing link to self - removing XXX",i.v,i.w,i.name),s.warn("Fixing and trixing - removing XXX",i.v,i.w,i.name),n=_(i.v),r=_(i.w),e.removeEdge(i.v,i.w,i.name);let a=i.w+"---"+i.v;e.setNode(a,{domId:a,id:a,labelStyle:"",labelText:l.label,padding:0,shape:"labelRect",style:""});let f=structuredClone(l),d=structuredClone(l);f.label="",f.arrowTypeEnd="none",d.label="",f.fromCluster=i.v,d.toCluster=i.v,e.setEdge(n,a,f,i.name+"-cyclic-special"),e.setEdge(a,r,d,i.name+"-cyclic-special")}else if(h[i.v]||h[i.w]){if(s.warn("Fixing and trixing - removing XXX",i.v,i.w,i.name),n=_(i.v),r=_(i.w),e.removeEdge(i.v,i.w,i.name),n!==i.v){let a=e.parent(n);h[a].externalConnections=!0,l.fromCluster=i.v}if(r!==i.w){let a=e.parent(r);h[a].externalConnections=!0,l.toCluster=i.w}s.warn("Fix Replacing with XXX",n,r,i.name),e.setEdge(n,r,l,i.name)}}),s.warn("Adjusted Graph",x(e)),yt(e,0),s.trace(h)},"adjustClustersAndEdges"),yt=g((e,t)=>{var n,r;if(s.warn("extractor - ",t,x(e),e.children("D")),t>10){s.error("Bailing out");return}let i=e.nodes(),l=!1;for(let a of i){let f=e.children(a);l=l||f.length>0}if(!l){s.debug("Done, no node has children",e.nodes());return}s.debug("Nodes = ",i,t);for(let a of i)if(s.debug("Extracting node",a,h,h[a]&&!h[a].externalConnections,!e.parent(a),e.node(a),e.children("D")," Depth ",t),!h[a])s.debug("Not a cluster",a,t);else if(!h[a].externalConnections&&e.children(a)&&e.children(a).length>0){s.warn("Cluster without external connections, without a parent and with children",a,t);let d=e.graph().rankdir==="TB"?"LR":"TB";(r=(n=h[a])==null?void 0:n.clusterData)!=null&&r.dir&&(d=h[a].clusterData.dir,s.warn("Fixing dir",h[a].clusterData.dir,d));let u=new R({multigraph:!0,compound:!0}).setGraph({rankdir:d,nodesep:50,ranksep:50,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}});s.warn("Old graph before copy",x(e)),gt(a,e,u,a),e.setNode(a,{clusterNode:!0,id:a,clusterData:h[a].clusterData,labelText:h[a].labelText,graph:u}),s.warn("New graph after copy node: (",a,")",x(u)),s.debug("Old graph after copy",x(e))}else s.warn("Cluster ** ",a," **not meeting the criteria !externalConnections:",!h[a].externalConnections," no parent: ",!e.parent(a)," children ",e.children(a)&&e.children(a).length>0,e.children("D"),t),s.debug(h);i=e.nodes(),s.warn("New list of nodes",i);for(let a of i){let f=e.node(a);s.warn(" Now next level",a,f),f.clusterNode&&yt(f.graph,t+1)}},"extractor"),bt=g((e,t)=>{if(t.length===0)return[];let i=Object.assign(t);return t.forEach(l=>{let n=e.children(l),r=bt(e,n);i=[...i,...r]}),i},"sorter"),kt=g(e=>bt(e,e.children()),"sortNodesByHierarchy"),Dt=g((e,t)=>{s.info("Creating subgraph rect for ",t.id,t);let i=p(),l=e.insert("g").attr("class","cluster"+(t.class?" "+t.class:"")).attr("id",t.id),n=l.insert("rect",":first-child"),r=D(i.flowchart.htmlLabels),a=l.insert("g").attr("class","cluster-label"),f=t.labelType==="markdown"?tt(a,t.labelText,{style:t.labelStyle,useHtmlLabels:r},i):a.node().appendChild(H(t.labelText,t.labelStyle,void 0,!0)),d=f.getBBox();if(D(i.flowchart.htmlLabels)){let c=f.children[0],o=E(f);d=c.getBoundingClientRect(),o.attr("width",d.width),o.attr("height",d.height)}let u=0*t.padding,b=u/2,y=t.width<=d.width+u?d.width+u:t.width;t.width<=d.width+u?t.diff=(d.width-t.width)/2-t.padding/2:t.diff=-t.padding/2,s.trace("Data ",t,JSON.stringify(t)),n.attr("style",t.style).attr("rx",t.rx).attr("ry",t.ry).attr("x",t.x-y/2).attr("y",t.y-t.height/2-b).attr("width",y).attr("height",t.height+u);let{subGraphTitleTopMargin:m}=J(i);r?a.attr("transform",`translate(${t.x-d.width/2}, ${t.y-t.height/2+m})`):a.attr("transform",`translate(${t.x}, ${t.y-t.height/2+m})`);let w=n.node().getBBox();return t.width=w.width,t.height=w.height,t.intersect=function(c){return X(t,c)},l},"rect"),Xt=g((e,t)=>{let i=e.insert("g").attr("class","note-cluster").attr("id",t.id),l=i.insert("rect",":first-child"),n=0*t.padding,r=n/2;l.attr("rx",t.rx).attr("ry",t.ry).attr("x",t.x-t.width/2-r).attr("y",t.y-t.height/2-r).attr("width",t.width+n).attr("height",t.height+n).attr("fill","none");let a=l.node().getBBox();return t.width=a.width,t.height=a.height,t.intersect=function(f){return X(t,f)},i},"noteGroup"),Bt=g((e,t)=>{let i=p(),l=e.insert("g").attr("class",t.classes).attr("id",t.id),n=l.insert("rect",":first-child"),r=l.insert("g").attr("class","cluster-label"),a=l.append("rect"),f=r.node().appendChild(H(t.labelText,t.labelStyle,void 0,!0)),d=f.getBBox();if(D(i.flowchart.htmlLabels)){let c=f.children[0],o=E(f);d=c.getBoundingClientRect(),o.attr("width",d.width),o.attr("height",d.height)}d=f.getBBox();let u=0*t.padding,b=u/2,y=t.width<=d.width+t.padding?d.width+t.padding:t.width;t.width<=d.width+t.padding?t.diff=(d.width+t.padding*0-t.width)/2:t.diff=-t.padding/2,n.attr("class","outer").attr("x",t.x-y/2-b).attr("y",t.y-t.height/2-b).attr("width",y+u).attr("height",t.height+u),a.attr("class","inner").attr("x",t.x-y/2-b).attr("y",t.y-t.height/2-b+d.height-1).attr("width",y+u).attr("height",t.height+u-d.height-3);let{subGraphTitleTopMargin:m}=J(i);r.attr("transform",`translate(${t.x-d.width/2}, ${t.y-t.height/2-t.padding/3+(D(i.flowchart.htmlLabels)?5:3)+m})`);let w=n.node().getBBox();return t.height=w.height,t.intersect=function(c){return X(t,c)},l},"roundedWithTitle"),Lt=g((e,t)=>{let i=e.insert("g").attr("class",t.classes).attr("id",t.id),l=i.insert("rect",":first-child"),n=0*t.padding,r=n/2;l.attr("class","divider").attr("x",t.x-t.width/2-r).attr("y",t.y-t.height/2).attr("width",t.width+n).attr("height",t.height+n);let a=l.node().getBBox();return t.width=a.width,t.height=a.height,t.diff=-t.padding/2,t.intersect=function(f){return X(t,f)},i},"divider"),Jt={rect:Dt,roundedWithTitle:Bt,noteGroup:Xt,divider:Lt},pt={},Rt=g((e,t)=>{s.trace("Inserting cluster");let i=t.shape||"rect";pt[t.id]=Jt[i](e,t)},"insertCluster"),_t=g(()=>{pt={}},"clear"),mt=g(async(e,t,i,l,n,r)=>{s.info("Graph in recursive render: XXX",x(t),n);let a=t.graph().rankdir;s.trace("Dir in recursive render - dir:",a);let f=e.insert("g").attr("class","root");t.nodes()?s.info("Recursive render XXX",t.nodes()):s.info("No nodes found for",t),t.edges().length>0&&s.trace("Recursive edges",t.edge(t.edges()[0]));let d=f.insert("g").attr("class","clusters"),u=f.insert("g").attr("class","edgePaths"),b=f.insert("g").attr("class","edgeLabels"),y=f.insert("g").attr("class","nodes");await Promise.all(t.nodes().map(async function(c){let o=t.node(c);if(n!==void 0){let v=JSON.parse(JSON.stringify(n.clusterData));s.info("Setting data for cluster XXX (",c,") ",v,n),t.setNode(n.id,v),t.parent(c)||(s.trace("Setting parent",c,n.id),t.setParent(c,n.id,v))}if(s.info("(Insert) Node XXX"+c+": "+JSON.stringify(t.node(c))),o!=null&&o.clusterNode){s.info("Cluster identified",c,o.width,t.node(c));let{ranksep:v,nodesep:N}=t.graph();o.graph.setGraph(Y(L({},o.graph.graph()),{ranksep:v,nodesep:N}));let T=await mt(y,o.graph,i,l,t.node(c),r),C=T.elem;rt(o,C),o.diff=T.diff||0,s.info("Node bounds (abc123)",c,o,o.width,o.x,o.y),lt(C,o),s.warn("Recursive render complete ",C,o)}else t.children(c).length>0?(s.info("Cluster - the non recursive path XXX",c,o.id,o,t),s.info(B(o.id,t)),h[o.id]={id:B(o.id,t),node:o}):(s.info("Node - the non recursive path",c,o.id,o),await at(y,t.node(c),{config:r,dir:a}))})),t.edges().forEach(async function(c){let o=t.edge(c.v,c.w,c.name);s.info("Edge "+c.v+" -> "+c.w+": "+JSON.stringify(c)),s.info("Edge "+c.v+" -> "+c.w+": ",c," ",JSON.stringify(t.edge(c))),s.info("Fix",h,"ids:",c.v,c.w,"Translating: ",h[c.v],h[c.w]),await dt(b,o)}),t.edges().forEach(function(c){s.info("Edge "+c.v+" -> "+c.w+": "+JSON.stringify(c))}),s.info("Graph before layout:",JSON.stringify(x(t))),s.info("#############################################"),s.info("### Layout ###"),s.info("#############################################"),s.info(t),et(t),s.info("Graph after layout:",JSON.stringify(x(t)));let m=0,{subGraphTitleTotalMargin:w}=J(r);return kt(t).forEach(function(c){let o=t.node(c);s.info("Position "+c+": "+JSON.stringify(t.node(c))),s.info("Position "+c+": ("+o.x,","+o.y,") width: ",o.width," height: ",o.height),o!=null&&o.clusterNode?(o.y+=w,z(o)):t.children(c).length>0?(o.height+=w,Rt(d,o),h[o.id].node=o):(o.y+=w/2,z(o))}),t.edges().forEach(function(c){let o=t.edge(c);s.info("Edge "+c.v+" -> "+c.w+": "+JSON.stringify(o),o),o.points.forEach(N=>N.y+=w/2);let v=ht(u,c,o,h,i,t,l);ft(o,v)}),t.nodes().forEach(function(c){let o=t.node(c);s.info(c,o.type,o.diff),o.type==="group"&&(m=o.diff)}),{elem:f,diff:m}},"recursiveRender"),At=g(async(e,t,i,l,n)=>{st(e,i,l,n),ot(),ct(),_t(),Et(),s.warn("Graph at first:",JSON.stringify(x(t))),Tt(t),s.warn("Graph after:",JSON.stringify(x(t)));let r=p();await mt(e,t,l,n,void 0,r)},"render"),V=g(e=>P.sanitizeText(e,p()),"sanitizeText"),W={dividerMargin:10,padding:5,textHeight:10,curve:void 0},Ot=g(function(e,t,i,l){s.info("keys:",[...e.keys()]),s.info(e),e.forEach(function(n){var f,d,u;let a={shape:"rect",id:n.id,domId:n.domId,labelText:V(n.id),labelStyle:"",style:"fill: none; stroke: black",padding:(u=(f=p().flowchart)==null?void 0:f.padding)!=null?u:(d=p().class)==null?void 0:d.padding};t.setNode(n.id,a),vt(n.classes,t,i,l,n.id),s.info("setNode",a)})},"addNamespaces"),vt=g(function(e,t,i,l,n){s.info("keys:",[...e.keys()]),s.info(e),[...e.values()].filter(r=>r.parent===n).forEach(function(r){var m,w,c,o;let a=r.cssClasses.join(" "),f=F(r.styles),d=(m=r.label)!=null?m:r.id,u=0,y={labelStyle:f.labelStyle,shape:"class_box",labelText:V(d),classData:r,rx:u,ry:u,class:a,style:f.style,id:r.id,domId:r.domId,tooltip:l.db.getTooltip(r.id,n)||"",haveCallback:r.haveCallback,link:r.link,width:r.type==="group"?500:void 0,type:r.type,padding:(o=(w=p().flowchart)==null?void 0:w.padding)!=null?o:(c=p().class)==null?void 0:c.padding};t.setNode(r.id,y),n&&t.setParent(r.id,n),s.info("setNode",y)})},"addClasses"),Pt=g(function(e,t,i,l){s.info(e),e.forEach(function(n,r){var o,v,N;let a=n,f="",d={labelStyle:"",style:""},u=a.text,b=0,m={labelStyle:d.labelStyle,shape:"note",labelText:V(u),noteData:a,rx:b,ry:b,class:f,style:d.style,id:a.id,domId:a.id,tooltip:"",type:"note",padding:(N=(o=p().flowchart)==null?void 0:o.padding)!=null?N:(v=p().class)==null?void 0:v.padding};if(t.setNode(a.id,m),s.info("setNode",m),!a.class||!l.has(a.class))return;let w=i+r,c={id:`edgeNote${w}`,classes:"relation",pattern:"dotted",arrowhead:"none",startLabelRight:"",endLabelLeft:"",arrowTypeStart:"none",arrowTypeEnd:"none",style:"fill:none",labelStyle:"",curve:M(W.curve,G)};t.setEdge(a.id,a.class,c,w)})},"addNotes"),Gt=g(function(e,t){let i=p().flowchart,l=0;e.forEach(function(n){var a,f;l++;let r={classes:"relation",pattern:n.relation.lineType==1?"dashed":"solid",id:I(n.id1,n.id2,{prefix:"id",counter:l}),arrowhead:n.type==="arrow_open"?"none":"normal",startLabelRight:n.relationTitle1==="none"?"":n.relationTitle1,endLabelLeft:n.relationTitle2==="none"?"":n.relationTitle2,arrowTypeStart:q(n.relation.type1),arrowTypeEnd:q(n.relation.type2),style:"fill:none",labelStyle:"",curve:M(i==null?void 0:i.curve,G)};if(s.info(r,n),n.style!==void 0){let d=F(n.style);r.style=d.style,r.labelStyle=d.labelStyle}n.text=n.title,n.text===void 0?n.style!==void 0&&(r.arrowheadStyle="fill: #333"):(r.arrowheadStyle="fill: #333",r.labelpos="c",((f=(a=p().flowchart)==null?void 0:a.htmlLabels)!=null?f:p().htmlLabels)?(r.labelType="html",r.label='<span class="edgeLabel">'+n.text+"</span>"):(r.labelType="text",r.label=n.text.replace(P.lineBreakRegex,`
|
|
`),n.style===void 0&&(r.style=r.style||"stroke: #333; stroke-width: 1.5px;fill:none"),r.labelStyle=r.labelStyle.replace("color:","fill:"))),t.setEdge(n.id1,n.id2,r,l)})},"addRelations"),Mt=g(function(e){W=L(L({},W),e)},"setConf"),Ft=g(async function(e,t,i,l){var N,T,C,K;s.info("Drawing class - ",t);let n=(N=p().flowchart)!=null?N:p().class,r=p().securityLevel;s.info("config:",n);let a=(T=n==null?void 0:n.nodeSpacing)!=null?T:50,f=(C=n==null?void 0:n.rankSpacing)!=null?C:50,d=new R({multigraph:!0,compound:!0}).setGraph({rankdir:l.db.getDirection(),nodesep:a,ranksep:f,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}}),u=l.db.getNamespaces(),b=l.db.getClasses(),y=l.db.getRelations(),m=l.db.getNotes();s.info(y),Ot(u,d,t,l),vt(b,d,t,l),Gt(y,d),Pt(m,d,y.length+1,b);let w;r==="sandbox"&&(w=E("#i"+t));let c=r==="sandbox"?E(w.nodes()[0].contentDocument.body):E("body"),o=c.select(`[id="${t}"]`),v=c.select("#"+t+" g");if(await At(v,d,["aggregation","extension","composition","dependency","lollipop"],"classDiagram",t),j.insertTitle(o,"classTitleText",(K=n==null?void 0:n.titleTopMargin)!=null?K:5,l.db.getDiagramTitle()),Z(d,o,n==null?void 0:n.diagramPadding,n==null?void 0:n.useMaxWidth),!(n!=null&&n.htmlLabels)){let Q=r==="sandbox"?w.nodes()[0].contentDocument:document,xt=Q.querySelectorAll('[id="'+t+'"] .edgeLabel .label');for(let O of xt){let U=O.getBBox(),k=Q.createElementNS("http://www.w3.org/2000/svg","rect");k.setAttribute("rx",0),k.setAttribute("ry",0),k.setAttribute("width",U.width),k.setAttribute("height",U.height),O.insertBefore(k,O.firstChild)}}},"draw");function q(e){let t;switch(e){case 0:t="aggregation";break;case 1:t="extension";break;case 2:t="composition";break;case 3:t="dependency";break;case 4:t="lollipop";break;default:t="none"}return t}g(q,"getArrowMarker");var $t={setConf:Mt,draw:Ft},Zt={parser:it,db:$,renderer:$t,styles:nt,init:g(e=>{e.class||(e.class={}),e.class.arrowMarkerAbsolute=e.arrowMarkerAbsolute,$.clear()},"init")};export{Zt as diagram};
|