@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,643 +0,0 @@
1
- // ============================================================
2
- // Event Line — Parser (spec §28)
3
- // ============================================================
4
- //
5
- // Consistency-locked syntax (decision #16) — every token reuses an idiom:
6
- // - event + date = timeline §15 line-prefix (`2012-02-05 XLVI`), date optional
7
- // - tag = trailing same-line metadata (`… XLVI g: Pop`)
8
- // - description = pyramid/ring bare indented body (`- ` bullets + markdown)
9
- // - directives = `no-scale` / `no-box` / `side above|below`
10
- //
11
- // Structure mirrors treemap's header/tag-block/content phases and pyramid's
12
- // bare-body description collection.
13
-
14
- import type { PaletteColors } from '../palettes';
15
- import {
16
- emit,
17
- formatDgmoError,
18
- makeDgmoError,
19
- makeFail,
20
- suggest,
21
- } from '../diagnostics';
22
- import type { DgmoError } from '../diagnostics';
23
- import { EVENT_LINE_DX } from './diagnostics';
24
- import type { Writable } from '../utils/brand';
25
- import type { TagGroup } from '../utils/tag-groups';
26
- import {
27
- matchTagBlockHeading,
28
- validateTagValues,
29
- validateTagGroupNames,
30
- stripDefaultModifier,
31
- finalizeAutoTagColors,
32
- injectDefaultTagMetadata,
33
- AUTO_TAG_COLOR_SENTINEL,
34
- tagAttrKey,
35
- } from '../utils/tag-groups';
36
- import {
37
- measureIndent,
38
- extractColor,
39
- parseFirstLine,
40
- splitNameAndMeta,
41
- tryParseSharedOption,
42
- warnUnknownMetaKeys,
43
- } from '../utils/parsing';
44
- import {
45
- EVENT_LINE_REGISTRY,
46
- withTagAliases,
47
- } from '../utils/reserved-key-registry';
48
- import { extractDatePrefix, parseTimelineDate } from '../timeline/parser';
49
- import type {
50
- EventLineEra,
51
- EventLineEvent,
52
- EventLineOptions,
53
- ParsedEventLine,
54
- } from './types';
55
-
56
- /** A non-ISO date attempt: leading digits with a slash or dot separator. */
57
- const NON_ISO_DATE_RE = /^\d{1,4}[/.]\d/;
58
- /** `TBD` date line-prefix (case-insensitive) — a future, unscheduled event. */
59
- const TBD_RE = /^TBD\b/i;
60
- /** `side above` / `side below` / `side alternate` — card placement. */
61
- const SIDE_RE = /^side\s+(above|below|alternate)\b/i;
62
- /** Era run delimiter `[Name]` (§28.6a) with optional trailing `collapsed`/color. */
63
- const ERA_RE = /^\[([^\]]+)\]\s*(.*)$/;
64
- /** `collapsed: true|false` inside an era's trailing metadata. */
65
- const ERA_COLLAPSED_RE = /\bcollapsed:\s*(true|false)\b/i;
66
- /** Legacy `section <Name>` — superseded by `[Name]`; emits a guiding warning. */
67
- const SECTION_SEAM_RE = /^section\b/i;
68
- /** `direction <X>` — only LR (horizontal) is supported; TB/BT are fast-follow. */
69
- const DIRECTION_RE = /^direction\s+(\w+)/i;
70
-
71
- export function parseEventLine(
72
- content: string,
73
- palette?: PaletteColors
74
- ): ParsedEventLine {
75
- const options: Writable<EventLineOptions> = {
76
- scale: true,
77
- side: 'alternate',
78
- noTitle: false,
79
- noBox: false,
80
- noLegend: false,
81
- };
82
- const result: Writable<ParsedEventLine> = {
83
- type: 'event-line',
84
- title: null,
85
- titleLineNumber: null,
86
- events: [],
87
- eras: [],
88
- tagGroups: [],
89
- options,
90
- diagnostics: [],
91
- error: null,
92
- };
93
-
94
- const fail = makeFail(result);
95
- const pushWarning = (line: number, message: string, code?: string): void => {
96
- result.diagnostics.push(makeDgmoError(line, message, 'warning', code));
97
- };
98
- const pushError = (line: number, message: string, code?: string): void => {
99
- const diag = makeDgmoError(line, message, 'error', code);
100
- result.diagnostics.push(diag);
101
- if (!result.error) result.error = formatDgmoError(diag);
102
- };
103
-
104
- if (!content?.trim()) return fail(0, 'No content provided');
105
-
106
- const lines = content.split('\n');
107
- let contentStarted = false;
108
- let headerParsed = false;
109
- const sharedOptions: Record<string, string> = {};
110
-
111
- let currentTagGroup: Writable<TagGroup> | null = null;
112
- let currentEvent: Writable<EventLineEvent> | null = null;
113
- let currentEra: string | null = null;
114
- // Indent of the open era's `[Name]` bracket; events must be indented deeper
115
- // to belong to it. -1 ⇒ no era open (an indent-0 event is then era-less).
116
- let eraIndent = -1;
117
- // Indent of the current event; a line indented deeper is its description.
118
- let currentEventIndent = 0;
119
- const aliasMap = new Map<string, string>();
120
-
121
- for (let i = 0; i < lines.length; i++) {
122
- const line = lines[i]!;
123
- const lineNumber = i + 1;
124
- const trimmed = line.trim();
125
-
126
- if (!trimmed) {
127
- currentTagGroup = null;
128
- continue;
129
- }
130
- if (trimmed.startsWith('//')) continue;
131
-
132
- const indent = measureIndent(line);
133
-
134
- // ── First line: `event-line [Title]` ──
135
- if (!headerParsed) {
136
- const firstLine = parseFirstLine(trimmed);
137
- if (firstLine?.chartType === 'event-line') {
138
- result.title = firstLine.title ?? null;
139
- result.titleLineNumber = lineNumber;
140
- headerParsed = true;
141
- continue;
142
- }
143
- let msg = 'Expected "event-line [Title]" as the first line.';
144
- const hint = suggest(firstLine?.chartType ?? trimmed, ['event-line']);
145
- if (hint) msg += ` ${hint}`;
146
- return fail(lineNumber, msg);
147
- }
148
-
149
- // ── Tag group heading: `tag Genre as g` (before content) ──
150
- const tagBlockMatch = matchTagBlockHeading(trimmed);
151
- if (tagBlockMatch) {
152
- if (contentStarted) {
153
- pushError(
154
- lineNumber,
155
- 'Tag groups must appear before event-line content',
156
- 'E_TAG_DECLARED_AFTER_CONTENT'
157
- );
158
- continue;
159
- }
160
- currentTagGroup = {
161
- name: tagBlockMatch.name,
162
- ...(tagBlockMatch.alias !== undefined && {
163
- alias: tagBlockMatch.alias,
164
- }),
165
- entries: [],
166
- lineNumber,
167
- };
168
- if (tagBlockMatch.alias) {
169
- aliasMap.set(
170
- tagBlockMatch.alias.toLowerCase(),
171
- tagAttrKey(tagBlockMatch.name)
172
- );
173
- }
174
- aliasMap.set(
175
- tagAttrKey(tagBlockMatch.name),
176
- tagAttrKey(tagBlockMatch.name)
177
- );
178
- result.tagGroups.push(currentTagGroup);
179
- continue;
180
- }
181
-
182
- // ── Tag entries (indented `Value color` under a heading) ──
183
- if (currentTagGroup && !contentStarted && indent > 0) {
184
- const { text: cleanEntry, isDefault } = stripDefaultModifier(trimmed);
185
- const { label, color } = extractColor(
186
- cleanEntry,
187
- palette,
188
- result.diagnostics,
189
- lineNumber
190
- );
191
- if (isDefault || currentTagGroup.entries.length === 0) {
192
- currentTagGroup.defaultValue = label;
193
- }
194
- currentTagGroup.entries.push({
195
- value: label,
196
- color: color ?? AUTO_TAG_COLOR_SENTINEL,
197
- lineNumber,
198
- });
199
- continue;
200
- }
201
-
202
- // ── Content phase: indentation classifies each line. ──
203
- //
204
- // Eras are top-level `[Name]` section headers whose member events are
205
- // INDENTED beneath them (the org §7 / version-control §29 idiom); an event
206
- // at indent 0 sits OUTSIDE any era. A line indented deeper than its event
207
- // is that event's description body (§28.4).
208
-
209
- // Description body — any line indented deeper than its event. Checked
210
- // before the era bracket so a bracketed prose line (` [aside]`) under an
211
- // event stays a description rather than opening a spurious era.
212
- if (currentEvent && indent > currentEventIndent) {
213
- const descLine = trimmed.startsWith('- ')
214
- ? `• ${trimmed.substring(2)}`
215
- : trimmed;
216
- currentEvent.description.push(descLine);
217
- continue;
218
- }
219
-
220
- // ── Era run delimiter: `[Name]` (§28.6a) — a section header whose member
221
- // events are indented beneath it. Dedenting to (or past) the bracket's
222
- // own indent leaves the era. Optional trailing `collapsed: true` and/or
223
- // a color name tint/fold the era.
224
- const eraMatch = trimmed.match(ERA_RE);
225
- if (eraMatch) {
226
- contentStarted = true;
227
- currentTagGroup = null;
228
- currentEvent = null;
229
- const name = eraMatch[1]!.trim();
230
- let rest = (eraMatch[2] ?? '').trim();
231
- let collapsed = false;
232
- const cm = rest.match(ERA_COLLAPSED_RE);
233
- if (cm) {
234
- collapsed = cm[1]!.toLowerCase() === 'true';
235
- rest = (
236
- rest.slice(0, cm.index) + rest.slice(cm.index! + cm[0].length)
237
- ).trim();
238
- }
239
- let color: string | null = null;
240
- if (rest) {
241
- // A lone trailing color token tints the era (named colors only; a hex
242
- // value is flagged by extractColor and left uncolored). Prefix a
243
- // placeholder so extractColor's trailing-token rule sees it.
244
- const token = rest.split(/\s+/).pop()!;
245
- const ex = extractColor(
246
- `x ${token}`,
247
- palette,
248
- result.diagnostics,
249
- lineNumber
250
- );
251
- if (ex.color !== undefined) color = token;
252
- }
253
- const era: EventLineEra = { name, color, collapsed, lineNumber };
254
- result.eras.push(era);
255
- currentEra = name;
256
- eraIndent = indent;
257
- continue;
258
- }
259
-
260
- // ── Top-level (indent 0) directives and reserved seams. ──
261
- if (indent === 0) {
262
- currentTagGroup = null;
263
- if (trimmed.toLowerCase() === 'no-scale') {
264
- options.scale = false;
265
- continue;
266
- }
267
- const sideMatch = trimmed.match(SIDE_RE);
268
- if (sideMatch) {
269
- options.side = sideMatch[1]!.toLowerCase() as EventLineOptions['side'];
270
- continue;
271
- }
272
- if (trimmed.toLowerCase() === 'no-box') {
273
- options.noBox = true;
274
- continue;
275
- }
276
- if (trimmed.toLowerCase() === 'no-legend') {
277
- options.noLegend = true;
278
- continue;
279
- }
280
- const dirMatch = trimmed.match(DIRECTION_RE);
281
- if (dirMatch) {
282
- const dir = dirMatch[1]!.toUpperCase();
283
- if (dir !== 'LR') {
284
- result.diagnostics.push(
285
- emit(EVENT_LINE_DX.UNSUPPORTED, lineNumber, {
286
- reason: `event-line is horizontal-only in v1; \`direction ${dir}\` (vertical orientation) is a fast-follow.`,
287
- })
288
- );
289
- }
290
- continue;
291
- }
292
- if (tryParseSharedOption(trimmed, sharedOptions)) continue;
293
- if (SECTION_SEAM_RE.test(trimmed)) {
294
- result.diagnostics.push(
295
- emit(EVENT_LINE_DX.UNSUPPORTED, lineNumber, {
296
- reason:
297
- 'Group events with `[Name]` era brackets (§28.6a), not `section`.',
298
- })
299
- );
300
- continue;
301
- }
302
- }
303
-
304
- // ── Event line ──
305
- // An event belongs to the open era only when indented beneath that era's
306
- // bracket; an indent-0 event sits outside any era and closes the run
307
- // (events outside eras are fully supported — they simply have `era: null`).
308
- const inEra = currentEra !== null && indent > eraIndent;
309
- if (!inEra) currentEra = null;
310
- contentStarted = true;
311
- const event = parseEventHeader(
312
- trimmed,
313
- lineNumber,
314
- currentEra,
315
- aliasMap,
316
- result.diagnostics,
317
- pushWarning
318
- );
319
- result.events.push(event);
320
- currentEvent = event;
321
- currentEventIndent = indent;
322
- }
323
-
324
- options.noTitle = sharedOptions['no-title'] === 'on';
325
-
326
- resolveFutureEvents(result.events as Writable<EventLineEvent>[]);
327
-
328
- // Finalize tag colors + validate (flat topology → no cascade).
329
- finalizeAutoTagColors(result.tagGroups as Writable<TagGroup>[], palette);
330
- if (result.tagGroups.length > 0) {
331
- validateTagValues(result.events, result.tagGroups, pushWarning, suggest);
332
- validateTagGroupNames(result.tagGroups, pushWarning);
333
- // A tag group's first value is its implicit default (§28.5): an event with
334
- // no explicit value belongs to it. Materialize that into metadata — like
335
- // org/boxes-and-lines/pert — so color AND legend focus treat the default as
336
- // a real category (e.g. hovering "Scope" lights every untagged event).
337
- injectDefaultTagMetadata(result.events, result.tagGroups);
338
- }
339
-
340
- if (result.events.length === 0 && !result.error) {
341
- const diag = emit(EVENT_LINE_DX.NO_EVENTS, result.titleLineNumber ?? 1);
342
- result.diagnostics.push(diag);
343
- result.error = formatDgmoError(diag);
344
- }
345
-
346
- // Eras render as date-spanning brackets, so an event dated outside its era's
347
- // chronological position makes adjacent era brackets overlap (§28.6a). Only
348
- // meaningful when the date scale drives x-position.
349
- const eraFlaggedLines = new Set<number>();
350
- if (options.scale) {
351
- validateEraDateOrder(result.events, result.eras, (err) => {
352
- eraFlaggedLines.add(err.line);
353
- result.diagnostics.push(err);
354
- });
355
- }
356
-
357
- // Any dated event listed before an earlier-dated one is out of chronological
358
- // order — a likely authoring slip (and, to-scale, it plots to the left of an
359
- // event listed above it). Era-spanning inversions already get the richer
360
- // ERA_DATE_ORDER message, so skip lines that check already flagged.
361
- validateEventDateOrder(result.events, eraFlaggedLines, result.diagnostics);
362
-
363
- return result;
364
- }
365
-
366
- /**
367
- * Infer a position for every FUTURE (`TBD`) event from its source-order DATED
368
- * neighbors, so the to-scale axis can place it even though it has no authored
369
- * date. A TBD between two dated events is INTERPOLATED into that gap (a tentative
370
- * "somewhere in here" point, with `futureSpan` carrying the gap for the whisker
371
- * cue); a TBD after the last dated event is parked just past it (the open
372
- * horizon, `futureSpan = null` → dashed spine tail); a TBD before the first
373
- * dated event lands in a lead-in pad. Multiple TBDs sharing one gap fan evenly
374
- * across it in source order. With no dated events at all, TBDs keep `dateValue`
375
- * null and ride along under even spacing.
376
- */
377
- function resolveFutureEvents(events: Writable<EventLineEvent>[]): void {
378
- const realVals = events
379
- .filter((e) => !e.future && e.dateValue !== null)
380
- .map((e) => e.dateValue!);
381
- if (realVals.length === 0) return;
382
-
383
- const hiAll = Math.max(...realVals);
384
- const loAll = Math.min(...realVals);
385
- const pad = hiAll > loAll ? (hiAll - loAll) * 0.15 : 1;
386
-
387
- // Nearest dated value before / after each event, in source order.
388
- const prevReal: (number | null)[] = [];
389
- let carry: number | null = null;
390
- for (const e of events) {
391
- prevReal.push(carry);
392
- if (!e.future && e.dateValue !== null) carry = e.dateValue;
393
- }
394
- const nextReal: (number | null)[] = new Array(events.length).fill(null);
395
- carry = null;
396
- for (let i = events.length - 1; i >= 0; i--) {
397
- nextReal[i] = carry;
398
- const e = events[i]!;
399
- if (!e.future && e.dateValue !== null) carry = e.dateValue;
400
- }
401
-
402
- // Group consecutive futures sharing the same (prev, next) bounds; fan evenly.
403
- let i = 0;
404
- while (i < events.length) {
405
- if (!events[i]!.future) {
406
- i++;
407
- continue;
408
- }
409
- const lo = prevReal[i]!;
410
- const hi = nextReal[i]!;
411
- let j = i;
412
- while (
413
- j < events.length &&
414
- events[j]!.future &&
415
- prevReal[j] === lo &&
416
- nextReal[j] === hi
417
- )
418
- j++;
419
- const group = events.slice(i, j);
420
- const g = group.length;
421
- if (lo !== null && hi !== null) {
422
- group.forEach((e, k) => {
423
- e.dateValue = lo + ((hi - lo) * (k + 1)) / (g + 1);
424
- e.futureSpan = [lo, hi];
425
- });
426
- } else if (lo === null && hi !== null) {
427
- const left = hi - pad;
428
- group.forEach((e, k) => {
429
- e.dateValue = left + ((hi - left) * (k + 1)) / (g + 1);
430
- e.futureSpan = [left, hi];
431
- });
432
- } else {
433
- // Trailing: park past the last dated event — the open horizon — evenly
434
- // spaced by `pad`, so a row of TBDs reads as a uniform march into the
435
- // future (the first sits `pad` past the last real date, each next `pad` on).
436
- group.forEach((e, k) => {
437
- e.dateValue = hiAll + pad * (k + 1);
438
- e.futureSpan = null;
439
- });
440
- }
441
- i = j;
442
- }
443
- }
444
-
445
- /**
446
- * Warn when dated events are listed out of chronological order — a later-listed
447
- * event dated before the dated event just above it. event-line reads
448
- * left-to-right by date, so a descending pair is almost always an authoring
449
- * slip. Undated events are skipped; coincident dates are in order.
450
- */
451
- function validateEventDateOrder(
452
- events: readonly EventLineEvent[],
453
- skipLines: ReadonlySet<number>,
454
- diagnostics: DgmoError[]
455
- ): void {
456
- let prev: EventLineEvent | null = null;
457
- for (const ev of events) {
458
- // Future (TBD) events carry an inferred dateValue, not an authored one —
459
- // never flag them (or use them as the reference) for chronological order.
460
- if (ev.future || ev.dateValue === null) continue;
461
- if (
462
- prev &&
463
- ev.dateValue < prev.dateValue! &&
464
- !skipLines.has(ev.lineNumber)
465
- ) {
466
- diagnostics.push(
467
- emit(EVENT_LINE_DX.DATE_ORDER, ev.lineNumber, {
468
- label: ev.label,
469
- date: ev.date,
470
- prevLabel: prev.label,
471
- prevDate: prev.date,
472
- })
473
- );
474
- }
475
- prev = ev;
476
- }
477
- }
478
-
479
- /**
480
- * Warn when a dated event sits in an era whose chronological run it breaks —
481
- * i.e. it is dated after a later era begins, or before an earlier era ends.
482
- * Eras are left-to-right date bands; a straggler makes their brackets overlap.
483
- */
484
- function validateEraDateOrder(
485
- events: readonly EventLineEvent[],
486
- eras: readonly EventLineEra[],
487
- emitWarn: (err: DgmoError) => void
488
- ): void {
489
- if (eras.length < 2) return;
490
- const order = new Map(eras.map((e, i) => [e.name, i]));
491
- const dated = events.filter(
492
- (e) =>
493
- !e.future && e.dateValue !== null && e.era !== null && order.has(e.era)
494
- );
495
- if (dated.length === 0) return;
496
-
497
- // Earliest and latest dated event per era index.
498
- const perEra = new Map<
499
- number,
500
- { min: EventLineEvent; max: EventLineEvent }
501
- >();
502
- for (const ev of dated) {
503
- const idx = order.get(ev.era!)!;
504
- const cur = perEra.get(idx);
505
- if (!cur) {
506
- perEra.set(idx, { min: ev, max: ev });
507
- } else {
508
- if (ev.dateValue! < cur.min.dateValue!) cur.min = ev;
509
- if (ev.dateValue! > cur.max.dateValue!) cur.max = ev;
510
- }
511
- }
512
-
513
- const n = eras.length;
514
- // prefixMax[k] = the latest-dated event across eras with index < k.
515
- // suffixMin[k] = the earliest-dated event across eras with index > k.
516
- const prefixMax: (EventLineEvent | null)[] = new Array(n).fill(null);
517
- const suffixMin: (EventLineEvent | null)[] = new Array(n).fill(null);
518
- for (let k = 1; k < n; k++) {
519
- const prev = perEra.get(k - 1)?.max ?? null;
520
- const carried = prefixMax[k - 1] ?? null;
521
- prefixMax[k] =
522
- prev && (!carried || prev.dateValue! > carried.dateValue!)
523
- ? prev
524
- : carried;
525
- }
526
- for (let k = n - 2; k >= 0; k--) {
527
- const next = perEra.get(k + 1)?.min ?? null;
528
- const carried = suffixMin[k + 1] ?? null;
529
- suffixMin[k] =
530
- next && (!carried || next.dateValue! < carried.dateValue!)
531
- ? next
532
- : carried;
533
- }
534
-
535
- for (const ev of dated) {
536
- const k = order.get(ev.era!)!;
537
- const ahead = suffixMin[k];
538
- const behind = prefixMax[k];
539
- if (ahead && ev.dateValue! > ahead.dateValue!) {
540
- emitWarn(
541
- emit(EVENT_LINE_DX.ERA_DATE_ORDER, ev.lineNumber, {
542
- label: ev.label,
543
- date: ev.date,
544
- era: ev.era,
545
- rel: 'after',
546
- otherEra: ahead.era,
547
- edge: 'begins',
548
- otherDate: ahead.date,
549
- })
550
- );
551
- } else if (behind && ev.dateValue! < behind.dateValue!) {
552
- emitWarn(
553
- emit(EVENT_LINE_DX.ERA_DATE_ORDER, ev.lineNumber, {
554
- label: ev.label,
555
- date: ev.date,
556
- era: ev.era,
557
- rel: 'before',
558
- otherEra: behind.era,
559
- edge: 'ends',
560
- otherDate: behind.date,
561
- })
562
- );
563
- }
564
- }
565
- }
566
-
567
- function parseEventHeader(
568
- trimmed: string,
569
- lineNumber: number,
570
- era: string | null,
571
- aliasMap: Map<string, string>,
572
- diagnostics: DgmoError[],
573
- pushWarning: (line: number, message: string, code?: string) => void
574
- ): Writable<EventLineEvent> {
575
- // Peel an optional ISO date line-prefix (timeline §15 idiom).
576
- let date: string | null = null;
577
- let dateValue: number | null = null;
578
- let future = false;
579
- let remainder = trimmed;
580
-
581
- // `TBD` line-prefix = a FUTURE, not-yet-scheduled event. Captioned verbatim;
582
- // its numeric position is resolved after parsing (just past the latest event).
583
- const tbdMatch = trimmed.match(TBD_RE);
584
- if (tbdMatch) {
585
- date = 'TBD';
586
- future = true;
587
- remainder = trimmed.slice(tbdMatch[0].length).trimStart();
588
- }
589
-
590
- const prefix = future ? null : extractDatePrefix(trimmed);
591
- if (prefix) {
592
- date = prefix.startDate;
593
- dateValue = parseTimelineDate(prefix.startDate);
594
- remainder = prefix.remainder || '';
595
- if (prefix.endDate) {
596
- diagnostics.push(
597
- emit(EVENT_LINE_DX.UNSUPPORTED, lineNumber, {
598
- reason:
599
- 'event-line events are points; a date range (`->`) is not supported — using the start date.',
600
- })
601
- );
602
- }
603
- } else if (!future && NON_ISO_DATE_RE.test(trimmed)) {
604
- const firstToken = trimmed.split(/\s+/)[0]!;
605
- diagnostics.push(
606
- emit(EVENT_LINE_DX.BAD_DATE, lineNumber, { token: firstToken })
607
- );
608
- }
609
-
610
- const registry = withTagAliases(
611
- EVENT_LINE_REGISTRY,
612
- new Set(aliasMap.keys())
613
- );
614
- const split = splitNameAndMeta(
615
- remainder,
616
- registry,
617
- aliasMap,
618
- undefined,
619
- diagnostics,
620
- lineNumber
621
- );
622
- warnUnknownMetaKeys(
623
- split.meta,
624
- registry,
625
- (msg) => pushWarning(lineNumber, msg),
626
- split.name
627
- );
628
-
629
- const metadata: Record<string, string> = { ...split.meta };
630
- if (split.color !== undefined) metadata['color'] = split.color;
631
-
632
- return {
633
- label: split.name || remainder.trim(),
634
- lineNumber,
635
- date,
636
- dateValue,
637
- future,
638
- futureSpan: null,
639
- metadata,
640
- description: [],
641
- era,
642
- };
643
- }