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