diff --git a/.vite/server.ts b/.vite/server.ts index 334398dd8..ddd6afdd6 100644 --- a/.vite/server.ts +++ b/.vite/server.ts @@ -16,6 +16,7 @@ async function createServer() { // Create Vite server in middleware mode const vite = await createViteServer({ configFile: './vite.config.ts', + mode: 'production', server: { middlewareMode: true }, appType: 'custom', // don't include Vite's default HTML handling middlewares }); diff --git a/packages/mermaid/src/diagram-api/diagramAPI.ts b/packages/mermaid/src/diagram-api/diagramAPI.ts index 2727ae4ef..cacf02fe1 100644 --- a/packages/mermaid/src/diagram-api/diagramAPI.ts +++ b/packages/mermaid/src/diagram-api/diagramAPI.ts @@ -4,7 +4,7 @@ import { getConfig as _getConfig } from '../config'; import { sanitizeText as _sanitizeText } from '../diagrams/common/common'; import { setupGraphViewbox as _setupGraphViewbox } from '../setupGraphViewbox'; import { addStylesForDiagram } from '../styles'; -import { DiagramDefinition, DiagramDetector } from './types'; +import { DiagramDefinition, DiagramDetector, ExternalDiagramDefinition } from './types'; /* Packaging and exposing resources for externa diagrams so that they can import @@ -70,3 +70,27 @@ export class DiagramNotFoundError extends Error { super(`Diagram ${message} not found.`); } } + +/** + * This is an internal function and should not be made public, as it will likely change. + * @internal + * @param diagrams - Array of {@link ExternalDiagramDefinition}. + */ +export const loadExternalDiagrams = async (...diagrams: ExternalDiagramDefinition[]) => { + log.debug(`Loading ${diagrams.length} external diagrams`); + // Load all lazy loaded diagrams in parallel + const results = await Promise.allSettled( + diagrams.map(async ({ id, detector, loader }) => { + const { diagram } = await loader(); + registerDiagram(id, diagram, detector); + }) + ); + const failed = results.filter((result) => result.status === 'rejected'); + if (failed.length > 0) { + log.error(`Failed to load ${failed.length} external diagrams`); + for (const res of failed) { + log.error(res); + } + throw new Error(`Failed to load ${failed.length} external diagrams`); + } +}; diff --git a/packages/mermaid/src/mermaid.ts b/packages/mermaid/src/mermaid.ts index 268a830ec..da13d2d01 100644 --- a/packages/mermaid/src/mermaid.ts +++ b/packages/mermaid/src/mermaid.ts @@ -8,7 +8,7 @@ import utils from './utils'; import { mermaidAPI } from './mermaidAPI'; import { registerLazyLoadedDiagrams } from './diagram-api/detectType'; import { isDetailedError, type DetailedError } from './utils'; -import { registerDiagram } from './diagram-api/diagramAPI'; +import { loadExternalDiagrams } from './diagram-api/diagramAPI'; import { ExternalDiagramDefinition } from './diagram-api/types'; export type { MermaidConfig, DetailedError, ExternalDiagramDefinition }; @@ -175,30 +175,6 @@ const initThrowsErrors = function ( } }; -/** - * This is an internal function and should not be made public, as it will likely change. - * @internal - * @param diagrams - Array of {@link ExternalDiagramDefinition}. - */ -const loadExternalDiagrams = async (diagrams: ExternalDiagramDefinition[]) => { - log.debug(`Loading ${diagrams.length} external diagrams`); - // Load all lazy loaded diagrams in parallel - const results = await Promise.allSettled( - diagrams.map(async ({ id, detector, loader }) => { - const { diagram } = await loader(); - registerDiagram(id, diagram, detector); - }) - ); - const failed = results.filter((result) => result.status === 'rejected'); - if (failed.length > 0) { - log.error(`Failed to load ${failed.length} external diagrams`); - for (const res of failed) { - log.error(res); - } - throw new Error(`Failed to load ${failed.length} external diagrams`); - } -}; - /** * Equivalent to {@link init()}, except an error will be thrown on error. * @@ -324,7 +300,7 @@ const registerExternalDiagrams = async ( if (lazyLoad) { registerLazyLoadedDiagrams(...diagrams); } else { - await loadExternalDiagrams(diagrams); + await loadExternalDiagrams(...diagrams); } }; diff --git a/packages/mermaid/src/styles.ts b/packages/mermaid/src/styles.ts index 0c4a7e1a5..5e7907a80 100644 --- a/packages/mermaid/src/styles.ts +++ b/packages/mermaid/src/styles.ts @@ -1,39 +1,7 @@ -import classDiagram from './diagrams/class/styles'; -import er from './diagrams/er/styles'; -import error from './diagrams/error/styles'; -import flowchart from './diagrams/flowchart/styles'; -import gantt from './diagrams/gantt/styles'; -// import gitGraph from './diagrams/git/styles'; -import info from './diagrams/info/styles'; -import pie from './diagrams/pie/styles'; -import requirement from './diagrams/requirement/styles'; -import sequence from './diagrams/sequence/styles'; -import stateDiagram from './diagrams/state/styles'; -import journey from './diagrams/user-journey/styles'; -import c4 from './diagrams/c4/styles'; -import { FlowChartStyleOptions } from './diagrams/flowchart/styles'; +import type { FlowChartStyleOptions } from './diagrams/flowchart/styles'; import { log } from './logger'; -// TODO @knut: Inject from registerDiagram. -const themes: Record = { - flowchart, - 'flowchart-v2': flowchart, - sequence, - gantt, - classDiagram, - 'classDiagram-v2': classDiagram, - class: classDiagram, - stateDiagram, - state: stateDiagram, - // gitGraph, - info, - pie, - er, - error, - journey, - requirement, - c4, -}; +const themes: Record = {}; const getStyles = ( type: string,