@sentropic/diagram-canvas 0.1.0 → 0.2.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 +9 -0
- package/contracts/diagram-anatomy.v1.json +2073 -0
- package/dist/camera.d.ts +9 -6
- package/dist/camera.js +14 -9
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/layout/bundleLabel.d.ts +12 -0
- package/dist/layout/bundleLabel.js +16 -0
- package/dist/layout/cache.js +7 -7
- package/dist/layout/channels.d.ts +28 -0
- package/dist/layout/channels.js +14 -0
- package/dist/layout/dock.d.ts +1 -0
- package/dist/layout/dock.js +18 -37
- package/dist/layout/engine.js +4 -4
- package/dist/layout/erd.d.ts +5 -0
- package/dist/layout/erd.js +85 -0
- package/dist/layout/fingerprint.d.ts +2 -2
- package/dist/layout/fingerprint.js +6 -2
- package/dist/layout/flow-order.d.ts +3 -0
- package/dist/layout/flow-order.js +14 -0
- package/dist/layout/flows.d.ts +89 -0
- package/dist/layout/flows.js +120 -0
- package/dist/layout/graph.d.ts +2 -0
- package/dist/layout/graph.js +5 -2
- package/dist/layout/hints.js +7 -6
- package/dist/layout/index.d.ts +3 -0
- package/dist/layout/index.js +3 -0
- package/dist/layout/labels.d.ts +1 -0
- package/dist/layout/labels.js +1 -1
- package/dist/layout/measure.d.ts +3 -3
- package/dist/layout/measure.js +5 -3
- package/dist/layout/measured.js +406 -75
- package/dist/layout/route.d.ts +2 -0
- package/dist/layout/route.js +2 -70
- package/dist/layout/sceneMeasure.d.ts +13 -0
- package/dist/layout/sceneMeasure.js +57 -0
- package/dist/layout/spacing.generated.d.ts +13 -0
- package/dist/layout/spacing.generated.js +8 -0
- package/dist/layout/types.d.ts +33 -4
- package/dist/layout/types.js +4 -10
- package/dist/presentation/diagramCardModel.d.ts +660 -0
- package/dist/presentation/diagramCardModel.js +1150 -0
- package/dist/presentation/diagramSceneModel.d.ts +69 -2
- package/dist/presentation/diagramSceneModel.js +146 -25
- package/dist/presentation/diagramSceneTypes.d.ts +91 -0
- package/dist/presentation/diagramSceneTypes.js +2 -0
- package/dist/presentation/erd.d.ts +81 -0
- package/dist/presentation/erd.js +156 -0
- package/dist/presentation/flowModel.d.ts +82 -0
- package/dist/presentation/flowModel.js +206 -0
- package/dist/presentation/index.d.ts +20 -0
- package/dist/presentation/index.js +14 -0
- package/dist/presentation/registry.d.ts +52 -0
- package/dist/presentation/registry.js +81 -0
- package/dist/presentation/renderCardSvg.d.ts +73 -0
- package/dist/presentation/renderCardSvg.js +144 -0
- package/dist/presentation/renderSceneSvg.d.ts +38 -0
- package/dist/presentation/renderSceneSvg.js +56 -0
- package/dist/presentation/renderZoneSvg.d.ts +79 -0
- package/dist/presentation/renderZoneSvg.js +180 -0
- package/dist/visibility.d.ts +1 -1
- package/dist/visibility.js +5 -4
- package/package.json +30 -4
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { type FlowIndex, type FlowStep } from "@sentropic/diagram-core";
|
|
2
|
+
import type { FlowArrow, FlowBundle, FlowVisibleTarget } from "../layout/flows.js";
|
|
3
|
+
import type { Visible } from "./flowModel.js";
|
|
4
|
+
import { type ErdCard } from "./erd.js";
|
|
1
5
|
/**
|
|
2
6
|
* `DiagramSceneFigure` — the pure half of the scene host (DC-2a lot L4,
|
|
3
7
|
* SPEC_EVOL_DC2A §4.3, §5, §6.7, Appendix D).
|
|
@@ -12,6 +16,7 @@
|
|
|
12
16
|
* off the layout signature, so this package names no other diagram layer.
|
|
13
17
|
*/
|
|
14
18
|
import { layoutMeasured, type CameraFit, type LayoutCacheStats, type LayoutHints, type LayoutMetrics, type LayoutOptions, type LayoutResult, type LevelOrientation, type LineMeasurer, type Rect, type RowPackOptions, type Vec2 } from "../index.js";
|
|
19
|
+
import { type BundleLabelGroup } from "../layout/bundleLabel.js";
|
|
15
20
|
import type { EntityPresentation } from "@sentropic/diagram-core";
|
|
16
21
|
/** The semantic document the layout engine reads. */
|
|
17
22
|
export type SceneDocument = Parameters<typeof layoutMeasured>[0];
|
|
@@ -55,7 +60,28 @@ export interface DiagramSceneSize {
|
|
|
55
60
|
}
|
|
56
61
|
/** Drawing union size at zoom 1, available without measuring rendered elements. */
|
|
57
62
|
export declare function sceneContentSize(result: LayoutResult | undefined): DiagramSceneSize;
|
|
63
|
+
/** Presentation data keyed by profile:type (or type), kept outside semantic profiles. */
|
|
64
|
+
export type SceneIconBindings = Readonly<Record<string, {
|
|
65
|
+
readonly icon?: string;
|
|
66
|
+
readonly role?: string;
|
|
67
|
+
readonly shape?: "component" | "flow" | "erd" | "note";
|
|
68
|
+
}>>;
|
|
69
|
+
export declare const ROLE_ICONS: Readonly<Record<string, string>>;
|
|
70
|
+
export declare function resolveScenePresentation(document: SceneDocument, presentation: ScenePresentation, bindings?: SceneIconBindings, strict?: boolean, view?: SceneView, resolveGlyph?: (name: string) => import("./diagramCardModel.js").DiagramGlyphPaths | undefined): {
|
|
71
|
+
presentation: {
|
|
72
|
+
entities: {
|
|
73
|
+
[k: string]: EntityPresentation;
|
|
74
|
+
};
|
|
75
|
+
contractPin: import("@sentropic/diagram-core").PresentationPin;
|
|
76
|
+
legends: Readonly<Record<string, import("@sentropic/diagram-core").LegendPresentation>>;
|
|
77
|
+
categoryTokens: readonly import("@sentropic/diagram-core").CategoryTokenBinding[];
|
|
78
|
+
};
|
|
79
|
+
missing: string[];
|
|
80
|
+
};
|
|
58
81
|
export interface SceneLayoutInput {
|
|
82
|
+
readonly iconBindings?: SceneIconBindings;
|
|
83
|
+
readonly strictIcons?: boolean;
|
|
84
|
+
readonly resolveGlyph?: (name: string) => import("./diagramCardModel.js").DiagramGlyphPaths | undefined;
|
|
59
85
|
readonly cache?: SceneLayoutCache;
|
|
60
86
|
readonly document: SceneDocument;
|
|
61
87
|
/** Retained source view (authored occurrences, fold groups). Optional: the engine synthesises one. */
|
|
@@ -67,6 +93,8 @@ export interface SceneLayoutInput {
|
|
|
67
93
|
readonly collapsed: readonly SceneOccurrenceRef[];
|
|
68
94
|
readonly hints?: LayoutHints;
|
|
69
95
|
readonly metrics?: Partial<LayoutMetrics>;
|
|
96
|
+
readonly flows?: LayoutOptions["flows"];
|
|
97
|
+
readonly flowTokens?: LayoutOptions["flowTokens"];
|
|
70
98
|
readonly rowPack?: RowPackOptions;
|
|
71
99
|
readonly targetWidth?: number;
|
|
72
100
|
readonly previousOrientation?: SceneOrientations;
|
|
@@ -81,7 +109,7 @@ export interface SceneLayoutInput {
|
|
|
81
109
|
export declare function layoutScene(input: SceneLayoutInput): LayoutResult;
|
|
82
110
|
/** Collapsed occurrence ids recorded by a view's fold groups. */
|
|
83
111
|
export declare function collapsedOccurrencesOf(view: SceneView | undefined): SceneOccurrenceRef[];
|
|
84
|
-
export type SceneNodeKind = "card" | "zone" | "legend-key" | "label";
|
|
112
|
+
export type SceneNodeKind = "card" | "zone" | "legend-key" | "label" | "erd";
|
|
85
113
|
export interface SceneNodeModel {
|
|
86
114
|
readonly occurrence: SceneOccurrenceRef;
|
|
87
115
|
readonly entity: string;
|
|
@@ -92,17 +120,53 @@ export interface SceneNodeModel {
|
|
|
92
120
|
readonly presentation?: EntityPresentation;
|
|
93
121
|
/** Text of a node with no card form (L-R12 label) or of a legend key. */
|
|
94
122
|
readonly text: string;
|
|
123
|
+
readonly erd?: ErdCard;
|
|
95
124
|
}
|
|
96
125
|
export interface SceneEdgeModel {
|
|
126
|
+
readonly directed: boolean;
|
|
127
|
+
readonly arrows: readonly FlowArrow[];
|
|
128
|
+
readonly flow?: FlowStep;
|
|
129
|
+
readonly bundle?: FlowBundle;
|
|
97
130
|
readonly occurrence: SceneOccurrenceRef;
|
|
98
131
|
readonly points: readonly Vec2[];
|
|
132
|
+
readonly markers?: string;
|
|
99
133
|
}
|
|
100
134
|
export interface SceneLabelModel {
|
|
101
135
|
readonly occurrence: SceneOccurrenceRef;
|
|
102
136
|
readonly lines: readonly string[];
|
|
103
137
|
readonly box: Rect;
|
|
138
|
+
readonly title?: string;
|
|
139
|
+
readonly bundle?: {
|
|
140
|
+
readonly header: string;
|
|
141
|
+
readonly groups: readonly BundleLabelGroup[];
|
|
142
|
+
};
|
|
143
|
+
readonly leader?: readonly Vec2[];
|
|
144
|
+
readonly erd?: boolean;
|
|
145
|
+
}
|
|
146
|
+
export interface SceneBadgeModel {
|
|
147
|
+
readonly id: string;
|
|
148
|
+
readonly occurrence: SceneOccurrenceRef;
|
|
149
|
+
readonly kind: "step" | "count";
|
|
150
|
+
readonly text: string;
|
|
151
|
+
readonly box: Rect;
|
|
152
|
+
readonly target: Visible;
|
|
104
153
|
}
|
|
105
154
|
export interface SceneModel {
|
|
155
|
+
readonly badges: readonly SceneBadgeModel[];
|
|
156
|
+
readonly flows: FlowIndex;
|
|
157
|
+
readonly flowTargets: Readonly<Record<string, FlowVisibleTarget>>;
|
|
158
|
+
readonly nodeTargets: readonly {
|
|
159
|
+
readonly occurrence: SceneOccurrenceRef;
|
|
160
|
+
readonly entity: string;
|
|
161
|
+
readonly anchor: {
|
|
162
|
+
readonly x: number;
|
|
163
|
+
readonly y: number;
|
|
164
|
+
};
|
|
165
|
+
}[];
|
|
166
|
+
readonly flowRepresentatives: Readonly<Record<string, string>>;
|
|
167
|
+
readonly flowEnds: Readonly<Record<string, readonly string[]>>;
|
|
168
|
+
readonly flowAncestors: Readonly<Record<string, readonly string[]>>;
|
|
169
|
+
readonly flowSummaryLabels: Readonly<Record<string, string>>;
|
|
106
170
|
readonly contentSize: DiagramSceneSize;
|
|
107
171
|
/** Bottom to top, in the scene's paint order. */
|
|
108
172
|
readonly nodes: readonly SceneNodeModel[];
|
|
@@ -123,7 +187,9 @@ export interface SceneModel {
|
|
|
123
187
|
* collapsed boxes and the title band of each expanded zone — an expanded
|
|
124
188
|
* zone's interior is not a blocker on the row-pack path).
|
|
125
189
|
*/
|
|
126
|
-
export declare function resolveScene(result: SceneLaidOut, input: Pick<SceneLayoutInput, "document" | "presentation" | "measureLines" | "metrics">): SceneModel;
|
|
190
|
+
export declare function resolveScene(result: SceneLaidOut, input: Pick<SceneLayoutInput, "document" | "presentation" | "measureLines" | "metrics" | "iconBindings" | "strictIcons" | "view" | "resolveGlyph" | "flows">): SceneModel;
|
|
191
|
+
/** Full presentation text retained alongside the textual relations (A14). */
|
|
192
|
+
export declare function sceneTextRows(scene: SceneModel, document: SceneDocument): readonly string[];
|
|
127
193
|
export interface SceneCameraInput {
|
|
128
194
|
readonly bounds?: Rect;
|
|
129
195
|
readonly viewWidth: number;
|
|
@@ -178,4 +244,5 @@ export declare function displayedRects(from: ReadonlyMap<string, Rect>, to: Read
|
|
|
178
244
|
export declare function rectsOf(scene: SceneModel): ReadonlyMap<string, Rect>;
|
|
179
245
|
/** Whether two rectangle sets are the same drawing: same ids, same numbers. */
|
|
180
246
|
export declare function sameRects(left: ReadonlyMap<string, Rect>, right: ReadonlyMap<string, Rect>): boolean;
|
|
247
|
+
export type { DiagramSceneFigureProps, DiagramSceneFigureLabels, DiagramSceneCamera } from "./diagramSceneTypes.js";
|
|
181
248
|
//# sourceMappingURL=diagramSceneModel.d.ts.map
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { flowIndex, parentOccurrenceOf, representativeOf } from "@sentropic/diagram-core";
|
|
2
|
+
import { measureErdCard, renderErdMarkerSvg, erdText, wrapErdText, placeErdRoleLabels, ERD_GEOMETRY } from "./erd.js";
|
|
1
3
|
/**
|
|
2
4
|
* `DiagramSceneFigure` — the pure half of the scene host (DC-2a lot L4,
|
|
3
5
|
* SPEC_EVOL_DC2A §4.3, §5, §6.7, Appendix D).
|
|
@@ -11,7 +13,11 @@
|
|
|
11
13
|
* (layout, scene, camera). The semantic-document and view types are read
|
|
12
14
|
* off the layout signature, so this package names no other diagram layer.
|
|
13
15
|
*/
|
|
14
|
-
import { buildScene, cameraFit, clampZoom, CONTENT_INSET, DEFAULT_ALLOCATED_LINES, DEFAULT_LAYOUT_METRICS, layoutFolded, layoutMeasured, placeEdgeLabels, rectUnion, relationRoute, sceneNodes, } from "../index.js";
|
|
16
|
+
import { buildScene, cameraFit, clampZoom, CONTENT_INSET, DEFAULT_ALLOCATED_LINES, DEFAULT_LAYOUT_METRICS, DEFAULT_MIN_READABLE_SCALE, layoutFolded, layoutMeasured, placeEdgeLabels, rectUnion, relationRoute, sceneNodes, sceneEdges, } from "../index.js";
|
|
17
|
+
import { measureBundleLabel } from "../layout/bundleLabel.js";
|
|
18
|
+
import { getDiagramGlyph } from "./registry.js";
|
|
19
|
+
import { ZONE_GEOMETRY } from "./diagramCardModel.js";
|
|
20
|
+
import { measureSceneBox } from "../layout/sceneMeasure.js";
|
|
15
21
|
/**
|
|
16
22
|
* `targetWidth` handed to the engine when the host supplies none. The
|
|
17
23
|
* measured path never re-packs on it (D-3) and the host never reads the
|
|
@@ -32,6 +38,29 @@ export const WHEEL_ZOOM_RATE = 0.0015;
|
|
|
32
38
|
export function sceneContentSize(result) {
|
|
33
39
|
return result?.status === "laid-out" ? { width: result.fit.width, height: result.fit.height } : { width: 0, height: 0 };
|
|
34
40
|
}
|
|
41
|
+
export const ROLE_ICONS = { card: "base", zone: "cluster", store: "db", actor: "user", api: "api", runtime: "server" };
|
|
42
|
+
export function resolveScenePresentation(document, presentation, bindings = {}, strict = true, view, resolveGlyph = getDiagramGlyph) {
|
|
43
|
+
const missing = [];
|
|
44
|
+
const entities = Object.fromEntries(Object.entries(presentation.entities).map(([id, entry]) => {
|
|
45
|
+
if (entry.form !== "card" && entry.form !== "container" && entry.form !== "legend")
|
|
46
|
+
return [id, entry];
|
|
47
|
+
const entityId = view?.entityOccurrences[id]?.entity ?? id.replace(/^occurrence:e\./, "entity:");
|
|
48
|
+
const entity = document.entities[entityId];
|
|
49
|
+
if (entity?.profile === "erd@1")
|
|
50
|
+
return [id, entry];
|
|
51
|
+
const binding = bindings[entity === undefined ? "" : entity.profile + ":" + entity.type] ?? bindings[entity?.type ?? ""];
|
|
52
|
+
if (binding?.shape !== undefined && binding.shape !== "component")
|
|
53
|
+
return [id, { ...entry, icon: entry.icon ?? "none" }];
|
|
54
|
+
const role = binding?.role ?? (entry.form === "card" ? "card" : "zone");
|
|
55
|
+
const icon = entry.icon ?? binding?.icon ?? ROLE_ICONS[role];
|
|
56
|
+
if (icon === undefined || resolveGlyph(icon) === undefined) {
|
|
57
|
+
missing.push(id);
|
|
58
|
+
return [id, { ...entry, icon: strict ? "unknown" : "none" }];
|
|
59
|
+
}
|
|
60
|
+
return [id, { ...entry, icon }];
|
|
61
|
+
}));
|
|
62
|
+
return { presentation: { ...presentation, entities }, missing };
|
|
63
|
+
}
|
|
35
64
|
/**
|
|
36
65
|
* One full layout pass (§6.5: fold → measure → place → route, never patched).
|
|
37
66
|
* Row-pack is always selected: an absent `rowPack` resolves to the DS
|
|
@@ -40,8 +69,11 @@ export function sceneContentSize(result) {
|
|
|
40
69
|
* required field carries no second metric source.
|
|
41
70
|
*/
|
|
42
71
|
export function layoutScene(input) {
|
|
72
|
+
const resolved = resolveScenePresentation(input.document, input.presentation, input.iconBindings, input.strictIcons, input.view, input.resolveGlyph);
|
|
43
73
|
const options = {
|
|
44
74
|
registry: input.registry,
|
|
75
|
+
...(input.flows === undefined ? {} : { flows: input.flows }),
|
|
76
|
+
...(input.flowTokens === undefined ? {} : { flowTokens: input.flowTokens }),
|
|
45
77
|
...(input.bindings === undefined ? {} : { bindings: input.bindings }),
|
|
46
78
|
measureText: (text) => {
|
|
47
79
|
const layout = input.measureLines({
|
|
@@ -53,7 +85,7 @@ export function layoutScene(input) {
|
|
|
53
85
|
});
|
|
54
86
|
return { width: layout.width, height: layout.height };
|
|
55
87
|
},
|
|
56
|
-
presentation:
|
|
88
|
+
presentation: resolved.presentation,
|
|
57
89
|
measureLines: input.measureLines,
|
|
58
90
|
collapsed: input.collapsed,
|
|
59
91
|
...(input.hints === undefined ? {} : { hints: input.hints }),
|
|
@@ -62,14 +94,14 @@ export function layoutScene(input) {
|
|
|
62
94
|
targetWidth: input.targetWidth ?? DEFAULT_SCENE_TARGET_WIDTH,
|
|
63
95
|
...(input.previousOrientation === undefined ? {} : { previousOrientation: input.previousOrientation }),
|
|
64
96
|
};
|
|
65
|
-
|
|
66
|
-
|
|
97
|
+
const result = input.cache !== undefined
|
|
98
|
+
? (input.view === undefined
|
|
67
99
|
? input.cache.layout(input.document, options)
|
|
68
|
-
: input.cache.layoutFolded(input.document, input.view, options)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
100
|
+
: input.cache.layoutFolded(input.document, input.view, options))
|
|
101
|
+
: input.view === undefined
|
|
102
|
+
? layoutMeasured(input.document, options)
|
|
103
|
+
: layoutFolded(input.document, input.view, options);
|
|
104
|
+
return result.status !== "laid-out" || resolved.missing.length === 0 ? result : { ...result, warnings: [...result.warnings, ...resolved.missing.map(id => ({ code: "card-icon-missing", refs: [id], message: "No icon resolves for this component; strict mode displays unknown" }))] };
|
|
73
105
|
}
|
|
74
106
|
/** Collapsed occurrence ids recorded by a view's fold groups. */
|
|
75
107
|
export function collapsedOccurrencesOf(view) {
|
|
@@ -101,13 +133,18 @@ function edgeLabelOf(document, relation) {
|
|
|
101
133
|
*/
|
|
102
134
|
export function resolveScene(result, input) {
|
|
103
135
|
const view = result.view;
|
|
136
|
+
const resolved = resolveScenePresentation(input.document, input.presentation, input.iconBindings, input.strictIcons, input.view, input.resolveGlyph);
|
|
104
137
|
const frame = buildScene({ document: input.document, views: { [view.viewId]: view } }, view.viewId);
|
|
138
|
+
const bundledMembers = new Set(Object.values(result.edgeBundles ?? {}).flatMap(bundle => bundle.members.slice(1)));
|
|
139
|
+
const items = frame.items.filter(item => item.kind !== "edge" || !bundledMembers.has(item.occurrence));
|
|
140
|
+
const visibleEdges = new Set(items.filter(item => item.kind === "edge").map(item => item.occurrence));
|
|
105
141
|
const collapsed = new Set(collapsedOccurrencesOf(view));
|
|
106
142
|
const nodes = sceneNodes(frame).map((node) => {
|
|
107
|
-
const presentation =
|
|
143
|
+
const presentation = resolved.presentation.entities[node.occurrence];
|
|
108
144
|
const form = presentation?.form;
|
|
109
145
|
const titled = presentation?.text.title !== undefined && presentation.text.title !== "";
|
|
110
|
-
const
|
|
146
|
+
const erd = input.document.entities[node.entity]?.profile === "erd@1";
|
|
147
|
+
const kind = erd ? "erd" : form === "legend-key"
|
|
111
148
|
? "legend-key"
|
|
112
149
|
: !titled
|
|
113
150
|
? "label"
|
|
@@ -120,7 +157,8 @@ export function resolveScene(result, input) {
|
|
|
120
157
|
occurrence: node.occurrence,
|
|
121
158
|
entity: node.entity,
|
|
122
159
|
kind,
|
|
123
|
-
collapsed: kind === "zone" && collapsed.has(node.occurrence),
|
|
160
|
+
collapsed: (kind === "zone" || kind === "erd") && collapsed.has(node.occurrence),
|
|
161
|
+
...(erd ? { erd: measureErdCard(input.document, node.entity, collapsed.has(node.occurrence), input.measureLines) } : {}),
|
|
124
162
|
rect: node.rect,
|
|
125
163
|
...(presentation === undefined ? {} : { presentation }),
|
|
126
164
|
text: presentation?.text.title ?? presentation?.text.body ?? "",
|
|
@@ -129,7 +167,7 @@ export function resolveScene(result, input) {
|
|
|
129
167
|
const measuredLabels = new Map((result.measurements?.slots ?? []).filter((slot) => slot.role === "edge-label").map((slot) => [slot.occurrence, slot.layout]));
|
|
130
168
|
const headerHeights = new Map((result.measurements?.headers ?? []).map((header) => [header.occurrence, header.height]));
|
|
131
169
|
const blockers = [];
|
|
132
|
-
for (const node of nodes) {
|
|
170
|
+
for (const node of result.labelBoxes === undefined || input.document.profileRefs.includes("erd@1") ? nodes : []) {
|
|
133
171
|
if (node.kind !== "zone" || node.collapsed) {
|
|
134
172
|
blockers.push(node.rect);
|
|
135
173
|
continue;
|
|
@@ -137,27 +175,74 @@ export function resolveScene(result, input) {
|
|
|
137
175
|
const height = headerHeights.get(node.occurrence);
|
|
138
176
|
if (height === undefined)
|
|
139
177
|
continue;
|
|
178
|
+
const ruleClearance = (ZONE_GEOMETRY.ruleHeight / 2 + 1) / DEFAULT_MIN_READABLE_SCALE;
|
|
140
179
|
blockers.push({
|
|
141
|
-
x: node.rect.x
|
|
142
|
-
y: node.rect.y
|
|
143
|
-
width: node.rect.width
|
|
144
|
-
height,
|
|
180
|
+
x: node.rect.x,
|
|
181
|
+
y: node.rect.y,
|
|
182
|
+
width: node.rect.width,
|
|
183
|
+
height: CONTENT_INSET + height + ZONE_GEOMETRY.ruleHeight / 2 + ruleClearance,
|
|
145
184
|
});
|
|
185
|
+
const reserve = measureSceneBox(node.presentation, node.occurrence, node.rect.width, false, input.measureLines, input.metrics?.containerPadding).footerReserve;
|
|
186
|
+
if (reserve > 0)
|
|
187
|
+
blockers.push({ x: node.rect.x, y: node.rect.y + node.rect.height - reserve - ZONE_GEOMETRY.borderWidth - ruleClearance,
|
|
188
|
+
width: node.rect.width, height: reserve + ZONE_GEOMETRY.borderWidth + ruleClearance });
|
|
189
|
+
}
|
|
190
|
+
const allFlows = flowIndex(input.document);
|
|
191
|
+
const flowTargets = result.flowTargets ?? {};
|
|
192
|
+
const flows = {
|
|
193
|
+
scenarios: allFlows.scenarios.map((scenario) => ({ ...scenario, steps: scenario.steps.filter((step) => flowTargets[step.relation] !== undefined) })),
|
|
194
|
+
byRelation: Object.fromEntries(Object.entries(allFlows.byRelation).filter(([id]) => flowTargets[id] !== undefined)),
|
|
195
|
+
byEntity: Object.fromEntries(Object.entries(allFlows.byEntity).map(([id, steps]) => [id, steps.filter((step) => flowTargets[step] !== undefined)])),
|
|
196
|
+
};
|
|
197
|
+
const flowAncestors = {};
|
|
198
|
+
for (const node of nodes) {
|
|
199
|
+
const parents = [];
|
|
200
|
+
for (let parent = parentOccurrenceOf(view, node.occurrence); parent !== undefined; parent = parentOccurrenceOf(view, parent))
|
|
201
|
+
parents.push(parent);
|
|
202
|
+
flowAncestors[node.occurrence] = parents;
|
|
203
|
+
}
|
|
204
|
+
const flowRepresentatives = Object.fromEntries(nodes.map((node) => [node.entity, node.occurrence]));
|
|
205
|
+
for (const occurrence of Object.values(view.entityOccurrences).sort((a, b) => byCodeUnit(a.id, b.id))) {
|
|
206
|
+
const box = representativeOf(view, collapsed, occurrence.id);
|
|
207
|
+
if (flowRepresentatives[occurrence.entity] === undefined && nodes.some((node) => node.occurrence === box))
|
|
208
|
+
flowRepresentatives[occurrence.entity] = box;
|
|
209
|
+
}
|
|
210
|
+
const flowEnds = {};
|
|
211
|
+
for (const [id, target] of Object.entries(flowTargets)) {
|
|
212
|
+
if (target.kind === "internal") {
|
|
213
|
+
flowEnds[id] = [target.box];
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
const occurrence = view.relationOccurrences[target.occurrence];
|
|
217
|
+
flowEnds[id] = occurrence?.endpoints.map((end) => view.portOccurrences[end.occurrence]?.ownerOccurrence ?? end.occurrence) ?? [];
|
|
146
218
|
}
|
|
147
219
|
const edges = [];
|
|
148
220
|
const entries = [];
|
|
149
221
|
const labelLines = new Map();
|
|
150
222
|
for (const id of Object.keys(view.relationOccurrences).sort(byCodeUnit)) {
|
|
223
|
+
if (!visibleEdges.has(id))
|
|
224
|
+
continue;
|
|
151
225
|
const occurrence = view.relationOccurrences[id];
|
|
152
|
-
if (occurrence.waypoints === undefined)
|
|
226
|
+
if (occurrence.waypoints === undefined || !visibleEdges.has(id))
|
|
153
227
|
continue;
|
|
154
228
|
const points = relationRoute(view, occurrence.id) ?? [];
|
|
155
229
|
if (points.length < 2)
|
|
156
230
|
continue;
|
|
157
|
-
|
|
231
|
+
const flow = flows.byRelation[occurrence.relation];
|
|
232
|
+
const bundle = result.flowBundles?.find((entry) => entry.carrier === occurrence.id);
|
|
233
|
+
// Preserve both flow presentation and ERD endpoint markers.
|
|
234
|
+
const semantic = input.document.relations[occurrence.relation];
|
|
235
|
+
let markers;
|
|
236
|
+
if (semantic?.profile === 'erd@1') {
|
|
237
|
+
const first = points[0], second = points[1], last = points[points.length - 1], before = points[points.length - 2];
|
|
238
|
+
markers = renderErdMarkerSvg(erdText(semantic.attributes, 'fromCardinality'), first, { x: second.x - first.x, y: second.y - first.y }) + renderErdMarkerSvg(erdText(semantic.attributes, 'toCardinality'), last, { x: before.x - last.x, y: before.y - last.y });
|
|
239
|
+
}
|
|
240
|
+
edges.push({ ...(markers === undefined ? {} : { markers }), occurrence: occurrence.id, points, directed: flow !== undefined, arrows: result.arrowBoxes?.[occurrence.id] ?? [], ...(flow === undefined ? {} : { flow }), ...(bundle === undefined ? {} : { bundle }) });
|
|
158
241
|
if (result.labelBoxes !== undefined && result.labelBoxes[id] === undefined)
|
|
159
242
|
continue;
|
|
160
|
-
const label =
|
|
243
|
+
const label = result.edgeBundles?.[id]?.label ?? (semantic?.profile === 'erd@1'
|
|
244
|
+
? ['fromRole', 'toRole'].map(role => erdText(semantic.attributes, role)).filter(Boolean).join(' / ') || edgeLabelOf(input.document, occurrence.relation)
|
|
245
|
+
: edgeLabelOf(input.document, occurrence.relation));
|
|
161
246
|
if (label === undefined)
|
|
162
247
|
continue;
|
|
163
248
|
const layout = measuredLabels.get(id) ?? input.measureLines({
|
|
@@ -167,22 +252,49 @@ export function resolveScene(result, input) {
|
|
|
167
252
|
allocatedLines: DEFAULT_ALLOCATED_LINES["edge-label"],
|
|
168
253
|
folded: false,
|
|
169
254
|
});
|
|
170
|
-
|
|
171
|
-
|
|
255
|
+
const lines = semantic?.profile === 'erd@1' ? wrapErdText(label, ERD_GEOMETRY.labelWidth, input.measureLines) : layout.lines;
|
|
256
|
+
labelLines.set(id, lines);
|
|
257
|
+
entries.push({ id, route: points, size: semantic?.profile === 'erd@1' ? { width: ERD_GEOMETRY.labelWidth, height: lines.length * ERD_GEOMETRY.lineHeight } : { width: layout.width, height: layout.height } });
|
|
172
258
|
}
|
|
173
259
|
const margin = input.metrics?.labelMargin ?? DEFAULT_LAYOUT_METRICS.labelMargin;
|
|
174
260
|
const labels = [];
|
|
175
|
-
let bounds
|
|
176
|
-
const
|
|
261
|
+
let bounds;
|
|
262
|
+
for (const item of items) {
|
|
263
|
+
const box = item.kind === "edge" ? item.bounds : item.rect;
|
|
264
|
+
bounds = bounds === undefined ? box : rectUnion(bounds, box);
|
|
265
|
+
}
|
|
266
|
+
const erd = input.document.profileRefs.length === 1 && input.document.profileRefs[0] === 'erd@1';
|
|
267
|
+
const placements = erd ? placeErdRoleLabels(entries, blockers, margin) : result.labelBoxes === undefined
|
|
177
268
|
? placeEdgeLabels(entries, blockers, margin)
|
|
178
269
|
: new Map(Object.entries(result.labelBoxes).map(([id, box]) => [id, { box }]));
|
|
179
270
|
for (const [id, placement] of placements) {
|
|
180
271
|
if (placement === undefined)
|
|
181
272
|
continue;
|
|
182
|
-
labels.push({ occurrence: id, lines: labelLines.get(id) ?? [], box: placement.box })
|
|
273
|
+
labels.push({ occurrence: id, lines: labelLines.get(id) ?? [], box: placement.box, ...(erd ? { erd: true } : {}), ...("leader" in placement ? { leader: placement.leader } : {}),
|
|
274
|
+
...(result.edgeBundles?.[id] === undefined ? {} : { title: result.edgeBundles[id].title }),
|
|
275
|
+
...(result.edgeBundles?.[id]?.relations === undefined ? {} : { bundle: result.edgeBundles[id].chip ?? measureBundleLabel(result.edgeBundles[id].relations, input.measureLines, input.metrics?.bundleLabelMaxWidth) }) });
|
|
183
276
|
bounds = bounds === undefined ? placement.box : rectUnion(bounds, placement.box);
|
|
184
277
|
}
|
|
278
|
+
const badges = [];
|
|
279
|
+
for (const step of flows.scenarios.flatMap((scenario) => scenario.steps)) {
|
|
280
|
+
const target = flowTargets[step.relation];
|
|
281
|
+
if (target === undefined || target.kind === "internal" || !target.badge || badges.some((badge) => badge.occurrence === target.occurrence))
|
|
282
|
+
continue;
|
|
283
|
+
const box = result.badgeBoxes?.[target.occurrence];
|
|
284
|
+
if (box === undefined)
|
|
285
|
+
continue;
|
|
286
|
+
const bundle = result.flowBundles?.find((entry) => entry.id === (target.kind === "bundle" ? target.id : ""));
|
|
287
|
+
const text = bundle === undefined ? step.badge : (input.flows?.countTemplate ?? "{n}").replaceAll("{n}", String(bundle.members.length));
|
|
288
|
+
badges.push({ id: target.occurrence, occurrence: target.occurrence, kind: bundle === undefined ? "step" : "count", text, box, target: target.kind === "bundle" ? { kind: "bundle", id: target.id } : { kind: "edge", occurrence: target.occurrence } });
|
|
289
|
+
bounds = bounds === undefined ? box : rectUnion(bounds, box);
|
|
290
|
+
}
|
|
291
|
+
for (const arrows of Object.values(result.arrowBoxes ?? {}))
|
|
292
|
+
for (const arrow of arrows)
|
|
293
|
+
bounds = bounds === undefined ? arrow.box : rectUnion(bounds, arrow.box);
|
|
294
|
+
const nodeTargets = nodes.filter((node) => Object.values(flowEnds).some((ends) => ends.some((id) => id === node.occurrence || (flowAncestors[id] ?? []).includes(node.occurrence)))).map((node) => ({ occurrence: node.occurrence, entity: node.entity, anchor: { x: node.rect.x, y: node.rect.y } }));
|
|
185
295
|
return {
|
|
296
|
+
badges, flows, flowTargets, nodeTargets, flowEnds, flowRepresentatives, flowAncestors,
|
|
297
|
+
flowSummaryLabels: Object.fromEntries(Object.entries(view.summaryLabels ?? {}).map(([id, definition]) => [id, definition.label])),
|
|
186
298
|
contentSize: sceneContentSize(result),
|
|
187
299
|
nodes,
|
|
188
300
|
edges,
|
|
@@ -191,6 +303,15 @@ export function resolveScene(result, input) {
|
|
|
191
303
|
orientations: result.orientations ?? {},
|
|
192
304
|
};
|
|
193
305
|
}
|
|
306
|
+
/** Full presentation text retained alongside the textual relations (A14). */
|
|
307
|
+
export function sceneTextRows(scene, document) {
|
|
308
|
+
const rows = scene.nodes.map(node => Object.values(node.presentation?.text ?? {}).filter(Boolean).join(" · "));
|
|
309
|
+
for (const relation of Object.values(document.relations)) {
|
|
310
|
+
const names = relation.endpoints.map(end => { const value = document.entities[end.target]?.attributes["name"]; return value?.kind === "text" ? String(value.value) : end.target; });
|
|
311
|
+
rows.push(names.join(" → ") + " · " + (edgeLabelOf(document, relation.id) ?? relation.type));
|
|
312
|
+
}
|
|
313
|
+
return rows;
|
|
314
|
+
}
|
|
194
315
|
/** §5.1 / BF-2 fit of the scene bounds, as `cameraFit` computes it. */
|
|
195
316
|
export function sceneFit(input) {
|
|
196
317
|
return cameraFit({
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { LayoutOptions, LayoutHints, LayoutMetrics, LayoutResult, LineMeasurer, RowPackOptions } from '../index.js';
|
|
2
|
+
import type { CardLineMeasure, DiagramGlyphPaths } from './diagramCardModel.js';
|
|
3
|
+
import type { StepChange, EffectiveTarget } from './flowModel.js';
|
|
4
|
+
import type { SceneDocument, SceneView, ScenePresentation, SceneOccurrenceRef, SceneLayoutCache, DiagramSceneSize } from './diagramSceneModel.js';
|
|
5
|
+
export interface DiagramSceneFigureLabels {
|
|
6
|
+
"navigator": string;
|
|
7
|
+
step: string;
|
|
8
|
+
scenario: string;
|
|
9
|
+
count: string;
|
|
10
|
+
node: string;
|
|
11
|
+
previous: string;
|
|
12
|
+
next: string;
|
|
13
|
+
allScenarios: string;
|
|
14
|
+
/** Accessible name of the camera control group. */
|
|
15
|
+
controls: string;
|
|
16
|
+
zoomIn: string;
|
|
17
|
+
zoomOut: string;
|
|
18
|
+
/** Visible text of the fit / reset control (« Ajuster »). */
|
|
19
|
+
fit: string;
|
|
20
|
+
/** Accessible name of the readout, e.g. « Zoom 85 % ». */
|
|
21
|
+
zoomLevel: (percent: number) => string;
|
|
22
|
+
/** Accessible name of the scrollable drawing region. */
|
|
23
|
+
viewport: string;
|
|
24
|
+
expand: (title: string) => string;
|
|
25
|
+
collapse: (title: string) => string;
|
|
26
|
+
}
|
|
27
|
+
export interface DiagramSceneCamera {
|
|
28
|
+
readonly zoom: number;
|
|
29
|
+
/** `round(zoom / maxDisplayScale × 100)`. */
|
|
30
|
+
readonly readout: number;
|
|
31
|
+
readonly minZoom: number;
|
|
32
|
+
readonly maxZoom: number;
|
|
33
|
+
/** The zoom a fit or reset applies. */
|
|
34
|
+
readonly fitZoom: number;
|
|
35
|
+
readonly pans: boolean;
|
|
36
|
+
}
|
|
37
|
+
export interface DiagramSceneFigureProps {
|
|
38
|
+
flows?: {
|
|
39
|
+
fanOutMax?: number;
|
|
40
|
+
};
|
|
41
|
+
scenario?: string | null;
|
|
42
|
+
defaultScenario?: string;
|
|
43
|
+
activeStep?: string | null;
|
|
44
|
+
defaultActiveStep?: string;
|
|
45
|
+
onStepChange?: (change: StepChange | null) => void;
|
|
46
|
+
onScenarioChange?: (scenario: string | null) => void;
|
|
47
|
+
onHighlightChange?: (target: EffectiveTarget | null) => void;
|
|
48
|
+
document: SceneDocument;
|
|
49
|
+
/** Retained source view (occurrences, fold groups). Optional: the engine synthesises one. */
|
|
50
|
+
view?: SceneView;
|
|
51
|
+
registry: LayoutOptions["registry"];
|
|
52
|
+
bindings?: LayoutOptions["bindings"];
|
|
53
|
+
presentation: ScenePresentation;
|
|
54
|
+
/** Declaration order (`rootOrder`, `ordering[parent]`) and the other layout hints. */
|
|
55
|
+
hints?: LayoutHints;
|
|
56
|
+
/** Runtime token numbers for the engine (gaps, caps). */
|
|
57
|
+
metrics?: Partial<LayoutMetrics>;
|
|
58
|
+
rowPack?: RowPackOptions;
|
|
59
|
+
/** L-R7 report width. The measured path never re-packs on it (D-3). */
|
|
60
|
+
targetWidth?: number;
|
|
61
|
+
/** Card text measurer, shared by the cards, the zones and the layout. */
|
|
62
|
+
measure?: CardLineMeasure;
|
|
63
|
+
iconBindings?: import("./diagramSceneModel.js").SceneIconBindings;
|
|
64
|
+
strictIcons?: boolean;
|
|
65
|
+
/** Layout line measurer. Defaults to the bridge over `measure`. */
|
|
66
|
+
measureLines?: LineMeasurer;
|
|
67
|
+
/** Controlled fold state: collapsed occurrence ids. */
|
|
68
|
+
collapsed?: readonly SceneOccurrenceRef[];
|
|
69
|
+
/** Initial collapsed occurrence ids when `collapsed` is not controlled. */
|
|
70
|
+
defaultFolds?: readonly SceneOccurrenceRef[];
|
|
71
|
+
title?: string;
|
|
72
|
+
/** Accessible name of the figure. Defaults to `title`. */
|
|
73
|
+
label?: string;
|
|
74
|
+
compact?: boolean;
|
|
75
|
+
labels?: Partial<DiagramSceneFigureLabels>;
|
|
76
|
+
resolveGlyph?: (name: string) => DiagramGlyphPaths | undefined;
|
|
77
|
+
onFoldChange?: (collapsed: readonly SceneOccurrenceRef[], change: {
|
|
78
|
+
occurrence: SceneOccurrenceRef;
|
|
79
|
+
collapsed: boolean;
|
|
80
|
+
}) => void;
|
|
81
|
+
onSelect?: (event: {
|
|
82
|
+
entityId: string;
|
|
83
|
+
}) => void;
|
|
84
|
+
/** One call per layout pass, with the engine result (warnings, refusals, orientations). */
|
|
85
|
+
onLayout?: (result: LayoutResult) => void;
|
|
86
|
+
onCameraChange?: (camera: DiagramSceneCamera) => void;
|
|
87
|
+
layoutCache?: SceneLayoutCache;
|
|
88
|
+
contentSize?: DiagramSceneSize;
|
|
89
|
+
onSizeChange?: (size: DiagramSceneSize) => void;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=diagramSceneTypes.d.ts.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Rect } from '../transform.js';
|
|
2
|
+
import { type SemanticDocument, type SemanticPort, type EntityRef, type ErdCardinality } from '@sentropic/diagram-core';
|
|
3
|
+
import type { LineMeasurer } from '../layout/measure.js';
|
|
4
|
+
import type { Vec2 } from '../transform.js';
|
|
5
|
+
/** Numeric mirrors of component.diagramErd; verified against the token source. */
|
|
6
|
+
export declare const ERD_GEOMETRY: {
|
|
7
|
+
readonly width: 460;
|
|
8
|
+
readonly headerHeight: 64;
|
|
9
|
+
readonly rowHeight: 32;
|
|
10
|
+
readonly lineHeight: 24;
|
|
11
|
+
readonly padding: 12;
|
|
12
|
+
readonly keyWidth: 56;
|
|
13
|
+
readonly nameWidth: 170;
|
|
14
|
+
readonly typeWidth: 170;
|
|
15
|
+
readonly fontSize: 18;
|
|
16
|
+
readonly titleFontSize: 24;
|
|
17
|
+
readonly markerLength: 24;
|
|
18
|
+
readonly markerHalfWidth: 8;
|
|
19
|
+
readonly markerRadius: 4;
|
|
20
|
+
readonly markerGap: 4;
|
|
21
|
+
readonly strokeWidth: 1.5;
|
|
22
|
+
readonly gapInline: 160;
|
|
23
|
+
readonly gapBlock: 120;
|
|
24
|
+
readonly labelWidth: 240;
|
|
25
|
+
};
|
|
26
|
+
export declare const escapeErdXml: (value: string) => string;
|
|
27
|
+
export declare function erdText(attributes: SemanticPort['attributes'], key: string): string;
|
|
28
|
+
export declare const erdFlag: (p: SemanticPort, key: string) => boolean;
|
|
29
|
+
export declare function erdFields(document: SemanticDocument, entity: string): SemanticPort[];
|
|
30
|
+
export interface ErdRow {
|
|
31
|
+
readonly field: SemanticPort;
|
|
32
|
+
readonly y: number;
|
|
33
|
+
readonly height: number;
|
|
34
|
+
readonly name: readonly string[];
|
|
35
|
+
readonly type: readonly string[];
|
|
36
|
+
readonly fk: readonly string[];
|
|
37
|
+
}
|
|
38
|
+
export interface ErdCard {
|
|
39
|
+
readonly title: string;
|
|
40
|
+
readonly titleLines: readonly string[];
|
|
41
|
+
readonly width: number;
|
|
42
|
+
readonly height: number;
|
|
43
|
+
readonly headerHeight: number;
|
|
44
|
+
readonly rows: readonly ErdRow[];
|
|
45
|
+
readonly collapsed: boolean;
|
|
46
|
+
}
|
|
47
|
+
/** Wraps without truncation, breaking at identifier/punctuation boundaries where possible. */
|
|
48
|
+
export declare function wrapErdText(text: string, width: number, measure?: LineMeasurer, fontSize?: number): string[];
|
|
49
|
+
export declare function measureErdCard(document: SemanticDocument, entity: EntityRef, collapsed?: boolean, measure?: LineMeasurer): ErdCard;
|
|
50
|
+
export declare function renderErdCardSvg(card: ErdCard): string;
|
|
51
|
+
export interface ErdMarker {
|
|
52
|
+
readonly lines: readonly (readonly [
|
|
53
|
+
Vec2,
|
|
54
|
+
Vec2
|
|
55
|
+
])[];
|
|
56
|
+
readonly circle?: {
|
|
57
|
+
readonly center: Vec2;
|
|
58
|
+
readonly radius: number;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** The outward direction follows the edge away from the card; geometry is token driven. */
|
|
62
|
+
export declare function erdMarkerGeometry(cardinality: ErdCardinality, anchor: Vec2, direction: Vec2, tokens?: {
|
|
63
|
+
readonly [K in keyof typeof ERD_GEOMETRY]: number;
|
|
64
|
+
}): ErdMarker;
|
|
65
|
+
export declare function renderErdMarkerSvg(cardinality: ErdCardinality, anchor: Vec2, direction: Vec2): string;
|
|
66
|
+
/** Escaped native HTML shared verbatim by both framework hosts; always includes folded fields. */
|
|
67
|
+
export declare function renderErdTable(document: SemanticDocument): string;
|
|
68
|
+
export interface ErdLabelEntry {
|
|
69
|
+
readonly id: string;
|
|
70
|
+
readonly route: readonly Vec2[];
|
|
71
|
+
readonly size: {
|
|
72
|
+
readonly width: number;
|
|
73
|
+
readonly height: number;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** Keep every role readable: crowded labels move to a free box with a leader instead of disappearing. */
|
|
77
|
+
export declare function placeErdRoleLabels(entries: readonly ErdLabelEntry[], blockers: readonly Rect[], margin: number): Map<string, {
|
|
78
|
+
box: Rect;
|
|
79
|
+
leader?: readonly Vec2[];
|
|
80
|
+
}>;
|
|
81
|
+
//# sourceMappingURL=erd.d.ts.map
|