mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-18 07:49:26 +02:00
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:
@@ -2,8 +2,9 @@ import { createText } from '../../createText.js';
|
|||||||
import type { Node } from '../../types.js';
|
import type { Node } from '../../types.js';
|
||||||
import { getConfig } from '../../../diagram-api/diagramAPI.js';
|
import { getConfig } from '../../../diagram-api/diagramAPI.js';
|
||||||
import { select } from 'd3';
|
import { select } from 'd3';
|
||||||
|
import defaultConfig from '../../../defaultConfig.js';
|
||||||
import { evaluate, sanitizeText } from '../../../diagrams/common/common.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';
|
import type { D3Selection, Point } from '../../../types.js';
|
||||||
|
|
||||||
export const labelHelper = async <T extends SVGGraphicsElement>(
|
export const labelHelper = async <T extends SVGGraphicsElement>(
|
||||||
@@ -77,10 +78,7 @@ export const labelHelper = async <T extends SVGGraphicsElement>(
|
|||||||
? getConfig().fontSize
|
? getConfig().fontSize
|
||||||
: window.getComputedStyle(document.body).fontSize;
|
: window.getComputedStyle(document.body).fontSize;
|
||||||
const enlargingFactor = 5;
|
const enlargingFactor = 5;
|
||||||
const parsedBodyFontSize =
|
const [parsedBodyFontSize = defaultConfig.fontSize] = parseFontSize(bodyFontSize);
|
||||||
typeof bodyFontSize === 'number'
|
|
||||||
? bodyFontSize
|
|
||||||
: parseInt(bodyFontSize ?? '', 10);
|
|
||||||
const width = parsedBodyFontSize * enlargingFactor + 'px';
|
const width = parsedBodyFontSize * enlargingFactor + 'px';
|
||||||
img.style.minWidth = width;
|
img.style.minWidth = width;
|
||||||
img.style.maxWidth = width;
|
img.style.maxWidth = width;
|
||||||
|
Reference in New Issue
Block a user