| 36 | `)}}}}})))})},"drawEdges"),Ir=ct(function(E,w,N){return Zt(this,null,function*(){let o=N.getConfigField("padding")*.75,a=N.getConfigField("fontSize"),n=N.getConfigField("iconSize")/2;yield Promise.all(w.nodes().map(c=>Zt(null,null,function*(){let t=ie(c);if(t.type==="group"){let{h:g,w:i,x1:r,y1:h}=c.boundingBox(),f=E.append("rect");f.attr("id",`group-${t.id}`).attr("x",r+n).attr("y",h+n).attr("width",i).attr("height",g).attr("class","node-bkg");let l=E.append("g"),L=r,y=h;if(t.icon){let p=l.append("g");p.html(`<g>${yield ce(t.icon,{height:o,width:o,fallbackPrefix:se.prefix})}</g>`),p.attr("transform","translate("+(L+n+1)+", "+(y+n+1)+")"),L+=o,y+=a/2-1-2}if(t.label){let p=l.append("g");yield ge(p,t.label,{useHtmlLabels:!1,width:i,classes:"architecture-service-label"},fe()),p.attr("dy","1em").attr("alignment-baseline","middle").attr("dominant-baseline","start").attr("text-anchor","start"),p.attr("transform","translate("+(L+n+4)+", "+(y+n+2)+")")}N.setElementForId(t.id,f)}})))})},"drawGroups"),Rr=ct(function(E,w,N){return Zt(this,null,function*(){let u=fe();for(let o of N){let a=w.append("g"),e=E.getConfigField("iconSize");if(o.title){let g=a.append("g");yield ge(g,o.title,{useHtmlLabels:!1,width:e*1.5,classes:"architecture-service-label"},u),g.attr("dy","1em").attr("alignment-baseline","middle").attr("dominant-baseline","middle").attr("text-anchor","middle"),g.attr("transform","translate("+e/2+", "+e+")")}let n=a.append("g");if(o.icon)n.html(`<g>${yield ce(o.icon,{height:e,width:e,fallbackPrefix:se.prefix})}</g>`);else if(o.iconText){n.html(`<g>${yield ce("blank",{height:e,width:e,fallbackPrefix:se.prefix})}</g>`);let r=n.append("g").append("foreignObject").attr("width",e).attr("height",e).append("div").attr("class","node-icon-text").attr("style",`height: ${e}px;`).append("div").html(Ue(o.iconText,u)),h=parseInt(window.getComputedStyle(r.node(),null).getPropertyValue("font-size").replace(/\D/g,""))??16;r.attr("style",`-webkit-line-clamp: ${Math.floor((e-2)/h)};`)}else n.append("path").attr("class","node-bkg").attr("id","node-"+o.id).attr("d",`M0,${e} V5 Q0,0 5,0 H${e-5} Q${e},0 ${e},5 V${e} Z`);a.attr("id",`service-${o.id}`).attr("class","architecture-service");let{width:c,height:t}=a.node().getBBox();o.width=c,o.height=t,E.setElementForId(o.id,a)}return 0})},"drawServices"),Sr=ct(function(E,w,N){N.forEach(u=>{let o=w.append("g"),a=E.getConfigField("iconSize");o.append("g").append("rect").attr("id","node-"+u.id).attr("fill-opacity","0").attr("width",a).attr("height",a),o.attr("class","architecture-junction");let{width:n,height:c}=o._groups[0][0].getBBox();o.width=n,o.height=c,E.setElementForId(u.id,o)})},"drawJunctions");Je([{name:se.prefix,icons:se}]);Ne.use(or.default);function sr(E,w,N){E.forEach(u=>{w.add({group:"nodes",data:{type:"service",id:u.id,icon:u.icon,label:u.title,parent:u.in,width:N.getConfigField("iconSize"),height:N.getConfigField("iconSize")},classes:"node-service"})})}ct(sr,"addServices");function hr(E,w,N){E.forEach(u=>{w.add({group:"nodes",data:{type:"junction",id:u.id,parent:u.in,width:N.getConfigField("iconSize"),height:N.getConfigField("iconSize")},classes:"node-junction"})})}ct(hr,"addJunctions");function lr(E,w){w.nodes().map(N=>{let u=ie(N);if(u.type==="group")return;u.x=N.position().x,u.y=N.position().y,E.getElementById(u.id).attr("transform","translate("+(u.x||0)+","+(u.y||0)+")")})}ct(lr,"positionNodes");function fr(E,w){E.forEach(N=>{w.add({group:"nodes",data:{type:"group",id:N.id,icon:N.icon,label:N.title,parent:N.in},classes:"node-group"})})}ct(fr,"addGroups");function cr(E,w){E.forEach(N=>{let{lhsId:u,rhsId:o,lhsInto:a,lhsGroup:e,rhsInto:n,lhsDir:c,rhsDir:t,rhsGroup:g,title:i}=N,r=De(N.lhsDir,N.rhsDir)?"segments":"straight",h={id:`${u}-${o}`,label:i,source:u,sourceDir:c,sourceArrow:a,sourceGroup:e,sourceEndpoint:c==="L"?"0 50%":c==="R"?"100% 50%":c==="T"?"50% 0":"50% 100%",target:o,targetDir:t,targetArrow:n,targetGroup:g,targetEndpoint:t==="L"?"0 50%":t==="R"?"100% 50%":t==="T"?"50% 0":"50% 100%"};w.add({group:"edges",data:h,classes:r})})}ct(cr,"addEdges");function gr(E,w,N){let u=ct((n,c)=>Object.entries(n).reduce((t,[g,i])=>{let r=0,h=Object.entries(i);if(h.length===1)return t[g]=h[0][1],t;for(let f=0;f<h.length-1;f++)for(let l=f+1;l<h.length;l++){let[L,y]=h[f],[p,C]=h[l];if(N[L]?.[p]===c)t[g]??=[],t[g]=[...t[g],...y,...C];else if(L==="default"||p==="default")t[g]??=[],t[g]=[...t[g],...y,...C];else{let A=`${g}-${r++}`;t[A]=y;let S=`${g}-${r++}`;t[S]=C}}return t},{}),"flattenAlignments"),o=w.map(n=>{let c={},t={};return Object.entries(n).forEach(([g,[i,r]])=>{let h=E.getNode(g)?.in??"default";c[r]??={},c[r][h]??=[],c[r][h].push(g),t[i]??={},t[i][h]??=[],t[i][h].push(g)}),{horiz:Object.values(u(c,"horizontal")).filter(g=>g.length>1),vert:Object.values(u(t,"vertical")).filter(g=>g.length>1)}}),[a,e]=o.reduce(([n,c],{horiz:t,vert:g})=>[[...n,...t],[...c,...g]],[[],[]]);return{horizontal:a,vertical:e}}ct(gr,"getAlignments");function ur(E,w){let N=[],u=ct(a=>`${a[0]},${a[1]}`,"posToStr"),o=ct(a=>a.split(",").map(e=>parseInt(e)),"strToPos");return E.forEach(a=>{let e=Object.fromEntries(Object.entries(a).map(([g,i])=>[u(i),g])),n=[u([0,0])],c={},t={L:[-1,0],R:[1,0],T:[0,1],B:[0,-1]};for(;n.length>0;){let g=n.shift();if(g){c[g]=1;let i=e[g];if(i){let r=o(g);Object.entries(t).forEach(([h,f])=>{let l=u([r[0]+f[0],r[1]+f[1]]),L=e[l];L&&!c[l]&&(n.push(l),N.push({[tr[h]]:L,[tr[yr(h)]]:i,gap:1.5*w.getConfigField("iconSize")}))})}}}}),N}ct(ur,"getRelativeConstraints");function dr(E,w,N,u,o,{spatialMaps:a,groupAlignments:e}){return new Promise(n=>{let c=be("body").append("div").attr("id","cy").attr("style","display:none"),t=Ne({container:document.getElementById("cy"),style:[{selector:"edge",style:{"curve-style":"straight",label:"data(label)","source-endpoint":"data(sourceEndpoint)","target-endpoint":"data(targetEndpoint)"}},{selector:"edge.segments",style:{"curve-style":"segments","segment-weights":"0","segment-distances":[.5],"edge-distances":"endpoints","source-endpoint":"data(sourceEndpoint)","target-endpoint":"data(targetEndpoint)"}},{selector:"node",style:{"compound-sizing-wrt-labels":"include"}},{selector:"node[label]",style:{"text-valign":"bottom","text-halign":"center","font-size":`${o.getConfigField("fontSize")}px`}},{selector:".node-service",style:{label:"data(label)",width:"data(width)",height:"data(height)"}},{selector:".node-junction",style:{width:"data(width)",height:"data(height)"}},{selector:".node-group",style:{padding:`${o.getConfigField("padding")}px`}}],layout:{name:"grid",boundingBox:{x1:0,x2:100,y1:0,y2:100}}});c.remove(),fr(N,t),sr(E,t,o),hr(w,t,o),cr(u,t);let g=gr(o,a,e),i=ur(a,o),r=t.layout({name:"fcose",quality:"proof",styleEnabled:!1,animate:!1,nodeDimensionsIncludeLabels:!1,idealEdgeLength(h){let[f,l]=h.connectedNodes(),{parent:L}=ie(f),{parent:y}=ie(l);return L===y?1.5*o.getConfigField("iconSize"):.5*o.getConfigField("iconSize")},edgeElasticity(h){let[f,l]=h.connectedNodes(),{parent:L}=ie(f),{parent:y}=ie(l);return L===y?.45:.001},alignmentConstraint:g,relativePlacementConstraint:i});r.one("layoutstop",()=>{function h(f,l,L,y){let p,C,{x:R,y:A}=f,{x:S,y:B}=l;C=(y-A+(R-L)*(A-B)/(R-S))/Math.sqrt(1+Math.pow((A-B)/(R-S),2)),p=Math.sqrt(Math.pow(y-A,2)+Math.pow(L-R,2)-Math.pow(C,2));let Y=Math.sqrt(Math.pow(S-R,2)+Math.pow(B-A,2));p=p/Y;let tt=(S-R)*(y-A)-(B-A)*(L-R);switch(!0){case tt>=0:tt=1;break;case tt<0:tt=-1;break}let x=(S-R)*(L-R)+(B-A)*(y-A);switch(!0){case x>=0:x=1;break;case x<0:x=-1;break}return C=Math.abs(C)*tt,p=p*x,{distances:C,weights:p}}ct(h,"getSegmentWeights"),t.startBatch();for(let f of Object.values(t.edges()))if(f.data?.()){let{x:l,y:L}=f.source().position(),{x:y,y:p}=f.target().position();if(l!==y&&L!==p){let C=f.sourceEndpoint(),R=f.targetEndpoint(),{sourceDir:A}=ir(f),[S,B]=qt(A)?[C.x,R.y]:[R.x,C.y],{weights:Y,distances:tt}=h(C,R,S,B);f.style("segment-distances",tt),f.style("segment-weights",Y)}}t.endBatch(),r.run()}),r.run(),t.ready(h=>{Te.info("Ready",h),n(t)})})}ct(dr,"layoutArchitecture");var Fr=ct((E,w,N,u)=>Zt(null,null,function*(){let o=u.db,a=o.getServices(),e=o.getJunctions(),n=o.getGroups(),c=o.getEdges(),t=o.getDataStructures(),g=ke(w),i=g.append("g");i.attr("class","architecture-edges");let r=g.append("g");r.attr("class","architecture-services");let h=g.append("g");h.attr("class","architecture-groups"),yield Rr(o,r,a),Sr(o,r,e);let f=yield dr(a,e,n,c,o,t);yield xr(i,f,o),yield Ir(h,f,o),lr(o,f),Ye(void 0,g,o.getConfigField("padding"),o.getConfigField("useMaxWidth"))}),"draw"),br={draw:Fr},Br={parser:ar,get db(){return new nr},renderer:br,styles:Dr};export{Br as diagram}; |