UNPKG

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