flowink 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/LICENSE +21 -0
- package/NOTICE.md +17 -0
- package/README.md +301 -0
- package/dist/errors.d.ts +13 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +3560 -0
- package/dist/index.js.map +7 -0
- package/dist/layout.d.ts +13 -0
- package/dist/parse.d.ts +3 -0
- package/dist/parser/generated.d.ts +3 -0
- package/dist/parser/preprocess.d.ts +11 -0
- package/dist/parser/semantic.d.ts +76 -0
- package/dist/place-labels.d.ts +15 -0
- package/dist/rasterize.d.ts +47 -0
- package/dist/text.d.ts +36 -0
- package/dist/types.d.ts +88 -0
- package/examples/basic.mmd +4 -0
- package/examples/chinese.mmd +2 -0
- package/examples/cycle.mmd +2 -0
- package/examples/decision.mmd +4 -0
- package/examples/hero.mmd +2 -0
- package/examples/subgraph.mmd +5 -0
- package/package.json +71 -0
- package/vendor/mermaid/LICENSE +21 -0
- package/vendor/mermaid/README.md +16 -0
- package/vendor/mermaid/flow.jison +635 -0
- package/vendor/mermaid/flowDb.ts +1336 -0
- package/vendor/mermaid/flowParser.ts +12 -0
- package/vendor/mermaid/provenance.json +14 -0
package/dist/layout.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lay out a parsed flow graph on an integer character grid.
|
|
3
|
+
*
|
|
4
|
+
* ELK does the global compound graph layout and orthogonal routing. The
|
|
5
|
+
* conversion at the end deliberately keeps every edge (including invisible
|
|
6
|
+
* edges) in the result; the rasterizer decides which strokes to draw.
|
|
7
|
+
*
|
|
8
|
+
* @param {FlowGraph} graph
|
|
9
|
+
* @returns {Promise<LayoutGraph>}
|
|
10
|
+
*/
|
|
11
|
+
export function layout(graph: FlowGraph): Promise<LayoutGraph>;
|
|
12
|
+
export type FlowGraph = import("./types.js").FlowGraph;
|
|
13
|
+
export type LayoutGraph = import("./types.js").LayoutGraph;
|
package/dist/parse.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export function parserError(error: any, source: any): FlowInkError;
|
|
2
|
+
export class FlowSemanticDB {
|
|
3
|
+
constructor(source: any);
|
|
4
|
+
source: any;
|
|
5
|
+
direction: string;
|
|
6
|
+
vertices: Map<any, any>;
|
|
7
|
+
edges: any[];
|
|
8
|
+
classes: Map<any, any>;
|
|
9
|
+
classTextStyles: Map<any, any>;
|
|
10
|
+
subGraphs: any[];
|
|
11
|
+
subGraphLookup: Map<any, any>;
|
|
12
|
+
tooltips: Map<any, any>;
|
|
13
|
+
interactions: Map<any, any>;
|
|
14
|
+
defaultStyles: any[];
|
|
15
|
+
defaultInterpolate: string;
|
|
16
|
+
vertexCounter: number;
|
|
17
|
+
firstGraphFlag: boolean;
|
|
18
|
+
lex: {
|
|
19
|
+
firstGraph: () => boolean;
|
|
20
|
+
};
|
|
21
|
+
title: string;
|
|
22
|
+
description: string;
|
|
23
|
+
firstGraph(): boolean;
|
|
24
|
+
clear(): void;
|
|
25
|
+
setDirection(direction: any): void;
|
|
26
|
+
addVertex(id: any, textObj: any, type: any, styles: any, classes: any, dir: any, props: any, rawShapeData: any): void;
|
|
27
|
+
addSingleLink(start: any, end: any, type: {}, id: any): void;
|
|
28
|
+
addLink(starts: any, ends: any, linkData?: {}): void;
|
|
29
|
+
destructLink(value: any, startValue: any): {
|
|
30
|
+
type: string;
|
|
31
|
+
stroke: string;
|
|
32
|
+
length?: undefined;
|
|
33
|
+
} | {
|
|
34
|
+
type: string;
|
|
35
|
+
stroke: string;
|
|
36
|
+
length: number;
|
|
37
|
+
};
|
|
38
|
+
addSubGraph(idObj: any, list: any, titleObj: any): {
|
|
39
|
+
styles: any[];
|
|
40
|
+
classes: any[];
|
|
41
|
+
metadata: {
|
|
42
|
+
labelType: any;
|
|
43
|
+
};
|
|
44
|
+
direction?: any;
|
|
45
|
+
id: any;
|
|
46
|
+
label: string;
|
|
47
|
+
nodeIds: any[];
|
|
48
|
+
};
|
|
49
|
+
addClass(ids: any, styles: any): void;
|
|
50
|
+
setClass(ids: any, className: any): void;
|
|
51
|
+
updateLink(positions: any, styles: any): void;
|
|
52
|
+
updateLinkInterpolate(positions: any, value: any): void;
|
|
53
|
+
setTooltip(ids: any, tooltip: any): void;
|
|
54
|
+
setLink(ids: any, link: any, target: any): void;
|
|
55
|
+
setClickEvent(ids: any, callback: any, args: any): void;
|
|
56
|
+
setAccTitle(value: any): void;
|
|
57
|
+
setAccDescription(value: any): void;
|
|
58
|
+
finalize(): {
|
|
59
|
+
source: any;
|
|
60
|
+
direction: string;
|
|
61
|
+
nodes: any[];
|
|
62
|
+
edges: any[];
|
|
63
|
+
subgraphs: any[];
|
|
64
|
+
classes: any;
|
|
65
|
+
metadata: {
|
|
66
|
+
title: string;
|
|
67
|
+
description: string;
|
|
68
|
+
accessibilityTitle: string;
|
|
69
|
+
accessibilityDescription: string;
|
|
70
|
+
defaultStyle: any[];
|
|
71
|
+
defaultInterpolate: string;
|
|
72
|
+
classTextStyles: any;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
import { FlowInkError } from '../errors.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** @typedef {import('./types.js').LayoutGraph} LayoutGraph */
|
|
2
|
+
/**
|
|
3
|
+
* Reposition every edge label around its own orthogonal route.
|
|
4
|
+
*
|
|
5
|
+
* The input graph is updated in place and returned for convenient piping.
|
|
6
|
+
* Boxes and routes are never rerouted. If a label (or supplied geometry)
|
|
7
|
+
* reaches a negative coordinate, the complete graph is translated and the
|
|
8
|
+
* advertised canvas is expanded accordingly.
|
|
9
|
+
*
|
|
10
|
+
* @param {LayoutGraph} layout
|
|
11
|
+
* @returns {LayoutGraph}
|
|
12
|
+
*/
|
|
13
|
+
export function placeLabels(layout: LayoutGraph): LayoutGraph;
|
|
14
|
+
export default placeLabels;
|
|
15
|
+
export type LayoutGraph = import("./types.js").LayoutGraph;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn an integer, orthogonally-routed layout into a terminal drawing.
|
|
3
|
+
*
|
|
4
|
+
* The rasterizer deliberately keeps a cell model until the very last step.
|
|
5
|
+
* This is what lets a wide character reserve its second cell and lets us
|
|
6
|
+
* detect a route that would otherwise disappear behind a node.
|
|
7
|
+
*
|
|
8
|
+
* @param {import('./types.js').LayoutGraph} layout
|
|
9
|
+
* @param {import('./types.js').RenderOptions} [options]
|
|
10
|
+
* @returns {string}
|
|
11
|
+
*/
|
|
12
|
+
export function rasterize(layout: import("./types.js").LayoutGraph, options?: import("./types.js").RenderOptions): string;
|
|
13
|
+
/** @param {import('./types.js').LayoutGraph} layout */
|
|
14
|
+
export function validateLayout(layout: import("./types.js").LayoutGraph): {
|
|
15
|
+
boxes: {
|
|
16
|
+
shape: string;
|
|
17
|
+
id: string;
|
|
18
|
+
kind: "node" | "subgraph";
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
lines: string[];
|
|
24
|
+
parentId?: string;
|
|
25
|
+
}[];
|
|
26
|
+
edges: {
|
|
27
|
+
points: {
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
}[];
|
|
31
|
+
arrowStart: import("./types.js").Arrow;
|
|
32
|
+
arrowEnd: import("./types.js").Arrow;
|
|
33
|
+
stroke: string;
|
|
34
|
+
id: string;
|
|
35
|
+
label?: {
|
|
36
|
+
x: number;
|
|
37
|
+
y: number;
|
|
38
|
+
lines: string[];
|
|
39
|
+
width: number;
|
|
40
|
+
height: number;
|
|
41
|
+
};
|
|
42
|
+
}[];
|
|
43
|
+
labels: any[];
|
|
44
|
+
width: number;
|
|
45
|
+
height: number;
|
|
46
|
+
};
|
|
47
|
+
export default rasterize;
|
package/dist/text.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Return the number of terminal character cells occupied by a string.
|
|
3
|
+
*
|
|
4
|
+
* `string-width` counts grapheme clusters and East Asian wide characters,
|
|
5
|
+
* which is the same unit used by the text rasterizer. A label can contain
|
|
6
|
+
* newlines, so this function returns the width of its widest line.
|
|
7
|
+
*
|
|
8
|
+
* @param {unknown} value
|
|
9
|
+
* @returns {number}
|
|
10
|
+
*/
|
|
11
|
+
export function displayWidth(value: unknown): number;
|
|
12
|
+
/**
|
|
13
|
+
* Convert a Mermaid label to plain, displayable lines. Markdown and HTML are
|
|
14
|
+
* parsed with marked only; no generated markup is inserted into a DOM or
|
|
15
|
+
* otherwise executed.
|
|
16
|
+
*
|
|
17
|
+
* @param {unknown} label
|
|
18
|
+
* @param {unknown} [labelType]
|
|
19
|
+
* @returns {string[]}
|
|
20
|
+
*/
|
|
21
|
+
export function labelLines(label: unknown, labelType?: unknown): string[];
|
|
22
|
+
/**
|
|
23
|
+
* Prepare a graph node for character-cell layout.
|
|
24
|
+
*
|
|
25
|
+
* @param {import('./types.js').FlowNode|Record<string, any>} node
|
|
26
|
+
* @returns {{lines:string[],shape:string,width:number,height:number,metadata:Record<string, any>,originalShape:string}}
|
|
27
|
+
*/
|
|
28
|
+
export function prepareNode(node?: import("./types.js").FlowNode | Record<string, any>): {
|
|
29
|
+
lines: string[];
|
|
30
|
+
shape: string;
|
|
31
|
+
width: number;
|
|
32
|
+
height: number;
|
|
33
|
+
metadata: Record<string, any>;
|
|
34
|
+
originalShape: string;
|
|
35
|
+
};
|
|
36
|
+
export const SHAPE_ALIASES: Map<string, string>;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export type Direction = "TB" | "BT" | "LR" | "RL";
|
|
2
|
+
export type Arrow = "none" | "point" | "circle" | "cross";
|
|
3
|
+
export type FlowNode = {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
labelType: string;
|
|
7
|
+
shape: string;
|
|
8
|
+
parentId?: string;
|
|
9
|
+
styles: string[];
|
|
10
|
+
classes: string[];
|
|
11
|
+
metadata: Record<string, any>;
|
|
12
|
+
};
|
|
13
|
+
export type FlowEdge = {
|
|
14
|
+
id: string;
|
|
15
|
+
source: string;
|
|
16
|
+
target: string;
|
|
17
|
+
label: string;
|
|
18
|
+
labelType: string;
|
|
19
|
+
arrowStart: Arrow;
|
|
20
|
+
arrowEnd: Arrow;
|
|
21
|
+
stroke: "normal" | "thick" | "dotted" | "invisible";
|
|
22
|
+
length: number;
|
|
23
|
+
styles: string[];
|
|
24
|
+
classes: string[];
|
|
25
|
+
animate?: boolean;
|
|
26
|
+
animation?: string;
|
|
27
|
+
curve?: string;
|
|
28
|
+
interpolate?: string;
|
|
29
|
+
isUserDefinedId?: boolean;
|
|
30
|
+
metadata: Record<string, any>;
|
|
31
|
+
};
|
|
32
|
+
export type FlowSubgraph = {
|
|
33
|
+
id: string;
|
|
34
|
+
label: string;
|
|
35
|
+
nodeIds: string[];
|
|
36
|
+
parentId?: string;
|
|
37
|
+
direction?: Direction;
|
|
38
|
+
styles: string[];
|
|
39
|
+
classes: string[];
|
|
40
|
+
metadata: Record<string, any>;
|
|
41
|
+
};
|
|
42
|
+
export type FlowGraph = {
|
|
43
|
+
source: string;
|
|
44
|
+
direction: Direction;
|
|
45
|
+
nodes: FlowNode[];
|
|
46
|
+
edges: FlowEdge[];
|
|
47
|
+
subgraphs: FlowSubgraph[];
|
|
48
|
+
classes: Record<string, string[]>;
|
|
49
|
+
metadata: Record<string, any>;
|
|
50
|
+
};
|
|
51
|
+
export type RenderOptions = {
|
|
52
|
+
charset?: "ascii" | "unicode";
|
|
53
|
+
};
|
|
54
|
+
export type Point = {
|
|
55
|
+
x: number;
|
|
56
|
+
y: number;
|
|
57
|
+
};
|
|
58
|
+
export type LayoutBox = {
|
|
59
|
+
id: string;
|
|
60
|
+
kind: "node" | "subgraph";
|
|
61
|
+
x: number;
|
|
62
|
+
y: number;
|
|
63
|
+
width: number;
|
|
64
|
+
height: number;
|
|
65
|
+
lines: string[];
|
|
66
|
+
shape: string;
|
|
67
|
+
parentId?: string;
|
|
68
|
+
};
|
|
69
|
+
export type LayoutEdge = {
|
|
70
|
+
id: string;
|
|
71
|
+
points: Point[];
|
|
72
|
+
arrowStart: Arrow;
|
|
73
|
+
arrowEnd: Arrow;
|
|
74
|
+
stroke: string;
|
|
75
|
+
label?: {
|
|
76
|
+
x: number;
|
|
77
|
+
y: number;
|
|
78
|
+
lines: string[];
|
|
79
|
+
width: number;
|
|
80
|
+
height: number;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
export type LayoutGraph = {
|
|
84
|
+
boxes: LayoutBox[];
|
|
85
|
+
edges: LayoutEdge[];
|
|
86
|
+
width: number;
|
|
87
|
+
height: number;
|
|
88
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "flowink",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Render Mermaid flowcharts as ASCII and Unicode diagrams in Node.js and browsers",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"examples",
|
|
18
|
+
"vendor/mermaid",
|
|
19
|
+
"LICENSE",
|
|
20
|
+
"NOTICE.md",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=22.12.0"
|
|
25
|
+
},
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public",
|
|
29
|
+
"registry": "https://registry.npmjs.org/"
|
|
30
|
+
},
|
|
31
|
+
"sideEffects": false,
|
|
32
|
+
"scripts": {
|
|
33
|
+
"generate": "node scripts/generate-parser.js",
|
|
34
|
+
"build": "npm run generate && node scripts/build.js",
|
|
35
|
+
"test": "node --test test/*.test.js",
|
|
36
|
+
"prepack": "npm run build",
|
|
37
|
+
"test:browser:build": "npm run build && node scripts/browser-smoke.js",
|
|
38
|
+
"test:types": "tsc --noEmit --skipLibCheck --module NodeNext --moduleResolution NodeNext --target ES2022 test/types.mts",
|
|
39
|
+
"test:package": "npm run build && node scripts/package-smoke.js"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"elkjs": "0.12.0",
|
|
43
|
+
"entities": "^6.0.1",
|
|
44
|
+
"js-yaml": "^4.1.0",
|
|
45
|
+
"marked": "^16.3.0",
|
|
46
|
+
"string-width": "^7.2.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"esbuild": "^0.25.0",
|
|
50
|
+
"jison": "0.4.18",
|
|
51
|
+
"jsdom": "^26.1.0",
|
|
52
|
+
"mermaid": "12.0.0",
|
|
53
|
+
"typescript": "^5.9.0"
|
|
54
|
+
},
|
|
55
|
+
"repository": {
|
|
56
|
+
"type": "git",
|
|
57
|
+
"url": "git+https://github.com/william1010121/flowink.git"
|
|
58
|
+
},
|
|
59
|
+
"homepage": "https://github.com/william1010121/flowink#readme",
|
|
60
|
+
"bugs": {
|
|
61
|
+
"url": "https://github.com/william1010121/flowink/issues"
|
|
62
|
+
},
|
|
63
|
+
"keywords": [
|
|
64
|
+
"mermaid",
|
|
65
|
+
"flowchart",
|
|
66
|
+
"ascii",
|
|
67
|
+
"unicode",
|
|
68
|
+
"diagram",
|
|
69
|
+
"text"
|
|
70
|
+
]
|
|
71
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014 - 2022 Knut Sveidqvist
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Mermaid flowchart provenance
|
|
2
|
+
|
|
3
|
+
FlowInk vendors the Mermaid flowchart grammar from Mermaid `12.0.0`, commit
|
|
4
|
+
`98a0945418c76238f15df2afaddbba4272656c3b`. The exact upstream grammar is
|
|
5
|
+
`flow.jison`; its SHA-256 is recorded in [provenance.json](./provenance.json).
|
|
6
|
+
|
|
7
|
+
The accompanying `flowDb.ts` and `flowParser.ts` files are upstream reference
|
|
8
|
+
sources for semantic and parser behavior. FlowInk's pure JavaScript adapter is
|
|
9
|
+
`src/parser/semantic.js`; it retains the parser-facing FlowDB operations while
|
|
10
|
+
omitting Mermaid's DOM and rendering dependencies. Mermaid's MIT license is
|
|
11
|
+
included in `LICENSE`.
|
|
12
|
+
|
|
13
|
+
Upstream sources:
|
|
14
|
+
|
|
15
|
+
- https://github.com/mermaid-js/mermaid/tree/98a0945418c76238f15df2afaddbba4272656c3b/packages/mermaid/src/diagrams/flowchart
|
|
16
|
+
- https://github.com/mermaid-js/mermaid/blob/98a0945418c76238f15df2afaddbba4272656c3b/LICENSE
|