π¬ 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): make the click target a shaped, coloured marker at the click point
Luis Ortizcbe265da14ee
diff --git a/src/core/capture/events/handlers.ts b/src/core/capture/events/handlers.tsindex ed7d995..ea0241a 100644--- a/src/core/capture/events/handlers.ts+++ b/src/core/capture/events/handlers.ts@@ -66,12 +66,13 @@ class CaptureController {}}- private async captureAction(action: string, target: HTMLElement) {+ private async captureAction(action: string, target: HTMLElement, point?: { x: number; y: number }) {await waitForPaint();+ const elementMeta = extractElementMeta(target);await sendMessage('captureStep', {guideId: this.guideId,action,- elementMeta: extractElementMeta(target),+ elementMeta: point ? { ...elementMeta, clickPoint: point } : elementMeta,domContext: extractDOMContext(target, action),});}@@ -99,7 +100,7 @@ class CaptureController {if (isNavigatingClick(target)) {me.preventDefault();me.stopImmediatePropagation();- this.queue.add(() => this.captureAction('click', target));+ this.queue.add(() => this.captureAction('click', target, { x: me.clientX, y: me.clientY }));const anchor = target.closest('a[href]') as HTMLAnchorElement;if (anchor) {const href = anchor.href;@@ -112,7 +113,7 @@ class CaptureController {return;}- this.queue.add(() => this.captureAction('click', target));+ this.queue.add(() => this.captureAction('click', target, { x: me.clientX, y: me.clientY }));}private onAuxClick(e: Event) {@@ -120,7 +121,9 @@ class CaptureController {if (!raw || !(raw instanceof Element)) return;const target = findFocusableAncestor(raw);if (isMimikElement(target)) return;- this.queue.add(() => this.captureAction('auxclick', target));+ this.queue.add(() =>+ this.captureAction('auxclick', target, { x: (e as MouseEvent).clientX, y: (e as MouseEvent).clientY }),+ );}private onKeydown(e: Event) {diff --git a/src/core/guides/types.ts b/src/core/guides/types.tsindex 15f9d76..f2ff325 100644--- a/src/core/guides/types.ts+++ b/src/core/guides/types.ts@@ -39,6 +39,7 @@ export interface Screenshot {height: number;bounds?: ScreenshotBounds;pixelRatio?: number;+ clickPoint?: { x: number; y: number };edits?: ScreenshotEdits;}@@ -62,4 +63,5 @@ export interface ElementMeta {dataTestId: string | null;rect: { x: number; y: number; width: number; height: number };devicePixelRatio: number;+ clickPoint?: { x: number; y: number };}diff --git a/src/core/screenshot/geometry.ts b/src/core/screenshot/geometry.tsindex cd49275..1cf49cc 100644--- a/src/core/screenshot/geometry.ts+++ b/src/core/screenshot/geometry.ts@@ -1,5 +1,6 @@import type { Screenshot, ScreenshotBounds } from '@/core/guides/types';-import type { Annotation } from './types';+import type { Annotation, ClickTarget } from './types';+import { DEFAULT_TARGET_COLOR } from './types';const PAD_RATIO = 0.3;@@ -99,6 +100,7 @@ export function annotationBounds(a: Annotation): ScreenshotBounds {switch (a.type) {case 'box':case 'redact':+ case 'target':return { x: a.x, y: a.y, width: a.w, height: a.h };case 'arrow':return {@@ -133,6 +135,7 @@ export function moveAnnotation(a: Annotation, dx: number, dy: number): Annotatioswitch (a.type) {case 'box':case 'redact':+ case 'target':case 'text':return { ...a, x: a.x + dx, y: a.y + dy };case 'arrow':@@ -143,7 +146,7 @@ export function moveAnnotation(a: Annotation, dx: number, dy: number): Annotatio}export function resizeAnnotation(a: Annotation, handle: Handle, dx: number, dy: number): Annotation {- if (a.type !== 'box' && a.type !== 'redact') return a;+ if (a.type !== 'box' && a.type !== 'redact' && a.type !== 'target') return a;const left = handle === 'nw' || handle === 'sw';const top = handle === 'nw' || handle === 'ne';return {@@ -154,3 +157,36 @@ export function resizeAnnotation(a: Annotation, handle: Handle, dx: number, dy:h: Math.max(MIN_ANNOTATION, top ? a.h - dy : a.h + dy),};}++const DEFAULT_TARGET_CSS_SIZE = 44;++export function resolveTarget(screenshot: Screenshot): ClickTarget | null {+ const explicit = screenshot.edits?.target;+ if (explicit !== undefined) return explicit;++ const dpr = screenshot.pixelRatio || 1;+ const size = DEFAULT_TARGET_CSS_SIZE * dpr;+ const point = screenshot.clickPoint;+ const bounds = screenshot.bounds;++ let cx: number;+ let cy: number;+ if (point) {+ cx = point.x * dpr;+ cy = point.y * dpr;+ } else if (bounds) {+ cx = (bounds.x + bounds.width / 2) * dpr;+ cy = (bounds.y + bounds.height / 2) * dpr;+ } else {+ return null;+ }++ return {+ x: cx - size / 2,+ y: cy - size / 2,+ width: size,+ height: size,+ shape: 'circle',+ color: DEFAULT_TARGET_COLOR,+ };+}diff --git a/src/core/screenshot/render.ts b/src/core/screenshot/render.tsindex 76ed356..71483af 100644--- a/src/core/screenshot/render.ts+++ b/src/core/screenshot/render.ts@@ -1,7 +1,10 @@import type { Screenshot } from '@/core/guides/types';-import { resolveViewport } from './geometry';+import { resolveTarget, resolveViewport } from './geometry';import type { Annotation } from './types';+const TARGET_STROKE = 4;+const TARGET_RADIUS = 10;+interface RenderOptions {format?: 'image/webp' | 'image/jpeg' | 'image/png';quality?: number;@@ -32,6 +35,18 @@ function drawAnnotation(ctx: OffscreenCanvasRenderingContext2D, a: Annotation, octx.lineWidth = 3;ctx.strokeRect(a.x, a.y, a.w, a.h);break;+ case 'target':+ ctx.strokeStyle = a.color;+ ctx.lineWidth = TARGET_STROKE;+ if (a.shape === 'circle') {+ ctx.beginPath();+ ctx.ellipse(a.x + a.w / 2, a.y + a.h / 2, a.w / 2, a.h / 2, 0, 0, Math.PI * 2);+ ctx.stroke();+ } else {+ drawRoundedRect(ctx, a.x, a.y, a.w, a.h, TARGET_RADIUS);+ ctx.stroke();+ }+ break;case 'arrow': {const head = 14;const angle = Math.atan2(a.y2 - a.y1, a.x2 - a.x1);@@ -90,16 +105,23 @@ export async function renderScreenshot(screenshot: Screenshot, opts: RenderOptioctx.translate(-viewport.x, -viewport.y);- const target = screenshot.edits?.target === undefined ? screenshot.bounds : screenshot.edits.target;+ const target = resolveTarget(screenshot);if (target) {- const dpr = screenshot.pixelRatio || 1;- ctx.save();- ctx.strokeStyle = '#4F46E5';- ctx.lineWidth = 3.5;- ctx.setLineDash([8, 5]);- drawRoundedRect(ctx, target.x * dpr, target.y * dpr, target.width * dpr, target.height * dpr, 12);- ctx.stroke();- ctx.restore();+ drawAnnotation(+ ctx,+ {+ id: 'target',+ type: 'target',+ x: target.x,+ y: target.y,+ w: target.width,+ h: target.height,+ color: target.color,+ shape: target.shape,+ },+ viewport.x,+ viewport.y,+ );}for (const a of screenshot.edits?.annotations ?? []) drawAnnotation(ctx, a, viewport.x, viewport.y);diff --git a/src/core/screenshot/types.ts b/src/core/screenshot/types.tsindex 28d1aac..c032fa8 100644--- a/src/core/screenshot/types.ts+++ b/src/core/screenshot/types.ts@@ -1,15 +1,36 @@import type { ScreenshotBounds } from '@/core/guides/types';+export type TargetShape = 'circle' | 'rect';++export const TARGET_COLORS = [+ '#F43F5E',+ '#EC4899',+ '#A855F7',+ '#3B82F6',+ '#14B8A6',+ '#22C55E',+ '#EAB308',+ '#F97316',+] as const;++export const DEFAULT_TARGET_COLOR = '#F97316';++export interface ClickTarget extends ScreenshotBounds {+ shape: TargetShape;+ color: string;+}+export type Annotation =| { id: string; type: 'box'; x: number; y: number; w: number; h: number; color: string }| { id: string; type: 'arrow'; x1: number; y1: number; x2: number; y2: number; color: string }| { id: string; type: 'text'; x: number; y: number; text: string; color: string; size: number }| { id: string; type: 'freehand'; points: number[]; color: string }- | { id: string; type: 'redact'; x: number; y: number; w: number; h: number; style: 'blur' | 'solid' };+ | { id: string; type: 'redact'; x: number; y: number; w: number; h: number; style: 'blur' | 'solid' }+ | { id: string; type: 'target'; x: number; y: number; w: number; h: number; color: string; shape: TargetShape };export interface ScreenshotEdits {viewport?: ScreenshotBounds;- target?: ScreenshotBounds | null;+ target?: ClickTarget | null;annotations?: Annotation[];alt?: string;}diff --git a/src/entrypoints/background/step-pipeline.ts b/src/entrypoints/background/step-pipeline.tsindex f8c0644..d824f3d 100644--- a/src/entrypoints/background/step-pipeline.ts+++ b/src/entrypoints/background/step-pipeline.ts@@ -24,6 +24,7 @@ async function takeScreenshot(stepId: string, meta: ElementMeta): Promise<stringheight: img.height,bounds: { x: meta.rect.x, y: meta.rect.y, width: meta.rect.width, height: meta.rect.height },pixelRatio: meta.devicePixelRatio,+ clickPoint: meta.clickPoint,};img.close();await saveScreenshot(screenshot);diff --git a/src/ui/shared/ScreenshotView.tsx b/src/ui/shared/ScreenshotView.tsxindex 0bc3feb..b9dc2b0 100644--- a/src/ui/shared/ScreenshotView.tsx+++ b/src/ui/shared/ScreenshotView.tsx@@ -3,9 +3,10 @@ import { useEffect, useRef, useState } from 'react';import { i18n } from '#imports';import { deleteScreenshot, updateScreenshotBlob, updateScreenshotEdits } from '@/core/guides/service';import type { Screenshot, ScreenshotBounds } from '@/core/guides/types';-import { panBy, resolveViewport, zoomBy } from '@/core/screenshot/geometry';+import { panBy, resolveTarget, resolveViewport, zoomBy } from '@/core/screenshot/geometry';import { renderScreenshot } from '@/core/screenshot/render';-import type { ScreenshotEdits } from '@/core/screenshot/types';+import type { ClickTarget, ScreenshotEdits } from '@/core/screenshot/types';+import { DEFAULT_TARGET_COLOR } from '@/core/screenshot/types';import {DropdownMenu,DropdownMenuContent,@@ -50,13 +51,13 @@ function withFullViewport(screenshot: Screenshot): Screenshot {};}-function defaultTargetRect(screenshot: Screenshot): ScreenshotBounds {+function defaultTargetRect(screenshot: Screenshot): ClickTarget {const dpr = screenshot.pixelRatio || 1;const width = screenshot.width / dpr;const height = screenshot.height / dpr;const w = width * TARGET_WIDTH_RATIO;const h = height * TARGET_HEIGHT_RATIO;- return { x: (width - w) / 2, y: (height - h) / 2, width: w, height: h };+ return { x: (width - w) / 2, y: (height - h) / 2, width: w, height: h, shape: 'circle', color: DEFAULT_TARGET_COLOR };}export default function ScreenshotView({@@ -221,7 +222,7 @@ export default function ScreenshotView({const handleAddClickTarget = () => {const nextEdits: ScreenshotEdits = {...effectiveEdits,- target: effectiveEdits?.target ?? effectiveScreenshot.bounds ?? defaultTargetRect(effectiveScreenshot),+ target: resolveTarget(effectiveScreenshot) ?? defaultTargetRect(effectiveScreenshot),};setEditsOverride(nextEdits);scheduleSave(nextEdits);