@sentropic/diagram-canvas 0.3.0 → 0.3.2

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.
package/README.md CHANGED
@@ -346,8 +346,8 @@ empty penalty, hysteresis); absent or empty, the DS defaults apply.
346
346
  `cameraFit` frames the scene bounds on both axes against the 16:9 fit box
347
347
  (`fitW = viewW`, `fitH = min(viewW × 9/16, 0.85 × windowH)`), never above the
348
348
  maximum display scale (0.62: readout 100 %, a card renders at about
349
- 285 × 124 CSS px) and holds a fit at the readability floor (0.45: an 18 px
350
- edge label renders at 8.1 CSS px) when the drawing is larger, reporting
349
+ 285 × 124 CSS px) and holds a fit at the readability floor (0.30: an 18 px
350
+ edge label renders at 5.4 CSS px) when the drawing is larger, reporting
351
351
  `pans`; `clampZoom` and `zoomReadout` complete it. Given a `zoomQuantum`, the
352
352
  applied fit is floored to that grid, never rounded up past the fit box;
353
353
  `sceneFit` passes `FIT_QUANTUM` (1e-3), and a scene host prints that one zoom
@@ -39,7 +39,7 @@
39
39
  "weight": 400,
40
40
  "lineHeight": 1.2222222222222223
41
41
  },
42
- "bodyInsetFromBar": 14,
42
+ "bodyInsetFromBar": 10,
43
43
  "ruleHeight": 1,
44
44
  "ruleMargin": 4,
45
45
  "ruleInsetStart": 16,
@@ -105,8 +105,8 @@
105
105
  "headerTextInset": 154,
106
106
  "collapsedWidth": 352,
107
107
  "collapsedHeight": 154,
