UNPKG

ranui

Version:

A framework-agnostic Web Components UI library built on native custom elements, with TypeScript types, light/dark theming, SSR and PWA support.

2 lines (1 loc) 12.1 kB
const C=require("./chunk-Y2CYZVJY-DPaYLFFP.cjs"),w=require("./src-D8aDujwE.cjs"),t=require("./chunk-I66GZJ75-BzqGKy7F.cjs"),N=require("./chunk-NSK5VX7P-DcRXFc-R.cjs"),T=require("./line-CAI5srU-.cjs");require("./chunk-4I5QYGJK-fRI-M8oC.cjs");require("./chunk-WRU74C26-zS0j4l0M.cjs");require("./chunk-7BUUIJ7U-DMv_UkjI.cjs");require("./chunk-UBXNYLIW-rJ4d6bZj.cjs");const z=require("./graphlib-Du-578Js.cjs"),L=require("./dagre-pZ5_xXza.cjs");require("./chunk-2GRJ4B5K-DpsV4HbN.cjs");require("./chunk-XXDRQBXY-D1dvxzcY.cjs");require("./chunk-KBJHAD2P-BGFVhtHr.cjs");require("./chunk-W5SLKNZC-z8QxkdMj.cjs");require("./chunk-QR6OTTB3-P6k0vwas.cjs");require("./chunk-7Z6QIM7H-EvMi8iUm.cjs");require("./chunk-J7OUQ5F2-Bgqy1PHL.cjs");const k=require("./chunk-5RXB4S5H-BMrLj5xI.cjs");var A=C.__name(e=>e.append("circle").attr("class","start-state").attr("r",t.getConfig2().state.sizeUnit).attr("cx",t.getConfig2().state.padding+t.getConfig2().state.sizeUnit).attr("cy",t.getConfig2().state.padding+t.getConfig2().state.sizeUnit),"drawStartState"),G=C.__name(e=>e.append("line").style("stroke","grey").style("stroke-dasharray","3").attr("x1",t.getConfig2().state.textHeight).attr("class","divider").attr("x2",t.getConfig2().state.textHeight*2).attr("y1",0).attr("y2",0),"drawDivider"),P=C.__name((e,n)=>{const d=e.append("text").attr("x",2*t.getConfig2().state.padding).attr("y",t.getConfig2().state.textHeight+2*t.getConfig2().state.padding).attr("font-size",t.getConfig2().state.fontSize).attr("class","state-title").text(n.id),s=d.node().getBBox();return e.insert("rect",":first-child").attr("x",t.getConfig2().state.padding).attr("y",t.getConfig2().state.padding).attr("width",s.width+2*t.getConfig2().state.padding).attr("height",s.height+2*t.getConfig2().state.padding).attr("rx",t.getConfig2().state.radius),d},"drawSimpleState"),R=C.__name((e,n)=>{const d=C.__name(function(c,u,B){const _=c.append("tspan").attr("x",2*t.getConfig2().state.padding).text(u);B||_.attr("dy",t.getConfig2().state.textHeight)},"addTspan"),s=e.append("text").attr("x",2*t.getConfig2().state.padding).attr("y",t.getConfig2().state.textHeight+1.3*t.getConfig2().state.padding).attr("font-size",t.getConfig2().state.fontSize).attr("class","state-title").text(n.descriptions[0]).node().getBBox(),r=s.height,p=e.append("text").attr("x",t.getConfig2().state.padding).attr("y",r+t.getConfig2().state.padding*.4+t.getConfig2().state.dividerMargin+t.getConfig2().state.textHeight).attr("class","state-description");let h=!0,i=!0;n.descriptions.forEach(function(c){h||(d(p,c,i),i=!1),h=!1});const o=e.append("line").attr("x1",t.getConfig2().state.padding).attr("y1",t.getConfig2().state.padding+r+t.getConfig2().state.dividerMargin/2).attr("y2",t.getConfig2().state.padding+r+t.getConfig2().state.dividerMargin/2).attr("class","descr-divider"),f=p.node().getBBox(),g=Math.max(f.width,s.width);return o.attr("x2",g+3*t.getConfig2().state.padding),e.insert("rect",":first-child").attr("x",t.getConfig2().state.padding).attr("y",t.getConfig2().state.padding).attr("width",g+2*t.getConfig2().state.padding).attr("height",f.height+r+2*t.getConfig2().state.padding).attr("rx",t.getConfig2().state.radius),e},"drawDescrState"),W=C.__name((e,n,d)=>{const s=t.getConfig2().state.padding,r=2*t.getConfig2().state.padding,p=e.node().getBBox(),h=p.width,i=p.x,o=e.append("text").attr("x",0).attr("y",t.getConfig2().state.titleShift).attr("font-size",t.getConfig2().state.fontSize).attr("class","state-title").text(n.id),f=o.node().getBBox().width+r;let g=Math.max(f,h);g===h&&(g=g+r);let c;const u=e.node().getBBox();n.doc,c=i-s,f>h&&(c=(h-g)/2+s),Math.abs(i-u.x)<s&&f>h&&(c=i-(f-h)/2);const B=1-t.getConfig2().state.textHeight;return e.insert("rect",":first-child").attr("x",c).attr("y",B).attr("class",d?"alt-composit":"composit").attr("width",g).attr("height",u.height+t.getConfig2().state.textHeight+t.getConfig2().state.titleShift+1).attr("rx","0"),o.attr("x",c+s),f<=h&&o.attr("x",i+(g-r)/2-f/2+s),e.insert("rect",":first-child").attr("x",c).attr("y",t.getConfig2().state.titleShift-t.getConfig2().state.textHeight-t.getConfig2().state.padding).attr("width",g).attr("height",t.getConfig2().state.textHeight*3).attr("rx",t.getConfig2().state.radius),e.insert("rect",":first-child").attr("x",c).attr("y",t.getConfig2().state.titleShift-t.getConfig2().state.textHeight-t.getConfig2().state.padding).attr("width",g).attr("height",u.height+3+2*t.getConfig2().state.textHeight).attr("rx",t.getConfig2().state.radius),e},"addTitleAndBox"),U=C.__name(e=>(e.append("circle").attr("class","end-state-outer").attr("r",t.getConfig2().state.sizeUnit+t.getConfig2().state.miniPadding).attr("cx",t.getConfig2().state.padding+t.getConfig2().state.sizeUnit+t.getConfig2().state.miniPadding).attr("cy",t.getConfig2().state.padding+t.getConfig2().state.sizeUnit+t.getConfig2().state.miniPadding),e.append("circle").attr("class","end-state-inner").attr("r",t.getConfig2().state.sizeUnit).attr("cx",t.getConfig2().state.padding+t.getConfig2().state.sizeUnit+2).attr("cy",t.getConfig2().state.padding+t.getConfig2().state.sizeUnit+2)),"drawEndState"),F=C.__name((e,n)=>{let d=t.getConfig2().state.forkWidth,s=t.getConfig2().state.forkHeight;if(n.parentId){let r=d;d=s,s=r}return e.append("rect").style("stroke","black").style("fill","black").attr("width",d).attr("height",s).attr("x",t.getConfig2().state.padding).attr("y",t.getConfig2().state.padding)},"drawForkJoinState"),D=C.__name((e,n,d,s)=>{let r=0;const p=s.append("text");p.style("text-anchor","start"),p.attr("class","noteText");let h=e.replace(/\r\n/g,"<br/>");h=h.replace(/\n/g,"<br/>");const i=h.split(t.common_default.lineBreakRegex);let o=1.25*t.getConfig2().state.noteMargin;for(const f of i){const g=f.trim();if(g.length>0){const c=p.append("tspan");if(c.text(g),o===0){const u=c.node().getBBox();o+=u.height}r+=o,c.attr("x",n+t.getConfig2().state.noteMargin),c.attr("y",d+r+1.25*t.getConfig2().state.noteMargin)}}return{textWidth:p.node().getBBox().width,textHeight:r}},"_drawLongText"),J=C.__name((e,n)=>{n.attr("class","state-note");const d=n.append("rect").attr("x",0).attr("y",t.getConfig2().state.padding),{textWidth:s,textHeight:r}=D(e,0,0,n.append("g"));return d.attr("height",r+2*t.getConfig2().state.noteMargin),d.attr("width",s+t.getConfig2().state.noteMargin*2),d},"drawNote"),v=C.__name(function(e,n){const d=n.id,s={id:d,label:n.id,width:0,height:0},r=e.append("g").attr("id",d).attr("class","stateGroup");n.type==="start"&&A(r),n.type==="end"&&U(r),(n.type==="fork"||n.type==="join")&&F(r,n),n.type==="note"&&J(n.note.text,r),n.type==="divider"&&G(r),n.type==="default"&&n.descriptions.length===0&&P(r,n),n.type==="default"&&n.descriptions.length>0&&R(r,n);const p=r.node().getBBox();return s.width=p.width+2*t.getConfig2().state.padding,s.height=p.height+2*t.getConfig2().state.padding,s},"drawState"),M=0,X=C.__name(function(e,n,d){const s=C.__name(function(o){switch(o){case k.StateDB.relationType.AGGREGATION:return"aggregation";case k.StateDB.relationType.EXTENSION:return"extension";case k.StateDB.relationType.COMPOSITION:return"composition";case k.StateDB.relationType.DEPENDENCY:return"dependency"}},"getRelationType");n.points=n.points.filter(o=>!Number.isNaN(o.y));const r=n.points,p=T.line_default().x(function(o){return o.x}).y(function(o){return o.y}).curve(N.basis_default),h=e.append("path").attr("d",p(r)).attr("id","edge"+M).attr("class","transition");let i="";if(t.getConfig2().state.arrowMarkerAbsolute&&(i=t.getUrl(!0)),h.attr("marker-end","url("+i+"#"+s(k.StateDB.relationType.DEPENDENCY)+"End)"),d.title!==void 0){const o=e.append("g").attr("class","stateLabel"),{x:f,y:g}=N.utils_default.calcLabelPosition(n.points),c=t.common_default.getRows(d.title);let u=0;const B=[];let _=0,E=0;for(let x=0;x<=c.length;x++){const l=o.append("text").attr("text-anchor","middle").text(c[x]).attr("x",f).attr("y",g+u),y=l.node().getBBox();_=Math.max(_,y.width),E=Math.min(E,y.x),w.log.info(y.x,f,g+u),u===0&&(u=l.node().getBBox().height,w.log.info("Title height",u,g)),B.push(l)}let b=u*c.length;if(c.length>1){const x=(c.length-1)*u*.5;B.forEach((l,y)=>l.attr("y",g+y*u-x)),b=u*c.length}const a=o.node().getBBox();o.insert("rect",":first-child").attr("class","box").attr("x",f-_/2-t.getConfig2().state.padding/2).attr("y",g-b/2-t.getConfig2().state.padding/2-3.5).attr("width",_+t.getConfig2().state.padding).attr("height",b+t.getConfig2().state.padding),w.log.info(a)}M++},"drawEdge"),m,q={},Y=C.__name(function(){},"setConf"),O=C.__name(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"),I=C.__name(function(e,n,d,s){m=t.getConfig2().state;const r=t.getConfig2().securityLevel;let p;r==="sandbox"&&(p=w.select_default("#i"+n));const h=r==="sandbox"?w.select_default(p.nodes()[0].contentDocument.body):w.select_default("body"),i=r==="sandbox"?p.nodes()[0].contentDocument:document;w.log.debug("Rendering diagram "+e);const o=h.select(`[id='${n}']`);O(o),H(s.db.getRootDoc(),o.append("g").attr("id",n+"-root"),void 0,!1,h,i,s);const f=m.padding,g=o.node().getBBox(),c=g.width+f*2,u=g.height+f*2,B=c*1.75;t.configureSvgSize(o,u,B,m.useMaxWidth),o.attr("viewBox",`${g.x-m.padding} ${g.y-m.padding} `+c+" "+u)},"draw"),Z=C.__name(e=>e?e.length*m.fontSizeFactor:1,"getLabelWidth"),H=C.__name((e,n,d,s,r,p,h)=>{const i=new z.Graph({compound:!0,multigraph:!0});let o,f=!0;for(o=0;o<e.length;o++)if(e[o].stmt==="relation"){f=!1;break}d?i.setGraph({rankdir:"LR",multigraph:!0,compound:!0,ranker:"tight-tree",ranksep:f?1:m.edgeLengthFactor,nodeSep:f?1:50,isMultiGraph:!0}):i.setGraph({rankdir:"TB",multigraph:!0,compound:!0,ranksep:f?1:m.edgeLengthFactor,nodeSep:f?1:50,ranker:"tight-tree",isMultiGraph:!0}),i.setDefaultEdgeLabel(function(){return{}});const g=h.db.getStates(),c=h.db.getRelations(),u=Object.keys(g);for(const a of u){const x=g[a];d&&(x.parentId=d);let l;if(x.doc){let y=n.append("g").attr("id",x.id).attr("class","stateGroup");l=H(x.doc,y,x.id,!s,r,p,h);{y=W(y,x,s);let S=y.node().getBBox();l.width=S.width,l.height=S.height+m.padding/2,q[x.id]={y:m.compositTitleSize}}}else l=v(n,x,i);if(x.note){const y=v(n,{descriptions:[],id:x.id+"-note",note:x.note,type:"note"},i);x.note.position==="left of"?(i.setNode(l.id+"-note",y),i.setNode(l.id,l)):(i.setNode(l.id,l),i.setNode(l.id+"-note",y)),i.setParent(l.id,l.id+"-group"),i.setParent(l.id+"-note",l.id+"-group")}else i.setNode(l.id,l)}w.log.debug("Count=",i.nodeCount(),i);let B=0;c.forEach(function(a){B++,w.log.debug("Setting edge",a),i.setEdge(a.id1,a.id2,{relation:a,width:Z(a.title),height:m.labelHeight*t.common_default.getRows(a.title).length,labelpos:"c"},"id"+B)}),L.layout(i),w.log.debug("Graph after layout",i.nodes());const _=n.node();i.nodes().forEach(function(a){a!==void 0&&i.node(a)!==void 0?(w.log.warn("Node "+a+": "+JSON.stringify(i.node(a))),r.select("#"+_.id+" #"+a).attr("transform","translate("+(i.node(a).x-i.node(a).width/2)+","+(i.node(a).y+(q[a]?q[a].y:0)-i.node(a).height/2)+" )"),r.select("#"+_.id+" #"+a).attr("data-x-shift",i.node(a).x-i.node(a).width/2),p.querySelectorAll("#"+_.id+" #"+a+" .divider").forEach(x=>{const l=x.parentElement;let y=0,S=0;l&&(l.parentElement&&(y=l.parentElement.getBBox().width),S=parseInt(l.getAttribute("data-x-shift"),10),Number.isNaN(S)&&(S=0)),x.setAttribute("x1",0-S+8),x.setAttribute("x2",y-S-8)})):w.log.debug("No Node "+a+": "+JSON.stringify(i.node(a)))});let E=_.getBBox();i.edges().forEach(function(a){a!==void 0&&i.edge(a)!==void 0&&(w.log.debug("Edge "+a.v+" -> "+a.w+": "+JSON.stringify(i.edge(a))),X(n,i.edge(a),i.edge(a).relation))}),E=_.getBBox();const b={id:d||"root",label:d||"root",width:0,height:0};return b.width=E.width+2*m.padding,b.height=E.height+2*m.padding,w.log.debug("Doc rendered",b,i),b},"renderDoc"),$={parser:k.stateDiagram_default,get db(){return new k.StateDB(1)},renderer:{setConf:Y,draw:I},styles:k.styles_default,init:C.__name(e=>{e.state||(e.state={}),e.state.arrowMarkerAbsolute=e.arrowMarkerAbsolute},"init")};exports.diagram=$;