@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
package/dist/layout/types.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* `ViewDocument`; everything below is either a call option or the outcome of
|
|
6
6
|
* one call (direction chosen, zoom, warnings), never persisted content.
|
|
7
7
|
*/
|
|
8
|
-
import type { Diagnostic, DiagramPresentation, EntityPresentation, ExecutorProfileBindings, OccurrenceRef, ProfileRegistry, ViewDocument, ViewRef } from "@sentropic/diagram-core";
|
|
8
|
+
import type { Diagnostic, DiagramPresentation, EntityPresentation, ExecutorProfileBindings, OccurrenceRef, ProfileRegistry, RelationPresentation, ViewDocument, ViewRef } from "@sentropic/diagram-core";
|
|
9
9
|
import type { AlignPinned, AnatomyPinned, DepthPinned } from "../presentation/diagramCardModel.js";
|
|
10
10
|
import type { LayoutHints } from "./hints.js";
|
|
11
11
|
import type { LineMeasurer } from "./measure.js";
|
|
@@ -38,6 +38,8 @@ export type TextMeasurer = ((text: string, role: TextRole | LegacyTextRole) => T
|
|
|
38
38
|
};
|
|
39
39
|
/** World units (CSS px at zoom 1). Every field has a default; see {@link DEFAULT_LAYOUT_METRICS}. */
|
|
40
40
|
export interface LayoutMetrics {
|
|
41
|
+
/** Single fixed gutter token between sibling zones on both axes (DE-2 ask 3, default 96). */
|
|
42
|
+
readonly zoneGutter?: number;
|
|
41
43
|
readonly gapMin?: number;
|
|
42
44
|
readonly gapMinBlock?: number;
|
|
43
45
|
readonly gapBase?: number;
|
|
@@ -47,6 +49,20 @@ export interface LayoutMetrics {
|
|
|
47
49
|
readonly labelBand?: number;
|
|
48
50
|
readonly gapMax?: number;
|
|
49
51
|
readonly bundleLabelMaxWidth?: number;
|
|
52
|
+
/** Minimum spacing between parallel segments, neighbouring elbows, ports and arrowheads (DE-2, default 24). */
|
|
53
|
+
readonly routeSpacing?: number;
|
|
54
|
+
/** Minimum clearance from a routed link segment to non-endpoint borders (DE-2, default 15). */
|
|
55
|
+
readonly routeBorderClearance?: number;
|
|
56
|
+
/** World-unit corner radius for rounded-elbow connectors (DE-2, default 12). */
|
|
57
|
+
readonly edgeCornerRadius?: number;
|
|
58
|
+
/** Dedicated resting connector stroke width, CSS px (token `diagramScene.linkStrokeWidth`, DE-2, default 2.5). */
|
|
59
|
+
readonly linkStrokeWidth?: number;
|
|
60
|
+
/** Stroke width for undirected related links on the r7 path. */
|
|
61
|
+
readonly linkRelatedStrokeWidth?: number;
|
|
62
|
+
/** Emphasized connector stroke width, CSS px (token `diagramScene.linkEmphasisStrokeWidth`, DE-2, default 3.5). */
|
|
63
|
+
readonly linkEmphasisStrokeWidth?: number;
|
|
64
|
+
/** Edge label font size, world px (token `diagramScene.edgeLabelSize`, DE-2, default 18). */
|
|
65
|
+
readonly edgeLabelSize?: number;
|
|
50
66
|
readonly nodePaddingX: number;
|
|
51
67
|
readonly nodePaddingY: number;
|
|
52
68
|
readonly nodeMinWidth: number;
|
|
@@ -93,6 +109,8 @@ export declare const DEFAULT_ROW_PACK: ResolvedRowPack;
|
|
|
93
109
|
/** Row-pack spacing defaults, mirroring the DS tokens (asserted by tests/layout/dc2a/tokens.test.ts). */
|
|
94
110
|
export declare const DEFAULT_ROW_GAP: 96;
|
|
95
111
|
export declare const DEFAULT_ROW_GAP_MAX: 240;
|
|
112
|
+
/** Fixed gutter between sibling zones on both axes (DE-2 ask 3, ≥ 96 world units). */
|
|
113
|
+
export declare const DEFAULT_ZONE_GUTTER: 96;
|
|
96
114
|
/** Orientation of one packed level (§4.1): shelves run as rows or as columns. */
|
|
97
115
|
export type LevelOrientation = "rows" | "columns";
|
|
98
116
|
/** Level key of the root level in orientation records (§4.1). */
|
|
@@ -121,6 +139,11 @@ export interface LayoutOptions {
|
|
|
121
139
|
*/
|
|
122
140
|
readonly presentation?: DiagramPresentation & {
|
|
123
141
|
readonly entities: Readonly<Record<string, EntityPresentation & AnatomyPinned & AlignPinned & DepthPinned>>;
|
|
142
|
+
/**
|
|
143
|
+
* Word-addressed connector styles keyed by relation occurrence id or
|
|
144
|
+
* semantic relation id (DE-2). Closed registry words only, never raw geometry.
|
|
145
|
+
*/
|
|
146
|
+
readonly relations?: Readonly<Record<string, RelationPresentation>>;
|
|
124
147
|
};
|
|
125
148
|
/** Injected shared line measurer for measured views (M3 §4.6.2/§5.6). */
|
|
126
149
|
readonly measureLines?: LineMeasurer;
|
|
@@ -167,6 +190,12 @@ export interface LayoutOptions {
|
|
|
167
190
|
* `surface1` expanded zone.
|
|
168
191
|
*/
|
|
169
192
|
readonly reportSurfaceSame?: boolean;
|
|
193
|
+
/**
|
|
194
|
+
* Opt-in non-blocking convention lints (DE-2 asks 5 & 6): arrow direction
|
|
195
|
+
* (`source` = initiator, when initiator metadata is declared) and opaque
|
|
196
|
+
* acronym zone tags (with `DLR-315` product kicker allowlist). Off by default.
|
|
197
|
+
*/
|
|
198
|
+
readonly conventions?: import("./conventions.js").DiagramConventionLintOptions;
|
|
170
199
|
}
|
|
171
200
|
/** The outcome of the L-R5 / L-R7 decision for one call. Derived, never persisted. */
|
|
172
201
|
export interface LayoutFit {
|
|
@@ -182,7 +211,7 @@ export interface LayoutFit {
|
|
|
182
211
|
readonly phone: boolean;
|
|
183
212
|
}
|
|
184
213
|
/** A rule the engine could not fully satisfy on this input, reported instead of dropped. */
|
|
185
|
-
export type LayoutWarningCode = "channel-unresolved" | "card-icon-missing" | "flow-bundled" | "badge-unplaced" | "flow-layout-unsupported" | "label-unplaced" | "label-budget-exhausted" | "route-obstructed" | "row-fill-partial" | "card-overflow" | "card-grown" | "zone-overflow" | "zone-surface-same" | "docking-overflow";
|
|
214
|
+
export type LayoutWarningCode = "channel-unresolved" | "card-icon-missing" | "flow-bundled" | "badge-unplaced" | "flow-layout-unsupported" | "label-unplaced" | "label-budget-exhausted" | "route-obstructed" | "route-spacing-conflict" | "channel-capacity-exceeded" | "row-fill-partial" | "card-overflow" | "card-grown" | "zone-overflow" | "zone-surface-same" | "arrow-direction-convention" | "zone-tag-opaque-acronym" | "docking-overflow";
|
|
186
215
|
export interface LayoutWarning {
|
|
187
216
|
readonly severity?: "info";
|
|
188
217
|
readonly code: LayoutWarningCode;
|
|
@@ -227,6 +256,8 @@ export type LayoutResult = {
|
|
|
227
256
|
* bounds (DEC-5, BF-7).
|
|
228
257
|
*/
|
|
229
258
|
readonly channels?: readonly import("./channels.js").LayoutChannel[];
|
|
259
|
+
/** Built-in geometric route-spacing audit report (DE-2 ask 2). */
|
|
260
|
+
readonly routeSpacing?: import("./routeSpacing.js").RouteSpacingReport;
|
|
230
261
|
readonly labelBoxes?: Readonly<Record<string, {
|
|
231
262
|
readonly x: number;
|
|
232
263
|
readonly y: number;
|
package/dist/layout/types.js
CHANGED
|
@@ -8,6 +8,8 @@ export const DEFAULT_ROW_PACK = {
|
|
|
8
8
|
/** Row-pack spacing defaults, mirroring the DS tokens (asserted by tests/layout/dc2a/tokens.test.ts). */
|
|
9
9
|
export const DEFAULT_ROW_GAP = spacing.gapMin;
|
|
10
10
|
export const DEFAULT_ROW_GAP_MAX = spacing.gapMax;
|
|
11
|
+
/** Fixed gutter between sibling zones on both axes (DE-2 ask 3, ≥ 96 world units). */
|
|
12
|
+
export const DEFAULT_ZONE_GUTTER = spacing.zoneGutter;
|
|
11
13
|
/** Level key of the root level in orientation records (§4.1). */
|
|
12
14
|
export const ROOT_LEVEL_KEY = "root";
|
|
13
15
|
/** One place where row-pack defaults resolve (§6.1), so cache keys see numbers only. */
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Rect, Vec2 } from "../transform.js";
|
|
2
|
+
/**
|
|
3
|
+
* Default corner radius for rounded-elbow connectors, world units (DE-2).
|
|
4
|
+
* Mirrors the `--st-component-diagramScene-edgeCornerRadius` token (`12px`).
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_EDGE_CORNER_RADIUS = 12;
|
|
7
|
+
/**
|
|
8
|
+
* Shared SVG `<path d="...">` builder for connectors with rounded elbows (DE-2).
|
|
9
|
+
*
|
|
10
|
+
* Replaces sharp polyline corners with quadratic Bézier curves (`Q`) whose
|
|
11
|
+
* radius is `cornerRadius` (default `12` world units) capped at half the
|
|
12
|
+
* shorter adjoining leg (`min(radius, lenIn / 2, lenOut / 2)`). Adjacent bends
|
|
13
|
+
* sharing a leg therefore never overlap, and the path always begins on the
|
|
14
|
+
* exact start dock (`M x0 y0`) and finishes on the exact end dock (`L xn yn`)
|
|
15
|
+
* with a non-zero arrival segment for `marker-end` orientation.
|
|
16
|
+
*/
|
|
17
|
+
export declare function connectorPath(points: readonly Vec2[], cornerRadius?: number): string;
|
|
18
|
+
/**
|
|
19
|
+
* Tight axis-aligned bounding boxes covering the two quadratic Bézier halves
|
|
20
|
+
* (`[enter, mid]` and `[mid, exit]`) of every rounded bend emitted by
|
|
21
|
+
* `connectorPath`. Because the Bézier curve and its midpoint chords stay
|
|
22
|
+
* inside these two rectangles, clearing them guarantees label clearance
|
|
23
|
+
* around rounded elbows as well as straight legs.
|
|
24
|
+
*/
|
|
25
|
+
export declare function connectorCornerBounds(points: readonly Vec2[], cornerRadius?: number): Rect[];
|
|
26
|
+
/**
|
|
27
|
+
* Parse a `connectorPath` SVG `d` string (`M`, `L`, `Q`) into ordered sampled
|
|
28
|
+
* points along the rendered curve: the first point is always the exact start
|
|
29
|
+
* dock and the last point is always the exact end dock.
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseConnectorPath(d: string): readonly Vec2[];
|
|
32
|
+
//# sourceMappingURL=connectorPath.d.ts.map
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default corner radius for rounded-elbow connectors, world units (DE-2).
|
|
3
|
+
* Mirrors the `--st-component-diagramScene-edgeCornerRadius` token (`12px`).
|
|
4
|
+
*/
|
|
5
|
+
export const DEFAULT_EDGE_CORNER_RADIUS = 12;
|
|
6
|
+
const EPSILON = 1e-6;
|
|
7
|
+
function formatCoord(value) {
|
|
8
|
+
const cleaned = Number(value.toPrecision(12));
|
|
9
|
+
return String(cleaned === 0 ? 0 : cleaned);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Remove consecutive duplicate points and redundant forward-collinear interior
|
|
13
|
+
* points while preserving the exact first and last dock coordinates.
|
|
14
|
+
*/
|
|
15
|
+
function simplifyElbowPoints(points) {
|
|
16
|
+
if (points.length <= 1)
|
|
17
|
+
return points.map((p) => ({ x: p.x, y: p.y }));
|
|
18
|
+
const dedup = [{ x: points[0].x, y: points[0].y }];
|
|
19
|
+
for (let i = 1; i < points.length; i += 1) {
|
|
20
|
+
const point = points[i];
|
|
21
|
+
const prev = dedup[dedup.length - 1];
|
|
22
|
+
if (Math.hypot(point.x - prev.x, point.y - prev.y) > EPSILON) {
|
|
23
|
+
dedup.push({ x: point.x, y: point.y });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (dedup.length === 1) {
|
|
27
|
+
// All input points coincided: preserve degenerate 2-point dock contact.
|
|
28
|
+
const last = points[points.length - 1];
|
|
29
|
+
dedup.push({ x: last.x, y: last.y });
|
|
30
|
+
return dedup;
|
|
31
|
+
}
|
|
32
|
+
// Keep exact terminal dock point even when the final step was sub-epsilon.
|
|
33
|
+
const end = points[points.length - 1];
|
|
34
|
+
dedup[dedup.length - 1] = { x: end.x, y: end.y };
|
|
35
|
+
if (dedup.length <= 2)
|
|
36
|
+
return dedup;
|
|
37
|
+
const simplified = [dedup[0]];
|
|
38
|
+
for (let i = 1; i < dedup.length - 1; i += 1) {
|
|
39
|
+
const prev = simplified[simplified.length - 1];
|
|
40
|
+
const curr = dedup[i];
|
|
41
|
+
const next = dedup[i + 1];
|
|
42
|
+
const dx1 = curr.x - prev.x;
|
|
43
|
+
const dy1 = curr.y - prev.y;
|
|
44
|
+
const dx2 = next.x - curr.x;
|
|
45
|
+
const dy2 = next.y - curr.y;
|
|
46
|
+
const len1 = Math.hypot(dx1, dy1);
|
|
47
|
+
const len2 = Math.hypot(dx2, dy2);
|
|
48
|
+
if (len1 <= EPSILON || len2 <= EPSILON)
|
|
49
|
+
continue;
|
|
50
|
+
const cross = (dx1 * dy2 - dy1 * dx2) / (len1 * len2);
|
|
51
|
+
const dot = (dx1 * dx2 + dy1 * dy2) / (len1 * len2);
|
|
52
|
+
// Drop forward-collinear interior points so they never cap an adjacent bend.
|
|
53
|
+
if (Math.abs(cross) <= EPSILON && dot > 0)
|
|
54
|
+
continue;
|
|
55
|
+
simplified.push(curr);
|
|
56
|
+
}
|
|
57
|
+
simplified.push(dedup[dedup.length - 1]);
|
|
58
|
+
return simplified;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Shared SVG `<path d="...">` builder for connectors with rounded elbows (DE-2).
|
|
62
|
+
*
|
|
63
|
+
* Replaces sharp polyline corners with quadratic Bézier curves (`Q`) whose
|
|
64
|
+
* radius is `cornerRadius` (default `12` world units) capped at half the
|
|
65
|
+
* shorter adjoining leg (`min(radius, lenIn / 2, lenOut / 2)`). Adjacent bends
|
|
66
|
+
* sharing a leg therefore never overlap, and the path always begins on the
|
|
67
|
+
* exact start dock (`M x0 y0`) and finishes on the exact end dock (`L xn yn`)
|
|
68
|
+
* with a non-zero arrival segment for `marker-end` orientation.
|
|
69
|
+
*/
|
|
70
|
+
export function connectorPath(points, cornerRadius = DEFAULT_EDGE_CORNER_RADIUS) {
|
|
71
|
+
if (points.length < 2)
|
|
72
|
+
return "";
|
|
73
|
+
const simplified = simplifyElbowPoints(points);
|
|
74
|
+
const safeRadius = Number.isFinite(cornerRadius) && cornerRadius > 0 ? cornerRadius : 0;
|
|
75
|
+
const start = simplified[0];
|
|
76
|
+
const parts = [`M${formatCoord(start.x)} ${formatCoord(start.y)}`];
|
|
77
|
+
let cursorX = start.x;
|
|
78
|
+
let cursorY = start.y;
|
|
79
|
+
for (let i = 1; i < simplified.length - 1; i += 1) {
|
|
80
|
+
const prev = simplified[i - 1];
|
|
81
|
+
const corner = simplified[i];
|
|
82
|
+
const next = simplified[i + 1];
|
|
83
|
+
const inX = corner.x - prev.x;
|
|
84
|
+
const inY = corner.y - prev.y;
|
|
85
|
+
const outX = next.x - corner.x;
|
|
86
|
+
const outY = next.y - corner.y;
|
|
87
|
+
const inLen = Math.hypot(inX, inY);
|
|
88
|
+
const outLen = Math.hypot(outX, outY);
|
|
89
|
+
const r = Math.min(safeRadius, inLen / 2, outLen / 2);
|
|
90
|
+
const cross = inLen > EPSILON && outLen > EPSILON ? (inX * outY - inY * outX) / (inLen * outLen) : 0;
|
|
91
|
+
if (r <= EPSILON || Math.abs(cross) <= EPSILON) {
|
|
92
|
+
parts.push(`L${formatCoord(corner.x)} ${formatCoord(corner.y)}`);
|
|
93
|
+
cursorX = corner.x;
|
|
94
|
+
cursorY = corner.y;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const enterX = corner.x - (inX / inLen) * r;
|
|
98
|
+
const enterY = corner.y - (inY / inLen) * r;
|
|
99
|
+
const exitX = corner.x + (outX / outLen) * r;
|
|
100
|
+
const exitY = corner.y + (outY / outLen) * r;
|
|
101
|
+
if (Math.hypot(enterX - cursorX, enterY - cursorY) > EPSILON) {
|
|
102
|
+
parts.push(`L${formatCoord(enterX)} ${formatCoord(enterY)}`);
|
|
103
|
+
}
|
|
104
|
+
parts.push(`Q${formatCoord(corner.x)} ${formatCoord(corner.y)} ${formatCoord(exitX)} ${formatCoord(exitY)}`);
|
|
105
|
+
cursorX = exitX;
|
|
106
|
+
cursorY = exitY;
|
|
107
|
+
}
|
|
108
|
+
const end = simplified[simplified.length - 1];
|
|
109
|
+
parts.push(`L${formatCoord(end.x)} ${formatCoord(end.y)}`);
|
|
110
|
+
return parts.join(" ");
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Tight axis-aligned bounding boxes covering the two quadratic Bézier halves
|
|
114
|
+
* (`[enter, mid]` and `[mid, exit]`) of every rounded bend emitted by
|
|
115
|
+
* `connectorPath`. Because the Bézier curve and its midpoint chords stay
|
|
116
|
+
* inside these two rectangles, clearing them guarantees label clearance
|
|
117
|
+
* around rounded elbows as well as straight legs.
|
|
118
|
+
*/
|
|
119
|
+
export function connectorCornerBounds(points, cornerRadius = DEFAULT_EDGE_CORNER_RADIUS) {
|
|
120
|
+
if (points.length < 3 || !Number.isFinite(cornerRadius) || cornerRadius <= 0)
|
|
121
|
+
return [];
|
|
122
|
+
const simplified = simplifyElbowPoints(points);
|
|
123
|
+
const boxes = [];
|
|
124
|
+
for (let i = 1; i < simplified.length - 1; i += 1) {
|
|
125
|
+
const prev = simplified[i - 1];
|
|
126
|
+
const corner = simplified[i];
|
|
127
|
+
const next = simplified[i + 1];
|
|
128
|
+
const inX = corner.x - prev.x;
|
|
129
|
+
const inY = corner.y - prev.y;
|
|
130
|
+
const outX = next.x - corner.x;
|
|
131
|
+
const outY = next.y - corner.y;
|
|
132
|
+
const inLen = Math.hypot(inX, inY);
|
|
133
|
+
const outLen = Math.hypot(outX, outY);
|
|
134
|
+
const r = Math.min(cornerRadius, inLen / 2, outLen / 2);
|
|
135
|
+
const cross = inLen > EPSILON && outLen > EPSILON ? (inX * outY - inY * outX) / (inLen * outLen) : 0;
|
|
136
|
+
if (r <= EPSILON || Math.abs(cross) <= EPSILON)
|
|
137
|
+
continue;
|
|
138
|
+
const enterX = corner.x - (inX / inLen) * r;
|
|
139
|
+
const enterY = corner.y - (inY / inLen) * r;
|
|
140
|
+
const exitX = corner.x + (outX / outLen) * r;
|
|
141
|
+
const exitY = corner.y + (outY / outLen) * r;
|
|
142
|
+
const midX = 0.25 * enterX + 0.5 * corner.x + 0.25 * exitX;
|
|
143
|
+
const midY = 0.25 * enterY + 0.5 * corner.y + 0.25 * exitY;
|
|
144
|
+
boxes.push({
|
|
145
|
+
x: Math.min(enterX, midX),
|
|
146
|
+
y: Math.min(enterY, midY),
|
|
147
|
+
width: Math.abs(enterX - midX),
|
|
148
|
+
height: Math.abs(enterY - midY),
|
|
149
|
+
}, {
|
|
150
|
+
x: Math.min(midX, exitX),
|
|
151
|
+
y: Math.min(midY, exitY),
|
|
152
|
+
width: Math.abs(midX - exitX),
|
|
153
|
+
height: Math.abs(midY - exitY),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return boxes;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Parse a `connectorPath` SVG `d` string (`M`, `L`, `Q`) into ordered sampled
|
|
160
|
+
* points along the rendered curve: the first point is always the exact start
|
|
161
|
+
* dock and the last point is always the exact end dock.
|
|
162
|
+
*/
|
|
163
|
+
export function parseConnectorPath(d) {
|
|
164
|
+
const tokens = d.match(/[MLQ]|[-+]?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?/gi);
|
|
165
|
+
if (tokens === null)
|
|
166
|
+
return [];
|
|
167
|
+
const out = [];
|
|
168
|
+
let index = 0;
|
|
169
|
+
let command = "";
|
|
170
|
+
let current;
|
|
171
|
+
while (index < tokens.length) {
|
|
172
|
+
const token = tokens[index];
|
|
173
|
+
if (/^[MLQ]$/i.test(token)) {
|
|
174
|
+
command = token.toUpperCase();
|
|
175
|
+
index += 1;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (command === "M" || command === "L") {
|
|
179
|
+
const x = Number(tokens[index]);
|
|
180
|
+
const y = Number(tokens[index + 1]);
|
|
181
|
+
index += 2;
|
|
182
|
+
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
183
|
+
return [];
|
|
184
|
+
current = { x, y };
|
|
185
|
+
out.push(current);
|
|
186
|
+
if (command === "M")
|
|
187
|
+
command = "L";
|
|
188
|
+
}
|
|
189
|
+
else if (command === "Q") {
|
|
190
|
+
const cx = Number(tokens[index]);
|
|
191
|
+
const cy = Number(tokens[index + 1]);
|
|
192
|
+
const ex = Number(tokens[index + 2]);
|
|
193
|
+
const ey = Number(tokens[index + 3]);
|
|
194
|
+
index += 4;
|
|
195
|
+
if (!Number.isFinite(cx) || !Number.isFinite(cy) || !Number.isFinite(ex) || !Number.isFinite(ey))
|
|
196
|
+
return [];
|
|
197
|
+
if (current !== undefined) {
|
|
198
|
+
// Quadratic Bézier midpoint at t = 0.5 lies on the rounded elbow.
|
|
199
|
+
out.push({
|
|
200
|
+
x: 0.25 * current.x + 0.5 * cx + 0.25 * ex,
|
|
201
|
+
y: 0.25 * current.y + 0.5 * cy + 0.25 * ey,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
current = { x: ex, y: ey };
|
|
205
|
+
out.push(current);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return out;
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=connectorPath.js.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type ArrowheadKind, type CanonicalArrowheadKind, type LinkEmphasis, type StrokeStyle } from "@sentropic/diagram-core";
|
|
2
|
+
import type { LayoutMetrics } from "../layout/types.js";
|
|
3
|
+
export interface ConnectorMarkerIds {
|
|
4
|
+
readonly filled: string;
|
|
5
|
+
readonly filledEmphasis: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ConnectorMarkerSpec {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly kind: "arrow";
|
|
10
|
+
readonly emphasis: LinkEmphasis;
|
|
11
|
+
readonly viewBox: string;
|
|
12
|
+
readonly refX: number;
|
|
13
|
+
readonly refY: number;
|
|
14
|
+
readonly markerUnits: "userSpaceOnUse";
|
|
15
|
+
readonly markerWidth: number;
|
|
16
|
+
readonly markerHeight: number;
|
|
17
|
+
readonly orient: "auto-start-reverse";
|
|
18
|
+
readonly path: string;
|
|
19
|
+
readonly fill: string;
|
|
20
|
+
readonly stroke?: string;
|
|
21
|
+
readonly strokeWidth?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Closed marker geometry table for the `@4` arrowhead registry (`arrow | none`, DE-2).
|
|
25
|
+
* Uses `markerUnits="userSpaceOnUse"` at `10.5 × 10.5` world units so raising
|
|
26
|
+
* `linkStrokeWidth` (`1.5 → 2.5/3.5px`) preserves the pre-DE-2 arrowhead size
|
|
27
|
+
* (`7 × 1.5 = 10.5`). Additional heads (hollow triangles, diamonds) are reserved for N2.
|
|
28
|
+
*/
|
|
29
|
+
export declare const ARROWHEAD_MARKER_GEOMETRY: Readonly<{
|
|
30
|
+
arrow: Readonly<{
|
|
31
|
+
viewBox: "0 0 10 10";
|
|
32
|
+
refX: 9;
|
|
33
|
+
refY: 5;
|
|
34
|
+
markerUnits: "userSpaceOnUse";
|
|
35
|
+
markerWidth: 10.5;
|
|
36
|
+
markerHeight: 10.5;
|
|
37
|
+
orient: "auto-start-reverse";
|
|
38
|
+
path: "M0 0L10 5L0 10Z";
|
|
39
|
+
}>;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Single emphasis-stroke token expression shared across Svelte, Vue and SVG
|
|
43
|
+
* targets (`--st-component-diagramScene-linkEmphasisStroke`, falling back to
|
|
44
|
+
* `--st-semantic-border-interactive` and the light core-theme value `#001f33`).
|
|
45
|
+
*/
|
|
46
|
+
export declare const LINK_EMPHASIS_STROKE_FALLBACK = "#001f33";
|
|
47
|
+
export declare const LINK_EMPHASIS_STROKE = "var(--st-component-diagramScene-linkEmphasisStroke, var(--st-semantic-border-interactive, #001f33))";
|
|
48
|
+
/** Derive deterministic per-host marker ids keeping the default arrow id first. */
|
|
49
|
+
export declare function connectorMarkerIds(baseArrowId: string): ConnectorMarkerIds;
|
|
50
|
+
/** Map a closed `StrokeStyle` registry word to its SVG `stroke-dasharray` value (absent for solid). */
|
|
51
|
+
export declare function connectorDashArray(strokeStyle: StrokeStyle | undefined): string | undefined;
|
|
52
|
+
/** Let themed shafts and swatches share the same dash token in every renderer. */
|
|
53
|
+
export declare function connectorDashPaint(strokeStyle: StrokeStyle | undefined): string | undefined;
|
|
54
|
+
export declare function connectorStrokeWidth(edge: Pick<ConnectorMarkerEdgeInput, "emphasis" | "arrowhead">, widths?: Pick<LayoutMetrics, "linkStrokeWidth" | "linkRelatedStrokeWidth" | "linkEmphasisStrokeWidth">): number;
|
|
55
|
+
/** Normalize a closed `ArrowheadKind` word (`arrow | none`). */
|
|
56
|
+
export declare function connectorMarkerKind(arrowhead: ArrowheadKind | undefined): CanonicalArrowheadKind;
|
|
57
|
+
export interface ConnectorMarkerEdgeInput {
|
|
58
|
+
readonly markers?: string;
|
|
59
|
+
readonly directed?: boolean;
|
|
60
|
+
readonly arrowhead?: ArrowheadKind;
|
|
61
|
+
readonly emphasis?: LinkEmphasis;
|
|
62
|
+
}
|
|
63
|
+
/** Resolve the `marker-end` URL reference for one scene edge, or `undefined` when suppressed (`none`, ERD, flow). */
|
|
64
|
+
export declare function connectorMarkerRef(edge: ConnectorMarkerEdgeInput, ids: ConnectorMarkerIds): string | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Additional `<marker>` definitions required by the scene beyond the default
|
|
67
|
+
* arrow marker (which hosts always emit first in `<defs>`).
|
|
68
|
+
*/
|
|
69
|
+
export declare function extraConnectorMarkers(edges: readonly ConnectorMarkerEdgeInput[], ids: ConnectorMarkerIds): readonly ConnectorMarkerSpec[];
|
|
70
|
+
//# sourceMappingURL=connectorStyle.d.ts.map
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { resolveArrowhead, resolveDashPattern, } from "@sentropic/diagram-core";
|
|
2
|
+
import { DEFAULT_LINK_EMPHASIS_STROKE_WIDTH, DEFAULT_LINK_RELATED_STROKE_WIDTH, DEFAULT_LINK_STROKE_WIDTH } from "../camera.js";
|
|
3
|
+
/**
|
|
4
|
+
* Closed marker geometry table for the `@4` arrowhead registry (`arrow | none`, DE-2).
|
|
5
|
+
* Uses `markerUnits="userSpaceOnUse"` at `10.5 × 10.5` world units so raising
|
|
6
|
+
* `linkStrokeWidth` (`1.5 → 2.5/3.5px`) preserves the pre-DE-2 arrowhead size
|
|
7
|
+
* (`7 × 1.5 = 10.5`). Additional heads (hollow triangles, diamonds) are reserved for N2.
|
|
8
|
+
*/
|
|
9
|
+
export const ARROWHEAD_MARKER_GEOMETRY = Object.freeze({
|
|
10
|
+
arrow: Object.freeze({
|
|
11
|
+
viewBox: "0 0 10 10",
|
|
12
|
+
refX: 9,
|
|
13
|
+
refY: 5,
|
|
14
|
+
markerUnits: "userSpaceOnUse",
|
|
15
|
+
markerWidth: 10.5,
|
|
16
|
+
markerHeight: 10.5,
|
|
17
|
+
orient: "auto-start-reverse",
|
|
18
|
+
path: "M0 0L10 5L0 10Z",
|
|
19
|
+
}),
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Single emphasis-stroke token expression shared across Svelte, Vue and SVG
|
|
23
|
+
* targets (`--st-component-diagramScene-linkEmphasisStroke`, falling back to
|
|
24
|
+
* `--st-semantic-border-interactive` and the light core-theme value `#001f33`).
|
|
25
|
+
*/
|
|
26
|
+
export const LINK_EMPHASIS_STROKE_FALLBACK = "#001f33";
|
|
27
|
+
export const LINK_EMPHASIS_STROKE = `var(--st-component-diagramScene-linkEmphasisStroke, var(--st-semantic-border-interactive, ${LINK_EMPHASIS_STROKE_FALLBACK}))`;
|
|
28
|
+
/** Derive deterministic per-host marker ids keeping the default arrow id first. */
|
|
29
|
+
export function connectorMarkerIds(baseArrowId) {
|
|
30
|
+
return {
|
|
31
|
+
filled: baseArrowId,
|
|
32
|
+
filledEmphasis: `${baseArrowId}-emphasis`,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** Map a closed `StrokeStyle` registry word to its SVG `stroke-dasharray` value (absent for solid). */
|
|
36
|
+
export function connectorDashArray(strokeStyle) {
|
|
37
|
+
const descriptor = resolveDashPattern(strokeStyle);
|
|
38
|
+
if (descriptor === undefined || descriptor.dashArray.length === 0)
|
|
39
|
+
return undefined;
|
|
40
|
+
return descriptor.dashArray.join(" ");
|
|
41
|
+
}
|
|
42
|
+
/** Let themed shafts and swatches share the same dash token in every renderer. */
|
|
43
|
+
export function connectorDashPaint(strokeStyle) {
|
|
44
|
+
const fallback = connectorDashArray(strokeStyle);
|
|
45
|
+
if (fallback === undefined)
|
|
46
|
+
return undefined;
|
|
47
|
+
const token = strokeStyle === "dashed" ? "linkDashDashed" : "linkDashDotted";
|
|
48
|
+
return `stroke-dasharray:var(--st-component-diagramScene-${token}, ${fallback})`;
|
|
49
|
+
}
|
|
50
|
+
export function connectorStrokeWidth(edge, widths) {
|
|
51
|
+
if (edge.emphasis === "emphasis")
|
|
52
|
+
return widths?.linkEmphasisStrokeWidth ?? DEFAULT_LINK_EMPHASIS_STROKE_WIDTH;
|
|
53
|
+
if (edge.arrowhead === "none")
|
|
54
|
+
return widths?.linkRelatedStrokeWidth ?? DEFAULT_LINK_RELATED_STROKE_WIDTH;
|
|
55
|
+
return widths?.linkStrokeWidth ?? DEFAULT_LINK_STROKE_WIDTH;
|
|
56
|
+
}
|
|
57
|
+
/** Normalize a closed `ArrowheadKind` word (`arrow | none`). */
|
|
58
|
+
export function connectorMarkerKind(arrowhead) {
|
|
59
|
+
return resolveArrowhead(arrowhead)?.canonicalKind ?? "arrow";
|
|
60
|
+
}
|
|
61
|
+
/** Resolve the `marker-end` URL reference for one scene edge, or `undefined` when suppressed (`none`, ERD, flow). */
|
|
62
|
+
export function connectorMarkerRef(edge, ids) {
|
|
63
|
+
if (edge.markers !== undefined || edge.directed === true)
|
|
64
|
+
return undefined;
|
|
65
|
+
const kind = connectorMarkerKind(edge.arrowhead);
|
|
66
|
+
if (kind === "none")
|
|
67
|
+
return undefined;
|
|
68
|
+
const emphasized = edge.emphasis === "emphasis";
|
|
69
|
+
return `url(#${emphasized ? ids.filledEmphasis : ids.filled})`;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Additional `<marker>` definitions required by the scene beyond the default
|
|
73
|
+
* arrow marker (which hosts always emit first in `<defs>`).
|
|
74
|
+
*/
|
|
75
|
+
export function extraConnectorMarkers(edges, ids) {
|
|
76
|
+
let needFilledEmphasis = false;
|
|
77
|
+
for (const edge of edges) {
|
|
78
|
+
if (edge.markers !== undefined || edge.directed === true)
|
|
79
|
+
continue;
|
|
80
|
+
const kind = connectorMarkerKind(edge.arrowhead);
|
|
81
|
+
if (kind === "none")
|
|
82
|
+
continue;
|
|
83
|
+
if (edge.emphasis === "emphasis") {
|
|
84
|
+
needFilledEmphasis = true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const specs = [];
|
|
88
|
+
if (needFilledEmphasis) {
|
|
89
|
+
specs.push({
|
|
90
|
+
id: ids.filledEmphasis,
|
|
91
|
+
kind: "arrow",
|
|
92
|
+
emphasis: "emphasis",
|
|
93
|
+
...ARROWHEAD_MARKER_GEOMETRY.arrow,
|
|
94
|
+
fill: LINK_EMPHASIS_STROKE,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return specs;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=connectorStyle.js.map
|
|
@@ -218,7 +218,7 @@ export declare function resolveDiagramAlign(anatomy: DiagramAnatomy | undefined,
|
|
|
218
218
|
* Edge label typography (DC-2a, tokens `diagramScene.edgeLabelFontSize` /
|
|
219
219
|
* `diagramScene.edgeLabelLineHeight`): 18 px on a 22 px line box. One line
|
|
220
220
|
* plus the engine's two 4 px label margins is 30 px, inside the 32 px sibling
|
|
221
|
-
* gap cap; at the 0.
|
|
221
|
+
* gap cap; at the 0.30 fit floor it renders at 5.4 CSS px.
|
|
222
222
|
*/
|
|
223
223
|
export declare const FLOW_BADGE_GEOMETRY: {
|
|
224
224
|
readonly size: 16;
|
|
@@ -96,7 +96,7 @@ export function resolveDiagramAlign(anatomy, align) {
|
|
|
96
96
|
* Edge label typography (DC-2a, tokens `diagramScene.edgeLabelFontSize` /
|
|
97
97
|
* `diagramScene.edgeLabelLineHeight`): 18 px on a 22 px line box. One line
|
|
98
98
|
* plus the engine's two 4 px label margins is 30 px, inside the 32 px sibling
|
|
99
|
-
* gap cap; at the 0.
|
|
99
|
+
* gap cap; at the 0.30 fit floor it renders at 5.4 CSS px.
|
|
100
100
|
*/
|
|
101
101
|
export const FLOW_BADGE_GEOMETRY = { size: 16, lineHeight: 20 };
|
|
102
102
|
export const EDGE_LABEL_GEOMETRY = { size: 18, weight: 400, lineHeight: 22 };
|