@diagrammo/dgmo 0.7.2 → 0.8.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.
Files changed (62) hide show
  1. package/AGENTS.md +15 -20
  2. package/README.md +56 -58
  3. package/dist/cli.cjs +188 -181
  4. package/dist/index.cjs +3529 -1061
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.cts +196 -43
  7. package/dist/index.d.ts +196 -43
  8. package/dist/index.js +3516 -1061
  9. package/dist/index.js.map +1 -1
  10. package/docs/language-reference.md +629 -289
  11. package/package.json +1 -1
  12. package/src/c4/layout.ts +6 -9
  13. package/src/c4/parser.ts +189 -83
  14. package/src/c4/renderer.ts +8 -9
  15. package/src/chart.ts +296 -83
  16. package/src/class/parser.ts +54 -37
  17. package/src/class/renderer.ts +8 -8
  18. package/src/cli.ts +8 -8
  19. package/src/colors.ts +4 -1
  20. package/src/completion.ts +757 -10
  21. package/src/d3.ts +312 -73
  22. package/src/dgmo-router.ts +63 -8
  23. package/src/echarts.ts +726 -231
  24. package/src/er/parser.ts +94 -76
  25. package/src/er/renderer.ts +6 -5
  26. package/src/gantt/parser.ts +144 -69
  27. package/src/gantt/renderer.ts +50 -14
  28. package/src/gantt/types.ts +3 -3
  29. package/src/graph/flowchart-parser.ts +97 -37
  30. package/src/graph/flowchart-renderer.ts +4 -3
  31. package/src/graph/state-parser.ts +50 -31
  32. package/src/graph/state-renderer.ts +4 -3
  33. package/src/index.ts +14 -5
  34. package/src/infra/compute.ts +1 -0
  35. package/src/infra/layout.ts +3 -0
  36. package/src/infra/parser.ts +291 -92
  37. package/src/infra/renderer.ts +172 -30
  38. package/src/infra/types.ts +5 -0
  39. package/src/initiative-status/layout.ts +1 -1
  40. package/src/initiative-status/parser.ts +121 -47
  41. package/src/initiative-status/renderer.ts +82 -31
  42. package/src/initiative-status/types.ts +10 -2
  43. package/src/kanban/parser.ts +60 -37
  44. package/src/kanban/renderer.ts +2 -2
  45. package/src/kanban/types.ts +1 -0
  46. package/src/org/layout.ts +9 -9
  47. package/src/org/parser.ts +39 -40
  48. package/src/org/renderer.ts +5 -6
  49. package/src/org/resolver.ts +26 -19
  50. package/src/render.ts +1 -1
  51. package/src/sequence/parser.ts +304 -95
  52. package/src/sequence/renderer.ts +9 -9
  53. package/src/sitemap/layout.ts +3 -4
  54. package/src/sitemap/parser.ts +57 -49
  55. package/src/sitemap/renderer.ts +6 -7
  56. package/src/utils/arrows.ts +25 -6
  57. package/src/utils/duration.ts +43 -7
  58. package/src/utils/legend-constants.ts +26 -0
  59. package/src/utils/legend-svg.ts +167 -0
  60. package/src/utils/parsing.ts +247 -7
  61. package/src/utils/tag-groups.ts +160 -15
  62. package/src/utils/title-constants.ts +9 -0
@@ -17,26 +17,79 @@ import { looksLikeInitiativeStatus, parseInitiativeStatus } from './initiative-s
17
17
  import { looksLikeSitemap, parseSitemap } from './sitemap/parser';
18
18
  import { parseInfra } from './infra/parser';
19
19
  import { parseGantt } from './gantt/parser';
20
+ import { ALL_CHART_TYPES, parseFirstLine } from './utils/parsing';
20
21
  import type { DgmoError } from './diagnostics';
21
22
 
