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