2023-08-22 10:14:11 +02:00
|
|
|
import type { Diagram } from '../Diagram.js';
|
2023-06-19 19:13:15 +02:00
|
|
|
import type { BaseDiagramConfig, MermaidConfig } from '../config.type.js';
|
2023-06-13 18:55:00 +02:00
|
|
|
import type * as d3 from 'd3';
|
2022-10-07 10:57:28 +02:00
|
|
|
|
|
|
|
export interface InjectUtils {
|
|
|
|
_log: any;
|
|
|
|
_setLogLevel: any;
|
|
|
|
_getConfig: any;
|
|
|
|
_sanitizeText: any;
|
|
|
|
_setupGraphViewbox: any;
|
2022-11-23 19:28:26 +01:00
|
|
|
_commonDb: any;
|
2023-01-19 19:03:05 +01:00
|
|
|
_parseDirective: any;
|
2022-10-07 10:57:28 +02:00
|
|
|
}
|
|
|
|
|
2022-11-19 21:48:40 +01:00
|
|
|
/**
|
|
|
|
* Generic Diagram DB that may apply to any diagram type.
|
|
|
|
*/
|
2023-06-13 11:24:10 +02:00
|
|
|
export interface DiagramDB {
|
2023-06-19 19:13:15 +02:00
|
|
|
// config
|
2023-06-19 20:56:35 +02:00
|
|
|
getConfig?: () => BaseDiagramConfig | undefined;
|
2023-06-19 19:13:15 +02:00
|
|
|
|
2023-08-20 16:23:33 +02:00
|
|
|
// db
|
2022-11-19 21:48:40 +01:00
|
|
|
clear?: () => void;
|
|
|
|
setDiagramTitle?: (title: string) => void;
|
2023-08-20 16:23:33 +02:00
|
|
|
getDiagramTitle?: () => string;
|
|
|
|
setAccTitle?: (title: string) => void;
|
2022-11-25 20:30:44 +01:00
|
|
|
getAccTitle?: () => string;
|
2023-08-20 16:23:33 +02:00
|
|
|
setAccDescription?: (describetion: string) => void;
|
2022-11-25 20:30:44 +01:00
|
|
|
getAccDescription?: () => string;
|
2023-08-20 16:23:33 +02:00
|
|
|
|
|
|
|
setDisplayMode?: (title: string) => void;
|
2023-02-19 08:38:13 +01:00
|
|
|
bindFunctions?: (element: Element) => void;
|
2022-11-19 21:48:40 +01:00
|
|
|
}
|
|
|
|
|
2022-10-07 10:57:28 +02:00
|
|
|
export interface DiagramDefinition {
|
2023-06-13 11:24:10 +02:00
|
|
|
db: DiagramDB;
|
2022-10-07 10:57:28 +02:00
|
|
|
renderer: any;
|
2023-08-10 21:26:04 +02:00
|
|
|
parser: ParserDefinition;
|
2023-06-12 22:10:20 +02:00
|
|
|
styles?: any;
|
2022-10-07 10:57:28 +02:00
|
|
|
init?: (config: MermaidConfig) => void;
|
2022-11-10 09:21:53 +01:00
|
|
|
injectUtils?: (
|
|
|
|
_log: InjectUtils['_log'],
|
|
|
|
_setLogLevel: InjectUtils['_setLogLevel'],
|
|
|
|
_getConfig: InjectUtils['_getConfig'],
|
|
|
|
_sanitizeText: InjectUtils['_sanitizeText'],
|
2022-11-23 19:28:26 +01:00
|
|
|
_setupGraphViewbox: InjectUtils['_setupGraphViewbox'],
|
2023-01-19 19:03:05 +01:00
|
|
|
_commonDb: InjectUtils['_commonDb'],
|
2023-01-25 17:49:35 +01:00
|
|
|
_parseDirective: InjectUtils['_parseDirective']
|
2022-11-10 09:21:53 +01:00
|
|
|
) => void;
|
2022-10-07 10:57:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface DetectorRecord {
|
|
|
|
detector: DiagramDetector;
|
|
|
|
loader?: DiagramLoader;
|
|
|
|
}
|
|
|
|
|
2022-11-10 09:21:53 +01:00
|
|
|
export interface ExternalDiagramDefinition {
|
|
|
|
id: string;
|
|
|
|
detector: DiagramDetector;
|
|
|
|
loader: DiagramLoader;
|
|
|
|
}
|
|
|
|
|
2022-10-07 10:57:28 +02:00
|
|
|
export type DiagramDetector = (text: string, config?: MermaidConfig) => boolean;
|
2022-11-10 09:21:53 +01:00
|
|
|
export type DiagramLoader = () => Promise<{ id: string; diagram: DiagramDefinition }>;
|
2023-06-12 18:36:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Type for function draws diagram in the tag with id: id based on the graph definition in text.
|
|
|
|
*
|
|
|
|
* @param text - The text of the diagram.
|
|
|
|
* @param id - The id of the diagram which will be used as a DOM element id.
|
|
|
|
* @param version - MermaidJS version from package.json.
|
|
|
|
* @param diagramObject - A standard diagram containing the DB and the text and type etc of the diagram.
|
|
|
|
*/
|
|
|
|
export type DrawDefinition = (
|
|
|
|
text: string,
|
|
|
|
id: string,
|
|
|
|
version: string,
|
|
|
|
diagramObject: Diagram
|
|
|
|
) => void;
|
2023-06-12 20:11:34 +02:00
|
|
|
|
2023-08-10 21:26:04 +02:00
|
|
|
export interface ParserDefinition {
|
|
|
|
parse: (text: string) => void;
|
2023-08-20 16:21:10 +02:00
|
|
|
parser?: { yy: DiagramDB };
|
2023-08-10 21:26:04 +02:00
|
|
|
}
|
|
|
|
|
2023-06-12 20:11:34 +02:00
|
|
|
/**
|
|
|
|
* Type for function parse directive from diagram code.
|
|
|
|
*
|
|
|
|
* @param statement -
|
|
|
|
* @param context -
|
|
|
|
* @param type -
|
|
|
|
*/
|
|
|
|
export type ParseDirectiveDefinition = (statement: string, context: string, type: string) => void;
|
2023-06-13 17:50:08 +02:00
|
|
|
|
2023-06-20 16:52:50 +02:00
|
|
|
export type HTML = d3.Selection<HTMLIFrameElement, unknown, Element | null, unknown>;
|
2023-06-13 18:55:00 +02:00
|
|
|
|
2023-06-20 16:52:50 +02:00
|
|
|
export type SVG = d3.Selection<SVGSVGElement, unknown, Element | null, unknown>;
|
2023-06-26 18:26:56 +02:00
|
|
|
|
2023-08-05 15:00:06 +02:00
|
|
|
export type Group = d3.Selection<SVGGElement, unknown, Element | null, unknown>;
|
|
|
|
|
2023-06-28 00:35:27 +02:00
|
|
|
export type DiagramStylesProvider = (options?: any) => string;
|