23
+ // ============================================================
24
+ // Content-based chart type inference helpers
25
+ // ============================================================
26
+
27
+ /** Gantt duration patterns: `10bd Task` or `10bd: Task` (with or without colon) */
28
+ const GANTT_DURATION_RE = /^\d+(?:\.\d+)?(?:min|bd|d|w|m|q|y|h)(?:\?)?\s*:?\s+/;
29
+ /** Gantt date patterns: `2025-01-01 Task` or `2025-01-01: Task` (with or without colon) */
30
+ const GANTT_DATE_RE = /^\d{4}-\d{2}-\d{2}(?:\s\d{2}:\d{2})?\s*:?\s+/;
31
+
32
+ /**
33
+ * Returns true if content looks like a gantt chart.
34
+ * Detects duration patterns like `10bd: Task` or `5d: Task`.
35
+ */
36
+ export function looksLikeGantt(content: string): boolean {
37
+ const lines = content.split('\n');
38
+ for (const line of lines) {
39
+ const trimmed = line.trim();
40
+ if (!trimmed || trimmed.startsWith('//')) continue;
41
+ if (GANTT_DURATION_RE.test(trimmed) || GANTT_DATE_RE.test(trimmed)) {
42
+ return true;
43
+ }
44
+ }
45
+ return false;
46
+ }
47
+
48
+ /** C4 `Name is a person/system/container/component` pattern */
49
+ const C4_TYPE_RE = /\bis\s+an?\s+(person|system|container|component)\b/i;
50
+
51
+ /**
52
+ * Returns true if content looks like a C4 diagram.
53
+ * Detects `Name is a person/system/container/component` declarations.
54
+ * Does NOT match bare words like `container` at line start.
55
+ */
56
+ export function looksLikeC4(content: string): boolean {
57
+ const lines = content.split('\n');
58
+ for (const line of lines) {
59
+ const trimmed = line.trim();
60
+ if (!trimmed || trimmed.startsWith('//')) continue;
61
+ if (C4_TYPE_RE.test(trimmed)) {
62
+ return true;
63
+ }
64
+ }
65
+ return false;
66
+ }
67
+
22
68
  /**
23
- * Extracts the `chart:` type value from raw file content.
24
- * Falls back to inference when no explicit `chart:` line is found
25
- * (e.g. content containing `->` is inferred as `sequence`).
69
+ * Extracts the chart type from raw file content.
70
+ * First tries the first non-empty, non-comment line as a bare chart type name
71
+ * (e.g., `gantt Product Launch`). Falls back to old `chart: type` syntax.
72
+ * Falls back to inference when no explicit chart type is found.
26
73
  */
27
74
  export function parseDgmoChartType(content: string): string | null {
28
75
  const lines = content.split('\n');
76
+
77
+ // Find first non-empty, non-comment line
29
78
  for (const line of lines) {
30
79
  const trimmed = line.trim();
31
- // Skip empty lines and comments
32
- if (!trimmed || trimmed.startsWith('//'))
33
- continue;
34
- const match = trimmed.match(/^chart\s*:\s*(.+)/i);
35
- if (match) return match[1].trim().toLowerCase();
80
+ if (!trimmed || trimmed.startsWith('//')) continue;
81
+
82
+ // Try new first-line detection (bare chart type name)
83
+ const firstLineResult = parseFirstLine(trimmed);
84
+ if (firstLineResult) return firstLineResult.chartType;
85
+
86
+ // Not a chart type on the first line — stop looking for explicit declaration
87
+ break;
36
88
  }
37
89
 
38
90
  // Infer chart type from content patterns (sequence before flowchart —
39
91
  // both use `->` but sequence uses bare names while flowchart uses shape delimiters)
92
+ // C4 must come AFTER sequence (both use `is a` but with different type nouns)
40
93
  if (looksLikeSequence(content)) return 'sequence';
41
94
  if (looksLikeFlowchart(content)) return 'flowchart';
42
95
  if (looksLikeClassDiagram(content)) return 'class';
@@ -45,6 +98,8 @@ export function parseDgmoChartType(content: string): string | null {
45
98
  if (looksLikeState(content)) return 'state';
46
99
  if (looksLikeSitemap(content)) return 'sitemap';
47
100
  if (looksLikeOrg(content)) return 'org';
101
+ if (looksLikeC4(content)) return 'c4';
102
+ if (looksLikeGantt(content)) return 'gantt';
48
103
 
49
104
  return null;
50
105
  }