import{s as e,d as t,p as s,D as o,a,b as r,S as i,c as n}from"./styles-0784dbeb-C75J6JpF.js";import{G as d}from"./graph-CMMNd1iJ.js";import{k as c,e as l,j as p,J as b,n as g,t as h}from"./mermaid-CC8t29Kt.js";import{r as y}from"./index-01f381cb-BTZhYtjS.js";import"./layout-OpUkgN66.js";import"./clone-Pz4U-6so.js";import"./edges-066a5561-DwxP7WHg.js";import"./createText-ca0c5216-CK9IizCN.js";const u="rect",m="rectWithTitle",f="statediagram",x=`${f}-state`,w="transition",$=`${w} note-edge`,T=`${f}-note`,S=`${f}-cluster`,A=`${f}-cluster-alt`,D="parent",j="note",k="----",v=`${k}${j}`,B=`${k}${D}`,E="fill:none",R="fill: #333",V="text",C="normal";let N={},z=0;function L(e="",t=0,s="",o=k){return`state-${e}${null!==s&&s.length>0?`${o}${s}`:""}-${t}`}const M=(e,t,s,o,i,n)=>{const d=s.id,p=null==(b=o[d])?"":b.classes?b.classes.join(" "):"";var b;if("root"!==d){let t=u;!0===s.start&&(t="start"),!1===s.start&&(t="end"),s.type!==a&&(t=s.type),N[d]||(N[d]={id:d,shape:t,description:h.sanitizeText(d,l()),classes:`${p} ${x}`});const o=N[d];s.description&&(Array.isArray(o.description)?(o.shape=m,o.description.push(s.description)):o.description.length>0?(o.shape=m,o.description=o.description===d?[s.description]:[o.description,s.description]):(o.shape=u,o.description=s.description),o.description=h.sanitizeTextOrArray(o.description,l())),1===o.description.length&&o.shape===m&&(o.shape=u),!o.type&&s.doc&&(c.info("Setting cluster for ",d,I(s)),o.type="group",o.dir=I(s),o.shape=s.type===r?"divider":"roundedWithTitle",o.classes=o.classes+" "+S+" "+(n?A:""));const i={labelStyle:"",shape:o.shape,labelText:o.description,classes:o.classes,style:"",id:d,dir:o.dir,domId:L(d,z),type:o.type,padding:15,centerLabel:!0};if(s.note){const t={labelStyle:"",shape:"note",labelText:s.note.text,classes:T,style:"",id:d+v+"-"+z,domId:L(d,z,j),type:o.type,padding:15},a={labelStyle:"",shape:"noteGroup",labelText:s.note.text,classes:o.classes,style:"",id:d+B,domId:L(d,z,D),type:"group",padding:0};z++;const r=d+B;e.setNode(r,a),e.setNode(t.id,t),e.setNode(d,i),e.setParent(d,r),e.setParent(t.id,r);let n=d,c=t.id;"left of"===s.note.position&&(n=t.id,c=d),e.setEdge(n,c,{arrowhead:"none",arrowType:"",style:E,labelStyle:"",classes:$,arrowheadStyle:R,labelpos:"c",labelType:V,thickness:C})}else e.setNode(d,i)}t&&"root"!==t.id&&(c.trace("Setting node ",d," to be child of its parent ",t.id),e.setParent(d,t.id)),s.doc&&(c.trace("Adding nodes children "),G(e,s,s.doc,o,i,!n))},G=(e,t,s,o,r,d)=>{c.trace("items",s),s.forEach(s=>{switch(s.stmt){case n:case a:M(e,t,s,o,r,d);break;case i:{M(e,t,s.state1,o,r,d),M(e,t,s.state2,o,r,d);const a={id:"edge"+z,arrowhead:"normal",arrowTypeEnd:"arrow_barb",style:E,labelStyle:"",label:h.sanitizeText(s.description,l()),arrowheadStyle:R,labelpos:"c",labelType:V,thickness:C,classes:w};e.setEdge(s.state1.id,s.state2.id,a,z),z++}}})},I=(e,t=o)=>{let s=t;if(e.doc)for(let t=0;t<e.doc.length;t++){const o=e.doc[t];"dir"===o.stmt&&(s=o.value)}return s},P={parser:s,db:t,renderer:{setConf:function(e){const t=Object.keys(e);for(const e of t);},getClasses:function(e,t){return t.db.extract(t.db.getRootDocV2()),t.db.getClasses()},draw:async function(e,t,s,o){c.info("Drawing state diagram (v2)",t),N={},o.db.getDirection();const{securityLevel:a,state:r}=l(),i=r.nodeSpacing||50,n=r.rankSpacing||50;c.info(o.db.getRootDocV2()),o.db.extract(o.db.getRootDocV2()),c.info(o.db.getRootDocV2());const h=o.db.getStates(),m=new d({multigraph:!0,compound:!0}).setGraph({rankdir:I(o.db.getRootDocV2()),nodesep:i,ranksep:n,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}});let x;M(m,void 0,o.db.getRootDocV2(),h,o.db,!0),"sandbox"===a&&(x=p("#i"+t));const w=p("sandbox"===a?x.nodes()[0].contentDocument.body:"body"),$=w.select(`[id="${t}"]`),T=w.select("#"+t+" g");await y(T,m,["barb"],f,t),b.insertTitle($,"statediagramTitleText",r.titleTopMargin,o.db.getDiagramTitle());const S=$.node().getBBox(),A=S.width+16,D=S.height+16;$.attr("class",f);const j=$.node().getBBox();g($,D,A,r.useMaxWidth);const k=`${j.x-8} ${j.y-8} ${A} ${D}`;c.debug(`viewBox ${k}`),$.attr("viewBox",k);const v=document.querySelectorAll('[id="'+t+'"] .edgeLabel .label');for(const e of v){const t=e.getBBox(),s=document.createElementNS("http://www.w3.org/2000/svg",u);s.setAttribute("rx",0),s.setAttribute("ry",0),s.setAttribute("width",t.width),s.setAttribute("height",t.height),e.insertBefore(s,e.firstChild)}}},styles:e,init:e=>{e.state||(e.state={}),e.state.arrowMarkerAbsolute=e.arrowMarkerAbsolute,t.clear()}};export{P as diagram};
