@nowline/layout 0.0.0-dev.20260601071750.g04bdff9

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 (193) 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/inline-date-pin-geometry.d.ts +46 -0
  44. package/dist/inline-date-pin-geometry.d.ts.map +1 -0
  45. package/dist/inline-date-pin-geometry.js +149 -0
  46. package/dist/inline-date-pin-geometry.js.map +1 -0
  47. package/dist/item-bar-geometry.d.ts +157 -0
  48. package/dist/item-bar-geometry.d.ts.map +1 -0
  49. package/dist/item-bar-geometry.js +214 -0
  50. package/dist/item-bar-geometry.js.map +1 -0
  51. package/dist/lane-utilization.d.ts +90 -0
  52. package/dist/lane-utilization.d.ts.map +1 -0
  53. package/dist/lane-utilization.js +206 -0
  54. package/dist/lane-utilization.js.map +1 -0
  55. package/dist/layout-context.d.ts +143 -0
  56. package/dist/layout-context.d.ts.map +1 -0
  57. package/dist/layout-context.js +8 -0
  58. package/dist/layout-context.js.map +1 -0
  59. package/dist/layout.d.ts +18 -0
  60. package/dist/layout.d.ts.map +1 -0
  61. package/dist/layout.js +1298 -0
  62. package/dist/layout.js.map +1 -0
  63. package/dist/nodes/anchor-node.d.ts +16 -0
  64. package/dist/nodes/anchor-node.d.ts.map +1 -0
  65. package/dist/nodes/anchor-node.js +68 -0
  66. package/dist/nodes/anchor-node.js.map +1 -0
  67. package/dist/nodes/footnote-node.d.ts +10 -0
  68. package/dist/nodes/footnote-node.d.ts.map +1 -0
  69. package/dist/nodes/footnote-node.js +41 -0
  70. package/dist/nodes/footnote-node.js.map +1 -0
  71. package/dist/nodes/group-node.d.ts +29 -0
  72. package/dist/nodes/group-node.d.ts.map +1 -0
  73. package/dist/nodes/group-node.js +195 -0
  74. package/dist/nodes/group-node.js.map +1 -0
  75. package/dist/nodes/include-node.d.ts +16 -0
  76. package/dist/nodes/include-node.d.ts.map +1 -0
  77. package/dist/nodes/include-node.js +117 -0
  78. package/dist/nodes/include-node.js.map +1 -0
  79. package/dist/nodes/item-node.d.ts +51 -0
  80. package/dist/nodes/item-node.d.ts.map +1 -0
  81. package/dist/nodes/item-node.js +108 -0
  82. package/dist/nodes/item-node.js.map +1 -0
  83. package/dist/nodes/marker-geometry.d.ts +22 -0
  84. package/dist/nodes/marker-geometry.d.ts.map +1 -0
  85. package/dist/nodes/marker-geometry.js +38 -0
  86. package/dist/nodes/marker-geometry.js.map +1 -0
  87. package/dist/nodes/milestone-node.d.ts +48 -0
  88. package/dist/nodes/milestone-node.d.ts.map +1 -0
  89. package/dist/nodes/milestone-node.js +210 -0
  90. package/dist/nodes/milestone-node.js.map +1 -0
  91. package/dist/nodes/parallel-node.d.ts +21 -0
  92. package/dist/nodes/parallel-node.d.ts.map +1 -0
  93. package/dist/nodes/parallel-node.js +88 -0
  94. package/dist/nodes/parallel-node.js.map +1 -0
  95. package/dist/nodes/roadmap-node.d.ts +76 -0
  96. package/dist/nodes/roadmap-node.d.ts.map +1 -0
  97. package/dist/nodes/roadmap-node.js +788 -0
  98. package/dist/nodes/roadmap-node.js.map +1 -0
  99. package/dist/nodes/swimlane-node.d.ts +38 -0
  100. package/dist/nodes/swimlane-node.d.ts.map +1 -0
  101. package/dist/nodes/swimlane-node.js +308 -0
  102. package/dist/nodes/swimlane-node.js.map +1 -0
  103. package/dist/renderable.d.ts +44 -0
  104. package/dist/renderable.d.ts.map +1 -0
  105. package/dist/renderable.js +21 -0
  106. package/dist/renderable.js.map +1 -0
  107. package/dist/row-packer.d.ts +125 -0
  108. package/dist/row-packer.d.ts.map +1 -0
  109. package/dist/row-packer.js +169 -0
  110. package/dist/row-packer.js.map +1 -0
  111. package/dist/style-resolution.d.ts +14 -0
  112. package/dist/style-resolution.d.ts.map +1 -0
  113. package/dist/style-resolution.js +191 -0
  114. package/dist/style-resolution.js.map +1 -0
  115. package/dist/themes/dark.d.ts +4 -0
  116. package/dist/themes/dark.d.ts.map +1 -0
  117. package/dist/themes/dark.js +241 -0
  118. package/dist/themes/dark.js.map +1 -0
  119. package/dist/themes/grayscale.d.ts +4 -0
  120. package/dist/themes/grayscale.d.ts.map +1 -0
  121. package/dist/themes/grayscale.js +237 -0
  122. package/dist/themes/grayscale.js.map +1 -0
  123. package/dist/themes/index.d.ts +19 -0
  124. package/dist/themes/index.d.ts.map +1 -0
  125. package/dist/themes/index.js +57 -0
  126. package/dist/themes/index.js.map +1 -0
  127. package/dist/themes/light.d.ts +4 -0
  128. package/dist/themes/light.d.ts.map +1 -0
  129. package/dist/themes/light.js +248 -0
  130. package/dist/themes/light.js.map +1 -0
  131. package/dist/themes/shape.d.ts +194 -0
  132. package/dist/themes/shape.d.ts.map +1 -0
  133. package/dist/themes/shape.js +6 -0
  134. package/dist/themes/shape.js.map +1 -0
  135. package/dist/themes/shared.d.ts +145 -0
  136. package/dist/themes/shared.d.ts.map +1 -0
  137. package/dist/themes/shared.js +310 -0
  138. package/dist/themes/shared.js.map +1 -0
  139. package/dist/time-scale.d.ts +39 -0
  140. package/dist/time-scale.d.ts.map +1 -0
  141. package/dist/time-scale.js +62 -0
  142. package/dist/time-scale.js.map +1 -0
  143. package/dist/types.d.ts +516 -0
  144. package/dist/types.d.ts.map +1 -0
  145. package/dist/types.js +6 -0
  146. package/dist/types.js.map +1 -0
  147. package/dist/view-preset.d.ts +23 -0
  148. package/dist/view-preset.d.ts.map +1 -0
  149. package/dist/view-preset.js +146 -0
  150. package/dist/view-preset.js.map +1 -0
  151. package/dist/working-calendar.d.ts +14 -0
  152. package/dist/working-calendar.d.ts.map +1 -0
  153. package/dist/working-calendar.js +74 -0
  154. package/dist/working-calendar.js.map +1 -0
  155. package/package.json +43 -0
  156. package/src/band-scale.ts +115 -0
  157. package/src/calendar.ts +244 -0
  158. package/src/capacity.ts +191 -0
  159. package/src/dsl-utils.ts +30 -0
  160. package/src/edge-routing.ts +550 -0
  161. package/src/frame-tab-geometry.ts +165 -0
  162. package/src/header-card-geometry.ts +48 -0
  163. package/src/i18n.ts +124 -0
  164. package/src/include-chrome-geometry.ts +156 -0
  165. package/src/index.ts +118 -0
  166. package/src/inline-date-pin-geometry.ts +196 -0
  167. package/src/item-bar-geometry.ts +271 -0
  168. package/src/lane-utilization.ts +259 -0
  169. package/src/layout-context.ts +182 -0
  170. package/src/layout.ts +1530 -0
  171. package/src/nodes/anchor-node.ts +77 -0
  172. package/src/nodes/footnote-node.ts +60 -0
  173. package/src/nodes/group-node.ts +260 -0
  174. package/src/nodes/include-node.ts +168 -0
  175. package/src/nodes/item-node.ts +171 -0
  176. package/src/nodes/marker-geometry.ts +43 -0
  177. package/src/nodes/milestone-node.ts +263 -0
  178. package/src/nodes/parallel-node.ts +110 -0
  179. package/src/nodes/roadmap-node.ts +957 -0
  180. package/src/nodes/swimlane-node.ts +423 -0
  181. package/src/renderable.ts +68 -0
  182. package/src/row-packer.ts +271 -0
  183. package/src/style-resolution.ts +243 -0
  184. package/src/themes/dark.ts +244 -0
  185. package/src/themes/grayscale.ts +240 -0
  186. package/src/themes/index.ts +66 -0
  187. package/src/themes/light.ts +251 -0
  188. package/src/themes/shape.ts +230 -0
  189. package/src/themes/shared.ts +369 -0
  190. package/src/time-scale.ts +78 -0
  191. package/src/types.ts +641 -0
  192. package/src/view-preset.ts +180 -0
  193. package/src/working-calendar.ts +91 -0
