From 2a544d59cee543dd9b9bcaa756567dd3dfdf7d85 Mon Sep 17 00:00:00 2001 From: Jamie Li Date: Wed, 12 Apr 2023 16:43:15 -0700 Subject: [PATCH] Add the ability to screenshot a part of the screen --- packages/storycap/src/node/capturing-browser.ts | 1 + packages/storycap/src/shared/screenshot-options-helper.ts | 1 + packages/storycap/src/shared/types.ts | 1 + 3 files changed, 3 insertions(+) diff --git a/packages/storycap/src/node/capturing-browser.ts b/packages/storycap/src/node/capturing-browser.ts index 2a3757083..3a91a2b78 100644 --- a/packages/storycap/src/node/capturing-browser.ts +++ b/packages/storycap/src/node/capturing-browser.ts @@ -418,6 +418,7 @@ export class CapturingBrowser extends StoryPreviewBrowser { fullPage: emittedScreenshotOptions.fullPage, omitBackground: emittedScreenshotOptions.omitBackground, captureBeyondViewport: emittedScreenshotOptions.captureBeyondViewport, + clip: emittedScreenshotOptions.clip ?? undefined, }); let buffer: Buffer | null = null; diff --git a/packages/storycap/src/shared/screenshot-options-helper.ts b/packages/storycap/src/shared/screenshot-options-helper.ts index 63360d27a..8996b0499 100644 --- a/packages/storycap/src/shared/screenshot-options-helper.ts +++ b/packages/storycap/src/shared/screenshot-options-helper.ts @@ -12,6 +12,7 @@ const defaultScreenshotOptions = { variants: {}, omitBackground: false, captureBeyondViewport: true, + clip: null, } as const; /** diff --git a/packages/storycap/src/shared/types.ts b/packages/storycap/src/shared/types.ts index 450a0dd94..85d23bb08 100644 --- a/packages/storycap/src/shared/types.ts +++ b/packages/storycap/src/shared/types.ts @@ -24,6 +24,7 @@ export interface ScreenshotOptionFragments { skip?: boolean; omitBackground?: boolean; captureBeyondViewport?: boolean; + clip?: { x: number; y: number; width: number; height: number } | null; } export interface ScreenshotOptionFragmentsForVariant extends ScreenshotOptionFragments {