Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix not rendered style when style is optional #4528

Merged
5 changes: 1 addition & 4 deletions packages/mermaid/src/diagram-api/diagramAPI.ts
Expand Up @@ -7,7 +7,6 @@ import { addStylesForDiagram } from '../styles.js';
import { DiagramDefinition, DiagramDetector } from './types.js';
import * as _commonDb from '../commonDb.js';
import { parseDirective as _parseDirective } from '../directiveUtils.js';
import isEmpty from 'lodash-es/isEmpty.js';

/*
Packaging and exposing resources for external diagrams so that they can import
Expand Down Expand Up @@ -51,9 +50,7 @@ export const registerDiagram = (
if (detector) {
addDetector(id, detector);
}
if (!isEmpty(diagram.styles)) {
addStylesForDiagram(id, diagram.styles);
}
addStylesForDiagram(id, diagram.styles);

if (diagram.injectUtils) {
diagram.injectUtils(
Expand Down
11 changes: 8 additions & 3 deletions packages/mermaid/src/styles.ts
@@ -1,7 +1,7 @@
import type { FlowChartStyleOptions } from './diagrams/flowchart/styles.js';
import { log } from './logger.js';

const themes: Record<string, any> = {};
const themes: Record<string, (options?: any) => string> = {};
Yokozuna59 marked this conversation as resolved.
Show resolved Hide resolved

const getStyles = (
type: string,
Expand Down Expand Up @@ -73,8 +73,13 @@ const getStyles = (
`;
};

export const addStylesForDiagram = (type: string, diagramTheme: unknown): void => {
themes[type] = diagramTheme;
export const addStylesForDiagram = (
type: string,
diagramTheme?: (options?: any) => string
Yokozuna59 marked this conversation as resolved.
Show resolved Hide resolved
): void => {
if (diagramTheme !== undefined) {
themes[type] = (options) => diagramTheme(options);
Yokozuna59 marked this conversation as resolved.
Show resolved Hide resolved
}
};

export default getStyles;