diff --git a/ts/adaptors/HTMLAdaptor.ts b/ts/adaptors/HTMLAdaptor.ts index b5d4799df..1a385a545 100644 --- a/ts/adaptors/HTMLAdaptor.ts +++ b/ts/adaptors/HTMLAdaptor.ts @@ -199,6 +199,12 @@ export class HTMLAdaptor< extends AbstractDOMAdaptor implements MinHTMLAdaptor { + /** + * The font size to use when it can't be measured (e.g., the element + * isn't in the DOM). + */ + public static DEFAULT_FONT_SIZE = 16; + /** * The HTML adaptor can measure DOM node sizes */ @@ -588,7 +594,10 @@ export class HTMLAdaptor< */ public fontSize(node: N) { const style = this.window.getComputedStyle(node); - return parseFloat(style.fontSize); + return parseFloat( + style.fontSize || + String((this.constructor as typeof HTMLAdaptor).DEFAULT_FONT_SIZE) + ); } /**