@chengchenccc/tui 0.1.1-rc.1
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/dist/autocomplete.d.ts +56 -0
- package/dist/autocomplete.d.ts.map +1 -0
- package/dist/autocomplete.js +647 -0
- package/dist/components/box.d.ts +22 -0
- package/dist/components/box.d.ts.map +1 -0
- package/dist/components/box.js +103 -0
- package/dist/components/card.d.ts +33 -0
- package/dist/components/card.d.ts.map +1 -0
- package/dist/components/card.js +49 -0
- package/dist/components/editor.d.ts +257 -0
- package/dist/components/editor.d.ts.map +1 -0
- package/dist/components/editor.js +1980 -0
- package/dist/components/input.d.ts +37 -0
- package/dist/components/input.d.ts.map +1 -0
- package/dist/components/input.js +389 -0
- package/dist/components/loader.d.ts +33 -0
- package/dist/components/loader.d.ts.map +1 -0
- package/dist/components/loader.js +100 -0
- package/dist/components/markdown.d.ts +108 -0
- package/dist/components/markdown.d.ts.map +1 -0
- package/dist/components/markdown.js +847 -0
- package/dist/components/markdown.test.d.ts +2 -0
- package/dist/components/markdown.test.d.ts.map +1 -0
- package/dist/components/markdown.test.js +81 -0
- package/dist/components/output-block.d.ts +44 -0
- package/dist/components/output-block.d.ts.map +1 -0
- package/dist/components/output-block.js +131 -0
- package/dist/components/select-list.d.ts +50 -0
- package/dist/components/select-list.d.ts.map +1 -0
- package/dist/components/select-list.js +166 -0
- package/dist/components/spacer.d.ts +12 -0
- package/dist/components/spacer.d.ts.map +1 -0
- package/dist/components/spacer.js +22 -0
- package/dist/components/statusline.d.ts +30 -0
- package/dist/components/statusline.d.ts.map +1 -0
- package/dist/components/statusline.js +46 -0
- package/dist/components/text.d.ts +19 -0
- package/dist/components/text.d.ts.map +1 -0
- package/dist/components/text.js +90 -0
- package/dist/components/truncated-text.d.ts +13 -0
- package/dist/components/truncated-text.d.ts.map +1 -0
- package/dist/components/truncated-text.js +50 -0
- package/dist/editor-component.d.ts +39 -0
- package/dist/editor-component.d.ts.map +1 -0
- package/dist/editor-component.js +1 -0
- package/dist/fuzzy.d.ts +16 -0
- package/dist/fuzzy.d.ts.map +1 -0
- package/dist/fuzzy.js +109 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/keybindings.d.ts +193 -0
- package/dist/keybindings.d.ts.map +1 -0
- package/dist/keybindings.js +191 -0
- package/dist/keys.d.ts +184 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +1191 -0
- package/dist/kill-ring.d.ts +28 -0
- package/dist/kill-ring.d.ts.map +1 -0
- package/dist/kill-ring.js +43 -0
- package/dist/mermaid.d.ts +23 -0
- package/dist/mermaid.d.ts.map +1 -0
- package/dist/mermaid.js +77 -0
- package/dist/mouse.d.ts +40 -0
- package/dist/mouse.d.ts.map +1 -0
- package/dist/mouse.js +39 -0
- package/dist/mouse.test.d.ts +2 -0
- package/dist/mouse.test.d.ts.map +1 -0
- package/dist/mouse.test.js +36 -0
- package/dist/native-modifiers.d.ts +3 -0
- package/dist/native-modifiers.d.ts.map +1 -0
- package/dist/native-modifiers.js +52 -0
- package/dist/stdin-buffer.d.ts +50 -0
- package/dist/stdin-buffer.d.ts.map +1 -0
- package/dist/stdin-buffer.js +360 -0
- package/dist/terminal-colors.d.ts +10 -0
- package/dist/terminal-colors.d.ts.map +1 -0
- package/dist/terminal-colors.js +58 -0
- package/dist/terminal-image.d.ts +90 -0
- package/dist/terminal-image.d.ts.map +1 -0
- package/dist/terminal-image.js +375 -0
- package/dist/terminal.d.ts +110 -0
- package/dist/terminal.d.ts.map +1 -0
- package/dist/terminal.js +432 -0
- package/dist/tui-scrollback.test.d.ts +2 -0
- package/dist/tui-scrollback.test.d.ts.map +1 -0
- package/dist/tui-scrollback.test.js +51 -0
- package/dist/tui.d.ts +330 -0
- package/dist/tui.d.ts.map +1 -0
- package/dist/tui.js +1568 -0
- package/dist/undo-stack.d.ts +17 -0
- package/dist/undo-stack.d.ts.map +1 -0
- package/dist/undo-stack.js +24 -0
- package/dist/utils.d.ts +85 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +1066 -0
- package/dist/vendor/mermaid-ascii/ascii/ansi.d.ts +42 -0
- package/dist/vendor/mermaid-ascii/ascii/ansi.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/ansi.js +361 -0
- package/dist/vendor/mermaid-ascii/ascii/canvas.d.ts +90 -0
- package/dist/vendor/mermaid-ascii/ascii/canvas.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/canvas.js +414 -0
- package/dist/vendor/mermaid-ascii/ascii/class-diagram.d.ts +8 -0
- package/dist/vendor/mermaid-ascii/ascii/class-diagram.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/class-diagram.js +623 -0
- package/dist/vendor/mermaid-ascii/ascii/converter.d.ts +13 -0
- package/dist/vendor/mermaid-ascii/ascii/converter.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/converter.js +233 -0
- package/dist/vendor/mermaid-ascii/ascii/draw.d.ts +67 -0
- package/dist/vendor/mermaid-ascii/ascii/draw.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/draw.js +1313 -0
- package/dist/vendor/mermaid-ascii/ascii/edge-bundling.d.ts +49 -0
- package/dist/vendor/mermaid-ascii/ascii/edge-bundling.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/edge-bundling.js +289 -0
- package/dist/vendor/mermaid-ascii/ascii/edge-routing.d.ts +44 -0
- package/dist/vendor/mermaid-ascii/ascii/edge-routing.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/edge-routing.js +302 -0
- package/dist/vendor/mermaid-ascii/ascii/er-diagram.d.ts +8 -0
- package/dist/vendor/mermaid-ascii/ascii/er-diagram.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/er-diagram.js +380 -0
- package/dist/vendor/mermaid-ascii/ascii/grid.d.ts +57 -0
- package/dist/vendor/mermaid-ascii/ascii/grid.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/grid.js +516 -0
- package/dist/vendor/mermaid-ascii/ascii/index.d.ts +66 -0
- package/dist/vendor/mermaid-ascii/ascii/index.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/index.js +133 -0
- package/dist/vendor/mermaid-ascii/ascii/multiline-utils.d.ts +28 -0
- package/dist/vendor/mermaid-ascii/ascii/multiline-utils.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/multiline-utils.js +60 -0
- package/dist/vendor/mermaid-ascii/ascii/pathfinder.d.ts +18 -0
- package/dist/vendor/mermaid-ascii/ascii/pathfinder.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/pathfinder.js +224 -0
- package/dist/vendor/mermaid-ascii/ascii/sequence.d.ts +8 -0
- package/dist/vendor/mermaid-ascii/ascii/sequence.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/sequence.js +416 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/circle.d.ts +12 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/circle.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/circle.js +22 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/corners.d.ts +35 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/corners.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/corners.js +91 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/diamond.d.ts +12 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/diamond.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/diamond.js +22 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/hexagon.d.ts +12 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/hexagon.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/hexagon.js +22 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/index.d.ts +27 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/index.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/index.js +66 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/rectangle.d.ts +32 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/rectangle.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/rectangle.js +149 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/rounded.d.ts +12 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/rounded.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/rounded.js +22 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/special.d.ts +60 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/special.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/special.js +253 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/stadium.d.ts +18 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/stadium.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/stadium.js +103 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/state.d.ts +31 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/state.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/state.js +167 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/types.d.ts +56 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/types.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/shapes/types.js +4 -0
- package/dist/vendor/mermaid-ascii/ascii/types.d.ts +207 -0
- package/dist/vendor/mermaid-ascii/ascii/types.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/types.js +39 -0
- package/dist/vendor/mermaid-ascii/ascii/validate.d.ts +52 -0
- package/dist/vendor/mermaid-ascii/ascii/validate.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/validate.js +97 -0
- package/dist/vendor/mermaid-ascii/ascii/xychart.d.ts +3 -0
- package/dist/vendor/mermaid-ascii/ascii/xychart.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/ascii/xychart.js +719 -0
- package/dist/vendor/mermaid-ascii/class/parser.d.ts +7 -0
- package/dist/vendor/mermaid-ascii/class/parser.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/class/parser.js +265 -0
- package/dist/vendor/mermaid-ascii/class/types.d.ts +103 -0
- package/dist/vendor/mermaid-ascii/class/types.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/class/types.js +7 -0
- package/dist/vendor/mermaid-ascii/er/parser.d.ts +7 -0
- package/dist/vendor/mermaid-ascii/er/parser.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/er/parser.js +162 -0
- package/dist/vendor/mermaid-ascii/er/types.d.ts +77 -0
- package/dist/vendor/mermaid-ascii/er/types.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/er/types.js +7 -0
- package/dist/vendor/mermaid-ascii/index.d.ts +2 -0
- package/dist/vendor/mermaid-ascii/index.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/index.js +13 -0
- package/dist/vendor/mermaid-ascii/multiline-utils.d.ts +10 -0
- package/dist/vendor/mermaid-ascii/multiline-utils.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/multiline-utils.js +29 -0
- package/dist/vendor/mermaid-ascii/parser.d.ts +8 -0
- package/dist/vendor/mermaid-ascii/parser.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/parser.js +558 -0
- package/dist/vendor/mermaid-ascii/sequence/parser.d.ts +7 -0
- package/dist/vendor/mermaid-ascii/sequence/parser.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/sequence/parser.js +182 -0
- package/dist/vendor/mermaid-ascii/sequence/types.d.ts +131 -0
- package/dist/vendor/mermaid-ascii/sequence/types.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/sequence/types.js +7 -0
- package/dist/vendor/mermaid-ascii/text-metrics.d.ts +24 -0
- package/dist/vendor/mermaid-ascii/text-metrics.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/text-metrics.js +69 -0
- package/dist/vendor/mermaid-ascii/types.d.ts +115 -0
- package/dist/vendor/mermaid-ascii/types.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/types.js +4 -0
- package/dist/vendor/mermaid-ascii/xychart/colors.d.ts +26 -0
- package/dist/vendor/mermaid-ascii/xychart/colors.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/xychart/colors.js +145 -0
- package/dist/vendor/mermaid-ascii/xychart/parser.d.ts +7 -0
- package/dist/vendor/mermaid-ascii/xychart/parser.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/xychart/parser.js +105 -0
- package/dist/vendor/mermaid-ascii/xychart/types.d.ts +146 -0
- package/dist/vendor/mermaid-ascii/xychart/types.d.ts.map +1 -0
- package/dist/vendor/mermaid-ascii/xychart/types.js +8 -0
- package/dist/virtual-terminal.d.ts +80 -0
- package/dist/virtual-terminal.d.ts.map +1 -0
- package/dist/virtual-terminal.js +284 -0
- package/dist/word-navigation.d.ts +25 -0
- package/dist/word-navigation.d.ts.map +1 -0
- package/dist/word-navigation.js +97 -0
- package/package.json +38 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// ASCII renderer — MermaidGraph → AsciiGraph converter
|
|
3
|
+
//
|
|
4
|
+
// Bridges the existing TypeScript parser output to the ASCII renderer's
|
|
5
|
+
// internal graph structure. This avoids maintaining a separate parser
|
|
6
|
+
// for ASCII rendering — we reuse parseMermaid() and convert its output.
|
|
7
|
+
// ============================================================================
|
|
8
|
+
import { EMPTY_STYLE } from "./types.js";
|
|
9
|
+
import { mkCanvas, mkRoleCanvas } from "./canvas.js";
|
|
10
|
+
/**
|
|
11
|
+
* Convert a parsed MermaidGraph into an AsciiGraph ready for grid layout.
|
|
12
|
+
*
|
|
13
|
+
* Key mappings:
|
|
14
|
+
* - MermaidGraph.nodes (Map) → ordered AsciiNode[] preserving insertion order
|
|
15
|
+
* - MermaidGraph.edges → AsciiEdge[] with resolved node references
|
|
16
|
+
* - MermaidGraph.subgraphs → AsciiSubgraph[] with parent/child tree
|
|
17
|
+
* - Node labels are used as display names (not raw IDs)
|
|
18
|
+
*/
|
|
19
|
+
export function convertToAsciiGraph(parsed, config) {
|
|
20
|
+
// Build node list preserving Map insertion order
|
|
21
|
+
const nodeMap = new Map();
|
|
22
|
+
let index = 0;
|
|
23
|
+
for (const [id, mNode] of parsed.nodes) {
|
|
24
|
+
const asciiNode = {
|
|
25
|
+
// Use the parser ID as the unique identity key to avoid collisions
|
|
26
|
+
// when multiple nodes share the same label (e.g. A[Web Server], C[Web Server]).
|
|
27
|
+
name: id,
|
|
28
|
+
// The label is used for rendering inside the box.
|
|
29
|
+
displayLabel: mNode.label,
|
|
30
|
+
// Preserve shape from parser for shape-aware rendering
|
|
31
|
+
shape: mNode.shape,
|
|
32
|
+
index,
|
|
33
|
+
gridCoord: null,
|
|
34
|
+
drawingCoord: null,
|
|
35
|
+
drawing: null,
|
|
36
|
+
drawn: false,
|
|
37
|
+
styleClassName: '',
|
|
38
|
+
styleClass: EMPTY_STYLE,
|
|
39
|
+
};
|
|
40
|
+
nodeMap.set(id, asciiNode);
|
|
41
|
+
index++;
|
|
42
|
+
}
|
|
43
|
+
const nodes = [...nodeMap.values()];
|
|
44
|
+
// Build edges with resolved node references
|
|
45
|
+
const edges = [];
|
|
46
|
+
for (const mEdge of parsed.edges) {
|
|
47
|
+
const from = nodeMap.get(mEdge.source);
|
|
48
|
+
const to = nodeMap.get(mEdge.target);
|
|
49
|
+
if (!from || !to)
|
|
50
|
+
continue;
|
|
51
|
+
edges.push({
|
|
52
|
+
from,
|
|
53
|
+
to,
|
|
54
|
+
text: mEdge.label ?? '',
|
|
55
|
+
path: [],
|
|
56
|
+
labelLine: [],
|
|
57
|
+
startDir: { x: 0, y: 0 },
|
|
58
|
+
endDir: { x: 0, y: 0 },
|
|
59
|
+
style: mEdge.style,
|
|
60
|
+
hasArrowStart: mEdge.hasArrowStart,
|
|
61
|
+
hasArrowEnd: mEdge.hasArrowEnd,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
// Convert subgraphs recursively
|
|
65
|
+
const subgraphs = [];
|
|
66
|
+
for (const mSg of parsed.subgraphs) {
|
|
67
|
+
convertSubgraph(mSg, null, nodeMap, subgraphs);
|
|
68
|
+
}
|
|
69
|
+
// Deduplicate subgraph node membership to match Go parser behavior.
|
|
70
|
+
// In Go, a node belongs only to the subgraph where it was FIRST DEFINED.
|
|
71
|
+
// The TS parser adds referenced nodes to all subgraphs they appear in,
|
|
72
|
+
// which causes incorrect bounding boxes when nodes span subgraph boundaries.
|
|
73
|
+
deduplicateSubgraphNodes(parsed.subgraphs, subgraphs, nodeMap, parsed);
|
|
74
|
+
// Apply class definitions
|
|
75
|
+
for (const [nodeId, className] of parsed.classAssignments) {
|
|
76
|
+
const node = nodeMap.get(nodeId);
|
|
77
|
+
const classDef = parsed.classDefs.get(className);
|
|
78
|
+
if (node && classDef) {
|
|
79
|
+
node.styleClassName = className;
|
|
80
|
+
node.styleClass = { name: className, styles: classDef };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
nodes,
|
|
85
|
+
edges,
|
|
86
|
+
canvas: mkCanvas(0, 0),
|
|
87
|
+
roleCanvas: mkRoleCanvas(0, 0),
|
|
88
|
+
grid: new Map(),
|
|
89
|
+
columnWidth: new Map(),
|
|
90
|
+
rowHeight: new Map(),
|
|
91
|
+
subgraphs,
|
|
92
|
+
config,
|
|
93
|
+
offsetX: 0,
|
|
94
|
+
offsetY: 0,
|
|
95
|
+
bundles: [], // Populated by analyzeEdgeBundles() during layout
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Recursively convert a MermaidSubgraph to AsciiSubgraph.
|
|
100
|
+
* Flattens the tree into the subgraphs array while maintaining parent/child references.
|
|
101
|
+
* This matches the Go implementation where all subgraphs are in a flat list
|
|
102
|
+
* but linked via parent/children pointers.
|
|
103
|
+
*/
|
|
104
|
+
function convertSubgraph(mSg, parent, nodeMap, allSubgraphs) {
|
|
105
|
+
// Normalize subgraph direction: BT→TD, RL→LR (same as root graph normalization)
|
|
106
|
+
let normalizedDirection;
|
|
107
|
+
if (mSg.direction) {
|
|
108
|
+
normalizedDirection = (mSg.direction === 'LR' || mSg.direction === 'RL') ? 'LR' : 'TD';
|
|
109
|
+
}
|
|
110
|
+
const sg = {
|
|
111
|
+
name: mSg.label,
|
|
112
|
+
nodes: [],
|
|
113
|
+
parent,
|
|
114
|
+
children: [],
|
|
115
|
+
minX: 0, minY: 0, maxX: 0, maxY: 0,
|
|
116
|
+
direction: normalizedDirection,
|
|
117
|
+
};
|
|
118
|
+
// Resolve node references
|
|
119
|
+
for (const nodeId of mSg.nodeIds) {
|
|
120
|
+
const node = nodeMap.get(nodeId);
|
|
121
|
+
if (node)
|
|
122
|
+
sg.nodes.push(node);
|
|
123
|
+
}
|
|
124
|
+
allSubgraphs.push(sg);
|
|
125
|
+
// Recurse into children
|
|
126
|
+
for (const childMSg of mSg.children) {
|
|
127
|
+
const child = convertSubgraph(childMSg, sg, nodeMap, allSubgraphs);
|
|
128
|
+
sg.children.push(child);
|
|
129
|
+
// Child nodes are also part of parent subgraphs (Go behavior).
|
|
130
|
+
// The Go parser adds nodes to ALL subgraphs in the stack, so a nested
|
|
131
|
+
// node belongs to both the inner and outer subgraph.
|
|
132
|
+
for (const childNode of child.nodes) {
|
|
133
|
+
if (!sg.nodes.includes(childNode)) {
|
|
134
|
+
sg.nodes.push(childNode);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return sg;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Deduplicate subgraph node membership to match Go parser behavior.
|
|
142
|
+
*
|
|
143
|
+
* The Go parser only adds a node to the subgraph that was active when the node
|
|
144
|
+
* was FIRST CREATED. If a node is later referenced inside a different subgraph,
|
|
145
|
+
* it is NOT added to that subgraph. The TS parser is more permissive — it adds
|
|
146
|
+
* referenced nodes to whichever subgraph they appear in.
|
|
147
|
+
*
|
|
148
|
+
* This function fixes the discrepancy by:
|
|
149
|
+
* 1. Walking the edges to determine which nodes were first created inside each subgraph
|
|
150
|
+
* 2. Removing nodes from subgraphs where they weren't first created
|
|
151
|
+
*/
|
|
152
|
+
function deduplicateSubgraphNodes(mermaidSubgraphs, asciiSubgraphs, nodeMap, parsed) {
|
|
153
|
+
// Build a map from MermaidSubgraph to its corresponding AsciiSubgraph.
|
|
154
|
+
// The ordering matches since we convert them in the same order.
|
|
155
|
+
const sgMap = new Map();
|
|
156
|
+
buildSgMap(mermaidSubgraphs, asciiSubgraphs, sgMap);
|
|
157
|
+
// Determine which subgraph each node was "first defined" in.
|
|
158
|
+
// A node is first defined in the subgraph where it first appears as a NEW node
|
|
159
|
+
// in the ordered edge/node list. We approximate this by checking the global
|
|
160
|
+
// node insertion order against subgraph membership.
|
|
161
|
+
const nodeOwner = new Map(); // nodeId → owning subgraph
|
|
162
|
+
// Walk all mermaid subgraphs in document order. For each subgraph,
|
|
163
|
+
// claim nodes that haven't been claimed yet by any previous subgraph.
|
|
164
|
+
function claimNodes(mSg) {
|
|
165
|
+
const asciiSg = sgMap.get(mSg);
|
|
166
|
+
if (!asciiSg)
|
|
167
|
+
return;
|
|
168
|
+
// Recurse into children first (they appear before parent in the Go parser stack,
|
|
169
|
+
// but nodes defined in children are added to parent too — this is handled by
|
|
170
|
+
// the convertSubgraph function which propagates child nodes to parents).
|
|
171
|
+
// For dedup, we process children first so their claims propagate up correctly.
|
|
172
|
+
for (const child of mSg.children) {
|
|
173
|
+
claimNodes(child);
|
|
174
|
+
}
|
|
175
|
+
// Claim unclaimed nodes in this subgraph
|
|
176
|
+
for (const nodeId of mSg.nodeIds) {
|
|
177
|
+
if (!nodeOwner.has(nodeId)) {
|
|
178
|
+
nodeOwner.set(nodeId, asciiSg);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
for (const mSg of mermaidSubgraphs) {
|
|
183
|
+
claimNodes(mSg);
|
|
184
|
+
}
|
|
185
|
+
// Now remove nodes from subgraphs that don't own them.
|
|
186
|
+
// A node should remain in: its owner subgraph + all ancestors of the owner.
|
|
187
|
+
for (const asciiSg of asciiSubgraphs) {
|
|
188
|
+
asciiSg.nodes = asciiSg.nodes.filter(node => {
|
|
189
|
+
// Find this node's ID in the nodeMap
|
|
190
|
+
let nodeId;
|
|
191
|
+
for (const [id, n] of nodeMap) {
|
|
192
|
+
if (n === node) {
|
|
193
|
+
nodeId = id;
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (!nodeId)
|
|
198
|
+
return false;
|
|
199
|
+
const owner = nodeOwner.get(nodeId);
|
|
200
|
+
if (!owner)
|
|
201
|
+
return true; // not in any subgraph claim — keep as-is
|
|
202
|
+
// Keep the node if this subgraph is the owner or an ancestor of the owner
|
|
203
|
+
return isAncestorOrSelf(asciiSg, owner);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/** Check if `candidate` is the same as or an ancestor of `target`. */
|
|
208
|
+
function isAncestorOrSelf(candidate, target) {
|
|
209
|
+
let current = target;
|
|
210
|
+
while (current !== null) {
|
|
211
|
+
if (current === candidate)
|
|
212
|
+
return true;
|
|
213
|
+
current = current.parent;
|
|
214
|
+
}
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
/** Build a mapping from MermaidSubgraph → AsciiSubgraph (matching by position). */
|
|
218
|
+
function buildSgMap(mSgs, aSgs, result) {
|
|
219
|
+
// The asciiSubgraphs array is flat (all subgraphs including nested ones),
|
|
220
|
+
// while mermaidSubgraphs is hierarchical. We need to flatten the mermaid tree
|
|
221
|
+
// in the same order the converter processes them (pre-order DFS).
|
|
222
|
+
const flatMermaid = [];
|
|
223
|
+
function flatten(sgs) {
|
|
224
|
+
for (const sg of sgs) {
|
|
225
|
+
flatMermaid.push(sg);
|
|
226
|
+
flatten(sg.children);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
flatten(mSgs);
|
|
230
|
+
for (let i = 0; i < flatMermaid.length && i < aSgs.length; i++) {
|
|
231
|
+
result.set(flatMermaid[i], aSgs[i]);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Canvas, DrawingCoord, AsciiGraph, AsciiNode, AsciiEdge, AsciiSubgraph, AsciiEdgeStyle } from './types.ts';
|
|
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;
|
|
67
|
+
//# sourceMappingURL=draw.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draw.d.ts","sourceRoot":"","sources":["../../../../src/vendor/mermaid-ascii/ascii/draw.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAChE,MAAM,YAAY,CAAA;AAkBnB;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,CAMnE;AA4ED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,CAElE;AAMD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,MAAM,EAAE,EAAE,EACpB,QAAQ,EAAE,OAAO,EACjB,OAAO,GAAE,MAAU,GAClB,MAAM,CAyER;AAkCD;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CACtB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,YAAY,EAClB,EAAE,EAAE,YAAY,EAChB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,OAAO,EACjB,KAAK,GAAE,cAAwB,GAC9B,YAAY,EAAE,CAmGhB;AAMD;;;;;;GAMG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,SAAS,GACd,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAgDlD;AA0pBD,wCAAwC;AACxC,wBAAgB,eAAe,CAAC,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,CA8B5E;AAED,qFAAqF;AACrF,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CA+B9F;AA0FD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAsHnD"}
|