SLOPSHOPPER

noppomario-mod

noppomario's mods for Claude Code, in one plugin. Today: the mermaid code fences in Claude's replies drawn where they stand — text on the terminal, ASCII in…

newrowspromptprocess
A shopper browsing a rack in a slop shop
Preview could not run: TypeError: Invalid URL: null/Users/raymondxu/slopshopper-mods/.cache/src/noppomario-claudecode-plugins-noppomario-mod/hooks/features/mermaid/./render-svg.mjs at new URLShim (inner.js:204:26) a
README

noppomario-mod

noppomario's mods for Claude Code, in one plugin. A plugin may name exactly one hooks module, so each feature lives under hooks/features/<name>/ and hooks/register.ts composes them.

mermaid

Draws the mermaid code fences in Claude's replies where they stand, and tells the model, once per conversation, to write diagrams as fences rather than draw them by hand. Laying a diagram out means counting display columns and a model counts characters, so a label in a wide script comes out crooked; a fence hands that arithmetic to code.

Where it draws

SurfaceHowWhat
Terminalui.renderBox-drawing text
Editor, desktop, mobileui.renderSVG
A session that draws nowhereMessageDisplayASCII text

The VS Code extension runs the agent as a stream-json client, where the engine draws nowhere and ui.render is never raised. So the panel is served by the MessageDisplay fallback today, and the SVG path sits dormant and starts working the day the extension attaches as a surface — no change here. Only one of them draws at a time: the hooks module sets an environment variable when a surface attaches, and the fallback stands down when it sees it.

The fallback draws with - | +. Box-drawing characters are East Asian Ambiguous, and a webview takes its font's word for their width; a terminal places by cell and VS Code draws them itself, so it can be trusted with them.

The renderer

zombie-mermaid, MIT, bundled into hooks/features/mermaid/vendor/. A hooks module may import only its own files and Claude Code installs no dependencies for a plugin, so the bundles are committed. Rebuild after changing the pinned version:

npm ci --ignore-scripts
npm run renderers

The SVG bundle is over the 1,048,576 bytes a hooks module will read, so hooks/render-svg.mjs draws in a child process.

Draws flowchart, sequenceDiagram, stateDiagram, classDiagram and erDiagram. A fence keeps its source when it does not parse or lays out wider than the terminal.

Tests

CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1 claude plugin test plugins/noppomario-mod

draw-text.test.ts and draw-svg.test.ts mount AssistantMessage through the plugin on a named surface and read the drawing back. The SVG tests name surfaces nothing raises today, which is how that path is held to its contract before it can run. renderer.test.ts guards the bundle: a renderer that draws crooked boxes is worse than one that does not draw.

