@zombie-mermaid/ascii-renderer 2.2.6 → 3.0.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.
Files changed (32) hide show
  1. package/dist/index.cjs +7 -7
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +1245 -1203
  4. package/dist/index.js.map +1 -1
  5. package/package.json +3 -3
  6. package/src/__tests__/ascii-decision-lr-box-start.test.ts +1 -1
  7. package/src/__tests__/ascii-er-attribute-column-order-1134.test.ts +69 -0
  8. package/src/__tests__/ascii-er-corner-glyphs.test.ts +27 -4
  9. package/src/__tests__/ascii-er-relationship-label-corruption-350.test.ts +13 -3
  10. package/src/__tests__/ascii-er-relationship-overwrite.test.ts +107 -0
  11. package/src/__tests__/ascii-er-stray-connectors.test.ts +15 -9
  12. package/src/__tests__/ascii-sequence-activation.test.ts +171 -0
  13. package/src/__tests__/ascii-shape-diamond.test.ts +1 -1
  14. package/src/__tests__/ascii-shape-rounded.test.ts +1 -1
  15. package/src/__tests__/ascii-shapes-circle.test.ts +1 -1
  16. package/src/__tests__/ascii-shapes-hexagon.test.ts +1 -1
  17. package/src/__tests__/ascii-shapes-special.test.ts +35 -0
  18. package/src/__tests__/ascii-validate.test.ts +1 -42
  19. package/src/__tests__/ascii.test.ts +1 -1
  20. package/src/__tests__/testdata/ascii/er_attributes.txt +9 -9
  21. package/src/__tests__/testdata/ascii/er_identifying.txt +8 -8
  22. package/src/__tests__/testdata/unicode/er_attributes.txt +9 -9
  23. package/src/__tests__/testdata/unicode/er_identifying.txt +8 -8
  24. package/src/{validate.ts → __tests__/validate.ts} +3 -40
  25. package/src/draw-boxes.ts +14 -0
  26. package/src/er-diagram.ts +134 -31
  27. package/src/sequence.ts +87 -1
  28. package/src/shapes/index.ts +47 -5
  29. package/src/shapes/circle.ts +0 -31
  30. package/src/shapes/diamond.ts +0 -31
  31. package/src/shapes/hexagon.ts +0 -35
  32. package/src/shapes/rounded.ts +0 -31
package/dist/index.cjs CHANGED
@@ -1,8 +1,8 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@zombie-mermaid/core"),t=require("@zombie-mermaid/mermaid-parser");function n(e){return[e.length-1,(e[0]?.length??1)-1]}var r=`\x1B]8;;\x1B\\`;function i(e){return`\x1b]8;;${e.replace(/[^\x21-\x7e]/gu,e=>encodeURIComponent(e))}\x1b\\`}var a=/\x1b\]8;[^\x07\x1b]*(?:\x1b\\|\x07)/g;function o(e){return e.replace(a,``)}function s(e,t){let n=[];for(let r=0;r<=e;r++){let e=[];for(let n=0;n<=t;n++)e.push(null);n.push(e)}return n}function c(e,t,n,r){let i=e[t];i===void 0||n<0||n>=i.length||(i[n]=r)}function l(e){for(let t of e)t.reverse();return e}function u(e,t,r,i,a){let[o,s]=n(t),l=Math.max(1,a?.from??1),u=Math.min(s-1,a?.to??s-1);for(let n=l;n<=u;n++){let a=-1,s=-1;for(let e=1;e<=o-1;e++)t[e]?.[n]!==` `&&(a===-1&&(a=e),s=e);if(a!==-1)for(let t=a;t<=s;t++)c(e,t+r.x,n+r.y,i)}}function d(t,r){let[i,a]=n(t.canvas),o=s(i,a);for(let n of t.nodes){if(!n.drawing||!n.drawingCoord)continue;let t=(0,e.safeHref)(r.get(n.name)?.href);t!==void 0&&u(o,n.drawing,n.drawingCoord,t)}return o}var f=class{current=null;advance(e){if(e===this.current)return``;let t=this.current===null?``:r;return e!==null&&(t+=i(e)),this.current=e,t}finish(){let e=this.current===null?``:r;return this.current=null,e}};function p(e,t){let n=new f,r=``;for(let[i,a]of e.entries())r+=n.advance(t[i]??null)+a;return r+n.finish()}var m={fg:`#27272a`,border:`#a1a1aa`,line:`#71717a`,arrow:`#52525b`,corner:`#71717a`,junction:`#a1a1aa`};function h(t){let n=t.line??(0,e.mixHexColors)(t.fg,t.bg,e.MIX.line),r=t.border??(0,e.mixHexColors)(t.fg,t.bg,e.MIX.nodeStroke);return{fg:t.fg,border:r,line:n,arrow:t.accent??(0,e.mixHexColors)(t.fg,t.bg,e.MIX.arrow),accent:t.accent,bg:t.bg,corner:n,junction:r}}function g(){let e=globalThis.process;if(e){if(!e.stdout?.isTTY)return`none`;let t=e.env?.COLORTERM?.toLowerCase()??``,n=e.env?.TERM?.toLowerCase()??``;return t===`truecolor`||t===`24bit`?`truecolor`:n.includes(`256color`)||n.includes(`256`)?`ansi256`:n&&n!==`dumb`?`ansi16`:`none`}return typeof document<`u`?`html`:`none`}function _(t){return(0,e.parseHexRgba)(t.startsWith(`#`)?t:`#${t}`)??{r:0,g:0,b:0}}var v=`\x1B[`,y=`${v}0m`;function b(e){let{r:t,g:n,b:r}=_(e);return`${v}38;2;${t};${n};${r}m`}function x(e,t,n){let r=(e+t+n)/3;if(Math.max(Math.abs(e-r),Math.abs(t-r),Math.abs(n-r))<10){let e=Math.round(r/255*23);return 232+Math.min(23,Math.max(0,e))}let i=e=>e<48?0:e<115?1:Math.min(5,Math.floor((e-35)/40)),a=i(e),o=i(t),s=i(n);return 16+36*a+6*o+s}function S(e){let{r:t,g:n,b:r}=_(e);return`${v}38;5;${x(t,n,r)}m`}function C(e){let{r:t,g:n,b:r}=_(e),i=.299*t+.587*n+.114*r,a=i>100?0:60,o;return o=t>180&&n<100&&r<100?31:n>180&&t<100&&r<100?32:t>150&&n>150&&r<100?33:r>180&&t<100&&n<100?34:t>150&&r>150&&n<100?35:n>150&&r>150&&t<100?36:i>200?37:i<50?30:37,`${v}${o+a}m`}function w(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}function T(e,t){return`<span style="color:${e}">${w(t)}</span>`}function E(e,t){switch(e){case`text`:return t.fg;case`border`:return t.border;case`line`:return t.line;case`arrow`:return t.arrow;case`corner`:return t.corner??t.line;case`junction`:return t.junction??t.border;default:return t.fg}}function D(e,t,n){if(n===`none`)return``;let r=E(e,t);switch(n){case`truecolor`:return b(r);case`ansi256`:return S(r);case`ansi16`:return C(r);default:return``}}function O(e,t,n,r,i){if(r===`none`)return i?p(e,i):e.join(``);if(r===`html`)return ee(e,t,n);let a=new f,o=``,s=null,c=``;for(let[l,u]of e.entries()){let e=t[l]??null,d=i?a.advance(i[l]??null):``;if(u===` `){c.length>0&&(o+=s===null?c:D(s,n,r)+c+y,c=``,s=null),o+=d+u;continue}if(e===s){c+=d+u;continue}c.length>0&&(o+=s===null?c:D(s,n,r)+c+y),c=d+u,s=e}return c.length>0&&s!==null?o+=D(s,n,r)+c+y:c.length>0&&(o+=c),o+a.finish()}function ee(e,t,n){let r=``,i=null,a=``,o=()=>{a.length!==0&&(r+=i===null?w(a):T(E(i,n),a),a=``,i=null)};for(let[n,s]of e.entries()){let e=t[n]??null;if(s===` `){o(),r+=` `;continue}if(e===i){a+=s;continue}o(),a=s,i=e}return o(),r}function k(e,t,n){if(n===`none`||e.length===0)return e;if(n===`html`)return T(t,e);let r;switch(n){case`truecolor`:r=b(t);break;case`ansi256`:r=S(t);break;case`ansi16`:r=C(t);break;default:return e}return`${r}${e}${y}`}var te=/\p{Mn}|\p{Me}/u;function ne(e){return te.test(e)}var A=new Intl.Segmenter(void 0,{granularity:`grapheme`}),j=`️`;function re(e){let t=[];for(let{segment:n}of A.segment(e))t.push(n);return t}function ie(t){if(t.includes(j))return 2;let n=!1,r=!1;for(let i of t)(0,e.isWideChar)(i)&&(n=!0),ne(i)||(r=!0);return n?2:+!!r}function M(e){let t=0;for(let n of re(e))t+=ie(n);return t}function ae(e){let t=[];for(let n of re(e)){let e=ie(n);e!==0&&(t.push(n),e===2&&t.push(``))}return t}function N(e,t){let n=[];for(let r=0;r<=e;r++){let e=[];for(let n=0;n<=t;n++)e.push(` `);n.push(e)}return n}function P(e){let[t,n]=L(e);return N(t,n)}function F(e,t){let n=[];for(let r=0;r<=e;r++){let e=[];for(let n=0;n<=t;n++)e.push(null);n.push(e)}return n}function oe(e,t,n){let r=e.length-1,i=(e[0]?.length??1)-1,a=F(Math.max(t,r),Math.max(n,i));for(let t=0;t<a.length;t++)for(let n=0;n<(a[0]?.length??0);n++)t<e.length&&n<(e[0]?.length??0)&&(a[t][n]=e[t][n]);return e.length=0,e.push(...a),e}function I(e,t,n,r){(t>=e.length||n>=(e[0]?.length??0))&&oe(e,t,n),e[t][n]=r}function L(e){return[e.length-1,(e[0]?.length??1)-1]}function se(e,t,n){let[r,i]=L(e),a=N(Math.max(t,r),Math.max(n,i));for(let t=0;t<a.length;t++)for(let n=0;n<(a[0]?.length??0);n++)t<e.length&&n<(e[0]?.length??0)&&(a[t][n]=e[t][n]);return e.length=0,e.push(...a),e}function R(e,t,n,r,i){let[a,o]=L(e);t<0||t>a||n<0||n>o||(e[t][n]=r,i&&I(i.roleCanvas,t,n,i.role))}var ce=new Set([`─`,`│`,`┌`,`┐`,`└`,`┘`,`├`,`┤`,`┬`,`┴`,`┼`,`╴`,`╵`,`╶`,`╷`]);function le(e){return ce.has(e)}function ue(e){return/^[a-zA-Z0-9]$/.test(e)}var de={"─":{"│":`┼`,"┌":`┬`,"┐":`┬`,"└":`┴`,"┘":`┴`,"├":`┼`,"┤":`┼`,"┬":`┬`,"┴":`┴`},"│":{"─":`┼`,"┌":`├`,"┐":`┤`,"└":`├`,"┘":`┤`,"├":`├`,"┤":`┤`,"┬":`┼`,"┴":`┼`},"┌":{"─":`┬`,"│":`├`,"┐":`┬`,"└":`├`,"┘":`┼`,"├":`├`,"┤":`┼`,"┬":`┬`,"┴":`┼`},"┐":{"─":`┬`,"│":`┤`,"┌":`┬`,"└":`┼`,"┘":`┤`,"├":`┼`,"┤":`┤`,"┬":`┬`,"┴":`┼`},"└":{"─":`┴`,"│":`├`,"┌":`├`,"┐":`┼`,"┘":`┴`,"├":`├`,"┤":`┼`,"┬":`┼`,"┴":`┴`},"┘":{"─":`┴`,"│":`┤`,"┌":`┼`,"┐":`┤`,"└":`┴`,"├":`┼`,"┤":`┤`,"┬":`┼`,"┴":`┴`},"├":{"─":`┼`,"│":`├`,"┌":`├`,"┐":`┼`,"└":`├`,"┘":`┼`,"┤":`┼`,"┬":`┼`,"┴":`┼`},"┤":{"─":`┼`,"│":`┤`,"┌":`┼`,"┐":`┤`,"└":`┼`,"┘":`┤`,"├":`┼`,"┬":`┼`,"┴":`┼`},"┬":{"─":`┬`,"│":`┼`,"┌":`┬`,"┐":`┬`,"└":`┼`,"┘":`┼`,"├":`┼`,"┤":`┼`,"┴":`┼`},"┴":{"─":`┴`,"│":`┼`,"┌":`┼`,"┐":`┼`,"└":`┴`,"┘":`┴`,"├":`┼`,"┤":`┼`,"┬":`┼`}};function fe(e,t){return de[e]?.[t]??e}function pe(e){let t=new Map,n=[];for(let r of e){let[e,i]=L(r),a=P(r);for(let n=0;n<=e;n++)for(let e=0;e<=i;e++){let i=r[n]?.[e];if(i===void 0||i===` `)continue;let o=`${n},${e}`,s=t.get(o);if(s!==void 0){if(!(s!==i&&le(s)&&le(i)))continue}else t.set(o,i);a[n][e]=i}n.push(a)}return n}function z(e,t,n,...r){let[i,a]=L(e);for(let e of r){let[n,r]=L(e);i=Math.max(i,n+t.x),a=Math.max(a,r+t.y)}let o=N(i,a);for(let t=0;t<=i;t++)for(let n=0;n<=a;n++)t<e.length&&n<(e[0]?.length??0)&&(o[t][n]=e[t][n]);for(let e of r)for(let r=0;r<e.length;r++)for(let i=0;i<(e[0]?.length??0);i++){let a=e[r][i];if(a!==` `){let e=r+t.x,s=i+t.y,c=o[e][s];!n&&le(a)&&le(c)?o[e][s]=fe(c,a):ue(c)&&ue(a)||(o[e][s]=a)}}return o}function me(e,t){let[n,r]=L(e),i=[],a=t?.roleCanvas,o=t?.colorMode??`none`,s=t?.theme??m,c=o===`html`?void 0:t?.linkCanvas;for(let t=0;t<=r;t++)if(o===`none`||!a){let r=[];for(let i=0;i<=n;i++)r.push(e[i][t]);if(c){let e=r.map((e,n)=>c[n]?.[t]??null);i.push(p(r,e))}else i.push(r.join(``))}else{let r=[],l=[],u=[];for(let i=0;i<=n;i++)r.push(e[i][t]),l.push(a[i]?.[t]??null),u.push(c?.[i]?.[t]??null);i.push(O(r,l,s,o,c?u:void 0))}return i.join(`
2
- `)}var he={"▲":`▼`,"▼":`▲`,"↖":`↙`,"↙":`↖`,"↗":`↘`,"↘":`↗`,"^":`v`,v:`^`,"┌":`└`,"└":`┌`,"┐":`┘`,"┘":`┐`,"┬":`┴`,"┴":`┬`,"╵":`╷`,"╷":`╵`};function ge(e){for(let t of e)t.reverse();for(let t of e)for(let[e,n]of t.entries()){let r=he[n];r&&(t[e]=r)}return e}function B(e){for(let t of e)t.reverse();return e}function _e(e,t,n,r=!1){let i=ae(n);se(e,t.x+i.length,t.y);for(let[n,a]of i.entries()){let i=t.x+n,o=e[i][t.y];(r||o===` `)&&(e[i][t.y]=a)}}function ve(e,t,n,r=0,i=0){let a=r,o=i;for(let e of t.values())a+=e;for(let e of n.values())o+=e;se(e,a-1,o-1)}function ye(e,t,n,r=0,i=0){let a=r,o=i;for(let e of t.values())a+=e;for(let e of n.values())o+=e;oe(e,a-1,o-1)}var be=60,xe=20,Se={hLine:`─`,vLine:`│`,origin:`┼`,yTick:`┤`,xTick:`┬`,bar:`█`,grid:`·`,cornerTL:`╭`,cornerTR:`╮`,cornerBL:`╰`,cornerBR:`╯`},Ce={hLine:`-`,vLine:`|`,origin:`+`,yTick:`+`,xTick:`+`,bar:`#`,grid:`.`,cornerTL:`+`,cornerTR:`+`,cornerBL:`+`,cornerBR:`+`};function we(e,n){let r=n.accent??t.CHART_ACCENT_FALLBACK;return e<=1?[r]:Array.from({length:e},(e,i)=>(0,t.getSeriesColor)(i,r,n.bg))}function Te(e,t){switch(e){case`text`:return t.fg;case`border`:return t.border;case`line`:return t.line;case`arrow`:return t.arrow;case`corner`:return t.corner??t.line;case`junction`:return t.junction??t.border;default:return t.fg}}function Ee(n,r,i,a){let o=(0,e.splitStatements)(n),s=(0,t.parseXYChart)(o),c=r.useAscii?Ce:Se;return s.horizontal?De(s,c,i,a):V(s,c,i,a)}function V(e,t,n,r){let i=Fe(e);if(i===0)return``;let a=e.yAxis.range;if(!a)throw Error(`XY chart: y-axis range was not set by the parser`);let o=Le(a.min,a.max),s=o.map(e=>Re(e)),c=Math.max(...s.map(e=>e.length))+1,l=Math.max(be,i*6),u=xe,d=Math.floor(l/i),f=Ie(e,i),p=!!e.title,m=!!e.xAxis.title,h=!!e.yAxis.title,g=e.series.length>1,_=p?0:-1,v=(p?2:0)+ +!!g,y=h?2:0,b=y+c+1,x=b+d*i+2,S=v+u,C=S+1,w=m?C+1:-1,T=C+1+ +!!m+0,E=je(x,T),D=H(x,T),O=Me(x,T),ee=we(e.series.length,r),k=e=>{let t=(e-a.min)/(a.max-a.min||1);return Math.round(t*19)},te=e=>b+Math.floor(d*(e+.5));e.title&&_>=0&&G(E,D,_,Math.floor(x/2-e.title.length/2),e.title,`text`),g&&Ae(E,D,O,e,+!!p,x,t,ee);for(let e=0;e<u;e++)U(E,D,v+(19-e),b-1,t.vLine,`border`);U(E,D,S,b-1,t.origin,`border`);for(let e of o){let n=k(e);if(n<0||n>=u)continue;let r=v+(19-n),i=Re(e);U(E,D,r,b-1,n===0?t.origin:t.yTick,`border`);let a=y+c-i.length;G(E,D,r,Math.max(0,a),i,`text`)}for(let e=b;e<b+d*i;e++)U(E,D,S,e,t.hLine,`border`);for(let e=0;e<i;e++){let n=te(e);U(E,D,S,n,t.xTick,`border`);let r=f[e],i=n-Math.floor(r.length/2);G(E,D,C,Math.max(0,i),r,`text`)}if(e.xAxis.title&&w>=0){let t=e.xAxis.title;G(E,D,w,Math.floor(x/2-t.length/2),t,`text`)}if(e.yAxis.title){let t=e.yAxis.title,n=v+Math.max(0,Math.floor((u-t.length)/2));for(let e=0;e<t.length;e++){let r=n+e;if(r>=v+u)break;U(E,D,r,0,t[e],`text`)}}for(let e of o){let n=k(e);if(n<0||n>=u)continue;let r=v+(19-n);for(let e=b;e<b+d*i;e++)W(E,r,e)===` `&&U(E,D,r,e,t.grid,`line`)}let ne=[];for(let t=0;t<e.series.length;t++)e.series[t].type===`bar`&&ne.push({data:e.series[t].data,globalIdx:t});if(ne.length>0){let e=Math.max(1,d-2),n=Math.max(1,Math.min(e,8)),r=k(Math.max(0,a.min));for(let e=0;e<ne.length;e++){let i=ne[e],a=ee[i.globalIdx];for(let e=0;e<i.data.length;e++){let o=te(e)-Math.floor(n/2),s=k(i.data[e]),c=Math.min(r,s),l=Math.max(r,s);for(let e=c;e<=l;e++){let r=v+(19-e);for(let e=o;e<o+n;e++)U(E,D,r,e,t.bar,`arrow`,O,a)}}}}let A=[];for(let t=0;t<e.series.length;t++)e.series[t].type===`line`&&A.push({data:e.series[t].data,globalIdx:t});for(let e of A){if(e.data.length===0)continue;let n=ee[e.globalIdx];Oe(E,D,e.data,te,k,v,u,b,d*i,t,O,n)}return Ne(E,D,O,n,r)}function De(e,t,n,r){let i=Fe(e);if(i===0)return``;let a=e.yAxis.range;if(!a)throw Error(`XY chart: y-axis range was not set by the parser`);let o=Le(a.min,a.max),s=Ie(e,i),c=Math.max(...s.map(e=>e.length))+1,l=Math.max(be,40),u=Math.max(2,Math.floor(xe/i)),d=u*i,f=!!e.title,p=!!e.yAxis.title,m=e.series.length>1,h=(f?2:0)+ +!!m,g=c+1,_=g+l+2,v=h+d+2+ +!!p,y=h+d,b=je(_,v),x=H(_,v),S=Me(_,v),C=we(e.series.length,r),w=e=>{let t=(e-a.min)/(a.max-a.min||1);return g+Math.round(t*59)},T=e=>h+Math.floor(u*(e+.5));e.title&&G(b,x,0,Math.floor(_/2-e.title.length/2),e.title,`text`),m&&Ae(b,x,S,e,+!!f,_,t,C);for(let e=h;e<h+d;e++)U(b,x,e,g-1,t.vLine,`border`);U(b,x,y,g-1,t.origin,`border`);for(let e=0;e<i;e++){let t=T(e),n=s[e],r=c-n.length;G(b,x,t,Math.max(0,r),n,`text`)}for(let e=g;e<g+l;e++)U(b,x,y,e,t.hLine,`border`);for(let e of o){let n=w(e);if(n<g||n>=g+l)continue;U(b,x,y,n,t.xTick,`border`);let r=Re(e);G(b,x,y+1,n-Math.floor(r.length/2),r,`text`)}if(e.yAxis.title){let t=e.yAxis.title;G(b,x,v-1,Math.floor(_/2-t.length/2),t,`text`)}for(let e of o){let n=w(e);if(!(n<g||n>=g+l))for(let e=h;e<h+d;e++)W(b,e,n)===` `&&U(b,x,e,n,t.grid,`line`)}let E=[];for(let t=0;t<e.series.length;t++)e.series[t].type===`bar`&&E.push({data:e.series[t].data,globalIdx:t});if(E.length>0){let e=w(Math.max(0,a.min));for(let n=0;n<E.length;n++){let r=E[n],i=C[r.globalIdx];for(let n=0;n<r.data.length;n++){let a=T(n),o=w(r.data[n]),s=Math.min(e,o),c=Math.max(e,o);for(let e=a;e<a+1;e++)for(let n=s;n<=c;n++)U(b,x,e,n,t.bar,`arrow`,S,i)}}}let D=[];for(let t=0;t<e.series.length;t++)e.series[t].type===`line`&&D.push({data:e.series[t].data,globalIdx:t});for(let e of D){if(e.data.length===0)continue;let n=C[e.globalIdx];ke(b,x,e.data,T,w,h,d,g,l,t,S,n)}return Ne(b,x,S,n,r)}function Oe(e,t,n,r,i,a,o,s,c,l,u,d){if(n.length===0)return;let f=n.map((e,t)=>({col:r(t),row:i(e)})),p=(n,r,i)=>{let l=a+(o-1-r);l>=0&&n>=s&&n<s+c&&U(e,t,l,n,i,`arrow`,u,d)};if(f.length===1){p(f[0].col,f[0].row,l.hLine);return}for(let e=0;e<f.length-1;e++){let t=f[e],n=f[e+1];if(t.row===n.row){for(let e=t.col;e<=n.col;e++)p(e,t.row,l.hLine);continue}let r=Math.round((t.col+n.col)/2),i=n.row>t.row;for(let e=t.col;e<r;e++)p(e,t.row,l.hLine);i?p(r,t.row,l.cornerBR):p(r,t.row,l.cornerTR);let a=Math.min(t.row,n.row),o=Math.max(t.row,n.row);for(let e=a+1;e<o;e++)p(r,e,l.vLine);i?p(r,n.row,l.cornerTL):p(r,n.row,l.cornerBL);for(let e=r+1;e<=n.col;e++)p(e,n.row,l.hLine);if(e===0){let e=Math.max(s,t.col-Math.floor((n.col-t.col)/4));for(let n=e;n<t.col;n++)p(n,t.row,l.hLine)}if(e===f.length-2){let e=Math.min(s+c-1,n.col+Math.floor((n.col-t.col)/4));for(let t=n.col+1;t<=e;t++)p(t,n.row,l.hLine)}}}function ke(e,t,n,r,i,a,o,s,c,l,u,d){if(n.length===0)return;let f=n.map((e,t)=>({row:r(t),col:i(e)})),p=(n,r,i)=>{n>=a&&n<a+o&&r>=s&&r<s+c&&U(e,t,n,r,i,`arrow`,u,d)};if(f.length===1){p(f[0].row,f[0].col,l.vLine);return}for(let e=0;e<f.length-1;e++){let t=f[e],n=f[e+1];if(t.col===n.col){for(let e=t.row;e<=n.row;e++)p(e,t.col,l.vLine);continue}let r=Math.round((t.row+n.row)/2),i=n.col>t.col;for(let e=t.row;e<r;e++)p(e,t.col,l.vLine);i?p(r,t.col,l.cornerBL):p(r,t.col,l.cornerBR);let a=Math.min(t.col,n.col),o=Math.max(t.col,n.col);for(let e=a+1;e<o;e++)p(r,e,l.hLine);i?p(r,n.col,l.cornerTR):p(r,n.col,l.cornerTL);for(let e=r+1;e<=n.row;e++)p(e,n.col,l.vLine)}}function Ae(e,t,n,r,i,a,o,s){let c=[],l=0,u=0;for(let e=0;e<r.series.length;e++)r.series[e].type===`bar`?(c.push({symbol:o.bar,label:`Bar ${l+1}`,globalIdx:e}),l++):(c.push({symbol:o.hLine,label:`Line ${u+1}`,globalIdx:e}),u++);let d=0;for(let e=0;e<c.length;e++)e>0&&(d+=2),d+=2+c[e].label.length;let f=Math.max(0,Math.floor(a/2-d/2));for(let r=0;r<c.length;r++){r>0&&(f+=2);let a=c[r];U(e,t,i,f,a.symbol,`arrow`,n,s[a.globalIdx]),f+=1,f+=1,G(e,t,i,f,a.label,`text`),f+=a.label.length}}function je(e,t){return N(e-1,t-1)}function H(e,t){return F(e-1,t-1)}function Me(e,t){return Array.from({length:e},()=>Array.from({length:t}).fill(null))}function U(e,t,n,r,i,a,o,s){r>=0&&r<e.length&&n>=0&&n<(e[0]?.length??0)&&(R(e,r,n,i,{role:a,roleCanvas:t}),o&&s&&(o[r][n]=s))}function W(e,t,n){return n>=0&&n<e.length&&t>=0&&t<e[0].length?e[n][t]:` `}function G(e,t,n,r,i,a){for(let o=0;o<i.length;o++)U(e,t,n,r+o,i[o],a)}function Ne(e,t,n,r,i){if(e.length===0)return``;let a=e[0].length,o=e.length,s=[];for(let c=0;c<a;c++){let a=[],l=[],u=[];for(let r=0;r<o;r++)a.push(e[r][c]),l.push(t[r][c]),u.push(n[r][c]);let d=a.length-1;for(;d>=0&&a[d]===` `;)d--;d<0?s.push(``):s.push(Pe(a.slice(0,d+1),l.slice(0,d+1),u.slice(0,d+1),i,r))}for(;s.length>0&&s[s.length-1]===``;)s.pop();return s.join(`
3
- `)}function Pe(e,t,n,r,i){if(i===`none`)return e.join(``);let a=``,o=null,s=``;for(let c=0;c<e.length;c++){let l=e[c];if(l===` `){s.length>0&&(a+=o?k(s,o,i):s,s=``,o=null),a+=` `;continue}let u=n[c]??null,d=t[c]??null,f=u??(d?Te(d,r):null);f===o?s+=l:(s.length>0&&(a+=o?k(s,o,i):s),s=l,o=f)}return s.length>0&&(a+=o?k(s,o,i):s),a}function Fe(e){if(e.xAxis.categories)return e.xAxis.categories.length;for(let t of e.series)if(t.data.length>0)return t.data.length;return 0}function Ie(e,t){if(e.xAxis.categories)return e.xAxis.categories;if(e.xAxis.range){let{min:n,max:r}=e.xAxis.range,i=t>1?(r-n)/(t-1):0;return Array.from({length:t},(e,t)=>Re(n+i*t))}return Array.from({length:t},(e,t)=>String(t+1))}function Le(e,t){let n=t-e;if(n<=0)return[e];let r=n/6,i=10**Math.floor(Math.log10(r)),a=r/i,o;o=a<=1.5?i:a<=3?2*i:a<=7?5*i:10*i;let s=Math.ceil(e/o)*o,c=[];for(let e=s;e<=t+o*.001;e+=o)c.push(Math.round(e*1e10)/1e10);return c}function Re(e){return Number.isInteger(e)?String(e):e.toFixed(+(Math.abs(e)<10))}var K={x:1,y:0},q={x:1,y:2},J={x:0,y:1},Y={x:2,y:1},ze={x:2,y:0},Be={x:0,y:0},Ve={x:2,y:2},He={x:0,y:2},Ue={x:1,y:1};function X(e,t){return e.x===t.x&&e.y===t.y}function We(e){return X(e,K)||X(e,q)||X(e,J)||X(e,Y)}function Ge(e){if(!We(e))throw Error(`Expected a cardinal direction (Up/Down/Left/Right); got {x:${e.x}, y:${e.y}}`);return e}function Ke(e,t,n,r){return Math.max(r,n+(e-t))}function qe(e,t){return e.x===t.x&&e.y===t.y}function Je(e,t){return e.x===t.x&&e.y===t.y}function Ye(e,t){return{x:e.x+t.x,y:e.y+t.y}}function Xe(e){return`${e.x},${e.y}`}function Z(e){let t=e.gridCoord;if(t===null)throw Error(`Node "${e.name}" has no gridCoord; grid layout must run before it is read`);return t}var Ze={name:``,styles:{}},Qe=class{#e=new Set;has(e){return this.#e.has(e)}add(e){this.#e.add(e)}delete(e){this.#e.delete(e)}keys(){return this.#e.keys()}};function $e(){return new Qe}function et(e){let t=$e();for(let n of e.keys())t.add(n);return t}function tt(e,t){return e.has(Xe(t))}function nt(e,t){return t.x<0||t.y<0?!1:!tt(e,t)}function rt(e,t,n=3){for(let r=0;r<n;r++)for(let i=0;i<n;i++)if(tt(e,{x:t.x+r,y:t.y+i}))return!1;return!0}function it(e,t,n=3){if(!rt(e,t,n))throw Error(`Grid block at (${t.x},${t.y}) is already occupied`);for(let r=0;r<n;r++)for(let i=0;i<n;i++){let n={x:t.x+r,y:t.y+i};e.add(Xe(n))}}var at=1e5;function ot(e){if(e.length===0)return[];let t=[e[0]];for(let n=1;n<e.length;n++){let r=e[n-1],i=e[n],a=r.x,o=r.y,s=Math.abs(i.x-r.x),c=Math.abs(i.y-r.y),l=r.x<i.x?1:-1,u=r.y<i.y?1:-1,d=s-c,f=0;for(;a!==i.x||o!==i.y;){if(f>=at)throw Error(`pathCells: segment from (${r.x},${r.y}) to (${i.x},${i.y}) did not reach its endpoint within ${at} steps`);let e=2*d;e>-c&&(d-=c,a+=l),e<s&&(d+=s,o+=u),t.push({x:a,y:o}),f++}}return t}var st=class{items=[];get length(){return this.items.length}push(e){this.items.push(e),this.bubbleUp(this.items.length-1)}pop(){if(this.items.length===0)return;let e=this.items[0],t=this.items.pop();return this.items.length>0&&(this.items[0]=t,this.sinkDown(0)),e}bubbleUp(e){let t=e;for(;t>0;){let e=t-1>>1;if(this.items[t].priority<this.items[e].priority)[this.items[t],this.items[e]]=[this.items[e],this.items[t]],t=e;else break}}sinkDown(e){let t=this.items.length,n=e;for(;;){let e=n,r=2*n+1,i=2*n+2;if(r<t&&this.items[r].priority<this.items[e].priority&&(e=r),i<t&&this.items[i].priority<this.items[e].priority&&(e=i),e!==n)[this.items[n],this.items[e]]=[this.items[e],this.items[n]],n=e;else break}}};function ct(e,t){let n=Math.abs(e.x-t.x),r=Math.abs(e.y-t.y);return n===0||r===0?n+r:n+r+1}var lt=[{x:1,y:0},{x:-1,y:0},{x:0,y:1},{x:0,y:-1}],ut=5e4,dt=2e5;function ft(e=dt){return{remaining:e}}function pt(e,t,n,r){if(r&&r.remaining<=0)return null;let i=new st;i.push({coord:t,priority:0});let a=new Map;a.set(Xe(t),0);let o=new Map;o.set(Xe(t),null);let s=0;for(;i.length>0;){if(++s>ut)return null;if(r){if(r.remaining<=0)return null;r.remaining--}let t=i.pop().coord;if(qe(t,n)){let e=[],n=t;for(;n!==null;)e.unshift(n),n=o.get(Xe(n))??null;return e}let c=a.get(Xe(t));if(c===void 0)throw Error(`A* pathfinding: missing cost for visited cell ${Xe(t)}`);for(let r of lt){let s={x:t.x+r.x,y:t.y+r.y};if(!nt(e,s)&&!qe(s,n))continue;let l=c+1,u=Xe(s),d=a.get(u);if(d===void 0||l<d){a.set(u,l);let e=l+ct(s,n);i.push({coord:s,priority:e}),o.set(u,t)}}}return null}function mt(e){if(e.length<=2)return e;let t=new Set,n=e[0],r=e[1];for(let i=2;i<e.length;i++){let a=e[i],o=r.x-n.x,s=r.y-n.y,c=a.x-r.x,l=a.y-r.y;o===c&&s===l&&t.add(i-1),n=r,r=a}return e.filter((e,n)=>!t.has(n))}function ht(e,t,n,r){if(t.x===n.x&&t.y===n.y)return!0;let i=t.x===n.x;if(!i&&t.y!==n.y)return!1;let a=i?n.y>t.y?1:-1:n.x>t.x?1:-1,o=i?t.y:t.x,s=i?n.y:n.x;for(o+=a;;o+=a){let n=o===s,a=i?{x:t.x,y:o}:{x:o,y:t.y};if(!(n&&!r)&&!nt(e,a))return!1;if(n)break}return!0}function gt(e,t,n,r){let i=r?{x:n.x,y:t.y}:{x:t.x,y:n.y};return!ht(e,t,i,!0)||!ht(e,i,n,!1)?null:[t,i,n]}function _t(e,t,n,r){if(t.x===n.x||t.y===n.y)return null;let i=X(r,J)||X(r,Y);return gt(e.grid,t,n,i)??gt(e.grid,t,n,!i)}function vt(e,t,n,r){if(!e.pathBudget)throw Error(`routeEdge requires graph.pathBudget to be set; call createPathBudget() (see grid.ts createMapping) before routing edges`);let i=_t(e,t,n,r)??pt(e.grid,t,n,e.pathBudget);return i?mt(i):null}function yt(e){if(e.config.graphDirection!==`TD`)return[];let t=[],n=new Set,r=new Map;for(let t of e.edges){if(t.from===t.to)continue;let e=r.get(t.to)??[];e.push(t),r.set(t.to,e)}for(let[i,a]of r){if(a.length<2||!bt(a,e)||a.some(e=>n.has(e)))continue;let r={type:`fan-in`,edges:[...a],sharedNode:i,otherNodes:a.map(e=>e.from),junctionPoint:null,sharedPath:[],junctionDir:Ue,sharedNodeDir:Ue};for(let e of a)e.bundle=r,n.add(e);t.push(r)}let i=new Map;for(let t of e.edges){if(t.from===t.to||n.has(t))continue;let e=i.get(t.from)??[];e.push(t),i.set(t.from,e)}for(let[r,a]of i){if(a.length<2||!bt(a,e))continue;let i={type:`fan-out`,edges:[...a],sharedNode:r,otherNodes:a.map(e=>e.to),junctionPoint:null,sharedPath:[],junctionDir:Ue,sharedNodeDir:Ue};for(let e of a)e.bundle=i,n.add(e);t.push(i)}return t}function bt(e,t){if(e.length<2)return!1;let n=e[0].style,r=Qt(t,e[0].from),i=Qt(t,e[0].to);for(let a of e){if(a.style!==n||a.text.length>0)return!1;let e=Qt(t,a.from),o=Qt(t,a.to);if(e!==r||o!==i||e!==o)return!1}let a=e.every(t=>t.to===e[0].to),o=a?e.map(e=>e.from):e.map(e=>e.to);if(new Set(o).size!==o.length||e.some(e=>e.parallelLane))return!1;let s=t.config.graphDirection===`LR`?`x`:`y`,c=(a?e[0].to:e[0].from).gridCoord;if(!c)return!1;for(let t of e){let e=(a?t.from:t.to).gridCoord;if(!e)return!1;if(a){if(e[s]>=c[s])return!1}else if(e[s]<=c[s])return!1}return!0}function xt(e,t){let n=e.config.graphDirection,r=Z(t.sharedNode);if(t.type===`fan-in`){if(n===`TD`){let e=r.y-1;return{x:r.x+1,y:e}}return{x:r.x-1,y:r.y+1}}if(n===`TD`){let e=r.y+3;return{x:r.x+1,y:e}}return{x:r.x+3,y:r.y+1}}function St(e,t){let n=e.config.graphDirection;t.junctionPoint=xt(e,t);let r=t.junctionPoint;if(t.type===`fan-in`){t.junctionDir=n===`TD`?K:J,t.sharedNodeDir=n===`TD`?q:Y;let i=Z(t.sharedNode),a=Ge(n===`TD`?K:J),o=Ye(i,a);t.sharedPath=vt(e,r,o,a)??[r,o];for(let i of t.edges){let o=Z(i.from),s=Ge(n===`TD`?q:Y),c=Ye(o,s);i.pathToJunction=vt(e,c,r,s)??[c,r],i.startDir=s,i.endDir=a,i.path=[...i.pathToJunction,...t.sharedPath.slice(1)]}}else{t.junctionDir=n===`TD`?q:Y,t.sharedNodeDir=n===`TD`?K:J;let i=Z(t.sharedNode),a=Ge(n===`TD`?q:Y),o=Ye(i,a);t.sharedPath=vt(e,o,r,a)??[o,r];for(let i of t.edges){let o=Z(i.to),s=Ge(n===`TD`?K:J),c=Ye(o,s);i.pathToJunction=vt(e,r,c,s)??[r,c],i.startDir=a,i.endDir=s,i.path=[...t.sharedPath,...i.pathToJunction.slice(1)]}}}function Ct(e){for(let t of e.bundles)St(e,t)}function wt(){return new Map}function Tt(e,t,n,r){for(let i of ot(n)){if(tt(e,i))continue;let n=t.get(Xe(i));if(n!==void 0&&n!==r)return i}return null}function Et(e,t,n,r){for(let i of ot(n)){if(tt(e,i))continue;let n=Xe(i);t.has(n)||t.set(n,r)}}function Dt(){return new Map}function Ot(e,t){return e.to===t.from||t.to===e.from}var kt=2;function At(e,t,n,r){let i=new Map,a=new Map;for(let o of ot(n)){if(tt(e,o))continue;let n=t.get(Xe(o));if(n!==void 0)for(let e of n)e!==r&&Ot(e,r)&&(i.set(e,(i.get(e)??0)+1),a.has(e)||a.set(e,o))}for(let[e,t]of i)if(t>=kt)return a.get(e);return null}function jt(e,t,n,r){for(let i of ot(n)){if(tt(e,i))continue;let n=Xe(i),a=t.get(n);a===void 0&&(a=new Set,t.set(n,a)),a.add(r)}}function Q(e){return e.split(`
4
- `)}function Mt(e){let t=Q(e);return Math.max(...t.map(e=>M(e)),0)}function Nt(e){return Q(e).length}var Pt={rectangle:{unicode:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`},ascii:{tl:`+`,tr:`+`,bl:`+`,br:`+`}},rounded:{unicode:{tl:`╭`,tr:`╮`,bl:`╰`,br:`╯`},ascii:{tl:`.`,tr:`.`,bl:`'`,br:`'`}},circle:{unicode:{tl:`◯`,tr:`◯`,bl:`◯`,br:`◯`},ascii:{tl:`o`,tr:`o`,bl:`o`,br:`o`}},doublecircle:{unicode:{tl:`◎`,tr:`◎`,bl:`◎`,br:`◎`},ascii:{tl:`@`,tr:`@`,bl:`@`,br:`@`}},diamond:{unicode:{tl:`◇`,tr:`◇`,bl:`◇`,br:`◇`},ascii:{tl:`<`,tr:`>`,bl:`<`,br:`>`}},hexagon:{unicode:{tl:`⌜`,tr:`⌝`,bl:`⌞`,br:`⌟`},ascii:{tl:`*`,tr:`*`,bl:`*`,br:`*`}},stadium:{unicode:{tl:`(`,tr:`)`,bl:`(`,br:`)`},ascii:{tl:`(`,tr:`)`,bl:`(`,br:`)`}},subroutine:{unicode:{tl:`╟`,tr:`╢`,bl:`╟`,br:`╢`},ascii:{tl:`|`,tr:`|`,bl:`|`,br:`|`}},cylinder:{unicode:{tl:`╭`,tr:`╮`,bl:`╰`,br:`╯`},ascii:{tl:`.`,tr:`.`,bl:`'`,br:`'`}},asymmetric:{unicode:{tl:`▷`,tr:`┐`,bl:`▷`,br:`┘`},ascii:{tl:`>`,tr:`+`,bl:`>`,br:`+`}},trapezoid:{unicode:{tl:`/`,tr:`\\`,bl:`└`,br:`┘`},ascii:{tl:`/`,tr:`\\`,bl:`+`,br:`+`}},"trapezoid-alt":{unicode:{tl:`┌`,tr:`┐`,bl:`\\`,br:`/`},ascii:{tl:`+`,tr:`+`,bl:`\\`,br:`/`}},parallelogram:{unicode:{tl:`/`,tr:`/`,bl:`/`,br:`/`},ascii:{tl:`/`,tr:`/`,bl:`/`,br:`/`}},"parallelogram-alt":{unicode:{tl:`\\`,tr:`\\`,bl:`\\`,br:`\\`},ascii:{tl:`\\`,tr:`\\`,bl:`\\`,br:`\\`}},"state-start":{unicode:{tl:`●`,tr:`●`,bl:`●`,br:`●`},ascii:{tl:`*`,tr:`*`,bl:`*`,br:`*`}},"state-end":{unicode:{tl:`◉`,tr:`◉`,bl:`◉`,br:`◉`},ascii:{tl:`@`,tr:`@`,bl:`@`,br:`@`}},document:{unicode:{tl:`┌`,tr:`┐`,bl:`╰`,br:`╮`},ascii:{tl:`+`,tr:`+`,bl:`'`,br:`~`}},"stacked-document":{unicode:{tl:`┌`,tr:`╗`,bl:`╰`,br:`╮`},ascii:{tl:`+`,tr:`#`,bl:`'`,br:`~`}},"stacked-process":{unicode:{tl:`┌`,tr:`╗`,bl:`└`,br:`╝`},ascii:{tl:`+`,tr:`#`,bl:`+`,br:`#`}},card:{unicode:{tl:`╱`,tr:`┐`,bl:`└`,br:`┘`},ascii:{tl:`/`,tr:`+`,bl:`+`,br:`+`}},"lined-process":{unicode:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`},ascii:{tl:`+`,tr:`+`,bl:`+`,br:`+`}},"divided-process":{unicode:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`},ascii:{tl:`+`,tr:`+`,bl:`+`,br:`+`}},"window-pane":{unicode:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`},ascii:{tl:`+`,tr:`+`,bl:`+`,br:`+`}},triangle:{unicode:{tl:`╱`,tr:`╲`,bl:`└`,br:`┘`},ascii:{tl:`/`,tr:`\\`,bl:`+`,br:`+`}},"flipped-triangle":{unicode:{tl:`┌`,tr:`┐`,bl:`╲`,br:`╱`},ascii:{tl:`+`,tr:`+`,bl:`\\`,br:`/`}},"filled-circle":{unicode:{tl:`●`,tr:`●`,bl:`●`,br:`●`},ascii:{tl:`*`,tr:`*`,bl:`*`,br:`*`}},"crossed-circle":{unicode:{tl:`╳`,tr:`╳`,bl:`╳`,br:`╳`},ascii:{tl:`X`,tr:`X`,bl:`X`,br:`X`}},"fork-join":{unicode:{tl:`━`,tr:`━`,bl:`━`,br:`━`},ascii:{tl:`=`,tr:`=`,bl:`=`,br:`=`}},"notched-pentagon":{unicode:{tl:`╱`,tr:`╲`,bl:`└`,br:`┘`},ascii:{tl:`/`,tr:`\\`,bl:`+`,br:`+`}},"sloped-rectangle":{unicode:{tl:`╱`,tr:`┐`,bl:`└`,br:`┘`},ascii:{tl:`/`,tr:`+`,bl:`+`,br:`+`}},flag:{unicode:{tl:`╭`,tr:`╮`,bl:`╰`,br:`╯`},ascii:{tl:`~`,tr:`~`,bl:`~`,br:`~`}},"bow-tie-rectangle":{unicode:{tl:`╲`,tr:`╱`,bl:`╱`,br:`╲`},ascii:{tl:`\\`,tr:`/`,bl:`/`,br:`\\`}},"half-rounded-rectangle":{unicode:{tl:`┌`,tr:`╮`,bl:`└`,br:`╯`},ascii:{tl:`+`,tr:`.`,bl:`+`,br:`'`}},brace:{unicode:{tl:`╭`,tr:`┐`,bl:`╰`,br:`┘`},ascii:{tl:`{`,tr:`+`,bl:`{`,br:`+`}},"brace-right":{unicode:{tl:`┌`,tr:`╮`,bl:`└`,br:`╯`},ascii:{tl:`+`,tr:`}`,bl:`+`,br:`}`}},braces:{unicode:{tl:`╭`,tr:`╮`,bl:`╰`,br:`╯`},ascii:{tl:`{`,tr:`}`,bl:`{`,br:`}`}},bolt:{unicode:{tl:`╱`,tr:`╲`,bl:`╲`,br:`╱`},ascii:{tl:`/`,tr:`\\`,bl:`\\`,br:`/`}},text:{unicode:{tl:` `,tr:` `,bl:` `,br:` `},ascii:{tl:` `,tr:` `,bl:` `,br:` `}},anchor:{unicode:{tl:` `,tr:` `,bl:` `,br:` `},ascii:{tl:` `,tr:` `,bl:` `,br:` `}}};function Ft(e,t){let n=Pt[e]??Pt.rectangle;return t?n.ascii:n.unicode}function It(e,t){let n=Q(e),r=Math.max(...n.map(e=>M(e)),0),i=n.length,a=2*t.padding+r,o=a+2,s=i+2*t.padding,c=s%2==0?s+1:s;return{width:o,height:c+2,labelArea:{x:1+t.padding,y:1+t.padding,width:r,height:i},gridColumns:[1,a,1],gridRows:[1,c,1]}}function Lt(e,t,n,r){let{width:i,height:a}=t,o=N(i-1,a-1),s={x:0,y:0},c={x:i-1,y:a-1},l=r?`-`:`─`,u=r?`|`:`│`;for(let e=s.x+1;e<c.x;e++)o[e][s.y]=l,o[e][c.y]=l;for(let e=s.y+1;e<c.y;e++)o[s.x][e]=u,o[c.x][e]=u;o[s.x][s.y]=n.tl,o[c.x][s.y]=n.tr,o[s.x][c.y]=n.bl,o[c.x][c.y]=n.br;let d=Q(e),f=i-1,p=a-1,m=Math.floor(p/2)-Math.floor((d.length-1)/2);for(let e=0;e<d.length;e++){let t=d[e],n=Math.floor(f/2)-Math.ceil(M(t)/2)+1,r=ae(t);for(let t=0;t<r.length;t++){let i=n+t,a=m+e;i>=0&&i<o.length&&a>=0&&a<o[0].length&&(o[i][a]=r[t])}}return o}function Rt(e,t,n){let{width:r,height:i}=t,a=n.x+Math.floor(r/2),o=n.y+Math.floor(i/2);return X(e,K)?{x:a,y:n.y}:X(e,q)?{x:a,y:n.y+i-1}:X(e,J)?{x:n.x,y:o}:X(e,Y)?{x:n.x+r-1,y:o}:X(e,Be)?{x:n.x,y:n.y}:X(e,ze)?{x:n.x+r-1,y:n.y}:X(e,He)?{x:n.x,y:n.y+i-1}:X(e,Ve)?{x:n.x+r-1,y:n.y+i-1}:{x:a,y:o}}var zt={getDimensions:It,render(e,t,n){return Lt(e,t,Ft(`rectangle`,n.useAscii),n.useAscii)},getAttachmentPoint:Rt},Bt=new Map([[`rectangle`,zt],[`rounded`,{getDimensions:It,render(e,t,n){return Lt(e,t,Ft(`rounded`,n.useAscii),n.useAscii)},getAttachmentPoint:Rt}],[`diamond`,{getDimensions:It,render(e,t,n){return Lt(e,t,Ft(`diamond`,n.useAscii),n.useAscii)},getAttachmentPoint:Rt}],[`stadium`,{getDimensions(e,t){let n=Q(e),r=Math.max(...n.map(e=>M(e)),0),i=n.length,a=2*t.padding+r,o=a+4,s=i+2*t.padding;return{width:o,height:Math.max(s+2,3),labelArea:{x:2+t.padding,y:1+t.padding,width:r,height:i},gridColumns:[2,a,2],gridRows:[1,s,1]}},render(e,t,n){let{width:r,height:i}=t,a=N(r-1,i-1),o=Math.floor(i/2),s=n.useAscii?`-`:`─`;if(i===3)a[0][o]=`(`,a[r-1][o]=`)`;else if(n.useAscii){for(let e=0;e<i;e++)a[0][e]=`(`,a[r-1][e]=`)`;for(let e=1;e<r-1;e++)a[e][0]=s,a[e][i-1]=s}else{a[0][0]=`╭`;for(let e=1;e<r-1;e++)a[e][0]=s;a[r-1][0]=`╮`;for(let e=1;e<i-1;e++)a[0][e]=`│`,a[r-1][e]=`│`;a[0][i-1]=`╰`;for(let e=1;e<r-1;e++)a[e][i-1]=s;a[r-1][i-1]=`╯`}let c=Q(e),l=o-Math.floor((c.length-1)/2);for(let e=0;e<c.length;e++){let t=c[e],n=Math.floor(r/2)-Math.floor(M(t)/2),o=ae(t);for(let t=0;t<o.length;t++){let s=n+t,c=l+e;s>0&&s<r-1&&c>=0&&c<i&&(a[s][c]=o[t])}}return a},getAttachmentPoint:Rt}],[`circle`,{getDimensions:It,render(e,t,n){return Lt(e,t,Ft(`circle`,n.useAscii),n.useAscii)},getAttachmentPoint:Rt}],[`subroutine`,{getDimensions(e,t){let n=Q(e),r=Math.max(...n.map(e=>M(e)),0),i=n.length,a=2*t.padding+r,o=a+4,s=i+2*t.padding;return{width:o,height:s+2,labelArea:{x:2+t.padding,y:1+t.padding,width:r,height:i},gridColumns:[2,a,2],gridRows:[1,s,1]}},render(e,t,n){let{width:r,height:i}=t,a=N(r-1,i-1),o=n.useAscii?`-`:`─`,s=n.useAscii?`|`:`│`;a[0][0]=n.useAscii?`+`:`┌`,a[1][0]=n.useAscii?`+`:`┬`;for(let e=2;e<r-2;e++)a[e][0]=o;a[r-2][0]=n.useAscii?`+`:`┬`,a[r-1][0]=n.useAscii?`+`:`┐`;for(let e=1;e<i-1;e++)a[0][e]=s,a[1][e]=s,a[r-2][e]=s,a[r-1][e]=s;a[0][i-1]=n.useAscii?`+`:`└`,a[1][i-1]=n.useAscii?`+`:`┴`;for(let e=2;e<r-2;e++)a[e][i-1]=o;a[r-2][i-1]=n.useAscii?`+`:`┴`,a[r-1][i-1]=n.useAscii?`+`:`┘`;let c=Q(e),l=Math.floor(i/2)-Math.floor((c.length-1)/2);for(let e=0;e<c.length;e++){let t=c[e],n=Math.floor(r/2)-Math.floor(M(t)/2),o=ae(t);for(let t=0;t<o.length;t++){let s=n+t,c=l+e;s>1&&s<r-2&&c>0&&c<i-1&&(a[s][c]=o[t])}}return a},getAttachmentPoint:Rt}],[`doublecircle`,{getDimensions:It,render(e,t,n){return Lt(e,t,Ft(`doublecircle`,n.useAscii),n.useAscii)},getAttachmentPoint:Rt}],[`hexagon`,{getDimensions:It,render(e,t,n){return Lt(e,t,Ft(`hexagon`,n.useAscii),n.useAscii)},getAttachmentPoint:Rt}],[`cylinder`,{getDimensions(e,t){let n=Q(e),r=Math.max(...n.map(e=>M(e)),0),i=n.length,a=2*t.padding+r,o=a+2,s=i+2*t.padding+2;return{width:o,height:s+2,labelArea:{x:1+t.padding,y:2+t.padding,width:r,height:i},gridColumns:[1,a,1],gridRows:[2,s-2,2]}},render(e,t,n){let{width:r,height:i}=t,a=N(r-1,i-1),o=n.useAscii?`-`:`─`,s=n.useAscii?`|`:`│`;a[0][0]=n.useAscii?`.`:`╭`;for(let e=1;e<r-1;e++)a[e][0]=o;a[r-1][0]=n.useAscii?`.`:`╮`,a[0][1]=s;for(let e=1;e<r-1;e++)a[e][1]=o;a[r-1][1]=s;for(let e=2;e<i-2;e++)a[0][e]=s,a[r-1][e]=s;a[0][i-2]=s;for(let e=1;e<r-1;e++)a[e][i-2]=o;a[r-1][i-2]=s,a[0][i-1]=n.useAscii?`'`:`╰`;for(let e=1;e<r-1;e++)a[e][i-1]=o;a[r-1][i-1]=n.useAscii?`'`:`╯`;let c=Q(e),l=Math.floor(i/2)-Math.floor((c.length-1)/2);for(let e=0;e<c.length;e++){let t=c[e],n=Math.floor(r/2)-Math.floor(M(t)/2),o=ae(t);for(let t=0;t<o.length;t++){let s=n+t,c=l+e;s>0&&s<r-1&&c>1&&c<i-2&&(a[s][c]=o[t])}}return a},getAttachmentPoint:Rt}],[`asymmetric`,{getDimensions:It,render(e,t,n){return Lt(e,t,Ft(`asymmetric`,n.useAscii),n.useAscii)},getAttachmentPoint:Rt}],[`trapezoid`,{getDimensions:It,render(e,t,n){return Lt(e,t,Ft(`trapezoid`,n.useAscii),n.useAscii)},getAttachmentPoint:Rt}],[`trapezoid-alt`,{getDimensions:It,render(e,t,n){return Lt(e,t,Ft(`trapezoid-alt`,n.useAscii),n.useAscii)},getAttachmentPoint:Rt}],[`parallelogram`,{getDimensions:It,render(e,t,n){return Lt(e,t,Ft(`parallelogram`,n.useAscii),n.useAscii)},getAttachmentPoint:Rt}],[`parallelogram-alt`,{getDimensions:It,render(e,t,n){return Lt(e,t,Ft(`parallelogram-alt`,n.useAscii),n.useAscii)},getAttachmentPoint:Rt}],[`state-start`,{getDimensions(e,t){return{width:5,height:3,labelArea:{x:2,y:1,width:1,height:1},gridColumns:[1,3,1],gridRows:[1,1,1]}},render(e,t,n){let{width:r,height:i}=t,a=N(r-1,i-1),o=Math.floor(r/2);return n.useAscii?(a[0][0]=`.`,a[1][0]=`-`,a[2][0]=`-`,a[3][0]=`-`,a[4][0]=`.`,a[0][1]=`|`,a[o][1]=`*`,a[4][1]=`|`,a[0][2]=`'`,a[1][2]=`-`,a[2][2]=`-`,a[3][2]=`-`,a[4][2]=`'`):(a[0][0]=`╭`,a[1][0]=`─`,a[2][0]=`─`,a[3][0]=`─`,a[4][0]=`╮`,a[0][1]=`│`,a[o][1]=`●`,a[4][1]=`│`,a[0][2]=`╰`,a[1][2]=`─`,a[2][2]=`─`,a[3][2]=`─`,a[4][2]=`╯`),a},getAttachmentPoint(e,t,n){let{width:r,height:i}=t,a=n.x+Math.floor(r/2),o=n.y+Math.floor(i/2);return X(e,K)?{x:a,y:n.y}:X(e,q)?{x:a,y:n.y+i-1}:X(e,J)?{x:n.x,y:o}:X(e,Y)?{x:n.x+r-1,y:o}:{x:a,y:o}}}],[`state-end`,{getDimensions(e,t){return{width:5,height:3,labelArea:{x:2,y:1,width:1,height:1},gridColumns:[1,3,1],gridRows:[1,1,1]}},render(e,t,n){let{width:r,height:i}=t,a=N(r-1,i-1),o=Math.floor(r/2);return n.useAscii?(a[0][0]=`#`,a[1][0]=`=`,a[2][0]=`=`,a[3][0]=`=`,a[4][0]=`#`,a[0][1]=`#`,a[o][1]=`*`,a[4][1]=`#`,a[0][2]=`#`,a[1][2]=`=`,a[2][2]=`=`,a[3][2]=`=`,a[4][2]=`#`):(a[0][0]=`╔`,a[1][0]=`═`,a[2][0]=`═`,a[3][0]=`═`,a[4][0]=`╗`,a[0][1]=`║`,a[o][1]=`◎`,a[4][1]=`║`,a[0][2]=`╚`,a[1][2]=`═`,a[2][2]=`═`,a[3][2]=`═`,a[4][2]=`╝`),a},getAttachmentPoint(e,t,n){let{width:r,height:i}=t,a=n.x+Math.floor(r/2),o=n.y+Math.floor(i/2);return X(e,K)?{x:a,y:n.y}:X(e,q)?{x:a,y:n.y+i-1}:X(e,J)?{x:n.x,y:o}:X(e,Y)?{x:n.x+r-1,y:o}:{x:a,y:o}}}]]);function Vt(e){return Bt.get(e)??zt}function Ht(e,t,n){return Vt(e).getDimensions(t,n)}function Ut(e,t,n,r){return Vt(e).getAttachmentPoint(t,n,r)}function Wt(e,t,n){let r=n?{x:t.x+n.x,y:t.y+n.y}:t,i=0;for(let t=0;t<r.x;t++)i+=e.columnWidth.get(t)??0;let a=0;for(let t=0;t<r.y;t++)a+=e.rowHeight.get(t)??0;let o=e.columnWidth.get(r.x)??0,s=e.rowHeight.get(r.y)??0;return{x:i+Math.floor(o/2)+e.offsetX,y:a+Math.floor(s/2)+e.offsetY}}function Gt(e,t){return t.map(t=>Wt(e,t))}function Kt(e,t,n,r){let i=r??rn(e,t);return rt(e.grid,n,3)?(it(e.grid,n,3),t.gridCoord=n,n):i===`LR`?Kt(e,t,{x:n.x,y:n.y+4},i):Kt(e,t,{x:n.x+4,y:n.y},i)}function qt(e,t){let n=Z(t),r=e.config.boxBorderPadding,i=Ht(t.shape,t.displayLabel,{useAscii:e.config.useAscii,padding:r}),a=i.gridColumns,o=i.gridRows;for(let t=0;t<a.length;t++){let r=n.x+t,i=e.columnWidth.get(r)??0;e.columnWidth.set(r,Math.max(i,a[t]))}for(let t=0;t<o.length;t++){let r=n.y+t,i=e.rowHeight.get(r)??0;e.rowHeight.set(r,Math.max(i,o[t]))}if(n.x>0){let t=e.columnWidth.get(n.x-1)??0;e.columnWidth.set(n.x-1,Math.max(t,e.config.paddingX))}if(n.y>0){let r=e.config.paddingY;an(e,t)&&(r+=4);let i=e.rowHeight.get(n.y-1)??0;e.rowHeight.set(n.y-1,Math.max(i,r))}}function Jt(e,t){for(let n of t)e.columnWidth.has(n.x)||e.columnWidth.set(n.x,Math.floor(e.config.paddingX/2)),e.rowHeight.has(n.y)||e.rowHeight.set(n.y,Math.floor(e.config.paddingY/2))}var Yt=8;function Xt(e,t,n,r,i){let a=[];try{for(let o=0;o<Yt;o++){let o=Tt(i,n,t.path,t.style)??At(i,r,t.path,t);if(!o)return;e.grid.add(Xe(o)),a.push(o),Mn(e,t)}}finally{for(let t of a)e.grid.delete(Xe(t))}}function Zt(e,t){return e.subgraphs.some(e=>e.nodes.includes(t))}function Qt(e,t){let n=null;for(let r of e.subgraphs)r.nodes.includes(t)&&(!n||$t(n,r))&&(n=r);return n}function $t(e,t){let n=t;for(;n!==null;){if(n===e)return!0;n=n.parent}return!1}function en(e,t){let n=Qt(e,t);if(!n)return null;let r=n;for(;r.parent;)r=r.parent;return r}function tn(e){let t=[...e.nodes];for(let n of e.children)t.push(...tn(n));return t}function nn(e,t,n){if(t===n)return!0;let r=new Set([t]),i=[t];for(;i.length>0;){let t=i.shift();for(let a of bn(e,t)){if(a===n)return!0;r.has(a)||(r.add(a),i.push(a))}}return!1}function rn(e,t){let n=Qt(e,t);return n?.direction?n.direction:e.config.graphDirection}function an(e,t){let n=Qt(e,t);if(!n)return!1;let r=!1;for(let i of e.edges)if(i.to===t&&Qt(e,i.from)!==n){r=!0;break}if(!r)return!1;let i=Z(t).y;for(let r of n.nodes){if(r===t||!r.gridCoord)continue;let a=!1;for(let t of e.edges)if(t.to===r&&Qt(e,t.from)!==n){a=!0;break}if(a&&r.gridCoord.y<i)return!1}return!0}function on(e,t){if(t.nodes.length===0)return;let n=1e6,r=1e6,i=-1e6,a=-1e6;for(let o of t.children)on(e,o),o.nodes.length>0&&(n=Math.min(n,o.minX),r=Math.min(r,o.minY),i=Math.max(i,o.maxX),a=Math.max(a,o.maxY));for(let e of t.nodes){if(!e.drawingCoord||!e.drawing)continue;let t=e.drawingCoord.x,o=e.drawingCoord.y,s=t+e.drawing.length-1,c=o+e.drawing[0].length-1;n=Math.min(n,t),r=Math.min(r,o),i=Math.max(i,s),a=Math.max(a,c)}t.minX=n-2,t.minY=r-2-2,t.maxX=i+2,t.maxY=a+2;let o=Math.max(0,...Q(t.name).map(e=>M(e))),s=t.maxX-t.minX,c=o+1;if(c>s){let e=c-s,n=Math.floor(e/2),r=e-n;t.minX-=n,t.maxX+=r}}function sn(e){let t=e.subgraphs.filter(e=>e.parent===null&&e.nodes.length>0);for(let e=0;e<t.length;e++)for(let n=e+1;n<t.length;n++){let r=t[e],i=t[n];r.minX<i.maxX&&r.maxX>i.minX&&(r.maxY>=i.minY-1&&r.minY<i.minY?i.minY=r.maxY+1+1:i.maxY>=r.minY-1&&i.minY<r.minY&&(r.minY=i.maxY+1+1)),r.minY<i.maxY&&r.maxY>i.minY&&(r.maxX>=i.minX-1&&r.minX<i.minX?i.minX=r.maxX+1+1:i.maxX>=r.minX-1&&i.minX<r.minX&&(r.minX=i.maxX+1+1))}}function cn(e){for(let t of e.subgraphs)on(e,t);sn(e)}function ln(e){if(e.subgraphs.length===0)return;let t=0,n=0;for(let r of e.subgraphs)t=Math.min(t,r.minX),n=Math.min(n,r.minY);let r=-t,i=-n;if(r!==0||i!==0){e.offsetX=r,e.offsetY=i;for(let t of e.subgraphs)t.minX+=r,t.minY+=i,t.maxX+=r,t.maxY+=i;for(let t of e.nodes)t.drawingCoord&&(t.drawingCoord.x+=r,t.drawingCoord.y+=i)}}function un(e,t){let n=t=>{let n=bn(e,t);return n.length>0?n[0].name:null},r=new Map,i=t.map((e,t)=>{let i=n(e);if(i===null)return t;let a=r.get(i);return a===void 0?(r.set(i,t),t):a});return t.map((e,t)=>({node:e,i:t})).sort((e,t)=>i[e.i]-i[t.i]||e.i-t.i).map(({node:e})=>e)}function dn(e,t){let n=new Set,r=t=>{let r=[t];for(;r.length>0;){let t=r.shift();if(!n.has(t.name)){n.add(t.name);for(let n of bn(e,t))r.push(n)}}};for(let e of t)r(e);let i=[...t];for(let t of e.nodes)n.has(t.name)||(i.push(t),r(t));return i}function fn(e,t){return e.nodes.find(e=>e.gridCoord!==null&&e.gridCoord.x===t.x&&e.gridCoord.y===t.y)}function pn(e,t,n,r,i){let a=r===`x`?`y`:`x`,o=i=>{let o=4;for(;;){let s=t[r]+i*o;if(s<0)return null;let c=r===`x`?{x:s,y:t[a]}:{x:t[a],y:s};if(rt(e.grid,c,3))return c;let l=fn(e,c);if(!l||en(e,l)!==n)return null;o+=4}};return o(i)??o(i*-1)}function mn(e,t,n,r){let i=en(e,t);if(!i)return;let a=n.get(i);if(!a)return;n.delete(i);let o=Z(t),s=rn(e,t)===`LR`?`y`:`x`;for(let t of a){let n=rn(e,t),a=pn(e,o,i,s,1);Kt(e,e.nodes[t.index],a??o,n),r.add(t)}}function hn(e,t){let n=!0;for(;n;){n=!1;let r=t=>e.config.graphDirection===`LR`?t.gridCoord?.y??0:t.gridCoord?.x??0,i=e.nodes.filter(e=>e.gridCoord!==null).sort((e,t)=>r(e)-r(t));for(let r of i){let i=r.gridCoord;if(i===null)continue;let a=[...bn(e,r)].sort((t,n)=>yn(e,t,n));for(let o of a){if(o.gridCoord!==null)continue;let a=Qt(e,r),s=Qt(e,o),c=a&&a===s&&a.direction?a.direction:e.config.graphDirection,l=c===`LR`?i.x+4:i.y+4,u;u=c===e.config.graphDirection?t[l]??0:c===`LR`?i.y:i.x;let d=c===`LR`?{x:l,y:u}:{x:u,y:l};Kt(e,e.nodes[o.index],d,c),c===e.config.graphDirection&&(t[l]=u+4),n=!0}}}}function gn(e){let t=e.config.graphDirection,n=[],r=new Set;for(let t of e.edges)t.from!==t.to&&r.add(t.to.name);let i=dn(e,e.nodes.filter(e=>!r.has(e.name))).filter(t=>{let n=Qt(e,t);if(!n)return!0;for(let r of e.edges)if(r.to===t&&Qt(e,r.from)!==n)return!1;return!0}),a=new Set(i),o=[],s=[];for(let t of i){let n=en(e,t);n!==null&&tn(n).some(n=>n!==t&&!a.has(n)&&!nn(e,t,n))?o.push(t):s.push(t)}let c=un(e,s),l=new Map;for(let t of o){let n=en(e,t),r=l.get(n);r?r.push(t):l.set(n,[t])}let u=new Set,d=!1,f=!1;for(let t of c)Zt(e,t)?bn(e,t).length>0&&(f=!0):d=!0;let p=t===`LR`&&d&&f,m,h=[];p?(m=c.filter(t=>!Zt(e,t)),h=c.filter(t=>Zt(e,t))):m=c;for(let r of m){let i=t===`LR`?{x:0,y:n[0]??0}:{x:n[0]??0,y:0};Kt(e,e.nodes[r.index],i),n[0]=(n[0]??0)+4,mn(e,r,l,u)}if(p&&h.length>0)for(let r of h){let i=t===`LR`?{x:4,y:n[4]??0}:{x:n[4]??0,y:4};Kt(e,e.nodes[r.index],i),n[4]=(n[4]??0)+4,mn(e,r,l,u)}hn(e,n);for(let t of o){if(u.has(t))continue;let r=en(e,t),i=rn(e,t),a=tn(r).filter(e=>e!==t&&e.gridCoord!==null),o;if(a.length>0){let t=a[0];for(let e of a)(i===`LR`?e.gridCoord.x<t.gridCoord.x:e.gridCoord.y<t.gridCoord.y)&&(t=e);let n=i===`LR`?`y`:`x`;o=pn(e,t.gridCoord,r,n,1)??{x:t.gridCoord.x,y:t.gridCoord.y}}else o=i===`LR`?{x:0,y:n[0]??0}:{x:n[0]??0,y:0},n[0]=(n[0]??0)+4;Kt(e,e.nodes[t.index],o,i)}hn(e,n);for(let t of e.nodes)qt(e,t);e.pathBudget=ft(),An(e),e.bundles=yt(e),Ct(e);let g=wt(),_=Dt(),v=et(e.grid);for(let t of e.edges){if(t.bundle&&t.path.length>0){Jt(e,t.path),Et(v,g,t.path,t.style),jt(v,_,t.path,t),Fn(e,t);continue}Mn(e,t),Xt(e,t,g,_,v),Jt(e,t.path),Et(v,g,t.path,t.style),jt(v,_,t.path,t),Fn(e,t)}for(let t of e.nodes)t.drawingCoord=Wt(e,Z(t)),t.drawing=mr(t,e);cn(e),ln(e),ve(e.canvas,e.columnWidth,e.rowHeight,e.offsetX,e.offsetY),ye(e.roleCanvas,e.columnWidth,e.rowHeight,e.offsetX,e.offsetY)}function _n(e,t){return e.edges.filter(e=>e.from.name===t.name)}function vn(e,t){let n=Qt(e,t),r=[],i=n;for(;i!==null;)r.unshift(i),i=i.parent;return r}function yn(e,t,n){let r=vn(e,t),i=vn(e,n),a=0;for(;a<r.length&&a<i.length&&r[a]===i[a];)a++;let o=r[a],s=i[a];return!o||!s||o===s?0:e.subgraphs.indexOf(s)-e.subgraphs.indexOf(o)}function bn(e,t){return _n(e,t).map(e=>e.to)}function xn(e){return e===K?q:e===q?K:e===J?Y:e===Y?J:e===ze?He:e===Be?Ve:e===Ve?Be:e===He?ze:Ue}function $(e,t){return e.x===t.x?e.y<t.y?q:K:e.y===t.y?e.x<t.x?Y:J:e.x<t.x?e.y<t.y?Ve:ze:e.y<t.y?He:Be}function Sn(e){return e===`LR`?[Y,q,q,Y]:[q,Y,Y,q]}function Cn(e,t){if(e.from===e.to)return Sn(t);let n=$(Z(e.from),Z(e.to)),r,i,a,o,s=t===`LR`?X(n,J)||X(n,Be)||X(n,He):X(n,K)||X(n,Be)||X(n,ze);return X(n,Ve)?t===`LR`?(r=q,i=J,a=Y,o=K):(r=Y,i=K,a=q,o=J):X(n,ze)?t===`LR`?(r=K,i=J,a=Y,o=q):(r=Y,i=q,a=K,o=J):X(n,He)?t===`LR`?(r=q,i=q,a=J,o=K):(r=J,i=K,a=q,o=Y):X(n,Be)?t===`LR`?(r=q,i=q,a=J,o=q):(r=Y,i=Y,a=K,o=Y):s?t===`LR`&&X(n,J)?(r=q,i=q,a=J,o=Y):t===`TD`&&X(n,K)?(r=Y,i=Y,a=K,o=q):(r=n,i=xn(n),a=n,o=xn(n)):(r=n,i=xn(n),a=n,o=xn(n)),[r,i,a,o]}var wn=2,Tn=200;function En(e,t){let n=e.gridCoord;return n?t.x>=n.x&&t.x<=n.x+2&&t.y>=n.y&&t.y<=n.y+2:!1}function Dn(e,t,n=[]){for(let r=1;r<t.length-1;r++){let i=t[r];if(tt(e.grid,i)&&!n.some(e=>En(e,i)))return!1}return!0}function On(e){let t=e.from.gridCoord,n=e.to.gridCoord;return!t||!n?!1:t.y===n.y&&t.x!==n.x}function kn(e){let t=e.from.name,n=e.to.name;return On(e)&&n<t?JSON.stringify([n,t]):JSON.stringify([t,n])}function An(e){let t=new Map;for(let n of e.edges){if(n.from===n.to)continue;let e=kn(n),r=t.get(e);r?r.push(n):t.set(e,[n])}for(let e of t.values()){if(e.length<2)continue;let t=new Set;for(let n=0;n<e.length;n++)e[n].parallelLane={index:n,total:e.length,usedOffsets:t}}}function jn(e,t,n,r,i){let a=Ye(Z(t.from),n),o=Ye(Z(t.to),r),s=X(n,J)||X(n,Y),c=[t.from,t.to],l=t.parallelLane.usedOffsets,u=X(n,Y)?1:X(n,J)?-1:X(n,q)?1:-1,d=X(r,Y)?1:X(r,J)?-1:X(r,q)?1:-1,f=s?{x:a.x+u,y:a.y}:{x:a.x,y:a.y+u},p=s?{x:o.x+d,y:o.y}:{x:o.x,y:o.y+d},m=[a,o],h=[a,o],g=wn*i;for(let t=0;t<Tn;t++){let n=g+t;if(l.has(n))continue;let r=a.y+n,i=a.x+n,u=s?[{x:a.x,y:r},{x:o.x,y:r}]:[{x:i,y:a.y},{x:i,y:o.y}],d=mt([a,...u,o]);if(Dn(e,ot(d),c))return l.add(n),{path:d,labelSegment:u};m=d,h=u;let _=s?f.x!==p.x:f.y!==p.y,v=s?_?[{x:f.x,y:r},{x:p.x,y:r}]:[{x:f.x,y:r},{x:f.x,y:r}]:_?[{x:i,y:f.y},{x:i,y:p.y}]:[{x:i,y:f.y},{x:i,y:f.y}],y=mt(s?[a,f,{x:f.x,y:r},{x:p.x,y:r},p,o]:[a,f,{x:i,y:f.y},{x:i,y:p.y},p,o]);if(Dn(e,ot(y),c))return l.add(n),{path:y,labelSegment:v};m=y,h=v}return{path:m,labelSegment:h}}function Mn(e,t){let n=Qt(e,t.from),r=Qt(e,t.to),[i,a,o,s]=Cn(t,n&&n===r&&n.direction?n.direction:e.config.graphDirection);if(t.parallelLane&&t.parallelLane.index>0){let n=X(i,a),r=n?o:i,c=n?s:a;t.startDir=r,t.endDir=c;let l=jn(e,t,r,c,t.parallelLane.index);t.path=l.path,t.text.length>0&&Ln(e,t,l.labelSegment,M(t.text));return}let c=Ye(Z(t.from),i),l=Ye(Z(t.to),a),u=vt(e,c,l,Ge(i)),d=vt(e,Ye(Z(t.from),o),Ye(Z(t.to),s),Ge(o));if(u!==null&&d!==null){u.length<=d.length?(t.startDir=i,t.endDir=a,t.path=u):(t.startDir=o,t.endDir=s,t.path=d);return}if(u!==null){t.startDir=i,t.endDir=a,t.path=u;return}if(d!==null){t.startDir=o,t.endDir=s,t.path=d;return}t.startDir=i,t.endDir=a,t.path=In([c,l])}function Nn(e,t){for(let n of e.nodes){let e=n.gridCoord;if(e&&t>=e.x&&t<=e.x+2)return!0}return!1}function Pn(e,t,n,r){if(!Nn(e,r))return r;for(let i=1;i<=n-t;i++){let a=r+i;if(a<=n&&!Nn(e,a))return a;let o=r-i;if(o>=t&&!Nn(e,o))return o}return r}function Fn(e,t){if(t.text.length===0||t.parallelLane&&t.parallelLane.index>0)return;let n=M(t.text),r=In(t.path),i=r.length,a=[];for(let t=1;t<i;t++){let n=r[t-1],i=r[t],o=[n,i],s=Rn(e,o),c=n.x===i.x;a.push({line:o,width:s,index:t,isVertical:c})}let o=t=>Dn(e,ot(t)),s=e=>e.index===1||e.index===a.length,c=a.filter(e=>e.width>=n&&!s(e)&&o(e.line)),l;if(c.length>0)c.sort((e,t)=>t.index-e.index),l=c[0].line;else{let e=a.filter(e=>e.width>=n&&o(e.line));if(e.length>0)e.sort((e,t)=>t.index-e.index),l=e[0].line;else{let e=a.filter(e=>!s(e)&&o(e.line)),n=a.filter(e=>o(e.line)),r=e.length>0?e:n.length>0?n:a;if(r.sort((e,t)=>t.width-e.width),r.length>0)l=r[0].line;else{let e=t.path[0]??{x:0,y:0};l=[e,e]}}}Ln(e,t,l,n)}function In(e){let t=[];for(let n of e){let e=t[t.length-1];e&&e.x!==n.x&&e.y!==n.y&&t.push({x:n.x,y:e.y}),t.push(n)}return t}function Ln(e,t,n,r){let i=Math.min(n[0].x,n[1].x),a=Math.max(n[0].x,n[1].x),o=Pn(e,i,a,i+Math.floor((a-i)/2)),s=e.columnWidth.get(o)??0;e.columnWidth.set(o,Math.max(s,r+2)),t.labelLine=[n[0],n[1]]}function Rn(e,t){let n=0,r=Math.min(t[0].x,t[1].x),i=Math.max(t[0].x,t[1].x);for(let t=r;t<=i;t++)n+=e.columnWidth.get(t)??0;return n}var zn={solid:{h:{unicode:`─`,ascii:`-`},v:{unicode:`│`,ascii:`|`}},dotted:{h:{unicode:`┄`,ascii:`.`},v:{unicode:`┆`,ascii:`:`}},thick:{h:{unicode:`━`,ascii:`=`},v:{unicode:`┃`,ascii:`‖`}},invisible:{h:{unicode:` `,ascii:` `},v:{unicode:` `,ascii:` `}}};function Bn(e,t,n,r,i,a,o=`solid`){let s=$(t,n),c=[],l=zn[o],u=a?l.h.ascii:l.h.unicode,d=a?l.v.ascii:l.v.unicode;if(X(s,K))for(let a=t.y-r;a>=n.y-i;a--)c.push({x:t.x,y:a}),R(e,t.x,a,d);else if(X(s,q))for(let a=t.y+r;a<=n.y+i;a++)c.push({x:t.x,y:a}),R(e,t.x,a,d);else if(X(s,J))for(let a=t.x-r;a>=n.x-i;a--)c.push({x:a,y:t.y}),R(e,a,t.y,u);else if(X(s,Y))for(let a=t.x+r;a<=n.x+i;a++)c.push({x:a,y:t.y}),R(e,a,t.y,u);else if(X(s,Be)){for(let i=t.x-r;i>=n.x;i--)c.push({x:i,y:t.y}),R(e,i,t.y,u);for(let r=t.y-1;r>=n.y-i;r--)c.push({x:n.x,y:r}),R(e,n.x,r,d)}else if(X(s,ze)){for(let i=t.x+r;i<=n.x;i++)c.push({x:i,y:t.y}),R(e,i,t.y,u);for(let r=t.y-1;r>=n.y-i;r--)c.push({x:n.x,y:r}),R(e,n.x,r,d)}else if(X(s,He)){for(let i=t.x-r;i>=n.x;i--)c.push({x:i,y:t.y}),R(e,i,t.y,u);for(let r=t.y+1;r<=n.y+i;r++)c.push({x:n.x,y:r}),R(e,n.x,r,d)}else if(X(s,Ve)){if(n.x-t.x<=1)for(let a=t.y+r;a<=n.y+i;a++)c.push({x:t.x,y:a}),R(e,t.x,a,d);else{for(let i=t.x+r;i<=n.x;i++)c.push({x:i,y:t.y}),R(e,i,t.y,u);for(let r=t.y+1;r<=n.y+i;r++)c.push({x:n.x,y:r}),R(e,n.x,r,d)}}return c}function Vn(e,t){if(t.path.length===0){let t=P(e.canvas);return[t,t,t,t,t,t]}let n=$n(e,t),[r,i,a]=Un(e,t.path,t.style),o=i.length>0,s=t.style===`invisible`,c=o&&!s?Kn(e,t.path,i[0],t.from):P(e.canvas),l;l=t.hasArrowEnd&&o?Xn(e,i[i.length-1],a[a.length-1],t.endMarker):P(e.canvas);let u;if(t.hasArrowStart&&o){let n=i[0][0],r=Hn(a[0]),o={x:n.x,y:n.y};X(a[0],Y)?o.x=n.x-1:X(a[0],J)?o.x=n.x+1:X(a[0],q)?o.y=n.y-1:X(a[0],K)&&(o.y=n.y+1),u=Xn(e,[n,o],r,t.startMarker)}else u=P(e.canvas);let d=s?P(e.canvas):Zn(e,t.path);return[r,c,l,u,d,n]}function Hn(e){return X(e,K)?q:X(e,q)?K:X(e,J)?Y:X(e,Y)?J:X(e,Be)?Ve:X(e,ze)?He:X(e,He)?ze:X(e,Ve)?Be:Ue}function Un(e,t,n=`solid`){let r=P(e.canvas),i=t[0],a=[],o=[];for(let s=1;s<t.length;s++){let c=t[s],l=Wt(e,i),u=Wt(e,c);if(Je(l,u)){i=c;continue}let d=$(i,c),f=Bn(r,l,u,1,-1,e.config.useAscii,n);f.length===0&&f.push(l),a.push(f),o.push(d),i=c}return[r,a,o]}var Wn=new Set([`│`,`┃`,`║`,`┆`,`┊`,`|`,`‖`]),Gn=new Set([`─`,`━`,`═`,`╌`,`┄`,`-`,`=`]);function Kn(e,t,n,r){let i=P(e.canvas),a=e.config.useAscii;if(r.shape===`state-start`||r.shape===`state-end`)return i;let o=n[0],s=$(t[0],t[1]),c=a?`+`:null,l=(t,n)=>e.canvas[t]?.[n];if(X(s,K)){let e=o.x,t=o.y+1,n=l(e,t);R(i,e,t,n!==void 0&&Gn.has(n)?c??`┴`:a?`|`:`│`)}else if(X(s,q)){let e=o.x,t=o.y-1,n=l(e,t);R(i,e,t,n!==void 0&&Gn.has(n)?c??`┬`:a?`|`:`│`)}else if(X(s,J)||X(s,Y)){let e=r.drawingCoord,t=r.drawing;if(e===null||t===null)throw Error(`drawBoxStart: node "${r.name}" has no drawingCoord/drawing assigned`);let n=t.length,u=X(s,J)?e.x:e.x+n-1,d=o.y,f=l(u,d);R(i,u,d,f!==void 0&&Wn.has(f)?c??(X(s,J)?`┤`:`├`):a?`-`:`─`)}return i}function qn(e,t){if(t===`circle`)return e?`o`:`○`;if(t===`cross`)return e?`x`:`✕`}function Jn(e){if(X(e,K))return`▲`;if(X(e,q))return`▼`;if(X(e,J))return`◄`;if(X(e,Y))return`►`;if(X(e,ze))return`↗`;if(X(e,Be))return`↖`;if(X(e,Ve))return`↘`;if(X(e,He))return`↙`}function Yn(e){if(X(e,K))return`^`;if(X(e,q))return`v`;if(X(e,J))return`<`;if(X(e,Y))return`>`}function Xn(e,t,n,r){let i=P(e.canvas);if(t.length===0)return i;let a=t[t.length-1],o=$(t.length>=2?t[t.length-2]:t[0],a);(t.length===1||X(o,Ue))&&(o=n);let s=qn(e.config.useAscii,r),c;if(s!==void 0)c=s;else if(e.config.useAscii){let e=Yn(o);c=e===void 0?Yn(n)??`*`:e}else{let e=Jn(o);c=e===void 0?Jn(n)??`●`:e}return R(i,a.x,a.y,c),i}function Zn(e,t){let n=P(e.canvas);for(let r=1;r<t.length-1;r++){let i=t[r],a=Wt(e,i),o=$(t[r-1],i),s=$(i,t[r+1]),c;c=e.config.useAscii?`+`:X(o,Y)&&X(s,q)||X(o,K)&&X(s,J)?`┐`:X(o,Y)&&X(s,K)||X(o,q)&&X(s,J)?`┘`:X(o,J)&&X(s,q)||X(o,K)&&X(s,Y)?`┌`:X(o,J)&&X(s,K)||X(o,q)&&X(s,Y)?`└`:`+`,R(n,a.x,a.y,c)}return n}function Qn(e,t){return e.edges.some(e=>e!==t&&e.from===t.to&&e.to===t.from)}function $n(e,t){let n=P(e.canvas);if(t.text.length===0)return n;let r=Gt(e,t.labelLine),i;if(t.path.length>=2){let e=t.path[0].y,n=t.path[t.path.length-1].y;n<e?i=!0:n>e&&(i=!1)}let a=Qn(e,t);return er(n,r,t.text,i,a),n}function er(e,t,n,r,i=!1){if(t.length<2)return;let a=Math.min(t[0].x,t[1].x),o=Math.max(t[0].x,t[1].x),s=Math.min(t[0].y,t[1].y),c=Math.max(t[0].y,t[1].y),l=a+Math.floor((o-a)/2),u=s+Math.floor((c-s)/2);if(r!==void 0&&a===o){let e=c-s,t=Math.max(1,Math.floor(e/4));(i?r:!r)?u-=t:u+=t}let d=Q(n),f=u-Math.floor((d.length-1)/2);for(let t=0;t<d.length;t++){let n=d[t];_e(e,{x:l-Math.floor(M(n)/2),y:f+t},n)}}function tr(e,t,n){let r=Z(t),i=0;for(let t=0;t<2;t++)i+=e.columnWidth.get(r.x+t)??0;let a=0;for(let t=0;t<2;t++)a+=e.rowHeight.get(r.y+t)??0;let o={width:i+1,height:a+1,labelArea:{x:0,y:0,width:0,height:0},gridColumns:[0,0,0],gridRows:[0,0,0]},s=t.drawingCoord;if(s===null)throw Error(`Node "${t.name}" has no drawingCoord; grid layout must run before bundled-edge drawing`);return Ut(t.shape,n,o,s)}function nr(e,t,n){let r=P(e.canvas),i=t.pathToJunction;if(!i||i.length===0)return[r,r,r,r,r,r];let a=P(e.canvas),o=e.config.useAscii,s=i.map((r,a)=>n.type===`fan-in`&&a===0?tr(e,t.from,t.startDir):n.type===`fan-out`&&a===i.length-1?tr(e,t.to,t.endDir):Wt(e,r));for(let e=1;e<s.length;e++){let n=s[e-1],r=s[e];Je(n,r)||Bn(a,n,r,1,-1,o,t.style)}let c=P(e.canvas);for(let t=1;t<i.length-1;t++){let n=i[t],r=Wt(e,n),a=$(i[t-1],n),s=$(n,i[t+1]),l;l=o?`+`:X(a,Y)&&X(s,q)||X(a,K)&&X(s,J)?`┐`:X(a,Y)&&X(s,K)||X(a,q)&&X(s,J)?`┘`:X(a,J)&&X(s,q)||X(a,K)&&X(s,Y)?`┌`:X(a,J)&&X(s,K)||X(a,q)&&X(s,Y)?`└`:`+`,R(c,r.x,r.y,l)}let l=P(e.canvas);if(n.type===`fan-in`&&i.length>=2){let e=s[0],t=$(i[0],i[1]),n=o?`+`:null;X(t,K)?R(l,e.x,e.y,n??`┴`):X(t,q)?R(l,e.x,e.y,n??`┬`):X(t,J)?R(l,e.x,e.y,n??`┤`):X(t,Y)&&R(l,e.x,e.y,n??`├`)}return[a,l,r,r,c,P(e.canvas)]}function rr(e,t){let n=P(e.canvas),r=P(e.canvas);if(t.sharedPath.length<2)return[n,r];let i=e.config.useAscii,a=t.edges[0]?.style??`solid`,o=e.config.graphDirection,s=t.sharedPath.map((n,r)=>{if(t.type===`fan-in`&&r===t.sharedPath.length-1){let n=o===`TD`?K:J;return tr(e,t.sharedNode,n)}if(t.type===`fan-out`&&r===0){let n=o===`TD`?q:Y;return tr(e,t.sharedNode,n)}return Wt(e,n)});for(let e=1;e<s.length;e++){let t=s[e-1],r=s[e];Je(t,r)||Bn(n,t,r,1,-1,i,a)}for(let n=1;n<t.sharedPath.length-1;n++){let a=t.sharedPath[n],o=Wt(e,a),s=$(t.sharedPath[n-1],a),c=$(a,t.sharedPath[n+1]),l;l=i?`+`:X(s,Y)&&X(c,q)||X(s,K)&&X(c,J)?`┐`:X(s,Y)&&X(c,K)||X(s,q)&&X(c,J)?`┘`:X(s,J)&&X(c,q)||X(s,K)&&X(c,Y)?`┌`:X(s,J)&&X(c,K)||X(s,q)&&X(c,Y)?`└`:`+`,R(r,o.x,o.y,l)}return[n,r]}function ir(e,t){let n=P(e.canvas);if(t.sharedPath.length<2)return n;let r=t.sharedPath.length-1,i=t.sharedPath[r-1],a=t.sharedPath[r],o=$(i,a),s=e.config.graphDirection,c=s===`TD`?K:J,l=tr(e,t.sharedNode,c);s===`TD`?--l.y:--l.x;let u=t.edges[0]?.endMarker,d=t.edges.every(e=>e.endMarker===u)?u:void 0,f=qn(e.config.useAscii,d),p;return p=f===void 0?e.config.useAscii?X(o,K)?`^`:X(o,q)?`v`:X(o,J)?`<`:X(o,Y)?`>`:`v`:X(o,K)?`▲`:X(o,q)?`▼`:X(o,J)?`◄`:X(o,Y)?`►`:`▼`:f,R(n,l.x,l.y,p),n}function ar(e,t){let n=P(e.canvas);if(!t.pathToJunction||t.pathToJunction.length<2)return n;let r=t.pathToJunction.length-1,i=t.pathToJunction[r-1],a=t.pathToJunction[r],o=$(i,a),s=e.config.graphDirection,c=s===`TD`?K:J,l=tr(e,t.to,c);s===`TD`?--l.y:--l.x;let u=qn(e.config.useAscii,t.endMarker),d;return d=u===void 0?e.config.useAscii?X(o,K)?`^`:X(o,q)?`v`:X(o,J)?`<`:X(o,Y)?`>`:`v`:X(o,K)?`▲`:X(o,q)?`▼`:X(o,J)?`◄`:X(o,Y)?`►`:`▼`:u,R(n,l.x,l.y,d),n}function or(e){return X(e,K)?q:X(e,q)?K:X(e,J)?Y:X(e,Y)?J:e}function sr(e,t){let n=P(e.canvas);if(t.sharedPath.length<2)return n;let r=t.sharedPath[0],i=t.sharedPath[1],a=or($(r,i)),o=e.config.graphDirection,s=o===`TD`?q:Y,c=tr(e,t.sharedNode,s);o===`TD`?c.y+=1:c.x+=1;let l;return l=e.config.useAscii?X(a,K)?`^`:X(a,q)?`v`:X(a,J)?`<`:X(a,Y)?`>`:`^`:X(a,K)?`▲`:X(a,q)?`▼`:X(a,J)?`◄`:X(a,Y)?`►`:`▲`,R(n,c.x,c.y,l),n}function cr(e,t){let n=P(e.canvas);if(!t.pathToJunction||t.pathToJunction.length<2)return n;let r=t.pathToJunction[0],i=t.pathToJunction[1],a=or($(r,i)),o=tr(e,t.from,t.startDir);X(t.startDir,K)?--o.y:X(t.startDir,q)?o.y+=1:X(t.startDir,J)?--o.x:X(t.startDir,Y)&&(o.x+=1);let s;return s=e.config.useAscii?X(a,K)?`^`:X(a,q)?`v`:X(a,J)?`<`:X(a,Y)?`>`:`v`:X(a,K)?`▲`:X(a,q)?`▼`:X(a,J)?`◄`:X(a,Y)?`►`:`▼`,R(n,o.x,o.y,s),n}function lr(e,t){let n=P(e.canvas);if(!t.junctionPoint)return n;let r=Wt(e,t.junctionPoint),i=e.config.useAscii,a=!1,o=!1,s=!1,c=!1;if(t.sharedPath.length>=2){let e=t.type===`fan-in`?0:t.sharedPath.length-1,n=t.type===`fan-in`?1:t.sharedPath.length-2,r=$(t.sharedPath[e],t.sharedPath[n]);X(r,q)?o=!0:X(r,K)?a=!0:X(r,Y)?c=!0:X(r,J)&&(s=!0)}for(let e of t.edges)if(e.pathToJunction&&e.pathToJunction.length>=2){let n=t.type===`fan-in`?e.pathToJunction.length-1:0,r=t.type===`fan-in`?e.pathToJunction.length-2:1,i=$(e.pathToJunction[r],e.pathToJunction[n]);X(i,q)?a=!0:X(i,K)?o=!0:X(i,Y)?s=!0:X(i,J)&&(c=!0)}let l;return l=i?`+`:a&&o&&s&&c?`┼`:o&&s&&c&&!a?`┬`:a&&s&&c&&!o?`┴`:a&&o&&c&&!s?`├`:a&&o&&s&&!c?`┤`:s&&c?`─`:a&&o?`│`:o&&c?`┌`:o&&s?`┐`:a&&c?`└`:a&&s?`┘`:`┼`,R(n,r.x,r.y,l),n}function ur(e,t){let n=e.maxX-e.minX,r=e.maxY-e.minY;if(n<=0||r<=0)return N(0,0);let i={x:0,y:0},a={x:n,y:r},o=N(n,r);if(t.config.useAscii){for(let e=i.x+1;e<a.x;e++)R(o,e,i.y,`-`);for(let e=i.x+1;e<a.x;e++)R(o,e,a.y,`-`);for(let e=i.y+1;e<a.y;e++)R(o,i.x,e,`|`);for(let e=i.y+1;e<a.y;e++)R(o,a.x,e,`|`);R(o,i.x,i.y,`+`),R(o,a.x,i.y,`+`),R(o,i.x,a.y,`+`),R(o,a.x,a.y,`+`)}else{for(let e=i.x+1;e<a.x;e++)R(o,e,i.y,`─`);for(let e=i.x+1;e<a.x;e++)R(o,e,a.y,`─`);for(let e=i.y+1;e<a.y;e++)R(o,i.x,e,`│`);for(let e=i.y+1;e<a.y;e++)R(o,a.x,e,`│`);R(o,i.x,i.y,`┌`),R(o,a.x,i.y,`┐`),R(o,i.x,a.y,`└`),R(o,a.x,a.y,`┘`)}return o}function dr(e,t){let n=e.maxX-e.minX,r=e.maxY-e.minY;if(n<=0||r<=0)return[N(0,0),{x:0,y:0},[]];let i=N(n,r),a=[],o=Q(e.name);for(let e=0;e<o.length;e++){let t=o[e],s=1+e,c=1+Math.ceil((n-1-M(t))/2);c<1&&(c=1);let l=ae(t);for(let e=0;e<l.length;e++)c+e>=n||s>=r||(R(i,c+e,s,l[e]),a.push({x:c+e,y:s}))}return[i,{x:e.minX,y:e.minY},a]}function fr(e,t){return pr(e,t)}function pr(e,t){let n=Z(e),r=t.config.useAscii,i=0;for(let e=0;e<2;e++)i+=t.columnWidth.get(n.x+e)??0;let a=0;for(let e=0;e<2;e++)a+=t.rowHeight.get(n.y+e)??0;let o={x:0,y:0},s={x:i,y:a},c=N(Math.max(o.x,s.x),Math.max(o.y,s.y)),l=Ft(e.shape,r),u=e.shape===`state-end`,d=r?u?`=`:`-`:u?`═`:`─`,f=r?u?`‖`:`|`:u?`║`:`│`,p=u?r?{tl:`#`,tr:`#`,bl:`#`,br:`#`}:{tl:`╔`,tr:`╗`,bl:`╚`,br:`╝`}:l;for(let e=o.x+1;e<s.x;e++)R(c,e,o.y,d);for(let e=o.x+1;e<s.x;e++)R(c,e,s.y,d);for(let e=o.y+1;e<s.y;e++)R(c,o.x,e,f);for(let e=o.y+1;e<s.y;e++)R(c,s.x,e,f);R(c,o.x,o.y,p.tl),R(c,s.x,o.y,p.tr),R(c,o.x,s.y,p.bl),R(c,s.x,s.y,p.br);let m=e.displayLabel,h=Q(m),g=o.y+Math.floor(a/2)-Math.floor((h.length-1)/2);for(let e=0;e<h.length;e++){let t=h[e],n=M(t),r=o.x+Math.floor(i/2)-Math.ceil(n/2)+1,a=ae(t);for(let t=0;t<a.length;t++)R(c,r+t,g+e,a[t])}return c}function mr(e,t){return fr(e,t)}function hr(e){return/^[┌┐└┘├┤┬┴┼│─╭╮╰╯+\-|]$/.test(e)?`border`:`text`}function gr(e,t=1){let n=Math.max(0,t),r=0;for(let t of e)for(let e of t)r=Math.max(r,M(e));let i=0;for(let t of e)i+=Math.max(t.length,1);return{width:r+2*n+2,height:i+(e.length-1)+2}}function _r(e,t,n=1){let r=Math.max(0,n),{width:i,height:a}=gr(e,r),o=t?`-`:`─`,s=t?`|`:`│`,c=t?`+`:`┌`,l=t?`+`:`┐`,u=t?`+`:`└`,d=t?`+`:`┘`,f=t?`+`:`├`,p=t?`+`:`┤`,m=N(i-1,a-1);R(m,0,0,c);for(let e=1;e<i-1;e++)R(m,e,0,o);R(m,i-1,0,l),R(m,0,a-1,u);for(let e=1;e<i-1;e++)R(m,e,a-1,o);R(m,i-1,a-1,d);for(let e=1;e<a-1;e++)R(m,0,e,s),R(m,i-1,e,s);let h=1;for(let t=0;t<e.length;t++){let n=e[t],a=n.length>0?n:[``];for(let e of a){let t=1+r,n=ae(e);for(let e=0;e<n.length;e++)R(m,t+e,h,n[e]);h++}if(t<e.length-1){R(m,0,h,f);for(let e=1;e<i-1;e++)R(m,e,h,o);R(m,i-1,h,p),h++}}return m}function vr(e){function t(e){return e.parent===null?0:1+t(e.parent)}let n=[...e];return n.sort((e,n)=>t(e)-t(n)),n}function yr(e,t,n,r){for(let i=0;i<t.length;i++)for(let a=0;a<(t[0]?.length??0);a++){let o=t[i]?.[a];if(o&&o!==` `){let t=i+n.x,o=a+n.y;t>=0&&o>=0&&I(e,t,o,r)}}}function br(e,t,n,r){for(let i of t)yr(e,i,n,r)}function xr(e,t,n){let r=e=>/^[┌┐└┘├┤┬┴┼│─╭╮╰╯+\-|.':]$/.test(e);for(let i=0;i<t.length;i++)for(let a=0;a<(t[0]?.length??0);a++){let o=t[i]?.[a];if(o&&o!==` `){let t=i+n.x,s=a+n.y;t>=0&&s>=0&&I(e,t,s,r(o)?`border`:`text`)}}}function Sr(e){let t=e.config.useAscii,n={x:0,y:0},r=vr(e.subgraphs);for(let n of r){let r=ur(n,e),i={x:n.minX,y:n.minY};e.canvas=z(e.canvas,i,t,r),yr(e.roleCanvas,r,i,`border`)}for(let n of e.nodes)!n.drawn&&n.drawingCoord&&n.drawing&&(e.canvas=z(e.canvas,n.drawingCoord,t,n.drawing),xr(e.roleCanvas,n.drawing,n.drawingCoord),n.drawn=!0);let i=[],a=[],o=[],s=[],c=[],l=[],u=[],d=new Set;for(let t of e.edges)if(t.bundle&&t.pathToJunction){let n=t.bundle,[r,f,,,p,m]=nr(e,t,n);if(i.push(r),a.push(p),c.push(f),l.push(m),n.type===`fan-in`&&t.hasArrowStart){let n=cr(e,t);s.push(n)}if(!d.has(n)){d.add(n);let[t,r]=rr(e,n);if(i.push(t),a.push(r),n.type===`fan-in`){let t=ir(e,n);o.push(t)}if(n.type===`fan-out`&&n.edges.every(e=>e.hasArrowStart)){let t=sr(e,n);s.push(t)}let c=lr(e,n);u.push(c)}if(n.type===`fan-out`&&t.hasArrowEnd){let n=ar(e,t);o.push(n)}}else{let[n,r,u,d,f,p]=Vn(e,t);i.push(n),a.push(f),o.push(u),s.push(d),c.push(r),l.push(p)}let f=pe(i);e.canvas=z(e.canvas,n,t,...f),br(e.roleCanvas,f,n,`line`),e.canvas=z(e.canvas,n,t,...a),br(e.roleCanvas,a,n,`corner`),e.canvas=z(e.canvas,n,t,...u),br(e.roleCanvas,u,n,`junction`),e.canvas=z(e.canvas,n,t,...o),br(e.roleCanvas,o,n,`arrow`),e.canvas=z(e.canvas,n,t,...c),br(e.roleCanvas,c,n,`junction`),e.canvas=z(e.canvas,n,t,...s),br(e.roleCanvas,s,n,`arrow`),e.canvas=z(e.canvas,n,t,...l),br(e.roleCanvas,l,n,`text`);for(let n of e.subgraphs){if(n.nodes.length===0)continue;let[r,i,a]=dr(n,e);e.canvas=z(e.canvas,i,t,r),yr(e.roleCanvas,r,i,`text`);for(let{x:t,y:n}of a){let a=r[t]?.[n];a===` `&&(R(e.canvas,t+i.x,n+i.y,a),I(e.roleCanvas,t+i.x,n+i.y,`text`))}}return e.canvas}function Cr(e,t,n,r){if(r(e))return e;let i=Math.max(e-t,n-e);for(let a=1;a<=i;a++){let i=e+a;if(i<=n&&r(i))return i;let o=e-a;if(o>=t&&r(o))return o}}function wr(e){return`${e.keys.length>0?e.keys.join(`,`)+` `:` `}${e.type} ${e.name}`}function Tr(e){let t=Q(e.label),n=e.attributes.map(wr);return n.length===0?[t]:[t,n]}function Er(e,t,n=!1,r=!1){if(t)switch(e){case`one`:return r?`+`:`|`;case`zero-one`:return n?`o|`:`|o`;case`many`:return n?`<`:`>`;case`zero-many`:return n?`o<`:`>o`}else switch(e){case`one`:return r?`┼`:`│`;case`zero-one`:return n?`○│`:`│○`;case`many`:return n?`╟`:`╢`;case`zero-many`:return n?`○╟`:`╢○`}}function Dr(e){let t=new Set,n=[],r=new Map;for(let t of e.entities)r.set(t.id,new Set);for(let t of e.relationships)r.get(t.entity1)?.add(t.entity2),r.get(t.entity2)?.add(t.entity1);function i(e,n){let i=[e];for(;i.length>0;){let e=i.pop();if(!t.has(e)){t.add(e),n.add(e);for(let n of r.get(e)??[])t.has(n)||i.push(n)}}}for(let r of e.entities)if(!t.has(r.id)){let e=new Set;i(r.id,e),e.size>0&&n.push(e)}return n}function Or(e,t,n){let r=e.get(t);if(r===void 0)throw Error(`ER diagram layout: missing ${n} for entity "${t}"`);return r}function kr(n,r,i,a){let o=(0,e.splitStatements)(n),s=(0,t.parseErDiagram)(o);if(s.entities.length===0)return``;let c=r.useAscii,l=Ke(r.paddingX,5,6,6),u=Ke(r.paddingY,5,4,2),d=Ke(r.paddingY,5,2,1),f=Math.max(...[`one`,`zero-one`,`many`,`zero-many`].flatMap(e=>[Er(e,c,!1).length,Er(e,c,!0).length])),p=new Map,m=new Map,h=new Map,g=new Map;for(let e of s.entities){g.set(e.id,e);let t=Tr(e);p.set(e.id,t);let{width:n,height:i}=gr(t,r.boxBorderPadding);m.set(e.id,n),h.set(e.id,i)}let _=new Map;for(let e of s.relationships){if(!e.label)continue;let t=[e.entity1,e.entity2].sort().join(`|`),n=Mt(e.label);_.set(t,Math.max(_.get(t)??0,n))}let v=Dr(s),y=new Map,b=0;for(let e of v){let t=s.entities.filter(t=>e.has(t.id)),n=Math.max(2,Math.ceil(Math.sqrt(t.length))),r=0,i=0,a=0;for(let e=0;e<t.length;e++){let o=t[e],s=Or(m,o.id,`box width`),c=Or(h,o.id,`box height`);a>=n&&(b+=i+u,r=0,i=0,a=0),y.set(o.id,{entity:o,sections:Or(p,o.id,`sections`),x:r,y:b,width:s,height:c});let d=l,f=a+1>=n,g=t[e+1];if(!f&&g){let e=[o.id,g.id].sort().join(`|`),t=_.get(e)??0;t>0&&(d=Math.max(d,t+2))}r+=s+d,i=Math.max(i,c),a++}b+=i+d}let x=0,S=0;for(let e of y.values())x=Math.max(x,e.x+e.width),S=Math.max(S,e.y+e.height);x+=4,S+=2;let C=N(x-1,S-1),w=F(x-1,S-1);function T(e,t,n,r){R(C,e,t,n,{role:r,roleCanvas:w})}function E(e,t){let n=w[e]?.[t];return n===`text`||n===`border`}function D(e,t,n,r,i){for(let a=0;a<e.length;a++){let e=t+a;if(!(e<r||e>i)&&E(e,n))return!1}return!0}function O(e,t,n,r,i){for(let a=0;a<e.length;a++){let e=t+a;if(!(e<r||e>i)&&(E(e,n)||w[e]?.[n]===`arrow`||ee.has(`${e},${n}`)))return!1}return!0}for(let e of y.values()){let t=_r(e.sections,c,r.boxBorderPadding);for(let n=0;n<t.length;n++)for(let r=0;r<t[0].length;r++){let i=t[n][r];if(i!==` `){let t=e.x+n,a=e.y+r;t<x&&a<S&&T(t,a,i,hr(i))}}}let ee=new Set;for(let e of y.values())for(let t=0;t<e.height;t++)for(let n=0;n<e.width;n++)ee.add(`${e.x+n},${e.y+t}`);function k(e,t,n,r){ee.has(`${e},${t}`)||(r===`text`||w[e]?.[t]!==`text`)&&T(e,t,n,r)}function te(e,t,n,r){w[e-1]?.[t]!==`text`&&w[e+1]?.[t]!==`text`&&k(e,t,n,r)}function ne(e,t,n,r){for(let i=n;i<=r;i++)for(let n=e;n<=t;n++){let e=C[n]?.[i];if(e!==void 0&&e!==` `)return!1}return!0}let A=[];function j(e,t,n){for(let r of A)if(Math.abs(r.x-e)===1&&t<=r.yEnd&&n>=r.yStart)return!0;return!1}function re(e,t,n){for(let r of A)if(!(Math.abs(r.x-e)>1)&&t<=r.yEnd&&n>=r.yStart)return!0;return!1}function ie(e,t,n){A.push({x:e,yStart:t,yEnd:n})}let M=c?`-`:`─`,P=c?`|`:`│`,I=c?`.`:`╌`,L=c?`:`:`┊`;function ce(e,t){return c?`+`:e===`down`?t===`right`?`┌`:`┐`:t===`right`?`└`:`┘`}function le(e,t,n,r){k(e,t,ce(n,r),`line`)}let ue=new Map,de=new Map;for(let e of s.relationships){let t=y.get(e.entity1),n=y.get(e.entity2);if(!t||!n)continue;let r=t.y+Math.floor(t.height/2),i=n.y+Math.floor(n.height/2);if(Math.abs(r-i)<Math.max(t.height,n.height))continue;let[a,o]=r<i?[t,n]:[n,t],s=a.x+Math.floor(a.width/2),c=o.x+Math.floor(o.width/2),l=de.get(a.entity.id);l||(l=[],de.set(a.entity.id,l)),l.push({rel:e,otherCenterX:c});let u=ue.get(o.entity.id);u||(u=[],ue.set(o.entity.id,u)),u.push({rel:e,otherCenterX:s})}function fe(e,t,n){let r=n.get(e.entity.id),i=e.x+Math.floor(e.width/2);if(!r||r.length<=1)return i;let a=[...r].sort((e,t)=>e.otherCenterX-t.otherCenterX),o=a.findIndex(e=>e.rel===t);if(o===-1)return i;let s=Math.min(1,Math.floor((e.width-1)/2)),c=Math.max(0,e.width-1-s*2),l=a.length>1?c/(a.length-1):0;return e.x+s+Math.round(o*l)}for(let e of s.relationships){let t=y.get(e.entity1),n=y.get(e.entity2);if(!t||!n)continue;let r=e.identifying?M:I,i=e.identifying?P:L,a=t.x+Math.floor(t.width/2),o=t.y+Math.floor(t.height/2),s=n.x+Math.floor(n.width/2),l=n.y+Math.floor(n.height/2);if(Math.abs(o-l)<Math.max(t.height,n.height)){let[o,l]=a<s?[t,n]:[n,t],[d,p]=a<s?[e.cardinality1,e.cardinality2]:[e.cardinality2,e.cardinality1],m=o.x+o.width,h=l.x-1,g=o.y+Math.floor(o.height/2),_;for(let e of y.values())e!==o&&e!==l&&e.y===o.y&&e.x<h+1&&e.x+e.width>m&&(_=Math.max(_??0,e.y+e.height));let v=h-m+1,b=+(v>=f+1),x=Er(d,c,!1),S=Er(p,c,!0),T=+(v>=3&&x[0]===P),E=+(v>=3&&S[S.length-1]===P),O=m+T,ee=h-E,A;if(_===void 0){for(let e=m;e<=h;e++)te(e,g,r,`line`);if(A=g+1,e.label){let t=m+b,n=h-b,r=Q(e.label).length,i=g+1+Math.max(u-1,1);for(;A<i&&!ne(t,n,A,A+r-1);)A++}}else{let t=Math.max(o.y+o.height,l.y+l.height,_),n=e.label?Q(e.label).length:0,a=t+1,s=t+Math.max(u*3,4);for(;a<s&&!ne(m,h,a,a+n);)a++;se(C,h+1,a+n+1),oe(w,h+1,a+n+1);for(let e=g;e<=a;e++)k(m,e,i,`line`),k(h,e,i,`line`);for(let e=m;e<=h;e++)te(e,a,r,`line`);m!==h&&(le(m,a,`up`,`right`),le(h,a,`up`,`left`)),A=a+1}for(let e=0;e<x.length;e++)k(O+e,g,x[e],`arrow`);for(let e=0;e<S.length;e++)k(ee-S.length+1+e,g,S[e],`arrow`);if(e.label){let t=Q(e.label),n=Math.floor((m+h)/2),r=m+b,i=h-b;for(let e=0;e<t.length;e++){let a=t[e],o=ae(a),s=Math.max(r,n-Math.floor(o.length/2)),c=A+e;if(se(C,Math.max(s+o.length,1),Math.max(c+1,1)),oe(w,Math.max(s+o.length,1),Math.max(c+1,1)),D(o,s,c,r,i))for(let e=0;e<o.length;e++){let t=s+e;t>=r&&t<=i&&k(t,c,o[e],`text`)}}}}else{let[a,s]=o<l?[t,n]:[n,t],[u,d]=o<l?[e.cardinality1,e.cardinality2]:[e.cardinality2,e.cardinality1],f=a.y+a.height,p=s.y-1,m=fe(a,e,de),h=fe(s,e,ue);function pe(e,t,n){for(let r=t;r<=n;r++)if(ee.has(`${e},${r}`))return!1;return!0}let g=f,_=p,v=Math.max(...[...y.values()].filter(e=>e.y===a.y).map(e=>e.y+e.height)),b=s.y,x=Math.max(f,v+1),S=Math.min(p,b-1);function z(e,t,n){let r=Math.floor(x<=S?(x+S)/2:(f+p)/2);if(x>S)return r;for(let r=x;r<=S;r++)if(ne(e,t,r,r+n))return r;return r}let E=m!==h,D=Math.min(m,h),A=Math.max(m,h),M=E?z(D,A,0):p,N=E?M-1:p,P=!pe(m,x,S)||!pe(h,x,S)||j(m,f,E?M:p)||E&&j(h,M,p),F=m;if(P){let e=C.length,t;for(let n=0;n<=e;n++){let e=m+n;if(pe(e,f,p)&&!re(e,f,p)){t=e;break}let r=m-n;if(n>0&&pe(r,f,p)&&!re(r,f,p)){t=r;break}}F=t??m;for(let e=f;e<=g;e++)k(m,e,i,`line`);for(let e=Math.min(m,F);e<=Math.max(m,F);e++)te(e,g,r,`line`);for(let e=g;e<=_;e++)k(F,e,i,`line`);for(let e=Math.min(F,h);e<=Math.max(F,h);e++)te(e,_,r,`line`);for(let e=_;e<=p;e++)k(h,e,i,`line`);if(m!==F){let e=F>m?`right`:`left`,t=e===`right`?`left`:`right`;le(m,g,`up`,e),le(F,g,`down`,t)}if(F!==h){let e=h>F?`right`:`left`,t=e===`right`?`left`:`right`;le(F,_,`up`,e),le(h,_,`down`,t)}ie(F,g,_)}else{for(let e=f;e<=N;e++)k(m,e,i,`line`);if(ie(m,f,E?M:N),E){for(let e=D;e<=A;e++)te(e,M,r,`line`);for(let e=M+1;e<=p;e++)k(h,e,i,`line`);ie(h,M,p);let e=h>m?`right`:`left`,t=e===`right`?`left`:`right`;le(m,M,`up`,e),le(h,M,`down`,t),F=h}}let I=Er(u,c,!1,!0);for(let e=0;e<I.length;e++)k(m-Math.floor(I.length/2)+e,g,I[e],`arrow`);let L=m===h?m:h,R=Er(d,c,!0,!0);for(let e=0;e<R.length;e++)k(L-Math.floor(R.length/2)+e,_,R[e],`arrow`);if(e.label){let t=Q(e.label),n=Math.max(I.length-1-Math.floor(I.length/2),R.length-1-Math.floor(R.length/2)),r=F+n+2,i=t.map(e=>ae(e)),a=r+Math.max(...i.map(e=>e.length))-1,o=t.length,s=Math.floor((f+p)/2)-Math.floor((o-1)/2);a>=0&&(se(C,a+1,p+1),oe(w,a+1,p+1));let c=null;for(let e=0;e<=p-f&&c===null;e++){let t=e===0?[s]:[s+e,s-e];for(let e of t)if(!(e<f||e+o-1>p)&&i.every((t,n)=>O(t,r,e+n,0,a))){c=e;break}}if(c!==null)for(let e=0;e<o;e++){let t=i[e],n=c+e;for(let e=0;e<t.length;e++){let i=r+e;i>=0&&k(i,n,t[e],`text`)}w[r-1]?.[n]===`line`&&T(r-1,n,` `,`line`);let a=r+t.length;w[a]?.[n]===`line`&&T(a,n,` `,`line`)}}}}return me(C,{roleCanvas:w,colorMode:i,theme:a})}var Ar=4,jr=[`O`,`/|\\`,`/ \\`],Mr=3,Nr=4;function Pr(e){return e.seqNumber===void 0?Ar:Ar+String(e.seqNumber).length}function Fr(n,r,i,a){let o=(0,e.splitStatements)(n),s=(0,t.parseSequenceDiagram)(o);if(s.actors.length===0)return``;let c=r.useAscii,l=c?`-`:`─`,u=c?`|`:`│`,d=c?`+`:`┌`,f=c?`+`:`┐`,p=c?`+`:`└`,m=c?`+`:`┘`,h=c?`+`:`┬`,g=c?`+`:`┴`,_=c?`+`:`├`,v=c?`+`:`┤`,y=new Map;s.actors.forEach((e,t)=>y.set(e.id,t));function b(e){let t=y.get(e);if(t===void 0)throw Error(`Sequence diagram: unknown actor "${e}"`);return t}function x(e){let t=Mt(e.label?`${e.type} [${e.label}]`:e.type);for(let n of e.dividers)n.label&&(t=Math.max(t,Mt(`[${n.label}]`)));return t}let S=Math.max(0,r.boxBorderPadding),C=e=>Math.max(Mt(e.label),e.type===`actor`?Mr:0),w=e=>Nt(e.label)+(e.type===`actor`?jr.length:0),T=s.actors.map(e=>C(e)+2*S+2),E=T.map(e=>Math.ceil(e/2)),D=s.actors.map(e=>w(e)+2),O=Math.max(...D,3),ee=(e,t)=>t-Math.floor(T[e]/2),k=Math.floor((O-1)/2),te=O-1-k,ne=new Map,A=new Map;s.actors.forEach((e,t)=>{e.createdAt!==void 0&&ne.set(e.createdAt,t),e.destroyedAt!==void 0&&A.set(e.destroyedAt,t)});let j=new Map,re=new Map,ie=s.boxes.filter(e=>e.actorIds.length>0).map(e=>{let t=e.actorIds.map(b);return{label:e.label,lo:Math.min(...t),hi:Math.max(...t)}}),P=ie.length>0,I=s.actors.map((e,t)=>ie.findIndex(e=>e.lo<=t&&t<=e.hi)),ce=+!!P,le=e=>e===``?0:Mt(e)+6,ue=Array(Math.max(s.actors.length-1,0)).fill(0);for(let e of s.messages){let t=b(e.from),n=b(e.to);if(t===n)continue;let r=Math.min(t,n),i=Math.max(t,n),a=Mt(e.label)+4,o=i-r,s=Math.ceil(a/o);for(let e=r;e<i;e++)ue[e]=Math.max(ue[e],s)}function de(e){let t=Q(e.text);return Math.max(...t.map(e=>M(e)))+2+2*S}let fe=Array(s.actors.length).fill(0),pe=Array(s.actors.length).fill(0),z=Array(s.actors.length).fill(0),he=Array(s.actors.length).fill(0);for(let e of s.notes)if(e.position===`left`||e.position===`right`){let t=b(e.actorIds[0]),n=de(e);e.position===`left`?fe[t]=Math.max(fe[t],n):pe[t]=Math.max(pe[t],n)}else if(e.position===`over`&&e.actorIds.length===1){let t=b(e.actorIds[0]),n=de(e),r=Math.floor(n/2),i=n-r;z[t]=Math.max(z[t],r),he[t]=Math.max(he[t],i)}let ge=Ke(r.paddingX,5,10,4),B=[Math.max(E[0]+(I[0]===-1?0:2),fe[0]+1,z[0])];for(let e=1;e<s.actors.length;e++){let t=I[e-1],n=I[e],r=t===n?0:(t===-1?0:1)+(n===-1?0:1),i=r===0?0:r*2-1,a=Math.max(pe[e-1],fe[e],he[e-1],z[e])+2,o=Math.max(E[e-1]+E[e]+2+i,ue[e-1]+2,a,ge);B[e]=B[e-1]+o}let _e=e=>ee(e.lo,B[e.lo])-1-1,ve=e=>Math.max(ee(e.hi,B[e.hi])+T[e.hi]-1+1+1,_e(e)+le(e.label)-1);for(let e of ie){if(e.hi+1>=s.actors.length)continue;let t=ee(e.hi+1,B[e.hi+1]),n=I[e.hi+1]===-1?0:2,r=ve(e)+1+1+n-t;if(r>0){let t=B.slice(e.hi+1).map(e=>e+r);B.splice(e.hi+1,t.length,...t)}}for(let e of s.blocks){let t=-1,n=-1,r=1/0,i=-1;for(let a=e.startIndex;a<=e.endIndex&&!(a>=s.messages.length);a++){let e=s.messages[a],o=b(e.from),c=b(e.to);if(t=t===-1?Math.min(o,c):Math.min(t,o,c),n=Math.max(n,o,c),r=Math.min(r,B[Math.min(o,c)]),i=Math.max(i,B[Math.max(o,c)]),o===c){let t=B[o]+Ar+2+Mt(e.label);i=Math.max(i,t)}}if(n===-1||n+1>=s.actors.length)continue;let a=Math.max(0,r-Nr),o=i+Nr,c=a+1+x(e),l=Math.max(o,c),u=B[n+1],d=l+2-u;if(d>0){let e=B.slice(n+1).map(e=>e+d);B.splice(n+1,e.length,...e)}}let ye=[],be=[],xe=new Map,Se=new Map,Ce=new Map,we=[],Te=ce,Ee=Te+O,V=Ee+ce,De=Ke(r.paddingY,5,1,0),Oe=Math.max(De,1);for(let e of s.notes){if(e.afterIndex!==-1)continue;V+=De;let t=Q(e.text),n=de(e),r=t.length+2,i=y.get(e.actorIds[0])??0,a;if(e.position===`left`)a=B[i]-n-1;else if(e.position===`right`)a=B[i]+2;else if(e.actorIds.length>=2){let t=y.get(e.actorIds[1])??i;a=Math.floor((B[i]+B[t])/2)-Math.floor(n/2)}else a=B[i]-Math.floor(n/2);a=Math.max(0,a),we.push({x:a,y:V,width:n,height:r,lines:t}),V+=r}for(let e=0;e<s.messages.length;e++){for(let t=0;t<s.blocks.length;t++)s.blocks[t].startIndex===e&&(V+=De+1,xe.set(t,V-1));for(let t=0;t<s.blocks.length;t++)for(let n=0;n<s.blocks[t].dividers.length;n++)s.blocks[t].dividers[n].index===e&&(V+=De,Ce.set(`${t}:${n}`,V),V+=Oe);V+=De;let t=s.messages[e],n=t.from===t.to,r=Nt(t.label),i=n?void 0:ne.get(e),a=A.get(e);if(n)be[e]=V+1,ye[e]=V,V+=2+r;else{let t=i===void 0?0:k,n=i===void 0?0:te;be[e]=V,ye[e]=V+r+t,V+=r+t+1+n,i!==void 0&&j.set(i,ye[e]-t)}a!==void 0&&(re.set(a,V),V+=1);for(let t=0;t<s.notes.length;t++)if(s.notes[t].afterIndex===e){V+=De;let e=s.notes[t],n=Q(e.text),r=de(e),i=n.length+2,a=y.get(e.actorIds[0])??0,o;if(e.position===`left`)o=B[a]-r-1;else if(e.position===`right`)o=B[a]+2;else if(e.actorIds.length>=2){let t=y.get(e.actorIds[1])??a;o=Math.floor((B[a]+B[t])/2)-Math.floor(r/2)}else o=B[a]-Math.floor(r/2);o=Math.max(0,o),we.push({x:o,y:V,width:r,height:i,lines:n}),V+=i}for(let t=0;t<s.blocks.length;t++)s.blocks[t].endIndex===e&&(V+=De,Se.set(t,V),V+=Oe)}V+=Oe;let ke=V,Ae=ke+ce,je=Ae+O+ce,H=(B[B.length-1]??0)+(E[E.length-1]??0)+2;for(let e of ie)H=Math.max(H,ve(e)+2);for(let e=0;e<s.messages.length;e++){let t=s.messages[e];if(t.from===t.to){let e=B[b(t.from)]+Pr(t)+2+2+Mt(t.label);H=Math.max(H,e+1)}}for(let e of we)H=Math.max(H,e.x+e.width+1);let Me=N(H,je-1),U=F(H,je-1);function W(e,t,n,r){R(Me,e,t,n,{role:r,roleCanvas:U})}function G(e,t,n,r,i){let a=ae(n);for(let n=0;n<a.length;n++){let o=e+n;if(i!==void 0&&o>=i||a[n+1]===``&&i!==void 0&&o+1>=i)break;W(o,t,a[n],r)}}function Ne(e,t,n,r,i){let a=r===`actor`?jr:[],o=[...a,...Q(n)],s=Math.max(Mt(n),a.length>0?Mr:0),c=s+2*S+2,h=i,g=h-2,_=e-Math.floor(c/2);W(_,t,d,`border`);for(let e=1;e<c-1;e++)W(_+e,t,l,`border`);W(_+c-1,t,f,`border`);for(let e=0;e<g;e++){let n=t+1+e;W(_,n,u,`border`),W(_+c-1,n,u,`border`);let r=o[e];r!==void 0&&G(_+1+S+Math.floor((s-M(r))/2),n,r,`text`)}let v=t+h-1;W(_,v,p,`border`);for(let e=1;e<c-1;e++)W(_+e,v,l,`border`);W(_+c-1,v,m,`border`)}let Pe=e=>{let t=j.get(e);return t===void 0?Ee:t+O},Fe=e=>re.get(e)??ke;for(let e=0;e<s.actors.length;e++){let t=B[e];for(let n=Pe(e);n<=Fe(e);n++)W(t,n,u,`line`)}let Ie=c?`+`:`┼`;function Le(e,t,n){let r=_e(e),i=ve(e),a=t+O+1;W(r,t,d,`border`),W(i,t,f,`border`),W(r,a,p,`border`),W(i,a,m,`border`);for(let e=r+1;e<i;e++)W(e,t,l,`border`),W(e,a,l,`border`);for(let e=t+1;e<a;e++)W(r,e,u,`border`),W(i,e,u,`border`);n!==``&&G(r+2,t,` ${Q(n)[0]} `,`text`);for(let n=e.lo;n<=e.hi;n++){let e=B[n];Pe(n)<=t&&t<=Fe(n)&&W(e,t,Ie,`junction`),Pe(n)<=a&&a<=Fe(n)&&W(e,a,Ie,`junction`)}}for(let e of ie)Le(e,0,e.label),Le(e,ke,``);for(let e=0;e<s.actors.length;e++){let t=s.actors[e],n=j.get(e)??Te,r=re.has(e);Ne(B[e],n,t.label,t.type,O),r||Ne(B[e],Ae,t.label,t.type,O),c||(W(B[e],n+O-1,h,`junction`),r||W(B[e],Ae,g,`junction`))}for(let e=0;e<s.messages.length;e++){let t=s.messages[e],n=b(t.from),r=b(t.to),i=B[n],a=B[r],o=n===r,d=t.lineStyle===`dashed`,f=t.arrowHead===`filled`,p=t.isLost===!0,m=c?`x`:`✕`,h=d?c?`.`:`╌`:l;if(o){let n=ye[e],r=Pr(t),a=t.seqNumber===void 0?void 0:String(t.seqNumber),o=Q(t.label);W(i,n,_,`junction`);let s=i+1;if(a!==void 0){for(let e=0;e<a.length;e++)W(i+1+e,n,a[e],`text`);s=i+1+a.length}for(let e=s;e<i+r;e++)W(e,n,h,`line`);W(i+r,n,c?`+`:`┐`,`corner`);let l=i+r+2;for(let e=0;e<o.length;e++){let t=n+1+e;W(i+r,t,u,`line`),G(l,t,o[e],`text`,H)}let d=n+1+o.length;W(i,d,p?m:f?c?`<`:`◀`:c?`<`:`◁`,`arrow`);for(let e=i+1;e<i+r;e++)W(e,d,h,`line`);W(i+r,d,c?`+`:`┘`,`corner`)}else{let n=be[e],o=ye[e],s=i<a,l=ne.get(e)===r,u=a;if(l){let e=ee(r,a),t=e+T[r]-1;u=s?e-1:t+1}let d=Math.floor((i+a)/2),g=Q(t.label);for(let e=0;e<g.length;e++){let t=g[e];G(d-Math.floor(M(t)/2),n+e,t,`text`,H)}if(s){for(let e=i+1;e<u;e++)W(e,o,h,`line`);W(u,o,p?m:f?c?`>`:`▶`:c?`>`:`▷`,`arrow`),t.bidirectional&&W(i,o,c?`<`:`◀`,`arrow`)}else{for(let e=u+1;e<i;e++)W(e,o,h,`line`);W(u,o,p?m:f?c?`<`:`◀`:c?`<`:`◁`,`arrow`),t.bidirectional&&W(i,o,c?`>`:`▶`,`arrow`)}if(t.seqNumber!==void 0){let e=String(t.seqNumber);if(s){let t=i+1;if(t+e.length<a)for(let n=0;n<e.length;n++)W(t+n,o,e[n],`text`)}else{let t=i-e.length;if(t>u)for(let n=0;n<e.length;n++)W(t+n,o,e[n],`text`)}}}}for(let[e,t]of re)W(B[e],t,c?`x`:`✕`,`arrow`);let Re=H-1;for(let e=0;e<s.blocks.length;e++){let t=s.blocks[e],n=xe.get(e),r=Se.get(e);if(n===void 0||r===void 0)continue;let i=H,a=0;for(let e=t.startIndex;e<=t.endIndex&&!(e>=s.messages.length);e++){let t=s.messages[e],n=y.get(t.from)??0,r=y.get(t.to)??0;if(i=Math.min(i,B[Math.min(n,r)]),a=Math.max(a,B[Math.max(n,r)]),n===r){let e=B[n]+Pr(t)+2+Mt(t.label);a=Math.max(a,e)}}let o=i-Nr,c=a+Nr,h=1/0,g=-1/0;for(let e of B)e>a&&e<h&&(h=e),e<i&&e>g&&(g=e);c>=h&&(c=Math.max(a,h-Nr)),o<=g&&(o=Math.min(i,g+Nr)),o=Math.max(0,o),c>Re&&(se(Me,c+1,je-1),oe(U,c+1,je-1),Re=c);let b=t.label?`${t.type} [${t.label}]`:t.type,S=o+1+x(t);if(S>c){c=S;let[e]=L(Me);c>e&&(se(Me,c,je-1),oe(U,c,je-1)),H=Math.max(H,c+1),Re=Math.max(Re,c)}W(o,n,d,`border`);for(let e=o+1;e<c;e++)W(e,n,l,`border`);W(c,n,f,`border`);let C=Q(b);for(let e=0;e<C.length&&n+e<r;e++)G(o+1,n+e,C[e],`text`,c);W(o,r,p,`border`);for(let e=o+1;e<c;e++)W(e,r,l,`border`);W(c,r,m,`border`);for(let e=n+1;e<r;e++)W(o,e,u,`border`),W(c,e,u,`border`);for(let n=0;n<t.dividers.length;n++){let r=Ce.get(`${e}:${n}`);if(r===void 0)continue;let i=K();W(o,r,_,`junction`);for(let e=o+1;e<c;e++)W(e,r,i,`line`);W(c,r,v,`junction`);let a=t.dividers[n].label;if(a){let e=`[${a}]`;G(o+1,r,e,`text`,c)}}}for(let e of we){se(Me,e.x+e.width,e.y+e.height),oe(U,e.x+e.width,e.y+e.height),W(e.x,e.y,d,`border`);for(let t=1;t<e.width-1;t++)W(e.x+t,e.y,l,`border`);W(e.x+e.width-1,e.y,f,`border`);for(let t=0;t<e.lines.length;t++){let n=e.y+1+t;W(e.x,n,u,`border`),W(e.x+e.width-1,n,u,`border`);for(let t=e.x+1;t<e.x+e.width-1;t++)W(t,n,` `,`text`);G(e.x+1+S,n,e.lines[t],`text`)}let t=e.y+e.height-1;W(e.x,t,p,`border`);for(let n=1;n<e.width-1;n++)W(e.x+n,t,l,`border`);W(e.x+e.width-1,t,m,`border`)}return me(Me,{roleCanvas:U,colorMode:i,theme:a});function K(){return c?`-`:`╌`}}function Ir(e,t){return e.rowStart<=t.rowEnd&&t.rowStart<=e.rowEnd}function Lr(e,t){let n=e.map(e=>({item:e,geom:t(e)})).sort((e,t)=>e.geom.idealMid-t.geom.idealMid),r=(e,t)=>{let r=n[e];if(r)for(let i=e+t;i>=0&&i<n.length;i+=t){let e=n[i];if(e&&Ir(e.geom,r.geom))return e.geom}},i=new Map;for(let[e,t]of n.entries()){let n=t.geom,a=r(e,-1),o=r(e,1),s=a&&a.end>=n.start?Math.floor((a.idealMid+n.idealMid)/2)+1:-1/0,c=o&&n.end>=o.start?Math.floor((n.idealMid+o.idealMid)/2):1/0;i.set(t.item,{left:s,right:c})}return i}function Rr(e){let n=[];e.annotation&&n.push(`<<${e.annotation}>>`);let r=Q(e.label);n.push(...r);let i=e.attributes.map(t.formatClassMember),a=e.methods.map(t.formatClassMember),o=[n];return i.length>0&&o.push(i),a.length>0&&o.push(a),o}function zr(e,t){return{type:e,markerAt:t,dashed:e===`dependency`||e===`realization`}}function Br(e,t,n){switch(e){case`inheritance`:case`realization`:return n===`down`?t?`^`:`△`:n===`up`?t?`v`:`▽`:n===`left`?t?`>`:`◁`:t?`<`:`▷`;case`composition`:return t?`*`:`◆`;case`aggregation`:return t?`o`:`◇`;case`association`:case`dependency`:return n===`down`?t?`v`:`▼`:n===`up`?t?`^`:`▲`:n===`left`?t?`<`:`◀`:t?`>`:`▶`}}function Vr(e,t,n,r,i){let a=e+t.length-1,o=r>e,s=i<a;if(!o&&!s)return{start:e,cells:t};let c=o?r:e,l=Math.max(0,(s?i:a)-c+1),u=+!!o+ +!!s;if(l===0)return{start:c,cells:[]};if(l<u)return{start:c,cells:[`…`]};let d=Math.max(0,l-u),f=ae(n),p=f.length<=d?f:o&&!s?f.slice(f.length-d):f.slice(0,d),m=[...o?[`…`]:[],...p,...s?[`…`]:[]];return{start:c+Math.max(0,Math.floor((l-m.length)/2)),cells:m}}function Hr(e){return Math.max(...Q(e).map(e=>M(e)))+2}function Ur(n,r,i,a,o={}){let c=(0,e.splitStatements)(n),{diagram:l,notesById:d}=Wr((0,t.parseClassDiagram)(c));if(l.classes.length===0)return``;let f=r.useAscii,p=Ke(r.paddingX,5,4,1),m=Ke(r.paddingY,5,3,1),h=new Map,g=new Map,_=new Map;for(let e of l.classes){let t=Rr(e);h.set(e.id,t);let{width:n,height:i}=gr(t,r.boxBorderPadding);g.set(e.id,n),_.set(e.id,i)}let v=new Map;for(let e of l.classes)v.set(e.id,e);let y=new Map,b=new Map;for(let e of l.relationships){let t=e.from,n=e.to,r=y.get(n)??new Set;y.set(n,r),r.add(t);let i=b.get(t)??new Set;b.set(t,i),i.add(n)}let x=new Map,S=l.classes.filter(e=>!y.has(e.id)||y.get(e.id).size===0).map(e=>e.id);for(let e of S)x.set(e,0);let C=l.classes.length-1,w=0;for(;w<S.length;){let e=S[w++],t=b.get(e);if(t)for(let n of t){let t=(x.get(e)??0)+1;t>C||(!x.has(n)||x.get(n)<t)&&(x.set(n,t),S.push(n))}}for(let e of l.classes)x.has(e.id)||x.set(e.id,0);Gr(d,x);let T=Math.max(...x.values(),0),E=Array.from({length:T+1},()=>[]);for(let e of l.classes)E[x.get(e.id)].push(e.id);let D=new Map,O=new Map;{let e=new Map;l.relationships.forEach((t,n)=>{let r=[t.from,t.to].sort().join(`::`),i=e.get(r)??[];i.push(n),e.set(r,i)});for(let t of e.values()){if(t.length<2)continue;let e=t.length,n=Math.max(...t.map(e=>{let t=l.relationships[e].label;return t?Hr(t):3}))+1;t.forEach((t,r)=>{D.set(t,Math.round((r-(e-1)/2)*n)),O.set(t,(e-1)*n)})}}let ee=new Map,k=new Map,te=new Map,ne=new Map;{let e=(e,t,n)=>{let r=new Map;l.relationships.forEach((t,n)=>{if(D.has(n)||!v.has(t.from)||!v.has(t.to))return;let i=x.get(t.from)??0;if((x.get(t.to)??0)-i!==1)return;let a=e(t),o=r.get(a)??[];o.push(n),r.set(a,o)});for(let e of r.values()){if(e.length<2)continue;let r=e.length,i=Math.max(...e.map(e=>{let t=l.relationships[e].label;return t?Hr(t):3}))+1;e.forEach((e,a)=>{t.set(e,Math.round((a-(r-1)/2)*i)),n.set(e,(r-1)*i)})}};e(e=>e.to,te,ne),e(e=>e.from,ee,k)}let A=new Map;for(let e of l.classes)A.set(e.id,{left:0,right:0});l.relationships.forEach((e,t)=>{if(!v.has(e.from)||!v.has(e.to))return;let n=e.label?Hr(e.label):1,r=D.get(t)??ee.get(t)??0,i=D.get(t)??te.get(t)??0,a=A.get(e.from);a.left=Math.max(a.left,Math.floor(n/2)-r),a.right=Math.max(a.right,r+n-1-Math.floor(n/2));let o=A.get(e.to);o.left=Math.max(o.left,Math.floor(n/2)-i),o.right=Math.max(o.right,i+n-1-Math.floor(n/2))});let j=new Map,re=0,ie=0;for(let e=0;e<=T;e++){let t=E[e];if(t.length===0)continue;let n=e=>{let t=y.get(e);return t&&t.size>0?[...t].sort().join(`,`):`root:${e}`},r=new Map;for(let e of t){let t=n(e),i=r.get(t);i||(i=[],r.set(t,i)),i.push(e)}let i=new Map,a=new Map,o=new Map;{let e=0;for(let n of t){let t=g.get(n),r=A.get(n),s=Math.max(0,r.left-Math.floor(t/2)),c=Math.max(0,r.right-(t-1-Math.floor(t/2)));i.set(n,e),a.set(n,s+t+c),o.set(n,s),e+=s+t+c+p}}let s=0,c=0,l=(e,t)=>{let n=v.get(e),r=g.get(e),i=_.get(e),l=o.get(e),u=a.get(e);j.set(e,{cls:n,sections:h.get(e),x:t+l,y:re,width:r,height:i}),ie=Math.max(ie,t+u),s=t+u+p,c=Math.max(c,i)},u=new Set;for(let c of t){if(u.has(c))continue;let t=n(c),d=y.get(c),f=d?[...d].filter(t=>x.get(t)<e):[];if(f.length===0){l(c,Math.max(i.get(c),s,0)),u.add(c);continue}let m=r.get(t),h=f.map(e=>{let t=j.get(e);return t.x+Math.floor(t.width/2)}),_=Math.round(h.reduce((e,t)=>e+t,0)/h.length),v=0;for(let e=0;e<m.length;e++)v+=a.get(m[e]),e<m.length-1&&(v+=p);let b=o.get(m[0]),S=m[m.length-1],C=a.get(S)-o.get(S)-g.get(S),w=v-b-C,T=_-b-Math.floor(w/2),E=Math.max(T,s,0);for(let e of m)l(e,E),u.add(e),E=s}re+=c+m}let P=ie,I=0;for(let e of j.values())P=Math.max(P,e.x+e.width),I=Math.max(I,e.y+e.height);P+=4,I+=2;let L=N(P-1,I-1),ce=F(P-1,I-1);function ue(e,t,n,r){R(L,e,t,n,{role:r,roleCanvas:ce})}let de=o.hyperlinks?s(P-1,I-1):void 0;for(let t of j.values()){let n=_r(t.sections,f,r.boxBorderPadding);for(let e=0;e<n.length;e++)for(let r=0;r<n[0].length;r++){let i=n[e][r];if(i!==` `){let n=t.x+e,a=t.y+r;n<P&&a<I&&ue(n,a,i,hr(i))}}if(de){let r=(0,e.safeHref)(l.interactions.get(t.cls.id)?.href),i=t.sections[0];if(r!==void 0&&i!==void 0){let e=1+ +!!t.cls.annotation;u(de,n,{x:t.x,y:t.y},r,{from:e,to:i.length})}}}let pe=new Set;for(let e of j.values())for(let t=0;t<e.height;t++)for(let n=0;n<e.width;n++)pe.add(`${e.x+n},${e.y+t}`);function z(e,t,n,r){pe.has(`${e},${t}`)||ue(e,t,n,r)}function he(e,t,n){for(let[r,i]of j.entries())if(!n?.has(r)&&e>=i.x&&e<=i.x+i.width-1&&t>=i.y&&t<=i.y+i.height-1)return!0;return!1}function ge(e,t,n,r){return Cr(e,0,e+P+9,e=>{for(let i=Math.min(t,n);i<=Math.max(t,n);i++)if(he(e,i,r))return!1;return!0})??P+2}let B=f?`-`:`─`,_e=f?`|`:`│`,ve=f?`.`:`╌`,ye=f?`:`:`┊`;function be(e,t,n){let r=Math.floor(n/2),i=n-1-r,a=t>r+i?(r+i)/t:1;return Math.max(-r,Math.min(i,Math.round(e*a)))}function xe(e,t,n){let r=D.get(e)??ee.get(e)??0,i=D.get(e)??te.get(e)??0,a=O.get(e)??k.get(e)??0,o=O.get(e)??ne.get(e)??0,s=t.x+Math.floor(t.width/2),c=n.x+Math.floor(n.width/2);return{fromCX:s+r,toCX:c+i,fromAnchorX:s+be(r,a,t.width),toAnchorX:c+be(i,o,n.width)}}function Se(e,t,n,r){if(pe.has(`${e},${t}`)||ce[e]?.[t]===`arrow`)return;let i=L[e]?.[t];if(!f&&i!==void 0&&le(i)&&le(n)){let a=fe(i,n);ue(e,t,a,a===n?r:`junction`);return}ue(e,t,n,r)}function Ce(e,t,n,r,i){if(t===n)return;let a=Math.min(t,n),o=Math.max(t,n);for(let t=a+1;t<o;t++)Se(t,e,r,`line`);if(f){Se(t,e,r,`line`),Se(n,e,r,`line`);return}let s=n>t,c=i?s?`└`:`┘`:s?`┌`:`┐`,l=i?s?`┐`:`┌`:s?`┘`:`└`;Se(t,e,c,`corner`),Se(n,e,l,`corner`)}let we=new Map,Te=new Map;l.relationships.forEach((e,t)=>{let n=j.get(e.from),r=j.get(e.to);if(!n||!r)return;let i=zr(e.type,e.markerAt),a=i.dashed?ve:B,o=i.dashed?ye:_e,s=new Set([e.from,e.to]),{fromCX:c,toCX:l,fromAnchorX:u,toAnchorX:d}=xe(t,n,r),p=n.y+n.height-1,m=r.y;if(p<m){let e=ge(c,p+1,m-1,s),n=e!==c;if(e>=P&&se(L,e+2,I),n){let n=p+1,r=m-1;we.set(t,{routeX:e,exitY:n,entryY:r,fromAnchorX:u,toAnchorX:d,clearSide:e>c?`right`:`left`});let s=Math.min(u,e),l=Math.max(u,e);for(let e=s;e<=l;e++)z(e,n,a,`line`);!f&&n<(L[0]?.length??0)&&(u<e?(z(u,n,`└`,`corner`),z(e,n,`┐`,`corner`)):(z(u,n,`┘`,`corner`),z(e,n,`┌`,`corner`)));for(let t=n+1;t<=r;t++)z(e,t,o,`line`);if(e!==d){let t=Math.min(e,d),n=Math.max(e,d);for(let e=t;e<=n;e++)z(e,r,a,`line`);!f&&r<(L[0]?.length??0)&&(e<d?(z(e,r,`└`,`corner`),z(d,r,`┐`,`corner`)):(z(e,r,`┘`,`corner`),z(d,r,`┌`,`corner`)))}if(i.markerAt===`to`){let e=i.type===`inheritance`||i.type===`realization`;z(d,r,Br(i.type,f,e?`up`:`down`),`arrow`)}if(i.markerAt===`from`){let e=Br(i.type,f,`down`);z(u,p+1,e,`arrow`)}}else{let e=p+Math.floor((m-p)/2),t=c!==u,n=l!==d;Ce(p+1,u,c,a,!0);for(let n=p+(t?2:1);n<=e;n++)z(c,n,o,`line`);if(c!==l&&e<(L[0]?.length??0)){let t=Math.min(c,l),n=Math.max(c,l);for(let r=t;r<=n;r++)z(r,e,a,`line`);f||(z(c,e,c<l?`└`:`┘`,`corner`),z(l,e,c<l?`┐`:`┌`,`corner`))}for(let t=e+1;t<m-+!!n;t++)z(l,t,o,`line`);if(Ce(m-1,d,l,a,!1),i.markerAt===`to`){let e=i.type===`inheritance`||i.type===`realization`;z(d,m-1,Br(i.type,f,e?`up`:`down`),`arrow`)}i.markerAt===`from`&&z(u,p+1,Br(i.type,f,`down`),`arrow`)}}else if(r.y+r.height-1<n.y){let e=n.y,t=r.y+r.height-1,s=t+Math.floor((e-t)/2),p=c!==u,m=l!==d;Ce(e-1,u,c,a,!1);for(let t=e-(p?2:1);t>=s;t--)z(c,t,o,`line`);if(c!==l){let e=Math.min(c,l),t=Math.max(c,l);for(let n=e;n<=t;n++)z(n,s,a,`line`);!f&&s>=0&&s<I&&(z(c,s,c<l?`┌`:`┐`,`corner`),z(l,s,c<l?`┘`:`└`,`corner`))}for(let e=s-1;e>t+ +!!m;e--)z(l,e,o,`line`);if(Ce(t+1,d,l,a,!0),i.markerAt===`from`){let t=Br(i.type,f,`up`),n=e-1;for(let e=0;e<t.length;e++)z(u-Math.floor(t.length/2)+e,n,t[e],`arrow`)}if(i.markerAt===`to`){let e=i.type===`inheritance`||i.type===`realization`?`down`:`up`,n=Br(i.type,f,e),r=t+1;for(let e=0;e<n.length;e++)z(d-Math.floor(n.length/2)+e,r,n[e],`arrow`)}}else{let s=r.y+r.height-1,m=Math.min(c,l),h=Math.max(c,l),g=Math.max(p,s);for(let[t,r]of j.entries())t!==e.from&&t!==e.to&&r.y===n.y&&r.x<h+1&&r.x+r.width>m&&(g=Math.max(g,r.y+r.height-1));let _=g+2;Te.set(t,_),se(L,P,_+1),oe(ce,P,_+1);let v=c!==u,y=l!==d;Ce(p+1,u,c,a,!0);for(let e=p+(v?2:1);e<=_;e++)z(c,e,o,`line`);for(let e=m;e<=h;e++)z(e,_,a,`line`);for(let e=_-1;e>=s+(y?2:1);e--)z(l,e,o,`line`);if(Ce(s+1,d,l,a,!0),i.markerAt===`from`){let e=Br(i.type,f,`down`),t=p+1;for(let n=0;n<e.length;n++)z(u-Math.floor(e.length/2)+n,t,e[n],`arrow`)}if(i.markerAt===`to`){let e=i.type===`inheritance`||i.type===`realization`,t=Br(i.type,f,e?`down`:`up`),n=r.y+r.height;for(let e=0;e<t.length;e++)z(d-Math.floor(t.length/2)+e,n,t[e],`arrow`)}}});function Ee(e,t,n,r){let{fromCX:i,toCX:a}=xe(e,t,n),o=t.y+t.height-1,s=n.y;if(o<s){let t=we.get(e);if(t){let e=t.exitY+1,n=t.entryY;if(n>=e)return{idealMidX:t.clearSide===`right`?t.routeX+1+Math.floor(r/2):t.routeX-1-Math.ceil(r/2),baseMidY:Math.floor((e+n)/2)};let i=Math.abs(t.routeX-t.fromAnchorX);return Math.abs(t.toAnchorX-t.routeX)>=i?{idealMidX:Math.floor((t.routeX+t.toAnchorX)/2),baseMidY:t.entryY}:{idealMidX:Math.floor((t.fromAnchorX+t.routeX)/2),baseMidY:t.exitY}}return{idealMidX:Math.floor((i+a)/2),baseMidY:Math.floor((o+1+s-1)/2)}}if(n.y+n.height-1<t.y){let e=n.y+n.height-1;return{idealMidX:Math.floor((i+a)/2),baseMidY:Math.floor((e+1+t.y-1)/2)}}return{idealMidX:Math.floor((i+a)/2),baseMidY:Te.get(e)??Math.max(o,n.y+n.height-1)+2}}function V(e,t,n,r,i,a,o){let s=r,c=Math.floor(a/2),l=e.y+e.height-1,u=t.y,d=!1;for(let e=0;e<a;e++){let t=s-c+e,r=n-Math.floor(i/2),a=Math.max(0,r);for(let e=a;e<a+i;e++)if(he(e,t,o)){d=!0;break}if(d)break}if(d){let e=l+1,t=u-1;for(let r=e;r<=t;r++){let e=!0,t=n-Math.floor(i/2),a=Math.max(0,t);for(let t=a;t<a+i;t++)if(he(t,r,o)){e=!1;break}if(e){s=r;break}}}return s}let De=new Map,Oe=[];for(let[e,t]of l.relationships.entries()){if(!t.label)continue;let n=j.get(t.from),r=j.get(t.to);if(!n||!r)continue;let i=Q(t.label),a=Math.floor(i.length/2),o=Math.max(...i.map(M))+2,{idealMidX:s,baseMidY:c}=Ee(e,n,r,o),l=new Set([t.from,t.to]),u=V(n,r,s,c,o,i.length,l);De.set(t,u);let d=Math.max(0,s-Math.floor(o/2));Oe.push({rel:t,idealMidX:s,naturalStart:d,naturalEnd:d+o-1,rowStart:u-a,rowEnd:u+a})}let ke=Lr(Oe,e=>({idealMid:e.idealMidX,start:e.naturalStart,end:e.naturalEnd,rowStart:e.rowStart,rowEnd:e.rowEnd})),Ae=new Map;for(let e of Oe){let t=ke.get(e);t&&Ae.set(e.rel,t)}for(let[e,t]of l.relationships.entries()){let n=j.get(t.from),r=j.get(t.to);if(!(!n||!r)&&t.label){let i=Q(t.label),{idealMidX:a}=Ee(e,n,r,Math.max(...i.map(e=>M(e)))+2),o=De.get(t)-Math.floor(i.length/2),s=Ae.get(t);for(let e=0;e<i.length;e++){let t=o+e,n=i[e],r=ae(` ${n} `),{start:c,cells:l}=Vr(Math.max(0,a-Math.floor(r.length/2)),r,n,Math.max(0,s.left),s.right),u=c+l.length;u>0&&t>=0&&(se(L,Math.max(u,1),Math.max(t+1,1)),oe(ce,Math.max(u,1),Math.max(t+1,1)));for(let e=0;e<l.length;e++){let n=c+e;n>=0&&t>=0&&ue(n,t,l[e],`text`)}}}}return Kr(d,j,L,f,ue),me(L,{roleCanvas:ce,colorMode:i,theme:a,linkCanvas:de})}function Wr(e){let t=new Map;if(e.notes.length===0)return{diagram:e,notesById:t};let n=(e,n)=>{let r=`note ${e}`;return t.set(r,n),{id:r,label:n.text,attributes:[],methods:[]}},r=new Set(e.classes.map(e=>e.id)),i=[];for(let t of e.classes){i.push(t);for(let[r,a]of e.notes.entries())a.forClass===t.id&&i.push(n(r,a))}for(let[t,a]of e.notes.entries())(a.forClass===void 0||!r.has(a.forClass))&&i.push(n(t,a));return{diagram:{...e,classes:i},notesById:t}}function Gr(e,t){for(let[n,r]of e){if(r.forClass===void 0)continue;let e=t.get(r.forClass);e!==void 0&&t.set(n,e)}}function Kr(e,t,n,r,i){if(e.size===0)return;let a=Ft(`rounded`,r),o=r?`.`:`╌`;for(let[r,s]of e){let e=t.get(r);if(!e)continue;let c=e.x+e.width-1,l=e.y+e.height-1;if(i(e.x,e.y,a.tl,`border`),i(c,e.y,a.tr,`border`),i(e.x,l,a.bl,`border`),i(c,l,a.br,`border`),s.forClass===void 0)continue;let u=t.get(s.forClass);if(!u||u.x+u.width>e.x||u.y!==e.y)continue;let d=u.y+1;for(let t=u.x+u.width;t<e.x;t++)n[t]?.[d]===` `&&i(t,d,o,`line`)}}function qr(e){let t=e.trim();return t.length>=2&&(t[0]===`"`&&t[t.length-1]===`"`||t[0]===`'`&&t[t.length-1]===`'`)?t.slice(1,-1):t}var Jr=`"graph <dir>"/"flowchart <dir>" (dir: TD, TB, LR, BT, RL), "stateDiagram-v2", "sequenceDiagram", "classDiagram", "erDiagram", "xychart-beta"`;function Yr(e){let t=e.trim().toLowerCase();if(/^sequence/.test(t))return`sequenceDiagram`;if(/^class/.test(t))return`classDiagram`;if(/^er/.test(t))return`erDiagram`;if(/^xychart/.test(t))return`xychart-beta`;if(/^state/.test(t))return`stateDiagram-v2`}var Xr=/^(?:[\w-]+@)?<?(?:-{2,}|={2,}|-\.+-?|~{3,})/;function Zr(e){let t=[];for(let n of e)n.forEach((e,n)=>{if(n===0&&t.length>0&&Xr.test(e.text)){let n=t[t.length-1];t[t.length-1]={text:`${n.text} ${e.text}`,line:n.line}}else t.push(e)});return t}function Qr(t){let n=(0,e.extractInitConfig)(t.split(`
5
- `).map(e=>e.trim())),r=Zr((0,e.splitStatementsByLine)(t));if(r.length===0)throw Error(`Empty mermaid diagram`);let i=r[0],a=/^stateDiagram(-v2)?\s*$/i.test(i.text)?ei(r):$r(r);return a.initConfig=n,a}function $r(t){let n=t[0];if(n===void 0)throw Error(`parseFlowchart called with no lines`);let r=n.text,i=r.match(/^(?:graph|flowchart)\s+(TD|TB|LR|BT|RL)\s*$/i);if(!i){let e=r.match(/^(?:graph|flowchart)\b\s*(.*)$/i);if(e){let t=e[1].trim();throw Error(t.length>0?`Line ${n.line}: Invalid direction "${t}" in header "${r}". Expected one of: TD, TB, LR, BT, RL.`:`Line ${n.line}: Missing direction in header "${r}". Expected e.g. "graph TD" or "flowchart LR" — one of: TD, TB, LR, BT, RL.`)}let t=Yr(r),i=t&&t.toLowerCase()!==r.trim().toLowerCase()?` Did you mean "${t}"?`:``;throw Error(`Line ${n.line}: Invalid mermaid header: "${r}".${i} Supported headers: ${Jr}.`)}let a={direction:(0,e.toDirection)(i[1]),nodes:new Map,edges:[],subgraphs:[],classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,linkStyles:new Map,interactions:new Map},o=[];for(let n=1;n<t.length;n++){let r=t[n].text;if((0,e.tryApplyClassDef)(r,a)||(0,e.tryApplyClassAssignment)(r,a)||(0,e.tryApplyStyleStatement)(r,a))continue;if(/^click\s+/i.test(r)){fi(r,a);continue}if(mi(r,a))continue;let i=r.match(/^linkStyle\s+(default|[\d,\s]+)\s+(.+)$/);if(i){let t=i[1].trim(),n=(0,e.parseStyleProps)(i[2]);if(t==="default")a.linkStyles.set(`default`,{...a.linkStyles.get(`default`),...n});else{let e=t.split(`,`).map(e=>parseInt(e.trim(),10));for(let t of e)isNaN(t)||a.linkStyles.set(t,{...a.linkStyles.get(t),...n})}continue}let s=r.match(/^direction\s+(TD|TB|LR|BT|RL)\s*$/i);if(s&&o.length>0){o[o.length-1].direction=(0,e.toDirection)(s[1]);continue}let c=r.match(/^subgraph\s+(.+)$/);if(c){let t=c[1].trim(),n=t.match(/^([^\s[]+)\s*\[(.+)\]$/),r,i;n?(r=n[1],i=(0,e.normalizeBrTags)(qr(n[2]))):(i=(0,e.normalizeBrTags)(qr(t)),r=i.replace(/\s+/g,`_`).replace(/[^\p{L}\p{N}_-]/gu,``));let a={id:r,label:i,nodeIds:[],children:[]};o.push(a);continue}if(r===`end`){let e=o.pop();e&&(o.length>0?o[o.length-1].children.push(e):a.subgraphs.push(e));continue}vi(r,a,o)}return a}function ei(t){let n={direction:`TD`,nodes:new Map,edges:[],subgraphs:[],classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,linkStyles:new Map,interactions:new Map},r=[],i=new Set,a=0,o=0;for(let s=1;s<t.length;s++){let c=t[s].text,l=c.match(/^direction\s+(TD|TB|LR|BT|RL)\s*$/i);if(l){r.length>0?r[r.length-1].direction=(0,e.toDirection)(l[1]):n.direction=(0,e.toDirection)(l[1]);continue}let u=c.match(/^linkStyle\s+(default|[\d,\s]+)\s+(.+)$/);if(u){let t=u[1].trim(),r=(0,e.parseStyleProps)(u[2]);if(t==="default")n.linkStyles.set(`default`,{...n.linkStyles.get(`default`),...r});else{let e=t.split(`,`).map(e=>parseInt(e.trim(),10));for(let t of e)isNaN(t)||n.linkStyles.set(t,{...n.linkStyles.get(t),...r})}continue}if(mi(c,n))continue;let d=c.match(/^state\s+(?:"([^"]+)"\s+as\s+)?([\w\p{L}]+)\s*\{$/u);if(d){let e=d[1]??d[2],t=d[2],a={id:t,label:e,nodeIds:[],children:[]};r.push(a),i.add(t),n.nodes.delete(t);continue}if(c===`}`){let e=r.pop();e&&(r.length>0?r[r.length-1].children.push(e):n.subgraphs.push(e));continue}let f=c.match(/^state\s+"([^"]+)"\s+as\s+([\w\p{L}]+)\s*$/u);if(f){let t=(0,e.normalizeBrTags)(f[1]),i=f[2];ti(n,r,{id:i,label:t,shape:`rounded`});continue}let p=c.match(/^(\[\*\]|[\w\p{L}-]+)\s*(?:([\w-]+)@)?-->\s*(\[\*\]|[\w\p{L}-]+)(?:\s*:\s*(.+))?$/u);if(p){let t=p[1],s=p[2],c=p[3],l=p[4]?.trim(),u=l?(0,e.normalizeBrTags)(l):void 0;t===`[*]`?(a++,t=`_start${a>1?a:``}`,ti(n,r,{id:t,label:``,shape:`state-start`})):i.has(t)||ni(n,r,t),c===`[*]`?(o++,c=`_end${o>1?o:``}`,ti(n,r,{id:c,label:``,shape:`state-end`})):i.has(c)||ni(n,r,c),n.edges.push({source:t,target:c,label:u,style:`solid`,hasArrowStart:!1,hasArrowEnd:!0,...s===void 0?{}:{id:s}});continue}let m=c.match(/^([\w\p{L}-]+)\s*:\s*(.+)$/u);if(m){let t=m[1];ti(n,r,{id:t,label:(0,e.normalizeBrTags)(m[2].trim()),shape:`rounded`});continue}}return n}function ti(e,t,n){if(e.nodes.has(n.id)||e.nodes.set(n.id,n),t.length>0){let e=t[t.length-1];e.nodeIds.includes(n.id)||e.nodeIds.push(n.id)}}function ni(e,t,n){if(!e.nodes.has(n))ti(e,t,{id:n,label:n,shape:`rounded`});else if(t.length>0){let e=t[t.length-1];e.nodeIds.includes(n)||e.nodeIds.push(n)}}var ri=/^(<|o|x)?(-{2,}|={2,}|-\.+-|~{3,})(>|o|x)?(?:\|([^|]*)\|)?/,ii=new Set([`--`,`==`]);function ai(e){if(e===`o`)return`circle`;if(e===`x`)return`cross`}var oi=/^(<|o|x)?(--|-\.|==)\s+(.+?)\s+(-{2,}[>ox]|={2,}[>ox]|\.+-[>ox]|-{3,}|={3,}|-\.+-)/,si=[{regex:/^([\w\p{L}-]+)\(\(\(((?:"[^"]*"|(?!\)\)\)).)+)\)\)\)/u,shape:`doublecircle`},{regex:/^([\w\p{L}-]+)\(\[((?:"[^"]*"|(?!\]\)).)+)\]\)/u,shape:`stadium`},{regex:/^([\w\p{L}-]+)\(\(((?:"[^"]*"|(?!\)\)).)+)\)\)/u,shape:`circle`},{regex:/^([\w\p{L}-]+)\[\[((?:"[^"]*"|(?!\]\]).)+)\]\]/u,shape:`subroutine`},{regex:/^([\w\p{L}-]+)\[\(((?:"[^"]*"|(?!\)\]).)+)\)\]/u,shape:`cylinder`},{regex:/^([\w\p{L}-]+)\[\/((?:"[^"]*"|(?![\\/]\]).)+)([\\/])\]/u,shape:e=>e===`\\`?`trapezoid`:`parallelogram`},{regex:/^([\w\p{L}-]+)\[\\((?:"[^"]*"|(?![\\/]\]).)+)([\\/])\]/u,shape:e=>e===`/`?`trapezoid-alt`:`parallelogram-alt`},{regex:/^([\w\p{L}-]+)>((?:"[^"]*"|(?!\]).)+)\]/u,shape:`asymmetric`},{regex:/^([\w\p{L}-]+)\{\{((?:"[^"]*"|(?!\}\}).)+)\}\}/u,shape:`hexagon`},{regex:/^([\w\p{L}-]+)\[((?:"[^"]*"|(?!\]).)+)\]/u,shape:`rectangle`},{regex:/^([\w\p{L}-]+)\(((?:"[^"]*"|(?!\)).)+)\)/u,shape:`rounded`},{regex:/^([\w\p{L}-]+)\{((?:"[^"]*"|(?!\}).)+)\}/u,shape:`diamond`}],ci=/^([\w\p{L}]+(?:-[\w\p{L}]+)*)/u,li=/^([\w\p{L}-]+)(?=@\{)/u;function ui(e){if(e.shape)return(0,t.resolveShapeName)(e.shape)??`rectangle`;if(e.icon!==void 0||e.img!==void 0)switch(e.form?.toLowerCase()){case`circle`:return`circle`;case`rounded`:return`rounded`;default:return`rectangle`}return`rectangle`}function di(e,t){return t.label!==void 0&&t.label.length>0?t.label:t.icon?t.icon:t.img?t.img:e}function fi(t,n){(0,e.applyClickStatement)(t,n.interactions)}var pi=/^([\w-]+)(?=@\{)/;function mi(e,n){let r=e.match(pi);if(!r||!n.edges.some(e=>e.id===r[1]))return!1;let i=(0,t.matchExpandedBlock)(e.slice(r[1].length));return i?(hi(n,r[1],(0,t.parseExpandedMeta)(i.body)),!0):!1}function hi(e,t,n){for(let r of e.edges)r.id===t&&(n.animate!==void 0&&(r.animate=n.animate.toLowerCase()!==`false`),n.animation!==void 0&&(r.animate=!0))}var gi=/^:::([\w][\w-]*)/,_i=/^([\w\p{L}-]+):::([\w][\w-]*)/u;function vi(t,n,r){let i=t.trim(),a=yi(i,n,r);if(!a||a.ids.length===0)return;i=a.remaining.trim();let o=a.ids;for(;i.length>0;){let t,a,s,c,l,u,d,f=i.match(/^([\w-]+)@(?=[-=<~ox])/);f&&(d=f[1],i=i.slice(f[0].length));let p=i.match(ri),m=p?.[2],h=p?.[1],g=p?.[3];if(p&&m!==void 0&&!(h===void 0&&g===void 0&&ii.has(m))){t=h!==void 0,l=ai(h);let n=p[4]?.trim();c=n?(0,e.normalizeBrTags)(n):void 0,i=i.slice(p[0].length).trim(),a=Ci(m),s=g!==void 0,u=ai(g)}else{let n=i.match(oi);if(!n)break;t=!!n[1],l=ai(n[1]);let r=n[3].trim();c=r?(0,e.normalizeBrTags)(r):void 0;let o=n[2],d=n[4];i=i.slice(n[0].length).trim(),a=wi(o,d),u=ai(d.slice(-1)),s=d.endsWith(`>`)||u!==void 0}let _=yi(i,n,r);if(!_||_.ids.length===0)break;i=_.remaining.trim();for(let e of o)for(let r of _.ids)n.edges.push({source:e,target:r,label:c,style:a,hasArrowStart:t,hasArrowEnd:s,...l===void 0?{}:{startMarker:l},...u===void 0?{}:{endMarker:u},...d===void 0?{}:{id:d}});o=_.ids}}function yi(e,t,n){let r=bi(e,t,n);if(!r)return null;let i=[r.id],a=r.remaining.trim();for(;a.startsWith(`&`);){a=a.slice(1).trim();let e=bi(a,t,n);if(!e)break;i.push(e.id),a=e.remaining.trim()}return{ids:i,remaining:a}}function bi(n,r,i){let a=null,o=n,s,c=o.match(_i);c&&(s=c[2],o=c[1]+o.slice(c[0].length));let l=o.match(li);if(l){let n=l[1],s=(0,t.matchExpandedBlock)(o.slice(n.length));if(s){let c=(0,t.parseExpandedMeta)(s.body);xi(r,i,{id:n,label:(0,e.normalizeBrTags)(di(n,c)),shape:ui(c)}),a=n,o=o.slice(n.length+s.length)}}if(a===null)for(let{regex:t,shape:n}of si){let s=o.match(t);if(s){a=s[1];let t=(0,e.normalizeBrTags)(s[2]),c=typeof n==`function`?n(s[3]??``):n;xi(r,i,{id:a,label:t,shape:c}),o=o.slice(s[0].length);break}}if(a===null){let e=o.match(ci);e&&(a=e[1],r.nodes.has(a)||xi(r,i,{id:a,label:a,shape:`rectangle`}),o=o.slice(e[0].length))}if(a===null)return null;s&&r.classAssignments.set(a,s);let u=o.match(gi);return u&&(r.classAssignments.set(a,u[1]),o=o.slice(u[0].length)),{id:a,remaining:o}}function xi(e,t,n){e.nodes.has(n.id)||e.nodes.set(n.id,n),Si(t,n.id)}function Si(e,t){if(e.length>0){let n=e[e.length-1];n.nodeIds.includes(t)||n.nodeIds.push(t)}}function Ci(e){return e.startsWith(`~`)?`invisible`:e.includes(`.`)?`dotted`:e.startsWith(`=`)?`thick`:`solid`}function wi(e,t){return e.includes(`.`)||t.includes(`.`)?`dotted`:e.startsWith(`=`)||t.startsWith(`=`)?`thick`:`solid`}function Ti(t,n){let r=new Set,i=new Map;for(let e of t.subgraphs)Ei(e,r,i);let a=new Map,o=0;for(let[n,i]of t.nodes){if(r.has(n))continue;let t={name:n,displayLabel:(0,e.stripFormattingTags)(i.label),shape:i.shape,index:o,gridCoord:null,drawingCoord:null,drawing:null,drawn:!1,styleClassName:``,styleClass:Ze};a.set(n,t),o++}let s=[...a.values()],c=[];for(let n of t.edges){let o=n.source,s=n.target;if(r.has(o)){let e=i.get(o),n=e?ki(e,t,`exit`):void 0;n&&(o=n)}if(r.has(s)){let e=i.get(s),n=e?ki(e,t,`entry`):void 0;n&&(s=n)}let l=a.get(o),u=a.get(s);!l||!u||c.push({from:l,to:u,text:n.label?(0,e.stripFormattingTags)(n.label):``,path:[],labelLine:[],startDir:{x:0,y:0},endDir:{x:0,y:0},style:n.style,hasArrowStart:n.hasArrowStart,hasArrowEnd:n.hasArrowEnd,...n.startMarker===void 0?{}:{startMarker:n.startMarker},...n.endMarker===void 0?{}:{endMarker:n.endMarker}})}let l=[];for(let e of t.subgraphs)Ai(e,null,a,l,t);ji(t.subgraphs,l,a);let u=t.classDefs.get(`default`);if(u)for(let e of a.values())e.styleClassName=`default`,e.styleClass={name:`default`,styles:u};for(let[e,n]of t.classAssignments){let r=a.get(e),i=t.classDefs.get(n);r&&i&&(r.styleClassName=n,r.styleClass={name:n,styles:u?{...u,...i}:i})}return{nodes:s,edges:c,canvas:N(0,0),roleCanvas:F(0,0),grid:$e(),columnWidth:new Map,rowHeight:new Map,subgraphs:l,config:n,offsetX:0,offsetY:0,bundles:[]}}function Ei(e,t,n){t.add(e.id),n.set(e.id,e);for(let r of e.children)Ei(r,t,n)}function Di(e,t){for(let n of e.nodeIds)t.add(n);for(let n of e.children)Di(n,t)}function Oi(e,t){let n=new Set;if(Di(e,n),n.size===0)return!0;let r=t=>n.has(t)||t===e.id;return!t.edges.some(e=>r(e.source)!==r(e.target))}function ki(e,t,n){let r=new Set;if(Di(e,r),r.size===0)return;let i=[...t.nodes.keys()].filter(e=>r.has(e));if(i.length===0)return;let a=i.filter(e=>n===`entry`?!t.edges.some(t=>t.target===e&&r.has(t.source)):!t.edges.some(t=>t.source===e&&r.has(t.target))),o=a.length>0?a:i;return n===`entry`?o[0]:o[o.length-1]}function Ai(e,t,n,r,i){let a;e.direction&&Oi(e,i)&&(a=e.direction===`LR`||e.direction===`RL`?`LR`:`TD`);let o={name:e.label,nodes:[],parent:t,children:[],minX:0,minY:0,maxX:0,maxY:0,direction:a};for(let t of e.nodeIds){let e=n.get(t);e&&o.nodes.push(e)}r.push(o);for(let t of e.children){let e=Ai(t,o,n,r,i);o.children.push(e);for(let t of e.nodes)o.nodes.includes(t)||o.nodes.push(t)}return o}function ji(e,t,n){let r=new Map;Ni(e,t,r);let i=new Map;function a(e){let t=r.get(e);if(t){for(let t of e.children)a(t);for(let n of e.nodeIds)i.has(n)||i.set(n,t)}}for(let t of e)a(t);for(let e of t)e.nodes=e.nodes.filter(t=>{let r;for(let[e,i]of n)if(i===t){r=e;break}if(!r)return!1;let a=i.get(r);return!a||Mi(e,a)})}function Mi(e,t){let n=t;for(;n!==null;){if(n===e)return!0;n=n.parent}return!1}function Ni(e,t,n){let r=[];function i(e){for(let t of e)r.push(t),i(t.children)}i(e);for(let e=0;e<r.length&&e<t.length;e++){let i=r[e],a=t[e];!i||!a||n.set(i,a)}}function Pi(t,n,r,i,a={}){let o=(0,e.withDirectionOverride)(Qr(t),a.direction);n.graphDirection=o.direction===`LR`||o.direction===`RL`?`LR`:`TD`;let s=Ti(o,n);gn(s),Sr(s);let c=a.hyperlinks?d(s,o.interactions):void 0;return o.direction===`BT`&&(ge(s.canvas),B(s.roleCanvas),c&&l(c)),me(s.canvas,{roleCanvas:s.roleCanvas,colorMode:r,theme:i,linkCanvas:c})}var Fi={xychart:(e,t,n,r)=>Ee(e,t,n,r),er:(e,t,n,r)=>kr(e,t,n,r),sequence:(e,t,n,r)=>Fr(e,t,n,r),class:(e,t,n,r,i)=>Ur(e,t,n,r,i),flowchart:(e,t,n,r,i)=>Pi(e,t,n,r,i)},Ii=/\x1b\[[0-9;]*m/g;function Li(e){let t=e.split(`
6
- `),n=t.reduce((e,t)=>Math.max(e,o(t.replace(Ii,``)).length),0),r=String(Math.max(0,t.length-1)).length,i=` `.repeat(r+1);return[i+Array.from({length:n},(e,t)=>String(Math.floor(t/10)%10)).join(``),i+Array.from({length:n},(e,t)=>String(t%10)).join(``),...t.map((e,t)=>`${String(t).padStart(r,` `)} ${e}`)].join(`
7
- `)}function Ri(t,n={}){let r={useAscii:n.useAscii??!1,paddingX:n.paddingX??5,paddingY:n.paddingY??5,boxBorderPadding:n.boxBorderPadding??1,graphDirection:`TD`},i=n.colorMode===`auto`||n.colorMode===void 0?g():n.colorMode,a={...m,...n.theme},o=Fi[(0,e.detectDiagramType)(t)](t,r,i,a,{hyperlinks:n.hyperlinks??!1,direction:n.direction});return n.showCoords?Li(o):o}var zi=Ri;exports.DEFAULT_ASCII_THEME=m,exports.detectColorMode=g,exports.diagramColorsToAsciiTheme=h,exports.renderMermaidASCII=Ri,exports.renderMermaidAscii=zi;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@zombie-mermaid/core"),t=require("@zombie-mermaid/mermaid-parser");function n(e){return[e.length-1,(e[0]?.length??1)-1]}var r=`\x1B]8;;\x1B\\`;function i(e){return`\x1b]8;;${e.replace(/[^\x21-\x7e]/gu,e=>encodeURIComponent(e))}\x1b\\`}var a=/\x1b\]8;[^\x07\x1b]*(?:\x1b\\|\x07)/g;function o(e){return e.replace(a,``)}function s(e,t){let n=[];for(let r=0;r<=e;r++){let e=[];for(let n=0;n<=t;n++)e.push(null);n.push(e)}return n}function c(e,t,n,r){let i=e[t];i===void 0||n<0||n>=i.length||(i[n]=r)}function l(e){for(let t of e)t.reverse();return e}function u(e,t,r,i,a){let[o,s]=n(t),l=Math.max(1,a?.from??1),u=Math.min(s-1,a?.to??s-1);for(let n=l;n<=u;n++){let a=-1,s=-1;for(let e=1;e<=o-1;e++)t[e]?.[n]!==` `&&(a===-1&&(a=e),s=e);if(a!==-1)for(let t=a;t<=s;t++)c(e,t+r.x,n+r.y,i)}}function d(t,r){let[i,a]=n(t.canvas),o=s(i,a);for(let n of t.nodes){if(!n.drawing||!n.drawingCoord)continue;let t=(0,e.safeHref)(r.get(n.name)?.href);t!==void 0&&u(o,n.drawing,n.drawingCoord,t)}return o}var f=class{current=null;advance(e){if(e===this.current)return``;let t=this.current===null?``:r;return e!==null&&(t+=i(e)),this.current=e,t}finish(){let e=this.current===null?``:r;return this.current=null,e}};function p(e,t){let n=new f,r=``;for(let[i,a]of e.entries())r+=n.advance(t[i]??null)+a;return r+n.finish()}var m={fg:`#27272a`,border:`#a1a1aa`,line:`#71717a`,arrow:`#52525b`,corner:`#71717a`,junction:`#a1a1aa`};function h(t){let n=t.line??(0,e.mixHexColors)(t.fg,t.bg,e.MIX.line),r=t.border??(0,e.mixHexColors)(t.fg,t.bg,e.MIX.nodeStroke);return{fg:t.fg,border:r,line:n,arrow:t.accent??(0,e.mixHexColors)(t.fg,t.bg,e.MIX.arrow),accent:t.accent,bg:t.bg,corner:n,junction:r}}function g(){let e=globalThis.process;if(e){if(!e.stdout?.isTTY)return`none`;let t=e.env?.COLORTERM?.toLowerCase()??``,n=e.env?.TERM?.toLowerCase()??``;return t===`truecolor`||t===`24bit`?`truecolor`:n.includes(`256color`)||n.includes(`256`)?`ansi256`:n&&n!==`dumb`?`ansi16`:`none`}return typeof document<`u`?`html`:`none`}function _(t){return(0,e.parseHexRgba)(t.startsWith(`#`)?t:`#${t}`)??{r:0,g:0,b:0}}var v=`\x1B[`,y=`${v}0m`;function b(e){let{r:t,g:n,b:r}=_(e);return`${v}38;2;${t};${n};${r}m`}function x(e,t,n){let r=(e+t+n)/3;if(Math.max(Math.abs(e-r),Math.abs(t-r),Math.abs(n-r))<10){let e=Math.round(r/255*23);return 232+Math.min(23,Math.max(0,e))}let i=e=>e<48?0:e<115?1:Math.min(5,Math.floor((e-35)/40)),a=i(e),o=i(t),s=i(n);return 16+36*a+6*o+s}function S(e){let{r:t,g:n,b:r}=_(e);return`${v}38;5;${x(t,n,r)}m`}function C(e){let{r:t,g:n,b:r}=_(e),i=.299*t+.587*n+.114*r,a=i>100?0:60,o;return o=t>180&&n<100&&r<100?31:n>180&&t<100&&r<100?32:t>150&&n>150&&r<100?33:r>180&&t<100&&n<100?34:t>150&&r>150&&n<100?35:n>150&&r>150&&t<100?36:i>200?37:i<50?30:37,`${v}${o+a}m`}function w(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}function T(e,t){return`<span style="color:${e}">${w(t)}</span>`}function E(e,t){switch(e){case`text`:return t.fg;case`border`:return t.border;case`line`:return t.line;case`arrow`:return t.arrow;case`corner`:return t.corner??t.line;case`junction`:return t.junction??t.border;default:return t.fg}}function D(e,t,n){if(n===`none`)return``;let r=E(e,t);switch(n){case`truecolor`:return b(r);case`ansi256`:return S(r);case`ansi16`:return C(r);default:return``}}function ee(e,t,n,r,i){if(r===`none`)return i?p(e,i):e.join(``);if(r===`html`)return O(e,t,n);let a=new f,o=``,s=null,c=``;for(let[l,u]of e.entries()){let e=t[l]??null,d=i?a.advance(i[l]??null):``;if(u===` `){c.length>0&&(o+=s===null?c:D(s,n,r)+c+y,c=``,s=null),o+=d+u;continue}if(e===s){c+=d+u;continue}c.length>0&&(o+=s===null?c:D(s,n,r)+c+y),c=d+u,s=e}return c.length>0&&s!==null?o+=D(s,n,r)+c+y:c.length>0&&(o+=c),o+a.finish()}function O(e,t,n){let r=``,i=null,a=``,o=()=>{a.length!==0&&(r+=i===null?w(a):T(E(i,n),a),a=``,i=null)};for(let[n,s]of e.entries()){let e=t[n]??null;if(s===` `){o(),r+=` `;continue}if(e===i){a+=s;continue}o(),a=s,i=e}return o(),r}function k(e,t,n){if(n===`none`||e.length===0)return e;if(n===`html`)return T(t,e);let r;switch(n){case`truecolor`:r=b(t);break;case`ansi256`:r=S(t);break;case`ansi16`:r=C(t);break;default:return e}return`${r}${e}${y}`}var te=/\p{Mn}|\p{Me}/u;function ne(e){return te.test(e)}var A=new Intl.Segmenter(void 0,{granularity:`grapheme`}),j=`️`;function re(e){let t=[];for(let{segment:n}of A.segment(e))t.push(n);return t}function ie(t){if(t.includes(j))return 2;let n=!1,r=!1;for(let i of t)(0,e.isWideChar)(i)&&(n=!0),ne(i)||(r=!0);return n?2:+!!r}function M(e){let t=0;for(let n of re(e))t+=ie(n);return t}function ae(e){let t=[];for(let n of re(e)){let e=ie(n);e!==0&&(t.push(n),e===2&&t.push(``))}return t}function N(e,t){let n=[];for(let r=0;r<=e;r++){let e=[];for(let n=0;n<=t;n++)e.push(` `);n.push(e)}return n}function P(e){let[t,n]=L(e);return N(t,n)}function F(e,t){let n=[];for(let r=0;r<=e;r++){let e=[];for(let n=0;n<=t;n++)e.push(null);n.push(e)}return n}function oe(e,t,n){let r=e.length-1,i=(e[0]?.length??1)-1,a=F(Math.max(t,r),Math.max(n,i));for(let t=0;t<a.length;t++)for(let n=0;n<(a[0]?.length??0);n++)t<e.length&&n<(e[0]?.length??0)&&(a[t][n]=e[t][n]);return e.length=0,e.push(...a),e}function I(e,t,n,r){(t>=e.length||n>=(e[0]?.length??0))&&oe(e,t,n),e[t][n]=r}function L(e){return[e.length-1,(e[0]?.length??1)-1]}function se(e,t,n){let[r,i]=L(e),a=N(Math.max(t,r),Math.max(n,i));for(let t=0;t<a.length;t++)for(let n=0;n<(a[0]?.length??0);n++)t<e.length&&n<(e[0]?.length??0)&&(a[t][n]=e[t][n]);return e.length=0,e.push(...a),e}function R(e,t,n,r,i){let[a,o]=L(e);t<0||t>a||n<0||n>o||(e[t][n]=r,i&&I(i.roleCanvas,t,n,i.role))}var ce=new Set([`─`,`│`,`┌`,`┐`,`└`,`┘`,`├`,`┤`,`┬`,`┴`,`┼`,`╴`,`╵`,`╶`,`╷`]);function le(e){return ce.has(e)}function z(e){return/^[a-zA-Z0-9]$/.test(e)}var ue={"─":{"│":`┼`,"┌":`┬`,"┐":`┬`,"└":`┴`,"┘":`┴`,"├":`┼`,"┤":`┼`,"┬":`┬`,"┴":`┴`},"│":{"─":`┼`,"┌":`├`,"┐":`┤`,"└":`├`,"┘":`┤`,"├":`├`,"┤":`┤`,"┬":`┼`,"┴":`┼`},"┌":{"─":`┬`,"│":`├`,"┐":`┬`,"└":`├`,"┘":`┼`,"├":`├`,"┤":`┼`,"┬":`┬`,"┴":`┼`},"┐":{"─":`┬`,"│":`┤`,"┌":`┬`,"└":`┼`,"┘":`┤`,"├":`┼`,"┤":`┤`,"┬":`┬`,"┴":`┼`},"└":{"─":`┴`,"│":`├`,"┌":`├`,"┐":`┼`,"┘":`┴`,"├":`├`,"┤":`┼`,"┬":`┼`,"┴":`┴`},"┘":{"─":`┴`,"│":`┤`,"┌":`┼`,"┐":`┤`,"└":`┴`,"├":`┼`,"┤":`┤`,"┬":`┼`,"┴":`┴`},"├":{"─":`┼`,"│":`├`,"┌":`├`,"┐":`┼`,"└":`├`,"┘":`┼`,"┤":`┼`,"┬":`┼`,"┴":`┼`},"┤":{"─":`┼`,"│":`┤`,"┌":`┼`,"┐":`┤`,"└":`┼`,"┘":`┤`,"├":`┼`,"┬":`┼`,"┴":`┼`},"┬":{"─":`┬`,"│":`┼`,"┌":`┬`,"┐":`┬`,"└":`┼`,"┘":`┼`,"├":`┼`,"┤":`┼`,"┴":`┼`},"┴":{"─":`┴`,"│":`┼`,"┌":`┼`,"┐":`┼`,"└":`┴`,"┘":`┴`,"├":`┼`,"┤":`┼`,"┬":`┼`}};function de(e,t){return ue[e]?.[t]??e}function fe(e){let t=new Map,n=[];for(let r of e){let[e,i]=L(r),a=P(r);for(let n=0;n<=e;n++)for(let e=0;e<=i;e++){let i=r[n]?.[e];if(i===void 0||i===` `)continue;let o=`${n},${e}`,s=t.get(o);if(s!==void 0){if(!(s!==i&&le(s)&&le(i)))continue}else t.set(o,i);a[n][e]=i}n.push(a)}return n}function B(e,t,n,...r){let[i,a]=L(e);for(let e of r){let[n,r]=L(e);i=Math.max(i,n+t.x),a=Math.max(a,r+t.y)}let o=N(i,a);for(let t=0;t<=i;t++)for(let n=0;n<=a;n++)t<e.length&&n<(e[0]?.length??0)&&(o[t][n]=e[t][n]);for(let e of r)for(let r=0;r<e.length;r++)for(let i=0;i<(e[0]?.length??0);i++){let a=e[r][i];if(a!==` `){let e=r+t.x,s=i+t.y,c=o[e][s];!n&&le(a)&&le(c)?o[e][s]=de(c,a):z(c)&&z(a)||(o[e][s]=a)}}return o}function pe(e,t){let[n,r]=L(e),i=[],a=t?.roleCanvas,o=t?.colorMode??`none`,s=t?.theme??m,c=o===`html`?void 0:t?.linkCanvas;for(let t=0;t<=r;t++)if(o===`none`||!a){let r=[];for(let i=0;i<=n;i++)r.push(e[i][t]);if(c){let e=r.map((e,n)=>c[n]?.[t]??null);i.push(p(r,e))}else i.push(r.join(``))}else{let r=[],l=[],u=[];for(let i=0;i<=n;i++)r.push(e[i][t]),l.push(a[i]?.[t]??null),u.push(c?.[i]?.[t]??null);i.push(ee(r,l,s,o,c?u:void 0))}return i.join(`
2
+ `)}var me={"▲":`▼`,"▼":`▲`,"↖":`↙`,"↙":`↖`,"↗":`↘`,"↘":`↗`,"^":`v`,v:`^`,"┌":`└`,"└":`┌`,"┐":`┘`,"┘":`┐`,"┬":`┴`,"┴":`┬`,"╵":`╷`,"╷":`╵`};function he(e){for(let t of e)t.reverse();for(let t of e)for(let[e,n]of t.entries()){let r=me[n];r&&(t[e]=r)}return e}function ge(e){for(let t of e)t.reverse();return e}function V(e,t,n,r=!1){let i=ae(n);se(e,t.x+i.length,t.y);for(let[n,a]of i.entries()){let i=t.x+n,o=e[i][t.y];(r||o===` `)&&(e[i][t.y]=a)}}function _e(e,t,n,r=0,i=0){let a=r,o=i;for(let e of t.values())a+=e;for(let e of n.values())o+=e;se(e,a-1,o-1)}function ve(e,t,n,r=0,i=0){let a=r,o=i;for(let e of t.values())a+=e;for(let e of n.values())o+=e;oe(e,a-1,o-1)}var ye=60,be=20,xe={hLine:`─`,vLine:`│`,origin:`┼`,yTick:`┤`,xTick:`┬`,bar:`█`,grid:`·`,cornerTL:`╭`,cornerTR:`╮`,cornerBL:`╰`,cornerBR:`╯`},Se={hLine:`-`,vLine:`|`,origin:`+`,yTick:`+`,xTick:`+`,bar:`#`,grid:`.`,cornerTL:`+`,cornerTR:`+`,cornerBL:`+`,cornerBR:`+`};function Ce(e,n){let r=n.accent??t.CHART_ACCENT_FALLBACK;return e<=1?[r]:Array.from({length:e},(e,i)=>(0,t.getSeriesColor)(i,r,n.bg))}function we(e,t){switch(e){case`text`:return t.fg;case`border`:return t.border;case`line`:return t.line;case`arrow`:return t.arrow;case`corner`:return t.corner??t.line;case`junction`:return t.junction??t.border;default:return t.fg}}function Te(n,r,i,a){let o=(0,e.splitStatements)(n),s=(0,t.parseXYChart)(o),c=r.useAscii?Se:xe;return s.horizontal?H(s,c,i,a):Ee(s,c,i,a)}function Ee(e,t,n,r){let i=Fe(e);if(i===0)return``;let a=e.yAxis.range;if(!a)throw Error(`XY chart: y-axis range was not set by the parser`);let o=Le(a.min,a.max),s=o.map(e=>Re(e)),c=Math.max(...s.map(e=>e.length))+1,l=Math.max(ye,i*6),u=be,d=Math.floor(l/i),f=Ie(e,i),p=!!e.title,m=!!e.xAxis.title,h=!!e.yAxis.title,g=e.series.length>1,_=p?0:-1,v=(p?2:0)+ +!!g,y=h?2:0,b=y+c+1,x=b+d*i+2,S=v+u,C=S+1,w=m?C+1:-1,T=C+1+ +!!m+0,E=Ae(x,T),D=je(x,T),ee=U(x,T),O=Ce(e.series.length,r),k=e=>{let t=(e-a.min)/(a.max-a.min||1);return Math.round(t*19)},te=e=>b+Math.floor(d*(e+.5));e.title&&_>=0&&G(E,D,_,Math.floor(x/2-e.title.length/2),e.title,`text`),g&&ke(E,D,ee,e,+!!p,x,t,O);for(let e=0;e<u;e++)W(E,D,v+(19-e),b-1,t.vLine,`border`);W(E,D,S,b-1,t.origin,`border`);for(let e of o){let n=k(e);if(n<0||n>=u)continue;let r=v+(19-n),i=Re(e);W(E,D,r,b-1,n===0?t.origin:t.yTick,`border`);let a=y+c-i.length;G(E,D,r,Math.max(0,a),i,`text`)}for(let e=b;e<b+d*i;e++)W(E,D,S,e,t.hLine,`border`);for(let e=0;e<i;e++){let n=te(e);W(E,D,S,n,t.xTick,`border`);let r=f[e],i=n-Math.floor(r.length/2);G(E,D,C,Math.max(0,i),r,`text`)}if(e.xAxis.title&&w>=0){let t=e.xAxis.title;G(E,D,w,Math.floor(x/2-t.length/2),t,`text`)}if(e.yAxis.title){let t=e.yAxis.title,n=v+Math.max(0,Math.floor((u-t.length)/2));for(let e=0;e<t.length;e++){let r=n+e;if(r>=v+u)break;W(E,D,r,0,t[e],`text`)}}for(let e of o){let n=k(e);if(n<0||n>=u)continue;let r=v+(19-n);for(let e=b;e<b+d*i;e++)Me(E,r,e)===` `&&W(E,D,r,e,t.grid,`line`)}let ne=[];for(let t=0;t<e.series.length;t++)e.series[t].type===`bar`&&ne.push({data:e.series[t].data,globalIdx:t});if(ne.length>0){let e=Math.max(1,d-2),n=Math.max(1,Math.min(e,8)),r=k(Math.max(0,a.min));for(let e=0;e<ne.length;e++){let i=ne[e],a=O[i.globalIdx];for(let e=0;e<i.data.length;e++){let o=te(e)-Math.floor(n/2),s=k(i.data[e]),c=Math.min(r,s),l=Math.max(r,s);for(let e=c;e<=l;e++){let r=v+(19-e);for(let e=o;e<o+n;e++)W(E,D,r,e,t.bar,`arrow`,ee,a)}}}}let A=[];for(let t=0;t<e.series.length;t++)e.series[t].type===`line`&&A.push({data:e.series[t].data,globalIdx:t});for(let e of A){if(e.data.length===0)continue;let n=O[e.globalIdx];De(E,D,e.data,te,k,v,u,b,d*i,t,ee,n)}return Ne(E,D,ee,n,r)}function H(e,t,n,r){let i=Fe(e);if(i===0)return``;let a=e.yAxis.range;if(!a)throw Error(`XY chart: y-axis range was not set by the parser`);let o=Le(a.min,a.max),s=Ie(e,i),c=Math.max(...s.map(e=>e.length))+1,l=Math.max(ye,40),u=Math.max(2,Math.floor(be/i)),d=u*i,f=!!e.title,p=!!e.yAxis.title,m=e.series.length>1,h=(f?2:0)+ +!!m,g=c+1,_=g+l+2,v=h+d+2+ +!!p,y=h+d,b=Ae(_,v),x=je(_,v),S=U(_,v),C=Ce(e.series.length,r),w=e=>{let t=(e-a.min)/(a.max-a.min||1);return g+Math.round(t*59)},T=e=>h+Math.floor(u*(e+.5));e.title&&G(b,x,0,Math.floor(_/2-e.title.length/2),e.title,`text`),m&&ke(b,x,S,e,+!!f,_,t,C);for(let e=h;e<h+d;e++)W(b,x,e,g-1,t.vLine,`border`);W(b,x,y,g-1,t.origin,`border`);for(let e=0;e<i;e++){let t=T(e),n=s[e],r=c-n.length;G(b,x,t,Math.max(0,r),n,`text`)}for(let e=g;e<g+l;e++)W(b,x,y,e,t.hLine,`border`);for(let e of o){let n=w(e);if(n<g||n>=g+l)continue;W(b,x,y,n,t.xTick,`border`);let r=Re(e);G(b,x,y+1,n-Math.floor(r.length/2),r,`text`)}if(e.yAxis.title){let t=e.yAxis.title;G(b,x,v-1,Math.floor(_/2-t.length/2),t,`text`)}for(let e of o){let n=w(e);if(!(n<g||n>=g+l))for(let e=h;e<h+d;e++)Me(b,e,n)===` `&&W(b,x,e,n,t.grid,`line`)}let E=[];for(let t=0;t<e.series.length;t++)e.series[t].type===`bar`&&E.push({data:e.series[t].data,globalIdx:t});if(E.length>0){let e=w(Math.max(0,a.min));for(let n=0;n<E.length;n++){let r=E[n],i=C[r.globalIdx];for(let n=0;n<r.data.length;n++){let a=T(n),o=w(r.data[n]),s=Math.min(e,o),c=Math.max(e,o);for(let e=a;e<a+1;e++)for(let n=s;n<=c;n++)W(b,x,e,n,t.bar,`arrow`,S,i)}}}let D=[];for(let t=0;t<e.series.length;t++)e.series[t].type===`line`&&D.push({data:e.series[t].data,globalIdx:t});for(let e of D){if(e.data.length===0)continue;let n=C[e.globalIdx];Oe(b,x,e.data,T,w,h,d,g,l,t,S,n)}return Ne(b,x,S,n,r)}function De(e,t,n,r,i,a,o,s,c,l,u,d){if(n.length===0)return;let f=n.map((e,t)=>({col:r(t),row:i(e)})),p=(n,r,i)=>{let l=a+(o-1-r);l>=0&&n>=s&&n<s+c&&W(e,t,l,n,i,`arrow`,u,d)};if(f.length===1){p(f[0].col,f[0].row,l.hLine);return}for(let e=0;e<f.length-1;e++){let t=f[e],n=f[e+1];if(t.row===n.row){for(let e=t.col;e<=n.col;e++)p(e,t.row,l.hLine);continue}let r=Math.round((t.col+n.col)/2),i=n.row>t.row;for(let e=t.col;e<r;e++)p(e,t.row,l.hLine);i?p(r,t.row,l.cornerBR):p(r,t.row,l.cornerTR);let a=Math.min(t.row,n.row),o=Math.max(t.row,n.row);for(let e=a+1;e<o;e++)p(r,e,l.vLine);i?p(r,n.row,l.cornerTL):p(r,n.row,l.cornerBL);for(let e=r+1;e<=n.col;e++)p(e,n.row,l.hLine);if(e===0){let e=Math.max(s,t.col-Math.floor((n.col-t.col)/4));for(let n=e;n<t.col;n++)p(n,t.row,l.hLine)}if(e===f.length-2){let e=Math.min(s+c-1,n.col+Math.floor((n.col-t.col)/4));for(let t=n.col+1;t<=e;t++)p(t,n.row,l.hLine)}}}function Oe(e,t,n,r,i,a,o,s,c,l,u,d){if(n.length===0)return;let f=n.map((e,t)=>({row:r(t),col:i(e)})),p=(n,r,i)=>{n>=a&&n<a+o&&r>=s&&r<s+c&&W(e,t,n,r,i,`arrow`,u,d)};if(f.length===1){p(f[0].row,f[0].col,l.vLine);return}for(let e=0;e<f.length-1;e++){let t=f[e],n=f[e+1];if(t.col===n.col){for(let e=t.row;e<=n.row;e++)p(e,t.col,l.vLine);continue}let r=Math.round((t.row+n.row)/2),i=n.col>t.col;for(let e=t.row;e<r;e++)p(e,t.col,l.vLine);i?p(r,t.col,l.cornerBL):p(r,t.col,l.cornerBR);let a=Math.min(t.col,n.col),o=Math.max(t.col,n.col);for(let e=a+1;e<o;e++)p(r,e,l.hLine);i?p(r,n.col,l.cornerTR):p(r,n.col,l.cornerTL);for(let e=r+1;e<=n.row;e++)p(e,n.col,l.vLine)}}function ke(e,t,n,r,i,a,o,s){let c=[],l=0,u=0;for(let e=0;e<r.series.length;e++)r.series[e].type===`bar`?(c.push({symbol:o.bar,label:`Bar ${l+1}`,globalIdx:e}),l++):(c.push({symbol:o.hLine,label:`Line ${u+1}`,globalIdx:e}),u++);let d=0;for(let e=0;e<c.length;e++)e>0&&(d+=2),d+=2+c[e].label.length;let f=Math.max(0,Math.floor(a/2-d/2));for(let r=0;r<c.length;r++){r>0&&(f+=2);let a=c[r];W(e,t,i,f,a.symbol,`arrow`,n,s[a.globalIdx]),f+=1,f+=1,G(e,t,i,f,a.label,`text`),f+=a.label.length}}function Ae(e,t){return N(e-1,t-1)}function je(e,t){return F(e-1,t-1)}function U(e,t){return Array.from({length:e},()=>Array.from({length:t}).fill(null))}function W(e,t,n,r,i,a,o,s){r>=0&&r<e.length&&n>=0&&n<(e[0]?.length??0)&&(R(e,r,n,i,{role:a,roleCanvas:t}),o&&s&&(o[r][n]=s))}function Me(e,t,n){return n>=0&&n<e.length&&t>=0&&t<e[0].length?e[n][t]:` `}function G(e,t,n,r,i,a){for(let o=0;o<i.length;o++)W(e,t,n,r+o,i[o],a)}function Ne(e,t,n,r,i){if(e.length===0)return``;let a=e[0].length,o=e.length,s=[];for(let c=0;c<a;c++){let a=[],l=[],u=[];for(let r=0;r<o;r++)a.push(e[r][c]),l.push(t[r][c]),u.push(n[r][c]);let d=a.length-1;for(;d>=0&&a[d]===` `;)d--;d<0?s.push(``):s.push(Pe(a.slice(0,d+1),l.slice(0,d+1),u.slice(0,d+1),i,r))}for(;s.length>0&&s[s.length-1]===``;)s.pop();return s.join(`
3
+ `)}function Pe(e,t,n,r,i){if(i===`none`)return e.join(``);let a=``,o=null,s=``;for(let c=0;c<e.length;c++){let l=e[c];if(l===` `){s.length>0&&(a+=o?k(s,o,i):s,s=``,o=null),a+=` `;continue}let u=n[c]??null,d=t[c]??null,f=u??(d?we(d,r):null);f===o?s+=l:(s.length>0&&(a+=o?k(s,o,i):s),s=l,o=f)}return s.length>0&&(a+=o?k(s,o,i):s),a}function Fe(e){if(e.xAxis.categories)return e.xAxis.categories.length;for(let t of e.series)if(t.data.length>0)return t.data.length;return 0}function Ie(e,t){if(e.xAxis.categories)return e.xAxis.categories;if(e.xAxis.range){let{min:n,max:r}=e.xAxis.range,i=t>1?(r-n)/(t-1):0;return Array.from({length:t},(e,t)=>Re(n+i*t))}return Array.from({length:t},(e,t)=>String(t+1))}function Le(e,t){let n=t-e;if(n<=0)return[e];let r=n/6,i=10**Math.floor(Math.log10(r)),a=r/i,o;o=a<=1.5?i:a<=3?2*i:a<=7?5*i:10*i;let s=Math.ceil(e/o)*o,c=[];for(let e=s;e<=t+o*.001;e+=o)c.push(Math.round(e*1e10)/1e10);return c}function Re(e){return Number.isInteger(e)?String(e):e.toFixed(+(Math.abs(e)<10))}var K={x:1,y:0},q={x:1,y:2},J={x:0,y:1},Y={x:2,y:1},ze={x:2,y:0},Be={x:0,y:0},Ve={x:2,y:2},He={x:0,y:2},Ue={x:1,y:1};function X(e,t){return e.x===t.x&&e.y===t.y}function We(e){return X(e,K)||X(e,q)||X(e,J)||X(e,Y)}function Ge(e){if(!We(e))throw Error(`Expected a cardinal direction (Up/Down/Left/Right); got {x:${e.x}, y:${e.y}}`);return e}function Ke(e,t,n,r){return Math.max(r,n+(e-t))}function qe(e,t){return e.x===t.x&&e.y===t.y}function Je(e,t){return e.x===t.x&&e.y===t.y}function Ye(e,t){return{x:e.x+t.x,y:e.y+t.y}}function Xe(e){return`${e.x},${e.y}`}function Z(e){let t=e.gridCoord;if(t===null)throw Error(`Node "${e.name}" has no gridCoord; grid layout must run before it is read`);return t}var Ze={name:``,styles:{}},Qe=class{#e=new Set;has(e){return this.#e.has(e)}add(e){this.#e.add(e)}delete(e){this.#e.delete(e)}keys(){return this.#e.keys()}};function $e(){return new Qe}function et(e){let t=$e();for(let n of e.keys())t.add(n);return t}function tt(e,t){return e.has(Xe(t))}function nt(e,t){return t.x<0||t.y<0?!1:!tt(e,t)}function rt(e,t,n=3){for(let r=0;r<n;r++)for(let i=0;i<n;i++)if(tt(e,{x:t.x+r,y:t.y+i}))return!1;return!0}function it(e,t,n=3){if(!rt(e,t,n))throw Error(`Grid block at (${t.x},${t.y}) is already occupied`);for(let r=0;r<n;r++)for(let i=0;i<n;i++){let n={x:t.x+r,y:t.y+i};e.add(Xe(n))}}var at=1e5;function ot(e){if(e.length===0)return[];let t=[e[0]];for(let n=1;n<e.length;n++){let r=e[n-1],i=e[n],a=r.x,o=r.y,s=Math.abs(i.x-r.x),c=Math.abs(i.y-r.y),l=r.x<i.x?1:-1,u=r.y<i.y?1:-1,d=s-c,f=0;for(;a!==i.x||o!==i.y;){if(f>=at)throw Error(`pathCells: segment from (${r.x},${r.y}) to (${i.x},${i.y}) did not reach its endpoint within ${at} steps`);let e=2*d;e>-c&&(d-=c,a+=l),e<s&&(d+=s,o+=u),t.push({x:a,y:o}),f++}}return t}var st=class{items=[];get length(){return this.items.length}push(e){this.items.push(e),this.bubbleUp(this.items.length-1)}pop(){if(this.items.length===0)return;let e=this.items[0],t=this.items.pop();return this.items.length>0&&(this.items[0]=t,this.sinkDown(0)),e}bubbleUp(e){let t=e;for(;t>0;){let e=t-1>>1;if(this.items[t].priority<this.items[e].priority)[this.items[t],this.items[e]]=[this.items[e],this.items[t]],t=e;else break}}sinkDown(e){let t=this.items.length,n=e;for(;;){let e=n,r=2*n+1,i=2*n+2;if(r<t&&this.items[r].priority<this.items[e].priority&&(e=r),i<t&&this.items[i].priority<this.items[e].priority&&(e=i),e!==n)[this.items[n],this.items[e]]=[this.items[e],this.items[n]],n=e;else break}}};function ct(e,t){let n=Math.abs(e.x-t.x),r=Math.abs(e.y-t.y);return n===0||r===0?n+r:n+r+1}var lt=[{x:1,y:0},{x:-1,y:0},{x:0,y:1},{x:0,y:-1}],ut=5e4,dt=2e5;function ft(e=dt){return{remaining:e}}function pt(e,t,n,r){if(r&&r.remaining<=0)return null;let i=new st;i.push({coord:t,priority:0});let a=new Map;a.set(Xe(t),0);let o=new Map;o.set(Xe(t),null);let s=0;for(;i.length>0;){if(++s>ut)return null;if(r){if(r.remaining<=0)return null;r.remaining--}let t=i.pop().coord;if(qe(t,n)){let e=[],n=t;for(;n!==null;)e.unshift(n),n=o.get(Xe(n))??null;return e}let c=a.get(Xe(t));if(c===void 0)throw Error(`A* pathfinding: missing cost for visited cell ${Xe(t)}`);for(let r of lt){let s={x:t.x+r.x,y:t.y+r.y};if(!nt(e,s)&&!qe(s,n))continue;let l=c+1,u=Xe(s),d=a.get(u);if(d===void 0||l<d){a.set(u,l);let e=l+ct(s,n);i.push({coord:s,priority:e}),o.set(u,t)}}}return null}function mt(e){if(e.length<=2)return e;let t=new Set,n=e[0],r=e[1];for(let i=2;i<e.length;i++){let a=e[i],o=r.x-n.x,s=r.y-n.y,c=a.x-r.x,l=a.y-r.y;o===c&&s===l&&t.add(i-1),n=r,r=a}return e.filter((e,n)=>!t.has(n))}function ht(e,t,n,r){if(t.x===n.x&&t.y===n.y)return!0;let i=t.x===n.x;if(!i&&t.y!==n.y)return!1;let a=i?n.y>t.y?1:-1:n.x>t.x?1:-1,o=i?t.y:t.x,s=i?n.y:n.x;for(o+=a;;o+=a){let n=o===s,a=i?{x:t.x,y:o}:{x:o,y:t.y};if(!(n&&!r)&&!nt(e,a))return!1;if(n)break}return!0}function gt(e,t,n,r){let i=r?{x:n.x,y:t.y}:{x:t.x,y:n.y};return!ht(e,t,i,!0)||!ht(e,i,n,!1)?null:[t,i,n]}function _t(e,t,n,r){if(t.x===n.x||t.y===n.y)return null;let i=X(r,J)||X(r,Y);return gt(e.grid,t,n,i)??gt(e.grid,t,n,!i)}function vt(e,t,n,r){if(!e.pathBudget)throw Error(`routeEdge requires graph.pathBudget to be set; call createPathBudget() (see grid.ts createMapping) before routing edges`);let i=_t(e,t,n,r)??pt(e.grid,t,n,e.pathBudget);return i?mt(i):null}function yt(e){if(e.config.graphDirection!==`TD`)return[];let t=[],n=new Set,r=new Map;for(let t of e.edges){if(t.from===t.to)continue;let e=r.get(t.to)??[];e.push(t),r.set(t.to,e)}for(let[i,a]of r){if(a.length<2||!bt(a,e)||a.some(e=>n.has(e)))continue;let r={type:`fan-in`,edges:[...a],sharedNode:i,otherNodes:a.map(e=>e.from),junctionPoint:null,sharedPath:[],junctionDir:Ue,sharedNodeDir:Ue};for(let e of a)e.bundle=r,n.add(e);t.push(r)}let i=new Map;for(let t of e.edges){if(t.from===t.to||n.has(t))continue;let e=i.get(t.from)??[];e.push(t),i.set(t.from,e)}for(let[r,a]of i){if(a.length<2||!bt(a,e))continue;let i={type:`fan-out`,edges:[...a],sharedNode:r,otherNodes:a.map(e=>e.to),junctionPoint:null,sharedPath:[],junctionDir:Ue,sharedNodeDir:Ue};for(let e of a)e.bundle=i,n.add(e);t.push(i)}return t}function bt(e,t){if(e.length<2)return!1;let n=e[0].style,r=hn(t,e[0].from),i=hn(t,e[0].to);for(let a of e){if(a.style!==n||a.text.length>0)return!1;let e=hn(t,a.from),o=hn(t,a.to);if(e!==r||o!==i||e!==o)return!1}let a=e.every(t=>t.to===e[0].to),o=a?e.map(e=>e.from):e.map(e=>e.to);if(new Set(o).size!==o.length||e.some(e=>e.parallelLane))return!1;let s=t.config.graphDirection===`LR`?`x`:`y`,c=(a?e[0].to:e[0].from).gridCoord;if(!c)return!1;for(let t of e){let e=(a?t.from:t.to).gridCoord;if(!e)return!1;if(a){if(e[s]>=c[s])return!1}else if(e[s]<=c[s])return!1}return!0}function xt(e,t){let n=e.config.graphDirection,r=Z(t.sharedNode);if(t.type===`fan-in`){if(n===`TD`){let e=r.y-1;return{x:r.x+1,y:e}}return{x:r.x-1,y:r.y+1}}if(n===`TD`){let e=r.y+3;return{x:r.x+1,y:e}}return{x:r.x+3,y:r.y+1}}function St(e,t){let n=e.config.graphDirection;t.junctionPoint=xt(e,t);let r=t.junctionPoint;if(t.type===`fan-in`){t.junctionDir=n===`TD`?K:J,t.sharedNodeDir=n===`TD`?q:Y;let i=Z(t.sharedNode),a=Ge(n===`TD`?K:J),o=Ye(i,a);t.sharedPath=vt(e,r,o,a)??[r,o];for(let i of t.edges){let o=Z(i.from),s=Ge(n===`TD`?q:Y),c=Ye(o,s);i.pathToJunction=vt(e,c,r,s)??[c,r],i.startDir=s,i.endDir=a,i.path=[...i.pathToJunction,...t.sharedPath.slice(1)]}}else{t.junctionDir=n===`TD`?q:Y,t.sharedNodeDir=n===`TD`?K:J;let i=Z(t.sharedNode),a=Ge(n===`TD`?q:Y),o=Ye(i,a);t.sharedPath=vt(e,o,r,a)??[o,r];for(let i of t.edges){let o=Z(i.to),s=Ge(n===`TD`?K:J),c=Ye(o,s);i.pathToJunction=vt(e,r,c,s)??[r,c],i.startDir=a,i.endDir=s,i.path=[...t.sharedPath,...i.pathToJunction.slice(1)]}}}function Ct(e){for(let t of e.bundles)St(e,t)}function wt(){return new Map}function Tt(e,t,n,r){for(let i of ot(n)){if(tt(e,i))continue;let n=t.get(Xe(i));if(n!==void 0&&n!==r)return i}return null}function Et(e,t,n,r){for(let i of ot(n)){if(tt(e,i))continue;let n=Xe(i);t.has(n)||t.set(n,r)}}function Dt(){return new Map}function Ot(e,t){return e.to===t.from||t.to===e.from}var kt=2;function At(e,t,n,r){let i=new Map,a=new Map;for(let o of ot(n)){if(tt(e,o))continue;let n=t.get(Xe(o));if(n!==void 0)for(let e of n)e!==r&&Ot(e,r)&&(i.set(e,(i.get(e)??0)+1),a.has(e)||a.set(e,o))}for(let[e,t]of i)if(t>=kt)return a.get(e);return null}function jt(e,t,n,r){for(let i of ot(n)){if(tt(e,i))continue;let n=Xe(i),a=t.get(n);a===void 0&&(a=new Set,t.set(n,a)),a.add(r)}}function Q(e){return e.split(`
4
+ `)}function Mt(e){let t=Q(e);return Math.max(...t.map(e=>M(e)),0)}function Nt(e){return Q(e).length}var Pt={rectangle:{unicode:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`},ascii:{tl:`+`,tr:`+`,bl:`+`,br:`+`}},rounded:{unicode:{tl:`╭`,tr:`╮`,bl:`╰`,br:`╯`},ascii:{tl:`.`,tr:`.`,bl:`'`,br:`'`}},circle:{unicode:{tl:`◯`,tr:`◯`,bl:`◯`,br:`◯`},ascii:{tl:`o`,tr:`o`,bl:`o`,br:`o`}},doublecircle:{unicode:{tl:`◎`,tr:`◎`,bl:`◎`,br:`◎`},ascii:{tl:`@`,tr:`@`,bl:`@`,br:`@`}},diamond:{unicode:{tl:`◇`,tr:`◇`,bl:`◇`,br:`◇`},ascii:{tl:`<`,tr:`>`,bl:`<`,br:`>`}},hexagon:{unicode:{tl:`⌜`,tr:`⌝`,bl:`⌞`,br:`⌟`},ascii:{tl:`*`,tr:`*`,bl:`*`,br:`*`}},stadium:{unicode:{tl:`(`,tr:`)`,bl:`(`,br:`)`},ascii:{tl:`(`,tr:`)`,bl:`(`,br:`)`}},subroutine:{unicode:{tl:`╟`,tr:`╢`,bl:`╟`,br:`╢`},ascii:{tl:`|`,tr:`|`,bl:`|`,br:`|`}},cylinder:{unicode:{tl:`╭`,tr:`╮`,bl:`╰`,br:`╯`},ascii:{tl:`.`,tr:`.`,bl:`'`,br:`'`}},asymmetric:{unicode:{tl:`▷`,tr:`┐`,bl:`▷`,br:`┘`},ascii:{tl:`>`,tr:`+`,bl:`>`,br:`+`}},trapezoid:{unicode:{tl:`/`,tr:`\\`,bl:`└`,br:`┘`},ascii:{tl:`/`,tr:`\\`,bl:`+`,br:`+`}},"trapezoid-alt":{unicode:{tl:`┌`,tr:`┐`,bl:`\\`,br:`/`},ascii:{tl:`+`,tr:`+`,bl:`\\`,br:`/`}},parallelogram:{unicode:{tl:`/`,tr:`/`,bl:`/`,br:`/`},ascii:{tl:`/`,tr:`/`,bl:`/`,br:`/`}},"parallelogram-alt":{unicode:{tl:`\\`,tr:`\\`,bl:`\\`,br:`\\`},ascii:{tl:`\\`,tr:`\\`,bl:`\\`,br:`\\`}},"state-start":{unicode:{tl:`●`,tr:`●`,bl:`●`,br:`●`},ascii:{tl:`*`,tr:`*`,bl:`*`,br:`*`}},"state-end":{unicode:{tl:`◉`,tr:`◉`,bl:`◉`,br:`◉`},ascii:{tl:`@`,tr:`@`,bl:`@`,br:`@`}},document:{unicode:{tl:`┌`,tr:`┐`,bl:`╰`,br:`╮`},ascii:{tl:`+`,tr:`+`,bl:`'`,br:`~`}},"stacked-document":{unicode:{tl:`┌`,tr:`╗`,bl:`╰`,br:`╮`},ascii:{tl:`+`,tr:`#`,bl:`'`,br:`~`}},"stacked-process":{unicode:{tl:`┌`,tr:`╗`,bl:`└`,br:`╝`},ascii:{tl:`+`,tr:`#`,bl:`+`,br:`#`}},card:{unicode:{tl:`╱`,tr:`┐`,bl:`└`,br:`┘`},ascii:{tl:`/`,tr:`+`,bl:`+`,br:`+`}},"lined-process":{unicode:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`},ascii:{tl:`+`,tr:`+`,bl:`+`,br:`+`}},"divided-process":{unicode:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`},ascii:{tl:`+`,tr:`+`,bl:`+`,br:`+`}},"window-pane":{unicode:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`},ascii:{tl:`+`,tr:`+`,bl:`+`,br:`+`}},triangle:{unicode:{tl:`╱`,tr:`╲`,bl:`└`,br:`┘`},ascii:{tl:`/`,tr:`\\`,bl:`+`,br:`+`}},"flipped-triangle":{unicode:{tl:`┌`,tr:`┐`,bl:`╲`,br:`╱`},ascii:{tl:`+`,tr:`+`,bl:`\\`,br:`/`}},"filled-circle":{unicode:{tl:`●`,tr:`●`,bl:`●`,br:`●`},ascii:{tl:`*`,tr:`*`,bl:`*`,br:`*`}},"crossed-circle":{unicode:{tl:`╳`,tr:`╳`,bl:`╳`,br:`╳`},ascii:{tl:`X`,tr:`X`,bl:`X`,br:`X`}},"fork-join":{unicode:{tl:`━`,tr:`━`,bl:`━`,br:`━`},ascii:{tl:`=`,tr:`=`,bl:`=`,br:`=`}},"notched-pentagon":{unicode:{tl:`╱`,tr:`╲`,bl:`└`,br:`┘`},ascii:{tl:`/`,tr:`\\`,bl:`+`,br:`+`}},"sloped-rectangle":{unicode:{tl:`╱`,tr:`┐`,bl:`└`,br:`┘`},ascii:{tl:`/`,tr:`+`,bl:`+`,br:`+`}},flag:{unicode:{tl:`╭`,tr:`╮`,bl:`╰`,br:`╯`},ascii:{tl:`~`,tr:`~`,bl:`~`,br:`~`}},"bow-tie-rectangle":{unicode:{tl:`╲`,tr:`╱`,bl:`╱`,br:`╲`},ascii:{tl:`\\`,tr:`/`,bl:`/`,br:`\\`}},"half-rounded-rectangle":{unicode:{tl:`┌`,tr:`╮`,bl:`└`,br:`╯`},ascii:{tl:`+`,tr:`.`,bl:`+`,br:`'`}},brace:{unicode:{tl:`╭`,tr:`┐`,bl:`╰`,br:`┘`},ascii:{tl:`{`,tr:`+`,bl:`{`,br:`+`}},"brace-right":{unicode:{tl:`┌`,tr:`╮`,bl:`└`,br:`╯`},ascii:{tl:`+`,tr:`}`,bl:`+`,br:`}`}},braces:{unicode:{tl:`╭`,tr:`╮`,bl:`╰`,br:`╯`},ascii:{tl:`{`,tr:`}`,bl:`{`,br:`}`}},bolt:{unicode:{tl:`╱`,tr:`╲`,bl:`╲`,br:`╱`},ascii:{tl:`/`,tr:`\\`,bl:`\\`,br:`/`}},text:{unicode:{tl:` `,tr:` `,bl:` `,br:` `},ascii:{tl:` `,tr:` `,bl:` `,br:` `}},anchor:{unicode:{tl:` `,tr:` `,bl:` `,br:` `},ascii:{tl:` `,tr:` `,bl:` `,br:` `}}};function Ft(e,t){let n=Pt[e]??Pt.rectangle;return t?n.ascii:n.unicode}function It(e,t){let n=Q(e),r=Math.max(...n.map(e=>M(e)),0),i=n.length,a=2*t.padding+r,o=a+2,s=i+2*t.padding,c=s%2==0?s+1:s;return{width:o,height:c+2,labelArea:{x:1+t.padding,y:1+t.padding,width:r,height:i},gridColumns:[1,a,1],gridRows:[1,c,1]}}function Lt(e,t,n,r){let{width:i,height:a}=t,o=N(i-1,a-1),s={x:0,y:0},c={x:i-1,y:a-1},l=r?`-`:`─`,u=r?`|`:`│`;for(let e=s.x+1;e<c.x;e++)o[e][s.y]=l,o[e][c.y]=l;for(let e=s.y+1;e<c.y;e++)o[s.x][e]=u,o[c.x][e]=u;o[s.x][s.y]=n.tl,o[c.x][s.y]=n.tr,o[s.x][c.y]=n.bl,o[c.x][c.y]=n.br;let d=Q(e),f=i-1,p=a-1,m=Math.floor(p/2)-Math.floor((d.length-1)/2);for(let e=0;e<d.length;e++){let t=d[e],n=Math.floor(f/2)-Math.ceil(M(t)/2)+1,r=ae(t);for(let t=0;t<r.length;t++){let i=n+t,a=m+e;i>=0&&i<o.length&&a>=0&&a<o[0].length&&(o[i][a]=r[t])}}return o}function Rt(e,t,n){let{width:r,height:i}=t,a=n.x+Math.floor(r/2),o=n.y+Math.floor(i/2);return X(e,K)?{x:a,y:n.y}:X(e,q)?{x:a,y:n.y+i-1}:X(e,J)?{x:n.x,y:o}:X(e,Y)?{x:n.x+r-1,y:o}:X(e,Be)?{x:n.x,y:n.y}:X(e,ze)?{x:n.x+r-1,y:n.y}:X(e,He)?{x:n.x,y:n.y+i-1}:X(e,Ve)?{x:n.x+r-1,y:n.y+i-1}:{x:a,y:o}}var zt={getDimensions:It,render(e,t,n){return Lt(e,t,Ft(`rectangle`,n.useAscii),n.useAscii)},getAttachmentPoint:Rt},Bt={getDimensions(e,t){return{width:5,height:3,labelArea:{x:2,y:1,width:1,height:1},gridColumns:[1,3,1],gridRows:[1,1,1]}},render(e,t,n){let{width:r,height:i}=t,a=N(r-1,i-1),o=Math.floor(r/2);return n.useAscii?(a[0][0]=`.`,a[1][0]=`-`,a[2][0]=`-`,a[3][0]=`-`,a[4][0]=`.`,a[0][1]=`|`,a[o][1]=`*`,a[4][1]=`|`,a[0][2]=`'`,a[1][2]=`-`,a[2][2]=`-`,a[3][2]=`-`,a[4][2]=`'`):(a[0][0]=`╭`,a[1][0]=`─`,a[2][0]=`─`,a[3][0]=`─`,a[4][0]=`╮`,a[0][1]=`│`,a[o][1]=`●`,a[4][1]=`│`,a[0][2]=`╰`,a[1][2]=`─`,a[2][2]=`─`,a[3][2]=`─`,a[4][2]=`╯`),a},getAttachmentPoint(e,t,n){let{width:r,height:i}=t,a=n.x+Math.floor(r/2),o=n.y+Math.floor(i/2);return X(e,K)?{x:a,y:n.y}:X(e,q)?{x:a,y:n.y+i-1}:X(e,J)?{x:n.x,y:o}:X(e,Y)?{x:n.x+r-1,y:o}:{x:a,y:o}}},Vt={getDimensions(e,t){return{width:5,height:3,labelArea:{x:2,y:1,width:1,height:1},gridColumns:[1,3,1],gridRows:[1,1,1]}},render(e,t,n){let{width:r,height:i}=t,a=N(r-1,i-1),o=Math.floor(r/2);return n.useAscii?(a[0][0]=`#`,a[1][0]=`=`,a[2][0]=`=`,a[3][0]=`=`,a[4][0]=`#`,a[0][1]=`#`,a[o][1]=`*`,a[4][1]=`#`,a[0][2]=`#`,a[1][2]=`=`,a[2][2]=`=`,a[3][2]=`=`,a[4][2]=`#`):(a[0][0]=`╔`,a[1][0]=`═`,a[2][0]=`═`,a[3][0]=`═`,a[4][0]=`╗`,a[0][1]=`║`,a[o][1]=`◎`,a[4][1]=`║`,a[0][2]=`╚`,a[1][2]=`═`,a[2][2]=`═`,a[3][2]=`═`,a[4][2]=`╝`),a},getAttachmentPoint(e,t,n){let{width:r,height:i}=t,a=n.x+Math.floor(r/2),o=n.y+Math.floor(i/2);return X(e,K)?{x:a,y:n.y}:X(e,q)?{x:a,y:n.y+i-1}:X(e,J)?{x:n.x,y:o}:X(e,Y)?{x:n.x+r-1,y:o}:{x:a,y:o}}},Ht={getDimensions(e,t){let n=Q(e),r=Math.max(...n.map(e=>M(e)),0),i=n.length,a=2*t.padding+r,o=a+4,s=i+2*t.padding;return{width:o,height:Math.max(s+2,3),labelArea:{x:2+t.padding,y:1+t.padding,width:r,height:i},gridColumns:[2,a,2],gridRows:[1,s,1]}},render(e,t,n){let{width:r,height:i}=t,a=N(r-1,i-1),o=Math.floor(i/2),s=n.useAscii?`-`:`─`;if(i===3)a[0][o]=`(`,a[r-1][o]=`)`;else if(n.useAscii){for(let e=0;e<i;e++)a[0][e]=`(`,a[r-1][e]=`)`;for(let e=1;e<r-1;e++)a[e][0]=s,a[e][i-1]=s}else{a[0][0]=`╭`;for(let e=1;e<r-1;e++)a[e][0]=s;a[r-1][0]=`╮`;for(let e=1;e<i-1;e++)a[0][e]=`│`,a[r-1][e]=`│`;a[0][i-1]=`╰`;for(let e=1;e<r-1;e++)a[e][i-1]=s;a[r-1][i-1]=`╯`}let c=Q(e),l=o-Math.floor((c.length-1)/2);for(let e=0;e<c.length;e++){let t=c[e],n=Math.floor(r/2)-Math.floor(M(t)/2),o=ae(t);for(let t=0;t<o.length;t++){let s=n+t,c=l+e;s>0&&s<r-1&&c>=0&&c<i&&(a[s][c]=o[t])}}return a},getAttachmentPoint:Rt},Ut={getDimensions(e,t){let n=Q(e),r=Math.max(...n.map(e=>M(e)),0),i=n.length,a=2*t.padding+r,o=a+4,s=i+2*t.padding;return{width:o,height:s+2,labelArea:{x:2+t.padding,y:1+t.padding,width:r,height:i},gridColumns:[2,a,2],gridRows:[1,s,1]}},render(e,t,n){let{width:r,height:i}=t,a=N(r-1,i-1),o=n.useAscii?`-`:`─`,s=n.useAscii?`|`:`│`;a[0][0]=n.useAscii?`+`:`┌`,a[1][0]=n.useAscii?`+`:`┬`;for(let e=2;e<r-2;e++)a[e][0]=o;a[r-2][0]=n.useAscii?`+`:`┬`,a[r-1][0]=n.useAscii?`+`:`┐`;for(let e=1;e<i-1;e++)a[0][e]=s,a[1][e]=s,a[r-2][e]=s,a[r-1][e]=s;a[0][i-1]=n.useAscii?`+`:`└`,a[1][i-1]=n.useAscii?`+`:`┴`;for(let e=2;e<r-2;e++)a[e][i-1]=o;a[r-2][i-1]=n.useAscii?`+`:`┴`,a[r-1][i-1]=n.useAscii?`+`:`┘`;let c=Q(e),l=Math.floor(i/2)-Math.floor((c.length-1)/2);for(let e=0;e<c.length;e++){let t=c[e],n=Math.floor(r/2)-Math.floor(M(t)/2),o=ae(t);for(let t=0;t<o.length;t++){let s=n+t,c=l+e;s>1&&s<r-2&&c>0&&c<i-1&&(a[s][c]=o[t])}}return a},getAttachmentPoint:Rt},Wt={getDimensions:It,render(e,t,n){return Lt(e,t,Ft(`doublecircle`,n.useAscii),n.useAscii)},getAttachmentPoint:Rt},Gt={getDimensions(e,t){let n=Q(e),r=Math.max(...n.map(e=>M(e)),0),i=n.length,a=2*t.padding+r,o=a+2,s=i+2*t.padding+2;return{width:o,height:s+2,labelArea:{x:1+t.padding,y:2+t.padding,width:r,height:i},gridColumns:[1,a,1],gridRows:[2,s-2,2]}},render(e,t,n){let{width:r,height:i}=t,a=N(r-1,i-1),o=n.useAscii?`-`:`─`,s=n.useAscii?`|`:`│`;a[0][0]=n.useAscii?`.`:`╭`;for(let e=1;e<r-1;e++)a[e][0]=o;a[r-1][0]=n.useAscii?`.`:`╮`,a[0][1]=s;for(let e=1;e<r-1;e++)a[e][1]=o;a[r-1][1]=s;for(let e=2;e<i-2;e++)a[0][e]=s,a[r-1][e]=s;a[0][i-2]=s;for(let e=1;e<r-1;e++)a[e][i-2]=o;a[r-1][i-2]=s,a[0][i-1]=n.useAscii?`'`:`╰`;for(let e=1;e<r-1;e++)a[e][i-1]=o;a[r-1][i-1]=n.useAscii?`'`:`╯`;let c=Q(e),l=Math.floor(i/2)-Math.floor((c.length-1)/2);for(let e=0;e<c.length;e++){let t=c[e],n=Math.floor(r/2)-Math.floor(M(t)/2),o=ae(t);for(let t=0;t<o.length;t++){let s=n+t,c=l+e;s>0&&s<r-1&&c>1&&c<i-2&&(a[s][c]=o[t])}}return a},getAttachmentPoint:Rt},Kt={getDimensions:It,render(e,t,n){return Lt(e,t,Ft(`asymmetric`,n.useAscii),n.useAscii)},getAttachmentPoint:Rt},qt={getDimensions:It,render(e,t,n){return Lt(e,t,Ft(`trapezoid`,n.useAscii),n.useAscii)},getAttachmentPoint:Rt},Jt={getDimensions:It,render(e,t,n){return Lt(e,t,Ft(`trapezoid-alt`,n.useAscii),n.useAscii)},getAttachmentPoint:Rt},Yt={getDimensions:It,render(e,t,n){return Lt(e,t,Ft(`parallelogram`,n.useAscii),n.useAscii)},getAttachmentPoint:Rt},Xt={getDimensions:It,render(e,t,n){return Lt(e,t,Ft(`parallelogram-alt`,n.useAscii),n.useAscii)},getAttachmentPoint:Rt};function Zt(e){return{getDimensions:It,render(t,n,r){return Lt(t,n,Ft(e,r.useAscii),r.useAscii)},getAttachmentPoint:Rt}}var Qt=Zt(`circle`),$t=Zt(`diamond`),en=Zt(`rounded`),tn=Zt(`hexagon`),nn=new Map([[`rectangle`,zt],[`rounded`,en],[`diamond`,$t],[`stadium`,Ht],[`circle`,Qt],[`subroutine`,Ut],[`doublecircle`,Wt],[`hexagon`,tn],[`cylinder`,Gt],[`asymmetric`,Kt],[`trapezoid`,qt],[`trapezoid-alt`,Jt],[`parallelogram`,Yt],[`parallelogram-alt`,Xt],[`state-start`,Bt],[`state-end`,Vt]]);function rn(e){return nn.get(e)??zt}function an(e,t,n){return rn(e).getDimensions(t,n)}function on(e,t,n,r){return rn(e).getAttachmentPoint(t,n,r)}function sn(e,t,n){let r=n?{x:t.x+n.x,y:t.y+n.y}:t,i=0;for(let t=0;t<r.x;t++)i+=e.columnWidth.get(t)??0;let a=0;for(let t=0;t<r.y;t++)a+=e.rowHeight.get(t)??0;let o=e.columnWidth.get(r.x)??0,s=e.rowHeight.get(r.y)??0;return{x:i+Math.floor(o/2)+e.offsetX,y:a+Math.floor(s/2)+e.offsetY}}function cn(e,t){return t.map(t=>sn(e,t))}function ln(e,t,n,r){let i=r??bn(e,t);return rt(e.grid,n,3)?(it(e.grid,n,3),t.gridCoord=n,n):i===`LR`?ln(e,t,{x:n.x,y:n.y+4},i):ln(e,t,{x:n.x+4,y:n.y},i)}function un(e,t){let n=Z(t),r=e.config.boxBorderPadding,i=an(t.shape,t.displayLabel,{useAscii:e.config.useAscii,padding:r}),a=i.gridColumns,o=i.gridRows;for(let t=0;t<a.length;t++){let r=n.x+t,i=e.columnWidth.get(r)??0;e.columnWidth.set(r,Math.max(i,a[t]))}for(let t=0;t<o.length;t++){let r=n.y+t,i=e.rowHeight.get(r)??0;e.rowHeight.set(r,Math.max(i,o[t]))}if(n.x>0){let t=e.columnWidth.get(n.x-1)??0;e.columnWidth.set(n.x-1,Math.max(t,e.config.paddingX))}if(n.y>0){let r=e.config.paddingY;xn(e,t)&&(r+=4);let i=e.rowHeight.get(n.y-1)??0;e.rowHeight.set(n.y-1,Math.max(i,r))}}function dn(e,t){for(let n of t)e.columnWidth.has(n.x)||e.columnWidth.set(n.x,Math.floor(e.config.paddingX/2)),e.rowHeight.has(n.y)||e.rowHeight.set(n.y,Math.floor(e.config.paddingY/2))}var fn=8;function pn(e,t,n,r,i){let a=[];try{for(let o=0;o<fn;o++){let o=Tt(i,n,t.path,t.style)??At(i,r,t.path,t);if(!o)return;e.grid.add(Xe(o)),a.push(o),Jn(e,t)}}finally{for(let t of a)e.grid.delete(Xe(t))}}function mn(e,t){return e.subgraphs.some(e=>e.nodes.includes(t))}function hn(e,t){let n=null;for(let r of e.subgraphs)r.nodes.includes(t)&&(!n||gn(n,r))&&(n=r);return n}function gn(e,t){let n=t;for(;n!==null;){if(n===e)return!0;n=n.parent}return!1}function _n(e,t){let n=hn(e,t);if(!n)return null;let r=n;for(;r.parent;)r=r.parent;return r}function vn(e){let t=[...e.nodes];for(let n of e.children)t.push(...vn(n));return t}function yn(e,t,n){if(t===n)return!0;let r=new Set([t]),i=[t];for(;i.length>0;){let t=i.shift();for(let a of In(e,t)){if(a===n)return!0;r.has(a)||(r.add(a),i.push(a))}}return!1}function bn(e,t){let n=hn(e,t);return n?.direction?n.direction:e.config.graphDirection}function xn(e,t){let n=hn(e,t);if(!n)return!1;let r=!1;for(let i of e.edges)if(i.to===t&&hn(e,i.from)!==n){r=!0;break}if(!r)return!1;let i=Z(t).y;for(let r of n.nodes){if(r===t||!r.gridCoord)continue;let a=!1;for(let t of e.edges)if(t.to===r&&hn(e,t.from)!==n){a=!0;break}if(a&&r.gridCoord.y<i)return!1}return!0}function Sn(e,t){if(t.nodes.length===0)return;let n=1e6,r=1e6,i=-1e6,a=-1e6;for(let o of t.children)Sn(e,o),o.nodes.length>0&&(n=Math.min(n,o.minX),r=Math.min(r,o.minY),i=Math.max(i,o.maxX),a=Math.max(a,o.maxY));for(let e of t.nodes){if(!e.drawingCoord||!e.drawing)continue;let t=e.drawingCoord.x,o=e.drawingCoord.y,s=t+e.drawing.length-1,c=o+e.drawing[0].length-1;n=Math.min(n,t),r=Math.min(r,o),i=Math.max(i,s),a=Math.max(a,c)}t.minX=n-2,t.minY=r-2-2,t.maxX=i+2,t.maxY=a+2;let o=Math.max(0,...Q(t.name).map(e=>M(e))),s=t.maxX-t.minX,c=o+1;if(c>s){let e=c-s,n=Math.floor(e/2),r=e-n;t.minX-=n,t.maxX+=r}}function Cn(e){let t=e.subgraphs.filter(e=>e.parent===null&&e.nodes.length>0);for(let e=0;e<t.length;e++)for(let n=e+1;n<t.length;n++){let r=t[e],i=t[n];r.minX<i.maxX&&r.maxX>i.minX&&(r.maxY>=i.minY-1&&r.minY<i.minY?i.minY=r.maxY+1+1:i.maxY>=r.minY-1&&i.minY<r.minY&&(r.minY=i.maxY+1+1)),r.minY<i.maxY&&r.maxY>i.minY&&(r.maxX>=i.minX-1&&r.minX<i.minX?i.minX=r.maxX+1+1:i.maxX>=r.minX-1&&i.minX<r.minX&&(r.minX=i.maxX+1+1))}}function wn(e){for(let t of e.subgraphs)Sn(e,t);Cn(e)}function Tn(e){if(e.subgraphs.length===0)return;let t=0,n=0;for(let r of e.subgraphs)t=Math.min(t,r.minX),n=Math.min(n,r.minY);let r=-t,i=-n;if(r!==0||i!==0){e.offsetX=r,e.offsetY=i;for(let t of e.subgraphs)t.minX+=r,t.minY+=i,t.maxX+=r,t.maxY+=i;for(let t of e.nodes)t.drawingCoord&&(t.drawingCoord.x+=r,t.drawingCoord.y+=i)}}function En(e,t){let n=t=>{let n=In(e,t);return n.length>0?n[0].name:null},r=new Map,i=t.map((e,t)=>{let i=n(e);if(i===null)return t;let a=r.get(i);return a===void 0?(r.set(i,t),t):a});return t.map((e,t)=>({node:e,i:t})).sort((e,t)=>i[e.i]-i[t.i]||e.i-t.i).map(({node:e})=>e)}function Dn(e,t){let n=new Set,r=t=>{let r=[t];for(;r.length>0;){let t=r.shift();if(!n.has(t.name)){n.add(t.name);for(let n of In(e,t))r.push(n)}}};for(let e of t)r(e);let i=[...t];for(let t of e.nodes)n.has(t.name)||(i.push(t),r(t));return i}function On(e,t){return e.nodes.find(e=>e.gridCoord!==null&&e.gridCoord.x===t.x&&e.gridCoord.y===t.y)}function kn(e,t,n,r,i){let a=r===`x`?`y`:`x`,o=i=>{let o=4;for(;;){let s=t[r]+i*o;if(s<0)return null;let c=r===`x`?{x:s,y:t[a]}:{x:t[a],y:s};if(rt(e.grid,c,3))return c;let l=On(e,c);if(!l||_n(e,l)!==n)return null;o+=4}};return o(i)??o(i*-1)}function An(e,t,n,r){let i=_n(e,t);if(!i)return;let a=n.get(i);if(!a)return;n.delete(i);let o=Z(t),s=bn(e,t)===`LR`?`y`:`x`;for(let t of a){let n=bn(e,t),a=kn(e,o,i,s,1);ln(e,e.nodes[t.index],a??o,n),r.add(t)}}function jn(e,t){let n=!0;for(;n;){n=!1;let r=t=>e.config.graphDirection===`LR`?t.gridCoord?.y??0:t.gridCoord?.x??0,i=e.nodes.filter(e=>e.gridCoord!==null).sort((e,t)=>r(e)-r(t));for(let r of i){let i=r.gridCoord;if(i===null)continue;let a=[...In(e,r)].sort((t,n)=>Fn(e,t,n));for(let o of a){if(o.gridCoord!==null)continue;let a=hn(e,r),s=hn(e,o),c=a&&a===s&&a.direction?a.direction:e.config.graphDirection,l=c===`LR`?i.x+4:i.y+4,u;u=c===e.config.graphDirection?t[l]??0:c===`LR`?i.y:i.x;let d=c===`LR`?{x:l,y:u}:{x:u,y:l};ln(e,e.nodes[o.index],d,c),c===e.config.graphDirection&&(t[l]=u+4),n=!0}}}}function Mn(e){let t=e.config.graphDirection,n=[],r=new Set;for(let t of e.edges)t.from!==t.to&&r.add(t.to.name);let i=Dn(e,e.nodes.filter(e=>!r.has(e.name))).filter(t=>{let n=hn(e,t);if(!n)return!0;for(let r of e.edges)if(r.to===t&&hn(e,r.from)!==n)return!1;return!0}),a=new Set(i),o=[],s=[];for(let t of i){let n=_n(e,t);n!==null&&vn(n).some(n=>n!==t&&!a.has(n)&&!yn(e,t,n))?o.push(t):s.push(t)}let c=En(e,s),l=new Map;for(let t of o){let n=_n(e,t),r=l.get(n);r?r.push(t):l.set(n,[t])}let u=new Set,d=!1,f=!1;for(let t of c)mn(e,t)?In(e,t).length>0&&(f=!0):d=!0;let p=t===`LR`&&d&&f,m,h=[];p?(m=c.filter(t=>!mn(e,t)),h=c.filter(t=>mn(e,t))):m=c;for(let r of m){let i=t===`LR`?{x:0,y:n[0]??0}:{x:n[0]??0,y:0};ln(e,e.nodes[r.index],i),n[0]=(n[0]??0)+4,An(e,r,l,u)}if(p&&h.length>0)for(let r of h){let i=t===`LR`?{x:4,y:n[4]??0}:{x:n[4]??0,y:4};ln(e,e.nodes[r.index],i),n[4]=(n[4]??0)+4,An(e,r,l,u)}jn(e,n);for(let t of o){if(u.has(t))continue;let r=_n(e,t),i=bn(e,t),a=vn(r).filter(e=>e!==t&&e.gridCoord!==null),o;if(a.length>0){let t=a[0];for(let e of a)(i===`LR`?e.gridCoord.x<t.gridCoord.x:e.gridCoord.y<t.gridCoord.y)&&(t=e);let n=i===`LR`?`y`:`x`;o=kn(e,t.gridCoord,r,n,1)??{x:t.gridCoord.x,y:t.gridCoord.y}}else o=i===`LR`?{x:0,y:n[0]??0}:{x:n[0]??0,y:0},n[0]=(n[0]??0)+4;ln(e,e.nodes[t.index],o,i)}jn(e,n);for(let t of e.nodes)un(e,t);e.pathBudget=ft(),Kn(e),e.bundles=yt(e),Ct(e);let g=wt(),_=Dt(),v=et(e.grid);for(let t of e.edges){if(t.bundle&&t.path.length>0){dn(e,t.path),Et(v,g,t.path,t.style),jt(v,_,t.path,t),Zn(e,t);continue}Jn(e,t),pn(e,t,g,_,v),dn(e,t.path),Et(v,g,t.path,t.style),jt(v,_,t.path,t),Zn(e,t)}for(let t of e.nodes)t.drawingCoord=sn(e,Z(t)),t.drawing=Ar(t,e);wn(e),Tn(e),_e(e.canvas,e.columnWidth,e.rowHeight,e.offsetX,e.offsetY),ve(e.roleCanvas,e.columnWidth,e.rowHeight,e.offsetX,e.offsetY)}function Nn(e,t){return e.edges.filter(e=>e.from.name===t.name)}function Pn(e,t){let n=hn(e,t),r=[],i=n;for(;i!==null;)r.unshift(i),i=i.parent;return r}function Fn(e,t,n){let r=Pn(e,t),i=Pn(e,n),a=0;for(;a<r.length&&a<i.length&&r[a]===i[a];)a++;let o=r[a],s=i[a];return!o||!s||o===s?0:e.subgraphs.indexOf(s)-e.subgraphs.indexOf(o)}function In(e,t){return Nn(e,t).map(e=>e.to)}function Ln(e){return e===K?q:e===q?K:e===J?Y:e===Y?J:e===ze?He:e===Be?Ve:e===Ve?Be:e===He?ze:Ue}function $(e,t){return e.x===t.x?e.y<t.y?q:K:e.y===t.y?e.x<t.x?Y:J:e.x<t.x?e.y<t.y?Ve:ze:e.y<t.y?He:Be}function Rn(e){return e===`LR`?[Y,q,q,Y]:[q,Y,Y,q]}function zn(e,t){if(e.from===e.to)return Rn(t);let n=$(Z(e.from),Z(e.to)),r,i,a,o,s=t===`LR`?X(n,J)||X(n,Be)||X(n,He):X(n,K)||X(n,Be)||X(n,ze);return X(n,Ve)?t===`LR`?(r=q,i=J,a=Y,o=K):(r=Y,i=K,a=q,o=J):X(n,ze)?t===`LR`?(r=K,i=J,a=Y,o=q):(r=Y,i=q,a=K,o=J):X(n,He)?t===`LR`?(r=q,i=q,a=J,o=K):(r=J,i=K,a=q,o=Y):X(n,Be)?t===`LR`?(r=q,i=q,a=J,o=q):(r=Y,i=Y,a=K,o=Y):s?t===`LR`&&X(n,J)?(r=q,i=q,a=J,o=Y):t===`TD`&&X(n,K)?(r=Y,i=Y,a=K,o=q):(r=n,i=Ln(n),a=n,o=Ln(n)):(r=n,i=Ln(n),a=n,o=Ln(n)),[r,i,a,o]}var Bn=2,Vn=200;function Hn(e,t){let n=e.gridCoord;return n?t.x>=n.x&&t.x<=n.x+2&&t.y>=n.y&&t.y<=n.y+2:!1}function Un(e,t,n=[]){for(let r=1;r<t.length-1;r++){let i=t[r];if(tt(e.grid,i)&&!n.some(e=>Hn(e,i)))return!1}return!0}function Wn(e){let t=e.from.gridCoord,n=e.to.gridCoord;return!t||!n?!1:t.y===n.y&&t.x!==n.x}function Gn(e){let t=e.from.name,n=e.to.name;return Wn(e)&&n<t?JSON.stringify([n,t]):JSON.stringify([t,n])}function Kn(e){let t=new Map;for(let n of e.edges){if(n.from===n.to)continue;let e=Gn(n),r=t.get(e);r?r.push(n):t.set(e,[n])}for(let e of t.values()){if(e.length<2)continue;let t=new Set;for(let n=0;n<e.length;n++)e[n].parallelLane={index:n,total:e.length,usedOffsets:t}}}function qn(e,t,n,r,i){let a=Ye(Z(t.from),n),o=Ye(Z(t.to),r),s=X(n,J)||X(n,Y),c=[t.from,t.to],l=t.parallelLane.usedOffsets,u=X(n,Y)?1:X(n,J)?-1:X(n,q)?1:-1,d=X(r,Y)?1:X(r,J)?-1:X(r,q)?1:-1,f=s?{x:a.x+u,y:a.y}:{x:a.x,y:a.y+u},p=s?{x:o.x+d,y:o.y}:{x:o.x,y:o.y+d},m=[a,o],h=[a,o],g=Bn*i;for(let t=0;t<Vn;t++){let n=g+t;if(l.has(n))continue;let r=a.y+n,i=a.x+n,u=s?[{x:a.x,y:r},{x:o.x,y:r}]:[{x:i,y:a.y},{x:i,y:o.y}],d=mt([a,...u,o]);if(Un(e,ot(d),c))return l.add(n),{path:d,labelSegment:u};m=d,h=u;let _=s?f.x!==p.x:f.y!==p.y,v=s?_?[{x:f.x,y:r},{x:p.x,y:r}]:[{x:f.x,y:r},{x:f.x,y:r}]:_?[{x:i,y:f.y},{x:i,y:p.y}]:[{x:i,y:f.y},{x:i,y:f.y}],y=mt(s?[a,f,{x:f.x,y:r},{x:p.x,y:r},p,o]:[a,f,{x:i,y:f.y},{x:i,y:p.y},p,o]);if(Un(e,ot(y),c))return l.add(n),{path:y,labelSegment:v};m=y,h=v}return{path:m,labelSegment:h}}function Jn(e,t){let n=hn(e,t.from),r=hn(e,t.to),[i,a,o,s]=zn(t,n&&n===r&&n.direction?n.direction:e.config.graphDirection);if(t.parallelLane&&t.parallelLane.index>0){let n=X(i,a),r=n?o:i,c=n?s:a;t.startDir=r,t.endDir=c;let l=qn(e,t,r,c,t.parallelLane.index);t.path=l.path,t.text.length>0&&$n(e,t,l.labelSegment,M(t.text));return}let c=Ye(Z(t.from),i),l=Ye(Z(t.to),a),u=vt(e,c,l,Ge(i)),d=vt(e,Ye(Z(t.from),o),Ye(Z(t.to),s),Ge(o));if(u!==null&&d!==null){u.length<=d.length?(t.startDir=i,t.endDir=a,t.path=u):(t.startDir=o,t.endDir=s,t.path=d);return}if(u!==null){t.startDir=i,t.endDir=a,t.path=u;return}if(d!==null){t.startDir=o,t.endDir=s,t.path=d;return}t.startDir=i,t.endDir=a,t.path=Qn([c,l])}function Yn(e,t){for(let n of e.nodes){let e=n.gridCoord;if(e&&t>=e.x&&t<=e.x+2)return!0}return!1}function Xn(e,t,n,r){if(!Yn(e,r))return r;for(let i=1;i<=n-t;i++){let a=r+i;if(a<=n&&!Yn(e,a))return a;let o=r-i;if(o>=t&&!Yn(e,o))return o}return r}function Zn(e,t){if(t.text.length===0||t.parallelLane&&t.parallelLane.index>0)return;let n=M(t.text),r=Qn(t.path),i=r.length,a=[];for(let t=1;t<i;t++){let n=r[t-1],i=r[t],o=[n,i],s=er(e,o),c=n.x===i.x;a.push({line:o,width:s,index:t,isVertical:c})}let o=t=>Un(e,ot(t)),s=e=>e.index===1||e.index===a.length,c=a.filter(e=>e.width>=n&&!s(e)&&o(e.line)),l;if(c.length>0)c.sort((e,t)=>t.index-e.index),l=c[0].line;else{let e=a.filter(e=>e.width>=n&&o(e.line));if(e.length>0)e.sort((e,t)=>t.index-e.index),l=e[0].line;else{let e=a.filter(e=>!s(e)&&o(e.line)),n=a.filter(e=>o(e.line)),r=e.length>0?e:n.length>0?n:a;if(r.sort((e,t)=>t.width-e.width),r.length>0)l=r[0].line;else{let e=t.path[0]??{x:0,y:0};l=[e,e]}}}$n(e,t,l,n)}function Qn(e){let t=[];for(let n of e){let e=t[t.length-1];e&&e.x!==n.x&&e.y!==n.y&&t.push({x:n.x,y:e.y}),t.push(n)}return t}function $n(e,t,n,r){let i=Math.min(n[0].x,n[1].x),a=Math.max(n[0].x,n[1].x),o=Xn(e,i,a,i+Math.floor((a-i)/2)),s=e.columnWidth.get(o)??0;e.columnWidth.set(o,Math.max(s,r+2)),t.labelLine=[n[0],n[1]]}function er(e,t){let n=0,r=Math.min(t[0].x,t[1].x),i=Math.max(t[0].x,t[1].x);for(let t=r;t<=i;t++)n+=e.columnWidth.get(t)??0;return n}var tr={solid:{h:{unicode:`─`,ascii:`-`},v:{unicode:`│`,ascii:`|`}},dotted:{h:{unicode:`┄`,ascii:`.`},v:{unicode:`┆`,ascii:`:`}},thick:{h:{unicode:`━`,ascii:`=`},v:{unicode:`┃`,ascii:`‖`}},invisible:{h:{unicode:` `,ascii:` `},v:{unicode:` `,ascii:` `}}};function nr(e,t,n,r,i,a,o=`solid`){let s=$(t,n),c=[],l=tr[o],u=a?l.h.ascii:l.h.unicode,d=a?l.v.ascii:l.v.unicode;if(X(s,K))for(let a=t.y-r;a>=n.y-i;a--)c.push({x:t.x,y:a}),R(e,t.x,a,d);else if(X(s,q))for(let a=t.y+r;a<=n.y+i;a++)c.push({x:t.x,y:a}),R(e,t.x,a,d);else if(X(s,J))for(let a=t.x-r;a>=n.x-i;a--)c.push({x:a,y:t.y}),R(e,a,t.y,u);else if(X(s,Y))for(let a=t.x+r;a<=n.x+i;a++)c.push({x:a,y:t.y}),R(e,a,t.y,u);else if(X(s,Be)){for(let i=t.x-r;i>=n.x;i--)c.push({x:i,y:t.y}),R(e,i,t.y,u);for(let r=t.y-1;r>=n.y-i;r--)c.push({x:n.x,y:r}),R(e,n.x,r,d)}else if(X(s,ze)){for(let i=t.x+r;i<=n.x;i++)c.push({x:i,y:t.y}),R(e,i,t.y,u);for(let r=t.y-1;r>=n.y-i;r--)c.push({x:n.x,y:r}),R(e,n.x,r,d)}else if(X(s,He)){for(let i=t.x-r;i>=n.x;i--)c.push({x:i,y:t.y}),R(e,i,t.y,u);for(let r=t.y+1;r<=n.y+i;r++)c.push({x:n.x,y:r}),R(e,n.x,r,d)}else if(X(s,Ve)){if(n.x-t.x<=1)for(let a=t.y+r;a<=n.y+i;a++)c.push({x:t.x,y:a}),R(e,t.x,a,d);else{for(let i=t.x+r;i<=n.x;i++)c.push({x:i,y:t.y}),R(e,i,t.y,u);for(let r=t.y+1;r<=n.y+i;r++)c.push({x:n.x,y:r}),R(e,n.x,r,d)}}return c}function rr(e,t){if(t.path.length===0){let t=P(e.canvas);return[t,t,t,t,t,t]}let n=hr(e,t),[r,i,a]=ar(e,t.path,t.style),o=i.length>0,s=t.style===`invisible`,c=o&&!s?cr(e,t.path,i[0],t.from):P(e.canvas),l;l=t.hasArrowEnd&&o?fr(e,i[i.length-1],a[a.length-1],t.endMarker):P(e.canvas);let u;if(t.hasArrowStart&&o){let n=i[0][0],r=ir(a[0]),o={x:n.x,y:n.y};X(a[0],Y)?o.x=n.x-1:X(a[0],J)?o.x=n.x+1:X(a[0],q)?o.y=n.y-1:X(a[0],K)&&(o.y=n.y+1),u=fr(e,[n,o],r,t.startMarker)}else u=P(e.canvas);let d=s?P(e.canvas):pr(e,t.path);return[r,c,l,u,d,n]}function ir(e){return X(e,K)?q:X(e,q)?K:X(e,J)?Y:X(e,Y)?J:X(e,Be)?Ve:X(e,ze)?He:X(e,He)?ze:X(e,Ve)?Be:Ue}function ar(e,t,n=`solid`){let r=P(e.canvas),i=t[0],a=[],o=[];for(let s=1;s<t.length;s++){let c=t[s],l=sn(e,i),u=sn(e,c);if(Je(l,u)){i=c;continue}let d=$(i,c),f=nr(r,l,u,1,-1,e.config.useAscii,n);f.length===0&&f.push(l),a.push(f),o.push(d),i=c}return[r,a,o]}var or=new Set([`│`,`┃`,`║`,`┆`,`┊`,`|`,`‖`]),sr=new Set([`─`,`━`,`═`,`╌`,`┄`,`-`,`=`]);function cr(e,t,n,r){let i=P(e.canvas),a=e.config.useAscii;if(r.shape===`state-start`||r.shape===`state-end`)return i;let o=n[0],s=$(t[0],t[1]),c=a?`+`:null,l=(t,n)=>e.canvas[t]?.[n];if(X(s,K)){let e=o.x,t=o.y+1,n=l(e,t);R(i,e,t,n!==void 0&&sr.has(n)?c??`┴`:a?`|`:`│`)}else if(X(s,q)){let e=o.x,t=o.y-1,n=l(e,t);R(i,e,t,n!==void 0&&sr.has(n)?c??`┬`:a?`|`:`│`)}else if(X(s,J)||X(s,Y)){let e=r.drawingCoord,t=r.drawing;if(e===null||t===null)throw Error(`drawBoxStart: node "${r.name}" has no drawingCoord/drawing assigned`);let n=t.length,u=X(s,J)?e.x:e.x+n-1,d=o.y,f=l(u,d);R(i,u,d,f!==void 0&&or.has(f)?c??(X(s,J)?`┤`:`├`):a?`-`:`─`)}return i}function lr(e,t){if(t===`circle`)return e?`o`:`○`;if(t===`cross`)return e?`x`:`✕`}function ur(e){if(X(e,K))return`▲`;if(X(e,q))return`▼`;if(X(e,J))return`◄`;if(X(e,Y))return`►`;if(X(e,ze))return`↗`;if(X(e,Be))return`↖`;if(X(e,Ve))return`↘`;if(X(e,He))return`↙`}function dr(e){if(X(e,K))return`^`;if(X(e,q))return`v`;if(X(e,J))return`<`;if(X(e,Y))return`>`}function fr(e,t,n,r){let i=P(e.canvas);if(t.length===0)return i;let a=t[t.length-1],o=$(t.length>=2?t[t.length-2]:t[0],a);(t.length===1||X(o,Ue))&&(o=n);let s=lr(e.config.useAscii,r),c;if(s!==void 0)c=s;else if(e.config.useAscii){let e=dr(o);c=e===void 0?dr(n)??`*`:e}else{let e=ur(o);c=e===void 0?ur(n)??`●`:e}return R(i,a.x,a.y,c),i}function pr(e,t){let n=P(e.canvas);for(let r=1;r<t.length-1;r++){let i=t[r],a=sn(e,i),o=$(t[r-1],i),s=$(i,t[r+1]),c;c=e.config.useAscii?`+`:X(o,Y)&&X(s,q)||X(o,K)&&X(s,J)?`┐`:X(o,Y)&&X(s,K)||X(o,q)&&X(s,J)?`┘`:X(o,J)&&X(s,q)||X(o,K)&&X(s,Y)?`┌`:X(o,J)&&X(s,K)||X(o,q)&&X(s,Y)?`└`:`+`,R(n,a.x,a.y,c)}return n}function mr(e,t){return e.edges.some(e=>e!==t&&e.from===t.to&&e.to===t.from)}function hr(e,t){let n=P(e.canvas);if(t.text.length===0)return n;let r=cn(e,t.labelLine),i;if(t.path.length>=2){let e=t.path[0].y,n=t.path[t.path.length-1].y;n<e?i=!0:n>e&&(i=!1)}let a=mr(e,t);return gr(n,r,t.text,i,a),n}function gr(e,t,n,r,i=!1){if(t.length<2)return;let a=Math.min(t[0].x,t[1].x),o=Math.max(t[0].x,t[1].x),s=Math.min(t[0].y,t[1].y),c=Math.max(t[0].y,t[1].y),l=a+Math.floor((o-a)/2),u=s+Math.floor((c-s)/2);if(r!==void 0&&a===o){let e=c-s,t=Math.max(1,Math.floor(e/4));(i?r:!r)?u-=t:u+=t}let d=Q(n),f=u-Math.floor((d.length-1)/2);for(let t=0;t<d.length;t++){let n=d[t];V(e,{x:l-Math.floor(M(n)/2),y:f+t},n)}}function _r(e,t,n){let r=Z(t),i=0;for(let t=0;t<2;t++)i+=e.columnWidth.get(r.x+t)??0;let a=0;for(let t=0;t<2;t++)a+=e.rowHeight.get(r.y+t)??0;let o={width:i+1,height:a+1,labelArea:{x:0,y:0,width:0,height:0},gridColumns:[0,0,0],gridRows:[0,0,0]},s=t.drawingCoord;if(s===null)throw Error(`Node "${t.name}" has no drawingCoord; grid layout must run before bundled-edge drawing`);return on(t.shape,n,o,s)}function vr(e,t,n){let r=P(e.canvas),i=t.pathToJunction;if(!i||i.length===0)return[r,r,r,r,r,r];let a=P(e.canvas),o=e.config.useAscii,s=i.map((r,a)=>n.type===`fan-in`&&a===0?_r(e,t.from,t.startDir):n.type===`fan-out`&&a===i.length-1?_r(e,t.to,t.endDir):sn(e,r));for(let e=1;e<s.length;e++){let n=s[e-1],r=s[e];Je(n,r)||nr(a,n,r,1,-1,o,t.style)}let c=P(e.canvas);for(let t=1;t<i.length-1;t++){let n=i[t],r=sn(e,n),a=$(i[t-1],n),s=$(n,i[t+1]),l;l=o?`+`:X(a,Y)&&X(s,q)||X(a,K)&&X(s,J)?`┐`:X(a,Y)&&X(s,K)||X(a,q)&&X(s,J)?`┘`:X(a,J)&&X(s,q)||X(a,K)&&X(s,Y)?`┌`:X(a,J)&&X(s,K)||X(a,q)&&X(s,Y)?`└`:`+`,R(c,r.x,r.y,l)}let l=P(e.canvas);if(n.type===`fan-in`&&i.length>=2){let e=s[0],t=$(i[0],i[1]),n=o?`+`:null;X(t,K)?R(l,e.x,e.y,n??`┴`):X(t,q)?R(l,e.x,e.y,n??`┬`):X(t,J)?R(l,e.x,e.y,n??`┤`):X(t,Y)&&R(l,e.x,e.y,n??`├`)}return[a,l,r,r,c,P(e.canvas)]}function yr(e,t){let n=P(e.canvas),r=P(e.canvas);if(t.sharedPath.length<2)return[n,r];let i=e.config.useAscii,a=t.edges[0]?.style??`solid`,o=e.config.graphDirection,s=t.sharedPath.map((n,r)=>{if(t.type===`fan-in`&&r===t.sharedPath.length-1){let n=o===`TD`?K:J;return _r(e,t.sharedNode,n)}if(t.type===`fan-out`&&r===0){let n=o===`TD`?q:Y;return _r(e,t.sharedNode,n)}return sn(e,n)});for(let e=1;e<s.length;e++){let t=s[e-1],r=s[e];Je(t,r)||nr(n,t,r,1,-1,i,a)}for(let n=1;n<t.sharedPath.length-1;n++){let a=t.sharedPath[n],o=sn(e,a),s=$(t.sharedPath[n-1],a),c=$(a,t.sharedPath[n+1]),l;l=i?`+`:X(s,Y)&&X(c,q)||X(s,K)&&X(c,J)?`┐`:X(s,Y)&&X(c,K)||X(s,q)&&X(c,J)?`┘`:X(s,J)&&X(c,q)||X(s,K)&&X(c,Y)?`┌`:X(s,J)&&X(c,K)||X(s,q)&&X(c,Y)?`└`:`+`,R(r,o.x,o.y,l)}return[n,r]}function br(e,t){let n=P(e.canvas);if(t.sharedPath.length<2)return n;let r=t.sharedPath.length-1,i=t.sharedPath[r-1],a=t.sharedPath[r],o=$(i,a),s=e.config.graphDirection,c=s===`TD`?K:J,l=_r(e,t.sharedNode,c);s===`TD`?--l.y:--l.x;let u=t.edges[0]?.endMarker,d=t.edges.every(e=>e.endMarker===u)?u:void 0,f=lr(e.config.useAscii,d),p;return p=f===void 0?e.config.useAscii?X(o,K)?`^`:X(o,q)?`v`:X(o,J)?`<`:X(o,Y)?`>`:`v`:X(o,K)?`▲`:X(o,q)?`▼`:X(o,J)?`◄`:X(o,Y)?`►`:`▼`:f,R(n,l.x,l.y,p),n}function xr(e,t){let n=P(e.canvas);if(!t.pathToJunction||t.pathToJunction.length<2)return n;let r=t.pathToJunction.length-1,i=t.pathToJunction[r-1],a=t.pathToJunction[r],o=$(i,a),s=e.config.graphDirection,c=s===`TD`?K:J,l=_r(e,t.to,c);s===`TD`?--l.y:--l.x;let u=lr(e.config.useAscii,t.endMarker),d;return d=u===void 0?e.config.useAscii?X(o,K)?`^`:X(o,q)?`v`:X(o,J)?`<`:X(o,Y)?`>`:`v`:X(o,K)?`▲`:X(o,q)?`▼`:X(o,J)?`◄`:X(o,Y)?`►`:`▼`:u,R(n,l.x,l.y,d),n}function Sr(e){return X(e,K)?q:X(e,q)?K:X(e,J)?Y:X(e,Y)?J:e}function Cr(e,t){let n=P(e.canvas);if(t.sharedPath.length<2)return n;let r=t.sharedPath[0],i=t.sharedPath[1],a=Sr($(r,i)),o=e.config.graphDirection,s=o===`TD`?q:Y,c=_r(e,t.sharedNode,s);o===`TD`?c.y+=1:c.x+=1;let l;return l=e.config.useAscii?X(a,K)?`^`:X(a,q)?`v`:X(a,J)?`<`:X(a,Y)?`>`:`^`:X(a,K)?`▲`:X(a,q)?`▼`:X(a,J)?`◄`:X(a,Y)?`►`:`▲`,R(n,c.x,c.y,l),n}function wr(e,t){let n=P(e.canvas);if(!t.pathToJunction||t.pathToJunction.length<2)return n;let r=t.pathToJunction[0],i=t.pathToJunction[1],a=Sr($(r,i)),o=_r(e,t.from,t.startDir);X(t.startDir,K)?--o.y:X(t.startDir,q)?o.y+=1:X(t.startDir,J)?--o.x:X(t.startDir,Y)&&(o.x+=1);let s;return s=e.config.useAscii?X(a,K)?`^`:X(a,q)?`v`:X(a,J)?`<`:X(a,Y)?`>`:`v`:X(a,K)?`▲`:X(a,q)?`▼`:X(a,J)?`◄`:X(a,Y)?`►`:`▼`,R(n,o.x,o.y,s),n}function Tr(e,t){let n=P(e.canvas);if(!t.junctionPoint)return n;let r=sn(e,t.junctionPoint),i=e.config.useAscii,a=!1,o=!1,s=!1,c=!1;if(t.sharedPath.length>=2){let e=t.type===`fan-in`?0:t.sharedPath.length-1,n=t.type===`fan-in`?1:t.sharedPath.length-2,r=$(t.sharedPath[e],t.sharedPath[n]);X(r,q)?o=!0:X(r,K)?a=!0:X(r,Y)?c=!0:X(r,J)&&(s=!0)}for(let e of t.edges)if(e.pathToJunction&&e.pathToJunction.length>=2){let n=t.type===`fan-in`?e.pathToJunction.length-1:0,r=t.type===`fan-in`?e.pathToJunction.length-2:1,i=$(e.pathToJunction[r],e.pathToJunction[n]);X(i,q)?a=!0:X(i,K)?o=!0:X(i,Y)?s=!0:X(i,J)&&(c=!0)}let l;return l=i?`+`:a&&o&&s&&c?`┼`:o&&s&&c&&!a?`┬`:a&&s&&c&&!o?`┴`:a&&o&&c&&!s?`├`:a&&o&&s&&!c?`┤`:s&&c?`─`:a&&o?`│`:o&&c?`┌`:o&&s?`┐`:a&&c?`└`:a&&s?`┘`:`┼`,R(n,r.x,r.y,l),n}function Er(e,t){let n=e.maxX-e.minX,r=e.maxY-e.minY;if(n<=0||r<=0)return N(0,0);let i={x:0,y:0},a={x:n,y:r},o=N(n,r);if(t.config.useAscii){for(let e=i.x+1;e<a.x;e++)R(o,e,i.y,`-`);for(let e=i.x+1;e<a.x;e++)R(o,e,a.y,`-`);for(let e=i.y+1;e<a.y;e++)R(o,i.x,e,`|`);for(let e=i.y+1;e<a.y;e++)R(o,a.x,e,`|`);R(o,i.x,i.y,`+`),R(o,a.x,i.y,`+`),R(o,i.x,a.y,`+`),R(o,a.x,a.y,`+`)}else{for(let e=i.x+1;e<a.x;e++)R(o,e,i.y,`─`);for(let e=i.x+1;e<a.x;e++)R(o,e,a.y,`─`);for(let e=i.y+1;e<a.y;e++)R(o,i.x,e,`│`);for(let e=i.y+1;e<a.y;e++)R(o,a.x,e,`│`);R(o,i.x,i.y,`┌`),R(o,a.x,i.y,`┐`),R(o,i.x,a.y,`└`),R(o,a.x,a.y,`┘`)}return o}function Dr(e,t){let n=e.maxX-e.minX,r=e.maxY-e.minY;if(n<=0||r<=0)return[N(0,0),{x:0,y:0},[]];let i=N(n,r),a=[],o=Q(e.name);for(let e=0;e<o.length;e++){let t=o[e],s=1+e,c=1+Math.ceil((n-1-M(t))/2);c<1&&(c=1);let l=ae(t);for(let e=0;e<l.length;e++)c+e>=n||s>=r||(R(i,c+e,s,l[e]),a.push({x:c+e,y:s}))}return[i,{x:e.minX,y:e.minY},a]}function Or(e,t){return kr(e,t)}function kr(e,t){let n=Z(e),r=t.config.useAscii,i=0;for(let e=0;e<2;e++)i+=t.columnWidth.get(n.x+e)??0;let a=0;for(let e=0;e<2;e++)a+=t.rowHeight.get(n.y+e)??0;let o={x:0,y:0},s={x:i,y:a},c=N(Math.max(o.x,s.x),Math.max(o.y,s.y)),l=Ft(e.shape,r),u=e.shape===`state-end`,d=r?u?`=`:`-`:u?`═`:`─`,f=r?u?`‖`:`|`:u?`║`:`│`,p=u?r?{tl:`#`,tr:`#`,bl:`#`,br:`#`}:{tl:`╔`,tr:`╗`,bl:`╚`,br:`╝`}:l;for(let e=o.x+1;e<s.x;e++)R(c,e,o.y,d);for(let e=o.x+1;e<s.x;e++)R(c,e,s.y,d);for(let e=o.y+1;e<s.y;e++)R(c,o.x,e,f);for(let e=o.y+1;e<s.y;e++)R(c,s.x,e,f);if(R(c,o.x,o.y,p.tl),R(c,s.x,o.y,p.tr),R(c,o.x,s.y,p.bl),R(c,s.x,s.y,p.br),e.shape===`cylinder`&&s.y-o.y>=4)for(let e of[o.y+1,s.y-1]){for(let t=o.x+1;t<s.x;t++)R(c,t,e,d);R(c,o.x,e,f),R(c,s.x,e,f)}let m=e.displayLabel,h=Q(m),g=o.y+Math.floor(a/2)-Math.floor((h.length-1)/2);for(let e=0;e<h.length;e++){let t=h[e],n=M(t),r=o.x+Math.floor(i/2)-Math.ceil(n/2)+1,a=ae(t);for(let t=0;t<a.length;t++)R(c,r+t,g+e,a[t])}return c}function Ar(e,t){return Or(e,t)}function jr(e){return/^[┌┐└┘├┤┬┴┼│─╭╮╰╯+\-|]$/.test(e)?`border`:`text`}function Mr(e,t=1){let n=Math.max(0,t),r=0;for(let t of e)for(let e of t)r=Math.max(r,M(e));let i=0;for(let t of e)i+=Math.max(t.length,1);return{width:r+2*n+2,height:i+(e.length-1)+2}}function Nr(e,t,n=1){let r=Math.max(0,n),{width:i,height:a}=Mr(e,r),o=t?`-`:`─`,s=t?`|`:`│`,c=t?`+`:`┌`,l=t?`+`:`┐`,u=t?`+`:`└`,d=t?`+`:`┘`,f=t?`+`:`├`,p=t?`+`:`┤`,m=N(i-1,a-1);R(m,0,0,c);for(let e=1;e<i-1;e++)R(m,e,0,o);R(m,i-1,0,l),R(m,0,a-1,u);for(let e=1;e<i-1;e++)R(m,e,a-1,o);R(m,i-1,a-1,d);for(let e=1;e<a-1;e++)R(m,0,e,s),R(m,i-1,e,s);let h=1;for(let t=0;t<e.length;t++){let n=e[t],a=n.length>0?n:[``];for(let e of a){let t=1+r,n=ae(e);for(let e=0;e<n.length;e++)R(m,t+e,h,n[e]);h++}if(t<e.length-1){R(m,0,h,f);for(let e=1;e<i-1;e++)R(m,e,h,o);R(m,i-1,h,p),h++}}return m}function Pr(e){function t(e){return e.parent===null?0:1+t(e.parent)}let n=[...e];return n.sort((e,n)=>t(e)-t(n)),n}function Fr(e,t,n,r){for(let i=0;i<t.length;i++)for(let a=0;a<(t[0]?.length??0);a++){let o=t[i]?.[a];if(o&&o!==` `){let t=i+n.x,o=a+n.y;t>=0&&o>=0&&I(e,t,o,r)}}}function Ir(e,t,n,r){for(let i of t)Fr(e,i,n,r)}function Lr(e,t,n){let r=e=>/^[┌┐└┘├┤┬┴┼│─╭╮╰╯+\-|.':]$/.test(e);for(let i=0;i<t.length;i++)for(let a=0;a<(t[0]?.length??0);a++){let o=t[i]?.[a];if(o&&o!==` `){let t=i+n.x,s=a+n.y;t>=0&&s>=0&&I(e,t,s,r(o)?`border`:`text`)}}}function Rr(e){let t=e.config.useAscii,n={x:0,y:0},r=Pr(e.subgraphs);for(let n of r){let r=Er(n,e),i={x:n.minX,y:n.minY};e.canvas=B(e.canvas,i,t,r),Fr(e.roleCanvas,r,i,`border`)}for(let n of e.nodes)!n.drawn&&n.drawingCoord&&n.drawing&&(e.canvas=B(e.canvas,n.drawingCoord,t,n.drawing),Lr(e.roleCanvas,n.drawing,n.drawingCoord),n.drawn=!0);let i=[],a=[],o=[],s=[],c=[],l=[],u=[],d=new Set;for(let t of e.edges)if(t.bundle&&t.pathToJunction){let n=t.bundle,[r,f,,,p,m]=vr(e,t,n);if(i.push(r),a.push(p),c.push(f),l.push(m),n.type===`fan-in`&&t.hasArrowStart){let n=wr(e,t);s.push(n)}if(!d.has(n)){d.add(n);let[t,r]=yr(e,n);if(i.push(t),a.push(r),n.type===`fan-in`){let t=br(e,n);o.push(t)}if(n.type===`fan-out`&&n.edges.every(e=>e.hasArrowStart)){let t=Cr(e,n);s.push(t)}let c=Tr(e,n);u.push(c)}if(n.type===`fan-out`&&t.hasArrowEnd){let n=xr(e,t);o.push(n)}}else{let[n,r,u,d,f,p]=rr(e,t);i.push(n),a.push(f),o.push(u),s.push(d),c.push(r),l.push(p)}let f=fe(i);e.canvas=B(e.canvas,n,t,...f),Ir(e.roleCanvas,f,n,`line`),e.canvas=B(e.canvas,n,t,...a),Ir(e.roleCanvas,a,n,`corner`),e.canvas=B(e.canvas,n,t,...u),Ir(e.roleCanvas,u,n,`junction`),e.canvas=B(e.canvas,n,t,...o),Ir(e.roleCanvas,o,n,`arrow`),e.canvas=B(e.canvas,n,t,...c),Ir(e.roleCanvas,c,n,`junction`),e.canvas=B(e.canvas,n,t,...s),Ir(e.roleCanvas,s,n,`arrow`),e.canvas=B(e.canvas,n,t,...l),Ir(e.roleCanvas,l,n,`text`);for(let n of e.subgraphs){if(n.nodes.length===0)continue;let[r,i,a]=Dr(n,e);e.canvas=B(e.canvas,i,t,r),Fr(e.roleCanvas,r,i,`text`);for(let{x:t,y:n}of a){let a=r[t]?.[n];a===` `&&(R(e.canvas,t+i.x,n+i.y,a),I(e.roleCanvas,t+i.x,n+i.y,`text`))}}return e.canvas}function zr(e,t,n,r){if(r(e))return e;let i=Math.max(e-t,n-e);for(let a=1;a<=i;a++){let i=e+a;if(i<=n&&r(i))return i;let o=e-a;if(o>=t&&r(o))return o}}function Br(e){let t=e.keys.length>0?` `+e.keys.join(`,`):``;return`${e.type} ${e.name}${t}`}function Vr(e){let t=Q(e.label),n=e.attributes.map(Br);return n.length===0?[t]:[t,n]}function Hr(e,t,n=!1,r=!1){if(t)switch(e){case`one`:return r?`+`:`|`;case`zero-one`:return n?`o|`:`|o`;case`many`:return n?`<`:`>`;case`zero-many`:return n?`o<`:`>o`}else switch(e){case`one`:return r?`┼`:`│`;case`zero-one`:return n?`○│`:`│○`;case`many`:return n?`╟`:`╢`;case`zero-many`:return n?`○╟`:`╢○`}}function Ur(e){let t=new Set,n=[],r=new Map;for(let t of e.entities)r.set(t.id,new Set);for(let t of e.relationships)r.get(t.entity1)?.add(t.entity2),r.get(t.entity2)?.add(t.entity1);function i(e,n){let i=[e];for(;i.length>0;){let e=i.pop();if(!t.has(e)){t.add(e),n.add(e);for(let n of r.get(e)??[])t.has(n)||i.push(n)}}}for(let r of e.entities)if(!t.has(r.id)){let e=new Set;i(r.id,e),e.size>0&&n.push(e)}return n}function Wr(e,t,n){let r=e.get(t);if(r===void 0)throw Error(`ER diagram layout: missing ${n} for entity "${t}"`);return r}function Gr(n,r,i,a){let o=(0,e.splitStatements)(n),s=(0,t.parseErDiagram)(o);if(s.entities.length===0)return``;let c=r.useAscii,l=Ke(r.paddingX,5,6,6),u=Ke(r.paddingY,5,4,2),d=Ke(r.paddingY,5,2,1),f=Math.max(...[`one`,`zero-one`,`many`,`zero-many`].flatMap(e=>[Hr(e,c,!1).length,Hr(e,c,!0).length])),p=new Map,m=new Map,h=new Map,g=new Map;for(let e of s.entities){g.set(e.id,e);let t=Vr(e);p.set(e.id,t);let{width:n,height:i}=Mr(t,r.boxBorderPadding);m.set(e.id,n),h.set(e.id,i)}let _=new Map;for(let e of s.relationships){if(!e.label)continue;let t=[e.entity1,e.entity2].sort().join(`|`),n=Mt(e.label);_.set(t,Math.max(_.get(t)??0,n))}let v=Ur(s),y=new Map,b=0;for(let e of v){let t=s.entities.filter(t=>e.has(t.id)),n=Math.max(2,Math.ceil(Math.sqrt(t.length))),r=0,i=0,a=0;for(let e=0;e<t.length;e++){let o=t[e],s=Wr(m,o.id,`box width`),c=Wr(h,o.id,`box height`);a>=n&&(b+=i+u,r=0,i=0,a=0),y.set(o.id,{entity:o,sections:Wr(p,o.id,`sections`),x:r,y:b,width:s,height:c});let d=l,f=a+1>=n,g=t[e+1];if(!f&&g){let e=[o.id,g.id].sort().join(`|`),t=_.get(e)??0;t>0&&(d=Math.max(d,t+2))}r+=s+d,i=Math.max(i,c),a++}b+=i+d}let x=0,S=0;for(let e of y.values())x=Math.max(x,e.x+e.width),S=Math.max(S,e.y+e.height);x+=4,S+=2;let C=N(x-1,S-1),w=F(x-1,S-1);function T(e,t,n,r){R(C,e,t,n,{role:r,roleCanvas:w})}function E(e,t){let n=w[e]?.[t];return n===`text`||n===`border`}function D(e,t,n,r,i){for(let a=0;a<e.length;a++){let e=t+a;if(!(e<r||e>i)&&E(e,n))return!1}return!0}function ee(e,t,n,r,i,a){for(let a=0;a<e.length;a++){let e=t+a;if(!(e<r||e>i)&&(E(e,n)||w[e]?.[n]===`arrow`||O.has(`${e},${n}`)))return!1}if(!a)return!0;for(let a=t-2;a<=t+e.length;a++)if(!(a<r-2||a>i+1)&&w[a]?.[n]===`line`&&!B.has(`${a},${n}`))return!1;return!0}for(let e of y.values()){let t=Nr(e.sections,c,r.boxBorderPadding);for(let n=0;n<t.length;n++)for(let r=0;r<t[0].length;r++){let i=t[n][r];if(i!==` `){let t=e.x+n,a=e.y+r;t<x&&a<S&&T(t,a,i,jr(i))}}}let O=new Set;for(let e of y.values())for(let t=0;t<e.height;t++)for(let n=0;n<e.width;n++)O.add(`${e.x+n},${e.y+t}`);function k(e,t,n,r){O.has(`${e},${t}`)||(r===`text`||w[e]?.[t]!==`text`)&&(ce(n)!==`dashed`||ce(C[e]?.[t])!==`solid`)&&(T(e,t,n,r),r===`line`&&B.add(`${e},${t}`))}function te(e,t,n,r){w[e-1]?.[t]!==`text`&&w[e+1]?.[t]!==`text`&&k(e,t,n,r)}function ne(e,t,n,r){for(let i=n;i<=r;i++)for(let n=e;n<=t;n++){let e=C[n]?.[i];if(e!==void 0&&e!==` `)return!1}return!0}let A=[];function j(e,t,n){for(let r of A)if(Math.abs(r.x-e)===1&&t<=r.yEnd&&n>=r.yStart)return!0;return!1}function re(e,t,n){for(let r of A)if(!(Math.abs(r.x-e)>1)&&t<=r.yEnd&&n>=r.yStart)return!0;return!1}function ie(e,t,n){A.push({x:e,yStart:t,yEnd:n})}let M=c?`-`:`─`,P=c?`|`:`│`,I=c?`.`:`╌`,L=c?`:`:`┊`;function ce(e){if(e===M||e===P)return`solid`;if(e===I||e===L)return`dashed`}function le(e,t){return c?`+`:e===`down`?t===`right`?`┌`:`┐`:t===`right`?`└`:`┘`}function z(e,t,n,r){k(e,t,le(n,r),`line`)}let ue=new Map,de=new Map;for(let e of s.relationships){let t=y.get(e.entity1),n=y.get(e.entity2);if(!t||!n)continue;let r=t.y+Math.floor(t.height/2),i=n.y+Math.floor(n.height/2);if(Math.abs(r-i)<Math.max(t.height,n.height))continue;let[a,o]=r<i?[t,n]:[n,t],s=a.x+Math.floor(a.width/2),c=o.x+Math.floor(o.width/2),l=de.get(a.entity.id);l||(l=[],de.set(a.entity.id,l)),l.push({rel:e,otherCenterX:c});let u=ue.get(o.entity.id);u||(u=[],ue.set(o.entity.id,u)),u.push({rel:e,otherCenterX:s})}function fe(e,t,n){let r=n.get(e.entity.id),i=e.x+Math.floor(e.width/2);if(!r||r.length<=1)return i;let a=[...r].sort((e,t)=>e.otherCenterX-t.otherCenterX),o=a.findIndex(e=>e.rel===t);if(o===-1)return i;let s=Math.min(1,Math.floor((e.width-1)/2)),c=Math.max(0,e.width-1-s*2),l=a.length>1?c/(a.length-1):0;return e.x+s+Math.round(o*l)}let B=new Set;for(let e of s.relationships){B=new Set;let t=y.get(e.entity1),n=y.get(e.entity2);if(!t||!n)continue;let r=e.identifying?M:I,i=e.identifying?P:L,a=t.x+Math.floor(t.width/2),o=t.y+Math.floor(t.height/2),s=n.x+Math.floor(n.width/2),l=n.y+Math.floor(n.height/2);if(Math.abs(o-l)<Math.max(t.height,n.height)){let[o,l]=a<s?[t,n]:[n,t],[d,p]=a<s?[e.cardinality1,e.cardinality2]:[e.cardinality2,e.cardinality1],m=o.x+o.width,h=l.x-1,g=o.y+Math.floor(o.height/2),_;for(let e of y.values())e!==o&&e!==l&&e.y===o.y&&e.x<h+1&&e.x+e.width>m&&(_=Math.max(_??0,e.y+e.height));let v=h-m+1,b=+(v>=f+1),x=Hr(d,c,!1),S=Hr(p,c,!0),T=+(v>=3&&x[0]===P),E=+(v>=3&&S[S.length-1]===P),ee=m+T,O=h-E,A;if(_===void 0){for(let e=m;e<=h;e++)te(e,g,r,`line`);if(A=g+1,e.label){let t=m+b,n=h-b,r=Q(e.label).length,i=g+1+Math.max(u-1,1);for(;A<i&&!ne(t,n,A,A+r-1);)A++}}else{let t=Math.max(o.y+o.height,l.y+l.height,_),n=e.label?Q(e.label).length:0,a=t+1,s=t+Math.max(u*3,4);for(;a<s&&!ne(m,h,a,a+n);)a++;se(C,h+1,a+n+1),oe(w,h+1,a+n+1);for(let e=g;e<=a;e++)k(m,e,i,`line`),k(h,e,i,`line`);for(let e=m;e<=h;e++)te(e,a,r,`line`);m!==h&&(z(m,a,`up`,`right`),z(h,a,`up`,`left`)),A=a+1}for(let e=0;e<x.length;e++)k(ee+e,g,x[e],`arrow`);for(let e=0;e<S.length;e++)k(O-S.length+1+e,g,S[e],`arrow`);if(e.label){let t=Q(e.label),n=Math.floor((m+h)/2),r=m+b,i=h-b;for(let e=0;e<t.length;e++){let a=t[e],o=ae(a),s=Math.max(r,n-Math.floor(o.length/2)),c=A+e;if(se(C,Math.max(s+o.length,1),Math.max(c+1,1)),oe(w,Math.max(s+o.length,1),Math.max(c+1,1)),D(o,s,c,r,i))for(let e=0;e<o.length;e++){let t=s+e;t>=r&&t<=i&&k(t,c,o[e],`text`)}}}}else{let[a,s]=o<l?[t,n]:[n,t],[u,d]=o<l?[e.cardinality1,e.cardinality2]:[e.cardinality2,e.cardinality1],f=a.y+a.height,p=s.y-1,m=fe(a,e,de),h=fe(s,e,ue);function me(e,t,n){for(let r=t;r<=n;r++)if(O.has(`${e},${r}`))return!1;return!0}let g=f,_=p,v=Math.max(...[...y.values()].filter(e=>e.y===a.y).map(e=>e.y+e.height)),b=s.y,x=Math.max(f,v+1),S=Math.min(p,b-1);function he(e,t,n){let r=Math.floor(x<=S?(x+S)/2:(f+p)/2);if(x>S)return r;for(let r=x;r<=S;r++)if(ne(e,t,r,r+n))return r;return r}let E=m!==h,D=Math.min(m,h),A=Math.max(m,h),M=E?he(D,A,0):p,N=E?M-1:p,P=!me(m,x,S)||!me(h,x,S)||j(m,f,E?M:p)||E&&j(h,M,p),F=m;if(P){let e=C.length,t;for(let n=0;n<=e;n++){let e=m+n;if(me(e,f,p)&&!re(e,f,p)){t=e;break}let r=m-n;if(n>0&&me(r,f,p)&&!re(r,f,p)){t=r;break}}F=t??m;for(let e=f;e<=g;e++)k(m,e,i,`line`);for(let e=Math.min(m,F);e<=Math.max(m,F);e++)te(e,g,r,`line`);for(let e=g;e<=_;e++)k(F,e,i,`line`);for(let e=Math.min(F,h);e<=Math.max(F,h);e++)te(e,_,r,`line`);for(let e=_;e<=p;e++)k(h,e,i,`line`);if(m!==F){let e=F>m?`right`:`left`,t=e===`right`?`left`:`right`;z(m,g,`up`,e),z(F,g,`down`,t)}if(F!==h){let e=h>F?`right`:`left`,t=e===`right`?`left`:`right`;z(F,_,`up`,e),z(h,_,`down`,t)}ie(F,g,_)}else{for(let e=f;e<=N;e++)k(m,e,i,`line`);if(ie(m,f,E?M:N),E){for(let e=D;e<=A;e++)te(e,M,r,`line`);for(let e=M+1;e<=p;e++)k(h,e,i,`line`);ie(h,M,p);let e=h>m?`right`:`left`,t=e===`right`?`left`:`right`;z(m,M,`up`,e),z(h,M,`down`,t),F=h}}let I=Hr(u,c,!1,!0);for(let e=0;e<I.length;e++)k(m-Math.floor(I.length/2)+e,g,I[e],`arrow`);let L=m===h?m:h,R=Hr(d,c,!0,!0);for(let e=0;e<R.length;e++)k(L-Math.floor(R.length/2)+e,_,R[e],`arrow`);if(e.label){let t=Q(e.label),n=Math.max(I.length-1-Math.floor(I.length/2),R.length-1-Math.floor(R.length/2)),r=F+n+2,i=t.map(e=>ae(e)),a=r+Math.max(...i.map(e=>e.length))-1,o=t.length,s=Math.floor((f+p)/2)-Math.floor((o-1)/2);a>=0&&(se(C,a+1,p+1),oe(w,a+1,p+1));let c=null;for(let e of[!0,!1]){for(let t=0;t<=p-f&&c===null;t++){let n=t===0?[s]:[s+t,s-t];for(let t of n)if(!(t<f||t+o-1>p)&&i.every((n,i)=>ee(n,r,t+i,0,a,e))){c=t;break}}if(c!==null)break}if(c!==null)for(let e=0;e<o;e++){let t=i[e],n=c+e;for(let e=0;e<t.length;e++){let i=r+e;i>=0&&k(i,n,t[e],`text`)}w[r-1]?.[n]===`line`&&T(r-1,n,` `,`line`);let a=r+t.length;w[a]?.[n]===`line`&&T(a,n,` `,`line`)}}}}return pe(C,{roleCanvas:w,colorMode:i,theme:a})}var Kr=4,qr=[`O`,`/|\\`,`/ \\`],Jr=3,Yr=4;function Xr(e){return e.seqNumber===void 0?Kr:Kr+String(e.seqNumber).length}function Zr(n,r,i,a){let o=(0,e.splitStatements)(n),s=(0,t.parseSequenceDiagram)(o);if(s.actors.length===0)return``;let c=r.useAscii,l=c?`-`:`─`,u=c?`|`:`│`,d=c?`+`:`┌`,f=c?`+`:`┐`,p=c?`+`:`└`,m=c?`+`:`┘`,h=c?`+`:`┬`,g=c?`+`:`┴`,_=c?`+`:`├`,v=c?`+`:`┤`,y=c?`‖`:`║`,b=new Map;s.actors.forEach((e,t)=>b.set(e.id,t));function x(e){let t=b.get(e);if(t===void 0)throw Error(`Sequence diagram: unknown actor "${e}"`);return t}function S(e){let t=Mt(e.label?`${e.type} [${e.label}]`:e.type);for(let n of e.dividers)n.label&&(t=Math.max(t,Mt(`[${n.label}]`)));return t}let C=Math.max(0,r.boxBorderPadding),w=e=>Math.max(Mt(e.label),e.type===`actor`?Jr:0),T=e=>Nt(e.label)+(e.type===`actor`?qr.length:0),E=s.actors.map(e=>w(e)+2*C+2),D=E.map(e=>Math.ceil(e/2)),ee=s.actors.map(e=>T(e)+2),O=Math.max(...ee,3),k=(e,t)=>t-Math.floor(E[e]/2),te=Math.floor((O-1)/2),ne=O-1-te,A=new Map,j=new Map;s.actors.forEach((e,t)=>{e.createdAt!==void 0&&A.set(e.createdAt,t),e.destroyedAt!==void 0&&j.set(e.destroyedAt,t)});let re=new Map,ie=new Map,P=s.boxes.filter(e=>e.actorIds.length>0).map(e=>{let t=e.actorIds.map(x);return{label:e.label,lo:Math.min(...t),hi:Math.max(...t)}}),I=P.length>0,ce=s.actors.map((e,t)=>P.findIndex(e=>e.lo<=t&&t<=e.hi)),le=+!!I,z=e=>e===``?0:Mt(e)+6,ue=Array(Math.max(s.actors.length-1,0)).fill(0);for(let e of s.messages){let t=x(e.from),n=x(e.to);if(t===n)continue;let r=Math.min(t,n),i=Math.max(t,n),a=Mt(e.label)+4,o=i-r,s=Math.ceil(a/o);for(let e=r;e<i;e++)ue[e]=Math.max(ue[e],s)}function de(e){let t=Q(e.text);return Math.max(...t.map(e=>M(e)))+2+2*C}let fe=Array(s.actors.length).fill(0),B=Array(s.actors.length).fill(0),me=Array(s.actors.length).fill(0),he=Array(s.actors.length).fill(0);for(let e of s.notes)if(e.position===`left`||e.position===`right`){let t=x(e.actorIds[0]),n=de(e);e.position===`left`?fe[t]=Math.max(fe[t],n):B[t]=Math.max(B[t],n)}else if(e.position===`over`&&e.actorIds.length===1){let t=x(e.actorIds[0]),n=de(e),r=Math.floor(n/2),i=n-r;me[t]=Math.max(me[t],r),he[t]=Math.max(he[t],i)}let ge=Ke(r.paddingX,5,10,4),V=[Math.max(D[0]+(ce[0]===-1?0:2),fe[0]+1,me[0])];for(let e=1;e<s.actors.length;e++){let t=ce[e-1],n=ce[e],r=t===n?0:(t===-1?0:1)+(n===-1?0:1),i=r===0?0:r*2-1,a=Math.max(B[e-1],fe[e],he[e-1],me[e])+2,o=Math.max(D[e-1]+D[e]+2+i,ue[e-1]+2,a,ge);V[e]=V[e-1]+o}let _e=e=>k(e.lo,V[e.lo])-1-1,ve=e=>Math.max(k(e.hi,V[e.hi])+E[e.hi]-1+1+1,_e(e)+z(e.label)-1);for(let e of P){if(e.hi+1>=s.actors.length)continue;let t=k(e.hi+1,V[e.hi+1]),n=ce[e.hi+1]===-1?0:2,r=ve(e)+1+1+n-t;if(r>0){let t=V.slice(e.hi+1).map(e=>e+r);V.splice(e.hi+1,t.length,...t)}}for(let e of s.blocks){let t=-1,n=-1,r=1/0,i=-1;for(let a=e.startIndex;a<=e.endIndex&&!(a>=s.messages.length);a++){let e=s.messages[a],o=x(e.from),c=x(e.to);if(t=t===-1?Math.min(o,c):Math.min(t,o,c),n=Math.max(n,o,c),r=Math.min(r,V[Math.min(o,c)]),i=Math.max(i,V[Math.max(o,c)]),o===c){let t=V[o]+Kr+2+Mt(e.label);i=Math.max(i,t)}}if(n===-1||n+1>=s.actors.length)continue;let a=Math.max(0,r-Yr),o=i+Yr,c=a+1+S(e),l=Math.max(o,c),u=V[n+1],d=l+2-u;if(d>0){let e=V.slice(n+1).map(e=>e+d);V.splice(n+1,e.length,...e)}}let ye=[],be=[],xe=new Map,Se=new Map,Ce=new Map,we=[],Te=le,Ee=Te+O,H=Ee+le,De=Ke(r.paddingY,5,1,0),Oe=Math.max(De,1);for(let e of s.notes){if(e.afterIndex!==-1)continue;H+=De;let t=Q(e.text),n=de(e),r=t.length+2,i=b.get(e.actorIds[0])??0,a;if(e.position===`left`)a=V[i]-n-1;else if(e.position===`right`)a=V[i]+2;else if(e.actorIds.length>=2){let t=b.get(e.actorIds[1])??i;a=Math.floor((V[i]+V[t])/2)-Math.floor(n/2)}else a=V[i]-Math.floor(n/2);a=Math.max(0,a),we.push({x:a,y:H,width:n,height:r,lines:t}),H+=r}for(let e=0;e<s.messages.length;e++){for(let t=0;t<s.blocks.length;t++)s.blocks[t].startIndex===e&&(H+=De+1,xe.set(t,H-1));for(let t=0;t<s.blocks.length;t++)for(let n=0;n<s.blocks[t].dividers.length;n++)s.blocks[t].dividers[n].index===e&&(H+=De,Ce.set(`${t}:${n}`,H),H+=Oe);H+=De;let t=s.messages[e],n=t.from===t.to,r=Nt(t.label),i=n?void 0:A.get(e),a=j.get(e);if(n)be[e]=H+1,ye[e]=H,H+=2+r;else{let t=i===void 0?0:te,n=i===void 0?0:ne;be[e]=H,ye[e]=H+r+t,H+=r+t+1+n,i!==void 0&&re.set(i,ye[e]-t)}a!==void 0&&(ie.set(a,H),H+=1);for(let t=0;t<s.notes.length;t++)if(s.notes[t].afterIndex===e){H+=De;let e=s.notes[t],n=Q(e.text),r=de(e),i=n.length+2,a=b.get(e.actorIds[0])??0,o;if(e.position===`left`)o=V[a]-r-1;else if(e.position===`right`)o=V[a]+2;else if(e.actorIds.length>=2){let t=b.get(e.actorIds[1])??a;o=Math.floor((V[a]+V[t])/2)-Math.floor(r/2)}else o=V[a]-Math.floor(r/2);o=Math.max(0,o),we.push({x:o,y:H,width:r,height:i,lines:n}),H+=i}for(let t=0;t<s.blocks.length;t++)s.blocks[t].endIndex===e&&(H+=De,Se.set(t,H),H+=Oe)}H+=Oe;let ke=H,Ae=ke+le,je=Ae+O+le,U=(V[V.length-1]??0)+(D[D.length-1]??0)+2;for(let e of P)U=Math.max(U,ve(e)+2);for(let e=0;e<s.messages.length;e++){let t=s.messages[e];if(t.from===t.to){let e=V[x(t.from)]+Xr(t)+2+2+Mt(t.label);U=Math.max(U,e+1)}}for(let e of we)U=Math.max(U,e.x+e.width+1);let W=N(U,je-1),Me=F(U,je-1);function G(e,t,n,r){R(W,e,t,n,{role:r,roleCanvas:Me})}function Ne(e,t,n,r,i){let a=ae(n);for(let n=0;n<a.length;n++){let o=e+n;if(i!==void 0&&o>=i||a[n+1]===``&&i!==void 0&&o+1>=i)break;G(o,t,a[n],r)}}function Pe(e,t,n,r,i){let a=r===`actor`?qr:[],o=[...a,...Q(n)],s=Math.max(Mt(n),a.length>0?Jr:0),c=s+2*C+2,h=i,g=h-2,_=e-Math.floor(c/2);G(_,t,d,`border`);for(let e=1;e<c-1;e++)G(_+e,t,l,`border`);G(_+c-1,t,f,`border`);for(let e=0;e<g;e++){let n=t+1+e;G(_,n,u,`border`),G(_+c-1,n,u,`border`);let r=o[e];r!==void 0&&Ne(_+1+C+Math.floor((s-M(r))/2),n,r,`text`)}let v=t+h-1;G(_,v,p,`border`);for(let e=1;e<c-1;e++)G(_+e,v,l,`border`);G(_+c-1,v,m,`border`)}let Fe=e=>{let t=re.get(e);return t===void 0?Ee:t+O},Ie=e=>ie.get(e)??ke,Le=new Map,Re=new Map;function K(e,t){let n=Re.get(e)??[];Re.set(e,n),n.push(t)}function q(e,t){let n=Re.get(e)?.pop();if(n===void 0)return;let r=Le.get(e)??[];Le.set(e,r),r.push({topRow:n,bottomRow:t})}let J=new Map;for(let e of s.activations){let t=J.get(e.afterIndex)??[];t.push(e),J.set(e.afterIndex,t)}function Y(e,t){for(let n of J.get(e)??[])n.kind===`start`?K(n.actorId,t):q(n.actorId,t)}Y(-1,Ee);for(let e=0;e<s.messages.length;e++){let t=s.messages[e],n=ye[e];t.activate&&K(t.to,n),t.deactivate&&q(t.from,n),Y(e,n)}for(let[e,t]of Re){if(t.length===0)continue;let n=Ie(x(e)),r=Le.get(e)??[];Le.set(e,r);for(let e of t)r.push({topRow:e,bottomRow:n})}function ze(e,t){let n=Le.get(e);return n?n.some(e=>t>=e.topRow&&t<=e.bottomRow):!1}for(let e=0;e<s.actors.length;e++){let t=V[e],n=s.actors[e].id;for(let r=Fe(e);r<=Ie(e);r++)G(t,r,ze(n,r)?y:u,`line`)}let Be=c?`+`:`┼`;function Ve(e,t,n){let r=_e(e),i=ve(e),a=t+O+1;G(r,t,d,`border`),G(i,t,f,`border`),G(r,a,p,`border`),G(i,a,m,`border`);for(let e=r+1;e<i;e++)G(e,t,l,`border`),G(e,a,l,`border`);for(let e=t+1;e<a;e++)G(r,e,u,`border`),G(i,e,u,`border`);n!==``&&Ne(r+2,t,` ${Q(n)[0]} `,`text`);for(let n=e.lo;n<=e.hi;n++){let e=V[n];Fe(n)<=t&&t<=Ie(n)&&G(e,t,Be,`junction`),Fe(n)<=a&&a<=Ie(n)&&G(e,a,Be,`junction`)}}for(let e of P)Ve(e,0,e.label),Ve(e,ke,``);for(let e=0;e<s.actors.length;e++){let t=s.actors[e],n=re.get(e)??Te,r=ie.has(e);Pe(V[e],n,t.label,t.type,O),r||Pe(V[e],Ae,t.label,t.type,O),c||(G(V[e],n+O-1,h,`junction`),r||G(V[e],Ae,g,`junction`))}for(let e=0;e<s.messages.length;e++){let t=s.messages[e],n=x(t.from),r=x(t.to),i=V[n],a=V[r],o=n===r,d=t.lineStyle===`dashed`,f=t.arrowHead===`filled`,p=t.isLost===!0,m=c?`x`:`✕`,h=d?c?`.`:`╌`:l;if(o){let n=ye[e],r=Xr(t),a=t.seqNumber===void 0?void 0:String(t.seqNumber),o=Q(t.label);G(i,n,_,`junction`);let s=i+1;if(a!==void 0){for(let e=0;e<a.length;e++)G(i+1+e,n,a[e],`text`);s=i+1+a.length}for(let e=s;e<i+r;e++)G(e,n,h,`line`);G(i+r,n,c?`+`:`┐`,`corner`);let l=i+r+2;for(let e=0;e<o.length;e++){let t=n+1+e;G(i+r,t,u,`line`),Ne(l,t,o[e],`text`,U)}let d=n+1+o.length;G(i,d,p?m:f?c?`<`:`◀`:c?`<`:`◁`,`arrow`);for(let e=i+1;e<i+r;e++)G(e,d,h,`line`);G(i+r,d,c?`+`:`┘`,`corner`)}else{let n=be[e],o=ye[e],s=i<a,l=A.get(e)===r,u=a;if(l){let e=k(r,a),t=e+E[r]-1;u=s?e-1:t+1}let d=Math.floor((i+a)/2),g=Q(t.label);for(let e=0;e<g.length;e++){let t=g[e];Ne(d-Math.floor(M(t)/2),n+e,t,`text`,U)}if(s){for(let e=i+1;e<u;e++)G(e,o,h,`line`);G(u,o,p?m:f?c?`>`:`▶`:c?`>`:`▷`,`arrow`),t.bidirectional&&G(i,o,c?`<`:`◀`,`arrow`)}else{for(let e=u+1;e<i;e++)G(e,o,h,`line`);G(u,o,p?m:f?c?`<`:`◀`:c?`<`:`◁`,`arrow`),t.bidirectional&&G(i,o,c?`>`:`▶`,`arrow`)}if(t.seqNumber!==void 0){let e=String(t.seqNumber);if(s){let t=i+1;if(t+e.length<a)for(let n=0;n<e.length;n++)G(t+n,o,e[n],`text`)}else{let t=i-e.length;if(t>u)for(let n=0;n<e.length;n++)G(t+n,o,e[n],`text`)}}}}for(let[e,t]of ie)G(V[e],t,c?`x`:`✕`,`arrow`);let He=U-1;for(let e=0;e<s.blocks.length;e++){let t=s.blocks[e],n=xe.get(e),r=Se.get(e);if(n===void 0||r===void 0)continue;let i=U,a=0;for(let e=t.startIndex;e<=t.endIndex&&!(e>=s.messages.length);e++){let t=s.messages[e],n=b.get(t.from)??0,r=b.get(t.to)??0;if(i=Math.min(i,V[Math.min(n,r)]),a=Math.max(a,V[Math.max(n,r)]),n===r){let e=V[n]+Xr(t)+2+Mt(t.label);a=Math.max(a,e)}}let o=i-Yr,c=a+Yr,h=1/0,g=-1/0;for(let e of V)e>a&&e<h&&(h=e),e<i&&e>g&&(g=e);c>=h&&(c=Math.max(a,h-Yr)),o<=g&&(o=Math.min(i,g+Yr)),o=Math.max(0,o),c>He&&(se(W,c+1,je-1),oe(Me,c+1,je-1),He=c);let y=t.label?`${t.type} [${t.label}]`:t.type,x=o+1+S(t);if(x>c){c=x;let[e]=L(W);c>e&&(se(W,c,je-1),oe(Me,c,je-1)),U=Math.max(U,c+1),He=Math.max(He,c)}G(o,n,d,`border`);for(let e=o+1;e<c;e++)G(e,n,l,`border`);G(c,n,f,`border`);let C=Q(y);for(let e=0;e<C.length&&n+e<r;e++)Ne(o+1,n+e,C[e],`text`,c);G(o,r,p,`border`);for(let e=o+1;e<c;e++)G(e,r,l,`border`);G(c,r,m,`border`);for(let e=n+1;e<r;e++)G(o,e,u,`border`),G(c,e,u,`border`);for(let n=0;n<t.dividers.length;n++){let r=Ce.get(`${e}:${n}`);if(r===void 0)continue;let i=Ue();G(o,r,_,`junction`);for(let e=o+1;e<c;e++)G(e,r,i,`line`);G(c,r,v,`junction`);let a=t.dividers[n].label;if(a){let e=`[${a}]`;Ne(o+1,r,e,`text`,c)}}}for(let e of we){se(W,e.x+e.width,e.y+e.height),oe(Me,e.x+e.width,e.y+e.height),G(e.x,e.y,d,`border`);for(let t=1;t<e.width-1;t++)G(e.x+t,e.y,l,`border`);G(e.x+e.width-1,e.y,f,`border`);for(let t=0;t<e.lines.length;t++){let n=e.y+1+t;G(e.x,n,u,`border`),G(e.x+e.width-1,n,u,`border`);for(let t=e.x+1;t<e.x+e.width-1;t++)G(t,n,` `,`text`);Ne(e.x+1+C,n,e.lines[t],`text`)}let t=e.y+e.height-1;G(e.x,t,p,`border`);for(let n=1;n<e.width-1;n++)G(e.x+n,t,l,`border`);G(e.x+e.width-1,t,m,`border`)}return pe(W,{roleCanvas:Me,colorMode:i,theme:a});function Ue(){return c?`-`:`╌`}}function Qr(e,t){return e.rowStart<=t.rowEnd&&t.rowStart<=e.rowEnd}function $r(e,t){let n=e.map(e=>({item:e,geom:t(e)})).sort((e,t)=>e.geom.idealMid-t.geom.idealMid),r=(e,t)=>{let r=n[e];if(r)for(let i=e+t;i>=0&&i<n.length;i+=t){let e=n[i];if(e&&Qr(e.geom,r.geom))return e.geom}},i=new Map;for(let[e,t]of n.entries()){let n=t.geom,a=r(e,-1),o=r(e,1),s=a&&a.end>=n.start?Math.floor((a.idealMid+n.idealMid)/2)+1:-1/0,c=o&&n.end>=o.start?Math.floor((n.idealMid+o.idealMid)/2):1/0;i.set(t.item,{left:s,right:c})}return i}function ei(e){let n=[];e.annotation&&n.push(`<<${e.annotation}>>`);let r=Q(e.label);n.push(...r);let i=e.attributes.map(t.formatClassMember),a=e.methods.map(t.formatClassMember),o=[n];return i.length>0&&o.push(i),a.length>0&&o.push(a),o}function ti(e,t){return{type:e,markerAt:t,dashed:e===`dependency`||e===`realization`}}function ni(e,t,n){switch(e){case`inheritance`:case`realization`:return n===`down`?t?`^`:`△`:n===`up`?t?`v`:`▽`:n===`left`?t?`>`:`◁`:t?`<`:`▷`;case`composition`:return t?`*`:`◆`;case`aggregation`:return t?`o`:`◇`;case`association`:case`dependency`:return n===`down`?t?`v`:`▼`:n===`up`?t?`^`:`▲`:n===`left`?t?`<`:`◀`:t?`>`:`▶`}}function ri(e,t,n,r,i){let a=e+t.length-1,o=r>e,s=i<a;if(!o&&!s)return{start:e,cells:t};let c=o?r:e,l=Math.max(0,(s?i:a)-c+1),u=+!!o+ +!!s;if(l===0)return{start:c,cells:[]};if(l<u)return{start:c,cells:[`…`]};let d=Math.max(0,l-u),f=ae(n),p=f.length<=d?f:o&&!s?f.slice(f.length-d):f.slice(0,d),m=[...o?[`…`]:[],...p,...s?[`…`]:[]];return{start:c+Math.max(0,Math.floor((l-m.length)/2)),cells:m}}function ii(e){return Math.max(...Q(e).map(e=>M(e)))+2}function ai(n,r,i,a,o={}){let c=(0,e.splitStatements)(n),{diagram:l,notesById:d}=oi((0,t.parseClassDiagram)(c));if(l.classes.length===0)return``;let f=r.useAscii,p=Ke(r.paddingX,5,4,1),m=Ke(r.paddingY,5,3,1),h=new Map,g=new Map,_=new Map;for(let e of l.classes){let t=ei(e);h.set(e.id,t);let{width:n,height:i}=Mr(t,r.boxBorderPadding);g.set(e.id,n),_.set(e.id,i)}let v=new Map;for(let e of l.classes)v.set(e.id,e);let y=new Map,b=new Map;for(let e of l.relationships){let t=e.from,n=e.to,r=y.get(n)??new Set;y.set(n,r),r.add(t);let i=b.get(t)??new Set;b.set(t,i),i.add(n)}let x=new Map,S=l.classes.filter(e=>!y.has(e.id)||y.get(e.id).size===0).map(e=>e.id);for(let e of S)x.set(e,0);let C=l.classes.length-1,w=0;for(;w<S.length;){let e=S[w++],t=b.get(e);if(t)for(let n of t){let t=(x.get(e)??0)+1;t>C||(!x.has(n)||x.get(n)<t)&&(x.set(n,t),S.push(n))}}for(let e of l.classes)x.has(e.id)||x.set(e.id,0);si(d,x);let T=Math.max(...x.values(),0),E=Array.from({length:T+1},()=>[]);for(let e of l.classes)E[x.get(e.id)].push(e.id);let D=new Map,ee=new Map;{let e=new Map;l.relationships.forEach((t,n)=>{let r=[t.from,t.to].sort().join(`::`),i=e.get(r)??[];i.push(n),e.set(r,i)});for(let t of e.values()){if(t.length<2)continue;let e=t.length,n=Math.max(...t.map(e=>{let t=l.relationships[e].label;return t?ii(t):3}))+1;t.forEach((t,r)=>{D.set(t,Math.round((r-(e-1)/2)*n)),ee.set(t,(e-1)*n)})}}let O=new Map,k=new Map,te=new Map,ne=new Map;{let e=(e,t,n)=>{let r=new Map;l.relationships.forEach((t,n)=>{if(D.has(n)||!v.has(t.from)||!v.has(t.to))return;let i=x.get(t.from)??0;if((x.get(t.to)??0)-i!==1)return;let a=e(t),o=r.get(a)??[];o.push(n),r.set(a,o)});for(let e of r.values()){if(e.length<2)continue;let r=e.length,i=Math.max(...e.map(e=>{let t=l.relationships[e].label;return t?ii(t):3}))+1;e.forEach((e,a)=>{t.set(e,Math.round((a-(r-1)/2)*i)),n.set(e,(r-1)*i)})}};e(e=>e.to,te,ne),e(e=>e.from,O,k)}let A=new Map;for(let e of l.classes)A.set(e.id,{left:0,right:0});l.relationships.forEach((e,t)=>{if(!v.has(e.from)||!v.has(e.to))return;let n=e.label?ii(e.label):1,r=D.get(t)??O.get(t)??0,i=D.get(t)??te.get(t)??0,a=A.get(e.from);a.left=Math.max(a.left,Math.floor(n/2)-r),a.right=Math.max(a.right,r+n-1-Math.floor(n/2));let o=A.get(e.to);o.left=Math.max(o.left,Math.floor(n/2)-i),o.right=Math.max(o.right,i+n-1-Math.floor(n/2))});let j=new Map,re=0,ie=0;for(let e=0;e<=T;e++){let t=E[e];if(t.length===0)continue;let n=e=>{let t=y.get(e);return t&&t.size>0?[...t].sort().join(`,`):`root:${e}`},r=new Map;for(let e of t){let t=n(e),i=r.get(t);i||(i=[],r.set(t,i)),i.push(e)}let i=new Map,a=new Map,o=new Map;{let e=0;for(let n of t){let t=g.get(n),r=A.get(n),s=Math.max(0,r.left-Math.floor(t/2)),c=Math.max(0,r.right-(t-1-Math.floor(t/2)));i.set(n,e),a.set(n,s+t+c),o.set(n,s),e+=s+t+c+p}}let s=0,c=0,l=(e,t)=>{let n=v.get(e),r=g.get(e),i=_.get(e),l=o.get(e),u=a.get(e);j.set(e,{cls:n,sections:h.get(e),x:t+l,y:re,width:r,height:i}),ie=Math.max(ie,t+u),s=t+u+p,c=Math.max(c,i)},u=new Set;for(let c of t){if(u.has(c))continue;let t=n(c),d=y.get(c),f=d?[...d].filter(t=>x.get(t)<e):[];if(f.length===0){l(c,Math.max(i.get(c),s,0)),u.add(c);continue}let m=r.get(t),h=f.map(e=>{let t=j.get(e);return t.x+Math.floor(t.width/2)}),_=Math.round(h.reduce((e,t)=>e+t,0)/h.length),v=0;for(let e=0;e<m.length;e++)v+=a.get(m[e]),e<m.length-1&&(v+=p);let b=o.get(m[0]),S=m[m.length-1],C=a.get(S)-o.get(S)-g.get(S),w=v-b-C,T=_-b-Math.floor(w/2),E=Math.max(T,s,0);for(let e of m)l(e,E),u.add(e),E=s}re+=c+m}let P=ie,I=0;for(let e of j.values())P=Math.max(P,e.x+e.width),I=Math.max(I,e.y+e.height);P+=4,I+=2;let L=N(P-1,I-1),ce=F(P-1,I-1);function z(e,t,n,r){R(L,e,t,n,{role:r,roleCanvas:ce})}let ue=o.hyperlinks?s(P-1,I-1):void 0;for(let t of j.values()){let n=Nr(t.sections,f,r.boxBorderPadding);for(let e=0;e<n.length;e++)for(let r=0;r<n[0].length;r++){let i=n[e][r];if(i!==` `){let n=t.x+e,a=t.y+r;n<P&&a<I&&z(n,a,i,jr(i))}}if(ue){let r=(0,e.safeHref)(l.interactions.get(t.cls.id)?.href),i=t.sections[0];if(r!==void 0&&i!==void 0){let e=1+ +!!t.cls.annotation;u(ue,n,{x:t.x,y:t.y},r,{from:e,to:i.length})}}}let fe=new Set;for(let e of j.values())for(let t=0;t<e.height;t++)for(let n=0;n<e.width;n++)fe.add(`${e.x+n},${e.y+t}`);function B(e,t,n,r){fe.has(`${e},${t}`)||z(e,t,n,r)}function me(e,t,n){for(let[r,i]of j.entries())if(!n?.has(r)&&e>=i.x&&e<=i.x+i.width-1&&t>=i.y&&t<=i.y+i.height-1)return!0;return!1}function he(e,t,n,r){return zr(e,0,e+P+9,e=>{for(let i=Math.min(t,n);i<=Math.max(t,n);i++)if(me(e,i,r))return!1;return!0})??P+2}let ge=f?`-`:`─`,V=f?`|`:`│`,_e=f?`.`:`╌`,ve=f?`:`:`┊`;function ye(e,t,n){let r=Math.floor(n/2),i=n-1-r,a=t>r+i?(r+i)/t:1;return Math.max(-r,Math.min(i,Math.round(e*a)))}function be(e,t,n){let r=D.get(e)??O.get(e)??0,i=D.get(e)??te.get(e)??0,a=ee.get(e)??k.get(e)??0,o=ee.get(e)??ne.get(e)??0,s=t.x+Math.floor(t.width/2),c=n.x+Math.floor(n.width/2);return{fromCX:s+r,toCX:c+i,fromAnchorX:s+ye(r,a,t.width),toAnchorX:c+ye(i,o,n.width)}}function xe(e,t,n,r){if(fe.has(`${e},${t}`)||ce[e]?.[t]===`arrow`)return;let i=L[e]?.[t];if(!f&&i!==void 0&&le(i)&&le(n)){let a=de(i,n);z(e,t,a,a===n?r:`junction`);return}z(e,t,n,r)}function Se(e,t,n,r,i){if(t===n)return;let a=Math.min(t,n),o=Math.max(t,n);for(let t=a+1;t<o;t++)xe(t,e,r,`line`);if(f){xe(t,e,r,`line`),xe(n,e,r,`line`);return}let s=n>t,c=i?s?`└`:`┘`:s?`┌`:`┐`,l=i?s?`┐`:`┌`:s?`┘`:`└`;xe(t,e,c,`corner`),xe(n,e,l,`corner`)}let Ce=new Map,we=new Map;l.relationships.forEach((e,t)=>{let n=j.get(e.from),r=j.get(e.to);if(!n||!r)return;let i=ti(e.type,e.markerAt),a=i.dashed?_e:ge,o=i.dashed?ve:V,s=new Set([e.from,e.to]),{fromCX:c,toCX:l,fromAnchorX:u,toAnchorX:d}=be(t,n,r),p=n.y+n.height-1,m=r.y;if(p<m){let e=he(c,p+1,m-1,s),n=e!==c;if(e>=P&&se(L,e+2,I),n){let n=p+1,r=m-1;Ce.set(t,{routeX:e,exitY:n,entryY:r,fromAnchorX:u,toAnchorX:d,clearSide:e>c?`right`:`left`});let s=Math.min(u,e),l=Math.max(u,e);for(let e=s;e<=l;e++)B(e,n,a,`line`);!f&&n<(L[0]?.length??0)&&(u<e?(B(u,n,`└`,`corner`),B(e,n,`┐`,`corner`)):(B(u,n,`┘`,`corner`),B(e,n,`┌`,`corner`)));for(let t=n+1;t<=r;t++)B(e,t,o,`line`);if(e!==d){let t=Math.min(e,d),n=Math.max(e,d);for(let e=t;e<=n;e++)B(e,r,a,`line`);!f&&r<(L[0]?.length??0)&&(e<d?(B(e,r,`└`,`corner`),B(d,r,`┐`,`corner`)):(B(e,r,`┘`,`corner`),B(d,r,`┌`,`corner`)))}if(i.markerAt===`to`){let e=i.type===`inheritance`||i.type===`realization`;B(d,r,ni(i.type,f,e?`up`:`down`),`arrow`)}if(i.markerAt===`from`){let e=ni(i.type,f,`down`);B(u,p+1,e,`arrow`)}}else{let e=p+Math.floor((m-p)/2),t=c!==u,n=l!==d;Se(p+1,u,c,a,!0);for(let n=p+(t?2:1);n<=e;n++)B(c,n,o,`line`);if(c!==l&&e<(L[0]?.length??0)){let t=Math.min(c,l),n=Math.max(c,l);for(let r=t;r<=n;r++)B(r,e,a,`line`);f||(B(c,e,c<l?`└`:`┘`,`corner`),B(l,e,c<l?`┐`:`┌`,`corner`))}for(let t=e+1;t<m-+!!n;t++)B(l,t,o,`line`);if(Se(m-1,d,l,a,!1),i.markerAt===`to`){let e=i.type===`inheritance`||i.type===`realization`;B(d,m-1,ni(i.type,f,e?`up`:`down`),`arrow`)}i.markerAt===`from`&&B(u,p+1,ni(i.type,f,`down`),`arrow`)}}else if(r.y+r.height-1<n.y){let e=n.y,t=r.y+r.height-1,s=t+Math.floor((e-t)/2),p=c!==u,m=l!==d;Se(e-1,u,c,a,!1);for(let t=e-(p?2:1);t>=s;t--)B(c,t,o,`line`);if(c!==l){let e=Math.min(c,l),t=Math.max(c,l);for(let n=e;n<=t;n++)B(n,s,a,`line`);!f&&s>=0&&s<I&&(B(c,s,c<l?`┌`:`┐`,`corner`),B(l,s,c<l?`┘`:`└`,`corner`))}for(let e=s-1;e>t+ +!!m;e--)B(l,e,o,`line`);if(Se(t+1,d,l,a,!0),i.markerAt===`from`){let t=ni(i.type,f,`up`),n=e-1;for(let e=0;e<t.length;e++)B(u-Math.floor(t.length/2)+e,n,t[e],`arrow`)}if(i.markerAt===`to`){let e=i.type===`inheritance`||i.type===`realization`?`down`:`up`,n=ni(i.type,f,e),r=t+1;for(let e=0;e<n.length;e++)B(d-Math.floor(n.length/2)+e,r,n[e],`arrow`)}}else{let s=r.y+r.height-1,m=Math.min(c,l),h=Math.max(c,l),g=Math.max(p,s);for(let[t,r]of j.entries())t!==e.from&&t!==e.to&&r.y===n.y&&r.x<h+1&&r.x+r.width>m&&(g=Math.max(g,r.y+r.height-1));let _=g+2;we.set(t,_),se(L,P,_+1),oe(ce,P,_+1);let v=c!==u,y=l!==d;Se(p+1,u,c,a,!0);for(let e=p+(v?2:1);e<=_;e++)B(c,e,o,`line`);for(let e=m;e<=h;e++)B(e,_,a,`line`);for(let e=_-1;e>=s+(y?2:1);e--)B(l,e,o,`line`);if(Se(s+1,d,l,a,!0),i.markerAt===`from`){let e=ni(i.type,f,`down`),t=p+1;for(let n=0;n<e.length;n++)B(u-Math.floor(e.length/2)+n,t,e[n],`arrow`)}if(i.markerAt===`to`){let e=i.type===`inheritance`||i.type===`realization`,t=ni(i.type,f,e?`down`:`up`),n=r.y+r.height;for(let e=0;e<t.length;e++)B(d-Math.floor(t.length/2)+e,n,t[e],`arrow`)}}});function Te(e,t,n,r){let{fromCX:i,toCX:a}=be(e,t,n),o=t.y+t.height-1,s=n.y;if(o<s){let t=Ce.get(e);if(t){let e=t.exitY+1,n=t.entryY;if(n>=e)return{idealMidX:t.clearSide===`right`?t.routeX+1+Math.floor(r/2):t.routeX-1-Math.ceil(r/2),baseMidY:Math.floor((e+n)/2)};let i=Math.abs(t.routeX-t.fromAnchorX);return Math.abs(t.toAnchorX-t.routeX)>=i?{idealMidX:Math.floor((t.routeX+t.toAnchorX)/2),baseMidY:t.entryY}:{idealMidX:Math.floor((t.fromAnchorX+t.routeX)/2),baseMidY:t.exitY}}return{idealMidX:Math.floor((i+a)/2),baseMidY:Math.floor((o+1+s-1)/2)}}if(n.y+n.height-1<t.y){let e=n.y+n.height-1;return{idealMidX:Math.floor((i+a)/2),baseMidY:Math.floor((e+1+t.y-1)/2)}}return{idealMidX:Math.floor((i+a)/2),baseMidY:we.get(e)??Math.max(o,n.y+n.height-1)+2}}function Ee(e,t,n,r,i,a,o){let s=r,c=Math.floor(a/2),l=e.y+e.height-1,u=t.y,d=!1;for(let e=0;e<a;e++){let t=s-c+e,r=n-Math.floor(i/2),a=Math.max(0,r);for(let e=a;e<a+i;e++)if(me(e,t,o)){d=!0;break}if(d)break}if(d){let e=l+1,t=u-1;for(let r=e;r<=t;r++){let e=!0,t=n-Math.floor(i/2),a=Math.max(0,t);for(let t=a;t<a+i;t++)if(me(t,r,o)){e=!1;break}if(e){s=r;break}}}return s}let H=new Map,De=[];for(let[e,t]of l.relationships.entries()){if(!t.label)continue;let n=j.get(t.from),r=j.get(t.to);if(!n||!r)continue;let i=Q(t.label),a=Math.floor(i.length/2),o=Math.max(...i.map(M))+2,{idealMidX:s,baseMidY:c}=Te(e,n,r,o),l=new Set([t.from,t.to]),u=Ee(n,r,s,c,o,i.length,l);H.set(t,u);let d=Math.max(0,s-Math.floor(o/2));De.push({rel:t,idealMidX:s,naturalStart:d,naturalEnd:d+o-1,rowStart:u-a,rowEnd:u+a})}let Oe=$r(De,e=>({idealMid:e.idealMidX,start:e.naturalStart,end:e.naturalEnd,rowStart:e.rowStart,rowEnd:e.rowEnd})),ke=new Map;for(let e of De){let t=Oe.get(e);t&&ke.set(e.rel,t)}for(let[e,t]of l.relationships.entries()){let n=j.get(t.from),r=j.get(t.to);if(!(!n||!r)&&t.label){let i=Q(t.label),{idealMidX:a}=Te(e,n,r,Math.max(...i.map(e=>M(e)))+2),o=H.get(t)-Math.floor(i.length/2),s=ke.get(t);for(let e=0;e<i.length;e++){let t=o+e,n=i[e],r=ae(` ${n} `),{start:c,cells:l}=ri(Math.max(0,a-Math.floor(r.length/2)),r,n,Math.max(0,s.left),s.right),u=c+l.length;u>0&&t>=0&&(se(L,Math.max(u,1),Math.max(t+1,1)),oe(ce,Math.max(u,1),Math.max(t+1,1)));for(let e=0;e<l.length;e++){let n=c+e;n>=0&&t>=0&&z(n,t,l[e],`text`)}}}}return ci(d,j,L,f,z),pe(L,{roleCanvas:ce,colorMode:i,theme:a,linkCanvas:ue})}function oi(e){let t=new Map;if(e.notes.length===0)return{diagram:e,notesById:t};let n=(e,n)=>{let r=`note ${e}`;return t.set(r,n),{id:r,label:n.text,attributes:[],methods:[]}},r=new Set(e.classes.map(e=>e.id)),i=[];for(let t of e.classes){i.push(t);for(let[r,a]of e.notes.entries())a.forClass===t.id&&i.push(n(r,a))}for(let[t,a]of e.notes.entries())(a.forClass===void 0||!r.has(a.forClass))&&i.push(n(t,a));return{diagram:{...e,classes:i},notesById:t}}function si(e,t){for(let[n,r]of e){if(r.forClass===void 0)continue;let e=t.get(r.forClass);e!==void 0&&t.set(n,e)}}function ci(e,t,n,r,i){if(e.size===0)return;let a=Ft(`rounded`,r),o=r?`.`:`╌`;for(let[r,s]of e){let e=t.get(r);if(!e)continue;let c=e.x+e.width-1,l=e.y+e.height-1;if(i(e.x,e.y,a.tl,`border`),i(c,e.y,a.tr,`border`),i(e.x,l,a.bl,`border`),i(c,l,a.br,`border`),s.forClass===void 0)continue;let u=t.get(s.forClass);if(!u||u.x+u.width>e.x||u.y!==e.y)continue;let d=u.y+1;for(let t=u.x+u.width;t<e.x;t++)n[t]?.[d]===` `&&i(t,d,o,`line`)}}function li(e){let t=e.trim();return t.length>=2&&(t[0]===`"`&&t[t.length-1]===`"`||t[0]===`'`&&t[t.length-1]===`'`)?t.slice(1,-1):t}var ui=`"graph <dir>"/"flowchart <dir>" (dir: TD, TB, LR, BT, RL), "stateDiagram-v2", "sequenceDiagram", "classDiagram", "erDiagram", "xychart-beta"`;function di(e){let t=e.trim().toLowerCase();if(/^sequence/.test(t))return`sequenceDiagram`;if(/^class/.test(t))return`classDiagram`;if(/^er/.test(t))return`erDiagram`;if(/^xychart/.test(t))return`xychart-beta`;if(/^state/.test(t))return`stateDiagram-v2`}var fi=/^(?:[\w-]+@)?<?(?:-{2,}|={2,}|-\.+-?|~{3,})/;function pi(e){let t=[];for(let n of e)n.forEach((e,n)=>{if(n===0&&t.length>0&&fi.test(e.text)){let n=t[t.length-1];t[t.length-1]={text:`${n.text} ${e.text}`,line:n.line}}else t.push(e)});return t}function mi(t){let n=(0,e.extractInitConfig)(t.split(`
5
+ `).map(e=>e.trim())),r=pi((0,e.splitStatementsByLine)(t));if(r.length===0)throw Error(`Empty mermaid diagram`);let i=r[0],a=/^stateDiagram(-v2)?\s*$/i.test(i.text)?gi(r):hi(r);return a.initConfig=n,a}function hi(t){let n=t[0];if(n===void 0)throw Error(`parseFlowchart called with no lines`);let r=n.text,i=r.match(/^(?:graph|flowchart)\s+(TD|TB|LR|BT|RL)\s*$/i);if(!i){let e=r.match(/^(?:graph|flowchart)\b\s*(.*)$/i);if(e){let t=e[1].trim();throw Error(t.length>0?`Line ${n.line}: Invalid direction "${t}" in header "${r}". Expected one of: TD, TB, LR, BT, RL.`:`Line ${n.line}: Missing direction in header "${r}". Expected e.g. "graph TD" or "flowchart LR" — one of: TD, TB, LR, BT, RL.`)}let t=di(r),i=t&&t.toLowerCase()!==r.trim().toLowerCase()?` Did you mean "${t}"?`:``;throw Error(`Line ${n.line}: Invalid mermaid header: "${r}".${i} Supported headers: ${ui}.`)}let a={direction:(0,e.toDirection)(i[1]),nodes:new Map,edges:[],subgraphs:[],classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,linkStyles:new Map,interactions:new Map},o=[];for(let n=1;n<t.length;n++){let r=t[n].text;if((0,e.tryApplyClassDef)(r,a)||(0,e.tryApplyClassAssignment)(r,a)||(0,e.tryApplyStyleStatement)(r,a))continue;if(/^click\s+/i.test(r)){Oi(r,a);continue}if(Ai(r,a))continue;let i=r.match(/^linkStyle\s+(default|[\d,\s]+)\s+(.+)$/);if(i){let t=i[1].trim(),n=(0,e.parseStyleProps)(i[2]);if(t==="default")a.linkStyles.set(`default`,{...a.linkStyles.get(`default`),...n});else{let e=t.split(`,`).map(e=>parseInt(e.trim(),10));for(let t of e)isNaN(t)||a.linkStyles.set(t,{...a.linkStyles.get(t),...n})}continue}let s=r.match(/^direction\s+(TD|TB|LR|BT|RL)\s*$/i);if(s&&o.length>0){o[o.length-1].direction=(0,e.toDirection)(s[1]);continue}let c=r.match(/^subgraph\s+(.+)$/);if(c){let t=c[1].trim(),n=t.match(/^([^\s[]+)\s*\[(.+)\]$/),r,i;n?(r=n[1],i=(0,e.normalizeBrTags)(li(n[2]))):(i=(0,e.normalizeBrTags)(li(t)),r=i.replace(/\s+/g,`_`).replace(/[^\p{L}\p{N}_-]/gu,``));let a={id:r,label:i,nodeIds:[],children:[]};o.push(a);continue}if(r===`end`){let e=o.pop();e&&(o.length>0?o[o.length-1].children.push(e):a.subgraphs.push(e));continue}Pi(r,a,o)}return a}function gi(t){let n={direction:`TD`,nodes:new Map,edges:[],subgraphs:[],classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,linkStyles:new Map,interactions:new Map},r=[],i=new Set,a=0,o=0;for(let s=1;s<t.length;s++){let c=t[s].text,l=c.match(/^direction\s+(TD|TB|LR|BT|RL)\s*$/i);if(l){r.length>0?r[r.length-1].direction=(0,e.toDirection)(l[1]):n.direction=(0,e.toDirection)(l[1]);continue}let u=c.match(/^linkStyle\s+(default|[\d,\s]+)\s+(.+)$/);if(u){let t=u[1].trim(),r=(0,e.parseStyleProps)(u[2]);if(t==="default")n.linkStyles.set(`default`,{...n.linkStyles.get(`default`),...r});else{let e=t.split(`,`).map(e=>parseInt(e.trim(),10));for(let t of e)isNaN(t)||n.linkStyles.set(t,{...n.linkStyles.get(t),...r})}continue}if(Ai(c,n))continue;let d=c.match(/^state\s+(?:"([^"]+)"\s+as\s+)?([\w\p{L}]+)\s*\{$/u);if(d){let e=d[1]??d[2],t=d[2],a={id:t,label:e,nodeIds:[],children:[]};r.push(a),i.add(t),n.nodes.delete(t);continue}if(c===`}`){let e=r.pop();e&&(r.length>0?r[r.length-1].children.push(e):n.subgraphs.push(e));continue}let f=c.match(/^state\s+"([^"]+)"\s+as\s+([\w\p{L}]+)\s*$/u);if(f){let t=(0,e.normalizeBrTags)(f[1]),i=f[2];_i(n,r,{id:i,label:t,shape:`rounded`});continue}let p=c.match(/^(\[\*\]|[\w\p{L}-]+)\s*(?:([\w-]+)@)?-->\s*(\[\*\]|[\w\p{L}-]+)(?:\s*:\s*(.+))?$/u);if(p){let t=p[1],s=p[2],c=p[3],l=p[4]?.trim(),u=l?(0,e.normalizeBrTags)(l):void 0;t===`[*]`?(a++,t=`_start${a>1?a:``}`,_i(n,r,{id:t,label:``,shape:`state-start`})):i.has(t)||vi(n,r,t),c===`[*]`?(o++,c=`_end${o>1?o:``}`,_i(n,r,{id:c,label:``,shape:`state-end`})):i.has(c)||vi(n,r,c),n.edges.push({source:t,target:c,label:u,style:`solid`,hasArrowStart:!1,hasArrowEnd:!0,...s===void 0?{}:{id:s}});continue}let m=c.match(/^([\w\p{L}-]+)\s*:\s*(.+)$/u);if(m){let t=m[1];_i(n,r,{id:t,label:(0,e.normalizeBrTags)(m[2].trim()),shape:`rounded`});continue}}return n}function _i(e,t,n){if(e.nodes.has(n.id)||e.nodes.set(n.id,n),t.length>0){let e=t[t.length-1];e.nodeIds.includes(n.id)||e.nodeIds.push(n.id)}}function vi(e,t,n){if(!e.nodes.has(n))_i(e,t,{id:n,label:n,shape:`rounded`});else if(t.length>0){let e=t[t.length-1];e.nodeIds.includes(n)||e.nodeIds.push(n)}}var yi=/^(<|o|x)?(-{2,}|={2,}|-\.+-|~{3,})(>|o|x)?(?:\|([^|]*)\|)?/,bi=new Set([`--`,`==`]);function xi(e){if(e===`o`)return`circle`;if(e===`x`)return`cross`}var Si=/^(<|o|x)?(--|-\.|==)\s+(.+?)\s+(-{2,}[>ox]|={2,}[>ox]|\.+-[>ox]|-{3,}|={3,}|-\.+-)/,Ci=[{regex:/^([\w\p{L}-]+)\(\(\(((?:"[^"]*"|(?!\)\)\)).)+)\)\)\)/u,shape:`doublecircle`},{regex:/^([\w\p{L}-]+)\(\[((?:"[^"]*"|(?!\]\)).)+)\]\)/u,shape:`stadium`},{regex:/^([\w\p{L}-]+)\(\(((?:"[^"]*"|(?!\)\)).)+)\)\)/u,shape:`circle`},{regex:/^([\w\p{L}-]+)\[\[((?:"[^"]*"|(?!\]\]).)+)\]\]/u,shape:`subroutine`},{regex:/^([\w\p{L}-]+)\[\(((?:"[^"]*"|(?!\)\]).)+)\)\]/u,shape:`cylinder`},{regex:/^([\w\p{L}-]+)\[\/((?:"[^"]*"|(?![\\/]\]).)+)([\\/])\]/u,shape:e=>e===`\\`?`trapezoid`:`parallelogram`},{regex:/^([\w\p{L}-]+)\[\\((?:"[^"]*"|(?![\\/]\]).)+)([\\/])\]/u,shape:e=>e===`/`?`trapezoid-alt`:`parallelogram-alt`},{regex:/^([\w\p{L}-]+)>((?:"[^"]*"|(?!\]).)+)\]/u,shape:`asymmetric`},{regex:/^([\w\p{L}-]+)\{\{((?:"[^"]*"|(?!\}\}).)+)\}\}/u,shape:`hexagon`},{regex:/^([\w\p{L}-]+)\[((?:"[^"]*"|(?!\]).)+)\]/u,shape:`rectangle`},{regex:/^([\w\p{L}-]+)\(((?:"[^"]*"|(?!\)).)+)\)/u,shape:`rounded`},{regex:/^([\w\p{L}-]+)\{((?:"[^"]*"|(?!\}).)+)\}/u,shape:`diamond`}],wi=/^([\w\p{L}]+(?:-[\w\p{L}]+)*)/u,Ti=/^([\w\p{L}-]+)(?=@\{)/u;function Ei(e){if(e.shape)return(0,t.resolveShapeName)(e.shape)??`rectangle`;if(e.icon!==void 0||e.img!==void 0)switch(e.form?.toLowerCase()){case`circle`:return`circle`;case`rounded`:return`rounded`;default:return`rectangle`}return`rectangle`}function Di(e,t){return t.label!==void 0&&t.label.length>0?t.label:t.icon?t.icon:t.img?t.img:e}function Oi(t,n){(0,e.applyClickStatement)(t,n.interactions)}var ki=/^([\w-]+)(?=@\{)/;function Ai(e,n){let r=e.match(ki);if(!r||!n.edges.some(e=>e.id===r[1]))return!1;let i=(0,t.matchExpandedBlock)(e.slice(r[1].length));return i?(ji(n,r[1],(0,t.parseExpandedMeta)(i.body)),!0):!1}function ji(e,t,n){for(let r of e.edges)r.id===t&&(n.animate!==void 0&&(r.animate=n.animate.toLowerCase()!==`false`),n.animation!==void 0&&(r.animate=!0))}var Mi=/^:::([\w][\w-]*)/,Ni=/^([\w\p{L}-]+):::([\w][\w-]*)/u;function Pi(t,n,r){let i=t.trim(),a=Fi(i,n,r);if(!a||a.ids.length===0)return;i=a.remaining.trim();let o=a.ids;for(;i.length>0;){let t,a,s,c,l,u,d,f=i.match(/^([\w-]+)@(?=[-=<~ox])/);f&&(d=f[1],i=i.slice(f[0].length));let p=i.match(yi),m=p?.[2],h=p?.[1],g=p?.[3];if(p&&m!==void 0&&!(h===void 0&&g===void 0&&bi.has(m))){t=h!==void 0,l=xi(h);let n=p[4]?.trim();c=n?(0,e.normalizeBrTags)(n):void 0,i=i.slice(p[0].length).trim(),a=zi(m),s=g!==void 0,u=xi(g)}else{let n=i.match(Si);if(!n)break;t=!!n[1],l=xi(n[1]);let r=n[3].trim();c=r?(0,e.normalizeBrTags)(r):void 0;let o=n[2],d=n[4];i=i.slice(n[0].length).trim(),a=Bi(o,d),u=xi(d.slice(-1)),s=d.endsWith(`>`)||u!==void 0}let _=Fi(i,n,r);if(!_||_.ids.length===0)break;i=_.remaining.trim();for(let e of o)for(let r of _.ids)n.edges.push({source:e,target:r,label:c,style:a,hasArrowStart:t,hasArrowEnd:s,...l===void 0?{}:{startMarker:l},...u===void 0?{}:{endMarker:u},...d===void 0?{}:{id:d}});o=_.ids}}function Fi(e,t,n){let r=Ii(e,t,n);if(!r)return null;let i=[r.id],a=r.remaining.trim();for(;a.startsWith(`&`);){a=a.slice(1).trim();let e=Ii(a,t,n);if(!e)break;i.push(e.id),a=e.remaining.trim()}return{ids:i,remaining:a}}function Ii(n,r,i){let a=null,o=n,s,c=o.match(Ni);c&&(s=c[2],o=c[1]+o.slice(c[0].length));let l=o.match(Ti);if(l){let n=l[1],s=(0,t.matchExpandedBlock)(o.slice(n.length));if(s){let c=(0,t.parseExpandedMeta)(s.body);Li(r,i,{id:n,label:(0,e.normalizeBrTags)(Di(n,c)),shape:Ei(c)}),a=n,o=o.slice(n.length+s.length)}}if(a===null)for(let{regex:t,shape:n}of Ci){let s=o.match(t);if(s){a=s[1];let t=(0,e.normalizeBrTags)(s[2]),c=typeof n==`function`?n(s[3]??``):n;Li(r,i,{id:a,label:t,shape:c}),o=o.slice(s[0].length);break}}if(a===null){let e=o.match(wi);e&&(a=e[1],r.nodes.has(a)||Li(r,i,{id:a,label:a,shape:`rectangle`}),o=o.slice(e[0].length))}if(a===null)return null;s&&r.classAssignments.set(a,s);let u=o.match(Mi);return u&&(r.classAssignments.set(a,u[1]),o=o.slice(u[0].length)),{id:a,remaining:o}}function Li(e,t,n){e.nodes.has(n.id)||e.nodes.set(n.id,n),Ri(t,n.id)}function Ri(e,t){if(e.length>0){let n=e[e.length-1];n.nodeIds.includes(t)||n.nodeIds.push(t)}}function zi(e){return e.startsWith(`~`)?`invisible`:e.includes(`.`)?`dotted`:e.startsWith(`=`)?`thick`:`solid`}function Bi(e,t){return e.includes(`.`)||t.includes(`.`)?`dotted`:e.startsWith(`=`)||t.startsWith(`=`)?`thick`:`solid`}function Vi(t,n){let r=new Set,i=new Map;for(let e of t.subgraphs)Hi(e,r,i);let a=new Map,o=0;for(let[n,i]of t.nodes){if(r.has(n))continue;let t={name:n,displayLabel:(0,e.stripFormattingTags)(i.label),shape:i.shape,index:o,gridCoord:null,drawingCoord:null,drawing:null,drawn:!1,styleClassName:``,styleClass:Ze};a.set(n,t),o++}let s=[...a.values()],c=[];for(let n of t.edges){let o=n.source,s=n.target;if(r.has(o)){let e=i.get(o),n=e?Gi(e,t,`exit`):void 0;n&&(o=n)}if(r.has(s)){let e=i.get(s),n=e?Gi(e,t,`entry`):void 0;n&&(s=n)}let l=a.get(o),u=a.get(s);!l||!u||c.push({from:l,to:u,text:n.label?(0,e.stripFormattingTags)(n.label):``,path:[],labelLine:[],startDir:{x:0,y:0},endDir:{x:0,y:0},style:n.style,hasArrowStart:n.hasArrowStart,hasArrowEnd:n.hasArrowEnd,...n.startMarker===void 0?{}:{startMarker:n.startMarker},...n.endMarker===void 0?{}:{endMarker:n.endMarker}})}let l=[];for(let e of t.subgraphs)Ki(e,null,a,l,t);qi(t.subgraphs,l,a);let u=t.classDefs.get(`default`);if(u)for(let e of a.values())e.styleClassName=`default`,e.styleClass={name:`default`,styles:u};for(let[e,n]of t.classAssignments){let r=a.get(e),i=t.classDefs.get(n);r&&i&&(r.styleClassName=n,r.styleClass={name:n,styles:u?{...u,...i}:i})}return{nodes:s,edges:c,canvas:N(0,0),roleCanvas:F(0,0),grid:$e(),columnWidth:new Map,rowHeight:new Map,subgraphs:l,config:n,offsetX:0,offsetY:0,bundles:[]}}function Hi(e,t,n){t.add(e.id),n.set(e.id,e);for(let r of e.children)Hi(r,t,n)}function Ui(e,t){for(let n of e.nodeIds)t.add(n);for(let n of e.children)Ui(n,t)}function Wi(e,t){let n=new Set;if(Ui(e,n),n.size===0)return!0;let r=t=>n.has(t)||t===e.id;return!t.edges.some(e=>r(e.source)!==r(e.target))}function Gi(e,t,n){let r=new Set;if(Ui(e,r),r.size===0)return;let i=[...t.nodes.keys()].filter(e=>r.has(e));if(i.length===0)return;let a=i.filter(e=>n===`entry`?!t.edges.some(t=>t.target===e&&r.has(t.source)):!t.edges.some(t=>t.source===e&&r.has(t.target))),o=a.length>0?a:i;return n===`entry`?o[0]:o[o.length-1]}function Ki(e,t,n,r,i){let a;e.direction&&Wi(e,i)&&(a=e.direction===`LR`||e.direction===`RL`?`LR`:`TD`);let o={name:e.label,nodes:[],parent:t,children:[],minX:0,minY:0,maxX:0,maxY:0,direction:a};for(let t of e.nodeIds){let e=n.get(t);e&&o.nodes.push(e)}r.push(o);for(let t of e.children){let e=Ki(t,o,n,r,i);o.children.push(e);for(let t of e.nodes)o.nodes.includes(t)||o.nodes.push(t)}return o}function qi(e,t,n){let r=new Map;Yi(e,t,r);let i=new Map;function a(e){let t=r.get(e);if(t){for(let t of e.children)a(t);for(let n of e.nodeIds)i.has(n)||i.set(n,t)}}for(let t of e)a(t);for(let e of t)e.nodes=e.nodes.filter(t=>{let r;for(let[e,i]of n)if(i===t){r=e;break}if(!r)return!1;let a=i.get(r);return!a||Ji(e,a)})}function Ji(e,t){let n=t;for(;n!==null;){if(n===e)return!0;n=n.parent}return!1}function Yi(e,t,n){let r=[];function i(e){for(let t of e)r.push(t),i(t.children)}i(e);for(let e=0;e<r.length&&e<t.length;e++){let i=r[e],a=t[e];!i||!a||n.set(i,a)}}function Xi(t,n,r,i,a={}){let o=(0,e.withDirectionOverride)(mi(t),a.direction);n.graphDirection=o.direction===`LR`||o.direction===`RL`?`LR`:`TD`;let s=Vi(o,n);Mn(s),Rr(s);let c=a.hyperlinks?d(s,o.interactions):void 0;return o.direction===`BT`&&(he(s.canvas),ge(s.roleCanvas),c&&l(c)),pe(s.canvas,{roleCanvas:s.roleCanvas,colorMode:r,theme:i,linkCanvas:c})}var Zi={xychart:(e,t,n,r)=>Te(e,t,n,r),er:(e,t,n,r)=>Gr(e,t,n,r),sequence:(e,t,n,r)=>Zr(e,t,n,r),class:(e,t,n,r,i)=>ai(e,t,n,r,i),flowchart:(e,t,n,r,i)=>Xi(e,t,n,r,i)},Qi=/\x1b\[[0-9;]*m/g;function $i(e){let t=e.split(`
6
+ `),n=t.reduce((e,t)=>Math.max(e,o(t.replace(Qi,``)).length),0),r=String(Math.max(0,t.length-1)).length,i=` `.repeat(r+1);return[i+Array.from({length:n},(e,t)=>String(Math.floor(t/10)%10)).join(``),i+Array.from({length:n},(e,t)=>String(t%10)).join(``),...t.map((e,t)=>`${String(t).padStart(r,` `)} ${e}`)].join(`
7
+ `)}function ea(t,n={}){let r={useAscii:n.useAscii??!1,paddingX:n.paddingX??5,paddingY:n.paddingY??5,boxBorderPadding:n.boxBorderPadding??1,graphDirection:`TD`},i=n.colorMode===`auto`||n.colorMode===void 0?g():n.colorMode,a={...m,...n.theme},o=Zi[(0,e.detectDiagramType)(t)](t,r,i,a,{hyperlinks:n.hyperlinks??!1,direction:n.direction});return n.showCoords?$i(o):o}var ta=ea;exports.DEFAULT_ASCII_THEME=m,exports.detectColorMode=g,exports.diagramColorsToAsciiTheme=h,exports.renderMermaidASCII=ea,exports.renderMermaidAscii=ta;
8
8
  //# sourceMappingURL=index.cjs.map