import{g as G,B as U,_ as v}from"./chunk-AI4T2ZLM-CoR2OeoK.js";import{f as O}from"./chunk-CCU7O4O5-C_HAswox.js";import{m as P}from"./chunk-EYG76IYJ-UAgStWzX.js";import"./chunk-6EQESGSB-BIUamy9L.js";import"./chunk-T244DUNM-Cf7yFFbm.js";import{m as y,a as t,i as H,p as k,W as R,h as T,aW as W,b1 as I,a_ as C,d as $}from"./mermaid.esm.min-RL45CjrO.js";import"./chunk-OMTJKCYW-DMe1YJoF.js";import"./app-BwvsBlHw.js";var _=y(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"),F=y(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"),J=y((e,i)=>{let g=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(i.id),s=g.node().getBBox();return e.insert("rect",":first-child").attr("x",t().state.padding).attr("y",t().state.padding).attr("width",s.width+2*t().state.padding).attr("height",s.height+2*t().state.padding).attr("rx",t().state.radius),g},"drawSimpleState"),Y=y((e,i)=>{let g=y(function(o,u,w){let B=o.append("tspan").attr("x",2*t().state.padding).text(u);w||B.attr("dy",t().state.textHeight)},"addTspan"),s=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(i.descriptions[0]).node().getBBox(),d=s.height,h=e.append("text").attr("x",t().state.padding).attr("y",d+t().state.padding*.4+t().state.dividerMargin+t().state.textHeight).attr("class","state-description"),c=!0,a=!0;i.descriptions.forEach(function(o){c||(g(h,o,a),a=!1),c=!1});let n=e.append("line").attr("x1",t().state.padding).attr("y1",t().state.padding+d+t().state.dividerMargin/2).attr("y2",t().state.padding+d+t().state.dividerMargin/2).attr("class","descr-divider"),x=h.node().getBBox(),l=Math.max(x.width,s.width);return n.attr("x2",l+3*t().state.padding),e.insert("rect",":first-child").attr("x",t().state.padding).attr("y",t().state.padding).attr("width",l+2*t().state.padding).attr("height",x.height+d+2*t().state.padding).attr("rx",t().state.radius),e},"drawDescrState"),j=y((e,i,g)=>{let s=t().state.padding,d=2*t().state.padding,h=e.node().getBBox(),c=h.width,a=h.x,n=e.append("text").attr("x",0).attr("y",t().state.titleShift).attr("font-size",t().state.fontSize).attr("class","state-title").text(i.id),x=n.node().getBBox().width+d,l=Math.max(x,c);l===c&&(l=l+d);let o,u=e.node().getBBox();i.doc,o=a-s,x>c&&(o=(c-l)/2+s),Math.abs(a-u.x)c&&(o=a-(x-c)/2);let w=1-t().state.textHeight;return e.insert("rect",":first-child").attr("x",o).attr("y",w).attr("class",g?"alt-composit":"composit").attr("width",l).attr("height",u.height+t().state.textHeight+t().state.titleShift+1).attr("rx","0"),n.attr("x",o+s),x<=c&&n.attr("x",a+(l-d)/2-x/2+s),e.insert("rect",":first-child").attr("x",o).attr("y",t().state.titleShift-t().state.textHeight-t().state.padding).attr("width",l).attr("height",t().state.textHeight*3).attr("rx",t().state.radius),e.insert("rect",":first-child").attr("x",o).attr("y",t().state.titleShift-t().state.textHeight-t().state.padding).attr("width",l).attr("height",u.height+3+2*t().state.textHeight).attr("rx",t().state.radius),e},"addTitleAndBox"),q=y(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"),X=y((e,i)=>{let g=t().state.forkWidth,s=t().state.forkHeight;if(i.parentId){let d=g;g=s,s=d}return e.append("rect").style("stroke","black").style("fill","black").attr("width",g).attr("height",s).attr("x",t().state.padding).attr("y",t().state.padding)},"drawForkJoinState"),Z=y((e,i,g,s)=>{let d=0,h=s.append("text");h.style("text-anchor","start"),h.attr("class","noteText");let c=e.replace(/\r\n/g,"
");c=c.replace(/\n/g,"
");let a=c.split(T.lineBreakRegex),n=1.25*t().state.noteMargin;for(let x of a){let l=x.trim();if(l.length>0){let o=h.append("tspan");if(o.text(l),n===0){let u=o.node().getBBox();n+=u.height}d+=n,o.attr("x",i+t().state.noteMargin),o.attr("y",g+d+1.25*t().state.noteMargin)}}return{textWidth:h.node().getBBox().width,textHeight:d}},"_drawLongText"),K=y((e,i)=>{i.attr("class","state-note");let g=i.append("rect").attr("x",0).attr("y",t().state.padding),s=i.append("g"),{textWidth:d,textHeight:h}=Z(e,0,0,s);return g.attr("height",h+2*t().state.noteMargin),g.attr("width",d+t().state.noteMargin*2),g},"drawNote"),A=y(function(e,i){let g=i.id,s={id:g,label:i.id,width:0,height:0},d=e.append("g").attr("id",g).attr("class","stateGroup");i.type==="start"&&_(d),i.type==="end"&&q(d),(i.type==="fork"||i.type==="join")&&X(d,i),i.type==="note"&&K(i.note.text,d),i.type==="divider"&&F(d),i.type==="default"&&i.descriptions.length===0&&J(d,i),i.type==="default"&&i.descriptions.length>0&&Y(d,i);let h=d.node().getBBox();return s.width=h.width+2*t().state.padding,s.height=h.height+2*t().state.padding,s},"drawState"),D=0,Q=y(function(e,i,g){let s=y(function(n){switch(n){case v.relationType.AGGREGATION:return"aggregation";case v.relationType.EXTENSION:return"extension";case v.relationType.COMPOSITION:return"composition";case v.relationType.DEPENDENCY:return"dependency"}},"getRelationType");i.points=i.points.filter(n=>!Number.isNaN(n.y));let d=i.points,h=W().x(function(n){return n.x}).y(function(n){return n.y}).curve(I),c=e.append("path").attr("d",h(d)).attr("id","edge"+D).attr("class","transition"),a="";if(t().state.arrowMarkerAbsolute&&(a=C(!0)),c.attr("marker-end","url("+a+"#"+s(v.relationType.DEPENDENCY)+"End)"),g.title!==void 0){let n=e.append("g").attr("class","stateLabel"),{x,y:l}=$.calcLabelPosition(i.points),o=T.getRows(g.title),u=0,w=[],B=0,S=0;for(let r=0;r<=o.length;r++){let f=n.append("text").attr("text-anchor","middle").text(o[r]).attr("x",x).attr("y",l+u),p=f.node().getBBox();B=Math.max(B,p.width),S=Math.min(S,p.x),k.info(p.x,x,l+u),u===0&&(u=f.node().getBBox().height,k.info("Title height",u,l)),w.push(f)}let N=u*o.length;if(o.length>1){let r=(o.length-1)*u*.5;w.forEach((f,p)=>f.attr("y",l+p*u-r)),N=u*o.length}let M=n.node().getBBox();n.insert("rect",":first-child").attr("class","box").attr("x",x-B/2-t().state.padding/2).attr("y",l-N/2-t().state.padding/2-3.5).attr("width",B+t().state.padding).attr("height",N+t().state.padding),k.info(M)}D++},"drawEdge"),m,z={},V=y(function(){},"setConf"),tt=y(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"),et=y(function(e,i,g,s){m=t().state;let d=t().securityLevel,h;d==="sandbox"&&(h=H("#i"+i));let c=d==="sandbox"?H(h.nodes()[0].contentDocument.body):H("body"),a=d==="sandbox"?h.nodes()[0].contentDocument:document;k.debug("Rendering diagram "+e);let n=c.select(`[id='${i}']`);tt(n);let x=s.db.getRootDoc();L(x,n,void 0,!1,c,a,s);let l=m.padding,o=n.node().getBBox(),u=o.width+l*2,w=o.height+l*2,B=u*1.75;R(n,w,B,m.useMaxWidth),n.attr("viewBox",`${o.x-m.padding} ${o.y-m.padding} `+u+" "+w)},"draw"),at=y(e=>e?e.length*m.fontSizeFactor:1,"getLabelWidth"),L=y((e,i,g,s,d,h,c)=>{let a=new P({compound:!0,multigraph:!0}),n,x=!0;for(n=0;n{let p=f.parentElement,E=0,b=0;p&&(p.parentElement&&(E=p.parentElement.getBBox().width),b=parseInt(p.getAttribute("data-x-shift"),10),Number.isNaN(b)&&(b=0)),f.setAttribute("x1",0-b+8),f.setAttribute("x2",E-b-8)})):k.debug("No Node "+r+": "+JSON.stringify(a.node(r)))});let N=S.getBBox();a.edges().forEach(function(r){r!==void 0&&a.edge(r)!==void 0&&(k.debug("Edge "+r.v+" -> "+r.w+": "+JSON.stringify(a.edge(r))),Q(i,a.edge(r),a.edge(r).relation))}),N=S.getBBox();let M={id:g||"root",label:g||"root",width:0,height:0};return M.width=N.width+2*m.padding,M.height=N.height+2*m.padding,k.debug("Doc rendered",M,a),M},"renderDoc"),it={setConf:V,draw:et},ht={parser:U,get db(){return new v(1)},renderer:it,styles:G,init:y(e=>{e.state||(e.state={}),e.state.arrowMarkerAbsolute=e.arrowMarkerAbsolute},"init")};export{ht as diagram};