@transitrix/diagrams 1.8.2 → 1.8.4

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.
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Brand default-theme regression tests (hub issue #548).
3
+ *
4
+ * Locks in the three-role brand mapping from `brand/transitrix_brand.md`:
5
+ * - Petrol = structure (node/edge stroke) and hierarchy depth (fill tint).
6
+ * - A depth ramp never switches hue — only lightness/saturation move.
7
+ * - Text stays WCAG-AA readable against every fill it can be drawn on.
8
+ * `hc` (VS Code high-contrast) is intentionally excluded — it's an
9
+ * accessibility override, not one of the three brand-contract themes.
10
+ */
11
+ import { describe, expect, it } from 'vitest';
12
+ import {
13
+ BRAND,
14
+ BRAND_EMPHASIS,
15
+ LAYER_COLORS,
16
+ LEVEL_COLORS,
17
+ MATURITY_COLORS,
18
+ TREE_MATURITY_COLORS,
19
+ STRUCTURAL,
20
+ TREE_LEVEL_COLORS,
21
+ } from '../tokens.js';
22
+
23
+ function hexToRgb(hex: string): [number, number, number] {
24
+ const n = hex.replace('#', '');
25
+ return [0, 2, 4].map((i) => parseInt(n.slice(i, i + 2), 16)) as [number, number, number];
26
+ }
27
+
28
+ function relativeLuminance([r, g, b]: [number, number, number]): number {
29
+ const f = (v: number): number => {
30
+ const c = v / 255;
31
+ return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
32
+ };
33
+ const [R, G, B] = [f(r), f(g), f(b)];
34
+ return 0.2126 * R + 0.7152 * G + 0.0722 * B;
35
+ }
36
+
37
+ /** WCAG 2.x contrast ratio between two hex colors (1..21). */
38
+ function contrast(a: string, b: string): number {
39
+ const la = relativeLuminance(hexToRgb(a));
40
+ const lb = relativeLuminance(hexToRgb(b));
41
+ const [hi, lo] = la > lb ? [la, lb] : [lb, la];
42
+ return (hi + 0.05) / (lo + 0.05);
43
+ }
44
+
45
+ /** Hue in degrees (0-360) from a hex color; undefined (grey) hues return -1. */
46
+ function hue(hex: string): number {
47
+ const [r, g, b] = hexToRgb(hex).map((v) => v / 255);
48
+ const max = Math.max(r, g, b), min = Math.min(r, g, b);
49
+ const delta = max - min;
50
+ if (delta < 0.001) return -1; // achromatic
51
+ let h: number;
52
+ if (max === r) h = ((g - b) / delta) % 6;
53
+ else if (max === g) h = (b - r) / delta + 2;
54
+ else h = (r - g) / delta + 4;
55
+ h *= 60;
56
+ return h < 0 ? h + 360 : h;
57
+ }
58
+
59
+ const PETROL_HUE = hue(BRAND.petrol);
60
+ const HUE_TOLERANCE = 6; // degrees — rounding slop from hand-tuned hex values
61
+
62
+ function expectSameHueFamily(hexes: string[], label: string): void {
63
+ for (const hex of hexes) {
64
+ const h = hue(hex);
65
+ const diff = Math.min(Math.abs(h - PETROL_HUE), 360 - Math.abs(h - PETROL_HUE));
66
+ expect(diff, `${label} ${hex} should stay in the petrol hue family (got hue ${h.toFixed(1)}, petrol is ${PETROL_HUE.toFixed(1)})`).toBeLessThanOrEqual(HUE_TOLERANCE);
67
+ }
68
+ }
69
+
70
+ // Minimum AA text-contrast ratios this design targets. Primary/secondary text
71
+ // is small (10-12px) so we hold the full 4.5:1 normal-text bar for the name
72
+ // label, and the calibrated ~4.0 bar the pre-brand palette already shipped
73
+ // for the muted secondary/id label (see brand-ramp calibration in PR #548).
74
+ const MIN_PRIMARY_CONTRAST = 4.5;
75
+ const MIN_SECONDARY_CONTRAST = 4.0;
76
+
77
+ describe('brand default theme (#548) — structure is petrol', () => {
78
+ it('nodeStroke and edgeStroke are brand petrol in the light theme', () => {
79
+ expect(STRUCTURAL.nodeStroke.light).toBe(BRAND.petrol);
80
+ expect(STRUCTURAL.edgeStroke.light).toBe(BRAND.petrol);
81
+ });
82
+
83
+ it('nodeStroke/edgeStroke stay in the petrol hue family in the dark theme', () => {
84
+ expectSameHueFamily([STRUCTURAL.nodeStroke.dark, STRUCTURAL.edgeStroke.dark], 'dark stroke');
85
+ });
86
+ });
87
+
88
+ describe('brand default theme (#548) — tint depth never switches hue', () => {
89
+ it('LEVEL_COLORS light ramp stays in the petrol hue family', () => {
90
+ expectSameHueFamily([...LEVEL_COLORS.light], 'LEVEL light');
91
+ });
92
+ it('LEVEL_COLORS dark ramp stays in the petrol hue family', () => {
93
+ expectSameHueFamily([...LEVEL_COLORS.dark], 'LEVEL dark');
94
+ });
95
+ it('LAYER_COLORS (DGCA/DGA columns) stay in the petrol hue family, both themes', () => {
96
+ const keys = ['driver', 'factor', 'goal', 'change', 'activity'] as const;
97
+ expectSameHueFamily(keys.map((k) => LAYER_COLORS[k].light), 'LAYER light');
98
+ expectSameHueFamily(keys.map((k) => LAYER_COLORS[k].dark), 'LAYER dark');
99
+ });
100
+ it('TREE_LEVEL_COLORS (capability map bands) stay in the petrol hue family, both themes', () => {
101
+ const keys = ['band0', 'band1', 'band2'] as const;
102
+ expectSameHueFamily(keys.map((k) => TREE_LEVEL_COLORS[k].light), 'BAND light');
103
+ expectSameHueFamily(keys.map((k) => TREE_LEVEL_COLORS[k].dark), 'BAND dark');
104
+ });
105
+ });
106
+
107
+ describe('brand default theme (#548) — WCAG-AA text-on-fill contrast', () => {
108
+ function checkFills(label: string, fills: string[], textPrimary: string, textSecondary: string): void {
109
+ for (const fill of fills) {
110
+ expect(contrast(fill, textPrimary), `${label} ${fill} vs text-primary`).toBeGreaterThanOrEqual(MIN_PRIMARY_CONTRAST);
111
+ expect(contrast(fill, textSecondary), `${label} ${fill} vs text-secondary`).toBeGreaterThanOrEqual(MIN_SECONDARY_CONTRAST);
112
+ }
113
+ }
114
+
115
+ it('LEVEL_COLORS — every slot, both themes', () => {
116
+ checkFills('LEVEL light', [...LEVEL_COLORS.light], STRUCTURAL.textPrimary.light, STRUCTURAL.textSecondary.light);
117
+ checkFills('LEVEL dark', [...LEVEL_COLORS.dark], STRUCTURAL.textPrimary.dark, STRUCTURAL.textSecondary.dark);
118
+ });
119
+
120
+ it('LAYER_COLORS — every column, both themes', () => {
121
+ const keys = ['driver', 'factor', 'goal', 'change', 'activity'] as const;
122
+ checkFills('LAYER light', keys.map((k) => LAYER_COLORS[k].light), STRUCTURAL.textPrimary.light, STRUCTURAL.textSecondary.light);
123
+ checkFills('LAYER dark', keys.map((k) => LAYER_COLORS[k].dark), STRUCTURAL.textPrimary.dark, STRUCTURAL.textSecondary.dark);
124
+ });
125
+
126
+ it('TREE_LEVEL_COLORS — every band, both themes', () => {
127
+ const keys = ['band0', 'band1', 'band2'] as const;
128
+ checkFills('BAND light', keys.map((k) => TREE_LEVEL_COLORS[k].light), STRUCTURAL.textPrimary.light, STRUCTURAL.textSecondary.light);
129
+ checkFills('BAND dark', keys.map((k) => TREE_LEVEL_COLORS[k].dark), STRUCTURAL.textPrimary.dark, STRUCTURAL.textSecondary.dark);
130
+ });
131
+
132
+ it('textPrimary/textSecondary stay readable against the shell background', () => {
133
+ expect(contrast(STRUCTURAL.textPrimary.light, '#ffffff')).toBeGreaterThanOrEqual(MIN_PRIMARY_CONTRAST);
134
+ expect(contrast(STRUCTURAL.textPrimary.dark, '#0a1628')).toBeGreaterThanOrEqual(MIN_PRIMARY_CONTRAST);
135
+ });
136
+ });
137
+
138
+ describe('brand default theme (#548) — amber/orange emphasis stays distinct from functional colors', () => {
139
+ it('does not reuse brand amber/orange for functional status', () => {
140
+ // FUNCTIONAL warning/error must remain visually distinct from the brand
141
+ // accents so a red error is never confused with brand orange, per
142
+ // brand/transitrix_brand.md "Don't reuse brand orange as semantic error".
143
+ expect(BRAND_EMPHASIS.orange.light).toBe(BRAND.orange);
144
+ expect(BRAND_EMPHASIS.amber.light).toBe(BRAND.amber);
145
+ });
146
+
147
+ it('critical-path emphasis tint pairs with the orange stroke, both themes', () => {
148
+ expect(contrast(BRAND_EMPHASIS.orange.light, BRAND_EMPHASIS.orangeTint.light)).toBeGreaterThan(1.5);
149
+ expect(contrast(BRAND_EMPHASIS.orange.dark, BRAND_EMPHASIS.orangeTint.dark)).toBeGreaterThan(1.5);
150
+ });
151
+ });
152
+
153
+ describe('maturity Likert ramp — one harmonious scale, white-label contrast', () => {
154
+ // .maturity-pill / tree-maturity badges hardcode white label text
155
+ // (capability-map-preview.ts, render-capability-tree.ts) regardless of
156
+ // theme, so every step needs AA (light/dark) or AAA (hc, since VS Code
157
+ // high-contrast mode exists specifically to demand stronger contrast)
158
+ // against white — not against the page's own text-primary/secondary.
159
+ const MIN_WHITE_CONTRAST_AA = 4.5;
160
+ const MIN_WHITE_CONTRAST_AAA = 7;
161
+
162
+ it('MATURITY_COLORS — every step reads white text at AA, light + dark', () => {
163
+ for (const hex of MATURITY_COLORS.light) {
164
+ expect(contrast(hex, '#ffffff'), `MATURITY light ${hex} vs white`).toBeGreaterThanOrEqual(MIN_WHITE_CONTRAST_AA);
165
+ }
166
+ for (const hex of MATURITY_COLORS.dark) {
167
+ expect(contrast(hex, '#ffffff'), `MATURITY dark ${hex} vs white`).toBeGreaterThanOrEqual(MIN_WHITE_CONTRAST_AA);
168
+ }
169
+ });
170
+
171
+ it('MATURITY_COLORS hc — every step reads white text at AAA', () => {
172
+ for (const hex of MATURITY_COLORS.hc) {
173
+ expect(contrast(hex, '#ffffff'), `MATURITY hc ${hex} vs white`).toBeGreaterThanOrEqual(MIN_WHITE_CONTRAST_AAA);
174
+ }
175
+ });
176
+
177
+ it('TREE_MATURITY_COLORS is the same harmonious ramp as MATURITY_COLORS', () => {
178
+ // Previously a divergent DSM-matching pink/yellow/blue set (plus a grey
179
+ // L1, an odd "no signal" hue for the worst rating) — "maturity" now
180
+ // means the same colors everywhere it's shown.
181
+ expect(TREE_MATURITY_COLORS.light).toEqual(MATURITY_COLORS.light);
182
+ expect(TREE_MATURITY_COLORS.dark).toEqual(MATURITY_COLORS.dark);
183
+ expect(TREE_MATURITY_COLORS.hc).toEqual(MATURITY_COLORS.hc);
184
+ });
185
+ });
@@ -1,4 +1,4 @@
1
1
  export type { AdaptiveTokens } from './tokens.js';
2
- export { BRAND, FUNCTIONAL, LAYER_COLORS, LEVEL_COLORS, MATURITY_COLORS, TREE_LEVEL_COLORS, TREE_MATURITY_COLORS, STRUCTURAL, TYPOGRAPHY, CSS_VAR, getBaseResetCss } from './tokens.js';
2
+ export { BRAND, BRAND_EMPHASIS, FUNCTIONAL, LAYER_COLORS, LEVEL_COLORS, MATURITY_COLORS, TREE_LEVEL_COLORS, TREE_MATURITY_COLORS, STRUCTURAL, TYPOGRAPHY, CSS_VAR, getBaseResetCss } from './tokens.js';
3
3
  export type { ThemeId } from './themes.js';
4
4
  export { generateWebviewCss, generateSvgEmbedCss } from './themes.js';
@@ -5,6 +5,7 @@ import {
5
5
  TREE_LEVEL_COLORS,
6
6
  TREE_MATURITY_COLORS,
7
7
  STRUCTURAL,
8
+ BRAND_EMPHASIS,
8
9
  TYPOGRAPHY,
9
10
  CSS_VAR,
10
11
  getBaseResetCss,
@@ -106,6 +107,9 @@ function diagramVars(variant: 'light' | 'dark' | 'hc'): string {
106
107
  `${CSS_VAR.maturity3}:${mat[2]}`,
107
108
  `${CSS_VAR.maturity4}:${mat[3]}`,
108
109
  `${CSS_VAR.maturity5}:${mat[4]}`,
110
+ `${CSS_VAR.brandAmber}:${BRAND_EMPHASIS.amber[variant]}`,
111
+ `${CSS_VAR.brandOrange}:${BRAND_EMPHASIS.orange[variant]}`,
112
+ `${CSS_VAR.brandOrangeTint}:${BRAND_EMPHASIS.orangeTint[variant]}`,
109
113
  ].join(';') + ';' + levelVars + treeVars;
110
114
  }
111
115
 
@@ -1,4 +1,4 @@
1
- /** Transitrix brand palette. */
1
+ /** Transitrix brand palette (`brand/transitrix_brand.md` — canonical). */
2
2
  export const BRAND = {
3
3
  petrol: '#004d67',
4
4
  amber: '#ffaf00',
@@ -13,61 +13,109 @@ export const FUNCTIONAL = {
13
13
  info: '#1d6fa8',
14
14
  } as const;
15
15
 
16
- /** Fill colors for FGCA/DGCA notation columns. */
16
+ /**
17
+ * Amber/orange "author emphasis" accents, theme-adjusted for contrast against
18
+ * each theme's background (dark theme gets the brand hues lightened per
19
+ * `brand/transitrix_brand.md` §Themes: "brand colours slightly desaturated
20
+ * for contrast on dark surfaces"). `orangeTint` is the light emphasis-fill
21
+ * paired with an `orange` stroke (e.g. Activities critical-path nodes).
22
+ * `hc` intentionally falls back to the plain BRAND hex — VS Code
23
+ * high-contrast mode prioritises accessibility overrides over brand fidelity.
24
+ */
25
+ export const BRAND_EMPHASIS = {
26
+ amber: { light: BRAND.amber, dark: '#ffc83d', hc: BRAND.amber },
27
+ orange: { light: BRAND.orange, dark: '#ff7542', hc: BRAND.orange },
28
+ orangeTint: { light: '#ffeee5', dark: '#432114', hc: '#ffeee5' },
29
+ } as const;
30
+
31
+ /**
32
+ * Fill colors for FGCA/DGCA notation columns — a petrol tint per stage
33
+ * (Driver → Goal → Change → Activity), deepening left to right like the
34
+ * Goals-tree level ladder below. Petrol tint = structural position, never a
35
+ * hue switch, per the brand's "structure via petrol" role mapping.
36
+ */
17
37
  export const LAYER_COLORS = {
18
- driver: { light: '#fef3c7', dark: '#292108', hc: '#f59e0b' },
19
- factor: { light: '#fef3c7', dark: '#292108', hc: '#f59e0b' },
20
- goal: { light: '#e0e7ff', dark: '#1e1b4b', hc: '#818cf8' },
21
- change: { light: '#dbeafe', dark: '#0c2042', hc: '#60a5fa' },
22
- activity: { light: '#d4edda', dark: '#0a2414', hc: '#4ade80' },
38
+ driver: { light: '#eaf3f6', dark: '#17262c', hc: '#f59e0b' },
39
+ factor: { light: '#eaf3f6', dark: '#17262c', hc: '#f59e0b' },
40
+ goal: { light: '#d9ecf2', dark: '#192f37', hc: '#818cf8' },
41
+ change: { light: '#c7e5ef', dark: '#1a3842', hc: '#60a5fa' },
42
+ activity: { light: '#b4e0ee', dark: '#1a414e', hc: '#4ade80' },
23
43
  } as const;
24
44
 
25
- /** Level fill colors for Goals tree nodes — 8 slots, cycled by level index. */
45
+ /**
46
+ * Level fill colors for Goals tree nodes — 8 slots, cycled by level index.
47
+ * A single-hue petrol tint ramp (level-0 lightest/root → level-7 deepest);
48
+ * hue never switches with depth. Saturation/lightness tuned so text-primary
49
+ * and text-secondary keep at least their pre-brand contrast ratio against
50
+ * every slot — see `theme/__tests__/tokens.test.ts`.
51
+ */
26
52
  export const LEVEL_COLORS = {
27
- light: ['#dbeafe', '#e0e7ff', '#d4edda', '#fef3c7', '#fce7f3', '#e0f2fe', '#f3e8ff', '#fef9c3'],
28
- dark: ['#0c2042', '#1e1b4b', '#0a2414', '#292108', '#2a0c1f', '#071e2e', '#1a0c33', '#2a2107'],
53
+ light: ['#eef4f7', '#e6f1f4', '#dfedf1', '#d7e9ef', '#cee6ed', '#c6e2ec', '#bfe0eb', '#b7deeb'],
54
+ dark: ['#152328', '#16292f', '#172e36', '#18333d', '#183944', '#183f4c', '#184554', '#174b5c'],
29
55
  hc: ['#60a5fa', '#818cf8', '#4ade80', '#f59e0b', '#f472b6', '#38bdf8', '#a78bfa', '#facc15'],
30
56
  } as const;
31
57
 
32
- /** Structural diagram colors (nodes, edges, text). */
58
+ /**
59
+ * Structural diagram colors (nodes, edges, text). nodeStroke/edgeStroke are
60
+ * brand petrol — "structure via petrol" per the brand's role mapping.
61
+ * textPrimary is a dark petrol ink (light theme) / near-white petrol-tinted
62
+ * (dark theme); textSecondary stays a muted grey with a faint petrol lean.
63
+ * `hc` is untouched — VS Code high-contrast accessibility overrides win over
64
+ * brand fidelity there.
65
+ */
33
66
  export const STRUCTURAL = {
34
- nodeStroke: { light: '#94a3b8', dark: '#475569', hc: '#e2e8f0' },
35
- edgeStroke: { light: '#94a3b8', dark: '#475569', hc: '#e2e8f0' },
36
- textPrimary: { light: '#1e293b', dark: '#f1f5f9', hc: '#ffffff' },
37
- textSecondary: { light: '#64748b', dark: '#94a3b8', hc: '#cbd5e1' },
38
- headerText: { light: '#374151', dark: '#e5e7eb', hc: '#ffffff' },
67
+ nodeStroke: { light: BRAND.petrol, dark: '#53a9c6', hc: '#e2e8f0' },
68
+ edgeStroke: { light: BRAND.petrol, dark: '#53a9c6', hc: '#e2e8f0' },
69
+ textPrimary: { light: '#0d2b35', dark: '#edf5f8', hc: '#ffffff' },
70
+ textSecondary: { light: '#516970', dark: '#adc8d1', hc: '#cbd5e1' },
71
+ headerText: { light: '#0d2b35', dark: '#edf5f8', hc: '#ffffff' },
39
72
  } as const;
40
73
 
41
74
  /**
42
- * Maturity scale fill colors — Likert 1..5, danger→success.
75
+ * Maturity scale fill colors — Likert 1..5, danger→success. A single
76
+ * harmonious ramp: consistent saturation curve, hue stepping smoothly
77
+ * red→orange→gold→yellow-green→green (never jumping registers the way the
78
+ * previous per-theme picks did), tuned so the badge's hardcoded white label
79
+ * text (`.maturity-pill`, capability-map-preview.ts) stays ≥4.5:1 AA at
80
+ * every step. Same ramp for light/dark — these are small solid badges, not
81
+ * background tints, so theme brightness doesn't change the contrast need.
82
+ * `hc` pushes the same hues darker/more saturated for AAA (≥7:1), since VS
83
+ * Code high-contrast mode exists specifically to demand stronger contrast.
43
84
  * Used by Capability Map and any future maturity-based notation.
44
85
  */
45
86
  export const MATURITY_COLORS = {
46
- light: ['#b91c1c', '#d97706', '#ca8a04', '#65a30d', '#15803d'],
47
- dark: ['#7f1d1d', '#92400e', '#854d0e', '#3f6212', '#14532d'],
48
- hc: ['#f87171', '#fb923c', '#facc15', '#a3e635', '#4ade80'],
87
+ light: ['#bf2518', '#b05911', '#8d7011', '#407d21', '#237b48'],
88
+ dark: ['#bf2518', '#b05911', '#8d7011', '#407d21', '#237b48'],
89
+ hc: ['#a0190d', '#864109', '#5a4607', '#316317', '#155630'],
49
90
  } as const;
50
91
 
51
92
  /**
52
- * DSM-matching capability tree node fill colors, grouped by depth band.
53
- * band0: depth 0–2 (pink)
54
- * band1: depth 3–4 (yellow)
55
- * band2: depth 5+ (blue)
93
+ * Capability tree node fill colors, grouped by depth band — a 3-step petrol
94
+ * tint (shallow → deep), same "petrol tint = structural depth" rule as
95
+ * LEVEL_COLORS above. Previously a DSM-matching pink/yellow/blue scheme;
96
+ * brand/transitrix_brand.md ("Components") anticipates DSM adopting the same
97
+ * shared color tokens, so Studio moving first is convergence, not drift.
98
+ * band0: depth 0–2 (shallowest)
99
+ * band1: depth 3–4
100
+ * band2: depth 5+ (deepest)
56
101
  */
57
102
  export const TREE_LEVEL_COLORS = {
58
- band0: { light: '#fee0e0', dark: '#3d0f0f', hc: '#ff9999' },
59
- band1: { light: '#ffffcb', dark: '#3a3500', hc: '#ffff88' },
60
- band2: { light: '#c2f0ff', dark: '#003d4d', hc: '#66ccff' },
103
+ band0: { light: '#e6f1f4', dark: '#152b32', hc: '#ff9999' },
104
+ band1: { light: '#d0e9f1', dark: '#153b47', hc: '#ffff88' },
105
+ band2: { light: '#b5e3f2', dark: '#114c5f', hc: '#66ccff' },
61
106
  } as const;
62
107
 
63
108
  /**
64
- * DSM-matching maturity badge fills for the capability tree (L1–L5).
65
- * Distinct from MATURITY_COLORS which drives the cards / compliance views.
109
+ * Maturity badge fills for the capability tree (L1–L5). Same ramp as
110
+ * MATURITY_COLORS — previously a separate DSM-matching pink/yellow/blue set
111
+ * that didn't even share L1's meaning (grey = lowest maturity, an odd
112
+ * "no signal" hue for the worst rating) and had white-label contrast as low
113
+ * as 1.07:1 in `hc`. One harmonious Likert ramp for "maturity" everywhere.
66
114
  */
67
115
  export const TREE_MATURITY_COLORS = {
68
- light: ['#c1c1c1', '#ff3d67', '#ff9a59', '#fdef59', '#83cca3'],
69
- dark: ['#555555', '#cc1040', '#d06020', '#c8c000', '#4d9970'],
70
- hc: ['#cccccc', '#ff6699', '#ffbb77', '#ffff44', '#88ddaa'],
116
+ light: MATURITY_COLORS.light,
117
+ dark: MATURITY_COLORS.dark,
118
+ hc: MATURITY_COLORS.hc,
71
119
  } as const;
72
120
 
73
121
  /**
@@ -158,6 +206,9 @@ export const CSS_VAR = {
158
206
  treeMaturity3: '--ts-tree-maturity-3',
159
207
  treeMaturity4: '--ts-tree-maturity-4',
160
208
  treeMaturity5: '--ts-tree-maturity-5',
209
+ brandAmber: '--ts-brand-amber',
210
+ brandOrange: '--ts-brand-orange',
211
+ brandOrangeTint: '--ts-brand-orange-tint',
161
212
  } as const;
162
213
 
163
214
  export function getBaseResetCss(): string {
@@ -1,13 +1,17 @@
1
1
  import { describe, expect, it } from 'vitest';
2
2
  import {
3
3
  layoutCenteredEntityText,
4
+ layoutLeafBlockText,
5
+ layoutHeaderBlockText,
4
6
  LINE_H_PRIMARY,
5
7
  LINE_H_SECONDARY,
8
+ TEXT_MARGIN_Y,
6
9
  maxCharsForInnerWidth,
7
10
  ROW_GROUP_GAP,
8
11
  wrapWords,
9
12
  wrapTextLines,
10
13
  } from '../entity-text-layout.js';
14
+ import { ENTITY_NODE_SIZE } from '../../node-size-presets.js';
11
15
 
12
16
  describe('entity-text-layout', () => {
13
17
  it('wrapWords respects max lines and truncates with ellipsis', () => {
@@ -71,3 +75,108 @@ describe('entity-text-layout', () => {
71
75
  expect(lines.every((l) => l.length <= 10)).toBe(true);
72
76
  });
73
77
  });
78
+
79
+ // Approximate half-extent (px) of each text class's glyphs around its centre
80
+ // y — font-size / 2, the same heuristic the render-blocks overlap regression
81
+ // test (#419) uses. Used below to assert text never visually crosses the box
82
+ // border, not just that the *nominal* line-height budget fits.
83
+ const HALF_EXTENT: Record<string, number> = {
84
+ 'text-primary': 6, // 12px font
85
+ 'text-secondary': 6, // 11px font, rounded up
86
+ 'text-id': 5, // 10px font
87
+ };
88
+
89
+ describe('entity text layout — never overflows the box, always keeps padding', () => {
90
+ const PRESETS = Object.entries(ENTITY_NODE_SIZE); // compact/normal/wide
91
+ const NAMES = [
92
+ 'Short',
93
+ 'Achieve full GDPR & NIS2 compliance',
94
+ 'A name so long it would need three or more lines to render in full without any height limit at all',
95
+ ];
96
+
97
+ function assertNoOverflowAndPadded(
98
+ specs: { cls: string; y: number }[],
99
+ boxTop: number,
100
+ boxBottom: number,
101
+ ): void {
102
+ for (const s of specs) {
103
+ const half = HALF_EXTENT[s.cls] ?? 6;
104
+ expect(s.y - half).toBeGreaterThanOrEqual(boxTop);
105
+ expect(s.y + half).toBeLessThanOrEqual(boxBottom);
106
+ }
107
+ }
108
+
109
+ for (const [presetName, size] of PRESETS) {
110
+ for (const withType of [false, true]) {
111
+ for (const name of NAMES) {
112
+ it(`layoutCenteredEntityText: ${presetName} preset, type=${withType}, name="${name.slice(0, 20)}…" stays inside the box`, () => {
113
+ const boxY = 0;
114
+ const specs = layoutCenteredEntityText({
115
+ boxX: 0,
116
+ boxY,
117
+ boxWidth: size.width,
118
+ boxHeight: size.height,
119
+ name,
120
+ type: withType ? 'Strategic Goal' : undefined,
121
+ id: 'GOAL-EU-COMPLIANCE-1',
122
+ nameMaxLines: 2,
123
+ idMaxLines: 1,
124
+ });
125
+ assertNoOverflowAndPadded(specs, boxY, boxY + size.height);
126
+ });
127
+ }
128
+ }
129
+ }
130
+
131
+ it('reproduces the reported case (wide preset, 2-line name + type + long id) with real padding on all sides', () => {
132
+ const size = ENTITY_NODE_SIZE.normal;
133
+ const boxY = 100;
134
+ const specs = layoutCenteredEntityText({
135
+ boxX: 0,
136
+ boxY,
137
+ boxWidth: size.width,
138
+ boxHeight: size.height,
139
+ name: 'Achieve full GDPR & NIS2 compliance',
140
+ type: 'Project Goal',
141
+ id: 'GOAL-EU-COMPLIANCE-1',
142
+ nameMaxLines: 2,
143
+ idMaxLines: 1,
144
+ });
145
+ const nameLines = specs.filter((s) => s.cls === 'text-primary');
146
+ expect(nameLines.length).toBe(2); // normal preset is tall enough to keep both lines
147
+ assertNoOverflowAndPadded(specs, boxY, boxY + size.height);
148
+ // Explicit padding, not just "doesn't cross the border".
149
+ const firstTop = Math.min(...specs.map((s) => s.y - (HALF_EXTENT[s.cls] ?? 6)));
150
+ const lastBottom = Math.max(...specs.map((s) => s.y + (HALF_EXTENT[s.cls] ?? 6)));
151
+ expect(firstTop - boxY).toBeGreaterThanOrEqual(TEXT_MARGIN_Y);
152
+ expect(boxY + size.height - lastBottom).toBeGreaterThanOrEqual(TEXT_MARGIN_Y);
153
+ });
154
+
155
+ it('layoutLeafBlockText stays inside the box for compact preset with a long name and id', () => {
156
+ const size = ENTITY_NODE_SIZE.compact;
157
+ const boxY = 0;
158
+ const specs = layoutLeafBlockText({
159
+ boxX: 0,
160
+ boxY,
161
+ boxWidth: size.width,
162
+ boxHeight: size.height,
163
+ name: 'Personal data records that linger after consent withdrawal across many systems and archives',
164
+ id: 'VERY_LONG_BLOCK_IDENTIFIER_WITH_MANY_SEGMENTS_AND_MORE',
165
+ });
166
+ assertNoOverflowAndPadded(specs, boxY, boxY + size.height);
167
+ });
168
+
169
+ it('layoutHeaderBlockText stays inside a short header strip', () => {
170
+ const boxY = 0;
171
+ const headerHeight = 28;
172
+ const specs = layoutHeaderBlockText({
173
+ boxX: 0,
174
+ boxY,
175
+ boxWidth: 250,
176
+ headerHeight,
177
+ name: 'A fairly long container name here',
178
+ id: 'VERY_LONG_CONTAINER_IDENTIFIER',
179
+ });
180
+ assertNoOverflowAndPadded(specs, boxY, boxY + headerHeight);
181
+ });
182
+ });