diff --git a/.npmrc b/.npmrc index 289684302..4c2f52b3b 100644 --- a/.npmrc +++ b/.npmrc @@ -1,3 +1,2 @@ auto-install-peers=true strict-peer-dependencies=false -use-inline-specifiers-lockfile-format=true 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 d8e06b62f..941e1fd18 100644 --- a/README.md +++ b/README.md @@ -240,6 +240,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 90ad677ea..2e7a1cbd7 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 df1fac0cd..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', () => { @@ -10,7 +10,6 @@ describe('Entity Relationship Diagram', () => { `, { logLevel: 1 } ); - cy.get('svg'); }); it('should render an ER diagram with a recursive relationship', () => { @@ -23,7 +22,6 @@ describe('Entity Relationship Diagram', () => { `, { logLevel: 1 } ); - cy.get('svg'); }); it('should render an ER diagram with multiple relationships between the same two entities', () => { @@ -35,7 +33,6 @@ describe('Entity Relationship Diagram', () => { `, { logLevel: 1 } ); - cy.get('svg'); }); it('should render a cyclical ER diagram', () => { @@ -48,7 +45,6 @@ describe('Entity Relationship Diagram', () => { `, { logLevel: 1 } ); - cy.get('svg'); }); it('should render a not-so-simple ER diagram', () => { @@ -66,7 +62,6 @@ describe('Entity Relationship Diagram', () => { `, { logLevel: 1 } ); - cy.get('svg'); }); it('should render multiple ER diagrams', () => { @@ -85,7 +80,6 @@ describe('Entity Relationship Diagram', () => { ], { logLevel: 1 } ); - cy.get('svg'); }); it('should render an ER diagram with blank or empty labels', () => { @@ -98,7 +92,6 @@ describe('Entity Relationship Diagram', () => { `, { logLevel: 1 } ); - cy.get('svg'); }); it('should render an ER diagrams when useMaxWidth is true (default)', () => { @@ -151,7 +144,6 @@ describe('Entity Relationship Diagram', () => { `, { er: { useMaxWidth: false } } ); - cy.get('svg'); }); it('should render entities with and without attributes', () => { @@ -164,7 +156,6 @@ describe('Entity Relationship Diagram', () => { `, { logLevel: 1 } ); - cy.get('svg'); }); it('should render entities with generic and array attributes', () => { @@ -179,7 +170,6 @@ describe('Entity Relationship Diagram', () => { `, { logLevel: 1 } ); - cy.get('svg'); }); it('should render entities with length in attributes type', () => { @@ -193,7 +183,6 @@ describe('Entity Relationship Diagram', () => { `, { logLevel: 1 } ); - cy.get('svg'); }); it('should render entities and attributes with big and small entity names', () => { @@ -209,7 +198,6 @@ describe('Entity Relationship Diagram', () => { `, { logLevel: 1 } ); - cy.get('svg'); }); it('should render entities with keys', () => { @@ -228,7 +216,6 @@ describe('Entity Relationship Diagram', () => { `, { logLevel: 1 } ); - cy.get('svg'); }); it('should render entities with comments', () => { @@ -247,7 +234,6 @@ describe('Entity Relationship Diagram', () => { `, { logLevel: 1 } ); - cy.get('svg'); }); it('should render entities with keys and comments', () => { @@ -267,7 +253,6 @@ describe('Entity Relationship Diagram', () => { `, { logLevel: 1 } ); - cy.get('svg'); }); it('should render entities with aliases', () => { @@ -285,7 +270,6 @@ describe('Entity Relationship Diagram', () => { `, { logLevel: 1 } ); - cy.get('svg'); }); it('1433: should render a simple ER diagram with a title', () => { diff --git a/cypress/integration/rendering/errorDiagram.spec.js b/cypress/integration/rendering/errorDiagram.spec.js new file mode 100644 index 000000000..e837565d3 --- /dev/null +++ b/cypress/integration/rendering/errorDiagram.spec.js @@ -0,0 +1,45 @@ +import { imgSnapshotTest } from '../../helpers/util'; + +describe('Error Diagrams', () => { + beforeEach(() => { + cy.on('uncaught:exception', (err) => { + expect(err.message).to.include('Parse error'); + // return false to prevent the error from + // failing this test + return false; + }); + }); + + it('should render a simple ER diagram', () => { + imgSnapshotTest( + ` + error + `, + { logLevel: 1 } + ); + }); + + it('should render error diagram for actual errors', () => { + imgSnapshotTest( + ` + flowchart TD + A[Christmas] --|Get money| B(Go shopping) + `, + { logLevel: 1 } + ); + }); + + it('should render error for wrong ER diagram', () => { + imgSnapshotTest( + ` + erDiagram + ATLAS-ORGANIZATION ||--|{ ATLAS-PROJECTS : "has many" + ATLAS-PROJECTS ||--|{ MONGODB-CLUSTERS : "has many" + ATLAS-PROJECTS ||--|{ ATLAS-TEAMS : "has many" + MONGODB-CLUSTERS ||..|{ + ATLAS-TEAMS ||..|{ + `, + { logLevel: 1 } + ); + }); +}); diff --git a/cypress/integration/rendering/flowchart-elk.spec.js b/cypress/integration/rendering/flowchart-elk.spec.js index 414037651..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', () => { @@ -684,4 +684,149 @@ A --> B { titleTopMargin: 0 } ); }); + describe('Markdown strings flowchart-elk (#4220)', () => { + describe('html labels', () => { + it('With styling and classes', () => { + imgSnapshotTest( + `%%{init: {"flowchart": {"htmlLabels": true}} }%% +flowchart-elk LR + A:::someclass --> B["\`The **cat** in the hat\`"]:::someclass + id1(Start)-->id2(Stop) + style id1 fill:#f9f,stroke:#333,stroke-width:4px + style id2 fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5 + classDef someclass fill:#f96 +`, + { titleTopMargin: 0 } + ); + }); + it('With formatting in a node', () => { + imgSnapshotTest( + `%%{init: {"flowchart": {"htmlLabels": true}} }%% +flowchart-elk LR + a{"\`The **cat** in the hat\`"} -- 1o --> b + a -- 2o --> c + a -- 3o --> d + g --2i--> a + d --1i--> a + h --3i -->a + b --> d(The dog in the hog) + c --> d +`, + { titleTopMargin: 0 } + ); + }); + it('New line in node and formatted edge label', () => { + imgSnapshotTest( + `%%{init: {"flowchart": {"htmlLabels": true}} }%% +flowchart-elk LR +b("\`The dog in **the** hog.(1) +NL\`") --"\`1o **bold**\`"--> c +`, + { titleTopMargin: 0 } + ); + }); + it('Wrapping long text with a new line', () => { + imgSnapshotTest( + `%%{init: {"flowchart": {"htmlLabels": true}} }%% +flowchart-elk LR +b(\`The dog in **the** hog.(1).. a a a a *very long text* about it +Word! + +Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. \`) --> c + +`, + { titleTopMargin: 0 } + ); + }); + it('Sub graphs and markdown strings', () => { + imgSnapshotTest( + `%%{init: {"flowchart": {"htmlLabels": true}} }%% +flowchart-elk LR +subgraph "One" + a("\`The **cat** + in the hat\`") -- "1o" --> b{{"\`The **dog** in the hog\`"}} +end +subgraph "\`**Two**\`" + c("\`The **cat** + in the hat\`") -- "\`1o **ipa**\`" --> d("The dog in the hog") +end + +`, + { titleTopMargin: 0 } + ); + }); + }); + + describe('svg text labels', () => { + it('With styling and classes', () => { + imgSnapshotTest( + `%%{init: {"flowchart": {"htmlLabels": false}} }%% +flowchart-elk LR + A:::someclass --> B["\`The **cat** in the hat\`"]:::someclass + id1(Start)-->id2(Stop) + style id1 fill:#f9f,stroke:#333,stroke-width:4px + style id2 fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5 + classDef someclass fill:#f96 +`, + { titleTopMargin: 0 } + ); + }); + it('With formatting in a node', () => { + imgSnapshotTest( + `%%{init: {"flowchart": {"htmlLabels": false}} }%% +flowchart-elk LR + a{"\`The **cat** in the hat\`"} -- 1o --> b + a -- 2o --> c + a -- 3o --> d + g --2i--> a + d --1i--> a + h --3i -->a + b --> d(The dog in the hog) + c --> d +`, + { titleTopMargin: 0 } + ); + }); + it('New line in node and formatted edge label', () => { + imgSnapshotTest( + `%%{init: {"flowchart": {"htmlLabels": false}} }%% +flowchart-elk LR +b("\`The dog in **the** hog.(1) +NL\`") --"\`1o **bold**\`"--> c +`, + { titleTopMargin: 0 } + ); + }); + it('Wrapping long text with a new line', () => { + imgSnapshotTest( + `%%{init: {"flowchart": {"htmlLabels": false}} }%% +flowchart-elk LR +b("\`The dog in **the** hog.(1).. a a a a *very long text* about it +Word! + +Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. \`") --> c + +`, + { titleTopMargin: 0 } + ); + }); + it('Sub graphs and markdown strings', () => { + imgSnapshotTest( + `%%{init: {"flowchart": {"htmlLabels": false}} }%% +flowchart-elk LR +subgraph "One" + a("\`The **cat** + in the hat\`") -- "1o" --> b{{"\`The **dog** in the hog\`"}} +end +subgraph "\`**Two**\`" + c("\`The **cat** + in the hat\`") -- "\`1o **ipa**\`" --> d("The dog in the hog") +end + +`, + { titleTopMargin: 0 } + ); + }); + }); + }); }); diff --git a/cypress/integration/rendering/flowchart-v2.spec.js b/cypress/integration/rendering/flowchart-v2.spec.js index abdb22265..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,4 +685,159 @@ 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', () => { + imgSnapshotTest( + `%%{init: {"flowchart": {"htmlLabels": true}} }%% +flowchart LR + A:::someclass --> B["\`The **cat** in the hat\`"]:::someclass + id1(Start)-->id2(Stop) + style id1 fill:#f9f,stroke:#333,stroke-width:4px + style id2 fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5 + classDef someclass fill:#f96 +`, + { titleTopMargin: 0 } + ); + }); + it('With formatting in a node', () => { + imgSnapshotTest( + `%%{init: {"flowchart": {"htmlLabels": true}} }%% +flowchart LR + a{"\`The **cat** in the hat\`"} -- 1o --> b + a -- 2o --> c + a -- 3o --> d + g --2i--> a + d --1i--> a + h --3i -->a + b --> d(The dog in the hog) + c --> d +`, + { titleTopMargin: 0 } + ); + }); + it('New line in node and formatted edge label', () => { + imgSnapshotTest( + `%%{init: {"flowchart": {"htmlLabels": true}} }%% +flowchart LR +b("\`The dog in **the** hog.(1) +NL\`") --"\`1o **bold**\`"--> c +`, + { titleTopMargin: 0 } + ); + }); + it('Wrapping long text with a new line', () => { + imgSnapshotTest( + `%%{init: {"flowchart": {"htmlLabels": true}} }%% +flowchart LR +b("\`The dog in **the** hog.(1).. a a a a *very long text* about it +Word! + +Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. \`") --> c + +`, + { titleTopMargin: 0 } + ); + }); + it('Sub graphs and markdown strings', () => { + imgSnapshotTest( + `%%{init: {"flowchart": {"htmlLabels": true}} }%% +flowchart LR +subgraph "One" + a("\`The **cat** + in the hat\`") -- "1o" --> b{{"\`The **dog** in the hog\`"}} +end +subgraph "\`**Two**\`" + c("\`The **cat** + in the hat\`") -- "\`1o **ipa**\`" --> d("The dog in the hog") +end + +`, + { titleTopMargin: 0 } + ); + }); + }); + + describe('svg text labels', () => { + it('With styling and classes', () => { + imgSnapshotTest( + `%%{init: {"flowchart": {"htmlLabels": false}} }%% +flowchart LR + A:::someclass --> B["\`The **cat** in the hat\`"]:::someclass + id1(Start)-->id2(Stop) + style id1 fill:#f9f,stroke:#333,stroke-width:4px + style id2 fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5 + classDef someclass fill:#f96 +`, + { titleTopMargin: 0 } + ); + }); + it('With formatting in a node', () => { + imgSnapshotTest( + `%%{init: {"flowchart": {"htmlLabels": false}} }%% +flowchart LR + a{"\`The **cat** in the hat\`"} -- 1o --> b + a -- 2o --> c + a -- 3o --> d + g --2i--> a + d --1i--> a + h --3i -->a + b --> d(The dog in the hog) + c --> d +`, + { titleTopMargin: 0 } + ); + }); + it('New line in node and formatted edge label', () => { + imgSnapshotTest( + `%%{init: {"flowchart": {"htmlLabels": false}} }%% +flowchart LR +b("\`The dog in **the** hog.(1) +NL\`") --"\`1o **bold**\`"--> c +`, + { titleTopMargin: 0 } + ); + }); + it('Wrapping long text with a new line', () => { + imgSnapshotTest( + `%%{init: {"flowchart": {"htmlLabels": false}} }%% +flowchart LR +b("\`The dog in **the** hog.(1).. a a a a *very long text* about it +Word! + +Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. \`") --> c + +`, + { titleTopMargin: 0 } + ); + }); + it('Sub graphs and markdown strings', () => { + imgSnapshotTest( + `%%{init: {"flowchart": {"htmlLabels": false}} }%% +flowchart LR +subgraph "One" + a("\`The **cat** + in the hat\`") -- "1o" --> b{{"\`The **dog** in the hog\`"}} +end +subgraph "\`**Two**\`" + c("\`The **cat** + in the hat\`") -- "\`1o **ipa**\`" --> d("The dog in the hog") +end + +`, + { titleTopMargin: 0 } + ); + }); + }); + }); }); 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/gantt.spec.js b/cypress/integration/rendering/gantt.spec.js index c0156eee3..cb65f73b0 100644 --- a/cypress/integration/rendering/gantt.spec.js +++ b/cypress/integration/rendering/gantt.spec.js @@ -133,6 +133,24 @@ describe('Gantt diagram', () => { ); }); + it('should default to showing today marker', () => { + // This test only works if the environment thinks today is 1010-10-10 + imgSnapshotTest( + ` + gantt + title Show today marker (vertical line should be visible) + dateFormat YYYY-MM-DD + axisFormat %d + %% Should default to being on + %% todayMarker on + section Section1 + Yesterday: 1010-10-09, 1d + Today: 1010-10-10, 1d + `, + {} + ); + }); + it('should hide today marker', () => { imgSnapshotTest( ` @@ -142,7 +160,8 @@ describe('Gantt diagram', () => { axisFormat %d todayMarker off section Section1 - Today: 1, -1h + Yesterday: 1010-10-09, 1d + Today: 1010-10-10, 1d `, {} ); @@ -157,7 +176,8 @@ describe('Gantt diagram', () => { axisFormat %d todayMarker stroke-width:5px,stroke:#00f,opacity:0.5 section Section1 - Today: 1, -1h + Yesterday: 1010-10-09, 1d + Today: 1010-10-10, 1d `, {} ); @@ -435,4 +455,39 @@ describe('Gantt diagram', () => { { gantt: { topAxis: true } } ); }); + + it('should render when compact is true', () => { + imgSnapshotTest( + ` + --- + displayMode: compact + --- + gantt + title GANTT compact + dateFormat HH:mm:ss + axisFormat %Hh%M + + section DB Clean + Clean: 12:00:00, 10m + Clean: 12:30:00, 12m + Clean: 13:00:00, 8m + Clean: 13:30:00, 9m + Clean: 14:00:00, 13m + Clean: 14:30:00, 10m + Clean: 15:00:00, 11m + + section Sessions + A: 12:00:00, 63m + B: 12:30:00, 12m + C: 13:05:00, 12m + D: 13:06:00, 33m + E: 13:15:00, 55m + F: 13:20:00, 12m + G: 13:32:00, 18m + H: 13:50:00, 20m + I: 14:10:00, 10m + `, + {} + ); + }); }); diff --git a/cypress/integration/rendering/mindmap.spec.ts b/cypress/integration/rendering/mindmap.spec.ts index 4663f6225..94b3f9ca0 100644 --- a/cypress/integration/rendering/mindmap.spec.ts +++ b/cypress/integration/rendering/mindmap.spec.ts @@ -223,5 +223,18 @@ mindmap shouldHaveRoot ); }); + describe('Markdown strings mindmaps (#4220)', () => { + it('Formatted label with linebreak and a wrapping label and emojis', () => { + imgSnapshotTest( + `mindmap + id1[\`**Start** with + a second line 😎\`] + id2[\`The dog in **the** hog... a *very long text* about it +Word!\`] +`, + { titleTopMargin: 0 } + ); + }); + }); /* The end */ }); 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 + + diff --git a/demos/gantt.html b/demos/gantt.html index 613dc8694..88f52ef5c 100644 --- a/demos/gantt.html +++ b/demos/gantt.html @@ -78,7 +78,7 @@ axisFormat %d/%m todayMarker off section Section1 - Today: 1, -01:00, 5min + Today: 1, 08-08-09-01:00, 5min
@@ -89,7 +89,7 @@ axisFormat %d/%m todayMarker stroke-width:5px,stroke:#00f,opacity:0.5 section Section1 - Today: 1, -01:00, 5min + Today: 1, 08-08-09-01:00, 5min
@@ -166,6 +166,37 @@
+
+    ---
+      displayMode: compact
+    ---
+    gantt
+    title GANTT compact
+    dateFormat  HH:mm:ss
+    axisFormat  %Hh%M
+
+    section DB Clean
+    Clean: 12:00:00, 10m
+    Clean: 12:30:00, 12m
+    Clean: 13:00:00, 8m
+    Clean: 13:30:00, 9m
+    Clean: 14:00:00, 13m
+    Clean: 14:30:00, 10m
+    Clean: 15:00:00, 11m
+
+    section Sessions
+    A: 12:00:00, 63m
+    B: 12:30:00, 12m
+    C: 13:05:00, 12m
+    D: 13:06:00, 33m
+    E: 13:15:00, 55m
+    F: 13:20:00, 12m
+    G: 13:32:00, 18m
+    H: 13:50:00, 20m
+    I: 14:10:00, 10m
+    
+
+ ``` -**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 c2c04f750..6f5b973e8 100644
--- a/docs/syntax/flowchart.md
+++ b/docs/syntax/flowchart.md
@@ -183,8 +183,6 @@ flowchart LR
 
 ### A hexagon node
 
-Code:
-
 ```mermaid-example
 flowchart LR
     id1{{This is the text in the box}}
@@ -712,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 6a7af3331..091cdeabe 100644 --- a/docs/syntax/gantt.md +++ b/docs/syntax/gantt.md @@ -257,9 +257,41 @@ The pattern is: More info in: +## Output in compact mode + +The compact mode allows you to display multiple tasks in the same row. Compact mode can be enabled for a gantt chart by setting the display mode of the graph via preceeding YAML settings. + +```mermaid-example +--- +displayMode: compact +--- +gantt + title A Gantt Diagram + dateFormat YYYY-MM-DD + + section Section + A task :a1, 2014-01-01, 30d + Another task :a2, 2014-01-20, 25d + Another one :a3, 2014-02-10, 20d +``` + +```mermaid +--- +displayMode: compact +--- +gantt + title A Gantt Diagram + dateFormat YYYY-MM-DD + + section Section + A task :a1, 2014-01-01, 30d + Another task :a2, 2014-01-20, 25d + Another one :a3, 2014-02-10, 20d +``` + ## Comments -Comments can be entered within a gantt chart, which will be ignored by the parser. Comments need to be on their own line and must be prefaced with `%%` (double percent signs). Any text after the start of the comment to the next newline will be treated as a comment, including any diagram syntax +Comments can be entered within a gantt chart, which will be ignored by the parser. Comments need to be on their own line and must be prefaced with `%%` (double percent signs). Any text after the start of the comment to the next newline will be treated as a comment, including any diagram syntax. ```mermaid-example gantt @@ -432,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 ad8aab77f..9687bbef7 100644 --- a/docs/syntax/mindmap.md +++ b/docs/syntax/mindmap.md @@ -224,7 +224,7 @@ mindmap C ``` -_These classes needs top be supplied by the site administrator._ +_These classes need to be supplied by the site administrator._ ## Unclear indentation @@ -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/docs/syntax/timeline.md b/docs/syntax/timeline.md index 58b12313d..f3db4bb59 100644 --- a/docs/syntax/timeline.md +++ b/docs/syntax/timeline.md @@ -8,7 +8,7 @@ > Timeline: This is an experimental diagram for now. The syntax and properties can change in future releases. The syntax is stable except for the icon integration which is the experimental part. -"A timeline is a type of diagram used to illustrate a chronology of events, dates, or periods of time. It is usually presented graphically to indicate the passing of time, and it is usually organized chronologically. A basic timeline presents a list of events in chronological order, usually using dates as markers. A timeline can also be used to show the relationship between events, such as the relationship between the events of a person's life. A timeline can also be used to show the relationship between events, such as the relationship between the events of a person's life." Wikipedia +"A timeline is a type of diagram used to illustrate a chronology of events, dates, or periods of time. It is usually presented graphically to indicate the passing of time, and it is usually organized chronologically. A basic timeline presents a list of events in chronological order, usually using dates as markers. A timeline can also be used to show the relationship between events, such as the relationship between the events of a person's life." Wikipedia ### An example of a timeline. @@ -213,7 +213,7 @@ However, if there is no section defined, then we have two possibilities: ``` -Note that this is no, section defined, and each time period and its corresponding events will have its own color scheme. +Note that there are no sections defined, and each time period and its corresponding events will have its own color scheme. 2. Disable the multiColor option using the `disableMultiColor` option. This will make all time periods and events follow the same color scheme. @@ -257,7 +257,7 @@ let us look at same example, where we have disabled the multiColor option. ### Customizing Color scheme -You can customize the color scheme using the `cScale0` to `cScale11` theme variables. Mermaid allows you to set unique colors for up-to 12, where `cScale0` variable will drive the value of the first section or time-period, `cScale1` will drive the value of the second section and so on. +You can customize the color scheme using the `cScale0` to `cScale11` theme variables. Mermaid allows you to set unique colors for up-to 12 sections, where `cScale0` variable will drive the value of the first section or time-period, `cScale1` will drive the value of the second section and so on. In case you have more than 12 sections, the color scheme will start to repeat. NOTE: Default values for these theme variables are picked from the selected theme. If you want to override the default values, you can use the `initialize` call to add your custom theme variable values. diff --git a/package.json b/package.json index 89de95949..0485d6f6e 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "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.29.0", + "packageManager": "pnpm@7.30.1", "keywords": [ "diagram", "markdown", @@ -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", @@ -112,6 +113,6 @@ "vitest": "^0.29.0" }, "volta": { - "node": "18.14.2" + "node": "18.15.0" } } 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 e40912c29..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", @@ -53,11 +53,12 @@ }, "dependencies": { "@braintree/sanitize-url": "^6.0.0", + "@khanacademy/simple-markdown": "^0.8.6", "cytoscape": "^3.23.0", "cytoscape-cose-bilkent": "^4.1.0", "cytoscape-fcose": "^2.1.0", "d3": "^7.4.0", - "dagre-d3-es": "7.0.9", + "dagre-d3-es": "7.0.10", "dayjs": "^1.11.7", "dompurify": "2.4.5", "elkjs": "^0.8.2", @@ -74,7 +75,7 @@ "@types/d3": "^7.4.0", "@types/dompurify": "^2.4.0", "@types/jsdom": "^21.0.0", - "@types/lodash-es": "^4.17.6", + "@types/lodash-es": "^4.17.7", "@types/micromatch": "^4.0.2", "@types/prettier": "^2.7.1", "@types/stylis": "^4.0.2", @@ -86,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 3010ce130..4fb329b28 100644 --- a/packages/mermaid/src/Diagram.ts +++ b/packages/mermaid/src/Diagram.ts @@ -1,10 +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 * 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; @@ -43,7 +44,10 @@ export class Diagram { // Similarly, we can't do this in getDiagramFromText() because some code // calls diagram.db.clear(), which would reset anything set by // extractFrontMatter(). - this.parser.parse = (text: string) => originalParse(extractFrontMatter(text, this.db)); + + this.parser.parse = (text: string) => + originalParse(cleanupComments(extractFrontMatter(text, this.db))); + this.parser.parser.yy = this.db; if (diagram.init) { diagram.init(cnf); 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 42ffde004..4e1e5141a 100644 --- a/packages/mermaid/src/commonDb.ts +++ b/packages/mermaid/src/commonDb.ts @@ -1,8 +1,9 @@ -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 = ''; + const sanitizeText = (txt: string): string => _sanitizeText(txt, getConfig()); export const clear = function (): void { @@ -36,10 +37,10 @@ export const getDiagramTitle = function (): string { }; export default { - setAccTitle, getAccTitle, + setAccTitle, + getDiagramTitle, setDiagramTitle, - getDiagramTitle: getDiagramTitle, getAccDescription, setAccDescription, clear, 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/config.type.ts b/packages/mermaid/src/config.type.ts index 157304149..545fdbbfb 100644 --- a/packages/mermaid/src/config.type.ts +++ b/packages/mermaid/src/config.type.ts @@ -335,6 +335,7 @@ export interface GanttDiagramConfig extends BaseDiagramConfig { axisFormat?: string; tickInterval?: string; topAxis?: boolean; + displayMode?: string; } export interface SequenceDiagramConfig extends BaseDiagramConfig { @@ -385,6 +386,7 @@ export interface FlowchartDiagramConfig extends BaseDiagramConfig { curve?: string; padding?: number; defaultRenderer?: string; + wrappingWidth?: number; } export interface FontConfig { diff --git a/packages/mermaid/src/dagre-wrapper/clusters.js b/packages/mermaid/src/dagre-wrapper/clusters.js index 57c3ff513..1ce716689 100644 --- a/packages/mermaid/src/dagre-wrapper/clusters.js +++ b/packages/mermaid/src/dagre-wrapper/clusters.js @@ -1,12 +1,13 @@ -import intersectRect from './intersect/intersect-rect'; -import { log } from '../logger'; -import createLabel from './createLabel'; +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.trace('Creating subgraph rect for ', node.id, node); + log.info('Creating subgraph rect for ', node.id, node); // Add outer g element const shapeSvg = parent @@ -17,12 +18,18 @@ const rect = (parent, node) => { // add the rect const rect = shapeSvg.insert('rect', ':first-child'); + const useHtmlLabels = evaluate(getConfig().flowchart.htmlLabels); + // Create the label and insert it after the rect const label = shapeSvg.insert('g').attr('class', 'cluster-label'); - const text = label - .node() - .appendChild(createLabel(node.labelText, node.labelStyle, undefined, true)); + // const text = label + // .node() + // .appendChild(createLabel(node.labelText, node.labelStyle, undefined, true)); + const text = + node.labelType === 'markdown' + ? createText(label, node.labelText, { style: node.labelStyle, useHtmlLabels }) + : label.node().appendChild(createLabel(node.labelText, node.labelStyle, undefined, true)); // Get the size of the label let bbox = text.getBBox(); @@ -56,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 - bbox.width / 2) + ', ' + (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 af5032096..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 @@ -41,7 +41,13 @@ function addHtmlLabel(node) { div.attr('xmlns', 'http://www.w3.org/1999/xhtml'); return fo.node(); } - +/** + * @param _vertexText + * @param style + * @param isTitle + * @param isNode + * @deprecated svg-util/createText instead + */ const createLabel = (_vertexText, style, isTitle, isNode) => { let vertexText = _vertexText || ''; if (typeof vertexText === 'object') { diff --git a/packages/mermaid/src/dagre-wrapper/edges.js b/packages/mermaid/src/dagre-wrapper/edges.js index f8c113694..1581658b0 100644 --- a/packages/mermaid/src/dagre-wrapper/edges.js +++ b/packages/mermaid/src/dagre-wrapper/edges.js @@ -1,9 +1,10 @@ -import { log } from '../logger'; -import createLabel from './createLabel'; +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 = {}; @@ -14,8 +15,17 @@ export const clear = () => { }; export const insertEdgeLabel = (elem, edge) => { + const useHtmlLabels = evaluate(getConfig().flowchart.htmlLabels); // Create the actual text element - const labelElement = createLabel(edge.label, edge.labelStyle); + const labelElement = + edge.labelType === 'markdown' + ? createText(elem, edge.label, { + style: edge.labelStyle, + useHtmlLabels, + addSvgBackground: true, + }) + : createLabel(edge.label, edge.labelStyle); + log.info('abc82', edge, edge.labelType); // Create outer g, edgeLabel, this will be positioned after graph layout const edgeLabel = elem.insert('g').attr('class', 'edgeLabel'); @@ -26,7 +36,7 @@ export const insertEdgeLabel = (elem, edge) => { // Center the label let bbox = labelElement.getBBox(); - if (evaluate(getConfig().flowchart.htmlLabels)) { + if (useHtmlLabels) { const div = labelElement.children[0]; const dv = select(labelElement); bbox = div.getBoundingClientRect(); 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 49b96b685..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,13 +310,19 @@ 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 + ); - log.trace('Classes = ', node.classes); // 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; const totalHeight = bbox.height + node.padding; rect @@ -324,6 +330,8 @@ const rect = (parent, node) => { .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 - halfPadding) .attr('y', -bbox.height / 2 - halfPadding) .attr('width', totalWidth) @@ -349,8 +357,8 @@ 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.trace('Classes = ', node.classes); // add the rect @@ -536,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; @@ -562,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 @@ -587,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'); @@ -623,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; @@ -973,7 +981,7 @@ const shapes = { let nodeElems = {}; -export const insertNode = (elem, node, dir) => { +export const insertNode = async (elem, node, dir) => { let newEl; let el; @@ -986,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) { @@ -1014,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 6de0da638..7ad412bdb 100644 --- a/packages/mermaid/src/dagre-wrapper/shapes/util.js +++ b/packages/mermaid/src/dagre-wrapper/shapes/util.js @@ -1,10 +1,13 @@ -import createLabel from '../createLabel'; -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 { @@ -27,9 +30,17 @@ export const labelHelper = (parent, node, _classes, isNode) => { labelText = typeof node.labelText === 'string' ? node.labelText : node.labelText[0]; } - const text = label - .node() - .appendChild( + const textNode = label.node(); + let text; + if (node.labelType === 'markdown') { + // text = textNode; + text = createText(label, sanitizeText(decodeEntities(labelText), getConfig()), { + useHtmlLabels, + width: node.width || getConfig().flowchart.wrappingWidth, + classes: 'markdown-node-label', + }); + } else { + text = textNode.appendChild( createLabel( sanitizeText(decodeEntities(labelText), getConfig()), node.labelStyle, @@ -37,23 +48,61 @@ export const labelHelper = (parent, node, _classes, isNode) => { 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 - label.attr('transform', 'translate(' + -bbox.width / 2 + ', ' + -bbox.height / 2 + ')'); - + 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 666efc364..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)].** @@ -258,6 +258,18 @@ const config: Partial = { * Default value: 'dagre-wrapper' */ defaultRenderer: 'dagre-wrapper', + /** + * | Parameter | Description | Type | Required | Values | + * | --------------- | ----------- | ------- | -------- | ----------------------- | + * | wrappingWidth | See notes | number | 4 | width of nodes where text is wrapped | + * + * **Notes:** + * + * When using markdown strings the text ius wrapped automatically, this + * value sets the max width of a text before it continues on a new line. + * Default value: 'dagre-wrapper' + */ + wrappingWidth: 200, }, /** The object containing configurations specific for sequence diagrams */ @@ -659,6 +671,17 @@ const config: Partial = { */ numberSectionStyles: 4, + /** + * | Parameter | Description | Type | Required | Values | + * | ----------- | ------------------------- | ------ | -------- | --------- | + * | displayMode | Controls the display mode | string | 4 | 'compact' | + * + * **Notes**: + * + * - **compact**: Enables displaying multiple tasks on the same row. + */ + displayMode: '', + /** * | Parameter | Description | Type | Required | Values | * | ---------- | ---------------------------- | ---- | -------- | ---------------- | @@ -684,7 +707,6 @@ const config: Partial = { * Default value: undefined */ tickInterval: undefined, - /** * | Parameter | Description | Type | Required | Values | * | ----------- | ----------- | ------- | -------- | ----------- | diff --git a/packages/mermaid/src/diagram-api/comments.spec.ts b/packages/mermaid/src/diagram-api/comments.spec.ts new file mode 100644 index 000000000..57a7d4a34 --- /dev/null +++ b/packages/mermaid/src/diagram-api/comments.spec.ts @@ -0,0 +1,94 @@ +// tests to check that comments are removed + +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 + A-->B +%% This is a comment +`; + expect(cleanupComments(text)).toMatchInlineSnapshot(` + "graph TD + A-->B + " + `); + }); + + it('should keep init statements when removing comments', () => { + const text = ` +%% This is a comment + +%% This is another comment +%%{init: {'theme': 'forest'}}%% +%%{ init: {'theme': 'space before init'}}%% +%%{init: {'theme': 'space after ending'}}%% +graph TD + A-->B + + B-->C +%% This is a comment +`; + expect(cleanupComments(text)).toMatchInlineSnapshot(` + "%%{init: {'theme': 'forest'}}%% + %%{ init: {'theme': 'space before init'}}%% + %%{init: {'theme': 'space after ending'}}%% + graph TD + A-->B + + B-->C + " + `); + }); + + it('should remove indented comments', () => { + const text = ` +%% This is a comment +graph TD + A-->B + %% This is a comment + C-->D +`; + expect(cleanupComments(text)).toMatchInlineSnapshot(` + "graph TD + A-->B + C-->D + " + `); + }); + + it('should remove empty newlines from start', () => { + const text = ` + + + + +%% This is a comment +graph TD + A-->B +`; + expect(cleanupComments(text)).toMatchInlineSnapshot(` + "graph TD + A-->B + " + `); + }); + + it('should remove comments at end of text with no newline', () => { + const text = ` +graph TD + A-->B +%% This is a comment`; + + expect(cleanupComments(text)).toMatchInlineSnapshot(` + "graph TD + A-->B + " + `); + }); +}); diff --git a/packages/mermaid/src/diagram-api/comments.ts b/packages/mermaid/src/diagram-api/comments.ts new file mode 100644 index 000000000..be39b0a0f --- /dev/null +++ b/packages/mermaid/src/diagram-api/comments.ts @@ -0,0 +1,8 @@ +/** + * Remove all lines starting with `%%` from the text that don't contain a `%%{` + * @param text - The text to remove comments from + * @returns cleaned text + */ +export const cleanupComments = (text: string): string => { + return text.trimStart().replace(/^\s*%%(?!{)[^\n]+\n?/gm, ''); +}; 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 73bfcf084..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 error from '../diagrams/error/errorDetector'; -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 = () => { @@ -28,6 +28,9 @@ export const addDiagrams = () => { // This is added here to avoid race-conditions. // We could optimize the loading logic somehow. hasLoadedDiagrams = true; + registerDiagram('error', errorDiagram, (text) => { + return text.toLowerCase().trim() === 'error'; + }); registerDiagram( '---', // --- diagram type may appear if YAML front-matter is not parsed correctly @@ -57,7 +60,6 @@ export const addDiagrams = () => { ); // Ordering of detectors is important. The first one to return true will be used. registerLazyLoadedDiagrams( - error, c4, classDiagramV2, classDiagram, 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 d6811388c..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'; @@ -11,6 +11,8 @@ export const frontMatterRegex = /^-{3}\s*[\n\r](.*?)[\n\r]-{3}\s*[\n\r]+/s; type FrontMatterMetadata = { title?: string; + // Allows custom display modes. Currently used for compact mode in gantt charts. + displayMode?: string; }; /** @@ -33,6 +35,10 @@ export function extractFrontMatter(text: string, db: DiagramDb): string { db.setDiagramTitle?.(parsed.title); } + if (parsed?.displayMode) { + db.setDisplayMode?.(parsed.displayMode); + } + return text.slice(matches[0].length); } else { return text; diff --git a/packages/mermaid/src/diagram-api/types.ts b/packages/mermaid/src/diagram-api/types.ts index 081136563..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; @@ -16,6 +16,7 @@ export interface InjectUtils { export interface DiagramDb { clear?: () => void; setDiagramTitle?: (title: string) => void; + setDisplayMode?: (title: string) => void; getAccTitle?: () => string; getAccDescription?: () => string; bindFunctions?: (element: Element) => void; 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 6468b5e8c..68e69d7af 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,7 +13,7 @@ import { clear as commonClear, setDiagramTitle, getDiagramTitle, -} from '../../commonDb'; +} from '../../commonDb.js'; import { ClassRelation, ClassNode, @@ -21,7 +21,7 @@ import { ClassMap, NamespaceMap, NamespaceNode, -} from './classTypes'; +} 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 48d7ca64d..e2fac62b9 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 e9b221141..f31cf8890 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, NamespaceMap } 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, NamespaceMap } from './classTypes.js'; const sanitizeText = (txt: string) => common.sanitizeText(txt, getConfig()); @@ -307,7 +307,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. @@ -361,7 +361,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.jison b/packages/mermaid/src/diagrams/er/parser/erDiagram.jison index d9f03c387..8ffa87c63 100644 --- a/packages/mermaid/src/diagrams/er/parser/erDiagram.jison +++ b/packages/mermaid/src/diagrams/er/parser/erDiagram.jison @@ -19,8 +19,6 @@ accDescr\s*"{"\s* { this.begin("acc_descr_multili ":" { this.popState(); this.begin('arg_directive'); return ':'; } \}\%\% { this.popState(); this.popState(); return 'close_directive'; } ((?:(?!\}\%\%).|\n)*) return 'arg_directive'; -\%%(?!\{)[^\n]* /* skip comments */ -[^\}]\%\%[^\n]* /* skip comments */ [\n]+ return 'NEWLINE'; \s+ /* skip whitespace */ [\s]+ return 'SPACE'; @@ -35,8 +33,6 @@ accDescr\s*"{"\s* { this.begin("acc_descr_multili [A-Za-z_][A-Za-z0-9\-_\[\]\(\)]* return 'ATTRIBUTE_WORD' \"[^"]*\" return 'COMMENT'; [\n]+ /* nothing */ -\%%(?!\{)[^\n]* /* skip comments in attribute block */ -[^\}]\%\%[^\n]* /* skip comments in attribute block */ "}" { this.popState(); return 'BLOCK_STOP'; } . return yytext[0]; 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/errorDetector.ts b/packages/mermaid/src/diagrams/error/errorDetector.ts deleted file mode 100644 index 2bdcd7028..000000000 --- a/packages/mermaid/src/diagrams/error/errorDetector.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types'; - -const id = 'error'; - -const detector: DiagramDetector = (text) => { - return text.toLowerCase().trim() === 'error'; -}; - -const loader = async () => { - const { diagram } = await import('./errorDiagram'); - return { id, diagram }; -}; - -const plugin: ExternalDiagramDefinition = { - id, - detector, - loader, -}; - -export default plugin; diff --git a/packages/mermaid/src/diagrams/error/errorDiagram.ts b/packages/mermaid/src/diagrams/error/errorDiagram.ts index d081e1028..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: () => { @@ -19,3 +19,5 @@ export const diagram: DiagramDefinition = { // no op }, }; + +export default diagram; diff --git a/packages/mermaid/src/diagrams/error/errorRenderer.ts b/packages/mermaid/src/diagrams/error/errorRenderer.ts index 60877cb8d..aa0e9e816 100644 --- a/packages/mermaid/src/diagrams/error/errorRenderer.ts +++ b/packages/mermaid/src/diagrams/error/errorRenderer.ts @@ -1,18 +1,16 @@ /** 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'; - -let conf = {}; +import { log } from '../../logger.js'; +import { getErrorMessage } from '../../utils.js'; /** * Merges the value of `conf` with the passed `cnf` * * @param cnf - Config to merge */ -export const setConf = function (cnf: any) { - conf = { ...conf, ...cnf }; +export const setConf = function () { + // no-op }; /** @@ -78,7 +76,7 @@ export const draw = (_text: string, id: string, mermaidVersion: string) => { .attr('y', 250) .attr('font-size', '150px') .style('text-anchor', 'middle') - .text('Syntax error in graph'); + .text('Syntax error in text'); g.append('text') // text label for the x axis .attr('class', 'error-text') .attr('x', 1250) 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 426d22dbb..b86c537dd 100644 --- a/packages/mermaid/src/diagrams/flowchart/elk/flowRenderer-elk.js +++ b/packages/mermaid/src/diagrams/flowchart/elk/flowRenderer-elk.js @@ -2,17 +2,18 @@ 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 { 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(); -const portPos = {}; +let portPos = {}; const conf = {}; export const setConf = function (cnf) { @@ -34,238 +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(' '); - } - - 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; - - // We create a SVG label, either by delegating to addHtmlLabel or manually - let vertexNode; - const labelData = { width: 0, height: 0 }; - if (evaluate(getConfig().flowchart.htmlLabels)) { - // TODO: addHtmlLabel accepts a labelStyle. Do we possibly have that? - const node = { - label: vertexText.replace( - /fa[blrs]?:fa-[\w-]+/g, - (s) => `` - ), - }; - vertexNode = addHtmlLabel(svg, node).node(); - const bbox = vertexNode.getBBox(); - labelData.width = bbox.width; - labelData.height = bbox.height; - labelData.labelNode = vertexNode; - vertexNode.parentNode.removeChild(vertexNode); - } 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); + /** + * Variable for storing the classes for the vertex + * + * @type {string} + */ + let classStr = 'default'; + if (vertex.classes.length > 0) { + classStr = vertex.classes.join(' '); } - vertexNode = svgLabel; - const bbox = vertexNode.getBBox(); - labelData.width = bbox.width; - labelData.height = bbox.height; - labelData.labelNode = vertexNode; - } + classStr = classStr + ' flowchart-label'; + const styles = getStylesFromArray(vertex.styles); - const ports = [ - { - id: vertex.id + '-west', - layoutOptions: { - 'port.side': 'WEST', - }, - }, - { - id: vertex.id + '-east', - layoutOptions: { - 'port.side': 'EAST', - }, - }, - { - id: vertex.id + '-south', - layoutOptions: { - 'port.side': 'SOUTH', - }, - }, - { - id: vertex.id + '-north', - layoutOptions: { - 'port.side': 'NORTH', - }, - }, - ]; + // 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; - 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, - 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; - if (node.type !== 'group') { - nodeEl = insertNode(nodes, node, vertex.dir); - boundingBox = nodeEl.node().getBBox(); - } + // We create a SVG label, either by delegating to addHtmlLabel or manually + let vertexNode; + const labelData = { width: 0, height: 0 }; - 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], - // }); - }); + const ports = [ + { + id: vertex.id + '-west', + layoutOptions: { + 'port.side': 'WEST', + }, + }, + { + id: vertex.id + '-east', + layoutOptions: { + 'port.side': 'EAST', + }, + }, + { + id: vertex.id + '-south', + layoutOptions: { + 'port.side': 'SOUTH', + }, + }, + { + 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'; + } + + // 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); + // } + // 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, + // }); + // } + 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; }; @@ -520,7 +514,7 @@ export const addEdges = function (edges, diagObj, graph, svg) { edgeData.labelpos = 'c'; } - edgeData.labelType = 'text'; + edgeData.labelType = edge.labelType; edgeData.label = edge.text.replace(common.lineBreakRegex, '\n'); if (edge.style === undefined) { @@ -775,6 +769,7 @@ export const draw = async function (text, id, _version, diagObj) { // Add temporary render element diagObj.db.clear(); nodeDb = {}; + portPos = {}; diagObj.db.setGen('gen-2'); // Parse the graph definition diagObj.parser.parse(text); @@ -845,9 +840,17 @@ export const draw = async function (text, id, _version, diagObj) { log.info('Subgraphs - ', subGraphs); for (let i = subGraphs.length - 1; i >= 0; i--) { subG = subGraphs[i]; - diagObj.db.addVertex(subG.id, subG.title, 'group', undefined, subG.classes, subG.dir); + diagObj.db.addVertex( + subG.id, + { text: subG.title, type: subG.labelType }, + 'group', + undefined, + subG.classes, + subG.dir + ); } + // debugger; // Add an element in the svg to be used to hold the subgraphs container // elements const subGraphsEl = svg.insert('g').attr('class', 'subgraphs'); @@ -860,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); + 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'); @@ -887,6 +890,8 @@ export const draw = async function (text, id, _version, diagObj) { }, width: node.labelData.width, height: node.labelData.height, + // width: 100, + // height: 100, }, ]; delete node.x; @@ -895,6 +900,7 @@ export const draw = async function (text, id, _version, diagObj) { delete node.height; } }); + insertChildren(graph.children, parentLookupDb); log.info('after layout', JSON.stringify(graph, null, 2)); const g = await elk.layout(graph); @@ -930,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/elk/styles.ts b/packages/mermaid/src/diagrams/flowchart/elk/styles.ts index e8e7065a0..60659df45 100644 --- a/packages/mermaid/src/diagrams/flowchart/elk/styles.ts +++ b/packages/mermaid/src/diagrams/flowchart/elk/styles.ts @@ -81,7 +81,7 @@ const getStyles = (options: FlowChartStyleOptions) => .edgeLabel { background-color: ${options.edgeLabelBackground}; rect { - opacity: 0.5; + opacity: 0.85; background-color: ${options.edgeLabelBackground}; fill: ${options.edgeLabelBackground}; } @@ -132,6 +132,11 @@ const getStyles = (options: FlowChartStyleOptions) => // fill:#ccc; // // stroke:black; // } + + .flowchart-label text { + text-anchor: middle; + } + ${genSections(options)} `; 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 31196ba96..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; @@ -59,13 +59,14 @@ export const lookUpDomId = function (id) { * * @param _id * @param text + * @param textObj * @param type * @param style * @param classes * @param dir * @param props */ -export const addVertex = function (_id, text, type, style, classes, dir, props = {}) { +export const addVertex = function (_id, textObj, type, style, classes, dir, props = {}) { let txt; let id = _id; if (id === undefined) { @@ -80,16 +81,17 @@ export const addVertex = function (_id, text, type, style, classes, dir, props = if (vertices[id] === undefined) { vertices[id] = { id: id, + labelType: 'text', domId: MERMAID_DOM_ID_PREFIX + id + '-' + vertexCounter, styles: [], classes: [], }; } vertexCounter++; - if (text !== undefined) { + if (textObj !== undefined) { config = configApi.getConfig(); - txt = sanitizeText(text.trim()); - + txt = sanitizeText(textObj.text.trim()); + vertices[id].labelType = textObj.type; // strip quotes if string starts and ends with a quote if (txt[0] === '"' && txt[txt.length - 1] === '"') { txt = txt.substring(1, txt.length - 1); @@ -131,24 +133,27 @@ export const addVertex = function (_id, text, type, style, classes, dir, props = * @param _end * @param type * @param linkText + * @param linkTextObj */ -export const addSingleLink = function (_start, _end, type, linkText) { +export const addSingleLink = function (_start, _end, type) { let start = _start; let end = _end; // if (start[0].match(/\d/)) start = MERMAID_DOM_ID_PREFIX + start; // if (end[0].match(/\d/)) end = MERMAID_DOM_ID_PREFIX + end; // log.info('Got edge...', start, end); - const edge = { start: start, end: end, type: undefined, text: '' }; - linkText = type.text; + const edge = { start: start, end: end, type: undefined, text: '', labelType: 'text' }; + log.info('abc78 Got edge...', edge); + const linkTextObj = type.text; - if (linkText !== undefined) { - edge.text = sanitizeText(linkText.trim()); + if (linkTextObj !== undefined) { + edge.text = sanitizeText(linkTextObj.text.trim()); // strip quotes if string starts and ends with a quote if (edge.text[0] === '"' && edge.text[edge.text.length - 1] === '"') { edge.text = edge.text.substring(1, edge.text.length - 1); } + edge.labelType = linkTextObj.type; } if (type !== undefined) { @@ -158,11 +163,12 @@ export const addSingleLink = function (_start, _end, type, linkText) { } edges.push(edge); }; -export const addLink = function (_start, _end, type, linktext) { +export const addLink = function (_start, _end, type) { + log.info('addLink (abc78)', _start, _end, type); let i, j; for (i = 0; i < _start.length; i++) { for (j = 0; j < _end.length; j++) { - addSingleLink(_start[i], _end[j], type, linktext); + addSingleLink(_start[i], _end[j], type); } } }; @@ -457,10 +463,9 @@ export const defaultStyle = function () { * @param _title */ export const addSubGraph = function (_id, list, _title) { - // console.log('addSubGraph', _id, list, _title); - let id = _id.trim(); - let title = _title; - if (_id === _title && _title.match(/\s/)) { + let id = _id.text.trim(); + let title = _title.text; + if (_id === _title && _title.text.match(/\s/)) { id = undefined; } /** @param a */ @@ -502,7 +507,14 @@ export const addSubGraph = function (_id, list, _title) { title = title || ''; title = sanitizeText(title); subCount = subCount + 1; - const subGraph = { id: id, nodes: nodeList, title: title.trim(), classes: [], dir }; + const subGraph = { + id: id, + nodes: nodeList, + title: title.trim(), + classes: [], + dir, + labelType: _title.type, + }; log.info('Adding', subGraph.id, subGraph.nodes, subGraph.dir); 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 2d3e21a44..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) { @@ -47,7 +47,7 @@ export const addVertices = function (vert, g, svgId, root, doc, diagObj) { 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 @@ -55,31 +55,36 @@ export const addVertices = function (vert, g, svgId, root, doc, diagObj) { // We create a SVG label, either by delegating to addHtmlLabel or manually let vertexNode; - if (evaluate(getConfig().flowchart.htmlLabels)) { - // TODO: addHtmlLabel accepts a labelStyle. Do we possibly have that? - const node = { - label: vertexText.replace( - /fa[blrs]?:fa-[\w-]+/g, - (s) => `` - ), - }; - vertexNode = addHtmlLabel(svg, node).node(); - vertexNode.parentNode.removeChild(vertexNode); + log.info('vertex', vertex, vertex.labelType); + if (vertex.labelType === 'markdown') { + log.info('vertex', vertex, vertex.labelType); } else { - const svgLabel = doc.createElementNS('http://www.w3.org/2000/svg', 'text'); - svgLabel.setAttribute('style', styles.labelStyle.replace('color:', 'fill:')); + if (evaluate(getConfig().flowchart.htmlLabels)) { + // TODO: addHtmlLabel accepts a labelStyle. Do we possibly have that? + const node = { + label: vertexText.replace( + /fa[blrs]?:fa-[\w-]+/g, + (s) => `` + ), + }; + vertexNode = addHtmlLabel(svg, node).node(); + vertexNode.parentNode.removeChild(vertexNode); + } 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); + 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); + 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; } - vertexNode = svgLabel; } let radious = 0; @@ -146,6 +151,7 @@ export const addVertices = function (vert, g, svgId, root, doc, diagObj) { labelStyle: styles.labelStyle, shape: _shape, labelText: vertexText, + labelType: vertex.labelType, rx: radious, ry: radious, class: classStr, @@ -165,6 +171,7 @@ export const addVertices = function (vert, g, svgId, root, doc, diagObj) { log.info('setNode', { labelStyle: styles.labelStyle, + labelType: vertex.labelType, shape: _shape, labelText: vertexText, rx: radious, @@ -312,7 +319,7 @@ export const addEdges = function (edges, g, diagObj) { edgeData.labelpos = 'c'; } - edgeData.labelType = 'text'; + edgeData.labelType = edge.labelType; edgeData.label = edge.text.replace(common.lineBreakRegex, '\n'); if (edge.style === undefined) { @@ -355,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'); @@ -405,7 +412,14 @@ export const draw = function (text, id, _version, diagObj) { for (let i = subGraphs.length - 1; i >= 0; i--) { subG = subGraphs[i]; log.info('Subgraph - ', subG); - diagObj.db.addVertex(subG.id, subG.title, 'group', undefined, subG.classes, subG.dir); + diagObj.db.addVertex( + subG.id, + { text: subG.title, type: subG.labelType }, + 'group', + undefined, + subG.classes, + subG.dir + ); } // Fetch the vertices/nodes and edges/links from the parsed graph definition @@ -437,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 7aeed304c..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,6 +1,7 @@ -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 { cleanupComments } from '../../../diagram-api/comments.js'; setConfig({ securityLevel: 'strict', @@ -13,7 +14,7 @@ describe('[Comments] when parsing', () => { }); it('should handle comments', function () { - const res = flow.parser.parse('graph TD;\n%% Comment\n A-->B;'); + const res = flow.parser.parse(cleanupComments('graph TD;\n%% Comment\n A-->B;')); const vert = flow.parser.yy.getVertices(); const edges = flow.parser.yy.getEdges(); @@ -28,7 +29,7 @@ describe('[Comments] when parsing', () => { }); it('should handle comments at the start', function () { - const res = flow.parser.parse('%% Comment\ngraph TD;\n A-->B;'); + const res = flow.parser.parse(cleanupComments('%% Comment\ngraph TD;\n A-->B;')); const vert = flow.parser.yy.getVertices(); const edges = flow.parser.yy.getEdges(); @@ -43,7 +44,7 @@ describe('[Comments] when parsing', () => { }); it('should handle comments at the end', function () { - const res = flow.parser.parse('graph TD;\n A-->B\n %% Comment at the end\n'); + const res = flow.parser.parse(cleanupComments('graph TD;\n A-->B\n %% Comment at the end\n')); const vert = flow.parser.yy.getVertices(); const edges = flow.parser.yy.getEdges(); @@ -58,7 +59,7 @@ describe('[Comments] when parsing', () => { }); it('should handle comments at the end no trailing newline', function () { - const res = flow.parser.parse('graph TD;\n A-->B\n%% Comment'); + const res = flow.parser.parse(cleanupComments('graph TD;\n A-->B\n%% Comment')); const vert = flow.parser.yy.getVertices(); const edges = flow.parser.yy.getEdges(); @@ -73,7 +74,7 @@ describe('[Comments] when parsing', () => { }); it('should handle comments at the end many trailing newlines', function () { - const res = flow.parser.parse('graph TD;\n A-->B\n%% Comment\n\n\n'); + const res = flow.parser.parse(cleanupComments('graph TD;\n A-->B\n%% Comment\n\n\n')); const vert = flow.parser.yy.getVertices(); const edges = flow.parser.yy.getEdges(); @@ -88,7 +89,7 @@ describe('[Comments] when parsing', () => { }); it('should handle no trailing newlines', function () { - const res = flow.parser.parse('graph TD;\n A-->B'); + const res = flow.parser.parse(cleanupComments('graph TD;\n A-->B')); const vert = flow.parser.yy.getVertices(); const edges = flow.parser.yy.getEdges(); @@ -103,7 +104,7 @@ describe('[Comments] when parsing', () => { }); it('should handle many trailing newlines', function () { - const res = flow.parser.parse('graph TD;\n A-->B\n\n'); + const res = flow.parser.parse(cleanupComments('graph TD;\n A-->B\n\n')); const vert = flow.parser.yy.getVertices(); const edges = flow.parser.yy.getEdges(); @@ -118,7 +119,7 @@ describe('[Comments] when parsing', () => { }); it('should handle a comment with blank rows in-between', function () { - const res = flow.parser.parse('graph TD;\n\n\n %% Comment\n A-->B;'); + const res = flow.parser.parse(cleanupComments('graph TD;\n\n\n %% Comment\n A-->B;')); const vert = flow.parser.yy.getVertices(); const edges = flow.parser.yy.getEdges(); @@ -134,7 +135,9 @@ describe('[Comments] when parsing', () => { it('should handle a comment with mermaid flowchart code in them', function () { const res = flow.parser.parse( - 'graph TD;\n\n\n %% Test od>Odd shape]-->|Two line
edge comment|ro;\n A-->B;' + cleanupComments( + 'graph TD;\n\n\n %% Test od>Odd shape]-->|Two line
edge comment|ro;\n A-->B;' + ) ); const vert = flow.parser.yy.getVertices(); 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 new file mode 100644 index 000000000..0e6efaef1 --- /dev/null +++ b/packages/mermaid/src/diagrams/flowchart/parser/flow-md-string.spec.js @@ -0,0 +1,64 @@ +import flowDb from '../flowDb.js'; +import flow from './flow.jison'; +import { setConfig } from '../../../config.js'; + +setConfig({ + securityLevel: 'strict', +}); + +describe('parsing a flow chart with markdown strings', function () { + beforeEach(function () { + flow.parser.yy = flowDb; + flow.parser.yy.clear(); + }); + + it('mardown formatting in nodes and labels', function () { + const res = flow.parser.parse(`flowchart +A["\`The cat in **the** hat\`"]-- "\`The *bat* in the chat\`" -->B["The dog in the hog"] -- "The rat in the mat" -->C;`); + + const vert = flow.parser.yy.getVertices(); + const edges = flow.parser.yy.getEdges(); + + expect(vert['A'].id).toBe('A'); + expect(vert['A'].text).toBe('The cat in **the** hat'); + expect(vert['A'].labelType).toBe('markdown'); + expect(vert['B'].id).toBe('B'); + expect(vert['B'].text).toBe('The dog in the hog'); + expect(vert['B'].labelType).toBe('text'); + expect(edges.length).toBe(2); + expect(edges[0].start).toBe('A'); + expect(edges[0].end).toBe('B'); + expect(edges[0].type).toBe('arrow_point'); + expect(edges[0].text).toBe('The *bat* in the chat'); + expect(edges[0].labelType).toBe('markdown'); + expect(edges[1].start).toBe('B'); + expect(edges[1].end).toBe('C'); + expect(edges[1].type).toBe('arrow_point'); + expect(edges[1].text).toBe('The rat in the mat'); + expect(edges[1].labelType).toBe('text'); + }); + it('mardown formatting in subgraphs', function () { + const res = flow.parser.parse(`flowchart LR +subgraph "One" + a("\`The **cat** + in the hat\`") -- "1o" --> b{{"\`The **dog** in the hog\`"}} +end +subgraph "\`**Two**\`" + c("\`The **cat** + in the hat\`") -- "\`1o **ipa**\`" --> d("The dog in the hog") +end`); + + const subgraphs = flow.parser.yy.getSubGraphs(); + expect(subgraphs.length).toBe(2); + const subgraph = subgraphs[0]; + + expect(subgraph.nodes.length).toBe(2); + expect(subgraph.title).toBe('One'); + expect(subgraph.labelType).toBe('text'); + + const subgraph2 = subgraphs[1]; + expect(subgraph2.nodes.length).toBe(2); + expect(subgraph2.title).toBe('**Two**'); + expect(subgraph2.labelType).toBe('markdown'); + }); +}); 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.jison b/packages/mermaid/src/diagrams/flowchart/parser/flow.jison index e2dad5881..51427118f 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/flow.jison +++ b/packages/mermaid/src/diagrams/flowchart/parser/flow.jison @@ -7,6 +7,7 @@ /* lexical grammar */ %lex %x string +%x md_string %x acc_title %x acc_descr %x acc_descr_multiline @@ -27,8 +28,6 @@ ":" { this.popState(); this.begin('arg_directive'); return ':'; } \}\%\% { this.popState(); this.popState(); return 'close_directive'; } ((?:(?!\}\%\%).|\n)*) return 'arg_directive'; -\%\%(?!\{)[^\n]* /* skip comments */ -[^\}]\%\%[^\n]* /* skip comments */ accTitle\s*":"\s* { this.begin("acc_title");return 'acc_title'; } (?!\n|;|#)*[^\n]* { this.popState(); return "acc_title_value"; } accDescr\s*":"\s* { this.begin("acc_descr");return 'acc_descr'; } @@ -37,6 +36,9 @@ accDescr\s*"{"\s* { this.begin("acc_descr_multili [\}] { this.popState(); } [^\}]* return "acc_descr_multiline_value"; // .*[^\n]* { return "acc_descr_line"} +["][`] { this.begin("md_string");} +[^`"]+ { return "MD_STR";} +[`]["] { this.popState();} ["] this.begin("string"); ["] this.popState(); [^"]* return "STR"; @@ -434,11 +436,13 @@ arrowText: ; text: textToken - {$$=$1;} + { $$={text:$1, type: 'text'};} | text textToken - {$$=$1+''+$2;} + { $$={text:$1.text+''+$2, type: $1.type};} | STR - {$$=$1;} + { $$={text: $1, type: 'text'};} + | MD_STR + { $$={text: $1, type: 'markdown'};} ; diff --git a/packages/mermaid/src/diagrams/flowchart/parser/flow.spec.js b/packages/mermaid/src/diagrams/flowchart/parser/flow.spec.js index 6b440da79..3852c4f92 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/flow.spec.js +++ b/packages/mermaid/src/diagrams/flowchart/parser/flow.spec.js @@ -1,6 +1,7 @@ -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 { cleanupComments } from '../../../diagram-api/comments.js'; setConfig({ securityLevel: 'strict', @@ -13,7 +14,7 @@ describe('parsing a flow chart', function () { }); it('should handle a trailing whitespaces after statements', function () { - const res = flow.parser.parse('graph TD;\n\n\n %% Comment\n A-->B; \n B-->C;'); + const res = flow.parser.parse(cleanupComments('graph TD;\n\n\n %% Comment\n A-->B; \n B-->C;')); const vert = flow.parser.yy.getVertices(); const edges = flow.parser.yy.getEdges(); 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 a89d33d3d..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}; } @@ -41,6 +41,15 @@ const getStyles = (options: FlowChartStyleOptions) => stroke: ${options.nodeBorder}; stroke-width: 1px; } + .flowchart-label text { + text-anchor: middle; + } + // .flowchart-label .text-outer-tspan { + // text-anchor: middle; + // } + // .flowchart-label .text-inner-tspan { + // text-anchor: start; + // } .node .label { text-align: center; @@ -83,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 475ee4de4..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); @@ -32,6 +32,7 @@ let links = {}; let sections = []; let tasks = []; let currentSection = ''; +let displayMode = ''; const tags = ['active', 'done', 'crit', 'milestone']; let funs = []; let inclusiveEndDates = false; @@ -55,6 +56,7 @@ export const clear = function () { rawTasks = []; dateFormat = ''; axisFormat = ''; + displayMode = ''; tickInterval = undefined; todayMarker = ''; includes = []; @@ -110,6 +112,14 @@ export const topAxisEnabled = function () { return topAxis; }; +export const setDisplayMode = function (txt) { + displayMode = txt; +}; + +export const getDisplayMode = function () { + return displayMode; +}; + export const getDateFormat = function () { return dateFormat; }; @@ -143,11 +153,11 @@ export const getSections = function () { }; export const getTasks = function () { - let allItemsPricessed = compileTasks(); + let allItemsProcessed = compileTasks(); const maxDepth = 10; let iterationCount = 0; - while (!allItemsPricessed && iterationCount < maxDepth) { - allItemsPricessed = compileTasks(); + while (!allItemsProcessed && iterationCount < maxDepth) { + allItemsProcessed = compileTasks(); iterationCount++; } @@ -719,6 +729,8 @@ export default { getAccTitle, setDiagramTitle, getDiagramTitle, + setDisplayMode, + getDisplayMode, setAccDescription, getAccDescription, addSection, diff --git a/packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts b/packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts index d65f2fdfd..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 () { @@ -34,6 +34,7 @@ describe('when using the ganttDb', function () { beforeEach(function () { ganttDb.setDateFormat('YYYY-MM-DD'); ganttDb.enableInclusiveEndDates(); + ganttDb.setDisplayMode('compact'); ganttDb.setTodayMarker('off'); ganttDb.setExcludes('weekends 2019-02-06,friday'); ganttDb.addSection('weekends skip test'); @@ -53,6 +54,7 @@ describe('when using the ganttDb', function () { ${'getExcludes'} | ${[]} ${'getSections'} | ${[]} ${'endDatesAreInclusive'} | ${false} + ${'getDisplayMode'} | ${''} `)('should clear $fn', ({ fn, expected }) => { expect(ganttDb[fn]()).toEqual(expected); }); 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 7a012beb5..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,20 +16,51 @@ 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'); }; +/** + * For this issue: + * https://github.com/mermaid-js/mermaid/issues/1618 + * + * Finds the number of intersections between tasks that happen at any point in time. + * Used to figure out how many rows are needed to display the tasks when the display + * mode is set to 'compact'. + * + * @param tasks + * @param orderOffset + */ +const getMaxIntersections = (tasks, orderOffset) => { + let timeline = [...tasks].map(() => -Infinity); + let sorted = [...tasks].sort((a, b) => a.startTime - b.startTime || a.order - b.order); + let maxIntersections = 0; + for (const element of sorted) { + for (let j = 0; j < timeline.length; j++) { + if (element.startTime >= timeline[j]) { + timeline[j] = element.endTime; + element.order = j + orderOffset; + if (j > maxIntersections) { + maxIntersections = j; + } + break; + } + } + } + + return maxIntersections; +}; + let w; export const draw = function (text, id, version, diagObj) { const conf = getConfig().gantt; + // diagObj.db.clear(); // parser.parse(text); - const securityLevel = getConfig().securityLevel; // Handle root and Document for when rendering in sandbox mode let sandboxElement; @@ -56,7 +87,40 @@ export const draw = function (text, id, version, diagObj) { const taskArray = diagObj.db.getTasks(); // Set height based on number of tasks - const h = taskArray.length * (conf.barHeight + conf.barGap) + 2 * conf.topPadding; + + let categories = []; + + for (const element of taskArray) { + categories.push(element.type); + } + + categories = checkUnique(categories); + const categoryHeights = {}; + + let h = 2 * conf.topPadding; + if (diagObj.db.getDisplayMode() === 'compact' || conf.displayMode === 'compact') { + const categoryElements = {}; + for (const element of taskArray) { + if (categoryElements[element.section] === undefined) { + categoryElements[element.section] = [element]; + } else { + categoryElements[element.section].push(element); + } + } + + let intersections = 0; + for (const category of Object.keys(categoryElements)) { + const categoryHeight = getMaxIntersections(categoryElements[category], intersections) + 1; + intersections += categoryHeight; + h += categoryHeight * (conf.barHeight + conf.barGap); + categoryHeights[category] = categoryHeight; + } + } else { + h += taskArray.length * (conf.barHeight + conf.barGap); + for (const category of categories) { + categoryHeights[category] = taskArray.filter((task) => task.type === category).length; + } + } // Set viewBox elem.setAttribute('viewBox', '0 0 ' + w + ' ' + h); @@ -74,16 +138,6 @@ export const draw = function (text, id, version, diagObj) { ]) .rangeRound([0, w - conf.leftPadding - conf.rightPadding]); - let categories = []; - - for (const element of taskArray) { - categories.push(element.type); - } - - const catsUnfiltered = categories; // for vert labels - - categories = checkUnique(categories); - /** * @param a * @param b @@ -157,11 +211,15 @@ export const draw = function (text, id, version, diagObj) { * @param w */ function drawRects(theArray, theGap, theTopPad, theSidePad, theBarHeight, theColorScale, w) { + // Get unique task orders. Required to draw the background rects when display mode is compact. + const uniqueTaskOrderIds = [...new Set(theArray.map((item) => item.order))]; + const uniqueTasks = uniqueTaskOrderIds.map((id) => theArray.find((item) => item.order === id)); + // Draw background rects covering the entire width of the graph, these form the section rows. svg .append('g') .selectAll('rect') - .data(theArray) + .data(uniqueTasks) .enter() .append('rect') .attr('x', 0) @@ -582,12 +640,9 @@ export const draw = function (text, id, version, diagObj) { * @param theTopPad */ function vertLabels(theGap, theTopPad) { - const numOccurances = []; let prevGap = 0; - for (const [i, category] of categories.entries()) { - numOccurances[i] = [category, getCount(category, catsUnfiltered)]; - } + const numOccurances = Object.keys(categoryHeights).map((d) => [d, categoryHeights[d]]); svg .append('g') // without doing this, impossible to put grid lines behind text @@ -625,7 +680,6 @@ export const draw = function (text, id, version, diagObj) { } }) .attr('font-size', conf.sectionFontSize) - .attr('font-size', conf.sectionFontSize) .attr('class', function (d) { for (const [i, category] of categories.entries()) { if (d[0] === category) { @@ -682,31 +736,6 @@ export const draw = function (text, id, version, diagObj) { } return result; } - - /** - * From this stack exchange question: - * http://stackoverflow.com/questions/14227981/count-how-many-strings-in-an-array-have-duplicates-in-the-same-array - * - * @param arr - */ - function getCounts(arr) { - let i = arr.length; // const to loop over - const obj = {}; // obj to store results - while (i) { - obj[arr[--i]] = (obj[arr[i]] || 0) + 1; // count occurrences - } - return obj; - } - - /** - * Get specific from everything - * - * @param word - * @param arr - */ - function getCount(word, arr) { - return getCounts(arr)[word] || 0; - } }; export default { diff --git a/packages/mermaid/src/diagrams/gantt/parser/gantt.jison b/packages/mermaid/src/diagrams/gantt/parser/gantt.jison index 2223aa378..0eb45ec41 100644 --- a/packages/mermaid/src/diagrams/gantt/parser/gantt.jison +++ b/packages/mermaid/src/diagrams/gantt/parser/gantt.jison @@ -131,9 +131,10 @@ statement | includes {yy.setIncludes($1.substr(9));$$=$1.substr(9);} | todayMarker {yy.setTodayMarker($1.substr(12));$$=$1.substr(12);} | title {yy.setDiagramTitle($1.substr(6));$$=$1.substr(6);} - | acc_title acc_title_value { $$=$2.trim();yy.setAccTitle($$); } - | acc_descr acc_descr_value { $$=$2.trim();yy.setAccDescription($$); } - | acc_descr_multiline_value { $$=$1.trim();yy.setAccDescription($$); } | section {yy.addSection($1.substr(8));$$=$1.substr(8);} + | acc_title acc_title_value { $$=$2.trim();yy.setAccTitle($$); } + | acc_descr acc_descr_value { $$=$2.trim();yy.setAccDescription($$); } + | acc_descr_multiline_value { $$=$1.trim();yy.setAccDescription($$); } + | section { yy.addSection($1.substr(8));$$=$1.substr(8); } | clickStatement | taskTxt taskData {yy.addTask($1,$2);$$='task';} | directive 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 c5b5fede1..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); @@ -167,12 +167,15 @@ function positionNodes(cy) { export const draw = async (text, id, version, diagObj) => { const conf = getConfig(); + // console.log('Config: ', conf); + conf.htmlLabels = false; + // This is done only for throwing the error if the text is not valid. diagObj.db.clear(); // Parse the graph definition diagObj.parser.parse(text); - log.debug('Renering info diagram\n' + text); + 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 d2f6bbf1a..9dd046a3d 100644 --- a/packages/mermaid/src/diagrams/mindmap/parser/mindmap.jison +++ b/packages/mermaid/src/diagrams/mindmap/parser/mindmap.jison @@ -12,12 +12,13 @@ %} %x NODE %x NSTR +%x NSTR2 %x ICON %x CLASS %% -\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'); } @@ -41,6 +42,9 @@ // !(-\() return 'NODE_ID'; [^\(\[\n\-\)\{\}]+ return 'NODE_ID'; <> return 'EOF'; +["][`] { this.begin("NSTR2");} +[^`"]+ { return "NODE_DESCR";} +[`]["] { this.popState();} ["] { yy.getLogger().trace('Starting NSTR');this.begin("NSTR");} [^"]+ { yy.getLogger().trace('description:', yytext); return "NODE_DESCR";} ["] {this.popState();} diff --git a/packages/mermaid/src/diagrams/mindmap/styles.js b/packages/mermaid/src/diagrams/mindmap/styles.js index 986a04514..863522fdf 100644 --- a/packages/mermaid/src/diagrams/mindmap/styles.js +++ b/packages/mermaid/src/diagrams/mindmap/styles.js @@ -70,5 +70,12 @@ const getStyles = (options) => .edge { fill: none; } + .mindmap-node-label { + dy: 1em; + alignment-baseline: middle; + text-anchor: middle; + dominant-baseline: middle; + text-align: center; + } `; export default getStyles; diff --git a/packages/mermaid/src/diagrams/mindmap/svgDraw.js b/packages/mermaid/src/diagrams/mindmap/svgDraw.js index 2b1aa021e..22132dae6 100644 --- a/packages/mermaid/src/diagrams/mindmap/svgDraw.js +++ b/packages/mermaid/src/diagrams/mindmap/svgDraw.js @@ -1,5 +1,6 @@ import { select } from 'd3'; -import * as db from './mindmapDb'; +import * as db from './mindmapDb.js'; +import { createText } from '../../rendering-util/createText.js'; const MAX_SECTIONS = 12; /** @@ -11,7 +12,7 @@ function wrap(text, width) { var text = select(this), words = text .text() - .split(/(\s+|
)/) + .split(/(\s+|)/) .reverse(), word, line = [], @@ -28,10 +29,10 @@ function wrap(text, width) { word = words[words.length - 1 - j]; line.push(word); tspan.text(line.join(' ').trim()); - if (tspan.node().getComputedTextLength() > width || word === '
') { + if (tspan.node().getComputedTextLength() > width || word === '
') { line.pop(); tspan.text(line.join(' ').trim()); - if (word === '
') { + if (word === '
') { line = ['']; } else { line = [word]; @@ -203,6 +204,7 @@ const roundedRectBkg = function (elem, node) { * @returns {number} The height nodes dom element */ export const drawNode = function (elem, node, fullSection, conf) { + const htmlLabels = conf.htmlLabels; const section = fullSection % (MAX_SECTIONS - 1); const nodeElem = elem.append('g'); node.section = section; @@ -215,15 +217,22 @@ export const drawNode = function (elem, node, fullSection, conf) { // Create the wrapped text element const textElem = nodeElem.append('g'); - const txt = textElem - .append('text') - .text(node.descr) - .attr('dy', '1em') - .attr('alignment-baseline', 'middle') - .attr('dominant-baseline', 'middle') - .attr('text-anchor', 'middle') - .call(wrap, node.width); - const bbox = txt.node().getBBox(); + const description = node.descr.replace(/()/g, '\n'); + const newEl = createText(textElem, description, { + useHtmlLabels: htmlLabels, + width: node.width, + classes: 'mindmap-node-label', + }); + + if (!htmlLabels) { + textElem + .attr('dy', '1em') + .attr('alignment-baseline', 'middle') + .attr('dominant-baseline', 'middle') + .attr('text-anchor', 'middle'); + } + // .call(wrap, node.width); + const bbox = textElem.node().getBBox(); const fontSize = conf.fontSize.replace ? conf.fontSize.replace('px', '') : conf.fontSize; node.height = bbox.height + fontSize * 1.1 * 0.5 + node.padding; node.width = bbox.width + 2 * node.padding; @@ -267,7 +276,16 @@ export const drawNode = function (elem, node, fullSection, conf) { ); } } else { - textElem.attr('transform', 'translate(' + node.width / 2 + ', ' + node.padding / 2 + ')'); + if (!htmlLabels) { + const dx = node.width / 2; + const dy = node.padding / 2; + textElem.attr('transform', 'translate(' + dx + ', ' + dy + ')'); + // textElem.attr('transform', 'translate(' + node.width / 2 + ', ' + node.padding / 2 + ')'); + } else { + const dx = (node.width - bbox.width) / 2; + const dy = (node.height - bbox.height) / 2; + textElem.attr('transform', 'translate(' + dx + ', ' + dy + ')'); + } } switch (node.type) { 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 42c7cbf5b..936607cbd 100644
--- a/packages/mermaid/src/docs/syntax/flowchart.md
+++ b/packages/mermaid/src/docs/syntax/flowchart.md
@@ -122,9 +122,7 @@ flowchart LR
 
 ### A hexagon node
 
-Code:
-
-```mmd
+```mermaid-example
 flowchart LR
     id1{{This is the text in the box}}
 ```
@@ -448,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 7c446d91f..422358d3e 100644 --- a/packages/mermaid/src/docs/syntax/gantt.md +++ b/packages/mermaid/src/docs/syntax/gantt.md @@ -189,9 +189,27 @@ The pattern is: More info in: [https://github.com/d3/d3-time#interval_every](https://github.com/d3/d3-time#interval_every) +## Output in compact mode + +The compact mode allows you to display multiple tasks in the same row. Compact mode can be enabled for a gantt chart by setting the display mode of the graph via preceeding YAML settings. + +```mmd +--- +displayMode: compact +--- +gantt + title A Gantt Diagram + dateFormat YYYY-MM-DD + + section Section + A task :a1, 2014-01-01, 30d + Another task :a2, 2014-01-20, 25d + Another one :a3, 2014-02-10, 20d +``` + ## Comments -Comments can be entered within a gantt chart, which will be ignored by the parser. Comments need to be on their own line and must be prefaced with `%%` (double percent signs). Any text after the start of the comment to the next newline will be treated as a comment, including any diagram syntax +Comments can be entered within a gantt chart, which will be ignored by the parser. Comments need to be on their own line and must be prefaced with `%%` (double percent signs). Any text after the start of the comment to the next newline will be treated as a comment, including any diagram syntax. ```mmd gantt @@ -356,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 c8a252691..64a25821a 100644 --- a/packages/mermaid/src/docs/syntax/mindmap.md +++ b/packages/mermaid/src/docs/syntax/mindmap.md @@ -138,7 +138,7 @@ mindmap C ``` -_These classes needs top be supplied by the site administrator._ +_These classes need to be supplied by the site administrator._ ## Unclear indentation @@ -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/syntax/timeline.md b/packages/mermaid/src/docs/syntax/timeline.md index ef48d2b61..4f2fc705b 100644 --- a/packages/mermaid/src/docs/syntax/timeline.md +++ b/packages/mermaid/src/docs/syntax/timeline.md @@ -2,7 +2,7 @@ > Timeline: This is an experimental diagram for now. The syntax and properties can change in future releases. The syntax is stable except for the icon integration which is the experimental part. -"A timeline is a type of diagram used to illustrate a chronology of events, dates, or periods of time. It is usually presented graphically to indicate the passing of time, and it is usually organized chronologically. A basic timeline presents a list of events in chronological order, usually using dates as markers. A timeline can also be used to show the relationship between events, such as the relationship between the events of a person's life. A timeline can also be used to show the relationship between events, such as the relationship between the events of a person's life." Wikipedia +"A timeline is a type of diagram used to illustrate a chronology of events, dates, or periods of time. It is usually presented graphically to indicate the passing of time, and it is usually organized chronologically. A basic timeline presents a list of events in chronological order, usually using dates as markers. A timeline can also be used to show the relationship between events, such as the relationship between the events of a person's life." Wikipedia ### An example of a timeline. @@ -139,7 +139,7 @@ However, if there is no section defined, then we have two possibilities: ``` -Note that this is no, section defined, and each time period and its corresponding events will have its own color scheme. +Note that there are no sections defined, and each time period and its corresponding events will have its own color scheme. 2. Disable the multiColor option using the `disableMultiColor` option. This will make all time periods and events follow the same color scheme. @@ -172,7 +172,7 @@ let us look at same example, where we have disabled the multiColor option. ### Customizing Color scheme -You can customize the color scheme using the `cScale0` to `cScale11` theme variables. Mermaid allows you to set unique colors for up-to 12, where `cScale0` variable will drive the value of the first section or time-period, `cScale1` will drive the value of the second section and so on. +You can customize the color scheme using the `cScale0` to `cScale11` theme variables. Mermaid allows you to set unique colors for up-to 12 sections, where `cScale0` variable will drive the value of the first section or time-period, `cScale1` will drive the value of the second section and so on. In case you have more than 12 sections, the color scheme will start to repeat. NOTE: Default values for these theme variables are picked from the selected theme. If you want to override the default values, you can use the `initialize` call to add your custom theme variable values. 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 bd99877b6..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, @@ -392,7 +392,7 @@ const render = (id: string, text: string, container?: Element): Promise ({ 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 1b440672a..5e9d0ead6 100644 --- a/packages/mermaid/src/mermaidAPI.ts +++ b/packages/mermaid/src/mermaidAPI.ts @@ -15,24 +15,31 @@ 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 = ['graph', 'flowchart', 'flowchart-v2', 'stateDiagram', 'stateDiagram-v2']; +const CLASSDEF_DIAGRAMS = [ + 'graph', + 'flowchart', + 'flowchart-v2', + 'flowchart-elk', + 'stateDiagram', + 'stateDiagram-v2', +]; const MAX_TEXTLENGTH = 50_000; const MAX_TEXTLENGTH_EXCEEDED_MSG = 'graph TB;a[Maximum text size in diagram exceeded];style a fill:#faa'; @@ -399,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; @@ -531,6 +544,10 @@ const render = async function ( attachFunctions(); + if (parseEncounteredException) { + throw parseEncounteredException; + } + // ------------------------------------------------------------------------------- // Remove the temporary HTML element if appropriate const tmpElementSelector = isSandboxed ? iFrameID_selector : enclosingDivID_selector; @@ -539,10 +556,6 @@ const render = async function ( node.remove(); } - if (parseEncounteredException) { - throw parseEncounteredException; - } - return { svg: svgCode, bindFunctions: diag.db.bindFunctions, @@ -650,6 +663,7 @@ function addA11yInfo( * numberSectionStyles: 4, * axisFormat: '%Y-%m-%d', * topAxis: false, + * displayMode: '', * }, * }; * mermaid.initialize(config); diff --git a/packages/mermaid/src/rendering-util/createText.js b/packages/mermaid/src/rendering-util/createText.js new file mode 100644 index 000000000..a5438b562 --- /dev/null +++ b/packages/mermaid/src/rendering-util/createText.js @@ -0,0 +1,224 @@ +import { select } from 'd3'; +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 + */ +function applyStyle(dom, styleFn) { + if (styleFn) { + dom.attr('style', styleFn); + } +} + +/** + * @param element + * @param {any} node + * @param width + * @param classes + * @returns {SVGForeignObjectElement} Node + */ +function addHtmlSpan(element, node, width, classes) { + const fo = element.append('foreignObject'); + // const newEl = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject'); + // const newEl = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject'); + const div = fo.append('xhtml:div'); + // const div = body.append('div'); + // const div = fo.append('div'); + + const label = node.label; + const labelClass = node.isNode ? 'nodeLabel' : 'edgeLabel'; + div.html( + `' + + label + + '' + ); + + applyStyle(div, node.labelStyle); + div.style('display', 'table-cell'); + div.style('white-space', 'nowrap'); + div.style('max-width', width + 'px'); + div.attr('xmlns', 'http://www.w3.org/1999/xhtml'); + + let bbox = div.node().getBoundingClientRect(); + if (bbox.width === width) { + div.style('display', 'table'); + div.style('white-space', 'break-spaces'); + div.style('width', width + 'px'); + bbox = div.node().getBoundingClientRect(); + } + + fo.style('width', bbox.width); + fo.style('height', bbox.height); + + return fo.node(); +} + +/** + * Creates a tspan element with the specified attributes for text positioning. + * + * @param {object} textElement - The parent text element to append the tspan element. + * @param {number} lineIndex - The index of the current line in the structuredText array. + * @param {number} lineHeight - The line height value for the text. + * @returns {object} The created tspan element. + */ +function createTspan(textElement, lineIndex, lineHeight) { + return textElement + .append('tspan') + .attr('class', 'text-outer-tspan') + .attr('x', 0) + .attr('y', lineIndex * lineHeight - 0.1 + 'em') + .attr('dy', lineHeight + 'em'); +} + +/** + * Creates a formatted text element by breaking lines and applying styles based on + * the given structuredText. + * + * @param {number} width - The maximum allowed width of the text. + * @param {object} g - The parent group element to append the formatted text. + * @param {Array} structuredText - The structured text data to format. + * @param addBackground + */ +function createFormattedText(width, g, structuredText, addBackground = false) { + const lineHeight = 1.1; + const labelGroup = g.append('g'); + let bkg = labelGroup.insert('rect').attr('class', 'background'); + const textElement = labelGroup.append('text').attr('y', '-10.1'); + // .attr('dominant-baseline', 'middle') + // .attr('text-anchor', 'middle'); + // .attr('text-anchor', 'middle'); + let lineIndex = -1; + structuredText.forEach((line) => { + lineIndex++; + let tspan = createTspan(textElement, lineIndex, lineHeight); + + let words = [...line].reverse(); + let currentWord; + let wrappedLine = []; + + while (words.length) { + currentWord = words.pop(); + wrappedLine.push(currentWord); + + updateTextContentAndStyles(tspan, wrappedLine); + + if (tspan.node().getComputedTextLength() > width) { + wrappedLine.pop(); + words.push(currentWord); + + updateTextContentAndStyles(tspan, wrappedLine); + + wrappedLine = []; + lineIndex++; + tspan = createTspan(textElement, lineIndex, lineHeight); + } + } + }); + if (addBackground) { + const bbox = textElement.node().getBBox(); + const padding = 2; + bkg + .attr('x', -padding) + .attr('y', -padding) + .attr('width', bbox.width + 2 * padding) + .attr('height', bbox.height + 2 * padding); + // .style('fill', 'red'); + + return labelGroup.node(); + } else { + return textElement.node(); + } +} + +/** + * Updates the text content and styles of the given tspan element based on the + * provided wrappedLine data. + * + * @param {object} tspan - The tspan element to update. + * @param {Array} wrappedLine - The line data to apply to the tspan element. + */ +function updateTextContentAndStyles(tspan, wrappedLine) { + tspan.text(''); + + wrappedLine.forEach((word, index) => { + const innerTspan = tspan + .append('tspan') + .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) { + innerTspan.text(word.content); + } else { + innerTspan.text(' ' + word.content); + } + }); +} + +/** + * + * @param el + * @param {*} text + * @param {*} param1 + * @param root0 + * @param root0.style + * @param root0.isTitle + * @param root0.classes + * @param root0.useHtmlLabels + * @param root0.isNode + * @returns + */ +// Note when using from flowcharts converting the API isNode means classes should be set accordingly. When using htmlLabels => to sett classes to'nodeLabel' when isNode=true otherwise 'edgeLabel' +// When not using htmlLabels => to set classes to 'title-row' when isTitle=true otherwise 'title-row' +export const createText = ( + el, + text = '', + { + style = '', + isTitle = false, + classes = '', + useHtmlLabels = true, + isNode = true, + width, + addSvgBackground = false, + } = {} +) => { + log.info('createText', text, style, isTitle, classes, useHtmlLabels, isNode, addSvgBackground); + if (useHtmlLabels) { + // TODO: addHtmlLabel accepts a labelStyle. Do we possibly have that? + // text = text.replace(/\\n|\n/g, '
'); + const htmlText = markdownToHTML(text); + // log.info('markdo wnToHTML' + text, markdownToHTML(text)); + const node = { + isNode, + label: decodeEntities(htmlText).replace( + /fa[blrs]?:fa-[\w-]+/g, + (s) => `` + ), + labelStyle: style.replace('fill:', 'color:'), + }; + let vertexNode = addHtmlSpan(el, node, width, classes); + 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 new file mode 100644 index 000000000..93704b2fe --- /dev/null +++ b/packages/mermaid/src/rendering-util/handle-markdown-text.js @@ -0,0 +1,94 @@ +import SimpleMarkdown from '@khanacademy/simple-markdown'; + +/** + * + * @param markdown + */ +function preprocessMarkdown(markdown) { + // Replace multiple newlines with a single newline + const withoutMultipleNewlines = markdown.replace(/\n{2,}/g, '\n'); + // Remove extra spaces at the beginning of each line + const withoutExtraSpaces = withoutMultipleNewlines.replace(/^\s+/gm, ''); + return withoutExtraSpaces; +} + +/** + * + * @param markdown + */ +export function markdownToLines(markdown) { + const preprocessedMarkdown = preprocessMarkdown(markdown); + const mdParse = SimpleMarkdown.defaultBlockParse; + const syntaxTree = mdParse(preprocessedMarkdown); + + let lines = [[]]; + let currentLine = 0; + + /** + * + * @param node + * @param parentType + */ + function processNode(node, parentType) { + if (node.type === 'text') { + const textLines = node.content.split('\n'); + + textLines.forEach((textLine, index) => { + if (index !== 0) { + currentLine++; + lines.push([]); + } + + // textLine.split(/ (?=[^!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]+)/).forEach((word) => { + textLine.split(' ').forEach((word) => { + if (word) { + lines[currentLine].push({ content: word, type: parentType || 'normal' }); + } + }); + }); + } else if (node.type === 'strong' || node.type === 'em') { + node.content.forEach((contentNode) => { + processNode(contentNode, node.type); + }); + } + } + + syntaxTree.forEach((treeNode) => { + if (treeNode.type === 'paragraph') { + treeNode.content.forEach((contentNode) => { + processNode(contentNode); + }); + } + }); + + return lines; +} + +/** + * + * @param markdown + */ +export function markdownToHTML(markdown) { + const mdParse = SimpleMarkdown.defaultBlockParse; + const syntaxTree = mdParse(markdown); + + /** + * + * @param node + */ + function output(node) { + if (node.type === 'text') { + return node.content.replace(/\n/g, '
'); + } else if (node.type === 'strong') { + return `${node.content.map(output).join('')}`; + } else if (node.type === 'em') { + return `${node.content.map(output).join('')}`; + } else if (node.type === 'paragraph') { + return `

${node.content.map(output).join('')}

`; + } else { + return ''; + } + } + + return syntaxTree.map(output).join(''); +} diff --git a/packages/mermaid/src/rendering-util/handle-markdown-text.spec.js b/packages/mermaid/src/rendering-util/handle-markdown-text.spec.js new file mode 100644 index 000000000..5e74a9956 --- /dev/null +++ b/packages/mermaid/src/rendering-util/handle-markdown-text.spec.js @@ -0,0 +1,253 @@ +// import { test } from 'vitest'; +import { markdownToLines, markdownToHTML } from './handle-markdown-text'; +import { test } from 'vitest'; + +test('markdownToLines - Basic test', () => { + const input = `This is regular text +Here is a new line +There is some words **with a bold** section +Here is a line *with an italic* section`; + + const expectedOutput = [ + [ + { content: 'This', type: 'normal' }, + { content: 'is', type: 'normal' }, + { content: 'regular', type: 'normal' }, + { content: 'text', type: 'normal' }, + ], + [ + { content: 'Here', type: 'normal' }, + { content: 'is', type: 'normal' }, + { content: 'a', type: 'normal' }, + { content: 'new', type: 'normal' }, + { content: 'line', type: 'normal' }, + ], + [ + { content: 'There', type: 'normal' }, + { content: 'is', type: 'normal' }, + { content: 'some', type: 'normal' }, + { content: 'words', type: 'normal' }, + { content: 'with', type: 'strong' }, + { content: 'a', type: 'strong' }, + { content: 'bold', type: 'strong' }, + { content: 'section', type: 'normal' }, + ], + [ + { content: 'Here', type: 'normal' }, + { content: 'is', type: 'normal' }, + { content: 'a', type: 'normal' }, + { content: 'line', type: 'normal' }, + { content: 'with', type: 'em' }, + { content: 'an', type: 'em' }, + { content: 'italic', type: 'em' }, + { content: 'section', type: 'normal' }, + ], + ]; + + const output = markdownToLines(input); + expect(output).toEqual(expectedOutput); +}); + +test('markdownToLines - Empty input', () => { + const input = ''; + const expectedOutput = [[]]; + const output = markdownToLines(input); + expect(output).toEqual(expectedOutput); +}); + +test('markdownToLines - No formatting', () => { + const input = `This is a simple test +with no formatting`; + + const expectedOutput = [ + [ + { content: 'This', type: 'normal' }, + { content: 'is', type: 'normal' }, + { content: 'a', type: 'normal' }, + { content: 'simple', type: 'normal' }, + { content: 'test', type: 'normal' }, + ], + [ + { content: 'with', type: 'normal' }, + { content: 'no', type: 'normal' }, + { content: 'formatting', type: 'normal' }, + ], + ]; + + const output = markdownToLines(input); + expect(output).toEqual(expectedOutput); +}); + +test('markdownToLines - Only bold formatting', () => { + const input = `This is a **bold** test`; + + const expectedOutput = [ + [ + { content: 'This', type: 'normal' }, + { content: 'is', type: 'normal' }, + { content: 'a', type: 'normal' }, + { content: 'bold', type: 'strong' }, + { content: 'test', type: 'normal' }, + ], + ]; + + const output = markdownToLines(input); + expect(output).toEqual(expectedOutput); +}); + +test('markdownToLines - paragraph 1', () => { + const input = `**Start** with + a second line`; + + const expectedOutput = [ + [ + { content: 'Start', type: 'strong' }, + { content: 'with', type: 'normal' }, + ], + [ + { content: 'a', type: 'normal' }, + { content: 'second', type: 'normal' }, + { content: 'line', type: 'normal' }, + ], + ]; + + const output = markdownToLines(input); + expect(output).toEqual(expectedOutput); +}); + +test('markdownToLines - paragraph', () => { + const input = `**Start** with + + a second line`; + + const expectedOutput = [ + [ + { content: 'Start', type: 'strong' }, + { content: 'with', type: 'normal' }, + ], + [ + { content: 'a', type: 'normal' }, + { content: 'second', type: 'normal' }, + { content: 'line', type: 'normal' }, + ], + ]; + + const output = markdownToLines(input); + expect(output).toEqual(expectedOutput); +}); + +test('markdownToLines - Only italic formatting', () => { + const input = `This is an *italic* test`; + + const expectedOutput = [ + [ + { content: 'This', type: 'normal' }, + { content: 'is', type: 'normal' }, + { content: 'an', type: 'normal' }, + { content: 'italic', type: 'em' }, + { content: 'test', type: 'normal' }, + ], + ]; + + const output = markdownToLines(input); + expect(output).toEqual(expectedOutput); +}); + +it('markdownToLines - Mixed formatting', () => { + const input = `*Italic* and **bold** formatting`; + + const expectedOutput = [ + [ + { content: 'Italic', type: 'em' }, + { content: 'and', type: 'normal' }, + { content: 'bold', type: 'strong' }, + { content: 'formatting', type: 'normal' }, + ], + ]; + + const output = markdownToLines(input); + expect(output).toEqual(expectedOutput); +}); + +it('markdownToLines - Mixed formatting', () => { + const input = `The dog in **the** hog... a *very long text* about it +Word!`; + + const expectedOutput = [ + [ + { content: 'The', type: 'normal' }, + { content: 'dog', type: 'normal' }, + { content: 'in', type: 'normal' }, + { content: 'the', type: 'strong' }, + { content: 'hog', type: 'normal' }, + { content: '.', type: 'normal' }, + { content: '.', type: 'normal' }, + { content: '.', type: 'normal' }, + { content: 'a', type: 'normal' }, + { content: 'very', type: 'em' }, + { content: 'long', type: 'em' }, + { content: 'text', type: 'em' }, + { content: 'about', type: 'normal' }, + { content: 'it', type: 'normal' }, + ], + [ + { content: 'Word', type: 'normal' }, + { content: '!', type: 'normal' }, + ], + ]; + + const output = markdownToLines(input); + expect(output).toEqual(expectedOutput); +}); + +test('markdownToHTML - Basic test', () => { + const input = `This is regular text +Here is a new line +There is some words **with a bold** section +Here is a line *with an italic* section`; + + const expectedOutput = `

This is regular text
Here is a new line
There is some words with a bold section
Here is a line with an italic section

`; + + const output = markdownToHTML(input); + expect(output).toEqual(expectedOutput); +}); + +test('markdownToHTML - Empty input', () => { + const input = ''; + const expectedOutput = ''; + const output = markdownToHTML(input); + expect(output).toEqual(expectedOutput); +}); + +test('markdownToHTML - No formatting', () => { + const input = `This is a simple test +with no formatting`; + + const expectedOutput = `

This is a simple test
with no formatting

`; + const output = markdownToHTML(input); + expect(output).toEqual(expectedOutput); +}); + +test('markdownToHTML - Only bold formatting', () => { + const input = `This is a **bold** test`; + + const expectedOutput = `

This is a bold test

`; + const output = markdownToHTML(input); + expect(output).toEqual(expectedOutput); +}); + +test('markdownToHTML - Only italic formatting', () => { + const input = `This is an *italic* test`; + + const expectedOutput = `

This is an italic test

`; + const output = markdownToHTML(input); + expect(output).toEqual(expectedOutput); +}); + +test('markdownToHTML - Mixed formatting', () => { + const input = `*Italic* and **bold** formatting`; + + const expectedOutput = `

Italic and bold formatting

`; + const output = markdownToHTML(input); + expect(output).toEqual(expectedOutput); +}); 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 a7a3a68e4..1847115cd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,387 +1,275 @@ -lockfileVersion: 5.4-inlineSpecifiers +lockfileVersion: 5.4 importers: .: + specifiers: + '@applitools/eyes-cypress': ^3.27.6 + '@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 + '@types/js-yaml': ^4.0.5 + '@types/jsdom': ^21.0.0 + '@types/lodash': ^4.14.188 + '@types/mdast': ^3.0.10 + '@types/node': ^18.11.9 + '@types/prettier': ^2.7.1 + '@types/rollup-plugin-visualizer': ^4.2.1 + '@typescript-eslint/eslint-plugin': ^5.48.2 + '@typescript-eslint/parser': ^5.48.2 + '@vitest/coverage-c8': ^0.29.0 + '@vitest/spy': ^0.29.0 + '@vitest/ui': ^0.29.0 + concurrently: ^7.5.0 + cors: ^2.8.5 + coveralls: ^3.1.1 + cypress: ^12.0.0 + cypress-image-snapshot: ^4.0.1 + esbuild: ^0.17.0 + eslint: ^8.32.0 + eslint-config-prettier: ^8.6.0 + eslint-plugin-cypress: ^2.12.1 + eslint-plugin-html: ^7.1.0 + eslint-plugin-jest: ^27.1.5 + eslint-plugin-jsdoc: ^39.6.2 + eslint-plugin-json: ^3.1.0 + eslint-plugin-lodash: ^7.4.0 + eslint-plugin-markdown: ^3.0.0 + eslint-plugin-no-only-tests: ^3.1.0 + eslint-plugin-tsdoc: ^0.2.17 + eslint-plugin-unicorn: ^45.0.0 + express: ^4.18.2 + globby: ^13.1.2 + husky: ^8.0.2 + jest: ^29.3.1 + jison: ^0.4.18 + js-yaml: ^4.1.0 + jsdom: ^21.0.0 + lint-staged: ^13.0.3 + path-browserify: ^1.0.1 + pnpm: ^7.15.0 + prettier: ^2.7.1 + prettier-plugin-jsdoc: ^0.4.2 + rimraf: ^4.0.0 + rollup-plugin-visualizer: ^5.8.3 + start-server-and-test: ^1.15.4 + ts-node: ^10.9.1 + typescript: ^4.8.4 + vite: ^4.1.1 + vitest: ^0.29.0 devDependencies: - '@applitools/eyes-cypress': - specifier: ^3.27.6 - version: 3.27.6 - '@commitlint/cli': - specifier: ^17.2.0 - version: 17.2.0 - '@commitlint/config-conventional': - specifier: ^17.2.0 - version: 17.2.0 - '@cspell/eslint-plugin': - specifier: ^6.14.2 - version: 6.14.2 - '@types/cors': - specifier: ^2.8.13 - version: 2.8.13 - '@types/eslint': - specifier: ^8.4.10 - version: 8.4.10 - '@types/express': - specifier: ^4.17.17 - version: 4.17.17 - '@types/js-yaml': - specifier: ^4.0.5 - version: 4.0.5 - '@types/jsdom': - specifier: ^21.0.0 - version: 21.1.0 - '@types/lodash': - specifier: ^4.14.188 - version: 4.14.188 - '@types/mdast': - specifier: ^3.0.10 - version: 3.0.10 - '@types/node': - specifier: ^18.11.9 - version: 18.11.9 - '@types/prettier': - specifier: ^2.7.1 - version: 2.7.1 - '@types/rollup-plugin-visualizer': - specifier: ^4.2.1 - version: 4.2.1 - '@typescript-eslint/eslint-plugin': - specifier: ^5.48.2 - version: 5.48.2_iljmjqxcygjq3saipl7gerxpvi - '@typescript-eslint/parser': - specifier: ^5.48.2 - version: 5.48.2_yygwinqv3a2io74xmwofqb7uka - '@vitest/coverage-c8': - specifier: ^0.29.0 - version: 0.29.2_vitest@0.29.2 - '@vitest/spy': - specifier: ^0.29.0 - version: 0.29.2 - '@vitest/ui': - specifier: ^0.29.0 - version: 0.29.2 - concurrently: - specifier: ^7.5.0 - version: 7.5.0 - cors: - specifier: ^2.8.5 - version: 2.8.5 - coveralls: - specifier: ^3.1.1 - version: 3.1.1 - cypress: - specifier: ^12.0.0 - version: 12.5.1 - cypress-image-snapshot: - specifier: ^4.0.1 - version: 4.0.1_cypress@12.5.1+jest@29.3.1 - esbuild: - specifier: ^0.17.0 - version: 0.17.0 - eslint: - specifier: ^8.32.0 - version: 8.32.0 - eslint-config-prettier: - specifier: ^8.6.0 - version: 8.6.0_eslint@8.32.0 - eslint-plugin-cypress: - specifier: ^2.12.1 - version: 2.12.1_eslint@8.32.0 - eslint-plugin-html: - specifier: ^7.1.0 - version: 7.1.0 - eslint-plugin-jest: - specifier: ^27.1.5 - version: 27.1.5_5rcd23qw3h5vuffwo2owxb3hw4 - eslint-plugin-jsdoc: - specifier: ^39.6.2 - version: 39.6.2_eslint@8.32.0 - eslint-plugin-json: - specifier: ^3.1.0 - version: 3.1.0 - eslint-plugin-lodash: - specifier: ^7.4.0 - version: 7.4.0_eslint@8.32.0 - eslint-plugin-markdown: - specifier: ^3.0.0 - version: 3.0.0_eslint@8.32.0 - eslint-plugin-no-only-tests: - specifier: ^3.1.0 - version: 3.1.0 - eslint-plugin-tsdoc: - specifier: ^0.2.17 - version: 0.2.17 - eslint-plugin-unicorn: - specifier: ^45.0.0 - version: 45.0.0_eslint@8.32.0 - express: - specifier: ^4.18.2 - version: 4.18.2 - globby: - specifier: ^13.1.2 - version: 13.1.2 - husky: - specifier: ^8.0.2 - version: 8.0.2 - jest: - specifier: ^29.3.1 - version: 29.3.1_odkjkoia5xunhxkdrka32ib6vi - jison: - specifier: ^0.4.18 - version: 0.4.18 - js-yaml: - specifier: ^4.1.0 - version: 4.1.0 - jsdom: - specifier: ^21.0.0 - version: 21.1.0 - lint-staged: - specifier: ^13.0.3 - version: 13.0.3 - path-browserify: - specifier: ^1.0.1 - version: 1.0.1 - pnpm: - specifier: ^7.15.0 - version: 7.15.0 - prettier: - specifier: ^2.7.1 - version: 2.7.1 - prettier-plugin-jsdoc: - specifier: ^0.4.2 - version: 0.4.2_prettier@2.7.1 - rimraf: - specifier: ^4.0.0 - version: 4.1.2 - rollup-plugin-visualizer: - specifier: ^5.8.3 - version: 5.8.3 - start-server-and-test: - specifier: ^1.15.4 - version: 1.15.4 - ts-node: - specifier: ^10.9.1 - version: 10.9.1_cbe7ovvae6zqfnmtgctpgpys54 - typescript: - specifier: ^4.8.4 - version: 4.8.4 - vite: - specifier: ^4.1.1 - version: 4.1.1_@types+node@18.11.9 - vitest: - specifier: ^0.29.0 - version: 0.29.2_hjnfa4mohew6fc4mnpzgbfyvpa + '@applitools/eyes-cypress': 3.27.6 + '@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 + '@types/js-yaml': 4.0.5 + '@types/jsdom': 21.1.0 + '@types/lodash': 4.14.188 + '@types/mdast': 3.0.10 + '@types/node': 18.11.9 + '@types/prettier': 2.7.1 + '@types/rollup-plugin-visualizer': 4.2.1 + '@typescript-eslint/eslint-plugin': 5.48.2_iljmjqxcygjq3saipl7gerxpvi + '@typescript-eslint/parser': 5.48.2_yygwinqv3a2io74xmwofqb7uka + '@vitest/coverage-c8': 0.29.2_vitest@0.29.2 + '@vitest/spy': 0.29.2 + '@vitest/ui': 0.29.2 + concurrently: 7.5.0 + cors: 2.8.5 + coveralls: 3.1.1 + cypress: 12.5.1 + cypress-image-snapshot: 4.0.1_cypress@12.5.1+jest@29.3.1 + esbuild: 0.17.0 + eslint: 8.32.0 + eslint-config-prettier: 8.6.0_eslint@8.32.0 + eslint-plugin-cypress: 2.12.1_eslint@8.32.0 + eslint-plugin-html: 7.1.0 + eslint-plugin-jest: 27.1.5_5rcd23qw3h5vuffwo2owxb3hw4 + eslint-plugin-jsdoc: 39.6.2_eslint@8.32.0 + eslint-plugin-json: 3.1.0 + eslint-plugin-lodash: 7.4.0_eslint@8.32.0 + eslint-plugin-markdown: 3.0.0_eslint@8.32.0 + eslint-plugin-no-only-tests: 3.1.0 + eslint-plugin-tsdoc: 0.2.17 + eslint-plugin-unicorn: 45.0.0_eslint@8.32.0 + express: 4.18.2 + globby: 13.1.2 + husky: 8.0.2 + jest: 29.3.1_odkjkoia5xunhxkdrka32ib6vi + jison: 0.4.18 + js-yaml: 4.1.0 + jsdom: 21.1.0 + lint-staged: 13.0.3 + path-browserify: 1.0.1 + pnpm: 7.15.0 + prettier: 2.7.1 + prettier-plugin-jsdoc: 0.4.2_prettier@2.7.1 + rimraf: 4.1.2 + rollup-plugin-visualizer: 5.8.3 + start-server-and-test: 1.15.4 + ts-node: 10.9.1_cbe7ovvae6zqfnmtgctpgpys54 + typescript: 4.8.4 + vite: 4.1.1_@types+node@18.11.9 + vitest: 0.29.2_hjnfa4mohew6fc4mnpzgbfyvpa packages/mermaid: + specifiers: + '@braintree/sanitize-url': ^6.0.0 + '@khanacademy/simple-markdown': ^0.8.6 + '@types/cytoscape': ^3.19.9 + '@types/d3': ^7.4.0 + '@types/dompurify': ^2.4.0 + '@types/jsdom': ^21.0.0 + '@types/lodash-es': ^4.17.7 + '@types/micromatch': ^4.0.2 + '@types/prettier': ^2.7.1 + '@types/stylis': ^4.0.2 + '@types/uuid': ^9.0.0 + '@typescript-eslint/eslint-plugin': ^5.42.1 + '@typescript-eslint/parser': ^5.42.1 + chokidar: ^3.5.3 + concurrently: ^7.5.0 + 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 + d3: ^7.4.0 + dagre-d3-es: 7.0.10 + dayjs: ^1.11.7 + dompurify: 2.4.5 + elkjs: ^0.8.2 + globby: ^13.1.2 + jison: ^0.4.18 + js-base64: ^3.7.2 + jsdom: ^21.0.0 + khroma: ^2.0.0 + lodash-es: ^4.17.21 + micromatch: ^4.0.5 + non-layered-tidy-tree-layout: ^2.0.2 + path-browserify: ^1.0.1 + prettier: ^2.7.1 + remark: ^14.0.2 + remark-frontmatter: ^4.0.1 + remark-gfm: ^3.0.1 + rimraf: ^4.0.0 + start-server-and-test: ^1.14.0 + stylis: ^4.1.2 + ts-dedent: ^2.2.0 + typedoc: ^0.23.18 + typedoc-plugin-markdown: ^3.13.6 + typescript: ^4.8.4 + unist-util-flatmap: ^1.0.0 + uuid: ^9.0.0 + vitepress: ^1.0.0-alpha.46 + vitepress-plugin-search: ^1.0.4-alpha.19 + web-worker: ^1.2.0 dependencies: - '@braintree/sanitize-url': - specifier: ^6.0.0 - version: 6.0.0 - cytoscape: - specifier: ^3.23.0 - version: 3.23.0 - cytoscape-cose-bilkent: - specifier: ^4.1.0 - version: 4.1.0_cytoscape@3.23.0 - cytoscape-fcose: - specifier: ^2.1.0 - version: 2.1.0_cytoscape@3.23.0 - d3: - specifier: ^7.4.0 - version: 7.8.2 - dagre-d3-es: - specifier: 7.0.9 - version: 7.0.9 - dayjs: - specifier: ^1.11.7 - version: 1.11.7 - dompurify: - specifier: 2.4.5 - version: 2.4.5 - elkjs: - specifier: ^0.8.2 - version: 0.8.2 - khroma: - specifier: ^2.0.0 - version: 2.0.0 - lodash-es: - specifier: ^4.17.21 - version: 4.17.21 - non-layered-tidy-tree-layout: - specifier: ^2.0.2 - version: 2.0.2 - stylis: - specifier: ^4.1.2 - version: 4.1.2 - ts-dedent: - specifier: ^2.2.0 - version: 2.2.0 - uuid: - specifier: ^9.0.0 - version: 9.0.0 - web-worker: - specifier: ^1.2.0 - version: 1.2.0 + '@braintree/sanitize-url': 6.0.0 + '@khanacademy/simple-markdown': 0.8.6_wcqkhtmu7mswc6yz4uyexck3ty + cytoscape: 3.23.0 + cytoscape-cose-bilkent: 4.1.0_cytoscape@3.23.0 + cytoscape-fcose: 2.1.0_cytoscape@3.23.0 + d3: 7.8.2 + dagre-d3-es: 7.0.10 + dayjs: 1.11.7 + dompurify: 2.4.5 + elkjs: 0.8.2 + khroma: 2.0.0 + lodash-es: 4.17.21 + non-layered-tidy-tree-layout: 2.0.2 + stylis: 4.1.2 + ts-dedent: 2.2.0 + uuid: 9.0.0 + web-worker: 1.2.0 devDependencies: - '@types/cytoscape': - specifier: ^3.19.9 - version: 3.19.9 - '@types/d3': - specifier: ^7.4.0 - version: 7.4.0 - '@types/dompurify': - specifier: ^2.4.0 - version: 2.4.0 - '@types/jsdom': - specifier: ^21.0.0 - version: 21.1.0 - '@types/lodash-es': - specifier: ^4.17.6 - version: 4.17.6 - '@types/micromatch': - specifier: ^4.0.2 - version: 4.0.2 - '@types/prettier': - specifier: ^2.7.1 - version: 2.7.1 - '@types/stylis': - specifier: ^4.0.2 - version: 4.0.2 - '@types/uuid': - specifier: ^9.0.0 - version: 9.0.0 - '@typescript-eslint/eslint-plugin': - specifier: ^5.42.1 - version: 5.42.1_qxgr6oy2qtsmmpo3f6iejuryuq - '@typescript-eslint/parser': - specifier: ^5.42.1 - version: 5.42.1_yygwinqv3a2io74xmwofqb7uka - chokidar: - specifier: ^3.5.3 - version: 3.5.3 - concurrently: - specifier: ^7.5.0 - version: 7.5.0 - coveralls: - specifier: ^3.1.1 - version: 3.1.1 - cpy-cli: - specifier: ^4.2.0 - version: 4.2.0 - cspell: - specifier: ^6.14.3 - version: 6.14.3 - globby: - specifier: ^13.1.2 - version: 13.1.2 - jison: - specifier: ^0.4.18 - version: 0.4.18 - js-base64: - specifier: ^3.7.2 - version: 3.7.2 - jsdom: - specifier: ^21.0.0 - version: 21.1.0 - micromatch: - specifier: ^4.0.5 - version: 4.0.5 - path-browserify: - specifier: ^1.0.1 - version: 1.0.1 - prettier: - specifier: ^2.7.1 - version: 2.7.1 - remark: - specifier: ^14.0.2 - version: 14.0.2 - remark-frontmatter: - specifier: ^4.0.1 - version: 4.0.1 - remark-gfm: - specifier: ^3.0.1 - version: 3.0.1 - rimraf: - specifier: ^4.0.0 - version: 4.1.2 - start-server-and-test: - specifier: ^1.14.0 - version: 1.14.0 - typedoc: - specifier: ^0.23.18 - version: 0.23.18_typescript@4.8.4 - typedoc-plugin-markdown: - specifier: ^3.13.6 - version: 3.13.6_typedoc@0.23.18 - typescript: - specifier: ^4.8.4 - version: 4.8.4 - unist-util-flatmap: - specifier: ^1.0.0 - version: 1.0.0 - vitepress: - specifier: ^1.0.0-alpha.46 - version: 1.0.0-alpha.46_tbpndr44ulefs3hehwpi2mkf2y - vitepress-plugin-search: - specifier: ^1.0.4-alpha.19 - version: 1.0.4-alpha.19_g67lr3vgasogkevpbew55lljzq + '@types/cytoscape': 3.19.9 + '@types/d3': 7.4.0 + '@types/dompurify': 2.4.0 + '@types/jsdom': 21.1.0 + '@types/lodash-es': 4.17.7 + '@types/micromatch': 4.0.2 + '@types/prettier': 2.7.1 + '@types/stylis': 4.0.2 + '@types/uuid': 9.0.0 + '@typescript-eslint/eslint-plugin': 5.42.1_qxgr6oy2qtsmmpo3f6iejuryuq + '@typescript-eslint/parser': 5.42.1_yygwinqv3a2io74xmwofqb7uka + chokidar: 3.5.3 + concurrently: 7.5.0 + 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 + jsdom: 21.1.0 + micromatch: 4.0.5 + path-browserify: 1.0.1 + prettier: 2.7.1 + remark: 14.0.2 + remark-frontmatter: 4.0.1 + remark-gfm: 3.0.1 + rimraf: 4.1.2 + start-server-and-test: 1.14.0 + typedoc: 0.23.18_typescript@4.8.4 + typedoc-plugin-markdown: 3.13.6_typedoc@0.23.18 + typescript: 4.8.4 + unist-util-flatmap: 1.0.0 + vitepress: 1.0.0-alpha.46_hoyvfk3ab7nzsjkhptt6ai7rzq + vitepress-plugin-search: 1.0.4-alpha.19_g67lr3vgasogkevpbew55lljzq packages/mermaid-example-diagram: + specifiers: + '@braintree/sanitize-url': ^6.0.0 + '@types/cytoscape': ^3.19.9 + concurrently: ^7.5.0 + cytoscape: ^3.23.0 + cytoscape-cose-bilkent: ^4.1.0 + cytoscape-fcose: ^2.1.0 + d3: ^7.0.0 + khroma: ^2.0.0 + mermaid: workspace:* + non-layered-tidy-tree-layout: ^2.0.2 + rimraf: ^4.0.0 dependencies: - '@braintree/sanitize-url': - specifier: ^6.0.0 - version: 6.0.0 - cytoscape: - specifier: ^3.23.0 - version: 3.23.0 - cytoscape-cose-bilkent: - specifier: ^4.1.0 - version: 4.1.0_cytoscape@3.23.0 - cytoscape-fcose: - specifier: ^2.1.0 - version: 2.1.0_cytoscape@3.23.0 - d3: - specifier: ^7.0.0 - version: 7.8.2 - khroma: - specifier: ^2.0.0 - version: 2.0.0 - non-layered-tidy-tree-layout: - specifier: ^2.0.2 - version: 2.0.2 + '@braintree/sanitize-url': 6.0.0 + cytoscape: 3.23.0 + cytoscape-cose-bilkent: 4.1.0_cytoscape@3.23.0 + cytoscape-fcose: 2.1.0_cytoscape@3.23.0 + d3: 7.8.2 + khroma: 2.0.0 + non-layered-tidy-tree-layout: 2.0.2 devDependencies: - '@types/cytoscape': - specifier: ^3.19.9 - version: 3.19.9 - concurrently: - specifier: ^7.5.0 - version: 7.5.0 - mermaid: - specifier: workspace:* - version: link:../mermaid - rimraf: - specifier: ^4.0.0 - version: 4.1.2 + '@types/cytoscape': 3.19.9 + concurrently: 7.5.0 + mermaid: link:../mermaid + rimraf: 4.1.2 tests/webpack: + specifiers: + '@mermaid-js/mermaid-example-diagram': workspace:* + mermaid: workspace:* + webpack: ^5.74.0 + webpack-cli: ^4.10.0 + webpack-dev-server: ^4.11.1 dependencies: - '@mermaid-js/mermaid-example-diagram': - specifier: workspace:* - version: link:../../packages/mermaid-example-diagram - mermaid: - specifier: workspace:* - version: link:../../packages/mermaid + '@mermaid-js/mermaid-example-diagram': link:../../packages/mermaid-example-diagram + mermaid: link:../../packages/mermaid devDependencies: - webpack: - specifier: ^5.74.0 - version: 5.75.0_webpack-cli@4.10.0 - webpack-cli: - specifier: ^4.10.0 - version: 4.10.0_uaydpeuxkjjcxdbyfgk36cjdxi - webpack-dev-server: - specifier: ^4.11.1 - version: 4.11.1_pda42hcaj7d62cr262fr632kue + webpack: 5.75.0_webpack-cli@4.10.0 + webpack-cli: 4.10.0_uaydpeuxkjjcxdbyfgk36cjdxi + webpack-dev-server: 4.11.1_pda42hcaj7d62cr262fr632kue packages: @@ -1705,10 +1593,10 @@ packages: resolution: {integrity: sha512-6SCwI7P8ao+se1TUsdZ7B4XzL+gqeQZnBc+2EONZlcVa0dVrk0NjETxozFKgMv0eEGH8QzP1fkN+A1rH61l4eg==} dev: true - /@docsearch/js/3.3.3_tbpndr44ulefs3hehwpi2mkf2y: + /@docsearch/js/3.3.3_hoyvfk3ab7nzsjkhptt6ai7rzq: resolution: {integrity: sha512-2xAv2GFuHzzmG0SSZgf8wHX0qZX8n9Y1ZirKUk5Wrdc+vH9CL837x2hZIUdwcPZI9caBA+/CzxsS68O4waYjUQ==} dependencies: - '@docsearch/react': 3.3.3_tbpndr44ulefs3hehwpi2mkf2y + '@docsearch/react': 3.3.3_hoyvfk3ab7nzsjkhptt6ai7rzq preact: 10.11.0 transitivePeerDependencies: - '@algolia/client-search' @@ -1717,7 +1605,7 @@ packages: - react-dom dev: true - /@docsearch/react/3.3.3_tbpndr44ulefs3hehwpi2mkf2y: + /@docsearch/react/3.3.3_hoyvfk3ab7nzsjkhptt6ai7rzq: resolution: {integrity: sha512-pLa0cxnl+G0FuIDuYlW+EBK6Rw2jwLw9B1RHIeS4N4s2VhsfJ/wzeCi3CWcs5yVfxLd5ZK50t//TMA5e79YT7Q==} peerDependencies: '@types/react': '>= 16.8.0 < 19.0.0' @@ -1735,6 +1623,8 @@ packages: '@algolia/autocomplete-preset-algolia': 1.7.4_qs6lk5nhygj2o3hj4sf6xnr724 '@docsearch/css': 3.3.3 algoliasearch: 4.14.2 + react: 16.14.0 + react-dom: 16.14.0_react@16.14.0 transitivePeerDependencies: - '@algolia/client-search' dev: true @@ -2464,6 +2354,17 @@ packages: '@jridgewell/sourcemap-codec': 1.4.14 dev: true + /@khanacademy/simple-markdown/0.8.6_wcqkhtmu7mswc6yz4uyexck3ty: + resolution: {integrity: sha512-mAUlR9lchzfqunR89pFvNI51jQKsMpJeWYsYWw0DQcUXczn/T/V6510utgvm7X0N3zN87j1SvuKk8cMbl9IAFw==} + peerDependencies: + react: 16.14.0 + react-dom: 16.14.0 + dependencies: + '@types/react': 18.0.33 + react: 16.14.0 + react-dom: 16.14.0_react@16.14.0 + dev: false + /@leichtgewicht/ip-codec/2.0.4: resolution: {integrity: sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A==} dev: true @@ -2506,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: @@ -2971,8 +2904,8 @@ packages: resolution: {integrity: sha512-HZQYqbiFVWufzCwexrvh694SOim8z2d+xJl5UNamcvQFejLY/2YUtzXHYi3cHdI7PMlS8ejH2slRAOJQ32aNbA==} dev: true - /@types/lodash-es/4.17.6: - resolution: {integrity: sha512-R+zTeVUKDdfoRxpAryaQNRKk3105Rrgx2CFRClIgRGaqDTdjsm8h6IYA8ir584W3ePzkZfst5xIgDwYrlh9HLg==} + /@types/lodash-es/4.17.7: + resolution: {integrity: sha512-z0ptr6UI10VlU6l5MYhGwS4mC8DZyYer2mCoyysZtSF7p26zOX8UpbrV0YpNYLGS8K4PUFIyEr62IMFFjveSiQ==} dependencies: '@types/lodash': 4.14.188 dev: true @@ -3047,6 +2980,10 @@ packages: resolution: {integrity: sha512-ri0UmynRRvZiiUJdiz38MmIblKK+oH30MztdBVR95dv/Ubw6neWSb8u1XpRb72L4qsZOhz+L+z9JD40SJmfWow==} dev: true + /@types/prop-types/15.7.5: + resolution: {integrity: sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==} + dev: false + /@types/qs/6.9.7: resolution: {integrity: sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==} dev: true @@ -3055,6 +2992,14 @@ packages: resolution: {integrity: sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==} dev: true + /@types/react/18.0.33: + resolution: {integrity: sha512-sHxzVxeanvQyQ1lr8NSHaj0kDzcNiGpILEVt69g9S31/7PfMvNCKLKcsHw4lYKjs3cGNJjXSP4mYzX43QlnjNA==} + dependencies: + '@types/prop-types': 15.7.5 + '@types/scheduler': 0.16.3 + csstype: 3.1.2 + dev: false + /@types/responselike/1.0.0: resolution: {integrity: sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA==} dependencies: @@ -3072,6 +3017,10 @@ packages: rollup: 2.79.1 dev: true + /@types/scheduler/0.16.3: + resolution: {integrity: sha512-5cJ8CB4yAx7BH1oMvdU0Jh9lrEXyPkar6F9G/ERswkCuvP4KQZfZkSjcMbAICCpQTN4OuZn8tz0HiKv9TGZgrQ==} + dev: false + /@types/semver/7.3.12: resolution: {integrity: sha512-WwA1MW0++RfXmCr12xeYOOC5baSC9mSb0ZqCquFzKhcoF4TvHu5MKOuXsncgZcpVFhB1pXd5hZmM0ryAoCp12A==} dev: true @@ -3504,7 +3453,7 @@ packages: '@vue/shared': 3.2.45 estree-walker: 2.0.2 magic-string: 0.25.9 - postcss: 8.4.20 + postcss: 8.4.21 source-map: 0.6.1 dev: true @@ -4596,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'} @@ -5229,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 @@ -5244,10 +5208,24 @@ 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.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: resolution: {integrity: sha512-PBpnhX/XItlx3/DAk5ozsXQHUi72exybBNH5Mpqj1DVmjq+S5Jd9WE5CRa4q5q0zuMZb2V2VpXHth6MjFpgj9Q==} engines: {node: '>=8'} @@ -5589,8 +5567,8 @@ packages: d3-zoom: 3.0.0 dev: false - /dagre-d3-es/7.0.9: - resolution: {integrity: sha512-rYR4QfVmy+sR44IBDvVtcAmOReGBvRCWDpO2QjYwqgh9yijw6eSHBqaPG/LIOEy7aBsniLvtMW6pg19qJhq60w==} + /dagre-d3-es/7.0.10: + resolution: {integrity: sha512-qTCQmEhcynucuaZgY5/+ti3X/rnszKZhEQH/ZdWdtP1tA/y3VoHJzcVrO9pjjJCNpigfscAtoUB5ONcd2wNn0A==} dependencies: d3: 7.8.2 lodash-es: 4.17.21 @@ -8213,7 +8191,6 @@ packages: /js-tokens/4.0.0: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} - dev: true /js-yaml/3.14.1: resolution: {integrity: sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==} @@ -8621,6 +8598,12 @@ packages: resolution: {integrity: sha512-cHlYSUpL2s7Fb3394mYxwTYj8niTaNHUCLr0qdiCXQfSjfuA7CKofpX2uSwEfFDQ0EB7JcnMnm+GjbqqoinYYg==} dev: true + /loose-envify/1.4.0: + resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==} + hasBin: true + dependencies: + js-tokens: 4.0.0 + /loupe/2.3.6: resolution: {integrity: sha512-RaPMZKiMy8/JruncMU5Bt6na1eftNoo++R4Y+N2FrxkDVTrGvcyzFTsaGif4QTeKESheMGegbhw6iUAq+5A8zA==} dependencies: @@ -8828,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 @@ -9432,7 +9419,6 @@ packages: /object-assign/4.1.1: resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==} engines: {node: '>=0.10.0'} - dev: true /object-inspect/1.12.2: resolution: {integrity: sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ==} @@ -9856,15 +9842,6 @@ packages: resolution: {integrity: sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==} dev: true - /postcss/8.4.20: - resolution: {integrity: sha512-6Q04AXR1212bXr5fh03u8aAwbLxAQNGQ/Q1LNa0VfOI06ZAlhPHtQvE4OIdpj4kLThXilalPnmDSOD65DcHt+g==} - engines: {node: ^10 || ^12 || >=14} - dependencies: - nanoid: 3.3.4 - picocolors: 1.0.0 - source-map-js: 1.0.2 - dev: true - /postcss/8.4.21: resolution: {integrity: sha512-tP7u/Sn/dVxK2NnruI4H9BG+x+Wxz6oeZ1cJ8P6G/PZY0IKk4k/63TDsQf2kQq3+qoJeLm2kIBUNlZe3zgb4Zg==} engines: {node: ^10 || ^12 || >=14} @@ -9943,6 +9920,13 @@ packages: sisteransi: 1.0.5 dev: true + /prop-types/15.8.1: + resolution: {integrity: sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==} + dependencies: + loose-envify: 1.4.0 + object-assign: 4.1.1 + react-is: 16.13.1 + /proxy-addr/2.0.7: resolution: {integrity: sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==} engines: {node: '>= 0.10'} @@ -10055,6 +10039,20 @@ packages: unpipe: 1.0.0 dev: true + /react-dom/16.14.0_react@16.14.0: + resolution: {integrity: sha512-1gCeQXDLoIqMgqD3IO2Ah9bnf0w9kzhwN5q4FGnHZ67hBm9yePzB5JJAIQCc8x3pFnNlwFq4RidZggNAAkzWWw==} + peerDependencies: + react: ^16.14.0 + dependencies: + loose-envify: 1.4.0 + object-assign: 4.1.1 + prop-types: 15.8.1 + react: 16.14.0 + scheduler: 0.19.1 + + /react-is/16.13.1: + resolution: {integrity: sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==} + /react-is/17.0.2: resolution: {integrity: sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==} dev: true @@ -10063,6 +10061,14 @@ packages: resolution: {integrity: sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==} dev: true + /react/16.14.0: + resolution: {integrity: sha512-0X2CImDkJGApiAlcf0ODKIneSwBPhqJawOa5wCtKbu7ZECrmS26NvtSILynQ66cgkT/RJ4LidJOc3bUESwmU8g==} + engines: {node: '>=0.10.0'} + dependencies: + loose-envify: 1.4.0 + object-assign: 4.1.1 + prop-types: 15.8.1 + /read-pkg-up/7.0.1: resolution: {integrity: sha512-zK0TB7Xd6JpCLmlLmufqykGE+/TlOePD6qKClNW7hHDKFh/J7/7gCWGR7joEQEW1bKq3a3yUZSObOoWLFQ4ohg==} engines: {node: '>=8'} @@ -10471,6 +10477,12 @@ packages: xmlchars: 2.2.0 dev: true + /scheduler/0.19.1: + resolution: {integrity: sha512-n/zwRWRYSUj0/3g/otKDRPMh6qv2SYMWNq85IEa8iZyAv8od9zDYpGSnpBEjNgcMNq6Scbu5KfIPxNF72R/2EA==} + dependencies: + loose-envify: 1.4.0 + object-assign: 4.1.1 + /schema-utils/3.1.1: resolution: {integrity: sha512-Y5PQxS4ITlC+EahLuXaY86TXfR7Dc5lw294alXOq86JAHCihAIZfqv8nNCWvaEJvaC51uN9hbLGeV0cFBdH+Fw==} engines: {node: '>= 10.13.0'} @@ -11769,16 +11781,16 @@ packages: '@types/markdown-it': 12.2.3 flexsearch: 0.7.31 markdown-it: 13.0.1 - vitepress: 1.0.0-alpha.46_tbpndr44ulefs3hehwpi2mkf2y + vitepress: 1.0.0-alpha.46_hoyvfk3ab7nzsjkhptt6ai7rzq vue: 3.2.45 dev: true - /vitepress/1.0.0-alpha.46_tbpndr44ulefs3hehwpi2mkf2y: + /vitepress/1.0.0-alpha.46_hoyvfk3ab7nzsjkhptt6ai7rzq: resolution: {integrity: sha512-HiKiHzC0iTPsRsKs8XcsMeMzCpcCt5LWcX9mpDr288Ju+nQf1G8A2+Wm44ZkBsVv4EHxFK4ChmWyZrL1OJUXpg==} hasBin: true dependencies: '@docsearch/css': 3.3.3 - '@docsearch/js': 3.3.3_tbpndr44ulefs3hehwpi2mkf2y + '@docsearch/js': 3.3.3_hoyvfk3ab7nzsjkhptt6ai7rzq '@vitejs/plugin-vue': 4.0.0_vite@4.1.1+vue@3.2.45 '@vue/devtools-api': 6.5.0 '@vueuse/core': 9.12.0_vue@3.2.45 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,