@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,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `renderCardSvg` — pure atomic-card SVG renderer (DC-1).
|
|
3
|
+
*
|
|
4
|
+
* Plain TypeScript, no Svelte import. Ships on the
|
|
5
|
+
* `@sentropic/design-system-svelte/diagram-render` subpath. Consumes the
|
|
6
|
+
* same geometry source as the Svelte `DiagramCard`: the `diagramCard`
|
|
7
|
+
* component tokens plus the `diagram-canvas` `measure.ts` constants, via
|
|
8
|
+
* `./diagramCardModel.js` (shared projection + line layout).
|
|
9
|
+
*
|
|
10
|
+
* Exactly one rule element, drawn non-scaling (§5.4, DIF-07, DH-04); fixed
|
|
11
|
+
* 460 × 200 box; square corners; footer pinned at 9.25. Long slots use
|
|
12
|
+
* measured ellipses (owner A14); title/description retain the complete text
|
|
13
|
+
* and informational diagnostics report the hidden length.
|
|
14
|
+
*/
|
|
15
|
+
import { layoutCard, projectCardProps, type CardDiagnostic, type CardLayout, type CardLineMeasure, type CardPresentationInput, type DiagramCardProps, type DiagramGlyphPaths } from "./diagramCardModel.js";
|
|
16
|
+
export type { CardDiagnostic, CardLayout, CardLineMeasure, CardPresentationInput, DiagramCardProps, DiagramGlyphPaths, };
|
|
17
|
+
export { projectCardProps };
|
|
18
|
+
/** Icon pictogram group at (x, y) in the caller's coordinate space. */
|
|
19
|
+
export declare function iconGroupFor(name: string, glyph: DiagramGlyphPaths | undefined, x: number, y: number, size: number): string;
|
|
20
|
+
/**
|
|
21
|
+
* Card-local content (border, accent bar, icon, slots, rule, footer,
|
|
22
|
+
* toggle) with no `<svg>` root — shared by `renderCardSvg` (wrapped in a
|
|
23
|
+
* standalone root) and `renderZoneSvg` (wrapped in a translated `<g>` for
|
|
24
|
+
* the collapsed zone, §6.2: the zone IS the card).
|
|
25
|
+
*/
|
|
26
|
+
export declare function renderCardContent(props: DiagramCardProps, measure?: CardLineMeasure): {
|
|
27
|
+
readonly content: string;
|
|
28
|
+
readonly layout: ReturnType<typeof layoutCard>;
|
|
29
|
+
};
|
|
30
|
+
/** The +/- toggle glyph in its slot box (card-local coordinates). */
|
|
31
|
+
export declare function toggleGlyph(toggle: {
|
|
32
|
+
collapsed: boolean;
|
|
33
|
+
label: string;
|
|
34
|
+
}, box: {
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
size: number;
|
|
38
|
+
}): string;
|
|
39
|
+
/** Content is always rendered (owner A11). The legacy refused variant remains for source compatibility. */
|
|
40
|
+
export type CardSvgResult = {
|
|
41
|
+
readonly kind: "rendered";
|
|
42
|
+
readonly svg: string;
|
|
43
|
+
readonly diagnostics: readonly CardDiagnostic[];
|
|
44
|
+
readonly layout: CardLayout;
|
|
45
|
+
} | {
|
|
46
|
+
readonly kind: "refused";
|
|
47
|
+
readonly diagnostics: readonly CardDiagnostic[];
|
|
48
|
+
readonly layout: CardLayout;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Render one atomic card as a standalone SVG string. `measure` defaults to
|
|
52
|
+
* the deterministic greedy wrapper; production hosts pass their measured
|
|
53
|
+
* `LineMeasurer` adapter. Returns all content and any hard-cap diagnostics (owner A11).
|
|
54
|
+
*/
|
|
55
|
+
export declare function renderCardSvg(props: DiagramCardProps, measure?: CardLineMeasure): CardSvgResult;
|
|
56
|
+
/**
|
|
57
|
+
* Convenience: project an `EntityPresentation` then render it. Returns
|
|
58
|
+
* `{ kind: "label" }` when the view carries no card presentation for the
|
|
59
|
+
* entity — the host renders a simple label node and no card — and
|
|
60
|
+
* `{ kind: "card", result }` otherwise, where `result` is the refused or
|
|
61
|
+
* rendered `CardSvgResult`.
|
|
62
|
+
*/
|
|
63
|
+
export declare function renderCardSvgFromPresentation(presentation: CardPresentationInput | undefined, opts: {
|
|
64
|
+
entityId: string;
|
|
65
|
+
toggle?: DiagramCardProps["toggle"];
|
|
66
|
+
measure?: CardLineMeasure;
|
|
67
|
+
}): {
|
|
68
|
+
kind: "card";
|
|
69
|
+
result: CardSvgResult;
|
|
70
|
+
} | {
|
|
71
|
+
kind: "label";
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=renderCardSvg.d.ts.map
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `renderCardSvg` — pure atomic-card SVG renderer (DC-1).
|
|
3
|
+
*
|
|
4
|
+
* Plain TypeScript, no Svelte import. Ships on the
|
|
5
|
+
* `@sentropic/design-system-svelte/diagram-render` subpath. Consumes the
|
|
6
|
+
* same geometry source as the Svelte `DiagramCard`: the `diagramCard`
|
|
7
|
+
* component tokens plus the `diagram-canvas` `measure.ts` constants, via
|
|
8
|
+
* `./diagramCardModel.js` (shared projection + line layout).
|
|
9
|
+
*
|
|
10
|
+
* Exactly one rule element, drawn non-scaling (§5.4, DIF-07, DH-04); fixed
|
|
11
|
+
* 460 × 200 box; square corners; footer pinned at 9.25. Long slots use
|
|
12
|
+
* measured ellipses (owner A14); title/description retain the complete text
|
|
13
|
+
* and informational diagnostics report the hidden length.
|
|
14
|
+
*/
|
|
15
|
+
import { cardFullText, CARD_GEOMETRY, defaultCardMeasure, layoutCard, projectCardProps, } from "./diagramCardModel.js";
|
|
16
|
+
import { DIAGRAM_GLYPH_BASE, getDiagramGlyph, } from "./registry.js";
|
|
17
|
+
export { projectCardProps };
|
|
18
|
+
function escapeXml(value) {
|
|
19
|
+
return String(value)
|
|
20
|
+
.replaceAll("&", "&")
|
|
21
|
+
.replaceAll("<", "<")
|
|
22
|
+
.replaceAll(">", ">")
|
|
23
|
+
.replaceAll('"', """);
|
|
24
|
+
}
|
|
25
|
+
const FONT_STACK = "var(--st-font-sans, system-ui, sans-serif)";
|
|
26
|
+
/** Icon pictogram group at (x, y) in the caller's coordinate space. */
|
|
27
|
+
export function iconGroupFor(name, glyph, x, y, size) {
|
|
28
|
+
if (glyph === undefined)
|
|
29
|
+
return "";
|
|
30
|
+
const scale = size / 64;
|
|
31
|
+
const lineStroke = glyph.darkLine === true
|
|
32
|
+
? "var(--st-component-diagramIcon-lineDarkStroke, var(--st-semantic-feedback-info))"
|
|
33
|
+
: "var(--st-component-diagramIcon-lineStroke, var(--st-semantic-surface-raised))";
|
|
34
|
+
return `<g class="st-diagramCard-icon" data-diagram-icon="${escapeXml(name)}" transform="translate(${x} ${y}) scale(${scale})" aria-hidden="true">` +
|
|
35
|
+
`<path d="${DIAGRAM_GLYPH_BASE}" fill="var(--st-component-diagramIcon-baseFill, color-mix(in srgb, var(--st-semantic-feedback-info) 18%, var(--st-semantic-surface-raised)))"/>` +
|
|
36
|
+
`<path d="${escapeXml(glyph.face)}" fill="var(--st-component-diagramIcon-faceFill, color-mix(in srgb, var(--st-semantic-feedback-info) 75%, var(--st-semantic-surface-raised)))" stroke="var(--st-component-diagramIcon-faceStroke, var(--st-semantic-feedback-info))" stroke-width="1.5" stroke-linejoin="round"/>` +
|
|
37
|
+
(glyph.line === undefined
|
|
38
|
+
? ""
|
|
39
|
+
: `<path d="${escapeXml(glyph.line)}" fill="none" stroke="${lineStroke}" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/>`) +
|
|
40
|
+
(glyph.text === undefined
|
|
41
|
+
? ""
|
|
42
|
+
: `<text x="32" y="47" text-anchor="middle" fill="var(--st-component-diagramIcon-lineStroke, var(--st-semantic-surface-raised))" font-size="13" font-weight="750">${escapeXml(glyph.text)}</text>`) +
|
|
43
|
+
`</g>`;
|
|
44
|
+
}
|
|
45
|
+
function textLines(lines, className, fill, extra) {
|
|
46
|
+
return lines
|
|
47
|
+
.map((line) => `<text class="${className}" x="${line.x}" y="${line.baseline}" text-anchor="${line.anchor === "middle" ? "middle" : "start"}" font-size="${line.size}" font-weight="${line.weight}" fill="${fill}"${extra}>${escapeXml(line.text)}</text>`)
|
|
48
|
+
.join("");
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Card-local content (border, accent bar, icon, slots, rule, footer,
|
|
52
|
+
* toggle) with no `<svg>` root — shared by `renderCardSvg` (wrapped in a
|
|
53
|
+
* standalone root) and `renderZoneSvg` (wrapped in a translated `<g>` for
|
|
54
|
+
* the collapsed zone, §6.2: the zone IS the card).
|
|
55
|
+
*/
|
|
56
|
+
export function renderCardContent(props, measure = defaultCardMeasure) {
|
|
57
|
+
const layout = layoutCard(props, measure);
|
|
58
|
+
const g = { ...CARD_GEOMETRY, height: layout.box.height };
|
|
59
|
+
const parts = [`<title>${escapeXml(cardFullText(props))}</title><desc>${escapeXml(cardFullText(props))}</desc>`];
|
|
60
|
+
// Border, then the accent bar over the left stroke (border-left look).
|
|
61
|
+
// A proposed card is always drawn dashed, independently of the tint
|
|
62
|
+
// (owner criterion 5); the dash pattern is the kit's `4 5`.
|
|
63
|
+
parts.push(`<rect x="1" y="1" width="${g.width - 2}" height="${g.height - 2}" fill="var(--st-component-diagramCard-surface, var(--st-semantic-surface-raised))" 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
|
+
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
|
+
if (layout.iconBox !== undefined) {
|
|
66
|
+
parts.push(iconGroupFor(layout.icon.name, layout.icon.glyph, layout.iconBox.x, layout.iconBox.y, layout.iconBox.size));
|
|
67
|
+
}
|
|
68
|
+
if (layout.kicker.length > 0) {
|
|
69
|
+
parts.push(textLines(layout.kicker, "st-diagramCard-kicker", "var(--st-component-diagramCard-secondaryText, var(--st-semantic-text-secondary))", ` letter-spacing="0.04em" style="text-transform:uppercase"`));
|
|
70
|
+
}
|
|
71
|
+
if (layout.title.length > 0) {
|
|
72
|
+
parts.push(textLines(layout.title, "st-diagramCard-title", "var(--st-component-diagramCard-text, var(--st-semantic-text-primary))", ""));
|
|
73
|
+
}
|
|
74
|
+
if (layout.body.length > 0) {
|
|
75
|
+
const secondary = layout.body.filter((line) => line.secondary);
|
|
76
|
+
const primary = layout.body.filter((line) => !line.secondary);
|
|
77
|
+
if (primary.length > 0) {
|
|
78
|
+
parts.push(textLines(primary, "st-diagramCard-body", "var(--st-component-diagramCard-text, var(--st-semantic-text-primary))", ""));
|
|
79
|
+
}
|
|
80
|
+
if (secondary.length > 0) {
|
|
81
|
+
parts.push(textLines(secondary, "st-diagramCard-detail", "var(--st-component-diagramCard-secondaryText, var(--st-semantic-text-secondary))", ""));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (layout.ruleY !== undefined) {
|
|
85
|
+
parts.push(`<line class="st-diagramCard-rule" x1="${layout.ruleX1}" x2="${layout.ruleX2}" y1="${layout.ruleY}" y2="${layout.ruleY}" stroke="var(--st-component-diagramCard-rule, var(--st-semantic-border-subtle))" stroke-width="${g.ruleHeight}" vector-effect="non-scaling-stroke"/>`);
|
|
86
|
+
}
|
|
87
|
+
if (layout.footerLines.length > 0) {
|
|
88
|
+
parts.push(textLines(layout.footerLines, "st-diagramCard-footer", "var(--st-component-diagramCard-text, var(--st-semantic-text-primary))", ""));
|
|
89
|
+
}
|
|
90
|
+
if (layout.toggleBox !== undefined && props.toggle !== undefined) {
|
|
91
|
+
parts.push(toggleGlyph(props.toggle, layout.toggleBox));
|
|
92
|
+
}
|
|
93
|
+
return { content: parts.join(""), layout };
|
|
94
|
+
}
|
|
95
|
+
/** The +/- toggle glyph in its slot box (card-local coordinates). */
|
|
96
|
+
export function toggleGlyph(toggle, box) {
|
|
97
|
+
const center = box.size / 2;
|
|
98
|
+
const arm = 7;
|
|
99
|
+
const glyph = toggle.collapsed
|
|
100
|
+
? `<path d="M ${center - arm} ${center} H ${center + arm} M ${center} ${center - arm} V ${center + arm}" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>`
|
|
101
|
+
: `<path d="M ${center - arm} ${center} H ${center + arm}" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>`;
|
|
102
|
+
return `<g class="st-diagramCard-toggle" data-toggle="true" data-collapsed="${toggle.collapsed ? "true" : "false"}" transform="translate(${box.x} ${box.y})" color="var(--st-semantic-text-primary)" aria-hidden="true"><title>${escapeXml(toggle.label)}</title><rect width="${box.size}" height="${box.size}" fill="transparent"/>${glyph}</g>`;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Render one atomic card as a standalone SVG string. `measure` defaults to
|
|
106
|
+
* the deterministic greedy wrapper; production hosts pass their measured
|
|
107
|
+
* `LineMeasurer` adapter. Returns all content and any hard-cap diagnostics (owner A11).
|
|
108
|
+
*/
|
|
109
|
+
export function renderCardSvg(props, measure = defaultCardMeasure) {
|
|
110
|
+
const { content, layout } = renderCardContent(props, measure);
|
|
111
|
+
const g = { ...CARD_GEOMETRY, height: layout.box.height };
|
|
112
|
+
const overflowSlots = layout.diagnostics
|
|
113
|
+
.filter((diagnostic) => diagnostic.code === "card-overflow")
|
|
114
|
+
.map((diagnostic) => diagnostic.slot);
|
|
115
|
+
const unknownIcon = layout.diagnostics.some((diagnostic) => diagnostic.code === "card-icon-unknown");
|
|
116
|
+
const firstOverflow = overflowSlots.length === 0 ? undefined : overflowSlots[0];
|
|
117
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" class="st-diagramCard" data-entity="${escapeXml(props.entityId)}"${props.tone === undefined ? "" : ` data-tone="${escapeXml(props.tone)}"`}${props.proposed === true ? ' data-proposed="true"' : ""}${firstOverflow === undefined ? "" : ` data-card-overflow="${firstOverflow}"`}${unknownIcon ? ` data-card-icon-unknown=""` : ""} width="${g.width}" height="${g.height}" viewBox="0 0 ${g.width} ${g.height}" role="img" aria-label="${escapeXml(props.title)}" aria-description="${escapeXml(cardFullText(props))}" style="font-family:${FONT_STACK}">` +
|
|
118
|
+
content +
|
|
119
|
+
`</svg>`;
|
|
120
|
+
return {
|
|
121
|
+
kind: "rendered",
|
|
122
|
+
svg,
|
|
123
|
+
diagnostics: layout.diagnostics,
|
|
124
|
+
layout,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Convenience: project an `EntityPresentation` then render it. Returns
|
|
129
|
+
* `{ kind: "label" }` when the view carries no card presentation for the
|
|
130
|
+
* entity — the host renders a simple label node and no card — and
|
|
131
|
+
* `{ kind: "card", result }` otherwise, where `result` is the refused or
|
|
132
|
+
* rendered `CardSvgResult`.
|
|
133
|
+
*/
|
|
134
|
+
export function renderCardSvgFromPresentation(presentation, opts) {
|
|
135
|
+
const resolved = projectCardProps(presentation, {
|
|
136
|
+
entityId: opts.entityId,
|
|
137
|
+
...(opts.toggle === undefined ? {} : { toggle: opts.toggle }),
|
|
138
|
+
resolveGlyph: getDiagramGlyph,
|
|
139
|
+
});
|
|
140
|
+
if (resolved.kind !== "card")
|
|
141
|
+
return { kind: "label" };
|
|
142
|
+
return { kind: "card", result: renderCardSvg(resolved.props, opts.measure) };
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=renderCardSvg.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Standalone server-side SVG, consuming exactly the scene model used by the framework hosts. */
|
|
2
|
+
import { type SceneLayoutInput } from './diagramSceneModel.js';
|
|
3
|
+
import { type CardLineMeasure } from './diagramCardModel.js';
|
|
4
|
+
export declare function renderSceneSvg(input: SceneLayoutInput, options?: {
|
|
5
|
+
measure?: CardLineMeasure;
|
|
6
|
+
title?: string;
|
|
7
|
+
}): {
|
|
8
|
+
svg: string;
|
|
9
|
+
result: {
|
|
10
|
+
readonly status: "laid-out";
|
|
11
|
+
readonly view: import("@sentropic/diagram-core").ViewDocument;
|
|
12
|
+
readonly fit: import("../index.js").LayoutFit;
|
|
13
|
+
readonly warnings: readonly import("../index.js").LayoutWarning[];
|
|
14
|
+
readonly badgeBoxes?: Readonly<Record<string, import("../transform.js").Rect>>;
|
|
15
|
+
readonly arrowBoxes?: Readonly<Record<string, readonly import("../index.js").FlowArrow[]>>;
|
|
16
|
+
readonly flowBundles?: readonly import("../index.js").FlowBundle[];
|
|
17
|
+
readonly flowTargets?: Readonly<Record<string, import("../index.js").FlowVisibleTarget>>;
|
|
18
|
+
readonly flowRepairPasses?: 0 | 1;
|
|
19
|
+
readonly measurements?: import("../index.js").LayoutMeasurements;
|
|
20
|
+
readonly orientations?: Readonly<Record<string, import("../index.js").LevelOrientation>>;
|
|
21
|
+
readonly channels?: readonly import("../index.js").LayoutChannel[];
|
|
22
|
+
readonly labelBoxes?: Readonly<Record<string, {
|
|
23
|
+
readonly x: number;
|
|
24
|
+
readonly y: number;
|
|
25
|
+
readonly width: number;
|
|
26
|
+
readonly height: number;
|
|
27
|
+
}>>;
|
|
28
|
+
readonly edgeBundles?: Readonly<Record<string, {
|
|
29
|
+
readonly members: readonly string[];
|
|
30
|
+
readonly label: string;
|
|
31
|
+
readonly title: string;
|
|
32
|
+
readonly relations?: readonly string[];
|
|
33
|
+
chip?: ReturnType<typeof import("../index.js").measureBundleLabel>;
|
|
34
|
+
}>>;
|
|
35
|
+
};
|
|
36
|
+
scene: import("./diagramSceneModel.js").SceneModel;
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=renderSceneSvg.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { renderErdCardSvg } from './erd.js';
|
|
2
|
+
/** Standalone server-side SVG, consuming exactly the scene model used by the framework hosts. */
|
|
3
|
+
import { layoutScene, resolveScene, sceneFit } from './diagramSceneModel.js';
|
|
4
|
+
import { cardLineMeasurer, defaultCardMeasure, sceneCardMeasure, projectCardProps, projectZoneProps } from './diagramCardModel.js';
|
|
5
|
+
import { renderCardSvg } from './renderCardSvg.js';
|
|
6
|
+
import { renderZoneSvg } from './renderZoneSvg.js';
|
|
7
|
+
import { getDiagramGlyph } from './registry.js';
|
|
8
|
+
const escape = (text) => text.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"');
|
|
9
|
+
export function renderSceneSvg(input, options = {}) {
|
|
10
|
+
const fallback = sceneCardMeasure(defaultCardMeasure);
|
|
11
|
+
const measureFor = (folded) => options.measure ?? (input.measureLines === undefined ? fallback : (text, role, availableWidth, allocatedLines) => {
|
|
12
|
+
const measured = input.measureLines({ text, role, availableWidth, allocatedLines, folded });
|
|
13
|
+
return { lines: measured.lines, tooWide: measured.width > availableWidth, lineWidths: measured.lines.map(() => measured.width) };
|
|
14
|
+
});
|
|
15
|
+
const measure = measureFor(false);
|
|
16
|
+
const measuredInput = { ...input, measureLines: options.measure === undefined ? input.measureLines ?? cardLineMeasurer(measure) : cardLineMeasurer(measure) };
|
|
17
|
+
const result = layoutScene(measuredInput);
|
|
18
|
+
if (result.status !== 'laid-out')
|
|
19
|
+
throw new Error('Scene refused: ' + JSON.stringify(result.refusals));
|
|
20
|
+
const scene = resolveScene(result, measuredInput), box = scene.bounds ?? { x: 0, y: 0, width: 1, height: 1 };
|
|
21
|
+
const viewportWidth = input.targetWidth ?? 1440;
|
|
22
|
+
const fit = sceneFit({ bounds: box, viewWidth: viewportWidth, windowHeight: 900 });
|
|
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 nodes = scene.nodes.map(node => {
|
|
25
|
+
const measure = measureFor(node.collapsed);
|
|
26
|
+
if (node.kind === 'erd' && node.erd !== undefined)
|
|
27
|
+
return `<g data-scene-occurrence="${escape(node.occurrence)}" transform="translate(${node.rect.x} ${node.rect.y})">${renderErdCardSvg(node.erd)}</g>`;
|
|
28
|
+
const props = { entityId: node.entity, resolveGlyph: input.resolveGlyph ?? getDiagramGlyph };
|
|
29
|
+
const projected = node.kind === 'zone' ? projectZoneProps(node.presentation, { ...props, collapsed: node.collapsed, ...(input.metrics?.containerPadding === undefined ? {} : { containerPadding: input.metrics.containerPadding }), width: node.rect.width, height: node.rect.height, toggleLabel: node.collapsed ? 'Expand' : 'Collapse' }) : projectCardProps(node.presentation, props);
|
|
30
|
+
if (projected.kind === 'label')
|
|
31
|
+
return `<text x="${node.rect.x}" y="${node.rect.y + 24}">${escape(node.text)}</text>`;
|
|
32
|
+
const rendered = projected.kind === 'zone' ? renderZoneSvg({ ...projected.props, autoSize: true }, { measure }) : renderCardSvg({ ...projected.props, autoSize: true, height: node.rect.height }, measure);
|
|
33
|
+
if (rendered.kind !== 'rendered')
|
|
34
|
+
throw new Error('Content must never refuse a component');
|
|
35
|
+
return `<g data-scene-occurrence="${escape(node.occurrence)}" transform="translate(${node.rect.x} ${node.rect.y})">${rendered.svg}</g>`;
|
|
36
|
+
}).join('');
|
|
37
|
+
const labels = scene.labels.map(label => {
|
|
38
|
+
const b = label.box;
|
|
39
|
+
let text = '';
|
|
40
|
+
if (label.bundle) {
|
|
41
|
+
text = `<text x="${b.width / 2}" y="22" text-anchor="middle">${escape(label.bundle.header)}</text>`;
|
|
42
|
+
label.bundle.groups.forEach((group, index) => {
|
|
43
|
+
text += `<g data-bundle-relation="${index}"><path d="M0 ${group.top}H${b.width}" stroke="var(--st-component-diagramScene-labelBorder, #cbd5e1)"/><text x="5" y="${group.top + 22}">•</text>`;
|
|
44
|
+
group.lines.forEach((line, i) => { text += `<text x="22" y="${group.top + 22 + i * 22}">${escape(line)}</text>`; });
|
|
45
|
+
text += '</g>';
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
else
|
|
49
|
+
label.lines.forEach((line, i) => { text += `<text x="${b.width / 2}" y="${18 + i * 22}" text-anchor="middle">${escape(line)}</text>`; });
|
|
50
|
+
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
|
+
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
|
+
}).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></defs>${edges}${nodes}${labels}</svg>`;
|
|
54
|
+
return { svg, result, scene };
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=renderSceneSvg.js.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `renderZoneSvg` — pure wrapping-card (zone) SVG renderer (DC-2 static
|
|
3
|
+
* half, spec §6).
|
|
4
|
+
*
|
|
5
|
+
* Plain TypeScript, no Svelte import. Ships on the
|
|
6
|
+
* `@sentropic/design-system-svelte/diagram-render` subpath next to
|
|
7
|
+
* `renderCardSvg`. Both renderers consume the same geometry source
|
|
8
|
+
* (`./diagramCardModel.js`): collapsed, the zone IS the atomic card
|
|
9
|
+
* (§6.2 — the card content is emitted inside a translated `<g>`); expanded,
|
|
10
|
+
* the frame carries the shared header, the header rule and the children.
|
|
11
|
+
*
|
|
12
|
+
* No hack from the hrpn FOLDED-CARD-HACKS list survives here: no
|
|
13
|
+
* `diagram-card-box` rect, no regex surgery on rendered output, no
|
|
14
|
+
* `foreignObject` toggle, no title pre-fitting (`FOLD_TITLE`), no
|
|
15
|
+
* function/detail re-roling (DH-08), no tint injection — the toggle is the
|
|
16
|
+
* same slot glyph as the card's and the subtitle is one body string.
|
|
17
|
+
*/
|
|
18
|
+
import { CARD_GEOMETRY, projectZoneProps, type CardDiagnostic, type CardLineMeasure, type DiagramZoneProps, type DiagramGlyphPaths, type ZoneChildSpec, type ZoneDiagnostic, type ZoneLayout, type ZonePresentationInput } from "./diagramCardModel.js";
|
|
19
|
+
export type { CardDiagnostic, CardLineMeasure, DiagramGlyphPaths, DiagramZoneProps, ZoneChildSpec, ZoneDiagnostic, ZonePresentationInput, };
|
|
20
|
+
export { projectZoneProps };
|
|
21
|
+
/**
|
|
22
|
+
* Zone-local content (no outer `<svg>`): collapsed, the translated card
|
|
23
|
+
* content; expanded, frame + header + rule + children. Coordinates are
|
|
24
|
+
* zone-local (the caller wraps in `translate(x y)`). The returned
|
|
25
|
+
* `diagnostics` aggregate the zone's own diagnostics with every descendant
|
|
26
|
+
* card/zone diagnostic, each keeping its own `entityId` and original slot
|
|
27
|
+
* text — a nested overflow is never lost inside a zone.
|
|
28
|
+
*/
|
|
29
|
+
export declare function zoneContent(props: DiagramZoneProps, children: readonly ZoneChildSpec[], measure: CardLineMeasure): {
|
|
30
|
+
content: string;
|
|
31
|
+
layout: ZoneLayout;
|
|
32
|
+
diagnostics: readonly ZoneDiagnostic[];
|
|
33
|
+
};
|
|
34
|
+
/** Content is always rendered (owner A11). The legacy refused variant remains for source compatibility. */
|
|
35
|
+
export type ZoneSvgResult = {
|
|
36
|
+
readonly kind: "rendered";
|
|
37
|
+
readonly svg: string;
|
|
38
|
+
readonly diagnostics: readonly ZoneDiagnostic[];
|
|
39
|
+
readonly layout: ZoneLayout;
|
|
40
|
+
} | {
|
|
41
|
+
readonly kind: "refused";
|
|
42
|
+
readonly diagnostics: readonly ZoneDiagnostic[];
|
|
43
|
+
readonly layout: ZoneLayout;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Render one zone as a standalone SVG string. Collapsed: the atomic card
|
|
47
|
+
* at the zone occurrence (460 × 200, plus the "+" toggle slot). Expanded:
|
|
48
|
+
* the frame with header, rule and children. `measure` defaults to the
|
|
49
|
+
* deterministic greedy wrapper. Returns all content and any hard-cap diagnostics (owner A11).
|
|
50
|
+
*/
|
|
51
|
+
export declare function renderZoneSvg(props: DiagramZoneProps, opts?: {
|
|
52
|
+
children?: readonly ZoneChildSpec[];
|
|
53
|
+
measure?: CardLineMeasure;
|
|
54
|
+
}): ZoneSvgResult;
|
|
55
|
+
/**
|
|
56
|
+
* Convenience: project an `EntityPresentation` then render the zone.
|
|
57
|
+
* Returns `{ kind: "label" }` when the view carries no zone presentation
|
|
58
|
+
* for the entity (L-R12), and `{ kind: "zone", result }` otherwise, where
|
|
59
|
+
* `result` is the refused or rendered `ZoneSvgResult`.
|
|
60
|
+
*/
|
|
61
|
+
export declare function renderZoneSvgFromPresentation(presentation: ZonePresentationInput | undefined, opts: {
|
|
62
|
+
entityId: string;
|
|
63
|
+
collapsed: boolean;
|
|
64
|
+
toggleLabel?: string;
|
|
65
|
+
align?: "left" | "center";
|
|
66
|
+
x?: number;
|
|
67
|
+
y?: number;
|
|
68
|
+
width?: number;
|
|
69
|
+
height?: number;
|
|
70
|
+
children?: readonly ZoneChildSpec[];
|
|
71
|
+
measure?: CardLineMeasure;
|
|
72
|
+
}): {
|
|
73
|
+
kind: "zone";
|
|
74
|
+
result: ZoneSvgResult;
|
|
75
|
+
} | {
|
|
76
|
+
kind: "label";
|
|
77
|
+
};
|
|
78
|
+
export { CARD_GEOMETRY };
|
|
79
|
+
//# sourceMappingURL=renderZoneSvg.d.ts.map
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `renderZoneSvg` — pure wrapping-card (zone) SVG renderer (DC-2 static
|
|
3
|
+
* half, spec §6).
|
|
4
|
+
*
|
|
5
|
+
* Plain TypeScript, no Svelte import. Ships on the
|
|
6
|
+
* `@sentropic/design-system-svelte/diagram-render` subpath next to
|
|
7
|
+
* `renderCardSvg`. Both renderers consume the same geometry source
|
|
8
|
+
* (`./diagramCardModel.js`): collapsed, the zone IS the atomic card
|
|
9
|
+
* (§6.2 — the card content is emitted inside a translated `<g>`); expanded,
|
|
10
|
+
* the frame carries the shared header, the header rule and the children.
|
|
11
|
+
*
|
|
12
|
+
* No hack from the hrpn FOLDED-CARD-HACKS list survives here: no
|
|
13
|
+
* `diagram-card-box` rect, no regex surgery on rendered output, no
|
|
14
|
+
* `foreignObject` toggle, no title pre-fitting (`FOLD_TITLE`), no
|
|
15
|
+
* function/detail re-roling (DH-08), no tint injection — the toggle is the
|
|
16
|
+
* same slot glyph as the card's and the subtitle is one body string.
|
|
17
|
+
*/
|
|
18
|
+
import { zoneFullText, CARD_GEOMETRY, ZONE_GEOMETRY, defaultCardMeasure, layoutZone, projectZoneProps, zoneCollapsedCardProps, } from "./diagramCardModel.js";
|
|
19
|
+
import { getDiagramGlyph } from "./registry.js";
|
|
20
|
+
import { iconGroupFor, renderCardContent, toggleGlyph } from "./renderCardSvg.js";
|
|
21
|
+
export { projectZoneProps };
|
|
22
|
+
function escapeXml(value) {
|
|
23
|
+
return String(value)
|
|
24
|
+
.replaceAll("&", "&")
|
|
25
|
+
.replaceAll("<", "<")
|
|
26
|
+
.replaceAll(">", ">")
|
|
27
|
+
.replaceAll('"', """);
|
|
28
|
+
}
|
|
29
|
+
const FONT_STACK = "var(--st-font-sans, system-ui, sans-serif)";
|
|
30
|
+
function textLines(lines, className, fill, extra) {
|
|
31
|
+
return lines
|
|
32
|
+
.map((line) => `<text class="${className}" x="${line.x}" y="${line.baseline}" text-anchor="${line.anchor === "middle" ? "middle" : "start"}" font-size="${line.size}" font-weight="${line.weight}" fill="${fill}"${extra}>${escapeXml(line.text)}</text>`)
|
|
33
|
+
.join("");
|
|
34
|
+
}
|
|
35
|
+
function childContent(child, measure) {
|
|
36
|
+
if (child.kind === "card") {
|
|
37
|
+
if (child.card === undefined)
|
|
38
|
+
throw new Error("fixture-error: card child without card props");
|
|
39
|
+
// The child's own diagnostics are kept with the child's entity id (and
|
|
40
|
+
// its original slot text): an overflowing child is aggregated by the
|
|
41
|
+
// zone, not silently dropped.
|
|
42
|
+
const { content, layout } = renderCardContent(child.card, measure);
|
|
43
|
+
const diagnostics = layout.diagnostics.map((diagnostic) => ({
|
|
44
|
+
code: diagnostic.code,
|
|
45
|
+
slot: diagnostic.slot,
|
|
46
|
+
entityId: diagnostic.entityId,
|
|
47
|
+
neededPx: diagnostic.neededPx,
|
|
48
|
+
allocatedPx: diagnostic.allocatedPx,
|
|
49
|
+
...(diagnostic.text === undefined ? {} : { text: diagnostic.text }),
|
|
50
|
+
...(diagnostic.hiddenLength === undefined ? {} : { hiddenLength: diagnostic.hiddenLength, severity: "info", reason: "truncated" }),
|
|
51
|
+
}));
|
|
52
|
+
return { content, diagnostics };
|
|
53
|
+
}
|
|
54
|
+
if (child.zone === undefined)
|
|
55
|
+
throw new Error("fixture-error: zone child without zone props");
|
|
56
|
+
const rendered = zoneContent(child.zone, child.children ?? [], measure);
|
|
57
|
+
return { content: rendered.content, diagnostics: rendered.diagnostics };
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Zone-local content (no outer `<svg>`): collapsed, the translated card
|
|
61
|
+
* content; expanded, frame + header + rule + children. Coordinates are
|
|
62
|
+
* zone-local (the caller wraps in `translate(x y)`). The returned
|
|
63
|
+
* `diagnostics` aggregate the zone's own diagnostics with every descendant
|
|
64
|
+
* card/zone diagnostic, each keeping its own `entityId` and original slot
|
|
65
|
+
* text — a nested overflow is never lost inside a zone.
|
|
66
|
+
*/
|
|
67
|
+
export function zoneContent(props, children, measure) {
|
|
68
|
+
const g = ZONE_GEOMETRY;
|
|
69
|
+
const layout = layoutZone(props, measure, children);
|
|
70
|
+
const x = layout.box.x;
|
|
71
|
+
const y = layout.box.y;
|
|
72
|
+
const parts = [`<title>${escapeXml(zoneFullText(props))}</title><desc>${escapeXml(zoneFullText(props))}</desc>`];
|
|
73
|
+
const descendantDiagnostics = [];
|
|
74
|
+
if (layout.collapsed) {
|
|
75
|
+
const cardProps = zoneCollapsedCardProps(props);
|
|
76
|
+
const { content } = renderCardContent(cardProps, measure);
|
|
77
|
+
parts.push(content);
|
|
78
|
+
return { content: parts.join(""), layout, diagnostics: layout.diagnostics };
|
|
79
|
+
}
|
|
80
|
+
const header = layout.header;
|
|
81
|
+
if (header === undefined)
|
|
82
|
+
throw new Error("fixture-error: expanded zone without header layout");
|
|
83
|
+
const width = layout.box.width;
|
|
84
|
+
const height = layout.box.height;
|
|
85
|
+
// Frame (expanded only; collapsed is the card border, §6.4).
|
|
86
|
+
// A proposed zone is always drawn dashed, independently of the tint
|
|
87
|
+
// (owner criterion 5); the dash pattern is the kit's `4 5`.
|
|
88
|
+
parts.push(`<rect class="st-diagramZone-frame" x="0" y="0" width="${width}" height="${height}" rx="${g.radius}" fill="var(--st-component-diagramZone-surface, var(--st-semantic-surface-raised))" 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
|
+
if (header.iconBox !== undefined) {
|
|
90
|
+
parts.push(iconGroupFor(layout.icon.name, layout.icon.glyph, header.iconBox.x - x, header.iconBox.y - y, header.iconBox.size));
|
|
91
|
+
}
|
|
92
|
+
if (header.kicker.length > 0) {
|
|
93
|
+
parts.push(textLines(header.kicker.map((line) => ({ ...line, x: line.x - x, baseline: line.baseline - y })), "st-diagramZone-kicker", "var(--st-component-diagramZone-secondaryText, var(--st-semantic-text-secondary))", ` letter-spacing="0.04em" style="text-transform:uppercase"`));
|
|
94
|
+
}
|
|
95
|
+
if (header.title.length > 0) {
|
|
96
|
+
parts.push(textLines(header.title.map((line) => ({ ...line, x: line.x - x, baseline: line.baseline - y })), "st-diagramZone-title", "var(--st-component-diagramZone-text, var(--st-semantic-text-primary))", ""));
|
|
97
|
+
}
|
|
98
|
+
if (header.subtitle.length > 0) {
|
|
99
|
+
parts.push(textLines(header.subtitle.map((line) => ({ ...line, x: line.x - x, baseline: line.baseline - y })), "st-diagramZone-subtitle", "var(--st-component-diagramZone-text, var(--st-semantic-text-primary))", ""));
|
|
100
|
+
}
|
|
101
|
+
// Header rule: same rule as the card footer rule (1 px, border-subtle,
|
|
102
|
+
// same insets), 4 px under the subtitle or the header block (§6.2).
|
|
103
|
+
parts.push(`<line class="st-diagramZone-rule" x1="${g.ruleInsetStart}" x2="${width - g.ruleInsetEnd}" y1="${header.ruleY - y}" y2="${header.ruleY - y}" stroke="var(--st-component-diagramZone-rule, var(--st-semantic-border-subtle))" stroke-width="${g.ruleHeight}" vector-effect="non-scaling-stroke"/>`);
|
|
104
|
+
if (header.toggleBox !== undefined && props.toggleLabel !== undefined) {
|
|
105
|
+
parts.push(toggleGlyph({ collapsed: false, label: props.toggleLabel }, { x: header.toggleBox.x - x, y: header.toggleBox.y - y, size: header.toggleBox.size }));
|
|
106
|
+
}
|
|
107
|
+
// Expanded footer (§6.1: folding never changes the footer) — the same
|
|
108
|
+
// pinned block as the collapsed card, with its own rule above it.
|
|
109
|
+
if (header.footer.length > 0) {
|
|
110
|
+
if (header.footerRuleY !== undefined) {
|
|
111
|
+
parts.push(`<line class="st-diagramZone-footerRule" x1="${g.ruleInsetStart}" x2="${width - g.ruleInsetEnd}" y1="${header.footerRuleY - y}" y2="${header.footerRuleY - y}" stroke="var(--st-component-diagramZone-rule, var(--st-semantic-border-subtle))" stroke-width="${g.ruleHeight}" vector-effect="non-scaling-stroke"/>`);
|
|
112
|
+
}
|
|
113
|
+
parts.push(textLines(header.footer.map((line) => ({ ...line, x: line.x - x, baseline: line.baseline - y })), "st-diagramZone-footer", "var(--st-component-diagramZone-text, var(--st-semantic-text-primary))", ""));
|
|
114
|
+
}
|
|
115
|
+
for (const child of children) {
|
|
116
|
+
const rendered = childContent(child, measure);
|
|
117
|
+
descendantDiagnostics.push(...rendered.diagnostics);
|
|
118
|
+
parts.push(`<g class="st-diagramZone-child" data-child-kind="${child.kind}" transform="translate(${child.x - x} ${child.y - y})">${rendered.content}</g>`);
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
content: parts.join(""),
|
|
122
|
+
layout,
|
|
123
|
+
diagnostics: [...layout.diagnostics, ...descendantDiagnostics],
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Render one zone as a standalone SVG string. Collapsed: the atomic card
|
|
128
|
+
* at the zone occurrence (460 × 200, plus the "+" toggle slot). Expanded:
|
|
129
|
+
* the frame with header, rule and children. `measure` defaults to the
|
|
130
|
+
* deterministic greedy wrapper. Returns all content and any hard-cap diagnostics (owner A11).
|
|
131
|
+
*/
|
|
132
|
+
export function renderZoneSvg(props, opts = {}) {
|
|
133
|
+
const measure = opts.measure ?? defaultCardMeasure;
|
|
134
|
+
const children = opts.children ?? [];
|
|
135
|
+
const { content, layout, diagnostics } = zoneContent(props, children, measure);
|
|
136
|
+
const { x, y, width, height } = layout.box;
|
|
137
|
+
const overflowSlots = diagnostics
|
|
138
|
+
.filter((diagnostic) => diagnostic.code === "zone-overflow")
|
|
139
|
+
.map((diagnostic) => diagnostic.slot);
|
|
140
|
+
const unknownIcon = diagnostics.some((diagnostic) => diagnostic.code === "zone-icon-unknown");
|
|
141
|
+
const firstOverflow = overflowSlots.length === 0 ? undefined : overflowSlots[0];
|
|
142
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" class="st-diagramZoneSvg" width="${x + width}" height="${y + height}" viewBox="0 0 ${x + width} ${y + height}" role="img" aria-label="${escapeXml(props.title)}" aria-description="${escapeXml(zoneFullText(props))}" style="font-family:${FONT_STACK}">` +
|
|
143
|
+
`<g class="st-diagramZone${layout.collapsed ? " st-diagramZone--collapsed" : " st-diagramZone--expanded"}" data-entity="${escapeXml(props.entityId)}" data-collapsed="${layout.collapsed ? "true" : "false"}"${props.tone === undefined ? "" : ` data-tone="${escapeXml(props.tone)}"`}${props.proposed === true ? ' data-proposed="true"' : ""}${firstOverflow === undefined ? "" : ` data-zone-overflow="${firstOverflow}"`}${unknownIcon ? ` data-zone-icon-unknown=""` : ""} transform="translate(${x} ${y})">` +
|
|
144
|
+
content +
|
|
145
|
+
`</g>` +
|
|
146
|
+
`</svg>`;
|
|
147
|
+
return { kind: "rendered", svg, diagnostics, layout };
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Convenience: project an `EntityPresentation` then render the zone.
|
|
151
|
+
* Returns `{ kind: "label" }` when the view carries no zone presentation
|
|
152
|
+
* for the entity (L-R12), and `{ kind: "zone", result }` otherwise, where
|
|
153
|
+
* `result` is the refused or rendered `ZoneSvgResult`.
|
|
154
|
+
*/
|
|
155
|
+
export function renderZoneSvgFromPresentation(presentation, opts) {
|
|
156
|
+
const resolved = projectZoneProps(presentation, {
|
|
157
|
+
entityId: opts.entityId,
|
|
158
|
+
collapsed: opts.collapsed,
|
|
159
|
+
...(opts.toggleLabel === undefined ? {} : { toggleLabel: opts.toggleLabel }),
|
|
160
|
+
...(opts.align === undefined ? {} : { align: opts.align }),
|
|
161
|
+
...(opts.x === undefined ? {} : { x: opts.x }),
|
|
162
|
+
...(opts.y === undefined ? {} : { y: opts.y }),
|
|
163
|
+
...(opts.width === undefined ? {} : { width: opts.width }),
|
|
164
|
+
...(opts.height === undefined ? {} : { height: opts.height }),
|
|
165
|
+
resolveGlyph: getDiagramGlyph,
|
|
166
|
+
});
|
|
167
|
+
if (resolved.kind !== "zone")
|
|
168
|
+
return { kind: "label" };
|
|
169
|
+
return {
|
|
170
|
+
kind: "zone",
|
|
171
|
+
result: renderZoneSvg(resolved.props, {
|
|
172
|
+
...(opts.children === undefined ? {} : { children: opts.children }),
|
|
173
|
+
...(opts.measure === undefined ? {} : { measure: opts.measure }),
|
|
174
|
+
}),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
// Re-exported for the zone parity corpus: the card geometry the collapsed
|
|
178
|
+
// zone reuses (DC-D13 — no second size).
|
|
179
|
+
export { CARD_GEOMETRY };
|
|
180
|
+
//# sourceMappingURL=renderZoneSvg.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Rect, Vec2 } from '../transform.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 declare function clearSceneLabels<T extends {
|
|
5
|
+
readonly box: Rect;
|
|
6
|
+
readonly leader?: readonly Vec2[];
|
|
7
|
+
}>(labels: readonly T[], routes: readonly (readonly Vec2[])[], shapes: readonly Rect[], clearance: number): T[];
|
|
8
|
+
//# sourceMappingURL=sceneLabelClearance.d.ts.map
|