@silverhand/mermaid-isomorphic
Version:
Transform mermaid diagrams in the browser or Node.js
100 lines • 2.82 kB
TypeScript
import { type MermaidConfig } from 'mermaid';
import { type BrowserType, type LaunchOptions } from 'playwright';
export interface CreateMermaidRendererOptions {
/**
* The Playwright browser to use.
*
* @default chromium
*/
browserType?: BrowserType;
/**
* The options used to launch the browser.
*/
launchOptions?: LaunchOptions;
}
export interface RenderResult {
/**
* The aria description of the diagram.
*/
description?: string;
/**
* The height of the resulting SVG.
*/
height: number;
/**
* The DOM id of the SVG node.
*/
id: string;
/**
* The diagram SVG rendered as a PNG buffer.
*/
screenshot?: Buffer;
/**
* The diagram rendered as an SVG.
*/
svg: string;
/**
* The title of the rendered diagram.
*/
title?: string;
/**
* The width of the resulting SVG.
*/
width: number;
}
export interface RenderOptions {
/**
* A URL that points to a custom CSS file to load.
*
* Use this to load custom fonts.
*
* This option is ignored in the browser. You need to include the CSS in your build manually.
*/
css?: Iterable<URL | string> | URL | string | undefined;
/**
* If true, a PNG screenshot of the diagram will be added.
*
* This is only supported in the Node.js.
*/
screenshot?: boolean;
/**
* The mermaid configuration.
*
* By default `fontFamily` is set to `arial,sans-serif`.
*
* This option is ignored in the browser. You need to call `mermaid.initialize()` manually.
*/
mermaidConfig?: MermaidConfig;
/**
* The prefix of the id.
*
* @default 'mermaid'
*/
prefix?: string | undefined;
}
/**
* Render Mermaid diagrams in the browser.
*
* @param diagrams
* The Mermaid diagrams to render.
* @param options
* Additional options to use when rendering the diagrams.
* @returns
* A list of settled promises that contains the rendered Mermaid diagram. Each result matches the
* same index of the input diagrams.
*/
export type MermaidRenderer = (diagrams: string[], options?: RenderOptions) => Promise<PromiseSettledResult<RenderResult>[]>;
/**
* Create a Mermaid renderer.
*
* The Mermaid renderer manages a browser instance. If multiple diagrams are being rendered
* simultaneously, the internal browser instance will be re-used. If no diagrams are being rendered,
* the browser will be closed.
*
* @param options
* The options of the Mermaid renderer.
* @returns
* A function that renders Mermaid diagrams in the browser.
*/
export declare function createMermaidRenderer(options?: CreateMermaidRendererOptions): MermaidRenderer;
//# sourceMappingURL=mermaid-isomorphic.d.ts.map