mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-23 02:06:45 +02:00
feat: Inject internal helpers into render function
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -4,34 +4,35 @@
|
|||||||
*/
|
*/
|
||||||
import { dedent } from 'ts-dedent';
|
import { dedent } from 'ts-dedent';
|
||||||
import type { MermaidConfig } from './config.type.js';
|
import type { MermaidConfig } from './config.type.js';
|
||||||
import { log } from './logger.js';
|
import { detectType, registerLazyLoadedDiagrams } from './diagram-api/detectType.js';
|
||||||
import utils from './utils.js';
|
|
||||||
import type { ParseOptions, ParseResult, RenderResult } from './types.js';
|
|
||||||
import { mermaidAPI } from './mermaidAPI.js';
|
|
||||||
import { registerLazyLoadedDiagrams, detectType } from './diagram-api/detectType.js';
|
|
||||||
import { loadRegisteredDiagrams } from './diagram-api/loadDiagram.js';
|
|
||||||
import type { ParseErrorFunction } from './Diagram.js';
|
|
||||||
import { isDetailedError } from './utils.js';
|
|
||||||
import type { DetailedError } from './utils.js';
|
|
||||||
import type { ExternalDiagramDefinition } from './diagram-api/types.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 { loadRegisteredDiagrams } from './diagram-api/loadDiagram.js';
|
||||||
|
import type { ExternalDiagramDefinition } from './diagram-api/types.js';
|
||||||
|
import type { ParseErrorFunction } from './Diagram.js';
|
||||||
|
import type { UnknownDiagramError } from './errors.js';
|
||||||
|
import type { internalHelpers } from './internals.js';
|
||||||
|
import { log } from './logger.js';
|
||||||
|
import { mermaidAPI } from './mermaidAPI.js';
|
||||||
import type { LayoutLoaderDefinition } from './rendering-util/render.js';
|
import type { LayoutLoaderDefinition } from './rendering-util/render.js';
|
||||||
import { internalHelpers } from './internals.js';
|
import { registerLayoutLoaders } from './rendering-util/render.js';
|
||||||
import type { LayoutData } from './rendering-util/types.js';
|
import type { LayoutData } from './rendering-util/types.js';
|
||||||
|
import type { ParseOptions, ParseResult, RenderResult } from './types.js';
|
||||||
|
import type { DetailedError } from './utils.js';
|
||||||
|
import utils, { isDetailedError } from './utils.js';
|
||||||
|
|
||||||
|
type InternalHelpers = typeof internalHelpers;
|
||||||
export type {
|
export type {
|
||||||
MermaidConfig,
|
|
||||||
DetailedError,
|
DetailedError,
|
||||||
ExternalDiagramDefinition,
|
ExternalDiagramDefinition,
|
||||||
|
InternalHelpers,
|
||||||
|
LayoutData,
|
||||||
|
LayoutLoaderDefinition,
|
||||||
|
MermaidConfig,
|
||||||
ParseErrorFunction,
|
ParseErrorFunction,
|
||||||
RenderResult,
|
|
||||||
ParseOptions,
|
ParseOptions,
|
||||||
ParseResult,
|
ParseResult,
|
||||||
|
RenderResult,
|
||||||
UnknownDiagramError,
|
UnknownDiagramError,
|
||||||
LayoutLoaderDefinition,
|
|
||||||
LayoutData,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface RunOptions {
|
export interface RunOptions {
|
||||||
@@ -432,11 +433,6 @@ export interface Mermaid {
|
|||||||
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 = {
|
||||||
@@ -453,7 +449,6 @@ const mermaid: Mermaid = {
|
|||||||
contentLoaded,
|
contentLoaded,
|
||||||
setParseErrorHandler,
|
setParseErrorHandler,
|
||||||
detectType,
|
detectType,
|
||||||
internalHelpers,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default mermaid;
|
export default mermaid;
|
||||||
|
@@ -1,7 +1,14 @@
|
|||||||
|
import { internalHelpers } from '$root/internals.js';
|
||||||
import { log } from '$root/logger.js';
|
import { log } from '$root/logger.js';
|
||||||
|
|
||||||
export interface LayoutAlgorithm {
|
export interface LayoutAlgorithm {
|
||||||
render(data4Layout: any, svg: any, element: any, algorithm?: string): any;
|
render(
|
||||||
|
data4Layout: any,
|
||||||
|
svg: any,
|
||||||
|
element: any,
|
||||||
|
helpers: typeof internalHelpers,
|
||||||
|
algorithm?: string
|
||||||
|
): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type LayoutLoader = () => Promise<LayoutAlgorithm>;
|
export type LayoutLoader = () => Promise<LayoutAlgorithm>;
|
||||||
@@ -38,7 +45,13 @@ export const render = async (data4Layout: any, svg: any, element: any) => {
|
|||||||
|
|
||||||
const layoutDefinition = layoutAlgorithms[data4Layout.layoutAlgorithm];
|
const layoutDefinition = layoutAlgorithms[data4Layout.layoutAlgorithm];
|
||||||
const layoutRenderer = await layoutDefinition.loader();
|
const layoutRenderer = await layoutDefinition.loader();
|
||||||
return layoutRenderer.render(data4Layout, svg, element, layoutDefinition.algorithm);
|
return layoutRenderer.render(
|
||||||
|
data4Layout,
|
||||||
|
svg,
|
||||||
|
element,
|
||||||
|
internalHelpers,
|
||||||
|
layoutDefinition.algorithm
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user