π¬ 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(guideme): base manual fallback on target position rather than any edit
Luis Ortiz71b520e5aaea
diff --git a/src/core/guideme/__tests__/manual.test.ts b/src/core/guideme/__tests__/manual.test.tsindex d21412b..ec79086 100644--- a/src/core/guideme/__tests__/manual.test.ts+++ b/src/core/guideme/__tests__/manual.test.ts@@ -1,7 +1,10 @@import { describe, expect, it } from 'vitest';import type { Screenshot, Step } from '@/core/guides/types';+import type { ClickTarget } from '@/core/screenshot/types';import { stepRequiresManual } from '../manual';+const BOUNDS = { x: 10, y: 20, width: 100, height: 40 };+const step = (overrides: Partial<Step> = {}): Step => ({id: 's1',guideId: 'g1',@@ -14,41 +17,57 @@ const step = (overrides: Partial<Step> = {}): Step => ({...overrides,});-const shot = (edits: Screenshot['edits'], bounds?: Screenshot['bounds']): Screenshot =>+const shot = (target: ClickTarget | null | undefined, bounds = BOUNDS, pixelRatio = 2): Screenshot =>({id: 'sc1',stepId: 's1',blob: new Blob(),mimeType: 'image/webp',- width: 100,- height: 100,- edits,+ width: 400,+ height: 200,+ pixelRatio,bounds,+ edits: { target },}) as Screenshot;+const captured: ClickTarget = { x: 20, y: 40, width: 200, height: 80, border: 'dashed', color: '#4F46E5' };+describe('stepRequiresManual', () => {it('requires manual advance when the step has no element metadata', () => {expect(stepRequiresManual(step({ elementMeta: undefined }), null)).toBe(true);});- it('stays automatic when the step has metadata and no screenshot', () => {+ it('stays automatic when there is no screenshot to inspect', () => {expect(stepRequiresManual(step(), null)).toBe(false);});- it('stays automatic for an untouched capture', () => {- const target = { x: 0, y: 0, width: 10, height: 10, border: 'dashed' as const, color: '#4F46E5' };- expect(stepRequiresManual(step(), shot({ target }, { x: 0, y: 0, width: 10, height: 10 }))).toBe(false);+ it('stays automatic for a target still sitting on the captured element', () => {+ expect(stepRequiresManual(step(), shot(captured))).toBe(false);+ });++ it('ignores a colour or border change', () => {+ expect(stepRequiresManual(step(), shot({ ...captured, color: '#22C55E', border: 'solid' }))).toBe(false);+ });++ it('tolerates sub-pixel rounding', () => {+ expect(stepRequiresManual(step(), shot({ ...captured, x: captured.x + 0.4 }))).toBe(false);+ });++ it('requires manual advance once the target is moved', () => {+ expect(stepRequiresManual(step(), shot({ ...captured, x: captured.x + 30 }))).toBe(true);});- it('requires manual advance once the edit flag is set', () => {- expect(stepRequiresManual(step(), shot({ requiresManual: true }))).toBe(true);+ it('requires manual advance once the target is resized', () => {+ expect(stepRequiresManual(step(), shot({ ...captured, height: captured.height + 25 }))).toBe(true);});- it('treats a cleared target on a real capture as manual', () => {- expect(stepRequiresManual(step(), shot({ target: null }, { x: 0, y: 0, width: 10, height: 10 }))).toBe(true);+ it('requires manual advance when the target was removed or the image replaced', () => {+ expect(stepRequiresManual(step(), shot(null))).toBe(true);});- it('does not flag a cleared target when the capture never had bounds', () => {- expect(stepRequiresManual(step(), shot({ target: null }))).toBe(false);+ it('stays automatic when the capture never recorded bounds', () => {+ const boundless = { ...shot(null) };+ boundless.bounds = undefined;+ expect(stepRequiresManual(step(), boundless)).toBe(false);});});diff --git a/src/core/guideme/manual.ts b/src/core/guideme/manual.tsindex 12a9964..2aeb471 100644--- a/src/core/guideme/manual.ts+++ b/src/core/guideme/manual.ts@@ -1,8 +1,22 @@import type { Screenshot, Step } from '@/core/guides/types';+const POSITION_TOLERANCE = 1;+export function stepRequiresManual(step: Step, screenshot: Screenshot | null | undefined): boolean {if (!step.elementMeta) return true;- if (!screenshot) return false;- if (screenshot.edits?.requiresManual === true) return true;- return screenshot.edits?.target === null && Boolean(screenshot.bounds);+ if (!screenshot?.bounds) return false;++ const target = screenshot.edits?.target;+ if (target === null) return true;+ if (!target) return false;++ const dpr = screenshot.pixelRatio || 1;+ const { bounds } = screenshot;+ const off = (a: number, b: number) => Math.abs(a - b) > POSITION_TOLERANCE;+ return (+ off(target.x, bounds.x * dpr) ||+ off(target.y, bounds.y * dpr) ||+ off(target.width, bounds.width * dpr) ||+ off(target.height, bounds.height * dpr)+ );}diff --git a/src/core/screenshot/types.ts b/src/core/screenshot/types.tsindex 2072781..5dfb947 100644--- a/src/core/screenshot/types.ts+++ b/src/core/screenshot/types.ts@@ -143,5 +143,4 @@ export interface ScreenshotEdits {target?: ClickTarget | null;annotations?: Annotation[];alt?: string;- requiresManual?: boolean;}diff --git a/src/ui/shared/AnnotationEditor.tsx b/src/ui/shared/AnnotationEditor.tsxindex 3953ba5..f2251d8 100644--- a/src/ui/shared/AnnotationEditor.tsx+++ b/src/ui/shared/AnnotationEditor.tsx@@ -36,7 +36,6 @@ import {import type {Annotation,ArrowEnd,- ClickTarget,FontFamily,LineWidth,ScreenshotEdits,@@ -286,18 +285,6 @@ function handleCorners(b: ScreenshotBounds): [Handle, number, number][] {];}-function sameTarget(a: ClickTarget | null, b: ClickTarget | null): boolean {- if (!a || !b) return a === b;- return (- Math.round(a.x) === Math.round(b.x) &&- Math.round(a.y) === Math.round(b.y) &&- Math.round(a.width) === Math.round(b.width) &&- Math.round(a.height) === Math.round(b.height) &&- a.color === b.color &&- a.border === b.border- );-}-function selectionBounds(a: Annotation, scale: number): ScreenshotBounds {const inset = SELECTION_GAP * scale;const b = annotationBounds(a);@@ -409,7 +396,6 @@ export default function AnnotationEditor({ screenshot, tool, onDone, onCancel }:setAnnotations((prev) => prev.map((a) => (a.id === TARGET_ID && a.type === 'target' ? { ...a, ...patch } : a)));};- const initialTargetRef = useRef<ClickTarget | null>(resolveTarget(screenshot));const canvasRef = useRef<HTMLCanvasElement>(null);const textInputRef = useRef<HTMLInputElement>(null);const dragRef = useRef<DragState | null>(null);@@ -891,7 +877,6 @@ export default function AnnotationEditor({ screenshot, tool, onDone, onCancel }:...screenshot.edits,annotations: annotations.filter((a) => a.id !== TARGET_ID),target: nextTarget,- requiresManual: screenshot.edits?.requiresManual || !sameTarget(initialTargetRef.current, nextTarget),};if (viewport) nextEdits.viewport = viewport;await updateScreenshotEdits(screenshot.id, nextEdits);diff --git a/src/ui/shared/ScreenshotView.tsx b/src/ui/shared/ScreenshotView.tsxindex a280db4..1c24c22 100644--- a/src/ui/shared/ScreenshotView.tsx+++ b/src/ui/shared/ScreenshotView.tsx@@ -235,7 +235,7 @@ export default function ScreenshotView({const { width, height } = bitmap;bitmap.close();- const nextEdits: ScreenshotEdits = { ...effectiveEdits, target: null, requiresManual: true };+ const nextEdits: ScreenshotEdits = { ...effectiveEdits, target: null };delete nextEdits.viewport;const nextScreenshot: Screenshot = { ...baseScreenshot, blob: file, mimeType: file.type, width, height };