@zombie-mermaid/mermaid-parser 4.1.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 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +100 -0
- package/dist/index.d.ts +100 -0
- package/dist/index.js +340 -179
- 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 +7 -4
- package/src/index.ts +3 -0
- package/src/pie/parser.ts +393 -0
- package/src/pie/types.ts +109 -0
package/dist/index.d.cts
CHANGED
|
@@ -663,6 +663,14 @@ export declare function parseGenericTypes(input: string): string;
|
|
|
663
663
|
*/
|
|
664
664
|
export declare function parseMermaid(text: string): MermaidGraph;
|
|
665
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
|
+
|
|
666
674
|
/**
|
|
667
675
|
* Parse a Mermaid sequence diagram.
|
|
668
676
|
* Expects the first line to be "sequenceDiagram".
|
|
@@ -690,6 +698,32 @@ export declare interface ParticipantBox {
|
|
|
690
698
|
actorIds: string[];
|
|
691
699
|
}
|
|
692
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
|
+
|
|
693
727
|
export declare interface PlotArea {
|
|
694
728
|
x: number;
|
|
695
729
|
y: number;
|
|
@@ -987,6 +1021,72 @@ export declare interface PositionedParticipantBox {
|
|
|
987
1021
|
height: number;
|
|
988
1022
|
}
|
|
989
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
|
+
|
|
990
1090
|
export declare interface PositionedSequenceDiagram {
|
|
991
1091
|
width: number;
|
|
992
1092
|
height: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -663,6 +663,14 @@ export declare function parseGenericTypes(input: string): string;
|
|
|
663
663
|
*/
|
|
664
664
|
export declare function parseMermaid(text: string): MermaidGraph;
|
|
665
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
|
+
|
|
666
674
|
/**
|
|
667
675
|
* Parse a Mermaid sequence diagram.
|
|
668
676
|
* Expects the first line to be "sequenceDiagram".
|
|
@@ -690,6 +698,32 @@ export declare interface ParticipantBox {
|
|
|
690
698
|
actorIds: string[];
|
|
691
699
|
}
|
|
692
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
|
+
|
|
693
727
|
export declare interface PlotArea {
|
|
694
728
|
x: number;
|
|
695
729
|
y: number;
|
|
@@ -987,6 +1021,72 @@ export declare interface PositionedParticipantBox {
|
|
|
987
1021
|
height: number;
|
|
988
1022
|
}
|
|
989
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
|
+
|
|
990
1090
|
export declare interface PositionedSequenceDiagram {
|
|
991
1091
|
width: number;
|
|
992
1092
|
height: number;
|