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