UNPKG

5.89 kBTypeScriptView Raw
1import type { MermaidConfig } from './config.type.js';
2import type { ParseOptions, RenderResult } from './mermaidAPI.js';
3import { mermaidAPI } from './mermaidAPI.js';
4import { detectType } from './diagram-api/detectType.js';
5import type { ParseErrorFunction } from './Diagram.js';
6import type { DetailedError } from './utils.js';
7import type { ExternalDiagramDefinition } from './diagram-api/types.js';
8import type { UnknownDiagramError } from './errors.js';
9export type { MermaidConfig, DetailedError, ExternalDiagramDefinition, ParseErrorFunction, RenderResult, ParseOptions, UnknownDiagramError, };
10export interface RunOptions {
11 /**
12 * The query selector to use when finding elements to render. Default: `".mermaid"`.
13 */
14 querySelector?: string;
15 /**
16 * The nodes to render. If this is set, `querySelector` will be ignored.
17 */
18 nodes?: ArrayLike<HTMLElement>;
19 /**
20 * A callback to call after each diagram is rendered.
21 */
22 postRenderCallback?: (id: string) => unknown;
23 /**
24 * If `true`, errors will be logged to the console, but not thrown. Default: `false`
25 */
26 suppressErrors?: boolean;
27}
28/**
29 * ## run
30 *
31 * Function that goes through the document to find the chart definitions in there and render them.
32 *
33 * The function tags the processed attributes with the attribute data-processed and ignores found
34 * elements with the attribute already set. This way the init function can be triggered several
35 * times.
36 *
37 * ```mermaid
38 * graph LR;
39 * a(Find elements)-->b{Processed}
40 * b-->|Yes|c(Leave element)
41 * b-->|No |d(Transform)
42 * ```
43 *
44 * Renders the mermaid diagrams
45 *
46 * @param options - Optional runtime configs
47 */
48declare const run: (options?: RunOptions) => Promise<void>;
49/**
50 * Used to set configurations for mermaid.
51 * This function should be called before the run function.
52 * @param config - Configuration object for mermaid.
53 */
54declare const initialize: (config: MermaidConfig) => void;
55/**
56 * ## init
57 *
58 * @deprecated Use {@link initialize} and {@link run} instead.
59 *
60 * Renders the mermaid diagrams
61 *
62 * @param config - **Deprecated**, please set configuration in {@link initialize}.
63 * @param nodes - **Default**: `.mermaid`. One of the following:
64 * - A DOM Node
65 * - An array of DOM nodes (as would come from a jQuery selector)
66 * - A W3C selector, a la `.mermaid`
67 * @param callback - Called once for each rendered diagram's id.
68 */
69declare const init: (config?: MermaidConfig, nodes?: string | HTMLElement | NodeListOf<HTMLElement>, callback?: ((id: string) => unknown) | undefined) => Promise<void>;
70/**
71 * Used to register external diagram types.
72 * @param diagrams - Array of {@link ExternalDiagramDefinition}.
73 * @param opts - If opts.lazyLoad is false, the diagrams will be loaded immediately.
74 */
75declare const registerExternalDiagrams: (diagrams: ExternalDiagramDefinition[], { lazyLoad, }?: {
76 lazyLoad?: boolean | undefined;
77}) => Promise<void>;
78/**
79 * ##contentLoaded Callback function that is called when page is loaded. This functions fetches
80 * configuration for mermaid rendering and calls init for rendering the mermaid diagrams on the
81 * page.
82 */
83declare const contentLoaded: () => void;
84/**
85 * ## setParseErrorHandler Alternative to directly setting parseError using:
86 *
87 * ```js
88 * mermaid.parseError = function(err,hash){=
89 * forExampleDisplayErrorInGui(err); // do something with the error
90 * };
91 * ```
92 *
93 * This is provided for environments where the mermaid object can't directly have a new member added
94 * to it (eg. dart interop wrapper). (Initially there is no parseError member of mermaid).
95 *
96 * @param parseErrorHandler - New parseError() callback.
97 */
98declare const setParseErrorHandler: (parseErrorHandler: (err: any, hash: any) => void) => void;
99/**
100 * Parse the text and validate the syntax.
101 * @param text - The mermaid diagram definition.
102 * @param parseOptions - Options for parsing.
103 * @returns true if the diagram is valid, false otherwise if parseOptions.suppressErrors is true.
104 * @throws Error if the diagram is invalid and parseOptions.suppressErrors is false.
105 */
106declare const parse: (text: string, parseOptions?: ParseOptions) => Promise<boolean | void>;
107/**
108 * Function that renders an svg with a graph from a chart definition. Usage example below.
109 *
110 * ```javascript
111 * element = document.querySelector('#graphDiv');
112 * const graphDefinition = 'graph TB\na-->b';
113 * const { svg, bindFunctions } = await mermaid.render('graphDiv', graphDefinition);
114 * element.innerHTML = svg;
115 * bindFunctions?.(element);
116 * ```
117 *
118 * @remarks
119 * Multiple calls to this function will be enqueued to run serially.
120 *
121 * @param id - The id for the SVG element (the element to be rendered)
122 * @param text - The text for the graph definition
123 * @param container - HTML element where the svg will be inserted. (Is usually element with the .mermaid class)
124 * If no svgContainingElement is provided then the SVG element will be appended to the body.
125 * Selector to element in which a div with the graph temporarily will be
126 * inserted. If one is provided a hidden div will be inserted in the body of the page instead. The
127 * element will be removed when rendering is completed.
128 * @returns Returns the SVG Definition and BindFunctions.
129 */
130declare const render: (id: string, text: string, container?: Element) => Promise<RenderResult>;
131export interface Mermaid {
132 startOnLoad: boolean;
133 parseError?: ParseErrorFunction;
134 mermaidAPI: typeof mermaidAPI;
135 parse: typeof parse;
136 render: typeof render;
137 init: typeof init;
138 run: typeof run;
139 registerExternalDiagrams: typeof registerExternalDiagrams;
140 initialize: typeof initialize;
141 contentLoaded: typeof contentLoaded;
142 setParseErrorHandler: typeof setParseErrorHandler;
143 detectType: typeof detectType;
144}
145declare const mermaid: Mermaid;
146export default mermaid;