import{o as e}from"./rolldown-runtime-Bhmf7a9N.js";import"./lucide-7srpeIMw.js";import{R as t,T as n,_ as r,hn as i,l as a,mn as o,s,un as c}from"./mermaid-7ea9cbd6-DmivzQ7-.js";import{t as l}from"./graphlib-B7zpM-Rl.js";import"./dagre-GVwvKV-L.js";import{t as u}from"./index-5325376f-B7yS05tn.js";import{a as d,i as f,o as p,r as m,s as h,t as g}from"./styles-ca3715f6-DDs293aW.js";e(i(),1),o();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,i,a,o,c)=>{let l=i.id,u=J(a[l]);if(l!==`root`){let t=_;i.start===!0&&(t=y),i.start===!1&&(t=b),i.type!==`default`&&(t=i.type),W[l]||(W[l]={id:l,shape:t,description:s.sanitizeText(l,r()),classes:`${u} ${E}`});let a=W[l];i.description&&(Array.isArray(a.description)?(a.shape=v,a.description.push(i.description)):a.description.length>0?(a.shape=v,a.description===l?a.description=[i.description]:a.description=[a.description,i.description]):(a.shape=_,a.description=i.description),a.description=s.sanitizeTextOrArray(a.description,r())),a.description.length===1&&a.shape===v&&(a.shape=_),!a.type&&i.doc&&(n.info(`Setting cluster for `,l,Q(i)),a.type=`group`,a.dir=Q(i),a.shape=i.type===`divider`?x:S,a.classes=a.classes+` `+j+` `+(c?M:``));let o={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(o.centerLabel=!0,i.note){let t={labelStyle:``,shape:C,labelText:i.note.text,classes:A,style:``,id:l+L+`-`+G,domId:Y(l,G,P),type:a.type,padding:15},n={labelStyle:``,shape:w,labelText:i.note.text,classes:a.classes,style:``,id:l+R,domId:Y(l,G,N),type:`group`,padding:0};G++;let r=l+R;e.setNode(r,n),e.setNode(t.id,t),e.setNode(l,o),e.setParent(l,r),e.setParent(t.id,r);let s=l,c=t.id;i.note.position===`left of`&&(s=t.id,c=l),e.setEdge(s,c,{arrowhead:`none`,arrowType:``,style:z,labelStyle:``,classes:k,arrowheadStyle:B,labelpos:V,labelType:H,thickness:U})}else e.setNode(l,o)}t&&t.id!==`root`&&(n.trace(`Setting node `,l,` to be child of its parent `,t.id),e.setParent(l,t.id)),i.doc&&(n.trace(`Adding nodes children `),Z(e,i,i.doc,a,o,!c))},Z=(e,t,i,a,o,c)=>{n.trace(`items`,i),i.forEach(n=>{switch(n.stmt){case f:X(e,t,n,a,o,c);break;case g:X(e,t,n,a,o,c);break;case m:{X(e,t,n.state1,a,o,c),X(e,t,n.state2,a,o,c);let i={id:`edge`+G,arrowhead:`normal`,arrowTypeEnd:`arrow_barb`,style:z,labelStyle:``,label:s.sanitizeText(n.description,r()),arrowheadStyle:B,labelpos:V,labelType:H,thickness:U,classes:D};e.setEdge(n.state1.id,n.state2.id,i,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,i,o,s){n.info(`Drawing state diagram (v2)`,i),W={},s.db.getDirection();let{securityLevel:d,state:f}=r(),p=f.nodeSpacing||50,m=f.rankSpacing||50;n.info(s.db.getRootDocV2()),s.db.extract(s.db.getRootDocV2()),n.info(s.db.getRootDocV2());let h=s.db.getStates(),g=new l({multigraph:!0,compound:!0}).setGraph({rankdir:Q(s.db.getRootDocV2()),nodesep:p,ranksep:m,marginx:8,marginy:8}).setDefaultEdgeLabel(function(){return{}});X(g,void 0,s.db.getRootDocV2(),h,s.db,!0);let v;d===`sandbox`&&(v=c(`#i`+i));let y=c(d===`sandbox`?v.nodes()[0].contentDocument.body:`body`),b=y.select(`[id="${i}"]`);await u(y.select(`#`+i+` g`),g,[`barb`],T,i),t.insertTitle(b,`statediagramTitleText`,f.titleTopMargin,s.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="`+i+`"] .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};