@dskripchenko/laravel-admin 1.52.1 → 1.53.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ var R=class extends Error{constructor(t,e=0,s=0,n){super(e>0?`${t} (line ${e}${s>0?`, column ${s}`:""})`:t),this.line=e,this.column=s,this.hint=n,this.name="DiagramError"}};function ve(t,e,s){return new R(`The diagram has ${e} ${t}; the limit is ${s}.`,0,0,"Split it into several diagrams.")}var rs='ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',Q={size:14,family:rs},Is={"--dg-font-family":rs,"--dg-text":"#1f2937","--dg-text-muted":"#6b7280","--dg-background":"transparent","--dg-line":"#64748b","--dg-node-fill":"#eef2ff","--dg-node-stroke":"#6366f1","--dg-node-text":"#1e1b4b","--dg-cluster-fill":"#f8fafc","--dg-cluster-stroke":"#cbd5e1","--dg-cluster-text":"#334155","--dg-edge-label-fill":"#ffffff","--dg-note-fill":"#fef9c3","--dg-note-stroke":"#ca8a04","--dg-note-text":"#422006","--dg-actor-fill":"#eef2ff","--dg-actor-stroke":"#6366f1","--dg-activation-fill":"#e0e7ff","--dg-block-stroke":"#94a3b8","--dg-block-label-fill":"#e2e8f0","--dg-grid":"#e5e7eb","--dg-task-fill":"#818cf8","--dg-task-stroke":"#4f46e5","--dg-task-done-fill":"#cbd5e1","--dg-task-done-stroke":"#64748b","--dg-task-active-fill":"#c7d2fe","--dg-task-crit-fill":"#f87171","--dg-task-crit-stroke":"#b91c1c","--dg-task-text":"#ffffff","--dg-task-text-dark":"#1f2937","--dg-exclude-fill":"rgba(148, 163, 184, 0.18)","--dg-today":"#ef4444","--dg-section-fill-0":"rgba(99, 102, 241, 0.06)","--dg-section-fill-1":"rgba(100, 116, 139, 0.06)","--dg-state-start":"#1f2937","--dg-lifeline":"#94a3b8","--dg-number-text":"#ffffff","--dg-rect-fill":"rgba(148, 163, 184, 0.12)","--dg-pie-stroke":"#ffffff","--dg-pie-text":"#ffffff"},Me=["#6366f1","#f59e0b","#10b981","#ef4444","#06b6d4","#8b5cf6","#84cc16","#ec4899","#f97316","#14b8a6","#64748b","#a855f7"];function Te(t){const e=t%Me.length;return`var(--dg-pie-${e+1}, ${Me[e]})`}function N(t){const e=Is[t];return e===void 0?`var(${t})`:`var(${t}, ${e})`}function Ls(t,e=""){const s=`#${t}`;return[`${s}{font-family:${N("--dg-font-family")};font-size:${Q.size}px;color:${N("--dg-text")}}`,`${s} text{fill:${N("--dg-text")}}`,`${s} .dg-label{fill:${N("--dg-node-text")}}`,`${s} .dg-node .dg-shape{fill:${N("--dg-node-fill")};stroke:${N("--dg-node-stroke")};stroke-width:1.5px}`,`${s} .dg-cluster-box{fill:${N("--dg-cluster-fill")};stroke:${N("--dg-cluster-stroke")};stroke-width:1px}`,`${s} .dg-cluster-label{fill:${N("--dg-cluster-text")};font-weight:600}`,`${s} .dg-edge{fill:none;stroke:${N("--dg-line")};stroke-width:1.5px}`,`${s} .dg-edge-thick{stroke-width:3.5px}`,`${s} .dg-edge-dotted{stroke-dasharray:3 3}`,`${s} .dg-marker{fill:${N("--dg-line")};stroke:${N("--dg-line")}}`,`${s} .dg-edge-label-box{fill:${N("--dg-edge-label-fill")};opacity:0.9}`,`${s} .dg-edge-label{fill:${N("--dg-text")}}`,`${s} .dg-muted{fill:${N("--dg-text-muted")}}`,`${s} a{cursor:pointer}`,e].filter(Boolean).join("")}var ls=/^[a-zA-Z][a-zA-Z0-9:_-]*$/;function v(t,e={},s=[]){if(!ls.test(t))throw new Error(`Invalid SVG tag name: ${t}`);return{tag:t,attrs:e,children:s.filter(n=>!!n)}}function kt(t){return{text:t}}function Ds(t){return t.replace(/[&<>]/g,e=>e==="&"?"&amp;":e==="<"?"&lt;":"&gt;")}function Ns(t){return t.replace(/[&<>"']/g,e=>{switch(e){case"&":return"&amp;";case"<":return"&lt;";case">":return"&gt;";case'"':return"&quot;";default:return"&#39;"}})}function V(t){if(!Number.isFinite(t))return"0";const e=Math.round(t*100)/100;return Object.is(e,-0)?"0":String(e)}function Rs(t){let e="";for(const[s,n]of Object.entries(t))if(!(n==null||n===!1)){if(!ls.test(s))throw new Error(`Invalid SVG attribute name: ${s}`);n===!0?e+=` ${s}=""`:typeof n=="number"?e+=` ${s}="${V(n)}"`:e+=` ${s}="${Ns(n)}"`}return e}function as(t){if("text"in t)return Ds(t.text);const e=Rs(t.attrs);return t.children.length===0?`<${t.tag}${e}/>`:`<${t.tag}${e}>${t.children.map(as).join("")}</${t.tag}>`}var vt=class{constructor(){this.parts=[]}moveTo(t,e){return this.parts.push(`M${V(t)},${V(e)}`),this}lineTo(t,e){return this.parts.push(`L${V(t)},${V(e)}`),this}curveTo(t,e,s,n,o,i){return this.parts.push(`C${V(t)},${V(e)} ${V(s)},${V(n)} ${V(o)},${V(i)}`),this}quadTo(t,e,s,n){return this.parts.push(`Q${V(t)},${V(e)} ${V(s)},${V(n)}`),this}arcTo(t,e,s,n,o,i,r){return this.parts.push(`A${V(t)},${V(e)} ${V(s)} ${n?1:0},${o?1:0} ${V(i)},${V(r)}`),this}close(){return this.parts.push("Z"),this}toString(){return this.parts.join(" ")}};function Os(t){let e=2166136261;for(let s=0;s<t.length;s++)e^=t.charCodeAt(s),e=Math.imul(e,16777619);return`dg-${(e>>>0).toString(36)}`}function _s(t){const e=t.replace(/[^a-zA-Z0-9_-]/g,"-");return/^[a-zA-Z]/.test(e)?e:`dg-${e}`}function Ot(t){const e=Math.ceil(t.width+16),s=Math.ceil(t.height+16),n=`${t.id}-title`;return{svg:as(v("svg",{xmlns:"http://www.w3.org/2000/svg",id:t.id,class:`dg dg-${t.type}`,width:e,height:s,viewBox:`0 0 ${e} ${s}`,role:"img","aria-labelledby":n,style:"max-width:100%;height:auto"},[v("title",{id:n},[kt(t.title)]),t.description?v("desc",{},[kt(t.description)]):null,v("style",{},[kt(Ls(t.id,t.css))]),t.defs&&t.defs.length>0?v("defs",{},t.defs):null,v("g",{transform:"translate(8,8)"},t.body)])),width:e,height:s,type:t.type}}var ue=1.25,Ws=[278,278,355,556,556,889,667,191,333,333,389,584,278,333,278,278,556,556,556,556,556,556,556,556,556,556,278,278,584,584,584,556,1015,667,667,722,722,667,611,778,722,278,500,667,556,833,722,778,667,778,722,667,611,722,667,944,667,667,611,278,278,278,469,556,333,556,556,500,556,556,278,556,556,222,222,500,222,833,556,556,556,556,333,500,278,556,500,722,500,500,500,334,260,334,584],Fs=1.06,Bs=new Set("гзтэсеё".split("")),Us=new Set("жмшщюыЖМШЩЮЫФф".split(""));function zs(t){const e=t.codePointAt(0)??0;return e>=32&&e<=126?Ws[e-32]??556:e>=1024&&e<=1279?Us.has(t)?800:Bs.has(t)?470:t===t.toUpperCase()?690:545:e>=11904&&e<=40959||e>=44032&&e<=55215||e>=63744&&e<=64255||e>=65280&&e<=65519||e>=127744&&e<=129791||e===8212||e===8230?1e3:e===8211?556:e===160?278:600}var Ps=(t,e)=>{let s=0;for(const o of t)s+=zs(o);let n=s/1e3*e.size*Fs;return e.weight==="bold"&&(n*=1.07),{width:n,height:e.size*ue}},gt;function Ys(){if(gt!==void 0)return gt;gt=null;try{const t=globalThis;if(t.navigator?.userAgent?.includes("jsdom"))return gt;typeof t.OffscreenCanvas=="function"?gt=new t.OffscreenCanvas(1,1).getContext("2d"):t.document&&typeof t.document.createElement=="function"&&(gt=t.document.createElement("canvas").getContext("2d")),gt&&gt.measureText("M").width<=0&&(gt=null)}catch{gt=null}return gt}function cs(t){return`${t.style==="italic"?"italic ":""}${t.weight==="bold"?"bold ":""}${t.size}px ${t.family}`}function Hs(t){const e=new Map;return(s,n)=>{const o=`${cs(n)}\0${s}`;let i=e.get(o);return i||(i=t(s,n),e.size>5e3&&e.clear(),e.set(o,i)),i}}function js(){const t=Ys();return t?Hs((e,s)=>(t.font=cs(s),{width:t.measureText(e).width,height:s.size*ue})):Ps}var qs={quot:'"',amp:"&",lt:"<",gt:">",apos:"'",nbsp:" ",semi:";",colon:":",num:"#",hash:"#"};function zt(t){return t.replace(/#(x[0-9a-fA-F]+|[0-9]+|[a-zA-Z]+);/g,(e,s)=>{if(s[0]==="x"||s[0]==="X"){const n=parseInt(s.slice(1),16);return Se(n)?String.fromCodePoint(n):e}if(/^[0-9]+$/.test(s)){const n=parseInt(s,10);return Se(n)?String.fromCodePoint(n):e}return qs[s.toLowerCase()]??e})}function Se(t){return t>0&&t<=1114111&&!(t>=55296&&t<=57343)}var Xs=/<br\s*\/?>/gi;function oe(t){const e=[],s=/(\*\*|__)(.+?)\1|(\*|_)(.+?)\3/g;let n=0;for(const o of t.matchAll(s)){const i=o.index??0;if(i>n&&e.push({text:t.slice(n,i)}),o[2]!==void 0)for(const r of oe(o[2]))e.push({...r,bold:!0});else if(o[4]!==void 0)for(const r of oe(o[4]))e.push({...r,italic:!0});n=i+o[0].length}return n<t.length&&e.push({text:t.slice(n)}),e.filter(o=>o.text.length>0)}function lt(t,e={}){const s=zt(t),n=(e.markdown?s.split(/\r?\n|<br\s*\/?>/i).map(o=>o.trim()):s.split(Xs)).map(o=>e.markdown?oe(o):o.length>0?[{text:o}]:[]);return{lines:n.length>0?n:[[]]}}function Nt(t){return{lines:t.split(`
2
+ `).map(e=>e.length>0?[{text:e}]:[])}}function ds(t){return t.lines.every(e=>e.every(s=>s.text.trim()===""))}function Gs(t,e){return{...e,weight:t.bold?"bold":e.weight,style:t.italic?"italic":e.style}}function ie(t,e,s){let n=0;for(const o of t)n+=s(o.text,Gs(o,e)).width;return n}function ge(t,e,s,n){const o=[];for(const i of t.lines){if(ie(i,s,n)<=e){o.push(i);continue}const r=[[]];for(const h of i){const b=h.text.split(/( +)/);for(const p of b)/^ +$/.test(p)?r.push([]):p.length>0&&r[r.length-1].push({...h,text:p})}let a=[],c=0;const l=n(" ",s).width;for(const h of r){if(h.length===0)continue;const b=ie(h,s,n);a.length>0&&c+l+b>e&&(o.push(a),a=[],c=0),a.length>0&&(a.push({...h[0],text:" "}),c+=l),a.push(...h),c+=b}o.push(a)}return{lines:o}}function st(t,e,s){const n=e.size*ue;let o=0;for(const i of t.lines)o=Math.max(o,ie(i,e,s));return{label:t,width:o,height:n*t.lines.length,lineHeight:n}}function tt(t,e,s,n={}){const{label:o,lineHeight:i}=t,r=s-i*o.lines.length/2,a=o.lines.map((c,l)=>{const h=r+i*l+i/2,b=c.map(p=>p.bold||p.italic?v("tspan",{"font-weight":p.bold?"bold":void 0,"font-style":p.italic?"italic":void 0,"dominant-baseline":"central"},[kt(p.text)]):kt(p.text));return v("tspan",{x:e,y:h,"dominant-baseline":"central"},b.length>0?b:[kt("")])});return v("text",{class:n.className??"dg-label","text-anchor":n.anchor??"middle","dominant-baseline":"central",style:n.style},a)}function Ks(t){let e=!1;for(let s=0;s<t.length;s++){const n=t[s];if(n==='"'&&(e=!e),!e&&n==="%"&&t[s+1]==="%")return t.slice(0,s)}return t}function St(t,e={}){const s=[],n=t.replace(/\r\n?/g,`
3
+ `).split(`
4
+ `);let o=!1;return n.forEach((i,r)=>{const a=r+1;if(o){i.includes("}%%")&&(o=!1);return}if(i.trimStart().startsWith("%%{")){i.includes("}%%")||(o=!0);return}const c=Ks(i),l=e.semicolons?Zs(c):[{text:c,offset:0}];for(const h of l){const b=h.text.length-h.text.trimStart().length,p=h.text.trim();p.length!==0&&s.push({text:p,line:a,column:h.offset+b+1})}}),s}function Zs(t){const e=[];let s=0,n=!1,o=0;for(let i=0;i<t.length;i++){const r=t[i];r==='"'&&(n=!n),!n&&("([{".includes(r)?s++:")]}".includes(r)?s=Math.max(0,s-1):r===";"&&s===0&&(e.push({text:t.slice(o,i),offset:o}),o=i+1))}return e.push({text:t.slice(o),offset:o}),e}function hs(t){const e=St(t)[0];if(!e)return null;const s=/^([A-Za-z][\w-]*)\s*(.*)$/.exec(e.text);return s?{keyword:s[1],rest:s[2].trim(),statement:e}:null}var Vs=class{constructor(t,e=t.text){this.statement=t,this.text=e,this.pos=0}get done(){return this.pos>=this.text.length}peek(t=0){return this.text[this.pos+t]??""}rest(){return this.text.slice(this.pos)}skipSpaces(){for(;!this.done&&/\s/.test(this.text[this.pos]);)this.pos++}startsWith(t){return this.text.startsWith(t,this.pos)}eat(t){return this.startsWith(t)?(this.pos+=t.length,!0):!1}match(t){const e=new RegExp(t.source,t.flags.replace("g","")+"y");e.lastIndex=this.pos;const s=e.exec(this.text);return s&&(this.pos+=s[0].length),s}column(t=this.pos){return this.statement.column+t}error(t,e,s=this.pos){return new R(t,this.statement.line,this.column(s),e)}};function Yt(t){const e=t.trim();return e.length>=2&&e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function _t(t,e,s){const n=t[e];let o=/^accTitle\s*:\s*(.*)$/.exec(n.text);if(o)return s.title=o[1].trim(),1;if(o=/^accDescr\s*:\s*(.*)$/.exec(n.text),o)return s.description=o[1].trim(),1;if(o=/^accDescr\s*\{\s*(.*)$/.exec(n.text),o){const i=[];let r=o[1],a=e;for(;;){const c=r.indexOf("}");if(c>=0){i.push(r.slice(0,c));break}if(i.push(r),a++,a>=t.length)break;r=t[a].text}return s.description=i.map(c=>c.trim()).filter(Boolean).join(" "),a-e+1}return 0}function Js(t){const e=St(t),s=e[0];if(!s||!/^pie\b/.test(s.text))throw new R('A pie chart starts with "pie"',s?.line??1,1);const n={type:"pie",showData:!1,slices:[],accessibility:{}};let o=s.text.slice(3).trim();if(/^showData\b/.test(o)&&(n.showData=!0,o=o.slice(8).trim()),/^title\b/.test(o))n.title=o.slice(5).trim();else if(o!=="")throw new R(`Unexpected "${o}" after "pie"`,s.line,s.column+4);for(let i=1;i<e.length;i++){const r=e[i],a=_t(e,i,n.accessibility);if(a>0){i+=a-1;continue}if(/^title\b/.test(r.text)){n.title=r.text.slice(5).trim();continue}if(/^showData$/.test(r.text)){n.showData=!0;continue}const c=/^("(?:[^"]*)"|'(?:[^']*)')\s*:\s*(-?[0-9]+(?:\.[0-9]+)?)\s*$/.exec(r.text);if(!c)throw new R(`"${r.text}" is not a slice`,r.line,r.column,'Write "Label" : 42');const l=Number(c[2]);if(l<0)throw new R("A slice cannot be negative",r.line,r.column);n.slices.push({label:Yt(c[1].replace(/^'|'$/g,'"')),value:l})}if(n.slices.length===0)throw new R("The pie chart has no slices",0,0,'Add lines like "Label" : 42');return n}var pt=130,Gt=14;function Qs(t){return Number.isInteger(t)?String(t):String(Math.round(t*100)/100)}function tn(t,e,s,n){const o=t.slices.reduce((O,P)=>O+P.value,0);if(o<=0)throw new R("All slices are zero",0,0);const i={...Q,size:18,weight:"bold"},r=t.title?st(Nt(t.title),i,e):null,a=r?r.height+16:0,c=pt,l=a+pt,h=[],b=[],p=[];let u=-Math.PI/2;const d=t.slices.filter(O=>O.value>0);t.slices.forEach((O,P)=>{if(O.value<=0)return;const m=O.value/o,w=m*Math.PI*2,M=Te(P);if(d.length===1)b.push(v("circle",{class:"dg-pie-slice",cx:c,cy:l,r:pt,style:`fill:${M}`}));else{const C=u,B=u+w,D=new vt().moveTo(c,l).lineTo(c+pt*Math.cos(C),l+pt*Math.sin(C)).arcTo(pt,pt,0,w>Math.PI,!0,c+pt*Math.cos(B),l+pt*Math.sin(B)).close();b.push(v("path",{class:"dg-pie-slice",d:D.toString(),style:`fill:${M}`}))}if(m>=.03){const C=u+w/2,B=d.length===1?0:pt*.68,D=`${Math.round(m*1e3)/10}%`;p.push(tt(st(Nt(D),Q,e),c+B*Math.cos(C),l+B*Math.sin(C),{className:"dg-pie-percent"}))}u+=w});const f=288,y=22,T=t.slices.length*y,$=l-T/2;let k=0;const S=t.slices.map((O,P)=>{const m=st(lt(t.showData?`${O.label} [${Qs(O.value)}]`:O.label),Q,e);k=Math.max(k,22+m.width);const w=$+P*y+y/2;return v("g",{class:"dg-pie-legend-item"},[v("rect",{x:f,y:w-Gt/2,width:Gt,height:Gt,rx:3,style:`fill:${Te(P)}`}),tt(m,310,w,{anchor:"start",className:"dg-pie-legend"})])}),E=f+k,I=Math.max(l+pt,$+T);r&&t.title&&h.push(tt(r,E/2,r.height/2,{className:"dg-title"})),h.push(v("g",{class:"dg-pie-slices"},b),v("g",{},p),v("g",{},S));const L=[`#${s} .dg-pie-slice{stroke:${N("--dg-pie-stroke")};stroke-width:2px}`,`#${s} .dg-pie-percent{fill:${N("--dg-pie-text")};font-weight:600}`,`#${s} .dg-pie-legend{fill:${N("--dg-text")}}`,`#${s} .dg-title{fill:${N("--dg-text")};font-size:18px;font-weight:bold}`].join("");return Ot({id:s,type:"pie",width:E,height:I,title:n??t.accessibility.title??t.title??"Pie chart",description:t.accessibility.description,body:h,css:L})}var re=/^(#[0-9a-fA-F]{3,4}|#[0-9a-fA-F]{6}|#[0-9a-fA-F]{8}|(rgb|rgba|hsl|hsla)\(\s*[0-9.]+%?\s*,\s*[0-9.]+%?\s*,\s*[0-9.]+%?\s*(,\s*[0-9.]+%?\s*)?\)|[a-zA-Z]{3,20})$/,fs=/^[0-9]+(\.[0-9]+)?(px|em)?$/,en=/^[0-9.]+([\s,]+[0-9.]+)*$/,Kt=/^(0(\.[0-9]+)?|1(\.0+)?)$/,Ee={fill:re,stroke:re,"stroke-width":fs,"stroke-dasharray":en,opacity:Kt,"fill-opacity":Kt,"stroke-opacity":Kt},Ae={color:re,"font-weight":/^(normal|bold|[1-9]00)$/,"font-style":/^(normal|italic)$/,"font-size":fs};function $t(t,e=0,s=0){const n={shape:{},text:{}};for(const o of sn(t)){const i=o.trim();if(i==="")continue;const r=i.indexOf(":");if(r<0)throw new R(`"${i}" is not a style declaration`,e,s,"Write property:value.");const a=i.slice(0,r).trim().toLowerCase(),c=i.slice(r+1).trim().replace(/\s*!important$/,""),l=Ee[a],h=Ae[a];if(!l&&!h)throw new R(`The style property "${a}" is not supported`,e,s,`Supported: ${[...Object.keys(Ee),...Object.keys(Ae)].join(", ")}.`);if(!(l??h).test(c))throw new R(`"${c}" is not a valid value for ${a}`,e,s);l?n.shape[a]=c:n.text[a==="color"?"fill":a]=c}return n}function sn(t){const e=[];let s=0,n=0;for(let o=0;o<t.length;o++){const i=t[o];i==="("?s++:i===")"?s=Math.max(0,s-1):(i===","||i===";")&&s===0&&(e.push(t.slice(n,o)),n=o+1)}return e.push(t.slice(n)),e}function us(...t){const e={shape:{},text:{}};for(const s of t)s&&(Object.assign(e.shape,s.shape),Object.assign(e.text,s.text));return e}function ut(t){const e=Object.entries(t);if(e.length!==0)return e.map(([s,n])=>`${s}:${n}`).join(";")}function gs(t){const e=t.trim();return/^(https?:|mailto:)/i.test(e)?e:/^[a-z][a-z0-9+.-]*:/i.test(e)||e.startsWith("//")?null:e}var pe=1e3,me=60*pe,we=60*me,ct=24*we,ps=7*ct,Ce=["January","February","March","April","May","June","July","August","September","October","November","December"],le=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Ie=Object.fromEntries(le.map((t,e)=>[t.toLowerCase(),e])),nn=[["YYYY","year","(\\d{4})"],["SSS","ms","(\\d{3})"],["YY","year2","(\\d{2})"],["MM","month","(\\d{2})"],["DD","day","(\\d{2})"],["HH","hour","(\\d{2})"],["mm","minute","(\\d{2})"],["ss","second","(\\d{2})"],["M","month","(\\d{1,2})"],["D","day","(\\d{1,2})"],["H","hour","(\\d{1,2})"],["m","minute","(\\d{1,2})"],["s","second","(\\d{1,2})"],["X","unix","(\\d+(?:\\.\\d+)?)"],["x","unixMs","(\\d+)"]],on=["MMMM","MMM","dddd","ddd","dd","Do","hh","A","a","ZZ","Z","Q","w","W","k","h","d"],ms=class extends Error{};function Le(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ws(t){const e=[];let s=0;t:for(;s<t.length;){if(t[s]==="["){const n=t.indexOf("]",s);if(n>s){e.push({pattern:Le(t.slice(s+1,n)),literal:""}),s=n+1;continue}}for(const n of on)if(t.startsWith(n,s))throw new ms(`The date token "${n}" is not supported`);for(const[n,o,i]of nn)if(t.startsWith(n,s)){e.push({field:o,pattern:i}),s+=n.length;continue t}e.push({pattern:Le(t[s]),literal:t[s]}),s++}return{source:t,regex:new RegExp(`^${e.map(n=>n.pattern).join("")}$`),fields:e.filter(n=>n.field).map(n=>n.field)}}function xs(t,e){return new Date(Date.UTC(t,e+1,0)).getUTCDate()}function Ht(t,e){const s=e.regex.exec(t.trim());if(!s)return null;let n=1970,o=1,i=1,r=0,a=0,c=0,l=0;for(let h=0;h<e.fields.length;h++){const b=s[h+1],p=Number(b);switch(e.fields[h]){case"unix":return Math.round(p*1e3);case"unixMs":return p;case"year":n=p;break;case"year2":n=2e3+p;break;case"month":o=p;break;case"day":i=p;break;case"hour":r=p;break;case"minute":a=p;break;case"second":c=p;break;case"ms":l=p}}return o<1||o>12||i<1||i>xs(n,o-1)||r>23||a>59||c>59?null:Date.UTC(n,o-1,i,r,a,c,l)}var rn=/^(\d+(?:\.\d+)?)(ms|[smhdwMy])$/;function ln(t){const e=rn.exec(t.trim());return e?{amount:Number(e[1]),unit:e[2]}:null}function an(t,e){const{amount:s,unit:n}=e;switch(n){case"ms":return t+s;case"s":return t+s*pe;case"m":return t+s*me;case"h":return t+s*we;case"d":return t+s*ct;case"w":return t+s*ps;case"M":return De(t,s);case"y":return De(t,s*12)}}function De(t,e){const s=Math.trunc(e),n=new Date(t),o=n.getUTCMonth()+s,i=n.getUTCFullYear()+Math.floor(o/12),r=(o%12+12)%12,a=Math.min(n.getUTCDate(),xs(i,r));return Date.UTC(i,r,a,n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds(),n.getUTCMilliseconds())+(e-s)*30*ct}function Rt(t){return Math.floor(t/ct)*ct}function ys(t){return new Date(t).getUTCDay()}function Ne(t){return new Date(Rt(t)).toISOString().slice(0,10)}function cn(t,e,s){const n=String(t);return n.length>=e?n:s.repeat(e-n.length)+n}var dn="aAbBdeHIjLmMpSuwyY%";function Re(t){for(let e=0;e<t.length;e++){if(t[e]!=="%")continue;let s=e+1;"-_0".includes(t[s]??"")&&s++;const n=t[s];if(!n||!dn.includes(n))return t.slice(e,s+1);e=s}return null}function Oe(t,e){const s=new Date(t);let n="";for(let o=0;o<e.length;o++){const i=e[o];if(i!=="%"){n+=i;continue}let r=null,a=e[o+1]??"";"-_0".includes(a)&&a!==""&&(r=a,a=e[o+2]??"",o++),o++;const c=(l,h,b)=>r==="-"?String(l):cn(l,h,r==="_"?" ":r==="0"?"0":b);switch(a){case"Y":n+=String(s.getUTCFullYear());break;case"y":n+=c(s.getUTCFullYear()%100,2,"0");break;case"m":n+=c(s.getUTCMonth()+1,2,"0");break;case"d":n+=c(s.getUTCDate(),2,"0");break;case"e":n+=c(s.getUTCDate(),2," ");break;case"H":n+=c(s.getUTCHours(),2,"0");break;case"I":n+=c(s.getUTCHours()%12||12,2,"0");break;case"M":n+=c(s.getUTCMinutes(),2,"0");break;case"S":n+=c(s.getUTCSeconds(),2,"0");break;case"L":n+=c(s.getUTCMilliseconds(),3,"0");break;case"p":n+=s.getUTCHours()<12?"AM":"PM";break;case"j":{const l=Date.UTC(s.getUTCFullYear(),0,1);n+=c(Math.floor((Rt(t)-l)/ct)+1,3,"0");break}case"a":n+=le[s.getUTCDay()].slice(0,3);break;case"A":n+=le[s.getUTCDay()];break;case"b":n+=Ce[s.getUTCMonth()].slice(0,3);break;case"B":n+=Ce[s.getUTCMonth()];break;case"w":n+=String(s.getUTCDay());break;case"u":n+=String(s.getUTCDay()||7);break;case"%":n+="%";break;default:n+=`%${a}`}}return n}var hn={millisecond:"ms",second:"s",minute:"m",hour:"h",day:"d",week:"w",month:"M"};function fn(t){const e=/^([1-9][0-9]*)(millisecond|second|minute|hour|day|week|month)$/.exec(t.trim());return e?{step:Number(e[1]),unit:hn[e[2]]}:null}var bs={ms:1,s:pe,m:me,h:we,d:ct,w:ps};function un(t){return t.unit==="M"?t.step*30*ct:t.step*bs[t.unit]}function _e(t,e,s,n=1e3){const o=[];if(s.unit==="M"){const a=new Date(t);let c=a.getUTCFullYear(),l=a.getUTCMonth();l-=l%s.step;let h=Date.UTC(c,l,1);for(;h<=e&&o.length<n;)h>=t&&o.push(h),l+=s.step,c+=Math.floor(l/12),l%=12,h=Date.UTC(c,l,1);return o}const i=bs[s.unit]*s.step;let r;if(s.unit==="w"){const a=Rt(t);r=a-ys(a)*ct}else s.unit==="d"?r=Rt(t):r=Math.floor(t/i)*i;for(;r<t;)r+=i;for(;r<=e&&o.length<n;)o.push(r),r+=i;return o}var gn=[{unit:"s",step:1},{unit:"s",step:5},{unit:"s",step:15},{unit:"s",step:30},{unit:"m",step:1},{unit:"m",step:5},{unit:"m",step:15},{unit:"m",step:30},{unit:"h",step:1},{unit:"h",step:3},{unit:"h",step:6},{unit:"h",step:12},{unit:"d",step:1},{unit:"d",step:2},{unit:"w",step:1},{unit:"w",step:2},{unit:"M",step:1},{unit:"M",step:3},{unit:"M",step:6},{unit:"M",step:12},{unit:"M",step:24},{unit:"M",step:60}],pn=["done","active","crit","milestone"],mn=new Set(["title","dateFormat","axisFormat","tickInterval","excludes","includes","weekend","todayMarker","topAxis","inclusiveEndDates","section","click","displayMode"]);function wn(t){const e=St(t),s=e[0];if(!s||!/^gantt$/.test(s.text))throw new R('A gantt chart starts with "gantt"',s?.line??1,s?.column??1);const n={type:"gantt",dateFormat:"YYYY-MM-DD",axisFormat:"%Y-%m-%d",axisFormatSet:!1,excludes:[],includes:[],todayMarker:"on",topAxis:!1,inclusiveEndDates:!1,sections:[],tasks:[],excludedRanges:[],accessibility:{}};let o=[6,0],i=s;const r=[],a=[];let c="",l=0;const h=new Map;for(let d=1;d<e.length;d++){const f=e[d],y=_t(e,d,n.accessibility);if(y>0){d+=y-1;continue}const T=/^([A-Za-z]+)(?:\s+(.*))?$/.exec(f.text),$=T?.[1]??"",k=(T?.[2]??"").trim();if(mn.has($)||!f.text.includes(":"))switch($){case"title":n.title=zt(k);continue;case"dateFormat":n.dateFormat=k,i=f;continue;case"axisFormat":if(Re(k))throw new R(`The axis format directive "${Re(k)}" is not supported`,f.line,f.column,"Supported: %Y %y %m %d %e %H %I %M %S %L %p %j %a %A %b %B %w %u %%.");n.axisFormat=k,n.axisFormatSet=!0;continue;case"tickInterval":{const w=fn(k);if(!w)throw new R(`"${k}" is not a tick interval`,f.line,f.column,"Write e.g. 1day, 2week, 1month.");n.tickInterval=w;continue}case"excludes":for(const w of We(k))n.excludes.push(w),h.set(w,f);continue;case"includes":n.includes.push(...We(k));continue;case"weekend":if(k==="friday")o=[5,6];else if(k==="saturday")o=[6,0];else throw new R(`"${k}" cannot start a weekend`,f.line,f.column,"Write friday or saturday.");continue;case"todayMarker":n.todayMarker=k===""?"on":k;continue;case"topAxis":n.topAxis=!0;continue;case"inclusiveEndDates":n.inclusiveEndDates=!0;continue;case"section":c=zt(k);continue;case"click":{const w=/^(\S+)\s+href\s+("[^"]*"|\S+)\s*$/.exec(k);if(!w)throw new R('Only "click <id> href <url>" is supported',f.line,f.column,"Callbacks are not run: a diagram cannot execute code.");const M=gs(Yt(w[2]));if(M===null)throw new R(`The link "${Yt(w[2])}" is not allowed`,f.line,f.column,"Use http(s), mailto or a relative link.");for(const C of w[1].split(","))a.push({id:C.trim(),href:M,statement:f});continue}case"displayMode":throw new R("displayMode is not supported",f.line,f.column,"Remove the line; every task gets its own row.");default:throw new R(`"${f.text}" is not a task`,f.line,f.column,"Write: Task name : 2024-01-01, 3d")}const S=f.text.indexOf(":"),E=zt(f.text.slice(0,S).trim());if(E==="")throw new R("The task has no name",f.line,f.column);const I=f.text.slice(S+1).split(",").map(w=>w.trim()),L={done:!1,active:!1,crit:!1,milestone:!1};for(;I.length>0&&pn.includes(I[0]);)L[I.shift()]=!0;if(I.some(w=>w===""))throw new R("The task has an empty item",f.line,f.column+S+1);let O=`task${++l}`,P=null,m;if(I.length===1)m=I[0];else if(I.length===2)P=I[0],m=I[1];else if(I.length===3)O=I[0],P=I[1],m=I[2];else throw new R(I.length===0?"The task has no dates":"The task has too many items",f.line,f.column+S+1,"Write: [tags,] [id,] [start,] end or duration");if(/\s/.test(O))throw new R(`"${O}" cannot be a task id: it contains a space`,f.line,f.column+S+1);if(r.some(w=>w.id===O))throw new R(`The task id "${O}" is used twice`,f.line,f.column+S+1);if(P===null&&r.length===0)throw new R("The first task needs a start date",f.line,f.column+S+1,"Write: Task : 2024-01-01, 3d");r.push({id:O,name:E,section:c,tags:L,startSpec:P,endSpec:m,statement:f})}let b;try{b=ws(n.dateFormat)}catch(d){throw d instanceof ms?new R(d.message,i.line,i.column):d}const p=xn(n,b,o,h),u=new Map(r.map(d=>[d.id,d]));r.forEach((d,f)=>ae(d,f,r,u,b,n,p));for(const d of a){const f=u.get(d.id);if(!f)throw new R(`No task has the id "${d.id}"`,d.statement.line,d.statement.column);f.href=d.href}for(const d of r)n.sections.includes(d.section)||n.sections.push(d.section),n.tasks.push({id:d.id,name:d.name,section:d.section,tags:d.tags,start:d.start,end:d.end,renderEnd:d.renderEnd,href:d.href,line:d.statement.line});if(p&&n.tasks.length>0){const d=Rt(Math.min(...n.tasks.map(y=>y.start))),f=Math.max(...n.tasks.map(y=>y.end));for(let y=d;y<f&&y<d+316224e6;y+=ct){if(!p(y))continue;const T=n.excludedRanges[n.excludedRanges.length-1];T&&T.end===y?T.end=y+ct:n.excludedRanges.push({start:y,end:y+ct})}}return n}function We(t){return t.split(/[\s,]+/).map(e=>e.trim().toLowerCase()).filter(Boolean)}function xn(t,e,s,n){if(t.excludes.length===0)return null;const o=new Set,i=new Set,r=ws("YYYY-MM-DD"),a=l=>{const h=Ht(l,e)??Ht(l,r);return h===null?null:Ne(h)};for(const l of t.excludes)if(l==="weekends")o.add(s[0]),o.add(s[1]);else if(l in Ie)o.add(Ie[l]);else{const h=a(l);if(h===null){const b=n.get(l);throw new R(`"${l}" in excludes is neither a weekday nor a date`,b?.line??0,b?.column??0)}i.add(h)}const c=new Set(t.includes.map(a).filter(l=>l!==null));return l=>{const h=Ne(l);return c.has(h)?!1:o.has(ys(l))||i.has(h)}}function At(t,e,s,n){const o=t.statement.text.indexOf(":"),i=n?t.statement.text.indexOf(n,o):-1;return new R(e,t.statement.line,t.statement.column+(i>=0?i:o+1),s)}function ae(t,e,s,n,o,i,r){if(t.end!==void 0)return;if(t.resolving)throw At(t,`The task "${t.name}" depends on itself through "after" or "until"`);t.resolving=!0;const a=u=>{const d=n.get(u);if(!d)throw At(t,`No task has the id "${u}"`,void 0,u);return ae(d,s.indexOf(d),s,n,o,i,r),d};let c;if(t.startSpec===null){const u=s[e-1];ae(u,e-1,s,n,o,i,r),c=u.end}else if(/^after\s/.test(t.startSpec)){const u=t.startSpec.slice(5).trim().split(/\s+/);c=Math.max(...u.map(d=>a(d).end))}else{const u=Ht(t.startSpec,o);if(u===null)throw At(t,`"${t.startSpec}" is not a date in the format ${o.source}`,void 0,t.startSpec);c=u}let l,h=!1;const b=ln(t.endSpec);if(b)l=an(c,b);else if(/^until\s/.test(t.endSpec)){const u=t.endSpec.slice(5).trim().split(/\s+/);l=Math.min(...u.map(d=>a(d).start)),h=!0}else{const u=Ht(t.endSpec,o);if(u===null)throw At(t,`"${t.endSpec}" is neither a duration nor a date in the format ${o.source}`,"Durations: 3d, 2w, 4h, 30m, 1M.",t.endSpec);l=i.inclusiveEndDates?u+ct:u,h=!0}if(l<c)throw At(t,`The task "${t.name}" ends before it starts`);let p=l;if(r&&!h&&!t.tags.milestone){let u=c,d=!1,f=0;for(;u<=l&&f++<1e5;)d||(p=l),d=r(u),d&&(l+=ct),u+=ct}t.start=c,t.end=l,t.renderEnd=Math.max(c,Math.min(p,l)),t.manualEnd=h,t.resolving=!1}var Ct=28,Zt=20,Ft=24,Fe=160,Be=800,yn={...Q,size:13},Ue={...Q,size:12},ze={...Q,weight:"bold"},bn={...Q,size:18,weight:"bold"},kn=1e3,It=1.12;function $n(t){switch(t.unit){case"ms":return"%H:%M:%S.%L";case"s":return"%H:%M:%S";case"m":case"h":return"%H:%M";case"M":return t.step>=12?"%Y":"%b %Y";default:return"%Y-%m-%d"}}function vn(t){return{lines:[lt(t).lines.flatMap((e,s)=>s===0?e:[{text:" "},...e])]}}function Mn(t){const e=["dg-task"];return t.tags.milestone&&e.push("dg-milestone"),t.tags.done&&e.push("dg-task-done"),t.tags.active&&e.push("dg-task-active"),t.tags.crit&&e.push("dg-task-crit"),e.join(" ")}function Tn(t,e,s,n,o){const i=t.tasks;if(i.length===0)throw new R("The gantt chart has no tasks",0,0,"Add lines like: Task : 2024-01-01, 3d");let r=Math.min(...i.map(F=>F.start)),a=Math.max(...i.map(F=>F.end));a<=r&&(r-=ct/2,a+=ct/2);const c=t.sections.filter(F=>F!==""),l=new Map(c.map(F=>[F,st(ge(lt(F),Fe,ze,e),ze,e)])),h=c.length>0?Math.min(Fe,Math.max(...[...l.values()].map(F=>F.width)))+24:0,b=h,p=Math.min(Be,Math.max(480,Be-h)),u=b+p,d=F=>b+(F-r)/(a-r)*p;let f=[],y=t.axisFormat;const T=F=>t.axisFormatSet?t.axisFormat:$n(F),$=(F,j)=>Math.max(0,...F.map(G=>e(Oe(G,j),Ue).width));if(t.tickInterval){if(f=_e(r,a,t.tickInterval,1001),f.length>kn)throw new R("tickInterval puts more than 1000 ticks on the axis",0,0,"Choose a longer interval.");y=T(t.tickInterval)}else for(const F of gn){if((a-r)/un(F)>80)continue;const j=_e(r,a,F);if(f=j,y=T(F),j.length*($(j,y)+16)<=p)break}const k=t.title?st(Nt(t.title),bn,e):null,S=(k?k.height+14:0)+(t.topAxis?Ft:0)+4,E=S+i.length*Ct,I=E+Ft,L=[],O=[];let P=0,m=u,w=0;i.forEach((F,j)=>{const G=i[j+1];if(G&&G.section===F.section)return;const J=t.sections.indexOf(F.section),it=S+w*Ct,x=(j-w+1)*Ct;L.push(v("rect",{class:`dg-gantt-section dg-gantt-section-${J%2}`,x:0,y:it,width:u,height:x}));const A=l.get(F.section);A&&O.push(tt(A,12,it+x/2,{anchor:"start",className:"dg-gantt-section-label"})),w=j+1});for(const F of t.excludedRanges){const j=Math.max(b,d(F.start)),G=Math.min(u,d(F.end));G>j&&L.push(v("rect",{class:"dg-gantt-exclude",x:j,y:S,width:G-j,height:E-S}))}const M=F=>f.map(j=>{const G=st(Nt(Oe(j,y)),Ue,e),J=d(j);return P=Math.min(P,J-G.width/2),m=Math.max(m,J+G.width/2),tt(G,J,F,{className:"dg-gantt-axis"})});if(L.push(v("g",{class:"dg-gantt-grid"},f.map(F=>v("line",{x1:d(F),y1:S,x2:d(F),y2:E})))),O.push(v("g",{},M(E+Ft/2))),t.topAxis&&O.push(v("g",{},M(S-Ft/2))),i.forEach((F,j)=>{const G=S+j*Ct+Ct/2,J=st(vn(F.name),yn,e),it=[],x=Mn(F);let A,W,X=!1;if(F.tags.milestone){const ot=(d(F.start)+d(F.renderEnd))/2,at=Zt/2;it.push(v("polygon",{class:x,points:`${V(ot)},${V(G-at)} ${V(ot+at)},${V(G)} ${V(ot)},${V(G+at)} ${V(ot-at)},${V(G)}`})),A=ot+at+6,W="start"}else{const ot=d(F.start),at=Math.max(2,d(F.renderEnd)-ot),mt=ot+at;it.push(v("rect",{class:x,x:ot,y:G-Zt/2,width:at,height:Zt,rx:3,ry:3})),J.width*It+12<=at?(X=!0,A=ot+at/2,W="middle"):mt+6+J.width*It<=u||ot-6-J.width*It<b?(A=mt+6,W="start"):(A=ot-6,W="end")}X||(W==="start"&&(m=Math.max(m,A+J.width*It)),W==="end"&&(P=Math.min(P,A-J.width*It)));const nt=X?`dg-task-text dg-task-text-inside${F.tags.done||F.tags.active?" dg-task-text-dark":""}`:"dg-task-text";it.push(tt(J,A,G,{anchor:W,className:nt}));const dt=v("g",{class:"dg-gantt-task","data-id":F.id},it);O.push(F.href?v("a",{href:F.href},[dt]):dt)}),o&&t.todayMarker!=="off"){const F=o.getTime();if(F>=r&&F<=a){const j=t.todayMarker==="on"?void 0:ut($t(t.todayMarker).shape);O.push(v("line",{class:"dg-gantt-today",x1:d(F),y1:S-4,x2:d(F),y2:E+4,style:j}))}}const C=Math.ceil(-P),B=m-P,D=[];k&&D.push(tt(k,B/2,k.height/2,{className:"dg-title"})),D.push(v("g",{transform:C>0?`translate(${C},0)`:void 0},[...L,...O]));const U=`#${s}`,Z=[`${U} .dg-title{fill:${N("--dg-text")};font-size:18px;font-weight:bold}`,`${U} .dg-gantt-section-0{fill:${N("--dg-section-fill-0")}}`,`${U} .dg-gantt-section-1{fill:${N("--dg-section-fill-1")}}`,`${U} .dg-gantt-section-label{fill:${N("--dg-text")};font-weight:bold}`,`${U} .dg-gantt-exclude{fill:${N("--dg-exclude-fill")}}`,`${U} .dg-gantt-grid line{stroke:${N("--dg-grid")};stroke-width:1px}`,`${U} .dg-gantt-axis{fill:${N("--dg-text-muted")};font-size:12px}`,`${U} .dg-task{fill:${N("--dg-task-fill")};stroke:${N("--dg-task-stroke")};stroke-width:1px}`,`${U} .dg-task-active{fill:${N("--dg-task-active-fill")}}`,`${U} .dg-task-done{fill:${N("--dg-task-done-fill")};stroke:${N("--dg-task-done-stroke")}}`,`${U} .dg-task-crit{fill:${N("--dg-task-crit-fill")};stroke:${N("--dg-task-crit-stroke")}}`,`${U} .dg-task-crit.dg-task-done{fill:${N("--dg-task-done-fill")};stroke:${N("--dg-task-crit-stroke")};stroke-width:2px}`,`${U} .dg-task-crit.dg-task-active{fill:${N("--dg-task-active-fill")};stroke:${N("--dg-task-crit-stroke")};stroke-width:2px}`,`${U} .dg-task-text{fill:${N("--dg-text")};font-size:13px}`,`${U} .dg-task-text-inside{fill:${N("--dg-task-text")}}`,`${U} .dg-task-text-dark{fill:${N("--dg-task-text-dark")}}`,`${U} .dg-gantt-today{stroke:${N("--dg-today")};stroke-width:2px}`].join("");return Ot({id:s,type:"gantt",width:B,height:I,title:n??t.accessibility.title??t.title??"Gantt chart",description:t.accessibility.description,body:D,css:Z})}var Pe={TB:"TB",TD:"TB",BT:"BT",LR:"LR",RL:"RL"},Sn=[{open:"(((",close:")))",shape:"doublecircle"},{open:"((",close:"))",shape:"circle"},{open:"([",close:"])",shape:"stadium"},{open:"[[",close:"]]",shape:"subroutine"},{open:"[(",close:")]",shape:"cylinder"},{open:"{{",close:"}}",shape:"hexagon"},{open:"[/",close:["/]","\\]"],shape:t=>t==="/]"?"parallelogram":"trapezoid"},{open:"[\\",close:["\\]","/]"],shape:t=>t==="\\]"?"parallelogram-alt":"trapezoid-alt"},{open:">",close:"]",shape:"asymmetric"},{open:"[",close:"]",shape:"rect"},{open:"(",close:")",shape:"round"},{open:"{",close:"}",shape:"rhombus"}],En=/[\p{L}\p{N}_](?:[\p{L}\p{N}_.$]|-(?=[\p{L}\p{N}_]))*/u;function Bt(t){return t===">"||t==="<"?"arrow":t==="x"?"cross":t==="o"?"circle":"none"}function Ye(t){const e=t.peek();return e===""||/[\s|&"]/.test(e)||/[[({>]/.test(e)===!1&&!/[\p{L}\p{N}_]/u.test(e)}function An(t,e){const s=Array.isArray(e)?e:[e];if(t.skipSpaces(),t.peek()==='"'){const r=t.pos,a=t.text.indexOf('"',r+1);if(a<0)throw t.error("The quoted text is not closed",'Add the closing "');let c=t.text.slice(r+1,a),l=!1;c.startsWith("`")&&c.endsWith("`")&&c.length>=2&&(c=c.slice(1,-1),l=!0),t.pos=a+1,t.skipSpaces();for(const h of s)if(t.eat(h))return{text:c,markdown:l,close:h};throw t.error(`Expected ${s.join(" or ")} after the text`)}let n=-1,o="";for(const r of s){const a=t.text.indexOf(r,t.pos);a>=0&&(n<0||a<n)&&(n=a,o=r)}if(n<0)throw t.error(`The shape is not closed: expected ${s.join(" or ")}`);const i=t.text.slice(t.pos,n).trim();return t.pos=n+o.length,{text:i,markdown:!1,close:o}}function Cn(t){const e=t.pos;t.skipSpaces();for(const{re:s,stroke:n}of[{re:/([<xo])?--(?![->.])\s*("[^"]*"|[^-|]+?)\s*(-{2,})([>xo]?)/u,stroke:"normal"},{re:/([<xo])?==(?![=>])\s*("[^"]*"|[^=|]+?)\s*(={2,})([>xo]?)/u,stroke:"thick"},{re:/([<xo])?-\.(?![-.])\s*("[^"]*"|[^.|]+?)\s*(\.+)-([>xo]?)/u,stroke:"dotted"}]){const o=t.pos,i=t.match(s);if(!i)continue;const r=i[3],a=i[4]??"";if(n!=="dotted"&&a===""&&r.length<3){t.pos=o;continue}if(a&&/[xo]/.test(a)&&!Ye(t)){t.pos=o;continue}let c=i[2].trim(),l=!1;c.startsWith('"')&&c.endsWith('"')&&(c=c.slice(1,-1)),c.startsWith("`")&&c.endsWith("`")&&c.length>=2&&(c=c.slice(1,-1),l=!0);const h=n==="dotted"?r.length:Math.max(1,r.length-(a?1:2));return{stroke:n,start:Bt(i[1]),end:Bt(a),length:h,text:c,markdown:l}}for(const{re:s,stroke:n}of[{re:/~{3,}/,stroke:"invisible"},{re:/([<xo])?-(\.+)-([>xo])?/,stroke:"dotted"},{re:/([<xo])?(={2,})([>xo])?/,stroke:"thick"},{re:/([<xo])?(-{2,})([>xo])?/,stroke:"normal"}]){const o=t.pos,i=t.match(s);if(!i)continue;if(n==="invisible")return{stroke:n,start:"none",end:"none",length:Math.max(1,i[0].length-2),markdown:!1};const r=i[2];let a=i[3];if(a&&/[xo]/.test(a)&&!Ye(t)&&(t.pos-=1,a=void 0),!a&&n!=="dotted"&&r.length<3){t.pos=o;continue}const c=n==="dotted"?r.length:Math.max(1,r.length-(a?1:2)),l={stroke:n,start:Bt(i[1]),end:Bt(a),length:c,markdown:!1},h=t.match(/\s*\|\s*("[^"]*"|[^|]*?)\s*\|/);if(h){let b=h[1].trim();b.startsWith('"')&&b.endsWith('"')&&(b=b.slice(1,-1)),b.startsWith("`")&&b.endsWith("`")&&b.length>=2&&(b=b.slice(1,-1),l.markdown=!0),l.text=b}return l}return t.pos=e,null}function In(t){t.skipSpaces();const e=t.match(En);if(!e)return null;const s={id:e[0],classes:[]};if(t.startsWith("@{"))throw t.error("The @{ shape: … } node syntax is not supported","Use the bracket shapes, e.g. A([text]).");for(const o of Sn){if(!t.startsWith(o.open))continue;if(o.open===">"&&t.peek(-1)==="-")break;t.pos+=o.open.length;const{text:i,markdown:r,close:a}=An(t,o.close);s.text=i,s.markdown=r,s.shape=typeof o.shape=="function"?o.shape(a):o.shape;break}const n=t.match(/:::([\w-]+)/);return n&&s.classes.push(n[1]),s}function Vt(t){return t.split(",").map(e=>e.trim()).filter(Boolean)}function Ln(t){const e=St(t,{semicolons:!0}),s=e[0],n=s?/^(flowchart|graph|flowchart-elk)\b\s*(\S*)\s*$/.exec(s.text):null;if(!s||!n)throw new R('A flowchart starts with "flowchart" or "graph"',s?.line??1,1);let o="TB";if(n[2]){const u=Pe[n[2].toUpperCase()];if(!u)throw new R(`"${n[2]}" is not a direction`,s.line,s.column+n[1].length+1,"Use TB, TD, BT, LR or RL.");o=u}const i={type:"flowchart",direction:o,nodes:new Map,edges:[],subgraphs:new Map,classDefs:new Map,accessibility:{}},r=[],a=[],c=[],l=[],h=[];let b=0;const p=u=>{let d=i.nodes.get(u.id);d||(d={id:u.id,text:u.id,markdown:!1,shape:"rect",classes:[]},i.nodes.set(u.id,d)),u.text!==void 0&&(d.text=u.text,d.markdown=u.markdown??!1),u.shape&&(d.shape=u.shape),d.classes.push(...u.classes);const f=r[r.length-1];return f&&d.subgraph===void 0&&!i.subgraphs.has(u.id)&&(d.subgraph=f.id),d};for(let u=1;u<e.length;u++){const d=e[u],f=d.text,y=_t(e,u,i.accessibility);if(y>0){u+=y-1;continue}let T=/^subgraph\b\s*(.*)$/.exec(f);if(T){const L=T[1].trim();let O,P,m=!1;const w=/^([\p{L}\p{N}_.-]+)\s*\[\s*(.*?)\s*\]$/u.exec(L);if(w?(O=w[1],P=w[2]):L.startsWith('"')?(P=L,O=`subgraph${b++}`):L===""?(O=`subgraph${b++}`,P=""):(O=L.replace(/\s+/g,"_"),P=L),P.startsWith('"')&&P.endsWith('"')&&P.length>=2&&(P=P.slice(1,-1)),P.startsWith("`")&&P.endsWith("`")&&P.length>=2&&(P=P.slice(1,-1),m=!0),i.subgraphs.has(O))throw new R(`Subgraph "${O}" is defined twice`,d.line,d.column);const M={id:O,title:P,markdown:m,parent:r[r.length-1]?.id,classes:[]};i.subgraphs.set(O,M),i.nodes.delete(O),r.push(M);continue}if(f==="end"){if(r.length===0)throw new R('"end" without a subgraph',d.line,d.column);r.pop();continue}if(T=/^direction\s+(\w+)$/.exec(f),T){const L=Pe[T[1].toUpperCase()];if(!L)throw new R(`"${T[1]}" is not a direction`,d.line,d.column+10);const O=r[r.length-1];O?O.direction=L:i.direction=L;continue}if(T=/^classDef\s+([\w,-]+)\s+(.+)$/.exec(f),T){const L=$t(T[2],d.line,d.column);for(const O of Vt(T[1]))i.classDefs.set(O,L);continue}if(T=/^class\s+(.+?)\s+([\w-]+)$/.exec(f),T){a.push({ids:Vt(T[1]),cls:T[2],s:d});continue}if(T=/^style\s+(\S+)\s+(.+)$/.exec(f),T){c.push({id:T[1],style:$t(T[2],d.line,d.column),s:d});continue}if(T=/^linkStyle\s+(default|[\d\s,]+?)\s+(?:interpolate\s+\w+\s*)?(.*)$/.exec(f),T){const L=T[1]==="default"?"default":Vt(T[1]).map(Number);l.push({which:L,style:$t(T[2]??"",d.line,d.column),s:d});continue}if(T=/^click\s+(\S+)\s+(.*)$/.exec(f),T){const L=T[2],O=/^(?:href\s+)?"([^"]*)"(?:\s+"([^"]*)")?(?:\s+(_blank|_self|_parent|_top))?\s*$/.exec(L);O&&h.push({id:T[1],href:O[1],tooltip:O[2],target:O[3],s:d});continue}const $=new Vs(d),k=[],S=()=>{const L=[];for(;;){const O=In($);if(!O)throw $.error(L.length===0?"Expected a node":'Expected a node after "&"');if(L.push(O),$.skipSpaces(),!$.eat("&"))break}return L};k.push(S());const E=[];for(;$.skipSpaces(),!$.done;){const L=Cn($);if(!L)throw $.error(`Unexpected "${$.rest()}"`,"Expected an edge such as --> or the end of the line.");E.push(L),k.push(S())}const I=k.map(L=>L.map(O=>i.subgraphs.has(O.id)&&!O.shape?O.id:p(O).id));E.forEach((L,O)=>{for(const P of I[O])for(const m of I[O+1])i.edges.push({from:P,to:m,stroke:L.stroke,start:L.start,end:L.end,length:L.length,text:L.text,markdown:L.markdown})})}if(r.length>0)throw new R(`Subgraph "${r[r.length-1].id}" is not closed`,0,0,'Add "end".');for(const u of a)for(const d of u.ids){const f=i.nodes.get(d)??i.subgraphs.get(d);if(!f)throw new R(`class refers to an unknown node "${d}"`,u.s.line,u.s.column);f.classes.push(u.cls)}for(const u of c){const d=i.nodes.get(u.id)??i.subgraphs.get(u.id);if(!d)throw new R(`style refers to an unknown node "${u.id}"`,u.s.line,u.s.column);d.style=u.style}for(const u of l){if(u.which==="default"){for(const d of i.edges)d.style={shape:{...d.style?.shape,...u.style.shape},text:{...d.style?.text,...u.style.text}};continue}for(const d of u.which){const f=i.edges[d];if(!f)throw new R(`linkStyle refers to edge ${d}, but there are ${i.edges.length}`,u.s.line,u.s.column);f.style=u.style}}for(const u of h){const d=i.nodes.get(u.id);if(!d)throw new R(`click refers to an unknown node "${u.id}"`,u.s.line,u.s.column);const f=gs(u.href);if(f===null)throw new R(`The link "${u.href}" is not allowed`,u.s.line,u.s.column,"Use http(s), mailto or a relative address.");d.link={href:f,tooltip:u.tooltip,target:u.target}}return i}function Dn(t,e){return Math.hypot(e.x-t.x,e.y-t.y)}function Pt(t,e){const s=e.x-t.x,n=e.y-t.y,o=t.width/2,i=t.height/2;if(s===0&&n===0)return{x:t.x,y:t.y+i};let r,a;return Math.abs(n)*o>Math.abs(s)*i?(a=n<0?-i:i,r=a*s/n):(r=s<0?-o:o,a=r*n/s),{x:t.x+r,y:t.y+a}}function Nn(t,e,s,n){const o=n.x-t.x,i=n.y-t.y;if(o===0&&i===0)return{x:t.x,y:t.y+s};const r=1/Math.sqrt(o*o/(e*e)+i*i/(s*s));return{x:t.x+o*r,y:t.y+i*r}}function Rn(t,e,s){let n=null,o=1/0;const i=s.x-t.x,r=s.y-t.y;for(let a=0;a<e.length;a++){const c=e[a],l=e[(a+1)%e.length],h=l.x-c.x,b=l.y-c.y,p=i*b-r*h;if(Math.abs(p)<1e-9)continue;const u=((c.x-t.x)*b-(c.y-t.y)*h)/p,d=((c.x-t.x)*r-(c.y-t.y)*i)/p;u>0&&d>=-1e-9&&d<=1+1e-9&&u<o&&(o=u,n={x:t.x+i*u,y:t.y+r*u})}return n??{x:t.x,y:t.y}}function On(t,e=.5){const s=[];for(const n of t){const o=s[s.length-1];(!o||Dn(o,n)>e)&&s.push(n)}return s}function ks(t){const e=On(t),s=new vt;if(e.length===0)return"";if(e.length===1)return s.moveTo(e[0].x,e[0].y).toString();let n=0,o=0,i=0,r=0;const a=(l,h)=>{s.curveTo((2*n+i)/3,(2*o+r)/3,(n+2*i)/3,(o+2*r)/3,(n+4*i+l)/6,(o+4*r+h)/6)};let c=0;for(const l of e)c===0?(c=1,s.moveTo(l.x,l.y)):c===1?c=2:(c===2&&(c=3,s.lineTo((5*n+i)/6,(5*o+r)/6)),a(l.x,l.y)),n=i,i=l.x,o=r,r=l.y;return c===3&&a(i,r),s.lineTo(i,r),s.toString()}function Tt(t,e,s=!1){return`${t}-m-${e}${s?"-start":""}`}function xe(t,e){const s=[];for(const n of new Set(e))for(const o of[!1,!0])s.push(_n(t,n,o));return s}function _n(t,e,s){const n={id:Tt(t,e,s),markerUnits:"userSpaceOnUse",orient:"auto"},o=s?"translate(10,0) scale(-1,1)":void 0;switch(e){case"arrow":return v("marker",{...n,viewBox:"0 0 10 10",refX:s?1:9,refY:5,markerWidth:10,markerHeight:10},[v("path",{class:"dg-marker",d:"M0,0 L10,5 L0,10 z",transform:o,"stroke-width":1})]);case"open-arrow":return v("marker",{...n,viewBox:"0 0 10 10",refX:s?1:9,refY:5,markerWidth:10,markerHeight:10},[v("path",{class:"dg-marker dg-marker-open",d:"M1,1 L9,5 L1,9",transform:o,style:"fill:none","stroke-width":1.5})]);case"half-arrow":return v("marker",{...n,viewBox:"0 0 10 10",refX:s?1:9,refY:5,markerWidth:10,markerHeight:10},[v("path",{class:"dg-marker",d:"M0,0 L10,5 L0,5 z",transform:o,"stroke-width":1})]);case"circle":return v("marker",{...n,viewBox:"0 0 10 10",refX:s?1:9,refY:5,markerWidth:9,markerHeight:9},[v("circle",{class:"dg-marker",cx:5,cy:5,r:4,"stroke-width":1})]);case"cross":return v("marker",{...n,viewBox:"0 0 10 10",refX:5,refY:5,markerWidth:11,markerHeight:11},[v("path",{class:"dg-marker",d:"M1,1 L9,9 M1,9 L9,1","stroke-width":2,style:"fill:none"})])}}function Wn(t){return t.map(e=>`${He(e.x)},${He(e.y)}`).join(" ")}function He(t){return Math.round(t*100)/100}function $s(t,e){return e.map(s=>({x:t.x+s.x,y:t.y+s.y}))}function vs(t,e,s){const n=e/2,o=s/2;switch(t){case"rhombus":case"choice":return[{x:0,y:-o},{x:n,y:0},{x:0,y:o},{x:-n,y:0}];case"hexagon":{const i=Math.min(s/2,e/4);return[{x:-n+i,y:-o},{x:n-i,y:-o},{x:n,y:0},{x:n-i,y:o},{x:-n+i,y:o},{x:-n,y:0}]}case"parallelogram":{const i=s/2;return[{x:-n+i,y:-o},{x:n,y:-o},{x:n-i,y:o},{x:-n,y:o}]}case"parallelogram-alt":{const i=s/2;return[{x:-n,y:-o},{x:n-i,y:-o},{x:n,y:o},{x:-n+i,y:o}]}case"trapezoid":{const i=s/2;return[{x:-n+i,y:-o},{x:n-i,y:-o},{x:n,y:o},{x:-n,y:o}]}case"trapezoid-alt":{const i=s/2;return[{x:-n,y:-o},{x:n,y:-o},{x:n-i,y:o},{x:-n+i,y:o}]}case"asymmetric":{const i=s/2;return[{x:-n,y:-o},{x:n,y:-o},{x:n,y:o},{x:-n,y:o},{x:-n+i,y:0}]}default:return null}}function ce(t,e,s){const n=e+32,o=s+18;switch(t){case"start":return{width:14,height:14};case"end":return{width:18,height:18};case"fork":return{width:70,height:8};case"choice":return{width:28,height:28};case"circle":{const i=Math.max(e,s)+18;return{width:i,height:i}}case"doublecircle":{const i=Math.max(e,s)+18+10;return{width:i,height:i}}case"rhombus":{const i=e+s+18;return{width:Math.max(i,40),height:Math.max(i*.75,40)}}case"hexagon":return{width:n+o/2,height:o};case"parallelogram":case"parallelogram-alt":case"trapezoid":case"trapezoid-alt":return{width:n+o/2,height:o};case"asymmetric":return{width:n+o/4,height:o};case"stadium":return{width:n+o/2,height:o};case"subroutine":return{width:n+16,height:o};case"cylinder":return{width:n,height:o+16};default:return{width:n,height:o}}}function de(t,e,s={}){const n=s.className??"dg-shape",o=s.style,{x:i,y:r,width:a,height:c}=e,l=i-a/2,h=r-c/2,b=vs(t,a,c);if(b)return v("polygon",{class:n,style:o,points:Wn($s(e,b))});switch(t){case"round":return v("rect",{class:n,style:o,x:l,y:h,width:a,height:c,rx:6,ry:6});case"stadium":return v("rect",{class:n,style:o,x:l,y:h,width:a,height:c,rx:c/2,ry:c/2});case"circle":return v("circle",{class:n,style:o,cx:i,cy:r,r:a/2});case"doublecircle":return v("g",{},[v("circle",{class:n,style:o,cx:i,cy:r,r:a/2}),v("circle",{class:n,style:o,cx:i,cy:r,r:a/2-5})]);case"subroutine":return v("g",{},[v("rect",{class:n,style:o,x:l,y:h,width:a,height:c}),v("line",{class:n,style:o,x1:l+8,y1:h,x2:l+8,y2:h+c}),v("line",{class:n,style:o,x1:l+a-8,y1:h,x2:l+a-8,y2:h+c})]);case"cylinder":{const u=a/2,d=new vt().moveTo(l,h+8).arcTo(u,8,0,!1,!1,l+a,h+8).lineTo(l+a,h+c-8).arcTo(u,8,0,!1,!0,l,h+c-8).close(),f=new vt().moveTo(l,h+8).arcTo(u,8,0,!1,!0,l+a,h+8);return v("g",{},[v("path",{class:n,style:o,d:d.toString()}),v("path",{class:n,style:o,d:f.toString(),"fill-opacity":0})])}case"start":return v("circle",{class:"dg-state-start",cx:i,cy:r,r:a/2});case"end":return v("g",{},[v("circle",{class:"dg-state-end-ring",cx:i,cy:r,r:a/2}),v("circle",{class:"dg-state-start",cx:i,cy:r,r:a/2-4})]);case"fork":return v("rect",{class:"dg-state-start",x:l,y:h,width:a,height:c,rx:2});default:return v("rect",{class:n,style:o,x:l,y:h,width:a,height:c})}}function he(t,e,s){const n=vs(t,e.width,e.height);if(n)return Rn(e,$s(e,n),s);switch(t){case"circle":case"doublecircle":case"start":case"end":return Nn(e,e.width/2,e.height/2,s);default:return Pt(e,s)}}var Fn=class{constructor(){this.nodes=new Map,this.edges=[],this.outMap=new Map,this.inMap=new Map}addNode(t){const e={...t,rank:0,order:0,x:0,y:0};return this.nodes.set(e.id,e),this.outMap.set(e.id,[]),this.inMap.set(e.id,[]),e}node(t){const e=this.nodes.get(t);if(!e)throw new Error(`Unknown node ${t}`);return e}addEdge(t){return this.edges.push(t),this.outMap.get(t.v).push(t),this.inMap.get(t.w).push(t),t}removeEdge(t){const e=s=>{const n=s.indexOf(t);n>=0&&s.splice(n,1)};e(this.edges),e(this.outMap.get(t.v)),e(this.inMap.get(t.w))}out(t){return this.outMap.get(t)??[]}in(t){return this.inMap.get(t)??[]}reindex(){for(const t of this.nodes.keys())this.outMap.set(t,[]),this.inMap.set(t,[]);for(const t of this.edges)this.outMap.get(t.v).push(t),this.inMap.get(t.w).push(t)}};function ye(t,e){const s=[];let n=t;for(;n;)s.unshift(n),n=e.get(n)??null;return s}function Bn(t){const e=[];for(const s of t.nodes.values())(e[s.rank]??=[]).push(s);for(let s=0;s<e.length;s++)e[s]??=[];return e}function Un(t,e){const s=new Set,n=e.map(()=>0),o=[...t.nodes.values()].sort((i,r)=>i.rank-r.rank);for(const i of o){if(s.has(i.id))continue;const r=[i];for(;r.length>0;){const a=r.pop();if(s.has(a.id))continue;s.add(a.id),a.order=n[a.rank]++;const c=t.out(a.id).map(l=>t.node(l.w));for(let l=c.length-1;l>=0;l--)s.has(c[l].id)||r.push(c[l])}}for(const i of e)i.sort((r,a)=>r.order-a.order)}function Jt(t,e,s,n){const o={nodes:[],children:new Map,items:[]};for(const c of t){let l=o;for(const h of ye(c.cluster,s)){let b=l.children.get(h);b||(b={cluster:h,nodes:[],children:new Map,items:[]},l.children.set(h,b),l.items.push(h)),l=b}l.nodes.push(c),l.items.push(c)}const i=new Map,r=c=>{const l=i.get(c);if(l!==void 0)return l;let h=0,b=0;const p=d=>{for(const f of d.nodes)h+=e.get(f.id),b++;for(const f of d.children.values())p(f)};p(c);const u=b>0?h/b:0;return i.set(c,u),u},a=c=>{const l=c.items.map((u,d)=>({item:u,index:d,k:typeof u=="string"?r(c.children.get(u)):e.get(u.id)}));l.sort((u,d)=>u.k-d.k||u.index-d.index);const h=l.flatMap((u,d)=>typeof u.item=="string"?[d]:[]),b=h.map(u=>l[u].item).sort((u,d)=>(n.get(u)??0)-(n.get(d)??0));h.forEach((u,d)=>{l[u].item=b[d]});const p=[];for(const u of l)typeof u.item=="string"?p.push(...a(c.children.get(u.item))):p.push(u.item);return p};return a(o)}function zn(t,e,s){const n=new Map(s.map((c,l)=>[c.id,l])),o=[];e.forEach((c,l)=>{for(const h of t.out(c.id)){const b=n.get(h.w);b!==void 0&&o.push({u:l,l:b,w:h.weight||1})}}),o.sort((c,l)=>c.u-l.u||c.l-l.l);let i=1;for(;i<s.length;)i<<=1;const r=new Array(2*i-1).fill(0);i-=1;let a=0;for(const c of o){let l=c.l+i;r[l]+=c.w;let h=0;for(;l>0;)l%2&&(h+=r[l+1]),l=l-1>>1,r[l]+=c.w;a+=c.w*h}return a}function Pn(t,e,s,n){const o=l=>{const h=new Map;return l.forEach((b,p)=>{for(const u of ye(b.cluster,n)){const d=h.get(u);d?d.to=p:h.set(u,{from:p,to:p})}}),h},i=o(e),r=o(s);if(i.size===0||r.size===0)return 0;const a=new Map(s.map((l,h)=>[l.id,h]));let c=0;return e.forEach((l,h)=>{for(const b of t.out(l.id)){const p=a.get(b.w);if(p!==void 0)for(const[u,d]of i){const f=r.get(u);f&&(h<d.from&&p>f.to||h>d.to&&p<f.from)&&(c+=2)}}}),c}function je(t,e,s=new Map){let n=0;for(let o=0;o+1<e.length;o++)n+=zn(t,e[o],e[o+1]),s.size>0&&(n+=Pn(t,e[o],e[o+1],s));return n}function qe(t,e){const s=new Map,n=new Map;for(const i of t)i.forEach((r,a)=>{const c=i.length>1?a/(i.length-1):.5;for(const l of ye(r.cluster,e))s.set(l,(s.get(l)??0)+c),n.set(l,(n.get(l)??0)+1)});const o=new Map;for(const[i,r]of s)o.set(i,r/n.get(i));return o}function Yn(t,e,s=24){const n=Bn(t);Un(t,n);let o=qe(n,e);for(let l=0;l<n.length;l++){const h=new Map(n[l].map((b,p)=>[b.id,p]));n[l]=Jt(n[l],h,e,o)}const i=l=>l.forEach(h=>h.forEach((b,p)=>b.order=p));i(n);let r=n.map(l=>l.slice()),a=je(t,n,e),c=0;for(let l=0;l<s&&a>0&&c<4;l++){const h=l%2===0,b=h?Array.from({length:n.length-1},(f,y)=>y+1):Array.from({length:n.length-1},(f,y)=>n.length-2-y),p=h?0:n.length-1,u=new Map(n[p].map((f,y)=>[f.id,y]));n[p]=Jt(n[p],u,e,o),n[p].forEach((f,y)=>f.order=y);for(const f of b){const y=n[f],T=new Map;for(const $ of y){const k=h?t.in($.id).map(S=>({order:t.node(S.v).order,w:S.weight||1})):t.out($.id).map(S=>({order:t.node(S.w).order,w:S.weight||1}));if(k.length===0)T.set($.id,$.order);else{let S=0,E=0;for(const I of k)S+=I.order*I.w,E+=I.w;T.set($.id,S/E)}}n[f]=Jt(y,T,e,o),n[f].forEach(($,k)=>$.order=k)}o=qe(n,e);const d=je(t,n,e);d<a?(a=d,r=n.map(f=>f.slice()),c=0):c++}return i(r),r}function yt(t){return t.dummy==="edge"||t.dummy==="label"||t.dummy==="spine"}function Lt(t,e,s){const n=yt(t)&&yt(e)?s.edgeSep:yt(t)||yt(e)?(s.nodeSep+s.edgeSep)/2:s.nodeSep;return t.width/2+n+e.width/2}function Hn(t,e){let s=0;t.forEach((n,o)=>{s=o===0?n.width/2:s+Lt(t[o-1],n,e),n.x=s})}function Xe(t){const e=t.slice().sort((n,o)=>n-o),s=e.length>>1;return e.length%2?e[s]:(e[s-1]+e[s])/2}function Ge(t,e,s,n){const o=new Array(t.length).fill(!1),i=t.map((r,a)=>a).sort((r,a)=>s.get(t[a].id)-s.get(t[r].id)||r-a);for(const r of i){const a=t[r],c=e.get(a.id);if(c===void 0){o[r]=!0;continue}if(c>a.x){let l=1/0,h=0;for(let p=r+1;p<t.length;p++)if(h+=Lt(t[p-1],t[p],n),o[p]){l=t[p].x-h;break}const b=Math.min(c,l);if(b>a.x){a.x=b;for(let p=r+1;p<t.length;p++){const u=t[p-1].x+Lt(t[p-1],t[p],n);if(t[p].x>=u)break;t[p].x=u}}}else if(c<a.x){let l=-1/0,h=0;for(let p=r-1;p>=0;p--)if(h+=Lt(t[p],t[p+1],n),o[p]){l=t[p].x+h;break}const b=Math.max(c,l);if(b<a.x){a.x=b;for(let p=r-1;p>=0;p--){const u=t[p+1].x-Lt(t[p],t[p+1],n);if(t[p].x<=u)break;t[p].x=u}}}o[r]=!0}}function jn(t,e,s,n=4){for(const i of e)Hn(i,s);const o=i=>{const r=i?Array.from({length:e.length-1},(a,c)=>c+1):Array.from({length:e.length-1},(a,c)=>e.length-2-c);for(const a of r){const c=e[a],l=new Map,h=new Map;for(const b of c){const p=i?t.in(b.id).map(d=>t.node(d.v)):t.out(b.id).map(d=>t.node(d.w));p.length>0&&l.set(b.id,Xe(p.map(d=>d.x)));const u=yt(b)&&p.some(yt)?1e6:p.length;h.set(b.id,u)}Ge(c,l,h,s)}};for(let i=0;i<n;i++)o(!0),o(!1);for(let i=0;i<e.length;i++){const r=e[i],a=new Map,c=new Map;for(const l of r){const h=[...t.in(l.id).map(b=>t.node(b.v)),...t.out(l.id).map(b=>t.node(b.w))];h.length>0&&a.set(l.id,Xe(h.map(b=>b.x))),c.set(l.id,yt(l)?1e6:h.length)}Ge(r,a,c,s)}}function qn(t,e,s,n){jn(t,e,n),Gn(t,e,s,n);let o=1/0;for(const r of t.nodes.values())o=Math.min(o,r.x-r.width/2);if(Number.isFinite(o))for(const r of t.nodes.values())r.x-=o;let i=0;e.forEach((r,a)=>{let c=0;for(const l of r)c=Math.max(c,l.height);a>0&&(i+=n.rankSep/2);for(const l of r)l.y=i+c/2;i+=c})}function Xn(t,e){const s=new Map;for(const n of t.nodes.values()){let o=n.cluster;for(;;){const i=s.get(o)??[];if(i.push(n),s.set(o,i),o===null)break;o=e.get(o)??null}}return s}function Ms(t){const e=new Map;for(const[s,n]of t){const o=e.get(n)??[];o.push(s),e.set(n,o)}return e}function Ts(t,e,s,n){const o=Ms(e),i=new Map;for(const c of t.nodes.values()){if(c.cluster===null)continue;const l=i.get(c.cluster)??[];l.push(c),i.set(c.cluster,l)}const r=new Map,a=c=>{const l=r.get(c);if(l)return l;let h=1/0,b=-1/0;for(const u of i.get(c)??[])h=Math.min(h,u.x-u.width/2),b=Math.max(b,u.x+u.width/2);for(const u of o.get(c)??[]){const d=a(u);h=Math.min(h,d.left),b=Math.max(b,d.right)}Number.isFinite(h)||(h=0,b=0);const p={left:h-s-(n?.get(c)??0),right:b+s};return r.set(c,p),p};for(const c of e.keys())a(c);return r}function Gn(t,e,s,n){if(s.size===0)return;const o=Ms(s),i=Xn(t,s),r=(c,l)=>{let h=c.cluster,b=null;for(;h!==l;){if(h===null)return null;b=h,h=s.get(h)??null}return b??c.id},a=c=>{for(const f of o.get(c)??[])a(f);const l=Ts(t,s,n.clusterPadding,n.frameLeft),h=new Map;for(const f of i.get(c)??[]){const y=r(f,c);if(!(y===null||h.has(y)))if(y===f.id)h.set(y,{cluster:!1,left:f.x-f.width/2,right:f.x+f.width/2,dummy:yt(f)});else{const T=l.get(y);h.set(y,{cluster:!0,left:T.left,right:T.right,dummy:!1})}}const b=new Map,p=new Map([...h.keys()].map(f=>[f,0]));for(const f of e){let y=null;for(const T of f){const $=r(T,c);if(!($===null||$===y)){if(y!==null){const k=h.get(y),S=h.get($),E=k.dummy&&S.dummy?n.edgeSep:k.dummy||S.dummy?(n.nodeSep+n.edgeSep)/2:n.nodeSep,I=b.get(y)??new Map;I.has($)||p.set($,p.get($)+1),I.set($,Math.max(I.get($)??-1/0,k.right-k.left+E)),b.set(y,I)}y=$}}}const u=new Map([...h].map(([f,y])=>[f,y.left])),d=[...h.keys()].filter(f=>p.get(f)===0);for(;d.length>0;){const f=d.shift();for(const[y,T]of b.get(f)??[])u.set(y,Math.max(u.get(y),u.get(f)+T)),p.set(y,p.get(y)-1),p.get(y)===0&&d.push(y)}for(const[f,y]of h){const T=u.get(f)-y.left;if(T!==0)if(y.cluster)for(const $ of i.get(f)??[])$.x+=T;else t.node(f).x+=T}};a(null)}function Kn(t){const e=new Map,s=[];for(const n of t.nodes.keys()){if(e.get(n))continue;const o=[{id:n,i:0}];for(e.set(n,1);o.length>0;){const i=o[o.length-1],r=t.out(i.id);if(i.i<r.length){const a=r[i.i++],c=e.get(a.w)??0;c===1?s.push(a):c===0&&(e.set(a.w,1),o.push({id:a.w,i:0}))}else e.set(i.id,2),o.pop()}}for(const n of s){const o=n.v;n.v=n.w,n.w=o,n.reversed=!n.reversed}s.length>0&&t.reindex()}function Zn(t,e){const s=new Set(e),n=new Map;for(const o of t.edges){if(!s.has(o.v)||o.v===o.w)continue;const i=`${o.v}\0${o.w}`,r=n.get(i);r?(r.weight+=o.weight,r.minlen=Math.max(r.minlen,o.minlen)):n.set(i,{v:o.v,w:o.w,minlen:o.minlen,weight:o.weight})}return{nodes:[...e],edges:[...n.values()]}}function Vn(t){const e=new Set,s=[];for(const n of t.nodes.keys()){if(e.has(n))continue;const o=[],i=[n];for(e.add(n);i.length>0;){const r=i.shift();o.push(r);for(const a of[...t.out(r),...t.in(r)]){const c=a.v===r?a.w:a.v;e.has(c)||(e.add(c),i.push(c))}}s.push(o)}return s}function Jn(t,e){const s=new Map(e.map(o=>[o,t.in(o).length])),n=e.filter(o=>s.get(o)===0);for(;n.length>0;){const o=n.shift(),i=t.in(o),r=t.out(o);if(i.length>0&&i.reduce((a,c)=>a+c.weight,0)>=r.reduce((a,c)=>a+c.weight,0)){let a=-1/0;for(const l of i)a=Math.max(a,t.node(l.v).rank+l.minlen);const c=t.node(o);a<c.rank&&(c.rank=a)}for(const a of r)s.set(a.w,s.get(a.w)-1),s.get(a.w)===0&&n.push(a.w)}}function Qn(t,e=2e3){for(const s of Vn(t)){const{nodes:n,edges:o}=Zn(t,s),i=to(n,o,e);let r=1/0;for(const c of i.values())r=Math.min(r,c);for(const[c,l]of i)t.node(c).rank=l-r;Jn(t,s);let a=1/0;for(const c of s)a=Math.min(a,t.node(c).rank);for(const c of s)t.node(c).rank-=a}}function to(t,e,s){const n=new Map,o=new Map;for(const m of t)n.set(m,[]),o.set(m,[]);for(const m of e)n.get(m.v).push(m),o.get(m.w).push(m);const i=(m,w)=>`${m}\0${w}`,r=new Map(e.map(m=>[i(m.v,m.w),m])),a=(m,w)=>r.get(i(m,w)),c=new Map,l=m=>{const w=[{id:m,i:0}],M=new Set([m]);for(;w.length>0;){const C=w[w.length-1],B=n.get(C.id);if(C.i<B.length){const D=B[C.i++];!c.has(D.w)&&!M.has(D.w)&&(M.add(D.w),w.push({id:D.w,i:0}))}else{let D=1/0;for(const U of B)D=Math.min(D,c.get(U.w)-U.minlen);c.set(C.id,D===1/0?0:D),w.pop()}}};for(const m of t)c.has(m)||l(m);if(t.length<=1||e.length===0)return c;const h=m=>c.get(m.w)-c.get(m.v)-m.minlen,b=new Map,p=(m,w)=>{b.get(m).add(w),b.get(w).add(m)},u=()=>{const m=[...b.keys()];for(;m.length>0;){const w=m.pop();for(const M of[...n.get(w),...o.get(w)]){const C=M.v===w?M.w:M.v;!b.has(C)&&h(M)===0&&(b.set(C,new Set),p(w,C),m.push(C))}}return b.size};for(b.set(t[0],new Set);u()<t.length;){let m=null,w=1/0;for(const C of e)if(b.has(C.v)!==b.has(C.w)){const B=h(C);B<w&&(w=B,m=C)}if(!m)break;const M=b.has(m.v)?w:-w;for(const C of b.keys())c.set(C,c.get(C)+M)}const d=t[0],f=new Map,y=new Map,T=new Map,$=new Map,k=(m,w)=>m<w?i(m,w):i(w,m),S=()=>{f.clear(),y.clear(),T.clear();let m=1;const w=[];T.set(d,void 0),w.push({id:d,it:b.get(d).values(),low:m});const M=new Set([d]);for(;w.length>0;){const C=w[w.length-1],B=C.it.next();if(B.done)f.set(C.id,C.low),y.set(C.id,m++),w.pop();else{const D=B.value;M.has(D)||(M.add(D),T.set(D,C.id),w.push({id:D,it:b.get(D).values(),low:m}))}}},E=()=>[...y.entries()].sort((m,w)=>m[1]-w[1]).map(([m])=>m),I=m=>{const w=T.get(m);let M=!0,C=a(m,w);C||(M=!1,C=a(w,m));let B=C.weight;for(const D of[...n.get(m),...o.get(m)]){const U=D.v===m,Z=U?D.w:D.v;if(Z===w)continue;const F=U===M;if(B+=F?D.weight:-D.weight,b.get(m).has(Z)){const j=$.get(k(m,Z))??0;B+=F?-j:j}}return B},L=()=>{$.clear();for(const m of E()){const w=T.get(m);w!==void 0&&$.set(k(m,w),I(m))}},O=()=>{const m=[...y.entries()].sort((w,M)=>M[1]-w[1]).map(([w])=>w);for(const w of m){const M=T.get(w);if(M===void 0)continue;const C=a(w,M);C?c.set(w,c.get(M)-C.minlen):c.set(w,c.get(M)+a(M,w).minlen)}},P=(m,w)=>f.get(w)<=y.get(m)&&y.get(m)<=y.get(w);S(),L();for(let m=0;m<s;m++){let w=null;for(const[U,Z]of T)if(Z!==void 0&&($.get(k(U,Z))??0)<0){w=a(U,Z)?{v:U,w:Z}:{v:Z,w:U};break}if(!w)break;let M=w.v,C=!1;y.get(w.v)>y.get(w.w)&&(M=w.w,C=!0);let B=null,D=1/0;for(const U of e)if(C===P(U.v,M)&&C!==P(U.w,M)){const Z=h(U);Z<D&&(D=Z,B=U)}if(!B)break;b.get(w.v).delete(w.w),b.get(w.w).delete(w.v),p(B.v,B.w),S(),L(),O()}return c}var eo=2e3,Ss=22;function Ke(t){const e=t.direction??"TB",s=e==="LR"||e==="RL",n={nodeSep:t.nodeSep??50,rankSep:t.rankSep??50,edgeSep:t.edgeSep??20,clusterPadding:t.clusterPadding??12};if(t.nodes.length>500)throw ve("nodes",t.nodes.length,500);if(t.edges.length>2e3)throw ve("edges",t.edges.length,eo);const o=(x,A)=>s?{width:A,height:x}:{width:x,height:A},i=new Fn,r=new Map((t.clusters??[]).map(x=>[x.id,x])),a=new Map;for(const x of r.values()){if(x.parent!==void 0&&!r.has(x.parent))throw new R(`Cluster "${x.id}" is inside an unknown cluster "${x.parent}"`);a.set(x.id,x.parent??null)}for(const x of r.keys()){let A=a.get(x)??null,W=0;for(;A!==null;){if(A===x||++W>r.size)throw new R(`Cluster "${x}" contains itself`);A=a.get(A)??null}}const c=t.edges.filter(x=>x.from===x.to&&!r.has(x.from)),l=new Map;for(const x of c){const A=x.label?(s?x.label.height:x.label.width)+6:0;l.set(x.from,Math.max(l.get(x.from)??0,Ss+A))}for(const x of t.nodes){if(i.nodes.has(x.id))continue;const A=o(x.width,x.height),W=l.get(x.id)??0;if(x.cluster!==void 0&&!r.has(x.cluster))throw new R(`Node "${x.id}" is inside an unknown cluster "${x.cluster}"`);i.addNode({id:x.id,width:A.width+W*2,height:A.height,cluster:x.cluster??null})}const h=x=>`\0top:${x}`,b=x=>`\0bottom:${x}`,p=new Map,u=new Map;n.frameLeft=u;for(const x of r.values()){const A=x.label??{width:0,height:0},W=A.height>0?A.height+6:0;p.set(x.id,W),s&&u.set(x.id,W);const X=e==="TB"?"top":e==="BT"?"bottom":null;i.addNode({id:h(x.id),width:X==="top"?A.width+2*n.clusterPadding:0,height:X==="top"?W:0,cluster:x.id,dummy:"border-top"}),i.addNode({id:b(x.id),width:X==="bottom"?A.width+2*n.clusterPadding:0,height:X==="bottom"?W:0,cluster:x.id,dummy:"border-bottom"})}let d=0;const f=(x,A)=>i.addEdge({id:`\0s${d++}`,v:x,w:A,minlen:1,weight:1,original:"",reversed:!1,structural:!0});for(const x of r.keys()){const A=[...i.nodes.values()].filter(X=>X.cluster===x&&!X.dummy),W=[...r.values()].filter(X=>(X.parent??null)===x);for(const X of A)f(h(x),X.id),f(X.id,b(x));for(const X of W)f(h(x),h(X.id)),f(b(X.id),b(x));A.length===0&&W.length===0&&f(h(x),b(x))}const y=x=>{const A=[];for(const W of t.nodes)W.cluster===x&&A.push(W.id);for(const W of r.values())(W.parent??null)===x&&A.push(...y(W.id));return A},T=(x,A)=>{if(r.has(x)){const W=y(x);return W.length===0?A?b(x):h(x):A?W[W.length-1]:W[0]}if(!i.nodes.has(x))throw new R(`Edge refers to an unknown node "${x}"`);return x},$=new Map;for(const x of t.edges){if(x.from===x.to&&!r.has(x.from))continue;const A=T(x.from,!0),W=T(x.to,!1);A!==W&&(x.label&&$.set(x.id,o(x.label.width,x.label.height)),i.addEdge({id:x.id,v:A,w:W,minlen:Math.max(1,x.minlen??1)*2,weight:x.weight??1,original:x.id,reversed:!1}))}Kn(i),Qn(i),oo(i,r.keys(),h,b);for(const x of i.edges.slice())x.structural&&i.node(x.w).rank-i.node(x.v).rank!==1&&i.removeEdge(x);const k=new Map;let S=0;const E=x=>{const A=i.node(x);return A.dummy==="border-top"||A.dummy==="border-bottom"?a.get(A.cluster)??null:A.cluster};for(const x of i.edges.slice()){if(x.structural)continue;const A=i.node(x.v),W=i.node(x.w),X=no(E(A.id),E(W.id),a),nt=[A.id],dt=W.rank-A.rank,ot=$.get(x.original),at=A.rank+Math.floor(dt/2);i.removeEdge(x);let mt=A.id;for(let ht=A.rank+1;ht<W.rank;ht++){const wt=!!ot&&ht===at,bt=i.addNode({id:`\0d${S++}`,width:wt?ot.width:0,height:wt?ot.height:0,cluster:X,dummy:wt?"label":"edge",edge:x.original});bt.rank=ht,i.addEdge({id:`${x.id}#${ht}`,v:mt,w:bt.id,minlen:1,weight:x.weight,original:x.original,reversed:x.reversed}),nt.push(bt.id),mt=bt.id}i.addEdge({id:`${x.id}#end`,v:mt,w:W.id,minlen:1,weight:x.weight,original:x.original,reversed:x.reversed}),nt.push(W.id),k.set(x.original,x.reversed?nt.reverse():nt)}io(i,r.keys(),a,h,b),qn(i,Yn(i,a),a,n);const I=Ts(i,a,n.clusterPadding,n.frameLeft),L=new Map,O=new Map;for(const x of i.nodes.values()){let A=x.cluster;for(;A!==null;){const W=O.get(A)??[];W.push(x),O.set(A,W),A=a.get(A)??null}}const P=x=>{let A=0,W=a.get(x)??null;for(;W!==null;)A++,W=a.get(W)??null;return A},m=[...r.keys()].sort((x,A)=>P(A)-P(x)),w=new Map;for(const x of m){let A=1/0,W=-1/0;for(const nt of O.get(x)??[])A=Math.min(A,nt.y-nt.height/2),W=Math.max(W,nt.y+nt.height/2);for(const nt of r.values()){if((nt.parent??null)!==x)continue;const dt=w.get(nt.id);dt&&(A=Math.min(A,dt.top),W=Math.max(W,dt.bottom))}const X=n.clusterPadding;w.set(x,{top:A-(e==="TB"?0:X),bottom:W+(e==="BT"?0:X)})}for(const x of r.keys()){const A=I.get(x),W=w.get(x),X=A.left;L.set(x,{x:(X+A.right)/2,y:(W.top+W.bottom)/2,width:A.right-X,height:W.bottom-W.top})}let M=0,C=0,B=0,D=0;for(const x of i.nodes.values())M=Math.max(M,x.x+x.width/2),C=Math.max(C,x.y+x.height/2);for(const x of L.values())B=Math.min(B,x.x-x.width/2),D=Math.min(D,x.y-x.height/2),M=Math.max(M,x.x+x.width/2),C=Math.max(C,x.y+x.height/2);const U=M-B,Z=C-D,F=x=>{const A=x.x-B,W=x.y-D;switch(e){case"BT":return{x:A,y:Z-W};case"LR":return{x:W,y:A};case"RL":return{x:Z-W,y:A};default:return{x:A,y:W}}},j=x=>{const A=F(x);return s?{x:A.x,y:A.y,width:x.height,height:x.width}:{...A,width:x.width,height:x.height}},G=new Map;for(const x of t.nodes){const A=F(i.node(x.id));G.set(x.id,{x:A.x,y:A.y,width:x.width,height:x.height})}const J=new Map;for(const[x,A]of L)J.set(x,j(A));const it=new Map;for(const x of t.edges){if(x.from===x.to&&!r.has(x.from)){it.set(x.id,ro(G.get(x.from),e,x.label));continue}const A=k.get(x.id);if(!A){it.set(x.id,{points:[]});continue}const W=A.slice(1,-1).map(dt=>i.node(dt)),X={points:W.map(dt=>F(dt))},nt=W.find(dt=>dt.dummy==="label");nt&&(X.label=F(nt)),(r.has(x.from)||r.has(x.to))&&so(X,F(i.node(A[0])),F(i.node(A[A.length-1])),{from:r.has(x.from)?J.get(x.from):void 0,to:r.has(x.to)?J.get(x.to):void 0}),it.set(x.id,X)}return{width:s?Z:U,height:s?U:Z,nodes:G,clusters:J,edges:it}}function Dt(t,e){return Math.abs(e.x-t.x)<=t.width/2&&Math.abs(e.y-t.y)<=t.height/2}function Ze(t,e,s){let n=0,o=1;for(let i=0;i<30;i++){const r=(n+o)/2;Dt(t,{x:e.x+(s.x-e.x)*r,y:e.y+(s.y-e.y)*r})?o=r:n=r}return{x:e.x+(s.x-e.x)*o,y:e.y+(s.y-e.y)*o}}function so(t,e,s,n){let o=[e,...t.points,s];if(n.to&&!Dt(n.to,e)){for(let i=1;i<o.length;i++)if(Dt(n.to,o[i])){const r=Ze(n.to,o[i-1],o[i]);o=[...o.slice(0,i),r];break}t.end=o[o.length-1]}if(n.from&&!Dt(n.from,o[o.length-1])){for(let i=o.length-2;i>=0;i--)if(Dt(n.from,o[i])){o=[Ze(n.from,o[i+1],o[i]),...o.slice(i+1)];break}t.start=o[0]}t.points=o.slice(1,-1)}function jt(t){const e=t.clusters??[];if(e.length===0)return Ke(t);const s=new Map(e.map(f=>[f.id,f.parent??null])),n=(f,y)=>{let T=f??null,$=0;for(;T!==null&&$++<=e.length;){if(T===y)return!0;T=s.get(T)??null}return!1},o=new Map(t.nodes.map(f=>[f.id,f.cluster??null])),i=f=>s.has(f)?{cluster:f,isCluster:!0}:{cluster:o.get(f)??null,isCluster:!1},r=f=>{for(const y of t.edges){const T=i(y.from),$=i(y.to),k=T.isCluster?n(T.cluster,f)&&T.cluster!==f:n(T.cluster,f);if(k!==($.isCluster?n($.cluster,f)&&$.cluster!==f:n($.cluster,f))){const S=k?$:T;if(!(S.isCluster&&S.cluster===f))return!1}}return!0},a=e.filter(f=>r(f.id)&&!e.some(y=>y.id!==f.id&&n(f.id,y.id)&&r(y.id)));if(a.length===0)return Ke(t);const c=t.clusterPadding??12,l=t.direction??"TB",h=new Map,b=new Set,p=new Set,u=new Set;for(const f of a){const y={...t,direction:f.direction??l,nodes:t.nodes.filter(E=>n(E.cluster,f.id)).map(E=>({...E,cluster:E.cluster===f.id?void 0:E.cluster})),clusters:e.filter(E=>E.id!==f.id&&n(E.id,f.id)).map(E=>({...E,parent:E.parent===f.id?void 0:E.parent})),edges:t.edges.filter(E=>{const I=i(E.from),L=i(E.to),O=n(I.cluster,f.id)&&!(I.isCluster&&I.cluster===f.id),P=n(L.cluster,f.id)&&!(L.isCluster&&L.cluster===f.id);return O&&P})};for(const E of y.nodes)b.add(E.id);for(const E of y.clusters??[])p.add(E.id);p.add(f.id);for(const E of y.edges)u.add(E.id);const T=jt(y),$=f.label&&f.label.height>0?f.label.height+6:0,k=Math.max(T.width,f.label?.width??0)+c*2,S=T.height+c*2+$;h.set(f.id,{result:T,title:$,width:k,height:S})}const d=jt({...t,nodes:[...t.nodes.filter(f=>!b.has(f.id)),...a.map(f=>({id:f.id,width:h.get(f.id).width,height:h.get(f.id).height,cluster:f.parent}))],clusters:e.filter(f=>!p.has(f.id)),edges:t.edges.filter(f=>!u.has(f.id))});for(const f of a){const y=d.nodes.get(f.id);d.nodes.delete(f.id),d.clusters.set(f.id,y);const{result:T,title:$}=h.get(f.id),k=y.x-y.width/2+(y.width-T.width)/2,S=y.y-y.height/2+c+$,E=I=>({x:I.x+k,y:I.y+S});for(const[I,L]of T.nodes)d.nodes.set(I,{...L,...E(L)});for(const[I,L]of T.clusters)d.clusters.set(I,{...L,...E(L)});for(const[I,L]of T.edges)d.edges.set(I,{...L,points:L.points.map(E),label:L.label&&E(L.label),start:L.start&&E(L.start),end:L.end&&E(L.end)})}return d}function no(t,e,s){const n=i=>{const r=[];for(;i!==null;)r.push(i),i=s.get(i)??null;return r},o=new Set(n(t));for(const i of n(e))if(o.has(i))return i;return null}function oo(t,e,s,n){const o=[...e];for(let i=0;i<o.length+1;i++){let r=!1;for(const a of o){const c=t.node(s(a)),l=t.node(n(a)),h=t.out(c.id).map(d=>t.node(d.w).rank),b=t.in(l.id).map(d=>t.node(d.v).rank),p=t.in(c.id).map(d=>t.node(d.v).rank+d.minlen),u=t.out(l.id).map(d=>t.node(d.w).rank-d.minlen);if(h.length>0){const d=Math.min(...h)-1,f=p.length>0?Math.max(...p):-1/0,y=Math.max(d,f);y!==c.rank&&y<=Math.min(...h)-1&&(c.rank=y,r=!0)}if(b.length>0){const d=Math.max(...b)+1,f=u.length>0?Math.min(...u):1/0,y=Math.min(d,f);y!==l.rank&&y>=Math.max(...b)+1&&(l.rank=y,r=!0)}}if(!r)break}}function io(t,e,s,n,o){const i=new Map;for(const a of t.nodes.values()){let c=a.cluster;for(;c!==null;){let l=i.get(c);l||i.set(c,l=new Set),l.add(a.rank),c=s.get(c)??null}}let r=0;for(const a of e){const c=t.node(n(a)).rank,l=t.node(o(a)).rank,h=i.get(a)??new Set;for(let b=c+1;b<l;b++){if(h.has(b))continue;const p=t.addNode({id:`\0spine${r++}`,width:0,height:0,cluster:a,dummy:"spine"});p.rank=b;let u=a;for(;u!==null;){let d=i.get(u);d||i.set(u,d=new Set),d.add(b),u=s.get(u)??null}}}}function ro(t,e,s){const n=e==="LR"||e==="RL",o=Ss;if(!n){const c=t.x+t.width/2,l=t.y-t.height/4,h=t.y+t.height/4;return{selfLoop:!0,points:[{x:c,y:l},{x:c+o,y:l-4},{x:c+o,y:h+4},{x:c,y:h}],label:s?{x:c+o+4+s.width/2,y:t.y}:void 0}}const i=t.y+t.height/2,r=t.x-t.width/4,a=t.x+t.width/4;return{selfLoop:!0,points:[{x:r,y:i},{x:r-4,y:i+o},{x:a+4,y:i+o},{x:a,y:i}],label:s?{x:t.x,y:i+o+4+s.height/2}:void 0}}var lo=200;function Qt(t,e,s,n=Q){let o=lt(t,{markdown:e});return e&&(o=ge(o,lo,n,s)),st(o,n,s)}function Ve(t){return t==="arrow"?"arrow":t==="circle"?"circle":t==="cross"?"cross":null}function Je(t,e,s){return us(s.get("default"),...t.map(n=>s.get(n)),e)}function ao(t,e,s,n){const o=new Map,i=new Map;for(const k of t.nodes.values()){const S=Qt(k.text,k.markdown,e);o.set(k.id,S),i.set(k.id,ce(k.shape,S.width,Math.max(S.height,Q.size*1.25)))}const r={...Q,weight:"bold"},a=new Map;for(const k of t.subgraphs.values())k.title.trim()!==""&&a.set(k.id,Qt(k.title,k.markdown,e,r));const c=new Map,l=t.edges.map((k,S)=>{let E;if(k.text!==void 0&&k.text!==""){const I=Qt(k.text,k.markdown,e);ds(I.label)||(c.set(S,I),E={width:I.width+8,height:I.height+4})}return{id:String(S),from:k.from,to:k.to,minlen:k.length,label:E}}),h=jt({direction:t.direction,nodes:[...t.nodes.values()].map(k=>({id:k.id,...i.get(k.id),cluster:k.subgraph})),edges:l,clusters:[...t.subgraphs.values()].map(k=>{const S=a.get(k.id);return{id:k.id,parent:k.parent,direction:k.direction,label:S?{width:S.width,height:S.height}:void 0}}),nodeSep:50,rankSep:50,clusterPadding:14}),b=k=>{let S=0,E=t.subgraphs.get(k)?.parent;for(;E;)S++,E=t.subgraphs.get(E)?.parent;return S},p=[...t.subgraphs.values()].sort((k,S)=>b(k.id)-b(S.id)).map(k=>{const S=h.clusters.get(k.id),E=Je(k.classes,k.style,t.classDefs),I=a.get(k.id);return v("g",{class:"dg-cluster","data-id":k.id},[v("rect",{class:"dg-cluster-box",x:S.x-S.width/2,y:S.y-S.height/2,width:S.width,height:S.height,rx:4,style:ut(E.shape)}),I?tt(I,S.x,S.y-S.height/2+6+I.height/2,{className:"dg-cluster-label",style:ut(E.text)}):null])}),u=k=>{const S=t.nodes.get(k);if(S){const I=h.nodes.get(k);return{box:I,clip:L=>he(S.shape,I,L)}}const E=h.clusters.get(k);return{box:E,clip:I=>he("rect",E,I)}},d=[],f=[],y=[];t.edges.forEach((k,S)=>{const E=h.edges.get(String(S));if(!E||k.stroke==="invisible")return;let I;if(E.selfLoop)I=E.points;else{const M=u(k.from),C=u(k.to),B=E.points[0]??C.box,D=E.points[E.points.length-1]??M.box;I=[E.start??M.clip(B),...E.points,E.end??C.clip(D)]}const L=k.style??{shape:{},text:{}},O=Ve(k.start),P=Ve(k.end);O&&d.push(O),P&&d.push(P);const m=["dg-edge",k.stroke==="thick"?"dg-edge-thick":"",k.stroke==="dotted"?"dg-edge-dotted":""].filter(Boolean).join(" ");f.push(v("path",{class:m,d:ks(I),"marker-start":O?`url(#${Tt(s,O,!0)})`:void 0,"marker-end":P?`url(#${Tt(s,P)})`:void 0,style:ut(L.shape),"data-from":k.from,"data-to":k.to}));const w=c.get(S);if(w&&E.label){const M=w.width+8,C=w.height+4;y.push(v("g",{class:"dg-edge-label-group"},[v("rect",{class:"dg-edge-label-box",x:E.label.x-M/2,y:E.label.y-C/2,width:M,height:C,rx:3}),tt(w,E.label.x,E.label.y,{className:"dg-edge-label",style:ut(L.text)})]))}});const T=[...t.nodes.values()].map(k=>{const S=h.nodes.get(k.id);if(!S)throw new R(`Node "${k.id}" was not laid out`);const E=Je(k.classes,k.style,t.classDefs),I=v("g",{class:["dg-node",...k.classes.map(L=>`dg-class-${L.replace(/[^\w-]/g,"")}`)].join(" "),"data-id":k.id},[k.tooltip||k.link?.tooltip?v("title",{},[{text:k.link?.tooltip??k.tooltip??""}]):null,de(k.shape,S,{style:ut(E.shape)}),tt(o.get(k.id),S.x,S.y,{style:ut(E.text)})]);return k.link?v("a",{href:k.link.href,target:k.link.target,rel:k.link.target==="_blank"?"noopener noreferrer":void 0},[I]):I}),$=[`#${s} .dg-edge-label-group text{fill:${N("--dg-text")}}`].join("");return Ot({id:s,type:"flowchart",width:h.width,height:h.height,title:n??t.accessibility.title??"Flowchart",description:t.accessibility.description,defs:xe(s,d),body:[v("g",{class:"dg-clusters"},p),v("g",{class:"dg-edges"},f),v("g",{class:"dg-edge-labels"},y),v("g",{class:"dg-nodes"},T)],css:$})}var co={...Q,size:13,weight:"bold"},Qe={...Q,size:13},ho={...Q,size:18,weight:"bold"},fo=90,uo=40,go=40,po=24,mo=28,wo=20,xo=240,Ut=12,yo=6,bo=20,ts=10,te=18,es=12;function ko(t){const e=[],s=new Set;for(const n of t.participants)if(!s.has(n)){if(n.box===void 0){e.push(n),s.add(n);continue}for(const o of t.participants)o.box===n.box&&!s.has(o)&&(e.push(o),s.add(o))}return e}function $o(t,e){const s=ko(t),n=new Map(s.map((g,_)=>[g.id,_])),o=g=>n.get(g),i=s.map(g=>st(lt(g.label),Q,e)),r=s.map((g,_)=>g.kind==="actor"?Math.max(i[_].width+8,50):Math.max(i[_].width+32,fo));let a=uo;s.forEach((g,_)=>{const z=g.kind==="actor"?38+i[_].height:i[_].height+20;a=Math.max(a,z)});const c=t.events.map(g=>{if(g.kind==="message"){const _=lt(g.text);return ds(_)?null:st(_,Q,e)}return g.kind==="note"?st(ge(lt(g.text),xo,Q,e),Q,e):null}),l=new Map,h=(g,_,z)=>{if(g===_||g<0||_<0||g>=s.length||_>=s.length)return;const H=`${Math.min(g,_)},${Math.max(g,_)}`;l.set(H,Math.max(l.get(H)??0,z))};t.events.forEach((g,_)=>{const z=c[_];if(g.kind==="message"){const H=o(g.from),Y=o(g.to),q=(z?.width??0)+(g.number!==void 0?wo:0);H===Y?h(H,H+1,Math.max(q+28,62)):h(H,Y,q+mo)}else if(g.kind==="note"&&z){const H=z.width+16,Y=g.actors.map(o).sort((et,rt)=>et-rt),q=Y[0],K=Y[Y.length-1];g.placement==="right"?h(q,q+1,H+Ut+12):g.placement==="left"?h(q-1,q,H+Ut+12):q===K?(h(q-1,q,H/2+16),h(q,q+1,H/2+16)):h(q,K,H-24)}});const b=[];s.forEach((g,_)=>{if(_===0){b.push(r[0]/2);return}const z=s[_-1],H=(z.box!==void 0||g.box!==void 0)&&z.box!==g.box;let Y=b[_-1]+r[_-1]/2+go+(H?po:0)+r[_]/2;for(let q=0;q<_;q++){const K=l.get(`${q},${_}`);K!==void 0&&(Y=Math.max(Y,b[q]+K))}b.push(Y)});const p=g=>b[o(g)],u=g=>r[o(g)];let d=0,f=null;if(t.title){const g=st(lt(t.title),ho,e);f={label:g,x:0,y:g.height/2},d=g.height+14}const y=d;if(t.boxes.length>0){const g=Math.max(0,...t.boxes.map(_=>_.label?st(lt(_.label),Q,e).height:0));d+=8+(g>0?g+6:0)}const T=d,$=[],k=new Map,S=new Map,E=new Set;s.forEach((g,_)=>{if(g.created){E.add(g.id);return}$.push({id:g.id,kind:g.kind,label:i[_],x:b[_],top:T,width:r[_],height:a}),k.set(g.id,T+a)}),d=T+a+10;const I=new Map,L=[],O=[],P=[],m=[],w=[],M=[],C=[],B=new Set;let D=null;const U=(g,_)=>{for(const z of M)z.min=Math.min(z.min,g),z.max=Math.max(z.max,_)},Z=g=>U(p(g)-te,p(g)+te),F=g=>{let _=I.get(g);return _||(_=[],I.set(g,_)),_},j=(g,_)=>p(g)-5+_*yo,G=(g,_)=>{const z=F(g),H=z[z.length-1];if(!H)return p(g);const Y=j(g,H.level);return _>0?Y+10:Y},J=(g,_)=>{const z=F(g);z.push({top:_,level:z.length})},it=(g,_)=>{const z=F(g).pop();z&&L.push({left:j(g,z.level),top:z.top,bottom:Math.max(_,z.top+8)})},x=(g,_)=>{E.delete(g);const z=o(g),H=s[z];$.push({id:g,kind:H.kind,label:i[z],x:b[z],top:_-a/2,width:r[z],height:a}),k.set(g,_+a/2),U(b[z]-r[z]/2,b[z]+r[z]/2)},A=g=>{const _=g.filter(z=>E.has(z));if(_.length!==0){for(const z of _)x(z,d+a/2);d+=a+10}},W=(g,_)=>{for(B.delete(g);F(g).length>0;)it(g,_);S.set(g,_),C.push({x:p(g),y:_})};t.events.forEach((g,_)=>{const z=c[_]??null;switch(g.kind){case"message":{const H=z?.height??0,Y=d+6;if(g.from===g.to){A([g.from]);const Wt=p(g.from),qt=G(g.from,1),Xt=z?d+6+H+4:d+12,Et=Xt+bo;g.deactivateSource&&it(g.from,Xt),g.activateTarget&&J(g.to,Et);const be=G(g.to,1),ke=Math.max(qt,be)+34,$e=qt+4+(g.number!==void 0?12:0);O.push({x1:qt,x2:be,y:Xt,y2:Et,self:!0,loopRight:ke,line:g.line,head:g.head,bidirectional:g.bidirectional,label:z,labelX:$e,labelY:d+6+H/2,anchor:"start",number:g.number}),U(Wt-te,Math.max(ke,$e+(z?.width??0))),B.has(g.from)&&W(g.from,Et),d=Et+10,D=Et;break}const q=E.has(g.from),K=E.has(g.to);let et=z?Y+H+4:d+14;(q||K)&&(et=Math.max(et,d+a/2+4)),q&&x(g.from,et),K&&x(g.to,et);const rt=p(g.to)>p(g.from)?1:-1,ft=q?p(g.from)+rt*u(g.from)/2:G(g.from,rt);g.deactivateSource&&it(g.from,et),g.activateTarget&&J(g.to,et);const Mt=K?p(g.to)-rt*u(g.to)/2:G(g.to,rt===1?-1:1);O.push({x1:ft,x2:Mt,y:et,y2:et,self:!1,loopRight:0,line:g.line,head:g.head,bidirectional:g.bidirectional,label:z,labelX:(ft+Mt)/2,labelY:et-4-H/2,anchor:"middle",number:g.number}),Z(g.from),Z(g.to),z&&U((ft+Mt)/2-z.width/2,(ft+Mt)/2+z.width/2);for(const Wt of[g.from,g.to])B.has(Wt)&&W(Wt,et);d=et+10,(q||K)&&(d=Math.max(d,et+a/2+10)),D=et;break}case"note":{if(!z)break;A(g.actors);const H=z.width+16,Y=z.height+16,q=d+6,K=Math.min(...g.actors.map(p)),et=Math.max(...g.actors.map(p));let rt,ft=H;g.placement==="right"?rt=K+Ut:g.placement==="left"?rt=K-Ut-H:(ft=Math.max(H,et-K+(K===et?0:32)),rt=(K+et)/2-ft/2),P.push({left:rt,top:q,width:ft,height:Y,label:z});for(const Mt of g.actors)Z(Mt);U(rt,rt+ft),d=q+Y+8,D=null;break}case"activate":A([g.actor]),J(g.actor,D??d),Z(g.actor),D===null&&(d+=4);break;case"deactivate":it(g.actor,D??d),D===null&&(d+=4);break;case"destroy":B.add(g.actor);break;case"block-start":if(g.block==="rect"){d+=6;const H={block:"rect",left:0,right:0,top:d,bottom:0,tab:null,tabWidth:0,guard:null,sections:[],color:g.color};M.push({frame:H,min:1/0,max:-1/0}),d+=6}else{d+=8;const H=st(lt(g.block),co,e),Y=g.text?st(lt(`[${g.text}]`),Qe,e):null,q={block:g.block,left:0,right:0,top:d,bottom:0,tab:H,tabWidth:H.width+16,guard:Y,sections:[]};M.push({frame:q,min:1/0,max:-1/0}),d+=Math.max(20,Y?Y.height+4:0)+6}D=null;break;case"block-section":{const H=M[M.length-1];d+=6;const Y=g.text?st(lt(`[${g.text}]`),Qe,e):null;H.frame.sections.push({y:d,guard:Y}),d+=(Y?Y.height+4:0)+6,D=null;break}case"block-end":{const H=M.pop(),{frame:Y}=H;d+=Y.block==="rect"?6:8,Y.bottom=d;let q=H.min,K=H.max;if(Number.isFinite(q)||(q=b[0]-40,K=b[0]+40),Y.left=q-ts,Y.right=K+ts,Y.block!=="rect"){const et=[Y.guard,...Y.sections.map(ft=>ft.guard)];let rt=Y.tabWidth+(Y.guard?Y.guard.width+8:0)+16;for(const ft of et)ft&&(rt=Math.max(rt,ft.width+24));Y.right-Y.left<rt&&(Y.right=Y.left+rt),m.push(Y)}else w.push(Y);U(Y.left,Y.right),d+=Y.block==="rect"?4:6,D=null;break}}});for(const g of E)A([g]);for(const g of B)W(g,d);for(const[g,_]of I)for(;_.length>0;)it(g,d);d+=12;const X=d;s.forEach((g,_)=>{S.has(g.id)||$.push({id:g.id,kind:g.kind,label:i[_],x:b[_],top:X,width:r[_],height:a})});let nt=X+a;const dt=s.map((g,_)=>({x:b[_],y1:k.get(g.id)??X,y2:S.get(g.id)??X})),ot=[];t.boxes.length>0&&(nt+=8,t.boxes.forEach((g,_)=>{const z=s.map((K,et)=>({p:K,i:et})).filter(({p:K})=>K.box===_);if(z.length===0)return;let H=Math.min(...z.map(({i:K})=>b[K]-r[K]/2))-es,Y=Math.max(...z.map(({i:K})=>b[K]+r[K]/2))+es;const q=g.label?st(lt(g.label),Q,e):null;if(q&&Y-H<q.width+16){const K=(q.width+16-(Y-H))/2;H-=K,Y+=K}ot.push({left:H,right:Y,top:y,bottom:nt,color:g.color,label:q})}));let at=1/0,mt=-1/0;const ht=(g,_)=>{at=Math.min(at,g,_),mt=Math.max(mt,g,_)};for(const g of $)ht(g.x-g.width/2,g.x+g.width/2);for(const g of ot)ht(g.left,g.right);for(const g of[...m,...w])ht(g.left,g.right);for(const g of P)ht(g.left,g.left+g.width);for(const g of O)ht(g.x1,g.x2),g.self?ht(g.loopRight,g.labelX+(g.label?.width??0)):g.label&&ht(g.labelX-g.label.width/2,g.labelX+g.label.width/2),g.number!==void 0&&ht(g.x1-10,g.x1+10);let wt=mt-at,bt=-at;return f&&(f.label.width>wt&&(bt+=(f.label.width-wt)/2,wt=f.label.width),f.x=wt/2),{width:wt,height:nt,offsetX:bt,title:f,groups:ot,rects:w,frames:m,lifelines:dt,activations:L,messages:O,notes:P,actors:$,crosses:C}}var Es=[{token:"<<-->>",line:"dotted",head:"arrow",both:!0},{token:"<<->>",line:"solid",head:"arrow",both:!0},{token:"-->>",line:"dotted",head:"arrow",both:!1},{token:"->>",line:"solid",head:"arrow",both:!1},{token:"--x",line:"dotted",head:"cross",both:!1},{token:"--)",line:"dotted",head:"open",both:!1},{token:"-->",line:"dotted",head:"none",both:!1},{token:"-x",line:"solid",head:"cross",both:!1},{token:"-)",line:"solid",head:"open",both:!1},{token:"->",line:"solid",head:"none",both:!1}],ss=Es.map(t=>t.token).join(", "),vo=/[<>:,;+]|^-|-$/,Mo=new Set("aliceblue antiquewhite aqua aquamarine azure beige bisque black blanchedalmond blue blueviolet brown burlywood cadetblue chartreuse chocolate coral cornflowerblue cornsilk crimson cyan darkblue darkcyan darkgoldenrod darkgray darkgreen darkgrey darkkhaki darkmagenta darkolivegreen darkorange darkorchid darkred darksalmon darkseagreen darkslateblue darkslategray darkslategrey darkturquoise darkviolet deeppink deepskyblue dimgray dimgrey dodgerblue firebrick floralwhite forestgreen fuchsia gainsboro ghostwhite gold goldenrod gray green greenyellow grey honeydew hotpink indianred indigo ivory khaki lavender lavenderblush lawngreen lemonchiffon lightblue lightcoral lightcyan lightgoldenrodyellow lightgray lightgreen lightgrey lightpink lightsalmon lightseagreen lightskyblue lightslategray lightslategrey lightsteelblue lightyellow lime limegreen linen magenta maroon mediumaquamarine mediumblue mediumorchid mediumpurple mediumseagreen mediumslateblue mediumspringgreen mediumturquoise mediumvioletred midnightblue mintcream mistyrose moccasin navajowhite navy oldlace olive olivedrab orange orangered orchid palegoldenrod palegreen paleturquoise palevioletred papayawhip peachpuff peru pink plum powderblue purple rebeccapurple red rosybrown royalblue saddlebrown salmon sandybrown seagreen seashell sienna silver skyblue slateblue slategray slategrey snow springgreen steelblue tan teal thistle tomato turquoise violet wheat white whitesmoke yellow yellowgreen transparent".split(" "));function ee(t,e,s){return $t(`fill:${t}`,e,s).shape.fill}function To(t){const e=[];for(const s of t){let n=0;for(let o=0;o<s.text.length;o++){if(s.text[o]!==";")continue;const i=s.text.slice(n,o);/#[a-zA-Z0-9]+$/.test(i)||(ns(e,s,n,o),n=o+1)}ns(e,s,n,s.text.length)}return e}function ns(t,e,s,n){const o=e.text.slice(s,n),i=o.trim();if(i==="")return;const r=o.length-o.trimStart().length;t.push({text:i,line:e.line,column:e.column+s+r})}var So=class{constructor(t){this.list=t,this.diagram={type:"sequence",participants:[],boxes:[],events:[],accessibility:{}},this.byId=new Map,this.stack=[],this.active=new Map,this.destroyed=new Set,this.pendingDestroy=new Set,this.numbering=null,this.currentBox=null}run(){const t=this.list[0];if(!t||!/^sequenceDiagram\s*$/.test(t.text))throw new R('A sequence diagram starts with "sequenceDiagram"',t?.line??1,t?.column??1);for(let s=1;s<this.list.length;s++){const n=_t(this.list,s,this.diagram.accessibility);if(n>0){s+=n-1;continue}this.statement(this.list[s])}const e=this.stack[this.stack.length-1];if(e)throw new R(`The "${e.block}" opened here is never closed`,e.line,0,'Add "end" after its last statement.');return this.diagram}statement(t){const e=t.text;let s;if(this.currentBox!==null&&!/^(create\s+)?(participant|actor)\b|^end$/i.test(e))throw new R("Only participant and actor declarations belong inside a box",t.line,t.column,'Close the box with "end" first.');if(s=/^title(?:\s*:\s*|\s+)(.*)$/i.exec(e)){this.diagram.title=s[1].trim();return}if(s=/^autonumber(?:\s+(.*))?$/i.exec(e)){this.autonumber(s[1]?.trim()??"",t);return}if(s=/^(create\s+)?(participant|actor)\s+(.+)$/i.exec(e)){this.declare(s[3],s[2].toLowerCase(),!!s[1],t,e.length-s[3].length);return}if(s=/^destroy\s+(.+)$/i.exec(e)){const n=this.id(s[1],t,e.length-s[1].length);if(!this.byId.has(n))throw new R(`"${n}" is not a participant`,t.line,t.column);this.pendingDestroy.add(n),this.diagram.events.push({kind:"destroy",actor:n,sourceLine:t.line});return}if(s=/^box(?:\s+(.*))?$/i.exec(e)){this.box(s[1]?.trim()??"",t);return}if(s=/^(activate|deactivate)\s+(.+)$/i.exec(e)){const n=s[1].toLowerCase(),o=this.use(s[2],t,e.length-s[2].length);n==="activate"?this.activate(o):this.deactivate(o,t),this.diagram.events.push({kind:n,actor:o,sourceLine:t.line});return}if(s=/^note\s+(left of|right of|over)\s+([^:]+?)\s*:\s?(.*)$/i.exec(e)){const n=s[1].toLowerCase().split(" ")[0],o=s[2].split(",").map(a=>a.trim());if(o.length>2||o.length===2&&n!=="over")throw new R('Only "over" spans two participants',t.line,t.column,"Note over A,B: text");const i=e.indexOf(s[2]),r=o.map(a=>this.use(a,t,i));this.diagram.events.push({kind:"note",placement:n,actors:r,text:s[3].trim(),sourceLine:t.line});return}if(/^note\b/i.test(e))throw new R(`"${e}" is not a note`,t.line,t.column,"Note left of A: text, Note right of A: text, Note over A,B: text");if(s=/^(loop|alt|opt|par|critical|break)(?:\s+(.*))?$/i.exec(e)){const n=s[1].toLowerCase();this.stack.push({block:n,line:t.line}),this.diagram.events.push({kind:"block-start",block:n,text:s[2]?.trim()??"",sourceLine:t.line});return}if(s=/^rect(?:\s+(.*))?$/i.exec(e)){const n=s[1]?.trim()??"";if(n==="")throw new R('"rect" needs a colour',t.line,t.column,"rect rgb(200, 220, 255)");const o=ee(n,t.line,t.column+5);this.stack.push({block:"rect",line:t.line}),this.diagram.events.push({kind:"block-start",block:"rect",text:"",color:o,sourceLine:t.line});return}if(s=/^(else|and|option)(?:\s+(.*))?$/i.exec(e)){const n=s[1].toLowerCase(),o={else:"alt",and:"par",option:"critical"}[n],i=this.stack[this.stack.length-1];if(!i||i.block!==o)throw new R(`"${n}" belongs inside "${o}"`,t.line,t.column);this.diagram.events.push({kind:"block-section",keyword:n,text:s[2]?.trim()??"",sourceLine:t.line});return}if(/^end$/i.test(e)){const n=this.stack.pop();if(!n)throw new R('"end" without a block to close',t.line,t.column);n.block==="box"?this.currentBox=null:this.diagram.events.push({kind:"block-end",sourceLine:t.line});return}this.message(t)}autonumber(t,e){if(t==="")this.numbering={next:1,step:1};else if(/^off$/i.test(t))this.numbering=null;else{const s=/^([0-9]+)(?:\s+([0-9]+))?$/.exec(t);if(!s)throw new R(`"${t}" is not a valid autonumber`,e.line,e.column,"autonumber [start [step]] or autonumber off");this.numbering={next:Number(s[1]),step:s[2]?Number(s[2]):1}}}box(t,e){if(this.stack.length>0)throw new R("A box cannot be nested inside a block or another box",e.line,e.column);let s,n=t;const o=/^((?:rgb|rgba|hsl|hsla)\([^)]*\))\s*(.*)$/i.exec(t),i=/^(#[0-9a-fA-F]{3,8}|[a-zA-Z]+)(?:\s+(.*))?$/.exec(t);o?(s=ee(o[1],e.line,e.column+4),n=o[2].trim()):i&&(i[1].startsWith("#")||Mo.has(i[1].toLowerCase()))&&(s=ee(i[1],e.line,e.column+4),n=i[2]?.trim()??""),this.diagram.boxes.push({label:n===""?void 0:n,color:s}),this.currentBox=this.diagram.boxes.length-1,this.stack.push({block:"box",line:e.line})}id(t,e,s){const n=t.trim();if(n===""||vo.test(n))throw new R(`"${n}" is not a valid participant name`,e.line,e.column+s);return n}declare(t,e,s,n,o){if(/@\{/.test(t))throw new R("Participant metadata (@{ … }) is not supported",n.line,n.column+o+t.indexOf("@"),'Use "participant A" or "actor A".');const i=/^(.+?)\s+as\s+(.+)$/.exec(t),r=this.id(i?i[1]:t,n,o),a=i?Yt(i[2]):r,c=this.byId.get(r);if(s&&c)throw new R(`"${r}" already exists and cannot be created again`,n.line,n.column+o);if(c){c.label=a,c.kind=e,this.currentBox!==null&&(c.box=this.currentBox);return}const l={id:r,label:a,kind:e,created:s};this.currentBox!==null&&(l.box=this.currentBox),this.byId.set(r,l),this.diagram.participants.push(l)}use(t,e,s){const n=this.id(t,e,s);if(this.destroyed.has(n))throw new R(`"${n}" was destroyed earlier and cannot be used`,e.line,e.column+s);if(!this.byId.has(n)){const o={id:n,label:n,kind:"participant",created:!1};this.byId.set(n,o),this.diagram.participants.push(o)}return n}activate(t){this.active.set(t,(this.active.get(t)??0)+1)}deactivate(t,e){const s=this.active.get(t)??0;if(s<=0)throw new R(`"${t}" is not active, so it cannot be deactivated`,e.line,e.column);this.active.set(t,s-1)}message(t){const e=t.text,s=e.indexOf(":"),n=s>=0?e.slice(0,s):e,o=s>=0?e.slice(s+1).trim():"",i=[];for(let $=0;$<n.length;$++){const k=Es.find(S=>n.startsWith(S.token,$));k&&(i.push({at:$,arrow:k}),$+=k.token.length-1)}if(i.length===0)throw new R(`"${e}" is not a statement`,t.line,t.column,`Messages are written A->>B: text, with one of ${ss}.`);const r=i.find($=>this.byId.has(n.slice(0,$.at).trim()))??i.find($=>$.arrow.head!=="cross")??i[0],a=n.slice(0,r.at);let c=n.slice(r.at+r.arrow.token.length);const l=r.at,h=r.at+r.arrow.token.length;let b=!1,p=!1;const u=/^\s*([+-])/.exec(c);u&&(u[1]==="+"?b=!0:p=!0,c=c.slice(u[0].length));const d=($,k)=>{if(/^[<>=)-]|[<>=-]$/.test($.trim()))throw new R(`"${e.slice(0,s>=0?s:e.length).trim()}" does not use a known arrow`,t.line,t.column+k,`Arrows: ${ss}.`)};d(c,h),d(a,l);const f=this.use(a,t,0),y=this.use(c,t,h);p&&this.deactivate(f,t),b&&this.activate(y);for(const $ of[f,y])this.pendingDestroy.has($)&&(this.pendingDestroy.delete($),this.destroyed.add($));const T={kind:"message",from:f,to:y,line:r.arrow.line,head:r.arrow.head,bidirectional:r.arrow.both,text:o,activateTarget:b,deactivateSource:p,sourceLine:t.line};this.numbering&&(T.number=this.numbering.next,this.numbering.next+=this.numbering.step),this.diagram.events.push(T)}};function Eo(t){const e=new So(To(St(t))).run();if(e.participants.length===0)throw new R("The sequence diagram has no participants",0,0,"Add a message such as A->>B: Hello");return e}var Ao=9;function As(t){switch(t){case"arrow":return"arrow";case"open":return"open-arrow";case"cross":return"cross";default:return null}}function Co(t){if(t.kind==="actor"){const e=t.x,s=t.top,n=7,o=s+14,i=o+13,r=s+34,a=new vt().moveTo(e,o).lineTo(e,i).moveTo(e-12,o+5).lineTo(e+12,o+5).moveTo(e,i).lineTo(e-10,r).moveTo(e,i).lineTo(e+10,r);return v("g",{class:"dg-actor"},[v("circle",{class:"dg-actor-figure",cx:e,cy:s+n,r:n}),v("path",{class:"dg-actor-figure dg-actor-limbs",d:a.toString()}),tt(t.label,e,r+4+t.label.height/2,{className:"dg-actor-label"})])}return v("g",{class:"dg-actor"},[v("rect",{class:"dg-actor-box",x:t.x-t.width/2,y:t.top,width:t.width,height:t.height,rx:4,ry:4}),tt(t.label,t.x,t.top+t.height/2,{className:"dg-actor-label"})])}function Io(t){const e=[v("rect",{class:"dg-block",x:t.left,y:t.top,width:t.right-t.left,height:t.bottom-t.top})];if(t.tab){const s=t.tabWidth,n=[[t.left,t.top],[t.left+s,t.top],[t.left+s,t.top+20-6],[t.left+s-6,t.top+20],[t.left,t.top+20]].map(([o,i])=>`${Math.round(o*100)/100},${Math.round(i*100)/100}`).join(" ");e.push(v("polygon",{class:"dg-block-tab",points:n}),tt(t.tab,t.left+s/2,t.top+10,{className:"dg-block-label"}))}t.guard&&e.push(tt(t.guard,t.left+t.tabWidth+8,t.top+Math.max(20,t.guard.height)/2,{anchor:"start",className:"dg-block-guard"}));for(const s of t.sections)e.push(v("line",{class:"dg-block-sep",x1:t.left,y1:s.y,x2:t.right,y2:s.y})),s.guard&&e.push(tt(s.guard,(t.left+t.right)/2,s.y+4+s.guard.height/2,{className:"dg-block-guard"}));return v("g",{class:`dg-frame dg-frame-${t.block}`},e)}function Lo(t,e){const s=As(t.head),n=s?`url(#${Tt(e,s)})`:void 0,o=s&&t.bidirectional?`url(#${Tt(e,s,!0)})`:void 0,i=`dg-message${t.line==="dotted"?" dg-message-dotted":""}`,r=[];if(t.self){const a=new vt().moveTo(t.x1,t.y).lineTo(t.loopRight,t.y).lineTo(t.loopRight,t.y2).lineTo(t.x2,t.y2);r.push(v("path",{class:i,d:a.toString(),"marker-end":n,"marker-start":o}))}else r.push(v("line",{class:i,x1:t.x1,y1:t.y,x2:t.x2,y2:t.y,"marker-end":n,"marker-start":o}));return t.label&&r.push(tt(t.label,t.labelX,t.labelY,{anchor:t.anchor,className:"dg-message-text"})),t.number!==void 0&&r.push(v("circle",{class:"dg-number",cx:t.x1,cy:t.y,r:Ao}),v("text",{class:"dg-number-text",x:t.x1,y:t.y,"text-anchor":"middle","dominant-baseline":"central"},[kt(String(t.number))])),v("g",{class:"dg-message-group"},r)}function Do(t,e,s,n){const o=new Set;for(const l of t.messages){const h=As(l.head);h&&o.add(h)}const i=[v("g",{class:"dg-groups"},t.groups.map(l=>v("g",{class:"dg-group"},[v("rect",{class:"dg-group-box",x:l.left,y:l.top,width:l.right-l.left,height:l.bottom-l.top,rx:4,style:l.color?`fill:${l.color}`:void 0}),l.label?tt(l.label,(l.left+l.right)/2,l.top+4+l.label.height/2,{className:"dg-group-label"}):null]))),v("g",{class:"dg-rects"},t.rects.map(l=>v("rect",{class:"dg-rect",x:l.left,y:l.top,width:l.right-l.left,height:l.bottom-l.top,style:l.color?`fill:${l.color}`:void 0}))),v("g",{class:"dg-lifelines"},t.lifelines.filter(l=>l.y2>l.y1).map(l=>v("line",{class:"dg-lifeline",x1:l.x,y1:l.y1,x2:l.x,y2:l.y2}))),v("g",{class:"dg-frames"},t.frames.map(Io)),v("g",{class:"dg-activations"},t.activations.map(l=>v("rect",{class:"dg-activation",x:l.left,y:l.top,width:10,height:l.bottom-l.top}))),v("g",{class:"dg-messages"},t.messages.map(l=>Lo(l,e))),v("g",{class:"dg-notes"},t.notes.map(l=>v("g",{class:"dg-note-group"},[v("rect",{class:"dg-note",x:l.left,y:l.top,width:l.width,height:l.height,rx:2}),tt(l.label,l.left+l.width/2,l.top+l.height/2,{className:"dg-note-text"})]))),v("g",{class:"dg-crosses"},t.crosses.map(l=>v("path",{class:"dg-destroy",d:new vt().moveTo(l.x-9,l.y-9).lineTo(l.x+9,l.y+9).moveTo(l.x-9,l.y+9).lineTo(l.x+9,l.y-9).toString()}))),v("g",{class:"dg-actors"},t.actors.map(Co))],r=[];t.title&&r.push(tt(t.title.label,t.title.x,t.title.y,{className:"dg-title"})),r.push(v("g",{transform:`translate(${Math.round(t.offsetX*100)/100},0)`},i));const a=`#${e}`,c=[`${a} .dg-title{fill:${N("--dg-text")};font-size:18px;font-weight:bold}`,`${a} .dg-actor-box{fill:${N("--dg-actor-fill")};stroke:${N("--dg-actor-stroke")};stroke-width:1.5px}`,`${a} .dg-actor-figure{fill:${N("--dg-actor-fill")};stroke:${N("--dg-actor-stroke")};stroke-width:1.5px}`,`${a} .dg-actor-limbs{fill:none}`,`${a} .dg-actor-label{fill:${N("--dg-text")}}`,`${a} .dg-lifeline{stroke:${N("--dg-lifeline")};stroke-width:1px;stroke-dasharray:4 3}`,`${a} .dg-activation{fill:${N("--dg-activation-fill")};stroke:${N("--dg-actor-stroke")};stroke-width:1px}`,`${a} .dg-message{fill:none;stroke:${N("--dg-line")};stroke-width:1.5px}`,`${a} .dg-message-dotted{stroke-dasharray:4 3}`,`${a} .dg-message-text{fill:${N("--dg-text")}}`,`${a} .dg-number{fill:${N("--dg-line")}}`,`${a} .dg-number-text{fill:${N("--dg-number-text")};font-size:11px;font-weight:bold}`,`${a} .dg-note{fill:${N("--dg-note-fill")};stroke:${N("--dg-note-stroke")};stroke-width:1px}`,`${a} .dg-note-text{fill:${N("--dg-note-text")}}`,`${a} .dg-block{fill:none;stroke:${N("--dg-block-stroke")};stroke-width:1.5px}`,`${a} .dg-block-tab{fill:${N("--dg-block-label-fill")};stroke:${N("--dg-block-stroke")};stroke-width:1px}`,`${a} .dg-block-label{fill:${N("--dg-text")};font-size:13px;font-weight:bold}`,`${a} .dg-block-guard{fill:${N("--dg-text-muted")};font-size:13px}`,`${a} .dg-block-sep{stroke:${N("--dg-block-stroke")};stroke-width:1px;stroke-dasharray:4 3}`,`${a} .dg-rect{fill:${N("--dg-rect-fill")}}`,`${a} .dg-group-box{fill:none;stroke:${N("--dg-cluster-stroke")};stroke-width:1px}`,`${a} .dg-group-label{fill:${N("--dg-cluster-text")};font-weight:600}`,`${a} .dg-destroy{fill:none;stroke:${N("--dg-line")};stroke-width:2px}`].join("");return Ot({id:e,type:"sequence",width:t.width,height:t.height,title:s,description:n,defs:xe(e,o),body:r,css:c})}function No(t,e,s,n){return Do($o(t,e),s,n??t.accessibility.title??t.title??"Sequence diagram",t.accessibility.description)}var Ro={TB:"TB",TD:"TB",BT:"BT",LR:"LR",RL:"RL"},xt="[\\p{L}\\p{N}_][\\p{L}\\p{N}_.-]*",os=`(\\[\\*\\]|${xt})`;function Oo(t){const e=St(t),s=e[0];if(!s||!/^stateDiagram(-v2)?$/.test(s.text))throw new R('A state diagram starts with "stateDiagram-v2"',s?.line??1,1);const n={type:"state",direction:"TB",states:new Map,composites:new Map,transitions:[],notes:[],classDefs:new Map,accessibility:{}},o=[],i=new Map,r=[],a=[],c=()=>o[o.length-1]?.id,l=p=>{const u=c()??"root",d=`\0${p?"start":"end"}:${u}`;return n.states.has(d)||n.states.set(d,{id:d,kind:p?"start":"end",name:"",descriptions:[],parent:c(),classes:[]}),d},h=(p,u)=>{const d=n.composites.get(p);if(d)return d;let f=n.states.get(p);return f||(f={id:p,kind:"state",name:p,descriptions:[],parent:c(),classes:[]},n.states.set(p,f)),f},b=p=>{const u=/^(.*?):::([\w-]+)$/.exec(p);return u?{id:u[1],cls:u[2]}:{id:p}};for(let p=1;p<e.length;p++){const u=e[p],d=u.text,f=_t(e,p,n.accessibility);if(f>0){p+=f-1;continue}let y=/^direction\s+(\w+)$/.exec(d);if(y){const $=Ro[y[1].toUpperCase()];if(!$)throw new R(`"${y[1]}" is not a direction`,u.line,u.column+10);const k=o[o.length-1];k?k.direction=$:n.direction=$;continue}if(y=/^classDef\s+([\w,-]+)\s+(.+)$/.exec(d),y){const $=$t(y[2],u.line,u.column);for(const k of y[1].split(","))n.classDefs.set(k.trim(),$);continue}if(y=/^class\s+(.+?)\s+([\w-]+)$/.exec(d),y){r.push({ids:y[1].split(",").map($=>$.trim()),cls:y[2],s:u});continue}if(y=/^style\s+(\S+)\s+(.+)$/.exec(d),y){a.push({id:y[1],style:$t(y[2],u.line,u.column),s:u});continue}if(y=new RegExp(`^note\\s+(left|right)\\s+of\\s+(${xt})\\s*(?::\\s*(.*))?$`,"u").exec(d),y){const $=y[1],k=y[2];let S=y[3];if(S===void 0){const E=[];let I=p+1;for(;I<e.length&&e[I].text!=="end note";I++)E.push(e[I].text);if(I>=e.length)throw new R("The note is not closed",u.line,u.column,'Add "end note".');S=E.join(`
5
+ `),p=I}n.notes.push({target:k,side:$,text:S});continue}if(y=new RegExp(`^state\\s+(?:"([^"]*)"\\s+as\\s+)?(${xt})\\s*\\{$`,"u").exec(d),y){const $=y[2];if(n.composites.has($))throw new R(`State "${$}" is defined twice`,u.line,u.column);const k=n.states.get($),S={id:$,name:y[1]??k?.name??$,parent:c(),region:!1,classes:k?.classes??[]};k&&(n.states.delete($),S.parent=k.parent),n.composites.set($,S),o.push(S);continue}if(d==="}"){for(;o.length>0&&o[o.length-1].region;)o.pop();if(o.length===0)throw new R('"}" without an open state',u.line,u.column);o.pop();continue}if(d==="--"){for(;o.length>0&&o[o.length-1].region;)o.pop();const $=o[o.length-1];if(!$)throw new R('"--" separates regions inside a composite state',u.line,u.column);const k=i.get($.id)??0;if(k===0){const E={id:`${$.id}\0r0`,name:"",parent:$.id,region:!0,classes:[]};n.composites.set(E.id,E);for(const I of n.states.values())I.parent===$.id&&(I.parent=E.id);for(const I of n.composites.values())I.parent===$.id&&I.id!==E.id&&(I.parent=E.id)}const S={id:`${$.id}\0r${k+1}`,name:"",parent:$.id,region:!0,classes:[]};i.set($.id,k+1),n.composites.set(S.id,S),o.push(S);continue}if(y=new RegExp(`^state\\s+"([^"]*)"\\s+as\\s+(${xt})$`,"u").exec(d),y){const $=h(y[2]);$.name=y[1];continue}if(y=new RegExp(`^state\\s+(${xt})\\s*<<(choice|fork|join)>>$`,"u").exec(d),y){const $=h(y[1]);"kind"in $&&($.kind=y[2]);continue}if(y=new RegExp(`^state\\s+(${xt})(?:\\s*:\\s*(.*))?$`,"u").exec(d),y){const $=h(y[1]);y[2]!==void 0&&"descriptions"in $&&$.descriptions.push(y[2].trim());continue}if(y=new RegExp(`^${os}(?::::([\\w-]+))?\\s*-->\\s*${os}(?::::([\\w-]+))?\\s*(?::\\s*(.*))?$`,"u").exec(d),y){const $=y[1]==="[*]"?l(!0):h(y[1]).id,k=y[3]==="[*]"?l(!1):h(y[3]).id;y[2]&&h($).classes.push(y[2]),y[4]&&h(k).classes.push(y[4]),n.transitions.push({from:$,to:k,label:y[5]?.trim()||void 0});continue}if(y=new RegExp(`^(${xt})\\s*:\\s*(.*)$`,"u").exec(d),y){const $=h(y[1]);"descriptions"in $&&$.descriptions.push(y[2].trim());continue}const T=b(d);if(new RegExp(`^${xt}$`,"u").test(T.id)){const $=h(T.id);T.cls&&$.classes.push(T.cls);continue}throw new R(`"${d}" is not a state diagram statement`,u.line,u.column)}if(o.some(p=>!p.region))throw new R(`State "${o.filter(p=>!p.region).pop().id}" is not closed`,0,0,'Add "}".');for(const p of r)for(const u of p.ids){const d=n.states.get(u)??n.composites.get(u);if(!d)throw new R(`class refers to an unknown state "${u}"`,p.s.line,p.s.column);d.classes.push(p.cls)}for(const p of a){const u=n.states.get(p.id)??n.composites.get(p.id);if(!u)throw new R(`style refers to an unknown state "${p.id}"`,p.s.line,p.s.column);u.style=p.style}for(const p of n.notes)if(!n.states.has(p.target)&&!n.composites.has(p.target))throw new R(`A note refers to an unknown state "${p.target}"`);return n}var se=16;function ne(t){switch(t){case"start":return"start";case"end":return"end";case"choice":return"choice";case"fork":case"join":return"fork";default:return"round"}}function is(t,e,s){return us(s.get("default"),...t.map(n=>s.get(n)),e)}function _o(t,e,s,n){const o=t.direction==="LR"||t.direction==="RL",i={...Q,weight:"bold"},r=new Map;for(const m of t.states.values())if(m.kind==="state")if(m.descriptions.length===0){const w=st(lt(m.name),Q,e),M=ce("round",w.width,w.height);r.set(m.id,{title:w,width:Math.max(M.width,60),height:M.height})}else{const w=st(lt(m.name),i,e),M=st(lt(m.descriptions.join("<br>")),Q,e);r.set(m.id,{title:w,body:M,width:Math.max(w.width,M.width,40)+32,height:w.height+M.height+27})}const a=m=>{if(m.kind==="state")return r.get(m.id);const w=ce(ne(m.kind),0,0);return(m.kind==="fork"||m.kind==="join")&&o?{width:w.height,height:w.width}:w},c=t.notes.map(m=>st(Nt(m.text),Q,e)),l=new Map,h=[];t.notes.forEach((m,w)=>{if(t.composites.has(m.target)){h.push(w);return}const M=c[w],C=(o?M.height:M.width)+16+se;l.set(m.target,Math.max(l.get(m.target)??0,C))});const b=[...t.states.values()].map(m=>{const w=a(m),M=l.get(m.id)??0,C=Math.max(0,...t.notes.map((B,D)=>B.target===m.id?(o?c[D].width:c[D].height)+16:0));return o?{id:m.id,width:Math.max(w.width,C),height:w.height+M*2,cluster:m.parent}:{id:m.id,width:w.width+M*2,height:Math.max(w.height,C),cluster:m.parent}});for(const m of h){const w=c[m];b.push({id:`\0note${m}`,width:w.width+16,height:w.height+16,cluster:t.composites.get(t.notes[m].target).parent})}const p=new Map,u=[...t.composites.values()].map(m=>{!m.region&&m.name!==""&&p.set(m.id,st(lt(m.name),i,e));const w=p.get(m.id);return{id:m.id,parent:m.parent,direction:m.direction,label:w?{width:w.width,height:w.height}:void 0}}),d=new Map,f=t.transitions.map((m,w)=>{let M;if(m.label){const C=st(lt(m.label),Q,e);d.set(w,C),M={width:C.width+8,height:C.height+4}}return{id:String(w),from:m.from,to:m.to,label:M}});for(const m of h)f.push({id:`note${m}`,from:`\0note${m}`,to:t.notes[m].target,weight:0});const y=jt({direction:t.direction,nodes:b,edges:f,clusters:u,nodeSep:40,rankSep:40,clusterPadding:14}),T=m=>{const w=y.nodes.get(m.id),M=a(m);return{x:w.x,y:w.y,width:M.width,height:M.height}},$=m=>{let w=0,M=t.composites.get(m)?.parent;for(;M;)w++,M=t.composites.get(M)?.parent;return w},k=[...t.composites.values()].sort((m,w)=>$(m.id)-$(w.id)).map(m=>{const w=y.clusters.get(m.id),M=is(m.classes,m.style,t.classDefs),C=w.x-w.width/2,B=w.y-w.height/2;if(m.region)return v("rect",{class:"dg-state-region",x:C,y:B,width:w.width,height:w.height,rx:4});const D=p.get(m.id),U=D?D.height+10:0;return v("g",{class:"dg-cluster dg-state-composite","data-id":m.id},[v("rect",{class:"dg-cluster-box",x:C,y:B,width:w.width,height:w.height,rx:8,style:ut(M.shape)}),D?v("line",{class:"dg-state-divider",x1:C,y1:B+U,x2:C+w.width,y2:B+U}):null,D?tt(D,w.x,B+U/2,{className:"dg-cluster-label",style:ut(M.text)}):null])}),S=m=>{const w=t.states.get(m);if(w){const C=T(w);return{box:C,clip:B=>he(ne(w.kind),C,B)}}const M=y.clusters.get(m)??y.nodes.get(m);return{box:M,clip:C=>Pt(M,C)}},E=[],I=[];t.transitions.forEach((m,w)=>{const M=y.edges.get(String(w));if(!M)return;let C;if(M.selfLoop)C=M.points;else{const D=S(m.from),U=S(m.to);C=[M.start??D.clip(M.points[0]??U.box),...M.points,M.end??U.clip(M.points[M.points.length-1]??D.box)]}E.push(v("path",{class:"dg-edge",d:ks(C),"marker-end":`url(#${Tt(s,"arrow")})`}));const B=d.get(w);if(B&&M.label){const D=B.width+8,U=B.height+4;I.push(v("g",{},[v("rect",{class:"dg-edge-label-box",x:M.label.x-D/2,y:M.label.y-U/2,width:D,height:U,rx:3}),tt(B,M.label.x,M.label.y,{className:"dg-edge-label"})]))}});const L=[];t.notes.forEach((m,w)=>{const M=c[w],C=M.width+16,B=M.height+16;let D,U;const Z=t.states.get(m.target);if(Z){const j=T(Z),G=m.side==="left"?-1:1;if(o){const J=j.height/2+se+B/2;D={x:j.x,y:j.y+G*J,width:C,height:B},U={x:j.x,y:j.y+G*j.height/2}}else{const J=j.width/2+se+C/2;D={x:j.x+G*J,y:j.y,width:C,height:B},U={x:j.x+G*j.width/2,y:j.y}}}else D=y.nodes.get(`\0note${w}`),U=Pt(y.clusters.get(m.target),D);const F=Pt(D,U);L.push(v("g",{class:"dg-note"},[v("line",{class:"dg-note-link",x1:F.x,y1:F.y,x2:U.x,y2:U.y}),v("rect",{class:"dg-note-box",x:D.x-C/2,y:D.y-B/2,width:C,height:B,rx:2}),tt(M,D.x,D.y,{className:"dg-note-text"})]))});const O=[...t.states.values()].map(m=>{const w=T(m),M=is(m.classes,m.style,t.classDefs);if(m.kind!=="state")return v("g",{class:`dg-node dg-state-${m.kind}`,"data-id":m.kind==="start"||m.kind==="end"?void 0:m.id},[de(ne(m.kind),w,{style:ut(M.shape)})]);const C=r.get(m.id),B=[de("round",w,{style:ut(M.shape)})];if(!C.body)B.push(tt(C.title,w.x,w.y,{style:ut(M.text)}));else{const D=w.y-w.height/2,U=D+9+C.title.height/2,Z=D+13.5+C.title.height;B.push(tt(C.title,w.x,U,{style:ut(M.text)}),v("line",{class:"dg-state-divider",x1:w.x-w.width/2,y1:Z,x2:w.x+w.width/2,y2:Z}),tt(C.body,w.x,Z+9/2+C.body.height/2+9/2,{style:ut(M.text)}))}return v("g",{class:["dg-node","dg-state",...m.classes.map(D=>`dg-class-${D.replace(/[^\w-]/g,"")}`)].join(" "),"data-id":m.id},B)}),P=[`#${s} .dg-state-start{fill:${N("--dg-state-start")};stroke:none}`,`#${s} .dg-state-end-ring{fill:none;stroke:${N("--dg-state-start")};stroke-width:1.5px}`,`#${s} .dg-state-divider{stroke:${N("--dg-node-stroke")};stroke-width:1px}`,`#${s} .dg-state-composite .dg-state-divider{stroke:${N("--dg-cluster-stroke")}}`,`#${s} .dg-state-region{fill:none;stroke:${N("--dg-cluster-stroke")};stroke-dasharray:5 4}`,`#${s} .dg-state-choice .dg-shape{fill:${N("--dg-node-fill")};stroke:${N("--dg-node-stroke")}}`,`#${s} .dg-note-box{fill:${N("--dg-note-fill")};stroke:${N("--dg-note-stroke")}}`,`#${s} .dg-note-text{fill:${N("--dg-note-text")}}`,`#${s} .dg-note-link{stroke:${N("--dg-note-stroke")};stroke-dasharray:3 3}`].join("");return Ot({id:s,type:"state",width:y.width,height:y.height,title:n??t.accessibility.title??"State diagram",description:t.accessibility.description,defs:xe(s,["arrow"]),body:[v("g",{class:"dg-clusters"},k),v("g",{class:"dg-edges"},E),v("g",{class:"dg-edge-labels"},I),v("g",{class:"dg-notes"},L),v("g",{class:"dg-nodes"},O)],css:P})}var Wo={pie:{parse:Js,render:tn},gantt:{parse:wn,render:Tn},flowchart:{parse:Ln,render:ao},sequence:{parse:Eo,render:No},state:{parse:Oo,render:_o}},fe={pie:"pie",gantt:"gantt",flowchart:"flowchart",graph:"flowchart","flowchart-elk":"flowchart",sequenceDiagram:"sequence",stateDiagram:"state","stateDiagram-v2":"state"};function Fo(t){const e=hs(t);return e?fe[e.keyword]??null:null}function Cs(t){const e=hs(t);if(!e)throw new R("The diagram is empty",0,0);const s=fe[e.keyword];if(!s)throw new R(`"${e.keyword}" is not a supported diagram type`,e.statement.line,e.statement.column,`Supported: ${Object.keys(fe).join(", ")}.`);return Wo[s]}function Bo(t){return Cs(t).parse(t)}function Uo(t,e={}){const s=Cs(t),n=s.parse(t),o=_s(e.idPrefix??Os(t));return s.render(n,e.measureText??js(),o,e.title,e.today)}export{R as DiagramError,Is as THEME_VARIABLES,Ps as approximateMeasurer,js as defaultMeasurer,Fo as detect,Bo as parse,Uo as render};
@@ -10,8 +10,8 @@ declare const _default: import("vue").DefineComponent<Props, {}, {}, {}, {}, imp
10
10
  code: string | null;
11
11
  title: string | null;
12
12
  wrap: boolean;
13
- language: string | null;
14
13
  maxHeight: string | null;
14
+ language: string | null;
15
15
  lineNumbers: boolean;
16
16
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
17
17
  export default _default;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Fenced-block renderers for every markdown the panel shows — the Markdown
3
+ * layout, field preview, widget and infolist entry, all drawn by the kit's
4
+ * UidMarkdown.
5
+ *
6
+ * ```mermaid blocks become diagrams through @dskripchenko/diagrams. It is
7
+ * imported on first use, so a page without diagrams never downloads it. The
8
+ * SVG it returns escapes every label by construction, which is what makes it
9
+ * safe to insert as markup; a source it cannot read comes back as an error,
10
+ * and UidMarkdown then shows the code with the message.
11
+ */
12
+ import type { App } from 'vue';
13
+ import { type UidMarkdownBlockRenderer, type UidMarkdownBlockRenderers } from '@dskripchenko/ui';
14
+ type DiagramsModule = typeof import('@dskripchenko/diagrams');
15
+ /** @internal Replaces the dynamic import, for tests. */
16
+ export declare function setDiagramsLoader(loader: (() => Promise<DiagramsModule>) | null): void;
17
+ export declare const mermaidRenderer: UidMarkdownBlockRenderer;
18
+ /** The renderers the panel registers app-wide. */
19
+ export declare const builtinMarkdownRenderers: UidMarkdownBlockRenderers;
20
+ /**
21
+ * Registers the built-in renderers for the whole app. A host adds its own
22
+ * the same way in `onAppCreated`, spreading these first:
23
+ * `app.provide(markdownBlockRenderersKey, { ...builtinMarkdownRenderers, chart })`.
24
+ */
25
+ export declare function provideBuiltinMarkdownRenderers(app: App): void;
26
+ export {};
@@ -0,0 +1,7 @@
1
+ import { type ComputedRef } from 'vue';
2
+ import type { UidMarkdownCalloutKind } from '@dskripchenko/ui';
3
+ /**
4
+ * Callout titles in the panel's language, through its own dictionaries —
5
+ * which cover more languages than the kit's string bags.
6
+ */
7
+ export declare function useCalloutTitles(): ComputedRef<Record<UidMarkdownCalloutKind, string>>;