@zombie-mermaid/svg-renderer 2.2.1 → 3.0.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.cts CHANGED
@@ -19,6 +19,7 @@ import { PositionedGraph } from '@zombie-mermaid/core';
19
19
  import { PositionedNode } from '@zombie-mermaid/core';
20
20
  import { PositionedSequenceDiagram } from '@zombie-mermaid/mermaid-parser';
21
21
  import { PositionedXYChart } from '@zombie-mermaid/mermaid-parser';
22
+ import { RenderOptions } from '@zombie-mermaid/core';
22
23
  import { SequenceDiagram } from '@zombie-mermaid/mermaid-parser';
23
24
  import { SequenceRenderOptions } from '@zombie-mermaid/core';
24
25
  import { SvgEmitOptions } from '@zombie-mermaid/core';
@@ -408,6 +409,66 @@ export declare function renderClassSvg(diagram: PositionedClassDiagram, colors:
408
409
  */
409
410
  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
+ /** @deprecated Use `renderMermaidSVGAsync` */
413
+ export declare const renderMermaid: typeof renderMermaidSVGAsync;
414
+
415
+ /**
416
+ * Render Mermaid diagram text to an SVG string — synchronously.
417
+ *
418
+ * Uses elk.bundled.js with a direct FakeWorker bypass (no setTimeout(0) delay).
419
+ * The ELK singleton is created lazily on first use and cached forever.
420
+ *
421
+ * Use this in React components with useMemo() to avoid flash:
422
+ * const svg = useMemo(() => renderMermaidSVG(code, opts), [code])
423
+ *
424
+ * @param text - Mermaid source text
425
+ * @param options - Rendering options (colors, font, spacing)
426
+ * @returns A self-contained SVG string
427
+ *
428
+ * @example
429
+ * ```ts
430
+ * const svg = renderMermaidSVG('graph TD\n A --> B')
431
+ *
432
+ * // With theme
433
+ * const svg = renderMermaidSVG('graph TD\n A --> B', {
434
+ * bg: '#1a1b26', fg: '#a9b1d6'
435
+ * })
436
+ *
437
+ * // With CSS variables (for live theme switching)
438
+ * const svg = renderMermaidSVG('graph TD\n A --> B', {
439
+ * bg: 'var(--background)', fg: 'var(--foreground)', transparent: true
440
+ * })
441
+ *
442
+ * // With the original source stamped onto the root <svg> as data-src —
443
+ * // handy for a "copy source" button or an "open in Mermaid Live" link
444
+ * // without re-attaching it via string surgery on the output.
445
+ * const svg = renderMermaidSVG('graph TD\n A --> B', { embedSource: true })
446
+ *
447
+ * // With an accessible name — role="img" + aria-labelledby pointing at a
448
+ * // <title> child, so assistive tech announces the diagram instead of
449
+ * // reading every node label individually (see issue #215).
450
+ * const svg = renderMermaidSVG('graph TD\n A --> B', {
451
+ * title: 'Flowchart: Build → Test → Ship'
452
+ * })
453
+ *
454
+ * // Decorative diagram — already described in surrounding prose, so it's
455
+ * // hidden from assistive tech (aria-hidden="true") instead of named.
456
+ * const svg = renderMermaidSVG('graph TD\n A --> B', { decorative: true })
457
+ * ```
458
+ */
459
+ export declare function renderMermaidSVG(text: string, options?: RenderOptions): string;
460
+
461
+ /**
462
+ * Render Mermaid diagram text to an SVG string — async.
463
+ *
464
+ * Same result as renderMermaidSVG() but returns a Promise.
465
+ * Useful in async contexts (server handlers, data loaders, etc.)
466
+ */
467
+ export declare function renderMermaidSVGAsync(text: string, options?: RenderOptions): Promise<string>;
468
+
469
+ /** @deprecated Use `renderMermaidSVG` */
470
+ export declare const renderMermaidSync: typeof renderMermaidSVG;
471
+
411
472
  /**
412
473
  * Render a positioned sequence diagram as an SVG string.
413
474
  *
@@ -512,6 +573,34 @@ export declare const STROKE_WIDTHS: {
512
573
  */
513
574
  export declare const TEXT_BASELINE_SHIFT: "0.35em";
514
575
 
576
+ /**
577
+ * The exact CSS declaration list the root `<svg style="…">` attribute would
578
+ * carry for these options — `--bg`, `--fg`, whichever enrichment colours
579
+ * were given, and (unless `transparent`) `background: var(--bg)`.
580
+ *
581
+ * For hosts with a strict `Content-Security-Policy`: a `style=` attribute
582
+ * can't be nonced, so a `style-src` without `'unsafe-inline'` drops it and
583
+ * the diagram loses its colours. Render with `styleAttribute: false` and
584
+ * put this string in your own stylesheet on the SVG (or any ancestor —
585
+ * custom properties inherit) instead. Pass the same options object to both
586
+ * calls so the declarations match what the render expects. See
587
+ * `RenderOptions.styleAttribute` / `RenderOptions.nonce` and issue #216.
588
+ *
589
+ * Built by the same function that fills the attribute in normal renders,
590
+ * so there is one variable list to keep in sync. The string is compact
591
+ * (`--bg:#fff;--fg:#000;background:var(--bg)`) — valid inside any rule
592
+ * block — and the colour values are yours, unescaped, exactly as the
593
+ * attribute has always carried them.
594
+ *
595
+ * @example
596
+ * ```ts
597
+ * const opts = { bg: '#1a1b26', fg: '#a9b1d6', nonce, styleAttribute: false }
598
+ * const svg = renderMermaidSVG('graph TD\n A --> B', opts)
599
+ * const css = `.diagram svg { ${themeCssVariables(opts)} }`
600
+ * ```
601
+ */
602
+ export declare function themeCssVariables(options?: RenderOptions): string;
603
+
515
604
  /**
516
605
  * Splice a `data-src` attribute (the original diagram source, escaped) onto
517
606
  * an already-built root `<svg ...>` opening tag, e.g. from
package/dist/index.d.ts CHANGED
@@ -19,6 +19,7 @@ import { PositionedGraph } from '@zombie-mermaid/core';
19
19
  import { PositionedNode } from '@zombie-mermaid/core';
20
20
  import { PositionedSequenceDiagram } from '@zombie-mermaid/mermaid-parser';
21
21
  import { PositionedXYChart } from '@zombie-mermaid/mermaid-parser';
22
+ import { RenderOptions } from '@zombie-mermaid/core';
22
23
  import { SequenceDiagram } from '@zombie-mermaid/mermaid-parser';
23
24
  import { SequenceRenderOptions } from '@zombie-mermaid/core';
24
25
  import { SvgEmitOptions } from '@zombie-mermaid/core';
@@ -408,6 +409,66 @@ export declare function renderClassSvg(diagram: PositionedClassDiagram, colors:
408
409
  */
409
410
  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
+ /** @deprecated Use `renderMermaidSVGAsync` */
413
+ export declare const renderMermaid: typeof renderMermaidSVGAsync;
414
+
415
+ /**
416
+ * Render Mermaid diagram text to an SVG string — synchronously.
417
+ *
418
+ * Uses elk.bundled.js with a direct FakeWorker bypass (no setTimeout(0) delay).
419
+ * The ELK singleton is created lazily on first use and cached forever.
420
+ *
421
+ * Use this in React components with useMemo() to avoid flash:
422
+ * const svg = useMemo(() => renderMermaidSVG(code, opts), [code])
423
+ *
424
+ * @param text - Mermaid source text
425
+ * @param options - Rendering options (colors, font, spacing)
426
+ * @returns A self-contained SVG string
427
+ *
428
+ * @example
429
+ * ```ts
430
+ * const svg = renderMermaidSVG('graph TD\n A --> B')
431
+ *
432
+ * // With theme
433
+ * const svg = renderMermaidSVG('graph TD\n A --> B', {
434
+ * bg: '#1a1b26', fg: '#a9b1d6'
435
+ * })
436
+ *
437
+ * // With CSS variables (for live theme switching)
438
+ * const svg = renderMermaidSVG('graph TD\n A --> B', {
439
+ * bg: 'var(--background)', fg: 'var(--foreground)', transparent: true
440
+ * })
441
+ *
442
+ * // With the original source stamped onto the root <svg> as data-src —
443
+ * // handy for a "copy source" button or an "open in Mermaid Live" link
444
+ * // without re-attaching it via string surgery on the output.
445
+ * const svg = renderMermaidSVG('graph TD\n A --> B', { embedSource: true })
446
+ *
447
+ * // With an accessible name — role="img" + aria-labelledby pointing at a
448
+ * // <title> child, so assistive tech announces the diagram instead of
449
+ * // reading every node label individually (see issue #215).
450
+ * const svg = renderMermaidSVG('graph TD\n A --> B', {
451
+ * title: 'Flowchart: Build → Test → Ship'
452
+ * })
453
+ *
454
+ * // Decorative diagram — already described in surrounding prose, so it's
455
+ * // hidden from assistive tech (aria-hidden="true") instead of named.
456
+ * const svg = renderMermaidSVG('graph TD\n A --> B', { decorative: true })
457
+ * ```
458
+ */
459
+ export declare function renderMermaidSVG(text: string, options?: RenderOptions): string;
460
+
461
+ /**
462
+ * Render Mermaid diagram text to an SVG string — async.
463
+ *
464
+ * Same result as renderMermaidSVG() but returns a Promise.
465
+ * Useful in async contexts (server handlers, data loaders, etc.)
466
+ */
467
+ export declare function renderMermaidSVGAsync(text: string, options?: RenderOptions): Promise<string>;
468
+
469
+ /** @deprecated Use `renderMermaidSVG` */
470
+ export declare const renderMermaidSync: typeof renderMermaidSVG;
471
+
411
472
  /**
412
473
  * Render a positioned sequence diagram as an SVG string.
413
474
  *
@@ -512,6 +573,34 @@ export declare const STROKE_WIDTHS: {
512
573
  */
513
574
  export declare const TEXT_BASELINE_SHIFT: "0.35em";
514
575
 
576
+ /**
577
+ * The exact CSS declaration list the root `<svg style="…">` attribute would
578
+ * carry for these options — `--bg`, `--fg`, whichever enrichment colours
579
+ * were given, and (unless `transparent`) `background: var(--bg)`.
580
+ *
581
+ * For hosts with a strict `Content-Security-Policy`: a `style=` attribute
582
+ * can't be nonced, so a `style-src` without `'unsafe-inline'` drops it and
583
+ * the diagram loses its colours. Render with `styleAttribute: false` and
584
+ * put this string in your own stylesheet on the SVG (or any ancestor —
585
+ * custom properties inherit) instead. Pass the same options object to both
586
+ * calls so the declarations match what the render expects. See
587
+ * `RenderOptions.styleAttribute` / `RenderOptions.nonce` and issue #216.
588
+ *
589
+ * Built by the same function that fills the attribute in normal renders,
590
+ * so there is one variable list to keep in sync. The string is compact
591
+ * (`--bg:#fff;--fg:#000;background:var(--bg)`) — valid inside any rule
592
+ * block — and the colour values are yours, unescaped, exactly as the
593
+ * attribute has always carried them.
594
+ *
595
+ * @example
596
+ * ```ts
597
+ * const opts = { bg: '#1a1b26', fg: '#a9b1d6', nonce, styleAttribute: false }
598
+ * const svg = renderMermaidSVG('graph TD\n A --> B', opts)
599
+ * const css = `.diagram svg { ${themeCssVariables(opts)} }`
600
+ * ```
601
+ */
602
+ export declare function themeCssVariables(options?: RenderOptions): string;
603
+
515
604
  /**
516
605
  * Splice a `data-src` attribute (the original diagram source, escaped) onto
517
606
  * an already-built root `<svg ...>` opening tag, e.g. from