@oh-my-pi/pi-utils 18.2.6 → 18.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/THIRD-PARTY-NOTICES.txt +0 -37
  3. package/dist/types/mermaid-ascii.d.ts +12 -4
  4. package/package.json +2 -2
  5. package/src/logger.ts +3 -1
  6. package/src/mermaid-ascii.ts +13 -7
  7. package/src/module-timer.ts +7 -4
  8. package/dist/types/vendor/mermaid-ascii/ascii/ansi.d.ts +0 -41
  9. package/dist/types/vendor/mermaid-ascii/ascii/canvas.d.ts +0 -89
  10. package/dist/types/vendor/mermaid-ascii/ascii/class-diagram.d.ts +0 -7
  11. package/dist/types/vendor/mermaid-ascii/ascii/converter.d.ts +0 -12
  12. package/dist/types/vendor/mermaid-ascii/ascii/draw.d.ts +0 -66
  13. package/dist/types/vendor/mermaid-ascii/ascii/edge-bundling.d.ts +0 -48
  14. package/dist/types/vendor/mermaid-ascii/ascii/edge-routing.d.ts +0 -43
  15. package/dist/types/vendor/mermaid-ascii/ascii/er-diagram.d.ts +0 -7
  16. package/dist/types/vendor/mermaid-ascii/ascii/grid.d.ts +0 -56
  17. package/dist/types/vendor/mermaid-ascii/ascii/index.d.ts +0 -65
  18. package/dist/types/vendor/mermaid-ascii/ascii/multiline-utils.d.ts +0 -27
  19. package/dist/types/vendor/mermaid-ascii/ascii/pathfinder.d.ts +0 -17
  20. package/dist/types/vendor/mermaid-ascii/ascii/sequence.d.ts +0 -7
  21. package/dist/types/vendor/mermaid-ascii/ascii/shapes/circle.d.ts +0 -11
  22. package/dist/types/vendor/mermaid-ascii/ascii/shapes/corners.d.ts +0 -34
  23. package/dist/types/vendor/mermaid-ascii/ascii/shapes/diamond.d.ts +0 -11
  24. package/dist/types/vendor/mermaid-ascii/ascii/shapes/hexagon.d.ts +0 -11
  25. package/dist/types/vendor/mermaid-ascii/ascii/shapes/index.d.ts +0 -26
  26. package/dist/types/vendor/mermaid-ascii/ascii/shapes/rectangle.d.ts +0 -31
  27. package/dist/types/vendor/mermaid-ascii/ascii/shapes/rounded.d.ts +0 -11
  28. package/dist/types/vendor/mermaid-ascii/ascii/shapes/special.d.ts +0 -59
  29. package/dist/types/vendor/mermaid-ascii/ascii/shapes/stadium.d.ts +0 -17
  30. package/dist/types/vendor/mermaid-ascii/ascii/shapes/state.d.ts +0 -30
  31. package/dist/types/vendor/mermaid-ascii/ascii/shapes/types.d.ts +0 -55
  32. package/dist/types/vendor/mermaid-ascii/ascii/types.d.ts +0 -206
  33. package/dist/types/vendor/mermaid-ascii/ascii/validate.d.ts +0 -51
  34. package/dist/types/vendor/mermaid-ascii/ascii/xychart.d.ts +0 -2
  35. package/dist/types/vendor/mermaid-ascii/class/parser.d.ts +0 -6
  36. package/dist/types/vendor/mermaid-ascii/class/types.d.ts +0 -102
  37. package/dist/types/vendor/mermaid-ascii/er/parser.d.ts +0 -6
  38. package/dist/types/vendor/mermaid-ascii/er/types.d.ts +0 -76
  39. package/dist/types/vendor/mermaid-ascii/index.d.ts +0 -1
  40. package/dist/types/vendor/mermaid-ascii/multiline-utils.d.ts +0 -9
  41. package/dist/types/vendor/mermaid-ascii/parser.d.ts +0 -7
  42. package/dist/types/vendor/mermaid-ascii/sequence/parser.d.ts +0 -6
  43. package/dist/types/vendor/mermaid-ascii/sequence/types.d.ts +0 -130
  44. package/dist/types/vendor/mermaid-ascii/text-metrics.d.ts +0 -23
  45. package/dist/types/vendor/mermaid-ascii/types.d.ts +0 -114
  46. package/dist/types/vendor/mermaid-ascii/xychart/colors.d.ts +0 -25
  47. package/dist/types/vendor/mermaid-ascii/xychart/parser.d.ts +0 -6
  48. package/dist/types/vendor/mermaid-ascii/xychart/types.d.ts +0 -145
  49. package/src/vendor/mermaid-ascii/NOTICE +0 -33
  50. package/src/vendor/mermaid-ascii/ascii/ansi.ts +0 -409
  51. package/src/vendor/mermaid-ascii/ascii/canvas.ts +0 -478
  52. package/src/vendor/mermaid-ascii/ascii/class-diagram.ts +0 -699
  53. package/src/vendor/mermaid-ascii/ascii/converter.ts +0 -271
  54. package/src/vendor/mermaid-ascii/ascii/draw.ts +0 -1389
  55. package/src/vendor/mermaid-ascii/ascii/edge-bundling.ts +0 -328
  56. package/src/vendor/mermaid-ascii/ascii/edge-routing.ts +0 -297
  57. package/src/vendor/mermaid-ascii/ascii/er-diagram.ts +0 -441
  58. package/src/vendor/mermaid-ascii/ascii/grid.ts +0 -593
  59. package/src/vendor/mermaid-ascii/ascii/index.ts +0 -187
  60. package/src/vendor/mermaid-ascii/ascii/multiline-utils.ts +0 -78
  61. package/src/vendor/mermaid-ascii/ascii/pathfinder.ts +0 -277
  62. package/src/vendor/mermaid-ascii/ascii/sequence.ts +0 -460
  63. package/src/vendor/mermaid-ascii/ascii/shapes/circle.ts +0 -27
  64. package/src/vendor/mermaid-ascii/ascii/shapes/corners.ts +0 -127
  65. package/src/vendor/mermaid-ascii/ascii/shapes/diamond.ts +0 -27
  66. package/src/vendor/mermaid-ascii/ascii/shapes/hexagon.ts +0 -27
  67. package/src/vendor/mermaid-ascii/ascii/shapes/index.ts +0 -101
  68. package/src/vendor/mermaid-ascii/ascii/shapes/rectangle.ts +0 -175
  69. package/src/vendor/mermaid-ascii/ascii/shapes/rounded.ts +0 -27
  70. package/src/vendor/mermaid-ascii/ascii/shapes/special.ts +0 -296
  71. package/src/vendor/mermaid-ascii/ascii/shapes/stadium.ts +0 -114
  72. package/src/vendor/mermaid-ascii/ascii/shapes/state.ts +0 -192
  73. package/src/vendor/mermaid-ascii/ascii/shapes/types.ts +0 -73
  74. package/src/vendor/mermaid-ascii/ascii/types.ts +0 -273
  75. package/src/vendor/mermaid-ascii/ascii/validate.ts +0 -120
  76. package/src/vendor/mermaid-ascii/ascii/xychart.ts +0 -875
  77. package/src/vendor/mermaid-ascii/class/parser.ts +0 -290
  78. package/src/vendor/mermaid-ascii/class/types.ts +0 -121
  79. package/src/vendor/mermaid-ascii/er/parser.ts +0 -181
  80. package/src/vendor/mermaid-ascii/er/types.ts +0 -91
  81. package/src/vendor/mermaid-ascii/index.ts +0 -14
  82. package/src/vendor/mermaid-ascii/multiline-utils.ts +0 -30
  83. package/src/vendor/mermaid-ascii/parser.ts +0 -645
  84. package/src/vendor/mermaid-ascii/sequence/parser.ts +0 -207
  85. package/src/vendor/mermaid-ascii/sequence/types.ts +0 -146
  86. package/src/vendor/mermaid-ascii/text-metrics.ts +0 -74
  87. package/src/vendor/mermaid-ascii/types.ts +0 -164
  88. package/src/vendor/mermaid-ascii/xychart/colors.ts +0 -140
  89. package/src/vendor/mermaid-ascii/xychart/parser.ts +0 -115
  90. package/src/vendor/mermaid-ascii/xychart/types.ts +0 -150