Source 7 files
hooks/register.ts 14 lines
1import type { On } from 'claude-code'
2
3import { register as mermaid } from './features/mermaid/index.ts'
4
5/**
6 * A plugin may name one hooks module, so the features live under `features/`
7 * and this composes them. Adding one is a folder and a line here.
8 *
9 * @param on the engine's registrar
10 */
11export function register(on: On) {
12	mermaid(on)
13}
14
hooks/features/mermaid/index.ts 36 lines
1import type { On } from 'claude-code'
2
3import { register as svg } from './draw-svg.ts'
4import { register as text } from './draw-text.ts'
5import { register as guidance } from './guidance.ts'
6
7/**
8 * Registers the mermaid feature: three ways in, one drawing at a time.
9 *
10 * A terminal and a surface with `Svg` draw through `ui.render`. A session
11 * that draws nowhere — the VS Code panel today, `-p`, the SDK — is served by
12 * the MessageDisplay hook, which stands down when NOPPOMARIO_MOD_DRAWS says
13 * one of the others has it. An environment variable, because that hook is a
14 * separate process, and spelled out at each call because the engine refuses
15 * a name it cannot read off the source.
16 *
17 * @param on the engine's registrar
18 */
19export function register(on: On) {
20	on('session.start', ($, e, next) => {
21		// Failing here leaves the fallback drawing, which is the safe way to be
22		// wrong.
23		if (e.surface !== null) void $.env.set('NOPPOMARIO_MOD_DRAWS', '1').catch(() => {})
24		return next(e)
25	})
26
27	on('session.attach', ($, e, next) => {
28		void $.env.set('NOPPOMARIO_MOD_DRAWS', '1').catch(() => {})
29		return next(e)
30	})
31
32	guidance(on)
33	text(on)
34	svg(on)
35}
36
hooks/features/mermaid/draw-svg.ts 140 lines
1import type { BoxProps, ElementConstructor, MarkdownProps, On, RenderElement, SvgProps } from 'claude-code'
2
3import { FENCE, HAS_FENCE } from './render.mjs'
4
5// The renderer's bundle is 1.6MB, over the 1,048,576 bytes a hooks module
6// will read, so a child process imports it instead. The limit is on what the
7// module graph reads, not on what a process the plugin starts may open.
8const CHILD = new URL('./render-svg.mjs', import.meta.url).pathname
9
10// Naming a font also drops the webfont import the renderer would write. An
11// SVG drawn as an image loads nothing from outside itself, so a link to a
12// font on the network is markup that measures one thing and draws another.
13const FONT = 'system-ui'
14
15const PALETTE = {
16	dark: { bg: '#1e1e1e', fg: '#d4d4d4', line: '#808080', accent: '#4ec9b0' },
17	light: { bg: '#ffffff', fg: '#24292f', line: '#6e7781', accent: '#0550ae' },
18}
19
20const MAX_ENTRIES = 32
21
22/** The elements this draws with; every surface that has `Svg` has these. */
23type Table = {
24	Box: ElementConstructor<BoxProps>
25	Markdown: ElementConstructor<MarkdownProps>
26	Svg: ElementConstructor<SvgProps>
27}
28
29// What a closure would hold: the engine wants each hook declared where it can
30// read it, so the hooks stay small. Resets when the module reloads.
31const drawn = new Map<string, string>()
32let palette: keyof typeof PALETTE | null = null
33
34/** A drawing per fence, markdown for the prose between; null if none drew. */
35async function treeOf(table: Table, text: string, draw: (source: string) => Promise<string | null>) {
36	const children: RenderElement[] = []
37	let read = 0
38
39	for (const match of text.matchAll(FENCE)) {
40		const markup = await draw(match[3] ?? '')
41		if (markup === null) continue
42
43		const before = text.slice(read, match.index)
44		if (before.trim() !== '') children.push(table.Markdown({ text: before }))
45		children.push(table.Svg({ source: markup, alt: altOf(match[3] ?? '') }))
46		read = (match.index ?? 0) + match[0].length
47	}
48
49	if (children.length === 0) return null
50
51	const after = text.slice(read)
52	if (after.trim() !== '') children.push(table.Markdown({ text: after }))
53
54	return table.Box({ flexDirection: 'column', gap: 1, children })
55}
56
57type Runner = {
58	process: {
59		run: (
60			argv: readonly string[],
61			init?: { stdin?: string },
62		) => Promise<{ exitCode: number; stdout: string }>
63	}
64}
65
66/** Draws one source in the child, remembering it by source and palette. */
67async function svgOf($: Runner, source: string) {
68	const key = `${palette}\n${source}`
69	const known = drawn.get(key)
70	if (known !== undefined) return known
71
72	const ask = JSON.stringify({ source, options: { font: FONT, ...PALETTE[palette ?? 'dark'] } })
73	const { exitCode, stdout } = await $.process
74		.run(['node', CHILD], { stdin: ask })
75		.catch(() => ({ exitCode: 1, stdout: '' }))
76
77	if (exitCode !== 0 || stdout === '') return null
78
79	if (drawn.size >= MAX_ENTRIES) drawn.delete(drawn.keys().next().value ?? '')
80	drawn.set(key, stdout)
81	return stdout
82}
83
84// A surface without the element draws nothing else of it, so the alt carries
85// the diagram itself.
86function altOf(source: string) {
87	const kind = source.trim().split(/\s|\n/)[0] ?? 'diagram'
88	const labels = [...source.matchAll(/[[({]"?([^\]"})|]+)"?[\])}]/g)].map(([, label]) => label)
89	return labels.length === 0 ? `A ${kind}` : `A ${kind}: ${labels.join(', ')}`
90}
91
92/**
93 * Registers the drawing on every surface whose element table carries `Svg`:
94 * the editor, the desktop app and the mobile app.
95 *
96 * None of them raises `ui.render` today — the VS Code extension runs the
97 * agent as a stream-json client, where the engine draws nowhere — so this
98 * sits dormant and starts working the day a client attaches, unchanged.
99 *
100 * Written out per surface: the engine reads a matcher off the source, where
101 * a loop variable would not resolve to a surface.
102 *
103 * @param on the engine's registrar
104 */
105export function register(on: On) {
106	on('config.set', { key: 'theme' }, ($, e, next) => {
107		palette = null
108		drawn.clear()
109		$.ui.invalidate('ui.render')
110		return next(e)
111	})
112
113	on('ui.render', { component: 'AssistantMessage', surface: 'vscode', props: { text: HAS_FENCE } }, async ($, e, next) => {
114		await paletteOf($)
115		const { Box, Markdown, Svg } = $.ui.resolve(e)
116		return (await treeOf({ Box, Markdown, Svg }, e.props.text, (source) => svgOf($, source))) ?? next(e)
117	})
118
119	on('ui.render', { component: 'AssistantMessage', surface: 'desktop', props: { text: HAS_FENCE } }, async ($, e, next) => {
120		await paletteOf($)
121		const { Box, Markdown, Svg } = $.ui.resolve(e)
122		return (await treeOf({ Box, Markdown, Svg }, e.props.text, (source) => svgOf($, source))) ?? next(e)
123	})
124
125	on('ui.render', { component: 'AssistantMessage', surface: 'mobile', props: { text: HAS_FENCE } }, async ($, e, next) => {
126		await paletteOf($)
127		const { Box, Markdown, Svg } = $.ui.resolve(e)
128		return (await treeOf({ Box, Markdown, Svg }, e.props.text, (source) => svgOf($, source))) ?? next(e)
129	})
130}
131
132/** Reads the engine's theme once; a failed read is no reason not to draw. */
133async function paletteOf($: { config: { list: () => Promise<readonly { key: string; value: unknown }[]> } }) {
134	if (palette !== null) return
135
136	const rows = await $.config.list().catch(() => [])
137	const theme = rows.find((row) => row.key === 'theme')
138	palette = String(theme?.value ?? 'dark').startsWith('light') ? 'light' : 'dark'
139}
140
hooks/features/mermaid/draw-text.ts 57 lines
1import type { On } from 'claude-code'
2
3import { DEFAULT_COLUMNS, HAS_FENCE, withDrawings } from './render.mjs'
4
5const MAX_ENTRIES = 32
6const MAX_CHARS = 250_000
7const MAX_ENTRY_CHARS = 50_000
8
9// A message re-renders on every frame and every change of width, so laying
10// an unchanged diagram out again is the one cost worth avoiding. Oldest out.
11function remember(drawn: Map<string, string>, key: string, text: string) {
12	drawn.delete(key)
13	if (key.length + text.length > MAX_ENTRY_CHARS) return
14
15	drawn.set(key, text)
16
17	let chars = 0
18	for (const [k, v] of drawn) chars += k.length + v.length
19	for (const [k, v] of drawn) {
20		if (drawn.size <= MAX_ENTRIES && chars <= MAX_CHARS) return
21		drawn.delete(k)
22		chars -= k.length + v.length
23	}
24}
25
26/**
27 * Draws a reply's mermaid fences as text, where they stand. The terminal
28 * alone: the other surfaces carry `Svg` and go through `draw-svg`.
29 *
30 * Box-drawing characters are safe here. A terminal places every character by
31 * cell, so a glyph wider than its cell is clipped rather than allowed to move
32 * its neighbours, and VS Code draws U+2500-U+257F itself rather than from the
33 * font. A webview has neither protection, which is why `message-display.mjs`
34 * draws the same diagrams in ASCII.
35 *
36 * @param on the engine's registrar
37 */
38export function register(on: On) {
39	const drawn = new Map<string, string>()
40
41	on(
42		'ui.render',
43		{ component: 'AssistantMessage', surface: 'terminal', props: { text: HAS_FENCE } },
44		($, e, next) => {
45			const columns = e.viewport?.columns ?? DEFAULT_COLUMNS
46			const key = `${columns}\n${e.props.text}`
47			const text =
48				drawn.get(key) ?? withDrawings(e.props.text, { columns, useAscii: false })
49
50			remember(drawn, key, text)
51
52			if (text === e.props.text) return next(e)
53			return next({ ...e, props: { ...e.props, text } })
54		},
55	)
56}
57
hooks/features/mermaid/guidance.ts 33 lines
1import type { On } from 'claude-code'
2
3const BLOCK = 'mermaidDiagrams'
4
5// Laying a diagram out means counting display columns, and a model counts
6// characters: a label in a wide script is two columns per character and the
7// box comes out crooked. A fence hands that arithmetic to the plugin.
8const GUIDANCE = `Diagrams in your replies are drawn for you. A \`\`\`mermaid fence is laid out and
9drawn on screen for the person, by a plugin, after you
10write it. The person sees the drawing; the fence itself is what you wrote.
11
12So when a reply calls for a diagram - a flow, a sequence, a state machine, a shape of
13a system - write it as a \`\`\`mermaid fence and let it be drawn. flowchart (graph),
14sequenceDiagram, stateDiagram, classDiagram and erDiagram all draw; another kind, or
15one that does not parse, shows its source instead, which is no worse than a fence.
16
17Do not draw a diagram yourself out of box-drawing or ASCII characters. Laying one out
18means counting display columns rather than characters, and a label in a wide script
19takes two columns per character, so a hand-drawn box comes out crooked. Prose, lists
20and tables are unaffected: this is about diagrams alone.`
21
22/**
23 * Adds the guidance to the conversation's first message, unconditionally:
24 * every session draws, one way or another.
25 *
26 * @param on the engine's registrar
27 */
28export function register(on: On) {
29	on('prompt.context', ($, e, next) =>
30		next({ ...e, blocks: [...e.blocks, { name: BLOCK, text: GUIDANCE }] }),
31	)
32}
33
hooks/features/mermaid/render.mjs 83 lines
1// .mjs so both sides can import it: the hooks module, which the engine loads
2// as TypeScript, and hooks/message-display.mjs, which runs as a Node process.
3
4import { renderMermaidASCII } from './vendor/zombie-text.mjs'
5
6/** A closed mermaid fence: indent, ticks, source. */
7export const FENCE = /^([ \t]{0,3})(`{3,}|~{3,})[ \t]*mermaid[^\n]*\n([\s\S]*?)\n[ \t]*\2[ \t]*$/gm
8
9export const HAS_FENCE = /^[ \t]{0,3}(?:`{3,}|~{3,})[ \t]*mermaid[ \t\r]*$/im
10
11export const DEFAULT_COLUMNS = 80
12
13// The renderer leaves five rows between ranks. Three is the least that still
14// puts an edge's label below its box rather than on the border. Box padding
15// is left alone: dropping it saves two rows per box but lets edges route
16// through labels, and `Fai|ed` is what this feature exists to prevent.
17const LAYOUT = { paddingY: 3 }
18
19/** A node's shape and label: `[]`, `()`, `([])`, `(())`, `[[]]`, `{}`. */
20const LABEL = /(?<=[\p{L}\p{N}_])(\[\[|\(\(|\(\[|\{|\[|\()([^\]})\n"|]+)(\]\]|\)\)|\]\)|\}|\]|\))/gu
21
22// Widens a label's margin from one column to two, which a wide script needs:
23// its characters are two columns each. Done to the source, so the renderer
24// measures the padding itself; inserting it into the drawing would move one
25// line and leave the rest. Edge labels get none — the renderer trims them.
26const padded = (source) => source.replace(LABEL, '$1  $2  $3')
27
28// `useAscii` leaves U+2016 in a state diagram's end marker. It is East Asian
29// Ambiguous, so a CJK font draws it two columns wide and shifts its row.
30// One character for one, so nothing moves.
31const asciiOnly = (drawn) => drawn.replace(/‖/gu, '|')
32
33/** East Asian Wide and Fullwidth; halfwidth katakana is narrow, so excluded. */
34const WIDE =
35	/[ᄀ-ᅟ〈〉⺀-〾ぁ-㏿㐀-䶿一-鿿ꀀ-꓏ꥠ-꥿가-힣豈-﫿︐-︙︰-﹯＀-⦆¢-₩]/
36
37export const displayWidth = (line) =>
38	[...line].reduce((columns, ch) => columns + (WIDE.test(ch) ? 2 : 1), 0)
39
40/**
41 * Draws one diagram as text, or answers null to keep the source: it did not
42 * parse, or it is wider than the room, where wrapping would break it.
43 *
44 * @param {string} source the diagram, without its fence
45 * @param {{ columns: number, useAscii: boolean }} options
46 * @returns {string | null}
47 */
48export function drawing(source, { columns, useAscii }) {
49	let text
50	try {
51		text = String(renderMermaidASCII(padded(source), { colorMode: 'none', ...LAYOUT, useAscii }))
52	} catch {
53		return null
54	}
55
56	const lines = (useAscii ? asciiOnly(text) : text)
57		.split('\n')
58		.map((line) => line.replace(/[ \t]+$/, ''))
59	while (lines.length > 0 && lines[lines.length - 1] === '') lines.pop()
60
61	if (lines.length === 0) return null
62	if (lines.some((line) => displayWidth(line) > columns)) return null
63
64	return lines.join('\n')
65}
66
67/**
68 * Replaces every fence with its drawing. One that does not draw keeps its
69 * source, so a failure shows the diagram's text rather than nothing.
70 *
71 * @param {string} text the reply's markdown
72 * @param {{ columns: number, useAscii: boolean }} options
73 * @returns {string}
74 */
75export function withDrawings(text, options) {
76	if (!HAS_FENCE.test(text)) return text
77
78	return text.replace(FENCE, (fence, indent, ticks, source) => {
79		const drawn = drawing(source, options)
80		return drawn === null ? fence : `${indent}${ticks}\n${drawn}\n${indent}${ticks}`
81	})
82}
83
hooks/features/mermaid/vendor/zombie-text.mjs 11 lines
1function Ft(e,t){let r=e.match(/^click\s+([\w\p{L}-]+)\s+(.*)$/iu);if(!r)return;let i=r[1],l=r[2].trim(),n={...t.get(i)},o=l.match(/^(?:call|callback)\s+(.+?)\s*$/i);if(o){let u=o[1].match(/^(.*?\))\s+"([^"]*)"\s*$/);u?(n.callback=u[1].trim(),n.tooltip=u[2]):n.callback=o[1].trim(),t.set(i,n);return}l=l.replace(/^href\s+/i,"");let a=[...l.matchAll(/"([^"]*)"/g)].map(u=>u[1]);a.length>0&&(n.href=a[0]),a.length>1&&(n.tooltip=a[1]);let s=l.match(/(_blank|_self|_parent|_top)\s*$/i);s&&(n.target=s[1].toLowerCase()),(n.href!==void 0||n.tooltip!==void 0)&&t.set(i,n)}function rr(e){if(!e||/[\x00-\x1F\x7F]/.test(e))return;let t=e.trim();if(/^[./#?]/.test(t))return t;let r=t.match(/^([a-zA-Z][a-zA-Z0-9+.-]*):/)?.[1];return r===void 0||/^(https?|mailto)$/i.test(r)?t:void 0}var wi=/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;function Br(e){let t=wi.exec(e.trim());if(!t)return null;let r=t[1];if(r===void 0)return null;let i=r;return(i.length===3||i.length===4)&&(i=i.split("").map(l=>l+l).join("")),{r:parseInt(i.slice(0,2),16),g:parseInt(i.slice(2,4),16),b:parseInt(i.slice(4,6),16),a:i.length===8?parseInt(i.slice(6,8),16)/255:1}}var jr=/^[&#](?:#?[0-9]+|#?[xX][0-9a-fA-F]+|[a-zA-Z][a-zA-Z0-9]*);/,Pr=new Set(["&","#"]);function Mi(e){let t=null;for(let r=0;r<e.length;r++){let i=e[r];if(t!==null){i===t&&(t=null);continue}if(i==='"'||i==="'"){t=i;continue}if(Pr.has(i)){let l=jr.exec(e.slice(r));if(l){r+=l[0].length-1;continue}}if(i==="%"&&e[r+1]==="%")return r}return-1}function vi(e){let t=[],r="",i=null;for(let l=0;l<e.length;l++){let n=e[l];if(i!==null){r+=n,n===i&&(i=null);continue}if(n==='"'||n==="'"){i=n,r+=n;continue}if(Pr.has(n)){let o=jr.exec(e.slice(l));if(o){r+=o[0],l+=o[0].length-1;continue}}if(n===";"){t.push(r),r="";continue}r+=n}return t.push(r),t}function nr(e){let t=[],r=e.split(`
2`);for(let i=0;i<r.length;i++){let l=r[i].trim(),n=i+1,o=Mi(l);if(o!==-1&&(l=l.slice(0,o).trim()),l.length===0)continue;let a=[];for(let s of vi(l)){let u=s.trim();u.length!==0&&a.push({text:u,line:n})}a.length>0&&t.push(a)}return t}function At(e){return nr(e).flat()}function ir(e){let t=At(e)[0]?.text.toLowerCase()??"";return/^xychart(?:-beta)?(?:\s|$)/.test(t)?"xychart":/^sequencediagram\s*$/.test(t)?"sequence":/^classdiagram\s*$/.test(t)?"class":/^erdiagram\s*$/.test(t)?"er":"flowchart"}function zr(e){return e==="TD"||e==="TB"||e==="LR"||e==="BT"||e==="RL"}function kt(e){let t=e?.toUpperCase();if(t===void 0||!zr(t))throw Error(`Invalid direction: "${e}"`);return t}function Yr(e,t){return t===void 0||!zr(t)?e:{...e,direction:t}}var Ai=new Set(["linear","basis","natural","step","stepBefore","stepAfter"]),Xr={theme:"colors come from the caller's bg/fg render options, which are usually CSS variables so a diagram inherits the host page's light/dark. A diagram-supplied theme would hard-code colors that fight it. Mermaid's theme names (default/dark/forest/neutral) also have no equivalent in this renderer's palettes \u2014 pass `bg`/`fg`, or a THEMES entry, instead",securitylevel:"this renderer emits static SVG and never executes diagram-supplied script, so there is no sandbox to configure",defaultrenderer:"ELK is the only layout engine; dagre/elk selection has no effect",fontfamily:"use the `font` render option instead",htmllabels:"labels are always rendered as SVG text; there is no HTML label mode",maxtextsize:"no text-size limit is enforced",startonload:"not a browser auto-render integration"},ki=/^\s*%%\{\s*(?:init|initialize)\s*:\s*([\s\S]*?)\}%%/i;function Ci(e){let t="",r=null;for(let i=0;i<e.length;i++){let l=e[i];if(r!==null){if(l==="\\"&&i+1<e.length){let n=e[i+1];t+=n==="'"?"'":`\\${n}`,i++}else l===r?(r=null,t+='"'):t+=l==='"'?'\\"':l;continue}if(l==='"'||l==="'"){r=l,t+='"';continue}if(/[A-Za-z_$]/.test(l)){let n=i;for(;n<e.length&&/[\w$-]/.test(e[n]);)n++;let o=e.slice(i,n),a=n;for(;a<e.length&&/\s/.test(e[a]);)a++;if(e[a]===":"){t+=`"${o}"`,i=n-1;continue}t+=/^(true|false|null)$/i.test(o)?o.toLowerCase():`"${o}"`,i=n-1;continue}t+=l}return t}function Si(e){let t=e.match(ki);if(!t)return;let r;try{r=JSON.parse(Ci(t[1]))}catch{return}if(typeof r!="object"||!r)return;let i={ignored:[]},l={...r};for(let[n,o]of Object.entries(l)){let a=n.toLowerCase();if(a==="theme"&&typeof o=="string"){i.theme=o,i.ignored.push(n);continue}if(a==="flowchart"&&typeof o=="object"&&o){let s={...o};for(let[u,f]of Object.entries(s)){if(u.toLowerCase()==="curve"&&typeof f=="string"){Ai.has(f)&&(i.curve=f);continue}u.toLowerCase()in Xr&&i.ignored.push(u)}continue}a in Xr&&i.ignored.push(n)}return i}function qr(e){let t={ignored:[]};for(let r of e){let i=Si(r);i&&(i.theme!==void 0&&(t.theme=i.theme),i.curve!==void 0&&(t.curve=i.curve),t.ignored.push(...i.ignored))}return t}function $i(e){return e>=4352&&e<=4447||e>=11904&&e<=12031||e>=12032&&e<=12255||e>=12288&&e<=12351||e>=12352&&e<=12447||e>=12448&&e<=12543||e>=12544&&e<=12591||e>=12592&&e<=12687||e>=12688&&e<=12799||e>=12800&&e<=13311||e>=13312&&e<=19903||e>=19968&&e<=40959||e>=44032&&e<=55215||e>=63744&&e<=64255||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=131072}var Li=/\p{Emoji_Presentation}/u,Di=/\p{Extended_Pictographic}/u;function Ii(e){return e>=9632&&e<=9727}function Ti(e){return e>=8596&&e<=8601||e===8617||e===8618}function Ei(e){if(Li.test(e))return!0;let t=e.codePointAt(0);return t!==void 0&&Ii(t)||t!==void 0&&Ti(t)?!1:Di.test(e)}function Wr(e){let t=e.codePointAt(0);return t===void 0?!1:$i(t)||Ei(e)}function Ee(e){let t=e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e;return(t.length>=2&&t.startsWith("`")&&t.endsWith("`")?t.slice(1,-1):t).replace(/<br\s*\/?>/gi,`
3`).replace(/\\n/g,`
4`).replace(/<\/?(?:sub|sup|small|mark)\s*>/gi,"").replace(/\*\*(.+?)\*\*/g,"<b>$1</b>").replace(/(?<!\*)\*([^\s*](?:[^*]*[^\s*])?)\*(?!\*)/g,"<i>$1</i>").replace(/~~(.+?)~~/g,"<s>$1</s>")}function lr(e){return e.replace(/<\/?(?:b|strong|i|em|u|s|del)\s*>/gi,"")}function zt(e){let t=e.replace(/;\s*$/,""),r={};for(let i of t.split(",")){let l=i.indexOf(":");if(l>0){let n=i.slice(0,l).trim(),o=i.slice(l+1).trim();n&&o&&(r[n]=o)}}return r}function Ht(e,t){let r=e.match(/^classDef\s+([\w,-]+)\s+(.+)$/);if(!r)return!1;let i=zt(r[2]);for(let l of r[1].split(",")){let n=l.trim();n&&t.classDefs.set(n,i)}return!0}function Ot(e,t){let r=e.match(/^class\s+([\w,-]+)\s+([\w-]+)\s*;?\s*$/);if(!r)return!1;let i=r[2];for(let l of r[1].split(","))t.classAssignments.set(l.trim(),i);return!0}function Nr(e,t){let r=e.match(/^cssClass\s+"([^"]*)"\s+([\w-]+)\s*;?\s*$/);if(!r)return!1;let i=r[2];for(let l of r[1].split(",")){let n=l.trim();n&&t.classAssignments.set(n,i)}return!0}function Vt(e,t){let r=e.match(/^style\s+([\w,-]+)\s+(.+)$/);if(!r)return!1;let i=zt(r[2]);for(let l of r[1].split(",").map(n=>n.trim()))t.nodeStyles.set(l,{...t.nodeStyles.get(l),...i});return!0}function Fr(e){let t=e.match(/^(.+?):::([\w][\w-]*)$/);return t?{id:t[1],className:t[2]}:{id:e}}var Qr="<\\|--|<\\|\\.\\.|\\*--|o--|-->|--\\*|--o|--\\|>|\\.\\.>|\\.\\.\\|>|<--|<\\.\\.?|--",Ri=new RegExp(Qr);function Ur(e){let t={classes:[],relationships:[],namespaces:[],interactions:new Map,classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,notes:[]},r=new Map,i=null,l=null,n=0,o;for(let s=1;s<e.length;s++){let u=e[s],f=u.text;if(l&&n>0){if(f==="}"){n--,n===0&&(l=null,o=void 0);continue}let j=f.match(/^<<(\w+)>>$/);if(j){l.annotation=j[1];continue}if(f.startsWith("<<"))throw Error(`Line ${u.line}: Malformed class annotation "${f}" \u2014 expected "<<name>>" (e.g. "<<interface>>").`);or(l,f,u.line);continue}if(/^click\s+/i.test(f)){Ft(f,t.interactions);continue}let h=f.match(/^note\s+(?:for\s+(\S+)\s+)?"([^"]*)"\s*$/);if(h){let j=h[1];t.notes.push({text:Ee(h[2]),...j?{forClass:j}:{}});continue}if(Ht(f,t)||Vt(f,t)||Nr(f,t)||Ot(f,t))continue;let c=f.match(/^namespace\s+(\S+)\s*\{$/);if(c){i={name:c[1],classIds:[]};continue}if(f==="}"&&i){t.namespaces.push(i),i=null;continue}let g=f.match(/^class\s+(\S+?)(?:\s*~(\w+)~)?\s*\{$/);if(g){let j=a(g[1],g[2]);l=r.get(j)??null,n=1,o=u.line;continue}let m=f.match(/^class\s+(\S+?)(?:\s*~(\w+)~)?\s*$/);if(m){a(m[1],m[2]);continue}let x=f.match(/^class\s+(\S+?)\s*\{\s*(.*?)\s*\}$/);if(x){let j=a(x[1],void 0),v=r.get(j),P=x[2],$=P.match(/^<<(\w+)>>$/);if(v&&$)v.annotation=$[1];else{if(v&&P.startsWith("<<"))throw Error(`Line ${u.line}: Malformed class annotation "${P}" \u2014 expected "<<name>>" (e.g. "<<interface>>").`);v&&P&&or(v,P,u.line)}continue}let A=f.match(/^(\S+?)\s*:\s*(.+)$/);if(A){let j=A[2];if(!j.match(/<\|--|--|\*--|o--|-->|\.\.>|\.\.\|>/)){or(Hr(r,A[1]),j,u.line);continue}}let M=ji(f);if(M){M.from=a(M.from,void 0,!1),M.to=a(M.to,void 0,!1),t.relationships.push(M);continue}if(Ri.test(f))throw Error(`Line ${u.line}: Malformed class-diagram relationship "${f}". Expected "FROM ARROW TO" (optionally with cardinalities and a ": label"), e.g. "Animal <|-- Dog" or 'A "1" --> "*" B : label'. ARROW must be one of <|--, <|.., *--, o--, -->, --*, --o, --|>, ..>, ..|>, <--, <.., or --.`)}if(l!==null)throw Error(`Line ${o}: Unclosed class body for "${l.id}" \u2014 expected a closing "}" before the diagram ends.`);return t.classes=[...r.values()],t;function a(s,u,f=!0){let{id:h,className:c}=Fr(s),g=h,m=u;if(!m){let A=h.match(/^(.+?)~(\w+)~$/);A&&(g=A[1],m=A[2])}let x=Hr(r,g);return m&&(x.label=`${g}<${m}>`),c&&t.classAssignments.set(g,c),f&&i&&i.classIds.push(g),g}}function or(e,t,r){let i=Bi(t,r);i&&(i.isMethod?e.methods.push(i.member):e.attributes.push(i.member))}function Hr(e,t){let r=e.get(t);return r||(r={id:t,label:t,attributes:[],methods:[]},e.set(t,r)),r}function sr(e,t){return Math.max(0,e.split(t).length-1)}function Xi(e){let t=sr(e,"~");if(t<=1)return e;let r=e,i=!1;t%2!=0&&r.startsWith("~")&&(r=r.slice(1),i=!0);let l=[...r],n=l.indexOf("~"),o=l.lastIndexOf("~");for(;n!==-1&&o!==-1&&n!==o;)l[n]="<",l[o]=">",n=l.indexOf("~"),o=l.lastIndexOf("~");return i&&l.unshift("~"),l.join("")}function Gt(e){let t=e.split(/(,)/),r=[];for(let i=0;i<t.length;i++){let l=t[i];if(l===","&&i>0&&i+1<t.length){let n=t[i-1],o=t[i+1];sr(n,"~")===1&&sr(o,"~")===1&&(l=`${n},${o}`,i++,r.pop())}r.push(Xi(l))}return r.join("")}function Bi(e,t){let r=e.trim().replace(/;$/,"");if(!r)return null;let i="",l=r,n=l[0];if((n==="+"||n==="-"||n==="#"||n==="~")&&(i=n,l=l.slice(1).trim()),l.includes("(")&&!l.includes(")"))throw Error(`Line ${t}: Malformed class member "${r}" \u2014 unclosed "(" in a method signature. Expected e.g. "+eat() void" or "+eat(Food f) void".`);let o=l.match(/^(.+?)\(([^)]*)\)(?:\s*(.+))?$/);if(o){let c=Gt(o[1].trim()),g=o[2]?.trim(),m=g?Gt(g):void 0,x=o[3]?.trim(),A=x?Gt(x):void 0,M=c.endsWith("$")||l.includes("$"),j=c.endsWith("*")||l.includes("*");return{member:{visibility:i,name:c.replace(/[$*]$/,""),type:A||void 0,isStatic:M,isAbstract:j,isMethod:!0,params:m},isMethod:!0}}let a=Gt(l).split(/\s+/),s,u;a.length>=2?(u=a[0],s=a.slice(1).join(" ")):s=a[0]??l;let f=s.endsWith("$"),h=s.endsWith("*");return{member:{visibility:i,name:s.replace(/[$*]$/,""),type:u||void 0,isStatic:f,isAbstract:h,isMethod:!1},isMethod:!1}}function ji(e){let t=e.match(RegExp(`^(\\S+?)\\s+(?:"([^"]*?)"\\s+)?(${Qr})\\s+(?:"([^"]*?)"\\s+)?(\\S+?)(?::::([\\w][\\w-]*))?(?:\\s*:\\s*(.+))?$`));if(!t)return null;let r=t[1],i=t[2],l=i?Ee(i):void 0,n=t[3].trim(),o=t[4],a=o?Ee(o):void 0,s=t[6]?`${t[5]}:::${t[6]}`:t[5],u=t[7]?.trim(),f=u?Ee(u):void 0,h=Pi(n);return h?{from:r,to:s,type:h.type,markerAt:h.markerAt,label:f,fromCardinality:l,toCardinality:a}:null}function Pi(e){switch(e.trim()){case"<|--":return{type:"inheritance",markerAt:"from"};case"--|>":return{type:"inheritance",markerAt:"to"};case"<|..":return{type:"realization",markerAt:"from"};case"..|>":return{type:"realization",markerAt:"to"};case"*--":return{type:"composition",markerAt:"from"};case"--*":return{type:"composition",markerAt:"to"};case"o--":return{type:"aggregation",markerAt:"from"};case"--o":return{type:"aggregation",markerAt:"to"};case"-->":return{type:"association",markerAt:"to"};case"<--":return{type:"association",markerAt:"from"};case"..>":return{type:"dependency",markerAt:"to"};case"<..":return{type:"dependency",markerAt:"from"};case"--":return{type:"association",markerAt:"to"};default:return null}}function ur(e){return`${e.visibility?`${e.visibility} `:""}${e.isMethod?`${e.name}(${e.params||""})`:e.name}${e.type?`: ${e.type}`:""}`}function Kr(e){let t={entities:[],relationships:[]},r=new Map,i=null;for(let l=1;l<e.length;l++){let n=e[l],o=n.text;if(i){if(o==="}"){i=null;continue}let f=Or(o);f&&i.attributes.push(f);continue}let a=o.match(/^direction\s+(TD|TB|LR|BT|RL)\s*$/i);if(a){t.direction=kt(a[1]);continue}let s=o.match(/^(\S+?)(?:\[(.+)\])?\s*\{(.*)$/);if(s){let f=s[1],h=s[2],c=ar(r,f,h===void 0?void 0:Ee(h.trim().replace(/^["']|["']$/g,""))),g=s[3].trim(),m=g.endsWith("}"),x=m?g.slice(0,-1).trim():g;for(let A of x.split(";").map(M=>M.trim()).filter(Boolean)){let M=Or(A);M&&c.attributes.push(M)}m||(i=c);continue}let u=zi(o,n.line);if(u){ar(r,u.entity1),ar(r,u.entity2),t.relationships.push(u);continue}}return t.entities=[...r.values()],t}function ar(e,t,r){let i=e.get(t);return i?r!==void 0&&(i.label=r):(i={id:t,label:r??t,attributes:[]},e.set(t,i)),i}function Or(e){let t=e.match(/^(\S+)\s+(\S+)(?:\s+(.+))?$/);if(!t)return null;let r=t[1],i=t[2],l=t[3]?.trim()??"",n=[],o,a=l.match(/"([^"]*)"/);a&&(o=Ee(a[1]));let s=l.replace(/"[^"]*"/,"").trim();for(let u of s.split(/\s+/)){let f=u.toUpperCase();(f==="PK"||f==="FK"||f==="UK")&&n.push(f)}return{type:r,name:i,keys:n,comment:o}}function zi(e,t){let r=e.match(/^(\S+)\s+(\S*(?:--|\.\.)\S*)\s+(\S+)\s*(?::\s*(.*))?$/);if(!r)return null;let i=r[1],l=r[2],n=r[3],o=r[4]!==void 0,a=r[4]?.trim()??"",s=l.match(/^([|o}{]*)(--|\.\.?)([|o}{]*)$/),u=s?Yi(s[1]):null,f=s?qi(s[3]):null;if(!u||!f)throw Error(`Line ${t}: Invalid ER relationship cardinality "${l}" in "${e}". Left side must be one of ||, |o, }|, }o; right side must be one of ||, o|, |{, o{ (e.g. "||--o{").`);if(!o||a.length===0)throw Error(`Line ${t}: ER relationship "${i} ${l} ${n}" is missing a ": label" \u2014 expected e.g. "${i} ${l} ${n} : label".`);return{entity1:i,entity2:n,cardinality1:u,cardinality2:f,label:Ee(a.replace(/^["']|["']$/g,"")),identifying:s[2]==="--"}}function Yi(e){return e==="||"?"one":e==="|o"?"zero-one":e==="}|"?"many":e==="}o"?"zero-many":null}function qi(e){return e==="||"?"one":e==="o|"?"zero-one":e==="|{"?"many":e==="o{"?"zero-many":null}var Wi=new Set("aliceblue antiquewhite aqua aquamarine azure beige bisque black blanchedalmond blue blueviolet brown burlywood cadetblue chartreuse chocolate coral cornflowerblue cornsilk crimson cyan darkblue darkcyan darkgoldenrod darkgray darkgreen darkgrey darkkhaki darkmagenta darkolivegreen darkorange darkorchid darkred darksalmon darkseagreen darkslateblue darkslategray darkslategrey darkturquoise darkviolet deeppink deepskyblue dimgray dimgrey dodgerblue firebrick floralwhite forestgreen fuchsia gainsboro ghostwhite gold goldenrod gray green greenyellow grey honeydew hotpink indianred indigo ivory khaki lavender lavenderblush lawngreen lemonchiffon lightblue lightcoral lightcyan lightgoldenrodyellow lightgray lightgreen lightgrey lightpink lightsalmon lightseagreen lightskyblue lightslategray lightslategrey lightsteelblue lightyellow lime limegreen linen magenta maroon mediumaquamarine mediumblue mediumorchid mediumpurple mediumseagreen mediumslateblue mediumspringgreen mediumturquoise mediumvioletred midnightblue mintcream mistyrose moccasin navajowhite navy oldlace olive olivedrab orange orangered orchid palegoldenrod palegreen paleturquoise palevioletred papayawhip peachpuff peru pink plum powderblue purple rebeccapurple red rosybrown royalblue saddlebrown salmon sandybrown seagreen seashell sienna silver skyblue slateblue slategray slategrey snow springgreen steelblue tan teal thistle tomato turquoise violet wheat white whitesmoke yellow yellowgreen".split(" ")),Ni=/^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,Fi=/^(?:rgba?|hsla?)\(\s*[\d.%]+(?:[\s,/]+[\d.%]+){2,3}\s*\)$/i;function Hi(e){return Wi.has(e.toLowerCase())||Ni.test(e)||Fi.test(e)}function Oi(e){let t=e.trim(),r=t.match(/^((?:rgba?|hsla?)\s*\([^)]*\)|#[0-9a-fA-F]+|\S+)?(.*)$/),i=r?.[1]??"",l=r?.[2]?.trim()??"";return i.toLowerCase()==="transparent"?{label:l}:i!==""&&Hi(i)?{color:i,label:l}:{label:t}}function Vi(e){return e==="loop"||e==="alt"||e==="opt"||e==="par"||e==="critical"||e==="break"||e==="rect"}function Gi(e){if(!Vi(e))throw Error(`Invalid block type: "${e}"`);return e}var Ji=/^(.+?)\s*(<<->>|<<-->>|--?>?>)\s*([+-]?)(.+?)\s*:\s*(.+)$/,Zi=/^(.+?)\s*(<<->>|<<-->>|--?>?>|--?[)x]|--?>>|--?>)\s*([+-]?)(.+?)\s*:\s*(.+)$/;function _r(e){let t={actors:[],messages:[],blocks:[],notes:[],activations:[],boxes:[]},r={open:void 0,membership:new Map},i=0,l,n=new Set,o=[],a={enabled:!1,next:1,step:1},s,u;for(let f=1;f<e.length;f++){let h=e[f],c=h.text,g=c.match(/^box(?:\s+(.*))?$/);if(g){if(r.open!==void 0)throw Error(`Line ${h.line}: Sequence diagram: a box cannot be nested inside another box \u2014 close the open box with "end" first`);let{color:Q,label:K}=Oi(g[1]??""),Ce={label:Ee(K),actorIds:[]};Q!==void 0&&(Ce.color=Q),t.boxes.push(Ce),r.open=t.boxes.length-1,i=o.length,l=h.line;continue}let m=c.match(/^create\s+(participant|actor)\s+(\S+?)(?:\s+as\s+(.+))?$/);if(m){let Q=m[1]==="actor"?"actor":"participant",K=m[2];if(n.has(K))throw Error(`Line ${h.line}: It is not possible to have actors with the same id, even if one is destroyed before the next is created. Use 'AS' aliases to simulate the behavior`);n.add(K),t.actors.push({id:K,label:Ee(m[3]?.trim()??K),type:Q}),fr(t,r,K,h.line),s=K;continue}let x=c.match(/^destroy\s+(.+)$/);if(x){let Q=x[1].trim();Yt(t,n,r,Q,h.line),u=Q;continue}let A=c.match(/^autonumber(?:\s+(off|\d+(?:\.\d{1,2})?)(?:\s+(\d+(?:\.\d{1,2})?))?)?$/);if(A){let Q=A[1],K=A[2];Q==="off"?a.enabled=!1:(a.enabled=!0,a.next=Q===void 0?1:Number(Q),a.step=K===void 0?1:Number(K));continue}let M=c.match(/^(participant|actor)\s+(\S+?)(?:\s+as\s+(.+))?$/);if(M){let Q=M[1]==="actor"?"actor":"participant",K=M[2],Ce=M[3]?.trim()??K,ue=Ee(Ce);n.has(K)||(n.add(K),t.actors.push({id:K,label:ue,type:Q})),fr(t,r,K,h.line);continue}let j=c.match(/^Note\s+(left of|right of|over)\s+([^:]+):\s*(.+)$/i);if(j){let Q=j[1].toLowerCase(),K=j[2].trim(),Ce=Ee(j[3].trim()),ue=K.split(",").map(F=>F.trim());for(let F of ue)Yt(t,n,r,F,h.line);let Me="over";Q==="left of"?Me="left":Q==="right of"&&(Me="right"),t.notes.push({actorIds:ue,text:Ce,position:Me,afterIndex:t.messages.length-1});continue}let v=c.match(/^(loop|alt|opt|par|critical|break|rect)\s*(.*)$/);if(v){let Q=Gi(v[1]),K=v[2]?.trim()??"",Ce=Ee(K);o.push({type:Q,label:Ce,startIndex:t.messages.length,dividers:[],line:h.line});continue}let P=c.match(/^(else|and)\s*(.*)$/);if(P&&o.length>0){let Q=P[2]?.trim()??"",K=Ee(Q);o[o.length-1].dividers.push({index:t.messages.length,label:K});continue}if(c==="end"&&r.open!==void 0&&o.length===i){r.open=void 0,l=void 0;continue}if(c==="end"&&o.length>0){let Q=o.pop();t.blocks.push({type:Q.type,label:Q.label,startIndex:Q.startIndex,endIndex:Math.max(t.messages.length-1,Q.startIndex),dividers:Q.dividers});continue}if(c==="end")throw Error(`Line ${h.line}: Sequence diagram: "end" does not match any open block ("loop"/"alt"/"opt"/"par"/"critical"/"break"/"rect") or "box" \u2014 nothing is currently open to close.`);let $=c.match(/^(activate|deactivate)\s+(.+)$/);if($){let Q=$[2].trim();Yt(t,n,r,Q,h.line),t.activations.push({actorId:Q,kind:$[1]==="activate"?"start":"end",afterIndex:t.messages.length-1});continue}let V=c.match(Ji)??c.match(Zi);if(V){let Q=V[2],K=V[4][0];if(K===">"||K===")")throw Error(`Line ${h.line}: Malformed sequence-diagram arrow in "${c}" \u2014 "${Q}${K}" is not a recognized arrow. Expected one of: ->, -->, ->>, -->>, -x, --x, -), --), <<->>, <<-->>.`);Qi(t,n,r,a,V[1],V[2],V[3],V[4],V[5],h.line);let Ce=t.messages.length-1,ue=t.messages[Ce];if(s!==void 0){if(ue.to!==s)throw Error(`Line ${h.line}: The created participant ${s} does not have an associated creating message after its declaration. Please check the sequence diagram.`);Vr(t,s).createdAt=Ce,s=void 0}if(u!==void 0){if(ue.from!==u&&ue.to!==u)throw Error(`Line ${h.line}: The destroyed participant ${u} does not have an associated destroying message after its declaration. Please check the sequence diagram.`);Vr(t,u).destroyedAt=Ce,u=void 0}continue}}if(o.length>0){let f=o[o.length-1];throw Error(`Line ${f.line}: Sequence diagram: unclosed "${f.type}" block \u2014 expected a matching "end" before the diagram ends.`)}if(r.open!==void 0){let f=t.boxes[r.open];throw Error(`Line ${l}: Sequence diagram: unclosed "box${f.label?` ${f.label}`:""}" \u2014 expected a matching "end" before the diagram ends.`)}return t}function Vr(e,t){let r=e.actors.find(i=>i.id===t);if(r===void 0)throw Error(`Sequence diagram: unknown actor "${t}"`);return r}function Yt(e,t,r,i,l){t.has(i)||(t.add(i),e.actors.push({id:i,label:i,type:"participant"})),fr(e,r,i,l)}function fr(e,t,r,i){let l=t.open;if(l===void 0)return;let n=t.membership.get(r);if(n!==l){if(n!==void 0){let o=e.boxes[n].label,a=e.boxes[l].label;throw Error(`Line ${i}: A same participant should only be defined in one Box: ${r} can't be in '${o}' and in '${a}' at the same time.`)}t.membership.set(r,l),e.boxes[l].actorIds.push(r)}}function Qi(e,t,r,i,l,n,o,a,s,u){Yt(e,t,r,l,u),Yt(e,t,r,a,u);let f=n==="<<->>"||n==="<<-->>",h=f?n==="<<-->>"?"dashed":"solid":n.startsWith("--")?"dashed":"solid",c=n.includes(">>")||n.includes("x")?"filled":"open",g=n.includes("x"),m={from:l,to:a,label:Ee(s.trim()),lineStyle:h,arrowHead:c};g&&(m.isLost=!0),f&&(m.bidirectional=!0),o==="+"&&(m.activate=!0),o==="-"&&(m.deactivate=!0),i.enabled&&(m.seqNumber=i.next,i.next=Math.round((i.next+i.step)*100)/100),e.messages.push(m)}function en(e){let t={},r={},i=[],l,n=!1;for(let o of e){let a=o.text;if(/^xychart(-beta)?\b/i.test(a)){/\bhorizontal\b/i.test(a)&&(n=!0);continue}let s=a.match(/^title\s+"([^"]+)"/);if(s){l=s[1];continue}let u=a.match(/^x-axis\s+(?:"([^"]*)"\s*)?\[([^\]]+)\]/);if(u){u[1]&&(t.title=u[1]),t.categories=Ui(u[2]).map(A=>Ki(A.trim()));continue}let f=a.match(/^x-axis\s+(?:"([^"]*)"\s+)?(-?\d+(?:\.\d+)?)\s*-->\s*(-?\d+(?:\.\d+)?)/);if(f){f[1]&&(t.title=f[1]),t.range={min:parseFloat(f[2]),max:parseFloat(f[3])};continue}let h=a.match(/^y-axis\s+(?:"([^"]*)"\s+)?(-?\d+(?:\.\d+)?)\s*-->\s*(-?\d+(?:\.\d+)?)/);if(h){h[1]&&(r.title=h[1]),r.range={min:parseFloat(h[2]),max:parseFloat(h[3])};continue}let c=a.match(/^y-axis\s+"([^"]+)"\s*$/);if(c){r.title=c[1];continue}let g=a.match(/^bar\s+\[([^\]]+)\]/);if(g){i.push({type:"bar",data:Gr(g[1],"bar",a,o.line)});continue}let m=a.match(/^line\s+\[([^\]]+)\]/);if(m){i.push({type:"line",data:Gr(m[1],"line",a,o.line)});continue}let x=a.match(/^(x-axis|y-axis|bar|line|title)\b/i);if(x)throw el(x[1].toLowerCase(),a,o.line)}if(!r.range&&i.length>0){let o=i.flatMap(f=>f.data),a=Math.min(...o),s=Math.max(...o),u=s-a||1;a-=u*.1,s+=u*.1,a>0&&a<u*.5&&(a=0),r.range={min:a,max:s}}return r.range||={min:0,max:100},{title:l,horizontal:n,xAxis:t,yAxis:r,series:i}}function Ui(e){let t=[],r="",i=!1;for(let l of e)l==='"'?(i=!i,r+=l):l===","&&!i?(t.push(r),r=""):r+=l;return t.push(r),t}function Ki(e){return e.length>=2&&e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function Gr(e,t,r,i){return e.split(",").map((l,n)=>{let o=l.trim(),a=parseFloat(o);if(o.length===0||Number.isNaN(a))throw Error(`Line ${i}: Invalid numeric value ${JSON.stringify(o)} at position ${n+1} in "${r}". Every value in a ${t} [...] list must be a number.`);return a})}var _i={"x-axis":"x-axis [A, B, C] (categories) or x-axis 0 --> 100 (numeric range), either optionally preceded by a quoted title","y-axis":'y-axis 0 --> 100 (numeric range) or y-axis "Title" (title only), optionally preceded by a quoted title before a range',bar:"bar [10, 20, 30] \u2014 a comma-separated numeric array in square brackets",line:"line [10, 20, 30] \u2014 a comma-separated numeric array in square brackets",title:'title "Chart Title" \u2014 a double-quoted string'};function el(e,t,r){let i=_i[e]??e;return Error(`Line ${r}: Malformed xychart-beta "${e}" directive: "${t}". Expected: ${i}.`)}var cr="#3b82f6";function tn(e){let t=e.replace("#",""),r=parseInt(t.substring(0,2),16)/255,i=parseInt(t.substring(2,4),16)/255,l=parseInt(t.substring(4,6),16)/255,n=Math.max(r,i,l),o=Math.min(r,i,l),a=(n+o)/2;if(n===o)return[0,0,a*100];let s=n-o,u=a>.5?s/(2-n-o):s/(n+o),f;return f=n===r?((i-l)/s+(i<l?6:0))/6:n===i?((l-r)/s+2)/6:((r-i)/s+4)/6,[f*360,u*100,a*100]}function tl(e,t,r){let i=t/100,l=r/100,n=(1-Math.abs(2*l-1))*i,o=n*(1-Math.abs(e/60%2-1)),a=l-n/2,s,u,f;e<60?(s=n,u=o,f=0):e<120?(s=o,u=n,f=0):e<180?(s=0,u=n,f=o):e<240?(s=0,u=o,f=n):e<300?(s=o,u=0,f=n):(s=n,u=0,f=o);let h=c=>Math.round((c+a)*255).toString(16).padStart(2,"0");return`#${h(s)}${h(u)}${h(f)}`}function Jr(e){return/^#[0-9a-fA-F]{6}$/.test(e)}function rl(e){return tn(e)[2]<50}function rn(e,t,r){if(e===0)return t;let i=Jr(t)?t:cr,l=r&&Jr(r)?r:void 0,[n,o]=tn(i),a=Math.max(55,Math.min(85,o)),s=Math.ceil(e/2),u=e%2==1,f=l&&rl(l)?!u:u,h=f?Math.max(25,48-s*13):Math.min(78,55+s*11);return tl(((n+(f?-8:12)*s)%360+360)%360,a,h)}var nl={rect:"rectangle",rectangle:"rectangle",proc:"rectangle",process:"rectangle","normal-rect":"rectangle",rounded:"rounded",event:"rounded","rounded-rect":"rounded",stadium:"stadium",pill:"stadium",terminal:"stadium",subproc:"subroutine",subprocess:"subroutine",subroutine:"subroutine","framed-rectangle":"subroutine","fr-rect":"subroutine",cyl:"cylinder",cylinder:"cylinder",db:"cylinder",database:"cylinder","h-cyl":"cylinder",das:"cylinder","horizontal-cylinder":"cylinder","lin-cyl":"cylinder","lined-cylinder":"cylinder",disk:"cylinder",circ:"circle",circle:"circle",start:"circle","dbl-circ":"doublecircle","double-circle":"doublecircle",stop:"doublecircle","f-circ":"filled-circle","filled-circle":"filled-circle",junction:"filled-circle","cross-circ":"crossed-circle","crossed-circle":"crossed-circle",summary:"crossed-circle",diam:"diamond",diamond:"diamond",decision:"diamond",question:"diamond",hex:"hexagon",hexagon:"hexagon",prepare:"hexagon",odd:"asymmetric","rect-left-inv-arrow":"asymmetric","lean-r":"parallelogram","lean-right":"parallelogram","in-out":"parallelogram","lean-l":"parallelogram-alt","lean-left":"parallelogram-alt","out-in":"parallelogram-alt","trap-b":"trapezoid","trapezoid-bottom":"trapezoid",priority:"trapezoid","trap-t":"trapezoid-alt","trapezoid-top":"trapezoid-alt",manual:"trapezoid-alt","curv-trap":"trapezoid-alt","curved-trapezoid":"trapezoid-alt",display:"trapezoid-alt",doc:"document",document:"document","lin-doc":"document","lined-document":"document","tag-doc":"document","tagged-document":"document",docs:"stacked-document",documents:"stacked-document","st-doc":"stacked-document","stacked-document":"stacked-document","notch-rect":"card",card:"card","notched-rectangle":"card","lin-rect":"lined-process","lined-rectangle":"lined-process","lin-proc":"lined-process","shaded-process":"lined-process","div-rect":"divided-process","divided-rectangle":"divided-process","div-proc":"divided-process","tag-rect":"rectangle","tagged-rectangle":"rectangle","tag-proc":"rectangle",procs:"stacked-process",processes:"stacked-process","st-rect":"stacked-process","stacked-rectangle":"stacked-process",tri:"triangle",triangle:"triangle",extract:"triangle","flip-tri":"flipped-triangle","flipped-triangle":"flipped-triangle","manual-file":"flipped-triangle","win-pane":"window-pane","window-pane":"window-pane","internal-storage":"window-pane",fork:"fork-join",join:"fork-join","long-rect":"fork-join","notch-pent":"notched-pentagon","loop-limit":"notched-pentagon","notched-pentagon":"notched-pentagon","sl-rect":"sloped-rectangle","sloped-rectangle":"sloped-rectangle","manual-input":"sloped-rectangle",flag:"flag","paper-tape":"flag","bow-rect":"bow-tie-rectangle","bow-tie-rectangle":"bow-tie-rectangle","stored-data":"bow-tie-rectangle",delay:"half-rounded-rectangle","half-rounded-rectangle":"half-rounded-rectangle",brace:"brace","brace-l":"brace",comment:"brace","brace-r":"brace-right",braces:"braces",bolt:"bolt","com-link":"bolt","lightning-bolt":"bolt",text:"text",anchor:"anchor"};function nn(e){return nl[e.trim().toLowerCase()]}function hr(e){let t={};for(let r of il(e,",")){let i=r.trim();if(i.length===0)continue;let l=ll(i,":");if(l===-1){t.shape??=Zr(i);continue}let n=i.slice(0,l).trim().toLowerCase(),o=Zr(i.slice(l+1).trim());n.length>0&&(t[n]=o)}return t}function il(e,t){let r=[],i="",l=null;for(let n of e){if(l!==null){i+=n,n===l&&(l=null);continue}if(n==='"'||n==="'"){l=n,i+=n;continue}if(n===t){r.push(i),i="";continue}i+=n}return r.push(i),r}function ll(e,t){let r=null;for(let i=0;i<e.length;i++){let l=e[i];if(r!==null){l===r&&(r=null);continue}if(l==='"'||l==="'"){r=l;continue}if(l===t)return i}return-1}function Zr(e){return e.length>=2&&(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))?e.slice(1,-1):e}function dr(e){if(!e.startsWith("@{"))return;let t=0,r=null;for(let i=1;i<e.length;i++){let l=e[i];if(r!==null){l===r&&(r=null);continue}if(l==='"'||l==="'"){r=l;continue}if(l==="{"){t++;continue}if(l==="}"&&(t--,t===0))return{body:e.slice(2,i),length:i+1}}}function En(e){return[e.length-1,(e[0]?.length??1)-1]}var ln="\x1B]8;;\x1B\\";function ol(e){return`\x1B]8;;${e.replace(/[^\x21-\x7e]/gu,t=>encodeURIComponent(t))}\x1B\\`}var al=/\x1b\]8;[^\x07\x1b]*(?:\x1b\\|\x07)/g;function sl(e){return e.replace(al,"")}function Rn(e,t){let r=[];for(let i=0;i<=e;i++){let l=[];for(let n=0;n<=t;n++)l.push(null);r.push(l)}return r}function fl(e,t,r,i){let l=e[t];l===void 0||r<0||r>=l.length||(l[r]=i)}function ul(e){for(let t of e)t.reverse();return e}function Xn(e,t,r,i,l){let[n,o]=En(t),a=Math.max(1,l?.from??1),s=Math.min(o-1,l?.to??o-1);for(let u=a;u<=s;u++){let f=-1,h=-1;for(let c=1;c<=n-1;c++)t[c]?.[u]!==" "&&(f===-1&&(f=c),h=c);if(f!==-1)for(let c=f;c<=h;c++)fl(e,c+r.x,u+r.y,i)}}function cl(e,t){let[r,i]=En(e.canvas),l=Rn(r,i);for(let n of e.nodes){if(!n.drawing||!n.drawingCoord)continue;let o=rr(t.get(n.name)?.href);o!==void 0&&Xn(l,n.drawing,n.drawingCoord,o)}return l}var Bn=class{current=null;advance(e){if(e===this.current)return"";let t=this.current===null?"":ln;return e!==null&&(t+=ol(e)),this.current=e,t}finish(){let e=this.current===null?"":ln;return this.current=null,e}};function jn(e,t){let r=new Bn,i="";for(let[l,n]of e.entries())i+=r.advance(t[l]??null)+n;return i+r.finish()}var Pn={fg:"#27272a",border:"#a1a1aa",line:"#71717a",arrow:"#52525b",corner:"#71717a",junction:"#a1a1aa"};function hl(){let e=globalThis.process;if(e){if(!e.stdout?.isTTY)return"none";let t=e.env?.COLORTERM?.toLowerCase()??"",r=e.env?.TERM?.toLowerCase()??"";return t==="truecolor"||t==="24bit"?"truecolor":r.includes("256color")||r.includes("256")?"ansi256":r&&r!=="dumb"?"ansi16":"none"}return typeof document<"u"?"html":"none"}function $r(e){return Br(e.startsWith("#")?e:`#${e}`)??{r:0,g:0,b:0}}var _t="\x1B[",Qt=`${_t}0m`;function zn(e){let{r:t,g:r,b:i}=$r(e);return`${_t}38;2;${t};${r};${i}m`}function dl(e,t,r){let i=(e+t+r)/3;if(Math.max(Math.abs(e-i),Math.abs(t-i),Math.abs(r-i))<10){let s=Math.round(i/255*23);return 232+Math.min(23,Math.max(0,s))}let l=s=>s<48?0:s<115?1:Math.min(5,Math.floor((s-35)/40)),n=l(e),o=l(t),a=l(r);return 16+36*n+6*o+a}function Yn(e){let{r:t,g:r,b:i}=$r(e);return`${_t}38;5;${dl(t,r,i)}m`}function qn(e){let{r:t,g:r,b:i}=$r(e),l=.299*t+.587*r+.114*i,n=l>100?0:60,o;return o=t>180&&r<100&&i<100?31:r>180&&t<100&&i<100?32:t>150&&r>150&&i<100?33:i>180&&t<100&&r<100?34:t>150&&i>150&&r<100?35:r>150&&i>150&&t<100?36:l>200?37:l<50?30:37,`${_t}${o+n}m`}function Wn(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Nn(e,t){return`<span style="color:${e}">${Wn(t)}</span>`}function Fn(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 gr(e,t,r){if(r==="none")return"";let i=Fn(e,t);switch(r){case"truecolor":return zn(i);case"ansi256":return Yn(i);case"ansi16":return qn(i);default:return""}}function gl(e,t,r,i,l){if(i==="none")return l?jn(e,l):e.join("");if(i==="html")return ml(e,t,r);let n=new Bn,o="",a=null,s="";for(let[u,f]of e.entries()){let h=t[u]??null,c=l?n.advance(l[u]??null):"";if(f===" "){s.length>0&&(o+=a===null?s:gr(a,r,i)+s+Qt,s="",a=null),o+=c+f;continue}if(h===a){s+=c+f;continue}s.length>0&&(o+=a===null?s:gr(a,r,i)+s+Qt),s=c+f,a=h}return s.length>0&&a!==null?o+=gr(a,r,i)+s+Qt:s.length>0&&(o+=s),o+n.finish()}function ml(e,t,r){let i="",l=null,n="",o=()=>{n.length!==0&&(i+=l===null?Wn(n):Nn(Fn(l,r),n),n="",l=null)};for(let[a,s]of e.entries()){let u=t[a]??null;if(s===" "){o(),i+=" ";continue}if(u===l){n+=s;continue}o(),n=s,l=u}return o(),i}function mr(e,t,r){if(r==="none"||e.length===0)return e;if(r==="html")return Nn(t,e);let i;switch(r){case"truecolor":i=zn(t);break;case"ansi256":i=Yn(t);break;case"ansi16":i=qn(t);break;default:return e}return`${i}${e}${Qt}`}var pl=/\p{Mn}|\p{Me}/u;function xl(e){return pl.test(e)}var yl=new Intl.Segmenter(void 0,{granularity:"grapheme"}),bl="\uFE0F";function Hn(e){let t=[];for(let{segment:r}of yl.segment(e))t.push(r);return t}function On(e){if(e.includes(bl))return 2;let t=!1,r=!1;for(let i of e)Wr(i)&&(t=!0),xl(i)||(r=!0);return t?2:+!!r}function Pe(e){let t=0;for(let r of Hn(e))t+=On(r);return t}function rt(e){let t=[];for(let r of Hn(e)){let i=On(r);i!==0&&(t.push(r),i===2&&t.push(""))}return t}function qe(e,t){let r=[];for(let i=0;i<=e;i++){let l=[];for(let n=0;n<=t;n++)l.push(" ");r.push(l)}return r}function Be(e){let[t,r]=Mt(e);return qe(t,r)}function Pt(e,t){let r=[];for(let i=0;i<=e;i++){let l=[];for(let n=0;n<=t;n++)l.push(null);r.push(l)}return r}function dt(e,t,r){let i=e.length-1,l=(e[0]?.length??1)-1,n=Pt(Math.max(t,i),Math.max(r,l));for(let o=0;o<n.length;o++)for(let a=0;a<(n[0]?.length??0);a++)o<e.length&&a<(e[0]?.length??0)&&(n[o][a]=e[o][a]);return e.length=0,e.push(...n),e}function er(e,t,r,i){(t>=e.length||r>=(e[0]?.length??0))&&dt(e,t,r),e[t][r]=i}function Mt(e){return[e.length-1,(e[0]?.length??1)-1]}function st(e,t,r){let[i,l]=Mt(e),n=qe(Math.max(t,i),Math.max(r,l));for(let o=0;o<n.length;o++)for(let a=0;a<(n[0]?.length??0);a++)o<e.length&&a<(e[0]?.length??0)&&(n[o][a]=e[o][a]);return e.length=0,e.push(...n),e}function G(e,t,r,i,l){let[n,o]=Mt(e);t<0||t>n||r<0||r>o||(e[t][r]=i,l&&er(l.roleCanvas,t,r,l.role))}var wl=new Set(["\u2500","\u2502","\u250C","\u2510","\u2514","\u2518","\u251C","\u2524","\u252C","\u2534","\u253C","\u2574","\u2575","\u2576","\u2577"]);function jt(e){return wl.has(e)}function on(e){return/^[a-zA-Z0-9]$/.test(e)}var Ml={"\u2500":{"\u2502":"\u253C","\u250C":"\u252C","\u2510":"\u252C","\u2514":"\u2534","\u2518":"\u2534","\u251C":"\u253C","\u2524":"\u253C","\u252C":"\u252C","\u2534":"\u2534"},"\u2502":{"\u2500":"\u253C","\u250C":"\u251C","\u2510":"\u2524","\u2514":"\u251C","\u2518":"\u2524","\u251C":"\u251C","\u2524":"\u2524","\u252C":"\u253C","\u2534":"\u253C"},"\u250C":{"\u2500":"\u252C","\u2502":"\u251C","\u2510":"\u252C","\u2514":"\u251C","\u2518":"\u253C","\u251C":"\u251C","\u2524":"\u253C","\u252C":"\u252C","\u2534":"\u253C"},"\u2510":{"\u2500":"\u252C","\u2502":"\u2524","\u250C":"\u252C","\u2514":"\u253C","\u2518":"\u2524","\u251C":"\u253C","\u2524":"\u2524","\u252C":"\u252C","\u2534":"\u253C"},"\u2514":{"\u2500":"\u2534","\u2502":"\u251C","\u250C":"\u251C","\u2510":"\u253C","\u2518":"\u2534","\u251C":"\u251C","\u2524":"\u253C","\u252C":"\u253C","\u2534":"\u2534"},"\u2518":{"\u2500":"\u2534","\u2502":"\u2524","\u250C":"\u253C","\u2510":"\u2524","\u2514":"\u2534","\u251C":"\u253C","\u2524":"\u2524","\u252C":"\u253C","\u2534":"\u2534"},"\u251C":{"\u2500":"\u253C","\u2502":"\u251C","\u250C":"\u251C","\u2510":"\u253C","\u2514":"\u251C","\u2518":"\u253C","\u2524":"\u253C","\u252C":"\u253C","\u2534":"\u253C"},"\u2524":{"\u2500":"\u253C","\u2502":"\u2524","\u250C":"\u253C","\u2510":"\u2524","\u2514":"\u253C","\u2518":"\u2524","\u251C":"\u253C","\u252C":"\u253C","\u2534":"\u253C"},"\u252C":{"\u2500":"\u252C","\u2502":"\u253C","\u250C":"\u252C","\u2510":"\u252C","\u2514":"\u253C","\u2518":"\u253C","\u251C":"\u253C","\u2524":"\u253C","\u2534":"\u253C"},"\u2534":{"\u2500":"\u2534","\u2502":"\u253C","\u250C":"\u253C","\u2510":"\u253C","\u2514":"\u2534","\u2518":"\u2534","\u251C":"\u253C","\u2524":"\u253C","\u252C":"\u253C"}};function Vn(e,t){return Ml[e]?.[t]??e}function vl(e){let t=new Map,r=[];for(let i of e){let[l,n]=Mt(i),o=Be(i);for(let a=0;a<=l;a++)for(let s=0;s<=n;s++){let u=i[a]?.[s];if(u===void 0||u===" ")continue;let f=`${a},${s}`,h=t.get(f);if(h!==void 0){if(!(h!==u&&jt(h)&&jt(u)))continue}else t.set(f,u);o[a][s]=u}r.push(o)}return r}function ut(e,t,r,...i){let[l,n]=Mt(e);for(let a of i){let[s,u]=Mt(a);l=Math.max(l,s+t.x),n=Math.max(n,u+t.y)}let o=qe(l,n);for(let a=0;a<=l;a++)for(let s=0;s<=n;s++)a<e.length&&s<(e[0]?.length??0)&&(o[a][s]=e[a][s]);for(let a of i)for(let s=0;s<a.length;s++)for(let u=0;u<(a[0]?.length??0);u++){let f=a[s][u];if(f!==" "){let h=s+t.x,c=u+t.y,g=o[h][c];!r&&jt(f)&&jt(g)?o[h][c]=Vn(g,f):on(g)&&on(f)||(o[h][c]=f)}}return o}function tr(e,t){let[r,i]=Mt(e),l=[],n=t?.roleCanvas,o=t?.colorMode??"none",a=t?.theme??Pn,s=o==="html"?void 0:t?.linkCanvas;for(let u=0;u<=i;u++)if(o==="none"||!n){let f=[];for(let h=0;h<=r;h++)f.push(e[h][u]);if(s){let h=f.map((c,g)=>s[g]?.[u]??null);l.push(jn(f,h))}else l.push(f.join(""))}else{let f=[],h=[],c=[];for(let g=0;g<=r;g++)f.push(e[g][u]),h.push(n[g]?.[u]??null),c.push(s?.[g]?.[u]??null);l.push(gl(f,h,a,o,s?c:void 0))}return l.join(`
5`)}var Al={"\u25B2":"\u25BC","\u25BC":"\u25B2","\u2196":"\u2199","\u2199":"\u2196","\u2197":"\u2198","\u2198":"\u2197","^":"v",v:"^","\u250C":"\u2514","\u2514":"\u250C","\u2510":"\u2518","\u2518":"\u2510","\u252C":"\u2534","\u2534":"\u252C","\u2575":"\u2577","\u2577":"\u2575"};function kl(e){for(let t of e)t.reverse();for(let t of e)for(let[r,i]of t.entries()){let l=Al[i];l&&(t[r]=l)}return e}function Cl(e){for(let t of e)t.reverse();return e}function Sl(e,t,r,i=!1){let l=rt(r);st(e,t.x+l.length,t.y);for(let[n,o]of l.entries()){let a=t.x+n,s=e[a][t.y];(i||s===" ")&&(e[a][t.y]=o)}}function $l(e,t,r,i=0,l=0){let n=i,o=l;for(let a of t.values())n+=a;for(let a of r.values())o+=a;st(e,n-1,o-1)}function Ll(e,t,r,i=0,l=0){let n=i,o=l;for(let a of t.values())n+=a;for(let a of r.values())o+=a;dt(e,n-1,o-1)}var Gn=60,Jn=20,Dl={hLine:"\u2500",vLine:"\u2502",origin:"\u253C",yTick:"\u2524",xTick:"\u252C",bar:"\u2588",grid:"\xB7",cornerTL:"\u256D",cornerTR:"\u256E",cornerBL:"\u2570",cornerBR:"\u256F"},Il={hLine:"-",vLine:"|",origin:"+",yTick:"+",xTick:"+",bar:"#",grid:".",cornerTL:"+",cornerTR:"+",cornerBL:"+",cornerBR:"+"};function Zn(e,t){let r=t.accent??cr;return e<=1?[r]:Array.from({length:e},(i,l)=>rn(l,r,t.bg))}function Tl(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 El(e,t,r,i){let l=At(e),n=en(l),o=t.useAscii?Il:Dl;return n.horizontal?Xl(n,o,r,i):Rl(n,o,r,i)}function Rl(e,t,r,i){let l=ri(e);if(l===0)return"";let n=e.yAxis.range;if(!n)throw Error("XY chart: y-axis range was not set by the parser");let o=ii(n.min,n.max),a=o.map(O=>Ut(O)),s=Math.max(...a.map(O=>O.length))+1,u=Math.max(Gn,l*6),f=Jn,h=Math.floor(u/l),c=ni(e,l),g=!!e.title,m=!!e.xAxis.title,x=!!e.yAxis.title,A=e.series.length>1,M=g?0:-1,j=(g?2:0)+ +!!A,v=x?2:0,P=v+s+1,$=P+h*l+2,V=j+f,Q=V+1,K=m?Q+1:-1,Ce=Q+1+ +!!m+0,ue=Un($,Ce),Me=Kn($,Ce),F=_n($,Ce),ve=Zn(e.series.length,i),me=O=>{let we=(O-n.min)/(n.max-n.min||1);return Math.round(we*19)},He=O=>P+Math.floor(h*(O+.5));e.title&&M>=0&&yt(ue,Me,M,Math.floor($/2-e.title.length/2),e.title,"text"),A&&Qn(ue,Me,F,e,+!!g,$,t,ve);for(let O=0;O<f;O++)Ne(ue,Me,j+(19-O),P-1,t.vLine,"border");Ne(ue,Me,V,P-1,t.origin,"border");for(let O of o){let we=me(O);if(we<0||we>=f)continue;let $e=j+(19-we),Se=Ut(O);Ne(ue,Me,$e,P-1,we===0?t.origin:t.yTick,"border");let Oe=v+s-Se.length;yt(ue,Me,$e,Math.max(0,Oe),Se,"text")}for(let O=P;O<P+h*l;O++)Ne(ue,Me,V,O,t.hLine,"border");for(let O=0;O<l;O++){let we=He(O);Ne(ue,Me,V,we,t.xTick,"border");let $e=c[O],Se=we-Math.floor($e.length/2);yt(ue,Me,Q,Math.max(0,Se),$e,"text")}if(e.xAxis.title&&K>=0){let O=e.xAxis.title;yt(ue,Me,K,Math.floor($/2-O.length/2),O,"text")}if(e.yAxis.title){let O=e.yAxis.title,we=j+Math.max(0,Math.floor((f-O.length)/2));for(let $e=0;$e<O.length;$e++){let Se=we+$e;if(Se>=j+f)break;Ne(ue,Me,Se,0,O[$e],"text")}}for(let O of o){let we=me(O);if(we<0||we>=f)continue;let $e=j+(19-we);for(let Se=P;Se<P+h*l;Se++)ei(ue,$e,Se)===" "&&Ne(ue,Me,$e,Se,t.grid,"line")}let ze=[];for(let O=0;O<e.series.length;O++)e.series[O].type==="bar"&&ze.push({data:e.series[O].data,globalIdx:O});if(ze.length>0){let O=Math.max(1,h-2),we=Math.max(1,Math.min(O,8)),$e=me(Math.max(0,n.min));for(let Se=0;Se<ze.length;Se++){let Oe=ze[Se],it=ve[Oe.globalIdx];for(let fe=0;fe<Oe.data.length;fe++){let Je=He(fe)-Math.floor(we/2),nt=me(Oe.data[fe]),lt=Math.min($e,nt),R=Math.max($e,nt);for(let H=lt;H<=R;H++){let I=j+(19-H);for(let ne=Je;ne<Je+we;ne++)Ne(ue,Me,I,ne,t.bar,"arrow",F,it)}}}}let Te=[];for(let O=0;O<e.series.length;O++)e.series[O].type==="line"&&Te.push({data:e.series[O].data,globalIdx:O});for(let O of Te){if(O.data.length===0)continue;let we=ve[O.globalIdx];Bl(ue,Me,O.data,He,me,j,f,P,h*l,t,F,we)}return ti(ue,Me,F,r,i)}function Xl(e,t,r,i){let l=ri(e);if(l===0)return"";let n=e.yAxis.range;if(!n)throw Error("XY chart: y-axis range was not set by the parser");let o=ii(n.min,n.max),a=ni(e,l),s=Math.max(...a.map(F=>F.length))+1,u=Math.max(Gn,40),f=Math.max(2,Math.floor(Jn/l)),h=f*l,c=!!e.title,g=!!e.yAxis.title,m=e.series.length>1,x=(c?2:0)+ +!!m,A=s+1,M=A+u+2,j=x+h+2+ +!!g,v=x+h,P=Un(M,j),$=Kn(M,j),V=_n(M,j),Q=Zn(e.series.length,i),K=F=>{let ve=(F-n.min)/(n.max-n.min||1);return A+Math.round(ve*59)},Ce=F=>x+Math.floor(f*(F+.5));e.title&&yt(P,$,0,Math.floor(M/2-e.title.length/2),e.title,"text"),m&&Qn(P,$,V,e,+!!c,M,t,Q);for(let F=x;F<x+h;F++)Ne(P,$,F,A-1,t.vLine,"border");Ne(P,$,v,A-1,t.origin,"border");for(let F=0;F<l;F++){let ve=Ce(F),me=a[F],He=s-me.length;yt(P,$,ve,Math.max(0,He),me,"text")}for(let F=A;F<A+u;F++)Ne(P,$,v,F,t.hLine,"border");for(let F of o){let ve=K(F);if(ve<A||ve>=A+u)continue;Ne(P,$,v,ve,t.xTick,"border");let me=Ut(F);yt(P,$,v+1,ve-Math.floor(me.length/2),me,"text")}if(e.yAxis.title){let F=e.yAxis.title;yt(P,$,j-1,Math.floor(M/2-F.length/2),F,"text")}for(let F of o){let ve=K(F);if(!(ve<A||ve>=A+u))for(let me=x;me<x+h;me++)ei(P,me,ve)===" "&&Ne(P,$,me,ve,t.grid,"line")}let ue=[];for(let F=0;F<e.series.length;F++)e.series[F].type==="bar"&&ue.push({data:e.series[F].data,globalIdx:F});if(ue.length>0){let F=K(Math.max(0,n.min));for(let ve=0;ve<ue.length;ve++){let me=ue[ve],He=Q[me.globalIdx];for(let ze=0;ze<me.data.length;ze++){let Te=Ce(ze),O=K(me.data[ze]),we=Math.min(F,O),$e=Math.max(F,O);for(let Se=Te;Se<Te+1;Se++)for(let Oe=we;Oe<=$e;Oe++)Ne(P,$,Se,Oe,t.bar,"arrow",V,He)}}}let Me=[];for(let F=0;F<e.series.length;F++)e.series[F].type==="line"&&Me.push({data:e.series[F].data,globalIdx:F});for(let F of Me){if(F.data.length===0)continue;let ve=Q[F.globalIdx];jl(P,$,F.data,Ce,K,x,h,A,u,t,V,ve)}return ti(P,$,V,r,i)}function Bl(e,t,r,i,l,n,o,a,s,u,f,h){if(r.length===0)return;let c=r.map((m,x)=>({col:i(x),row:l(m)})),g=(m,x,A)=>{let M=n+(o-1-x);M>=0&&m>=a&&m<a+s&&Ne(e,t,M,m,A,"arrow",f,h)};if(c.length===1){g(c[0].col,c[0].row,u.hLine);return}for(let m=0;m<c.length-1;m++){let x=c[m],A=c[m+1];if(x.row===A.row){for(let $=x.col;$<=A.col;$++)g($,x.row,u.hLine);continue}let M=Math.round((x.col+A.col)/2),j=A.row>x.row;for(let $=x.col;$<M;$++)g($,x.row,u.hLine);j?g(M,x.row,u.cornerBR):g(M,x.row,u.cornerTR);let v=Math.min(x.row,A.row),P=Math.max(x.row,A.row);for(let $=v+1;$<P;$++)g(M,$,u.vLine);j?g(M,A.row,u.cornerTL):g(M,A.row,u.cornerBL);for(let $=M+1;$<=A.col;$++)g($,A.row,u.hLine);if(m===0){let $=Math.max(a,x.col-Math.floor((A.col-x.col)/4));for(let V=$;V<x.col;V++)g(V,x.row,u.hLine)}if(m===c.length-2){let $=Math.min(a+s-1,A.col+Math.floor((A.col-x.col)/4));for(let V=A.col+1;V<=$;V++)g(V,A.row,u.hLine)}}}function jl(e,t,r,i,l,n,o,a,s,u,f,h){if(r.length===0)return;let c=r.map((m,x)=>({row:i(x),col:l(m)})),g=(m,x,A)=>{m>=n&&m<n+o&&x>=a&&x<a+s&&Ne(e,t,m,x,A,"arrow",f,h)};if(c.length===1){g(c[0].row,c[0].col,u.vLine);return}for(let m=0;m<c.length-1;m++){let x=c[m],A=c[m+1];if(x.col===A.col){for(let $=x.row;$<=A.row;$++)g($,x.col,u.vLine);continue}let M=Math.round((x.row+A.row)/2),j=A.col>x.col;for(let $=x.row;$<M;$++)g($,x.col,u.vLine);j?g(M,x.col,u.cornerBL):g(M,x.col,u.cornerBR);let v=Math.min(x.col,A.col),P=Math.max(x.col,A.col);for(let $=v+1;$<P;$++)g(M,$,u.hLine);j?g(M,A.col,u.cornerTR):g(M,A.col,u.cornerTL);for(let $=M+1;$<=A.row;$++)g($,A.col,u.vLine)}}function Qn(e,t,r,i,l,n,o,a){let s=[],u=0,f=0;for(let g=0;g<i.series.length;g++)i.series[g].type==="bar"?(s.push({symbol:o.bar,label:`Bar ${u+1}`,globalIdx:g}),u++):(s.push({symbol:o.hLine,label:`Line ${f+1}`,globalIdx:g}),f++);let h=0;for(let g=0;g<s.length;g++)g>0&&(h+=2),h+=2+s[g].label.length;let c=Math.max(0,Math.floor(n/2-h/2));for(let g=0;g<s.length;g++){g>0&&(c+=2);let m=s[g];Ne(e,t,l,c,m.symbol,"arrow",r,a[m.globalIdx]),c+=1,c+=1,yt(e,t,l,c,m.label,"text"),c+=m.label.length}}function Un(e,t){return qe(e-1,t-1)}function Kn(e,t){return Pt(e-1,t-1)}function _n(e,t){return Array.from({length:e},()=>Array.from({length:t}).fill(null))}function Ne(e,t,r,i,l,n,o,a){i>=0&&i<e.length&&r>=0&&r<(e[0]?.length??0)&&(G(e,i,r,l,{role:n,roleCanvas:t}),o&&a&&(o[i][r]=a))}function ei(e,t,r){return r>=0&&r<e.length&&t>=0&&t<e[0].length?e[r][t]:" "}function yt(e,t,r,i,l,n){for(let o=0;o<l.length;o++)Ne(e,t,r,i+o,l[o],n)}function ti(e,t,r,i,l){if(e.length===0)return"";let n=e[0].length,o=e.length,a=[];for(let s=0;s<n;s++){let u=[],f=[],h=[];for(let g=0;g<o;g++)u.push(e[g][s]),f.push(t[g][s]),h.push(r[g][s]);let c=u.length-1;for(;c>=0&&u[c]===" ";)c--;c<0?a.push(""):a.push(Pl(u.slice(0,c+1),f.slice(0,c+1),h.slice(0,c+1),l,i))}for(;a.length>0&&a[a.length-1]==="";)a.pop();return a.join(`
6`)}function Pl(e,t,r,i,l){if(l==="none")return e.join("");let n="",o=null,a="";for(let s=0;s<e.length;s++){let u=e[s];if(u===" "){a.length>0&&(n+=o?mr(a,o,l):a,a="",o=null),n+=" ";continue}let f=r[s]??null,h=t[s]??null,c=f??(h?Tl(h,i):null);c===o?a+=u:(a.length>0&&(n+=o?mr(a,o,l):a),a=u,o=c)}return a.length>0&&(n+=o?mr(a,o,l):a),n}function ri(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 ni(e,t){if(e.xAxis.categories)return e.xAxis.categories;if(e.xAxis.range){let{min:r,max:i}=e.xAxis.range,l=t>1?(i-r)/(t-1):0;return Array.from({length:t},(n,o)=>Ut(r+l*o))}return Array.from({length:t},(r,i)=>String(i+1))}function ii(e,t){let r=t-e;if(r<=0)return[e];let i=r/6,l=10**Math.floor(Math.log10(i)),n=i/l,o;o=n<=1.5?l:n<=3?2*l:n<=7?5*l:10*l;let a=Math.ceil(e/o)*o,s=[];for(let u=a;u<=t+o*.001;u+=o)s.push(Math.round(u*1e10)/1e10);return s}function Ut(e){return Number.isInteger(e)?String(e):e.toFixed(+(Math.abs(e)<10))}var re={x:1,y:0},J={x:1,y:2},U={x:0,y:1},Z={x:2,y:1},gt={x:2,y:0},ft={x:0,y:0},bt={x:2,y:2},mt={x:0,y:2},St={x:1,y:1};function p(e,t){return e.x===t.x&&e.y===t.y}function zl(e){return p(e,re)||p(e,J)||p(e,U)||p(e,Z)}function Xt(e){if(!zl(e))throw Error(`Expected a cardinal direction (Up/Down/Left/Right); got {x:${e.x}, y:${e.y}}`);return e}function $t(e,t,r,i){return Math.max(i,r+(e-t))}function an(e,t){return e.x===t.x&&e.y===t.y}function Lr(e,t){return e.x===t.x&&e.y===t.y}function ht(e,t){return{x:e.x+t.x,y:e.y+t.y}}function Ue(e){return`${e.x},${e.y}`}function We(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 Yl={name:"",styles:{}},ql=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 li(){return new ql}function Wl(e){let t=li();for(let r of e.keys())t.add(r);return t}function It(e,t){return e.has(Ue(t))}function oi(e,t){return t.x<0||t.y<0?!1:!It(e,t)}function Dr(e,t,r=3){for(let i=0;i<r;i++)for(let l=0;l<r;l++)if(It(e,{x:t.x+i,y:t.y+l}))return!1;return!0}function Nl(e,t,r=3){if(!Dr(e,t,r))throw Error(`Grid block at (${t.x},${t.y}) is already occupied`);for(let i=0;i<r;i++)for(let l=0;l<r;l++){let n={x:t.x+i,y:t.y+l};e.add(Ue(n))}}var sn=1e5;function Dt(e){if(e.length===0)return[];let t=[e[0]];for(let r=1;r<e.length;r++){let i=e[r-1],l=e[r],n=i.x,o=i.y,a=Math.abs(l.x-i.x),s=Math.abs(l.y-i.y),u=i.x<l.x?1:-1,f=i.y<l.y?1:-1,h=a-s,c=0;for(;n!==l.x||o!==l.y;){if(c>=sn)throw Error(`pathCells: segment from (${i.x},${i.y}) to (${l.x},${l.y}) did not reach its endpoint within ${sn} steps`);let g=2*h;g>-s&&(h-=s,n+=u),g<a&&(h+=a,o+=f),t.push({x:n,y:o}),c++}}return t}var Fl=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 r=t-1>>1;if(this.items[t].priority<this.items[r].priority)[this.items[t],this.items[r]]=[this.items[r],this.items[t]],t=r;else break}}sinkDown(e){let t=this.items.length,r=e;for(;;){let i=r,l=2*r+1,n=2*r+2;if(l<t&&this.items[l].priority<this.items[i].priority&&(i=l),n<t&&this.items[n].priority<this.items[i].priority&&(i=n),i!==r)[this.items[r],this.items[i]]=[this.items[i],this.items[r]],r=i;else break}}};function Hl(e,t){let r=Math.abs(e.x-t.x),i=Math.abs(e.y-t.y);return r===0||i===0?r+i:r+i+1}var Ol=[{x:1,y:0},{x:-1,y:0},{x:0,y:1},{x:0,y:-1}],Vl=5e4,Gl=2e5;function Jl(e=Gl){return{remaining:e}}function Zl(e,t,r,i){if(i&&i.remaining<=0)return null;let l=new Fl;l.push({coord:t,priority:0});let n=new Map;n.set(Ue(t),0);let o=new Map;o.set(Ue(t),null);let a=0;for(;l.length>0;){if(++a>Vl)return null;if(i){if(i.remaining<=0)return null;i.remaining--}let s=l.pop().coord;if(an(s,r)){let f=[],h=s;for(;h!==null;)f.unshift(h),h=o.get(Ue(h))??null;return f}let u=n.get(Ue(s));if(u===void 0)throw Error(`A* pathfinding: missing cost for visited cell ${Ue(s)}`);for(let f of Ol){let h={x:s.x+f.x,y:s.y+f.y};if(!oi(e,h)&&!an(h,r))continue;let c=u+1,g=Ue(h),m=n.get(g);if(m===void 0||c<m){n.set(g,c);let x=c+Hl(h,r);l.push({coord:h,priority:x}),o.set(g,s)}}}return null}function vr(e){if(e.length<=2)return e;let t=new Set,r=e[0],i=e[1];for(let l=2;l<e.length;l++){let n=e[l],o=i.x-r.x,a=i.y-r.y,s=n.x-i.x,u=n.y-i.y;o===s&&a===u&&t.add(l-1),r=i,i=n}return e.filter((l,n)=>!t.has(n))}function fn(e,t,r,i){if(t.x===r.x&&t.y===r.y)return!0;let l=t.x===r.x;if(!l&&t.y!==r.y)return!1;let n=l?r.y>t.y?1:-1:r.x>t.x?1:-1,o=l?t.y:t.x,a=l?r.y:r.x;for(o+=n;;o+=n){let s=o===a,u=l?{x:t.x,y:o}:{x:o,y:t.y};if(!(s&&!i)&&!oi(e,u))return!1;if(s)break}return!0}function un(e,t,r,i){let l=i?{x:r.x,y:t.y}:{x:t.x,y:r.y};return!fn(e,t,l,!0)||!fn(e,l,r,!1)?null:[t,l,r]}function Ql(e,t,r,i){if(t.x===r.x||t.y===r.y)return null;let l=p(i,U)||p(i,Z);return un(e.grid,t,r,l)??un(e.grid,t,r,!l)}function Bt(e,t,r,i){if(!e.pathBudget)throw Error("routeEdge requires graph.pathBudget to be set; call createPathBudget() (see grid.ts createMapping) before routing edges");let l=Ql(e,t,r,i)??Zl(e.grid,t,r,e.pathBudget);return l?vr(l):null}function Ul(e){if(e.config.graphDirection!=="TD")return[];let t=[],r=new Set,i=new Map;for(let n of e.edges){if(n.from===n.to)continue;let o=i.get(n.to)??[];o.push(n),i.set(n.to,o)}for(let[n,o]of i){if(o.length<2||!cn(o,e)||o.some(s=>r.has(s)))continue;let a={type:"fan-in",edges:[...o],sharedNode:n,otherNodes:o.map(s=>s.from),junctionPoint:null,sharedPath:[],junctionDir:St,sharedNodeDir:St};for(let s of o)s.bundle=a,r.add(s);t.push(a)}let l=new Map;for(let n of e.edges){if(n.from===n.to||r.has(n))continue;let o=l.get(n.from)??[];o.push(n),l.set(n.from,o)}for(let[n,o]of l){if(o.length<2||!cn(o,e))continue;let a={type:"fan-out",edges:[...o],sharedNode:n,otherNodes:o.map(s=>s.to),junctionPoint:null,sharedPath:[],junctionDir:St,sharedNodeDir:St};for(let s of o)s.bundle=a,r.add(s);t.push(a)}return t}function cn(e,t){if(e.length<2)return!1;let r=e[0].style,i=Ge(t,e[0].from),l=Ge(t,e[0].to);for(let u of e){if(u.style!==r||u.text.length>0)return!1;let f=Ge(t,u.from),h=Ge(t,u.to);if(f!==i||h!==l||f!==h)return!1}let n=e.every(u=>u.to===e[0].to),o=n?e.map(u=>u.from):e.map(u=>u.to);if(new Set(o).size!==o.length||e.some(u=>u.parallelLane))return!1;let a=t.config.graphDirection==="LR"?"x":"y",s=(n?e[0].to:e[0].from).gridCoord;if(!s)return!1;for(let u of e){let f=(n?u.from:u.to).gridCoord;if(!f)return!1;if(n){if(f[a]>=s[a])return!1}else if(f[a]<=s[a])return!1}return!0}function Kl(e,t){let r=e.config.graphDirection,i=We(t.sharedNode);if(t.type==="fan-in"){if(r==="TD"){let l=i.y-1;return{x:i.x+1,y:l}}return{x:i.x-1,y:i.y+1}}if(r==="TD"){let l=i.y+3;return{x:i.x+1,y:l}}return{x:i.x+3,y:i.y+1}}function _l(e,t){let r=e.config.graphDirection;t.junctionPoint=Kl(e,t);let i=t.junctionPoint;if(t.type==="fan-in"){t.junctionDir=r==="TD"?re:U,t.sharedNodeDir=r==="TD"?J:Z;let l=We(t.sharedNode),n=Xt(r==="TD"?re:U),o=ht(l,n);t.sharedPath=Bt(e,i,o,n)??[i,o];for(let a of t.edges){let s=We(a.from),u=Xt(r==="TD"?J:Z),f=ht(s,u);a.pathToJunction=Bt(e,f,i,u)??[f,i],a.startDir=u,a.endDir=n,a.path=[...a.pathToJunction,...t.sharedPath.slice(1)]}}else{t.junctionDir=r==="TD"?J:Z,t.sharedNodeDir=r==="TD"?re:U;let l=We(t.sharedNode),n=Xt(r==="TD"?J:Z),o=ht(l,n);t.sharedPath=Bt(e,o,i,n)??[o,i];for(let a of t.edges){let s=We(a.to),u=Xt(r==="TD"?re:U),f=ht(s,u);a.pathToJunction=Bt(e,i,f,u)??[i,f],a.startDir=n,a.endDir=u,a.path=[...t.sharedPath,...a.pathToJunction.slice(1)]}}}function eo(e){for(let t of e.bundles)_l(e,t)}function to(){return new Map}function ro(e,t,r,i){for(let l of Dt(r)){if(It(e,l))continue;let n=t.get(Ue(l));if(n!==void 0&&n!==i)return l}return null}function hn(e,t,r,i){for(let l of Dt(r)){if(It(e,l))continue;let n=Ue(l);t.has(n)||t.set(n,i)}}function no(){return new Map}function io(e,t){return e.to===t.from||t.to===e.from}var lo=2;function oo(e,t,r,i){let l=new Map,n=new Map;for(let o of Dt(r)){if(It(e,o))continue;let a=t.get(Ue(o));if(a!==void 0)for(let s of a)s!==i&&io(s,i)&&(l.set(s,(l.get(s)??0)+1),n.has(s)||n.set(s,o))}for(let[o,a]of l)if(a>=lo)return n.get(o);return null}function dn(e,t,r,i){for(let l of Dt(r)){if(It(e,l))continue;let n=Ue(l),o=t.get(n);o===void 0&&(o=new Set,t.set(n,o)),o.add(i)}}function Le(e){return e.split(`
7`)}function ct(e){let t=Le(e);return Math.max(...t.map(r=>Pe(r)),0)}function gn(e){return Le(e).length}var mn={rectangle:{unicode:{tl:"\u250C",tr:"\u2510",bl:"\u2514",br:"\u2518"},ascii:{tl:"+",tr:"+",bl:"+",br:"+"}},rounded:{unicode:{tl:"\u256D",tr:"\u256E",bl:"\u2570",br:"\u256F"},ascii:{tl:".",tr:".",bl:"'",br:"'"}},circle:{unicode:{tl:"\u25EF",tr:"\u25EF",bl:"\u25EF",br:"\u25EF"},ascii:{tl:"o",tr:"o",bl:"o",br:"o"}},doublecircle:{unicode:{tl:"\u25CE",tr:"\u25CE",bl:"\u25CE",br:"\u25CE"},ascii:{tl:"@",tr:"@",bl:"@",br:"@"}},diamond:{unicode:{tl:"\u25C7",tr:"\u25C7",bl:"\u25C7",br:"\u25C7"},ascii:{tl:"<",tr:">",bl:"<",br:">"}},hexagon:{unicode:{tl:"\u231C",tr:"\u231D",bl:"\u231E",br:"\u231F"},ascii:{tl:"*",tr:"*",bl:"*",br:"*"}},stadium:{unicode:{tl:"(",tr:")",bl:"(",br:")"},ascii:{tl:"(",tr:")",bl:"(",br:")"}},subroutine:{unicode:{tl:"\u255F",tr:"\u2562",bl:"\u255F",br:"\u2562"},ascii:{tl:"|",tr:"|",bl:"|",br:"|"}},cylinder:{unicode:{tl:"\u256D",tr:"\u256E",bl:"\u2570",br:"\u256F"},ascii:{tl:".",tr:".",bl:"'",br:"'"}},asymmetric:{unicode:{tl:"\u25B7",tr:"\u2510",bl:"\u25B7",br:"\u2518"},ascii:{tl:">",tr:"+",bl:">",br:"+"}},trapezoid:{unicode:{tl:"/",tr:"\\",bl:"\u2514",br:"\u2518"},ascii:{tl:"/",tr:"\\",bl:"+",br:"+"}},"trapezoid-alt":{unicode:{tl:"\u250C",tr:"\u2510",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:"\u25CF",tr:"\u25CF",bl:"\u25CF",br:"\u25CF"},ascii:{tl:"*",tr:"*",bl:"*",br:"*"}},"state-end":{unicode:{tl:"\u25C9",tr:"\u25C9",bl:"\u25C9",br:"\u25C9"},ascii:{tl:"@",tr:"@",bl:"@",br:"@"}},document:{unicode:{tl:"\u250C",tr:"\u2510",bl:"\u2570",br:"\u256E"},ascii:{tl:"+",tr:"+",bl:"'",br:"~"}},"stacked-document":{unicode:{tl:"\u250C",tr:"\u2557",bl:"\u2570",br:"\u256E"},ascii:{tl:"+",tr:"#",bl:"'",br:"~"}},"stacked-process":{unicode:{tl:"\u250C",tr:"\u2557",bl:"\u2514",br:"\u255D"},ascii:{tl:"+",tr:"#",bl:"+",br:"#"}},card:{unicode:{tl:"\u2571",tr:"\u2510",bl:"\u2514",br:"\u2518"},ascii:{tl:"/",tr:"+",bl:"+",br:"+"}},"lined-process":{unicode:{tl:"\u250C",tr:"\u2510",bl:"\u2514",br:"\u2518"},ascii:{tl:"+",tr:"+",bl:"+",br:"+"}},"divided-process":{unicode:{tl:"\u250C",tr:"\u2510",bl:"\u2514",br:"\u2518"},ascii:{tl:"+",tr:"+",bl:"+",br:"+"}},"window-pane":{unicode:{tl:"\u250C",tr:"\u2510",bl:"\u2514",br:"\u2518"},ascii:{tl:"+",tr:"+",bl:"+",br:"+"}},triangle:{unicode:{tl:"\u2571",tr:"\u2572",bl:"\u2514",br:"\u2518"},ascii:{tl:"/",tr:"\\",bl:"+",br:"+"}},"flipped-triangle":{unicode:{tl:"\u250C",tr:"\u2510",bl:"\u2572",br:"\u2571"},ascii:{tl:"+",tr:"+",bl:"\\",br:"/"}},"filled-circle":{unicode:{tl:"\u25CF",tr:"\u25CF",bl:"\u25CF",br:"\u25CF"},ascii:{tl:"*",tr:"*",bl:"*",br:"*"}},"crossed-circle":{unicode:{tl:"\u2573",tr:"\u2573",bl:"\u2573",br:"\u2573"},ascii:{tl:"X",tr:"X",bl:"X",br:"X"}},"fork-join":{unicode:{tl:"\u2501",tr:"\u2501",bl:"\u2501",br:"\u2501"},ascii:{tl:"=",tr:"=",bl:"=",br:"="}},"notched-pentagon":{unicode:{tl:"\u2571",tr:"\u2572",bl:"\u2514",br:"\u2518"},ascii:{tl:"/",tr:"\\",bl:"+",br:"+"}},"sloped-rectangle":{unicode:{tl:"\u2571",tr:"\u2510",bl:"\u2514",br:"\u2518"},ascii:{tl:"/",tr:"+",bl:"+",br:"+"}},flag:{unicode:{tl:"\u256D",tr:"\u256E",bl:"\u2570",br:"\u256F"},ascii:{tl:"~",tr:"~",bl:"~",br:"~"}},"bow-tie-rectangle":{unicode:{tl:"\u2572",tr:"\u2571",bl:"\u2571",br:"\u2572"},ascii:{tl:"\\",tr:"/",bl:"/",br:"\\"}},"half-rounded-rectangle":{unicode:{tl:"\u250C",tr:"\u256E",bl:"\u2514",br:"\u256F"},ascii:{tl:"+",tr:".",bl:"+",br:"'"}},brace:{unicode:{tl:"\u256D",tr:"\u2510",bl:"\u2570",br:"\u2518"},ascii:{tl:"{",tr:"+",bl:"{",br:"+"}},"brace-right":{unicode:{tl:"\u250C",tr:"\u256E",bl:"\u2514",br:"\u256F"},ascii:{tl:"+",tr:"}",bl:"+",br:"}"}},braces:{unicode:{tl:"\u256D",tr:"\u256E",bl:"\u2570",br:"\u256F"},ascii:{tl:"{",tr:"}",bl:"{",br:"}"}},bolt:{unicode:{tl:"\u2571",tr:"\u2572",bl:"\u2572",br:"\u2571"},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 tt(e,t){let r=mn[e]??mn.rectangle;return t?r.ascii:r.unicode}function ot(e,t){let r=Le(e),i=Math.max(...r.map(u=>Pe(u)),0),l=r.length,n=2*t.padding+i,o=n+2,a=l+2*t.padding,s=a%2==0?a+1:a;return{width:o,height:s+2,labelArea:{x:1+t.padding,y:1+t.padding,width:i,height:l},gridColumns:[1,n,1],gridRows:[1,s,1]}}function at(e,t,r,i){let{width:l,height:n}=t,o=qe(l-1,n-1),a={x:0,y:0},s={x:l-1,y:n-1},u=i?"-":"\u2500",f=i?"|":"\u2502";for(let x=a.x+1;x<s.x;x++)o[x][a.y]=u,o[x][s.y]=u;for(let x=a.y+1;x<s.y;x++)o[a.x][x]=f,o[s.x][x]=f;o[a.x][a.y]=r.tl,o[s.x][a.y]=r.tr,o[a.x][s.y]=r.bl,o[s.x][s.y]=r.br;let h=Le(e),c=l-1,g=n-1,m=Math.floor(g/2)-Math.floor((h.length-1)/2);for(let x=0;x<h.length;x++){let A=h[x],M=Math.floor(c/2)-Math.ceil(Pe(A)/2)+1,j=rt(A);for(let v=0;v<j.length;v++){let P=M+v,$=m+x;P>=0&&P<o.length&&$>=0&&$<o[0].length&&(o[P][$]=j[v])}}return o}function Qe(e,t,r){let{width:i,height:l}=t,n=r.x+Math.floor(i/2),o=r.y+Math.floor(l/2);return p(e,re)?{x:n,y:r.y}:p(e,J)?{x:n,y:r.y+l-1}:p(e,U)?{x:r.x,y:o}:p(e,Z)?{x:r.x+i-1,y:o}:p(e,ft)?{x:r.x,y:r.y}:p(e,gt)?{x:r.x+i-1,y:r.y}:p(e,mt)?{x:r.x,y:r.y+l-1}:p(e,bt)?{x:r.x+i-1,y:r.y+l-1}:{x:n,y:o}}var ai={getDimensions:ot,render(e,t,r){return at(e,t,tt("rectangle",r.useAscii),r.useAscii)},getAttachmentPoint:Qe},ao=new Map([["rectangle",ai],["rounded",{getDimensions:ot,render(e,t,r){return at(e,t,tt("rounded",r.useAscii),r.useAscii)},getAttachmentPoint:Qe}],["diamond",{getDimensions:ot,render(e,t,r){return at(e,t,tt("diamond",r.useAscii),r.useAscii)},getAttachmentPoint:Qe}],["stadium",{getDimensions(e,t){let r=Le(e),i=Math.max(...r.map(s=>Pe(s)),0),l=r.length,n=2*t.padding+i,o=n+4,a=l+2*t.padding;return{width:o,height:Math.max(a+2,3),labelArea:{x:2+t.padding,y:1+t.padding,width:i,height:l},gridColumns:[2,n,2],gridRows:[1,a,1]}},render(e,t,r){let{width:i,height:l}=t,n=qe(i-1,l-1),o=Math.floor(l/2),a=r.useAscii?"-":"\u2500";if(l===3)n[0][o]="(",n[i-1][o]=")";else if(r.useAscii){for(let f=0;f<l;f++)n[0][f]="(",n[i-1][f]=")";for(let f=1;f<i-1;f++)n[f][0]=a,n[f][l-1]=a}else{n[0][0]="\u256D";for(let f=1;f<i-1;f++)n[f][0]=a;n[i-1][0]="\u256E";for(let f=1;f<l-1;f++)n[0][f]="\u2502",n[i-1][f]="\u2502";n[0][l-1]="\u2570";for(let f=1;f<i-1;f++)n[f][l-1]=a;n[i-1][l-1]="\u256F"}let s=Le(e),u=o-Math.floor((s.length-1)/2);for(let f=0;f<s.length;f++){let h=s[f],c=Math.floor(i/2)-Math.floor(Pe(h)/2),g=rt(h);for(let m=0;m<g.length;m++){let x=c+m,A=u+f;x>0&&x<i-1&&A>=0&&A<l&&(n[x][A]=g[m])}}return n},getAttachmentPoint:Qe}],["circle",{getDimensions:ot,render(e,t,r){return at(e,t,tt("circle",r.useAscii),r.useAscii)},getAttachmentPoint:Qe}],["subroutine",{getDimensions(e,t){let r=Le(e),i=Math.max(...r.map(s=>Pe(s)),0),l=r.length,n=2*t.padding+i,o=n+4,a=l+2*t.padding;return{width:o,height:a+2,labelArea:{x:2+t.padding,y:1+t.padding,width:i,height:l},gridColumns:[2,n,2],gridRows:[1,a,1]}},render(e,t,r){let{width:i,height:l}=t,n=qe(i-1,l-1),o=r.useAscii?"-":"\u2500",a=r.useAscii?"|":"\u2502";n[0][0]=r.useAscii?"+":"\u250C",n[1][0]=r.useAscii?"+":"\u252C";for(let f=2;f<i-2;f++)n[f][0]=o;n[i-2][0]=r.useAscii?"+":"\u252C",n[i-1][0]=r.useAscii?"+":"\u2510";for(let f=1;f<l-1;f++)n[0][f]=a,n[1][f]=a,n[i-2][f]=a,n[i-1][f]=a;n[0][l-1]=r.useAscii?"+":"\u2514",n[1][l-1]=r.useAscii?"+":"\u2534";for(let f=2;f<i-2;f++)n[f][l-1]=o;n[i-2][l-1]=r.useAscii?"+":"\u2534",n[i-1][l-1]=r.useAscii?"+":"\u2518";let s=Le(e),u=Math.floor(l/2)-Math.floor((s.length-1)/2);for(let f=0;f<s.length;f++){let h=s[f],c=Math.floor(i/2)-Math.floor(Pe(h)/2),g=rt(h);for(let m=0;m<g.length;m++){let x=c+m,A=u+f;x>1&&x<i-2&&A>0&&A<l-1&&(n[x][A]=g[m])}}return n},getAttachmentPoint:Qe}],["doublecircle",{getDimensions:ot,render(e,t,r){return at(e,t,tt("doublecircle",r.useAscii),r.useAscii)},getAttachmentPoint:Qe}],["hexagon",{getDimensions:ot,render(e,t,r){return at(e,t,tt("hexagon",r.useAscii),r.useAscii)},getAttachmentPoint:Qe}],["cylinder",{getDimensions(e,t){let r=Le(e),i=Math.max(...r.map(s=>Pe(s)),0),l=r.length,n=2*t.padding+i,o=n+2,a=l+2*t.padding+2;return{width:o,height:a+2,labelArea:{x:1+t.padding,y:2+t.padding,width:i,height:l},gridColumns:[1,n,1],gridRows:[2,a-2,2]}},render(e,t,r){let{width:i,height:l}=t,n=qe(i-1,l-1),o=r.useAscii?"-":"\u2500",a=r.useAscii?"|":"\u2502";n[0][0]=r.useAscii?".":"\u256D";for(let f=1;f<i-1;f++)n[f][0]=o;n[i-1][0]=r.useAscii?".":"\u256E",n[0][1]=a;for(let f=1;f<i-1;f++)n[f][1]=o;n[i-1][1]=a;for(let f=2;f<l-2;f++)n[0][f]=a,n[i-1][f]=a;n[0][l-2]=a;for(let f=1;f<i-1;f++)n[f][l-2]=o;n[i-1][l-2]=a,n[0][l-1]=r.useAscii?"'":"\u2570";for(let f=1;f<i-1;f++)n[f][l-1]=o;n[i-1][l-1]=r.useAscii?"'":"\u256F";let s=Le(e),u=Math.floor(l/2)-Math.floor((s.length-1)/2);for(let f=0;f<s.length;f++){let h=s[f],c=Math.floor(i/2)-Math.floor(Pe(h)/2),g=rt(h);for(let m=0;m<g.length;m++){let x=c+m,A=u+f;x>0&&x<i-1&&A>1&&A<l-2&&(n[x][A]=g[m])}}return n},getAttachmentPoint:Qe}],["asymmetric",{getDimensions:ot,render(e,t,r){return at(e,t,tt("asymmetric",r.useAscii),r.useAscii)},getAttachmentPoint:Qe}],["trapezoid",{getDimensions:ot,render(e,t,r){return at(e,t,tt("trapezoid",r.useAscii),r.useAscii)},getAttachmentPoint:Qe}],["trapezoid-alt",{getDimensions:ot,render(e,t,r){return at(e,t,tt("trapezoid-alt",r.useAscii),r.useAscii)},getAttachmentPoint:Qe}],["parallelogram",{getDimensions:ot,render(e,t,r){return at(e,t,tt("parallelogram",r.useAscii),r.useAscii)},getAttachmentPoint:Qe}],["parallelogram-alt",{getDimensions:ot,render(e,t,r){return at(e,t,tt("parallelogram-alt",r.useAscii),r.useAscii)},getAttachmentPoint:Qe}],["state-start",{getDimensions(e,t){return{width:5,height:3,labelArea:{x:2,y:1,width:1,height:1},gridColumns:[1,3,1],gridRows:[1,1,1]}},render(e,t,r){let{width:i,height:l}=t,n=qe(i-1,l-1),o=Math.floor(i/2);return r.useAscii?(n[0][0]=".",n[1][0]="-",n[2][0]="-",n[3][0]="-",n[4][0]=".",n[0][1]="|",n[o][1]="*",n[4][1]="|",n[0][2]="'",n[1][2]="-",n[2][2]="-",n[3][2]="-",n[4][2]="'"):(n[0][0]="\u256D",n[1][0]="\u2500",n[2][0]="\u2500",n[3][0]="\u2500",n[4][0]="\u256E",n[0][1]="\u2502",n[o][1]="\u25CF",n[4][1]="\u2502",n[0][2]="\u2570",n[1][2]="\u2500",n[2][2]="\u2500",n[3][2]="\u2500",n[4][2]="\u256F"),n},getAttachmentPoint(e,t,r){let{width:i,height:l}=t,n=r.x+Math.floor(i/2),o=r.y+Math.floor(l/2);return p(e,re)?{x:n,y:r.y}:p(e,J)?{x:n,y:r.y+l-1}:p(e,U)?{x:r.x,y:o}:p(e,Z)?{x:r.x+i-1,y:o}:{x:n,y:o}}}],["state-end",{getDimensions(e,t){return{width:5,height:3,labelArea:{x:2,y:1,width:1,height:1},gridColumns:[1,3,1],gridRows:[1,1,1]}},render(e,t,r){let{width:i,height:l}=t,n=qe(i-1,l-1),o=Math.floor(i/2);return r.useAscii?(n[0][0]="#",n[1][0]="=",n[2][0]="=",n[3][0]="=",n[4][0]="#",n[0][1]="#",n[o][1]="*",n[4][1]="#",n[0][2]="#",n[1][2]="=",n[2][2]="=",n[3][2]="=",n[4][2]="#"):(n[0][0]="\u2554",n[1][0]="\u2550",n[2][0]="\u2550",n[3][0]="\u2550",n[4][0]="\u2557",n[0][1]="\u2551",n[o][1]="\u25CE",n[4][1]="\u2551",n[0][2]="\u255A",n[1][2]="\u2550",n[2][2]="\u2550",n[3][2]="\u2550",n[4][2]="\u255D"),n},getAttachmentPoint(e,t,r){let{width:i,height:l}=t,n=r.x+Math.floor(i/2),o=r.y+Math.floor(l/2);return p(e,re)?{x:n,y:r.y}:p(e,J)?{x:n,y:r.y+l-1}:p(e,U)?{x:r.x,y:o}:p(e,Z)?{x:r.x+i-1,y:o}:{x:n,y:o}}}]]);function si(e){return ao.get(e)??ai}function so(e,t,r){return si(e).getDimensions(t,r)}function fo(e,t,r,i){return si(e).getAttachmentPoint(t,r,i)}function pt(e,t,r){let i=r?{x:t.x+r.x,y:t.y+r.y}:t,l=0;for(let s=0;s<i.x;s++)l+=e.columnWidth.get(s)??0;let n=0;for(let s=0;s<i.y;s++)n+=e.rowHeight.get(s)??0;let o=e.columnWidth.get(i.x)??0,a=e.rowHeight.get(i.y)??0;return{x:l+Math.floor(o/2)+e.offsetX,y:n+Math.floor(a/2)+e.offsetY}}function uo(e,t){return t.map(r=>pt(e,r))}function Lt(e,t,r,i){let l=i??Kt(e,t);return Dr(e.grid,r,3)?(Nl(e.grid,r,3),t.gridCoord=r,r):l==="LR"?Lt(e,t,{x:r.x,y:r.y+4},l):Lt(e,t,{x:r.x+4,y:r.y},l)}function co(e,t){let r=We(t),i=e.config.boxBorderPadding,l=so(t.shape,t.displayLabel,{useAscii:e.config.useAscii,padding:i}),n=l.gridColumns,o=l.gridRows;for(let a=0;a<n.length;a++){let s=r.x+a,u=e.columnWidth.get(s)??0;e.columnWidth.set(s,Math.max(u,n[a]))}for(let a=0;a<o.length;a++){let s=r.y+a,u=e.rowHeight.get(s)??0;e.rowHeight.set(s,Math.max(u,o[a]))}if(r.x>0){let a=e.columnWidth.get(r.x-1)??0;e.columnWidth.set(r.x-1,Math.max(a,e.config.paddingX))}if(r.y>0){let a=e.config.paddingY;xo(e,t)&&(a+=4);let s=e.rowHeight.get(r.y-1)??0;e.rowHeight.set(r.y-1,Math.max(s,a))}}function pn(e,t){for(let r of t)e.columnWidth.has(r.x)||e.columnWidth.set(r.x,Math.floor(e.config.paddingX/2)),e.rowHeight.has(r.y)||e.rowHeight.set(r.y,Math.floor(e.config.paddingY/2))}var ho=8;function go(e,t,r,i,l){let n=[];try{for(let o=0;o<ho;o++){let a=ro(l,r,t.path,t.style)??oo(l,i,t.path,t);if(!a)return;e.grid.add(Ue(a)),n.push(a),ci(e,t)}}finally{for(let o of n)e.grid.delete(Ue(o))}}function pr(e,t){return e.subgraphs.some(r=>r.nodes.includes(t))}function Ge(e,t){let r=null;for(let i of e.subgraphs)i.nodes.includes(t)&&(!r||mo(r,i))&&(r=i);return r}function mo(e,t){let r=t;for(;r!==null;){if(r===e)return!0;r=r.parent}return!1}function Wt(e,t){let r=Ge(e,t);if(!r)return null;let i=r;for(;i.parent;)i=i.parent;return i}function Ar(e){let t=[...e.nodes];for(let r of e.children)t.push(...Ar(r));return t}function po(e,t,r){if(t===r)return!0;let i=new Set([t]),l=[t];for(;l.length>0;){let n=l.shift();for(let o of Nt(e,n)){if(o===r)return!0;i.has(o)||(i.add(o),l.push(o))}}return!1}function Kt(e,t){let r=Ge(e,t);return r?.direction?r.direction:e.config.graphDirection}function xo(e,t){let r=Ge(e,t);if(!r)return!1;let i=!1;for(let n of e.edges)if(n.to===t&&Ge(e,n.from)!==r){i=!0;break}if(!i)return!1;let l=We(t).y;for(let n of r.nodes){if(n===t||!n.gridCoord)continue;let o=!1;for(let a of e.edges)if(a.to===n&&Ge(e,a.from)!==r){o=!0;break}if(o&&n.gridCoord.y<l)return!1}return!0}function fi(e,t){if(t.nodes.length===0)return;let r=1e6,i=1e6,l=-1e6,n=-1e6;for(let u of t.children)fi(e,u),u.nodes.length>0&&(r=Math.min(r,u.minX),i=Math.min(i,u.minY),l=Math.max(l,u.maxX),n=Math.max(n,u.maxY));for(let u of t.nodes){if(!u.drawingCoord||!u.drawing)continue;let f=u.drawingCoord.x,h=u.drawingCoord.y,c=f+u.drawing.length-1,g=h+u.drawing[0].length-1;r=Math.min(r,f),i=Math.min(i,h),l=Math.max(l,c),n=Math.max(n,g)}t.minX=r-2,t.minY=i-2-2,t.maxX=l+2,t.maxY=n+2;let o=Math.max(0,...Le(t.name).map(u=>Pe(u))),a=t.maxX-t.minX,s=o+1;if(s>a){let u=s-a,f=Math.floor(u/2),h=u-f;t.minX-=f,t.maxX+=h}}function yo(e){let t=e.subgraphs.filter(r=>r.parent===null&&r.nodes.length>0);for(let r=0;r<t.length;r++)for(let i=r+1;i<t.length;i++){let l=t[r],n=t[i];l.minX<n.maxX&&l.maxX>n.minX&&(l.maxY>=n.minY-1&&l.minY<n.minY?n.minY=l.maxY+1+1:n.maxY>=l.minY-1&&n.minY<l.minY&&(l.minY=n.maxY+1+1)),l.minY<n.maxY&&l.maxY>n.minY&&(l.maxX>=n.minX-1&&l.minX<n.minX?n.minX=l.maxX+1+1:n.maxX>=l.minX-1&&n.minX<l.minX&&(l.minX=n.maxX+1+1))}}function bo(e){for(let t of e.subgraphs)fi(e,t);yo(e)}function wo(e){if(e.subgraphs.length===0)return;let t=0,r=0;for(let n of e.subgraphs)t=Math.min(t,n.minX),r=Math.min(r,n.minY);let i=-t,l=-r;if(i!==0||l!==0){e.offsetX=i,e.offsetY=l;for(let n of e.subgraphs)n.minX+=i,n.minY+=l,n.maxX+=i,n.maxY+=l;for(let n of e.nodes)n.drawingCoord&&(n.drawingCoord.x+=i,n.drawingCoord.y+=l)}}function Mo(e,t){let r=n=>{let o=Nt(e,n);return o.length>0?o[0].name:null},i=new Map,l=t.map((n,o)=>{let a=r(n);if(a===null)return o;let s=i.get(a);return s===void 0?(i.set(a,o),o):s});return t.map((n,o)=>({node:n,i:o})).sort((n,o)=>l[n.i]-l[o.i]||n.i-o.i).map(({node:n})=>n)}function vo(e,t){let r=new Set,i=n=>{let o=[n];for(;o.length>0;){let a=o.shift();if(!r.has(a.name)){r.add(a.name);for(let s of Nt(e,a))o.push(s)}}};for(let n of t)i(n);let l=[...t];for(let n of e.nodes)r.has(n.name)||(l.push(n),i(n));return l}function Ao(e,t){return e.nodes.find(r=>r.gridCoord!==null&&r.gridCoord.x===t.x&&r.gridCoord.y===t.y)}function ui(e,t,r,i,l){let n=i==="x"?"y":"x",o=a=>{let s=4;for(;;){let u=t[i]+a*s;if(u<0)return null;let f=i==="x"?{x:u,y:t[n]}:{x:t[n],y:u};if(Dr(e.grid,f,3))return f;let h=Ao(e,f);if(!h||Wt(e,h)!==r)return null;s+=4}};return o(l)??o(l*-1)}function xn(e,t,r,i){let l=Wt(e,t);if(!l)return;let n=r.get(l);if(!n)return;r.delete(l);let o=We(t),a=Kt(e,t)==="LR"?"y":"x";for(let s of n){let u=Kt(e,s),f=ui(e,o,l,a,1);Lt(e,e.nodes[s.index],f??o,u),i.add(s)}}function yn(e,t){let r=!0;for(;r;){r=!1;let i=n=>e.config.graphDirection==="LR"?n.gridCoord?.y??0:n.gridCoord?.x??0,l=e.nodes.filter(n=>n.gridCoord!==null).sort((n,o)=>i(n)-i(o));for(let n of l){let o=n.gridCoord;if(o===null)continue;let a=[...Nt(e,n)].sort((s,u)=>So(e,s,u));for(let s of a){if(s.gridCoord!==null)continue;let u=Ge(e,n),f=Ge(e,s),h=u&&u===f&&u.direction?u.direction:e.config.graphDirection,c=h==="LR"?o.x+4:o.y+4,g;g=h===e.config.graphDirection?t[c]??0:h==="LR"?o.y:o.x;let m=h==="LR"?{x:c,y:g}:{x:g,y:c};Lt(e,e.nodes[s.index],m,h),h===e.config.graphDirection&&(t[c]=g+4),r=!0}}}}function ko(e){let t=e.config.graphDirection,r=[],i=new Set;for(let v of e.edges)v.from!==v.to&&i.add(v.to.name);let l=vo(e,e.nodes.filter(v=>!i.has(v.name))).filter(v=>{let P=Ge(e,v);if(!P)return!0;for(let $ of e.edges)if($.to===v&&Ge(e,$.from)!==P)return!1;return!0}),n=new Set(l),o=[],a=[];for(let v of l){let P=Wt(e,v);P!==null&&Ar(P).some($=>$!==v&&!n.has($)&&!po(e,v,$))?o.push(v):a.push(v)}let s=Mo(e,a),u=new Map;for(let v of o){let P=Wt(e,v),$=u.get(P);$?$.push(v):u.set(P,[v])}let f=new Set,h=!1,c=!1;for(let v of s)pr(e,v)?Nt(e,v).length>0&&(c=!0):h=!0;let g=t==="LR"&&h&&c,m,x=[];g?(m=s.filter(v=>!pr(e,v)),x=s.filter(v=>pr(e,v))):m=s;for(let v of m){let P=t==="LR"?{x:0,y:r[0]??0}:{x:r[0]??0,y:0};Lt(e,e.nodes[v.index],P),r[0]=(r[0]??0)+4,xn(e,v,u,f)}if(g&&x.length>0)for(let v of x){let P=t==="LR"?{x:4,y:r[4]??0}:{x:r[4]??0,y:4};Lt(e,e.nodes[v.index],P),r[4]=(r[4]??0)+4,xn(e,v,u,f)}yn(e,r);for(let v of o){if(f.has(v))continue;let P=Wt(e,v),$=Kt(e,v),V=Ar(P).filter(K=>K!==v&&K.gridCoord!==null),Q;if(V.length>0){let K=V[0];for(let ue of V)($==="LR"?ue.gridCoord.x<K.gridCoord.x:ue.gridCoord.y<K.gridCoord.y)&&(K=ue);let Ce=$==="LR"?"y":"x";Q=ui(e,K.gridCoord,P,Ce,1)??{x:K.gridCoord.x,y:K.gridCoord.y}}else Q=$==="LR"?{x:0,y:r[0]??0}:{x:r[0]??0,y:0},r[0]=(r[0]??0)+4;Lt(e,e.nodes[v.index],Q,$)}yn(e,r);for(let v of e.nodes)co(e,v);e.pathBudget=Jl(),Xo(e),e.bundles=Ul(e),eo(e);let A=to(),M=no(),j=Wl(e.grid);for(let v of e.edges){if(v.bundle&&v.path.length>0){pn(e,v.path),hn(j,A,v.path,v.style),dn(j,M,v.path,v),wn(e,v);continue}ci(e,v),go(e,v,A,M,j),pn(e,v.path),hn(j,A,v.path,v.style),dn(j,M,v.path,v),wn(e,v)}for(let v of e.nodes)v.drawingCoord=pt(e,We(v)),v.drawing=la(v,e);bo(e),wo(e),$l(e.canvas,e.columnWidth,e.rowHeight,e.offsetX,e.offsetY),Ll(e.roleCanvas,e.columnWidth,e.rowHeight,e.offsetX,e.offsetY)}function Co(e,t){return e.edges.filter(r=>r.from.name===t.name)}function bn(e,t){let r=Ge(e,t),i=[],l=r;for(;l!==null;)i.unshift(l),l=l.parent;return i}function So(e,t,r){let i=bn(e,t),l=bn(e,r),n=0;for(;n<i.length&&n<l.length&&i[n]===l[n];)n++;let o=i[n],a=l[n];return!o||!a||o===a?0:e.subgraphs.indexOf(a)-e.subgraphs.indexOf(o)}function Nt(e,t){return Co(e,t).map(r=>r.to)}function Jt(e){return e===re?J:e===J?re:e===U?Z:e===Z?U:e===gt?mt:e===ft?bt:e===bt?ft:e===mt?gt:St}function Fe(e,t){return e.x===t.x?e.y<t.y?J:re:e.y===t.y?e.x<t.x?Z:U:e.x<t.x?e.y<t.y?bt:gt:e.y<t.y?mt:ft}function $o(e){return e==="LR"?[Z,J,J,Z]:[J,Z,Z,J]}function Lo(e,t){if(e.from===e.to)return $o(t);let r=Fe(We(e.from),We(e.to)),i,l,n,o,a=t==="LR"?p(r,U)||p(r,ft)||p(r,mt):p(r,re)||p(r,ft)||p(r,gt);return p(r,bt)?t==="LR"?(i=J,l=U,n=Z,o=re):(i=Z,l=re,n=J,o=U):p(r,gt)?t==="LR"?(i=re,l=U,n=Z,o=J):(i=Z,l=J,n=re,o=U):p(r,mt)?t==="LR"?(i=J,l=J,n=U,o=re):(i=U,l=re,n=J,o=Z):p(r,ft)?t==="LR"?(i=J,l=J,n=U,o=J):(i=Z,l=Z,n=re,o=Z):a?t==="LR"&&p(r,U)?(i=J,l=J,n=U,o=Z):t==="TD"&&p(r,re)?(i=Z,l=Z,n=re,o=J):(i=r,l=Jt(r),n=r,o=Jt(r)):(i=r,l=Jt(r),n=r,o=Jt(r)),[i,l,n,o]}var Do=2,Io=200;function To(e,t){let r=e.gridCoord;return r?t.x>=r.x&&t.x<=r.x+2&&t.y>=r.y&&t.y<=r.y+2:!1}function kr(e,t,r=[]){for(let i=1;i<t.length-1;i++){let l=t[i];if(It(e.grid,l)&&!r.some(n=>To(n,l)))return!1}return!0}function Eo(e){let t=e.from.gridCoord,r=e.to.gridCoord;return!t||!r?!1:t.y===r.y&&t.x!==r.x}function Ro(e){let t=e.from.name,r=e.to.name;return Eo(e)&&r<t?JSON.stringify([r,t]):JSON.stringify([t,r])}function Xo(e){let t=new Map;for(let r of e.edges){if(r.from===r.to)continue;let i=Ro(r),l=t.get(i);l?l.push(r):t.set(i,[r])}for(let r of t.values()){if(r.length<2)continue;let i=new Set;for(let l=0;l<r.length;l++)r[l].parallelLane={index:l,total:r.length,usedOffsets:i}}}function Bo(e,t,r,i,l){let n=ht(We(t.from),r),o=ht(We(t.to),i),a=p(r,U)||p(r,Z),s=[t.from,t.to],u=t.parallelLane.usedOffsets,f=p(r,Z)?1:p(r,U)?-1:p(r,J)?1:-1,h=p(i,Z)?1:p(i,U)?-1:p(i,J)?1:-1,c=a?{x:n.x+f,y:n.y}:{x:n.x,y:n.y+f},g=a?{x:o.x+h,y:o.y}:{x:o.x,y:o.y+h},m=[n,o],x=[n,o],A=Do*l;for(let M=0;M<Io;M++){let j=A+M;if(u.has(j))continue;let v=n.y+j,P=n.x+j,$=a?[{x:n.x,y:v},{x:o.x,y:v}]:[{x:P,y:n.y},{x:P,y:o.y}],V=vr([n,...$,o]);if(kr(e,Dt(V),s))return u.add(j),{path:V,labelSegment:$};m=V,x=$;let Q=a?c.x!==g.x:c.y!==g.y,K=a?Q?[{x:c.x,y:v},{x:g.x,y:v}]:[{x:c.x,y:v},{x:c.x,y:v}]:Q?[{x:P,y:c.y},{x:P,y:g.y}]:[{x:P,y:c.y},{x:P,y:c.y}],Ce=vr(a?[n,c,{x:c.x,y:v},{x:g.x,y:v},g,o]:[n,c,{x:P,y:c.y},{x:P,y:g.y},g,o]);if(kr(e,Dt(Ce),s))return u.add(j),{path:Ce,labelSegment:K};m=Ce,x=K}return{path:m,labelSegment:x}}function ci(e,t){let r=Ge(e,t.from),i=Ge(e,t.to),[l,n,o,a]=Lo(t,r&&r===i&&r.direction?r.direction:e.config.graphDirection);if(t.parallelLane&&t.parallelLane.index>0){let c=p(l,n),g=c?o:l,m=c?a:n;t.startDir=g,t.endDir=m;let x=Bo(e,t,g,m,t.parallelLane.index);t.path=x.path,t.text.length>0&&di(e,t,x.labelSegment,Pe(t.text));return}let s=ht(We(t.from),l),u=ht(We(t.to),n),f=Bt(e,s,u,Xt(l)),h=Bt(e,ht(We(t.from),o),ht(We(t.to),a),Xt(o));if(f!==null&&h!==null){f.length<=h.length?(t.startDir=l,t.endDir=n,t.path=f):(t.startDir=o,t.endDir=a,t.path=h);return}if(f!==null){t.startDir=l,t.endDir=n,t.path=f;return}if(h!==null){t.startDir=o,t.endDir=a,t.path=h;return}t.startDir=l,t.endDir=n,t.path=hi([s,u])}function xr(e,t){for(let r of e.nodes){let i=r.gridCoord;if(i&&t>=i.x&&t<=i.x+2)return!0}return!1}function jo(e,t,r,i){if(!xr(e,i))return i;for(let l=1;l<=r-t;l++){let n=i+l;if(n<=r&&!xr(e,n))return n;let o=i-l;if(o>=t&&!xr(e,o))return o}return i}function wn(e,t){if(t.text.length===0||t.parallelLane&&t.parallelLane.index>0)return;let r=Pe(t.text),i=hi(t.path),l=i.length,n=[];for(let f=1;f<l;f++){let h=i[f-1],c=i[f],g=[h,c],m=Po(e,g),x=h.x===c.x;n.push({line:g,width:m,index:f,isVertical:x})}let o=f=>kr(e,Dt(f)),a=f=>f.index===1||f.index===n.length,s=n.filter(f=>f.width>=r&&!a(f)&&o(f.line)),u;if(s.length>0)s.sort((f,h)=>h.index-f.index),u=s[0].line;else{let f=n.filter(h=>h.width>=r&&o(h.line));if(f.length>0)f.sort((h,c)=>c.index-h.index),u=f[0].line;else{let h=n.filter(m=>!a(m)&&o(m.line)),c=n.filter(m=>o(m.line)),g=h.length>0?h:c.length>0?c:n;if(g.sort((m,x)=>x.width-m.width),g.length>0)u=g[0].line;else{let m=t.path[0]??{x:0,y:0};u=[m,m]}}}di(e,t,u,r)}function hi(e){let t=[];for(let r of e){let i=t[t.length-1];i&&i.x!==r.x&&i.y!==r.y&&t.push({x:r.x,y:i.y}),t.push(r)}return t}function di(e,t,r,i){let l=Math.min(r[0].x,r[1].x),n=Math.max(r[0].x,r[1].x),o=jo(e,l,n,l+Math.floor((n-l)/2)),a=e.columnWidth.get(o)??0;e.columnWidth.set(o,Math.max(a,i+2)),t.labelLine=[r[0],r[1]]}function Po(e,t){let r=0,i=Math.min(t[0].x,t[1].x),l=Math.max(t[0].x,t[1].x);for(let n=i;n<=l;n++)r+=e.columnWidth.get(n)??0;return r}var zo={solid:{h:{unicode:"\u2500",ascii:"-"},v:{unicode:"\u2502",ascii:"|"}},dotted:{h:{unicode:"\u2504",ascii:"."},v:{unicode:"\u2506",ascii:":"}},thick:{h:{unicode:"\u2501",ascii:"="},v:{unicode:"\u2503",ascii:"\u2016"}},invisible:{h:{unicode:" ",ascii:" "},v:{unicode:" ",ascii:" "}}};function Ir(e,t,r,i,l,n,o="solid"){let a=Fe(t,r),s=[],u=zo[o],f=n?u.h.ascii:u.h.unicode,h=n?u.v.ascii:u.v.unicode;if(p(a,re))for(let c=t.y-i;c>=r.y-l;c--)s.push({x:t.x,y:c}),G(e,t.x,c,h);else if(p(a,J))for(let c=t.y+i;c<=r.y+l;c++)s.push({x:t.x,y:c}),G(e,t.x,c,h);else if(p(a,U))for(let c=t.x-i;c>=r.x-l;c--)s.push({x:c,y:t.y}),G(e,c,t.y,f);else if(p(a,Z))for(let c=t.x+i;c<=r.x+l;c++)s.push({x:c,y:t.y}),G(e,c,t.y,f);else if(p(a,ft)){for(let c=t.x-i;c>=r.x;c--)s.push({x:c,y:t.y}),G(e,c,t.y,f);for(let c=t.y-1;c>=r.y-l;c--)s.push({x:r.x,y:c}),G(e,r.x,c,h)}else if(p(a,gt)){for(let c=t.x+i;c<=r.x;c++)s.push({x:c,y:t.y}),G(e,c,t.y,f);for(let c=t.y-1;c>=r.y-l;c--)s.push({x:r.x,y:c}),G(e,r.x,c,h)}else if(p(a,mt)){for(let c=t.x-i;c>=r.x;c--)s.push({x:c,y:t.y}),G(e,c,t.y,f);for(let c=t.y+1;c<=r.y+l;c++)s.push({x:r.x,y:c}),G(e,r.x,c,h)}else if(p(a,bt))if(r.x-t.x<=1)for(let c=t.y+i;c<=r.y+l;c++)s.push({x:t.x,y:c}),G(e,t.x,c,h);else{for(let c=t.x+i;c<=r.x;c++)s.push({x:c,y:t.y}),G(e,c,t.y,f);for(let c=t.y+1;c<=r.y+l;c++)s.push({x:r.x,y:c}),G(e,r.x,c,h)}return s}function Yo(e,t){if(t.path.length===0){let c=Be(e.canvas);return[c,c,c,c,c,c]}let r=Vo(e,t),[i,l,n]=Wo(e,t.path,t.style),o=l.length>0,a=t.style==="invisible",s=o&&!a?Fo(e,t.path,l[0],t.from):Be(e.canvas),u;u=t.hasArrowEnd&&o?kn(e,l[l.length-1],n[n.length-1],t.endMarker):Be(e.canvas);let f;if(t.hasArrowStart&&o){let c=l[0][0],g=qo(n[0]),m={x:c.x,y:c.y};p(n[0],Z)?m.x=c.x-1:p(n[0],U)?m.x=c.x+1:p(n[0],J)?m.y=c.y-1:p(n[0],re)&&(m.y=c.y+1),f=kn(e,[c,m],g,t.startMarker)}else f=Be(e.canvas);let h=a?Be(e.canvas):Ho(e,t.path);return[i,s,u,f,h,r]}function qo(e){return p(e,re)?J:p(e,J)?re:p(e,U)?Z:p(e,Z)?U:p(e,ft)?bt:p(e,gt)?mt:p(e,mt)?gt:p(e,bt)?ft:St}function Wo(e,t,r="solid"){let i=Be(e.canvas),l=t[0],n=[],o=[];for(let a=1;a<t.length;a++){let s=t[a],u=pt(e,l),f=pt(e,s);if(Lr(u,f)){l=s;continue}let h=Fe(l,s),c=Ir(i,u,f,1,-1,e.config.useAscii,r);c.length===0&&c.push(u),n.push(c),o.push(h),l=s}return[i,n,o]}var No=new Set(["\u2502","\u2503","\u2551","\u2506","\u250A","|","\u2016"]),Mn=new Set(["\u2500","\u2501","\u2550","\u254C","\u2504","-","="]);function Fo(e,t,r,i){let l=Be(e.canvas),n=e.config.useAscii;if(i.shape==="state-start"||i.shape==="state-end")return l;let o=r[0],a=Fe(t[0],t[1]),s=n?"+":null,u=(f,h)=>e.canvas[f]?.[h];if(p(a,re)){let f=o.x,h=o.y+1,c=u(f,h);G(l,f,h,c!==void 0&&Mn.has(c)?s??"\u2534":n?"|":"\u2502")}else if(p(a,J)){let f=o.x,h=o.y-1,c=u(f,h);G(l,f,h,c!==void 0&&Mn.has(c)?s??"\u252C":n?"|":"\u2502")}else if(p(a,U)||p(a,Z)){let f=i.drawingCoord,h=i.drawing;if(f===null||h===null)throw Error(`drawBoxStart: node "${i.name}" has no drawingCoord/drawing assigned`);let c=h.length,g=p(a,U)?f.x:f.x+c-1,m=o.y,x=u(g,m);G(l,g,m,x!==void 0&&No.has(x)?s??(p(a,U)?"\u2524":"\u251C"):n?"-":"\u2500")}return l}function Tr(e,t){if(t==="circle")return e?"o":"\u25CB";if(t==="cross")return e?"x":"\u2715"}function vn(e){if(p(e,re))return"\u25B2";if(p(e,J))return"\u25BC";if(p(e,U))return"\u25C4";if(p(e,Z))return"\u25BA";if(p(e,gt))return"\u2197";if(p(e,ft))return"\u2196";if(p(e,bt))return"\u2198";if(p(e,mt))return"\u2199"}function An(e){if(p(e,re))return"^";if(p(e,J))return"v";if(p(e,U))return"<";if(p(e,Z))return">"}function kn(e,t,r,i){let l=Be(e.canvas);if(t.length===0)return l;let n=t[t.length-1],o=Fe(t.length>=2?t[t.length-2]:t[0],n);(t.length===1||p(o,St))&&(o=r);let a=Tr(e.config.useAscii,i),s;if(a!==void 0)s=a;else if(e.config.useAscii){let u=An(o);s=u===void 0?An(r)??"*":u}else{let u=vn(o);s=u===void 0?vn(r)??"\u25CF":u}return G(l,n.x,n.y,s),l}function Ho(e,t){let r=Be(e.canvas);for(let i=1;i<t.length-1;i++){let l=t[i],n=pt(e,l),o=Fe(t[i-1],l),a=Fe(l,t[i+1]),s;s=e.config.useAscii?"+":p(o,Z)&&p(a,J)||p(o,re)&&p(a,U)?"\u2510":p(o,Z)&&p(a,re)||p(o,J)&&p(a,U)?"\u2518":p(o,U)&&p(a,J)||p(o,re)&&p(a,Z)?"\u250C":p(o,U)&&p(a,re)||p(o,J)&&p(a,Z)?"\u2514":"+",G(r,n.x,n.y,s)}return r}function Oo(e,t){return e.edges.some(r=>r!==t&&r.from===t.to&&r.to===t.from)}function Vo(e,t){let r=Be(e.canvas);if(t.text.length===0)return r;let i=uo(e,t.labelLine),l;if(t.path.length>=2){let o=t.path[0].y,a=t.path[t.path.length-1].y;a<o?l=!0:a>o&&(l=!1)}let n=Oo(e,t);return Go(r,i,t.text,l,n),r}function Go(e,t,r,i,l=!1){if(t.length<2)return;let n=Math.min(t[0].x,t[1].x),o=Math.max(t[0].x,t[1].x),a=Math.min(t[0].y,t[1].y),s=Math.max(t[0].y,t[1].y),u=n+Math.floor((o-n)/2),f=a+Math.floor((s-a)/2);if(i!==void 0&&n===o){let g=s-a,m=Math.max(1,Math.floor(g/4));(l?i:!i)?f-=m:f+=m}let h=Le(r),c=f-Math.floor((h.length-1)/2);for(let g=0;g<h.length;g++){let m=h[g];Sl(e,{x:u-Math.floor(Pe(m)/2),y:c+g},m)}}function vt(e,t,r){let i=We(t),l=0;for(let s=0;s<2;s++)l+=e.columnWidth.get(i.x+s)??0;let n=0;for(let s=0;s<2;s++)n+=e.rowHeight.get(i.y+s)??0;let o={width:l+1,height:n+1,labelArea:{x:0,y:0,width:0,height:0},gridColumns:[0,0,0],gridRows:[0,0,0]},a=t.drawingCoord;if(a===null)throw Error(`Node "${t.name}" has no drawingCoord; grid layout must run before bundled-edge drawing`);return fo(t.shape,r,o,a)}function Jo(e,t,r){let i=Be(e.canvas),l=t.pathToJunction;if(!l||l.length===0)return[i,i,i,i,i,i];let n=Be(e.canvas),o=e.config.useAscii,a=l.map((f,h)=>r.type==="fan-in"&&h===0?vt(e,t.from,t.startDir):r.type==="fan-out"&&h===l.length-1?vt(e,t.to,t.endDir):pt(e,f));for(let f=1;f<a.length;f++){let h=a[f-1],c=a[f];Lr(h,c)||Ir(n,h,c,1,-1,o,t.style)}let s=Be(e.canvas);for(let f=1;f<l.length-1;f++){let h=l[f],c=pt(e,h),g=Fe(l[f-1],h),m=Fe(h,l[f+1]),x;x=o?"+":p(g,Z)&&p(m,J)||p(g,re)&&p(m,U)?"\u2510":p(g,Z)&&p(m,re)||p(g,J)&&p(m,U)?"\u2518":p(g,U)&&p(m,J)||p(g,re)&&p(m,Z)?"\u250C":p(g,U)&&p(m,re)||p(g,J)&&p(m,Z)?"\u2514":"+",G(s,c.x,c.y,x)}let u=Be(e.canvas);if(r.type==="fan-in"&&l.length>=2){let f=a[0],h=Fe(l[0],l[1]),c=o?"+":null;p(h,re)?G(u,f.x,f.y,c??"\u2534"):p(h,J)?G(u,f.x,f.y,c??"\u252C"):p(h,U)?G(u,f.x,f.y,c??"\u2524"):p(h,Z)&&G(u,f.x,f.y,c??"\u251C")}return[n,u,i,i,s,Be(e.canvas)]}function Zo(e,t){let r=Be(e.canvas),i=Be(e.canvas);if(t.sharedPath.length<2)return[r,i];let l=e.config.useAscii,n=t.edges[0]?.style??"solid",o=e.config.graphDirection,a=t.sharedPath.map((s,u)=>{if(t.type==="fan-in"&&u===t.sharedPath.length-1){let f=o==="TD"?re:U;return vt(e,t.sharedNode,f)}if(t.type==="fan-out"&&u===0){let f=o==="TD"?J:Z;return vt(e,t.sharedNode,f)}return pt(e,s)});for(let s=1;s<a.length;s++){let u=a[s-1],f=a[s];Lr(u,f)||Ir(r,u,f,1,-1,l,n)}for(let s=1;s<t.sharedPath.length-1;s++){let u=t.sharedPath[s],f=pt(e,u),h=Fe(t.sharedPath[s-1],u),c=Fe(u,t.sharedPath[s+1]),g;g=l?"+":p(h,Z)&&p(c,J)||p(h,re)&&p(c,U)?"\u2510":p(h,Z)&&p(c,re)||p(h,J)&&p(c,U)?"\u2518":p(h,U)&&p(c,J)||p(h,re)&&p(c,Z)?"\u250C":p(h,U)&&p(c,re)||p(h,J)&&p(c,Z)?"\u2514":"+",G(i,f.x,f.y,g)}return[r,i]}function Qo(e,t){let r=Be(e.canvas);if(t.sharedPath.length<2)return r;let i=t.sharedPath.length-1,l=t.sharedPath[i-1],n=t.sharedPath[i],o=Fe(l,n),a=e.config.graphDirection,s=a==="TD"?re:U,u=vt(e,t.sharedNode,s);a==="TD"?--u.y:--u.x;let f=t.edges[0]?.endMarker,h=t.edges.every(m=>m.endMarker===f)?f:void 0,c=Tr(e.config.useAscii,h),g;return g=c===void 0?e.config.useAscii?p(o,re)?"^":p(o,J)?"v":p(o,U)?"<":p(o,Z)?">":"v":p(o,re)?"\u25B2":p(o,J)?"\u25BC":p(o,U)?"\u25C4":p(o,Z)?"\u25BA":"\u25BC":c,G(r,u.x,u.y,g),r}function Uo(e,t){let r=Be(e.canvas);if(!t.pathToJunction||t.pathToJunction.length<2)return r;let i=t.pathToJunction.length-1,l=t.pathToJunction[i-1],n=t.pathToJunction[i],o=Fe(l,n),a=e.config.graphDirection,s=a==="TD"?re:U,u=vt(e,t.to,s);a==="TD"?--u.y:--u.x;let f=Tr(e.config.useAscii,t.endMarker),h;return h=f===void 0?e.config.useAscii?p(o,re)?"^":p(o,J)?"v":p(o,U)?"<":p(o,Z)?">":"v":p(o,re)?"\u25B2":p(o,J)?"\u25BC":p(o,U)?"\u25C4":p(o,Z)?"\u25BA":"\u25BC":f,G(r,u.x,u.y,h),r}function gi(e){return p(e,re)?J:p(e,J)?re:p(e,U)?Z:p(e,Z)?U:e}function Ko(e,t){let r=Be(e.canvas);if(t.sharedPath.length<2)return r;let i=t.sharedPath[0],l=t.sharedPath[1],n=gi(Fe(i,l)),o=e.config.graphDirection,a=o==="TD"?J:Z,s=vt(e,t.sharedNode,a);o==="TD"?s.y+=1:s.x+=1;let u;return u=e.config.useAscii?p(n,re)?"^":p(n,J)?"v":p(n,U)?"<":p(n,Z)?">":"^":p(n,re)?"\u25B2":p(n,J)?"\u25BC":p(n,U)?"\u25C4":p(n,Z)?"\u25BA":"\u25B2",G(r,s.x,s.y,u),r}function _o(e,t){let r=Be(e.canvas);if(!t.pathToJunction||t.pathToJunction.length<2)return r;let i=t.pathToJunction[0],l=t.pathToJunction[1],n=gi(Fe(i,l)),o=vt(e,t.from,t.startDir);p(t.startDir,re)?--o.y:p(t.startDir,J)?o.y+=1:p(t.startDir,U)?--o.x:p(t.startDir,Z)&&(o.x+=1);let a;return a=e.config.useAscii?p(n,re)?"^":p(n,J)?"v":p(n,U)?"<":p(n,Z)?">":"v":p(n,re)?"\u25B2":p(n,J)?"\u25BC":p(n,U)?"\u25C4":p(n,Z)?"\u25BA":"\u25BC",G(r,o.x,o.y,a),r}function ea(e,t){let r=Be(e.canvas);if(!t.junctionPoint)return r;let i=pt(e,t.junctionPoint),l=e.config.useAscii,n=!1,o=!1,a=!1,s=!1;if(t.sharedPath.length>=2){let f=t.type==="fan-in"?0:t.sharedPath.length-1,h=t.type==="fan-in"?1:t.sharedPath.length-2,c=Fe(t.sharedPath[f],t.sharedPath[h]);p(c,J)?o=!0:p(c,re)?n=!0:p(c,Z)?s=!0:p(c,U)&&(a=!0)}for(let f of t.edges)if(f.pathToJunction&&f.pathToJunction.length>=2){let h=t.type==="fan-in"?f.pathToJunction.length-1:0,c=t.type==="fan-in"?f.pathToJunction.length-2:1,g=Fe(f.pathToJunction[c],f.pathToJunction[h]);p(g,J)?n=!0:p(g,re)?o=!0:p(g,Z)?a=!0:p(g,U)&&(s=!0)}let u;return u=l?"+":n&&o&&a&&s?"\u253C":o&&a&&s&&!n?"\u252C":n&&a&&s&&!o?"\u2534":n&&o&&s&&!a?"\u251C":n&&o&&a&&!s?"\u2524":a&&s?"\u2500":n&&o?"\u2502":o&&s?"\u250C":o&&a?"\u2510":n&&s?"\u2514":n&&a?"\u2518":"\u253C",G(r,i.x,i.y,u),r}function ta(e,t){let r=e.maxX-e.minX,i=e.maxY-e.minY;if(r<=0||i<=0)return qe(0,0);let l={x:0,y:0},n={x:r,y:i},o=qe(r,i);if(t.config.useAscii){for(let a=l.x+1;a<n.x;a++)G(o,a,l.y,"-");for(let a=l.x+1;a<n.x;a++)G(o,a,n.y,"-");for(let a=l.y+1;a<n.y;a++)G(o,l.x,a,"|");for(let a=l.y+1;a<n.y;a++)G(o,n.x,a,"|");G(o,l.x,l.y,"+"),G(o,n.x,l.y,"+"),G(o,l.x,n.y,"+"),G(o,n.x,n.y,"+")}else{for(let a=l.x+1;a<n.x;a++)G(o,a,l.y,"\u2500");for(let a=l.x+1;a<n.x;a++)G(o,a,n.y,"\u2500");for(let a=l.y+1;a<n.y;a++)G(o,l.x,a,"\u2502");for(let a=l.y+1;a<n.y;a++)G(o,n.x,a,"\u2502");G(o,l.x,l.y,"\u250C"),G(o,n.x,l.y,"\u2510"),G(o,l.x,n.y,"\u2514"),G(o,n.x,n.y,"\u2518")}return o}function ra(e,t){let r=e.maxX-e.minX,i=e.maxY-e.minY;if(r<=0||i<=0)return[qe(0,0),{x:0,y:0},[]];let l=qe(r,i),n=[],o=Le(e.name);for(let a=0;a<o.length;a++){let s=o[a],u=1+a,f=1+Math.ceil((r-1-Pe(s))/2);f<1&&(f=1);let h=rt(s);for(let c=0;c<h.length;c++)f+c>=r||u>=i||(G(l,f+c,u,h[c]),n.push({x:f+c,y:u}))}return[l,{x:e.minX,y:e.minY},n]}function na(e,t){return ia(e,t)}function ia(e,t){let r=We(e),i=t.config.useAscii,l=0;for(let M=0;M<2;M++)l+=t.columnWidth.get(r.x+M)??0;let n=0;for(let M=0;M<2;M++)n+=t.rowHeight.get(r.y+M)??0;let o={x:0,y:0},a={x:l,y:n},s=qe(Math.max(o.x,a.x),Math.max(o.y,a.y)),u=tt(e.shape,i),f=e.shape==="state-end",h=i?f?"=":"-":f?"\u2550":"\u2500",c=i?f?"\u2016":"|":f?"\u2551":"\u2502",g=f?i?{tl:"#",tr:"#",bl:"#",br:"#"}:{tl:"\u2554",tr:"\u2557",bl:"\u255A",br:"\u255D"}:u;for(let M=o.x+1;M<a.x;M++)G(s,M,o.y,h);for(let M=o.x+1;M<a.x;M++)G(s,M,a.y,h);for(let M=o.y+1;M<a.y;M++)G(s,o.x,M,c);for(let M=o.y+1;M<a.y;M++)G(s,a.x,M,c);G(s,o.x,o.y,g.tl),G(s,a.x,o.y,g.tr),G(s,o.x,a.y,g.bl),G(s,a.x,a.y,g.br);let m=e.displayLabel,x=Le(m),A=o.y+Math.floor(n/2)-Math.floor((x.length-1)/2);for(let M=0;M<x.length;M++){let j=x[M],v=Pe(j),P=o.x+Math.floor(l/2)-Math.ceil(v/2)+1,$=rt(j);for(let V=0;V<$.length;V++)G(s,P+V,A+M,$[V])}return s}function la(e,t){return na(e,t)}function mi(e){return/^[┌┐└┘├┤┬┴┼│─╭╮╰╯+\-|]$/.test(e)?"border":"text"}function Er(e,t=1){let r=Math.max(0,t),i=0;for(let n of e)for(let o of n)i=Math.max(i,Pe(o));let l=0;for(let n of e)l+=Math.max(n.length,1);return{width:i+2*r+2,height:l+(e.length-1)+2}}function pi(e,t,r=1){let i=Math.max(0,r),{width:l,height:n}=Er(e,i),o=t?"-":"\u2500",a=t?"|":"\u2502",s=t?"+":"\u250C",u=t?"+":"\u2510",f=t?"+":"\u2514",h=t?"+":"\u2518",c=t?"+":"\u251C",g=t?"+":"\u2524",m=qe(l-1,n-1);G(m,0,0,s);for(let A=1;A<l-1;A++)G(m,A,0,o);G(m,l-1,0,u),G(m,0,n-1,f);for(let A=1;A<l-1;A++)G(m,A,n-1,o);G(m,l-1,n-1,h);for(let A=1;A<n-1;A++)G(m,0,A,a),G(m,l-1,A,a);let x=1;for(let A=0;A<e.length;A++){let M=e[A],j=M.length>0?M:[""];for(let v of j){let P=1+i,$=rt(v);for(let V=0;V<$.length;V++)G(m,P+V,x,$[V]);x++}if(A<e.length-1){G(m,0,x,c);for(let v=1;v<l-1;v++)G(m,v,x,o);G(m,l-1,x,g),x++}}return m}function oa(e){function t(i){return i.parent===null?0:1+t(i.parent)}let r=[...e];return r.sort((i,l)=>t(i)-t(l)),r}function Cr(e,t,r,i){for(let l=0;l<t.length;l++)for(let n=0;n<(t[0]?.length??0);n++){let o=t[l]?.[n];if(o&&o!==" "){let a=l+r.x,s=n+r.y;a>=0&&s>=0&&er(e,a,s,i)}}}function Ct(e,t,r,i){for(let l of t)Cr(e,l,r,i)}function aa(e,t,r){let i=l=>/^[┌┐└┘├┤┬┴┼│─╭╮╰╯+\-|.':]$/.test(l);for(let l=0;l<t.length;l++)for(let n=0;n<(t[0]?.length??0);n++){let o=t[l]?.[n];if(o&&o!==" "){let a=l+r.x,s=n+r.y;a>=0&&s>=0&&er(e,a,s,i(o)?"border":"text")}}}function sa(e){let t=e.config.useAscii,r={x:0,y:0},i=oa(e.subgraphs);for(let g of i){let m=ta(g,e),x={x:g.minX,y:g.minY};e.canvas=ut(e.canvas,x,t,m),Cr(e.roleCanvas,m,x,"border")}for(let g of e.nodes)!g.drawn&&g.drawingCoord&&g.drawing&&(e.canvas=ut(e.canvas,g.drawingCoord,t,g.drawing),aa(e.roleCanvas,g.drawing,g.drawingCoord),g.drawn=!0);let l=[],n=[],o=[],a=[],s=[],u=[],f=[],h=new Set;for(let g of e.edges)if(g.bundle&&g.pathToJunction){let m=g.bundle,[x,A,,,M,j]=Jo(e,g,m);if(l.push(x),n.push(M),s.push(A),u.push(j),m.type==="fan-in"&&g.hasArrowStart){let v=_o(e,g);a.push(v)}if(!h.has(m)){h.add(m);let[v,P]=Zo(e,m);if(l.push(v),n.push(P),m.type==="fan-in"){let V=Qo(e,m);o.push(V)}if(m.type==="fan-out"&&m.edges.every(V=>V.hasArrowStart)){let V=Ko(e,m);a.push(V)}let $=ea(e,m);f.push($)}if(m.type==="fan-out"&&g.hasArrowEnd){let v=Uo(e,g);o.push(v)}}else{let[m,x,A,M,j,v]=Yo(e,g);l.push(m),n.push(j),o.push(A),a.push(M),s.push(x),u.push(v)}let c=vl(l);e.canvas=ut(e.canvas,r,t,...c),Ct(e.roleCanvas,c,r,"line"),e.canvas=ut(e.canvas,r,t,...n),Ct(e.roleCanvas,n,r,"corner"),e.canvas=ut(e.canvas,r,t,...f),Ct(e.roleCanvas,f,r,"junction"),e.canvas=ut(e.canvas,r,t,...o),Ct(e.roleCanvas,o,r,"arrow"),e.canvas=ut(e.canvas,r,t,...s),Ct(e.roleCanvas,s,r,"junction"),e.canvas=ut(e.canvas,r,t,...a),Ct(e.roleCanvas,a,r,"arrow"),e.canvas=ut(e.canvas,r,t,...u),Ct(e.roleCanvas,u,r,"text");for(let g of e.subgraphs){if(g.nodes.length===0)continue;let[m,x,A]=ra(g,e);e.canvas=ut(e.canvas,x,t,m),Cr(e.roleCanvas,m,x,"text");for(let{x:M,y:j}of A){let v=m[M]?.[j];v===" "&&(G(e.canvas,M+x.x,j+x.y,v),er(e.roleCanvas,M+x.x,j+x.y,"text"))}}return e.canvas}function fa(e,t,r,i){if(i(e))return e;let l=Math.max(e-t,r-e);for(let n=1;n<=l;n++){let o=e+n;if(o<=r&&i(o))return o;let a=e-n;if(a>=t&&i(a))return a}}function ua(e){return`${e.keys.length>0?e.keys.join(",")+" ":"   "}${e.type} ${e.name}`}function ca(e){let t=Le(e.label),r=e.attributes.map(ua);return r.length===0?[t]:[t,r]}function Et(e,t,r=!1,i=!1){if(t)switch(e){case"one":return i?"+":"|";case"zero-one":return r?"o|":"|o";case"many":return r?"<":">";case"zero-many":return r?"o<":">o"}else switch(e){case"one":return i?"\u253C":"\u2502";case"zero-one":return r?"\u25CB\u2502":"\u2502\u25CB";case"many":return r?"\u255F":"\u2562";case"zero-many":return r?"\u25CB\u255F":"\u2562\u25CB"}}function ha(e){let t=new Set,r=[],i=new Map;for(let n of e.entities)i.set(n.id,new Set);for(let n of e.relationships)i.get(n.entity1)?.add(n.entity2),i.get(n.entity2)?.add(n.entity1);function l(n,o){let a=[n];for(;a.length>0;){let s=a.pop();if(!t.has(s)){t.add(s),o.add(s);for(let u of i.get(s)??[])t.has(u)||a.push(u)}}}for(let n of e.entities)if(!t.has(n.id)){let o=new Set;l(n.id,o),o.size>0&&r.push(o)}return r}function yr(e,t,r){let i=e.get(t);if(i===void 0)throw Error(`ER diagram layout: missing ${r} for entity "${t}"`);return i}function da(e,t,r,i){let l=At(e),n=Kr(l);if(n.entities.length===0)return"";let o=t.useAscii,a=$t(t.paddingX,5,6,6),s=$t(t.paddingY,5,4,2),u=$t(t.paddingY,5,2,1),f=Math.max(...["one","zero-one","many","zero-many"].flatMap(R=>[Et(R,o,!1).length,Et(R,o,!0).length])),h=new Map,c=new Map,g=new Map,m=new Map;for(let R of n.entities){m.set(R.id,R);let H=ca(R);h.set(R.id,H);let{width:I,height:ne}=Er(H,t.boxBorderPadding);c.set(R.id,I),g.set(R.id,ne)}let x=new Map;for(let R of n.relationships){if(!R.label)continue;let H=[R.entity1,R.entity2].sort().join("|"),I=ct(R.label);x.set(H,Math.max(x.get(H)??0,I))}let A=ha(n),M=new Map,j=0;for(let R of A){let H=n.entities.filter(de=>R.has(de.id)),I=Math.max(2,Math.ceil(Math.sqrt(H.length))),ne=0,be=0,pe=0;for(let de=0;de<H.length;de++){let Ye=H[de],Ve=yr(c,Ye.id,"box width"),De=yr(g,Ye.id,"box height");pe>=I&&(j+=be+s,ne=0,be=0,pe=0),M.set(Ye.id,{entity:Ye,sections:yr(h,Ye.id,"sections"),x:ne,y:j,width:Ve,height:De});let Ie=a,Ke=pe+1>=I,_e=H[de+1];if(!Ke&&_e){let te=[Ye.id,_e.id].sort().join("|"),ce=x.get(te)??0;ce>0&&(Ie=Math.max(Ie,ce+2))}ne+=Ve+Ie,be=Math.max(be,De),pe++}j+=be+u}let v=0,P=0;for(let R of M.values())v=Math.max(v,R.x+R.width),P=Math.max(P,R.y+R.height);v+=4,P+=2;let $=qe(v-1,P-1),V=Pt(v-1,P-1);function Q(R,H,I,ne){G($,R,H,I,{role:ne,roleCanvas:V})}function K(R,H){let I=V[R]?.[H];return I==="text"||I==="border"}function Ce(R,H,I,ne,be){for(let pe=0;pe<R.length;pe++){let de=H+pe;if(!(de<ne||de>be)&&K(de,I))return!1}return!0}function ue(R,H,I,ne,be){for(let pe=0;pe<R.length;pe++){let de=H+pe;if(!(de<ne||de>be)&&(K(de,I)||V[de]?.[I]==="arrow"||Me.has(`${de},${I}`)))return!1}return!0}for(let R of M.values()){let H=pi(R.sections,o,t.boxBorderPadding);for(let I=0;I<H.length;I++)for(let ne=0;ne<H[0].length;ne++){let be=H[I][ne];if(be!==" "){let pe=R.x+I,de=R.y+ne;pe<v&&de<P&&Q(pe,de,be,mi(be))}}}let Me=new Set;for(let R of M.values())for(let H=0;H<R.height;H++)for(let I=0;I<R.width;I++)Me.add(`${R.x+I},${R.y+H}`);function F(R,H,I,ne){Me.has(`${R},${H}`)||(ne==="text"||V[R]?.[H]!=="text")&&Q(R,H,I,ne)}function ve(R,H,I,ne){V[R-1]?.[H]!=="text"&&V[R+1]?.[H]!=="text"&&F(R,H,I,ne)}function me(R,H,I,ne){for(let be=I;be<=ne;be++)for(let pe=R;pe<=H;pe++){let de=$[pe]?.[be];if(de!==void 0&&de!==" ")return!1}return!0}let He=[];function ze(R,H,I){for(let ne of He)if(Math.abs(ne.x-R)===1&&H<=ne.yEnd&&I>=ne.yStart)return!0;return!1}function Te(R,H,I){for(let ne of He)if(!(Math.abs(ne.x-R)>1)&&H<=ne.yEnd&&I>=ne.yStart)return!0;return!1}function O(R,H,I){He.push({x:R,yStart:H,yEnd:I})}let we=o?"-":"\u2500",$e=o?"|":"\u2502",Se=o?".":"\u254C",Oe=o?":":"\u250A";function it(R,H){return o?"+":R==="down"?H==="right"?"\u250C":"\u2510":H==="right"?"\u2514":"\u2518"}function fe(R,H,I,ne){F(R,H,it(I,ne),"line")}let Je=new Map,nt=new Map;for(let R of n.relationships){let H=M.get(R.entity1),I=M.get(R.entity2);if(!H||!I)continue;let ne=H.y+Math.floor(H.height/2),be=I.y+Math.floor(I.height/2);if(Math.abs(ne-be)<Math.max(H.height,I.height))continue;let[pe,de]=ne<be?[H,I]:[I,H],Ye=pe.x+Math.floor(pe.width/2),Ve=de.x+Math.floor(de.width/2),De=nt.get(pe.entity.id);De||(De=[],nt.set(pe.entity.id,De)),De.push({rel:R,otherCenterX:Ve});let Ie=Je.get(de.entity.id);Ie||(Ie=[],Je.set(de.entity.id,Ie)),Ie.push({rel:R,otherCenterX:Ye})}function lt(R,H,I){let ne=I.get(R.entity.id),be=R.x+Math.floor(R.width/2);if(!ne||ne.length<=1)return be;let pe=[...ne].sort((Ie,Ke)=>Ie.otherCenterX-Ke.otherCenterX),de=pe.findIndex(Ie=>Ie.rel===H);if(de===-1)return be;let Ye=Math.min(1,Math.floor((R.width-1)/2)),Ve=Math.max(0,R.width-1-Ye*2),De=pe.length>1?Ve/(pe.length-1):0;return R.x+Ye+Math.round(de*De)}for(let R of n.relationships){let H=M.get(R.entity1),I=M.get(R.entity2);if(!H||!I)continue;let ne=R.identifying?we:Se,be=R.identifying?$e:Oe,pe=H.x+Math.floor(H.width/2),de=H.y+Math.floor(H.height/2),Ye=I.x+Math.floor(I.width/2),Ve=I.y+Math.floor(I.height/2);if(Math.abs(de-Ve)<Math.max(H.height,I.height)){let[De,Ie]=pe<Ye?[H,I]:[I,H],[Ke,_e]=pe<Ye?[R.cardinality1,R.cardinality2]:[R.cardinality2,R.cardinality1],te=De.x+De.width,ce=Ie.x-1,y=De.y+Math.floor(De.height/2),C;for(let z of M.values())z!==De&&z!==Ie&&z.y===De.y&&z.x<ce+1&&z.x+z.width>te&&(C=Math.max(C??0,z.y+z.height));let D=ce-te+1,B=+(D>=f+1),S=Et(Ke,o,!1),N=Et(_e,o,!0),ae=+(D>=3&&S[0]===$e),E=+(D>=3&&N[N.length-1]===$e),Y=te+ae,ie=ce-E,le;if(C===void 0){for(let z=te;z<=ce;z++)ve(z,y,ne,"line");if(le=y+1,R.label){let z=te+B,oe=ce-B,_=Le(R.label).length,ee=y+1+Math.max(s-1,1);for(;le<ee&&!me(z,oe,le,le+_-1);)le++}}else{let z=Math.max(De.y+De.height,Ie.y+Ie.height,C),oe=R.label?Le(R.label).length:0,_=z+1,ee=z+Math.max(s*3,4);for(;_<ee&&!me(te,ce,_,_+oe);)_++;st($,ce+1,_+oe+1),dt(V,ce+1,_+oe+1);for(let se=y;se<=_;se++)F(te,se,be,"line"),F(ce,se,be,"line");for(let se=te;se<=ce;se++)ve(se,_,ne,"line");te!==ce&&(fe(te,_,"up","right"),fe(ce,_,"up","left")),le=_+1}for(let z=0;z<S.length;z++)F(Y+z,y,S[z],"arrow");for(let z=0;z<N.length;z++)F(ie-N.length+1+z,y,N[z],"arrow");if(R.label){let z=Le(R.label),oe=Math.floor((te+ce)/2),_=te+B,ee=ce-B;for(let se=0;se<z.length;se++){let d=z[se],b=rt(d),L=Math.max(_,oe-Math.floor(b.length/2)),X=le+se;if(st($,Math.max(L+b.length,1),Math.max(X+1,1)),dt(V,Math.max(L+b.length,1),Math.max(X+1,1)),Ce(b,L,X,_,ee))for(let k=0;k<b.length;k++){let T=L+k;T>=_&&T<=ee&&F(T,X,b[k],"text")}}}}else{let D=function(k,T,w){for(let W=T;W<=w;W++)if(Me.has(`${k},${W}`))return!1;return!0},ie=function(k,T,w){let W=Math.floor(E<=Y?(E+Y)/2:(te+ce)/2);if(E>Y)return W;for(let he=E;he<=Y;he++)if(me(k,T,he,he+w))return he;return W},[De,Ie]=de<Ve?[H,I]:[I,H],[Ke,_e]=de<Ve?[R.cardinality1,R.cardinality2]:[R.cardinality2,R.cardinality1],te=De.y+De.height,ce=Ie.y-1,y=lt(De,R,nt),C=lt(Ie,R,Je),B=te,S=ce,N=Math.max(...[...M.values()].filter(k=>k.y===De.y).map(k=>k.y+k.height)),ae=Ie.y,E=Math.max(te,N+1),Y=Math.min(ce,ae-1),le=y!==C,z=Math.min(y,C),oe=Math.max(y,C),_=le?ie(z,oe,0):ce,ee=le?_-1:ce,se=!D(y,E,Y)||!D(C,E,Y)||ze(y,te,le?_:ce)||le&&ze(C,_,ce),d=y;if(se){let k=$.length,T;for(let w=0;w<=k;w++){let W=y+w;if(D(W,te,ce)&&!Te(W,te,ce)){T=W;break}let he=y-w;if(w>0&&D(he,te,ce)&&!Te(he,te,ce)){T=he;break}}d=T??y;for(let w=te;w<=B;w++)F(y,w,be,"line");for(let w=Math.min(y,d);w<=Math.max(y,d);w++)ve(w,B,ne,"line");for(let w=B;w<=S;w++)F(d,w,be,"line");for(let w=Math.min(d,C);w<=Math.max(d,C);w++)ve(w,S,ne,"line");for(let w=S;w<=ce;w++)F(C,w,be,"line");if(y!==d){let w=d>y?"right":"left",W=w==="right"?"left":"right";fe(y,B,"up",w),fe(d,B,"down",W)}if(d!==C){let w=C>d?"right":"left",W=w==="right"?"left":"right";fe(d,S,"up",w),fe(C,S,"down",W)}O(d,B,S)}else{for(let k=te;k<=ee;k++)F(y,k,be,"line");if(O(y,te,le?_:ee),le){for(let w=z;w<=oe;w++)ve(w,_,ne,"line");for(let w=_+1;w<=ce;w++)F(C,w,be,"line");O(C,_,ce);let k=C>y?"right":"left",T=k==="right"?"left":"right";fe(y,_,"up",k),fe(C,_,"down",T),d=C}}let b=Et(Ke,o,!1,!0);for(let k=0;k<b.length;k++)F(y-Math.floor(b.length/2)+k,B,b[k],"arrow");let L=y===C?y:C,X=Et(_e,o,!0,!0);for(let k=0;k<X.length;k++)F(L-Math.floor(X.length/2)+k,S,X[k],"arrow");if(R.label){let k=Le(R.label),T=Math.max(b.length-1-Math.floor(b.length/2),X.length-1-Math.floor(X.length/2)),w=d+T+2,W=k.map(ge=>rt(ge)),he=w+Math.max(...W.map(ge=>ge.length))-1,Ae=k.length,je=Math.floor((te+ce)/2)-Math.floor((Ae-1)/2);he>=0&&(st($,he+1,ce+1),dt(V,he+1,ce+1));let ke=null;for(let ge=0;ge<=ce-te&&ke===null;ge++){let q=ge===0?[je]:[je+ge,je-ge];for(let xe of q)if(!(xe<te||xe+Ae-1>ce)&&W.every((Re,Xe)=>ue(Re,w,xe+Xe,0,he))){ke=xe;break}}if(ke!==null)for(let ge=0;ge<Ae;ge++){let q=W[ge],xe=ke+ge;for(let Xe=0;Xe<q.length;Xe++){let Ze=w+Xe;Ze>=0&&F(Ze,xe,q[Xe],"text")}V[w-1]?.[xe]==="line"&&Q(w-1,xe," ","line");let Re=w+q.length;V[Re]?.[xe]==="line"&&Q(Re,xe," ","line")}}}}return tr($,{roleCanvas:V,colorMode:r,theme:i})}var Sr=4,Cn=["O","/|\\","/ \\"],Sn=3,Rt=4;function br(e){return e.seqNumber===void 0?Sr:Sr+String(e.seqNumber).length}function ga(e,t,r,i){let l=At(e),n=_r(l);if(n.actors.length===0)return"";let o=t.useAscii,a=o?"-":"\u2500",s=o?"|":"\u2502",u=o?"+":"\u250C",f=o?"+":"\u2510",h=o?"+":"\u2514",c=o?"+":"\u2518",g=o?"+":"\u252C",m=o?"+":"\u2534",x=o?"+":"\u251C",A=o?"+":"\u2524",M=new Map;n.actors.forEach((d,b)=>M.set(d.id,b));function j(d){let b=M.get(d);if(b===void 0)throw Error(`Sequence diagram: unknown actor "${d}"`);return b}function v(d){let b=ct(d.label?`${d.type} [${d.label}]`:d.type);for(let L of d.dividers)L.label&&(b=Math.max(b,ct(`[${L.label}]`)));return b}let P=Math.max(0,t.boxBorderPadding),$=d=>Math.max(ct(d.label),d.type==="actor"?Sn:0),V=d=>gn(d.label)+(d.type==="actor"?Cn.length:0),Q=n.actors.map(d=>$(d)+2*P+2),K=Q.map(d=>Math.ceil(d/2)),Ce=n.actors.map(d=>V(d)+2),ue=Math.max(...Ce,3),Me=(d,b)=>b-Math.floor(Q[d]/2),F=Math.floor((ue-1)/2),ve=ue-1-F,me=new Map,He=new Map;n.actors.forEach((d,b)=>{d.createdAt!==void 0&&me.set(d.createdAt,b),d.destroyedAt!==void 0&&He.set(d.destroyedAt,b)});let ze=new Map,Te=new Map,O=n.boxes.filter(d=>d.actorIds.length>0).map(d=>{let b=d.actorIds.map(j);return{label:d.label,lo:Math.min(...b),hi:Math.max(...b)}}),we=O.length>0,$e=n.actors.map((d,b)=>O.findIndex(L=>L.lo<=b&&b<=L.hi)),Se=+!!we,Oe=d=>d===""?0:ct(d)+6,it=Array(Math.max(n.actors.length-1,0)).fill(0);for(let d of n.messages){let b=j(d.from),L=j(d.to);if(b===L)continue;let X=Math.min(b,L),k=Math.max(b,L),T=ct(d.label)+4,w=k-X,W=Math.ceil(T/w);for(let he=X;he<k;he++)it[he]=Math.max(it[he],W)}function fe(d){let b=Le(d.text);return Math.max(...b.map(L=>Pe(L)))+2+2*P}let Je=Array(n.actors.length).fill(0),nt=Array(n.actors.length).fill(0),lt=Array(n.actors.length).fill(0),R=Array(n.actors.length).fill(0);for(let d of n.notes)if(d.position==="left"||d.position==="right"){let b=j(d.actorIds[0]),L=fe(d);d.position==="left"?Je[b]=Math.max(Je[b],L):nt[b]=Math.max(nt[b],L)}else if(d.position==="over"&&d.actorIds.length===1){let b=j(d.actorIds[0]),L=fe(d),X=Math.floor(L/2),k=L-X;lt[b]=Math.max(lt[b],X),R[b]=Math.max(R[b],k)}let H=$t(t.paddingX,5,10,4),I=[Math.max(K[0]+($e[0]===-1?0:2),Je[0]+1,lt[0])];for(let d=1;d<n.actors.length;d++){let b=$e[d-1],L=$e[d],X=b===L?0:(b===-1?0:1)+(L===-1?0:1),k=X===0?0:X*2-1,T=Math.max(nt[d-1],Je[d],R[d-1],lt[d])+2,w=Math.max(K[d-1]+K[d]+2+k,it[d-1]+2,T,H);I[d]=I[d-1]+w}let ne=d=>Me(d.lo,I[d.lo])-1-1,be=d=>Math.max(Me(d.hi,I[d.hi])+Q[d.hi]-1+1+1,ne(d)+Oe(d.label)-1);for(let d of O){if(d.hi+1>=n.actors.length)continue;let b=Me(d.hi+1,I[d.hi+1]),L=$e[d.hi+1]===-1?0:2,X=be(d)+1+1+L-b;if(X>0){let k=I.slice(d.hi+1).map(T=>T+X);I.splice(d.hi+1,k.length,...k)}}for(let d of n.blocks){let b=-1,L=-1,X=1/0,k=-1;for(let ke=d.startIndex;ke<=d.endIndex&&!(ke>=n.messages.length);ke++){let ge=n.messages[ke],q=j(ge.from),xe=j(ge.to);if(b=b===-1?Math.min(q,xe):Math.min(b,q,xe),L=Math.max(L,q,xe),X=Math.min(X,I[Math.min(q,xe)]),k=Math.max(k,I[Math.max(q,xe)]),q===xe){let Re=I[q]+Sr+2+ct(ge.label);k=Math.max(k,Re)}}if(L===-1||L+1>=n.actors.length)continue;let T=Math.max(0,X-Rt),w=k+Rt,W=T+1+v(d),he=Math.max(w,W),Ae=I[L+1],je=he+2-Ae;if(je>0){let ke=I.slice(L+1).map(ge=>ge+je);I.splice(L+1,ke.length,...ke)}}let pe=[],de=[],Ye=new Map,Ve=new Map,De=new Map,Ie=[],Ke=Se,_e=Ke+ue,te=_e+Se,ce=$t(t.paddingY,5,1,0),y=Math.max(ce,1);for(let d of n.notes){if(d.afterIndex!==-1)continue;te+=ce;let b=Le(d.text),L=fe(d),X=b.length+2,k=M.get(d.actorIds[0])??0,T;if(d.position==="left")T=I[k]-L-1;else if(d.position==="right")T=I[k]+2;else if(d.actorIds.length>=2){let w=M.get(d.actorIds[1])??k;T=Math.floor((I[k]+I[w])/2)-Math.floor(L/2)}else T=I[k]-Math.floor(L/2);T=Math.max(0,T),Ie.push({x:T,y:te,width:L,height:X,lines:b}),te+=X}for(let d=0;d<n.messages.length;d++){for(let w=0;w<n.blocks.length;w++)n.blocks[w].startIndex===d&&(te+=ce+1,Ye.set(w,te-1));for(let w=0;w<n.blocks.length;w++)for(let W=0;W<n.blocks[w].dividers.length;W++)n.blocks[w].dividers[W].index===d&&(te+=ce,De.set(`${w}:${W}`,te),te+=y);te+=ce;let b=n.messages[d],L=b.from===b.to,X=gn(b.label),k=L?void 0:me.get(d),T=He.get(d);if(L)de[d]=te+1,pe[d]=te,te+=2+X;else{let w=k===void 0?0:F,W=k===void 0?0:ve;de[d]=te,pe[d]=te+X+w,te+=X+w+1+W,k!==void 0&&ze.set(k,pe[d]-w)}T!==void 0&&(Te.set(T,te),te+=1);for(let w=0;w<n.notes.length;w++)if(n.notes[w].afterIndex===d){te+=ce;let W=n.notes[w],he=Le(W.text),Ae=fe(W),je=he.length+2,ke=M.get(W.actorIds[0])??0,ge;if(W.position==="left")ge=I[ke]-Ae-1;else if(W.position==="right")ge=I[ke]+2;else if(W.actorIds.length>=2){let q=M.get(W.actorIds[1])??ke;ge=Math.floor((I[ke]+I[q])/2)-Math.floor(Ae/2)}else ge=I[ke]-Math.floor(Ae/2);ge=Math.max(0,ge),Ie.push({x:ge,y:te,width:Ae,height:je,lines:he}),te+=je}for(let w=0;w<n.blocks.length;w++)n.blocks[w].endIndex===d&&(te+=ce,Ve.set(w,te),te+=y)}te+=y;let C=te,D=C+Se,B=D+ue+Se,S=(I[I.length-1]??0)+(K[K.length-1]??0)+2;for(let d of O)S=Math.max(S,be(d)+2);for(let d=0;d<n.messages.length;d++){let b=n.messages[d];if(b.from===b.to){let L=I[j(b.from)]+br(b)+2+2+ct(b.label);S=Math.max(S,L+1)}}for(let d of Ie)S=Math.max(S,d.x+d.width+1);let N=qe(S,B-1),ae=Pt(S,B-1);function E(d,b,L,X){G(N,d,b,L,{role:X,roleCanvas:ae})}function Y(d,b,L,X,k){let T=rt(L);for(let w=0;w<T.length;w++){let W=d+w;if(k!==void 0&&W>=k||T[w+1]===""&&k!==void 0&&W+1>=k)break;E(W,b,T[w],X)}}function ie(d,b,L,X,k){let T=X==="actor"?Cn:[],w=[...T,...Le(L)],W=Math.max(ct(L),T.length>0?Sn:0),he=W+2*P+2,Ae=k,je=Ae-2,ke=d-Math.floor(he/2);E(ke,b,u,"border");for(let q=1;q<he-1;q++)E(ke+q,b,a,"border");E(ke+he-1,b,f,"border");for(let q=0;q<je;q++){let xe=b+1+q;E(ke,xe,s,"border"),E(ke+he-1,xe,s,"border");let Re=w[q];Re!==void 0&&Y(ke+1+P+Math.floor((W-Pe(Re))/2),xe,Re,"text")}let ge=b+Ae-1;E(ke,ge,h,"border");for(let q=1;q<he-1;q++)E(ke+q,ge,a,"border");E(ke+he-1,ge,c,"border")}let le=d=>{let b=ze.get(d);return b===void 0?_e:b+ue},z=d=>Te.get(d)??C;for(let d=0;d<n.actors.length;d++){let b=I[d];for(let L=le(d);L<=z(d);L++)E(b,L,s,"line")}let oe=o?"+":"\u253C";function _(d,b,L){let X=ne(d),k=be(d),T=b+ue+1;E(X,b,u,"border"),E(k,b,f,"border"),E(X,T,h,"border"),E(k,T,c,"border");for(let w=X+1;w<k;w++)E(w,b,a,"border"),E(w,T,a,"border");for(let w=b+1;w<T;w++)E(X,w,s,"border"),E(k,w,s,"border");L!==""&&Y(X+2,b,` ${Le(L)[0]} `,"text");for(let w=d.lo;w<=d.hi;w++){let W=I[w];le(w)<=b&&b<=z(w)&&E(W,b,oe,"junction"),le(w)<=T&&T<=z(w)&&E(W,T,oe,"junction")}}for(let d of O)_(d,0,d.label),_(d,C,"");for(let d=0;d<n.actors.length;d++){let b=n.actors[d],L=ze.get(d)??Ke,X=Te.has(d);ie(I[d],L,b.label,b.type,ue),X||ie(I[d],D,b.label,b.type,ue),o||(E(I[d],L+ue-1,g,"junction"),X||E(I[d],D,m,"junction"))}for(let d=0;d<n.messages.length;d++){let b=n.messages[d],L=j(b.from),X=j(b.to),k=I[L],T=I[X],w=L===X,W=b.lineStyle==="dashed",he=b.arrowHead==="filled",Ae=b.isLost===!0,je=o?"x":"\u2715",ke=W?o?".":"\u254C":a;if(w){let ge=pe[d],q=br(b),xe=b.seqNumber===void 0?void 0:String(b.seqNumber),Re=Le(b.label);E(k,ge,x,"junction");let Xe=k+1;if(xe!==void 0){for(let ye=0;ye<xe.length;ye++)E(k+1+ye,ge,xe[ye],"text");Xe=k+1+xe.length}for(let ye=Xe;ye<k+q;ye++)E(ye,ge,ke,"line");E(k+q,ge,o?"+":"\u2510","corner");let Ze=k+q+2;for(let ye=0;ye<Re.length;ye++){let et=ge+1+ye;E(k+q,et,s,"line"),Y(Ze,et,Re[ye],"text",S)}let Tt=ge+1+Re.length;E(k,Tt,Ae?je:he?o?"<":"\u25C0":o?"<":"\u25C1","arrow");for(let ye=k+1;ye<k+q;ye++)E(ye,Tt,ke,"line");E(k+q,Tt,o?"+":"\u2518","corner")}else{let ge=de[d],q=pe[d],xe=k<T,Re=me.get(d)===X,Xe=T;if(Re){let ye=Me(X,T),et=ye+Q[X]-1;Xe=xe?ye-1:et+1}let Ze=Math.floor((k+T)/2),Tt=Le(b.label);for(let ye=0;ye<Tt.length;ye++){let et=Tt[ye];Y(Ze-Math.floor(Pe(et)/2),ge+ye,et,"text",S)}if(xe){for(let ye=k+1;ye<Xe;ye++)E(ye,q,ke,"line");E(Xe,q,Ae?je:he?o?">":"\u25B6":o?">":"\u25B7","arrow"),b.bidirectional&&E(k,q,o?"<":"\u25C0","arrow")}else{for(let ye=Xe+1;ye<k;ye++)E(ye,q,ke,"line");E(Xe,q,Ae?je:he?o?"<":"\u25C0":o?"<":"\u25C1","arrow"),b.bidirectional&&E(k,q,o?">":"\u25B6","arrow")}if(b.seqNumber!==void 0){let ye=String(b.seqNumber);if(xe){let et=k+1;if(et+ye.length<T)for(let xt=0;xt<ye.length;xt++)E(et+xt,q,ye[xt],"text")}else{let et=k-ye.length;if(et>Xe)for(let xt=0;xt<ye.length;xt++)E(et+xt,q,ye[xt],"text")}}}}for(let[d,b]of Te)E(I[d],b,o?"x":"\u2715","arrow");let ee=S-1;for(let d=0;d<n.blocks.length;d++){let b=n.blocks[d],L=Ye.get(d),X=Ve.get(d);if(L===void 0||X===void 0)continue;let k=S,T=0;for(let q=b.startIndex;q<=b.endIndex&&!(q>=n.messages.length);q++){let xe=n.messages[q],Re=M.get(xe.from)??0,Xe=M.get(xe.to)??0;if(k=Math.min(k,I[Math.min(Re,Xe)]),T=Math.max(T,I[Math.max(Re,Xe)]),Re===Xe){let Ze=I[Re]+br(xe)+2+ct(xe.label);T=Math.max(T,Ze)}}let w=k-Rt,W=T+Rt,he=1/0,Ae=-1/0;for(let q of I)q>T&&q<he&&(he=q),q<k&&q>Ae&&(Ae=q);W>=he&&(W=Math.max(T,he-Rt)),w<=Ae&&(w=Math.min(k,Ae+Rt)),w=Math.max(0,w),W>ee&&(st(N,W+1,B-1),dt(ae,W+1,B-1),ee=W);let je=b.label?`${b.type} [${b.label}]`:b.type,ke=w+1+v(b);if(ke>W){W=ke;let[q]=Mt(N);W>q&&(st(N,W,B-1),dt(ae,W,B-1)),S=Math.max(S,W+1),ee=Math.max(ee,W)}E(w,L,u,"border");for(let q=w+1;q<W;q++)E(q,L,a,"border");E(W,L,f,"border");let ge=Le(je);for(let q=0;q<ge.length&&L+q<X;q++)Y(w+1,L+q,ge[q],"text",W);E(w,X,h,"border");for(let q=w+1;q<W;q++)E(q,X,a,"border");E(W,X,c,"border");for(let q=L+1;q<X;q++)E(w,q,s,"border"),E(W,q,s,"border");for(let q=0;q<b.dividers.length;q++){let xe=De.get(`${d}:${q}`);if(xe===void 0)continue;let Re=se();E(w,xe,x,"junction");for(let Ze=w+1;Ze<W;Ze++)E(Ze,xe,Re,"line");E(W,xe,A,"junction");let Xe=b.dividers[q].label;if(Xe){let Ze=`[${Xe}]`;Y(w+1,xe,Ze,"text",W)}}}for(let d of Ie){st(N,d.x+d.width,d.y+d.height),dt(ae,d.x+d.width,d.y+d.height),E(d.x,d.y,u,"border");for(let L=1;L<d.width-1;L++)E(d.x+L,d.y,a,"border");E(d.x+d.width-1,d.y,f,"border");for(let L=0;L<d.lines.length;L++){let X=d.y+1+L;E(d.x,X,s,"border"),E(d.x+d.width-1,X,s,"border");for(let k=d.x+1;k<d.x+d.width-1;k++)E(k,X," ","text");Y(d.x+1+P,X,d.lines[L],"text")}let b=d.y+d.height-1;E(d.x,b,h,"border");for(let L=1;L<d.width-1;L++)E(d.x+L,b,a,"border");E(d.x+d.width-1,b,c,"border")}return tr(N,{roleCanvas:ae,colorMode:r,theme:i});function se(){return o?"-":"\u254C"}}function ma(e,t){return e.rowStart<=t.rowEnd&&t.rowStart<=e.rowEnd}function pa(e,t){let r=e.map(n=>({item:n,geom:t(n)})).sort((n,o)=>n.geom.idealMid-o.geom.idealMid),i=(n,o)=>{let a=r[n];if(a)for(let s=n+o;s>=0&&s<r.length;s+=o){let u=r[s];if(u&&ma(u.geom,a.geom))return u.geom}},l=new Map;for(let[n,o]of r.entries()){let a=o.geom,s=i(n,-1),u=i(n,1),f=s&&s.end>=a.start?Math.floor((s.idealMid+a.idealMid)/2)+1:-1/0,h=u&&a.end>=u.start?Math.floor((a.idealMid+u.idealMid)/2):1/0;l.set(o.item,{left:f,right:h})}return l}function xa(e){let t=[];e.annotation&&t.push(`<<${e.annotation}>>`);let r=Le(e.label);t.push(...r);let i=e.attributes.map(ur),l=e.methods.map(ur),n=[t];return i.length>0&&n.push(i),l.length>0&&n.push(l),n}function ya(e,t){return{type:e,markerAt:t,dashed:e==="dependency"||e==="realization"}}function wt(e,t,r){switch(e){case"inheritance":case"realization":return r==="down"?t?"^":"\u25B3":r==="up"?t?"v":"\u25BD":r==="left"?t?">":"\u25C1":t?"<":"\u25B7";case"composition":return t?"*":"\u25C6";case"aggregation":return t?"o":"\u25C7";case"association":case"dependency":return r==="down"?t?"v":"\u25BC":r==="up"?t?"^":"\u25B2":r==="left"?t?"<":"\u25C0":t?">":"\u25B6"}}function ba(e,t,r,i,l){let n=e+t.length-1,o=i>e,a=l<n;if(!o&&!a)return{start:e,cells:t};let s=o?i:e,u=Math.max(0,(a?l:n)-s+1),f=+!!o+ +!!a;if(u===0)return{start:s,cells:[]};if(u<f)return{start:s,cells:["\u2026"]};let h=Math.max(0,u-f),c=rt(r),g=c.length<=h?c:o&&!a?c.slice(c.length-h):c.slice(0,h),m=[...o?["\u2026"]:[],...g,...a?["\u2026"]:[]];return{start:s+Math.max(0,Math.floor((u-m.length)/2)),cells:m}}function wr(e){return Math.max(...Le(e).map(t=>Pe(t)))+2}function wa(e,t,r,i,l={}){let n=At(e),{diagram:o,notesById:a}=Ma(Ur(n));if(o.classes.length===0)return"";let s=t.useAscii,u=$t(t.paddingX,5,4,1),f=$t(t.paddingY,5,3,1),h=new Map,c=new Map,g=new Map;for(let y of o.classes){let C=xa(y);h.set(y.id,C);let{width:D,height:B}=Er(C,t.boxBorderPadding);c.set(y.id,D),g.set(y.id,B)}let m=new Map;for(let y of o.classes)m.set(y.id,y);let x=new Map,A=new Map;for(let y of o.relationships){let C=y.from,D=y.to,B=x.get(D)??new Set;x.set(D,B),B.add(C);let S=A.get(C)??new Set;A.set(C,S),S.add(D)}let M=new Map,j=o.classes.filter(y=>!x.has(y.id)||x.get(y.id).size===0).map(y=>y.id);for(let y of j)M.set(y,0);let v=o.classes.length-1,P=0;for(;P<j.length;){let y=j[P++],C=A.get(y);if(C)for(let D of C){let B=(M.get(y)??0)+1;B>v||(!M.has(D)||M.get(D)<B)&&(M.set(D,B),j.push(D))}}for(let y of o.classes)M.has(y.id)||M.set(y.id,0);va(a,M);let $=Math.max(...M.values(),0),V=Array.from({length:$+1},()=>[]);for(let y of o.classes)V[M.get(y.id)].push(y.id);let Q=new Map,K=new Map;{let y=new Map;o.relationships.forEach((C,D)=>{let B=[C.from,C.to].sort().join("::"),S=y.get(B)??[];S.push(D),y.set(B,S)});for(let C of y.values()){if(C.length<2)continue;let D=C.length,B=Math.max(...C.map(S=>{let N=o.relationships[S].label;return N?wr(N):3}))+1;C.forEach((S,N)=>{Q.set(S,Math.round((N-(D-1)/2)*B)),K.set(S,(D-1)*B)})}}let Ce=new Map,ue=new Map,Me=new Map,F=new Map;{let y=(C,D,B)=>{let S=new Map;o.relationships.forEach((N,ae)=>{if(Q.has(ae)||!m.has(N.from)||!m.has(N.to))return;let E=M.get(N.from)??0;if((M.get(N.to)??0)-E!==1)return;let Y=C(N),ie=S.get(Y)??[];ie.push(ae),S.set(Y,ie)});for(let N of S.values()){if(N.length<2)continue;let ae=N.length,E=Math.max(...N.map(Y=>{let ie=o.relationships[Y].label;return ie?wr(ie):3}))+1;N.forEach((Y,ie)=>{D.set(Y,Math.round((ie-(ae-1)/2)*E)),B.set(Y,(ae-1)*E)})}};y(C=>C.to,Me,F),y(C=>C.from,Ce,ue)}let ve=new Map;for(let y of o.classes)ve.set(y.id,{left:0,right:0});o.relationships.forEach((y,C)=>{if(!m.has(y.from)||!m.has(y.to))return;let D=y.label?wr(y.label):1,B=Q.get(C)??Ce.get(C)??0,S=Q.get(C)??Me.get(C)??0,N=ve.get(y.from);N.left=Math.max(N.left,Math.floor(D/2)-B),N.right=Math.max(N.right,B+D-1-Math.floor(D/2));let ae=ve.get(y.to);ae.left=Math.max(ae.left,Math.floor(D/2)-S),ae.right=Math.max(ae.right,S+D-1-Math.floor(D/2))});let me=new Map,He=0,ze=0;for(let y=0;y<=$;y++){let C=V[y];if(C.length===0)continue;let D=z=>{let oe=x.get(z);return oe&&oe.size>0?[...oe].sort().join(","):`root:${z}`},B=new Map;for(let z of C){let oe=D(z),_=B.get(oe);_||(_=[],B.set(oe,_)),_.push(z)}let S=new Map,N=new Map,ae=new Map;{let z=0;for(let oe of C){let _=c.get(oe),ee=ve.get(oe),se=Math.max(0,ee.left-Math.floor(_/2)),d=Math.max(0,ee.right-(_-1-Math.floor(_/2)));S.set(oe,z),N.set(oe,se+_+d),ae.set(oe,se),z+=se+_+d+u}}let E=0,Y=0,ie=(z,oe)=>{let _=m.get(z),ee=c.get(z),se=g.get(z),d=ae.get(z),b=N.get(z);me.set(z,{cls:_,sections:h.get(z),x:oe+d,y:He,width:ee,height:se}),ze=Math.max(ze,oe+b),E=oe+b+u,Y=Math.max(Y,se)},le=new Set;for(let z of C){if(le.has(z))continue;let oe=D(z),_=x.get(z),ee=_?[..._].filter(Ae=>M.get(Ae)<y):[];if(ee.length===0){ie(z,Math.max(S.get(z),E,0)),le.add(z);continue}let se=B.get(oe),d=ee.map(Ae=>{let je=me.get(Ae);return je.x+Math.floor(je.width/2)}),b=Math.round(d.reduce((Ae,je)=>Ae+je,0)/d.length),L=0;for(let Ae=0;Ae<se.length;Ae++)L+=N.get(se[Ae]),Ae<se.length-1&&(L+=u);let X=ae.get(se[0]),k=se[se.length-1],T=N.get(k)-ae.get(k)-c.get(k),w=L-X-T,W=b-X-Math.floor(w/2),he=Math.max(W,E,0);for(let Ae of se)ie(Ae,he),le.add(Ae),he=E}He+=Y+f}let Te=ze,O=0;for(let y of me.values())Te=Math.max(Te,y.x+y.width),O=Math.max(O,y.y+y.height);Te+=4,O+=2;let we=qe(Te-1,O-1),$e=Pt(Te-1,O-1);function Se(y,C,D,B){G(we,y,C,D,{role:B,roleCanvas:$e})}let Oe=l.hyperlinks?Rn(Te-1,O-1):void 0;for(let y of me.values()){let C=pi(y.sections,s,t.boxBorderPadding);for(let D=0;D<C.length;D++)for(let B=0;B<C[0].length;B++){let S=C[D][B];if(S!==" "){let N=y.x+D,ae=y.y+B;N<Te&&ae<O&&Se(N,ae,S,mi(S))}}if(Oe){let D=rr(o.interactions.get(y.cls.id)?.href),B=y.sections[0];if(D!==void 0&&B!==void 0){let S=1+ +!!y.cls.annotation;Xn(Oe,C,{x:y.x,y:y.y},D,{from:S,to:B.length})}}}let it=new Set;for(let y of me.values())for(let C=0;C<y.height;C++)for(let D=0;D<y.width;D++)it.add(`${y.x+D},${y.y+C}`);function fe(y,C,D,B){it.has(`${y},${C}`)||Se(y,C,D,B)}function Je(y,C,D){for(let[B,S]of me.entries())if(!D?.has(B)&&y>=S.x&&y<=S.x+S.width-1&&C>=S.y&&C<=S.y+S.height-1)return!0;return!1}function nt(y,C,D,B){return fa(y,0,y+Te+9,S=>{for(let N=Math.min(C,D);N<=Math.max(C,D);N++)if(Je(S,N,B))return!1;return!0})??Te+2}let lt=s?"-":"\u2500",R=s?"|":"\u2502",H=s?".":"\u254C",I=s?":":"\u250A";function ne(y,C,D){let B=Math.floor(D/2),S=D-1-B,N=C>B+S?(B+S)/C:1;return Math.max(-B,Math.min(S,Math.round(y*N)))}function be(y,C,D){let B=Q.get(y)??Ce.get(y)??0,S=Q.get(y)??Me.get(y)??0,N=K.get(y)??ue.get(y)??0,ae=K.get(y)??F.get(y)??0,E=C.x+Math.floor(C.width/2),Y=D.x+Math.floor(D.width/2);return{fromCX:E+B,toCX:Y+S,fromAnchorX:E+ne(B,N,C.width),toAnchorX:Y+ne(S,ae,D.width)}}function pe(y,C,D,B){if(it.has(`${y},${C}`)||$e[y]?.[C]==="arrow")return;let S=we[y]?.[C];if(!s&&S!==void 0&&jt(S)&&jt(D)){let N=Vn(S,D);Se(y,C,N,N===D?B:"junction");return}Se(y,C,D,B)}function de(y,C,D,B,S){if(C===D)return;let N=Math.min(C,D),ae=Math.max(C,D);for(let le=N+1;le<ae;le++)pe(le,y,B,"line");if(s){pe(C,y,B,"line"),pe(D,y,B,"line");return}let E=D>C,Y=S?E?"\u2514":"\u2518":E?"\u250C":"\u2510",ie=S?E?"\u2510":"\u250C":E?"\u2518":"\u2514";pe(C,y,Y,"corner"),pe(D,y,ie,"corner")}let Ye=new Map,Ve=new Map;o.relationships.forEach((y,C)=>{let D=me.get(y.from),B=me.get(y.to);if(!D||!B)return;let S=ya(y.type,y.markerAt),N=S.dashed?H:lt,ae=S.dashed?I:R,E=new Set([y.from,y.to]),{fromCX:Y,toCX:ie,fromAnchorX:le,toAnchorX:z}=be(C,D,B),oe=D.y+D.height-1,_=B.y;if(oe<_){let ee=nt(Y,oe+1,_-1,E),se=ee!==Y;if(ee>=Te&&st(we,ee+2,O),se){let d=oe+1,b=_-1;Ye.set(C,{routeX:ee,exitY:d,entryY:b,fromAnchorX:le,toAnchorX:z,clearSide:ee>Y?"right":"left"});let L=Math.min(le,ee),X=Math.max(le,ee);for(let k=L;k<=X;k++)fe(k,d,N,"line");!s&&d<(we[0]?.length??0)&&(le<ee?(fe(le,d,"\u2514","corner"),fe(ee,d,"\u2510","corner")):(fe(le,d,"\u2518","corner"),fe(ee,d,"\u250C","corner")));for(let k=d+1;k<=b;k++)fe(ee,k,ae,"line");if(ee!==z){let k=Math.min(ee,z),T=Math.max(ee,z);for(let w=k;w<=T;w++)fe(w,b,N,"line");!s&&b<(we[0]?.length??0)&&(ee<z?(fe(ee,b,"\u2514","corner"),fe(z,b,"\u2510","corner")):(fe(ee,b,"\u2518","corner"),fe(z,b,"\u250C","corner")))}if(S.markerAt==="to"){let k=S.type==="inheritance"||S.type==="realization";fe(z,b,wt(S.type,s,k?"up":"down"),"arrow")}if(S.markerAt==="from"){let k=wt(S.type,s,"down");fe(le,oe+1,k,"arrow")}}else{let d=oe+Math.floor((_-oe)/2),b=Y!==le,L=ie!==z;de(oe+1,le,Y,N,!0);for(let X=oe+(b?2:1);X<=d;X++)fe(Y,X,ae,"line");if(Y!==ie&&d<(we[0]?.length??0)){let X=Math.min(Y,ie),k=Math.max(Y,ie);for(let T=X;T<=k;T++)fe(T,d,N,"line");s||(fe(Y,d,Y<ie?"\u2514":"\u2518","corner"),fe(ie,d,Y<ie?"\u2510":"\u250C","corner"))}for(let X=d+1;X<_-+!!L;X++)fe(ie,X,ae,"line");if(de(_-1,z,ie,N,!1),S.markerAt==="to"){let X=S.type==="inheritance"||S.type==="realization";fe(z,_-1,wt(S.type,s,X?"up":"down"),"arrow")}S.markerAt==="from"&&fe(le,oe+1,wt(S.type,s,"down"),"arrow")}}else if(B.y+B.height-1<D.y){let ee=D.y,se=B.y+B.height-1,d=se+Math.floor((ee-se)/2),b=Y!==le,L=ie!==z;de(ee-1,le,Y,N,!1);for(let X=ee-(b?2:1);X>=d;X--)fe(Y,X,ae,"line");if(Y!==ie){let X=Math.min(Y,ie),k=Math.max(Y,ie);for(let T=X;T<=k;T++)fe(T,d,N,"line");!s&&d>=0&&d<O&&(fe(Y,d,Y<ie?"\u250C":"\u2510","corner"),fe(ie,d,Y<ie?"\u2518":"\u2514","corner"))}for(let X=d-1;X>se+ +!!L;X--)fe(ie,X,ae,"line");if(de(se+1,z,ie,N,!0),S.markerAt==="from"){let X=wt(S.type,s,"up"),k=ee-1;for(let T=0;T<X.length;T++)fe(le-Math.floor(X.length/2)+T,k,X[T],"arrow")}if(S.markerAt==="to"){let X=S.type==="inheritance"||S.type==="realization"?"down":"up",k=wt(S.type,s,X),T=se+1;for(let w=0;w<k.length;w++)fe(z-Math.floor(k.length/2)+w,T,k[w],"arrow")}}else{let ee=B.y+B.height-1,se=Math.min(Y,ie),d=Math.max(Y,ie),b=Math.max(oe,ee);for(let[T,w]of me.entries())T!==y.from&&T!==y.to&&w.y===D.y&&w.x<d+1&&w.x+w.width>se&&(b=Math.max(b,w.y+w.height-1));let L=b+2;Ve.set(C,L),st(we,Te,L+1),dt($e,Te,L+1);let X=Y!==le,k=ie!==z;de(oe+1,le,Y,N,!0);for(let T=oe+(X?2:1);T<=L;T++)fe(Y,T,ae,"line");for(let T=se;T<=d;T++)fe(T,L,N,"line");for(let T=L-1;T>=ee+(k?2:1);T--)fe(ie,T,ae,"line");if(de(ee+1,z,ie,N,!0),S.markerAt==="from"){let T=wt(S.type,s,"down"),w=oe+1;for(let W=0;W<T.length;W++)fe(le-Math.floor(T.length/2)+W,w,T[W],"arrow")}if(S.markerAt==="to"){let T=S.type==="inheritance"||S.type==="realization",w=wt(S.type,s,T?"down":"up"),W=B.y+B.height;for(let he=0;he<w.length;he++)fe(z-Math.floor(w.length/2)+he,W,w[he],"arrow")}}});function De(y,C,D,B){let{fromCX:S,toCX:N}=be(y,C,D),ae=C.y+C.height-1,E=D.y;if(ae<E){let Y=Ye.get(y);if(Y){let ie=Y.exitY+1,le=Y.entryY;if(le>=ie)return{idealMidX:Y.clearSide==="right"?Y.routeX+1+Math.floor(B/2):Y.routeX-1-Math.ceil(B/2),baseMidY:Math.floor((ie+le)/2)};let z=Math.abs(Y.routeX-Y.fromAnchorX);return Math.abs(Y.toAnchorX-Y.routeX)>=z?{idealMidX:Math.floor((Y.routeX+Y.toAnchorX)/2),baseMidY:Y.entryY}:{idealMidX:Math.floor((Y.fromAnchorX+Y.routeX)/2),baseMidY:Y.exitY}}return{idealMidX:Math.floor((S+N)/2),baseMidY:Math.floor((ae+1+E-1)/2)}}if(D.y+D.height-1<C.y){let Y=D.y+D.height-1;return{idealMidX:Math.floor((S+N)/2),baseMidY:Math.floor((Y+1+C.y-1)/2)}}return{idealMidX:Math.floor((S+N)/2),baseMidY:Ve.get(y)??Math.max(ae,D.y+D.height-1)+2}}function Ie(y,C,D,B,S,N,ae){let E=B,Y=Math.floor(N/2),ie=y.y+y.height-1,le=C.y,z=!1;for(let oe=0;oe<N;oe++){let _=E-Y+oe,ee=D-Math.floor(S/2),se=Math.max(0,ee);for(let d=se;d<se+S;d++)if(Je(d,_,ae)){z=!0;break}if(z)break}if(z){let oe=ie+1,_=le-1;for(let ee=oe;ee<=_;ee++){let se=!0,d=D-Math.floor(S/2),b=Math.max(0,d);for(let L=b;L<b+S;L++)if(Je(L,ee,ae)){se=!1;break}if(se){E=ee;break}}}return E}let Ke=new Map,_e=[];for(let[y,C]of o.relationships.entries()){if(!C.label)continue;let D=me.get(C.from),B=me.get(C.to);if(!D||!B)continue;let S=Le(C.label),N=Math.floor(S.length/2),ae=Math.max(...S.map(Pe))+2,{idealMidX:E,baseMidY:Y}=De(y,D,B,ae),ie=new Set([C.from,C.to]),le=Ie(D,B,E,Y,ae,S.length,ie);Ke.set(C,le);let z=Math.max(0,E-Math.floor(ae/2));_e.push({rel:C,idealMidX:E,naturalStart:z,naturalEnd:z+ae-1,rowStart:le-N,rowEnd:le+N})}let te=pa(_e,y=>({idealMid:y.idealMidX,start:y.naturalStart,end:y.naturalEnd,rowStart:y.rowStart,rowEnd:y.rowEnd})),ce=new Map;for(let y of _e){let C=te.get(y);C&&ce.set(y.rel,C)}for(let[y,C]of o.relationships.entries()){let D=me.get(C.from),B=me.get(C.to);if(!(!D||!B)&&C.label){let S=Le(C.label),{idealMidX:N}=De(y,D,B,Math.max(...S.map(Y=>Pe(Y)))+2),ae=Ke.get(C)-Math.floor(S.length/2),E=ce.get(C);for(let Y=0;Y<S.length;Y++){let ie=ae+Y,le=S[Y],z=rt(` ${le} `),{start:oe,cells:_}=ba(Math.max(0,N-Math.floor(z.length/2)),z,le,Math.max(0,E.left),E.right),ee=oe+_.length;ee>0&&ie>=0&&(st(we,Math.max(ee,1),Math.max(ie+1,1)),dt($e,Math.max(ee,1),Math.max(ie+1,1)));for(let se=0;se<_.length;se++){let d=oe+se;d>=0&&ie>=0&&Se(d,ie,_[se],"text")}}}}return Aa(a,me,we,s,Se),tr(we,{roleCanvas:$e,colorMode:r,theme:i,linkCanvas:Oe})}function Ma(e){let t=new Map;if(e.notes.length===0)return{diagram:e,notesById:t};let r=(n,o)=>{let a=`note ${n}`;return t.set(a,o),{id:a,label:o.text,attributes:[],methods:[]}},i=new Set(e.classes.map(n=>n.id)),l=[];for(let n of e.classes){l.push(n);for(let[o,a]of e.notes.entries())a.forClass===n.id&&l.push(r(o,a))}for(let[n,o]of e.notes.entries())(o.forClass===void 0||!i.has(o.forClass))&&l.push(r(n,o));return{diagram:{...e,classes:l},notesById:t}}function va(e,t){for(let[r,i]of e){if(i.forClass===void 0)continue;let l=t.get(i.forClass);l!==void 0&&t.set(r,l)}}function Aa(e,t,r,i,l){if(e.size===0)return;let n=tt("rounded",i),o=i?".":"\u254C";for(let[a,s]of e){let u=t.get(a);if(!u)continue;let f=u.x+u.width-1,h=u.y+u.height-1;if(l(u.x,u.y,n.tl,"border"),l(f,u.y,n.tr,"border"),l(u.x,h,n.bl,"border"),l(f,h,n.br,"border"),s.forClass===void 0)continue;let c=t.get(s.forClass);if(!c||c.x+c.width>u.x||c.y!==u.y)continue;let g=c.y+1;for(let m=c.x+c.width;m<u.x;m++)r[m]?.[g]===" "&&l(m,g,o,"line")}}function $n(e){let t=e.trim();return t.length>=2&&(t[0]==='"'&&t[t.length-1]==='"'||t[0]==="'"&&t[t.length-1]==="'")?t.slice(1,-1):t}var ka='"graph <dir>"/"flowchart <dir>" (dir: TD, TB, LR, BT, RL), "stateDiagram-v2", "sequenceDiagram", "classDiagram", "erDiagram", "xychart-beta"';function Ca(e){let t=e.trim().toLowerCase();if(/^sequence/.test(t))return"sequenceDiagram";if(/^class/.test(t))return"classDiagram";if(/^er/.test(t))return"erDiagram";if(/^xychart/.test(t))return"xychart-beta";if(/^state/.test(t))return"stateDiagram-v2"}var Sa=/^(?:[\w-]+@)?<?(?:-{2,}|={2,}|-\.+-?|~{3,})/;function $a(e){let t=[];for(let r of e)r.forEach((i,l)=>{if(l===0&&t.length>0&&Sa.test(i.text)){let n=t[t.length-1];t[t.length-1]={text:`${n.text} ${i.text}`,line:n.line}}else t.push(i)});return t}function La(e){let t=qr(e.split(`
8`).map(n=>n.trim())),r=$a(nr(e));if(r.length===0)throw Error("Empty mermaid diagram");let i=r[0],l=/^stateDiagram(-v2)?\s*$/i.test(i.text)?Ia(r):Da(r);return l.initConfig=t,l}function Da(e){let t=e[0];if(t===void 0)throw Error("parseFlowchart called with no lines");let r=t.text,i=r.match(/^(?:graph|flowchart)\s+(TD|TB|LR|BT|RL)\s*$/i);if(!i){let o=r.match(/^(?:graph|flowchart)\b\s*(.*)$/i);if(o){let u=o[1].trim();throw Error(u.length>0?`Line ${t.line}: Invalid direction "${u}" in header "${r}". Expected one of: TD, TB, LR, BT, RL.`:`Line ${t.line}: Missing direction in header "${r}". Expected e.g. "graph TD" or "flowchart LR" \u2014 one of: TD, TB, LR, BT, RL.`)}let a=Ca(r),s=a&&a.toLowerCase()!==r.trim().toLowerCase()?` Did you mean "${a}"?`:"";throw Error(`Line ${t.line}: Invalid mermaid header: "${r}".${s} Supported headers: ${ka}.`)}let l={direction:kt(i[1]),nodes:new Map,edges:[],subgraphs:[],classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,linkStyles:new Map,interactions:new Map},n=[];for(let o=1;o<e.length;o++){let a=e[o].text;if(Ht(a,l)||Ot(a,l)||Vt(a,l))continue;if(/^click\s+/i.test(a)){Ya(a,l);continue}if(xi(a,l))continue;let s=a.match(/^linkStyle\s+(default|[\d,\s]+)\s+(.+)$/);if(s){let h=s[1].trim(),c=zt(s[2]);if(h==="default")l.linkStyles.set("default",{...l.linkStyles.get("default"),...c});else{let g=h.split(",").map(m=>parseInt(m.trim(),10));for(let m of g)isNaN(m)||l.linkStyles.set(m,{...l.linkStyles.get(m),...c})}continue}let u=a.match(/^direction\s+(TD|TB|LR|BT|RL)\s*$/i);if(u&&n.length>0){n[n.length-1].direction=kt(u[1]);continue}let f=a.match(/^subgraph\s+(.+)$/);if(f){let h=f[1].trim(),c=h.match(/^([^\s[]+)\s*\[(.+)\]$/),g,m;c?(g=c[1],m=Ee($n(c[2]))):(m=Ee($n(h)),g=m.replace(/\s+/g,"_").replace(/[^\p{L}\p{N}_-]/gu,""));let x={id:g,label:m,nodeIds:[],children:[]};n.push(x);continue}if(a==="end"){let h=n.pop();h&&(n.length>0?n[n.length-1].children.push(h):l.subgraphs.push(h));continue}Ha(a,l,n)}return l}function Ia(e){let t={direction:"TD",nodes:new Map,edges:[],subgraphs:[],classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,linkStyles:new Map,interactions:new Map},r=[],i=new Set,l=0,n=0;for(let o=1;o<e.length;o++){let a=e[o].text,s=a.match(/^direction\s+(TD|TB|LR|BT|RL)\s*$/i);if(s){r.length>0?r[r.length-1].direction=kt(s[1]):t.direction=kt(s[1]);continue}let u=a.match(/^linkStyle\s+(default|[\d,\s]+)\s+(.+)$/);if(u){let m=u[1].trim(),x=zt(u[2]);if(m==="default")t.linkStyles.set("default",{...t.linkStyles.get("default"),...x});else{let A=m.split(",").map(M=>parseInt(M.trim(),10));for(let M of A)isNaN(M)||t.linkStyles.set(M,{...t.linkStyles.get(M),...x})}continue}if(xi(a,t))continue;let f=a.match(/^state\s+(?:"([^"]+)"\s+as\s+)?([\w\p{L}]+)\s*\{$/u);if(f){let m=f[1]??f[2],x=f[2],A={id:x,label:m,nodeIds:[],children:[]};r.push(A),i.add(x),t.nodes.delete(x);continue}if(a==="}"){let m=r.pop();m&&(r.length>0?r[r.length-1].children.push(m):t.subgraphs.push(m));continue}let h=a.match(/^state\s+"([^"]+)"\s+as\s+([\w\p{L}]+)\s*$/u);if(h){let m=Ee(h[1]),x=h[2];qt(t,r,{id:x,label:m,shape:"rounded"});continue}let c=a.match(/^(\[\*\]|[\w\p{L}-]+)\s*(?:([\w-]+)@)?-->\s*(\[\*\]|[\w\p{L}-]+)(?:\s*:\s*(.+))?$/u);if(c){let m=c[1],x=c[2],A=c[3],M=c[4]?.trim(),j=M?Ee(M):void 0;m==="[*]"?(l++,m=`_start${l>1?l:""}`,qt(t,r,{id:m,label:"",shape:"state-start"})):i.has(m)||Ln(t,r,m),A==="[*]"?(n++,A=`_end${n>1?n:""}`,qt(t,r,{id:A,label:"",shape:"state-end"})):i.has(A)||Ln(t,r,A),t.edges.push({source:m,target:A,label:j,style:"solid",hasArrowStart:!1,hasArrowEnd:!0,...x===void 0?{}:{id:x}});continue}let g=a.match(/^([\w\p{L}-]+)\s*:\s*(.+)$/u);if(g){let m=g[1];qt(t,r,{id:m,label:Ee(g[2].trim()),shape:"rounded"});continue}}return t}function qt(e,t,r){if(e.nodes.has(r.id)||e.nodes.set(r.id,r),t.length>0){let i=t[t.length-1];i.nodeIds.includes(r.id)||i.nodeIds.push(r.id)}}function Ln(e,t,r){if(!e.nodes.has(r))qt(e,t,{id:r,label:r,shape:"rounded"});else if(t.length>0){let i=t[t.length-1];i.nodeIds.includes(r)||i.nodeIds.push(r)}}var Ta=/^(<|o|x)?(-{2,}|={2,}|-\.+-|~{3,})(>|o|x)?(?:\|([^|]*)\|)?/,Ea=new Set(["--","=="]);function Zt(e){if(e==="o")return"circle";if(e==="x")return"cross"}var Ra=/^(<|o|x)?(--|-\.|==)\s+(.+?)\s+(-{2,}[>ox]|={2,}[>ox]|\.+-[>ox]|-{3,}|={3,}|-\.+-)/,Xa=[{regex:/^([\w\p{L}-]+)\(\(\(((?:"[^"]*"|(?!\)\)\)).)+)\)\)\)/u,shape:"doublecircle"},{regex:/^([\w\p{L}-]+)\(\[((?:"[^"]*"|(?!\]\)).)+)\]\)/u,shape:"stadium"},{regex:/^([\w\p{L}-]+)\(\(((?:"[^"]*"|(?!\)\)).)+)\)\)/u,shape:"circle"},{regex:/^([\w\p{L}-]+)\[\[((?:"[^"]*"|(?!\]\]).)+)\]\]/u,shape:"subroutine"},{regex:/^([\w\p{L}-]+)\[\(((?:"[^"]*"|(?!\)\]).)+)\)\]/u,shape:"cylinder"},{regex:/^([\w\p{L}-]+)\[\/((?:"[^"]*"|(?![\\/]\]).)+)([\\/])\]/u,shape:e=>e==="\\"?"trapezoid":"parallelogram"},{regex:/^([\w\p{L}-]+)\[\\((?:"[^"]*"|(?![\\/]\]).)+)([\\/])\]/u,shape:e=>e==="/"?"trapezoid-alt":"parallelogram-alt"},{regex:/^([\w\p{L}-]+)>((?:"[^"]*"|(?!\]).)+)\]/u,shape:"asymmetric"},{regex:/^([\w\p{L}-]+)\{\{((?:"[^"]*"|(?!\}\}).)+)\}\}/u,shape:"hexagon"},{regex:/^([\w\p{L}-]+)\[((?:"[^"]*"|(?!\]).)+)\]/u,shape:"rectangle"},{regex:/^([\w\p{L}-]+)\(((?:"[^"]*"|(?!\)).)+)\)/u,shape:"rounded"},{regex:/^([\w\p{L}-]+)\{((?:"[^"]*"|(?!\}).)+)\}/u,shape:"diamond"}],Ba=/^([\w\p{L}]+(?:-[\w\p{L}]+)*)/u,ja=/^([\w\p{L}-]+)(?=@\{)/u;function Pa(e){if(e.shape)return nn(e.shape)??"rectangle";if(e.icon!==void 0||e.img!==void 0)switch(e.form?.toLowerCase()){case"circle":return"circle";case"rounded":return"rounded";default:return"rectangle"}return"rectangle"}function za(e,t){return t.label!==void 0&&t.label.length>0?t.label:t.icon?t.icon:t.img?t.img:e}function Ya(e,t){Ft(e,t.interactions)}var qa=/^([\w-]+)(?=@\{)/;function xi(e,t){let r=e.match(qa);if(!r||!t.edges.some(l=>l.id===r[1]))return!1;let i=dr(e.slice(r[1].length));return i?(Wa(t,r[1],hr(i.body)),!0):!1}function Wa(e,t,r){for(let i of e.edges)i.id===t&&(r.animate!==void 0&&(i.animate=r.animate.toLowerCase()!=="false"),r.animation!==void 0&&(i.animate=!0))}var Na=/^:::([\w][\w-]*)/,Fa=/^([\w\p{L}-]+):::([\w][\w-]*)/u;function Ha(e,t,r){let i=e.trim(),l=Dn(i,t,r);if(!l||l.ids.length===0)return;i=l.remaining.trim();let n=l.ids;for(;i.length>0;){let o,a,s,u,f,h,c,g=i.match(/^([\w-]+)@(?=[-=<~ox])/);g&&(c=g[1],i=i.slice(g[0].length));let m=i.match(Ta),x=m?.[2],A=m?.[1],M=m?.[3];if(m&&x!==void 0&&!(A===void 0&&M===void 0&&Ea.has(x))){o=A!==void 0,f=Zt(A);let v=m[4]?.trim();u=v?Ee(v):void 0,i=i.slice(m[0].length).trim(),a=Va(x),s=M!==void 0,h=Zt(M)}else{let v=i.match(Ra);if(!v)break;o=!!v[1],f=Zt(v[1]);let P=v[3].trim();u=P?Ee(P):void 0;let $=v[2],V=v[4];i=i.slice(v[0].length).trim(),a=Ga($,V),h=Zt(V.slice(-1)),s=V.endsWith(">")||h!==void 0}let j=Dn(i,t,r);if(!j||j.ids.length===0)break;i=j.remaining.trim();for(let v of n)for(let P of j.ids)t.edges.push({source:v,target:P,label:u,style:a,hasArrowStart:o,hasArrowEnd:s,...f===void 0?{}:{startMarker:f},...h===void 0?{}:{endMarker:h},...c===void 0?{}:{id:c}});n=j.ids}}function Dn(e,t,r){let i=In(e,t,r);if(!i)return null;let l=[i.id],n=i.remaining.trim();for(;n.startsWith("&");){n=n.slice(1).trim();let o=In(n,t,r);if(!o)break;l.push(o.id),n=o.remaining.trim()}return{ids:l,remaining:n}}function In(e,t,r){let i=null,l=e,n,o=l.match(Fa);o&&(n=o[2],l=o[1]+l.slice(o[0].length));let a=l.match(ja);if(a){let u=a[1],f=dr(l.slice(u.length));if(f){let h=hr(f.body);Mr(t,r,{id:u,label:Ee(za(u,h)),shape:Pa(h)}),i=u,l=l.slice(u.length+f.length)}}if(i===null)for(let{regex:u,shape:f}of Xa){let h=l.match(u);if(h){i=h[1];let c=Ee(h[2]),g=typeof f=="function"?f(h[3]??""):f;Mr(t,r,{id:i,label:c,shape:g}),l=l.slice(h[0].length);break}}if(i===null){let u=l.match(Ba);u&&(i=u[1],t.nodes.has(i)||Mr(t,r,{id:i,label:i,shape:"rectangle"}),l=l.slice(u[0].length))}if(i===null)return null;n&&t.classAssignments.set(i,n);let s=l.match(Na);return s&&(t.classAssignments.set(i,s[1]),l=l.slice(s[0].length)),{id:i,remaining:l}}function Mr(e,t,r){e.nodes.has(r.id)||e.nodes.set(r.id,r),Oa(t,r.id)}function Oa(e,t){if(e.length>0){let r=e[e.length-1];r.nodeIds.includes(t)||r.nodeIds.push(t)}}function Va(e){return e.startsWith("~")?"invisible":e.includes(".")?"dotted":e.startsWith("=")?"thick":"solid"}function Ga(e,t){return e.includes(".")||t.includes(".")?"dotted":e.startsWith("=")||t.startsWith("=")?"thick":"solid"}function Ja(e,t){let r=new Set,i=new Map;for(let f of e.subgraphs)yi(f,r,i);let l=new Map,n=0;for(let[f,h]of e.nodes){if(r.has(f))continue;let c={name:f,displayLabel:lr(h.label),shape:h.shape,index:n,gridCoord:null,drawingCoord:null,drawing:null,drawn:!1,styleClassName:"",styleClass:Yl};l.set(f,c),n++}let o=[...l.values()],a=[];for(let f of e.edges){let h=f.source,c=f.target;if(r.has(h)){let x=i.get(h),A=x?Tn(x,e,"exit"):void 0;A&&(h=A)}if(r.has(c)){let x=i.get(c),A=x?Tn(x,e,"entry"):void 0;A&&(c=A)}let g=l.get(h),m=l.get(c);!g||!m||a.push({from:g,to:m,text:f.label?lr(f.label):"",path:[],labelLine:[],startDir:{x:0,y:0},endDir:{x:0,y:0},style:f.style,hasArrowStart:f.hasArrowStart,hasArrowEnd:f.hasArrowEnd,...f.startMarker===void 0?{}:{startMarker:f.startMarker},...f.endMarker===void 0?{}:{endMarker:f.endMarker}})}let s=[];for(let f of e.subgraphs)bi(f,null,l,s,e);Qa(e.subgraphs,s,l);let u=e.classDefs.get("default");if(u)for(let f of l.values())f.styleClassName="default",f.styleClass={name:"default",styles:u};for(let[f,h]of e.classAssignments){let c=l.get(f),g=e.classDefs.get(h);c&&g&&(c.styleClassName=h,c.styleClass={name:h,styles:u?{...u,...g}:g})}return{nodes:o,edges:a,canvas:qe(0,0),roleCanvas:Pt(0,0),grid:li(),columnWidth:new Map,rowHeight:new Map,subgraphs:s,config:t,offsetX:0,offsetY:0,bundles:[]}}function yi(e,t,r){t.add(e.id),r.set(e.id,e);for(let i of e.children)yi(i,t,r)}function Rr(e,t){for(let r of e.nodeIds)t.add(r);for(let r of e.children)Rr(r,t)}function Za(e,t){let r=new Set;if(Rr(e,r),r.size===0)return!0;let i=l=>r.has(l)||l===e.id;return!t.edges.some(l=>i(l.source)!==i(l.target))}function Tn(e,t,r){let i=new Set;if(Rr(e,i),i.size===0)return;let l=[...t.nodes.keys()].filter(a=>i.has(a));if(l.length===0)return;let n=l.filter(a=>r==="entry"?!t.edges.some(s=>s.target===a&&i.has(s.source)):!t.edges.some(s=>s.source===a&&i.has(s.target))),o=n.length>0?n:l;return r==="entry"?o[0]:o[o.length-1]}function bi(e,t,r,i,l){let n;e.direction&&Za(e,l)&&(n=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:n};for(let a of e.nodeIds){let s=r.get(a);s&&o.nodes.push(s)}i.push(o);for(let a of e.children){let s=bi(a,o,r,i,l);o.children.push(s);for(let u of s.nodes)o.nodes.includes(u)||o.nodes.push(u)}return o}function Qa(e,t,r){let i=new Map;Ka(e,t,i);let l=new Map;function n(o){let a=i.get(o);if(a){for(let s of o.children)n(s);for(let s of o.nodeIds)l.has(s)||l.set(s,a)}}for(let o of e)n(o);for(let o of t)o.nodes=o.nodes.filter(a=>{let s;for(let[f,h]of r)if(h===a){s=f;break}if(!s)return!1;let u=l.get(s);return!u||Ua(o,u)})}function Ua(e,t){let r=t;for(;r!==null;){if(r===e)return!0;r=r.parent}return!1}function Ka(e,t,r){let i=[];function l(n){for(let o of n)i.push(o),l(o.children)}l(e);for(let n=0;n<i.length&&n<t.length;n++){let o=i[n],a=t[n];!o||!a||r.set(o,a)}}function _a(e,t,r,i,l={}){let n=Yr(La(e),l.direction);t.graphDirection=n.direction==="LR"||n.direction==="RL"?"LR":"TD";let o=Ja(n,t);ko(o),sa(o);let a=l.hyperlinks?cl(o,n.interactions):void 0;return n.direction==="BT"&&(kl(o.canvas),Cl(o.roleCanvas),a&&ul(a)),tr(o.canvas,{roleCanvas:o.roleCanvas,colorMode:r,theme:i,linkCanvas:a})}var es={xychart:(e,t,r,i)=>El(e,t,r,i),er:(e,t,r,i)=>da(e,t,r,i),sequence:(e,t,r,i)=>ga(e,t,r,i),class:(e,t,r,i,l)=>wa(e,t,r,i,l),flowchart:(e,t,r,i,l)=>_a(e,t,r,i,l)},ts=/\x1b\[[0-9;]*m/g;function rs(e){let t=e.split(`
9`),r=t.reduce((n,o)=>Math.max(n,sl(o.replace(ts,"")).length),0),i=String(Math.max(0,t.length-1)).length,l=" ".repeat(i+1);return[l+Array.from({length:r},(n,o)=>String(Math.floor(o/10)%10)).join(""),l+Array.from({length:r},(n,o)=>String(o%10)).join(""),...t.map((n,o)=>`${String(o).padStart(i," ")} ${n}`)].join(`
10`)}function ns(e,t={}){let r={useAscii:t.useAscii??!1,paddingX:t.paddingX??5,paddingY:t.paddingY??5,boxBorderPadding:t.boxBorderPadding??1,graphDirection:"TD"},i=t.colorMode==="auto"||t.colorMode===void 0?hl():t.colorMode,l={...Pn,...t.theme},n=es[ir(e)](e,r,i,l,{hyperlinks:t.hyperlinks??!1,direction:t.direction});return t.showCoords?rs(n):n}export{ns as renderMermaidASCII};
11