UNPKG

10.2 kBTypeScriptView Raw
1import type { CurveFactory } from 'd3';
2import type { MermaidConfig } from './config.type.js';
3import type { D3Element } from './mermaidAPI.js';
4import type { Point, TextDimensionConfig, TextDimensions } from './types.js';
5export declare const ZERO_WIDTH_SPACE = "\u200B";
6/**
7 * Detects the init config object from the text
8 *
9 * @param text - The text defining the graph. For example:
10 *
11 * ```mermaid
12 * %%{init: {"theme": "debug", "logLevel": 1 }}%%
13 * graph LR
14 * a-->b
15 * b-->c
16 * c-->d
17 * d-->e
18 * e-->f
19 * f-->g
20 * g-->h
21 * ```
22 *
23 * Or
24 *
25 * ```mermaid
26 * %%{initialize: {"theme": "dark", logLevel: "debug" }}%%
27 * graph LR
28 * a-->b
29 * b-->c
30 * c-->d
31 * d-->e
32 * e-->f
33 * f-->g
34 * g-->h
35 * ```
36 *
37 * @param config - Optional mermaid configuration object.
38 * @returns The json object representing the init passed to mermaid.initialize()
39 */
40export declare const detectInit: (text: string, config?: MermaidConfig) => MermaidConfig | undefined;
41interface Directive {
42 type?: string;
43 args?: unknown;
44}
45/**
46 * Detects the directive from the text.
47 *
48 * Text can be single line or multiline. If type is null or omitted,
49 * the first directive encountered in text will be returned
50 *
51 * ```mermaid
52 * graph LR
53 * %%{someDirective}%%
54 * a-->b
55 * b-->c
56 * c-->d
57 * d-->e
58 * e-->f
59 * f-->g
60 * g-->h
61 * ```
62 *
63 * @param text - The text defining the graph
64 * @param type - The directive to return (default: `null`)
65 * @returns An object or Array representing the directive(s) matched by the input type.
66 * If a single directive was found, that directive object will be returned.
67 */
68export declare const detectDirective: (text: string, type?: string | RegExp | null) => Directive | Directive[];
69export declare const removeDirectives: (text: string) => string;
70/**
71 * Detects whether a substring in present in a given array
72 *
73 * @param str - The substring to detect
74 * @param arr - The array to search
75 * @returns The array index containing the substring or -1 if not present
76 */
77export declare const isSubstringInArray: (str: string, arr: string[]) => number;
78/**
79 * Returns a d3 curve given a curve name
80 *
81 * @param interpolate - The interpolation name
82 * @param defaultCurve - The default curve to return
83 * @returns The curve factory to use
84 */
85export declare function interpolateToCurve(interpolate: string | undefined, defaultCurve: CurveFactory): CurveFactory;
86/**
87 * Formats a URL string
88 *
89 * @param linkStr - String of the URL
90 * @param config - Configuration passed to MermaidJS
91 * @returns The formatted URL or `undefined`.
92 */
93export declare function formatUrl(linkStr: string, config: MermaidConfig): string | undefined;
94/**
95 * Runs a function
96 *
97 * @param functionName - A dot separated path to the function relative to the `window`
98 * @param params - Parameters to pass to the function
99 */
100export declare const runFunc: (functionName: string, ...params: unknown[]) => void;
101/**
102 * {@inheritdoc traverseEdge}
103 */
104declare function calcLabelPosition(points: Point[]): Point;
105export declare const roundNumber: (num: number, precision?: number) => number;
106export declare const calculatePoint: (points: Point[], distanceToTraverse: number) => Point;
107/**
108 * Calculates the terminal label position.
109 *
110 * @param terminalMarkerSize - Terminal marker size.
111 * @param position - Position of label relative to points.
112 * @param _points - Array of points.
113 * @returns - The `cardinalityPosition`.
114 */
115declare function calcTerminalLabelPosition(terminalMarkerSize: number, position: 'start_left' | 'start_right' | 'end_left' | 'end_right', _points: Point[]): Point;
116/**
117 * Gets styles from an array of declarations
118 *
119 * @param arr - Declarations
120 * @returns The styles grouped as strings
121 */
122export declare function getStylesFromArray(arr: string[]): {
123 style: string;
124 labelStyle: string;
125};
126export declare const generateId: () => string;
127export declare const random: (options: {
128 length: number;
129}) => string;
130export declare const getTextObj: () => {
131 x: number;
132 y: number;
133 fill: undefined;
134 anchor: string;
135 style: string;
136 width: number;
137 height: number;
138 textMargin: number;
139 rx: number;
140 ry: number;
141 valign: undefined;
142 text: string;
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: number, 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'];
191/**
192 * This calculates the dimensions of the given text, font size, font family, font weight, and
193 * margins.
194 *
195 * @param text - The text to calculate the width of
196 * @param config - The config for fontSize, fontFamily, fontWeight, and margin all impacting
197 * the resulting size
198 * @returns The dimensions for the given text
199 */
200export declare const calculateTextDimensions: (text: string, config: TextDimensionConfig) => TextDimensions;
201export declare class InitIDGenerator {
202 private count;
203 next: () => number;
204 constructor(deterministic?: boolean, seed?: string);
205}
206/**
207 * Decodes HTML, source: {@link https://github.com/shrpne/entity-decode/blob/v2.0.1/browser.js}
208 *
209 * @param html - HTML as a string
210 * @returns Unescaped HTML
211 */
212export declare const entityDecode: (html: string) => string;
213export interface DetailedError {
214 str: string;
215 hash: any;
216 error?: any;
217 message?: string;
218}
219/** @param error - The error to check */
220export declare function isDetailedError(error: any): error is DetailedError;
221/** @param error - The error to convert to an error message */
222export declare function getErrorMessage(error: unknown): string;
223/**
224 * Appends <text> element with the given title and css class.
225 *
226 * @param parent - d3 svg object to append title to
227 * @param cssClass - CSS class for the <text> element containing the title
228 * @param titleTopMargin - Margin in pixels between title and rest of the graph
229 * @param title - The title. If empty, returns immediately.
230 */
231export declare const insertTitle: (parent: D3Element, cssClass: string, titleTopMargin: number, title?: string) => void;
232/**
233 * Parses a raw fontSize configuration value into a number and string value.
234 *
235 * @param fontSize - a string or number font size configuration value
236 *
237 * @returns parsed number and string style font size values, or nulls if a number value can't
238 * be parsed from an input string.
239 */
240export declare const parseFontSize: (fontSize: string | number | undefined) => [number?, string?];
241export declare function cleanAndMerge<T>(defaultData: T, data?: Partial<T>): T;
242declare const _default: {
243 assignWithDepth: (dst: any, src: any, { depth, clobber }?: {
244 depth?: number | undefined;
245 clobber?: boolean | undefined;
246 }) => any;
247 wrapLabel: (label: string, maxWidth: number, config: WrapLabelConfig) => string;
248 calculateTextHeight: typeof calculateTextHeight;
249 calculateTextWidth: typeof calculateTextWidth;
250 calculateTextDimensions: (text: string, config: TextDimensionConfig) => TextDimensions;
251 cleanAndMerge: typeof cleanAndMerge;
252 detectInit: (text: string, config?: MermaidConfig | undefined) => MermaidConfig | undefined;
253 detectDirective: (text: string, type?: string | RegExp | null) => Directive | Directive[];
254 isSubstringInArray: (str: string, arr: string[]) => number;
255 interpolateToCurve: typeof interpolateToCurve;
256 calcLabelPosition: typeof calcLabelPosition;
257 calcCardinalityPosition: (isRelationTypePresent: boolean, points: Point[], initialPosition: Point) => {
258 x: number;
259 y: number;
260 };
261 calcTerminalLabelPosition: typeof calcTerminalLabelPosition;
262 formatUrl: typeof formatUrl;
263 getStylesFromArray: typeof getStylesFromArray;
264 generateId: () => string;
265 random: (options: {
266 length: number;
267 }) => string;
268 runFunc: (functionName: string, ...params: unknown[]) => void;
269 entityDecode: (html: string) => string;
270 insertTitle: (parent: any, cssClass: string, titleTopMargin: number, title?: string | undefined) => void;
271 parseFontSize: (fontSize: string | number | undefined) => [(number | undefined)?, (string | undefined)?];
272 InitIDGenerator: typeof InitIDGenerator;
273};
274export default _default;
275/**
276 * @param text - text to be encoded
277 * @returns
278 */
279export declare const encodeEntities: (text: string) => string;
280/**
281 *
282 * @param text - text to be decoded
283 * @returns
284 */
285export declare const decodeEntities: (text: string) => string;
286export declare const isString: (value: unknown) => value is string;