From 1d59779c522c6e2c78a435919cd290804b40f8b7 Mon Sep 17 00:00:00 2001 From: seanryans Date: Thu, 13 Mar 2025 17:27:26 -0700 Subject: [PATCH] feat: add flag to disable font size shrinking --- README.md | 7 +++++++ src/clone-node.ts | 6 +++++- src/types.ts | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a18a2a8b..1d2de444 100644 --- a/README.md +++ b/README.md @@ -302,6 +302,13 @@ Defaults to `image/png` An array of style property names. Can be used to manually specify which style properties are included when cloning nodes. This can be useful for performance-critical scenarios. +### skipFontSizeShrink + +When supplied, the library will skip the process of shrinking the font size. +You may experience the text breaking on the last word. + +Defaults to `false` + ## Browsers Only standard lib is currently used, but make sure your browser supports: diff --git a/src/clone-node.ts b/src/clone-node.ts index 5dfcd117..867c049f 100644 --- a/src/clone-node.ts +++ b/src/clone-node.ts @@ -136,7 +136,11 @@ function cloneCSSStyle( } else { getStyleProperties(options).forEach((name) => { let value = sourceStyle.getPropertyValue(name) - if (name === 'font-size' && value.endsWith('px')) { + if ( + !options.skipFontSizeShrink && + name === 'font-size' && + value.endsWith('px') + ) { const reducedFont = Math.floor(parseFloat(value.substring(0, value.length - 2))) - 0.1 value = `${reducedFont}px` diff --git a/src/types.ts b/src/types.ts index 6023c3c2..0a332ccf 100644 --- a/src/types.ts +++ b/src/types.ts @@ -90,6 +90,10 @@ export interface Options { * A string indicating the image format. The default type is image/png; that type is also used if the given type isn't supported. */ type?: string + /** + * A boolean to turn off shrinking font size. + */ + skipFontSizeShrink?: boolean /** *