@@ -0,0 +1,196 @@
1
+ // Inline-date pin glyph placement.
2
+ //
3
+ // `after:DATE` paints a calendar glyph in the entity's top-LEFT decoration
4
+ // slot; `before:DATE` paints it in the top-RIGHT slot. The two helpers
5
+ // below produce `Point` coordinates for the glyph's top-left corner, plus
6
+ // a `spilled` flag indicating whether the bar was too narrow to host the
7
+ // glyph inside (item case only — containers always have room).
8
+ //
9
+ // Slot interleaving rules (per specs/rendering.md "Inline-date glyph"):
10
+ //
11
+ // Item top-LEFT: glyph sits at the bar's leftmost slot when no link icon
12
+ // is present, otherwise one decoration step right of the link icon's
13
+ // right edge.
14
+ //
15
+ // Item top-RIGHT: glyph sits at the bar's rightmost slot when no status
16
+ // dot or footnotes are present, one step LEFT of the status dot when no
17
+ // footnotes, and one step LEFT of the LEFTMOST footnote indicator when
18
+ // footnotes are present (so the inline-date glyph inserts at the LEFT
19
+ // end of the existing badge cluster rather than reordering it).
20
+ //
21
+ // Container (group, parallel): glyph sits at the bounding box's top
22
+ // corners with the standard inset. Containers don't carry status dots
23
+ // or footnote indicators in their own decoration row, so no
24
+ // interleaving math is needed.
25
+
26
+ import {
27
+ INLINE_DATE_GLYPH_GAP_PX,
28
+ INLINE_DATE_GLYPH_INSET_LEFT_PX,
29
+ INLINE_DATE_GLYPH_INSET_RIGHT_PX,
30
+ INLINE_DATE_GLYPH_INSET_TOP_PX,
31
+ INLINE_DATE_GLYPH_TILE_SIZE_PX,
32
+ ITEM_CAPTION_SPILL_GAP_PX,
33
+ ITEM_FOOTNOTE_INDICATOR_INSET_RIGHT_PX,
34
+ ITEM_FOOTNOTE_INDICATOR_STEP_PX,
35
+ ITEM_LINK_ICON_INSET_PX,
36
+ ITEM_LINK_ICON_TILE_SIZE_PX,
37
+ ITEM_STATUS_DOT_INSET_RIGHT_PX,
38
+ ITEM_STATUS_DOT_RADIUS_PX,
39
+ MIN_BAR_WIDTH_FOR_INLINE_DATE_PX,
40
+ } from './item-bar-geometry.js';
41
+ import type { BoundingBox, InlineDatePin, Point } from './types.js';
42
+
43
+ export interface ItemInlineDatePinInputs {
44
+ box: BoundingBox;
45
+ /** ISO date string from `after:DATE`, or undefined when no inline `after`. */
46
+ afterDate: string | undefined;
47
+ /** ISO date string from `before:DATE`, or undefined when no inline `before`. */
48
+ beforeDate: string | undefined;
49
+ hasLinkIcon: boolean;
50
+ /** Number of footnote indicators rendered in the bar's top-RIGHT cluster. */
51
+ footnoteCount: number;
52
+ }
53
+
54
+ /**
55
+ * Compute inline-date pin glyph placements for an item bar. Returns an
56
+ * empty array when neither `afterDate` nor `beforeDate` is set.
57
+ *
58
+ * Item bars participate in the narrow-bar spill family — when the bar is
59
+ * narrower than `MIN_BAR_WIDTH_FOR_INLINE_DATE_PX`, the `before:` glyph
60
+ * spills RIGHT of the bar (joining the status-dot / footnote spill
61
+ * column) and the `after:` glyph spills LEFT of the bar's leading edge
62
+ * so the side semantics stay readable.
63
+ */
64
+ export function computeItemInlineDatePins(opts: ItemInlineDatePinInputs): InlineDatePin[] {
65
+ const { box, afterDate, beforeDate, hasLinkIcon, footnoteCount } = opts;
66
+ if (!afterDate && !beforeDate) return [];
67
+
68
+ const pins: InlineDatePin[] = [];
69
+ const tileSize = INLINE_DATE_GLYPH_TILE_SIZE_PX;
70
+ const topY = box.y + INLINE_DATE_GLYPH_INSET_TOP_PX;
71
+ const spilled = box.width < MIN_BAR_WIDTH_FOR_INLINE_DATE_PX;
72
+
73
+ if (afterDate) {
74
+ const insideLeftX = hasLinkIcon
75
+ ? box.x +
76
+ ITEM_LINK_ICON_INSET_PX +
77
+ ITEM_LINK_ICON_TILE_SIZE_PX +
78
+ INLINE_DATE_GLYPH_GAP_PX
79
+ : box.x + INLINE_DATE_GLYPH_INSET_LEFT_PX;
80
+ const glyphLeft: Point = spilled
81
+ ? {
82
+ x: box.x - ITEM_CAPTION_SPILL_GAP_PX - tileSize,
83
+ y: topY,
84
+ }
85
+ : { x: insideLeftX, y: topY };
86
+ pins.push({
87
+ side: 'after',
88
+ isoDate: afterDate,
89
+ glyphTopLeft: glyphLeft,
90
+ glyphSize: tileSize,
91
+ spilled,
92
+ });
93
+ }
94
+
95
+ if (beforeDate) {
96
+ // Walk LEFT from the rightmost top-decoration slot:
97
+ // - rightmost footnote anchors at (box.right - INSET_RIGHT_PX)
98
+ // - leftmost footnote sits one step further left per extra digit
99
+ // - status dot left edge sits at (box.right - INSET_RIGHT - DOT_RADIUS)
100
+ // - inline-date glyph sits one INLINE_DATE_GLYPH_GAP_PX further left
101
+ const rightEdge = box.x + box.width;
102
+ let anchorRightX: number;
103
+ if (footnoteCount > 0) {
104
+ const leftmostFootnoteCenter =
105
+ rightEdge -
106
+ ITEM_FOOTNOTE_INDICATOR_INSET_RIGHT_PX -
107
+ (footnoteCount - 1) * ITEM_FOOTNOTE_INDICATOR_STEP_PX;
108
+ anchorRightX = leftmostFootnoteCenter - INLINE_DATE_GLYPH_GAP_PX;
109
+ } else {
110
+ const dotLeftEdge =
111
+ rightEdge - ITEM_STATUS_DOT_INSET_RIGHT_PX - ITEM_STATUS_DOT_RADIUS_PX;
112
+ anchorRightX = dotLeftEdge - INLINE_DATE_GLYPH_GAP_PX;
113
+ }
114
+ const insideRightX = anchorRightX - tileSize;
115
+ const glyphLeft: Point = spilled
116
+ ? {
117
+ x: rightEdge + ITEM_CAPTION_SPILL_GAP_PX,
118
+ y: topY,
119
+ }
120
+ : { x: insideRightX, y: topY };
121
+ pins.push({
122
+ side: 'before',
123
+ isoDate: beforeDate,
124
+ glyphTopLeft: glyphLeft,
125
+ glyphSize: tileSize,
126
+ spilled,
127
+ });
128
+ }
129
+
130
+ return pins;
131
+ }
132
+
133
+ export interface ContainerInlineDatePinInputs {
134
+ /** Bounding box that anchors the glyph corners. For styled groups and
135
+ * bracketed parallels this is the visible box; for unstyled groups
136
+ * and bare parallels it is the logical bounding box (leftmost child
137
+ * start, rightmost child end, top of the highest child row). */
138
+ box: BoundingBox;
139
+ afterDate: string | undefined;
140
+ beforeDate: string | undefined;
141
+ }
142
+
143
+ /**
144
+ * Compute inline-date pin glyph placements for a container (group or
145
+ * parallel). The glyphs sit flush to the box's top-LEFT (`after`) and
146
+ * top-RIGHT (`before`) corners with the standard inset; containers
147
+ * never spill (they always have room for a 12 px tile in their own
148
+ * top-decoration row).
149
+ */
150
+ export function computeContainerInlineDatePins(
151
+ opts: ContainerInlineDatePinInputs,
152
+ ): InlineDatePin[] {
153
+ const { box, afterDate, beforeDate } = opts;
154
+ if (!afterDate && !beforeDate) return [];
155
+
156
+ const pins: InlineDatePin[] = [];
157
+ const tileSize = INLINE_DATE_GLYPH_TILE_SIZE_PX;
158
+ const topY = box.y + INLINE_DATE_GLYPH_INSET_TOP_PX;
159
+
160
+ if (afterDate) {
161
+ pins.push({
162
+ side: 'after',
163
+ isoDate: afterDate,
164
+ glyphTopLeft: { x: box.x + INLINE_DATE_GLYPH_INSET_LEFT_PX, y: topY },
165
+ glyphSize: tileSize,
166
+ spilled: false,
167
+ });
168
+ }
169
+
170
+ if (beforeDate) {
171
+ pins.push({
172
+ side: 'before',
173
+ isoDate: beforeDate,
174
+ glyphTopLeft: {
175
+ x: box.x + box.width - INLINE_DATE_GLYPH_INSET_RIGHT_PX - tileSize,
176
+ y: topY,
177
+ },
178
+ glyphSize: tileSize,
179
+ spilled: false,
180
+ });
181
+ }
182
+
183
+ return pins;
184
+ }
185
+
186
+ /**
187
+ * Returns the first ISO date literal in `values`, or undefined when none
188
+ * is present. The validator enforces "at most one inline date per
189
+ * direction" so this lookup is unambiguous.
190
+ */
191
+ export function pickInlineDate(values: readonly string[]): string | undefined {
192
+ for (const v of values) {
193
+ if (/^\d{4}-\d{2}-\d{2}$/.test(v)) return v;
194
+ }
195
+ return undefined;
196
+ }
@@ -0,0 +1,271 @@
1
+ // Item-bar internal geometry — the "rails" inside an item rectangle:
2
+ // caption text (title + meta), label chips along the bottom, status
3
+ // dot at the upper-right, footnote indicators just left of the dot,
4
+ // and the link icon tile at the bottom-right.
5
+ //
6
+ // These metrics are shared between layout (label-chip placement,
7
+ // future content-aware width estimation) and renderer (text baselines
8
+ // + glyph positions). Keeping them in one module means a single edit
9
+ // re-skins every item bar consistently — the alternative is hunting
10
+ // matching `+ 12`s across two packages.
11
+ //
12
+ // Coordinate convention: every offset is **relative to the item's
13
+ // `box`** (`box.x` for X, `box.y` for Y), with `box.height` /
14
+ // `box.width` used as the "right edge" / "bottom edge" anchor where
15
+ // noted.
16
+
17
+ // ---- Caption (title + meta text) ---------------------------------
18
+
19
+ /** Horizontal inset (px) for the caption's left edge inside the bar. */
20
+ export const ITEM_CAPTION_INSET_X_PX = 12;
21
+
22
+ /**
23
+ * When the bar's title would overflow to the right, layout sets
24
+ * `textSpills` and the caption renders to the RIGHT of the bar; this
25
+ * is the gap (px) between the bar's right edge and the spilled
26
+ * caption.
27
+ */
28
+ export const ITEM_CAPTION_SPILL_GAP_PX = 6;
29
+
30
+ /** Baseline Y of the title text relative to the bar's top. */
31
+ export const ITEM_CAPTION_TITLE_BASELINE_OFFSET_PX = 20;
32
+
33
+ /** Baseline Y of the meta text (second line) relative to the bar's top. */
34
+ export const ITEM_CAPTION_META_BASELINE_OFFSET_PX = 38;
35
+
36
+ /** Font size (px) of the title text. */
37
+ export const ITEM_CAPTION_TITLE_FONT_SIZE_PX = 13;
38
+
39
+ /** Font size (px) of the meta text. */
40
+ export const ITEM_CAPTION_META_FONT_SIZE_PX = 11;
41
+
42
+ // ---- Status dot (upper-right glyph) ------------------------------
43
+
44
+ /** Distance (px) from the bar's right edge to the dot's center. */
45
+ export const ITEM_STATUS_DOT_INSET_RIGHT_PX = 12;
46
+
47
+ /** Distance (px) from the bar's top edge to the dot's center. */
48
+ export const ITEM_STATUS_DOT_INSET_TOP_PX = 12;
49
+
50
+ /** Radius (px) of the status dot. */
51
+ export const ITEM_STATUS_DOT_RADIUS_PX = 5;
52
+
53
+ // ---- Footnote indicators (numbers next to status dot) ------------
54
+
55
+ /**
56
+ * X offset (px from bar's right edge) where the rightmost footnote
57
+ * digit's anchor sits. Tuned to leave room for the status dot.
58
+ */
59
+ export const ITEM_FOOTNOTE_INDICATOR_INSET_RIGHT_PX = 22;
60
+
61
+ /** Baseline Y (px from bar's top) for footnote indicator digits. */
62
+ export const ITEM_FOOTNOTE_INDICATOR_BASELINE_OFFSET_PX = 14;
63
+
64
+ /**
65
+ * Horizontal step (px) between consecutive footnote indicators when
66
+ * an item carries more than one footnote — they walk LEFT from the
67
+ * status dot.
68
+ */
69
+ export const ITEM_FOOTNOTE_INDICATOR_STEP_PX = 8;
70
+
71
+ // ---- Link icon tile (bottom-right) -------------------------------
72
+
73
+ /** Side length (px) of the square link-icon tile. */
74
+ export const ITEM_LINK_ICON_TILE_SIZE_PX = 14;
75
+
76
+ /** Distance (px) from the bar's right/bottom edges to the tile's edge. */
77
+ export const ITEM_LINK_ICON_INSET_PX = 6;
78
+
79
+ // ---- Narrow-bar decoration spill --------------------------------
80
+
81
+ /**
82
+ * Horizontal gap (px) between consecutive decorations (status dot,
83
+ * link icon, footnote, title) when they spill into the column to
84
+ * the right of a bar that's too narrow to host them inside.
85
+ */
86
+ export const ITEM_DECORATION_SPILL_GAP_PX = 4;
87
+
88
+ /**
89
+ * Minimum bar width (px) needed to host the status dot inside the
90
+ * bar with its full inset. Below this, the dot would have to
91
+ * extend past the bar's left edge, so the dot spills into the
92
+ * caption column to the right of the bar instead.
93
+ */
94
+ export const MIN_BAR_WIDTH_FOR_DOT_PX = ITEM_STATUS_DOT_INSET_RIGHT_PX + ITEM_STATUS_DOT_RADIUS_PX;
95
+
96
+ /**
97
+ * Minimum bar width (px) needed to host the link-icon tile AND the
98
+ * status dot inside the bar with at least
99
+ * `ITEM_DECORATION_SPILL_GAP_PX` of breathing room between them.
100
+ * Below this, the link icon would visually collide with (or push
101
+ * into) the dot's column, so the icon spills out and renders ahead
102
+ * of the (also-spilled) title.
103
+ */
104
+ export const MIN_BAR_WIDTH_FOR_LINK_AND_DOT_PX =
105
+ ITEM_LINK_ICON_INSET_PX +
106
+ ITEM_LINK_ICON_TILE_SIZE_PX +
107
+ ITEM_DECORATION_SPILL_GAP_PX +
108
+ ITEM_STATUS_DOT_INSET_RIGHT_PX +
109
+ ITEM_STATUS_DOT_RADIUS_PX;
110
+
111
+ /**
112
+ * Minimum bar width (px) needed to host the footnote indicator at
113
+ * its inset-right position without overshooting the bar's left
114
+ * edge or colliding with a leading link icon. Approximate width
115
+ * for one digit is 8px (font-size 10, bold).
116
+ */
117
+ export const MIN_BAR_WIDTH_FOR_FOOTNOTE_PX = ITEM_FOOTNOTE_INDICATOR_INSET_RIGHT_PX + 1;
118
+
119
+ // ---- Inline-date glyph (after:DATE / before:DATE corner badge) ---
120
+ //
121
+ // Renders the renderer's built-in `calendar` SVG at top-LEFT (`after`)
122
+ // or top-RIGHT (`before`) of the entity bar. Sized as a sibling of
123
+ // the status dot and footnote indicators (smaller than the link tile)
124
+ // so the top-decoration row stays visually unified. See
125
+ // specs/rendering.md "Inline-date glyph".
126
+
127
+ /** Side length (px) of the inline-date calendar glyph tile. */
128
+ export const INLINE_DATE_GLYPH_TILE_SIZE_PX = 12;
129
+
130
+ /** Distance (px) from the bar's left edge to the glyph's left edge
131
+ * when the glyph sits at the leftmost top-decoration slot (no link
132
+ * icon present). */
133
+ export const INLINE_DATE_GLYPH_INSET_LEFT_PX = 6;
134
+
135
+ /** Distance (px) from the bar's right edge to the glyph's right edge
136
+ * when the glyph sits at the rightmost top-decoration slot (no
137
+ * status dot or footnote present). */
138
+ export const INLINE_DATE_GLYPH_INSET_RIGHT_PX = 6;
139
+
140
+ /** Distance (px) from the bar's top edge to the glyph's top edge. */
141
+ export const INLINE_DATE_GLYPH_INSET_TOP_PX = 5;
142
+
143
+ /** Horizontal gap (px) between the inline-date glyph and an adjacent
144
+ * decoration (link icon on the left, status dot / footnote indicator
145
+ * on the right). Matches the existing decoration spill gap so the
146
+ * top-decoration row reads as one rhythm. */
147
+ export const INLINE_DATE_GLYPH_GAP_PX = ITEM_DECORATION_SPILL_GAP_PX;
148
+
149
+ /**
150
+ * Minimum bar width (px) needed to host the inline-date glyph inside
151
+ * the bar. Below this, the glyph spills:
152
+ * - `before:` glyph spills RIGHT into the column the status dot
153
+ * uses (same family of decorations, same step pitch).
154
+ * - `after:` glyph spills LEFT of the bar's leading edge so the
155
+ * side semantics (after vs before) stay readable in the spill.
156
+ *
157
+ * The threshold reserves room for the glyph itself plus a small
158
+ * clearance from the link-icon column (when present) so the two
159
+ * glyphs don't overlap inside narrow bars.
160
+ */
161
+ export const MIN_BAR_WIDTH_FOR_INLINE_DATE_PX =
162
+ INLINE_DATE_GLYPH_INSET_LEFT_PX +
163
+ INLINE_DATE_GLYPH_TILE_SIZE_PX +
164
+ INLINE_DATE_GLYPH_GAP_PX +
165
+ INLINE_DATE_GLYPH_TILE_SIZE_PX +
166
+ INLINE_DATE_GLYPH_INSET_RIGHT_PX;
167
+
168
+ // ---- Label chips (along the bar's bottom) ------------------------
169
+
170
+ /** Height (px) of a label chip rectangle. */
171
+ export const LABEL_CHIP_HEIGHT_PX = 13;
172
+
173
+ /**
174
+ * Vertical gap (px) between the top of the bottom progress strip and
175
+ * the BOTTOM of a label chip. Keeps chips from touching the strip and
176
+ * gives a clear visual rail.
177
+ */
178
+ export const LABEL_CHIP_GAP_ABOVE_PROGRESS_STRIP_PX = 3;
179
+
180
+ /** Horizontal gap (px) between consecutive chips in a row. */
181
+ export const LABEL_CHIP_GAP_BETWEEN_PX = 4;
182
+
183
+ /**
184
+ * Vertical gap (px) between two stacked chip rows when chips spill
185
+ * outside the bar and form a multi-row column to the right.
186
+ */
187
+ export const LABEL_CHIP_ROW_GAP_PX = 4;
188
+
189
+ /**
190
+ * Vertical row pitch (px) for a stacked chip column — chip height +
191
+ * inter-row gap.
192
+ */
193
+ export const LABEL_CHIP_ROW_STEP_PX = LABEL_CHIP_HEIGHT_PX + LABEL_CHIP_ROW_GAP_PX;
194
+
195
+ /**
196
+ * Slack budget (fraction) applied ONCE per item when chips spill
197
+ * outside the bar. If a chip would overflow its row by less than
198
+ * `SPILL_ROW_SLACK_FRACTION × chip.width`, the row is allowed to
199
+ * stretch by the overflow amount and keep the chip on it instead of
200
+ * wrapping. This rescues "lonely chip" cases where one chip just
201
+ * barely overshoots; once the slack is consumed, no further row
202
+ * expansions happen for that item.
203
+ */
204
+ export const SPILL_ROW_SLACK_FRACTION = 0.25;
205
+
206
+ export interface ChipRowSample<T> {
207
+ id: T;
208
+ width: number;
209
+ }
210
+
211
+ export interface SpillChipPack<T> {
212
+ /** Rows ordered top-to-bottom — `rows[0]` sits at the chip
213
+ * column's top y, `rows[1]` one `LABEL_CHIP_ROW_STEP_PX` below,
214
+ * and so on. */
215
+ rows: ChipRowSample<T>[][];
216
+ /** True when the slack rule was used to keep an extra chip on
217
+ * row 0 (or whichever row was being filled when the overflow
218
+ * happened). At most one expansion per item. */
219
+ expanded: boolean;
220
+ }
221
+
222
+ /**
223
+ * Pack `chips` into rows for the SPILL column to the right of an
224
+ * item bar. Each row is capped at `barVisualWidth` (with gaps
225
+ * between chips). When a chip would overflow:
226
+ *
227
+ * - If the row is empty, place the chip anyway (a chip wider than
228
+ * the cap occupies its own row).
229
+ * - Else if the slack rule applies (`overflow ≤ 0.25 × chip.width`)
230
+ * AND the slack hasn't already been used for this item, expand
231
+ * the current row by `overflow` and keep the chip on it.
232
+ * - Else wrap the chip to a fresh row.
233
+ */
234
+ export function packSpillChips<T>(
235
+ chips: ChipRowSample<T>[],
236
+ barVisualWidth: number,
237
+ ): SpillChipPack<T> {
238
+ if (chips.length === 0) return { rows: [[]], expanded: false };
239
+ const rows: ChipRowSample<T>[][] = [[]];
240
+ let used = 0;
241
+ let rowCap = barVisualWidth;
242
+ let expanded = false;
243
+ for (const chip of chips) {
244
+ const row = rows[rows.length - 1];
245
+ const needed = (row.length === 0 ? 0 : LABEL_CHIP_GAP_BETWEEN_PX) + chip.width;
246
+ const wouldBe = used + needed;
247
+ if (wouldBe <= rowCap) {
248
+ row.push(chip);
249
+ used = wouldBe;
250
+ continue;
251
+ }
252
+ if (row.length === 0) {
253
+ row.push(chip);
254
+ used = chip.width;
255
+ continue;
256
+ }
257
+ const overflow = wouldBe - rowCap;
258
+ const slack = chip.width * SPILL_ROW_SLACK_FRACTION;
259
+ if (!expanded && overflow <= slack) {
260
+ row.push(chip);
261
+ used = wouldBe;
262
+ rowCap = wouldBe;
263
+ expanded = true;
264
+ continue;
265
+ }
266
+ rows.push([chip]);
267
+ used = chip.width;
268
+ rowCap = barVisualWidth;
269
+ }
270
+ return { rows, expanded };
271
+ }