mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-14 22:09:29 +02:00
Remove katex from mermaid.tiny
This commit is contained in:
@@ -32,7 +32,7 @@ const buildPackage = async (entryName: keyof typeof packageOptions) => {
|
||||
{
|
||||
...iifeOptions,
|
||||
minify: true,
|
||||
includeLargeDiagrams: false,
|
||||
includeLargeFeatures: false,
|
||||
metafile: shouldVisualize,
|
||||
}
|
||||
);
|
||||
|
@@ -14,7 +14,7 @@ export interface MermaidBuildOptions {
|
||||
metafile: boolean;
|
||||
format: 'esm' | 'iife';
|
||||
entryName: keyof typeof packageOptions;
|
||||
includeLargeDiagrams: boolean;
|
||||
includeLargeFeatures: boolean;
|
||||
}
|
||||
|
||||
export const defaultOptions: Omit<MermaidBuildOptions, 'entryName'> = {
|
||||
@@ -22,7 +22,7 @@ export const defaultOptions: Omit<MermaidBuildOptions, 'entryName'> = {
|
||||
metafile: false,
|
||||
core: false,
|
||||
format: 'esm',
|
||||
includeLargeDiagrams: true,
|
||||
includeLargeFeatures: true,
|
||||
} as const;
|
||||
|
||||
const buildOptions = (override: BuildOptions): BuildOptions => {
|
||||
@@ -43,14 +43,14 @@ const buildOptions = (override: BuildOptions): BuildOptions => {
|
||||
|
||||
const getFileName = (
|
||||
fileName: string,
|
||||
{ core, format, minify, includeLargeDiagrams }: MermaidBuildOptions
|
||||
{ core, format, minify, includeLargeFeatures }: MermaidBuildOptions
|
||||
) => {
|
||||
if (core) {
|
||||
fileName += '.core';
|
||||
} else if (format === 'esm') {
|
||||
fileName += '.esm';
|
||||
}
|
||||
if (!includeLargeDiagrams) {
|
||||
if (!includeLargeFeatures) {
|
||||
fileName += '.tiny';
|
||||
}
|
||||
if (minify) {
|
||||
@@ -60,7 +60,7 @@ const getFileName = (
|
||||
};
|
||||
|
||||
export const getBuildConfig = (options: MermaidBuildOptions): BuildOptions => {
|
||||
const { core, entryName, metafile, format, includeLargeDiagrams, minify } = options;
|
||||
const { core, entryName, metafile, format, includeLargeFeatures, minify } = options;
|
||||
const external: string[] = ['require', 'fs', 'path'];
|
||||
const { name, file, packageName } = packageOptions[entryName];
|
||||
const outFileName = getFileName(name, options);
|
||||
@@ -75,7 +75,7 @@ export const getBuildConfig = (options: MermaidBuildOptions): BuildOptions => {
|
||||
chunkNames: `chunks/${outFileName}/[name]-[hash]`,
|
||||
define: {
|
||||
// This needs to be stringified for esbuild
|
||||
includeLargeDiagrams: `${includeLargeDiagrams}`,
|
||||
includeLargeFeatures: `${includeLargeFeatures}`,
|
||||
'import.meta.vitest': 'undefined',
|
||||
},
|
||||
});
|
||||
|
@@ -95,7 +95,7 @@ export const getBuildConfig = ({ minify, core, watch, entryName }: BuildOptions)
|
||||
],
|
||||
define: {
|
||||
// Needs to be string
|
||||
includeLargeDiagrams: 'true',
|
||||
includeLargeFeatures: 'true',
|
||||
},
|
||||
};
|
||||
|
||||
|
@@ -68,7 +68,7 @@ export const addDiagrams = () => {
|
||||
}
|
||||
);
|
||||
|
||||
if (includeLargeDiagrams) {
|
||||
if (includeLargeFeatures) {
|
||||
registerLazyLoadedDiagrams(flowchartElk, mindmap);
|
||||
}
|
||||
|
||||
|
@@ -341,6 +341,7 @@ export const renderKatex = async (text: string, config: MermaidConfig): Promise<
|
||||
return text.replace(katexRegex, 'MathML is unsupported in this environment.');
|
||||
}
|
||||
|
||||
if (includeLargeFeatures) {
|
||||
const { default: katex } = await import('katex');
|
||||
return text
|
||||
.split(lineBreakRegex)
|
||||
@@ -364,6 +365,12 @@ export const renderKatex = async (text: string, config: MermaidConfig): Promise<
|
||||
.replace(/\n/g, ' ')
|
||||
.replace(/<annotation.*<\/annotation>/g, '')
|
||||
);
|
||||
}
|
||||
|
||||
return text.replace(
|
||||
katexRegex,
|
||||
'Katex is unsupported in mermaid.tiny.js. Please use mermaid.js or mermaid.min.js.'
|
||||
);
|
||||
};
|
||||
|
||||
export default {
|
||||
|
@@ -32,7 +32,7 @@ import type { DiagramMetadata, DiagramStyleClassDef } from './diagram-api/types.
|
||||
import { preprocessDiagram } from './preprocess.js';
|
||||
import { decodeEntities } from './utils.js';
|
||||
|
||||
const version = packageVersion + (includeLargeDiagrams ? '' : '-tiny');
|
||||
const version = packageVersion + (includeLargeFeatures ? '' : '-tiny');
|
||||
|
||||
const MAX_TEXTLENGTH = 50_000;
|
||||
const MAX_TEXTLENGTH_EXCEEDED_MSG =
|
||||
|
2
packages/mermaid/src/type.d.ts
vendored
2
packages/mermaid/src/type.d.ts
vendored
@@ -1,2 +1,2 @@
|
||||
// eslint-disable-next-line no-var
|
||||
declare var includeLargeDiagrams: boolean;
|
||||
declare var includeLargeFeatures: boolean;
|
||||
|
@@ -36,7 +36,7 @@ export default defineConfig({
|
||||
},
|
||||
define: {
|
||||
// Needs to be string
|
||||
includeLargeDiagrams: 'true',
|
||||
includeLargeFeatures: 'true',
|
||||
'import.meta.vitest': 'undefined',
|
||||
},
|
||||
});
|
||||
|
Reference in New Issue
Block a user