UNPKG

1.73 kBTypeScriptView Raw
1/**
2 * Renders text and computes text bounding boxes.
3 *
4 */
5export default class TextRenderer {
6 static $inject: string[];
7 /**
8 * @param config
9 */
10 constructor(config?: TextRendererConfig);
11 /**
12 * Get the new bounds of an externally rendered,
13 * layouted label.
14 *
15 * @param bounds
16 * @param text
17 *
18 * @return
19 */
20 getExternalLabelBounds: (bounds: Rect, text: string) => Rect;
21 /**
22 * Get the new bounds of text annotation.
23 *
24 * @param bounds
25 * @param text
26 *
27 * @return
28 */
29 getTextAnnotationBounds: (bounds: Rect, text: string) => Rect;
30 /**
31 * Create a layouted text element.
32 *
33 * @param text
34 * @param options
35 *
36 * @return rendered text
37 */
38 createText: (text: string, options?: TextLayoutConfig) => SVGElement;
39 /**
40 * Get default text style.
41 */
42 getDefaultStyle: () => {
43 fontFamily: string;
44 fontSize: number;
45 fontWeight: string;
46 lineHeight: number;
47 } & Partial<TextRendererStyle>;
48 /**
49 * Get the external text style.
50 */
51 getExternalStyle: () => {
52 fontFamily: string;
53 fontSize: number;
54 fontWeight: string;
55 lineHeight: number;
56 } & Partial<TextRendererStyle> & {
57 fontSize: number;
58 };
59}
60
61export type TextRendererStyle = {
62 fontFamily: string;
63 fontSize: number;
64 fontWeight: string;
65 lineHeight: number;
66};
67
68export type TextRendererConfig = {
69 defaultStyle?: Partial<TextRendererStyle>;
70 externalStyle?: Partial<TextRendererStyle>;
71};
72
73type TextLayoutConfig = import('diagram-js/lib/util/Text').TextLayoutConfig;
74type Rect = import('diagram-js/lib/util/Types').Rect;