2 lines
10 KiB
JavaScript
2 lines
10 KiB
JavaScript
import{a as X,c as N,d as J}from"./chunk-LCXTWHL2.mjs";import{a as O}from"./chunk-KRXBNO2N.mjs";import{D as F}from"./chunk-W44A43WB.mjs";import"./chunk-6764PJDD.mjs";import"./chunk-ZXARS5L4.mjs";import"./chunk-VU6ZFW4Y.mjs";import"./chunk-7J6CGLKN.mjs";import"./chunk-KGFNY3KK.mjs";import"./chunk-5IMINLNL.mjs";import"./chunk-T2UQINTJ.mjs";import"./chunk-5VCL7Z4A.mjs";import"./chunk-UY5QBCOK.mjs";import"./chunk-INKRHTLW.mjs";import{p as C}from"./chunk-QA3QBVWF.mjs";import"./chunk-KNLZD3CH.mjs";import{B as P,G as z,O as R,_ as t}from"./chunk-67TQ5CYL.mjs";import{H as W,L as U,b,h as L}from"./chunk-7W6UQGC5.mjs";import{a as f}from"./chunk-AQ6EADP3.mjs";var j=f(e=>e.append("circle").attr("class","start-state").attr("r",t().state.sizeUnit).attr("cx",t().state.padding+t().state.sizeUnit).attr("cy",t().state.padding+t().state.sizeUnit),"drawStartState"),q=f(e=>e.append("line").style("stroke","grey").style("stroke-dasharray","3").attr("x1",t().state.textHeight).attr("class","divider").attr("x2",t().state.textHeight*2).attr("y1",0).attr("y2",0),"drawDivider"),Z=f((e,n)=>{let s=e.append("text").attr("x",2*t().state.padding).attr("y",t().state.textHeight+2*t().state.padding).attr("font-size",t().state.fontSize).attr("class","state-title").text(n.id),c=s.node().getBBox();return e.insert("rect",":first-child").attr("x",t().state.padding).attr("y",t().state.padding).attr("width",c.width+2*t().state.padding).attr("height",c.height+2*t().state.padding).attr("rx",t().state.radius),s},"drawSimpleState"),K=f((e,n)=>{let s=f(function(d,w,y){let E=d.append("tspan").attr("x",2*t().state.padding).text(w);y||E.attr("dy",t().state.textHeight)},"addTspan"),r=e.append("text").attr("x",2*t().state.padding).attr("y",t().state.textHeight+1.3*t().state.padding).attr("font-size",t().state.fontSize).attr("class","state-title").text(n.descriptions[0]).node().getBBox(),g=r.height,h=e.append("text").attr("x",t().state.padding).attr("y",g+t().state.padding*.4+t().state.dividerMargin+t().state.textHeight).attr("class","state-description"),i=!0,o=!0;n.descriptions.forEach(function(d){i||(s(h,d,o),o=!1),i=!1});let m=e.append("line").attr("x1",t().state.padding).attr("y1",t().state.padding+g+t().state.dividerMargin/2).attr("y2",t().state.padding+g+t().state.dividerMargin/2).attr("class","descr-divider"),x=h.node().getBBox(),p=Math.max(x.width,r.width);return m.attr("x2",p+3*t().state.padding),e.insert("rect",":first-child").attr("x",t().state.padding).attr("y",t().state.padding).attr("width",p+2*t().state.padding).attr("height",x.height+g+2*t().state.padding).attr("rx",t().state.radius),e},"drawDescrState"),v=f((e,n,s)=>{let c=t().state.padding,r=2*t().state.padding,g=e.node().getBBox(),h=g.width,i=g.x,o=e.append("text").attr("x",0).attr("y",t().state.titleShift).attr("font-size",t().state.fontSize).attr("class","state-title").text(n.id),x=o.node().getBBox().width+r,p=Math.max(x,h);p===h&&(p=p+r);let d,w=e.node().getBBox();n.doc,d=i-c,x>h&&(d=(h-p)/2+c),Math.abs(i-w.x)<c&&x>h&&(d=i-(x-h)/2);let y=1-t().state.textHeight;return e.insert("rect",":first-child").attr("x",d).attr("y",y).attr("class",s?"alt-composit":"composit").attr("width",p).attr("height",w.height+t().state.textHeight+t().state.titleShift+1).attr("rx","0"),o.attr("x",d+c),x<=h&&o.attr("x",i+(p-r)/2-x/2+c),e.insert("rect",":first-child").attr("x",d).attr("y",t().state.titleShift-t().state.textHeight-t().state.padding).attr("width",p).attr("height",t().state.textHeight*3).attr("rx",t().state.radius),e.insert("rect",":first-child").attr("x",d).attr("y",t().state.titleShift-t().state.textHeight-t().state.padding).attr("width",p).attr("height",w.height+3+2*t().state.textHeight).attr("rx",t().state.radius),e},"addTitleAndBox"),Q=f(e=>(e.append("circle").attr("class","end-state-outer").attr("r",t().state.sizeUnit+t().state.miniPadding).attr("cx",t().state.padding+t().state.sizeUnit+t().state.miniPadding).attr("cy",t().state.padding+t().state.sizeUnit+t().state.miniPadding),e.append("circle").attr("class","end-state-inner").attr("r",t().state.sizeUnit).attr("cx",t().state.padding+t().state.sizeUnit+2).attr("cy",t().state.padding+t().state.sizeUnit+2)),"drawEndState"),V=f((e,n)=>{let s=t().state.forkWidth,c=t().state.forkHeight;if(n.parentId){let r=s;s=c,c=r}return e.append("rect").style("stroke","black").style("fill","black").attr("width",s).attr("height",c).attr("x",t().state.padding).attr("y",t().state.padding)},"drawForkJoinState");var D=f((e,n,s,c)=>{let r=0,g=c.append("text");g.style("text-anchor","start"),g.attr("class","noteText");let h=e.replace(/\r\n/g,"<br/>");h=h.replace(/\n/g,"<br/>");let i=h.split(z.lineBreakRegex),o=1.25*t().state.noteMargin;for(let m of i){let x=m.trim();if(x.length>0){let p=g.append("tspan");if(p.text(x),o===0){let d=p.node().getBBox();o+=d.height}r+=o,p.attr("x",n+t().state.noteMargin),p.attr("y",s+r+1.25*t().state.noteMargin)}}return{textWidth:g.node().getBBox().width,textHeight:r}},"_drawLongText"),tt=f((e,n)=>{n.attr("class","state-note");let s=n.append("rect").attr("x",0).attr("y",t().state.padding),c=n.append("g"),{textWidth:r,textHeight:g}=D(e,0,0,c);return s.attr("height",g+2*t().state.noteMargin),s.attr("width",r+t().state.noteMargin*2),s},"drawNote"),A=f(function(e,n){let s=n.id,c={id:s,label:n.id,width:0,height:0},r=e.append("g").attr("id",s).attr("class","stateGroup");n.type==="start"&&j(r),n.type==="end"&&Q(r),(n.type==="fork"||n.type==="join")&&V(r,n),n.type==="note"&&tt(n.note.text,r),n.type==="divider"&&q(r),n.type==="default"&&n.descriptions.length===0&&Z(r,n),n.type==="default"&&n.descriptions.length>0&&K(r,n);let g=r.node().getBBox();return c.width=g.width+2*t().state.padding,c.height=g.height+2*t().state.padding,c},"drawState"),Y=0,I=f(function(e,n,s){let c=f(function(o){switch(o){case N.relationType.AGGREGATION:return"aggregation";case N.relationType.EXTENSION:return"extension";case N.relationType.COMPOSITION:return"composition";case N.relationType.DEPENDENCY:return"dependency"}},"getRelationType");n.points=n.points.filter(o=>!Number.isNaN(o.y));let r=n.points,g=W().x(function(o){return o.x}).y(function(o){return o.y}).curve(U),h=e.append("path").attr("d",g(r)).attr("id","edge"+Y).attr("class","transition"),i="";if(t().state.arrowMarkerAbsolute&&(i=P(!0)),h.attr("marker-end","url("+i+"#"+c(N.relationType.DEPENDENCY)+"End)"),s.title!==void 0){let o=e.append("g").attr("class","stateLabel"),{x:m,y:x}=C.calcLabelPosition(n.points),p=z.getRows(s.title),d=0,w=[],y=0,E=0;for(let a=0;a<=p.length;a++){let u=o.append("text").attr("text-anchor","middle").text(p[a]).attr("x",m).attr("y",x+d),l=u.node().getBBox();y=Math.max(y,l.width),E=Math.min(E,l.x),b.info(l.x,m,x+d),d===0&&(d=u.node().getBBox().height,b.info("Title height",d,x)),w.push(u)}let M=d*p.length;if(p.length>1){let a=(p.length-1)*d*.5;w.forEach((u,l)=>u.attr("y",x+l*d-a)),M=d*p.length}let H=o.node().getBBox();o.insert("rect",":first-child").attr("class","box").attr("x",m-y/2-t().state.padding/2).attr("y",x-M/2-t().state.padding/2-3.5).attr("width",y+t().state.padding).attr("height",M+t().state.padding),b.info(H)}Y++},"drawEdge");var S,G={},et=f(function(){},"setConf"),it=f(function(e){e.append("defs").append("marker").attr("id","dependencyEnd").attr("refX",19).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 19,7 L9,13 L14,7 L9,1 Z")},"insertMarkers"),nt=f(function(e,n,s,c){S=t().state;let r=t().securityLevel,g;r==="sandbox"&&(g=L("#i"+n));let h=r==="sandbox"?L(g.nodes()[0].contentDocument.body):L("body"),i=r==="sandbox"?g.nodes()[0].contentDocument:document;b.debug("Rendering diagram "+e);let o=h.select(`[id='${n}']`);it(o);let m=c.db.getRootDoc(),x=o.append("g").attr("id",n+"-root");$(m,x,void 0,!1,h,i,c);let p=S.padding,d=o.node().getBBox(),w=d.width+p*2,y=d.height+p*2,E=w*1.75;R(o,y,E,S.useMaxWidth),o.attr("viewBox",`${d.x-S.padding} ${d.y-S.padding} `+w+" "+y)},"draw"),at=f(e=>e?e.length*S.fontSizeFactor:1,"getLabelWidth"),$=f((e,n,s,c,r,g,h)=>{let i=new F({compound:!0,multigraph:!0}),o,m=!0;for(o=0;o<e.length;o++)if(e[o].stmt==="relation"){m=!1;break}s?i.setGraph({rankdir:"LR",multigraph:!0,compound:!0,ranker:"tight-tree",ranksep:m?1:S.edgeLengthFactor,nodeSep:m?1:50,isMultiGraph:!0}):i.setGraph({rankdir:"TB",multigraph:!0,compound:!0,ranksep:m?1:S.edgeLengthFactor,nodeSep:m?1:50,ranker:"tight-tree",isMultiGraph:!0}),i.setDefaultEdgeLabel(function(){return{}});let x=h.db.getStates(),p=h.db.getRelations(),d=Object.keys(x),w=!0;for(let a of d){let u=x[a];s&&(u.parentId=s);let l;if(u.doc){let B=n.append("g").attr("id",u.id).attr("class","stateGroup");if(l=$(u.doc,B,u.id,!c,r,g,h),w){B=v(B,u,c);let k=B.node().getBBox();l.width=k.width,l.height=k.height+S.padding/2,G[u.id]={y:S.compositTitleSize}}else{let k=B.node().getBBox();l.width=k.width,l.height=k.height}}else l=A(n,u,i);if(u.note){let B={descriptions:[],id:u.id+"-note",note:u.note,type:"note"},k=A(n,B,i);u.note.position==="left of"?(i.setNode(l.id+"-note",k),i.setNode(l.id,l)):(i.setNode(l.id,l),i.setNode(l.id+"-note",k)),i.setParent(l.id,l.id+"-group"),i.setParent(l.id+"-note",l.id+"-group")}else i.setNode(l.id,l)}b.debug("Count=",i.nodeCount(),i);let y=0;p.forEach(function(a){y++,b.debug("Setting edge",a),i.setEdge(a.id1,a.id2,{relation:a,width:at(a.title),height:S.labelHeight*z.getRows(a.title).length,labelpos:"c"},"id"+y)}),O(i),b.debug("Graph after layout",i.nodes());let E=n.node();i.nodes().forEach(function(a){a!==void 0&&i.node(a)!==void 0?(b.warn("Node "+a+": "+JSON.stringify(i.node(a))),r.select("#"+E.id+" #"+a).attr("transform","translate("+(i.node(a).x-i.node(a).width/2)+","+(i.node(a).y+(G[a]?G[a].y:0)-i.node(a).height/2)+" )"),r.select("#"+E.id+" #"+a).attr("data-x-shift",i.node(a).x-i.node(a).width/2),g.querySelectorAll("#"+E.id+" #"+a+" .divider").forEach(l=>{let B=l.parentElement,k=0,T=0;B&&(B.parentElement&&(k=B.parentElement.getBBox().width),T=parseInt(B.getAttribute("data-x-shift"),10),Number.isNaN(T)&&(T=0)),l.setAttribute("x1",0-T+8),l.setAttribute("x2",k-T-8)})):b.debug("No Node "+a+": "+JSON.stringify(i.node(a)))});let M=E.getBBox();i.edges().forEach(function(a){a!==void 0&&i.edge(a)!==void 0&&(b.debug("Edge "+a.v+" -> "+a.w+": "+JSON.stringify(i.edge(a))),I(n,i.edge(a),i.edge(a).relation))}),M=E.getBBox();let H={id:s||"root",label:s||"root",width:0,height:0};return H.width=M.width+2*S.padding,H.height=M.height+2*S.padding,b.debug("Doc rendered",H,i),H},"renderDoc"),_={setConf:et,draw:nt};var Ht={parser:X,get db(){return new N(1)},renderer:_,styles:J,init:f(e=>{e.state||(e.state={}),e.state.arrowMarkerAbsolute=e.arrowMarkerAbsolute},"init")};export{Ht as diagram};
|