@zombie-mermaid/svg-renderer 2.2.1
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/LICENSE +22 -0
- package/dist/index.cjs +56 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +524 -0
- package/dist/index.d.ts +524 -0
- package/dist/index.js +2994 -0
- package/dist/index.js.map +1 -0
- package/package.json +37 -0
- package/src/__tests__/elk-adapter-utils.test.ts +166 -0
- package/src/class/layout.ts +360 -0
- package/src/class/renderer.ts +636 -0
- package/src/edge-curves.ts +204 -0
- package/src/elk-instance.ts +292 -0
- package/src/er/layout.ts +200 -0
- package/src/er/renderer.ts +493 -0
- package/src/index.ts +58 -0
- package/src/layout-engine/constants.ts +19 -0
- package/src/layout-engine/edge-bundling.ts +379 -0
- package/src/layout-engine/elk-adapter-utils.ts +81 -0
- package/src/layout-engine/elk-graph-builder.ts +240 -0
- package/src/layout-engine/from-elk.ts +685 -0
- package/src/layout-engine/layer-alignment.ts +174 -0
- package/src/layout-engine/to-elk.ts +695 -0
- package/src/layout-engine.ts +74 -0
- package/src/layout.ts +8 -0
- package/src/renderer.ts +1485 -0
- package/src/resolve-colors.ts +339 -0
- package/src/sequence/layout.ts +698 -0
- package/src/sequence/renderer.ts +546 -0
- package/src/shape-clipping.ts +197 -0
- package/src/styles.ts +118 -0
- package/src/xychart/layout.ts +682 -0
- package/src/xychart/renderer.ts +684 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,524 @@
|
|
|
1
|
+
import { ClassDiagram } from '@zombie-mermaid/mermaid-parser';
|
|
2
|
+
import { ClassRenderOptions } from '@zombie-mermaid/core';
|
|
3
|
+
import { CurveStyle } from '@zombie-mermaid/core';
|
|
4
|
+
import { DiagramColors } from '@zombie-mermaid/core';
|
|
5
|
+
import { Direction } from '@zombie-mermaid/core';
|
|
6
|
+
import { ElkExtendedEdge } from 'elkjs';
|
|
7
|
+
import { ElkLabel } from 'elkjs';
|
|
8
|
+
import { ElkNode } from 'elkjs';
|
|
9
|
+
import { ErDiagram } from '@zombie-mermaid/mermaid-parser';
|
|
10
|
+
import { ErRenderOptions } from '@zombie-mermaid/core';
|
|
11
|
+
import { FlowchartRenderOptions } from '@zombie-mermaid/core';
|
|
12
|
+
import { LayoutCache } from '@zombie-mermaid/core';
|
|
13
|
+
import { LayoutOptions } from 'elkjs';
|
|
14
|
+
import { MermaidGraph } from '@zombie-mermaid/core';
|
|
15
|
+
import { Point } from '@zombie-mermaid/core';
|
|
16
|
+
import { PositionedClassDiagram } from '@zombie-mermaid/mermaid-parser';
|
|
17
|
+
import { PositionedErDiagram } from '@zombie-mermaid/mermaid-parser';
|
|
18
|
+
import { PositionedGraph } from '@zombie-mermaid/core';
|
|
19
|
+
import { PositionedNode } from '@zombie-mermaid/core';
|
|
20
|
+
import { PositionedSequenceDiagram } from '@zombie-mermaid/mermaid-parser';
|
|
21
|
+
import { PositionedXYChart } from '@zombie-mermaid/mermaid-parser';
|
|
22
|
+
import { SequenceDiagram } from '@zombie-mermaid/mermaid-parser';
|
|
23
|
+
import { SequenceRenderOptions } from '@zombie-mermaid/core';
|
|
24
|
+
import { SvgEmitOptions } from '@zombie-mermaid/core';
|
|
25
|
+
import { XYChart } from '@zombie-mermaid/mermaid-parser';
|
|
26
|
+
import { XyChartRenderOptions } from '@zombie-mermaid/core';
|
|
27
|
+
|
|
28
|
+
/** Arrow head dimensions — matches spec: 8px wide × ~5px tall */
|
|
29
|
+
export declare const ARROW_HEAD: {
|
|
30
|
+
readonly width: 8;
|
|
31
|
+
readonly height: 5;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The `elk.*` options every one of the three graph builders sets, with the
|
|
36
|
+
* values they all agree on. Callers spread the result and add their own
|
|
37
|
+
* diagram-specific options on top.
|
|
38
|
+
*/
|
|
39
|
+
export declare function baseElkLayoutOptions(spec: {
|
|
40
|
+
direction: ElkDirection;
|
|
41
|
+
nodeSpacing: number;
|
|
42
|
+
layerSpacing: number;
|
|
43
|
+
padding: number | ElkPaddingSides;
|
|
44
|
+
}): LayoutOptions;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Height of the label band at the top of a `box … end` group, in px — the
|
|
48
|
+
* label's font size plus vertical breathing room. Shared with the renderer
|
|
49
|
+
* so the label lands centred in the band the layout reserved for it.
|
|
50
|
+
*/
|
|
51
|
+
export declare function boxLabelHeight(labelFontSize: number): number;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Build a single-source/single-target ELK edge, with a measured label when
|
|
55
|
+
* `label` is non-empty. An absent or empty label leaves `labels` off the
|
|
56
|
+
* edge entirely (rather than setting it to an empty array or `undefined`),
|
|
57
|
+
* matching what all three builders did by hand.
|
|
58
|
+
*/
|
|
59
|
+
export declare function buildElkEdge(spec: {
|
|
60
|
+
id: string;
|
|
61
|
+
source: string;
|
|
62
|
+
target: string;
|
|
63
|
+
label?: string;
|
|
64
|
+
labelStyle: ElkEdgeLabelStyle;
|
|
65
|
+
}): ElkExtendedEdge;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Measure an edge label and build ELK's label box for it.
|
|
69
|
+
*
|
|
70
|
+
* The `+8` / `+6` are the horizontal/vertical breathing room all three
|
|
71
|
+
* builders have always added around the measured text so ELK reserves a
|
|
72
|
+
* slightly larger channel than the glyphs strictly need.
|
|
73
|
+
*/
|
|
74
|
+
export declare function buildElkEdgeLabel(text: string, style: ElkEdgeLabelStyle): ElkLabel;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Build a leaf ELK node.
|
|
78
|
+
*
|
|
79
|
+
* `label` is attached as an ELK label when supplied — the flowchart/state
|
|
80
|
+
* path does that (ELK reads it for nothing, but `from-elk.ts` reads it
|
|
81
|
+
* back); class and ER carry labels in their own side tables instead and
|
|
82
|
+
* omit it. An empty-string label is still a label, so the check is
|
|
83
|
+
* `undefined`, not truthiness.
|
|
84
|
+
*/
|
|
85
|
+
export declare function buildElkLeafNode(id: string, size: {
|
|
86
|
+
width: number;
|
|
87
|
+
height: number;
|
|
88
|
+
}, label?: string): ElkNode;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Layout id for the i-th note. A class id is a run of non-whitespace
|
|
92
|
+
* (`\S+` in the parser), so an id containing a space can never collide
|
|
93
|
+
* with one; ELK treats ids as opaque strings.
|
|
94
|
+
*/
|
|
95
|
+
export declare function classNoteId(index: number): string;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Clip an edge endpoint to the actual shape boundary of a node.
|
|
99
|
+
*
|
|
100
|
+
* @param points - The edge points array
|
|
101
|
+
* @param node - The node to clip to
|
|
102
|
+
* @param isStart - True if clipping the start point (source), false for end (target)
|
|
103
|
+
* @returns New points array with clipped endpoint
|
|
104
|
+
*/
|
|
105
|
+
export declare function clipEdgeToShape(points: Point[], node: PositionedNode, isStart: boolean): Point[];
|
|
106
|
+
|
|
107
|
+
/** Layout constants for class diagrams */
|
|
108
|
+
export declare const CLS: {
|
|
109
|
+
readonly padding: 40;
|
|
110
|
+
readonly boxPadX: 8;
|
|
111
|
+
readonly headerBaseHeight: 32;
|
|
112
|
+
readonly annotationHeight: 16;
|
|
113
|
+
readonly memberRowHeight: 20;
|
|
114
|
+
readonly sectionPadY: 8;
|
|
115
|
+
readonly emptySectionHeight: 8;
|
|
116
|
+
readonly minWidth: 120;
|
|
117
|
+
readonly memberFontSize: 11;
|
|
118
|
+
readonly memberFontWeight: 400;
|
|
119
|
+
readonly nodeSpacing: 40;
|
|
120
|
+
readonly layerSpacing: 60;
|
|
121
|
+
/** Horizontal / vertical padding inside a note box, around its text */
|
|
122
|
+
readonly notePadX: 10;
|
|
123
|
+
readonly notePadY: 6;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Convert MermaidGraph to ELK format (for benchmarking conversion overhead).
|
|
128
|
+
*/
|
|
129
|
+
export declare function convertToElkFormat(graph: MermaidGraph, options?: FlowchartRenderOptions): ElkNode;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Create a new opt-in layout cache with a bounded size (default 20
|
|
133
|
+
* entries). Once full, the least-recently-used entry is evicted to make
|
|
134
|
+
* room for a new one.
|
|
135
|
+
*
|
|
136
|
+
* Pass the result to `elkLayoutSync()` directly, or via
|
|
137
|
+
* `RenderOptions.layoutCache` (threaded through by `layoutGraphSync()`,
|
|
138
|
+
* `layoutClassDiagramSync()`, and `layoutErDiagramSync()`) to memoize
|
|
139
|
+
* layout across repeated renders of the same diagram + options.
|
|
140
|
+
*/
|
|
141
|
+
export declare function createLayoutCache(maxSize?: number): LayoutCache;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Convert a Mermaid `direction` to ELK's `elk.direction` value.
|
|
145
|
+
*
|
|
146
|
+
* `fallback` covers the no-`direction`-statement case only — every member
|
|
147
|
+
* of `Direction` has an explicit mapping. Pass the diagram type's entry
|
|
148
|
+
* from `ELK_DIRECTION_FALLBACK` rather than a bare string literal, so the
|
|
149
|
+
* per-type defaults stay documented in one place.
|
|
150
|
+
*/
|
|
151
|
+
export declare function directionToElk(dir: Direction | undefined, fallback: ElkDirection): ElkDirection;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* The `elk.direction` each diagram type falls back to when its source
|
|
155
|
+
* carries no `direction` statement.
|
|
156
|
+
*
|
|
157
|
+
* These genuinely differ per diagram type, and the difference is
|
|
158
|
+
* intentional rather than an accident of three separate implementations:
|
|
159
|
+
*
|
|
160
|
+
* - **flowchart / state** — `DOWN`. `MermaidGraph.direction` is a required
|
|
161
|
+
* field the parser always fills in (defaulting to `TD`), so the fallback
|
|
162
|
+
* is only a type-level backstop; the effective default is mermaid's own
|
|
163
|
+
* top-down flowchart default.
|
|
164
|
+
* - **class** — `DOWN`. `ClassDiagram` has no direction concept at all (see
|
|
165
|
+
* `ClassRenderOptions` in `packages/core/src/types.ts`: class diagrams
|
|
166
|
+
* "have no `direction` or `curve` concept"), so this is the renderer's
|
|
167
|
+
* single fixed orientation, matching Mermaid's own TB class rendering —
|
|
168
|
+
* which `../class/layout.ts` relies on to put a `note for X` above its
|
|
169
|
+
* class.
|
|
170
|
+
* - **ER** — `RIGHT`. An ER diagram's `direction` is optional
|
|
171
|
+
* (`ErDiagram.direction?`), left `undefined` when the source has no
|
|
172
|
+
* `direction` statement, and this renderer has always laid those out
|
|
173
|
+
* left-to-right. `direction TB`/`LR`/`BT`/`RL` in the source (or
|
|
174
|
+
* `RenderOptions.direction`, applied via `withDirectionOverride`) still
|
|
175
|
+
* wins over it.
|
|
176
|
+
*
|
|
177
|
+
* The *mappings* were never in conflict — both hand-rolled
|
|
178
|
+
* `directionToElk()` implementations agreed on all five `Direction` values
|
|
179
|
+
* (`LR`→`RIGHT`, `RL`→`LEFT`, `BT`→`UP`, `TD`/`TB`→`DOWN`). Only the
|
|
180
|
+
* no-direction fallback differed, which is why it is a parameter here
|
|
181
|
+
* rather than something to reconcile away.
|
|
182
|
+
*/
|
|
183
|
+
export declare const ELK_DIRECTION_FALLBACK: {
|
|
184
|
+
readonly flowchart: "DOWN";
|
|
185
|
+
readonly state: "DOWN";
|
|
186
|
+
readonly class: "DOWN";
|
|
187
|
+
readonly er: "RIGHT";
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
/** The four values ELK's `elk.direction` option accepts in this codebase. */
|
|
191
|
+
export declare type ElkDirection = 'DOWN' | 'UP' | 'LEFT' | 'RIGHT';
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* How a caller wants its edge labels measured and placed. `fontSize` is
|
|
195
|
+
* the resolved `fontSizes.edgeLabel`; `layoutOptions`, when given, is
|
|
196
|
+
* attached to the ELK label itself.
|
|
197
|
+
*/
|
|
198
|
+
export declare interface ElkEdgeLabelStyle {
|
|
199
|
+
fontSize: number;
|
|
200
|
+
layoutOptions?: LayoutOptions;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Run ELK layout synchronously.
|
|
205
|
+
*
|
|
206
|
+
* Bypasses BOTH of ELK's setTimeout(0) wrappers:
|
|
207
|
+
* - FakeWorker.postMessage wraps dispatch in setTimeout(0) — bypassed by
|
|
208
|
+
* calling dispatcher.saveDispatch() directly
|
|
209
|
+
* - PromisedWorker.onmessage wraps receive in setTimeout(0) — bypassed by
|
|
210
|
+
* replacing rawWorker.onmessage with a direct interceptor
|
|
211
|
+
*
|
|
212
|
+
* @param cache - Optional opt-in layout cache (see `createLayoutCache()`).
|
|
213
|
+
* When provided, a cache hit returns the previous result without running
|
|
214
|
+
* ELK layout again. Omitted/undefined preserves the original
|
|
215
|
+
* always-recompute behavior exactly.
|
|
216
|
+
*/
|
|
217
|
+
export declare function elkLayoutSync(graph: ElkNode, cache?: LayoutCache): ElkNode;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Format ELK's `elk.padding` value. A single number applies to all four
|
|
221
|
+
* sides; an object sets them individually.
|
|
222
|
+
*/
|
|
223
|
+
export declare function elkPadding(padding: number | ElkPaddingSides): string;
|
|
224
|
+
|
|
225
|
+
/** Per-side padding, for the asymmetric case (a subgraph's header gap). */
|
|
226
|
+
export declare interface ElkPaddingSides {
|
|
227
|
+
top: number;
|
|
228
|
+
left: number;
|
|
229
|
+
bottom: number;
|
|
230
|
+
right: number;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** Average character width in px for monospace fonts (uniform glyph width) */
|
|
234
|
+
export declare function estimateMonoTextWidth(text: string, fontSize: number): number;
|
|
235
|
+
|
|
236
|
+
/** Average character width in px at the given font size and weight (proportional font) */
|
|
237
|
+
export declare function estimateTextWidth(text: string, fontSize: number, fontWeight: number): number;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Evaluate one CSS value against a flat set of custom-property
|
|
241
|
+
* declarations — the expression engine behind `resolveCssColors`, exposed
|
|
242
|
+
* so it can be unit-tested (and reused) without building an SVG around it.
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* evaluateCssColorValue('color-mix(in srgb, var(--fg) 50%, var(--bg))',
|
|
246
|
+
* { '--fg': '#000000', '--bg': '#ffffff' }) // → '#808080'
|
|
247
|
+
*/
|
|
248
|
+
export declare function evaluateCssColorValue(value: string, declarations: Record<string, string>): string;
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Compute an edge label's center position from ELK's placed label box
|
|
252
|
+
* (`label.x/y` is the box's top-left corner).
|
|
253
|
+
*
|
|
254
|
+
* `offsetX`/`offsetY` translate into an ancestor's coordinate space, same
|
|
255
|
+
* as `extractEdgePoints`.
|
|
256
|
+
*
|
|
257
|
+
* Returns `undefined` if ELK didn't place a label (no label on the edge,
|
|
258
|
+
* or ELK left `x`/`y` unset).
|
|
259
|
+
*/
|
|
260
|
+
export declare function extractEdgeLabelPosition(elkEdge: ElkExtendedEdge, offsetX?: number, offsetY?: number): Point | undefined;
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Walk an ELK edge's first routed section into a flat point path:
|
|
264
|
+
* `startPoint → bendPoints → endPoint`.
|
|
265
|
+
*
|
|
266
|
+
* ELK can theoretically produce multiple sections per edge (for edges
|
|
267
|
+
* split across hierarchy boundaries via ports), but all three call sites
|
|
268
|
+
* only ever read `sections[0]` — hierarchical decomposition in this
|
|
269
|
+
* codebase is handled by emitting separate ELK edges (see
|
|
270
|
+
* `to-elk.ts`/`parseHopEdgeId` in `from-elk.ts`), not multi-section edges.
|
|
271
|
+
*
|
|
272
|
+
* `offsetX`/`offsetY` translate the section's coordinates into an
|
|
273
|
+
* ancestor's coordinate space, for callers walking a nested ELK result
|
|
274
|
+
* (`from-elk.ts`). Callers with a flat (non-hierarchical) ELK graph
|
|
275
|
+
* (`class/layout.ts`, `er/layout.ts`) can omit them.
|
|
276
|
+
*
|
|
277
|
+
* Returns an empty array if the edge has no routed sections.
|
|
278
|
+
*/
|
|
279
|
+
export declare function extractEdgePoints(elkEdge: ElkExtendedEdge, offsetX?: number, offsetY?: number): Point[];
|
|
280
|
+
|
|
281
|
+
/** Default font sizes used in the renderer (in px). Overridable via `RenderOptions.fontSizes`. */
|
|
282
|
+
export declare const FONT_SIZES: {
|
|
283
|
+
/** Node label text */
|
|
284
|
+
readonly nodeLabel: 13;
|
|
285
|
+
/** Edge label text */
|
|
286
|
+
readonly edgeLabel: 11;
|
|
287
|
+
/** Subgraph header text */
|
|
288
|
+
readonly groupHeader: 12;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
/** Font weights used per element type */
|
|
292
|
+
export declare const FONT_WEIGHTS: {
|
|
293
|
+
readonly nodeLabel: 500;
|
|
294
|
+
readonly edgeLabel: 400;
|
|
295
|
+
readonly groupHeader: 600;
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
/** Partial font-size overrides, as accepted by `RenderOptions.fontSizes`. */
|
|
299
|
+
export declare type FontSizeOptions = Partial<FontSizes>;
|
|
300
|
+
|
|
301
|
+
/** Resolved font-size set — same shape as {@link FONT_SIZES} but mutable numbers. */
|
|
302
|
+
export declare type FontSizes = {
|
|
303
|
+
[K in keyof typeof FONT_SIZES]: number;
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
/** Vertical gap between a subgraph header band and the content area below it (px).
|
|
307
|
+
* Without this, nested subgraph headers sit flush against their parent's header band.
|
|
308
|
+
* Increased from 8 to 12 to provide more clearance for edges routing near headers. */
|
|
309
|
+
export declare const GROUP_HEADER_CONTENT_PAD = 12;
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Per-label layout options the flowchart/state path sets on every edge
|
|
313
|
+
* label. Class and ER instead set `elk.edgeLabels.placement` once on the
|
|
314
|
+
* root graph, so they pass no per-label options.
|
|
315
|
+
*/
|
|
316
|
+
export declare const INLINE_CENTERED_EDGE_LABEL: LayoutOptions;
|
|
317
|
+
|
|
318
|
+
export { LayoutCache }
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Lay out a parsed class diagram using ELK.js (synchronous).
|
|
322
|
+
*/
|
|
323
|
+
export declare function layoutClassDiagramSync(diagram: ClassDiagram, options?: ClassRenderOptions): PositionedClassDiagram;
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Lay out a parsed ER diagram using ELK.js (synchronous).
|
|
327
|
+
*/
|
|
328
|
+
export declare function layoutErDiagramSync(diagram: ErDiagram, options?: ErRenderOptions): PositionedErDiagram;
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Lay out a parsed MermaidGraph using ELK.js (synchronous).
|
|
332
|
+
* Returns a fully positioned graph ready for rendering.
|
|
333
|
+
*/
|
|
334
|
+
export declare function layoutGraphSync(graph: MermaidGraph, options?: FlowchartRenderOptions): PositionedGraph;
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Lay out a parsed sequence diagram.
|
|
338
|
+
* Returns a fully positioned diagram ready for SVG rendering.
|
|
339
|
+
*/
|
|
340
|
+
export declare function layoutSequenceDiagram(diagram: SequenceDiagram, options?: SequenceRenderOptions): PositionedSequenceDiagram;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Lay out a parsed XY chart by computing pixel coordinates.
|
|
344
|
+
*/
|
|
345
|
+
export declare function layoutXYChart(chart: XYChart, _options?: XyChartRenderOptions): PositionedXYChart;
|
|
346
|
+
|
|
347
|
+
/** Monospace font family used for code-like text (class members, types) */
|
|
348
|
+
export declare const MONO_FONT: "'JetBrains Mono'";
|
|
349
|
+
|
|
350
|
+
/** Full CSS fallback chain for monospace text */
|
|
351
|
+
export declare const MONO_FONT_STACK: "'JetBrains Mono', 'SF Mono', 'Fira Code', ui-monospace, monospace";
|
|
352
|
+
|
|
353
|
+
/** Padding inside node shapes */
|
|
354
|
+
export declare const NODE_PADDING: {
|
|
355
|
+
/** Horizontal padding inside rectangles/rounded/stadium (increased from 16 for better label fit) */
|
|
356
|
+
readonly horizontal: 20;
|
|
357
|
+
/** Vertical padding inside rectangles/rounded/stadium */
|
|
358
|
+
readonly vertical: 10;
|
|
359
|
+
/** Extra padding for diamond shapes (they need more space due to rotation) */
|
|
360
|
+
readonly diamondExtra: 24;
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Build the `d` attribute for an edge's routed points under `curve`.
|
|
365
|
+
*
|
|
366
|
+
* A path with fewer than two points cannot be drawn; the caller already skips
|
|
367
|
+
* those, but this degrades to an empty string rather than emitting `M`
|
|
368
|
+
* followed by nothing.
|
|
369
|
+
*/
|
|
370
|
+
export declare function pointsToPath(points: Point[], curve?: CurveStyle): string;
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Render a positioned class diagram as an SVG string.
|
|
374
|
+
*
|
|
375
|
+
* @param colors - DiagramColors with bg/fg and optional enrichment variables.
|
|
376
|
+
* @param transparent - If true, renders with transparent background.
|
|
377
|
+
* @param embedSource - Original diagram source to stamp onto the root `<svg>`
|
|
378
|
+
* as `data-src` (from `options.embedSource`). Omitted
|
|
379
|
+
* when the option is off.
|
|
380
|
+
* @param title - Accessible name (from `options.title`). See svgOpenTag() in
|
|
381
|
+
* packages/core/src/theme.ts.
|
|
382
|
+
* @param decorative - Marks the SVG decorative (from `options.decorative`).
|
|
383
|
+
* @param linksEnabled - Whether `click`-based `<a href>` links and `<title>`
|
|
384
|
+
* tooltips render (from `options.interactivity !==
|
|
385
|
+
* 'none'`, see `resolveLinksEnabled` in
|
|
386
|
+
* src/diagram-registry.ts).
|
|
387
|
+
* Default true — matches the flowchart/state renderer.
|
|
388
|
+
* @param emit - Strict-CSP controls (from `options.nonce` /
|
|
389
|
+
* `options.styleAttribute`, see #216). Default: no nonce,
|
|
390
|
+
* root `style` attribute on.
|
|
391
|
+
*/
|
|
392
|
+
export declare function renderClassSvg(diagram: PositionedClassDiagram, colors: DiagramColors, font?: string, transparent?: boolean, fontSizes?: FontSizes, embedSource?: string, title?: string, decorative?: boolean, linksEnabled?: boolean, emit?: SvgEmitOptions): string;
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Render a positioned ER diagram as an SVG string.
|
|
396
|
+
*
|
|
397
|
+
* @param colors - DiagramColors with bg/fg and optional enrichment variables.
|
|
398
|
+
* @param transparent - If true, renders with transparent background.
|
|
399
|
+
* @param embedSource - Original diagram source to stamp onto the root `<svg>`
|
|
400
|
+
* as `data-src` (from `options.embedSource`). Omitted
|
|
401
|
+
* when the option is off.
|
|
402
|
+
* @param title - Accessible name (from `options.title`). See svgOpenTag() in
|
|
403
|
+
* packages/core/src/theme.ts.
|
|
404
|
+
* @param decorative - Marks the SVG decorative (from `options.decorative`).
|
|
405
|
+
* @param emit - Strict-CSP controls (from `options.nonce` /
|
|
406
|
+
* `options.styleAttribute`, see #216). Default: no nonce,
|
|
407
|
+
* root `style` attribute on.
|
|
408
|
+
*/
|
|
409
|
+
export declare function renderErSvg(diagram: PositionedErDiagram, colors: DiagramColors, font?: string, transparent?: boolean, fontSizes?: FontSizes, embedSource?: string, title?: string, decorative?: boolean, emit?: SvgEmitOptions): string;
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Render a positioned sequence diagram as an SVG string.
|
|
413
|
+
*
|
|
414
|
+
* @param colors - DiagramColors with bg/fg and optional enrichment variables.
|
|
415
|
+
* @param transparent - If true, renders with transparent background.
|
|
416
|
+
* @param embedSource - Original diagram source to stamp onto the root `<svg>`
|
|
417
|
+
* as `data-src` (from `options.embedSource`). Omitted
|
|
418
|
+
* when the option is off.
|
|
419
|
+
* @param title - Accessible name (from `options.title`). See svgOpenTag() in
|
|
420
|
+
* packages/core/src/theme.ts.
|
|
421
|
+
* @param decorative - Marks the SVG decorative (from `options.decorative`).
|
|
422
|
+
* @param emit - Strict-CSP controls (from `options.nonce` /
|
|
423
|
+
* `options.styleAttribute`, see #216). Default: no nonce,
|
|
424
|
+
* root `style` attribute on.
|
|
425
|
+
*/
|
|
426
|
+
export declare function renderSequenceSvg(diagram: PositionedSequenceDiagram, colors: DiagramColors, font?: string, transparent?: boolean, fontSizes?: FontSizes, embedSource?: string, title?: string, decorative?: boolean, emit?: SvgEmitOptions): string;
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Render a positioned graph as an SVG string.
|
|
430
|
+
*
|
|
431
|
+
* @param colors - DiagramColors with bg/fg and optional enrichment variables.
|
|
432
|
+
* These are set as CSS custom properties on the <svg> tag.
|
|
433
|
+
* All element colors reference derived --_xxx variables.
|
|
434
|
+
* @param transparent - If true, renders with transparent background.
|
|
435
|
+
* @param embedSource - Original diagram source to stamp onto the root `<svg>`
|
|
436
|
+
* as `data-src` (from `options.embedSource`). Omitted
|
|
437
|
+
* when the option is off.
|
|
438
|
+
* @param animationEnabled - Whether `e1@{ animate: true }` edges actually
|
|
439
|
+
* animate (from `options.interactivity === 'full'`,
|
|
440
|
+
* see `resolveAnimationEnabled` in
|
|
441
|
+
* src/diagram-registry.ts).
|
|
442
|
+
* Default true — preserves the previously-ungated
|
|
443
|
+
* behavior for callers who don't pass it.
|
|
444
|
+
* @param linksEnabled - Whether `click`-based `<a href>` links and `<title>`
|
|
445
|
+
* tooltips render (from
|
|
446
|
+
* `options.interactivity !== 'none'`, see
|
|
447
|
+
* `resolveLinksEnabled` in src/diagram-registry.ts). Default true
|
|
448
|
+
* — preserves the previously-ungated behavior for
|
|
449
|
+
* callers who don't pass it.
|
|
450
|
+
* @param title - Accessible name (from `options.title`). See svgOpenTag() in
|
|
451
|
+
* packages/core/src/theme.ts.
|
|
452
|
+
* @param decorative - Marks the SVG decorative (from `options.decorative`).
|
|
453
|
+
* @param emit - Strict-CSP controls (from `options.nonce` /
|
|
454
|
+
* `options.styleAttribute`, see #216): a `nonce` for every
|
|
455
|
+
* `<style>` element, and whether the root `style="…"`
|
|
456
|
+
* attribute is emitted at all. Default: no nonce, attribute on.
|
|
457
|
+
*/
|
|
458
|
+
export declare function renderSvg(graph: PositionedGraph, colors: DiagramColors, font?: string, transparent?: boolean, fontSizes?: FontSizes, curve?: CurveStyle, embedSource?: string, animationEnabled?: boolean, linksEnabled?: boolean, title?: string, decorative?: boolean, emit?: SvgEmitOptions): string;
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Render a positioned XY chart as an SVG string.
|
|
462
|
+
*
|
|
463
|
+
* @param embedSource - Original diagram source to stamp onto the root
|
|
464
|
+
* `<svg>` as `data-src` (from `options.embedSource`).
|
|
465
|
+
* Omitted when the option is off.
|
|
466
|
+
* @param title - Accessible name (from `options.title`). See svgOpenTag() in
|
|
467
|
+
* packages/core/src/theme.ts.
|
|
468
|
+
* @param decorative - Marks the SVG decorative (from `options.decorative`).
|
|
469
|
+
* @param emit - Strict-CSP controls (from `options.nonce` /
|
|
470
|
+
* `options.styleAttribute`, see #216). Default: no nonce,
|
|
471
|
+
* root `style` attribute on.
|
|
472
|
+
*/
|
|
473
|
+
export declare function renderXYChartSvg(chart: PositionedXYChart, colors: DiagramColors, font?: string, transparent?: boolean, interactive?: boolean, embedSource?: string, title?: string, decorative?: boolean, emit?: SvgEmitOptions): string;
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Replace every `var(--…)` and `color-mix(…)` in an SVG produced by this
|
|
477
|
+
* library's renderer with its computed sRGB value (`#rrggbb`, or
|
|
478
|
+
* `rgba(r, g, b, a)` when translucent).
|
|
479
|
+
*
|
|
480
|
+
* `colors` seeds the variable scope with the caller's palette; the SVG's
|
|
481
|
+
* own declarations (the root `style` attribute and any `<style>` block)
|
|
482
|
+
* are then read on top, so the derived `--_*` variables resolve through
|
|
483
|
+
* exactly the `color-mix()` rules `buildStyleBlock` emitted. See the
|
|
484
|
+
* module comment for what is and isn't rewritten.
|
|
485
|
+
*/
|
|
486
|
+
export declare function resolveCssColors(svg: string, colors: DiagramColors): string;
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Merge user-provided font-size overrides over the {@link FONT_SIZES} defaults.
|
|
490
|
+
* Any field left unspecified (or `undefined`) falls back to its default.
|
|
491
|
+
*/
|
|
492
|
+
export declare function resolveFontSizes(overrides?: FontSizeOptions): FontSizes;
|
|
493
|
+
|
|
494
|
+
/** Stroke widths per element type (in px) */
|
|
495
|
+
export declare const STROKE_WIDTHS: {
|
|
496
|
+
readonly outerBox: 1;
|
|
497
|
+
readonly innerBox: 0.75;
|
|
498
|
+
/** Edge connector stroke (increased from 0.75 for better visibility) */
|
|
499
|
+
readonly connector: 1;
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Vertical shift applied to all text elements for font-agnostic centering.
|
|
504
|
+
*
|
|
505
|
+
* Instead of relying on `dominant-baseline="central"` (which each font interprets
|
|
506
|
+
* differently based on its own ascent/descent metrics), we use the default alphabetic
|
|
507
|
+
* baseline and shift down by 0.35em. This places the optical center of text at the
|
|
508
|
+
* y coordinate, regardless of font family (Inter, JetBrains Mono, system fallbacks).
|
|
509
|
+
*
|
|
510
|
+
* The 0.35em value approximates the distance from alphabetic baseline to visual
|
|
511
|
+
* center of Latin text. Using `em` units ensures it scales with font size.
|
|
512
|
+
*/
|
|
513
|
+
export declare const TEXT_BASELINE_SHIFT: "0.35em";
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Splice a `data-src` attribute (the original diagram source, escaped) onto
|
|
517
|
+
* an already-built root `<svg ...>` opening tag, e.g. from
|
|
518
|
+
* `embedSource: true`. Applied to the string `svgOpenTag()` returns rather
|
|
519
|
+
* than the diagram source's own markup, so it always lands on the root
|
|
520
|
+
* element regardless of diagram type. No-op when `source` is undefined.
|
|
521
|
+
*/
|
|
522
|
+
export declare function withDataSrc(svgTag: string, source: string | undefined): string;
|
|
523
|
+
|
|
524
|
+
export { }
|