Skip to content

Commit

Permalink
add extra content height
Browse files Browse the repository at this point in the history
  • Loading branch information
cjtantay committed Nov 8, 2024
1 parent a252019 commit 24f9ea0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const CROSSWALK_ALLOWED_EXTS = {
};

const FIXED_FALLBACK_SCREENSHOT_WIDTH = 375;
const EXTRA_CONTENT_HEIGHT = 200;

/**
* @typedef {Object} BakerOptions
Expand Down Expand Up @@ -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({
Expand Down
10 changes: 8 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 24f9ea0

Please sign in to comment.