Compare commits

..

1 Commits

Author SHA1 Message Date
Sidharth Vinod
fed9d3568d Refactor GitHub Actions workflow for lockfile validation
Removed Node.js setup step and pnpm action version.

Co-Authored-By: alois@aloisklink.com
2025-11-03 23:29:28 -08:00
34 changed files with 63 additions and 171 deletions

View File

@@ -1,5 +0,0 @@
---
'mermaid': patch
---
fix: Proper separation between strings and markdown strings

View File

@@ -1,5 +1,3 @@
!viewbox
# It should be viewBox
# This file contains coding related terms # This file contains coding related terms
ALPHANUM ALPHANUM
antiscript antiscript

View File

@@ -64,7 +64,6 @@ rscratch
shiki shiki
Slidev Slidev
sparkline sparkline
speccharts
sphinxcontrib sphinxcontrib
ssim ssim
stylis stylis

View File

@@ -71,9 +71,6 @@ export const getBuildConfig = (options: MermaidBuildOptions): BuildOptions => {
const external: string[] = ['require', 'fs', 'path']; const external: string[] = ['require', 'fs', 'path'];
const outFileName = getFileName(name, options); const outFileName = getFileName(name, options);
const { dependencies, version } = JSON.parse(
readFileSync(resolve(__dirname, `../packages/${packageName}/package.json`), 'utf-8')
);
const output: BuildOptions = buildOptions({ const output: BuildOptions = buildOptions({
...rest, ...rest,
absWorkingDir: resolve(__dirname, `../packages/${packageName}`), absWorkingDir: resolve(__dirname, `../packages/${packageName}`),
@@ -85,13 +82,15 @@ export const getBuildConfig = (options: MermaidBuildOptions): BuildOptions => {
chunkNames: `chunks/${outFileName}/[name]-[hash]`, chunkNames: `chunks/${outFileName}/[name]-[hash]`,
define: { define: {
// This needs to be stringified for esbuild // This needs to be stringified for esbuild
'injected.includeLargeFeatures': `${includeLargeFeatures}`, includeLargeFeatures: `${includeLargeFeatures}`,
'injected.version': `'${version}'`,
'import.meta.vitest': 'undefined', 'import.meta.vitest': 'undefined',
}, },
}); });
if (core) { if (core) {
const { dependencies } = JSON.parse(
readFileSync(resolve(__dirname, `../packages/${packageName}/package.json`), 'utf-8')
);
// Core build is used to generate file without bundled dependencies. // Core build is used to generate file without bundled dependencies.
// This is used by downstream projects to bundle dependencies themselves. // This is used by downstream projects to bundle dependencies themselves.
// Ignore dependencies and any dependencies of dependencies // Ignore dependencies and any dependencies of dependencies

View File

@@ -42,4 +42,5 @@ jobs:
publish: pnpm changeset:publish publish: pnpm changeset:publish
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_CONFIG_PROVENANCE: true NPM_CONFIG_PROVENANCE: true

View File

@@ -78,8 +78,6 @@ export const getBuildConfig = ({ minify, core, watch, entryName }: BuildOptions)
}, },
define: { define: {
'import.meta.vitest': 'undefined', 'import.meta.vitest': 'undefined',
'injected.includeLargeFeatures': 'true',
'injected.version': `'0.0.0'`,
}, },
resolve: { resolve: {
extensions: [], extensions: [],
@@ -96,6 +94,10 @@ export const getBuildConfig = ({ minify, core, watch, entryName }: BuildOptions)
}), }),
...visualizerOptions(packageName, core), ...visualizerOptions(packageName, core),
], ],
define: {
// Needs to be string
includeLargeFeatures: 'true',
},
}; };
if (watch && config.build) { if (watch && config.build) {

View File

@@ -99,7 +99,6 @@ export const openURLAndVerifyRendering = (
cy.visit(url); cy.visit(url);
cy.window().should('have.property', 'rendered', true); cy.window().should('have.property', 'rendered', true);
cy.get('svg').should('be.visible'); cy.get('svg').should('be.visible');
// cspell:ignore viewbox
cy.get('svg').should('not.have.attr', 'viewbox'); cy.get('svg').should('not.have.attr', 'viewbox');
if (validation) { if (validation) {

View File

@@ -1174,8 +1174,8 @@ end
end end
githost["Github, Gitlab, BitBucket, etc."] githost["Github, Gitlab, BitBucket, etc."]
githost2["\`Github, Gitlab, BitBucket, etc.\`"] githost2["\`Github, Gitlab, BitBucket, etc.\`"]
a["\`1.\`"] a["1."]
b["\`- x\`"] b["- x"]
`; `;
it('should render raw strings', () => { it('should render raw strings', () => {

View File

@@ -1003,49 +1003,4 @@ graph TD
} }
); );
}); });
it('#5824: should be able to render string and markdown labels', () => {
imgSnapshotTest(
`
flowchart TB
mermaid{"What is\nyourmermaid version?"} --> v10["<11"] --"\`<**1**1\`"--> fine["No bug"]
mermaid --> v11[">= v11"] -- ">= v11" --> broken["Affected by https://github.com/mermaid-js/mermaid/issues/5824"]
subgraph subgraph1["\`How to fix **fix**\`"]
broken --> B["B"]
end
githost["Github, Gitlab, BitBucket, etc."]
githost2["\`Github, Gitlab, BitBucket, etc.\`"]
a["1."]
b["- x"]
`,
{
flowchart: { htmlLabels: true },
securityLevel: 'loose',
}
);
});
it('69: should render subgraphs with adhoc list headings', () => {
imgSnapshotTest(
`
graph TB
subgraph "1. first"
a1-->a2
end
subgraph 2. second
b1-->b2
end
`,
{ fontFamily: 'courier' }
);
});
it('70: should render subgraphs with markdown headings', () => {
imgSnapshotTest(
`
graph TB
subgraph "\`**strong**\`"
a1-->a2
end
`,
{ fontFamily: 'courier' }
);
});
}); });

