Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion src/clone-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ function cloneCSSStyle<T extends HTMLElement>(
} 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`
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
*
Expand Down
Loading