@sentropic/diagram-canvas 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +21 -0
  2. package/dist/camera.d.ts +24 -3
  3. package/dist/camera.js +31 -8
  4. package/dist/index.d.ts +4 -0
  5. package/dist/index.js +4 -0
  6. package/dist/layout/cache.js +12 -2
  7. package/dist/layout/channels.d.ts +10 -0
  8. package/dist/layout/channels.js +13 -0
  9. package/dist/layout/conventions.d.ts +117 -0
  10. package/dist/layout/conventions.js +185 -0
  11. package/dist/layout/dock.d.ts +2 -0
  12. package/dist/layout/dock.js +5 -1
  13. package/dist/layout/fingerprint.d.ts +4 -2
  14. package/dist/layout/fingerprint.js +26 -2
  15. package/dist/layout/hints.d.ts +1 -1
  16. package/dist/layout/hints.js +10 -3
  17. package/dist/layout/index.d.ts +5 -3
  18. package/dist/layout/index.js +5 -3
  19. package/dist/layout/measure.d.ts +6 -0
  20. package/dist/layout/measure.js +28 -0
  21. package/dist/layout/measured.js +1047 -95
  22. package/dist/layout/route.d.ts +27 -1
  23. package/dist/layout/route.js +640 -32
  24. package/dist/layout/routeSpacing.d.ts +84 -0
  25. package/dist/layout/routeSpacing.js +472 -0
  26. package/dist/layout/spacing.generated.d.ts +10 -1
  27. package/dist/layout/spacing.generated.js +10 -1
  28. package/dist/layout/types.d.ts +33 -2
  29. package/dist/layout/types.js +2 -0
  30. package/dist/presentation/connectorPath.d.ts +32 -0
  31. package/dist/presentation/connectorPath.js +213 -0
  32. package/dist/presentation/connectorStyle.d.ts +70 -0
  33. package/dist/presentation/connectorStyle.js +99 -0
  34. package/dist/presentation/diagramSceneModel.d.ts +56 -4
  35. package/dist/presentation/diagramSceneModel.js +222 -31
  36. package/dist/presentation/diagramSceneTypes.d.ts +9 -0
  37. package/dist/presentation/index.d.ts +4 -0
  38. package/dist/presentation/index.js +4 -0
  39. package/dist/presentation/linkLegend.d.ts +132 -0
  40. package/dist/presentation/linkLegend.js +231 -0
  41. package/dist/presentation/renderSceneSvg.d.ts +3 -1
  42. package/dist/presentation/renderSceneSvg.js +81 -11
  43. package/dist/presentation/sceneLabelClearance.d.ts +1 -1
  44. package/dist/presentation/sceneLabelClearance.js +19 -3
  45. package/dist/r7Mode.d.ts +13 -0
  46. package/dist/r7Mode.js +67 -0
  47. package/dist/visibility.d.ts +1 -1
  48. package/dist/visibility.js +3 -2
  49. package/package.json +2 -2
@@ -15,11 +15,14 @@
15
15
  * the engine as numbers (§6.2), so a token change changes the fingerprint in
16
16
  * the call that observes it, with no token-version export.
17
17
  */
18
+ import { DEFAULT_EDGE_LABEL_SIZE } from "../camera.js";
19
+ import { isR7ConnectorPresentation } from "../r7Mode.js";
18
20
  import { isLayoutGroup, resolveRowGaps } from "./hints.js";
19
21
  import { channelMetrics } from "./channels.js";
22
+ import { DEFAULT_ROUTE_BORDER_CLEARANCE, DEFAULT_ROUTE_SPACING } from "./routeSpacing.js";
20
23
  import { DEFAULT_LAYOUT_METRICS, resolveRowPack } from "./types.js";
21
24
  /** Bumped whenever measured placement changes for unchanged inputs. */
22
- export const LAYOUT_ENGINE_VERSION = "dc2c.owner.5";
25
+ export const LAYOUT_ENGINE_VERSION = "de2.gutter.2";
23
26
  const byString = (left, right) => (left < right ? -1 : left > right ? 1 : 0);
24
27
  /** JSON with object keys sorted: equal values give equal text, whatever the insertion order. */
