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