mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-12-02 02:24:20 +01:00
fix pnpm lock and use promise.all to speed up icon replacement
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
// @ts-nocheck TODO: Fix types
|
// @ts-nocheck TODO: Fix types
|
||||||
import { select } from 'd3';
|
import { select } from 'd3';
|
||||||
import type { MermaidConfig } from '../config.type.js';
|
import type { MermaidConfig } from '../config.type.js';
|
||||||
import { getConfig } from '../diagram-api/diagramAPI.js';
|
import { getConfig, sanitizeText } from '../diagram-api/diagramAPI.js';
|
||||||
import type { SVGGroup } from '../diagram-api/types.js';
|
import type { SVGGroup } from '../diagram-api/types.js';
|
||||||
import common, { hasKatex, renderKatex } from '../diagrams/common/common.js';
|
import common, { hasKatex, renderKatex } from '../diagrams/common/common.js';
|
||||||
import type { D3TSpanElement, D3TextElement } from '../diagrams/common/commonTypes.js';
|
import type { D3TSpanElement, D3TextElement } from '../diagrams/common/commonTypes.js';
|
||||||
@@ -192,24 +192,26 @@ export async function replaceIconSubstring(text: string) {
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
let newText = text;
|
const replacements = await Promise.all(
|
||||||
|
matches.map(async ([fullMatch, prefix, iconName]) => {
|
||||||
for (const match of matches) {
|
const registeredIconName = `${prefix}:${iconName}`;
|
||||||
const [fullMatch, prefix, iconName] = match;
|
try {
|
||||||
const registeredIconName = `${prefix}:${iconName}`;
|
const isIconRegistered = await isIconAvailable(registeredIconName);
|
||||||
try {
|
const replacement = isIconRegistered
|
||||||
const isIconAvail = await isIconAvailable(registeredIconName);
|
? await getIconSVG(registeredIconName, undefined, { class: 'label-icon' })
|
||||||
if (isIconAvail) {
|
: `<i class='${sanitizeText(fullMatch).replace(':', ' ')}'></i>`;
|
||||||
const faIcon = await getIconSVG(registeredIconName, undefined, { class: 'label-icon' });
|
return { fullMatch, replacement };
|
||||||
newText = newText.replace(fullMatch, faIcon);
|
} catch (error) {
|
||||||
} else {
|
log.error(`Error processing ${registeredIconName}:`, error);
|
||||||
newText = newText.replace(fullMatch, `<i class='${fullMatch.replace(':', ' ')}'></i>`);
|
return { fullMatch, replacement: fullMatch };
|
||||||
}
|
}
|
||||||
} catch (error) {
|
})
|
||||||
log.error(`Error processing ${registeredIconName}:`, error);
|
);
|
||||||
}
|
|
||||||
}
|
return replacements.reduce(
|
||||||
return newText;
|
(text, { fullMatch, replacement }) => text.replace(fullMatch, replacement),
|
||||||
|
text
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note when using from flowcharts converting the API isNode means classes should be set accordingly. When using htmlLabels => to sett classes to'nodeLabel' when isNode=true otherwise 'edgeLabel'
|
// Note when using from flowcharts converting the API isNode means classes should be set accordingly. When using htmlLabels => to sett classes to'nodeLabel' when isNode=true otherwise 'edgeLabel'
|
||||||
|
|||||||
2
pnpm-lock.yaml
generated
2
pnpm-lock.yaml
generated
@@ -22669,4 +22669,4 @@ snapshots:
|
|||||||
|
|
||||||
yocto-queue@1.1.1: {}
|
yocto-queue@1.1.1: {}
|
||||||
|
|
||||||
zwitch@2.0.4: {}
|
zwitch@2.0.4: {}
|
||||||
|
|||||||
Reference in New Issue
Block a user