From 938949885487dff8ff43ed0da6e380aa0920e555 Mon Sep 17 00:00:00 2001 From: Ivo Dejanovic Date: Tue, 11 Mar 2025 09:03:55 +0100 Subject: [PATCH] update: body height limit --- src/utils/layout/calculate-page-layout.ts | 9 +++++---- test/utils/layout/calculate-page-layout.test.ts | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/utils/layout/calculate-page-layout.ts b/src/utils/layout/calculate-page-layout.ts index 9610b12..3165c98 100644 --- a/src/utils/layout/calculate-page-layout.ts +++ b/src/utils/layout/calculate-page-layout.ts @@ -19,11 +19,12 @@ export default function calculatePageLayout( const footerY = footerHeight ? -1 : 0; const bodyY = footerHeight - (pageHeight ? 1 : 0); const backgroundY = 0; + const BODY_HEIGHT_MIN_FACTOR = 0.25; - if (bodyHeight < pageHeight / 3) { - throw new Error( - `Header/footer too big. Page height: ${pageHeight}px, header: ${headerHeight}px, footer: ${footerHeight}px, body: ${bodyHeight}px.` - ); + if (bodyHeight < pageHeight * BODY_HEIGHT_MIN_FACTOR) { + throw new Error('The header and footer are too large to fit on the page. Please reduce their size and try again.', { + cause: `Page height: ${pageHeight}px, header: ${headerHeight}px, footer: ${footerHeight}px, body: ${bodyHeight}px`, + }); } return { diff --git a/test/utils/layout/calculate-page-layout.test.ts b/test/utils/layout/calculate-page-layout.test.ts index b5cbc1c..179a811 100644 --- a/test/utils/layout/calculate-page-layout.test.ts +++ b/test/utils/layout/calculate-page-layout.test.ts @@ -58,7 +58,7 @@ describe('calculatePageLayout', () => { const pageHeight = 1000; expect(() => calculatePageLayout(settings, pageHeight)).toThrow( - `Header/footer too big. Page height: 1000px, header: 1000px, footer: 1000px, body: -998px.` + 'The header and footer are too large to fit on the page. Please reduce their size and try again.' ); });