Remove katex from mermaid.tiny

This commit is contained in:
Sidharth Vinod
2024-03-01 12:54:42 +05:30
parent 3a12a63c32
commit 882e4971eb
8 changed files with 38 additions and 31 deletions

View File

@@ -32,7 +32,7 @@ const buildPackage = async (entryName: keyof typeof packageOptions) => {
{
...iifeOptions,
minify: true,
includeLargeDiagrams: false,
includeLargeFeatures: false,
metafile: shouldVisualize,
}
);

View File

@@ -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',
},
});

View File

@@ -95,7 +95,7 @@ export const getBuildConfig = ({ minify, core, watch, entryName }: BuildOptions)
],
define: {
// Needs to be string
includeLargeDiagrams: 'true',
includeLargeFeatures: 'true',
},
};

View File

@@ -68,7 +68,7 @@ export const addDiagrams = () => {
}
);
if (includeLargeDiagrams) {
if (includeLargeFeatures) {
registerLazyLoadedDiagrams(flowchartElk, mindmap);
}

View File

@@ -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 {

View File

@@ -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 =

View File

@@ -1,2 +1,2 @@
// eslint-disable-next-line no-var
declare var includeLargeDiagrams: boolean;
declare var includeLargeFeatures: boolean;

View File

@@ -36,7 +36,7 @@ export default defineConfig({
},
define: {
// Needs to be string
includeLargeDiagrams: 'true',
includeLargeFeatures: 'true',
'import.meta.vitest': 'undefined',
},
});