@sentropic/diagram-canvas 0.3.1 → 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
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";
@@ -1070,7 +1069,7 @@ function layoutMeasuredPass(document, options, sourceView, forced) {
1070
1069
  const zoneGeo = anatomyZoneGeometry(occurrenceAnatomy(representativeOf(id)));
1071
1070
  const inner = innerWidthOf(size.width);
1072
1071
  rects.set(id, { x, y, width: size.width, height: size.height });
1073
- const ruleClearance = (zoneGeo.ruleHeight / 2 + 1) / DEFAULT_MIN_READABLE_SCALE;
1072
+ const ruleClearance = (zoneGeo.ruleHeight / 2 + 1) / LABEL_CLEARANCE_REFERENCE_SCALE;
1074
1073
  titleBands.set(id, { x, y, width: size.width, height: zoneGeo.headerInset + header.height });
1075
1074
  const footerReserve = sceneBoxAt(representativeOf(id), size.width, false).footerReserve;
1076
1075
  if (footerReserve > 0)
@@ -1174,9 +1173,9 @@ function layoutMeasuredPass(document, options, sourceView, forced) {
1174
1173
  // Footer bands constrain text placement. Routes may cross a zone's
1175
1174
  // footer while leaving it; a label on that route still has to clear it.
1176
1175
  // Header measurement ends at the rule's top. Reserve its non-scaling
1177
- // 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.
1178
1177
  // Routes may cross a rule while leaving their own zone.
1179
- const ruleClearance = (ZONE_GEOMETRY.ruleHeight / 2 + 1) / DEFAULT_MIN_READABLE_SCALE;
1178
+ const ruleClearance = (ZONE_GEOMETRY.ruleHeight / 2 + 1) / LABEL_CLEARANCE_REFERENCE_SCALE;
1180
1179
  const fixedShapes = [...routeShapes, ...[...titleBands.values()].map(band => ({
1181
1180
  x: band.x, y: band.y + band.height, width: band.width,
1182
1181
  height: ZONE_GEOMETRY.ruleHeight / 2 + ruleClearance,
@@ -218,7 +218,7 @@ export declare function resolveDiagramAlign(anatomy: DiagramAnatomy | undefined,
218
218
  * Edge label typography (DC-2a, tokens `diagramScene.edgeLabelFontSize` /
219
219
  * `diagramScene.edgeLabelLineHeight`): 18 px on a 22 px line box. One line
220
220
  * plus the engine's two 4 px label margins is 30 px, inside the 32 px sibling
221
- * 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.
222
222
  */
223
223
  export declare const FLOW_BADGE_GEOMETRY: {
224
224
  readonly size: 16;
@@ -96,7 +96,7 @@ export function resolveDiagramAlign(anatomy, align) {
96
96
  * Edge label typography (DC-2a, tokens `diagramScene.edgeLabelFontSize` /
97
97
  * `diagramScene.edgeLabelLineHeight`): 18 px on a 22 px line box. One line
98
98
  * plus the engine's two 4 px label margins is 30 px, inside the 32 px sibling
99
- * 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.
100
100
  */
101
101
  export const FLOW_BADGE_GEOMETRY = { size: 16, lineHeight: 20 };
102
102
  export const EDGE_LABEL_GEOMETRY = { size: 18, weight: 400, lineHeight: 22 };
@@ -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
  /**
@@ -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
  /**
@@ -276,9 +276,8 @@ export function resolveScene(result, input) {
276
276
  const connectorCutouts = [];
277
277
  const footerWidths = new Map((result.measurements?.slots ?? []).filter((slot) => slot.role === "footer").map((slot) => [slot.occurrence, slot.layout.width]));
278
278
  const margin = input.metrics?.labelMargin ?? DEFAULT_LAYOUT_METRICS.labelMargin;
279
- // Non-scaling connector paint is widest in world units at the readability
280
- // floor. Reserve it as well as the label-padding token supplied by hosts.
281
- 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);
282
281
  const zoneInset = input.metrics?.containerPadding ?? ZONE_GEOMETRY.contentInsetInline;
283
282
  for (const node of nodes) {
284
283
  if (node.kind !== "zone" || node.collapsed) {
@@ -289,7 +288,7 @@ export function resolveScene(result, input) {
289
288
  if (height === undefined)
290
289
  continue;
291
290
  const zoneGeo = anatomyZoneGeometry(node.presentation?.anatomy);
292
- const ruleClearance = (zoneGeo.ruleHeight / 2 + 1) / DEFAULT_MIN_READABLE_SCALE;
291
+ const ruleClearance = (zoneGeo.ruleHeight / 2 + 1) / LABEL_CLEARANCE_REFERENCE_SCALE;
293
292
  blockers.push({
294
293
  x: node.rect.x,
295
294
  y: node.rect.y,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentropic/diagram-canvas",
3
- "version": "0.3.1",
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"