@diagrammo/dgmo 0.47.0 → 0.48.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 (319) hide show
  1. package/dist/auto.js +1 -1
  2. package/dist/auto.mjs +1 -1
  3. package/dist/element.js +1 -1
  4. package/dist/element.mjs +1 -1
  5. package/package.json +19 -70
  6. package/dist/advanced.cjs +0 -71648
  7. package/dist/advanced.d.cts +0 -5719
  8. package/dist/auto.cjs +0 -70648
  9. package/dist/auto.d.cts +0 -54
  10. package/dist/block.cjs +0 -70208
  11. package/dist/block.d.cts +0 -115
  12. package/dist/editor.cjs +0 -526
  13. package/dist/editor.d.cts +0 -26
  14. package/dist/element.cjs +0 -70530
  15. package/dist/element.d.cts +0 -62
  16. package/dist/highlight.cjs +0 -852
  17. package/dist/highlight.d.cts +0 -49
  18. package/dist/index.cjs +0 -70491
  19. package/dist/index.d.cts +0 -160
  20. package/dist/pert.cjs +0 -325
  21. package/dist/pert.d.cts +0 -559
  22. package/dist/themes-1-CuKpeH.d.cts +0 -908
  23. package/src/advanced.ts +0 -873
  24. package/src/arc/parser.ts +0 -15
  25. package/src/arc/renderer.ts +0 -633
  26. package/src/auto/index.ts +0 -621
  27. package/src/auto/shared.ts +0 -370
  28. package/src/auto/styles.ts +0 -73
  29. package/src/block/layout.ts +0 -198
  30. package/src/block/parser.ts +0 -427
  31. package/src/block/renderer.ts +0 -484
  32. package/src/block/types.ts +0 -67
  33. package/src/boxes-and-lines/collapse.ts +0 -96
  34. package/src/boxes-and-lines/focus.ts +0 -257
  35. package/src/boxes-and-lines/label-placement.ts +0 -339
  36. package/src/boxes-and-lines/layout-grouped.ts +0 -912
  37. package/src/boxes-and-lines/layout-layered.ts +0 -722
  38. package/src/boxes-and-lines/layout-search.ts +0 -1678
  39. package/src/boxes-and-lines/layout.ts +0 -398
  40. package/src/boxes-and-lines/parser.ts +0 -1181
  41. package/src/boxes-and-lines/renderer.ts +0 -1465
  42. package/src/boxes-and-lines/types.ts +0 -66
  43. package/src/c4/layout.ts +0 -2441
  44. package/src/c4/parser.ts +0 -1158
  45. package/src/c4/renderer.ts +0 -2008
  46. package/src/c4/types.ts +0 -89
  47. package/src/chart-type-registry.ts +0 -529
  48. package/src/chart-types.ts +0 -225
  49. package/src/chart.ts +0 -685
  50. package/src/charts-d3/bar.ts +0 -338
  51. package/src/charts-d3/chord.ts +0 -140
  52. package/src/charts-d3/function.ts +0 -147
  53. package/src/charts-d3/funnel.ts +0 -104
  54. package/src/charts-d3/heatmap.ts +0 -145
  55. package/src/charts-d3/index.ts +0 -337
  56. package/src/charts-d3/interactions.ts +0 -477
  57. package/src/charts-d3/line.ts +0 -344
  58. package/src/charts-d3/mount.ts +0 -151
  59. package/src/charts-d3/pie.ts +0 -117
  60. package/src/charts-d3/polar.ts +0 -89
  61. package/src/charts-d3/radar.ts +0 -0
  62. package/src/charts-d3/sankey.ts +0 -0
  63. package/src/charts-d3/scatter.ts +0 -185
  64. package/src/charts-d3/shared.ts +0 -208
  65. package/src/class/layout.ts +0 -326
  66. package/src/class/parser.ts +0 -635
  67. package/src/class/renderer.ts +0 -793
  68. package/src/class/types.ts +0 -58
  69. package/src/cli-banner.ts +0 -106
  70. package/src/cli.ts +0 -1080
  71. package/src/colors-diagnostics.ts +0 -35
  72. package/src/colors.ts +0 -379
  73. package/src/completion-types.ts +0 -27
  74. package/src/completion.ts +0 -2668
  75. package/src/cycle/layout.ts +0 -1026
  76. package/src/cycle/parser.ts +0 -387
  77. package/src/cycle/renderer.ts +0 -653
  78. package/src/cycle/types.ts +0 -101
  79. package/src/d3.ts +0 -1434
  80. package/src/data-chart-parser.ts +0 -1007
  81. package/src/dgmo-router.ts +0 -296
  82. package/src/diagnostics-registry.ts +0 -108
  83. package/src/diagnostics.ts +0 -0
  84. package/src/dimensions.ts +0 -20
  85. package/src/directives-registry.ts +0 -396
  86. package/src/editor/dgmo.grammar +0 -76
  87. package/src/editor/dgmo.grammar.d.ts +0 -2
  88. package/src/editor/dgmo.grammar.js +0 -18
  89. package/src/editor/dgmo.grammar.terms.d.ts +0 -5
  90. package/src/editor/dgmo.grammar.terms.js +0 -35
  91. package/src/editor/highlight-api.ts +0 -596
  92. package/src/editor/highlight.ts +0 -36
  93. package/src/editor/index.ts +0 -27
  94. package/src/editor/keywords.ts +0 -128
  95. package/src/editor/tokens.ts +0 -30
  96. package/src/element/index.ts +0 -432
  97. package/src/embed/css.ts +0 -312
  98. package/src/embed/escape.ts +0 -15
  99. package/src/embed/index.ts +0 -280
  100. package/src/er/classify.ts +0 -228
  101. package/src/er/layout.ts +0 -530
  102. package/src/er/parser.ts +0 -750
  103. package/src/er/renderer.ts +0 -725
  104. package/src/er/types.ts +0 -52
  105. package/src/error-card.ts +0 -269
  106. package/src/event-line/diagnostics.ts +0 -117
  107. package/src/event-line/parser.ts +0 -643
  108. package/src/event-line/renderer.ts +0 -1742
  109. package/src/event-line/types.ts +0 -74
  110. package/src/fonts.ts +0 -3
  111. package/src/gantt/calculator.ts +0 -979
  112. package/src/gantt/parser.ts +0 -1641
  113. package/src/gantt/renderer.ts +0 -3787
  114. package/src/gantt/resolver.ts +0 -172
  115. package/src/gantt/types.ts +0 -206
  116. package/src/graph/diagnostics.ts +0 -64
  117. package/src/graph/edge-spline.ts +0 -29
  118. package/src/graph/flowchart-parser.ts +0 -759
  119. package/src/graph/flowchart-renderer.ts +0 -817
  120. package/src/graph/layout.ts +0 -472
  121. package/src/graph/notes.ts +0 -21
  122. package/src/graph/state-collapse.ts +0 -78
  123. package/src/graph/state-parser.ts +0 -574
  124. package/src/graph/state-renderer.ts +0 -653
  125. package/src/graph/types.ts +0 -65
  126. package/src/index.ts +0 -261
  127. package/src/infra/compute.ts +0 -1385
  128. package/src/infra/layout.ts +0 -888
  129. package/src/infra/parser.ts +0 -1234
  130. package/src/infra/renderer.ts +0 -2534
  131. package/src/infra/roles.ts +0 -75
  132. package/src/infra/types.ts +0 -216
  133. package/src/infra/validation.ts +0 -201
  134. package/src/journey-map/layout.ts +0 -490
  135. package/src/journey-map/parser.ts +0 -557
  136. package/src/journey-map/renderer.ts +0 -1580
  137. package/src/journey-map/types.ts +0 -47
  138. package/src/kanban/mutations.ts +0 -175
  139. package/src/kanban/parser.ts +0 -509
  140. package/src/kanban/renderer.ts +0 -1449
  141. package/src/kanban/types.ts +0 -39
  142. package/src/label-layout.ts +0 -368
  143. package/src/map/colorize.ts +0 -54
  144. package/src/map/completion.ts +0 -316
  145. package/src/map/context-labels.ts +0 -609
  146. package/src/map/data/PROVENANCE.json +0 -1
  147. package/src/map/data/README.md +0 -40
  148. package/src/map/data/airport-collisions.json +0 -1
  149. package/src/map/data/airports.json +0 -1
  150. package/src/map/data/gazetteer.json +0 -1
  151. package/src/map/data/lakes.json +0 -1
  152. package/src/map/data/mountain-ranges.json +0 -1
  153. package/src/map/data/na-lakes.json +0 -1
  154. package/src/map/data/na-land.json +0 -1
  155. package/src/map/data/region-names.json +0 -1
  156. package/src/map/data/rivers.json +0 -1
  157. package/src/map/data/types.ts +0 -121
  158. package/src/map/data/us-states.json +0 -1
  159. package/src/map/data/water-bodies.json +0 -1
  160. package/src/map/data/world-coarse.json +0 -1
  161. package/src/map/data/world-detail.json +0 -1
  162. package/src/map/diagnostics.ts +0 -134
  163. package/src/map/dimensions.ts +0 -150
  164. package/src/map/geo-query.ts +0 -295
  165. package/src/map/geo.ts +0 -438
  166. package/src/map/invert.ts +0 -111
  167. package/src/map/layout.ts +0 -5069
  168. package/src/map/legend-band.ts +0 -127
  169. package/src/map/load-data.ts +0 -186
  170. package/src/map/parser.ts +0 -783
  171. package/src/map/renderer.ts +0 -1445
  172. package/src/map/resolved-types.ts +0 -160
  173. package/src/map/resolver.ts +0 -1146
  174. package/src/map/types.ts +0 -194
  175. package/src/mindmap/collapse.ts +0 -67
  176. package/src/mindmap/layout.ts +0 -649
  177. package/src/mindmap/parser.ts +0 -430
  178. package/src/mindmap/renderer.ts +0 -637
  179. package/src/mindmap/text-wrap.ts +0 -218
  180. package/src/mindmap/types.ts +0 -56
  181. package/src/org/collapse.ts +0 -151
  182. package/src/org/layout.ts +0 -1262
  183. package/src/org/parser.ts +0 -519
  184. package/src/org/renderer.ts +0 -866
  185. package/src/org/resolver.ts +0 -636
  186. package/src/palettes/atlas.ts +0 -77
  187. package/src/palettes/blueprint.ts +0 -73
  188. package/src/palettes/catppuccin.ts +0 -84
  189. package/src/palettes/color-utils.ts +0 -443
  190. package/src/palettes/index.ts +0 -67
  191. package/src/palettes/nord.ts +0 -67
  192. package/src/palettes/registry.ts +0 -114
  193. package/src/palettes/slate.ts +0 -73
  194. package/src/palettes/tidewater.ts +0 -73
  195. package/src/palettes/tokyo-night.ts +0 -86
  196. package/src/palettes/types.ts +0 -88
  197. package/src/pert/analyzer.ts +0 -1183
  198. package/src/pert/diagnostics.ts +0 -110
  199. package/src/pert/index.ts +0 -43
  200. package/src/pert/internal.ts +0 -252
  201. package/src/pert/layout.ts +0 -971
  202. package/src/pert/monte-carlo.ts +0 -446
  203. package/src/pert/parser.ts +0 -1606
  204. package/src/pert/renderer.ts +0 -4009
  205. package/src/pert/share-normalize.ts +0 -62
  206. package/src/pert/types.ts +0 -604
  207. package/src/pyramid/parser.ts +0 -185
  208. package/src/pyramid/renderer.ts +0 -768
  209. package/src/pyramid/types.ts +0 -28
  210. package/src/quadrant/parser.ts +0 -18
  211. package/src/quadrant/renderer.ts +0 -638
  212. package/src/raci/diagnostics.ts +0 -213
  213. package/src/raci/index.ts +0 -23
  214. package/src/raci/mutations.ts +0 -321
  215. package/src/raci/parser.ts +0 -699
  216. package/src/raci/renderer.ts +0 -1627
  217. package/src/raci/types.ts +0 -82
  218. package/src/raci/variants.ts +0 -320
  219. package/src/render.ts +0 -268
  220. package/src/ring/parser.ts +0 -212
  221. package/src/ring/renderer.ts +0 -490
  222. package/src/ring/types.ts +0 -27
  223. package/src/sequence/collapse.ts +0 -174
  224. package/src/sequence/parser.ts +0 -1596
  225. package/src/sequence/participant-inference.ts +0 -152
  226. package/src/sequence/renderer.ts +0 -3168
  227. package/src/sequence/tag-resolution.ts +0 -164
  228. package/src/sharing.ts +0 -211
  229. package/src/sitemap/collapse.ts +0 -100
  230. package/src/sitemap/layout.ts +0 -925
  231. package/src/sitemap/parser.ts +0 -755
  232. package/src/sitemap/renderer.ts +0 -828
  233. package/src/sitemap/types.ts +0 -42
  234. package/src/slope/parser.ts +0 -18
  235. package/src/slope/renderer.ts +0 -378
  236. package/src/swimlane/diagnostics.ts +0 -94
  237. package/src/swimlane/layout.ts +0 -597
  238. package/src/swimlane/parser.ts +0 -613
  239. package/src/swimlane/renderer.ts +0 -681
  240. package/src/swimlane/types.ts +0 -151
  241. package/src/tech-radar/interactive.ts +0 -1129
  242. package/src/tech-radar/layout.ts +0 -197
  243. package/src/tech-radar/parser.ts +0 -436
  244. package/src/tech-radar/renderer.ts +0 -1239
  245. package/src/tech-radar/shared.ts +0 -151
  246. package/src/tech-radar/types.ts +0 -86
  247. package/src/themes.ts +0 -22
  248. package/src/timeline/parser.ts +0 -472
  249. package/src/timeline/renderer.ts +0 -3024
  250. package/src/timeline/types.ts +0 -33
  251. package/src/timeline/viz-parser.ts +0 -21
  252. package/src/treemap/diagnostics.ts +0 -62
  253. package/src/treemap/layout-radial.ts +0 -233
  254. package/src/treemap/layout.ts +0 -189
  255. package/src/treemap/parser.ts +0 -463
  256. package/src/treemap/renderer-radial.ts +0 -438
  257. package/src/treemap/renderer.ts +0 -572
  258. package/src/treemap/treemap-shared.ts +0 -309
  259. package/src/treemap/types.ts +0 -60
  260. package/src/utils/arrow-markers.ts +0 -51
  261. package/src/utils/arrows-diagnostics.ts +0 -62
  262. package/src/utils/arrows.ts +0 -227
  263. package/src/utils/brand.ts +0 -61
  264. package/src/utils/card.ts +0 -183
  265. package/src/utils/collapse-engine/tree-edges.ts +0 -115
  266. package/src/utils/collapse-engine/tree.ts +0 -117
  267. package/src/utils/d3-helpers.ts +0 -219
  268. package/src/utils/d3-types.ts +0 -9
  269. package/src/utils/description-helpers.ts +0 -38
  270. package/src/utils/duration.ts +0 -312
  271. package/src/utils/export-container.ts +0 -41
  272. package/src/utils/expr-eval.ts +0 -27
  273. package/src/utils/fit-canvas.ts +0 -64
  274. package/src/utils/hover-styles.ts +0 -673
  275. package/src/utils/inline-markdown.ts +0 -96
  276. package/src/utils/legend-constants.ts +0 -48
  277. package/src/utils/legend-d3.ts +0 -618
  278. package/src/utils/legend-integration.ts +0 -107
  279. package/src/utils/legend-layout.ts +0 -776
  280. package/src/utils/legend-svg.ts +0 -214
  281. package/src/utils/legend-types.ts +0 -272
  282. package/src/utils/name-normalize.ts +0 -163
  283. package/src/utils/note-box/constants.ts +0 -25
  284. package/src/utils/note-box/index.ts +0 -11
  285. package/src/utils/note-box/metrics.ts +0 -90
  286. package/src/utils/note-box/svg.ts +0 -331
  287. package/src/utils/notes/bounds.ts +0 -30
  288. package/src/utils/notes/build.ts +0 -131
  289. package/src/utils/notes/index.ts +0 -18
  290. package/src/utils/notes/model.ts +0 -19
  291. package/src/utils/notes/parse.ts +0 -131
  292. package/src/utils/notes/place.ts +0 -177
  293. package/src/utils/notes/resolve.ts +0 -88
  294. package/src/utils/number-format.ts +0 -36
  295. package/src/utils/parsing.ts +0 -953
  296. package/src/utils/reserved-key-registry.ts +0 -239
  297. package/src/utils/safe-href.ts +0 -38
  298. package/src/utils/scaling.ts +0 -97
  299. package/src/utils/svg-embed.ts +0 -251
  300. package/src/utils/tag-groups.ts +0 -607
  301. package/src/utils/text-measure.ts +0 -122
  302. package/src/utils/time-ticks.ts +0 -253
  303. package/src/utils/title-constants.ts +0 -24
  304. package/src/utils/visual-conventions.ts +0 -61
  305. package/src/utils/wrapped-desc.ts +0 -87
  306. package/src/venn/parser.ts +0 -18
  307. package/src/venn/renderer.ts +0 -1047
  308. package/src/version-control/diagnostics.ts +0 -67
  309. package/src/version-control/parser.ts +0 -544
  310. package/src/version-control/renderer.ts +0 -724
  311. package/src/version-control/types.ts +0 -100
  312. package/src/visualizations/parse.ts +0 -1560
  313. package/src/visualizations/types.ts +0 -262
  314. package/src/wireframe/layout.ts +0 -479
  315. package/src/wireframe/parser.ts +0 -1114
  316. package/src/wireframe/renderer.ts +0 -1318
  317. package/src/wireframe/types.ts +0 -110
  318. package/src/wordcloud/parser.ts +0 -18
  319. package/src/wordcloud/renderer.ts +0 -357
