From 02903be558dcc99cc006a223fc1987e5554b1933 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Fri, 18 Nov 2022 14:28:28 +0530 Subject: [PATCH 01/67] feat: Split C4 & Flow --- .../mermaid/src/diagram-api/detectType.ts | 5 ++ .../src/diagram-api/diagram-orchestration.ts | 80 ++----------------- .../mermaid/src/diagrams/c4/c4Detector.ts | 19 ++++- packages/mermaid/src/diagrams/c4/c4Diagram.ts | 16 ++++ .../diagrams/flowchart/flowDetector copy.ts | 24 ++++++ .../src/diagrams/flowchart/flowDetector-v2.ts | 18 ++++- .../src/diagrams/flowchart/flowDetector.ts | 18 ++++- .../src/diagrams/flowchart/flowDiagram-v2.ts | 25 ++++++ .../src/diagrams/flowchart/flowDiagram.ts | 24 ++++++ 9 files changed, 153 insertions(+), 76 deletions(-) create mode 100644 packages/mermaid/src/diagrams/c4/c4Diagram.ts create mode 100644 packages/mermaid/src/diagrams/flowchart/flowDetector copy.ts create mode 100644 packages/mermaid/src/diagrams/flowchart/flowDiagram-v2.ts create mode 100644 packages/mermaid/src/diagrams/flowchart/flowDiagram.ts diff --git a/packages/mermaid/src/diagram-api/detectType.ts b/packages/mermaid/src/diagram-api/detectType.ts index 9536fded2..1ea4f2b4d 100644 --- a/packages/mermaid/src/diagram-api/detectType.ts +++ b/packages/mermaid/src/diagram-api/detectType.ts @@ -1,6 +1,7 @@ import { MermaidConfig } from '../config.type'; import { log } from '../logger'; import { DetectorRecord, DiagramDetector, DiagramLoader } from './types'; +import { ExternalDiagramDefinition } from '../diagram-api/types'; const directive = /[%]{2}[{]\s*(?:(?:(\w+)\s*:|(\w+))\s*(?:(?:(\w+))|((?:(?![}][%]{2}).|\r?\n)*))?\s*)(?:[}][%]{2})?/gi; @@ -43,6 +44,10 @@ export const detectType = function (text: string, config?: MermaidConfig): strin throw new Error(`No diagram type detected for text: ${text}`); }; +export const addDiagram = ({ id, detector, loader }: ExternalDiagramDefinition) => { + addDetector(id, detector, loader); +}; + export const addDetector = (key: string, detector: DiagramDetector, loader?: DiagramLoader) => { if (detectors[key]) { throw new Error(`Detector with key ${key} already exists`); diff --git a/packages/mermaid/src/diagram-api/diagram-orchestration.ts b/packages/mermaid/src/diagram-api/diagram-orchestration.ts index a26edb303..88dfcffeb 100644 --- a/packages/mermaid/src/diagram-api/diagram-orchestration.ts +++ b/packages/mermaid/src/diagram-api/diagram-orchestration.ts @@ -1,4 +1,7 @@ import { registerDiagram } from './diagramAPI'; +import c4 from '../diagrams/c4/c4Detector'; +import flowchart from '../diagrams/flowchart/flowDetector'; +import flowchartV2 from '../diagrams/flowchart/flowDetector-v2'; // @ts-ignore: TODO Fix ts errors import gitGraphParser from '../diagrams/git/parser/gitGraph'; @@ -7,13 +10,6 @@ import gitGraphDb from '../diagrams/git/gitGraphAst'; import gitGraphRenderer from '../diagrams/git/gitGraphRenderer'; import gitGraphStyles from '../diagrams/git/styles'; -// @ts-ignore: TODO Fix ts errors -import c4Parser from '../diagrams/c4/parser/c4Diagram'; -import { c4Detector } from '../diagrams/c4/c4Detector'; -import c4Db from '../diagrams/c4/c4Db'; -import c4Renderer from '../diagrams/c4/c4Renderer'; -import c4Styles from '../diagrams/c4/styles'; - // @ts-ignore: TODO Fix ts errors import classParser from '../diagrams/class/parser/classDiagram'; import { classDetector } from '../diagrams/class/classDetector'; @@ -30,15 +26,6 @@ import erDb from '../diagrams/er/erDb'; import erRenderer from '../diagrams/er/erRenderer'; import erStyles from '../diagrams/er/styles'; -// @ts-ignore: TODO Fix ts errors -import flowParser from '../diagrams/flowchart/parser/flow'; -import { flowDetector } from '../diagrams/flowchart/flowDetector'; -import { flowDetectorV2 } from '../diagrams/flowchart/flowDetector-v2'; -import flowDb from '../diagrams/flowchart/flowDb'; -import flowRenderer from '../diagrams/flowchart/flowRenderer'; -import flowRendererV2 from '../diagrams/flowchart/flowRenderer-v2'; -import flowStyles from '../diagrams/flowchart/styles'; - // @ts-ignore: TODO Fix ts errors import ganttParser from '../diagrams/gantt/parser/gantt'; import { ganttDetector } from '../diagrams/gantt/ganttDetector'; @@ -89,10 +76,10 @@ import { journeyDetector } from '../diagrams/user-journey/journeyDetector'; import journeyDb from '../diagrams/user-journey/journeyDb'; import journeyRenderer from '../diagrams/user-journey/journeyRenderer'; import journeyStyles from '../diagrams/user-journey/styles'; -import { setConfig } from '../config'; import errorRenderer from '../diagrams/error/errorRenderer'; import errorStyles from '../diagrams/error/styles'; +import { addDiagram } from './detectType'; let hasLoadedDiagrams = false; export const addDiagrams = () => { @@ -125,20 +112,7 @@ export const addDiagrams = () => { }, (text) => text.toLowerCase().trim() === 'error' ); - - registerDiagram( - 'c4', - { - parser: c4Parser, - db: c4Db, - renderer: c4Renderer, - styles: c4Styles, - init: (cnf) => { - c4Renderer.setConf(cnf.c4); - }, - }, - c4Detector - ); + addDiagram(c4); registerDiagram( 'class', { @@ -295,47 +269,9 @@ export const addDiagrams = () => { journeyDetector ); - registerDiagram( - 'flowchart', - { - parser: flowParser, - db: flowDb, - renderer: flowRendererV2, - styles: flowStyles, - init: (cnf) => { - if (!cnf.flowchart) { - cnf.flowchart = {}; - } - // TODO, broken as of 2022-09-14 (13809b50251845475e6dca65cc395761be38fbd2) - cnf.flowchart.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute; - flowRenderer.setConf(cnf.flowchart); - flowDb.clear(); - flowDb.setGen('gen-1'); - }, - }, - flowDetector - ); - registerDiagram( - 'flowchart-v2', - { - parser: flowParser, - db: flowDb, - renderer: flowRendererV2, - styles: flowStyles, - init: (cnf) => { - if (!cnf.flowchart) { - cnf.flowchart = {}; - } - cnf.flowchart.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute; - // flowchart-v2 uses dagre-wrapper, which doesn't have access to flowchart cnf - setConfig({ flowchart: { arrowMarkerAbsolute: cnf.arrowMarkerAbsolute } }); - flowRendererV2.setConf(cnf.flowchart); - flowDb.clear(); - flowDb.setGen('gen-2'); - }, - }, - flowDetectorV2 - ); + addDiagram(flowchart); + addDiagram(flowchartV2); + registerDiagram( 'gitGraph', { parser: gitGraphParser, db: gitGraphDb, renderer: gitGraphRenderer, styles: gitGraphStyles }, diff --git a/packages/mermaid/src/diagrams/c4/c4Detector.ts b/packages/mermaid/src/diagrams/c4/c4Detector.ts index 49ba95b8e..08b8bbf55 100644 --- a/packages/mermaid/src/diagrams/c4/c4Detector.ts +++ b/packages/mermaid/src/diagrams/c4/c4Detector.ts @@ -1,5 +1,20 @@ -import type { DiagramDetector } from '../../diagram-api/types'; +import type { ExternalDiagramDefinition } from '../../diagram-api/types'; -export const c4Detector: DiagramDetector = (txt) => { +const id = 'c4'; + +const detector = (txt: string) => { return txt.match(/^\s*C4Context|C4Container|C4Component|C4Dynamic|C4Deployment/) !== null; }; + +const loader = async () => { + const { diagram } = await import('./c4Diagram'); + return { id, diagram }; +}; + +const plugin: ExternalDiagramDefinition = { + id, + detector, + loader, +}; + +export default plugin; diff --git a/packages/mermaid/src/diagrams/c4/c4Diagram.ts b/packages/mermaid/src/diagrams/c4/c4Diagram.ts new file mode 100644 index 000000000..d51be7160 --- /dev/null +++ b/packages/mermaid/src/diagrams/c4/c4Diagram.ts @@ -0,0 +1,16 @@ +// @ts-ignore: TODO Fix ts errors +import c4Parser from './parser/c4Diagram'; +import c4Db from './c4Db'; +import c4Renderer from './c4Renderer'; +import c4Styles from './styles'; +import { MermaidConfig } from '../../config.type'; + +export const diagram = { + parser: c4Parser, + db: c4Db, + renderer: c4Renderer, + styles: c4Styles, + init: (cnf: MermaidConfig) => { + c4Renderer.setConf(cnf.c4); + }, +}; diff --git a/packages/mermaid/src/diagrams/flowchart/flowDetector copy.ts b/packages/mermaid/src/diagrams/flowchart/flowDetector copy.ts new file mode 100644 index 000000000..3d09f36ae --- /dev/null +++ b/packages/mermaid/src/diagrams/flowchart/flowDetector copy.ts @@ -0,0 +1,24 @@ +import type { DiagramDetector } from '../../diagram-api/types'; +import type { ExternalDiagramDefinition } from '../../diagram-api/types'; + +const id = 'flowchart'; + +const detector: DiagramDetector = (txt, config) => { + // If we have confired to only use new flow charts this function shohuld always return false + // as in not signalling true for a legacy flowchart + if (config?.flowchart?.defaultRenderer === 'dagre-wrapper') return false; + return txt.match(/^\s*graph/) !== null; +}; + +const loader = async () => { + const { diagram } = await import('./flowDiagram'); + return { id, diagram }; +}; + +const plugin: ExternalDiagramDefinition = { + id, + detector, + loader, +}; + +export default plugin; diff --git a/packages/mermaid/src/diagrams/flowchart/flowDetector-v2.ts b/packages/mermaid/src/diagrams/flowchart/flowDetector-v2.ts index c2ec736c7..565cd2104 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowDetector-v2.ts +++ b/packages/mermaid/src/diagrams/flowchart/flowDetector-v2.ts @@ -1,8 +1,24 @@ import type { DiagramDetector } from '../../diagram-api/types'; +import type { ExternalDiagramDefinition } from '../../diagram-api/types'; -export const flowDetectorV2: DiagramDetector = (txt, config) => { +const id = 'flowchart-v2'; + +const detector: DiagramDetector = (txt, config) => { // If we have confgured to use dagre-wrapper then we should return true in this function for graph code thus making it use the new flowchart diagram if (config?.flowchart?.defaultRenderer === 'dagre-wrapper' && txt.match(/^\s*graph/) !== null) return true; return txt.match(/^\s*flowchart/) !== null; }; + +const loader = async () => { + const { diagram } = await import('./flowDiagram-v2'); + return { id, diagram }; +}; + +const plugin: ExternalDiagramDefinition = { + id, + detector, + loader, +}; + +export default plugin; diff --git a/packages/mermaid/src/diagrams/flowchart/flowDetector.ts b/packages/mermaid/src/diagrams/flowchart/flowDetector.ts index 740d12847..3d09f36ae 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowDetector.ts +++ b/packages/mermaid/src/diagrams/flowchart/flowDetector.ts @@ -1,8 +1,24 @@ import type { DiagramDetector } from '../../diagram-api/types'; +import type { ExternalDiagramDefinition } from '../../diagram-api/types'; -export const flowDetector: DiagramDetector = (txt, config) => { +const id = 'flowchart'; + +const detector: DiagramDetector = (txt, config) => { // If we have confired to only use new flow charts this function shohuld always return false // as in not signalling true for a legacy flowchart if (config?.flowchart?.defaultRenderer === 'dagre-wrapper') return false; return txt.match(/^\s*graph/) !== null; }; + +const loader = async () => { + const { diagram } = await import('./flowDiagram'); + return { id, diagram }; +}; + +const plugin: ExternalDiagramDefinition = { + id, + detector, + loader, +}; + +export default plugin; diff --git a/packages/mermaid/src/diagrams/flowchart/flowDiagram-v2.ts b/packages/mermaid/src/diagrams/flowchart/flowDiagram-v2.ts new file mode 100644 index 000000000..8cd49de65 --- /dev/null +++ b/packages/mermaid/src/diagrams/flowchart/flowDiagram-v2.ts @@ -0,0 +1,25 @@ +// @ts-ignore: TODO Fix ts errors +import flowParser from './parser/flow'; +import flowDb from './flowDb'; +import flowRendererV2 from './flowRenderer-v2'; +import flowStyles from './styles'; +import { MermaidConfig } from '../../config.type'; +import { setConfig } from '../../config'; + +export const diagram = { + parser: flowParser, + db: flowDb, + renderer: flowRendererV2, + styles: flowStyles, + init: (cnf: MermaidConfig) => { + if (!cnf.flowchart) { + cnf.flowchart = {}; + } + cnf.flowchart.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute; + // flowchart-v2 uses dagre-wrapper, which doesn't have access to flowchart cnf + setConfig({ flowchart: { arrowMarkerAbsolute: cnf.arrowMarkerAbsolute } }); + flowRendererV2.setConf(cnf.flowchart); + flowDb.clear(); + flowDb.setGen('gen-2'); + }, +}; diff --git a/packages/mermaid/src/diagrams/flowchart/flowDiagram.ts b/packages/mermaid/src/diagrams/flowchart/flowDiagram.ts new file mode 100644 index 000000000..d68a7c01d --- /dev/null +++ b/packages/mermaid/src/diagrams/flowchart/flowDiagram.ts @@ -0,0 +1,24 @@ +// @ts-ignore: TODO Fix ts errors +import flowParser from './parser/flow'; +import flowDb from './flowDb'; +import flowRenderer from './flowRenderer'; +import flowRendererV2 from './flowRenderer-v2'; +import flowStyles from './styles'; +import { MermaidConfig } from '../../config.type'; + +export const diagram = { + parser: flowParser, + db: flowDb, + renderer: flowRendererV2, + styles: flowStyles, + init: (cnf: MermaidConfig) => { + if (!cnf.flowchart) { + cnf.flowchart = {}; + } + // TODO, broken as of 2022-09-14 (13809b50251845475e6dca65cc395761be38fbd2) + cnf.flowchart.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute; + flowRenderer.setConf(cnf.flowchart); + flowDb.clear(); + flowDb.setGen('gen-1'); + }, +}; From 5dec9eb2f54dcccd1df96766b6575c8a34080a93 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Fri, 18 Nov 2022 16:09:10 +0530 Subject: [PATCH 02/67] fix: C4 type --- packages/mermaid/src/diagrams/c4/c4Diagram.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/mermaid/src/diagrams/c4/c4Diagram.ts b/packages/mermaid/src/diagrams/c4/c4Diagram.ts index d51be7160..6f8f25db2 100644 --- a/packages/mermaid/src/diagrams/c4/c4Diagram.ts +++ b/packages/mermaid/src/diagrams/c4/c4Diagram.ts @@ -4,8 +4,9 @@ import c4Db from './c4Db'; import c4Renderer from './c4Renderer'; import c4Styles from './styles'; import { MermaidConfig } from '../../config.type'; +import { DiagramDefinition } from '../../diagram-api/types'; -export const diagram = { +export const diagram: DiagramDefinition = { parser: c4Parser, db: c4Db, renderer: c4Renderer, From 4492c5ed4e29e3ef05d2f938cbebc7c884f8b4d4 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Fri, 18 Nov 2022 16:09:36 +0530 Subject: [PATCH 03/67] chore(split): classDiagram --- .../src/diagrams/class/classDetector-V2.ts | 19 ++++++++++++++++-- .../src/diagrams/class/classDetector.ts | 19 ++++++++++++++++-- .../src/diagrams/class/classDiagram-v2.ts | 20 +++++++++++++++++++ .../src/diagrams/class/classDiagram.ts | 20 +++++++++++++++++++ 4 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 packages/mermaid/src/diagrams/class/classDiagram-v2.ts create mode 100644 packages/mermaid/src/diagrams/class/classDiagram.ts diff --git a/packages/mermaid/src/diagrams/class/classDetector-V2.ts b/packages/mermaid/src/diagrams/class/classDetector-V2.ts index d65caf9a8..51b93fb0d 100644 --- a/packages/mermaid/src/diagrams/class/classDetector-V2.ts +++ b/packages/mermaid/src/diagrams/class/classDetector-V2.ts @@ -1,9 +1,24 @@ -import type { DiagramDetector } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; -export const classDetectorV2: DiagramDetector = (txt, config) => { +const id = 'classDiagram'; + +const detector: DiagramDetector = (txt, config) => { // If we have confgured to use dagre-wrapper then we should return true in this function for classDiagram code thus making it use the new class diagram if (txt.match(/^\s*classDiagram/) !== null && config?.class?.defaultRenderer === 'dagre-wrapper') return true; // We have not opted to use the new renderer so we should return true if we detect a class diagram return txt.match(/^\s*classDiagram-v2/) !== null; }; + +const loader = async () => { + const { diagram } = await import('./classDiagram-v2'); + return { id, diagram }; +}; + +const plugin: ExternalDiagramDefinition = { + id, + detector, + loader, +}; + +export default plugin; diff --git a/packages/mermaid/src/diagrams/class/classDetector.ts b/packages/mermaid/src/diagrams/class/classDetector.ts index ef6389a60..dc2f4261f 100644 --- a/packages/mermaid/src/diagrams/class/classDetector.ts +++ b/packages/mermaid/src/diagrams/class/classDetector.ts @@ -1,8 +1,23 @@ -import type { DiagramDetector } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; -export const classDetector: DiagramDetector = (txt, config) => { +const id = 'class'; + +const detector: DiagramDetector = (txt, config) => { // If we have confgured to use dagre-wrapper then we should never return true in this function if (config?.class?.defaultRenderer === 'dagre-wrapper') return false; // We have not opted to use the new renderer so we should return true if we detect a class diagram return txt.match(/^\s*classDiagram/) !== null; }; + +const loader = async () => { + const { diagram } = await import('./classDiagram'); + return { id, diagram }; +}; + +const plugin: ExternalDiagramDefinition = { + id, + detector, + loader, +}; + +export default plugin; diff --git a/packages/mermaid/src/diagrams/class/classDiagram-v2.ts b/packages/mermaid/src/diagrams/class/classDiagram-v2.ts new file mode 100644 index 000000000..2f0bbf371 --- /dev/null +++ b/packages/mermaid/src/diagrams/class/classDiagram-v2.ts @@ -0,0 +1,20 @@ +import { DiagramDefinition } from '../../diagram-api/types'; +// @ts-ignore: TODO Fix ts errors +import parser from './parser/classDiagram'; +import db from './classDb'; +import styles from './styles'; +import renderer from './classRenderer-v2'; + +export const diagram: DiagramDefinition = { + parser, + db, + renderer, + styles, + init: (cnf) => { + if (!cnf.class) { + cnf.class = {}; + } + cnf.class.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute; + db.clear(); + }, +}; diff --git a/packages/mermaid/src/diagrams/class/classDiagram.ts b/packages/mermaid/src/diagrams/class/classDiagram.ts new file mode 100644 index 000000000..250d04176 --- /dev/null +++ b/packages/mermaid/src/diagrams/class/classDiagram.ts @@ -0,0 +1,20 @@ +import { DiagramDefinition } from '../../diagram-api/types'; +// @ts-ignore: TODO Fix ts errors +import parser from './parser/classDiagram'; +import db from './classDb'; +import styles from './styles'; +import renderer from './classRenderer'; + +export const diagram: DiagramDefinition = { + parser, + db, + renderer, + styles, + init: (cnf) => { + if (!cnf.class) { + cnf.class = {}; + } + cnf.class.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute; + db.clear(); + }, +}; From 43aa831dd292351176419793bde47a1a2c6de234 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Fri, 18 Nov 2022 16:09:45 +0530 Subject: [PATCH 04/67] chore(split): ER --- .../mermaid/src/diagrams/er/erDetector.ts | 19 +++++++++++++++++-- packages/mermaid/src/diagrams/er/erDiagram.ts | 12 ++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 packages/mermaid/src/diagrams/er/erDiagram.ts diff --git a/packages/mermaid/src/diagrams/er/erDetector.ts b/packages/mermaid/src/diagrams/er/erDetector.ts index 5a87a949e..f73baa434 100644 --- a/packages/mermaid/src/diagrams/er/erDetector.ts +++ b/packages/mermaid/src/diagrams/er/erDetector.ts @@ -1,5 +1,20 @@ -import type { DiagramDetector } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; -export const erDetector: DiagramDetector = (txt) => { +const id = 'er'; + +const detector: DiagramDetector = (txt) => { return txt.match(/^\s*erDiagram/) !== null; }; + +const loader = async () => { + const { diagram } = await import('./erDiagram'); + return { id, diagram }; +}; + +const plugin: ExternalDiagramDefinition = { + id, + detector, + loader, +}; + +export default plugin; diff --git a/packages/mermaid/src/diagrams/er/erDiagram.ts b/packages/mermaid/src/diagrams/er/erDiagram.ts new file mode 100644 index 000000000..a5b0da9c1 --- /dev/null +++ b/packages/mermaid/src/diagrams/er/erDiagram.ts @@ -0,0 +1,12 @@ +// @ts-ignore: TODO Fix ts errors +import erParser from './parser/erDiagram'; +import erDb from './erDb'; +import erRenderer from './erRenderer'; +import erStyles from './styles'; + +export const diagram = { + parser: erParser, + db: erDb, + renderer: erRenderer, + styles: erStyles, +}; From 38e5c3a81ea3c54b365b500f17573b1bea5e18a2 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Fri, 18 Nov 2022 16:09:56 +0530 Subject: [PATCH 05/67] chore(split): Gantt --- .../src/diagrams/gantt/ganttDetector.ts | 19 +++++++++++++++++-- .../src/diagrams/gantt/ganttDiagram.ts | 13 +++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 packages/mermaid/src/diagrams/gantt/ganttDiagram.ts diff --git a/packages/mermaid/src/diagrams/gantt/ganttDetector.ts b/packages/mermaid/src/diagrams/gantt/ganttDetector.ts index 5de167010..3fe2bbe7e 100644 --- a/packages/mermaid/src/diagrams/gantt/ganttDetector.ts +++ b/packages/mermaid/src/diagrams/gantt/ganttDetector.ts @@ -1,5 +1,20 @@ -import type { DiagramDetector } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; -export const ganttDetector: DiagramDetector = (txt) => { +const id = 'gantt'; + +const detector: DiagramDetector = (txt) => { return txt.match(/^\s*gantt/) !== null; }; + +const loader = async () => { + const { diagram } = await import('./ganttDiagram'); + return { id, diagram }; +}; + +const plugin: ExternalDiagramDefinition = { + id, + detector, + loader, +}; + +export default plugin; diff --git a/packages/mermaid/src/diagrams/gantt/ganttDiagram.ts b/packages/mermaid/src/diagrams/gantt/ganttDiagram.ts new file mode 100644 index 000000000..b1341052d --- /dev/null +++ b/packages/mermaid/src/diagrams/gantt/ganttDiagram.ts @@ -0,0 +1,13 @@ +// @ts-ignore: TODO Fix ts errors +import ganttParser from './parser/gantt'; +import ganttDb from './ganttDb'; +import ganttRenderer from './ganttRenderer'; +import ganttStyles from './styles'; +import { DiagramDefinition } from '../../diagram-api/types'; + +export const diagram: DiagramDefinition = { + parser: ganttParser, + db: ganttDb, + renderer: ganttRenderer, + styles: ganttStyles, +}; From 25bc381361a7d2e616bd7f4b8e535ec27c243e14 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Fri, 18 Nov 2022 16:10:06 +0530 Subject: [PATCH 06/67] chore(split): gitGraph --- .../src/diagrams/git/gitGraphDetector.ts | 18 +++++++++++++++++- .../src/diagrams/git/gitGraphDiagram.ts | 13 +++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 packages/mermaid/src/diagrams/git/gitGraphDiagram.ts diff --git a/packages/mermaid/src/diagrams/git/gitGraphDetector.ts b/packages/mermaid/src/diagrams/git/gitGraphDetector.ts index f890501a5..46d09c6e5 100644 --- a/packages/mermaid/src/diagrams/git/gitGraphDetector.ts +++ b/packages/mermaid/src/diagrams/git/gitGraphDetector.ts @@ -1,5 +1,21 @@ import type { DiagramDetector } from '../../diagram-api/types'; +import type { ExternalDiagramDefinition } from '../../diagram-api/types'; -export const gitGraphDetector: DiagramDetector = (txt) => { +const id = 'gitGraph'; + +const detector: DiagramDetector = (txt) => { return txt.match(/^\s*gitGraph/) !== null; }; + +const loader = async () => { + const { diagram } = await import('./gitGraphDiagram'); + return { id, diagram }; +}; + +const plugin: ExternalDiagramDefinition = { + id, + detector, + loader, +}; + +export default plugin; diff --git a/packages/mermaid/src/diagrams/git/gitGraphDiagram.ts b/packages/mermaid/src/diagrams/git/gitGraphDiagram.ts new file mode 100644 index 000000000..9ef3506a0 --- /dev/null +++ b/packages/mermaid/src/diagrams/git/gitGraphDiagram.ts @@ -0,0 +1,13 @@ +// @ts-ignore: TODO Fix ts errors +import gitGraphParser from './parser/gitGraph'; +import gitGraphDb from './gitGraphAst'; +import gitGraphRenderer from './gitGraphRenderer'; +import gitGraphStyles from './styles'; +import { DiagramDefinition } from '../../diagram-api/types'; + +export const diagram: DiagramDefinition = { + parser: gitGraphParser, + db: gitGraphDb, + renderer: gitGraphRenderer, + styles: gitGraphStyles, +}; From f03364f3287f3a0185eca59bc53069592593d4cb Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Fri, 18 Nov 2022 16:10:15 +0530 Subject: [PATCH 07/67] chore(split): Info --- .../mermaid/src/diagrams/info/infoDetector.ts | 19 +++++++++++++++++-- .../mermaid/src/diagrams/info/infoDiagram.ts | 13 +++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 packages/mermaid/src/diagrams/info/infoDiagram.ts diff --git a/packages/mermaid/src/diagrams/info/infoDetector.ts b/packages/mermaid/src/diagrams/info/infoDetector.ts index 8bccb578f..a022e3ccb 100644 --- a/packages/mermaid/src/diagrams/info/infoDetector.ts +++ b/packages/mermaid/src/diagrams/info/infoDetector.ts @@ -1,5 +1,20 @@ -import type { DiagramDetector } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; -export const infoDetector: DiagramDetector = (txt) => { +const id = 'info'; + +const detector: DiagramDetector = (txt) => { return txt.match(/^\s*info/) !== null; }; + +const loader = async () => { + const { diagram } = await import('./infoDiagram'); + return { id, diagram }; +}; + +const plugin: ExternalDiagramDefinition = { + id, + detector, + loader, +}; + +export default plugin; diff --git a/packages/mermaid/src/diagrams/info/infoDiagram.ts b/packages/mermaid/src/diagrams/info/infoDiagram.ts new file mode 100644 index 000000000..a8100a79f --- /dev/null +++ b/packages/mermaid/src/diagrams/info/infoDiagram.ts @@ -0,0 +1,13 @@ +import { DiagramDefinition } from '../../diagram-api/types'; +// @ts-ignore: TODO Fix ts errors +import parser from './parser/info'; +import db from './infoDb'; +import styles from './styles'; +import renderer from './infoRenderer'; + +export const diagram: DiagramDefinition = { + parser, + db, + renderer, + styles, +}; From e0cd76e6fd74491414319cd338756c8c8e9661d0 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Fri, 18 Nov 2022 16:10:25 +0530 Subject: [PATCH 08/67] chore(split): Pie --- .../mermaid/src/diagrams/pie/pieDetector.ts | 19 +++++++++++++++++-- .../mermaid/src/diagrams/pie/pieDiagram.ts | 13 +++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 packages/mermaid/src/diagrams/pie/pieDiagram.ts diff --git a/packages/mermaid/src/diagrams/pie/pieDetector.ts b/packages/mermaid/src/diagrams/pie/pieDetector.ts index 65a011c7a..dd1224db9 100644 --- a/packages/mermaid/src/diagrams/pie/pieDetector.ts +++ b/packages/mermaid/src/diagrams/pie/pieDetector.ts @@ -1,5 +1,20 @@ -import type { DiagramDetector } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; -export const pieDetector: DiagramDetector = (txt) => { +const id = 'pie'; + +const detector: DiagramDetector = (txt) => { return txt.match(/^\s*pie/) !== null; }; + +const loader = async () => { + const { diagram } = await import('./pieDiagram'); + return { id, diagram }; +}; + +const plugin: ExternalDiagramDefinition = { + id, + detector, + loader, +}; + +export default plugin; diff --git a/packages/mermaid/src/diagrams/pie/pieDiagram.ts b/packages/mermaid/src/diagrams/pie/pieDiagram.ts new file mode 100644 index 000000000..3a586f668 --- /dev/null +++ b/packages/mermaid/src/diagrams/pie/pieDiagram.ts @@ -0,0 +1,13 @@ +import { DiagramDefinition } from '../../diagram-api/types'; +// @ts-ignore: TODO Fix ts errors +import parser from './parser/pie'; +import db from './pieDb'; +import styles from './styles'; +import renderer from './pieRenderer'; + +export const diagram: DiagramDefinition = { + parser, + db, + renderer, + styles, +}; From 6d5a6ad0c844fa5a9a4cfac1da5eb315c940d653 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Fri, 18 Nov 2022 16:10:42 +0530 Subject: [PATCH 09/67] chore(split): Requirement --- .../requirement/requirementDetector.ts | 19 +++++++++++++++++-- .../requirement/requirementDiagram.ts | 13 +++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 packages/mermaid/src/diagrams/requirement/requirementDiagram.ts diff --git a/packages/mermaid/src/diagrams/requirement/requirementDetector.ts b/packages/mermaid/src/diagrams/requirement/requirementDetector.ts index 164da6c1a..1102fde0c 100644 --- a/packages/mermaid/src/diagrams/requirement/requirementDetector.ts +++ b/packages/mermaid/src/diagrams/requirement/requirementDetector.ts @@ -1,5 +1,20 @@ -import type { DiagramDetector } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; -export const requirementDetector: DiagramDetector = (txt) => { +const id = 'requirement'; + +const detector: DiagramDetector = (txt) => { return txt.match(/^\s*requirement(Diagram)?/) !== null; }; + +const loader = async () => { + const { diagram } = await import('./requirementDiagram'); + return { id, diagram }; +}; + +const plugin: ExternalDiagramDefinition = { + id, + detector, + loader, +}; + +export default plugin; diff --git a/packages/mermaid/src/diagrams/requirement/requirementDiagram.ts b/packages/mermaid/src/diagrams/requirement/requirementDiagram.ts new file mode 100644 index 000000000..37f6177b6 --- /dev/null +++ b/packages/mermaid/src/diagrams/requirement/requirementDiagram.ts @@ -0,0 +1,13 @@ +import { DiagramDefinition } from '../../diagram-api/types'; +// @ts-ignore: TODO Fix ts errors +import parser from './parser/requirementDiagram'; +import db from './requirementDb'; +import styles from './styles'; +import renderer from './requirementRenderer'; + +export const diagram: DiagramDefinition = { + parser, + db, + renderer, + styles, +}; From 4fd826ac8c73a659af31fd2acc630b07a2ff1f42 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Fri, 18 Nov 2022 16:10:51 +0530 Subject: [PATCH 10/67] chore(split): Sequence --- .../src/diagrams/sequence/sequenceDetector.ts | 19 +++++++++++++++++-- .../src/diagrams/sequence/sequenceDiagram.ts | 13 +++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 packages/mermaid/src/diagrams/sequence/sequenceDiagram.ts diff --git a/packages/mermaid/src/diagrams/sequence/sequenceDetector.ts b/packages/mermaid/src/diagrams/sequence/sequenceDetector.ts index 52640b134..c436e65d4 100644 --- a/packages/mermaid/src/diagrams/sequence/sequenceDetector.ts +++ b/packages/mermaid/src/diagrams/sequence/sequenceDetector.ts @@ -1,5 +1,20 @@ -import type { DiagramDetector } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; -export const sequenceDetector: DiagramDetector = (txt) => { +const id = 'sequence'; + +const detector: DiagramDetector = (txt) => { return txt.match(/^\s*sequenceDiagram/) !== null; }; + +const loader = async () => { + const { diagram } = await import('./sequenceDiagram'); + return { id, diagram }; +}; + +const plugin: ExternalDiagramDefinition = { + id, + detector, + loader, +}; + +export default plugin; diff --git a/packages/mermaid/src/diagrams/sequence/sequenceDiagram.ts b/packages/mermaid/src/diagrams/sequence/sequenceDiagram.ts new file mode 100644 index 000000000..fdec7f86d --- /dev/null +++ b/packages/mermaid/src/diagrams/sequence/sequenceDiagram.ts @@ -0,0 +1,13 @@ +import { DiagramDefinition } from '../../diagram-api/types'; +// @ts-ignore: TODO Fix ts errors +import parser from './parser/sequenceDiagram'; +import db from './sequenceDb'; +import styles from './styles'; +import renderer from './sequenceRenderer'; + +export const diagram: DiagramDefinition = { + parser, + db, + renderer, + styles, +}; From 616c969a0397a5289e1f64be63b54120a5aafe4a Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Fri, 18 Nov 2022 16:11:03 +0530 Subject: [PATCH 11/67] chore(split): Flow type --- packages/mermaid/src/diagrams/flowchart/flowDetector.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/mermaid/src/diagrams/flowchart/flowDetector.ts b/packages/mermaid/src/diagrams/flowchart/flowDetector.ts index 3d09f36ae..71e409331 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowDetector.ts +++ b/packages/mermaid/src/diagrams/flowchart/flowDetector.ts @@ -1,10 +1,9 @@ -import type { DiagramDetector } from '../../diagram-api/types'; -import type { ExternalDiagramDefinition } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; const id = 'flowchart'; const detector: DiagramDetector = (txt, config) => { - // If we have confired to only use new flow charts this function shohuld always return false + // If we have confirmed to only use new flow charts this function should always return false // as in not signalling true for a legacy flowchart if (config?.flowchart?.defaultRenderer === 'dagre-wrapper') return false; return txt.match(/^\s*graph/) !== null; From 89b5eb56f24fbcd90052679abe3c80fb4a4aa5bd Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Fri, 18 Nov 2022 16:11:19 +0530 Subject: [PATCH 12/67] chore(split): Orchestration --- .../src/diagram-api/diagram-orchestration.ts | 195 ++---------------- 1 file changed, 21 insertions(+), 174 deletions(-) diff --git a/packages/mermaid/src/diagram-api/diagram-orchestration.ts b/packages/mermaid/src/diagram-api/diagram-orchestration.ts index 88dfcffeb..69a01821a 100644 --- a/packages/mermaid/src/diagram-api/diagram-orchestration.ts +++ b/packages/mermaid/src/diagram-api/diagram-orchestration.ts @@ -2,64 +2,15 @@ import { registerDiagram } from './diagramAPI'; import c4 from '../diagrams/c4/c4Detector'; import flowchart from '../diagrams/flowchart/flowDetector'; import flowchartV2 from '../diagrams/flowchart/flowDetector-v2'; - -// @ts-ignore: TODO Fix ts errors -import gitGraphParser from '../diagrams/git/parser/gitGraph'; -import { gitGraphDetector } from '../diagrams/git/gitGraphDetector'; -import gitGraphDb from '../diagrams/git/gitGraphAst'; -import gitGraphRenderer from '../diagrams/git/gitGraphRenderer'; -import gitGraphStyles from '../diagrams/git/styles'; - -// @ts-ignore: TODO Fix ts errors -import classParser from '../diagrams/class/parser/classDiagram'; -import { classDetector } from '../diagrams/class/classDetector'; -import { classDetectorV2 } from '../diagrams/class/classDetector-V2'; -import classDb from '../diagrams/class/classDb'; -import classRenderer from '../diagrams/class/classRenderer'; -import classRendererV2 from '../diagrams/class/classRenderer-v2'; -import classStyles from '../diagrams/class/styles'; - -// @ts-ignore: TODO Fix ts errors -import erParser from '../diagrams/er/parser/erDiagram'; -import { erDetector } from '../diagrams/er/erDetector'; -import erDb from '../diagrams/er/erDb'; -import erRenderer from '../diagrams/er/erRenderer'; -import erStyles from '../diagrams/er/styles'; - -// @ts-ignore: TODO Fix ts errors -import ganttParser from '../diagrams/gantt/parser/gantt'; -import { ganttDetector } from '../diagrams/gantt/ganttDetector'; -import ganttDb from '../diagrams/gantt/ganttDb'; -import ganttRenderer from '../diagrams/gantt/ganttRenderer'; -import ganttStyles from '../diagrams/gantt/styles'; - -// @ts-ignore: TODO Fix ts errors -import infoParser from '../diagrams/info/parser/info'; -import infoDb from '../diagrams/info/infoDb'; -import infoRenderer from '../diagrams/info/infoRenderer'; -import { infoDetector } from '../diagrams/info/infoDetector'; -import infoStyles from '../diagrams/info/styles'; - -// @ts-ignore: TODO Fix ts errors -import pieParser from '../diagrams/pie/parser/pie'; -import { pieDetector } from '../diagrams/pie/pieDetector'; -import pieDb from '../diagrams/pie/pieDb'; -import pieRenderer from '../diagrams/pie/pieRenderer'; -import pieStyles from '../diagrams/pie/styles'; - -// @ts-ignore: TODO Fix ts errors -import requirementParser from '../diagrams/requirement/parser/requirementDiagram'; -import { requirementDetector } from '../diagrams/requirement/requirementDetector'; -import requirementDb from '../diagrams/requirement/requirementDb'; -import requirementRenderer from '../diagrams/requirement/requirementRenderer'; -import requirementStyles from '../diagrams/requirement/styles'; - -// @ts-ignore: TODO Fix ts errors -import sequenceParser from '../diagrams/sequence/parser/sequenceDiagram'; -import { sequenceDetector } from '../diagrams/sequence/sequenceDetector'; -import sequenceDb from '../diagrams/sequence/sequenceDb'; -import sequenceRenderer from '../diagrams/sequence/sequenceRenderer'; -import sequenceStyles from '../diagrams/sequence/styles'; +import er from '../diagrams/er/erDetector'; +import git from '../diagrams/git/gitGraphDetector'; +import gantt from '../diagrams/gantt/ganttDetector'; +import info from '../diagrams/info/infoDetector'; +import pie from '../diagrams/pie/pieDetector'; +import requirement from '../diagrams/requirement/requirementDetector'; +import sequence from '../diagrams/sequence/sequenceDetector'; +import classDiagram from '../diagrams/class/classDetector'; +import classDiagramV2 from '../diagrams/class/classDetector-V2'; // @ts-ignore: TODO Fix ts errors import stateParser from '../diagrams/state/parser/stateDiagram'; @@ -113,113 +64,18 @@ export const addDiagrams = () => { (text) => text.toLowerCase().trim() === 'error' ); addDiagram(c4); - registerDiagram( - 'class', - { - parser: classParser, - db: classDb, - renderer: classRenderer, - styles: classStyles, - init: (cnf) => { - if (!cnf.class) { - cnf.class = {}; - } - cnf.class.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute; - classDb.clear(); - }, - }, - classDetector - ); - registerDiagram( - 'classDiagram', - { - parser: classParser, - db: classDb, - renderer: classRendererV2, - styles: classStyles, - init: (cnf) => { - if (!cnf.class) { - cnf.class = {}; - } - cnf.class.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute; - classDb.clear(); - }, - }, - classDetectorV2 - ); - registerDiagram( - 'er', - { - parser: erParser, - db: erDb, - renderer: erRenderer, - styles: erStyles, - }, - erDetector - ); - registerDiagram( - 'gantt', - { - parser: ganttParser, - db: ganttDb, - renderer: ganttRenderer, - styles: ganttStyles, - }, - ganttDetector - ); - registerDiagram( - 'info', - { - parser: infoParser, - db: infoDb, - renderer: infoRenderer, - styles: infoStyles, - }, - infoDetector - ); - registerDiagram( - 'pie', - { - parser: pieParser, - db: pieDb, - renderer: pieRenderer, - styles: pieStyles, - }, - pieDetector - ); - registerDiagram( - 'requirement', - { - parser: requirementParser, - db: requirementDb, - renderer: requirementRenderer, - styles: requirementStyles, - }, - requirementDetector - ); - registerDiagram( - 'sequence', - { - parser: sequenceParser, - db: sequenceDb, - renderer: sequenceRenderer, - styles: sequenceStyles, - init: (cnf) => { - if (!cnf.sequence) { - cnf.sequence = {}; - } - cnf.sequence.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute; - if ('sequenceDiagram' in cnf) { - throw new Error( - '`mermaid config.sequenceDiagram` has been renamed to `config.sequence`. Please update your mermaid config.' - ); - } - sequenceDb.setWrap(cnf.wrap); - sequenceRenderer.setConf(cnf.sequence); - }, - }, - sequenceDetector - ); + addDiagram(classDiagram); + addDiagram(classDiagramV2); + addDiagram(er); + addDiagram(gantt); + addDiagram(info); + addDiagram(pie); + addDiagram(requirement); + addDiagram(sequence); + addDiagram(flowchart); + addDiagram(flowchartV2); + addDiagram(git); + registerDiagram( 'state', { @@ -268,13 +124,4 @@ export const addDiagrams = () => { }, journeyDetector ); - - addDiagram(flowchart); - addDiagram(flowchartV2); - - registerDiagram( - 'gitGraph', - { parser: gitGraphParser, db: gitGraphDb, renderer: gitGraphRenderer, styles: gitGraphStyles }, - gitGraphDetector - ); }; From e5768454f1c3f5284ba3066e9df32ff9820f2373 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Fri, 18 Nov 2022 16:19:38 +0530 Subject: [PATCH 13/67] chore(split): State Diagram --- .../src/diagram-api/diagram-orchestration.ts | 48 ++----------------- .../src/diagrams/state/stateDetector-V2.ts | 19 +++++++- .../src/diagrams/state/stateDetector.ts | 19 +++++++- .../src/diagrams/state/stateDiagram-v2.ts | 20 ++++++++ .../src/diagrams/state/stateDiagram.ts | 20 ++++++++ 5 files changed, 78 insertions(+), 48 deletions(-) create mode 100644 packages/mermaid/src/diagrams/state/stateDiagram-v2.ts create mode 100644 packages/mermaid/src/diagrams/state/stateDiagram.ts diff --git a/packages/mermaid/src/diagram-api/diagram-orchestration.ts b/packages/mermaid/src/diagram-api/diagram-orchestration.ts index 69a01821a..0f12a7ee7 100644 --- a/packages/mermaid/src/diagram-api/diagram-orchestration.ts +++ b/packages/mermaid/src/diagram-api/diagram-orchestration.ts @@ -11,15 +11,8 @@ import requirement from '../diagrams/requirement/requirementDetector'; import sequence from '../diagrams/sequence/sequenceDetector'; import classDiagram from '../diagrams/class/classDetector'; import classDiagramV2 from '../diagrams/class/classDetector-V2'; - -// @ts-ignore: TODO Fix ts errors -import stateParser from '../diagrams/state/parser/stateDiagram'; -import { stateDetector } from '../diagrams/state/stateDetector'; -import { stateDetectorV2 } from '../diagrams/state/stateDetector-V2'; -import stateDb from '../diagrams/state/stateDb'; -import stateRenderer from '../diagrams/state/stateRenderer'; -import stateRendererV2 from '../diagrams/state/stateRenderer-v2'; -import stateStyles from '../diagrams/state/styles'; +import state from '../diagrams/state/stateDetector'; +import stateV2 from '../diagrams/state/stateDetector-V2'; // @ts-ignore: TODO Fix ts errors import journeyParser from '../diagrams/user-journey/parser/journey'; @@ -75,41 +68,8 @@ export const addDiagrams = () => { addDiagram(flowchart); addDiagram(flowchartV2); addDiagram(git); - - registerDiagram( - 'state', - { - parser: stateParser, - db: stateDb, - renderer: stateRenderer, - styles: stateStyles, - init: (cnf) => { - if (!cnf.state) { - cnf.state = {}; - } - cnf.state.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute; - stateDb.clear(); - }, - }, - stateDetector - ); - registerDiagram( - 'stateDiagram', - { - parser: stateParser, - db: stateDb, - renderer: stateRendererV2, - styles: stateStyles, - init: (cnf) => { - if (!cnf.state) { - cnf.state = {}; - } - cnf.state.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute; - stateDb.clear(); - }, - }, - stateDetectorV2 - ); + addDiagram(state); + addDiagram(stateV2); registerDiagram( 'journey', { diff --git a/packages/mermaid/src/diagrams/state/stateDetector-V2.ts b/packages/mermaid/src/diagrams/state/stateDetector-V2.ts index 7fd9633c6..afc2e59fb 100644 --- a/packages/mermaid/src/diagrams/state/stateDetector-V2.ts +++ b/packages/mermaid/src/diagrams/state/stateDetector-V2.ts @@ -1,8 +1,23 @@ -import type { DiagramDetector } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; -export const stateDetectorV2: DiagramDetector = (text, config) => { +const id = 'stateDiagram'; + +const detector: DiagramDetector = (text, config) => { if (text.match(/^\s*stateDiagram-v2/) !== null) return true; if (text.match(/^\s*stateDiagram/) && config?.state?.defaultRenderer === 'dagre-wrapper') return true; return false; }; + +const loader = async () => { + const { diagram } = await import('./stateDiagram-v2'); + return { id, diagram }; +}; + +const plugin: ExternalDiagramDefinition = { + id, + detector, + loader, +}; + +export default plugin; diff --git a/packages/mermaid/src/diagrams/state/stateDetector.ts b/packages/mermaid/src/diagrams/state/stateDetector.ts index 614f327c2..89d6e45bf 100644 --- a/packages/mermaid/src/diagrams/state/stateDetector.ts +++ b/packages/mermaid/src/diagrams/state/stateDetector.ts @@ -1,8 +1,23 @@ -import type { DiagramDetector } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; -export const stateDetector: DiagramDetector = (txt, config) => { +const id = 'state'; + +const detector: DiagramDetector = (txt, config) => { // If we have confired to only use new state diagrams this function should always return false // as in not signalling true for a legacy state diagram if (config?.state?.defaultRenderer === 'dagre-wrapper') return false; return txt.match(/^\s*stateDiagram/) !== null; }; + +const loader = async () => { + const { diagram } = await import('./stateDiagram'); + return { id, diagram }; +}; + +const plugin: ExternalDiagramDefinition = { + id, + detector, + loader, +}; + +export default plugin; diff --git a/packages/mermaid/src/diagrams/state/stateDiagram-v2.ts b/packages/mermaid/src/diagrams/state/stateDiagram-v2.ts new file mode 100644 index 000000000..f7ee4f052 --- /dev/null +++ b/packages/mermaid/src/diagrams/state/stateDiagram-v2.ts @@ -0,0 +1,20 @@ +import { DiagramDefinition } from '../../diagram-api/types'; +// @ts-ignore: TODO Fix ts errors +import parser from './parser/stateDiagram'; +import db from './stateDb'; +import styles from './styles'; +import renderer from './stateRenderer-v2'; + +export const diagram: DiagramDefinition = { + parser, + db, + renderer, + styles, + init: (cnf) => { + if (!cnf.state) { + cnf.state = {}; + } + cnf.state.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute; + db.clear(); + }, +}; diff --git a/packages/mermaid/src/diagrams/state/stateDiagram.ts b/packages/mermaid/src/diagrams/state/stateDiagram.ts new file mode 100644 index 000000000..570d599de --- /dev/null +++ b/packages/mermaid/src/diagrams/state/stateDiagram.ts @@ -0,0 +1,20 @@ +import { DiagramDefinition } from '../../diagram-api/types'; +// @ts-ignore: TODO Fix ts errors +import parser from './parser/stateDiagram'; +import db from './stateDb'; +import styles from './styles'; +import renderer from './stateRenderer'; + +export const diagram: DiagramDefinition = { + parser, + db, + renderer, + styles, + init: (cnf) => { + if (!cnf.state) { + cnf.state = {}; + } + cnf.state.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute; + db.clear(); + }, +}; From 0b4c6f647755ff681fdc04d626bfb91ca544ceef Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Fri, 18 Nov 2022 16:22:38 +0530 Subject: [PATCH 14/67] chore(split): Journey --- .../src/diagram-api/diagram-orchestration.ts | 23 ++----------------- .../diagrams/user-journey/journeyDetector.ts | 19 +++++++++++++-- .../diagrams/user-journey/journeyDiagram.ts | 17 ++++++++++++++ 3 files changed, 36 insertions(+), 23 deletions(-) create mode 100644 packages/mermaid/src/diagrams/user-journey/journeyDiagram.ts diff --git a/packages/mermaid/src/diagram-api/diagram-orchestration.ts b/packages/mermaid/src/diagram-api/diagram-orchestration.ts index 0f12a7ee7..eed4269f6 100644 --- a/packages/mermaid/src/diagram-api/diagram-orchestration.ts +++ b/packages/mermaid/src/diagram-api/diagram-orchestration.ts @@ -13,13 +13,7 @@ import classDiagram from '../diagrams/class/classDetector'; import classDiagramV2 from '../diagrams/class/classDetector-V2'; import state from '../diagrams/state/stateDetector'; import stateV2 from '../diagrams/state/stateDetector-V2'; - -// @ts-ignore: TODO Fix ts errors -import journeyParser from '../diagrams/user-journey/parser/journey'; -import { journeyDetector } from '../diagrams/user-journey/journeyDetector'; -import journeyDb from '../diagrams/user-journey/journeyDb'; -import journeyRenderer from '../diagrams/user-journey/journeyRenderer'; -import journeyStyles from '../diagrams/user-journey/styles'; +import journey from '../diagrams/user-journey/journeyDetector'; import errorRenderer from '../diagrams/error/errorRenderer'; import errorStyles from '../diagrams/error/styles'; @@ -70,18 +64,5 @@ export const addDiagrams = () => { addDiagram(git); addDiagram(state); addDiagram(stateV2); - registerDiagram( - 'journey', - { - parser: journeyParser, - db: journeyDb, - renderer: journeyRenderer, - styles: journeyStyles, - init: (cnf) => { - journeyRenderer.setConf(cnf.journey); - journeyDb.clear(); - }, - }, - journeyDetector - ); + addDiagram(journey); }; diff --git a/packages/mermaid/src/diagrams/user-journey/journeyDetector.ts b/packages/mermaid/src/diagrams/user-journey/journeyDetector.ts index 535e7be9d..90b2fd6e1 100644 --- a/packages/mermaid/src/diagrams/user-journey/journeyDetector.ts +++ b/packages/mermaid/src/diagrams/user-journey/journeyDetector.ts @@ -1,5 +1,20 @@ -import type { DiagramDetector } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; -export const journeyDetector: DiagramDetector = (txt) => { +const id = 'journey'; + +const detector: DiagramDetector = (txt) => { return txt.match(/^\s*journey/) !== null; }; + +const loader = async () => { + const { diagram } = await import('./journeyDiagram'); + return { id, diagram }; +}; + +const plugin: ExternalDiagramDefinition = { + id, + detector, + loader, +}; + +export default plugin; diff --git a/packages/mermaid/src/diagrams/user-journey/journeyDiagram.ts b/packages/mermaid/src/diagrams/user-journey/journeyDiagram.ts new file mode 100644 index 000000000..c3a2a3c6b --- /dev/null +++ b/packages/mermaid/src/diagrams/user-journey/journeyDiagram.ts @@ -0,0 +1,17 @@ +import { DiagramDefinition } from '../../diagram-api/types'; +// @ts-ignore: TODO Fix ts errors +import parser from './parser/journey'; +import db from './journeyDb'; +import styles from './styles'; +import renderer from './journeyRenderer'; + +export const diagram: DiagramDefinition = { + parser, + db, + renderer, + styles, + init: (cnf) => { + renderer.setConf(cnf.journey); + db.clear(); + }, +}; From fa51121f29e0dbcb41744b454429cbe6d1f1bfe1 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Fri, 18 Nov 2022 16:30:54 +0530 Subject: [PATCH 15/67] chore(split): Error --- .../src/diagram-api/diagram-orchestration.ts | 29 ++----------------- .../src/diagrams/error/errorDetector.ts | 20 +++++++++++++ .../src/diagrams/error/errorDiagram.ts | 21 ++++++++++++++ 3 files changed, 43 insertions(+), 27 deletions(-) create mode 100644 packages/mermaid/src/diagrams/error/errorDetector.ts create mode 100644 packages/mermaid/src/diagrams/error/errorDiagram.ts diff --git a/packages/mermaid/src/diagram-api/diagram-orchestration.ts b/packages/mermaid/src/diagram-api/diagram-orchestration.ts index eed4269f6..64a7e5ad8 100644 --- a/packages/mermaid/src/diagram-api/diagram-orchestration.ts +++ b/packages/mermaid/src/diagram-api/diagram-orchestration.ts @@ -1,4 +1,3 @@ -import { registerDiagram } from './diagramAPI'; import c4 from '../diagrams/c4/c4Detector'; import flowchart from '../diagrams/flowchart/flowDetector'; import flowchartV2 from '../diagrams/flowchart/flowDetector-v2'; @@ -14,9 +13,7 @@ import classDiagramV2 from '../diagrams/class/classDetector-V2'; import state from '../diagrams/state/stateDetector'; import stateV2 from '../diagrams/state/stateDetector-V2'; import journey from '../diagrams/user-journey/journeyDetector'; - -import errorRenderer from '../diagrams/error/errorRenderer'; -import errorStyles from '../diagrams/error/styles'; +import error from '../diagrams/error/errorDetector'; import { addDiagram } from './detectType'; let hasLoadedDiagrams = false; @@ -27,29 +24,7 @@ export const addDiagrams = () => { // This is added here to avoid race-conditions. // We could optimize the loading logic somehow. hasLoadedDiagrams = true; - registerDiagram( - 'error', - // Special diagram with error messages but setup as a regular diagram - { - db: { - clear: () => { - // Quite ok, clear needs to be there for error to work as a regular diagram - }, - }, - styles: errorStyles, - renderer: errorRenderer, - parser: { - parser: { yy: {} }, - parse: () => { - // no op - }, - }, - init: () => { - // no op - }, - }, - (text) => text.toLowerCase().trim() === 'error' - ); + addDiagram(error); addDiagram(c4); addDiagram(classDiagram); addDiagram(classDiagramV2); diff --git a/packages/mermaid/src/diagrams/error/errorDetector.ts b/packages/mermaid/src/diagrams/error/errorDetector.ts new file mode 100644 index 000000000..2bdcd7028 --- /dev/null +++ b/packages/mermaid/src/diagrams/error/errorDetector.ts @@ -0,0 +1,20 @@ +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; + +const id = 'error'; + +const detector: DiagramDetector = (text) => { + return text.toLowerCase().trim() === 'error'; +}; + +const loader = async () => { + const { diagram } = await import('./errorDiagram'); + return { id, diagram }; +}; + +const plugin: ExternalDiagramDefinition = { + id, + detector, + loader, +}; + +export default plugin; diff --git a/packages/mermaid/src/diagrams/error/errorDiagram.ts b/packages/mermaid/src/diagrams/error/errorDiagram.ts new file mode 100644 index 000000000..d081e1028 --- /dev/null +++ b/packages/mermaid/src/diagrams/error/errorDiagram.ts @@ -0,0 +1,21 @@ +import { DiagramDefinition } from '../../diagram-api/types'; +import styles from './styles'; +import renderer from './errorRenderer'; +export const diagram: DiagramDefinition = { + db: { + clear: () => { + // Quite ok, clear needs to be there for error to work as a regular diagram + }, + }, + styles, + renderer, + parser: { + parser: { yy: {} }, + parse: () => { + // no op + }, + }, + init: () => { + // no op + }, +}; From 0854bab12415d5842b7c5b5a950a43c3202407e8 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Fri, 18 Nov 2022 16:51:50 +0530 Subject: [PATCH 16/67] fix: Remove diagram dependency from mermaidAPI --- packages/mermaid/src/mermaid.ts | 9 +-------- packages/mermaid/src/mermaidAPI.ts | 22 +++++----------------- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/packages/mermaid/src/mermaid.ts b/packages/mermaid/src/mermaid.ts index ac8872ef6..3a8da77ad 100644 --- a/packages/mermaid/src/mermaid.ts +++ b/packages/mermaid/src/mermaid.ts @@ -13,7 +13,6 @@ import { ExternalDiagramDefinition } from './diagram-api/types'; export type { MermaidConfig, DetailedError, ExternalDiagramDefinition }; -let externalDiagramsRegistered = false; /** * ## init * @@ -50,12 +49,7 @@ const init = async function ( callback?: Function ) { try { - // Not really sure if we need to check this, or simply call initThrowsErrorsAsync directly. - if (externalDiagramsRegistered) { - await initThrowsErrorsAsync(config, nodes, callback); - } else { - initThrowsErrors(config, nodes, callback); - } + await initThrowsErrorsAsync(config, nodes, callback); } catch (e) { log.warn('Syntax Error rendering'); if (isDetailedError(e)) { @@ -343,7 +337,6 @@ const registerExternalDiagrams = async ( } else { await loadExternalDiagrams(diagrams); } - externalDiagramsRegistered = true; }; /** diff --git a/packages/mermaid/src/mermaidAPI.ts b/packages/mermaid/src/mermaidAPI.ts index faba5fef8..986d0b157 100644 --- a/packages/mermaid/src/mermaidAPI.ts +++ b/packages/mermaid/src/mermaidAPI.ts @@ -18,12 +18,7 @@ import { compile, serialize, stringify } from 'stylis'; import pkg from '../package.json'; import * as configApi from './config'; import { addDiagrams } from './diagram-api/diagram-orchestration'; -import classDb from './diagrams/class/classDb'; -import flowDb from './diagrams/flowchart/flowDb'; -import flowRenderer from './diagrams/flowchart/flowRenderer'; -import ganttDb from './diagrams/gantt/ganttDb'; import Diagram, { getDiagramFromText } from './Diagram'; -import errorRenderer from './diagrams/error/errorRenderer'; import { attachFunctions } from './interactionDb'; import { log, setLogLevel } from './logger'; import getStyles from './styles'; @@ -32,6 +27,7 @@ import utils, { directiveSanitizer } from './utils'; import DOMPurify from 'dompurify'; import { MermaidConfig } from './config.type'; import { evaluate } from './diagrams/common/common'; +import errorRenderer from './diagrams/error/errorRenderer'; /** * @param text @@ -271,7 +267,7 @@ const render = function ( // classDef if (graphType === 'flowchart' || graphType === 'flowchart-v2' || graphType === 'graph') { - const classes: any = flowRenderer.getClasses(text, diag); + const classes: any = diag.renderer.getClasses(text, diag); const htmlLabels = cnf.htmlLabels || cnf.flowchart?.htmlLabels; for (const className in classes) { if (htmlLabels) { @@ -364,14 +360,10 @@ const render = function ( switch (graphType) { case 'flowchart': case 'flowchart-v2': - cb(svgCode, flowDb.bindFunctions); - break; case 'gantt': - cb(svgCode, ganttDb.bindFunctions); - break; case 'class': case 'classDiagram': - cb(svgCode, classDb.bindFunctions); + cb(svgCode, diag.db.bindFunctions); break; default: cb(svgCode); @@ -544,7 +536,7 @@ const renderAsync = async function ( // classDef if (graphType === 'flowchart' || graphType === 'flowchart-v2' || graphType === 'graph') { - const classes: any = flowRenderer.getClasses(text, diag); + const classes: any = diag.renderer.getClasses(text, diag); const htmlLabels = cnf.htmlLabels || cnf.flowchart?.htmlLabels; for (const className in classes) { if (htmlLabels) { @@ -637,14 +629,10 @@ const renderAsync = async function ( switch (graphType) { case 'flowchart': case 'flowchart-v2': - cb(svgCode, flowDb.bindFunctions); - break; case 'gantt': - cb(svgCode, ganttDb.bindFunctions); - break; case 'class': case 'classDiagram': - cb(svgCode, classDb.bindFunctions); + cb(svgCode, diag.db.bindFunctions); break; default: cb(svgCode); From 7306b5ac4587197daa88a9c11634cb97d498fbd6 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Fri, 18 Nov 2022 17:52:55 +0530 Subject: [PATCH 17/67] feat: Add size inspection plugin --- .vite/build.ts | 5 +- package.json | 1 + packages/mermaid/package.json | 4 +- .../flowchart/parser/flow-direction.spec.js | 2 +- .../flowchart/parser/subgraph.spec.js | 2 +- packages/mermaid/src/utils.spec.js | 2 +- packages/mermaid/src/utils.ts | 2 +- pnpm-lock.yaml | 130 ++++++++++-------- vdocs/.vitepress/config.ts | 1 - 9 files changed, 82 insertions(+), 67 deletions(-) diff --git a/.vite/build.ts b/.vite/build.ts index 2b686b765..d9c8ffe30 100644 --- a/.vite/build.ts +++ b/.vite/build.ts @@ -1,8 +1,9 @@ -import { build, InlineConfig } from 'vite'; +import { build, InlineConfig, type PluginOption } from 'vite'; import { resolve } from 'path'; import { fileURLToPath } from 'url'; import jisonPlugin from './jisonPlugin.js'; import { readFileSync } from 'fs'; +import { visualizer } from 'rollup-plugin-visualizer'; const watch = process.argv.includes('--watch'); const mermaidOnly = process.argv.includes('--mermaid'); @@ -95,7 +96,7 @@ export const getBuildConfig = ({ minify, core, watch, entryName }: BuildOptions) resolve: { extensions: ['.jison', '.js', '.ts', '.json'], }, - plugins: [jisonPlugin()], + plugins: [jisonPlugin(), visualizer({ template: 'network' }) as PluginOption], }; if (watch && config.build) { diff --git a/package.json b/package.json index ce5b12ce4..c30973985 100644 --- a/package.json +++ b/package.json @@ -107,6 +107,7 @@ "prettier-plugin-jsdoc": "^0.4.2", "remark": "^14.0.2", "rimraf": "^3.0.2", + "rollup-plugin-visualizer": "^5.8.3", "start-server-and-test": "^1.14.0", "ts-node": "^10.9.1", "typescript": "^4.8.4", diff --git a/packages/mermaid/package.json b/packages/mermaid/package.json index f8ff46325..a8f8ed371 100644 --- a/packages/mermaid/package.json +++ b/packages/mermaid/package.json @@ -55,7 +55,7 @@ "fast-clone": "^1.5.13", "graphlib": "^2.1.8", "khroma": "^2.0.0", - "lodash": "^4.17.21", + "lodash-es": "^4.17.21", "moment-mini": "^2.24.0", "non-layered-tidy-tree-layout": "^2.0.2", "stylis": "^4.1.2", @@ -70,7 +70,7 @@ "@types/eslint": "^8.4.6", "@types/express": "^4.17.13", "@types/jsdom": "^20.0.0", - "@types/lodash": "^4.14.185", + "@types/lodash-es": "^4.17.6", "@types/prettier": "^2.7.0", "@types/stylis": "^4.0.2", "@types/uuid": "^8.3.4", diff --git a/packages/mermaid/src/diagrams/flowchart/parser/flow-direction.spec.js b/packages/mermaid/src/diagrams/flowchart/parser/flow-direction.spec.js index a56184f11..d6a41d15f 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/flow-direction.spec.js +++ b/packages/mermaid/src/diagrams/flowchart/parser/flow-direction.spec.js @@ -1,6 +1,6 @@ import flowDb from '../flowDb'; import flow from './flow'; -import filter from 'lodash/filter'; +import filter from 'lodash-es/filter'; import { setConfig } from '../../../config'; // import DOMPurify from 'dompurify'; diff --git a/packages/mermaid/src/diagrams/flowchart/parser/subgraph.spec.js b/packages/mermaid/src/diagrams/flowchart/parser/subgraph.spec.js index aa8e9217f..6fec233e7 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/subgraph.spec.js +++ b/packages/mermaid/src/diagrams/flowchart/parser/subgraph.spec.js @@ -1,6 +1,6 @@ import flowDb from '../flowDb'; import flow from './flow'; -import filter from 'lodash/filter'; +import filter from 'lodash-es/filter'; import { setConfig } from '../../../config'; setConfig({ diff --git a/packages/mermaid/src/utils.spec.js b/packages/mermaid/src/utils.spec.js index 4a511b3c0..ca2dfeab9 100644 --- a/packages/mermaid/src/utils.spec.js +++ b/packages/mermaid/src/utils.spec.js @@ -3,7 +3,7 @@ import utils from './utils'; import assignWithDepth from './assignWithDepth'; import { detectType } from './diagram-api/detectType'; import { addDiagrams } from './diagram-api/diagram-orchestration'; -import memoize from 'lodash/memoize'; +import memoize from 'lodash-es/memoize'; addDiagrams(); describe('when assignWithDepth: should merge objects within objects', function () { diff --git a/packages/mermaid/src/utils.ts b/packages/mermaid/src/utils.ts index f969ecc62..a6a9c2577 100644 --- a/packages/mermaid/src/utils.ts +++ b/packages/mermaid/src/utils.ts @@ -20,7 +20,7 @@ import { log } from './logger'; import { detectType } from './diagram-api/detectType'; import assignWithDepth from './assignWithDepth'; import { MermaidConfig } from './config.type'; -import memoize from 'lodash/memoize'; +import memoize from 'lodash-es/memoize'; // Effectively an enum of the supported curve types, accessible by name const d3CurveTypes = { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index de2066b8d..1142c0722 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -145,6 +145,9 @@ importers: rimraf: specifier: ^3.0.2 version: 3.0.2 + rollup-plugin-visualizer: + specifier: ^5.8.3 + version: 5.8.3_rollup@2.79.1 start-server-and-test: specifier: ^1.14.0 version: 1.14.0 @@ -165,7 +168,7 @@ importers: version: 1.0.0-alpha.28_ysryt2e75uhznkanan6iyjk4mi vitepress-plugin-mermaid: specifier: ^2.0.8 - version: 2.0.8_2q5vfj2vm6nj3r62ddjdsi7aoe + version: 2.0.8_qntmym4r3eiuu4ikfhr4jvwbjq vitepress-plugin-search: specifier: ^1.0.4-alpha.11 version: 1.0.4-alpha.15_pb3anlaclwt5smse4ujf447uy4 @@ -199,7 +202,7 @@ importers: khroma: specifier: ^2.0.0 version: 2.0.0 - lodash: + lodash-es: specifier: ^4.17.21 version: 4.17.21 moment-mini: @@ -239,9 +242,9 @@ importers: '@types/jsdom': specifier: ^20.0.0 version: 20.0.0 - '@types/lodash': - specifier: ^4.14.185 - version: 4.14.185 + '@types/lodash-es': + specifier: ^4.17.6 + version: 4.17.6 '@types/prettier': specifier: ^2.7.0 version: 2.7.0 @@ -2675,7 +2678,6 @@ packages: /@braintree/sanitize-url/6.0.0: resolution: {integrity: sha512-mgmE7XBYY/21erpzhexk4Cj1cyTQ9LzvnTxtzM17BJ7ERMNE6W72mQRo0I1Ud8eFJ+RVVIcBNhLFZ3GX4XFz5w==} - dev: false /@colors/colors/1.5.0: resolution: {integrity: sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==} @@ -3930,8 +3932,10 @@ packages: resolution: {integrity: sha512-HZQYqbiFVWufzCwexrvh694SOim8z2d+xJl5UNamcvQFejLY/2YUtzXHYi3cHdI7PMlS8ejH2slRAOJQ32aNbA==} dev: true - /@types/lodash/4.14.185: - resolution: {integrity: sha512-evMDG1bC4rgQg4ku9tKpuMh5iBNEwNa3tf9zRHdP1qlv+1WUg44xat4IxCE14gIpZRGUUWAx2VhItCZc25NfMA==} + /@types/lodash-es/4.17.6: + resolution: {integrity: sha512-R+zTeVUKDdfoRxpAryaQNRKk3105Rrgx2CFRClIgRGaqDTdjsm8h6IYA8ir584W3ePzkZfst5xIgDwYrlh9HLg==} + dependencies: + '@types/lodash': 4.14.188 dev: true /@types/lodash/4.14.188: @@ -5176,7 +5180,7 @@ packages: /axios/0.21.4_debug@4.3.2: resolution: {integrity: sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==} dependencies: - follow-redirects: 1.15.2 + follow-redirects: 1.15.2_debug@4.3.2 transitivePeerDependencies: - debug dev: true @@ -5184,7 +5188,7 @@ packages: /axios/0.26.0: resolution: {integrity: sha512-lKoGLMYtHvFrPVt3r+RBMp9nh34N0M8zEfCWqdWZx6phynIEhQqAdydpyBAAG211zlhX9Rgu08cOamy6XjE5Og==} dependencies: - follow-redirects: 1.15.2 + follow-redirects: 1.15.2_debug@4.3.2 transitivePeerDependencies: - debug dev: true @@ -6519,12 +6523,10 @@ packages: engines: {node: '>=12'} dependencies: internmap: 2.0.3 - dev: false /d3-axis/3.0.0: resolution: {integrity: sha512-IH5tgjV4jE/GhHkRV0HiVYPDtvfjHQlQfJHs0usq7M30XcSBvOotpmH1IgkcXsO/5gEQZD43B//fc7SRT5S+xw==} engines: {node: '>=12'} - dev: false /d3-brush/3.0.0: resolution: {integrity: sha512-ALnjWlVYkXsVIGlOsuWH1+3udkYFI48Ljihfnh8FZPF2QS9o+PzGLBslO0PjzVoHLZ2KCVgAM8NVkXPJB2aNnQ==} @@ -6535,38 +6537,32 @@ packages: d3-interpolate: 3.0.1 d3-selection: 3.0.0 d3-transition: 3.0.1_d3-selection@3.0.0 - dev: false /d3-chord/3.0.1: resolution: {integrity: sha512-VE5S6TNa+j8msksl7HwjxMHDM2yNK3XCkusIlpX5kwauBfXuyLAtNg9jCp/iHH61tgI4sb6R/EIMWCqEIdjT/g==} engines: {node: '>=12'} dependencies: d3-path: 3.0.1 - dev: false /d3-color/3.1.0: resolution: {integrity: sha512-zg/chbXyeBtMQ1LbD/WSoW2DpC3I0mpmPdW+ynRTj/x2DAWYrIY7qeZIHidozwV24m4iavr15lNwIwLxRmOxhA==} engines: {node: '>=12'} - dev: false /d3-contour/4.0.0: resolution: {integrity: sha512-7aQo0QHUTu/Ko3cP9YK9yUTxtoDEiDGwnBHyLxG5M4vqlBkO/uixMRele3nfsfj6UXOcuReVpVXzAboGraYIJw==} engines: {node: '>=12'} dependencies: d3-array: 3.2.0 - dev: false /d3-delaunay/6.0.2: resolution: {integrity: sha512-IMLNldruDQScrcfT+MWnazhHbDJhcRJyOEBAJfwQnHle1RPh6WDuLvxNArUju2VSMSUuKlY5BGHRJ2cYyoFLQQ==} engines: {node: '>=12'} dependencies: delaunator: 5.0.0 - dev: false /d3-dispatch/3.0.1: resolution: {integrity: sha512-rzUyPU/S7rwUflMyLc1ETDeBj0NRuHKKAcvukozwhshr6g6c5d8zh4c2gQjY2bZ0dXeGLWc1PF174P2tVvKhfg==} engines: {node: '>=12'} - dev: false /d3-drag/3.0.0: resolution: {integrity: sha512-pWbUJLdETVA8lQNJecMxoXfH6x+mO2UQo8rSmZ+QqxcbyA3hfeprFgIT//HW2nlHChWeIIMwS2Fq+gEARkhTkg==} @@ -6574,7 +6570,6 @@ packages: dependencies: d3-dispatch: 3.0.1 d3-selection: 3.0.0 - dev: false /d3-dsv/3.0.1: resolution: {integrity: sha512-UG6OvdI5afDIFP9w4G0mNq50dSOsXHJaRE8arAS5o9ApWnIElp8GZw1Dun8vP8OyHOZ/QJUKUJwxiiCCnUwm+Q==} @@ -6584,19 +6579,16 @@ packages: commander: 7.2.0 iconv-lite: 0.6.3 rw: 1.3.3 - dev: false /d3-ease/3.0.1: resolution: {integrity: sha512-wR/XK3D3XcLIZwpbvQwQ5fK+8Ykds1ip7A2Txe0yxncXSdq1L9skcG7blcedkOX+ZcgxGAmLX1FrRGbADwzi0w==} engines: {node: '>=12'} - dev: false /d3-fetch/3.0.1: resolution: {integrity: sha512-kpkQIM20n3oLVBKGg6oHrUchHM3xODkTzjMoj7aWQFq5QEM+R6E4WkzT5+tojDY7yjez8KgCBRoj4aEr99Fdqw==} engines: {node: '>=12'} dependencies: d3-dsv: 3.0.1 - dev: false /d3-force/3.0.0: resolution: {integrity: sha512-zxV/SsA+U4yte8051P4ECydjD/S+qeYtnaIyAs9tgHCqfguma/aAQDjo85A9Z6EKhBirHRJHXIgJUlffT4wdLg==} @@ -6605,51 +6597,42 @@ packages: d3-dispatch: 3.0.1 d3-quadtree: 3.0.1 d3-timer: 3.0.1 - dev: false /d3-format/3.1.0: resolution: {integrity: sha512-YyUI6AEuY/Wpt8KWLgZHsIU86atmikuoOmCfommt0LYHiQSPjvX2AcFc38PX0CBpr2RCyZhjex+NS/LPOv6YqA==} engines: {node: '>=12'} - dev: false /d3-geo/3.0.1: resolution: {integrity: sha512-Wt23xBych5tSy9IYAM1FR2rWIBFWa52B/oF/GYe5zbdHrg08FU8+BuI6X4PvTwPDdqdAdq04fuWJpELtsaEjeA==} engines: {node: '>=12'} dependencies: d3-array: 3.2.0 - dev: false /d3-hierarchy/3.1.2: resolution: {integrity: sha512-FX/9frcub54beBdugHjDCdikxThEqjnR93Qt7PvQTOHxyiNCAlvMrHhclk3cD5VeAaq9fxmfRp+CnWw9rEMBuA==} engines: {node: '>=12'} - dev: false /d3-interpolate/3.0.1: resolution: {integrity: sha512-3bYs1rOD33uo8aqJfKP3JWPAibgw8Zm2+L9vBKEHJ2Rg+viTR7o5Mmv5mZcieN+FRYaAOWX5SJATX6k1PWz72g==} engines: {node: '>=12'} dependencies: d3-color: 3.1.0 - dev: false /d3-path/3.0.1: resolution: {integrity: sha512-gq6gZom9AFZby0YLduxT1qmrp4xpBA1YZr19OI717WIdKE2OM5ETq5qrHLb301IgxhLwcuxvGZVLeeWc/k1I6w==} engines: {node: '>=12'} - dev: false /d3-polygon/3.0.1: resolution: {integrity: sha512-3vbA7vXYwfe1SYhED++fPUQlWSYTTGmFmQiany/gdbiWgU/iEyQzyymwL9SkJjFFuCS4902BSzewVGsHHmHtXg==} engines: {node: '>=12'} - dev: false /d3-quadtree/3.0.1: resolution: {integrity: sha512-04xDrxQTDTCFwP5H6hRhsRcb9xxv2RzkcsygFzmkSIOJy3PeRJP7sNk3VRIbKXcog561P9oU0/rVH6vDROAgUw==} engines: {node: '>=12'} - dev: false /d3-random/3.0.1: resolution: {integrity: sha512-FXMe9GfxTxqd5D6jFsQ+DJ8BJS4E/fT5mqqdjovykEB2oFbTMDVdg1MGFxfQW+FBOGoB++k8swBrgwSHT1cUXQ==} engines: {node: '>=12'} - dev: false /d3-scale-chromatic/3.0.0: resolution: {integrity: sha512-Lx9thtxAKrO2Pq6OO2Ua474opeziKr279P/TKZsMAhYyNDD3EnCffdbgeSYN5O7m2ByQsxtuP2CSDczNUIZ22g==} @@ -6657,7 +6640,6 @@ packages: dependencies: d3-color: 3.1.0 d3-interpolate: 3.0.1 - dev: false /d3-scale/4.0.2: resolution: {integrity: sha512-GZW464g1SH7ag3Y7hXjf8RoUuAFIqklOAq3MRl4OaWabTFJY9PN/E1YklhXLh+OQ3fM9yS2nOkCoS+WLZ6kvxQ==} @@ -6668,38 +6650,32 @@ packages: d3-interpolate: 3.0.1 d3-time: 3.0.0 d3-time-format: 4.1.0 - dev: false /d3-selection/3.0.0: resolution: {integrity: sha512-fmTRWbNMmsmWq6xJV8D19U/gw/bwrHfNXxrIN+HfZgnzqTHp9jOmKMhsTUjXOJnZOdZY9Q28y4yebKzqDKlxlQ==} engines: {node: '>=12'} - dev: false /d3-shape/3.1.0: resolution: {integrity: sha512-tGDh1Muf8kWjEDT/LswZJ8WF85yDZLvVJpYU9Nq+8+yW1Z5enxrmXOhTArlkaElU+CTn0OTVNli+/i+HP45QEQ==} engines: {node: '>=12'} dependencies: d3-path: 3.0.1 - dev: false /d3-time-format/4.1.0: resolution: {integrity: sha512-dJxPBlzC7NugB2PDLwo9Q8JiTR3M3e4/XANkreKSUxF8vvXKqm1Yfq4Q5dl8budlunRVlUUaDUgFt7eA8D6NLg==} engines: {node: '>=12'} dependencies: d3-time: 3.0.0 - dev: false /d3-time/3.0.0: resolution: {integrity: sha512-zmV3lRnlaLI08y9IMRXSDshQb5Nj77smnfpnd2LrBa/2K281Jijactokeak14QacHs/kKq0AQ121nidNYlarbQ==} engines: {node: '>=12'} dependencies: d3-array: 3.2.0 - dev: false /d3-timer/3.0.1: resolution: {integrity: sha512-ndfJ/JxxMd3nw31uyKoY2naivF+r29V+Lc0svZxe1JvvIRmi8hUsrMvdOwgS1o6uBHmiz91geQ0ylPP0aj1VUA==} engines: {node: '>=12'} - dev: false /d3-transition/3.0.1_d3-selection@3.0.0: resolution: {integrity: sha512-ApKvfjsSR6tg06xrL434C0WydLr7JewBB3V+/39RMHsaXTOG0zmt/OAXeng5M5LBm0ojmxJrpomQVZ1aPvBL4w==} @@ -6713,7 +6689,6 @@ packages: d3-interpolate: 3.0.1 d3-selection: 3.0.0 d3-timer: 3.0.1 - dev: false /d3-zoom/3.0.0: resolution: {integrity: sha512-b8AmV3kfQaqWAuacbPuNbL6vahnOJflOhexLzMMNLga62+/nh0JzvJ0aO/5a5MVgUFGS7Hu1P9P03o3fJkDCyw==} @@ -6724,7 +6699,6 @@ packages: d3-interpolate: 3.0.1 d3-selection: 3.0.0 d3-transition: 3.0.1_d3-selection@3.0.0 - dev: false /d3/7.6.1: resolution: {integrity: sha512-txMTdIHFbcpLx+8a0IFhZsbp+PfBBPt8yfbmukZTQFroKuFqIwqswF0qE5JXWefylaAVpSXFoKm3yP+jpNLFLw==} @@ -6760,7 +6734,6 @@ packages: d3-timer: 3.0.1 d3-transition: 3.0.1_d3-selection@3.0.0 d3-zoom: 3.0.0 - dev: false /dagre-d3/0.6.4: resolution: {integrity: sha512-e/6jXeCP7/ptlAM48clmX4xTZc5Ek6T6kagS7Oz2HrYSdqcLZFLqpAfh7ldbZRFfxCZVyh61NEPR08UQRVxJzQ==} @@ -6769,14 +6742,12 @@ packages: dagre: 0.8.5 graphlib: 2.1.8 lodash: 4.17.21 - dev: false /dagre/0.8.5: resolution: {integrity: sha512-/aTqmnRta7x7MCCpExk7HQL2O4owCT2h8NT//9I1OQ9vt29Pa0BzSAkR5lwFUcQ7491yVi/3CXU9jQ5o0Mn2Sw==} dependencies: graphlib: 2.1.8 lodash: 4.17.21 - dev: false /dargs/7.0.0: resolution: {integrity: sha512-2iy1EkLdlBzQGvbweYRFxmFath8+K7+AKB0TlhHWkNuH+TmovaMH/Wp7V7R4u7f4SnX3OgLsU9t1NI9ioDnUpg==} @@ -7016,7 +6987,6 @@ packages: resolution: {integrity: sha512-AyLvtyJdbv/U1GkiS6gUUzclRoAY4Gs75qkMygJJhU75LW4DNuSF2RMzpxs9jw9Oz1BobHjTdkG3zdP55VxAqw==} dependencies: robust-predicates: 3.0.1 - dev: false /delayed-stream/1.0.0: resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==} @@ -7223,7 +7193,6 @@ packages: /dompurify/2.4.0: resolution: {integrity: sha512-Be9tbQMZds4a3C6xTmz68NlMfeONA//4dOavl/1rNw50E+/QO0KVpbcU0PcaW0nsQxurXls9ZocqFxk8R2mWEA==} - dev: false /domutils/3.0.1: resolution: {integrity: sha512-z08c1l761iKhDFtfXO04C7kTdPBLi41zwOZl00WS8b5eiaebNpY00HKbztwBq+e3vyqWNwWF3mP9YLUeqIrF+Q==} @@ -8231,7 +8200,6 @@ packages: /fast-clone/1.5.13: resolution: {integrity: sha512-0ez7coyFBQFjZtId+RJqJ+EQs61w9xARfqjqK0AD9vIUkSxWD4HvPt80+5evebZ1tTnv1GYKrPTipx7kOW5ipA==} - dev: false /fast-deep-equal/3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} @@ -8412,6 +8380,18 @@ packages: optional: true dev: true + /follow-redirects/1.15.2_debug@4.3.2: + resolution: {integrity: sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==} + engines: {node: '>=4.0'} + peerDependencies: + debug: '*' + peerDependenciesMeta: + debug: + optional: true + dependencies: + debug: 4.3.2 + dev: true + /for-in/1.0.2: resolution: {integrity: sha512-7EwmXrOjyL+ChxMhmG5lnW9MPt1aIeZEwKhQzoBUdTV0N3zuwWDZYVJatDvZ2OyzPUvdIAZDsCetk3coyMfcnQ==} engines: {node: '>=0.10.0'} @@ -8862,7 +8842,6 @@ packages: resolution: {integrity: sha512-jcLLfkpoVGmH7/InMC/1hIvOPSUh38oJtGhvrOFGzioE1DZ+0YW16RgmOJhHiuWTvGiJQ9Z1Ik43JvkRPRvE+A==} dependencies: lodash: 4.17.21 - dev: false /gray-matter/4.0.3: resolution: {integrity: sha512-5v6yZd4JK3eMI3FqqCouswVqwugaA9r4dNZB1wwcmrD02QkV5H0y7XBQW8QwQqEaZY1pM9aqORSORhJRdNK44Q==} @@ -9375,7 +9354,6 @@ packages: /internmap/2.0.3: resolution: {integrity: sha512-5Hh7Y1wQbvY5ooGgPbDaL5iYLAPzMTUrjMulskHLH6wnv/A+1q5rgEaiuqEjB+oxGXIVZs1FF+R/KPN3ZSQYYg==} engines: {node: '>=12'} - dev: false /interpret/2.2.0: resolution: {integrity: sha512-Ju0Bz/cEia55xDwUWEa8+olFpCiQoypjnQySseKtmjNrnps3P+xfpUmGr90T7yjlVJmOtybRvPXhKMbHr+fWnw==} @@ -10493,7 +10471,6 @@ packages: /khroma/2.0.0: resolution: {integrity: sha512-2J8rDNlQWbtiNYThZRvmMv5yt44ZakX+Tz5ZIp/mN1pt4snn+m030Va5Z4v8xA0cQFDXBwO/8i42xL4QPsVk3g==} - dev: false /kind-of/3.2.2: resolution: {integrity: sha512-NOW9QQXMoZGg/oqnVNoNTTIFEIid1627WCffUBJEdMxYApq7mNE7CpzucIPc+ZQg25Phej7IJSmX3hO+oblOtQ==} @@ -10731,6 +10708,10 @@ packages: p-locate: 5.0.0 dev: true + /lodash-es/4.17.21: + resolution: {integrity: sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==} + dev: false + /lodash.debounce/4.0.8: resolution: {integrity: sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==} dev: true @@ -11030,6 +11011,24 @@ packages: engines: {node: '>= 8'} dev: true + /mermaid/9.2.2: + resolution: {integrity: sha512-6s7eKMqFJGS+0MYjmx8f6ZigqKBJVoSx5ql2gw6a4Aa+WJ49QiEJg7gPwywaBg3DZMs79UP7trESp4+jmaQccw==} + dependencies: + '@braintree/sanitize-url': 6.0.0 + d3: 7.6.1 + dagre: 0.8.5 + dagre-d3: 0.6.4 + dompurify: 2.4.0 + fast-clone: 1.5.13 + graphlib: 2.1.8 + khroma: 2.0.0 + lodash: 4.17.21 + moment-mini: 2.29.4 + non-layered-tidy-tree-layout: 2.0.2 + stylis: 4.1.2 + uuid: 9.0.0 + dev: true + /methods/1.1.2: resolution: {integrity: sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==} engines: {node: '>= 0.6'} @@ -11372,7 +11371,6 @@ packages: /moment-mini/2.29.4: resolution: {integrity: sha512-uhXpYwHFeiTbY9KSgPPRoo1nt8OxNVdMVoTBYHfSEKeRkIkwGpO+gERmhuhBtzfaeOyTkykSrm2+noJBgqt3Hg==} - dev: false /mri/1.2.0: resolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==} @@ -11510,7 +11508,6 @@ packages: /non-layered-tidy-tree-layout/2.0.2: resolution: {integrity: sha512-gkXMxRzUH+PB0ax9dUN0yYF0S25BqeAYqhgMaLUFmpXLEk7Fcu8f4emJuOAY0V8kjDICxROIKsTAKsV/v355xw==} - dev: false /normalize-package-data/2.5.0: resolution: {integrity: sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==} @@ -12831,7 +12828,22 @@ packages: /robust-predicates/3.0.1: resolution: {integrity: sha512-ndEIpszUHiG4HtDsQLeIuMvRsDnn8c8rYStabochtUeCvfuvNptb5TUbVD68LRAILPX7p9nqQGh4xJgn3EHS/g==} - dev: false + + /rollup-plugin-visualizer/5.8.3_rollup@2.79.1: + resolution: {integrity: sha512-QGJk4Bqe4AOat5AjipOh8esZH1nck5X2KFpf4VytUdSUuuuSwvIQZjMGgjcxe/zXexltqaXp5Vx1V3LmnQH15Q==} + engines: {node: '>=14'} + hasBin: true + peerDependencies: + rollup: 2.x || 3.x + peerDependenciesMeta: + rollup: + optional: true + dependencies: + open: 8.4.0 + rollup: 2.79.1 + source-map: 0.7.4 + yargs: 17.6.2 + dev: true /rollup/2.79.1: resolution: {integrity: sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==} @@ -12849,7 +12861,6 @@ packages: /rw/1.3.3: resolution: {integrity: sha512-PdhdWy89SiZogBLaw42zdeqtRJ//zFd2PgQavcICDUgJT5oW10QCRKbJ6bg4r0/UY2M6BWd5tkxuGFRvCkgfHQ==} - dev: false /rxjs/7.5.6: resolution: {integrity: sha512-dnyv2/YsXhnm461G+R/Pe5bWP41Nm6LBXEYWI6eiFP4fiwx6WRI/CD0zbdVAudd9xwLEF2IDcKXLHit0FYjUzw==} @@ -13271,6 +13282,11 @@ packages: engines: {node: '>=0.10.0'} dev: true + /source-map/0.7.4: + resolution: {integrity: sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA==} + engines: {node: '>= 8'} + dev: true + /sourcemap-codec/1.4.8: resolution: {integrity: sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==} dev: true @@ -13621,7 +13637,6 @@ packages: /stylis/4.1.2: resolution: {integrity: sha512-Nn2CCrG2ZaFziDxaZPN43CXqn+j7tcdjPFCkRBkFue8QYXC2HdEwnw5TCBo4yQZ2WxKYeSi0fdoOrtEqgDrXbA==} - dev: false /subarg/1.0.0: resolution: {integrity: sha512-RIrIdRY0X1xojthNcVtgT9sjpOGagEUKpZdgBUi054OEPFo282yg+zE+t1Rj3+RqKq2xStL7uUHhY+AjbC4BXg==} @@ -14086,7 +14101,7 @@ packages: '@tsconfig/node14': 1.0.3 '@tsconfig/node16': 1.0.3 '@types/node': 14.18.33 - acorn: 8.8.0 + acorn: 8.8.1 acorn-walk: 8.2.0 arg: 4.1.3 create-require: 1.1.1 @@ -14477,7 +14492,6 @@ packages: /uuid/9.0.0: resolution: {integrity: sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==} hasBin: true - dev: false /uvu/0.5.6: resolution: {integrity: sha512-+g8ENReyr8YsOc6fv/NVJs2vFdHBnBNdfE49rshrTzDWOlUx4Gq7KOS2GD8eqhy2j+Ejq29+SbKH8yjkAqXqoA==} @@ -14711,14 +14725,14 @@ packages: fsevents: 2.3.2 dev: true - /vitepress-plugin-mermaid/2.0.8_2q5vfj2vm6nj3r62ddjdsi7aoe: + /vitepress-plugin-mermaid/2.0.8_qntmym4r3eiuu4ikfhr4jvwbjq: resolution: {integrity: sha512-ywWxTeg9kMv7ZPf/igCBF4ZHhWZAyRtbPnA12ICQuNK2AMp7r5IHOfnuX1EJQf8gNdsh8bcvvSvm8Ll92fdOTw==} peerDependencies: mermaid: ^8.0.0 || ^9.0.0 vite-plugin-md: ^0.20.4 vitepress: ^0.21.6 || ^1.0.0 || ^1.0.0-alpha dependencies: - mermaid: link:packages/mermaid + mermaid: 9.2.2 vite-plugin-md: 0.20.4_2vrekto2ma5pf5j2eoe6xabo24 vitepress: 1.0.0-alpha.28_ysryt2e75uhznkanan6iyjk4mi dev: true diff --git a/vdocs/.vitepress/config.ts b/vdocs/.vitepress/config.ts index d3cdccc9a..48bb382c0 100644 --- a/vdocs/.vitepress/config.ts +++ b/vdocs/.vitepress/config.ts @@ -1,7 +1,6 @@ import { version } from '../../package.json'; import ExampleMarkdown from './mermaid-markdown-all'; import { defineConfig } from 'vitepress'; -import { update } from 'lodash'; export default defineConfig({ lang: 'en-US', From 2e028ce36d78c857693becedb2cac2549308a3ca Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Sun, 20 Nov 2022 00:38:35 +0530 Subject: [PATCH 18/67] chore: Unify `registerLazyLoadedDiagrams` --- cypress/platform/flow2.html | 46 +++++++++++++++++++ .../mermaid/src/diagram-api/detectType.ts | 6 ++- .../src/diagram-api/diagram-orchestration.ts | 36 ++++++++------- packages/mermaid/src/mermaid.ts | 15 +----- 4 files changed, 71 insertions(+), 32 deletions(-) create mode 100644 cypress/platform/flow2.html diff --git a/cypress/platform/flow2.html b/cypress/platform/flow2.html new file mode 100644 index 000000000..b23f00be6 --- /dev/null +++ b/cypress/platform/flow2.html @@ -0,0 +1,46 @@ + + + + + + +
+      graph TB
+      subgraph One
+        a1-->a2-->a3
+      end
+    
+
+      graph TB
+        a_a --> b_b:::apa --> c_c:::apa
+        classDef apa fill:#f9f,stroke:#333,stroke-width:4px;
+        class a_a apa;
+    
+
+      graph TB
+        a_a(Aftonbladet) --> b_b[gorilla]:::apa --> c_c{chimp}:::apa -->a_a
+        a_a --> c --> d_d --> c_c
+        classDef apa fill:#f9f,stroke:#333,stroke-width:4px;
+        class a_a apa;
+        click a_a "http://www.aftonbladet.se" "apa"
+    
+ + + + diff --git a/packages/mermaid/src/diagram-api/detectType.ts b/packages/mermaid/src/diagram-api/detectType.ts index 1ea4f2b4d..c27f79b6c 100644 --- a/packages/mermaid/src/diagram-api/detectType.ts +++ b/packages/mermaid/src/diagram-api/detectType.ts @@ -44,8 +44,10 @@ export const detectType = function (text: string, config?: MermaidConfig): strin throw new Error(`No diagram type detected for text: ${text}`); }; -export const addDiagram = ({ id, detector, loader }: ExternalDiagramDefinition) => { - addDetector(id, detector, loader); +export const registerLazyLoadedDiagrams = (...diagrams: ExternalDiagramDefinition[]) => { + for (const { id, detector, loader } of diagrams) { + addDetector(id, detector, loader); + } }; export const addDetector = (key: string, detector: DiagramDetector, loader?: DiagramLoader) => { diff --git a/packages/mermaid/src/diagram-api/diagram-orchestration.ts b/packages/mermaid/src/diagram-api/diagram-orchestration.ts index 64a7e5ad8..c6b8b579a 100644 --- a/packages/mermaid/src/diagram-api/diagram-orchestration.ts +++ b/packages/mermaid/src/diagram-api/diagram-orchestration.ts @@ -14,7 +14,7 @@ import state from '../diagrams/state/stateDetector'; import stateV2 from '../diagrams/state/stateDetector-V2'; import journey from '../diagrams/user-journey/journeyDetector'; import error from '../diagrams/error/errorDetector'; -import { addDiagram } from './detectType'; +import { registerLazyLoadedDiagrams } from './detectType'; let hasLoadedDiagrams = false; export const addDiagrams = () => { @@ -24,20 +24,22 @@ export const addDiagrams = () => { // This is added here to avoid race-conditions. // We could optimize the loading logic somehow. hasLoadedDiagrams = true; - addDiagram(error); - addDiagram(c4); - addDiagram(classDiagram); - addDiagram(classDiagramV2); - addDiagram(er); - addDiagram(gantt); - addDiagram(info); - addDiagram(pie); - addDiagram(requirement); - addDiagram(sequence); - addDiagram(flowchart); - addDiagram(flowchartV2); - addDiagram(git); - addDiagram(state); - addDiagram(stateV2); - addDiagram(journey); + registerLazyLoadedDiagrams( + error, + c4, + classDiagram, + classDiagramV2, + er, + gantt, + info, + pie, + requirement, + sequence, + flowchart, + flowchartV2, + git, + state, + stateV2, + journey + ); }; diff --git a/packages/mermaid/src/mermaid.ts b/packages/mermaid/src/mermaid.ts index 3a8da77ad..268a830ec 100644 --- a/packages/mermaid/src/mermaid.ts +++ b/packages/mermaid/src/mermaid.ts @@ -6,7 +6,7 @@ import type { MermaidConfig } from './config.type'; import { log } from './logger'; import utils from './utils'; import { mermaidAPI } from './mermaidAPI'; -import { addDetector } from './diagram-api/detectType'; +import { registerLazyLoadedDiagrams } from './diagram-api/detectType'; import { isDetailedError, type DetailedError } from './utils'; import { registerDiagram } from './diagram-api/diagramAPI'; import { ExternalDiagramDefinition } from './diagram-api/types'; @@ -175,17 +175,6 @@ const initThrowsErrors = function ( } }; -/** - * This is an internal function and should not be made public, as it will likely change. - * @internal - * @param diagrams - Array of {@link ExternalDiagramDefinition}. - */ -const registerLazyLoadedDiagrams = (diagrams: ExternalDiagramDefinition[]) => { - for (const { id, detector, loader } of diagrams) { - addDetector(id, detector, loader); - } -}; - /** * This is an internal function and should not be made public, as it will likely change. * @internal @@ -333,7 +322,7 @@ const registerExternalDiagrams = async ( } = {} ) => { if (lazyLoad) { - registerLazyLoadedDiagrams(diagrams); + registerLazyLoadedDiagrams(...diagrams); } else { await loadExternalDiagrams(diagrams); } From e861fbb5170a5ade38db52320f55dd580547e522 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Sun, 20 Nov 2022 11:09:08 +0530 Subject: [PATCH 19/67] feat: unbundle styles --- .vite/server.ts | 1 + .../mermaid/src/diagram-api/diagramAPI.ts | 26 +++++++++++++- packages/mermaid/src/mermaid.ts | 28 ++------------- packages/mermaid/src/styles.ts | 36 ++----------------- 4 files changed, 30 insertions(+), 61 deletions(-) diff --git a/.vite/server.ts b/.vite/server.ts index 334398dd8..ddd6afdd6 100644 --- a/.vite/server.ts +++ b/.vite/server.ts @@ -16,6 +16,7 @@ async function createServer() { // Create Vite server in middleware mode const vite = await createViteServer({ configFile: './vite.config.ts', + mode: 'production', server: { middlewareMode: true }, appType: 'custom', // don't include Vite's default HTML handling middlewares }); diff --git a/packages/mermaid/src/diagram-api/diagramAPI.ts b/packages/mermaid/src/diagram-api/diagramAPI.ts index 2727ae4ef..cacf02fe1 100644 --- a/packages/mermaid/src/diagram-api/diagramAPI.ts +++ b/packages/mermaid/src/diagram-api/diagramAPI.ts @@ -4,7 +4,7 @@ import { getConfig as _getConfig } from '../config'; import { sanitizeText as _sanitizeText } from '../diagrams/common/common'; import { setupGraphViewbox as _setupGraphViewbox } from '../setupGraphViewbox'; import { addStylesForDiagram } from '../styles'; -import { DiagramDefinition, DiagramDetector } from './types'; +import { DiagramDefinition, DiagramDetector, ExternalDiagramDefinition } from './types'; /* Packaging and exposing resources for externa diagrams so that they can import @@ -70,3 +70,27 @@ export class DiagramNotFoundError extends Error { super(`Diagram ${message} not found.`); } } + +/** + * This is an internal function and should not be made public, as it will likely change. + * @internal + * @param diagrams - Array of {@link ExternalDiagramDefinition}. + */ +export const loadExternalDiagrams = async (...diagrams: ExternalDiagramDefinition[]) => { + log.debug(`Loading ${diagrams.length} external diagrams`); + // Load all lazy loaded diagrams in parallel + const results = await Promise.allSettled( + diagrams.map(async ({ id, detector, loader }) => { + const { diagram } = await loader(); + registerDiagram(id, diagram, detector); + }) + ); + const failed = results.filter((result) => result.status === 'rejected'); + if (failed.length > 0) { + log.error(`Failed to load ${failed.length} external diagrams`); + for (const res of failed) { + log.error(res); + } + throw new Error(`Failed to load ${failed.length} external diagrams`); + } +}; diff --git a/packages/mermaid/src/mermaid.ts b/packages/mermaid/src/mermaid.ts index 268a830ec..da13d2d01 100644 --- a/packages/mermaid/src/mermaid.ts +++ b/packages/mermaid/src/mermaid.ts @@ -8,7 +8,7 @@ import utils from './utils'; import { mermaidAPI } from './mermaidAPI'; import { registerLazyLoadedDiagrams } from './diagram-api/detectType'; import { isDetailedError, type DetailedError } from './utils'; -import { registerDiagram } from './diagram-api/diagramAPI'; +import { loadExternalDiagrams } from './diagram-api/diagramAPI'; import { ExternalDiagramDefinition } from './diagram-api/types'; export type { MermaidConfig, DetailedError, ExternalDiagramDefinition }; @@ -175,30 +175,6 @@ const initThrowsErrors = function ( } }; -/** - * This is an internal function and should not be made public, as it will likely change. - * @internal - * @param diagrams - Array of {@link ExternalDiagramDefinition}. - */ -const loadExternalDiagrams = async (diagrams: ExternalDiagramDefinition[]) => { - log.debug(`Loading ${diagrams.length} external diagrams`); - // Load all lazy loaded diagrams in parallel - const results = await Promise.allSettled( - diagrams.map(async ({ id, detector, loader }) => { - const { diagram } = await loader(); - registerDiagram(id, diagram, detector); - }) - ); - const failed = results.filter((result) => result.status === 'rejected'); - if (failed.length > 0) { - log.error(`Failed to load ${failed.length} external diagrams`); - for (const res of failed) { - log.error(res); - } - throw new Error(`Failed to load ${failed.length} external diagrams`); - } -}; - /** * Equivalent to {@link init()}, except an error will be thrown on error. * @@ -324,7 +300,7 @@ const registerExternalDiagrams = async ( if (lazyLoad) { registerLazyLoadedDiagrams(...diagrams); } else { - await loadExternalDiagrams(diagrams); + await loadExternalDiagrams(...diagrams); } }; diff --git a/packages/mermaid/src/styles.ts b/packages/mermaid/src/styles.ts index 0c4a7e1a5..5e7907a80 100644 --- a/packages/mermaid/src/styles.ts +++ b/packages/mermaid/src/styles.ts @@ -1,39 +1,7 @@ -import classDiagram from './diagrams/class/styles'; -import er from './diagrams/er/styles'; -import error from './diagrams/error/styles'; -import flowchart from './diagrams/flowchart/styles'; -import gantt from './diagrams/gantt/styles'; -// import gitGraph from './diagrams/git/styles'; -import info from './diagrams/info/styles'; -import pie from './diagrams/pie/styles'; -import requirement from './diagrams/requirement/styles'; -import sequence from './diagrams/sequence/styles'; -import stateDiagram from './diagrams/state/styles'; -import journey from './diagrams/user-journey/styles'; -import c4 from './diagrams/c4/styles'; -import { FlowChartStyleOptions } from './diagrams/flowchart/styles'; +import type { FlowChartStyleOptions } from './diagrams/flowchart/styles'; import { log } from './logger'; -// TODO @knut: Inject from registerDiagram. -const themes: Record = { - flowchart, - 'flowchart-v2': flowchart, - sequence, - gantt, - classDiagram, - 'classDiagram-v2': classDiagram, - class: classDiagram, - stateDiagram, - state: stateDiagram, - // gitGraph, - info, - pie, - er, - error, - journey, - requirement, - c4, -}; +const themes: Record = {}; const getStyles = ( type: string, From b04517b146c63057262d576a0b8e0df7c9847dbd Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Sun, 20 Nov 2022 12:00:34 +0530 Subject: [PATCH 20/67] chore: Cleanup --- .../rendering/stateDiagram-v2.spec.js | 6 ++-- docs/community/newDiagram.md | 4 +-- docs/config/setup/modules/mermaidAPI.md | 20 +++++------ docs/intro/n00b-gettingStarted.md | 30 ++++++++-------- .../mermaid/src/diagram-api/diagramAPI.ts | 2 +- packages/mermaid/src/docs.mts | 2 +- .../src/docs/intro/n00b-gettingStarted.md | 34 +++++++++++-------- 7 files changed, 51 insertions(+), 47 deletions(-) diff --git a/cypress/integration/rendering/stateDiagram-v2.spec.js b/cypress/integration/rendering/stateDiagram-v2.spec.js index 3800a1bf5..5b43c890c 100644 --- a/cypress/integration/rendering/stateDiagram-v2.spec.js +++ b/cypress/integration/rendering/stateDiagram-v2.spec.js @@ -530,7 +530,7 @@ stateDiagram-v2 [*] --> A A --> B: test({ foo#colon; 'far' }) B --> [*] - classDef badBadEvent fill:#f00,color:white,font-weight:bold + classDef badBadEvent fill:#f00,color:white,font-weight:bold class B badBadEvent `, { logLevel: 0, fontFamily: 'courier' } @@ -543,14 +543,14 @@ stateDiagram-v2 classDef notMoving fill:white classDef movement font-style:italic; classDef badBadEvent fill:#f00,color:white,font-weight:bold - + [*] --> Still Still --> [*] Still --> Moving Moving --> Still Moving --> Crash Crash --> [*] - + class Still notMoving class Moving, Crash movement class Crash badBadEvent diff --git a/docs/community/newDiagram.md b/docs/community/newDiagram.md index 7f08e0d95..da86f9838 100644 --- a/docs/community/newDiagram.md +++ b/docs/community/newDiagram.md @@ -174,8 +174,8 @@ The syntax for adding title and description looks like this: accDescr: The description accDescr { - Syntax for a description text - written on multiple lines. + Syntax for a description text + written on multiple lines. } In a similar way to the directives the jison syntax are quite similar between the diagrams. diff --git a/docs/config/setup/modules/mermaidAPI.md b/docs/config/setup/modules/mermaidAPI.md index 0acfe4f97..b1387eb0e 100644 --- a/docs/config/setup/modules/mermaidAPI.md +++ b/docs/config/setup/modules/mermaidAPI.md @@ -80,7 +80,7 @@ mermaid.initialize(config); #### Defined in -[mermaidAPI.ts:949](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L949) +[mermaidAPI.ts:938](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L938) ## Functions @@ -111,7 +111,7 @@ Return the last node appended #### Defined in -[mermaidAPI.ts:292](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L292) +[mermaidAPI.ts:289](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L289) --- @@ -137,7 +137,7 @@ the cleaned up svgCode #### Defined in -[mermaidAPI.ts:243](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L243) +[mermaidAPI.ts:240](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L240) --- @@ -163,7 +163,7 @@ the string with all the user styles #### Defined in -[mermaidAPI.ts:170](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L170) +[mermaidAPI.ts:167](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L167) --- @@ -186,7 +186,7 @@ the string with all the user styles #### Defined in -[mermaidAPI.ts:220](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L220) +[mermaidAPI.ts:217](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L217) --- @@ -213,7 +213,7 @@ with an enclosing block that has each of the cssClasses followed by !important; #### Defined in -[mermaidAPI.ts:154](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L154) +[mermaidAPI.ts:151](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L151) --- @@ -233,7 +233,7 @@ with an enclosing block that has each of the cssClasses followed by !important; #### Defined in -[mermaidAPI.ts:128](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L128) +[mermaidAPI.ts:125](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L125) --- @@ -253,7 +253,7 @@ with an enclosing block that has each of the cssClasses followed by !important; #### Defined in -[mermaidAPI.ts:99](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L99) +[mermaidAPI.ts:96](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L96) --- @@ -279,7 +279,7 @@ Put the svgCode into an iFrame. Return the iFrame code #### Defined in -[mermaidAPI.ts:271](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L271) +[mermaidAPI.ts:268](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L268) --- @@ -305,4 +305,4 @@ Remove any existing elements from the given document #### Defined in -[mermaidAPI.ts:343](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L343) +[mermaidAPI.ts:340](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L340) diff --git a/docs/intro/n00b-gettingStarted.md b/docs/intro/n00b-gettingStarted.md index 5ee34972e..2f422758e 100644 --- a/docs/intro/n00b-gettingStarted.md +++ b/docs/intro/n00b-gettingStarted.md @@ -111,9 +111,9 @@ b. The importing of mermaid library through the `mermaid.esm.js` or `mermaid.esm Here is a mermaid diagram:
-        graph TD
-        A[Client] --> B[Load Balancer]
-        B --> C[Server01]
+        graph TD 
+        A[Client] --> B[Load Balancer] 
+        B --> C[Server01] 
         B --> D[Server02]
   
@@ -156,18 +156,18 @@ Please refer to the [Mindmap](./mindmap.md?id=integrating-with-your-librarywebsi Here is one mermaid diagram:
-            graph TD
-            A[Client] --> B[Load Balancer]
-            B --> C[Server1]
+            graph TD 
+            A[Client] --> B[Load Balancer] 
+            B --> C[Server1] 
             B --> D[Server2]
     
And here is another:
-            graph TD
+            graph TD 
             A[Client] -->|tcp_123| B
-            B(Load Balancer)
-            B -->|tcp_456| C[Server1]
+            B(Load Balancer) 
+            B -->|tcp_456| C[Server1] 
             B -->|tcp_456| D[Server2]
     
@@ -189,15 +189,15 @@ In this example mermaid.js is referenced in `src` as a separate JavaScript file,
-            graph LR
-            A --- B
-            B-->C[fa:fa-ban forbidden]
+            graph LR 
+            A --- B 
+            B-->C[fa:fa-ban forbidden] 
             B-->D(fa:fa-spinner);
     
-            graph TD
-            A[Client] --> B[Load Balancer]
-            B --> C[Server1]
+            graph TD 
+            A[Client] --> B[Load Balancer] 
+            B --> C[Server1] 
             B --> D[Server2]
     
@@ -276,12 +276,6 @@ From version 9.4.0 you can simplify this code to: ``` -or if you prefer not using the ESM package: - -```html - -``` - Note that more complex integrations that use the **render** function directly need to use the **renderAsync** method instead in order to render mind maps. You can also refer the implementation in the live editor [here](https://github.com/mermaid-js/mermaid-live-editor/blob/develop/src/lib/util/mermaid.ts) to see how the async loading is done. diff --git a/docs/syntax/timeline.md b/docs/syntax/timeline.md index 6e3be305f..1c7e6e002 100644 --- a/docs/syntax/timeline.md +++ b/docs/syntax/timeline.md @@ -466,7 +466,9 @@ Timeline uses experimental lazy loading & async rendering features which could c You can use this method to add mermaid including the timeline diagram to a web page: ```html - + ``` Note that more complex integrations that the **render** function directly need to use the **renderAsync** method instead in order to render timeline. diff --git a/packages/mermaid/src/docs/intro/n00b-gettingStarted.md b/packages/mermaid/src/docs/intro/n00b-gettingStarted.md index c347f2ef3..cfc16e707 100644 --- a/packages/mermaid/src/docs/intro/n00b-gettingStarted.md +++ b/packages/mermaid/src/docs/intro/n00b-gettingStarted.md @@ -118,7 +118,7 @@ b. The importing of mermaid library through the `mermaid.esm.js` or `mermaid.esm ``` **Notes**: -Rendering in Mermaid is initialized by `mermaid.initialize()` call. You can place `mermaid.initialize()` inside `mermaid.min.js` for brevity. However, doing the opposite lets you control when it starts looking for `
`tags inside the web page with `mermaid.initialize()`. This is useful when you think that not all `
` tags may have loaded on the execution of `mermaid.min.js` file. +Rendering in Mermaid is initialized by `mermaid.initialize()` call. You can place `mermaid.initialize()` inside `mermaid.esm.min.mjs` for brevity. However, doing the opposite lets you control when it starts looking for `
`tags inside the web page with `mermaid.initialize()`. This is useful when you think that not all `
` tags may have loaded on the execution of `mermaid.esm.min.mjs` file. `startOnLoad` is one of the parameters that can be defined by `mermaid.initialize()` diff --git a/packages/mermaid/src/docs/syntax/mindmap.md b/packages/mermaid/src/docs/syntax/mindmap.md index cce7d2e3d..968277334 100644 --- a/packages/mermaid/src/docs/syntax/mindmap.md +++ b/packages/mermaid/src/docs/syntax/mindmap.md @@ -170,7 +170,7 @@ You can still use the pre 9.4.0 method to add mermaid with mindmaps to a web pag ```html @@ -184,12 +184,6 @@ From version 9.4.0 you can simplify this code to: ``` -or if you prefer not using the ESM package: - -```html - -``` - Note that more complex integrations that use the **render** function directly need to use the **renderAsync** method instead in order to render mind maps. You can also refer the implementation in the live editor [here](https://github.com/mermaid-js/mermaid-live-editor/blob/develop/src/lib/util/mermaid.ts) to see how the async loading is done. diff --git a/packages/mermaid/src/docs/syntax/timeline.md b/packages/mermaid/src/docs/syntax/timeline.md index 94a485d22..bed8d8ef5 100644 --- a/packages/mermaid/src/docs/syntax/timeline.md +++ b/packages/mermaid/src/docs/syntax/timeline.md @@ -298,7 +298,9 @@ Timeline uses experimental lazy loading & async rendering features which could c You can use this method to add mermaid including the timeline diagram to a web page: ```html - + ``` Note that more complex integrations that the **render** function directly need to use the **renderAsync** method instead in order to render timeline. From d22e8d92c6e33ac659e198f0818cfc8112179fa0 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Sun, 19 Feb 2023 01:10:15 +0530 Subject: [PATCH 31/67] chore: Remove all non async render/parse/init --- .../external-diagrams-example-diagram.html | 2 +- docs/config/setup/modules/mermaidAPI.md | 22 +- docs/syntax/mindmap.md | 2 - docs/syntax/timeline.md | 2 - packages/mermaid/src/__mocks__/mermaidAPI.ts | 1 - .../src/docs/.vitepress/theme/mermaid.ts | 2 +- packages/mermaid/src/docs/syntax/mindmap.md | 2 - packages/mermaid/src/docs/syntax/timeline.md | 2 - packages/mermaid/src/mermaid.spec.ts | 6 +- packages/mermaid/src/mermaid.ts | 126 +--------- packages/mermaid/src/mermaidAPI.spec.ts | 8 +- packages/mermaid/src/mermaidAPI.ts | 222 +----------------- tests/webpack/src/index.js | 2 +- 13 files changed, 32 insertions(+), 367 deletions(-) diff --git a/cypress/platform/external-diagrams-example-diagram.html b/cypress/platform/external-diagrams-example-diagram.html index 9d2cad778..a1339d4e6 100644 --- a/cypress/platform/external-diagrams-example-diagram.html +++ b/cypress/platform/external-diagrams-example-diagram.html @@ -17,7 +17,7 @@ example-diagram await mermaid.registerExternalDiagrams([exampleDiagram]); await mermaid.initialize({ logLevel: 0 }); - await mermaid.initThrowsErrorsAsync(); + await mermaid.initThrowsErrors(); if (window.Cypress) { window.rendered = true; } diff --git a/docs/config/setup/modules/mermaidAPI.md b/docs/config/setup/modules/mermaidAPI.md index bd9833c5b..2cdeb597a 100644 --- a/docs/config/setup/modules/mermaidAPI.md +++ b/docs/config/setup/modules/mermaidAPI.md @@ -26,7 +26,7 @@ Renames and re-exports [mermaidAPI](mermaidAPI.md#mermaidapi) ### mermaidAPI -• `Const` **mermaidAPI**: `Readonly`<{ `defaultConfig`: `MermaidConfig` = configApi.defaultConfig; `getConfig`: () => `MermaidConfig` = configApi.getConfig; `getSiteConfig`: () => `MermaidConfig` = configApi.getSiteConfig; `globalReset`: () => `void` ; `initialize`: (`options`: `MermaidConfig`) => `void` ; `parse`: (`text`: `string`, `parseError?`: `ParseErrorFunction`) => `boolean` ; `parseAsync`: (`text`: `string`, `parseError?`: `ParseErrorFunction`) => `Promise`<`boolean`> ; `parseDirective`: (`p`: `any`, `statement`: `string`, `context`: `string`, `type`: `string`) => `void` ; `render`: (`id`: `string`, `text`: `string`, `cb?`: (`svgCode`: `string`, `bindFunctions?`: (`element`: `Element`) => `void`) => `void`, `svgContainingElement?`: `Element`) => `string` ; `renderAsync`: (`id`: `string`, `text`: `string`, `cb?`: (`svgCode`: `string`, `bindFunctions?`: (`element`: `Element`) => `void`) => `void`, `svgContainingElement?`: `Element`) => `Promise`<`string`> ; `reset`: () => `void` ; `setConfig`: (`conf`: `MermaidConfig`) => `MermaidConfig` = configApi.setConfig; `updateSiteConfig`: (`conf`: `MermaidConfig`) => `MermaidConfig` = configApi.updateSiteConfig }> +• `Const` **mermaidAPI**: `Readonly`<{ `defaultConfig`: `MermaidConfig` = configApi.defaultConfig; `getConfig`: () => `MermaidConfig` = configApi.getConfig; `getSiteConfig`: () => `MermaidConfig` = configApi.getSiteConfig; `globalReset`: () => `void` ; `initialize`: (`options`: `MermaidConfig`) => `void` ; `parse`: (`text`: `string`, `parseError?`: `ParseErrorFunction`) => `Promise`<`boolean`> ; `parseDirective`: (`p`: `any`, `statement`: `string`, `context`: `string`, `type`: `string`) => `void` ; `render`: (`id`: `string`, `text`: `string`, `cb?`: (`svgCode`: `string`, `bindFunctions?`: (`element`: `Element`) => `void`) => `void`, `svgContainingElement?`: `Element`) => `Promise`<`string`> ; `reset`: () => `void` ; `setConfig`: (`conf`: `MermaidConfig`) => `MermaidConfig` = configApi.setConfig; `updateSiteConfig`: (`conf`: `MermaidConfig`) => `MermaidConfig` = configApi.updateSiteConfig }> ## mermaidAPI configuration defaults @@ -90,7 +90,7 @@ mermaid.initialize(config); #### Defined in -[mermaidAPI.ts:887](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L887) +[mermaidAPI.ts:671](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L671) ## Functions @@ -121,7 +121,7 @@ Return the last node appended #### Defined in -[mermaidAPI.ts:288](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L288) +[mermaidAPI.ts:278](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L278) --- @@ -147,7 +147,7 @@ the cleaned up svgCode #### Defined in -[mermaidAPI.ts:239](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L239) +[mermaidAPI.ts:229](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L229) --- @@ -173,7 +173,7 @@ the string with all the user styles #### Defined in -[mermaidAPI.ts:168](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L168) +[mermaidAPI.ts:158](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L158) --- @@ -196,7 +196,7 @@ the string with all the user styles #### Defined in -[mermaidAPI.ts:216](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L216) +[mermaidAPI.ts:206](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L206) --- @@ -223,7 +223,7 @@ with an enclosing block that has each of the cssClasses followed by !important; #### Defined in -[mermaidAPI.ts:152](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L152) +[mermaidAPI.ts:142](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L142) --- @@ -243,7 +243,7 @@ with an enclosing block that has each of the cssClasses followed by !important; #### Defined in -[mermaidAPI.ts:132](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L132) +[mermaidAPI.ts:122](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L122) --- @@ -263,7 +263,7 @@ with an enclosing block that has each of the cssClasses followed by !important; #### Defined in -[mermaidAPI.ts:103](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L103) +[mermaidAPI.ts:93](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L93) --- @@ -289,7 +289,7 @@ Put the svgCode into an iFrame. Return the iFrame code #### Defined in -[mermaidAPI.ts:267](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L267) +[mermaidAPI.ts:257](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L257) --- @@ -314,4 +314,4 @@ Remove any existing elements from the given document #### Defined in -[mermaidAPI.ts:338](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L338) +[mermaidAPI.ts:328](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L328) diff --git a/docs/syntax/mindmap.md b/docs/syntax/mindmap.md index 362fd85c7..ad8aab77f 100644 --- a/docs/syntax/mindmap.md +++ b/docs/syntax/mindmap.md @@ -276,6 +276,4 @@ From version 9.4.0 you can simplify this code to: ``` -Note that more complex integrations that use the **render** function directly need to use the **renderAsync** method instead in order to render mind maps. - You can also refer the implementation in the live editor [here](https://github.com/mermaid-js/mermaid-live-editor/blob/develop/src/lib/util/mermaid.ts) to see how the async loading is done. diff --git a/docs/syntax/timeline.md b/docs/syntax/timeline.md index 1c7e6e002..58b12313d 100644 --- a/docs/syntax/timeline.md +++ b/docs/syntax/timeline.md @@ -471,6 +471,4 @@ You can use this method to add mermaid including the timeline diagram to a web p ``` -Note that more complex integrations that the **render** function directly need to use the **renderAsync** method instead in order to render timeline. - You can also refer the implementation in the live editor [here](https://github.com/mermaid-js/mermaid-live-editor/blob/develop/src/lib/util/mermaid.ts) to see how the async loading is done. diff --git a/packages/mermaid/src/__mocks__/mermaidAPI.ts b/packages/mermaid/src/__mocks__/mermaidAPI.ts index 12c1652bc..50018bcad 100644 --- a/packages/mermaid/src/__mocks__/mermaidAPI.ts +++ b/packages/mermaid/src/__mocks__/mermaidAPI.ts @@ -21,7 +21,6 @@ function parse(text: string, parseError?: ParseErrorFunction): boolean { // original version cannot be modified since it was frozen with `Object.freeze()` export const mermaidAPI = { render: vi.fn(), - renderAsync: vi.fn(), parse, parseDirective: vi.fn(), initialize: vi.fn(), diff --git a/packages/mermaid/src/docs/.vitepress/theme/mermaid.ts b/packages/mermaid/src/docs/.vitepress/theme/mermaid.ts index 2234ef498..c5b57f886 100644 --- a/packages/mermaid/src/docs/.vitepress/theme/mermaid.ts +++ b/packages/mermaid/src/docs/.vitepress/theme/mermaid.ts @@ -2,6 +2,6 @@ import mermaid, { type MermaidConfig } from 'mermaid'; export const render = async (id: string, code: string, config: MermaidConfig): Promise => { mermaid.initialize(config); - const svg = await mermaid.renderAsync(id, code); + const svg = await mermaid.render(id, code); return svg; }; diff --git a/packages/mermaid/src/docs/syntax/mindmap.md b/packages/mermaid/src/docs/syntax/mindmap.md index 968277334..c8a252691 100644 --- a/packages/mermaid/src/docs/syntax/mindmap.md +++ b/packages/mermaid/src/docs/syntax/mindmap.md @@ -184,6 +184,4 @@ From version 9.4.0 you can simplify this code to: ``` -Note that more complex integrations that use the **render** function directly need to use the **renderAsync** method instead in order to render mind maps. - You can also refer the implementation in the live editor [here](https://github.com/mermaid-js/mermaid-live-editor/blob/develop/src/lib/util/mermaid.ts) to see how the async loading is done. diff --git a/packages/mermaid/src/docs/syntax/timeline.md b/packages/mermaid/src/docs/syntax/timeline.md index bed8d8ef5..ef48d2b61 100644 --- a/packages/mermaid/src/docs/syntax/timeline.md +++ b/packages/mermaid/src/docs/syntax/timeline.md @@ -303,6 +303,4 @@ You can use this method to add mermaid including the timeline diagram to a web p ``` -Note that more complex integrations that the **render** function directly need to use the **renderAsync** method instead in order to render timeline. - You can also refer the implementation in the live editor [here](https://github.com/mermaid-js/mermaid-live-editor/blob/develop/src/lib/util/mermaid.ts) to see how the async loading is done. diff --git a/packages/mermaid/src/mermaid.spec.ts b/packages/mermaid/src/mermaid.spec.ts index aa797af0e..f9709510e 100644 --- a/packages/mermaid/src/mermaid.spec.ts +++ b/packages/mermaid/src/mermaid.spec.ts @@ -48,7 +48,7 @@ describe('when using mermaid and ', function () { const node = document.createElement('div'); node.appendChild(document.createTextNode('graph TD;\na;')); - mermaid.initThrowsErrors(undefined, node); + await mermaid.initThrowsErrors(undefined, node); // mermaidAPI.render function has been mocked, since it doesn't yet work // in Node.JS (only works in browser) expect(mermaidAPI.render).toHaveBeenCalled(); @@ -72,9 +72,9 @@ describe('when using mermaid and ', function () { ) ).rejects.toThrow('Failed to load 1 external diagrams'); - expect(() => mermaid.initThrowsErrorsAsync(undefined, node)).not.toThrow(); + expect(() => mermaid.initThrowsErrors(undefined, node)).not.toThrow(); // should still render, even if lazyLoadedDiagrams fails - expect(mermaidAPI.renderAsync).toHaveBeenCalled(); + expect(mermaidAPI.render).toHaveBeenCalled(); }); it('should defer diagram load based on parameter', async () => { diff --git a/packages/mermaid/src/mermaid.ts b/packages/mermaid/src/mermaid.ts index be06c2167..540e0368e 100644 --- a/packages/mermaid/src/mermaid.ts +++ b/packages/mermaid/src/mermaid.ts @@ -50,7 +50,7 @@ const init = async function ( callback?: Function ) { try { - await initThrowsErrorsAsync(config, nodes, callback); + await initThrowsErrors(config, nodes, callback); } catch (e) { log.warn('Syntax Error rendering'); if (isDetailedError(e)) { @@ -87,96 +87,6 @@ const handleError = (error: unknown, errors: DetailedError[], parseError?: Parse } }; -const initThrowsErrors = function ( - config?: MermaidConfig, - // eslint-disable-next-line no-undef - nodes?: string | HTMLElement | NodeListOf, - // eslint-disable-next-line @typescript-eslint/ban-types - callback?: Function -) { - const conf = mermaidAPI.getConfig(); - if (config) { - // This is a legacy way of setting config. It is not documented and should be removed in the future. - // @ts-ignore: TODO Fix ts errors - mermaid.sequenceConfig = config; - } - - // if last argument is a function this is the callback function - log.debug(`${!callback ? 'No ' : ''}Callback function found`); - let nodesToProcess: ArrayLike; - if (nodes === undefined) { - nodesToProcess = document.querySelectorAll('.mermaid'); - } else if (typeof nodes === 'string') { - nodesToProcess = document.querySelectorAll(nodes); - } else if (nodes instanceof HTMLElement) { - nodesToProcess = [nodes]; - } else if (nodes instanceof NodeList) { - nodesToProcess = nodes; - } else { - throw new Error('Invalid argument nodes for mermaid.init'); - } - - log.debug(`Found ${nodesToProcess.length} diagrams`); - if (config?.startOnLoad !== undefined) { - log.debug('Start On Load: ' + config?.startOnLoad); - mermaidAPI.updateSiteConfig({ startOnLoad: config?.startOnLoad }); - } - - // generate the id of the diagram - const idGenerator = new utils.initIdGenerator(conf.deterministicIds, conf.deterministicIDSeed); - - let txt: string; - const errors: DetailedError[] = []; - - // element is the current div with mermaid class - // eslint-disable-next-line unicorn/prefer-spread - for (const element of Array.from(nodesToProcess)) { - log.info('Rendering diagram: ' + element.id); - /*! Check if previously processed */ - if (element.getAttribute('data-processed')) { - continue; - } - element.setAttribute('data-processed', 'true'); - - const id = `mermaid-${idGenerator.next()}`; - - // Fetch the graph definition including tags - txt = element.innerHTML; - - // transforms the html to pure text - txt = dedent(utils.entityDecode(txt)) // removes indentation, required for YAML parsing - .trim() - .replace(//gi, '
'); - - const init = utils.detectInit(txt); - if (init) { - log.debug('Detected early reinit: ', init); - } - try { - mermaidAPI.render( - id, - txt, - (svgCode: string, bindFunctions?: (el: Element) => void) => { - element.innerHTML = svgCode; - if (callback !== undefined) { - callback(id); - } - if (bindFunctions) { - bindFunctions(element); - } - }, - element - ); - } catch (error) { - handleError(error, errors, mermaid.parseError); - } - } - if (errors.length > 0) { - // TODO: We should be throwing an error object. - throw errors[0]; - } -}; - /** * This is an internal function and should not be made public, as it will likely change. * @internal @@ -204,10 +114,6 @@ const loadExternalDiagrams = async (...diagrams: ExternalDiagramDefinition[]) => /** * Equivalent to {@link init}, except an error will be thrown on error. * - * @alpha - * @deprecated This is an internal function and will very likely be modified in v10, or earlier. - * We recommend staying with {@link initThrowsErrors} if you don't need `lazyLoadedDiagrams`. - * * @param config - **Deprecated** Mermaid sequenceConfig. * @param nodes - One of: * - A DOM Node @@ -216,7 +122,7 @@ const loadExternalDiagrams = async (...diagrams: ExternalDiagramDefinition[]) => * @param callback - Function that is called with the id of each generated mermaid diagram. * @returns Resolves on success, otherwise the {@link Promise} will be rejected. */ -const initThrowsErrorsAsync = async function ( +const initThrowsErrors = async function ( config?: MermaidConfig, nodes?: string | HTMLElement | NodeListOf, // eslint-disable-next-line @typescript-eslint/ban-types @@ -282,7 +188,7 @@ const initThrowsErrorsAsync = async function ( log.debug('Detected early reinit: ', init); } try { - await mermaidAPI.renderAsync( + await mermaidAPI.render( id, txt, (svgCode: string, bindFunctions?: (el: Element) => void) => { @@ -369,10 +275,6 @@ const setParseErrorHandler = function (newParseErrorHandler: (err: any, hash: an mermaid.parseError = newParseErrorHandler; }; -const parse = (txt: string) => { - return mermaidAPI.parse(txt, mermaid.parseError); -}; - const executionQueue: (() => Promise)[] = []; let executionQueueRunning = false; const executeQueue = async () => { @@ -395,15 +297,14 @@ const executeQueue = async () => { /** * @param txt - The mermaid code to be parsed. - * @deprecated This is an internal function and should not be used. Will be removed in v10. */ -const parseAsync = (txt: string): Promise => { +const parse = (txt: string): Promise => { return new Promise((resolve, reject) => { // This promise will resolve when the mermaidAPI.render call is done. // It will be queued first and will be executed when it is first in line const performCall = () => new Promise((res, rej) => { - mermaidAPI.parseAsync(txt, mermaid.parseError).then( + mermaidAPI.parse(txt, mermaid.parseError).then( (r) => { // This resolves for the promise for the queue handling res(r); @@ -422,10 +323,7 @@ const parseAsync = (txt: string): Promise => { }); }; -/** - * @deprecated This is an internal function and should not be used. Will be removed in v10. - */ -const renderAsync = ( +const render = ( id: string, text: string, cb?: (svgCode: string, bindFunctions?: (element: Element) => void) => void, @@ -436,7 +334,7 @@ const renderAsync = ( // It will be queued first and will be executed when it is first in line const performCall = () => new Promise((res, rej) => { - mermaidAPI.renderAsync(id, text, cb, container).then( + mermaidAPI.render(id, text, cb, container).then( (r) => { // This resolves for the promise for the queue handling res(r); @@ -461,12 +359,9 @@ const mermaid: { parseError?: ParseErrorFunction; mermaidAPI: typeof mermaidAPI; parse: typeof parse; - parseAsync: typeof parseAsync; - render: typeof mermaidAPI.render; - renderAsync: typeof renderAsync; + render: typeof render; init: typeof init; initThrowsErrors: typeof initThrowsErrors; - initThrowsErrorsAsync: typeof initThrowsErrorsAsync; registerExternalDiagrams: typeof registerExternalDiagrams; initialize: typeof initialize; contentLoaded: typeof contentLoaded; @@ -476,12 +371,9 @@ const mermaid: { diagrams: {}, mermaidAPI, parse, - parseAsync, - render: mermaidAPI.render, - renderAsync, + render, init, initThrowsErrors, - initThrowsErrorsAsync, registerExternalDiagrams, initialize, parseError: undefined, diff --git a/packages/mermaid/src/mermaidAPI.spec.ts b/packages/mermaid/src/mermaidAPI.spec.ts index 67138435e..e86b9b15f 100644 --- a/packages/mermaid/src/mermaidAPI.spec.ts +++ b/packages/mermaid/src/mermaidAPI.spec.ts @@ -720,10 +720,10 @@ describe('mermaidAPI', function () { const diagramText = `${diagramType}\n accTitle: ${a11yTitle}\n accDescr: ${a11yDescr}\n`; const expectedDiagramType = testedDiagram.expectedType; - it('aria-roledscription is set to the diagram type, addSVGa11yTitleDescription is called', () => { + it('aria-roledscription is set to the diagram type, addSVGa11yTitleDescription is called', async () => { const a11yDiagramInfo_spy = vi.spyOn(accessibility, 'setA11yDiagramInfo'); const a11yTitleDesc_spy = vi.spyOn(accessibility, 'addSVGa11yTitleDescription'); - mermaidAPI.render(id, diagramText); + await mermaidAPI.render(id, diagramText); expect(a11yDiagramInfo_spy).toHaveBeenCalledWith( expect.anything(), expectedDiagramType @@ -735,7 +735,7 @@ describe('mermaidAPI', function () { }); }); - describe('renderAsync', () => { + describe('render', () => { // Be sure to add async before each test (anonymous) method // These are more like integration tests right now because nothing is mocked. @@ -775,7 +775,7 @@ describe('mermaidAPI', function () { it('aria-roledscription is set to the diagram type, addSVGa11yTitleDescription is called', async () => { const a11yDiagramInfo_spy = vi.spyOn(accessibility, 'setA11yDiagramInfo'); const a11yTitleDesc_spy = vi.spyOn(accessibility, 'addSVGa11yTitleDescription'); - await mermaidAPI.renderAsync(id, diagramText); + await mermaidAPI.render(id, diagramText); expect(a11yDiagramInfo_spy).toHaveBeenCalledWith( expect.anything(), expectedDiagramType diff --git a/packages/mermaid/src/mermaidAPI.ts b/packages/mermaid/src/mermaidAPI.ts index 55a3055eb..275ec656b 100644 --- a/packages/mermaid/src/mermaidAPI.ts +++ b/packages/mermaid/src/mermaidAPI.ts @@ -80,17 +80,7 @@ export type D3Element = any; * @param text - The mermaid diagram definition. * @param parseError - If set, handles errors. */ -function parse(text: string, parseError?: ParseErrorFunction): boolean { - addDiagrams(); - const diagram = new Diagram(text, parseError); - return diagram.parse(text, parseError); -} - -/** - * @param text - The mermaid diagram definition. - * @param parseError - If set, handles errors. - */ -async function parseAsync(text: string, parseError?: ParseErrorFunction): Promise { +async function parse(text: string, parseError?: ParseErrorFunction): Promise { addDiagrams(); const diagram = await getDiagramFromText(text, parseError); return diagram.parse(text, parseError); @@ -375,214 +365,8 @@ export const removeExistingElements = ( * element will be removed when rendering is completed. * @returns Returns the rendered element as a string containing the SVG definition. */ -const render = function ( - id: string, - text: string, - cb?: (svgCode: string, bindFunctions?: (element: Element) => void) => void, - svgContainingElement?: Element -): string { - addDiagrams(); - configApi.reset(); - - // Add Directives. Must do this before getting the config and before creating the diagram. - const graphInit = utils.detectInit(text); - if (graphInit) { - directiveSanitizer(graphInit); - configApi.addDirective(graphInit); - } - - const config = configApi.getConfig(); - log.debug(config); - - // Check the maximum allowed text size - // TODO: Remove magic number - if (text.length > (config?.maxTextSize ?? 50000)) { - text = MAX_TEXTLENGTH_EXCEEDED_MSG; - } - - // clean up text CRLFs - text = text.replace(/\r\n?/g, '\n'); // parser problems on CRLF ignore all CR and leave LF;; - - const idSelector = '#' + id; - const iFrameID = 'i' + id; - const iFrameID_selector = '#' + iFrameID; - const enclosingDivID = 'd' + id; - const enclosingDivID_selector = '#' + enclosingDivID; - - let root: any = select('body'); - - const isSandboxed = config.securityLevel === SECURITY_LVL_SANDBOX; - const isLooseSecurityLevel = config.securityLevel === SECURITY_LVL_LOOSE; - - const fontFamily = config.fontFamily; - - // ------------------------------------------------------------------------------- - // Define the root d3 node - // In regular execution the svgContainingElement will be the element with a mermaid class - - if (svgContainingElement !== undefined) { - if (svgContainingElement) { - svgContainingElement.innerHTML = ''; - } - - if (isSandboxed) { - // If we are in sandboxed mode, we do everything mermaid related in a (sandboxed )iFrame - const iframe = sandboxedIframe(select(svgContainingElement), iFrameID); - root = select(iframe.nodes()[0]!.contentDocument!.body); - root.node().style.margin = 0; - } else { - root = select(svgContainingElement); - } - appendDivSvgG(root, id, enclosingDivID, `font-family: ${fontFamily}`, XMLNS_XLINK_STD); - } else { - // No svgContainingElement was provided - - // If there is an existing element with the id, we remove it. This likely a previously rendered diagram - removeExistingElements(document, id, enclosingDivID, iFrameID); - - // Add the temporary div used for rendering with the enclosingDivID. - // This temporary div will contain a svg with the id == id - - if (isSandboxed) { - // If we are in sandboxed mode, we do everything mermaid related in a (sandboxed) iFrame - const iframe = sandboxedIframe(select('body'), iFrameID); - root = select(iframe.nodes()[0]!.contentDocument!.body); - root.node().style.margin = 0; - } else { - root = select('body'); - } - - appendDivSvgG(root, id, enclosingDivID); - } - - text = encodeEntities(text); - - // ------------------------------------------------------------------------------- - // Create the diagram - - // Important that we do not create the diagram until after the directives have been included - let diag; - let parseEncounteredException; - - try { - // diag = new Diagram(text); - diag = getDiagramFromText(text); - if ('then' in diag) { - throw new Error('Diagram is a promise. Use renderAsync.'); - } - } catch (error) { - diag = new Diagram('error'); - parseEncounteredException = error; - } - - // Get the temporary div element containing the svg (the parent HTML Element) - const element = root.select(enclosingDivID_selector).node(); - const graphType = diag.type; - - // ------------------------------------------------------------------------------- - // Create and insert the styles (user styles, theme styles, config styles) - // These are dealing with HTML Elements, not d3 nodes. - - // Insert an element into svg. This is where we put the styles - const svg = element.firstChild; - const firstChild = svg.firstChild; - const diagramClassDefs = CLASSDEF_DIAGRAMS.includes(graphType) - ? diag.renderer.getClasses(text, diag) - : {}; - - const rules = createUserStyles( - config, - graphType, - // @ts-ignore convert renderer to TS. - diagramClassDefs, - idSelector - ); - - // svg is a HTML element (not a d3 node) - const style1 = document.createElement('style'); - style1.innerHTML = rules; - svg.insertBefore(style1, firstChild); - - // ------------------------------------------------------------------------------- - // Draw the diagram with the renderer - try { - diag.renderer.draw(text, id, version, diag); - } catch (e) { - errorRenderer.draw(text, id, version); - throw e; - } - - // This is the d3 node for the svg element - const svgNode = root.select(`${enclosingDivID_selector} svg`); - const a11yTitle = diag.db.getAccTitle?.(); - const a11yDescr = diag.db.getAccDescription?.(); - addA11yInfo(graphType, svgNode, a11yTitle, a11yDescr); - - // ------------------------------------------------------------------------------- - // Clean up SVG code - root.select(`[id="${id}"]`).selectAll('foreignobject > *').attr('xmlns', XMLNS_XHTML_STD); - - // Fix for when the base tag is used - let svgCode = root.select(enclosingDivID_selector).node().innerHTML; - - log.debug('config.arrowMarkerAbsolute', config.arrowMarkerAbsolute); - svgCode = cleanUpSvgCode(svgCode, isSandboxed, evaluate(config.arrowMarkerAbsolute)); - - if (isSandboxed) { - const svgEl = root.select(enclosingDivID_selector + ' svg').node(); - svgCode = putIntoIFrame(svgCode, svgEl); - } else if (!isLooseSecurityLevel) { - // Sanitize the svgCode using DOMPurify - svgCode = DOMPurify.sanitize(svgCode, { - ADD_TAGS: DOMPURIFY_TAGS, - ADD_ATTR: DOMPURIFY_ATTR, - }); - } - - // ------------------------------------------------------------------------------- - // Do any callbacks (cb = callback) - if (cb !== undefined) { - switch (graphType) { - case 'flowchart': - case 'flowchart-v2': - cb(svgCode, flowDb.bindFunctions); - break; - case 'gantt': - cb(svgCode, ganttDb.bindFunctions); - break; - case 'class': - case 'classDiagram': - cb(svgCode, classDb.bindFunctions); - break; - default: - cb(svgCode); - } - } else { - log.debug('CB = undefined!'); - } - attachFunctions(); - - // ------------------------------------------------------------------------------- - // Remove the temporary element if appropriate - const tmpElementSelector = isSandboxed ? iFrameID_selector : enclosingDivID_selector; - const node = select(tmpElementSelector).node(); - if (node && 'remove' in node) { - node.remove(); - } - - if (parseEncounteredException) { - throw parseEncounteredException; - } - - return svgCode; -}; - -/** - * @deprecated This is an internal function and should not be used. Will be removed in v10. - */ - -const renderAsync = async function ( +const render = async function ( id: string, text: string, cb?: (svgCode: string, bindFunctions?: (element: Element) => void) => void, @@ -886,9 +670,7 @@ function addA11yInfo( export const mermaidAPI = Object.freeze({ render, - renderAsync, parse, - parseAsync, parseDirective, initialize, getConfig: configApi.getConfig, diff --git a/tests/webpack/src/index.js b/tests/webpack/src/index.js index 092972694..51738aa62 100644 --- a/tests/webpack/src/index.js +++ b/tests/webpack/src/index.js @@ -4,7 +4,7 @@ const mermaid = require('mermaid'); import mindmap from '@mermaid-js/mermaid-mindmap'; const render = async (graph) => { - const svg = await mermaid.renderAsync('dummy', graph); + const svg = await mermaid.render('dummy', graph); console.log(svg); document.getElementById('graphDiv').innerHTML = svg; }; From eaa84d2d910f1817e9744c019ef18a0ee7b97526 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Sun, 19 Feb 2023 13:08:13 +0530 Subject: [PATCH 32/67] feat: Break render and parse types Both render and parse are async now. Return type of render contains svg and bindFunctions. Parse will not throw error if parseOptions.silent is passed. --- V10-BreakingChanges.md | 22 ++++- .../interfaces/mermaidAPI.RenderResult.md | 78 ++++++++++++++++++ docs/config/setup/modules/mermaidAPI.md | 28 ++++--- packages/mermaid/src/Diagram.ts | 81 +++++-------------- .../mermaid/src/diagram-api/detectType.ts | 3 +- packages/mermaid/src/diagram-api/types.ts | 1 + .../src/diagrams/class/classRenderer-v2.js | 22 ----- .../src/diagrams/sequence/sequenceRenderer.ts | 5 +- packages/mermaid/src/errors.ts | 6 ++ packages/mermaid/src/mermaid.ts | 59 +++++++------- packages/mermaid/src/mermaidAPI.ts | 80 +++++++++--------- 11 files changed, 213 insertions(+), 172 deletions(-) create mode 100644 docs/config/setup/interfaces/mermaidAPI.RenderResult.md create mode 100644 packages/mermaid/src/errors.ts diff --git a/V10-BreakingChanges.md b/V10-BreakingChanges.md index bd9110d1a..e3322a3a1 100644 --- a/V10-BreakingChanges.md +++ b/V10-BreakingChanges.md @@ -1,5 +1,25 @@ -# A collection of updates that change the behaviour +# A collection of updates that change the behavior + +## Async + +`init`, `parse`, `render` are now async. ## Lazy loading and asynchronisity - Invalid dates are rendered as syntax error instead of returning best guess or the current date + +## ParseError is removed + +```js +//< v10.0.0 +mermaid.parse(text, parseError); + +//>= v10.0.0 +await mermaid.parse(text).catch(parseError); +// or +try { + await mermaid.parse(text); +} catch (err) { + parseError(err); +} +``` diff --git a/docs/config/setup/interfaces/mermaidAPI.RenderResult.md b/docs/config/setup/interfaces/mermaidAPI.RenderResult.md new file mode 100644 index 000000000..b95b0acff --- /dev/null +++ b/docs/config/setup/interfaces/mermaidAPI.RenderResult.md @@ -0,0 +1,78 @@ +> **Warning** +> +> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. +> +> ## Please edit the corresponding file in [/packages/mermaid/src/docs/config/setup/interfaces/mermaidAPI.RenderResult.md](../../../../packages/mermaid/src/docs/config/setup/interfaces/mermaidAPI.RenderResult.md). + +# Interface: RenderResult + +[mermaidAPI](../modules/mermaidAPI.md).RenderResult + +Function that renders an svg with a graph from a chart definition. Usage example below. + +```javascript +mermaidAPI.initialize({ + startOnLoad: true, +}); +$(function () { + const graphDefinition = 'graph TB\na-->b'; + const cb = function (svgGraph) { + console.log(svgGraph); + }; + mermaidAPI.render('id1', graphDefinition, cb); +}); +``` + +**`Param`** + +The id for the SVG element (the element to be rendered) + +**`Param`** + +The text for the graph definition + +**`Param`** + +Callback which is called after rendering is finished with the svg code as in param. + +**`Param`** + +HTML element where the svg will be inserted. (Is usually element with the .mermaid class) +If no svgContainingElement is provided then the SVG element will be appended to the body. +Selector to element in which a div with the graph temporarily will be +inserted. If one is provided a hidden div will be inserted in the body of the page instead. The +element will be removed when rendering is completed. + +## Properties + +### bindFunctions + +• `Optional` **bindFunctions**: (`element`: `Element`) => `void` + +#### Type declaration + +▸ (`element`): `void` + +##### Parameters + +| Name | Type | +| :-------- | :-------- | +| `element` | `Element` | + +##### Returns + +`void` + +#### Defined in + +[mermaidAPI.ts:382](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L382) + +--- + +### svg + +• **svg**: `string` + +#### Defined in + +[mermaidAPI.ts:381](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L381) diff --git a/docs/config/setup/modules/mermaidAPI.md b/docs/config/setup/modules/mermaidAPI.md index 2cdeb597a..f75dd85c7 100644 --- a/docs/config/setup/modules/mermaidAPI.md +++ b/docs/config/setup/modules/mermaidAPI.md @@ -6,6 +6,10 @@ # Module: mermaidAPI +## Interfaces + +- [RenderResult](../interfaces/mermaidAPI.RenderResult.md) + ## References ### default @@ -20,13 +24,13 @@ Renames and re-exports [mermaidAPI](mermaidAPI.md#mermaidapi) #### Defined in -[mermaidAPI.ts:75](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L75) +[mermaidAPI.ts:71](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L71) ## Variables ### mermaidAPI -• `Const` **mermaidAPI**: `Readonly`<{ `defaultConfig`: `MermaidConfig` = configApi.defaultConfig; `getConfig`: () => `MermaidConfig` = configApi.getConfig; `getSiteConfig`: () => `MermaidConfig` = configApi.getSiteConfig; `globalReset`: () => `void` ; `initialize`: (`options`: `MermaidConfig`) => `void` ; `parse`: (`text`: `string`, `parseError?`: `ParseErrorFunction`) => `Promise`<`boolean`> ; `parseDirective`: (`p`: `any`, `statement`: `string`, `context`: `string`, `type`: `string`) => `void` ; `render`: (`id`: `string`, `text`: `string`, `cb?`: (`svgCode`: `string`, `bindFunctions?`: (`element`: `Element`) => `void`) => `void`, `svgContainingElement?`: `Element`) => `Promise`<`string`> ; `reset`: () => `void` ; `setConfig`: (`conf`: `MermaidConfig`) => `MermaidConfig` = configApi.setConfig; `updateSiteConfig`: (`conf`: `MermaidConfig`) => `MermaidConfig` = configApi.updateSiteConfig }> +• `Const` **mermaidAPI**: `Readonly`<{ `defaultConfig`: `MermaidConfig` = configApi.defaultConfig; `getConfig`: () => `MermaidConfig` = configApi.getConfig; `getSiteConfig`: () => `MermaidConfig` = configApi.getSiteConfig; `globalReset`: () => `void` ; `initialize`: (`options`: `MermaidConfig`) => `void` ; `parse`: (`text`: `string`, `parseOptions?`: { `silent?`: `boolean` }) => `Promise`<`boolean` | `void`> ; `parseDirective`: (`p`: `any`, `statement`: `string`, `context`: `string`, `type`: `string`) => `void` ; `render`: (`id`: `string`, `text`: `string`, `svgContainingElement?`: `Element`) => `Promise`<[`RenderResult`](../interfaces/mermaidAPI.RenderResult.md)> ; `reset`: () => `void` ; `setConfig`: (`conf`: `MermaidConfig`) => `MermaidConfig` = configApi.setConfig; `updateSiteConfig`: (`conf`: `MermaidConfig`) => `MermaidConfig` = configApi.updateSiteConfig }> ## mermaidAPI configuration defaults @@ -90,7 +94,7 @@ mermaid.initialize(config); #### Defined in -[mermaidAPI.ts:671](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L671) +[mermaidAPI.ts:666](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L666) ## Functions @@ -121,7 +125,7 @@ Return the last node appended #### Defined in -[mermaidAPI.ts:278](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L278) +[mermaidAPI.ts:289](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L289) --- @@ -147,7 +151,7 @@ the cleaned up svgCode #### Defined in -[mermaidAPI.ts:229](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L229) +[mermaidAPI.ts:240](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L240) --- @@ -173,7 +177,7 @@ the string with all the user styles #### Defined in -[mermaidAPI.ts:158](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L158) +[mermaidAPI.ts:169](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L169) --- @@ -196,7 +200,7 @@ the string with all the user styles #### Defined in -[mermaidAPI.ts:206](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L206) +[mermaidAPI.ts:217](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L217) --- @@ -223,7 +227,7 @@ with an enclosing block that has each of the cssClasses followed by !important; #### Defined in -[mermaidAPI.ts:142](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L142) +[mermaidAPI.ts:153](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L153) --- @@ -243,7 +247,7 @@ with an enclosing block that has each of the cssClasses followed by !important; #### Defined in -[mermaidAPI.ts:122](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L122) +[mermaidAPI.ts:133](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L133) --- @@ -263,7 +267,7 @@ with an enclosing block that has each of the cssClasses followed by !important; #### Defined in -[mermaidAPI.ts:93](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L93) +[mermaidAPI.ts:104](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L104) --- @@ -289,7 +293,7 @@ Put the svgCode into an iFrame. Return the iFrame code #### Defined in -[mermaidAPI.ts:257](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L257) +[mermaidAPI.ts:268](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L268) --- @@ -314,4 +318,4 @@ Remove any existing elements from the given document #### Defined in -[mermaidAPI.ts:328](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L328) +[mermaidAPI.ts:339](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L339) diff --git a/packages/mermaid/src/Diagram.ts b/packages/mermaid/src/Diagram.ts index 1f68e52ba..3a0818854 100644 --- a/packages/mermaid/src/Diagram.ts +++ b/packages/mermaid/src/Diagram.ts @@ -3,26 +3,24 @@ import { log } from './logger'; import { getDiagram, registerDiagram } from './diagram-api/diagramAPI'; import { detectType, getDiagramLoader } from './diagram-api/detectType'; import { extractFrontMatter } from './diagram-api/frontmatter'; -import { isDetailedError } from './utils'; -import type { DetailedError } from './utils'; +import { UnknownDiagramError } from './errors'; +import { DetailedError } from './utils'; export type ParseErrorFunction = (err: string | DetailedError | unknown, hash?: any) => void; - export class Diagram { type = 'graph'; parser; renderer; db; - private detectTypeFailed = false; - constructor(public txt: string, parseError?: ParseErrorFunction) { + private detectError?: UnknownDiagramError; + constructor(public text: string) { + this.text += '\n'; const cnf = configApi.getConfig(); - this.txt = txt; try { - this.type = detectType(txt, cnf); + this.type = detectType(text, cnf); } catch (e) { - this.handleError(e, parseError); this.type = 'error'; - this.detectTypeFailed = true; + this.detectError = e as UnknownDiagramError; } const diagram = getDiagram(this.type); log.debug('Type ' + this.type); @@ -46,44 +44,19 @@ export class Diagram { diagram.init(cnf); log.info('Initialized diagram ' + this.type, cnf); } - this.txt += '\n'; - - this.parse(this.txt, parseError); + this.parse(); } - parse(text: string, parseError?: ParseErrorFunction): boolean { - if (this.detectTypeFailed) { - return false; + parse() { + if (this.detectError) { + throw this.detectError; } - try { - text = text + '\n'; - this.db.clear?.(); - this.parser.parse(text); - return true; - } catch (error) { - this.handleError(error, parseError); - } - return false; + this.db.clear?.(); + this.parser.parse(this.text); } - handleError(error: unknown, parseError?: ParseErrorFunction) { - // Is this the correct way to access mermaid's parseError() - // method ? (or global.mermaid.parseError()) ? - - if (parseError === undefined) { - // No mermaid.parseError() handler defined, so re-throw it - throw error; - } - - if (isDetailedError(error)) { - // Handle case where error string and hash were - // wrapped in object like`const error = { str, hash };` - parseError(error.str, error.hash); - return; - } - - // Otherwise, assume it is just an error string and pass it on - parseError(error as string); + async render(id: string, version: string) { + await this.renderer.draw(this.text, id, version, this); } getParser() { @@ -95,10 +68,7 @@ export class Diagram { } } -export const getDiagramFromText = ( - txt: string, - parseError?: ParseErrorFunction -): Diagram | Promise => { +export const getDiagramFromText = async (txt: string): Promise => { const type = detectType(txt, configApi.getConfig()); try { // Trying to find the diagram @@ -106,19 +76,12 @@ export const getDiagramFromText = ( } catch (error) { const loader = getDiagramLoader(type); if (!loader) { - throw new Error(`Diagram ${type} not found.`); + throw new UnknownDiagramError(`Diagram ${type} not found.`); } - // TODO: Uncomment for v10 - // // Diagram not available, loading it - // const { diagram } = await loader(); - // registerDiagram(type, diagram, undefined, diagram.injectUtils); - // // new diagram will try getDiagram again and if fails then it is a valid throw - return loader().then(({ diagram }) => { - registerDiagram(type, diagram, undefined); - return new Diagram(txt, parseError); - }); + // Diagram not available, loading it + // new diagram will try getDiagram again and if fails then it is a valid throw + const { id, diagram } = await loader(); + registerDiagram(id, diagram); } - return new Diagram(txt, parseError); + return new Diagram(txt); }; - -export default Diagram; diff --git a/packages/mermaid/src/diagram-api/detectType.ts b/packages/mermaid/src/diagram-api/detectType.ts index b75e914fb..3c9237e5b 100644 --- a/packages/mermaid/src/diagram-api/detectType.ts +++ b/packages/mermaid/src/diagram-api/detectType.ts @@ -7,6 +7,7 @@ import type { ExternalDiagramDefinition, } from './types'; import { frontMatterRegex } from './frontmatter'; +import { UnknownDiagramError } from '../errors'; const directive = /%{2}{\s*(?:(\w+)\s*:|(\w+))\s*(?:(\w+)|((?:(?!}%{2}).|\r?\n)*))?\s*(?:}%{2})?/gi; const anyComment = /\s*%%.*\n/gm; @@ -44,7 +45,7 @@ export const detectType = function (text: string, config?: MermaidConfig): strin } } - throw new Error(`No diagram type detected for text: ${text}`); + throw new UnknownDiagramError(`No diagram type detected for text: ${text}`); }; export const registerLazyLoadedDiagrams = (...diagrams: ExternalDiagramDefinition[]) => { diff --git a/packages/mermaid/src/diagram-api/types.ts b/packages/mermaid/src/diagram-api/types.ts index d60019577..081136563 100644 --- a/packages/mermaid/src/diagram-api/types.ts +++ b/packages/mermaid/src/diagram-api/types.ts @@ -18,6 +18,7 @@ export interface DiagramDb { setDiagramTitle?: (title: string) => void; getAccTitle?: () => string; getAccDescription?: () => string; + bindFunctions?: (element: Element) => void; } export interface DiagramDefinition { diff --git a/packages/mermaid/src/diagrams/class/classRenderer-v2.js b/packages/mermaid/src/diagrams/class/classRenderer-v2.js index d95c29fd5..b7e538583 100644 --- a/packages/mermaid/src/diagrams/class/classRenderer-v2.js +++ b/packages/mermaid/src/diagrams/class/classRenderer-v2.js @@ -348,19 +348,6 @@ export const setConf = function (cnf) { */ export const draw = function (text, id, _version, diagObj) { log.info('Drawing class - ', id); - // diagObj.db.clear(); - // const parser = diagObj.db.parser; - // parser.yy = classDb; - - // Parse the graph definition - // try { - // parser.parse(text); - // } catch (err) { - // log.debug('Parsing failed'); - // } - - // Fetch the default direction, use TD if none was found - //let dir = 'TD'; const conf = getConfig().flowchart; const securityLevel = getConfig().securityLevel; @@ -384,15 +371,6 @@ export const draw = function (text, id, _version, diagObj) { return {}; }); - // let subG; - // const subGraphs = flowDb.getSubGraphs(); - // log.info('Subgraphs - ', subGraphs); - // for (let i = subGraphs.length - 1; i >= 0; i--) { - // subG = subGraphs[i]; - // log.info('Subgraph - ', subG); - // flowDb.addVertex(subG.id, subG.title, 'group', undefined, subG.classes); - // } - // Fetch the vertices/nodes and edges/links from the parsed graph definition const classes = diagObj.db.getClasses(); const relations = diagObj.db.getRelations(); diff --git a/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts b/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts index e4ce05350..acee7bbe5 100644 --- a/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts +++ b/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts @@ -2,15 +2,12 @@ import { select, selectAll } from 'd3'; import svgDraw, { drawText, fixLifeLineHeights } from './svgDraw'; import { log } from '../../logger'; -// import { parser } from './parser/sequenceDiagram'; import common from '../common/common'; -// import sequenceDb from './sequenceDb'; import * as configApi from '../../config'; import assignWithDepth from '../../assignWithDepth'; import utils from '../../utils'; import { configureSvgSize } from '../../setupGraphViewbox'; -import Diagram from '../../Diagram'; -import { convert } from '../../tests/util'; +import { Diagram } from '../../Diagram'; let conf = {}; diff --git a/packages/mermaid/src/errors.ts b/packages/mermaid/src/errors.ts new file mode 100644 index 000000000..e3650c5a9 --- /dev/null +++ b/packages/mermaid/src/errors.ts @@ -0,0 +1,6 @@ +export class UnknownDiagramError extends Error { + constructor(message: string) { + super(message); + this.name = 'UnknownDiagramError'; + } +} diff --git a/packages/mermaid/src/mermaid.ts b/packages/mermaid/src/mermaid.ts index 540e0368e..c4499bbc3 100644 --- a/packages/mermaid/src/mermaid.ts +++ b/packages/mermaid/src/mermaid.ts @@ -7,7 +7,7 @@ import dedent from 'ts-dedent'; import { MermaidConfig } from './config.type'; import { log } from './logger'; import utils from './utils'; -import { mermaidAPI } from './mermaidAPI'; +import { mermaidAPI, RenderResult } from './mermaidAPI'; import { registerLazyLoadedDiagrams } from './diagram-api/detectType'; import type { ParseErrorFunction } from './Diagram'; import { isDetailedError } from './utils'; @@ -44,10 +44,8 @@ export type { MermaidConfig, DetailedError, ExternalDiagramDefinition, ParseErro */ const init = async function ( config?: MermaidConfig, - // eslint-disable-next-line no-undef nodes?: string | HTMLElement | NodeListOf, - // eslint-disable-next-line @typescript-eslint/ban-types - callback?: Function + callback?: (id: string) => unknown ) { try { await initThrowsErrors(config, nodes, callback); @@ -125,8 +123,7 @@ const loadExternalDiagrams = async (...diagrams: ExternalDiagramDefinition[]) => const initThrowsErrors = async function ( config?: MermaidConfig, nodes?: string | HTMLElement | NodeListOf, - // eslint-disable-next-line @typescript-eslint/ban-types - callback?: Function + callback?: (id: string) => unknown ) { const conf = mermaidAPI.getConfig(); @@ -188,20 +185,14 @@ const initThrowsErrors = async function ( log.debug('Detected early reinit: ', init); } try { - await mermaidAPI.render( - id, - txt, - (svgCode: string, bindFunctions?: (el: Element) => void) => { - element.innerHTML = svgCode; - if (callback !== undefined) { - callback(id); - } - if (bindFunctions) { - bindFunctions(element); - } - }, - element - ); + const { svg, bindFunctions } = await mermaidAPI.render(id, txt, element); + element.innerHTML = svg; + if (callback) { + callback(id); + } + if (bindFunctions) { + bindFunctions(element); + } } catch (error) { handleError(error, errors, mermaid.parseError); } @@ -296,15 +287,24 @@ const executeQueue = async () => { }; /** - * @param txt - The mermaid code to be parsed. + * Parse the text and validate the syntax. + * @param text - The mermaid diagram definition. + * @param parseOptions - Options for parsing. + * @returns true if the diagram is valid, false otherwise if parseOptions.silent is true. + * @throws Error if the diagram is invalid and parseOptions.silent is false. */ -const parse = (txt: string): Promise => { +const parse = async ( + text: string, + parseOptions?: { + silent?: boolean; + } +): Promise => { return new Promise((resolve, reject) => { // This promise will resolve when the mermaidAPI.render call is done. // It will be queued first and will be executed when it is first in line const performCall = () => new Promise((res, rej) => { - mermaidAPI.parse(txt, mermaid.parseError).then( + mermaidAPI.parse(text, parseOptions).then( (r) => { // This resolves for the promise for the queue handling res(r); @@ -313,6 +313,7 @@ const parse = (txt: string): Promise => { }, (e) => { log.error('Error parsing', e); + mermaid.parseError?.(e); rej(e); reject(e); } @@ -323,18 +324,13 @@ const parse = (txt: string): Promise => { }); }; -const render = ( - id: string, - text: string, - cb?: (svgCode: string, bindFunctions?: (element: Element) => void) => void, - container?: Element -): Promise => { +const render = (id: string, text: string, container?: Element): Promise => { return new Promise((resolve, reject) => { // This promise will resolve when the mermaidAPI.render call is done. // It will be queued first and will be executed when it is first in line const performCall = () => new Promise((res, rej) => { - mermaidAPI.render(id, text, cb, container).then( + mermaidAPI.render(id, text, container).then( (r) => { // This resolves for the promise for the queue handling res(r); @@ -343,6 +339,7 @@ const render = ( }, (e) => { log.error('Error parsing', e); + mermaid.parseError?.(e); rej(e); reject(e); } @@ -355,7 +352,6 @@ const render = ( const mermaid: { startOnLoad: boolean; - diagrams: any; parseError?: ParseErrorFunction; mermaidAPI: typeof mermaidAPI; parse: typeof parse; @@ -368,7 +364,6 @@ const mermaid: { setParseErrorHandler: typeof setParseErrorHandler; } = { startOnLoad: true, - diagrams: {}, mermaidAPI, parse, render, diff --git a/packages/mermaid/src/mermaidAPI.ts b/packages/mermaid/src/mermaidAPI.ts index 275ec656b..5a71bb08e 100644 --- a/packages/mermaid/src/mermaidAPI.ts +++ b/packages/mermaid/src/mermaidAPI.ts @@ -17,11 +17,7 @@ import { compile, serialize, stringify } from 'stylis'; import { version } from '../package.json'; import * as configApi from './config'; import { addDiagrams } from './diagram-api/diagram-orchestration'; -import classDb from './diagrams/class/classDb'; -import flowDb from './diagrams/flowchart/flowDb'; -import ganttDb from './diagrams/gantt/ganttDb'; -import Diagram, { getDiagramFromText } from './Diagram'; -import type { ParseErrorFunction } from './Diagram'; +import { Diagram, getDiagramFromText } from './Diagram'; import errorRenderer from './diagrams/error/errorRenderer'; import { attachFunctions } from './interactionDb'; import { log, setLogLevel } from './logger'; @@ -37,7 +33,7 @@ import { parseDirective } from './directiveUtils'; // diagram names that support classDef statements const CLASSDEF_DIAGRAMS = ['graph', 'flowchart', 'flowchart-v2', 'stateDiagram', 'stateDiagram-v2']; - +const MAX_TEXTLENGTH = 50_000; const MAX_TEXTLENGTH_EXCEEDED_MSG = 'graph TB;a[Maximum text size in diagram exceeded];style a fill:#faa'; @@ -74,16 +70,34 @@ interface DiagramStyleClassDef { // @ts-ignore Could replicate the type definition in d3. This also makes it possible to use the untyped info from the js diagram files. export type D3Element = any; -// ---------------------------------------------------------------------------- - /** + * Parse the text and validate the syntax. * @param text - The mermaid diagram definition. - * @param parseError - If set, handles errors. + * @param parseOptions - Options for parsing. + * @returns true if the diagram is valid, false otherwise if parseOptions.silent is true. + * @throws Error if the diagram is invalid and parseOptions.silent is false. */ -async function parse(text: string, parseError?: ParseErrorFunction): Promise { + +async function parse( + text: string, + parseOptions?: { + silent?: boolean; + } +): Promise { addDiagrams(); - const diagram = await getDiagramFromText(text, parseError); - return diagram.parse(text, parseError); + let error; + try { + const diagram = await getDiagramFromText(text); + diagram.parse(); + } catch (err) { + error = err; + } + if (parseOptions?.silent) { + return error === undefined; + } + if (error) { + throw error; + } } /** @@ -366,12 +380,16 @@ export const removeExistingElements = ( * @returns Returns the rendered element as a string containing the SVG definition. */ +export interface RenderResult { + svg: string; + bindFunctions?: (element: Element) => void; +} + const render = async function ( id: string, text: string, - cb?: (svgCode: string, bindFunctions?: (element: Element) => void) => void, svgContainingElement?: Element -): Promise { +): Promise { addDiagrams(); configApi.reset(); @@ -387,8 +405,7 @@ const render = async function ( log.debug(config); // Check the maximum allowed text size - // TODO: Remove magic number - if (text.length > (config?.maxTextSize ?? 50000)) { + if (text.length > (config?.maxTextSize ?? MAX_TEXTLENGTH)) { text = MAX_TEXTLENGTH_EXCEEDED_MSG; } @@ -453,11 +470,10 @@ const render = async function ( // Create the diagram // Important that we do not create the diagram until after the directives have been included - let diag; + let diag: Diagram; let parseEncounteredException; try { - // diag = new Diagram(text); diag = await getDiagramFromText(text); } catch (error) { diag = new Diagram('error'); @@ -510,7 +526,7 @@ const render = async function ( root.select(`[id="${id}"]`).selectAll('foreignobject > *').attr('xmlns', XMLNS_XHTML_STD); // Fix for when the base tag is used - let svgCode = root.select(enclosingDivID_selector).node().innerHTML; + let svgCode: string = root.select(enclosingDivID_selector).node().innerHTML; log.debug('config.arrowMarkerAbsolute', config.arrowMarkerAbsolute); svgCode = cleanUpSvgCode(svgCode, isSandboxed, evaluate(config.arrowMarkerAbsolute)); @@ -526,27 +542,6 @@ const render = async function ( }); } - // ------------------------------------------------------------------------------- - // Do any callbacks (cb = callback) - if (cb !== undefined) { - switch (graphType) { - case 'flowchart': - case 'flowchart-v2': - cb(svgCode, flowDb.bindFunctions); - break; - case 'gantt': - cb(svgCode, ganttDb.bindFunctions); - break; - case 'class': - case 'classDiagram': - cb(svgCode, classDb.bindFunctions); - break; - default: - cb(svgCode); - } - } else { - log.debug('CB = undefined!'); - } attachFunctions(); // ------------------------------------------------------------------------------- @@ -561,7 +556,10 @@ const render = async function ( throw parseEncounteredException; } - return svgCode; + return { + svg: svgCode, + bindFunctions: diag.db.bindFunctions, + }; }; /** From d2927435ab18ee172a544ad648fc49812ad84289 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Sun, 19 Feb 2023 13:09:31 +0530 Subject: [PATCH 33/67] Fix tests --- packages/mermaid/src/__mocks__/mermaidAPI.ts | 19 +- packages/mermaid/src/diagram.spec.ts | 31 +- .../flowchart/flowRenderer.addEdges.spec.js | 2 +- .../diagrams/sequence/sequenceDiagram.spec.js | 350 +++++++++--------- packages/mermaid/src/mermaid.spec.ts | 47 +-- packages/mermaid/src/mermaidAPI.spec.ts | 77 ++-- 6 files changed, 267 insertions(+), 259 deletions(-) diff --git a/packages/mermaid/src/__mocks__/mermaidAPI.ts b/packages/mermaid/src/__mocks__/mermaidAPI.ts index 50018bcad..95b87d990 100644 --- a/packages/mermaid/src/__mocks__/mermaidAPI.ts +++ b/packages/mermaid/src/__mocks__/mermaidAPI.ts @@ -5,23 +5,14 @@ */ import * as configApi from '../config'; import { vi } from 'vitest'; -import { addDiagrams } from '../diagram-api/diagram-orchestration'; -import Diagram, { type ParseErrorFunction } from '../Diagram'; - -// Normally, we could just do the following to get the original `parse()` -// implementation, however, requireActual returns a promise and it's not documented how to use withing mock file. - -/** {@inheritDoc mermaidAPI.parse} */ -function parse(text: string, parseError?: ParseErrorFunction): boolean { - addDiagrams(); - const diagram = new Diagram(text, parseError); - return diagram.parse(text, parseError); -} +import { mermaidAPI as mAPI } from '../mermaidAPI'; // original version cannot be modified since it was frozen with `Object.freeze()` export const mermaidAPI = { - render: vi.fn(), - parse, + render: vi.fn().mockResolvedValue({ + svg: '', + }), + parse: mAPI.parse, parseDirective: vi.fn(), initialize: vi.fn(), getConfig: configApi.getConfig, diff --git a/packages/mermaid/src/diagram.spec.ts b/packages/mermaid/src/diagram.spec.ts index ebe088a86..a862c7936 100644 --- a/packages/mermaid/src/diagram.spec.ts +++ b/packages/mermaid/src/diagram.spec.ts @@ -1,18 +1,18 @@ import { describe, test, expect } from 'vitest'; -import Diagram, { getDiagramFromText } from './Diagram'; +import { Diagram, getDiagramFromText } from './Diagram'; import { addDetector } from './diagram-api/detectType'; import { addDiagrams } from './diagram-api/diagram-orchestration'; addDiagrams(); describe('diagram detection', () => { - test('should detect inbuilt diagrams', () => { - const graph = getDiagramFromText('graph TD; A-->B') as Diagram; + test('should detect inbuilt diagrams', async () => { + const graph = (await getDiagramFromText('graph TD; A-->B')) as Diagram; expect(graph).toBeInstanceOf(Diagram); expect(graph.type).toBe('flowchart-v2'); - const sequence = getDiagramFromText( + const sequence = (await getDiagramFromText( 'sequenceDiagram; Alice->>+John: Hello John, how are you?' - ) as Diagram; + )) as Diagram; expect(sequence).toBeInstanceOf(Diagram); expect(sequence.type).toBe('sequence'); }); @@ -44,14 +44,15 @@ describe('diagram detection', () => { expect(diagram.type).toBe('loki'); }); - test('should throw the right error for incorrect diagram', () => { - expect(() => getDiagramFromText('graph TD; A-->')).toThrowErrorMatchingInlineSnapshot(` -"Parse error on line 3: -graph TD; A--> ---------------^ -Expecting 'AMP', 'ALPHA', 'COLON', 'PIPE', 'TESTSTR', 'DOWN', 'DEFAULT', 'NUM', 'COMMA', 'MINUS', 'BRKT', 'DOT', 'PUNCTUATION', 'UNICODE_TEXT', 'PLUS', 'EQUALS', 'MULT', 'UNDERSCORE', got 'EOF'" - `); - expect(() => getDiagramFromText('sequenceDiagram; A-->B')).toThrowErrorMatchingInlineSnapshot(` + test('should throw the right error for incorrect diagram', async () => { + await expect(getDiagramFromText('graph TD; A-->')).rejects.toThrowErrorMatchingInlineSnapshot(` + "Parse error on line 2: + graph TD; A--> + --------------^ + Expecting 'AMP', 'ALPHA', 'COLON', 'PIPE', 'TESTSTR', 'DOWN', 'DEFAULT', 'NUM', 'COMMA', 'MINUS', 'BRKT', 'DOT', 'PUNCTUATION', 'UNICODE_TEXT', 'PLUS', 'EQUALS', 'MULT', 'UNDERSCORE', got 'EOF'" + `); + await expect(getDiagramFromText('sequenceDiagram; A-->B')).rejects + .toThrowErrorMatchingInlineSnapshot(` "Parse error on line 1: ...quenceDiagram; A-->B -----------------------^ @@ -59,8 +60,8 @@ Expecting 'TXT', got 'NEWLINE'" `); }); - test('should throw the right error for unregistered diagrams', () => { - expect(() => getDiagramFromText('thor TD; A-->B')).toThrowError( + test('should throw the right error for unregistered diagrams', async () => { + await expect(getDiagramFromText('thor TD; A-->B')).rejects.toThrowError( 'No diagram type detected for text: thor TD; A-->B' ); }); diff --git a/packages/mermaid/src/diagrams/flowchart/flowRenderer.addEdges.spec.js b/packages/mermaid/src/diagrams/flowchart/flowRenderer.addEdges.spec.js index 41868e203..01b6163cb 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowRenderer.addEdges.spec.js +++ b/packages/mermaid/src/diagrams/flowchart/flowRenderer.addEdges.spec.js @@ -1,7 +1,7 @@ import flowDb from './flowDb'; import flowParser from './parser/flow'; import flowRenderer from './flowRenderer'; -import Diagram from '../../Diagram'; +import { Diagram } from '../../Diagram'; import { addDiagrams } from '../../diagram-api/diagram-orchestration'; addDiagrams(); diff --git a/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js b/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js index 80850c2f2..72daca932 100644 --- a/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js +++ b/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js @@ -2,7 +2,7 @@ import { vi } from 'vitest'; import * as configApi from '../../config'; import mermaidAPI from '../../mermaidAPI'; -import Diagram from '../../Diagram'; +import { Diagram } from '../../Diagram'; import { addDiagrams } from '../../diagram-api/diagram-orchestration'; /** @@ -176,14 +176,14 @@ Note right of Bob: Bob thinks Bob-->Alice: I am good thanks!`); diagram.db.clear(); }); - it('should handle a sequenceDiagram definition', function () { + it('should handle a sequenceDiagram definition', async function () { const str = ` sequenceDiagram Alice->Bob:Hello Bob, how are you? Note right of Bob: Bob thinks Bob-->Alice: I am good thanks!`; - mermaidAPI.parse(str, diagram); + await mermaidAPI.parse(str, diagram); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); actors.Bob.description = 'Bob'; @@ -194,18 +194,18 @@ Bob-->Alice: I am good thanks!`; expect(messages[0].from).toBe('Alice'); expect(messages[2].from).toBe('Bob'); }); - it('should not show sequence numbers per default', function () { + it('should not show sequence numbers per default', async () => { const str = ` sequenceDiagram Alice->Bob:Hello Bob, how are you? Note right of Bob: Bob thinks Bob-->Alice: I am good thanks!`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); diagram.renderer.draw(str, 'tst', '1.2.3', diagram); // needs to be rendered for the correct value of visibility auto numbers expect(diagram.db.showSequenceNumbers()).toBe(false); }); - it('should show sequence numbers when autonumber is enabled', function () { + it('should show sequence numbers when autonumber is enabled', async () => { const str = ` sequenceDiagram autonumber @@ -213,11 +213,11 @@ Alice->Bob:Hello Bob, how are you? Note right of Bob: Bob thinks Bob-->Alice: I am good thanks!`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); diagram.renderer.draw(str, 'tst', '1.2.3', diagram); // needs to be rendered for the correct value of visibility auto numbers expect(diagram.db.showSequenceNumbers()).toBe(true); }); - it('should handle a sequenceDiagram definition with a title:', function () { + it('should handle a sequenceDiagram definition with a title:', async () => { const str = ` sequenceDiagram title: Diagram Title @@ -225,7 +225,7 @@ Alice->Bob:Hello Bob, how are you? Note right of Bob: Bob thinks Bob-->Alice: I am good thanks!`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); actors.Bob.description = 'Bob'; @@ -240,7 +240,7 @@ Bob-->Alice: I am good thanks!`; expect(title).toBe('Diagram Title'); }); - it('should handle a sequenceDiagram definition with a title without a :', function () { + it('should handle a sequenceDiagram definition with a title without a :', async () => { const str = ` sequenceDiagram title Diagram Title @@ -248,7 +248,7 @@ Alice->Bob:Hello Bob, how are you? Note right of Bob: Bob thinks Bob-->Alice: I am good thanks!`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); actors.Bob.description = 'Bob'; @@ -263,7 +263,7 @@ Bob-->Alice: I am good thanks!`; expect(title).toBe('Diagram Title'); }); - it('should handle a sequenceDiagram definition with a accessibility title and description (accDescr)', function () { + it('should handle a sequenceDiagram definition with a accessibility title and description (accDescr)', async () => { const str = ` sequenceDiagram title: Diagram Title @@ -272,13 +272,13 @@ accDescr: Accessibility Description Alice->Bob:Hello Bob, how are you? `; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); expect(diagram.db.getDiagramTitle()).toBe('Diagram Title'); expect(diagram.db.getAccTitle()).toBe('This is the title'); expect(diagram.db.getAccDescription()).toBe('Accessibility Description'); const messages = diagram.db.getMessages(); }); - it('should handle a sequenceDiagram definition with a accessibility title and multiline description (accDescr)', function () { + it('should handle a sequenceDiagram definition with a accessibility title and multiline description (accDescr)', async () => { const str = ` sequenceDiagram accTitle: This is the title @@ -289,19 +289,19 @@ Description Alice->Bob:Hello Bob, how are you? `; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); expect(diagram.db.getAccTitle()).toBe('This is the title'); expect(diagram.db.getAccDescription()).toBe('Accessibility\nDescription'); const messages = diagram.db.getMessages(); }); - it('should space in actor names', function () { + it('should space in actor names', async () => { const str = ` sequenceDiagram Alice->Bob:Hello Bob, how are - you? Bob-->Alice: I am good thanks!`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); actors.Bob.description = 'Bob'; @@ -312,13 +312,13 @@ Bob-->Alice: I am good thanks!`; expect(messages[0].from).toBe('Alice'); expect(messages[1].from).toBe('Bob'); }); - it('should handle dashes in actor names', function () { + it('should handle dashes in actor names', async () => { const str = ` sequenceDiagram Alice-in-Wonderland->Bob:Hello Bob, how are - you? Bob-->Alice-in-Wonderland:I am good thanks!`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors['Alice-in-Wonderland'].description).toBe('Alice-in-Wonderland'); expect(actors.Bob.description).toBe('Bob'); @@ -330,7 +330,7 @@ Bob-->Alice-in-Wonderland:I am good thanks!`; expect(messages[1].from).toBe('Bob'); }); - it('should handle dashes in participant names', function () { + it('should handle dashes in participant names', async () => { const str = ` sequenceDiagram participant Alice-in-Wonderland @@ -338,7 +338,7 @@ participant Bob Alice-in-Wonderland->Bob:Hello Bob, how are - you? Bob-->Alice-in-Wonderland:I am good thanks!`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(Object.keys(actors)).toEqual(['Alice-in-Wonderland', 'Bob']); expect(actors['Alice-in-Wonderland'].description).toBe('Alice-in-Wonderland'); @@ -351,7 +351,7 @@ Bob-->Alice-in-Wonderland:I am good thanks!`; expect(messages[1].from).toBe('Bob'); }); - it('should alias participants', function () { + it('should alias participants', async () => { const str = ` sequenceDiagram participant A as Alice @@ -359,7 +359,7 @@ participant B as Bob A->B:Hello Bob, how are you? B-->A: I am good thanks!`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); @@ -372,7 +372,7 @@ B-->A: I am good thanks!`; expect(messages[0].from).toBe('A'); expect(messages[1].from).toBe('B'); }); - it('should alias a mix of actors and participants apa12', function () { + it('should alias a mix of actors and participants apa12', async () => { const str = ` sequenceDiagram actor Alice as Alice2 @@ -385,7 +385,7 @@ sequenceDiagram John->>Mandy: Hi Mandy Mandy ->>Joan: Hi Joan`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(Object.keys(actors)).toEqual(['Alice', 'Bob', 'John', 'Mandy', 'Joan']); @@ -400,7 +400,7 @@ sequenceDiagram expect(messages[0].from).toBe('Alice'); expect(messages[4].to).toBe('Joan'); }); - it('should alias actors apa13', function () { + it('should alias actors apa13', async () => { const str = ` sequenceDiagram actor A as Alice @@ -408,7 +408,7 @@ actor B as Bob A->B:Hello Bob, how are you? B-->A: I am good thanks!`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(Object.keys(actors)).toEqual(['A', 'B']); @@ -420,12 +420,12 @@ B-->A: I am good thanks!`; expect(messages[0].from).toBe('A'); expect(messages[1].from).toBe('B'); }); - it('should handle in async messages', function () { + it('should handle in async messages', async () => { const str = ` sequenceDiagram Alice-xBob:Hello Bob, how are you?`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); expect(actors.Bob.description).toBe('Bob'); @@ -435,12 +435,12 @@ Alice-xBob:Hello Bob, how are you?`; expect(messages.length).toBe(1); expect(messages[0].type).toBe(diagram.db.LINETYPE.SOLID_CROSS); }); - it('should handle in async dotted messages', function () { + it('should handle in async dotted messages', async () => { const str = ` sequenceDiagram Alice--xBob:Hello Bob, how are you?`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); expect(actors.Bob.description).toBe('Bob'); @@ -450,12 +450,12 @@ Alice--xBob:Hello Bob, how are you?`; expect(messages.length).toBe(1); expect(messages[0].type).toBe(diagram.db.LINETYPE.DOTTED_CROSS); }); - it('should handle in sync messages', function () { + it('should handle in sync messages', async () => { const str = ` sequenceDiagram Alice-)Bob:Hello Bob, how are you?`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); expect(actors.Bob.description).toBe('Bob'); @@ -465,12 +465,12 @@ Alice-)Bob:Hello Bob, how are you?`; expect(messages.length).toBe(1); expect(messages[0].type).toBe(diagram.db.LINETYPE.SOLID_POINT); }); - it('should handle in sync dotted messages', function () { + it('should handle in sync dotted messages', async () => { const str = ` sequenceDiagram Alice--)Bob:Hello Bob, how are you?`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); expect(actors.Bob.description).toBe('Bob'); @@ -480,12 +480,12 @@ Alice--)Bob:Hello Bob, how are you?`; expect(messages.length).toBe(1); expect(messages[0].type).toBe(diagram.db.LINETYPE.DOTTED_POINT); }); - it('should handle in arrow messages', function () { + it('should handle in arrow messages', async () => { const str = ` sequenceDiagram Alice->>Bob:Hello Bob, how are you?`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); expect(actors.Bob.description).toBe('Bob'); @@ -495,10 +495,10 @@ Alice->>Bob:Hello Bob, how are you?`; expect(messages.length).toBe(1); expect(messages[0].type).toBe(diagram.db.LINETYPE.SOLID); }); - it('should handle in arrow messages', function () { + it('should handle in arrow messages', async () => { const str = 'sequenceDiagram\n' + 'Alice-->>Bob:Hello Bob, how are you?'; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); expect(actors.Bob.description).toBe('Bob'); @@ -508,7 +508,7 @@ Alice->>Bob:Hello Bob, how are you?`; expect(messages.length).toBe(1); expect(messages[0].type).toBe(diagram.db.LINETYPE.DOTTED); }); - it('should handle actor activation', function () { + it('should handle actor activation', async () => { const str = ` sequenceDiagram Alice-->>Bob:Hello Bob, how are you? @@ -516,7 +516,7 @@ activate Bob Bob-->>Alice:Hello Alice, I'm fine and you? deactivate Bob`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); expect(actors.Bob.description).toBe('Bob'); @@ -531,13 +531,13 @@ deactivate Bob`; expect(messages[3].type).toBe(diagram.db.LINETYPE.ACTIVE_END); expect(messages[3].from.actor).toBe('Bob'); }); - it('should handle actor one line notation activation', function () { + it('should handle actor one line notation activation', async () => { const str = ` sequenceDiagram Alice-->>+Bob:Hello Bob, how are you? Bob-->>- Alice:Hello Alice, I'm fine and you?`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); expect(actors.Bob.description).toBe('Bob'); @@ -552,7 +552,7 @@ deactivate Bob`; expect(messages[3].type).toBe(diagram.db.LINETYPE.ACTIVE_END); expect(messages[3].from.actor).toBe('Bob'); }); - it('should handle stacked activations', function () { + it('should handle stacked activations', async () => { const str = ` sequenceDiagram Alice-->>+Bob:Hello Bob, how are you? @@ -560,7 +560,7 @@ deactivate Bob`; Bob-->>- Alice:Hello Alice, please meet Carol? Carol->>- Bob:Oh Bob, I'm so happy to be here!`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); expect(actors.Bob.description).toBe('Bob'); @@ -579,7 +579,7 @@ deactivate Bob`; expect(messages[7].type).toBe(diagram.db.LINETYPE.ACTIVE_END); expect(messages[7].from.actor).toBe('Carol'); }); - it('should handle fail parsing when activating an inactive participant', function () { + it('should handle fail parsing when activating an inactive participant', async () => { const str = ` sequenceDiagram participant user as End User @@ -598,14 +598,14 @@ deactivate Bob`; let error = false; try { - mermaidAPI.parse(str); + await mermaidAPI.parse(str); } catch (e) { error = true; } expect(error).toBe(true); }); - it('should handle comments in a sequenceDiagram', function () { + it('should handle comments in a sequenceDiagram', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? @@ -613,7 +613,7 @@ deactivate Bob`; Note right of Bob: Bob thinks Bob-->Alice: I am good thanks!`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); actors.Bob.description = 'Bob'; @@ -624,7 +624,7 @@ deactivate Bob`; expect(messages[0].from).toBe('Alice'); expect(messages[2].from).toBe('Bob'); }); - it('should handle new lines in a sequenceDiagram', function () { + it('should handle new lines in a sequenceDiagram', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? @@ -634,7 +634,7 @@ deactivate Bob`; Bob-->Alice: I am good thanks! `; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); actors.Bob.description = 'Bob'; @@ -645,11 +645,11 @@ deactivate Bob`; expect(messages[0].from).toBe('Alice'); expect(messages[2].from).toBe('Bob'); }); - it('should handle semicolons', function () { + it('should handle semicolons', async () => { const str = ` sequenceDiagram;Alice->Bob: Hello Bob, how are you?;Note right of Bob: Bob thinks;Bob-->Alice: I am good thanks!;`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); actors.Bob.description = 'Bob'; @@ -660,7 +660,7 @@ sequenceDiagram;Alice->Bob: Hello Bob, how are you?;Note right of Bob: Bob think expect(messages[0].from).toBe('Alice'); expect(messages[2].from).toBe('Bob'); }); - it('should handle one leading space in lines in a sequenceDiagram', function () { + it('should handle one leading space in lines in a sequenceDiagram', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? @@ -669,7 +669,7 @@ sequenceDiagram Note right of Bob: Bob thinks Bob-->Alice: I am good thanks!`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); actors.Bob.description = 'Bob'; @@ -680,7 +680,7 @@ Bob-->Alice: I am good thanks!`; expect(messages[0].from).toBe('Alice'); expect(messages[2].from).toBe('Bob'); }); - it('should handle several leading spaces in lines in a sequenceDiagram', function () { + it('should handle several leading spaces in lines in a sequenceDiagram', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? @@ -689,7 +689,7 @@ sequenceDiagram Note right of Bob: Bob thinks Bob-->Alice: I am good thanks!`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); actors.Bob.description = 'Bob'; @@ -700,7 +700,7 @@ Bob-->Alice: I am good thanks!`; expect(messages[0].from).toBe('Alice'); expect(messages[2].from).toBe('Bob'); }); - it('should handle several leading spaces in lines in a sequenceDiagram', function () { + it('should handle several leading spaces in lines in a sequenceDiagram', async () => { const str = ` sequenceDiagram participant Alice @@ -714,7 +714,7 @@ Note right of John: Rational thoughts
prevail... John->Bob: How about you? Bob-->John: Jolly good!`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); actors.Bob.description = 'Bob'; @@ -725,7 +725,7 @@ Bob-->John: Jolly good!`; expect(messages[0].from).toBe('Alice'); expect(messages[2].from).toBe('John'); }); - it('should handle different line breaks', function () { + it('should handle different line breaks', async () => { const str = ` sequenceDiagram participant 1 as multiline
text @@ -742,7 +742,7 @@ note right of 4: multiline
text note right of 1: multiline
text `; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors['1'].description).toBe('multiline
text'); @@ -760,7 +760,7 @@ note right of 1: multiline
text expect(messages[6].message).toBe('multiline
text'); expect(messages[7].message).toBe('multiline
text'); }); - it('should handle notes and messages without wrap specified', function () { + it('should handle notes and messages without wrap specified', async () => { const str = ` sequenceDiagram participant 1 @@ -777,7 +777,7 @@ note right of 4: multiline
text note right of 1:nowrap: multiline
text `; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const messages = diagram.db.getMessages(); expect(messages[0].message).toBe('single-line text'); @@ -799,7 +799,7 @@ note right of 1:nowrap: multiline
text expect(messages[6].wrap).toBe(false); expect(messages[7].wrap).toBe(false); }); - it('should handle notes and messages with wrap specified', function () { + it('should handle notes and messages with wrap specified', async () => { const str = ` sequenceDiagram participant 1 @@ -812,7 +812,7 @@ note right of 2:wrap: single-line text note right of 3:wrap: multiline
text `; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const messages = diagram.db.getMessages(); expect(messages[0].message).toBe('single-line text'); @@ -824,7 +824,7 @@ note right of 3:wrap: multiline
text expect(messages[2].wrap).toBe(true); expect(messages[3].wrap).toBe(true); }); - it('should handle notes and messages with nowrap or line breaks', function () { + it('should handle notes and messages with nowrap or line breaks', async () => { const str = ` sequenceDiagram participant 1 @@ -833,7 +833,7 @@ participant 2 note right of 2: single-line text `; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const messages = diagram.db.getMessages(); expect(messages[0].message).toBe('single-line text'); @@ -841,20 +841,20 @@ note right of 2: single-line text expect(messages[0].wrap).toBe(false); expect(messages[1].wrap).toBe(false); }); - it('should handle notes over a single actor', function () { + it('should handle notes over a single actor', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? Note over Bob: Bob thinks `; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const messages = diagram.db.getMessages(); expect(messages[1].from).toBe('Bob'); expect(messages[1].to).toBe('Bob'); }); - it('should handle notes over multiple actors', function () { + it('should handle notes over multiple actors', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? @@ -862,7 +862,7 @@ Note over Alice,Bob: confusion Note over Bob,Alice: resolution `; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const messages = diagram.db.getMessages(); expect(messages[1].from).toBe('Alice'); @@ -870,7 +870,7 @@ Note over Bob,Alice: resolution expect(messages[2].from).toBe('Bob'); expect(messages[2].to).toBe('Alice'); }); - it('should handle loop statements', function () { + it('should handle loop statements', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? @@ -882,7 +882,7 @@ loop Multiple happy responses Bob-->Alice: I am good thanks! end`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); actors.Bob.description = 'Bob'; @@ -893,7 +893,7 @@ end`; expect(messages[0].from).toBe('Alice'); expect(messages[1].from).toBe('Bob'); }); - it('should add a rect around sequence', function () { + it('should add a rect around sequence', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? @@ -904,7 +904,7 @@ end`; end `; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); actors.Bob.description = 'Bob'; @@ -917,7 +917,7 @@ end`; expect(messages[4].type).toEqual(diagram.db.LINETYPE.RECT_END); }); - it('should allow for nested rects', function () { + it('should allow for nested rects', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? @@ -929,7 +929,7 @@ end`; Bob-->Alice: I am good thanks end `; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); actors.Bob.description = 'Bob'; @@ -944,7 +944,7 @@ end`; expect(messages[5].type).toEqual(diagram.db.LINETYPE.DOTTED_OPEN); expect(messages[6].type).toEqual(diagram.db.LINETYPE.RECT_END); }); - it('should handle opt statements', function () { + it('should handle opt statements', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? @@ -956,7 +956,7 @@ opt Perhaps a happy response Bob-->Alice: I am good thanks! end`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); actors.Bob.description = 'Bob'; @@ -967,7 +967,7 @@ end`; expect(messages[0].from).toBe('Alice'); expect(messages[1].from).toBe('Bob'); }); - it('should handle alt statements', function () { + it('should handle alt statements', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? @@ -981,7 +981,7 @@ else isSick Bob-->Alice: Feel sick... end`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); @@ -993,7 +993,7 @@ end`; expect(messages[0].from).toBe('Alice'); expect(messages[1].from).toBe('Bob'); }); - it('should handle alt statements with multiple elses', function () { + it('should handle alt statements with multiple elses', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? @@ -1008,7 +1008,7 @@ Bob-->Alice: Feel sick... else default Bob-->Alice: :-) end`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const messages = diagram.db.getMessages(); expect(messages.length).toBe(9); expect(messages[1].from).toBe('Bob'); @@ -1020,14 +1020,14 @@ end`; expect(messages[7].from).toBe('Bob'); expect(messages[8].type).toBe(diagram.db.LINETYPE.ALT_END); }); - it('should handle critical statements without options', function () { + it('should handle critical statements without options', async () => { const str = ` sequenceDiagram critical Establish a connection to the DB Service-->DB: connect end`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Service.description).toBe('Service'); @@ -1040,7 +1040,7 @@ sequenceDiagram expect(messages[1].from).toBe('Service'); expect(messages[2].type).toBe(diagram.db.LINETYPE.CRITICAL_END); }); - it('should handle critical statements with options', function () { + it('should handle critical statements with options', async () => { const str = ` sequenceDiagram critical Establish a connection to the DB @@ -1051,7 +1051,7 @@ sequenceDiagram Service-->Service: Log different error end`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Service.description).toBe('Service'); @@ -1068,7 +1068,7 @@ sequenceDiagram expect(messages[5].from).toBe('Service'); expect(messages[6].type).toBe(diagram.db.LINETYPE.CRITICAL_END); }); - it('should handle break statements', function () { + it('should handle break statements', async () => { const str = ` sequenceDiagram Consumer-->API: Book something @@ -1078,7 +1078,7 @@ sequenceDiagram end API-->BillingService: Start billing process`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Consumer.description).toBe('Consumer'); @@ -1094,7 +1094,7 @@ sequenceDiagram expect(messages[4].type).toBe(diagram.db.LINETYPE.BREAK_END); expect(messages[5].from).toBe('API'); }); - it('should handle par statements a sequenceDiagram', function () { + it('should handle par statements a sequenceDiagram', async () => { const str = ` sequenceDiagram par Parallel one @@ -1108,7 +1108,7 @@ Alice->>Bob: What do you think about it? Bob-->>Alice: It's good! end`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.Alice.description).toBe('Alice'); @@ -1121,26 +1121,26 @@ end`; expect(messages[1].from).toBe('Alice'); expect(messages[2].from).toBe('Bob'); }); - it('should handle special characters in signals', function () { + it('should handle special characters in signals', async () => { const str = 'sequenceDiagram\n' + 'Alice->Bob: -:<>,;# comment'; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const messages = diagram.db.getMessages(); expect(messages[0].message).toBe('-:<>,'); }); - it('should handle special characters in notes', function () { + it('should handle special characters in notes', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? Note right of Bob: -:<>,;# comment`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const messages = diagram.db.getMessages(); expect(messages[1].message).toBe('-:<>,'); }); - it('should handle special characters in loop', function () { + it('should handle special characters in loop', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? @@ -1148,12 +1148,12 @@ loop -:<>,;# comment Bob-->Alice: I am good thanks! end`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const messages = diagram.db.getMessages(); expect(messages[1].message).toBe('-:<>,'); }); - it('should handle special characters in opt', function () { + it('should handle special characters in opt', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? @@ -1161,12 +1161,12 @@ opt -:<>,;# comment Bob-->Alice: I am good thanks! end`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const messages = diagram.db.getMessages(); expect(messages[1].message).toBe('-:<>,'); }); - it('should handle special characters in alt', function () { + it('should handle special characters in alt', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? @@ -1176,13 +1176,13 @@ else ,<>:-#; comment Bob-->Alice: I am good thanks! end`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const messages = diagram.db.getMessages(); expect(messages[1].message).toBe('-:<>,'); expect(messages[3].message).toBe(',<>:-'); }); - it('should handle special characters in par', function () { + it('should handle special characters in par', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? @@ -1192,13 +1192,13 @@ and ,<>:-#; comment Bob-->Alice: I am good thanks! end`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const messages = diagram.db.getMessages(); expect(messages[1].message).toBe('-:<>,'); expect(messages[3].message).toBe(',<>:-'); }); - it('should handle no-label loop', function () { + it('should handle no-label loop', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? @@ -1206,13 +1206,13 @@ loop Bob-->Alice: I am good thanks! end`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const messages = diagram.db.getMessages(); expect(messages[1].message).toBe(''); expect(messages[2].message).toBe('I am good thanks!'); }); - it('should handle no-label opt', function () { + it('should handle no-label opt', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? @@ -1220,13 +1220,13 @@ opt # comment Bob-->Alice: I am good thanks! end`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const messages = diagram.db.getMessages(); expect(messages[1].message).toBe(''); expect(messages[2].message).toBe('I am good thanks!'); }); - it('should handle no-label alt', function () { + it('should handle no-label alt', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? @@ -1235,7 +1235,7 @@ else # comment Bob-->Alice: I am good thanks! end`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const messages = diagram.db.getMessages(); expect(messages[1].message).toBe(''); @@ -1243,7 +1243,7 @@ end`; expect(messages[3].message).toBe(''); expect(messages[4].message).toBe('I am good thanks!'); }); - it('should handle no-label par', function () { + it('should handle no-label par', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? @@ -1252,7 +1252,7 @@ and # comment Bob-->Alice: I am good thanks! end`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const messages = diagram.db.getMessages(); expect(messages[1].message).toBe(''); @@ -1261,7 +1261,7 @@ end`; expect(messages[4].message).toBe('I am good thanks!'); }); - it('should handle links', function () { + it('should handle links', async () => { const str = ` sequenceDiagram participant a as Alice @@ -1275,7 +1275,7 @@ link a: Swagger @ https://swagger.contoso.com link a: Tests @ https://tests.contoso.com/?svc=alice@contoso.com `; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.a.links['Repo']).toBe('https://repo.contoso.com/'); expect(actors.b.links['Repo']).toBe(undefined); @@ -1288,7 +1288,7 @@ link a: Tests @ https://tests.contoso.com/?svc=alice@contoso.com expect(actors.a.links['Tests']).toBe('https://tests.contoso.com/?svc=alice@contoso.com'); }); - it('should handle properties EXPERIMENTAL: USE WITH CAUTION', function () { + it('should handle properties EXPERIMENTAL: USE WITH CAUTION', async () => { //Be aware that the syntax for "properties" is likely to be changed. const str = ` sequenceDiagram @@ -1299,7 +1299,7 @@ properties a: {"class": "internal-service-actor", "icon": "@clock"} properties b: {"class": "external-service-actor", "icon": "@computer"} `; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(actors.a.properties['class']).toBe('internal-service-actor'); expect(actors.b.properties['class']).toBe('external-service-actor'); @@ -1308,7 +1308,7 @@ properties b: {"class": "external-service-actor", "icon": "@computer"} expect(actors.c.properties['class']).toBe(undefined); }); - it('should handle box', function () { + it('should handle box', async () => { const str = ` sequenceDiagram box green Group 1 @@ -1324,14 +1324,14 @@ link a: Swagger @ https://swagger.contoso.com link a: Tests @ https://tests.contoso.com/?svc=alice@contoso.com `; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const boxes = diagram.db.getBoxes(); expect(boxes[0].name).toEqual('Group 1'); expect(boxes[0].actorKeys).toEqual(['a', 'b']); expect(boxes[0].fill).toEqual('green'); }); - it('should handle box without color', function () { + it('should handle box without color', async () => { const str = ` sequenceDiagram box Group 1 @@ -1347,14 +1347,14 @@ link a: Tests @ https://tests.contoso.com/?svc=alice@contoso.com link a: Tests @ https://tests.contoso.com/?svc=alice@contoso.com `; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const boxes = diagram.db.getBoxes(); expect(boxes[0].name).toEqual('Group 1'); expect(boxes[0].actorKeys).toEqual(['a', 'b']); expect(boxes[0].fill).toEqual('transparent'); }); - it('should handle box without description', function () { + it('should handle box without description', async () => { const str = ` sequenceDiagram box Aqua @@ -1370,7 +1370,7 @@ link a: Tests @ https://tests.contoso.com/?svc=alice@contoso.com link a: Tests @ https://tests.contoso.com/?svc=alice@contoso.com `; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const boxes = diagram.db.getBoxes(); expect(boxes[0].name).toBeFalsy(); expect(boxes[0].actorKeys).toEqual(['a', 'b']); @@ -1403,7 +1403,7 @@ describe('when checking the bounds in a sequenceDiagram', function () { diagram.renderer.bounds.init(); conf = diagram.db.getConfig(); }); - it('should handle a simple bound call', function () { + it('should handle a simple bound call', async () => { diagram.renderer.bounds.insert(100, 100, 200, 200); const { bounds } = diagram.renderer.bounds.getBounds(); @@ -1412,7 +1412,7 @@ describe('when checking the bounds in a sequenceDiagram', function () { expect(bounds.stopx).toBe(200); expect(bounds.stopy).toBe(200); }); - it('should handle an expanding bound', function () { + it('should handle an expanding bound', async () => { diagram.renderer.bounds.insert(100, 100, 200, 200); diagram.renderer.bounds.insert(25, 50, 300, 400); @@ -1422,7 +1422,7 @@ describe('when checking the bounds in a sequenceDiagram', function () { expect(bounds.stopx).toBe(300); expect(bounds.stopy).toBe(400); }); - it('should handle inserts within the bound without changing the outer bounds', function () { + it('should handle inserts within the bound without changing the outer bounds', async () => { diagram.renderer.bounds.insert(100, 100, 200, 200); diagram.renderer.bounds.insert(25, 50, 300, 400); diagram.renderer.bounds.insert(125, 150, 150, 200); @@ -1433,7 +1433,7 @@ describe('when checking the bounds in a sequenceDiagram', function () { expect(bounds.stopx).toBe(300); expect(bounds.stopy).toBe(400); }); - it('should handle a loop without expanding the area', function () { + it('should handle a loop without expanding the area', async () => { diagram.renderer.bounds.insert(25, 50, 300, 400); diagram.renderer.bounds.verticalPos = 150; diagram.renderer.bounds.newLoop(); @@ -1454,7 +1454,7 @@ describe('when checking the bounds in a sequenceDiagram', function () { expect(bounds.stopx).toBe(300); expect(bounds.stopy).toBe(400); }); - it('should handle multiple loops withtout expanding the bounds', function () { + it('should handle multiple loops withtout expanding the bounds', async () => { diagram.renderer.bounds.insert(100, 100, 1000, 1000); diagram.renderer.bounds.verticalPos = 200; diagram.renderer.bounds.newLoop(); @@ -1485,7 +1485,7 @@ describe('when checking the bounds in a sequenceDiagram', function () { expect(bounds.stopx).toBe(1000); expect(bounds.stopy).toBe(1000); }); - it('should handle a loop that expands the area', function () { + it('should handle a loop that expands the area', async () => { diagram.renderer.bounds.insert(100, 100, 200, 200); diagram.renderer.bounds.verticalPos = 200; diagram.renderer.bounds.newLoop(); @@ -1555,13 +1555,13 @@ Bob-->Alice: I am good thanks!`); }); ['tspan', 'fo', 'old', undefined].forEach(function (textPlacement) { it(` -it should handle one actor, when textPlacement is ${textPlacement}`, function () { +it should handle one actor, when textPlacement is ${textPlacement}`, async () => { const str = ` sequenceDiagram participant Alice`; // mermaidAPI.reinitialize({ sequence: { textPlacement: textPlacement } }); - mermaidAPI.parse(str); + await mermaidAPI.parse(str); // diagram.renderer.setConf(mermaidAPI.getConfig().sequence); diagram.renderer.draw(str, 'tst', '1.2.3', diagram); @@ -1572,7 +1572,7 @@ participant Alice`; expect(bounds.stopy).toBe(conf.height); }); }); - it('should handle same actor with different whitespace properly', function () { + it('should handle same actor with different whitespace properly', async () => { const str = ` sequenceDiagram participant Alice @@ -1580,12 +1580,12 @@ participant Alice participant Alice `; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); const actors = diagram.db.getActors(); expect(Object.keys(actors)).toEqual(['Alice']); }); - it('should handle one actor and a centered note', function () { + it('should handle one actor and a centered note', async () => { const str = ` sequenceDiagram participant Alice @@ -1593,7 +1593,7 @@ Note over Alice: Alice thinks `; expect(mermaidAPI.getConfig().sequence.mirrorActors).toBeFalsy(); - mermaidAPI.parse(str); + await mermaidAPI.parse(str); diagram.renderer.draw(str, 'tst', '1.2.3', diagram); const { bounds, models } = diagram.renderer.bounds.getBounds(); @@ -1603,13 +1603,13 @@ Note over Alice: Alice thinks // 10 comes from mock of text height expect(bounds.stopy).toBe(models.lastNote().stopy); }); - it('should handle one actor and a note to the left', function () { + it('should handle one actor and a note to the left', async () => { const str = ` sequenceDiagram participant Alice Note left of Alice: Alice thinks`; - mermaidAPI.parse(str, diagram); + await mermaidAPI.parse(str); diagram.renderer.draw(str, 'tst', '1.2.3', diagram); const { bounds, models } = diagram.renderer.bounds.getBounds(); @@ -1619,13 +1619,13 @@ Note left of Alice: Alice thinks`; // 10 comes from mock of text height expect(bounds.stopy).toBe(models.lastNote().stopy); }); - it('should handle one actor and a note to the right', function () { + it('should handle one actor and a note to the right', async () => { const str = ` sequenceDiagram participant Alice Note right of Alice: Alice thinks`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); diagram.renderer.draw(str, 'tst', '1.2.3', diagram); const { bounds, models } = diagram.renderer.bounds.getBounds(); @@ -1635,12 +1635,12 @@ Note right of Alice: Alice thinks`; // 10 comes from mock of text height expect(bounds.stopy).toBe(models.lastNote().stopy); }); - it('should handle two actors', function () { + it('should handle two actors', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you?`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); diagram.renderer.draw(str, 'tst', '1.2.3', diagram); const { bounds, models } = diagram.renderer.bounds.getBounds(); @@ -1649,7 +1649,7 @@ Alice->Bob: Hello Bob, how are you?`; expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin); expect(bounds.stopy).toBe(models.lastMessage().stopy + 10); }); - it('should handle two actors in a box', function () { + it('should handle two actors in a box', async () => { const str = ` sequenceDiagram box rgb(34, 56, 0) Group1 @@ -1658,7 +1658,7 @@ participant Bob end Alice->Bob: Hello Bob, how are you?`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); diagram.renderer.draw(str, 'tst', '1.2.3', diagram); const { bounds, models } = diagram.renderer.bounds.getBounds(); @@ -1667,13 +1667,13 @@ Alice->Bob: Hello Bob, how are you?`; expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin + conf.boxTextMargin * 2); expect(bounds.stopy).toBe(models.lastMessage().stopy + 20); }); - it('should handle two actors with init directive', function () { + it('should handle two actors with init directive', async () => { const str = ` %%{init: {'logLevel': 0}}%% sequenceDiagram Alice->Bob: Hello Bob, how are you?`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); diagram.renderer.draw(str, 'tst', '1.2.3', diagram); const { bounds, models } = diagram.renderer.bounds.getBounds(); @@ -1684,7 +1684,7 @@ Alice->Bob: Hello Bob, how are you?`; expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin); expect(bounds.stopy).toBe(models.lastMessage().stopy + 10); }); - it('should handle two actors with init directive with multiline directive', function () { + it('should handle two actors with init directive with multiline directive', async () => { const str = ` %%{init: { 'logLevel': 0}}%% sequenceDiagram @@ -1693,7 +1693,7 @@ wrap }%% Alice->Bob: Hello Bob, how are you?`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); diagram.renderer.draw(str, 'tst', '1.2.3', diagram); const msgs = diagram.db.getMessages(); @@ -1706,7 +1706,7 @@ Alice->Bob: Hello Bob, how are you?`; expect(bounds.stopy).toBe(models.lastMessage().stopy + 10); expect(msgs.every((v) => v.wrap)).toBe(true); }); - it('should handle two actors and two centered shared notes', function () { + it('should handle two actors and two centered shared notes', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? @@ -1714,7 +1714,7 @@ Note over Alice,Bob: Looks Note over Bob,Alice: Looks back `; // mermaidAPI.initialize({logLevel:0}) - mermaidAPI.parse(str); + await mermaidAPI.parse(str); diagram.renderer.draw(str, 'tst', '1.2.3', diagram); const { bounds, models } = diagram.renderer.bounds.getBounds(); @@ -1723,13 +1723,13 @@ Note over Bob,Alice: Looks back expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin); expect(bounds.stopy).toBe(models.lastNote().stopy); }); - it('should draw two actors and two messages', function () { + it('should draw two actors and two messages', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? Bob->Alice: Fine!`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); diagram.renderer.draw(str, 'tst', '1.2.3', diagram); const { bounds, models } = diagram.renderer.bounds.getBounds(); @@ -1738,14 +1738,14 @@ Bob->Alice: Fine!`; expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin); expect(bounds.stopy).toBe(models.lastMessage().stopy + 10); }); - it('should draw two actors notes to the right', function () { + it('should draw two actors notes to the right', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? Note right of Bob: Bob thinks Bob->Alice: Fine!`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); diagram.renderer.draw(str, 'tst', '1.2.3', diagram); const { bounds, models } = diagram.renderer.bounds.getBounds(); @@ -1757,14 +1757,14 @@ Bob->Alice: Fine!`; expect(bounds.stopx).toBe(expStopX); expect(bounds.stopy).toBe(models.lastMessage().stopy + 10); }); - it('should draw two actors notes to the left', function () { + it('should draw two actors notes to the left', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? Note left of Alice: Bob thinks Bob->Alice: Fine!`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); diagram.renderer.draw(str, 'tst', '1.2.3', diagram); const { bounds, models } = diagram.renderer.bounds.getBounds(); @@ -1774,14 +1774,14 @@ Bob->Alice: Fine!`; expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin); expect(bounds.stopy).toBe(models.lastMessage().stopy + 10); }); - it('should draw two actors notes to the left with text wrapped (inline)', function () { + it('should draw two actors notes to the left with text wrapped (inline)', async () => { const str = ` sequenceDiagram Alice->>Bob:wrap: Hello Bob, how are you? If you are not available right now, I can leave you a message. Please get back to me as soon as you can! Note left of Alice: Bob thinks Bob->>Alice: Fine!`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); diagram.renderer.draw(str, 'tst', '1.2.3', diagram); const { bounds, models } = diagram.renderer.bounds.getBounds(); @@ -1793,7 +1793,7 @@ Bob->>Alice: Fine!`; expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin); expect(bounds.stopy).toBe(models.lastMessage().stopy + 10); }); - it('should draw two actors notes to the left with text wrapped (directive)', function () { + it('should draw two actors notes to the left with text wrapped (directive)', async () => { const str = ` %%{init: { 'theme': 'dark' } }%% sequenceDiagram @@ -1802,7 +1802,7 @@ Alice->>Bob: Hello Bob, how are you? If you are not available right now, I can l Note left of Alice: Bob thinks Bob->>Alice: Fine!`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); diagram.renderer.draw(str, 'tst', '1.2.3', diagram); const { bounds, models } = diagram.renderer.bounds.getBounds(); @@ -1816,7 +1816,7 @@ Bob->>Alice: Fine!`; expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin); expect(bounds.stopy).toBe(models.lastMessage().stopy + 10); }); - it('should draw two actors notes to the left with text wrapped and the init directive sets the theme to dark', function () { + it('should draw two actors notes to the left with text wrapped and the init directive sets the theme to dark', async () => { const str = ` %%{init:{'theme':'dark'}}%% sequenceDiagram @@ -1825,7 +1825,7 @@ Alice->>Bob: Hello Bob, how are you? If you are not available right now, I can l Note left of Alice: Bob thinks Bob->>Alice: Fine!`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); diagram.renderer.draw(str, 'tst', '1.2.3', diagram); const { bounds, models } = diagram.renderer.bounds.getBounds(); @@ -1839,7 +1839,7 @@ Bob->>Alice: Fine!`; expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin); expect(bounds.stopy).toBe(models.lastMessage().stopy + 10); }); - it('should draw two actors, notes to the left with text wrapped and the init directive sets the theme to dark and fontFamily to Menlo, fontSize to 18, and fontWeight to 800', function () { + it('should draw two actors, notes to the left with text wrapped and the init directive sets the theme to dark and fontFamily to Menlo, fontSize to 18, and fontWeight to 800', async () => { const str = ` %%{init: { "theme": "dark", 'config': { "fontFamily": "Menlo", "fontSize": 18, "messageFontWeight": 400, "wrap": true }}}%% sequenceDiagram @@ -1847,7 +1847,7 @@ Alice->>Bob: Hello Bob, how are you? If you are not available right now, I can l Note left of Alice: Bob thinks Bob->>Alice: Fine!`; // mermaidAPI.initialize({ logLevel: 0 }); - mermaidAPI.parse(str, diagram); + await mermaidAPI.parse(str); diagram.renderer.draw(str, 'tst', '1.2.3', diagram); const { bounds, models } = diagram.renderer.bounds.getBounds(); @@ -1864,14 +1864,14 @@ Bob->>Alice: Fine!`; expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin); expect(bounds.stopy).toBe(models.lastMessage().stopy + 10); }); - it('should draw two loops', function () { + it('should draw two loops', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, how are you? loop Cheers Bob->Alice: Fine! end`; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); diagram.renderer.draw(str, 'tst', '1.2.3', diagram); const { bounds, models } = diagram.renderer.bounds.getBounds(); @@ -1881,7 +1881,7 @@ end`; expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin); expect(bounds.stopy).toBe(models.lastLoop().stopy); }); - it('should draw background rect', function () { + it('should draw background rect', async () => { const str = ` sequenceDiagram Alice->Bob: Hello Bob, are you alright? @@ -1889,7 +1889,7 @@ end`; Bob->Alice: I feel surrounded by darkness end `; - mermaidAPI.parse(str); + await mermaidAPI.parse(str); diagram.renderer.draw(str, 'tst', '1.2.3', diagram); const { bounds, models } = diagram.renderer.bounds.getBounds(); expect(bounds.startx).toBe(0); @@ -1900,7 +1900,7 @@ end`; }); }); -describe('when rendering a sequenceDiagram with actor mirror activated', function () { +describe('when rendering a sequenceDiagram with actor mirror activated', () => { beforeAll(() => { let conf = { diagramMarginX: 50, @@ -1931,14 +1931,14 @@ describe('when rendering a sequenceDiagram with actor mirror activated', functio diagram.renderer.bounds.init(); }); ['tspan', 'fo', 'old', undefined].forEach(function (textPlacement) { - it('should handle one actor, when textPlacement is' + textPlacement, function () { + it('should handle one actor, when textPlacement is' + textPlacement, async () => { mermaidAPI.initialize(addConf(conf, 'textPlacement', textPlacement)); diagram.renderer.bounds.init(); const str = ` sequenceDiagram participant Alice`; diagram.renderer.bounds.init(); - mermaidAPI.parse(str); + await mermaidAPI.parse(str); diagram.renderer.draw(str, 'tst', '1.2.3', diagram); const { bounds, models } = diagram.renderer.bounds.getBounds(); @@ -1950,7 +1950,7 @@ participant Alice`; }); }); -describe('when rendering a sequenceDiagram with directives', function () { +describe('when rendering a sequenceDiagram with directives', () => { beforeAll(function () { let conf = { diagramMarginX: 50, @@ -1975,7 +1975,7 @@ describe('when rendering a sequenceDiagram with directives', function () { diagram.renderer.bounds.init(); }); - it('should handle one actor, when theme is dark and logLevel is 1 DX1 (dfg1)', function () { + it('should handle one actor, when theme is dark and logLevel is 1 DX1 (dfg1)', async () => { const str = ` %%{init: { "theme": "dark", "logLevel": 1 } }%% sequenceDiagram @@ -1985,7 +1985,7 @@ participant Alice diagram = new Diagram(str); diagram.renderer.bounds.init(); - mermaidAPI.parse(str); + await mermaidAPI.parse(str); diagram.renderer.draw(str, 'tst', '1.2.3', diagram); @@ -2000,7 +2000,7 @@ participant Alice models.lastActor().y + models.lastActor().height + mermaid.sequence.boxMargin ); }); - it('should handle one actor, when logLevel is 3 (dfg0)', function () { + it('should handle one actor, when logLevel is 3 (dfg0)', async () => { const str = ` %%{initialize: { "logLevel": 3 }}%% sequenceDiagram @@ -2020,7 +2020,7 @@ participant Alice models.lastActor().y + models.lastActor().height + mermaid.sequence.boxMargin ); }); - it('should hide sequence numbers when autonumber is removed when autonumber is enabled', function () { + it('should hide sequence numbers when autonumber is removed when autonumber is enabled', async () => { const str1 = ` sequenceDiagram autonumber @@ -2028,7 +2028,7 @@ Alice->Bob:Hello Bob, how are you? Note right of Bob: Bob thinks Bob-->Alice: I am good thanks!`; - mermaidAPI.parse(str1, diagram); + await mermaidAPI.parse(str1); diagram.renderer.draw(str1, 'tst', '1.2.3', diagram); // needs to be rendered for the correct value of visibility auto numbers expect(diagram.db.showSequenceNumbers()).toBe(true); @@ -2038,7 +2038,7 @@ Alice->Bob:Hello Bob, how are you? Note right of Bob: Bob thinks Bob-->Alice: I am good thanks!`; - mermaidAPI.parse(str2, diagram); + await mermaidAPI.parse(str2); diagram.renderer.draw(str2, 'tst', '1.2.3', diagram); expect(diagram.db.showSequenceNumbers()).toBe(false); }); diff --git a/packages/mermaid/src/mermaid.spec.ts b/packages/mermaid/src/mermaid.spec.ts index f9709510e..f50661dcf 100644 --- a/packages/mermaid/src/mermaid.spec.ts +++ b/packages/mermaid/src/mermaid.spec.ts @@ -6,12 +6,12 @@ const spyOn = vi.spyOn; vi.mock('./mermaidAPI'); afterEach(() => { - vi.restoreAllMocks(); + vi.clearAllMocks(); }); -describe('when using mermaid and ', function () { - describe('when detecting chart type ', function () { - it('should not start rendering with mermaid.startOnLoad set to false', function () { +describe('when using mermaid and ', () => { + describe('when detecting chart type ', () => { + it('should not start rendering with mermaid.startOnLoad set to false', async () => { mermaid.startOnLoad = false; document.body.innerHTML = '
graph TD;\na;
'; spyOn(mermaid, 'init'); @@ -19,7 +19,7 @@ describe('when using mermaid and ', function () { expect(mermaid.init).not.toHaveBeenCalled(); }); - it('should start rendering with both startOnLoad set', function () { + it('should start rendering with both startOnLoad set', async () => { mermaid.startOnLoad = true; document.body.innerHTML = '
graph TD;\na;
'; spyOn(mermaid, 'init'); @@ -27,7 +27,7 @@ describe('when using mermaid and ', function () { expect(mermaid.init).toHaveBeenCalled(); }); - it('should start rendering with mermaid.startOnLoad', function () { + it('should start rendering with mermaid.startOnLoad', async () => { mermaid.startOnLoad = true; document.body.innerHTML = '
graph TD;\na;
'; spyOn(mermaid, 'init'); @@ -35,7 +35,7 @@ describe('when using mermaid and ', function () { expect(mermaid.init).toHaveBeenCalled(); }); - it('should start rendering as a default with no changes performed', function () { + it('should start rendering as a default with no changes performed', async () => { document.body.innerHTML = '
graph TD;\na;
'; spyOn(mermaid, 'init'); mermaid.contentLoaded(); @@ -43,7 +43,7 @@ describe('when using mermaid and ', function () { }); }); - describe('when using #initThrowsErrors', function () { + describe('when using #initThrowsErrors', () => { it('should accept single node', async () => { const node = document.createElement('div'); node.appendChild(document.createTextNode('graph TD;\na;')); @@ -54,7 +54,8 @@ describe('when using mermaid and ', function () { expect(mermaidAPI.render).toHaveBeenCalled(); }); }); - describe('when using #registerExternalDiagrams', function () { + + describe('when using #registerExternalDiagrams', () => { it('should throw error (but still render) if registerExternalDiagrams fails', async () => { const node = document.createElement('div'); node.appendChild(document.createTextNode('graph TD;\na;')); @@ -137,19 +138,21 @@ describe('when using mermaid and ', function () { }); }); - describe('checking validity of input ', function () { - it('should throw for an invalid definition', function () { - expect(() => mermaid.parse('this is not a mermaid diagram definition')).toThrow(); + describe('checking validity of input ', () => { + it('should throw for an invalid definition', async () => { + await expect(mermaid.parse('this is not a mermaid diagram definition')).rejects.toThrow(); }); - it('should not throw for a valid flow definition', function () { - expect(() => mermaid.parse('graph TD;A--x|text including URL space|B;')).not.toThrow(); + it('should not throw for a valid flow definition', async () => { + await expect( + mermaid.parse('graph TD;A--x|text including URL space|B;') + ).resolves.not.toThrow(); }); - it('should throw for an invalid flow definition', function () { - expect(() => mermaid.parse('graph TQ;A--x|text including URL space|B;')).toThrow(); + it('should throw for an invalid flow definition', async () => { + await expect(mermaid.parse('graph TQ;A--x|text including URL space|B;')).rejects.toThrow(); }); - it('should not throw for a valid sequenceDiagram definition (mmds1)', function () { + it('should not throw for a valid sequenceDiagram definition (mmds1)', async () => { const text = 'sequenceDiagram\n' + 'Alice->Bob: Hello Bob, how are you?\n\n' + @@ -160,10 +163,10 @@ describe('when using mermaid and ', function () { 'else isSick\n' + 'Bob-->Alice: Feel sick...\n' + 'end'; - expect(() => mermaid.parse(text)).not.toThrow(); + await expect(mermaid.parse(text)).resolves.not.toThrow(); }); - it('should throw for an invalid sequenceDiagram definition', function () { + it('should throw for an invalid sequenceDiagram definition', async () => { const text = 'sequenceDiagram\n' + 'Alice:->Bob: Hello Bob, how are you?\n\n' + @@ -174,15 +177,15 @@ describe('when using mermaid and ', function () { 'else isSick\n' + 'Bob-->Alice: Feel sick...\n' + 'end'; - expect(() => mermaid.parse(text)).toThrow(); + await expect(mermaid.parse(text)).rejects.toThrow(); }); - it('should return false for invalid definition WITH a parseError() callback defined', function () { + it('should return false for invalid definition WITH a parseError() callback defined', async () => { let parseErrorWasCalled = false; mermaid.setParseErrorHandler(() => { parseErrorWasCalled = true; }); - expect(mermaid.parse('this is not a mermaid diagram definition')).toEqual(false); + await expect(mermaid.parse('this is not a mermaid diagram definition')).rejects.toThrow(); expect(parseErrorWasCalled).toEqual(true); }); }); diff --git a/packages/mermaid/src/mermaidAPI.spec.ts b/packages/mermaid/src/mermaidAPI.spec.ts index e86b9b15f..b16237866 100644 --- a/packages/mermaid/src/mermaidAPI.spec.ts +++ b/packages/mermaid/src/mermaidAPI.spec.ts @@ -76,7 +76,7 @@ import { compile, serialize } from 'stylis'; // ------------------------------------------------------------------------------------- -describe('mermaidAPI', function () { +describe('mermaidAPI', () => { describe('encodeEntities', () => { it('removes the ending ; from style [text1]:[optional word]#[text2]; with ', () => { const text = 'style this; is ; everything :something#not-nothing; and this too;'; @@ -515,13 +515,13 @@ describe('mermaidAPI', function () { }); }); - describe('initialize', function () { - beforeEach(function () { + describe('initialize', () => { + beforeEach(() => { document.body.innerHTML = ''; mermaidAPI.globalReset(); }); - it('copies a literal into the configuration', function () { + it('copies a literal into the configuration', () => { const orgConfig: any = mermaidAPI.getConfig(); expect(orgConfig.testLiteral).toBe(undefined); @@ -533,7 +533,7 @@ describe('mermaidAPI', function () { expect(config.testLiteral).toBe(true); }); - it('copies an object into the configuration', function () { + it('copies an object into the configuration', () => { const orgConfig: any = mermaidAPI.getConfig(); expect(orgConfig.testObject).toBe(undefined); @@ -559,7 +559,7 @@ describe('mermaidAPI', function () { expect(config.testObject.test3).toBe(true); }); - it('resets mermaid config to global defaults', function () { + it('resets mermaid config to global defaults', () => { const config = { logLevel: 0, securityLevel: 'loose', @@ -576,7 +576,7 @@ describe('mermaidAPI', function () { expect(mermaidAPI.getConfig().securityLevel).toBe('strict'); }); - it('prevents changes to site defaults (sneaky)', function () { + it('prevents changes to site defaults (sneaky)', () => { const config: any = { logLevel: 0, }; @@ -584,7 +584,7 @@ describe('mermaidAPI', function () { const siteConfig = mermaidAPI.getSiteConfig(); expect(mermaidAPI.getConfig().logLevel).toBe(0); config.secure = { - toString: function () { + toString: () => { mermaidAPI.initialize({ securityLevel: 'loose' }); }, }; @@ -595,7 +595,7 @@ describe('mermaidAPI', function () { expect(mermaidAPI.getSiteConfig()).toEqual(siteConfig); expect(mermaidAPI.getConfig()).toEqual(siteConfig); }); - it('prevents clobbering global defaults (direct)', function () { + it('prevents clobbering global defaults (direct)', () => { const config = assignWithDepth({}, mermaidAPI.defaultConfig); assignWithDepth(config, { logLevel: 0 }); @@ -611,7 +611,7 @@ describe('mermaidAPI', function () { ); expect(mermaidAPI.defaultConfig['logLevel']).toBe(5); }); - it('prevents changes to global defaults (direct)', function () { + it('prevents changes to global defaults (direct)', () => { let error: any = { message: '' }; try { mermaidAPI.defaultConfig['logLevel'] = 0; @@ -623,7 +623,7 @@ describe('mermaidAPI', function () { ); expect(mermaidAPI.defaultConfig['logLevel']).toBe(5); }); - it('prevents sneaky changes to global defaults (assignWithDepth)', function () { + it('prevents sneaky changes to global defaults (assignWithDepth)', () => { const config = { logLevel: 0, }; @@ -640,48 +640,61 @@ describe('mermaidAPI', function () { }); }); - describe('dompurify config', function () { - it('allows dompurify config to be set', function () { + describe('dompurify config', () => { + it('allows dompurify config to be set', () => { mermaidAPI.initialize({ dompurifyConfig: { ADD_ATTR: ['onclick'] } }); expect(mermaidAPI!.getConfig()!.dompurifyConfig!.ADD_ATTR).toEqual(['onclick']); }); }); - describe('parse', function () { + describe('parse', () => { mermaid.parseError = undefined; // ensure it parseError undefined - it('throws for an invalid definition (with no mermaid.parseError() defined)', function () { + it('throws for an invalid definition (with no mermaid.parseError() defined)', async () => { expect(mermaid.parseError).toEqual(undefined); - expect(() => mermaidAPI.parse('this is not a mermaid diagram definition')).toThrow(); + await expect( + mermaidAPI.parse('this is not a mermaid diagram definition') + ).rejects.toThrowError(); }); - it('throws for a nicer error for a invalid definition starting with `---`', function () { + it('throws for a nicer error for a invalid definition starting with `---`', async () => { expect(mermaid.parseError).toEqual(undefined); - expect(() => + await expect( mermaidAPI.parse(` --- title: a malformed YAML front-matter `) - ).toThrow( + ).rejects.toThrow( 'Diagrams beginning with --- are not valid. ' + 'If you were trying to use a YAML front-matter, please ensure that ' + "you've correctly opened and closed the YAML front-matter with unindented `---` blocks" ); }); - it('does not throw for a valid definition', function () { - expect(() => mermaidAPI.parse('graph TD;A--x|text including URL space|B;')).not.toThrow(); + it('does not throw for a valid definition', async () => { + await expect( + mermaidAPI.parse('graph TD;A--x|text including URL space|B;') + ).resolves.not.toThrow(); }); - it('returns false for invalid definition WITH a parseError() callback defined', function () { - let parseErrorWasCalled = false; - // also test setParseErrorHandler() call working to set mermaid.parseError - expect( - mermaidAPI.parse('this is not a mermaid diagram definition', () => { - parseErrorWasCalled = true; - }) - ).toEqual(false); - expect(parseErrorWasCalled).toEqual(true); + it('throws for invalid definition', async () => { + await expect( + mermaidAPI.parse('this is not a mermaid diagram definition') + ).rejects.toThrowErrorMatchingInlineSnapshot( + '"No diagram type detected for text: this is not a mermaid diagram definition"' + ); }); - it('returns true for valid definition', function () { - expect(mermaidAPI.parse('graph TD;A--x|text including URL space|B;')).toEqual(true); + it('returns false for invalid definition with silent option', async () => { + await expect( + mermaidAPI.parse('this is not a mermaid diagram definition', { silent: true }) + ).resolves.toBe(false); + }); + it('resolves for valid definition', async () => { + await expect( + mermaidAPI.parse('graph TD;A--x|text including URL space|B;') + ).resolves.not.toThrow(); + }); + it('returns true for valid definition with silent option', async () => { + await expect( + mermaidAPI.parse('graph TD;A--x|text including URL space|B;', { silent: true }) + ).resolves.toBe(true); }); }); From 735aceb37a3a5907c97e9de0ca243fa6ae1b31a4 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Sun, 19 Feb 2023 14:03:11 +0530 Subject: [PATCH 34/67] Fix E2E Tests --- .vite/server.ts | 10 +--- cypress/platform/bundle-test.js | 16 ++---- cypress/platform/class.html | 4 +- cypress/platform/click_security_loose.html | 4 +- cypress/platform/click_security_other.html | 4 +- cypress/platform/click_security_sandbox.html | 4 +- cypress/platform/click_security_strict.html | 4 +- cypress/platform/css1.html | 4 +- cypress/platform/current2.html | 4 +- cypress/platform/e2e.html | 38 +------------ cypress/platform/flow.html | 4 +- cypress/platform/ghsa1.html | 14 ++--- cypress/platform/ghsa2.html | 6 +- cypress/platform/ghsa3.html | 16 +++--- cypress/platform/git-graph.html | 4 +- cypress/platform/gitgraph.html | 4 +- cypress/platform/gitgraph2.html | 4 +- cypress/platform/huge.html | 4 +- cypress/platform/info.html | 4 +- cypress/platform/interaction.html | 4 +- cypress/platform/per.html | 2 +- cypress/platform/regression/issue-1874.html | 18 +++--- cypress/platform/render-after-error.html | 15 +++-- cypress/platform/rerender.html | 16 +++--- cypress/platform/showcase_base.html | 4 +- cypress/platform/showcase_base_dark.html | 4 +- cypress/platform/showcase_dark.html | 4 +- cypress/platform/showcase_default.html | 4 +- cypress/platform/showcase_forest.html | 4 +- cypress/platform/showcase_neutral.html | 4 +- cypress/platform/sidv.html | 6 -- cypress/platform/subgraph.html | 4 +- cypress/platform/theme-directives.html | 4 +- cypress/platform/user-journey.html | 4 +- cypress/platform/vertices.html | 4 +- cypress/platform/viewer.js | 29 +++------- cypress/platform/xss.html | 4 +- cypress/platform/xss10.html | 11 ++-- cypress/platform/xss11.html | 11 ++-- cypress/platform/xss12.html | 11 ++-- cypress/platform/xss13.html | 11 ++-- cypress/platform/xss14.html | 11 ++-- cypress/platform/xss15.html | 11 ++-- cypress/platform/xss16.html | 11 ++-- cypress/platform/xss17.html | 11 ++-- cypress/platform/xss18.html | 11 ++-- cypress/platform/xss19.html | 11 ++-- cypress/platform/xss2.html | 6 +- cypress/platform/xss20.html | 10 ++-- cypress/platform/xss21.html | 12 ++-- cypress/platform/xss22.html | 4 +- cypress/platform/xss3.html | 4 +- cypress/platform/xss4.html | 9 ++- cypress/platform/xss5.html | 11 ++-- cypress/platform/xss6.html | 11 ++-- cypress/platform/xss7.html | 11 ++-- cypress/platform/xss8.html | 11 ++-- cypress/platform/xss9.html | 11 ++-- demos/c4context.html | 22 +++---- demos/classchart.html | 4 +- demos/dataflowchart.html | 4 +- demos/er.html | 2 +- demos/flowchart.html | 4 +- demos/gantt.html | 4 +- demos/git.html | 4 +- demos/journey.html | 4 +- demos/requirements.html | 4 +- demos/sequence.html | 4 +- demos/state.html | 4 +- demos/timeline.html | 4 +- docs/config/usage.md | 4 +- package.json | 4 +- packages/mermaid/src/docs/config/usage.md | 4 +- pnpm-lock.yaml | 60 +++++++++++++++++++- 74 files changed, 298 insertions(+), 334 deletions(-) diff --git a/.vite/server.ts b/.vite/server.ts index 0f1fef91d..6f8959348 100644 --- a/.vite/server.ts +++ b/.vite/server.ts @@ -1,13 +1,7 @@ -import express, { NextFunction, Request, Response } from 'express'; +import express from 'express'; +import cors from 'cors'; import { createServer as createViteServer } from 'vite'; -const cors = (req: Request, res: Response, next: NextFunction) => { - res.header('Access-Control-Allow-Origin', '*'); - res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE'); - res.header('Access-Control-Allow-Headers', 'Content-Type'); - - next(); -}; async function createServer() { const app = express(); diff --git a/cypress/platform/bundle-test.js b/cypress/platform/bundle-test.js index a991918c4..edd3dfbc4 100644 --- a/cypress/platform/bundle-test.js +++ b/cypress/platform/bundle-test.js @@ -49,13 +49,9 @@ mermaid.initialize({ ], }, }); -mermaid.render( - 'the-id-of-the-svg', - code, - (svg) => { - console.log(svg); - const elem = document.querySelector('#graph-to-be'); - elem.innerHTML = svg; - } - // ,document.querySelector('#tmp') -); +void (async () => { + const { svg } = await mermaid.render('the-id-of-the-svg', code); + console.log(svg); + const elem = document.querySelector('#graph-to-be'); + elem.innerHTML = svg; +})(); diff --git a/cypress/platform/class.html b/cypress/platform/class.html index 1d72c34a5..052dd18b9 100644 --- a/cypress/platform/class.html +++ b/cypress/platform/class.html @@ -113,8 +113,8 @@ classE o-- classF : aggregation callback Shape "callbackFunction" "This is a tooltip for a callback" - - + diff --git a/cypress/platform/click_security_other.html b/cypress/platform/click_security_other.html index 5338cac06..7dc75ea88 100644 --- a/cypress/platform/click_security_other.html +++ b/cypress/platform/click_security_other.html @@ -59,8 +59,8 @@ Add another diagram to demo page : 48h - - - - - - - - - - - + diff --git a/cypress/platform/flow.html b/cypress/platform/flow.html index ed70f80d0..0060ac3cb 100644 --- a/cypress/platform/flow.html +++ b/cypress/platform/flow.html @@ -29,8 +29,8 @@ click a_a "http://www.aftonbladet.se" "apa" - - - - - diff --git a/cypress/platform/git-graph.html b/cypress/platform/git-graph.html index da6025f4b..4cb2656f1 100644 --- a/cypress/platform/git-graph.html +++ b/cypress/platform/git-graph.html @@ -43,8 +43,8 @@ cssClass "BankAccount" customCss - - - - - - - - + - -

Example

@@ -26,4 +16,12 @@ sequenceDiagram
     Note left of Ernie: Cookies are good
     
+ diff --git a/cypress/platform/render-after-error.html b/cypress/platform/render-after-error.html index f5165e0ee..72ccac34c 100644 --- a/cypress/platform/render-after-error.html +++ b/cypress/platform/render-after-error.html @@ -9,19 +9,18 @@
- - diff --git a/cypress/platform/rerender.html b/cypress/platform/rerender.html index ab1b8e009..44ffd8fa8 100644 --- a/cypress/platform/rerender.html +++ b/cypress/platform/rerender.html @@ -9,20 +9,20 @@
- - diff --git a/cypress/platform/showcase_base.html b/cypress/platform/showcase_base.html index 227d79cf7..32a2ae72a 100644 --- a/cypress/platform/showcase_base.html +++ b/cypress/platform/showcase_base.html @@ -313,8 +313,8 @@ requirementDiagram merge release
- - - - - - - - - - - - - - diff --git a/cypress/platform/xss11.html b/cypress/platform/xss11.html index ca97aeaab..302f39ee9 100644 --- a/cypress/platform/xss11.html +++ b/cypress/platform/xss11.html @@ -49,8 +49,8 @@
- - diff --git a/cypress/platform/xss12.html b/cypress/platform/xss12.html index eb1bce327..b1e2c1d0a 100644 --- a/cypress/platform/xss12.html +++ b/cypress/platform/xss12.html @@ -49,8 +49,8 @@
- - diff --git a/cypress/platform/xss13.html b/cypress/platform/xss13.html index f2d90cddb..9f505ea7b 100644 --- a/cypress/platform/xss13.html +++ b/cypress/platform/xss13.html @@ -49,8 +49,8 @@
- - diff --git a/cypress/platform/xss14.html b/cypress/platform/xss14.html index f429b355a..e68b87b78 100644 --- a/cypress/platform/xss14.html +++ b/cypress/platform/xss14.html @@ -49,8 +49,8 @@
- - diff --git a/cypress/platform/xss15.html b/cypress/platform/xss15.html index 70ebe9f86..3fa6b7151 100644 --- a/cypress/platform/xss15.html +++ b/cypress/platform/xss15.html @@ -49,8 +49,8 @@
- - diff --git a/cypress/platform/xss16.html b/cypress/platform/xss16.html index 9325a70aa..6f8a734eb 100644 --- a/cypress/platform/xss16.html +++ b/cypress/platform/xss16.html @@ -49,8 +49,8 @@
- - diff --git a/cypress/platform/xss17.html b/cypress/platform/xss17.html index c498f3f3e..bd7e1c57e 100644 --- a/cypress/platform/xss17.html +++ b/cypress/platform/xss17.html @@ -49,8 +49,8 @@
- - diff --git a/cypress/platform/xss18.html b/cypress/platform/xss18.html index 3e9cfd35c..ccacfadbb 100644 --- a/cypress/platform/xss18.html +++ b/cypress/platform/xss18.html @@ -49,8 +49,8 @@
- - diff --git a/cypress/platform/xss19.html b/cypress/platform/xss19.html index ca747b39e..7966abb8c 100644 --- a/cypress/platform/xss19.html +++ b/cypress/platform/xss19.html @@ -49,8 +49,8 @@
- - diff --git a/cypress/platform/xss2.html b/cypress/platform/xss2.html index 18b4be6fc..da95e3797 100644 --- a/cypress/platform/xss2.html +++ b/cypress/platform/xss2.html @@ -48,8 +48,8 @@ Alice->>Bob: Hi Bob Bob->>Alice: Hi Alice - - - diff --git a/cypress/platform/xss21.html b/cypress/platform/xss21.html index b2f67cd93..7cfa17c9e 100644 --- a/cypress/platform/xss21.html +++ b/cypress/platform/xss21.html @@ -49,8 +49,8 @@
- - diff --git a/cypress/platform/xss22.html b/cypress/platform/xss22.html index d7e47cd02..50ff3b732 100644 --- a/cypress/platform/xss22.html +++ b/cypress/platform/xss22.html @@ -8,8 +8,8 @@ graph TD A --> B["<a href='javascript#9;t#colon;alert(document.location)'>AAA</a>"] - - diff --git a/cypress/platform/xss3.html b/cypress/platform/xss3.html index 78fabc4aa..f01aab37e 100644 --- a/cypress/platform/xss3.html +++ b/cypress/platform/xss3.html @@ -36,8 +36,8 @@ graph LR A --> B - - - diff --git a/cypress/platform/xss5.html b/cypress/platform/xss5.html index f87e65505..f7abf7a45 100644 --- a/cypress/platform/xss5.html +++ b/cypress/platform/xss5.html @@ -49,8 +49,8 @@
- - diff --git a/cypress/platform/xss6.html b/cypress/platform/xss6.html index bc0f78561..7d7ae18d1 100644 --- a/cypress/platform/xss6.html +++ b/cypress/platform/xss6.html @@ -49,8 +49,8 @@
- - diff --git a/cypress/platform/xss7.html b/cypress/platform/xss7.html index d8b2a7620..177b4342c 100644 --- a/cypress/platform/xss7.html +++ b/cypress/platform/xss7.html @@ -49,8 +49,8 @@
- - diff --git a/cypress/platform/xss8.html b/cypress/platform/xss8.html index cf2969f39..5852c2693 100644 --- a/cypress/platform/xss8.html +++ b/cypress/platform/xss8.html @@ -49,8 +49,8 @@
- - diff --git a/cypress/platform/xss9.html b/cypress/platform/xss9.html index 916f1506d..cf2ad1359 100644 --- a/cypress/platform/xss9.html +++ b/cypress/platform/xss9.html @@ -49,8 +49,8 @@
- - diff --git a/demos/c4context.html b/demos/c4context.html index e085e611c..cf358b550 100644 --- a/demos/c4context.html +++ b/demos/c4context.html @@ -217,8 +217,8 @@
- - - - diff --git a/demos/classchart.html b/demos/classchart.html index e8e48e482..b20dda2a3 100644 --- a/demos/classchart.html +++ b/demos/classchart.html @@ -154,8 +154,8 @@
- - - - - - - - - - - - - diff --git a/package.json b/package.json index ddbb61381..8e4c50118 100644 --- a/package.json +++ b/package.json @@ -58,8 +58,9 @@ "@commitlint/cli": "^17.2.0", "@commitlint/config-conventional": "^17.2.0", "@cspell/eslint-plugin": "^6.14.2", + "@types/cors": "^2.8.13", "@types/eslint": "^8.4.10", - "@types/express": "^4.17.14", + "@types/express": "^4.17.17", "@types/js-yaml": "^4.0.5", "@types/jsdom": "^21.0.0", "@types/lodash": "^4.14.188", @@ -73,6 +74,7 @@ "@vitest/spy": "^0.28.4", "@vitest/ui": "^0.28.4", "concurrently": "^7.5.0", + "cors": "^2.8.5", "coveralls": "^3.1.1", "cypress": "^12.0.0", "cypress-image-snapshot": "^4.0.1", diff --git a/packages/mermaid/src/docs/config/usage.md b/packages/mermaid/src/docs/config/usage.md index c805c623a..dd989069f 100644 --- a/packages/mermaid/src/docs/config/usage.md +++ b/packages/mermaid/src/docs/config/usage.md @@ -327,8 +327,8 @@ The future proof way of setting the configuration is by using the initialization on what kind of integration you use. ```html - - diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cf6d9c342..c99933c35 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,12 +16,15 @@ importers: '@cspell/eslint-plugin': specifier: ^6.14.2 version: 6.14.2 + '@types/cors': + specifier: ^2.8.13 + version: 2.8.13 '@types/eslint': specifier: ^8.4.10 version: 8.4.10 '@types/express': - specifier: ^4.17.14 - version: 4.17.14 + specifier: ^4.17.17 + version: 4.17.17 '@types/js-yaml': specifier: ^4.0.5 version: 4.0.5 @@ -61,6 +64,9 @@ importers: concurrently: specifier: ^7.5.0 version: 7.5.0 + cors: + specifier: ^2.8.5 + version: 2.8.5 coveralls: specifier: ^3.1.1 version: 3.1.1 @@ -2650,6 +2656,12 @@ packages: '@types/node': 18.11.9 dev: true + /@types/cors/2.8.13: + resolution: {integrity: sha512-RG8AStHlUiV5ysZQKq97copd2UmVYw3/pRMLefISZ3S1hK104Cwm7iLQ3fTKx+lsUH2CE8FlLaYeEA2LSeqYUA==} + dependencies: + '@types/node': 18.11.9 + dev: true + /@types/cytoscape/3.19.9: resolution: {integrity: sha512-oqCx0ZGiBO0UESbjgq052vjDAy2X53lZpMrWqiweMpvVwKw/2IiYDdzPFK6+f4tMfdv9YKEM9raO5bAZc3UYBg==} dev: true @@ -2875,6 +2887,14 @@ packages: '@types/range-parser': 1.2.4 dev: true + /@types/express-serve-static-core/4.17.33: + resolution: {integrity: sha512-TPBqmR/HRYI3eC2E5hmiivIzv+bidAfXofM+sbonAGvyDhySGw9/PQZFt2BLOrjUUR++4eJVpx6KnLQK1Fk9tA==} + dependencies: + '@types/node': 18.11.9 + '@types/qs': 6.9.7 + '@types/range-parser': 1.2.4 + dev: true + /@types/express/4.17.14: resolution: {integrity: sha512-TEbt+vaPFQ+xpxFLFssxUDXj5cWCxZJjIcB7Yg0k0GMHGtgtQgpvx/MUQUeAkNbA9AAGrwkAsoeItdTgS7FMyg==} dependencies: @@ -2884,6 +2904,15 @@ packages: '@types/serve-static': 1.15.0 dev: true + /@types/express/4.17.17: + resolution: {integrity: sha512-Q4FmmuLGBG58btUnfS1c1r/NQdlp3DMfGDGig8WhfpA2YRUtEkxAjkZb0yvplJGYdF1fsQ81iMDcH24sSCNC/Q==} + dependencies: + '@types/body-parser': 1.19.2 + '@types/express-serve-static-core': 4.17.33 + '@types/qs': 6.9.7 + '@types/serve-static': 1.15.0 + dev: true + /@types/flexsearch/0.7.3: resolution: {integrity: sha512-HXwADeHEP4exXkCIwy2n1+i0f1ilP1ETQOH5KDOugjkTFZPntWo0Gr8stZOaebkxsdx+k0X/K6obU/+it07ocg==} dev: true @@ -4222,7 +4251,7 @@ packages: /axios/0.27.2_debug@4.3.4: resolution: {integrity: sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==} dependencies: - follow-redirects: 1.15.2_debug@4.3.2 + follow-redirects: 1.15.2_debug@4.3.4 form-data: 4.0.0 transitivePeerDependencies: - debug @@ -4965,6 +4994,14 @@ packages: resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==} dev: true + /cors/2.8.5: + resolution: {integrity: sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==} + engines: {node: '>= 0.10'} + dependencies: + object-assign: 4.1.1 + vary: 1.1.2 + dev: true + /cose-base/1.0.3: resolution: {integrity: sha512-s9whTXInMSgAp/NVXVNuVxVKzGH2qck3aQlVHxDCdAEPgtMKwc4Wq6/QKhgdEdgbLSi9rBTAcPoRa6JpiG4ksg==} dependencies: @@ -6791,6 +6828,18 @@ packages: debug: 4.3.2 dev: true + /follow-redirects/1.15.2_debug@4.3.4: + resolution: {integrity: sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==} + engines: {node: '>=4.0'} + peerDependencies: + debug: '*' + peerDependenciesMeta: + debug: + optional: true + dependencies: + debug: 4.3.4 + dev: true + /foreground-child/2.0.0: resolution: {integrity: sha512-dCIq9FpEcyQyXKCkyzmlPTFNgrCzPudOe+mhvJU5zAtlBnGVy2yKxtfsxK2tQBThwq225jcvBjpw1Gr40uzZCA==} engines: {node: '>=8.0.0'} @@ -9466,6 +9515,11 @@ packages: resolution: {integrity: sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==} dev: true + /object-assign/4.1.1: + resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==} + engines: {node: '>=0.10.0'} + dev: true + /object-inspect/1.12.2: resolution: {integrity: sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ==} dev: true From 6aa3ea43ae4975b6bb03015e4e72aa97d7f9b8fe Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Sun, 19 Feb 2023 14:13:30 +0530 Subject: [PATCH 35/67] Remove Readme --- packages/mermaid/README.md | 346 ------------------------------- packages/mermaid/README.zh-CN.md | 334 ----------------------------- 2 files changed, 680 deletions(-) delete mode 100644 packages/mermaid/README.md delete mode 100644 packages/mermaid/README.zh-CN.md diff --git a/packages/mermaid/README.md b/packages/mermaid/README.md deleted file mode 100644 index d453d2ec0..000000000 --- a/packages/mermaid/README.md +++ /dev/null @@ -1,346 +0,0 @@ -# mermaid - -[![Build CI Status](https://github.com/mermaid-js/mermaid/actions/workflows/build.yml/badge.svg)](https://github.com/mermaid-js/mermaid/actions/workflows/build.yml) [![NPM](https://img.shields.io/npm/v/mermaid)](https://www.npmjs.com/package/mermaid) [![npm minified gzipped bundle size](https://img.shields.io/bundlephobia/minzip/mermaid)](https://bundlephobia.com/package/mermaid) [![Coverage Status](https://coveralls.io/repos/github/mermaid-js/mermaid/badge.svg?branch=master)](https://coveralls.io/github/mermaid-js/mermaid?branch=master) [![CDN Status](https://img.shields.io/jsdelivr/npm/hm/mermaid)](https://www.jsdelivr.com/package/npm/mermaid) [![NPM](https://img.shields.io/npm/dm/mermaid)](https://www.npmjs.com/package/mermaid) [![Join our Slack!](https://img.shields.io/static/v1?message=join%20chat&color=9cf&logo=slack&label=slack)](https://join.slack.com/t/mermaid-talk/shared_invite/enQtNzc4NDIyNzk4OTAyLWVhYjQxOTI2OTg4YmE1ZmJkY2Y4MTU3ODliYmIwOTY3NDJlYjA0YjIyZTdkMDMyZTUwOGI0NjEzYmEwODcwOTE) [![Twitter Follow](https://img.shields.io/twitter/follow/mermaidjs_?style=social)](https://twitter.com/mermaidjs_) - -English | [简体中文](./README.zh-CN.md) - - - -:trophy: **Mermaid was nominated and won the [JS Open Source Awards (2019)](https://osawards.com/javascript/2019) in the category "The most exciting use of technology"!!!** - -**Thanks to all involved, people committing pull requests, people answering questions! 🙏** - -Explore Mermaid.js in depth, with real-world examples, tips & tricks from the creator... The first official book on Mermaid is available for purchase. Check it out! - -## About - - - -Mermaid is a JavaScript-based diagramming and charting tool that uses Markdown-inspired text definitions and a renderer to create and modify complex diagrams. The main purpose of Mermaid is to help documentation catch up with development. - -> Doc-Rot is a Catch-22 that Mermaid helps to solve. - -Diagramming and documentation costs precious developer time and gets outdated quickly. -But not having diagrams or docs ruins productivity and hurts organizational learning.
-Mermaid addresses this problem by enabling users to create easily modifiable diagrams. It can also be made part of production scripts (and other pieces of code).
-
- -Mermaid allows even non-programmers to easily create detailed diagrams through the [Mermaid Live Editor](https://mermaid.live/).
-[Tutorials](./docs/Tutorials.md) has video tutorials. -Use Mermaid with your favorite applications, check out the list of [Integrations and Usages of Mermaid](./docs/integrations.md). - -You can also use Mermaid within [GitHub](https://github.blog/2022-02-14-include-diagrams-markdown-files-mermaid/) as well many of your other favorite applications—check out the list of [Integrations and Usages of Mermaid](./docs/integrations.md). - -For a more detailed introduction to Mermaid and some of its more basic uses, look to the [Beginner's Guide](./docs/n00b-overview.md), [Usage](./docs/usage.md) and [Tutorials](./docs/Tutorials.md). - -🌐 [CDN](https://www.jsdelivr.com/package/npm/mermaid) | 📖 [Documentation](https://mermaidjs.github.io) | 🙌 [Contribution](https://github.com/mermaid-js/mermaid/blob/develop/CONTRIBUTING.md) | 📜 [Changelog](./docs/CHANGELOG.md) - -In our release process we rely heavily on visual regression tests using [applitools](https://applitools.com/). Applitools is a great service which has been easy to use and integrate with our tests. - - - - - - - -## Examples - -**The following are some examples of the diagrams, charts and graphs that can be made using Mermaid. Click here to jump into the [text syntax](https://mermaid-js.github.io/mermaid/#/n00b-syntaxReference).** - - - -### Flowchart [docs - live editor] - -``` -flowchart LR - -A[Hard] -->|Text| B(Round) -B --> C{Decision} -C -->|One| D[Result 1] -C -->|Two| E[Result 2] -``` - -```mermaid -flowchart LR - -A[Hard] -->|Text| B(Round) -B --> C{Decision} -C -->|One| D[Result 1] -C -->|Two| E[Result 2] -``` - -### Sequence diagram [docs - live editor] - -``` -sequenceDiagram -Alice->>John: Hello John, how are you? -loop Healthcheck - John->>John: Fight against hypochondria -end -Note right of John: Rational thoughts! -John-->>Alice: Great! -John->>Bob: How about you? -Bob-->>John: Jolly good! -``` - -```mermaid -sequenceDiagram -Alice->>John: Hello John, how are you? -loop Healthcheck - John->>John: Fight against hypochondria -end -Note right of John: Rational thoughts! -John-->>Alice: Great! -John->>Bob: How about you? -Bob-->>John: Jolly good! -``` - -### Gantt chart [docs - live editor] - -``` -gantt - section Section - Completed :done, des1, 2014-01-06,2014-01-08 - Active :active, des2, 2014-01-07, 3d - Parallel 1 : des3, after des1, 1d - Parallel 2 : des4, after des1, 1d - Parallel 3 : des5, after des3, 1d - Parallel 4 : des6, after des4, 1d -``` - -```mermaid -gantt - section Section - Completed :done, des1, 2014-01-06,2014-01-08 - Active :active, des2, 2014-01-07, 3d - Parallel 1 : des3, after des1, 1d - Parallel 2 : des4, after des1, 1d - Parallel 3 : des5, after des3, 1d - Parallel 4 : des6, after des4, 1d -``` - -### Class diagram [docs - live editor] - -``` -classDiagram -Class01 <|-- AveryLongClass : Cool -<> Class01 -Class09 --> C2 : Where am I? -Class09 --* C3 -Class09 --|> Class07 -Class07 : equals() -Class07 : Object[] elementData -Class01 : size() -Class01 : int chimp -Class01 : int gorilla -class Class10 { - <> - int id - size() -} -``` - -```mermaid -classDiagram -Class01 <|-- AveryLongClass : Cool -<> Class01 -Class09 --> C2 : Where am I? -Class09 --* C3 -Class09 --|> Class07 -Class07 : equals() -Class07 : Object[] elementData -Class01 : size() -Class01 : int chimp -Class01 : int gorilla -class Class10 { - <> - int id - size() -} -``` - -### State diagram [docs - live editor] - -``` -stateDiagram-v2 -[*] --> Still -Still --> [*] -Still --> Moving -Moving --> Still -Moving --> Crash -Crash --> [*] -``` - -```mermaid -stateDiagram-v2 -[*] --> Still -Still --> [*] -Still --> Moving -Moving --> Still -Moving --> Crash -Crash --> [*] -``` - -### Pie chart [docs - live editor] - -``` -pie -"Dogs" : 386 -"Cats" : 85.9 -"Rats" : 15 -``` - -```mermaid -pie -"Dogs" : 386 -"Cats" : 85.9 -"Rats" : 15 -``` - -### Git graph [experimental - live editor] - -### User Journey diagram [docs - live editor] - -``` - journey - title My working day - section Go to work - Make tea: 5: Me - Go upstairs: 3: Me - Do work: 1: Me, Cat - section Go home - Go downstairs: 5: Me - Sit down: 3: Me -``` - -```mermaid - journey - title My working day - section Go to work - Make tea: 5: Me - Go upstairs: 3: Me - Do work: 1: Me, Cat - section Go home - Go downstairs: 5: Me - Sit down: 3: Me -``` - -### C4 diagram [docs] - -``` -C4Context -title System Context diagram for Internet Banking System - -Person(customerA, "Banking Customer A", "A customer of the bank, with personal bank accounts.") -Person(customerB, "Banking Customer B") -Person_Ext(customerC, "Banking Customer C") -System(SystemAA, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.") - -Person(customerD, "Banking Customer D", "A customer of the bank,
with personal bank accounts.") - -Enterprise_Boundary(b1, "BankBoundary") { - - SystemDb_Ext(SystemE, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.") - - System_Boundary(b2, "BankBoundary2") { - System(SystemA, "Banking System A") - System(SystemB, "Banking System B", "A system of the bank, with personal bank accounts.") - } - - System_Ext(SystemC, "E-mail system", "The internal Microsoft Exchange e-mail system.") - SystemDb(SystemD, "Banking System D Database", "A system of the bank, with personal bank accounts.") - - Boundary(b3, "BankBoundary3", "boundary") { - SystemQueue(SystemF, "Banking System F Queue", "A system of the bank, with personal bank accounts.") - SystemQueue_Ext(SystemG, "Banking System G Queue", "A system of the bank, with personal bank accounts.") - } -} - -BiRel(customerA, SystemAA, "Uses") -BiRel(SystemAA, SystemE, "Uses") -Rel(SystemAA, SystemC, "Sends e-mails", "SMTP") -Rel(SystemC, customerA, "Sends e-mails to") -``` - -```mermaid -C4Context -title System Context diagram for Internet Banking System - -Person(customerA, "Banking Customer A", "A customer of the bank, with personal bank accounts.") -Person(customerB, "Banking Customer B") -Person_Ext(customerC, "Banking Customer C") -System(SystemAA, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.") - -Person(customerD, "Banking Customer D", "A customer of the bank,
with personal bank accounts.") - -Enterprise_Boundary(b1, "BankBoundary") { - - SystemDb_Ext(SystemE, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.") - - System_Boundary(b2, "BankBoundary2") { - System(SystemA, "Banking System A") - System(SystemB, "Banking System B", "A system of the bank, with personal bank accounts.") - } - - System_Ext(SystemC, "E-mail system", "The internal Microsoft Exchange e-mail system.") - SystemDb(SystemD, "Banking System D Database", "A system of the bank, with personal bank accounts.") - - Boundary(b3, "BankBoundary3", "boundary") { - SystemQueue(SystemF, "Banking System F Queue", "A system of the bank, with personal bank accounts.") - SystemQueue_Ext(SystemG, "Banking System G Queue", "A system of the bank, with personal bank accounts.") - } -} - -BiRel(customerA, SystemAA, "Uses") -BiRel(SystemAA, SystemE, "Uses") -Rel(SystemAA, SystemC, "Sends e-mails", "SMTP") -Rel(SystemC, customerA, "Sends e-mails to") -``` - -## Release - -For those who have the permission to do so: - -Update version number in `package.json`. - -```sh -npm publish -``` - -The above command generates files into the `dist` folder and publishes them to npmjs.org. - -## Related projects - -- [Command Line Interface](https://github.com/mermaid-js/mermaid-cli) -- [Live Editor](https://github.com/mermaid-js/mermaid-live-editor) -- [HTTP Server](https://github.com/TomWright/mermaid-server) - -## Contributors [![Good first issue](https://img.shields.io/github/labels/mermaid-js/mermaid/Good%20first%20issue%21)](https://github.com/mermaid-js/mermaid/issues?q=is%3Aissue+is%3Aopen+label%3A%22Good+first+issue%21%22) [![Contributors](https://img.shields.io/github/contributors/mermaid-js/mermaid)](https://github.com/mermaid-js/mermaid/graphs/contributors) [![Commits](https://img.shields.io/github/commit-activity/m/mermaid-js/mermaid)](https://github.com/mermaid-js/mermaid/graphs/contributors) - -Mermaid is a growing community and is always accepting new contributors. There's a lot of different ways to help out and we're always looking for extra hands! Look at [this issue](https://github.com/mermaid-js/mermaid/issues/866) if you want to know where to start helping out. - -Detailed information about how to contribute can be found in the [contribution guide](CONTRIBUTING.md) - -## Security and safe diagrams - -For public sites, it can be precarious to retrieve text from users on the internet, storing that content for presentation in a browser at a later stage. The reason is that the user content can contain embedded malicious scripts that will run when the data is presented. For Mermaid this is a risk, specially as mermaid diagrams contain many characters that are used in html which makes the standard sanitation unusable as it also breaks the diagrams. We still make an effort to sanitise the incoming code and keep refining the process but it is hard to guarantee that there are no loop holes. - -As an extra level of security for sites with external users we are happy to introduce a new security level in which the diagram is rendered in a sandboxed iframe preventing javascript in the code from being executed. This is a great step forward for better security. - -_Unfortunately you can not have a cake and eat it at the same time which in this case means that some of the interactive functionality gets blocked along with the possible malicious code._ - -## Reporting vulnerabilities - -To report a vulnerability, please e-mail security@mermaid.live with a description of the issue, the steps you took to create the issue, affected versions, and if known, mitigations for the issue. - -## Appreciation - -A quick note from Knut Sveidqvist: - -> _Many thanks to the [d3](https://d3js.org/) and [dagre-d3](https://github.com/cpettitt/dagre-d3) projects for providing the graphical layout and drawing libraries!_ >_Thanks also to the [js-sequence-diagram](https://bramp.github.io/js-sequence-diagrams) project for usage of the grammar for the sequence diagrams. Thanks to Jessica Peter for inspiration and starting point for gantt rendering._ >_Thank you to [Tyler Long](https://github.com/tylerlong) who has been a collaborator since April 2017._ -> -> _Thank you to the ever-growing list of [contributors](https://github.com/knsv/mermaid/graphs/contributors) that brought the project this far!_ - ---- - -_Mermaid was created by Knut Sveidqvist for easier documentation._ diff --git a/packages/mermaid/README.zh-CN.md b/packages/mermaid/README.zh-CN.md deleted file mode 100644 index 3612ba0a9..000000000 --- a/packages/mermaid/README.zh-CN.md +++ /dev/null @@ -1,334 +0,0 @@ -# mermaid - -[![Build CI Status](https://github.com/mermaid-js/mermaid/actions/workflows/build.yml/badge.svg)](https://github.com/mermaid-js/mermaid/actions/workflows/build.yml) [![NPM](https://img.shields.io/npm/v/mermaid)](https://www.npmjs.com/package/mermaid) [![npm minified gzipped bundle size](https://img.shields.io/bundlephobia/minzip/mermaid)](https://bundlephobia.com/package/mermaid) [![Coverage Status](https://coveralls.io/repos/github/mermaid-js/mermaid/badge.svg?branch=master)](https://coveralls.io/github/mermaid-js/mermaid?branch=master) [![CDN Status](https://img.shields.io/jsdelivr/npm/hm/mermaid)](https://www.jsdelivr.com/package/npm/mermaid) [![NPM](https://img.shields.io/npm/dm/mermaid)](https://www.npmjs.com/package/mermaid) [![Join our Slack!](https://img.shields.io/static/v1?message=join%20chat&color=9cf&logo=slack&label=slack)](https://join.slack.com/t/mermaid-talk/shared_invite/enQtNzc4NDIyNzk4OTAyLWVhYjQxOTI2OTg4YmE1ZmJkY2Y4MTU3ODliYmIwOTY3NDJlYjA0YjIyZTdkMDMyZTUwOGI0NjEzYmEwODcwOTE) [![Twitter Follow](https://img.shields.io/twitter/follow/mermaidjs_?style=social)](https://twitter.com/mermaidjs_) - -[English](./README.md) | 简体中文 - - - -:trophy: **Mermaid 被提名并获得了 [JS Open Source Awards (2019)](https://osawards.com/javascript/2019) 的 "The most exciting use of technology" 奖项!!!** - -**感谢所有参与进来提交 PR,解答疑问的人们! 🙏** - -Explore Mermaid.js in depth, with real-world examples, tips & tricks from the creator... The first official book on Mermaid is available for purchase. Check it out! - -## 关于 Mermaid - - - -Mermaid 是一个基于 Javascript 的图表绘制工具,通过解析类 Markdown 的文本语法来实现图表的创建和动态修改。Mermaid 诞生的主要目的是让文档的更新能够及时跟上开发进度。 - -> Doc-Rot 是 Mermaid 致力于解决的一个难题。 - -绘图和编写文档花费了开发者宝贵的开发时间,而且随着业务的变更,它很快就会过期。 但是如果缺少了图表或文档,对于生产力和团队新人的业务学习都会产生巨大的阻碍。
-Mermaid 通过允许用户创建便于修改的图表来解决这一难题,它也可以作为生产脚本(或其他代码)的一部分。
-
-Mermaid 甚至能让非程序员也能通过 [Mermaid Live Editor](https://mermaid.live/) 轻松创建详细的图表。
-你可以访问 [教程](./docs/Tutorials.md) 来查看 Live Editor 的视频教程,也可以查看 [Mermaid 的集成和使用](./docs/integrations.md) 这个清单来检查你的文档工具是否已经集成了 Mermaid 支持。 - -如果想要查看关于 Mermaid 更详细的介绍及基础使用方式,可以查看 [入门指引](./docs/n00b-overview.md), [用法](./docs/usage.md) 和 [教程](./docs/Tutorials.md). - -🌐 [CDN](https://www.jsdelivr.com/package/npm/mermaid) | 📖 [文档](https://mermaidjs.github.io) | 🙌 [贡献](https://github.com/mermaid-js/mermaid/blob/develop/CONTRIBUTING.md) | 📜 [更新日志](./docs/CHANGELOG.md) - - - -## 示例 - -**下面是一些可以使用 Mermaid 创建的图表示例。点击 [语法](https://mermaid-js.github.io/mermaid/#/n00b-syntaxReference) 查看详情。** - - - - -### 流程图 [文档 - live editor] - -``` -flowchart LR -A[Hard] -->|Text| B(Round) -B --> C{Decision} -C -->|One| D[Result 1] -C -->|Two| E[Result 2] -``` - -```mermaid -flowchart LR -A[Hard] -->|Text| B(Round) -B --> C{Decision} -C -->|One| D[Result 1] -C -->|Two| E[Result 2] -``` - -### 时序图 [文档 - live editor] - -``` -sequenceDiagram -Alice->>John: Hello John, how are you? -loop Healthcheck - John->>John: Fight against hypochondria -end -Note right of John: Rational thoughts! -John-->>Alice: Great! -John->>Bob: How about you? -Bob-->>John: Jolly good! -``` - -```mermaid -sequenceDiagram -Alice->>John: Hello John, how are you? -loop Healthcheck - John->>John: Fight against hypochondria -end -Note right of John: Rational thoughts! -John-->>Alice: Great! -John->>Bob: How about you? -Bob-->>John: Jolly good! -``` - -### 甘特图 [文档 - live editor] - -``` -gantt - section Section - Completed :done, des1, 2014-01-06,2014-01-08 - Active :active, des2, 2014-01-07, 3d - Parallel 1 : des3, after des1, 1d - Parallel 2 : des4, after des1, 1d - Parallel 3 : des5, after des3, 1d - Parallel 4 : des6, after des4, 1d -``` - -```mermaid -gantt - section Section - Completed :done, des1, 2014-01-06,2014-01-08 - Active :active, des2, 2014-01-07, 3d - Parallel 1 : des3, after des1, 1d - Parallel 2 : des4, after des1, 1d - Parallel 3 : des5, after des3, 1d - Parallel 4 : des6, after des4, 1d -``` - -### 类图 [文档 - live editor] - -``` -classDiagram -Class01 <|-- AveryLongClass : Cool -<> Class01 -Class09 --> C2 : Where am I? -Class09 --* C3 -Class09 --|> Class07 -Class07 : equals() -Class07 : Object[] elementData -Class01 : size() -Class01 : int chimp -Class01 : int gorilla -class Class10 { - <> - int id - size() -} -``` - -```mermaid -classDiagram -Class01 <|-- AveryLongClass : Cool -<> Class01 -Class09 --> C2 : Where am I? -Class09 --* C3 -Class09 --|> Class07 -Class07 : equals() -Class07 : Object[] elementData -Class01 : size() -Class01 : int chimp -Class01 : int gorilla -class Class10 { - <> - int id - size() -} -``` - -### 状态图 [[docs - live editor] - -``` -stateDiagram-v2 -[*] --> Still -Still --> [*] -Still --> Moving -Moving --> Still -Moving --> Crash -Crash --> [*] -``` - -```mermaid -stateDiagram-v2 -[*] --> Still -Still --> [*] -Still --> Moving -Moving --> Still -Moving --> Crash -Crash --> [*] -``` - -### 饼图 [文档 - live editor] - -``` -pie -"Dogs" : 386 -"Cats" : 85 -"Rats" : 15 -``` - -```mermaid -pie -"Dogs" : 386 -"Cats" : 85 -"Rats" : 15 -``` - -### Git 图 [实验特性 - live editor] - -### 用户体验旅程图 [文档 - live editor] - -``` - journey - title My working day - section Go to work - Make tea: 5: Me - Go upstairs: 3: Me - Do work: 1: Me, Cat - section Go home - Go downstairs: 5: Me - Sit down: 3: Me -``` - -```mermaid - journey - title My working day - section Go to work - Make tea: 5: Me - Go upstairs: 3: Me - Do work: 1: Me, Cat - section Go home - Go downstairs: 5: Me - Sit down: 3: Me -``` - -### C4 图 [文档] - -``` -C4Context -title System Context diagram for Internet Banking System - -Person(customerA, "Banking Customer A", "A customer of the bank, with personal bank accounts.") -Person(customerB, "Banking Customer B") -Person_Ext(customerC, "Banking Customer C") -System(SystemAA, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.") - -Person(customerD, "Banking Customer D", "A customer of the bank,
with personal bank accounts.") - -Enterprise_Boundary(b1, "BankBoundary") { - - SystemDb_Ext(SystemE, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.") - - System_Boundary(b2, "BankBoundary2") { - System(SystemA, "Banking System A") - System(SystemB, "Banking System B", "A system of the bank, with personal bank accounts.") - } - - System_Ext(SystemC, "E-mail system", "The internal Microsoft Exchange e-mail system.") - SystemDb(SystemD, "Banking System D Database", "A system of the bank, with personal bank accounts.") - - Boundary(b3, "BankBoundary3", "boundary") { - SystemQueue(SystemF, "Banking System F Queue", "A system of the bank, with personal bank accounts.") - SystemQueue_Ext(SystemG, "Banking System G Queue", "A system of the bank, with personal bank accounts.") - } -} - -BiRel(customerA, SystemAA, "Uses") -BiRel(SystemAA, SystemE, "Uses") -Rel(SystemAA, SystemC, "Sends e-mails", "SMTP") -Rel(SystemC, customerA, "Sends e-mails to") -``` - -```mermaid -C4Context -title System Context diagram for Internet Banking System - -Person(customerA, "Banking Customer A", "A customer of the bank, with personal bank accounts.") -Person(customerB, "Banking Customer B") -Person_Ext(customerC, "Banking Customer C") -System(SystemAA, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.") - -Person(customerD, "Banking Customer D", "A customer of the bank,
with personal bank accounts.") - -Enterprise_Boundary(b1, "BankBoundary") { - - SystemDb_Ext(SystemE, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.") - - System_Boundary(b2, "BankBoundary2") { - System(SystemA, "Banking System A") - System(SystemB, "Banking System B", "A system of the bank, with personal bank accounts.") - } - - System_Ext(SystemC, "E-mail system", "The internal Microsoft Exchange e-mail system.") - SystemDb(SystemD, "Banking System D Database", "A system of the bank, with personal bank accounts.") - - Boundary(b3, "BankBoundary3", "boundary") { - SystemQueue(SystemF, "Banking System F Queue", "A system of the bank, with personal bank accounts.") - SystemQueue_Ext(SystemG, "Banking System G Queue", "A system of the bank, with personal bank accounts.") - } -} - -BiRel(customerA, SystemAA, "Uses") -BiRel(SystemAA, SystemE, "Uses") -Rel(SystemAA, SystemC, "Sends e-mails", "SMTP") -Rel(SystemC, customerA, "Sends e-mails to") -``` - -## 发布 - -对于有权限的同学来说,你可以通过以下步骤来完成发布操作: - -更新 `package.json` 中的版本号,然后执行如下命令: - -```sh -npm publish -``` - -以上的命令会将文件打包到 `dist` 目录并发布至 npmjs.org. - -## 相关项目 - -- [Command Line Interface](https://github.com/mermaid-js/mermaid-cli) -- [Live Editor](https://github.com/mermaid-js/mermaid-live-editor) -- [HTTP Server](https://github.com/TomWright/mermaid-server) - -## 贡献者 [![Good first issue](https://img.shields.io/github/labels/mermaid-js/mermaid/Good%20first%20issue%21)](https://github.com/mermaid-js/mermaid/issues?q=is%3Aissue+is%3Aopen+label%3A%22Good+first+issue%21%22) [![Contributors](https://img.shields.io/github/contributors/mermaid-js/mermaid)](https://github.com/mermaid-js/mermaid/graphs/contributors) [![Commits](https://img.shields.io/github/commit-activity/m/mermaid-js/mermaid)](https://github.com/mermaid-js/mermaid/graphs/contributors) - -Mermaid 是一个不断发展中的社区,并且还在接收新的贡献者。有很多不同的方式可以参与进来,而且我们还在寻找额外的帮助。如果你想知道如何开始贡献,请查看 [这个 issue](https://github.com/mermaid-js/mermaid/issues/866)。 - -关于如何贡献的详细信息可以在 [贡献指南](CONTRIBUTING.md) 中找到。 - -## 安全 - -对于公开网站来说,从互联网上的用户处检索文本、存储供后续在浏览器中展示的内容可能是不安全的,理由是用户的内容可能嵌入一些数据加载完成之后就会运行的恶意脚本,这些对于 Mermaid 来说毫无疑问是一个风险,尤其是 mermaid 图表还包含了许多在 html 中使用的字符,这意味着我们难以使用常规的手段来过滤不安全代码,因为这些常规手段会造成图表损坏。我们仍然在努力对获取到的代码进行安全过滤并不断完善我们的程序,但很难保证没有漏洞。 - -作为拥有外部用户的网站的额外安全级别,我们很高兴推出一个新的安全级别,其中的图表在沙盒 iframe 中渲染,防止代码中的 javascript 被执行,这是在安全性方面迈出的一大步。 - -_很不幸的是,鱼与熊掌不可兼得,在这个场景下它意味着在可能的恶意代码被阻止时,也会损失部分交互能力_。 - -## 报告漏洞 - -如果想要报告漏洞,请发送邮件到 security@mermaid.live, 并附上问题的描述、复现问题的步骤、受影响的版本,以及解决问题的方案(如果有的话)。 - -## 鸣谢 - -来自 Knut Sveidqvist: - -> _特别感谢 [d3](https://d3js.org/) 和 [dagre-d3](https://github.com/cpettitt/dagre-d3) 这两个优秀的项目,它们提供了图形布局和绘图工具库! _ >_同样感谢 [js-sequence-diagram](https://bramp.github.io/js-sequence-diagrams) 提供了时序图语法的使用。 感谢 Jessica Peter 提供了甘特图渲染的灵感。_ >_感谢 [Tyler Long](https://github.com/tylerlong) 从 2017 年四月开始成为了项目的合作者。_ -> -> _感谢越来越多的 [贡献者们](https://github.com/knsv/mermaid/graphs/contributors),没有你们,就没有这个项目的今天!_ - ---- - -_Mermaid 是由 Knut Sveidqvist 创建,它为了更简单的文档编写而生。_ From 1684faf6325c55a0999e309b130a729363598340 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Sun, 19 Feb 2023 14:15:50 +0530 Subject: [PATCH 36/67] Fix lint --- .vite/server.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/.vite/server.ts b/.vite/server.ts index 6f8959348..35bc56cd1 100644 --- a/.vite/server.ts +++ b/.vite/server.ts @@ -2,7 +2,6 @@ import express from 'express'; import cors from 'cors'; import { createServer as createViteServer } from 'vite'; - async function createServer() { const app = express(); From 6e3d96e16dcf675c3049c8180094858d6af1382b Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Sun, 19 Feb 2023 14:18:09 +0530 Subject: [PATCH 37/67] fix Server --- .vite/server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vite/server.ts b/.vite/server.ts index 35bc56cd1..650cd103d 100644 --- a/.vite/server.ts +++ b/.vite/server.ts @@ -12,7 +12,7 @@ async function createServer() { appType: 'custom', // don't include Vite's default HTML handling middlewares }); - app.use(cors); + app.use(cors()); app.use(express.static('./packages/mermaid/dist')); // app.use(express.static('./packages/mermaid-example-diagram/dist')); app.use(express.static('./packages/mermaid-example-diagram/dist')); From 8c64a907211be0f9823658b0ee8254e696c041d9 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Sun, 19 Feb 2023 14:21:15 +0530 Subject: [PATCH 38/67] Fix docs --- .vite/server.ts | 1 - .../interfaces/mermaidAPI.RenderResult.md | 4 ++-- docs/config/setup/modules/mermaidAPI.md | 20 +++++++++---------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.vite/server.ts b/.vite/server.ts index 650cd103d..7a65cba00 100644 --- a/.vite/server.ts +++ b/.vite/server.ts @@ -14,7 +14,6 @@ async function createServer() { app.use(cors()); app.use(express.static('./packages/mermaid/dist')); - // app.use(express.static('./packages/mermaid-example-diagram/dist')); app.use(express.static('./packages/mermaid-example-diagram/dist')); app.use(vite.middlewares); app.use(express.static('demos')); diff --git a/docs/config/setup/interfaces/mermaidAPI.RenderResult.md b/docs/config/setup/interfaces/mermaidAPI.RenderResult.md index b95b0acff..89a8d70b2 100644 --- a/docs/config/setup/interfaces/mermaidAPI.RenderResult.md +++ b/docs/config/setup/interfaces/mermaidAPI.RenderResult.md @@ -65,7 +65,7 @@ element will be removed when rendering is completed. #### Defined in -[mermaidAPI.ts:382](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L382) +[mermaidAPI.ts:385](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L385) --- @@ -75,4 +75,4 @@ element will be removed when rendering is completed. #### Defined in -[mermaidAPI.ts:381](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L381) +[mermaidAPI.ts:384](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L384) diff --git a/docs/config/setup/modules/mermaidAPI.md b/docs/config/setup/modules/mermaidAPI.md index f75dd85c7..7d45a5a13 100644 --- a/docs/config/setup/modules/mermaidAPI.md +++ b/docs/config/setup/modules/mermaidAPI.md @@ -94,7 +94,7 @@ mermaid.initialize(config); #### Defined in -[mermaidAPI.ts:666](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L666) +[mermaidAPI.ts:669](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L669) ## Functions @@ -125,7 +125,7 @@ Return the last node appended #### Defined in -[mermaidAPI.ts:289](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L289) +[mermaidAPI.ts:292](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L292) --- @@ -151,7 +151,7 @@ the cleaned up svgCode #### Defined in -[mermaidAPI.ts:240](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L240) +[mermaidAPI.ts:243](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L243) --- @@ -177,7 +177,7 @@ the string with all the user styles #### Defined in -[mermaidAPI.ts:169](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L169) +[mermaidAPI.ts:172](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L172) --- @@ -200,7 +200,7 @@ the string with all the user styles #### Defined in -[mermaidAPI.ts:217](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L217) +[mermaidAPI.ts:220](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L220) --- @@ -227,7 +227,7 @@ with an enclosing block that has each of the cssClasses followed by !important; #### Defined in -[mermaidAPI.ts:153](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L153) +[mermaidAPI.ts:156](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L156) --- @@ -247,7 +247,7 @@ with an enclosing block that has each of the cssClasses followed by !important; #### Defined in -[mermaidAPI.ts:133](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L133) +[mermaidAPI.ts:136](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L136) --- @@ -267,7 +267,7 @@ with an enclosing block that has each of the cssClasses followed by !important; #### Defined in -[mermaidAPI.ts:104](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L104) +[mermaidAPI.ts:107](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L107) --- @@ -293,7 +293,7 @@ Put the svgCode into an iFrame. Return the iFrame code #### Defined in -[mermaidAPI.ts:268](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L268) +[mermaidAPI.ts:271](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L271) --- @@ -318,4 +318,4 @@ Remove any existing elements from the given document #### Defined in -[mermaidAPI.ts:339](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L339) +[mermaidAPI.ts:342](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L342) From 8363552c3aab91dd367c7d1761538219fc71005f Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Sun, 19 Feb 2023 14:52:08 +0530 Subject: [PATCH 39/67] Skip flowchart-elk failing test --- cypress/integration/rendering/flowchart-elk.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/integration/rendering/flowchart-elk.spec.js b/cypress/integration/rendering/flowchart-elk.spec.js index 0d4ec4211..ee803b0d8 100644 --- a/cypress/integration/rendering/flowchart-elk.spec.js +++ b/cypress/integration/rendering/flowchart-elk.spec.js @@ -133,7 +133,7 @@ describe('Flowchart ELK', () => { }); }); - it('V2 elk - 16: Render Stadium shape', () => { + it.skip('V2 elk - 16: Render Stadium shape', () => { imgSnapshotTest( ` flowchart-elk TD A([stadium shape test]) From 57fd3e586a7342731ff4eee9aedc10555de0c553 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Sun, 19 Feb 2023 14:58:55 +0530 Subject: [PATCH 40/67] chore: Rename lazy loaded diagram definitions --- packages/mermaid/src/diagrams/flowchart/elk/detector.ts | 2 +- .../elk/{diagram-definition.ts => flowchart-elk-definition.ts} | 0 packages/mermaid/src/diagrams/mindmap/detector.ts | 2 +- .../mindmap/{diagram-definition.ts => mindmap-definition.ts} | 0 packages/mermaid/src/diagrams/timeline/detector.ts | 2 +- .../timeline/{diagram-definition.ts => timeline-definition.ts} | 0 6 files changed, 3 insertions(+), 3 deletions(-) rename packages/mermaid/src/diagrams/flowchart/elk/{diagram-definition.ts => flowchart-elk-definition.ts} (100%) rename packages/mermaid/src/diagrams/mindmap/{diagram-definition.ts => mindmap-definition.ts} (100%) rename packages/mermaid/src/diagrams/timeline/{diagram-definition.ts => timeline-definition.ts} (100%) diff --git a/packages/mermaid/src/diagrams/flowchart/elk/detector.ts b/packages/mermaid/src/diagrams/flowchart/elk/detector.ts index 41760ff4d..c6fa77957 100644 --- a/packages/mermaid/src/diagrams/flowchart/elk/detector.ts +++ b/packages/mermaid/src/diagrams/flowchart/elk/detector.ts @@ -16,7 +16,7 @@ const detector: DiagramDetector = (txt: string, config?: MermaidConfig): boolean }; const loader = async () => { - const { diagram } = await import('./diagram-definition.js'); + const { diagram } = await import('./flowchart-elk-definition.js'); return { id, diagram }; }; diff --git a/packages/mermaid/src/diagrams/flowchart/elk/diagram-definition.ts b/packages/mermaid/src/diagrams/flowchart/elk/flowchart-elk-definition.ts similarity index 100% rename from packages/mermaid/src/diagrams/flowchart/elk/diagram-definition.ts rename to packages/mermaid/src/diagrams/flowchart/elk/flowchart-elk-definition.ts diff --git a/packages/mermaid/src/diagrams/mindmap/detector.ts b/packages/mermaid/src/diagrams/mindmap/detector.ts index c96b19097..2e2b1c7d6 100644 --- a/packages/mermaid/src/diagrams/mindmap/detector.ts +++ b/packages/mermaid/src/diagrams/mindmap/detector.ts @@ -6,7 +6,7 @@ const detector = (txt: string) => { }; const loader = async () => { - const { diagram } = await import('./diagram-definition.js'); + const { diagram } = await import('./mindmap-definition.js'); return { id, diagram }; }; diff --git a/packages/mermaid/src/diagrams/mindmap/diagram-definition.ts b/packages/mermaid/src/diagrams/mindmap/mindmap-definition.ts similarity index 100% rename from packages/mermaid/src/diagrams/mindmap/diagram-definition.ts rename to packages/mermaid/src/diagrams/mindmap/mindmap-definition.ts diff --git a/packages/mermaid/src/diagrams/timeline/detector.ts b/packages/mermaid/src/diagrams/timeline/detector.ts index faa86a72c..9bd2b5ece 100644 --- a/packages/mermaid/src/diagrams/timeline/detector.ts +++ b/packages/mermaid/src/diagrams/timeline/detector.ts @@ -7,7 +7,7 @@ const detector = (txt: string) => { }; const loader = async () => { - const { diagram } = await import('./diagram-definition.js'); + const { diagram } = await import('./timeline-definition.js'); return { id, diagram }; }; diff --git a/packages/mermaid/src/diagrams/timeline/diagram-definition.ts b/packages/mermaid/src/diagrams/timeline/timeline-definition.ts similarity index 100% rename from packages/mermaid/src/diagrams/timeline/diagram-definition.ts rename to packages/mermaid/src/diagrams/timeline/timeline-definition.ts From 4ea7294eeb2aa71a48c984562750958dd92900de Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Sun, 19 Feb 2023 16:10:08 +0530 Subject: [PATCH 41/67] fix(#3406, #3394): Remove init & initThrowsErrors New run function added as replacement. --- V10-BreakingChanges.md | 35 ++- .../external-diagrams-example-diagram.html | 2 +- cypress/platform/render-after-error.html | 3 +- cypress/platform/rerender.html | 2 +- .../interfaces/mermaidAPI.ParseOptions.md | 19 ++ .../interfaces/mermaidAPI.RenderResult.md | 4 +- docs/config/setup/modules/mermaidAPI.md | 25 +-- packages/mermaid/src/mermaid.spec.ts | 28 ++- packages/mermaid/src/mermaid.ts | 202 ++++++++++-------- packages/mermaid/src/mermaidAPI.spec.ts | 4 +- packages/mermaid/src/mermaidAPI.ts | 17 +- 11 files changed, 215 insertions(+), 126 deletions(-) create mode 100644 docs/config/setup/interfaces/mermaidAPI.ParseOptions.md diff --git a/V10-BreakingChanges.md b/V10-BreakingChanges.md index e3322a3a1..121fdd596 100644 --- a/V10-BreakingChanges.md +++ b/V10-BreakingChanges.md @@ -2,7 +2,7 @@ ## Async -`init`, `parse`, `render` are now async. +`parse`, `render` are now async. ## Lazy loading and asynchronisity @@ -23,3 +23,36 @@ try { parseError(err); } ``` + +## Init deprecated and InitThrowsErrors removed + +The config passed to `init` was not being used eariler. +It will now be used. +The `init` function is deprecated and will be removed in the next major release. +init currently works as a wrapper to `initialize` and `run`. + +```js +//< v10.0.0 +mermaid.init(config, selector, cb); + +//>= v10.0.0 +mermaid.initialize(config); +mermaid.run({ + querySelector: selector, + postRenderCallback: cb, + suppressErrors: true, +}); +``` + +```js +//< v10.0.0 +mermaid.initThrowsErrors(config, selector, cb); + +//>= v10.0.0 +mermaid.initialize(config); +mermaid.run({ + querySelector: selector, + postRenderCallback: cb, + suppressErrors: false, +}); +``` diff --git a/cypress/platform/external-diagrams-example-diagram.html b/cypress/platform/external-diagrams-example-diagram.html index a1339d4e6..b5b716ff8 100644 --- a/cypress/platform/external-diagrams-example-diagram.html +++ b/cypress/platform/external-diagrams-example-diagram.html @@ -17,7 +17,7 @@ example-diagram await mermaid.registerExternalDiagrams([exampleDiagram]); await mermaid.initialize({ logLevel: 0 }); - await mermaid.initThrowsErrors(); + await mermaid.run(); if (window.Cypress) { window.rendered = true; } diff --git a/cypress/platform/render-after-error.html b/cypress/platform/render-after-error.html index 72ccac34c..2334158c2 100644 --- a/cypress/platform/render-after-error.html +++ b/cypress/platform/render-after-error.html @@ -11,7 +11,8 @@