@sentropic/diagram-canvas 0.2.2 → 0.2.4
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
CHANGED
|
@@ -348,8 +348,12 @@ empty penalty, hysteresis); absent or empty, the DS defaults apply.
|
|
|
348
348
|
maximum display scale (0.62: readout 100 %, a card renders at about
|
|
349
349
|
285 × 124 CSS px) and holds a fit at the readability floor (0.45: an 18 px
|
|
350
350
|
edge label renders at 8.1 CSS px) when the drawing is larger, reporting
|
|
351
|
-
`pans`; `clampZoom` and `zoomReadout` complete it.
|
|
352
|
-
|
|
351
|
+
`pans`; `clampZoom` and `zoomReadout` complete it. Given a `zoomQuantum`, the
|
|
352
|
+
applied fit is floored to that grid, never rounded up past the fit box;
|
|
353
|
+
`sceneFit` passes `FIT_QUANTUM` (1e-3), and a scene host prints that one zoom
|
|
354
|
+
everywhere: world transform, camera state, `data-zoom`, `--st-diagram-zoom`,
|
|
355
|
+
flow hit size and painted-bounds read. No DOM lives here: a scene host passes
|
|
356
|
+
its measured sizes in.
|
|
353
357
|
|
|
354
358
|
The acceptance scenes, the §7 metrics helper, the column baseline as recorded
|
|
355
359
|
before the placement changed (`baseline.json`), the numbers of the shipped
|
package/dist/camera.d.ts
CHANGED
|
@@ -42,6 +42,13 @@ export interface CameraFitInput {
|
|
|
42
42
|
readonly maxDisplayScale?: number;
|
|
43
43
|
/** Optional higher readability floor; never lowers the absolute 0.45 floor. */
|
|
44
44
|
readonly minReadableScale?: number;
|
|
45
|
+
/**
|
|
46
|
+
* Grid the applied fit zoom lands on, scale units. The fit is floored to
|
|
47
|
+
* it, never rounded: an applied zoom above `zoomFit` would paint past the
|
|
48
|
+
* fit box. The display cap and the readability floor are token values and
|
|
49
|
+
* stay exact. Absent: the applied zoom is the exact fit.
|
|
50
|
+
*/
|
|
51
|
+
readonly zoomQuantum?: number;
|
|
45
52
|
}
|
|
46
53
|
export interface CameraFit {
|
|
47
54
|
/** The usable §5.1 fit box, excluding scrollbars, CSS px. */
|
|
@@ -49,7 +56,7 @@ export interface CameraFit {
|
|
|
49
56
|
readonly fitHeight: number;
|
|
50
57
|
/** Zoom framing the whole drawing on both axes, never above the maximum display scale. */
|
|
51
58
|
readonly zoomFit: number;
|
|
52
|
-
/** Zoom a fit or reset applies: `zoomFit` clamped to the readability floor. */
|
|
59
|
+
/** Zoom a fit or reset applies: `zoomFit`, floored to `zoomQuantum` when one is given, clamped to the readability floor. */
|
|
53
60
|
readonly zoom: number;
|
|
54
61
|
/** Interactive range: zoom-out stops at the readable fit, zoom-in at the display cap. */
|
|
55
62
|
readonly minZoom: number;
|
|
@@ -59,6 +66,9 @@ export interface CameraFit {
|
|
|
59
66
|
}
|
|
60
67
|
/** Screen-space inset for non-scaling strokes and CSS layout rounding. */
|
|
61
68
|
export declare const FIT_PAINT_INSET = 1;
|
|
69
|
+
/** Largest multiple of `quantum` that is not above `value`. A quantum that
|
|
70
|
+
* is not a finite positive number defines no grid: the value is returned. */
|
|
71
|
+
export declare function floorToQuantum(value: number, quantum: number): number;
|
|
62
72
|
/** §5.1: `fitW = viewW`, `fitH = min(viewW × 9/16, 0.85 × windowH)`. */
|
|
63
73
|
export declare function fitBox(viewWidth: number, windowHeight: number): {
|
|
64
74
|
readonly width: number;
|
package/dist/camera.js
CHANGED
|
@@ -29,6 +29,22 @@ export const FIT_WINDOW_HEIGHT_SHARE = 0.85;
|
|
|
29
29
|
export const FIT_ASPECT = 16 / 9;
|
|
30
30
|
/** Screen-space inset for non-scaling strokes and CSS layout rounding. */
|
|
31
31
|
export const FIT_PAINT_INSET = 1;
|
|
32
|
+
/** Largest multiple of `quantum` that is not above `value`. A quantum that
|
|
33
|
+
* is not a finite positive number defines no grid: the value is returned. */
|
|
34
|
+
export function floorToQuantum(value, quantum) {
|
|
35
|
+
if (!(quantum > 0) || !Number.isFinite(quantum) || !Number.isFinite(value))
|
|
36
|
+
return value;
|
|
37
|
+
const perUnit = 1 / quantum;
|
|
38
|
+
let steps = Math.floor(value * perUnit);
|
|
39
|
+
// The product is rounded: it can land one ulp on either side of an exact
|
|
40
|
+
// multiple (0.501 × 1000 = 500.99999999999994). Settle on the largest
|
|
41
|
+
// step that is not above the value, so the result never exceeds it.
|
|
42
|
+
if (steps / perUnit > value)
|
|
43
|
+
steps -= 1;
|
|
44
|
+
else if ((steps + 1) / perUnit <= value)
|
|
45
|
+
steps += 1;
|
|
46
|
+
return steps / perUnit;
|
|
47
|
+
}
|
|
32
48
|
/** §5.1: `fitW = viewW`, `fitH = min(viewW × 9/16, 0.85 × windowH)`. */
|
|
33
49
|
export function fitBox(viewWidth, windowHeight) {
|
|
34
50
|
return { width: viewWidth, height: Math.min(viewWidth / FIT_ASPECT, FIT_WINDOW_HEIGHT_SHARE * windowHeight) };
|
|
@@ -46,9 +62,13 @@ export function cameraFit(input) {
|
|
|
46
62
|
return { fitWidth: box.width, fitHeight: box.height, zoomFit: maxZoom, zoom: maxZoom, minZoom: maxZoom, maxZoom, pans: false };
|
|
47
63
|
}
|
|
48
64
|
const zoomFit = Math.min(Math.max(0, box.width - 2 * FIT_PAINT_INSET) / bounds.width, Math.max(0, box.height - 2 * FIT_PAINT_INSET) / bounds.height, maxZoom);
|
|
65
|
+
// The applied zoom is quantised here, once, and downward: every consumer
|
|
66
|
+
// (transform, camera state, painted-bounds read) gets this single value,
|
|
67
|
+
// and the fit height below is the one of the drawing at that same zoom.
|
|
68
|
+
const applied = input.zoomQuantum === undefined || zoomFit >= maxZoom ? zoomFit : floorToQuantum(zoomFit, input.zoomQuantum);
|
|
49
69
|
// All hosts and camera inputs share this range. A small frame or a large
|
|
50
70
|
// unfolded scene reaches the floor, then scrolls instead of shrinking text.
|
|
51
|
-
const zoom = Math.max(readableFloor,
|
|
71
|
+
const zoom = Math.max(readableFloor, applied);
|
|
52
72
|
const fitHeight = Math.min(box.height, Math.ceil((bounds.height * zoom + 2 * FIT_PAINT_INSET) * 64) / 64);
|
|
53
73
|
return { fitWidth: box.width, fitHeight, zoomFit, zoom, minZoom: zoom, maxZoom, pans: zoom > zoomFit };
|
|
54
74
|
}
|
|
@@ -122,6 +122,47 @@ export interface SceneNodeModel {
|
|
|
122
122
|
readonly text: string;
|
|
123
123
|
readonly erd?: ErdCard;
|
|
124
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Paint plane of a node, relative to the connectors. A scene paints, bottom
|
|
127
|
+
* to top: every `frame`, the connectors, every `box`, then badges and labels.
|
|
128
|
+
*
|
|
129
|
+
* A `frame` is the surface of an expanded zone: it carries an opaque fill and
|
|
130
|
+
* holds the boxes its relations join, so a connector painted under it is
|
|
131
|
+
* hidden along its whole run inside the zone while its label, painted last,
|
|
132
|
+
* stays visible. The frame also paints its own footer text where routes run:
|
|
133
|
+
* the connector layer is masked over it (`sceneConnectorMask`), so a route
|
|
134
|
+
* leaving a zone passes behind its footer text. A `box` is atomic (card, collapsed zone, ERD card, legend
|
|
135
|
+
* key, label node): a route ends on its border and stays under it.
|
|
136
|
+
*
|
|
137
|
+
* The order matches the scene frame (`scene.ts`): a container sits on a
|
|
138
|
+
* negative plane, a connector between two cards on plane 0, under the cards.
|
|
139
|
+
*/
|
|
140
|
+
export type ScenePaintPlane = "frame" | "box";
|
|
141
|
+
export declare function scenePaintPlane(node: Pick<SceneNodeModel, "kind" | "collapsed">): ScenePaintPlane;
|
|
142
|
+
/** The nodes of one paint plane, in the scene's own bottom-to-top order. */
|
|
143
|
+
export declare function sceneNodesOnPlane<T extends Pick<SceneNodeModel, "kind" | "collapsed">>(nodes: readonly T[], plane: ScenePaintPlane): readonly T[];
|
|
144
|
+
/** World margin of the connector mask around the scene bounds: stroke, arrow heads and markers stay inside. */
|
|
145
|
+
export declare const CONNECTOR_MASK_MARGIN = 64;
|
|
146
|
+
/**
|
|
147
|
+
* World slack of a connector cutout beyond the label clearance. The cutout is
|
|
148
|
+
* derived from the measured footer width and the frozen line box; the slack
|
|
149
|
+
* absorbs the difference between that measure and the rendered ink: measured
|
|
150
|
+
* in a browser at the readability floor, the ink reaches half a world unit
|
|
151
|
+
* past the measured box, and a connector end is painted one stroke further.
|
|
152
|
+
*/
|
|
153
|
+
export declare const CONNECTOR_CUTOUT_SLACK = 3;
|
|
154
|
+
export interface SceneConnectorMask {
|
|
155
|
+
/** The painted region: the scene bounds grown by `CONNECTOR_MASK_MARGIN`. */
|
|
156
|
+
readonly region: Rect;
|
|
157
|
+
/** The boxes cut out of it (`SceneModel.connectorCutouts`). */
|
|
158
|
+
readonly cutouts: readonly Rect[];
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The mask of the connector layer: everything is painted but the footer text
|
|
162
|
+
* of the expanded zones. `undefined` when there is nothing to cut out (no
|
|
163
|
+
* expanded zone with a footer): the layer then needs no mask at all.
|
|
164
|
+
*/
|
|
165
|
+
export declare function sceneConnectorMask(scene: Pick<SceneModel, "bounds" | "connectorCutouts">): SceneConnectorMask | undefined;
|
|
125
166
|
export interface SceneEdgeModel {
|
|
126
167
|
readonly directed: boolean;
|
|
127
168
|
readonly arrows: readonly FlowArrow[];
|
|
@@ -172,6 +213,15 @@ export interface SceneModel {
|
|
|
172
213
|
readonly nodes: readonly SceneNodeModel[];
|
|
173
214
|
readonly edges: readonly SceneEdgeModel[];
|
|
174
215
|
readonly labels: readonly SceneLabelModel[];
|
|
216
|
+
/**
|
|
217
|
+
* Footer text box of every expanded zone, grown by the label clearance: the
|
|
218
|
+
* one text a frame paints where routes run. A route may cross a zone footer
|
|
219
|
+
* or follow it on its way out (the router keeps every route out of a title
|
|
220
|
+
* band, not out of a footer band), so the connector layer is masked over
|
|
221
|
+
* these boxes: a connector is painted above the frame surface and passes
|
|
222
|
+
* behind the footer text, never through it.
|
|
223
|
+
*/
|
|
224
|
+
readonly connectorCutouts: readonly Rect[];
|
|
175
225
|
/**
|
|
176
226
|
* Fit bbox (BF-7): `rectUnion(scene.bounds, placed label boxes)`.
|
|
177
227
|
* `undefined` for an empty scene.
|
|
@@ -198,7 +248,15 @@ export interface SceneCameraInput {
|
|
|
198
248
|
readonly maxDisplayScale?: number;
|
|
199
249
|
readonly minReadableScale?: number;
|
|
200
250
|
}
|
|
201
|
-
/**
|
|
251
|
+
/**
|
|
252
|
+
* Quantum of the applied fit zoom, scale units. `sceneFit` floors every fit
|
|
253
|
+
* to it, so a fit does not follow sub-quantum changes of its bounds. The
|
|
254
|
+
* hosts print the resulting zoom as it is: one value for the world
|
|
255
|
+
* transform, the camera state, `data-zoom`, `--st-diagram-zoom`, the flow
|
|
256
|
+
* hit size and the painted-bounds read. Nothing is rounded again downstream.
|
|
257
|
+
*/
|
|
258
|
+
export declare const FIT_QUANTUM = 0.001;
|
|
259
|
+
/** §5.1 / BF-2 fit of the scene bounds, as `cameraFit` computes it on the `FIT_QUANTUM` grid. */
|
|
202
260
|
export declare function sceneFit(input: SceneCameraInput): CameraFit;
|
|
203
261
|
/**
|
|
204
262
|
* The camera zoom for a request (Z-1, Z-7, Z-8). `undefined` means « no
|
|
@@ -115,6 +115,37 @@ export function collapsedOccurrencesOf(view) {
|
|
|
115
115
|
}
|
|
116
116
|
return found;
|
|
117
117
|
}
|
|
118
|
+
export function scenePaintPlane(node) {
|
|
119
|
+
return node.kind === "zone" && !node.collapsed ? "frame" : "box";
|
|
120
|
+
}
|
|
121
|
+
/** The nodes of one paint plane, in the scene's own bottom-to-top order. */
|
|
122
|
+
export function sceneNodesOnPlane(nodes, plane) {
|
|
123
|
+
return nodes.filter((node) => scenePaintPlane(node) === plane);
|
|
124
|
+
}
|
|
125
|
+
/** World margin of the connector mask around the scene bounds: stroke, arrow heads and markers stay inside. */
|
|
126
|
+
export const CONNECTOR_MASK_MARGIN = 64;
|
|
127
|
+
/**
|
|
128
|
+
* World slack of a connector cutout beyond the label clearance. The cutout is
|
|
129
|
+
* derived from the measured footer width and the frozen line box; the slack
|
|
130
|
+
* absorbs the difference between that measure and the rendered ink: measured
|
|
131
|
+
* in a browser at the readability floor, the ink reaches half a world unit
|
|
132
|
+
* past the measured box, and a connector end is painted one stroke further.
|
|
133
|
+
*/
|
|
134
|
+
export const CONNECTOR_CUTOUT_SLACK = 3;
|
|
135
|
+
/**
|
|
136
|
+
* The mask of the connector layer: everything is painted but the footer text
|
|
137
|
+
* of the expanded zones. `undefined` when there is nothing to cut out (no
|
|
138
|
+
* expanded zone with a footer): the layer then needs no mask at all.
|
|
139
|
+
*/
|
|
140
|
+
export function sceneConnectorMask(scene) {
|
|
141
|
+
if (scene.bounds === undefined || scene.connectorCutouts.length === 0)
|
|
142
|
+
return undefined;
|
|
143
|
+
const { x, y, width, height } = scene.bounds;
|
|
144
|
+
return {
|
|
145
|
+
region: { x: x - CONNECTOR_MASK_MARGIN, y: y - CONNECTOR_MASK_MARGIN, width: width + 2 * CONNECTOR_MASK_MARGIN, height: height + 2 * CONNECTOR_MASK_MARGIN },
|
|
146
|
+
cutouts: scene.connectorCutouts,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
118
149
|
const byCodeUnit = (left, right) => (left < right ? -1 : left > right ? 1 : 0);
|
|
119
150
|
function edgeLabelOf(document, relation) {
|
|
120
151
|
const attributes = document.relations[relation]?.attributes;
|
|
@@ -167,6 +198,13 @@ export function resolveScene(result, input) {
|
|
|
167
198
|
const measuredLabels = new Map((result.measurements?.slots ?? []).filter((slot) => slot.role === "edge-label").map((slot) => [slot.occurrence, slot.layout]));
|
|
168
199
|
const headerHeights = new Map((result.measurements?.headers ?? []).map((header) => [header.occurrence, header.height]));
|
|
169
200
|
const blockers = [];
|
|
201
|
+
const connectorCutouts = [];
|
|
202
|
+
const footerWidths = new Map((result.measurements?.slots ?? []).filter((slot) => slot.role === "footer").map((slot) => [slot.occurrence, slot.layout.width]));
|
|
203
|
+
const margin = input.metrics?.labelMargin ?? DEFAULT_LAYOUT_METRICS.labelMargin;
|
|
204
|
+
// Non-scaling connector paint is widest in world units at the readability
|
|
205
|
+
// floor. Reserve it as well as the label-padding token supplied by hosts.
|
|
206
|
+
const paintClearance = margin + ZONE_GEOMETRY.borderWidth / (2 * DEFAULT_MIN_READABLE_SCALE);
|
|
207
|
+
const zoneInset = input.metrics?.containerPadding ?? ZONE_GEOMETRY.contentInsetInline;
|
|
170
208
|
for (const node of nodes) {
|
|
171
209
|
if (node.kind !== "zone" || node.collapsed) {
|
|
172
210
|
blockers.push(node.rect);
|
|
@@ -186,9 +224,23 @@ export function resolveScene(result, input) {
|
|
|
186
224
|
// the presentation instead of measuring the scene again during replay.
|
|
187
225
|
const reserve = node.presentation?.text.footer?.trim()
|
|
188
226
|
? lineBoxHeight(ZONE_GEOMETRY.footer.size) + ZONE_GEOMETRY.ruleHeight + 2 * ZONE_GEOMETRY.ruleMargin + ZONE_GEOMETRY.footerBottomInset : 0;
|
|
189
|
-
if (reserve > 0)
|
|
227
|
+
if (reserve > 0) {
|
|
190
228
|
blockers.push({ x: node.rect.x, y: node.rect.y + node.rect.height - reserve - ZONE_GEOMETRY.borderWidth - ruleClearance,
|
|
191
229
|
width: node.rect.width, height: reserve + ZONE_GEOMETRY.borderWidth + ruleClearance });
|
|
230
|
+
// The footer line as `layoutZone` seats it: one line box pinned above
|
|
231
|
+
// the bottom border, from the content inset, as wide as its measured
|
|
232
|
+
// text (the whole inner width when the result carries no measurement).
|
|
233
|
+
const inner = Math.max(0, node.rect.width - 2 * zoneInset);
|
|
234
|
+
const lineHeight = lineBoxHeight(ZONE_GEOMETRY.footer.size);
|
|
235
|
+
const bottom = node.rect.y + node.rect.height - ZONE_GEOMETRY.borderWidth - ZONE_GEOMETRY.footerBottomInset;
|
|
236
|
+
const pad = paintClearance + CONNECTOR_CUTOUT_SLACK;
|
|
237
|
+
connectorCutouts.push({
|
|
238
|
+
x: node.rect.x + zoneInset - pad,
|
|
239
|
+
y: bottom - lineHeight - pad,
|
|
240
|
+
width: Math.min(footerWidths.get(node.occurrence) ?? inner, inner) + 2 * pad,
|
|
241
|
+
height: lineHeight + 2 * pad,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
192
244
|
}
|
|
193
245
|
const allFlows = flowIndex(input.document);
|
|
194
246
|
const flowTargets = result.flowTargets ?? {};
|
|
@@ -259,7 +311,6 @@ export function resolveScene(result, input) {
|
|
|
259
311
|
labelLines.set(id, lines);
|
|
260
312
|
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 } });
|
|
261
313
|
}
|
|
262
|
-
const margin = input.metrics?.labelMargin ?? DEFAULT_LAYOUT_METRICS.labelMargin;
|
|
263
314
|
const labels = [];
|
|
264
315
|
let bounds;
|
|
265
316
|
for (const item of items) {
|
|
@@ -270,8 +321,11 @@ export function resolveScene(result, input) {
|
|
|
270
321
|
const placements = erd ? placeErdRoleLabels(entries, blockers, margin) : result.labelBoxes === undefined
|
|
271
322
|
? placeEdgeLabels(entries, blockers, margin)
|
|
272
323
|
: new Map(Object.entries(result.labelBoxes).map(([id, box]) => [id, { box }]));
|
|
324
|
+
// A label is the label of a drawn connector: a placement whose relation has
|
|
325
|
+
// no route in this scene is dropped, so a label never paints without a line.
|
|
326
|
+
const labelled = new Set(entries.map((entry) => entry.id));
|
|
273
327
|
for (const [id, placement] of placements) {
|
|
274
|
-
if (placement === undefined)
|
|
328
|
+
if (placement === undefined || !labelled.has(id))
|
|
275
329
|
continue;
|
|
276
330
|
labels.push({ occurrence: id, lines: labelLines.get(id) ?? [], box: placement.box, ...(erd ? { erd: true } : {}), ...("leader" in placement ? { leader: placement.leader } : {}),
|
|
277
331
|
...(result.edgeBundles?.[id] === undefined ? {} : { title: result.edgeBundles[id].title }),
|
|
@@ -293,9 +347,7 @@ export function resolveScene(result, input) {
|
|
|
293
347
|
for (const arrows of Object.values(result.arrowBoxes ?? {}))
|
|
294
348
|
for (const arrow of arrows)
|
|
295
349
|
bounds = bounds === undefined ? arrow.box : rectUnion(bounds, arrow.box);
|
|
296
|
-
|
|
297
|
-
// floor. Reserve it as well as the label-padding token supplied by hosts.
|
|
298
|
-
const clearedLabels = clearSceneLabels(labels, edges.map(edge => edge.points), [...blockers, ...badges.map(badge => badge.box), ...edges.flatMap(edge => edge.arrows.map(arrow => arrow.box))], margin + ZONE_GEOMETRY.borderWidth / (2 * DEFAULT_MIN_READABLE_SCALE));
|
|
350
|
+
const clearedLabels = clearSceneLabels(labels, edges.map(edge => edge.points), [...blockers, ...badges.map(badge => badge.box), ...edges.flatMap(edge => edge.arrows.map(arrow => arrow.box))], paintClearance);
|
|
299
351
|
for (const { box } of clearedLabels) {
|
|
300
352
|
const padded = { x: box.x - margin, y: box.y - margin, width: box.width + 2 * margin, height: box.height + 2 * margin };
|
|
301
353
|
bounds = bounds === undefined ? padded : rectUnion(bounds, padded);
|
|
@@ -312,6 +364,7 @@ export function resolveScene(result, input) {
|
|
|
312
364
|
nodes,
|
|
313
365
|
edges,
|
|
314
366
|
labels: clearedLabels,
|
|
367
|
+
connectorCutouts,
|
|
315
368
|
...(bounds === undefined ? {} : { bounds }),
|
|
316
369
|
orientations: result.orientations ?? {},
|
|
317
370
|
};
|
|
@@ -325,7 +378,15 @@ export function sceneTextRows(scene, document) {
|
|
|
325
378
|
}
|
|
326
379
|
return rows;
|
|
327
380
|
}
|
|
328
|
-
/**
|
|
381
|
+
/**
|
|
382
|
+
* Quantum of the applied fit zoom, scale units. `sceneFit` floors every fit
|
|
383
|
+
* to it, so a fit does not follow sub-quantum changes of its bounds. The
|
|
384
|
+
* hosts print the resulting zoom as it is: one value for the world
|
|
385
|
+
* transform, the camera state, `data-zoom`, `--st-diagram-zoom`, the flow
|
|
386
|
+
* hit size and the painted-bounds read. Nothing is rounded again downstream.
|
|
387
|
+
*/
|
|
388
|
+
export const FIT_QUANTUM = 1e-3;
|
|
389
|
+
/** §5.1 / BF-2 fit of the scene bounds, as `cameraFit` computes it on the `FIT_QUANTUM` grid. */
|
|
329
390
|
export function sceneFit(input) {
|
|
330
391
|
return cameraFit({
|
|
331
392
|
...(input.bounds === undefined ? {} : { bounds: input.bounds }),
|
|
@@ -334,6 +395,7 @@ export function sceneFit(input) {
|
|
|
334
395
|
...(input.scrollbarHeight === undefined ? {} : { scrollbarHeight: input.scrollbarHeight }),
|
|
335
396
|
...(input.maxDisplayScale === undefined ? {} : { maxDisplayScale: input.maxDisplayScale }),
|
|
336
397
|
...(input.minReadableScale === undefined ? {} : { minReadableScale: input.minReadableScale }),
|
|
398
|
+
zoomQuantum: FIT_QUANTUM,
|
|
337
399
|
});
|
|
338
400
|
}
|
|
339
401
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { renderErdCardSvg } from './erd.js';
|
|
2
2
|
/** Standalone server-side SVG, consuming exactly the scene model used by the framework hosts. */
|
|
3
|
-
import { layoutScene, resolveScene, sceneFit } from './diagramSceneModel.js';
|
|
3
|
+
import { layoutScene, resolveScene, sceneConnectorMask, sceneFit, sceneNodesOnPlane } from './diagramSceneModel.js';
|
|
4
4
|
import { cardLineMeasurer, defaultCardMeasure, sceneCardMeasure, projectCardProps, projectZoneProps } from './diagramCardModel.js';
|
|
5
5
|
import { renderCardSvg } from './renderCardSvg.js';
|
|
6
6
|
import { renderZoneSvg } from './renderZoneSvg.js';
|
|
@@ -21,7 +21,7 @@ export function renderSceneSvg(input, options = {}) {
|
|
|
21
21
|
const viewportWidth = input.targetWidth ?? 1440;
|
|
22
22
|
const fit = sceneFit({ bounds: box, viewWidth: viewportWidth, windowHeight: 900 });
|
|
23
23
|
const edges = scene.edges.map(edge => `<polyline data-scene-edge="${escape(edge.occurrence)}" points="${edge.points.map(p => p.x + ',' + p.y).join(' ')}" fill="none" stroke="var(--st-component-diagramScene-edgeStroke, #64748b)" stroke-width="1.5" stroke-linejoin="round" ${edge.markers === undefined ? 'marker-end="url(#scene-arrow)"' : ''}/>${edge.markers ?? ''}`).join('');
|
|
24
|
-
const
|
|
24
|
+
const drawNode = (node) => {
|
|
25
25
|
const measure = measureFor(node.collapsed);
|
|
26
26
|
if (node.kind === 'erd' && node.erd !== undefined)
|
|
27
27
|
return `<g data-scene-occurrence="${escape(node.occurrence)}" transform="translate(${node.rect.x} ${node.rect.y})">${renderErdCardSvg(node.erd)}</g>`;
|
|
@@ -33,7 +33,15 @@ export function renderSceneSvg(input, options = {}) {
|
|
|
33
33
|
if (rendered.kind !== 'rendered')
|
|
34
34
|
throw new Error('Content must never refuse a component');
|
|
35
35
|
return `<g data-scene-occurrence="${escape(node.occurrence)}" transform="translate(${node.rect.x} ${node.rect.y})">${rendered.svg}</g>`;
|
|
36
|
-
}
|
|
36
|
+
};
|
|
37
|
+
// Expanded zone surfaces are opaque: they paint under the connectors, the boxes above them.
|
|
38
|
+
// The connector layer is masked over the footer text the frames paint themselves.
|
|
39
|
+
const mask = sceneConnectorMask(scene);
|
|
40
|
+
const box4 = (r) => `x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}"`;
|
|
41
|
+
const maskDef = mask === undefined ? '' : `<mask id="scene-connector-mask" maskUnits="userSpaceOnUse" ${box4(mask.region)}><rect ${box4(mask.region)} fill="#fff"/>${mask.cutouts.map(cutout => `<rect data-scene-cutout="" ${box4(cutout)} fill="#000"/>`).join('')}</mask>`;
|
|
42
|
+
const connectors = `<g data-scene-connectors=""${mask === undefined ? '' : ' mask="url(#scene-connector-mask)"'}>${edges}</g>`;
|
|
43
|
+
const frames = sceneNodesOnPlane(scene.nodes, 'frame').map(drawNode).join('');
|
|
44
|
+
const boxes = sceneNodesOnPlane(scene.nodes, 'box').map(drawNode).join('');
|
|
37
45
|
const labels = scene.labels.map(label => {
|
|
38
46
|
const b = label.box;
|
|
39
47
|
let text = '';
|
|
@@ -50,7 +58,7 @@ export function renderSceneSvg(input, options = {}) {
|
|
|
50
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)"/>`;
|
|
51
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>`;
|
|
52
60
|
}).join('');
|
|
53
|
-
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
|
|
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>`;
|
|
54
62
|
return { svg, result, scene };
|
|
55
63
|
}
|
|
56
64
|
//# sourceMappingURL=renderSceneSvg.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentropic/diagram-canvas",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
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"
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"main": "./dist/index.js",
|
|
58
58
|
"sideEffects": false,
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@sentropic/diagram-core": "0.
|
|
60
|
+
"@sentropic/diagram-core": "0.3.0"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "node ../../scripts/sync-diagram-spacing.mjs && tsc -p tsconfig.json",
|