|
| 1 | +declare module "@terrastruct/d2" { |
| 2 | + interface RenderOptions { |
| 3 | + /** Enable sketch mode [default: false] */ |
| 4 | + sketch?: boolean; |
| 5 | + /** Theme ID to use [default: 0] */ |
| 6 | + themeID?: number; |
| 7 | + /** Theme ID to use when client is in dark mode */ |
| 8 | + darkThemeID?: number; |
| 9 | + /** Center the SVG in the containing viewbox [default: false] */ |
| 10 | + center?: boolean; |
| 11 | + /** Pixels padded around the rendered diagram [default: 100] */ |
| 12 | + pad?: number; |
| 13 | + /** Scale the output. E.g., 0.5 to halve the default size. The default will render SVG's that will fit to screen. Setting to 1 turns off SVG fitting to screen. */ |
| 14 | + scale?: number; |
| 15 | + /** Adds an appendix for tooltips and links [default: false] */ |
| 16 | + forceAppendix?: boolean; |
| 17 | + /** Target board/s to render. If target ends with '', it will be rendered with all of its scenarios, steps, and layers. Otherwise, only the target board will be rendered. E.g. target: 'layers.x.*' to render layer 'x' with all of its children. Pass '' to render all scenarios, steps, and layers. By default, only the root board is rendered. Multi-board outputs are currently only supported for animated SVGs and so animateInterval must be set to a value greater than 0 when targeting multiple boards. */ |
| 18 | + target?: string; |
| 19 | + /** If given, multiple boards are packaged as 1 SVG which transitions through each board at the interval (in milliseconds). */ |
| 20 | + animateInterval?: number; |
| 21 | + /** Add a salt value to ensure the output uses unique IDs. This is useful when generating multiple identical diagrams to be included in the same HTML doc, so that duplicate IDs do not cause invalid HTML. The salt value is a string that will be appended to IDs in the output. */ |
| 22 | + salt?: string; |
| 23 | + /** Omit XML tag (<?xml ...?>) from output SVG files. Useful when generating SVGs for direct HTML embedding. */ |
| 24 | + noXMLTag?: boolean; |
| 25 | + } |
| 26 | + |
| 27 | + interface CompileOptions extends RenderOptions { |
| 28 | + /** Layout engine to use [default: 'dagre'] */ |
| 29 | + layout?: 'dagre' | 'elk'; |
| 30 | + /** A byte array containing .ttf file to use for the regular font. If none provided, Source Sans Pro Regular is used. */ |
| 31 | + fontRegular?: Uint8Array; |
| 32 | + /** A byte array containing .ttf file to use for the italic font. If none provided, Source Sans Pro Italic is used. */ |
| 33 | + fontItalic?: Uint8Array; |
| 34 | + /** A byte array containing .ttf file to use for the bold font. If none provided, Source Sans Pro Bold is used. */ |
| 35 | + fontBold?: Uint8Array; |
| 36 | + /** A byte array containing .ttf file to use for the semibold font. If none provided, Source Sans Pro Semibold is used. */ |
| 37 | + fontSemibold?: Uint8Array; |
| 38 | + } |
| 39 | + |
| 40 | + interface CompileRequest { |
| 41 | + /** A mapping of D2 file paths to their content*/ |
| 42 | + fs: Record<string, string>; |
| 43 | + /** The path of the entry D2 file [default: index]*/ |
| 44 | + inputPath: string; |
| 45 | + /** The CompileOptions to pass to the compiler*/ |
| 46 | + options: CompileOptions; |
| 47 | + } |
| 48 | + |
| 49 | + interface Diagram { |
| 50 | + config: RenderOptions; |
| 51 | + } |
| 52 | + |
| 53 | + interface CompileResult { |
| 54 | + /** Compiled D2 diagram*/ |
| 55 | + diagram: Diagram; |
| 56 | + /** RenderOptions: Render options merged with configuration set in diagram*/ |
| 57 | + renderOptions: RenderOptions; |
| 58 | + fs: Record<string, string>; |
| 59 | + graph: unknown; |
| 60 | + } |
| 61 | + |
| 62 | + class D2 { |
| 63 | + compile(input: string | CompileRequest, options?: CompileOptions): Promise<CompileResult>; |
| 64 | + render(diagram: Diagram, options?: RenderOptions): Promise<string>; |
| 65 | + } |
| 66 | +} |
0 commit comments