π¬ A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots π
TypeScript browser-extensionchrome-extensiondocumentationfirefox-extensionguide-generatorlocal-firstmanifest-v3privacy-firstproductivityreactscreenshotstep-by-step-guidetutorialtypescriptworkflowwxt
fix(core): frame a small target tightly on a large capture
Luis Ortiz33bd8de2c183
diff --git a/packages/core/src/screenshot/__tests__/geometry.test.ts b/packages/core/src/screenshot/__tests__/geometry.test.tsindex 7658baa..0038183 100644--- a/packages/core/src/screenshot/__tests__/geometry.test.ts+++ b/packages/core/src/screenshot/__tests__/geometry.test.ts@@ -233,3 +233,27 @@ describe('resizeAnnotation', () => {expect(resizeAnnotation(arrow, 'se', 20, 0)).toMatchObject({ x1: 10, y1: 10, x2: 130, y2: 60 });});});++describe('viewport padding on a large frame', () => {+ const shot = (imgW: number, imgH: number, w: number, h: number) =>+ ({+ id: 's',+ stepId: 't',+ blob: new Blob(),+ mimeType: 'image/png',+ width: imgW,+ height: imgH,+ pixelRatio: 1,+ bounds: { x: imgW / 2, y: imgH / 2, width: w, height: h },+ }) as Screenshot;++ it('frames a small target tightly instead of a third of the screen', () => {+ const viewport = resolveViewport(shot(2560, 1440, 40, 40));+ expect(viewport.width).toBeLessThan(2560 * 0.15);+ });++ it('leaves a browser-sized target as it was', () => {+ const viewport = resolveViewport(shot(1440, 900, 120, 40));+ expect(viewport.width).toBeCloseTo(552, 0);+ });+});diff --git a/packages/core/src/screenshot/geometry.ts b/packages/core/src/screenshot/geometry.tsindex 944c56f..6294b41 100644--- a/packages/core/src/screenshot/geometry.ts+++ b/packages/core/src/screenshot/geometry.ts@@ -3,6 +3,7 @@ import type { Annotation, ClickTarget } from './types';import { DEFAULT_TARGET_COLOR } from './types';const PAD_RATIO = 0.3;+const MAX_PAD_MULTIPLE = 6;export function clamp(val: number, min: number, max: number): number {return Math.max(min, Math.min(max, val));@@ -34,8 +35,8 @@ export function resolveViewport(screenshot: Screenshot): ScreenshotBounds {const imgAspect = imgW / imgH;const elAspect = bw / bh;- let visW = bw + PAD_RATIO * imgW;- let visH = bh + PAD_RATIO * imgH;+ let visW = bw + Math.min(PAD_RATIO * imgW, bw * MAX_PAD_MULTIPLE);+ let visH = bh + Math.min(PAD_RATIO * imgH, bh * MAX_PAD_MULTIPLE);if (elAspect > 1) {visH = visW / imgAspect;