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