@asyncapi/studio
Version:
One place that allows you to develop an AsyncAPI document, validate it, convert it to the latest version, preview the documentation and visualize the events flow.
1 lines • 10.9 kB
JavaScript
;exports.id=5785,exports.ids=[5785],exports.modules={45785:(t,e,a)=>{a.d(e,{diagram:()=>v});var n,i=a(33941);a(86720),a(76786),a(73043),a(19669),a(88441),a(70116),a(73943),a(65732),a(64890);var r=a(63951),d=a(51635),s=a(17605),o=a(25329),g=a(2658),l=a(19386),p=(0,s.eW)(t=>t.append("circle").attr("class","start-state").attr("r",(0,d.nV)().state.sizeUnit).attr("cx",(0,d.nV)().state.padding+(0,d.nV)().state.sizeUnit).attr("cy",(0,d.nV)().state.padding+(0,d.nV)().state.sizeUnit),"drawStartState"),h=(0,s.eW)(t=>t.append("line").style("stroke","grey").style("stroke-dasharray","3").attr("x1",(0,d.nV)().state.textHeight).attr("class","divider").attr("x2",2*(0,d.nV)().state.textHeight).attr("y1",0).attr("y2",0),"drawDivider"),c=(0,s.eW)((t,e)=>{let a=t.append("text").attr("x",2*(0,d.nV)().state.padding).attr("y",(0,d.nV)().state.textHeight+2*(0,d.nV)().state.padding).attr("font-size",(0,d.nV)().state.fontSize).attr("class","state-title").text(e.id),n=a.node().getBBox();return t.insert("rect",":first-child").attr("x",(0,d.nV)().state.padding).attr("y",(0,d.nV)().state.padding).attr("width",n.width+2*(0,d.nV)().state.padding).attr("height",n.height+2*(0,d.nV)().state.padding).attr("rx",(0,d.nV)().state.radius),a},"drawSimpleState"),x=(0,s.eW)((t,e)=>{let a=(0,s.eW)(function(t,e,a){let n=t.append("tspan").attr("x",2*(0,d.nV)().state.padding).text(e);a||n.attr("dy",(0,d.nV)().state.textHeight)},"addTspan"),n=t.append("text").attr("x",2*(0,d.nV)().state.padding).attr("y",(0,d.nV)().state.textHeight+1.3*(0,d.nV)().state.padding).attr("font-size",(0,d.nV)().state.fontSize).attr("class","state-title").text(e.descriptions[0]).node().getBBox(),i=n.height,r=t.append("text").attr("x",(0,d.nV)().state.padding).attr("y",i+.4*(0,d.nV)().state.padding+(0,d.nV)().state.dividerMargin+(0,d.nV)().state.textHeight).attr("class","state-description"),o=!0,g=!0;e.descriptions.forEach(function(t){o||(a(r,t,g),g=!1),o=!1});let l=t.append("line").attr("x1",(0,d.nV)().state.padding).attr("y1",(0,d.nV)().state.padding+i+(0,d.nV)().state.dividerMargin/2).attr("y2",(0,d.nV)().state.padding+i+(0,d.nV)().state.dividerMargin/2).attr("class","descr-divider"),p=r.node().getBBox(),h=Math.max(p.width,n.width);return l.attr("x2",h+3*(0,d.nV)().state.padding),t.insert("rect",":first-child").attr("x",(0,d.nV)().state.padding).attr("y",(0,d.nV)().state.padding).attr("width",h+2*(0,d.nV)().state.padding).attr("height",p.height+i+2*(0,d.nV)().state.padding).attr("rx",(0,d.nV)().state.radius),t},"drawDescrState"),V=(0,s.eW)((t,e,a)=>{let n;let i=(0,d.nV)().state.padding,r=2*(0,d.nV)().state.padding,s=t.node().getBBox(),o=s.width,g=s.x,l=t.append("text").attr("x",0).attr("y",(0,d.nV)().state.titleShift).attr("font-size",(0,d.nV)().state.fontSize).attr("class","state-title").text(e.id),p=l.node().getBBox().width+r,h=Math.max(p,o);h===o&&(h+=r);let c=t.node().getBBox();e.doc,n=g-i,p>o&&(n=(o-h)/2+i),Math.abs(g-c.x)<i&&p>o&&(n=g-(p-o)/2);let x=1-(0,d.nV)().state.textHeight;return t.insert("rect",":first-child").attr("x",n).attr("y",x).attr("class",a?"alt-composit":"composit").attr("width",h).attr("height",c.height+(0,d.nV)().state.textHeight+(0,d.nV)().state.titleShift+1).attr("rx","0"),l.attr("x",n+i),p<=o&&l.attr("x",g+(h-r)/2-p/2+i),t.insert("rect",":first-child").attr("x",n).attr("y",(0,d.nV)().state.titleShift-(0,d.nV)().state.textHeight-(0,d.nV)().state.padding).attr("width",h).attr("height",3*(0,d.nV)().state.textHeight).attr("rx",(0,d.nV)().state.radius),t.insert("rect",":first-child").attr("x",n).attr("y",(0,d.nV)().state.titleShift-(0,d.nV)().state.textHeight-(0,d.nV)().state.padding).attr("width",h).attr("height",c.height+3+2*(0,d.nV)().state.textHeight).attr("rx",(0,d.nV)().state.radius),t},"addTitleAndBox"),u=(0,s.eW)(t=>(t.append("circle").attr("class","end-state-outer").attr("r",(0,d.nV)().state.sizeUnit+(0,d.nV)().state.miniPadding).attr("cx",(0,d.nV)().state.padding+(0,d.nV)().state.sizeUnit+(0,d.nV)().state.miniPadding).attr("cy",(0,d.nV)().state.padding+(0,d.nV)().state.sizeUnit+(0,d.nV)().state.miniPadding),t.append("circle").attr("class","end-state-inner").attr("r",(0,d.nV)().state.sizeUnit).attr("cx",(0,d.nV)().state.padding+(0,d.nV)().state.sizeUnit+2).attr("cy",(0,d.nV)().state.padding+(0,d.nV)().state.sizeUnit+2)),"drawEndState"),f=(0,s.eW)((t,e)=>{let a=(0,d.nV)().state.forkWidth,n=(0,d.nV)().state.forkHeight;if(e.parentId){let t=a;a=n,n=t}return t.append("rect").style("stroke","black").style("fill","black").attr("width",a).attr("height",n).attr("x",(0,d.nV)().state.padding).attr("y",(0,d.nV)().state.padding)},"drawForkJoinState"),y=(0,s.eW)((t,e,a,n)=>{let i=0,r=n.append("text");r.style("text-anchor","start"),r.attr("class","noteText");let s=t.replace(/\r\n/g,"<br/>"),o=(s=s.replace(/\n/g,"<br/>")).split(d.SY.lineBreakRegex),g=1.25*(0,d.nV)().state.noteMargin;for(let t of o){let n=t.trim();if(n.length>0){let t=r.append("tspan");t.text(n),0===g&&(g+=t.node().getBBox().height),i+=g,t.attr("x",e+(0,d.nV)().state.noteMargin),t.attr("y",a+i+1.25*(0,d.nV)().state.noteMargin)}}return{textWidth:r.node().getBBox().width,textHeight:i}},"_drawLongText"),w=(0,s.eW)((t,e)=>{e.attr("class","state-note");let a=e.append("rect").attr("x",0).attr("y",(0,d.nV)().state.padding),{textWidth:n,textHeight:i}=y(t,0,0,e.append("g"));return a.attr("height",i+2*(0,d.nV)().state.noteMargin),a.attr("width",n+2*(0,d.nV)().state.noteMargin),a},"drawNote"),b=(0,s.eW)(function(t,e){let a=e.id,n={id:a,label:e.id,width:0,height:0},i=t.append("g").attr("id",a).attr("class","stateGroup");"start"===e.type&&p(i),"end"===e.type&&u(i),("fork"===e.type||"join"===e.type)&&f(i,e),"note"===e.type&&w(e.note.text,i),"divider"===e.type&&h(i),"default"===e.type&&0===e.descriptions.length&&c(i,e),"default"===e.type&&e.descriptions.length>0&&x(i,e);let r=i.node().getBBox();return n.width=r.width+2*(0,d.nV)().state.padding,n.height=r.height+2*(0,d.nV)().state.padding,n},"drawState"),B=0,m=(0,s.eW)(function(t,e,a){let n=(0,s.eW)(function(t){switch(t){case i.oI.relationType.AGGREGATION:return"aggregation";case i.oI.relationType.EXTENSION:return"extension";case i.oI.relationType.COMPOSITION:return"composition";case i.oI.relationType.DEPENDENCY:return"dependency"}},"getRelationType");e.points=e.points.filter(t=>!Number.isNaN(t.y));let g=e.points,l=(0,o.jvg)().x(function(t){return t.x}).y(function(t){return t.y}).curve(o.$0Z),p=t.append("path").attr("d",l(g)).attr("id","edge"+B).attr("class","transition"),h="";if((0,d.nV)().state.arrowMarkerAbsolute&&(h=(0,d.Gr)(!0)),p.attr("marker-end","url("+h+"#"+n(i.oI.relationType.DEPENDENCY)+"End)"),void 0!==a.title){let n=t.append("g").attr("class","stateLabel"),{x:i,y:o}=r.w8.calcLabelPosition(e.points),g=d.SY.getRows(a.title),l=0,p=[],h=0,c=0;for(let t=0;t<=g.length;t++){let e=n.append("text").attr("text-anchor","middle").text(g[t]).attr("x",i).attr("y",o+l),a=e.node().getBBox();h=Math.max(h,a.width),c=Math.min(c,a.x),s.cM.info(a.x,i,o+l),0===l&&(l=e.node().getBBox().height,s.cM.info("Title height",l,o)),p.push(e)}let x=l*g.length;if(g.length>1){let t=(g.length-1)*l*.5;p.forEach((e,a)=>e.attr("y",o+a*l-t)),x=l*g.length}let V=n.node().getBBox();n.insert("rect",":first-child").attr("class","box").attr("x",i-h/2-(0,d.nV)().state.padding/2).attr("y",o-x/2-(0,d.nV)().state.padding/2-3.5).attr("width",h+(0,d.nV)().state.padding).attr("height",x+(0,d.nV)().state.padding),s.cM.info(V)}B++},"drawEdge"),M={},S=(0,s.eW)(function(){},"setConf"),k=(0,s.eW)(function(t){t.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"),E=(0,s.eW)(function(t,e,a,i){let r;n=(0,d.nV)().state;let g=(0,d.nV)().securityLevel;"sandbox"===g&&(r=(0,o.Ys)("#i"+e));let l="sandbox"===g?(0,o.Ys)(r.nodes()[0].contentDocument.body):(0,o.Ys)("body"),p="sandbox"===g?r.nodes()[0].contentDocument:document;s.cM.debug("Rendering diagram "+t);let h=l.select(`[id='${e}']`);k(h),W(i.db.getRootDoc(),h,void 0,!1,l,p,i);let c=n.padding,x=h.node().getBBox(),V=x.width+2*c,u=x.height+2*c;(0,d.v2)(h,u,1.75*V,n.useMaxWidth),h.attr("viewBox",`${x.x-n.padding} ${x.y-n.padding} `+V+" "+u)},"draw"),N=(0,s.eW)(t=>t?t.length*n.fontSizeFactor:1,"getLabelWidth"),W=(0,s.eW)((t,e,a,i,r,o,p)=>{let h;let c=new l.k({compound:!0,multigraph:!0}),x=!0;for(h=0;h<t.length;h++)if("relation"===t[h].stmt){x=!1;break}a?c.setGraph({rankdir:"LR",multigraph:!0,compound:!0,ranker:"tight-tree",ranksep:x?1:n.edgeLengthFactor,nodeSep:x?1:50,isMultiGraph:!0}):c.setGraph({rankdir:"TB",multigraph:!0,compound:!0,ranksep:x?1:n.edgeLengthFactor,nodeSep:x?1:50,ranker:"tight-tree",isMultiGraph:!0}),c.setDefaultEdgeLabel(function(){return{}});let u=p.db.getStates(),f=p.db.getRelations();for(let t of Object.keys(u)){let d;let s=u[t];if(a&&(s.parentId=a),s.doc){let t=e.append("g").attr("id",s.id).attr("class","stateGroup");d=W(s.doc,t,s.id,!i,r,o,p);{let e=(t=V(t,s,i)).node().getBBox();d.width=e.width,d.height=e.height+n.padding/2,M[s.id]={y:n.compositTitleSize}}}else d=b(e,s,c);if(s.note){let t=b(e,{descriptions:[],id:s.id+"-note",note:s.note,type:"note"},c);"left of"===s.note.position?(c.setNode(d.id+"-note",t),c.setNode(d.id,d)):(c.setNode(d.id,d),c.setNode(d.id+"-note",t)),c.setParent(d.id,d.id+"-group"),c.setParent(d.id+"-note",d.id+"-group")}else c.setNode(d.id,d)}s.cM.debug("Count=",c.nodeCount(),c);let y=0;f.forEach(function(t){y++,s.cM.debug("Setting edge",t),c.setEdge(t.id1,t.id2,{relation:t,width:N(t.title),height:n.labelHeight*d.SY.getRows(t.title).length,labelpos:"c"},"id"+y)}),(0,g.bK)(c),s.cM.debug("Graph after layout",c.nodes());let w=e.node();c.nodes().forEach(function(t){void 0!==t&&void 0!==c.node(t)?(s.cM.warn("Node "+t+": "+JSON.stringify(c.node(t))),r.select("#"+w.id+" #"+t).attr("transform","translate("+(c.node(t).x-c.node(t).width/2)+","+(c.node(t).y+(M[t]?M[t].y:0)-c.node(t).height/2)+" )"),r.select("#"+w.id+" #"+t).attr("data-x-shift",c.node(t).x-c.node(t).width/2),o.querySelectorAll("#"+w.id+" #"+t+" .divider").forEach(t=>{let e=t.parentElement,a=0,n=0;e&&(e.parentElement&&(a=e.parentElement.getBBox().width),Number.isNaN(n=parseInt(e.getAttribute("data-x-shift"),10))&&(n=0)),t.setAttribute("x1",0-n+8),t.setAttribute("x2",a-n-8)})):s.cM.debug("No Node "+t+": "+JSON.stringify(c.node(t)))});let B=w.getBBox();c.edges().forEach(function(t){void 0!==t&&void 0!==c.edge(t)&&(s.cM.debug("Edge "+t.v+" -> "+t.w+": "+JSON.stringify(c.edge(t))),m(e,c.edge(t),c.edge(t).relation))}),B=w.getBBox();let S={id:a||"root",label:a||"root",width:0,height:0};return S.width=B.width+2*n.padding,S.height=B.height+2*n.padding,s.cM.debug("Doc rendered",S,c),S},"renderDoc"),v={parser:i.J8,get db(){return new i.oI(1)},renderer:{setConf:S,draw:E},styles:i.Ee,init:(0,s.eW)(t=>{t.state||(t.state={}),t.state.arrowMarkerAbsolute=t.arrowMarkerAbsolute},"init")}}};