@zombie-mermaid/svg-renderer 5.0.1 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts DELETED
@@ -1,732 +0,0 @@
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 { ElkConstructor } from '@zombie-mermaid/core';
7
- import { ElkExtendedEdge } from '@zombie-mermaid/core';
8
- import { ElkLabel } from '@zombie-mermaid/core';
9
- import { ElkNode } from '@zombie-mermaid/core';
10
- import { ErDiagram } from '@zombie-mermaid/mermaid-parser';
11
- import { ErRenderOptions } from '@zombie-mermaid/core';
12
- import { FlowchartRenderOptions } from '@zombie-mermaid/core';
13
- import { LayoutCache } from '@zombie-mermaid/core';
14
- import { LayoutOptions } from '@zombie-mermaid/core';
15
- import { MermaidGraph } from '@zombie-mermaid/core';
16
- import { PieChart } from '@zombie-mermaid/mermaid-parser';
17
- import { Point } from '@zombie-mermaid/core';
18
- import { PositionedClassDiagram } from '@zombie-mermaid/mermaid-parser';
19
- import { PositionedErDiagram } from '@zombie-mermaid/mermaid-parser';
20
- import { PositionedGraph } from '@zombie-mermaid/core';
21
- import { PositionedNode } from '@zombie-mermaid/core';
22
- import { PositionedPieChart } from '@zombie-mermaid/mermaid-parser';
23
- import { PositionedSequenceDiagram } from '@zombie-mermaid/mermaid-parser';
24
- import { PositionedXYChart } from '@zombie-mermaid/mermaid-parser';
25
- import { RenderOptions } from '@zombie-mermaid/core';
26
- import { SequenceDiagram } from '@zombie-mermaid/mermaid-parser';
27
- import { SequenceRenderOptions } from '@zombie-mermaid/core';
28
- import { SvgEmitOptions } from '@zombie-mermaid/core';
29
- import { XYChart } from '@zombie-mermaid/mermaid-parser';
30
- import { XyChartRenderOptions } from '@zombie-mermaid/core';
31
-
32
- /**
33
- * Distance from the bottom of a stick-figure (`actor`) icon to the vertical
34
- * centre of its label. Shared with the renderer so the label lands where the
35
- * layout reserved room for it.
36
- */
37
- export declare const ACTOR_LABEL_OFFSET = 14;
38
-
39
- /** Arrow head dimensions — matches spec: 8px wide × ~5px tall */
40
- export declare const ARROW_HEAD: {
41
- readonly width: 8;
42
- readonly height: 5;
43
- };
44
-
45
- /**
46
- * The `elk.*` options every one of the three graph builders sets, with the
47
- * values they all agree on. Callers spread the result and add their own
48
- * diagram-specific options on top.
49
- */
50
- export declare function baseElkLayoutOptions(spec: {
51
- direction: ElkDirection;
52
- nodeSpacing: number;
53
- layerSpacing: number;
54
- padding: number | ElkPaddingSides;
55
- }): LayoutOptions;
56
-
57
- /**
58
- * Height of the label band at the top of a `box … end` group, in px — the
59
- * label's font size plus vertical breathing room. Shared with the renderer
60
- * so the label lands centred in the band the layout reserved for it.
61
- */
62
- export declare function boxLabelHeight(labelFontSize: number): number;
63
-
64
- /**
65
- * Build a single-source/single-target ELK edge, with a measured label when
66
- * `label` is non-empty. An absent or empty label leaves `labels` off the
67
- * edge entirely (rather than setting it to an empty array or `undefined`),
68
- * matching what all three builders did by hand.
69
- */
70
- export declare function buildElkEdge(spec: {
71
- id: string;
72
- source: string;
73
- target: string;
74
- label?: string;
75
- labelStyle: ElkEdgeLabelStyle;
76
- }): ElkExtendedEdge;
77
-
78
- /**
79
- * Measure an edge label and build ELK's label box for it.
80
- *
81
- * The `+8` / `+6` are the horizontal/vertical breathing room all three
82
- * builders have always added around the measured text so ELK reserves a
83
- * slightly larger channel than the glyphs strictly need.
84
- */
85
- export declare function buildElkEdgeLabel(text: string, style: ElkEdgeLabelStyle): ElkLabel;
86
-
87
- /**
88
- * Build a leaf ELK node.
89
- *
90
- * `label` is attached as an ELK label when supplied — the flowchart/state
91
- * path does that (ELK reads it for nothing, but `from-elk.ts` reads it
92
- * back); class and ER carry labels in their own side tables instead and
93
- * omit it. An empty-string label is still a label, so the check is
94
- * `undefined`, not truthiness.
95
- */
96
- export declare function buildElkLeafNode(id: string, size: {
97
- width: number;
98
- height: number;
99
- }, label?: string): ElkNode;
100
-
101
- /**
102
- * SVG `<style>` block for a diagram: core's `buildStyleBlock` plus, when
103
- * `hasMonoFont` is set, the self-hosted mono font subset for the `.mono`
104
- * rule. The subset lives here rather than in `core` because only SVG output
105
- * embeds it (#1319).
106
- */
107
- export declare function buildSvgStyleBlock(font: string, hasMonoFont: boolean, nonce?: string): string;
108
-
109
- /**
110
- * Layout id for the i-th note. A class id is a run of non-whitespace
111
- * (`\S+` in the parser), so an id containing a space can never collide
112
- * with one; ELK treats ids as opaque strings.
113
- */
114
- export declare function classNoteId(index: number): string;
115
-
116
- /**
117
- * Clip an edge endpoint to the actual shape boundary of a node.
118
- *
119
- * @param points - The edge points array
120
- * @param node - The node to clip to
121
- * @param isStart - True if clipping the start point (source), false for end (target)
122
- * @returns New points array with clipped endpoint
123
- */
124
- export declare function clipEdgeToShape(points: Point[], node: PositionedNode, isStart: boolean): Point[];
125
-
126
- /** Layout constants for class diagrams */
127
- export declare const CLS: {
128
- readonly padding: 40;
129
- readonly boxPadX: 8;
130
- readonly headerBaseHeight: 32;
131
- readonly annotationHeight: 16;
132
- readonly memberRowHeight: 20;
133
- readonly sectionPadY: 8;
134
- readonly emptySectionHeight: 8;
135
- readonly minWidth: 120;
136
- readonly memberFontSize: 11;
137
- readonly memberFontWeight: 400;
138
- readonly nodeSpacing: 40;
139
- readonly layerSpacing: 60;
140
- /** Horizontal / vertical padding inside a note box, around its text */
141
- readonly notePadX: 10;
142
- readonly notePadY: 6;
143
- /** Space reserved above a namespace's classes for its title */
144
- readonly namespaceTitleHeight: 28;
145
- /** Padding between a namespace frame and its classes (other three sides) */
146
- readonly namespacePad: 16;
147
- readonly namespaceTitleFontSize: 12;
148
- };
149
-
150
- /**
151
- * Convert MermaidGraph to ELK format (for benchmarking conversion overhead).
152
- */
153
- export declare function convertToElkFormat(graph: MermaidGraph, options?: FlowchartRenderOptions): ElkNode;
154
-
155
- /**
156
- * Create a new opt-in layout cache with a bounded size (default 20
157
- * entries). Once full, the least-recently-used entry is evicted to make
158
- * room for a new one.
159
- *
160
- * Pass the result to `elkLayoutSync()` directly, or via
161
- * `RenderOptions.layoutCache` (threaded through by `layoutGraphSync()`,
162
- * `layoutClassDiagramSync()`, and `layoutErDiagramSync()`) to memoize
163
- * layout across repeated renders of the same diagram + options.
164
- */
165
- export declare function createLayoutCache(maxSize?: number): LayoutCache;
166
-
167
- /**
168
- * Convert a Mermaid `direction` to ELK's `elk.direction` value.
169
- *
170
- * `fallback` covers the no-`direction`-statement case only — every member
171
- * of `Direction` has an explicit mapping. Pass the diagram type's entry
172
- * from `ELK_DIRECTION_FALLBACK` rather than a bare string literal, so the
173
- * per-type defaults stay documented in one place.
174
- */
175
- export declare function directionToElk(dir: Direction | undefined, fallback: ElkDirection): ElkDirection;
176
-
177
- /**
178
- * The `elk.direction` each diagram type falls back to when its source
179
- * carries no `direction` statement.
180
- *
181
- * These genuinely differ per diagram type, and the difference is
182
- * intentional rather than an accident of three separate implementations:
183
- *
184
- * - **flowchart / state** — `DOWN`. `MermaidGraph.direction` is a required
185
- * field the parser always fills in (defaulting to `TD`), so the fallback
186
- * is only a type-level backstop; the effective default is mermaid's own
187
- * top-down flowchart default.
188
- * - **class** — `DOWN`. `ClassDiagram` has no direction concept at all (see
189
- * `ClassRenderOptions` in `packages/core/src/types.ts`: class diagrams
190
- * "have no `direction` or `curve` concept"), so this is the renderer's
191
- * single fixed orientation, matching Mermaid's own TB class rendering —
192
- * which `../class/layout.ts` relies on to put a `note for X` above its
193
- * class.
194
- * - **C4** — `DOWN`. `C4Diagram.direction` is never set by the parser (C4
195
- * sources have no direction statement), only by `RenderOptions.direction`,
196
- * so an unset one is the top-down layout every C4 diagram is drawn in.
197
- * - **ER** — `DOWN`. An ER diagram's `direction` is optional
198
- * (`ErDiagram.direction?`), left `undefined` when the source has no
199
- * `direction` statement, and official Mermaid lays those out top-to-bottom
200
- * (#1250; this renderer used to lay them out left-to-right).
201
- * `direction TB`/`LR`/`BT`/`RL` in the source (or
202
- * `RenderOptions.direction`, applied via `withDirectionOverride`) still
203
- * wins over it.
204
- *
205
- * The *mappings* were never in conflict — both hand-rolled
206
- * `directionToElk()` implementations agreed on all five `Direction` values
207
- * (`LR`→`RIGHT`, `RL`→`LEFT`, `BT`→`UP`, `TD`/`TB`→`DOWN`). Only the
208
- * no-direction fallback differed, which is why it is a parameter here
209
- * rather than something to reconcile away.
210
- */
211
- export declare const ELK_DIRECTION_FALLBACK: {
212
- readonly flowchart: "DOWN";
213
- readonly state: "DOWN";
214
- readonly class: "DOWN";
215
- readonly er: "DOWN";
216
- readonly c4: "DOWN";
217
- };
218
-
219
- /** The four values ELK's `elk.direction` option accepts in this codebase. */
220
- export declare type ElkDirection = 'DOWN' | 'UP' | 'LEFT' | 'RIGHT';
221
-
222
- /**
223
- * How a caller wants its edge labels measured and placed. `fontSize` is
224
- * the resolved `fontSizes.edgeLabel`; `layoutOptions`, when given, is
225
- * attached to the ELK label itself.
226
- */
227
- export declare interface ElkEdgeLabelStyle {
228
- fontSize: number;
229
- layoutOptions?: LayoutOptions;
230
- }
231
-
232
- /**
233
- * Run ELK layout synchronously.
234
- *
235
- * Bypasses BOTH of ELK's setTimeout(0) wrappers:
236
- * - FakeWorker.postMessage wraps dispatch in setTimeout(0) — bypassed by
237
- * calling dispatcher.saveDispatch() directly
238
- * - PromisedWorker.onmessage wraps receive in setTimeout(0) — bypassed by
239
- * replacing rawWorker.onmessage with a direct interceptor
240
- *
241
- * @param cache - Optional opt-in layout cache (see `createLayoutCache()`).
242
- * When provided, a cache hit returns the previous result without running
243
- * ELK layout again. Omitted/undefined preserves the original
244
- * always-recompute behavior exactly.
245
- */
246
- export declare function elkLayoutSync(graph: ElkNode, cache?: LayoutCache): ElkNode;
247
-
248
- /** Thrown when a graph diagram renders and no `elkjs` constructor is available. */
249
- export declare class ElkNotRegisteredError extends Error {
250
- constructor();
251
- }
252
-
253
- /**
254
- * Format ELK's `elk.padding` value. A single number applies to all four
255
- * sides; an object sets them individually.
256
- */
257
- export declare function elkPadding(padding: number | ElkPaddingSides): string;
258
-
259
- /** Per-side padding, for the asymmetric case (a subgraph's header gap). */
260
- export declare interface ElkPaddingSides {
261
- top: number;
262
- left: number;
263
- bottom: number;
264
- right: number;
265
- }
266
-
267
- /** Average character width in px for monospace fonts (uniform glyph width) */
268
- export declare function estimateMonoTextWidth(text: string, fontSize: number): number;
269
-
270
- /** Average character width in px at the given font size and weight (proportional font) */
271
- export declare function estimateTextWidth(text: string, fontSize: number, fontWeight: number): number;
272
-
273
- /**
274
- * Evaluate one CSS value against a flat set of custom-property
275
- * declarations — the expression engine behind `resolveCssColors`, exposed
276
- * so it can be unit-tested (and reused) without building an SVG around it.
277
- *
278
- * @example
279
- * evaluateCssColorValue('color-mix(in srgb, var(--fg) 50%, var(--bg))',
280
- * { '--fg': '#000000', '--bg': '#ffffff' }) // → '#808080'
281
- */
282
- export declare function evaluateCssColorValue(value: string, declarations: Record<string, string>): string;
283
-
284
- /**
285
- * Compute an edge label's center position from ELK's placed label box
286
- * (`label.x/y` is the box's top-left corner).
287
- *
288
- * `offsetX`/`offsetY` translate into an ancestor's coordinate space, same
289
- * as `extractEdgePoints`.
290
- *
291
- * Returns `undefined` if ELK didn't place a label (no label on the edge,
292
- * or ELK left `x`/`y` unset).
293
- */
294
- export declare function extractEdgeLabelPosition(elkEdge: ElkExtendedEdge, offsetX?: number, offsetY?: number): Point | undefined;
295
-
296
- /**
297
- * Walk an ELK edge's first routed section into a flat point path:
298
- * `startPoint → bendPoints → endPoint`.
299
- *
300
- * ELK can theoretically produce multiple sections per edge (for edges
301
- * split across hierarchy boundaries via ports), but all three call sites
302
- * only ever read `sections[0]` — hierarchical decomposition in this
303
- * codebase is handled by emitting separate ELK edges (see
304
- * `to-elk.ts`/`parseHopEdgeId` in `from-elk.ts`), not multi-section edges.
305
- *
306
- * `offsetX`/`offsetY` translate the section's coordinates into an
307
- * ancestor's coordinate space, for callers walking a nested ELK result
308
- * (`from-elk.ts`). Callers with a flat (non-hierarchical) ELK graph
309
- * (`class/layout.ts`, `er/layout.ts`) can omit them.
310
- *
311
- * Returns an empty array if the edge has no routed sections.
312
- */
313
- export declare function extractEdgePoints(elkEdge: ElkExtendedEdge, offsetX?: number, offsetY?: number): Point[];
314
-
315
- /** Default font sizes used in the renderer (in px). Overridable via `RenderOptions.fontSizes`. */
316
- export declare const FONT_SIZES: {
317
- /** Node label text */
318
- readonly nodeLabel: 13;
319
- /** Edge label text */
320
- readonly edgeLabel: 11;
321
- /** Subgraph header text */
322
- readonly groupHeader: 12;
323
- };
324
-
325
- /** Font weights used per element type */
326
- export declare const FONT_WEIGHTS: {
327
- readonly nodeLabel: 500;
328
- readonly edgeLabel: 400;
329
- readonly groupHeader: 600;
330
- };
331
-
332
- /** Partial font-size overrides, as accepted by `RenderOptions.fontSizes`. */
333
- export declare type FontSizeOptions = Partial<FontSizes>;
334
-
335
- /** Resolved font-size set — same shape as {@link FONT_SIZES} but mutable numbers. */
336
- export declare type FontSizes = {
337
- [K in keyof typeof FONT_SIZES]: number;
338
- };
339
-
340
- /**
341
- * Format a set of evenly-spaced tick values with enough decimal places to
342
- * keep every label distinct. Precision comes from the tick step, not the
343
- * magnitude of the value: a 0.5 step around 100 needs one decimal, or
344
- * 99.5 and 100.5 both collapse into neighbouring whole numbers.
345
- */
346
- export declare function formatTickLabels(ticks: number[]): string[];
347
-
348
- /** Vertical gap between a subgraph header band and the content area below it (px).
349
- * Without this, nested subgraph headers sit flush against their parent's header band.
350
- * Increased from 8 to 12 to provide more clearance for edges routing near headers. */
351
- export declare const GROUP_HEADER_CONTENT_PAD = 12;
352
-
353
- /**
354
- * Per-label layout options the flowchart/state path sets on every edge
355
- * label. Class and ER instead set `elk.edgeLabels.placement` once on the
356
- * root graph, so they pass no per-label options.
357
- */
358
- export declare const INLINE_CENTERED_EDGE_LABEL: LayoutOptions;
359
-
360
- export { LayoutCache }
361
-
362
- /**
363
- * Lay out a parsed class diagram using ELK.js (synchronous).
364
- */
365
- export declare function layoutClassDiagramSync(diagram: ClassDiagram, options?: ClassRenderOptions): PositionedClassDiagram;
366
-
367
- /**
368
- * Lay out a parsed ER diagram using ELK.js (synchronous).
369
- */
370
- export declare function layoutErDiagramSync(diagram: ErDiagram, options?: ErRenderOptions): PositionedErDiagram;
371
-
372
- /**
373
- * Lay out a flowchart, with its subgraphs arranged the way mermaid.js arranges
374
- * them (see `layout-engine/compound-flat.ts`). Anything that layout doesn't
375
- * handle, or can't make fit, is laid out by `layoutGraphSync`, so this is a
376
- * drop-in for it wherever the graph is a flowchart. Other diagram types that
377
- * share the engine (state, architecture) keep using `layoutGraphSync`.
378
- */
379
- export declare function layoutFlowchartSync(rawGraph: MermaidGraph, options?: FlowchartRenderOptions): PositionedGraph;
380
-
381
- /**
382
- * Lay out a parsed MermaidGraph using ELK.js (synchronous).
383
- * Returns a fully positioned graph ready for rendering.
384
- */
385
- export declare function layoutGraphSync(graph: MermaidGraph, options?: FlowchartRenderOptions): PositionedGraph;
386
-
387
- /** Lay out a parsed pie chart. Options are accepted for registry parity; none apply. */
388
- export declare function layoutPieChart(chart: PieChart, _options?: unknown): PositionedPieChart;
389
-
390
- /**
391
- * Lay out a parsed sequence diagram.
392
- * Returns a fully positioned diagram ready for SVG rendering.
393
- */
394
- export declare function layoutSequenceDiagram(diagram: SequenceDiagram, options?: SequenceRenderOptions): PositionedSequenceDiagram;
395
-
396
- /**
397
- * Lay out a parsed XY chart by computing pixel coordinates.
398
- */
399
- export declare function layoutXYChart(chart: XYChart, _options?: XyChartRenderOptions): PositionedXYChart;
400
-
401
- /** Monospace font family used for code-like text (class members, types) */
402
- export declare const MONO_FONT: "'JetBrains Mono'";
403
-
404
- /** Full CSS fallback chain for monospace text */
405
- export declare const MONO_FONT_STACK: "'JetBrains Mono', 'SF Mono', 'Fira Code', ui-monospace, monospace";
406
-
407
- /** Generate "nice" tick values for a numeric range */
408
- export declare function niceTickValues(min: number, max: number): number[];
409
-
410
- /** Padding inside node shapes */
411
- export declare const NODE_PADDING: {
412
- /** Horizontal padding inside rectangles/rounded/stadium (increased from 16 for better label fit) */
413
- readonly horizontal: 20;
414
- /** Vertical padding inside rectangles/rounded/stadium */
415
- readonly vertical: 10;
416
- /** Extra padding for diamond shapes (they need more space due to rotation) */
417
- readonly diamondExtra: 24;
418
- };
419
-
420
- /** Mermaid pieRenderer.ts constants (default config and default theme). */
421
- export declare const PIE: {
422
- /** Frame height; the pie's own width equals it. */
423
- readonly height: 450;
424
- readonly margin: 40;
425
- readonly legendRectSize: 18;
426
- readonly legendSpacing: 4;
427
- /** `pie.textPosition` default: label distance as a fraction of the radius. */
428
- readonly textPosition: 0.75;
429
- /** `pieOuterStrokeWidth`; the outline circle sits half of it outside the pie. */
430
- readonly outerStrokeWidth: 2;
431
- /** `pieTitleTextSize` */
432
- readonly titleFontSize: 25;
433
- /** `pieSectionTextSize` */
434
- readonly sectionFontSize: 17;
435
- /** `pieLegendTextSize` */
436
- readonly legendFontSize: 17;
437
- readonly fontWeight: 400;
438
- /** Mermaid's `pie1`..`pie12` scale wraps after this many colours. */
439
- readonly paletteSize: 12;
440
- /** Slices below this percentage of the total are not drawn. */
441
- readonly minPercent: 1;
442
- };
443
-
444
- /** CSS value for palette slot `index`: slot 0 follows `--accent` live. */
445
- export declare function pieColorValue(index: number, accent: string | undefined, bg: string): string;
446
-
447
- /**
448
- * Build the `d` attribute for an edge's routed points under `curve`.
449
- *
450
- * A path with fewer than two points cannot be drawn; the caller already skips
451
- * those, but this degrades to an empty string rather than emitting `M`
452
- * followed by nothing.
453
- */
454
- export declare function pointsToPath(points: Point[], curve?: CurveStyle): string;
455
-
456
- /**
457
- * Register the `elkjs` constructor used for flowchart, state, class, ER and
458
- * architecture layout. Call once before rendering, in browsers and bundlers:
459
- *
460
- * import ELK from 'elkjs/lib/elk.bundled.js'
461
- * registerElk(ELK)
462
- *
463
- * Under Node (and Bun) this is optional when `elkjs` is installed: it is
464
- * auto-loaded on first use. Calling it again swaps the constructor and drops
465
- * the cached instance.
466
- */
467
- export declare function registerElk(ctor: ElkConstructor): void;
468
-
469
- /**
470
- * Render a positioned class diagram as an SVG string.
471
- *
472
- * @param colors - DiagramColors with bg/fg and optional enrichment variables.
473
- * @param transparent - If true, renders with transparent background.
474
- * @param embedSource - Original diagram source to stamp onto the root `<svg>`
475
- * as `data-src` (from `options.embedSource`). Omitted
476
- * when the option is off.
477
- * @param title - Accessible name (from `options.title`). See svgOpenTag() in
478
- * packages/core/src/theme.ts.
479
- * @param decorative - Marks the SVG decorative (from `options.decorative`).
480
- * @param linksEnabled - Whether `click`-based `<a href>` links and `<title>`
481
- * tooltips render (from `options.interactivity !==
482
- * 'none'`, see `resolveLinksEnabled` in
483
- * src/diagram-registry.ts).
484
- * Default true — matches the flowchart/state renderer.
485
- * @param emit - Strict-CSP controls (from `options.nonce` /
486
- * `options.styleAttribute`, see #216). Default: no nonce,
487
- * root `style` attribute on.
488
- */
489
- 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;
490
-
491
- /**
492
- * Render a positioned ER diagram as an SVG string.
493
- *
494
- * @param colors - DiagramColors with bg/fg and optional enrichment variables.
495
- * @param transparent - If true, renders with transparent background.
496
- * @param embedSource - Original diagram source to stamp onto the root `<svg>`
497
- * as `data-src` (from `options.embedSource`). Omitted
498
- * when the option is off.
499
- * @param title - Accessible name (from `options.title`). See svgOpenTag() in
500
- * packages/core/src/theme.ts.
501
- * @param decorative - Marks the SVG decorative (from `options.decorative`).
502
- * @param emit - Strict-CSP controls (from `options.nonce` /
503
- * `options.styleAttribute`, see #216). Default: no nonce,
504
- * root `style` attribute on.
505
- */
506
- export declare function renderErSvg(diagram: PositionedErDiagram, colors: DiagramColors, font?: string, transparent?: boolean, fontSizes?: FontSizes, embedSource?: string, title?: string, decorative?: boolean, emit?: SvgEmitOptions): string;
507
-
508
- /** @deprecated Use `renderMermaidSVGAsync` */
509
- export declare const renderMermaid: typeof renderMermaidSVGAsync;
510
-
511
- /**
512
- * Render Mermaid diagram text to an SVG string — synchronously.
513
- *
514
- * Uses elk.bundled.js with a direct FakeWorker bypass (no setTimeout(0) delay).
515
- * The ELK singleton is created lazily on first use and cached forever.
516
- *
517
- * Use this in React components with useMemo() to avoid flash:
518
- * const svg = useMemo(() => renderMermaidSVG(code, opts), [code])
519
- *
520
- * @param text - Mermaid source text
521
- * @param options - Rendering options (colors, font, spacing)
522
- * @returns A self-contained SVG string
523
- *
524
- * @example
525
- * ```ts
526
- * const svg = renderMermaidSVG('graph TD\n A --> B')
527
- *
528
- * // With theme
529
- * const svg = renderMermaidSVG('graph TD\n A --> B', {
530
- * bg: '#1a1b26', fg: '#a9b1d6'
531
- * })
532
- *
533
- * // With CSS variables (for live theme switching)
534
- * const svg = renderMermaidSVG('graph TD\n A --> B', {
535
- * bg: 'var(--background)', fg: 'var(--foreground)', transparent: true
536
- * })
537
- *
538
- * // With the original source stamped onto the root <svg> as data-src —
539
- * // handy for a "copy source" button or an "open in Mermaid Live" link
540
- * // without re-attaching it via string surgery on the output.
541
- * const svg = renderMermaidSVG('graph TD\n A --> B', { embedSource: true })
542
- *
543
- * // With an accessible name — role="img" + aria-labelledby pointing at a
544
- * // <title> child, so assistive tech announces the diagram instead of
545
- * // reading every node label individually (see issue #215).
546
- * const svg = renderMermaidSVG('graph TD\n A --> B', {
547
- * title: 'Flowchart: Build → Test → Ship'
548
- * })
549
- *
550
- * // Decorative diagram — already described in surrounding prose, so it's
551
- * // hidden from assistive tech (aria-hidden="true") instead of named.
552
- * const svg = renderMermaidSVG('graph TD\n A --> B', { decorative: true })
553
- * ```
554
- */
555
- export declare function renderMermaidSVG(text: string, options?: RenderOptions): string;
556
-
557
- /**
558
- * Render Mermaid diagram text to an SVG string — async.
559
- *
560
- * Same result as renderMermaidSVG() but returns a Promise.
561
- * Useful in async contexts (server handlers, data loaders, etc.)
562
- */
563
- export declare function renderMermaidSVGAsync(text: string, options?: RenderOptions): Promise<string>;
564
-
565
- /** @deprecated Use `renderMermaidSVG` */
566
- export declare const renderMermaidSync: typeof renderMermaidSVG;
567
-
568
- /**
569
- * Render a positioned pie chart as an SVG string.
570
- *
571
- * The accessible name is `title` (from `options.title`) when given,
572
- * otherwise the chart's own `accTitle`; `accDescr` becomes the root
573
- * `<desc>`. Both are dropped when `decorative` is set — see svgOpenTag() in
574
- * packages/core/src/theme.ts.
575
- */
576
- export declare function renderPieSvg(chart: PositionedPieChart, colors: DiagramColors, font?: string, transparent?: boolean, embedSource?: string, title?: string, decorative?: boolean, emit?: SvgEmitOptions): string;
577
-
578
- /**
579
- * Render a positioned sequence diagram as an SVG string.
580
- *
581
- * @param colors - DiagramColors with bg/fg and optional enrichment variables.
582
- * @param transparent - If true, renders with transparent background.
583
- * @param embedSource - Original diagram source to stamp onto the root `<svg>`
584
- * as `data-src` (from `options.embedSource`). Omitted
585
- * when the option is off.
586
- * @param title - Accessible name (from `options.title`). See svgOpenTag() in
587
- * packages/core/src/theme.ts.
588
- * @param decorative - Marks the SVG decorative (from `options.decorative`).
589
- * @param emit - Strict-CSP controls (from `options.nonce` /
590
- * `options.styleAttribute`, see #216). Default: no nonce,
591
- * root `style` attribute on.
592
- */
593
- export declare function renderSequenceSvg(diagram: PositionedSequenceDiagram, colors: DiagramColors, font?: string, transparent?: boolean, fontSizes?: FontSizes, embedSource?: string, title?: string, decorative?: boolean, emit?: SvgEmitOptions): string;
594
-
595
- /**
596
- * Render a positioned graph as an SVG string.
597
- *
598
- * @param colors - DiagramColors with bg/fg and optional enrichment variables.
599
- * These are set as CSS custom properties on the <svg> tag.
600
- * All element colors reference derived --_xxx variables.
601
- * @param transparent - If true, renders with transparent background.
602
- * @param embedSource - Original diagram source to stamp onto the root `<svg>`
603
- * as `data-src` (from `options.embedSource`). Omitted
604
- * when the option is off.
605
- * @param animationEnabled - Whether `e1@{ animate: true }` edges actually
606
- * animate (from `options.interactivity === 'full'`,
607
- * see `resolveAnimationEnabled` in
608
- * src/diagram-registry.ts).
609
- * Default true — preserves the previously-ungated
610
- * behavior for callers who don't pass it.
611
- * @param linksEnabled - Whether `click`-based `<a href>` links and `<title>`
612
- * tooltips render (from
613
- * `options.interactivity !== 'none'`, see
614
- * `resolveLinksEnabled` in src/diagram-registry.ts). Default true
615
- * — preserves the previously-ungated behavior for
616
- * callers who don't pass it.
617
- * @param title - Accessible name (from `options.title`). See svgOpenTag() in
618
- * packages/core/src/theme.ts.
619
- * @param decorative - Marks the SVG decorative (from `options.decorative`).
620
- * @param emit - Strict-CSP controls (from `options.nonce` /
621
- * `options.styleAttribute`, see #216): a `nonce` for every
622
- * `<style>` element, and whether the root `style="…"`
623
- * attribute is emitted at all. Default: no nonce, attribute on.
624
- */
625
- 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;
626
-
627
- /**
628
- * Render a positioned XY chart as an SVG string.
629
- *
630
- * @param embedSource - Original diagram source to stamp onto the root
631
- * `<svg>` as `data-src` (from `options.embedSource`).
632
- * Omitted when the option is off.
633
- * @param title - Accessible name (from `options.title`). See svgOpenTag() in
634
- * packages/core/src/theme.ts.
635
- * @param decorative - Marks the SVG decorative (from `options.decorative`).
636
- * @param emit - Strict-CSP controls (from `options.nonce` /
637
- * `options.styleAttribute`, see #216). Default: no nonce,
638
- * root `style` attribute on.
639
- */
640
- export declare function renderXYChartSvg(chart: PositionedXYChart, colors: DiagramColors, font?: string, transparent?: boolean, interactive?: boolean, embedSource?: string, title?: string, decorative?: boolean, emit?: SvgEmitOptions): string;
641
-
642
- /**
643
- * Replace every `var(--…)` and `color-mix(…)` in an SVG produced by this
644
- * library's renderer with its computed sRGB value (`#rrggbb`, or
645
- * `rgba(r, g, b, a)` when translucent).
646
- *
647
- * `colors` seeds the variable scope with the caller's palette; the SVG's
648
- * own declarations (the root `style` attribute and any `<style>` block)
649
- * are then read on top, so the derived `--_*` variables resolve through
650
- * exactly the `color-mix()` rules `buildStyleBlock` emitted. See the
651
- * module comment for what is and isn't rewritten.
652
- */
653
- export declare function resolveCssColors(svg: string, colors: DiagramColors): string;
654
-
655
- /**
656
- * Merge user-provided font-size overrides over the {@link FONT_SIZES} defaults.
657
- * Any field left unspecified (or `undefined`) falls back to its default.
658
- */
659
- export declare function resolveFontSizes(overrides?: FontSizeOptions): FontSizes;
660
-
661
- export declare function smoothCurvePath(points: Array<{
662
- x: number;
663
- y: number;
664
- }>): string;
665
-
666
- /** Stroke widths per element type (in px) */
667
- export declare const STROKE_WIDTHS: {
668
- readonly outerBox: 1;
669
- readonly innerBox: 0.75;
670
- /** Edge connector stroke (increased from 0.75 for better visibility) */
671
- readonly connector: 1;
672
- };
673
-
674
- /**
675
- * Vertical shift applied to all text elements for font-agnostic centering.
676
- *
677
- * Instead of relying on `dominant-baseline="central"` (which each font interprets
678
- * differently based on its own ascent/descent metrics), we use the default alphabetic
679
- * baseline and shift down by 0.35em. This places the optical center of text at the
680
- * y coordinate, regardless of font family (Inter, JetBrains Mono, system fallbacks).
681
- *
682
- * The 0.35em value approximates the distance from alphabetic baseline to visual
683
- * center of Latin text. Using `em` units ensures it scales with font size.
684
- */
685
- export declare const TEXT_BASELINE_SHIFT: "0.35em";
686
-
687
- /**
688
- * The exact CSS declaration list the root `<svg style="…">` attribute would
689
- * carry for these options — `--bg`, `--fg`, whichever enrichment colours
690
- * were given, and (unless `transparent`) `background: var(--bg)`.
691
- *
692
- * For hosts with a strict `Content-Security-Policy`: a `style=` attribute
693
- * can't be nonced, so a `style-src` without `'unsafe-inline'` drops it and
694
- * the diagram loses its colours. Render with `styleAttribute: false` and
695
- * put this string in your own stylesheet on the SVG (or any ancestor —
696
- * custom properties inherit) instead. Pass the same options object to both
697
- * calls so the declarations match what the render expects. See
698
- * `RenderOptions.styleAttribute` / `RenderOptions.nonce` and issue #216.
699
- *
700
- * Built by the same function that fills the attribute in normal renders,
701
- * so there is one variable list to keep in sync. The string is compact
702
- * (`--bg:#fff;--fg:#000;background:var(--bg)`) — valid inside any rule
703
- * block — and the colour values are yours, unescaped, exactly as the
704
- * attribute has always carried them.
705
- *
706
- * @example
707
- * ```ts
708
- * const opts = { bg: '#1a1b26', fg: '#a9b1d6', nonce, styleAttribute: false }
709
- * const svg = renderMermaidSVG('graph TD\n A --> B', opts)
710
- * const css = `.diagram svg { ${themeCssVariables(opts)} }`
711
- * ```
712
- */
713
- export declare function themeCssVariables(options?: RenderOptions): string;
714
-
715
- /**
716
- * Splice a `data-src` attribute (the original diagram source, escaped) onto
717
- * an already-built root `<svg ...>` opening tag, e.g. from
718
- * `embedSource: true`. Applied to the string `svgOpenTag()` returns rather
719
- * than the diagram source's own markup, so it always lands on the root
720
- * element regardless of diagram type. No-op when `source` is undefined.
721
- */
722
- export declare function withDataSrc(svgTag: string, source: string | undefined): string;
723
-
724
- /**
725
- * Step between shown x-axis labels: 1 when every pair of neighbouring labels
726
- * keeps `X_LABEL_MIN_GAP` of clear space, otherwise the smallest n for which
727
- * every pair of shown (every n-th) labels does. Checked pairwise on the real
728
- * widths so one long label doesn't thin out an otherwise roomy axis.
729
- */
730
- export declare function xLabelStep(labels: string[], bandWidth: number): number;
731
-
732
- export { }