diff --git a/.vite/build.ts b/.vite/build.ts index 268db3270..183158288 100644 --- a/.vite/build.ts +++ b/.vite/build.ts @@ -3,6 +3,7 @@ import { resolve } from 'path'; import { fileURLToPath } from 'url'; import jisonPlugin from './jisonPlugin.js'; import { readFileSync } from 'fs'; +import typescript from '@rollup/plugin-typescript'; import { visualizer } from 'rollup-plugin-visualizer'; import type { TemplateType } from 'rollup-plugin-visualizer/dist/plugin/template-types.js'; @@ -102,9 +103,14 @@ export const getBuildConfig = ({ minify, core, watch, entryName }: BuildOptions) }, }, resolve: { - extensions: ['.jison', '.js', '.ts', '.json'], + extensions: [], }, - plugins: [jisonPlugin(), ...visualizerOptions(packageName, core)], + plugins: [ + jisonPlugin(), + // @ts-expect-error According to the type definitions, rollup plugins are incompatible with vite + typescript({ compilerOptions: { declaration: false } }), + ...visualizerOptions(packageName, core), + ], }; if (watch && config.build) { diff --git a/README.md b/README.md index d42e2f7e1..31c6d62c6 100644 --- a/README.md +++ b/README.md @@ -226,6 +226,44 @@ pie ### Git graph [experimental - live editor] +### Bar chart (using gantt chart) [docs - live editor] + +``` +gantt + title Git Issues - days since last update + dateFormat X + axisFormat %s + + section Issue19062 + 71 : 0, 71 + section Issue19401 + 36 : 0, 36 + section Issue193 + 34 : 0, 34 + section Issue7441 + 9 : 0, 9 + section Issue1300 + 5 : 0, 5 +``` + +```mermaid +gantt + title Git Issues - days since last update + dateFormat X + axisFormat %s + + section Issue19062 + 71 : 0, 71 + section Issue19401 + 36 : 0, 36 + section Issue193 + 34 : 0, 34 + section Issue7441 + 9 : 0, 9 + section Issue1300 + 5 : 0, 5 +``` + ### User Journey diagram [docs - live editor] ``` diff --git a/__mocks__/d3.ts b/__mocks__/d3.ts index af35020c5..b472a3181 100644 --- a/__mocks__/d3.ts +++ b/__mocks__/d3.ts @@ -1,5 +1,5 @@ // @ts-nocheck TODO: Fix TS -import { MockedD3 } from '../packages/mermaid/src/tests/MockedD3'; +import { MockedD3 } from '../packages/mermaid/src/tests/MockedD3.js'; export const select = function () { return new MockedD3(); diff --git a/cSpell.json b/cSpell.json index d860c5e33..94276b683 100644 --- a/cSpell.json +++ b/cSpell.json @@ -47,6 +47,7 @@ "graphviz", "grav", "greywolf", + "huynh", "inkdrop", "jaoude", "jison", @@ -90,6 +91,7 @@ "sidharthv", "sphinxcontrib", "statediagram", + "steph", "stylis", "substate", "sveidqvist", diff --git a/cypress/integration/other/configuration.spec.js b/cypress/integration/other/configuration.spec.js index 513cf0714..6df7edd84 100644 --- a/cypress/integration/other/configuration.spec.js +++ b/cypress/integration/other/configuration.spec.js @@ -1,4 +1,4 @@ -import { renderGraph } from '../../helpers/util'; +import { renderGraph } from '../../helpers/util.js'; describe('Configuration', () => { describe('arrowMarkerAbsolute', () => { it('should handle default value false of arrowMarkerAbsolute', () => { diff --git a/cypress/integration/other/external-diagrams.spec.js b/cypress/integration/other/external-diagrams.spec.js index c94235162..4ade11e81 100644 --- a/cypress/integration/other/external-diagrams.spec.js +++ b/cypress/integration/other/external-diagrams.spec.js @@ -1,4 +1,4 @@ -import { urlSnapshotTest } from '../../helpers/util'; +import { urlSnapshotTest } from '../../helpers/util.js'; describe('mermaid', () => { describe('registerDiagram', () => { diff --git a/cypress/integration/other/ghsa.spec.js b/cypress/integration/other/ghsa.spec.js index 4fadc7855..8f28d9f53 100644 --- a/cypress/integration/other/ghsa.spec.js +++ b/cypress/integration/other/ghsa.spec.js @@ -1,4 +1,4 @@ -import { urlSnapshotTest } from '../../helpers/util'; +import { urlSnapshotTest } from '../../helpers/util.js'; describe('CSS injections', () => { it('should not allow CSS injections outside of the diagram', () => { diff --git a/cypress/integration/rendering/classDiagram-v2.spec.js b/cypress/integration/rendering/classDiagram-v2.spec.js index 71810cfa4..a11571814 100644 --- a/cypress/integration/rendering/classDiagram-v2.spec.js +++ b/cypress/integration/rendering/classDiagram-v2.spec.js @@ -1,4 +1,4 @@ -import { imgSnapshotTest } from '../../helpers/util'; +import { imgSnapshotTest } from '../../helpers/util.js'; describe('Class diagram V2', () => { it('0: should render a simple class diagram', () => { imgSnapshotTest( diff --git a/cypress/integration/rendering/classDiagram.spec.js b/cypress/integration/rendering/classDiagram.spec.js index e21be67ec..cda455f0e 100644 --- a/cypress/integration/rendering/classDiagram.spec.js +++ b/cypress/integration/rendering/classDiagram.spec.js @@ -1,4 +1,4 @@ -import { imgSnapshotTest, renderGraph } from '../../helpers/util'; +import { imgSnapshotTest, renderGraph } from '../../helpers/util.js'; describe('Class diagram', () => { it('1: should render a simple class diagram', () => { diff --git a/cypress/integration/rendering/current.spec.js b/cypress/integration/rendering/current.spec.js index 033752c66..e0b36d53a 100644 --- a/cypress/integration/rendering/current.spec.js +++ b/cypress/integration/rendering/current.spec.js @@ -1,4 +1,4 @@ -import { imgSnapshotTest } from '../../helpers/util'; +import { imgSnapshotTest } from '../../helpers/util.js'; describe('Current diagram', () => { it('should render a state with states in it', () => { diff --git a/cypress/integration/rendering/debug.spec.js b/cypress/integration/rendering/debug.spec.js index 673cadf3e..afde4af3e 100644 --- a/cypress/integration/rendering/debug.spec.js +++ b/cypress/integration/rendering/debug.spec.js @@ -1,4 +1,4 @@ -import { imgSnapshotTest } from '../../helpers/util'; +import { imgSnapshotTest } from '../../helpers/util.js'; describe('Flowchart', () => { it('34: testing the label width in percy', () => { diff --git a/cypress/integration/rendering/erDiagram.spec.js b/cypress/integration/rendering/erDiagram.spec.js index faa511626..0c6eaa838 100644 --- a/cypress/integration/rendering/erDiagram.spec.js +++ b/cypress/integration/rendering/erDiagram.spec.js @@ -1,4 +1,4 @@ -import { imgSnapshotTest, renderGraph } from '../../helpers/util'; +import { imgSnapshotTest, renderGraph } from '../../helpers/util.js'; describe('Entity Relationship Diagram', () => { it('should render a simple ER diagram', () => { diff --git a/cypress/integration/rendering/flowchart-elk.spec.js b/cypress/integration/rendering/flowchart-elk.spec.js index 68d8b3ce5..d0ef42c5d 100644 --- a/cypress/integration/rendering/flowchart-elk.spec.js +++ b/cypress/integration/rendering/flowchart-elk.spec.js @@ -1,4 +1,4 @@ -import { imgSnapshotTest, renderGraph } from '../../helpers/util'; +import { imgSnapshotTest, renderGraph } from '../../helpers/util.js'; describe.skip('Flowchart ELK', () => { it('1-elk: should render a simple flowchart', () => { diff --git a/cypress/integration/rendering/flowchart-v2.spec.js b/cypress/integration/rendering/flowchart-v2.spec.js index 4513cc87d..eaa14ed50 100644 --- a/cypress/integration/rendering/flowchart-v2.spec.js +++ b/cypress/integration/rendering/flowchart-v2.spec.js @@ -1,4 +1,4 @@ -import { imgSnapshotTest, renderGraph } from '../../helpers/util'; +import { imgSnapshotTest, renderGraph } from '../../helpers/util.js'; describe('Flowchart v2', () => { it('1: should render a simple flowchart', () => { @@ -685,6 +685,16 @@ A ~~~ B { titleTopMargin: 0 } ); }); + it('4023: Should render html labels with images and-or text correctly', () => { + imgSnapshotTest( + `flowchart TD + B[] + B-->C[ more text ] + B-->D( some text) + B-->E(plain)`, + {} + ); + }); describe('Markdown strings flowchart (#4220)', () => { describe('html labels', () => { it('With styling and classes', () => { diff --git a/cypress/integration/rendering/flowchart.spec.js b/cypress/integration/rendering/flowchart.spec.js index c4ef54fcf..d25043d28 100644 --- a/cypress/integration/rendering/flowchart.spec.js +++ b/cypress/integration/rendering/flowchart.spec.js @@ -1,4 +1,4 @@ -import { imgSnapshotTest, renderGraph } from '../../helpers/util'; +import { imgSnapshotTest, renderGraph } from '../../helpers/util.js'; describe('Graph', () => { it('1: should render a simple flowchart no htmlLabels', () => { diff --git a/cypress/integration/rendering/sequencediagram.spec.js b/cypress/integration/rendering/sequencediagram.spec.js index f8948240a..687fc245b 100644 --- a/cypress/integration/rendering/sequencediagram.spec.js +++ b/cypress/integration/rendering/sequencediagram.spec.js @@ -1,6 +1,6 @@ /// -import { imgSnapshotTest, renderGraph } from '../../helpers/util'; +import { imgSnapshotTest, renderGraph } from '../../helpers/util.js'; context('Sequence diagram', () => { it('should render a sequence diagram with boxes', () => { diff --git a/cypress/integration/rendering/stateDiagram-v2.spec.js b/cypress/integration/rendering/stateDiagram-v2.spec.js index 047e240fc..700791621 100644 --- a/cypress/integration/rendering/stateDiagram-v2.spec.js +++ b/cypress/integration/rendering/stateDiagram-v2.spec.js @@ -1,4 +1,4 @@ -import { imgSnapshotTest, renderGraph } from '../../helpers/util'; +import { imgSnapshotTest, renderGraph } from '../../helpers/util.js'; describe('State diagram', () => { it('v2 should render a simple info', () => { @@ -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/cypress/integration/rendering/stateDiagram.spec.js b/cypress/integration/rendering/stateDiagram.spec.js index cdcc48a07..28c24d398 100644 --- a/cypress/integration/rendering/stateDiagram.spec.js +++ b/cypress/integration/rendering/stateDiagram.spec.js @@ -1,4 +1,4 @@ -import { imgSnapshotTest, renderGraph } from '../../helpers/util'; +import { imgSnapshotTest, renderGraph } from '../../helpers/util.js'; describe('State diagram', () => { it('should render a simple state diagrams', () => { diff --git a/cypress/platform/ashish2.html b/cypress/platform/ashish2.html index bcea4f4cc..76fbd36f7 100644 --- a/cypress/platform/ashish2.html +++ b/cypress/platform/ashish2.html @@ -188,7 +188,7 @@ mindmap //import mindmap from '../../packages/mermaid-mindmap/src/detector'; // import example from '../../packages/mermaid-example-diagram/src/detector'; // import timeline from '../../packages/mermaid-timeline/src/detector'; - import mermaid from '../../packages/mermaid/src/mermaid'; + import mermaid from './mermaid.esm.mjs'; // await mermaid.registerExternalDiagrams([]); mermaid.parseError = function (err, hash) { // console.error('Mermaid error: ', err); diff --git a/cypress/platform/bundle-test.js b/cypress/platform/bundle-test.js index edd3dfbc4..f5bf0ecd6 100644 --- a/cypress/platform/bundle-test.js +++ b/cypress/platform/bundle-test.js @@ -1,4 +1,5 @@ -import mermaid from '../../packages/mermaid/src/mermaid'; +// TODO: this file should be testing the ./mermaid.core.mjs file, as that's the file listed in the package.json file that users will use +import mermaid from './mermaid.esm.mjs'; let code = `flowchart LR Power_Supply --> Transmitter_A diff --git a/cypress/platform/external-diagrams-example-diagram.html b/cypress/platform/external-diagrams-example-diagram.html index b5b716ff8..495b7e59d 100644 --- a/cypress/platform/external-diagrams-example-diagram.html +++ b/cypress/platform/external-diagrams-example-diagram.html @@ -11,9 +11,9 @@ example-diagram ``` -**Doing so will command the mermaid parser to look for the `
` or `
` tags with `class="mermaid"`. From these tags mermaid will try to read the diagram/chart definitions and render them into SVG charts.**
+**Doing so commands the mermaid parser to look for the `
` or `
` tags with `class="mermaid"`. From these tags, mermaid tries read the diagram/chart definitions and render them into SVG charts.**
 
-**Examples can be found at** [Other examples](../syntax/examples.md)
+**Examples can be found in** [Other examples](../syntax/examples.md)
 
 ## Sibling projects
 
diff --git a/docs/news/announcements.md b/docs/news/announcements.md
new file mode 100644
index 000000000..112bde52c
--- /dev/null
+++ b/docs/news/announcements.md
@@ -0,0 +1,13 @@
+> **Warning**
+>
+> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
+>
+> ## Please edit the corresponding file in [/packages/mermaid/src/docs/news/announcements.md](../../packages/mermaid/src/docs/news/announcements.md).
+
+# Announcements
+
+## [Automatic text wrapping in flowcharts is here!](https://www.mermaidchart.com/blog/posts/automatic-text-wrapping-in-flowcharts-is-here)
+
+3 April 2023 · 3 mins
+
+Markdown Strings reduce the hassle # Starting from v10.
diff --git a/docs/news/blog.md b/docs/news/blog.md
new file mode 100644
index 000000000..dc6f3f635
--- /dev/null
+++ b/docs/news/blog.md
@@ -0,0 +1,31 @@
+> **Warning**
+>
+> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
+>
+> ## Please edit the corresponding file in [/packages/mermaid/src/docs/news/blog.md](../../packages/mermaid/src/docs/news/blog.md).
+
+# Blog
+
+## [Mermaid Chart officially launched with sharable diagram links and presentation mode](https://www.mermaidchart.com/blog/posts/mermaid-chart-officially-launched-with-sharable-diagram-links-and-presentation-mode/)
+
+27 March 2023 · 2 mins
+
+Exciting news for all Mermaid OSS fans: Mermaid Chart has officially launched with Mermaid Chart!
+
+## [If you're not excited about ChatGPT, then you're not being creative](https://www.mermaidchart.com/blog/posts/if-youre-not-excited-about-chatgpt-then-youre-not-being-creative-enough/)
+
+8 March 2023 · 9 mins
+
+The hype around AI in general and ChatGPT, in particular, is so intense that it’s very understandable to assume the hype train is driving straight toward the trough of disillusionment.
+
+## [Flow charts are O(n)2 complex, so don't go over 100 connections](https://www.mermaidchart.com/blog/posts/flow-charts-are-on2-complex-so-dont-go-over-100-connections/)
+
+1 March 2023 · 12 mins
+
+Flowchart design is a game of balance: Read about the importance of dialling in the right level of detail and how to manage complexity in large flowcharts.
+
+## [Busting the myth that developers can't write](https://www.mermaidchart.com/blog/posts/busting-the-myth-that-developers-cant-write/)
+
+10 February 2023 · 10 mins
+
+Busting the myth that developers can’t write # It’s an annoying stereotype that developers don’t know how to write, speak, and otherwise communicate.
diff --git a/docs/public/favicon.ico b/docs/public/favicon.ico
index d41818c5b..05d8a737b 100644
Binary files a/docs/public/favicon.ico and b/docs/public/favicon.ico differ
diff --git a/docs/syntax/flowchart.md b/docs/syntax/flowchart.md
index c79f12b23..6f5b973e8 100644
--- a/docs/syntax/flowchart.md
+++ b/docs/syntax/flowchart.md
@@ -710,6 +710,44 @@ flowchart LR
   B1 --> B2
 ```
 
+## Markdown Strings
+
+The "Markdown Strings" feature enhances flowcharts and mind maps by offering a more versatile string type, which supports text formatting options such as bold and italics, and automatically wraps text within labels.
+
+```mermaid-example
+%%{init: {"flowchart": {"htmlLabels": false}} }%%
+flowchart LR
+subgraph "One"
+  a("`The **cat**
+  in the hat`") -- "edge label" --> b{{"`The **dog** in the hog`"}}
+end
+subgraph "`**Two**`"
+  c("`The **cat**
+  in the hat`") -- "`Bold **edge label**`" --> d("The dog in the hog")
+end
+```
+
+```mermaid
+%%{init: {"flowchart": {"htmlLabels": false}} }%%
+flowchart LR
+subgraph "One"
+  a("`The **cat**
+  in the hat`") -- "edge label" --> b{{"`The **dog** in the hog`"}}
+end
+subgraph "`**Two**`"
+  c("`The **cat**
+  in the hat`") -- "`Bold **edge label**`" --> d("The dog in the hog")
+end
+```
+
+Formatting:
+
+- For bold text, use double asterisks \*\* before and after the text.
+- For italics, use single asterisks \* before and after the text.
+- With traditional strings, you needed to add 
tags for text to wrap in nodes. However, markdown strings automatically wrap text when it becomes too long and allows you to start a new line by simply using a newline character instead of a
tag. + +This feature is applicable to node labels, edge labels, and subgraph labels. + ## Interaction It is possible to bind a click event to a node, the click can lead to either a javascript callback or to a link which will be opened in a new browser tab. **Note**: This functionality is disabled when using `securityLevel='strict'` and enabled when using `securityLevel='loose'`. diff --git a/docs/syntax/gantt.md b/docs/syntax/gantt.md index 1b12063d7..091cdeabe 100644 --- a/docs/syntax/gantt.md +++ b/docs/syntax/gantt.md @@ -464,3 +464,41 @@ Beginner's tip—a full example using interactive links in an html context: ``` + +## Examples + +### Bar chart (using gantt chart) + +```mermaid-example +gantt + title Git Issues - days since last update + dateFormat X + axisFormat %s + section Issue19062 + 71 : 0, 71 + section Issue19401 + 36 : 0, 36 + section Issue193 + 34 : 0, 34 + section Issue7441 + 9 : 0, 9 + section Issue1300 + 5 : 0, 5 +``` + +```mermaid +gantt + title Git Issues - days since last update + dateFormat X + axisFormat %s + section Issue19062 + 71 : 0, 71 + section Issue19401 + 36 : 0, 36 + section Issue193 + 34 : 0, 34 + section Issue7441 + 9 : 0, 9 + section Issue1300 + 5 : 0, 5 +``` diff --git a/docs/syntax/mindmap.md b/docs/syntax/mindmap.md index babe47756..9687bbef7 100644 --- a/docs/syntax/mindmap.md +++ b/docs/syntax/mindmap.md @@ -254,6 +254,34 @@ Root C ``` +## Markdown Strings + +The "Markdown Strings" feature enhances mind maps by offering a more versatile string type, which supports text formatting options such as bold and italics, and automatically wraps text within labels. + +```mermaid-example +mindmap + id1["`**Root** with +a second line +Unicode works too: 🤓`"] + id2["`The dog in **the** hog... a *very long text* that wraps to a new line`"] + id3[Regular labels still works] +``` + +```mermaid +mindmap + id1["`**Root** with +a second line +Unicode works too: 🤓`"] + id2["`The dog in **the** hog... a *very long text* that wraps to a new line`"] + id3[Regular labels still works] +``` + +Formatting: + +- For bold text, use double asterisks \*\* before and after the text. +- For italics, use single asterisks \* before and after the text. +- With traditional strings, you needed to add
tags for text to wrap in nodes. However, markdown strings automatically wrap text when it becomes too long and allows you to start a new line by simply using a newline character instead of a
tag. + ## Integrating with your library/website. Mindmap uses the experimental lazy loading & async rendering features which could change in the future. From version 9.4.0 this diagram is included in mermaid but use lazy loading in order to keep the size of mermaid down. This is important in order to be able to add additional diagrams going forward. diff --git a/package.json b/package.json index ca642e890..0485d6f6e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "mermaid-monorepo", "private": true, - "version": "10.0.2", + "version": "10.1.0", "description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.", "type": "module", "packageManager": "pnpm@7.30.1", @@ -58,6 +58,7 @@ "@commitlint/cli": "^17.2.0", "@commitlint/config-conventional": "^17.2.0", "@cspell/eslint-plugin": "^6.14.2", + "@rollup/plugin-typescript": "^11.0.0", "@types/cors": "^2.8.13", "@types/eslint": "^8.4.10", "@types/express": "^4.17.17", diff --git a/packages/mermaid-example-diagram/src/diagram-definition.ts b/packages/mermaid-example-diagram/src/diagram-definition.ts index c31b3d6e7..f29c8ee7f 100644 --- a/packages/mermaid-example-diagram/src/diagram-definition.ts +++ b/packages/mermaid-example-diagram/src/diagram-definition.ts @@ -1,9 +1,9 @@ // @ts-ignore: TODO Fix ts errors -import parser from './parser/exampleDiagram'; -import * as db from './exampleDiagramDb'; -import renderer from './exampleDiagramRenderer'; -import styles from './styles'; -import { injectUtils } from './mermaidUtils'; +import parser from './parser/exampleDiagram.jison'; +import * as db from './exampleDiagramDb.js'; +import renderer from './exampleDiagramRenderer.js'; +import styles from './styles.js'; +import { injectUtils } from './mermaidUtils.js'; export const diagram = { db, diff --git a/packages/mermaid-example-diagram/src/exampleDiagram.spec.js b/packages/mermaid-example-diagram/src/exampleDiagram.spec.js index 96c8cd5b2..9cfe33a1b 100644 --- a/packages/mermaid-example-diagram/src/exampleDiagram.spec.js +++ b/packages/mermaid-example-diagram/src/exampleDiagram.spec.js @@ -1,6 +1,6 @@ -import { parser } from './parser/exampleDiagram'; -import * as db from './exampleDiagramDb'; -import { injectUtils } from './mermaidUtils'; +import { parser } from './parser/exampleDiagram.jison'; +import * as db from './exampleDiagramDb.js'; +import { injectUtils } from './mermaidUtils.js'; // Todo fix utils functions for tests import { log, @@ -8,7 +8,7 @@ import { getConfig, sanitizeText, setupGraphViewBox, -} from '../../mermaid/src/diagram-api/diagramAPI'; +} from '../../mermaid/src/diagram-api/diagramAPI.js'; injectUtils(log, setLogLevel, getConfig, sanitizeText, setupGraphViewBox); diff --git a/packages/mermaid-example-diagram/src/exampleDiagramDb.js b/packages/mermaid-example-diagram/src/exampleDiagramDb.js index 8429ec5d6..a5fa88e6d 100644 --- a/packages/mermaid-example-diagram/src/exampleDiagramDb.js +++ b/packages/mermaid-example-diagram/src/exampleDiagramDb.js @@ -1,5 +1,5 @@ /** Created by knut on 15-01-14. */ -import { log } from './mermaidUtils'; +import { log } from './mermaidUtils.js'; var message = ''; var info = false; diff --git a/packages/mermaid-example-diagram/src/exampleDiagramRenderer.js b/packages/mermaid-example-diagram/src/exampleDiagramRenderer.js index 0d7340677..2c6839203 100644 --- a/packages/mermaid-example-diagram/src/exampleDiagramRenderer.js +++ b/packages/mermaid-example-diagram/src/exampleDiagramRenderer.js @@ -1,6 +1,6 @@ /** Created by knut on 14-12-11. */ import { select } from 'd3'; -import { log, getConfig, setupGraphViewbox } from './mermaidUtils'; +import { log, getConfig, setupGraphViewbox } from './mermaidUtils.js'; /** * Draws a an info picture in the tag with id: id based on the graph definition in text. diff --git a/packages/mermaid-example-diagram/tsconfig.json b/packages/mermaid-example-diagram/tsconfig.json index 310137cc0..45076b7b5 100644 --- a/packages/mermaid-example-diagram/tsconfig.json +++ b/packages/mermaid-example-diagram/tsconfig.json @@ -1,6 +1,5 @@ { "extends": "../../tsconfig.json", - "module": "esnext", "compilerOptions": { "rootDir": "./src", "outDir": "./dist" diff --git a/packages/mermaid/package.json b/packages/mermaid/package.json index 82a641719..12da8c2ff 100644 --- a/packages/mermaid/package.json +++ b/packages/mermaid/package.json @@ -1,6 +1,6 @@ { "name": "mermaid", - "version": "10.0.2", + "version": "10.1.0", "description": "Markdown-ish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.", "type": "module", "module": "./dist/mermaid.core.mjs", @@ -87,6 +87,7 @@ "coveralls": "^3.1.1", "cpy-cli": "^4.2.0", "cspell": "^6.14.3", + "csstree-validator": "^3.0.0", "globby": "^13.1.2", "jison": "^0.4.18", "js-base64": "^3.7.2", diff --git a/packages/mermaid/src/Diagram.ts b/packages/mermaid/src/Diagram.ts index adb596734..4fb329b28 100644 --- a/packages/mermaid/src/Diagram.ts +++ b/packages/mermaid/src/Diagram.ts @@ -1,11 +1,11 @@ -import * as configApi from './config'; -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 { UnknownDiagramError } from './errors'; -import { DetailedError } from './utils'; -import { cleanupComments } from './diagram-api/comments'; +import * as configApi from './config.js'; +import { log } from './logger.js'; +import { getDiagram, registerDiagram } from './diagram-api/diagramAPI.js'; +import { detectType, getDiagramLoader } from './diagram-api/detectType.js'; +import { extractFrontMatter } from './diagram-api/frontmatter.js'; +import { UnknownDiagramError } from './errors.js'; +import { DetailedError } from './utils.js'; +import { cleanupComments } from './diagram-api/comments.js'; export type ParseErrorFunction = (err: string | DetailedError | unknown, hash?: any) => void; diff --git a/packages/mermaid/src/__mocks__/mermaidAPI.ts b/packages/mermaid/src/__mocks__/mermaidAPI.ts index 95b87d990..a2d19ef24 100644 --- a/packages/mermaid/src/__mocks__/mermaidAPI.ts +++ b/packages/mermaid/src/__mocks__/mermaidAPI.ts @@ -3,9 +3,9 @@ * * We can't easily use `vi.spyOn(mermaidAPI, "function")` since the object is frozen with `Object.freeze()`. */ -import * as configApi from '../config'; +import * as configApi from '../config.js'; import { vi } from 'vitest'; -import { mermaidAPI as mAPI } from '../mermaidAPI'; +import { mermaidAPI as mAPI } from '../mermaidAPI.js'; // original version cannot be modified since it was frozen with `Object.freeze()` export const mermaidAPI = { diff --git a/packages/mermaid/src/accessibility.spec.ts b/packages/mermaid/src/accessibility.spec.ts index 60415ea37..eac82ee34 100644 --- a/packages/mermaid/src/accessibility.spec.ts +++ b/packages/mermaid/src/accessibility.spec.ts @@ -1,6 +1,6 @@ -import { MockedD3 } from './tests/MockedD3'; -import { setA11yDiagramInfo, addSVGa11yTitleDescription } from './accessibility'; -import { D3Element } from './mermaidAPI'; +import { MockedD3 } from './tests/MockedD3.js'; +import { setA11yDiagramInfo, addSVGa11yTitleDescription } from './accessibility.js'; +import { D3Element } from './mermaidAPI.js'; describe('accessibility', () => { const fauxSvgNode = new MockedD3(); diff --git a/packages/mermaid/src/accessibility.ts b/packages/mermaid/src/accessibility.ts index 8e073aa76..eba3ba9a7 100644 --- a/packages/mermaid/src/accessibility.ts +++ b/packages/mermaid/src/accessibility.ts @@ -5,7 +5,7 @@ * @see https://www.w3.org/TR/svg-aam-1.0/ * */ -import { D3Element } from './mermaidAPI'; +import { D3Element } from './mermaidAPI.js'; import isEmpty from 'lodash-es/isEmpty.js'; diff --git a/packages/mermaid/src/commonDb.ts b/packages/mermaid/src/commonDb.ts index a9ad0f54b..4e1e5141a 100644 --- a/packages/mermaid/src/commonDb.ts +++ b/packages/mermaid/src/commonDb.ts @@ -1,5 +1,5 @@ -import { sanitizeText as _sanitizeText } from './diagrams/common/common'; -import { getConfig } from './config'; +import { sanitizeText as _sanitizeText } from './diagrams/common/common.js'; +import { getConfig } from './config.js'; let title = ''; let diagramTitle = ''; let description = ''; diff --git a/packages/mermaid/src/config.spec.js b/packages/mermaid/src/config.spec.js index b104f37cc..1f7fd976b 100644 --- a/packages/mermaid/src/config.spec.js +++ b/packages/mermaid/src/config.spec.js @@ -1,4 +1,4 @@ -import * as configApi from './config'; +import * as configApi from './config.js'; describe('when working with site config', function () { beforeEach(() => { diff --git a/packages/mermaid/src/config.ts b/packages/mermaid/src/config.ts index bc0066cec..838716e2f 100644 --- a/packages/mermaid/src/config.ts +++ b/packages/mermaid/src/config.ts @@ -1,8 +1,8 @@ -import assignWithDepth from './assignWithDepth'; -import { log } from './logger'; -import theme from './themes'; -import config from './defaultConfig'; -import type { MermaidConfig } from './config.type'; +import assignWithDepth from './assignWithDepth.js'; +import { log } from './logger.js'; +import theme from './themes/index.js'; +import config from './defaultConfig.js'; +import type { MermaidConfig } from './config.type.js'; export const defaultConfig: MermaidConfig = Object.freeze(config); diff --git a/packages/mermaid/src/dagre-wrapper/clusters.js b/packages/mermaid/src/dagre-wrapper/clusters.js index 453fcb8f5..1ce716689 100644 --- a/packages/mermaid/src/dagre-wrapper/clusters.js +++ b/packages/mermaid/src/dagre-wrapper/clusters.js @@ -1,10 +1,10 @@ -import intersectRect from './intersect/intersect-rect'; -import { log } from '../logger'; -import createLabel from './createLabel'; -import { createText } from '../rendering-util/createText'; +import intersectRect from './intersect/intersect-rect.js'; +import { log } from '../logger.js'; +import createLabel from './createLabel.js'; +import { createText } from '../rendering-util/createText.js'; import { select } from 'd3'; -import { getConfig } from '../config'; -import { evaluate } from '../diagrams/common/common'; +import { getConfig } from '../config.js'; +import { evaluate } from '../diagrams/common/common.js'; const rect = (parent, node) => { log.info('Creating subgraph rect for ', node.id, node); @@ -63,13 +63,20 @@ const rect = (parent, node) => { .attr('width', width) .attr('height', node.height + padding); + if (useHtmlLabels) { + label.attr( + 'transform', + // This puts the labal on top of the box instead of inside it + 'translate(' + (node.x - bbox.width / 2) + ', ' + (node.y - node.height / 2) + ')' + ); + } else { + label.attr( + 'transform', + // This puts the labal on top of the box instead of inside it + 'translate(' + node.x + ', ' + (node.y - node.height / 2) + ')' + ); + } // Center the label - label.attr( - 'transform', - // This puts the labal on top of the box instead of inside it - // 'translate(' + (node.x - bbox.width / 2) + ', ' + (node.y - node.height / 2 - bbox.height) + ')' - 'translate(' + node.x + ', ' + (node.y - node.height / 2) + ')' - ); const rectBox = rect.node().getBBox(); node.width = rectBox.width; diff --git a/packages/mermaid/src/dagre-wrapper/createLabel.js b/packages/mermaid/src/dagre-wrapper/createLabel.js index ff7834c4f..a8351c812 100644 --- a/packages/mermaid/src/dagre-wrapper/createLabel.js +++ b/packages/mermaid/src/dagre-wrapper/createLabel.js @@ -1,8 +1,8 @@ import { select } from 'd3'; -import { log } from '../logger'; -import { getConfig } from '../config'; -import { evaluate } from '../diagrams/common/common'; -import { decodeEntities } from '../mermaidAPI'; +import { log } from '../logger.js'; +import { getConfig } from '../config.js'; +import { evaluate } from '../diagrams/common/common.js'; +import { decodeEntities } from '../mermaidAPI.js'; /** * @param dom diff --git a/packages/mermaid/src/dagre-wrapper/edges.js b/packages/mermaid/src/dagre-wrapper/edges.js index d4b7d37b8..1581658b0 100644 --- a/packages/mermaid/src/dagre-wrapper/edges.js +++ b/packages/mermaid/src/dagre-wrapper/edges.js @@ -1,10 +1,10 @@ -import { log } from '../logger'; -import createLabel from './createLabel'; -import { createText } from '../rendering-util/createText'; +import { log } from '../logger.js'; +import createLabel from './createLabel.js'; +import { createText } from '../rendering-util/createText.js'; import { line, curveBasis, select } from 'd3'; -import { getConfig } from '../config'; -import utils from '../utils'; -import { evaluate } from '../diagrams/common/common'; +import { getConfig } from '../config.js'; +import utils from '../utils.js'; +import { evaluate } from '../diagrams/common/common.js'; let edgeLabels = {}; let terminalLabels = {}; diff --git a/packages/mermaid/src/dagre-wrapper/edges.spec.js b/packages/mermaid/src/dagre-wrapper/edges.spec.js index 627691a8e..9b2772ecd 100644 --- a/packages/mermaid/src/dagre-wrapper/edges.spec.js +++ b/packages/mermaid/src/dagre-wrapper/edges.spec.js @@ -1,5 +1,5 @@ -import { intersection } from './edges'; -import { setLogLevel } from '../logger'; +import { intersection } from './edges.js'; +import { setLogLevel } from '../logger.js'; describe('Graphlib decorations', () => { let node; diff --git a/packages/mermaid/src/dagre-wrapper/index.js b/packages/mermaid/src/dagre-wrapper/index.js index ce3ef6014..590242b02 100644 --- a/packages/mermaid/src/dagre-wrapper/index.js +++ b/packages/mermaid/src/dagre-wrapper/index.js @@ -1,20 +1,20 @@ import { layout as dagreLayout } from 'dagre-d3-es/src/dagre/index.js'; import * as graphlibJson from 'dagre-d3-es/src/graphlib/json.js'; -import insertMarkers from './markers'; -import { updateNodeBounds } from './shapes/util'; +import insertMarkers from './markers.js'; +import { updateNodeBounds } from './shapes/util.js'; import { clear as clearGraphlib, clusterDb, adjustClustersAndEdges, findNonClusterChild, sortNodesByHierarchy, -} from './mermaid-graphlib'; -import { insertNode, positionNode, clear as clearNodes, setNodeElem } from './nodes'; -import { insertCluster, clear as clearClusters } from './clusters'; -import { insertEdgeLabel, positionEdgeLabel, insertEdge, clear as clearEdges } from './edges'; -import { log } from '../logger'; +} from './mermaid-graphlib.js'; +import { insertNode, positionNode, clear as clearNodes, setNodeElem } from './nodes.js'; +import { insertCluster, clear as clearClusters } from './clusters.js'; +import { insertEdgeLabel, positionEdgeLabel, insertEdge, clear as clearEdges } from './edges.js'; +import { log } from '../logger.js'; -const recursiveRender = (_elem, graph, diagramtype, parentCluster) => { +const recursiveRender = async (_elem, graph, diagramtype, parentCluster) => { log.info('Graph in recursive render: XXX', graphlibJson.write(graph), parentCluster); const dir = graph.graph().rankdir; log.trace('Dir in recursive render - dir:', dir); @@ -35,44 +35,46 @@ const recursiveRender = (_elem, graph, diagramtype, parentCluster) => { // Insert nodes, this will insert them into the dom and each node will get a size. The size is updated // to the abstract node and is later used by dagre for the layout - graph.nodes().forEach(function (v) { - const node = graph.node(v); - if (parentCluster !== undefined) { - const data = JSON.parse(JSON.stringify(parentCluster.clusterData)); - // data.clusterPositioning = true; - log.info('Setting data for cluster XXX (', v, ') ', data, parentCluster); - graph.setNode(parentCluster.id, data); - if (!graph.parent(v)) { - log.trace('Setting parent', v, parentCluster.id); - graph.setParent(v, parentCluster.id, data); + await Promise.all( + graph.nodes().map(async function (v) { + const node = graph.node(v); + if (parentCluster !== undefined) { + const data = JSON.parse(JSON.stringify(parentCluster.clusterData)); + // data.clusterPositioning = true; + log.info('Setting data for cluster XXX (', v, ') ', data, parentCluster); + graph.setNode(parentCluster.id, data); + if (!graph.parent(v)) { + log.trace('Setting parent', v, parentCluster.id); + graph.setParent(v, parentCluster.id, data); + } } - } - log.info('(Insert) Node XXX' + v + ': ' + JSON.stringify(graph.node(v))); - if (node && node.clusterNode) { - // const children = graph.children(v); - log.info('Cluster identified', v, node.width, graph.node(v)); - const o = recursiveRender(nodes, node.graph, diagramtype, graph.node(v)); - const newEl = o.elem; - updateNodeBounds(node, newEl); - node.diff = o.diff || 0; - log.info('Node bounds (abc123)', v, node, node.width, node.x, node.y); - setNodeElem(newEl, node); + log.info('(Insert) Node XXX' + v + ': ' + JSON.stringify(graph.node(v))); + if (node && node.clusterNode) { + // const children = graph.children(v); + log.info('Cluster identified', v, node.width, graph.node(v)); + const o = await recursiveRender(nodes, node.graph, diagramtype, graph.node(v)); + const newEl = o.elem; + updateNodeBounds(node, newEl); + node.diff = o.diff || 0; + log.info('Node bounds (abc123)', v, node, node.width, node.x, node.y); + setNodeElem(newEl, node); - log.warn('Recursive render complete ', newEl, node); - } else { - if (graph.children(v).length > 0) { - // This is a cluster but not to be rendered recursively - // Render as before - log.info('Cluster - the non recursive path XXX', v, node.id, node, graph); - log.info(findNonClusterChild(node.id, graph)); - clusterDb[node.id] = { id: findNonClusterChild(node.id, graph), node }; - // insertCluster(clusters, graph.node(v)); + log.warn('Recursive render complete ', newEl, node); } else { - log.info('Node - the non recursive path', v, node.id, node); - insertNode(nodes, graph.node(v), dir); + if (graph.children(v).length > 0) { + // This is a cluster but not to be rendered recursively + // Render as before + log.info('Cluster - the non recursive path XXX', v, node.id, node, graph); + log.info(findNonClusterChild(node.id, graph)); + clusterDb[node.id] = { id: findNonClusterChild(node.id, graph), node }; + // insertCluster(clusters, graph.node(v)); + } else { + log.info('Node - the non recursive path', v, node.id, node); + await insertNode(nodes, graph.node(v), dir); + } } - } - }); + }) + ); // Insert labels, this will insert them into the dom so that the width can be calculated // Also figure out which edges point to/from clusters and adjust them accordingly @@ -146,7 +148,7 @@ const recursiveRender = (_elem, graph, diagramtype, parentCluster) => { return { elem, diff }; }; -export const render = (elem, graph, markers, diagramtype, id) => { +export const render = async (elem, graph, markers, diagramtype, id) => { insertMarkers(elem, markers, diagramtype, id); clearNodes(); clearEdges(); @@ -157,7 +159,7 @@ export const render = (elem, graph, markers, diagramtype, id) => { adjustClustersAndEdges(graph); log.warn('Graph after:', graphlibJson.write(graph)); // log.warn('Graph ever after:', graphlibJson.write(graph.node('A').graph)); - recursiveRender(elem, graph, diagramtype); + await recursiveRender(elem, graph, diagramtype); }; // const shapeDefinitions = {}; diff --git a/packages/mermaid/src/dagre-wrapper/intersect/intersect-circle.js b/packages/mermaid/src/dagre-wrapper/intersect/intersect-circle.js index c4d320426..8f5ba72df 100644 --- a/packages/mermaid/src/dagre-wrapper/intersect/intersect-circle.js +++ b/packages/mermaid/src/dagre-wrapper/intersect/intersect-circle.js @@ -1,4 +1,4 @@ -import intersectEllipse from './intersect-ellipse'; +import intersectEllipse from './intersect-ellipse.js'; /** * @param node diff --git a/packages/mermaid/src/dagre-wrapper/intersect/intersect-polygon.js b/packages/mermaid/src/dagre-wrapper/intersect/intersect-polygon.js index cd124150f..6941372c7 100644 --- a/packages/mermaid/src/dagre-wrapper/intersect/intersect-polygon.js +++ b/packages/mermaid/src/dagre-wrapper/intersect/intersect-polygon.js @@ -1,6 +1,6 @@ /* eslint "no-console": off */ -import intersectLine from './intersect-line'; +import intersectLine from './intersect-line.js'; export default intersectPolygon; diff --git a/packages/mermaid/src/dagre-wrapper/markers.js b/packages/mermaid/src/dagre-wrapper/markers.js index 1a3f74bee..57d092fdf 100644 --- a/packages/mermaid/src/dagre-wrapper/markers.js +++ b/packages/mermaid/src/dagre-wrapper/markers.js @@ -1,6 +1,6 @@ /** Setup arrow head and define the marker. The result is appended to the svg. */ -import { log } from '../logger'; +import { log } from '../logger.js'; // Only add the number of markers that the diagram needs const insertMarkers = (elem, markerArray, type, id) => { @@ -142,7 +142,7 @@ const point = (elem, type) => { .append('marker') .attr('id', type + '-pointEnd') .attr('class', 'marker ' + type) - .attr('viewBox', '0 0 12 20') + .attr('viewBox', '0 0 10 10') .attr('refX', 10) .attr('refY', 5) .attr('markerUnits', 'userSpaceOnUse') diff --git a/packages/mermaid/src/dagre-wrapper/mermaid-graphlib.js b/packages/mermaid/src/dagre-wrapper/mermaid-graphlib.js index 875ac4def..72ef96965 100644 --- a/packages/mermaid/src/dagre-wrapper/mermaid-graphlib.js +++ b/packages/mermaid/src/dagre-wrapper/mermaid-graphlib.js @@ -1,5 +1,5 @@ /** Decorates with functions required by mermaids dagre-wrapper. */ -import { log } from '../logger'; +import { log } from '../logger.js'; import * as graphlibJson from 'dagre-d3-es/src/graphlib/json.js'; import * as graphlib from 'dagre-d3-es/src/graphlib/index.js'; diff --git a/packages/mermaid/src/dagre-wrapper/mermaid-graphlib.spec.js b/packages/mermaid/src/dagre-wrapper/mermaid-graphlib.spec.js index 25fb75d64..1444a82c4 100644 --- a/packages/mermaid/src/dagre-wrapper/mermaid-graphlib.spec.js +++ b/packages/mermaid/src/dagre-wrapper/mermaid-graphlib.spec.js @@ -5,8 +5,8 @@ import { adjustClustersAndEdges, extractDescendants, sortNodesByHierarchy, -} from './mermaid-graphlib'; -import { setLogLevel, log } from '../logger'; +} from './mermaid-graphlib.js'; +import { setLogLevel, log } from '../logger.js'; describe('Graphlib decorations', () => { let g; diff --git a/packages/mermaid/src/dagre-wrapper/nodes.js b/packages/mermaid/src/dagre-wrapper/nodes.js index 3e71f500a..b842fa9a5 100644 --- a/packages/mermaid/src/dagre-wrapper/nodes.js +++ b/packages/mermaid/src/dagre-wrapper/nodes.js @@ -1,15 +1,15 @@ import { select } from 'd3'; -import { log } from '../logger'; -import { labelHelper, updateNodeBounds, insertPolygonShape } from './shapes/util'; -import { getConfig } from '../config'; +import { log } from '../logger.js'; +import { labelHelper, updateNodeBounds, insertPolygonShape } from './shapes/util.js'; +import { getConfig } from '../config.js'; import intersect from './intersect/index.js'; -import createLabel from './createLabel'; -import note from './shapes/note'; -import { parseMember } from '../diagrams/class/svgDraw'; -import { evaluate } from '../diagrams/common/common'; +import createLabel from './createLabel.js'; +import note from './shapes/note.js'; +import { parseMember } from '../diagrams/class/svgDraw.js'; +import { evaluate } from '../diagrams/common/common.js'; -const question = (parent, node) => { - const { shapeSvg, bbox } = labelHelper(parent, node, undefined, true); +const question = async (parent, node) => { + const { shapeSvg, bbox } = await labelHelper(parent, node, undefined, true); const w = bbox.width + node.padding; const h = bbox.height + node.padding; @@ -69,8 +69,8 @@ const choice = (parent, node) => { return shapeSvg; }; -const hexagon = (parent, node) => { - const { shapeSvg, bbox } = labelHelper(parent, node, undefined, true); +const hexagon = async (parent, node) => { + const { shapeSvg, bbox } = await labelHelper(parent, node, undefined, true); const f = 4; const h = bbox.height + node.padding; @@ -96,8 +96,8 @@ const hexagon = (parent, node) => { return shapeSvg; }; -const rect_left_inv_arrow = (parent, node) => { - const { shapeSvg, bbox } = labelHelper(parent, node, undefined, true); +const rect_left_inv_arrow = async (parent, node) => { + const { shapeSvg, bbox } = await labelHelper(parent, node, undefined, true); const w = bbox.width + node.padding; const h = bbox.height + node.padding; @@ -122,8 +122,8 @@ const rect_left_inv_arrow = (parent, node) => { return shapeSvg; }; -const lean_right = (parent, node) => { - const { shapeSvg, bbox } = labelHelper(parent, node, undefined, true); +const lean_right = async (parent, node) => { + const { shapeSvg, bbox } = await labelHelper(parent, node, undefined, true); const w = bbox.width + node.padding; const h = bbox.height + node.padding; @@ -145,8 +145,8 @@ const lean_right = (parent, node) => { return shapeSvg; }; -const lean_left = (parent, node) => { - const { shapeSvg, bbox } = labelHelper(parent, node, undefined, true); +const lean_left = async (parent, node) => { + const { shapeSvg, bbox } = await labelHelper(parent, node, undefined, true); const w = bbox.width + node.padding; const h = bbox.height + node.padding; @@ -168,8 +168,8 @@ const lean_left = (parent, node) => { return shapeSvg; }; -const trapezoid = (parent, node) => { - const { shapeSvg, bbox } = labelHelper(parent, node, undefined, true); +const trapezoid = async (parent, node) => { + const { shapeSvg, bbox } = await labelHelper(parent, node, undefined, true); const w = bbox.width + node.padding; const h = bbox.height + node.padding; @@ -191,8 +191,8 @@ const trapezoid = (parent, node) => { return shapeSvg; }; -const inv_trapezoid = (parent, node) => { - const { shapeSvg, bbox } = labelHelper(parent, node, undefined, true); +const inv_trapezoid = async (parent, node) => { + const { shapeSvg, bbox } = await labelHelper(parent, node, undefined, true); const w = bbox.width + node.padding; const h = bbox.height + node.padding; @@ -214,8 +214,8 @@ const inv_trapezoid = (parent, node) => { return shapeSvg; }; -const rect_right_inv_arrow = (parent, node) => { - const { shapeSvg, bbox } = labelHelper(parent, node, undefined, true); +const rect_right_inv_arrow = async (parent, node) => { + const { shapeSvg, bbox } = await labelHelper(parent, node, undefined, true); const w = bbox.width + node.padding; const h = bbox.height + node.padding; @@ -238,8 +238,8 @@ const rect_right_inv_arrow = (parent, node) => { return shapeSvg; }; -const cylinder = (parent, node) => { - const { shapeSvg, bbox } = labelHelper(parent, node, undefined, true); +const cylinder = async (parent, node) => { + const { shapeSvg, bbox } = await labelHelper(parent, node, undefined, true); const w = bbox.width + node.padding; const rx = w / 2; @@ -310,21 +310,30 @@ const cylinder = (parent, node) => { return shapeSvg; }; -const rect = (parent, node) => { - const { shapeSvg, bbox, halfPadding } = labelHelper(parent, node, 'node ' + node.classes, true); +const rect = async (parent, node) => { + const { shapeSvg, bbox, halfPadding } = await labelHelper( + parent, + node, + 'node ' + node.classes, + true + ); // add the rect const rect = shapeSvg.insert('rect', ':first-child'); - const totalWidth = bbox.width + node.padding * 2; - const totalHeight = bbox.height + node.padding * 2; + // const totalWidth = bbox.width + node.padding * 2; + // const totalHeight = bbox.height + node.padding * 2; + const totalWidth = bbox.width + node.padding; + const totalHeight = bbox.height + node.padding; rect .attr('class', 'basic label-container') .attr('style', node.style) .attr('rx', node.rx) .attr('ry', node.ry) - .attr('x', -bbox.width / 2 - node.padding) - .attr('y', -bbox.height / 2 - node.padding) + // .attr('x', -bbox.width / 2 - node.padding) + // .attr('y', -bbox.height / 2 - node.padding) + .attr('x', -bbox.width / 2 - halfPadding) + .attr('y', -bbox.height / 2 - halfPadding) .attr('width', totalWidth) .attr('height', totalHeight); @@ -348,10 +357,10 @@ const rect = (parent, node) => { return shapeSvg; }; -const labelRect = (parent, node) => { - const { shapeSvg } = labelHelper(parent, node, 'label', true); +const labelRect = async (parent, node) => { + const { shapeSvg } = await labelHelper(parent, node, 'label', true); - log.info('Classes = ', node.classes); + log.trace('Classes = ', node.classes); // add the rect const rect = shapeSvg.insert('rect', ':first-child'); @@ -535,8 +544,8 @@ const rectWithTitle = (parent, node) => { return shapeSvg; }; -const stadium = (parent, node) => { - const { shapeSvg, bbox } = labelHelper(parent, node, undefined, true); +const stadium = async (parent, node) => { + const { shapeSvg, bbox } = await labelHelper(parent, node, undefined, true); const h = bbox.height + node.padding; const w = bbox.width + h / 4 + node.padding; @@ -561,8 +570,8 @@ const stadium = (parent, node) => { return shapeSvg; }; -const circle = (parent, node) => { - const { shapeSvg, bbox, halfPadding } = labelHelper(parent, node, undefined, true); +const circle = async (parent, node) => { + const { shapeSvg, bbox, halfPadding } = await labelHelper(parent, node, undefined, true); const circle = shapeSvg.insert('circle', ':first-child'); // center the circle around its coordinate @@ -586,8 +595,8 @@ const circle = (parent, node) => { return shapeSvg; }; -const doublecircle = (parent, node) => { - const { shapeSvg, bbox, halfPadding } = labelHelper(parent, node, undefined, true); +const doublecircle = async (parent, node) => { + const { shapeSvg, bbox, halfPadding } = await labelHelper(parent, node, undefined, true); const gap = 5; const circleGroup = shapeSvg.insert('g', ':first-child'); const outerCircle = circleGroup.insert('circle'); @@ -622,8 +631,8 @@ const doublecircle = (parent, node) => { return shapeSvg; }; -const subroutine = (parent, node) => { - const { shapeSvg, bbox } = labelHelper(parent, node, undefined, true); +const subroutine = async (parent, node) => { + const { shapeSvg, bbox } = await labelHelper(parent, node, undefined, true); const w = bbox.width + node.padding; const h = bbox.height + node.padding; @@ -972,7 +981,7 @@ const shapes = { let nodeElems = {}; -export const insertNode = (elem, node, dir) => { +export const insertNode = async (elem, node, dir) => { let newEl; let el; @@ -985,9 +994,9 @@ export const insertNode = (elem, node, dir) => { target = node.linkTarget || '_blank'; } newEl = elem.insert('svg:a').attr('xlink:href', node.link).attr('target', target); - el = shapes[node.shape](newEl, node, dir); + el = await shapes[node.shape](newEl, node, dir); } else { - el = shapes[node.shape](elem, node, dir); + el = await shapes[node.shape](elem, node, dir); newEl = el; } if (node.tooltip) { @@ -1013,6 +1022,7 @@ export const clear = () => { export const positionNode = (node) => { const el = nodeElems[node.id]; + log.trace( 'Transforming node', node.diff, diff --git a/packages/mermaid/src/dagre-wrapper/patterns.js b/packages/mermaid/src/dagre-wrapper/patterns.js index 75afa8bcc..3025f8ef9 100644 --- a/packages/mermaid/src/dagre-wrapper/patterns.js +++ b/packages/mermaid/src/dagre-wrapper/patterns.js @@ -1,6 +1,6 @@ /** Setup arrow head and define the marker. The result is appended to the svg. */ -// import { log } from '../logger'; +// import { log } from '../logger.js'; // Only add the number of markers that the diagram needs const insertPatterns = (elem, patternArray, type, id) => { diff --git a/packages/mermaid/src/dagre-wrapper/shapes/note.js b/packages/mermaid/src/dagre-wrapper/shapes/note.js index 6b693fdf6..17661e169 100644 --- a/packages/mermaid/src/dagre-wrapper/shapes/note.js +++ b/packages/mermaid/src/dagre-wrapper/shapes/note.js @@ -1,9 +1,19 @@ -import { updateNodeBounds, labelHelper } from './util'; -import { log } from '../../logger'; +import { updateNodeBounds, labelHelper } from './util.js'; +import { log } from '../../logger.js'; +import { getConfig } from '../../config.js'; import intersect from '../intersect/index.js'; -const note = (parent, node) => { - const { shapeSvg, bbox, halfPadding } = labelHelper(parent, node, 'node ' + node.classes, true); +const note = async (parent, node) => { + const useHtmlLabels = node.useHtmlLabels || getConfig().flowchart.htmlLabels; + if (!useHtmlLabels) { + node.centerLabel = true; + } + const { shapeSvg, bbox, halfPadding } = await labelHelper( + parent, + node, + 'node ' + node.classes, + true + ); log.info('Classes = ', node.classes); // add the rect diff --git a/packages/mermaid/src/dagre-wrapper/shapes/util.js b/packages/mermaid/src/dagre-wrapper/shapes/util.js index b5de2bd6b..7ad412bdb 100644 --- a/packages/mermaid/src/dagre-wrapper/shapes/util.js +++ b/packages/mermaid/src/dagre-wrapper/shapes/util.js @@ -1,11 +1,13 @@ -import createLabel from '../createLabel'; -import { createText } from '../../rendering-util/createText'; -import { getConfig } from '../../config'; -import { decodeEntities } from '../../mermaidAPI'; +import createLabel from '../createLabel.js'; +import { createText } from '../../rendering-util/createText.js'; +import { getConfig } from '../../config.js'; +import { decodeEntities } from '../../mermaidAPI.js'; import { select } from 'd3'; -import { evaluate, sanitizeText } from '../../diagrams/common/common'; -export const labelHelper = (parent, node, _classes, isNode) => { +import { evaluate, sanitizeText } from '../../diagrams/common/common.js'; + +export const labelHelper = async (parent, node, _classes, isNode) => { let classes; + const useHtmlLabels = node.useHtmlLabels || evaluate(getConfig().flowchart.htmlLabels); if (!_classes) { classes = 'node default'; } else { @@ -33,7 +35,7 @@ export const labelHelper = (parent, node, _classes, isNode) => { if (node.labelType === 'markdown') { // text = textNode; text = createText(label, sanitizeText(decodeEntities(labelText), getConfig()), { - useHtmlLabels: getConfig().flowchart.htmlLabels, + useHtmlLabels, width: node.width || getConfig().flowchart.wrappingWidth, classes: 'markdown-node-label', }); @@ -50,23 +52,56 @@ export const labelHelper = (parent, node, _classes, isNode) => { // Get the size of the label let bbox = text.getBBox(); + const halfPadding = node.padding / 2; if (evaluate(getConfig().flowchart.htmlLabels)) { const div = text.children[0]; const dv = select(text); + + // if there are images, need to wait for them to load before getting the bounding box + const images = div.getElementsByTagName('img'); + if (images) { + const noImgText = labelText.replace(/]*>/g, '').trim() === ''; + + await Promise.all( + [...images].map( + (img) => + new Promise((res) => + img.addEventListener('load', function () { + img.style.display = 'flex'; + img.style.flexDirection = 'column'; + + if (noImgText) { + // default size if no text + const bodyFontSize = getConfig().fontSize + ? getConfig().fontSize + : window.getComputedStyle(document.body).fontSize; + const enlargingFactor = 5; + img.style.width = parseInt(bodyFontSize, 10) * enlargingFactor + 'px'; + } else { + img.style.width = '100%'; + } + res(img); + }) + ) + ) + ); + } + bbox = div.getBoundingClientRect(); dv.attr('width', bbox.width); dv.attr('height', bbox.height); } - const halfPadding = node.padding / 2; - // Center the label - if (getConfig().flowchart.htmlLabels) { + if (useHtmlLabels) { label.attr('transform', 'translate(' + -bbox.width / 2 + ', ' + -bbox.height / 2 + ')'); } else { label.attr('transform', 'translate(' + 0 + ', ' + -bbox.height / 2 + ')'); } + if (node.centerLabel) { + label.attr('transform', 'translate(' + -bbox.width / 2 + ', ' + -bbox.height / 2 + ')'); + } label.insert('rect', ':first-child'); return { shapeSvg, bbox, halfPadding, label }; }; diff --git a/packages/mermaid/src/defaultConfig.ts b/packages/mermaid/src/defaultConfig.ts index 2ca995251..9c6d6f46e 100644 --- a/packages/mermaid/src/defaultConfig.ts +++ b/packages/mermaid/src/defaultConfig.ts @@ -1,5 +1,5 @@ -import theme from './themes'; -import { MermaidConfig } from './config.type'; +import theme from './themes/index.js'; +import { MermaidConfig } from './config.type.js'; /** * **Configuration methods in Mermaid version 8.6.0 have been updated, to learn more[[click * here](8.6.0_docs.md)].** diff --git a/packages/mermaid/src/diagram-api/comments.spec.ts b/packages/mermaid/src/diagram-api/comments.spec.ts index a2c896079..57a7d4a34 100644 --- a/packages/mermaid/src/diagram-api/comments.spec.ts +++ b/packages/mermaid/src/diagram-api/comments.spec.ts @@ -1,12 +1,12 @@ // tests to check that comments are removed -import { cleanupComments } from './comments'; +import { cleanupComments } from './comments.js'; import { describe, it, expect } from 'vitest'; describe('comments', () => { it('should remove comments', () => { const text = ` - + %% This is a comment %% This is another comment graph TD @@ -27,7 +27,7 @@ graph TD %% This is another comment %%{init: {'theme': 'forest'}}%% %%{ init: {'theme': 'space before init'}}%% -%%{init: {'theme': 'space after ending'}}%% +%%{init: {'theme': 'space after ending'}}%% graph TD A-->B @@ -37,7 +37,7 @@ graph TD expect(cleanupComments(text)).toMatchInlineSnapshot(` "%%{init: {'theme': 'forest'}}%% %%{ init: {'theme': 'space before init'}}%% - %%{init: {'theme': 'space after ending'}}%% + %%{init: {'theme': 'space after ending'}}%% graph TD A-->B diff --git a/packages/mermaid/src/diagram-api/detectType.ts b/packages/mermaid/src/diagram-api/detectType.ts index 0d26487cf..8351a67df 100644 --- a/packages/mermaid/src/diagram-api/detectType.ts +++ b/packages/mermaid/src/diagram-api/detectType.ts @@ -1,14 +1,14 @@ -import { MermaidConfig } from '../config.type'; -import { log } from '../logger'; +import { MermaidConfig } from '../config.type.js'; +import { log } from '../logger.js'; import type { DetectorRecord, DiagramDetector, DiagramLoader, ExternalDiagramDefinition, -} from './types'; -import { frontMatterRegex } from './frontmatter'; -import { getDiagram, registerDiagram } from './diagramAPI'; -import { UnknownDiagramError } from '../errors'; +} from './types.js'; +import { frontMatterRegex } from './frontmatter.js'; +import { getDiagram, registerDiagram } from './diagramAPI.js'; +import { UnknownDiagramError } from '../errors.js'; const directive = /%{2}{\s*(?:(\w+)\s*:|(\w+))\s*(?:(\w+)|((?:(?!}%{2}).|\r?\n)*))?\s*(?:}%{2})?/gi; const anyComment = /\s*%%.*\n/gm; diff --git a/packages/mermaid/src/diagram-api/diagram-orchestration.spec.ts b/packages/mermaid/src/diagram-api/diagram-orchestration.spec.ts index 81909fe5e..d6c6b3046 100644 --- a/packages/mermaid/src/diagram-api/diagram-orchestration.spec.ts +++ b/packages/mermaid/src/diagram-api/diagram-orchestration.spec.ts @@ -1,6 +1,6 @@ import { it, describe, expect } from 'vitest'; -import { detectType } from './detectType'; -import { addDiagrams } from './diagram-orchestration'; +import { detectType } from './detectType.js'; +import { addDiagrams } from './diagram-orchestration.js'; describe('diagram-orchestration', () => { it('should register diagrams', () => { diff --git a/packages/mermaid/src/diagram-api/diagram-orchestration.ts b/packages/mermaid/src/diagram-api/diagram-orchestration.ts index a88a34f19..0d4e6159d 100644 --- a/packages/mermaid/src/diagram-api/diagram-orchestration.ts +++ b/packages/mermaid/src/diagram-api/diagram-orchestration.ts @@ -1,24 +1,24 @@ -import c4 from '../diagrams/c4/c4Detector'; -import flowchart from '../diagrams/flowchart/flowDetector'; -import flowchartV2 from '../diagrams/flowchart/flowDetector-v2'; -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'; -import state from '../diagrams/state/stateDetector'; -import stateV2 from '../diagrams/state/stateDetector-V2'; -import journey from '../diagrams/user-journey/journeyDetector'; -import errorDiagram from '../diagrams/error/errorDiagram'; -import flowchartElk from '../diagrams/flowchart/elk/detector'; -import timeline from '../diagrams/timeline/detector'; -import mindmap from '../diagrams/mindmap/detector'; -import { registerLazyLoadedDiagrams } from './detectType'; -import { registerDiagram } from './diagramAPI'; +import c4 from '../diagrams/c4/c4Detector.js'; +import flowchart from '../diagrams/flowchart/flowDetector.js'; +import flowchartV2 from '../diagrams/flowchart/flowDetector-v2.js'; +import er from '../diagrams/er/erDetector.js'; +import git from '../diagrams/git/gitGraphDetector.js'; +import gantt from '../diagrams/gantt/ganttDetector.js'; +import info from '../diagrams/info/infoDetector.js'; +import pie from '../diagrams/pie/pieDetector.js'; +import requirement from '../diagrams/requirement/requirementDetector.js'; +import sequence from '../diagrams/sequence/sequenceDetector.js'; +import classDiagram from '../diagrams/class/classDetector.js'; +import classDiagramV2 from '../diagrams/class/classDetector-V2.js'; +import state from '../diagrams/state/stateDetector.js'; +import stateV2 from '../diagrams/state/stateDetector-V2.js'; +import journey from '../diagrams/user-journey/journeyDetector.js'; +import errorDiagram from '../diagrams/error/errorDiagram.js'; +import flowchartElk from '../diagrams/flowchart/elk/detector.js'; +import timeline from '../diagrams/timeline/detector.js'; +import mindmap from '../diagrams/mindmap/detector.js'; +import { registerLazyLoadedDiagrams } from './detectType.js'; +import { registerDiagram } from './diagramAPI.js'; let hasLoadedDiagrams = false; export const addDiagrams = () => { diff --git a/packages/mermaid/src/diagram-api/diagramAPI.spec.ts b/packages/mermaid/src/diagram-api/diagramAPI.spec.ts index 4bdcc5e39..49bde1a66 100644 --- a/packages/mermaid/src/diagram-api/diagramAPI.spec.ts +++ b/packages/mermaid/src/diagram-api/diagramAPI.spec.ts @@ -1,8 +1,8 @@ -import { detectType } from './detectType'; -import { getDiagram, registerDiagram } from './diagramAPI'; -import { addDiagrams } from './diagram-orchestration'; -import { DiagramDetector } from './types'; -import { getDiagramFromText } from '../Diagram'; +import { detectType } from './detectType.js'; +import { getDiagram, registerDiagram } from './diagramAPI.js'; +import { addDiagrams } from './diagram-orchestration.js'; +import { DiagramDetector } from './types.js'; +import { getDiagramFromText } from '../Diagram.js'; import { it, describe, expect, beforeAll } from 'vitest'; addDiagrams(); diff --git a/packages/mermaid/src/diagram-api/diagramAPI.ts b/packages/mermaid/src/diagram-api/diagramAPI.ts index c5841b96b..7e89d9cd7 100644 --- a/packages/mermaid/src/diagram-api/diagramAPI.ts +++ b/packages/mermaid/src/diagram-api/diagramAPI.ts @@ -1,12 +1,12 @@ -import { addDetector } from './detectType'; -import { log as _log, setLogLevel as _setLogLevel } from '../logger'; -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 * as _commonDb from '../commonDb'; -import { parseDirective as _parseDirective } from '../directiveUtils'; +import { addDetector } from './detectType.js'; +import { log as _log, setLogLevel as _setLogLevel } from '../logger.js'; +import { getConfig as _getConfig } from '../config.js'; +import { sanitizeText as _sanitizeText } from '../diagrams/common/common.js'; +import { setupGraphViewbox as _setupGraphViewbox } from '../setupGraphViewbox.js'; +import { addStylesForDiagram } from '../styles.js'; +import { DiagramDefinition, DiagramDetector } from './types.js'; +import * as _commonDb from '../commonDb.js'; +import { parseDirective as _parseDirective } from '../directiveUtils.js'; /* Packaging and exposing resources for external diagrams so that they can import diff --git a/packages/mermaid/src/diagram-api/frontmatter.spec.ts b/packages/mermaid/src/diagram-api/frontmatter.spec.ts index 4eb9789e2..ef05c8f14 100644 --- a/packages/mermaid/src/diagram-api/frontmatter.spec.ts +++ b/packages/mermaid/src/diagram-api/frontmatter.spec.ts @@ -1,5 +1,5 @@ import { vi } from 'vitest'; -import { extractFrontMatter } from './frontmatter'; +import { extractFrontMatter } from './frontmatter.js'; const dbMock = () => ({ setDiagramTitle: vi.fn() }); diff --git a/packages/mermaid/src/diagram-api/frontmatter.ts b/packages/mermaid/src/diagram-api/frontmatter.ts index a9c4995e6..8c0e998f6 100644 --- a/packages/mermaid/src/diagram-api/frontmatter.ts +++ b/packages/mermaid/src/diagram-api/frontmatter.ts @@ -1,4 +1,4 @@ -import { DiagramDb } from './types'; +import { DiagramDb } from './types.js'; // The "* as yaml" part is necessary for tree-shaking import * as yaml from 'js-yaml'; diff --git a/packages/mermaid/src/diagram-api/types.ts b/packages/mermaid/src/diagram-api/types.ts index 8c5d14eb8..f95ca5ab5 100644 --- a/packages/mermaid/src/diagram-api/types.ts +++ b/packages/mermaid/src/diagram-api/types.ts @@ -1,4 +1,4 @@ -import { MermaidConfig } from '../config.type'; +import { MermaidConfig } from '../config.type.js'; export interface InjectUtils { _log: any; diff --git a/packages/mermaid/src/diagram.spec.ts b/packages/mermaid/src/diagram.spec.ts index 5a4718d0b..aa613d8e5 100644 --- a/packages/mermaid/src/diagram.spec.ts +++ b/packages/mermaid/src/diagram.spec.ts @@ -1,7 +1,7 @@ import { describe, test, expect } from 'vitest'; -import { Diagram, getDiagramFromText } from './Diagram'; -import { addDetector } from './diagram-api/detectType'; -import { addDiagrams } from './diagram-api/diagram-orchestration'; +import { Diagram, getDiagramFromText } from './Diagram.js'; +import { addDetector } from './diagram-api/detectType.js'; +import { addDiagrams } from './diagram-api/diagram-orchestration.js'; addDiagrams(); diff --git a/packages/mermaid/src/diagrams/c4/c4Db.js b/packages/mermaid/src/diagrams/c4/c4Db.js index d337b15c0..09dcc13cd 100644 --- a/packages/mermaid/src/diagrams/c4/c4Db.js +++ b/packages/mermaid/src/diagrams/c4/c4Db.js @@ -1,7 +1,7 @@ -import mermaidAPI from '../../mermaidAPI'; -import * as configApi from '../../config'; -import { sanitizeText } from '../common/common'; -import { setAccTitle, getAccTitle, getAccDescription, setAccDescription } from '../../commonDb'; +import mermaidAPI from '../../mermaidAPI.js'; +import * as configApi from '../../config.js'; +import { sanitizeText } from '../common/common.js'; +import { setAccTitle, getAccTitle, getAccDescription, setAccDescription } from '../../commonDb.js'; let c4ShapeArray = []; let boundaryParseStack = ['']; diff --git a/packages/mermaid/src/diagrams/c4/c4Detector.ts b/packages/mermaid/src/diagrams/c4/c4Detector.ts index 08b8bbf55..e6e82c6be 100644 --- a/packages/mermaid/src/diagrams/c4/c4Detector.ts +++ b/packages/mermaid/src/diagrams/c4/c4Detector.ts @@ -1,4 +1,4 @@ -import type { ExternalDiagramDefinition } from '../../diagram-api/types'; +import type { ExternalDiagramDefinition } from '../../diagram-api/types.js'; const id = 'c4'; @@ -7,7 +7,7 @@ const detector = (txt: string) => { }; const loader = async () => { - const { diagram } = await import('./c4Diagram'); + const { diagram } = await import('./c4Diagram.js'); return { id, diagram }; }; diff --git a/packages/mermaid/src/diagrams/c4/c4Diagram.ts b/packages/mermaid/src/diagrams/c4/c4Diagram.ts index 6f8f25db2..04567fafa 100644 --- a/packages/mermaid/src/diagrams/c4/c4Diagram.ts +++ b/packages/mermaid/src/diagrams/c4/c4Diagram.ts @@ -1,10 +1,10 @@ // @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'; -import { DiagramDefinition } from '../../diagram-api/types'; +import c4Parser from './parser/c4Diagram.jison'; +import c4Db from './c4Db.js'; +import c4Renderer from './c4Renderer.js'; +import c4Styles from './styles.js'; +import { MermaidConfig } from '../../config.type.js'; +import { DiagramDefinition } from '../../diagram-api/types.js'; export const diagram: DiagramDefinition = { parser: c4Parser, diff --git a/packages/mermaid/src/diagrams/c4/c4Renderer.js b/packages/mermaid/src/diagrams/c4/c4Renderer.js index a51fe0b6a..28600241c 100644 --- a/packages/mermaid/src/diagrams/c4/c4Renderer.js +++ b/packages/mermaid/src/diagrams/c4/c4Renderer.js @@ -1,13 +1,13 @@ import { select } from 'd3'; -import svgDraw from './svgDraw'; -import { log } from '../../logger'; -import { parser } from './parser/c4Diagram'; -import common from '../common/common'; -import c4Db from './c4Db'; -import * as configApi from '../../config'; -import assignWithDepth from '../../assignWithDepth'; -import { wrapLabel, calculateTextWidth, calculateTextHeight } from '../../utils'; -import { configureSvgSize } from '../../setupGraphViewbox'; +import svgDraw from './svgDraw.js'; +import { log } from '../../logger.js'; +import { parser } from './parser/c4Diagram.jison'; +import common from '../common/common.js'; +import c4Db from './c4Db.js'; +import * as configApi from '../../config.js'; +import assignWithDepth from '../../assignWithDepth.js'; +import { wrapLabel, calculateTextWidth, calculateTextHeight } from '../../utils.js'; +import { configureSvgSize } from '../../setupGraphViewbox.js'; let globalBoundaryMaxX = 0, globalBoundaryMaxY = 0; diff --git a/packages/mermaid/src/diagrams/c4/parser/c4Boundary.spec.js b/packages/mermaid/src/diagrams/c4/parser/c4Boundary.spec.js index c7130f557..f43f00748 100644 --- a/packages/mermaid/src/diagrams/c4/parser/c4Boundary.spec.js +++ b/packages/mermaid/src/diagrams/c4/parser/c4Boundary.spec.js @@ -1,6 +1,6 @@ -import c4Db from '../c4Db'; +import c4Db from '../c4Db.js'; import c4 from './c4Diagram.jison'; -import { setConfig } from '../../../config'; +import { setConfig } from '../../../config.js'; setConfig({ securityLevel: 'strict', diff --git a/packages/mermaid/src/diagrams/c4/parser/c4Diagram.spec.js b/packages/mermaid/src/diagrams/c4/parser/c4Diagram.spec.js index b79934b84..543e87a21 100644 --- a/packages/mermaid/src/diagrams/c4/parser/c4Diagram.spec.js +++ b/packages/mermaid/src/diagrams/c4/parser/c4Diagram.spec.js @@ -1,6 +1,6 @@ -import c4Db from '../c4Db'; +import c4Db from '../c4Db.js'; import c4 from './c4Diagram.jison'; -import { setConfig } from '../../../config'; +import { setConfig } from '../../../config.js'; setConfig({ securityLevel: 'strict', diff --git a/packages/mermaid/src/diagrams/c4/parser/c4Person.spec.js b/packages/mermaid/src/diagrams/c4/parser/c4Person.spec.js index b504c0384..4eff0047c 100644 --- a/packages/mermaid/src/diagrams/c4/parser/c4Person.spec.js +++ b/packages/mermaid/src/diagrams/c4/parser/c4Person.spec.js @@ -1,6 +1,6 @@ -import c4Db from '../c4Db'; +import c4Db from '../c4Db.js'; import c4 from './c4Diagram.jison'; -import { setConfig } from '../../../config'; +import { setConfig } from '../../../config.js'; setConfig({ securityLevel: 'strict', diff --git a/packages/mermaid/src/diagrams/c4/parser/c4PersonExt.spec.js b/packages/mermaid/src/diagrams/c4/parser/c4PersonExt.spec.js index 76547600a..f4b824e88 100644 --- a/packages/mermaid/src/diagrams/c4/parser/c4PersonExt.spec.js +++ b/packages/mermaid/src/diagrams/c4/parser/c4PersonExt.spec.js @@ -1,6 +1,6 @@ -import c4Db from '../c4Db'; +import c4Db from '../c4Db.js'; import c4 from './c4Diagram.jison'; -import { setConfig } from '../../../config'; +import { setConfig } from '../../../config.js'; setConfig({ securityLevel: 'strict', diff --git a/packages/mermaid/src/diagrams/c4/parser/c4System.spec.js b/packages/mermaid/src/diagrams/c4/parser/c4System.spec.js index 6d81c7379..e2c2b26f7 100644 --- a/packages/mermaid/src/diagrams/c4/parser/c4System.spec.js +++ b/packages/mermaid/src/diagrams/c4/parser/c4System.spec.js @@ -1,6 +1,6 @@ -import c4Db from '../c4Db'; +import c4Db from '../c4Db.js'; import c4 from './c4Diagram.jison'; -import { setConfig } from '../../../config'; +import { setConfig } from '../../../config.js'; setConfig({ securityLevel: 'strict', diff --git a/packages/mermaid/src/diagrams/c4/svgDraw.js b/packages/mermaid/src/diagrams/c4/svgDraw.js index 690dd26ad..2d660e6e7 100644 --- a/packages/mermaid/src/diagrams/c4/svgDraw.js +++ b/packages/mermaid/src/diagrams/c4/svgDraw.js @@ -1,4 +1,4 @@ -import common from '../common/common'; +import common from '../common/common.js'; import { sanitizeUrl } from '@braintree/sanitize-url'; export const drawRect = function (elem, rectData) { diff --git a/packages/mermaid/src/diagrams/class/classDb.ts b/packages/mermaid/src/diagrams/class/classDb.ts index 48ef7ccbe..8fa1eeb26 100644 --- a/packages/mermaid/src/diagrams/class/classDb.ts +++ b/packages/mermaid/src/diagrams/class/classDb.ts @@ -1,10 +1,10 @@ // @ts-expect-error - d3 types issue import { select, Selection } from 'd3'; -import { log } from '../../logger'; -import * as configApi from '../../config'; -import common from '../common/common'; -import utils from '../../utils'; -import mermaidAPI from '../../mermaidAPI'; +import { log } from '../../logger.js'; +import * as configApi from '../../config.js'; +import common from '../common/common.js'; +import utils from '../../utils.js'; +import mermaidAPI from '../../mermaidAPI.js'; import { setAccTitle, getAccTitle, @@ -13,8 +13,8 @@ import { clear as commonClear, setDiagramTitle, getDiagramTitle, -} from '../../commonDb'; -import { ClassRelation, ClassNode, ClassNote, ClassMap } from './classTypes'; +} from '../../commonDb.js'; +import { ClassRelation, ClassNode, ClassNote, ClassMap } from './classTypes.js'; const MERMAID_DOM_ID_PREFIX = 'classId-'; diff --git a/packages/mermaid/src/diagrams/class/classDetector-V2.ts b/packages/mermaid/src/diagrams/class/classDetector-V2.ts index 1d4255719..9eda53a4b 100644 --- a/packages/mermaid/src/diagrams/class/classDetector-V2.ts +++ b/packages/mermaid/src/diagrams/class/classDetector-V2.ts @@ -1,4 +1,4 @@ -import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types.js'; const id = 'classDiagram'; @@ -15,7 +15,7 @@ const detector: DiagramDetector = (txt, config) => { }; const loader = async () => { - const { diagram } = await import('./classDiagram-v2'); + const { diagram } = await import('./classDiagram-v2.js'); return { id, diagram }; }; diff --git a/packages/mermaid/src/diagrams/class/classDetector.ts b/packages/mermaid/src/diagrams/class/classDetector.ts index ef8ea61e7..e2eee9bb3 100644 --- a/packages/mermaid/src/diagrams/class/classDetector.ts +++ b/packages/mermaid/src/diagrams/class/classDetector.ts @@ -1,4 +1,4 @@ -import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types.js'; const id = 'class'; @@ -12,7 +12,7 @@ const detector: DiagramDetector = (txt, config) => { }; const loader = async () => { - const { diagram } = await import('./classDiagram'); + const { diagram } = await import('./classDiagram.js'); return { id, diagram }; }; diff --git a/packages/mermaid/src/diagrams/class/classDiagram-styles.spec.js b/packages/mermaid/src/diagrams/class/classDiagram-styles.spec.js index 702fa3ac3..a693fbbea 100644 --- a/packages/mermaid/src/diagrams/class/classDiagram-styles.spec.js +++ b/packages/mermaid/src/diagrams/class/classDiagram-styles.spec.js @@ -1,5 +1,5 @@ -import { parser } from './parser/classDiagram'; -import classDb from './classDb'; +import { parser } from './parser/classDiagram.jison'; +import classDb from './classDb.js'; describe('class diagram, ', function () { describe('when parsing data from a classDiagram it', function () { diff --git a/packages/mermaid/src/diagrams/class/classDiagram-v2.ts b/packages/mermaid/src/diagrams/class/classDiagram-v2.ts index 2f0bbf371..5b952627c 100644 --- a/packages/mermaid/src/diagrams/class/classDiagram-v2.ts +++ b/packages/mermaid/src/diagrams/class/classDiagram-v2.ts @@ -1,9 +1,9 @@ -import { DiagramDefinition } from '../../diagram-api/types'; +import { DiagramDefinition } from '../../diagram-api/types.js'; // @ts-ignore: TODO Fix ts errors -import parser from './parser/classDiagram'; -import db from './classDb'; -import styles from './styles'; -import renderer from './classRenderer-v2'; +import parser from './parser/classDiagram.jison'; +import db from './classDb.js'; +import styles from './styles.js'; +import renderer from './classRenderer-v2.js'; export const diagram: DiagramDefinition = { parser, diff --git a/packages/mermaid/src/diagrams/class/classDiagram.spec.ts b/packages/mermaid/src/diagrams/class/classDiagram.spec.ts index 24fbc41ea..6dbf9c081 100644 --- a/packages/mermaid/src/diagrams/class/classDiagram.spec.ts +++ b/packages/mermaid/src/diagrams/class/classDiagram.spec.ts @@ -1,6 +1,6 @@ // @ts-expect-error Jison doesn't export types -import { parser } from './parser/classDiagram'; -import classDb from './classDb'; +import { parser } from './parser/classDiagram.jison'; +import classDb from './classDb.js'; import { vi, describe, it, expect } from 'vitest'; const spyOn = vi.spyOn; diff --git a/packages/mermaid/src/diagrams/class/classDiagram.ts b/packages/mermaid/src/diagrams/class/classDiagram.ts index 250d04176..0d2a246b4 100644 --- a/packages/mermaid/src/diagrams/class/classDiagram.ts +++ b/packages/mermaid/src/diagrams/class/classDiagram.ts @@ -1,9 +1,9 @@ -import { DiagramDefinition } from '../../diagram-api/types'; +import { DiagramDefinition } from '../../diagram-api/types.js'; // @ts-ignore: TODO Fix ts errors -import parser from './parser/classDiagram'; -import db from './classDb'; -import styles from './styles'; -import renderer from './classRenderer'; +import parser from './parser/classDiagram.jison'; +import db from './classDb.js'; +import styles from './styles.js'; +import renderer from './classRenderer.js'; export const diagram: DiagramDefinition = { parser, diff --git a/packages/mermaid/src/diagrams/class/classRenderer-v2.ts b/packages/mermaid/src/diagrams/class/classRenderer-v2.ts index e308990c6..82447c54f 100644 --- a/packages/mermaid/src/diagrams/class/classRenderer-v2.ts +++ b/packages/mermaid/src/diagrams/class/classRenderer-v2.ts @@ -1,14 +1,14 @@ // @ts-ignore d3 types are not available import { select, curveLinear } from 'd3'; import * as graphlib from 'dagre-d3-es/src/graphlib/index.js'; -import { log } from '../../logger'; -import { getConfig } from '../../config'; +import { log } from '../../logger.js'; +import { getConfig } from '../../config.js'; import { render } from '../../dagre-wrapper/index.js'; -import utils from '../../utils'; -import { interpolateToCurve, getStylesFromArray } from '../../utils'; -import { setupGraphViewbox } from '../../setupGraphViewbox'; -import common from '../common/common'; -import { ClassRelation, ClassNote, ClassMap, EdgeData } from './classTypes'; +import utils from '../../utils.js'; +import { interpolateToCurve, getStylesFromArray } from '../../utils.js'; +import { setupGraphViewbox } from '../../setupGraphViewbox.js'; +import common from '../common/common.js'; +import { ClassRelation, ClassNote, ClassMap, EdgeData } from './classTypes.js'; const sanitizeText = (txt: string) => common.sanitizeText(txt, getConfig()); @@ -248,7 +248,7 @@ export const setConf = function (cnf: any) { * @param _version - * @param diagObj - */ -export const draw = function (text: string, id: string, _version: string, diagObj: any) { +export const draw = async function (text: string, id: string, _version: string, diagObj: any) { log.info('Drawing class - ', id); // TODO V10: Why flowchart? Might be a mistake when copying. @@ -300,7 +300,7 @@ export const draw = function (text: string, id: string, _version: string, diagOb // Run the renderer. This is what draws the final graph. // @ts-ignore Ignore type error for now const element = root.select('#' + id + ' g'); - render( + await render( element, g, ['aggregation', 'extension', 'composition', 'dependency', 'lollipop'], diff --git a/packages/mermaid/src/diagrams/class/classRenderer.js b/packages/mermaid/src/diagrams/class/classRenderer.js index 80a7f26e4..3774f7b8c 100644 --- a/packages/mermaid/src/diagrams/class/classRenderer.js +++ b/packages/mermaid/src/diagrams/class/classRenderer.js @@ -1,10 +1,10 @@ import { select } from 'd3'; import { layout as dagreLayout } from 'dagre-d3-es/src/dagre/index.js'; import * as graphlib from 'dagre-d3-es/src/graphlib/index.js'; -import { log } from '../../logger'; -import svgDraw from './svgDraw'; -import { configureSvgSize } from '../../setupGraphViewbox'; -import { getConfig } from '../../config'; +import { log } from '../../logger.js'; +import svgDraw from './svgDraw.js'; +import { configureSvgSize } from '../../setupGraphViewbox.js'; +import { getConfig } from '../../config.js'; let idCache = {}; const padding = 20; diff --git a/packages/mermaid/src/diagrams/class/styles.js b/packages/mermaid/src/diagrams/class/styles.js index 981cd7b73..15386bf9e 100644 --- a/packages/mermaid/src/diagrams/class/styles.js +++ b/packages/mermaid/src/diagrams/class/styles.js @@ -41,7 +41,7 @@ const getStyles = (options) => .divider { stroke: ${options.nodeBorder}; - stroke: 1; + stroke-width: 1; } g.clickable { diff --git a/packages/mermaid/src/diagrams/class/svgDraw.js b/packages/mermaid/src/diagrams/class/svgDraw.js index cc6909280..3ce8e980b 100644 --- a/packages/mermaid/src/diagrams/class/svgDraw.js +++ b/packages/mermaid/src/diagrams/class/svgDraw.js @@ -1,7 +1,7 @@ import { line, curveBasis } from 'd3'; -import utils from '../../utils'; -import { log } from '../../logger'; -import { parseGenericTypes } from '../common/common'; +import utils from '../../utils.js'; +import { log } from '../../logger.js'; +import { parseGenericTypes } from '../common/common.js'; let edgeCount = 0; export const drawEdge = function (elem, path, relation, conf, diagObj) { diff --git a/packages/mermaid/src/diagrams/class/svgDraw.spec.js b/packages/mermaid/src/diagrams/class/svgDraw.spec.js index ec8785559..2e7c64fa0 100644 --- a/packages/mermaid/src/diagrams/class/svgDraw.spec.js +++ b/packages/mermaid/src/diagrams/class/svgDraw.spec.js @@ -1,4 +1,4 @@ -import svgDraw from './svgDraw'; +import svgDraw from './svgDraw.js'; describe('class member Renderer, ', function () { describe('when parsing text to build method display string', function () { diff --git a/packages/mermaid/src/diagrams/common/common.spec.js b/packages/mermaid/src/diagrams/common/common.spec.js index 8fd6229da..d1c68e892 100644 --- a/packages/mermaid/src/diagrams/common/common.spec.js +++ b/packages/mermaid/src/diagrams/common/common.spec.js @@ -1,4 +1,4 @@ -import { sanitizeText, removeScript, parseGenericTypes } from './common'; +import { sanitizeText, removeScript, parseGenericTypes } from './common.js'; describe('when securityLevel is antiscript, all script must be removed', function () { /** diff --git a/packages/mermaid/src/diagrams/common/common.ts b/packages/mermaid/src/diagrams/common/common.ts index d34a2df68..3b72e8718 100644 --- a/packages/mermaid/src/diagrams/common/common.ts +++ b/packages/mermaid/src/diagrams/common/common.ts @@ -1,5 +1,5 @@ import DOMPurify from 'dompurify'; -import { MermaidConfig } from '../../config.type'; +import { MermaidConfig } from '../../config.type.js'; /** * Gets the rows of lines in a string diff --git a/packages/mermaid/src/diagrams/er/erDb.js b/packages/mermaid/src/diagrams/er/erDb.js index 026e08420..5f2af0da1 100644 --- a/packages/mermaid/src/diagrams/er/erDb.js +++ b/packages/mermaid/src/diagrams/er/erDb.js @@ -1,6 +1,6 @@ -import { log } from '../../logger'; -import mermaidAPI from '../../mermaidAPI'; -import * as configApi from '../../config'; +import { log } from '../../logger.js'; +import mermaidAPI from '../../mermaidAPI.js'; +import * as configApi from '../../config.js'; import { setAccTitle, @@ -10,7 +10,7 @@ import { clear as commonClear, setDiagramTitle, getDiagramTitle, -} from '../../commonDb'; +} from '../../commonDb.js'; let entities = {}; let relationships = []; diff --git a/packages/mermaid/src/diagrams/er/erDetector.ts b/packages/mermaid/src/diagrams/er/erDetector.ts index f73baa434..b8a191af2 100644 --- a/packages/mermaid/src/diagrams/er/erDetector.ts +++ b/packages/mermaid/src/diagrams/er/erDetector.ts @@ -1,4 +1,4 @@ -import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types.js'; const id = 'er'; @@ -7,7 +7,7 @@ const detector: DiagramDetector = (txt) => { }; const loader = async () => { - const { diagram } = await import('./erDiagram'); + const { diagram } = await import('./erDiagram.js'); return { id, diagram }; }; diff --git a/packages/mermaid/src/diagrams/er/erDiagram.ts b/packages/mermaid/src/diagrams/er/erDiagram.ts index a5b0da9c1..da3d777ad 100644 --- a/packages/mermaid/src/diagrams/er/erDiagram.ts +++ b/packages/mermaid/src/diagrams/er/erDiagram.ts @@ -1,8 +1,8 @@ // @ts-ignore: TODO Fix ts errors -import erParser from './parser/erDiagram'; -import erDb from './erDb'; -import erRenderer from './erRenderer'; -import erStyles from './styles'; +import erParser from './parser/erDiagram.jison'; +import erDb from './erDb.js'; +import erRenderer from './erRenderer.js'; +import erStyles from './styles.js'; export const diagram = { parser: erParser, diff --git a/packages/mermaid/src/diagrams/er/erRenderer.js b/packages/mermaid/src/diagrams/er/erRenderer.js index 5dd5024bb..87d7ac607 100644 --- a/packages/mermaid/src/diagrams/er/erRenderer.js +++ b/packages/mermaid/src/diagrams/er/erRenderer.js @@ -1,12 +1,12 @@ import * as graphlib from 'dagre-d3-es/src/graphlib/index.js'; import { line, curveBasis, select } from 'd3'; import { layout as dagreLayout } from 'dagre-d3-es/src/dagre/index.js'; -import { getConfig } from '../../config'; -import { log } from '../../logger'; -import utils from '../../utils'; -import erMarkers from './erMarkers'; -import { configureSvgSize } from '../../setupGraphViewbox'; -import { parseGenericTypes } from '../common/common'; +import { getConfig } from '../../config.js'; +import { log } from '../../logger.js'; +import utils from '../../utils.js'; +import erMarkers from './erMarkers.js'; +import { configureSvgSize } from '../../setupGraphViewbox.js'; +import { parseGenericTypes } from '../common/common.js'; import { v5 as uuid5 } from 'uuid'; /** Regex used to remove chars from the entity name so the result can be used in an id */ diff --git a/packages/mermaid/src/diagrams/er/erRenderer.spec.ts b/packages/mermaid/src/diagrams/er/erRenderer.spec.ts index ca0f62bd2..0cba06b56 100644 --- a/packages/mermaid/src/diagrams/er/erRenderer.spec.ts +++ b/packages/mermaid/src/diagrams/er/erRenderer.spec.ts @@ -1,4 +1,4 @@ -import { generateId } from './erRenderer'; +import { generateId } from './erRenderer.js'; describe('erRenderer', () => { describe('generateId', () => { diff --git a/packages/mermaid/src/diagrams/er/parser/erDiagram.spec.js b/packages/mermaid/src/diagrams/er/parser/erDiagram.spec.js index ca497a2ac..904521d50 100644 --- a/packages/mermaid/src/diagrams/er/parser/erDiagram.spec.js +++ b/packages/mermaid/src/diagrams/er/parser/erDiagram.spec.js @@ -1,6 +1,6 @@ -import { setConfig } from '../../../config'; -import erDb from '../erDb'; -import erDiagram from './erDiagram'; // jison file +import { setConfig } from '../../../config.js'; +import erDb from '../erDb.js'; +import erDiagram from './erDiagram.jison'; // jison file setConfig({ securityLevel: 'strict', diff --git a/packages/mermaid/src/diagrams/error/errorDiagram.ts b/packages/mermaid/src/diagrams/error/errorDiagram.ts index 7b9f18c3b..76efdb0ae 100644 --- a/packages/mermaid/src/diagrams/error/errorDiagram.ts +++ b/packages/mermaid/src/diagrams/error/errorDiagram.ts @@ -1,6 +1,6 @@ -import { DiagramDefinition } from '../../diagram-api/types'; -import styles from './styles'; -import renderer from './errorRenderer'; +import { DiagramDefinition } from '../../diagram-api/types.js'; +import styles from './styles.js'; +import renderer from './errorRenderer.js'; export const diagram: DiagramDefinition = { db: { clear: () => { diff --git a/packages/mermaid/src/diagrams/error/errorRenderer.ts b/packages/mermaid/src/diagrams/error/errorRenderer.ts index 046bcfdcf..aa0e9e816 100644 --- a/packages/mermaid/src/diagrams/error/errorRenderer.ts +++ b/packages/mermaid/src/diagrams/error/errorRenderer.ts @@ -1,8 +1,8 @@ /** Created by knut on 14-12-11. */ // @ts-ignore TODO: Investigate D3 issue import { select } from 'd3'; -import { log } from '../../logger'; -import { getErrorMessage } from '../../utils'; +import { log } from '../../logger.js'; +import { getErrorMessage } from '../../utils.js'; /** * Merges the value of `conf` with the passed `cnf` diff --git a/packages/mermaid/src/diagrams/flowchart/elk/detector.spec.ts b/packages/mermaid/src/diagrams/flowchart/elk/detector.spec.ts index 17cd5c0ea..6e949c57b 100644 --- a/packages/mermaid/src/diagrams/flowchart/elk/detector.spec.ts +++ b/packages/mermaid/src/diagrams/flowchart/elk/detector.spec.ts @@ -1,4 +1,4 @@ -import plugin from './detector'; +import plugin from './detector.js'; import { describe, it } from 'vitest'; const { detector } = plugin; diff --git a/packages/mermaid/src/diagrams/flowchart/elk/detector.ts b/packages/mermaid/src/diagrams/flowchart/elk/detector.ts index c6fa77957..482bc961c 100644 --- a/packages/mermaid/src/diagrams/flowchart/elk/detector.ts +++ b/packages/mermaid/src/diagrams/flowchart/elk/detector.ts @@ -1,5 +1,5 @@ -import type { MermaidConfig } from '../../../config.type'; -import type { ExternalDiagramDefinition, DiagramDetector } from '../../../diagram-api/types'; +import type { MermaidConfig } from '../../../config.type.js'; +import type { ExternalDiagramDefinition, DiagramDetector } from '../../../diagram-api/types.js'; const id = 'flowchart-elk'; diff --git a/packages/mermaid/src/diagrams/flowchart/elk/flowRenderer-elk.js b/packages/mermaid/src/diagrams/flowchart/elk/flowRenderer-elk.js index 5849177b9..b86c537dd 100644 --- a/packages/mermaid/src/diagrams/flowchart/elk/flowRenderer-elk.js +++ b/packages/mermaid/src/diagrams/flowchart/elk/flowRenderer-elk.js @@ -2,14 +2,14 @@ import { select, line, curveLinear } from 'd3'; import { insertNode } from '../../../dagre-wrapper/nodes.js'; import insertMarkers from '../../../dagre-wrapper/markers.js'; import { insertEdgeLabel } from '../../../dagre-wrapper/edges.js'; -import { findCommonAncestor } from './render-utils'; -import { labelHelper } from '../../../dagre-wrapper/shapes/util'; +import { findCommonAncestor } from './render-utils.js'; +import { labelHelper } from '../../../dagre-wrapper/shapes/util.js'; import { addHtmlLabel } from 'dagre-d3-es/src/dagre-js/label/add-html-label.js'; -import { getConfig } from '../../../config'; -import { log } from '../../../logger'; -import { setupGraphViewbox } from '../../../setupGraphViewbox'; -import common, { evaluate } from '../../common/common'; -import { interpolateToCurve, getStylesFromArray } from '../../../utils'; +import { getConfig } from '../../../config.js'; +import { log } from '../../../logger.js'; +import { setupGraphViewbox } from '../../../setupGraphViewbox.js'; +import common, { evaluate } from '../../common/common.js'; +import { interpolateToCurve, getStylesFromArray } from '../../../utils.js'; import ELK from 'elkjs/lib/elk.bundled.js'; const elk = new ELK(); @@ -35,229 +35,231 @@ let nodeDb = {}; // * @param doc // * @param diagObj // */ -export const addVertices = function (vert, svgId, root, doc, diagObj, parentLookupDb, graph) { +export const addVertices = async function (vert, svgId, root, doc, diagObj, parentLookupDb, graph) { const svg = root.select(`[id="${svgId}"]`); const nodes = svg.insert('g').attr('class', 'nodes'); const keys = Object.keys(vert); // Iterate through each item in the vertex object (containing all the vertices found) in the graph definition - keys.forEach(function (id) { - const vertex = vert[id]; + await Promise.all( + keys.map(async function (id) { + const vertex = vert[id]; - /** - * Variable for storing the classes for the vertex - * - * @type {string} - */ - let classStr = 'default'; - if (vertex.classes.length > 0) { - classStr = vertex.classes.join(' '); - } - classStr = classStr + ' flowchart-label'; - const styles = getStylesFromArray(vertex.styles); + /** + * Variable for storing the classes for the vertex + * + * @type {string} + */ + let classStr = 'default'; + if (vertex.classes.length > 0) { + classStr = vertex.classes.join(' '); + } + classStr = classStr + ' flowchart-label'; + const styles = getStylesFromArray(vertex.styles); - // Use vertex id as text in the box if no text is provided by the graph definition - let vertexText = vertex.text !== undefined ? vertex.text : vertex.id; + // Use vertex id as text in the box if no text is provided by the graph definition + let vertexText = vertex.text !== undefined ? vertex.text : vertex.id; - // We create a SVG label, either by delegating to addHtmlLabel or manually - let vertexNode; - const labelData = { width: 0, height: 0 }; + // We create a SVG label, either by delegating to addHtmlLabel or manually + let vertexNode; + const labelData = { width: 0, height: 0 }; - const ports = [ - { - id: vertex.id + '-west', - layoutOptions: { - 'port.side': 'WEST', + const ports = [ + { + id: vertex.id + '-west', + layoutOptions: { + 'port.side': 'WEST', + }, }, - }, - { - id: vertex.id + '-east', - layoutOptions: { - 'port.side': 'EAST', + { + id: vertex.id + '-east', + layoutOptions: { + 'port.side': 'EAST', + }, }, - }, - { - id: vertex.id + '-south', - layoutOptions: { - 'port.side': 'SOUTH', + { + id: vertex.id + '-south', + layoutOptions: { + 'port.side': 'SOUTH', + }, }, - }, - { - id: vertex.id + '-north', - layoutOptions: { - 'port.side': 'NORTH', + { + id: vertex.id + '-north', + layoutOptions: { + 'port.side': 'NORTH', + }, }, - }, - ]; + ]; - let radious = 0; - let _shape = ''; - let layoutOptions = {}; - // Set the shape based parameters - switch (vertex.type) { - case 'round': - radious = 5; - _shape = 'rect'; - break; - case 'square': - _shape = 'rect'; - break; - case 'diamond': - _shape = 'question'; - layoutOptions = { - portConstraints: 'FIXED_SIDE', - }; - break; - case 'hexagon': - _shape = 'hexagon'; - break; - case 'odd': - _shape = 'rect_left_inv_arrow'; - break; - case 'lean_right': - _shape = 'lean_right'; - break; - case 'lean_left': - _shape = 'lean_left'; - break; - case 'trapezoid': - _shape = 'trapezoid'; - break; - case 'inv_trapezoid': - _shape = 'inv_trapezoid'; - break; - case 'odd_right': - _shape = 'rect_left_inv_arrow'; - break; - case 'circle': - _shape = 'circle'; - break; - case 'ellipse': - _shape = 'ellipse'; - break; - case 'stadium': - _shape = 'stadium'; - break; - case 'subroutine': - _shape = 'subroutine'; - break; - case 'cylinder': - _shape = 'cylinder'; - break; - case 'group': - _shape = 'rect'; - break; - case 'doublecircle': - _shape = 'doublecircle'; - break; - default: - _shape = 'rect'; - } + let radious = 0; + let _shape = ''; + let layoutOptions = {}; + // Set the shape based parameters + switch (vertex.type) { + case 'round': + radious = 5; + _shape = 'rect'; + break; + case 'square': + _shape = 'rect'; + break; + case 'diamond': + _shape = 'question'; + layoutOptions = { + portConstraints: 'FIXED_SIDE', + }; + break; + case 'hexagon': + _shape = 'hexagon'; + break; + case 'odd': + _shape = 'rect_left_inv_arrow'; + break; + case 'lean_right': + _shape = 'lean_right'; + break; + case 'lean_left': + _shape = 'lean_left'; + break; + case 'trapezoid': + _shape = 'trapezoid'; + break; + case 'inv_trapezoid': + _shape = 'inv_trapezoid'; + break; + case 'odd_right': + _shape = 'rect_left_inv_arrow'; + break; + case 'circle': + _shape = 'circle'; + break; + case 'ellipse': + _shape = 'ellipse'; + break; + case 'stadium': + _shape = 'stadium'; + break; + case 'subroutine': + _shape = 'subroutine'; + break; + case 'cylinder': + _shape = 'cylinder'; + break; + case 'group': + _shape = 'rect'; + break; + case 'doublecircle': + _shape = 'doublecircle'; + break; + default: + _shape = 'rect'; + } - // Add the node - const node = { - labelStyle: styles.labelStyle, - shape: _shape, - labelText: vertexText, - labelType: vertex.labelType, - rx: radious, - ry: radious, - class: classStr, - style: styles.style, - id: vertex.id, - link: vertex.link, - linkTarget: vertex.linkTarget, - tooltip: diagObj.db.getTooltip(vertex.id) || '', - domId: diagObj.db.lookUpDomId(vertex.id), - haveCallback: vertex.haveCallback, - width: vertex.type === 'group' ? 500 : undefined, - dir: vertex.dir, - type: vertex.type, - props: vertex.props, - padding: getConfig().flowchart.padding, - }; - let boundingBox; - let nodeEl; + // Add the node + const node = { + labelStyle: styles.labelStyle, + shape: _shape, + labelText: vertexText, + labelType: vertex.labelType, + rx: radious, + ry: radious, + class: classStr, + style: styles.style, + id: vertex.id, + link: vertex.link, + linkTarget: vertex.linkTarget, + tooltip: diagObj.db.getTooltip(vertex.id) || '', + domId: diagObj.db.lookUpDomId(vertex.id), + haveCallback: vertex.haveCallback, + width: vertex.type === 'group' ? 500 : undefined, + dir: vertex.dir, + type: vertex.type, + props: vertex.props, + padding: getConfig().flowchart.padding, + }; + let boundingBox; + let nodeEl; - // Add the element to the DOM - if (node.type !== 'group') { - nodeEl = insertNode(nodes, node, vertex.dir); - boundingBox = nodeEl.node().getBBox(); - } else { - const svgLabel = doc.createElementNS('http://www.w3.org/2000/svg', 'text'); - // svgLabel.setAttribute('style', styles.labelStyle.replace('color:', 'fill:')); - // const rows = vertexText.split(common.lineBreakRegex); - // for (const row of rows) { - // const tspan = doc.createElementNS('http://www.w3.org/2000/svg', 'tspan'); - // tspan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve'); - // tspan.setAttribute('dy', '1em'); - // tspan.setAttribute('x', '1'); - // tspan.textContent = row; - // svgLabel.appendChild(tspan); + // Add the element to the DOM + if (node.type !== 'group') { + nodeEl = insertNode(nodes, node, vertex.dir); + boundingBox = nodeEl.node().getBBox(); + } else { + const svgLabel = doc.createElementNS('http://www.w3.org/2000/svg', 'text'); + // svgLabel.setAttribute('style', styles.labelStyle.replace('color:', 'fill:')); + // const rows = vertexText.split(common.lineBreakRegex); + // for (const row of rows) { + // const tspan = doc.createElementNS('http://www.w3.org/2000/svg', 'tspan'); + // tspan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve'); + // tspan.setAttribute('dy', '1em'); + // tspan.setAttribute('x', '1'); + // tspan.textContent = row; + // svgLabel.appendChild(tspan); + // } + // vertexNode = svgLabel; + // const bbox = vertexNode.getBBox(); + const { shapeSvg, bbox } = await labelHelper(nodes, node, undefined, true); + labelData.width = bbox.width; + labelData.wrappingWidth = getConfig().flowchart.wrappingWidth; + labelData.height = bbox.height; + labelData.labelNode = shapeSvg.node(); + node.labelData = labelData; + } + // const { shapeSvg, bbox } = await labelHelper(svg, node, undefined, true); + + const data = { + id: vertex.id, + ports: vertex.type === 'diamond' ? ports : [], + // labelStyle: styles.labelStyle, + // shape: _shape, + layoutOptions, + labelText: vertexText, + labelData, + // labels: [{ text: vertexText }], + // rx: radius, + // ry: radius, + // class: classStr, + // style: styles.style, + // link: vertex.link, + // linkTarget: vertex.linkTarget, + // tooltip: diagObj.db.getTooltip(vertex.id) || '', + domId: diagObj.db.lookUpDomId(vertex.id), + // haveCallback: vertex.haveCallback, + width: boundingBox?.width, + height: boundingBox?.height, + // dir: vertex.dir, + type: vertex.type, + // props: vertex.props, + // padding: getConfig().flowchart.padding, + // boundingBox, + el: nodeEl, + parent: parentLookupDb.parentById[vertex.id], + }; + // if (!Object.keys(parentLookupDb.childrenById).includes(vertex.id)) { + // graph.children.push({ + // ...data, + // }); // } - // vertexNode = svgLabel; - // const bbox = vertexNode.getBBox(); - const { shapeSvg, bbox } = labelHelper(nodes, node, undefined, true); - labelData.width = bbox.width; - labelData.wrappingWidth = getConfig().flowchart.wrappingWidth; - labelData.height = bbox.height; - labelData.labelNode = shapeSvg.node(); - node.labelData = labelData; - } - // const { shapeSvg, bbox } = labelHelper(svg, node, undefined, true); - - const data = { - id: vertex.id, - ports: vertex.type === 'diamond' ? ports : [], - // labelStyle: styles.labelStyle, - // shape: _shape, - layoutOptions, - labelText: vertexText, - labelData, - // labels: [{ text: vertexText }], - // rx: radius, - // ry: radius, - // class: classStr, - // style: styles.style, - // link: vertex.link, - // linkTarget: vertex.linkTarget, - // tooltip: diagObj.db.getTooltip(vertex.id) || '', - domId: diagObj.db.lookUpDomId(vertex.id), - // haveCallback: vertex.haveCallback, - width: boundingBox?.width, - height: boundingBox?.height, - // dir: vertex.dir, - type: vertex.type, - // props: vertex.props, - // padding: getConfig().flowchart.padding, - // boundingBox, - el: nodeEl, - parent: parentLookupDb.parentById[vertex.id], - }; - // if (!Object.keys(parentLookupDb.childrenById).includes(vertex.id)) { - // graph.children.push({ - // ...data, - // }); - // } - nodeDb[node.id] = data; - // log.trace('setNode', { - // labelStyle: styles.labelStyle, - // shape: _shape, - // labelText: vertexText, - // rx: radius, - // ry: radius, - // class: classStr, - // style: styles.style, - // id: vertex.id, - // domId: diagObj.db.lookUpDomId(vertex.id), - // width: vertex.type === 'group' ? 500 : undefined, - // type: vertex.type, - // dir: vertex.dir, - // props: vertex.props, - // padding: getConfig().flowchart.padding, - // parent: parentLookupDb.parentById[vertex.id], - // }); - }); + nodeDb[node.id] = data; + // log.trace('setNode', { + // labelStyle: styles.labelStyle, + // shape: _shape, + // labelText: vertexText, + // rx: radius, + // ry: radius, + // class: classStr, + // style: styles.style, + // id: vertex.id, + // domId: diagObj.db.lookUpDomId(vertex.id), + // width: vertex.type === 'group' ? 500 : undefined, + // type: vertex.type, + // dir: vertex.dir, + // props: vertex.props, + // padding: getConfig().flowchart.padding, + // parent: parentLookupDb.parentById[vertex.id], + // }); + }) + ); return graph; }; @@ -861,7 +863,7 @@ export const draw = async function (text, id, _version, diagObj) { // in order to get the size of the node. You can't get the size of a node // that is not in the dom so we need to add it to the dom, get the size // we will position the nodes when we get the layout from elkjs - graph = addVertices(vert, id, root, doc, diagObj, parentLookupDb, graph, svg); + graph = await addVertices(vert, id, root, doc, diagObj, parentLookupDb, graph); // Time for the edges, we start with adding an element in the node to hold the edges const edgesEl = svg.insert('g').attr('class', 'edges edgePath'); @@ -934,9 +936,12 @@ const drawNodes = (relX, relY, nodeArray, svg, subgraphsEl, diagObj, depth) => { .attr('width', node.width) .attr('height', node.height); const label = subgraphEl.insert('g').attr('class', 'label'); + const labelCentering = getConfig().flowchart.htmlLabels ? node.labelData.width / 2 : 0; label.attr( 'transform', - `translate(${node.labels[0].x + relX + node.x}, ${node.labels[0].y + relY + node.y})` + `translate(${node.labels[0].x + relX + node.x + labelCentering}, ${ + node.labels[0].y + relY + node.y + 3 + })` ); label.node().appendChild(node.labelData.labelNode); diff --git a/packages/mermaid/src/diagrams/flowchart/elk/flowchart-elk-definition.ts b/packages/mermaid/src/diagrams/flowchart/elk/flowchart-elk-definition.ts index c45873238..9855c7389 100644 --- a/packages/mermaid/src/diagrams/flowchart/elk/flowchart-elk-definition.ts +++ b/packages/mermaid/src/diagrams/flowchart/elk/flowchart-elk-definition.ts @@ -1,9 +1,9 @@ // @ts-ignore: JISON typing missing -import parser from '../parser/flow'; +import parser from '../parser/flow.jison'; -import * as db from '../flowDb'; -import renderer from './flowRenderer-elk'; -import styles from './styles'; +import * as db from '../flowDb.js'; +import renderer from './flowRenderer-elk.js'; +import styles from './styles.js'; export const diagram = { db, diff --git a/packages/mermaid/src/diagrams/flowchart/elk/render-utils.spec.ts b/packages/mermaid/src/diagrams/flowchart/elk/render-utils.spec.ts index d845fa697..d048b07a3 100644 --- a/packages/mermaid/src/diagrams/flowchart/elk/render-utils.spec.ts +++ b/packages/mermaid/src/diagrams/flowchart/elk/render-utils.spec.ts @@ -1,4 +1,4 @@ -import { findCommonAncestor, TreeData } from './render-utils'; +import { findCommonAncestor, TreeData } from './render-utils.js'; describe('when rendering a flowchart using elk ', () => { let lookupDb: TreeData; beforeEach(() => { diff --git a/packages/mermaid/src/diagrams/flowchart/flowChartShapes.spec.js b/packages/mermaid/src/diagrams/flowchart/flowChartShapes.spec.js index e7e535056..96e6f6fd7 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowChartShapes.spec.js +++ b/packages/mermaid/src/diagrams/flowchart/flowChartShapes.spec.js @@ -1,4 +1,4 @@ -import { addToRender } from './flowChartShapes'; +import { addToRender } from './flowChartShapes.js'; describe('flowchart shapes', function () { // rect-based shapes diff --git a/packages/mermaid/src/diagrams/flowchart/flowDb.js b/packages/mermaid/src/diagrams/flowchart/flowDb.js index 85dc5337e..f7e1a38db 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowDb.js +++ b/packages/mermaid/src/diagrams/flowchart/flowDb.js @@ -1,9 +1,9 @@ import { select } from 'd3'; -import utils from '../../utils'; -import * as configApi from '../../config'; -import common from '../common/common'; -import mermaidAPI from '../../mermaidAPI'; -import { log } from '../../logger'; +import utils from '../../utils.js'; +import * as configApi from '../../config.js'; +import common from '../common/common.js'; +import mermaidAPI from '../../mermaidAPI.js'; +import { log } from '../../logger.js'; import { setAccTitle, getAccTitle, @@ -12,7 +12,7 @@ import { clear as commonClear, setDiagramTitle, getDiagramTitle, -} from '../../commonDb'; +} from '../../commonDb.js'; const MERMAID_DOM_ID_PREFIX = 'flowchart-'; let vertexCounter = 0; diff --git a/packages/mermaid/src/diagrams/flowchart/flowDb.spec.js b/packages/mermaid/src/diagrams/flowchart/flowDb.spec.js index c1aa640fc..09f8c8678 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowDb.spec.js +++ b/packages/mermaid/src/diagrams/flowchart/flowDb.spec.js @@ -1,4 +1,4 @@ -import flowDb from './flowDb'; +import flowDb from './flowDb.js'; describe('flow db subgraphs', () => { let subgraphs; diff --git a/packages/mermaid/src/diagrams/flowchart/flowDetector-v2.ts b/packages/mermaid/src/diagrams/flowchart/flowDetector-v2.ts index 5b2aaf1bd..9c00545bf 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowDetector-v2.ts +++ b/packages/mermaid/src/diagrams/flowchart/flowDetector-v2.ts @@ -1,5 +1,5 @@ -import type { DiagramDetector } from '../../diagram-api/types'; -import type { ExternalDiagramDefinition } from '../../diagram-api/types'; +import type { DiagramDetector } from '../../diagram-api/types.js'; +import type { ExternalDiagramDefinition } from '../../diagram-api/types.js'; const id = 'flowchart-v2'; @@ -19,7 +19,7 @@ const detector: DiagramDetector = (txt, config) => { }; const loader = async () => { - const { diagram } = await import('./flowDiagram-v2'); + const { diagram } = await import('./flowDiagram-v2.js'); return { id, diagram }; }; diff --git a/packages/mermaid/src/diagrams/flowchart/flowDetector.ts b/packages/mermaid/src/diagrams/flowchart/flowDetector.ts index a8b116ccd..84aafa249 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowDetector.ts +++ b/packages/mermaid/src/diagrams/flowchart/flowDetector.ts @@ -1,4 +1,4 @@ -import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types.js'; const id = 'flowchart'; @@ -15,7 +15,7 @@ const detector: DiagramDetector = (txt, config) => { }; const loader = async () => { - const { diagram } = await import('./flowDiagram'); + const { diagram } = await import('./flowDiagram.js'); return { id, diagram }; }; diff --git a/packages/mermaid/src/diagrams/flowchart/flowDiagram-v2.ts b/packages/mermaid/src/diagrams/flowchart/flowDiagram-v2.ts index 8cd49de65..7a2c0e0bc 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowDiagram-v2.ts +++ b/packages/mermaid/src/diagrams/flowchart/flowDiagram-v2.ts @@ -1,10 +1,10 @@ // @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'; +import flowParser from './parser/flow.jison'; +import flowDb from './flowDb.js'; +import flowRendererV2 from './flowRenderer-v2.js'; +import flowStyles from './styles.js'; +import { MermaidConfig } from '../../config.type.js'; +import { setConfig } from '../../config.js'; export const diagram = { parser: flowParser, diff --git a/packages/mermaid/src/diagrams/flowchart/flowDiagram.ts b/packages/mermaid/src/diagrams/flowchart/flowDiagram.ts index d68a7c01d..7018e4890 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowDiagram.ts +++ b/packages/mermaid/src/diagrams/flowchart/flowDiagram.ts @@ -1,10 +1,10 @@ // @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'; +import flowParser from './parser/flow.jison'; +import flowDb from './flowDb.js'; +import flowRenderer from './flowRenderer.js'; +import flowRendererV2 from './flowRenderer-v2.js'; +import flowStyles from './styles.js'; +import { MermaidConfig } from '../../config.type.js'; export const diagram = { parser: flowParser, diff --git a/packages/mermaid/src/diagrams/flowchart/flowRenderer-v2.js b/packages/mermaid/src/diagrams/flowchart/flowRenderer-v2.js index a87f23e04..0b8d47543 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowRenderer-v2.js +++ b/packages/mermaid/src/diagrams/flowchart/flowRenderer-v2.js @@ -1,16 +1,16 @@ import * as graphlib from 'dagre-d3-es/src/graphlib/index.js'; import { select, curveLinear, selectAll } from 'd3'; -import flowDb from './flowDb'; -import { getConfig } from '../../config'; -import utils from '../../utils'; +import flowDb from './flowDb.js'; +import { getConfig } from '../../config.js'; +import utils from '../../utils.js'; import { render } from '../../dagre-wrapper/index.js'; import { addHtmlLabel } from 'dagre-d3-es/src/dagre-js/label/add-html-label.js'; -import { log } from '../../logger'; -import common, { evaluate } from '../common/common'; -import { interpolateToCurve, getStylesFromArray } from '../../utils'; -import { setupGraphViewbox } from '../../setupGraphViewbox'; +import { log } from '../../logger.js'; +import common, { evaluate } from '../common/common.js'; +import { interpolateToCurve, getStylesFromArray } from '../../utils.js'; +import { setupGraphViewbox } from '../../setupGraphViewbox.js'; const conf = {}; export const setConf = function (cnf) { @@ -362,7 +362,7 @@ export const getClasses = function (text, diagObj) { * @param id */ -export const draw = function (text, id, _version, diagObj) { +export const draw = async function (text, id, _version, diagObj) { log.info('Drawing flowchart'); diagObj.db.clear(); flowDb.setGen('gen-2'); @@ -451,7 +451,7 @@ export const draw = function (text, id, _version, diagObj) { // Run the renderer. This is what draws the final graph. const element = root.select('#' + id + ' g'); - render(element, g, ['point', 'circle', 'cross'], 'flowchart', id); + await render(element, g, ['point', 'circle', 'cross'], 'flowchart', id); utils.insertTitle(svg, 'flowchartTitleText', conf.titleTopMargin, diagObj.db.getDiagramTitle()); diff --git a/packages/mermaid/src/diagrams/flowchart/flowRenderer.addEdges.spec.js b/packages/mermaid/src/diagrams/flowchart/flowRenderer.addEdges.spec.js index 7744053f0..4b7fe272d 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 { parser } from './parser/flow'; -import flowRenderer from './flowRenderer'; -import { addDiagrams } from '../../diagram-api/diagram-orchestration'; +import flowDb from './flowDb.js'; +import { parser } from './parser/flow.jison'; +import flowRenderer from './flowRenderer.js'; +import { addDiagrams } from '../../diagram-api/diagram-orchestration.js'; const diag = { db: flowDb, diff --git a/packages/mermaid/src/diagrams/flowchart/flowRenderer.js b/packages/mermaid/src/diagrams/flowchart/flowRenderer.js index 63234b57c..575706935 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowRenderer.js +++ b/packages/mermaid/src/diagrams/flowchart/flowRenderer.js @@ -1,14 +1,14 @@ import * as graphlib from 'dagre-d3-es/src/graphlib/index.js'; import { select, curveLinear, selectAll } from 'd3'; -import { getConfig } from '../../config'; +import { getConfig } from '../../config.js'; import { render as Render } from 'dagre-d3-es'; import { applyStyle } from 'dagre-d3-es/src/dagre-js/util.js'; import { addHtmlLabel } from 'dagre-d3-es/src/dagre-js/label/add-html-label.js'; -import { log } from '../../logger'; -import common, { evaluate } from '../common/common'; -import { interpolateToCurve, getStylesFromArray } from '../../utils'; -import { setupGraphViewbox } from '../../setupGraphViewbox'; -import flowChartShapes from './flowChartShapes'; +import { log } from '../../logger.js'; +import common, { evaluate } from '../common/common.js'; +import { interpolateToCurve, getStylesFromArray } from '../../utils.js'; +import { setupGraphViewbox } from '../../setupGraphViewbox.js'; +import flowChartShapes from './flowChartShapes.js'; const conf = {}; export const setConf = function (cnf) { diff --git a/packages/mermaid/src/diagrams/flowchart/flowRenderer.spec.js b/packages/mermaid/src/diagrams/flowchart/flowRenderer.spec.js index 4e1ce1019..0e9e8c0de 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowRenderer.spec.js +++ b/packages/mermaid/src/diagrams/flowchart/flowRenderer.spec.js @@ -1,5 +1,5 @@ -import { addVertices, addEdges } from './flowRenderer'; -import { setConfig } from '../../config'; +import { addVertices, addEdges } from './flowRenderer.js'; +import { setConfig } from '../../config.js'; setConfig({ flowchart: { diff --git a/packages/mermaid/src/diagrams/flowchart/parser/flow-arrows.spec.js b/packages/mermaid/src/diagrams/flowchart/parser/flow-arrows.spec.js index 594e7220b..699aa333d 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/flow-arrows.spec.js +++ b/packages/mermaid/src/diagrams/flowchart/parser/flow-arrows.spec.js @@ -1,6 +1,6 @@ -import flowDb from '../flowDb'; -import flow from './flow'; -import { setConfig } from '../../../config'; +import flowDb from '../flowDb.js'; +import flow from './flow.jison'; +import { setConfig } from '../../../config.js'; setConfig({ securityLevel: 'strict', diff --git a/packages/mermaid/src/diagrams/flowchart/parser/flow-comments.spec.js b/packages/mermaid/src/diagrams/flowchart/parser/flow-comments.spec.js index cb1e4a923..4b0b0c830 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/flow-comments.spec.js +++ b/packages/mermaid/src/diagrams/flowchart/parser/flow-comments.spec.js @@ -1,7 +1,7 @@ -import flowDb from '../flowDb'; -import flow from './flow'; -import { setConfig } from '../../../config'; -import { cleanupComments } from '../../../diagram-api/comments'; +import flowDb from '../flowDb.js'; +import flow from './flow.jison'; +import { setConfig } from '../../../config.js'; +import { cleanupComments } from '../../../diagram-api/comments.js'; setConfig({ securityLevel: 'strict', 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 7726ce0f7..ce6b0b0c4 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 { setConfig } from '../../../config'; +import flowDb from '../flowDb.js'; +import flow from './flow.jison'; +import { setConfig } from '../../../config.js'; setConfig({ securityLevel: 'strict', diff --git a/packages/mermaid/src/diagrams/flowchart/parser/flow-edges.spec.js b/packages/mermaid/src/diagrams/flowchart/parser/flow-edges.spec.js index e2ecec4d5..dcac21ee7 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/flow-edges.spec.js +++ b/packages/mermaid/src/diagrams/flowchart/parser/flow-edges.spec.js @@ -1,6 +1,6 @@ -import flowDb from '../flowDb'; -import flow from './flow'; -import { setConfig } from '../../../config'; +import flowDb from '../flowDb.js'; +import flow from './flow.jison'; +import { setConfig } from '../../../config.js'; setConfig({ securityLevel: 'strict', diff --git a/packages/mermaid/src/diagrams/flowchart/parser/flow-huge.spec.js b/packages/mermaid/src/diagrams/flowchart/parser/flow-huge.spec.js index 9097c49e3..48fc2be16 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/flow-huge.spec.js +++ b/packages/mermaid/src/diagrams/flowchart/parser/flow-huge.spec.js @@ -1,6 +1,6 @@ -import flowDb from '../flowDb'; -import flow from './flow'; -import { setConfig } from '../../../config'; +import flowDb from '../flowDb.js'; +import flow from './flow.jison'; +import { setConfig } from '../../../config.js'; setConfig({ securityLevel: 'strict', diff --git a/packages/mermaid/src/diagrams/flowchart/parser/flow-interactions.spec.js b/packages/mermaid/src/diagrams/flowchart/parser/flow-interactions.spec.js index 7d3e3ed04..cb3f48cca 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/flow-interactions.spec.js +++ b/packages/mermaid/src/diagrams/flowchart/parser/flow-interactions.spec.js @@ -1,6 +1,6 @@ -import flowDb from '../flowDb'; -import flow from './flow'; -import { setConfig } from '../../../config'; +import flowDb from '../flowDb.js'; +import flow from './flow.jison'; +import { setConfig } from '../../../config.js'; import { vi } from 'vitest'; const spyOn = vi.spyOn; diff --git a/packages/mermaid/src/diagrams/flowchart/parser/flow-lines.spec.js b/packages/mermaid/src/diagrams/flowchart/parser/flow-lines.spec.js index 0fd1e9e9c..ec157e646 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/flow-lines.spec.js +++ b/packages/mermaid/src/diagrams/flowchart/parser/flow-lines.spec.js @@ -1,6 +1,6 @@ -import flowDb from '../flowDb'; -import flow from './flow'; -import { setConfig } from '../../../config'; +import flowDb from '../flowDb.js'; +import flow from './flow.jison'; +import { setConfig } from '../../../config.js'; setConfig({ securityLevel: 'strict', diff --git a/packages/mermaid/src/diagrams/flowchart/parser/flow-md-string.spec.js b/packages/mermaid/src/diagrams/flowchart/parser/flow-md-string.spec.js index 005d257e0..0e6efaef1 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/flow-md-string.spec.js +++ b/packages/mermaid/src/diagrams/flowchart/parser/flow-md-string.spec.js @@ -1,6 +1,6 @@ -import flowDb from '../flowDb'; -import flow from './flow'; -import { setConfig } from '../../../config'; +import flowDb from '../flowDb.js'; +import flow from './flow.jison'; +import { setConfig } from '../../../config.js'; setConfig({ securityLevel: 'strict', diff --git a/packages/mermaid/src/diagrams/flowchart/parser/flow-singlenode.spec.js b/packages/mermaid/src/diagrams/flowchart/parser/flow-singlenode.spec.js index ee41a5c39..b959f019e 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/flow-singlenode.spec.js +++ b/packages/mermaid/src/diagrams/flowchart/parser/flow-singlenode.spec.js @@ -1,6 +1,6 @@ -import flowDb from '../flowDb'; -import flow from './flow'; -import { setConfig } from '../../../config'; +import flowDb from '../flowDb.js'; +import flow from './flow.jison'; +import { setConfig } from '../../../config.js'; setConfig({ securityLevel: 'strict', diff --git a/packages/mermaid/src/diagrams/flowchart/parser/flow-style.spec.js b/packages/mermaid/src/diagrams/flowchart/parser/flow-style.spec.js index 050d64f91..512a0b833 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/flow-style.spec.js +++ b/packages/mermaid/src/diagrams/flowchart/parser/flow-style.spec.js @@ -1,6 +1,6 @@ -import flowDb from '../flowDb'; -import flow from './flow'; -import { setConfig } from '../../../config'; +import flowDb from '../flowDb.js'; +import flow from './flow.jison'; +import { setConfig } from '../../../config.js'; setConfig({ securityLevel: 'strict', diff --git a/packages/mermaid/src/diagrams/flowchart/parser/flow-text.spec.js b/packages/mermaid/src/diagrams/flowchart/parser/flow-text.spec.js index e990f41b4..db43e75bf 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/flow-text.spec.js +++ b/packages/mermaid/src/diagrams/flowchart/parser/flow-text.spec.js @@ -1,6 +1,6 @@ -import flowDb from '../flowDb'; -import flow from './flow'; -import { setConfig } from '../../../config'; +import flowDb from '../flowDb.js'; +import flow from './flow.jison'; +import { setConfig } from '../../../config.js'; setConfig({ securityLevel: 'strict', diff --git a/packages/mermaid/src/diagrams/flowchart/parser/flow-vertice-chaining.spec.js b/packages/mermaid/src/diagrams/flowchart/parser/flow-vertice-chaining.spec.js index 36aaae767..3f1078030 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/flow-vertice-chaining.spec.js +++ b/packages/mermaid/src/diagrams/flowchart/parser/flow-vertice-chaining.spec.js @@ -1,6 +1,6 @@ -import flowDb from '../flowDb'; -import flow from './flow'; -import { setConfig } from '../../../config'; +import flowDb from '../flowDb.js'; +import flow from './flow.jison'; +import { setConfig } from '../../../config.js'; setConfig({ securityLevel: 'strict', diff --git a/packages/mermaid/src/diagrams/flowchart/parser/flow.spec.js b/packages/mermaid/src/diagrams/flowchart/parser/flow.spec.js index 692e72f37..3852c4f92 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/flow.spec.js +++ b/packages/mermaid/src/diagrams/flowchart/parser/flow.spec.js @@ -1,7 +1,7 @@ -import flowDb from '../flowDb'; -import flow from './flow'; -import { setConfig } from '../../../config'; -import { cleanupComments } from '../../../diagram-api/comments'; +import flowDb from '../flowDb.js'; +import flow from './flow.jison'; +import { setConfig } from '../../../config.js'; +import { cleanupComments } from '../../../diagram-api/comments.js'; setConfig({ securityLevel: 'strict', diff --git a/packages/mermaid/src/diagrams/flowchart/parser/subgraph.spec.js b/packages/mermaid/src/diagrams/flowchart/parser/subgraph.spec.js index ae6f178b8..12b2e4a39 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 { setConfig } from '../../../config'; +import flowDb from '../flowDb.js'; +import flow from './flow.jison'; +import { setConfig } from '../../../config.js'; setConfig({ securityLevel: 'strict', diff --git a/packages/mermaid/src/diagrams/flowchart/styles.ts b/packages/mermaid/src/diagrams/flowchart/styles.ts index 86ffcb7ed..964505c2d 100644 --- a/packages/mermaid/src/diagrams/flowchart/styles.ts +++ b/packages/mermaid/src/diagrams/flowchart/styles.ts @@ -23,11 +23,11 @@ const getStyles = (options: FlowChartStyleOptions) => .cluster-label text { fill: ${options.titleColor}; } - .cluster-label span { + .cluster-label span,p { color: ${options.titleColor}; } - .label text,span { + .label text,span,p { fill: ${options.nodeTextColor || options.textColor}; color: ${options.nodeTextColor || options.textColor}; } @@ -92,7 +92,7 @@ const getStyles = (options: FlowChartStyleOptions) => fill: ${options.titleColor}; } - .cluster span { + .cluster span,p { color: ${options.titleColor}; } /* .cluster div { diff --git a/packages/mermaid/src/diagrams/gantt/ganttDb.js b/packages/mermaid/src/diagrams/gantt/ganttDb.js index fa872027d..dc811cb64 100644 --- a/packages/mermaid/src/diagrams/gantt/ganttDb.js +++ b/packages/mermaid/src/diagrams/gantt/ganttDb.js @@ -1,12 +1,12 @@ import { sanitizeUrl } from '@braintree/sanitize-url'; -import dayjs from 'dayjs'; -import dayjsIsoWeek from 'dayjs/plugin/isoWeek.js'; -import dayjsCustomParseFormat from 'dayjs/plugin/customParseFormat.js'; -import dayjsAdvancedFormat from 'dayjs/plugin/advancedFormat.js'; -import { log } from '../../logger'; -import * as configApi from '../../config'; -import utils from '../../utils'; -import mermaidAPI from '../../mermaidAPI'; +import dayjs from 'dayjs/esm/index.js'; +import dayjsIsoWeek from 'dayjs/esm/plugin/isoWeek/index.js'; +import dayjsCustomParseFormat from 'dayjs/esm/plugin/customParseFormat/index.js'; +import dayjsAdvancedFormat from 'dayjs/esm/plugin/advancedFormat/index.js'; +import { log } from '../../logger.js'; +import * as configApi from '../../config.js'; +import utils from '../../utils.js'; +import mermaidAPI from '../../mermaidAPI.js'; import { setAccTitle, @@ -16,7 +16,7 @@ import { clear as commonClear, setDiagramTitle, getDiagramTitle, -} from '../../commonDb'; +} from '../../commonDb.js'; dayjs.extend(dayjsIsoWeek); dayjs.extend(dayjsCustomParseFormat); diff --git a/packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts b/packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts index 812cfd9b8..c7e00bf69 100644 --- a/packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts +++ b/packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts @@ -1,7 +1,7 @@ // @ts-nocheck TODO: Fix TS -import dayjs from 'dayjs'; -import ganttDb from './ganttDb'; -import { convert } from '../../tests/util'; +import dayjs from 'dayjs/esm/index.js'; +import ganttDb from './ganttDb.js'; +import { convert } from '../../tests/util.js'; describe('when using the ganttDb', function () { beforeEach(function () { diff --git a/packages/mermaid/src/diagrams/gantt/ganttDetector.ts b/packages/mermaid/src/diagrams/gantt/ganttDetector.ts index 3fe2bbe7e..4a736cb90 100644 --- a/packages/mermaid/src/diagrams/gantt/ganttDetector.ts +++ b/packages/mermaid/src/diagrams/gantt/ganttDetector.ts @@ -1,4 +1,4 @@ -import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types.js'; const id = 'gantt'; @@ -7,7 +7,7 @@ const detector: DiagramDetector = (txt) => { }; const loader = async () => { - const { diagram } = await import('./ganttDiagram'); + const { diagram } = await import('./ganttDiagram.js'); return { id, diagram }; }; diff --git a/packages/mermaid/src/diagrams/gantt/ganttDiagram.ts b/packages/mermaid/src/diagrams/gantt/ganttDiagram.ts index b1341052d..0104c7d0c 100644 --- a/packages/mermaid/src/diagrams/gantt/ganttDiagram.ts +++ b/packages/mermaid/src/diagrams/gantt/ganttDiagram.ts @@ -1,9 +1,9 @@ // @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'; +import ganttParser from './parser/gantt.jison'; +import ganttDb from './ganttDb.js'; +import ganttRenderer from './ganttRenderer.js'; +import ganttStyles from './styles.js'; +import { DiagramDefinition } from '../../diagram-api/types.js'; export const diagram: DiagramDefinition = { parser: ganttParser, diff --git a/packages/mermaid/src/diagrams/gantt/ganttRenderer.js b/packages/mermaid/src/diagrams/gantt/ganttRenderer.js index 78bf2fcea..a148d8a9e 100644 --- a/packages/mermaid/src/diagrams/gantt/ganttRenderer.js +++ b/packages/mermaid/src/diagrams/gantt/ganttRenderer.js @@ -1,5 +1,5 @@ -import dayjs from 'dayjs'; -import { log } from '../../logger'; +import dayjs from 'dayjs/esm/index.js'; +import { log } from '../../logger.js'; import { select, scaleTime, @@ -16,9 +16,9 @@ import { timeWeek, timeMonth, } from 'd3'; -import common from '../common/common'; -import { getConfig } from '../../config'; -import { configureSvgSize } from '../../setupGraphViewbox'; +import common from '../common/common.js'; +import { getConfig } from '../../config.js'; +import { configureSvgSize } from '../../setupGraphViewbox.js'; export const setConf = function () { log.debug('Something is calling, setConf, remove the call'); diff --git a/packages/mermaid/src/diagrams/gantt/parser/gantt.spec.js b/packages/mermaid/src/diagrams/gantt/parser/gantt.spec.js index 9a1401cad..020bab0ed 100644 --- a/packages/mermaid/src/diagrams/gantt/parser/gantt.spec.js +++ b/packages/mermaid/src/diagrams/gantt/parser/gantt.spec.js @@ -1,6 +1,6 @@ -import { parser } from './gantt'; -import ganttDb from '../ganttDb'; -import { convert } from '../../../tests/util'; +import { parser } from './gantt.jison'; +import ganttDb from '../ganttDb.js'; +import { convert } from '../../../tests/util.js'; import { vi } from 'vitest'; const spyOn = vi.spyOn; const parserFnConstructor = (str) => { diff --git a/packages/mermaid/src/diagrams/git/gitGraphAst.js b/packages/mermaid/src/diagrams/git/gitGraphAst.js index dded48efa..416479d15 100644 --- a/packages/mermaid/src/diagrams/git/gitGraphAst.js +++ b/packages/mermaid/src/diagrams/git/gitGraphAst.js @@ -1,9 +1,9 @@ -import { log } from '../../logger'; -import { random } from '../../utils'; -import mermaidAPI from '../../mermaidAPI'; -import * as configApi from '../../config'; -import { getConfig } from '../../config'; -import common from '../common/common'; +import { log } from '../../logger.js'; +import { random } from '../../utils.js'; +import mermaidAPI from '../../mermaidAPI.js'; +import * as configApi from '../../config.js'; +import { getConfig } from '../../config.js'; +import common from '../common/common.js'; import { setAccTitle, getAccTitle, @@ -12,7 +12,7 @@ import { clear as commonClear, setDiagramTitle, getDiagramTitle, -} from '../../commonDb'; +} from '../../commonDb.js'; let mainBranchName = getConfig().gitGraph.mainBranchName; let mainBranchOrder = getConfig().gitGraph.mainBranchOrder; diff --git a/packages/mermaid/src/diagrams/git/gitGraphDetector.ts b/packages/mermaid/src/diagrams/git/gitGraphDetector.ts index 46d09c6e5..aeb37e5bc 100644 --- a/packages/mermaid/src/diagrams/git/gitGraphDetector.ts +++ b/packages/mermaid/src/diagrams/git/gitGraphDetector.ts @@ -1,5 +1,5 @@ -import type { DiagramDetector } from '../../diagram-api/types'; -import type { ExternalDiagramDefinition } from '../../diagram-api/types'; +import type { DiagramDetector } from '../../diagram-api/types.js'; +import type { ExternalDiagramDefinition } from '../../diagram-api/types.js'; const id = 'gitGraph'; @@ -8,7 +8,7 @@ const detector: DiagramDetector = (txt) => { }; const loader = async () => { - const { diagram } = await import('./gitGraphDiagram'); + const { diagram } = await import('./gitGraphDiagram.js'); return { id, diagram }; }; diff --git a/packages/mermaid/src/diagrams/git/gitGraphDiagram.ts b/packages/mermaid/src/diagrams/git/gitGraphDiagram.ts index 9ef3506a0..08ff126c4 100644 --- a/packages/mermaid/src/diagrams/git/gitGraphDiagram.ts +++ b/packages/mermaid/src/diagrams/git/gitGraphDiagram.ts @@ -1,9 +1,9 @@ // @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'; +import gitGraphParser from './parser/gitGraph.jison'; +import gitGraphDb from './gitGraphAst.js'; +import gitGraphRenderer from './gitGraphRenderer.js'; +import gitGraphStyles from './styles.js'; +import { DiagramDefinition } from '../../diagram-api/types.js'; export const diagram: DiagramDefinition = { parser: gitGraphParser, diff --git a/packages/mermaid/src/diagrams/git/gitGraphParserV2.spec.js b/packages/mermaid/src/diagrams/git/gitGraphParserV2.spec.js index cad44ea1f..764fbb214 100644 --- a/packages/mermaid/src/diagrams/git/gitGraphParserV2.spec.js +++ b/packages/mermaid/src/diagrams/git/gitGraphParserV2.spec.js @@ -1,7 +1,7 @@ /* eslint-env jasmine */ // Todo reintroduce without cryptoRandomString -import gitGraphAst from './gitGraphAst'; -import { parser } from './parser/gitGraph'; +import gitGraphAst from './gitGraphAst.js'; +import { parser } from './parser/gitGraph.jison'; //import randomString from 'crypto-random-string'; //import cryptoRandomString from 'crypto-random-string'; diff --git a/packages/mermaid/src/diagrams/git/gitGraphRenderer-old.js b/packages/mermaid/src/diagrams/git/gitGraphRenderer-old.js index ca288bfae..b8cff72ec 100644 --- a/packages/mermaid/src/diagrams/git/gitGraphRenderer-old.js +++ b/packages/mermaid/src/diagrams/git/gitGraphRenderer-old.js @@ -1,9 +1,9 @@ import { curveBasis, line, select } from 'd3'; -import db from './gitGraphAst'; -import gitGraphParser from './parser/gitGraph'; -import { logger } from '../../logger'; -import { interpolateToCurve } from '../../utils'; +import db from './gitGraphAst.js'; +import gitGraphParser from './parser/gitGraph.js'; +import { logger } from '../../logger.js'; +import { interpolateToCurve } from '../../utils.js'; let allCommitsDict = {}; let branchNum; diff --git a/packages/mermaid/src/diagrams/git/gitGraphRenderer.js b/packages/mermaid/src/diagrams/git/gitGraphRenderer.js index 787eb2490..8d88c601d 100644 --- a/packages/mermaid/src/diagrams/git/gitGraphRenderer.js +++ b/packages/mermaid/src/diagrams/git/gitGraphRenderer.js @@ -1,7 +1,7 @@ import { select } from 'd3'; -import { getConfig, setupGraphViewbox } from '../../diagram-api/diagramAPI'; -import { log } from '../../logger'; -import utils from '../../utils'; +import { getConfig, setupGraphViewbox } from '../../diagram-api/diagramAPI.js'; +import { log } from '../../logger.js'; +import utils from '../../utils.js'; let allCommitsDict = {}; diff --git a/packages/mermaid/src/diagrams/git/layout.js b/packages/mermaid/src/diagrams/git/layout.js index de866a72b..0dbe57765 100644 --- a/packages/mermaid/src/diagrams/git/layout.js +++ b/packages/mermaid/src/diagrams/git/layout.js @@ -1,4 +1,4 @@ -import { getConfig } from '../../config'; +import { getConfig } from '../../config.js'; export default (dir, _branches) => { const config = getConfig().gitGraph; diff --git a/packages/mermaid/src/diagrams/info/info.spec.js b/packages/mermaid/src/diagrams/info/info.spec.js index 8bcce51d4..6f1a59d1c 100644 --- a/packages/mermaid/src/diagrams/info/info.spec.js +++ b/packages/mermaid/src/diagrams/info/info.spec.js @@ -1,5 +1,5 @@ -import { parser } from './parser/info'; -import infoDb from './infoDb'; +import { parser } from './parser/info.jison'; +import infoDb from './infoDb.js'; describe('when parsing an info graph it', function () { let ex; beforeEach(function () { diff --git a/packages/mermaid/src/diagrams/info/infoDb.js b/packages/mermaid/src/diagrams/info/infoDb.js index 2a04f1633..81ba8057f 100644 --- a/packages/mermaid/src/diagrams/info/infoDb.js +++ b/packages/mermaid/src/diagrams/info/infoDb.js @@ -1,6 +1,6 @@ /** Created by knut on 15-01-14. */ -import { log } from '../../logger'; -import { clear } from '../../commonDb'; +import { log } from '../../logger.js'; +import { clear } from '../../commonDb.js'; var message = ''; var info = false; diff --git a/packages/mermaid/src/diagrams/info/infoDetector.ts b/packages/mermaid/src/diagrams/info/infoDetector.ts index a022e3ccb..ad9b9163d 100644 --- a/packages/mermaid/src/diagrams/info/infoDetector.ts +++ b/packages/mermaid/src/diagrams/info/infoDetector.ts @@ -1,4 +1,4 @@ -import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types.js'; const id = 'info'; @@ -7,7 +7,7 @@ const detector: DiagramDetector = (txt) => { }; const loader = async () => { - const { diagram } = await import('./infoDiagram'); + const { diagram } = await import('./infoDiagram.js'); return { id, diagram }; }; diff --git a/packages/mermaid/src/diagrams/info/infoDiagram.ts b/packages/mermaid/src/diagrams/info/infoDiagram.ts index a8100a79f..a26e915e5 100644 --- a/packages/mermaid/src/diagrams/info/infoDiagram.ts +++ b/packages/mermaid/src/diagrams/info/infoDiagram.ts @@ -1,9 +1,9 @@ -import { DiagramDefinition } from '../../diagram-api/types'; +import { DiagramDefinition } from '../../diagram-api/types.js'; // @ts-ignore: TODO Fix ts errors -import parser from './parser/info'; -import db from './infoDb'; -import styles from './styles'; -import renderer from './infoRenderer'; +import parser from './parser/info.jison'; +import db from './infoDb.js'; +import styles from './styles.js'; +import renderer from './infoRenderer.js'; export const diagram: DiagramDefinition = { parser, diff --git a/packages/mermaid/src/diagrams/info/infoRenderer.js b/packages/mermaid/src/diagrams/info/infoRenderer.js index 1caa7222c..9441a3226 100644 --- a/packages/mermaid/src/diagrams/info/infoRenderer.js +++ b/packages/mermaid/src/diagrams/info/infoRenderer.js @@ -1,7 +1,7 @@ /** Created by knut on 14-12-11. */ import { select } from 'd3'; -import { log } from '../../logger'; -import { getConfig } from '../../config'; +import { log } from '../../logger.js'; +import { getConfig } from '../../config.js'; /** * Draws a an info picture in the tag with id: id based on the graph definition in text. diff --git a/packages/mermaid/src/diagrams/mindmap/detector.ts b/packages/mermaid/src/diagrams/mindmap/detector.ts index 2e2b1c7d6..95e16dea9 100644 --- a/packages/mermaid/src/diagrams/mindmap/detector.ts +++ b/packages/mermaid/src/diagrams/mindmap/detector.ts @@ -1,4 +1,4 @@ -import type { ExternalDiagramDefinition } from '../../diagram-api/types'; +import type { ExternalDiagramDefinition } from '../../diagram-api/types.js'; const id = 'mindmap'; const detector = (txt: string) => { diff --git a/packages/mermaid/src/diagrams/mindmap/mindmap-definition.ts b/packages/mermaid/src/diagrams/mindmap/mindmap-definition.ts index 61b41d347..846fd5dc5 100644 --- a/packages/mermaid/src/diagrams/mindmap/mindmap-definition.ts +++ b/packages/mermaid/src/diagrams/mindmap/mindmap-definition.ts @@ -1,8 +1,8 @@ // @ts-ignore: TODO Fix ts errors -import mindmapParser from './parser/mindmap'; -import * as mindmapDb from './mindmapDb'; -import mindmapRenderer from './mindmapRenderer'; -import mindmapStyles from './styles'; +import mindmapParser from './parser/mindmap.jison'; +import * as mindmapDb from './mindmapDb.js'; +import mindmapRenderer from './mindmapRenderer.js'; +import mindmapStyles from './styles.js'; export const diagram = { db: mindmapDb, diff --git a/packages/mermaid/src/diagrams/mindmap/mindmap.spec.js b/packages/mermaid/src/diagrams/mindmap/mindmap.spec.js index e8793e86a..845205f9b 100644 --- a/packages/mermaid/src/diagrams/mindmap/mindmap.spec.js +++ b/packages/mermaid/src/diagrams/mindmap/mindmap.spec.js @@ -1,7 +1,7 @@ -import { parser as mindmap } from './parser/mindmap'; -import * as mindmapDB from './mindmapDb'; +import { parser as mindmap } from './parser/mindmap.jison'; +import * as mindmapDB from './mindmapDb.js'; // Todo fix utils functions for tests -import { setLogLevel } from '../../diagram-api/diagramAPI'; +import { setLogLevel } from '../../diagram-api/diagramAPI.js'; describe('when parsing a mindmap ', function () { beforeEach(function () { diff --git a/packages/mermaid/src/diagrams/mindmap/mindmapDb.js b/packages/mermaid/src/diagrams/mindmap/mindmapDb.js index 71aa449d9..9413581d6 100644 --- a/packages/mermaid/src/diagrams/mindmap/mindmapDb.js +++ b/packages/mermaid/src/diagrams/mindmap/mindmapDb.js @@ -1,6 +1,6 @@ -import { getConfig } from '../../config'; -import { sanitizeText as _sanitizeText } from '../../diagrams/common/common'; -import { log } from '../../logger'; +import { getConfig } from '../../config.js'; +import { sanitizeText as _sanitizeText } from '../../diagrams/common/common.js'; +import { log } from '../../logger.js'; export const sanitizeText = (text) => _sanitizeText(text, getConfig()); diff --git a/packages/mermaid/src/diagrams/mindmap/mindmapRenderer.js b/packages/mermaid/src/diagrams/mindmap/mindmapRenderer.js index a2a4def59..01d675d83 100644 --- a/packages/mermaid/src/diagrams/mindmap/mindmapRenderer.js +++ b/packages/mermaid/src/diagrams/mindmap/mindmapRenderer.js @@ -1,12 +1,12 @@ /** Created by knut on 14-12-11. */ import { select } from 'd3'; -import { log } from '../../logger'; -import { getConfig } from '../../config'; -import { setupGraphViewbox } from '../../setupGraphViewbox'; -import svgDraw from './svgDraw'; +import { log } from '../../logger.js'; +import { getConfig } from '../../config.js'; +import { setupGraphViewbox } from '../../setupGraphViewbox.js'; +import svgDraw from './svgDraw.js'; import cytoscape from 'cytoscape/dist/cytoscape.umd.js'; import coseBilkent from 'cytoscape-cose-bilkent'; -import * as db from './mindmapDb'; +import * as db from './mindmapDb.js'; // Inject the layout algorithm into cytoscape cytoscape.use(coseBilkent); @@ -175,7 +175,7 @@ export const draw = async (text, id, version, diagObj) => { // Parse the graph definition diagObj.parser.parse(text); - log.debug('Renering mindmap diagram\n' + text, diagObj); + log.debug('Rendering mindmap diagram\n' + text, diagObj.parser); const securityLevel = getConfig().securityLevel; // Handle root and Document for when rendering in sandbox mode diff --git a/packages/mermaid/src/diagrams/mindmap/parser/mindmap.jison b/packages/mermaid/src/diagrams/mindmap/parser/mindmap.jison index 84a6191cf..9dd046a3d 100644 --- a/packages/mermaid/src/diagrams/mindmap/parser/mindmap.jison +++ b/packages/mermaid/src/diagrams/mindmap/parser/mindmap.jison @@ -18,7 +18,7 @@ %% -\s*\%\%.* {yy.getLogger().trace('Found comment',yytext);} +\s*\%\%.* {yy.getLogger().trace('Found comment',yytext); return 'SPACELINE';} // \%\%[^\n]*\n /* skip comments */ "mindmap" return 'MINDMAP'; ":::" { this.begin('CLASS'); } diff --git a/packages/mermaid/src/diagrams/mindmap/svgDraw.js b/packages/mermaid/src/diagrams/mindmap/svgDraw.js index 8b58c11a3..22132dae6 100644 --- a/packages/mermaid/src/diagrams/mindmap/svgDraw.js +++ b/packages/mermaid/src/diagrams/mindmap/svgDraw.js @@ -1,6 +1,6 @@ import { select } from 'd3'; -import * as db from './mindmapDb'; -import { createText } from '../../rendering-util/createText'; +import * as db from './mindmapDb.js'; +import { createText } from '../../rendering-util/createText.js'; const MAX_SECTIONS = 12; /** @@ -217,7 +217,8 @@ export const drawNode = function (elem, node, fullSection, conf) { // Create the wrapped text element const textElem = nodeElem.append('g'); - const newEl = createText(textElem, node.descr, { + const description = node.descr.replace(/()/g, '\n'); + const newEl = createText(textElem, description, { useHtmlLabels: htmlLabels, width: node.width, classes: 'mindmap-node-label', diff --git a/packages/mermaid/src/diagrams/pie/parser/pie.spec.js b/packages/mermaid/src/diagrams/pie/parser/pie.spec.js index 21523dde4..5e5c0b4f5 100644 --- a/packages/mermaid/src/diagrams/pie/parser/pie.spec.js +++ b/packages/mermaid/src/diagrams/pie/parser/pie.spec.js @@ -1,6 +1,6 @@ -import pieDb from '../pieDb'; -import pie from './pie'; -import { setConfig } from '../../../config'; +import pieDb from '../pieDb.js'; +import pie from './pie.jison'; +import { setConfig } from '../../../config.js'; setConfig({ securityLevel: 'strict', diff --git a/packages/mermaid/src/diagrams/pie/pieDb.js b/packages/mermaid/src/diagrams/pie/pieDb.js index 5ccf6d29e..2c86752c6 100644 --- a/packages/mermaid/src/diagrams/pie/pieDb.js +++ b/packages/mermaid/src/diagrams/pie/pieDb.js @@ -1,7 +1,7 @@ -import { log } from '../../logger'; -import mermaidAPI from '../../mermaidAPI'; -import * as configApi from '../../config'; -import common from '../common/common'; +import { log } from '../../logger.js'; +import mermaidAPI from '../../mermaidAPI.js'; +import * as configApi from '../../config.js'; +import common from '../common/common.js'; import { setAccTitle, getAccTitle, @@ -10,7 +10,7 @@ import { getAccDescription, setAccDescription, clear as commonClear, -} from '../../commonDb'; +} from '../../commonDb.js'; let sections = {}; let showData = false; diff --git a/packages/mermaid/src/diagrams/pie/pieDetector.ts b/packages/mermaid/src/diagrams/pie/pieDetector.ts index dd1224db9..34d3c0cf6 100644 --- a/packages/mermaid/src/diagrams/pie/pieDetector.ts +++ b/packages/mermaid/src/diagrams/pie/pieDetector.ts @@ -1,4 +1,4 @@ -import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types.js'; const id = 'pie'; @@ -7,7 +7,7 @@ const detector: DiagramDetector = (txt) => { }; const loader = async () => { - const { diagram } = await import('./pieDiagram'); + const { diagram } = await import('./pieDiagram.js'); return { id, diagram }; }; diff --git a/packages/mermaid/src/diagrams/pie/pieDiagram.ts b/packages/mermaid/src/diagrams/pie/pieDiagram.ts index 3a586f668..4c6b7d3bc 100644 --- a/packages/mermaid/src/diagrams/pie/pieDiagram.ts +++ b/packages/mermaid/src/diagrams/pie/pieDiagram.ts @@ -1,9 +1,9 @@ -import { DiagramDefinition } from '../../diagram-api/types'; +import { DiagramDefinition } from '../../diagram-api/types.js'; // @ts-ignore: TODO Fix ts errors -import parser from './parser/pie'; -import db from './pieDb'; -import styles from './styles'; -import renderer from './pieRenderer'; +import parser from './parser/pie.jison'; +import db from './pieDb.js'; +import styles from './styles.js'; +import renderer from './pieRenderer.js'; export const diagram: DiagramDefinition = { parser, diff --git a/packages/mermaid/src/diagrams/pie/pieRenderer.js b/packages/mermaid/src/diagrams/pie/pieRenderer.js index 9b25f5f43..1ee34e192 100644 --- a/packages/mermaid/src/diagrams/pie/pieRenderer.js +++ b/packages/mermaid/src/diagrams/pie/pieRenderer.js @@ -1,9 +1,9 @@ /** Created by AshishJ on 11-09-2019. */ import { select, scaleOrdinal, pie as d3pie, arc } from 'd3'; -import { log } from '../../logger'; -import { configureSvgSize } from '../../setupGraphViewbox'; -import * as configApi from '../../config'; -import { parseFontSize } from '../../utils'; +import { log } from '../../logger.js'; +import { configureSvgSize } from '../../setupGraphViewbox.js'; +import * as configApi from '../../config.js'; +import { parseFontSize } from '../../utils.js'; let conf = configApi.getConfig(); diff --git a/packages/mermaid/src/diagrams/requirement/parser/requirementDiagram.spec.js b/packages/mermaid/src/diagrams/requirement/parser/requirementDiagram.spec.js index 4857a37ef..1b4c5da31 100644 --- a/packages/mermaid/src/diagrams/requirement/parser/requirementDiagram.spec.js +++ b/packages/mermaid/src/diagrams/requirement/parser/requirementDiagram.spec.js @@ -1,6 +1,6 @@ -import { setConfig } from '../../../config'; -import requirementDb from '../requirementDb'; -import reqDiagram from './requirementDiagram'; +import { setConfig } from '../../../config.js'; +import requirementDb from '../requirementDb.js'; +import reqDiagram from './requirementDiagram.jison'; setConfig({ securityLevel: 'strict', diff --git a/packages/mermaid/src/diagrams/requirement/requirementDb.js b/packages/mermaid/src/diagrams/requirement/requirementDb.js index df5eb0ab9..1d0a3e2e1 100644 --- a/packages/mermaid/src/diagrams/requirement/requirementDb.js +++ b/packages/mermaid/src/diagrams/requirement/requirementDb.js @@ -1,6 +1,6 @@ -import * as configApi from '../../config'; -import { log } from '../../logger'; -import mermaidAPI from '../../mermaidAPI'; +import * as configApi from '../../config.js'; +import { log } from '../../logger.js'; +import mermaidAPI from '../../mermaidAPI.js'; import { setAccTitle, @@ -8,7 +8,7 @@ import { getAccDescription, setAccDescription, clear as commonClear, -} from '../../commonDb'; +} from '../../commonDb.js'; let relations = []; let latestRequirement = {}; diff --git a/packages/mermaid/src/diagrams/requirement/requirementDetector.ts b/packages/mermaid/src/diagrams/requirement/requirementDetector.ts index 1102fde0c..87fcea790 100644 --- a/packages/mermaid/src/diagrams/requirement/requirementDetector.ts +++ b/packages/mermaid/src/diagrams/requirement/requirementDetector.ts @@ -1,4 +1,4 @@ -import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types.js'; const id = 'requirement'; @@ -7,7 +7,7 @@ const detector: DiagramDetector = (txt) => { }; const loader = async () => { - const { diagram } = await import('./requirementDiagram'); + const { diagram } = await import('./requirementDiagram.js'); return { id, diagram }; }; diff --git a/packages/mermaid/src/diagrams/requirement/requirementDiagram.ts b/packages/mermaid/src/diagrams/requirement/requirementDiagram.ts index 37f6177b6..4505afc56 100644 --- a/packages/mermaid/src/diagrams/requirement/requirementDiagram.ts +++ b/packages/mermaid/src/diagrams/requirement/requirementDiagram.ts @@ -1,9 +1,9 @@ -import { DiagramDefinition } from '../../diagram-api/types'; +import { DiagramDefinition } from '../../diagram-api/types.js'; // @ts-ignore: TODO Fix ts errors -import parser from './parser/requirementDiagram'; -import db from './requirementDb'; -import styles from './styles'; -import renderer from './requirementRenderer'; +import parser from './parser/requirementDiagram.jison'; +import db from './requirementDb.js'; +import styles from './styles.js'; +import renderer from './requirementRenderer.js'; export const diagram: DiagramDefinition = { parser, diff --git a/packages/mermaid/src/diagrams/requirement/requirementRenderer.js b/packages/mermaid/src/diagrams/requirement/requirementRenderer.js index 9fd746bd1..b88f5c203 100644 --- a/packages/mermaid/src/diagrams/requirement/requirementRenderer.js +++ b/packages/mermaid/src/diagrams/requirement/requirementRenderer.js @@ -1,11 +1,11 @@ import { line, select } from 'd3'; import { layout as dagreLayout } from 'dagre-d3-es/src/dagre/index.js'; import * as graphlib from 'dagre-d3-es/src/graphlib/index.js'; -import { log } from '../../logger'; -import { configureSvgSize } from '../../setupGraphViewbox'; -import common from '../common/common'; -import markers from './requirementMarkers'; -import { getConfig } from '../../config'; +import { log } from '../../logger.js'; +import { configureSvgSize } from '../../setupGraphViewbox.js'; +import common from '../common/common.js'; +import markers from './requirementMarkers.js'; +import { getConfig } from '../../config.js'; let conf = {}; let relCnt = 0; diff --git a/packages/mermaid/src/diagrams/requirement/styles.js b/packages/mermaid/src/diagrams/requirement/styles.js index d0579d204..9db0fa00a 100644 --- a/packages/mermaid/src/diagrams/requirement/styles.js +++ b/packages/mermaid/src/diagrams/requirement/styles.js @@ -16,7 +16,7 @@ const getStyles = (options) => ` .reqBox { fill: ${options.requirementBackground}; - fill-opacity: 100%; + fill-opacity: 1.0; stroke: ${options.requirementBorderColor}; stroke-width: ${options.requirementBorderSize}; } @@ -26,7 +26,7 @@ const getStyles = (options) => ` } .reqLabelBox { fill: ${options.relationLabelBackground}; - fill-opacity: 100%; + fill-opacity: 1.0; } .req-title-line { diff --git a/packages/mermaid/src/diagrams/sequence/sequenceDb.js b/packages/mermaid/src/diagrams/sequence/sequenceDb.js index 5c5554c72..6550df9fa 100644 --- a/packages/mermaid/src/diagrams/sequence/sequenceDb.js +++ b/packages/mermaid/src/diagrams/sequence/sequenceDb.js @@ -1,7 +1,7 @@ -import mermaidAPI from '../../mermaidAPI'; -import * as configApi from '../../config'; -import { log } from '../../logger'; -import { sanitizeText } from '../common/common'; +import mermaidAPI from '../../mermaidAPI.js'; +import * as configApi from '../../config.js'; +import { log } from '../../logger.js'; +import { sanitizeText } from '../common/common.js'; import { setAccTitle, getAccTitle, @@ -10,7 +10,7 @@ import { getAccDescription, setAccDescription, clear as commonClear, -} from '../../commonDb'; +} from '../../commonDb.js'; let prevActor = undefined; let actors = {}; diff --git a/packages/mermaid/src/diagrams/sequence/sequenceDetector.ts b/packages/mermaid/src/diagrams/sequence/sequenceDetector.ts index c436e65d4..a808feea2 100644 --- a/packages/mermaid/src/diagrams/sequence/sequenceDetector.ts +++ b/packages/mermaid/src/diagrams/sequence/sequenceDetector.ts @@ -1,4 +1,4 @@ -import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types.js'; const id = 'sequence'; @@ -7,7 +7,7 @@ const detector: DiagramDetector = (txt) => { }; const loader = async () => { - const { diagram } = await import('./sequenceDiagram'); + const { diagram } = await import('./sequenceDiagram.js'); return { id, diagram }; }; diff --git a/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js b/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js index 08f6abee1..a6cff4a6c 100644 --- a/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js +++ b/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js @@ -1,9 +1,9 @@ import { vi } from 'vitest'; -import * as configApi from '../../config'; -import mermaidAPI from '../../mermaidAPI'; -import { Diagram, getDiagramFromText } from '../../Diagram'; -import { addDiagrams } from '../../diagram-api/diagram-orchestration'; +import * as configApi from '../../config.js'; +import mermaidAPI from '../../mermaidAPI.js'; +import { Diagram, getDiagramFromText } from '../../Diagram.js'; +import { addDiagrams } from '../../diagram-api/diagram-orchestration.js'; beforeAll(async () => { // Is required to load the sequence diagram diff --git a/packages/mermaid/src/diagrams/sequence/sequenceDiagram.ts b/packages/mermaid/src/diagrams/sequence/sequenceDiagram.ts index fdec7f86d..382d47b61 100644 --- a/packages/mermaid/src/diagrams/sequence/sequenceDiagram.ts +++ b/packages/mermaid/src/diagrams/sequence/sequenceDiagram.ts @@ -1,9 +1,9 @@ -import { DiagramDefinition } from '../../diagram-api/types'; +import { DiagramDefinition } from '../../diagram-api/types.js'; // @ts-ignore: TODO Fix ts errors -import parser from './parser/sequenceDiagram'; -import db from './sequenceDb'; -import styles from './styles'; -import renderer from './sequenceRenderer'; +import parser from './parser/sequenceDiagram.jison'; +import db from './sequenceDb.js'; +import styles from './styles.js'; +import renderer from './sequenceRenderer.js'; export const diagram: DiagramDefinition = { parser, diff --git a/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts b/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts index acee7bbe5..eca647153 100644 --- a/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts +++ b/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts @@ -1,13 +1,13 @@ // @ts-nocheck TODO: fix file import { select, selectAll } from 'd3'; -import svgDraw, { drawText, fixLifeLineHeights } from './svgDraw'; -import { log } from '../../logger'; -import common from '../common/common'; -import * as configApi from '../../config'; -import assignWithDepth from '../../assignWithDepth'; -import utils from '../../utils'; -import { configureSvgSize } from '../../setupGraphViewbox'; -import { Diagram } from '../../Diagram'; +import svgDraw, { drawText, fixLifeLineHeights } from './svgDraw.js'; +import { log } from '../../logger.js'; +import common from '../common/common.js'; +import * as configApi from '../../config.js'; +import assignWithDepth from '../../assignWithDepth.js'; +import utils from '../../utils.js'; +import { configureSvgSize } from '../../setupGraphViewbox.js'; +import { Diagram } from '../../Diagram.js'; let conf = {}; diff --git a/packages/mermaid/src/diagrams/sequence/svgDraw.js b/packages/mermaid/src/diagrams/sequence/svgDraw.js index be34daf4b..376ca6161 100644 --- a/packages/mermaid/src/diagrams/sequence/svgDraw.js +++ b/packages/mermaid/src/diagrams/sequence/svgDraw.js @@ -1,6 +1,6 @@ -import common from '../common/common'; -import { addFunction } from '../../interactionDb'; -import { parseFontSize } from '../../utils'; +import common from '../common/common.js'; +import { addFunction } from '../../interactionDb.js'; +import { parseFontSize } from '../../utils.js'; import { sanitizeUrl } from '@braintree/sanitize-url'; export const drawRect = function (elem, rectData) { diff --git a/packages/mermaid/src/diagrams/sequence/svgDraw.spec.js b/packages/mermaid/src/diagrams/sequence/svgDraw.spec.js index ed60285ed..04cde0a2c 100644 --- a/packages/mermaid/src/diagrams/sequence/svgDraw.spec.js +++ b/packages/mermaid/src/diagrams/sequence/svgDraw.spec.js @@ -1,5 +1,5 @@ import { vi } from 'vitest'; -import svgDraw from './svgDraw'; +import svgDraw from './svgDraw.js'; // This is the only place that uses this mock export const MockD3 = (name, parent) => { diff --git a/packages/mermaid/src/diagrams/state/parser/state-parser.spec.js b/packages/mermaid/src/diagrams/state/parser/state-parser.spec.js index f8ea694a6..e56931ade 100644 --- a/packages/mermaid/src/diagrams/state/parser/state-parser.spec.js +++ b/packages/mermaid/src/diagrams/state/parser/state-parser.spec.js @@ -1,6 +1,6 @@ -import stateDb from '../stateDb'; -import stateDiagram from './stateDiagram'; -import { setConfig } from '../../../config'; +import stateDb from '../stateDb.js'; +import stateDiagram from './stateDiagram.jison'; +import { setConfig } from '../../../config.js'; setConfig({ securityLevel: 'strict', diff --git a/packages/mermaid/src/diagrams/state/parser/state-style.spec.js b/packages/mermaid/src/diagrams/state/parser/state-style.spec.js index 75ecb4b13..9ce41df50 100644 --- a/packages/mermaid/src/diagrams/state/parser/state-style.spec.js +++ b/packages/mermaid/src/diagrams/state/parser/state-style.spec.js @@ -1,6 +1,6 @@ -import stateDb from '../stateDb'; -import stateDiagram from './stateDiagram'; -import { setConfig } from '../../../config'; +import stateDb from '../stateDb.js'; +import stateDiagram from './stateDiagram.jison'; +import { setConfig } from '../../../config.js'; setConfig({ securityLevel: 'strict', diff --git a/packages/mermaid/src/diagrams/state/shapes.js b/packages/mermaid/src/diagrams/state/shapes.js index 0a495e56c..e82a1ad61 100644 --- a/packages/mermaid/src/diagrams/state/shapes.js +++ b/packages/mermaid/src/diagrams/state/shapes.js @@ -1,10 +1,10 @@ import { line, curveBasis } from 'd3'; import idCache from './id-cache.js'; -import stateDb from './stateDb'; -import utils from '../../utils'; -import common from '../common/common'; -import { getConfig } from '../../config'; -import { log } from '../../logger'; +import stateDb from './stateDb.js'; +import utils from '../../utils.js'; +import common from '../common/common.js'; +import { getConfig } from '../../config.js'; +import { log } from '../../logger.js'; /** * Draws a start state as a black circle diff --git a/packages/mermaid/src/diagrams/state/stateDb.js b/packages/mermaid/src/diagrams/state/stateDb.js index 81b8ffb8b..d9c789a99 100644 --- a/packages/mermaid/src/diagrams/state/stateDb.js +++ b/packages/mermaid/src/diagrams/state/stateDb.js @@ -1,8 +1,8 @@ -import { log } from '../../logger'; -import { generateId } from '../../utils'; -import mermaidAPI from '../../mermaidAPI'; -import common from '../common/common'; -import * as configApi from '../../config'; +import { log } from '../../logger.js'; +import { generateId } from '../../utils.js'; +import mermaidAPI from '../../mermaidAPI.js'; +import common from '../common/common.js'; +import * as configApi from '../../config.js'; import { setAccTitle, getAccTitle, @@ -11,7 +11,7 @@ import { clear as commonClear, setDiagramTitle, getDiagramTitle, -} from '../../commonDb'; +} from '../../commonDb.js'; import { DEFAULT_DIAGRAM_DIRECTION, @@ -21,7 +21,7 @@ import { STMT_APPLYCLASS, DEFAULT_STATE_TYPE, DIVIDER_TYPE, -} from './stateCommon'; +} from './stateCommon.js'; const START_NODE = '[*]'; const START_TYPE = 'start'; diff --git a/packages/mermaid/src/diagrams/state/stateDb.spec.js b/packages/mermaid/src/diagrams/state/stateDb.spec.js index d51d919c3..0264c34cc 100644 --- a/packages/mermaid/src/diagrams/state/stateDb.spec.js +++ b/packages/mermaid/src/diagrams/state/stateDb.spec.js @@ -1,4 +1,4 @@ -import stateDb from './stateDb'; +import stateDb from './stateDb.js'; describe('State Diagram stateDb', () => { beforeEach(() => { diff --git a/packages/mermaid/src/diagrams/state/stateDetector-V2.ts b/packages/mermaid/src/diagrams/state/stateDetector-V2.ts index 5fa617a76..8a96e93a2 100644 --- a/packages/mermaid/src/diagrams/state/stateDetector-V2.ts +++ b/packages/mermaid/src/diagrams/state/stateDetector-V2.ts @@ -1,4 +1,4 @@ -import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types.js'; const id = 'stateDiagram'; @@ -16,7 +16,7 @@ const detector: DiagramDetector = (text, config) => { }; const loader = async () => { - const { diagram } = await import('./stateDiagram-v2'); + const { diagram } = await import('./stateDiagram-v2.js'); return { id, diagram }; }; diff --git a/packages/mermaid/src/diagrams/state/stateDetector.ts b/packages/mermaid/src/diagrams/state/stateDetector.ts index ee6b3ac2c..eb252305c 100644 --- a/packages/mermaid/src/diagrams/state/stateDetector.ts +++ b/packages/mermaid/src/diagrams/state/stateDetector.ts @@ -1,4 +1,4 @@ -import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types.js'; const id = 'state'; @@ -12,7 +12,7 @@ const detector: DiagramDetector = (txt, config) => { }; const loader = async () => { - const { diagram } = await import('./stateDiagram'); + const { diagram } = await import('./stateDiagram.js'); return { id, diagram }; }; diff --git a/packages/mermaid/src/diagrams/state/stateDiagram-v2.spec.js b/packages/mermaid/src/diagrams/state/stateDiagram-v2.spec.js index 7ed5555db..e64ecfdf8 100644 --- a/packages/mermaid/src/diagrams/state/stateDiagram-v2.spec.js +++ b/packages/mermaid/src/diagrams/state/stateDiagram-v2.spec.js @@ -1,5 +1,5 @@ -import { parser } from './parser/stateDiagram'; -import stateDb from './stateDb'; +import { parser } from './parser/stateDiagram.jison'; +import stateDb from './stateDb.js'; import stateDiagram from './parser/stateDiagram.jison'; describe('state diagram V2, ', function () { diff --git a/packages/mermaid/src/diagrams/state/stateDiagram-v2.ts b/packages/mermaid/src/diagrams/state/stateDiagram-v2.ts index f7ee4f052..616a97556 100644 --- a/packages/mermaid/src/diagrams/state/stateDiagram-v2.ts +++ b/packages/mermaid/src/diagrams/state/stateDiagram-v2.ts @@ -1,9 +1,9 @@ -import { DiagramDefinition } from '../../diagram-api/types'; +import { DiagramDefinition } from '../../diagram-api/types.js'; // @ts-ignore: TODO Fix ts errors -import parser from './parser/stateDiagram'; -import db from './stateDb'; -import styles from './styles'; -import renderer from './stateRenderer-v2'; +import parser from './parser/stateDiagram.jison'; +import db from './stateDb.js'; +import styles from './styles.js'; +import renderer from './stateRenderer-v2.js'; export const diagram: DiagramDefinition = { parser, diff --git a/packages/mermaid/src/diagrams/state/stateDiagram.spec.js b/packages/mermaid/src/diagrams/state/stateDiagram.spec.js index d2bbb409e..e6e470140 100644 --- a/packages/mermaid/src/diagrams/state/stateDiagram.spec.js +++ b/packages/mermaid/src/diagrams/state/stateDiagram.spec.js @@ -1,5 +1,5 @@ -import { parser } from './parser/stateDiagram'; -import stateDb from './stateDb'; +import { parser } from './parser/stateDiagram.jison'; +import stateDb from './stateDb.js'; describe('state diagram, ', function () { describe('when parsing an info graph it', function () { diff --git a/packages/mermaid/src/diagrams/state/stateDiagram.ts b/packages/mermaid/src/diagrams/state/stateDiagram.ts index 570d599de..44552c246 100644 --- a/packages/mermaid/src/diagrams/state/stateDiagram.ts +++ b/packages/mermaid/src/diagrams/state/stateDiagram.ts @@ -1,9 +1,9 @@ -import { DiagramDefinition } from '../../diagram-api/types'; +import { DiagramDefinition } from '../../diagram-api/types.js'; // @ts-ignore: TODO Fix ts errors -import parser from './parser/stateDiagram'; -import db from './stateDb'; -import styles from './styles'; -import renderer from './stateRenderer'; +import parser from './parser/stateDiagram.jison'; +import db from './stateDb.js'; +import styles from './styles.js'; +import renderer from './stateRenderer.js'; export const diagram: DiagramDefinition = { parser, diff --git a/packages/mermaid/src/diagrams/state/stateRenderer-v2.js b/packages/mermaid/src/diagrams/state/stateRenderer-v2.js index 8629f74db..20ae0d112 100644 --- a/packages/mermaid/src/diagrams/state/stateRenderer-v2.js +++ b/packages/mermaid/src/diagrams/state/stateRenderer-v2.js @@ -1,11 +1,11 @@ import * as graphlib from 'dagre-d3-es/src/graphlib/index.js'; import { select } from 'd3'; -import { getConfig } from '../../config'; +import { getConfig } from '../../config.js'; import { render } from '../../dagre-wrapper/index.js'; -import { log } from '../../logger'; -import { configureSvgSize } from '../../setupGraphViewbox'; -import common from '../common/common'; -import utils from '../../utils'; +import { log } from '../../logger.js'; +import { configureSvgSize } from '../../setupGraphViewbox.js'; +import common from '../common/common.js'; +import utils from '../../utils.js'; import { DEFAULT_DIAGRAM_DIRECTION, @@ -14,7 +14,7 @@ import { STMT_RELATION, DEFAULT_STATE_TYPE, DIVIDER_TYPE, -} from './stateCommon'; +} from './stateCommon.js'; // -------------------------------------- // Shapes @@ -232,6 +232,9 @@ const setupNode = (g, parent, parsedItem, diagramStates, diagramDb, altFlag) => type: newNode.type, padding: 15, //getConfig().flowchart.padding }; + // if (useHtmlLabels) { + nodeData.centerLabel = true; + // } if (parsedItem.note) { // Todo: set random id @@ -240,6 +243,7 @@ const setupNode = (g, parent, parsedItem, diagramStates, diagramDb, altFlag) => shape: SHAPE_NOTE, labelText: parsedItem.note.text, classes: CSS_DIAGRAM_NOTE, + // useHtmlLabels: false, style: '', // styles.style, id: itemId + NOTE_ID + '-' + graphItemCount, domId: stateDomId(itemId, graphItemCount, NOTE), @@ -378,7 +382,7 @@ const getDir = (parsedItem, defaultDir = DEFAULT_NESTED_DOC_DIR) => { * @param _version * @param diag */ -export const draw = function (text, id, _version, diag) { +export const draw = async function (text, id, _version, diag) { log.info('Drawing state diagram (v2)', id); // diag.sb.clear(); nodeDb = {}; @@ -432,7 +436,7 @@ export const draw = function (text, id, _version, diag) { // Run the renderer. This is what draws the final graph. const element = root.select('#' + id + ' g'); - render(element, g, ['barb'], CSS_DIAGRAM, id); + await render(element, g, ['barb'], CSS_DIAGRAM, id); const padding = 8; diff --git a/packages/mermaid/src/diagrams/state/stateRenderer-v2.spec.js b/packages/mermaid/src/diagrams/state/stateRenderer-v2.spec.js index 3a118e607..a190fe05b 100644 --- a/packages/mermaid/src/diagrams/state/stateRenderer-v2.spec.js +++ b/packages/mermaid/src/diagrams/state/stateRenderer-v2.spec.js @@ -1,8 +1,8 @@ import { expectTypeOf } from 'vitest'; -import { parser } from './parser/stateDiagram'; -import stateDb from './stateDb'; -import stateRendererV2 from './stateRenderer-v2'; +import { parser } from './parser/stateDiagram.jison'; +import stateDb from './stateDb.js'; +import stateRendererV2 from './stateRenderer-v2.js'; // Can use this instead of having to register diagrams and load/orchestrate them, etc. class FauxDiagramObj { diff --git a/packages/mermaid/src/diagrams/state/stateRenderer.js b/packages/mermaid/src/diagrams/state/stateRenderer.js index 8d410fdd9..74913a748 100644 --- a/packages/mermaid/src/diagrams/state/stateRenderer.js +++ b/packages/mermaid/src/diagrams/state/stateRenderer.js @@ -1,11 +1,11 @@ import { select } from 'd3'; import { layout as dagreLayout } from 'dagre-d3-es/src/dagre/index.js'; import * as graphlib from 'dagre-d3-es/src/graphlib/index.js'; -import { log } from '../../logger'; -import common from '../common/common'; -import { drawState, addTitleAndBox, drawEdge } from './shapes'; -import { getConfig } from '../../config'; -import { configureSvgSize } from '../../setupGraphViewbox'; +import { log } from '../../logger.js'; +import common from '../common/common.js'; +import { drawState, addTitleAndBox, drawEdge } from './shapes.js'; +import { getConfig } from '../../config.js'; +import { configureSvgSize } from '../../setupGraphViewbox.js'; // TODO Move conf object to main conf in mermaidAPI let conf; diff --git a/packages/mermaid/src/diagrams/timeline/detector.ts b/packages/mermaid/src/diagrams/timeline/detector.ts index 9bd2b5ece..57d8f66ad 100644 --- a/packages/mermaid/src/diagrams/timeline/detector.ts +++ b/packages/mermaid/src/diagrams/timeline/detector.ts @@ -1,4 +1,4 @@ -import type { ExternalDiagramDefinition } from '../../diagram-api/types'; +import type { ExternalDiagramDefinition } from '../../diagram-api/types.js'; const id = 'timeline'; diff --git a/packages/mermaid/src/diagrams/timeline/timeline-definition.ts b/packages/mermaid/src/diagrams/timeline/timeline-definition.ts index 898af8b78..7f671291f 100644 --- a/packages/mermaid/src/diagrams/timeline/timeline-definition.ts +++ b/packages/mermaid/src/diagrams/timeline/timeline-definition.ts @@ -1,8 +1,8 @@ // @ts-ignore: TODO Fix ts errors import parser from './parser/timeline.jison'; -import * as db from './timelineDb'; -import renderer from './timelineRenderer'; -import styles from './styles'; +import * as db from './timelineDb.js'; +import renderer from './timelineRenderer.js'; +import styles from './styles.js'; export const diagram = { db, diff --git a/packages/mermaid/src/diagrams/timeline/timeline.spec.js b/packages/mermaid/src/diagrams/timeline/timeline.spec.js index 0697b194e..1f6a96024 100644 --- a/packages/mermaid/src/diagrams/timeline/timeline.spec.js +++ b/packages/mermaid/src/diagrams/timeline/timeline.spec.js @@ -1,8 +1,8 @@ -import { parser as timeline } from './parser/timeline'; -import * as timelineDB from './timelineDb'; -// import { injectUtils } from './mermaidUtils'; -import * as _commonDb from '../../commonDb'; -import { parseDirective as _parseDirective } from '../../directiveUtils'; +import { parser as timeline } from './parser/timeline.jison'; +import * as timelineDB from './timelineDb.js'; +// import { injectUtils } from './mermaidUtils.js'; +import * as _commonDb from '../../commonDb.js'; +import { parseDirective as _parseDirective } from '../../directiveUtils.js'; import { log, @@ -10,7 +10,7 @@ import { getConfig, sanitizeText, setupGraphViewBox, -} from '../../diagram-api/diagramAPI'; +} from '../../diagram-api/diagramAPI.js'; // injectUtils( // log, diff --git a/packages/mermaid/src/diagrams/timeline/timelineDb.js b/packages/mermaid/src/diagrams/timeline/timelineDb.js index 7bc5c2692..337cfe441 100644 --- a/packages/mermaid/src/diagrams/timeline/timelineDb.js +++ b/packages/mermaid/src/diagrams/timeline/timelineDb.js @@ -1,5 +1,5 @@ -import { parseDirective as _parseDirective } from '../../directiveUtils'; -import * as commonDb from '../../commonDb'; +import { parseDirective as _parseDirective } from '../../directiveUtils.js'; +import * as commonDb from '../../commonDb.js'; let currentSection = ''; let currentTaskId = 0; diff --git a/packages/mermaid/src/diagrams/timeline/timelineRenderer.ts b/packages/mermaid/src/diagrams/timeline/timelineRenderer.ts index 272ecf0c1..65abe8fd9 100644 --- a/packages/mermaid/src/diagrams/timeline/timelineRenderer.ts +++ b/packages/mermaid/src/diagrams/timeline/timelineRenderer.ts @@ -1,11 +1,11 @@ // @ts-ignore - db not typed yet import { select, Selection } from 'd3'; -import svgDraw from './svgDraw'; -import { log } from '../../logger'; -import { getConfig } from '../../config'; -import { setupGraphViewbox } from '../../setupGraphViewbox'; -import { Diagram } from '../../Diagram'; -import { MermaidConfig } from '../../config.type'; +import svgDraw from './svgDraw.js'; +import { log } from '../../logger.js'; +import { getConfig } from '../../config.js'; +import { setupGraphViewbox } from '../../setupGraphViewbox.js'; +import { Diagram } from '../../Diagram.js'; +import { MermaidConfig } from '../../config.type.js'; interface Block { number: number; diff --git a/packages/mermaid/src/diagrams/user-journey/journeyDb.js b/packages/mermaid/src/diagrams/user-journey/journeyDb.js index ce8705094..d4f34e942 100644 --- a/packages/mermaid/src/diagrams/user-journey/journeyDb.js +++ b/packages/mermaid/src/diagrams/user-journey/journeyDb.js @@ -1,5 +1,5 @@ -import mermaidAPI from '../../mermaidAPI'; -import * as configApi from '../../config'; +import mermaidAPI from '../../mermaidAPI.js'; +import * as configApi from '../../config.js'; import { setAccTitle, getAccTitle, @@ -8,7 +8,7 @@ import { getAccDescription, setAccDescription, clear as commonClear, -} from '../../commonDb'; +} from '../../commonDb.js'; let currentSection = ''; diff --git a/packages/mermaid/src/diagrams/user-journey/journeyDb.spec.js b/packages/mermaid/src/diagrams/user-journey/journeyDb.spec.js index 78955c794..c740e40d0 100644 --- a/packages/mermaid/src/diagrams/user-journey/journeyDb.spec.js +++ b/packages/mermaid/src/diagrams/user-journey/journeyDb.spec.js @@ -1,5 +1,5 @@ -import journeyDb from './journeyDb'; -import { convert } from '../../tests/util'; +import journeyDb from './journeyDb.js'; +import { convert } from '../../tests/util.js'; describe('when using the journeyDb', function () { beforeEach(function () { diff --git a/packages/mermaid/src/diagrams/user-journey/journeyDetector.ts b/packages/mermaid/src/diagrams/user-journey/journeyDetector.ts index 90b2fd6e1..0dd488782 100644 --- a/packages/mermaid/src/diagrams/user-journey/journeyDetector.ts +++ b/packages/mermaid/src/diagrams/user-journey/journeyDetector.ts @@ -1,4 +1,4 @@ -import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; +import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types.js'; const id = 'journey'; @@ -7,7 +7,7 @@ const detector: DiagramDetector = (txt) => { }; const loader = async () => { - const { diagram } = await import('./journeyDiagram'); + const { diagram } = await import('./journeyDiagram.js'); return { id, diagram }; }; diff --git a/packages/mermaid/src/diagrams/user-journey/journeyDiagram.ts b/packages/mermaid/src/diagrams/user-journey/journeyDiagram.ts index c3a2a3c6b..969cf0e5e 100644 --- a/packages/mermaid/src/diagrams/user-journey/journeyDiagram.ts +++ b/packages/mermaid/src/diagrams/user-journey/journeyDiagram.ts @@ -1,9 +1,9 @@ -import { DiagramDefinition } from '../../diagram-api/types'; +import { DiagramDefinition } from '../../diagram-api/types.js'; // @ts-ignore: TODO Fix ts errors -import parser from './parser/journey'; -import db from './journeyDb'; -import styles from './styles'; -import renderer from './journeyRenderer'; +import parser from './parser/journey.jison'; +import db from './journeyDb.js'; +import styles from './styles.js'; +import renderer from './journeyRenderer.js'; export const diagram: DiagramDefinition = { parser, diff --git a/packages/mermaid/src/diagrams/user-journey/journeyRenderer.ts b/packages/mermaid/src/diagrams/user-journey/journeyRenderer.ts index c34f8f5b2..9ea880f69 100644 --- a/packages/mermaid/src/diagrams/user-journey/journeyRenderer.ts +++ b/packages/mermaid/src/diagrams/user-journey/journeyRenderer.ts @@ -1,8 +1,8 @@ // @ts-nocheck TODO: fix file import { select } from 'd3'; -import svgDraw from './svgDraw'; -import { getConfig } from '../../config'; -import { configureSvgSize } from '../../setupGraphViewbox'; +import svgDraw from './svgDraw.js'; +import { getConfig } from '../../config.js'; +import { configureSvgSize } from '../../setupGraphViewbox.js'; export const setConf = function (cnf) { const keys = Object.keys(cnf); diff --git a/packages/mermaid/src/diagrams/user-journey/parser/journey.spec.js b/packages/mermaid/src/diagrams/user-journey/parser/journey.spec.js index cc54d9f78..8ed342bb5 100644 --- a/packages/mermaid/src/diagrams/user-journey/parser/journey.spec.js +++ b/packages/mermaid/src/diagrams/user-journey/parser/journey.spec.js @@ -1,5 +1,5 @@ -import { parser } from './journey'; -import journeyDb from '../journeyDb'; +import { parser } from './journey.jison'; +import journeyDb from '../journeyDb.js'; const parserFnConstructor = (str) => { return () => { diff --git a/packages/mermaid/src/directiveUtils.ts b/packages/mermaid/src/directiveUtils.ts index 2d2971a85..563856631 100644 --- a/packages/mermaid/src/directiveUtils.ts +++ b/packages/mermaid/src/directiveUtils.ts @@ -1,7 +1,7 @@ -import * as configApi from './config'; +import * as configApi from './config.js'; -import { log } from './logger'; -import { directiveSanitizer } from './utils'; +import { log } from './logger.js'; +import { directiveSanitizer } from './utils.js'; let currentDirective: { type?: string; args?: any } | undefined = {}; diff --git a/packages/mermaid/src/docs/.vitepress/config.ts b/packages/mermaid/src/docs/.vitepress/config.ts index 9b01fdbde..2ca53b348 100644 --- a/packages/mermaid/src/docs/.vitepress/config.ts +++ b/packages/mermaid/src/docs/.vitepress/config.ts @@ -1,5 +1,5 @@ import { version } from '../../../package.json'; -import MermaidExample from './mermaid-markdown-all'; +import MermaidExample from './mermaid-markdown-all.js'; import { defineConfig, MarkdownOptions } from 'vitepress'; const allMarkdownTransformers: MarkdownOptions = { @@ -28,7 +28,16 @@ export default defineConfig({ }, socialLinks: [ { icon: 'github', link: 'https://github.com/mermaid-js/mermaid' }, - { icon: 'slack', link: 'https://mermaid-talk.slack.com' }, + { + icon: 'slack', + link: 'https://join.slack.com/t/mermaid-talk/shared_invite/enQtNzc4NDIyNzk4OTAyLWVhYjQxOTI2OTg4YmE1ZmJkY2Y4MTU3ODliYmIwOTY3NDJlYjA0YjIyZTdkMDMyZTUwOGI0NjEzYmEwODcwOTE', + }, + { + icon: { + svg: '', + }, + link: 'https://www.mermaidchart.com/', + }, ], }, }); @@ -42,6 +51,11 @@ function nav() { activeMatch: '/config/', }, { text: 'Integrations', link: '/ecosystem/integrations', activeMatch: '/ecosystem/' }, + { + text: 'Latest News', + link: '/news/announcements', + activeMatch: '/announcements', + }, { text: version, items: [ @@ -80,6 +94,7 @@ function sidebarAll() { ...sidebarEcosystem(), ...sidebarConfig(), ...sidebarCommunity(), + ...sidebarNews(), ]; } @@ -162,3 +177,16 @@ function sidebarCommunity() { }, ]; } + +function sidebarNews() { + return [ + { + text: '📰 Latest News', + collapsible: true, + items: [ + { text: 'Announcements', link: '/news/announcements' }, + { text: 'Blog', link: '/news/blog' }, + ], + }, + ]; +} diff --git a/packages/mermaid/src/docs/.vitepress/theme/index.ts b/packages/mermaid/src/docs/.vitepress/theme/index.ts index 273880d91..0eebb82c5 100644 --- a/packages/mermaid/src/docs/.vitepress/theme/index.ts +++ b/packages/mermaid/src/docs/.vitepress/theme/index.ts @@ -2,7 +2,7 @@ import DefaultTheme from 'vitepress/theme'; import './custom.css'; // @ts-ignore import Mermaid from './Mermaid.vue'; -import { getRedirect } from './redirect'; +import { getRedirect } from './redirect.js'; export default { ...DefaultTheme, diff --git a/packages/mermaid/src/docs/.vitepress/theme/redirect.spec.ts b/packages/mermaid/src/docs/.vitepress/theme/redirect.spec.ts index ec0404264..3d88913d1 100644 --- a/packages/mermaid/src/docs/.vitepress/theme/redirect.spec.ts +++ b/packages/mermaid/src/docs/.vitepress/theme/redirect.spec.ts @@ -2,7 +2,7 @@ // Update https://github.com/mermaid-js/mermaid/blob/18c27c6f1d0537a738cbd95898df301b83c38ffc/packages/mermaid/src/docs.mts#L246 once fixed import { expect, test } from 'vitest'; -import { getRedirect } from './redirect'; +import { getRedirect } from './redirect.js'; test.each([ // Old docs, localhost diff --git a/packages/mermaid/src/docs/ecosystem/integrations.md b/packages/mermaid/src/docs/ecosystem/integrations.md index ac8f2659b..a0a904425 100644 --- a/packages/mermaid/src/docs/ecosystem/integrations.md +++ b/packages/mermaid/src/docs/ecosystem/integrations.md @@ -17,6 +17,7 @@ They also serve as proof of concept, for the variety of things that can be built - [Mermaid Flow Visual Editor](https://www.mermaidflow.app) (**Native support**) - [Deepdwn](https://billiam.itch.io/deepdwn) (**Native support**) - [Joplin](https://joplinapp.org) (**Native support**) +- [Slab](https://slab.com) (**Native support**) - [Swimm](https://swimm.io) (**Native support**) - [Notion](https://notion.so) (**Native support**) - [Observable](https://observablehq.com/@observablehq/mermaid) (**Native support**) diff --git a/packages/mermaid/src/docs/index.md b/packages/mermaid/src/docs/index.md index b0b38bd79..59b6607fe 100644 --- a/packages/mermaid/src/docs/index.md +++ b/packages/mermaid/src/docs/index.md @@ -23,15 +23,15 @@ features: - title: ➕ Easy to use! details: Easily create and render detailed diagrams and charts with the Mermaid Live Editor. link: https://mermaid.live/ - - title: 🎥 Video Tutorials! - details: Curated list of video tutorials and examples created by the community. - link: ../../config/Tutorials.html - title: 🧩 Integrations available! details: Use Mermaid with your favorite applications, check out the integrations list. link: ../../ecosystem/integrations.md - title: 🏆 Award winning! details: 2019 JavaScript Open Source Award winner for "The Most Exciting Use of Technology". link: https://osawards.com/javascript/2019 + - title: 🥰 Mermaid + Mermaid Chart + details: Mermaid Chart is a major supporter of the Mermaid project. + link: https://www.mermaidchart.com/ --- diff --git a/packages/mermaid/src/docs/intro/index.md b/packages/mermaid/src/docs/intro/index.md index 2e94e9f5c..e886b5f60 100644 --- a/packages/mermaid/src/docs/intro/index.md +++ b/packages/mermaid/src/docs/intro/index.md @@ -76,7 +76,7 @@ To Deploy Mermaid: ### [Mermaid API](../config/setup/README.md): -**To deploy mermaid without a bundler, one can insert a `script` tag with an absolute address and a `mermaid.initialize` call into the HTML like so:** +**To deploy mermaid without a bundler, insert a `script` tag with an absolute address and a `mermaid.initialize` call into the HTML using the following example:** ```html ``` -**Doing so will command the mermaid parser to look for the `
` or `
` tags with `class="mermaid"`. From these tags mermaid will try to read the diagram/chart definitions and render them into SVG charts.**
+**Doing so commands the mermaid parser to look for the `
` or `
` tags with `class="mermaid"`. From these tags, mermaid tries read the diagram/chart definitions and render them into SVG charts.**
 
-**Examples can be found at** [Other examples](../syntax/examples.md)
+**Examples can be found in** [Other examples](../syntax/examples.md)
 
 ## Sibling projects
 
diff --git a/packages/mermaid/src/docs/news/announcements.md b/packages/mermaid/src/docs/news/announcements.md
new file mode 100644
index 000000000..4dd07bf3b
--- /dev/null
+++ b/packages/mermaid/src/docs/news/announcements.md
@@ -0,0 +1,7 @@
+# Announcements
+
+## [Automatic text wrapping in flowcharts is here!](https://www.mermaidchart.com/blog/posts/automatic-text-wrapping-in-flowcharts-is-here)
+
+3 April 2023 · 3 mins
+
+Markdown Strings reduce the hassle # Starting from v10.
diff --git a/packages/mermaid/src/docs/news/blog.md b/packages/mermaid/src/docs/news/blog.md
new file mode 100644
index 000000000..b835bbe35
--- /dev/null
+++ b/packages/mermaid/src/docs/news/blog.md
@@ -0,0 +1,25 @@
+# Blog
+
+## [Mermaid Chart officially launched with sharable diagram links and presentation mode](https://www.mermaidchart.com/blog/posts/mermaid-chart-officially-launched-with-sharable-diagram-links-and-presentation-mode/)
+
+27 March 2023 · 2 mins
+
+Exciting news for all Mermaid OSS fans: Mermaid Chart has officially launched with Mermaid Chart!
+
+## [If you're not excited about ChatGPT, then you're not being creative](https://www.mermaidchart.com/blog/posts/if-youre-not-excited-about-chatgpt-then-youre-not-being-creative-enough/)
+
+8 March 2023 · 9 mins
+
+The hype around AI in general and ChatGPT, in particular, is so intense that it’s very understandable to assume the hype train is driving straight toward the trough of disillusionment.
+
+## [Flow charts are O(n)2 complex, so don't go over 100 connections](https://www.mermaidchart.com/blog/posts/flow-charts-are-on2-complex-so-dont-go-over-100-connections/)
+
+1 March 2023 · 12 mins
+
+Flowchart design is a game of balance: Read about the importance of dialling in the right level of detail and how to manage complexity in large flowcharts.
+
+## [Busting the myth that developers can't write](https://www.mermaidchart.com/blog/posts/busting-the-myth-that-developers-cant-write/)
+
+10 February 2023 · 10 mins
+
+Busting the myth that developers can’t write # It’s an annoying stereotype that developers don’t know how to write, speak, and otherwise communicate.
diff --git a/packages/mermaid/src/docs/public/favicon.ico b/packages/mermaid/src/docs/public/favicon.ico
index d41818c5b..05d8a737b 100644
Binary files a/packages/mermaid/src/docs/public/favicon.ico and b/packages/mermaid/src/docs/public/favicon.ico differ
diff --git a/packages/mermaid/src/docs/syntax/flowchart.md b/packages/mermaid/src/docs/syntax/flowchart.md
index 8e73f597b..936607cbd 100644
--- a/packages/mermaid/src/docs/syntax/flowchart.md
+++ b/packages/mermaid/src/docs/syntax/flowchart.md
@@ -446,6 +446,31 @@ flowchart LR
   B1 --> B2
 ```
 
+## Markdown Strings
+
+The "Markdown Strings" feature enhances flowcharts and mind maps by offering a more versatile string type, which supports text formatting options such as bold and italics, and automatically wraps text within labels.
+
+```mermaid-example
+%%{init: {"flowchart": {"htmlLabels": false}} }%%
+flowchart LR
+subgraph "One"
+  a("`The **cat**
+  in the hat`") -- "edge label" --> b{{"`The **dog** in the hog`"}}
+end
+subgraph "`**Two**`"
+  c("`The **cat**
+  in the hat`") -- "`Bold **edge label**`" --> d("The dog in the hog")
+end
+```
+
+Formatting:
+
+- For bold text, use double asterisks \*\* before and after the text.
+- For italics, use single asterisks \* before and after the text.
+- With traditional strings, you needed to add 
tags for text to wrap in nodes. However, markdown strings automatically wrap text when it becomes too long and allows you to start a new line by simply using a newline character instead of a
tag. + +This feature is applicable to node labels, edge labels, and subgraph labels. + ## Interaction It is possible to bind a click event to a node, the click can lead to either a javascript callback or to a link which will be opened in a new browser tab. **Note**: This functionality is disabled when using `securityLevel='strict'` and enabled when using `securityLevel='loose'`. diff --git a/packages/mermaid/src/docs/syntax/gantt.md b/packages/mermaid/src/docs/syntax/gantt.md index eaa07c707..422358d3e 100644 --- a/packages/mermaid/src/docs/syntax/gantt.md +++ b/packages/mermaid/src/docs/syntax/gantt.md @@ -374,3 +374,24 @@ Beginner's tip—a full example using interactive links in an html context: ``` + +## Examples + +### Bar chart (using gantt chart) + +```mermaid-example +gantt + title Git Issues - days since last update + dateFormat X + axisFormat %s + section Issue19062 + 71 : 0, 71 + section Issue19401 + 36 : 0, 36 + section Issue193 + 34 : 0, 34 + section Issue7441 + 9 : 0, 9 + section Issue1300 + 5 : 0, 5 +``` diff --git a/packages/mermaid/src/docs/syntax/mindmap.md b/packages/mermaid/src/docs/syntax/mindmap.md index 1cb1f68d4..64a25821a 100644 --- a/packages/mermaid/src/docs/syntax/mindmap.md +++ b/packages/mermaid/src/docs/syntax/mindmap.md @@ -162,6 +162,25 @@ Root C ``` +## Markdown Strings + +The "Markdown Strings" feature enhances mind maps by offering a more versatile string type, which supports text formatting options such as bold and italics, and automatically wraps text within labels. + +```mermaid-example +mindmap + id1["`**Root** with +a second line +Unicode works too: 🤓`"] + id2["`The dog in **the** hog... a *very long text* that wraps to a new line`"] + id3[Regular labels still works] +``` + +Formatting: + +- For bold text, use double asterisks \*\* before and after the text. +- For italics, use single asterisks \* before and after the text. +- With traditional strings, you needed to add
tags for text to wrap in nodes. However, markdown strings automatically wrap text when it becomes too long and allows you to start a new line by simply using a newline character instead of a
tag. + ## Integrating with your library/website. Mindmap uses the experimental lazy loading & async rendering features which could change in the future. From version 9.4.0 this diagram is included in mermaid but use lazy loading in order to keep the size of mermaid down. This is important in order to be able to add additional diagrams going forward. diff --git a/packages/mermaid/src/docs/vite.config.ts b/packages/mermaid/src/docs/vite.config.ts index 179e271fd..63d2aa5fa 100644 --- a/packages/mermaid/src/docs/vite.config.ts +++ b/packages/mermaid/src/docs/vite.config.ts @@ -1,5 +1,6 @@ import { defineConfig, type PluginOption, searchForWorkspaceRoot } from 'vite'; import path from 'path'; +// @ts-expect-error This package has an incorrect export map. import { SearchPlugin } from 'vitepress-plugin-search'; const virtualModuleId = 'virtual:mermaid-config'; diff --git a/packages/mermaid/src/logger.ts b/packages/mermaid/src/logger.ts index 44b98315c..da5e8a221 100644 --- a/packages/mermaid/src/logger.ts +++ b/packages/mermaid/src/logger.ts @@ -2,7 +2,7 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-empty-function */ /* eslint-disable no-console */ -import dayjs from 'dayjs'; +import dayjs from 'dayjs/esm/index.js'; export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal'; diff --git a/packages/mermaid/src/mermaid.spec.ts b/packages/mermaid/src/mermaid.spec.ts index 36490798b..e27428545 100644 --- a/packages/mermaid/src/mermaid.spec.ts +++ b/packages/mermaid/src/mermaid.spec.ts @@ -1,7 +1,7 @@ -import mermaid from './mermaid'; -import { mermaidAPI } from './mermaidAPI'; -import './diagram-api/diagram-orchestration'; -import { addDiagrams } from './diagram-api/diagram-orchestration'; +import mermaid from './mermaid.js'; +import { mermaidAPI } from './mermaidAPI.js'; +import './diagram-api/diagram-orchestration.js'; +import { addDiagrams } from './diagram-api/diagram-orchestration.js'; import { beforeAll, describe, it, expect, vi } from 'vitest'; beforeAll(async () => { @@ -9,7 +9,7 @@ beforeAll(async () => { }); const spyOn = vi.spyOn; -vi.mock('./mermaidAPI'); +vi.mock('./mermaidAPI.js'); afterEach(() => { vi.clearAllMocks(); diff --git a/packages/mermaid/src/mermaid.ts b/packages/mermaid/src/mermaid.ts index 4b02adb1c..30297e7b5 100644 --- a/packages/mermaid/src/mermaid.ts +++ b/packages/mermaid/src/mermaid.ts @@ -2,21 +2,21 @@ * Web page integration module for the mermaid framework. It uses the mermaidAPI for mermaid * functionality and to render the diagrams to svg code! */ -import dedent from 'ts-dedent'; -import { MermaidConfig } from './config.type'; -import { log } from './logger'; -import utils from './utils'; -import { mermaidAPI, ParseOptions, RenderResult } from './mermaidAPI'; +import { dedent } from 'ts-dedent'; +import { MermaidConfig } from './config.type.js'; +import { log } from './logger.js'; +import utils from './utils.js'; +import { mermaidAPI, ParseOptions, RenderResult } from './mermaidAPI.js'; import { registerLazyLoadedDiagrams, loadRegisteredDiagrams, detectType, -} from './diagram-api/detectType'; -import type { ParseErrorFunction } from './Diagram'; -import { isDetailedError } from './utils'; -import type { DetailedError } from './utils'; -import { ExternalDiagramDefinition } from './diagram-api/types'; -import { UnknownDiagramError } from './errors'; +} from './diagram-api/detectType.js'; +import type { ParseErrorFunction } from './Diagram.js'; +import { isDetailedError } from './utils.js'; +import type { DetailedError } from './utils.js'; +import { ExternalDiagramDefinition } from './diagram-api/types.js'; +import { UnknownDiagramError } from './errors.js'; export type { MermaidConfig, diff --git a/packages/mermaid/src/mermaidAPI.spec.ts b/packages/mermaid/src/mermaidAPI.spec.ts index edd2d47bb..48121f36e 100644 --- a/packages/mermaid/src/mermaidAPI.spec.ts +++ b/packages/mermaid/src/mermaidAPI.spec.ts @@ -4,14 +4,14 @@ import { vi } from 'vitest'; // ------------------------------------- // Mocks and mocking -import { MockedD3 } from './tests/MockedD3'; +import { MockedD3 } from './tests/MockedD3.js'; // Note: If running this directly from within an IDE, the mocks directory must be at packages/mermaid/mocks vi.mock('d3'); vi.mock('dagre-d3'); // mermaidAPI.spec.ts: -import * as accessibility from './accessibility'; // Import it this way so we can use spyOn(accessibility,...) +import * as accessibility from './accessibility.js'; // Import it this way so we can use spyOn(accessibility,...) vi.mock('./accessibility', () => ({ setA11yDiagramInfo: vi.fn(), addSVGa11yTitleDescription: vi.fn(), @@ -33,10 +33,10 @@ vi.mock('./diagrams/state/stateRenderer-v2'); // ------------------------------------- -import mermaid from './mermaid'; -import { MermaidConfig } from './config.type'; +import mermaid from './mermaid.js'; +import { MermaidConfig } from './config.type.js'; -import mermaidAPI, { removeExistingElements } from './mermaidAPI'; +import mermaidAPI, { removeExistingElements } from './mermaidAPI.js'; import { encodeEntities, decodeEntities, @@ -45,9 +45,9 @@ import { appendDivSvgG, cleanUpSvgCode, putIntoIFrame, -} from './mermaidAPI'; +} from './mermaidAPI.js'; -import assignWithDepth from './assignWithDepth'; +import assignWithDepth from './assignWithDepth.js'; // -------------- // Mocks @@ -58,7 +58,7 @@ vi.mock('./styles', () => { default: vi.fn().mockReturnValue(' .userStyle { font-weight:bold; }'), }; }); -import getStyles from './styles'; +import getStyles from './styles.js'; vi.mock('stylis', () => { return { diff --git a/packages/mermaid/src/mermaidAPI.ts b/packages/mermaid/src/mermaidAPI.ts index b015994ac..5e9d0ead6 100644 --- a/packages/mermaid/src/mermaidAPI.ts +++ b/packages/mermaid/src/mermaidAPI.ts @@ -15,21 +15,21 @@ import { select } from 'd3'; import { compile, serialize, stringify } from 'stylis'; // @ts-ignore: TODO Fix ts errors import { version } from '../package.json'; -import * as configApi from './config'; -import { addDiagrams } from './diagram-api/diagram-orchestration'; -import { Diagram, getDiagramFromText } from './Diagram'; -import errorRenderer from './diagrams/error/errorRenderer'; -import { attachFunctions } from './interactionDb'; -import { log, setLogLevel } from './logger'; -import getStyles from './styles'; -import theme from './themes'; -import utils, { directiveSanitizer } from './utils'; +import * as configApi from './config.js'; +import { addDiagrams } from './diagram-api/diagram-orchestration.js'; +import { Diagram, getDiagramFromText } from './Diagram.js'; +import errorRenderer from './diagrams/error/errorRenderer.js'; +import { attachFunctions } from './interactionDb.js'; +import { log, setLogLevel } from './logger.js'; +import getStyles from './styles.js'; +import theme from './themes/index.js'; +import utils, { directiveSanitizer } from './utils.js'; import DOMPurify from 'dompurify'; -import { MermaidConfig } from './config.type'; -import { evaluate } from './diagrams/common/common'; +import { MermaidConfig } from './config.type.js'; +import { evaluate } from './diagrams/common/common.js'; import isEmpty from 'lodash-es/isEmpty.js'; -import { setA11yDiagramInfo, addSVGa11yTitleDescription } from './accessibility'; -import { parseDirective } from './directiveUtils'; +import { setA11yDiagramInfo, addSVGa11yTitleDescription } from './accessibility.js'; +import { parseDirective } from './directiveUtils.js'; // diagram names that support classDef statements const CLASSDEF_DIAGRAMS = [ @@ -406,6 +406,12 @@ const render = async function ( // clean up text CRLFs text = text.replace(/\r\n?/g, '\n'); // parser problems on CRLF ignore all CR and leave LF;; + // clean up html tags so that all attributes use single quotes, parser throws error on double quotes + text = text.replace( + /<(\w+)([^>]*)>/g, + (match, tag, attributes) => '<' + tag + attributes.replace(/="([^"]*)"/g, "='$1'") + '>' + ); + const idSelector = '#' + id; const iFrameID = 'i' + id; const iFrameID_selector = '#' + iFrameID; diff --git a/packages/mermaid/src/rendering-util/createText.js b/packages/mermaid/src/rendering-util/createText.js index 1097cd0df..a5438b562 100644 --- a/packages/mermaid/src/rendering-util/createText.js +++ b/packages/mermaid/src/rendering-util/createText.js @@ -1,9 +1,9 @@ import { select } from 'd3'; -import { log } from '../logger'; -import { getConfig } from '../config'; -import { evaluate } from '../diagrams/common/common'; -import { decodeEntities } from '../mermaidAPI'; -import { markdownToHTML, markdownToLines } from '../rendering-util/handle-markdown-text'; +import { log } from '../logger.js'; +import { getConfig } from '../config.js'; +import { evaluate } from '../diagrams/common/common.js'; +import { decodeEntities } from '../mermaidAPI.js'; +import { markdownToHTML, markdownToLines } from '../rendering-util/handle-markdown-text.js'; /** * @param dom * @param styleFn @@ -152,26 +152,8 @@ function updateTextContentAndStyles(tspan, wrappedLine) { .attr('font-style', word.type === 'em' ? 'italic' : 'normal') .attr('class', 'text-inner-tspan') .attr('font-weight', word.type === 'strong' ? 'bold' : 'normal'); - const special = [ - '<', - '>', - '&', - '"', - "'", - '.', - ',', - ':', - ';', - '!', - '?', - '(', - ')', - '[', - ']', - '{', - '}', - ]; - if (index !== 0 && special.includes(word.content)) { + const special = ['"', "'", '.', ',', ':', ';', '!', '?', '(', ')', '[', ']', '{', '}']; + if (index === 0) { innerTspan.text(word.content); } else { innerTspan.text(' ' + word.content); @@ -225,7 +207,17 @@ export const createText = ( return vertexNode; } else { const structuredText = markdownToLines(text); - + const special = ['"', "'", '.', ',', ':', ';', '!', '?', '(', ')', '[', ']', '{', '}']; + let lastWord; + structuredText.forEach((line) => { + line.forEach((word) => { + if (special.includes(word.content) && lastWord) { + lastWord.content += word.content; + word.content = ''; + } + lastWord = word; + }); + }); const svgLabel = createFormattedText(width, el, structuredText, addSvgBackground); return svgLabel; } diff --git a/packages/mermaid/src/rendering-util/handle-markdown-text.js b/packages/mermaid/src/rendering-util/handle-markdown-text.js index cd79623fe..93704b2fe 100644 --- a/packages/mermaid/src/rendering-util/handle-markdown-text.js +++ b/packages/mermaid/src/rendering-util/handle-markdown-text.js @@ -38,6 +38,8 @@ export function markdownToLines(markdown) { currentLine++; lines.push([]); } + + // textLine.split(/ (?=[^!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]+)/).forEach((word) => { textLine.split(' ').forEach((word) => { if (word) { lines[currentLine].push({ content: word, type: parentType || 'normal' }); diff --git a/packages/mermaid/src/setupGraphViewbox.js b/packages/mermaid/src/setupGraphViewbox.js index 14929d3d7..c4aeeceea 100644 --- a/packages/mermaid/src/setupGraphViewbox.js +++ b/packages/mermaid/src/setupGraphViewbox.js @@ -1,4 +1,4 @@ -import { log } from './logger'; +import { log } from './logger.js'; /** * Applies d3 attributes diff --git a/packages/mermaid/src/setupGraphViewbox.spec.js b/packages/mermaid/src/setupGraphViewbox.spec.js index 6b5c3e210..36154e2df 100644 --- a/packages/mermaid/src/setupGraphViewbox.spec.js +++ b/packages/mermaid/src/setupGraphViewbox.spec.js @@ -1,8 +1,8 @@ -import utils from './utils'; -import assignWithDepth from './assignWithDepth'; -import { detectType } from './diagram-api/detectType'; -import { addDiagrams } from './diagram-api/diagram-orchestration'; -import { calculateSvgSizeAttrs } from './setupGraphViewbox'; +import utils from './utils.js'; +import assignWithDepth from './assignWithDepth.js'; +import { detectType } from './diagram-api/detectType.js'; +import { addDiagrams } from './diagram-api/diagram-orchestration.js'; +import { calculateSvgSizeAttrs } from './setupGraphViewbox.js'; addDiagrams(); describe('when calculating SVG size', function () { diff --git a/packages/mermaid/src/styles.spec.ts b/packages/mermaid/src/styles.spec.ts new file mode 100644 index 000000000..f827c611b --- /dev/null +++ b/packages/mermaid/src/styles.spec.ts @@ -0,0 +1,120 @@ +import { vi } from 'vitest'; + +// @ts-expect-error This module has no TypeScript types +import { validate } from 'csstree-validator'; +import { compile, serialize, stringify } from 'stylis'; + +import { getConfig } from './config.js'; +import theme from './themes/index.js'; + +/** + * Import the getStyles function from each diagram. + * + * Unfortunately, we can't use the `diagrams/*?/*Detector.ts` functions, + * because many of the diagrams have a circular dependency import error + * (they import mermaidAPI.js, which imports diagramOrchestrator.js, which causes a loop) + */ +import c4 from './diagrams/c4/styles.js'; +import classDiagram from './diagrams/class/styles.js'; +import flowchart from './diagrams/flowchart/styles.js'; +import flowchartElk from './diagrams/flowchart/elk/styles.js'; +import er from './diagrams/er/styles.js'; +import error from './diagrams/error/styles.js'; +import git from './diagrams/git/styles.js'; +import gantt from './diagrams/gantt/styles.js'; +import info from './diagrams/info/styles.js'; +import pie from './diagrams/pie/styles.js'; +import requirement from './diagrams/requirement/styles.js'; +import sequence from './diagrams/sequence/styles.js'; +import state from './diagrams/state/styles.js'; +import journey from './diagrams/user-journey/styles.js'; +import timeline from './diagrams/timeline/styles.js'; +import mindmap from './diagrams/mindmap/styles.js'; +import themes from './themes/index.js'; + +async function checkValidStylisCSSStyleSheet(stylisString: string) { + const cssString = serialize(compile(`#my-svg-id{${stylisString}}`), stringify); + const errors = validate(cssString, 'this-file-was-created-by-tests.css') as Error[]; + + const unexpectedErrors = errors.filter((error) => { + const cssErrorsToIgnore = [ + // Valid in SVG2, see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/rx + // Ideally, we'd remove this, since some browsers do not support SVG2. + 'Unknown property `rx`', + // Valid in SVG2, see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/ry + 'Unknown property `ry`', + // TODO: I'm pretty sure that even in SVG2, this isn't allowed to be a CSS + // attribute. + 'Unknown property `dy`', + ]; + return !cssErrorsToIgnore.some((cssErrorToIgnore) => error.message.match(cssErrorToIgnore)); + }); + + if (unexpectedErrors.length > 0) { + throw new Error( + `The given CSS string was invalid: ${errors}.\n\n` + + 'Copy the below CSS into https://jigsaw.w3.org/css-validator/validator to help debug where the invalid CSS is:\n\n' + + `Original CSS value was ${cssString}` + ); + } +} + +describe('styles', () => { + beforeEach(() => { + // resets the styles added to addStylesForDiagram() + vi.resetModules(); + }); + + describe('getStyles', () => { + test('should return a valid style for an empty type', async () => { + const { default: getStyles, addStylesForDiagram } = await import('./styles.js'); + + const diagramType = 'my-custom-mocked-type-with-no-styles'; + const myTypeGetStylesFunc = vi.fn().mockReturnValue(''); + + addStylesForDiagram(diagramType, myTypeGetStylesFunc); + + const styles = getStyles(diagramType, '', getConfig().themeVariables); + + await checkValidStylisCSSStyleSheet(styles); + }); + + /** + * Test CSS for each diagram type and each theme. + */ + for (const themeId of Object.keys(theme) as (keyof typeof theme)[]) { + for (const [diagramId, getDiagramStyles] of Object.entries({ + c4, + classDiagram, + er, + error, + flowchart, + flowchartElk, + gantt, + git, + info, + journey, + mindmap, + pie, + requirement, + sequence, + state, + timeline, + })) { + test(`should return a valid style for diagram ${diagramId} and theme ${themeId}`, async () => { + const { default: getStyles, addStylesForDiagram } = await import('./styles.js'); + + addStylesForDiagram(diagramId, getDiagramStyles); + const styles = getStyles( + diagramId, + '', + // @ts-expect-error This will probably be broken until we create a proper Themes type. + themes[themeId].getThemeVariables() + ); + + await checkValidStylisCSSStyleSheet(styles); + }); + } + } + }); +}); diff --git a/packages/mermaid/src/styles.ts b/packages/mermaid/src/styles.ts index 588c26cb1..a6e752475 100644 --- a/packages/mermaid/src/styles.ts +++ b/packages/mermaid/src/styles.ts @@ -1,5 +1,5 @@ -import type { FlowChartStyleOptions } from './diagrams/flowchart/styles'; -import { log } from './logger'; +import type { FlowChartStyleOptions } from './diagrams/flowchart/styles.js'; +import { log } from './logger.js'; const themes: Record = {}; diff --git a/packages/mermaid/src/tests/MockedD3.ts b/packages/mermaid/src/tests/MockedD3.ts index ccf21a269..6d8d721e0 100644 --- a/packages/mermaid/src/tests/MockedD3.ts +++ b/packages/mermaid/src/tests/MockedD3.ts @@ -1,4 +1,4 @@ -import type {} from '@vitest/spy/dist/index'; +import type {} from '@vitest/spy/dist/index.js'; /** * This is a mocked/stubbed version of the d3 Selection type. Each of the main functions are all diff --git a/packages/mermaid/src/themes/index.js b/packages/mermaid/src/themes/index.js index 94e2b95a4..6ffe6274d 100644 --- a/packages/mermaid/src/themes/index.js +++ b/packages/mermaid/src/themes/index.js @@ -1,8 +1,8 @@ -import { getThemeVariables as baseThemeVariables } from './theme-base'; -import { getThemeVariables as darkThemeVariables } from './theme-dark'; -import { getThemeVariables as defaultThemeVariables } from './theme-default'; -import { getThemeVariables as forestThemeVariables } from './theme-forest'; -import { getThemeVariables as neutralThemeVariables } from './theme-neutral'; +import { getThemeVariables as baseThemeVariables } from './theme-base.js'; +import { getThemeVariables as darkThemeVariables } from './theme-dark.js'; +import { getThemeVariables as defaultThemeVariables } from './theme-default.js'; +import { getThemeVariables as forestThemeVariables } from './theme-forest.js'; +import { getThemeVariables as neutralThemeVariables } from './theme-neutral.js'; export default { base: { diff --git a/packages/mermaid/src/themes/theme-base.js b/packages/mermaid/src/themes/theme-base.js index 01f8a9c0b..6e26e12a2 100644 --- a/packages/mermaid/src/themes/theme-base.js +++ b/packages/mermaid/src/themes/theme-base.js @@ -1,9 +1,9 @@ import { darken, lighten, adjust, invert } from 'khroma'; -import { mkBorder } from './theme-helpers'; +import { mkBorder } from './theme-helpers.js'; import { oldAttributeBackgroundColorEven, oldAttributeBackgroundColorOdd, -} from './erDiagram-oldHardcodedValues'; +} from './erDiagram-oldHardcodedValues.js'; class Theme { constructor() { @@ -46,8 +46,12 @@ class Theme { this.secondaryTextColor = this.secondaryTextColor || invert(this.secondaryColor); this.tertiaryTextColor = this.tertiaryTextColor || invert(this.tertiaryColor); this.lineColor = this.lineColor || invert(this.background); + this.arrowheadColor = this.arrowheadColor || invert(this.background); this.textColor = this.textColor || this.primaryTextColor; + // TODO: should this instead default to secondaryBorderColor? + this.border2 = this.border2 || this.tertiaryBorderColor; + /* Flowchart variables */ this.nodeBkg = this.nodeBkg || this.primaryColor; this.mainBkg = this.mainBkg || this.primaryColor; @@ -219,7 +223,7 @@ class Theme { /* requirement-diagram */ this.requirementBackground = this.requirementBackground || this.primaryColor; this.requirementBorderColor = this.requirementBorderColor || this.primaryBorderColor; - this.requirementBorderSize = this.requirementBorderSize || this.primaryBorderColor; + this.requirementBorderSize = this.requirementBorderSize || '1'; this.requirementTextColor = this.requirementTextColor || this.primaryTextColor; this.relationColor = this.relationColor || this.lineColor; this.relationLabelBackground = diff --git a/packages/mermaid/src/themes/theme-dark.js b/packages/mermaid/src/themes/theme-dark.js index 9585a2e27..7298f3a0c 100644 --- a/packages/mermaid/src/themes/theme-dark.js +++ b/packages/mermaid/src/themes/theme-dark.js @@ -1,5 +1,5 @@ import { invert, lighten, darken, rgba, adjust } from 'khroma'; -import { mkBorder } from './theme-helpers'; +import { mkBorder } from './theme-helpers.js'; class Theme { constructor() { @@ -64,6 +64,7 @@ class Theme { this.sectionBkgColor = darken('#EAE8D9', 30); this.altSectionBkgColor = 'calculated'; this.sectionBkgColor2 = '#EAE8D9'; + this.excludeBkgColor = darken(this.sectionBkgColor, 10); this.taskBorderColor = rgba(255, 255, 255, 70); this.taskBkgColor = 'calculated'; this.taskTextColor = 'calculated'; @@ -81,9 +82,8 @@ class Theme { this.todayLineColor = '#DB5757'; /* C4 Context Diagram variables */ - - this.personBorder = 'calculated'; - this.personBkg = 'calculated'; + this.personBorder = this.primaryBorderColor; + this.personBkg = this.mainBkg; /* state colors */ this.labelColor = 'calculated'; @@ -232,7 +232,7 @@ class Theme { /* requirement-diagram */ this.requirementBackground = this.requirementBackground || this.primaryColor; this.requirementBorderColor = this.requirementBorderColor || this.primaryBorderColor; - this.requirementBorderSize = this.requirementBorderSize || this.primaryBorderColor; + this.requirementBorderSize = this.requirementBorderSize || '1'; this.requirementTextColor = this.requirementTextColor || this.primaryTextColor; this.relationColor = this.relationColor || this.lineColor; this.relationLabelBackground = @@ -257,6 +257,14 @@ class Theme { this.gitInv5 = this.gitInv5 || invert(this.git5); this.gitInv6 = this.gitInv6 || invert(this.git6); this.gitInv7 = this.gitInv7 || invert(this.git7); + this.gitBranchLabel0 = this.gitBranchLabel0 || invert(this.labelTextColor); + this.gitBranchLabel1 = this.gitBranchLabel1 || this.labelTextColor; + this.gitBranchLabel2 = this.gitBranchLabel2 || this.labelTextColor; + this.gitBranchLabel3 = this.gitBranchLabel3 || invert(this.labelTextColor); + this.gitBranchLabel4 = this.gitBranchLabel4 || this.labelTextColor; + this.gitBranchLabel5 = this.gitBranchLabel5 || this.labelTextColor; + this.gitBranchLabel6 = this.gitBranchLabel6 || this.labelTextColor; + this.gitBranchLabel7 = this.gitBranchLabel7 || this.labelTextColor; this.tagLabelColor = this.tagLabelColor || this.primaryTextColor; this.tagLabelBackground = this.tagLabelBackground || this.primaryColor; diff --git a/packages/mermaid/src/themes/theme-default.js b/packages/mermaid/src/themes/theme-default.js index c91029de3..b29e93862 100644 --- a/packages/mermaid/src/themes/theme-default.js +++ b/packages/mermaid/src/themes/theme-default.js @@ -1,9 +1,9 @@ import { invert, lighten, rgba, adjust, darken } from 'khroma'; -import { mkBorder } from './theme-helpers'; +import { mkBorder } from './theme-helpers.js'; import { oldAttributeBackgroundColorEven, oldAttributeBackgroundColorOdd, -} from './erDiagram-oldHardcodedValues'; +} from './erDiagram-oldHardcodedValues.js'; class Theme { constructor() { @@ -109,9 +109,8 @@ class Theme { this.todayLineColor = 'red'; /* C4 Context Diagram variables */ - - this.personBorder = 'calculated'; - this.personBkg = 'calculated'; + this.personBorder = this.primaryBorderColor; + this.personBkg = this.mainBkg; /* state colors */ this.labelColor = 'black'; @@ -251,7 +250,7 @@ class Theme { /* requirement-diagram */ this.requirementBackground = this.requirementBackground || this.primaryColor; this.requirementBorderColor = this.requirementBorderColor || this.primaryBorderColor; - this.requirementBorderSize = this.requirementBorderSize || this.primaryBorderColor; + this.requirementBorderSize = this.requirementBorderSize || '1'; this.requirementTextColor = this.requirementTextColor || this.primaryTextColor; this.relationColor = this.relationColor || this.lineColor; this.relationLabelBackground = this.relationLabelBackground || this.labelBackground; diff --git a/packages/mermaid/src/themes/theme-forest.js b/packages/mermaid/src/themes/theme-forest.js index 96d6c35c1..dbff069b7 100644 --- a/packages/mermaid/src/themes/theme-forest.js +++ b/packages/mermaid/src/themes/theme-forest.js @@ -1,9 +1,9 @@ import { darken, lighten, adjust, invert } from 'khroma'; -import { mkBorder } from './theme-helpers'; +import { mkBorder } from './theme-helpers.js'; import { oldAttributeBackgroundColorEven, oldAttributeBackgroundColorOdd, -} from './erDiagram-oldHardcodedValues'; +} from './erDiagram-oldHardcodedValues.js'; class Theme { constructor() { @@ -83,9 +83,8 @@ class Theme { this.todayLineColor = 'red'; /* C4 Context Diagram variables */ - - this.personBorder = 'calculated'; - this.personBkg = 'calculated'; + this.personBorder = this.primaryBorderColor; + this.personBkg = this.mainBkg; /* state colors */ this.labelColor = 'black'; @@ -94,6 +93,15 @@ class Theme { this.errorTextColor = '#552222'; } updateColors() { + /* Sequence Diagram variables */ + this.actorBorder = darken(this.mainBkg, 20); + this.actorBkg = this.mainBkg; + this.labelBoxBkgColor = this.actorBkg; + this.labelTextColor = this.actorTextColor; + this.loopTextColor = this.actorTextColor; + this.noteBorderColor = this.border2; + this.noteTextColor = this.actorTextColor; + /* Each color-set will have a background, a foreground and a border color */ this.cScale0 = this.cScale0 || this.primaryColor; this.cScale1 = this.cScale1 || this.secondaryColor; @@ -145,16 +153,6 @@ class Theme { this.clusterBorder = this.border2; this.defaultLinkColor = this.lineColor; - /* Sequence Diagram variables */ - - this.actorBorder = darken(this.mainBkg, 20); - this.actorBkg = this.mainBkg; - this.labelBoxBkgColor = this.actorBkg; - this.labelTextColor = this.actorTextColor; - this.loopTextColor = this.actorTextColor; - this.noteBorderColor = this.border2; - this.noteTextColor = this.actorTextColor; - /* Gantt chart variables */ this.taskBorderColor = this.border1; @@ -220,7 +218,7 @@ class Theme { /* requirement-diagram */ this.requirementBackground = this.requirementBackground || this.primaryColor; this.requirementBorderColor = this.requirementBorderColor || this.primaryBorderColor; - this.requirementBorderSize = this.requirementBorderSize || this.primaryBorderColor; + this.requirementBorderSize = this.requirementBorderSize || '1'; this.requirementTextColor = this.requirementTextColor || this.primaryTextColor; this.relationColor = this.relationColor || this.lineColor; this.relationLabelBackground = this.relationLabelBackground || this.edgeLabelBackground; @@ -262,6 +260,14 @@ class Theme { this.gitInv5 = this.gitInv5 || invert(this.git5); this.gitInv6 = this.gitInv6 || invert(this.git6); this.gitInv7 = this.gitInv7 || invert(this.git7); + this.gitBranchLabel0 = this.gitBranchLabel0 || invert(this.labelTextColor); + this.gitBranchLabel1 = this.gitBranchLabel1 || this.labelTextColor; + this.gitBranchLabel2 = this.gitBranchLabel2 || this.labelTextColor; + this.gitBranchLabel3 = this.gitBranchLabel3 || invert(this.labelTextColor); + this.gitBranchLabel4 = this.gitBranchLabel4 || this.labelTextColor; + this.gitBranchLabel5 = this.gitBranchLabel5 || this.labelTextColor; + this.gitBranchLabel6 = this.gitBranchLabel6 || this.labelTextColor; + this.gitBranchLabel7 = this.gitBranchLabel7 || this.labelTextColor; this.tagLabelColor = this.tagLabelColor || this.primaryTextColor; this.tagLabelBackground = this.tagLabelBackground || this.primaryColor; diff --git a/packages/mermaid/src/themes/theme-neutral.js b/packages/mermaid/src/themes/theme-neutral.js index 8bb5ff693..bc0725276 100644 --- a/packages/mermaid/src/themes/theme-neutral.js +++ b/packages/mermaid/src/themes/theme-neutral.js @@ -1,9 +1,9 @@ import { invert, darken, lighten, adjust } from 'khroma'; -import { mkBorder } from './theme-helpers'; +import { mkBorder } from './theme-helpers.js'; import { oldAttributeBackgroundColorEven, oldAttributeBackgroundColorOdd, -} from './erDiagram-oldHardcodedValues'; +} from './erDiagram-oldHardcodedValues.js'; // const Color = require ( 'khroma/dist/color' ).default // Color.format.hex.stringify(Color.parse('hsl(210, 66.6666666667%, 95%)')); // => "#EAF2FB" @@ -95,9 +95,8 @@ class Theme { this.todayLineColor = 'calculated'; /* C4 Context Diagram variables */ - - this.personBorder = 'calculated'; - this.personBkg = 'calculated'; + this.personBorder = this.primaryBorderColor; + this.personBkg = this.mainBkg; /* state colors */ this.labelColor = 'black'; @@ -109,6 +108,22 @@ class Theme { this.secondBkg = lighten(this.contrast, 55); this.border2 = this.contrast; + /* Sequence Diagram variables */ + + this.actorBorder = lighten(this.border1, 23); + this.actorBkg = this.mainBkg; + this.actorTextColor = this.text; + this.actorLineColor = this.lineColor; + this.signalColor = this.text; + this.signalTextColor = this.text; + this.labelBoxBkgColor = this.actorBkg; + this.labelBoxBorderColor = this.actorBorder; + this.labelTextColor = this.text; + this.loopTextColor = this.text; + this.noteBorderColor = '#999'; + this.noteBkgColor = '#666'; + this.noteTextColor = '#fff'; + /* Color Scale */ /* Each color-set will have a background, a foreground and a border color */ @@ -162,22 +177,6 @@ class Theme { this.defaultLinkColor = this.lineColor; this.titleColor = this.text; - /* Sequence Diagram variables */ - - this.actorBorder = lighten(this.border1, 23); - this.actorBkg = this.mainBkg; - this.actorTextColor = this.text; - this.actorLineColor = this.lineColor; - this.signalColor = this.text; - this.signalTextColor = this.text; - this.labelBoxBkgColor = this.actorBkg; - this.labelBoxBorderColor = this.actorBorder; - this.labelTextColor = this.text; - this.loopTextColor = this.text; - this.noteBorderColor = '#999'; - this.noteBkgColor = '#666'; - this.noteTextColor = '#fff'; - /* Gantt chart variables */ this.sectionBkgColor = lighten(this.contrast, 30); @@ -250,7 +249,7 @@ class Theme { /* requirement-diagram */ this.requirementBackground = this.requirementBackground || this.primaryColor; this.requirementBorderColor = this.requirementBorderColor || this.primaryBorderColor; - this.requirementBorderSize = this.requirementBorderSize || this.primaryBorderColor; + this.requirementBorderSize = this.requirementBorderSize || '1'; this.requirementTextColor = this.requirementTextColor || this.primaryTextColor; this.relationColor = this.relationColor || this.lineColor; this.relationLabelBackground = this.relationLabelBackground || this.edgeLabelBackground; diff --git a/packages/mermaid/src/utils.spec.js b/packages/mermaid/src/utils.spec.js index 0f0bc1e92..ae3234cb9 100644 --- a/packages/mermaid/src/utils.spec.js +++ b/packages/mermaid/src/utils.spec.js @@ -1,10 +1,10 @@ import { vi } from 'vitest'; -import utils from './utils'; -import assignWithDepth from './assignWithDepth'; -import { detectType } from './diagram-api/detectType'; -import { addDiagrams } from './diagram-api/diagram-orchestration'; +import utils from './utils.js'; +import assignWithDepth from './assignWithDepth.js'; +import { detectType } from './diagram-api/detectType.js'; +import { addDiagrams } from './diagram-api/diagram-orchestration.js'; import memoize from 'lodash-es/memoize.js'; -import { MockedD3 } from './tests/MockedD3'; +import { MockedD3 } from './tests/MockedD3.js'; addDiagrams(); diff --git a/packages/mermaid/src/utils.ts b/packages/mermaid/src/utils.ts index 0c4b9d1a8..6f824062d 100644 --- a/packages/mermaid/src/utils.ts +++ b/packages/mermaid/src/utils.ts @@ -24,12 +24,12 @@ import { curveStepBefore, select, } from 'd3'; -import common from './diagrams/common/common'; -import { configKeys } from './defaultConfig'; -import { log } from './logger'; -import { detectType } from './diagram-api/detectType'; -import assignWithDepth from './assignWithDepth'; -import { MermaidConfig } from './config.type'; +import common from './diagrams/common/common.js'; +import { configKeys } from './defaultConfig.js'; +import { log } from './logger.js'; +import { detectType } from './diagram-api/detectType.js'; +import assignWithDepth from './assignWithDepth.js'; +import { MermaidConfig } from './config.type.js'; import memoize from 'lodash-es/memoize.js'; // Effectively an enum of the supported curve types, accessible by name diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 792b7f890..1847115cd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,7 @@ importers: '@commitlint/cli': ^17.2.0 '@commitlint/config-conventional': ^17.2.0 '@cspell/eslint-plugin': ^6.14.2 + '@rollup/plugin-typescript': ^11.0.0 '@types/cors': ^2.8.13 '@types/eslint': ^8.4.10 '@types/express': ^4.17.17 @@ -65,6 +66,7 @@ importers: '@commitlint/cli': 17.2.0 '@commitlint/config-conventional': 17.2.0 '@cspell/eslint-plugin': 6.14.2 + '@rollup/plugin-typescript': 11.0.0_typescript@4.8.4 '@types/cors': 2.8.13 '@types/eslint': 8.4.10 '@types/express': 4.17.17 @@ -138,6 +140,7 @@ importers: coveralls: ^3.1.1 cpy-cli: ^4.2.0 cspell: ^6.14.3 + csstree-validator: ^3.0.0 cytoscape: ^3.23.0 cytoscape-cose-bilkent: ^4.1.0 cytoscape-fcose: ^2.1.0 @@ -206,6 +209,7 @@ importers: coveralls: 3.1.1 cpy-cli: 4.2.0 cspell: 6.14.3 + csstree-validator: 3.0.0 globby: 13.1.2 jison: 0.4.18 js-base64: 3.7.2 @@ -2356,7 +2360,7 @@ packages: react: 16.14.0 react-dom: 16.14.0 dependencies: - '@types/react': 18.0.28 + '@types/react': 18.0.33 react: 16.14.0 react-dom: 16.14.0_react@16.14.0 dev: false @@ -2403,6 +2407,38 @@ packages: resolution: {integrity: sha512-a5Sab1C4/icpTZVzZc5Ghpz88yQtGOyNqYXcZgOssB2uuAr+wF/MvN6bgtW32q7HHrvBki+BsZ0OuNv6EV3K9g==} dev: true + /@rollup/plugin-typescript/11.0.0_typescript@4.8.4: + resolution: {integrity: sha512-goPyCWBiimk1iJgSTgsehFD5OOFHiAknrRJjqFCudcW8JtWiBlK284Xnn4flqMqg6YAjVG/EE+3aVzrL5qNSzQ==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^2.14.0||^3.0.0 + tslib: '*' + typescript: '>=3.7.0' + peerDependenciesMeta: + rollup: + optional: true + tslib: + optional: true + dependencies: + '@rollup/pluginutils': 5.0.2 + resolve: 1.22.1 + typescript: 4.8.4 + dev: true + + /@rollup/pluginutils/5.0.2: + resolution: {integrity: sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0 + peerDependenciesMeta: + rollup: + optional: true + dependencies: + '@types/estree': 1.0.0 + estree-walker: 2.0.2 + picomatch: 2.3.1 + dev: true + /@sideway/address/4.1.4: resolution: {integrity: sha512-7vwq+rOHVWjyXxVlR76Agnvhy8I9rpzjosTESvmhNeXOXdZZB15Fl+TI9x1SiHZH5Jv2wTGduSxFDIaq0m3DUw==} dependencies: @@ -2956,12 +2992,12 @@ packages: resolution: {integrity: sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==} dev: true - /@types/react/18.0.28: - resolution: {integrity: sha512-RD0ivG1kEztNBdoAK7lekI9M+azSnitIn85h4iOiaLjaTrMjzslhaqCGaI4IyCJ1RljWiLCEu4jyrLLgqxBTew==} + /@types/react/18.0.33: + resolution: {integrity: sha512-sHxzVxeanvQyQ1lr8NSHaj0kDzcNiGpILEVt69g9S31/7PfMvNCKLKcsHw4lYKjs3cGNJjXSP4mYzX43QlnjNA==} dependencies: '@types/prop-types': 15.7.5 - '@types/scheduler': 0.16.2 - csstype: 3.1.1 + '@types/scheduler': 0.16.3 + csstype: 3.1.2 dev: false /@types/responselike/1.0.0: @@ -2981,8 +3017,8 @@ packages: rollup: 2.79.1 dev: true - /@types/scheduler/0.16.2: - resolution: {integrity: sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==} + /@types/scheduler/0.16.3: + resolution: {integrity: sha512-5cJ8CB4yAx7BH1oMvdU0Jh9lrEXyPkar6F9G/ERswkCuvP4KQZfZkSjcMbAICCpQTN4OuZn8tz0HiKv9TGZgrQ==} dev: false /@types/semver/7.3.12: @@ -4065,7 +4101,7 @@ packages: /axios/0.21.4_debug@4.3.2: resolution: {integrity: sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==} dependencies: - follow-redirects: 1.15.2_debug@4.3.4 + follow-redirects: 1.15.2_debug@4.3.2 transitivePeerDependencies: - debug dev: true @@ -4509,6 +4545,13 @@ packages: jsonlint: 1.6.0 dev: true + /clap/3.1.1: + resolution: {integrity: sha512-vp42956Ax06WwaaheYEqEOgXZ3VKJxgccZ0gJL0HpyiupkIS9RVJFo5eDU1BPeQAOqz+cclndZg4DCqG1sJReQ==} + engines: {node: ^12.20.0 || ^14.13.0 || >=15.0.0, npm: '>=7.0.0'} + dependencies: + ansi-colors: 4.1.3 + dev: true + /clean-regexp/1.0.0: resolution: {integrity: sha512-GfisEZEJvzKrmGWkvfhgzcz/BllN1USeqD2V6tg14OAOgaCD2Z/PUEuxnAZ/nPvmaHRG7a8y77p1T/IRQ4D1Hw==} engines: {node: '>=4'} @@ -5142,6 +5185,14 @@ packages: source-map: 0.6.1 dev: true + /css-tree/2.3.1: + resolution: {integrity: sha512-6Fv1DV/TYw//QF5IzQdqsNDjx/wc8TrMBZsqjL9eW01tWb7R7k/mq+/VXfJCl7SoD5emsJop9cOByJZfs8hYIw==} + engines: {node: ^10 || ^12.20.0 || ^14.13.0 || >=15.0.0} + dependencies: + mdn-data: 2.0.30 + source-map-js: 1.0.2 + dev: true + /cssom/0.3.8: resolution: {integrity: sha512-b0tGHbfegbhPJpxpiBPU2sCkigAqtM9O121le6bbOlgyV+NyGyCmVfJ6QW9eRjz8CpNfWEOYBIMIGRYkLwsIYg==} dev: true @@ -5157,12 +5208,22 @@ packages: cssom: 0.3.8 dev: true + /csstree-validator/3.0.0: + resolution: {integrity: sha512-Y5OSq3wI0Xz6L7DCgJQtQ97U+v99SkX9r663VjpvUMJPhEr0A149OxiAGqcnokB5bt81irgnMudspBzujzqn0w==} + engines: {node: ^12.20.0 || ^14.13.0 || >=15.0.0, npm: '>=7.0.0'} + hasBin: true + dependencies: + clap: 3.1.1 + css-tree: 2.3.1 + resolve: 1.22.1 + dev: true + /csstype/2.6.21: resolution: {integrity: sha512-Z1PhmomIfypOpoMjRQB70jfvy/wxT50qW08YXO5lMIJkrdq4yOTR+AW7FqutScmB9NkLwxo+jU+kZLbofZZq/w==} dev: true - /csstype/3.1.1: - resolution: {integrity: sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw==} + /csstype/3.1.2: + resolution: {integrity: sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==} dev: false /cypress-image-snapshot/4.0.1_cypress@12.5.1+jest@29.3.1: @@ -6641,6 +6702,28 @@ packages: resolution: {integrity: sha512-XGozTsMPYkm+6b5QL3Z9wQcJjNYxp0CYn3U1gO7dwD6PAqU1SVWZxI9CCg3z+ml3YfqdPnrBehaBrnH2AGKbNA==} dev: true + /follow-redirects/1.15.2: + resolution: {integrity: sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==} + engines: {node: '>=4.0'} + peerDependencies: + debug: '*' + peerDependenciesMeta: + debug: + 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 + /follow-redirects/1.15.2_debug@4.3.4: resolution: {integrity: sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==} engines: {node: '>=4.0'} @@ -7190,7 +7273,7 @@ packages: engines: {node: '>=8.0.0'} dependencies: eventemitter3: 4.0.7 - follow-redirects: 1.15.2_debug@4.3.4 + follow-redirects: 1.15.2 requires-port: 1.0.0 transitivePeerDependencies: - debug @@ -8728,6 +8811,10 @@ packages: resolution: {integrity: sha512-n4Vypz/DZgwo0iMHLQL49dJzlp7YtAJP+N07MZHpjPf/5XJuHUWstviF4Mn2jEiR/GNmtnRRqnwsXExk3igfFA==} dev: true + /mdn-data/2.0.30: + resolution: {integrity: sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA==} + dev: true + /mdn-data/2.0.6: resolution: {integrity: sha512-rQvjv71olwNHgiTbfPZFkJtjNMciWgswYeciZhtvWLO8bmX3TnhyA62I6sTWOyZssWHJJjY6/KiWwqQsWWsqOA==} dev: true diff --git a/tsconfig.json b/tsconfig.json index c66d62784..29c790cbb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,9 +27,8 @@ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ /* Modules */ - "module": "es2022" /* Specify what module code is generated. */, + "module": "nodenext", // "rootDir": "./packages" /* Specify the root folder within your source files. */, - "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */, // "baseUrl": "./src" /* Specify the base directory to resolve non-relative module names. */, // "paths": {} /* Specify a set of entries that re-map imports to additional lookup locations. */, // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ diff --git a/vite.config.ts b/vite.config.ts index e79295425..dfd0431bb 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,11 +1,16 @@ -import jison from './.vite/jisonPlugin'; +import jison from './.vite/jisonPlugin.js'; +import typescript from '@rollup/plugin-typescript'; import { defineConfig } from 'vitest/config'; export default defineConfig({ resolve: { - extensions: ['.jison', '.js', '.ts', '.json'], + extensions: ['.js'], }, - plugins: [jison()], + plugins: [ + jison(), + // @ts-expect-error According to the type definitions, rollup plugins are incompatible with vite + typescript({ compilerOptions: { declaration: false } }), + ], test: { environment: 'jsdom', globals: true,