View File

@@ -10,7 +10,7 @@
# Interface: ParseOptions # Interface: ParseOptions
Defined in: [packages/mermaid/src/types.ts:89](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L89) Defined in: [packages/mermaid/src/types.ts:88](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L88)
## Properties ## Properties
@@ -18,7 +18,7 @@ Defined in: [packages/mermaid/src/types.ts:89](https://github.com/mermaid-js/mer
> `optional` **suppressErrors**: `boolean` > `optional` **suppressErrors**: `boolean`
Defined in: [packages/mermaid/src/types.ts:94](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L94) Defined in: [packages/mermaid/src/types.ts:93](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L93)
If `true`, parse will return `false` instead of throwing error when the diagram is invalid. If `true`, parse will return `false` instead of throwing error when the diagram is invalid.
The `parseError` function will not be called. The `parseError` function will not be called.

View File

@@ -10,7 +10,7 @@
# Interface: ParseResult # Interface: ParseResult
Defined in: [packages/mermaid/src/types.ts:97](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L97) Defined in: [packages/mermaid/src/types.ts:96](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L96)
## Properties ## Properties
@@ -18,7 +18,7 @@ Defined in: [packages/mermaid/src/types.ts:97](https://github.com/mermaid-js/mer
> **config**: [`MermaidConfig`](MermaidConfig.md) > **config**: [`MermaidConfig`](MermaidConfig.md)
Defined in: [packages/mermaid/src/types.ts:105](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L105) Defined in: [packages/mermaid/src/types.ts:104](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L104)
The config passed as YAML frontmatter or directives The config passed as YAML frontmatter or directives
@@ -28,6 +28,6 @@ The config passed as YAML frontmatter or directives
> **diagramType**: `string` > **diagramType**: `string`
Defined in: [packages/mermaid/src/types.ts:101](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L101) Defined in: [packages/mermaid/src/types.ts:100](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L100)
The diagram type, e.g. 'flowchart', 'sequence', etc. The diagram type, e.g. 'flowchart', 'sequence', etc.

View File

@@ -10,7 +10,7 @@
# Interface: RenderResult # Interface: RenderResult
Defined in: [packages/mermaid/src/types.ts:115](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L115) Defined in: [packages/mermaid/src/types.ts:114](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L114)
## Properties ## Properties
@@ -18,7 +18,7 @@ Defined in: [packages/mermaid/src/types.ts:115](https://github.com/mermaid-js/me
> `optional` **bindFunctions**: (`element`) => `void` > `optional` **bindFunctions**: (`element`) => `void`
Defined in: [packages/mermaid/src/types.ts:133](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L133) Defined in: [packages/mermaid/src/types.ts:132](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L132)
Bind function to be called after the svg has been inserted into the DOM. Bind function to be called after the svg has been inserted into the DOM.
This is necessary for adding event listeners to the elements in the svg. This is necessary for adding event listeners to the elements in the svg.
@@ -45,7 +45,7 @@ bindFunctions?.(div); // To call bindFunctions only if it's present.
> **diagramType**: `string` > **diagramType**: `string`
Defined in: [packages/mermaid/src/types.ts:123](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L123) Defined in: [packages/mermaid/src/types.ts:122](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L122)
The diagram type, e.g. 'flowchart', 'sequence', etc. The diagram type, e.g. 'flowchart', 'sequence', etc.
@@ -55,6 +55,6 @@ The diagram type, e.g. 'flowchart', 'sequence', etc.
> **svg**: `string` > **svg**: `string`
Defined in: [packages/mermaid/src/types.ts:119](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L119) Defined in: [packages/mermaid/src/types.ts:118](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L118)
The svg code for the rendered graph. The svg code for the rendered graph.

View File

@@ -57,8 +57,6 @@ To add an integration to this list, see the [Integrations - create page](./integ
- [GitHub Writer](https://github.com/ckeditor/github-writer) - [GitHub Writer](https://github.com/ckeditor/github-writer)
- [SVG diagram generator](https://github.com/SimonKenyonShepard/mermaidjs-github-svg-generator) - [SVG diagram generator](https://github.com/SimonKenyonShepard/mermaidjs-github-svg-generator)
- [GitLab](https://docs.gitlab.com/ee/user/markdown.html#diagrams-and-flowcharts) ✅ - [GitLab](https://docs.gitlab.com/ee/user/markdown.html#diagrams-and-flowcharts) ✅
- [GNU Octave](https://octave.org/) ✅
- [octave_mermaid_js](https://github.com/CNOCTAVE/octave_mermaid_js) ✅
- [Mermaid Plugin for JetBrains IDEs](https://plugins.jetbrains.com/plugin/20146-mermaid) - [Mermaid Plugin for JetBrains IDEs](https://plugins.jetbrains.com/plugin/20146-mermaid)
- [MonsterWriter](https://www.monsterwriter.com/) ✅ - [MonsterWriter](https://www.monsterwriter.com/) ✅
- [Joplin](https://joplinapp.org) ✅ - [Joplin](https://joplinapp.org) ✅
@@ -274,7 +272,6 @@ Communication tools and platforms
- [reveal.js-mermaid-plugin](https://github.com/ludwick/reveal.js-mermaid-plugin) - [reveal.js-mermaid-plugin](https://github.com/ludwick/reveal.js-mermaid-plugin)
- [Reveal CK](https://github.com/jedcn/reveal-ck) - [Reveal CK](https://github.com/jedcn/reveal-ck)
- [reveal-ck-mermaid-plugin](https://github.com/tmtm/reveal-ck-mermaid-plugin) - [reveal-ck-mermaid-plugin](https://github.com/tmtm/reveal-ck-mermaid-plugin)
- [speccharts: Turn your test suites into specification diagrams](https://github.com/arnaudrenaud/speccharts)
- [Vitepress Plugin](https://github.com/sametcn99/vitepress-mermaid-renderer) - [Vitepress Plugin](https://github.com/sametcn99/vitepress-mermaid-renderer)
<!--- cspell:ignore Blazorade HueHive ---> <!--- cspell:ignore Blazorade HueHive --->

View File

@@ -18,9 +18,7 @@
"elk", "elk",
"mermaid" "mermaid"
], ],
"scripts": { "scripts": {},
"clean": "rimraf dist"
},
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/mermaid-js/mermaid" "url": "https://github.com/mermaid-js/mermaid"

View File

@@ -19,9 +19,7 @@
"mermaid", "mermaid",
"layout" "layout"
], ],
"scripts": { "scripts": {},
"clean": "rimraf dist"
},
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/mermaid-js/mermaid" "url": "https://github.com/mermaid-js/mermaid"

View File

@@ -72,7 +72,7 @@ export const addDiagrams = () => {
} }
); );
if (injected.includeLargeFeatures) { if (includeLargeFeatures) {
registerLazyLoadedDiagrams(flowchartElk, mindmap, architecture); registerLazyLoadedDiagrams(flowchartElk, mindmap, architecture);
} }

View File

@@ -333,7 +333,7 @@ const renderKatexUnsanitized = async (text: string, config: MermaidConfig): Prom
return text.replace(katexRegex, 'MathML is unsupported in this environment.'); return text.replace(katexRegex, 'MathML is unsupported in this environment.');
} }
if (injected.includeLargeFeatures) { if (includeLargeFeatures) {
const { default: katex } = await import('katex'); const { default: katex } = await import('katex');
const outputMode = const outputMode =
config.forceLegacyMathML || (!isMathMLSupported() && config.legacyMathML) config.forceLegacyMathML || (!isMathMLSupported() && config.legacyMathML)

View File

@@ -85,17 +85,6 @@ export class FlowDB implements DiagramDB {
return common.sanitizeText(txt, this.config); return common.sanitizeText(txt, this.config);
} }
private sanitizeNodeLabelType(labelType?: string) {
switch (labelType) {
case 'markdown':
case 'string':
case 'text':
return labelType;
default:
return 'markdown';
}
}
/** /**
* Function to lookup domId from id in the graph definition. * Function to lookup domId from id in the graph definition.
* *
@@ -219,7 +208,6 @@ export class FlowDB implements DiagramDB {
if (doc?.label) { if (doc?.label) {
vertex.text = doc?.label; vertex.text = doc?.label;
vertex.labelType = this.sanitizeNodeLabelType(doc?.labelType);
} }
if (doc?.icon) { if (doc?.icon) {
vertex.icon = doc?.icon; vertex.icon = doc?.icon;
@@ -279,7 +267,7 @@ export class FlowDB implements DiagramDB {
if (edge.text.startsWith('"') && edge.text.endsWith('"')) { if (edge.text.startsWith('"') && edge.text.endsWith('"')) {
edge.text = edge.text.substring(1, edge.text.length - 1); edge.text = edge.text.substring(1, edge.text.length - 1);
} }
edge.labelType = this.sanitizeNodeLabelType(linkTextObj.type); edge.labelType = linkTextObj.type;
} }
if (type !== undefined) { if (type !== undefined) {
@@ -714,7 +702,7 @@ You have to call mermaid.initialize.`
title: title.trim(), title: title.trim(),
classes: [], classes: [],
dir, dir,
labelType: this.sanitizeNodeLabelType(_title?.type), labelType: _title.type,
}; };
log.info('Adding', subGraph.id, subGraph.nodes, subGraph.dir); log.info('Adding', subGraph.id, subGraph.nodes, subGraph.dir);
@@ -1024,7 +1012,6 @@ You have to call mermaid.initialize.`
const baseNode = { const baseNode = {
id: vertex.id, id: vertex.id,
label: vertex.text, label: vertex.text,
labelType: vertex.labelType,
labelStyle: '', labelStyle: '',
parentId, parentId,
padding: config.flowchart?.padding || 8, padding: config.flowchart?.padding || 8,
@@ -1101,7 +1088,6 @@ You have to call mermaid.initialize.`
id: subGraph.id, id: subGraph.id,
label: subGraph.title, label: subGraph.title,
labelStyle: '', labelStyle: '',
labelType: subGraph.labelType,
parentId: parentDB.get(subGraph.id), parentId: parentDB.get(subGraph.id),
padding: 8, padding: 8,
cssCompiledStyles: this.getCompiledStyles(subGraph.classes), cssCompiledStyles: this.getCompiledStyles(subGraph.classes),
@@ -1133,7 +1119,6 @@ You have to call mermaid.initialize.`
end: rawEdge.end, end: rawEdge.end,
type: rawEdge.type ?? 'normal', type: rawEdge.type ?? 'normal',
label: rawEdge.text, label: rawEdge.text,
labelType: rawEdge.labelType,
labelpos: 'c', labelpos: 'c',
thickness: rawEdge.stroke, thickness: rawEdge.stroke,
minlen: rawEdge.length, minlen: rawEdge.length,

View File

@@ -29,7 +29,7 @@ export interface FlowVertex {
domId: string; domId: string;
haveCallback?: boolean; haveCallback?: boolean;
id: string; id: string;
labelType: 'markdown' | 'string' | 'text'; labelType: 'text';
link?: string; link?: string;
linkTarget?: string; linkTarget?: string;
props?: any; props?: any;
@@ -62,7 +62,7 @@ export interface FlowEdge {
style?: string[]; style?: string[];
length?: number; length?: number;
text: string; text: string;
labelType: 'markdown' | 'string' | 'text'; labelType: 'text';
classes: string[]; classes: string[];
id?: string; id?: string;
animation?: 'fast' | 'slow'; animation?: 'fast' | 'slow';

View File

@@ -1,7 +1,8 @@
import type { InfoFields, InfoDB } from './infoTypes.js'; import type { InfoFields, InfoDB } from './infoTypes.js';
import packageJson from '../../../package.json' assert { type: 'json' };
export const DEFAULT_INFO_DB: InfoFields = { export const DEFAULT_INFO_DB: InfoFields = {
version: injected.version + (injected.includeLargeFeatures ? '' : '-tiny'), version: packageJson.version + (includeLargeFeatures ? '' : '-tiny'),
} as const; } as const;
export const getVersion = (): string => DEFAULT_INFO_DB.version; export const getVersion = (): string => DEFAULT_INFO_DB.version;

View File

@@ -62,7 +62,6 @@ const getData = function () {
const node = { const node = {
id: section.id, id: section.id,
label: sanitizeText(section.label ?? '', conf), label: sanitizeText(section.label ?? '', conf),
labelType: 'markdown',
isGroup: true, isGroup: true,
ticket: section.ticket, ticket: section.ticket,
shape: 'kanbanSection', shape: 'kanbanSection',
@@ -77,7 +76,6 @@ const getData = function () {
id: item.id, id: item.id,
parentId: section.id, parentId: section.id,
label: sanitizeText(item.label ?? '', conf), label: sanitizeText(item.label ?? '', conf),
labelType: 'markdown',
isGroup: false, isGroup: false,
ticket: item?.ticket, ticket: item?.ticket,
priority: item?.priority, priority: item?.priority,

View File

@@ -260,7 +260,6 @@ export class MindmapDB {
id: node.id.toString(), id: node.id.toString(),
domId: 'node_' + node.id.toString(), domId: 'node_' + node.id.toString(),
label: node.descr, label: node.descr,
labelType: 'markdown',
isGroup: false, isGroup: false,
shape: getShapeFromType(node.type), shape: getShapeFromType(node.type),
width: node.width, width: node.width,

View File

@@ -16,7 +16,6 @@ export interface MindmapNode {
x?: number; x?: number;
y?: number; y?: number;
isRoot?: boolean; isRoot?: boolean;
labelType?: string;
} }
export type FilledMindMapNode = RequiredDeep<MindmapNode>; export type FilledMindMapNode = RequiredDeep<MindmapNode>;

View File

@@ -1,6 +1,6 @@
import type { MarkdownOptions } from 'vitepress'; import type { MarkdownOptions } from 'vitepress';
import { defineConfig } from 'vitepress'; import { defineConfig } from 'vitepress';
import packageJson from '../../../package.json' with { type: 'json' }; import packageJson from '../../../package.json' assert { type: 'json' };
import { addCanonicalUrls } from './canonical-urls.js'; import { addCanonicalUrls } from './canonical-urls.js';
import MermaidExample from './mermaid-markdown-all.js'; import MermaidExample from './mermaid-markdown-all.js';

View File

@@ -52,8 +52,6 @@ To add an integration to this list, see the [Integrations - create page](./integ
- [GitHub Writer](https://github.com/ckeditor/github-writer) - [GitHub Writer](https://github.com/ckeditor/github-writer)
- [SVG diagram generator](https://github.com/SimonKenyonShepard/mermaidjs-github-svg-generator) - [SVG diagram generator](https://github.com/SimonKenyonShepard/mermaidjs-github-svg-generator)
- [GitLab](https://docs.gitlab.com/ee/user/markdown.html#diagrams-and-flowcharts) ✅ - [GitLab](https://docs.gitlab.com/ee/user/markdown.html#diagrams-and-flowcharts) ✅
- [GNU Octave](https://octave.org/) ✅
- [octave_mermaid_js](https://github.com/CNOCTAVE/octave_mermaid_js) ✅
- [Mermaid Plugin for JetBrains IDEs](https://plugins.jetbrains.com/plugin/20146-mermaid) - [Mermaid Plugin for JetBrains IDEs](https://plugins.jetbrains.com/plugin/20146-mermaid)
- [MonsterWriter](https://www.monsterwriter.com/) ✅ - [MonsterWriter](https://www.monsterwriter.com/) ✅
- [Joplin](https://joplinapp.org) ✅ - [Joplin](https://joplinapp.org) ✅
@@ -269,7 +267,6 @@ Communication tools and platforms
- [reveal.js-mermaid-plugin](https://github.com/ludwick/reveal.js-mermaid-plugin) - [reveal.js-mermaid-plugin](https://github.com/ludwick/reveal.js-mermaid-plugin)
- [Reveal CK](https://github.com/jedcn/reveal-ck) - [Reveal CK](https://github.com/jedcn/reveal-ck)
- [reveal-ck-mermaid-plugin](https://github.com/tmtm/reveal-ck-mermaid-plugin) - [reveal-ck-mermaid-plugin](https://github.com/tmtm/reveal-ck-mermaid-plugin)
- [speccharts: Turn your test suites into specification diagrams](https://github.com/arnaudrenaud/speccharts)
- [Vitepress Plugin](https://github.com/sametcn99/vitepress-mermaid-renderer) - [Vitepress Plugin](https://github.com/sametcn99/vitepress-mermaid-renderer)
<!--- cspell:ignore Blazorade HueHive ---> <!--- cspell:ignore Blazorade HueHive --->

View File

@@ -7,6 +7,7 @@ import { select } from 'd3';
import { compile, serialize, stringify } from 'stylis'; import { compile, serialize, stringify } from 'stylis';
import DOMPurify from 'dompurify'; import DOMPurify from 'dompurify';
import isEmpty from 'lodash-es/isEmpty.js'; import isEmpty from 'lodash-es/isEmpty.js';
import packageJson from '../package.json' assert { type: 'json' };
import { addSVGa11yTitleDescription, setA11yDiagramInfo } from './accessibility.js'; import { addSVGa11yTitleDescription, setA11yDiagramInfo } from './accessibility.js';
import assignWithDepth from './assignWithDepth.js'; import assignWithDepth from './assignWithDepth.js';
import * as configApi from './config.js'; import * as configApi from './config.js';
@@ -420,12 +421,12 @@ const render = async function (
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
// Draw the diagram with the renderer // Draw the diagram with the renderer
try { try {
await diag.renderer.draw(text, id, injected.version, diag); await diag.renderer.draw(text, id, packageJson.version, diag);
} catch (e) { } catch (e) {
if (config.suppressErrorRendering) { if (config.suppressErrorRendering) {
removeTempElements(); removeTempElements();
} else { } else {
errorRenderer.draw(text, id, injected.version); errorRenderer.draw(text, id, packageJson.version);
} }
throw e; throw e;
} }

View File

@@ -42,7 +42,7 @@ const registerDefaultLayoutLoaders = () => {
name: 'dagre', name: 'dagre',
loader: async () => await import('./layout-algorithms/dagre/index.js'), loader: async () => await import('./layout-algorithms/dagre/index.js'),
}, },
...(injected.includeLargeFeatures ...(includeLargeFeatures
? [ ? [
{ {
name: 'cose-bilkent', name: 'cose-bilkent',

View File

@@ -30,17 +30,11 @@ const rect = async (parent, node) => {
// Create the label and insert it after the rect // Create the label and insert it after the rect
const labelEl = shapeSvg.insert('g').attr('class', 'cluster-label '); const labelEl = shapeSvg.insert('g').attr('class', 'cluster-label ');
let text; const text = await createText(labelEl, node.label, {
if (node.labelType === 'markdown') { style: node.labelStyle,
text = await createText(labelEl, node.label, { useHtmlLabels,
style: node.labelStyle, isNode: true,
useHtmlLabels, });
isNode: true,
});
} else {
const labelElement = await createLabel(node.label, node.labelStyle, false, true);
text = labelEl.node()?.appendChild(labelElement);
}
// Get the size of the label // Get the size of the label
let bbox = text.getBBox(); let bbox = text.getBBox();

View File

@@ -29,7 +29,7 @@ import {
import rough from 'roughjs'; import rough from 'roughjs';
import createLabel from './createLabel.js'; import createLabel from './createLabel.js';
import { addEdgeMarkers } from './edgeMarker.ts'; import { addEdgeMarkers } from './edgeMarker.ts';
import { isLabelStyle } from './shapes/handDrawnShapeStyles.js'; import { isLabelStyle, styles2String } from './shapes/handDrawnShapeStyles.js';
export const edgeLabels = new Map(); export const edgeLabels = new Map();
export const terminalLabels = new Map(); export const terminalLabels = new Map();
@@ -47,16 +47,14 @@ export const getLabelStyles = (styleArray) => {
export const insertEdgeLabel = async (elem, edge) => { export const insertEdgeLabel = async (elem, edge) => {
let useHtmlLabels = evaluate(getConfig().flowchart.htmlLabels); let useHtmlLabels = evaluate(getConfig().flowchart.htmlLabels);
const labelElement = const { labelStyles } = styles2String(edge);
edge.labelType === 'markdown' edge.labelStyle = labelStyles;
? await createText(elem, edge.label, { const labelElement = await createText(elem, edge.label, {
style: getLabelStyles(edge.labelStyle), style: edge.labelStyle,
useHtmlLabels, useHtmlLabels,
addSvgBackground: true, addSvgBackground: true,
isNode: false, isNode: false,
}) });
: await createLabel(edge.label, getLabelStyles(edge.labelStyle), undefined, false);
log.info('abc82', edge, edge.labelType); log.info('abc82', edge, edge.labelType);
// Create outer g, edgeLabel, this will be positioned after graph layout // Create outer g, edgeLabel, this will be positioned after graph layout

View File

@@ -62,12 +62,9 @@ export async function erBox<T extends SVGGraphicsElement>(parent: D3Selection<T>
// drawRect doesn't center non-htmlLabels correctly as of now, so translate label // drawRect doesn't center non-htmlLabels correctly as of now, so translate label
if (!evaluate(config.htmlLabels)) { if (!evaluate(config.htmlLabels)) {
const textElement = shapeSvg.select('.label text'); const textElement = shapeSvg.select('text');
const textNode = textElement.node() as SVGTextElement; const bbox = (textElement.node() as SVGTextElement)?.getBBox();
if (textNode) { textElement.attr('transform', `translate(${-bbox.width / 2}, 0)`);
const bbox = textNode.getBBox();
textElement.attr('transform', `translate(${-bbox.width / 2}, 0)`);
}
} }
return shapeSvg; return shapeSvg;
} }

View File

@@ -1,4 +1,3 @@
import createLabel from '../createLabel.js';
import { createText } from '../../createText.js'; import { createText } from '../../createText.js';
import type { Node } from '../../types.js'; import type { Node } from '../../types.js';
import { getConfig } from '../../../diagram-api/diagramAPI.js'; import { getConfig } from '../../../diagram-api/diagramAPI.js';
@@ -14,7 +13,7 @@ export const labelHelper = async <T extends SVGGraphicsElement>(
_classes?: string _classes?: string
) => { ) => {
let cssClasses; let cssClasses;
const useHtmlLabels = node.useHtmlLabels || evaluate(getConfig()?.flowchart?.htmlLabels); const useHtmlLabels = node.useHtmlLabels || evaluate(getConfig()?.htmlLabels);
if (!_classes) { if (!_classes) {
cssClasses = 'node default'; cssClasses = 'node default';
} else { } else {
@@ -41,26 +40,14 @@ export const labelHelper = async <T extends SVGGraphicsElement>(
label = typeof node.label === 'string' ? node.label : node.label[0]; label = typeof node.label === 'string' ? node.label : node.label[0];
} }
let text; const text = await createText(labelEl, sanitizeText(decodeEntities(label), getConfig()), {
if (node.labelType === 'markdown') { useHtmlLabels,
text = await createText(labelEl, sanitizeText(decodeEntities(label), getConfig()), { width: node.width || getConfig().flowchart?.wrappingWidth,
useHtmlLabels, // @ts-expect-error -- This is currently not used. Should this be `classes` instead?
width: node.width || getConfig().flowchart?.wrappingWidth, cssClasses: 'markdown-node-label',
// @ts-expect-error -- This is currently not used. Should this be `classes` instead? style: node.labelStyle,
cssClasses: 'markdown-node-label', addSvgBackground: !!node.icon || !!node.img,
style: node.labelStyle, });
addSvgBackground: !!node.icon || !!node.img,
});
} else {
const labelElement = await createLabel(
sanitizeText(decodeEntities(label), getConfig()),
node.labelStyle,
false,
true
);
text = labelEl.node()?.appendChild(labelElement);
}
// Get the size of the label // Get the size of the label
let bbox = text.getBBox(); let bbox = text.getBBox();
const halfPadding = (node?.padding ?? 0) / 2; const halfPadding = (node?.padding ?? 0) / 2;

View File

@@ -1,5 +1,2 @@
// eslint-disable-next-line no-var // eslint-disable-next-line no-var
declare var injected: { declare var includeLargeFeatures: boolean;
version: string;
includeLargeFeatures: boolean;
};

View File

@@ -1,7 +1,6 @@
export interface NodeMetaData { export interface NodeMetaData {
shape?: string; shape?: string;
label?: string; label?: string;
labelType?: string;
icon?: string; icon?: string;
form?: string; form?: string;
pos?: 't' | 'b'; pos?: 't' | 'b';

View File

@@ -35,8 +35,7 @@ export default defineConfig({
}, },
define: { define: {
// Needs to be string // Needs to be string
'injected.includeLargeFeatures': 'true', includeLargeFeatures: 'true',
'import.meta.vitest': 'undefined', 'import.meta.vitest': 'undefined',
packageVersion: "'0.0.0'",
}, },
}); });