UNPKG

@eventcatalogtest/studio

Version:

A drag and drop UI for distributed systems that keeps your diagrams where they belong – in your repo

1 lines 10.9 kB
"use strict";exports.id=7034,exports.ids=[7034],exports.modules={57034:(a,b,c)=>{c.d(b,{diagram:()=>C});var d,e=c(68704);c(82939),c(23386),c(23255),c(44514),c(96005),c(8837),c(4740),c(8688),c(7827);var f=c(65299),g=c(32892),h=c(38073),i=c(43644),j=c(77275),k=(0,g.K2)(a=>a.append("circle").attr("class","start-state").attr("r",(0,g.D7)().state.sizeUnit).attr("cx",(0,g.D7)().state.padding+(0,g.D7)().state.sizeUnit).attr("cy",(0,g.D7)().state.padding+(0,g.D7)().state.sizeUnit),"drawStartState"),l=(0,g.K2)(a=>a.append("line").style("stroke","grey").style("stroke-dasharray","3").attr("x1",(0,g.D7)().state.textHeight).attr("class","divider").attr("x2",2*(0,g.D7)().state.textHeight).attr("y1",0).attr("y2",0),"drawDivider"),m=(0,g.K2)((a,b)=>{let c=a.append("text").attr("x",2*(0,g.D7)().state.padding).attr("y",(0,g.D7)().state.textHeight+2*(0,g.D7)().state.padding).attr("font-size",(0,g.D7)().state.fontSize).attr("class","state-title").text(b.id),d=c.node().getBBox();return a.insert("rect",":first-child").attr("x",(0,g.D7)().state.padding).attr("y",(0,g.D7)().state.padding).attr("width",d.width+2*(0,g.D7)().state.padding).attr("height",d.height+2*(0,g.D7)().state.padding).attr("rx",(0,g.D7)().state.radius),c},"drawSimpleState"),n=(0,g.K2)((a,b)=>{let c=(0,g.K2)(function(a,b,c){let d=a.append("tspan").attr("x",2*(0,g.D7)().state.padding).text(b);c||d.attr("dy",(0,g.D7)().state.textHeight)},"addTspan"),d=a.append("text").attr("x",2*(0,g.D7)().state.padding).attr("y",(0,g.D7)().state.textHeight+1.3*(0,g.D7)().state.padding).attr("font-size",(0,g.D7)().state.fontSize).attr("class","state-title").text(b.descriptions[0]).node().getBBox(),e=d.height,f=a.append("text").attr("x",(0,g.D7)().state.padding).attr("y",e+.4*(0,g.D7)().state.padding+(0,g.D7)().state.dividerMargin+(0,g.D7)().state.textHeight).attr("class","state-description"),h=!0,i=!0;b.descriptions.forEach(function(a){h||(c(f,a,i),i=!1),h=!1});let j=a.append("line").attr("x1",(0,g.D7)().state.padding).attr("y1",(0,g.D7)().state.padding+e+(0,g.D7)().state.dividerMargin/2).attr("y2",(0,g.D7)().state.padding+e+(0,g.D7)().state.dividerMargin/2).attr("class","descr-divider"),k=f.node().getBBox(),l=Math.max(k.width,d.width);return j.attr("x2",l+3*(0,g.D7)().state.padding),a.insert("rect",":first-child").attr("x",(0,g.D7)().state.padding).attr("y",(0,g.D7)().state.padding).attr("width",l+2*(0,g.D7)().state.padding).attr("height",k.height+e+2*(0,g.D7)().state.padding).attr("rx",(0,g.D7)().state.radius),a},"drawDescrState"),o=(0,g.K2)((a,b,c)=>{let d,e=(0,g.D7)().state.padding,f=2*(0,g.D7)().state.padding,h=a.node().getBBox(),i=h.width,j=h.x,k=a.append("text").attr("x",0).attr("y",(0,g.D7)().state.titleShift).attr("font-size",(0,g.D7)().state.fontSize).attr("class","state-title").text(b.id),l=k.node().getBBox().width+f,m=Math.max(l,i);m===i&&(m+=f);let n=a.node().getBBox();b.doc,d=j-e,l>i&&(d=(i-m)/2+e),Math.abs(j-n.x)<e&&l>i&&(d=j-(l-i)/2);let o=1-(0,g.D7)().state.textHeight;return a.insert("rect",":first-child").attr("x",d).attr("y",o).attr("class",c?"alt-composit":"composit").attr("width",m).attr("height",n.height+(0,g.D7)().state.textHeight+(0,g.D7)().state.titleShift+1).attr("rx","0"),k.attr("x",d+e),l<=i&&k.attr("x",j+(m-f)/2-l/2+e),a.insert("rect",":first-child").attr("x",d).attr("y",(0,g.D7)().state.titleShift-(0,g.D7)().state.textHeight-(0,g.D7)().state.padding).attr("width",m).attr("height",3*(0,g.D7)().state.textHeight).attr("rx",(0,g.D7)().state.radius),a.insert("rect",":first-child").attr("x",d).attr("y",(0,g.D7)().state.titleShift-(0,g.D7)().state.textHeight-(0,g.D7)().state.padding).attr("width",m).attr("height",n.height+3+2*(0,g.D7)().state.textHeight).attr("rx",(0,g.D7)().state.radius),a},"addTitleAndBox"),p=(0,g.K2)(a=>(a.append("circle").attr("class","end-state-outer").attr("r",(0,g.D7)().state.sizeUnit+(0,g.D7)().state.miniPadding).attr("cx",(0,g.D7)().state.padding+(0,g.D7)().state.sizeUnit+(0,g.D7)().state.miniPadding).attr("cy",(0,g.D7)().state.padding+(0,g.D7)().state.sizeUnit+(0,g.D7)().state.miniPadding),a.append("circle").attr("class","end-state-inner").attr("r",(0,g.D7)().state.sizeUnit).attr("cx",(0,g.D7)().state.padding+(0,g.D7)().state.sizeUnit+2).attr("cy",(0,g.D7)().state.padding+(0,g.D7)().state.sizeUnit+2)),"drawEndState"),q=(0,g.K2)((a,b)=>{let c=(0,g.D7)().state.forkWidth,d=(0,g.D7)().state.forkHeight;if(b.parentId){let a=c;c=d,d=a}return a.append("rect").style("stroke","black").style("fill","black").attr("width",c).attr("height",d).attr("x",(0,g.D7)().state.padding).attr("y",(0,g.D7)().state.padding)},"drawForkJoinState"),r=(0,g.K2)((a,b,c,d)=>{let e=0,f=d.append("text");f.style("text-anchor","start"),f.attr("class","noteText");let h=a.replace(/\r\n/g,"<br/>"),i=(h=h.replace(/\n/g,"<br/>")).split(g.Y2.lineBreakRegex),j=1.25*(0,g.D7)().state.noteMargin;for(let a of i){let d=a.trim();if(d.length>0){let a=f.append("tspan");a.text(d),0===j&&(j+=a.node().getBBox().height),e+=j,a.attr("x",b+(0,g.D7)().state.noteMargin),a.attr("y",c+e+1.25*(0,g.D7)().state.noteMargin)}}return{textWidth:f.node().getBBox().width,textHeight:e}},"_drawLongText"),s=(0,g.K2)((a,b)=>{b.attr("class","state-note");let c=b.append("rect").attr("x",0).attr("y",(0,g.D7)().state.padding),{textWidth:d,textHeight:e}=r(a,0,0,b.append("g"));return c.attr("height",e+2*(0,g.D7)().state.noteMargin),c.attr("width",d+2*(0,g.D7)().state.noteMargin),c},"drawNote"),t=(0,g.K2)(function(a,b){let c=b.id,d={id:c,label:b.id,width:0,height:0},e=a.append("g").attr("id",c).attr("class","stateGroup");"start"===b.type&&k(e),"end"===b.type&&p(e),("fork"===b.type||"join"===b.type)&&q(e,b),"note"===b.type&&s(b.note.text,e),"divider"===b.type&&l(e),"default"===b.type&&0===b.descriptions.length&&m(e,b),"default"===b.type&&b.descriptions.length>0&&n(e,b);let f=e.node().getBBox();return d.width=f.width+2*(0,g.D7)().state.padding,d.height=f.height+2*(0,g.D7)().state.padding,d},"drawState"),u=0,v=(0,g.K2)(function(a,b,c){let d=(0,g.K2)(function(a){switch(a){case e.u4.relationType.AGGREGATION:return"aggregation";case e.u4.relationType.EXTENSION:return"extension";case e.u4.relationType.COMPOSITION:return"composition";case e.u4.relationType.DEPENDENCY:return"dependency"}},"getRelationType");b.points=b.points.filter(a=>!Number.isNaN(a.y));let i=b.points,j=(0,h.n8j)().x(function(a){return a.x}).y(function(a){return a.y}).curve(h.qrM),k=a.append("path").attr("d",j(i)).attr("id","edge"+u).attr("class","transition"),l="";if((0,g.D7)().state.arrowMarkerAbsolute&&(l=(0,g.ID)(!0)),k.attr("marker-end","url("+l+"#"+d(e.u4.relationType.DEPENDENCY)+"End)"),void 0!==c.title){let d=a.append("g").attr("class","stateLabel"),{x:e,y:h}=f._K.calcLabelPosition(b.points),i=g.Y2.getRows(c.title),j=0,k=[],l=0,m=0;for(let a=0;a<=i.length;a++){let b=d.append("text").attr("text-anchor","middle").text(i[a]).attr("x",e).attr("y",h+j),c=b.node().getBBox();l=Math.max(l,c.width),m=Math.min(m,c.x),g.Rm.info(c.x,e,h+j),0===j&&(j=b.node().getBBox().height,g.Rm.info("Title height",j,h)),k.push(b)}let n=j*i.length;if(i.length>1){let a=(i.length-1)*j*.5;k.forEach((b,c)=>b.attr("y",h+c*j-a)),n=j*i.length}let o=d.node().getBBox();d.insert("rect",":first-child").attr("class","box").attr("x",e-l/2-(0,g.D7)().state.padding/2).attr("y",h-n/2-(0,g.D7)().state.padding/2-3.5).attr("width",l+(0,g.D7)().state.padding).attr("height",n+(0,g.D7)().state.padding),g.Rm.info(o)}u++},"drawEdge"),w={},x=(0,g.K2)(function(){},"setConf"),y=(0,g.K2)(function(a){a.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"),z=(0,g.K2)(function(a,b,c,e){let f;d=(0,g.D7)().state;let i=(0,g.D7)().securityLevel;"sandbox"===i&&(f=(0,h.Ltv)("#i"+b));let j="sandbox"===i?(0,h.Ltv)(f.nodes()[0].contentDocument.body):(0,h.Ltv)("body"),k="sandbox"===i?f.nodes()[0].contentDocument:document;g.Rm.debug("Rendering diagram "+a);let l=j.select(`[id='${b}']`);y(l),B(e.db.getRootDoc(),l,void 0,!1,j,k,e);let m=d.padding,n=l.node().getBBox(),o=n.width+2*m,p=n.height+2*m;(0,g.a$)(l,p,1.75*o,d.useMaxWidth),l.attr("viewBox",`${n.x-d.padding} ${n.y-d.padding} `+o+" "+p)},"draw"),A=(0,g.K2)(a=>a?a.length*d.fontSizeFactor:1,"getLabelWidth"),B=(0,g.K2)((a,b,c,e,f,h,k)=>{let l,m=new j.T({compound:!0,multigraph:!0}),n=!0;for(l=0;l<a.length;l++)if("relation"===a[l].stmt){n=!1;break}c?m.setGraph({rankdir:"LR",multigraph:!0,compound:!0,ranker:"tight-tree",ranksep:n?1:d.edgeLengthFactor,nodeSep:n?1:50,isMultiGraph:!0}):m.setGraph({rankdir:"TB",multigraph:!0,compound:!0,ranksep:n?1:d.edgeLengthFactor,nodeSep:n?1:50,ranker:"tight-tree",isMultiGraph:!0}),m.setDefaultEdgeLabel(function(){return{}});let p=k.db.getStates(),q=k.db.getRelations();for(let a of Object.keys(p)){let g,i=p[a];if(c&&(i.parentId=c),i.doc){let a=b.append("g").attr("id",i.id).attr("class","stateGroup");g=B(i.doc,a,i.id,!e,f,h,k);{let b=(a=o(a,i,e)).node().getBBox();g.width=b.width,g.height=b.height+d.padding/2,w[i.id]={y:d.compositTitleSize}}}else g=t(b,i,m);if(i.note){let a=t(b,{descriptions:[],id:i.id+"-note",note:i.note,type:"note"},m);"left of"===i.note.position?(m.setNode(g.id+"-note",a),m.setNode(g.id,g)):(m.setNode(g.id,g),m.setNode(g.id+"-note",a)),m.setParent(g.id,g.id+"-group"),m.setParent(g.id+"-note",g.id+"-group")}else m.setNode(g.id,g)}g.Rm.debug("Count=",m.nodeCount(),m);let r=0;q.forEach(function(a){r++,g.Rm.debug("Setting edge",a),m.setEdge(a.id1,a.id2,{relation:a,width:A(a.title),height:d.labelHeight*g.Y2.getRows(a.title).length,labelpos:"c"},"id"+r)}),(0,i.Zp)(m),g.Rm.debug("Graph after layout",m.nodes());let s=b.node();m.nodes().forEach(function(a){void 0!==a&&void 0!==m.node(a)?(g.Rm.warn("Node "+a+": "+JSON.stringify(m.node(a))),f.select("#"+s.id+" #"+a).attr("transform","translate("+(m.node(a).x-m.node(a).width/2)+","+(m.node(a).y+(w[a]?w[a].y:0)-m.node(a).height/2)+" )"),f.select("#"+s.id+" #"+a).attr("data-x-shift",m.node(a).x-m.node(a).width/2),h.querySelectorAll("#"+s.id+" #"+a+" .divider").forEach(a=>{let b=a.parentElement,c=0,d=0;b&&(b.parentElement&&(c=b.parentElement.getBBox().width),Number.isNaN(d=parseInt(b.getAttribute("data-x-shift"),10))&&(d=0)),a.setAttribute("x1",0-d+8),a.setAttribute("x2",c-d-8)})):g.Rm.debug("No Node "+a+": "+JSON.stringify(m.node(a)))});let u=s.getBBox();m.edges().forEach(function(a){void 0!==a&&void 0!==m.edge(a)&&(g.Rm.debug("Edge "+a.v+" -> "+a.w+": "+JSON.stringify(m.edge(a))),v(b,m.edge(a),m.edge(a).relation))});let x={id:c||"root",label:c||"root",width:0,height:0};return x.width=(u=s.getBBox()).width+2*d.padding,x.height=u.height+2*d.padding,g.Rm.debug("Doc rendered",x,m),x},"renderDoc"),C={parser:e.Zk,get db(){return new e.u4(1)},renderer:{setConf:x,draw:z},styles:e.tM,init:(0,g.K2)(a=>{a.state||(a.state={}),a.state.arrowMarkerAbsolute=a.arrowMarkerAbsolute},"init")}}};