@sentropic/diagram-canvas 0.3.1 → 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.
- package/README.md +23 -2
- package/dist/camera.d.ts +28 -9
- package/dist/camera.js +34 -13
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/layout/cache.js +12 -2
- package/dist/layout/channels.d.ts +10 -0
- package/dist/layout/channels.js +13 -0
- package/dist/layout/conventions.d.ts +117 -0
- package/dist/layout/conventions.js +185 -0
- package/dist/layout/dock.d.ts +2 -0
- package/dist/layout/dock.js +5 -1
- package/dist/layout/fingerprint.d.ts +4 -2
- package/dist/layout/fingerprint.js +26 -2
- package/dist/layout/hints.d.ts +1 -1
- package/dist/layout/hints.js +10 -3
- package/dist/layout/index.d.ts +5 -3
- package/dist/layout/index.js +5 -3
- package/dist/layout/labels.d.ts +2 -0
- package/dist/layout/labels.js +2 -0
- package/dist/layout/measure.d.ts +6 -0
- package/dist/layout/measure.js +28 -0
- package/dist/layout/measured.js +1051 -100
- package/dist/layout/route.d.ts +27 -1
- package/dist/layout/route.js +640 -32
- package/dist/layout/routeSpacing.d.ts +84 -0
- package/dist/layout/routeSpacing.js +472 -0
- package/dist/layout/spacing.generated.d.ts +10 -1
- package/dist/layout/spacing.generated.js +10 -1
- package/dist/layout/types.d.ts +33 -2
- package/dist/layout/types.js +2 -0
- package/dist/presentation/connectorPath.d.ts +32 -0
- package/dist/presentation/connectorPath.js +213 -0
- package/dist/presentation/connectorStyle.d.ts +70 -0
- package/dist/presentation/connectorStyle.js +99 -0
- package/dist/presentation/diagramCardModel.d.ts +1 -1
- package/dist/presentation/diagramCardModel.js +1 -1
- package/dist/presentation/diagramSceneModel.d.ts +58 -7
- package/dist/presentation/diagramSceneModel.js +225 -35
- package/dist/presentation/diagramSceneTypes.d.ts +9 -0
- package/dist/presentation/index.d.ts +4 -0
- package/dist/presentation/index.js +4 -0
- package/dist/presentation/linkLegend.d.ts +132 -0
- package/dist/presentation/linkLegend.js +231 -0
- package/dist/presentation/renderSceneSvg.d.ts +3 -1
- package/dist/presentation/renderSceneSvg.js +81 -11
- package/dist/presentation/sceneLabelClearance.d.ts +1 -1
- package/dist/presentation/sceneLabelClearance.js +19 -3
- package/dist/r7Mode.d.ts +13 -0
- package/dist/r7Mode.js +67 -0
- package/dist/visibility.d.ts +1 -1
- package/dist/visibility.js +3 -2
- package/package.json +2 -2
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatic link-style legend for `SceneModel` (DE-2, OWNER-ADDENDA ask 4).
|
|
3
|
+
*
|
|
4
|
+
* Inspects the visible connector styles actually drawn in the current fold
|
|
5
|
+
* state, orders them in a fixed canonical order, and places a self-contained
|
|
6
|
+
* legend strip anchored on an edge (right by default) outside the flow of
|
|
7
|
+
* functional zones. Suppressed automatically when fewer than two distinct
|
|
8
|
+
* connector styles are visible, or when `anchor === "none"`.
|
|
9
|
+
*
|
|
10
|
+
* Pure geometry and presentation data: zero DOM, zero framework dependencies.
|
|
11
|
+
*/
|
|
12
|
+
import type { CanonicalArrowheadKind, LinkEmphasis, StrokeStyle } from "@sentropic/diagram-core";
|
|
13
|
+
import type { LineMeasurer } from "../layout/measure.js";
|
|
14
|
+
import type { LayoutMetrics } from "../layout/types.js";
|
|
15
|
+
import type { Rect } from "../transform.js";
|
|
16
|
+
/** Where the automatic link-style legend strip sits relative to the functional drawing. */
|
|
17
|
+
export type LinkLegendAnchor = "right" | "bottom" | "none";
|
|
18
|
+
/** Canonical sort orders over the three closed connector registry axes. */
|
|
19
|
+
export declare const LINK_LEGEND_STROKE_ORDER: readonly StrokeStyle[];
|
|
20
|
+
export declare const LINK_LEGEND_EMPHASIS_ORDER: readonly LinkEmphasis[];
|
|
21
|
+
export declare const LINK_LEGEND_ARROWHEAD_ORDER: readonly CanonicalArrowheadKind[];
|
|
22
|
+
/** World-unit geometry constants shared by SVG, Svelte and Vue renderers. */
|
|
23
|
+
export declare const LINK_LEGEND_GAP = 48;
|
|
24
|
+
export declare const LINK_LEGEND_PADDING = 16;
|
|
25
|
+
export declare const LINK_LEGEND_HEADER_HEIGHT = 30;
|
|
26
|
+
export declare const LINK_LEGEND_HEADER_GAP = 8;
|
|
27
|
+
export declare const LINK_LEGEND_SWATCH_WIDTH = 56;
|
|
28
|
+
export declare const LINK_LEGEND_SWATCH_HEIGHT = 16;
|
|
29
|
+
export declare const LINK_LEGEND_SWATCH_GAP = 14;
|
|
30
|
+
export declare const LINK_LEGEND_ROW_HEIGHT = 28;
|
|
31
|
+
export declare const LINK_LEGEND_ROW_GAP = 8;
|
|
32
|
+
export declare const LINK_LEGEND_MIN_WIDTH = 240;
|
|
33
|
+
export declare const LINK_LEGEND_FONT_SIZE = 18;
|
|
34
|
+
export interface LinkLegendEdgeInput {
|
|
35
|
+
readonly markers?: string;
|
|
36
|
+
readonly directed?: boolean;
|
|
37
|
+
readonly strokeStyle?: StrokeStyle;
|
|
38
|
+
readonly arrowhead?: "arrow" | CanonicalArrowheadKind;
|
|
39
|
+
readonly emphasis?: LinkEmphasis;
|
|
40
|
+
}
|
|
41
|
+
export interface LinkLegendStyleKey {
|
|
42
|
+
readonly strokeStyle: StrokeStyle;
|
|
43
|
+
readonly arrowhead: CanonicalArrowheadKind;
|
|
44
|
+
readonly emphasis: LinkEmphasis;
|
|
45
|
+
}
|
|
46
|
+
export interface LinkLegendEntry extends LinkLegendStyleKey {
|
|
47
|
+
/** Deterministic key: `<strokeStyle>:<arrowhead>:<emphasis>`. */
|
|
48
|
+
readonly key: string;
|
|
49
|
+
/** Human-readable label shown beside the sample swatch. */
|
|
50
|
+
readonly label: string;
|
|
51
|
+
/** Count of visible connectors using this style in the current fold state. */
|
|
52
|
+
readonly count: number;
|
|
53
|
+
/** Top offset of this row inside the legend box (world units). */
|
|
54
|
+
readonly rowY: number;
|
|
55
|
+
/** Height of this row inside the legend box (world units). */
|
|
56
|
+
readonly rowHeight: number;
|
|
57
|
+
}
|
|
58
|
+
export interface SceneLinkLegend {
|
|
59
|
+
readonly anchor: Exclude<LinkLegendAnchor, "none">;
|
|
60
|
+
readonly title: string;
|
|
61
|
+
/** Outer bounding rectangle in world coordinates, outside the functional flow. */
|
|
62
|
+
readonly rect: Rect;
|
|
63
|
+
/** Visible styles in fixed canonical order (always length >= 2). */
|
|
64
|
+
readonly entries: readonly LinkLegendEntry[];
|
|
65
|
+
readonly padding: number;
|
|
66
|
+
readonly headerHeight: number;
|
|
67
|
+
readonly headerGap: number;
|
|
68
|
+
readonly rowHeight: number;
|
|
69
|
+
readonly rowGap: number;
|
|
70
|
+
readonly swatchWidth: number;
|
|
71
|
+
readonly swatchHeight: number;
|
|
72
|
+
readonly swatchGap: number;
|
|
73
|
+
readonly fontSize: number;
|
|
74
|
+
}
|
|
75
|
+
export interface LinkLegendSwatchGeometry {
|
|
76
|
+
readonly viewBox: string;
|
|
77
|
+
readonly width: number;
|
|
78
|
+
readonly height: number;
|
|
79
|
+
readonly linePath: string;
|
|
80
|
+
readonly arrowPath?: string;
|
|
81
|
+
readonly stroke: string;
|
|
82
|
+
readonly strokeWidth: number;
|
|
83
|
+
readonly dashArray?: string;
|
|
84
|
+
readonly arrowFill?: string;
|
|
85
|
+
readonly arrowStroke?: string;
|
|
86
|
+
readonly arrowStrokeWidth?: number;
|
|
87
|
+
}
|
|
88
|
+
/** Stable canonical key for a connector style triple. */
|
|
89
|
+
export declare function linkStyleKey(style: LinkLegendStyleKey): string;
|
|
90
|
+
/** Default human-readable label derived strictly from the closed registry words. */
|
|
91
|
+
export declare function defaultLinkStyleLabel(style: LinkLegendStyleKey): string;
|
|
92
|
+
/**
|
|
93
|
+
* Collect distinct visible connector styles in fixed canonical order.
|
|
94
|
+
* Returns an empty list when fewer than two distinct styles are drawn
|
|
95
|
+
* (single-style and edgeless scenes omit the legend).
|
|
96
|
+
*/
|
|
97
|
+
export declare function collectLinkLegendStyles(edges: readonly LinkLegendEdgeInput[]): readonly (LinkLegendStyleKey & {
|
|
98
|
+
readonly key: string;
|
|
99
|
+
readonly count: number;
|
|
100
|
+
})[];
|
|
101
|
+
export interface BuildSceneLinkLegendInput {
|
|
102
|
+
readonly edges: readonly LinkLegendEdgeInput[];
|
|
103
|
+
readonly contentBounds: Rect | undefined;
|
|
104
|
+
readonly measureLines: LineMeasurer;
|
|
105
|
+
/** Anchor edge strip (`"right"` by default). `"none"` suppresses the legend. */
|
|
106
|
+
readonly anchor?: LinkLegendAnchor;
|
|
107
|
+
/** Legend heading text (defaults to `"Legend"`). */
|
|
108
|
+
readonly title?: string;
|
|
109
|
+
/** Optional custom labels keyed by `linkStyleKey(...)`. */
|
|
110
|
+
readonly labels?: Readonly<Record<string, string>>;
|
|
111
|
+
/** Optional world-unit font size override (defaults to `edgeLabelSize`, 18). */
|
|
112
|
+
readonly fontSize?: number;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Compute the automatic link-style legend and its anchored world rectangle
|
|
116
|
+
* outside `contentBounds`. Returns `undefined` when suppressed or when fewer
|
|
117
|
+
* than two distinct styles are drawn.
|
|
118
|
+
*/
|
|
119
|
+
export declare function buildSceneLinkLegend(input: BuildSceneLinkLegendInput): SceneLinkLegend | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* Shared inline CSS positioning and geometry custom properties for HTML legend
|
|
122
|
+
* hosts (Svelte and Vue), keeping every box, header, gap, row and swatch pixel
|
|
123
|
+
* identical to `buildSceneLinkLegend` and `renderSceneSvg` at every `edgeLabelSize`.
|
|
124
|
+
*/
|
|
125
|
+
export declare function linkLegendBoxStyle(legend: SceneLinkLegend, opacity?: number): string;
|
|
126
|
+
/**
|
|
127
|
+
* Inline SVG swatch geometry for a legend entry. Draws the sample line and
|
|
128
|
+
* arrowhead directly without `<marker>` ids so SVG, Svelte and Vue stay
|
|
129
|
+
* id-collision-free and DOM-identical.
|
|
130
|
+
*/
|
|
131
|
+
export declare function linkLegendSwatchGeometry(style: LinkLegendStyleKey, widths?: Pick<LayoutMetrics, "linkStrokeWidth" | "linkRelatedStrokeWidth" | "linkEmphasisStrokeWidth">): LinkLegendSwatchGeometry;
|
|
132
|
+
//# sourceMappingURL=linkLegend.d.ts.map
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { DEFAULT_EDGE_LABEL_SIZE } from "../camera.js";
|
|
2
|
+
import { connectorDashArray, connectorMarkerKind, connectorStrokeWidth, LINK_EMPHASIS_STROKE } from "./connectorStyle.js";
|
|
3
|
+
import { cardLineMeasurer } from "./diagramCardModel.js";
|
|
4
|
+
/** Canonical sort orders over the three closed connector registry axes. */
|
|
5
|
+
export const LINK_LEGEND_STROKE_ORDER = Object.freeze([
|
|
6
|
+
"solid",
|
|
7
|
+
"dashed",
|
|
8
|
+
"dotted",
|
|
9
|
+
]);
|
|
10
|
+
export const LINK_LEGEND_EMPHASIS_ORDER = Object.freeze([
|
|
11
|
+
"default",
|
|
12
|
+
"emphasis",
|
|
13
|
+
]);
|
|
14
|
+
export const LINK_LEGEND_ARROWHEAD_ORDER = Object.freeze([
|
|
15
|
+
"arrow",
|
|
16
|
+
"none",
|
|
17
|
+
]);
|
|
18
|
+
/** World-unit geometry constants shared by SVG, Svelte and Vue renderers. */
|
|
19
|
+
export const LINK_LEGEND_GAP = 48;
|
|
20
|
+
export const LINK_LEGEND_PADDING = 16;
|
|
21
|
+
export const LINK_LEGEND_HEADER_HEIGHT = 30;
|
|
22
|
+
export const LINK_LEGEND_HEADER_GAP = 8;
|
|
23
|
+
export const LINK_LEGEND_SWATCH_WIDTH = 56;
|
|
24
|
+
export const LINK_LEGEND_SWATCH_HEIGHT = 16;
|
|
25
|
+
export const LINK_LEGEND_SWATCH_GAP = 14;
|
|
26
|
+
export const LINK_LEGEND_ROW_HEIGHT = 28;
|
|
27
|
+
export const LINK_LEGEND_ROW_GAP = 8;
|
|
28
|
+
export const LINK_LEGEND_MIN_WIDTH = 240;
|
|
29
|
+
export const LINK_LEGEND_FONT_SIZE = DEFAULT_EDGE_LABEL_SIZE;
|
|
30
|
+
const EDGE_STROKE = "var(--st-component-diagramScene-edgeStroke, #64748b)";
|
|
31
|
+
const EMPHASIS_STROKE = LINK_EMPHASIS_STROKE;
|
|
32
|
+
const measureLegendFallback = cardLineMeasurer();
|
|
33
|
+
/** Stable canonical key for a connector style triple. */
|
|
34
|
+
export function linkStyleKey(style) {
|
|
35
|
+
return `${style.strokeStyle}:${style.arrowhead}:${style.emphasis}`;
|
|
36
|
+
}
|
|
37
|
+
/** Default human-readable label derived strictly from the closed registry words. */
|
|
38
|
+
export function defaultLinkStyleLabel(style) {
|
|
39
|
+
const parts = [];
|
|
40
|
+
if (style.emphasis === "emphasis")
|
|
41
|
+
parts.push("Emphasis");
|
|
42
|
+
if (style.strokeStyle === "dashed") {
|
|
43
|
+
parts.push("Proposed (dashed)");
|
|
44
|
+
}
|
|
45
|
+
else if (style.strokeStyle === "dotted") {
|
|
46
|
+
parts.push("Dotted");
|
|
47
|
+
}
|
|
48
|
+
else if (parts.length === 0) {
|
|
49
|
+
parts.push("Link");
|
|
50
|
+
}
|
|
51
|
+
if (style.arrowhead === "none") {
|
|
52
|
+
parts.push("Undirected");
|
|
53
|
+
}
|
|
54
|
+
return parts.join(" · ");
|
|
55
|
+
}
|
|
56
|
+
function styleRank(style) {
|
|
57
|
+
const stroke = LINK_LEGEND_STROKE_ORDER.indexOf(style.strokeStyle);
|
|
58
|
+
const emphasis = LINK_LEGEND_EMPHASIS_ORDER.indexOf(style.emphasis);
|
|
59
|
+
const arrowhead = LINK_LEGEND_ARROWHEAD_ORDER.indexOf(style.arrowhead);
|
|
60
|
+
return stroke * 4 + emphasis * 2 + arrowhead;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Collect distinct visible connector styles in fixed canonical order.
|
|
64
|
+
* Returns an empty list when fewer than two distinct styles are drawn
|
|
65
|
+
* (single-style and edgeless scenes omit the legend).
|
|
66
|
+
*/
|
|
67
|
+
export function collectLinkLegendStyles(edges) {
|
|
68
|
+
const counts = new Map();
|
|
69
|
+
for (const edge of edges) {
|
|
70
|
+
if (edge.markers !== undefined || edge.directed === true)
|
|
71
|
+
continue;
|
|
72
|
+
const strokeStyle = edge.strokeStyle ?? "solid";
|
|
73
|
+
const arrowhead = connectorMarkerKind(edge.arrowhead);
|
|
74
|
+
const emphasis = edge.emphasis === "emphasis" ? "emphasis" : "default";
|
|
75
|
+
const triple = { strokeStyle, arrowhead, emphasis };
|
|
76
|
+
const key = linkStyleKey(triple);
|
|
77
|
+
const existing = counts.get(key);
|
|
78
|
+
if (existing !== undefined) {
|
|
79
|
+
existing.count += 1;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
counts.set(key, { ...triple, count: 1 });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (counts.size < 2)
|
|
86
|
+
return [];
|
|
87
|
+
return [...counts.entries()]
|
|
88
|
+
.map(([key, value]) => ({
|
|
89
|
+
key,
|
|
90
|
+
strokeStyle: value.strokeStyle,
|
|
91
|
+
arrowhead: value.arrowhead,
|
|
92
|
+
emphasis: value.emphasis,
|
|
93
|
+
count: value.count,
|
|
94
|
+
}))
|
|
95
|
+
.sort((left, right) => styleRank(left) - styleRank(right));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Compute the automatic link-style legend and its anchored world rectangle
|
|
99
|
+
* outside `contentBounds`. Returns `undefined` when suppressed or when fewer
|
|
100
|
+
* than two distinct styles are drawn.
|
|
101
|
+
*/
|
|
102
|
+
export function buildSceneLinkLegend(input) {
|
|
103
|
+
const anchor = input.anchor ?? "right";
|
|
104
|
+
if (anchor === "none" || input.contentBounds === undefined)
|
|
105
|
+
return undefined;
|
|
106
|
+
const collected = collectLinkLegendStyles(input.edges);
|
|
107
|
+
if (collected.length < 2)
|
|
108
|
+
return undefined;
|
|
109
|
+
const title = input.title ?? "Legend";
|
|
110
|
+
const fontSize = input.fontSize ?? LINK_LEGEND_FONT_SIZE;
|
|
111
|
+
const scale = fontSize > 0 && Number.isFinite(fontSize) ? fontSize / LINK_LEGEND_FONT_SIZE : 1;
|
|
112
|
+
const headerHeight = scale === 1 ? LINK_LEGEND_HEADER_HEIGHT : Math.ceil(LINK_LEGEND_HEADER_HEIGHT * scale);
|
|
113
|
+
const headerGap = scale === 1 ? LINK_LEGEND_HEADER_GAP : Math.ceil(LINK_LEGEND_HEADER_GAP * scale);
|
|
114
|
+
const rowHeight = Math.max(LINK_LEGEND_SWATCH_HEIGHT, scale === 1 ? LINK_LEGEND_ROW_HEIGHT : Math.ceil(LINK_LEGEND_ROW_HEIGHT * scale));
|
|
115
|
+
const rowGap = scale === 1 ? LINK_LEGEND_ROW_GAP : Math.ceil(LINK_LEGEND_ROW_GAP * scale);
|
|
116
|
+
const measureWidth = (text) => {
|
|
117
|
+
const request = { text, role: "edge-label", availableWidth: Number.MAX_SAFE_INTEGER, allocatedLines: 1, folded: false };
|
|
118
|
+
const layout = input.measureLines(request);
|
|
119
|
+
// CardLineMeasure without lineWidths reports the allocation as its width.
|
|
120
|
+
return (layout.width >= request.availableWidth || !Number.isFinite(layout.width)
|
|
121
|
+
? measureLegendFallback(request).width
|
|
122
|
+
: layout.width) * scale;
|
|
123
|
+
};
|
|
124
|
+
const scaledTitleWidth = measureWidth(title);
|
|
125
|
+
let maxLabelWidth = 0;
|
|
126
|
+
const entries = collected.map((item, index) => {
|
|
127
|
+
const label = input.labels?.[item.key] ?? defaultLinkStyleLabel(item);
|
|
128
|
+
const scaledWidth = measureWidth(label);
|
|
129
|
+
if (scaledWidth > maxLabelWidth)
|
|
130
|
+
maxLabelWidth = scaledWidth;
|
|
131
|
+
const rowY = LINK_LEGEND_PADDING +
|
|
132
|
+
headerHeight +
|
|
133
|
+
headerGap +
|
|
134
|
+
index * (rowHeight + rowGap);
|
|
135
|
+
return {
|
|
136
|
+
...item,
|
|
137
|
+
label,
|
|
138
|
+
rowY,
|
|
139
|
+
rowHeight,
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
const contentWidth = Math.max(scaledTitleWidth, LINK_LEGEND_SWATCH_WIDTH + LINK_LEGEND_SWATCH_GAP + maxLabelWidth);
|
|
143
|
+
const width = Math.ceil(Math.max(LINK_LEGEND_MIN_WIDTH, 2 * LINK_LEGEND_PADDING + contentWidth));
|
|
144
|
+
const height = 2 * LINK_LEGEND_PADDING +
|
|
145
|
+
headerHeight +
|
|
146
|
+
headerGap +
|
|
147
|
+
entries.length * rowHeight +
|
|
148
|
+
Math.max(0, entries.length - 1) * rowGap;
|
|
149
|
+
const rect = anchor === "bottom"
|
|
150
|
+
? {
|
|
151
|
+
x: input.contentBounds.x,
|
|
152
|
+
y: input.contentBounds.y + input.contentBounds.height + LINK_LEGEND_GAP,
|
|
153
|
+
width,
|
|
154
|
+
height,
|
|
155
|
+
}
|
|
156
|
+
: {
|
|
157
|
+
x: input.contentBounds.x + input.contentBounds.width + LINK_LEGEND_GAP,
|
|
158
|
+
y: input.contentBounds.y,
|
|
159
|
+
width,
|
|
160
|
+
height,
|
|
161
|
+
};
|
|
162
|
+
return {
|
|
163
|
+
anchor,
|
|
164
|
+
title,
|
|
165
|
+
rect,
|
|
166
|
+
entries,
|
|
167
|
+
padding: LINK_LEGEND_PADDING,
|
|
168
|
+
headerHeight,
|
|
169
|
+
headerGap,
|
|
170
|
+
rowHeight,
|
|
171
|
+
rowGap,
|
|
172
|
+
swatchWidth: LINK_LEGEND_SWATCH_WIDTH,
|
|
173
|
+
swatchHeight: LINK_LEGEND_SWATCH_HEIGHT,
|
|
174
|
+
swatchGap: LINK_LEGEND_SWATCH_GAP,
|
|
175
|
+
fontSize,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Shared inline CSS positioning and geometry custom properties for HTML legend
|
|
180
|
+
* hosts (Svelte and Vue), keeping every box, header, gap, row and swatch pixel
|
|
181
|
+
* identical to `buildSceneLinkLegend` and `renderSceneSvg` at every `edgeLabelSize`.
|
|
182
|
+
*/
|
|
183
|
+
export function linkLegendBoxStyle(legend, opacity) {
|
|
184
|
+
return (`left:${legend.rect.x}px;top:${legend.rect.y}px;width:${legend.rect.width}px;height:${legend.rect.height}px;` +
|
|
185
|
+
`--st-diagram-legend-padding:${legend.padding}px;` +
|
|
186
|
+
`--st-diagram-legend-header-height:${legend.headerHeight}px;` +
|
|
187
|
+
`--st-diagram-legend-header-gap:${legend.headerGap}px;` +
|
|
188
|
+
`--st-diagram-legend-row-height:${legend.rowHeight}px;` +
|
|
189
|
+
`--st-diagram-legend-row-gap:${legend.rowGap}px;` +
|
|
190
|
+
`--st-diagram-legend-swatch-width:${legend.swatchWidth}px;` +
|
|
191
|
+
`--st-diagram-legend-swatch-height:${legend.swatchHeight}px;` +
|
|
192
|
+
`--st-diagram-legend-swatch-gap:${legend.swatchGap}px;` +
|
|
193
|
+
`--st-diagram-legend-font-size:${legend.fontSize}px` +
|
|
194
|
+
(opacity === undefined ? "" : `;opacity:${opacity}`));
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Inline SVG swatch geometry for a legend entry. Draws the sample line and
|
|
198
|
+
* arrowhead directly without `<marker>` ids so SVG, Svelte and Vue stay
|
|
199
|
+
* id-collision-free and DOM-identical.
|
|
200
|
+
*/
|
|
201
|
+
export function linkLegendSwatchGeometry(style, widths) {
|
|
202
|
+
const emphasized = style.emphasis === "emphasis";
|
|
203
|
+
const stroke = emphasized ? EMPHASIS_STROKE : EDGE_STROKE;
|
|
204
|
+
const strokeWidth = connectorStrokeWidth(style, widths);
|
|
205
|
+
const dashArray = connectorDashArray(style.strokeStyle);
|
|
206
|
+
const lineEnd = style.arrowhead === "none" ? 54 : 46;
|
|
207
|
+
const linePath = `M2 8H${lineEnd}`;
|
|
208
|
+
if (style.arrowhead === "none") {
|
|
209
|
+
return {
|
|
210
|
+
viewBox: `0 0 ${LINK_LEGEND_SWATCH_WIDTH} ${LINK_LEGEND_SWATCH_HEIGHT}`,
|
|
211
|
+
width: LINK_LEGEND_SWATCH_WIDTH,
|
|
212
|
+
height: LINK_LEGEND_SWATCH_HEIGHT,
|
|
213
|
+
linePath,
|
|
214
|
+
stroke,
|
|
215
|
+
strokeWidth,
|
|
216
|
+
...(dashArray === undefined ? {} : { dashArray }),
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
viewBox: `0 0 ${LINK_LEGEND_SWATCH_WIDTH} ${LINK_LEGEND_SWATCH_HEIGHT}`,
|
|
221
|
+
width: LINK_LEGEND_SWATCH_WIDTH,
|
|
222
|
+
height: LINK_LEGEND_SWATCH_HEIGHT,
|
|
223
|
+
linePath,
|
|
224
|
+
arrowPath: "M44 3L54 8L44 13Z",
|
|
225
|
+
stroke,
|
|
226
|
+
strokeWidth,
|
|
227
|
+
...(dashArray === undefined ? {} : { dashArray }),
|
|
228
|
+
arrowFill: stroke,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=linkLegend.js.map
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
/** Standalone server-side SVG, consuming exactly the scene model used by the framework hosts. */
|
|
2
1
|
import { type SceneLayoutInput } from './diagramSceneModel.js';
|
|
3
2
|
import { type CardLineMeasure } from './diagramCardModel.js';
|
|
4
3
|
export declare function renderSceneSvg(input: SceneLayoutInput, options?: {
|
|
5
4
|
measure?: CardLineMeasure;
|
|
6
5
|
title?: string;
|
|
6
|
+
fitToWindow?: boolean;
|
|
7
|
+
windowHeight?: number;
|
|
7
8
|
}): {
|
|
8
9
|
svg: string;
|
|
9
10
|
result: {
|
|
@@ -19,6 +20,7 @@ export declare function renderSceneSvg(input: SceneLayoutInput, options?: {
|
|
|
19
20
|
readonly measurements?: import("../index.js").LayoutMeasurements;
|
|
20
21
|
readonly orientations?: Readonly<Record<string, import("../index.js").LevelOrientation>>;
|
|
21
22
|
readonly channels?: readonly import("../index.js").LayoutChannel[];
|
|
23
|
+
readonly routeSpacing?: import("../index.js").RouteSpacingReport;
|
|
22
24
|
readonly labelBoxes?: Readonly<Record<string, {
|
|
23
25
|
readonly x: number;
|
|
24
26
|
readonly y: number;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { renderErdCardSvg } from './erd.js';
|
|
2
2
|
/** Standalone server-side SVG, consuming exactly the scene model used by the framework hosts. */
|
|
3
|
-
import {
|
|
3
|
+
import { connectorStrokeWidth, LINK_EMPHASIS_STROKE, LINK_EMPHASIS_STROKE_FALLBACK, } from './connectorStyle.js';
|
|
4
|
+
import { connectorDashArray, connectorDashPaint, connectorMarkerIds, connectorMarkerRef, connectorPath, DEFAULT_EDGE_CORNER_RADIUS, DEFAULT_EDGE_LABEL_SIZE, DEFAULT_LINK_STROKE_WIDTH, extraConnectorMarkers, layoutScene, linkLegendSwatchGeometry, resolveScene, sceneConnectorMask, sceneFit, sceneNodesOnPlane, } from './diagramSceneModel.js';
|
|
4
5
|
import { cardLineMeasurer, defaultCardMeasure, sceneCardMeasure, projectCardProps, projectZoneProps } from './diagramCardModel.js';
|
|
5
6
|
import { renderCardSvg } from './renderCardSvg.js';
|
|
6
7
|
import { renderZoneSvg } from './renderZoneSvg.js';
|
|
@@ -17,10 +18,46 @@ export function renderSceneSvg(input, options = {}) {
|
|
|
17
18
|
const result = layoutScene(measuredInput);
|
|
18
19
|
if (result.status !== 'laid-out')
|
|
19
20
|
throw new Error('Scene refused: ' + JSON.stringify(result.refusals));
|
|
20
|
-
const scene = resolveScene(result, measuredInput), box = scene.bounds ?? { x: 0, y: 0, width: 1, height: 1 };
|
|
21
21
|
const viewportWidth = input.targetWidth ?? 1440;
|
|
22
|
-
const
|
|
23
|
-
const
|
|
22
|
+
const viewport = { viewWidth: viewportWidth, windowHeight: options.windowHeight ?? 900, fitToWindow: options.fitToWindow ?? false };
|
|
23
|
+
const scene = resolveScene(result, measuredInput, viewport), box = scene.bounds ?? { x: 0, y: 0, width: 1, height: 1 };
|
|
24
|
+
const fit = sceneFit({ bounds: box, ...viewport });
|
|
25
|
+
const cornerRadius = input.metrics?.edgeCornerRadius ?? DEFAULT_EDGE_CORNER_RADIUS;
|
|
26
|
+
const linkStrokeWidth = input.metrics?.linkStrokeWidth ?? DEFAULT_LINK_STROKE_WIDTH;
|
|
27
|
+
const edgeLabelSize = scene.overviewEdgeLabelSize ?? (scene.r7Connectors ? input.metrics?.edgeLabelSize : undefined) ?? DEFAULT_EDGE_LABEL_SIZE;
|
|
28
|
+
const markerIds = connectorMarkerIds('scene-arrow');
|
|
29
|
+
const extraMarkers = extraConnectorMarkers(scene.edges, markerIds);
|
|
30
|
+
const extraMarkerDefs = extraMarkers.map(marker => {
|
|
31
|
+
const strokeAttrs = marker.stroke === undefined ? '' : ` stroke="${escape(marker.stroke)}" stroke-width="${marker.strokeWidth ?? 1.5}"`;
|
|
32
|
+
return `<marker id="${escape(marker.id)}" data-arrowhead-kind="${escape(marker.kind)}" data-arrowhead-emphasis="${escape(marker.emphasis)}" viewBox="${marker.viewBox}" refX="${marker.refX}" refY="${marker.refY}" markerUnits="${marker.markerUnits}" markerWidth="${marker.markerWidth}" markerHeight="${marker.markerHeight}" orient="${marker.orient}"><path d="${marker.path}" fill="${escape(marker.fill)}"${strokeAttrs}/></marker>`;
|
|
33
|
+
}).join('');
|
|
34
|
+
const edges = scene.edges.map(edge => {
|
|
35
|
+
if (!edge.r7) {
|
|
36
|
+
const markerAttr = edge.markers === undefined ? ' marker-end="url(#scene-arrow)"' : '';
|
|
37
|
+
return `<polyline data-scene-edge="${escape(edge.occurrence)}" points="${edge.points.map(p => p.x + ',' + p.y).join(' ')}" fill="none" stroke="var(--st-component-diagramScene-edgeStroke, #64748b)" stroke-width="1.5" stroke-linejoin="round"${markerAttr}/>${edge.markers ?? ''}`;
|
|
38
|
+
}
|
|
39
|
+
const emphasized = edge.emphasis === 'emphasis';
|
|
40
|
+
const stroke = emphasized ? LINK_EMPHASIS_STROKE : 'var(--st-component-diagramScene-edgeStroke, #64748b)';
|
|
41
|
+
const strokeWidth = connectorStrokeWidth(edge, input.metrics);
|
|
42
|
+
const dash = connectorDashArray(edge.strokeStyle);
|
|
43
|
+
const markerRef = connectorMarkerRef(edge, markerIds);
|
|
44
|
+
const attrs = [
|
|
45
|
+
`data-scene-edge="${escape(edge.occurrence)}"`,
|
|
46
|
+
'data-connector-mode="r7"',
|
|
47
|
+
`d="${connectorPath(edge.points, cornerRadius)}"`,
|
|
48
|
+
...(edge.strokeStyle === undefined ? [] : [`data-edge-stroke="${escape(edge.strokeStyle)}"`]),
|
|
49
|
+
...(edge.arrowhead === undefined ? [] : [`data-edge-arrowhead="${escape(edge.arrowhead)}"`]),
|
|
50
|
+
...(edge.emphasis === undefined ? [] : [`data-edge-emphasis="${escape(edge.emphasis)}"`]),
|
|
51
|
+
'fill="none"',
|
|
52
|
+
`stroke="${stroke}"`,
|
|
53
|
+
`stroke-width="${strokeWidth}"`,
|
|
54
|
+
'vector-effect="non-scaling-stroke"',
|
|
55
|
+
'stroke-linejoin="round"',
|
|
56
|
+
...(dash === undefined ? [] : [`stroke-dasharray="${dash}"`, `style="${connectorDashPaint(edge.strokeStyle)}"`]),
|
|
57
|
+
...(markerRef === undefined ? [] : [`marker-end="${markerRef}"`]),
|
|
58
|
+
].join(' ');
|
|
59
|
+
return `<path ${attrs}/>${edge.markers ?? ''}`;
|
|
60
|
+
}).join('');
|
|
24
61
|
const drawNode = (node) => {
|
|
25
62
|
const measure = measureFor(node.collapsed);
|
|
26
63
|
if (node.kind === 'erd' && node.erd !== undefined)
|
|
@@ -44,21 +81,54 @@ export function renderSceneSvg(input, options = {}) {
|
|
|
44
81
|
const boxes = sceneNodesOnPlane(scene.nodes, 'box').map(drawNode).join('');
|
|
45
82
|
const labels = scene.labels.map(label => {
|
|
46
83
|
const b = label.box;
|
|
84
|
+
const labelLineHeight = Math.round(22 * (edgeLabelSize / DEFAULT_EDGE_LABEL_SIZE));
|
|
85
|
+
const firstBaseline = Math.round(edgeLabelSize);
|
|
47
86
|
let text = '';
|
|
48
87
|
if (label.bundle) {
|
|
49
|
-
text = `<text x="${b.width / 2}" y="
|
|
88
|
+
text = `<text x="${b.width / 2}" y="${labelLineHeight}" text-anchor="middle">${escape(label.bundle.header)}</text>`;
|
|
50
89
|
label.bundle.groups.forEach((group, index) => {
|
|
51
|
-
text += `<g data-bundle-relation="${index}"><path d="M0 ${group.top}H${b.width}" stroke="var(--st-component-diagramScene-labelBorder, #cbd5e1)"/><text x="5" y="${group.top +
|
|
52
|
-
group.lines.forEach((line, i) => { text += `<text x="22" y="${group.top +
|
|
90
|
+
text += `<g data-bundle-relation="${index}"><path d="M0 ${group.top}H${b.width}" stroke="var(--st-component-diagramScene-labelBorder, #cbd5e1)"/><text x="5" y="${group.top + labelLineHeight}">•</text>`;
|
|
91
|
+
group.lines.forEach((line, i) => { text += `<text x="22" y="${group.top + labelLineHeight + i * labelLineHeight}">${escape(line)}</text>`; });
|
|
53
92
|
text += '</g>';
|
|
54
93
|
});
|
|
55
94
|
}
|
|
56
95
|
else
|
|
57
|
-
label.lines.forEach((line, i) => { text += `<text x="${b.width / 2}" y="${
|
|
58
|
-
const leader = label.leader === undefined ? '' :
|
|
59
|
-
|
|
96
|
+
label.lines.forEach((line, i) => { text += `<text x="${b.width / 2}" y="${firstBaseline + i * labelLineHeight}" text-anchor="middle">${escape(line)}</text>`; });
|
|
97
|
+
const leader = label.leader === undefined ? '' : (scene.r7Connectors && !label.erd
|
|
98
|
+
? `<path data-scene-leader="${escape(label.occurrence)}" data-connector-mode="r7" d="${connectorPath(label.leader, cornerRadius)}" fill="none" stroke="var(--st-component-diagramScene-edgeStroke, #64748b)" stroke-width="${linkStrokeWidth}" vector-effect="non-scaling-stroke" stroke-linejoin="round"/>`
|
|
99
|
+
: `<polyline points="${label.leader.map(p => p.x + ',' + p.y).join(' ')}" fill="none" stroke="var(--st-component-diagramScene-edgeStroke, #64748b)"/>`);
|
|
100
|
+
return leader + `<g data-scene-label="${escape(label.occurrence)}" transform="translate(${b.x} ${b.y})" font-size="${edgeLabelSize}" 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
101
|
}).join('');
|
|
61
|
-
const
|
|
102
|
+
const defaultMarker = scene.r7Connectors
|
|
103
|
+
? '<marker id="scene-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="userSpaceOnUse" markerWidth="10.5" markerHeight="10.5" orient="auto-start-reverse"><path d="M0 0L10 5L0 10Z" fill="var(--st-component-diagramScene-edgeStroke, #64748b)"/></marker>'
|
|
104
|
+
: '<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>';
|
|
105
|
+
const legend = (() => {
|
|
106
|
+
const l = scene.linkLegend;
|
|
107
|
+
if (l === undefined)
|
|
108
|
+
return '';
|
|
109
|
+
const r = l.rect;
|
|
110
|
+
const ruleY = l.padding + l.headerHeight - 0.5;
|
|
111
|
+
const titleY = l.padding + l.headerHeight / 2 + l.fontSize * 0.35;
|
|
112
|
+
const rows = l.entries.map(entry => {
|
|
113
|
+
const swatch = linkLegendSwatchGeometry(entry, input.metrics);
|
|
114
|
+
const swatchY = entry.rowY + (entry.rowHeight - swatch.height) / 2;
|
|
115
|
+
const lineAttrs = [
|
|
116
|
+
`data-legend-swatch="${escape(entry.key)}"`,
|
|
117
|
+
`d="${swatch.linePath}"`,
|
|
118
|
+
'fill="none"',
|
|
119
|
+
`stroke="${escape(swatch.stroke)}"`,
|
|
120
|
+
`stroke-width="${swatch.strokeWidth}"`,
|
|
121
|
+
'vector-effect="non-scaling-stroke"',
|
|
122
|
+
...(swatch.dashArray === undefined ? [] : [`stroke-dasharray="${escape(swatch.dashArray)}"`, `style="${connectorDashPaint(entry.strokeStyle)}"`]),
|
|
123
|
+
].join(' ');
|
|
124
|
+
const arrow = swatch.arrowPath === undefined ? '' : `<path d="${swatch.arrowPath}" fill="${escape(swatch.arrowFill ?? swatch.stroke)}"${swatch.arrowStroke === undefined ? '' : ` stroke="${escape(swatch.arrowStroke)}" stroke-width="${swatch.arrowStrokeWidth ?? 1.5}"`}/>`;
|
|
125
|
+
const textX = l.padding + l.swatchWidth + l.swatchGap;
|
|
126
|
+
const textY = entry.rowY + entry.rowHeight / 2 + l.fontSize * 0.35;
|
|
127
|
+
return `<g data-legend-style="${escape(entry.key)}" data-edge-stroke="${escape(entry.strokeStyle)}" data-edge-arrowhead="${escape(entry.arrowhead)}" data-edge-emphasis="${escape(entry.emphasis)}"><g transform="translate(${l.padding} ${swatchY})"><path ${lineAttrs}/>${arrow}</g><text x="${textX}" y="${textY}" font-size="${l.fontSize}" fill="var(--st-component-diagramScene-labelText, #172033)">${escape(entry.label)}</text></g>`;
|
|
128
|
+
}).join('');
|
|
129
|
+
return `<g data-scene-legend="" data-legend-anchor="${escape(l.anchor)}" transform="translate(${r.x} ${r.y})"><rect width="${r.width}" height="${r.height}" fill="var(--st-component-diagramScene-labelSurface, #ffffff)" stroke="var(--st-component-diagramScene-labelBorder, #cbd5e1)"/><text x="${l.padding}" y="${titleY}" font-size="${l.fontSize}" font-weight="700" fill="var(--st-component-diagramScene-labelText, #172033)">${escape(l.title)}</text><path d="M${l.padding} ${ruleY}H${r.width - l.padding}" stroke="var(--st-component-diagramScene-labelBorder, #cbd5e1)"/>${rows}</g>`;
|
|
130
|
+
})();
|
|
131
|
+
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>${scene.r7Connectors ? `@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-border-interactive:#2563eb;--st-semantic-feedback-info:#2563eb;--st-component-diagramScene-edgeStroke:#64748b;--st-component-diagramScene-linkStrokeWidth:2.5px;--st-component-diagramScene-linkRelatedStrokeWidth:3px;--st-component-diagramScene-linkPrimaryStrokeWidth:3.5px;--st-component-diagramScene-linkEmphasisStroke:${LINK_EMPHASIS_STROKE_FALLBACK};--st-component-diagramScene-linkEmphasisStrokeWidth:3.5px;--st-component-diagramScene-linkDashDashed:8 6;--st-component-diagramScene-linkDashDotted:2 5;--st-component-diagramScene-edgeCornerRadius:12px;--st-component-diagramScene-edgeLabelSize:18px}` : "@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>${defaultMarker}${extraMarkerDefs}${maskDef}</defs>${frames}${connectors}${boxes}${labels}${legend}</svg>`;
|
|
62
132
|
return { svg, result, scene };
|
|
63
133
|
}
|
|
64
134
|
//# sourceMappingURL=renderSceneSvg.js.map
|
|
@@ -4,5 +4,5 @@ import type { Rect, Vec2 } from '../transform.js';
|
|
|
4
4
|
export declare function clearSceneLabels<T extends {
|
|
5
5
|
readonly box: Rect;
|
|
6
6
|
readonly leader?: readonly Vec2[];
|
|
7
|
-
}>(labels: readonly T[], routes: readonly (readonly Vec2[])[], shapes: readonly Rect[], clearance: number): T[];
|
|
7
|
+
}>(labels: readonly T[], routes: readonly (readonly Vec2[])[], shapes: readonly Rect[], clearance: number, cornerRadius?: number, routeExtraMargins?: readonly number[]): T[];
|
|
8
8
|
//# sourceMappingURL=sceneLabelClearance.d.ts.map
|
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
import { normaliseRect } from '../geometry.js';
|
|
2
|
+
import { connectorCornerBounds } from './connectorPath.js';
|
|
2
3
|
/** Keep measured label sizes and routes; move only labels whose paint would
|
|
3
4
|
* cover a connector. The same deterministic placement is used by both hosts. */
|
|
4
|
-
export function clearSceneLabels(labels, routes, shapes, clearance) {
|
|
5
|
+
export function clearSceneLabels(labels, routes, shapes, clearance, cornerRadius = 0, routeExtraMargins) {
|
|
5
6
|
const bounds = shapes.map(normaliseRect);
|
|
6
|
-
for (
|
|
7
|
+
for (let r = 0; r < routes.length; r++) {
|
|
8
|
+
const route = routes[r];
|
|
9
|
+
const extra = Math.max(0, routeExtraMargins?.[r] ?? 0);
|
|
7
10
|
for (let i = 1; i < route.length; i++) {
|
|
8
11
|
const a = route[i - 1], b = route[i];
|
|
9
|
-
bounds.push({
|
|
12
|
+
bounds.push({
|
|
13
|
+
x: Math.min(a.x, b.x) - extra,
|
|
14
|
+
y: Math.min(a.y, b.y) - extra,
|
|
15
|
+
width: Math.abs(a.x - b.x) + 2 * extra,
|
|
16
|
+
height: Math.abs(a.y - b.y) + 2 * extra,
|
|
17
|
+
});
|
|
10
18
|
}
|
|
19
|
+
if (cornerRadius > 0) {
|
|
20
|
+
for (const bend of connectorCornerBounds(route, cornerRadius)) {
|
|
21
|
+
bounds.push(extra > 0
|
|
22
|
+
? { x: bend.x - extra, y: bend.y - extra, width: bend.width + 2 * extra, height: bend.height + 2 * extra }
|
|
23
|
+
: bend);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
11
27
|
// Normalise each obstacle once, rather than allocating two rectangles for
|
|
12
28
|
// every candidate/obstacle pair during the search. Use these same bounds
|
|
13
29
|
// for candidate generation, including persisted negative extents.
|
package/dist/r7Mode.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type DiagramAnatomyVersion, type DiagramPresentation, type RelationPresentation, type SemanticDocument, type ViewDocument } from "@sentropic/diagram-core";
|
|
2
|
+
export type R7PresentationLike = Pick<DiagramPresentation, "contractPin" | "entities"> & {
|
|
3
|
+
readonly relations?: Readonly<Record<string, RelationPresentation>>;
|
|
4
|
+
};
|
|
5
|
+
export type R7DocumentLike = Pick<SemanticDocument, "profileRefs" | "relations"> & Partial<Pick<SemanticDocument, "typeDefinitions" | "entities">>;
|
|
6
|
+
export declare function diagramAnatomyOf(presentation: R7PresentationLike, view: ViewDocument | undefined, occurrence: string): DiagramAnatomyVersion;
|
|
7
|
+
/**
|
|
8
|
+
* Compact anatomy or an authored connector style opts into DE-2. The
|
|
9
|
+
* presentation pin alone leaves full-size scenes unchanged (REQ-R7-28).
|
|
10
|
+
* ERD and views containing only numbered flows keep their own routing.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isR7ConnectorPresentation(presentation: R7PresentationLike | undefined, view?: ViewDocument, document?: R7DocumentLike): boolean;
|
|
13
|
+
//# sourceMappingURL=r7Mode.d.ts.map
|
package/dist/r7Mode.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { isPresentationContractV2Pin, } from "@sentropic/diagram-core";
|
|
2
|
+
import { entityVerdict, relationVerdict } from "./visibility.js";
|
|
3
|
+
export function diagramAnatomyOf(presentation, view, occurrence) {
|
|
4
|
+
const entry = presentation.entities?.[occurrence];
|
|
5
|
+
return entry?.anatomy
|
|
6
|
+
?? view?.presentation?.entityAnatomy?.[occurrence]
|
|
7
|
+
?? view?.presentation?.anatomy
|
|
8
|
+
?? "v1";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Compact anatomy or an authored connector style opts into DE-2. The
|
|
12
|
+
* presentation pin alone leaves full-size scenes unchanged (REQ-R7-28).
|
|
13
|
+
* ERD and views containing only numbered flows keep their own routing.
|
|
14
|
+
*/
|
|
15
|
+
export function isR7ConnectorPresentation(presentation, view, document) {
|
|
16
|
+
if (document?.profileRefs?.length === 1 && document.profileRefs[0] === "erd@1")
|
|
17
|
+
return false;
|
|
18
|
+
const hasFilters = (view?.filters?.length ?? 0) > 0;
|
|
19
|
+
const occurrences = view == null ? [] : Object.values(view.relationOccurrences ?? {}).filter((occ) => {
|
|
20
|
+
if (occ == null)
|
|
21
|
+
return false;
|
|
22
|
+
if (!hasFilters)
|
|
23
|
+
return true;
|
|
24
|
+
const relation = document?.relations?.[occ.relation];
|
|
25
|
+
if (relation !== undefined && !relationVerdict(view, relation, document).visible)
|
|
26
|
+
return false;
|
|
27
|
+
if (document?.entities != null && view.entityOccurrences != null) {
|
|
28
|
+
for (const endpoint of occ.endpoints ?? []) {
|
|
29
|
+
const ownerOccId = view.portOccurrences?.[endpoint.occurrence]?.ownerOccurrence ?? endpoint.occurrence;
|
|
30
|
+
const entityId = view.entityOccurrences[ownerOccId]?.entity;
|
|
31
|
+
const entity = entityId === undefined ? undefined : document.entities[entityId];
|
|
32
|
+
if (entity !== undefined && !entityVerdict(view, entity).visible)
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
});
|
|
38
|
+
if (document != null) {
|
|
39
|
+
const relations = view == null
|
|
40
|
+
? Object.values(document.relations ?? {})
|
|
41
|
+
: occurrences.map((occ) => document.relations?.[occ.relation]);
|
|
42
|
+
const types = relations.flatMap((relation) => relation == null ? [] : [relation.type]);
|
|
43
|
+
if (types.includes("flow-step") && types.every((type) => type === "flow-step" || type === "contains"))
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const effectivePresentation = presentation ?? view?.presentation?.diagram;
|
|
47
|
+
if (effectivePresentation != null) {
|
|
48
|
+
const entities = view?.entityOccurrences ?? effectivePresentation.entities;
|
|
49
|
+
if (Object.keys(entities ?? {}).some((id) => diagramAnatomyOf(effectivePresentation, view, id) === "v2"))
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
if (view?.presentation?.anatomy === "v2" && effectivePresentation == null)
|
|
53
|
+
return true;
|
|
54
|
+
const styles = presentation?.relations;
|
|
55
|
+
if (view == null && Object.keys(styles ?? {}).length > 0)
|
|
56
|
+
return true;
|
|
57
|
+
const authoredPin = view?.presentation?.diagram?.contractPin;
|
|
58
|
+
const suppliedPin = presentation?.contractPin;
|
|
59
|
+
const unpinnedDashes = authoredPin === undefined && (suppliedPin === undefined || isPresentationContractV2Pin(suppliedPin));
|
|
60
|
+
return occurrences.some((occ) => styles?.[occ.id] != null ||
|
|
61
|
+
styles?.[occ.relation] != null ||
|
|
62
|
+
occ.strokeStyle === "dotted" ||
|
|
63
|
+
(occ.strokeStyle === "dashed" && unpinnedDashes) ||
|
|
64
|
+
occ.arrowhead !== undefined ||
|
|
65
|
+
occ.emphasis !== undefined);
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=r7Mode.js.map
|
package/dist/visibility.d.ts
CHANGED
|
@@ -76,7 +76,7 @@ interface Verdict {
|
|
|
76
76
|
readonly cause?: string;
|
|
77
77
|
}
|
|
78
78
|
export declare function entityVerdict(view: ViewDocument, entity: Entity): Verdict;
|
|
79
|
-
export declare function relationVerdict(view: ViewDocument, relation: Relation, document?: SemanticDocument): Verdict;
|
|
79
|
+
export declare function relationVerdict(view: ViewDocument, relation: Relation, document?: Partial<Pick<SemanticDocument, "typeDefinitions">>): Verdict;
|
|
80
80
|
export interface VisibilityInput {
|
|
81
81
|
readonly document: SemanticDocument;
|
|
82
82
|
readonly view: ViewDocument;
|