@linxiraos/pi-utils 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/CHANGELOG.md +449 -0
  2. package/README.md +36 -0
  3. package/dist/types/abortable.d.ts +32 -0
  4. package/dist/types/acp/connection.d.ts +118 -0
  5. package/dist/types/acp/protocol.d.ts +526 -0
  6. package/dist/types/acp/schema.d.ts +41 -0
  7. package/dist/types/acp/stream.d.ts +8 -0
  8. package/dist/types/acp/transport.d.ts +81 -0
  9. package/dist/types/acp.d.ts +6 -0
  10. package/dist/types/async.d.ts +20 -0
  11. package/dist/types/binary.d.ts +17 -0
  12. package/dist/types/browsers.d.ts +68 -0
  13. package/dist/types/chalk.d.ts +125 -0
  14. package/dist/types/cli.d.ts +134 -0
  15. package/dist/types/color.d.ts +102 -0
  16. package/dist/types/dates.d.ts +7 -0
  17. package/dist/types/dirs.d.ts +282 -0
  18. package/dist/types/docx/converter.d.ts +46 -0
  19. package/dist/types/docx/xml.d.ts +26 -0
  20. package/dist/types/docx/zip.d.ts +6 -0
  21. package/dist/types/docx.d.ts +11 -0
  22. package/dist/types/dom/core.d.ts +431 -0
  23. package/dist/types/dom/parser.d.ts +7 -0
  24. package/dist/types/dom/selector.d.ts +5 -0
  25. package/dist/types/dom.d.ts +5 -0
  26. package/dist/types/env.d.ts +124 -0
  27. package/dist/types/fetch-retry.d.ts +96 -0
  28. package/dist/types/file-lock.d.ts +23 -0
  29. package/dist/types/format.d.ts +37 -0
  30. package/dist/types/frontmatter.d.ts +46 -0
  31. package/dist/types/fs-error.d.ts +31 -0
  32. package/dist/types/glob.d.ts +28 -0
  33. package/dist/types/headers.d.ts +34 -0
  34. package/dist/types/index.d.ts +39 -0
  35. package/dist/types/json-parse.d.ts +74 -0
  36. package/dist/types/json.d.ts +14 -0
  37. package/dist/types/logger/rotating-file.d.ts +18 -0
  38. package/dist/types/logger.d.ts +96 -0
  39. package/dist/types/loop-phase.d.ts +10 -0
  40. package/dist/types/lru.d.ts +46 -0
  41. package/dist/types/marked/core.d.ts +445 -0
  42. package/dist/types/marked.d.ts +2 -0
  43. package/dist/types/mermaid-ascii.d.ts +11 -0
  44. package/dist/types/mime.d.ts +29 -0
  45. package/dist/types/module-timer.d.ts +1 -0
  46. package/dist/types/path-tree.d.ts +76 -0
  47. package/dist/types/path.d.ts +2 -0
  48. package/dist/types/peek-file.d.ts +29 -0
  49. package/dist/types/postmortem.d.ts +104 -0
  50. package/dist/types/process-name.d.ts +7 -0
  51. package/dist/types/procmgr.d.ts +74 -0
  52. package/dist/types/prompt.d.ts +18 -0
  53. package/dist/types/ptree.d.ts +110 -0
  54. package/dist/types/readability/readability.d.ts +9 -0
  55. package/dist/types/readability/readerable.d.ts +10 -0
  56. package/dist/types/readability/types.d.ts +70 -0
  57. package/dist/types/readability.d.ts +4 -0
  58. package/dist/types/ring.d.ts +93 -0
  59. package/dist/types/runtime-install.d.ts +78 -0
  60. package/dist/types/sanitize-text.d.ts +29 -0
  61. package/dist/types/snowflake.d.ts +25 -0
  62. package/dist/types/stderr-guard.d.ts +22 -0
  63. package/dist/types/stream.d.ts +67 -0
  64. package/dist/types/tab-spacing.d.ts +24 -0
  65. package/dist/types/temp.d.ts +17 -0
  66. package/dist/types/template.d.ts +62 -0
  67. package/dist/types/timing-buffer.d.ts +22 -0
  68. package/dist/types/tls-fetch.d.ts +37 -0
  69. package/dist/types/turndown/gfm.d.ts +11 -0
  70. package/dist/types/turndown/html.d.ts +5 -0
  71. package/dist/types/turndown/service.d.ts +21 -0
  72. package/dist/types/turndown/types.d.ts +70 -0
  73. package/dist/types/turndown.d.ts +4 -0
  74. package/dist/types/type-guards.d.ts +5 -0
  75. package/dist/types/vendor/mermaid-ascii/ascii/ansi.d.ts +41 -0
  76. package/dist/types/vendor/mermaid-ascii/ascii/canvas.d.ts +89 -0
  77. package/dist/types/vendor/mermaid-ascii/ascii/class-diagram.d.ts +7 -0
  78. package/dist/types/vendor/mermaid-ascii/ascii/converter.d.ts +12 -0
  79. package/dist/types/vendor/mermaid-ascii/ascii/draw.d.ts +66 -0
  80. package/dist/types/vendor/mermaid-ascii/ascii/edge-bundling.d.ts +48 -0
  81. package/dist/types/vendor/mermaid-ascii/ascii/edge-routing.d.ts +43 -0
  82. package/dist/types/vendor/mermaid-ascii/ascii/er-diagram.d.ts +7 -0
  83. package/dist/types/vendor/mermaid-ascii/ascii/grid.d.ts +56 -0
  84. package/dist/types/vendor/mermaid-ascii/ascii/index.d.ts +65 -0
  85. package/dist/types/vendor/mermaid-ascii/ascii/multiline-utils.d.ts +27 -0
  86. package/dist/types/vendor/mermaid-ascii/ascii/pathfinder.d.ts +17 -0
  87. package/dist/types/vendor/mermaid-ascii/ascii/sequence.d.ts +7 -0
  88. package/dist/types/vendor/mermaid-ascii/ascii/shapes/circle.d.ts +11 -0
  89. package/dist/types/vendor/mermaid-ascii/ascii/shapes/corners.d.ts +34 -0
  90. package/dist/types/vendor/mermaid-ascii/ascii/shapes/diamond.d.ts +11 -0
  91. package/dist/types/vendor/mermaid-ascii/ascii/shapes/hexagon.d.ts +11 -0
  92. package/dist/types/vendor/mermaid-ascii/ascii/shapes/index.d.ts +26 -0
  93. package/dist/types/vendor/mermaid-ascii/ascii/shapes/rectangle.d.ts +31 -0
  94. package/dist/types/vendor/mermaid-ascii/ascii/shapes/rounded.d.ts +11 -0
  95. package/dist/types/vendor/mermaid-ascii/ascii/shapes/special.d.ts +59 -0
  96. package/dist/types/vendor/mermaid-ascii/ascii/shapes/stadium.d.ts +17 -0
  97. package/dist/types/vendor/mermaid-ascii/ascii/shapes/state.d.ts +30 -0
  98. package/dist/types/vendor/mermaid-ascii/ascii/shapes/types.d.ts +55 -0
  99. package/dist/types/vendor/mermaid-ascii/ascii/types.d.ts +206 -0
  100. package/dist/types/vendor/mermaid-ascii/ascii/validate.d.ts +51 -0
  101. package/dist/types/vendor/mermaid-ascii/ascii/xychart.d.ts +2 -0
  102. package/dist/types/vendor/mermaid-ascii/class/parser.d.ts +6 -0
  103. package/dist/types/vendor/mermaid-ascii/class/types.d.ts +102 -0
  104. package/dist/types/vendor/mermaid-ascii/er/parser.d.ts +6 -0
  105. package/dist/types/vendor/mermaid-ascii/er/types.d.ts +76 -0
  106. package/dist/types/vendor/mermaid-ascii/index.d.ts +1 -0
  107. package/dist/types/vendor/mermaid-ascii/multiline-utils.d.ts +9 -0
  108. package/dist/types/vendor/mermaid-ascii/parser.d.ts +7 -0
  109. package/dist/types/vendor/mermaid-ascii/sequence/parser.d.ts +6 -0
  110. package/dist/types/vendor/mermaid-ascii/sequence/types.d.ts +130 -0
  111. package/dist/types/vendor/mermaid-ascii/text-metrics.d.ts +21 -0
  112. package/dist/types/vendor/mermaid-ascii/types.d.ts +114 -0
  113. package/dist/types/vendor/mermaid-ascii/xychart/colors.d.ts +25 -0
  114. package/dist/types/vendor/mermaid-ascii/xychart/parser.d.ts +6 -0
  115. package/dist/types/vendor/mermaid-ascii/xychart/types.d.ts +145 -0
  116. package/dist/types/version.d.ts +18 -0
  117. package/dist/types/vterm/buffer.d.ts +99 -0
  118. package/dist/types/vterm/terminal.d.ts +44 -0
  119. package/dist/types/vterm.d.ts +8 -0
  120. package/dist/types/which.d.ts +37 -0
  121. package/dist/types/worker-host.d.ts +51 -0
  122. package/dist/types/xml.d.ts +31 -0
  123. package/package.json +59 -0
  124. package/src/abortable.ts +109 -0
  125. package/src/acp/connection.ts +344 -0
  126. package/src/acp/protocol.ts +466 -0
  127. package/src/acp/schema.ts +160 -0
  128. package/src/acp/stream.ts +82 -0
  129. package/src/acp/transport.ts +213 -0
  130. package/src/acp.ts +6 -0
  131. package/src/async.ts +91 -0
  132. package/src/binary.ts +50 -0
  133. package/src/browsers.ts +501 -0
  134. package/src/chalk.ts +312 -0
  135. package/src/cli.ts +529 -0
  136. package/src/color.ts +302 -0
  137. package/src/dates.ts +194 -0
  138. package/src/dirs.ts +1026 -0
  139. package/src/docx/converter.ts +681 -0
  140. package/src/docx/xml.ts +166 -0
  141. package/src/docx/zip.ts +87 -0
  142. package/src/docx.ts +20 -0
  143. package/src/dom/core.ts +1254 -0
  144. package/src/dom/parser.ts +370 -0
  145. package/src/dom/selector.ts +290 -0
  146. package/src/dom.ts +33 -0
  147. package/src/env.ts +400 -0
  148. package/src/fetch-retry.ts +379 -0
  149. package/src/file-lock.ts +69 -0
  150. package/src/format.ts +113 -0
  151. package/src/frontmatter.ts +205 -0
  152. package/src/fs-error.ts +56 -0
  153. package/src/glob.ts +189 -0
  154. package/src/headers.ts +167 -0
  155. package/src/index.ts +59 -0
  156. package/src/json-parse.ts +821 -0
  157. package/src/json.ts +23 -0
  158. package/src/logger/rotating-file.ts +149 -0
  159. package/src/logger.ts +798 -0
  160. package/src/loop-phase.ts +49 -0
  161. package/src/lru.ts +185 -0
  162. package/src/marked/core.ts +1576 -0
  163. package/src/marked.ts +2 -0
  164. package/src/mermaid-ascii.ts +31 -0
  165. package/src/mime.ts +159 -0
  166. package/src/module-timer.ts +148 -0
  167. package/src/path-tree.ts +147 -0
  168. package/src/path.ts +28 -0
  169. package/src/peek-file.ts +188 -0
  170. package/src/postmortem.ts +433 -0
  171. package/src/process-name.ts +57 -0
  172. package/src/procmgr.ts +247 -0
  173. package/src/prompt.ts +545 -0
  174. package/src/ptree.ts +412 -0
  175. package/src/readability/readability.ts +533 -0
  176. package/src/readability/readerable.ts +51 -0
  177. package/src/readability/types.ts +72 -0
  178. package/src/readability.ts +11 -0
  179. package/src/ring.ts +169 -0
  180. package/src/runtime-install.ts +393 -0
  181. package/src/sanitize-text.ts +96 -0
  182. package/src/snowflake.ts +121 -0
  183. package/src/stderr-guard.ts +155 -0
  184. package/src/stream.ts +454 -0
  185. package/src/tab-spacing.ts +336 -0
  186. package/src/temp.ts +134 -0
  187. package/src/template.ts +586 -0
  188. package/src/timing-buffer.ts +47 -0
  189. package/src/tls-fetch.ts +178 -0
  190. package/src/turndown/gfm.ts +106 -0
  191. package/src/turndown/html.ts +257 -0
  192. package/src/turndown/service.ts +334 -0
  193. package/src/turndown/types.ts +81 -0
  194. package/src/turndown.ts +5 -0
  195. package/src/type-guards.ts +17 -0
  196. package/src/vendor/mermaid-ascii/NOTICE +33 -0
  197. package/src/vendor/mermaid-ascii/ascii/ansi.ts +409 -0
  198. package/src/vendor/mermaid-ascii/ascii/canvas.ts +476 -0
  199. package/src/vendor/mermaid-ascii/ascii/class-diagram.ts +699 -0
  200. package/src/vendor/mermaid-ascii/ascii/converter.ts +271 -0
  201. package/src/vendor/mermaid-ascii/ascii/draw.ts +1382 -0
  202. package/src/vendor/mermaid-ascii/ascii/edge-bundling.ts +328 -0
  203. package/src/vendor/mermaid-ascii/ascii/edge-routing.ts +297 -0
  204. package/src/vendor/mermaid-ascii/ascii/er-diagram.ts +441 -0
  205. package/src/vendor/mermaid-ascii/ascii/grid.ts +578 -0
  206. package/src/vendor/mermaid-ascii/ascii/index.ts +187 -0
  207. package/src/vendor/mermaid-ascii/ascii/multiline-utils.ts +78 -0
  208. package/src/vendor/mermaid-ascii/ascii/pathfinder.ts +277 -0
  209. package/src/vendor/mermaid-ascii/ascii/sequence.ts +460 -0
  210. package/src/vendor/mermaid-ascii/ascii/shapes/circle.ts +27 -0
  211. package/src/vendor/mermaid-ascii/ascii/shapes/corners.ts +127 -0
  212. package/src/vendor/mermaid-ascii/ascii/shapes/diamond.ts +27 -0
  213. package/src/vendor/mermaid-ascii/ascii/shapes/hexagon.ts +27 -0
  214. package/src/vendor/mermaid-ascii/ascii/shapes/index.ts +101 -0
  215. package/src/vendor/mermaid-ascii/ascii/shapes/rectangle.ts +175 -0
  216. package/src/vendor/mermaid-ascii/ascii/shapes/rounded.ts +27 -0
  217. package/src/vendor/mermaid-ascii/ascii/shapes/special.ts +296 -0
  218. package/src/vendor/mermaid-ascii/ascii/shapes/stadium.ts +114 -0
  219. package/src/vendor/mermaid-ascii/ascii/shapes/state.ts +192 -0
  220. package/src/vendor/mermaid-ascii/ascii/shapes/types.ts +73 -0
  221. package/src/vendor/mermaid-ascii/ascii/types.ts +273 -0
  222. package/src/vendor/mermaid-ascii/ascii/validate.ts +120 -0
  223. package/src/vendor/mermaid-ascii/ascii/xychart.ts +875 -0
  224. package/src/vendor/mermaid-ascii/class/parser.ts +290 -0
  225. package/src/vendor/mermaid-ascii/class/types.ts +121 -0
  226. package/src/vendor/mermaid-ascii/er/parser.ts +181 -0
  227. package/src/vendor/mermaid-ascii/er/types.ts +91 -0
  228. package/src/vendor/mermaid-ascii/index.ts +14 -0
  229. package/src/vendor/mermaid-ascii/multiline-utils.ts +30 -0
  230. package/src/vendor/mermaid-ascii/parser.ts +645 -0
  231. package/src/vendor/mermaid-ascii/sequence/parser.ts +207 -0
  232. package/src/vendor/mermaid-ascii/sequence/types.ts +146 -0
  233. package/src/vendor/mermaid-ascii/text-metrics.ts +71 -0
  234. package/src/vendor/mermaid-ascii/types.ts +164 -0
  235. package/src/vendor/mermaid-ascii/xychart/colors.ts +140 -0
  236. package/src/vendor/mermaid-ascii/xychart/parser.ts +115 -0
  237. package/src/vendor/mermaid-ascii/xychart/types.ts +150 -0
  238. package/src/version.ts +99 -0
  239. package/src/vterm/buffer.ts +218 -0
  240. package/src/vterm/terminal.ts +773 -0
  241. package/src/vterm.ts +8 -0
  242. package/src/which.ts +234 -0
  243. package/src/worker-host.ts +100 -0
  244. package/src/xml.ts +313 -0
