SLOPSHOPPER

mermaid-pane

Claude renders Mermaid diagrams into a side pane (auto-opens on any ```mermaid block in a reply); reopen with /diagrams

paneguardcommandtoaststatustool
v0.3.0no licenseupdated 2026-10-18namdar12/claude-mods/plugins/mermaid-pane
A shopper browsing a rack in a slop shop
Preview · a replayed session in a sandbox
claude · ~/work/app · mermaid-pane
│ ┃ Diagrams ✕ › fix the failing auth test and add an audit log call │ ┃ No diagrams yet │ ┃ Ask Claude to draw one. Any ```mermaid block ⏺ Read(src/auth.ts) │ ┃ in a reply appears here automatically. ⎿ Read 6 lines │ ⏺ Update(src/auth.ts) │ ⎿ Added 2 lines, removed 1 line │ ⏺ Bash(bun test) │ ⎿ 3 pass, 1 fail │ │ ● Done. refresh now rejects expired claims and logs an audit event. │ │ ✻ Worked for 42s · done 4:20 PM │ │ › /diagrams │ ⎿ mermaid-pane: Diagrams pane opened (no diagrams yet). │ │ ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── › ? for shortcuts

Draws

Pane · Diagrams
No diagrams yet Ask Claude to draw one. Any ```mermaid block in a reply appears here automatically.
README

claude-mods

Mods for Claude Code, published as a plugin marketplace.

ModWhat it does
mermaid-paneRenders Mermaid diagrams into a side pane. Any `mermaid block in Claude's reply opens there automatically, and Claude also gets a show_diagram tool. Page through them with n/p, view the source with s, open in the browser with o; reopen with /diagrams.
cca-quizMultiple-choice practice for the Claude Certified Architect exams, shown above the prompt while Claude works. Toggle with /quiz (/quiz on, /quiz off, /quiz reset); answer with 1–4.
session-park/park-all saves and closes every open Claude Code terminal session (the one you ran it in last) so you can upgrade; /unpark-all reopens each one resumed in its original directory. /park-all force also closes sessions that are mid-turn.

Install

At the prompt of a Claude Code terminal session:

/plugin install mermaid-pane --marketplace namdar12/claude-mods
/plugin install cca-quiz --marketplace namdar12/claude-mods
/plugin install session-park --marketplace namdar12/claude-mods

Answer y to add the marketplace, then pick a scope (user scope is first; Enter selects it). The mod is active right away.

From a shell:

claude plugin install mermaid-pane --marketplace namdar12/claude-mods
claude plugin install cca-quiz --marketplace namdar12/claude-mods
claude plugin install session-park --marketplace namdar12/claude-mods

In the desktop app, where /plugin does not run: click + next to the prompt box, then Plugins, Add marketplace with namdar12/claude-mods, then Add plugin.

Notes

  • mermaid-pane renders with npx @mermaid-js/mermaid-cli (Node.js required; the first render downloads it) and writes diagrams to ~/.claude/mermaid-diagrams/. Image sizing (sips) and "open in browser" (open) use macOS commands; on other systems the pane still shows the diagram source.
  • kitty and Ghostty show the rendered picture (the kitty graphics protocol). Every other terminal (Warp, iTerm2, WezTerm, Terminal.app, …) gets the diagram drawn in box-drawing characters on white, its labels wrapped to fit the pane's width: widen the pane (ctrl+x ← in the fullscreen layout) to see more. Flowcharts, sequence, state, class and ER diagrams draw as text; other types show their source. o always opens the full picture in the browser.
  • The text renderer is beautiful-mermaid (MIT), vendored in plugins/mermaid-pane/hooks/vendor/.
  • session-park needs its helper script on your machine (Python 3, macOS). After installing the mod, copy plugins/session-park/bin/claude-park to ~/.local/bin/claude-park and make it executable (chmod +x). Restore opens one Warp tab per session, or Terminal.app windows when Warp is not installed. You can also run it from a shell: claude-park park, claude-park restore, claude-park list.
Source 3 files
hooks/register.tsx 542 lines
1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, Register } from 'claude-code'
3
4import type { Diagram } from '../types'
5import { renderMermaidASCII } from './vendor/beautiful-mermaid-ascii.js'
6
7const PANE = 'mermaid'
8const TOOL = 'mcp__mermaid-pane__show_diagram'
9const MMDC = ['npx', '-y', '@mermaid-js/mermaid-cli@11']
10const FENCE = /```mermaid[^\n]*\n([\s\S]*?)```/g
11
12const diagrams = atom({ plugin: 'mermaid-pane', key: 'diagrams' } as const, [] as Diagram[])
13const index = atom({ plugin: 'mermaid-pane', key: 'index' } as const, 0)
14const showSource = atom({ plugin: 'mermaid-pane', key: 'showSource' } as const, false)
15
16const LABEL_WIDTH = 16
17// Tighter label wraps tried in turn until the diagram fits the pane.
18const FIT_WIDTHS = [24, 16, 12]
19const DOCK_MIN = 44
20// The text view's paper: dark ink on white, a cell of margin each side.
21const PAPER = '#ffffff'
22const INK = '#1f2328'
23const MARGIN = 1
24const DOCK_MAX = 80
25const INLINE_ROWS = 30
26
27// A word longer than `width` split after its / _ . - marks; a word without them stays whole.
28export const splitWord = (word: string, width: number): string[] =>
29  word.length <= width ? [word] : word.split(/(?<=[/_.\-])/).filter(Boolean)
30
31// Breaks a label into lines of about `width` characters, joined by <br/>.
32export const wrapLabel = (text: string, width = LABEL_WIDTH) => {
33  const words = text
34    .replace(/<br\s*\/?>/gi, ' ')
35    .trim()
36    .split(/\s+/)
37    .flatMap(word => splitWord(word, width))
38  const lines: string[] = []
39  let line = ''
40  for (const word of words) {
41    if (line && line.length + 1 + word.length > width) {
42      lines.push(line)
43      line = word
44    } else {
45      line = line ? `${line} ${word}` : word
46    }
47  }
48  if (line) lines.push(line)
49
50  return lines.join('<br/>')
51}
52
53// Wraps long labels so a diagram drawn as text fits a narrow pane: sequence messages
54// and participant names (notes draw wrong wrapped), flowchart [box] labels and |edge| labels.
55export const narrowSource = (source: string, width = LABEL_WIDTH) => {
56  const long = (text: string) => text.trim().length > width
57  const isSequence = /^\s*sequenceDiagram\b/.test(source)
58
59  return source
60    .split('\n')
61    .map(line => {
62      if (isSequence) {
63        const message = line.match(
64          /^(\s*([^:\s]+?)\s*(?:->>|-->>|->|-->|-x|--x|-\)|--\))[+-]?\s*([^:\s]+?)\s*:)(.*)$/,
65        )
66        // A message to itself draws wrong wrapped.
67        const isSelf = message && message[2] === message[3]
68        if (message && !isSelf && long(message[4]!)) return `${message[1]} ${wrapLabel(message[4]!, width)}`
69        const actor = line.match(/^(\s*(?:participant|actor)\s+\S+\s+as\s+)(.*)$/)
70        if (actor && long(actor[2]!)) return `${actor[1]}${wrapLabel(actor[2]!, width)}`
71
72        return line
73      }
74
75      return line
76        .replace(/\[([^\[\]"|]+)\]/g, (all, label: string) => (long(label) ? `[${wrapLabel(label, width)}]` : all))
77        .replace(/\|([^|"]+)\|/g, (all, label: string) => (long(label) ? `|${wrapLabel(label, width)}|` : all))
78    })
79    .join('\n')
80}
81
82const pending = new Set<string>()
83const artCache = new Map<string, TextArt>()
84
85type TextArt = { lines: string[]; width: number } | { error: string }
86
87const isBlankRow = (line: string) => /^[\s│]*$/.test(line)
88
89// Fewer rows without losing an arrow or a label: a sequence diagram drops its rows of
90// bare lifelines; a flowchart, whose bare rows are its edges, only a repeat of the row above.
91export const collapseRows = (lines: string[], isSequence = false) =>
92  lines.filter((line, i) =>
93    isSequence ? !isBlankRow(line) : i === 0 || !isBlankRow(line) || line !== lines[i - 1],
94  )
95
96// The diagram drawn in box-drawing characters, for terminals that cannot show the PNG:
97// boxes without inner padding and repeated blank rows dropped, to fit more in view.
98export const textArt = (source: string, labelWidth = LABEL_WIDTH): TextArt => {
99  try {
100    const drawn = renderMermaidASCII(narrowSource(source, labelWidth), {
101      colorMode: 'none',
102      paddingX: 2,
103      paddingY: 1,
104      boxBorderPadding: 0,
105    })
106    const isSequence = /^\s*sequenceDiagram\b/.test(source)
107    const lines = collapseRows(
108      drawn.split('\n').map(line => line.trimEnd()),
109      isSequence,
110    )
111    while (lines.length && !lines.at(-1)) lines.pop()
112    if (!lines.length) return { error: 'the renderer drew nothing' }
113
114    return { lines, width: Math.max(...lines.map(line => Array.from(line).length)) }
115  } catch (error) {
116    return { error: error instanceof Error ? error.message : String(error) }
117  }
118}
119
120const artFor = (diagram: Diagram, labelWidth: number) => {
121  const key = `${diagram.id}:${labelWidth}`
122  let art = artCache.get(key)
123  if (!art) {
124    art = textArt(diagram.source, labelWidth)
125    artCache.set(key, art)
126    if (artCache.size > 200) artCache.delete(artCache.keys().next().value!)
127  }
128
129  return art
130}
131
132// The widest-label drawing that fits `columns`, else the narrowest one there is.
133export const fitArt = (draw: (labelWidth: number) => TextArt, columns: number) => {
134  let narrowest: TextArt | undefined
135  for (const labelWidth of FIT_WIDTHS) {
136    const art = draw(labelWidth)
137    if (!('lines' in art)) return art
138    if (art.width <= columns) return art
139    if (!narrowest || ('lines' in narrowest && art.width < narrowest.width)) narrowest = art
140  }
141
142  return narrowest!
143}
144
145const artOf = (diagram: Diagram, columns = DOCK_MAX - MARGIN * 2) =>
146  fitArt(labelWidth => artFor(diagram, labelWidth), columns)
147
148export const hasKittyGraphics = (env: string) => {
149  const [program = '', term = '', kittyWindow = ''] = env.split('|')
150
151  return /ghostty/i.test(program) || /kitty/i.test(term) || kittyWindow.trim() !== ''
152}
153
154let kittyPromise: Promise<boolean> | undefined
155
156// The engine's Image draws only through the kitty graphics protocol (kitty, Ghostty).
157const canDrawImages = ($: EngineInterface) => {
158  kittyPromise ??= $.process
159    .run(['sh', '-c', 'printf "%s|%s|%s" "$TERM_PROGRAM" "$TERM" "$KITTY_WINDOW_ID"'])
160    .then(({ stdout }) => hasKittyGraphics(stdout))
161    .catch(() => false)
162
163  return kittyPromise
164}
165
166const escapeHtml = (text: string) =>
167  text.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;')
168
169export const htmlPage = (title: string, source: string) => `<!doctype html>
170<html><head><meta charset="utf-8"><title>${escapeHtml(title)}</title>
171<style>body{font-family:system-ui;margin:24px;background:#fff;color:#111}
172@media (prefers-color-scheme:dark){body{background:#111;color:#eee}}
173pre.src{background:#8881;padding:12px;overflow:auto}</style></head>
174<body><h2>${escapeHtml(title)}</h2>
175<pre class="mermaid">${escapeHtml(source)}</pre>
176<details><summary>Source</summary><pre class="src">${escapeHtml(source)}</pre></details>
177<script type="module">
178import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs'
179mermaid.initialize({ startOnLoad: true, theme: matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'default' })
180</script></body></html>
181`
182
183export const fitImage = (
184  width: number | undefined,
185  height: number | undefined,
186  maxColumns: number,
187  maxRows: number,
188) => {
189  const ratio = width && height ? height / width : 0.5
190  let columns = Math.max(1, Math.min(255, maxColumns))
191  let rows = Math.max(1, Math.round((columns * ratio) / 2))
192  if (rows > maxRows) {
193    rows = Math.max(1, maxRows)
194    columns = Math.max(1, Math.min(columns, Math.round((rows * 2) / ratio)))
195  }
196
197  return { columns, rows: Math.min(255, rows) }
198}
199
200export const cleanSource = (raw: string) =>
201  raw
202    .replace(/^\s*```(?:mermaid)?\s*\n/, '')
203    .replace(/\n\s*```\s*$/, '')
204    .trim()
205
206export const extractMermaid = (text: string) => {
207  const found: { title: string; source: string }[] = []
208  for (const match of text.matchAll(FENCE)) {
209    const source = match[1]!.trim()
210    if (!source) continue
211    const before = text
212      .slice(0, match.index)
213      .split('\n')
214      .map(line => line.trim())
215      .filter(Boolean)
216    const label = before.at(-1) ?? ''
217    const isLabel =
218      /^(#{1,6}\s|\*\*)/.test(label) || (label.endsWith(':') && label.length <= 60)
219    const heading = isLabel
220      ? label
221          .replace(/^#{1,6}\s+/, '')
222          .replaceAll('**', '')
223          .replace(/:$/, '')
224          .trim()
225      : ''
226    const kind = source.split(/\s/)[0] || 'diagram'
227    found.push({ title: (heading || kind).slice(0, 120), source })
228  }
229
230  return found
231}
232
233let dirPromise: Promise<string> | undefined
234
235const diagramDir = ($: EngineInterface) => {
236  dirPromise ??= $.process
237    .run(['printenv', 'HOME'])
238    .then(({ stdout }) => `${stdout.trim()}/.claude/mermaid-diagrams`)
239
240  return dirPromise
241}
242
243const render = async ($: EngineInterface, title: string, source: string): Promise<Diagram> => {
244  const dir = await diagramDir($)
245  const id = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`
246  const base = `${dir}/${id}`
247  const diagram: Diagram = { id, title, source, htmlPath: `${base}.html`, createdAt: Date.now() }
248
249  await $.fs.write(`${base}.mmd`, source)
250  await $.fs.write(diagram.htmlPath, htmlPage(title, source))
251
252  const ran = await $.process
253    .run([...MMDC, '-i', `${base}.mmd`, '-o', `${base}.png`, '-b', 'white', '-s', '2', '-q'], {
254      timeoutMs: 180_000,
255    })
256    .catch((error: unknown) => ({ exitCode: -1, stdout: '', stderr: String(error) }))
257
258  if (ran.exitCode !== 0 || !(await $.fs.exists(`${base}.png`))) {
259    const reason = ran.stderr.trim().split('\n').slice(-6).join('\n')
260
261    return { ...diagram, error: reason || `mermaid-cli exited ${ran.exitCode}` }
262  }
263
264  diagram.pngPath = `${base}.png`
265  const size = await $.process
266    .run(['sips', '-g', 'pixelWidth', '-g', 'pixelHeight', diagram.pngPath])
267    .catch(() => undefined)
268  diagram.width = Number(size?.stdout.match(/pixelWidth: (\d+)/)?.[1]) || undefined
269  diagram.height = Number(size?.stdout.match(/pixelHeight: (\d+)/)?.[1]) || undefined
270
271  return diagram
272}
273
274// The dock as wide as the diagram's text needs, within a sidebar's bounds.
275export const dockColumns = (art: TextArt | undefined) =>
276  art && 'lines' in art ? Math.min(DOCK_MAX, Math.max(DOCK_MIN, art.width + MARGIN * 2 + 2)) : DOCK_MAX
277
278const openPane = ($: EngineInterface, focus = false, diagram?: Diagram) =>
279  $.ui.open({
280    id: PANE,
281    title: 'Diagrams',
282    columns: dockColumns(diagram ? artOf(diagram) : undefined),
283    rows: INLINE_ROWS,
284    ...(focus ? { focus: true as const } : {}),
285  })
286
287const addDiagram = async ($: EngineInterface, title: string, source: string) => {
288  $.ui.status('Rendering diagram…')
289  try {
290    const diagram = await render($, title, source)
291    const list = await update($, diagrams, all => [...all, diagram].slice(-50))
292    await update($, index, () => list.length - 1)
293    await update($, showSource, () => false)
294    const opened = await openPane($, false, diagram)
295
296    return { diagram, count: list.length, isPlaced: opened.isPlaced }
297  } finally {
298    $.ui.status(undefined)
299  }
300}
301
302const renderAll = async ($: EngineInterface, found: { title: string; source: string }[]) => {
303  for (const { title, source } of found) {
304    try {
305      await addDiagram($, title, source)
306    } catch {
307      $.ui.toast(`Diagrams: could not render "${title}"`)
308    } finally {
309      pending.delete(source)
310    }
311  }
312}
313
314const responseText = (content: readonly { type: string; [field: string]: unknown }[]) =>
315  content
316    .filter(block => block.type === 'text' && typeof block.text === 'string')
317    .map(block => block.text as string)
318    .join('\n')
319
320export const register: Register = on => {
321  on('session.start', async ($, e, next) => {
322    void canDrawImages($)
323    await $.command.register({
324      name: 'diagrams',
325      description: 'Open the Mermaid diagrams pane (close it with its x; reopen any time)',
326    })
327    await $.tool.register({
328      name: 'show_diagram',
329      description:
330        'Render a Mermaid diagram and show it in the user\'s side "Diagrams" pane, which keeps ' +
331        'every diagram of the session (they page through them; /diagrams reopens it). A ' +
332        '```mermaid block in your reply is also shown there automatically, so use this tool ' +
333        'when the diagram should appear only in the pane. Pass only the Mermaid source, no ``` ' +
334        'fences. If the result reports a syntax error, fix the source and call again.',
335      inputSchema: {
336        type: 'object',
337        properties: {
338          title: { type: 'string', description: 'Short title for the diagram' },
339          mermaid: { type: 'string', description: 'Mermaid source, e.g. "flowchart LR\\n A-->B"' },
340        },
341        required: ['title', 'mermaid'],
342      },
343    })
344
345    return next(e)
346  })
347
348  on('command.run', { command: 'diagrams' }, async $ => {
349    const list = await read($, diagrams)
350    const opened = await openPane($, true, list[Math.min(await read($, index), list.length - 1)])
351    const count = list.length
352      ? `${list.length} diagram${list.length === 1 ? '' : 's'}`
353      : 'no diagrams yet'
354    const seat = opened.isPlaced ? '' : ' It is waiting for room: widen the terminal.'
355
356    return { text: `Diagrams pane opened (${count}).${seat}` }
357  })
358
359  on('session.append', { door: 'response' }, async ($, e, next) => {
360    const stored = await next(e)
361    if (e.agentId || e.message.type !== 'assistant') return stored
362
363    try {
364      const text = responseText(e.message.content)
365      if (!text.includes('```mermaid')) return stored
366
367      const known = new Set((await read($, diagrams)).map(d => d.source))
368      const fresh = extractMermaid(text).filter(d => !known.has(d.source) && !pending.has(d.source))
369      if (fresh.length) {
370        for (const d of fresh) pending.add(d.source)
371        $.clock.after(0, () => void renderAll($, fresh))
372      }
373    } catch {
374      $.ui.status(undefined)
375    }
376
377    return stored
378  })
379
380  on('tool.call', { tool: TOOL }, async ($, e) => {
381    const args = e as unknown as { title?: unknown; mermaid?: unknown }
382    const title = String(args.title ?? 'Diagram').slice(0, 120)
383    const source = cleanSource(String(args.mermaid ?? ''))
384    if (!source) return { deny: 'mermaid source is empty' }
385
386    const { diagram, count, isPlaced } = await addDiagram($, title, source)
387    const seat = isPlaced ? '' : ' The pane is waiting for room; the user can run /diagrams.'
388
389    if (diagram.error) {
390      return {
391        result: `Mermaid failed to render "${title}" (shown as source in the pane):\n${diagram.error}\nFix the syntax and call show_diagram again.`,
392      }
393    }
394
395    return {
396      result: `Rendered "${title}" in the Diagrams pane (${count} in this session). Browser view: ${diagram.htmlPath}.${seat}`,
397    }
398  }).catch(($, _e, next) => {
399    $.ui.status(undefined)
400
401    return { result: `show_diagram failed (${next.error.kind}): ${next.error.message ?? 'unknown error'}` }
402  })
403
404  on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
405    const { Box, Text, Button, Code } = $.ui.resolve(e)
406    const list = await read($, diagrams)
407    const at = Math.min(Math.max(0, await read($, index)), Math.max(0, list.length - 1))
408    const isSource = await read($, showSource)
409    const columns = e.props.bodyColumns
410    const bodyRows = e.props.scroll?.bodyRows ?? (e.viewport?.rows ?? 30) - 2
411    if (list.length === 0) {
412      return (
413        <Box flexDirection="column">
414          <Text bold>No diagrams yet</Text>
415          <Text dimColor wrap="wrap">
416            Ask Claude to draw one. Any ```mermaid block in a reply appears here automatically.
417          </Text>
418        </Box>
419      )
420    }
421
422    const current = list[at]!
423    const go = async (delta: number) => {
424      await update($, index, i => Math.min(list.length - 1, Math.max(0, i + delta)))
425    }
426
427    const isImage = e.surface === 'terminal' && !!current.pngPath && (await canDrawImages($))
428    const art =
429      e.surface === 'terminal' && !isSource && !current.error && !isImage
430        ? artOf(current, columns - MARGIN * 2)
431        : undefined
432    const isCut = !!art && 'lines' in art && art.width > columns - MARGIN * 2
433    const widen = e.props.placement === 'dock' ? 'ctrl+x ← widens the pane' : 'a wider terminal shows more'
434    const hint = e.props.isFocused ? (
435      <Text dimColor wrap="wrap">
436        n next · p prev · s source · o open in browser · c copy · Esc back to the prompt
437      </Text>
438    ) : (
439      <Text dimColor wrap="wrap">
440        Press ctrl+x tab to give this pane the keys (n next · p prev · o open in browser)
441      </Text>
442    )
443
444
445    const controls = (
446      <Box flexDirection="row" gap={1} flexWrap="wrap">
447        <Button key="prev" label="◀ prev" hotkey="p" onPress={() => go(-1)} />
448        <Button key="next" label="next ▶" hotkey="n" onPress={() => go(1)} />
449        <Button
450          key="source"
451          label={isSource ? 'diagram' : 'source'}
452          hotkey="s"
453          onPress={() => update($, showSource, v => !v)}
454        />
455        <Button
456          key="open"
457          label="open in browser"
458          hotkey="o"
459          onPress={() => void $.process.run(['open', current.htmlPath])}
460        />
461        <Button
462          key="copy"
463          label="copy"
464          hotkey="c"
465          onPress={() => void $.ui.copy({ text: current.source, surface: e.surface })}
466        />
467      </Box>
468    )
469
470    const header = (
471      <Box flexDirection="column">
472        <Text bold wrap="truncate-end">
473          {current.title}
474        </Text>
475        <Text dimColor>
476          {at + 1} / {list.length} · {new Date(current.createdAt).toLocaleTimeString()}
477        </Text>
478      </Box>
479    )
480
481    let body
482    if (current.error) {
483      body = (
484        <Box flexDirection="column">
485          <Text color="red">Render failed:</Text>
486          <Text dimColor>{current.error}</Text>
487          <Code source={current.source} language="mermaid" startLine={1} />
488        </Box>
489      )
490    } else if (isImage && !isSource) {
491      const { Image } = $.ui.resolve(e)
492      const fit = fitImage(current.width, current.height, columns, Math.max(4, bodyRows - 7))
493      body = (
494        <Image
495          key={current.id}
496          source={{ file: current.pngPath!, format: 'png' }}
497          columns={fit.columns}
498          rows={fit.rows}
499          alt={`[${current.title}] press o to open it in the browser, s for source.`}
500        />
501      )
502    } else if (art && 'lines' in art) {
503      body = (
504        <Box key={`art-${current.id}`} flexDirection="column">
505          {isCut ? (
506            <Text dimColor wrap="wrap">
507              Cut at the right edge: {widen}, or o opens it in the browser.
508            </Text>
509          ) : null}
510          <Box flexDirection="column" backgroundColor={PAPER} paddingX={MARGIN}>
511            {art.lines.map((line, i) => (
512              <Text key={`l${i}`} wrap="truncate-end" color={INK} backgroundColor={PAPER}>
513                {line.padEnd(Math.min(art.width, columns - MARGIN * 2), ' ')}
514              </Text>
515            ))}
516          </Box>
517        </Box>
518      )
519    } else {
520      body = (
521        <Box flexDirection="column">
522          {art && 'error' in art ? (
523            <Text dimColor wrap="wrap">
524              Can't draw this one as text ({art.error.split('\n')[0]}). Press o for the picture.
525            </Text>
526          ) : null}
527          <Code source={current.source} language="mermaid" startLine={1} />
528        </Box>
529      )
530    }
531
532    return (
533      <Box flexDirection="column" gap={1}>
534        {header}
535        {controls}
536        {hint}
537        {body}
538      </Box>
539    )
540  })
541}
542
hooks/vendor/beautiful-mermaid-ascii.js 40 lines
1/*
2 * beautiful-mermaid 1.1.3, ASCII/Unicode renderer only (src/ascii), bundled with esbuild.
3 * https://www.npmjs.com/package/beautiful-mermaid
4 * Its ASCII engine is based on mermaid-ascii by Alexander Grooff.
5 *
6 * MIT License
7 * 
8 * Copyright (c) 2026 Craft Docs
9 * 
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
16 * 
17 * The above copyright notice and this permission notice shall be included in all
18 * copies or substantial portions of the Software.
19 * 
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * SOFTWARE.
27 */
28function lt(t){return(t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t).replace(/<br\s*\/?>/gi,`
29`).replace(/\\n/g,`
30`).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 Se(t){let e=t.split(`
31`).map(i=>i.trim()).filter(i=>i.length>0&&!i.startsWith("%%"));if(e.length===0)throw new Error("Empty mermaid diagram");let n=e[0];return/^stateDiagram(-v2)?\s*$/i.test(n)?Fn(e):zn(e)}function zn(t){let e=t[0].match(/^(?:graph|flowchart)\s+(TD|TB|LR|BT|RL)\s*$/i);if(!e)throw new Error(`Invalid mermaid header: "${t[0]}". Expected "graph TD", "flowchart LR", "stateDiagram-v2", etc.`);let i={direction:e[1].toUpperCase(),nodes:new Map,edges:[],subgraphs:[],classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,linkStyles:new Map},s=[];for(let r=1;r<t.length;r++){let o=t[r],a=o.match(/^classDef\s+(\w+)\s+(.+)$/);if(a){let u=a[1],g=a[2],m=Vt(g);i.classDefs.set(u,m);continue}let c=o.match(/^class\s+([\w,-]+)\s+(\w+)$/);if(c){let u=c[1].split(",").map(m=>m.trim()),g=c[2];for(let m of u)i.classAssignments.set(m,g);continue}let l=o.match(/^style\s+([\w,-]+)\s+(.+)$/);if(l){let u=l[1].split(",").map(m=>m.trim()),g=Vt(l[2]);for(let m of u)i.nodeStyles.set(m,{...i.nodeStyles.get(m),...g});continue}let f=o.match(/^linkStyle\s+(default|[\d,\s]+)\s+(.+)$/);if(f){let u=f[1].trim(),g=Vt(f[2]);if(u==="default")i.linkStyles.set("default",{...i.linkStyles.get("default"),...g});else{let m=u.split(",").map(b=>parseInt(b.trim(),10));for(let b of m)isNaN(b)||i.linkStyles.set(b,{...i.linkStyles.get(b),...g})}continue}let h=o.match(/^direction\s+(TD|TB|LR|BT|RL)\s*$/i);if(h&&s.length>0){s[s.length-1].direction=h[1].toUpperCase();continue}let d=o.match(/^subgraph\s+(.+)$/);if(d){let u=d[1].trim(),g=u.match(/^([\w-]+)\s*\[(.+)\]$/),m,b;g?(m=g[1],b=lt(g[2])):(b=lt(u),m=u.replace(/\s+/g,"_").replace(/[^\w]/g,""));let A={id:m,label:b,nodeIds:[],children:[]};s.push(A);continue}if(o==="end"){let u=s.pop();u&&(s.length>0?s[s.length-1].children.push(u):i.subgraphs.push(u));continue}Qn(o,i,s)}return i}function Fn(t){let e={direction:"TD",nodes:new Map,edges:[],subgraphs:[],classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,linkStyles:new Map},n=[],i=new Set,s=0,r=0;for(let o=1;o<t.length;o++){let a=t[o],c=a.match(/^direction\s+(TD|TB|LR|BT|RL)\s*$/i);if(c){n.length>0?n[n.length-1].direction=c[1].toUpperCase():e.direction=c[1].toUpperCase();continue}let l=a.match(/^linkStyle\s+(default|[\d,\s]+)\s+(.+)$/);if(l){let g=l[1].trim(),m=Vt(l[2]);if(g==="default")e.linkStyles.set("default",{...e.linkStyles.get("default"),...m});else{let b=g.split(",").map(A=>parseInt(A.trim(),10));for(let A of b)isNaN(A)||e.linkStyles.set(A,{...e.linkStyles.get(A),...m})}continue}let f=a.match(/^state\s+(?:"([^"]+)"\s+as\s+)?([\w\p{L}]+)\s*\{$/u);if(f){let g=f[1]??f[2],m=f[2],b={id:m,label:g,nodeIds:[],children:[]};n.push(b),i.add(m),e.nodes.delete(m);continue}if(a==="}"){let g=n.pop();g&&(n.length>0?n[n.length-1].children.push(g):e.subgraphs.push(g));continue}let h=a.match(/^state\s+"([^"]+)"\s+as\s+([\w\p{L}]+)\s*$/u);if(h){let g=lt(h[1]),m=h[2];zt(e,n,{id:m,label:g,shape:"rounded"});continue}let d=a.match(/^(\[\*\]|[\w\p{L}-]+)\s*(-->)\s*(\[\*\]|[\w\p{L}-]+)(?:\s*:\s*(.+))?$/u);if(d){let g=d[1],m=d[3],b=d[4]?.trim(),A=b?lt(b):void 0;g==="[*]"?(s++,g=`_start${s>1?s:""}`,zt(e,n,{id:g,label:"",shape:"state-start"})):i.has(g)||we(e,n,g),m==="[*]"?(r++,m=`_end${r>1?r:""}`,zt(e,n,{id:m,label:"",shape:"state-end"})):i.has(m)||we(e,n,m),e.edges.push({source:g,target:m,label:A,style:"solid",hasArrowStart:!1,hasArrowEnd:!0});continue}let u=a.match(/^([\w\p{L}-]+)\s*:\s*(.+)$/u);if(u){let g=u[1],m=lt(u[2].trim());zt(e,n,{id:g,label:m,shape:"rounded"});continue}}return e}function zt(t,e,n){if(!t.nodes.has(n.id)&&t.nodes.set(n.id,n),e.length>0){let s=e[e.length-1];s.nodeIds.includes(n.id)||s.nodeIds.push(n.id)}}function we(t,e,n){if(!t.nodes.has(n))zt(t,e,{id:n,label:n,shape:"rounded"});else if(e.length>0){let i=e[e.length-1];i.nodeIds.includes(n)||i.nodeIds.push(n)}}function Vt(t){let e=t.replace(/;\s*$/,""),n={};for(let i of e.split(",")){let s=i.indexOf(":");if(s>0){let r=i.slice(0,s).trim(),o=i.slice(s+1).trim();r&&o&&(n[r]=o)}}return n}var Jn=/^(<)?(-->|-.->|==>|---|-\.-|===)(?:\|([^|]*)\|)?/,Un=/^(<)?(--|-\.|==)\s+(.+?)\s+(-->|---|\.\->|-\.\-|==>|===)/,qn=[{regex:/^([\w-]+)\(\(\((.+?)\)\)\)/,shape:"doublecircle"},{regex:/^([\w-]+)\(\[(.+?)\]\)/,shape:"stadium"},{regex:/^([\w-]+)\(\((.+?)\)\)/,shape:"circle"},{regex:/^([\w-]+)\[\[(.+?)\]\]/,shape:"subroutine"},{regex:/^([\w-]+)\[\((.+?)\)\]/,shape:"cylinder"},{regex:/^([\w-]+)\[\/(.+?)\\\]/,shape:"trapezoid"},{regex:/^([\w-]+)\[\\(.+?)\/\]/,shape:"trapezoid-alt"},{regex:/^([\w-]+)>(.+?)\]/,shape:"asymmetric"},{regex:/^([\w-]+)\{\{(.+?)\}\}/,shape:"hexagon"},{regex:/^([\w-]+)\[(.+?)\]/,shape:"rectangle"},{regex:/^([\w-]+)\((.+?)\)/,shape:"rounded"},{regex:/^([\w-]+)\{(.+?)\}/,shape:"diamond"}],Vn=/^([\w-]+)/,Kn=/^:::([\w][\w-]*)/;function Qn(t,e,n){let i=t.trim(),s=Me(i,e,n);if(!s||s.ids.length===0)return;i=s.remaining.trim();let r=s.ids;for(;i.length>0;){let o,a,c,l,f=i.match(Jn);if(f){o=!!f[1];let d=f[2],u=f[3]?.trim();l=u?lt(u):void 0,i=i.slice(f[0].length).trim(),a=tr(d),c=d.endsWith(">")}else{let d=i.match(Un);if(!d)break;o=!!d[1];let u=d[3].trim();l=u?lt(u):void 0;let g=d[2],m=d[4];i=i.slice(d[0].length).trim(),a=er(g,m),c=m.endsWith(">")}let h=Me(i,e,n);if(!h||h.ids.length===0)break;i=h.remaining.trim();for(let d of r)for(let u of h.ids)e.edges.push({source:d,target:u,label:l,style:a,hasArrowStart:o,hasArrowEnd:c});r=h.ids}}function Me(t,e,n){let i=Ae(t,e,n);if(!i)return null;let s=[i.id],r=i.remaining.trim();for(;r.startsWith("&");){r=r.slice(1).trim();let o=Ae(r,e,n);if(!o)break;s.push(o.id),r=o.remaining.trim()}return{ids:s,remaining:r}}function Ae(t,e,n){let i=null,s=t;for(let{regex:o,shape:a}of qn){let c=t.match(o);if(c){i=c[1];let l=lt(c[2]);ve(e,n,{id:i,label:l,shape:a}),s=t.slice(c[0].length);break}}if(i===null){let o=t.match(Vn);o&&(i=o[1],e.nodes.has(i)||ve(e,n,{id:i,label:i,shape:"rectangle"}),s=t.slice(o[0].length))}if(i===null)return null;let r=s.match(Kn);return r&&(e.classAssignments.set(i,r[1]),s=s.slice(r[0].length)),{id:i,remaining:s}}function ve(t,e,n){!t.nodes.has(n.id)&&t.nodes.set(n.id,n),Zn(e,n.id)}function Zn(t,e){if(t.length>0){let n=t[t.length-1];n.nodeIds.includes(e)||n.nodeIds.push(e)}}function tr(t){return t==="-.->"||t==="-.-"?"dotted":t==="==>"||t==="==="?"thick":"solid"}function er(t,e){return t==="-."||e===".->"||e==="-.-"?"dotted":t==="=="||e==="==>"||e==="==="?"thick":"solid"}var j={x:1,y:0},B={x:1,y:2},O={x:0,y:1},H={x:2,y:1},Ct={x:2,y:0},yt={x:0,y:0},Rt={x:2,y:2},wt={x:0,y:2},Et={x:1,y:1};function ae(t,e){return t.x===e.x&&t.y===e.y}function Kt(t,e){return t.x===e.x&&t.y===e.y}function Ft(t,e){return{x:t.x+e.x,y:t.y+e.y}}function kt(t){return`${t.x},${t.y}`}var Re={name:"",styles:{}};var Zt={fg:"#27272a",border:"#a1a1aa",line:"#71717a",arrow:"#52525b",corner:"#71717a",junction:"#a1a1aa"};function De(){let t=globalThis.process;if(t){if(!t.stdout?.isTTY)return"none";let e=t.env?.COLORTERM?.toLowerCase()??"",n=t.env?.TERM?.toLowerCase()??"";return e==="truecolor"||e==="24bit"?"truecolor":n.includes("256color")||n.includes("256")?"ansi256":n&&n!=="dumb"?"ansi16":"none"}return typeof document<"u"?"html":"none"}function le(t){let e=t.replace("#","");return e.length===3?{r:parseInt(e[0]+e[0],16),g:parseInt(e[1]+e[1],16),b:parseInt(e[2]+e[2],16)}:{r:parseInt(e.substring(0,2),16),g:parseInt(e.substring(2,4),16),b:parseInt(e.substring(4,6),16)}}var te="\x1B[",Qt=`${te}0m`;function Te(t){let{r:e,g:n,b:i}=le(t);return`${te}38;2;${e};${n};${i}m`}function nr(t,e,n){let i=(t+e+n)/3;if(Math.max(Math.abs(t-i),Math.abs(e-i),Math.abs(n-i))<10){let l=Math.round(i/255*23);return 232+Math.min(23,Math.max(0,l))}let r=l=>l<48?0:l<115?1:Math.min(5,Math.floor((l-35)/40)),o=r(t),a=r(e),c=r(n);return 16+36*o+6*a+c}function Le(t){let{r:e,g:n,b:i}=le(t),s=nr(e,n,i);return`${te}38;5;${s}m`}function Ee(t){let{r:e,g:n,b:i}=le(t),s=.299*e+.587*n+.114*i,r=s>100?0:60,o;return e>180&&n<100&&i<100?o=31:n>180&&e<100&&i<100?o=32:e>150&&n>150&&i<100?o=33:i>180&&e<100&&n<100?o=34:e>150&&i>150&&n<100?o=35:n>150&&i>150&&e<100?o=36:s>200?o=37:s<50?o=30:o=37,`${te}${o+r}m`}function ke(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Ie(t,e){return`<span style="color:${t}">${ke(e)}</span>`}function Ge(t,e){switch(t){case"text":return e.fg;case"border":return e.border;case"line":return e.line;case"arrow":return e.arrow;case"corner":return e.corner??e.line;case"junction":return e.junction??e.border;default:return e.fg}}function ce(t,e,n){if(n==="none")return"";let i=Ge(t,e);switch(n){case"truecolor":return Te(i);case"ansi256":return Le(i);case"ansi16":return Ee(i);default:return""}}function Ne(t,e,n,i){if(i==="none")return t.join("");if(i==="html")return rr(t,e,n);let s="",r=null,o="";for(let a=0;a<t.length;a++){let c=t[a],l=e[a]??null;if(c===" "){o.length>0&&(r!==null?s+=ce(r,n,i)+o+Qt:s+=o,o="",r=null),s+=c;continue}if(l===r){o+=c;continue}o.length>0&&(r!==null?s+=ce(r,n,i)+o+Qt:s+=o),o=c,r=l}return o.length>0&&r!==null?s+=ce(r,n,i)+o+Qt:o.length>0&&(s+=o),s}function rr(t,e,n){let i="",s=null,r="",o=()=>{r.length!==0&&(s!==null?i+=Ie(Ge(s,n),r):i+=ke(r),r="",s=null)};for(let a=0;a<t.length;a++){let c=t[a],l=e[a]??null;if(c===" "){o(),i+=" ";continue}if(l===s){r+=c;continue}o(),r=c,s=l}return o(),i}function ee(t,e,n){if(n==="none"||t.length===0)return t;if(n==="html")return Ie(e,t);let i;switch(n){case"truecolor":i=Te(e);break;case"ansi256":i=Le(e);break;case"ansi16":i=Ee(e);break;default:return t}return`${i}${t}${Qt}`}function st(t,e){let n=[];for(let i=0;i<=t;i++){let s=[];for(let r=0;r<=e;r++)s.push(" ");n.push(s)}return n}function ut(t){let[e,n]=Jt(t);return st(e,n)}function Nt(t,e){let n=[];for(let i=0;i<=t;i++){let s=[];for(let r=0;r<=e;r++)s.push(null);n.push(s)}return n}function It(t,e,n){let i=t.length-1,s=(t[0]?.length??1)-1,r=Math.max(e,i),o=Math.max(n,s),a=Nt(r,o);for(let c=0;c<a.length;c++)for(let l=0;l<a[0].length;l++)c<t.length&&l<t[0].length&&(a[c][l]=t[c][l]);return t.length=0,t.push(...a),t}function Yt(t,e,n,i){(e>=t.length||n>=(t[0]?.length??0))&&It(t,e,n),t[e][n]=i}function Jt(t){return[t.length-1,(t[0]?.length??1)-1]}function Dt(t,e,n){let[i,s]=Jt(t),r=Math.max(e,i),o=Math.max(n,s),a=st(r,o);for(let c=0;c<a.length;c++)for(let l=0;l<a[0].length;l++)c<t.length&&l<t[0].length&&(a[c][l]=t[c][l]);return t.length=0,t.push(...a),t}var or=new Set(["\u2500","\u2502","\u250C","\u2510","\u2514","\u2518","\u251C","\u2524","\u252C","\u2534","\u253C","\u2574","\u2575","\u2576","\u2577"]);function Ye(t){return or.has(t)}function $e(t){return/^[a-zA-Z0-9]$/.test(t)}var ir={"\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 sr(t,e){return ir[t]?.[e]??t}function Tt(t,e,n,...i){let[s,r]=Jt(t);for(let a of i){let[c,l]=Jt(a);s=Math.max(s,c+e.x),r=Math.max(r,l+e.y)}let o=st(s,r);for(let a=0;a<=s;a++)for(let c=0;c<=r;c++)a<t.length&&c<t[0].length&&(o[a][c]=t[a][c]);for(let a of i)for(let c=0;c<a.length;c++)for(let l=0;l<a[0].length;l++){let f=a[c][l];if(f!==" "){let h=c+e.x,d=l+e.y,u=o[h][d];!n&&Ye(f)&&Ye(u)?o[h][d]=sr(u,f):$e(u)&&$e(f)||(o[h][d]=f)}}return o}function Xt(t,e){let[n,i]=Jt(t),s=[],r=e?.roleCanvas,o=e?.colorMode??"none",a=e?.theme??Zt;for(let c=0;c<=i;c++)if(o==="none"||!r){let l="";for(let f=0;f<=n;f++)l+=t[f][c];s.push(l)}else{let l=[],f=[];for(let h=0;h<=n;h++)l.push(t[h][c]),f.push(r[h]?.[c]??null);s.push(Ne(l,f,a,o))}return s.join(`
32`)}var ar={"\u25B2":"\u25BC","\u25BC":"\u25B2","\u25E4":"\u25E3","\u25E3":"\u25E4","\u25E5":"\u25E2","\u25E2":"\u25E5","^":"v",v:"^","\u250C":"\u2514","\u2514":"\u250C","\u2510":"\u2518","\u2518":"\u2510","\u252C":"\u2534","\u2534":"\u252C","\u2575":"\u2577","\u2577":"\u2575"};function Be(t){for(let e of t)e.reverse();for(let e of t)for(let n=0;n<e.length;n++){let i=ar[e[n]];i&&(e[n]=i)}return t}function Xe(t){for(let e of t)e.reverse();return t}function fe(t,e,n,i=!1){Dt(t,e.x+n.length,e.y);for(let s=0;s<n.length;s++){let r=e.x+s,o=t[r][e.y];(i||o===" ")&&(t[r][e.y]=n[s])}}function Pe(t,e,n){let i=0,s=0;for(let r of e.values())i+=r;for(let r of n.values())s+=r;Dt(t,i-1,s-1)}function He(t,e,n){let i=0,s=0;for(let r of e.values())i+=r;for(let r of n.values())s+=r;It(t,i-1,s-1)}function We(t,e){let n=new Map,i=0;for(let[a,c]of t.nodes){let l={name:a,displayLabel:c.label,shape:c.shape,index:i,gridCoord:null,drawingCoord:null,drawing:null,drawn:!1,styleClassName:"",styleClass:Re};n.set(a,l),i++}let s=[...n.values()],r=[];for(let a of t.edges){let c=n.get(a.source),l=n.get(a.target);!c||!l||r.push({from:c,to:l,text:a.label??"",path:[],labelLine:[],startDir:{x:0,y:0},endDir:{x:0,y:0},style:a.style,hasArrowStart:a.hasArrowStart,hasArrowEnd:a.hasArrowEnd})}let o=[];for(let a of t.subgraphs)_e(a,null,n,o);cr(t.subgraphs,o,n,t);for(let[a,c]of t.classAssignments){let l=n.get(a),f=t.classDefs.get(c);l&&f&&(l.styleClassName=c,l.styleClass={name:c,styles:f})}return{nodes:s,edges:r,canvas:st(0,0),roleCanvas:Nt(0,0),grid:new Map,columnWidth:new Map,rowHeight:new Map,subgraphs:o,config:e,offsetX:0,offsetY:0,bundles:[]}}function _e(t,e,n,i){let s;t.direction&&(s=t.direction==="LR"||t.direction==="RL"?"LR":"TD");let r={name:t.label,nodes:[],parent:e,children:[],minX:0,minY:0,maxX:0,maxY:0,direction:s};for(let o of t.nodeIds){let a=n.get(o);a&&r.nodes.push(a)}i.push(r);for(let o of t.children){let a=_e(o,r,n,i);r.children.push(a);for(let c of a.nodes)r.nodes.includes(c)||r.nodes.push(c)}return r}function cr(t,e,n,i){let s=new Map;fr(t,e,s);let r=new Map;function o(a){let c=s.get(a);if(c){for(let l of a.children)o(l);for(let l of a.nodeIds)r.has(l)||r.set(l,c)}}for(let a of t)o(a);for(let a of e)a.nodes=a.nodes.filter(c=>{let l;for(let[h,d]of n)if(d===c){l=h;break}if(!l)return!1;let f=r.get(l);return f?lr(a,f):!0})}function lr(t,e){let n=e;for(;n!==null;){if(n===t)return!0;n=n.parent}return!1}function fr(t,e,n){let i=[];function s(r){for(let o of r)i.push(o),s(o.children)}s(t);for(let r=0;r<i.length&&r<e.length;r++)n.set(i[r],e[r])}var de=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],n=this.items.pop();return this.items.length>0&&(this.items[0]=n,this.sinkDown(0)),e}bubbleUp(e){for(;e>0;){let n=e-1>>1;if(this.items[e].priority<this.items[n].priority)[this.items[e],this.items[n]]=[this.items[n],this.items[e]],e=n;else break}}sinkDown(e){let n=this.items.length;for(;;){let i=e,s=2*e+1,r=2*e+2;if(s<n&&this.items[s].priority<this.items[i].priority&&(i=s),r<n&&this.items[r].priority<this.items[i].priority&&(i=r),i!==e)[this.items[e],this.items[i]]=[this.items[i],this.items[e]],e=i;else break}}};function dr(t,e){let n=Math.abs(t.x-e.x),i=Math.abs(t.y-e.y);return n===0||i===0?n+i:n+i+1}var ur=[{x:1,y:0},{x:-1,y:0},{x:0,y:1},{x:0,y:-1}];function hr(t,e){return e.x<0||e.y<0?!1:!t.has(kt(e))}function Pt(t,e,n){let i=new de;i.push({coord:e,priority:0});let s=new Map;s.set(kt(e),0);let r=new Map;for(r.set(kt(e),null);i.length>0;){let o=i.pop().coord;if(ae(o,n)){let c=[],l=o;for(;l!==null;)c.unshift(l),l=r.get(kt(l))??null;return c}let a=s.get(kt(o));for(let c of ur){let l={x:o.x+c.x,y:o.y+c.y};if(!hr(t,l)&&!ae(l,n))continue;let f=a+1,h=kt(l),d=s.get(h);if(d===void 0||f<d){s.set(h,f);let u=f+dr(l,n);i.push({coord:l,priority:u}),r.set(h,o)}}}return null}function Gt(t){if(t.length<=2)return t;let e=new Set,n=t[0],i=t[1];for(let s=2;s<t.length;s++){let r=t[s],o=i.x-n.x,a=i.y-n.y,c=r.x-i.x,l=r.y-i.y;o===c&&a===l&&e.add(s-1),n=i,i=r}return t.filter((s,r)=>!e.has(r))}function ne(t){return t===j?B:t===B?j:t===O?H:t===H?O:t===Ct?wt:t===yt?Rt:t===Rt?yt:t===wt?Ct:Et}function p(t,e){return t.x===e.x&&t.y===e.y}function mt(t,e){return t.x===e.x?t.y<e.y?B:j:t.y===e.y?t.x<e.x?H:O:t.x<e.x?t.y<e.y?Rt:Ct:t.y<e.y?wt:yt}function gr(t){return t==="LR"?[H,B,B,H]:[B,H,H,B]}function mr(t,e){if(t.from===t.to)return gr(e);let n=mt(t.from.gridCoord,t.to.gridCoord),i,s,r,o,a=e==="LR"?p(n,O)||p(n,yt)||p(n,wt):p(n,j)||p(n,yt)||p(n,Ct);return p(n,Rt)?e==="LR"?(i=B,s=O,r=H,o=j):(i=H,s=j,r=B,o=O):p(n,Ct)?e==="LR"?(i=j,s=O,r=H,o=B):(i=H,s=B,r=j,o=O):p(n,wt)?e==="LR"?(i=B,s=B,r=O,o=j):(i=O,s=j,r=B,o=H):p(n,yt)?e==="LR"?(i=B,s=B,r=O,o=B):(i=H,s=H,r=j,o=H):a?e==="LR"&&p(n,O)?(i=B,s=B,r=O,o=H):e==="TD"&&p(n,j)?(i=H,s=H,r=j,o=B):(i=n,s=ne(n),r=n,o=ne(n)):(i=n,s=ne(n),r=n,o=ne(n)),[i,s,r,o]}function je(t,e){let n=bt(t,e.from),i=bt(t,e.to),s=n&&n===i&&n.direction?n.direction:t.config.graphDirection,[r,o,a,c]=mr(e,s),l=Ft(e.from.gridCoord,r),f=Ft(e.to.gridCoord,o),h=Pt(t.grid,l,f),d=Ft(e.from.gridCoord,a),u=Ft(e.to.gridCoord,c),g=Pt(t.grid,d,u);if(h!==null&&g!==null){h=Gt(h),g=Gt(g),h.length<=g.length?(e.startDir=r,e.endDir=o,e.path=h):(e.startDir=a,e.endDir=c,e.path=g);return}if(h!==null){e.startDir=r,e.endDir=o,e.path=Gt(h);return}if(g!==null){e.startDir=a,e.endDir=c,e.path=Gt(g);return}e.startDir=r,e.endDir=o,e.path=[l,f]}function ue(t,e){if(e.text.length===0)return;let n=e.text.length,i=e.path.length,s=t.config.graphDirection==="TD",r=[];for(let d=1;d<i;d++){let u=e.path[d-1],g=e.path[d],m=[u,g],b=pr(t,m),A=u.x===g.x;r.push({line:m,width:b,index:d,isVertical:A})}let o=r.filter(d=>d.width>=n&&d.index>1),a;if(o.length>0)o.sort((d,u)=>u.index-d.index),a=o[0].line;else{let d=r.filter(u=>u.width>=n);d.length>0?(d.sort((u,g)=>g.index-u.index),a=d[0].line):(r.sort((u,g)=>g.width-u.width),a=r[0]?.line??[e.path[0],e.path[1]])}let c=Math.min(a[0].x,a[1].x),l=Math.max(a[0].x,a[1].x),f=c+Math.floor((l-c)/2),h=t.columnWidth.get(f)??0;t.columnWidth.set(f,Math.max(h,n+2)),e.labelLine=[a[0],a[1]]}function pr(t,e){let n=0,i=Math.min(e[0].x,e[1].x),s=Math.max(e[0].x,e[1].x);for(let r=i;r<=s;r++)n+=t.columnWidth.get(r)??0;return n}function ze(t){if(t.config.graphDirection!=="TD")return[];let e=[],n=new Set,i=new Map;for(let r of t.edges){if(r.from===r.to)continue;let o=i.get(r.to)??[];o.push(r),i.set(r.to,o)}for(let[r,o]of i){if(o.length<2||!Oe(o,t)||o.some(c=>n.has(c)))continue;let a={type:"fan-in",edges:[...o],sharedNode:r,otherNodes:o.map(c=>c.from),junctionPoint:null,sharedPath:[],junctionDir:Et,sharedNodeDir:Et};for(let c of o)c.bundle=a,n.add(c);e.push(a)}let s=new Map;for(let r of t.edges){if(r.from===r.to||n.has(r))continue;let o=s.get(r.from)??[];o.push(r),s.set(r.from,o)}for(let[r,o]of s){if(o.length<2||!Oe(o,t))continue;let a={type:"fan-out",edges:[...o],sharedNode:r,otherNodes:o.map(c=>c.to),junctionPoint:null,sharedPath:[],junctionDir:Et,sharedNodeDir:Et};for(let c of o)c.bundle=a,n.add(c);e.push(a)}return e}function Oe(t,e){if(t.length<2)return!1;let n=t[0].style,i=bt(e,t[0].from),s=bt(e,t[0].to);for(let r of t){if(r.style!==n||r.text.length>0)return!1;let o=bt(e,r.from),a=bt(e,r.to);if(o!==i||a!==s||o!==a)return!1}return!0}function xr(t,e){let n=t.config.graphDirection,i=e.sharedNode.gridCoord,s=e.otherNodes.map(r=>r.gridCoord);if(e.type==="fan-in"){let r=Math.min(...s.map(l=>l.x)),o=Math.max(...s.map(l=>l.x)),a=Math.min(...s.map(l=>l.y)),c=Math.max(...s.map(l=>l.y));if(n==="TD"){let l=i.y-1,f=Math.floor((r+o)/2)+1;return{x:i.x+1,y:l}}else{let l=i.x-1,f=i.y+1;return{x:l,y:f}}}else{let r=Math.min(...s.map(l=>l.x)),o=Math.max(...s.map(l=>l.x)),a=Math.min(...s.map(l=>l.y)),c=Math.max(...s.map(l=>l.y));if(n==="TD"){let l=i.y+3;return{x:i.x+1,y:l}}else{let l=i.x+3,f=i.y+1;return{x:l,y:f}}}}function br(t,e){let n=t.config.graphDirection;e.junctionPoint=xr(t,e);let i=e.junctionPoint;if(e.type==="fan-in"){e.junctionDir=n==="TD"?j:O,e.sharedNodeDir=n==="TD"?B:H;let s=e.sharedNode.gridCoord,r=n==="TD"?{x:s.x+1,y:s.y}:{x:s.x,y:s.y+1},o=Pt(t.grid,i,r);e.sharedPath=o?Gt(o):[i,r];for(let a of e.edges){let c=a.from.gridCoord,l=n==="TD"?{x:c.x+1,y:c.y+2}:{x:c.x+2,y:c.y+1},f=Pt(t.grid,l,i);a.pathToJunction=f?Gt(f):[l,i],a.startDir=n==="TD"?B:H,a.endDir=n==="TD"?j:O,a.path=[...a.pathToJunction,...e.sharedPath.slice(1)]}}else{e.junctionDir=n==="TD"?B:H,e.sharedNodeDir=n==="TD"?j:O;let s=e.sharedNode.gridCoord,r=n==="TD"?{x:s.x+1,y:s.y+2}:{x:s.x+2,y:s.y+1},o=Pt(t.grid,r,i);e.sharedPath=o?Gt(o):[r,i];for(let a of e.edges){let c=a.to.gridCoord,l=n==="TD"?{x:c.x+1,y:c.y}:{x:c.x,y:c.y+1},f=Pt(t.grid,i,l);a.pathToJunction=f?Gt(f):[i,l],a.startDir=n==="TD"?B:H,a.endDir=n==="TD"?j:O,a.path=[...e.sharedPath,...a.pathToJunction.slice(1)]}}}function Fe(t){for(let e of t.bundles)br(t,e)}function it(t){return t.split(`
33`)}function re(t){let e=it(t);return Math.max(...e.map(n=>n.length),0)}function he(t){return it(t).length}var Je={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:"/"}},"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:"@"}}};function pt(t,e){let n=Je[t]??Je.rectangle;return e?n.ascii:n.unicode}function Mt(t,e){let n=it(t),i=Math.max(...n.map(f=>f.length),0),s=n.length,r=2*e.padding+i,o=r+2,a=s+2*e.padding,c=a%2===0?a+1:a,l=c+2;return{width:o,height:l,labelArea:{x:1+e.padding,y:1+e.padding,width:i,height:s},gridColumns:[1,r,1],gridRows:[1,c,1]}}function At(t,e,n,i){let{width:s,height:r}=e,o=st(s-1,r-1),a={x:0,y:0},c={x:s-1,y:r-1},l=i?"-":"\u2500",f=i?"|":"\u2502";for(let b=a.x+1;b<c.x;b++)o[b][a.y]=l,o[b][c.y]=l;for(let b=a.y+1;b<c.y;b++)o[a.x][b]=f,o[c.x][b]=f;o[a.x][a.y]=n.tl,o[c.x][a.y]=n.tr,o[a.x][c.y]=n.bl,o[c.x][c.y]=n.br;let h=it(t),d=s-1,u=r-1,m=Math.floor(u/2)-Math.floor((h.length-1)/2);for(let b=0;b<h.length;b++){let A=h[b],$=Math.floor(d/2)-Math.ceil(A.length/2)+1;for(let v=0;v<A.length;v++){let W=$+v,T=m+b;W>=0&&W<o.length&&T>=0&&T<o[0].length&&(o[W][T]=A[v])}}return o}function gt(t,e,n){let{width:i,height:s}=e,r=n.x+Math.floor(i/2),o=n.y+Math.floor(s/2);return p(t,j)?{x:r,y:n.y}:p(t,B)?{x:r,y:n.y+s-1}:p(t,O)?{x:n.x,y:o}:p(t,H)?{x:n.x+i-1,y:o}:p(t,yt)?{x:n.x,y:n.y}:p(t,Ct)?{x:n.x+i-1,y:n.y}:p(t,wt)?{x:n.x,y:n.y+s-1}:p(t,Rt)?{x:n.x+i-1,y:n.y+s-1}:{x:r,y:o}}var ge={getDimensions:Mt,render(t,e,n){let i=pt("rectangle",n.useAscii);return At(t,e,i,n.useAscii)},getAttachmentPoint:gt};var Ue={getDimensions:Mt,render(t,e,n){let i=pt("diamond",n.useAscii);return At(t,e,i,n.useAscii)},getAttachmentPoint:gt};var qe={getDimensions:Mt,render(t,e,n){let i=pt("circle",n.useAscii);return At(t,e,i,n.useAscii)},getAttachmentPoint:gt};var Ve={getDimensions(t,e){return{width:5,height:3,labelArea:{x:2,y:1,width:1,height:1},gridColumns:[1,3,1],gridRows:[1,1,1]}},render(t,e,n){let{width:i,height:s}=e,r=st(i-1,s-1),o=Math.floor(i/2);return n.useAscii?(r[0][0]=".",r[1][0]="-",r[2][0]="-",r[3][0]="-",r[4][0]=".",r[0][1]="|",r[o][1]="*",r[4][1]="|",r[0][2]="'",r[1][2]="-",r[2][2]="-",r[3][2]="-",r[4][2]="'"):(r[0][0]="\u256D",r[1][0]="\u2500",r[2][0]="\u2500",r[3][0]="\u2500",r[4][0]="\u256E",r[0][1]="\u2502",r[o][1]="\u25CF",r[4][1]="\u2502",r[0][2]="\u2570",r[1][2]="\u2500",r[2][2]="\u2500",r[3][2]="\u2500",r[4][2]="\u256F"),r},getAttachmentPoint(t,e,n){let{width:i,height:s}=e,r=n.x+Math.floor(i/2),o=n.y+Math.floor(s/2);return p(t,j)?{x:r,y:n.y}:p(t,B)?{x:r,y:n.y+s-1}:p(t,O)?{x:n.x,y:o}:p(t,H)?{x:n.x+i-1,y:o}:{x:r,y:o}}},Ke={getDimensions(t,e){return{width:5,height:3,labelArea:{x:2,y:1,width:1,height:1},gridColumns:[1,3,1],gridRows:[1,1,1]}},render(t,e,n){let{width:i,height:s}=e,r=st(i-1,s-1),o=Math.floor(i/2);return n.useAscii?(r[0][0]="#",r[1][0]="=",r[2][0]="=",r[3][0]="=",r[4][0]="#",r[0][1]="#",r[o][1]="*",r[4][1]="#",r[0][2]="#",r[1][2]="=",r[2][2]="=",r[3][2]="=",r[4][2]="#"):(r[0][0]="\u2554",r[1][0]="\u2550",r[2][0]="\u2550",r[3][0]="\u2550",r[4][0]="\u2557",r[0][1]="\u2551",r[o][1]="\u25CE",r[4][1]="\u2551",r[0][2]="\u255A",r[1][2]="\u2550",r[2][2]="\u2550",r[3][2]="\u2550",r[4][2]="\u255D"),r},getAttachmentPoint(t,e,n){let{width:i,height:s}=e,r=n.x+Math.floor(i/2),o=n.y+Math.floor(s/2);return p(t,j)?{x:r,y:n.y}:p(t,B)?{x:r,y:n.y+s-1}:p(t,O)?{x:n.x,y:o}:p(t,H)?{x:n.x+i-1,y:o}:{x:r,y:o}}};var Qe={getDimensions:Mt,render(t,e,n){let i=pt("rounded",n.useAscii);return At(t,e,i,n.useAscii)},getAttachmentPoint:gt};var Ze={getDimensions(t,e){let n=it(t),i=Math.max(...n.map(l=>l.length),0),s=n.length,r=2*e.padding+i,o=r+4,a=s+2*e.padding,c=Math.max(a+2,3);return{width:o,height:c,labelArea:{x:2+e.padding,y:1+e.padding,width:i,height:s},gridColumns:[2,r,2],gridRows:[1,a,1]}},render(t,e,n){let{width:i,height:s}=e,r=st(i-1,s-1),o=Math.floor(s/2),a=n.useAscii?"-":"\u2500";if(s===3)r[0][o]="(",r[i-1][o]=")";else if(n.useAscii){for(let f=0;f<s;f++)r[0][f]="(",r[i-1][f]=")";for(let f=1;f<i-1;f++)r[f][0]=a,r[f][s-1]=a}else{r[0][0]="\u256D";for(let f=1;f<i-1;f++)r[f][0]=a;r[i-1][0]="\u256E";for(let f=1;f<s-1;f++)r[0][f]="\u2502",r[i-1][f]="\u2502";r[0][s-1]="\u2570";for(let f=1;f<i-1;f++)r[f][s-1]=a;r[i-1][s-1]="\u256F"}let c=it(t),l=o-Math.floor((c.length-1)/2);for(let f=0;f<c.length;f++){let h=c[f],d=Math.floor(i/2)-Math.floor(h.length/2);for(let u=0;u<h.length;u++){let g=d+u,m=l+f;g>0&&g<i-1&&m>=0&&m<s&&(r[g][m]=h[u])}}return r},getAttachmentPoint:gt};var tn={getDimensions:Mt,render(t,e,n){let i=pt("hexagon",n.useAscii);return At(t,e,i,n.useAscii)},getAttachmentPoint:gt};var en={getDimensions(t,e){let n=it(t),i=Math.max(...n.map(l=>l.length),0),s=n.length,r=2*e.padding+i,o=r+4,a=s+2*e.padding,c=a+2;return{width:o,height:c,labelArea:{x:2+e.padding,y:1+e.padding,width:i,height:s},gridColumns:[2,r,2],gridRows:[1,a,1]}},render(t,e,n){let{width:i,height:s}=e,r=st(i-1,s-1),o=n.useAscii?"-":"\u2500",a=n.useAscii?"|":"\u2502";r[0][0]=n.useAscii?"+":"\u250C",r[1][0]=n.useAscii?"+":"\u252C";for(let h=2;h<i-2;h++)r[h][0]=o;r[i-2][0]=n.useAscii?"+":"\u252C",r[i-1][0]=n.useAscii?"+":"\u2510";for(let h=1;h<s-1;h++)r[0][h]=a,r[1][h]=a,r[i-2][h]=a,r[i-1][h]=a;r[0][s-1]=n.useAscii?"+":"\u2514",r[1][s-1]=n.useAscii?"+":"\u2534";for(let h=2;h<i-2;h++)r[h][s-1]=o;r[i-2][s-1]=n.useAscii?"+":"\u2534",r[i-1][s-1]=n.useAscii?"+":"\u2518";let c=it(t),f=Math.floor(s/2)-Math.floor((c.length-1)/2);for(let h=0;h<c.length;h++){let d=c[h],u=Math.floor(i/2)-Math.floor(d.length/2);for(let g=0;g<d.length;g++){let m=u+g,b=f+h;m>1&&m<i-2&&b>0&&b<s-1&&(r[m][b]=d[g])}}return r},getAttachmentPoint:gt},nn={getDimensions:Mt,render(t,e,n){let i=pt("doublecircle",n.useAscii);return At(t,e,i,n.useAscii)},getAttachmentPoint:gt},rn={getDimensions(t,e){let n=it(t),i=Math.max(...n.map(l=>l.length),0),s=n.length,r=2*e.padding+i,o=r+2,a=s+2*e.padding+2,c=a+2;return{width:o,height:c,labelArea:{x:1+e.padding,y:2+e.padding,width:i,height:s},gridColumns:[1,r,1],gridRows:[2,a-2,2]}},render(t,e,n){let{width:i,height:s}=e,r=st(i-1,s-1),o=n.useAscii?"-":"\u2500",a=n.useAscii?"|":"\u2502";r[0][0]=n.useAscii?".":"\u256D";for(let h=1;h<i-1;h++)r[h][0]=o;r[i-1][0]=n.useAscii?".":"\u256E",r[0][1]=a;for(let h=1;h<i-1;h++)r[h][1]=o;r[i-1][1]=a;for(let h=2;h<s-2;h++)r[0][h]=a,r[i-1][h]=a;r[0][s-2]=a;for(let h=1;h<i-1;h++)r[h][s-2]=o;r[i-1][s-2]=a,r[0][s-1]=n.useAscii?"'":"\u2570";for(let h=1;h<i-1;h++)r[h][s-1]=o;r[i-1][s-1]=n.useAscii?"'":"\u256F";let c=it(t),f=Math.floor(s/2)-Math.floor((c.length-1)/2);for(let h=0;h<c.length;h++){let d=c[h],u=Math.floor(i/2)-Math.floor(d.length/2);for(let g=0;g<d.length;g++){let m=u+g,b=f+h;m>0&&m<i-1&&b>1&&b<s-2&&(r[m][b]=d[g])}}return r},getAttachmentPoint:gt},on={getDimensions:Mt,render(t,e,n){let i=pt("asymmetric",n.useAscii);return At(t,e,i,n.useAscii)},getAttachmentPoint:gt},sn={getDimensions:Mt,render(t,e,n){let i=pt("trapezoid",n.useAscii);return At(t,e,i,n.useAscii)},getAttachmentPoint:gt},an={getDimensions:Mt,render(t,e,n){let i=pt("trapezoid-alt",n.useAscii);return At(t,e,i,n.useAscii)},getAttachmentPoint:gt};var yr=new Map([["rectangle",ge],["rounded",Qe],["diamond",Ue],["stadium",Ze],["circle",qe],["subroutine",en],["doublecircle",nn],["hexagon",tn],["cylinder",rn],["asymmetric",on],["trapezoid",sn],["trapezoid-alt",an],["state-start",Ve],["state-end",Ke]]);function cn(t){return yr.get(t)??ge}function ln(t,e,n){return cn(t).getDimensions(e,n)}function fn(t,e,n,i){return cn(t).getAttachmentPoint(e,n,i)}function Cr(t,e){return wr(t,e)}function wr(t,e){let n=t.gridCoord,i=e.config.useAscii,s=0;for(let v=0;v<2;v++)s+=e.columnWidth.get(n.x+v)??0;let r=0;for(let v=0;v<2;v++)r+=e.rowHeight.get(n.y+v)??0;let o={x:0,y:0},a={x:s,y:r},c=st(Math.max(o.x,a.x),Math.max(o.y,a.y)),l=pt(t.shape,i),f=t.shape==="state-end",h=i?f?"=":"-":f?"\u2550":"\u2500",d=i?f?"\u2016":"|":f?"\u2551":"\u2502",g=f?i?{tl:"#",tr:"#",bl:"#",br:"#"}:{tl:"\u2554",tr:"\u2557",bl:"\u255A",br:"\u255D"}:l;for(let v=o.x+1;v<a.x;v++)c[v][o.y]=h;for(let v=o.x+1;v<a.x;v++)c[v][a.y]=h;for(let v=o.y+1;v<a.y;v++)c[o.x][v]=d;for(let v=o.y+1;v<a.y;v++)c[a.x][v]=d;c[o.x][o.y]=g.tl,c[a.x][o.y]=g.tr,c[o.x][a.y]=g.bl,c[a.x][a.y]=g.br;let m=t.displayLabel,b=it(m),$=o.y+Math.floor(r/2)-Math.floor((b.length-1)/2);for(let v=0;v<b.length;v++){let W=b[v],T=o.x+Math.floor(s/2)-Math.ceil(W.length/2)+1;for(let U=0;U<W.length;U++)T+U>=0&&T+U<c.length&&$+v>=0&&$+v<c[0].length&&(c[T+U][$+v]=W[U])}return c}function un(t,e){return Cr(t,e)}function oe(t,e,n=1){let i=0;for(let v of t)for(let W of v)i=Math.max(i,W.length);let r=i+2*n+2,o=0;for(let v of t)o+=Math.max(v.length,1);let a=t.length-1,c=o+a+2,l=e?"-":"\u2500",f=e?"|":"\u2502",h=e?"+":"\u250C",d=e?"+":"\u2510",u=e?"+":"\u2514",g=e?"+":"\u2518",m=e?"+":"\u251C",b=e?"+":"\u2524",A=st(r-1,c-1);A[0][0]=h;for(let v=1;v<r-1;v++)A[v][0]=l;A[r-1][0]=d,A[0][c-1]=u;for(let v=1;v<r-1;v++)A[v][c-1]=l;A[r-1][c-1]=g;for(let v=1;v<c-1;v++)A[0][v]=f,A[r-1][v]=f;let $=1;for(let v=0;v<t.length;v++){let W=t[v],T=W.length>0?W:[""];for(let U of T){let ht=1+n;for(let X=0;X<U.length;X++)A[ht+X][$]=U[X];$++}if(v<t.length-1){A[0][$]=m;for(let U=1;U<r-1;U++)A[U][$]=l;A[r-1][$]=b,$++}}return A}var Mr={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"}}};function pe(t,e,n,i,s,r,o="solid"){let a=mt(e,n),c=[],l=Mr[o],f=r?l.h.ascii:l.h.unicode,h=r?l.v.ascii:l.v.unicode;if(p(a,j))for(let d=e.y-i;d>=n.y-s;d--)c.push({x:e.x,y:d}),t[e.x][d]=h;else if(p(a,B))for(let d=e.y+i;d<=n.y+s;d++)c.push({x:e.x,y:d}),t[e.x][d]=h;else if(p(a,O))for(let d=e.x-i;d>=n.x-s;d--)c.push({x:d,y:e.y}),t[d][e.y]=f;else if(p(a,H))for(let d=e.x+i;d<=n.x+s;d++)c.push({x:d,y:e.y}),t[d][e.y]=f;else if(p(a,yt)){for(let d=e.x-i;d>=n.x;d--)c.push({x:d,y:e.y}),t[d][e.y]=f;for(let d=e.y-1;d>=n.y-s;d--)c.push({x:n.x,y:d}),t[n.x][d]=h}else if(p(a,Ct)){for(let d=e.x+i;d<=n.x;d++)c.push({x:d,y:e.y}),t[d][e.y]=f;for(let d=e.y-1;d>=n.y-s;d--)c.push({x:n.x,y:d}),t[n.x][d]=h}else if(p(a,wt)){for(let d=e.x-i;d>=n.x;d--)c.push({x:d,y:e.y}),t[d][e.y]=f;for(let d=e.y+1;d<=n.y+s;d++)c.push({x:n.x,y:d}),t[n.x][d]=h}else if(p(a,Rt))if(n.x-e.x<=1)for(let u=e.y+i;u<=n.y+s;u++)c.push({x:e.x,y:u}),t[e.x][u]=h;else{for(let u=e.x+i;u<=n.x;u++)c.push({x:u,y:e.y}),t[u][e.y]=f;for(let u=e.y+1;u<=n.y+s;u++)c.push({x:n.x,y:u}),t[n.x][u]=h}return c}function Ar(t,e){if(e.path.length===0){let f=ut(t.canvas);return[f,f,f,f,f,f]}let n=Tr(t,e),[i,s,r]=Sr(t,e.path,e.style),o=Rr(t,e.path,s[0],e.from.shape),a;e.hasArrowEnd?a=dn(t,s[s.length-1],r[r.length-1]):a=ut(t.canvas);let c;if(e.hasArrowStart&&s.length>0){let h=s[0][0],d=vr(r[0]),u={x:h.x,y:h.y};p(r[0],H)?u.x=h.x-1:p(r[0],O)?u.x=h.x+1:p(r[0],B)?u.y=h.y-1:p(r[0],j)&&(u.y=h.y+1),c=dn(t,[h,u],d)}else c=ut(t.canvas);let l=Dr(t,e.path);return[i,o,a,c,l,n]}function vr(t){return p(t,j)?B:p(t,B)?j:p(t,O)?H:p(t,H)?O:p(t,yt)?Rt:p(t,Ct)?wt:p(t,wt)?Ct:p(t,Rt)?yt:Et}function Sr(t,e,n="solid"){let i=ut(t.canvas),s=e[0],r=[],o=[];for(let a=1;a<e.length;a++){let c=e[a],l=Lt(t,s),f=Lt(t,c);if(Kt(l,f)){s=c;continue}let h=mt(s,c),d=pe(i,l,f,1,-1,t.config.useAscii,n);d.length===0&&d.push(l),r.push(d),o.push(h),s=c}return[i,r,o]}function Rr(t,e,n,i){let s=ut(t.canvas);if(t.config.useAscii||i==="state-start"||i==="state-end")return s;let r=n[0],o=mt(e[0],e[1]);return p(o,j)?s[r.x][r.y+1]="\u2534":p(o,B)?s[r.x][r.y-1]="\u252C":p(o,O)?s[r.x+1][r.y]="\u2524":p(o,H)&&(s[r.x-1][r.y]="\u251C"),s}function dn(t,e,n){let i=ut(t.canvas);if(e.length===0)return i;let s=e[0],r=e[e.length-1],o=mt(s,r);(e.length===1||p(o,Et))&&(o=n);let a;return t.config.useAscii?p(o,j)?a="^":p(o,B)?a="v":p(o,O)?a="<":p(o,H)?a=">":p(n,j)?a="^":p(n,B)?a="v":p(n,O)?a="<":p(n,H)?a=">":a="*":p(o,j)?a="\u25B2":p(o,B)?a="\u25BC":p(o,O)?a="\u25C4":p(o,H)?a="\u25BA":p(o,Ct)?a="\u25E5":p(o,yt)?a="\u25E4":p(o,Rt)?a="\u25E2":p(o,wt)?a="\u25E3":p(n,j)?a="\u25B2":p(n,B)?a="\u25BC":p(n,O)?a="\u25C4":p(n,H)?a="\u25BA":p(n,Ct)?a="\u25E5":p(n,yt)?a="\u25E4":p(n,Rt)?a="\u25E2":p(n,wt)?a="\u25E3":a="\u25CF",i[r.x][r.y]=a,i}function Dr(t,e){let n=ut(t.canvas);for(let i=1;i<e.length-1;i++){let s=e[i],r=Lt(t,s),o=mt(e[i-1],s),a=mt(s,e[i+1]),c;t.config.useAscii?c="+":p(o,H)&&p(a,B)||p(o,j)&&p(a,O)?c="\u2510":p(o,H)&&p(a,j)||p(o,B)&&p(a,O)?c="\u2518":p(o,O)&&p(a,B)||p(o,j)&&p(a,H)?c="\u250C":p(o,O)&&p(a,j)||p(o,B)&&p(a,H)?c="\u2514":c="+",n[r.x][r.y]=c}return n}function Tr(t,e){let n=ut(t.canvas);if(e.text.length===0)return n;let i=gn(t,e.labelLine),s;if(e.path.length>=2){let r=e.path[0].y,o=e.path[e.path.length-1].y;o<r?s=!0:o>r&&(s=!1)}return Lr(n,i,e.text,s),n}function Lr(t,e,n,i){if(e.length<2)return;let s=Math.min(e[0].x,e[1].x),r=Math.max(e[0].x,e[1].x),o=Math.min(e[0].y,e[1].y),a=Math.max(e[0].y,e[1].y),c=s+Math.floor((r-s)/2),l=o+Math.floor((a-o)/2);if(i!==void 0&&s===r){let d=a-o,u=Math.max(1,Math.floor(d/4));i?l=l+u:l=l-u}let f=it(n),h=l-Math.floor((f.length-1)/2);for(let d=0;d<f.length;d++){let u=f[d],g=c-Math.floor(u.length/2);fe(t,{x:g,y:h+d},u)}}function jt(t,e,n){let i=e.gridCoord,s=0;for(let c=0;c<2;c++)s+=t.columnWidth.get(i.x+c)??0;let r=0;for(let c=0;c<2;c++)r+=t.rowHeight.get(i.y+c)??0;let o={width:s+1,height:r+1,labelArea:{x:0,y:0,width:0,height:0},gridColumns:[0,0,0],gridRows:[0,0,0]},a=e.drawingCoord;return fn(e.shape,n,o,a)}function Er(t,e,n){let i=ut(t.canvas);if(!e.pathToJunction||e.pathToJunction.length===0)return[i,i,i,i,i,i];let s=ut(t.canvas),r=t.config.useAscii,o=e.pathToJunction.map((f,h)=>n.type==="fan-in"&&h===0?jt(t,e.from,e.startDir):n.type==="fan-out"&&h===e.pathToJunction.length-1?jt(t,e.to,e.endDir):Lt(t,f));for(let f=1;f<o.length;f++){let h=o[f-1],d=o[f];Kt(h,d)||pe(s,h,d,1,-1,r,e.style)}let a=ut(t.canvas);for(let f=1;f<e.pathToJunction.length-1;f++){let h=e.pathToJunction[f],d=Lt(t,h),u=mt(e.pathToJunction[f-1],h),g=mt(h,e.pathToJunction[f+1]),m;r?m="+":p(u,H)&&p(g,B)||p(u,j)&&p(g,O)?m="\u2510":p(u,H)&&p(g,j)||p(u,B)&&p(g,O)?m="\u2518":p(u,O)&&p(g,B)||p(u,j)&&p(g,H)?m="\u250C":p(u,O)&&p(g,j)||p(u,B)&&p(g,H)?m="\u2514":m="+",a[d.x][d.y]=m}let c=ut(t.canvas);if(n.type==="fan-in"&&e.pathToJunction.length>=2){let f=o[0],h=mt(e.pathToJunction[0],e.pathToJunction[1]);r||(p(h,j)?c[f.x][f.y]="\u2534":p(h,B)?c[f.x][f.y]="\u252C":p(h,O)?c[f.x][f.y]="\u2524":p(h,H)&&(c[f.x][f.y]="\u251C"))}let l=ut(t.canvas);return[s,c,i,i,a,l]}function kr(t,e){let n=ut(t.canvas),i=ut(t.canvas);if(e.sharedPath.length<2)return[n,i];let s=t.config.useAscii,r=e.edges[0]?.style??"solid",o=t.config.graphDirection,a=e.sharedPath.map((c,l)=>{if(e.type==="fan-in"&&l===e.sharedPath.length-1){let f=o==="TD"?j:O;return jt(t,e.sharedNode,f)}if(e.type==="fan-out"&&l===0){let f=o==="TD"?B:H;return jt(t,e.sharedNode,f)}return Lt(t,c)});for(let c=1;c<a.length;c++){let l=a[c-1],f=a[c];Kt(l,f)||pe(n,l,f,1,-1,s,r)}for(let c=1;c<e.sharedPath.length-1;c++){let l=e.sharedPath[c],f=Lt(t,l),h=mt(e.sharedPath[c-1],l),d=mt(l,e.sharedPath[c+1]),u;s?u="+":p(h,H)&&p(d,B)||p(h,j)&&p(d,O)?u="\u2510":p(h,H)&&p(d,j)||p(h,B)&&p(d,O)?u="\u2518":p(h,O)&&p(d,B)||p(h,j)&&p(d,H)?u="\u250C":p(h,O)&&p(d,j)||p(h,B)&&p(d,H)?u="\u2514":u="+",i[f.x][f.y]=u}return[n,i]}function Ir(t,e){let n=ut(t.canvas);if(e.sharedPath.length<2)return n;let i=e.sharedPath.length-1,s=e.sharedPath[i-1],r=e.sharedPath[i],o=mt(s,r),a=t.config.graphDirection,c=a==="TD"?j:O,l=jt(t,e.sharedNode,c);a==="TD"?l.y-=1:l.x-=1;let f;return t.config.useAscii?p(o,j)?f="^":p(o,B)?f="v":p(o,O)?f="<":p(o,H)?f=">":f="v":p(o,j)?f="\u25B2":p(o,B)?f="\u25BC":p(o,O)?f="\u25C4":p(o,H)?f="\u25BA":f="\u25BC",n[l.x][l.y]=f,n}function Gr(t,e){let n=ut(t.canvas);if(!e.pathToJunction||e.pathToJunction.length<2)return n;let i=e.pathToJunction.length-1,s=e.pathToJunction[i-1],r=e.pathToJunction[i],o=mt(s,r),a=t.config.graphDirection,c=a==="TD"?j:O,l=jt(t,e.to,c);a==="TD"?l.y-=1:l.x-=1;let f;return t.config.useAscii?p(o,j)?f="^":p(o,B)?f="v":p(o,O)?f="<":p(o,H)?f=">":f="v":p(o,j)?f="\u25B2":p(o,B)?f="\u25BC":p(o,O)?f="\u25C4":p(o,H)?f="\u25BA":f="\u25BC",n[l.x][l.y]=f,n}function Nr(t,e){let n=ut(t.canvas);if(!e.junctionPoint)return n;let i=Lt(t,e.junctionPoint),s=t.config.useAscii,r=!1,o=!1,a=!1,c=!1;if(e.sharedPath.length>=2){let f=e.type==="fan-in"?0:e.sharedPath.length-1,h=e.type==="fan-in"?1:e.sharedPath.length-2,d=mt(e.sharedPath[f],e.sharedPath[h]);p(d,B)?o=!0:p(d,j)?r=!0:p(d,H)?c=!0:p(d,O)&&(a=!0)}for(let f of e.edges)if(f.pathToJunction&&f.pathToJunction.length>=2){let h=e.type==="fan-in"?f.pathToJunction.length-1:0,d=e.type==="fan-in"?f.pathToJunction.length-2:1,u=mt(f.pathToJunction[d],f.pathToJunction[h]);p(u,B)?r=!0:p(u,j)?o=!0:p(u,H)?a=!0:p(u,O)&&(c=!0)}let l;return s?l="+":r&&o&&a&&c?l="\u253C":o&&a&&c&&!r?l="\u252C":r&&a&&c&&!o?l="\u2534":r&&o&&c&&!a?l="\u251C":r&&o&&a&&!c?l="\u2524":a&&c?l="\u2500":r&&o?l="\u2502":o&&c?l="\u250C":o&&a?l="\u2510":r&&c?l="\u2514":r&&a?l="\u2518":l="\u253C",n[i.x][i.y]=l,n}function Yr(t,e){let n=t.maxX-t.minX,i=t.maxY-t.minY;if(n<=0||i<=0)return st(0,0);let s={x:0,y:0},r={x:n,y:i},o=st(n,i);if(e.config.useAscii){for(let a=s.x+1;a<r.x;a++)o[a][s.y]="-";for(let a=s.x+1;a<r.x;a++)o[a][r.y]="-";for(let a=s.y+1;a<r.y;a++)o[s.x][a]="|";for(let a=s.y+1;a<r.y;a++)o[r.x][a]="|";o[s.x][s.y]="+",o[r.x][s.y]="+",o[s.x][r.y]="+",o[r.x][r.y]="+"}else{for(let a=s.x+1;a<r.x;a++)o[a][s.y]="\u2500";for(let a=s.x+1;a<r.x;a++)o[a][r.y]="\u2500";for(let a=s.y+1;a<r.y;a++)o[s.x][a]="\u2502";for(let a=s.y+1;a<r.y;a++)o[r.x][a]="\u2502";o[s.x][s.y]="\u250C",o[r.x][s.y]="\u2510",o[s.x][r.y]="\u2514",o[r.x][r.y]="\u2518"}return o}function $r(t,e){let n=t.maxX-t.minX,i=t.maxY-t.minY;if(n<=0||i<=0)return[st(0,0),{x:0,y:0}];let s=st(n,i),r=it(t.name);for(let o=0;o<r.length;o++){let a=r[o],c=1+o,l=Math.floor(n/2)-Math.floor(a.length/2);l<1&&(l=1);for(let f=0;f<a.length;f++)l+f<n&&c<i&&(s[l+f][c]=a[f])}return[s,{x:t.minX,y:t.minY}]}function Br(t){function e(i){return i.parent===null?0:1+e(i.parent)}let n=[...t];return n.sort((i,s)=>e(i)-e(s)),n}function me(t,e,n,i){for(let s=0;s<e.length;s++)for(let r=0;r<(e[0]?.length??0);r++){let o=e[s]?.[r];if(o&&o!==" "){let a=s+n.x,c=r+n.y;a>=0&&c>=0&&Yt(t,a,c,i)}}}function Wt(t,e,n,i){for(let s of e)me(t,s,n,i)}function Xr(t,e,n){let i=s=>/^[┌┐└┘├┤┬┴┼│─╭╮╰╯+\-|.':]$/.test(s);for(let s=0;s<e.length;s++)for(let r=0;r<(e[0]?.length??0);r++){let o=e[s]?.[r];if(o&&o!==" "){let a=s+n.x,c=r+n.y;a>=0&&c>=0&&Yt(t,a,c,i(o)?"border":"text")}}}function hn(t){let e=t.config.useAscii,n={x:0,y:0},i=Br(t.subgraphs);for(let d of i){let u=Yr(d,t),g={x:d.minX,y:d.minY};t.canvas=Tt(t.canvas,g,e,u),me(t.roleCanvas,u,g,"border")}for(let d of t.nodes)!d.drawn&&d.drawingCoord&&d.drawing&&(t.canvas=Tt(t.canvas,d.drawingCoord,e,d.drawing),Xr(t.roleCanvas,d.drawing,d.drawingCoord),d.drawn=!0);let s=[],r=[],o=[],a=[],c=[],l=[],f=[],h=new Set;for(let d of t.edges)if(d.bundle&&d.pathToJunction){let u=d.bundle,[g,m,,,b,A]=Er(t,d,u);if(s.push(g),r.push(b),c.push(m),l.push(A),!h.has(u)){h.add(u);let[$,v]=kr(t,u);if(s.push($),r.push(v),u.type==="fan-in"){let T=Ir(t,u);o.push(T)}let W=Nr(t,u);f.push(W)}if(u.type==="fan-out"&&d.hasArrowEnd){let $=Gr(t,d);o.push($)}}else{let[u,g,m,b,A,$]=Ar(t,d);s.push(u),r.push(A),o.push(m),a.push(b),c.push(g),l.push($)}t.canvas=Tt(t.canvas,n,e,...s),Wt(t.roleCanvas,s,n,"line"),t.canvas=Tt(t.canvas,n,e,...r),Wt(t.roleCanvas,r,n,"corner"),t.canvas=Tt(t.canvas,n,e,...f),Wt(t.roleCanvas,f,n,"junction"),t.canvas=Tt(t.canvas,n,e,...o),Wt(t.roleCanvas,o,n,"arrow"),t.canvas=Tt(t.canvas,n,e,...c),Wt(t.roleCanvas,c,n,"junction"),t.canvas=Tt(t.canvas,n,e,...a),Wt(t.roleCanvas,a,n,"arrow"),t.canvas=Tt(t.canvas,n,e,...l),Wt(t.roleCanvas,l,n,"text");for(let d of t.subgraphs){if(d.nodes.length===0)continue;let[u,g]=$r(d,t);t.canvas=Tt(t.canvas,g,e,u),me(t.roleCanvas,u,g,"text")}return t.canvas}function Lt(t,e,n){let i=n?{x:e.x+n.x,y:e.y+n.y}:e,s=0;for(let c=0;c<i.x;c++)s+=t.columnWidth.get(c)??0;let r=0;for(let c=0;c<i.y;c++)r+=t.rowHeight.get(c)??0;let o=t.columnWidth.get(i.x)??0,a=t.rowHeight.get(i.y)??0;return{x:s+Math.floor(o/2)+t.offsetX,y:r+Math.floor(a/2)+t.offsetY}}function gn(t,e){return e.map(n=>Lt(t,n))}function Ut(t,e,n,i){let s=i??Wr(t,e);if(t.grid.has(kt(n)))return s==="LR"?Ut(t,e,{x:n.x,y:n.y+4},s):Ut(t,e,{x:n.x+4,y:n.y},s);for(let r=0;r<3;r++)for(let o=0;o<3;o++){let a={x:n.x+r,y:n.y+o};t.grid.set(kt(a),e)}return e.gridCoord=n,n}function Pr(t,e){let n=e.gridCoord,i=t.config.boxBorderPadding,s=ln(e.shape,e.displayLabel,{useAscii:t.config.useAscii,padding:i}),r=s.gridColumns,o=s.gridRows;for(let a=0;a<r.length;a++){let c=n.x+a,l=t.columnWidth.get(c)??0;t.columnWidth.set(c,Math.max(l,r[a]))}for(let a=0;a<o.length;a++){let c=n.y+a,l=t.rowHeight.get(c)??0;t.rowHeight.set(c,Math.max(l,o[a]))}if(n.x>0){let a=t.columnWidth.get(n.x-1)??0;t.columnWidth.set(n.x-1,Math.max(a,t.config.paddingX))}if(n.y>0){let a=t.config.paddingY;_r(t,e)&&(a+=4);let c=t.rowHeight.get(n.y-1)??0;t.rowHeight.set(n.y-1,Math.max(c,a))}}function mn(t,e){for(let n of e)t.columnWidth.has(n.x)||t.columnWidth.set(n.x,Math.floor(t.config.paddingX/2)),t.rowHeight.has(n.y)||t.rowHeight.set(n.y,Math.floor(t.config.paddingY/2))}function xe(t,e){return t.subgraphs.some(n=>n.nodes.includes(e))}function bt(t,e){let n=null;for(let i of t.subgraphs)i.nodes.includes(e)&&(!n||Hr(n,i))&&(n=i);return n}function Hr(t,e){let n=e;for(;n!==null;){if(n===t)return!0;n=n.parent}return!1}function Wr(t,e){let n=bt(t,e);return n?.direction?n.direction:t.config.graphDirection}function _r(t,e){let n=bt(t,e);if(!n)return!1;let i=!1;for(let s of t.edges)if(s.to===e&&bt(t,s.from)!==n){i=!0;break}if(!i)return!1;for(let s of n.nodes){if(s===e||!s.gridCoord)continue;let r=!1;for(let o of t.edges)if(o.to===s&&bt(t,o.from)!==n){r=!0;break}if(r&&s.gridCoord.y<e.gridCoord.y)return!1}return!0}function pn(t,e){if(e.nodes.length===0)return;let n=1e6,i=1e6,s=-1e6,r=-1e6;for(let c of e.children)pn(t,c),c.nodes.length>0&&(n=Math.min(n,c.minX),i=Math.min(i,c.minY),s=Math.max(s,c.maxX),r=Math.max(r,c.maxY));for(let c of e.nodes){if(!c.drawingCoord||!c.drawing)continue;let l=c.drawingCoord.x,f=c.drawingCoord.y,h=l+c.drawing.length-1,d=f+c.drawing[0].length-1;n=Math.min(n,l),i=Math.min(i,f),s=Math.max(s,h),r=Math.max(r,d)}let o=2,a=2;e.minX=n-o,e.minY=i-o-a,e.maxX=s+o,e.maxY=r+o}function jr(t){let n=t.subgraphs.filter(i=>i.parent===null&&i.nodes.length>0);for(let i=0;i<n.length;i++)for(let s=i+1;s<n.length;s++){let r=n[i],o=n[s];r.minX<o.maxX&&r.maxX>o.minX&&(r.maxY>=o.minY-1&&r.minY<o.minY?o.minY=r.maxY+1+1:o.maxY>=r.minY-1&&o.minY<r.minY&&(r.minY=o.maxY+1+1)),r.minY<o.maxY&&r.maxY>o.minY&&(r.maxX>=o.minX-1&&r.minX<o.minX?o.minX=r.maxX+1+1:o.maxX>=r.minX-1&&o.minX<r.minX&&(r.minX=o.maxX+1+1))}}function Or(t){for(let e of t.subgraphs)pn(t,e);jr(t)}function zr(t){if(t.subgraphs.length===0)return;let e=0,n=0;for(let r of t.subgraphs)e=Math.min(e,r.minX),n=Math.min(n,r.minY);let i=-e,s=-n;if(!(i===0&&s===0)){t.offsetX=i,t.offsetY=s;for(let r of t.subgraphs)r.minX+=i,r.minY+=s,r.maxX+=i,r.maxY+=s;for(let r of t.nodes)r.drawingCoord&&(r.drawingCoord.x+=i,r.drawingCoord.y+=s)}}function xn(t){let e=t.config.graphDirection,n=new Array(100).fill(0),i=new Set,s=[];for(let d of t.nodes){i.has(d.name)||s.push(d),i.add(d.name);for(let u of be(t,d))i.add(u.name)}let r=s.filter(d=>{let u=bt(t,d);if(!u)return!0;for(let g of t.edges)if(g.to===d&&bt(t,g.from)!==u)return!1;return!0}),o=!1,a=!1;for(let d of r)xe(t,d)?be(t,d).length>0&&(a=!0):o=!0;let c=e==="LR"&&o&&a,l,f=[];c?(l=r.filter(d=>!xe(t,d)),f=r.filter(d=>xe(t,d))):l=r;for(let d of l){let u=e==="LR"?{x:0,y:n[0]}:{x:n[0],y:0};Ut(t,t.nodes[d.index],u),n[0]=n[0]+4}if(c&&f.length>0)for(let u of f){let g=e==="LR"?{x:4,y:n[4]}:{x:n[4],y:4};Ut(t,t.nodes[u.index],g),n[4]=n[4]+4}let h=l.length+f.length;for(;h<t.nodes.length;){let d=h;for(let u of t.nodes){if(u.gridCoord===null)continue;let g=u.gridCoord;for(let m of be(t,u)){if(m.gridCoord!==null)continue;let b=bt(t,u),A=bt(t,m),$=b&&b===A&&b.direction?b.direction:t.config.graphDirection,v=$==="LR"?g.x+4:g.y+4,W;$!==t.config.graphDirection?W=$==="LR"?g.y:g.x:W=n[v];let T=$==="LR"?{x:v,y:W}:{x:W,y:v};Ut(t,t.nodes[m.index],T,$),$===t.config.graphDirection&&(n[v]=W+4),h++}}if(h===d)break}for(let d of t.nodes)Pr(t,d);t.bundles=ze(t),Fe(t);for(let d of t.edges){if(d.bundle&&d.path.length>0){mn(t,d.path),ue(t,d);continue}je(t,d),mn(t,d.path),ue(t,d)}for(let d of t.nodes)d.drawingCoord=Lt(t,d.gridCoord),d.drawing=un(d,t);Pe(t.canvas,t.columnWidth,t.rowHeight),He(t.roleCanvas,t.columnWidth,t.rowHeight),Or(t),zr(t)}function Fr(t,e){return t.edges.filter(n=>n.from.name===e.name)}function be(t,e){return Fr(t,e).map(n=>n.to)}function bn(t){let e={actors:[],messages:[],blocks:[],notes:[]},n=new Set,i=[];for(let s=1;s<t.length;s++){let r=t[s],o=r.match(/^(participant|actor)\s+(\S+?)(?:\s+as\s+(.+))?$/);if(o){let d=o[1],u=o[2],g=o[3]?.trim()??u,m=lt(g);n.has(u)||(n.add(u),e.actors.push({id:u,label:m,type:d}));continue}let a=r.match(/^Note\s+(left of|right of|over)\s+([^:]+):\s*(.+)$/i);if(a){let d=a[1].toLowerCase(),u=a[2].trim(),g=lt(a[3].trim()),m=u.split(",").map(A=>A.trim());for(let A of m)qt(e,n,A);let b="over";d==="left of"?b="left":d==="right of"&&(b="right"),e.notes.push({actorIds:m,text:g,position:b,afterIndex:e.messages.length-1});continue}let c=r.match(/^(loop|alt|opt|par|critical|break|rect)\s*(.*)$/);if(c){let d=c[1],u=c[2]?.trim()??"",g=lt(u);i.push({type:d,label:g,startIndex:e.messages.length,dividers:[]});continue}let l=r.match(/^(else|and)\s*(.*)$/);if(l&&i.length>0){let d=l[2]?.trim()??"",u=lt(d);i[i.length-1].dividers.push({index:e.messages.length,label:u});continue}if(r==="end"&&i.length>0){let d=i.pop();e.blocks.push({type:d.type,label:d.label,startIndex:d.startIndex,endIndex:Math.max(e.messages.length-1,d.startIndex),dividers:d.dividers});continue}let f=r.match(/^(\S+?)\s*(--?>?>|--?[)x]|--?>>|--?>)\s*([+-]?)(\S+?)\s*:\s*(.+)$/);if(f){let d=f[1],u=f[2],g=f[3],m=f[4],b=lt(f[5].trim());qt(e,n,d),qt(e,n,m);let A=u.startsWith("--")?"dashed":"solid",$=u.includes(">>")||u.includes("x")?"filled":"open",v={from:d,to:m,label:b,lineStyle:A,arrowHead:$};g==="+"&&(v.activate=!0),g==="-"&&(v.deactivate=!0),e.messages.push(v);continue}let h=r.match(/^(\S+?)\s*(->>|-->>|-\)|--\)|-x|--x|->|-->)\s*([+-]?)(\S+?)\s*:\s*(.+)$/);if(h){let d=h[1],u=h[2],g=h[3],m=h[4],b=lt(h[5].trim());qt(e,n,d),qt(e,n,m);let A=u.startsWith("--")?"dashed":"solid",$=u.includes(">>")||u.includes("x")?"filled":"open",v={from:d,to:m,label:b,lineStyle:A,arrowHead:$};g==="+"&&(v.activate=!0),g==="-"&&(v.deactivate=!0),e.messages.push(v);continue}}return e}function qt(t,e,n){e.has(n)||(e.add(n),t.actors.push({id:n,label:n,type:"participant"}))}function yn(t,e,n,i){let s=t.split(`
34`).map(x=>x.trim()).filter(x=>x.length>0&&!x.startsWith("%%")),r=bn(s);if(r.actors.length===0)return"";let o=e.useAscii,a=o?"-":"\u2500",c=o?"|":"\u2502",l=o?"+":"\u250C",f=o?"+":"\u2510",h=o?"+":"\u2514",d=o?"+":"\u2518",u=o?"+":"\u252C",g=o?"+":"\u2534",m=o?"+":"\u251C",b=o?"+":"\u2524",A=new Map;r.actors.forEach((x,C)=>A.set(x.id,C));let $=1,W=r.actors.map(x=>re(x.label)+2*$+2).map(x=>Math.ceil(x/2)),T=r.actors.map(x=>he(x.label)+2),U=Math.max(...T,3),ht=new Array(Math.max(r.actors.length-1,0)).fill(0);for(let x of r.messages){let C=A.get(x.from),E=A.get(x.to);if(C===E)continue;let L=Math.min(C,E),Y=Math.max(C,E),R=re(x.label)+4,J=Y-L,G=Math.ceil(R/J);for(let S=L;S<Y;S++)ht[S]=Math.max(ht[S],G)}let X=[W[0]];for(let x=1;x<r.actors.length;x++){let C=Math.max(W[x-1]+W[x]+2,ht[x-1]+2,10);X[x]=X[x-1]+C}let nt=[],I=[],K=new Map,y=new Map,q=new Map,V=[],Q=U;for(let x=0;x<r.messages.length;x++){for(let Y=0;Y<r.blocks.length;Y++)r.blocks[Y].startIndex===x&&(Q+=2,K.set(Y,Q-1));for(let Y=0;Y<r.blocks.length;Y++)for(let R=0;R<r.blocks[Y].dividers.length;R++)r.blocks[Y].dividers[R].index===x&&(Q+=1,q.set(`${Y}:${R}`,Q),Q+=1);Q+=1;let C=r.messages[x],E=C.from===C.to,L=he(C.label);E?(I[x]=Q+1,nt[x]=Q,Q+=2+L):(I[x]=Q,nt[x]=Q+L,Q+=L+1);for(let Y=0;Y<r.notes.length;Y++)if(r.notes[Y].afterIndex===x){Q+=1;let R=r.notes[Y],J=it(R.text),G=Math.max(...J.map(_=>_.length))+4,S=J.length+2,F=A.get(R.actorIds[0])??0,D;if(R.position==="left")D=X[F]-G-1;else if(R.position==="right")D=X[F]+2;else if(R.actorIds.length>=2){let _=A.get(R.actorIds[1])??F;D=Math.floor((X[F]+X[_])/2)-Math.floor(G/2)}else D=X[F]-Math.floor(G/2);D=Math.max(0,D),V.push({x:D,y:Q,width:G,height:S,lines:J}),Q+=S}for(let Y=0;Y<r.blocks.length;Y++)r.blocks[Y].endIndex===x&&(Q+=1,y.set(Y,Q),Q+=1)}Q+=1;let k=Q,Z=k+U,at=X[X.length-1]??0,ct=W[W.length-1]??0,w=at+ct+2;for(let x=0;x<r.messages.length;x++){let C=r.messages[x];if(C.from===C.to){let E=A.get(C.from),L=X[E]+6+2+C.label.length;w=Math.max(w,L+1)}}for(let x of V)w=Math.max(w,x.x+x.width+1);let P=st(w,Z-1),N=Nt(w,Z-1);function M(x,C,E,L){x>=0&&x<P.length&&C>=0&&C<(P[0]?.length??0)&&(P[x][C]=E,Yt(N,x,C,L))}function z(x,C,E){let L=it(E),Y=re(E),R=Y+2*$+2,J=L.length+2,G=x-Math.floor(R/2);M(G,C,l,"border");for(let F=1;F<R-1;F++)M(G+F,C,a,"border");M(G+R-1,C,f,"border");for(let F=0;F<L.length;F++){let D=C+1+F;M(G,D,c,"border"),M(G+R-1,D,c,"border");let _=L[F],ot=G+1+$+Math.floor((Y-_.length)/2);for(let et=0;et<_.length;et++)M(ot+et,D,_[et],"text")}let S=C+J-1;M(G,S,h,"border");for(let F=1;F<R-1;F++)M(G+F,S,a,"border");M(G+R-1,S,d,"border")}for(let x=0;x<r.actors.length;x++){let C=X[x];for(let E=U;E<=k;E++)M(C,E,c,"line")}for(let x=0;x<r.actors.length;x++){let C=r.actors[x];z(X[x],0,C.label),z(X[x],k,C.label),o||(M(X[x],U-1,u,"junction"),M(X[x],k,g,"junction"))}for(let x=0;x<r.messages.length;x++){let C=r.messages[x],E=A.get(C.from),L=A.get(C.to),Y=X[E],R=X[L],J=E===L,G=C.lineStyle==="dashed",S=C.arrowHead==="filled",F=G?o?".":"\u254C":a;if(J){let D=nt[x],_=Math.max(4,4);M(Y,D,m,"junction");for(let rt=Y+1;rt<Y+_;rt++)M(rt,D,F,"line");M(Y+_,D,o?"+":"\u2510","corner"),M(Y+_,D+1,c,"line");let ot=Y+_+2;for(let rt=0;rt<C.label.length;rt++)ot+rt<w&&M(ot+rt,D+1,C.label[rt],"text");let et=S?o?"<":"\u25C0":o?"<":"\u25C1";M(Y,D+2,et,"arrow");for(let rt=Y+1;rt<Y+_;rt++)M(rt,D+2,F,"line");M(Y+_,D+2,o?"+":"\u2518","corner")}else{let D=I[x],_=nt[x],ot=Y<R,et=Math.floor((Y+R)/2),rt=it(C.label);for(let ft=0;ft<rt.length;ft++){let dt=rt[ft],vt=et-Math.floor(dt.length/2),Bt=D+ft;for(let St=0;St<dt.length;St++){let _t=vt+St;_t>=0&&_t<w&&M(_t,Bt,dt[St],"text")}}if(ot){for(let dt=Y+1;dt<R;dt++)M(dt,_,F,"line");M(R,_,S?o?">":"\u25B6":o?">":"\u25B7","arrow")}else{for(let dt=R+1;dt<Y;dt++)M(dt,_,F,"line");M(R,_,S?o?"<":"\u25C0":o?"<":"\u25C1","arrow")}}}for(let x=0;x<r.blocks.length;x++){let C=r.blocks[x],E=K.get(x),L=y.get(x);if(E===void 0||L===void 0)continue;let Y=w,R=0;for(let D=C.startIndex;D<=C.endIndex&&!(D>=r.messages.length);D++){let _=r.messages[D],ot=A.get(_.from)??0,et=A.get(_.to)??0;Y=Math.min(Y,X[Math.min(ot,et)]),R=Math.max(R,X[Math.max(ot,et)])}let J=Math.max(0,Y-4),G=Math.min(w-1,R+4);M(J,E,l,"border");for(let D=J+1;D<G;D++)M(D,E,a,"border");M(G,E,f,"border");let S=C.label?`${C.type} [${C.label}]`:C.type,F=it(S);for(let D=0;D<F.length&&E+D<L;D++){let _=F[D];for(let ot=0;ot<_.length&&J+1+ot<G;ot++)M(J+1+ot,E+D,_[ot],"text")}M(J,L,h,"border");for(let D=J+1;D<G;D++)M(D,L,a,"border");M(G,L,d,"border");for(let D=E+1;D<L;D++)M(J,D,c,"border"),M(G,D,c,"border");for(let D=0;D<C.dividers.length;D++){let _=q.get(`${x}:${D}`);if(_===void 0)continue;let ot=tt();M(J,_,m,"junction");for(let rt=J+1;rt<G;rt++)M(rt,_,ot,"line");M(G,_,b,"junction");let et=C.dividers[D].label;if(et){let rt=`[${et}]`;for(let ft=0;ft<rt.length&&J+1+ft<G;ft++)M(J+1+ft,_,rt[ft],"text")}}}for(let x of V){Dt(P,x.x+x.width,x.y+x.height),It(N,x.x+x.width,x.y+x.height),M(x.x,x.y,l,"border");for(let E=1;E<x.width-1;E++)M(x.x+E,x.y,a,"border");M(x.x+x.width-1,x.y,f,"border");for(let E=0;E<x.lines.length;E++){let L=x.y+1+E;M(x.x,L,c,"border"),M(x.x+x.width-1,L,c,"border");for(let Y=0;Y<x.lines[E].length;Y++)M(x.x+2+Y,L,x.lines[E][Y],"text")}let C=x.y+x.height-1;M(x.x,C,h,"border");for(let E=1;E<x.width-1;E++)M(x.x+E,C,a,"border");M(x.x+x.width-1,C,d,"border")}return Xt(P,{roleCanvas:N,colorMode:n,theme:i});function tt(){return o?"-":"\u254C"}}function wn(t){let e={classes:[],relationships:[],namespaces:[]},n=new Map,i=null,s=null,r=0;for(let o=1;o<t.length;o++){let a=t[o];if(s&&r>0){if(a==="}"){r--,r===0&&(s=null);continue}let g=a.match(/^<<(\w+)>>$/);if(g){s.annotation=g[1];continue}let m=Cn(a);m&&(m.isMethod?s.methods.push(m.member):s.attributes.push(m.member));continue}let c=a.match(/^namespace\s+(\S+)\s*\{$/);if(c){i={name:c[1],classIds:[]};continue}if(a==="}"&&i){e.namespaces.push(i),i=null;continue}let l=a.match(/^class\s+(\S+?)(?:\s*~(\w+)~)?\s*\{$/);if(l){let g=l[1],m=l[2],b=Ot(n,g);m&&(b.label=`${g}<${m}>`),s=b,r=1,i&&i.classIds.push(g);continue}let f=a.match(/^class\s+(\S+?)(?:\s*~(\w+)~)?\s*$/);if(f){let g=f[1],m=f[2],b=Ot(n,g);m&&(b.label=`${g}<${m}>`),i&&i.classIds.push(g);continue}let h=a.match(/^class\s+(\S+?)\s*\{\s*<<(\w+)>>\s*\}$/);if(h){let g=Ot(n,h[1]);g.annotation=h[2];continue}let d=a.match(/^(\S+?)\s*:\s*(.+)$/);if(d){let g=d[2];if(!g.match(/<\|--|--|\*--|o--|-->|\.\.>|\.\.\|>/)){let m=Ot(n,d[1]),b=Cn(g);b&&(b.isMethod?m.methods.push(b.member):m.attributes.push(b.member));continue}}let u=Jr(a);if(u){Ot(n,u.from),Ot(n,u.to),e.relationships.push(u);continue}}return e.classes=[...n.values()],e}function Ot(t,e){let n=t.get(e);return n||(n={id:e,label:e,attributes:[],methods:[]},t.set(e,n)),n}function Cn(t){let e=t.trim().replace(/;$/,"");if(!e)return null;let n="",i=e;/^[+\-#~]/.test(i)&&(n=i[0],i=i.slice(1).trim());let s=i.match(/^(.+?)\(([^)]*)\)(?:\s*(.+))?$/);if(s){let f=s[1].trim(),h=s[2]?.trim()||void 0,d=s[3]?.trim(),u=f.endsWith("$")||i.includes("$"),g=f.endsWith("*")||i.includes("*");return{member:{visibility:n,name:f.replace(/[$*]$/,""),type:d||void 0,isStatic:u,isAbstract:g,isMethod:!0,params:h},isMethod:!0}}let r=i.split(/\s+/),o,a;r.length>=2?(a=r[0],o=r.slice(1).join(" ")):o=r[0]??i;let c=o.endsWith("$"),l=o.endsWith("*");return{member:{visibility:n,name:o.replace(/[$*]$/,""),type:a||void 0,isStatic:c,isAbstract:l,isMethod:!1},isMethod:!1}}function Jr(t){let e=t.match(/^(\S+?)\s+(?:"([^"]*?)"\s+)?(<\|--|<\|\.\.|\*--|o--|-->|--\*|--o|--\|>|\.\.>|\.\.\|>|<--|<\.\.?|--)\s+(?:"([^"]*?)"\s+)?(\S+?)(?:\s*:\s*(.+))?$/);if(!e)return null;let n=e[1],i=e[2],s=i?lt(i):void 0,r=e[3].trim(),o=e[4],a=o?lt(o):void 0,c=e[5],l=e[6]?.trim(),f=l?lt(l):void 0,h=Ur(r);return h?{from:n,to:c,type:h.type,markerAt:h.markerAt,label:f,fromCardinality:s,toCardinality:a}:null}function Ur(t){switch(t.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 qr(t){return/^[┌┐└┘├┤┬┴┼│─╭╮╰╯+\-|]$/.test(t)?"border":"text"}function Mn(t){let e=t.visibility||"",n=t.type?`: ${t.type}`:"";return`${e}${t.name}${n}`}function Vr(t){let e=[];t.annotation&&e.push(`<<${t.annotation}>>`);let n=it(t.label);e.push(...n);let i=t.attributes.map(Mn),s=t.methods.map(Mn);return i.length===0&&s.length===0?[e]:s.length===0?[e,i]:[e,i,s]}function Kr(t,e){return{type:t,markerAt:e,dashed:t==="dependency"||t==="realization"}}function Ht(t,e,n){switch(t){case"inheritance":case"realization":return n==="down"?e?"^":"\u25B3":n==="up"?e?"v":"\u25BD":n==="left"?e?">":"\u25C1":e?"<":"\u25B7";case"composition":return e?"*":"\u25C6";case"aggregation":return e?"o":"\u25C7";case"association":case"dependency":return n==="down"?e?"v":"\u25BC":n==="up"?e?"^":"\u25B2":n==="left"?e?"<":"\u25C0":e?">":"\u25B6"}}function An(t,e,n,i){let s=t.split(`
35`).map(w=>w.trim()).filter(w=>w.length>0&&!w.startsWith("%%")),r=wn(s);if(r.classes.length===0)return"";let o=e.useAscii,a=4,c=3,l=new Map,f=new Map,h=new Map;for(let w of r.classes){let P=Vr(w);l.set(w.id,P);let N=0;for(let x of P)for(let C of x)N=Math.max(N,C.length);let M=N+4,z=0;for(let x of P)z+=Math.max(x.length,1);let tt=z+(P.length-1)+2;f.set(w.id,M),h.set(w.id,tt)}let d=new Map;for(let w of r.classes)d.set(w.id,w);let u=new Map,g=new Map;for(let w of r.relationships){let P=w.type==="inheritance"||w.type==="realization",N=P&&w.markerAt==="to"?w.to:w.from,M=P&&w.markerAt==="to"?w.from:w.to;u.has(M)||u.set(M,new Set),u.get(M).add(N),g.has(N)||g.set(N,new Set),g.get(N).add(M)}let m=new Map,A=r.classes.filter(w=>!u.has(w.id)||u.get(w.id).size===0).map(w=>w.id);for(let w of A)m.set(w,0);let $=r.classes.length-1,v=0;for(;v<A.length;){let w=A[v++],P=g.get(w);if(P)for(let N of P){let M=(m.get(w)??0)+1;M>$||(!m.has(N)||m.get(N)<M)&&(m.set(N,M),A.push(N))}}for(let w of r.classes)m.has(w.id)||m.set(w.id,0);let W=Math.max(...m.values(),0),T=Array.from({length:W+1},()=>[]);for(let w of r.classes)T[m.get(w.id)].push(w.id);let U=new Map,ht=0;for(let w=0;w<=W;w++){let P=T[w];if(P.length===0)continue;let N=0,M=0;for(let z of P){let tt=d.get(z),x=f.get(z),C=h.get(z);U.set(z,{cls:tt,sections:l.get(z),x:N,y:ht,width:x,height:C}),N+=x+a,M=Math.max(M,C)}ht+=M+c}let X=0,nt=0;for(let w of U.values())X=Math.max(X,w.x+w.width),nt=Math.max(nt,w.y+w.height);X+=4,nt+=2;let I=st(X-1,nt-1),K=Nt(X-1,nt-1);function y(w,P,N,M){w>=0&&w<I.length&&P>=0&&P<(I[0]?.length??0)&&(I[w][P]=N,Yt(K,w,P,M))}for(let w of U.values()){let P=oe(w.sections,o);for(let N=0;N<P.length;N++)for(let M=0;M<P[0].length;M++){let z=P[N][M];if(z!==" "){let tt=w.x+N,x=w.y+M;tt<X&&x<nt&&y(tt,x,z,qr(z))}}}let q=[];for(let w of U.values())q.push({x1:w.x,x2:w.x+w.width-1,y1:w.y,y2:w.y+w.height-1});function V(w,P,N){for(let[M,z]of U.entries())if(!N?.has(M)&&w>=z.x&&w<=z.x+z.width-1&&P>=z.y&&P<=z.y+z.height-1)return!0;return!1}function Q(w,P,N,M){let z=!0;for(let tt=Math.min(P,N);tt<=Math.max(P,N);tt++)if(V(w,tt,M)){z=!1;break}if(z)return w;for(let tt=1;tt<X+10;tt++){let x=w+tt;z=!0;for(let E=Math.min(P,N);E<=Math.max(P,N);E++)if(V(x,E,M)){z=!1;break}if(z)return x;let C=w-tt;if(C>=0){z=!0;for(let E=Math.min(P,N);E<=Math.max(P,N);E++)if(V(C,E,M)){z=!1;break}if(z)return C}}return X+2}let k=o?"-":"\u2500",Z=o?"|":"\u2502",at=o?".":"\u254C",ct=o?":":"\u250A";for(let w of r.relationships){let P=U.get(w.from),N=U.get(w.to);if(!P||!N)continue;let M=Kr(w.type,w.markerAt),z=M.dashed?at:k,tt=M.dashed?ct:Z,x=new Set([w.from,w.to]),C=P.x+Math.floor(P.width/2),E=P.y+P.height-1,L=N.x+Math.floor(N.width/2),Y=N.y;if(E<Y){let R=Q(C,E+1,Y-1,x),J=R!==C;if(R>=X&&Dt(I,R+2,nt),J){let G=E+1,S=Y-1,F=Math.min(C,R),D=Math.max(C,R);for(let _=F;_<=D;_++)y(_,G,z,"line");!o&&G<(I[0]?.length??0)&&(C<R?(y(C,G,"\u2514","corner"),y(R,G,"\u2510","corner")):(y(C,G,"\u2518","corner"),y(R,G,"\u250C","corner")));for(let _=G+1;_<=S;_++)y(R,_,tt,"line");if(R!==L){let _=Math.min(R,L),ot=Math.max(R,L);for(let et=_;et<=ot;et++)y(et,S,z,"line");!o&&S<(I[0]?.length??0)&&(R<L?(y(R,S,"\u2514","corner"),y(L,S,"\u2510","corner")):(y(R,S,"\u2518","corner"),y(L,S,"\u250C","corner")))}if(M.markerAt==="to"){let _=Ht(M.type,o,"down");y(L,S,_,"arrow")}if(M.markerAt==="from"){let _=Ht(M.type,o,"down");y(C,E+1,_,"arrow")}}else{let G=E+Math.floor((Y-E)/2);for(let S=E+1;S<=G;S++)y(C,S,tt,"line");if(C!==L&&G<(I[0]?.length??0)){let S=Math.min(C,L),F=Math.max(C,L);for(let D=S;D<=F;D++)y(D,G,z,"line");o||(y(C,G,C<L?"\u2514":"\u2518","corner"),y(L,G,C<L?"\u2510":"\u250C","corner"))}for(let S=G+1;S<Y;S++)y(L,S,tt,"line");M.markerAt==="to"&&y(L,Y-1,Ht(M.type,o,"down"),"arrow"),M.markerAt==="from"&&y(C,E+1,Ht(M.type,o,"down"),"arrow")}}else if(N.y+N.height-1<P.y){let R=P.y,J=N.y+N.height-1,G=J+Math.floor((R-J)/2);for(let S=R-1;S>=G;S--)y(C,S,tt,"line");if(C!==L){let S=Math.min(C,L),F=Math.max(C,L);for(let D=S;D<=F;D++)y(D,G,z,"line");!o&&G>=0&&G<nt&&(y(C,G,C<L?"\u250C":"\u2510","corner"),y(L,G,C<L?"\u2518":"\u2514","corner"))}for(let S=G-1;S>J;S--)y(L,S,tt,"line");if(M.markerAt==="from"){let S=Ht(M.type,o,"up"),F=R-1;for(let D=0;D<S.length;D++)y(C-Math.floor(S.length/2)+D,F,S[D],"arrow")}if(M.markerAt==="to"){let F=M.type==="inheritance"||M.type==="realization"?"down":"up",D=Ht(M.type,o,F),_=J+1;for(let ot=0;ot<D.length;ot++)y(L-Math.floor(D.length/2)+ot,_,D[ot],"arrow")}}else{let R=Math.max(E,N.y+N.height-1)+2;Dt(I,X,R+1),It(K,X,R+1);for(let S=E+1;S<=R;S++)y(C,S,tt,"line");let J=Math.min(C,L),G=Math.max(C,L);for(let S=J;S<=G;S++)y(S,R,z,"line");for(let S=R-1;S>=N.y+N.height;S--)y(L,S,tt,"line");if(M.markerAt==="from"){let S=Ht(M.type,o,"down"),F=E+1;for(let D=0;D<S.length;D++)y(C-Math.floor(S.length/2)+D,F,S[D],"arrow")}if(M.markerAt==="to"){let S=Ht(M.type,o,"up"),F=N.y+N.height;for(let D=0;D<S.length;D++)y(L-Math.floor(S.length/2)+D,F,S[D],"arrow")}}if(w.label){let R=it(w.label),J=Math.max(...R.map(et=>et.length))+2,G,S;if(E<Y)G=Math.floor((E+1+Y-1)/2),S=Math.floor((C+L)/2);else if(N.y+N.height-1<P.y){let et=N.y+N.height-1;G=Math.floor((et+1+P.y-1)/2),S=Math.floor((C+L)/2)}else G=Math.max(E,N.y+N.height-1)+2,S=Math.floor((C+L)/2);let F=G,D=Math.floor(R.length/2),_=!1;for(let et=0;et<R.length;et++){let rt=F-D+et,ft=S-Math.floor(J/2),dt=Math.max(0,ft);for(let vt=dt;vt<dt+J;vt++)if(V(vt,rt,x)){_=!0;break}if(_)break}if(_){let et=E+1,rt=Y-1;for(let ft=et;ft<=rt;ft++){let dt=!0,vt=S-Math.floor(J/2),Bt=Math.max(0,vt);for(let St=Bt;St<Bt+J;St++)if(V(St,ft,x)){dt=!1;break}if(dt){F=ft;break}}}let ot=F-D;for(let et=0;et<R.length;et++){let rt=` ${R[et]} `,ft=S-Math.floor(rt.length/2),dt=Math.max(0,ft),vt=ot+et,Bt=dt+rt.length;Bt>0&&vt>=0&&(Dt(I,Math.max(Bt,1),Math.max(vt+1,1)),It(K,Math.max(Bt,1),Math.max(vt+1,1)));for(let St=0;St<rt.length;St++){let _t=dt+St;_t>=0&&vt>=0&&y(_t,vt,rt[St],"text")}}}}return Xt(I,{roleCanvas:K,colorMode:n,theme:i})}function Sn(t){let e={entities:[],relationships:[]},n=new Map,i=null;for(let s=1;s<t.length;s++){let r=t[s];if(i){if(r==="}"){i=null;continue}let c=Qr(r);c&&i.attributes.push(c);continue}let o=r.match(/^(\S+)\s*\{$/);if(o){let c=o[1];i=ye(n,c);continue}let a=Zr(r);if(a){ye(n,a.entity1),ye(n,a.entity2),e.relationships.push(a);continue}}return e.entities=[...n.values()],e}function ye(t,e){let n=t.get(e);return n||(n={id:e,label:e,attributes:[]},t.set(e,n)),n}function Qr(t){let e=t.match(/^(\S+)\s+(\S+)(?:\s+(.+))?$/);if(!e)return null;let n=e[1],i=e[2],s=e[3]?.trim()??"",r=[],o,a=s.match(/"([^"]*)"/);a&&(o=lt(a[1]));let c=s.replace(/"[^"]*"/,"").trim();for(let l of c.split(/\s+/)){let f=l.toUpperCase();(f==="PK"||f==="FK"||f==="UK")&&r.push(f)}return{type:n,name:i,keys:r,comment:o}}function Zr(t){let e=t.match(/^(\S+)\s+([|o}{]+(?:--|\.\.)[|o}{]+)\s+(\S+)\s*:\s*(.+)$/);if(!e)return null;let n=e[1],i=e[2],s=e[3],r=e[4].trim().replace(/^["']|["']$/g,""),o=lt(r),a=i.match(/^([|o}{]+)(--|\.\.?)([|o}{]+)$/);if(!a)return null;let c=a[1],l=a[2],f=a[3],h=vn(c),d=vn(f),u=l==="--";return!h||!d?null:{entity1:n,entity2:s,cardinality1:h,cardinality2:d,label:o,identifying:u}}function vn(t){let e=t.split("").sort().join("");return e==="||"?"one":e==="o|"?"zero-one":e==="|}"||e==="{|"?"many":e==="{o"||e==="o{"?"zero-many":null}function to(t){return/^[┌┐└┘├┤┬┴┼│─╭╮╰╯+\-|]$/.test(t)?"border":"text"}function eo(t){return`${t.keys.length>0?t.keys.join(",")+" ":"   "}${t.type} ${t.name}`}function no(t){let e=it(t.label),n=t.attributes.map(eo);return n.length===0?[e]:[e,n]}function ie(t,e,n=!1){if(e)switch(t){case"one":return"|";case"zero-one":return"o|";case"many":return n?"<":">";case"zero-many":return n?"o<":">o"}else switch(t){case"one":return"\u2502";case"zero-one":return"\u25CB\u2502";case"many":return n?"\u255F":"\u2562";case"zero-many":return n?"\u25CB\u255F":"\u2562\u25CB"}}function ro(t){let e=new Set,n=[],i=new Map;for(let r of t.entities)i.set(r.id,new Set);for(let r of t.relationships)i.get(r.entity1)?.add(r.entity2),i.get(r.entity2)?.add(r.entity1);function s(r,o){let a=[r];for(;a.length>0;){let c=a.pop();if(!e.has(c)){e.add(c),o.add(c);for(let l of i.get(c)??[])e.has(l)||a.push(l)}}}for(let r of t.entities)if(!e.has(r.id)){let o=new Set;s(r.id,o),o.size>0&&n.push(o)}return n}function Rn(t,e,n,i){let s=t.split(`
36`).map(I=>I.trim()).filter(I=>I.length>0&&!I.startsWith("%%")),r=Sn(s);if(r.entities.length===0)return"";let o=e.useAscii,a=6,c=4,l=6,f=new Map,h=new Map,d=new Map,u=new Map;for(let I of r.entities){u.set(I.id,I);let K=no(I);f.set(I.id,K);let y=0;for(let k of K)for(let Z of k)y=Math.max(y,Z.length);let q=y+4,V=0;for(let k of K)V+=Math.max(k.length,1);let Q=V+(K.length-1)+2;h.set(I.id,q),d.set(I.id,Q)}let g=ro(r),m=new Map,b=0;for(let I of g){let K=r.entities.filter(Z=>I.has(Z.id)),y=Math.max(2,Math.ceil(Math.sqrt(K.length))),q=0,V=0,Q=0,k=b;for(let Z of K){let at=h.get(Z.id),ct=d.get(Z.id);Q>=y&&(b+=V+c,q=0,V=0,Q=0),m.set(Z.id,{entity:Z,sections:f.get(Z.id),x:q,y:b,width:at,height:ct}),q+=at+a,V=Math.max(V,ct),Q++}b+=V+l}let A=0,$=0;for(let I of m.values())A=Math.max(A,I.x+I.width),$=Math.max($,I.y+I.height);A+=4,$+=2;let v=st(A-1,$-1),W=Nt(A-1,$-1);function T(I,K,y,q){I>=0&&I<v.length&&K>=0&&K<(v[0]?.length??0)&&(v[I][K]=y,Yt(W,I,K,q))}for(let I of m.values()){let K=oe(I.sections,o);for(let y=0;y<K.length;y++)for(let q=0;q<K[0].length;q++){let V=K[y][q];if(V!==" "){let Q=I.x+y,k=I.y+q;Q<A&&k<$&&T(Q,k,V,to(V))}}}let U=o?"-":"\u2500",ht=o?"|":"\u2502",X=o?".":"\u254C",nt=o?":":"\u250A";for(let I of r.relationships){let K=m.get(I.entity1),y=m.get(I.entity2);if(!K||!y)continue;let q=I.identifying?U:X,V=I.identifying?ht:nt,Q=K.x+Math.floor(K.width/2),k=K.y+Math.floor(K.height/2),Z=y.x+Math.floor(y.width/2),at=y.y+Math.floor(y.height/2);if(Math.abs(k-at)<Math.max(K.height,y.height)){let[w,P]=Q<Z?[K,y]:[y,K],[N,M]=Q<Z?[I.cardinality1,I.cardinality2]:[I.cardinality2,I.cardinality1],z=w.x+w.width,tt=P.x-1,x=w.y+Math.floor(w.height/2);for(let L=z;L<=tt;L++)T(L,x,q,"line");let C=ie(N,o,!1);for(let L=0;L<C.length;L++)T(z+L,x,C[L],"arrow");let E=ie(M,o,!0);for(let L=0;L<E.length;L++)T(tt-E.length+1+L,x,E[L],"arrow");if(I.label){let L=it(I.label),Y=Math.floor((z+tt)/2);for(let R=0;R<L.length;R++){let J=L[R],G=Math.max(z,Y-Math.floor(J.length/2)),S=x+1+R;Dt(v,Math.max(G+J.length,1),Math.max(S+1,1)),It(W,Math.max(G+J.length,1),Math.max(S+1,1));for(let F=0;F<J.length;F++){let D=G+F;D>=z&&D<=tt&&T(D,S,J[F],"text")}}}}else{let[w,P]=k<at?[K,y]:[y,K],[N,M]=k<at?[I.cardinality1,I.cardinality2]:[I.cardinality2,I.cardinality1],z=w.y+w.height,tt=P.y-1,x=w.x+Math.floor(w.width/2);for(let R=z;R<=tt;R++)T(x,R,V,"line");let C=P.x+Math.floor(P.width/2);if(x!==C){let R=Math.floor((z+tt)/2),J=Math.min(x,C),G=Math.max(x,C);for(let S=J;S<=G;S++)T(S,R,q,"line");for(let S=R+1;S<=tt;S++)T(C,S,V,"line")}let E=ie(N,o,!1);for(let R=0;R<E.length;R++)T(x-Math.floor(E.length/2)+R,z,E[R],"arrow");let L=x!==C?C:x,Y=ie(M,o,!0);for(let R=0;R<Y.length;R++)T(L-Math.floor(Y.length/2)+R,tt,Y[R],"arrow");if(I.label){let R=it(I.label),G=Math.floor((z+tt)/2)-Math.floor((R.length-1)/2);for(let S=0;S<R.length;S++){let F=R[S],D=x+2,_=G+S;if(_>=0)for(let ot=0;ot<F.length;ot++){let et=D+ot;et>=0&&(Dt(v,et+1,_+1),It(W,et+1,_+1),T(et,_,F[ot],"text"))}}}}}return Xt(v,{roleCanvas:W,colorMode:n,theme:i})}function Tn(t){let e={},n={},i=[],s,r=!1;for(let o of t){if(/^xychart(-beta)?\b/i.test(o)){/\bhorizontal\b/i.test(o)&&(r=!0);continue}let a=o.match(/^title\s+"([^"]+)"/);if(a){s=a[1];continue}let c=o.match(/^x-axis\s+(?:"([^"]*)"\s*)?\[([^\]]+)\]/);if(c){c[1]&&(e.title=c[1]),e.categories=c[2].split(",").map(g=>g.trim());continue}let l=o.match(/^x-axis\s+(?:"([^"]*)"\s+)?(-?\d+(?:\.\d+)?)\s*-->\s*(-?\d+(?:\.\d+)?)/);if(l){l[1]&&(e.title=l[1]),e.range={min:parseFloat(l[2]),max:parseFloat(l[3])};continue}let f=o.match(/^y-axis\s+(?:"([^"]*)"\s+)?(-?\d+(?:\.\d+)?)\s*-->\s*(-?\d+(?:\.\d+)?)/);if(f){f[1]&&(n.title=f[1]),n.range={min:parseFloat(f[2]),max:parseFloat(f[3])};continue}let h=o.match(/^y-axis\s+"([^"]+)"\s*$/);if(h){n.title=h[1];continue}let d=o.match(/^bar\s+\[([^\]]+)\]/);if(d){i.push({type:"bar",data:Dn(d[1])});continue}let u=o.match(/^line\s+\[([^\]]+)\]/);if(u){i.push({type:"line",data:Dn(u[1])});continue}}if(!n.range&&i.length>0){let o=i.flatMap(f=>f.data),a=Math.min(...o),c=Math.max(...o),l=c-a||1;a=a-l*.1,c=c+l*.1,a>0&&a<l*.5&&(a=0),n.range={min:a,max:c}}return n.range||(n.range={min:0,max:100}),{title:s,horizontal:r,xAxis:e,yAxis:n,series:i}}function Dn(t){return t.split(",").map(e=>parseFloat(e.trim()))}var Ce="#3b82f6";function En(t){let e=t.replace("#",""),n=parseInt(e.substring(0,2),16)/255,i=parseInt(e.substring(2,4),16)/255,s=parseInt(e.substring(4,6),16)/255,r=Math.max(n,i,s),o=Math.min(n,i,s),a=(r+o)/2;if(r===o)return[0,0,a*100];let c=r-o,l=a>.5?c/(2-r-o):c/(r+o),f;return r===n?f=((i-s)/c+(i<s?6:0))/6:r===i?f=((s-n)/c+2)/6:f=((n-i)/c+4)/6,[f*360,l*100,a*100]}function oo(t,e,n){let i=e/100,s=n/100,r=(1-Math.abs(2*s-1))*i,o=r*(1-Math.abs(t/60%2-1)),a=s-r/2,c,l,f;t<60?(c=r,l=o,f=0):t<120?(c=o,l=r,f=0):t<180?(c=0,l=r,f=o):t<240?(c=0,l=o,f=r):t<300?(c=o,l=0,f=r):(c=r,l=0,f=o);let h=d=>Math.round((d+a)*255).toString(16).padStart(2,"0");return`#${h(c)}${h(l)}${h(f)}`}function Ln(t){return/^#[0-9a-fA-F]{6}$/.test(t)}function io(t){return En(t)[2]<50}function kn(t,e,n){if(t===0)return e;let i=Ln(e)?e:Ce,s=n&&Ln(n)?n:void 0,[r,o]=En(i),a=Math.max(55,Math.min(85,o)),c=Math.ceil(t/2),l=t%2===1,f=s&&io(s)?!l:l,h=f?Math.max(25,48-c*13):Math.min(78,55+c*11),d=(f?-8:12)*c,u=((r+d)%360+360)%360;return oo(u,a,h)}var In=60,Gn=20,so={hLine:"\u2500",vLine:"\u2502",origin:"\u253C",yTick:"\u2524",xTick:"\u252C",bar:"\u2588",grid:"\xB7",cornerTL:"\u256D",cornerTR:"\u256E",cornerBL:"\u2570",cornerBR:"\u256F"},ao={hLine:"-",vLine:"|",origin:"+",yTick:"+",xTick:"+",bar:"#",grid:".",cornerTL:"+",cornerTR:"+",cornerBL:"+",cornerBR:"+"};function Nn(t,e){let n=e.accent??Ce;return t<=1?[n]:Array.from({length:t},(i,s)=>kn(s,n,e.bg))}function co(t,e){switch(t){case"text":return e.fg;case"border":return e.border;case"line":return e.line;case"arrow":return e.arrow;case"corner":return e.corner??e.line;case"junction":return e.junction??e.border;default:return e.fg}}function Yn(t,e,n,i){let s=t.split(`
37`).map(a=>a.trim()).filter(a=>a.length>0&&!a.startsWith("%%")),r=Tn(s),o=e.useAscii?ao:so;return r.horizontal?fo(r,o,n,i):lo(r,o,n,i)}function lo(t,e,n,i){let s=_n(t);if(s===0)return"";let r=t.yAxis.range,o=On(r.min,r.max),a=o.map(k=>se(k)),c=Math.max(...a.map(k=>k.length))+1,l=Math.max(In,s*6),f=Gn,h=Math.floor(l/s),d=jn(t,s),u=!!t.title,g=!!t.xAxis.title,m=t.series.length>1,b=u?0:-1,A=(u?2:0)+(m?1:0),$=c+1,v=$+h*s+2,W=A+f,T=W+1,U=g?T+1:-1,ht=T+1+(g?1:0)+0,X=Bn(v,ht),nt=Xn(v,ht),I=Pn(v,ht),K=Nn(t.series.length,i),y=k=>{let Z=(k-r.min)/(r.max-r.min||1);return Math.round(Z*(f-1))},q=k=>$+Math.floor(h*(k+.5));u&&b>=0&&$t(X,nt,b,Math.floor(v/2-t.title.length/2),t.title,"text"),m&&$n(X,nt,I,t,u?1:0,v,e,K);for(let k=0;k<f;k++){let Z=A+(f-1-k);xt(X,nt,Z,$-1,e.vLine,"border")}xt(X,nt,W,$-1,e.origin,"border");for(let k of o){let Z=y(k);if(Z<0||Z>=f)continue;let at=A+(f-1-Z),ct=se(k);xt(X,nt,at,$-1,Z===0?e.origin:e.yTick,"border");let w=c-ct.length;$t(X,nt,at,Math.max(0,w),ct,"text")}for(let k=$;k<$+h*s;k++)xt(X,nt,W,k,e.hLine,"border");for(let k=0;k<s;k++){let Z=q(k);xt(X,nt,W,Z,e.xTick,"border");let at=d[k],ct=Z-Math.floor(at.length/2);$t(X,nt,T,Math.max(0,ct),at,"text")}if(g&&U>=0){let k=t.xAxis.title;$t(X,nt,U,Math.floor(v/2-k.length/2),k,"text")}for(let k of o){let Z=y(k);if(Z<0||Z>=f)continue;let at=A+(f-1-Z);for(let ct=$;ct<$+h*s;ct++)Hn(X,at,ct)===" "&&xt(X,nt,at,ct,e.grid,"line")}let V=[];for(let k=0;k<t.series.length;k++)t.series[k].type==="bar"&&V.push({data:t.series[k].data,globalIdx:k});if(V.length>0){let k=V.length,Z=Math.max(1,h-2),at=Math.max(1,Math.min(Math.floor(Z/k),8)),ct=at*k+(k-1),w=y(Math.max(0,r.min));for(let P=0;P<V.length;P++){let N=V[P],M=K[N.globalIdx];for(let z=0;z<N.data.length;z++){let C=q(z)-Math.floor(ct/2)+P*(at+1),E=y(N.data[z]),L=Math.min(w,E),Y=Math.max(w,E);for(let R=L;R<=Y;R++){let J=A+(f-1-R);for(let G=C;G<C+at;G++)xt(X,nt,J,G,e.bar,"arrow",I,M)}}}}let Q=[];for(let k=0;k<t.series.length;k++)t.series[k].type==="line"&&Q.push({data:t.series[k].data,globalIdx:k});for(let k of Q){if(k.data.length===0)continue;let Z=K[k.globalIdx];uo(X,nt,k.data,q,y,A,f,$,h*s,e,I,Z)}return Wn(X,nt,I,n,i)}function fo(t,e,n,i){let s=_n(t);if(s===0)return"";let r=t.yAxis.range,o=On(r.min,r.max),a=jn(t,s),c=Math.max(...a.map(y=>y.length))+1,l=Math.max(In,40),f=Math.max(2,Math.floor(Gn/s)),h=f*s,d=!!t.title,u=!!t.yAxis.title,g=t.series.length>1,m=(d?2:0)+(g?1:0),b=c+1,A=b+l+2,$=m+h+2+(u?1:0),v=m+h,W=Bn(A,$),T=Xn(A,$),U=Pn(A,$),ht=Nn(t.series.length,i),X=y=>{let q=(y-r.min)/(r.max-r.min||1);return b+Math.round(q*(l-1))},nt=y=>m+Math.floor(f*(y+.5));d&&$t(W,T,0,Math.floor(A/2-t.title.length/2),t.title,"text"),g&&$n(W,T,U,t,d?1:0,A,e,ht);for(let y=m;y<m+h;y++)xt(W,T,y,b-1,e.vLine,"border");xt(W,T,v,b-1,e.origin,"border");for(let y=0;y<s;y++){let q=nt(y),V=a[y],Q=c-V.length;$t(W,T,q,Math.max(0,Q),V,"text")}for(let y=b;y<b+l;y++)xt(W,T,v,y,e.hLine,"border");for(let y of o){let q=X(y);if(q<b||q>=b+l)continue;xt(W,T,v,q,e.xTick,"border");let V=se(y);$t(W,T,v+1,q-Math.floor(V.length/2),V,"text")}if(u){let y=t.yAxis.title;$t(W,T,$-1,Math.floor(A/2-y.length/2),y,"text")}for(let y of o){let q=X(y);if(!(q<b||q>=b+l))for(let V=m;V<m+h;V++)Hn(W,V,q)===" "&&xt(W,T,V,q,e.grid,"line")}let I=[];for(let y=0;y<t.series.length;y++)t.series[y].type==="bar"&&I.push({data:t.series[y].data,globalIdx:y});if(I.length>0){let y=I.length,q=1,V=q*y+(y-1),Q=X(Math.max(0,r.min));for(let k=0;k<I.length;k++){let Z=I[k],at=ht[Z.globalIdx];for(let ct=0;ct<Z.data.length;ct++){let N=nt(ct)-Math.floor(V/2)+k*(q+1),M=X(Z.data[ct]),z=Math.min(Q,M),tt=Math.max(Q,M);for(let x=N;x<N+q;x++)for(let C=z;C<=tt;C++)xt(W,T,x,C,e.bar,"arrow",U,at)}}}let K=[];for(let y=0;y<t.series.length;y++)t.series[y].type==="line"&&K.push({data:t.series[y].data,globalIdx:y});for(let y of K){if(y.data.length===0)continue;let q=ht[y.globalIdx];ho(W,T,y.data,nt,X,m,h,b,l,e,U,q)}return Wn(W,T,U,n,i)}function uo(t,e,n,i,s,r,o,a,c,l,f,h){if(n.length===0)return;let d=n.map((g,m)=>({col:i(m),row:s(g)})),u=(g,m,b)=>{let A=r+(o-1-m);A>=0&&g>=a&&g<a+c&&xt(t,e,A,g,b,"arrow",f,h)};if(d.length===1){u(d[0].col,d[0].row,l.hLine);return}for(let g=0;g<d.length-1;g++){let m=d[g],b=d[g+1];if(m.row===b.row){for(let T=m.col;T<=b.col;T++)u(T,m.row,l.hLine);continue}let A=Math.round((m.col+b.col)/2),$=b.row>m.row;for(let T=m.col;T<A;T++)u(T,m.row,l.hLine);$?u(A,m.row,l.cornerBR):u(A,m.row,l.cornerTR);let v=Math.min(m.row,b.row),W=Math.max(m.row,b.row);for(let T=v+1;T<W;T++)u(A,T,l.vLine);$?u(A,b.row,l.cornerTL):u(A,b.row,l.cornerBL);for(let T=A+1;T<=b.col;T++)u(T,b.row,l.hLine);if(g===0){let T=Math.max(a,m.col-Math.floor((b.col-m.col)/4));for(let U=T;U<m.col;U++)u(U,m.row,l.hLine)}if(g===d.length-2){let T=Math.min(a+c-1,b.col+Math.floor((b.col-m.col)/4));for(let U=b.col+1;U<=T;U++)u(U,b.row,l.hLine)}}}function ho(t,e,n,i,s,r,o,a,c,l,f,h){if(n.length===0)return;let d=n.map((g,m)=>({row:i(m),col:s(g)})),u=(g,m,b)=>{g>=r&&g<r+o&&m>=a&&m<a+c&&xt(t,e,g,m,b,"arrow",f,h)};if(d.length===1){u(d[0].row,d[0].col,l.vLine);return}for(let g=0;g<d.length-1;g++){let m=d[g],b=d[g+1];if(m.col===b.col){for(let T=m.row;T<=b.row;T++)u(T,m.col,l.vLine);continue}let A=Math.round((m.row+b.row)/2),$=b.col>m.col;for(let T=m.row;T<A;T++)u(T,m.col,l.vLine);$?u(A,m.col,l.cornerBL):u(A,m.col,l.cornerBR);let v=Math.min(m.col,b.col),W=Math.max(m.col,b.col);for(let T=v+1;T<W;T++)u(A,T,l.hLine);$?u(A,b.col,l.cornerTR):u(A,b.col,l.cornerTL);for(let T=A+1;T<=b.row;T++)u(T,b.col,l.vLine)}}function $n(t,e,n,i,s,r,o,a){let c=[],l=0,f=0;for(let g=0;g<i.series.length;g++)i.series[g].type==="bar"?(c.push({symbol:o.bar,label:`Bar ${l+1}`,globalIdx:g}),l++):(c.push({symbol:o.hLine,label:`Line ${f+1}`,globalIdx:g}),f++);let h=0;for(let g=0;g<c.length;g++)g>0&&(h+=2),h+=2+c[g].label.length;let u=Math.max(0,Math.floor(r/2-h/2));for(let g=0;g<c.length;g++){g>0&&(u+=2);let m=c[g];xt(t,e,s,u,m.symbol,"arrow",n,a[m.globalIdx]),u+=1,u+=1,$t(t,e,s,u,m.label,"text"),u+=m.label.length}}function Bn(t,e){return Array.from({length:t},()=>Array.from({length:e},()=>" "))}function Xn(t,e){return Array.from({length:t},()=>Array.from({length:e}).fill(null))}function Pn(t,e){return Array.from({length:t},()=>Array.from({length:e}).fill(null))}function xt(t,e,n,i,s,r,o,a){i>=0&&i<t.length&&n>=0&&n<t[0].length&&(t[i][n]=s,e[i][n]=r,o&&a&&(o[i][n]=a))}function Hn(t,e,n){return n>=0&&n<t.length&&e>=0&&e<t[0].length?t[n][e]:" "}function $t(t,e,n,i,s,r){for(let o=0;o<s.length;o++)xt(t,e,n,i+o,s[o],r)}function Wn(t,e,n,i,s){if(t.length===0)return"";let r=t[0].length,o=t.length,a=[];for(let c=0;c<r;c++){let l=[],f=[],h=[];for(let u=0;u<o;u++)l.push(t[u][c]),f.push(e[u][c]),h.push(n[u][c]);let d=l.length-1;for(;d>=0&&l[d]===" ";)d--;d<0?a.push(""):a.push(go(l.slice(0,d+1),f.slice(0,d+1),h.slice(0,d+1),s,i))}for(;a.length>0&&a[a.length-1]==="";)a.pop();return a.join(`
38`)}function go(t,e,n,i,s){if(s==="none")return t.join("");let r="",o=null,a="";for(let c=0;c<t.length;c++){let l=t[c];if(l===" "){a.length>0&&(r+=o?ee(a,o,s):a,a="",o=null),r+=" ";continue}let f=n[c]??null,h=e[c]??null,d=f??(h?co(h,i):null);d===o?a+=l:(a.length>0&&(r+=o?ee(a,o,s):a),a=l,o=d)}return a.length>0&&(r+=o?ee(a,o,s):a),r}function _n(t){if(t.xAxis.categories)return t.xAxis.categories.length;for(let e of t.series)if(e.data.length>0)return e.data.length;return 0}function jn(t,e){if(t.xAxis.categories)return t.xAxis.categories;if(t.xAxis.range){let{min:n,max:i}=t.xAxis.range,s=e>1?(i-n)/(e-1):0;return Array.from({length:e},(r,o)=>se(n+s*o))}return Array.from({length:e},(n,i)=>String(i+1))}function On(t,e){let n=e-t;if(n<=0)return[t];let i=n/6,s=Math.pow(10,Math.floor(Math.log10(i))),r=i/s,o;r<=1.5?o=s:r<=3?o=2*s:r<=7?o=5*s:o=10*s;let a=Math.ceil(t/o)*o,c=[];for(let l=a;l<=e+o*.001;l+=o)c.push(Math.round(l*1e10)/1e10);return c}function se(t){return Number.isInteger(t)?String(t):t.toFixed(Math.abs(t)<10?1:0)}function mo(t){let e=t.trim().split(`
39`)[0]?.trim().toLowerCase()??"";return/^xychart(-beta)?\b/.test(e)?"xychart":/^sequencediagram\s*$/.test(e)?"sequence":/^classdiagram\s*$/.test(e)?"class":/^erdiagram\s*$/.test(e)?"er":"flowchart"}function po(t,e={}){let n={useAscii:e.useAscii??!1,paddingX:e.paddingX??5,paddingY:e.paddingY??5,boxBorderPadding:e.boxBorderPadding??1,graphDirection:"TD"},i=e.colorMode==="auto"||e.colorMode===void 0?De():e.colorMode,s={...Zt,...e.theme};switch(mo(t)){case"xychart":return Yn(t,n,i,s);case"sequence":return yn(t,n,i,s);case"class":return An(t,n,i,s);case"er":return Rn(t,n,i,s);case"flowchart":default:{let o=Se(t);o.direction==="LR"||o.direction==="RL"?n.graphDirection="LR":n.graphDirection="TD";let a=We(o,n);return xn(a),hn(a),o.direction==="BT"&&(Be(a.canvas),Xe(a.roleCanvas)),Xt(a.canvas,{roleCanvas:a.roleCanvas,colorMode:i,theme:s})}}}export{po as renderMermaidASCII};
40
types/index.d.ts 22 lines
1export type Diagram = {
2  id: string
3  title: string
4  source: string
5  htmlPath: string
6  pngPath?: string
7  width?: number
8  height?: number
9  error?: string
10  createdAt: number
11}
12
13declare module 'claude-code' {
14  interface PluginState {
15    'mermaid-pane': {
16      diagrams: Diagram[]
17      index: number
18      showSource: boolean
19    }
20  }
21}
22