@diagrammo/dgmo 0.47.0 → 0.48.1

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 (345) hide show
  1. package/dist/advanced.js +11 -11
  2. package/dist/auto.js +16 -16
  3. package/dist/auto.mjs +41 -12
  4. package/dist/block.js +4 -4
  5. package/dist/{chunk-FNB3PNGF.js → chunk-7DTWEFUE.js} +3 -3
  6. package/dist/{chunk-2DXMZRWJ.js → chunk-B65G5DNL.js} +8 -1
  7. package/dist/{chunk-RZCF2VVM.js → chunk-B7JUCQUA.js} +3 -1
  8. package/dist/{chunk-DU7W62N5.js → chunk-FANX6UJR.js} +3 -3
  9. package/dist/{chunk-6FZYCKXB.js → chunk-HSH73DP6.js} +2 -2
  10. package/dist/{chunk-P4RH4OSP.js → chunk-ILKORZ3H.js} +2 -2
  11. package/dist/{chunk-Y5QGVTVC.js → chunk-JTSMEYIZ.js} +7 -3
  12. package/dist/{chunk-RCERWOJR.js → chunk-ODZVHU3R.js} +1 -2
  13. package/dist/{chunk-DZAQBW35.js → chunk-SGZYXELT.js} +3 -7
  14. package/dist/{chunk-CUVHQHZ7.js → chunk-THXCFRTU.js} +3 -3
  15. package/dist/{chunk-IH6ZMVQ5.js → chunk-UC7TFHUM.js} +29 -11
  16. package/dist/{chunk-EMS2SK26.js → chunk-ZBWMSD5N.js} +3 -1
  17. package/dist/cli.cjs +15 -15
  18. package/dist/{dgmo-router-DZCIDUO5.js → dgmo-router-X35VLZLM.js} +3 -3
  19. package/dist/element.js +16 -16
  20. package/dist/element.mjs +41 -12
  21. package/dist/{flowchart-renderer-ZAEOL4DX.js → flowchart-renderer-SNDSII4D.js} +2 -2
  22. package/dist/index.d.ts +4 -2
  23. package/dist/index.js +4 -4
  24. package/dist/{parser-FUSKFGZN.js → parser-2EWECDSA.js} +2 -2
  25. package/dist/{renderer-UWA5XS74.js → renderer-4JHRUBE6.js} +3 -3
  26. package/dist/{renderer-WZRREQ2P.js → renderer-5MYBMBYO.js} +2 -2
  27. package/dist/{renderer-TOCOVLHS.js → renderer-B2OMQIQG.js} +3 -3
  28. package/dist/{renderer-2XQQQ6QR.js → renderer-N43WR5GV.js} +3 -3
  29. package/dist/{renderer-T7YKC5VP.js → renderer-ZRNG54CW.js} +3 -3
  30. package/dist/{state-renderer-RFYHSP4K.js → state-renderer-B4DQBM6M.js} +2 -2
  31. package/package.json +23 -71
  32. package/dist/advanced.cjs +0 -71648
  33. package/dist/advanced.d.cts +0 -5719
  34. package/dist/auto.cjs +0 -70648
  35. package/dist/auto.d.cts +0 -54
  36. package/dist/block.cjs +0 -70208
  37. package/dist/block.d.cts +0 -115
  38. package/dist/editor.cjs +0 -526
  39. package/dist/editor.d.cts +0 -26
  40. package/dist/element.cjs +0 -70530
  41. package/dist/element.d.cts +0 -62
  42. package/dist/highlight.cjs +0 -852
  43. package/dist/highlight.d.cts +0 -49
  44. package/dist/index.cjs +0 -70491
  45. package/dist/index.d.cts +0 -160
  46. package/dist/pert.cjs +0 -325
  47. package/dist/pert.d.cts +0 -559
  48. package/dist/themes-1-CuKpeH.d.cts +0 -908
  49. package/src/advanced.ts +0 -873
  50. package/src/arc/parser.ts +0 -15
  51. package/src/arc/renderer.ts +0 -633
  52. package/src/auto/index.ts +0 -621
  53. package/src/auto/shared.ts +0 -370
  54. package/src/auto/styles.ts +0 -73
  55. package/src/block/layout.ts +0 -198
  56. package/src/block/parser.ts +0 -427
  57. package/src/block/renderer.ts +0 -484
  58. package/src/block/types.ts +0 -67
  59. package/src/boxes-and-lines/collapse.ts +0 -96
  60. package/src/boxes-and-lines/focus.ts +0 -257
  61. package/src/boxes-and-lines/label-placement.ts +0 -339
  62. package/src/boxes-and-lines/layout-grouped.ts +0 -912
  63. package/src/boxes-and-lines/layout-layered.ts +0 -722
  64. package/src/boxes-and-lines/layout-search.ts +0 -1678
  65. package/src/boxes-and-lines/layout.ts +0 -398
  66. package/src/boxes-and-lines/parser.ts +0 -1181
  67. package/src/boxes-and-lines/renderer.ts +0 -1465
  68. package/src/boxes-and-lines/types.ts +0 -66
  69. package/src/c4/layout.ts +0 -2441
  70. package/src/c4/parser.ts +0 -1158
  71. package/src/c4/renderer.ts +0 -2008
  72. package/src/c4/types.ts +0 -89
  73. package/src/chart-type-registry.ts +0 -529
  74. package/src/chart-types.ts +0 -225
  75. package/src/chart.ts +0 -685
  76. package/src/charts-d3/bar.ts +0 -338
  77. package/src/charts-d3/chord.ts +0 -140
  78. package/src/charts-d3/function.ts +0 -147
  79. package/src/charts-d3/funnel.ts +0 -104
  80. package/src/charts-d3/heatmap.ts +0 -145
  81. package/src/charts-d3/index.ts +0 -337
  82. package/src/charts-d3/interactions.ts +0 -477
  83. package/src/charts-d3/line.ts +0 -344
  84. package/src/charts-d3/mount.ts +0 -151
  85. package/src/charts-d3/pie.ts +0 -117
  86. package/src/charts-d3/polar.ts +0 -89
  87. package/src/charts-d3/radar.ts +0 -0
  88. package/src/charts-d3/sankey.ts +0 -0
  89. package/src/charts-d3/scatter.ts +0 -185
  90. package/src/charts-d3/shared.ts +0 -208
  91. package/src/class/layout.ts +0 -326
  92. package/src/class/parser.ts +0 -635
  93. package/src/class/renderer.ts +0 -793
  94. package/src/class/types.ts +0 -58
  95. package/src/cli-banner.ts +0 -106
  96. package/src/cli.ts +0 -1080
  97. package/src/colors-diagnostics.ts +0 -35
  98. package/src/colors.ts +0 -379
  99. package/src/completion-types.ts +0 -27
  100. package/src/completion.ts +0 -2668
  101. package/src/cycle/layout.ts +0 -1026
  102. package/src/cycle/parser.ts +0 -387
  103. package/src/cycle/renderer.ts +0 -653
  104. package/src/cycle/types.ts +0 -101
  105. package/src/d3.ts +0 -1434
  106. package/src/data-chart-parser.ts +0 -1007
  107. package/src/dgmo-router.ts +0 -296
  108. package/src/diagnostics-registry.ts +0 -108
  109. package/src/diagnostics.ts +0 -0
  110. package/src/dimensions.ts +0 -20
  111. package/src/directives-registry.ts +0 -396
  112. package/src/editor/dgmo.grammar +0 -76
  113. package/src/editor/dgmo.grammar.d.ts +0 -2
  114. package/src/editor/dgmo.grammar.js +0 -18
  115. package/src/editor/dgmo.grammar.terms.d.ts +0 -5
  116. package/src/editor/dgmo.grammar.terms.js +0 -35
  117. package/src/editor/highlight-api.ts +0 -596
  118. package/src/editor/highlight.ts +0 -36
  119. package/src/editor/index.ts +0 -27
  120. package/src/editor/keywords.ts +0 -128
  121. package/src/editor/tokens.ts +0 -30
  122. package/src/element/index.ts +0 -432
  123. package/src/embed/css.ts +0 -312
  124. package/src/embed/escape.ts +0 -15
  125. package/src/embed/index.ts +0 -280
  126. package/src/er/classify.ts +0 -228
  127. package/src/er/layout.ts +0 -530
  128. package/src/er/parser.ts +0 -750
  129. package/src/er/renderer.ts +0 -725
  130. package/src/er/types.ts +0 -52
  131. package/src/error-card.ts +0 -269
  132. package/src/event-line/diagnostics.ts +0 -117
  133. package/src/event-line/parser.ts +0 -643
  134. package/src/event-line/renderer.ts +0 -1742
  135. package/src/event-line/types.ts +0 -74
  136. package/src/fonts.ts +0 -3
  137. package/src/gantt/calculator.ts +0 -979
  138. package/src/gantt/parser.ts +0 -1641
  139. package/src/gantt/renderer.ts +0 -3787
  140. package/src/gantt/resolver.ts +0 -172
  141. package/src/gantt/types.ts +0 -206
  142. package/src/graph/diagnostics.ts +0 -64
  143. package/src/graph/edge-spline.ts +0 -29
  144. package/src/graph/flowchart-parser.ts +0 -759
  145. package/src/graph/flowchart-renderer.ts +0 -817
  146. package/src/graph/layout.ts +0 -472
  147. package/src/graph/notes.ts +0 -21
  148. package/src/graph/state-collapse.ts +0 -78
  149. package/src/graph/state-parser.ts +0 -574
  150. package/src/graph/state-renderer.ts +0 -653
  151. package/src/graph/types.ts +0 -65
  152. package/src/index.ts +0 -261
  153. package/src/infra/compute.ts +0 -1385
  154. package/src/infra/layout.ts +0 -888
  155. package/src/infra/parser.ts +0 -1234
  156. package/src/infra/renderer.ts +0 -2534
  157. package/src/infra/roles.ts +0 -75
  158. package/src/infra/types.ts +0 -216
  159. package/src/infra/validation.ts +0 -201
  160. package/src/journey-map/layout.ts +0 -490
  161. package/src/journey-map/parser.ts +0 -557
  162. package/src/journey-map/renderer.ts +0 -1580
  163. package/src/journey-map/types.ts +0 -47
  164. package/src/kanban/mutations.ts +0 -175
  165. package/src/kanban/parser.ts +0 -509
  166. package/src/kanban/renderer.ts +0 -1449
  167. package/src/kanban/types.ts +0 -39
  168. package/src/label-layout.ts +0 -368
  169. package/src/map/colorize.ts +0 -54
  170. package/src/map/completion.ts +0 -316
  171. package/src/map/context-labels.ts +0 -609
  172. package/src/map/data/PROVENANCE.json +0 -1
  173. package/src/map/data/README.md +0 -40
  174. package/src/map/data/airport-collisions.json +0 -1
  175. package/src/map/data/airports.json +0 -1
  176. package/src/map/data/gazetteer.json +0 -1
  177. package/src/map/data/lakes.json +0 -1
  178. package/src/map/data/mountain-ranges.json +0 -1
  179. package/src/map/data/na-lakes.json +0 -1
  180. package/src/map/data/na-land.json +0 -1
  181. package/src/map/data/region-names.json +0 -1
  182. package/src/map/data/rivers.json +0 -1
  183. package/src/map/data/types.ts +0 -121
  184. package/src/map/data/us-states.json +0 -1
  185. package/src/map/data/water-bodies.json +0 -1
  186. package/src/map/data/world-coarse.json +0 -1
  187. package/src/map/data/world-detail.json +0 -1
  188. package/src/map/diagnostics.ts +0 -134
  189. package/src/map/dimensions.ts +0 -150
  190. package/src/map/geo-query.ts +0 -295
  191. package/src/map/geo.ts +0 -438
  192. package/src/map/invert.ts +0 -111
  193. package/src/map/layout.ts +0 -5069
  194. package/src/map/legend-band.ts +0 -127
  195. package/src/map/load-data.ts +0 -186
  196. package/src/map/parser.ts +0 -783
  197. package/src/map/renderer.ts +0 -1445
  198. package/src/map/resolved-types.ts +0 -160
  199. package/src/map/resolver.ts +0 -1146
  200. package/src/map/types.ts +0 -194
  201. package/src/mindmap/collapse.ts +0 -67
  202. package/src/mindmap/layout.ts +0 -649
  203. package/src/mindmap/parser.ts +0 -430
  204. package/src/mindmap/renderer.ts +0 -637
  205. package/src/mindmap/text-wrap.ts +0 -218
  206. package/src/mindmap/types.ts +0 -56
  207. package/src/org/collapse.ts +0 -151
  208. package/src/org/layout.ts +0 -1262
  209. package/src/org/parser.ts +0 -519
  210. package/src/org/renderer.ts +0 -866
  211. package/src/org/resolver.ts +0 -636
  212. package/src/palettes/atlas.ts +0 -77
  213. package/src/palettes/blueprint.ts +0 -73
  214. package/src/palettes/catppuccin.ts +0 -84
  215. package/src/palettes/color-utils.ts +0 -443
  216. package/src/palettes/index.ts +0 -67
  217. package/src/palettes/nord.ts +0 -67
  218. package/src/palettes/registry.ts +0 -114
  219. package/src/palettes/slate.ts +0 -73
  220. package/src/palettes/tidewater.ts +0 -73
  221. package/src/palettes/tokyo-night.ts +0 -86
  222. package/src/palettes/types.ts +0 -88
  223. package/src/pert/analyzer.ts +0 -1183
  224. package/src/pert/diagnostics.ts +0 -110
  225. package/src/pert/index.ts +0 -43
  226. package/src/pert/internal.ts +0 -252
  227. package/src/pert/layout.ts +0 -971
  228. package/src/pert/monte-carlo.ts +0 -446
  229. package/src/pert/parser.ts +0 -1606
  230. package/src/pert/renderer.ts +0 -4009
  231. package/src/pert/share-normalize.ts +0 -62
  232. package/src/pert/types.ts +0 -604
  233. package/src/pyramid/parser.ts +0 -185
  234. package/src/pyramid/renderer.ts +0 -768
  235. package/src/pyramid/types.ts +0 -28
  236. package/src/quadrant/parser.ts +0 -18
  237. package/src/quadrant/renderer.ts +0 -638
  238. package/src/raci/diagnostics.ts +0 -213
  239. package/src/raci/index.ts +0 -23
  240. package/src/raci/mutations.ts +0 -321
  241. package/src/raci/parser.ts +0 -699
  242. package/src/raci/renderer.ts +0 -1627
  243. package/src/raci/types.ts +0 -82
  244. package/src/raci/variants.ts +0 -320
  245. package/src/render.ts +0 -268
  246. package/src/ring/parser.ts +0 -212
  247. package/src/ring/renderer.ts +0 -490
  248. package/src/ring/types.ts +0 -27
  249. package/src/sequence/collapse.ts +0 -174
  250. package/src/sequence/parser.ts +0 -1596
  251. package/src/sequence/participant-inference.ts +0 -152
  252. package/src/sequence/renderer.ts +0 -3168
  253. package/src/sequence/tag-resolution.ts +0 -164
  254. package/src/sharing.ts +0 -211
  255. package/src/sitemap/collapse.ts +0 -100
  256. package/src/sitemap/layout.ts +0 -925
  257. package/src/sitemap/parser.ts +0 -755
  258. package/src/sitemap/renderer.ts +0 -828
  259. package/src/sitemap/types.ts +0 -42
  260. package/src/slope/parser.ts +0 -18
  261. package/src/slope/renderer.ts +0 -378
  262. package/src/swimlane/diagnostics.ts +0 -94
  263. package/src/swimlane/layout.ts +0 -597
  264. package/src/swimlane/parser.ts +0 -613
  265. package/src/swimlane/renderer.ts +0 -681
  266. package/src/swimlane/types.ts +0 -151
  267. package/src/tech-radar/interactive.ts +0 -1129
  268. package/src/tech-radar/layout.ts +0 -197
  269. package/src/tech-radar/parser.ts +0 -436
  270. package/src/tech-radar/renderer.ts +0 -1239
  271. package/src/tech-radar/shared.ts +0 -151
  272. package/src/tech-radar/types.ts +0 -86
  273. package/src/themes.ts +0 -22
  274. package/src/timeline/parser.ts +0 -472
  275. package/src/timeline/renderer.ts +0 -3024
  276. package/src/timeline/types.ts +0 -33
  277. package/src/timeline/viz-parser.ts +0 -21
  278. package/src/treemap/diagnostics.ts +0 -62
  279. package/src/treemap/layout-radial.ts +0 -233
  280. package/src/treemap/layout.ts +0 -189
  281. package/src/treemap/parser.ts +0 -463
  282. package/src/treemap/renderer-radial.ts +0 -438
  283. package/src/treemap/renderer.ts +0 -572
  284. package/src/treemap/treemap-shared.ts +0 -309
  285. package/src/treemap/types.ts +0 -60
  286. package/src/utils/arrow-markers.ts +0 -51
  287. package/src/utils/arrows-diagnostics.ts +0 -62
  288. package/src/utils/arrows.ts +0 -227
  289. package/src/utils/brand.ts +0 -61
  290. package/src/utils/card.ts +0 -183
  291. package/src/utils/collapse-engine/tree-edges.ts +0 -115
  292. package/src/utils/collapse-engine/tree.ts +0 -117
  293. package/src/utils/d3-helpers.ts +0 -219
  294. package/src/utils/d3-types.ts +0 -9
  295. package/src/utils/description-helpers.ts +0 -38
  296. package/src/utils/duration.ts +0 -312
  297. package/src/utils/export-container.ts +0 -41
  298. package/src/utils/expr-eval.ts +0 -27
  299. package/src/utils/fit-canvas.ts +0 -64
  300. package/src/utils/hover-styles.ts +0 -673
  301. package/src/utils/inline-markdown.ts +0 -96
  302. package/src/utils/legend-constants.ts +0 -48
  303. package/src/utils/legend-d3.ts +0 -618
  304. package/src/utils/legend-integration.ts +0 -107
  305. package/src/utils/legend-layout.ts +0 -776
  306. package/src/utils/legend-svg.ts +0 -214
  307. package/src/utils/legend-types.ts +0 -272
  308. package/src/utils/name-normalize.ts +0 -163
  309. package/src/utils/note-box/constants.ts +0 -25
  310. package/src/utils/note-box/index.ts +0 -11
  311. package/src/utils/note-box/metrics.ts +0 -90
  312. package/src/utils/note-box/svg.ts +0 -331
  313. package/src/utils/notes/bounds.ts +0 -30
  314. package/src/utils/notes/build.ts +0 -131
  315. package/src/utils/notes/index.ts +0 -18
  316. package/src/utils/notes/model.ts +0 -19
  317. package/src/utils/notes/parse.ts +0 -131
  318. package/src/utils/notes/place.ts +0 -177
  319. package/src/utils/notes/resolve.ts +0 -88
  320. package/src/utils/number-format.ts +0 -36
  321. package/src/utils/parsing.ts +0 -953
  322. package/src/utils/reserved-key-registry.ts +0 -239
  323. package/src/utils/safe-href.ts +0 -38
  324. package/src/utils/scaling.ts +0 -97
  325. package/src/utils/svg-embed.ts +0 -251
  326. package/src/utils/tag-groups.ts +0 -607
  327. package/src/utils/text-measure.ts +0 -122
  328. package/src/utils/time-ticks.ts +0 -253
  329. package/src/utils/title-constants.ts +0 -24
  330. package/src/utils/visual-conventions.ts +0 -61
  331. package/src/utils/wrapped-desc.ts +0 -87
  332. package/src/venn/parser.ts +0 -18
  333. package/src/venn/renderer.ts +0 -1047
  334. package/src/version-control/diagnostics.ts +0 -67
  335. package/src/version-control/parser.ts +0 -544
  336. package/src/version-control/renderer.ts +0 -724
  337. package/src/version-control/types.ts +0 -100
  338. package/src/visualizations/parse.ts +0 -1560
  339. package/src/visualizations/types.ts +0 -262
  340. package/src/wireframe/layout.ts +0 -479
  341. package/src/wireframe/parser.ts +0 -1114
  342. package/src/wireframe/renderer.ts +0 -1318
  343. package/src/wireframe/types.ts +0 -110
  344. package/src/wordcloud/parser.ts +0 -18
  345. package/src/wordcloud/renderer.ts +0 -357
