diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 000000000..025779ed2 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +yarn pre-commit diff --git a/.lintstagedrc.json b/.lintstagedrc.json new file mode 100644 index 000000000..f9b7eed74 --- /dev/null +++ b/.lintstagedrc.json @@ -0,0 +1,5 @@ +{ + "*": [ + "yarn lint:fix" + ] +} diff --git a/README.md b/README.md index d620bb8ee..6f52c6d7d 100644 --- a/README.md +++ b/README.md @@ -204,7 +204,7 @@ pie - [Live Editor](https://github.com/mermaid-js/mermaid-live-editor) - [HTTP Server](https://github.com/TomWright/mermaid-server) -## Contributors [](https://github.com/mermaid-js/mermaid/issues?q=is%3Aissue+is%3Aopen+label%3A%22Help+wanted%21%22) [](https://github.com/mermaid-js/mermaid/graphs/contributors) [](https://github.com/mermaid-js/mermaid/graphs/contributors) +## Contributors [](https://github.com/mermaid-js/mermaid/issues?q=is%3Aissue+is%3Aopen+label%3A%22Good+first+issue%21%22) [](https://github.com/mermaid-js/mermaid/graphs/contributors) [](https://github.com/mermaid-js/mermaid/graphs/contributors) Mermaid is a growing community and is always accepting new contributors. There's a lot of different ways to help out and we're always looking for extra hands! Look at [this issue](https://github.com/mermaid-js/mermaid/issues/866) if you want to know where to start helping out. diff --git a/README.zh-CN.md b/README.zh-CN.md index 416589ee4..7252f3d34 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -201,7 +201,7 @@ pie - [Live Editor](https://github.com/mermaid-js/mermaid-live-editor) - [HTTP Server](https://github.com/TomWright/mermaid-server) -## 贡献者 [](https://github.com/mermaid-js/mermaid/issues?q=is%3Aissue+is%3Aopen+label%3A%22Help+wanted%21%22) [](https://github.com/mermaid-js/mermaid/graphs/contributors) [](https://github.com/mermaid-js/mermaid/graphs/contributors) +## 贡献者 [](https://github.com/mermaid-js/mermaid/issues?q=is%3Aissue+is%3Aopen+label%3A%22Good+first+issue%21%22) [](https://github.com/mermaid-js/mermaid/graphs/contributors) [](https://github.com/mermaid-js/mermaid/graphs/contributors) Mermaid 是一个不断发展中的社区,并且还在接收新的贡献者。有很多不同的方式可以参与进来,而且我们还在寻找额外的帮助。如果你想知道如何开始贡献,请查看 [这个 issue](https://github.com/mermaid-js/mermaid/issues/866)。 diff --git a/cypress/integration/other/xss.spec.js b/cypress/integration/other/xss.spec.js index 911acc71e..529eee16d 100644 --- a/cypress/integration/other/xss.spec.js +++ b/cypress/integration/other/xss.spec.js @@ -105,4 +105,9 @@ describe('XSS', () => { cy.wait(1000); cy.get('#the-malware').should('not.exist'); }); + it('should not allow maniplulating antiscript to run javascript iframes in class diagrams', () => { + cy.visit('http://localhost:9000/xss14.html'); + cy.wait(1000); + cy.get('#the-malware').should('not.exist'); + }); }); diff --git a/cypress/integration/rendering/flowchart-v2.spec.js b/cypress/integration/rendering/flowchart-v2.spec.js index 28ee03014..60fba981e 100644 --- a/cypress/integration/rendering/flowchart-v2.spec.js +++ b/cypress/integration/rendering/flowchart-v2.spec.js @@ -610,7 +610,7 @@ flowchart RL imgSnapshotTest( `flowchart TB a{{"Lorem 'ipsum' dolor 'sit' amet, 'consectetur' adipiscing 'elit'."}} - --> b{{"Lorem #quot;ipsum#quot; dolor #quot;sit#quot; amet,#quot;consectetur#quot; adipiscing #quot;elit#quot;."}} + --> b{{"Lorem #quot;ipsum#quot; dolor #quot;sit#quot; amet,#quot;consectetur#quot; adipiscing #quot;elit#quot;."}} `, { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' } ); @@ -638,4 +638,15 @@ flowchart RL { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' } ); }); + + it('2388: handling default in the node name', () => { + imgSnapshotTest( + ` + flowchart LR + default-index.js --> dot.template.js + index.js --> module-utl.js + `, + { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' } + ); + }); }); diff --git a/cypress/platform/xss14.html b/cypress/platform/xss14.html new file mode 100644 index 000000000..f8d1ccb22 --- /dev/null +++ b/cypress/platform/xss14.html @@ -0,0 +1,104 @@ + +
+ + + + + + + +mermaid.initialize({ flowchart:{ htmlLabels: false } });\r\n *\r\n * **Example 2:**
\r\n *\r\n * A summary of all options and their defaults is found [here](#mermaidapi-configuration-defaults).\r\n * A description of each option follows below.\r\n *\r\n * @name Configuration\r\n */\r\nconst config = {\r\n /**\r\n * Theme , the CSS style sheet\r\n *\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------- | --------------- | ------ | -------- | ---------------------------------------------- |\r\n * | theme | Built in Themes | string | Optional | 'default', 'forest', 'dark', 'neutral', 'null' |\r\n *\r\n * **Notes:** To disable any pre-defined mermaid theme, use \"null\".
\"theme\": \"forest\",\r\n * \"themeCSS\": \".node rect { fill: red; }\"\r\n */\r\n theme: 'default',\r\n themeVariables: theme['default'].getThemeVariables(),\r\n themeCSS: undefined,\r\n /* **maxTextSize** - The maximum allowed size of the users text diamgram */\r\n maxTextSize: 50000,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ---------- | ------------------------------------------------------ | ------ | -------- | --------------------------- |\r\n * | fontFamily | specifies the font to be used in the rendered diagrams | string | Required | Any Possible CSS FontFamily |\r\n *\r\n * **Notes:** Default value: '\"trebuchet ms\", verdana, arial, sans-serif;'.\r\n */\r\n fontFamily: '\"trebuchet ms\", verdana, arial, sans-serif;',\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------- | ----------------------------------------------------- | ---------------- | -------- | ------------- |\r\n * | logLevel | This option decides the amount of logging to be used. | string \\| number | Required | 1, 2, 3, 4, 5 |\r\n *\r\n * **Notes:**\r\n *\r\n * - Debug: 1\r\n * - Info: 2\r\n * - Warn: 3\r\n * - Error: 4\r\n * - Fatal: 5 (default)\r\n */\r\n logLevel: 5,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ------------- | --------------------------------- | ------ | -------- | ------------------------------- |\r\n * | securitylevel | Level of trust for parsed diagram | string | Required | 'strict', 'loose', 'antiscript' |\r\n *\r\n * **Notes**:\r\n *\r\n * - **strict**: (**default**) tags in text are encoded, click functionality is disabled\r\n * - **loose**: tags in text are allowed, click functionality is enabled\r\n * - **antiscript**: html tags in text are allowed, (only script element is removed), click\r\n * functionality is enabled\r\n */\r\n securityLevel: 'strict',\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ----------- | -------------------------------------------- | ------- | -------- | ----------- |\r\n * | startOnLoad | Dictates whether mermaid starts on Page load | boolean | Required | true, false |\r\n *\r\n * **Notes:** Default value: true\r\n */\r\n startOnLoad: true,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ------------------- | ---------------------------------------------------------------------------- | ------- | -------- | ----------- |\r\n * | arrowMarkerAbsolute | Controls whether or arrow markers in html code are absolute paths or anchors | boolean | Required | true, false |\r\n *\r\n * **Notes**:\r\n *\r\n * This matters if you are using base tag settings.\r\n *\r\n * Default value: false\r\n */\r\n arrowMarkerAbsolute: false,\r\n\r\n /**\r\n * This option controls which currentConfig keys are considered *secure* and can only be changed\r\n * via call to mermaidAPI.initialize. Calls to mermaidAPI.reinitialize cannot make changes to the\r\n * `secure` keys in the current currentConfig. This prevents malicious graph directives from\r\n * overriding a site's default security.\r\n *\r\n * **Notes**:\r\n *\r\n * Default value: ['secure', 'securityLevel', 'startOnLoad', 'maxTextSize']\r\n */\r\n secure: ['secure', 'securityLevel', 'startOnLoad', 'maxTextSize'],\r\n\r\n /**\r\n * This option controls if the generated ids of nodes in the SVG are generated randomly or based\r\n * on a seed. If set to false, the IDs are generated based on the current date and thus are not\r\n * deterministic. This is the default behaviour.\r\n *\r\n * **Notes**:\r\n *\r\n * This matters if your files are checked into sourcecontrol e.g. git and should not change unless\r\n * content is changed.\r\n *\r\n * Default value: false\r\n */\r\n deterministicIds: false,\r\n\r\n /**\r\n * This option is the optional seed for deterministic ids. if set to undefined but\r\n * deterministicIds is true, a simple number iterator is used. You can set this attribute to base\r\n * the seed on a static string.\r\n */\r\n deterministicIDSeed: undefined,\r\n\r\n /** The object containing configurations specific for flowcharts */\r\n flowchart: {\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | -------------- | ----------------------------------------------- | ------- | -------- | ------------------ |\r\n * | diagramPadding | Amount of padding around the diagram as a whole | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:**\r\n *\r\n * The amount of padding around the diagram as a whole so that embedded diagrams have margins,\r\n * expressed in pixels\r\n *\r\n * Default value: 8\r\n */\r\n diagramPadding: 8,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ---------- | -------------------------------------------------------------------------------------------- | ------- | -------- | ----------- |\r\n * | htmlLabels | Flag for setting whether or not a html tag should be used for rendering labels on the edges. | boolean | Required | true, false |\r\n *\r\n * **Notes:** Default value: true.\r\n */\r\n htmlLabels: true,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ----------- | --------------------------------------------------- | ------- | -------- | ------------------- |\r\n * | nodeSpacing | Defines the spacing between nodes on the same level | Integer | Required | Any positive Number |\r\n *\r\n * **Notes:**\r\n *\r\n * Pertains to horizontal spacing for TB (top to bottom) or BT (bottom to top) graphs, and the\r\n * vertical spacing for LR as well as RL graphs.**\r\n *\r\n * Default value: 50\r\n */\r\n nodeSpacing: 50,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ----------- | ----------------------------------------------------- | ------- | -------- | ------------------- |\r\n * | rankSpacing | Defines the spacing between nodes on different levels | Integer | Required | Any Positive Number |\r\n *\r\n * **Notes**:\r\n *\r\n * Pertains to vertical spacing for TB (top to bottom) or BT (bottom to top), and the horizontal\r\n * spacing for LR as well as RL graphs.\r\n *\r\n * Default value 50\r\n */\r\n rankSpacing: 50,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------- | -------------------------------------------------- | ------ | -------- | ----------------------------- |\r\n * | curve | Defines how mermaid renders curves for flowcharts. | string | Required | 'basis', 'linear', 'cardinal' |\r\n *\r\n * **Notes:**\r\n *\r\n * Default Value: 'basis'\r\n */\r\n curve: 'basis',\r\n // Only used in new experimental rendering\r\n // represents the padding between the labels and the shape\r\n padding: 15,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ----------- | ----------- | ------- | -------- | ----------- |\r\n * | useMaxWidth | See notes | boolean | 4 | true, false |\r\n *\r\n * **Notes:**\r\n *\r\n * When this flag is set the height and width is set to 100% and is then scaling with the\r\n * available space if not the absolute space required is used.\r\n *\r\n * Default value: true\r\n */\r\n useMaxWidth: true,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------------- | ----------- | ------- | -------- | ----------------------- |\r\n * | defaultRenderer | See notes | boolean | 4 | dagre-d3, dagre-wrapper |\r\n *\r\n * **Notes:**\r\n *\r\n * Decides which rendering engine that is to be used for the rendering. Legal values are:\r\n * dagre-d3 dagre-wrapper - wrapper for dagre implemented in mermaid\r\n *\r\n * Default value: 'dagre-d3'\r\n */\r\n defaultRenderer: 'dagre-d3',\r\n },\r\n\r\n /** The object containing configurations specific for sequence diagrams */\r\n sequence: {\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------------- | ---------------------------- | ------- | -------- | ------------------ |\r\n * | activationWidth | Width of the activation rect | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value :10\r\n */\r\n activationWidth: 10,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | -------------- | ---------------------------------------------------- | ------- | -------- | ------------------ |\r\n * | diagramMarginX | Margin to the right and left of the sequence diagram | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 50\r\n */\r\n diagramMarginX: 50,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | -------------- | ------------------------------------------------- | ------- | -------- | ------------------ |\r\n * | diagramMarginY | Margin to the over and under the sequence diagram | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 10\r\n */\r\n diagramMarginY: 10,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ----------- | --------------------- | ------- | -------- | ------------------ |\r\n * | actorMargin | Margin between actors | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 50\r\n */\r\n actorMargin: 50,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------- | -------------------- | ------- | -------- | ------------------ |\r\n * | width | Width of actor boxes | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 150\r\n */\r\n width: 150,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------- | --------------------- | ------- | -------- | ------------------ |\r\n * | height | Height of actor boxes | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 65\r\n */\r\n height: 65,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------- | ------------------------ | ------- | -------- | ------------------ |\r\n * | boxMargin | Margin around loop boxes | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 10\r\n */\r\n boxMargin: 10,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ------------- | -------------------------------------------- | ------- | -------- | ------------------ |\r\n * | boxTextMargin | Margin around the text in loop/alt/opt boxes | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 5\r\n */\r\n boxTextMargin: 5,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ---------- | ------------------- | ------- | -------- | ------------------ |\r\n * | noteMargin | margin around notes | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 10\r\n */\r\n noteMargin: 10,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ------------- | ---------------------- | ------- | -------- | ------------------ |\r\n * | messageMargin | Space between messages | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 35\r\n */\r\n messageMargin: 35,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ------------ | --------------------------- | ------ | -------- | ------------------------- |\r\n * | messageAlign | Multiline message alignment | string | Required | 'left', 'center', 'right' |\r\n *\r\n * **Notes:** Default value: 'center'\r\n */\r\n messageAlign: 'center',\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ------------ | --------------------------- | ------- | -------- | ----------- |\r\n * | mirrorActors | Mirror actors under diagram | boolean | Required | true, false |\r\n *\r\n * **Notes:** Default value: true\r\n */\r\n mirrorActors: true,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ---------- | ----------------------------------------------------------------------- | ------- | -------- | ----------- |\r\n * | forceMenus | forces actor popup menus to always be visible (to support E2E testing). | Boolean | Required | True, False |\r\n *\r\n * **Notes:**\r\n *\r\n * Default value: false.\r\n */\r\n forceMenus: false,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------------- | ------------------------------------------ | ------- | -------- | ------------------ |\r\n * | bottomMarginAdj | Prolongs the edge of the diagram downwards | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:**\r\n *\r\n * Depending on css styling this might need adjustment.\r\n *\r\n * Default value: 1\r\n */\r\n bottomMarginAdj: 1,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ----------- | ----------- | ------- | -------- | ----------- |\r\n * | useMaxWidth | See Notes | boolean | Required | true, false |\r\n *\r\n * **Notes:** When this flag is set to true, the height and width is set to 100% and is then\r\n * scaling with the available space. If set to false, the absolute space required is used.\r\n *\r\n * Default value: true\r\n */\r\n useMaxWidth: true,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ----------- | ------------------------------------ | ------- | -------- | ----------- |\r\n * | rightAngles | display curve arrows as right angles | boolean | Required | true, false |\r\n *\r\n * **Notes:**\r\n *\r\n * This will display arrows that start and begin at the same node as right angles, rather than a curve\r\n *\r\n * Default value: false\r\n */\r\n rightAngles: false,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ------------------- | ------------------------------- | ------- | -------- | ----------- |\r\n * | showSequenceNumbers | This will show the node numbers | boolean | Required | true, false |\r\n *\r\n * **Notes:** Default value: false\r\n */\r\n showSequenceNumbers: false,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ------------- | -------------------------------------------------- | ------- | -------- | ------------------ |\r\n * | actorFontSize | This sets the font size of the actor's description | Integer | Require | Any Positive Value |\r\n *\r\n * **Notes:** **Default value 14**..\r\n */\r\n actorFontSize: 14,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------------- | ---------------------------------------------------- | ------ | -------- | --------------------------- |\r\n * | actorFontFamily | This sets the font family of the actor's description | string | Required | Any Possible CSS FontFamily |\r\n *\r\n * **Notes:** Default value: \"'Open-Sans\", \"sans-serif\"'\r\n */\r\n actorFontFamily: '\"Open-Sans\", \"sans-serif\"',\r\n\r\n /**\r\n * This sets the font weight of the actor's description\r\n *\r\n * **Notes:** Default value: 400.\r\n */\r\n actorFontWeight: 400,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ------------ | ----------------------------------------------- | ------- | -------- | ------------------ |\r\n * | noteFontSize | This sets the font size of actor-attached notes | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 14\r\n */\r\n noteFontSize: 14,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | -------------- | -------------------------------------------------- | ------ | -------- | --------------------------- |\r\n * | noteFontFamily | This sets the font family of actor-attached notes. | string | Required | Any Possible CSS FontFamily |\r\n *\r\n * **Notes:** Default value: ''\"trebuchet ms\", verdana, arial, sans-serif'\r\n */\r\n noteFontFamily: '\"trebuchet ms\", verdana, arial, sans-serif',\r\n\r\n /**\r\n * This sets the font weight of the note's description\r\n *\r\n * **Notes:** Default value: 400\r\n */\r\n noteFontWeight: 400,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------- | ---------------------------------------------------- | ------ | -------- | ------------------------- |\r\n * | noteAlign | This sets the text alignment of actor-attached notes | string | required | 'left', 'center', 'right' |\r\n *\r\n * **Notes:** Default value: 'center'\r\n */\r\n noteAlign: 'center',\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------------- | ----------------------------------------- | ------- | -------- | ------------------- |\r\n * | messageFontSize | This sets the font size of actor messages | Integer | Required | Any Positive Number |\r\n *\r\n * **Notes:** Default value: 16\r\n */\r\n messageFontSize: 16,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ----------------- | ------------------------------------------- | ------ | -------- | --------------------------- |\r\n * | messageFontFamily | This sets the font family of actor messages | string | Required | Any Possible CSS FontFamily |\r\n *\r\n * **Notes:** Default value: '\"trebuchet ms\", verdana, arial, sans-serif'\r\n */\r\n messageFontFamily: '\"trebuchet ms\", verdana, arial, sans-serif',\r\n\r\n /**\r\n * This sets the font weight of the message's description\r\n *\r\n * **Notes:** Default value: 400.\r\n */\r\n messageFontWeight: 400,\r\n\r\n /**\r\n * This sets the auto-wrap state for the diagram\r\n *\r\n * **Notes:** Default value: false.\r\n */\r\n wrap: false,\r\n\r\n /**\r\n * This sets the auto-wrap padding for the diagram (sides only)\r\n *\r\n * **Notes:** Default value: 0.\r\n */\r\n wrapPadding: 10,\r\n\r\n /**\r\n * This sets the width of the loop-box (loop, alt, opt, par)\r\n *\r\n * **Notes:** Default value: 50.\r\n */\r\n labelBoxWidth: 50,\r\n\r\n /**\r\n * This sets the height of the loop-box (loop, alt, opt, par)\r\n *\r\n * **Notes:** Default value: 20.\r\n */\r\n labelBoxHeight: 20,\r\n\r\n messageFont: function () {\r\n return {\r\n fontFamily: this.messageFontFamily,\r\n fontSize: this.messageFontSize,\r\n fontWeight: this.messageFontWeight,\r\n };\r\n },\r\n noteFont: function () {\r\n return {\r\n fontFamily: this.noteFontFamily,\r\n fontSize: this.noteFontSize,\r\n fontWeight: this.noteFontWeight,\r\n };\r\n },\r\n actorFont: function () {\r\n return {\r\n fontFamily: this.actorFontFamily,\r\n fontSize: this.actorFontSize,\r\n fontWeight: this.actorFontWeight,\r\n };\r\n },\r\n },\r\n\r\n /** The object containing configurations specific for gantt diagrams */\r\n gantt: {\r\n /**\r\n * ### titleTopMargin\r\n *\r\n * | Parameter | Description | Type | Required | Values |\r\n * | -------------- | ---------------------------------------------- | ------- | -------- | ------------------ |\r\n * | titleTopMargin | Margin top for the text over the gantt diagram | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 25\r\n */\r\n titleTopMargin: 25,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------- | ----------------------------------- | ------- | -------- | ------------------ |\r\n * | barHeight | The height of the bars in the graph | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 20\r\n */\r\n barHeight: 20,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------- | ---------------------------------------------------------------- | ------- | -------- | ------------------ |\r\n * | barGap | The margin between the different activities in the gantt diagram | Integer | Optional | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 4\r\n */\r\n barGap: 4,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ---------- | -------------------------------------------------------------------------- | ------- | -------- | ------------------ |\r\n * | topPadding | Margin between title and gantt diagram and between axis and gantt diagram. | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 50\r\n */\r\n topPadding: 50,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ------------ | ----------------------------------------------------------------------- | ------- | -------- | ------------------ |\r\n * | rightPadding | The space allocated for the section name to the right of the activities | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 75\r\n */\r\n rightPadding: 75,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ----------- | ---------------------------------------------------------------------- | ------- | -------- | ------------------ |\r\n * | leftPadding | The space allocated for the section name to the left of the activities | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 75\r\n */\r\n leftPadding: 75,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | -------------------- | -------------------------------------------- | ------- | -------- | ------------------ |\r\n * | gridLineStartPadding | Vertical starting position of the grid lines | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 35\r\n */\r\n gridLineStartPadding: 35,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------- | ----------- | ------- | -------- | ------------------ |\r\n * | fontSize | Font size | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 11\r\n */\r\n fontSize: 11,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------------- | ---------------------- | ------- | -------- | ------------------ |\r\n * | sectionFontSize | Font size for sections | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 11\r\n */\r\n sectionFontSize: 11,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ------------------- | ---------------------------------------- | ------- | -------- | ------------------ |\r\n * | numberSectionStyles | The number of alternating section styles | Integer | 4 | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 4\r\n */\r\n numberSectionStyles: 4,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ---------- | --------------------------- | ---- | -------- | ---------------- |\r\n * | axisFormat | Datetime format of the axis | 3 | Required | Date in yy-mm-dd |\r\n *\r\n * **Notes:**\r\n *\r\n * This might need adjustment to match your locale and preferences\r\n *\r\n * Default value: '%Y-%m-%d'.\r\n */\r\n axisFormat: '%Y-%m-%d',\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ----------- | ----------- | ------- | -------- | ----------- |\r\n * | useMaxWidth | See notes | boolean | 4 | true, false |\r\n *\r\n * **Notes:**\r\n *\r\n * When this flag is set the height and width is set to 100% and is then scaling with the\r\n * available space if not the absolute space required is used.\r\n *\r\n * Default value: true\r\n */\r\n useMaxWidth: true,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------- | ----------- | ------- | -------- | ----------- |\r\n * | topAxis | See notes | Boolean | 4 | True, False |\r\n *\r\n * **Notes:** when this flag is set date labels will be added to the top of the chart\r\n *\r\n * **Default value false**.\r\n */\r\n topAxis: false,\r\n\r\n useWidth: undefined,\r\n },\r\n\r\n /** The object containing configurations specific for journey diagrams */\r\n journey: {\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | -------------- | ---------------------------------------------------- | ------- | -------- | ------------------ |\r\n * | diagramMarginX | Margin to the right and left of the sequence diagram | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 50\r\n */\r\n diagramMarginX: 50,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | -------------- | -------------------------------------------------- | ------- | -------- | ------------------ |\r\n * | diagramMarginY | Margin to the over and under the sequence diagram. | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 10\r\n */\r\n diagramMarginY: 10,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ----------- | --------------------- | ------- | -------- | ------------------ |\r\n * | actorMargin | Margin between actors | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 50\r\n */\r\n leftMargin: 150,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------- | -------------------- | ------- | -------- | ------------------ |\r\n * | width | Width of actor boxes | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 150\r\n */\r\n width: 150,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------- | --------------------- | ------- | -------- | ------------------ |\r\n * | height | Height of actor boxes | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 65\r\n */\r\n height: 50,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------- | ------------------------ | ------- | -------- | ------------------ |\r\n * | boxMargin | Margin around loop boxes | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 10\r\n */\r\n boxMargin: 10,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ------------- | -------------------------------------------- | ------- | -------- | ------------------ |\r\n * | boxTextMargin | Margin around the text in loop/alt/opt boxes | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 5\r\n */\r\n boxTextMargin: 5,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ---------- | ------------------- | ------- | -------- | ------------------ |\r\n * | noteMargin | Margin around notes | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Default value: 10\r\n */\r\n noteMargin: 10,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ------------- | ----------------------- | ------- | -------- | ------------------ |\r\n * | messageMargin | Space between messages. | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:**\r\n *\r\n * Space between messages.\r\n *\r\n * Default value: 35\r\n */\r\n messageMargin: 35,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ------------ | --------------------------- | ---- | -------- | ------------------------- |\r\n * | messageAlign | Multiline message alignment | 3 | 4 | 'left', 'center', 'right' |\r\n *\r\n * **Notes:** Default value: 'center'\r\n */\r\n messageAlign: 'center',\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------------- | ------------------------------------------ | ------- | -------- | ------------------ |\r\n * | bottomMarginAdj | Prolongs the edge of the diagram downwards | Integer | 4 | Any Positive Value |\r\n *\r\n * **Notes:**\r\n *\r\n * Depending on css styling this might need adjustment.\r\n *\r\n * Default value: 1\r\n */\r\n bottomMarginAdj: 1,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ----------- | ----------- | ------- | -------- | ----------- |\r\n * | useMaxWidth | See notes | boolean | 4 | true, false |\r\n *\r\n * **Notes:**\r\n *\r\n * When this flag is set the height and width is set to 100% and is then scaling with the\r\n * available space if not the absolute space required is used.\r\n *\r\n * Default value: true\r\n */\r\n useMaxWidth: true,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ----------- | --------------------------------- | ---- | -------- | ----------- |\r\n * | rightAngles | Curved Arrows become Right Angles | 3 | 4 | true, false |\r\n *\r\n * **Notes:**\r\n *\r\n * This will display arrows that start and begin at the same node as right angles, rather than a curves\r\n *\r\n * Default value: false\r\n */\r\n rightAngles: false,\r\n taskFontSize: 14,\r\n taskFontFamily: '\"Open-Sans\", \"sans-serif\"',\r\n taskMargin: 50,\r\n // width of activation box\r\n activationWidth: 10,\r\n\r\n // text placement as: tspan | fo | old only text as before\r\n textPlacement: 'fo',\r\n actorColours: ['#8FBC8F', '#7CFC00', '#00FFFF', '#20B2AA', '#B0E0E6', '#FFFFE0'],\r\n\r\n sectionFills: ['#191970', '#8B008B', '#4B0082', '#2F4F4F', '#800000', '#8B4513', '#00008B'],\r\n sectionColours: ['#fff'],\r\n },\r\n class: {\r\n arrowMarkerAbsolute: false,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ----------- | ----------- | ------- | -------- | ----------- |\r\n * | useMaxWidth | See notes | boolean | 4 | true, false |\r\n *\r\n * **Notes:**\r\n *\r\n * When this flag is set the height and width is set to 100% and is then scaling with the\r\n * available space if not the absolute space required is used.\r\n *\r\n * Default value: true\r\n */\r\n useMaxWidth: true,\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------------- | ----------- | ------- | -------- | ----------------------- |\r\n * | defaultRenderer | See notes | boolean | 4 | dagre-d3, dagre-wrapper |\r\n *\r\n * **Notes**:\r\n *\r\n * Decides which rendering engine that is to be used for the rendering. Legal values are:\r\n * dagre-d3 dagre-wrapper - wrapper for dagre implemented in mermaid\r\n *\r\n * Default value: 'dagre-d3'\r\n */\r\n defaultRenderer: 'dagre-wrapper',\r\n },\r\n git: {\r\n arrowMarkerAbsolute: false,\r\n\r\n useWidth: undefined,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ----------- | ----------- | ------- | -------- | ----------- |\r\n * | useMaxWidth | See notes | boolean | 4 | true, false |\r\n *\r\n * **Notes:**\r\n *\r\n * When this flag is set the height and width is set to 100% and is then scaling with the\r\n * available space if not the absolute space required is used.\r\n *\r\n * Default value: true\r\n */\r\n useMaxWidth: true,\r\n },\r\n state: {\r\n dividerMargin: 10,\r\n sizeUnit: 5,\r\n padding: 8,\r\n textHeight: 10,\r\n titleShift: -15,\r\n noteMargin: 10,\r\n forkWidth: 70,\r\n forkHeight: 7,\r\n // Used\r\n miniPadding: 2,\r\n // Font size factor, this is used to guess the width of the edges labels before rendering by dagre\r\n // layout. This might need updating if/when switching font\r\n fontSizeFactor: 5.02,\r\n fontSize: 24,\r\n labelHeight: 16,\r\n edgeLengthFactor: '20',\r\n compositTitleSize: 35,\r\n radius: 5,\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ----------- | ----------- | ------- | -------- | ----------- |\r\n * | useMaxWidth | See notes | boolean | 4 | true, false |\r\n *\r\n * **Notes:**\r\n *\r\n * When this flag is set the height and width is set to 100% and is then scaling with the\r\n * available space if not the absolute space required is used.\r\n *\r\n * Default value: true\r\n */\r\n useMaxWidth: true,\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------------- | ----------- | ------- | -------- | ----------------------- |\r\n * | defaultRenderer | See notes | boolean | 4 | dagre-d3, dagre-wrapper |\r\n *\r\n * **Notes:**\r\n *\r\n * Decides which rendering engine that is to be used for the rendering. Legal values are:\r\n * dagre-d3 dagre-wrapper - wrapper for dagre implemented in mermaid\r\n *\r\n * Default value: 'dagre-d3'\r\n */\r\n defaultRenderer: 'dagre-wrapper',\r\n },\r\n\r\n /** The object containing configurations specific for entity relationship diagrams */\r\n er: {\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | -------------- | ----------------------------------------------- | ------- | -------- | ------------------ |\r\n * | diagramPadding | Amount of padding around the diagram as a whole | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:**\r\n *\r\n * The amount of padding around the diagram as a whole so that embedded diagrams have margins,\r\n * expressed in pixels\r\n *\r\n * Default value: 20\r\n */\r\n diagramPadding: 20,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------------- | ---------------------------------------- | ------ | -------- | ---------------------- |\r\n * | layoutDirection | Directional bias for layout of entities. | string | Required | \"TB\", \"BT\", \"LR\", \"RL\" |\r\n *\r\n * **Notes:**\r\n *\r\n * 'TB' for Top-Bottom, 'BT'for Bottom-Top, 'LR' for Left-Right, or 'RL' for Right to Left.\r\n *\r\n * T = top, B = bottom, L = left, and R = right.\r\n *\r\n * Default value: 'TB'\r\n */\r\n layoutDirection: 'TB',\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | -------------- | ---------------------------------- | ------- | -------- | ------------------ |\r\n * | minEntityWidth | The minimum width of an entity box | Integer | Required | Any Positive Value |\r\n *\r\n * **Notes:** Expressed in pixels. Default value: 100\r\n */\r\n minEntityWidth: 100,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------------- | ----------------------------------- | ------- | -------- | ------------------ |\r\n * | minEntityHeight | The minimum height of an entity box | Integer | 4 | Any Positive Value |\r\n *\r\n * **Notes:** Expressed in pixels Default value: 75\r\n */\r\n minEntityHeight: 75,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ------------- | ----------------------------------------------------------- | ------- | -------- | ------------------ |\r\n * | entityPadding | Minimum internal padding betweentext in box and box borders | Integer | 4 | Any Positive Value |\r\n *\r\n * **Notes:**\r\n *\r\n * The minimum internal padding betweentext in an entity box and the enclosing box borders,\r\n * expressed in pixels.\r\n *\r\n * Default value: 15\r\n */\r\n entityPadding: 15,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------- | ----------------------------------- | ------ | -------- | -------------------- |\r\n * | stroke | Stroke color of box edges and lines | string | 4 | Any recognized color |\r\n *\r\n * **Notes:** Default value: 'gray'\r\n */\r\n stroke: 'gray',\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------- | -------------------------- | ------ | -------- | -------------------- |\r\n * | fill | Fill color of entity boxes | string | 4 | Any recognized color |\r\n *\r\n * **Notes:** Default value: 'honeydew'\r\n */\r\n fill: 'honeydew',\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | --------- | ------------------- | ------- | -------- | ------------------ |\r\n * | fontSize | Font Size in pixels | Integer | | Any Positive Value |\r\n *\r\n * **Notes:**\r\n *\r\n * Font size (expressed as an integer representing a number of pixels) Default value: 12\r\n */\r\n fontSize: 12,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ----------- | ----------- | ------- | -------- | ----------- |\r\n * | useMaxWidth | See Notes | boolean | Required | true, false |\r\n *\r\n * **Notes:**\r\n *\r\n * When this flag is set to true, the diagram width is locked to 100% and scaled based on\r\n * available space. If set to false, the diagram reserves its absolute width.\r\n *\r\n * Default value: true\r\n */\r\n useMaxWidth: true,\r\n },\r\n\r\n /** The object containing configurations specific for pie diagrams */\r\n pie: {\r\n useWidth: undefined,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ----------- | ----------- | ------- | -------- | ----------- |\r\n * | useMaxWidth | See Notes | boolean | Required | true, false |\r\n *\r\n * **Notes:**\r\n *\r\n * When this flag is set to true, the diagram width is locked to 100% and scaled based on\r\n * available space. If set to false, the diagram reserves its absolute width.\r\n *\r\n * Default value: true\r\n */\r\n useMaxWidth: true,\r\n },\r\n\r\n /** The object containing configurations specific for req diagrams */\r\n requirement: {\r\n useWidth: undefined,\r\n\r\n /**\r\n * | Parameter | Description | Type | Required | Values |\r\n * | ----------- | ----------- | ------- | -------- | ----------- |\r\n * | useMaxWidth | See Notes | boolean | Required | true, false |\r\n *\r\n * **Notes:**\r\n *\r\n * When this flag is set to true, the diagram width is locked to 100% and scaled based on\r\n * available space. If set to false, the diagram reserves its absolute width.\r\n *\r\n * Default value: true\r\n */\r\n useMaxWidth: true,\r\n\r\n rect_fill: '#f9f9f9',\r\n text_color: '#333',\r\n rect_border_size: '0.5px',\r\n rect_border_color: '#bbb',\r\n rect_min_width: 200,\r\n rect_min_height: 200,\r\n fontSize: 14,\r\n rect_padding: 10,\r\n line_height: 20,\r\n },\r\n};\r\n\r\nconfig.class.arrowMarkerAbsolute = config.arrowMarkerAbsolute;\r\nconfig.git.arrowMarkerAbsolute = config.arrowMarkerAbsolute;\r\n\r\nconst keyify = (obj, prefix = '') =>\r\n Object.keys(obj).reduce((res, el) => {\r\n if (Array.isArray(obj[el])) {\r\n return res;\r\n } else if (typeof obj[el] === 'object' && obj[el] !== null) {\r\n return [...res, prefix + el, ...keyify(obj[el], '')];\r\n }\r\n return [...res, prefix + el];\r\n }, []);\r\n\r\nexport const configKeys = keyify(config, '');\r\nexport default config;\r\n","import { select } from 'd3';\r\nimport { log } from '../../logger';\r\nimport * as configApi from '../../config';\r\nimport common from '../common/common';\r\nimport utils from '../../utils';\r\nimport mermaidAPI from '../../mermaidAPI';\r\n\r\nconst MERMAID_DOM_ID_PREFIX = 'classid-';\r\n\r\nlet relations = [];\r\nlet classes = {};\r\nlet classCounter = 0;\r\n\r\nlet funs = [];\r\n\r\nexport const parseDirective = function (statement, context, type) {\r\n mermaidAPI.parseDirective(this, statement, context, type);\r\n};\r\n\r\nconst splitClassNameAndType = function (id) {\r\n let genericType = '';\r\n let className = id;\r\n\r\n if (id.indexOf('~') > 0) {\r\n let split = id.split('~');\r\n className = split[0];\r\n\r\n genericType = common.sanitizeText(split[1], configApi.getConfig());\r\n }\r\n\r\n return { className: className, type: genericType };\r\n};\r\n\r\n/**\r\n * Function called by parser when a node definition has been found.\r\n *\r\n * @param id\r\n * @public\r\n */\r\nexport const addClass = function (id) {\r\n let classId = splitClassNameAndType(id);\r\n // Only add class if not exists\r\n if (typeof classes[classId.className] !== 'undefined') return;\r\n\r\n classes[classId.className] = {\r\n id: classId.className,\r\n type: classId.type,\r\n cssClasses: [],\r\n methods: [],\r\n members: [],\r\n annotations: [],\r\n domId: MERMAID_DOM_ID_PREFIX + classId.className + '-' + classCounter,\r\n };\r\n\r\n classCounter++;\r\n};\r\n\r\n/**\r\n * Function to lookup domId from id in the graph definition.\r\n *\r\n * @param id\r\n * @public\r\n */\r\nexport const lookUpDomId = function (id) {\r\n const classKeys = Object.keys(classes);\r\n for (let i = 0; i < classKeys.length; i++) {\r\n if (classes[classKeys[i]].id === id) {\r\n return classes[classKeys[i]].domId;\r\n }\r\n }\r\n};\r\n\r\nexport const clear = function () {\r\n relations = [];\r\n classes = {};\r\n funs = [];\r\n funs.push(setupToolTips);\r\n};\r\n\r\nexport const getClass = function (id) {\r\n return classes[id];\r\n};\r\nexport const getClasses = function () {\r\n return classes;\r\n};\r\n\r\nexport const getRelations = function () {\r\n return relations;\r\n};\r\n\r\nexport const addRelation = function (relation) {\r\n log.debug('Adding relation: ' + JSON.stringify(relation));\r\n addClass(relation.id1);\r\n addClass(relation.id2);\r\n\r\n relation.id1 = splitClassNameAndType(relation.id1).className;\r\n relation.id2 = splitClassNameAndType(relation.id2).className;\r\n\r\n relations.push(relation);\r\n};\r\n\r\n/**\r\n * Adds an annotation to the specified class Annotations mark special properties of the given type\r\n * (like 'interface' or 'service')\r\n *\r\n * @param className The class name\r\n * @param annotation The name of the annotation without any brackets\r\n * @public\r\n */\r\nexport const addAnnotation = function (className, annotation) {\r\n const validatedClassName = splitClassNameAndType(className).className;\r\n classes[validatedClassName].annotations.push(annotation);\r\n};\r\n\r\n/**\r\n * Adds a member to the specified class\r\n *\r\n * @param className The class name\r\n * @param member The full name of the member. If the member is enclosed in <