@nowline/layout 0.8.5 → 0.9.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 (339) hide show
  1. package/dist/axis-columns.d.ts +70 -0
  2. package/dist/axis-columns.d.ts.map +1 -0
  3. package/dist/axis-columns.js +104 -0
  4. package/dist/axis-columns.js.map +1 -0
  5. package/dist/band-scale.d.ts.map +1 -1
  6. package/dist/calendar-resolver.d.ts +27 -0
  7. package/dist/calendar-resolver.d.ts.map +1 -0
  8. package/dist/calendar-resolver.js +132 -0
  9. package/dist/calendar-resolver.js.map +1 -0
  10. package/dist/calendar.d.ts +0 -19
  11. package/dist/calendar.d.ts.map +1 -1
  12. package/dist/calendar.js +4 -44
  13. package/dist/calendar.js.map +1 -1
  14. package/dist/canvas-width.d.ts +23 -0
  15. package/dist/canvas-width.d.ts.map +1 -0
  16. package/dist/canvas-width.js +26 -0
  17. package/dist/canvas-width.js.map +1 -0
  18. package/dist/capacity.d.ts +28 -0
  19. package/dist/capacity.d.ts.map +1 -1
  20. package/dist/capacity.js +64 -29
  21. package/dist/capacity.js.map +1 -1
  22. package/dist/chart-translation.d.ts +22 -0
  23. package/dist/chart-translation.d.ts.map +1 -0
  24. package/dist/chart-translation.js +83 -0
  25. package/dist/chart-translation.js.map +1 -0
  26. package/dist/container-header-geometry.d.ts +64 -0
  27. package/dist/container-header-geometry.d.ts.map +1 -0
  28. package/dist/container-header-geometry.js +89 -0
  29. package/dist/container-header-geometry.js.map +1 -0
  30. package/dist/dsl-utils.d.ts +3 -4
  31. package/dist/dsl-utils.d.ts.map +1 -1
  32. package/dist/dsl-utils.js +8 -25
  33. package/dist/dsl-utils.js.map +1 -1
  34. package/dist/edge-routing.d.ts +69 -78
  35. package/dist/edge-routing.d.ts.map +1 -1
  36. package/dist/edge-routing.js +271 -401
  37. package/dist/edge-routing.js.map +1 -1
  38. package/dist/frame-tab-geometry.d.ts +24 -14
  39. package/dist/frame-tab-geometry.d.ts.map +1 -1
  40. package/dist/frame-tab-geometry.js +69 -23
  41. package/dist/frame-tab-geometry.js.map +1 -1
  42. package/dist/header-card-geometry.d.ts +12 -0
  43. package/dist/header-card-geometry.d.ts.map +1 -1
  44. package/dist/header-card-geometry.js +14 -2
  45. package/dist/header-card-geometry.js.map +1 -1
  46. package/dist/header-logo.d.ts +28 -0
  47. package/dist/header-logo.d.ts.map +1 -0
  48. package/dist/header-logo.js +51 -0
  49. package/dist/header-logo.js.map +1 -0
  50. package/dist/i18n.d.ts +11 -0
  51. package/dist/i18n.d.ts.map +1 -1
  52. package/dist/i18n.js +11 -1
  53. package/dist/i18n.js.map +1 -1
  54. package/dist/index.d.ts +20 -8
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +17 -7
  57. package/dist/index.js.map +1 -1
  58. package/dist/inline-date-pin-geometry.d.ts +19 -11
  59. package/dist/inline-date-pin-geometry.d.ts.map +1 -1
  60. package/dist/inline-date-pin-geometry.js +45 -46
  61. package/dist/inline-date-pin-geometry.js.map +1 -1
  62. package/dist/item-bar-geometry.d.ts +192 -4
  63. package/dist/item-bar-geometry.d.ts.map +1 -1
  64. package/dist/item-bar-geometry.js +258 -5
  65. package/dist/item-bar-geometry.js.map +1 -1
  66. package/dist/item-port-geometry.d.ts +13 -0
  67. package/dist/item-port-geometry.d.ts.map +1 -0
  68. package/dist/item-port-geometry.js +63 -0
  69. package/dist/item-port-geometry.js.map +1 -0
  70. package/dist/layout-context.d.ts +115 -51
  71. package/dist/layout-context.d.ts.map +1 -1
  72. package/dist/layout-context.js +96 -5
  73. package/dist/layout-context.js.map +1 -1
  74. package/dist/layout-insights.d.ts.map +1 -1
  75. package/dist/layout-insights.js +73 -1
  76. package/dist/layout-insights.js.map +1 -1
  77. package/dist/layout.d.ts +35 -0
  78. package/dist/layout.d.ts.map +1 -1
  79. package/dist/layout.js +18 -1315
  80. package/dist/layout.js.map +1 -1
  81. package/dist/nodes/anchor-node.d.ts.map +1 -1
  82. package/dist/nodes/anchor-node.js +11 -4
  83. package/dist/nodes/anchor-node.js.map +1 -1
  84. package/dist/nodes/content-extent.d.ts +24 -0
  85. package/dist/nodes/content-extent.d.ts.map +1 -0
  86. package/dist/nodes/content-extent.js +100 -0
  87. package/dist/nodes/content-extent.js.map +1 -0
  88. package/dist/nodes/dependency-edges.d.ts +6 -0
  89. package/dist/nodes/dependency-edges.d.ts.map +1 -0
  90. package/dist/nodes/dependency-edges.js +148 -0
  91. package/dist/nodes/dependency-edges.js.map +1 -0
  92. package/dist/nodes/footnote-node.d.ts +24 -3
  93. package/dist/nodes/footnote-node.d.ts.map +1 -1
  94. package/dist/nodes/footnote-node.js +129 -25
  95. package/dist/nodes/footnote-node.js.map +1 -1
  96. package/dist/nodes/group-node.d.ts +10 -21
  97. package/dist/nodes/group-node.d.ts.map +1 -1
  98. package/dist/nodes/group-node.js +79 -154
  99. package/dist/nodes/group-node.js.map +1 -1
  100. package/dist/nodes/header-node.d.ts +56 -0
  101. package/dist/nodes/header-node.d.ts.map +1 -0
  102. package/dist/nodes/header-node.js +163 -0
  103. package/dist/nodes/header-node.js.map +1 -0
  104. package/dist/nodes/include-node.d.ts +22 -12
  105. package/dist/nodes/include-node.d.ts.map +1 -1
  106. package/dist/nodes/include-node.js +95 -62
  107. package/dist/nodes/include-node.js.map +1 -1
  108. package/dist/nodes/item-measure.d.ts +135 -0
  109. package/dist/nodes/item-measure.d.ts.map +1 -0
  110. package/dist/nodes/item-measure.js +514 -0
  111. package/dist/nodes/item-measure.js.map +1 -0
  112. package/dist/nodes/item-node.d.ts +162 -9
  113. package/dist/nodes/item-node.d.ts.map +1 -1
  114. package/dist/nodes/item-node.js +256 -69
  115. package/dist/nodes/item-node.js.map +1 -1
  116. package/dist/nodes/marker-band.d.ts +118 -0
  117. package/dist/nodes/marker-band.d.ts.map +1 -0
  118. package/dist/nodes/marker-band.js +303 -0
  119. package/dist/nodes/marker-band.js.map +1 -0
  120. package/dist/nodes/marker-geometry.js +1 -1
  121. package/dist/nodes/marker-geometry.js.map +1 -1
  122. package/dist/nodes/milestone-node.d.ts +112 -15
  123. package/dist/nodes/milestone-node.d.ts.map +1 -1
  124. package/dist/nodes/milestone-node.js +246 -95
  125. package/dist/nodes/milestone-node.js.map +1 -1
  126. package/dist/nodes/nowline-node.d.ts +8 -0
  127. package/dist/nodes/nowline-node.d.ts.map +1 -0
  128. package/dist/nodes/nowline-node.js +74 -0
  129. package/dist/nodes/nowline-node.js.map +1 -0
  130. package/dist/nodes/parallel-node.d.ts +7 -12
  131. package/dist/nodes/parallel-node.d.ts.map +1 -1
  132. package/dist/nodes/parallel-node.js +66 -32
  133. package/dist/nodes/parallel-node.js.map +1 -1
  134. package/dist/nodes/region-markers.d.ts +41 -0
  135. package/dist/nodes/region-markers.d.ts.map +1 -0
  136. package/dist/nodes/region-markers.js +130 -0
  137. package/dist/nodes/region-markers.js.map +1 -0
  138. package/dist/nodes/roadmap-node.d.ts +9 -72
  139. package/dist/nodes/roadmap-node.d.ts.map +1 -1
  140. package/dist/nodes/roadmap-node.js +38 -788
  141. package/dist/nodes/roadmap-node.js.map +1 -1
  142. package/dist/nodes/row-track.d.ts +33 -0
  143. package/dist/nodes/row-track.d.ts.map +1 -0
  144. package/dist/nodes/row-track.js +170 -0
  145. package/dist/nodes/row-track.js.map +1 -0
  146. package/dist/nodes/sequence-item.d.ts +25 -0
  147. package/dist/nodes/sequence-item.d.ts.map +1 -0
  148. package/dist/nodes/sequence-item.js +396 -0
  149. package/dist/nodes/sequence-item.js.map +1 -0
  150. package/dist/nodes/sequence-one.d.ts +5 -0
  151. package/dist/nodes/sequence-one.d.ts.map +1 -0
  152. package/dist/nodes/sequence-one.js +26 -0
  153. package/dist/nodes/sequence-one.js.map +1 -0
  154. package/dist/nodes/swimlane-node.d.ts +5 -17
  155. package/dist/nodes/swimlane-node.d.ts.map +1 -1
  156. package/dist/nodes/swimlane-node.js +62 -147
  157. package/dist/nodes/swimlane-node.js.map +1 -1
  158. package/dist/nodes/wave-node.d.ts +52 -0
  159. package/dist/nodes/wave-node.d.ts.map +1 -0
  160. package/dist/nodes/wave-node.js +483 -0
  161. package/dist/nodes/wave-node.js.map +1 -0
  162. package/dist/non-working-display.d.ts +14 -0
  163. package/dist/non-working-display.d.ts.map +1 -0
  164. package/dist/non-working-display.js +28 -0
  165. package/dist/non-working-display.js.map +1 -0
  166. package/dist/phases/date-window.d.ts +48 -0
  167. package/dist/phases/date-window.d.ts.map +1 -0
  168. package/dist/phases/date-window.js +130 -0
  169. package/dist/phases/date-window.js.map +1 -0
  170. package/dist/phases/finalize.d.ts +198 -0
  171. package/dist/phases/finalize.d.ts.map +1 -0
  172. package/dist/phases/finalize.js +1058 -0
  173. package/dist/phases/finalize.js.map +1 -0
  174. package/dist/phases/measure.d.ts +77 -0
  175. package/dist/phases/measure.d.ts.map +1 -0
  176. package/dist/phases/measure.js +222 -0
  177. package/dist/phases/measure.js.map +1 -0
  178. package/dist/phases/place.d.ts +28 -0
  179. package/dist/phases/place.d.ts.map +1 -0
  180. package/dist/phases/place.js +225 -0
  181. package/dist/phases/place.js.map +1 -0
  182. package/dist/renderable.d.ts.map +1 -1
  183. package/dist/renderable.js +23 -3
  184. package/dist/renderable.js.map +1 -1
  185. package/dist/resolve-today.d.ts +11 -1
  186. package/dist/resolve-today.d.ts.map +1 -1
  187. package/dist/resolve-today.js +26 -12
  188. package/dist/resolve-today.js.map +1 -1
  189. package/dist/row-packer.d.ts +42 -16
  190. package/dist/row-packer.d.ts.map +1 -1
  191. package/dist/row-packer.js +51 -78
  192. package/dist/row-packer.js.map +1 -1
  193. package/dist/schedule.d.ts +58 -1
  194. package/dist/schedule.d.ts.map +1 -1
  195. package/dist/schedule.js +280 -106
  196. package/dist/schedule.js.map +1 -1
  197. package/dist/start-rules.d.ts +27 -0
  198. package/dist/start-rules.d.ts.map +1 -0
  199. package/dist/start-rules.js +91 -0
  200. package/dist/start-rules.js.map +1 -0
  201. package/dist/start-terms.d.ts +23 -0
  202. package/dist/start-terms.d.ts.map +1 -0
  203. package/dist/start-terms.js +27 -0
  204. package/dist/start-terms.js.map +1 -0
  205. package/dist/status-dot.d.ts +46 -0
  206. package/dist/status-dot.d.ts.map +1 -0
  207. package/dist/status-dot.js +78 -0
  208. package/dist/status-dot.js.map +1 -0
  209. package/dist/style-resolution.d.ts.map +1 -1
  210. package/dist/style-resolution.js +23 -43
  211. package/dist/style-resolution.js.map +1 -1
  212. package/dist/text-measure.d.ts +28 -0
  213. package/dist/text-measure.d.ts.map +1 -0
  214. package/dist/text-measure.js +70 -0
  215. package/dist/text-measure.js.map +1 -0
  216. package/dist/themes/contrast.d.ts +4 -0
  217. package/dist/themes/contrast.d.ts.map +1 -0
  218. package/dist/themes/contrast.js +32 -0
  219. package/dist/themes/contrast.js.map +1 -0
  220. package/dist/themes/dark.d.ts.map +1 -1
  221. package/dist/themes/dark.js +28 -1
  222. package/dist/themes/dark.js.map +1 -1
  223. package/dist/themes/grayscale.d.ts.map +1 -1
  224. package/dist/themes/grayscale.js +28 -1
  225. package/dist/themes/grayscale.js.map +1 -1
  226. package/dist/themes/index.d.ts +4 -11
  227. package/dist/themes/index.d.ts.map +1 -1
  228. package/dist/themes/index.js +6 -4
  229. package/dist/themes/index.js.map +1 -1
  230. package/dist/themes/light.d.ts.map +1 -1
  231. package/dist/themes/light.js +28 -1
  232. package/dist/themes/light.js.map +1 -1
  233. package/dist/themes/shape.d.ts +31 -0
  234. package/dist/themes/shape.d.ts.map +1 -1
  235. package/dist/themes/shared.d.ts +44 -50
  236. package/dist/themes/shared.d.ts.map +1 -1
  237. package/dist/themes/shared.js +79 -83
  238. package/dist/themes/shared.js.map +1 -1
  239. package/dist/time-scale.d.ts +42 -6
  240. package/dist/time-scale.d.ts.map +1 -1
  241. package/dist/time-scale.js +109 -17
  242. package/dist/time-scale.js.map +1 -1
  243. package/dist/types.d.ts +528 -11
  244. package/dist/types.d.ts.map +1 -1
  245. package/dist/view-preset.d.ts +61 -6
  246. package/dist/view-preset.d.ts.map +1 -1
  247. package/dist/view-preset.js +439 -24
  248. package/dist/view-preset.js.map +1 -1
  249. package/dist/wave-barrier.d.ts +107 -0
  250. package/dist/wave-barrier.d.ts.map +1 -0
  251. package/dist/wave-barrier.js +174 -0
  252. package/dist/wave-barrier.js.map +1 -0
  253. package/dist/wave-hatch.d.ts +4 -0
  254. package/dist/wave-hatch.d.ts.map +1 -0
  255. package/dist/wave-hatch.js +21 -0
  256. package/dist/wave-hatch.js.map +1 -0
  257. package/dist/wave-layout.d.ts +99 -0
  258. package/dist/wave-layout.d.ts.map +1 -0
  259. package/dist/wave-layout.js +130 -0
  260. package/dist/wave-layout.js.map +1 -0
  261. package/dist/working-calendar.d.ts +128 -4
  262. package/dist/working-calendar.d.ts.map +1 -1
  263. package/dist/working-calendar.js +725 -51
  264. package/dist/working-calendar.js.map +1 -1
  265. package/dist/working-span.d.ts +11 -0
  266. package/dist/working-span.d.ts.map +1 -0
  267. package/dist/working-span.js +18 -0
  268. package/dist/working-span.js.map +1 -0
  269. package/package.json +7 -7
  270. package/src/axis-columns.ts +140 -0
  271. package/src/calendar-resolver.ts +161 -0
  272. package/src/calendar.ts +4 -45
  273. package/src/canvas-width.ts +36 -0
  274. package/src/capacity.ts +71 -30
  275. package/src/chart-translation.ts +88 -0
  276. package/src/container-header-geometry.ts +116 -0
  277. package/src/dsl-utils.ts +8 -26
  278. package/src/edge-routing.ts +347 -491
  279. package/src/frame-tab-geometry.ts +78 -25
  280. package/src/header-card-geometry.ts +17 -2
  281. package/src/header-logo.ts +67 -0
  282. package/src/i18n.ts +22 -1
  283. package/src/index.ts +97 -12
  284. package/src/inline-date-pin-geometry.ts +55 -58
  285. package/src/item-bar-geometry.ts +341 -5
  286. package/src/item-port-geometry.ts +69 -0
  287. package/src/layout-context.ts +210 -72
  288. package/src/layout-insights.ts +109 -2
  289. package/src/layout.ts +57 -1530
  290. package/src/nodes/anchor-node.ts +11 -4
  291. package/src/nodes/content-extent.ts +107 -0
  292. package/src/nodes/dependency-edges.ts +171 -0
  293. package/src/nodes/footnote-node.ts +171 -31
  294. package/src/nodes/group-node.ts +92 -215
  295. package/src/nodes/header-node.ts +255 -0
  296. package/src/nodes/include-node.ts +124 -110
  297. package/src/nodes/item-measure.ts +723 -0
  298. package/src/nodes/item-node.ts +358 -80
  299. package/src/nodes/marker-band.ts +406 -0
  300. package/src/nodes/marker-geometry.ts +1 -1
  301. package/src/nodes/milestone-node.ts +321 -136
  302. package/src/nodes/nowline-node.ts +87 -0
  303. package/src/nodes/parallel-node.ts +69 -39
  304. package/src/nodes/region-markers.ts +194 -0
  305. package/src/nodes/roadmap-node.ts +46 -950
  306. package/src/nodes/row-track.ts +217 -0
  307. package/src/nodes/sequence-item.ts +433 -0
  308. package/src/nodes/sequence-one.ts +40 -0
  309. package/src/nodes/swimlane-node.ts +66 -206
  310. package/src/nodes/wave-node.ts +609 -0
  311. package/src/non-working-display.ts +32 -0
  312. package/src/phases/date-window.ts +191 -0
  313. package/src/phases/finalize.ts +1303 -0
  314. package/src/phases/measure.ts +329 -0
  315. package/src/phases/place.ts +318 -0
  316. package/src/renderable.ts +23 -3
  317. package/src/resolve-today.ts +28 -25
  318. package/src/row-packer.ts +85 -84
  319. package/src/schedule.ts +362 -114
  320. package/src/start-rules.ts +113 -0
  321. package/src/start-terms.ts +38 -0
  322. package/src/status-dot.ts +81 -0
  323. package/src/style-resolution.ts +27 -57
  324. package/src/text-measure.ts +71 -0
  325. package/src/themes/contrast.ts +34 -0
  326. package/src/themes/dark.ts +28 -1
  327. package/src/themes/grayscale.ts +28 -1
  328. package/src/themes/index.ts +10 -7
  329. package/src/themes/light.ts +28 -1
  330. package/src/themes/shape.ts +38 -0
  331. package/src/themes/shared.ts +85 -93
  332. package/src/time-scale.ts +117 -19
  333. package/src/types.ts +529 -20
  334. package/src/view-preset.ts +520 -27
  335. package/src/wave-barrier.ts +242 -0
  336. package/src/wave-hatch.ts +25 -0
  337. package/src/wave-layout.ts +203 -0
  338. package/src/working-calendar.ts +875 -57
  339. package/src/working-span.ts +19 -0