@@ -1,1641 +0,0 @@
1
- // ============================================================
2
- // Gantt Chart Parser
3
- // ============================================================
4
-
5
- import { formatDgmoError, makeDgmoError } from '../diagnostics';
6
- import {
7
- GANTT_REGISTRY,
8
- withTagAliases,
9
- isReservedKey,
10
- } from '../utils/reserved-key-registry';
11
- import { splitNameAndMeta, warnUnknownMetaKeys } from '../utils/parsing';
12
- import { GANTT_OPTION_SET, GANTT_BOOLEAN_SET } from '../directives-registry';
13
- import type { DgmoError } from '../diagnostics';
14
- import type { TagGroup } from '../utils/tag-groups';
15
- import type { Writable } from '../utils/brand';
16
- import {
17
- matchTagBlockHeading,
18
- stripDefaultModifier,
19
- validateTagGroupNames,
20
- tagAttrKey,
21
- } from '../utils/tag-groups';
22
- import { measureIndent, extractColor, parseFirstLine } from '../utils/parsing';
23
- import {
24
- parseOffset,
25
- parseOffsetPrefix,
26
- parseDuration,
27
- } from '../utils/duration';
28
- import { normalizeName } from '../utils/name-normalize';
29
- import type { PaletteColors } from '../palettes';
30
- import { getSeriesColors } from '../palettes';
31
- import type {
32
- ParsedGantt,
33
- GanttNode,
34
- GanttTask,
35
- GanttGroup,
36
- GanttDependency,
37
- GanttParallelBlock,
38
- Duration,
39
- DurationUnit,
40
- Offset,
41
- Weekday,
42
- } from './types';
43
-
44
- // ── Regexes ─────────────────────────────────────────────────
45
-
46
- /** Group container: `[GroupName]` with optional pipe metadata */
47
- const GROUP_RE = /^\[(.+?)\]\s*(.*)$/;
48
-
49
- /** Dependency: `-> TargetName` or `-label-> TargetName` (label captured) */
50
- const DEPENDENCY_RE = /^(?:-(.+?))?->\s*(.+)$/;
51
-
52
- /** Comment line */
53
- const COMMENT_RE = /^\/\//;
54
-
55
- /** Era: `era YYYY[-MM[-DD[ HH:MM]]] -> YYYY[-MM[-DD[ HH:MM]]] Label (color?)` */
56
- const ERA_RE =
57
- /^era\s+(\d{4}(?:-\d{2}(?:-\d{2}(?: \d{2}:\d{2})?)?)?)\s*(?:->|\u2013>)\s*(\d{4}(?:-\d{2}(?:-\d{2}(?: \d{2}:\d{2})?)?)?)\s+(.+)$/i;
58
-
59
- /** Marker: `marker YYYY[-MM[-DD[ HH:MM]]] Label (color?)` */
60
- const MARKER_RE =
61
- /^marker\s+(\d{4}(?:-\d{2}(?:-\d{2}(?: \d{2}:\d{2})?)?)?)\s+(.+)$/i;
62
-
63
- /** Holiday date: `2024-01-15 Label` */
64
- const HOLIDAY_DATE_RE = /^(\d{4}-\d{2}-\d{2})\s+(.+)$/;
65
-
66
- /** Holiday range: `2024-12-24 -> 2024-12-31 Label` */
67
- const HOLIDAY_RANGE_RE =
68
- /^(\d{4}-\d{2}-\d{2})\s*(?:->|\u2013>)\s*(\d{4}-\d{2}-\d{2})\s+(.+)$/;
69
-
70
- /** Workweek override: `workweek sun-thu` */
71
- const WORKWEEK_RE = /^workweek\s+(.+)$/i;
72
-
73
- /** Era entry (inside era block, no `era` prefix): `YYYY[-MM[-DD[ HH:MM]]] -> YYYY[-MM[-DD[ HH:MM]]] Label` */
74
- const ERA_ENTRY_RE =
75
- /^(\d{4}(?:-\d{2}(?:-\d{2}(?: \d{2}:\d{2})?)?)?)\s*(?:->|\u2013>)\s*(\d{4}(?:-\d{2}(?:-\d{2}(?: \d{2}:\d{2})?)?)?)\s+(.+)$/;
76
-
77
- /** Marker entry (inside marker block, no `marker` prefix): `YYYY[-MM[-DD[ HH:MM]]] Label` */
78
- const MARKER_ENTRY_RE =
79
- /^(\d{4}(?:-\d{2}(?:-\d{2}(?: \d{2}:\d{2})?)?)?)\s+(.+)$/;
80
-
81
- // ── New-syntax regexes (v2: positional duration, arrow graph) ─
82
-
83
- /** Offset prefix at line start: `+4w Task...` or `+10bd [Group]` */
84
- const OFFSET_PREFIX_RE = /^\+(\d+(?:\.\d+)?(?:min|bd|d|w|m|q|y|h|s))\s+(.*)/;
85
-
86
- /** Duration token (for right-to-left positional scan) */
87
- const DURATION_TOKEN_RE = /^(\d+(?:\.\d+)?)(min|bd|d|w|m|q|y|h|s)(\?)?$/;
88
-
89
- /** Arrow with lag: `-3w-> Rest` */
90
- const LAG_ARROW_RE = /^-(\d+(?:\.\d+)?(?:min|bd|d|w|m|q|y|h|s))->\s*(.*)/;
91
-
92
- /** Arrow with lead (negative lag): `--2w-> Rest` */
93
- const LEAD_ARROW_RE = /^--(\d+(?:\.\d+)?(?:min|bd|d|w|m|q|y|h|s))->\s*(.*)/;
94
-
95
- /** Basic arrow: `-> Rest` */
96
- const BASIC_ARROW_RE = /^->\s*(.*)/;
97
-
98
- /** Era with offset: `era +4w -> +8w Label [color]` */
99
- const ERA_OFFSET_RE =
100
- /^era\s+\+(\d+(?:\.\d+)?(?:min|bd|d|w|m|q|y|h|s))\s*(?:->|–>)\s*\+(\d+(?:\.\d+)?(?:min|bd|d|w|m|q|y|h|s))\s+(.+)$/i;
101
-
102
- /** Marker with offset: `marker +10w Label [color]` */
103
- const MARKER_OFFSET_RE =
104
- /^marker\s+\+(\d+(?:\.\d+)?(?:min|bd|d|w|m|q|y|h|s))\s+(.+)$/i;
105
-
106
- // Valid weekday names
107
- const WEEKDAY_MAP: Record<string, Weekday> = {
108
- mon: 'mon',
109
- tue: 'tue',
110
- wed: 'wed',
111
- thu: 'thu',
112
- fri: 'fri',
113
- sat: 'sat',
114
- sun: 'sun',
115
- monday: 'mon',
116
- tuesday: 'tue',
117
- wednesday: 'wed',
118
- thursday: 'thu',
119
- friday: 'fri',
120
- saturday: 'sat',
121
- sunday: 'sun',
122
- };
123
-
124
- // ── Block Stack ─────────────────────────────────────────────
125
-
126
- type ContainerType = 'group' | 'parallel' | 'task';
127
-
128
- interface BlockEntry {
129
- node: Writable<GanttGroup> | Writable<GanttParallelBlock>;
130
- indent: number;
131
- containerType: ContainerType;
132
- taskRef?: Writable<GanttNode & { kind: 'task' }>;
133
- }
134
-
135
- // ── Parser ──────────────────────────────────────────────────
136
-
137
- export function parseGantt(
138
- content: string,
139
- palette?: PaletteColors
140
- ): ParsedGantt {
141
- const lines = content.split('\n');
142
- const diagnostics: DgmoError[] = [];
143
-
144
- const holidays: Writable<ParsedGantt['holidays']> = {
145
- dates: [],
146
- ranges: [],
147
- workweek: ['mon', 'tue', 'wed', 'thu', 'fri'],
148
- };
149
- const result: Writable<ParsedGantt> = {
150
- nodes: [],
151
- holidays,
152
- tagGroups: [],
153
- eras: [],
154
- markers: [],
155
- options: {
156
- start: null,
157
- title: null,
158
- titleLineNumber: null,
159
- todayMarker: 'off',
160
- criticalPath: false,
161
- dependencies: true,
162
- sort: 'default',
163
- defaultSwimlaneGroup: null,
164
- activeTag: null,
165
- optionLineNumbers: {},
166
- holidaysLineNumber: null,
167
- sprintLength: null,
168
- sprintNumber: null,
169
- sprintStart: null,
170
- sprintMode: null,
171
- solidFill: false,
172
- noTitle: false,
173
- },
174
- diagnostics,
175
- error: null,
176
- syntaxMode: 'new', // always new-mode at 1.0
177
- };
178
-
179
- // Bespoke (not the shared makeFail, Story 111.4): gantt accumulates into a
180
- // local `diagnostics` array, not `result.diagnostics`.
181
- const fail = (line: number, message: string): ParsedGantt => {
182
- const diag = makeDgmoError(line, message);
183
- diagnostics.push(diag);
184
- result.error = formatDgmoError(diag);
185
- return result;
186
- };
187
-
188
- const warn = (line: number, message: string): void => {
189
- diagnostics.push(makeDgmoError(line, message, 'warning'));
190
- };
191
-
192
- /** Red squiggly but parsing continues — line is wrong, rest of chart is fine */
193
- const softError = (line: number, message: string): void => {
194
- diagnostics.push(makeDgmoError(line, message, 'error'));
195
- };
196
-
197
- // ── Alias map for pipe metadata (per A1 convention) ─────
198
-
199
- const metaAliasMap = new Map<string, string>();
200
- // ── nameAliasMap: TD-18 entity-name aliases (per C8) ────
201
- const nameAliasMap = new Map<string, string>();
202
- function peelAlias(label: string): { label: string; alias?: string } {
203
- const trimmed = label.trim();
204
- const m = trimmed.match(/^(.*?)\s+as\s+([A-Za-z][A-Za-z0-9_]{0,11})\s*$/);
205
- if (!m) return { label: trimmed };
206
- // Capture groups 1 and 2 are guaranteed by successful regex match.
207
- return { label: m[1]!.trim(), alias: m[2]! };
208
- }
209
- function resolveAliasTarget(token: string): string {
210
- return nameAliasMap.get(token.trim()) ?? token;
211
- }
212
-
213
- // ── Block stack ─────────────────────────────────────────
214
-
215
- const blockStack: BlockEntry[] = [];
216
-
217
- const currentContainer = (): GanttNode[] => {
218
- // Walk down from the top of the stack to find the nearest
219
- // group/parallel container. Skip task entries — tasks don't
220
- // contain other tasks in the tree (deps are via arrows, not nesting).
221
- for (let k = blockStack.length - 1; k >= 0; k--) {
222
- if (blockStack[k]!.containerType !== 'task') {
223
- return blockStack[k]!.node.children;
224
- }
225
- }
226
- return result.nodes;
227
- };
228
-
229
- const currentGroupPath = (): string[] => {
230
- const path: string[] = [];
231
- for (const entry of blockStack) {
232
- if (entry.containerType === 'group') {
233
- path.push((entry.node as GanttGroup).name);
234
- }
235
- }
236
- return path;
237
- };
238
-
239
- // ── State ───────────────────────────────────────────────
240
-
241
- let seenChartType = false;
242
- let inHolidaysBlock = false;
243
- let holidaysBlockIndent = 0;
244
- let inTagBlock = false;
245
- let currentTagGroup: Writable<TagGroup> | null = null;
246
- let tagBlockIndent = 0;
247
- let inEraBlock = false;
248
- let eraBlockIndent = 0;
249
- let inMarkerBlock = false;
250
- let markerBlockIndent = 0;
251
- let lastTaskNode: Writable<GanttNode & { kind: 'task' }> | null = null;
252
- let taskIdCounter = 0;
253
- const seriesColors = palette ? getSeriesColors(palette) : [];
254
- // 1.0: parser is always new-mode; legacy scheduling forms were removed.
255
- const syntaxMode = 'new' as const;
256
- result.syntaxMode = syntaxMode;
257
- // const definedTaskNames = new Map<string, string>(); // normalized name → scope key (Phase 6 diagnostics)
258
-
259
- // ── Main Parse Loop ─────────────────────────────────────
260
-
261
- for (let i = 0; i < lines.length; i++) {
262
- // In-bounds by loop guard.
263
- const rawLine = lines[i]!;
264
- const line = rawLine.trim();
265
- const indent = measureIndent(rawLine);
266
- const lineNumber = i + 1;
267
-
268
- // Skip empty lines
269
- if (!line) {
270
- // Empty line ends holidays/tag/era/marker blocks only if at root indent
271
- if (inHolidaysBlock && indent <= holidaysBlockIndent) {
272
- inHolidaysBlock = false;
273
- }
274
- if (inEraBlock && indent <= eraBlockIndent) {
275
- inEraBlock = false;
276
- }
277
- if (inMarkerBlock && indent <= markerBlockIndent) {
278
- inMarkerBlock = false;
279
- }
280
- if (inTagBlock && indent <= tagBlockIndent) {
281
- inTagBlock = false;
282
- if (currentTagGroup) {
283
- result.tagGroups.push(currentTagGroup);
284
- currentTagGroup = null;
285
- }
286
- }
287
- continue;
288
- }
289
-
290
- // ── Chart type ────────────────────────────────────────
291
-
292
- if (!seenChartType) {
293
- const firstLineResult = parseFirstLine(line);
294
- if (firstLineResult) {
295
- if (firstLineResult.chartType !== 'gantt') {
296
- return fail(
297
- lineNumber,
298
- `Expected chart type "gantt", got "${firstLineResult.chartType}"`
299
- );
300
- }
301
- seenChartType = true;
302
- if (firstLineResult.title) {
303
- result.options.title = firstLineResult.title;
304
- result.options.titleLineNumber = lineNumber;
305
- }
306
- continue;
307
- }
308
- }
309
-
310
- // ── Holidays block ────────────────────────────────────
311
-
312
- if (inHolidaysBlock) {
313
- if (indent <= holidaysBlockIndent) {
314
- inHolidaysBlock = false;
315
- // fall through to process this line normally
316
- } else {
317
- // Parse holiday entries
318
- const rangeMatch = line.match(HOLIDAY_RANGE_RE);
319
- if (rangeMatch) {
320
- // Capture groups 1-3 guaranteed by successful regex match.
321
- holidays.ranges.push({
322
- startDate: rangeMatch[1]!,
323
- endDate: rangeMatch[2]!,
324
- label: rangeMatch[3]!.trim(),
325
- lineNumber,
326
- });
327
- continue;
328
- }
329
-
330
- const dateMatch = line.match(HOLIDAY_DATE_RE);
331
- if (dateMatch) {
332
- // Capture groups 1-2 guaranteed by successful regex match.
333
- holidays.dates.push({
334
- date: dateMatch[1]!,
335
- label: dateMatch[2]!.trim(),
336
- lineNumber,
337
- });
338
- continue;
339
- }
340
-
341
- const workweekMatch = line.match(WORKWEEK_RE);
342
- if (workweekMatch) {
343
- // Capture group 1 guaranteed by successful regex match.
344
- const days = parseWorkweek(workweekMatch[1]!.trim());
345
- if (days) {
346
- holidays.workweek = days;
347
- } else {
348
- warn(
349
- lineNumber,
350
- `Invalid workweek format: "${workweekMatch[1]}". Use day range like "sun-thu" or comma-separated days.`
351
- );
352
- }
353
- continue;
354
- }
355
-
356
- // Skip comments inside holidays
357
- if (COMMENT_RE.test(line)) continue;
358
-
359
- warn(
360
- lineNumber,
361
- `Unrecognized holiday entry: "${line}". Use a date '2024-02-19 Presidents Day' or a range '2024-05-27 -> 2024-05-29 Memorial Weekend'. (§13.3)`
362
- );
363
- continue;
364
- }
365
- }
366
-
367
- // ── Era block entries ─────────────────────────────────
368
-
369
- if (inEraBlock) {
370
- if (indent <= eraBlockIndent) {
371
- inEraBlock = false;
372
- // fall through to process this line normally
373
- } else {
374
- if (COMMENT_RE.test(line)) continue;
375
- const eraEntryMatch = line.match(ERA_ENTRY_RE);
376
- if (eraEntryMatch) {
377
- // Capture groups 1-3 guaranteed by successful regex match.
378
- const eraLabelRaw = eraEntryMatch[3]!.trim();
379
- const eraExtracted = extractColor(
380
- eraLabelRaw,
381
- palette,
382
- diagnostics,
383
- lineNumber
384
- );
385
- result.eras.push({
386
- startDate: eraEntryMatch[1]!,
387
- endDate: eraEntryMatch[2]!,
388
- label: eraExtracted.label,
389
- color: eraExtracted.color || null,
390
- lineNumber,
391
- });
392
- } else {
393
- warn(
394
- lineNumber,
395
- `Unrecognized era entry: "${line}". Use 'YYYY-MM-DD -> YYYY-MM-DD Label [color]' (e.g. '2026-04-06 -> 2026-04-10 Conference purple'). (§13.5)`
396
- );
397
- }
398
- continue;
399
- }
400
- }
401
-
402
- // ── Marker block entries ─────────────────────────────
403
-
404
- if (inMarkerBlock) {
405
- if (indent <= markerBlockIndent) {
406
- inMarkerBlock = false;
407
- // fall through to process this line normally
408
- } else {
409
- if (COMMENT_RE.test(line)) continue;
410
- const markerEntryMatch = line.match(MARKER_ENTRY_RE);
411
- if (markerEntryMatch) {
412
- // Capture groups 1-2 guaranteed by successful regex match.
413
- const markerLabelRaw = markerEntryMatch[2]!.trim();
414
- const markerExtracted = extractColor(
415
- markerLabelRaw,
416
- palette,
417
- diagnostics,
418
- lineNumber
419
- );
420
- result.markers.push({
421
- date: markerEntryMatch[1]!,
422
- label: markerExtracted.label,
423
- color: markerExtracted.color || null,
424
- lineNumber,
425
- });
426
- } else {
427
- warn(
428
- lineNumber,
429
- `Unrecognized marker entry: "${line}". Use 'YYYY-MM-DD Label [color]' (e.g. '2026-03-27 Board Review' or '2026-06-15 Release green'). (§13.6)`
430
- );
431
- }
432
- continue;
433
- }
434
- }
435
-
436
- // ── Tag block entries ─────────────────────────────────
437
-
438
- if (inTagBlock && currentTagGroup) {
439
- if (indent <= tagBlockIndent) {
440
- // End of tag block
441
- inTagBlock = false;
442
- result.tagGroups.push(currentTagGroup);
443
- currentTagGroup = null;
444
- // fall through to process this line normally
445
- } else {
446
- // Parse tag entry: `Value color` or `Value`
447
- // First entry is the default unless another is marked `default`
448
- if (COMMENT_RE.test(line)) continue;
449
- const { text: cleanEntry, isDefault } = stripDefaultModifier(line);
450
- const extracted = extractColor(
451
- cleanEntry,
452
- palette,
453
- diagnostics,
454
- lineNumber
455
- );
456
- const color =
457
- extracted.color ||
458
- seriesColors[currentTagGroup.entries.length % seriesColors.length] ||
459
- '#888888';
460
- const isFirstEntry = currentTagGroup.entries.length === 0;
461
- currentTagGroup.entries.push({
462
- value: extracted.label,
463
- color,
464
- lineNumber,
465
- });
466
- if (isDefault) {
467
- currentTagGroup.defaultValue = extracted.label;
468
- } else if (isFirstEntry) {
469
- currentTagGroup.defaultValue = extracted.label;
470
- }
471
- continue;
472
- }
473
- }
474
-
475
- // ── Close blocks when indent decreases ────────────────
476
- // CRITICAL: close blocks BEFORE matching new elements
477
-
478
- // Track pop depth for sequential vs parallel arrow semantics.
479
- // Consecutive same-indent arrows = sequential chain.
480
- // Returning from a deeper subtree = parallel branch from parent.
481
- {
482
- let hadDeeperPop = false;
483
- let lastPoppedTaskRef: typeof lastTaskNode = null;
484
-
485
- while (blockStack.length > 0) {
486
- const top = blockStack[blockStack.length - 1]!;
487
- if (indent <= top.indent) {
488
- if (top.indent > indent) hadDeeperPop = true;
489
- if (top.containerType === 'task' && top.taskRef) {
490
- lastPoppedTaskRef = top.taskRef;
491
- }
492
- blockStack.pop();
493
- } else {
494
- break;
495
- }
496
- }
497
-
498
- if (hadDeeperPop) {
499
- // Came back from deeper subtree → parallel from parent
500
- for (let k = blockStack.length - 1; k >= 0; k--) {
501
- if (
502
- blockStack[k]!.containerType === 'task' &&
503
- blockStack[k]!.taskRef
504
- ) {
505
- lastTaskNode = blockStack[k]!.taskRef!;
506
- break;
507
- }
508
- }
509
- if (
510
- blockStack.length === 0 ||
511
- !blockStack.some((e) => e.containerType === 'task')
512
- ) {
513
- lastTaskNode = null;
514
- }
515
- } else if (lastPoppedTaskRef) {
516
- // Same-indent pop only → sequential from popped sibling
517
- lastTaskNode = lastPoppedTaskRef;
518
- }
519
- // If nothing was popped, lastTaskNode stays the same
520
- }
521
-
522
- // ── NEW-MODE: arrow / task / group / metadata parsing ──
523
-
524
- if (syntaxMode === 'new') {
525
- // 1. Arrow lines: `->`, `-3w->`, `--2w->`, `-label-> Target`
526
- const arrowResult = matchArrowLine(line);
527
- if (arrowResult) {
528
- // Parse remainder as task content (name + optional duration +
529
- // metadata).
530
- const content = parseNewTaskContent(arrowResult.rest, lineNumber);
531
-
532
- if (content.duration || content.explicitStart) {
533
- // Definition + dependency: create task AND edge
534
- const task = makeTask(
535
- content.name,
536
- content.duration,
537
- content.uncertain,
538
- lineNumber,
539
- content.explicitStart,
540
- content.preExtracted
541
- );
542
- const taskNode: GanttNode = { kind: 'task', ...task };
543
-
544
- // Add dependency ON lastTaskNode pointing TO the new task.
545
- // Convention: task.dependencies[].targetName = "the task that starts after this task finishes"
546
- if (lastTaskNode) {
547
- (lastTaskNode.dependencies as GanttDependency[]).push({
548
- targetName: content.name,
549
- ...(arrowResult.label !== undefined && {
550
- label: arrowResult.label,
551
- }),
552
- ...(arrowResult.lag !== undefined && { offset: arrowResult.lag }),
553
- lineNumber,
554
- });
555
- }
556
-
557
- currentContainer().push(taskNode);
558
- const writableTask = taskNode as Writable<
559
- GanttNode & { kind: 'task' }
560
- >;
561
- lastTaskNode = writableTask;
562
- blockStack.push({
563
- node: taskNode as unknown as Writable<GanttGroup>,
564
- indent,
565
- containerType: 'task',
566
- taskRef: writableTask,
567
- });
568
- } else {
569
- // Reference only: dependency edge from lastTaskNode to target.
570
- // The target body may carry offset metadata in the §1.4
571
- // (`Target offset: 2bd`) form.
572
- if (lastTaskNode) {
573
- const depBody = arrowResult.rest;
574
- let targetSegment: string;
575
- let meta: Record<string, string>;
576
- {
577
- const depRegistry = withTagAliases(
578
- GANTT_REGISTRY,
579
- new Set(metaAliasMap.keys())
580
- );
581
- const split = splitNameAndMeta(
582
- depBody.trim(),
583
- depRegistry,
584
- metaAliasMap
585
- );
586
- warnUnknownMetaKeys(
587
- split.meta,
588
- depRegistry,
589
- (msg) => warn(lineNumber, msg),
590
- split.name
591
- );
592
- targetSegment = split.name;
593
- meta = split.meta;
594
- }
595
- const targetName = resolveAliasTarget(targetSegment);
596
- let offset: Offset | undefined = arrowResult.lag;
597
-
598
- if (meta['lag'] || meta['lead']) {
599
- const key = meta['lag'] ? 'lag' : 'lead';
600
- softError(
601
- lineNumber,
602
- `"${key}" is no longer supported — use "offset: ${meta[key]}" instead.${key === 'lead' ? ' Negate the value for lead behavior: "offset: -...".' : ''}`
603
- );
604
- }
605
- if (meta['offset']) {
606
- const raw = meta['offset'];
607
- if (raw.trim().startsWith('+')) {
608
- warn(
609
- lineNumber,
610
- `Invalid offset: "${raw}". Explicit "+" is not supported — use "${raw.trim().slice(1)}" instead.`
611
- );
612
- } else {
613
- offset = parseOffset(raw) ?? undefined;
614
- if (!offset) {
615
- warn(
616
- lineNumber,
617
- `Invalid offset: "${raw}". Expected format like "3bd", "-5d", or "0bd".`
618
- );
619
- }
620
- }
621
- }
622
-
623
- (lastTaskNode.dependencies as GanttDependency[]).push({
624
- targetName,
625
- ...(arrowResult.label !== undefined && {
626
- label: arrowResult.label,
627
- }),
628
- ...(offset !== undefined && { offset }),
629
- lineNumber,
630
- });
631
- } else {
632
- softError(
633
- lineNumber,
634
- `Arrow '-> ${content.name}' has no source task — indent it under the task it follows (e.g. 'Design 5bd' then indented '-> ${content.name} 3bd'). (§13)`
635
- );
636
- }
637
- }
638
- continue;
639
- }
640
-
641
- // 2. Scope-based metadata: indented `key: value` under a task
642
- if (indent > 0 && lastTaskNode) {
643
- const colonIdx = line.indexOf(':');
644
- if (colonIdx > 0) {
645
- const candidateKey = line.substring(0, colonIdx).trim().toLowerCase();
646
- const registry = withTagAliases(
647
- GANTT_REGISTRY,
648
- new Set(metaAliasMap.keys())
649
- );
650
- const resolvedKey =
651
- metaAliasMap.get(normalizeName(candidateKey)) ?? candidateKey;
652
- if (isReservedKey(registry, resolvedKey)) {
653
- const value = line.substring(colonIdx + 1).trim();
654
- // Attach to the owning task (walk up block stack)
655
- const ownerTask =
656
- findOwningTask(blockStack, indent) ?? lastTaskNode;
657
- if (ownerTask) {
658
- const mutableMeta = ownerTask.metadata as Record<string, string>;
659
- if (resolvedKey === 'progress') {
660
- const p = parseFloat(value);
661
- if (!Number.isNaN(p)) {
662
- (ownerTask as Writable<GanttTask>).progress = p;
663
- }
664
- } else if (resolvedKey === 'offset') {
665
- const off = parseOffsetPrefix(value) ?? parseOffset(value);
666
- if (off) (ownerTask as Writable<GanttTask>).offset = off;
667
- } else {
668
- mutableMeta[resolvedKey] = value;
669
- }
670
- }
671
- continue;
672
- }
673
- }
674
- }
675
-
676
- // 3. Comment under a task
677
- if (lastTaskNode && indent > 0 && COMMENT_RE.test(line)) {
678
- const commentText = line.replace(/^\/\/\s?/, '');
679
- lastTaskNode.comment = lastTaskNode.comment
680
- ? lastTaskNode.comment + '\n' + commentText
681
- : commentText;
682
- continue;
683
- }
684
-
685
- // 4. Top-level comment
686
- if (COMMENT_RE.test(line)) continue;
687
-
688
- // 5. Skip to shared header options (holidays, tags, eras, markers, options)
689
- // These are handled below in the shared section. Fall through to them.
690
- // But first check for: era/marker with offsets, offset+group, offset+task, group, positional task
691
-
692
- // 6. Era with offset: `era +4w -> +8w Label [color]`
693
- const eraOffsetMatch = line.match(ERA_OFFSET_RE);
694
- if (eraOffsetMatch) {
695
- const startOff = parseOffsetPrefix('+' + eraOffsetMatch[1]!);
696
- const endOff = parseOffsetPrefix('+' + eraOffsetMatch[2]!);
697
- const eraLabelRaw = eraOffsetMatch[3]!.trim();
698
- const eraExtracted = extractColor(
699
- eraLabelRaw,
700
- palette,
701
- diagnostics,
702
- lineNumber
703
- );
704
- result.eras.push({
705
- startDate: '',
706
- endDate: '',
707
- label: eraExtracted.label,
708
- color: eraExtracted.color || null,
709
- lineNumber,
710
- ...(startOff && { offsetStart: startOff }),
711
- ...(endOff && { offsetEnd: endOff }),
712
- });
713
- continue;
714
- }
715
-
716
- // 7. Marker with offset: `marker +10w Label [color]`
717
- const markerOffsetMatch = line.match(MARKER_OFFSET_RE);
718
- if (markerOffsetMatch) {
719
- const dateOff = parseOffsetPrefix('+' + markerOffsetMatch[1]!);
720
- const markerLabelRaw = markerOffsetMatch[2]!.trim();
721
- const markerExtracted = extractColor(
722
- markerLabelRaw,
723
- palette,
724
- diagnostics,
725
- lineNumber
726
- );
727
- result.markers.push({
728
- date: '',
729
- label: markerExtracted.label,
730
- color: markerExtracted.color || null,
731
- lineNumber,
732
- ...(dateOff && { offsetDate: dateOff }),
733
- });
734
- continue;
735
- }
736
-
737
- // Fall through to shared sections (holidays, tags, date-based eras/markers,
738
- // options). They will continue if matched. If nothing matches, we reach
739
- // the new-mode task/group section below (after shared options).
740
- }
741
-
742
- // ── Top-level comment ─────────────────────────────────
743
-
744
- if (COMMENT_RE.test(line)) continue;
745
-
746
- // ── Header options ────────────────────────────────────
747
-
748
- if (line.toLowerCase() === 'holiday' || line.toLowerCase() === 'holidays') {
749
- inHolidaysBlock = true;
750
- holidaysBlockIndent = indent;
751
- result.options.holidaysLineNumber = lineNumber;
752
- continue;
753
- }
754
-
755
- // Single-line holiday: `holiday 2024-12-25 Christmas`
756
- const holidayInlineMatch = line.match(
757
- /^holiday\s+(\d{4}-\d{2}-\d{2})\s+(.+)$/i
758
- );
759
- if (holidayInlineMatch) {
760
- // Capture groups 1-2 guaranteed by successful regex match.
761
- holidays.dates.push({
762
- date: holidayInlineMatch[1]!,
763
- label: holidayInlineMatch[2]!.trim(),
764
- lineNumber,
765
- });
766
- result.options.holidaysLineNumber ??= lineNumber;
767
- continue;
768
- }
769
-
770
- // Tag block heading
771
- const tagMatch = matchTagBlockHeading(line);
772
- if (tagMatch) {
773
- inTagBlock = true;
774
- tagBlockIndent = indent;
775
- currentTagGroup = {
776
- name: tagMatch.name,
777
- ...(tagMatch.alias !== undefined && { alias: tagMatch.alias }),
778
- entries: [],
779
- lineNumber,
780
- };
781
- if (tagMatch.alias) {
782
- metaAliasMap.set(
783
- normalizeName(tagMatch.alias),
784
- tagAttrKey(tagMatch.name)
785
- );
786
- }
787
- metaAliasMap.set(normalizeName(tagMatch.name), tagAttrKey(tagMatch.name));
788
- continue;
789
- }
790
-
791
- // Top-level workweek (outside holiday block)
792
- const topWorkweekMatch = line.match(WORKWEEK_RE);
793
- if (topWorkweekMatch) {
794
- // Capture group 1 guaranteed by successful regex match.
795
- const days = parseWorkweek(topWorkweekMatch[1]!.trim());
796
- if (days) {
797
- holidays.workweek = days;
798
- } else {
799
- warn(
800
- lineNumber,
801
- `Invalid workweek format: "${topWorkweekMatch[1]}". Use day range like "sun-thu" or comma-separated days.`
802
- );
803
- }
804
- continue;
805
- }
806
-
807
- // Era block: bare `era` keyword starts a block
808
- if (line.toLowerCase() === 'era') {
809
- inEraBlock = true;
810
- eraBlockIndent = indent;
811
- continue;
812
- }
813
-
814
- // Era (inline)
815
- const eraMatch = line.match(ERA_RE);
816
- if (eraMatch) {
817
- // Capture groups 1-3 guaranteed by successful regex match.
818
- const eraLabelRaw = eraMatch[3]!.trim();
819
- const eraExtracted = extractColor(
820
- eraLabelRaw,
821
- palette,
822
- diagnostics,
823
- lineNumber
824
- );
825
- result.eras.push({
826
- startDate: eraMatch[1]!,
827
- endDate: eraMatch[2]!,
828
- label: eraExtracted.label,
829
- color: eraExtracted.color || null,
830
- lineNumber,
831
- });
832
- continue;
833
- }
834
-
835
- // Marker block: bare `marker` keyword starts a block
836
- if (line.toLowerCase() === 'marker') {
837
- inMarkerBlock = true;
838
- markerBlockIndent = indent;
839
- continue;
840
- }
841
-
842
- // Marker (inline)
843
- const markerMatch = line.match(MARKER_RE);
844
- if (markerMatch) {
845
- // Capture groups 1-2 guaranteed by successful regex match.
846
- const markerLabelRaw = markerMatch[2]!.trim();
847
- const markerExtracted = extractColor(
848
- markerLabelRaw,
849
- palette,
850
- diagnostics,
851
- lineNumber
852
- );
853
- result.markers.push({
854
- date: markerMatch[1]!,
855
- label: markerExtracted.label,
856
- color: markerExtracted.color || null,
857
- lineNumber,
858
- });
859
- continue;
860
- }
861
-
862
- // ── New-syntax task: `Name duration: Xd` or `Name start: DATE` ─
863
- {
864
- const registry = withTagAliases(
865
- GANTT_REGISTRY,
866
- new Set(metaAliasMap.keys())
867
- );
868
- const split = splitNameAndMeta(
869
- line,
870
- registry,
871
- metaAliasMap,
872
- undefined,
873
- diagnostics,
874
- lineNumber
875
- );
876
- warnUnknownMetaKeys(
877
- split.meta,
878
- registry,
879
- (msg) => warn(lineNumber, msg),
880
- split.name
881
- );
882
- const rawDur = split.meta['duration'];
883
- const rawStart = split.meta['start'];
884
-
885
- if (rawDur !== undefined || rawStart !== undefined) {
886
- let duration: Duration | null = null;
887
- let uncertain = false;
888
-
889
- if (rawDur !== undefined) {
890
- const uncertainMatch = rawDur.match(/^(.+)\?$/);
891
- const durStr = uncertainMatch ? uncertainMatch[1]! : rawDur;
892
- if (uncertainMatch) uncertain = true;
893
- duration = parseDuration(durStr);
894
- if (!duration) {
895
- softError(
896
- lineNumber,
897
- `Invalid duration: "${rawDur}". Expected format like "30bd", "5d", "1.5w".`
898
- );
899
- continue;
900
- }
901
- }
902
-
903
- let explicitStart: string | undefined;
904
- if (rawStart !== undefined) {
905
- if (!/^\d{4}-\d{2}-\d{2}(?: \d{2}:\d{2})?$/.test(rawStart)) {
906
- softError(
907
- lineNumber,
908
- `Invalid start date: "${rawStart}". Expected YYYY-MM-DD or YYYY-MM-DD HH:MM.`
909
- );
910
- continue;
911
- }
912
- explicitStart = rawStart;
913
- }
914
-
915
- const taskName = split.name.trim();
916
- if (!taskName) {
917
- softError(lineNumber, `Task name cannot be empty.`);
918
- continue;
919
- }
920
-
921
- if (split.alias) nameAliasMap.set(split.alias, taskName);
922
-
923
- const preExtracted = { ...split.meta };
924
- delete preExtracted['duration'];
925
- delete preExtracted['start'];
926
- if (split.color) preExtracted['color'] = split.color;
927
-
928
- const task = makeTask(
929
- taskName,
930
- duration,
931
- uncertain,
932
- lineNumber,
933
- explicitStart,
934
- preExtracted
935
- );
936
- const taskNode: GanttNode = { kind: 'task', ...task };
937
- currentContainer().push(taskNode);
938
- const writableTaskN = taskNode as Writable<
939
- GanttNode & { kind: 'task' }
940
- >;
941
- lastTaskNode = writableTaskN;
942
- blockStack.push({
943
- node: taskNode as unknown as Writable<GanttGroup>,
944
- indent,
945
- containerType: 'task',
946
- taskRef: writableTaskN,
947
- });
948
- continue;
949
- }
950
- }
951
-
952
- // Options — space-separated: `start 2024-04-01`, `title My Plan`
953
- // Boolean options: bare keyword = on, `no-X` = off
954
- const optNoColonMatch = line.match(/^([a-z][a-z0-9-]*)\s+(.+)$/i);
955
- const bareKeyword = line.match(/^([a-z][a-z0-9-]*)$/i);
956
-
957
- // Bare boolean keywords
958
- // Capture group 1 guaranteed by successful regex match.
959
- if (bareKeyword && KNOWN_BOOLEANS.has(bareKeyword[1]!.toLowerCase())) {
960
- const key = bareKeyword[1]!.toLowerCase();
961
- result.options.optionLineNumbers[key] = lineNumber;
962
- switch (key) {
963
- case 'critical-path':
964
- result.options.criticalPath = true;
965
- break;
966
- case 'today-marker':
967
- result.options.todayMarker = 'on';
968
- break;
969
- case 'solid-fill':
970
- result.options.solidFill = true;
971
- break;
972
- case 'no-title':
973
- result.options.noTitle = true;
974
- break;
975
- }
976
- continue;
977
- }
978
-
979
- // Negated booleans: `no-dependencies`, `no-critical-path`
980
- // Capture group 1 guaranteed by successful regex match.
981
- if (bareKeyword && bareKeyword[1]!.toLowerCase().startsWith('no-')) {
982
- const base = bareKeyword[1]!.toLowerCase().substring(3);
983
- if (KNOWN_BOOLEANS.has(base)) {
984
- result.options.optionLineNumbers[base] = lineNumber;
985
- switch (base) {
986
- case 'dependencies':
987
- result.options.dependencies = false;
988
- break;
989
- case 'critical-path':
990
- result.options.criticalPath = false;
991
- break;
992
- case 'today-marker':
993
- result.options.todayMarker = 'off';
994
- break;
995
- }
996
- continue;
997
- }
998
- }
999
-
1000
- // Capture groups 1-2 guaranteed by successful regex match.
1001
- if (optNoColonMatch && isKnownOption(optNoColonMatch[1]!.toLowerCase())) {
1002
- const key = optNoColonMatch[1]!.toLowerCase();
1003
- const value = optNoColonMatch[2]!.trim();
1004
- result.options.optionLineNumbers[key] = lineNumber;
1005
-
1006
- switch (key) {
1007
- case 'start':
1008
- result.options.start = value;
1009
- break;
1010
- case 'title':
1011
- result.options.title = value;
1012
- result.options.titleLineNumber = lineNumber;
1013
- break;
1014
- case 'today-marker':
1015
- if (/^\d{4}-\d{2}-\d{2}(?: \d{2}:\d{2})?$/.test(value)) {
1016
- result.options.todayMarker = value;
1017
- } else {
1018
- warn(
1019
- lineNumber,
1020
- `Invalid today-marker value: "${value}". Expected YYYY-MM-DD.`
1021
- );
1022
- }
1023
- break;
1024
- case 'critical-path':
1025
- result.options.criticalPath = true;
1026
- break;
1027
- case 'dependencies':
1028
- // Boolean with value — but `dependencies` is now default ON, so only `no-dependencies` turns it off
1029
- result.options.dependencies = true;
1030
- break;
1031
- case 'sort':
1032
- if (value === 'tag' || value.startsWith('tag:')) {
1033
- result.options.sort = 'tag';
1034
- const colonIdx = value.indexOf(':');
1035
- if (colonIdx !== -1) {
1036
- result.options.defaultSwimlaneGroup =
1037
- value.slice(colonIdx + 1).trim() || null;
1038
- }
1039
- } else {
1040
- warn(
1041
- lineNumber,
1042
- `Invalid sort value: "${value}". Expected "tag" or "tag:GroupName".`
1043
- );
1044
- }
1045
- break;
1046
- // `lane-by <group>`: the canonical swimlane-axis directive (view-state).
1047
- // Equivalent to `sort: tag:<group>` — enables tag swimlanes on the named
1048
- // group. `sort tag` remains a back-compat spelling.
1049
- case 'lane-by':
1050
- result.options.sort = 'tag';
1051
- result.options.defaultSwimlaneGroup = value.trim() || null;
1052
- break;
1053
- case 'active-tag':
1054
- result.options.activeTag = value;
1055
- break;
1056
- case 'sprint-length': {
1057
- const dur = parseDuration(value);
1058
- if (!dur) {
1059
- warn(
1060
- lineNumber,
1061
- `Invalid sprint-length value: "${value}". Expected a duration like "2w" or "10d".`
1062
- );
1063
- } else if (dur.unit !== 'd' && dur.unit !== 'w') {
1064
- warn(
1065
- lineNumber,
1066
- `sprint-length only accepts "d" or "w" units, got "${dur.unit}".`
1067
- );
1068
- } else if (dur.amount <= 0) {
1069
- warn(lineNumber, `sprint-length must be greater than 0.`);
1070
- } else if (
1071
- !Number.isInteger(dur.amount * (dur.unit === 'w' ? 7 : 1))
1072
- ) {
1073
- warn(
1074
- lineNumber,
1075
- `sprint-length must resolve to a whole number of days.`
1076
- );
1077
- } else {
1078
- result.options.sprintLength = dur;
1079
- }
1080
- break;
1081
- }
1082
- case 'sprint-number': {
1083
- const n = Number(value);
1084
- if (!Number.isFinite(n) || !Number.isInteger(n) || n <= 0) {
1085
- warn(
1086
- lineNumber,
1087
- `sprint-number must be a positive integer, got "${value}".`
1088
- );
1089
- } else {
1090
- result.options.sprintNumber = n;
1091
- }
1092
- break;
1093
- }
1094
- case 'sprint-start': {
1095
- if (!/^\d{4}-\d{2}-\d{2}$/.test(value)) {
1096
- warn(
1097
- lineNumber,
1098
- `sprint-start requires a full date (YYYY-MM-DD), got "${value}".`
1099
- );
1100
- } else if (Number.isNaN(new Date(value + 'T00:00:00').getTime())) {
1101
- warn(lineNumber, `sprint-start is not a valid date: "${value}".`);
1102
- } else {
1103
- result.options.sprintStart = value;
1104
- }
1105
- break;
1106
- }
1107
- }
1108
- continue;
1109
- }
1110
-
1111
- // ── NEW-MODE: offset prefix + group / positional task ──
1112
-
1113
- if (syntaxMode === 'new') {
1114
- // Check for offset prefix: `+4w [Group]` or `+4w Task 30bd`
1115
- let restAfterOffset = line;
1116
- let lineOffset: Offset | undefined;
1117
- const offMatch = line.match(OFFSET_PREFIX_RE);
1118
- if (offMatch) {
1119
- lineOffset = parseOffsetPrefix('+' + offMatch[1]!) ?? undefined;
1120
- restAfterOffset = offMatch[2]!;
1121
- }
1122
-
1123
- // Group: `[GroupName]` with optional offset
1124
- const gm = restAfterOffset.match(GROUP_RE);
1125
- if (gm) {
1126
- if (
1127
- blockStack.length > 0 &&
1128
- blockStack[blockStack.length - 1]!.containerType === 'task'
1129
- ) {
1130
- softError(
1131
- lineNumber,
1132
- `Cannot nest a group inside a task. Groups must be inside other groups.`
1133
- );
1134
- continue;
1135
- }
1136
- const afterBrackets = gm[2]!.trim();
1137
- let metadata: Record<string, string> = {};
1138
- if (afterBrackets) {
1139
- const groupRegistry = withTagAliases(
1140
- GANTT_REGISTRY,
1141
- new Set(metaAliasMap.keys())
1142
- );
1143
- // `afterBrackets` is the same-line metadata tail; run it through
1144
- // splitNameAndMeta with a placeholder name so only the meta region
1145
- // is parsed (§1.4 same-line `key: value`).
1146
- const split = splitNameAndMeta(
1147
- `_ ${afterBrackets}`,
1148
- groupRegistry,
1149
- metaAliasMap,
1150
- undefined,
1151
- result.diagnostics,
1152
- lineNumber
1153
- );
1154
- warnUnknownMetaKeys(
1155
- split.meta,
1156
- groupRegistry,
1157
- (msg) => warn(lineNumber, msg),
1158
- split.name
1159
- );
1160
- metadata = split.meta;
1161
- }
1162
- // `[Group] collapsed: true` view-state marker (§ mirrors sequence): a
1163
- // reserved same-line key that seeds the group collapsed. Extracted into
1164
- // a typed field so it drives render/export; dropped from metadata.
1165
- let collapsed = false;
1166
- if (metadata['collapsed']?.toLowerCase() === 'true') {
1167
- collapsed = true;
1168
- delete metadata['collapsed'];
1169
- }
1170
- const groupPeeled = peelAlias(gm[1]!);
1171
- if (groupPeeled.alias)
1172
- nameAliasMap.set(groupPeeled.alias, groupPeeled.label);
1173
- const group: Writable<GanttGroup> = {
1174
- name: groupPeeled.label,
1175
- color: null,
1176
- metadata,
1177
- ...(lineOffset && { offset: lineOffset }),
1178
- ...(collapsed && { collapsed: true }),
1179
- lineNumber,
1180
- children: [],
1181
- };
1182
- const groupNode: GanttNode = { kind: 'group', ...group };
1183
- currentContainer().push(groupNode);
1184
- blockStack.push({
1185
- node: groupNode as unknown as Writable<GanttGroup>,
1186
- indent,
1187
- containerType: 'group',
1188
- });
1189
- lastTaskNode = null;
1190
- continue;
1191
- }
1192
-
1193
- // Positional task: `[+offset] Name Duration [metadata]`
1194
- // Also handles milestones: `Launch 0d`, offset tasks: `+4w Task 30bd`
1195
- {
1196
- const content = parseNewTaskContent(restAfterOffset, lineNumber);
1197
- if (
1198
- content.name &&
1199
- !content.duration &&
1200
- !content.explicitStart &&
1201
- !lineOffset
1202
- ) {
1203
- softError(
1204
- lineNumber,
1205
- `Expected task with duration/start (e.g., "${content.name} 5d"), group brackets (e.g., "[Group]"), or keyword. Got: "${line}"`
1206
- );
1207
- continue;
1208
- }
1209
- if (content.name || content.duration || content.explicitStart) {
1210
- const task = makeTask(
1211
- content.name,
1212
- content.duration,
1213
- content.uncertain,
1214
- lineNumber,
1215
- content.explicitStart,
1216
- content.preExtracted
1217
- );
1218
- if (lineOffset) {
1219
- (task as Writable<GanttTask>).offset = lineOffset;
1220
- }
1221
- const taskNode: GanttNode = { kind: 'task', ...task };
1222
- currentContainer().push(taskNode);
1223
- const writableTask = taskNode as Writable<
1224
- GanttNode & { kind: 'task' }
1225
- >;
1226
- lastTaskNode = writableTask;
1227
- blockStack.push({
1228
- node: taskNode as unknown as Writable<GanttGroup>,
1229
- indent,
1230
- containerType: 'task',
1231
- taskRef: writableTask,
1232
- });
1233
- continue;
1234
- }
1235
- }
1236
-
1237
- // If nothing matched in new mode, emit error
1238
- softError(
1239
- lineNumber,
1240
- `Expected task (e.g., "Task Name 5d"), arrow (e.g., "-> Task 3w"), group (e.g., "[Group]"), or directive. Got: "${line}"`
1241
- );
1242
- continue;
1243
- }
1244
- }
1245
-
1246
- // ── Finalize ────────────────────────────────────────────
1247
-
1248
- // Push final tag group if still open
1249
- if (currentTagGroup) {
1250
- result.tagGroups.push(currentTagGroup);
1251
- }
1252
-
1253
- // If no chart type was declared, that's acceptable (inferred from context)
1254
-
1255
- // Validate sort: tag requires tag groups
1256
- if (result.options.sort === 'tag' && result.tagGroups.length === 0) {
1257
- warn(0, 'sort tag has no effect — no tag groups defined.');
1258
- result.options.sort = 'default';
1259
- }
1260
-
1261
- validateTagGroupNames(result.tagGroups, warn, (line, msg) => {
1262
- const diag = makeDgmoError(line, msg);
1263
- diagnostics.push(diag);
1264
- if (!result.error) result.error = formatDgmoError(diag);
1265
- });
1266
-
1267
- // ── Sprint mode detection ──────────────────────────────
1268
- const hasSprintOption =
1269
- result.options.sprintLength !== null ||
1270
- result.options.sprintNumber !== null ||
1271
- result.options.sprintStart !== null;
1272
-
1273
- const hasSprintUnit = hasSprintDurationUnit(result.nodes);
1274
-
1275
- if (hasSprintOption) {
1276
- result.options.sprintMode = 'explicit';
1277
- } else if (hasSprintUnit) {
1278
- result.options.sprintMode = 'auto';
1279
- }
1280
-
1281
- // Apply defaults when sprint mode is active
1282
- if (result.options.sprintMode) {
1283
- if (!result.options.sprintLength) {
1284
- result.options.sprintLength = { amount: 2, unit: 'w' };
1285
- }
1286
- if (result.options.sprintNumber === null) {
1287
- result.options.sprintNumber = 1;
1288
- }
1289
- // sprintStart defaults to chart start or today — handled in calculator
1290
- }
1291
-
1292
- return result;
1293
-
1294
- // ── Helper: match arrow line (new syntax) ──────────────
1295
-
1296
- interface ArrowMatch {
1297
- rest: string;
1298
- lag?: Offset | undefined;
1299
- label?: string | undefined;
1300
- }
1301
-
1302
- function matchArrowLine(trimmedLine: string): ArrowMatch | null {
1303
- // Lead arrow: `--2w-> Rest` (negative lag)
1304
- const leadMatch = trimmedLine.match(LEAD_ARROW_RE);
1305
- if (leadMatch) {
1306
- const dur = parseDuration(leadMatch[1]!);
1307
- const match: ArrowMatch = { rest: leadMatch[2]! };
1308
- if (dur) match.lag = { duration: dur, direction: -1 };
1309
- return match;
1310
- }
1311
- // Lag arrow: `-3w-> Rest` (positive lag)
1312
- const lagMatch = trimmedLine.match(LAG_ARROW_RE);
1313
- if (lagMatch) {
1314
- const dur = parseDuration(lagMatch[1]!);
1315
- const match: ArrowMatch = { rest: lagMatch[2]! };
1316
- if (dur) match.lag = { duration: dur, direction: 1 };
1317
- return match;
1318
- }
1319
- // Basic arrow: `-> Rest`
1320
- const basicMatch = trimmedLine.match(BASIC_ARROW_RE);
1321
- if (basicMatch) {
1322
- return { rest: basicMatch[1]! };
1323
- }
1324
- // Labeled arrow: `-blocks-> Rest` / `-depends on-> Rest`.
1325
- // The label is any text between the leading `-` and `->` that is
1326
- // NOT a pure lag/lead duration (those are handled above).
1327
- const labeledMatch = trimmedLine.match(DEPENDENCY_RE);
1328
- if (labeledMatch?.[1]) {
1329
- return { rest: labeledMatch[2]!, label: labeledMatch[1].trim() };
1330
- }
1331
- return null;
1332
- }
1333
-
1334
- // ── Helper: parse new task content (positional duration) ─
1335
-
1336
- interface NewTaskContent {
1337
- name: string;
1338
- duration: Duration | null;
1339
- uncertain: boolean;
1340
- explicitStart?: string | undefined;
1341
- preExtracted: Record<string, string>;
1342
- }
1343
-
1344
- function parseNewTaskContent(rawContent: string, ln: number): NewTaskContent {
1345
- const registry = withTagAliases(
1346
- GANTT_REGISTRY,
1347
- new Set(metaAliasMap.keys())
1348
- );
1349
- const split = splitNameAndMeta(
1350
- rawContent,
1351
- registry,
1352
- metaAliasMap,
1353
- undefined,
1354
- diagnostics,
1355
- ln
1356
- );
1357
- warnUnknownMetaKeys(
1358
- split.meta,
1359
- registry,
1360
- (msg) => warn(ln, msg),
1361
- split.name
1362
- );
1363
-
1364
- let name = split.name;
1365
- let duration: Duration | null = null;
1366
- let uncertain = false;
1367
- let explicitStart: string | undefined;
1368
- const metadata = { ...split.meta };
1369
-
1370
- // Check for explicit `duration:` key (fallback for ambiguous names)
1371
- if (metadata['duration']) {
1372
- const durStr = metadata['duration'];
1373
- const uncertainMatch = durStr.match(/^(.+)\?$/);
1374
- const cleanDur = uncertainMatch ? uncertainMatch[1]! : durStr;
1375
- if (uncertainMatch) uncertain = true;
1376
- duration = parseDuration(cleanDur);
1377
- if (!duration) {
1378
- softError(
1379
- ln,
1380
- `Invalid duration: "${durStr}". Expected format like "30bd", "5d", "1.5w".`
1381
- );
1382
- }
1383
- delete metadata['duration'];
1384
- }
1385
-
1386
- // Check for explicit `start:` key
1387
- if (metadata['start']) {
1388
- const raw = metadata['start'];
1389
- if (!/^\d{4}-\d{2}-\d{2}(?: \d{2}:\d{2})?$/.test(raw)) {
1390
- softError(ln, `Invalid start date: "${raw}". Expected YYYY-MM-DD.`);
1391
- } else {
1392
- explicitStart = raw;
1393
- }
1394
- delete metadata['start'];
1395
- }
1396
-
1397
- // Right-to-left scan for positional duration (only if no explicit keys)
1398
- if (!duration && !explicitStart) {
1399
- const tokens = name.split(/\s+/).filter(Boolean);
1400
- for (let j = tokens.length - 1; j >= 0; j--) {
1401
- const m = tokens[j]!.match(DURATION_TOKEN_RE);
1402
- if (m) {
1403
- duration = { amount: parseFloat(m[1]!), unit: m[2]! as DurationUnit };
1404
- uncertain = !!m[3];
1405
- name = tokens.slice(0, j).join(' ');
1406
- break;
1407
- }
1408
- }
1409
- }
1410
-
1411
- // Build pre-extracted metadata (color, remaining keys)
1412
- const preExtracted = { ...metadata };
1413
- if (split.color) preExtracted['color'] = split.color;
1414
-
1415
- return {
1416
- name: name.trim(),
1417
- duration,
1418
- uncertain,
1419
- explicitStart,
1420
- preExtracted,
1421
- };
1422
- }
1423
-
1424
- // ── Helper: find owning task for scope-based metadata ───
1425
-
1426
- function findOwningTask(
1427
- stack: BlockEntry[],
1428
- metaIndent: number
1429
- ): Writable<GanttNode & { kind: 'task' }> | null {
1430
- for (let k = stack.length - 1; k >= 0; k--) {
1431
- const entry = stack[k]!;
1432
- if (
1433
- entry.containerType === 'task' &&
1434
- entry.taskRef &&
1435
- entry.indent < metaIndent
1436
- ) {
1437
- return entry.taskRef;
1438
- }
1439
- }
1440
- return null;
1441
- }
1442
-
1443
- // ── Helper: create a task ───────────────────────────────
1444
-
1445
- function makeTask(
1446
- labelRaw: string,
1447
- duration: Duration | null,
1448
- uncertain: boolean,
1449
- ln: number,
1450
- explicitStart?: string,
1451
- preExtractedMeta?: Record<string, string>
1452
- ): GanttTask {
1453
- // TD-18: peel optional `as <alias>` from the label.
1454
- const peeled = peelAlias(labelRaw);
1455
- let label = peeled.label;
1456
- if (peeled.alias) nameAliasMap.set(peeled.alias, label);
1457
-
1458
- // Check for reserved keyword
1459
- if (label.toLowerCase() === 'parallel') {
1460
- softError(
1461
- ln,
1462
- `"parallel" is a reserved keyword and cannot be used as a task name.`
1463
- );
1464
- }
1465
-
1466
- const metadata: Record<string, string> = {};
1467
-
1468
- // §1.4 unified metadata grammar — pick up the same-line form
1469
- // (`Name key: value`) by running splitNameAndMeta on the label.
1470
- {
1471
- const registry = withTagAliases(
1472
- GANTT_REGISTRY,
1473
- new Set(metaAliasMap.keys())
1474
- );
1475
- const split = splitNameAndMeta(
1476
- label,
1477
- registry,
1478
- metaAliasMap,
1479
- undefined,
1480
- result.diagnostics,
1481
- ln
1482
- );
1483
- warnUnknownMetaKeys(
1484
- split.meta,
1485
- registry,
1486
- (msg) => warn(ln, msg),
1487
- split.name
1488
- );
1489
- if (Object.keys(split.meta).length > 0) {
1490
- label = split.name;
1491
- Object.assign(metadata, split.meta);
1492
- }
1493
- }
1494
-
1495
- if (preExtractedMeta) {
1496
- Object.assign(metadata, preExtractedMeta);
1497
- }
1498
-
1499
- // Extract progress from metadata or shorthand
1500
- let progress: number | null = null;
1501
- if (metadata['progress']) {
1502
- progress = parseFloat(metadata['progress']);
1503
- delete metadata['progress'];
1504
- }
1505
-
1506
- // Reject lag/lead — use offset instead
1507
- if (metadata['lag'] || metadata['lead']) {
1508
- const key = metadata['lag'] ? 'lag' : 'lead';
1509
- softError(
1510
- ln,
1511
- `"${key}" is no longer supported — use "offset: ${metadata[key]}" instead.${key === 'lead' ? ' Negate the value for lead behavior: "offset: -...".' : ''}`
1512
- );
1513
- }
1514
-
1515
- // Extract task-level offset from metadata
1516
- let taskOffset: Offset | undefined;
1517
- if (metadata['offset']) {
1518
- const raw = metadata['offset'];
1519
- if (raw.trim().startsWith('+')) {
1520
- warn(
1521
- ln,
1522
- `Invalid offset: "${raw}". Explicit "+" is not supported — use "${raw.trim().slice(1)}" instead.`
1523
- );
1524
- } else {
1525
- taskOffset = parseOffset(raw) ?? undefined;
1526
- if (!taskOffset) {
1527
- warn(
1528
- ln,
1529
- `Invalid offset: "${raw}". Expected format like "3bd", "-5d", or "0bd".`
1530
- );
1531
- }
1532
- }
1533
- delete metadata['offset'];
1534
- }
1535
-
1536
- // Inherit metadata from parent groups (tag inheritance)
1537
- const groupPath = currentGroupPath();
1538
- const inheritedMeta: Record<string, string> = {};
1539
- for (const entry of blockStack) {
1540
- if (entry.containerType === 'group') {
1541
- const groupNode = entry.node as GanttGroup;
1542
- Object.assign(inheritedMeta, groupNode.metadata);
1543
- }
1544
- // parallel blocks are transparent for tags — skip
1545
- }
1546
- // Task's own metadata overrides inherited
1547
- const effectiveMetadata = { ...inheritedMeta, ...metadata };
1548
-
1549
- const id = `task_${taskIdCounter++}`;
1550
-
1551
- return {
1552
- id,
1553
- label,
1554
- duration,
1555
- ...(explicitStart !== undefined && { explicitStart }),
1556
- uncertain,
1557
- progress,
1558
- ...(taskOffset !== undefined && { offset: taskOffset }),
1559
- isDefinition: duration !== null || explicitStart !== undefined,
1560
- dependencies: [],
1561
- metadata: effectiveMetadata,
1562
- lineNumber: ln,
1563
- groupPath,
1564
- };
1565
- }
1566
- }
1567
-
1568
- // ── Utility: parse workweek string ────────────────────────
1569
-
1570
- function parseWorkweek(s: string): Weekday[] | null {
1571
- // Try range format: "sun-thu"
1572
- const rangeParts = s.toLowerCase().split('-');
1573
- if (rangeParts.length === 2) {
1574
- // In-bounds by length === 2 check.
1575
- const start = WEEKDAY_MAP[rangeParts[0]!.trim()];
1576
- const end = WEEKDAY_MAP[rangeParts[1]!.trim()];
1577
- if (start && end) {
1578
- const allDays: Weekday[] = [
1579
- 'mon',
1580
- 'tue',
1581
- 'wed',
1582
- 'thu',
1583
- 'fri',
1584
- 'sat',
1585
- 'sun',
1586
- ];
1587
- const startIdx = allDays.indexOf(start);
1588
- const endIdx = allDays.indexOf(end);
1589
- const days: Weekday[] = [];
1590
- let idx = startIdx;
1591
- while (true) {
1592
- // In-bounds: allDays has length 7 and idx stays in [0..6] via % 7.
1593
- days.push(allDays[idx]!);
1594
- if (idx === endIdx) break;
1595
- idx = (idx + 1) % 7;
1596
- }
1597
- return days;
1598
- }
1599
- }
1600
-
1601
- // Try comma-separated: "mon, tue, wed, thu, fri"
1602
- const parts = s
1603
- .toLowerCase()
1604
- .split(',')
1605
- .map((p) => p.trim());
1606
- const days: Weekday[] = [];
1607
- for (const part of parts) {
1608
- const day = WEEKDAY_MAP[part];
1609
- if (!day) return null;
1610
- days.push(day);
1611
- }
1612
- return days.length > 0 ? days : null;
1613
- }
1614
-
1615
- // ── Known option keys ─────────────────────────────────────
1616
-
1617
- // Derived from the single-source directives registry; the anti-drift guard
1618
- // (tests/highlight-coverage.test.ts) cross-checks this vocab against the
1619
- // editor keyword sets. Re-exported under the historical names for callers.
1620
- export const GANTT_KNOWN_OPTIONS = GANTT_OPTION_SET;
1621
- const KNOWN_OPTIONS = GANTT_KNOWN_OPTIONS;
1622
-
1623
- /** Boolean options that can appear as bare keywords or with `no-` prefix. */
1624
- export const GANTT_KNOWN_BOOLEANS = GANTT_BOOLEAN_SET;
1625
- const KNOWN_BOOLEANS = GANTT_KNOWN_BOOLEANS;
1626
-
1627
- function isKnownOption(key: string): boolean {
1628
- return KNOWN_OPTIONS.has(key);
1629
- }
1630
-
1631
- /** Check if any task in the tree uses the `s` (sprint) duration unit. */
1632
- function hasSprintDurationUnit(nodes: readonly GanttNode[]): boolean {
1633
- for (const node of nodes) {
1634
- if (node.kind === 'task') {
1635
- if (node.duration?.unit === 's') return true;
1636
- } else if (node.kind === 'group' || node.kind === 'parallel') {
1637
- if (hasSprintDurationUnit(node.children)) return true;
1638
- }
1639
- }
1640
- return false;
1641
- }