index.d.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /// <reference types="node" />
  2. import type { Worker as NodeJSWorker } from "worker_threads";
  3. import type { RenderOptions, GraphvizJSONOutput } from "./types";
  4. declare type VizConstructorOptionsWorkerURL = {
  5. workerURL: string | URL;
  6. };
  7. declare type VizConstructorOptionsWorker = {
  8. worker: Worker | NodeJSWorker;
  9. };
  10. export declare type VizConstructorOptions = VizConstructorOptionsWorkerURL | VizConstructorOptionsWorker;
  11. /**
  12. * The Viz class provides an interface between the rendering worker(s) and the
  13. * "main" thread.
  14. */
  15. declare class Viz {
  16. private _wrapper;
  17. /**
  18. * Constructs a new Viz instance.
  19. *
  20. * If the `workerURL` option is given, its value must be the URL of one of the
  21. * rendering script files included in the distribution (E.G.:
  22. * `render.browser.js`).
  23. * If the worker option is given, its value must be a `Worker` object
  24. * constructed with the URL or path of one of the rendering script files
  25. * included in the distribution (E.G.: `render.node.js`).
  26. *
  27. * @param options An object containing option properties on the worker to use.
  28. * @throws {Error} if no options are given.
  29. */
  30. constructor(options: VizConstructorOptions);
  31. /**
  32. * Renders a DOT graph to the specified format.
  33. * @param src DOT representation of the graph to render.
  34. * @param options Options for the rendering engine.
  35. * @returns Raw output of Graphviz as a string.
  36. */
  37. renderString(src: string, { format, engine, files, images, yInvert, nop, }?: RenderOptions): Promise<string>;
  38. /**
  39. * Renders the graph as a JSON object.
  40. * @param src DOT representation of the graph to render
  41. * @param options Options for the rendering engine. `format` is ignored,
  42. * unless it is json or json0.
  43. * @returns Parsed JSON object from Graphviz.
  44. * @see https://graphviz.gitlab.io/_pages/doc/info/output.html#d:json
  45. */
  46. renderJSONObject(src: string, options?: RenderOptions): Promise<GraphvizJSONOutput>;
  47. /**
  48. * Terminates the worker, clearing all on-going work.
  49. */
  50. terminateWorker(): Promise<number> | void;
  51. }
  52. export default Viz;
  53. export type { RenderOptions, GraphvizJSONOutput };