package/dist/layout.js CHANGED
@@ -1,1319 +1,22 @@
1
- import { isGroupBlock, isItemDeclaration, isParallelBlock } from '@nowline/core';
2
- import { addDays, daysBetween, deriveItemDurationDays, deriveTotalEffortDays, resolveDuration, } from './calendar.js';
3
- import { estimateCapacitySuffixWidth, formatCapacityNumber, parseCapacityValue, resolveCapacityIcon, } from './capacity.js';
4
- import { parseDate, propValue, propValues } from './dsl-utils.js';
5
- import { ChannelGrid, collectRoutingObstacles, routeChannelEdges, } from './edge-routing.js';
6
- import { HEADER_AUTHOR_FONT_SIZE_PX, HEADER_AUTHOR_LINE_HEIGHT_PX, HEADER_CARD_PADDING_BOTTOM, HEADER_CARD_PADDING_TOP, HEADER_CARD_PADDING_X, HEADER_TITLE_FONT_SIZE_PX, HEADER_TITLE_LINE_HEIGHT_PX, HEADER_TITLE_TO_AUTHOR_GAP_PX, } from './header-card-geometry.js';
7
- import { localeStrings } from './i18n.js';
8
- import { computeItemInlineDatePins, pickInlineDate } from './inline-date-pin-geometry.js';
9
- import { ITEM_CAPTION_INSET_X_PX, ITEM_CAPTION_META_BASELINE_OFFSET_PX, ITEM_CAPTION_SPILL_GAP_PX, ITEM_CAPTION_TITLE_FONT_SIZE_PX, ITEM_DECORATION_SPILL_GAP_PX, ITEM_FOOTNOTE_INDICATOR_STEP_PX, ITEM_LINK_ICON_TILE_SIZE_PX, ITEM_STATUS_DOT_RADIUS_PX, LABEL_CHIP_GAP_ABOVE_PROGRESS_STRIP_PX, LABEL_CHIP_GAP_BETWEEN_PX, LABEL_CHIP_HEIGHT_PX, LABEL_CHIP_ROW_STEP_PX, MIN_BAR_WIDTH_FOR_DOT_PX, MIN_BAR_WIDTH_FOR_FOOTNOTE_PX, MIN_BAR_WIDTH_FOR_LINK_AND_DOT_PX, packSpillChips, } from './item-bar-geometry.js';
10
- import { newCursor } from './layout-context.js';
11
- import { GroupNode } from './nodes/group-node.js';
12
- import { ItemNode } from './nodes/item-node.js';
13
- import { ParallelNode } from './nodes/parallel-node.js';
1
+ // layoutRoadmap — the package's layout entry point: builds (or reuses) the
2
+ // day schedule and hands the roadmap to `RoadmapNode`, which runs the four
3
+ // layout phases (specs/layout-phases.md §3.1).
4
+ import { buildWavePlan } from '@nowline/core';
14
5
  import { RoadmapNode } from './nodes/roadmap-node.js';
