@zombie-mermaid/ascii-renderer 4.1.0 → 4.2.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.
- package/dist/index.cjs +5 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2771 -2109
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/ascii-back-edge-loop-1349.test.ts +78 -0
- package/src/__tests__/ascii-beside-cells-other-labels-1338.test.ts +94 -0
- package/src/__tests__/ascii-center-parent-over-children.test.ts +4 -1
- package/src/__tests__/ascii-charset-border-junctions.test.ts +5 -3
- package/src/__tests__/ascii-cluster-entry-multi-1181.test.ts +15 -7
- package/src/__tests__/ascii-cluster-exit-anchoring-1148.test.ts +45 -29
- package/src/__tests__/ascii-cluster-exit-lanes-1182.test.ts +15 -9
- package/src/__tests__/ascii-cluster-exit-offsets-1182.test.ts +169 -0
- package/src/__tests__/ascii-cluster-exit-wall-start-1330.test.ts +109 -0
- package/src/__tests__/ascii-edge-bundling-rank-violation-454.test.ts +10 -5
- package/src/__tests__/ascii-fan-in-center-1339.test.ts +185 -0
- package/src/__tests__/ascii-fan-out-exit-offsets-1308.test.ts +168 -0
- package/src/__tests__/ascii-fan-out-upstream-113.test.ts +4 -2
- package/src/__tests__/ascii-label-attribution.test.ts +121 -0
- package/src/__tests__/ascii-label-gaps-157-upstream.test.ts +59 -0
- package/src/__tests__/ascii-label-placement-1347.test.ts +63 -0
- package/src/__tests__/ascii-label-spaces-1348.test.ts +46 -0
- package/src/__tests__/ascii-labeled-fan-in-center-1339.test.ts +106 -0
- package/src/__tests__/ascii-longest-path-layering.test.ts +74 -0
- package/src/__tests__/ascii-port-offsets-1350.test.ts +94 -0
- package/src/__tests__/ascii-reciprocal-routing-1349.test.ts +70 -0
- package/src/__tests__/pie-ascii.test.ts +386 -0
- package/src/__tests__/testdata/ascii/ampersand_rhs.txt +13 -15
- package/src/__tests__/testdata/ascii/ampersand_td_fanin.txt +15 -15
- package/src/__tests__/testdata/ascii/backlink_from_bottom.txt +7 -15
- package/src/__tests__/testdata/ascii/backlink_from_top.txt +7 -15
- package/src/__tests__/testdata/ascii/backlink_with_short_y_padding.txt +6 -13
- package/src/__tests__/testdata/ascii/comments.txt +7 -15
- package/src/__tests__/testdata/ascii/preserve_order_of_definition.txt +7 -15
- package/src/__tests__/testdata/ascii/subgraph_complex_mixed.txt +19 -21
- package/src/__tests__/testdata/ascii/subgraph_multiple_edges.txt +21 -21
- package/src/__tests__/testdata/unicode/ampersand_rhs.txt +13 -15
- package/src/__tests__/testdata/unicode/backlink_from_bottom.txt +7 -15
- package/src/__tests__/testdata/unicode/backlink_from_top.txt +7 -15
- package/src/__tests__/testdata/unicode/comments.txt +7 -15
- package/src/__tests__/testdata/unicode/preserve_order_of_definition.txt +7 -15
- package/src/cluster-boundary.ts +3 -1
- package/src/draw-arrows.ts +369 -32
- package/src/draw.ts +15 -1
- package/src/edge-cell-styles.ts +88 -0
- package/src/edge-routing.ts +198 -11
- package/src/flowchart.ts +35 -3
- package/src/grid.ts +257 -17
- package/src/index.ts +1 -0
- package/src/pie.ts +254 -0
- package/src/port-offsets.ts +601 -0
- package/src/registry.ts +3 -0
- package/src/types.ts +7 -0
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
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){return e.reverse(),e}function d(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 f(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&&d(o,n.drawing,n.drawingCoord,t)}return o}var p=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 m(e,t){let n=new p,r=``;for(let[i,a]of e.entries())r+=n.advance(t[i]??null)+a;return r+n.finish()}var h={fg:`#27272a`,border:`#a1a1aa`,line:`#71717a`,arrow:`#52525b`,corner:`#71717a`,junction:`#a1a1aa`};function g(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 _(){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 v(t){return(0,e.parseHexRgba)(t.startsWith(`#`)?t:`#${t}`)??{r:0,g:0,b:0}}var y=`\x1B[`,b=`${y}0m`;function x(e){let{r:t,g:n,b:r}=v(e);return`${y}38;2;${t};${n};${r}m`}function S(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 C(e){let{r:t,g:n,b:r}=v(e);return`${y}38;5;${S(t,n,r)}m`}function w(e){let{r:t,g:n,b:r}=v(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,`${y}${o+a}m`}function ee(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`)}var T=/^█+$/;function E(e,t){return`<span style="${T.test(t)?`color:${e};background:${e}`:`color:${e}`}">${ee(t)}</span>`}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 D(e,t,n){if(n===`none`)return``;let r=te(e,t);switch(n){case`truecolor`:return x(r);case`ansi256`:return C(r);case`ansi16`:return w(r);default:return``}}function O(e,t,n,r,i){if(r===`none`)return i?m(e,i):e.join(``);if(r===`html`)return k(e,t,n);let a=new p,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+b,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+b),c=d+u,s=e}return c.length>0&&s!==null?o+=D(s,n,r)+c+b:c.length>0&&(o+=c),o+a.finish()}function k(e,t,n){let r=``,i=null,a=``,o=()=>{a.length!==0&&(r+=i===null?ee(a):E(te(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 ne(e,t,n){if(n===`none`||e.length===0)return e;if(n===`html`)return E(t,e);let r;switch(n){case`truecolor`:r=x(t);break;case`ansi256`:r=C(t);break;case`ansi16`:r=w(t);break;default:return e}return`${r}${e}${b}`}var A=/\p{Mn}|\p{Me}/u;function re(e){return A.test(e)}var ie=new Intl.Segmenter(void 0,{granularity:`grapheme`}),j=`️`;function M(e){let t=[];for(let{segment:n}of ie.segment(e))t.push(n);return t}function ae(t){if(t.includes(j))return 2;let n=!1,r=!1;for(let i of t)(0,e.isWideChar)(i)&&(n=!0),re(i)||(r=!0);return n?2:+!!r}function N(e){let t=0;for(let n of M(e))t+=ae(n);return t}function oe(e){let t=[];for(let n of M(e)){let e=ae(n);e!==0&&(t.push(n),e===2&&t.push(``))}return t}function P(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 F(e){let[t,n]=L(e);return P(t,n)}function se(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 ce(e,t,n){let r=e.length-1,i=(e[0]?.length??1)-1,a=se(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))&&ce(e,t,n),e[t][n]=r}function L(e){return[e.length-1,(e[0]?.length??1)-1]}function le(e,t,n){let[r,i]=L(e),a=P(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 z=new Set([`─`,`│`,`┌`,`┐`,`└`,`┘`,`├`,`┤`,`┬`,`┴`,`┼`,`╴`,`╵`,`╶`,`╷`]);function ue(e){return z.has(e)}function de(e){return/^[a-zA-Z0-9]$/.test(e)}var fe={"─":{"│":`┼`,"┌":`┬`,"┐":`┬`,"└":`┴`,"┘":`┴`,"├":`┼`,"┤":`┼`,"┬":`┬`,"┴":`┴`},"│":{"─":`┼`,"┌":`├`,"┐":`┤`,"└":`├`,"┘":`┤`,"├":`├`,"┤":`┤`,"┬":`┼`,"┴":`┼`},"┌":{"─":`┬`,"│":`├`,"┐":`┬`,"└":`├`,"┘":`┼`,"├":`├`,"┤":`┼`,"┬":`┬`,"┴":`┼`},"┐":{"─":`┬`,"│":`┤`,"┌":`┬`,"└":`┼`,"┘":`┤`,"├":`┼`,"┤":`┤`,"┬":`┬`,"┴":`┼`},"└":{"─":`┴`,"│":`├`,"┌":`├`,"┐":`┼`,"┘":`┴`,"├":`├`,"┤":`┼`,"┬":`┼`,"┴":`┴`},"┘":{"─":`┴`,"│":`┤`,"┌":`┼`,"┐":`┤`,"└":`┴`,"├":`┼`,"┤":`┤`,"┬":`┼`,"┴":`┴`},"├":{"─":`┼`,"│":`├`,"┌":`├`,"┐":`┼`,"└":`├`,"┘":`┼`,"┤":`┼`,"┬":`┼`,"┴":`┼`},"┤":{"─":`┼`,"│":`┤`,"┌":`┼`,"┐":`┤`,"└":`┼`,"┘":`┤`,"├":`┼`,"┬":`┼`,"┴":`┼`},"┬":{"─":`┬`,"│":`┼`,"┌":`┬`,"┐":`┬`,"└":`┼`,"┘":`┼`,"├":`┼`,"┤":`┼`,"┴":`┼`},"┴":{"─":`┴`,"│":`┼`,"┌":`┼`,"┐":`┼`,"└":`┴`,"┘":`┴`,"├":`┼`,"┤":`┼`,"┬":`┼`}};function pe(e,t){return fe[e]?.[t]??e}function me(e){let t=new Map,n=[];for(let r of e){let[e,i]=L(r),a=F(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&&ue(s)&&ue(i)))continue}else t.set(o,i);a[n][e]=i}n.push(a)}return n}function he(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=P(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&&ue(a)&&ue(c)?o[e][s]=pe(c,a):de(c)&&de(a)||(o[e][s]=a)}}return o}function ge(e,t){let[n,r]=L(e),i=[],a=t?.roleCanvas,o=t?.colorMode??`none`,s=t?.theme??h,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(m(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
2
|
`)}var B={"▲":`▼`,"▼":`▲`,"↖":`↙`,"↙":`↖`,"↗":`↘`,"↘":`↗`,"^":`v`,v:`^`,"┌":`└`,"└":`┌`,"┐":`┘`,"┘":`┐`,"┬":`┴`,"┴":`┬`,"╭":`╰`,"╰":`╭`,"╮":`╯`,"╯":`╮`,"╵":`╷`,"╷":`╵`};function V(e,t){for(let[n,r]of e.entries())for(let[e,i]of r.entries()){if(t?.[n]?.[e]===`text`)continue;let a=B[i];a&&(r[e]=a)}for(let t of e)t.reverse();return e}function _e(e,t,n,r){let i=[],a=new Set;for(let{x0:e,y0:r,x1:o,y1:s}of n){if(r===s)continue;let n=[];for(let i=e;i<=o;i++)for(let e=r;e<=s;e++){let r=`${i},${e}`;t[i]?.[e]!==`text`||a.has(r)||(a.add(r),n.push([i,e]))}i.push({cells:n,ySum:r+s})}for(let{cells:n,ySum:a}of i)ve(e,n,a,` `),ve(t,n,a,null),r&&ve(r,n,a,null)}function ve(e,t,n,r){let i=t.map(([t,n])=>e[t][n]);for(let[n,i]of t)e[n][i]=r;for(let[r,[a,o]]of t.entries())e[a][n-o]=i[r]}function ye(e){for(let t of e)t.reverse();return e}var be={"►":`◄`,"◄":`►`,">":`<`,"<":`>`,"↖":`↗`,"↗":`↖`,"↙":`↘`,"↘":`↙`,"┌":`┐`,"┐":`┌`,"└":`┘`,"┘":`└`,"├":`┤`,"┤":`├`,"╭":`╮`,"╮":`╭`,"╰":`╯`,"╯":`╰`,"╔":`╗`,"╗":`╔`,"╚":`╝`,"╝":`╚`,"╟":`╢`,"╢":`╟`,"⌜":`⌝`,"⌝":`⌜`,"⌞":`⌟`,"⌟":`⌞`,"╱":`╲`,"╲":`╱`,"/":`\\`,"\\":`/`,"◢":`◣`,"◣":`◢`,"◤":`◥`,"◥":`◤`,"◸":`◹`,"◹":`◸`,"◺":`◿`,"◿":`◺`};function xe(e,t){for(let[n,r]of e.entries())for(let[e,i]of r.entries()){if(t?.[n]?.[e]===`text`)continue;let a=be[i];a&&(r[e]=a)}return e.reverse(),e}function Se(e,t,n,r){let i=[],a=new Set;for(let{x0:r,y0:o,x1:s,y1:c}of n){if(r===s)continue;let n=[];for(let i=r;i<=s;i++)for(let r=o;r<=c;r++){let o=`${i},${r}`;t[i]?.[r]!==`text`&&e[i]?.[r]!==``||a.has(o)||(a.add(o),n.push([i,r]))}i.push({cells:n,xSum:r+s})}for(let{cells:n,xSum:a}of i)Ce(e,n,a,` `),Ce(t,n,a,null),r&&Ce(r,n,a,null)}function Ce(e,t,n,r){let i=t.map(([t,n])=>e[t][n]);for(let[n,i]of t)e[n][i]=r;for(let[r,[a,o]]of t.entries())e[n-a][o]=i[r]}function we(e){return e.reverse(),e}function Te(e,t,n,r=!1){let i=oe(n);le(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 Ee(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;le(e,a-1,o-1)}function H(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;ce(e,a-1,o-1)}var De=60,Oe=20,ke={hLine:`─`,vLine:`│`,origin:`┼`,yTick:`┤`,xTick:`┬`,bar:`█`,grid:`·`,cornerTL:`╭`,cornerTR:`╮`,cornerBL:`╰`,cornerBR:`╯`},Ae={hLine:`-`,vLine:`|`,origin:`+`,yTick:`+`,xTick:`+`,bar:`#`,grid:`.`,cornerTL:`+`,cornerTR:`+`,cornerBL:`+`,cornerBR:`+`};function je(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 Me(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 Ne(n,r,i,a){let o=(0,e.splitStatements)(n),s=(0,t.parseXYChart)(o),c=r.useAscii?Ae:ke;return s.horizontal?U(s,c,i,a):Pe(s,c,i,a)}function Pe(e,t,n,r){let i=Ge(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=qe(a.min,a.max),s=Je(o),c=Math.max(...s.map(e=>e.length))+1,l=Math.max(De,i*6),u=Oe,d=Math.floor(l/i),f=Ke(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,ee=C+1+ +!!m+0,T=Re(x,ee),E=ze(x,ee),te=Be(x,ee),D=je(e.series.length,r),O=e=>{let t=(e-a.min)/(a.max-a.min||1);return Math.round(t*19)},k=e=>b+Math.floor(d*(e+.5));e.title&&_>=0&&He(T,E,_,Math.floor(x/2-e.title.length/2),e.title,`text`),g&&Le(T,E,te,e,+!!p,x,t,D);for(let e=0;e<u;e++)W(T,E,v+(19-e),b-1,t.vLine,`border`);W(T,E,S,b-1,t.origin,`border`);for(let[e,n]of o.entries()){let r=O(n);if(r<0||r>=u)continue;let i=v+(19-r),a=s[e];W(T,E,i,b-1,r===0?t.origin:t.yTick,`border`);let o=y+c-a.length;He(T,E,i,Math.max(0,o),a,`text`)}for(let e=b;e<b+d*i;e++)W(T,E,S,e,t.hLine,`border`);for(let e=0;e<i;e++){let n=k(e);W(T,E,S,n,t.xTick,`border`);let r=f[e],i=n-Math.floor(r.length/2);He(T,E,C,Math.max(0,i),r,`text`)}if(e.xAxis.title&&w>=0){let t=e.xAxis.title;He(T,E,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(T,E,r,0,t[e],`text`)}}for(let e of o){let n=O(e);if(n<0||n>=u)continue;let r=v+(19-n);for(let e=b;e<b+d*i;e++)Ve(T,r,e)===` `&&W(T,E,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=O(Math.max(0,a.min));for(let e=0;e<ne.length;e++){let i=ne[e],a=D[i.globalIdx];for(let e=0;e<i.data.length;e++){let o=k(e)-Math.floor(n/2),s=O(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(T,E,r,e,t.bar,`arrow`,te,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=D[e.globalIdx];Fe(T,E,e.data,k,O,v,u,b,d*i,t,te,n)}return Ue(T,E,te,n,r)}function U(e,t,n,r){let i=Ge(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=qe(a.min,a.max),s=Je(o),c=Ke(e,i),l=Math.max(...c.map(e=>e.length))+1,u=Math.max(De,40),d=Math.max(2,Math.floor(Oe/i)),f=d*i,p=!!e.title,m=!!e.yAxis.title,h=e.series.length>1,g=(p?2:0)+ +!!h,_=l+1,v=_+u+2,y=g+f+2+ +!!m,b=g+f,x=Re(v,y),S=ze(v,y),C=Be(v,y),w=je(e.series.length,r),ee=e=>{let t=(e-a.min)/(a.max-a.min||1);return _+Math.round(t*59)},T=e=>g+Math.floor(d*(e+.5));e.title&&He(x,S,0,Math.floor(v/2-e.title.length/2),e.title,`text`),h&&Le(x,S,C,e,+!!p,v,t,w);for(let e=g;e<g+f;e++)W(x,S,e,_-1,t.vLine,`border`);W(x,S,b,_-1,t.origin,`border`);for(let e=0;e<i;e++){let t=T(e),n=c[e],r=l-n.length;He(x,S,t,Math.max(0,r),n,`text`)}for(let e=_;e<_+u;e++)W(x,S,b,e,t.hLine,`border`);for(let[e,n]of o.entries()){let r=ee(n);if(r<_||r>=_+u)continue;W(x,S,b,r,t.xTick,`border`);let i=s[e];He(x,S,b+1,r-Math.floor(i.length/2),i,`text`)}if(e.yAxis.title){let t=e.yAxis.title;He(x,S,y-1,Math.floor(v/2-t.length/2),t,`text`)}for(let e of o){let n=ee(e);if(!(n<_||n>=_+u))for(let e=g;e<g+f;e++)Ve(x,e,n)===` `&&W(x,S,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=ee(Math.max(0,a.min));for(let n=0;n<E.length;n++){let r=E[n],i=w[r.globalIdx];for(let n=0;n<r.data.length;n++){let a=T(n),o=ee(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(x,S,e,n,t.bar,`arrow`,C,i)}}}let te=[];for(let t=0;t<e.series.length;t++)e.series[t].type===`line`&&te.push({data:e.series[t].data,globalIdx:t});for(let e of te){if(e.data.length===0)continue;let n=w[e.globalIdx];Ie(x,S,e.data,T,ee,g,f,_,u,t,C,n)}return Ue(x,S,C,n,r)}function Fe(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 Ie(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 Le(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,He(e,t,i,f,a.label,`text`),f+=a.label.length}}function Re(e,t){return P(e-1,t-1)}function ze(e,t){return se(e-1,t-1)}function Be(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 Ve(e,t,n){return n>=0&&n<e.length&&t>=0&&t<e[0].length?e[n][t]:` `}function He(e,t,n,r,i,a){for(let o=0;o<i.length;o++)W(e,t,n,r+o,i[o],a)}function Ue(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(We(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 We(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?ne(s,o,i):s,s=``,o=null),a+=` `;continue}let u=n[c]??null,d=t[c]??null,f=u??(d?Me(d,r):null);f===o?s+=l:(s.length>0&&(a+=o?ne(s,o,i):s),s=l,o=f)}return s.length>0&&(a+=o?ne(s,o,i):s),a}function Ge(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 Ke(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)=>Ye(n+i*t))}return Array.from({length:t},(e,t)=>String(t+1))}function qe(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 Je(e){let t=e.length>1?Math.abs(e[1]-e[0]):0,n=t>0&&t<1?Math.ceil(-Math.log10(t)-1e-9):0;return e.map(e=>String(Number.isInteger(e)&&n===0?e:Number(e.toFixed(n))))}function Ye(e){return Number.isInteger(e)?String(e):e.toFixed(+(Math.abs(e)<10))}var G={x:1,y:0},K={x:1,y:2},q={x:0,y:1},J={x:2,y:1},Xe={x:2,y:0},Ze={x:0,y:0},Qe={x:2,y:2},$e={x:0,y:2},et={x:1,y:1};function Y(e,t){return e.x===t.x&&e.y===t.y}function tt(e){return Y(e,G)||Y(e,K)||Y(e,q)||Y(e,J)}function nt(e){if(!tt(e))throw Error(`Expected a cardinal direction (Up/Down/Left/Right); got {x:${e.x}, y:${e.y}}`);return e}function rt(e,t,n,r){return Math.max(r,n+(e-t))}function it(e,t){return e.x===t.x&&e.y===t.y}function at(e,t){return e.x===t.x&&e.y===t.y}function ot(e,t){return{x:e.x+t.x,y:e.y+t.y}}function X(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 st={name:``,styles:{}},ct=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 lt(){return new ct}function ut(e){let t=lt();for(let n of e.keys())t.add(n);return t}function dt(e,t){return e.has(X(t))}function ft(e,t){return t.x<0||t.y<0?!1:!dt(e,t)}function pt(e,t,n=3){for(let r=0;r<n;r++)for(let i=0;i<n;i++)if(dt(e,{x:t.x+r,y:t.y+i}))return!1;return!0}function mt(e,t,n=3){if(!pt(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(X(n))}}var ht=1e5;function gt(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>=ht)throw Error(`pathCells: segment from (${r.x},${r.y}) to (${i.x},${i.y}) did not reach its endpoint within ${ht} 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 _t=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 vt(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 yt=.001,bt=[{x:1,y:0},{x:-1,y:0},{x:0,y:1},{x:0,y:-1}],xt=5e4,St=2e5;function Ct(e=St){return{remaining:e}}function wt(e,t,n,r,i=!1){if(r&&r.remaining<=0)return null;let a=new _t;a.push({coord:t,priority:0});let o=new Map;o.set(X(t),0);let s=new Map;s.set(X(t),null);let c=0;for(;a.length>0;){if(++c>xt)return null;if(r){if(r.remaining<=0)return null;r.remaining--}let t=a.pop().coord;if(it(t,n)){let e=[],n=t;for(;n!==null;)e.unshift(n),n=s.get(X(n))??null;return e}let l=o.get(X(t));if(l===void 0)throw Error(`A* pathfinding: missing cost for visited cell ${X(t)}`);for(let r of bt){let c={x:t.x+r.x,y:t.y+r.y};if(!ft(e,c)&&!it(c,n))continue;let u=i?s.get(X(t)):null,d=u&&(t.x-u.x!==r.x||t.y-u.y!==r.y),f=l+1+(d?yt:0),p=X(c),m=o.get(p);if(m===void 0||f<m){o.set(p,f);let e=f+vt(c,n);a.push({coord:c,priority:e}),s.set(p,t)}}}return null}function Tt(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 Et(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)&&!ft(e,a))return!1;if(n)break}return!0}function Dt(e,t,n,r){let i=r?{x:n.x,y:t.y}:{x:t.x,y:n.y};return!Et(e,t,i,!0)||!Et(e,i,n,!1)?null:[t,i,n]}function Ot(e,t,n,r){if(t.x===n.x||t.y===n.y)return null;let i=Y(r,q)||Y(r,J);return Dt(e.grid,t,n,i)??Dt(e.grid,t,n,!i)}function kt(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=Ot(e,t,n,r)??wt(e.grid,t,n,e.pathBudget,e.preferStraightRoutes===!0);return i?Tt(i):null}function At(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||!jt(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:et,sharedNodeDir:et};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||!jt(a,e))continue;let i={type:`fan-out`,edges:[...a],sharedNode:r,otherNodes:a.map(e=>e.to),junctionPoint:null,sharedPath:[],junctionDir:et,sharedNodeDir:et};for(let e of a)e.bundle=i,n.add(e);t.push(i)}return t}function jt(e,t){if(e.length<2)return!1;let n=e[0].style,r=rr(t,e[0].from),i=rr(t,e[0].to);for(let a of e){if(a.style!==n||a.text.length>0)return!1;let e=rr(t,a.from),o=rr(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 Mt(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 Nt(e,t){let n=e.config.graphDirection;t.junctionPoint=Mt(e,t);let r=t.junctionPoint;if(t.type===`fan-in`){t.junctionDir=n===`TD`?G:q,t.sharedNodeDir=n===`TD`?K:J;let i=Z(t.sharedNode),a=nt(n===`TD`?G:q),o=ot(i,a);t.sharedPath=kt(e,r,o,a)??[r,o];for(let i of t.edges){let o=Z(i.from),s=nt(n===`TD`?K:J),c=ot(o,s);i.pathToJunction=kt(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`?K:J,t.sharedNodeDir=n===`TD`?G:q;let i=Z(t.sharedNode),a=nt(n===`TD`?K:J),o=ot(i,a);t.sharedPath=kt(e,o,r,a)??[o,r];for(let i of t.edges){let o=Z(i.to),s=nt(n===`TD`?G:q),c=ot(o,s);i.pathToJunction=kt(e,r,c,s)??[r,c],i.startDir=a,i.endDir=s,i.path=[...t.sharedPath,...i.pathToJunction.slice(1)]}}}function Pt(e){for(let t of e.bundles)Nt(e,t)}function Ft(e){let t=null;for(let n of e.nodes){let e=n.gridCoord;if(e){if(!t){t={minX:e.x,minY:e.y,maxX:e.x+2,maxY:e.y+2};continue}t.minX=Math.min(t.minX,e.x),t.minY=Math.min(t.minY,e.y),t.maxX=Math.max(t.maxX,e.x+2),t.maxY=Math.max(t.maxY,e.y+2)}}return t}function It(e,t,n){let r=e.config.graphDirection!==`LR`,i=r?K:J,a=r?G:q,o=ot(Z(t.anchor),i),s=ot(Z(n.to),a),c=kt(e,t.gutter,s,nt(r?J:K));if(!c||c.length<2)return null;let l=[o,...c];return{path:l,startDir:i,endDir:a,labelSegment:Rt(t)?[l[l.length-2],l[l.length-1]]:[l[1],l[2]]}}function Lt(e,t){let n=t.clusterTarget;if(!n||t.bundle||t.from===t.to)return null;let r=Ft(n),i=t.from.gridCoord;if(!r||!i||n.nodes.includes(t.from)||!n.nodes.includes(t.to))return null;let a=e.config.graphDirection!==`LR`;if(a?i.y+2>=r.minY-1:i.x+2>=r.minX-1)return null;let o=(e,t,n)=>Math.min(Math.max(e,t),n),s=a?{x:o(i.x+1,r.minX+1,r.maxX-1),y:r.minY-1}:{x:r.minX-1,y:o(i.y+1,r.minY+1,r.maxY-1)};if(!ft(e.grid,s))return null;let c=a?K:J,l=a?G:q,u=kt(e,ot(i,c),s,nt(c));return!u||u.length<2?null:{path:u,startDir:c,endDir:l}}function Rt(e){for(let t of e.edges)if(t.parallelLane)return!0;return!1}function zt(e){let t=e.config.graphDirection!==`LR`,n=new Map;for(let t of e.edges){let e=t.clusterSource;if(!e)continue;let r=n.get(e);r?r.push(t):n.set(e,[t])}for(let r=0;r<=Bt;r++){let i=new Map,a=null;for(let[r,o]of n){let n=Ht(e,r,o,t);if(typeof n==`number`){a=n;break}n&&i.set(r,n)}if(a===null||r===Bt){i.size>0&&(e.clusterExitPlans=i);return}Vt(e,t,a)}}var Bt=4;function Vt(e,t,n){let r=e=>t?{x:e.x>=n?e.x+1:e.x,y:e.y}:{x:e.x,y:e.y>=n?e.y+1:e.y};for(let t of e.nodes)t.gridCoord&&=r(t.gridCoord);let i=[...e.grid.keys()];for(let t of i)e.grid.delete(t);for(let t of i){let[n,i]=t.split(`,`).map(Number);e.grid.add(X(r({x:n,y:i})))}let a=t?e.columnWidth:e.rowHeight,o=[...a].filter(([e])=>e>=n);for(let[e]of o)a.delete(e);for(let[e,t]of o)a.set(e+1,t);a.set(n,t?e.config.paddingX:e.config.paddingY)}function Ht(e,t,n,r){let i=Ft(t);if(!i)return null;let a=n.filter(e=>{let n=e.from.gridCoord,a=e.to.gridCoord;return!n||!a||e.bundle||e.from===e.to||!t.nodes.includes(e.from)||t.nodes.includes(e.to)?!1:r?a.y>i.maxY+1:a.x>i.maxX+1}),o=new Set(a),s=new Map;for(let t of e.edges){if(!t.parallelLane)continue;let e=s.get(t.parallelLane.usedOffsets);e?e.push(t):s.set(t.parallelLane.usedOffsets,[t])}let c=a.filter(e=>!e.parallelLane||s.get(e.parallelLane.usedOffsets).every(e=>o.has(e)));if(c.length===0)return null;let l=c[0].from;if(c.some(e=>e.from!==l))return null;let u=Z(l),d=r?{x:u.x+1,y:i.maxY+1}:{x:i.maxX+1,y:u.y+1},f=ot(u,r?K:J),p={box:i,anchor:l,gutter:d,edges:new Set(c)},m=new Set;for(let t of c){let n=t.parallelLane;if(n&&n.index>0&&!Wt(e,p,t)){let r=Ut(e,p,t)?.insertAt,i=c.some(e=>e.parallelLane?.usedOffsets!==n.usedOffsets);if(r!==void 0&&i)return r;m.add(n.usedOffsets)}}if(c=c.filter(e=>!e.parallelLane||!m.has(e.parallelLane.usedOffsets)),new Set(c.map(e=>e.parallelLane?.usedOffsets??e)).size<2)return null;let h=r?d.y-f.y:d.x-f.x;for(let t=1;t<=h;t++){let n=r?{x:f.x,y:f.y+t}:{x:f.x+t,y:f.y};if(!ft(e.grid,n))return null}let g={box:i,anchor:l,gutter:d,edges:new Set(c)};for(let t of c)if(!It(e,g,t))return null;return g}function Ut(e,t,n){let r=e.config.graphDirection!==`LR`,i=n.parallelLane.index;if(i>3)return null;let a=Z(n.to),o=r?a.x:a.y,s=o+1,c=r?t.gutter.x:t.gutter.y,l={lane:o+3,attach:o+2,dir:r?q:G},u={lane:o-1,attach:o,dir:r?J:K},d=r?e.columnWidth:e.rowHeight,f=c>=s;if(i===3||i===2&&f){let t=o+4+(f?i-2:0);if(t===c)return null;let n=e.nodes.some(e=>{let n=Z(e),i=r?n.x:n.y;return i<=t&&t<=i+2});return{...l,lane:t,insertAt:n||!d.has(t)?t:void 0}}let p=(c>=s?[l,u]:[u,l])[i-1];return p.lane===c?null:p.lane<0?{...p,insertAt:0}:d.has(p.lane)?p:null}function Wt(e,t,n){let r=e.config.graphDirection!==`LR`,i=Z(n.to),a=t.gutter,o=Ut(e,t,n);if(!o||o.insertAt!==void 0)return null;let s=Tt(r?[a,{x:o.lane,y:a.y},{x:o.lane,y:i.y+1},{x:o.attach,y:i.y+1}]:[a,{x:a.x,y:o.lane},{x:i.x+1,y:o.lane},{x:i.x+1,y:o.attach}]);if(!Wr(e,gt(s),[n.from,n.to]))return null;let c=r?[{x:o.lane,y:a.y},{x:o.lane,y:i.y}]:[{x:a.x,y:o.lane},{x:i.x,y:o.lane}];return{path:s,endDir:o.dir,labelSegment:c}}var Gt=64;function Kt(e){let t=e.clusterExitPlans;if(!t)return!1;let n=e.config.graphDirection!==`LR`,r=!1,i=[...t].sort(([e],[t])=>qt(e)-qt(t));for(let[t,a]of i){let i=n?t.maxY:t.maxX,o=n?e.rowHeight:e.columnWidth,s=n?a.gutter.y:a.gutter.x;for(let t=0;t<Gt&&!Jt(e,a,i,n);t++)o.set(s,(o.get(s)??0)+1),r=!0}return r}function qt(e){let t=0;for(let n=e.parent;n;n=n.parent)t++;return t}function Jt(e,t,n,r){let i=e=>r?e.y:e.x;if(i($(e,t.gutter))<=n)return!1;for(let a of t.edges){let t=Di(e,a),o=a.path[a.path.length-1];if(!t||!o)continue;let s=i($(e,o))-1;for(let{x:e,y:i,text:a}of t){let t=r?i:e,o=r?i:e+N(a)-1;if(t<=n||o>=s)return!1}}return!0}function Q(e){return e.split(`
|
|
4
|
-
`)}function Yt(e){let t=Q(e);return Math.max(...t.map(e=>N(e)),0)}function Xt(e){return Q(e).length}function Zt(e,t){let n=e.maxX-e.minX,r=e.maxY-e.minY;if(n<=0||r<=0)return P(0,0);let i={x:0,y:0},a={x:n,y:r},o=P(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}var Qt=new Set([`│`,`┃`,`║`,`┆`,`┊`,`|`,`:`,`‖`,`┼`,`╋`]);function $t(e){return e!==void 0&&Qt.has(e)}function en(e,t,n,r){let i=(t,i)=>{for(let a=t-i;a<t+e.length+i;a++)if(!(a<1||a>=n)&&r(a))return!0;return!1};if(!i(t,1))return t;let a=Math.max(1,n-e.length);for(let e of[1,0]){let n=-1;for(let r=1;r<=a;r++)i(r,e)||(n<0||Math.abs(r-t)<Math.abs(n-t))&&(n=r);if(n>=0)return n}return null}function tn(e,t){return Math.max(1,1+Math.ceil((t-1-e.length)/2))}function nn(e,t,n){let r=oe(e),i=en(r,tn(r,t),t,n);if(i===null||i+r.length>=t)return!1;for(let e=i-1;e<i+r.length+1;e++)if(e>=1&&e<t&&n(e))return!1;return!0}function rn(e,t,n=()=>!1){let r=e.maxX-e.minX,i=e.maxY-e.minY;if(r<=0||i<=0)return[P(0,0),{x:0,y:0},[]];let a=P(r,i),o=[],s=Q(e.name);for(let e=0;e<s.length;e++){let t=s[e],c=1+e,l=1+Math.ceil((r-1-N(t))/2);l<1&&(l=1);let u=oe(t);l=en(u,l,r,e=>n(e,c))??l;for(let e=0;e<u.length;e++)l+e>=r||c>=i||u[e]===` `&&n(l+e,c)||(R(a,l+e,c,u[e]),o.push({x:l+e,y:c}))}return[a,{x:e.minX,y:e.minY},o]}var an=16;function on(e,t){return e.nodes.includes(t.from)||e.nodes.includes(t.to)}function sn(e,t){let n=[],r=!1;for(let i of e.subgraphs){if(on(i,t))continue;let a=Ft(i);if(a){r=!0;for(let t=a.minX;t<=a.maxX;t++)for(let r=a.minY;r<=a.maxY;r++){let i=X({x:t,y:r});e.grid.has(i)||(e.grid.add(i),n.push(i))}}}return{added:n,engaged:r}}function cn(e,t){for(let n of t)e.grid.delete(n)}function ln(e,t,n){if(t.size===0)return!1;let r=e.config.graphDirection!==`LR`,i=r?e.columnWidth:e.rowHeight,a=!1;for(let o=0;o<an;o++){let o=un(e,t,r);if(!o)break;i.set(o.index,(i.get(o.index)??0)+o.by),a=!0,n()}return a}function un(e,t,n){for(let r of t){let t=r.path;for(let r=1;r<t.length;r++){let i=t[r-1],a=t[r];if(n?i.x!==a.x||i.y===a.y:i.y!==a.y||i.x===a.x)continue;let o=n?i.x:i.y,s=n?$(e,i).x:$(e,i).y,c=n?$(e,i).y:$(e,i).x,l=n?$(e,a).y:$(e,a).x,u=Math.min(c,l),d=Math.max(c,l);for(let t of e.subgraphs){let e=Ft(t);if(!e)continue;let r=n?t.minX:t.minY,i=n?t.maxX:t.maxY,a=n?t.minY:t.minX,c=n?t.maxY:t.maxX;if(d<=a||u>=c)continue;let l=n?e.minX:e.minY,f=n?e.maxX:e.maxY;if(o>f){if(s>i+1)continue;let e=i+2-s;return o-1>f?{index:o-1,by:e}:{index:o,by:2*e}}if(o<l){if(s<r-1)continue;let e=s+2-r;return o+1<l?{index:o+1,by:e}:{index:o,by:2*e}}}}}return null}var dn=4;function fn(e,t){if(e.config.graphDirection===`LR`)return;let n=new Set;for(let r=0;r<e.subgraphs.length;r++){let r=e.subgraphs.find(t=>t.nodes.length>0&&!n.has(t)&&mn(e,t));if(!r)return;let i=pn(r)+dn;for(let a=1;a<=i&&(r.titleRoom=a,t(),mn(e,r));a++)a===i&&(r.titleRoom=0,t(),n.add(r))}}function pn(e){return Math.max(0,...Q(e.name).map(e=>N(e)))}function mn(e,t){let n=t.maxX-t.minX,r=Q(t.name);for(let i=0;i<r.length;i++){let a=t.minY+1+i,o=new Set;for(let n of e.edges)for(let r=1;r<n.path.length;r++){let i=n.path[r-1],s=n.path[r];if(i.x!==s.x||i.y===s.y)continue;let c=$(e,i),l=$(e,s);a<Math.min(c.y,l.y)||a>Math.max(c.y,l.y)||c.x>t.minX&&c.x<t.maxX&&o.add(c.x-t.minX)}if(o.size!==0&&!nn(r[i],n,e=>o.has(e)))return!0}return!1}function hn(){return new Map}function gn(e,t,n,r){for(let i of gt(n)){if(dt(e,i))continue;let n=t.get(X(i));if(n!==void 0&&n!==r)return i}return null}function _n(e,t,n,r){for(let i of gt(n)){if(dt(e,i))continue;let n=X(i);t.has(n)||t.set(n,r)}}function vn(){return new Map}function yn(e,t){return e.to===t.from||t.to===e.from}var bn=2;function xn(e,t){return t(e)?1:bn}function Sn(e,t,n,r,i=()=>!1){let a=new Map,o=new Map;for(let i of gt(n)){if(dt(e,i))continue;let n=t.get(X(i));if(n!==void 0)for(let e of n)e!==r&&yn(e,r)&&(a.set(e,(a.get(e)??0)+1),o.has(e)||o.set(e,i))}for(let[e,t]of a)if(t>=xn(e,i))return o.get(e);return null}function Cn(e,t,n,r){for(let i of gt(n)){if(dt(e,i))continue;let n=X(i),a=t.get(n);a===void 0&&(a=new Set,t.set(n,a)),a.add(r)}}var wn={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 Tn(e,t){let n=wn[e]??wn.rectangle;return t?n.ascii:n.unicode}function En(e,t){let n=Q(e),r=Math.max(...n.map(e=>N(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 Dn(e,t,n,r){let{width:i,height:a}=t,o=P(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(N(t)/2)+1,r=oe(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 On(e,t,n){let{width:r,height:i}=t,a=n.x+Math.floor(r/2),o=n.y+Math.floor(i/2);return Y(e,G)?{x:a,y:n.y}:Y(e,K)?{x:a,y:n.y+i-1}:Y(e,q)?{x:n.x,y:o}:Y(e,J)?{x:n.x+r-1,y:o}:Y(e,Ze)?{x:n.x,y:n.y}:Y(e,Xe)?{x:n.x+r-1,y:n.y}:Y(e,$e)?{x:n.x,y:n.y+i-1}:Y(e,Qe)?{x:n.x+r-1,y:n.y+i-1}:{x:a,y:o}}var kn={getDimensions:En,render(e,t,n){return Dn(e,t,Tn(`rectangle`,n.useAscii),n.useAscii)},getAttachmentPoint:On},An={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=P(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 Y(e,G)?{x:a,y:n.y}:Y(e,K)?{x:a,y:n.y+i-1}:Y(e,q)?{x:n.x,y:o}:Y(e,J)?{x:n.x+r-1,y:o}:{x:a,y:o}}},jn={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=P(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 Y(e,G)?{x:a,y:n.y}:Y(e,K)?{x:a,y:n.y+i-1}:Y(e,q)?{x:n.x,y:o}:Y(e,J)?{x:n.x+r-1,y:o}:{x:a,y:o}}},Mn={getDimensions(e,t){let n=Q(e),r=Math.max(...n.map(e=>N(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=P(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(N(t)/2),o=oe(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:On},Nn={getDimensions(e,t){let n=Q(e),r=Math.max(...n.map(e=>N(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=P(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(N(t)/2),o=oe(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:On},Pn={getDimensions:En,render(e,t,n){return Dn(e,t,Tn(`doublecircle`,n.useAscii),n.useAscii)},getAttachmentPoint:On},Fn={getDimensions(e,t){let n=Q(e),r=Math.max(...n.map(e=>N(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=P(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(N(t)/2),o=oe(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:On},In={getDimensions:En,render(e,t,n){return Dn(e,t,Tn(`asymmetric`,n.useAscii),n.useAscii)},getAttachmentPoint:On},Ln={getDimensions:En,render(e,t,n){return Dn(e,t,Tn(`trapezoid`,n.useAscii),n.useAscii)},getAttachmentPoint:On},Rn={getDimensions:En,render(e,t,n){return Dn(e,t,Tn(`trapezoid-alt`,n.useAscii),n.useAscii)},getAttachmentPoint:On},zn={getDimensions:En,render(e,t,n){return Dn(e,t,Tn(`parallelogram`,n.useAscii),n.useAscii)},getAttachmentPoint:On},Bn={getDimensions:En,render(e,t,n){return Dn(e,t,Tn(`parallelogram-alt`,n.useAscii),n.useAscii)},getAttachmentPoint:On};function Vn(e){return{getDimensions:En,render(t,n,r){return Dn(t,n,Tn(e,r.useAscii),r.useAscii)},getAttachmentPoint:On}}var Hn=Vn(`circle`),Un=Vn(`diamond`),Wn=Vn(`rounded`),Gn=Vn(`hexagon`),Kn=new Map([[`rectangle`,kn],[`rounded`,Wn],[`diamond`,Un],[`stadium`,Mn],[`circle`,Hn],[`subroutine`,Nn],[`doublecircle`,Pn],[`hexagon`,Gn],[`cylinder`,Fn],[`asymmetric`,In],[`trapezoid`,Ln],[`trapezoid-alt`,Rn],[`parallelogram`,zn],[`parallelogram-alt`,Bn],[`state-start`,An],[`state-end`,jn]]);function qn(e){return Kn.get(e)??kn}function Jn(e,t,n){return qn(e).getDimensions(t,n)}function Yn(e,t,n,r){return qn(e).getAttachmentPoint(t,n,r)}function $(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 Xn(e,t){return t.map(t=>$(e,t))}function Zn(e,t,n,r){let i=r??cr(e,t);return pt(e.grid,n,3)?(mt(e.grid,n,3),t.gridCoord=n,n):i===`LR`?Zn(e,t,{x:n.x,y:n.y+4},i):Zn(e,t,{x:n.x+4,y:n.y},i)}function Qn(e,t){let n=Z(t),r=e.config.boxBorderPadding,i=Jn(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;lr(e,t)&&(r+=4);let i=e.rowHeight.get(n.y-1)??0;e.rowHeight.set(n.y-1,Math.max(i,r))}}function $n(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 er=8;function tr(e,t,n,r,i){let a=[],o=(e.clusterExitPlans?.size??0)>0;o&&(e.preferStraightRoutes=!0);try{for(let o=0;o<er;o++){let o=gn(i,n,t.path,t.style)??Sn(i,r,t.path,t,t=>t.clusterSource!==void 0&&e.clusterExitPlans?.get(t.clusterSource)?.edges.has(t)===!0);if(!o)return;e.grid.add(X(o)),a.push(o),Xr(e,t)}}finally{o&&(e.preferStraightRoutes=!1);for(let t of a)e.grid.delete(X(t))}}function nr(e,t){return e.subgraphs.some(e=>e.nodes.includes(t))}function rr(e,t){let n=null;for(let r of e.subgraphs)r.nodes.includes(t)&&(!n||ir(n,r))&&(n=r);return n}function ir(e,t){let n=t;for(;n!==null;){if(n===e)return!0;n=n.parent}return!1}function ar(e,t){let n=rr(e,t);if(!n)return null;let r=n;for(;r.parent;)r=r.parent;return r}function or(e){let t=[...e.nodes];for(let n of e.children)t.push(...or(n));return t}function sr(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 Ir(e,t)){if(a===n)return!0;r.has(a)||(r.add(a),i.push(a))}}return!1}function cr(e,t){let n=rr(e,t);return n?.direction?n.direction:e.config.graphDirection}function lr(e,t){let n=rr(e,t);if(!n)return!1;let r=!1;for(let i of e.edges)if(i.to===t&&rr(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&&rr(e,t.from)!==n){a=!0;break}if(a&&r.gridCoord.y<i)return!1}return!0}function ur(e,t){if(t.nodes.length===0)return;let n=1e6,r=1e6,i=-1e6,a=-1e6;for(let o of t.children)ur(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=>N(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}let l=t.titleRoom??0;l>0&&(t.maxX+=l)}function dr(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 fr(e){return Math.max(0,...Q(e.name).map(e=>N(e)))+1}function pr(e){let t=null;for(let n of or(e)){let e=n.gridCoord;e&&(t=t?{minX:Math.min(t.minX,e.x),minY:Math.min(t.minY,e.y),maxX:Math.max(t.maxX,e.x+2),maxY:Math.max(t.maxY,e.y+2)}:{minX:e.x,minY:e.y,maxX:e.x+2,maxY:e.y+2})}return t}function mr(e){let t=e.subgraphs.filter(e=>e.nodes.length>0),n=(e,t)=>ir(e,t)||ir(t,e),r=!1;for(let i=0;i<64;i++){for(let t of e.subgraphs)ur(e,t);let i=!1;for(let a of t){for(let o of t){if(n(a,o)||!(a.minX<o.minX)||!(a.minY<o.maxY&&a.maxY>o.minY))continue;let t=a.maxX+2-o.minX;if(t<=0)continue;let s=a.parent===null&&o.parent===null,c=a.maxX+2,l=or(o).every(e=>!e.drawingCoord||e.drawingCoord.x>c);if(s&&l&&o.maxX-c>=fr(o))continue;let u=pr(a),d=pr(o);if(!u||!d||u.maxX+1>=d.minX)continue;let f=u.maxX+1;e.columnWidth.set(f,(e.columnWidth.get(f)??0)+t);for(let t of e.nodes)t.drawingCoord=$(e,Z(t));i=!0,r=!0;break}if(i)break}if(!i)break}return hr(e),r}function hr(e){for(let t of e.subgraphs)ur(e,t);dr(e)}function gr(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 _r(e,t){let n=t=>{let n=Ir(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 vr(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 Ir(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 yr(e,t){return e.nodes.find(e=>e.gridCoord!==null&&e.gridCoord.x===t.x&&e.gridCoord.y===t.y)}function br(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(pt(e.grid,c,3))return c;let l=yr(e,c);if(!l||ar(e,l)!==n)return null;o+=4}};return o(i)??o(i*-1)}function xr(e,t,n,r){let i=ar(e,t);if(!i)return;let a=n.get(i);if(!a)return;n.delete(i);let o=Z(t),s=cr(e,t)===`LR`?`y`:`x`;for(let t of a){let n=cr(e,t),a=br(e,o,i,s,1);Zn(e,e.nodes[t.index],a??o,n),r.add(t)}}function Sr(e,t){let n=e.config.boxBorderPadding;for(let r of e.edges){if(r.from!==t||!r.text)continue;let e=N(r.to.displayLabel)+2*n+2;if(Math.floor(e/2)<N(r.text)+2)return!1}return!0}function Cr(e,t){for(let n=0;n<3;n++)for(let r=0;r<3;r++)e.grid.delete(X({x:t.x+n,y:t.y+r}))}function wr(e,t,n){let r=Z(t);Cr(e,r);let i=pt(e.grid,n,3)?n:r;return mt(e.grid,i,3),t.gridCoord=i,i===n}function Tr(e,t,n){let r=e.nodes.filter(e=>e.gridCoord!==null&&e.gridCoord.x>t);for(let t of r)Cr(e,Z(t));for(let t of r){let r=Z(t);t.gridCoord={x:r.x+n,y:r.y},mt(e.grid,t.gridCoord,3)}}function Er(e){if(e.config.graphDirection!==`TD`||!e.edges.every(e=>{let t=e.from.gridCoord,n=e.to.gridCoord;return t!==null&&n!==null&&t.y<n.y}))return;let t=e.nodes.filter(e=>e.gridCoord!==null).sort((e,t)=>Z(t).y-Z(e).y);for(let n of t){let t=Z(n);if(nr(e,n))continue;let r=Ir(e,n);if(r.length<1)continue;let i=!0;for(let a of r){let r=a.gridCoord;if(r===null||r.y!==t.y+4||nr(e,a)||e.edges.some(e=>e.to===a&&e.from!==n)){i=!1;break}}if(!i)continue;let a=r.map(e=>Z(e).x),o=(Math.min(...a)+Math.max(...a))/2;if(o%4!=0){if(o+2<=t.x)continue;if(Sr(e,n)){wr(e,n,{x:o,y:t.y});continue}let i=new Set([n]),a=[...r];for(let t=a.pop();t;t=a.pop())i.has(t)||(i.add(t),a.push(...Ir(e,t)));for(let t of e.edges)t.to===n&&i.add(t.from);if(e.nodes.some(e=>e.gridCoord!==null&&e.gridCoord.x>o&&!i.has(e)))continue;Tr(e,o,4),o+=2}o>t.x&&wr(e,n,{x:o,y:t.y})}}function Dr(e,t){let n=!1,r=new Set,i=new Set,a=!0;for(;a;){a=!1;let o=!1,s=t=>e.config.graphDirection===`LR`?t.gridCoord?.y??0:t.gridCoord?.x??0,c=e.nodes.filter(e=>e.gridCoord!==null).sort((e,t)=>s(e)-s(t));for(let s of c){let c=s.gridCoord;if(c===null)continue;let l=[...Ir(e,s)].sort((t,n)=>Fr(e,t,n));for(let u of l){if(u.gridCoord!==null)continue;let l=kr(e,u);if(!n&&l.some(e=>e.gridCoord===null)){if(o=!0,!r.has(u)){r.add(u);let n=e.config.graphDirection===`LR`?c.x+4:c.y+4;t[n]=(t[n]??0)+4}continue}let d=rr(e,s),f=rr(e,u),p=d&&d===f&&d.direction?d.direction:e.config.graphDirection,m=p===`LR`?c.x+4:c.y+4;if(p===e.config.graphDirection)for(let e of l){let t=e.gridCoord;t&&(m=Math.max(m,p===`LR`?t.x+4:t.y+4))}let h;if(p!==e.config.graphDirection)h=p===`LR`?c.y:c.x;else{let n=Or(e,u,m);h=Math.max(t[m]??0,n??0,i.has(s)?p===`LR`?c.y:c.x:0),n!==void 0&&h===n&&i.add(u)}let g=p===`LR`?{x:m,y:h}:{x:h,y:m};Zn(e,e.nodes[u.index],g,p),p===e.config.graphDirection&&(t[m]=h+4),a=!0}}!a&&o&&!n&&(n=!0,a=!0)}}function Or(e,t,n){let r=e.config.graphDirection===`LR`,i=new Set,a=!1;for(let o of e.edges){if(o.to!==t||o.from===t)continue;let e=o.from.gridCoord;!e||(r?e.x:e.y)>=n||(i.add(r?e.y:e.x),o.clusterTarget&&(a=!0))}if(i.size<2||!a)return;let o=Math.min(...i),s=Math.max(...i);return Math.floor((o+s)/2)}function kr(e,t){let n=[];for(let r of e.edges)r.to!==t||!r.clusterTarget||r.from===t||n.includes(r.from)||or(r.clusterTarget).includes(r.from)||n.push(r.from);return n}function Ar(e,t,n,r){let i=new Set(e.edges.filter(e=>e.to===t&&e.from!==t).map(e=>e.from));if(i.size!==1)return;let[a]=[...i],o=a.gridCoord;if(!(!o||nr(e,a))&&!e.edges.some(e=>e.to===a||e.from===a&&e.to!==t)&&!(r?o.y===n.y:o.x===n.x)){for(let t=0;t<3;t++)for(let n=0;n<3;n++)e.grid.delete(X({x:o.x+t,y:o.y+n}));Zn(e,a,r?{x:o.x,y:n.y}:{x:n.x,y:o.y})}}function jr(e){let t=e.config.graphDirection===`LR`;for(let n=0;n<e.nodes.length+1;n++){let n=!1;for(let r of e.subgraphs){let i=or(r),a=pr(r);if(a)for(let r of e.nodes){let o=r.gridCoord;if(!(!o||i.includes(r))&&!(o.x+2<a.minX||o.x>a.maxX||o.y+2<a.minY||o.y>a.maxY)){for(let t=0;t<3;t++)for(let n=0;n<3;n++)e.grid.delete(X({x:o.x+t,y:o.y+n}));Ar(e,r,Zn(e,r,t?{x:o.x,y:a.maxY+2}:{x:a.maxX+2,y:o.y}),t),n=!0}}}if(!n)return}}function Mr(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=vr(e,e.nodes.filter(e=>!r.has(e.name))),a=new Set(i),o=[],s=[];for(let t of i){let n=ar(e,t);n!==null&&or(n).some(n=>n!==t&&!a.has(n)&&!sr(e,t,n))?o.push(t):s.push(t)}let c=_r(e,s),l=new Map;for(let t of o){let n=ar(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)nr(e,t)?Ir(e,t).length>0&&(f=!0):d=!0;let p=t===`LR`&&d&&f,m,h=[];p?(m=c.filter(t=>!nr(e,t)),h=c.filter(t=>nr(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};Zn(e,e.nodes[r.index],i),n[0]=(n[0]??0)+4,xr(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};Zn(e,e.nodes[r.index],i),n[4]=(n[4]??0)+4,xr(e,r,l,u)}Dr(e,n);for(let t of o){if(u.has(t))continue;let r=ar(e,t),i=cr(e,t),a=or(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=br(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;Zn(e,e.nodes[t.index],o,i)}Dr(e,n),Er(e),jr(e);for(let t of e.nodes)Qn(e,t);e.pathBudget=Ct(),qr(e),zt(e),e.bundles=At(e),Pt(e);let g=hn(),_=vn(),v=ut(e.grid),y=new Set;for(let t of e.edges){if(t.bundle&&t.path.length>0){$n(e,t.path),_n(v,g,t.path,t.style),Cn(v,_,t.path,t),$r(e,t);continue}let{added:n,engaged:r}=sn(e,t);r&&y.add(t);let i=e.preferStraightRoutes;r&&(e.preferStraightRoutes=!0),Xr(e,t),tr(e,t,g,_,v),e.preferStraightRoutes=i,cn(e,n),$n(e,t.path),_n(v,g,t.path,t.style),Cn(v,_,t.path,t),$r(e,t)}for(let t of e.nodes)t.drawingCoord=$(e,Z(t)),t.drawing=Yi(t,e);if(hr(e),mr(e),Kt(e)){for(let t of e.nodes)t.drawingCoord=$(e,Z(t));hr(e)}let b=()=>{for(let t of e.nodes)t.drawingCoord=$(e,Z(t));hr(e)};ln(e,y,b),fn(e,()=>{b(),ln(e,y,b)}),mr(e),ln(e,y,b),gr(e),Ee(e.canvas,e.columnWidth,e.rowHeight,e.offsetX,e.offsetY),H(e.roleCanvas,e.columnWidth,e.rowHeight,e.offsetX,e.offsetY)}function Nr(e,t){return e.edges.filter(e=>e.from.name===t.name)}function Pr(e,t){let n=rr(e,t),r=[],i=n;for(;i!==null;)r.unshift(i),i=i.parent;return r}function Fr(e,t,n){let r=Pr(e,t),i=Pr(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 Ir(e,t){return Nr(e,t).map(e=>e.to)}function Lr(e){return e===G?K:e===K?G:e===q?J:e===J?q:e===Xe?$e:e===Ze?Qe:e===Qe?Ze:e===$e?Xe:et}function Rr(e,t){return e.x===t.x?e.y<t.y?K:G:e.y===t.y?e.x<t.x?J:q:e.x<t.x?e.y<t.y?Qe:Xe:e.y<t.y?$e:Ze}function zr(e){return e===`LR`?[J,K,K,J]:[K,J,J,K]}function Br(e,t){if(e.from===e.to)return zr(t);let n=Rr(Z(e.from),Z(e.to)),r,i,a,o,s=t===`LR`?Y(n,q)||Y(n,Ze)||Y(n,$e):Y(n,G)||Y(n,Ze)||Y(n,Xe);return Y(n,Qe)?t===`LR`?(r=K,i=q,a=J,o=G):(r=J,i=G,a=K,o=q):Y(n,Xe)?t===`LR`?(r=G,i=q,a=J,o=K):(r=J,i=K,a=G,o=q):Y(n,$e)?t===`LR`?(r=K,i=K,a=q,o=G):(r=q,i=G,a=K,o=J):Y(n,Ze)?t===`LR`?(r=K,i=K,a=q,o=K):(r=J,i=J,a=G,o=J):s?t===`LR`&&Y(n,q)?(r=K,i=K,a=q,o=J):t===`TD`&&Y(n,G)?(r=J,i=J,a=G,o=K):(r=n,i=Lr(n),a=n,o=Lr(n)):(r=n,i=Lr(n),a=n,o=Lr(n)),[r,i,a,o]}var Vr=2,Hr=200;function Ur(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 Wr(e,t,n=[]){for(let r=1;r<t.length-1;r++){let i=t[r];if(dt(e.grid,i)&&!n.some(e=>Ur(e,i)))return!1}return!0}function Gr(e){let t=e.from.gridCoord,n=e.to.gridCoord;return!t||!n?!1:t.y===n.y&&t.x!==n.x}function Kr(e){let t=e.from.name,n=e.to.name;return Gr(e)&&n<t?JSON.stringify([n,t]):JSON.stringify([t,n])}function qr(e){let t=new Map;for(let n of e.edges){if(n.from===n.to)continue;let e=Kr(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 Jr(e,t,n,r,i){let a=ot(Z(t.from),n),o=ot(Z(t.to),r),s=Y(n,q)||Y(n,J),c=[t.from,t.to],l=t.parallelLane.usedOffsets,u=Y(n,J)?1:Y(n,q)?-1:Y(n,K)?1:-1,d=Y(r,J)?1:Y(r,q)?-1:Y(r,K)?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=Vr*i;for(let n=0;n<Hr;n++){let r=g+n;if(l.has(r))continue;let i=a.y+r,u=a.x+r;{let n=s?K:J,i=ot(Z(t.from),n),a=ot(Z(t.to),n),o=s?[{x:i.x,y:Math.max(i.y,a.y)+r-1},{x:a.x,y:Math.max(i.y,a.y)+r-1}]:[{x:Math.max(i.x,a.x)+r-1,y:i.y},{x:Math.max(i.x,a.x)+r-1,y:a.y}],u=Tt([i,...o,a]);if(Wr(e,gt(u),c))return l.add(r),{path:u,labelSegment:o,faces:{startDir:n,endDir:n}}}let d=s?[{x:a.x,y:i},{x:o.x,y:i}]:[{x:u,y:a.y},{x:u,y:o.y}],_=Tt([a,d[0],s?{x:p.x,y:i}:{x:u,y:p.y},p,o]);if(Wr(e,gt(_),c))return l.add(r),{path:_,labelSegment:d};m=_,h=d;let v=s?f.x!==p.x:f.y!==p.y,y=s?v?[{x:f.x,y:i},{x:p.x,y:i}]:[{x:f.x,y:i},{x:f.x,y:i}]:v?[{x:u,y:f.y},{x:u,y:p.y}]:[{x:u,y:f.y},{x:u,y:f.y}],b=Tt(s?[a,f,{x:f.x,y:i},{x:p.x,y:i},p,o]:[a,f,{x:u,y:f.y},{x:u,y:p.y},p,o]);if(Wr(e,gt(b),c))return l.add(r),{path:b,labelSegment:y};m=b,h=y}return{path:m,labelSegment:h}}function Yr(e,t,n){let r=e.config.graphDirection===`LR`?J:K,i=ot(Z(t.anchor),r),a=Wt(e,t,n);return a?{path:[i,...a.path],startDir:r,endDir:a.endDir,labelSegment:a.labelSegment}:null}function Xr(e,t){let n=rr(e,t.from),r=rr(e,t.to),[i,a,o,s]=Br(t,n&&n===r&&n.direction?n.direction:e.config.graphDirection),c=t.clusterSource?e.clusterExitPlans?.get(t.clusterSource):void 0;if(c?.edges.has(t)){let n=t.parallelLane&&t.parallelLane.index>0?Yr(e,c,t):It(e,c,t);if(n){t.startDir=n.startDir,t.endDir=n.endDir,t.path=n.path,t.text.length>0&&ti(e,t,n.labelSegment,N(t.text));return}c.edges.delete(t),t.labelLine=[]}if(t.clusterTarget){let n=Lt(e,t);if(n){t.startDir=n.startDir,t.endDir=n.endDir,t.path=n.path,t.clusterEntered=!0;let r=n.path[n.path.length-1];if(t.text.length>0&&e.config.graphDirection===`LR`){let n=e.columnWidth.get(r.x)??0;e.columnWidth.set(r.x,Math.max(n,N(t.text)+5))}return}t.clusterEntered=!1}if(t.parallelLane&&t.parallelLane.index>0){let n=Y(i,a),r=n?o:i,c=n?s:a;t.startDir=r,t.endDir=c;let l=Jr(e,t,r,c,t.parallelLane.index);t.path=l.path,l.faces&&(t.startDir=l.faces.startDir,t.endDir=l.faces.endDir),t.text.length>0&&ti(e,t,l.labelSegment,N(t.text));return}let l=ot(Z(t.from),i),u=ot(Z(t.to),a),d=kt(e,l,u,nt(i)),f=kt(e,ot(Z(t.from),o),ot(Z(t.to),s),nt(o));if(d!==null&&f!==null){d.length<=f.length?(t.startDir=i,t.endDir=a,t.path=d):(t.startDir=o,t.endDir=s,t.path=f);return}if(d!==null){t.startDir=i,t.endDir=a,t.path=d;return}if(f!==null){t.startDir=o,t.endDir=s,t.path=f;return}t.startDir=i,t.endDir=a,t.path=ei([l,u])}function Zr(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 Qr(e,t,n,r){if(!Zr(e,r))return r;for(let i=1;i<=n-t;i++){let a=r+i;if(a<=n&&!Zr(e,a))return a;let o=r-i;if(o>=t&&!Zr(e,o))return o}return r}function $r(e,t){if(t.text.length===0||t.parallelLane&&t.parallelLane.index>0||t.clusterSource&&e.clusterExitPlans?.get(t.clusterSource)?.edges.has(t))return;let n=N(t.text),r=ei(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=ri(e,o),c=n.x===i.x;a.push({line:o,width:s,index:t,isVertical:c})}let o=t=>Wr(e,gt(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]}}}ti(e,t,l,n)}function ei(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 ti(e,t,n,r){let i=Math.min(n[0].x,n[1].x),a=Math.max(n[0].x,n[1].x),o=Qr(e,i,a,i+Math.floor((a-i)/2)),s=e.columnWidth.get(o)??0;e.columnWidth.set(o,Math.max(s,r+2,ni(e,t,r))),t.labelLine=[n[0],n[1]]}function ni(e,t,n){let r=t.from.gridCoord,i=t.to.gridCoord;if(!r||!i||r.x!==i.x||r.y===i.y)return 0;let a=e.edges.find(e=>e!==t&&e.from===t.to&&e.to===t.from);return a?2*(Math.max(n,N(a.text))+2):0}function ri(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 ii={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 ai(e,t,n,r,i,a,o=`solid`){let s=Rr(t,n),c=[],l=ii[o],u=a?l.h.ascii:l.h.unicode,d=a?l.v.ascii:l.v.unicode;if(Y(s,G))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(Y(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(Y(s,q))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(Y(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(Y(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(Y(s,Xe)){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(Y(s,$e)){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(Y(s,Qe)){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 oi(e,t){if(t.path.length===0){let t=F(e.canvas);return[t,t,t,t,t,t]}let n=Ii(e,t),r=ci(e,t),i=r?mi(e,t,r):void 0,[a,o,s]=hi(e,t.path,t.style,r,i,Ti(e,t)),c=o.length>0,l=t.style===`invisible`,u=c&&!l?vi(e,t.path,o[0],t.from):F(e.canvas),d;d=t.hasArrowEnd&&c?Si(e,o[o.length-1],s[s.length-1],t.endMarker):F(e.canvas);let f;if(t.hasArrowStart&&c){let n=o[0][0],r=si(s[0]),i={x:n.x,y:n.y};Y(s[0],J)?i.x=n.x-1:Y(s[0],q)?i.x=n.x+1:Y(s[0],K)?i.y=n.y-1:Y(s[0],G)&&(i.y=n.y+1),f=Si(e,[n,i],r,t.startMarker)}else f=F(e.canvas);let p=l?F(e.canvas):Ci(e,t.path,i);return[a,u,d,f,p,n]}function si(e){return Y(e,G)?K:Y(e,K)?G:Y(e,q)?J:Y(e,J)?q:Y(e,Ze)?Qe:Y(e,Xe)?$e:Y(e,$e)?Xe:Y(e,Qe)?Ze:et}function ci(e,t){let n=li(e,t),r=t.clusterTarget;if(!n||!r)return n;let i=ui(e,r).get(t);return i===void 0?n:e.config.graphDirection===`LR`?{x:n.x,y:i}:{x:i,y:n.y}}function li(e,t){let n=t.clusterTarget,r=t.path[t.path.length-1],i=t.path[t.path.length-2];if(!t.clusterEntered||!n||!r||!i)return;let a=$(e,i),o=$(e,r);return e.config.graphDirection===`LR`?n.minX>a.x?{x:n.minX,y:o.y}:void 0:n.minY>a.y?{x:o.x,y:n.minY}:void 0}function ui(e,t){let n=e.config.graphDirection===`LR`,r=[];for(let i of e.edges){if(i.clusterTarget!==t)continue;let a=li(e,i),o=i.path[0];if(!a||!o)continue;let s=$(e,o);r.push({edge:i,at:n?a.y:a.x,from:n?s.y:s.x})}let i=new Map;if(r.length<2)return i;r.sort((e,t)=>e.from-t.from);let a=r.map(e=>e.at);if(a.every((e,t)=>t===0||e-a[t-1]>=2))return i;let o=n?t.minY+1:t.minX+1,s=n?t.maxY-1:t.maxX-1,c=pi(a,o,s,di)??pi(a,o,s,fi);if(!c)return i;let l=e=>(e[0]+e[e.length-1])/2,u=Math.round(l(r.map(e=>e.from))-l(c)),d=Math.max(o-c[0],Math.min(s-c.at(-1),u));return r.forEach((e,t)=>i.set(e.edge,c[t]+d)),i}var di=3,fi=2;function pi(e,t,n,r){let i=[...e];for(let e=0;e<i.length;e++)i[e]=Math.max(i[e],e===0?t:i[e-1]+r);for(let e=i.length-1;e>=0;e--)i[e]=Math.min(i[e],e===i.length-1?n:i[e+1]-r);return i[0]<t?void 0:i}function mi(e,t,n){let r=t.path[t.path.length-1];if(!r||t.path.length<2)return;let i=e.config.graphDirection===`LR`,a=$(e,r),o=$(e,t.path[0]),s=i?Math.min(a.x,n.x-2):Math.min(a.y,n.y-2);if(s<=(i?o.x:o.y))return;let c=i?r.x:r.y,l=t.path.findIndex(e=>(i?e.x:e.y)===c);if(l<1)return;let u=$(e,t.path[l]),d=i?n.y:n.x;if((i?u.y:u.x)===d)return;let f=t.path.slice(0,l).map(t=>$(e,t)),p=i?{x:s,y:u.y}:{x:u.x,y:s},m=i?{x:s,y:d}:{x:d,y:s};return f.push(p,m,n),{points:f,jog:[p,m]}}function hi(e,t,n=`solid`,r,i,a=0){let o=F(e.canvas),s=t[0],c=[],l=[],u=e=>a===0?e:{x:e.x+a,y:e.y};if(i){for(let t=1;t<i.points.length;t++){let r=i.points[t-1],a=i.points[t];if(at(r,a))continue;let s=ai(o,r,a,1,-1,e.config.useAscii,n);s.length===0&&s.push(r),c.push(s),l.push(Rr(r,a))}return[o,c,l]}for(let i=1;i<t.length;i++){let a=t[i],d=u($(e,s)),f=r&&i===t.length-1?u(r):u($(e,a));if(at(d,f)){s=a;continue}let p=Rr(s,a),m=ai(o,d,f,1,-1,e.config.useAscii,n);m.length===0&&m.push(d),c.push(m),l.push(p),s=a}return[o,c,l]}var gi=new Set([`│`,`┃`,`║`,`┆`,`┊`,`|`,`‖`]),_i=new Set([`─`,`━`,`═`,`╌`,`┄`,`-`,`=`]);function vi(e,t,n,r){let i=F(e.canvas),a=e.config.useAscii;if(r.shape===`state-start`||r.shape===`state-end`)return i;let o=n[0],s=Rr(t[0],t[1]),c=a?`+`:null,l=(t,n)=>e.canvas[t]?.[n];if(Y(s,G)){let e=o.x,t=o.y+1,n=l(e,t);R(i,e,t,n!==void 0&&_i.has(n)?c??`┴`:a?`|`:`│`)}else if(Y(s,K)){let e=o.x,t=o.y-1,n=l(e,t);R(i,e,t,n!==void 0&&_i.has(n)?c??`┬`:a?`|`:`│`)}else if(Y(s,q)||Y(s,J)){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=Y(s,q)?e.x:e.x+n-1,d=o.y,f=l(u,d);R(i,u,d,f!==void 0&&gi.has(f)?c??(Y(s,q)?`┤`:`├`):a?`-`:`─`)}return i}function yi(e,t){if(t===`circle`)return e?`o`:`○`;if(t===`cross`)return e?`x`:`✕`}function bi(e){if(Y(e,G))return`▲`;if(Y(e,K))return`▼`;if(Y(e,q))return`◄`;if(Y(e,J))return`►`;if(Y(e,Xe))return`↗`;if(Y(e,Ze))return`↖`;if(Y(e,Qe))return`↘`;if(Y(e,$e))return`↙`}function xi(e){if(Y(e,G))return`^`;if(Y(e,K))return`v`;if(Y(e,q))return`<`;if(Y(e,J))return`>`}function Si(e,t,n,r){let i=F(e.canvas);if(t.length===0)return i;let a=t[t.length-1],o=Rr(t.length>=2?t[t.length-2]:t[0],a);(t.length===1||Y(o,et))&&(o=n);let s=yi(e.config.useAscii,r),c;if(s!==void 0)c=s;else if(e.config.useAscii){let e=xi(o);c=e===void 0?xi(n)??`*`:e}else{let e=bi(o);c=e===void 0?bi(n)??`●`:e}return R(i,a.x,a.y,c),i}function Ci(e,t,n){let r=F(e.canvas),i=n?n.points:t;for(let a=1;a<i.length-1;a++){let o=i[a],s=n?n.points[a]:$(e,t[a]),c=Rr(i[a-1],o),l=Rr(o,i[a+1]),u;u=e.config.useAscii?`+`:Y(c,l)?Y(c,G)||Y(c,K)?`│`:`─`:Y(c,J)&&Y(l,K)||Y(c,G)&&Y(l,q)?`┐`:Y(c,J)&&Y(l,G)||Y(c,K)&&Y(l,q)?`┘`:Y(c,q)&&Y(l,K)||Y(c,G)&&Y(l,J)?`┌`:Y(c,q)&&Y(l,G)||Y(c,K)&&Y(l,J)?`└`:`+`,R(r,s.x,s.y,u)}return r}function wi(e,t){return e.edges.some(e=>e!==t&&e.from===t.to&&e.to===t.from)}function Ti(e,t){let n=Ei(e,t);if(!n)return 0;for(let r of[t,n]){if(r.text.length===0)continue;let t=r.path[1].y>r.path[0].y?`right`:`left`;if(!ji(e,r,Ai(Oi(e,r),$(e,r.path[0]).x+(t===`right`?1:-1),t)))return 0}return t.path[1].y>t.path[0].y?1:-1}function Ei(e,t){if(t.from===t.to||t.path.length!==2)return;let n=e.edges.find(e=>e!==t&&e.from===t.to&&e.to===t.from);if(!n||n.path.length!==2||ki(e,t)||ki(e,n))return;let[r,i]=t.path,[a,o]=n.path;if(r.x===i.x&&a.x===o.x&&r.x===a.x&&r.y!==i.y&&i.y>r.y!=o.y>a.y){for(let e of[t.from,t.to])if(!e.drawing||e.drawing.length<5)return;return n}}function Di(e,t){if(t.text.length===0)return null;let n=Oi(e,t),r=Ti(e,t);return r===0?n:Ai(n,$(e,t.path[0]).x+r,r>0?`right`:`left`)}function Oi(e,t){let n=Mi(e,t,Xn(e,t.labelLine)),r;if(t.path.length>=2){let e=t.path[0].y,n=t.path[t.path.length-1].y;n<e?r=!0:n>e&&(r=!1)}let i=wi(e,t)||e.config.graphDirection!==`LR`&&t.clusterSource!==void 0&&e.clusterExitPlans?.get(t.clusterSource)?.edges.has(t)===!0,a=Pi(e,t,Ni(e,Fi(e,Li(n,t.text,r,i),n[0]?.x===n[1]?.x?n[0]?.x:void 0),n));if(r!==void 0&&n.length>=2&&n[0].x===n[1].x&&!ki(e,t)){let i=Ai(a,n[0].x,r?`left`:`right`);if(ji(e,t,i))return i}return a}function ki(e,t){return t.clusterSource!==void 0&&e.clusterExitPlans?.get(t.clusterSource)?.edges.has(t)===!0}function Ai(e,t,n){return e.map(e=>({...e,x:n===`right`?t+2:t-1-N(e.text)}))}function ji(e,t,n){for(let{x:r,y:i,text:a}of n){let n=r,o=r+N(a)-1;if(n<0)return!1;for(let t of e.nodes){if(!t.drawingCoord||!t.drawing)continue;let e=t.drawingCoord.x,r=t.drawingCoord.y;if(o>=e&&n<e+t.drawing.length&&i>=r&&i<r+(t.drawing[0]?.length??0))return!1}for(let t of e.subgraphs){if(t.nodes.length===0)continue;let e=Q(t.name).length,r=i>=t.minY&&i<=t.maxY,a=[t.minX,t.maxX].some(e=>e>=n&&e<=o);if(r&&a||(i===t.maxY||i>=t.minY&&i<=t.minY+e)&&o>=t.minX&&n<=t.maxX)return!1}for(let r of e.edges){if(r===t)continue;let a=Xn(e,r.path);for(let e=1;e<a.length;e++){let t=a[e-1],r=a[e];if(i>=Math.min(t.y,r.y)&&i<=Math.max(t.y,r.y)&&o>=Math.min(t.x,r.x)&&n<=Math.max(t.x,r.x))return!1}}}return!0}function Mi(e,t,n){let r=ci(e,t),i=r?mi(e,t,r):void 0,a=t.path[t.path.length-1];if(!i||!a||n.length<2)return n;let o=$(e,a),s=e.config.graphDirection===`LR`;return n.every(e=>s?e.x===o.x:e.y===o.y)?i.jog:n}function Ni(e,t,n){if(n.length<2||e.subgraphs.length===0)return t;let r=Math.min(n[0].y,n[1].y),i=Math.max(n[0].y,n[1].y),a=(t,n)=>e.subgraphs.some(e=>{if(e.nodes.length===0)return!1;let r=Q(e.name).length;return n>=e.minY&&n<=e.minY+r&&t.x<=e.maxX&&t.x+N(t.text)-1>=e.minX});return t.map(e=>{if(!a(e,e.y))return e;let t=null;for(let n=r+1;n<i;n++)a(e,n)||(t===null||Math.abs(n-e.y)<Math.abs(t-e.y))&&(t=n);return t===null?e:{...e,y:t}})}function Pi(e,t,n){let r=t.clusterSource?e.clusterExitPlans?.get(t.clusterSource):void 0;if(e.config.graphDirection!==`LR`||!r?.edges.has(t)||!t.parallelLane||t.parallelLane.index===0)return n;let i=$(e,r.gutter).x+2;return n.map(e=>e.x<i?{...e,x:i}:e)}function Fi(e,t,n){return n===void 0?t:t.map(t=>{let r=N(t.text),{x:i}=t;for(let a of e.subgraphs)if(!(t.y<=a.minY||t.y>=a.maxY))for(let e of[a.minX,a.maxX])e<i||e>=i+r||n===e||(i=n>e?e+1:e-r);return i===t.x?t:{...t,x:i}})}function Ii(e,t){let n=F(e.canvas);for(let{x:r,y:i,text:a}of Di(e,t)??[])Te(n,{x:r,y:i},a);return n}function Li(e,t,n,r=!1){if(e.length<2)return[];let i=Math.min(e[0].x,e[1].x),a=Math.max(e[0].x,e[1].x),o=Math.min(e[0].y,e[1].y),s=Math.max(e[0].y,e[1].y),c=i+Math.floor((a-i)/2),l=o+Math.floor((s-o)/2);if(n!==void 0&&i===a){let e=s-o,t=Math.max(1,Math.floor(e/4));(r?n:!n)?l-=t:l+=t}let u=Q(t),d=l-Math.floor((u.length-1)/2);return u.map((e,t)=>({x:c-Math.floor(N(e)/2),y:d+t,text:e}))}function Ri(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 Yn(t.shape,n,o,s)}function zi(e,t,n){let r=F(e.canvas),i=t.pathToJunction;if(!i||i.length===0)return[r,r,r,r,r,r];let a=F(e.canvas),o=e.config.useAscii,s=i.map((r,a)=>n.type===`fan-in`&&a===0?Ri(e,t.from,t.startDir):n.type===`fan-out`&&a===i.length-1?Ri(e,t.to,t.endDir):$(e,r));for(let e=1;e<s.length;e++){let n=s[e-1],r=s[e];at(n,r)||ai(a,n,r,1,-1,o,t.style)}let c=F(e.canvas);for(let t=1;t<i.length-1;t++){let n=i[t],r=$(e,n),a=Rr(i[t-1],n),s=Rr(n,i[t+1]),l;l=o?`+`:Y(a,J)&&Y(s,K)||Y(a,G)&&Y(s,q)?`┐`:Y(a,J)&&Y(s,G)||Y(a,K)&&Y(s,q)?`┘`:Y(a,q)&&Y(s,K)||Y(a,G)&&Y(s,J)?`┌`:Y(a,q)&&Y(s,G)||Y(a,K)&&Y(s,J)?`└`:`+`,R(c,r.x,r.y,l)}let l=F(e.canvas);if(n.type===`fan-in`&&i.length>=2){let e=s[0],t=Rr(i[0],i[1]),n=o?`+`:null;Y(t,G)?R(l,e.x,e.y,n??`┴`):Y(t,K)?R(l,e.x,e.y,n??`┬`):Y(t,q)?R(l,e.x,e.y,n??`┤`):Y(t,J)&&R(l,e.x,e.y,n??`├`)}return[a,l,r,r,c,F(e.canvas)]}function Bi(e,t){let n=F(e.canvas),r=F(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`?G:q;return Ri(e,t.sharedNode,n)}if(t.type===`fan-out`&&r===0){let n=o===`TD`?K:J;return Ri(e,t.sharedNode,n)}return $(e,n)});for(let e=1;e<s.length;e++){let t=s[e-1],r=s[e];at(t,r)||ai(n,t,r,1,-1,i,a)}for(let n=1;n<t.sharedPath.length-1;n++){let a=t.sharedPath[n],o=$(e,a),s=Rr(t.sharedPath[n-1],a),c=Rr(a,t.sharedPath[n+1]),l;l=i?`+`:Y(s,J)&&Y(c,K)||Y(s,G)&&Y(c,q)?`┐`:Y(s,J)&&Y(c,G)||Y(s,K)&&Y(c,q)?`┘`:Y(s,q)&&Y(c,K)||Y(s,G)&&Y(c,J)?`┌`:Y(s,q)&&Y(c,G)||Y(s,K)&&Y(c,J)?`└`:`+`,R(r,o.x,o.y,l)}return[n,r]}function Vi(e,t){let n=F(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=Rr(i,a),s=e.config.graphDirection,c=s===`TD`?G:q,l=Ri(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=yi(e.config.useAscii,d),p;return p=f===void 0?e.config.useAscii?Y(o,G)?`^`:Y(o,K)?`v`:Y(o,q)?`<`:Y(o,J)?`>`:`v`:Y(o,G)?`▲`:Y(o,K)?`▼`:Y(o,q)?`◄`:Y(o,J)?`►`:`▼`:f,R(n,l.x,l.y,p),n}function Hi(e,t){let n=F(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=Rr(i,a),s=e.config.graphDirection,c=s===`TD`?G:q,l=Ri(e,t.to,c);s===`TD`?--l.y:--l.x;let u=yi(e.config.useAscii,t.endMarker),d;return d=u===void 0?e.config.useAscii?Y(o,G)?`^`:Y(o,K)?`v`:Y(o,q)?`<`:Y(o,J)?`>`:`v`:Y(o,G)?`▲`:Y(o,K)?`▼`:Y(o,q)?`◄`:Y(o,J)?`►`:`▼`:u,R(n,l.x,l.y,d),n}function Ui(e){return Y(e,G)?K:Y(e,K)?G:Y(e,q)?J:Y(e,J)?q:e}function Wi(e,t){let n=F(e.canvas);if(t.sharedPath.length<2)return n;let r=t.sharedPath[0],i=t.sharedPath[1],a=Ui(Rr(r,i)),o=e.config.graphDirection,s=o===`TD`?K:J,c=Ri(e,t.sharedNode,s);o===`TD`?c.y+=1:c.x+=1;let l;return l=e.config.useAscii?Y(a,G)?`^`:Y(a,K)?`v`:Y(a,q)?`<`:Y(a,J)?`>`:`^`:Y(a,G)?`▲`:Y(a,K)?`▼`:Y(a,q)?`◄`:Y(a,J)?`►`:`▲`,R(n,c.x,c.y,l),n}function Gi(e,t){let n=F(e.canvas);if(!t.pathToJunction||t.pathToJunction.length<2)return n;let r=t.pathToJunction[0],i=t.pathToJunction[1],a=Ui(Rr(r,i)),o=Ri(e,t.from,t.startDir);Y(t.startDir,G)?--o.y:Y(t.startDir,K)?o.y+=1:Y(t.startDir,q)?--o.x:Y(t.startDir,J)&&(o.x+=1);let s;return s=e.config.useAscii?Y(a,G)?`^`:Y(a,K)?`v`:Y(a,q)?`<`:Y(a,J)?`>`:`v`:Y(a,G)?`▲`:Y(a,K)?`▼`:Y(a,q)?`◄`:Y(a,J)?`►`:`▼`,R(n,o.x,o.y,s),n}function Ki(e,t){let n=F(e.canvas);if(!t.junctionPoint)return n;let r=$(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=Rr(t.sharedPath[e],t.sharedPath[n]);Y(r,K)?o=!0:Y(r,G)?a=!0:Y(r,J)?c=!0:Y(r,q)&&(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=Rr(e.pathToJunction[r],e.pathToJunction[n]);Y(i,K)?a=!0:Y(i,G)?o=!0:Y(i,J)?s=!0:Y(i,q)&&(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 qi(e,t){return Ji(e,t)}function Ji(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=P(Math.max(o.x,s.x),Math.max(o.y,s.y)),l=Tn(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);e.labelRows={top:g,bottom:g+h.length-1};for(let e=0;e<h.length;e++){let t=h[e],n=N(t),r=o.x+Math.floor(i/2)-Math.ceil(n/2)+1,a=oe(t);for(let t=0;t<a.length;t++)R(c,r+t,g+e,a[t])}return c}function Yi(e,t){return qi(e,t)}function Xi(e){return/^[┌┐└┘├┤┬┴┼│─╭╮╰╯+\-|]$/.test(e)?`border`:`text`}function Zi(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,N(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 Qi(e,t,n=1){let r=Math.max(0,n),{width:i,height:a}=Zi(e,r),o=t?`-`:`─`,s=t?`|`:`│`,c=t?`+`:`┌`,l=t?`+`:`┐`,u=t?`+`:`└`,d=t?`+`:`┘`,f=t?`+`:`├`,p=t?`+`:`┤`,m=P(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=oe(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 $i(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 ea(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 ta(e,t,n,r){for(let i of t)ea(e,i,n,r)}function na(e){let t=null;for(let[n,r]of e.entries())for(let[e,i]of r.entries())i!==` `&&(t=t?{x0:Math.min(t.x0,n),x1:Math.max(t.x1,n),y0:Math.min(t.y0,e),y1:Math.max(t.y1,e)}:{x0:n,x1:n,y0:e,y1:e});return t}function ra(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 ia(e){let t=[];e.labelRects=t;let n=e.config.useAscii,r={x:0,y:0},i=$i(e.subgraphs);for(let t of i){let r=Zt(t,e),i={x:t.minX,y:t.minY};e.canvas=he(e.canvas,i,n,r),ea(e.roleCanvas,r,i,`border`)}for(let r of e.nodes)if(!r.drawn&&r.drawingCoord&&r.drawing){if(e.canvas=he(e.canvas,r.drawingCoord,n,r.drawing),ra(e.roleCanvas,r.drawing,r.drawingCoord),r.labelRows){let{x:n,y:i}=r.drawingCoord,a={x0:n+1,x1:n+r.drawing.length-2,y0:i+r.labelRows.top,y1:i+r.labelRows.bottom};t.push(a);for(let t=a.x0;t<=a.x1;t++)for(let n=a.y0;n<=a.y1;n++){let r=e.canvas[t]?.[n];r&&r!==` `&&I(e.roleCanvas,t,n,`text`)}}r.drawn=!0}let a=[],o=[],s=[],c=[],l=[],u=[],d=[],f=new Set;for(let t of e.edges)if(t.bundle&&t.pathToJunction){let n=t.bundle,[r,i,,,p,m]=zi(e,t,n);if(a.push(r),o.push(p),l.push(i),u.push(m),n.type===`fan-in`&&t.hasArrowStart){let n=Gi(e,t);c.push(n)}if(!f.has(n)){f.add(n);let[t,r]=Bi(e,n);if(a.push(t),o.push(r),n.type===`fan-in`){let t=Vi(e,n);s.push(t)}if(n.type===`fan-out`&&n.edges.every(e=>e.hasArrowStart)){let t=Wi(e,n);c.push(t)}let i=Ki(e,n);d.push(i)}if(n.type===`fan-out`&&t.hasArrowEnd){let n=Hi(e,t);s.push(n)}}else{let[n,r,i,d,f,p]=oi(e,t);a.push(n),o.push(f),s.push(i),c.push(d),l.push(r),u.push(p)}let p=me(a);e.canvas=he(e.canvas,r,n,...p),ta(e.roleCanvas,p,r,`line`),e.canvas=he(e.canvas,r,n,...o),ta(e.roleCanvas,o,r,`corner`),e.canvas=he(e.canvas,r,n,...d),ta(e.roleCanvas,d,r,`junction`),e.canvas=he(e.canvas,r,n,...s),ta(e.roleCanvas,s,r,`arrow`),e.canvas=he(e.canvas,r,n,...l),ta(e.roleCanvas,l,r,`junction`),e.canvas=he(e.canvas,r,n,...c),ta(e.roleCanvas,c,r,`arrow`),e.canvas=he(e.canvas,r,n,...u),ta(e.roleCanvas,u,r,`text`);for(let e of u){let n=na(e);n&&t.push(n)}for(let r of e.subgraphs){if(r.nodes.length===0)continue;let[i,a,o]=rn(r,e,(t,n)=>$t(e.canvas[t+r.minX]?.[n+r.minY])&&(e.canvas[t+r.minX]?.[n+r.minY+1]??` `)!==` `);e.canvas=he(e.canvas,a,n,i),ea(e.roleCanvas,i,a,`text`);let s=na(i);s&&t.push({x0:s.x0+a.x,x1:s.x1+a.x,y0:s.y0+a.y,y1:s.y1+a.y});for(let{x:t,y:n}of o){let r=i[t]?.[n];r===` `&&(R(e.canvas,t+a.x,n+a.y,r),I(e.roleCanvas,t+a.x,n+a.y,`text`))}}return e.canvas}function aa(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 oa(e){let t=e.keys.length>0?` `+e.keys.join(`,`):``;return`${e.type} ${e.name}${t}`}function sa(e){let t=Q(e.label),n=e.attributes.map(oa);return n.length===0?[t]:[t,n]}function ca(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 la(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 ua(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 da(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=rt(r.paddingX,5,6,6),u=rt(r.paddingY,5,4,2),d=rt(r.paddingY,5,2,1),f=Math.max(...[`one`,`zero-one`,`many`,`zero-many`].flatMap(e=>[ca(e,c,!1).length,ca(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=sa(e);p.set(e.id,t);let{width:n,height:i}=Zi(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=Yt(e.label);_.set(t,Math.max(_.get(t)??0,n))}let v=la(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=ua(m,o.id,`box width`),c=ua(h,o.id,`box height`);a>=n&&(b+=i+u,r=0,i=0,a=0),y.set(o.id,{entity:o,sections:ua(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=P(x-1,S-1),w=se(x-1,S-1);function ee(e,t,n,r){R(C,e,t,n,{role:r,roleCanvas:w})}function T(e,t){let n=w[e]?.[t];return n===`text`||n===`border`}function E(e,t,n,r,i){for(let a=0;a<e.length;a++){let e=t+a;if(!(e<r||e>i)&&T(e,n))return!1}return!0}function te(e,t,n,r,i,a){for(let a=0;a<e.length;a++){let e=t+a;if(!(e<r||e>i)&&(T(e,n)||w[e]?.[n]===`arrow`||D.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`&&!pe.has(`${a},${n}`))return!1;return!0}for(let e of y.values()){let t=Qi(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&&ee(t,a,i,Xi(i))}}}let D=new Set;for(let e of y.values())for(let t=0;t<e.height;t++)for(let n=0;n<e.width;n++)D.add(`${e.x+n},${e.y+t}`);function O(e,t,n,r){D.has(`${e},${t}`)||(r===`text`||w[e]?.[t]!==`text`)&&(I(n)!==`dashed`||I(C[e]?.[t])!==`solid`)&&(ee(e,t,n,r),r===`line`&&pe.add(`${e},${t}`))}function k(e,t,n,r){w[e-1]?.[t]!==`text`&&w[e+1]?.[t]!==`text`&&O(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 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){for(let r of A)if(!(Math.abs(r.x-e)>1)&&t<=r.yEnd&&n>=r.yStart)return!0;return!1}function j(e,t,n){A.push({x:e,yStart:t,yEnd:n})}let M=c?`-`:`─`,ae=c?`|`:`│`,N=c?`.`:`╌`,F=c?`:`:`┊`;function I(e){if(e===M||e===ae)return`solid`;if(e===N||e===F)return`dashed`}function L(e,t){return c?`+`:e===`down`?t===`right`?`┌`:`┐`:t===`right`?`└`:`┘`}function z(e,t,n,r){O(e,t,L(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 pe=new Set;for(let e of s.relationships){pe=new Set;let t=y.get(e.entity1),n=y.get(e.entity2);if(!t||!n)continue;let r=e.identifying?M:N,i=e.identifying?ae:F,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=ca(d,c,!1),S=ca(p,c,!0),ee=+(v>=3&&x[0]===ae),T=+(v>=3&&S[S.length-1]===ae),te=m+ee,D=h-T,A;if(_===void 0){for(let e=m;e<=h;e++)k(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++;le(C,h+1,a+n+1),ce(w,h+1,a+n+1);for(let e=g;e<=a;e++)O(m,e,i,`line`),O(h,e,i,`line`);for(let e=m;e<=h;e++)k(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++)O(te+e,g,x[e],`arrow`);for(let e=0;e<S.length;e++)O(D-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=oe(a),s=Math.max(r,n-Math.floor(o.length/2)),c=A+e;if(le(C,Math.max(s+o.length,1),Math.max(c+1,1)),ce(w,Math.max(s+o.length,1),Math.max(c+1,1)),E(o,s,c,r,i))for(let e=0;e<o.length;e++){let t=s+e;t>=r&&t<=i&&O(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(D.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 T=m!==h,E=Math.min(m,h),A=Math.max(m,h),M=T?he(E,A,0):p,ae=T?M-1:p,N=!me(m,x,S)||!me(h,x,S)||re(m,f,T?M:p)||T&&re(h,M,p),P=m;if(N){let e=C.length,t;for(let n=0;n<=e;n++){let e=m+n;if(me(e,f,p)&&!ie(e,f,p)){t=e;break}let r=m-n;if(n>0&&me(r,f,p)&&!ie(r,f,p)){t=r;break}}P=t??m;for(let e=f;e<=g;e++)O(m,e,i,`line`);for(let e=Math.min(m,P);e<=Math.max(m,P);e++)k(e,g,r,`line`);for(let e=g;e<=_;e++)O(P,e,i,`line`);for(let e=Math.min(P,h);e<=Math.max(P,h);e++)k(e,_,r,`line`);for(let e=_;e<=p;e++)O(h,e,i,`line`);if(m!==P){let e=P>m?`right`:`left`,t=e===`right`?`left`:`right`;z(m,g,`up`,e),z(P,g,`down`,t)}if(P!==h){let e=h>P?`right`:`left`,t=e===`right`?`left`:`right`;z(P,_,`up`,e),z(h,_,`down`,t)}j(P,g,_)}else{for(let e=f;e<=ae;e++)O(m,e,i,`line`);if(j(m,f,T?M:ae),T){for(let e=E;e<=A;e++)k(e,M,r,`line`);for(let e=M+1;e<=p;e++)O(h,e,i,`line`);j(h,M,p);let e=h>m?`right`:`left`,t=e===`right`?`left`:`right`;z(m,M,`up`,e),z(h,M,`down`,t),P=h}}let F=ca(u,c,!1,!0);for(let e=0;e<F.length;e++)O(m-Math.floor(F.length/2)+e,g,F[e],`arrow`);let se=m===h?m:h,I=ca(d,c,!0,!0);for(let e=0;e<I.length;e++)O(se-Math.floor(I.length/2)+e,_,I[e],`arrow`);if(e.label){let t=Q(e.label),n=Math.max(F.length-1-Math.floor(F.length/2),I.length-1-Math.floor(I.length/2)),r=P+n+2,i=t.map(e=>oe(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&&(le(C,a+1,p+1),ce(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)=>te(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&&O(i,n,t[e],`text`)}w[r-1]?.[n]===`line`&&ee(r-1,n,` `,`line`);let a=r+t.length;w[a]?.[n]===`line`&&ee(a,n,` `,`line`)}}}}return ge(C,{roleCanvas:w,colorMode:i,theme:a})}var fa=4,pa=[`O`,`/|\\`,`/ \\`],ma=3,ha=4;function ga(e){return e.seqNumber===void 0?fa:fa+String(e.seqNumber).length}function _a(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=Yt(e.label?`${e.type} [${e.label}]`:e.type);for(let n of e.dividers)n.label&&(t=Math.max(t,Yt(`[${n.label}]`)));return t}let C=Math.max(0,r.boxBorderPadding),w=e=>Math.max(Yt(e.label),e.type===`actor`?ma:0),ee=e=>Xt(e.label)+(e.type===`actor`?pa.length:0),T=s.actors.map(e=>w(e)+2*C+2),E=T.map(e=>Math.ceil(e/2)),te=s.actors.map(e=>ee(e)+2),D=Math.max(...te,3),O=(e,t)=>t-Math.floor(T[e]/2),k=Math.floor((D-1)/2),ne=D-1-k,A=new Map,re=new Map;s.actors.forEach((e,t)=>{e.createdAt!==void 0&&A.set(e.createdAt,t),e.destroyedAt!==void 0&&re.set(e.destroyedAt,t)});let ie=new Map,j=new Map,M=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)}}),ae=M.length>0,F=s.actors.map((e,t)=>M.findIndex(e=>e.lo<=t&&t<=e.hi)),I=+!!ae,z=e=>e===``?0:Yt(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=Yt(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=>N(e)))+2+2*C}let fe=Array(s.actors.length).fill(0),pe=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):pe[t]=Math.max(pe[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 B=rt(r.paddingX,5,10,4),V=[Math.max(E[0]+(F[0]===-1?0:2),fe[0]+1,me[0])];for(let e=1;e<s.actors.length;e++){let t=F[e-1],n=F[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],me[e])+2,o=Math.max(E[e-1]+E[e]+2+i,ue[e-1]+2,a,B);V[e]=V[e-1]+o}let _e=e=>O(e.lo,V[e.lo])-1-1,ve=e=>Math.max(O(e.hi,V[e.hi])+T[e.hi]-1+1+1,_e(e)+z(e.label)-1);for(let e of M){if(e.hi+1>=s.actors.length)continue;let t=O(e.hi+1,V[e.hi+1]),n=F[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]+fa+2+Yt(e.label);i=Math.max(i,t)}}if(n===-1||n+1>=s.actors.length)continue;let a=Math.max(0,r-ha),o=i+ha,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=I,Ee=Te+D,H=Ee+I,De=rt(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=Xt(t.label),i=n?void 0:A.get(e),a=re.get(e);if(n)be[e]=H+1,ye[e]=H,H+=2+r;else{let t=i===void 0?0:k,n=i===void 0?0:ne;be[e]=H,ye[e]=H+r+t,H+=r+t+1+n,i!==void 0&&ie.set(i,ye[e]-t)}a!==void 0&&(j.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+I,je=Ae+D+I,Me=(V[V.length-1]??0)+(E[E.length-1]??0)+2;for(let e of M)Me=Math.max(Me,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)]+ga(t)+2+2+Yt(t.label);Me=Math.max(Me,e+1)}}for(let e of we)Me=Math.max(Me,e.x+e.width+1);let Ne=P(Me,je-1),Pe=se(Me,je-1);function U(e,t,n,r){R(Ne,e,t,n,{role:r,roleCanvas:Pe})}function Fe(e,t,n,r,i){let a=oe(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;U(o,t,a[n],r)}}function Ie(e,t,n,r,i){let a=r===`actor`?pa:[],o=[...a,...Q(n)],s=Math.max(Yt(n),a.length>0?ma:0),c=s+2*C+2,h=i,g=h-2,_=e-Math.floor(c/2);U(_,t,d,`border`);for(let e=1;e<c-1;e++)U(_+e,t,l,`border`);U(_+c-1,t,f,`border`);for(let e=0;e<g;e++){let n=t+1+e;U(_,n,u,`border`),U(_+c-1,n,u,`border`);let r=o[e];r!==void 0&&Fe(_+1+C+Math.floor((s-N(r))/2),n,r,`text`)}let v=t+h-1;U(_,v,p,`border`);for(let e=1;e<c-1;e++)U(_+e,v,l,`border`);U(_+c-1,v,m,`border`)}let Le=e=>{let t=ie.get(e);return t===void 0?Ee:t+D},Re=e=>j.get(e)??ke,ze=new Map,Be=new Map;function W(e,t){let n=Be.get(e)??[];Be.set(e,n),n.push(t)}function Ve(e,t){let n=Be.get(e)?.pop();if(n===void 0)return;let r=ze.get(e)??[];ze.set(e,r),r.push({topRow:n,bottomRow:t})}let He=new Map;for(let e of s.activations){let t=He.get(e.afterIndex)??[];t.push(e),He.set(e.afterIndex,t)}function Ue(e,t){for(let n of He.get(e)??[])n.kind===`start`?W(n.actorId,t):Ve(n.actorId,t)}Ue(-1,Ee);for(let e=0;e<s.messages.length;e++){let t=s.messages[e],n=ye[e];t.activate&&W(t.to,n),t.deactivate&&Ve(t.from,n),Ue(e,n)}for(let[e,t]of Be){if(t.length===0)continue;let n=Re(x(e)),r=ze.get(e)??[];ze.set(e,r);for(let e of t)r.push({topRow:e,bottomRow:n})}function We(e,t){let n=ze.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=Le(e);r<=Re(e);r++)U(t,r,We(n,r)?y:u,`line`)}let Ge=c?`+`:`┼`;function Ke(e,t,n){let r=_e(e),i=ve(e),a=t+D+1;U(r,t,d,`border`),U(i,t,f,`border`),U(r,a,p,`border`),U(i,a,m,`border`);for(let e=r+1;e<i;e++)U(e,t,l,`border`),U(e,a,l,`border`);for(let e=t+1;e<a;e++)U(r,e,u,`border`),U(i,e,u,`border`);n!==``&&Fe(r+2,t,` ${Q(n)[0]} `,`text`);for(let n=e.lo;n<=e.hi;n++){let e=V[n];Le(n)<=t&&t<=Re(n)&&U(e,t,Ge,`junction`),Le(n)<=a&&a<=Re(n)&&U(e,a,Ge,`junction`)}}for(let e of M)Ke(e,0,e.label),Ke(e,ke,``);for(let e=0;e<s.actors.length;e++){let t=s.actors[e],n=ie.get(e)??Te,r=j.has(e);Ie(V[e],n,t.label,t.type,D),r||Ie(V[e],Ae,t.label,t.type,D),c||(U(V[e],n+D-1,h,`junction`),r||U(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=ga(t),a=t.seqNumber===void 0?void 0:String(t.seqNumber),o=Q(t.label);U(i,n,_,`junction`);let s=i+1;if(a!==void 0){for(let e=0;e<a.length;e++)U(i+1+e,n,a[e],`text`);s=i+1+a.length}for(let e=s;e<i+r;e++)U(e,n,h,`line`);U(i+r,n,c?`+`:`┐`,`corner`);let l=i+r+2;for(let e=0;e<o.length;e++){let t=n+1+e;U(i+r,t,u,`line`),Fe(l,t,o[e],`text`,Me)}let d=n+1+o.length;U(i,d,p?m:f?c?`<`:`◀`:c?`<`:`◁`,`arrow`);for(let e=i+1;e<i+r;e++)U(e,d,h,`line`);U(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=O(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];Fe(d-Math.floor(N(t)/2),n+e,t,`text`,Me)}if(s){for(let e=i+1;e<u;e++)U(e,o,h,`line`);U(u,o,p?m:f?c?`>`:`▶`:c?`>`:`▷`,`arrow`),t.bidirectional&&U(i,o,c?`<`:`◀`,`arrow`)}else{for(let e=u+1;e<i;e++)U(e,o,h,`line`);U(u,o,p?m:f?c?`<`:`◀`:c?`<`:`◁`,`arrow`),t.bidirectional&&U(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++)U(t+n,o,e[n],`text`)}else{let t=i-e.length;if(t>u)for(let n=0;n<e.length;n++)U(t+n,o,e[n],`text`)}}}}for(let[e,t]of j)U(V[e],t,c?`x`:`✕`,`arrow`);let qe=Me-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=Me,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]+ga(t)+2+Yt(t.label);a=Math.max(a,e)}}let o=i-ha,c=a+ha,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-ha)),o<=g&&(o=Math.min(i,g+ha)),o=Math.max(0,o),c>qe&&(le(Ne,c+1,je-1),ce(Pe,c+1,je-1),qe=c);let y=t.label?`${t.type} [${t.label}]`:t.type,x=o+1+S(t);if(x>c){c=x;let[e]=L(Ne);c>e&&(le(Ne,c,je-1),ce(Pe,c,je-1)),Me=Math.max(Me,c+1),qe=Math.max(qe,c)}U(o,n,d,`border`);for(let e=o+1;e<c;e++)U(e,n,l,`border`);U(c,n,f,`border`);let C=Q(y);for(let e=0;e<C.length&&n+e<r;e++)Fe(o+1,n+e,C[e],`text`,c);U(o,r,p,`border`);for(let e=o+1;e<c;e++)U(e,r,l,`border`);U(c,r,m,`border`);for(let e=n+1;e<r;e++)U(o,e,u,`border`),U(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=Je();U(o,r,_,`junction`);for(let e=o+1;e<c;e++)U(e,r,i,`line`);U(c,r,v,`junction`);let a=t.dividers[n].label;if(a){let e=`[${a}]`;Fe(o+1,r,e,`text`,c)}}}for(let e of we){le(Ne,e.x+e.width,e.y+e.height),ce(Pe,e.x+e.width,e.y+e.height),U(e.x,e.y,d,`border`);for(let t=1;t<e.width-1;t++)U(e.x+t,e.y,l,`border`);U(e.x+e.width-1,e.y,f,`border`);for(let t=0;t<e.lines.length;t++){let n=e.y+1+t;U(e.x,n,u,`border`),U(e.x+e.width-1,n,u,`border`);for(let t=e.x+1;t<e.x+e.width-1;t++)U(t,n,` `,`text`);Fe(e.x+1+C,n,e.lines[t],`text`)}let t=e.y+e.height-1;U(e.x,t,p,`border`);for(let n=1;n<e.width-1;n++)U(e.x+n,t,l,`border`);U(e.x+e.width-1,t,m,`border`)}return ge(Ne,{roleCanvas:Pe,colorMode:i,theme:a});function Je(){return c?`-`:`╌`}}function va(e,t){return e.rowStart<=t.rowEnd&&t.rowStart<=e.rowEnd}function ya(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&&va(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 ba(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 xa(e,t){return{type:e,markerAt:t,dashed:e===`dependency`||e===`realization`}}function Sa(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 Ca(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=oe(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 wa(e){return Math.max(...Q(e).map(e=>N(e)))+2}var Ta=2,Ea=2,Da=2,Oa=4,ka=3;function Aa(e,t){let n=new Set(e.classes.map(e=>e.id)),r=new Set,i=[];for(let a of e.namespaces){let e=[];for(let i of a.classIds)if(!(!n.has(i)||r.has(i))){r.add(i),e.push(i);for(let[n,r]of t)r.forClass===i&&e.push(n)}e.length>0&&i.push({name:a.name,ids:e})}return i}function ja(e,t){let n=[],r=new Set;for(let i of e){let a=t.get(i);a===void 0?n.push(i):r.has(a)||(r.add(a),n.push(...e.filter(e=>t.get(e)===a)))}return n}function Ma(n,r,i,a,o={}){let c=(0,e.splitStatements)(n),{diagram:l,notesById:u}=Na((0,t.parseClassDiagram)(c));if(l.classes.length===0)return``;let f=Aa(l,u),p=new Map;for(let[e,t]of f.entries())for(let n of t.ids)p.set(n,e);let m=r.useAscii,h=rt(r.paddingX,5,4,1)+(f.length>0?Oa:0),g=rt(r.paddingY,5,3,1)+(f.length>0?ka:0),_=new Map,v=new Map,y=new Map;for(let e of l.classes){let t=ba(e);_.set(e.id,t);let{width:n,height:i}=Zi(t,r.boxBorderPadding);v.set(e.id,n),y.set(e.id,i)}let b=new Map;for(let e of l.classes)b.set(e.id,e);let x=new Map,S=new Map;for(let e of l.relationships){let t=e.from,n=e.to,r=x.get(n)??new Set;x.set(n,r),r.add(t);let i=S.get(t)??new Set;S.set(t,i),i.add(n)}let C=new Map,w=l.classes.filter(e=>!x.has(e.id)||x.get(e.id).size===0).map(e=>e.id);for(let e of w)C.set(e,0);let ee=l.classes.length-1,T=0;for(;T<w.length;){let e=w[T++],t=S.get(e);if(t)for(let n of t){let t=(C.get(e)??0)+1;t>ee||(!C.has(n)||C.get(n)<t)&&(C.set(n,t),w.push(n))}}for(let e of l.classes)C.has(e.id)||C.set(e.id,0);Pa(u,C);let E=Math.max(...C.values(),0),te=Array.from({length:E+1},()=>[]);for(let e of l.classes)te[C.get(e.id)].push(e.id);if(f.length>0)for(let[e,t]of te.entries())te[e]=ja(t,p);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?wa(t):3}))+1;t.forEach((t,r)=>{D.set(t,Math.round((r-(e-1)/2)*n)),O.set(t,(e-1)*n)})}}let k=new Map,ne=new Map,A=new Map,re=new Map;{let e=(e,t,n)=>{let r=new Map;l.relationships.forEach((t,n)=>{if(D.has(n)||!b.has(t.from)||!b.has(t.to))return;let i=C.get(t.from)??0;if((C.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?wa(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,A,re),e(e=>e.from,k,ne)}let ie=new Map;for(let e of l.classes)ie.set(e.id,{left:0,right:0});l.relationships.forEach((e,t)=>{if(!b.has(e.from)||!b.has(e.to))return;let n=e.label?wa(e.label):1,r=D.get(t)??k.get(t)??0,i=D.get(t)??A.get(t)??0,a=ie.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=ie.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,M=0,ae=0;for(let e=0;e<=E;e++){let t=te[e];if(t.length===0)continue;let n=e=>{let t=x.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=v.get(n),r=ie.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+h}}let s=0,c=0,l=(e,t)=>{let n=b.get(e),r=v.get(e),i=y.get(e),l=o.get(e),u=a.get(e);j.set(e,{cls:n,sections:_.get(e),x:t+l,y:M,width:r,height:i}),ae=Math.max(ae,t+u),s=t+u+h,c=Math.max(c,i)},u=new Set;for(let c of t){if(u.has(c))continue;let t=n(c),d=x.get(c),f=d?[...d].filter(t=>C.get(t)<e):[];if(f.length===0){l(c,Math.max(i.get(c),s,0)),u.add(c);continue}let p=r.get(t),m=f.map(e=>{let t=j.get(e);return t.x+Math.floor(t.width/2)}),g=Math.round(m.reduce((e,t)=>e+t,0)/m.length),_=0;for(let e=0;e<p.length;e++)_+=a.get(p[e]),e<p.length-1&&(_+=h);let y=o.get(p[0]),b=p[p.length-1],S=a.get(b)-o.get(b)-v.get(b),w=_-y-S,ee=g-y-Math.floor(w/2),T=Math.max(ee,s,0);for(let e of p)l(e,T),u.add(e),T=s}M+=c+g}let F=[];if(f.length>0){for(let e of j.values())e.x+=Ta,e.y+=Ea;ae+=Ta;for(let e of f){let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e.ids){let e=j.get(a);e&&(t=Math.min(t,e.x),n=Math.min(n,e.y),r=Math.max(r,e.x+e.width-1),i=Math.max(i,e.y+e.height-1))}if(t===1/0)continue;let a=t-Ta,o=Math.max(r+Ta,a+N(e.name)+5);F.push({name:e.name,x0:a,y0:n-Ea,x1:o,y1:i+Da})}}let I=ae;for(let e of F)I=Math.max(I,e.x1+1);let L=0;for(let e of j.values())I=Math.max(I,e.x+e.width),L=Math.max(L,e.y+e.height);for(let e of F)L=Math.max(L,e.y1+1);I+=4,L+=2;let z=P(I-1,L-1),de=se(I-1,L-1);function fe(e,t,n,r){R(z,e,t,n,{role:r,roleCanvas:de})}let me=o.hyperlinks?s(I-1,L-1):void 0;for(let t of j.values()){let n=Qi(t.sections,m,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<I&&a<L&&fe(n,a,i,Xi(i))}}if(me){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;d(me,n,{x:t.x,y:t.y},r,{from:e,to:i.length})}}}let he=new Set;for(let e of j.values())for(let t=0;t<e.height;t++)for(let n=0;n<e.width;n++)he.add(`${e.x+n},${e.y+t}`);function B(e,t,n,r){he.has(`${e},${t}`)||fe(e,t,n,r)}function V(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 _e(e,t,n,r){return aa(e,0,e+I+9,e=>{for(let i=Math.min(t,n);i<=Math.max(t,n);i++)if(V(e,i,r))return!1;return!0})??I+2}let ve=m?`-`:`─`,ye=m?`|`:`│`,be=m?`.`:`╌`,xe=m?`:`:`┊`;function Se(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 Ce(e,t,n){let r=D.get(e)??k.get(e)??0,i=D.get(e)??A.get(e)??0,a=O.get(e)??ne.get(e)??0,o=O.get(e)??re.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+Se(r,a,t.width),toAnchorX:c+Se(i,o,n.width)}}function we(e,t,n,r){if(he.has(`${e},${t}`)||de[e]?.[t]===`arrow`)return;let i=z[e]?.[t];if(!m&&i!==void 0&&ue(i)&&ue(n)){let a=pe(i,n);fe(e,t,a,a===n?r:`junction`);return}fe(e,t,n,r)}function Te(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++)we(t,e,r,`line`);if(m){we(t,e,r,`line`),we(n,e,r,`line`);return}let s=n>t,c=i?s?`└`:`┘`:s?`┌`:`┐`,l=i?s?`┐`:`┌`:s?`┘`:`└`;we(t,e,c,`corner`),we(n,e,l,`corner`)}let Ee=new Map,H=new Map;l.relationships.forEach((e,t)=>{let n=j.get(e.from),r=j.get(e.to);if(!n||!r)return;let i=xa(e.type,e.markerAt),a=i.dashed?be:ve,o=i.dashed?xe:ye,s=new Set([e.from,e.to]),{fromCX:c,toCX:l,fromAnchorX:u,toAnchorX:d}=Ce(t,n,r),f=n.y+n.height-1,p=r.y;if(f<p){let e=_e(c,f+1,p-1,s),n=e!==c;if(e>=I&&le(z,e+2,L),n){let n=f+1,r=p-1;Ee.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`);!m&&n<(z[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`);!m&&r<(z[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,Sa(i.type,m,e?`up`:`down`),`arrow`)}if(i.markerAt===`from`){let e=Sa(i.type,m,`down`);B(u,f+1,e,`arrow`)}}else{let e=f+Math.floor((p-f)/2),t=c!==u,n=l!==d;Te(f+1,u,c,a,!0);for(let n=f+(t?2:1);n<=e;n++)B(c,n,o,`line`);if(c!==l&&e<(z[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`);m||(B(c,e,c<l?`└`:`┘`,`corner`),B(l,e,c<l?`┐`:`┌`,`corner`))}for(let t=e+1;t<p-+!!n;t++)B(l,t,o,`line`);if(Te(p-1,d,l,a,!1),i.markerAt===`to`){let e=i.type===`inheritance`||i.type===`realization`;B(d,p-1,Sa(i.type,m,e?`up`:`down`),`arrow`)}i.markerAt===`from`&&B(u,f+1,Sa(i.type,m,`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),f=c!==u,p=l!==d;Te(e-1,u,c,a,!1);for(let t=e-(f?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`);!m&&s>=0&&s<L&&(B(c,s,c<l?`┌`:`┐`,`corner`),B(l,s,c<l?`┘`:`└`,`corner`))}for(let e=s-1;e>t+ +!!p;e--)B(l,e,o,`line`);if(Te(t+1,d,l,a,!0),i.markerAt===`from`){let t=Sa(i.type,m,`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=Sa(i.type,m,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,p=Math.min(c,l),h=Math.max(c,l),g=Math.max(f,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>p&&(g=Math.max(g,r.y+r.height-1));let _=g+2;H.set(t,_),le(z,I,_+1),ce(de,I,_+1);let v=c!==u,y=l!==d;Te(f+1,u,c,a,!0);for(let e=f+(v?2:1);e<=_;e++)B(c,e,o,`line`);for(let e=p;e<=h;e++)B(e,_,a,`line`);for(let e=_-1;e>=s+(y?2:1);e--)B(l,e,o,`line`);if(Te(s+1,d,l,a,!0),i.markerAt===`from`){let e=Sa(i.type,m,`down`),t=f+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=Sa(i.type,m,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 De(e,t,n,r){let{fromCX:i,toCX:a}=Ce(e,t,n),o=t.y+t.height-1,s=n.y;if(o<s){let t=Ee.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:H.get(e)??Math.max(o,n.y+n.height-1)+2}}function Oe(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(V(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(V(t,r,o)){e=!1;break}if(e){s=r;break}}}return s}let ke=new Map,Ae=[];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(N))+2,{idealMidX:s,baseMidY:c}=De(e,n,r,o),l=new Set([t.from,t.to]),u=Oe(n,r,s,c,o,i.length,l);ke.set(t,u);let d=Math.max(0,s-Math.floor(o/2));Ae.push({rel:t,idealMidX:s,naturalStart:d,naturalEnd:d+o-1,rowStart:u-a,rowEnd:u+a})}let je=ya(Ae,e=>({idealMid:e.idealMidX,start:e.naturalStart,end:e.naturalEnd,rowStart:e.rowStart,rowEnd:e.rowEnd})),Me=new Map;for(let e of Ae){let t=je.get(e);t&&Me.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}=De(e,n,r,Math.max(...i.map(e=>N(e)))+2),o=ke.get(t)-Math.floor(i.length/2),s=Me.get(t);for(let e=0;e<i.length;e++){let t=o+e,n=i[e],r=oe(` ${n} `),{start:c,cells:l}=Ca(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&&(le(z,Math.max(u,1),Math.max(t+1,1)),ce(de,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&&fe(n,t,l[e],`text`)}}}}for(let e of F){let t=m?`-`:`─`,n=m?`|`:`│`,r=m?{tl:`+`,tr:`+`,bl:`+`,br:`+`}:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`},i=oe(` ${e.name} `),a=t=>(z[t]?.[e.y0]??` `)===` `,o=e.x0+2;for(;Array.from({length:i.length+2},(e,t)=>o-1+t).some(e=>!a(e));)o++;e.x1=Math.max(e.x1,o+i.length+1),le(z,e.x1+1,e.y1+1),ce(de,e.x1+1,e.y1+1);let s=(e,t,n,r)=>{z[e]?.[t]===` `&&fe(e,t,n,r)};for(let n=e.x0+1;n<e.x1;n++)s(n,e.y0,t,`border`),s(n,e.y1,t,`border`);for(let t=e.y0+1;t<e.y1;t++)s(e.x0,t,n,`border`),s(e.x1,t,n,`border`);s(e.x0,e.y0,r.tl,`border`),s(e.x1,e.y0,r.tr,`border`),s(e.x0,e.y1,r.bl,`border`),s(e.x1,e.y1,r.br,`border`);for(let[n,r]of i.entries())z[o+n]?.[e.y0]===t&&fe(o+n,e.y0,r,`text`)}return Fa(u,j,z,m,fe),ge(z,{roleCanvas:de,colorMode:i,theme:a,linkCanvas:me})}function Na(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 Pa(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 Fa(e,t,n,r,i){if(e.size===0)return;let a=Tn(`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 Ia(t,n){let r=new Set,i=new Map;for(let e of t.subgraphs)La(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:st};a.set(n,t),o++}let s=[...a.values()],c=[],l=new Map,u=new Map;for(let n of t.edges){let o=n.source,s=n.target,d,f;if((0,e.isEdgeWithinOwnCluster)(n,i))continue;if(r.has(o)){let e=i.get(o),n=e?Ba(e,t,`exit`):void 0;n&&(o=n),d=n?e:void 0}if(r.has(s)){let e=i.get(s),n=e?Ba(e,t,`entry`):void 0;n&&(s=n),f=n?e:void 0}let p=a.get(o),m=a.get(s);if(!p||!m)continue;let h={from:p,to:m,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}};c.push(h),d&&l.set(h,d),f&&u.set(h,f)}let d=[];for(let e of t.subgraphs)Va(e,null,a,d,t);if(Ha(t.subgraphs,d,a),l.size>0||u.size>0){let e=new Map;Wa(t.subgraphs,d,e);for(let[t,n]of l){let r=e.get(n);r&&(t.clusterSource=r)}for(let[t,n]of u){let r=e.get(n);r&&(t.clusterTarget=r)}}let f=t.classDefs.get(`default`);if(f)for(let e of a.values())e.styleClassName=`default`,e.styleClass={name:`default`,styles:f};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:f?{...f,...i}:i})}return{nodes:s,edges:c,canvas:P(0,0),roleCanvas:se(0,0),grid:lt(),columnWidth:new Map,rowHeight:new Map,subgraphs:d,config:n,offsetX:0,offsetY:0,bundles:[]}}function La(e,t,n){t.add(e.id),n.set(e.id,e);for(let r of e.children)La(r,t,n)}function Ra(e,t){for(let n of e.nodeIds)t.add(n);for(let n of e.children)Ra(n,t)}function za(e,t){let n=new Set;if(Ra(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 Ba(e,t,n){let r=new Set;if(Ra(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 Va(e,t,n,r,i){let a;e.direction&&za(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=Va(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 Ha(e,t,n){let r=new Map;Wa(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||Ua(e,a)})}function Ua(e,t){let n=t;for(;n!==null;){if(n===e)return!0;n=n.parent}return!1}function Wa(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 Ga(n,r,i,a,o={}){return Ka((0,e.withDirectionOverride)((0,t.parseMermaid)(n),o.direction),r,i,a,o)}function Ka(e,t,n,r,i){t.graphDirection=e.direction===`LR`||e.direction===`RL`?`LR`:`TD`;let a=Ia(e,t);Mr(a),ia(a);let o=i.hyperlinks?f(a,e.interactions):void 0;return e.direction===`BT`&&(_e(a.canvas,a.roleCanvas,a.labelRects??[],o),V(a.canvas,a.roleCanvas),ye(a.roleCanvas),o&&l(o)),e.direction===`RL`&&(Se(a.canvas,a.roleCanvas,a.labelRects??[],o),xe(a.canvas,a.roleCanvas),we(a.roleCanvas),o&&u(o)),ge(a.canvas,{roleCanvas:a.roleCanvas,colorMode:n,theme:r,linkCanvas:o})}function qa(n,r,i,a,o={}){let s=(0,t.architectureToGraph)((0,t.parseArchitecture)((0,e.splitStatements)(n)));return Ka((0,e.withDirectionOverride)(s,o.direction),r,i,a,o)}var Ja=28,Ya=2;function Xa(e,n){let r=new Map(e.map(e=>[e,e])),i=e=>{let t=e;for(;r.get(t)!==t;)t=r.get(t);return t},a=new Set(e);for(let e of n){let n=(0,t.c4Placement)(e);if(n.axis===`horizontal`&&a.has(n.source)&&a.has(n.target)){let e=i(n.source),t=i(n.target);e!==t&&r.set(t,e)}}let o=new Map;for(let t of e)o.set(i(t),o.get(i(t))??new Set);for(let e of n){let n=(0,t.c4Placement)(e);if(n.axis===`horizontal`||!a.has(n.source)||!a.has(n.target))continue;let r=i(n.source),s=i(n.target);r!==s&&o.get(r).add(s)}let s=new Map,c=new Map,l=e=>{s.set(e,1);let t=[];for(let n of o.get(e)??[]){let e=s.get(n)??0;e!==1&&(t.push(n),e===0&&l(n))}c.set(e,t),s.set(e,2)};for(let e of o.keys())s.has(e)||l(e);let u=new Map,d=e=>{let t=u.get(e);if(t!==void 0)return t;u.set(e,0);let n=0;for(let[t,r]of c)r.includes(e)&&(n=Math.max(n,d(t)+1));return u.set(e,n),n},f=new Map;for(let t of e)f.set(t,d(i(t)));return f}var Za=[` o `,`/|\\`,`/ \\`];function Qa(e){let n=[];return e.kind===`person`&&n.push(...Za),n.push(...(0,t.wrapC4Text)(e.label,Ja),(0,t.c4TypeLine)(e)),e.description&&n.push(``,...(0,t.wrapC4Text)(e.description,Ja)),{lines:n,glyph:e.kind===`person`}}function $a(e,t){let{lines:n,glyph:r}=Qa(e),i=Math.max(...n.map(N)),a=e.shape===`db`?2:0;return{kind:`el`,el:e,lines:n,glyph:r,order:t,rank:0,box:{x:0,y:0,w:Math.max(14,i+4),h:n.length+2+a}}}function eo(n,r,i,a,o={}){let s=(0,e.withDirectionOverride)((0,t.parseC4Diagram)((0,e.splitStatements)(n)),o.direction);if(s.elements.length===0&&s.boundaries.length===0)return``;let c=r.useAscii,l=rt(r.paddingX,5,6,4),u=rt(r.paddingY,5,4,3)+ +!!s.relationships.some(e=>(0,t.c4RelLabelLines)(e).length>1),d=new Map;for(let[e,t]of s.elements.entries())d.set(t.alias,$a(t,e));let f=Xa([...s.elements.map(e=>e.alias),...to(s.boundaries)],s.relationships);for(let[e,t]of d)t.rank=f.get(e)??0;let p=new Map,m=new Set,h=e=>{let n=[];for(let t of e.elementAliases)m.add(t),n.push(d.get(t));for(let t of e.children)n.push(h(t));let r=(0,t.c4BoundaryTypeLine)(e),i=r?2:1;if(n.length===0){let n=[...(0,t.wrapC4Text)(e.label,Ja)];r&&n.push(r);let a={kind:`b`,b:e,rows:[],vgaps:[],headerH:i,order:2**53-1,rank:f.get(e.alias)??0,box:{x:0,y:0,w:Math.max(14,Math.max(...n.map(N))+4),h:n.length+2}};return p.set(e.alias,a),a}let a={kind:`b`,b:e,rows:[],vgaps:[],headerH:i,order:0,rank:0,box:{x:0,y:0,w:0,h:0}};a.rows=ao(n,s),s.direction===`BT`&&a.rows.reverse(),a.vgaps=co(a.rows,s,u),p.set(e.alias,a);let o=a.rows.flat();return a.order=Math.min(...o.map(e=>e.order)),a.rank=Math.min(...o.map(e=>e.rank)),oo(a,l),a},g=s.boundaries.map(h),_=ao([...s.elements.filter(e=>!m.has(e.alias)).map(e=>d.get(e.alias)),...g],s);s.direction===`BT`&&_.reverse();let v=co(_,s,u),y=s.title?2:0,b=(e,t,n,r,i)=>{let a=r;for(let[r,o]of e.entries()){let e=io(o,s,l),c=o.reduce((e,t)=>e+t.box.w,0)+no(e),u=n+Math.floor((i-c)/2),d=Math.max(...o.map(e=>e.box.h));o.forEach((t,n)=>{x(t,u,a+Math.floor((d-t.box.h)/2)),u+=t.box.w+(e[n]??0)}),a+=d+(t[r]??0)}},x=(e,t,n)=>{e.box.x=t,e.box.y=n,e.kind===`b`&&e.rows.length>0&&b(e.rows,e.vgaps,t+2,n+e.headerH+2,e.box.w-4)},S=Math.max(..._.map(e=>e.reduce((e,t)=>e+t.box.w,0)+no(io(e,s,l))));b(_,v,Ya,Ya+y,S);let C=0,w=0,ee=[...d.values(),...p.values()].map(e=>e.box);for(let e of ee)C=Math.max(C,e.x+e.w),w=Math.max(w,e.y+e.h);let T=C+Ya+1,E=w+Ya+1,te=P(T,E),D=se(T,E),O=(e,t,n,r)=>R(te,e,t,n,{role:r,roleCanvas:D}),k=(e,t,n,r)=>{let i=e;for(let e of oe(n))O(i,t,e,r),i++},ne=Array.from({length:T+1},()=>Array(E+1).fill(0)),A=Array.from({length:T+1},()=>Array(E+1).fill(!1)),re=e=>{for(let t=e.x;t<e.x+e.w;t++)for(let n=e.y;n<e.y+e.h;n++)A[t][n]=!0};if(s.title){let e=N(s.title);k(Math.max(0,Math.floor((T-e)/2)),1,s.title,`text`);for(let e=0;e<T;e++)A[e][1]=!0}let ie=e=>{let{x:n,y:r,w:i,h:a}=e.box,o=c?`-`:`╌`,s=c?`:`:`╎`,[l,u,d,f]=c?[`+`,`+`,`+`,`+`]:[`╭`,`╮`,`╰`,`╯`];for(let e=0;e<i;e++)ne[n+e][r]|=mo,ne[n+e][r+a-1]|=mo;for(let e=0;e<a;e++)ne[n][r+e]|=ho,ne[n+i-1][r+e]|=ho;for(let e=1;e<i-1;e++)O(n+e,r,o,`border`),O(n+e,r+a-1,o,`border`);for(let e=1;e<a-1;e++)O(n,r+e,s,`border`),O(n+i-1,r+e,s,`border`);if(O(n,r,l,`border`),O(n+i-1,r,u,`border`),O(n,r+a-1,d,`border`),O(n+i-1,r+a-1,f,`border`),e.rows.length>0){k(n+2,r+1,e.b.label,`text`);let a=(0,t.c4BoundaryTypeLine)(e.b);a&&k(n+2,r+2,a,`text`);let o=Math.max(N(e.b.label),N(a??``))+2;for(let t=1;t<=o&&n+t<n+i-1;t++)for(let i=1;i<=e.headerH;i++)A[n+t][r+i]=!0}else{let a=[...(0,t.wrapC4Text)(e.b.label,Ja)],o=(0,t.c4BoundaryTypeLine)(e.b);o&&a.push(o),a.forEach((e,t)=>k(n+Math.floor((i-N(e))/2),r+1+t,e,`text`)),re(e.box)}},j=e=>{for(let t of e)t.kind===`b`&&(ie(t),j(t.rows.flat()))};j(_.flat());let M=e=>{let{x:t,y:n,w:r,h:i}=e.box,a=e.el,o=a.external,s=c?o?`.`:`-`:o?`┄`:`─`,l=c?o?`:`:`|`:o?`┆`:`│`,u=a.kind===`person`||a.shape!=="default",[d,f,p,m]=c?[`+`,`+`,`+`,`+`]:u?[`╭`,`╮`,`╰`,`╯`]:[`┌`,`┐`,`└`,`┘`];for(let e=1;e<r-1;e++)O(t+e,n,s,`border`),O(t+e,n+i-1,s,`border`);let h=a.shape===`queue`?`(`:l,g=a.shape===`queue`?`)`:l;for(let e=1;e<i-1;e++)O(t,n+e,h,`border`),O(t+r-1,n+e,g,`border`);O(t,n,d,`border`),O(t+r-1,n,f,`border`),O(t,n+i-1,p,`border`),O(t+r-1,n+i-1,m,`border`);let _=n+1;if(a.shape===`db`){let e=c?`+`:`├`,a=c?`+`:`┤`;for(let o of[n+1,n+i-2]){O(t,o,e,`junction`),O(t+r-1,o,a,`junction`);for(let e=1;e<r-1;e++)O(t+e,o,s,`border`)}_=n+2}e.lines.forEach((n,i)=>{let a=e.glyph&&i<Za.length,o=N(n);k(t+Math.floor((r-o)/2),_+i,n,a?`border`:`text`)}),re(e.box)};for(let e of d.values())M(e);let ae=e=>{let t=d.get(e);return t?{box:t.box,boundary:!1}:{box:p.get(e).box,boundary:!0}},F=Array.from({length:T+1},()=>Array(E+1).fill(0)),ce=new Map,I=[];for(let e of s.relationships){if(e.from===e.to)continue;let t=ae(e.from),n=ae(e.to),r=[];t.boundary&&p.get(e.from).rows.length>0&&r.push(t.box),n.boundary&&p.get(e.to).rows.length>0&&r.push(n.box);let i=Co(t.box,n.box,{width:T,height:E,blocked:A,masks:F,arrows:ce,borders:ne},r);if(!i)continue;I.push({rel:e,path:i}),xo(i,F,t.box,n.box);let a=i[i.length-1],o=i[0];(!e.reversed||e.bidirectional)&&ce.set(`${a[0]},${a[1]}`,_o(go(a,n.box),c)),(e.bidirectional||e.reversed)&&ce.set(`${o[0]},${o[1]}`,_o(go(o,t.box),c))}for(let e=0;e<=T;e++)for(let t=0;t<=E;t++){let n=F[e][t];if(n===0)continue;let r=ce.get(`${e},${t}`);r?O(e,t,r,`arrow`):O(e,t,yo(n,c),bo(n)?`corner`:`line`)}for(let[e,t]of ce){let[n,r]=e.split(`,`).map(Number);O(n,r,t,`arrow`)}let L=(e,t)=>e>=0&&t>=0&&e<=T&&t<=E&&te[e][t]===` `&&!A[e][t],le=(e,t)=>e>=0&&t>=0&&e<=T&&t<=E&&!A[e][t]&&!ce.has(`${e},${t}`)&&(te[e][t]===` `||F[e][t]!==0);for(let{rel:e,path:n}of I){let r=(0,t.c4RelLabelLines)(e);if(r.length===0)continue;let i=Math.max(...r.map(N)),a=[r];for(let e of[18,12,8,6])i>e&&a.push(r.flatMap((n,r)=>r===0?(0,t.wrapC4Text)(n,e):[n]));let o=e=>a.some(t=>To(t,n,L,le,k,e));o(!1)||o(!0)}return ge(te,{roleCanvas:D,colorMode:i,theme:a})}function to(e){return e.flatMap(e=>e.elementAliases.length===0&&e.children.length===0?[e.alias]:to(e.children))}var no=e=>e.reduce((e,t)=>e+t,0);function ro(e,n,r){let i=(e,t)=>e.kind===`el`?e.el.alias===t:e.b.alias===t,a=0;for(let o of r.relationships){let r=(0,t.c4Placement)(o);r.axis===`horizontal`&&(i(e,r.source)&&i(n,r.target)||i(n,r.source)&&i(e,r.target))&&(a=Math.max(a,...(0,t.c4RelLabelLines)(o).map(N)))}return a}function io(e,t,n){let r=[];for(let i=0;i<e.length-1;i++){let a=ro(e[i],e[i+1],t);r.push(Math.max(n,a>0?a+4:0))}return r}function ao(e,n){let r=new Map;for(let t of e)r.set(t.rank,[...r.get(t.rank)??[],t]);let i=[...r.entries()].sort((e,t)=>e[0]-t[0]).map(([,e])=>e.sort((e,t)=>e.order-t.order)),a=e=>e.kind===`el`?e.el.alias:e.b.alias;for(let e of i)for(let r=0;r<e.length;r++){let r=!1;for(let i of n.relationships){let n=(0,t.c4Placement)(i);if(n.axis!==`horizontal`)continue;let o=e.map(a),s=o.indexOf(n.source),c=o.indexOf(n.target);if(s<0||c<0||s<c)continue;let[l]=e.splice(s,1);e.splice(c,0,l),r=!0}if(!r)break}return i}function oo(e,n){let r=0,i=e.headerH+2;for(let[t,a]of e.rows.entries()){let o=no(a.map(e=>e.box.w))+(a.length-1)*n;r=Math.max(r,o),i+=Math.max(...a.map(e=>e.box.h))+(e.vgaps[t]??0)}let a=Math.max(N(e.b.label),N((0,t.c4BoundaryTypeLine)(e.b)??``));e.box.w=Math.max(r,a)+4,e.box.h=i+2}function so(e,t=new Set){if(e.kind===`el`)t.add(e.el.alias);else{t.add(e.b.alias);for(let n of e.rows)for(let e of n)so(e,t)}return t}function co(e,n,r){let i=new Map;e.forEach((e,t)=>{for(let n of e)for(let e of so(n))i.set(e,t)});let a=e.map(()=>0);for(let e of n.relationships){let n=i.get(e.from),r=i.get(e.to);if(n===void 0||r===void 0||n===r)continue;let o=(0,t.c4RelLabelLines)(e).length;if(o!==0)for(let e=Math.min(n,r);e<Math.max(n,r);e++)a[e]=a[e]+o+1}return e.slice(0,-1).map((e,t)=>Math.max(r,a[t]+1))}var lo=1,uo=2,fo=4,po=8,mo=1,ho=2;function go(e,t){let[n,r]=e;return r<t.y?uo:r>=t.y+t.h?lo:n<t.x?po:fo}function _o(e,t){return e===uo?t?`v`:`▼`:e===lo?t?`^`:`▲`:e===po?t?`>`:`►`:t?`<`:`◄`}var vo={[lo]:`│`,[uo]:`│`,3:`│`,[fo]:`─`,[po]:`─`,12:`─`,10:`┌`,6:`┐`,9:`└`,5:`┘`,11:`├`,7:`┤`,14:`┬`,13:`┴`,15:`┼`};function yo(e,t){let n=vo[e]??`┼`;return t?n===`│`?`|`:n===`─`?`-`:`+`:n}function bo(e){return e===10||e===6||e===9||e===5}function xo(e,t,n,r){let i=(e,t)=>t[0]>e[0]?po:t[0]<e[0]?fo:t[1]>e[1]?uo:lo,a=e=>e===lo?uo:e===uo?lo:e===fo?po:fo;for(let n=0;n<e.length;n++){let[r,o]=e[n];n>0&&(t[r][o]|=a(i(e[n-1],e[n]))),n<e.length-1&&(t[r][o]|=i(e[n],e[n+1]))}let o=e[0],s=e[e.length-1];t[o[0]][o[1]]|=go(o,n),t[s[0]][s[1]]|=go(s,r)}function So(e,t,n){let r=[],i=e.x+e.w/2,a=e.y+e.h/2,o=t.x+t.w/2,s=t.y+t.h/2,c=t.y<e.y+e.h&&e.y<t.y+t.h,l=new Set;c?l.add(o>i?po:fo):l.add(s>a?uo:lo);let u=e=>l.has(e)?0:e===uo&&l.has(lo)||e===lo&&l.has(uo)||e===fo&&l.has(po)||e===po&&l.has(fo)?14:7,d=(e,t,i,a)=>{e<0||t<0||e>n.width||t>n.height||n.blocked[e][t]||r.push({cell:[e,t],cost:u(i)+Math.abs(a)*.2})};for(let t=e.x+1;t<e.x+e.w-1;t++)d(t,e.y-1,lo,t-i),d(t,e.y+e.h,uo,t-i);for(let t=e.y+1;t<e.y+e.h-1;t++)d(e.x-1,t,fo,t-a),d(e.x+e.w,t,po,t-a);return r}function Co(e,t,n,r){let i=(e,t)=>r.some(n=>e>=n.x&&e<n.x+n.w&&t>=n.y&&t<n.y+n.h),a=So(e,t,n).filter(e=>!i(...e.cell)),o=new Map;for(let r of So(t,e,n))i(...r.cell)||o.set(`${r.cell[0]},${r.cell[1]}`,r.cost);if(a.length===0||o.size===0)return;let s=(e,n)=>(e<t.x?t.x-e:e>=t.x+t.w?e-(t.x+t.w-1):0)+(n<t.y?t.y-n:n>=t.y+t.h?n-(t.y+t.h-1):0),c=[],l=new Map;for(let e of a){let[t,n]=e.cell;c.push({x:t,y:n,dir:0,g:e.cost,f:e.cost+s(t,n),parent:void 0}),l.set(`${t},${n},0`,e.cost)}let u=[[0,-1,lo],[0,1,uo],[-1,0,fo],[1,0,po]],d=0;for(;c.length>0&&d++<2e5;){let e=0;for(let t=1;t<c.length;t++)c[t].f<c[e].f&&(e=t);let t=c.splice(e,1)[0],r=`${t.x},${t.y}`;if(o.get(r)!==void 0){let e=[];for(let n=t;n;n=n.parent)e.push([n.x,n.y]);return e.reverse()}for(let[e,r,a]of u){let u=t.x+e,d=t.y+r;if(u<0||d<0||u>n.width||d>n.height)continue;let f=o.has(`${u},${d}`);if(n.blocked[u][d]&&!f||i(u,d)||n.arrows.has(`${u},${d}`))continue;let p=1;t.dir!==0&&t.dir!==a&&(p+=2);let m=n.borders[u][d];m!==0&&(a===fo||a===po?(m&mo)!==0:(m&ho)!==0)&&(p+=12);let h=n.masks[u][d];if(h!==0){let e=a===fo||a===po,t=!!(h&12),n=!!(h&3);p+=e&&t||!e&&n?8:3}let g=t.g+p+(f?o.get(`${u},${d}`)??0:0),_=`${u},${d},${a}`;(l.get(_)??1/0)<=g||(l.set(_,g),c.push({x:u,y:d,dir:a,g,f:g+s(u,d),parent:t}))}}}function wo(e){let t=[],n=0;for(;n<e.length-1;){let r=e[n+1][1]===e[n][1],i=n+1;for(;i<e.length-1&&e[i+1][1]===e[i][1]===r;)i++;let[a,o]=e[n],[s,c]=e[i];t.push({horizontal:r,x0:Math.min(a,s),y0:Math.min(o,c),len:Math.abs(s-a)+Math.abs(c-o)+1}),n=i}return t}function To(e,t,n,r,i,a){let o=e.map(N),s=e=>e.every(([e,t],r)=>{let i=o[r];for(let r=0;r<i;r++)if(!n(e+r,t))return!1;return n(e-1,t)&&n(e+i,t)}),c=e=>Array.from({length:e},(e,t)=>t).sort((t,n)=>Math.abs(t-e/2)-Math.abs(n-e/2));for(let n of a?[]:wo(t).sort((e,t)=>t.len-e.len))for(let t of c(n.len)){let r=[];if(n.horizontal){let i=n.x0+t;r.push(e.map((e,t)=>[i-Math.floor(o[t]/2),t===0?n.y0-1:n.y0+t])),e.length===1&&r.push([[i-Math.floor(o[0]/2),n.y0+1]])}else{let i=n.y0+t-Math.floor((e.length-1)/2);for(let t of[1,-1])r.push(e.map((e,r)=>[t>0?n.x0+2:n.x0-1-o[r],i+r]))}for(let t of r)if(s(t))return t.forEach(([t,n],r)=>i(t,n,e[r],`text`)),!0}let l=e=>e.every(([e,t],n)=>{for(let i=0;i<o[n];i++)if(!r(e+i,t))return!1;return!0});for(let n of a?wo(t).sort((e,t)=>t.len-e.len):[])for(let t of c(n.len)){let r=e.map((r,i)=>n.horizontal?[n.x0+t-Math.floor(o[i]/2),n.y0+i-+(e.length>1)]:[n.x0-Math.floor(o[i]/2),n.y0+t+i]);if(l(r))return r.forEach(([t,n],r)=>i(t,n,e[r],`text`)),!0}return!1}var Eo={xychart:(e,t,n,r)=>Ne(e,t,n,r),er:(e,t,n,r)=>da(e,t,n,r),sequence:(e,t,n,r)=>_a(e,t,n,r),class:(e,t,n,r,i)=>Ma(e,t,n,r,i),flowchart:(e,t,n,r,i)=>Ga(e,t,n,r,i),architecture:(e,t,n,r,i)=>qa(e,t,n,r,i),c4:(e,t,n,r,i)=>eo(e,t,n,r,i)},Do=/\x1b\[[0-9;]*m/g;function Oo(e){let t=e.split(`
|
|
5
|
-
`)
|
|
6
|
-
`)
|
|
3
|
+
`)}function We(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?ne(s,o,i):s,s=``,o=null),a+=` `;continue}let u=n[c]??null,d=t[c]??null,f=u??(d?Me(d,r):null);f===o?s+=l:(s.length>0&&(a+=o?ne(s,o,i):s),s=l,o=f)}return s.length>0&&(a+=o?ne(s,o,i):s),a}function Ge(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 Ke(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)=>Ye(n+i*t))}return Array.from({length:t},(e,t)=>String(t+1))}function qe(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 Je(e){let t=e.length>1?Math.abs(e[1]-e[0]):0,n=t>0&&t<1?Math.ceil(-Math.log10(t)-1e-9):0;return e.map(e=>String(Number.isInteger(e)&&n===0?e:Number(e.toFixed(n))))}function Ye(e){return Number.isInteger(e)?String(e):e.toFixed(+(Math.abs(e)<10))}var G={x:1,y:0},K={x:1,y:2},q={x:0,y:1},J={x:2,y:1},Xe={x:2,y:0},Ze={x:0,y:0},Qe={x:2,y:2},$e={x:0,y:2},et={x:1,y:1};function Y(e,t){return e.x===t.x&&e.y===t.y}function tt(e){return Y(e,G)||Y(e,K)||Y(e,q)||Y(e,J)}function nt(e){if(!tt(e))throw Error(`Expected a cardinal direction (Up/Down/Left/Right); got {x:${e.x}, y:${e.y}}`);return e}function rt(e,t,n,r){return Math.max(r,n+(e-t))}function it(e,t){return e.x===t.x&&e.y===t.y}function at(e,t){return e.x===t.x&&e.y===t.y}function ot(e,t){return{x:e.x+t.x,y:e.y+t.y}}function X(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 st={name:``,styles:{}},ct=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 lt(){return new ct}function ut(e){let t=lt();for(let n of e.keys())t.add(n);return t}function dt(e,t){return e.has(X(t))}function ft(e,t){return t.x<0||t.y<0?!1:!dt(e,t)}function pt(e,t,n=3){for(let r=0;r<n;r++)for(let i=0;i<n;i++)if(dt(e,{x:t.x+r,y:t.y+i}))return!1;return!0}function mt(e,t,n=3){if(!pt(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(X(n))}}var ht=1e5;function gt(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>=ht)throw Error(`pathCells: segment from (${r.x},${r.y}) to (${i.x},${i.y}) did not reach its endpoint within ${ht} 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 _t=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 vt(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 yt=.001,bt=[{x:1,y:0},{x:-1,y:0},{x:0,y:1},{x:0,y:-1}],xt=5e4,St=2e5;function Ct(e=St){return{remaining:e}}function wt(e,t,n,r,i=!1){if(r&&r.remaining<=0)return null;let a=new _t;a.push({coord:t,priority:0});let o=new Map;o.set(X(t),0);let s=new Map;s.set(X(t),null);let c=0;for(;a.length>0;){if(++c>xt)return null;if(r){if(r.remaining<=0)return null;r.remaining--}let t=a.pop().coord;if(it(t,n)){let e=[],n=t;for(;n!==null;)e.unshift(n),n=s.get(X(n))??null;return e}let l=o.get(X(t));if(l===void 0)throw Error(`A* pathfinding: missing cost for visited cell ${X(t)}`);for(let r of bt){let c={x:t.x+r.x,y:t.y+r.y};if(!ft(e,c)&&!it(c,n))continue;let u=i?s.get(X(t)):null,d=u&&(t.x-u.x!==r.x||t.y-u.y!==r.y),f=l+1+(d?yt:0),p=X(c),m=o.get(p);if(m===void 0||f<m){o.set(p,f);let e=f+vt(c,n);a.push({coord:c,priority:e}),s.set(p,t)}}}return null}function Tt(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 Et(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)&&!ft(e,a))return!1;if(n)break}return!0}function Dt(e,t,n,r){let i=r?{x:n.x,y:t.y}:{x:t.x,y:n.y};return!Et(e,t,i,!0)||!Et(e,i,n,!1)?null:[t,i,n]}function Ot(e,t,n,r){if(t.x===n.x||t.y===n.y)return null;let i=Y(r,q)||Y(r,J);return Dt(e.grid,t,n,i)??Dt(e.grid,t,n,!i)}function kt(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=Ot(e,t,n,r)??wt(e.grid,t,n,e.pathBudget,e.preferStraightRoutes===!0);return i?Tt(i):null}function At(e){let t=null;for(let n of e.nodes){let e=n.gridCoord;if(e){if(!t){t={minX:e.x,minY:e.y,maxX:e.x+2,maxY:e.y+2};continue}t.minX=Math.min(t.minX,e.x),t.minY=Math.min(t.minY,e.y),t.maxX=Math.max(t.maxX,e.x+2),t.maxY=Math.max(t.maxY,e.y+2)}}return t}function jt(e,t,n){let r=e.config.graphDirection!==`LR`,i=r?K:J,a=r?G:q,o=ot(Z(t.anchor),i),s=ot(Z(n.to),a),c=kt(e,t.gutter,s,nt(r?J:K));if(!c||c.length<2)return null;let l=[o,...c];return{path:l,startDir:i,endDir:a,labelSegment:Nt(t)?[l[l.length-2],l[l.length-1]]:[l[1],l[2]]}}function Mt(e,t){let n=t.clusterTarget;if(!n||t.bundle||t.from===t.to)return null;let r=At(n),i=t.from.gridCoord;if(!r||!i||n.nodes.includes(t.from)||!n.nodes.includes(t.to))return null;let a=e.config.graphDirection!==`LR`;if(a?i.y+2>=r.minY-1:i.x+2>=r.minX-1)return null;let o=(e,t,n)=>Math.min(Math.max(e,t),n),s=a?{x:o(i.x+1,r.minX+1,r.maxX-1),y:r.minY-1}:{x:r.minX-1,y:o(i.y+1,r.minY+1,r.maxY-1)};if(!ft(e.grid,s))return null;let c=a?K:J,l=a?G:q,u=kt(e,ot(i,c),s,nt(c));return!u||u.length<2?null:{path:u,startDir:c,endDir:l}}function Nt(e){for(let t of e.edges)if(t.parallelLane)return!0;return!1}function Pt(e){let t=e.config.graphDirection!==`LR`,n=new Map;for(let t of e.edges){let e=t.clusterSource;if(!e)continue;let r=n.get(e);r?r.push(t):n.set(e,[t])}for(let r=0;r<=Ft;r++){let i=new Map,a=null;for(let[r,o]of n){let n=Lt(e,r,o,t);if(typeof n==`number`){a=n;break}n&&i.set(r,n)}if(a===null||r===Ft){i.size>0&&(e.clusterExitPlans=i);return}It(e,t,a)}}var Ft=4;function It(e,t,n){let r=e=>t?{x:e.x>=n?e.x+1:e.x,y:e.y}:{x:e.x,y:e.y>=n?e.y+1:e.y};for(let t of e.nodes)t.gridCoord&&=r(t.gridCoord);let i=[...e.grid.keys()];for(let t of i)e.grid.delete(t);for(let t of i){let[n,i]=t.split(`,`).map(Number);e.grid.add(X(r({x:n,y:i})))}let a=t?e.columnWidth:e.rowHeight,o=[...a].filter(([e])=>e>=n);for(let[e]of o)a.delete(e);for(let[e,t]of o)a.set(e+1,t);a.set(n,t?e.config.paddingX:e.config.paddingY)}function Lt(e,t,n,r){let i=At(t);if(!i)return null;let a=n.filter(e=>{let n=e.from.gridCoord,a=e.to.gridCoord;return!n||!a||e.bundle||e.from===e.to||!t.nodes.includes(e.from)||t.nodes.includes(e.to)?!1:r?a.y>i.maxY+1:a.x>i.maxX+1}),o=new Set(a),s=new Map;for(let t of e.edges){if(!t.parallelLane)continue;let e=s.get(t.parallelLane.usedOffsets);e?e.push(t):s.set(t.parallelLane.usedOffsets,[t])}let c=a.filter(e=>!e.parallelLane||s.get(e.parallelLane.usedOffsets).every(e=>o.has(e)));if(c.length===0)return null;let l=c[0].from;if(c.some(e=>e.from!==l))return null;let u=Z(l),d=r?{x:u.x+1,y:i.maxY+1}:{x:i.maxX+1,y:u.y+1},f=ot(u,r?K:J),p={box:i,anchor:l,gutter:d,edges:new Set(c)},m=new Set;for(let t of c){let n=t.parallelLane;if(n&&n.index>0&&!zt(e,p,t)){let r=Rt(e,p,t)?.insertAt,i=c.some(e=>e.parallelLane?.usedOffsets!==n.usedOffsets);if(r!==void 0&&i)return r;m.add(n.usedOffsets)}}if(c=c.filter(e=>!e.parallelLane||!m.has(e.parallelLane.usedOffsets)),new Set(c.map(e=>e.parallelLane?.usedOffsets??e)).size<2)return null;let h=r?d.y-f.y:d.x-f.x;for(let t=1;t<=h;t++){let n=r?{x:f.x,y:f.y+t}:{x:f.x+t,y:f.y};if(!ft(e.grid,n))return null}let g={box:i,anchor:l,gutter:d,edges:new Set(c)};for(let t of c)if(!jt(e,g,t))return null;return g}function Rt(e,t,n){let r=e.config.graphDirection!==`LR`,i=n.parallelLane.index;if(i>3)return null;let a=Z(n.to),o=r?a.x:a.y,s=o+1,c=r?t.gutter.x:t.gutter.y,l={lane:o+3,attach:o+2,dir:r?q:G},u={lane:o-1,attach:o,dir:r?J:K},d=r?e.columnWidth:e.rowHeight,f=c>=s;if(i===3||i===2&&f){let t=o+4+(f?i-2:0);if(t===c)return null;let n=e.nodes.some(e=>{let n=Z(e),i=r?n.x:n.y;return i<=t&&t<=i+2});return{...l,lane:t,insertAt:n||!d.has(t)?t:void 0}}let p=(c>=s?[l,u]:[u,l])[i-1];return p.lane===c?null:p.lane<0?{...p,insertAt:0}:d.has(p.lane)?p:null}function zt(e,t,n){let r=e.config.graphDirection!==`LR`,i=Z(n.to),a=t.gutter,o=Rt(e,t,n);if(!o||o.insertAt!==void 0)return null;let s=Tt(r?[a,{x:o.lane,y:a.y},{x:o.lane,y:i.y+1},{x:o.attach,y:i.y+1}]:[a,{x:a.x,y:o.lane},{x:i.x+1,y:o.lane},{x:i.x+1,y:o.attach}]);if(!Zt(e,gt(s),[n.from,n.to]))return null;let c=r?[{x:o.lane,y:a.y},{x:o.lane,y:i.y}]:[{x:a.x,y:o.lane},{x:i.x,y:o.lane}];return{path:s,endDir:o.dir,labelSegment:c}}var Bt=64;function Vt(e){let t=e.clusterExitPlans;if(!t)return!1;let n=e.config.graphDirection!==`LR`,r=!1,i=[...t].sort(([e],[t])=>Ht(e)-Ht(t));for(let[t,a]of i){let i=n?t.maxY:t.maxX,o=n?e.rowHeight:e.columnWidth,s=n?a.gutter.y:a.gutter.x;for(let t=0;t<Bt&&!Ut(e,a,i,n);t++)o.set(s,(o.get(s)??0)+1),r=!0}return r}function Ht(e){let t=0;for(let n=e.parent;n;n=n.parent)t++;return t}function Ut(e,t,n,r){let i=e=>r?e.y:e.x;if(i($(e,t.gutter))<=n)return!1;for(let a of t.edges){let t=aa(e,a),o=a.path[a.path.length-1];if(!t||!o)continue;let s=i($(e,o))-1;for(let{x:e,y:i,text:a}of t){let t=r?i:e,o=r?i:e+N(a)-1;if(t<=n||o>=s)return!1}}return!0}function Wt(e){return e===G?K:e===K?G:e===q?J:e===J?q:e===Xe?$e:e===Ze?Qe:e===Qe?Ze:e===$e?Xe:et}function Gt(e,t){return e.x===t.x?e.y<t.y?K:G:e.y===t.y?e.x<t.x?J:q:e.x<t.x?e.y<t.y?Qe:Xe:e.y<t.y?$e:Ze}function Kt(e){return e===`LR`?[J,K,K,J]:[K,J,J,K]}function qt(e,t){if(e.from===e.to)return Kt(t);let n=Gt(Z(e.from),Z(e.to)),r,i,a,o,s=t===`LR`?Y(n,q)||Y(n,Ze)||Y(n,$e):Y(n,G)||Y(n,Ze)||Y(n,Xe);return t===`LR`&&e.to.fanInCentered&&(Y(n,Qe)||Y(n,Xe))?(r=J,i=q,a=J,o=q):Y(n,Qe)?t===`LR`?(r=K,i=q,a=J,o=G):(r=J,i=G,a=K,o=q):Y(n,Xe)?t===`LR`?(r=G,i=q,a=J,o=K):(r=J,i=K,a=G,o=q):Y(n,$e)?t===`LR`?(r=K,i=K,a=q,o=G):(r=q,i=G,a=K,o=J):Y(n,Ze)?t===`LR`?(r=K,i=K,a=q,o=K):(r=J,i=J,a=G,o=J):s?t===`LR`&&Y(n,q)?(r=K,i=K,a=q,o=J):t===`TD`&&Y(n,G)?(r=J,i=J,a=G,o=K):(r=n,i=Wt(n),a=n,o=Wt(n)):(r=n,i=Wt(n),a=n,o=Wt(n)),[r,i,a,o]}var Jt=2,Yt=200;function Xt(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 Zt(e,t,n=[]){for(let r=1;r<t.length-1;r++){let i=t[r];if(dt(e.grid,i)&&!n.some(e=>Xt(e,i)))return!1}return!0}function Qt(e){let t=e.from.gridCoord,n=e.to.gridCoord;return!t||!n?!1:t.y===n.y&&t.x!==n.x}function $t(e){let t=e.from.name,n=e.to.name;return Qt(e)&&n<t?JSON.stringify([n,t]):JSON.stringify([t,n])}function en(e){let t=new Map;for(let n of e.edges){if(n.from===n.to)continue;let e=$t(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 tn(e,t,n,r,i){let a=ot(Z(t.from),n),o=ot(Z(t.to),r),s=Y(n,q)||Y(n,J),c=[t.from,t.to],l=t.parallelLane.usedOffsets,u=Y(n,J)?1:Y(n,q)?-1:Y(n,K)?1:-1,d=Y(r,J)?1:Y(r,q)?-1:Y(r,K)?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=Jt*i;for(let n=0;n<Yt;n++){let r=g+n;if(l.has(r))continue;let i=a.y+r,u=a.x+r;{let n=s?K:J,i=ot(Z(t.from),n),a=ot(Z(t.to),n),o=s?[{x:i.x,y:Math.max(i.y,a.y)+r-1},{x:a.x,y:Math.max(i.y,a.y)+r-1}]:[{x:Math.max(i.x,a.x)+r-1,y:i.y},{x:Math.max(i.x,a.x)+r-1,y:a.y}],u=Tt([i,...o,a]);if(Zt(e,gt(u),c))return l.add(r),{path:u,labelSegment:o,faces:{startDir:n,endDir:n}}}let d=s?[{x:a.x,y:i},{x:o.x,y:i}]:[{x:u,y:a.y},{x:u,y:o.y}],_=Tt([a,d[0],s?{x:p.x,y:i}:{x:u,y:p.y},p,o]);if(Zt(e,gt(_),c))return l.add(r),{path:_,labelSegment:d};m=_,h=d;let v=s?f.x!==p.x:f.y!==p.y,y=s?v?[{x:f.x,y:i},{x:p.x,y:i}]:[{x:f.x,y:i},{x:f.x,y:i}]:v?[{x:u,y:f.y},{x:u,y:p.y}]:[{x:u,y:f.y},{x:u,y:f.y}],b=Tt(s?[a,f,{x:f.x,y:i},{x:p.x,y:i},p,o]:[a,f,{x:u,y:f.y},{x:u,y:p.y},p,o]);if(Zt(e,gt(b),c))return l.add(r),{path:b,labelSegment:y};m=b,h=y}return{path:m,labelSegment:h}}function nn(e,t,n){let r=e.config.graphDirection===`LR`?J:K,i=ot(Z(t.anchor),r),a=zt(e,t,n);return a?{path:[i,...a.path],startDir:r,endDir:a.endDir,labelSegment:a.labelSegment}:null}function rn(e,t){let n=kr(e,t.from),r=kr(e,t.to),[i,a,o,s]=qt(t,n&&n===r&&n.direction?n.direction:e.config.graphDirection),c=t.clusterSource?e.clusterExitPlans?.get(t.clusterSource):void 0;if(c?.edges.has(t)){let n=t.parallelLane&&t.parallelLane.index>0?nn(e,c,t):jt(e,c,t);if(n){t.startDir=n.startDir,t.endDir=n.endDir,t.path=n.path,t.text.length>0&&dn(e,t,n.labelSegment,N(t.text));return}c.edges.delete(t),t.labelLine=[]}if(t.clusterTarget){let n=Mt(e,t);if(n){t.startDir=n.startDir,t.endDir=n.endDir,t.path=n.path,t.clusterEntered=!0;let r=n.path[n.path.length-1];if(t.text.length>0&&e.config.graphDirection===`LR`){let n=e.columnWidth.get(r.x)??0;e.columnWidth.set(r.x,Math.max(n,N(t.text)+5))}return}t.clusterEntered=!1}if(t.parallelLane&&t.parallelLane.index>0){let n=Y(i,a),r=n?o:i,c=n?s:a;t.startDir=r,t.endDir=c;let l=tn(e,t,r,c,t.parallelLane.index);t.path=l.path,l.faces&&(t.startDir=l.faces.startDir,t.endDir=l.faces.endDir),t.text.length>0&&dn(e,t,l.labelSegment,N(t.text));return}if(an(e,t.to)&&!Y(i,o)){let n=kt(e,ot(Z(t.from),o),ot(Z(t.to),s),nt(o));if(n!==null){t.startDir=o,t.endDir=s,t.path=n;return}}let l=ot(Z(t.from),i),u=ot(Z(t.to),a),d=kt(e,l,u,nt(i)),f=kt(e,ot(Z(t.from),o),ot(Z(t.to),s),nt(o));if(d!==null&&f!==null){d.length<=f.length?(t.startDir=i,t.endDir=a,t.path=d):(t.startDir=o,t.endDir=s,t.path=f);return}if(d!==null){t.startDir=i,t.endDir=a,t.path=d;return}if(f!==null){t.startDir=o,t.endDir=s,t.path=f;return}t.startDir=i,t.endDir=a,t.path=un([l,u])}function an(e,t){return t.fanInCentered===!0&&!e.edges.some(e=>e.to===t&&e.clusterTarget)&&e.edges.some(e=>e.to===t&&e.text.length>0)}function on(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 sn(e,t,n,r){if(!on(e,r))return r;for(let i=1;i<=n-t;i++){let a=r+i;if(a<=n&&!on(e,a))return a;let o=r-i;if(o>=t&&!on(e,o))return o}return r}function cn(e){let t=new Map,n=new Map;for(let r of e.edges){for(let e of gt(un(r.path))){let n=`${e.x},${e.y}`,i=t.get(n);i?i.add(r):t.set(n,new Set([r]))}r.labelLine.length===2&&n.set(r,[r.labelLine[0],r.labelLine[1]])}return{cover:t,chosen:n}}function ln(e,t,n){if(t.text.length===0||t.parallelLane&&t.parallelLane.index>0||t.clusterSource&&e.clusterExitPlans?.get(t.clusterSource)?.edges.has(t))return;let r=N(t.text);if(an(e,t.to)&&(Y(t.endDir,q)||Y(t.endDir,J))&&t.path.length>=2&&t.path[0].x===t.path[1].x){dn(e,t,[t.path[0],t.path[1]],r);return}let i=un(t.path),a=i.length,o=[];for(let t=1;t<a;t++){let n=i[t-1],r=i[t],a=[n,r],s=pn(e,a),c=n.x===r.x;o.push({line:a,width:s,index:t,isVertical:c})}let s=t=>Zt(e,gt(t)),c=e=>e.index===1||e.index===o.length,l=o.filter(e=>e.width>=r&&!c(e)&&s(e.line)),u=new Set([t.path[0],t.path[t.path.length-1]].map(e=>e?`${e.x},${e.y}`:``)),d=e=>{if(!n)return[0,0];let r=gt(e),i=0;for(let e of r){let r=`${e.x},${e.y}`;if(u.has(r))continue;let a=n.cover.get(r);a&&[...a].some(e=>e!==t)&&i++}let a=new Set(r.map(e=>`${e.x},${e.y}`)),o=0;for(let[e,r]of n.chosen)e!==t&>(r).some(e=>a.has(`${e.x},${e.y}`))&&(o=1);return[o,i]},f=(e,t)=>{let n=d(e.line),r=d(t.line);return n[0]-r[0]||n[1]-r[1]||t.index-e.index},p;if(l.length>0)l.sort(f),p=l[0].line;else{let i=t=>{if(!n||!t.isVertical||on(e,t.line[0].x))return!1;let[r,i]=d(t.line);return r===0&&i===0},a=o.filter(e=>(e.width>=r||i(e))&&s(e.line));if(a.length>0)a.sort(f),p=a[0].line;else{let n=o.filter(e=>!c(e)&&s(e.line)),i=o.filter(e=>s(e.line)),a=n.length>0?n:i.length>0?i:o,l=t=>{let[n,i]=d(t.line),a=Math.min(t.line[0].x,t.line[1].x),o=Math.max(t.line[0].x,t.line[1].x),s=t.width<r;for(let t=a;s&&t<=o;t++)on(e,t)||(s=!1);return[n,i+(s?1e3:0)]};if(a.sort((e,t)=>{let n=l(e),r=l(t);return n[0]-r[0]||n[1]-r[1]||t.width-e.width}),a.length>0)p=a[0].line;else{let e=t.path[0]??{x:0,y:0};p=[e,e]}}}dn(e,t,p,r),n?.chosen.set(t,p)}function un(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 dn(e,t,n,r){let i=Math.min(n[0].x,n[1].x),a=Math.max(n[0].x,n[1].x),o=sn(e,i,a,i+Math.floor((a-i)/2)),s=fn(e,t,r);if(!(n[0].y===n[1].y&&on(e,o)&&s===0&&pn(e,n)>=r+2)){let t=e.columnWidth.get(o)??0;e.columnWidth.set(o,Math.max(t,r+2,s))}t.labelLine=[n[0],n[1]]}function fn(e,t,n){let r=t.from.gridCoord,i=t.to.gridCoord;if(!r||!i||r.x!==i.x||r.y===i.y)return 0;let a=e.edges.find(e=>e!==t&&e.from===t.to&&e.to===t.from);return a?2*(Math.max(n,N(a.text))+2):0}function pn(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}function mn(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||!hn(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:et,sharedNodeDir:et};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||!hn(a,e))continue;let i={type:`fan-out`,edges:[...a],sharedNode:r,otherNodes:a.map(e=>e.to),junctionPoint:null,sharedPath:[],junctionDir:et,sharedNodeDir:et};for(let e of a)e.bundle=i,n.add(e);t.push(i)}return t}function hn(e,t){if(e.length<2)return!1;let n=e[0].style,r=kr(t,e[0].from),i=kr(t,e[0].to);for(let a of e){if(a.style!==n||a.text.length>0)return!1;let e=kr(t,a.from),o=kr(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 gn(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 _n(e,t){let n=e.config.graphDirection;t.junctionPoint=gn(e,t);let r=t.junctionPoint;if(t.type===`fan-in`){t.junctionDir=n===`TD`?G:q,t.sharedNodeDir=n===`TD`?K:J;let i=Z(t.sharedNode),a=nt(n===`TD`?G:q),o=ot(i,a);t.sharedPath=kt(e,r,o,a)??[r,o];for(let i of t.edges){let o=Z(i.from),s=nt(n===`TD`?K:J),c=ot(o,s);i.pathToJunction=kt(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`?K:J,t.sharedNodeDir=n===`TD`?G:q;let i=Z(t.sharedNode),a=nt(n===`TD`?K:J),o=ot(i,a);t.sharedPath=kt(e,o,r,a)??[o,r];for(let i of t.edges){let o=Z(i.to),s=nt(n===`TD`?G:q),c=ot(o,s);i.pathToJunction=kt(e,r,c,s)??[r,c],i.startDir=a,i.endDir=s,i.path=[...t.sharedPath,...i.pathToJunction.slice(1)]}}}function vn(e){for(let t of e.bundles)_n(e,t)}function Q(e){return e.split(`
|
|
4
|
+
`)}function yn(e){let t=Q(e);return Math.max(...t.map(e=>N(e)),0)}function bn(e){return Q(e).length}function xn(e,t){let n=e.maxX-e.minX,r=e.maxY-e.minY;if(n<=0||r<=0)return P(0,0);let i={x:0,y:0},a={x:n,y:r},o=P(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}var Sn=new Set([`│`,`┃`,`║`,`┆`,`┊`,`|`,`:`,`‖`,`┼`,`╋`]);function Cn(e){return e!==void 0&&Sn.has(e)}function wn(e,t,n,r){let i=(t,i)=>{for(let a=t-i;a<t+e.length+i;a++)if(!(a<1||a>=n)&&r(a))return!0;return!1};if(!i(t,1))return t;let a=Math.max(1,n-e.length);for(let e of[1,0]){let n=-1;for(let r=1;r<=a;r++)i(r,e)||(n<0||Math.abs(r-t)<Math.abs(n-t))&&(n=r);if(n>=0)return n}return null}function Tn(e,t){return Math.max(1,1+Math.ceil((t-1-e.length)/2))}function En(e,t,n){let r=oe(e),i=wn(r,Tn(r,t),t,n);if(i===null||i+r.length>=t)return!1;for(let e=i-1;e<i+r.length+1;e++)if(e>=1&&e<t&&n(e))return!1;return!0}function Dn(e,t,n=()=>!1){let r=e.maxX-e.minX,i=e.maxY-e.minY;if(r<=0||i<=0)return[P(0,0),{x:0,y:0},[]];let a=P(r,i),o=[],s=Q(e.name);for(let e=0;e<s.length;e++){let t=s[e],c=1+e,l=1+Math.ceil((r-1-N(t))/2);l<1&&(l=1);let u=oe(t);l=wn(u,l,r,e=>n(e,c))??l;for(let e=0;e<u.length;e++)l+e>=r||c>=i||u[e]===` `&&n(l+e,c)||(R(a,l+e,c,u[e]),o.push({x:l+e,y:c}))}return[a,{x:e.minX,y:e.minY},o]}var On=16;function kn(e,t){return e.nodes.includes(t.from)||e.nodes.includes(t.to)}function An(e,t){let n=[],r=!1;for(let i of e.subgraphs){if(kn(i,t))continue;let a=At(i);if(a){r=!0;for(let t=a.minX;t<=a.maxX;t++)for(let r=a.minY;r<=a.maxY;r++){let i=X({x:t,y:r});e.grid.has(i)||(e.grid.add(i),n.push(i))}}}return{added:n,engaged:r}}function jn(e,t){for(let n of t)e.grid.delete(n)}function Mn(e,t,n){if(t.size===0)return!1;let r=e.config.graphDirection!==`LR`,i=r?e.columnWidth:e.rowHeight,a=!1;for(let o=0;o<On;o++){let o=Nn(e,t,r);if(!o)break;i.set(o.index,(i.get(o.index)??0)+o.by),a=!0,n()}return a}function Nn(e,t,n){for(let r of t){let t=r.path;for(let r=1;r<t.length;r++){let i=t[r-1],a=t[r];if(n?i.x!==a.x||i.y===a.y:i.y!==a.y||i.x===a.x)continue;let o=n?i.x:i.y,s=n?$(e,i).x:$(e,i).y,c=n?$(e,i).y:$(e,i).x,l=n?$(e,a).y:$(e,a).x,u=Math.min(c,l),d=Math.max(c,l);for(let t of e.subgraphs){let e=At(t);if(!e)continue;let r=n?t.minX:t.minY,i=n?t.maxX:t.maxY,a=n?t.minY:t.minX,c=n?t.maxY:t.maxX;if(d<=a||u>=c)continue;let l=n?e.minX:e.minY,f=n?e.maxX:e.maxY;if(o>f){if(s>i+1)continue;let e=i+2-s;return o-1>f?{index:o-1,by:e}:{index:o,by:2*e}}if(o<l){if(s<r-1)continue;let e=s+2-r;return o+1<l?{index:o+1,by:e}:{index:o,by:2*e}}}}}return null}var Pn=4;function Fn(e,t){if(e.config.graphDirection===`LR`)return;let n=new Set;for(let r=0;r<e.subgraphs.length;r++){let r=e.subgraphs.find(t=>t.nodes.length>0&&!n.has(t)&&Ln(e,t));if(!r)return;let i=In(r)+Pn;for(let a=1;a<=i&&(r.titleRoom=a,t(),Ln(e,r));a++)a===i&&(r.titleRoom=0,t(),n.add(r))}}function In(e){return Math.max(0,...Q(e.name).map(e=>N(e)))}function Ln(e,t){let n=t.maxX-t.minX,r=Q(t.name);for(let i=0;i<r.length;i++){let a=t.minY+1+i,o=new Set;for(let n of e.edges)for(let r=1;r<n.path.length;r++){let i=n.path[r-1],s=n.path[r];if(i.x!==s.x||i.y===s.y)continue;let c=$(e,i),l=$(e,s);a<Math.min(c.y,l.y)||a>Math.max(c.y,l.y)||c.x>t.minX&&c.x<t.maxX&&o.add(c.x-t.minX)}if(o.size!==0&&!En(r[i],n,e=>o.has(e)))return!0}return!1}function Rn(){return new Map}function zn(e,t,n,r){for(let i of gt(n)){if(dt(e,i))continue;let n=t.get(X(i));if(n!==void 0&&n!==r)return i}return null}function Bn(e,t,n,r){for(let i of gt(n)){if(dt(e,i))continue;let n=X(i);t.has(n)||t.set(n,r)}}function Vn(){return new Map}function Hn(e,t){return e.to===t.from||t.to===e.from}function Un(e){return e.from===e.to||e.path.length<2||e.bundle!==void 0||e.parallelLane!==void 0||e.style===`invisible`||e.clusterSource!==void 0||e.clusterTarget!==void 0}function Wn(e,t,n){let r=new Set;if(Un(e)||Un(t))return r;let i=e.from===t.to&&e.to===t.from,a=(e,t)=>e!==void 0&&t!==void 0&&e.x===t.x&&e.y===t.y,o=e=>new Set(gt(e).map(X)),s=(e,t)=>{let n=o(t);for(let t of o(e))n.has(t)&&r.add(t)},c=e.path;if(c.length<2||n.length<2)return r;let l=e=>[e[0],e[1]],u=e=>[e[e.length-2],e[e.length-1]];return e.from===t.to&&a(c[0],n[n.length-1])&&(i||!a(c[1],n[n.length-2]))&&s(l(c),u(n)),e.to===t.from&&a(c[c.length-1],n[0])&&(i||!a(c[c.length-2],n[1]))&&s(u(c),l(n)),r}var Gn=2;function Kn(e,t){return t(e)?1:Gn}function qn(e,t,n,r,i=()=>!1){let a=new Map,o=new Map,s=new Map,c=e=>{let t=s.get(e);return t||(t=Wn(e,r,n),s.set(e,t)),t};for(let i of gt(n)){if(dt(e,i))continue;let n=t.get(X(i));if(n!==void 0)for(let e of n)e!==r&&Hn(e,r)&&(c(e).has(X(i))||(a.set(e,(a.get(e)??0)+1),o.has(e)||o.set(e,i)))}for(let[e,t]of a)if(t>=Kn(e,i))return o.get(e);return null}function Jn(e,t,n,r){for(let i of gt(n)){if(dt(e,i))continue;let n=X(i),a=t.get(n);a===void 0&&(a=new Set,t.set(n,a)),a.add(r)}}var Yn={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 Xn(e,t){let n=Yn[e]??Yn.rectangle;return t?n.ascii:n.unicode}function Zn(e,t){let n=Q(e),r=Math.max(...n.map(e=>N(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 Qn(e,t,n,r){let{width:i,height:a}=t,o=P(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(N(t)/2)+1,r=oe(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 $n(e,t,n){let{width:r,height:i}=t,a=n.x+Math.floor(r/2),o=n.y+Math.floor(i/2);return Y(e,G)?{x:a,y:n.y}:Y(e,K)?{x:a,y:n.y+i-1}:Y(e,q)?{x:n.x,y:o}:Y(e,J)?{x:n.x+r-1,y:o}:Y(e,Ze)?{x:n.x,y:n.y}:Y(e,Xe)?{x:n.x+r-1,y:n.y}:Y(e,$e)?{x:n.x,y:n.y+i-1}:Y(e,Qe)?{x:n.x+r-1,y:n.y+i-1}:{x:a,y:o}}var er={getDimensions:Zn,render(e,t,n){return Qn(e,t,Xn(`rectangle`,n.useAscii),n.useAscii)},getAttachmentPoint:$n},tr={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=P(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 Y(e,G)?{x:a,y:n.y}:Y(e,K)?{x:a,y:n.y+i-1}:Y(e,q)?{x:n.x,y:o}:Y(e,J)?{x:n.x+r-1,y:o}:{x:a,y:o}}},nr={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=P(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 Y(e,G)?{x:a,y:n.y}:Y(e,K)?{x:a,y:n.y+i-1}:Y(e,q)?{x:n.x,y:o}:Y(e,J)?{x:n.x+r-1,y:o}:{x:a,y:o}}},rr={getDimensions(e,t){let n=Q(e),r=Math.max(...n.map(e=>N(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=P(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(N(t)/2),o=oe(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:$n},ir={getDimensions(e,t){let n=Q(e),r=Math.max(...n.map(e=>N(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=P(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(N(t)/2),o=oe(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:$n},ar={getDimensions:Zn,render(e,t,n){return Qn(e,t,Xn(`doublecircle`,n.useAscii),n.useAscii)},getAttachmentPoint:$n},or={getDimensions(e,t){let n=Q(e),r=Math.max(...n.map(e=>N(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=P(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(N(t)/2),o=oe(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:$n},sr={getDimensions:Zn,render(e,t,n){return Qn(e,t,Xn(`asymmetric`,n.useAscii),n.useAscii)},getAttachmentPoint:$n},cr={getDimensions:Zn,render(e,t,n){return Qn(e,t,Xn(`trapezoid`,n.useAscii),n.useAscii)},getAttachmentPoint:$n},lr={getDimensions:Zn,render(e,t,n){return Qn(e,t,Xn(`trapezoid-alt`,n.useAscii),n.useAscii)},getAttachmentPoint:$n},ur={getDimensions:Zn,render(e,t,n){return Qn(e,t,Xn(`parallelogram`,n.useAscii),n.useAscii)},getAttachmentPoint:$n},dr={getDimensions:Zn,render(e,t,n){return Qn(e,t,Xn(`parallelogram-alt`,n.useAscii),n.useAscii)},getAttachmentPoint:$n};function fr(e){return{getDimensions:Zn,render(t,n,r){return Qn(t,n,Xn(e,r.useAscii),r.useAscii)},getAttachmentPoint:$n}}var pr=fr(`circle`),mr=fr(`diamond`),hr=fr(`rounded`),gr=fr(`hexagon`),_r=new Map([[`rectangle`,er],[`rounded`,hr],[`diamond`,mr],[`stadium`,rr],[`circle`,pr],[`subroutine`,ir],[`doublecircle`,ar],[`hexagon`,gr],[`cylinder`,or],[`asymmetric`,sr],[`trapezoid`,cr],[`trapezoid-alt`,lr],[`parallelogram`,ur],[`parallelogram-alt`,dr],[`state-start`,tr],[`state-end`,nr]]);function vr(e){return _r.get(e)??er}function yr(e,t,n){return vr(e).getDimensions(t,n)}function br(e,t,n,r){return vr(e).getAttachmentPoint(t,n,r)}function $(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 xr(e,t){return t.map(t=>$(e,t))}function Sr(e,t,n,r){let i=r??Pr(e,t);return pt(e.grid,n,3)?(mt(e.grid,n,3),t.gridCoord=n,n):i===`LR`?Sr(e,t,{x:n.x,y:n.y+4},i):Sr(e,t,{x:n.x+4,y:n.y},i)}function Cr(e,t,n,r=new Set){let i=t.gridCoord;if(!i||r.has(t))return!1;r.add(t);let a=new Set;for(let n of e.edges)n.to===t&&n.from!==t&&a.add(n.from);for(let t of a){let o=t.gridCoord;if(o&&(a.size>1&&o[n]+1===i[n]-1||o[n]===i[n]&&Cr(e,t,n,r)))return!0}for(let r of e.edges){let a=r.from===t&&r.to!==t?r.to.gridCoord:null;if(!a||a[n]+1!==i[n]-1)continue;let o=new Set;for(let t of e.edges)t.to===r.to&&t.from!==r.to&&o.add(t.from);if(o.size>1)return!0}return!1}function wr(e,t){let n=Z(t),r=e.config.boxBorderPadding,i=yr(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&&!Cr(e,t,`x`)){let t=e.columnWidth.get(n.x-1)??0;e.columnWidth.set(n.x-1,Math.max(t,e.config.paddingX))}let s=e.config.graphDirection===`LR`&&e.nodes.some(e=>{let r=e.gridCoord;return e!==t&&r!==null&&r.y<=n.y-1&&n.y-1<=r.y+2&&r.x!==n.x});if(n.y>0&&!s&&!Cr(e,t,`y`)){let r=e.config.paddingY;Fr(e,t)&&(r+=4);let i=e.rowHeight.get(n.y-1)??0;e.rowHeight.set(n.y-1,Math.max(i,r))}}function Tr(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 Er=8;function Dr(e,t,n,r,i){let a=[];e.preferStraightRoutes=!0;try{for(let o=0;o<Er;o++){let o=zn(i,n,t.path,t.style)??qn(i,r,t.path,t,t=>t.clusterSource!==void 0&&e.clusterExitPlans?.get(t.clusterSource)?.edges.has(t)===!0);if(!o)return;e.grid.add(X(o)),a.push(o),rn(e,t)}}finally{e.preferStraightRoutes=!1;for(let t of a)e.grid.delete(X(t))}}function Or(e,t){return e.subgraphs.some(e=>e.nodes.includes(t))}function kr(e,t){let n=null;for(let r of e.subgraphs)r.nodes.includes(t)&&(!n||Ar(n,r))&&(n=r);return n}function Ar(e,t){let n=t;for(;n!==null;){if(n===e)return!0;n=n.parent}return!1}function jr(e,t){let n=kr(e,t);if(!n)return null;let r=n;for(;r.parent;)r=r.parent;return r}function Mr(e){let t=[...e.nodes];for(let n of e.children)t.push(...Mr(n));return t}function Nr(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 fi(e,t)){if(a===n)return!0;r.has(a)||(r.add(a),i.push(a))}}return!1}function Pr(e,t){let n=kr(e,t);return n?.direction?n.direction:e.config.graphDirection}function Fr(e,t){let n=kr(e,t);if(!n)return!1;let r=!1;for(let i of e.edges)if(i.to===t&&kr(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&&kr(e,t.from)!==n){a=!0;break}if(a&&r.gridCoord.y<i)return!1}return!0}function Ir(e,t){if(t.nodes.length===0)return;let n=1e6,r=1e6,i=-1e6,a=-1e6;for(let o of t.children)Ir(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=>N(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}let l=t.titleRoom??0;l>0&&(t.maxX+=l)}function Lr(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 Rr(e){return Math.max(0,...Q(e.name).map(e=>N(e)))+1}function zr(e){let t=null;for(let n of Mr(e)){let e=n.gridCoord;e&&(t=t?{minX:Math.min(t.minX,e.x),minY:Math.min(t.minY,e.y),maxX:Math.max(t.maxX,e.x+2),maxY:Math.max(t.maxY,e.y+2)}:{minX:e.x,minY:e.y,maxX:e.x+2,maxY:e.y+2})}return t}function Br(e){let t=e.subgraphs.filter(e=>e.nodes.length>0),n=(e,t)=>Ar(e,t)||Ar(t,e),r=!1;for(let i=0;i<64;i++){for(let t of e.subgraphs)Ir(e,t);let i=!1;for(let a of t){for(let o of t){if(n(a,o)||!(a.minX<o.minX)||!(a.minY<o.maxY&&a.maxY>o.minY))continue;let t=a.maxX+2-o.minX;if(t<=0)continue;let s=a.parent===null&&o.parent===null,c=a.maxX+2,l=Mr(o).every(e=>!e.drawingCoord||e.drawingCoord.x>c);if(s&&l&&o.maxX-c>=Rr(o))continue;let u=zr(a),d=zr(o);if(!u||!d||u.maxX+1>=d.minX)continue;let f=u.maxX+1;e.columnWidth.set(f,(e.columnWidth.get(f)??0)+t);for(let t of e.nodes)t.drawingCoord=$(e,Z(t));i=!0,r=!0;break}if(i)break}if(!i)break}return Vr(e),r}function Vr(e){for(let t of e.subgraphs)Ir(e,t);Lr(e)}function Hr(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 Ur(e,t){let n=t=>{let n=fi(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 Wr(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 fi(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 Gr(e,t){return e.nodes.find(e=>e.gridCoord!==null&&e.gridCoord.x===t.x&&e.gridCoord.y===t.y)}function Kr(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(pt(e.grid,c,3))return c;let l=Gr(e,c);if(!l||jr(e,l)!==n)return null;o+=4}};return o(i)??o(i*-1)}function qr(e,t,n,r){let i=jr(e,t);if(!i)return;let a=n.get(i);if(!a)return;n.delete(i);let o=Z(t),s=Pr(e,t)===`LR`?`y`:`x`;for(let t of a){let n=Pr(e,t),a=Kr(e,o,i,s,1);Sr(e,e.nodes[t.index],a??o,n),r.add(t)}}function Jr(e,t){let n=e.config.boxBorderPadding;for(let r of e.edges){if(r.from!==t||!r.text)continue;let e=N(r.to.displayLabel)+2*n+2;if(Math.floor(e/2)<N(r.text)+2)return!1}return!0}function Yr(e,t){for(let n=0;n<3;n++)for(let r=0;r<3;r++)e.grid.delete(X({x:t.x+n,y:t.y+r}))}function Xr(e,t,n){let r=Z(t);Yr(e,r);let i=pt(e.grid,n,3)?n:r;return mt(e.grid,i,3),t.gridCoord=i,i===n}function Zr(e,t,n){let r=e.nodes.filter(e=>e.gridCoord!==null&&e.gridCoord.x>t);for(let t of r)Yr(e,Z(t));for(let t of r){let r=Z(t);t.gridCoord={x:r.x+n,y:r.y},mt(e.grid,t.gridCoord,3)}}function Qr(e){if(e.config.graphDirection!==`TD`||!e.edges.every(e=>{let t=e.from.gridCoord,n=e.to.gridCoord;return t!==null&&n!==null&&t.y<n.y}))return;let t=e.nodes.filter(e=>e.gridCoord!==null).sort((e,t)=>Z(t).y-Z(e).y);for(let n of t){let t=Z(n);if(Or(e,n))continue;let r=fi(e,n);if(r.length<1)continue;let i=!0;for(let a of r){let r=a.gridCoord;if(r===null||r.y!==t.y+4||Or(e,a)||e.edges.some(e=>e.to===a&&e.from!==n)){i=!1;break}}if(!i)continue;let a=r.map(e=>Z(e).x),o=(Math.min(...a)+Math.max(...a))/2;if(o%4!=0){if(o+2<=t.x)continue;if(Jr(e,n)){Xr(e,n,{x:o,y:t.y});continue}let i=new Set([n]),a=[...r];for(let t=a.pop();t;t=a.pop())i.has(t)||(i.add(t),a.push(...fi(e,t)));for(let t of e.edges)t.to===n&&i.add(t.from);if(e.nodes.some(e=>e.gridCoord!==null&&e.gridCoord.x>o&&!i.has(e)))continue;Zr(e,o,4),o+=2}o>t.x&&Xr(e,n,{x:o,y:t.y})}}function $r(e,t,n){let r=!1,i=new Set,a=new Set,o=!0;for(;o;){o=!1;let s=!1,c=t=>e.config.graphDirection===`LR`?t.gridCoord?.y??0:t.gridCoord?.x??0,l=e.nodes.filter(e=>e.gridCoord!==null).sort((e,t)=>c(e)-c(t));for(let c of l){let l=c.gridCoord;if(l===null)continue;let u=[...fi(e,c)].sort((t,n)=>di(e,t,n));for(let d of u){if(d.gridCoord!==null)continue;let u=ai(e,d);if(!r&&u.some(e=>e.gridCoord===null)){if(s=!0,!i.has(d)){i.add(d);let n=e.config.graphDirection===`LR`?l.x+4:l.y+4;t[n]=(t[n]??0)+4}continue}let f=kr(e,c),p=kr(e,d),m=f&&f===p&&f.direction?f.direction:e.config.graphDirection,h=m===`LR`?l.x+4:l.y+4;if(m===e.config.graphDirection){h=Math.max(h,n.get(d)??0);for(let e of u){let t=e.gridCoord;t&&(h=Math.max(h,m===`LR`?t.x+4:t.y+4))}}let g;if(m!==e.config.graphDirection)g=m===`LR`?l.y:l.x;else{let n=ti(e,d,h);g=Math.max(t[h]??0,n??0,ei(e,l,d,h,m===`LR`)),n!==void 0&&g===n&&(a.add(d),d.fanInCentered=!0)}let _=m===`LR`?{x:h,y:g}:{x:g,y:h};Sr(e,e.nodes[d.index],_,m),m===e.config.graphDirection&&(t[h]=g+4),o=!0}}!o&&s&&!r&&(r=!0,o=!0)}}function ei(e,t,n,r,i){let a=i?t.y:t.x,o=i?t.x:t.y,s=()=>e.nodes.some(t=>{let s=t.gridCoord;if(!s)return!1;let c=i?s.x:s.y;return(i?s.y:s.x)===a&&c>o&&c<r&&!fi(e,t).includes(n)});for(;s();)a+=4;return a}function ti(e,t,n){let r=e.config.graphDirection===`LR`,i=new Set,a=new Set,o=!1,s=!1;for(let c of e.edges){if(c.to!==t||c.from===t)continue;let e=c.from.gridCoord;!e||(r?e.x:e.y)>=n||(i.add(r?e.y:e.x),a.add(c.from),c.clusterTarget&&(o=!0),c.text!==``&&(s=!0))}if(i.size<2||s&&!o&&!ni(e,t,r)||!o&&e.edges.some(e=>e.from!==e.to&&e.to!==t&&a.has(e.from)))return;if(!o){let n=new Set;for(let r of e.edges)r.from===t&&r.to!==t&&n.add(r.to);if(n.size>1)return}if(!o&&e.edges.some(e=>{let i=e.to.gridCoord;return e.from===t&&e.to!==t&&i!==null&&(r?i.x:i.y)<=n}))return;let c=Math.min(...i),l=Math.max(...i);return Math.floor((c+l)/2)}function ni(e,t,n){return!n&&!ri(e,t)}function ri(e,t){let n=new Set(e.edges.filter(e=>e.to===t&&e.from!==t).map(e=>e.from)),r=new Set([t]),i=[t];for(let t=i.pop();t;t=i.pop())for(let a of e.edges)if(!(a.from!==t||r.has(a.to))){if(n.has(a.to))return!0;r.add(a.to),i.push(a.to)}return!1}function ii(e,t){let n=new Map,r=new Map,i=t=>{r.set(t,`open`);let a=[];for(let n of fi(e,t))n!==t&&r.get(n)!==`open`&&(a.push(n),r.has(n)||i(n));n.set(t,a),r.set(t,`done`)};for(let e of t)r.has(e)||i(e);let a=new Map,o=[...n.keys()].reverse();for(let e of o)a.set(e,0);for(let e of o){let t=(a.get(e)??0)+4;for(let r of n.get(e)??[])a.set(r,Math.max(a.get(r)??0,t))}return a}function ai(e,t){let n=[];for(let r of e.edges)r.to!==t||!r.clusterTarget||r.from===t||n.includes(r.from)||Mr(r.clusterTarget).includes(r.from)||n.push(r.from);return n}function oi(e,t,n,r){let i=new Set(e.edges.filter(e=>e.to===t&&e.from!==t).map(e=>e.from));if(i.size!==1)return;let[a]=[...i],o=a.gridCoord;if(!(!o||Or(e,a))&&!e.edges.some(e=>e.to===a||e.from===a&&e.to!==t)&&!(r?o.y===n.y:o.x===n.x)){for(let t=0;t<3;t++)for(let n=0;n<3;n++)e.grid.delete(X({x:o.x+t,y:o.y+n}));Sr(e,a,r?{x:o.x,y:n.y}:{x:n.x,y:o.y})}}function si(e){let t=e.config.graphDirection===`LR`;for(let n=0;n<e.nodes.length+1;n++){let n=!1;for(let r of e.subgraphs){let i=Mr(r),a=zr(r);if(a)for(let r of e.nodes){let o=r.gridCoord;if(!(!o||i.includes(r))&&!(o.x+2<a.minX||o.x>a.maxX||o.y+2<a.minY||o.y>a.maxY)){for(let t=0;t<3;t++)for(let n=0;n<3;n++)e.grid.delete(X({x:o.x+t,y:o.y+n}));oi(e,r,Sr(e,r,t?{x:o.x,y:a.maxY+2}:{x:a.maxX+2,y:o.y}),t),n=!0}}}if(!n)return}}function ci(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=Wr(e,e.nodes.filter(e=>!r.has(e.name))),a=ii(e,i),o=new Set(i),s=[],c=[];for(let t of i){let n=jr(e,t);n!==null&&Mr(n).some(n=>n!==t&&!o.has(n)&&!Nr(e,t,n))?s.push(t):c.push(t)}let l=Ur(e,c),u=new Map;for(let t of s){let n=jr(e,t),r=u.get(n);r?r.push(t):u.set(n,[t])}let d=new Set,f=!1,p=!1;for(let t of l)Or(e,t)?fi(e,t).length>0&&(p=!0):f=!0;let m=t===`LR`&&f&&p,h,g=[];m?(h=l.filter(t=>!Or(e,t)),g=l.filter(t=>Or(e,t))):h=l;for(let r of h){let i=t===`LR`?{x:0,y:n[0]??0}:{x:n[0]??0,y:0};Sr(e,e.nodes[r.index],i),n[0]=(n[0]??0)+4,qr(e,r,u,d)}if(m&&g.length>0)for(let r of g){let i=t===`LR`?{x:4,y:n[4]??0}:{x:n[4]??0,y:4};Sr(e,e.nodes[r.index],i),n[4]=(n[4]??0)+4,qr(e,r,u,d)}$r(e,n,a);for(let t of s){if(d.has(t))continue;let r=jr(e,t),i=Pr(e,t),a=Mr(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=Kr(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;Sr(e,e.nodes[t.index],o,i)}$r(e,n,a),Qr(e),si(e);for(let t of e.nodes)wr(e,t);e.pathBudget=Ct(),en(e),Pt(e),e.bundles=mn(e),vn(e);let _=Rn(),v=Vn(),y=ut(e.grid),b=new Set;for(let t of e.edges){if(t.bundle&&t.path.length>0){Tr(e,t.path),Bn(y,_,t.path,t.style),Jn(y,v,t.path,t);continue}let{added:n,engaged:r}=An(e,t);r&&b.add(t);let i=e.preferStraightRoutes;r&&(e.preferStraightRoutes=!0),rn(e,t),Dr(e,t,_,v,y),e.preferStraightRoutes=i,jn(e,n),Tr(e,t.path),Bn(y,_,t.path,t.style),Jn(y,v,t.path,t)}let x=cn(e);for(let t of e.edges)ln(e,t,x);for(let t of e.nodes)t.drawingCoord=$(e,Z(t)),t.drawing=Na(t,e);if(Vr(e),Br(e),Vt(e)){for(let t of e.nodes)t.drawingCoord=$(e,Z(t));Vr(e)}let S=()=>{for(let t of e.nodes)t.drawingCoord=$(e,Z(t));Vr(e)};Mn(e,b,S),Fn(e,()=>{S(),Mn(e,b,S)}),Br(e),Mn(e,b,S),Hr(e),Ee(e.canvas,e.columnWidth,e.rowHeight,e.offsetX,e.offsetY),H(e.roleCanvas,e.columnWidth,e.rowHeight,e.offsetX,e.offsetY)}function li(e,t){return e.edges.filter(e=>e.from.name===t.name)}function ui(e,t){let n=kr(e,t),r=[],i=n;for(;i!==null;)r.unshift(i),i=i.parent;return r}function di(e,t,n){let r=ui(e,t),i=ui(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 fi(e,t){return li(e,t).map(e=>e.to)}var pi=2,mi=(e,t)=>`${e.index}|${t.x},${t.y}`,hi=Un,gi=e=>e>0?1:e<0?-1:0;function _i(e){let t=e.path,n=t.length-1,r=t[0],i=t[1];if(i.x===r.x&&i.y!==r.y){let a=1;for(;a+1<=n&&t[a+1].x===r.x;)a++;let o=t[a+1];return{axis:`v`,line:r.x,from:0,to:a,side:i.y>r.y?`bottom`:`top`,node:e.from,cell:r,turn:o?gi(o.x-r.x):0}}if(i.y===r.y&&i.x!==r.x){let a=1;for(;a+1<=n&&t[a+1].y===r.y;)a++;let o=t[a+1];return{axis:`h`,line:r.y,from:0,to:a,side:i.x>r.x?`right`:`left`,node:e.from,cell:r,turn:o?gi(o.y-r.y):0}}}function vi(e){let t=e.path,n=t.length-1,r=t[n],i=t[n-1];if(i.x===r.x&&i.y!==r.y){let a=n-1;for(;a-1>=0&&t[a-1].x===r.x;)a--;let o=t[a-1];return{axis:`v`,line:r.x,from:a,to:n,side:r.y>i.y?`top`:`bottom`,node:e.to,cell:r,turn:o?gi(r.x-o.x):0}}if(i.y===r.y&&i.x!==r.x){let a=n-1;for(;a-1>=0&&t[a-1].y===r.y;)a--;let o=t[a-1];return{axis:`h`,line:r.y,from:a,to:n,side:r.x>i.x?`left`:`right`,node:e.to,cell:r,turn:o?gi(r.y-o.y):0}}}function yi(e){let t=_i(e),n=vi(e);if(!t&&!n)return;let r=e.path.length-1,i={straight:t!==void 0&&n!==void 0&&t.to===r&&n.from===0};return t&&(i.start=t),n&&(i.end=n),i}function bi(e,t){let n=t.node,r=n.drawingCoord,i=n.drawing;if(!r||!i)return;let a=i.length,o=i[0]?.length??0,s=$(e,t.cell);if(t.axis===`v`)return a<3||o<1?void 0:{centre:s.x,lo:r.x+1,hi:r.x+a-2,border:t.side===`top`?0:o-1};if(!(o<3||a<1))return{centre:s.y,lo:r.y+1,hi:r.y+o-2,border:t.side===`left`?0:a-1}}function xi(e,t,n){if(t<n.lo||t>n.hi)return!1;let r=e.node.drawingCoord,i=e.node.drawing;if(e.axis===`v`){let e=i[t-r.x]?.[n.border];return e===`─`||e===`-`}let a=i[n.border]?.[t-r.y];return a===`│`||a===`|`}function Si(e,t){return e.axis===`v`?t===`S`==(e.side===`bottom`)?1:-1:e.turn===0?t===`S`==(e.side===`right`)?1:-1:e.side===`right`?-e.turn:e.turn}function Ci(e,t){let n=e.path[t.from],r=e.path[t.to];return t.axis===`v`?Math.abs(r.y-n.y):Math.abs(r.x-n.x)}function wi(e,t,n,r,i){for(let a of[`top`,`bottom`,`left`,`right`]){let o=t.filter(e=>e.run.side===a),s=o.some(e=>e.straight);for(let t of[-1,1]){let a=o.filter(e=>!e.straight&&e.run.turn===t),c=[...new Set(a.map(e=>Ci(e.edge,e.run)))];if(c.sort((e,t)=>t-e),c.length+ +!!s<2)continue;let l=e=>n+t*pi*(c.indexOf(e)+ +!!s),u=bi(e,a[0].run);if(u!==void 0&&c.every(e=>{let t=l(e);return xi(a[0].run,u.centre+t,u)&&r.every(e=>Math.abs(e-t)>=pi)}))for(let e of a)i.set(e.edge,l(Ci(e.edge,e.run)))}}}function Ti(e){return Ei.get(e)??Oi(e)}var Ei=new WeakMap;function Di(e,t){if(Ei.has(e))return t();Ei.set(e,Oi(e));try{return t()}finally{Ei.delete(e)}}function Oi(e){let t=new Map;if(e.edges.length<2)return t;let n=new Map,r=e=>{let t=e;for(;n.get(t)!==t;)t=n.get(t);return n.set(e,t),t},i=(e,t)=>{n.set(r(e),r(t))},a=new Map,o=new Map,s=new Map,c=(e,t,r,i,c)=>{let l=mi(e,t),u=`${l}|${r}`;n.has(u)||n.set(u,u),o.set(u,(o.get(u)??0)+1);let d=a.get(u);(!d||c&&!d.fixed)&&a.set(u,{run:i,role:r,fixed:c});let f=s.get(l)??new Set;return f.add(r),s.set(l,f),u},l=new Map,u=new Map;for(let t of e.edges){if(t.from===t.to||t.path.length<2)continue;if(hi(t)){let e=_i(t),n=vi(t);e&&c(t.from,t.path[0],`S`,e,!0),n&&c(t.to,t.path[t.path.length-1],`E`,n,!0);continue}let e=yi(t);if(!e)continue;let n={r:e};if(e.start){n.s=c(e.start.node,e.start.cell,`S`,e.start,!1);let r=u.get(n.s)??[];r.push({edge:t,run:e.start,straight:e.straight}),u.set(n.s,r)}e.end&&(n.e=c(e.end.node,e.end.cell,`E`,e.end,!1)),e.straight&&n.s&&n.e&&i(n.s,n.e),l.set(t,n)}let d=e=>e.slice(0,e.lastIndexOf(`|`)),f=e=>(s.get(e)?.size??0)>1,p=new Map;for(let e of a.keys()){let t=r(e),n=p.get(t);n?n.push(e):p.set(t,[e])}let m=new Set;for(let[t,{r:n,s:i,e:a}]of l){if(!n.straight||!i||!a)continue;let s=e.edges.find(e=>e!==t&&e.from===t.to&&e.to===t.from),c=s&&l.get(s);if(!c?.r.straight||!c.s||!c.e)continue;let u=[i,a,c.s,c.e],p=u.every(e=>o.get(e)===1),h=new Set(u.map(d));p&&h.size===2&&u.every(e=>f(d(e)))&&m.add(r(i))}let h=new Map;for(let[t,n]of p){if(m.has(t))continue;let r=n.map(e=>a.get(e));if(r.some(e=>e.fixed))continue;let i=n.map(d);if(!i.some(f))continue;let o=i.some(e=>[...a.entries()].some(([t,n])=>n.fixed&&t.startsWith(`${e}|`)))?pi:1,s=Si(r[0].run,r[0].role)*o;r.every(t=>{let n=bi(e,t.run);return n!==void 0&&xi(t.run,n.centre+s,n)})&&h.set(t,s)}let g=e=>({axis:e.axis,line:e.line,from:e.from,to:e.to}),_=e=>h.get(r(e))??0,v=new Map;for(let[t,n]of u){if(n.length<2||a.get(t).fixed)continue;let r=d(t),i=[...a.keys()].filter(e=>e!==t&&d(e)===r).map(_);wi(e,n,_(t),i,v)}for(let[e,{r:n,s:i,e:a}]of l){let o=v.get(e)??(i?_(i):0),s=a?h.get(r(a))??0:0;if(o===0&&s===0)continue;let c={start:o,end:s};n.start&&(c.startRun=g(n.start)),n.end&&(c.endRun=g(n.end)),t.set(e,c)}return t}function ki(e,t){let n=Ti(e).get(t);if(!n)return;let r=t.path.map(()=>({x:0,y:0}));for(let[e,t]of[[n.startRun,n.start],[n.endRun,n.end]])if(e)for(let n=e.from;n<=e.to;n++)e.axis===`v`?r[n].x=t:r[n].y=t;return r}function Ai(e,t){let n=xr(e,t.labelLine),r=Ti(e).get(t);if(!r)return n;let i=t.path;return n.map((e,n)=>{let a=t.labelLine[n],o=e.x,s=e.y,c=!1,l=!1;for(let[e,t]of[[r.startRun,r.start],[r.endRun,r.end]]){if(!e)continue;let n=i[e.from],r=i[e.to];e.axis===`v`?!c&&a.x===e.line&&a.y>=Math.min(n.y,r.y)&&a.y<=Math.max(n.y,r.y)&&(o+=t,c=!0):!l&&a.y===e.line&&a.x>=Math.min(n.x,r.x)&&a.x<=Math.max(n.x,r.x)&&(s+=t,l=!0)}return{x:o,y:s}})}function ji(e,t){let n=xr(e,t.path),r=ki(e,t);return r?n.map((e,t)=>({x:e.x+r[t].x,y:e.y+r[t].y})):n}var Mi={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 Ni(e,t,n,r,i,a,o=`solid`){let s=Gt(t,n),c=[],l=Mi[o],u=a?l.h.ascii:l.h.unicode,d=a?l.v.ascii:l.v.unicode;if(Y(s,G))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(Y(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(Y(s,q))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(Y(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(Y(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(Y(s,Xe)){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(Y(s,$e)){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(Y(s,Qe)){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 Pi(e,t){if(t.path.length===0){let t=F(e.canvas);return[t,t,t,t,t,t]}let n=ya(e,t),r=Ii(e,t),i=Li(e,t),a=r?Gi(e,t,r):zi(e,t,i),o=na(e,t),s=ki(e,t)??(o===0?void 0:t.path.map(()=>({x:o,y:0}))),[c,l,u]=Ki(e,t.path,t.style,r,a,s,i),d=l.length>0,f=t.style===`invisible`,p=d&&!f?Yi(e,t.path,l[0],t.from,i&&{x:i.x+na(e,t),y:i.y}):F(e.canvas),m;m=t.hasArrowEnd&&d?$i(e,l[l.length-1],u[u.length-1],t.endMarker):F(e.canvas);let h;if(t.hasArrowStart&&d){let n=l[0][0],r=Fi(u[0]),i={x:n.x,y:n.y};Y(u[0],J)?i.x=n.x-1:Y(u[0],q)?i.x=n.x+1:Y(u[0],K)?i.y=n.y-1:Y(u[0],G)&&(i.y=n.y+1),h=$i(e,[n,i],r,t.startMarker)}else h=F(e.canvas);let g=f?F(e.canvas):ea(e,t.path,a,s);return[c,p,m,h,g,n]}function Fi(e){return Y(e,G)?K:Y(e,K)?G:Y(e,q)?J:Y(e,J)?q:Y(e,Ze)?Qe:Y(e,Xe)?$e:Y(e,$e)?Xe:Y(e,Qe)?Ze:et}function Ii(e,t){let n=Bi(e,t),r=t.clusterTarget;if(!n||!r)return n;let i=Vi(e,r).get(t);return i===void 0?n:e.config.graphDirection===`LR`?{x:n.x,y:i}:{x:i,y:n.y}}function Li(e,t){let n=t.clusterSource;if(!n||e.clusterExitPlans?.get(n)?.edges.has(t)!==!0)return;let r=$(e,t.path[0]),i=Ri(e,n).get(t);return e.config.graphDirection===`LR`?{x:n.maxX,y:i??r.y}:{x:i??r.x,y:n.maxY}}function Ri(e,t){let n=new Map,r=e.clusterExitPlans?.get(t);if(!r)return n;let i=e.config.graphDirection===`LR`,a=new Map;for(let e of r.edges){let t=e.parallelLane?.usedOffsets??e,n=a.get(t);n?n.push(e):a.set(t,[e])}if(a.size<2)return n;let o=[...a.values()].map(t=>{let n=Z(t[0].to),r=$(e,i?{x:n.x,y:n.y+1}:{x:n.x+1,y:n.y});return{edges:t,want:i?r.y:r.x}}).sort((e,t)=>e.want-t.want),s=i?t.minY:t.minX,c=i?t.maxY:t.maxX,l;for(let e of[2,1]){let t=s+e,n=c-e,r=o.map(e=>Math.min(n,Math.max(t,e.want)));if(l=Wi(r,t,n,Hi)??Wi(r,t,n,Ui),l)break}return l&&o.forEach((e,t)=>{for(let r of e.edges)n.set(r,l[t])}),n}function zi(e,t,n){if(!n||t.path.length<2)return;let r=e.config.graphDirection===`LR`,i=t.path.map(t=>$(e,t)),a=i[0];if((r?a.y:a.x)===(r?n.y:n.x))return;let o=i[1],s=r?{x:o.x,y:n.y}:{x:n.x,y:o.y},c=i.slice(2),l=c[0],u=l&&l.x!==s.x&&l.y!==s.y?[r?{x:s.x,y:l.y}:{x:l.x,y:s.y}]:[];return{points:[n,s,...u,...c].filter((e,t,n)=>t===0||!at(e,n[t-1])),jog:[s,...u]}}function Bi(e,t){let n=t.clusterTarget,r=t.path[t.path.length-1],i=t.path[t.path.length-2];if(!t.clusterEntered||!n||!r||!i)return;let a=$(e,i),o=$(e,r);return e.config.graphDirection===`LR`?n.minX>a.x?{x:n.minX,y:o.y}:void 0:n.minY>a.y?{x:o.x,y:n.minY}:void 0}function Vi(e,t){let n=e.config.graphDirection===`LR`,r=[];for(let i of e.edges){if(i.clusterTarget!==t)continue;let a=Bi(e,i),o=i.path[0];if(!a||!o)continue;let s=$(e,o);r.push({edge:i,at:n?a.y:a.x,from:n?s.y:s.x})}let i=new Map;if(r.length<2)return i;r.sort((e,t)=>e.from-t.from);let a=r.map(e=>e.at);if(a.every((e,t)=>t===0||e-a[t-1]>=2))return i;let o=n?t.minY+1:t.minX+1,s=n?t.maxY-1:t.maxX-1,c=Wi(a,o,s,Hi)??Wi(a,o,s,Ui);if(!c)return i;let l=e=>(e[0]+e[e.length-1])/2,u=Math.round(l(r.map(e=>e.from))-l(c)),d=Math.max(o-c[0],Math.min(s-c.at(-1),u));return r.forEach((e,t)=>i.set(e.edge,c[t]+d)),i}var Hi=3,Ui=2;function Wi(e,t,n,r){let i=[...e];for(let e=0;e<i.length;e++)i[e]=Math.max(i[e],e===0?t:i[e-1]+r);for(let e=i.length-1;e>=0;e--)i[e]=Math.min(i[e],e===i.length-1?n:i[e+1]-r);return i[0]<t?void 0:i}function Gi(e,t,n){let r=t.path[t.path.length-1];if(!r||t.path.length<2)return;let i=e.config.graphDirection===`LR`,a=$(e,r),o=$(e,t.path[0]),s=i?Math.min(a.x,n.x-2):Math.min(a.y,n.y-2);if(s<=(i?o.x:o.y))return;let c=i?r.x:r.y,l=t.path.findIndex(e=>(i?e.x:e.y)===c);if(l<1)return;let u=$(e,t.path[l]),d=i?n.y:n.x;if((i?u.y:u.x)===d)return;let f=t.path.slice(0,l).map(t=>$(e,t)),p=i?{x:s,y:u.y}:{x:u.x,y:s},m=i?{x:s,y:d}:{x:d,y:s};return f.push(p,m,n),{points:f,jog:[p,m]}}function Ki(e,t,n=`solid`,r,i,a,o){let s=F(e.canvas),c=t[0],l=[],u=[],d=(e,t)=>{let n=a?.[t];return n===void 0||n.x===0&&n.y===0?e:{x:e.x+n.x,y:e.y+n.y}};if(i){for(let t=1;t<i.points.length;t++){let r=i.points[t-1],a=i.points[t];if(at(r,a))continue;let o=Ni(s,r,a,1,-1,e.config.useAscii,n);o.length===0&&o.push(r),l.push(o),u.push(Gt(r,a))}return[s,l,u]}for(let i=1;i<t.length;i++){let a=t[i],f=d(o&&i===1?o:$(e,c),i-1),p=r&&i===t.length-1?d(r,i):d($(e,a),i);if(at(f,p)){c=a;continue}let m=Gt(c,a),h=Ni(s,f,p,1,-1,e.config.useAscii,n);h.length===0&&h.push(f),l.push(h),u.push(m),c=a}return[s,l,u]}var qi=new Set([`│`,`┃`,`║`,`┆`,`┊`,`|`,`‖`]),Ji=new Set([`─`,`━`,`═`,`╌`,`┄`,`-`,`=`]);function Yi(e,t,n,r,i){let a=F(e.canvas),o=e.config.useAscii;if(!i&&(r.shape===`state-start`||r.shape===`state-end`))return a;let s=n[0],c=Gt(t[0],t[1]),l=o?`+`:null,u=(t,n)=>e.canvas[t]?.[n];if(i){let e=Y(c,K)?`┬`:`├`;R(a,i.x,i.y,l??e)}else if(Y(c,G)){let e=s.x,t=s.y+1,n=u(e,t);R(a,e,t,n!==void 0&&Ji.has(n)?l??`┴`:o?`|`:`│`)}else if(Y(c,K)){let e=s.x,t=s.y-1,n=u(e,t);R(a,e,t,n!==void 0&&Ji.has(n)?l??`┬`:o?`|`:`│`)}else if(Y(c,q)||Y(c,J)){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,i=Y(c,q)?e.x:e.x+n-1,d=s.y,f=u(i,d);R(a,i,d,f!==void 0&&qi.has(f)?l??(Y(c,q)?`┤`:`├`):o?`-`:`─`)}return a}function Xi(e,t){if(t===`circle`)return e?`o`:`○`;if(t===`cross`)return e?`x`:`✕`}function Zi(e){if(Y(e,G))return`▲`;if(Y(e,K))return`▼`;if(Y(e,q))return`◄`;if(Y(e,J))return`►`;if(Y(e,Xe))return`↗`;if(Y(e,Ze))return`↖`;if(Y(e,Qe))return`↘`;if(Y(e,$e))return`↙`}function Qi(e){if(Y(e,G))return`^`;if(Y(e,K))return`v`;if(Y(e,q))return`<`;if(Y(e,J))return`>`}function $i(e,t,n,r){let i=F(e.canvas);if(t.length===0)return i;let a=t[t.length-1],o=Gt(t.length>=2?t[t.length-2]:t[0],a);(t.length===1||Y(o,et))&&(o=n);let s=Xi(e.config.useAscii,r),c;if(s!==void 0)c=s;else if(e.config.useAscii){let e=Qi(o);c=e===void 0?Qi(n)??`*`:e}else{let e=Zi(o);c=e===void 0?Zi(n)??`●`:e}return R(i,a.x,a.y,c),i}function ea(e,t,n,r){let i=F(e.canvas),a=n?n.points:t;for(let o=1;o<a.length-1;o++){let s=a[o],c=n?n.points[o]:$(e,t[o]),l=r?.[o],u=l?{x:c.x+l.x,y:c.y+l.y}:c,d=Gt(a[o-1],s),f=Gt(s,a[o+1]),p;p=e.config.useAscii?Y(d,f)?Y(d,G)||Y(d,K)?`|`:`-`:`+`:Y(d,f)?Y(d,G)||Y(d,K)?`│`:`─`:Y(d,J)&&Y(f,K)||Y(d,G)&&Y(f,q)?`┐`:Y(d,J)&&Y(f,G)||Y(d,K)&&Y(f,q)?`┘`:Y(d,q)&&Y(f,K)||Y(d,G)&&Y(f,J)?`┌`:Y(d,q)&&Y(f,G)||Y(d,K)&&Y(f,J)?`└`:`+`,R(i,u.x,u.y,p)}return i}function ta(e,t){return e.edges.some(e=>e!==t&&e.from===t.to&&e.to===t.from)}function na(e,t){return ra(e,t,!0)}function ra(e,t,n){let r=ia(e,t);if(!r)return 0;let i=Ti(e);if(i.has(t)||i.has(r))return 0;for(let i of[t,r]){if(i.text.length===0)continue;let t=i.path[1].y>i.path[0].y?`right`:`left`;if(!ua(e,i,la(sa(e,i,n),$(e,i.path[0]).x+(t===`right`?1:-1),t),n))return 0}return t.path[1].y>t.path[0].y?1:-1}function ia(e,t){if(t.from===t.to||t.path.length!==2)return;let n=e.edges.find(e=>e!==t&&e.from===t.to&&e.to===t.from);if(!n||n.path.length!==2||ca(e,t)||ca(e,n))return;let[r,i]=t.path,[a,o]=n.path;if(r.x===i.x&&a.x===o.x&&r.x===a.x&&r.y!==i.y&&i.y>r.y!=o.y>a.y){for(let e of[t.from,t.to])if(!e.drawing||e.drawing.length<5)return;return n}}function aa(e,t){return oa(e,t,!0)}function oa(e,t,n){if(t.text.length===0)return null;let r=sa(e,t,n),i=ra(e,t,n);return i===0?r:la(r,$(e,t.path[0]).x+i,i>0?`right`:`left`)}function sa(e,t,n){let r=ma(e,t,Ai(e,t)),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=ta(e,t)||e.config.graphDirection!==`LR`&&t.clusterSource!==void 0&&e.clusterExitPlans?.get(t.clusterSource)?.edges.has(t)===!0,o=_a(e,t,ga(e,va(e,xa(r,t.text,i,a),r[0]?.x===r[1]?.x?r[0]?.x:void 0),r));if(i!==void 0&&r.length>=2&&r[0].x===r[1].x&&!ca(e,t)){let a=la(o,r[0].x,i?`left`:`right`);if(ua(e,t,a,n)){let i=Math.min(r[0].y,r[1].y)+1,o=Math.max(r[0].y,r[1].y)-1,s=a.map(e=>e.y),c=Math.max(...s)-Math.min(...s);for(let r of[2,1]){if(ua(e,t,a,n,r))return a;for(let s=1;s<=o-i;s++)for(let l of[s,-s]){let s=a.map(e=>({...e,y:e.y+l})),u=Math.min(...s.map(e=>e.y));if(!(u<i||u+c>o)&&ua(e,t,s,n,r))return s}}return a}}return o}function ca(e,t){return t.clusterSource!==void 0&&e.clusterExitPlans?.get(t.clusterSource)?.edges.has(t)===!0}function la(e,t,n){return e.map(e=>({...e,x:n===`right`?t+2:t-1-N(e.text)}))}function ua(e,t,n,r,i=0){return pa(e,t,n,i)&&(!r||!da(e,t,n))}function da(e,t,n){let r=fa(e,t);return n.some(e=>r.some(t=>e.y===t.y&&e.x<=t.x+N(t.text)-1&&t.x<=e.x+N(e.text)-1))}function fa(e,t){let n=[];for(let r of e.edges)r===t||r.path.length<2||n.push(...oa(e,r,!1)??[]);return n}function pa(e,t,n,r=0){for(let{x:i,y:a,text:o}of n){let n=i,s=i+N(o)-1;if(n<0)return!1;for(let t of e.nodes){if(!t.drawingCoord||!t.drawing)continue;let e=t.drawingCoord.x,r=t.drawingCoord.y;if(s>=e&&n<e+t.drawing.length&&a>=r&&a<r+(t.drawing[0]?.length??0))return!1}for(let t of e.subgraphs){if(t.nodes.length===0)continue;let e=Q(t.name).length,r=a>=t.minY&&a<=t.maxY,i=[t.minX,t.maxX].some(e=>e>=n&&e<=s);if(r&&i||(a===t.maxY||a>=t.minY&&a<=t.minY+e)&&s>=t.minX&&n<=t.maxX)return!1}for(let i of e.edges){if(i===t)continue;let o=ji(e,i);for(let e=1;e<o.length;e++){let t=o[e-1],i=o[e];if(a>=Math.min(t.y,i.y)-r&&a<=Math.max(t.y,i.y)+r&&s>=Math.min(t.x,i.x)-r&&n<=Math.max(t.x,i.x)+r)return!1}}}return!0}function ma(e,t,n){let r=Ii(e,t),i=r?Gi(e,t,r):void 0,a=t.path[t.path.length-1];if(!r&&n.length>=2)return ha(e,t,n);if(!i||!a||n.length<2)return n;let o=$(e,a),s=e.config.graphDirection===`LR`;return n.every(e=>s?e.x===o.x:e.y===o.y)?i.jog:n}function ha(e,t,n){let r=zi(e,t,Li(e,t));if(!r)return n;let i=e.config.graphDirection===`LR`,a=$(e,t.path[0]),o=r.jog[0];return n.every(e=>i?e.x===o.x:e.y===o.y)?n.map(e=>(i?e.y===a.y:e.x===a.x)?i?{x:e.x,y:o.y}:{x:o.x,y:e.y}:e):n}function ga(e,t,n){if(n.length<2||e.subgraphs.length===0)return t;let r=Math.min(n[0].y,n[1].y),i=Math.max(n[0].y,n[1].y),a=(t,n)=>e.subgraphs.some(e=>{if(e.nodes.length===0)return!1;let r=Q(e.name).length;return n>=e.minY&&n<=e.minY+r&&t.x<=e.maxX&&t.x+N(t.text)-1>=e.minX});return t.map(e=>{if(!a(e,e.y))return e;let t=null;for(let n=r+1;n<i;n++)a(e,n)||(t===null||Math.abs(n-e.y)<Math.abs(t-e.y))&&(t=n);return t===null?e:{...e,y:t}})}function _a(e,t,n){let r=t.clusterSource?e.clusterExitPlans?.get(t.clusterSource):void 0;if(e.config.graphDirection!==`LR`||!r?.edges.has(t)||!t.parallelLane||t.parallelLane.index===0)return n;let i=$(e,r.gutter).x+2;return n.map(e=>e.x<i?{...e,x:i}:e)}function va(e,t,n){return n===void 0?t:t.map(t=>{let r=N(t.text),{x:i}=t;for(let a of e.subgraphs)if(!(t.y<=a.minY||t.y>=a.maxY))for(let e of[a.minX,a.maxX])e<i||e>=i+r||n===e||(i=n>e?e+1:e-r);return i===t.x?t:{...t,x:i}})}function ya(e,t){let n=F(e.canvas);for(let{x:r,y:i,text:a}of aa(e,t)??[])Te(n,{x:r,y:i},a);return n}function ba(e,t){let n=[];for(let{x:r,y:i,text:a}of aa(e,t)??[]){let e=oe(a),t=e.findIndex(e=>e!==` `),o=e.findLastIndex(e=>e!==` `);for(let a=t+1;a<o;a++)e[a]===` `&&n.push({x:r+a,y:i})}return n}function xa(e,t,n,r=!1){if(e.length<2)return[];let i=Math.min(e[0].x,e[1].x),a=Math.max(e[0].x,e[1].x),o=Math.min(e[0].y,e[1].y),s=Math.max(e[0].y,e[1].y),c=i+Math.floor((a-i)/2),l=o+Math.floor((s-o)/2);if(n!==void 0&&i===a){let e=s-o,t=Math.max(1,Math.floor(e/4));(r?n:!n)?l-=t:l+=t}let u=Q(t),d=l-Math.floor((u.length-1)/2);return u.map((e,t)=>({x:c-Math.floor(N(e)/2),y:d+t,text:e}))}function Sa(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 br(t.shape,n,o,s)}function Ca(e,t,n){let r=F(e.canvas),i=t.pathToJunction;if(!i||i.length===0)return[r,r,r,r,r,r];let a=F(e.canvas),o=e.config.useAscii,s=i.map((r,a)=>n.type===`fan-in`&&a===0?Sa(e,t.from,t.startDir):n.type===`fan-out`&&a===i.length-1?Sa(e,t.to,t.endDir):$(e,r));for(let e=1;e<s.length;e++){let n=s[e-1],r=s[e];at(n,r)||Ni(a,n,r,1,-1,o,t.style)}let c=F(e.canvas);for(let t=1;t<i.length-1;t++){let n=i[t],r=$(e,n),a=Gt(i[t-1],n),s=Gt(n,i[t+1]),l;l=o?`+`:Y(a,J)&&Y(s,K)||Y(a,G)&&Y(s,q)?`┐`:Y(a,J)&&Y(s,G)||Y(a,K)&&Y(s,q)?`┘`:Y(a,q)&&Y(s,K)||Y(a,G)&&Y(s,J)?`┌`:Y(a,q)&&Y(s,G)||Y(a,K)&&Y(s,J)?`└`:`+`,R(c,r.x,r.y,l)}let l=F(e.canvas);if(n.type===`fan-in`&&i.length>=2){let e=s[0],t=Gt(i[0],i[1]),n=o?`+`:null;Y(t,G)?R(l,e.x,e.y,n??`┴`):Y(t,K)?R(l,e.x,e.y,n??`┬`):Y(t,q)?R(l,e.x,e.y,n??`┤`):Y(t,J)&&R(l,e.x,e.y,n??`├`)}return[a,l,r,r,c,F(e.canvas)]}function wa(e,t){let n=F(e.canvas),r=F(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`?G:q;return Sa(e,t.sharedNode,n)}if(t.type===`fan-out`&&r===0){let n=o===`TD`?K:J;return Sa(e,t.sharedNode,n)}return $(e,n)});for(let e=1;e<s.length;e++){let t=s[e-1],r=s[e];at(t,r)||Ni(n,t,r,1,-1,i,a)}for(let n=1;n<t.sharedPath.length-1;n++){let a=t.sharedPath[n],o=$(e,a),s=Gt(t.sharedPath[n-1],a),c=Gt(a,t.sharedPath[n+1]),l;l=i?`+`:Y(s,J)&&Y(c,K)||Y(s,G)&&Y(c,q)?`┐`:Y(s,J)&&Y(c,G)||Y(s,K)&&Y(c,q)?`┘`:Y(s,q)&&Y(c,K)||Y(s,G)&&Y(c,J)?`┌`:Y(s,q)&&Y(c,G)||Y(s,K)&&Y(c,J)?`└`:`+`,R(r,o.x,o.y,l)}return[n,r]}function Ta(e,t){let n=F(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=Gt(i,a),s=e.config.graphDirection,c=s===`TD`?G:q,l=Sa(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=Xi(e.config.useAscii,d),p;return p=f===void 0?e.config.useAscii?Y(o,G)?`^`:Y(o,K)?`v`:Y(o,q)?`<`:Y(o,J)?`>`:`v`:Y(o,G)?`▲`:Y(o,K)?`▼`:Y(o,q)?`◄`:Y(o,J)?`►`:`▼`:f,R(n,l.x,l.y,p),n}function Ea(e,t){let n=F(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=Gt(i,a),s=e.config.graphDirection,c=s===`TD`?G:q,l=Sa(e,t.to,c);s===`TD`?--l.y:--l.x;let u=Xi(e.config.useAscii,t.endMarker),d;return d=u===void 0?e.config.useAscii?Y(o,G)?`^`:Y(o,K)?`v`:Y(o,q)?`<`:Y(o,J)?`>`:`v`:Y(o,G)?`▲`:Y(o,K)?`▼`:Y(o,q)?`◄`:Y(o,J)?`►`:`▼`:u,R(n,l.x,l.y,d),n}function Da(e){return Y(e,G)?K:Y(e,K)?G:Y(e,q)?J:Y(e,J)?q:e}function Oa(e,t){let n=F(e.canvas);if(t.sharedPath.length<2)return n;let r=t.sharedPath[0],i=t.sharedPath[1],a=Da(Gt(r,i)),o=e.config.graphDirection,s=o===`TD`?K:J,c=Sa(e,t.sharedNode,s);o===`TD`?c.y+=1:c.x+=1;let l;return l=e.config.useAscii?Y(a,G)?`^`:Y(a,K)?`v`:Y(a,q)?`<`:Y(a,J)?`>`:`^`:Y(a,G)?`▲`:Y(a,K)?`▼`:Y(a,q)?`◄`:Y(a,J)?`►`:`▲`,R(n,c.x,c.y,l),n}function ka(e,t){let n=F(e.canvas);if(!t.pathToJunction||t.pathToJunction.length<2)return n;let r=t.pathToJunction[0],i=t.pathToJunction[1],a=Da(Gt(r,i)),o=Sa(e,t.from,t.startDir);Y(t.startDir,G)?--o.y:Y(t.startDir,K)?o.y+=1:Y(t.startDir,q)?--o.x:Y(t.startDir,J)&&(o.x+=1);let s;return s=e.config.useAscii?Y(a,G)?`^`:Y(a,K)?`v`:Y(a,q)?`<`:Y(a,J)?`>`:`v`:Y(a,G)?`▲`:Y(a,K)?`▼`:Y(a,q)?`◄`:Y(a,J)?`►`:`▼`,R(n,o.x,o.y,s),n}function Aa(e,t){let n=F(e.canvas);if(!t.junctionPoint)return n;let r=$(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=Gt(t.sharedPath[e],t.sharedPath[n]);Y(r,K)?o=!0:Y(r,G)?a=!0:Y(r,J)?c=!0:Y(r,q)&&(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=Gt(e.pathToJunction[r],e.pathToJunction[n]);Y(i,K)?a=!0:Y(i,G)?o=!0:Y(i,J)?s=!0:Y(i,q)&&(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 ja(e,t){return Ma(e,t)}function Ma(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=P(Math.max(o.x,s.x),Math.max(o.y,s.y)),l=Xn(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);e.labelRows={top:g,bottom:g+h.length-1};for(let e=0;e<h.length;e++){let t=h[e],n=N(t),r=o.x+Math.floor(i/2)-Math.ceil(n/2)+1,a=oe(t);for(let t=0;t<a.length;t++)R(c,r+t,g+e,a[t])}return c}function Na(e,t){return ja(e,t)}function Pa(e){return/^[┌┐└┘├┤┬┴┼│─╭╮╰╯+\-|]$/.test(e)?`border`:`text`}function Fa(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,N(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 Ia(e,t,n=1){let r=Math.max(0,n),{width:i,height:a}=Fa(e,r),o=t?`-`:`─`,s=t?`|`:`│`,c=t?`+`:`┌`,l=t?`+`:`┐`,u=t?`+`:`└`,d=t?`+`:`┘`,f=t?`+`:`├`,p=t?`+`:`┤`,m=P(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=oe(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 La(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 Ra(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 za(e,t,n,r){for(let i of t)Ra(e,i,n,r)}function Ba(e){let t=null;for(let[n,r]of e.entries())for(let[e,i]of r.entries())i!==` `&&(t=t?{x0:Math.min(t.x0,n),x1:Math.max(t.x1,n),y0:Math.min(t.y0,e),y1:Math.max(t.y1,e)}:{x0:n,x1:n,y0:e,y1:e});return t}function Va(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 Ha(e){return Di(e,()=>Ua(e))}function Ua(e){let t=[];e.labelRects=t;let n=e.config.useAscii,r={x:0,y:0},i=La(e.subgraphs);for(let t of i){let r=xn(t,e),i={x:t.minX,y:t.minY};e.canvas=he(e.canvas,i,n,r),Ra(e.roleCanvas,r,i,`border`)}for(let r of e.nodes)if(!r.drawn&&r.drawingCoord&&r.drawing){if(e.canvas=he(e.canvas,r.drawingCoord,n,r.drawing),Va(e.roleCanvas,r.drawing,r.drawingCoord),r.labelRows){let{x:n,y:i}=r.drawingCoord,a={x0:n+1,x1:n+r.drawing.length-2,y0:i+r.labelRows.top,y1:i+r.labelRows.bottom};t.push(a);for(let t=a.x0;t<=a.x1;t++)for(let n=a.y0;n<=a.y1;n++){let r=e.canvas[t]?.[n];r&&r!==` `&&I(e.roleCanvas,t,n,`text`)}}r.drawn=!0}let a=[],o=[],s=[],c=[],l=[],u=[],d=[],f=new Set;for(let t of e.edges)if(t.bundle&&t.pathToJunction){let n=t.bundle,[r,i,,,p,m]=Ca(e,t,n);if(a.push(r),o.push(p),l.push(i),u.push(m),n.type===`fan-in`&&t.hasArrowStart){let n=ka(e,t);c.push(n)}if(!f.has(n)){f.add(n);let[t,r]=wa(e,n);if(a.push(t),o.push(r),n.type===`fan-in`){let t=Ta(e,n);s.push(t)}if(n.type===`fan-out`&&n.edges.every(e=>e.hasArrowStart)){let t=Oa(e,n);c.push(t)}let i=Aa(e,n);d.push(i)}if(n.type===`fan-out`&&t.hasArrowEnd){let n=Ea(e,t);s.push(n)}}else{let[n,r,i,d,f,p]=Pi(e,t);a.push(n),o.push(f),s.push(i),c.push(d),l.push(r),u.push(p)}let p=me(a);e.canvas=he(e.canvas,r,n,...p),za(e.roleCanvas,p,r,`line`),e.canvas=he(e.canvas,r,n,...o),za(e.roleCanvas,o,r,`corner`),e.canvas=he(e.canvas,r,n,...d),za(e.roleCanvas,d,r,`junction`),e.canvas=he(e.canvas,r,n,...s),za(e.roleCanvas,s,r,`arrow`),e.canvas=he(e.canvas,r,n,...l),za(e.roleCanvas,l,r,`junction`),e.canvas=he(e.canvas,r,n,...c),za(e.roleCanvas,c,r,`arrow`),e.canvas=he(e.canvas,r,n,...u),za(e.roleCanvas,u,r,`text`);for(let t of e.edges)if(!(t.bundle&&t.pathToJunction))for(let{x:n,y:r}of ba(e,t))R(e.canvas,n,r,` `),I(e.roleCanvas,n,r,`text`);for(let e of u){let n=Ba(e);n&&t.push(n)}for(let r of e.subgraphs){if(r.nodes.length===0)continue;let[i,a,o]=Dn(r,e,(t,n)=>Cn(e.canvas[t+r.minX]?.[n+r.minY])&&(e.canvas[t+r.minX]?.[n+r.minY+1]??` `)!==` `);e.canvas=he(e.canvas,a,n,i),Ra(e.roleCanvas,i,a,`text`);let s=Ba(i);s&&t.push({x0:s.x0+a.x,x1:s.x1+a.x,y0:s.y0+a.y,y1:s.y1+a.y});for(let{x:t,y:n}of o){let r=i[t]?.[n];r===` `&&(R(e.canvas,t+a.x,n+a.y,r),I(e.roleCanvas,t+a.x,n+a.y,`text`))}}return e.canvas}function Wa(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 Ga(e){let t=e.keys.length>0?` `+e.keys.join(`,`):``;return`${e.type} ${e.name}${t}`}function Ka(e){let t=Q(e.label),n=e.attributes.map(Ga);return n.length===0?[t]:[t,n]}function qa(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 Ja(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 Ya(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 Xa(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=rt(r.paddingX,5,6,6),u=rt(r.paddingY,5,4,2),d=rt(r.paddingY,5,2,1),f=Math.max(...[`one`,`zero-one`,`many`,`zero-many`].flatMap(e=>[qa(e,c,!1).length,qa(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=Ka(e);p.set(e.id,t);let{width:n,height:i}=Fa(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=yn(e.label);_.set(t,Math.max(_.get(t)??0,n))}let v=Ja(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=Ya(m,o.id,`box width`),c=Ya(h,o.id,`box height`);a>=n&&(b+=i+u,r=0,i=0,a=0),y.set(o.id,{entity:o,sections:Ya(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=P(x-1,S-1),w=se(x-1,S-1);function ee(e,t,n,r){R(C,e,t,n,{role:r,roleCanvas:w})}function T(e,t){let n=w[e]?.[t];return n===`text`||n===`border`}function E(e,t,n,r,i){for(let a=0;a<e.length;a++){let e=t+a;if(!(e<r||e>i)&&T(e,n))return!1}return!0}function te(e,t,n,r,i,a){for(let a=0;a<e.length;a++){let e=t+a;if(!(e<r||e>i)&&(T(e,n)||w[e]?.[n]===`arrow`||D.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`&&!pe.has(`${a},${n}`))return!1;return!0}for(let e of y.values()){let t=Ia(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&&ee(t,a,i,Pa(i))}}}let D=new Set;for(let e of y.values())for(let t=0;t<e.height;t++)for(let n=0;n<e.width;n++)D.add(`${e.x+n},${e.y+t}`);function O(e,t,n,r){D.has(`${e},${t}`)||(r===`text`||w[e]?.[t]!==`text`)&&(I(n)!==`dashed`||I(C[e]?.[t])!==`solid`)&&(ee(e,t,n,r),r===`line`&&pe.add(`${e},${t}`))}function k(e,t,n,r){w[e-1]?.[t]!==`text`&&w[e+1]?.[t]!==`text`&&O(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 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){for(let r of A)if(!(Math.abs(r.x-e)>1)&&t<=r.yEnd&&n>=r.yStart)return!0;return!1}function j(e,t,n){A.push({x:e,yStart:t,yEnd:n})}let M=c?`-`:`─`,ae=c?`|`:`│`,N=c?`.`:`╌`,F=c?`:`:`┊`;function I(e){if(e===M||e===ae)return`solid`;if(e===N||e===F)return`dashed`}function L(e,t){return c?`+`:e===`down`?t===`right`?`┌`:`┐`:t===`right`?`└`:`┘`}function z(e,t,n,r){O(e,t,L(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 pe=new Set;for(let e of s.relationships){pe=new Set;let t=y.get(e.entity1),n=y.get(e.entity2);if(!t||!n)continue;let r=e.identifying?M:N,i=e.identifying?ae:F,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=qa(d,c,!1),S=qa(p,c,!0),ee=+(v>=3&&x[0]===ae),T=+(v>=3&&S[S.length-1]===ae),te=m+ee,D=h-T,A;if(_===void 0){for(let e=m;e<=h;e++)k(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++;le(C,h+1,a+n+1),ce(w,h+1,a+n+1);for(let e=g;e<=a;e++)O(m,e,i,`line`),O(h,e,i,`line`);for(let e=m;e<=h;e++)k(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++)O(te+e,g,x[e],`arrow`);for(let e=0;e<S.length;e++)O(D-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=oe(a),s=Math.max(r,n-Math.floor(o.length/2)),c=A+e;if(le(C,Math.max(s+o.length,1),Math.max(c+1,1)),ce(w,Math.max(s+o.length,1),Math.max(c+1,1)),E(o,s,c,r,i))for(let e=0;e<o.length;e++){let t=s+e;t>=r&&t<=i&&O(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(D.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 T=m!==h,E=Math.min(m,h),A=Math.max(m,h),M=T?he(E,A,0):p,ae=T?M-1:p,N=!me(m,x,S)||!me(h,x,S)||re(m,f,T?M:p)||T&&re(h,M,p),P=m;if(N){let e=C.length,t;for(let n=0;n<=e;n++){let e=m+n;if(me(e,f,p)&&!ie(e,f,p)){t=e;break}let r=m-n;if(n>0&&me(r,f,p)&&!ie(r,f,p)){t=r;break}}P=t??m;for(let e=f;e<=g;e++)O(m,e,i,`line`);for(let e=Math.min(m,P);e<=Math.max(m,P);e++)k(e,g,r,`line`);for(let e=g;e<=_;e++)O(P,e,i,`line`);for(let e=Math.min(P,h);e<=Math.max(P,h);e++)k(e,_,r,`line`);for(let e=_;e<=p;e++)O(h,e,i,`line`);if(m!==P){let e=P>m?`right`:`left`,t=e===`right`?`left`:`right`;z(m,g,`up`,e),z(P,g,`down`,t)}if(P!==h){let e=h>P?`right`:`left`,t=e===`right`?`left`:`right`;z(P,_,`up`,e),z(h,_,`down`,t)}j(P,g,_)}else{for(let e=f;e<=ae;e++)O(m,e,i,`line`);if(j(m,f,T?M:ae),T){for(let e=E;e<=A;e++)k(e,M,r,`line`);for(let e=M+1;e<=p;e++)O(h,e,i,`line`);j(h,M,p);let e=h>m?`right`:`left`,t=e===`right`?`left`:`right`;z(m,M,`up`,e),z(h,M,`down`,t),P=h}}let F=qa(u,c,!1,!0);for(let e=0;e<F.length;e++)O(m-Math.floor(F.length/2)+e,g,F[e],`arrow`);let se=m===h?m:h,I=qa(d,c,!0,!0);for(let e=0;e<I.length;e++)O(se-Math.floor(I.length/2)+e,_,I[e],`arrow`);if(e.label){let t=Q(e.label),n=Math.max(F.length-1-Math.floor(F.length/2),I.length-1-Math.floor(I.length/2)),r=P+n+2,i=t.map(e=>oe(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&&(le(C,a+1,p+1),ce(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)=>te(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&&O(i,n,t[e],`text`)}w[r-1]?.[n]===`line`&&ee(r-1,n,` `,`line`);let a=r+t.length;w[a]?.[n]===`line`&&ee(a,n,` `,`line`)}}}}return ge(C,{roleCanvas:w,colorMode:i,theme:a})}var Za=4,Qa=[`O`,`/|\\`,`/ \\`],$a=3,eo=4;function to(e){return e.seqNumber===void 0?Za:Za+String(e.seqNumber).length}function no(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=yn(e.label?`${e.type} [${e.label}]`:e.type);for(let n of e.dividers)n.label&&(t=Math.max(t,yn(`[${n.label}]`)));return t}let C=Math.max(0,r.boxBorderPadding),w=e=>Math.max(yn(e.label),e.type===`actor`?$a:0),ee=e=>bn(e.label)+(e.type===`actor`?Qa.length:0),T=s.actors.map(e=>w(e)+2*C+2),E=T.map(e=>Math.ceil(e/2)),te=s.actors.map(e=>ee(e)+2),D=Math.max(...te,3),O=(e,t)=>t-Math.floor(T[e]/2),k=Math.floor((D-1)/2),ne=D-1-k,A=new Map,re=new Map;s.actors.forEach((e,t)=>{e.createdAt!==void 0&&A.set(e.createdAt,t),e.destroyedAt!==void 0&&re.set(e.destroyedAt,t)});let ie=new Map,j=new Map,M=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)}}),ae=M.length>0,F=s.actors.map((e,t)=>M.findIndex(e=>e.lo<=t&&t<=e.hi)),I=+!!ae,z=e=>e===``?0:yn(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=yn(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=>N(e)))+2+2*C}let fe=Array(s.actors.length).fill(0),pe=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):pe[t]=Math.max(pe[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 B=rt(r.paddingX,5,10,4),V=[Math.max(E[0]+(F[0]===-1?0:2),fe[0]+1,me[0])];for(let e=1;e<s.actors.length;e++){let t=F[e-1],n=F[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],me[e])+2,o=Math.max(E[e-1]+E[e]+2+i,ue[e-1]+2,a,B);V[e]=V[e-1]+o}let _e=e=>O(e.lo,V[e.lo])-1-1,ve=e=>Math.max(O(e.hi,V[e.hi])+T[e.hi]-1+1+1,_e(e)+z(e.label)-1);for(let e of M){if(e.hi+1>=s.actors.length)continue;let t=O(e.hi+1,V[e.hi+1]),n=F[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]+Za+2+yn(e.label);i=Math.max(i,t)}}if(n===-1||n+1>=s.actors.length)continue;let a=Math.max(0,r-eo),o=i+eo,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=I,Ee=Te+D,H=Ee+I,De=rt(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=bn(t.label),i=n?void 0:A.get(e),a=re.get(e);if(n)be[e]=H+1,ye[e]=H,H+=2+r;else{let t=i===void 0?0:k,n=i===void 0?0:ne;be[e]=H,ye[e]=H+r+t,H+=r+t+1+n,i!==void 0&&ie.set(i,ye[e]-t)}a!==void 0&&(j.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+I,je=Ae+D+I,Me=(V[V.length-1]??0)+(E[E.length-1]??0)+2;for(let e of M)Me=Math.max(Me,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)]+to(t)+2+2+yn(t.label);Me=Math.max(Me,e+1)}}for(let e of we)Me=Math.max(Me,e.x+e.width+1);let Ne=P(Me,je-1),Pe=se(Me,je-1);function U(e,t,n,r){R(Ne,e,t,n,{role:r,roleCanvas:Pe})}function Fe(e,t,n,r,i){let a=oe(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;U(o,t,a[n],r)}}function Ie(e,t,n,r,i){let a=r===`actor`?Qa:[],o=[...a,...Q(n)],s=Math.max(yn(n),a.length>0?$a:0),c=s+2*C+2,h=i,g=h-2,_=e-Math.floor(c/2);U(_,t,d,`border`);for(let e=1;e<c-1;e++)U(_+e,t,l,`border`);U(_+c-1,t,f,`border`);for(let e=0;e<g;e++){let n=t+1+e;U(_,n,u,`border`),U(_+c-1,n,u,`border`);let r=o[e];r!==void 0&&Fe(_+1+C+Math.floor((s-N(r))/2),n,r,`text`)}let v=t+h-1;U(_,v,p,`border`);for(let e=1;e<c-1;e++)U(_+e,v,l,`border`);U(_+c-1,v,m,`border`)}let Le=e=>{let t=ie.get(e);return t===void 0?Ee:t+D},Re=e=>j.get(e)??ke,ze=new Map,Be=new Map;function W(e,t){let n=Be.get(e)??[];Be.set(e,n),n.push(t)}function Ve(e,t){let n=Be.get(e)?.pop();if(n===void 0)return;let r=ze.get(e)??[];ze.set(e,r),r.push({topRow:n,bottomRow:t})}let He=new Map;for(let e of s.activations){let t=He.get(e.afterIndex)??[];t.push(e),He.set(e.afterIndex,t)}function Ue(e,t){for(let n of He.get(e)??[])n.kind===`start`?W(n.actorId,t):Ve(n.actorId,t)}Ue(-1,Ee);for(let e=0;e<s.messages.length;e++){let t=s.messages[e],n=ye[e];t.activate&&W(t.to,n),t.deactivate&&Ve(t.from,n),Ue(e,n)}for(let[e,t]of Be){if(t.length===0)continue;let n=Re(x(e)),r=ze.get(e)??[];ze.set(e,r);for(let e of t)r.push({topRow:e,bottomRow:n})}function We(e,t){let n=ze.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=Le(e);r<=Re(e);r++)U(t,r,We(n,r)?y:u,`line`)}let Ge=c?`+`:`┼`;function Ke(e,t,n){let r=_e(e),i=ve(e),a=t+D+1;U(r,t,d,`border`),U(i,t,f,`border`),U(r,a,p,`border`),U(i,a,m,`border`);for(let e=r+1;e<i;e++)U(e,t,l,`border`),U(e,a,l,`border`);for(let e=t+1;e<a;e++)U(r,e,u,`border`),U(i,e,u,`border`);n!==``&&Fe(r+2,t,` ${Q(n)[0]} `,`text`);for(let n=e.lo;n<=e.hi;n++){let e=V[n];Le(n)<=t&&t<=Re(n)&&U(e,t,Ge,`junction`),Le(n)<=a&&a<=Re(n)&&U(e,a,Ge,`junction`)}}for(let e of M)Ke(e,0,e.label),Ke(e,ke,``);for(let e=0;e<s.actors.length;e++){let t=s.actors[e],n=ie.get(e)??Te,r=j.has(e);Ie(V[e],n,t.label,t.type,D),r||Ie(V[e],Ae,t.label,t.type,D),c||(U(V[e],n+D-1,h,`junction`),r||U(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=to(t),a=t.seqNumber===void 0?void 0:String(t.seqNumber),o=Q(t.label);U(i,n,_,`junction`);let s=i+1;if(a!==void 0){for(let e=0;e<a.length;e++)U(i+1+e,n,a[e],`text`);s=i+1+a.length}for(let e=s;e<i+r;e++)U(e,n,h,`line`);U(i+r,n,c?`+`:`┐`,`corner`);let l=i+r+2;for(let e=0;e<o.length;e++){let t=n+1+e;U(i+r,t,u,`line`),Fe(l,t,o[e],`text`,Me)}let d=n+1+o.length;U(i,d,p?m:f?c?`<`:`◀`:c?`<`:`◁`,`arrow`);for(let e=i+1;e<i+r;e++)U(e,d,h,`line`);U(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=O(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];Fe(d-Math.floor(N(t)/2),n+e,t,`text`,Me)}if(s){for(let e=i+1;e<u;e++)U(e,o,h,`line`);U(u,o,p?m:f?c?`>`:`▶`:c?`>`:`▷`,`arrow`),t.bidirectional&&U(i,o,c?`<`:`◀`,`arrow`)}else{for(let e=u+1;e<i;e++)U(e,o,h,`line`);U(u,o,p?m:f?c?`<`:`◀`:c?`<`:`◁`,`arrow`),t.bidirectional&&U(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++)U(t+n,o,e[n],`text`)}else{let t=i-e.length;if(t>u)for(let n=0;n<e.length;n++)U(t+n,o,e[n],`text`)}}}}for(let[e,t]of j)U(V[e],t,c?`x`:`✕`,`arrow`);let qe=Me-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=Me,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]+to(t)+2+yn(t.label);a=Math.max(a,e)}}let o=i-eo,c=a+eo,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-eo)),o<=g&&(o=Math.min(i,g+eo)),o=Math.max(0,o),c>qe&&(le(Ne,c+1,je-1),ce(Pe,c+1,je-1),qe=c);let y=t.label?`${t.type} [${t.label}]`:t.type,x=o+1+S(t);if(x>c){c=x;let[e]=L(Ne);c>e&&(le(Ne,c,je-1),ce(Pe,c,je-1)),Me=Math.max(Me,c+1),qe=Math.max(qe,c)}U(o,n,d,`border`);for(let e=o+1;e<c;e++)U(e,n,l,`border`);U(c,n,f,`border`);let C=Q(y);for(let e=0;e<C.length&&n+e<r;e++)Fe(o+1,n+e,C[e],`text`,c);U(o,r,p,`border`);for(let e=o+1;e<c;e++)U(e,r,l,`border`);U(c,r,m,`border`);for(let e=n+1;e<r;e++)U(o,e,u,`border`),U(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=Je();U(o,r,_,`junction`);for(let e=o+1;e<c;e++)U(e,r,i,`line`);U(c,r,v,`junction`);let a=t.dividers[n].label;if(a){let e=`[${a}]`;Fe(o+1,r,e,`text`,c)}}}for(let e of we){le(Ne,e.x+e.width,e.y+e.height),ce(Pe,e.x+e.width,e.y+e.height),U(e.x,e.y,d,`border`);for(let t=1;t<e.width-1;t++)U(e.x+t,e.y,l,`border`);U(e.x+e.width-1,e.y,f,`border`);for(let t=0;t<e.lines.length;t++){let n=e.y+1+t;U(e.x,n,u,`border`),U(e.x+e.width-1,n,u,`border`);for(let t=e.x+1;t<e.x+e.width-1;t++)U(t,n,` `,`text`);Fe(e.x+1+C,n,e.lines[t],`text`)}let t=e.y+e.height-1;U(e.x,t,p,`border`);for(let n=1;n<e.width-1;n++)U(e.x+n,t,l,`border`);U(e.x+e.width-1,t,m,`border`)}return ge(Ne,{roleCanvas:Pe,colorMode:i,theme:a});function Je(){return c?`-`:`╌`}}function ro(e,t){return e.rowStart<=t.rowEnd&&t.rowStart<=e.rowEnd}function io(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&&ro(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 ao(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 oo(e,t){return{type:e,markerAt:t,dashed:e===`dependency`||e===`realization`}}function so(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 co(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=oe(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 lo(e){return Math.max(...Q(e).map(e=>N(e)))+2}var uo=2,fo=2,po=2,mo=4,ho=3;function go(e,t){let n=new Set(e.classes.map(e=>e.id)),r=new Set,i=[];for(let a of e.namespaces){let e=[];for(let i of a.classIds)if(!(!n.has(i)||r.has(i))){r.add(i),e.push(i);for(let[n,r]of t)r.forClass===i&&e.push(n)}e.length>0&&i.push({name:a.name,ids:e})}return i}function _o(e,t){let n=[],r=new Set;for(let i of e){let a=t.get(i);a===void 0?n.push(i):r.has(a)||(r.add(a),n.push(...e.filter(e=>t.get(e)===a)))}return n}function vo(n,r,i,a,o={}){let c=(0,e.splitStatements)(n),{diagram:l,notesById:u}=yo((0,t.parseClassDiagram)(c));if(l.classes.length===0)return``;let f=go(l,u),p=new Map;for(let[e,t]of f.entries())for(let n of t.ids)p.set(n,e);let m=r.useAscii,h=rt(r.paddingX,5,4,1)+(f.length>0?mo:0),g=rt(r.paddingY,5,3,1)+(f.length>0?ho:0),_=new Map,v=new Map,y=new Map;for(let e of l.classes){let t=ao(e);_.set(e.id,t);let{width:n,height:i}=Fa(t,r.boxBorderPadding);v.set(e.id,n),y.set(e.id,i)}let b=new Map;for(let e of l.classes)b.set(e.id,e);let x=new Map,S=new Map;for(let e of l.relationships){let t=e.from,n=e.to,r=x.get(n)??new Set;x.set(n,r),r.add(t);let i=S.get(t)??new Set;S.set(t,i),i.add(n)}let C=new Map,w=l.classes.filter(e=>!x.has(e.id)||x.get(e.id).size===0).map(e=>e.id);for(let e of w)C.set(e,0);let ee=l.classes.length-1,T=0;for(;T<w.length;){let e=w[T++],t=S.get(e);if(t)for(let n of t){let t=(C.get(e)??0)+1;t>ee||(!C.has(n)||C.get(n)<t)&&(C.set(n,t),w.push(n))}}for(let e of l.classes)C.has(e.id)||C.set(e.id,0);bo(u,C);let E=Math.max(...C.values(),0),te=Array.from({length:E+1},()=>[]);for(let e of l.classes)te[C.get(e.id)].push(e.id);if(f.length>0)for(let[e,t]of te.entries())te[e]=_o(t,p);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?lo(t):3}))+1;t.forEach((t,r)=>{D.set(t,Math.round((r-(e-1)/2)*n)),O.set(t,(e-1)*n)})}}let k=new Map,ne=new Map,A=new Map,re=new Map;{let e=(e,t,n)=>{let r=new Map;l.relationships.forEach((t,n)=>{if(D.has(n)||!b.has(t.from)||!b.has(t.to))return;let i=C.get(t.from)??0;if((C.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?lo(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,A,re),e(e=>e.from,k,ne)}let ie=new Map;for(let e of l.classes)ie.set(e.id,{left:0,right:0});l.relationships.forEach((e,t)=>{if(!b.has(e.from)||!b.has(e.to))return;let n=e.label?lo(e.label):1,r=D.get(t)??k.get(t)??0,i=D.get(t)??A.get(t)??0,a=ie.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=ie.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,M=0,ae=0;for(let e=0;e<=E;e++){let t=te[e];if(t.length===0)continue;let n=e=>{let t=x.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=v.get(n),r=ie.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+h}}let s=0,c=0,l=(e,t)=>{let n=b.get(e),r=v.get(e),i=y.get(e),l=o.get(e),u=a.get(e);j.set(e,{cls:n,sections:_.get(e),x:t+l,y:M,width:r,height:i}),ae=Math.max(ae,t+u),s=t+u+h,c=Math.max(c,i)},u=new Set;for(let c of t){if(u.has(c))continue;let t=n(c),d=x.get(c),f=d?[...d].filter(t=>C.get(t)<e):[];if(f.length===0){l(c,Math.max(i.get(c),s,0)),u.add(c);continue}let p=r.get(t),m=f.map(e=>{let t=j.get(e);return t.x+Math.floor(t.width/2)}),g=Math.round(m.reduce((e,t)=>e+t,0)/m.length),_=0;for(let e=0;e<p.length;e++)_+=a.get(p[e]),e<p.length-1&&(_+=h);let y=o.get(p[0]),b=p[p.length-1],S=a.get(b)-o.get(b)-v.get(b),w=_-y-S,ee=g-y-Math.floor(w/2),T=Math.max(ee,s,0);for(let e of p)l(e,T),u.add(e),T=s}M+=c+g}let F=[];if(f.length>0){for(let e of j.values())e.x+=uo,e.y+=fo;ae+=uo;for(let e of f){let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e.ids){let e=j.get(a);e&&(t=Math.min(t,e.x),n=Math.min(n,e.y),r=Math.max(r,e.x+e.width-1),i=Math.max(i,e.y+e.height-1))}if(t===1/0)continue;let a=t-uo,o=Math.max(r+uo,a+N(e.name)+5);F.push({name:e.name,x0:a,y0:n-fo,x1:o,y1:i+po})}}let I=ae;for(let e of F)I=Math.max(I,e.x1+1);let L=0;for(let e of j.values())I=Math.max(I,e.x+e.width),L=Math.max(L,e.y+e.height);for(let e of F)L=Math.max(L,e.y1+1);I+=4,L+=2;let z=P(I-1,L-1),de=se(I-1,L-1);function fe(e,t,n,r){R(z,e,t,n,{role:r,roleCanvas:de})}let me=o.hyperlinks?s(I-1,L-1):void 0;for(let t of j.values()){let n=Ia(t.sections,m,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<I&&a<L&&fe(n,a,i,Pa(i))}}if(me){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;d(me,n,{x:t.x,y:t.y},r,{from:e,to:i.length})}}}let he=new Set;for(let e of j.values())for(let t=0;t<e.height;t++)for(let n=0;n<e.width;n++)he.add(`${e.x+n},${e.y+t}`);function B(e,t,n,r){he.has(`${e},${t}`)||fe(e,t,n,r)}function V(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 _e(e,t,n,r){return Wa(e,0,e+I+9,e=>{for(let i=Math.min(t,n);i<=Math.max(t,n);i++)if(V(e,i,r))return!1;return!0})??I+2}let ve=m?`-`:`─`,ye=m?`|`:`│`,be=m?`.`:`╌`,xe=m?`:`:`┊`;function Se(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 Ce(e,t,n){let r=D.get(e)??k.get(e)??0,i=D.get(e)??A.get(e)??0,a=O.get(e)??ne.get(e)??0,o=O.get(e)??re.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+Se(r,a,t.width),toAnchorX:c+Se(i,o,n.width)}}function we(e,t,n,r){if(he.has(`${e},${t}`)||de[e]?.[t]===`arrow`)return;let i=z[e]?.[t];if(!m&&i!==void 0&&ue(i)&&ue(n)){let a=pe(i,n);fe(e,t,a,a===n?r:`junction`);return}fe(e,t,n,r)}function Te(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++)we(t,e,r,`line`);if(m){we(t,e,r,`line`),we(n,e,r,`line`);return}let s=n>t,c=i?s?`└`:`┘`:s?`┌`:`┐`,l=i?s?`┐`:`┌`:s?`┘`:`└`;we(t,e,c,`corner`),we(n,e,l,`corner`)}let Ee=new Map,H=new Map;l.relationships.forEach((e,t)=>{let n=j.get(e.from),r=j.get(e.to);if(!n||!r)return;let i=oo(e.type,e.markerAt),a=i.dashed?be:ve,o=i.dashed?xe:ye,s=new Set([e.from,e.to]),{fromCX:c,toCX:l,fromAnchorX:u,toAnchorX:d}=Ce(t,n,r),f=n.y+n.height-1,p=r.y;if(f<p){let e=_e(c,f+1,p-1,s),n=e!==c;if(e>=I&&le(z,e+2,L),n){let n=f+1,r=p-1;Ee.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`);!m&&n<(z[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`);!m&&r<(z[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,so(i.type,m,e?`up`:`down`),`arrow`)}if(i.markerAt===`from`){let e=so(i.type,m,`down`);B(u,f+1,e,`arrow`)}}else{let e=f+Math.floor((p-f)/2),t=c!==u,n=l!==d;Te(f+1,u,c,a,!0);for(let n=f+(t?2:1);n<=e;n++)B(c,n,o,`line`);if(c!==l&&e<(z[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`);m||(B(c,e,c<l?`└`:`┘`,`corner`),B(l,e,c<l?`┐`:`┌`,`corner`))}for(let t=e+1;t<p-+!!n;t++)B(l,t,o,`line`);if(Te(p-1,d,l,a,!1),i.markerAt===`to`){let e=i.type===`inheritance`||i.type===`realization`;B(d,p-1,so(i.type,m,e?`up`:`down`),`arrow`)}i.markerAt===`from`&&B(u,f+1,so(i.type,m,`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),f=c!==u,p=l!==d;Te(e-1,u,c,a,!1);for(let t=e-(f?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`);!m&&s>=0&&s<L&&(B(c,s,c<l?`┌`:`┐`,`corner`),B(l,s,c<l?`┘`:`└`,`corner`))}for(let e=s-1;e>t+ +!!p;e--)B(l,e,o,`line`);if(Te(t+1,d,l,a,!0),i.markerAt===`from`){let t=so(i.type,m,`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=so(i.type,m,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,p=Math.min(c,l),h=Math.max(c,l),g=Math.max(f,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>p&&(g=Math.max(g,r.y+r.height-1));let _=g+2;H.set(t,_),le(z,I,_+1),ce(de,I,_+1);let v=c!==u,y=l!==d;Te(f+1,u,c,a,!0);for(let e=f+(v?2:1);e<=_;e++)B(c,e,o,`line`);for(let e=p;e<=h;e++)B(e,_,a,`line`);for(let e=_-1;e>=s+(y?2:1);e--)B(l,e,o,`line`);if(Te(s+1,d,l,a,!0),i.markerAt===`from`){let e=so(i.type,m,`down`),t=f+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=so(i.type,m,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 De(e,t,n,r){let{fromCX:i,toCX:a}=Ce(e,t,n),o=t.y+t.height-1,s=n.y;if(o<s){let t=Ee.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:H.get(e)??Math.max(o,n.y+n.height-1)+2}}function Oe(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(V(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(V(t,r,o)){e=!1;break}if(e){s=r;break}}}return s}let ke=new Map,Ae=[];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(N))+2,{idealMidX:s,baseMidY:c}=De(e,n,r,o),l=new Set([t.from,t.to]),u=Oe(n,r,s,c,o,i.length,l);ke.set(t,u);let d=Math.max(0,s-Math.floor(o/2));Ae.push({rel:t,idealMidX:s,naturalStart:d,naturalEnd:d+o-1,rowStart:u-a,rowEnd:u+a})}let je=io(Ae,e=>({idealMid:e.idealMidX,start:e.naturalStart,end:e.naturalEnd,rowStart:e.rowStart,rowEnd:e.rowEnd})),Me=new Map;for(let e of Ae){let t=je.get(e);t&&Me.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}=De(e,n,r,Math.max(...i.map(e=>N(e)))+2),o=ke.get(t)-Math.floor(i.length/2),s=Me.get(t);for(let e=0;e<i.length;e++){let t=o+e,n=i[e],r=oe(` ${n} `),{start:c,cells:l}=co(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&&(le(z,Math.max(u,1),Math.max(t+1,1)),ce(de,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&&fe(n,t,l[e],`text`)}}}}for(let e of F){let t=m?`-`:`─`,n=m?`|`:`│`,r=m?{tl:`+`,tr:`+`,bl:`+`,br:`+`}:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`},i=oe(` ${e.name} `),a=t=>(z[t]?.[e.y0]??` `)===` `,o=e.x0+2;for(;Array.from({length:i.length+2},(e,t)=>o-1+t).some(e=>!a(e));)o++;e.x1=Math.max(e.x1,o+i.length+1),le(z,e.x1+1,e.y1+1),ce(de,e.x1+1,e.y1+1);let s=(e,t,n,r)=>{z[e]?.[t]===` `&&fe(e,t,n,r)};for(let n=e.x0+1;n<e.x1;n++)s(n,e.y0,t,`border`),s(n,e.y1,t,`border`);for(let t=e.y0+1;t<e.y1;t++)s(e.x0,t,n,`border`),s(e.x1,t,n,`border`);s(e.x0,e.y0,r.tl,`border`),s(e.x1,e.y0,r.tr,`border`),s(e.x0,e.y1,r.bl,`border`),s(e.x1,e.y1,r.br,`border`);for(let[n,r]of i.entries())z[o+n]?.[e.y0]===t&&fe(o+n,e.y0,r,`text`)}return xo(u,j,z,m,fe),ge(z,{roleCanvas:de,colorMode:i,theme:a,linkCanvas:me})}function yo(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 bo(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 xo(e,t,n,r,i){if(e.size===0)return;let a=Xn(`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 So(t,n){let r=new Set,i=new Map;for(let e of t.subgraphs)Co(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:st};a.set(n,t),o++}let s=[...a.values()],c=[],l=new Map,u=new Map;for(let n of t.edges){let o=n.source,s=n.target,d,f;if((0,e.isEdgeWithinOwnCluster)(n,i))continue;if(r.has(o)){let e=i.get(o),n=e?Eo(e,t,`exit`):void 0;n&&(o=n),d=n?e:void 0}if(r.has(s)){let e=i.get(s),n=e?Eo(e,t,`entry`):void 0;n&&(s=n),f=n?e:void 0}let p=a.get(o),m=a.get(s);if(!p||!m)continue;let h={from:p,to:m,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}};c.push(h),d&&l.set(h,d),f&&u.set(h,f)}let d=[];for(let e of t.subgraphs)Do(e,null,a,d,t);if(Oo(t.subgraphs,d,a),l.size>0||u.size>0){let e=new Map;Ao(t.subgraphs,d,e);for(let[t,n]of l){let r=e.get(n);r&&(t.clusterSource=r)}for(let[t,n]of u){let r=e.get(n);r&&(t.clusterTarget=r)}}let f=t.classDefs.get(`default`);if(f)for(let e of a.values())e.styleClassName=`default`,e.styleClass={name:`default`,styles:f};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:f?{...f,...i}:i})}return{nodes:s,edges:c,canvas:P(0,0),roleCanvas:se(0,0),grid:lt(),columnWidth:new Map,rowHeight:new Map,subgraphs:d,config:n,offsetX:0,offsetY:0,bundles:[]}}function Co(e,t,n){t.add(e.id),n.set(e.id,e);for(let r of e.children)Co(r,t,n)}function wo(e,t){for(let n of e.nodeIds)t.add(n);for(let n of e.children)wo(n,t)}function To(e,t){let n=new Set;if(wo(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 Eo(e,t,n){let r=new Set;if(wo(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 Do(e,t,n,r,i){let a;e.direction&&To(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=Do(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 Oo(e,t,n){let r=new Map;Ao(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||ko(e,a)})}function ko(e,t){let n=t;for(;n!==null;){if(n===e)return!0;n=n.parent}return!1}function Ao(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 jo(t){for(let n of t.nodes.values())n.label=(0,e.decodeXmlEntitiesInLabel)(n.label);for(let n of t.edges)n.label&&=(0,e.decodeXmlEntitiesInLabel)(n.label);let n=t=>{for(let r of t)r.label=(0,e.decodeXmlEntitiesInLabel)(r.label),n(r.children)};return n(t.subgraphs),t}function Mo(n,r,i,a,o={}){return No((0,e.withDirectionOverride)(jo((0,t.parseMermaid)(n)),o.direction),r,i,a,o)}function No(e,t,n,r,i){t.graphDirection=e.direction===`LR`||e.direction===`RL`?`LR`:`TD`;let a=So(e,t);ci(a),Ha(a);let o=i.hyperlinks?f(a,e.interactions):void 0;return e.direction===`BT`&&(_e(a.canvas,a.roleCanvas,a.labelRects??[],o),V(a.canvas,a.roleCanvas),ye(a.roleCanvas),o&&l(o)),e.direction===`RL`&&(Se(a.canvas,a.roleCanvas,a.labelRects??[],o),xe(a.canvas,a.roleCanvas),we(a.roleCanvas),o&&u(o)),ge(a.canvas,{roleCanvas:a.roleCanvas,colorMode:n,theme:r,linkCanvas:o})}function Po(n,r,i,a,o={}){let s=(0,t.architectureToGraph)((0,t.parseArchitecture)((0,e.splitStatements)(n)));return No((0,e.withDirectionOverride)(s,o.direction),r,i,a,o)}var Fo=28,Io=2;function Lo(e,n){let r=new Map(e.map(e=>[e,e])),i=e=>{let t=e;for(;r.get(t)!==t;)t=r.get(t);return t},a=new Set(e);for(let e of n){let n=(0,t.c4Placement)(e);if(n.axis===`horizontal`&&a.has(n.source)&&a.has(n.target)){let e=i(n.source),t=i(n.target);e!==t&&r.set(t,e)}}let o=new Map;for(let t of e)o.set(i(t),o.get(i(t))??new Set);for(let e of n){let n=(0,t.c4Placement)(e);if(n.axis===`horizontal`||!a.has(n.source)||!a.has(n.target))continue;let r=i(n.source),s=i(n.target);r!==s&&o.get(r).add(s)}let s=new Map,c=new Map,l=e=>{s.set(e,1);let t=[];for(let n of o.get(e)??[]){let e=s.get(n)??0;e!==1&&(t.push(n),e===0&&l(n))}c.set(e,t),s.set(e,2)};for(let e of o.keys())s.has(e)||l(e);let u=new Map,d=e=>{let t=u.get(e);if(t!==void 0)return t;u.set(e,0);let n=0;for(let[t,r]of c)r.includes(e)&&(n=Math.max(n,d(t)+1));return u.set(e,n),n},f=new Map;for(let t of e)f.set(t,d(i(t)));return f}var Ro=[` o `,`/|\\`,`/ \\`];function zo(e){let n=[];return e.kind===`person`&&n.push(...Ro),n.push(...(0,t.wrapC4Text)(e.label,Fo),(0,t.c4TypeLine)(e)),e.description&&n.push(``,...(0,t.wrapC4Text)(e.description,Fo)),{lines:n,glyph:e.kind===`person`}}function Bo(e,t){let{lines:n,glyph:r}=zo(e),i=Math.max(...n.map(N)),a=e.shape===`db`?2:0;return{kind:`el`,el:e,lines:n,glyph:r,order:t,rank:0,box:{x:0,y:0,w:Math.max(14,i+4),h:n.length+2+a}}}function Vo(n,r,i,a,o={}){let s=(0,e.withDirectionOverride)((0,t.parseC4Diagram)((0,e.splitStatements)(n)),o.direction);if(s.elements.length===0&&s.boundaries.length===0)return``;let c=r.useAscii,l=rt(r.paddingX,5,6,4),u=rt(r.paddingY,5,4,3)+ +!!s.relationships.some(e=>(0,t.c4RelLabelLines)(e).length>1),d=new Map;for(let[e,t]of s.elements.entries())d.set(t.alias,Bo(t,e));let f=Lo([...s.elements.map(e=>e.alias),...Ho(s.boundaries)],s.relationships);for(let[e,t]of d)t.rank=f.get(e)??0;let p=new Map,m=new Set,h=e=>{let n=[];for(let t of e.elementAliases)m.add(t),n.push(d.get(t));for(let t of e.children)n.push(h(t));let r=(0,t.c4BoundaryTypeLine)(e),i=r?2:1;if(n.length===0){let n=[...(0,t.wrapC4Text)(e.label,Fo)];r&&n.push(r);let a={kind:`b`,b:e,rows:[],vgaps:[],headerH:i,order:2**53-1,rank:f.get(e.alias)??0,box:{x:0,y:0,w:Math.max(14,Math.max(...n.map(N))+4),h:n.length+2}};return p.set(e.alias,a),a}let a={kind:`b`,b:e,rows:[],vgaps:[],headerH:i,order:0,rank:0,box:{x:0,y:0,w:0,h:0}};a.rows=Ko(n,s),s.direction===`BT`&&a.rows.reverse(),a.vgaps=Yo(a.rows,s,u),p.set(e.alias,a);let o=a.rows.flat();return a.order=Math.min(...o.map(e=>e.order)),a.rank=Math.min(...o.map(e=>e.rank)),qo(a,l),a},g=s.boundaries.map(h),_=Ko([...s.elements.filter(e=>!m.has(e.alias)).map(e=>d.get(e.alias)),...g],s);s.direction===`BT`&&_.reverse();let v=Yo(_,s,u),y=s.title?2:0,b=(e,t,n,r,i)=>{let a=r;for(let[r,o]of e.entries()){let e=Go(o,s,l),c=o.reduce((e,t)=>e+t.box.w,0)+Uo(e),u=n+Math.floor((i-c)/2),d=Math.max(...o.map(e=>e.box.h));o.forEach((t,n)=>{x(t,u,a+Math.floor((d-t.box.h)/2)),u+=t.box.w+(e[n]??0)}),a+=d+(t[r]??0)}},x=(e,t,n)=>{e.box.x=t,e.box.y=n,e.kind===`b`&&e.rows.length>0&&b(e.rows,e.vgaps,t+2,n+e.headerH+2,e.box.w-4)},S=Math.max(..._.map(e=>e.reduce((e,t)=>e+t.box.w,0)+Uo(Go(e,s,l))));b(_,v,Io,Io+y,S);let C=0,w=0,ee=[...d.values(),...p.values()].map(e=>e.box);for(let e of ee)C=Math.max(C,e.x+e.w),w=Math.max(w,e.y+e.h);let T=C+Io+1,E=w+Io+1,te=P(T,E),D=se(T,E),O=(e,t,n,r)=>R(te,e,t,n,{role:r,roleCanvas:D}),k=(e,t,n,r)=>{let i=e;for(let e of oe(n))O(i,t,e,r),i++},ne=Array.from({length:T+1},()=>Array(E+1).fill(0)),A=Array.from({length:T+1},()=>Array(E+1).fill(!1)),re=e=>{for(let t=e.x;t<e.x+e.w;t++)for(let n=e.y;n<e.y+e.h;n++)A[t][n]=!0};if(s.title){let e=N(s.title);k(Math.max(0,Math.floor((T-e)/2)),1,s.title,`text`);for(let e=0;e<T;e++)A[e][1]=!0}let ie=e=>{let{x:n,y:r,w:i,h:a}=e.box,o=c?`-`:`╌`,s=c?`:`:`╎`,[l,u,d,f]=c?[`+`,`+`,`+`,`+`]:[`╭`,`╮`,`╰`,`╯`];for(let e=0;e<i;e++)ne[n+e][r]|=es,ne[n+e][r+a-1]|=es;for(let e=0;e<a;e++)ne[n][r+e]|=ts,ne[n+i-1][r+e]|=ts;for(let e=1;e<i-1;e++)O(n+e,r,o,`border`),O(n+e,r+a-1,o,`border`);for(let e=1;e<a-1;e++)O(n,r+e,s,`border`),O(n+i-1,r+e,s,`border`);if(O(n,r,l,`border`),O(n+i-1,r,u,`border`),O(n,r+a-1,d,`border`),O(n+i-1,r+a-1,f,`border`),e.rows.length>0){k(n+2,r+1,e.b.label,`text`);let a=(0,t.c4BoundaryTypeLine)(e.b);a&&k(n+2,r+2,a,`text`);let o=Math.max(N(e.b.label),N(a??``))+2;for(let t=1;t<=o&&n+t<n+i-1;t++)for(let i=1;i<=e.headerH;i++)A[n+t][r+i]=!0}else{let a=[...(0,t.wrapC4Text)(e.b.label,Fo)],o=(0,t.c4BoundaryTypeLine)(e.b);o&&a.push(o),a.forEach((e,t)=>k(n+Math.floor((i-N(e))/2),r+1+t,e,`text`)),re(e.box)}},j=e=>{for(let t of e)t.kind===`b`&&(ie(t),j(t.rows.flat()))};j(_.flat());let M=e=>{let{x:t,y:n,w:r,h:i}=e.box,a=e.el,o=a.external,s=c?o?`.`:`-`:o?`┄`:`─`,l=c?o?`:`:`|`:o?`┆`:`│`,u=a.kind===`person`||a.shape!=="default",[d,f,p,m]=c?[`+`,`+`,`+`,`+`]:u?[`╭`,`╮`,`╰`,`╯`]:[`┌`,`┐`,`└`,`┘`];for(let e=1;e<r-1;e++)O(t+e,n,s,`border`),O(t+e,n+i-1,s,`border`);let h=a.shape===`queue`?`(`:l,g=a.shape===`queue`?`)`:l;for(let e=1;e<i-1;e++)O(t,n+e,h,`border`),O(t+r-1,n+e,g,`border`);O(t,n,d,`border`),O(t+r-1,n,f,`border`),O(t,n+i-1,p,`border`),O(t+r-1,n+i-1,m,`border`);let _=n+1;if(a.shape===`db`){let e=c?`+`:`├`,a=c?`+`:`┤`;for(let o of[n+1,n+i-2]){O(t,o,e,`junction`),O(t+r-1,o,a,`junction`);for(let e=1;e<r-1;e++)O(t+e,o,s,`border`)}_=n+2}e.lines.forEach((n,i)=>{let a=e.glyph&&i<Ro.length,o=N(n);k(t+Math.floor((r-o)/2),_+i,n,a?`border`:`text`)}),re(e.box)};for(let e of d.values())M(e);let ae=e=>{let t=d.get(e);return t?{box:t.box,boundary:!1}:{box:p.get(e).box,boundary:!0}},F=Array.from({length:T+1},()=>Array(E+1).fill(0)),ce=new Map,I=[];for(let e of s.relationships){if(e.from===e.to)continue;let t=ae(e.from),n=ae(e.to),r=[];t.boundary&&p.get(e.from).rows.length>0&&r.push(t.box),n.boundary&&p.get(e.to).rows.length>0&&r.push(n.box);let i=ls(t.box,n.box,{width:T,height:E,blocked:A,masks:F,arrows:ce,borders:ne},r);if(!i)continue;I.push({rel:e,path:i}),ss(i,F,t.box,n.box);let a=i[i.length-1],o=i[0];(!e.reversed||e.bidirectional)&&ce.set(`${a[0]},${a[1]}`,rs(ns(a,n.box),c)),(e.bidirectional||e.reversed)&&ce.set(`${o[0]},${o[1]}`,rs(ns(o,t.box),c))}for(let e=0;e<=T;e++)for(let t=0;t<=E;t++){let n=F[e][t];if(n===0)continue;let r=ce.get(`${e},${t}`);r?O(e,t,r,`arrow`):O(e,t,as(n,c),os(n)?`corner`:`line`)}for(let[e,t]of ce){let[n,r]=e.split(`,`).map(Number);O(n,r,t,`arrow`)}let L=(e,t)=>e>=0&&t>=0&&e<=T&&t<=E&&te[e][t]===` `&&!A[e][t],le=(e,t)=>e>=0&&t>=0&&e<=T&&t<=E&&!A[e][t]&&!ce.has(`${e},${t}`)&&(te[e][t]===` `||F[e][t]!==0);for(let{rel:e,path:n}of I){let r=(0,t.c4RelLabelLines)(e);if(r.length===0)continue;let i=Math.max(...r.map(N)),a=[r];for(let e of[18,12,8,6])i>e&&a.push(r.flatMap((n,r)=>r===0?(0,t.wrapC4Text)(n,e):[n]));let o=e=>a.some(t=>ds(t,n,L,le,k,e));o(!1)||o(!0)}return ge(te,{roleCanvas:D,colorMode:i,theme:a})}function Ho(e){return e.flatMap(e=>e.elementAliases.length===0&&e.children.length===0?[e.alias]:Ho(e.children))}var Uo=e=>e.reduce((e,t)=>e+t,0);function Wo(e,n,r){let i=(e,t)=>e.kind===`el`?e.el.alias===t:e.b.alias===t,a=0;for(let o of r.relationships){let r=(0,t.c4Placement)(o);r.axis===`horizontal`&&(i(e,r.source)&&i(n,r.target)||i(n,r.source)&&i(e,r.target))&&(a=Math.max(a,...(0,t.c4RelLabelLines)(o).map(N)))}return a}function Go(e,t,n){let r=[];for(let i=0;i<e.length-1;i++){let a=Wo(e[i],e[i+1],t);r.push(Math.max(n,a>0?a+4:0))}return r}function Ko(e,n){let r=new Map;for(let t of e)r.set(t.rank,[...r.get(t.rank)??[],t]);let i=[...r.entries()].sort((e,t)=>e[0]-t[0]).map(([,e])=>e.sort((e,t)=>e.order-t.order)),a=e=>e.kind===`el`?e.el.alias:e.b.alias;for(let e of i)for(let r=0;r<e.length;r++){let r=!1;for(let i of n.relationships){let n=(0,t.c4Placement)(i);if(n.axis!==`horizontal`)continue;let o=e.map(a),s=o.indexOf(n.source),c=o.indexOf(n.target);if(s<0||c<0||s<c)continue;let[l]=e.splice(s,1);e.splice(c,0,l),r=!0}if(!r)break}return i}function qo(e,n){let r=0,i=e.headerH+2;for(let[t,a]of e.rows.entries()){let o=Uo(a.map(e=>e.box.w))+(a.length-1)*n;r=Math.max(r,o),i+=Math.max(...a.map(e=>e.box.h))+(e.vgaps[t]??0)}let a=Math.max(N(e.b.label),N((0,t.c4BoundaryTypeLine)(e.b)??``));e.box.w=Math.max(r,a)+4,e.box.h=i+2}function Jo(e,t=new Set){if(e.kind===`el`)t.add(e.el.alias);else{t.add(e.b.alias);for(let n of e.rows)for(let e of n)Jo(e,t)}return t}function Yo(e,n,r){let i=new Map;e.forEach((e,t)=>{for(let n of e)for(let e of Jo(n))i.set(e,t)});let a=e.map(()=>0);for(let e of n.relationships){let n=i.get(e.from),r=i.get(e.to);if(n===void 0||r===void 0||n===r)continue;let o=(0,t.c4RelLabelLines)(e).length;if(o!==0)for(let e=Math.min(n,r);e<Math.max(n,r);e++)a[e]=a[e]+o+1}return e.slice(0,-1).map((e,t)=>Math.max(r,a[t]+1))}var Xo=1,Zo=2,Qo=4,$o=8,es=1,ts=2;function ns(e,t){let[n,r]=e;return r<t.y?Zo:r>=t.y+t.h?Xo:n<t.x?$o:Qo}function rs(e,t){return e===Zo?t?`v`:`▼`:e===Xo?t?`^`:`▲`:e===$o?t?`>`:`►`:t?`<`:`◄`}var is={[Xo]:`│`,[Zo]:`│`,3:`│`,[Qo]:`─`,[$o]:`─`,12:`─`,10:`┌`,6:`┐`,9:`└`,5:`┘`,11:`├`,7:`┤`,14:`┬`,13:`┴`,15:`┼`};function as(e,t){let n=is[e]??`┼`;return t?n===`│`?`|`:n===`─`?`-`:`+`:n}function os(e){return e===10||e===6||e===9||e===5}function ss(e,t,n,r){let i=(e,t)=>t[0]>e[0]?$o:t[0]<e[0]?Qo:t[1]>e[1]?Zo:Xo,a=e=>e===Xo?Zo:e===Zo?Xo:e===Qo?$o:Qo;for(let n=0;n<e.length;n++){let[r,o]=e[n];n>0&&(t[r][o]|=a(i(e[n-1],e[n]))),n<e.length-1&&(t[r][o]|=i(e[n],e[n+1]))}let o=e[0],s=e[e.length-1];t[o[0]][o[1]]|=ns(o,n),t[s[0]][s[1]]|=ns(s,r)}function cs(e,t,n){let r=[],i=e.x+e.w/2,a=e.y+e.h/2,o=t.x+t.w/2,s=t.y+t.h/2,c=t.y<e.y+e.h&&e.y<t.y+t.h,l=new Set;c?l.add(o>i?$o:Qo):l.add(s>a?Zo:Xo);let u=e=>l.has(e)?0:e===Zo&&l.has(Xo)||e===Xo&&l.has(Zo)||e===Qo&&l.has($o)||e===$o&&l.has(Qo)?14:7,d=(e,t,i,a)=>{e<0||t<0||e>n.width||t>n.height||n.blocked[e][t]||r.push({cell:[e,t],cost:u(i)+Math.abs(a)*.2})};for(let t=e.x+1;t<e.x+e.w-1;t++)d(t,e.y-1,Xo,t-i),d(t,e.y+e.h,Zo,t-i);for(let t=e.y+1;t<e.y+e.h-1;t++)d(e.x-1,t,Qo,t-a),d(e.x+e.w,t,$o,t-a);return r}function ls(e,t,n,r){let i=(e,t)=>r.some(n=>e>=n.x&&e<n.x+n.w&&t>=n.y&&t<n.y+n.h),a=cs(e,t,n).filter(e=>!i(...e.cell)),o=new Map;for(let r of cs(t,e,n))i(...r.cell)||o.set(`${r.cell[0]},${r.cell[1]}`,r.cost);if(a.length===0||o.size===0)return;let s=(e,n)=>(e<t.x?t.x-e:e>=t.x+t.w?e-(t.x+t.w-1):0)+(n<t.y?t.y-n:n>=t.y+t.h?n-(t.y+t.h-1):0),c=[],l=new Map;for(let e of a){let[t,n]=e.cell;c.push({x:t,y:n,dir:0,g:e.cost,f:e.cost+s(t,n),parent:void 0}),l.set(`${t},${n},0`,e.cost)}let u=[[0,-1,Xo],[0,1,Zo],[-1,0,Qo],[1,0,$o]],d=0;for(;c.length>0&&d++<2e5;){let e=0;for(let t=1;t<c.length;t++)c[t].f<c[e].f&&(e=t);let t=c.splice(e,1)[0],r=`${t.x},${t.y}`;if(o.get(r)!==void 0){let e=[];for(let n=t;n;n=n.parent)e.push([n.x,n.y]);return e.reverse()}for(let[e,r,a]of u){let u=t.x+e,d=t.y+r;if(u<0||d<0||u>n.width||d>n.height)continue;let f=o.has(`${u},${d}`);if(n.blocked[u][d]&&!f||i(u,d)||n.arrows.has(`${u},${d}`))continue;let p=1;t.dir!==0&&t.dir!==a&&(p+=2);let m=n.borders[u][d];m!==0&&(a===Qo||a===$o?(m&es)!==0:(m&ts)!==0)&&(p+=12);let h=n.masks[u][d];if(h!==0){let e=a===Qo||a===$o,t=!!(h&12),n=!!(h&3);p+=e&&t||!e&&n?8:3}let g=t.g+p+(f?o.get(`${u},${d}`)??0:0),_=`${u},${d},${a}`;(l.get(_)??1/0)<=g||(l.set(_,g),c.push({x:u,y:d,dir:a,g,f:g+s(u,d),parent:t}))}}}function us(e){let t=[],n=0;for(;n<e.length-1;){let r=e[n+1][1]===e[n][1],i=n+1;for(;i<e.length-1&&e[i+1][1]===e[i][1]===r;)i++;let[a,o]=e[n],[s,c]=e[i];t.push({horizontal:r,x0:Math.min(a,s),y0:Math.min(o,c),len:Math.abs(s-a)+Math.abs(c-o)+1}),n=i}return t}function ds(e,t,n,r,i,a){let o=e.map(N),s=e=>e.every(([e,t],r)=>{let i=o[r];for(let r=0;r<i;r++)if(!n(e+r,t))return!1;return n(e-1,t)&&n(e+i,t)}),c=e=>Array.from({length:e},(e,t)=>t).sort((t,n)=>Math.abs(t-e/2)-Math.abs(n-e/2));for(let n of a?[]:us(t).sort((e,t)=>t.len-e.len))for(let t of c(n.len)){let r=[];if(n.horizontal){let i=n.x0+t;r.push(e.map((e,t)=>[i-Math.floor(o[t]/2),t===0?n.y0-1:n.y0+t])),e.length===1&&r.push([[i-Math.floor(o[0]/2),n.y0+1]])}else{let i=n.y0+t-Math.floor((e.length-1)/2);for(let t of[1,-1])r.push(e.map((e,r)=>[t>0?n.x0+2:n.x0-1-o[r],i+r]))}for(let t of r)if(s(t))return t.forEach(([t,n],r)=>i(t,n,e[r],`text`)),!0}let l=e=>e.every(([e,t],n)=>{for(let i=0;i<o[n];i++)if(!r(e+i,t))return!1;return!0});for(let n of a?us(t).sort((e,t)=>t.len-e.len):[])for(let t of c(n.len)){let r=e.map((r,i)=>n.horizontal?[n.x0+t-Math.floor(o[i]/2),n.y0+i-+(e.length>1)]:[n.x0-Math.floor(o[i]/2),n.y0+t+i]);if(l(r))return r.forEach(([t,n],r)=>i(t,n,e[r],`text`)),!0}return!1}var fs=1,ps=12,ms=` `,hs=` `,gs=4,_s={solid:`█`,patterns:`█▓▒░`,noSegment:`·`},vs={solid:`#`,patterns:`#=*+`,noSegment:`.`};function ys(e,t){let n=e.length;if(n===0)return[];let r=e.reduce((e,t)=>e+t,0);if(!(r>0))return e.map(()=>0);let i=e.map((e,n)=>{let i=e/r*t;return{i:n,exact:i,count:Math.floor(i)}}),a=t-i.reduce((e,t)=>e+t.count,0),o=[...i].sort((e,t)=>t.exact-t.count-(e.exact-e.count)||e.i-t.i);for(let e of o){if(a<=0)break;e.count++,a--}if(n<=t)for(let e of i){if(e.count!==0)continue;let t,n=-1/0;for(let e of i){let r=e.count-e.exact;e.count>1&&r>n&&(n=r,t=e)}if(t===void 0)break;t.count--,e.count=1}return i.map(e=>e.count)}function bs(e,t=50){let n=e.slices.reduce((e,t)=>e+t.value,0),r=e.slices.map(e=>e.value/n*100>=fs),i=ys(e.slices.filter((e,t)=>r[t]).map(e=>e.value),t),a=0,o=e.slices.map((t,o)=>{let s=e.showData?`${t.label} [${String(t.value)}]`:t.label,c=o%ps;if(!r[o])return{text:s,percentText:``,colorIndex:c,cells:0,drawnIndex:-1};let l={text:s,percentText:`${(t.value/n*100).toFixed(0)}%`,colorIndex:c,cells:i[a]??0,drawnIndex:a};return a++,l});return{title:e.title&&e.title.length>0?e.title:void 0,rows:o,barWidth:t}}function xs(e,n){return(0,t.getSeriesColor)(e,n.accent??t.CHART_ACCENT_FALLBACK,n.bg)}function Ss(e,n,r,i){let a=bs((0,t.parsePieChart)(e)),o=n.useAscii?vs:_s,s=r!==`none`,c=(e,t)=>ne(e,t,r),l=e=>e.drawnIndex<0?o.noSegment:s?o.solid:o.patterns.charAt(e.drawnIndex%o.patterns.length),u=[],d=a.barWidth+2;if(a.title!==void 0){let e=Math.max(0,Math.floor((d-N(a.title))/2));u.push(` `.repeat(e)+c(a.title,i.fg),``)}let f=``,p=0;for(let e of a.rows)e.cells<=0||(f+=c(l(e).repeat(e.cells),xs(e.colorIndex,i)),p+=e.cells);if(f+=` `.repeat(Math.max(0,a.barWidth-p)),u.push(c(`[`,i.border)+f+c(`]`,i.border)),a.rows.length>0){u.push(``);let e=Math.max(...a.rows.map(e=>N(e.text)));for(let t of a.rows){let n=c(l(t),xs(t.colorIndex,i)),r=c(t.text,i.fg)+` `.repeat(e-N(t.text)),a=c(t.percentText.padStart(gs),i.fg),o=t.percentText.length>0?`${ms}${n} ${r}${hs}${a}`:`${ms}${n} ${c(t.text,i.fg)}`;u.push(o)}}return u.join(`
|
|
5
|
+
`)}var Cs={xychart:(e,t,n,r)=>Ne(e,t,n,r),er:(e,t,n,r)=>Xa(e,t,n,r),sequence:(e,t,n,r)=>no(e,t,n,r),class:(e,t,n,r,i)=>vo(e,t,n,r,i),flowchart:(e,t,n,r,i)=>Mo(e,t,n,r,i),architecture:(e,t,n,r,i)=>Po(e,t,n,r,i),c4:(e,t,n,r,i)=>Vo(e,t,n,r,i),pie:(e,t,n,r)=>Ss(e,t,n,r)},ws=/\x1b\[[0-9;]*m/g;function Ts(e){let t=e.split(`
|
|
6
|
+
`),n=t.reduce((e,t)=>Math.max(e,o(t.replace(ws,``)).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 Es(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?_():n.colorMode,a={...h,...n.theme},o=Cs[(0,e.detectDiagramType)(t)](t,r,i,a,{hyperlinks:n.hyperlinks??!1,direction:n.direction});return n.showCoords?Ts(o):o}var Ds=Es;exports.DEFAULT_ASCII_THEME=h,exports.detectColorMode=_,exports.diagramColorsToAsciiTheme=g,exports.renderMermaidASCII=Es,exports.renderMermaidAscii=Ds;
|
|
7
8
|
//# sourceMappingURL=index.cjs.map
|