mermaid2term 0.1.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/README.md +229 -0
- package/bin/mermaid2term.js +2 -0
- package/dist/cli.cjs +1289 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +1287 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +1288 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +301 -0
- package/dist/index.d.ts +301 -0
- package/dist/index.js +1265 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core type definitions for the mermaid2term library
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Grid coordinate - logical positioning in the layout grid
|
|
6
|
+
* Each node occupies a 3x3 grid cell (border + content + border)
|
|
7
|
+
*/
|
|
8
|
+
interface GridCoord {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Drawing coordinate - physical character position in the output canvas
|
|
14
|
+
*/
|
|
15
|
+
interface DrawingCoord {
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Direction for graph layout and edge routing
|
|
21
|
+
*/
|
|
22
|
+
type Direction = 'up' | 'down' | 'left' | 'right';
|
|
23
|
+
/**
|
|
24
|
+
* Graph flow direction
|
|
25
|
+
*/
|
|
26
|
+
type GraphDirection = 'LR' | 'RL' | 'TD' | 'BT';
|
|
27
|
+
/**
|
|
28
|
+
* Shape types for flowchart nodes
|
|
29
|
+
*/
|
|
30
|
+
type NodeShape = 'rect' | 'round' | 'diamond' | 'circle' | 'asymmetric' | 'hexagon' | 'parallelogram' | 'trapezoid' | 'cylinder' | 'subroutine';
|
|
31
|
+
/**
|
|
32
|
+
* A node in the diagram graph
|
|
33
|
+
*/
|
|
34
|
+
interface Node {
|
|
35
|
+
/** Unique identifier */
|
|
36
|
+
id: string;
|
|
37
|
+
/** Display label (may differ from id) */
|
|
38
|
+
label: string;
|
|
39
|
+
/** Visual shape */
|
|
40
|
+
shape: NodeShape;
|
|
41
|
+
/** Style class name (from classDef) */
|
|
42
|
+
styleClass?: string;
|
|
43
|
+
/** Assigned grid position after layout */
|
|
44
|
+
gridCoord?: GridCoord;
|
|
45
|
+
/** Assigned drawing position after coordinate transformation */
|
|
46
|
+
drawingCoord?: DrawingCoord;
|
|
47
|
+
/** Width in characters (calculated from label + padding) */
|
|
48
|
+
width?: number;
|
|
49
|
+
/** Height in characters */
|
|
50
|
+
height?: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Arrow/line style for edges
|
|
54
|
+
*/
|
|
55
|
+
type EdgeStyle = 'solid' | 'dotted' | 'thick';
|
|
56
|
+
/**
|
|
57
|
+
* Arrow head type
|
|
58
|
+
*/
|
|
59
|
+
type ArrowType = 'arrow' | 'open' | 'circle' | 'cross';
|
|
60
|
+
/**
|
|
61
|
+
* An edge connecting two nodes
|
|
62
|
+
*/
|
|
63
|
+
interface Edge {
|
|
64
|
+
/** Source node id */
|
|
65
|
+
from: string;
|
|
66
|
+
/** Target node id */
|
|
67
|
+
to: string;
|
|
68
|
+
/** Optional label on the edge */
|
|
69
|
+
label?: string;
|
|
70
|
+
/** Line style */
|
|
71
|
+
style: EdgeStyle;
|
|
72
|
+
/** Arrow head type at the target end */
|
|
73
|
+
arrowType: ArrowType;
|
|
74
|
+
/** Whether arrow points both ways */
|
|
75
|
+
bidirectional: boolean;
|
|
76
|
+
/** Calculated path through grid after layout */
|
|
77
|
+
path?: GridCoord[];
|
|
78
|
+
/** Starting direction from source node */
|
|
79
|
+
startDirection?: Direction;
|
|
80
|
+
/** Ending direction into target node */
|
|
81
|
+
endDirection?: Direction;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Style class definition (from classDef)
|
|
85
|
+
*/
|
|
86
|
+
interface StyleClass {
|
|
87
|
+
name: string;
|
|
88
|
+
fill?: string;
|
|
89
|
+
stroke?: string;
|
|
90
|
+
color?: string;
|
|
91
|
+
strokeWidth?: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Character set to use for rendering
|
|
95
|
+
*/
|
|
96
|
+
type Charset = 'unicode' | 'ascii';
|
|
97
|
+
/**
|
|
98
|
+
* Options for rendering diagrams
|
|
99
|
+
*/
|
|
100
|
+
interface RenderOptions {
|
|
101
|
+
/** Character set - unicode for nice box drawing, ascii for compatibility */
|
|
102
|
+
charset: Charset;
|
|
103
|
+
/** Maximum output width in characters (0 = unlimited) */
|
|
104
|
+
maxWidth: number;
|
|
105
|
+
/** Horizontal spacing between nodes (in grid units) */
|
|
106
|
+
paddingX: number;
|
|
107
|
+
/** Vertical spacing between nodes (in grid units) */
|
|
108
|
+
paddingY: number;
|
|
109
|
+
/** Padding inside node borders */
|
|
110
|
+
borderPadding: number;
|
|
111
|
+
/** Show debug coordinates overlay */
|
|
112
|
+
showCoords: boolean;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Default render options
|
|
116
|
+
*/
|
|
117
|
+
declare const DEFAULT_RENDER_OPTIONS: RenderOptions;
|
|
118
|
+
/**
|
|
119
|
+
* Supported diagram types
|
|
120
|
+
*/
|
|
121
|
+
type DiagramType = 'flowchart' | 'sequence' | 'class' | 'state' | 'er' | 'unknown';
|
|
122
|
+
/**
|
|
123
|
+
* Base interface for all diagram ASTs
|
|
124
|
+
*/
|
|
125
|
+
interface BaseDiagramAST {
|
|
126
|
+
type: DiagramType;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Result of layout computation
|
|
130
|
+
*/
|
|
131
|
+
interface LayoutResult {
|
|
132
|
+
/** Total width needed */
|
|
133
|
+
width: number;
|
|
134
|
+
/** Total height needed */
|
|
135
|
+
height: number;
|
|
136
|
+
/** Positioned nodes */
|
|
137
|
+
nodes: Node[];
|
|
138
|
+
/** Routed edges */
|
|
139
|
+
edges: Edge[];
|
|
140
|
+
/** Column widths (grid coord -> char width) */
|
|
141
|
+
columnWidths: Map<number, number>;
|
|
142
|
+
/** Row heights (grid coord -> char height) */
|
|
143
|
+
rowHeights: Map<number, number>;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Interface that all diagram type renderers must implement
|
|
147
|
+
*/
|
|
148
|
+
interface DiagramRenderer<T extends BaseDiagramAST = BaseDiagramAST> {
|
|
149
|
+
/** Parse input string into diagram AST */
|
|
150
|
+
parse(input: string): T;
|
|
151
|
+
/** Compute layout positions for all elements */
|
|
152
|
+
layout(ast: T, options: RenderOptions): LayoutResult;
|
|
153
|
+
/** Render laid-out diagram to ASCII string */
|
|
154
|
+
render(layout: LayoutResult, options: RenderOptions): string;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
declare class Canvas {
|
|
158
|
+
private width;
|
|
159
|
+
private height;
|
|
160
|
+
private grid;
|
|
161
|
+
private chars;
|
|
162
|
+
constructor(width: number, height: number, charset?: Charset);
|
|
163
|
+
getWidth(): number;
|
|
164
|
+
getHeight(): number;
|
|
165
|
+
set(x: number, y: number, char: string): void;
|
|
166
|
+
forceSet(x: number, y: number, char: string): void;
|
|
167
|
+
get(x: number, y: number): string;
|
|
168
|
+
drawText(x: number, y: number, text: string): void;
|
|
169
|
+
drawHorizontalLine(x1: number, x2: number, y: number, char?: string): void;
|
|
170
|
+
drawVerticalLine(x: number, y1: number, y2: number, char?: string): void;
|
|
171
|
+
drawBox(x: number, y: number, width: number, height: number): void;
|
|
172
|
+
drawArrow(x: number, y: number, direction: 'up' | 'down' | 'left' | 'right'): void;
|
|
173
|
+
expandTo(newWidth: number, newHeight: number): void;
|
|
174
|
+
merge(other: Canvas, offsetX: number, offsetY: number): void;
|
|
175
|
+
fixJunctions(): void;
|
|
176
|
+
toString(): string;
|
|
177
|
+
static fromCoord(coord: DrawingCoord): {
|
|
178
|
+
x: number;
|
|
179
|
+
y: number;
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
interface BoxChars {
|
|
184
|
+
topLeft: string;
|
|
185
|
+
topRight: string;
|
|
186
|
+
bottomLeft: string;
|
|
187
|
+
bottomRight: string;
|
|
188
|
+
horizontal: string;
|
|
189
|
+
vertical: string;
|
|
190
|
+
}
|
|
191
|
+
interface LineChars {
|
|
192
|
+
horizontal: string;
|
|
193
|
+
vertical: string;
|
|
194
|
+
dottedHorizontal: string;
|
|
195
|
+
dottedVertical: string;
|
|
196
|
+
thickHorizontal: string;
|
|
197
|
+
thickVertical: string;
|
|
198
|
+
}
|
|
199
|
+
interface ArrowChars {
|
|
200
|
+
up: string;
|
|
201
|
+
down: string;
|
|
202
|
+
left: string;
|
|
203
|
+
right: string;
|
|
204
|
+
upOpen: string;
|
|
205
|
+
downOpen: string;
|
|
206
|
+
leftOpen: string;
|
|
207
|
+
rightOpen: string;
|
|
208
|
+
circle: string;
|
|
209
|
+
cross: string;
|
|
210
|
+
}
|
|
211
|
+
interface JunctionChars {
|
|
212
|
+
cross: string;
|
|
213
|
+
leftT: string;
|
|
214
|
+
rightT: string;
|
|
215
|
+
topT: string;
|
|
216
|
+
bottomT: string;
|
|
217
|
+
}
|
|
218
|
+
interface CharacterSet {
|
|
219
|
+
box: BoxChars;
|
|
220
|
+
line: LineChars;
|
|
221
|
+
arrow: ArrowChars;
|
|
222
|
+
junction: JunctionChars;
|
|
223
|
+
}
|
|
224
|
+
declare function getCharacterSet(charset: Charset): CharacterSet;
|
|
225
|
+
declare function mergeJunctionChars(existing: string, incoming: string): string;
|
|
226
|
+
declare function isLineOrJunctionChar(char: string): boolean;
|
|
227
|
+
declare function isJunctionChar(char: string): boolean;
|
|
228
|
+
declare function isHorizontalChar(char: string): boolean;
|
|
229
|
+
declare function isVerticalChar(char: string): boolean;
|
|
230
|
+
declare function connectsLeft(char: string): boolean;
|
|
231
|
+
declare function connectsRight(char: string): boolean;
|
|
232
|
+
declare function connectsUp(char: string): boolean;
|
|
233
|
+
declare function connectsDown(char: string): boolean;
|
|
234
|
+
declare function getJunctionChar(up: boolean, down: boolean, left: boolean, right: boolean, charset: Charset): string;
|
|
235
|
+
|
|
236
|
+
interface FlowchartNode extends Node {
|
|
237
|
+
index: number;
|
|
238
|
+
}
|
|
239
|
+
interface FlowchartEdge extends Edge {
|
|
240
|
+
index: number;
|
|
241
|
+
}
|
|
242
|
+
interface Subgraph {
|
|
243
|
+
id: string;
|
|
244
|
+
label: string;
|
|
245
|
+
nodeIds: string[];
|
|
246
|
+
}
|
|
247
|
+
interface FlowchartAST extends BaseDiagramAST {
|
|
248
|
+
type: 'flowchart';
|
|
249
|
+
direction: GraphDirection;
|
|
250
|
+
nodes: Map<string, FlowchartNode>;
|
|
251
|
+
edges: FlowchartEdge[];
|
|
252
|
+
subgraphs: Subgraph[];
|
|
253
|
+
styleClasses: Map<string, StyleClass>;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
declare function parseFlowchart(input: string): FlowchartAST;
|
|
257
|
+
|
|
258
|
+
declare function renderFlowchart(ast: FlowchartAST, options: RenderOptions): string;
|
|
259
|
+
|
|
260
|
+
interface LayoutedGraph {
|
|
261
|
+
nodes: Map<string, FlowchartNode>;
|
|
262
|
+
edges: FlowchartEdge[];
|
|
263
|
+
backEdges: Set<FlowchartEdge>;
|
|
264
|
+
width: number;
|
|
265
|
+
height: number;
|
|
266
|
+
columnWidths: Map<number, number>;
|
|
267
|
+
rowHeights: Map<number, number>;
|
|
268
|
+
}
|
|
269
|
+
declare function layoutFlowchart(ast: FlowchartAST, options: RenderOptions): LayoutedGraph;
|
|
270
|
+
|
|
271
|
+
type MessageStyle = 'solid' | 'dotted';
|
|
272
|
+
type ArrowStyle = 'filled' | 'open';
|
|
273
|
+
interface Participant {
|
|
274
|
+
id: string;
|
|
275
|
+
alias: string;
|
|
276
|
+
index: number;
|
|
277
|
+
}
|
|
278
|
+
interface Message {
|
|
279
|
+
from: string;
|
|
280
|
+
to: string;
|
|
281
|
+
text: string;
|
|
282
|
+
style: MessageStyle;
|
|
283
|
+
arrowStyle: ArrowStyle;
|
|
284
|
+
index: number;
|
|
285
|
+
}
|
|
286
|
+
interface SequenceAST extends BaseDiagramAST {
|
|
287
|
+
type: 'sequence';
|
|
288
|
+
participants: Map<string, Participant>;
|
|
289
|
+
messages: Message[];
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
declare function parseSequence(input: string): SequenceAST;
|
|
293
|
+
|
|
294
|
+
declare function renderSequence(ast: SequenceAST, options: RenderOptions): string;
|
|
295
|
+
|
|
296
|
+
declare function detectDiagramType(input: string): DiagramType;
|
|
297
|
+
declare function render(input: string, options?: Partial<RenderOptions>): string;
|
|
298
|
+
declare function renderToFlowchart(input: string, options?: Partial<RenderOptions>): string;
|
|
299
|
+
declare function renderToSequence(input: string, options?: Partial<RenderOptions>): string;
|
|
300
|
+
|
|
301
|
+
export { type ArrowChars, type ArrowStyle, type ArrowType, type BaseDiagramAST, type BoxChars, Canvas, type CharacterSet, type Charset, DEFAULT_RENDER_OPTIONS, type DiagramRenderer, type DiagramType, type Direction, type DrawingCoord, type Edge, type EdgeStyle, type FlowchartAST, type FlowchartEdge, type FlowchartNode, type GraphDirection, type GridCoord, type JunctionChars, type LayoutResult, type LineChars, type Message, type MessageStyle, type Node, type NodeShape, type Participant, type RenderOptions, type SequenceAST, type StyleClass, type Subgraph, connectsDown, connectsLeft, connectsRight, connectsUp, detectDiagramType, getCharacterSet, getJunctionChar, isHorizontalChar, isJunctionChar, isLineOrJunctionChar, isVerticalChar, layoutFlowchart, mergeJunctionChars, parseFlowchart, parseSequence, render, renderFlowchart, renderSequence, renderToFlowchart, renderToSequence };
|