package/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [18.2.7] - 2026-09-21
6
+
7
+ ### Changed
8
+
9
+ - Mermaid diagrams are now rendered with the native renderer, with output remaining unchanged.
10
+ - PI_TIMING span lines now include their start offset to make unspanned gaps easier to identify.
11
+
12
+ ### Fixed
13
+
14
+ - Fixed a startup crash when PI_TIMING profiled modules loaded via require() or TypeScript declaration assets.
15
+
5
16
  ## [18.2.5] - 2026-09-17
6
17
 
7
18
  ### Added
@@ -587,7 +598,7 @@
587
598
 
588
599
  ### Changed
589
600
 
590
- - Mermaid diagrams are now rendered to ASCII by a first-party vendored renderer (`src/vendor/mermaid-ascii`, derived from the MIT-licensed `beautiful-mermaid`, ASCII pipeline only) with terminal display width measured via `Bun.stringWidth` (grapheme-aware, correct for wide/East-Asian glyphs and emoji). Inline label formatting (HTML formatting tags and markdown emphasis) is now reduced to plain text instead of printed raw.
601
+ - Mermaid diagrams are now rendered to ASCII by a first-party renderer (initially derived from the MIT-licensed `beautiful-mermaid`, ASCII pipeline only) with terminal display width measured via `Bun.stringWidth` (grapheme-aware, correct for wide/East-Asian glyphs and emoji). Inline label formatting (HTML formatting tags and markdown emphasis) is now reduced to plain text instead of printed raw.
591
602
 
592
603
  ### Removed
593
604
 
@@ -335,43 +335,6 @@ This license allows the work and adaptations of it to be shared and used
335
335
  commercially, as long as it is attributed to Poppy Works. The font is bundled
336
336
  here (crates/pi-natives/src/fonts/Silver.ttf) as a CJK/Unicode bitmap fallback.
337
337
 