108
- "collapsedInset": 16,
109
- "collapsedSubtitleMarginInline": 16,
108
+ "collapsedInset": 12,
109
+ "collapsedSubtitleMarginInline": 12,
110
110
  "allocatedLines": {
111
111
  "kicker": 1,
112
112
  "title": 1,
@@ -140,17 +140,17 @@
140
140
  "title": [
141
141
  {
142
142
  "text": "Title",
143
- "x": 206,
143
+ "x": 68,
144
144
  "baseline": 45.203125,
145
145
  "size": 32,
146
146
  "weight": 700,
147
147
  "secondary": false,
148
- "anchor": "middle"
148
+ "anchor": "start"
149
149
  }
150
150
  ],
151
151
  "headerBlockHeight": 52,
152
- "bodyX": 14,
153
- "bodyWidth": 330,
152
+ "bodyX": 10,
153
+ "bodyWidth": 334,
154
154
  "bodyArea": {
155
155
  "top": 66,
156
156
  "bottom": 146
@@ -158,7 +158,7 @@
158
158
  "body": [
159
159
  {
160
160
  "text": "Body",
161
- "x": 179,
161
+ "x": 177,
162
162
  "baseline": 112.40625,
163
163
  "size": 24,
164
164
  "weight": 400,
@@ -198,23 +198,23 @@
198
198
  "kicker": [
199
199
  {
200
200
  "text": "KICKER",
201
- "x": 237,
201
+ "x": 92,
202
202
  "baseline": 32,
203
203
  "size": 22,
204
204
  "weight": 400,
205
205
  "secondary": true,
206
- "anchor": "middle"
206
+ "anchor": "start"
207
207
  }
208
208
  ],
209
209
  "title": [
210
210
  {
211
211
  "text": "Title",
212
- "x": 237,
212
+ "x": 92,
213
213
  "baseline": 70.59375,
214
214
  "size": 32,
215
215
  "weight": 700,
216
216
  "secondary": false,
217
- "anchor": "middle"
217
+ "anchor": "start"
218
218
  }
219
219
  ],
220
220
  "headerBlockHeight": 70.1875,
@@ -251,12 +251,12 @@
251
251
  "footerLines": [
252
252
  {
253
253
  "text": "Footer",
254
- "x": 233,
254
+ "x": 16,
255
255
  "baseline": 179.5625,
256
256
  "size": 24,
257
257
  "weight": 700,
258
258
  "secondary": false,
259
- "anchor": "middle"
259
+ "anchor": "start"
260
260
  }
261
261
  ],
262
262
  "footerBottom": 188.75,
@@ -321,23 +321,23 @@
321
321
  "kicker": [
322
322
  {
323
323
  "text": "KICKER",
324
- "x": 237,
324
+ "x": 92,
325
325
  "baseline": 32,
326
326
  "size": 22,
327
327
  "weight": 400,
328
328
  "secondary": true,
329
- "anchor": "middle"
329
+ "anchor": "start"
330
330
  }
331
331
  ],
332
332
  "title": [
333
333
  {
334
334
  "text": "Zone",
335
- "x": 237,
335
+ "x": 92,
336
336
  "baseline": 70.59375,
337
337
  "size": 32,
338
338
  "weight": 700,
339
339
  "secondary": false,
340
- "anchor": "middle"
340
+ "anchor": "start"
341
341
  }
342
342
  ],
343
343
  "headerBlockHeight": 70.1875,
@@ -365,12 +365,12 @@
365
365
  "footerLines": [
366
366
  {
367
367
  "text": "Footer",
368
- "x": 233,
368
+ "x": 16,
369
369
  "baseline": 179.5625,
370
370
  "size": 24,
371
371
  "weight": 700,
372
372
  "secondary": false,
373
- "anchor": "middle"
373
+ "anchor": "start"
374
374
  }
375
375
  ],
376
376
  "footerBottom": 188.75,
@@ -433,35 +433,35 @@
433
433
  "kicker": [
434
434
  {
435
435
  "text": "KICKER",
436
- "x": 291,
436
+ "x": 68,
437
437
  "baseline": 34,
438
438
  "size": 22,
439
439
  "weight": 400,
440
440
  "secondary": true,
441
- "anchor": "middle"
441
+ "anchor": "start"
442
442
  }
443
443
  ],
444
444
  "title": [
445
445
  {
446
446
  "text": "Zone",
447
- "x": 291,
447
+ "x": 68,
448
448
  "baseline": 72.59375,
449
449
  "size": 32,
450
450
  "weight": 700,
451
451
  "secondary": false,
452
- "anchor": "middle"
452
+ "anchor": "start"
453
453
  }
454
454
  ],
455
455
  "headerBlockHeight": 70.1875,
456
456
  "subtitle": [
457
457
  {
458
458
  "text": "Subtitle",
459
- "x": 175,
459
+ "x": 12,
460
460
  "baseline": 110.1875,
461
461
  "size": 24,
462
462
  "weight": 400,
463
463
  "secondary": false,
464
- "anchor": "middle"
464
+ "anchor": "start"
465
465
  }
466
466
  ],
467
467
  "subtitleWidth": 326,
@@ -476,12 +476,12 @@
476
476
  "footer": [
477
477
  {
478
478
  "text": "Footer",
479
- "x": 300,
479
+ "x": 16,
480
480
  "baseline": 184.875,
481
481
  "size": 24,
482
482
  "weight": 700,
483
483
  "secondary": false,
484
- "anchor": "middle"
484
+ "anchor": "start"
485
485
  }
486
486
  ],
487
487
  "footerRuleY": 157.875,
@@ -513,7 +513,7 @@
513
513
  "bodyFontSize": "var(--st-component-diagramCard-bodyFontSize)",
514
514
  "bodyFontWeight": "var(--st-component-diagramCard-bodyFontWeight)",
515
515
  "bodyLineHeight": "var(--st-component-diagramCard-bodyLineHeight)",
516
- "bodyInsetFromBar": "var(--st-component-diagramCard-bodyInsetFromBar)",
516
+ "bodyInsetFromBar": "10px",
517
517
  "ruleHeight": "var(--st-component-diagramCard-ruleHeight)",
518
518
  "ruleMargin": "var(--st-component-diagramCard-ruleMargin)",
519
519
  "ruleInsetStart": "var(--st-component-diagramCard-ruleInsetStart)",
package/dist/camera.d.ts CHANGED
@@ -12,16 +12,14 @@
12
12
  export declare const DEFAULT_MAX_DISPLAY_SCALE = 0.62;
13
13
  /**
14
14
  * Hard display floor: fit scales down to it, then the viewport scrolls.
15
- * 0.45 is the smallest two-decimal scale holding both the 18 px edge
16
- * label (BF-2, the binding constraint: 18 × 0.45 = 8.1 CSS px ≥ 8 CSS px
17
- * floor; 0.42 gives 7.56) and the 22 px kicker (22 × 0.45 = 9.9 CSS px).
15
+ * R7 owner decision (21/11): default to fitting the whole figure down to 30 %.
18
16
  */
19
- export declare const DEFAULT_MIN_READABLE_SCALE = 0.45;
17
+ export declare const DEFAULT_MIN_READABLE_SCALE = 0.3;
20
18
  /** World font size of an edge label, px (token `diagramScene.edgeLabelFontSize`). */
21
19
  export declare const DEFAULT_EDGE_LABEL_FONT_SIZE = 18;
22
20
  /** World line box of an edge label, px (token `diagramScene.edgeLabelLineHeight`). */
23
21
  export declare const DEFAULT_EDGE_LABEL_LINE_HEIGHT = 22;
24
- /** Minimum rendered edge-label size, CSS px. */
22
+ /** Original DC-2a edge-label readability reference, CSS px. */
25
23
  export declare const MIN_EDGE_LABEL_CSS_PX = 8;
26
24
  /** Share of the window height a figure may take (§5.1 fit box). */
27
25
  export declare const FIT_WINDOW_HEIGHT_SHARE = 0.85;
@@ -40,7 +38,7 @@ export interface CameraFitInput {
40
38
  /** Measured horizontal scrollbar thickness (`offsetHeight - clientHeight`), CSS px. */
41
39
  readonly scrollbarHeight?: number;
42
40
  readonly maxDisplayScale?: number;
43
- /** Optional higher readability floor; never lowers the absolute 0.45 floor. */
41
+ /** Optional higher readability floor; never lowers the absolute 0.30 floor. */
44
42
  readonly minReadableScale?: number;
45
43
  /**
46
44
  * Grid the applied fit zoom lands on, scale units. The fit is floored to
package/dist/camera.js CHANGED
@@ -12,16 +12,14 @@
12
12
  export const DEFAULT_MAX_DISPLAY_SCALE = 0.62;
13
13
  /**
14
14
  * Hard display floor: fit scales down to it, then the viewport scrolls.
15
- * 0.45 is the smallest two-decimal scale holding both the 18 px edge
16
- * label (BF-2, the binding constraint: 18 × 0.45 = 8.1 CSS px ≥ 8 CSS px
17
- * floor; 0.42 gives 7.56) and the 22 px kicker (22 × 0.45 = 9.9 CSS px).
15
+ * R7 owner decision (21/11): default to fitting the whole figure down to 30 %.
18
16
  */
19
- export const DEFAULT_MIN_READABLE_SCALE = 0.45;
17
+ export const DEFAULT_MIN_READABLE_SCALE = 0.30;
20
18
  /** World font size of an edge label, px (token `diagramScene.edgeLabelFontSize`). */
21
19
  export const DEFAULT_EDGE_LABEL_FONT_SIZE = 18;
22
20
  /** World line box of an edge label, px (token `diagramScene.edgeLabelLineHeight`). */
23
21
  export const DEFAULT_EDGE_LABEL_LINE_HEIGHT = 22;
24
- /** Minimum rendered edge-label size, CSS px. */
22
+ /** Original DC-2a edge-label readability reference, CSS px. */
25
23
  export const MIN_EDGE_LABEL_CSS_PX = 8;
26
24
  /** Share of the window height a figure may take (§5.1 fit box). */
27
25
  export const FIT_WINDOW_HEIGHT_SHARE = 0.85;
@@ -67,7 +65,7 @@ export function cameraFit(input) {
67
65
  // and the fit height below is the one of the drawing at that same zoom.
68
66
  const applied = input.zoomQuantum === undefined || zoomFit >= maxZoom ? zoomFit : floorToQuantum(zoomFit, input.zoomQuantum);
69
67
  // All hosts and camera inputs share this range. A small frame or a large
70
- // unfolded scene reaches the floor, then scrolls instead of shrinking text.
68
+ // unfolded scene reaches the floor, then scrolls to expose the rest.
71
69
  const zoom = Math.max(readableFloor, applied);
72
70
  const fitHeight = Math.min(box.height, Math.ceil((bounds.height * zoom + 2 * FIT_PAINT_INSET) * 64) / 64);
73
71
  return { fitWidth: box.width, fitHeight, zoomFit, zoom, minZoom: zoom, maxZoom, pans: zoom > zoomFit };
@@ -25,6 +25,8 @@
25
25
  import { type OccurrenceRef, type ViewDocument } from "@sentropic/diagram-core";
26
26
  import type { Rect, Vec2 } from "../transform.js";
27
27
  import type { TextSize } from "./types.js";
28
+ /** Zoom used to convert non-scaling ink into fixed world-space label clearance. */
29
+ export declare const LABEL_CLEARANCE_REFERENCE_SCALE = 0.45;
28
30
  export interface LabelPlacement {
29
31
  /** Index `k` of the segment `route[k] -> route[k + 1]` the label sits on. */
30
32
  readonly segment: number;
@@ -25,6 +25,8 @@
25
25
  import {} from "@sentropic/diagram-core";
26
26
  import { rectsIntersect } from "../geometry.js";
27
27
  import { portAnchorPoint } from "../scene.js";
28
+ /** Zoom used to convert non-scaling ink into fixed world-space label clearance. */
29
+ export const LABEL_CLEARANCE_REFERENCE_SCALE = 0.45;
28
30
  /** Length of one route segment, Manhattan: every route here is orthogonal. */
29
31
  export function segmentLength(route, segment) {
30
32
  const a = route[segment];
@@ -3,7 +3,6 @@ import { validateFlows } from "@sentropic/diagram-core";
3
3
  import { relationVerdict } from "../visibility.js";
4
4
  import { DEFAULT_FLOW_TOKENS, planFlows, placeFlowMarks } from "./flows.js";
5
5
  import { layoutErd } from "./erd.js";
6
- import { DEFAULT_MIN_READABLE_SCALE } from "../camera.js";
7
6
  /**
8
7
  * Measured diagram layout (M3 §4.6–§4.8, layout half of §5.6; placement by
9
8
  * SPEC_EVOL_DC2A §3–§4).
@@ -36,7 +35,7 @@ import { isAncestor } from "./graph.js";
36
35
  import { effectiveStretch, groupLeaves, isLayoutGroup, resolveGaps, resolveOrder, resolveRowGaps, validateHints, } from "./hints.js";
37
36
  import { measureSceneBox } from "./sceneMeasure.js";
38
37
  import { anatomyCardGeometry, anatomyZoneGeometry, ZONE_GEOMETRY, zoneDepthSurface } from "../presentation/diagramCardModel.js";
39
- import { placePackedLabel } from "./labels.js";
38
+ import { LABEL_CLEARANCE_REFERENCE_SCALE, placePackedLabel } from "./labels.js";
40
39
  import { CONTENT_INSET, DEFAULT_ALLOCATED_LINES, FIXED_CARD_HEIGHT, FIXED_CARD_WIDTH, headerAvailableWidth, headerOverflows, innerWidthOf, LEGEND_KEY_HEIGHT, measureHeader, SWATCH_ALLOCATION, TOGGLE_ALLOCATION, UNWRAPPED_PROBE_WIDTH, } from "./measure.js";
41
40
  import { measureBundleLabel } from "./bundleLabel.js";
42
41
  import { channelGap, channelMetrics } from "./channels.js";
@@ -878,6 +877,10 @@ function layoutMeasuredPass(document, options, sourceView, forced) {
878
877
  packedRuns.set(run.key, { run, rows, shelves, boxes, positions: seated.positions, alongBase, acrossBase });
879
878
  return { width: seated.width, height: seated.height };
880
879
  };
880
+ const legendKeyCardWidth = (id) => {
881
+ const parent = graph.nodes.get(id)?.parent;
882
+ return parent !== undefined ? cardWidthOf(representativeOf(parent)) : cardWidthOf(representativeOf(id));
883
+ };
881
884
  const sizeBox = (id) => {
882
885
  const kind = kinds.get(id);
883
886
  if (kind === "leaf" || kind === "container-collapsed" || kind === "legend-collapsed") {
@@ -890,7 +893,7 @@ function layoutMeasuredPass(document, options, sourceView, forced) {
890
893
  return size;
891
894
  }
892
895
  if (kind === "legend-key")
893
- return { width: innerWidthOf(FIXED_CARD_WIDTH), height: LEGEND_KEY_HEIGHT };
896
+ return { width: innerWidthOf(legendKeyCardWidth(id)), height: LEGEND_KEY_HEIGHT };
894
897
  const zoneGeo = anatomyZoneGeometry(occurrenceAnatomy(representativeOf(id)));
895
898
  const hasIcon = presentation.entities[representativeOf(id)]?.icon !== "none";
896
899
  const headerReserve = zoneGeo.headerTextInset - (hasIcon ? 0 : zoneGeo.iconSize + zoneGeo.iconTextGap);
@@ -1058,7 +1061,7 @@ function layoutMeasuredPass(document, options, sourceView, forced) {
1058
1061
  return;
1059
1062
  }
1060
1063
  if (kind === "legend-key") {
1061
- rects.set(id, { x, y, width: innerWidthOf(FIXED_CARD_WIDTH), height: LEGEND_KEY_HEIGHT });
1064
+ rects.set(id, { x, y, width: innerWidthOf(legendKeyCardWidth(id)), height: LEGEND_KEY_HEIGHT });
1062
1065
  return;
1063
1066
  }
1064
1067
  const size = packedSizes.get(id);
@@ -1066,7 +1069,7 @@ function layoutMeasuredPass(document, options, sourceView, forced) {
1066
1069
  const zoneGeo = anatomyZoneGeometry(occurrenceAnatomy(representativeOf(id)));
1067
1070
  const inner = innerWidthOf(size.width);
1068
1071
  rects.set(id, { x, y, width: size.width, height: size.height });
1069
- const ruleClearance = (zoneGeo.ruleHeight / 2 + 1) / DEFAULT_MIN_READABLE_SCALE;
1072
+ const ruleClearance = (zoneGeo.ruleHeight / 2 + 1) / LABEL_CLEARANCE_REFERENCE_SCALE;
1070
1073
  titleBands.set(id, { x, y, width: size.width, height: zoneGeo.headerInset + header.height });
1071
1074
  const footerReserve = sceneBoxAt(representativeOf(id), size.width, false).footerReserve;
1072
1075
  if (footerReserve > 0)
@@ -1129,7 +1132,7 @@ function layoutMeasuredPass(document, options, sourceView, forced) {
1129
1132
  const text = slotTexts(document, presentation, occurrence, id);
1130
1133
  if (kind === "legend-key") {
1131
1134
  const parent = graph.nodes.get(id)?.parent;
1132
- const inner = parent !== undefined && legendInner.has(parent) ? legendInner.get(parent) : innerWidthOf(FIXED_CARD_WIDTH);
1135
+ const inner = parent !== undefined && legendInner.has(parent) ? legendInner.get(parent) : innerWidthOf(legendKeyCardWidth(id));
1133
1136
  recordSlot(occurrence, "legend-label", measure({
1134
1137
  text: text.title ?? "",
1135
1138
  role: "legend-label",
@@ -1140,7 +1143,7 @@ function layoutMeasuredPass(document, options, sourceView, forced) {
1140
1143
  continue;
1141
1144
  }
1142
1145
  const expanded = kind === "container-expanded" || kind === "legend-expanded";
1143
- const inner = expanded ? innerWidthOf(outerWidths.get(id) ?? FIXED_CARD_WIDTH) : innerWidthOf(FIXED_CARD_WIDTH);
1146
+ const inner = expanded ? innerWidthOf(outerWidths.get(id) ?? cardWidthOf(occurrence)) : innerWidthOf(cardWidthOf(occurrence));
1144
1147
  const rendered = sceneBoxAt(occurrence, rects.get(id).width, !expanded && kind !== "leaf");
1145
1148
  for (const role of ["body", "detail", "footer"]) {
1146
1149
  if (text[role] === undefined)
@@ -1170,9 +1173,9 @@ function layoutMeasuredPass(document, options, sourceView, forced) {
1170
1173
  // Footer bands constrain text placement. Routes may cross a zone's
1171
1174
  // footer while leaving it; a label on that route still has to clear it.
1172
1175
  // Header measurement ends at the rule's top. Reserve its non-scaling
1173
- // paint plus one CSS px at the display floor for label placement.
1176
+ // paint plus one CSS px at the fixed reference scale for label placement.
1174
1177
  // Routes may cross a rule while leaving their own zone.
1175
- const ruleClearance = (ZONE_GEOMETRY.ruleHeight / 2 + 1) / DEFAULT_MIN_READABLE_SCALE;
1178
+ const ruleClearance = (ZONE_GEOMETRY.ruleHeight / 2 + 1) / LABEL_CLEARANCE_REFERENCE_SCALE;
1176
1179
  const fixedShapes = [...routeShapes, ...[...titleBands.values()].map(band => ({
1177
1180
  x: band.x, y: band.y + band.height, width: band.width,
1178
1181
  height: ZONE_GEOMETRY.ruleHeight / 2 + ruleClearance,
@@ -124,6 +124,8 @@ export declare const CARD_GEOMETRY_V2: {
124
124
  readonly headerInset: 12;
125
125
  readonly iconSize: 52;
126
126
  readonly iconTextGap: 4;
127
+ /** Preserves v1's −2 px body-vs-header offset (`10 − 12 = −2`, matching `14 − 16`). */
128
+ readonly bodyInsetFromBar: 10;
127
129
  readonly foldedHeaderTextWidth: 210;
128
130
  /** Title on one line first (addendum 8); v1 keeps two lines. */
129
131
  readonly allocatedLines: {
@@ -162,8 +164,6 @@ export declare const CARD_GEOMETRY_V2: {
162
164
  readonly weight: 400;
163
165
  readonly lineHeight: number;
164
166
  };
165
- /** Accent-bar left edge → first body glyph. */
166
- readonly bodyInsetFromBar: 14;
167
167
  readonly ruleHeight: 1;
168
168
  readonly ruleMargin: 4;
169
169
  readonly ruleInsetStart: 16;
@@ -204,11 +204,21 @@ export interface AnatomyPinned {
204
204
  export interface AlignPinned {
205
205
  readonly align?: "left" | "center";
206
206
  }
207
+ /**
208
+ * Effective header/footer alignment for a card or zone:
209
+ * - Absent `align` is always `"left"` (compact `v2` never centres implicitly).
210
+ * - Explicit `"v1"` anatomy (including `fallback-v1`) keeps the frozen 0.41.5
211
+ * alignment (`"left"`); view-driven centring applies only when a view
212
+ * explicitly asks `align: "center"` on compact `v2`.
213
+ * - Direct unpinned calls (`anatomy === undefined`) preserve 0.41.5's
214
+ * `props.align ?? "left"` behaviour.
215
+ */
216
+ export declare function resolveDiagramAlign(anatomy: DiagramAnatomy | undefined, align: "left" | "center" | undefined): "left" | "center";
207
217
  /**
208
218
  * Edge label typography (DC-2a, tokens `diagramScene.edgeLabelFontSize` /
209
219
  * `diagramScene.edgeLabelLineHeight`): 18 px on a 22 px line box. One line
210
220
  * plus the engine's two 4 px label margins is 30 px, inside the 32 px sibling
211
- * gap cap; at the 0.45 readability floor it renders at 8.1 CSS px.
221
+ * gap cap; at the 0.30 fit floor it renders at 5.4 CSS px.
212
222
  */
213
223
  export declare const FLOW_BADGE_GEOMETRY: {
214
224
  readonly size: 16;
@@ -559,8 +569,10 @@ export interface CardLayout {
559
569
  * Lay out fixed card slots with measured ellipses and a pinned footer.
560
570
  * Informational diagnostics retain the original text and hidden length.
561
571
  * Missing glyphs use the visible unknown icon (owner A2/A11).
562
- * Compact `v2` cards default to `"center"` alignment and fall back per box
563
- * to frozen `v1` (`460 × 200`) on overflow instead of dropping slots.
572
+ * Compact `v2` cards default to `"left"` alignment (centring only when
573
+ * `align: "center"` is explicitly requested on compact `v2`) and fall back
574
+ * per box to frozen `v1` (`460 × 200`, `"left"` header/footer alignment as in
575
+ * 0.41.5) on overflow instead of dropping slots.
564
576
  */
565
577
  export declare function layoutCard(props: DiagramCardProps, measure: CardLineMeasure): CardLayout;
566
578
  /**
@@ -639,9 +651,10 @@ export declare const ZONE_GEOMETRY: {
639
651
  };
640
652
  /**
641
653
  * Compact zone geometry (`diagram-anatomy/v2`): the collapsed zone IS the
642
- * compact card (`352 × 154`, collapsed subtitle measure `352 − 2 × 32`);
643
- * expanded chrome follows the compact insets (header `12`, icon `52`,
644
- * gap `4`). Unlisted leaves keep v1 values; type scale unchanged.
654
+ * compact card (`352 × 154`, collapsed subtitle measure `352 − 2 × 24 = 304`,
655
+ * preserving v1's ~86 % width ratio); expanded chrome follows the compact
656
+ * insets (header `12`, icon `52`, gap `4`). Unlisted leaves keep v1 values;
657
+ * type scale unchanged.
645
658
  */
646
659
  export declare const ZONE_GEOMETRY_V2: {
647
660
  readonly headerInset: 12;
@@ -655,6 +668,8 @@ export declare const ZONE_GEOMETRY_V2: {
655
668
  readonly headerTextInset: 154;
656
669
  readonly collapsedWidth: 352;
657
670
  readonly collapsedHeight: 154;
671
+ readonly collapsedInset: 12;
672
+ readonly collapsedSubtitleMarginInline: 12;
658
673
  readonly allocatedLines: {
659
674
  readonly kicker: 1;
660
675
  readonly title: 1;
@@ -704,8 +719,6 @@ export declare const ZONE_GEOMETRY_V2: {
704
719
  */
705
720
  readonly toggleTopInset: 8;
706
721
  readonly toggleInset: 8;
707
- readonly collapsedInset: 16;
708
- readonly collapsedSubtitleMarginInline: 16;
709
722
  };
710
723
  /** Select the zone geometry for a pinned anatomy (default `"v1"`). */
711
724
  export declare function anatomyZoneGeometry(anatomy: DiagramAnatomy | undefined): typeof ZONE_GEOMETRY | typeof ZONE_GEOMETRY_V2;
@@ -68,6 +68,8 @@ export const CARD_GEOMETRY_V2 = {
68
68
  headerInset: 12,
69
69
  iconSize: 52,
70
70
  iconTextGap: 4,
71
+ /** Preserves v1's −2 px body-vs-header offset (`10 − 12 = −2`, matching `14 − 16`). */
72
+ bodyInsetFromBar: 10,
71
73
  foldedHeaderTextWidth: 210,
72
74
  /** Title on one line first (addendum 8); v1 keeps two lines. */
73
75
  allocatedLines: { kicker: 1, title: 1, body: 2, footer: 1 },
@@ -76,11 +78,25 @@ export const CARD_GEOMETRY_V2 = {
76
78
  export function anatomyCardGeometry(anatomy) {
77
79
  return anatomy === "v2" ? CARD_GEOMETRY_V2 : CARD_GEOMETRY;
78
80
  }
81
+ /**
82
+ * Effective header/footer alignment for a card or zone:
83
+ * - Absent `align` is always `"left"` (compact `v2` never centres implicitly).
84
+ * - Explicit `"v1"` anatomy (including `fallback-v1`) keeps the frozen 0.41.5
85
+ * alignment (`"left"`); view-driven centring applies only when a view
86
+ * explicitly asks `align: "center"` on compact `v2`.
87
+ * - Direct unpinned calls (`anatomy === undefined`) preserve 0.41.5's
88
+ * `props.align ?? "left"` behaviour.
89
+ */
90
+ export function resolveDiagramAlign(anatomy, align) {
91
+ if (anatomy === "v1")
92
+ return "left";
93
+ return align ?? "left";
94
+ }
79
95
  /**
80
96
  * Edge label typography (DC-2a, tokens `diagramScene.edgeLabelFontSize` /
81
97
  * `diagramScene.edgeLabelLineHeight`): 18 px on a 22 px line box. One line
82
98
  * plus the engine's two 4 px label margins is 30 px, inside the 32 px sibling
83
- * gap cap; at the 0.45 readability floor it renders at 8.1 CSS px.
99
+ * gap cap; at the 0.30 fit floor it renders at 5.4 CSS px.
84
100
  */
85
101
  export const FLOW_BADGE_GEOMETRY = { size: 16, lineHeight: 20 };
86
102
  export const EDGE_LABEL_GEOMETRY = { size: 18, weight: 400, lineHeight: 22 };
@@ -784,18 +800,20 @@ function layoutCardAt(props, measure, anatomy, align) {
784
800
  * Lay out fixed card slots with measured ellipses and a pinned footer.
785
801
  * Informational diagnostics retain the original text and hidden length.
786
802
  * Missing glyphs use the visible unknown icon (owner A2/A11).
787
- * Compact `v2` cards default to `"center"` alignment and fall back per box
788
- * to frozen `v1` (`460 × 200`) on overflow instead of dropping slots.
803
+ * Compact `v2` cards default to `"left"` alignment (centring only when
804
+ * `align: "center"` is explicitly requested on compact `v2`) and fall back
805
+ * per box to frozen `v1` (`460 × 200`, `"left"` header/footer alignment as in
806
+ * 0.41.5) on overflow instead of dropping slots.
789
807
  */
790
808
  export function layoutCard(props, measure) {
791
- const align = props.align ?? (props.anatomy === "v2" ? "center" : "left");
809
+ const align = resolveDiagramAlign(props.anatomy, props.align);
792
810
  const primary = layoutCardAt(props, measure, props.anatomy, align);
793
811
  if (props.anatomy !== "v2")
794
812
  return primary;
795
813
  const v2Overflows = primary.diagnostics.filter((diagnostic) => diagnostic.code === "card-overflow");
796
814
  if (v2Overflows.length === 0)
797
815
  return primary;
798
- const fallback = layoutCardAt(props, measure, "v1", align);
816
+ const fallback = layoutCardAt(props, measure, "v1", "left");
799
817
  const stillOverflows = fallback.diagnostics.some((diagnostic) => diagnostic.code === "card-overflow");
800
818
  const diagnostics = stillOverflows
801
819
  ? [...fallback.diagnostics]
@@ -878,9 +896,10 @@ export const ZONE_GEOMETRY = {
878
896
  };
879
897
  /**
880
898
  * Compact zone geometry (`diagram-anatomy/v2`): the collapsed zone IS the
881
- * compact card (`352 × 154`, collapsed subtitle measure `352 − 2 × 32`);
882
- * expanded chrome follows the compact insets (header `12`, icon `52`,
883
- * gap `4`). Unlisted leaves keep v1 values; type scale unchanged.
899
+ * compact card (`352 × 154`, collapsed subtitle measure `352 − 2 × 24 = 304`,
900
+ * preserving v1's ~86 % width ratio); expanded chrome follows the compact
901
+ * insets (header `12`, icon `52`, gap `4`). Unlisted leaves keep v1 values;
902
+ * type scale unchanged.
884
903
  */
885
904
  export const ZONE_GEOMETRY_V2 = {
886
905
  ...ZONE_GEOMETRY,
@@ -895,6 +914,8 @@ export const ZONE_GEOMETRY_V2 = {
895
914
  headerTextInset: 154,
896
915
  collapsedWidth: CARD_GEOMETRY_V2.width,
897
916
  collapsedHeight: CARD_GEOMETRY_V2.height,
917
+ collapsedInset: 12,
918
+ collapsedSubtitleMarginInline: 12,
898
919
  allocatedLines: { kicker: 1, title: 1, subtitle: 2, footer: 1 },
899
920
  };
900
921
  /** Select the zone geometry for a pinned anatomy (default `"v1"`). */
@@ -1040,7 +1061,7 @@ export function layoutZone(props, measure, children = []) {
1040
1061
  ? g.headerInset
1041
1062
  : g.headerTextInset - (g.headerInset + g.iconSize + g.iconTextGap);
1042
1063
  const headerTextWidth = Math.max(0, x + width - headerTextX - rightHeaderReserve);
1043
- const align = props.align ?? (props.anatomy === "v2" ? "center" : "left");
1064
+ const align = resolveDiagramAlign(props.anatomy, props.align);
1044
1065
  const headerAnchor = align === "center" ? "middle" : "start";
1045
1066
  const headerLineX = align === "center" ? headerTextX + headerTextWidth / 2 : headerTextX;
1046
1067
  const fitSlot = (text, role, width, budget, slot = role) => truncateSlot(text, role, width, budget, measure, diagnostic => diagnostics.push({ ...diagnostic, code: "zone-overflow", slot, entityId: props.entityId }));
@@ -41,9 +41,8 @@ export interface SceneLayoutCache {
41
41
  stats(): LayoutCacheStats;
42
42
  }
43
43
  /**
44
- * `targetWidth` handed to the engine when the host supplies none. The
45
- * measured path never re-packs on it (D-3) and the host never reads the
46
- * layout fit report (Z-8), so a resize re-runs no layout.
44
+ * Default layout report width. The measured path never re-packs on it (D-3).
45
+ * Hosts use the measured frame width for the camera fit (Z-8).
47
46
  */
48
47
  export declare const DEFAULT_SCENE_TARGET_WIDTH = 1440;
49
48
  /**
@@ -250,7 +249,9 @@ export interface SceneModel {
250
249
  */
251
250
  export declare function resolveScene(result: SceneLaidOut, input: Pick<SceneLayoutInput, "document" | "presentation" | "measureLines" | "metrics" | "iconBindings" | "strictIcons" | "view" | "resolveGlyph" | "flows" | "depthParityStart">): SceneModel;
252
251
  /** Default labels for `DiagramSceneFigure`, including the DE-1b containment fallback label. */
253
- export declare const DEFAULT_SCENE_LABELS: DiagramSceneFigureLabels;
252
+ export declare const DEFAULT_SCENE_LABELS: DiagramSceneFigureLabels & {
253
+ readonly contains: string;
254
+ };
254
255
  /** Full presentation text retained alongside the textual relations (A14, DE-1b). */
255
256
  export declare function sceneTextRows(scene: SceneModel, document: SceneDocument, labels?: Partial<Pick<DiagramSceneFigureLabels, "contains">>): readonly string[];
256
257
  export interface SceneCameraInput {
@@ -14,15 +14,15 @@ import { measureErdCard, renderErdMarkerSvg, erdText, wrapErdText, placeErdRoleL
14
14
  * (layout, scene, camera). The semantic-document and view types are read
15
15
  * off the layout signature, so this package names no other diagram layer.
16
16
  */
17
- import { buildScene, cameraFit, clampZoom, CONTENT_INSET, DEFAULT_ALLOCATED_LINES, DEFAULT_LAYOUT_METRICS, DEFAULT_MIN_READABLE_SCALE, FIT_PAINT_INSET, layoutFolded, layoutMeasured, placeEdgeLabels, rectUnion, relationRoute, sceneNodes, sceneEdges, } from "../index.js";
17
+ import { buildScene, cameraFit, clampZoom, CONTENT_INSET, DEFAULT_ALLOCATED_LINES, DEFAULT_LAYOUT_METRICS, FIT_PAINT_INSET, layoutFolded, layoutMeasured, placeEdgeLabels, rectUnion, relationRoute, sceneNodes, sceneEdges, } from "../index.js";
18
18
  import { measureBundleLabel } from "../layout/bundleLabel.js";
19
+ import { LABEL_CLEARANCE_REFERENCE_SCALE } from "../layout/labels.js";
19
20
  import { getDiagramGlyph } from "./registry.js";
20
21
  import { anatomyZoneGeometry, lineBoxHeight, ZONE_GEOMETRY } from "./diagramCardModel.js";
21
22
  import { clearSceneLabels } from "./sceneLabelClearance.js";
22
23
  /**
23
- * `targetWidth` handed to the engine when the host supplies none. The
24
- * measured path never re-packs on it (D-3) and the host never reads the
25
- * layout fit report (Z-8), so a resize re-runs no layout.
24
+ * Default layout report width. The measured path never re-packs on it (D-3).
25
+ * Hosts use the measured frame width for the camera fit (Z-8).
26
26
  */
27
27
  export const DEFAULT_SCENE_TARGET_WIDTH = 1440;
28
28
  /**
@@ -48,7 +48,15 @@ export function resolveScenePresentation(document, presentation, bindings = {},
48
48
  * everywhere means `"v1"` — existing views do not move.
49
49
  */
50
50
  const viewAnatomy = view?.presentation?.anatomy;
51
- const withViewAnatomy = (entry) => entry.anatomy === undefined && viewAnatomy !== undefined ? { ...entry, anatomy: viewAnatomy } : entry;
51
+ const withViewAnatomy = (entry) => {
52
+ const resolved = entry.anatomy === undefined && viewAnatomy !== undefined ? { ...entry, anatomy: viewAnatomy } : entry;
53
+ // View-level centring applies only when explicitly requested on compact v2 anatomy.
54
+ if (resolved.anatomy !== "v2" && resolved.align === "center") {
55
+ const { align: _ignored, ...rest } = resolved;
56
+ return rest;
57
+ }
58
+ return resolved;
59
+ };
52
60
  const entities = Object.fromEntries(Object.entries(presentation.entities).map(([id, entry]) => {
53
61
  if (entry.form !== "card" && entry.form !== "container" && entry.form !== "legend")
54
62
  return [id, withViewAnatomy(entry)];
@@ -268,9 +276,8 @@ export function resolveScene(result, input) {
268
276
  const connectorCutouts = [];
269
277
  const footerWidths = new Map((result.measurements?.slots ?? []).filter((slot) => slot.role === "footer").map((slot) => [slot.occurrence, slot.layout.width]));
270
278
  const margin = input.metrics?.labelMargin ?? DEFAULT_LAYOUT_METRICS.labelMargin;
271
- // Non-scaling connector paint is widest in world units at the readability
272
- // floor. Reserve it as well as the label-padding token supplied by hosts.
273
- const paintClearance = margin + ZONE_GEOMETRY.borderWidth / (2 * DEFAULT_MIN_READABLE_SCALE);
279
+ // Add a fixed allowance for non-scaling ink to the host’s label-padding token.
280
+ const paintClearance = margin + ZONE_GEOMETRY.borderWidth / (2 * LABEL_CLEARANCE_REFERENCE_SCALE);
274
281
  const zoneInset = input.metrics?.containerPadding ?? ZONE_GEOMETRY.contentInsetInline;
275
282
  for (const node of nodes) {
276
283
  if (node.kind !== "zone" || node.collapsed) {
@@ -281,7 +288,7 @@ export function resolveScene(result, input) {
281
288
  if (height === undefined)
282
289
  continue;
283
290
  const zoneGeo = anatomyZoneGeometry(node.presentation?.anatomy);
284
- const ruleClearance = (zoneGeo.ruleHeight / 2 + 1) / DEFAULT_MIN_READABLE_SCALE;
291
+ const ruleClearance = (zoneGeo.ruleHeight / 2 + 1) / LABEL_CLEARANCE_REFERENCE_SCALE;
285
292
  blockers.push({
286
293
  x: node.rect.x,
287
294
  y: node.rect.y,
@@ -450,10 +457,6 @@ export const DEFAULT_SCENE_LABELS = Object.freeze({
450
457
  collapse: (title) => `Collapse ${title}`,
451
458
  contains: "includes",
452
459
  });
453
- function isContainmentRelation(document, relation) {
454
- const baseType = document.typeDefinitions?.[relation.type]?.baseType ?? relation.type;
455
- return baseType === "contains";
456
- }
457
460
  /** Full presentation text retained alongside the textual relations (A14, DE-1b). */
458
461
  export function sceneTextRows(scene, document, labels) {
459
462
  const containsLabel = labels?.contains ?? DEFAULT_SCENE_LABELS.contains;
@@ -461,7 +464,9 @@ export function sceneTextRows(scene, document, labels) {
461
464
  for (const relation of Object.values(document.relations)) {
462
465
  const names = relation.endpoints.map(end => { const value = document.entities[end.target]?.attributes["name"]; return value?.kind === "text" ? String(value.value) : end.target; });
463
466
  const explicit = edgeLabelOf(document, relation.id);
464
- const fallback = isContainmentRelation(document, relation) ? containsLabel : relation.type;
467
+ // W1-28: only replace the literal "contains" relation type so refined
468
+ // containment subtypes (e.g. "owns" with baseType "contains") keep their name.
469
+ const fallback = relation.type === "contains" ? containsLabel : relation.type;
465
470
  rows.push(names.join(" → ") + " · " + (explicit ?? fallback));
466
471
  }
467
472
  return rows;
@@ -24,7 +24,7 @@ export interface DiagramSceneFigureLabels {
24
24
  expand: (title: string) => string;
25
25
  collapse: (title: string) => string;
26
26
  /** Localized fallback label for containment relations without an explicit edge label (DE-1b). */
27
- contains: string;
27
+ contains?: string;
28
28
  }
29
29
  export interface DiagramSceneCamera {
30
30
  readonly zoom: number;
@@ -115,7 +115,7 @@ export function renderCardSvg(props, measure = defaultCardMeasure) {
115
115
  const { content, layout } = renderCardContent(props, measure);
116
116
  const g = { ...anatomyCardGeometry(layout.anatomyFallback ?? props.anatomy), width: layout.box.width, height: layout.box.height };
117
117
  const overflowSlots = layout.diagnostics
118
- .filter((diagnostic) => diagnostic.code === "card-overflow")
118
+ .filter((diagnostic) => diagnostic.code === "card-overflow" && diagnostic.reason !== "fallback-v1")
119
119
  .map((diagnostic) => diagnostic.slot);
120
120
  const unknownIcon = layout.diagnostics.some((diagnostic) => diagnostic.code === "card-icon-unknown");
121
121
  const firstOverflow = overflowSlots.length === 0 ? undefined : overflowSlots[0];
@@ -58,7 +58,7 @@ export function renderSceneSvg(input, options = {}) {
58
58
  const leader = label.leader === undefined ? '' : `<polyline points="${label.leader.map(p => p.x + ',' + p.y).join(' ')}" fill="none" stroke="var(--st-component-diagramScene-edgeStroke, #64748b)"/>`;
59
59
  return leader + `<g data-scene-label="${escape(label.occurrence)}" transform="translate(${b.x} ${b.y})" font-size="18" fill="var(--st-component-diagramScene-labelText, #172033)"><rect width="${b.width}" height="${b.height}" fill="var(--st-component-diagramScene-labelSurface, #ffffff)" stroke="var(--st-component-diagramScene-labelBorder, #cbd5e1)"/>${text}</g>`;
60
60
  }).join('');
61
- const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${box.x - 2} ${box.y - 2} ${box.width + 4} ${box.height + 4}" width="${(box.width + 4) * fit.zoom}" height="${(box.height + 4) * fit.zoom}" data-viewport-width="${viewportWidth}" data-display-scale="${fit.zoom}" role="img" aria-label="${escape(options.title ?? input.document.documentId)}" font-family="Inter, system-ui, sans-serif"><title>${escape(options.title ?? input.document.documentId)}</title><style>@font-face{font-family:Inter;src:local('Inter');font-weight:100 900}svg{--st-font-sans:Inter,system-ui,sans-serif;--st-semantic-surface-raised:#fff;--st-semantic-surface-subtle:#f8fafc;--st-component-diagramZone-surface1:#fff;--st-component-diagramZone-surface2:#f8fafc;--st-semantic-text-primary:#172033;--st-semantic-text-secondary:#475569;--st-semantic-border-strong:#64748b;--st-semantic-border-subtle:#cbd5e1;--st-semantic-feedback-info:#2563eb}</style><defs><marker id="scene-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0 0L10 5L0 10Z" fill="var(--st-component-diagramScene-edgeStroke, #64748b)"/></marker>${maskDef}</defs>${frames}${connectors}${boxes}${labels}</svg>`;
61
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${box.x - 2} ${box.y - 2} ${box.width + 4} ${box.height + 4}" width="${(box.width + 4) * fit.zoom}" height="${(box.height + 4) * fit.zoom}" data-viewport-width="${viewportWidth}" data-display-scale="${fit.zoom}" role="img" aria-label="${escape(options.title ?? input.document.documentId)}" font-family="Inter, system-ui, sans-serif"><title>${escape(options.title ?? input.document.documentId)}</title><style>@font-face{font-family:Inter;src:local('Inter');font-weight:100 900}svg:root{--st-font-sans:Inter,system-ui,sans-serif;--st-semantic-surface-raised:#fff;--st-semantic-surface-subtle:#f8fafc;--st-component-diagramZone-surface1:#fff;--st-component-diagramZone-surface2:#f8fafc;--st-semantic-text-primary:#172033;--st-semantic-text-secondary:#475569;--st-semantic-border-strong:#64748b;--st-semantic-border-subtle:#cbd5e1;--st-semantic-feedback-info:#2563eb}</style><defs><marker id="scene-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0 0L10 5L0 10Z" fill="var(--st-component-diagramScene-edgeStroke, #64748b)"/></marker>${maskDef}</defs>${frames}${connectors}${boxes}${labels}</svg>`;
62
62
  return { svg, result, scene };
63
63
  }
64
64
  //# sourceMappingURL=renderSceneSvg.js.map
@@ -140,7 +140,7 @@ export function renderZoneSvg(props, opts = {}) {
140
140
  const { content, layout, diagnostics } = zoneContent(props, children, measure);
141
141
  const { x, y, width, height } = layout.box;
142
142
  const overflowSlots = diagnostics
143
- .filter((diagnostic) => diagnostic.code === "zone-overflow")
143
+ .filter((diagnostic) => diagnostic.code === "zone-overflow" && diagnostic.reason !== "fallback-v1")
144
144
  .map((diagnostic) => diagnostic.slot);
145
145
  const unknownIcon = diagnostics.some((diagnostic) => diagnostic.code === "zone-icon-unknown");
146
146
  const firstOverflow = overflowSlots.length === 0 ? undefined : overflowSlots[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentropic/diagram-canvas",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Headless diagram scenes, layout, hit testing and pure presentation models/SVG helpers. No DOM or framework.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -58,7 +58,7 @@
58
58
  "main": "./dist/index.js",
59
59
  "sideEffects": false,
60
60
  "dependencies": {
61
- "@sentropic/diagram-core": "0.4.0"
61
+ "@sentropic/diagram-core": "0.4.1"
62
62
  },
63
63
  "scripts": {
64
64
  "build": "node ../../scripts/sync-diagram-spacing.mjs && tsc -p tsconfig.json",