@@ -0,0 +1,43 @@
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;
@@ -0,0 +1,7 @@
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;
@@ -0,0 +1,56 @@
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;
@@ -0,0 +1,65 @@
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;
@@ -0,0 +1,27 @@
1
+ import type { Canvas } from './types.js';
2
+ /**
3
+ * Split a label into lines.
4
+ * Labels are already normalized by parsers (br tags → \n).
5
+ */
6
+ export declare function splitLines(label: string): string[];
7
+ /**
8
+ * Get the maximum line width for sizing calculations.
9
+ * Used to determine column widths for multi-line labels.
10
+ */
11
+ export declare function maxLineWidth(label: string): number;
12
+ /**
13
+ * Get the number of lines for height calculations.
14
+ * Used to determine row heights for multi-line labels.
15
+ */
16
+ export declare function lineCount(label: string): number;
17
+ /**
18
+ * Draw multi-line text centered at (cx, cy).
19
+ * Expands vertically from the center point.
20
+ * Each line is horizontally centered independently.
21
+ */
22
+ export declare function drawMultilineTextCentered(canvas: Canvas, label: string, cx: number, cy: number): void;
23
+ /**
24
+ * Draw multi-line text left-aligned starting at (x, y).
25
+ * Each subsequent line is placed one row below.
26
+ */
27
+ export declare function drawMultilineTextLeft(canvas: Canvas, label: string, x: number, y: number): void;
@@ -0,0 +1,17 @@
1
+ import type { GridCoord, AsciiNode } from './types.js';
2
+ /**
3
+ * Manhattan distance with a +1 penalty when both dx and dy are non-zero.
4
+ * This encourages the pathfinder to prefer straight lines and minimize corners.
5
+ */
6
+ export declare function heuristic(a: GridCoord, b: GridCoord): number;
7
+ /**
8
+ * Find a path from `from` to `to` on the grid using A*.
9
+ * Returns the path as an array of GridCoords, or null if no bounded path exists.
10
+ */
11
+ export declare function getPath(grid: Map<string, AsciiNode>, from: GridCoord, to: GridCoord): GridCoord[] | null;
12
+ /**
13
+ * Simplify a path by removing intermediate waypoints on straight segments.
14
+ * E.g., [(0,0), (1,0), (2,0), (2,1)] becomes [(0,0), (2,0), (2,1)].
15
+ * This reduces the number of line-drawing operations.
16
+ */
17
+ export declare function mergePath(path: GridCoord[]): GridCoord[];
@@ -0,0 +1,7 @@
1
+ import type { AsciiConfig, AsciiTheme, ColorMode } from './types.js';
2
+ /**
3
+ * Render a Mermaid sequence diagram to ASCII/Unicode text.
4
+ *
5
+ * Pipeline: parse → layout (columns + rows) → draw onto canvas → string.
6
+ */
7
+ export declare function renderSequenceAscii(text: string, config: AsciiConfig, colorMode?: ColorMode, theme?: AsciiTheme): string;
@@ -0,0 +1,11 @@
1
+ import type { ShapeRenderer } from './types.js';
2
+ /**
3
+ * Circle shape renderer.
4
+ * Uses circle markers (◯) at corners to indicate circular shape semantics.
5
+ *
6
+ * Renders as:
7
+ * ◯─────────◯
8
+ * │ Label │
9
+ * ◯─────────◯
10
+ */
11
+ export declare const circleRenderer: ShapeRenderer;
@@ -0,0 +1,34 @@
1
+ import type { AsciiNodeShape } from '../types.js';
2
+ /**
3
+ * Corner characters for a shape in both Unicode and ASCII modes.
4
+ */
5
+ export interface CornerChars {
6
+ /** Top-left corner */
7
+ tl: string;
8
+ /** Top-right corner */
9
+ tr: string;
10
+ /** Bottom-left corner */
11
+ bl: string;
12
+ /** Bottom-right corner */
13
+ br: string;
14
+ }
15
+ /**
16
+ * Shape corner configuration with both Unicode and ASCII variants.
17
+ */
18
+ export interface ShapeCorners {
19
+ unicode: CornerChars;
20
+ ascii: CornerChars;
21
+ }
22
+ /**
23
+ * Corner character lookup table for all shape types.
24
+ *
25
+ * Design principles:
26
+ * - All shapes use orthogonal box structure (no diagonals)
27
+ * - Corner characters indicate shape semantics
28
+ * - ASCII fallbacks use available punctuation
29
+ */
30
+ export declare const SHAPE_CORNERS: Record<AsciiNodeShape, ShapeCorners>;
31
+ /**
32
+ * Get corner characters for a shape type.
33
+ */
34
+ export declare function getCorners(shape: AsciiNodeShape, useAscii: boolean): CornerChars;
@@ -0,0 +1,11 @@
1
+ import type { ShapeRenderer } from './types.js';
2
+ /**
3
+ * Diamond shape renderer.
4
+ * Uses diamond markers (◇) at corners to indicate decision node semantics.
5
+ *
6
+ * Renders as:
7
+ * ◇─────────◇
8
+ * │ Label │
9
+ * ◇─────────◇
10
+ */
11
+ export declare const diamondRenderer: ShapeRenderer;
@@ -0,0 +1,11 @@
1
+ import type { ShapeRenderer } from './types.js';
2
+ /**
3
+ * Hexagon shape renderer.
4
+ * Uses hexagon markers (⬡) at corners to indicate process node semantics.
5
+ *
6
+ * Renders as:
7
+ * ⬡─────────⬡
8
+ * │ Label │
9
+ * ⬡─────────⬡
10
+ */
11
+ export declare const hexagonRenderer: ShapeRenderer;
@@ -0,0 +1,26 @@
1
+ import type { AsciiNodeShape, Canvas, DrawingCoord, Direction } from '../types.js';
2
+ import type { ShapeRenderer, ShapeDimensions, ShapeRenderOptions, ShapeRegistry } from './types.js';
3
+ export type { ShapeRenderer, ShapeDimensions, ShapeRenderOptions, ShapeRegistry };
4
+ /**
5
+ * Global shape registry — maps shape types to their renderers.
6
+ * Rectangle is the default fallback for unregistered shapes.
7
+ */
8
+ export declare const shapeRegistry: ShapeRegistry;
9
+ /**
10
+ * Get the renderer for a shape type, falling back to rectangle.
11
+ */
12
+ export declare function getShapeRenderer(shape: AsciiNodeShape): ShapeRenderer;
13
+ /**
14
+ * Render a node shape to a canvas.
15
+ * This is the main entry point for shape rendering.
16
+ */
17
+ export declare function renderShape(shape: AsciiNodeShape, label: string, options: ShapeRenderOptions): Canvas;
18
+ /**
19
+ * Get dimensions for a shape given a label.
20
+ * Used during layout to determine node size.
21
+ */
22
+ export declare function getShapeDimensions(shape: AsciiNodeShape, label: string, options: ShapeRenderOptions): ShapeDimensions;
23
+ /**
24
+ * Get edge attachment point for a shape.
25
+ */
26
+ export declare function getShapeAttachmentPoint(shape: AsciiNodeShape, dir: Direction, dimensions: ShapeDimensions, baseCoord: DrawingCoord): DrawingCoord;
@@ -0,0 +1,31 @@
1
+ import type { Canvas, DrawingCoord, Direction } from '../types.js';
2
+ import type { ShapeRenderer, ShapeDimensions, ShapeRenderOptions } from './types.js';
3
+ import { type CornerChars } from './corners.js';
4
+ /**
5
+ * Calculate standard box dimensions for any rectangular shape.
6
+ * Used by rectangle, circle, diamond, hexagon, etc.
7
+ */
8
+ export declare function getBoxDimensions(label: string, options: ShapeRenderOptions): ShapeDimensions;
9
+ /**
10
+ * Render a box with custom corner characters.
11
+ * This is the core rendering function used by all rectangular shapes.
12
+ *
13
+ * @param label - Text to display in the box
14
+ * @param dimensions - Pre-calculated dimensions
15
+ * @param corners - Corner characters (tl, tr, bl, br)
16
+ * @param useAscii - Whether to use ASCII or Unicode for lines
17
+ */
18
+ export declare function renderBox(label: string, dimensions: ShapeDimensions, corners: CornerChars, useAscii: boolean): Canvas;
19
+ /**
20
+ * Calculate edge attachment point for rectangular shapes.
21
+ * All box-based shapes use the same attachment logic.
22
+ */
23
+ export declare function getBoxAttachmentPoint(dir: Direction, dimensions: ShapeDimensions, baseCoord: DrawingCoord): DrawingCoord;
24
+ /**
25
+ * Rectangle shape renderer — the default box shape.
26
+ * Renders as:
27
+ * ┌─────────┐
28
+ * │ Label │
29
+ * └─────────┘
30
+ */
31
+ export declare const rectangleRenderer: ShapeRenderer;
@@ -0,0 +1,11 @@
1
+ import type { ShapeRenderer } from './types.js';
2
+ /**
3
+ * Rounded rectangle shape renderer.
4
+ * Uses rounded corner markers (╭╮╰╯) to indicate soft edges.
5
+ *
6
+ * Renders as:
7
+ * ╭─────────╮
8
+ * │ Label │
9
+ * ╰─────────╯
10
+ */
11
+ export declare const roundedRenderer: ShapeRenderer;
@@ -0,0 +1,59 @@
1
+ import type { ShapeRenderer } from './types.js';
2
+ /**
3
+ * Subroutine shape renderer — double-bordered rectangle.
4
+ * Renders as:
5
+ * ┌┬─────────┬┐
6
+ * ││ Label ││
7
+ * └┴─────────┴┘
8
+ */
9
+ export declare const subroutineRenderer: ShapeRenderer;
10
+ /**
11
+ * Double circle shape renderer.
12
+ * Uses double circle markers (◎) at corners.
13
+ *
14
+ * Renders as:
15
+ * ◎─────────◎
16
+ * │ Label │
17
+ * ◎─────────◎
18
+ */
19
+ export declare const doublecircleRenderer: ShapeRenderer;
20
+ /**
21
+ * Cylinder shape renderer — database symbol.
22
+ * Renders as:
23
+ * ╭─────╮
24
+ * │─────│
25
+ * │ DB │
26
+ * │─────│
27
+ * ╰─────╯
28
+ */
29
+ export declare const cylinderRenderer: ShapeRenderer;
30
+ /**
31
+ * Asymmetric (flag/banner) shape renderer.
32
+ * Uses arrow markers (▷) on left corners.
33
+ *
34
+ * Renders as:
35
+ * ▷─────────┐
36
+ * │ Label │
37
+ * ▷─────────┘
38
+ */
39
+ export declare const asymmetricRenderer: ShapeRenderer;
40
+ /**
41
+ * Trapezoid shape renderer — wider at bottom.
42
+ * Uses slope markers (◸◹) on top corners.
43
+ *
44
+ * Renders as:
45
+ * ◸─────────◹
46
+ * │ Label │
47
+ * └─────────┘
48
+ */
49
+ export declare const trapezoidRenderer: ShapeRenderer;
50
+ /**
51
+ * Trapezoid-alt shape renderer — wider at top.
52
+ * Uses slope markers (◺◿) on bottom corners.
53
+ *
54
+ * Renders as:
55
+ * ┌─────────┐
56
+ * │ Label │
57
+ * ◺─────────◿
58
+ */
59
+ export declare const trapezoidAltRenderer: ShapeRenderer;
@@ -0,0 +1,17 @@
1
+ import type { ShapeRenderer } from './types.js';
2
+ /**
3
+ * Stadium (pill) shape renderer.
4
+ *
5
+ * Single-line: ( Label )
6
+ *
7
+ * Multi-line unicode:
8
+ * ╭──────────╮
9
+ * │ Label │
10
+ * ╰──────────╯
11
+ *
12
+ * Multi-line ASCII:
13
+ * (----------)
14
+ * ( Label )
15
+ * (----------)
16
+ */
17
+ export declare const stadiumRenderer: ShapeRenderer;
@@ -0,0 +1,30 @@
1
+ import type { ShapeRenderer } from './types.js';
2
+ /**
3
+ * State start pseudo-state renderer — filled circle in rounded box.
4
+ * Renders as:
5
+ * ╭───╮
6
+ * │ ● │ (Unicode)
7
+ * ╰───╯
8
+ *
9
+ * .---.
10
+ * | * | (ASCII)
11
+ * '---'
12
+ *
13
+ * This represents the UML initial pseudo-state.
14
+ */
15
+ export declare const stateStartRenderer: ShapeRenderer;
16
+ /**
17
+ * State end pseudo-state renderer — bullseye in double-bordered box.
18
+ * Renders as:
19
+ * ╔═══╗
20
+ * ║ ◎ ║ (Unicode)
21
+ * ╚═══╝
22
+ *
23
+ * #===#
24
+ * # * # (ASCII)
25
+ * #===#
26
+ *
27
+ * This represents the UML final state. The double border distinguishes it
28
+ * from the start state's single rounded border.
29
+ */
30
+ export declare const stateEndRenderer: ShapeRenderer;
@@ -0,0 +1,55 @@
1
+ import type { Canvas, DrawingCoord, Direction, AsciiNodeShape } from '../types.js';
2
+ /**
3
+ * Dimensions calculated for a shape, used by layout and rendering.
4
+ */
5
+ export interface ShapeDimensions {
6
+ /** Total width in characters including borders */
7
+ width: number;
8
+ /** Total height in characters including borders */
9
+ height: number;
10
+ /** Label area bounds (where text can be placed) */
11
+ labelArea: {
12
+ x: number;
13
+ y: number;
14
+ width: number;
15
+ height: number;
16
+ };
17
+ /** Grid column widths for the 3-column layout [left, center, right] */
18
+ gridColumns: [number, number, number];
19
+ /** Grid row heights for the 3-row layout [top, middle, bottom] */
20
+ gridRows: [number, number, number];
21
+ }
22
+ /**
23
+ * Options passed to shape renderers.
24
+ */
25
+ export interface ShapeRenderOptions {
26
+ /** Use ASCII chars (+,-,|) vs Unicode box-drawing (┌,─,│) */
27
+ useAscii: boolean;
28
+ /** Padding inside the shape */
29
+ padding: number;
30
+ }
31
+ /**
32
+ * Interface for pluggable shape renderers.
33
+ * Each shape type implements this interface.
34
+ */
35
+ export interface ShapeRenderer {
36
+ /**
37
+ * Calculate dimensions for this shape given a label.
38
+ * Used during layout to determine node size.
39
+ */
40
+ getDimensions(label: string, options: ShapeRenderOptions): ShapeDimensions;
41
+ /**
42
+ * Render the shape to a canvas.
43
+ * Returns a standalone canvas containing just the shape.
44
+ */
45
+ render(label: string, dimensions: ShapeDimensions, options: ShapeRenderOptions): Canvas;
46
+ /**
47
+ * Get the edge attachment point for a given direction.
48
+ * Used by edge routing to determine where edges connect.
49
+ */
50
+ getAttachmentPoint(dir: Direction, dimensions: ShapeDimensions, baseCoord: DrawingCoord): DrawingCoord;
51
+ }
52
+ /**
53
+ * Registry of shape renderers keyed by shape type.
54
+ */
55
+ export type ShapeRegistry = Map<AsciiNodeShape, ShapeRenderer>;