UNPKG

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