@sentropic/diagram-canvas 0.2.4 → 0.3.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/contracts/diagram-anatomy.v1.json +26 -7
- package/contracts/diagram-anatomy.v2.json +645 -0
- package/dist/layout/cache.js +1 -0
- package/dist/layout/measured.js +97 -23
- package/dist/layout/sceneMeasure.d.ts +2 -1
- package/dist/layout/sceneMeasure.js +10 -8
- package/dist/layout/types.d.ts +15 -4
- package/dist/presentation/diagramCardModel.d.ts +310 -11
- package/dist/presentation/diagramCardModel.js +167 -49
- package/dist/presentation/diagramSceneModel.d.ts +20 -7
- package/dist/presentation/diagramSceneModel.js +108 -20
- package/dist/presentation/diagramSceneTypes.d.ts +4 -0
- package/dist/presentation/renderCardSvg.js +9 -4
- package/dist/presentation/renderSceneSvg.js +1 -1
- package/dist/presentation/renderZoneSvg.js +8 -3
- package/dist/visibility.d.ts +1 -1
- package/dist/visibility.js +25 -3
- package/package.json +3 -2
|
@@ -23,6 +23,8 @@ export interface DiagramSceneFigureLabels {
|
|
|
23
23
|
viewport: string;
|
|
24
24
|
expand: (title: string) => string;
|
|
25
25
|
collapse: (title: string) => string;
|
|
26
|
+
/** Localized fallback label for containment relations without an explicit edge label (DE-1b). */
|
|
27
|
+
contains: string;
|
|
26
28
|
}
|
|
27
29
|
export interface DiagramSceneCamera {
|
|
28
30
|
readonly zoom: number;
|
|
@@ -62,6 +64,8 @@ export interface DiagramSceneFigureProps {
|
|
|
62
64
|
measure?: CardLineMeasure;
|
|
63
65
|
iconBindings?: import("./diagramSceneModel.js").SceneIconBindings;
|
|
64
66
|
strictIcons?: boolean;
|
|
67
|
+
/** Selectable start parity for alternating zone depth surfaces (`0` default, `1` flipped). */
|
|
68
|
+
depthParityStart?: 0 | 1;
|
|
65
69
|
/** Layout line measurer. Defaults to the bridge over `measure`. */
|
|
66
70
|
measureLines?: LineMeasurer;
|
|
67
71
|
/** Controlled fold state: collapsed occurrence ids. */
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* measured ellipses (owner A14); title/description retain the complete text
|
|
13
13
|
* and informational diagnostics report the hidden length.
|
|
14
14
|
*/
|
|
15
|
-
import {
|
|
15
|
+
import { anatomyCardGeometry, cardFullText, defaultCardMeasure, layoutCard, projectCardProps, } from "./diagramCardModel.js";
|
|
16
16
|
import { DIAGRAM_GLYPH_BASE, getDiagramGlyph, } from "./registry.js";
|
|
17
17
|
export { projectCardProps };
|
|
18
18
|
function escapeXml(value) {
|
|
@@ -55,12 +55,17 @@ function textLines(lines, className, fill, extra) {
|
|
|
55
55
|
*/
|
|
56
56
|
export function renderCardContent(props, measure = defaultCardMeasure) {
|
|
57
57
|
const layout = layoutCard(props, measure);
|
|
58
|
-
const g = { ...
|
|
58
|
+
const g = { ...anatomyCardGeometry(layout.anatomyFallback ?? props.anatomy), width: layout.box.width, height: layout.box.height };
|
|
59
59
|
const parts = [`<title>${escapeXml(cardFullText(props))}</title><desc>${escapeXml(cardFullText(props))}</desc>`];
|
|
60
60
|
// Border, then the accent bar over the left stroke (border-left look).
|
|
61
61
|
// A proposed card is always drawn dashed, independently of the tint
|
|
62
62
|
// (owner criterion 5); the dash pattern is the kit's `4 5`.
|
|
63
|
-
|
|
63
|
+
// Owner addendum 1: a folded zone keeps its depth background; leaf cards
|
|
64
|
+
// keep the resting card surface.
|
|
65
|
+
const surfaceFill = props.surface === undefined
|
|
66
|
+
? "var(--st-component-diagramCard-surface, var(--st-semantic-surface-raised))"
|
|
67
|
+
: `var(--st-component-diagramZone-${props.surface}, var(--st-semantic-surface-${props.surface === "surface1" ? "raised" : "subtle"}))`;
|
|
68
|
+
parts.push(`<rect x="1" y="1" width="${g.width - 2}" height="${g.height - 2}" fill="${surfaceFill}" stroke="var(--st-component-diagramCard-border, var(--st-semantic-border-strong))" stroke-width="${g.borderWidth}"${props.proposed === true ? ` stroke-dasharray="var(--st-component-diagramCard-proposedDashArray, 4 5)"` : ""}/>`);
|
|
64
69
|
parts.push(`<rect x="0" y="0" width="${g.accentWidth}" height="${g.height}" fill="var(--st-component-diagramCard-border, var(--st-semantic-border-strong))"/>`);
|
|
65
70
|
if (layout.iconBox !== undefined) {
|
|
66
71
|
parts.push(iconGroupFor(layout.icon.name, layout.icon.glyph, layout.iconBox.x, layout.iconBox.y, layout.iconBox.size));
|
|
@@ -108,7 +113,7 @@ export function toggleGlyph(toggle, box) {
|
|
|
108
113
|
*/
|
|
109
114
|
export function renderCardSvg(props, measure = defaultCardMeasure) {
|
|
110
115
|
const { content, layout } = renderCardContent(props, measure);
|
|
111
|
-
const g = { ...
|
|
116
|
+
const g = { ...anatomyCardGeometry(layout.anatomyFallback ?? props.anatomy), width: layout.box.width, height: layout.box.height };
|
|
112
117
|
const overflowSlots = layout.diagnostics
|
|
113
118
|
.filter((diagnostic) => diagnostic.code === "card-overflow")
|
|
114
119
|
.map((diagnostic) => diagnostic.slot);
|
|
@@ -58,7 +58,7 @@ export function renderSceneSvg(input, options = {}) {
|
|
|
58
58
|
const leader = label.leader === undefined ? '' : `<polyline points="${label.leader.map(p => p.x + ',' + p.y).join(' ')}" fill="none" stroke="var(--st-component-diagramScene-edgeStroke, #64748b)"/>`;
|
|
59
59
|
return leader + `<g data-scene-label="${escape(label.occurrence)}" transform="translate(${b.x} ${b.y})" font-size="18" 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
60
|
}).join('');
|
|
61
|
-
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>@font-face{font-family:Inter;src:local('Inter');font-weight:100 900}svg{--st-font-sans:Inter,system-ui,sans-serif;--st-semantic-surface-raised:#fff;--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><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>${maskDef}</defs>${frames}${connectors}${boxes}${labels}</svg>`;
|
|
61
|
+
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>@font-face{font-family:Inter;src:local('Inter');font-weight:100 900}svg{--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><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>${maskDef}</defs>${frames}${connectors}${boxes}${labels}</svg>`;
|
|
62
62
|
return { svg, result, scene };
|
|
63
63
|
}
|
|
64
64
|
//# sourceMappingURL=renderSceneSvg.js.map
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* function/detail re-roling (DH-08), no tint injection — the toggle is the
|
|
16
16
|
* same slot glyph as the card's and the subtitle is one body string.
|
|
17
17
|
*/
|
|
18
|
-
import { zoneFullText, CARD_GEOMETRY, ZONE_GEOMETRY, defaultCardMeasure, layoutZone, projectZoneProps, zoneCollapsedCardProps, } from "./diagramCardModel.js";
|
|
18
|
+
import { zoneFullText, anatomyZoneGeometry, CARD_GEOMETRY, ZONE_GEOMETRY, defaultCardMeasure, layoutZone, projectZoneProps, zoneCollapsedCardProps, } from "./diagramCardModel.js";
|
|
19
19
|
import { getDiagramGlyph } from "./registry.js";
|
|
20
20
|
import { iconGroupFor, renderCardContent, toggleGlyph } from "./renderCardSvg.js";
|
|
21
21
|
export { projectZoneProps };
|
|
@@ -65,7 +65,7 @@ function childContent(child, measure) {
|
|
|
65
65
|
* text — a nested overflow is never lost inside a zone.
|
|
66
66
|
*/
|
|
67
67
|
export function zoneContent(props, children, measure) {
|
|
68
|
-
const g =
|
|
68
|
+
const g = anatomyZoneGeometry(props.anatomy);
|
|
69
69
|
const layout = layoutZone(props, measure, children);
|
|
70
70
|
const x = layout.box.x;
|
|
71
71
|
const y = layout.box.y;
|
|
@@ -85,7 +85,12 @@ export function zoneContent(props, children, measure) {
|
|
|
85
85
|
// Frame (expanded only; collapsed is the card border, §6.4).
|
|
86
86
|
// A proposed zone is always drawn dashed, independently of the tint
|
|
87
87
|
// (owner criterion 5); the dash pattern is the kit's `4 5`.
|
|
88
|
-
|
|
88
|
+
// Owner addendum 1: an explicitly threaded depth paints the resolved
|
|
89
|
+
// depth surface; without depth the frame keeps its resting surface.
|
|
90
|
+
const surfaceFill = props.depth === undefined && props.depthParityStart === undefined
|
|
91
|
+
? "var(--st-component-diagramZone-surface, var(--st-semantic-surface-raised))"
|
|
92
|
+
: `var(--st-component-diagramZone-${layout.surface ?? "surface1"}, var(--st-semantic-surface-${(layout.surface ?? "surface1") === "surface1" ? "raised" : "subtle"}))`;
|
|
93
|
+
parts.push(`<rect class="st-diagramZone-frame" x="0" y="0" width="${width}" height="${height}" rx="${g.radius}" fill="${surfaceFill}" stroke="var(--st-component-diagramZone-border, var(--st-semantic-border-strong))" stroke-width="${g.borderWidth}"${props.proposed === true ? ` stroke-dasharray="var(--st-component-diagramZone-proposedDashArray, 4 5)"` : ""}/>`);
|
|
89
94
|
if (header.iconBox !== undefined) {
|
|
90
95
|
parts.push(iconGroupFor(layout.icon.name, layout.icon.glyph, header.iconBox.x - x, header.iconBox.y - y, header.iconBox.size));
|
|
91
96
|
}
|
package/dist/visibility.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ export type ExclusionReason =
|
|
|
55
55
|
| "endpoint-hidden"
|
|
56
56
|
/** A port occurrence whose owner entity occurrence is not visible. */
|
|
57
57
|
| "owner-hidden"
|
|
58
|
-
/** An entity occurrence in a visual group whose `collapsed` is true. */
|
|
58
|
+
/** An entity occurrence in a visual group (or nested under one) whose `collapsed` is true. */
|
|
59
59
|
| "group-collapsed"
|
|
60
60
|
/** A reference that resolves to nothing: the scene cannot place what it cannot resolve. */
|
|
61
61
|
| "unresolved-reference"
|
package/dist/visibility.js
CHANGED
|
@@ -130,6 +130,28 @@ export function relationVerdict(view, relation, document) {
|
|
|
130
130
|
: false),
|
|
131
131
|
]);
|
|
132
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Walk an entity occurrence's ancestor group chain (matching `diagram-core`
|
|
135
|
+
* `hiddenByFold`) and return the id of the first collapsed ancestor group, if
|
|
136
|
+
* any. A cycle in malformed group references terminates via `seen`.
|
|
137
|
+
*/
|
|
138
|
+
function collapsedAncestorGroupOf(view, occurrenceId) {
|
|
139
|
+
const seen = new Set();
|
|
140
|
+
let currentId = occurrenceId;
|
|
141
|
+
while (currentId !== undefined && !seen.has(currentId)) {
|
|
142
|
+
seen.add(currentId);
|
|
143
|
+
const current = view.entityOccurrences[currentId];
|
|
144
|
+
if (current === undefined || current.group === undefined)
|
|
145
|
+
return undefined;
|
|
146
|
+
const group = view.groups[current.group];
|
|
147
|
+
if (group === undefined)
|
|
148
|
+
return undefined;
|
|
149
|
+
if (group.collapsed === true)
|
|
150
|
+
return group.id;
|
|
151
|
+
currentId = group.occurrence;
|
|
152
|
+
}
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
133
155
|
/**
|
|
134
156
|
* The three passes are ordered because the cascade needs them so: entity
|
|
135
157
|
* occurrences first, then ports (whose owner is an entity occurrence), then
|
|
@@ -151,9 +173,9 @@ export function evaluateVisibility({ document, view }) {
|
|
|
151
173
|
});
|
|
152
174
|
continue;
|
|
153
175
|
}
|
|
154
|
-
const
|
|
155
|
-
if (
|
|
156
|
-
exclusions.push({ occurrence: occurrence.id, kind: "entity", reason: "group-collapsed", cause:
|
|
176
|
+
const collapsedGroup = collapsedAncestorGroupOf(view, occurrence.id);
|
|
177
|
+
if (collapsedGroup !== undefined) {
|
|
178
|
+
exclusions.push({ occurrence: occurrence.id, kind: "entity", reason: "group-collapsed", cause: collapsedGroup });
|
|
157
179
|
continue;
|
|
158
180
|
}
|
|
159
181
|
const verdict = entityVerdict(view, entity);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentropic/diagram-canvas",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Headless diagram scenes, layout, hit testing and pure presentation models/SVG helpers. No DOM or framework.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"import": "./dist/presentation/index.js"
|
|
49
49
|
},
|
|
50
50
|
"./diagram-anatomy": "./contracts/diagram-anatomy.v1.json",
|
|
51
|
+
"./diagram-anatomy-v2": "./contracts/diagram-anatomy.v2.json",
|
|
51
52
|
"./flowModel": {
|
|
52
53
|
"types": "./dist/presentation/flowModel.d.ts",
|
|
53
54
|
"import": "./dist/presentation/flowModel.js"
|
|
@@ -57,7 +58,7 @@
|
|
|
57
58
|
"main": "./dist/index.js",
|
|
58
59
|
"sideEffects": false,
|
|
59
60
|
"dependencies": {
|
|
60
|
-
"@sentropic/diagram-core": "0.
|
|
61
|
+
"@sentropic/diagram-core": "0.4.0"
|
|
61
62
|
},
|
|
62
63
|
"scripts": {
|
|
63
64
|
"build": "node ../../scripts/sync-diagram-spacing.mjs && tsc -p tsconfig.json",
|