UNPKG

6.58 kBTypeScriptView Raw
1import { Diagram } from './Diagram.js';
2import type { MermaidConfig } from './config.type.js';
3import type { DiagramMetadata, DiagramStyleClassDef } from './diagram-api/types.js';
4export interface ParseOptions {
5 suppressErrors?: boolean;
6}
7export type D3Element = any;
8export interface RenderResult {
9 /**
10 * The svg code for the rendered graph.
11 */
12 svg: string;
13 /**
14 * Bind function to be called after the svg has been inserted into the DOM.
15 * This is necessary for adding event listeners to the elements in the svg.
16 * ```js
17 * const { svg, bindFunctions } = mermaidAPI.render('id1', 'graph TD;A-->B');
18 * div.innerHTML = svg;
19 * bindFunctions?.(div); // To call bindFunctions only if it's present.
20 * ```
21 */
22 bindFunctions?: (element: Element) => void;
23}
24/**
25 * Parse the text and validate the syntax.
26 * @param text - The mermaid diagram definition.
27 * @param parseOptions - Options for parsing.
28 * @returns true if the diagram is valid, false otherwise if parseOptions.suppressErrors is true.
29 * @throws Error if the diagram is invalid and parseOptions.suppressErrors is false.
30 */
31declare function parse(text: string, parseOptions?: ParseOptions): Promise<boolean>;
32/**
33 * Create a CSS style that starts with the given class name, then the element,
34 * with an enclosing block that has each of the cssClasses followed by !important;
35 * @param cssClass - CSS class name
36 * @param element - CSS element
37 * @param cssClasses - list of CSS styles to append after the element
38 * @returns - the constructed string
39 */
40export declare const cssImportantStyles: (cssClass: string, element: string, cssClasses?: string[]) => string;
41/**
42 * Create the user styles
43 * @internal
44 * @param config - configuration that has style and theme settings to use
45 * @param classDefs - the classDefs in the diagram text. Might be null if none were defined. Usually is the result of a call to getClasses(...)
46 * @returns the string with all the user styles
47 */
48export declare const createCssStyles: (config: MermaidConfig, classDefs?: Record<string, DiagramStyleClassDef> | null | undefined) => string;
49export declare const createUserStyles: (config: MermaidConfig, graphType: string, classDefs: Record<string, DiagramStyleClassDef> | undefined, svgId: string) => string;
50/**
51 * Clean up svgCode. Do replacements needed
52 *
53 * @param svgCode - the code to clean up
54 * @param inSandboxMode - security level
55 * @param useArrowMarkerUrls - should arrow marker's use full urls? (vs. just the anchors)
56 * @returns the cleaned up svgCode
57 */
58export declare const cleanUpSvgCode: (svgCode: string | undefined, inSandboxMode: boolean, useArrowMarkerUrls: boolean) => string;
59/**
60 * Put the svgCode into an iFrame. Return the iFrame code
61 *
62 * @param svgCode - the svg code to put inside the iFrame
63 * @param svgElement - the d3 node that has the current svgElement so we can get the height from it
64 * @returns - the code with the iFrame that now contains the svgCode
65 * TODO replace btoa(). Replace with buf.toString('base64')?
66 */
67export declare const putIntoIFrame: (svgCode?: string, svgElement?: D3Element) => string;
68/**
69 * Append an enclosing div, then svg, then g (group) to the d3 parentRoot. Set attributes.
70 * Only set the style attribute on the enclosing div if divStyle is given.
71 * Only set the xmlns:xlink attribute on svg if svgXlink is given.
72 * Return the last node appended
73 *
74 * @param parentRoot - the d3 node to append things to
75 * @param id - the value to set the id attr to
76 * @param enclosingDivId - the id to set the enclosing div to
77 * @param divStyle - if given, the style to set the enclosing div to
78 * @param svgXlink - if given, the link to set the new svg element to
79 * @returns - returns the parentRoot that had nodes appended
80 */
81export declare const appendDivSvgG: (parentRoot: D3Element, id: string, enclosingDivId: string, divStyle?: string, svgXlink?: string) => D3Element;
82/**
83 * Remove any existing elements from the given document
84 *
85 * @param doc - the document to removed elements from
86 * @param id - id for any existing SVG element
87 * @param divSelector - selector for any existing enclosing div element
88 * @param iFrameSelector - selector for any existing iFrame element
89 */
90export declare const removeExistingElements: (doc: Document, id: string, divId: string, iFrameId: string) => void;
91/**
92 * @param options - Initial Mermaid options
93 */
94declare function initialize(options?: MermaidConfig): void;
95/**
96 * ## mermaidAPI configuration defaults
97 *
98 * ```ts
99 * const config = {
100 * theme: 'default',
101 * logLevel: 'fatal',
102 * securityLevel: 'strict',
103 * startOnLoad: true,
104 * arrowMarkerAbsolute: false,
105 *
106 * er: {
107 * diagramPadding: 20,
108 * layoutDirection: 'TB',
109 * minEntityWidth: 100,
110 * minEntityHeight: 75,
111 * entityPadding: 15,
112 * stroke: 'gray',
113 * fill: 'honeydew',
114 * fontSize: 12,
115 * useMaxWidth: true,
116 * },
117 * flowchart: {
118 * diagramPadding: 8,
119 * htmlLabels: true,
120 * curve: 'basis',
121 * },
122 * sequence: {
123 * diagramMarginX: 50,
124 * diagramMarginY: 10,
125 * actorMargin: 50,
126 * width: 150,
127 * height: 65,
128 * boxMargin: 10,
129 * boxTextMargin: 5,
130 * noteMargin: 10,
131 * messageMargin: 35,
132 * messageAlign: 'center',
133 * mirrorActors: true,
134 * bottomMarginAdj: 1,
135 * useMaxWidth: true,
136 * rightAngles: false,
137 * showSequenceNumbers: false,
138 * },
139 * gantt: {
140 * titleTopMargin: 25,
141 * barHeight: 20,
142 * barGap: 4,
143 * topPadding: 50,
144 * leftPadding: 75,
145 * gridLineStartPadding: 35,
146 * fontSize: 11,
147 * fontFamily: '"Open Sans", sans-serif',
148 * numberSectionStyles: 4,
149 * axisFormat: '%Y-%m-%d',
150 * topAxis: false,
151 * displayMode: '',
152 * },
153 * };
154 * mermaid.initialize(config);
155 * ```
156 */
157export declare const mermaidAPI: Readonly<{
158 render: (id: string, text: string, svgContainingElement?: Element) => Promise<RenderResult>;
159 parse: typeof parse;
160 getDiagramFromText: (text: string, metadata?: Pick<DiagramMetadata, 'title'>) => Promise<Diagram>;
161 initialize: typeof initialize;
162 getConfig: () => MermaidConfig;
163 setConfig: (conf: MermaidConfig) => MermaidConfig;
164 getSiteConfig: () => MermaidConfig;
165 updateSiteConfig: (conf: MermaidConfig) => MermaidConfig;
166 reset: () => void;
167 globalReset: () => void;
168 defaultConfig: MermaidConfig;
169}>;
170export default mermaidAPI;