1 line
5.4 KiB
JavaScript
1 line
5.4 KiB
JavaScript
import{p as J,d as v,s as Q,D as M,a as X,S as Z,b as F,c as I}from"./styles-0784dbeb-BVDhejU9.js";import{G as tt}from"./graph-ycAwupyV.js";import{l as p,c as g,h as x,u as et,i as ot,j as m}from"./intro-BodfkIHJ.js";import{r as st}from"./index-01f381cb-gs-d4097.js";import"./dayjs.min-BIwLhz4I.js";import"./layout-Eujil20e.js";import"./_baseClone-BMmn5UJb.js";import"./toString-DnxJX3Gz.js";import"./isSymbol-Br3Fhm6g.js";import"./_initCloneObject-D0ofMy5o.js";import"./isObject-C3e4t58V.js";import"./parseCss-DVoar98F.js";import"./index-D0unROMo.js";import"./iframe-D8iLOA0Z.js";import"../sb-preview/runtime.js";import"./index-DwChlhAQ.js";import"./_commonjsHelpers-BosuxZz1.js";import"./index-D-8MO0q_.js";import"./index-DxKRhftL.js";import"./index-DrFu-skq.js";import"./index-CROxjmim.js";import"./docsPage-CrCNk6vV.js";import"./index-CswL0fy2.js";import"./Table-DhJ76JVj.js";import"./_color-UiaLB_4F.js";import"./clone-BwatiCUu.js";import"./edges-066a5561-3oAg0gTk.js";import"./createText-ca0c5216-DzQLIp_i.js";import"./line-B7vJzkqu.js";import"./array-BKyUJesY.js";import"./path-CbwjOpE9.js";import"./toNumber-BrygkUtK.js";import"./_baseSet-DBo-XiK2.js";const h="rect",C="rectWithTitle",nt="start",it="end",rt="divider",ct="roundedWithTitle",lt="note",at="noteGroup",_="statediagram",dt="state",pt=`${_}-${dt}`,H="transition",Et="note",St="note-edge",Tt=`${H} ${St}`,_t=`${_}-${Et}`,ut="cluster",Dt=`${_}-${ut}`,bt="cluster-alt",ft=`${_}-${bt}`,U="parent",V="note",At="state",G="----",ht=`${G}${V}`,B=`${G}${U}`,Y="fill:none",W="fill: #333",z="c",j="text",q="normal";let y={},d=0;const yt=function(t){const n=Object.keys(t);for(const e of n)t[e]},gt=function(t,n){return n.db.extract(n.db.getRootDocV2()),n.db.getClasses()};function $t(t){return t==null?"":t.classes?t.classes.join(" "):""}function R(t="",n=0,e="",i=G){const r=e!==null&&e.length>0?`${i}${e}`:"";return`${At}-${t}${r}-${n}`}const A=(t,n,e,i,r,c)=>{const o=e.id,u=$t(i[o]);if(o!=="root"){let S=h;e.start===!0&&(S=nt),e.start===!1&&(S=it),e.type!==M&&(S=e.type),y[o]||(y[o]={id:o,shape:S,description:m.sanitizeText(o,g()),classes:`${u} ${pt}`});const s=y[o];e.description&&(Array.isArray(s.description)?(s.shape=C,s.description.push(e.description)):s.description.length>0?(s.shape=C,s.description===o?s.description=[e.description]:s.description=[s.description,e.description]):(s.shape=h,s.description=e.description),s.description=m.sanitizeTextOrArray(s.description,g())),s.description.length===1&&s.shape===C&&(s.shape=h),!s.type&&e.doc&&(p.info("Setting cluster for ",o,w(e)),s.type="group",s.dir=w(e),s.shape=e.type===X?rt:ct,s.classes=s.classes+" "+Dt+" "+(c?ft:""));const T={labelStyle:"",shape:s.shape,labelText:s.description,classes:s.classes,style:"",id:o,dir:s.dir,domId:R(o,d),type:s.type,padding:15};if(T.centerLabel=!0,e.note){const l={labelStyle:"",shape:lt,labelText:e.note.text,classes:_t,style:"",id:o+ht+"-"+d,domId:R(o,d,V),type:s.type,padding:15},a={labelStyle:"",shape:at,labelText:e.note.text,classes:s.classes,style:"",id:o+B,domId:R(o,d,U),type:"group",padding:0};d++;const D=o+B;t.setNode(D,a),t.setNode(l.id,l),t.setNode(o,T),t.setParent(o,D),t.setParent(l.id,D);let E=o,b=l.id;e.note.position==="left of"&&(E=l.id,b=o),t.setEdge(E,b,{arrowhead:"none",arrowType:"",style:Y,labelStyle:"",classes:Tt,arrowheadStyle:W,labelpos:z,labelType:j,thickness:q})}else t.setNode(o,T)}n&&n.id!=="root"&&(p.trace("Setting node ",o," to be child of its parent ",n.id),t.setParent(o,n.id)),e.doc&&(p.trace("Adding nodes children "),xt(t,e,e.doc,i,r,!c))},xt=(t,n,e,i,r,c)=>{p.trace("items",e),e.forEach(o=>{switch(o.stmt){case F:A(t,n,o,i,r,c);break;case M:A(t,n,o,i,r,c);break;case Z:{A(t,n,o.state1,i,r,c),A(t,n,o.state2,i,r,c);const u={id:"edge"+d,arrowhead:"normal",arrowTypeEnd:"arrow_barb",style:Y,labelStyle:"",label:m.sanitizeText(o.description,g()),arrowheadStyle:W,labelpos:z,labelType:j,thickness:q,classes:H};t.setEdge(o.state1.id,o.state2.id,u,d),d++}break}})},w=(t,n=I)=>{let e=n;if(t.doc)for(let i=0;i<t.doc.length;i++){const r=t.doc[i];r.stmt==="dir"&&(e=r.value)}return e},Ct=async function(t,n,e,i){p.info("Drawing state diagram (v2)",n),y={},i.db.getDirection();const{securityLevel:r,state:c}=g(),o=c.nodeSpacing||50,u=c.rankSpacing||50;p.info(i.db.getRootDocV2()),i.db.extract(i.db.getRootDocV2()),p.info(i.db.getRootDocV2());const S=i.db.getStates(),s=new tt({multigraph:!0,compound:!0}).setGraph({rankdir:w(i.db.getRootDocV2()),nodesep:o,ranksep:u,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}});A(s,void 0,i.db.getRootDocV2(),S,i.db,!0);let T;r==="sandbox"&&(T=x("#i"+n));const l=r==="sandbox"?x(T.nodes()[0].contentDocument.body):x("body"),a=l.select(`[id="${n}"]`),D=l.select("#"+n+" g");await st(D,s,["barb"],_,n);const E=8;et.insertTitle(a,"statediagramTitleText",c.titleTopMargin,i.db.getDiagramTitle());const b=a.node().getBBox(),N=b.width+E*2,L=b.height+E*2;a.attr("class",_);const P=a.node().getBBox();ot(a,L,N,c.useMaxWidth);const O=`${P.x-E} ${P.y-E} ${N} ${L}`;p.debug(`viewBox ${O}`),a.attr("viewBox",O);const K=document.querySelectorAll('[id="'+n+'"] .edgeLabel .label');for(const $ of K){const k=$.getBBox(),f=document.createElementNS("http://www.w3.org/2000/svg",h);f.setAttribute("rx",0),f.setAttribute("ry",0),f.setAttribute("width",k.width),f.setAttribute("height",k.height),$.insertBefore(f,$.firstChild)}},Rt={setConf:yt,getClasses:gt,draw:Ct},ce={parser:J,db:v,renderer:Rt,styles:Q,init:t=>{t.state||(t.state={}),t.state.arrowMarkerAbsolute=t.arrowMarkerAbsolute,v.clear()}};export{ce as diagram};
|