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