import{a as G,b as S,c as I}from"./chunk-ECCGSHQT.js";import{a as W}from"./chunk-XM6WGYDH.js";import{A}from"./chunk-UPYRJHJI.js";import{G as _,Ga as y,I as C,J as R,Ka as O,ab as T,b as J,c as Z,db as P,h as E,nb as v}from"./chunk-VNKGKUEF.js";import{h as N}from"./chunk-3NXJ7VWC.js";var at=N(J(),1),it=N(Z(),1),nt=N(R(),1);var X=0,F=function(i,r,t,o,p){let g=function(e){switch(e){case p.db.relationType.AGGREGATION:return"aggregation";case p.db.relationType.EXTENSION:return"extension";case p.db.relationType.COMPOSITION:return"composition";case p.db.relationType.DEPENDENCY:return"dependency";case p.db.relationType.LOLLIPOP:return"lollipop"}};r.points=r.points.filter(e=>!Number.isNaN(e.y));let s=r.points,c=_().x(function(e){return e.x}).y(function(e){return e.y}).curve(C),n=i.append("path").attr("d",c(s)).attr("id","edge"+X).attr("class","relation"),a="";o.arrowMarkerAbsolute&&(a=window.location.protocol+"//"+window.location.host+window.location.pathname+window.location.search,a=a.replace(/\(/g,"\\("),a=a.replace(/\)/g,"\\)")),t.relation.lineType==1&&n.attr("class","relation dashed-line"),t.relation.lineType==10&&n.attr("class","relation dotted-line"),t.relation.type1!=="none"&&n.attr("marker-start","url("+a+"#"+g(t.relation.type1)+"Start)"),t.relation.type2!=="none"&&n.attr("marker-end","url("+a+"#"+g(t.relation.type2)+"End)");let f,h,x=r.points.length,b=T.calcLabelPosition(r.points);f=b.x,h=b.y;let u,m,w,k;if(x%2!==0&&x>1){let e=T.calcCardinalityPosition(t.relation.type1!=="none",r.points,r.points[0]),d=T.calcCardinalityPosition(t.relation.type2!=="none",r.points,r.points[x-1]);y.debug("cardinality_1_point "+JSON.stringify(e)),y.debug("cardinality_2_point "+JSON.stringify(d)),u=e.x,m=e.y,w=d.x,k=d.y}if(t.title!==void 0){let e=i.append("g").attr("class","classLabel"),d=e.append("text").attr("class","label").attr("x",f).attr("y",h).attr("fill","red").attr("text-anchor","middle").text(t.title);window.label=d;let l=d.node().getBBox();e.insert("rect",":first-child").attr("class","box").attr("x",l.x-o.padding/2).attr("y",l.y-o.padding/2).attr("width",l.width+o.padding).attr("height",l.height+o.padding)}y.info("Rendering relation "+JSON.stringify(t)),t.relationTitle1!==void 0&&t.relationTitle1!=="none"&&i.append("g").attr("class","cardinality").append("text").attr("class","type1").attr("x",u).attr("y",m).attr("fill","black").attr("font-size","6").text(t.relationTitle1),t.relationTitle2!==void 0&&t.relationTitle2!=="none"&&i.append("g").attr("class","cardinality").append("text").attr("class","type2").attr("x",w).attr("y",k).attr("fill","black").attr("font-size","6").text(t.relationTitle2),X++},U=function(i,r,t,o){y.debug("Rendering class ",r,t);let p=r.id,g={id:p,label:r.id,width:0,height:0},s=i.append("g").attr("id",o.db.lookUpDomId(p)).attr("class","classGroup"),c;r.link?c=s.append("svg:a").attr("xlink:href",r.link).attr("target",r.linkTarget).append("text").attr("y",t.textHeight+t.padding).attr("x",0):c=s.append("text").attr("y",t.textHeight+t.padding).attr("x",0);let n=!0;r.annotations.forEach(function(d){let l=c.append("tspan").text("\xAB"+d+"\xBB");n||l.attr("dy",t.textHeight),n=!1});let a=$(r),f=c.append("tspan").text(a).attr("class","title");n||f.attr("dy",t.textHeight);let h=c.node().getBBox().height,x,b,u;if(r.members.length>0){x=s.append("line").attr("x1",0).attr("y1",t.padding+h+t.dividerMargin/2).attr("y2",t.padding+h+t.dividerMargin/2);let d=s.append("text").attr("x",t.padding).attr("y",h+t.dividerMargin+t.textHeight).attr("fill","white").attr("class","classText");n=!0,r.members.forEach(function(l){Y(d,l,n,t),n=!1}),b=d.node().getBBox()}if(r.methods.length>0){u=s.append("line").attr("x1",0).attr("y1",t.padding+h+t.dividerMargin+b.height).attr("y2",t.padding+h+t.dividerMargin+b.height);let d=s.append("text").attr("x",t.padding).attr("y",h+2*t.dividerMargin+b.height+t.textHeight).attr("fill","white").attr("class","classText");n=!0,r.methods.forEach(function(l){Y(d,l,n,t),n=!1})}let m=s.node().getBBox();var w=" ";r.cssClasses.length>0&&(w=w+r.cssClasses.join(" "));let e=s.insert("rect",":first-child").attr("x",0).attr("y",0).attr("width",m.width+2*t.padding).attr("height",m.height+t.padding+.5*t.dividerMargin).attr("class",w).node().getBBox().width;return c.node().childNodes.forEach(function(d){d.setAttribute("x",(e-d.getBBox().width)/2)}),r.tooltip&&c.insert("title").text(r.tooltip),x&&x.attr("x2",e),u&&u.attr("x2",e),g.width=e,g.height=m.height+t.padding+.5*t.dividerMargin,g},$=function(i){let r=i.id;return i.type&&(r+="<"+O(i.type)+">"),r},z=function(i,r,t,o){y.debug("Rendering note ",r,t);let p=r.id,g={id:p,text:r.text,width:0,height:0},s=i.append("g").attr("id",p).attr("class","classGroup"),c=s.append("text").attr("y",t.textHeight+t.padding).attr("x",0),n=JSON.parse(`"${r.text}"`).split(` `);n.forEach(function(x){y.debug(`Adding line: ${x}`),c.append("tspan").text(x).attr("class","title").attr("dy",t.textHeight)});let a=s.node().getBBox(),h=s.insert("rect",":first-child").attr("x",0).attr("y",0).attr("width",a.width+2*t.padding).attr("height",a.height+n.length*t.textHeight+t.padding+.5*t.dividerMargin).node().getBBox().width;return c.node().childNodes.forEach(function(x){x.setAttribute("x",(h-x.getBBox().width)/2)}),g.width=h,g.height=a.height+n.length*t.textHeight+t.padding+.5*t.dividerMargin,g},Y=function(i,r,t,o){let{displayText:p,cssStyle:g}=r.getDisplayDetails(),s=i.append("tspan").attr("x",o.padding).text(p);g!==""&&s.attr("style",r.cssStyle),t||s.attr("dy",o.textHeight)},H={getClassTitleString:$,drawClass:U,drawEdge:F,drawNote:z},M={},B=20,L=function(i){let r=Object.entries(M).find(t=>t[1].label===i);if(r)return r[0]},V=function(i){i.append("defs").append("marker").attr("id","extensionStart").attr("class","extension").attr("refX",0).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("path").attr("d","M 1,7 L18,13 V 1 Z"),i.append("defs").append("marker").attr("id","extensionEnd").attr("refX",19).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 1,1 V 13 L18,7 Z"),i.append("defs").append("marker").attr("id","compositionStart").attr("class","extension").attr("refX",0).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L1,7 L9,1 Z"),i.append("defs").append("marker").attr("id","compositionEnd").attr("refX",19).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L1,7 L9,1 Z"),i.append("defs").append("marker").attr("id","aggregationStart").attr("class","extension").attr("refX",0).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L1,7 L9,1 Z"),i.append("defs").append("marker").attr("id","aggregationEnd").attr("refX",19).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L1,7 L9,1 Z"),i.append("defs").append("marker").attr("id","dependencyStart").attr("class","extension").attr("refX",0).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("path").attr("d","M 5,7 L9,13 L1,7 L9,1 Z"),i.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 18,7 L9,13 L14,7 L9,1 Z")},q=function(i,r,t,o){let p=v().class;M={},y.info("Rendering diagram "+i);let g=v().securityLevel,s;g==="sandbox"&&(s=E("#i"+r));let c=g==="sandbox"?E(s.nodes()[0].contentDocument.body):E("body"),n=c.select(`[id='${r}']`);V(n);let a=new A({multigraph:!0});a.setGraph({isMultiGraph:!0}),a.setDefaultEdgeLabel(function(){return{}});let f=o.db.getClasses(),h=Object.keys(f);for(let e of h){let d=f[e],l=H.drawClass(n,d,p,o);M[l.id]=l,a.setNode(l.id,l),y.info("Org height: "+l.height)}o.db.getRelations().forEach(function(e){y.info("tjoho"+L(e.id1)+L(e.id2)+JSON.stringify(e)),a.setEdge(L(e.id1),L(e.id2),{relation:e},e.title||"DEFAULT")}),o.db.getNotes().forEach(function(e){y.debug(`Adding note: ${JSON.stringify(e)}`);let d=H.drawNote(n,e,p,o);M[d.id]=d,a.setNode(d.id,d),e.class&&e.class in f&&a.setEdge(e.id,L(e.class),{relation:{id1:e.id,id2:e.class,relation:{type1:"none",type2:"none",lineType:10}}},"DEFAULT")}),W(a),a.nodes().forEach(function(e){e!==void 0&&a.node(e)!==void 0&&(y.debug("Node "+e+": "+JSON.stringify(a.node(e))),c.select("#"+(o.db.lookUpDomId(e)||e)).attr("transform","translate("+(a.node(e).x-a.node(e).width/2)+","+(a.node(e).y-a.node(e).height/2)+" )"))}),a.edges().forEach(function(e){e!==void 0&&a.edge(e)!==void 0&&(y.debug("Edge "+e.v+" -> "+e.w+": "+JSON.stringify(a.edge(e))),H.drawEdge(n,a.edge(e),a.edge(e).relation,p,o))});let u=n.node().getBBox(),m=u.width+B*2,w=u.height+B*2;P(n,w,m,p.useMaxWidth);let k=`${u.x-B} ${u.y-B} ${m} ${w}`;y.debug(`viewBox ${k}`),n.attr("viewBox",k)},K={draw:q},dt={parser:G,db:S,renderer:K,styles:I,init:i=>{i.class||(i.class={}),i.class.arrowMarkerAbsolute=i.arrowMarkerAbsolute,S.clear()}};export{dt as diagram};