338
- -------------------------------------------------------------------------------
339
- packages/utils/src/vendor/mermaid-ascii/NOTICE
340
-
341
- This directory contains an in-house Mermaid-diagram-to-ASCII renderer adapted
342
- from beautiful-mermaid (https://github.com/lukilabs/beautiful-mermaid), used
343
- under the MIT License.
344
-
345
- Copyright (c) 2026 Craft Docs
346
-
347
- Only the ASCII rendering pipeline is ported (flowchart/state, sequence, class,
348
- ER, and xychart diagrams); the SVG renderer and its `elkjs` graph-layout
349
- dependency, the browser entry point, and the SVG theme/style modules were
350
- dropped. Terminal display width is reimplemented on `Bun.stringWidth`, and
351
- inline label formatting (HTML tags, markdown emphasis) is reduced to plain text
352
- for ASCII output. Layout and edge-routing logic is preserved faithfully so
353
- ASCII output matches the upstream package.
354
-
355
- MIT License
356
-
357
- Permission is hereby granted, free of charge, to any person obtaining a copy
358
- of this software and associated documentation files (the "Software"), to deal
359
- in the Software without restriction, including without limitation the rights
360
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
361
- copies of the Software, and to permit persons to whom the Software is
362
- furnished to do so, subject to the following conditions:
363
-
364
- The above copyright notice and this permission notice shall be included in all
365
- copies or substantial portions of the Software.
366
-
367
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
368
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
369
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
370
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
371
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
372
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
373
- SOFTWARE.
374
-
375
338
  -------------------------------------------------------------------------------
376
339
  packages/coding-agent/src/markit/NOTICE
377
340
 
@@ -1,7 +1,15 @@
1
- import { type AsciiRenderOptions } from "./vendor/mermaid-ascii/index.js";
2
- export type { AsciiRenderOptions as MermaidAsciiRenderOptions };
3
- export declare function renderMermaidAscii(source: string, options?: AsciiRenderOptions): string;
4
- export declare function renderMermaidAsciiSafe(source: string, options?: AsciiRenderOptions): string | null;
1
+ import { type MermaidRenderOptions, renderMermaidAscii } from "@oh-my-pi/pi-natives";
2
+ /**
3
+ * Native Mermaid → ASCII/Unicode renderer (flowchart, state, sequence, class,
4
+ * ER, xychart). Synchronous because callers render inside the compositor;
5
+ * throws on empty input, an unknown flowchart header, or an invalid
6
+ * `direction`/`colorMode` value.
7
+ */
8
+ export { renderMermaidAscii };
9
+ /** Options for {@link renderMermaidAscii}; every field optional. */
10
+ export type MermaidAsciiRenderOptions = MermaidRenderOptions;
11
+ /** {@link renderMermaidAscii}, returning `null` instead of throwing. */
12
+ export declare function renderMermaidAsciiSafe(source: string, options?: MermaidAsciiRenderOptions): string | null;
5
13
  /**
6
14
  * Extract mermaid code blocks from markdown text.
7
15
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oh-my-pi/pi-utils",
3
- "version": "18.2.6",
3
+ "version": "18.2.7",
4
4
  "description": "Shared utilities for pi packages",
5
5
  "keywords": [
6
6
  "cli",
@@ -54,7 +54,7 @@
54
54
  "fmt": "oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts'"
55
55
  },
56
56
  "dependencies": {
57
- "@oh-my-pi/pi-natives": "18.2.6"
57
+ "@oh-my-pi/pi-natives": "18.2.7"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@types/bun": "^1.3.14"
package/src/logger.ts CHANGED
@@ -644,7 +644,9 @@ function printSpan(span: Span, depth: number, lines: string[]): void {
644
644
  const tag = parallel ? " [parallel]" : "";
645
645
  const self = selfTimeOf(span);
646
646
  const selfStr = span.children.length > 0 && self > LOGGED_TIMING_THRESHOLD_MS ? ` (self ${fmtMs(self)})` : "";
647
- lines.push(`${indent}${span.op}: ${fmtMs(dur)}${selfStr}${tag}`);
647
+ // Start offset from process origin: gaps between consecutive siblings are
648
+ // the parent's own (unspanned) work, which duration alone cannot locate.
649
+ lines.push(`${indent}${span.op}: ${fmtMs(dur)}${selfStr}${tag} @${span.start.toFixed(0)}ms`);
648
650
 
649
651
  // Split children into work spans and module-load spans for summarization.
650
652
  const work: Span[] = [];
@@ -1,14 +1,20 @@
1
- import { type AsciiRenderOptions, renderMermaidASCII } from "./vendor/mermaid-ascii";
1
+ import { type MermaidRenderOptions, renderMermaidAscii } from "@oh-my-pi/pi-natives";
2
2
 
3
- export type { AsciiRenderOptions as MermaidAsciiRenderOptions };
3
+ /**
4
+ * Native Mermaid → ASCII/Unicode renderer (flowchart, state, sequence, class,
5
+ * ER, xychart). Synchronous because callers render inside the compositor;
6
+ * throws on empty input, an unknown flowchart header, or an invalid
7
+ * `direction`/`colorMode` value.
8
+ */
9
+ export { renderMermaidAscii };
4
10
 
5
- export function renderMermaidAscii(source: string, options?: AsciiRenderOptions): string {
6
- return renderMermaidASCII(source, options);
7
- }
11
+ /** Options for {@link renderMermaidAscii}; every field optional. */
12
+ export type MermaidAsciiRenderOptions = MermaidRenderOptions;
8
13
 
9
- export function renderMermaidAsciiSafe(source: string, options?: AsciiRenderOptions): string | null {
14
+ /** {@link renderMermaidAscii}, returning `null` instead of throwing. */
15
+ export function renderMermaidAsciiSafe(source: string, options?: MermaidAsciiRenderOptions): string | null {
10
16
  try {
11
- return renderMermaidASCII(source, options);
17
+ return renderMermaidAscii(source, options);
12
18
  } catch {
13
19
  return null;
14
20
  }
@@ -40,6 +40,7 @@
40
40
  * - **Dev runs only.** In the compiled `omp` binary every module is pre-bundled
41
41
  * into bunfs, so `onLoad` never fires; profile with a `bun --preload` dev run.
42
42
  */
43
+ import { readFileSync } from "node:fs";
43
44
  import { plugin } from "bun";
44
45
  import { moduleLoadBuffer } from "./timing-buffer";
45
46
 
@@ -48,8 +49,8 @@ import { moduleLoadBuffer } from "./timing-buffer";
48
49
  // `{ contents, loader: "js" }`, Bun forces ESM and CJS modules fail to load
49
50
  // (e.g. `Missing 'default' export`). Our own source tree (where the interesting
50
51
  // timing lives) is uniformly TypeScript, so a TS-only filter is both safe and
51
- // sufficient.
52
- const MODULE_LOADER_FILTER = /\.[mc]?tsx?$/;
52
+ // sufficient. Declaration files are imported as text assets, never evaluated.
53
+ const MODULE_LOADER_FILTER = /^(?!.*\.d\.[mc]?ts$).*\.[mc]?tsx?$/;
53
54
  const MODULE_COMPLETE_KEY: symbol = Symbol.for("omp.moduleLoadComplete");
54
55
  const MODULE_BODY_START_KEY: symbol = Symbol.for("omp.moduleBodyStart");
55
56
  const STATIC_IMPORT_PATTERN =
@@ -133,10 +134,12 @@ if (process.env.PI_TIMING) {
133
134
  plugin({
134
135
  name: "pi-module-load-timer",
135
136
  setup(build) {
136
- build.onLoad({ filter: MODULE_LOADER_FILTER }, async args => {
137
+ // Synchronous on purpose: a module served by an async onLoad cannot be
138
+ // `require()`d (cli.ts requires postmortem through Bun's CJS bridge).
139
+ build.onLoad({ filter: MODULE_LOADER_FILTER }, args => {
137
140
  starts.set(args.path, performance.now());
138
141
  childSetFor(importsByPath, args.path);
139
- const contents = await Bun.file(args.path).text();
142
+ const contents = readFileSync(args.path, "utf8");
140
143
  addImportEdges(importsByPath, args.path, contents);
141
144
  return {
142
145
  contents: instrumentContents(args.path, contents),
@@ -1,41 +0,0 @@
1
- import type { CharRole, AsciiTheme, ColorMode } from './types.js';
2
- /**
3
- * Default ASCII theme derived from the SVG renderer's color palette.
4
- * Uses the same mixing ratios to maintain visual consistency.
5
- */
6
- export declare const DEFAULT_ASCII_THEME: AsciiTheme;
7
- /**
8
- * Detect the best color mode for the current environment.
9
- *
10
- * Terminal detection order:
11
- * 1. COLORTERM=truecolor or COLORTERM=24bit → truecolor
12
- * 2. TERM contains "256color" → ansi256
13
- * 3. TERM is set and not "dumb" → ansi16
14
- *
15
- * Browser: returns 'html' (uses <span> tags with inline styles).
16
- * Unknown/piped: returns 'none'.
17
- */
18
- export declare function detectColorMode(): ColorMode;
19
- /**
20
- * Generate the ANSI escape sequence for a role color.
21
- */
22
- export declare function getAnsiColor(role: CharRole, theme: AsciiTheme, mode: ColorMode): string;
23
- /**
24
- * Get the ANSI reset sequence.
25
- */
26
- export declare function getAnsiReset(mode: ColorMode): string;
27
- /**
28
- * Wrap a character with ANSI color codes based on its role.
29
- */
30
- export declare function colorizeChar(char: string, role: CharRole | null, theme: AsciiTheme, mode: ColorMode): string;
31
- /**
32
- * Colorize an entire line efficiently by grouping consecutive same-role characters.
33
- * This reduces the number of escape sequences (ANSI) or span tags (HTML) in the output.
34
- */
35
- export declare function colorizeLine(chars: string[], roles: (CharRole | null)[], theme: AsciiTheme, mode: ColorMode): string;
36
- /**
37
- * Colorize a text string with a direct hex color.
38
- * Used by renderers that need per-cell color control (e.g. multi-series xychart).
39
- * Handles all output modes: ANSI (16/256/truecolor) and HTML.
40
- */
41
- export declare function colorizeText(text: string, hex: string, mode: ColorMode): string;
@@ -1,89 +0,0 @@
1
- import type { Canvas, DrawingCoord, RoleCanvas, CharRole, AsciiTheme, ColorMode } from './types.js';
2
- /**
3
- * Create a blank canvas filled with spaces.
4
- * Dimensions are inclusive: mkCanvas(3, 2) creates a 4x3 grid (indices 0..3, 0..2).
5
- */
6
- export declare function mkCanvas(x: number, y: number): Canvas;
7
- /** Create a blank canvas with the same dimensions as the given canvas. */
8
- export declare function copyCanvas(source: Canvas): Canvas;
9
- /**
10
- * Create a blank role canvas filled with nulls.
11
- * Same dimensions as mkCanvas — column-major, roleCanvas[x][y].
12
- */
13
- export declare function mkRoleCanvas(x: number, y: number): RoleCanvas;
14
- /** Create a blank role canvas with the same dimensions as the given role canvas. */
15
- export declare function copyRoleCanvas(source: RoleCanvas): RoleCanvas;
16
- /**
17
- * Grow the role canvas to fit at least (newX, newY), preserving existing roles.
18
- * Mutates the role canvas in place and returns it.
19
- */
20
- export declare function increaseRoleCanvasSize(roleCanvas: RoleCanvas, newX: number, newY: number): RoleCanvas;
21
- /**
22
- * Set a role at a specific coordinate.
23
- * Expands the role canvas if necessary.
24
- */
25
- export declare function setRole(roleCanvas: RoleCanvas, x: number, y: number, role: CharRole): void;
26
- /**
27
- * Merge role canvases — same logic as mergeCanvases but for roles.
28
- * Non-null roles in overlays overwrite null roles in base.
29
- */
30
- export declare function mergeRoleCanvases(base: RoleCanvas, offset: DrawingCoord, ...overlays: RoleCanvas[]): RoleCanvas;
31
- /** Returns [maxX, maxY] — the highest valid indices in each dimension. */
32
- export declare function getCanvasSize(canvas: Canvas): [number, number];
33
- /**
34
- * Grow the canvas to fit at least (newX, newY), preserving existing content.
35
- * Mutates the canvas in place and returns it.
36
- */
37
- export declare function increaseSize(canvas: Canvas, newX: number, newY: number): Canvas;
38
- export declare function isJunctionChar(c: string): boolean;
39
- export declare function mergeJunctions(c1: string, c2: string): string;
40
- /**
41
- * Merge overlay canvases onto a base canvas at the given offset.
42
- * Non-space characters in overlays overwrite the base.
43
- * When both characters are Unicode junction chars, they're merged intelligently.
44
- */
45
- export declare function mergeCanvases(base: Canvas, offset: DrawingCoord, useAscii: boolean, ...overlays: Canvas[]): Canvas;
46
- /** Options for converting canvas to string with optional coloring. */
47
- export interface CanvasToStringOptions {
48
- /** Role canvas for applying colors. If not provided, output is plain text. */
49
- roleCanvas?: RoleCanvas;
50
- /** Color mode for terminal output. Default: 'none' */
51
- colorMode?: ColorMode;
52
- /** Theme colors for ASCII output. Uses default theme if not provided. */
53
- theme?: AsciiTheme;
54
- }
55
- /**
56
- * Convert the canvas to a multi-line string (row by row, left to right).
57
- * Optionally applies ANSI color codes based on character roles.
58
- */
59
- export declare function canvasToString(canvas: Canvas, options?: CanvasToStringOptions): string;
60
- /**
61
- * Flip the canvas vertically (mirror across the horizontal center).
62
- * Reverses row order within each column and remaps directional characters
63
- * (arrows, corners, junctions) so they point the correct way after flip.
64
- *
65
- * Used to transform a TD-rendered canvas into BT output.
66
- * Mutates the canvas in place and returns it.
67
- */
68
- export declare function flipCanvasVertically(canvas: Canvas): Canvas;
69
- /**
70
- * Flip the role canvas vertically to match flipCanvasVertically.
71
- * Mutates the role canvas in place and returns it.
72
- */
73
- export declare function flipRoleCanvasVertically(roleCanvas: RoleCanvas): RoleCanvas;
74
- /**
75
- * Draw text string onto the canvas starting at the given coordinate.
76
- * By default, preserves existing non-space characters (labels don't overwrite each other).
77
- * Set forceOverwrite=true to always overwrite (for box content).
78
- */
79
- export declare function drawText(canvas: Canvas, start: DrawingCoord, text: string, forceOverwrite?: boolean): void;
80
- /**
81
- * Set the canvas size to fit all grid columns and rows.
82
- * Called after layout to ensure the canvas covers the full drawing area.
83
- */
84
- export declare function setCanvasSizeToGrid(canvas: Canvas, columnWidth: Map<number, number>, rowHeight: Map<number, number>): void;
85
- /**
86
- * Set the role canvas size to match the grid dimensions.
87
- * Should be called alongside setCanvasSizeToGrid.
88
- */
89
- export declare function setRoleCanvasSizeToGrid(roleCanvas: RoleCanvas, columnWidth: Map<number, number>, rowHeight: Map<number, number>): void;
@@ -1,7 +0,0 @@
1
- import type { AsciiConfig, AsciiTheme, ColorMode } from './types.js';
2
- /**
3
- * Render a Mermaid class diagram to ASCII/Unicode text.
4
- *
5
- * Pipeline: parse → build boxes → level-based layout → draw boxes → draw relationships → string.
6
- */
7
- export declare function renderClassAscii(text: string, config: AsciiConfig, colorMode?: ColorMode, theme?: AsciiTheme): string;
@@ -1,12 +0,0 @@
1
- import type { MermaidGraph } from '../types.js';
2
- import type { AsciiGraph, AsciiConfig } from './types.js';
3
- /**
4
- * Convert a parsed MermaidGraph into an AsciiGraph ready for grid layout.
5
- *
6
- * Key mappings:
7
- * - MermaidGraph.nodes (Map) → ordered AsciiNode[] preserving insertion order
8
- * - MermaidGraph.edges → AsciiEdge[] with resolved node references
9
- * - MermaidGraph.subgraphs → AsciiSubgraph[] with parent/child tree
10
- * - Node labels are used as display names (not raw IDs)
11
- */
12
- export declare function convertToAsciiGraph(parsed: MermaidGraph, config: AsciiConfig): AsciiGraph;
@@ -1,66 +0,0 @@
1
- import type { Canvas, DrawingCoord, AsciiGraph, AsciiNode, AsciiEdge, AsciiSubgraph, AsciiEdgeStyle } from './types.js';
2
- /**
3
- * Draw a node using its shape type.
4
- * Returns a standalone canvas containing the rendered shape.
5
- *
6
- * For basic shapes (rectangle, rounded), uses grid-determined dimensions
7
- * to ensure consistent sizing across nodes in the same column.
8
- * For special shapes (diamond, circle, state pseudo-states, etc.),
9
- * uses shape-specific dimension calculation but centers the content
10
- * within the grid cell dimensions to ensure proper vertical alignment.
11
- */
12
- export declare function drawNode(node: AsciiNode, graph: AsciiGraph): Canvas;
13
- /**
14
- * Draw a node box with centered label text.
15
- * Returns a standalone canvas containing just the box.
16
- * Box size is determined by the grid column/row sizes for the node's position.
17
- */
18
- export declare function drawBox(node: AsciiNode, graph: AsciiGraph): Canvas;
19
- /**
20
- * Draw a multi-section box with horizontal dividers between sections.
21
- * Used by class diagrams (header | attributes | methods) and ER diagrams (header | attributes).
22
- * Each section is an array of text lines to render left-aligned with padding.
23
- *
24
- * @param sections - Array of sections, each section is an array of text lines
25
- * @param useAscii - true for ASCII chars, false for Unicode box-drawing
26
- * @param padding - horizontal padding inside the box (default 1)
27
- * @returns A standalone Canvas containing the multi-section box
28
- */
29
- export declare function drawMultiBox(sections: string[][], useAscii: boolean, padding?: number): Canvas;
30
- /**
31
- * Draw a line between two drawing coordinates using orthogonal Manhattan routing.
32
- * Returns the list of coordinates that were drawn on.
33
- * offsetFrom/offsetTo control how many cells to skip at the start/end.
34
- *
35
- * All lines use 90° bends only - no diagonal lines are produced.
36
- * For diagonal directions, uses horizontal-first routing (draws horizontal
37
- * segment, then vertical segment).
38
- */
39
- export declare function drawLine(canvas: Canvas, from: DrawingCoord, to: DrawingCoord, offsetFrom: number, offsetTo: number, useAscii: boolean, style?: AsciiEdgeStyle): DrawingCoord[];
40
- /**
41
- * Draw a complete arrow (edge) between two nodes.
42
- * Returns 6 separate canvases for layered compositing:
43
- * [path, boxStart, arrowHeadEnd, arrowHeadStart, corners, label]
44
- *
45
- * Supports bidirectional arrows via edge.hasArrowStart and edge.hasArrowEnd.
46
- */
47
- export declare function drawArrow(graph: AsciiGraph, edge: AsciiEdge): [Canvas, Canvas, Canvas, Canvas, Canvas, Canvas];
48
- /** Draw a subgraph border rectangle. */
49
- export declare function drawSubgraphBox(sg: AsciiSubgraph, graph: AsciiGraph): Canvas;
50
- /** Draw a subgraph label centered in its header area. Supports multi-line labels. */
51
- export declare function drawSubgraphLabel(sg: AsciiSubgraph, graph: AsciiGraph): [Canvas, DrawingCoord];
52
- /**
53
- * Main draw function — renders the entire graph onto the canvas.
54
- * Drawing order matters for correct layering:
55
- * 1. Subgraph borders (bottom layer)
56
- * 2. Node boxes
57
- * 3. Edge paths (lines)
58
- * 4. Edge corners
59
- * 5. Arrowheads
60
- * 6. Box-start junctions
61
- * 7. Edge labels
62
- * 8. Subgraph labels (top layer)
63
- *
64
- * Also fills the roleCanvas with character roles for colored output.
65
- */
66
- export declare function drawGraph(graph: AsciiGraph): Canvas;
@@ -1,48 +0,0 @@
1
- import type { AsciiGraph, EdgeBundle, GridCoord } from './types.js';
2
- /**
3
- * Analyze graph edges and create bundles for parallel links.
4
- *
5
- * Groups edges by:
6
- * - Fan-in: Multiple edges sharing the same target (A & B --> C)
7
- * - Fan-out: Multiple edges sharing the same source (A --> B & C)
8
- *
9
- * Only creates bundles when:
10
- * - Graph direction is TD (top-down) - LR routing handles merging naturally
11
- * - 2+ edges share the endpoint
12
- * - All edges have the same style (solid/dotted/thick)
13
- * - None of the edges have labels (labels would overlap at junction)
14
- * - Edges are not self-loops
15
- *
16
- * @returns Array of bundles. Each edge can belong to at most one bundle.
17
- */
18
- export declare function analyzeEdgeBundles(graph: AsciiGraph): EdgeBundle[];
19
- /**
20
- * Calculate the optimal junction point for a bundle.
21
- *
22
- * For fan-in (A & B --> C):
23
- * - Junction is placed between the sources and the target
24
- * - In TD: above the target, horizontally centered between sources
25
- * - In LR: left of the target, vertically centered between sources
26
- *
27
- * For fan-out (A --> B & C):
28
- * - Junction is placed between the source and the targets
29
- * - In TD: below the source, horizontally centered between targets
30
- * - In LR: right of the source, vertically centered between targets
31
- */
32
- export declare function calculateJunctionPoint(graph: AsciiGraph, bundle: EdgeBundle): GridCoord;
33
- /**
34
- * Route all edges in a bundle through the junction point.
35
- *
36
- * For fan-in bundles:
37
- * 1. Route each source → junction (stored in edge.pathToJunction)
38
- * 2. Route junction → target (stored in bundle.sharedPath)
39
- *
40
- * For fan-out bundles:
41
- * 1. Route source → junction (stored in bundle.sharedPath)
42
- * 2. Route junction → each target (stored in edge.pathToJunction)
43
- */
44
- export declare function routeBundledEdges(graph: AsciiGraph, bundle: EdgeBundle): void;
45
- /**
46
- * Process all bundles in a graph: calculate junction points and route edges.
47
- */
48
- export declare function processBundles(graph: AsciiGraph): void;
@@ -1,43 +0,0 @@
1
- import type { Direction, AsciiEdge, AsciiGraph } from './types.js';
2
- export declare function getOpposite(d: Direction): Direction;
3
- /** Compare directions by value (not reference). */
4
- export declare function dirEquals(a: Direction, b: Direction): boolean;
5
- /**
6
- * Determine 8-way direction from one coordinate to another.
7
- * Uses the coordinate difference to pick one of 8 cardinal/ordinal directions.
8
- */
9
- export declare function determineDirection(from: {
10
- x: number;
11
- y: number;
12
- }, to: {
13
- x: number;
14
- y: number;
15
- }): Direction;
16
- /**
17
- * Determine preferred and alternative start/end directions for an edge.
18
- * Returns [preferredStart, preferredEnd, alternativeStart, alternativeEnd].
19
- *
20
- * The edge routing tries both pairs and picks the shorter path.
21
- * Direction selection depends on relative node positions and graph direction (LR vs TD).
22
- */
23
- export declare function determineStartAndEndDir(edge: AsciiEdge, graphDirection: string): [Direction, Direction, Direction, Direction];
24
- /**
25
- * Determine the path for an edge by trying two candidate routes (preferred + alternative)
26
- * and picking the shorter one. Sets edge.path, edge.startDir, edge.endDir.
27
- *
28
- * When both A* paths fail (common for edges crossing subgraph boundaries), falls back
29
- * to a direct path using the start/end points. This ensures edges always have a path
30
- * for arrowhead rendering.
31
- *
32
- * Uses the effective direction for edge routing, respecting subgraph direction overrides
33
- * when both source and target are in the same subgraph.
34
- */
35
- export declare function determinePath(graph: AsciiGraph, edge: AsciiEdge): void;
36
- /**
37
- * Find the best line segment in an edge's path to place a label on.
38
- * Prefers vertical segments for TD/BT graphs and horizontal for LR/RL to avoid
39
- * label collisions when multiple edges share initial segments.
40
- * Falls back to the widest segment if none are suitable.
41
- * Also increases the column width at the label position to fit the text.
42
- */
43
- export declare function determineLabelLine(graph: AsciiGraph, edge: AsciiEdge): void;
@@ -1,7 +0,0 @@
1
- import type { AsciiConfig, AsciiTheme, ColorMode } from './types.js';
2
- /**
3
- * Render a Mermaid ER diagram to ASCII/Unicode text.
4
- *
5
- * Pipeline: parse → build boxes → component-aware layout → draw boxes → draw relationships → string.
6
- */
7
- export declare function renderErAscii(text: string, config: AsciiConfig, colorMode?: ColorMode, theme?: AsciiTheme): string;
@@ -1,56 +0,0 @@
1
- import type { GridCoord, DrawingCoord, Direction, AsciiGraph, AsciiNode, AsciiSubgraph } from './types.js';
2
- /**
3
- * Convert a grid coordinate to a drawing (character) coordinate.
4
- * Sums column widths up to the target column, and row heights up to the target row,
5
- * then centers within the cell.
6
- */
7
- export declare function gridToDrawingCoord(graph: AsciiGraph, c: GridCoord, dir?: Direction): DrawingCoord;
8
- /** Convert a path of grid coords to drawing coords. */
9
- export declare function lineToDrawing(graph: AsciiGraph, line: GridCoord[]): DrawingCoord[];
10
- /**
11
- * Reserve a 3x3 block in the grid for a node.
12
- * If the requested position is occupied, recursively shift by 4 grid units
13
- * (in the perpendicular direction based on effective direction) until a free spot is found.
14
- *
15
- * @param effectiveDir - Optional direction override. If not provided, uses the node's
16
- * effective direction (subgraph direction if in a subgraph with override,
17
- * otherwise graph direction).
18
- */
19
- export declare function reserveSpotInGrid(graph: AsciiGraph, node: AsciiNode, requested: GridCoord, effectiveDir?: 'LR' | 'TD'): GridCoord;
20
- /**
21
- * Set column widths and row heights for a node's 3x3 grid block.
22
- * Each node occupies 3 columns (border, content, border) and 3 rows.
23
- * Uses shape-aware dimensions to properly size non-rectangular shapes.
24
- */
25
- export declare function setColumnWidth(graph: AsciiGraph, node: AsciiNode): void;
26
- /** Ensure grid has width/height entries for all cells along an edge path. */
27
- export declare function increaseGridSizeForPath(graph: AsciiGraph, path: GridCoord[]): void;
28
- /**
29
- * Get the innermost subgraph that directly contains this node.
30
- * Returns null if node is not in any subgraph.
31
- */
32
- export declare function getNodeSubgraph(graph: AsciiGraph, node: AsciiNode): AsciiSubgraph | null;
33
- /**
34
- * Get the effective direction for a node's layout.
35
- * Returns the subgraph's direction override if the node is in a subgraph with one,
36
- * otherwise returns the graph-level direction.
37
- */
38
- export declare function getEffectiveDirection(graph: AsciiGraph, node: AsciiNode): 'LR' | 'TD';
39
- export declare function calculateSubgraphBoundingBoxes(graph: AsciiGraph): void;
40
- /**
41
- * Offset all drawing coordinates so subgraph borders don't go negative.
42
- * If any subgraph has negative min coordinates, shift everything positive.
43
- */
44
- export declare function offsetDrawingForSubgraphs(graph: AsciiGraph): void;
45
- /**
46
- * createMapping performs the full grid layout:
47
- * 1. Place root nodes on the grid
48
- * 2. Place child nodes level by level
49
- * 3. Compute column widths and row heights
50
- * 4. Run A* pathfinding for all edges
51
- * 5. Determine label placement
52
- * 6. Convert grid coords → drawing coords
53
- * 7. Generate node box drawings
54
- * 8. Calculate subgraph bounding boxes
55
- */
56
- export declare function createMapping(graph: AsciiGraph): void;
@@ -1,65 +0,0 @@
1
- import { detectColorMode, DEFAULT_ASCII_THEME } from './ansi.js';
2
- import type { AsciiTheme, ColorMode } from './types.js';
3
- import type { Direction } from '../types.js';
4
- export type { AsciiTheme, ColorMode };
5
- export { DEFAULT_ASCII_THEME, detectColorMode };
6
- export interface AsciiRenderOptions {
7
- /** true = ASCII chars (+,-,|,>), false = Unicode box-drawing (┌,─,│,►). Default: false */
8
- useAscii?: boolean;
9
- /** Horizontal spacing between nodes. Default: 5 */
10
- paddingX?: number;
11
- /** Vertical spacing between nodes. Default: 5 */
12
- paddingY?: number;
13
- /** Padding inside node boxes. Default: 1 */
14
- boxBorderPadding?: number;
15
- /**
16
- * Force the layout direction, overriding the direction parsed from the
17
- * diagram source. Applies to the flowchart + state-diagram grid pipeline
18
- * (sequence/class/ER/xychart renderers ignore it). Useful for re-fitting a
19
- * wide `LR` graph into a narrow viewport by laying it out top-down.
20
- * Default: undefined (use the source's own direction).
21
- */
22
- direction?: Direction;
23
- /**
24
- * Color mode for output.
25
- * - 'none': No colors (plain text)
26
- * - 'auto': Auto-detect (terminal ANSI capabilities, or HTML in browsers)
27
- * - 'ansi16': 16-color ANSI
28
- * - 'ansi256': 256-color xterm
29
- * - 'truecolor': 24-bit RGB
30
- * - 'html': HTML <span> tags with inline color styles (for browser rendering)
31
- * Default: 'auto'
32
- */
33
- colorMode?: ColorMode | 'auto';
34
- /** Theme colors for ASCII output. Uses default theme if not provided. */
35
- theme?: Partial<AsciiTheme>;
36
- }
37
- /**
38
- * Render Mermaid diagram text to an ASCII/Unicode string.
39
- *
40
- * Synchronous — no async layout engine needed (unlike the SVG renderer).
41
- * Auto-detects diagram type from the header line and dispatches to
42
- * the appropriate renderer.
43
- *
44
- * @param text - Mermaid source text (any supported diagram type)
45
- * @param options - Rendering options
46
- * @returns Multi-line ASCII/Unicode string
47
- *
48
- * @example
49
- * ```ts
50
- * const result = renderMermaidAscii(`
51
- * graph LR
52
- * A --> B --> C
53
- * `, { useAscii: true })
54
- *
55
- * // Output:
56
- * // +---+ +---+ +---+
57
- * // | | | | | |
58
- * // | A |---->| B |---->| C |
59
- * // | | | | | |
60
- * // +---+ +---+ +---+
61
- * ```
62
- */
63
- export declare function renderMermaidASCII(text: string, options?: AsciiRenderOptions): string;
64
- /** Lowercase alias kept as the public name used by the pi-utils wrapper. */
65
- export declare const renderMermaidAscii: typeof renderMermaidASCII;