@@ -1,67 +0,0 @@
1
- // ============================================================
2
- // Version-Control (git graph) — Diagnostic Registry
3
- // ============================================================
4
- //
5
- // Declarative catalog of version-control-specific diagnostics. This is
6
- // the single source of truth for the codes/wording the parser emits via
7
- // `emit(VERSION_CONTROL_DX.<KEY>, line, params)`. Consumers (the CLI
8
- // `diagnostics` subcommand, the console error-review surface, MCP
9
- // `validate_diagram`, and the spec docs) enumerate this catalog; the
10
- // parser never re-types wording at the call site.
11
- //
12
- // Message builders mirror the parser's exact wording. They tolerate being
13
- // called with `{}` so the catalog can render a representative message
14
- // without live params.
15
- //
16
- // Notes on fidelity:
17
- // - `E_VERSION_CONTROL_UNKNOWN_BRANCH` is emitted from THREE sites with
18
- // slightly different wording — `merge references … (§29.4)`,
19
- // `rebase references … (§29.8)`, and `reset references … (§29.8)`. The
20
- // builder below parameterizes the verb (`op`), branch, and section so it
21
- // reproduces any of the three exactly; the representative `{}` form uses
22
- // the `merge` wording.
23
-
24
- import type { DiagnosticSpec } from '../diagnostics';
25
-
26
- /** Keyed specs — referenced by the parser's `emit()` call sites. */
27
- export const VERSION_CONTROL_DX = {
28
- NO_COMMITS: {
29
- code: 'E_VERSION_CONTROL_NO_COMMITS',
30
- severity: 'error',
31
- chartType: 'version-control',
32
- title: 'No commits',
33
- message: 'version-control has no commits.',
34
- hint: 'Add at least one indented commit line under a branch.',
35
- example: 'version-control Empty',
36
- },
37
- UNKNOWN_BRANCH: {
38
- code: 'E_VERSION_CONTROL_UNKNOWN_BRANCH',
39
- severity: 'warning',
40
- chartType: 'version-control',
41
- title: 'Unknown branch reference',
42
- message: (p) => {
43
- const op = (p.op as string) ?? 'merge';
44
- const branch = (p.branch as string) ?? 'ghostbranch';
45
- const section = (p.section as string) ?? '§29.4';
46
- return `${op} references unknown branch "${branch}". (${section})`;
47
- },
48
- hint: 'Declare the branch (a bare top-level line) before referencing it in merge/rebase/reset.',
49
- example: 'version-control U\n\nmain\n A\n merge ghostbranch',
50
- },
51
- AMBIGUOUS_REF: {
52
- code: 'E_VERSION_CONTROL_AMBIGUOUS_REF',
53
- severity: 'warning',
54
- chartType: 'version-control',
55
- title: 'Ambiguous commit reference',
56
- message: (p) => {
57
- const ref = (p.ref as string) ?? 'Fix';
58
- const count = (p.count as number | string) ?? 2;
59
- return `Commit reference "${ref}" matches ${count} commits — use an explicit id:. (§29.10)`;
60
- },
61
- hint: 'Give the target commit an `id:` and reference that id, or make the message unique.',
62
- example: 'version-control A\n\nmain\n Fix\n Fix\n cherry-pick Fix',
63
- },
64
- } satisfies Record<string, DiagnosticSpec>;
65
-
66
- export const VERSION_CONTROL_DIAGNOSTICS: DiagnosticSpec[] =
67
- Object.values(VERSION_CONTROL_DX);
@@ -1,544 +0,0 @@
1
- // ============================================================
2
- // Version-Control — Parser (spec §29)
3
- // ============================================================
4
- //
5
- // Keyword-less grammar: a bare top-level line is a branch, a bare indented line
6
- // is a commit. Re-naming a branch resumes it (replaces `checkout`). Only `merge`
7
- // and `cherry-pick` are required verbs; beyond-Mermaid verbs `ref` / `rebase` /
8
- // `reset` (top-level) and `revert` / `note` (indented) add HEAD + remote-tracking,
9
- // the rebase/reset/revert/squash operations, and step annotations. The parser
10
- // also does the topological placement (seq) and the rebase/reset/squash/revert
11
- // transforms — the renderer only does pixel layout + SVG. Mirrors
12
- // docs/version-control-syntax-mockups.html parse().
13
-
14
- import type { PaletteColors } from '../palettes';
15
- import { emit, formatDgmoError, makeFail, suggest } from '../diagnostics';
16
- import type { DgmoError } from '../diagnostics';
17
- import { VERSION_CONTROL_DX } from './diagnostics';
18
- import type { Writable } from '../utils/brand';
19
- import { measureIndent, parseFirstLine, extractColor } from '../utils/parsing';
20
- import type {
21
- ParsedVersionControl,
22
- VCBranch,
23
- VCDirection,
24
- VCNode,
25
- VCNote,
26
- VCOptions,
27
- VCRef,
28
- } from './types';
29
-
30
- interface WorkBranch {
31
- name: string;
32
- creationLane: number;
33
- colorToken: string | null;
34
- order: number | null;
35
- tip: number | null;
36
- pendingParent: number | null;
37
- ab: { ahead: number; behind: number } | null;
38
- }
39
-
40
- type Mut = Writable<VCNode>;
41
-
42
- export function parseVersionControl(
43
- content: string,
44
- palette?: PaletteColors
45
- ): ParsedVersionControl {
46
- const options: Writable<VCOptions> = {
47
- direction: 'LR',
48
- noLabels: false,
49
- noLanes: false,
50
- noHead: false,
51
- };
52
- const result: Writable<ParsedVersionControl> = {
53
- type: 'version-control',
54
- title: null,
55
- titleLineNumber: null,
56
- nodes: [],
57
- branches: [],
58
- refs: [],
59
- notes: [],
60
- options,
61
- diagnostics: [],
62
- error: null,
63
- };
64
-
65
- const fail = makeFail(result);
66
-
67
- if (!content?.trim()) return fail(0, 'No content provided');
68
-
69
- const nodes = result.nodes as Mut[];
70
- const branches = new Map<string, WorkBranch>();
71
- const order: string[] = [];
72
- const refs = result.refs as Writable<VCRef>[];
73
- const notes = result.notes as Writable<VCNote>[];
74
- let active: string | null = null;
75
- let seq = 0;
76
- let laneCounter = 0;
77
- let headerParsed = false;
78
-
79
- const makeBranch = (
80
- name: string,
81
- parentName: string | null,
82
- colorToken: string | null,
83
- ord: number | null
84
- ): WorkBranch => {
85
- const existing = branches.get(name);
86
- if (existing) return existing;
87
- const b: WorkBranch = {
88
- name,
89
- creationLane: laneCounter++,
90
- colorToken,
91
- order: ord,
92
- tip: null,
93
- pendingParent: null,
94
- ab: null,
95
- };
96
- if (parentName != null) {
97
- const par = branches.get(parentName);
98
- b.pendingParent = par ? par.tip : null;
99
- }
100
- branches.set(name, b);
101
- order.push(name);
102
- return b;
103
- };
104
-
105
- const matchesRef = (ref: string): Mut[] =>
106
- nodes.filter((n) => n.message === ref || n.id === ref);
107
- const findByRef = (ref: string, lineNumber: number): Mut | null => {
108
- const m = matchesRef(ref);
109
- if (m.length === 0) return null;
110
- if (m.length > 1 && !/^[0-9a-f]{4,}$/.test(ref)) {
111
- result.diagnostics.push(
112
- emit(VERSION_CONTROL_DX.AMBIGUOUS_REF, lineNumber, {
113
- ref,
114
- count: m.length,
115
- })
116
- );
117
- }
118
- return m[m.length - 1]!;
119
- };
120
-
121
- const addNode = (
122
- fields: Pick<VCNode, 'kind' | 'message' | 'type' | 'tag' | 'lineNumber'> & {
123
- id: string | null;
124
- }
125
- ): Mut => {
126
- const b = branches.get(active!)!;
127
- const id = fields.id ?? null;
128
- const node: Mut = {
129
- key: nodes.length,
130
- branch: active!,
131
- lane: b.creationLane,
132
- seq: seq++,
133
- kind: fields.kind,
134
- message: fields.message,
135
- type: fields.type,
136
- id,
137
- tag: fields.tag,
138
- lineNumber: fields.lineNumber,
139
- prev: b.tip,
140
- parent: null,
141
- mergeFrom: null,
142
- cherryFrom: null,
143
- revertFrom: null,
144
- squashFrom: null,
145
- movedTo: null,
146
- ghost: false,
147
- };
148
- if (b.pendingParent != null && node.prev === null) {
149
- node.parent = b.pendingParent;
150
- b.pendingParent = null;
151
- }
152
- b.tip = node.key;
153
- nodes.push(node);
154
- return node;
155
- };
156
-
157
- const ensureActive = (lineNumber: number): void => {
158
- if (!active) {
159
- makeBranch('main', null, null, null);
160
- active = 'main';
161
- }
162
- void lineNumber;
163
- };
164
-
165
- const doRebase = (fb: string, tb: string, lineNumber: number): void => {
166
- const fbr = branches.get(fb);
167
- const tbr = branches.get(tb);
168
- if (!fbr || !tbr) {
169
- result.diagnostics.push(
170
- emit(VERSION_CONTROL_DX.UNKNOWN_BRANCH, lineNumber, {
171
- op: 'rebase',
172
- branch: !fbr ? fb : tb,
173
- section: '§29.8',
174
- })
175
- );
176
- return;
177
- }
178
- const feats = nodes
179
- .filter((n) => n.branch === fb)
180
- .sort((a, b) => a.seq - b.seq);
181
- let prev: number | null = null;
182
- const first = tbr.tip;
183
- for (const o of feats) {
184
- o.ghost = true;
185
- const copy: Mut = {
186
- key: nodes.length,
187
- branch: fb,
188
- lane: fbr.creationLane,
189
- seq: seq++,
190
- kind: 'commit',
191
- message: o.message,
192
- type: o.type,
193
- id: o.id,
194
- tag: o.tag,
195
- lineNumber: o.lineNumber,
196
- prev,
197
- parent: prev == null ? first : null,
198
- mergeFrom: null,
199
- cherryFrom: null,
200
- revertFrom: null,
201
- squashFrom: null,
202
- movedTo: null,
203
- ghost: false,
204
- };
205
- o.movedTo = copy.key;
206
- nodes.push(copy);
207
- prev = copy.key;
208
- }
209
- fbr.tip = prev;
210
- active = fb;
211
- };
212
-
213
- const lines = content.split('\n');
214
- for (let i = 0; i < lines.length; i++) {
215
- const line = lines[i]!;
216
- const lineNumber = i + 1;
217
- const trimmed = line.trim();
218
- if (!trimmed || trimmed.startsWith('//')) continue;
219
- const indent = measureIndent(line);
220
-
221
- // ── First line: `version-control [Title]` ──
222
- if (!headerParsed) {
223
- const firstLine = parseFirstLine(trimmed);
224
- if (firstLine?.chartType === 'version-control') {
225
- result.title = firstLine.title ?? null;
226
- result.titleLineNumber = lineNumber;
227
- headerParsed = true;
228
- continue;
229
- }
230
- let msg = 'Expected "version-control [Title]" as the first line.';
231
- const hint = suggest(firstLine?.chartType ?? trimmed, [
232
- 'version-control',
233
- ]);
234
- if (hint) msg += ` ${hint}`;
235
- return fail(lineNumber, msg);
236
- }
237
-
238
- // ── Directives ──
239
- const dir = /^direction\s+(LR|TB|BT)$/i.exec(trimmed);
240
- if (dir) {
241
- options.direction = dir[1]!.toUpperCase() as VCDirection;
242
- continue;
243
- }
244
- if (trimmed === 'no-labels') {
245
- options.noLabels = true;
246
- continue;
247
- }
248
- if (trimmed === 'no-lanes') {
249
- options.noLanes = true;
250
- continue;
251
- }
252
- if (trimmed === 'no-head') {
253
- options.noHead = true;
254
- continue;
255
- }
256
-
257
- if (indent === 0) {
258
- // ── Top-level operation verbs ──
259
- let m: RegExpExecArray | null;
260
- if ((m = /^ref\s+(.+?)\s+at\s+(.+?)(?:\s+(remote))?$/.exec(trimmed))) {
261
- const nm = m[1]!.trim();
262
- const tgt = findByRef(m[2]!.trim(), lineNumber);
263
- refs.push({
264
- name: nm,
265
- atKey: tgt ? tgt.key : null,
266
- remote: !!m[3] || /^(origin|upstream)\//.test(nm),
267
- head: nm === 'HEAD',
268
- lineNumber,
269
- });
270
- continue;
271
- }
272
- if ((m = /^rebase\s+(.+?)\s+onto\s+(.+)$/.exec(trimmed))) {
273
- doRebase(m[1]!.trim(), m[2]!.trim(), lineNumber);
274
- continue;
275
- }
276
- if ((m = /^reset\s+(.+?)\s+to\s+(.+)$/.exec(trimmed))) {
277
- const br = branches.get(m[1]!.trim());
278
- const tgt = findByRef(m[2]!.trim(), lineNumber);
279
- if (!br) {
280
- result.diagnostics.push(
281
- emit(VERSION_CONTROL_DX.UNKNOWN_BRANCH, lineNumber, {
282
- op: 'reset',
283
- branch: m[1]!.trim(),
284
- section: '§29.8',
285
- })
286
- );
287
- } else if (tgt) {
288
- for (const n of nodes) {
289
- if (n.branch === br.name && n.seq > tgt.seq) n.ghost = true;
290
- }
291
- br.tip = tgt.key;
292
- active = br.name;
293
- }
294
- continue;
295
- }
296
-
297
- // ── Branch declaration / resume ──
298
- // extractColor strips + validates the trailing token (§1.5 diagnostics) and
299
- // resolves to hex; we keep the NAME so the renderer resolves per-palette.
300
- const lastWord = trimmed.split(/\s+/).pop() ?? '';
301
- const colored = extractColor(
302
- trimmed,
303
- palette,
304
- result.diagnostics as DgmoError[],
305
- lineNumber
306
- );
307
- let rest = colored.label;
308
- const colorToken = colored.color !== undefined ? lastWord : null;
309
- let ord: number | null = null;
310
- const om = /\s+order:\s*(\d+)\s*$/.exec(rest);
311
- if (om) {
312
- ord = Number(om[1]);
313
- rest = rest.replace(/\s+order:\s*\d+\s*$/, '');
314
- }
315
- let name = rest.trim();
316
- let parent: string | null = null;
317
- const fm = rest.split(/\s+from\s+/);
318
- if (fm.length === 2) {
319
- name = fm[0]!.trim();
320
- parent = fm[1]!.trim();
321
- }
322
- const existing = branches.get(name);
323
- if (existing) {
324
- active = name;
325
- } else {
326
- makeBranch(name, parent != null ? parent : active, colorToken, ord);
327
- active = name;
328
- }
329
- continue;
330
- }
331
-
332
- // ── Indented: explicit verbs, else a commit ──
333
- ensureActive(lineNumber);
334
- let m: RegExpExecArray | null;
335
- if (/^merge\b/.test(trimmed)) {
336
- const { msg, tag, id, type } = peelMeta(trimmed.slice(5).trim());
337
- let src = msg.trim();
338
- let strat: string | null = null;
339
- const sm = /^(.*?)\s+(squash|ff|no-ff)$/.exec(src);
340
- if (sm) {
341
- src = sm[1]!.trim();
342
- strat = sm[2]!;
343
- }
344
- const sb = branches.get(src);
345
- if (!sb) {
346
- result.diagnostics.push(
347
- emit(VERSION_CONTROL_DX.UNKNOWN_BRANCH, lineNumber, {
348
- op: 'merge',
349
- branch: src,
350
- section: '§29.4',
351
- })
352
- );
353
- }
354
- if (strat === 'squash') {
355
- if (sb) for (const n of nodes) if (n.branch === src) n.ghost = true;
356
- const node = addNode({
357
- kind: 'commit',
358
- message: `Squash ${src}`,
359
- type: 'normal',
360
- tag: tag ?? null,
361
- id: id ?? null,
362
- lineNumber,
363
- });
364
- node.squashFrom = sb ? sb.tip : null;
365
- } else {
366
- const node = addNode({
367
- kind: 'merge',
368
- message: src,
369
- type: (type as VCNode['type']) ?? 'normal',
370
- tag: tag ?? null,
371
- id: id ?? null,
372
- lineNumber,
373
- });
374
- node.mergeFrom = sb ? sb.tip : null;
375
- }
376
- continue;
377
- }
378
- if (/^cherry-pick\b/.test(trimmed)) {
379
- const ref = trimmed.slice(11).trim();
380
- const s = findByRef(ref, lineNumber);
381
- const node = addNode({
382
- kind: 'cherry',
383
- message: ref,
384
- type: 'normal',
385
- tag: null,
386
- id: null,
387
- lineNumber,
388
- });
389
- node.cherryFrom = s ? s.key : null;
390
- continue;
391
- }
392
- if (/^revert\b/.test(trimmed)) {
393
- const ref = trimmed.slice(6).trim();
394
- const s = findByRef(ref, lineNumber);
395
- const node = addNode({
396
- kind: 'commit',
397
- message: s ? `Revert ${s.message}` : 'Revert',
398
- type: 'reverse',
399
- tag: null,
400
- id: null,
401
- lineNumber,
402
- });
403
- node.revertFrom = s ? s.key : null;
404
- continue;
405
- }
406
- if ((m = /^note\b\s*(.*)$/.exec(trimmed))) {
407
- const b = branches.get(active!)!;
408
- notes.push({
409
- num: notes.length + 1,
410
- anchorKey: b.tip,
411
- text: m[1]!.trim(),
412
- lineNumber,
413
- });
414
- continue;
415
- }
416
- // bare commit — `commit` keyword optional (empty/dotless only)
417
- const body = trimmed.replace(/^commit\b\s*/, '');
418
- const { msg, tag, id, type } = peelMeta(body);
419
- addNode({
420
- kind: 'commit',
421
- message: msg || null,
422
- type: (type as VCNode['type']) ?? 'normal',
423
- tag: tag ?? null,
424
- id: id ?? null,
425
- lineNumber,
426
- });
427
- }
428
-
429
- // ── HEAD auto-sits on the active tip ──
430
- if (!options.noHead && active) {
431
- const tip = branches.get(active)!.tip;
432
- if (tip != null && !refs.some((r) => r.head)) {
433
- refs.push({
434
- name: 'HEAD',
435
- atKey: tip,
436
- remote: false,
437
- head: true,
438
- lineNumber: 0,
439
- });
440
- }
441
- }
442
-
443
- // ── Ahead/behind: local branch X vs an origin/X ref (DAG set difference) ──
444
- const ancestors = (key: number): Set<number> => {
445
- const seen = new Set<number>();
446
- const st = [key];
447
- while (st.length) {
448
- const k = st.pop()!;
449
- if (seen.has(k)) continue;
450
- seen.add(k);
451
- const n = nodes[k];
452
- if (n) {
453
- if (n.prev != null) st.push(n.prev);
454
- if (n.parent != null) st.push(n.parent);
455
- if (n.mergeFrom != null) st.push(n.mergeFrom);
456
- }
457
- }
458
- return seen;
459
- };
460
- for (const bn of order) {
461
- const b = branches.get(bn)!;
462
- if (b.tip == null) continue;
463
- const rr = refs.find(
464
- (r) =>
465
- r.remote && (r.name === `origin/${bn}` || r.name.endsWith(`/${bn}`))
466
- );
467
- if (rr?.atKey != null) {
468
- const A = ancestors(b.tip);
469
- const B = ancestors(rr.atKey);
470
- let ahead = 0;
471
- let behind = 0;
472
- A.forEach((k) => {
473
- if (!B.has(k)) ahead++;
474
- });
475
- B.forEach((k) => {
476
- if (!A.has(k)) behind++;
477
- });
478
- b.ab = { ahead, behind };
479
- }
480
- }
481
-
482
- // ── Lane ordering: honor `order:`, else declaration order ──
483
- const ordered = [...order].sort((a, b) => {
484
- const ba = branches.get(a)!;
485
- const bb = branches.get(b)!;
486
- const ka = ba.order ?? ba.creationLane;
487
- const kb = bb.order ?? bb.creationLane;
488
- return ka - kb || ba.creationLane - bb.creationLane;
489
- });
490
- const laneOf = new Map<string, number>();
491
- ordered.forEach((nm, idx) => laneOf.set(nm, idx));
492
- for (const n of nodes) (n as Mut).lane = laneOf.get(n.branch)!;
493
-
494
- // ── Emit branch list (declaration order preserved for legend/gutter) ──
495
- result.branches = order.map((nm): VCBranch => {
496
- const b = branches.get(nm)!;
497
- return {
498
- name: nm,
499
- lane: laneOf.get(nm)!,
500
- colorToken: b.colorToken,
501
- order: b.order,
502
- tip: b.tip,
503
- ab: b.ab,
504
- };
505
- });
506
-
507
- if (nodes.length === 0 && !result.error) {
508
- const diag = emit(
509
- VERSION_CONTROL_DX.NO_COMMITS,
510
- result.titleLineNumber ?? 1
511
- );
512
- result.diagnostics.push(diag);
513
- result.error = formatDgmoError(diag);
514
- }
515
-
516
- return result;
517
- }
518
-
519
- /** Peel same-line `id:` / `tag:` / `type:` metadata off a commit/merge body. */
520
- function peelMeta(s: string): {
521
- msg: string;
522
- tag: string | null;
523
- type: string | null;
524
- id: string | null;
525
- } {
526
- const out = {
527
- msg: s,
528
- tag: null as string | null,
529
- type: null as string | null,
530
- id: null as string | null,
531
- };
532
- const idx = s.search(/\b(tag|type|id)\s*:/);
533
- if (idx >= 0) {
534
- out.msg = s.slice(0, idx).trim();
535
- const re = /(tag|type|id)\s*:\s*([^,]+)/g;
536
- let m: RegExpExecArray | null;
537
- const rest = s.slice(idx);
538
- while ((m = re.exec(rest)) !== null) {
539
- const k = m[1] as 'tag' | 'type' | 'id';
540
- out[k] = m[2]!.trim();
541
- }
542
- }
543
- return out;
544
- }