UNPKG

10 kBTypeScriptView Raw
1import { CurveFactory } from 'd3';
2import { MermaidConfig } from './config.type.js';
3/**
4 * Detects the init config object from the text
5 *
6 * @param text - The text defining the graph. For example:
7 *
8 * ```mermaid
9 * %%{init: {"theme": "debug", "logLevel": 1 }}%%
10 * graph LR
11 * a-->b
12 * b-->c
13 * c-->d
14 * d-->e
15 * e-->f
16 * f-->g
17 * g-->h
18 * ```
19 *
20 * Or
21 *
22 * ```mermaid
23 * %%{initialize: {"theme": "dark", logLevel: "debug" }}%%
24 * graph LR
25 * a-->b
26 * b-->c
27 * c-->d
28 * d-->e
29 * e-->f
30 * f-->g
31 * g-->h
32 * ```
33 *
34 * @param config - Optional mermaid configuration object.
35 * @returns The json object representing the init passed to mermaid.initialize()
36 */
37export declare const detectInit: (text: string, config?: MermaidConfig) => MermaidConfig;
38/**
39 * Detects the directive from the text.
40 *
41 * Text can be single line or multiline. If type is null or omitted,
42 * the first directive encountered in text will be returned
43 *
44 * ```mermaid
45 * graph LR
46 * %%{someDirective}%%
47 * a-->b
48 * b-->c
49 * c-->d
50 * d-->e
51 * e-->f
52 * f-->g
53 * g-->h
54 * ```
55 *
56 * @param text - The text defining the graph
57 * @param type - The directive to return (default: `null`)
58 * @returns An object or Array representing the directive(s) matched by the input type.
59 * If a single directive was found, that directive object will be returned.
60 */
61export declare const detectDirective: (text: string, type?: string | RegExp) => {
62 type?: string | undefined;
63 args?: any;
64} | {
65 type?: string | undefined;
66 args?: any;
67}[];
68/**
69 * Detects whether a substring in present in a given array
70 *
71 * @param str - The substring to detect
72 * @param arr - The array to search
73 * @returns The array index containing the substring or -1 if not present
74 */
75export declare const isSubstringInArray: (str: string, arr: string[]) => number;
76/**
77 * Returns a d3 curve given a curve name
78 *
79 * @param interpolate - The interpolation name
80 * @param defaultCurve - The default curve to return
81 * @returns The curve factory to use
82 */
83export declare function interpolateToCurve(interpolate: string | undefined, defaultCurve: CurveFactory): CurveFactory;
84/**
85 * Formats a URL string
86 *
87 * @param linkStr - String of the URL
88 * @param config - Configuration passed to MermaidJS
89 * @returns The formatted URL or `undefined`.
90 */
91export declare function formatUrl(linkStr: string, config: MermaidConfig): string | undefined;
92/**
93 * Runs a function
94 *
95 * @param functionName - A dot separated path to the function relative to the `window`
96 * @param params - Parameters to pass to the function
97 */
98export declare const runFunc: (functionName: string, ...params: any[]) => void;
99/** A (x, y) point */
100interface Point {
101 /** The x value */
102 x: number;
103 /** The y value */
104 y: number;
105}
106/**
107 * {@inheritdoc traverseEdge}
108 */
109declare function calcLabelPosition(points: Point[]): Point;
110/**
111 * Calculates the terminal label position.
112 *
113 * @param terminalMarkerSize - Terminal marker size.
114 * @param position - Position of label relative to points.
115 * @param _points - Array of points.
116 * @returns - The `cardinalityPosition`.
117 */
118declare function calcTerminalLabelPosition(terminalMarkerSize: number, position: 'start_left' | 'start_right' | 'end_left' | 'end_right', _points: Point[]): Point;
119/**
120 * Gets styles from an array of declarations
121 *
122 * @param arr - Declarations
123 * @returns The styles grouped as strings
124 */
125export declare function getStylesFromArray(arr: string[]): {
126 style: string;
127 labelStyle: string;
128};
129export declare const generateId: () => string;
130export declare const random: (options: any) => string;
131export declare const getTextObj: () => {
132 x: number;
133 y: number;
134 fill: undefined;
135 anchor: string;
136 style: string;
137 width: number;
138 height: number;
139 textMargin: number;
140 rx: number;
141 ry: number;
142 valign: undefined;
143};
144/**
145 * Adds text to an element
146 *
147 * @param elem - SVG Element to add text to
148 * @param textData - Text options.
149 * @returns Text element with given styling and content
150 */
151export declare const drawSimpleText: (elem: SVGElement, textData: {
152 text: string;
153 x: number;
154 y: number;
155 anchor: 'start' | 'middle' | 'end';
156 fontFamily: string;
157 fontSize: string | number;
158 fontWeight: string | number;
159 fill: string;
160 class: string | undefined;
161 textMargin: number;
162}) => SVGTextElement;
163interface WrapLabelConfig {
164 fontSize: number;
165 fontFamily: string;
166 fontWeight: number;
167 joinWith: string;
168}
169export declare const wrapLabel: (label: string, maxWidth: string, config: WrapLabelConfig) => string;
170/**
171 * This calculates the text's height, taking into account the wrap breaks and both the statically
172 * configured height, width, and the length of the text (in pixels).
173 *
174 * If the wrapped text text has greater height, we extend the height, so it's value won't overflow.
175 *
176 * @param text - The text to measure
177 * @param config - The config for fontSize, fontFamily, and fontWeight all impacting the
178 * resulting size
179 * @returns The height for the given text
180 */
181export declare function calculateTextHeight(text: Parameters<typeof calculateTextDimensions>[0], config: Parameters<typeof calculateTextDimensions>[1]): ReturnType<typeof calculateTextDimensions>['height'];
182/**
183 * This calculates the width of the given text, font size and family.
184 *
185 * @param text - The text to calculate the width of
186 * @param config - The config for fontSize, fontFamily, and fontWeight all impacting the
187 * resulting size
188 * @returns The width for the given text
189 */
190export declare function calculateTextWidth(text: Parameters<typeof calculateTextDimensions>[0], config: Parameters<typeof calculateTextDimensions>[1]): ReturnType<typeof calculateTextDimensions>['width'];
191interface TextDimensionConfig {
192 fontSize?: number;
193 fontWeight?: number;
194 fontFamily?: string;
195}
196interface TextDimensions {
197 width: number;
198 height: number;
199 lineHeight?: number;
200}
201/**
202 * This calculates the dimensions of the given text, font size, font family, font weight, and
203 * margins.
204 *
205 * @param text - The text to calculate the width of
206 * @param config - The config for fontSize, fontFamily, fontWeight, and margin all impacting
207 * the resulting size
208 * @returns The dimensions for the given text
209 */
210export declare const calculateTextDimensions: (text: string, config: TextDimensionConfig) => TextDimensions;
211export declare const initIdGenerator: {
212 new (deterministic: any, seed: any): {
213 next(): number;
214 };
215};
216/**
217 * Decodes HTML, source: {@link https://github.com/shrpne/entity-decode/blob/v2.0.1/browser.js}
218 *
219 * @param html - HTML as a string
220 * @returns Unescaped HTML
221 */
222export declare const entityDecode: (html: string) => string;
223/**
224 * Sanitizes directive objects
225 *
226 * @param args - Directive's JSON
227 */
228export declare const directiveSanitizer: (args: any) => void;
229export declare const sanitizeCss: (str: any) => any;
230export interface DetailedError {
231 str: string;
232 hash: any;
233 error?: any;
234 message?: string;
235}
236/** @param error - The error to check */
237export declare function isDetailedError(error: unknown): error is DetailedError;
238/** @param error - The error to convert to an error message */
239export declare function getErrorMessage(error: unknown): string;
240/**
241 * Appends <text> element with the given title and css class.
242 *
243 * @param parent - d3 svg object to append title to
244 * @param cssClass - CSS class for the <text> element containing the title
245 * @param titleTopMargin - Margin in pixels between title and rest of the graph
246 * @param title - The title. If empty, returns immediately.
247 */
248export declare const insertTitle: (parent: any, cssClass: string, titleTopMargin: number, title?: string) => void;
249/**
250 * Parses a raw fontSize configuration value into a number and string value.
251 *
252 * @param fontSize - a string or number font size configuration value
253 *
254 * @returns parsed number and string style font size values, or nulls if a number value can't
255 * be parsed from an input string.
256 */
257export declare const parseFontSize: (fontSize: string | number | undefined) => [number?, string?];
258declare const _default: {
259 assignWithDepth: (dst: any, src: any, config?: {
260 depth: number;
261 clobber: boolean;
262 } | undefined) => any;
263 wrapLabel: (label: string, maxWidth: string, config: WrapLabelConfig) => string;
264 calculateTextHeight: typeof calculateTextHeight;
265 calculateTextWidth: typeof calculateTextWidth;
266 calculateTextDimensions: (text: string, config: TextDimensionConfig) => TextDimensions;
267 detectInit: (text: string, config?: MermaidConfig | undefined) => MermaidConfig;
268 detectDirective: (text: string, type?: string | RegExp) => {
269 type?: string | undefined;
270 args?: any;
271 } | {
272 type?: string | undefined;
273 args?: any;
274 }[];
275 isSubstringInArray: (str: string, arr: string[]) => number;
276 interpolateToCurve: typeof interpolateToCurve;
277 calcLabelPosition: typeof calcLabelPosition;
278 calcCardinalityPosition: (isRelationTypePresent: any, points: any, initialPosition: any) => {
279 x: number;
280 y: number;
281 };
282 calcTerminalLabelPosition: typeof calcTerminalLabelPosition;
283 formatUrl: typeof formatUrl;
284 getStylesFromArray: typeof getStylesFromArray;
285 generateId: () => string;
286 random: (options: any) => string;
287 runFunc: (functionName: string, ...params: any[]) => void;
288 entityDecode: (html: string) => string;
289 initIdGenerator: {
290 new (deterministic: any, seed: any): {
291 next(): number;
292 };
293 };
294 directiveSanitizer: (args: any) => void;
295 sanitizeCss: (str: any) => any;
296 insertTitle: (parent: any, cssClass: string, titleTopMargin: number, title?: string | undefined) => void;
297 parseFontSize: (fontSize: string | number | undefined) => [(number | undefined)?, (string | undefined)?];
298};
299export default _default;