refactor: use parseFontSize()

Handle `NaN` values by using `parseFontSize()`.

Suggested-by: https://github.com/mermaid-js/mermaid/pull/5974#discussion_r1810570967
This commit is contained in:
Alois Klink
2024-10-22 21:30:56 +09:00
parent 6cc0132e0a
commit bb97fdbd1e

View File

@@ -2,8 +2,9 @@ import { createText } from '../../createText.js';
import type { Node } from '../../types.js';
import { getConfig } from '../../../diagram-api/diagramAPI.js';
import { select } from 'd3';
import defaultConfig from '../../../defaultConfig.js';
import { evaluate, sanitizeText } from '../../../diagrams/common/common.js';
import { decodeEntities, handleUndefinedAttr } from '../../../utils.js';
import { decodeEntities, handleUndefinedAttr, parseFontSize } from '../../../utils.js';
import type { D3Selection, Point } from '../../../types.js';
export const labelHelper = async <T extends SVGGraphicsElement>(
@@ -77,10 +78,7 @@ export const labelHelper = async <T extends SVGGraphicsElement>(
? getConfig().fontSize
: window.getComputedStyle(document.body).fontSize;
const enlargingFactor = 5;
const parsedBodyFontSize =
typeof bodyFontSize === 'number'
? bodyFontSize
: parseInt(bodyFontSize ?? '', 10);
const [parsedBodyFontSize = defaultConfig.fontSize] = parseFontSize(bodyFontSize);
const width = parsedBodyFontSize * enlargingFactor + 'px';
img.style.minWidth = width;
img.style.maxWidth = width;