@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.
- package/CHANGELOG.md +449 -0
- package/README.md +36 -0
- package/dist/types/abortable.d.ts +32 -0
- package/dist/types/acp/connection.d.ts +118 -0
- package/dist/types/acp/protocol.d.ts +526 -0
- package/dist/types/acp/schema.d.ts +41 -0
- package/dist/types/acp/stream.d.ts +8 -0
- package/dist/types/acp/transport.d.ts +81 -0
- package/dist/types/acp.d.ts +6 -0
- package/dist/types/async.d.ts +20 -0
- package/dist/types/binary.d.ts +17 -0
- package/dist/types/browsers.d.ts +68 -0
- package/dist/types/chalk.d.ts +125 -0
- package/dist/types/cli.d.ts +134 -0
- package/dist/types/color.d.ts +102 -0
- package/dist/types/dates.d.ts +7 -0
- package/dist/types/dirs.d.ts +282 -0
- package/dist/types/docx/converter.d.ts +46 -0
- package/dist/types/docx/xml.d.ts +26 -0
- package/dist/types/docx/zip.d.ts +6 -0
- package/dist/types/docx.d.ts +11 -0
- package/dist/types/dom/core.d.ts +431 -0
- package/dist/types/dom/parser.d.ts +7 -0
- package/dist/types/dom/selector.d.ts +5 -0
- package/dist/types/dom.d.ts +5 -0
- package/dist/types/env.d.ts +124 -0
- package/dist/types/fetch-retry.d.ts +96 -0
- package/dist/types/file-lock.d.ts +23 -0
- package/dist/types/format.d.ts +37 -0
- package/dist/types/frontmatter.d.ts +46 -0
- package/dist/types/fs-error.d.ts +31 -0
- package/dist/types/glob.d.ts +28 -0
- package/dist/types/headers.d.ts +34 -0
- package/dist/types/index.d.ts +39 -0
- package/dist/types/json-parse.d.ts +74 -0
- package/dist/types/json.d.ts +14 -0
- package/dist/types/logger/rotating-file.d.ts +18 -0
- package/dist/types/logger.d.ts +96 -0
- package/dist/types/loop-phase.d.ts +10 -0
- package/dist/types/lru.d.ts +46 -0
- package/dist/types/marked/core.d.ts +445 -0
- package/dist/types/marked.d.ts +2 -0
- package/dist/types/mermaid-ascii.d.ts +11 -0
- package/dist/types/mime.d.ts +29 -0
- package/dist/types/module-timer.d.ts +1 -0
- package/dist/types/path-tree.d.ts +76 -0
- package/dist/types/path.d.ts +2 -0
- package/dist/types/peek-file.d.ts +29 -0
- package/dist/types/postmortem.d.ts +104 -0
- package/dist/types/process-name.d.ts +7 -0
- package/dist/types/procmgr.d.ts +74 -0
- package/dist/types/prompt.d.ts +18 -0
- package/dist/types/ptree.d.ts +110 -0
- package/dist/types/readability/readability.d.ts +9 -0
- package/dist/types/readability/readerable.d.ts +10 -0
- package/dist/types/readability/types.d.ts +70 -0
- package/dist/types/readability.d.ts +4 -0
- package/dist/types/ring.d.ts +93 -0
- package/dist/types/runtime-install.d.ts +78 -0
- package/dist/types/sanitize-text.d.ts +29 -0
- package/dist/types/snowflake.d.ts +25 -0
- package/dist/types/stderr-guard.d.ts +22 -0
- package/dist/types/stream.d.ts +67 -0
- package/dist/types/tab-spacing.d.ts +24 -0
- package/dist/types/temp.d.ts +17 -0
- package/dist/types/template.d.ts +62 -0
- package/dist/types/timing-buffer.d.ts +22 -0
- package/dist/types/tls-fetch.d.ts +37 -0
- package/dist/types/turndown/gfm.d.ts +11 -0
- package/dist/types/turndown/html.d.ts +5 -0
- package/dist/types/turndown/service.d.ts +21 -0
- package/dist/types/turndown/types.d.ts +70 -0
- package/dist/types/turndown.d.ts +4 -0
- package/dist/types/type-guards.d.ts +5 -0
- package/dist/types/vendor/mermaid-ascii/ascii/ansi.d.ts +41 -0
- package/dist/types/vendor/mermaid-ascii/ascii/canvas.d.ts +89 -0
- package/dist/types/vendor/mermaid-ascii/ascii/class-diagram.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/ascii/converter.d.ts +12 -0
- package/dist/types/vendor/mermaid-ascii/ascii/draw.d.ts +66 -0
- package/dist/types/vendor/mermaid-ascii/ascii/edge-bundling.d.ts +48 -0
- package/dist/types/vendor/mermaid-ascii/ascii/edge-routing.d.ts +43 -0
- package/dist/types/vendor/mermaid-ascii/ascii/er-diagram.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/ascii/grid.d.ts +56 -0
- package/dist/types/vendor/mermaid-ascii/ascii/index.d.ts +65 -0
- package/dist/types/vendor/mermaid-ascii/ascii/multiline-utils.d.ts +27 -0
- package/dist/types/vendor/mermaid-ascii/ascii/pathfinder.d.ts +17 -0
- package/dist/types/vendor/mermaid-ascii/ascii/sequence.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/circle.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/corners.d.ts +34 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/diamond.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/hexagon.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/index.d.ts +26 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/rectangle.d.ts +31 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/rounded.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/special.d.ts +59 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/stadium.d.ts +17 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/state.d.ts +30 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/types.d.ts +55 -0
- package/dist/types/vendor/mermaid-ascii/ascii/types.d.ts +206 -0
- package/dist/types/vendor/mermaid-ascii/ascii/validate.d.ts +51 -0
- package/dist/types/vendor/mermaid-ascii/ascii/xychart.d.ts +2 -0
- package/dist/types/vendor/mermaid-ascii/class/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/class/types.d.ts +102 -0
- package/dist/types/vendor/mermaid-ascii/er/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/er/types.d.ts +76 -0
- package/dist/types/vendor/mermaid-ascii/index.d.ts +1 -0
- package/dist/types/vendor/mermaid-ascii/multiline-utils.d.ts +9 -0
- package/dist/types/vendor/mermaid-ascii/parser.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/sequence/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/sequence/types.d.ts +130 -0
- package/dist/types/vendor/mermaid-ascii/text-metrics.d.ts +21 -0
- package/dist/types/vendor/mermaid-ascii/types.d.ts +114 -0
- package/dist/types/vendor/mermaid-ascii/xychart/colors.d.ts +25 -0
- package/dist/types/vendor/mermaid-ascii/xychart/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/xychart/types.d.ts +145 -0
- package/dist/types/version.d.ts +18 -0
- package/dist/types/vterm/buffer.d.ts +99 -0
- package/dist/types/vterm/terminal.d.ts +44 -0
- package/dist/types/vterm.d.ts +8 -0
- package/dist/types/which.d.ts +37 -0
- package/dist/types/worker-host.d.ts +51 -0
- package/dist/types/xml.d.ts +31 -0
- package/package.json +59 -0
- package/src/abortable.ts +109 -0
- package/src/acp/connection.ts +344 -0
- package/src/acp/protocol.ts +466 -0
- package/src/acp/schema.ts +160 -0
- package/src/acp/stream.ts +82 -0
- package/src/acp/transport.ts +213 -0
- package/src/acp.ts +6 -0
- package/src/async.ts +91 -0
- package/src/binary.ts +50 -0
- package/src/browsers.ts +501 -0
- package/src/chalk.ts +312 -0
- package/src/cli.ts +529 -0
- package/src/color.ts +302 -0
- package/src/dates.ts +194 -0
- package/src/dirs.ts +1026 -0
- package/src/docx/converter.ts +681 -0
- package/src/docx/xml.ts +166 -0
- package/src/docx/zip.ts +87 -0
- package/src/docx.ts +20 -0
- package/src/dom/core.ts +1254 -0
- package/src/dom/parser.ts +370 -0
- package/src/dom/selector.ts +290 -0
- package/src/dom.ts +33 -0
- package/src/env.ts +400 -0
- package/src/fetch-retry.ts +379 -0
- package/src/file-lock.ts +69 -0
- package/src/format.ts +113 -0
- package/src/frontmatter.ts +205 -0
- package/src/fs-error.ts +56 -0
- package/src/glob.ts +189 -0
- package/src/headers.ts +167 -0
- package/src/index.ts +59 -0
- package/src/json-parse.ts +821 -0
- package/src/json.ts +23 -0
- package/src/logger/rotating-file.ts +149 -0
- package/src/logger.ts +798 -0
- package/src/loop-phase.ts +49 -0
- package/src/lru.ts +185 -0
- package/src/marked/core.ts +1576 -0
- package/src/marked.ts +2 -0
- package/src/mermaid-ascii.ts +31 -0
- package/src/mime.ts +159 -0
- package/src/module-timer.ts +148 -0
- package/src/path-tree.ts +147 -0
- package/src/path.ts +28 -0
- package/src/peek-file.ts +188 -0
- package/src/postmortem.ts +433 -0
- package/src/process-name.ts +57 -0
- package/src/procmgr.ts +247 -0
- package/src/prompt.ts +545 -0
- package/src/ptree.ts +412 -0
- package/src/readability/readability.ts +533 -0
- package/src/readability/readerable.ts +51 -0
- package/src/readability/types.ts +72 -0
- package/src/readability.ts +11 -0
- package/src/ring.ts +169 -0
- package/src/runtime-install.ts +393 -0
- package/src/sanitize-text.ts +96 -0
- package/src/snowflake.ts +121 -0
- package/src/stderr-guard.ts +155 -0
- package/src/stream.ts +454 -0
- package/src/tab-spacing.ts +336 -0
- package/src/temp.ts +134 -0
- package/src/template.ts +586 -0
- package/src/timing-buffer.ts +47 -0
- package/src/tls-fetch.ts +178 -0
- package/src/turndown/gfm.ts +106 -0
- package/src/turndown/html.ts +257 -0
- package/src/turndown/service.ts +334 -0
- package/src/turndown/types.ts +81 -0
- package/src/turndown.ts +5 -0
- package/src/type-guards.ts +17 -0
- package/src/vendor/mermaid-ascii/NOTICE +33 -0
- package/src/vendor/mermaid-ascii/ascii/ansi.ts +409 -0
- package/src/vendor/mermaid-ascii/ascii/canvas.ts +476 -0
- package/src/vendor/mermaid-ascii/ascii/class-diagram.ts +699 -0
- package/src/vendor/mermaid-ascii/ascii/converter.ts +271 -0
- package/src/vendor/mermaid-ascii/ascii/draw.ts +1382 -0
- package/src/vendor/mermaid-ascii/ascii/edge-bundling.ts +328 -0
- package/src/vendor/mermaid-ascii/ascii/edge-routing.ts +297 -0
- package/src/vendor/mermaid-ascii/ascii/er-diagram.ts +441 -0
- package/src/vendor/mermaid-ascii/ascii/grid.ts +578 -0
- package/src/vendor/mermaid-ascii/ascii/index.ts +187 -0
- package/src/vendor/mermaid-ascii/ascii/multiline-utils.ts +78 -0
- package/src/vendor/mermaid-ascii/ascii/pathfinder.ts +277 -0
- package/src/vendor/mermaid-ascii/ascii/sequence.ts +460 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/circle.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/corners.ts +127 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/diamond.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/hexagon.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/index.ts +101 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/rectangle.ts +175 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/rounded.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/special.ts +296 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/stadium.ts +114 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/state.ts +192 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/types.ts +73 -0
- package/src/vendor/mermaid-ascii/ascii/types.ts +273 -0
- package/src/vendor/mermaid-ascii/ascii/validate.ts +120 -0
- package/src/vendor/mermaid-ascii/ascii/xychart.ts +875 -0
- package/src/vendor/mermaid-ascii/class/parser.ts +290 -0
- package/src/vendor/mermaid-ascii/class/types.ts +121 -0
- package/src/vendor/mermaid-ascii/er/parser.ts +181 -0
- package/src/vendor/mermaid-ascii/er/types.ts +91 -0
- package/src/vendor/mermaid-ascii/index.ts +14 -0
- package/src/vendor/mermaid-ascii/multiline-utils.ts +30 -0
- package/src/vendor/mermaid-ascii/parser.ts +645 -0
- package/src/vendor/mermaid-ascii/sequence/parser.ts +207 -0
- package/src/vendor/mermaid-ascii/sequence/types.ts +146 -0
- package/src/vendor/mermaid-ascii/text-metrics.ts +71 -0
- package/src/vendor/mermaid-ascii/types.ts +164 -0
- package/src/vendor/mermaid-ascii/xychart/colors.ts +140 -0
- package/src/vendor/mermaid-ascii/xychart/parser.ts +115 -0
- package/src/vendor/mermaid-ascii/xychart/types.ts +150 -0
- package/src/version.ts +99 -0
- package/src/vterm/buffer.ts +218 -0
- package/src/vterm/terminal.ts +773 -0
- package/src/vterm.ts +8 -0
- package/src/which.ts +234 -0
- package/src/worker-host.ts +100 -0
- package/src/xml.ts +313 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import type { NodeShape } from '../types.js';
|
|
2
|
+
export type { NodeShape };
|
|
3
|
+
/**
|
|
4
|
+
* Shape type for ASCII rendering — maps parser shapes to ASCII renderers.
|
|
5
|
+
* Most shapes from the parser are supported, with fallback to 'rectangle'.
|
|
6
|
+
*/
|
|
7
|
+
export type AsciiNodeShape = NodeShape;
|
|
8
|
+
/** Logical grid coordinate — nodes occupy 3x3 blocks on this grid. */
|
|
9
|
+
export interface GridCoord {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
}
|
|
13
|
+
/** Character-level coordinate on the 2D text canvas. */
|
|
14
|
+
export interface DrawingCoord {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Direction constants model positions on a node's 3x3 grid block.
|
|
20
|
+
* Each node occupies grid cells [x..x+2, y..y+2].
|
|
21
|
+
* Directions are offsets into that block, used for edge attachment points.
|
|
22
|
+
*
|
|
23
|
+
* (0,0) UL (1,0) Up (2,0) UR
|
|
24
|
+
* (0,1) Left (1,1) Mid (2,1) Right
|
|
25
|
+
* (0,2) LL (1,2) Down (2,2) LR
|
|
26
|
+
*/
|
|
27
|
+
export interface Direction {
|
|
28
|
+
readonly x: number;
|
|
29
|
+
readonly y: number;
|
|
30
|
+
}
|
|
31
|
+
export declare const Up: Direction;
|
|
32
|
+
export declare const Down: Direction;
|
|
33
|
+
export declare const Left: Direction;
|
|
34
|
+
export declare const Right: Direction;
|
|
35
|
+
export declare const UpperRight: Direction;
|
|
36
|
+
export declare const UpperLeft: Direction;
|
|
37
|
+
export declare const LowerRight: Direction;
|
|
38
|
+
export declare const LowerLeft: Direction;
|
|
39
|
+
export declare const Middle: Direction;
|
|
40
|
+
/** All named directions for iteration. */
|
|
41
|
+
export declare const ALL_DIRECTIONS: readonly Direction[];
|
|
42
|
+
/**
|
|
43
|
+
* 2D text canvas — column-major (canvas[x][y]).
|
|
44
|
+
* Each cell holds a single character (or space).
|
|
45
|
+
*/
|
|
46
|
+
export type Canvas = string[][];
|
|
47
|
+
/** A node in the ASCII graph, positioned on the grid. */
|
|
48
|
+
export interface AsciiNode {
|
|
49
|
+
/** Unique identity key — the original node ID from the parser (e.g. "A", "B"). */
|
|
50
|
+
name: string;
|
|
51
|
+
/** Human-readable label for rendering inside the box (e.g. "Web Server"). */
|
|
52
|
+
displayLabel: string;
|
|
53
|
+
/** Node shape from the parser (e.g. "rectangle", "diamond", "circle"). */
|
|
54
|
+
shape: AsciiNodeShape;
|
|
55
|
+
index: number;
|
|
56
|
+
gridCoord: GridCoord | null;
|
|
57
|
+
drawingCoord: DrawingCoord | null;
|
|
58
|
+
drawing: Canvas | null;
|
|
59
|
+
drawn: boolean;
|
|
60
|
+
styleClassName: string;
|
|
61
|
+
styleClass: AsciiStyleClass;
|
|
62
|
+
}
|
|
63
|
+
/** Style class for colored node text (ported from Go's classDef). */
|
|
64
|
+
export interface AsciiStyleClass {
|
|
65
|
+
name: string;
|
|
66
|
+
styles: Record<string, string>;
|
|
67
|
+
}
|
|
68
|
+
/** Edge line style for ASCII rendering. */
|
|
69
|
+
export type AsciiEdgeStyle = 'solid' | 'dotted' | 'thick';
|
|
70
|
+
/** An edge in the ASCII graph, with a routed path. */
|
|
71
|
+
export interface AsciiEdge {
|
|
72
|
+
from: AsciiNode;
|
|
73
|
+
to: AsciiNode;
|
|
74
|
+
text: string;
|
|
75
|
+
path: GridCoord[];
|
|
76
|
+
labelLine: GridCoord[];
|
|
77
|
+
startDir: Direction;
|
|
78
|
+
endDir: Direction;
|
|
79
|
+
/** Line style: solid (default), dotted (-.->) or thick (==>) */
|
|
80
|
+
style: AsciiEdgeStyle;
|
|
81
|
+
/** Whether to render an arrowhead at the start (source end) of the edge */
|
|
82
|
+
hasArrowStart: boolean;
|
|
83
|
+
/** Whether to render an arrowhead at the end (target end) of the edge */
|
|
84
|
+
hasArrowEnd: boolean;
|
|
85
|
+
/** Bundle this edge belongs to (if any). Set during bundling analysis. */
|
|
86
|
+
bundle?: EdgeBundle;
|
|
87
|
+
/**
|
|
88
|
+
* For bundled edges: path from source/target to the junction point.
|
|
89
|
+
* The full visual path is: pathToJunction + bundle.sharedPath (for fan-in)
|
|
90
|
+
* or bundle.sharedPath + pathToJunction (for fan-out).
|
|
91
|
+
*/
|
|
92
|
+
pathToJunction?: GridCoord[];
|
|
93
|
+
}
|
|
94
|
+
/** A subgraph container with bounding box for rendering. */
|
|
95
|
+
export interface AsciiSubgraph {
|
|
96
|
+
name: string;
|
|
97
|
+
nodes: AsciiNode[];
|
|
98
|
+
parent: AsciiSubgraph | null;
|
|
99
|
+
children: AsciiSubgraph[];
|
|
100
|
+
minX: number;
|
|
101
|
+
minY: number;
|
|
102
|
+
maxX: number;
|
|
103
|
+
maxY: number;
|
|
104
|
+
/** Optional direction override for layout within this subgraph (LR or TD). */
|
|
105
|
+
direction?: 'LR' | 'TD';
|
|
106
|
+
}
|
|
107
|
+
/** Configuration for ASCII rendering. */
|
|
108
|
+
export interface AsciiConfig {
|
|
109
|
+
/** true = ASCII chars (+,-,|), false = Unicode box-drawing (┌,─,│). Default: false */
|
|
110
|
+
useAscii: boolean;
|
|
111
|
+
/** Horizontal spacing between nodes. Default: 5 */
|
|
112
|
+
paddingX: number;
|
|
113
|
+
/** Vertical spacing between nodes. Default: 5 */
|
|
114
|
+
paddingY: number;
|
|
115
|
+
/** Padding inside node boxes. Default: 1 */
|
|
116
|
+
boxBorderPadding: number;
|
|
117
|
+
/** Graph direction: "LR" or "TD". */
|
|
118
|
+
graphDirection: 'LR' | 'TD';
|
|
119
|
+
}
|
|
120
|
+
/** Full ASCII graph state used during layout and rendering. */
|
|
121
|
+
export interface AsciiGraph {
|
|
122
|
+
nodes: AsciiNode[];
|
|
123
|
+
edges: AsciiEdge[];
|
|
124
|
+
canvas: Canvas;
|
|
125
|
+
/** Role canvas — tracks the role of each character for colored output. */
|
|
126
|
+
roleCanvas: RoleCanvas;
|
|
127
|
+
/** Grid occupancy map — maps "x,y" keys to node references. */
|
|
128
|
+
grid: Map<string, AsciiNode>;
|
|
129
|
+
columnWidth: Map<number, number>;
|
|
130
|
+
rowHeight: Map<number, number>;
|
|
131
|
+
subgraphs: AsciiSubgraph[];
|
|
132
|
+
config: AsciiConfig;
|
|
133
|
+
/** Offset applied to all drawing coords to accommodate subgraph borders. */
|
|
134
|
+
offsetX: number;
|
|
135
|
+
offsetY: number;
|
|
136
|
+
/** Edge bundles for parallel link visualization. Set during bundling analysis. */
|
|
137
|
+
bundles: EdgeBundle[];
|
|
138
|
+
}
|
|
139
|
+
export declare function gridCoordEquals(a: GridCoord, b: GridCoord): boolean;
|
|
140
|
+
export declare function drawingCoordEquals(a: DrawingCoord, b: DrawingCoord): boolean;
|
|
141
|
+
/** Apply a direction offset to a grid coordinate (move into the 3x3 block). */
|
|
142
|
+
export declare function gridCoordDirection(c: GridCoord, dir: Direction): GridCoord;
|
|
143
|
+
/** Key for storing GridCoord in a Map. */
|
|
144
|
+
export declare function gridKey(c: GridCoord): string;
|
|
145
|
+
/** Default empty style class. */
|
|
146
|
+
export declare const EMPTY_STYLE: AsciiStyleClass;
|
|
147
|
+
/**
|
|
148
|
+
* Role of a character in the ASCII diagram, used for theming.
|
|
149
|
+
* Each role maps to a different color when colors are enabled.
|
|
150
|
+
*/
|
|
151
|
+
export type CharRole = 'text' | 'border' | 'line' | 'arrow' | 'corner' | 'junction';
|
|
152
|
+
/**
|
|
153
|
+
* Role canvas — parallel to Canvas, tracks the role of each character.
|
|
154
|
+
* Same column-major structure: roleCanvas[x][y] gives the role at (x, y).
|
|
155
|
+
* null means the character has no role (whitespace).
|
|
156
|
+
*/
|
|
157
|
+
export type RoleCanvas = (CharRole | null)[][];
|
|
158
|
+
/**
|
|
159
|
+
* Theme colors for ASCII output — hex color strings.
|
|
160
|
+
* Derived from the SVG theme system for visual consistency.
|
|
161
|
+
*/
|
|
162
|
+
export interface AsciiTheme {
|
|
163
|
+
/** Text color (node labels, edge labels) */
|
|
164
|
+
fg: string;
|
|
165
|
+
/** Box border color (node borders, subgraph borders) */
|
|
166
|
+
border: string;
|
|
167
|
+
/** Edge line color (paths between nodes) */
|
|
168
|
+
line: string;
|
|
169
|
+
/** Arrowhead color (▲▼◄► or ^v<>) */
|
|
170
|
+
arrow: string;
|
|
171
|
+
/** Theme accent color (optional, used by xycharts for series 0) */
|
|
172
|
+
accent?: string;
|
|
173
|
+
/** Background color (optional, used by xycharts for dark-mode-aware shading) */
|
|
174
|
+
bg?: string;
|
|
175
|
+
/** Corner character color (optional, defaults to line) */
|
|
176
|
+
corner?: string;
|
|
177
|
+
/** Junction character color (optional, defaults to border) */
|
|
178
|
+
junction?: string;
|
|
179
|
+
}
|
|
180
|
+
/** Color mode for output. */
|
|
181
|
+
export type ColorMode = 'none' | 'ansi16' | 'ansi256' | 'truecolor' | 'html';
|
|
182
|
+
/**
|
|
183
|
+
* Edge bundle — groups edges that share a common source or target.
|
|
184
|
+
* Used to visually merge parallel links before they reach the shared node.
|
|
185
|
+
*
|
|
186
|
+
* For fan-in (A & B --> C): multiple sources converge to one target.
|
|
187
|
+
* For fan-out (A --> B & C): one source diverges to multiple targets.
|
|
188
|
+
*/
|
|
189
|
+
export interface EdgeBundle {
|
|
190
|
+
/** Bundle type: fan-in = many→one, fan-out = one→many */
|
|
191
|
+
type: 'fan-in' | 'fan-out';
|
|
192
|
+
/** Edges in this bundle */
|
|
193
|
+
edges: AsciiEdge[];
|
|
194
|
+
/** The common node (target for fan-in, source for fan-out) */
|
|
195
|
+
sharedNode: AsciiNode;
|
|
196
|
+
/** The non-shared nodes (sources for fan-in, targets for fan-out) */
|
|
197
|
+
otherNodes: AsciiNode[];
|
|
198
|
+
/** Junction point where edges merge/split — set during routing */
|
|
199
|
+
junctionPoint: GridCoord | null;
|
|
200
|
+
/** Path from junction to shared node (drawn once for all edges) */
|
|
201
|
+
sharedPath: GridCoord[];
|
|
202
|
+
/** Direction when entering/exiting the junction */
|
|
203
|
+
junctionDir: Direction;
|
|
204
|
+
/** Direction when entering/exiting the shared node */
|
|
205
|
+
sharedNodeDir: Direction;
|
|
206
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ASCII Rendering Validation Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides validation functions for ASCII diagram output,
|
|
5
|
+
* including diagonal line detection to ensure orthogonal-only routing.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Characters that represent diagonal lines in ASCII and Unicode modes.
|
|
9
|
+
* These should never appear in properly rendered diagrams.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DIAGONAL_CHARS: {
|
|
12
|
+
readonly ascii: readonly ['/', '\\'];
|
|
13
|
+
readonly unicode: readonly ['╱', '╲'];
|
|
14
|
+
readonly all: readonly ['/', '\\', '╱', '╲'];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Position of a diagonal character in ASCII output.
|
|
18
|
+
*/
|
|
19
|
+
export interface DiagonalPosition {
|
|
20
|
+
line: number;
|
|
21
|
+
col: number;
|
|
22
|
+
char: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Check if ASCII output contains any diagonal line characters.
|
|
26
|
+
* Returns true if diagonals are found (which is an error condition).
|
|
27
|
+
*
|
|
28
|
+
* @param asciiOutput - The rendered ASCII diagram string
|
|
29
|
+
* @returns true if diagonal characters are present, false otherwise
|
|
30
|
+
*/
|
|
31
|
+
export declare function hasDiagonalLines(asciiOutput: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Find all diagonal line character positions in ASCII output.
|
|
34
|
+
* Useful for debugging when diagonals are detected.
|
|
35
|
+
*
|
|
36
|
+
* Skips diagonal characters that appear inside node labels (between box borders).
|
|
37
|
+
* This prevents false positives from labels like "feature/auth" or "release/1.0".
|
|
38
|
+
*
|
|
39
|
+
* @param asciiOutput - The rendered ASCII diagram string
|
|
40
|
+
* @returns Array of positions where diagonal characters were found
|
|
41
|
+
*/
|
|
42
|
+
export declare function findDiagonalLines(asciiOutput: string): DiagonalPosition[];
|
|
43
|
+
/**
|
|
44
|
+
* Assert that ASCII output contains no diagonal lines.
|
|
45
|
+
* Throws an error with detailed position information if diagonals are found.
|
|
46
|
+
*
|
|
47
|
+
* @param asciiOutput - The rendered ASCII diagram string
|
|
48
|
+
* @param context - Optional context string for error message (e.g., diagram name)
|
|
49
|
+
* @throws Error if diagonal characters are present
|
|
50
|
+
*/
|
|
51
|
+
export declare function assertNoDiagonals(asciiOutput: string, context?: string): void;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/** Parsed class diagram — logical structure from mermaid text */
|
|
2
|
+
export interface ClassDiagram {
|
|
3
|
+
/** All class definitions */
|
|
4
|
+
classes: ClassNode[];
|
|
5
|
+
/** Relationships between classes */
|
|
6
|
+
relationships: ClassRelationship[];
|
|
7
|
+
/** Optional namespace groupings */
|
|
8
|
+
namespaces: ClassNamespace[];
|
|
9
|
+
}
|
|
10
|
+
export interface ClassNode {
|
|
11
|
+
id: string;
|
|
12
|
+
label: string;
|
|
13
|
+
/** Annotation like <<interface>>, <<abstract>>, <<service>>, <<enumeration>> */
|
|
14
|
+
annotation?: string;
|
|
15
|
+
/** Class attributes (fields/properties) */
|
|
16
|
+
attributes: ClassMember[];
|
|
17
|
+
/** Class methods (functions) */
|
|
18
|
+
methods: ClassMember[];
|
|
19
|
+
}
|
|
20
|
+
export interface ClassMember {
|
|
21
|
+
/** Visibility: + public, - private, # protected, ~ package */
|
|
22
|
+
visibility: '+' | '-' | '#' | '~' | '';
|
|
23
|
+
/** Member name */
|
|
24
|
+
name: string;
|
|
25
|
+
/** Type annotation (e.g., "String", "int", "void") */
|
|
26
|
+
type?: string;
|
|
27
|
+
/** Whether the member is static (underlined in UML) */
|
|
28
|
+
isStatic?: boolean;
|
|
29
|
+
/** Whether the member is abstract (italic in UML) */
|
|
30
|
+
isAbstract?: boolean;
|
|
31
|
+
/** Whether the member is a method (renders with parentheses) */
|
|
32
|
+
isMethod?: boolean;
|
|
33
|
+
/** Method parameters (e.g., "data", "key, val") — only for methods */
|
|
34
|
+
params?: string;
|
|
35
|
+
}
|
|
36
|
+
/** Relationship types following UML conventions */
|
|
37
|
+
export type RelationshipType = 'inheritance' | 'composition' | 'aggregation' | 'association' | 'dependency' | 'realization';
|
|
38
|
+
export interface ClassRelationship {
|
|
39
|
+
from: string;
|
|
40
|
+
to: string;
|
|
41
|
+
type: RelationshipType;
|
|
42
|
+
/**
|
|
43
|
+
* Which end of the relationship line has the UML marker (triangle, diamond, arrow).
|
|
44
|
+
* Determined by the arrow syntax direction:
|
|
45
|
+
* - Prefix markers like `<|--`, `*--`, `o--` → 'from' (marker on left/from side)
|
|
46
|
+
* - Suffix markers like `..|>`, `-->`, `..>`, `--*`, `--o` → 'to' (marker on right/to side)
|
|
47
|
+
*/
|
|
48
|
+
markerAt: 'from' | 'to';
|
|
49
|
+
/** Label on the relationship line */
|
|
50
|
+
label?: string;
|
|
51
|
+
/** Cardinality at the "from" end (e.g., "1", "*", "0..1") */
|
|
52
|
+
fromCardinality?: string;
|
|
53
|
+
/** Cardinality at the "to" end */
|
|
54
|
+
toCardinality?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface ClassNamespace {
|
|
57
|
+
name: string;
|
|
58
|
+
classIds: string[];
|
|
59
|
+
}
|
|
60
|
+
export interface PositionedClassDiagram {
|
|
61
|
+
width: number;
|
|
62
|
+
height: number;
|
|
63
|
+
classes: PositionedClassNode[];
|
|
64
|
+
relationships: PositionedClassRelationship[];
|
|
65
|
+
}
|
|
66
|
+
export interface PositionedClassNode {
|
|
67
|
+
id: string;
|
|
68
|
+
label: string;
|
|
69
|
+
annotation?: string;
|
|
70
|
+
attributes: ClassMember[];
|
|
71
|
+
methods: ClassMember[];
|
|
72
|
+
x: number;
|
|
73
|
+
y: number;
|
|
74
|
+
width: number;
|
|
75
|
+
height: number;
|
|
76
|
+
/** Height of the header section (name + annotation) */
|
|
77
|
+
headerHeight: number;
|
|
78
|
+
/** Height of the attributes section */
|
|
79
|
+
attrHeight: number;
|
|
80
|
+
/** Height of the methods section */
|
|
81
|
+
methodHeight: number;
|
|
82
|
+
}
|
|
83
|
+
export interface PositionedClassRelationship {
|
|
84
|
+
from: string;
|
|
85
|
+
to: string;
|
|
86
|
+
type: RelationshipType;
|
|
87
|
+
/** Which end of the line has the UML marker — propagated from ClassRelationship */
|
|
88
|
+
markerAt: 'from' | 'to';
|
|
89
|
+
label?: string;
|
|
90
|
+
fromCardinality?: string;
|
|
91
|
+
toCardinality?: string;
|
|
92
|
+
/** Path points from source to target */
|
|
93
|
+
points: Array<{
|
|
94
|
+
x: number;
|
|
95
|
+
y: number;
|
|
96
|
+
}>;
|
|
97
|
+
/** Dagre-computed label center position (avoids overlaps between nearby edges) */
|
|
98
|
+
labelPosition?: {
|
|
99
|
+
x: number;
|
|
100
|
+
y: number;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** Parsed ER diagram — logical structure from mermaid text */
|
|
2
|
+
export interface ErDiagram {
|
|
3
|
+
/** All entity definitions */
|
|
4
|
+
entities: ErEntity[];
|
|
5
|
+
/** Relationships between entities */
|
|
6
|
+
relationships: ErRelationship[];
|
|
7
|
+
}
|
|
8
|
+
export interface ErEntity {
|
|
9
|
+
id: string;
|
|
10
|
+
/** Display name (same as id unless aliased) */
|
|
11
|
+
label: string;
|
|
12
|
+
/** Entity attributes (columns) */
|
|
13
|
+
attributes: ErAttribute[];
|
|
14
|
+
}
|
|
15
|
+
export interface ErAttribute {
|
|
16
|
+
/** Data type (string, int, varchar, etc.) */
|
|
17
|
+
type: string;
|
|
18
|
+
/** Attribute name */
|
|
19
|
+
name: string;
|
|
20
|
+
/** Key constraints: PK, FK, UK */
|
|
21
|
+
keys: Array<'PK' | 'FK' | 'UK'>;
|
|
22
|
+
/** Optional comment */
|
|
23
|
+
comment?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Cardinality notation (crow's foot):
|
|
27
|
+
* 'one' || exactly one
|
|
28
|
+
* 'zero-one' |o zero or one
|
|
29
|
+
* 'many' }| one or more
|
|
30
|
+
* 'zero-many' o{ zero or more
|
|
31
|
+
*/
|
|
32
|
+
export type Cardinality = 'one' | 'zero-one' | 'many' | 'zero-many';
|
|
33
|
+
export interface ErRelationship {
|
|
34
|
+
entity1: string;
|
|
35
|
+
entity2: string;
|
|
36
|
+
/** Cardinality at entity1's end */
|
|
37
|
+
cardinality1: Cardinality;
|
|
38
|
+
/** Cardinality at entity2's end */
|
|
39
|
+
cardinality2: Cardinality;
|
|
40
|
+
/** Relationship verb/label (e.g., "places", "contains") */
|
|
41
|
+
label: string;
|
|
42
|
+
/** Whether the relationship is identifying (solid line) or non-identifying (dashed) */
|
|
43
|
+
identifying: boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface PositionedErDiagram {
|
|
46
|
+
width: number;
|
|
47
|
+
height: number;
|
|
48
|
+
entities: PositionedErEntity[];
|
|
49
|
+
relationships: PositionedErRelationship[];
|
|
50
|
+
}
|
|
51
|
+
export interface PositionedErEntity {
|
|
52
|
+
id: string;
|
|
53
|
+
label: string;
|
|
54
|
+
attributes: ErAttribute[];
|
|
55
|
+
x: number;
|
|
56
|
+
y: number;
|
|
57
|
+
width: number;
|
|
58
|
+
height: number;
|
|
59
|
+
/** Height of the header row */
|
|
60
|
+
headerHeight: number;
|
|
61
|
+
/** Height per attribute row */
|
|
62
|
+
rowHeight: number;
|
|
63
|
+
}
|
|
64
|
+
export interface PositionedErRelationship {
|
|
65
|
+
entity1: string;
|
|
66
|
+
entity2: string;
|
|
67
|
+
cardinality1: Cardinality;
|
|
68
|
+
cardinality2: Cardinality;
|
|
69
|
+
label: string;
|
|
70
|
+
identifying: boolean;
|
|
71
|
+
/** Path points from entity1 to entity2 */
|
|
72
|
+
points: Array<{
|
|
73
|
+
x: number;
|
|
74
|
+
y: number;
|
|
75
|
+
}>;
|
|
76
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ascii/index.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize label text for terminal ASCII output: strip surrounding quotes,
|
|
3
|
+
* convert <br> tags and literal newline escapes to newlines, and reduce
|
|
4
|
+
* inline formatting (HTML bold/italic/underline/strike tags and the markdown
|
|
5
|
+
* bold, italic, and strikethrough markers) to plain text. The ASCII renderer
|
|
6
|
+
* has no styled spans, so preserving the markup would print raw tags and
|
|
7
|
+
* markers inside node boxes.
|
|
8
|
+
*/
|
|
9
|
+
export declare function normalizeBrTags(label: string): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MermaidGraph } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parse Mermaid text into a logical graph structure.
|
|
4
|
+
* Auto-detects diagram type (flowchart or state diagram).
|
|
5
|
+
* Throws on invalid/unsupported input.
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseMermaid(text: string): MermaidGraph;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/** Parsed sequence diagram — logical structure from mermaid text */
|
|
2
|
+
export interface SequenceDiagram {
|
|
3
|
+
/** Ordered list of actors/participants */
|
|
4
|
+
actors: Actor[];
|
|
5
|
+
/** Messages between actors in chronological order */
|
|
6
|
+
messages: Message[];
|
|
7
|
+
/** Structural blocks (loop, alt, opt, par, critical) */
|
|
8
|
+
blocks: Block[];
|
|
9
|
+
/** Notes attached to actors */
|
|
10
|
+
notes: Note[];
|
|
11
|
+
}
|
|
12
|
+
export interface Actor {
|
|
13
|
+
id: string;
|
|
14
|
+
label: string;
|
|
15
|
+
/** 'participant' renders as a box, 'actor' renders as a stick figure */
|
|
16
|
+
type: 'participant' | 'actor';
|
|
17
|
+
}
|
|
18
|
+
export interface Message {
|
|
19
|
+
from: string;
|
|
20
|
+
to: string;
|
|
21
|
+
label: string;
|
|
22
|
+
/** Arrow style: solid line or dashed line */
|
|
23
|
+
lineStyle: 'solid' | 'dashed';
|
|
24
|
+
/** Arrow head: filled (closed) or open */
|
|
25
|
+
arrowHead: 'filled' | 'open';
|
|
26
|
+
/** Activate the target lifeline (+) */
|
|
27
|
+
activate?: boolean;
|
|
28
|
+
/** Deactivate the source lifeline (-) */
|
|
29
|
+
deactivate?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface Block {
|
|
32
|
+
/** Block type keyword */
|
|
33
|
+
type: 'loop' | 'alt' | 'opt' | 'par' | 'critical' | 'break' | 'rect';
|
|
34
|
+
/** Label for the block header */
|
|
35
|
+
label: string;
|
|
36
|
+
/** Index of the first message inside this block */
|
|
37
|
+
startIndex: number;
|
|
38
|
+
/** Index of the last message inside this block (inclusive) */
|
|
39
|
+
endIndex: number;
|
|
40
|
+
/** For alt/par blocks: indices where "else"/"and" dividers appear (message indices) */
|
|
41
|
+
dividers: Array<{
|
|
42
|
+
index: number;
|
|
43
|
+
label: string;
|
|
44
|
+
}>;
|
|
45
|
+
}
|
|
46
|
+
export interface Note {
|
|
47
|
+
/** Which actor(s) the note is attached to */
|
|
48
|
+
actorIds: string[];
|
|
49
|
+
/** Note text content */
|
|
50
|
+
text: string;
|
|
51
|
+
/** Position relative to the actor(s) */
|
|
52
|
+
position: 'left' | 'right' | 'over';
|
|
53
|
+
/** Message index after which this note appears */
|
|
54
|
+
afterIndex: number;
|
|
55
|
+
}
|
|
56
|
+
export interface PositionedSequenceDiagram {
|
|
57
|
+
width: number;
|
|
58
|
+
height: number;
|
|
59
|
+
actors: PositionedActor[];
|
|
60
|
+
lifelines: Lifeline[];
|
|
61
|
+
messages: PositionedMessage[];
|
|
62
|
+
activations: Activation[];
|
|
63
|
+
blocks: PositionedBlock[];
|
|
64
|
+
notes: PositionedNote[];
|
|
65
|
+
}
|
|
66
|
+
export interface PositionedActor {
|
|
67
|
+
id: string;
|
|
68
|
+
label: string;
|
|
69
|
+
type: 'participant' | 'actor';
|
|
70
|
+
/** Center x of the actor box */
|
|
71
|
+
x: number;
|
|
72
|
+
/** Top y of the actor box */
|
|
73
|
+
y: number;
|
|
74
|
+
width: number;
|
|
75
|
+
height: number;
|
|
76
|
+
}
|
|
77
|
+
/** Vertical dashed line from actor to bottom of diagram */
|
|
78
|
+
export interface Lifeline {
|
|
79
|
+
actorId: string;
|
|
80
|
+
x: number;
|
|
81
|
+
topY: number;
|
|
82
|
+
bottomY: number;
|
|
83
|
+
}
|
|
84
|
+
export interface PositionedMessage {
|
|
85
|
+
from: string;
|
|
86
|
+
to: string;
|
|
87
|
+
label: string;
|
|
88
|
+
lineStyle: 'solid' | 'dashed';
|
|
89
|
+
arrowHead: 'filled' | 'open';
|
|
90
|
+
/** Start point (from actor's lifeline) */
|
|
91
|
+
x1: number;
|
|
92
|
+
/** End point (to actor's lifeline) */
|
|
93
|
+
x2: number;
|
|
94
|
+
/** Vertical position */
|
|
95
|
+
y: number;
|
|
96
|
+
/** Whether this is a self-message (same actor) */
|
|
97
|
+
isSelf: boolean;
|
|
98
|
+
}
|
|
99
|
+
/** Narrow rectangle on a lifeline showing active processing */
|
|
100
|
+
export interface Activation {
|
|
101
|
+
actorId: string;
|
|
102
|
+
x: number;
|
|
103
|
+
topY: number;
|
|
104
|
+
bottomY: number;
|
|
105
|
+
width: number;
|
|
106
|
+
}
|
|
107
|
+
export interface PositionedBlock {
|
|
108
|
+
type: Block['type'];
|
|
109
|
+
label: string;
|
|
110
|
+
x: number;
|
|
111
|
+
y: number;
|
|
112
|
+
width: number;
|
|
113
|
+
height: number;
|
|
114
|
+
/** Divider lines within the block (for alt/par) */
|
|
115
|
+
dividers: Array<{
|
|
116
|
+
y: number;
|
|
117
|
+
label: string;
|
|
118
|
+
}>;
|
|
119
|
+
}
|
|
120
|
+
export interface PositionedNote {
|
|
121
|
+
text: string;
|
|
122
|
+
x: number;
|
|
123
|
+
y: number;
|
|
124
|
+
width: number;
|
|
125
|
+
height: number;
|
|
126
|
+
/** Actor IDs this note is attached to (for SVG attribution) */
|
|
127
|
+
actors?: string[];
|
|
128
|
+
/** Note position relative to actors (for SVG attribution) */
|
|
129
|
+
position?: 'left' | 'right' | 'over';
|
|
130
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Placeholder occupying the second cell of a fullwidth glyph on the ASCII
|
|
3
|
+
* canvas. U+0000 cannot appear in parsed Mermaid labels, is treated as
|
|
4
|
+
* occupied label content by canvas merging, and is stripped at
|
|
5
|
+
* serialization time. Invariant: a WIDE_PAD cell always sits immediately
|
|
6
|
+
* right of its lead cell; canvas writes keep the pair atomic.
|
|
7
|
+
*/
|
|
8
|
+
export declare const WIDE_PAD = "\0";
|
|
9
|
+
/**
|
|
10
|
+
* Display width of a string in terminal columns, summed over grapheme
|
|
11
|
+
* clusters so it always equals `toCells(text).length`. ASCII-only strings
|
|
12
|
+
* take a fast path.
|
|
13
|
+
*/
|
|
14
|
+
export declare function displayWidth(text: string): number;
|
|
15
|
+
/**
|
|
16
|
+
* Expand a string into ASCII-canvas cells: each 2-column grapheme cluster
|
|
17
|
+
* is stored whole in one cell and followed by WIDE_PAD, so that
|
|
18
|
+
* `cells.length === displayWidth(text)`. Per-character placement loops can
|
|
19
|
+
* iterate the result with plain cell offsets.
|
|
20
|
+
*/
|
|
21
|
+
export declare function toCells(text: string): string[];
|