@dskripchenko/diagrams 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Measures with a table of glyph widths. Deterministic, which also makes it
3
+ * the measurer for tests and snapshots.
4
+ */
5
+ export declare const approximateMeasurer: TextMeasurer;
6
+
7
+ /**
8
+ * The best measurer the environment offers: a canvas when there is one,
9
+ * otherwise the glyph table.
10
+ */
11
+ export declare function defaultMeasurer(): TextMeasurer;
12
+
13
+ /** The diagram type a source declares on its first line, or null. */
14
+ export declare function detect(source: string): DiagramType | null;
15
+
16
+ /**
17
+ * The one error every parser and layout throws.
18
+ *
19
+ * A diagram source is written by a person, and the useful answer to "it does
20
+ * not render" is where and why — so the position is part of the error, not a
21
+ * guess the caller has to make from the message.
22
+ */
23
+ export declare class DiagramError extends Error {
24
+ readonly line: number;
25
+ readonly column: number;
26
+ readonly hint?: string | undefined;
27
+ readonly name = "DiagramError";
28
+ /**
29
+ * @param message What is wrong, in a sentence.
30
+ * @param line 1-based line of the source, or 0 when the error is about the whole diagram.
31
+ * @param column 1-based column, or 0 when unknown.
32
+ * @param hint What to write instead, when there is an obvious answer.
33
+ */
34
+ constructor(message: string, line?: number, column?: number, hint?: string | undefined);
35
+ }
36
+
37
+ export declare type DiagramType = 'pie' | 'gantt' | 'flowchart' | 'sequence' | 'state';
38
+
39
+ export declare interface FontSpec {
40
+ /** Pixels. */
41
+ size: number;
42
+ family: string;
43
+ weight?: 'normal' | 'bold';
44
+ style?: 'normal' | 'italic';
45
+ }
46
+
47
+ /** Parses without laying out: the diagram's structure, for tools and tests. */
48
+ export declare function parse(source: string): unknown;
49
+
50
+ /**
51
+ * Renders a diagram to an SVG string.
52
+ *
53
+ * @throws DiagramError when the source cannot be read; the error carries the line and column.
54
+ */
55
+ export declare function render(source: string, options?: RenderOptions): RenderResult;
56
+
57
+ export declare interface RenderOptions {
58
+ /** How text is measured; defaults to a canvas in the browser and a glyph table elsewhere. */
59
+ measureText?: TextMeasurer;
60
+ /**
61
+ * Prefix for every id inside the SVG. Must be unique on the page when the
62
+ * same diagram is shown twice; defaults to a hash of the source.
63
+ */
64
+ idPrefix?: string;
65
+ /** Accessible title; defaults to the diagram's own title or its type. */
66
+ title?: string;
67
+ /**
68
+ * Gantt charts: the date of the "today" line. Without it no line is drawn,
69
+ * so the output never depends on the clock.
70
+ */
71
+ today?: Date;
72
+ }
73
+
74
+ export declare interface RenderResult {
75
+ svg: string;
76
+ width: number;
77
+ height: number;
78
+ type: string;
79
+ }
80
+
81
+ export declare type TextMeasurer = (text: string, font: FontSpec) => TextSize;
82
+
83
+ export declare interface TextSize {
84
+ width: number;
85
+ height: number;
86
+ }
87
+
88
+ /** Variable name → light-theme default. The documented theming surface. */
89
+ export declare const THEME_VARIABLES: Readonly<Record<string, string>>;
90
+
91
+ export { }