25
28
  function canonical(value) {
@@ -56,10 +59,22 @@ const groupOf = (group) => ({
56
59
  /** The resolved inputs behind the fingerprint, for a cache that wants to compare or log them. */
57
60
  export function layoutFingerprintInputs(input) {
58
61
  const { options } = input;
62
+ const r7Routing = input.r7Routing ?? isR7ConnectorPresentation(options.presentation);
59
63
  const metrics = { ...DEFAULT_LAYOUT_METRICS, ...options.metrics };
60
64
  const hints = options.hints ?? {};
61
65
  const gaps = resolveRowGaps(hints, metrics);
66
+ const zoneGutter = r7Routing ? resolveRowGaps(hints, metrics, true).zoneX : undefined;
62
67
  const tokens = input.tokens ?? {};
68
+ const routeSpacing = r7Routing ? (options.metrics?.routeSpacing ?? DEFAULT_ROUTE_SPACING) : 0;
69
+ const routeBorderClearance = r7Routing
70
+ ? (options.metrics?.routeBorderClearance ?? DEFAULT_ROUTE_BORDER_CLEARANCE)
71
+ : metrics.clearance;
72
+ const baseSlotSpacing = options.metrics?.trackSpacing ?? channelMetrics({}, true).trackSpacing;
73
+ const slotSpacing = options.metrics?.slotSpacing ??
74
+ (r7Routing ? Math.max(routeSpacing, baseSlotSpacing) : baseSlotSpacing);
75
+ const edgeLabelSize = metrics.edgeLabelSize !== undefined && Number.isFinite(metrics.edgeLabelSize) && metrics.edgeLabelSize > 0
76
+ ? metrics.edgeLabelSize
77
+ : DEFAULT_EDGE_LABEL_SIZE;
63
78
  return {
64
79
  engine: LAYOUT_ENGINE_VERSION,
65
80
  flows: options.flows,
@@ -67,8 +82,17 @@ export function layoutFingerprintInputs(input) {
67
82
  fold: [...(options.collapsed ?? [])].map(String).sort(byString),
68
83
  rowPack: resolveRowPack(options.rowPack),
69
84
  gaps,
85
+ zoneGutter,
70
86
  channels: { inline: channelMetrics(metrics, true), block: channelMetrics(metrics, false), bundleLabelMaxWidth: metrics.bundleLabelMaxWidth ?? 320 },
71
- metrics: { clearance: metrics.clearance, labelMargin: metrics.labelMargin, slotSpacing: options.metrics?.slotSpacing ?? options.metrics?.trackSpacing ?? 14, nodeGap: metrics.nodeGap },
87
+ metrics: {
88
+ clearance: metrics.clearance,
89
+ labelMargin: metrics.labelMargin,
90
+ routeSpacing,
91
+ routeBorderClearance,
92
+ slotSpacing,
93
+ nodeGap: metrics.nodeGap,
94
+ edgeLabelSize,
95
+ },
72
96
  previousOrientation: Object.entries(options.previousOrientation ?? {}).sort(([left], [right]) => byString(left, right)),
73
97
  hints: {
74
98
  ordering: hints.ordering,
@@ -82,7 +82,7 @@ export interface ResolvedRowGaps {
82
82
  * the token number passed as a metric, else the engine default mirroring the
83
83
  * token. The caps come from the metrics only: no hint raises a cap.
84
84
  */
85
- export declare function resolveRowGaps(hints: LayoutHints | undefined, metrics: LayoutMetrics): ResolvedRowGaps;
85
+ export declare function resolveRowGaps(hints: LayoutHints | undefined, metrics: LayoutMetrics, useZoneGutter?: boolean): ResolvedRowGaps;
86
86
  /** Local stretch overrides global stretch (M3 §4.7). */
87
87
  export declare function effectiveStretch(groupStretch: boolean | undefined, globalStretch: boolean | undefined): boolean;
88
88
  //# sourceMappingURL=hints.d.ts.map
@@ -139,12 +139,19 @@ export function resolveGaps(hints, metrics) {
139
139
  * the token number passed as a metric, else the engine default mirroring the
140
140
  * token. The caps come from the metrics only: no hint raises a cap.
141
141
  */
142
- export function resolveRowGaps(hints, metrics) {
142
+ export function resolveRowGaps(hints, metrics, useZoneGutter = false) {
143
+ // REQ-R7-14 (DE-2 ask 3): on the r7 path, sibling-zone gutters use one single
144
+ // fixed `zoneGutter` token (>= 96) on both axes; per-axis `zoneGapX/Y` hints
145
+ // cannot shrink or split it. On v1 (`useZoneGutter === false`), hints keep
146
+ // exact main behaviour.
147
+ const zoneGutter = useZoneGutter
148
+ ? Math.max(spacing.zoneGutter, metrics.zoneGutter ?? spacing.zoneGutter)
149
+ : undefined;
143
150
  return {
144
151
  cardX: hints?.cardGapX ?? metrics.rowGapInline ?? metrics.gapMin ?? DEFAULT_ROW_GAP,
145
152
  cardY: hints?.cardGapY ?? metrics.rowGapBlock ?? metrics.gapMinBlock ?? spacing.gapMinBlock,
146
- zoneX: hints?.zoneGapX ?? metrics.rowGapInline ?? metrics.gapMin ?? DEFAULT_ROW_GAP,
147
- zoneY: hints?.zoneGapY ?? metrics.rowGapBlock ?? metrics.gapMinBlock ?? spacing.gapMinBlock,
153
+ zoneX: zoneGutter ?? hints?.zoneGapX ?? metrics.rowGapInline ?? metrics.gapMin ?? DEFAULT_ROW_GAP,
154
+ zoneY: zoneGutter ?? hints?.zoneGapY ?? metrics.rowGapBlock ?? metrics.gapMinBlock ?? spacing.gapMinBlock,
148
155
  maxX: metrics.gapInlineMax ?? metrics.gapMax ?? DEFAULT_ROW_GAP_MAX,
149
156
  maxY: metrics.gapBlockMax ?? metrics.gapMax ?? DEFAULT_ROW_GAP_MAX,
150
157
  };
@@ -1,5 +1,7 @@
1
+ export { ARROW_DIRECTION_CONVENTION, DEFAULT_ZONE_TAG_ACRONYM_ALLOWLIST, isOpaqueAcronymZoneTag, lintArrowDirection, lintDiagramConventions, lintZoneTagAcronyms, type ArrowDirectionEdgeInput, type DiagramConventionLintOptions, type LintArrowDirectionInput, type LintDiagramConventionsInput, type LintZoneTagAcronymsInput, type ZoneTagLintEntry, } from "./conventions.js";
1
2
  export { measureBundleLabel, type BundleLabelGroup } from "./bundleLabel.js";
2
- export { channelMetrics, channelGap, type LayoutChannel, type ChannelMetrics } from "./channels.js";
3
+ export { channelMetrics, channelGap, channelCapacity, type LayoutChannel, type ChannelMetrics } from "./channels.js";
4
+ export { checkRouteSpacing, DEFAULT_ROUTE_BORDER_CLEARANCE, DEFAULT_ROUTE_SPACING, segmentToRectDistance, type ChannelCapacitySummary, type CheckedRoute, type CheckRouteSpacingInput, type RouteSpacingConflict, type RouteSpacingConflictKind, type RouteSpacingReport, } from "./routeSpacing.js";
3
5
  /**
4
6
  * The layout engine (SPEC §10.5, rules L-R1–L-R11): a `generic@1`
5
7
  * `SemanticDocument` in, a `diagram-core` `ViewDocument` out. Pure computation,
@@ -12,12 +14,12 @@ export { createLayoutCache, type LayoutCache, type LayoutCacheConfig, type Layou
12
14
  export { digestOf, LAYOUT_ENGINE_VERSION, layoutFingerprint, layoutFingerprintInputs, type LayoutFingerprintInput, } from "./fingerprint.js";
13
15
  export { chooseOrientation, packColumns, packRows, packScore, seatShelves, PACK_FILL_TOLERANCE, PACK_SCORE_EPSILON, type OrientationChoice, type PackBox, type PackOptions, type PackOrientation, type PackPosition, type PackResult, type SeatedShelves, } from "./pack.js";
14
16
  export { effectiveStretch, groupLeaves, isLayoutGroup, resolveGaps, resolveOrder, resolveRowGaps, validateHints, type HintScope, type LayoutGroup, type LayoutHints, type ResolvedGaps, type ResolvedRowGaps, } from "./hints.js";
15
- export { CONTENT_INSET, DEFAULT_ALLOCATED_LINES, FIXED_CARD_HEIGHT, FIXED_CARD_WIDTH, headerAvailableWidth, headerBandHeight, headerOverflows, innerWidthOf, LEGEND_KEY_HEIGHT, measureHeader, RULE_GAP, SWATCH_ALLOCATION, TOGGLE_ALLOCATION, UNWRAPPED_PROBE_WIDTH, type EntityMeasurementInput, type FootprintDecl, type HeaderMeasurement, type LayoutMeasurements, type LineLayout, type LineMeasurer, type MeasurementOverflow, type MeasureRequest, type SlotMeasurement, } from "./measure.js";
17
+ export { CONTENT_INSET, DEFAULT_ALLOCATED_LINES, FIXED_CARD_HEIGHT, FIXED_CARD_WIDTH, headerAvailableWidth, headerBandHeight, headerOverflows, innerWidthOf, LEGEND_KEY_HEIGHT, measureHeader, RULE_GAP, scaleEdgeLabelMeasurer, SWATCH_ALLOCATION, TOGGLE_ALLOCATION, UNWRAPPED_PROBE_WIDTH, type EntityMeasurementInput, type FootprintDecl, type HeaderMeasurement, type LayoutMeasurements, type LineLayout, type LineMeasurer, type MeasurementOverflow, type MeasureRequest, type SlotMeasurement, } from "./measure.js";
16
18
  export { BARYCENTRE_SWEEPS, dummyKey, orderLevel, type LevelEdge, type LevelOrder } from "./rank.js";
17
19
  export { parallelRelations, sideToward } from "./dock.js";
18
20
  export { ROW_FILL_ROUNDS } from "./place.js";
19
21
  export { edgeLabelCandidates, edgeLabelPlacement, labelBoxOnSegment, placeEdgeLabels, placeEdgeLabelsPacked, placePackedLabel, relationRoute, type LabelEntry, type LabelPlacement, type PackedLabelEntry, } from "./labels.js";
20
- export { bendCount, routeEdges, simplifyRoute, type RouteOutcome, type RouteRequest } from "./route.js";
22
+ export { bendCount, routeEdges, simplifyRoute, subdivideChannelTracks, type RouteOutcome, type RouteRequest } from "./route.js";
21
23
  export * from "./types.js";
22
24
  export { FLOW_BADGE_FONT_SIZE, FLOW_BADGE_LINE_HEIGHT, DEFAULT_FLOW_TOKENS, type FlowTokens, type FlowArrow, type FlowBundle, type FlowVisibleTarget } from "./flows.js";
23
25
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,7 @@
1
+ export { ARROW_DIRECTION_CONVENTION, DEFAULT_ZONE_TAG_ACRONYM_ALLOWLIST, isOpaqueAcronymZoneTag, lintArrowDirection, lintDiagramConventions, lintZoneTagAcronyms, } from "./conventions.js";
1
2
  export { measureBundleLabel } from "./bundleLabel.js";
2
- export { channelMetrics, channelGap } from "./channels.js";
3
+ export { channelMetrics, channelGap, channelCapacity } from "./channels.js";
4
+ export { checkRouteSpacing, DEFAULT_ROUTE_BORDER_CLEARANCE, DEFAULT_ROUTE_SPACING, segmentToRectDistance, } from "./routeSpacing.js";
3
5
  /**
4
6
  * The layout engine (SPEC §10.5, rules L-R1–L-R11): a `generic@1`
5
7
  * `SemanticDocument` in, a `diagram-core` `ViewDocument` out. Pure computation,
@@ -12,12 +14,12 @@ export { createLayoutCache } from "./cache.js";
12
14
  export { digestOf, LAYOUT_ENGINE_VERSION, layoutFingerprint, layoutFingerprintInputs, } from "./fingerprint.js";
13
15
  export { chooseOrientation, packColumns, packRows, packScore, seatShelves, PACK_FILL_TOLERANCE, PACK_SCORE_EPSILON, } from "./pack.js";
14
16
  export { effectiveStretch, groupLeaves, isLayoutGroup, resolveGaps, resolveOrder, resolveRowGaps, validateHints, } from "./hints.js";
15
- export { CONTENT_INSET, DEFAULT_ALLOCATED_LINES, FIXED_CARD_HEIGHT, FIXED_CARD_WIDTH, headerAvailableWidth, headerBandHeight, headerOverflows, innerWidthOf, LEGEND_KEY_HEIGHT, measureHeader, RULE_GAP, SWATCH_ALLOCATION, TOGGLE_ALLOCATION, UNWRAPPED_PROBE_WIDTH, } from "./measure.js";
17
+ export { CONTENT_INSET, DEFAULT_ALLOCATED_LINES, FIXED_CARD_HEIGHT, FIXED_CARD_WIDTH, headerAvailableWidth, headerBandHeight, headerOverflows, innerWidthOf, LEGEND_KEY_HEIGHT, measureHeader, RULE_GAP, scaleEdgeLabelMeasurer, SWATCH_ALLOCATION, TOGGLE_ALLOCATION, UNWRAPPED_PROBE_WIDTH, } from "./measure.js";
16
18
  export { BARYCENTRE_SWEEPS, dummyKey, orderLevel } from "./rank.js";
17
19
  export { parallelRelations, sideToward } from "./dock.js";
18
20
  export { ROW_FILL_ROUNDS } from "./place.js";
19
21
  export { edgeLabelCandidates, edgeLabelPlacement, labelBoxOnSegment, placeEdgeLabels, placeEdgeLabelsPacked, placePackedLabel, relationRoute, } from "./labels.js";
20
- export { bendCount, routeEdges, simplifyRoute } from "./route.js";
22
+ export { bendCount, routeEdges, simplifyRoute, subdivideChannelTracks } from "./route.js";
21
23
  export * from "./types.js";
22
24
  export { FLOW_BADGE_FONT_SIZE, FLOW_BADGE_LINE_HEIGHT, DEFAULT_FLOW_TOKENS } from "./flows.js";
23
25
  //# sourceMappingURL=index.js.map
@@ -57,6 +57,12 @@ export interface LineLayout {
57
57
  export type LineMeasurer = ((request: MeasureRequest) => LineLayout) & {
58
58
  readonly version?: string;
59
59
  };
60
+ /**
61
+ * Scale an injected `LineMeasurer` for the `edge-label` role when a caller
62
+ * overrides `metrics.edgeLabelSize` away from the default 18 px token size
63
+ * (REQ-R7-11). Returns `measureLines` unchanged at the default size.
64
+ */
65
+ export declare function scaleEdgeLabelMeasurer(measureLines: LineMeasurer, edgeLabelSize: number | undefined, baseSize?: number): LineMeasurer;
60
66
  export interface EntityMeasurementInput {
61
67
  readonly entity: EntityRef;
62
68
  readonly occurrence: OccurrenceRef;
@@ -23,6 +23,34 @@ export const TOGGLE_ALLOCATION = 66;
23
23
  export const SWATCH_ALLOCATION = 32;
24
24
  /** Probing width for the unwrapped header width of §4.6.2 order (a). */
25
25
  export const UNWRAPPED_PROBE_WIDTH = 100000;
26
+ /**
27
+ * Scale an injected `LineMeasurer` for the `edge-label` role when a caller
28
+ * overrides `metrics.edgeLabelSize` away from the default 18 px token size
29
+ * (REQ-R7-11). Returns `measureLines` unchanged at the default size.
30
+ */
31
+ export function scaleEdgeLabelMeasurer(measureLines, edgeLabelSize, baseSize = 18) {
32
+ if (edgeLabelSize === undefined ||
33
+ !Number.isFinite(edgeLabelSize) ||
34
+ edgeLabelSize <= 0 ||
35
+ Math.abs(edgeLabelSize - baseSize) < 1e-9) {
36
+ return measureLines;
37
+ }
38
+ const scale = edgeLabelSize / baseSize;
39
+ const scaled = (request) => {
40
+ if (request.role !== "edge-label")
41
+ return measureLines(request);
42
+ const availableWidth = Number.isFinite(request.availableWidth)
43
+ ? request.availableWidth / scale
44
+ : request.availableWidth;
45
+ const measured = measureLines({ ...request, availableWidth });
46
+ return {
47
+ ...measured,
48
+ width: measured.width * scale,
49
+ height: measured.height * scale,
50
+ };
51
+ };
52
+ return scaled;
53
+ }
26
54
  /** Frozen line allocation per slot (M3 §4.6.2). */
27
55
  export const DEFAULT_ALLOCATED_LINES = {
28
56
  kicker: 1,