π¬ 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
feat(screenshot): let a render bake only the redactions
davbio1f21e491ce27
diff --git a/src/core/screenshot/__tests__/render.test.ts b/src/core/screenshot/__tests__/render.test.tsindex 9459b9c..4603611 100644--- a/src/core/screenshot/__tests__/render.test.ts+++ b/src/core/screenshot/__tests__/render.test.ts@@ -225,4 +225,38 @@ describe('renderScreenshot annotations', () => {expect(drawAnnotation).not.toHaveBeenCalled();});++ describe("annotations: 'redactions'", () => {+ // This is the guarantee the bundle format rests on: the exported pixels must+ // carry the redactions and nothing else. Inverting the filter would ship the+ // concealed content in the clear, so it is asserted directly rather than via+ // the caller.+ it('draws the redactions and leaves every other annotation out', async () => {+ const s = makeScreenshot({+ bounds: { x: 10, y: 10, width: 20, height: 20 },+ edits: { annotations },+ });+ await renderScreenshot(s, { annotations: 'redactions', target: false });++ const ids = drawAnnotation.mock.calls.map((c) => (c[1] as Annotation).id);+ expect(ids).toEqual(['a2']);+ });++ it('still draws everything under the default', async () => {+ await renderScreenshot(makeScreenshot({ edits: { annotations } }), { target: false });++ const ids = drawAnnotation.mock.calls.map((c) => (c[1] as Annotation).id);+ expect(ids).toEqual(['a1', 'a2']);+ });++ it('draws nothing when the screenshot has no redactions to bake', async () => {+ const box = annotations[0];+ await renderScreenshot(makeScreenshot({ edits: { annotations: [box] } }), {+ annotations: 'redactions',+ target: false,+ });++ expect(drawAnnotation).not.toHaveBeenCalled();+ });+ });});diff --git a/src/core/screenshot/render.ts b/src/core/screenshot/render.tsindex 2853375..cc13446 100644--- a/src/core/screenshot/render.ts+++ b/src/core/screenshot/render.ts@@ -7,6 +7,8 @@ interface RenderOptions {quality?: number;viewport?: ScreenshotBounds;target?: boolean;+ /** 'redactions' bakes only what must never be undone, leaving the rest editable. */+ annotations?: 'all' | 'redactions';}export async function imageDimensions(file: Blob): Promise<{ width: number; height: number }> {@@ -47,7 +49,11 @@ export async function renderScreenshot(screenshot: Screenshot, opts: RenderOptio);}- for (const a of screenshot.edits?.annotations ?? []) drawAnnotation(ctx, a, viewport.x, viewport.y);+ const only = opts.annotations ?? 'all';+ for (const a of screenshot.edits?.annotations ?? []) {+ if (only === 'redactions' && a.type !== 'redact') continue;+ drawAnnotation(ctx, a, viewport.x, viewport.y);+ }return canvas.convertToBlob({ type: format, quality });}