@diagrammo/dgmo 0.3.1 → 0.4.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.
@@ -99,8 +99,8 @@ export function parseDgmoChartType(content: string): string | null {
99
99
  return null;
100
100
  }
101
101
 
102
- // Standard chart types parsed by parseChart (then rendered via ECharts)
103
- const STANDARD_CHART_TYPES = new Set([
102
+ /** Standard chart types parsed by parseChart (then rendered via ECharts). */
103
+ export const STANDARD_CHART_TYPES = new Set([
104
104
  'bar', 'line', 'multi-line', 'area', 'pie', 'doughnut',
105
105
  'radar', 'polar-area', 'bar-stacked',
106
106
  ]);
@@ -110,6 +110,18 @@ const ECHART_TYPES = new Set([
110
110
  'scatter', 'sankey', 'chord', 'function', 'heatmap', 'funnel',
111
111
  ]);
112
112
 
113
+ /** Map chart type strings to their parse function (content → { diagnostics }). */
114
+ const PARSE_DISPATCH = new Map<string, (content: string) => { diagnostics: DgmoError[] }>([
115
+ ['sequence', (c) => parseSequenceDgmo(c)],
116
+ ['flowchart', (c) => parseFlowchart(c)],
117
+ ['class', (c) => parseClassDiagram(c)],
118
+ ['er', (c) => parseERDiagram(c)],
119
+ ['org', (c) => parseOrg(c)],
120
+ ['kanban', (c) => parseKanban(c)],
121
+ ['c4', (c) => parseC4(c)],
122
+ ['initiative-status', (c) => parseInitiativeStatus(c)],
123
+ ]);
124
+
113
125
  /**
114
126
  * Parse DGMO content and return diagnostics without rendering.
115
127
  * Useful for the CLI and editor to surface all errors before attempting render.
@@ -119,52 +131,19 @@ export function parseDgmo(content: string): { diagnostics: DgmoError[] } {
119
131
 
120
132
  if (!chartType) {
121
133
  // No chart type detected — try D3 parser as fallback (it handles missing chart: line)
122
- const parsed = parseD3(content);
123
- return { diagnostics: parsed.diagnostics };
134
+ return { diagnostics: parseD3(content).diagnostics };
124
135
  }
125
136
 
126
- if (chartType === 'sequence') {
127
- const parsed = parseSequenceDgmo(content);
128
- return { diagnostics: parsed.diagnostics };
129
- }
130
- if (chartType === 'flowchart') {
131
- const parsed = parseFlowchart(content);
132
- return { diagnostics: parsed.diagnostics };
133
- }
134
- if (chartType === 'class') {
135
- const parsed = parseClassDiagram(content);
136
- return { diagnostics: parsed.diagnostics };
137
- }
138
- if (chartType === 'er') {
139
- const parsed = parseERDiagram(content);
140
- return { diagnostics: parsed.diagnostics };
141
- }
142
- if (chartType === 'org') {
143
- const parsed = parseOrg(content);
144
- return { diagnostics: parsed.diagnostics };
145
- }
146
- if (chartType === 'kanban') {
147
- const parsed = parseKanban(content);
148
- return { diagnostics: parsed.diagnostics };
149
- }
150
- if (chartType === 'c4') {
151
- const parsed = parseC4(content);
152
- return { diagnostics: parsed.diagnostics };
153
- }
154
- if (chartType === 'initiative-status') {
155
- const parsed = parseInitiativeStatus(content);
156
- return { diagnostics: parsed.diagnostics };
157
- }
137
+ const directParser = PARSE_DISPATCH.get(chartType);
138
+ if (directParser) return { diagnostics: directParser(content).diagnostics };
139
+
158
140
  if (STANDARD_CHART_TYPES.has(chartType)) {
159
- const parsed = parseChart(content);
160
- return { diagnostics: parsed.diagnostics };
141
+ return { diagnostics: parseChart(content).diagnostics };
161
142
  }
162
143
  if (ECHART_TYPES.has(chartType)) {
163
- const parsed = parseEChart(content);
164
- return { diagnostics: parsed.diagnostics };
144
+ return { diagnostics: parseEChart(content).diagnostics };
165
145
  }
166
146
 
167
147
  // D3 types (slope, wordcloud, arc, timeline, venn, quadrant)
168
- const parsed = parseD3(content);
169
- return { diagnostics: parsed.diagnostics };
148
+ return { diagnostics: parseD3(content).diagnostics };
170
149
  }