mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-26 10:49:38 +02:00
@@ -22,14 +22,9 @@ export const packageOptions = {
|
|||||||
packageName: 'mermaid-zenuml',
|
packageName: 'mermaid-zenuml',
|
||||||
file: 'detector.ts',
|
file: 'detector.ts',
|
||||||
},
|
},
|
||||||
'mermaid-flowchart-elk': {
|
|
||||||
name: 'mermaid-flowchart-elk',
|
|
||||||
packageName: 'mermaid-flowchart-elk',
|
|
||||||
file: 'detector.ts',
|
|
||||||
},
|
|
||||||
'mermaid-layout-elk': {
|
'mermaid-layout-elk': {
|
||||||
name: 'mermaid-layout-elk',
|
name: 'mermaid-layout-elk',
|
||||||
packageName: 'mermaid-layout-elk',
|
packageName: 'mermaid-layout-elk',
|
||||||
file: 'index.ts',
|
file: 'layouts.ts',
|
||||||
},
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import jison from 'jison';
|
import jison from 'jison';
|
||||||
|
|
||||||
export const transformJison = (src: string): string => {
|
export const transformJison = (src: string): string => {
|
||||||
|
// @ts-ignore - Jison is not typed properly
|
||||||
const parser = new jison.Generator(src, {
|
const parser = new jison.Generator(src, {
|
||||||
moduleType: 'js',
|
moduleType: 'js',
|
||||||
'token-stack': true,
|
'token-stack': true,
|
||||||
|
@@ -27,6 +27,7 @@ controly
|
|||||||
CSSCLASS
|
CSSCLASS
|
||||||
CYLINDEREND
|
CYLINDEREND
|
||||||
CYLINDERSTART
|
CYLINDERSTART
|
||||||
|
DAGA
|
||||||
datakey
|
datakey
|
||||||
DEND
|
DEND
|
||||||
descr
|
descr
|
||||||
|
@@ -7,8 +7,8 @@ import { MermaidBuildOptions, defaultOptions, getBuildConfig } from './util.js';
|
|||||||
const shouldVisualize = process.argv.includes('--visualize');
|
const shouldVisualize = process.argv.includes('--visualize');
|
||||||
|
|
||||||
const buildPackage = async (entryName: keyof typeof packageOptions) => {
|
const buildPackage = async (entryName: keyof typeof packageOptions) => {
|
||||||
const commonOptions = { ...defaultOptions, entryName } as const;
|
const commonOptions: MermaidBuildOptions = { ...defaultOptions, entryName } as const;
|
||||||
const buildConfigs = [
|
const buildConfigs: MermaidBuildOptions[] = [
|
||||||
// package.mjs
|
// package.mjs
|
||||||
{ ...commonOptions },
|
{ ...commonOptions },
|
||||||
// package.min.mjs
|
// package.min.mjs
|
||||||
|
@@ -8,7 +8,7 @@ import { jisonPlugin } from './jisonPlugin.js';
|
|||||||
|
|
||||||
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
||||||
|
|
||||||
export interface MermaidBuildOptions {
|
export interface MermaidBuildOptions extends BuildOptions {
|
||||||
minify: boolean;
|
minify: boolean;
|
||||||
core: boolean;
|
core: boolean;
|
||||||
metafile: boolean;
|
metafile: boolean;
|
||||||
|
@@ -508,6 +508,8 @@ mindmap
|
|||||||
// import mindmap from '../../packages/mermaid-mindmap/src/detector';
|
// import mindmap from '../../packages/mermaid-mindmap/src/detector';
|
||||||
// import example from '../../packages/mermaid-example-diagram/src/mermaid-example-diagram.core.mjs';
|
// import example from '../../packages/mermaid-example-diagram/src/mermaid-example-diagram.core.mjs';
|
||||||
import mermaid from './mermaid.esm.mjs';
|
import mermaid from './mermaid.esm.mjs';
|
||||||
|
import { layouts } from './mermaid-layout-elk.esm.mjs';
|
||||||
|
mermaid.registerLayoutLoaders(layouts);
|
||||||
// await mermaid.registerExternalDiagrams([example]);
|
// await mermaid.registerExternalDiagrams([example]);
|
||||||
mermaid.parseError = function (err, hash) {
|
mermaid.parseError = function (err, hash) {
|
||||||
// console.error('Mermaid error: ', err);
|
// console.error('Mermaid error: ', err);
|
||||||
|
@@ -34,7 +34,7 @@
|
|||||||
"elkjs": "^0.9.3",
|
"elkjs": "^0.9.3",
|
||||||
"d3": "^7.9.0"
|
"d3": "^7.9.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"peerDependencies": {
|
||||||
"mermaid": "workspace:^"
|
"mermaid": "workspace:^"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
|
17
packages/mermaid-layout-elk/src/layouts.ts
Normal file
17
packages/mermaid-layout-elk/src/layouts.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import type { LayoutLoaderDefinition } from 'mermaid';
|
||||||
|
|
||||||
|
const loader = async () => await import(`./render.js`);
|
||||||
|
const algos = ['elk.stress', 'elk.force', 'elk.mrtree', 'elk.sporeOverlap'];
|
||||||
|
|
||||||
|
export const layouts: LayoutLoaderDefinition[] = [
|
||||||
|
{
|
||||||
|
name: 'elk',
|
||||||
|
loader,
|
||||||
|
algorithm: 'elk.layered',
|
||||||
|
},
|
||||||
|
...algos.map((algo) => ({
|
||||||
|
name: algo,
|
||||||
|
loader,
|
||||||
|
algorithm: algo,
|
||||||
|
})),
|
||||||
|
];
|
@@ -1,21 +1,22 @@
|
|||||||
// @ts-nocheck File not ready to check types
|
// @ts-nocheck File not ready to check types
|
||||||
|
import { curveLinear } from 'd3';
|
||||||
import ELK from 'elkjs/lib/elk.bundled.js';
|
import ELK from 'elkjs/lib/elk.bundled.js';
|
||||||
import { getConfig } from '../../mermaid/src/config.js';
|
import mermaid from 'mermaid';
|
||||||
import common from '../../mermaid/src/diagrams/common/common.js';
|
import { findCommonAncestor } from './find-common-ancestor.js';
|
||||||
import { log } from '../../mermaid/src/logger.js';
|
|
||||||
import { insertCluster } from '../../mermaid/src/rendering-util/rendering-elements/clusters.js';
|
const {
|
||||||
import {
|
common,
|
||||||
|
getConfig,
|
||||||
|
insertCluster,
|
||||||
insertEdge,
|
insertEdge,
|
||||||
insertEdgeLabel,
|
insertEdgeLabel,
|
||||||
|
insertMarkers,
|
||||||
|
insertNode,
|
||||||
|
interpolateToCurve,
|
||||||
|
labelHelper,
|
||||||
|
log,
|
||||||
positionEdgeLabel,
|
positionEdgeLabel,
|
||||||
} from '../../mermaid/src/rendering-util/rendering-elements/edges.js';
|
} = mermaid.internalHelpers;
|
||||||
import { curveLinear } from 'd3';
|
|
||||||
import { interpolateToCurve } from '../../mermaid/src/utils.js';
|
|
||||||
import insertMarkers from '../../mermaid/src/rendering-util/rendering-elements/markers.js';
|
|
||||||
import { insertNode } from '../../mermaid/src/rendering-util/rendering-elements/nodes.js';
|
|
||||||
import { labelHelper } from '../../mermaid/src/rendering-util/rendering-elements/shapes/util.js';
|
|
||||||
import { findCommonAncestor } from './find-common-ancestor.js';
|
|
||||||
|
|
||||||
const nodeDb = {};
|
const nodeDb = {};
|
||||||
const portPos = {};
|
const portPos = {};
|
||||||
@@ -214,25 +215,6 @@ const addSubGraphs = function (nodeArr) {
|
|||||||
return parentLookupDb;
|
return parentLookupDb;
|
||||||
};
|
};
|
||||||
|
|
||||||
const insertChildren = (nodeArray, parentLookupDb) => {
|
|
||||||
nodeArray.forEach((node) => {
|
|
||||||
// Check if we have reached the end of the tree
|
|
||||||
if (!node.children) {
|
|
||||||
node.children = [];
|
|
||||||
}
|
|
||||||
// Check if the node has children
|
|
||||||
const childIds = parentLookupDb.childrenById[node.id];
|
|
||||||
// If the node has children, add them to the node
|
|
||||||
if (childIds) {
|
|
||||||
childIds.forEach((childId) => {
|
|
||||||
node.children.push(nodeDb[childId]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// Recursive call
|
|
||||||
insertChildren(node.children, parentLookupDb);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const getEdgeStartEndPoint = (edge, dir) => {
|
const getEdgeStartEndPoint = (edge, dir) => {
|
||||||
let source = edge.start;
|
let source = edge.start;
|
||||||
let target = edge.end;
|
let target = edge.end;
|
||||||
@@ -272,14 +254,6 @@ const calcOffset = function (src, dest, parentLookupDb) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add edges to graph based on parsed graph definition
|
* Add edges to graph based on parsed graph definition
|
||||||
*
|
|
||||||
* @param {object} edges The edges to add to the graph
|
|
||||||
* @param {object} g The graph object
|
|
||||||
* @param cy
|
|
||||||
* @param diagObj
|
|
||||||
* @param dataForLayout
|
|
||||||
* @param graph
|
|
||||||
* @param svg
|
|
||||||
*/
|
*/
|
||||||
export const addEdges = function (dataForLayout, graph, svg) {
|
export const addEdges = function (dataForLayout, graph, svg) {
|
||||||
log.info('abc78 DAGA edges = ', dataForLayout);
|
log.info('abc78 DAGA edges = ', dataForLayout);
|
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"extends": "../../tsconfig.json",
|
"extends": "../../tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"rootDir": "../..",
|
"rootDir": "./src",
|
||||||
"outDir": "./dist",
|
"outDir": "./dist",
|
||||||
"types": ["vitest/importMeta", "vitest/globals"]
|
"types": ["vitest/importMeta", "vitest/globals"]
|
||||||
},
|
},
|
||||||
|
31
packages/mermaid/src/internals.ts
Normal file
31
packages/mermaid/src/internals.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import { getConfig } from './config.js';
|
||||||
|
import common from './diagrams/common/common.js';
|
||||||
|
import { log } from './logger.js';
|
||||||
|
import { insertCluster } from './rendering-util/rendering-elements/clusters.js';
|
||||||
|
import {
|
||||||
|
insertEdge,
|
||||||
|
insertEdgeLabel,
|
||||||
|
positionEdgeLabel,
|
||||||
|
} from './rendering-util/rendering-elements/edges.js';
|
||||||
|
import insertMarkers from './rendering-util/rendering-elements/markers.js';
|
||||||
|
import { insertNode } from './rendering-util/rendering-elements/nodes.js';
|
||||||
|
import { labelHelper } from './rendering-util/rendering-elements/shapes/util.js';
|
||||||
|
import { interpolateToCurve } from './utils.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal helpers for mermaid
|
||||||
|
* @deprecated - This should not be used by external packages, as the definitions will change without notice.
|
||||||
|
*/
|
||||||
|
export const internalHelpers = {
|
||||||
|
common,
|
||||||
|
getConfig,
|
||||||
|
insertCluster,
|
||||||
|
insertEdge,
|
||||||
|
insertEdgeLabel,
|
||||||
|
insertMarkers,
|
||||||
|
insertNode,
|
||||||
|
interpolateToCurve,
|
||||||
|
labelHelper,
|
||||||
|
log,
|
||||||
|
positionEdgeLabel,
|
||||||
|
};
|
@@ -16,6 +16,9 @@ import type { DetailedError } from './utils.js';
|
|||||||
import type { ExternalDiagramDefinition } from './diagram-api/types.js';
|
import type { ExternalDiagramDefinition } from './diagram-api/types.js';
|
||||||
import type { UnknownDiagramError } from './errors.js';
|
import type { UnknownDiagramError } from './errors.js';
|
||||||
import { addDiagrams } from './diagram-api/diagram-orchestration.js';
|
import { addDiagrams } from './diagram-api/diagram-orchestration.js';
|
||||||
|
import { registerLayoutLoaders } from './rendering-util/render.js';
|
||||||
|
import type { LayoutLoaderDefinition } from './rendering-util/render.js';
|
||||||
|
import { internalHelpers } from './internals.js';
|
||||||
|
|
||||||
export type {
|
export type {
|
||||||
MermaidConfig,
|
MermaidConfig,
|
||||||
@@ -26,6 +29,7 @@ export type {
|
|||||||
ParseOptions,
|
ParseOptions,
|
||||||
ParseResult,
|
ParseResult,
|
||||||
UnknownDiagramError,
|
UnknownDiagramError,
|
||||||
|
LayoutLoaderDefinition,
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface RunOptions {
|
export interface RunOptions {
|
||||||
@@ -413,11 +417,17 @@ export interface Mermaid {
|
|||||||
render: typeof render;
|
render: typeof render;
|
||||||
init: typeof init;
|
init: typeof init;
|
||||||
run: typeof run;
|
run: typeof run;
|
||||||
|
registerLayoutLoaders: typeof registerLayoutLoaders;
|
||||||
registerExternalDiagrams: typeof registerExternalDiagrams;
|
registerExternalDiagrams: typeof registerExternalDiagrams;
|
||||||
initialize: typeof initialize;
|
initialize: typeof initialize;
|
||||||
contentLoaded: typeof contentLoaded;
|
contentLoaded: typeof contentLoaded;
|
||||||
setParseErrorHandler: typeof setParseErrorHandler;
|
setParseErrorHandler: typeof setParseErrorHandler;
|
||||||
detectType: typeof detectType;
|
detectType: typeof detectType;
|
||||||
|
/**
|
||||||
|
* Internal helpers for mermaid
|
||||||
|
* @deprecated - This should not be used by external packages, as the definitions will change without notice.
|
||||||
|
*/
|
||||||
|
internalHelpers: typeof internalHelpers;
|
||||||
}
|
}
|
||||||
|
|
||||||
const mermaid: Mermaid = {
|
const mermaid: Mermaid = {
|
||||||
@@ -428,11 +438,13 @@ const mermaid: Mermaid = {
|
|||||||
init,
|
init,
|
||||||
run,
|
run,
|
||||||
registerExternalDiagrams,
|
registerExternalDiagrams,
|
||||||
|
registerLayoutLoaders,
|
||||||
initialize,
|
initialize,
|
||||||
parseError: undefined,
|
parseError: undefined,
|
||||||
contentLoaded,
|
contentLoaded,
|
||||||
setParseErrorHandler,
|
setParseErrorHandler,
|
||||||
detectType,
|
detectType,
|
||||||
|
internalHelpers,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default mermaid;
|
export default mermaid;
|
||||||
|
@@ -1,34 +0,0 @@
|
|||||||
export const render = async (data4Layout, svg, element) => {
|
|
||||||
switch (data4Layout.layoutAlgorithm) {
|
|
||||||
case 'dagre': {
|
|
||||||
const layoutRenderer = await import('./layout-algorithms/dagre/index.js');
|
|
||||||
return layoutRenderer.render(data4Layout, svg, element);
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'elk': {
|
|
||||||
// TODO: Should fix this import path
|
|
||||||
const layoutRenderer = await import('../../../mermaid-layout-elk/src/index.js');
|
|
||||||
return layoutRenderer.render(data4Layout, svg, element, 'elk.layered');
|
|
||||||
}
|
|
||||||
case 'stress': {
|
|
||||||
// TODO: Should fix this import path
|
|
||||||
const layoutRenderer = await import('../../../mermaid-layout-elk/src/index.js');
|
|
||||||
return layoutRenderer.render(data4Layout, svg, element, 'elk.stress');
|
|
||||||
}
|
|
||||||
case 'force': {
|
|
||||||
// TODO: Should fix this import path
|
|
||||||
const layoutRenderer = await import('../../../mermaid-layout-elk/src/index.js');
|
|
||||||
return layoutRenderer.render(data4Layout, svg, element, 'elk.force');
|
|
||||||
}
|
|
||||||
case 'mrtree': {
|
|
||||||
// TODO: Should fix this import path
|
|
||||||
const layoutRenderer = await import('../../../mermaid-layout-elk/src/index.js');
|
|
||||||
return layoutRenderer.render(data4Layout, svg, element, 'elk.mrtree');
|
|
||||||
}
|
|
||||||
case 'sporeOverlap': {
|
|
||||||
// TODO: Should fix this import path
|
|
||||||
const layoutRenderer = await import('../../../mermaid-layout-elk/src/index.js');
|
|
||||||
return layoutRenderer.render(data4Layout, svg, element, 'elk.sporeOverlap');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
40
packages/mermaid/src/rendering-util/render.ts
Normal file
40
packages/mermaid/src/rendering-util/render.ts
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
export interface LayoutAlgorithm {
|
||||||
|
render(data4Layout: any, svg: any, element: any, algorithm?: string): any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type LayoutLoader = () => Promise<LayoutAlgorithm>;
|
||||||
|
export interface LayoutLoaderDefinition {
|
||||||
|
name: string;
|
||||||
|
loader: LayoutLoader;
|
||||||
|
algorithm?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const layoutAlgorithms: Record<string, LayoutLoaderDefinition> = {};
|
||||||
|
|
||||||
|
export const registerLayoutLoaders = (loaders: LayoutLoaderDefinition[]) => {
|
||||||
|
for (const loader of loaders) {
|
||||||
|
layoutAlgorithms[loader.name] = loader;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: Should we load dagre without lazy loading?
|
||||||
|
const registerDefaultLayoutLoaders = () => {
|
||||||
|
registerLayoutLoaders([
|
||||||
|
{
|
||||||
|
name: 'dagre',
|
||||||
|
loader: async () => await import('./layout-algorithms/dagre/index.js'),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
|
registerDefaultLayoutLoaders();
|
||||||
|
|
||||||
|
export const render = async (data4Layout: any, svg: any, element: any) => {
|
||||||
|
if (!(data4Layout.layoutAlgorithm in layoutAlgorithms)) {
|
||||||
|
throw new Error(`Unknown layout algorithm: ${data4Layout.layoutAlgorithm}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const layoutDefinition = layoutAlgorithms[data4Layout.layoutAlgorithm];
|
||||||
|
const layoutRenderer = await layoutDefinition.loader();
|
||||||
|
return layoutRenderer.render(data4Layout, svg, element, layoutDefinition.algorithm);
|
||||||
|
};
|
@@ -8,7 +8,6 @@
|
|||||||
"paths": {
|
"paths": {
|
||||||
"$root/*": ["src/*"]
|
"$root/*": ["src/*"]
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
"include": ["./src/**/*.ts", "./package.json"],
|
"include": ["./src/**/*.ts", "./package.json"]
|
||||||
}
|
}
|
||||||
|
1
pnpm-lock.yaml
generated
1
pnpm-lock.yaml
generated
@@ -442,7 +442,6 @@ importers:
|
|||||||
elkjs:
|
elkjs:
|
||||||
specifier: ^0.9.3
|
specifier: ^0.9.3
|
||||||
version: 0.9.3
|
version: 0.9.3
|
||||||
devDependencies:
|
|
||||||
mermaid:
|
mermaid:
|
||||||
specifier: workspace:^
|
specifier: workspace:^
|
||||||
version: link:../mermaid
|
version: link:../mermaid
|
||||||
|
@@ -66,7 +66,7 @@
|
|||||||
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
||||||
// "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
|
// "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
|
||||||
// "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
|
// "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
|
||||||
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
"noEmitOnError": false /* Disable emitting files if any type checking errors are reported. */,
|
||||||
// "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
|
// "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
|
||||||
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
||||||
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
||||||
|
@@ -15,7 +15,6 @@ export default defineConfig({
|
|||||||
plugins: [
|
plugins: [
|
||||||
jison(),
|
jison(),
|
||||||
jsonSchemaPlugin(), // handles .schema.yaml JSON Schema files
|
jsonSchemaPlugin(), // handles .schema.yaml JSON Schema files
|
||||||
// @ts-expect-error According to the type definitions, rollup plugins are incompatible with vite
|
|
||||||
typescript({ compilerOptions: { declaration: false } }),
|
typescript({ compilerOptions: { declaration: false } }),
|
||||||
],
|
],
|
||||||
test: {
|
test: {
|
||||||
|
Reference in New Issue
Block a user