@sentropic/diagram-canvas 0.1.0 → 0.2.2
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 +12 -7
- package/dist/camera.js +18 -10
- 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 +70 -2
- package/dist/presentation/diagramSceneModel.js +165 -30
- 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/presentation/sceneLabelClearance.d.ts +8 -0
- package/dist/presentation/sceneLabelClearance.js +85 -0
- package/dist/visibility.d.ts +1 -1
- package/dist/visibility.js +5 -4
- package/package.json +31 -5
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { normaliseRect } from '../geometry.js';
|
|
2
|
+
/** Keep measured label sizes and routes; move only labels whose paint would
|
|
3
|
+
* cover a connector. The same deterministic placement is used by both hosts. */
|
|
4
|
+
export function clearSceneLabels(labels, routes, shapes, clearance) {
|
|
5
|
+
const bounds = shapes.map(normaliseRect);
|
|
6
|
+
for (const route of routes)
|
|
7
|
+
for (let i = 1; i < route.length; i++) {
|
|
8
|
+
const a = route[i - 1], b = route[i];
|
|
9
|
+
bounds.push({ x: Math.min(a.x, b.x), y: Math.min(a.y, b.y), width: Math.abs(a.x - b.x), height: Math.abs(a.y - b.y) });
|
|
10
|
+
}
|
|
11
|
+
// Normalise each obstacle once, rather than allocating two rectangles for
|
|
12
|
+
// every candidate/obstacle pair during the search. Use these same bounds
|
|
13
|
+
// for candidate generation, including persisted negative extents.
|
|
14
|
+
return labels.map(label => {
|
|
15
|
+
const { box } = label;
|
|
16
|
+
const padded = (x, y) => ({ x: x - clearance, y: y - clearance, width: box.width + 2 * clearance, height: box.height + 2 * clearance });
|
|
17
|
+
const candidates = [{ x: box.x, y: box.y, cost: 0 }];
|
|
18
|
+
const compare = (a, b) => a.cost - b.cost || a.y - b.y || a.x - b.x;
|
|
19
|
+
const visited = new Set([`${box.x},${box.y}`]);
|
|
20
|
+
const add = (x, y) => {
|
|
21
|
+
const key = `${x},${y}`;
|
|
22
|
+
if (visited.has(key))
|
|
23
|
+
return;
|
|
24
|
+
visited.add(key);
|
|
25
|
+
const candidate = { x, y, cost: Math.abs(x - box.x) + Math.abs(y - box.y) };
|
|
26
|
+
let index = candidates.length;
|
|
27
|
+
candidates.push(candidate);
|
|
28
|
+
while (index > 0) {
|
|
29
|
+
const parent = (index - 1) >> 1;
|
|
30
|
+
if (compare(candidates[parent], candidate) <= 0)
|
|
31
|
+
break;
|
|
32
|
+
candidates[index] = candidates[parent];
|
|
33
|
+
index = parent;
|
|
34
|
+
}
|
|
35
|
+
candidates[index] = candidate;
|
|
36
|
+
};
|
|
37
|
+
// Expand only boundaries of obstacles actually hit. Coordinates come
|
|
38
|
+
// from a finite set of rectangle edges; no unbounded nudge loop or
|
|
39
|
+
// quadratic Cartesian grid is needed for dense scenes.
|
|
40
|
+
while (candidates.length > 0) {
|
|
41
|
+
// A min-heap preserves the exact cost/y/x order without sorting and
|
|
42
|
+
// shifting the entire frontier at every visited position.
|
|
43
|
+
const choice = candidates[0];
|
|
44
|
+
const last = candidates.pop();
|
|
45
|
+
if (candidates.length > 0) {
|
|
46
|
+
let index = 0;
|
|
47
|
+
while (2 * index + 1 < candidates.length) {
|
|
48
|
+
let child = 2 * index + 1;
|
|
49
|
+
if (child + 1 < candidates.length && compare(candidates[child + 1], candidates[child]) < 0)
|
|
50
|
+
child++;
|
|
51
|
+
if (compare(last, candidates[child]) <= 0)
|
|
52
|
+
break;
|
|
53
|
+
candidates[index] = candidates[child];
|
|
54
|
+
index = child;
|
|
55
|
+
}
|
|
56
|
+
candidates[index] = last;
|
|
57
|
+
}
|
|
58
|
+
const area = normaliseRect(padded(choice.x, choice.y));
|
|
59
|
+
const right = area.x + area.width, bottom = area.y + area.height;
|
|
60
|
+
const hitIndex = bounds.findIndex(obstacle => area.x < obstacle.x + obstacle.width && obstacle.x < right
|
|
61
|
+
&& area.y < obstacle.y + obstacle.height && obstacle.y < bottom);
|
|
62
|
+
const hit = bounds[hitIndex];
|
|
63
|
+
if (hit === undefined) {
|
|
64
|
+
const placed = { ...box, x: choice.x, y: choice.y };
|
|
65
|
+
bounds.push(normaliseRect(placed));
|
|
66
|
+
if (choice.cost === 0)
|
|
67
|
+
return label;
|
|
68
|
+
// Keep the route anchor and attach the last segment to the moved box.
|
|
69
|
+
const anchor = label.leader?.at(-2);
|
|
70
|
+
const leader = anchor === undefined ? undefined : [
|
|
71
|
+
...label.leader.slice(0, -1),
|
|
72
|
+
{ x: Math.max(placed.x, Math.min(anchor.x, placed.x + placed.width)),
|
|
73
|
+
y: Math.max(placed.y, Math.min(anchor.y, placed.y + placed.height)) },
|
|
74
|
+
];
|
|
75
|
+
return { ...label, box: placed, ...(leader === undefined ? {} : { leader }) };
|
|
76
|
+
}
|
|
77
|
+
add(hit.x - clearance - box.width, choice.y);
|
|
78
|
+
add(hit.x + hit.width + clearance, choice.y);
|
|
79
|
+
add(choice.x, hit.y - clearance - box.height);
|
|
80
|
+
add(choice.x, hit.y + hit.height + clearance);
|
|
81
|
+
}
|
|
82
|
+
return label;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=sceneLabelClearance.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): Verdict;
|
|
79
|
+
export declare function relationVerdict(view: ViewDocument, relation: Relation, document?: SemanticDocument): Verdict;
|
|
80
80
|
export interface VisibilityInput {
|
|
81
81
|
readonly document: SemanticDocument;
|
|
82
82
|
readonly view: ViewDocument;
|
package/dist/visibility.js
CHANGED
|
@@ -122,9 +122,9 @@ export function entityVerdict(view, entity) {
|
|
|
122
122
|
verdictFor(filtersOfKind(view, "attribute-equals"), (filter) => filter.kind === "attribute-equals" ? attributeMatches(entity.attributes, filter.attribute, filter.value) : false),
|
|
123
123
|
]);
|
|
124
124
|
}
|
|
125
|
-
export function relationVerdict(view, relation) {
|
|
125
|
+
export function relationVerdict(view, relation, document) {
|
|
126
126
|
return combine([
|
|
127
|
-
verdictFor(filtersOfKind(view, "relation-type"), (filter) => filter.kind === "relation-type" ? filter.types.includes(relation.type) : false),
|
|
127
|
+
verdictFor(filtersOfKind(view, "relation-type"), (filter) => filter.kind === "relation-type" ? filter.types.includes(relation.type) || (document?.typeDefinitions[relation.type]?.profile === relation.profile && filter.types.includes(document.typeDefinitions[relation.type].baseType)) : false),
|
|
128
128
|
verdictFor(filtersOfKind(view, "attribute-equals"), (filter) => filter.kind === "attribute-equals"
|
|
129
129
|
? attributeMatches(relation.attributes, filter.attribute, filter.value)
|
|
130
130
|
: false),
|
|
@@ -179,7 +179,8 @@ export function evaluateVisibility({ document, view }) {
|
|
|
179
179
|
});
|
|
180
180
|
continue;
|
|
181
181
|
}
|
|
182
|
-
|
|
182
|
+
const foldedErd = document.ports[occurrence.port]?.profile === 'erd@1' && Object.values(view.groups).some(group => group.occurrence === occurrence.ownerOccurrence && group.collapsed);
|
|
183
|
+
if (foldedErd || !visible.has(occurrence.ownerOccurrence)) {
|
|
183
184
|
exclusions.push({
|
|
184
185
|
occurrence: occurrence.id,
|
|
185
186
|
kind: "port",
|
|
@@ -202,7 +203,7 @@ export function evaluateVisibility({ document, view }) {
|
|
|
202
203
|
});
|
|
203
204
|
continue;
|
|
204
205
|
}
|
|
205
|
-
const verdict = relationVerdict(view, relation);
|
|
206
|
+
const verdict = relationVerdict(view, relation, document);
|
|
206
207
|
if (!verdict.visible) {
|
|
207
208
|
exclusions.push({
|
|
208
209
|
occurrence: occurrence.id,
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentropic/diagram-canvas",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Headless
|
|
3
|
+
"version": "0.2.2",
|
|
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"
|
|
7
7
|
},
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
10
10
|
"!dist/**/*.map",
|
|
11
|
-
"!dist/.srchash"
|
|
11
|
+
"!dist/.srchash",
|
|
12
|
+
"contracts"
|
|
12
13
|
],
|
|
13
14
|
"type": "module",
|
|
14
15
|
"license": "MIT",
|
|
@@ -22,19 +23,44 @@
|
|
|
22
23
|
"types": "./dist/index.d.ts",
|
|
23
24
|
"import": "./dist/index.js"
|
|
24
25
|
},
|
|
26
|
+
"./diagramCardModel": {
|
|
27
|
+
"types": "./dist/presentation/diagramCardModel.d.ts",
|
|
28
|
+
"import": "./dist/presentation/diagramCardModel.js"
|
|
29
|
+
},
|
|
25
30
|
"./diagramSceneModel": {
|
|
26
31
|
"types": "./dist/presentation/diagramSceneModel.d.ts",
|
|
27
32
|
"import": "./dist/presentation/diagramSceneModel.js"
|
|
33
|
+
},
|
|
34
|
+
"./diagram-icons": {
|
|
35
|
+
"types": "./dist/presentation/registry.d.ts",
|
|
36
|
+
"import": "./dist/presentation/registry.js"
|
|
37
|
+
},
|
|
38
|
+
"./renderCardSvg": {
|
|
39
|
+
"types": "./dist/presentation/renderCardSvg.d.ts",
|
|
40
|
+
"import": "./dist/presentation/renderCardSvg.js"
|
|
41
|
+
},
|
|
42
|
+
"./renderZoneSvg": {
|
|
43
|
+
"types": "./dist/presentation/renderZoneSvg.d.ts",
|
|
44
|
+
"import": "./dist/presentation/renderZoneSvg.js"
|
|
45
|
+
},
|
|
46
|
+
"./diagram-render": {
|
|
47
|
+
"types": "./dist/presentation/index.d.ts",
|
|
48
|
+
"import": "./dist/presentation/index.js"
|
|
49
|
+
},
|
|
50
|
+
"./diagram-anatomy": "./contracts/diagram-anatomy.v1.json",
|
|
51
|
+
"./flowModel": {
|
|
52
|
+
"types": "./dist/presentation/flowModel.d.ts",
|
|
53
|
+
"import": "./dist/presentation/flowModel.js"
|
|
28
54
|
}
|
|
29
55
|
},
|
|
30
56
|
"types": "./dist/index.d.ts",
|
|
31
57
|
"main": "./dist/index.js",
|
|
32
58
|
"sideEffects": false,
|
|
33
59
|
"dependencies": {
|
|
34
|
-
"@sentropic/diagram-core": "0.
|
|
60
|
+
"@sentropic/diagram-core": "0.2.0"
|
|
35
61
|
},
|
|
36
62
|
"scripts": {
|
|
37
|
-
"build": "tsc -p tsconfig.json",
|
|
63
|
+
"build": "node ../../scripts/sync-diagram-spacing.mjs && tsc -p tsconfig.json",
|
|
38
64
|
"check": "tsc -p tsconfig.check.json",
|
|
39
65
|
"test": "vitest run"
|
|
40
66
|
}
|