From bb97fdbd1e539f9585a613844b06b6593d09e44d Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Tue, 22 Oct 2024 21:30:56 +0900 Subject: [PATCH] refactor: use `parseFontSize()` Handle `NaN` values by using `parseFontSize()`. Suggested-by: https://github.com/mermaid-js/mermaid/pull/5974#discussion_r1810570967 --- .../src/rendering-util/rendering-elements/shapes/util.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/util.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/util.ts index fcae715d8..883129e9a 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/util.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/util.ts @@ -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 ( @@ -77,10 +78,7 @@ export const labelHelper = async ( ? 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;