import{a as X,h as N,i as J}from"./chunk-MI6V2DPC.mjs";import{a as F,b as O}from"./chunk-LU4ULLGK.mjs";import"./chunk-2NUPJ2B5.mjs";import"./chunk-PUD22X6X.mjs";import{L as U}from"./chunk-6WX52H5W.mjs";import{e as T}from"./chunk-GO66RM32.mjs";import"./chunk-UW4DGUNY.mjs";import{I as P,M as R,a as h,g as b,m as L,ra as t,ua as W}from"./chunk-3OFI44Y5.mjs";var A={},j=h((e,n)=>{A[e]=n},"set"),K=h(e=>A[e],"get"),Y=h(()=>Object.keys(A),"keys"),Q=h(()=>Y().length,"size"),v={get:K,set:j,keys:Y,size:Q};var V=h(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"),D=h(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"),tt=h((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),d=s.node().getBBox();return e.insert("rect",":first-child").attr("x",t().state.padding).attr("y",t().state.padding).attr("width",d.width+2*t().state.padding).attr("height",d.height+2*t().state.padding).attr("rx",t().state.radius),s},"drawSimpleState"),et=h((e,n)=>{let s=h(function(l,y,w){let k=l.append("tspan").attr("x",2*t().state.padding).text(y);w||k.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,x=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(l){i||(s(x,l,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"),f=x.node().getBBox(),c=Math.max(f.width,r.width);return m.attr("x2",c+3*t().state.padding),e.insert("rect",":first-child").attr("x",t().state.padding).attr("y",t().state.padding).attr("width",c+2*t().state.padding).attr("height",f.height+g+2*t().state.padding).attr("rx",t().state.radius),e},"drawDescrState"),$=h((e,n,s)=>{let d=t().state.padding,r=2*t().state.padding,g=e.node().getBBox(),x=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),f=o.node().getBBox().width+r,c=Math.max(f,x);c===x&&(c=c+r);let l,y=e.node().getBBox();n.doc,l=i-d,f>x&&(l=(x-c)/2+d),Math.abs(i-y.x)x&&(l=i-(f-x)/2);let w=1-t().state.textHeight;return e.insert("rect",":first-child").attr("x",l).attr("y",w).attr("class",s?"alt-composit":"composit").attr("width",c).attr("height",y.height+t().state.textHeight+t().state.titleShift+1).attr("rx","0"),o.attr("x",l+d),f<=x&&o.attr("x",i+(c-r)/2-f/2+d),e.insert("rect",":first-child").attr("x",l).attr("y",t().state.titleShift-t().state.textHeight-t().state.padding).attr("width",c).attr("height",t().state.textHeight*3).attr("rx",t().state.radius),e.insert("rect",":first-child").attr("x",l).attr("y",t().state.titleShift-t().state.textHeight-t().state.padding).attr("width",c).attr("height",y.height+3+2*t().state.textHeight).attr("rx",t().state.radius),e},"addTitleAndBox"),it=h(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"),nt=h((e,n)=>{let s=t().state.forkWidth,d=t().state.forkHeight;if(n.parentId){let r=s;s=d,d=r}return e.append("rect").style("stroke","black").style("fill","black").attr("width",s).attr("height",d).attr("x",t().state.padding).attr("y",t().state.padding)},"drawForkJoinState");var at=h((e,n,s,d)=>{let r=0,g=d.append("text");g.style("text-anchor","start"),g.attr("class","noteText");let x=e.replace(/\r\n/g,"
");x=x.replace(/\n/g,"
");let i=x.split(T.lineBreakRegex),o=1.25*t().state.noteMargin;for(let m of i){let f=m.trim();if(f.length>0){let c=g.append("tspan");if(c.text(f),o===0){let l=c.node().getBBox();o+=l.height}r+=o,c.attr("x",n+t().state.noteMargin),c.attr("y",s+r+1.25*t().state.noteMargin)}}return{textWidth:g.node().getBBox().width,textHeight:r}},"_drawLongText"),rt=h((e,n)=>{n.attr("class","state-note");let s=n.append("rect").attr("x",0).attr("y",t().state.padding),d=n.append("g"),{textWidth:r,textHeight:g}=at(e,0,0,d);return s.attr("height",g+2*t().state.noteMargin),s.attr("width",r+t().state.noteMargin*2),s},"drawNote"),C=h(function(e,n){let s=n.id,d={id:s,label:n.id,width:0,height:0},r=e.append("g").attr("id",s).attr("class","stateGroup");n.type==="start"&&V(r),n.type==="end"&&it(r),(n.type==="fork"||n.type==="join")&&nt(r,n),n.type==="note"&&rt(n.note.text,r),n.type==="divider"&&D(r),n.type==="default"&&n.descriptions.length===0&&tt(r,n),n.type==="default"&&n.descriptions.length>0&&et(r,n);let g=r.node().getBBox();return d.width=g.width+2*t().state.padding,d.height=g.height+2*t().state.padding,v.set(s,d),d},"drawState"),I=0,_=h(function(e,n,s){let d=h(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=P().x(function(o){return o.x}).y(function(o){return o.y}).curve(R),x=e.append("path").attr("d",g(r)).attr("id","edge"+I).attr("class","transition"),i="";if(t().state.arrowMarkerAbsolute&&(i=window.location.protocol+"//"+window.location.host+window.location.pathname+window.location.search,i=i.replace(/\(/g,"\\("),i=i.replace(/\)/g,"\\)")),x.attr("marker-end","url("+i+"#"+d(N.relationType.DEPENDENCY)+"End)"),s.title!==void 0){let o=e.append("g").attr("class","stateLabel"),{x:m,y:f}=U.calcLabelPosition(n.points),c=T.getRows(s.title),l=0,y=[],w=0,k=0;for(let a=0;a<=c.length;a++){let u=o.append("text").attr("text-anchor","middle").text(c[a]).attr("x",m).attr("y",f+l),p=u.node().getBBox();w=Math.max(w,p.width),k=Math.min(k,p.x),b.info(p.x,m,f+l),l===0&&(l=u.node().getBBox().height,b.info("Title height",l,f)),y.push(u)}let M=l*c.length;if(c.length>1){let a=(c.length-1)*l*.5;y.forEach((u,p)=>u.attr("y",f+p*l-a)),M=l*c.length}let H=o.node().getBBox();o.insert("rect",":first-child").attr("class","box").attr("x",m-w/2-t().state.padding/2).attr("y",f-M/2-t().state.padding/2-3.5).attr("width",w+t().state.padding).attr("height",M+t().state.padding),b.info(H)}I++},"drawEdge");var S,G={},ot=h(function(){},"setConf"),st=h(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"),dt=h(function(e,n,s,d){S=t().state;let r=t().securityLevel,g;r==="sandbox"&&(g=L("#i"+n));let x=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=x.select(`[id='${n}']`);st(o);let m=d.db.getRootDoc();q(m,o,void 0,!1,x,i,d);let f=S.padding,c=o.node().getBBox(),l=c.width+f*2,y=c.height+f*2,w=l*1.75;W(o,y,w,S.useMaxWidth),o.attr("viewBox",`${c.x-S.padding} ${c.y-S.padding} `+l+" "+y)},"draw"),ct=h(e=>e?e.length*S.fontSizeFactor:1,"getLabelWidth"),q=h((e,n,s,d,r,g,x)=>{let i=new F({compound:!0,multigraph:!0}),o,m=!0;for(o=0;o{let B=p.parentElement,E=0,z=0;B&&(B.parentElement&&(E=B.parentElement.getBBox().width),z=parseInt(B.getAttribute("data-x-shift"),10),Number.isNaN(z)&&(z=0)),p.setAttribute("x1",0-z+8),p.setAttribute("x2",E-z-8)})):b.debug("No Node "+a+": "+JSON.stringify(i.node(a)))});let M=k.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))),_(n,i.edge(a),i.edge(a).relation))}),M=k.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"),Z={setConf:ot,draw:dt};var Rt={parser:X,db:N,renderer:Z,styles:J,init:e=>{e.state||(e.state={}),e.state.arrowMarkerAbsolute=e.arrowMarkerAbsolute,N.clear()}};export{Rt as diagram};