15
- import { SwimlaneNode } from './nodes/swimlane-node.js';
16
- import { resolveLabelChipStyle, resolveStyle } from './style-resolution.js';
17
- import { GUTTER_PX, HEADER_BESIDE_MAX_WIDTH_PX, HEADER_BESIDE_MIN_WIDTH_PX, ITEM_INSET_PX, MIN_ITEM_WIDTH, NOW_PILL_LABEL_FONT_SIZE_PX, NOW_PILL_LABEL_INSET_X_PX, NOW_PILL_WIDTH_PX, PADDING_PX, PROGRESS_STRIP_HEIGHT_PX, } from './themes/shared.js';
18
- import { daysPerUnit } from './working-calendar.js';
19
- function statusFromProp(raw) {
20
- switch (raw) {
21
- case 'done':
22
- case 'completed':
23
- return 'done';
24
- case 'in-progress':
25
- case 'active':
26
- return 'in-progress';
27
- case 'at-risk':
28
- case 'blocked':
29
- case 'planned':
30
- return raw;
31
- case undefined:
32
- return 'planned';
33
- default:
34
- return 'neutral';
35
- }
36
- }
37
- function parseProgressFraction(raw) {
38
- if (!raw)
39
- return 0;
40
- const m = /^(\d{1,3})%$/.exec(raw);
41
- if (!m)
42
- return 0;
43
- return Math.max(0, Math.min(100, parseInt(m[1], 10))) / 100;
44
- }
45
- // Resolve a `size:NAME` value to its size declaration's effort literal, used
46
- // by displays that want the literal duration string (not days). Returns the
47
- // original string for raw literals (`1w`, `3d`) and undefined for missing
48
- // values. m5 will adjust callers to apply capacity-aware derivation when the
49
- // caller wants the calendar duration; this helper continues to expose the
50
- // raw effort/duration literal for chips, captions, and tooltips.
51
- function resolveDurationLiteral(raw, ctx) {
52
- if (!raw)
53
- return undefined;
54
- if (/^\d+(?:\.\d+)?[dwmqy]$/.test(raw) || /^\d+%$/.test(raw))
55
- return raw;
56
- return ctx.sizes.get(raw)?.effortLiteral ?? raw;
57
- }
58
- // Resolve a person/team id to its declared title when present (id otherwise).
59
- function resolveActorDisplay(raw, ctx) {
60
- if (!raw)
61
- return undefined;
62
- return ctx.teams.get(raw)?.title ?? ctx.persons.get(raw)?.title ?? raw;
63
- }
64
- function parseLinkIcon(link) {
65
- if (!link)
66
- return { icon: 'none' };
67
- const lower = link.toLowerCase();
68
- if (lower.includes('linear.app'))
69
- return { icon: 'linear', href: link };
70
- if (lower.includes('github.com'))
71
- return { icon: 'github', href: link };
72
- if (lower.includes('atlassian.net') || lower.includes('jira.')) {
73
- return { icon: 'jira', href: link };
74
- }
75
- return { icon: 'generic', href: link };
76
- }
77
- // Bake a named/hex color from a label's `bg:` or `fg:` into the chip style.
78
- function buildLabelChip(label, ctx, x, y, maxWidth) {
79
- const style = resolveLabelChipStyle(label, ctx);
80
- // Prefer the short name (id) when it exists — chips inside an item bar
81
- // are tight; the long title risks overflowing.
82
- const text = label.name ?? label.title ?? '';
83
- const padKey = style.padding === 'none' ? 'xs' : style.padding;
84
- const pad = PADDING_PX[padKey];
85
- let width = Math.max(20, Math.round(text.length * 5.5 + pad * 2));
86
- if (maxWidth !== undefined)
87
- width = Math.min(width, maxWidth);
88
- return {
89
- text,
90
- style,
91
- box: { x, y, width, height: LABEL_CHIP_HEIGHT_PX },
92
- };
93
- }
94
- // Sequence a set of nodes into a single horizontal track. `parallelInside`
95
- // indicates the caller is inside a ParallelBlock and each child occupies a
96
- // fresh sub-track (caller passes a new cursor per call).
97
- function sequenceItem(node, cursor, ctx, ownerOverride) {
98
- const props = node.properties;
99
- const style = resolveStyle('item', props, ctx.styleCtx);
100
- // Sizing precedence (specs/dsl.md § "Sizing precedence"):
101
- // 1. `duration:LITERAL` wins as the calendar duration — `size:NAME`
102
- // becomes a pure annotation (chip only).
103
- // 2. Otherwise, `size:NAME` derives `effort ÷ capacity` (default
104
- // capacity = 1).
105
- // The validator requires one of the two on every item.
106
- const sizeRef = propValue(props, 'size');
107
- const sizeResolved = sizeRef ? (ctx.sizes.get(sizeRef) ?? null) : null;
108
- const durationDays = deriveItemDurationDays(props, ctx.sizes, ctx.cal);
109
- // Total work in single-engineer days, used below to normalize a literal
110
- // `remaining:` value into a progress fraction. Stays per-engineer
111
- // regardless of the item's `capacity:` so a `remaining:1w` always means
112
- // "one engineer-week of work left".
113
- const totalEffortDays = deriveTotalEffortDays(props, ctx.sizes, ctx.cal);
114
- const afterRaw = propValues(props, 'after');
115
- const beforeRaw = propValues(props, 'before');
116
- const dateRaw = propValue(props, 'date');
117
- const remainingDays = resolveDuration(propValue(props, 'remaining'), ctx.sizes, ctx.cal);
118
- // Resolve start x: explicit date > after-chain > cursor position.
119
- // `after:` accepts both entity ids (looked up in entityRightEdges) and
120
- // inline ISO date literals (resolved through the time scale). The
121
- // validator enforces "at most one inline date per direction" so at most
122
- // one element will hit the date path per item.
123
- let startX = cursor.x;
124
- const explicitDate = parseDate(dateRaw);
125
- if (explicitDate) {
126
- const xd = ctx.scale.forwardWithinDomain(explicitDate);
127
- if (xd !== null)
128
- startX = xd;
129
- }
130
- else if (afterRaw.length > 0) {
131
- let maxEnd = cursor.x;
132
- for (const ref of afterRaw) {
133
- const inlineDate = parseDate(ref);
134
- if (inlineDate) {
135
- const xd = ctx.scale.forwardWithinDomain(inlineDate);
136
- if (xd !== null)
137
- maxEnd = Math.max(maxEnd, xd);
138
- continue;
139
- }
140
- const endX = ctx.entityRightEdges.get(ref);
141
- if (endX !== undefined)
142
- maxEnd = Math.max(maxEnd, endX);
143
- }
144
- startX = Math.max(cursor.x, maxEnd);
145
- }
146
- const naturalWidth = Math.max(MIN_ITEM_WIDTH, durationDays * ctx.timeline.pixelsPerDay);
147
- // Logical extent — what the item "owns" in time (used for chaining,
148
- // `after:` lookups, dependency-arrow attach points).
149
- const logicalLeft = startX;
150
- const logicalRight = startX + naturalWidth;
151
- const linkRaw = propValue(props, 'link');
152
- const linkInfo = parseLinkIcon(linkRaw);
153
- const hasLinkIcon = linkInfo.icon !== 'none';
154
- // Pre-compute the chip row geometry — every chip renders at its
155
- // NATURAL text-fit width on a single horizontal row, never
156
- // truncated. We only need the total row width here so we can
157
- // decide whether the row fits inside the bar; concrete chip
158
- // (x, y) placement comes after ItemNode resolves the visible
159
- // bar box below.
160
- //
161
- // Chips sit at the bar's bottom (just above the progress strip)
162
- // and the link icon (when present) sits in the bar's UPPER-LEFT
163
- // corner, so they no longer share a vertical band — chips have
164
- // the full caption-inset-bounded inner width regardless of
165
- // whether a link icon is rendered. The link-icon column's
166
- // horizontal cost is borne by the caption (title/meta) inset
167
- // instead, see `ItemNode`.
168
- const visualWidthPredict = Math.max(MIN_ITEM_WIDTH, naturalWidth - 2 * ITEM_INSET_PX);
169
- const labelIds = propValues(props, 'labels');
170
- const chipSamples = [];
171
- for (const labelId of labelIds) {
172
- const label = ctx.labels.get(labelId);
173
- if (!label)
174
- continue;
175
- const sample = buildLabelChip(label, ctx.styleCtx, 0, 0);
176
- chipSamples.push({ id: label, width: sample.box.width });
177
- }
178
- let chipRowWidth = 0;
179
- for (let i = 0; i < chipSamples.length; i += 1) {
180
- if (i > 0)
181
- chipRowWidth += LABEL_CHIP_GAP_BETWEEN_PX;
182
- chipRowWidth += chipSamples[i].width;
183
- }
184
- const chipInsideAvailWidth = Math.max(0, visualWidthPredict - 2 * ITEM_CAPTION_INSET_X_PX);
185
- const chipsOutside = chipSamples.length > 0 && chipRowWidth > chipInsideAvailWidth;
186
- // Handle `before:` — item must end by the earliest cap. Each cap is
187
- // either an entity id (looked up in entityLeftEdges) or an inline ISO
188
- // date literal (resolved through the time scale). The validator enforces
189
- // "at most one inline date per direction" so at most one element per
190
- // before-list will hit the date path.
191
- let hasOverflow = false;
192
- let overflowBox;
193
- let overflowAnchorId;
194
- if (beforeRaw.length > 0) {
195
- let earliestCapX;
196
- let earliestCapRef;
197
- for (const ref of beforeRaw) {
198
- const inlineDate = parseDate(ref);
199
- const capX = inlineDate
200
- ? (ctx.scale.forwardWithinDomain(inlineDate) ?? undefined)
201
- : ctx.entityLeftEdges.get(ref);
202
- if (capX === undefined)
203
- continue;
204
- if (earliestCapX === undefined || capX < earliestCapX) {
205
- earliestCapX = capX;
206
- earliestCapRef = ref;
207
- }
208
- }
209
- if (earliestCapX !== undefined && logicalRight > earliestCapX) {
210
- hasOverflow = true;
211
- overflowBox = {
212
- x: earliestCapX,
213
- y: cursor.y,
214
- width: logicalRight - earliestCapX,
215
- height: ctx.bandScale.bandwidth(),
216
- };
217
- overflowAnchorId = earliestCapRef;
218
- }
219
- }
220
- // Progress fraction
221
- const statusRaw = propValue(props, 'status');
222
- const status = statusFromProp(statusRaw);
223
- let progress = parseProgressFraction(statusRaw);
224
- if (progress === 0 && status === 'done')
225
- progress = 1;
226
- const remainingPctMatch = /^(\d{1,3})%$/.exec(propValue(props, 'remaining') ?? '');
227
- if (progress === 0 && status === 'in-progress' && remainingPctMatch) {
228
- const pct = Math.max(0, Math.min(100, parseInt(remainingPctMatch[1], 10))) / 100;
229
- progress = 1 - pct;
230
- }
231
- if (progress === 0 && status === 'in-progress' && remainingDays > 0 && totalEffortDays > 0) {
232
- // `remaining:` literal is single-engineer days; `totalEffortDays`
233
- // is also single-engineer days, so the ratio is unit-correct.
234
- // Clamp to [0, 1] — the renderer paints 100% remaining when the
235
- // author overshot, matching the spec's "warn-and-clamp" overflow
236
- // behavior. (Validation defers the warn to layout-time today; a
237
- // future diagnostics channel can surface it back to the user.)
238
- progress = Math.max(0, Math.min(1, 1 - remainingDays / totalEffortDays));
239
- }
240
- // Apply the status-tinted item background when the resolved bg is still
241
- // theme-default. Authors who set explicit `bg:` keep their override.
242
- // Per m2d handoff Resolution 3: layout owns this so the renderer stays
243
- // palette-dumb.
244
- const STATUS_TINT_LIGHT = {
245
- done: '#ecfdf5',
246
- 'in-progress': '#eff6ff',
247
- 'at-risk': '#fffbeb',
248
- blocked: '#fee2e2',
249
- planned: '#f8fafc',
250
- neutral: '#f8fafc',
251
- };
252
- const STATUS_TINT_DARK = {
253
- done: '#052e16',
254
- 'in-progress': '#172554',
255
- 'at-risk': '#422006',
256
- blocked: '#7f1d1d',
257
- planned: '#1e293b',
258
- neutral: '#1e293b',
259
- };
260
- const STATUS_TINT_GREY = {
261
- done: '#ebebeb',
262
- 'in-progress': '#e4e4e4',
263
- 'at-risk': '#eeeeee',
264
- blocked: '#dcdcdc',
265
- planned: '#f5f5f5',
266
- neutral: '#f5f5f5',
267
- };
268
- const STATUS_BORDER = {
269
- done: ctx.styleCtx.theme.status.done,
270
- 'in-progress': ctx.styleCtx.theme.status.inProgress,
271
- 'at-risk': ctx.styleCtx.theme.status.atRisk,
272
- blocked: ctx.styleCtx.theme.status.blocked,
273
- planned: ctx.styleCtx.theme.status.planned,
274
- neutral: ctx.styleCtx.theme.status.neutral,
275
- };
276
- const themeName = ctx.styleCtx.theme.name;
277
- const isDark = themeName === 'dark';
278
- const themeDefaultBg = isDark ? '#0f172a' : '#ffffff';
279
- const themeDefaultFg = themeName === 'grayscale' ? '#9e9e9e' : '#94a3b8';
280
- if (style.bg === themeDefaultBg) {
281
- style.bg =
282
- themeName === 'grayscale'
283
- ? STATUS_TINT_GREY[status]
284
- : isDark
285
- ? STATUS_TINT_DARK[status]
286
- : STATUS_TINT_LIGHT[status];
287
- }
288
- if (style.fg === themeDefaultFg) {
289
- style.fg = STATUS_BORDER[status];
290
- }
291
- // Pre-format the secondary line shown inside the item bar.
292
- //
293
- // Driver-only meta line (`rendering.md` § Item size chip): exactly one
294
- // leading token — the explicit non-empty `duration:LITERAL` when set,
295
- // otherwise the size chip when `size:` drives. Never both; bar width
296
- // already encodes derived calendar span for sized items.
297
- const explicitDurationLiteral = propValue(props, 'duration');
298
- const durationDrives = !!explicitDurationLiteral && /^\d+(?:\.\d+)?[dwmqy]$/.test(explicitDurationLiteral);
299
- const sizeChipText = sizeResolved ? (sizeResolved.title ?? sizeResolved.name) : '';
300
- const driverToken = durationDrives
301
- ? explicitDurationLiteral
302
- : sizeChipText || undefined;
303
- const remainingRaw = propValue(props, 'remaining');
304
- const remainingLiteral = resolveDurationLiteral(remainingRaw, ctx);
305
- const ownerDisplay = resolveActorDisplay(ownerOverride ?? propValue(props, 'owner'), ctx);
306
- const metaHead = () => [driverToken, ownerDisplay].filter(Boolean).join(' ');
307
- let metaText;
308
- if (status === 'in-progress' && remainingLiteral) {
309
- const head = metaHead();
310
- metaText = head
311
- ? `${head} — ${remainingLiteral} remaining`
312
- : `${remainingLiteral} remaining`;
313
- }
314
- else if (status === 'in-progress' && progress > 0 && progress < 1) {
315
- const pct = Math.round((1 - progress) * 100);
316
- const head = metaHead();
317
- metaText = head ? `${head} — ${pct}% remaining` : `${pct}% remaining`;
318
- }
319
- else if (ownerDisplay || driverToken) {
320
- metaText = metaHead() || undefined;
321
- }
322
- // Capacity suffix — appended after metaText at render time. Layout's
323
- // job here is to (a) parse the value out of `capacity:`, (b) format
324
- // the display number, (c) resolve `capacity-icon` to either a
325
- // built-in name or a literal string the renderer can paint directly,
326
- // and (d) feed the suffix's estimated width into ItemNode so spill
327
- // detection accounts for `2w 5×` rather than just `2w`. The suffix
328
- // disappears entirely when capacity is missing or non-positive.
329
- const capacityRaw = propValue(props, 'capacity');
330
- const capacityValue = parseCapacityValue(capacityRaw);
331
- let capacity = null;
332
- let capacityTrailingWidth = 0;
333
- if (capacityValue !== null) {
334
- const capacityText = formatCapacityNumber(capacityValue);
335
- const capacityIcon = resolveCapacityIcon(style.capacityIcon, ctx.symbols);
336
- capacity = { value: capacityValue, text: capacityText, icon: capacityIcon };
337
- const META_FONT_SIZE_PX_LOCAL = 11;
338
- // Add a small leading separator (a single space's worth) only when
339
- // the suffix sits next to existing meta text, so `m 5×` has air
340
- // between the driver token and the count. Standalone suffix needs no
341
- // leading separator.
342
- const separatorWidth = metaText ? estimateTextWidth(' ', META_FONT_SIZE_PX_LOCAL) : 0;
343
- capacityTrailingWidth =
344
- separatorWidth +
345
- estimateCapacitySuffixWidth(capacityText, capacityIcon, META_FONT_SIZE_PX_LOCAL);
346
- }
347
- // Visual bar + caption-spill decision delegated to ItemNode. Logical
348
- // extent (used by chaining and `after:` lookups) stays on
349
- // logicalLeft/logicalRight; ItemNode computes the inset visual box and
350
- // whether the title+meta line overflows the bar's inner padded width.
351
- const titleStr = node.title ?? node.name ?? '';
352
- const placed = new ItemNode({
353
- id: node.name ?? '',
354
- title: titleStr,
355
- logicalLeftX: logicalLeft,
356
- logicalRightX: logicalRight,
357
- metaText,
358
- metaTrailingWidth: capacityTrailingWidth,
359
- hasLinkIcon,
360
- }).place({ x: logicalLeft, y: cursor.y }, { time: ctx.scale, bands: ctx.bandScale, style });
361
- const itemBox = placed.box;
362
- const bandwidth = ctx.bandScale.bandwidth();
363
- // Narrow-bar decoration spill — when a bar is too narrow to host
364
- // the dot, link icon, or footnote with its full inset, those
365
- // glyphs render in the same spill column as the (already-
366
- // spilling) caption text, in reading order
367
- // `[bar][dot][icon][title][footnote#…][meta]`. Each decoration's
368
- // threshold is independent (a 20-px-wide bar can host the dot
369
- // but not the icon, etc.); see the `MIN_BAR_WIDTH_FOR_*`
370
- // constants in `item-bar-geometry`.
371
- //
372
- // Forcing `textSpills` when `iconSpills` keeps the icon and
373
- // title visually adjacent — otherwise a spilled icon would
374
- // float at `bar.right + 6` while the title stayed inside the
375
- // bar, breaking the icon→title affordance.
376
- const dotSpills = itemBox.width < MIN_BAR_WIDTH_FOR_DOT_PX;
377
- const iconSpills = hasLinkIcon && itemBox.width < MIN_BAR_WIDTH_FOR_LINK_AND_DOT_PX;
378
- const footnoteSpillsForNarrow = itemBox.width < MIN_BAR_WIDTH_FOR_FOOTNOTE_PX;
379
- const textSpills = placed.textSpills || iconSpills;
380
- // Label chips lay out left → right at natural text width.
381
- //
382
- // INSIDE the bar (chipsOutside === false): single row,
383
- // left-aligned at the caption inset, anchored just above the
384
- // bottom progress strip.
385
- //
386
- // OUTSIDE the bar (chipsOutside === true): the whole chip set
387
- // moves to the spill column at `bar.right + 6`. Within the
388
- // column, chips pack into rows capped at the bar's visual
389
- // width — see `packSpillChips`. Row 0 sits at the same y the
390
- // single-row would have used; subsequent rows stack DOWNWARD by
391
- // one `LABEL_CHIP_ROW_STEP_PX`.
392
- //
393
- // When chips spill, the BAR ITSELF GROWS DOWNWARD so the chip
394
- // column reads as enclosed by the bar — the painted footprint
395
- // of the bar is `bandwidth + chipBarExtra` and the bottom
396
- // progress strip moves with the new bottom edge. Chip Y is
397
- // anchored to the ORIGINAL bandwidth (relative to the bar's
398
- // top), not to the grown box.height, so row 0 stays where a
399
- // single-row chip would naturally render and rows 1..N grow
400
- // downward into the new bar area.
401
- //
402
- // When the caption ALSO spills (`textSpills && chipsOutside`),
403
- // row 0's y drops below the meta baseline so the spilled stack
404
- // reads `title → meta → chip-row-0 → chip-row-1 → ...` at a
405
- // single column inside the (now-taller) bar.
406
- let chipPack = null;
407
- if (chipsOutside) {
408
- chipPack = packSpillChips(chipSamples, itemBox.width);
409
- }
410
- const chipRowCount = chipPack ? chipPack.rows.length : chipSamples.length > 0 ? 1 : 0;
411
- // Capacity suffix renders on the same line as metaText. Treat the meta
412
- // line as present whenever EITHER metaText OR a capacity suffix will
413
- // paint, so chip-row pitch reserves the right amount of vertical space.
414
- const hasMeta = metaText !== undefined || capacity !== null;
415
- const chipBarExtra = computeChipBarExtra(chipsOutside, textSpills, chipRowCount, bandwidth, hasMeta);
416
- if (chipBarExtra > 0) {
417
- itemBox.height = bandwidth + chipBarExtra;
418
- }
419
- const labelChips = [];
420
- const baseChipY = itemBox.y +
421
- bandwidth -
422
- PROGRESS_STRIP_HEIGHT_PX -
423
- LABEL_CHIP_HEIGHT_PX -
424
- LABEL_CHIP_GAP_ABOVE_PROGRESS_STRIP_PX;
425
- const captionStackChipY = itemBox.y + ITEM_CAPTION_META_BASELINE_OFFSET_PX + LABEL_CHIP_GAP_ABOVE_PROGRESS_STRIP_PX;
426
- // Inside-bar chips with meta need to clear the meta baseline —
427
- // the natural `baseChipY` (anchored to bar bottom) sits above
428
- // the meta line at typical bandwidths, so the chip rect would
429
- // overlap the meta text vertically. Use whichever Y is lower.
430
- // Outside-bar chips already reuse `captionStackChipY` when the
431
- // caption ALSO spills; with caption inside we don't need to
432
- // shift them since they're horizontally separated from the meta.
433
- const stackBelowMeta = (chipsOutside && textSpills) || (!chipsOutside && hasMeta && chipSamples.length > 0);
434
- const chipRow0Y = stackBelowMeta ? Math.max(baseChipY, captionStackChipY) : baseChipY;
435
- const chipStartX = chipsOutside
436
- ? itemBox.x + itemBox.width + ITEM_CAPTION_SPILL_GAP_PX
437
- : itemBox.x + ITEM_CAPTION_INSET_X_PX;
438
- let chipsRightX = chipStartX;
439
- if (chipPack) {
440
- for (let r = 0; r < chipPack.rows.length; r += 1) {
441
- const rowY = chipRow0Y + r * LABEL_CHIP_ROW_STEP_PX;
442
- let rowCursorX = chipStartX;
443
- for (const sample of chipPack.rows[r]) {
444
- const chip = buildLabelChip(sample.id, ctx.styleCtx, rowCursorX, rowY);
445
- labelChips.push(chip);
446
- rowCursorX += chip.box.width + LABEL_CHIP_GAP_BETWEEN_PX;
447
- }
448
- const rowRight = rowCursorX - LABEL_CHIP_GAP_BETWEEN_PX;
449
- if (rowRight > chipsRightX)
450
- chipsRightX = rowRight;
451
- }
452
- }
453
- else {
454
- let rowCursorX = chipStartX;
455
- for (const sample of chipSamples) {
456
- const chip = buildLabelChip(sample.id, ctx.styleCtx, rowCursorX, chipRow0Y);
457
- labelChips.push(chip);
458
- rowCursorX += chip.box.width + LABEL_CHIP_GAP_BETWEEN_PX;
459
- }
460
- chipsRightX = chipSamples.length > 0 ? rowCursorX - LABEL_CHIP_GAP_BETWEEN_PX : chipStartX;
461
- }
462
- // Footnote superscript indicators. Per `specs/dsl.md`, footnotes
463
- // attach via the `on:` property on the footnote declaration only —
464
- // there is no forward `footnote:` property on the host entity. Walk
465
- // `footnoteHosts` (built from each footnote's `on:` list) and emit
466
- // a superscript for every footnote that names this item.
467
- const footnoteIndicatorSet = new Set();
468
- if (node.name) {
469
- for (const [fid, hosts] of ctx.footnoteHosts.entries()) {
470
- if (hosts.includes(node.name)) {
471
- const n = ctx.footnoteIndex.get(fid);
472
- if (n !== undefined)
473
- footnoteIndicatorSet.add(n);
474
- }
475
- }
476
- }
477
- const footnoteIndicators = [...footnoteIndicatorSet].sort((a, b) => a - b);
478
- const owner = ownerDisplay ?? ownerOverride ?? propValue(props, 'owner');
479
- const description = node.description?.text;
480
- // Footnote glyphs only need to spill when there's at least one
481
- // indicator AND the bar is too narrow to host them at the inset-
482
- // right anchor. Compute the final boolean here once we know the
483
- // indicator count.
484
- const footnoteSpills = footnoteIndicators.length > 0 && footnoteSpillsForNarrow;
485
- // Spill-column x positions for the decorations. The cluster
486
- // mirrors the in-bar reading order so users see the same visual
487
- // hierarchy whether everything fits inside or trails off to the
488
- // right:
489
- //
490
- // In-bar (default): [icon] [title] [¹²] [dot]
491
- // Spilled (narrow): [bar] [icon?] [title][¹²?] [dot?]
492
- //
493
- // The dot lives at the trailing edge in BOTH cases — pushing it
494
- // to the LEFT of the title (with the title trailing it) read as
495
- // the dot belonging to the next item, not this one. A missing
496
- // decoration just collapses out of the row; e.g. an item with
497
- // no link AND a too-narrow bar gives `[bar] [title] [dot]`.
498
- //
499
- // `decorationsRightX` is the furthest right edge any spilled
500
- // glyph reaches; the row-packer uses it (alongside spilled-chip
501
- // width) to reserve x-extent so the next chained item bumps to
502
- // a fresh row instead of landing under the spilled cluster.
503
- const SPILL_COLUMN_X0 = itemBox.x + itemBox.width + ITEM_CAPTION_SPILL_GAP_PX;
504
- let spillCursor = SPILL_COLUMN_X0;
505
- // Advance the cursor by `gap` IFF something has already been
506
- // placed in the column — keeps the cluster from leaving a
507
- // dangling gap past its final glyph (which would over-reserve
508
- // x-extent and shift downstream items).
509
- let needGap = false;
510
- let iconSpillX = null;
511
- if (iconSpills) {
512
- if (needGap)
513
- spillCursor += ITEM_DECORATION_SPILL_GAP_PX;
514
- iconSpillX = spillCursor;
515
- spillCursor = iconSpillX + ITEM_LINK_ICON_TILE_SIZE_PX;
516
- needGap = true;
517
- }
518
- let captionSpillWidth = 0;
519
- if (textSpills) {
520
- if (needGap)
521
- spillCursor += ITEM_DECORATION_SPILL_GAP_PX;
522
- const titleW = estimateTextWidth(titleStr, ITEM_CAPTION_TITLE_FONT_SIZE_PX);
523
- // Spill column width is the wider of the title and the *full* meta
524
- // line (text + capacity suffix). `capacityTrailingWidth` is 0 when
525
- // no capacity suffix is rendered, so this stays a no-op for items
526
- // without `capacity:`.
527
- const metaW = (metaText ? estimateTextWidth(metaText, 11) : 0) + capacityTrailingWidth;
528
- captionSpillWidth = Math.max(titleW, metaW);
529
- spillCursor += captionSpillWidth;
530
- needGap = true;
531
- }
532
- let footnoteSpillStartX = null;
533
- if (footnoteSpills) {
534
- if (needGap)
535
- spillCursor += ITEM_DECORATION_SPILL_GAP_PX;
536
- footnoteSpillStartX = spillCursor;
537
- spillCursor += footnoteIndicators.length * ITEM_FOOTNOTE_INDICATOR_STEP_PX;
538
- needGap = true;
539
- }
540
- let dotSpillCx = null;
541
- if (dotSpills) {
542
- if (needGap)
543
- spillCursor += ITEM_DECORATION_SPILL_GAP_PX;
544
- dotSpillCx = spillCursor + ITEM_STATUS_DOT_RADIUS_PX;
545
- spillCursor = dotSpillCx + ITEM_STATUS_DOT_RADIUS_PX;
546
- needGap = true;
547
- }
548
- const decorationsRightX = Math.max(itemBox.x + itemBox.width, spillCursor);
549
- const id = node.name;
550
- // Reference-target edges resolve `after:` / `before:` lookups, so only
551
- // EXPLICIT ids register here — an id-less item never becomes a
552
- // referenceable target. Entity edges live in LOGICAL space so chained
553
- // items / `after:` references sit on the column boundary, not on the
554
- // visually inset bar edge. The visible 12 px gutter between bars then
555
- // becomes a clean attach corridor.
556
- if (id) {
557
- ctx.entityLeftEdges.set(id, logicalLeft);
558
- ctx.entityRightEdges.set(id, logicalRight);
559
- }
560
- // Drawing / flow maps key on a registration handle EVERY item has: the
561
- // explicit id when present, else a synthetic, non-referenceable handle
562
- // (see `syntheticItemKey`). This lets a title-only item register its own
563
- // dependency-arrow target geometry and join flow-key dedup without
564
- // entering the human-referenceable namespace above.
565
- const drawKey = id ?? syntheticItemKey(node);
566
- ctx.entityMidpoints.set(drawKey, {
567
- x: (logicalLeft + logicalRight) / 2,
568
- y: itemBox.y + itemBox.height / 2,
569
- });
570
- // Visual edges — where dependency arrows actually attach. These sit
571
- // ITEM_INSET_PX inside the column boundaries so the arrows emerge from
572
- // the painted bar edge instead of the inter-column gutter. See
573
- // LayoutContext.entityVisualLeftX/RightX.
574
- ctx.entityVisualLeftX.set(drawKey, itemBox.x);
575
- ctx.entityVisualRightX.set(drawKey, itemBox.x + itemBox.width);
576
- // Dependency-arrow source point. Default = the bar's right edge at row
577
- // midpoint. When the caption spills past the bar's right edge
578
- // (`textSpills`), the spilled title / meta occupy the area immediately
579
- // right of the bar at row midline. Keep X on the bar's right edge so the
580
- // arrow visually leaves the bar's side, but drop Y to the vertical center
581
- // of the bottom progress strip so the arrow runs UNDERNEATH the spilled
582
- // text rather than through it. Mirrors the slack-arrow attach below.
583
- const arrowSource = textSpills
584
- ? {
585
- x: itemBox.x + itemBox.width,
586
- y: itemBox.y + itemBox.height - PROGRESS_STRIP_HEIGHT_PX / 2,
587
- }
588
- : {
589
- x: itemBox.x + itemBox.width,
590
- y: itemBox.y + itemBox.height / 2,
591
- };
592
- ctx.itemArrowSource.set(drawKey, arrowSource);
593
- ctx.itemFlowKey.set(drawKey, ctx.currentFlowKey);
594
- // Slack-arrow attach Y. Defaults to the bar's row midpoint; when the
595
- // caption spills past the bar's right edge, drop to the progress-strip's
596
- // vertical center so the arrow aligns with the bottom-edge progress bar
597
- // instead of running through the adjacent title/meta text. The `/ 2`
598
- // keeps the attach point on the strip's vertical center if
599
- // `PROGRESS_STRIP_HEIGHT_PX` is ever bumped.
600
- const slackAttachY = textSpills
601
- ? itemBox.y + itemBox.height - PROGRESS_STRIP_HEIGHT_PX / 2
602
- : itemBox.y + itemBox.height / 2;
603
- ctx.itemSlackAttachY.set(drawKey, slackAttachY);
604
- cursor.x = logicalRight;
605
- cursor.maxX = Math.max(cursor.maxX, cursor.x);
606
- // The next row in a parallel/group/lane starts at
607
- // `cursor.y + cursor.height`. Default pitch is `bandScale.step()`
608
- // (bandwidth + inter-row gap). When the bar grew to enclose a
609
- // spilled chip column, the pitch grows by the SAME amount so the
610
- // inter-row gap stays constant — the next row's bar starts
611
- // `step − bandwidth` px below the (now-taller) bar bottom.
612
- cursor.height = Math.max(cursor.height, ctx.bandScale.step() + chipBarExtra);
613
- const inlineDatePins = computeItemInlineDatePins({
614
- box: itemBox,
615
- afterDate: pickInlineDate(afterRaw),
616
- beforeDate: pickInlineDate(beforeRaw),
617
- hasLinkIcon,
618
- footnoteCount: footnoteIndicators.length,
619
- });
620
- const result = {
621
- kind: 'item',
622
- id,
623
- title: titleStr,
624
- box: itemBox,
625
- status,
626
- progressFraction: progress,
627
- footnoteIndicators,
628
- labelChips,
629
- chipsOutside,
630
- chipsRightX,
631
- linkIcon: linkInfo.icon,
632
- linkHref: linkInfo.href,
633
- hasOverflow,
634
- overflowBox,
635
- overflowAnchorId,
636
- owner,
637
- description,
638
- metaText,
639
- textSpills,
640
- dotSpills,
641
- iconSpills,
642
- footnoteSpills,
643
- dotSpillCx,
644
- iconSpillX,
645
- footnoteSpillStartX,
646
- decorationsRightX,
647
- capacity,
648
- size: sizeResolved,
649
- style,
650
- inlineDatePins: inlineDatePins.length > 0 ? inlineDatePins : undefined,
651
- };
652
- return result;
653
- }
654
- function sequenceParallel(node, cursor, ctx) {
655
- return new ParallelNode(node, { sequenceOne, newCursor }).place(cursor, ctx);
656
- }
657
- function sequenceGroup(node, cursor, ctx) {
658
- return new GroupNode(node, {
659
- sequenceItem,
660
- sequenceOne,
661
- resolveChildStart,
662
- newCursor,
663
- estimateTextWidth,
664
- predictItemChipExtraHeight,
665
- }).place(cursor, ctx);
666
- }
667
- function sequenceOne(node, cursor, ctx) {
668
- if (isItemDeclaration(node))
669
- return sequenceItem(node, cursor, ctx);
670
- if (isParallelBlock(node))
671
- return sequenceParallel(node, cursor, ctx);
672
- if (isGroupBlock(node))
673
- return sequenceGroup(node, cursor, ctx);
674
- throw new Error(`Unknown swimlane child type: ${node.$type ?? 'unknown'}`);
675
- }
676
- // Rough px-width estimate for sans-serif text. Intentionally pessimistic
677
- // (uses ~0.58 em per char) so we err toward "doesn't fit" and trigger a
678
- // row bump rather than draw an item with a clipped title.
679
- function estimateTextWidth(text, fontSize) {
680
- return text.length * fontSize * 0.58;
681
- }
682
- /**
683
- * Internal drawing handle for an id-less item. Title-only items have no
684
- * `node.name`, yet they still need a stable key to register their own
685
- * dependency-arrow target geometry and join flow-key dedup. The handle is
686
- * derived from the item's source position so it is deterministic and
687
- * byte-stable, and the `#item@line:col` form cannot be produced by the
688
- * grammar's id rule — so `after:` / `before:` / `on:` can never resolve to it
689
- * (an id-less item stays non-referenceable; declare an explicit id to
690
- * reference it). Distinct items always start at distinct positions, so the
691
- * handle is unique within a file.
692
- */
693
- function syntheticItemKey(node) {
694
- const start = node.$cstNode?.range.start;
695
- return `#item@${start ? start.line + 1 : 0}:${start ? start.character + 1 : 0}`;
696
- }
697
- /**
698
- * Compute the extra vertical px the bar grows when its spilled chip
699
- * column would otherwise extend below the (single-row) bottom. The
700
- * bar's painted footprint becomes `bandwidth + chipBarExtra`, the
701
- * progress strip rides the new bottom, and chip rows pack inside
702
- * the taller bar (anchored from the bar TOP so row 0 doesn't shift
703
- * when the bar grows).
704
- *
705
- * Returns 0 when chips fit inside the bar, when there are no chips,
706
- * or when the spilled column happens to fit inside `bandwidth` (a
707
- * single row with the caption inside, for instance).
708
- *
709
- * The same number is the row-pitch increase the swimlane / group
710
- * row-packer needs to reserve so the next row clears the taller
711
- * bar — `cursor.height = step + chipBarExtra` and the predict
712
- * helper returns this verbatim.
713
- */
714
- function computeChipBarExtra(chipsOutside, captionSpills, chipRowCount, bandwidth, hasMeta) {
715
- if (chipRowCount === 0)
716
- return 0;
717
- // Row 0 anchor relative to the bar's TOP — three regimes:
718
- //
719
- // 1. chipsOutside + captionSpills → chips stack below the
720
- // spilled meta line (`captionStackTop`).
721
- // 2. chips INSIDE the bar AND meta is present → chip top must
722
- // clear the meta baseline; the natural `baseTop` sits
723
- // ABOVE the meta line at default bandwidth (=56), so we
724
- // take whichever is lower of base/captionStack.
725
- // 3. otherwise (in-bar w/o meta, or chipsOutside w/o caption
726
- // spill) → row 0 hugs the bar bottom at `baseTop`.
727
- //
728
- // Cases (2) and (3-with-multi-row-spill) can both grow the bar;
729
- // case (3-with-single-row-inside-no-meta) never grows.
730
- const baseTop = bandwidth -
731
- PROGRESS_STRIP_HEIGHT_PX -
732
- LABEL_CHIP_HEIGHT_PX -
733
- LABEL_CHIP_GAP_ABOVE_PROGRESS_STRIP_PX;
734
- const captionStackTop = ITEM_CAPTION_META_BASELINE_OFFSET_PX + LABEL_CHIP_GAP_ABOVE_PROGRESS_STRIP_PX;
735
- let chipRow0Top;
736
- if (chipsOutside && captionSpills) {
737
- chipRow0Top = captionStackTop;
738
- }
739
- else if (!chipsOutside && hasMeta) {
740
- chipRow0Top = Math.max(baseTop, captionStackTop);
741
- }
742
- else {
743
- chipRow0Top = baseTop;
744
- }
745
- const lastRowBottomTop = chipRow0Top + (chipRowCount - 1) * LABEL_CHIP_ROW_STEP_PX + LABEL_CHIP_HEIGHT_PX;
746
- // The bar must be tall enough to fit `lastRowBottomTop` plus a
747
- // GAP above the progress strip plus the progress strip itself.
748
- const requiredHeight = lastRowBottomTop + LABEL_CHIP_GAP_ABOVE_PROGRESS_STRIP_PX + PROGRESS_STRIP_HEIGHT_PX;
749
- return Math.max(0, requiredHeight - bandwidth);
750
- }
751
- /**
752
- * Predict an item's bar growth (and therefore row-pitch growth) for
753
- * a multi-row spilled chip column BEFORE the bar is sequenced. Used
754
- * by the swimlane / group row-packer so neighboring rows on later
755
- * rows are positioned correctly without a retroactive shift.
756
- *
757
- * Mirrors the chip-pack + caption-spill arithmetic in
758
- * `sequenceItem` so prediction and placement agree byte-for-byte.
759
- */
760
- function predictItemChipExtraHeight(item, ctx) {
761
- const props = item.properties;
762
- const labelIds = propValues(props, 'labels');
763
- if (labelIds.length === 0)
764
- return 0;
765
- const durationDays = deriveItemDurationDays(props, ctx.sizes, ctx.cal);
766
- const naturalWidth = Math.max(MIN_ITEM_WIDTH, durationDays * ctx.timeline.pixelsPerDay);
767
- const visualWidth = Math.max(MIN_ITEM_WIDTH, naturalWidth - 2 * ITEM_INSET_PX);
768
- const samples = [];
769
- for (const labelId of labelIds) {
770
- const label = ctx.labels.get(labelId);
771
- if (!label)
772
- continue;
773
- const sample = buildLabelChip(label, ctx.styleCtx, 0, 0);
774
- samples.push({ id: label, width: sample.box.width });
775
- }
776
- if (samples.length === 0)
777
- return 0;
778
- let chipRowWidth = 0;
779
- for (let i = 0; i < samples.length; i += 1) {
780
- if (i > 0)
781
- chipRowWidth += LABEL_CHIP_GAP_BETWEEN_PX;
782
- chipRowWidth += samples[i].width;
783
- }
784
- const insideAvail = Math.max(0, visualWidth - 2 * ITEM_CAPTION_INSET_X_PX);
785
- const chipsOutside = chipRowWidth > insideAvail;
786
- // `hasMeta` mirrors `metaText !== undefined` in `sequenceItem`,
787
- // plus the capacity suffix (which renders on the same meta line).
788
- // metaText is set whenever an item declares a duration, owner,
789
- // or remaining — so we just check those four props. Status
790
- // strings (in-progress) only matter when paired with one of
791
- // these, so this is an upper bound (false-positives still grow
792
- // the bar by exactly the same amount as the renderer would, so
793
- // they stay byte-stable).
794
- const hasMeta = propValue(props, 'duration') !== undefined ||
795
- propValue(props, 'size') !== undefined ||
796
- propValue(props, 'owner') !== undefined ||
797
- propValue(props, 'remaining') !== undefined ||
798
- propValue(props, 'capacity') !== undefined;
799
- const titleStr = item.title ?? item.name ?? '';
800
- const titleW = titleStr ? estimateTextWidth(titleStr, ITEM_CAPTION_TITLE_FONT_SIZE_PX) : 0;
801
- const captionSpills = titleW > insideAvail;
802
- const pack = chipsOutside ? packSpillChips(samples, visualWidth) : null;
803
- const chipRowCount = pack ? pack.rows.length : samples.length > 0 ? 1 : 0;
804
- return computeChipBarExtra(chipsOutside, captionSpills, chipRowCount, ctx.bandScale.bandwidth(), hasMeta);
805
- }
806
- // Resolve the desired startX for a swimlane child, honoring `date:` (fixed
807
- // pin) > `start:` (fixed pin) > `after:` (chain after refs) > sequential
808
- // default (continue from `seqDefault`, which is the lane's rightmost time
809
- // cursor across all rows).
810
- //
811
- // `after:` accepts both entity ids (looked up in `ctx.entityRightEdges`) and
812
- // inline ISO date literals (looked up via `ctx.scale.forwardWithinDomain`).
813
- // The validator already enforces "at most one inline date per direction" so
814
- // at most one element in the list will hit the date path.
815
- function resolveChildStart(props, seqDefault, laneLeftX, ctx) {
816
- const explicitDate = parseDate(propValue(props, 'date')) ?? parseDate(propValue(props, 'start'));
817
- if (explicitDate) {
818
- const xd = ctx.scale.forwardWithinDomain(explicitDate);
819
- if (xd !== null)
820
- return xd;
821
- }
822
- const afterRefs = propValues(props, 'after');
823
- if (afterRefs.length > 0) {
824
- let maxEnd = laneLeftX;
825
- for (const ref of afterRefs) {
826
- const inlineDate = parseDate(ref);
827
- if (inlineDate) {
828
- const xd = ctx.scale.forwardWithinDomain(inlineDate);
829
- if (xd !== null)
830
- maxEnd = Math.max(maxEnd, xd);
831
- continue;
832
- }
833
- const endX = ctx.entityRightEdges.get(ref);
834
- if (endX !== undefined)
835
- maxEnd = Math.max(maxEnd, endX);
836
- }
837
- return Math.max(laneLeftX, maxEnd);
838
- }
839
- return seqDefault;
840
- }
841
- function _buildSwimlane(lane, y, bandIndex, ctx) {
842
- return new SwimlaneNode({ lane, bandIndex }, {
843
- sequenceItem,
844
- sequenceOne,
845
- resolveChildStart,
846
- newCursor,
847
- estimateTextWidth,
848
- predictItemChipExtraHeight,
849
- }).place({ x: ctx.timeline.originX, y }, ctx);
850
- }
851
- // Card-sizing constants for beside-mode headers live in
852
- // `header-card-geometry.ts` so the renderer can paint with the same
853
- // numbers the layout sized against. Title and author both wrap at
854
- // MAX_CONTENT_WIDTH (= MAX header width minus 2 * padding). The card
855
- // hugs its content in the MIN..MAX range and grows vertically when
856
- // wrapping is needed.
857
- //
858
- // Left margin between the canvas's left edge and the visible card. The
859
- // matching right-side breathing room is owned by `GUTTER_PX` (the canonical
860
- // content gutter, applied between `chartLeftX` and `originX`), so the gap
861
- // from the card's right edge to the timeline strip is the same as the gap
862
- // between two adjacent items.
863
- const HEADER_CARD_OUTER_PAD = 6;
864
- // Word-wrap `text` so that no line wider than `maxWidth` (in px). Long single
865
- // words are kept on their own line even if they overflow — we never split a
866
- // word in the middle.
867
- function wrapText(text, maxWidth, fontSize) {
868
- if (!text)
869
- return [];
870
- const words = text.split(/\s+/).filter((w) => w.length > 0);
871
- if (words.length === 0)
872
- return [];
873
- const lines = [];
874
- let cur = '';
875
- for (const word of words) {
876
- const trial = cur ? `${cur} ${word}` : word;
877
- if (cur && estimateTextWidth(trial, fontSize) > maxWidth) {
878
- lines.push(cur);
879
- cur = word;
880
- }
881
- else {
882
- cur = trial;
883
- }
884
- }
885
- if (cur)
886
- lines.push(cur);
887
- return lines;
888
- }
889
- function sizeBesideHeader(title, author) {
890
- const maxContentWidth = HEADER_BESIDE_MAX_WIDTH_PX - 2 * HEADER_CARD_PADDING_X;
891
- const titleLines = wrapText(title, maxContentWidth, HEADER_TITLE_FONT_SIZE_PX);
892
- const authorLines = wrapText(author ?? '', maxContentWidth, HEADER_AUTHOR_FONT_SIZE_PX);
893
- let widest = 0;
894
- for (const line of titleLines)
895
- widest = Math.max(widest, estimateTextWidth(line, HEADER_TITLE_FONT_SIZE_PX));
896
- for (const line of authorLines)
897
- widest = Math.max(widest, estimateTextWidth(line, HEADER_AUTHOR_FONT_SIZE_PX));
898
- const naturalCardWidth = widest + 2 * HEADER_CARD_PADDING_X;
899
- // `HEADER_BESIDE_{MIN,MAX}_WIDTH_PX` bound the **boxWidth** (= cardWidth
900
- // + left outer pad). Subtract one outer pad to derive the cardWidth
901
- // bounds.
902
- const cardWidth = Math.max(HEADER_BESIDE_MIN_WIDTH_PX - HEADER_CARD_OUTER_PAD, Math.min(HEADER_BESIDE_MAX_WIDTH_PX - HEADER_CARD_OUTER_PAD, naturalCardWidth));
903
- const titleBlockHeight = titleLines.length > 0 ? (titleLines.length - 1) * HEADER_TITLE_LINE_HEIGHT_PX : 0;
904
- const authorBlockHeight = authorLines.length > 0
905
- ? HEADER_TITLE_TO_AUTHOR_GAP_PX +
906
- (authorLines.length - 1) * HEADER_AUTHOR_LINE_HEIGHT_PX
907
- : 0;
908
- const cardHeight = HEADER_CARD_PADDING_TOP + titleBlockHeight + authorBlockHeight + HEADER_CARD_PADDING_BOTTOM;
909
- // `boxWidth` only includes the LEFT outer pad — the right-side breathing
910
- // room between the card and the chart is owned by `GUTTER_PX` in
911
- // `RoadmapNode`. So `boxWidth` doubles as `chartLeftX` (the card's right
912
- // edge in canvas coordinates).
913
- const boxWidth = cardWidth + HEADER_CARD_OUTER_PAD;
914
- return { titleLines, authorLines, cardWidth, cardHeight, boxWidth };
915
- }
916
- // Compute a sensible [startDate, endDate] window.
917
- //
918
- // Precedence:
919
- // 1. Explicit `length:` on the roadmap declaration wins.
920
- // 2. Otherwise we derive the end day from the actual content extent
921
- // (latest item end, anchor date, milestone date/after, and today's
922
- // now-line if it falls past the content). This keeps the rendered
923
- // chart from defaulting to a 180-day desert when the content only
924
- // spans a few weeks.
925
- // 3. As a last resort (no content + no length), fall back to a small
926
- // 4-week placeholder so an empty roadmap still draws a sensible axis.
927
- function computeDateWindow(file, ctx, resolved, today, scale) {
928
- const roadmap = file.roadmapDecl;
929
- const props = roadmap?.properties ?? [];
930
- const startRaw = propValue(props, 'start');
931
- // Spec (`specs/dsl.md`): "A roadmap with no `start:` and no dates is
932
- // purely relative — renderers choose their own reference date (e.g.
933
- // the day of rendering)." Use the caller's `today` (the resolved
934
- // `--now`) when present so the start lines up with the now-line, and
935
- // fall back to actual today's UTC midnight otherwise. Either default
936
- // is dangerous — output drifts day-to-day — but it's strictly better
937
- // than the legacy "Jan 1 of the current year" fallback that drifted
938
- // every January 1 by 365 days at once. Authors should set `start:`
939
- // for any roadmap they want to be reproducible.
940
- const startDate = parseDate(startRaw) ?? defaultStartDate(today);
941
- const lengthRaw = propValue(props, 'length');
942
- if (lengthRaw) {
943
- const days = literalDays(lengthRaw, ctx.cal);
944
- if (days > 0) {
945
- return { startDate, endDate: addDays(startDate, days) };
946
- }
947
- }
948
- const contentDays = computeContentEndDay(resolved, ctx, startDate, today);
949
- const tickDays = daysPerUnit(scale.unit, ctx.cal);
950
- // Round up to the smallest tick boundary that is `>= contentDays`. When
951
- // the latest content lands exactly on a tick boundary the chart ends
952
- // exactly there (no extra trailing tick); otherwise we extend to the
953
- // next tick so the right edge always sits on a labelled column.
954
- const padded = contentDays > 0 ? Math.ceil(contentDays / tickDays) * tickDays : 4 * ctx.cal.daysPerWeek;
955
- return { startDate, endDate: addDays(startDate, Math.max(1, padded)) };
956
- }
957
- /**
958
- * Reference date used when a roadmap omits `start:`. Prefers the
959
- * caller-supplied `today` (UTC midnight already, when it comes from
960
- * the CLI); falls back to actual today's UTC midnight so the layout
961
- * still produces a valid window for direct API callers that don't pass
962
- * a `today`. Date components are taken in UTC to match `parseDate`.
963
- */
964
- function defaultStartDate(today) {
965
- const ref = today ?? new Date();
966
- return new Date(Date.UTC(ref.getUTCFullYear(), ref.getUTCMonth(), ref.getUTCDate()));
967
- }
968
- function literalDays(literal, cal) {
969
- const m = /^(\d+(?:\.\d+)?)([dwmqy])$/.exec(literal);
970
- if (!m)
971
- return 0;
972
- const n = parseFloat(m[1]);
973
- switch (m[2]) {
974
- case 'd':
975
- return n;
976
- case 'w':
977
- return n * cal.daysPerWeek;
978
- case 'm':
979
- return n * cal.daysPerMonth;
980
- case 'q':
981
- return n * cal.daysPerQuarter;
982
- case 'y':
983
- return n * cal.daysPerYear;
984
- default:
985
- return 0;
986
- }
987
- }
988
- // Walk every dated/sequenced entity in the resolved content and return the
989
- // latest day-offset from `startDate`. Mirrors the sequencer's start-rules
990
- // (date: > start: > after: > previous-in-lane) without producing positions.
991
- function computeContentEndDay(resolved, ctx, startDate, today) {
992
- const itemEnd = new Map();
993
- const anchorEnd = new Map();
994
- const milestoneEnd = new Map();
995
- let maxDay = 0;
996
- // Resolve a single `after:` element to a day-offset from `startDate`.
997
- // The element is either an entity id (looked up in itemEnd / anchorEnd /
998
- // milestoneEnd) or an inline ISO date literal (converted directly via
999
- // `daysBetween`). The validator already enforces "at most one inline date
1000
- // per direction", so at most one element per list will hit the date path.
1001
- const resolveAfterDay = (ref) => {
1002
- const inlineDate = parseDate(ref);
1003
- if (inlineDate)
1004
- return daysBetween(startDate, inlineDate);
1005
- if (itemEnd.has(ref))
1006
- return itemEnd.get(ref);
1007
- if (anchorEnd.has(ref))
1008
- return anchorEnd.get(ref);
1009
- if (milestoneEnd.has(ref))
1010
- return milestoneEnd.get(ref);
1011
- return 0;
1012
- };
1013
- // Pre-seed anchors fixed by `date:` so items that reference them get a
1014
- // valid end-day during the lane walk.
1015
- for (const anchor of resolved.content.anchors.values()) {
1016
- const d = parseDate(propValue(anchor.properties, 'date'));
1017
- if (d && anchor.name) {
1018
- const day = daysBetween(startDate, d);
1019
- anchorEnd.set(anchor.name, day);
1020
- maxDay = Math.max(maxDay, day);
1021
- }
1022
- }
1023
- const walkLane = (children, baselineEnd) => {
1024
- let prevEnd = baselineEnd;
1025
- for (const child of children) {
1026
- if (child.$type === 'DescriptionDirective')
1027
- continue;
1028
- prevEnd = walkNode(child, prevEnd);
1029
- maxDay = Math.max(maxDay, prevEnd);
1030
- }
1031
- return prevEnd;
1032
- };
1033
- const walkNode = (node, prevEnd) => {
1034
- if (isItemDeclaration(node)) {
1035
- const dur = deriveItemDurationDays(node.properties, ctx.sizes, ctx.cal);
1036
- const dateProp = parseDate(propValue(node.properties, 'date'));
1037
- const startProp = parseDate(propValue(node.properties, 'start'));
1038
- const afterRefs = propValues(node.properties, 'after');
1039
- let start = prevEnd;
1040
- if (dateProp) {
1041
- start = daysBetween(startDate, dateProp);
1042
- }
1043
- else if (startProp) {
1044
- start = daysBetween(startDate, startProp);
1045
- }
1046
- else if (afterRefs.length > 0) {
1047
- start = Math.max(prevEnd, ...afterRefs.map(resolveAfterDay));
1048
- }
1049
- const end = start + dur;
1050
- if (node.name)
1051
- itemEnd.set(node.name, end);
1052
- return end;
1053
- }
1054
- if (isParallelBlock(node)) {
1055
- // All children share the parallel's start; the block's effective
1056
- // end is the maximum child end. The parallel's own `after:`
1057
- // (including inline-date pins) widens that shared start.
1058
- const afterRefs = propValues(node.properties, 'after');
1059
- const containerStart = afterRefs.length > 0
1060
- ? Math.max(prevEnd, ...afterRefs.map(resolveAfterDay))
1061
- : prevEnd;
1062
- let parallelEnd = containerStart;
1063
- for (const child of node.content) {
1064
- if (child.$type === 'DescriptionDirective')
1065
- continue;
1066
- const childEnd = walkNode(child, containerStart);
1067
- parallelEnd = Math.max(parallelEnd, childEnd);
1068
- }
1069
- return parallelEnd;
1070
- }
1071
- if (isGroupBlock(node)) {
1072
- // The group's own `after:` (including inline-date pins) widens
1073
- // the baseline before walking the inner sequential lane.
1074
- const afterRefs = propValues(node.properties, 'after');
1075
- const containerStart = afterRefs.length > 0
1076
- ? Math.max(prevEnd, ...afterRefs.map(resolveAfterDay))
1077
- : prevEnd;
1078
- return walkLane(node.content, containerStart);
1079
- }
1080
- return prevEnd;
1081
- };
1082
- for (const lane of resolved.content.swimlanes.values()) {
1083
- walkLane(lane.content, 0);
1084
- }
1085
- // Milestones (after items so `after:` references can resolve).
1086
- for (const ms of resolved.content.milestones.values()) {
1087
- const d = parseDate(propValue(ms.properties, 'date'));
1088
- if (d) {
1089
- const day = daysBetween(startDate, d);
1090
- if (ms.name)
1091
- milestoneEnd.set(ms.name, day);
1092
- maxDay = Math.max(maxDay, day);
1093
- continue;
1094
- }
1095
- const after = propValues(ms.properties, 'after');
1096
- if (after.length > 0) {
1097
- // Milestones disallow inline date literals at the validator
1098
- // level (rule 24a — milestones already have `date:`). The
1099
- // shared `resolveAfterDay` helper still handles such input
1100
- // gracefully if it slips past, treating the date as the
1101
- // milestone's effective day.
1102
- const day = Math.max(0, ...after.map(resolveAfterDay));
1103
- if (ms.name)
1104
- milestoneEnd.set(ms.name, day);
1105
- maxDay = Math.max(maxDay, day);
1106
- }
1107
- }
1108
- // Isolated includes contribute their own content extent against the
1109
- // shared timeline.
1110
- for (const region of resolved.content.isolatedRegions) {
1111
- const nestedMax = computeContentEndDay({
1112
- config: region.config,
1113
- content: region.content,
1114
- diagnostics: [],
1115
- processedFiles: new Set(),
1116
- }, ctx, startDate, undefined);
1117
- maxDay = Math.max(maxDay, nestedMax);
1118
- }
1119
- if (today) {
1120
- const t = daysBetween(startDate, today);
1121
- if (t > 0)
1122
- maxDay = Math.max(maxDay, t);
1123
- }
1124
- return maxDay;
1125
- }
1126
- function buildDependencies(items, swimlanes, includes, ctx) {
1127
- // m2g+: collect every painted item bar + every visible parallel /
1128
- // group bracket once, hand to the channel router so it can drop
1129
- // vertical legs in clean inter-column gutters and nudge away from
1130
- // bracket strokes that would otherwise be hugged.
1131
- const grid = new ChannelGrid(collectRoutingObstacles(swimlanes, includes));
1132
- const requests = [];
1133
- const pending = [];
1134
- for (const [id, item] of items) {
1135
- const afters = propValues(item.properties, 'after');
1136
- const targetMid = ctx.entityMidpoints.get(id);
1137
- const targetVisualLeftX = ctx.entityVisualLeftX.get(id);
1138
- if (!targetMid || targetVisualLeftX === undefined)
1139
- continue;
1140
- // The arrow always TERMINATES at the target item's left
1141
- // visual edge, vertically centered on the bar.
1142
- const targetPoint = { x: targetVisualLeftX, y: targetMid.y };
1143
- for (const pred of afters) {
1144
- // Source point depends on what kind of predecessor `pred`
1145
- // is. For ITEMS we use the per-item arrow source point
1146
- // — (visualRight, midY) by default, dropping to
1147
- // (visualRight, bar.bottom - PROGRESS_STRIP_HEIGHT/2) when
1148
- // the caption spilled past the right edge so the arrow
1149
- // exits below the spilled title / meta text. For ANCHORS
1150
- // / MILESTONES we attach to the marker's vertical CUT
1151
- // LINE at the TARGET item's row mid-Y — the dashed/solid
1152
- // cut line already drops through the chart and reads as
1153
- // the arrow's stem, so a short horizontal stub from the
1154
- // line into the bar's left edge is the cleanest
1155
- // connection.
1156
- const itemSource = ctx.itemArrowSource.get(pred);
1157
- let from;
1158
- const isMarkerPred = itemSource === undefined;
1159
- if (itemSource) {
1160
- from = itemSource;
1161
- }
1162
- else {
1163
- const markerMid = ctx.entityMidpoints.get(pred);
1164
- if (!markerMid)
1165
- continue;
1166
- from = { x: markerMid.x, y: targetMid.y };
1167
- }
1168
- // Skip same-row contiguous chains for ITEM → ITEM only:
1169
- // when the target sits immediately to the right of the
1170
- // source on the same row, the spatial flow already
1171
- // conveys ordering and an arrow is redundant noise.
1172
- // MARKER → ITEM stubs always draw (the cut line is the
1173
- // stem; the short stub completes the visual connection
1174
- // even when the bar is right next to the cut line).
1175
- if (!isMarkerPred &&
1176
- Math.abs(from.y - targetPoint.y) < 0.5 &&
1177
- targetPoint.x - from.x < 20) {
1178
- continue;
1179
- }
1180
- requests.push({
1181
- fromId: pred,
1182
- toId: id,
1183
- from,
1184
- to: targetPoint,
1185
- isMarkerSource: isMarkerPred,
1186
- });
1187
- pending.push({ fromId: pred, toId: id });
1188
- }
1189
- }
1190
- const routed = routeChannelEdges(requests, grid);
1191
- const out = [];
1192
- for (let i = 0; i < routed.length; i++) {
1193
- const r = routed[i];
1194
- out.push({
1195
- fromId: pending[i].fromId,
1196
- toId: pending[i].toId,
1197
- waypoints: r.waypoints,
1198
- kind: r.underBar ? 'underBar' : 'normal',
1199
- style: resolveStyle('item', [], ctx.styleCtx),
1200
- });
1201
- }
1202
- return out;
1203
- }
1204
- function buildNowline(today, ctx, locale) {
1205
- if (!today)
1206
- return null;
1207
- const x = ctx.scale.forwardWithinDomain(today);
1208
- if (x === null)
1209
- return null;
1210
- // Pill row is the band reserved at the very top of the timeline area.
1211
- // The line drops from the bottom of the pill (top of the date headers)
1212
- // through any marker row and into the chart, so the pill and line stay
1213
- // visually connected.
1214
- const pillTopY = ctx.timeline.box.y;
1215
- const lineTopY = ctx.timeline.tickPanelY;
1216
- // Pill width is locale-aware: en-US's `'now'` (3 chars) fits the
1217
- // 36 px default trivially; longer strings like fr's `'maint.'`
1218
- // (6 chars) need a wider pill to avoid clipping. Floor at the
1219
- // default so en-US output stays byte-stable; grow when the
1220
- // measured label needs it. The 2× inset matches the renderer's
1221
- // flag-mode label inset (`NOW_PILL_LABEL_INSET_X_PX`) and gives
1222
- // the same visual padding to centered-mode strings.
1223
- const label = localeStrings(locale).nowLabel;
1224
- const labelTextWidth = estimateTextWidth(label, NOW_PILL_LABEL_FONT_SIZE_PX);
1225
- const pillWidth = Math.max(NOW_PILL_WIDTH_PX, Math.ceil(labelTextWidth + 2 * NOW_PILL_LABEL_INSET_X_PX));
1226
- // The "chart's left edge" the pill must clear is `chartLeftX` (in
1227
- // beside-mode, the right edge of the header card; in above-mode,
1228
- // the canvas left edge at x=0). originX = chartLeftX + GUTTER_PX,
1229
- // so we recover chartLeftX as `originX - GUTTER_PX`.
1230
- const chartLeftX = ctx.timeline.originX - GUTTER_PX;
1231
- const halfPill = pillWidth / 2;
1232
- let pillMode;
1233
- if (x - halfPill < chartLeftX) {
1234
- // Centered pill would intrude into the header card / past the
1235
- // canvas left edge — anchor the pill's LEFT side to the line
1236
- // and let it extend right into the chart.
1237
- pillMode = 'flag-right';
1238
- }
1239
- else if (x + halfPill > ctx.chartRightX) {
1240
- // Centered pill would clip past the canvas right edge — anchor
1241
- // the pill's RIGHT side to the line and let it extend left.
1242
- pillMode = 'flag-left';
1243
- }
1244
- else {
1245
- pillMode = 'center';
1246
- }
1247
- // Bottom-most Y the now-line should reach. When a mirrored bottom
1248
- // tick panel exists, thread the line through it (so the line ties
1249
- // the two date strips together visually). Otherwise stop at the
1250
- // last swimlane — never extend into the footnote area below.
1251
- const bottomTickPanelY = ctx.timeline.bottomTickPanelY;
1252
- const bottomTickPanelHeight = ctx.timeline.bottomTickPanelHeight ?? 0;
1253
- const lineBottomY = bottomTickPanelY !== undefined && bottomTickPanelHeight > 0
1254
- ? bottomTickPanelY + bottomTickPanelHeight
1255
- : ctx.swimlaneBottomY;
1256
- return {
1257
- x,
1258
- topY: lineTopY,
1259
- bottomY: lineBottomY,
1260
- pillTopY,
1261
- pillMode,
1262
- label,
1263
- pillWidth,
1264
- style: resolveStyle('item', [], ctx.styleCtx),
1265
- };
1266
- }
1267
- // Mutable layout-time context shared across helpers.
1268
- // Traverse the full content tree to build an `items` map keyed by id.
1269
- function collectItems(swimlanes) {
1270
- const out = new Map();
1271
- const walk = (node) => {
1272
- if (isItemDeclaration(node)) {
1273
- // Title-only items register under a synthetic, non-referenceable
1274
- // handle so they still appear as dependency-edge targets.
1275
- out.set(node.name ?? syntheticItemKey(node), node);
1276
- return;
1277
- }
1278
- if (isParallelBlock(node)) {
1279
- for (const child of node.content) {
1280
- if (child.$type === 'DescriptionDirective')
1281
- continue;
1282
- walk(child);
1283
- }
1284
- return;
1285
- }
1286
- if (isGroupBlock(node)) {
1287
- for (const child of node.content) {
1288
- if (child.$type === 'DescriptionDirective')
1289
- continue;
1290
- walk(child);
1291
- }
1292
- return;
1293
- }
1294
- };
1295
- for (const lane of swimlanes) {
1296
- for (const child of lane.content) {
1297
- if (child.$type === 'DescriptionDirective')
1298
- continue;
1299
- walk(child);
1300
- }
1301
- }
1302
- return out;
1303
- }
6
+ import { scheduleRoadmap } from './schedule.js';
1304
7
  export function layoutRoadmap(file, resolved, options = {}) {
1305
- return new RoadmapNode().place(file, resolved, options, {
1306
- sequenceItem,
1307
- sequenceOne,
1308
- resolveChildStart,
1309
- newCursor,
1310
- estimateTextWidth,
1311
- predictItemChipExtraHeight,
1312
- computeDateWindow,
1313
- sizeBesideHeader,
1314
- collectItems,
1315
- buildDependencies,
1316
- buildNowline,
1317
- });
8
+ // The wave plan and the day schedule (engine C) are built once per
9
+ // layout, unless the caller already built them for this very
10
+ // `ResolveResult` (specs/scheduler-unification.md §3.6). The schedule
11
+ // carries the plan (`schedule.plan`, undefined without waves); engine A
12
+ // reads it for the barrier passes and the date window is a projection of
13
+ // the schedule.
14
+ const schedule = options.schedule?.resolved === resolved
15
+ ? options.schedule
16
+ : scheduleRoadmap(file, resolved, {
17
+ today: options.today,
18
+ plan: buildWavePlan(resolved) ?? null,
19
+ });
20
+ return new RoadmapNode().place(file, resolved, options, schedule);
1318
21
  }
1319
22
  //# sourceMappingURL=layout.js.map