@zombie-mermaid/mermaid-parser 4.0.0 → 4.2.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/dist/index.cjs +9 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +110 -0
- package/dist/index.d.ts +110 -0
- package/dist/index.js +841 -248
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/flowchart-edge-label-space-before-pipe.test.ts +54 -0
- package/src/__tests__/pie-mermaid-spec.test.ts +308 -0
- package/src/__tests__/pie-parser.test.ts +452 -0
- package/src/flowchart-parser.ts +1327 -0
- package/src/index.ts +7 -2
- package/src/pie/parser.ts +393 -0
- package/src/pie/types.ts +109 -0
package/dist/index.d.cts
CHANGED
|
@@ -5,6 +5,7 @@ import { NodeShape } from '@zombie-mermaid/core';
|
|
|
5
5
|
import { Point } from '@zombie-mermaid/core';
|
|
6
6
|
import { Statement } from '@zombie-mermaid/core';
|
|
7
7
|
import { StyleDirectives } from '@zombie-mermaid/core';
|
|
8
|
+
import { toDirection } from '@zombie-mermaid/core';
|
|
8
9
|
|
|
9
10
|
/** Narrow rectangle on a lifeline showing active processing */
|
|
10
11
|
export declare interface Activation {
|
|
@@ -655,6 +656,21 @@ export declare function parseExpandedMeta(body: string): ExpandedNodeMeta;
|
|
|
655
656
|
*/
|
|
656
657
|
export declare function parseGenericTypes(input: string): string;
|
|
657
658
|
|
|
659
|
+
/**
|
|
660
|
+
* Parse Mermaid text into a logical graph structure.
|
|
661
|
+
* Auto-detects diagram type (flowchart or state diagram).
|
|
662
|
+
* Throws on invalid/unsupported input.
|
|
663
|
+
*/
|
|
664
|
+
export declare function parseMermaid(text: string): MermaidGraph;
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* Parse Mermaid pie chart source text.
|
|
668
|
+
*
|
|
669
|
+
* Throws `Line N: …` errors (the shape the MCP diagnostics expect) for
|
|
670
|
+
* anything Mermaid's own parser would reject.
|
|
671
|
+
*/
|
|
672
|
+
export declare function parsePieChart(text: string): PieChart;
|
|
673
|
+
|
|
658
674
|
/**
|
|
659
675
|
* Parse a Mermaid sequence diagram.
|
|
660
676
|
* Expects the first line to be "sequenceDiagram".
|
|
@@ -682,6 +698,32 @@ export declare interface ParticipantBox {
|
|
|
682
698
|
actorIds: string[];
|
|
683
699
|
}
|
|
684
700
|
|
|
701
|
+
/** A parsed Mermaid pie chart. */
|
|
702
|
+
export declare interface PieChart {
|
|
703
|
+
/** `title …`, either on the `pie` header line or on its own line. */
|
|
704
|
+
title?: string;
|
|
705
|
+
/** `accTitle: …` accessible title. */
|
|
706
|
+
accTitle?: string;
|
|
707
|
+
/** `accDescr: …` or multi-line `accDescr { … }` accessible description. */
|
|
708
|
+
accDescr?: string;
|
|
709
|
+
/** `pie showData` — show each slice's raw value next to its legend label. */
|
|
710
|
+
showData: boolean;
|
|
711
|
+
/**
|
|
712
|
+
* Slices in source order. A label that repeats keeps its first value and
|
|
713
|
+
* position; later duplicates are ignored, as in Mermaid. May be empty:
|
|
714
|
+
* Mermaid accepts a bare `pie` with no slices.
|
|
715
|
+
*/
|
|
716
|
+
slices: PieSlice[];
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
/** One slice of a pie chart, in source order. */
|
|
720
|
+
export declare interface PieSlice {
|
|
721
|
+
/** Slice label, with its surrounding quotes removed and escapes resolved. */
|
|
722
|
+
label: string;
|
|
723
|
+
/** Slice value. Never negative; zero is allowed (Mermaid accepts it). */
|
|
724
|
+
value: number;
|
|
725
|
+
}
|
|
726
|
+
|
|
685
727
|
export declare interface PlotArea {
|
|
686
728
|
x: number;
|
|
687
729
|
y: number;
|
|
@@ -979,6 +1021,72 @@ export declare interface PositionedParticipantBox {
|
|
|
979
1021
|
height: number;
|
|
980
1022
|
}
|
|
981
1023
|
|
|
1024
|
+
export declare interface PositionedPieChart {
|
|
1025
|
+
width: number;
|
|
1026
|
+
height: number;
|
|
1027
|
+
/** Pie centre. */
|
|
1028
|
+
cx: number;
|
|
1029
|
+
cy: number;
|
|
1030
|
+
/** Slice radius. */
|
|
1031
|
+
radius: number;
|
|
1032
|
+
/** Radius of the outline circle drawn around the pie. */
|
|
1033
|
+
outerRadius: number;
|
|
1034
|
+
/** Title text and its anchor (text-anchor middle, alphabetic baseline). */
|
|
1035
|
+
title?: {
|
|
1036
|
+
text: string;
|
|
1037
|
+
x: number;
|
|
1038
|
+
y: number;
|
|
1039
|
+
};
|
|
1040
|
+
/** Drawn slices, in source order. */
|
|
1041
|
+
slices: PositionedPieSlice[];
|
|
1042
|
+
/** Legend rows, one per parsed slice, in source order. */
|
|
1043
|
+
legend: PositionedPieLegendItem[];
|
|
1044
|
+
/** `accTitle`, carried through for the SVG accessible name. */
|
|
1045
|
+
accTitle?: string;
|
|
1046
|
+
/** `accDescr`, carried through for the SVG `<desc>`. */
|
|
1047
|
+
accDescr?: string;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
/** One legend row: a colour swatch and its label. Every slice gets one. */
|
|
1051
|
+
export declare interface PositionedPieLegendItem {
|
|
1052
|
+
/** Row text: the label, or `label [value]` when `showData` is on. */
|
|
1053
|
+
text: string;
|
|
1054
|
+
colorIndex: number;
|
|
1055
|
+
/** Top-left corner of the square swatch. */
|
|
1056
|
+
x: number;
|
|
1057
|
+
y: number;
|
|
1058
|
+
/** Swatch side length. */
|
|
1059
|
+
size: number;
|
|
1060
|
+
/** Text anchor (text-anchor start, alphabetic baseline). */
|
|
1061
|
+
textX: number;
|
|
1062
|
+
textY: number;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
/** One drawn slice. Slices under 1% of the total are never positioned. */
|
|
1066
|
+
export declare interface PositionedPieSlice {
|
|
1067
|
+
/** Slice label (as parsed). */
|
|
1068
|
+
label: string;
|
|
1069
|
+
/** Slice value (as parsed). */
|
|
1070
|
+
value: number;
|
|
1071
|
+
/**
|
|
1072
|
+
* Palette slot: the slice's index among *all* slices in source order,
|
|
1073
|
+
* modulo 12 — Mermaid's `pie1`..`pie12` colour scale is keyed by every
|
|
1074
|
+
* label, including slices too small to draw, and wraps after 12.
|
|
1075
|
+
*/
|
|
1076
|
+
colorIndex: number;
|
|
1077
|
+
/** Start angle, radians clockwise from 12 o'clock. */
|
|
1078
|
+
startAngle: number;
|
|
1079
|
+
/** End angle, radians clockwise from 12 o'clock. */
|
|
1080
|
+
endAngle: number;
|
|
1081
|
+
/** SVG path data for the wedge (or full circle for a 100% slice). */
|
|
1082
|
+
path: string;
|
|
1083
|
+
/** Percentage label, `((value / total) * 100).toFixed(0) + '%'` as in Mermaid. */
|
|
1084
|
+
percentText: string;
|
|
1085
|
+
/** Anchor of the percentage label (text-anchor middle, alphabetic baseline). */
|
|
1086
|
+
labelX: number;
|
|
1087
|
+
labelY: number;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
982
1090
|
export declare interface PositionedSequenceDiagram {
|
|
983
1091
|
width: number;
|
|
984
1092
|
height: number;
|
|
@@ -1071,6 +1179,8 @@ export declare interface SequenceDiagram {
|
|
|
1071
1179
|
*/
|
|
1072
1180
|
export declare function toBlockType(value: string): Block['type'];
|
|
1073
1181
|
|
|
1182
|
+
export { toDirection }
|
|
1183
|
+
|
|
1074
1184
|
/** Greedy word wrap; a word longer than `width` stays on its own line. */
|
|
1075
1185
|
export declare function wrapC4Text(text: string, width: number): string[];
|
|
1076
1186
|
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { NodeShape } from '@zombie-mermaid/core';
|
|
|
5
5
|
import { Point } from '@zombie-mermaid/core';
|
|
6
6
|
import { Statement } from '@zombie-mermaid/core';
|
|
7
7
|
import { StyleDirectives } from '@zombie-mermaid/core';
|
|
8
|
+
import { toDirection } from '@zombie-mermaid/core';
|
|
8
9
|
|
|
9
10
|
/** Narrow rectangle on a lifeline showing active processing */
|
|
10
11
|
export declare interface Activation {
|
|
@@ -655,6 +656,21 @@ export declare function parseExpandedMeta(body: string): ExpandedNodeMeta;
|
|
|
655
656
|
*/
|
|
656
657
|
export declare function parseGenericTypes(input: string): string;
|
|
657
658
|
|
|
659
|
+
/**
|
|
660
|
+
* Parse Mermaid text into a logical graph structure.
|
|
661
|
+
* Auto-detects diagram type (flowchart or state diagram).
|
|
662
|
+
* Throws on invalid/unsupported input.
|
|
663
|
+
*/
|
|
664
|
+
export declare function parseMermaid(text: string): MermaidGraph;
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* Parse Mermaid pie chart source text.
|
|
668
|
+
*
|
|
669
|
+
* Throws `Line N: …` errors (the shape the MCP diagnostics expect) for
|
|
670
|
+
* anything Mermaid's own parser would reject.
|
|
671
|
+
*/
|
|
672
|
+
export declare function parsePieChart(text: string): PieChart;
|
|
673
|
+
|
|
658
674
|
/**
|
|
659
675
|
* Parse a Mermaid sequence diagram.
|
|
660
676
|
* Expects the first line to be "sequenceDiagram".
|
|
@@ -682,6 +698,32 @@ export declare interface ParticipantBox {
|
|
|
682
698
|
actorIds: string[];
|
|
683
699
|
}
|
|
684
700
|
|
|
701
|
+
/** A parsed Mermaid pie chart. */
|
|
702
|
+
export declare interface PieChart {
|
|
703
|
+
/** `title …`, either on the `pie` header line or on its own line. */
|
|
704
|
+
title?: string;
|
|
705
|
+
/** `accTitle: …` accessible title. */
|
|
706
|
+
accTitle?: string;
|
|
707
|
+
/** `accDescr: …` or multi-line `accDescr { … }` accessible description. */
|
|
708
|
+
accDescr?: string;
|
|
709
|
+
/** `pie showData` — show each slice's raw value next to its legend label. */
|
|
710
|
+
showData: boolean;
|
|
711
|
+
/**
|
|
712
|
+
* Slices in source order. A label that repeats keeps its first value and
|
|
713
|
+
* position; later duplicates are ignored, as in Mermaid. May be empty:
|
|
714
|
+
* Mermaid accepts a bare `pie` with no slices.
|
|
715
|
+
*/
|
|
716
|
+
slices: PieSlice[];
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
/** One slice of a pie chart, in source order. */
|
|
720
|
+
export declare interface PieSlice {
|
|
721
|
+
/** Slice label, with its surrounding quotes removed and escapes resolved. */
|
|
722
|
+
label: string;
|
|
723
|
+
/** Slice value. Never negative; zero is allowed (Mermaid accepts it). */
|
|
724
|
+
value: number;
|
|
725
|
+
}
|
|
726
|
+
|
|
685
727
|
export declare interface PlotArea {
|
|
686
728
|
x: number;
|
|
687
729
|
y: number;
|
|
@@ -979,6 +1021,72 @@ export declare interface PositionedParticipantBox {
|
|
|
979
1021
|
height: number;
|
|
980
1022
|
}
|
|
981
1023
|
|
|
1024
|
+
export declare interface PositionedPieChart {
|
|
1025
|
+
width: number;
|
|
1026
|
+
height: number;
|
|
1027
|
+
/** Pie centre. */
|
|
1028
|
+
cx: number;
|
|
1029
|
+
cy: number;
|
|
1030
|
+
/** Slice radius. */
|
|
1031
|
+
radius: number;
|
|
1032
|
+
/** Radius of the outline circle drawn around the pie. */
|
|
1033
|
+
outerRadius: number;
|
|
1034
|
+
/** Title text and its anchor (text-anchor middle, alphabetic baseline). */
|
|
1035
|
+
title?: {
|
|
1036
|
+
text: string;
|
|
1037
|
+
x: number;
|
|
1038
|
+
y: number;
|
|
1039
|
+
};
|
|
1040
|
+
/** Drawn slices, in source order. */
|
|
1041
|
+
slices: PositionedPieSlice[];
|
|
1042
|
+
/** Legend rows, one per parsed slice, in source order. */
|
|
1043
|
+
legend: PositionedPieLegendItem[];
|
|
1044
|
+
/** `accTitle`, carried through for the SVG accessible name. */
|
|
1045
|
+
accTitle?: string;
|
|
1046
|
+
/** `accDescr`, carried through for the SVG `<desc>`. */
|
|
1047
|
+
accDescr?: string;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
/** One legend row: a colour swatch and its label. Every slice gets one. */
|
|
1051
|
+
export declare interface PositionedPieLegendItem {
|
|
1052
|
+
/** Row text: the label, or `label [value]` when `showData` is on. */
|
|
1053
|
+
text: string;
|
|
1054
|
+
colorIndex: number;
|
|
1055
|
+
/** Top-left corner of the square swatch. */
|
|
1056
|
+
x: number;
|
|
1057
|
+
y: number;
|
|
1058
|
+
/** Swatch side length. */
|
|
1059
|
+
size: number;
|
|
1060
|
+
/** Text anchor (text-anchor start, alphabetic baseline). */
|
|
1061
|
+
textX: number;
|
|
1062
|
+
textY: number;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
/** One drawn slice. Slices under 1% of the total are never positioned. */
|
|
1066
|
+
export declare interface PositionedPieSlice {
|
|
1067
|
+
/** Slice label (as parsed). */
|
|
1068
|
+
label: string;
|
|
1069
|
+
/** Slice value (as parsed). */
|
|
1070
|
+
value: number;
|
|
1071
|
+
/**
|
|
1072
|
+
* Palette slot: the slice's index among *all* slices in source order,
|
|
1073
|
+
* modulo 12 — Mermaid's `pie1`..`pie12` colour scale is keyed by every
|
|
1074
|
+
* label, including slices too small to draw, and wraps after 12.
|
|
1075
|
+
*/
|
|
1076
|
+
colorIndex: number;
|
|
1077
|
+
/** Start angle, radians clockwise from 12 o'clock. */
|
|
1078
|
+
startAngle: number;
|
|
1079
|
+
/** End angle, radians clockwise from 12 o'clock. */
|
|
1080
|
+
endAngle: number;
|
|
1081
|
+
/** SVG path data for the wedge (or full circle for a 100% slice). */
|
|
1082
|
+
path: string;
|
|
1083
|
+
/** Percentage label, `((value / total) * 100).toFixed(0) + '%'` as in Mermaid. */
|
|
1084
|
+
percentText: string;
|
|
1085
|
+
/** Anchor of the percentage label (text-anchor middle, alphabetic baseline). */
|
|
1086
|
+
labelX: number;
|
|
1087
|
+
labelY: number;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
982
1090
|
export declare interface PositionedSequenceDiagram {
|
|
983
1091
|
width: number;
|
|
984
1092
|
height: number;
|
|
@@ -1071,6 +1179,8 @@ export declare interface SequenceDiagram {
|
|
|
1071
1179
|
*/
|
|
1072
1180
|
export declare function toBlockType(value: string): Block['type'];
|
|
1073
1181
|
|
|
1182
|
+
export { toDirection }
|
|
1183
|
+
|
|
1074
1184
|
/** Greedy word wrap; a word longer than `width` stays on its own line. */
|
|
1075
1185
|
export declare function wrapC4Text(text: string, width: number): string[];
|
|
1076
1186
|
|