From 24f9ea022b77328cea1ba35d10d2da63cda70632 Mon Sep 17 00:00:00 2001 From: "C. J. Tantay" Date: Fri, 8 Nov 2024 14:25:53 -0800 Subject: [PATCH] add extra content height --- lib/index.js | 4 +++- lib/utils.js | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index 5f5785bf..40fb08ec 100644 --- a/lib/index.js +++ b/lib/index.js @@ -54,6 +54,7 @@ const CROSSWALK_ALLOWED_EXTS = { }; const FIXED_FALLBACK_SCREENSHOT_WIDTH = 375; +const EXTRA_CONTENT_HEIGHT = 200; /** * @typedef {Object} BakerOptions @@ -420,7 +421,8 @@ export class Baker extends EventEmitter { const contentHeight = calculateContentHeight( FIXED_FALLBACK_SCREENSHOT_WIDTH, boundingBox.width, - boundingBox.height + boundingBox.height, + EXTRA_CONTENT_HEIGHT ); await page.setViewport({ diff --git a/lib/utils.js b/lib/utils.js index b3f62efb..d21bd893 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -176,9 +176,15 @@ export function isObject(value) { * @param fixedWidth {number} The fixed width of the viewport. * @param elementWidth {number} The width of the bounding box of the element. * @param elementHeight {number} The height of the bounding box of the element. + * @param extraContentHeight {number} The additional height to add to the calculated content height. * @returns {number} The calculated content height. */ -export function calculateContentHeight(fixedWidth, elementWidth, elementHeight) { +export function calculateContentHeight( + fixedWidth, + elementWidth, + elementHeight, + extraContentHeight = 0 +){ const scaleFactor = fixedWidth / elementWidth; - return Math.round(elementHeight * scaleFactor); + return Math.round(elementHeight * scaleFactor) + extraContentHeight; }