🎬 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(editor): keep the dashed target outline and make its colour and border editable
Luis Ortiz01f7035b77b8
diff --git a/src/core/screenshot/geometry.ts b/src/core/screenshot/geometry.tsindex 1cf49cc..f3637ff 100644--- a/src/core/screenshot/geometry.ts+++ b/src/core/screenshot/geometry.ts@@ -158,35 +158,20 @@ export function resizeAnnotation(a: Annotation, handle: Handle, dx: number, 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;+ if (!bounds) return null;- 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;- }-+ const dpr = screenshot.pixelRatio || 1;return {- x: cx - size / 2,- y: cy - size / 2,- width: size,- height: size,- shape: 'circle',+ x: bounds.x * dpr,+ y: bounds.y * dpr,+ width: bounds.width * dpr,+ height: bounds.height * dpr,+ border: 'dashed',color: DEFAULT_TARGET_COLOR,};}diff --git a/src/core/screenshot/render.ts b/src/core/screenshot/render.tsindex 71483af..d980538 100644--- a/src/core/screenshot/render.ts+++ b/src/core/screenshot/render.ts@@ -2,8 +2,8 @@ import type { Screenshot } from '@/core/guides/types';import { resolveTarget, resolveViewport } from './geometry';import type { Annotation } from './types';-const TARGET_STROKE = 4;-const TARGET_RADIUS = 10;+const TARGET_STROKE = 3.5;+const TARGET_RADIUS = 12;interface RenderOptions {format?: 'image/webp' | 'image/jpeg' | 'image/png';@@ -38,14 +38,9 @@ function drawAnnotation(ctx: OffscreenCanvasRenderingContext2D, a: Annotation, ocase '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();- }+ if (a.border === 'dashed') ctx.setLineDash([8, 5]);+ drawRoundedRect(ctx, a.x, a.y, a.w, a.h, TARGET_RADIUS);+ ctx.stroke();break;case 'arrow': {const head = 14;@@ -117,7 +112,7 @@ export async function renderScreenshot(screenshot: Screenshot, opts: RenderOptiow: target.width,h: target.height,color: target.color,- shape: target.shape,+ border: target.border,},viewport.x,viewport.y,diff --git a/src/core/screenshot/types.ts b/src/core/screenshot/types.tsindex c032fa8..ba4cc3d 100644--- a/src/core/screenshot/types.ts+++ b/src/core/screenshot/types.ts@@ -1,8 +1,9 @@import type { ScreenshotBounds } from '@/core/guides/types';-export type TargetShape = 'circle' | 'rect';+export type TargetBorder = 'dashed' | 'solid';export const TARGET_COLORS = [+ '#4F46E5','#F43F5E','#EC4899','#A855F7',@@ -10,13 +11,12 @@ export const TARGET_COLORS = ['#14B8A6','#22C55E','#EAB308',- '#F97316',] as const;-export const DEFAULT_TARGET_COLOR = '#F97316';+export const DEFAULT_TARGET_COLOR = '#4F46E5';export interface ClickTarget extends ScreenshotBounds {- shape: TargetShape;+ border: TargetBorder;color: string;}@@ -26,7 +26,7 @@ export type Annotation =| { 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: 'target'; x: number; y: number; w: number; h: number; color: string; shape: TargetShape };+ | { id: string; type: 'target'; x: number; y: number; w: number; h: number; color: string; border: TargetBorder };export interface ScreenshotEdits {viewport?: ScreenshotBounds;diff --git a/src/locales/en.yml b/src/locales/en.ymlindex a829d6f..b2dc41d 100644--- a/src/locales/en.yml+++ b/src/locales/en.yml@@ -185,7 +185,7 @@ annotationEditor:colorLabel: ColourtextPlaceholder: Type something...targetColor: Target color- targetShape: Target shape+ targetBorder: Border styledone: DoneexportMenu:diff --git a/src/locales/es.yml b/src/locales/es.ymlindex e117d0d..71f3b42 100644--- a/src/locales/es.yml+++ b/src/locales/es.yml@@ -185,7 +185,7 @@ annotationEditor:colorLabel: ColortextPlaceholder: Escribe algo...targetColor: Color del objetivo- targetShape: Forma del objetivo+ targetBorder: Estilo del bordedone: ListoexportMenu:diff --git a/src/locales/fr.yml b/src/locales/fr.ymlindex 003ea95..d81c763 100644--- a/src/locales/fr.yml+++ b/src/locales/fr.yml@@ -185,7 +185,7 @@ annotationEditor:colorLabel: CouleurtextPlaceholder: "Écrivez quelque chose..."targetColor: Couleur de la cible- targetShape: Forme de la cible+ targetBorder: Style de borduredone: "Terminé"exportMenu:diff --git a/src/locales/pt-BR.yml b/src/locales/pt-BR.ymlindex 649697b..546c7de 100644--- a/src/locales/pt-BR.yml+++ b/src/locales/pt-BR.yml@@ -185,7 +185,7 @@ annotationEditor:colorLabel: CortextPlaceholder: Digite algo...targetColor: Cor do alvo- targetShape: Forma do alvo+ targetBorder: Estilo da bordadone: ProntoexportMenu:diff --git a/src/ui/shared/AnnotationEditor.tsx b/src/ui/shared/AnnotationEditor.tsxindex 0f71abe..20b394c 100644--- a/src/ui/shared/AnnotationEditor.tsx+++ b/src/ui/shared/AnnotationEditor.tsx@@ -1,13 +1,12 @@import {ArrowUpRight,Check,- Circle,Crop,EyeOff,MousePointer2,PenTool,- RectangleHorizontal,Square,+ SquareDashed,Trash2,Type,X,@@ -26,7 +25,7 @@ import {resizeAnnotation,resolveTarget,} from '@/core/screenshot/geometry';-import type { Annotation, ScreenshotEdits, TargetShape } from '@/core/screenshot/types';+import type { Annotation, ScreenshotEdits, TargetBorder } from '@/core/screenshot/types';import { TARGET_COLORS } from '@/core/screenshot/types';type EditorTool = 'select' | 'box' | 'arrow' | 'text' | 'freehand' | 'redact' | 'crop';@@ -113,16 +112,11 @@ function drawShape(ctx: CanvasRenderingContext2D, a: Annotation, alpha: number)break;case 'target':ctx.strokeStyle = a.color;- ctx.lineWidth = 4;- 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 {- ctx.beginPath();- ctx.roundRect(a.x, a.y, a.w, a.h, 10);- ctx.stroke();- }+ ctx.lineWidth = 3.5;+ if (a.border === 'dashed') ctx.setLineDash([8, 5]);+ ctx.beginPath();+ ctx.roundRect(a.x, a.y, a.w, a.h, 12);+ ctx.stroke();break;case 'arrow': {const head = 14;@@ -178,7 +172,7 @@ export default function AnnotationEditor({ screenshot, tool, onDone, onCancel }:if (!t) return existing;return [...existing,- { id: TARGET_ID, type: 'target', x: t.x, y: t.y, w: t.width, h: t.height, color: t.color, shape: t.shape },+ { id: TARGET_ID, type: 'target', x: t.x, y: t.y, w: t.width, h: t.height, color: t.color, border: t.border },];});const [viewport, setViewport] = useState<ScreenshotBounds | undefined>(screenshot.edits?.viewport);@@ -195,7 +189,7 @@ export default function AnnotationEditor({ screenshot, tool, onDone, onCancel }:const selected = annotations.find((a) => a.id === selectedId);const selectedTarget = selected?.type === 'target' ? selected : null;- const updateTarget = (patch: { color?: string; shape?: TargetShape }) => {+ const updateTarget = (patch: { color?: string; border?: TargetBorder }) => {setAnnotations((prev) => prev.map((a) => (a.id === TARGET_ID && a.type === 'target' ? { ...a, ...patch } : a)));};@@ -476,7 +470,7 @@ export default function AnnotationEditor({ screenshot, tool, onDone, onCancel }:y: targetAnnotation.y,width: targetAnnotation.w,height: targetAnnotation.h,- shape: targetAnnotation.shape,+ border: targetAnnotation.border,color: targetAnnotation.color,}: null,@@ -596,11 +590,11 @@ export default function AnnotationEditor({ screenshot, tool, onDone, onCancel }:/><buttontype="button"- title={i18n.t('annotationEditor.targetShape')}- onClick={() => updateTarget({ shape: selectedTarget.shape === 'circle' ? 'rect' : 'circle' })}+ title={i18n.t('annotationEditor.targetBorder')}+ onClick={() => updateTarget({ border: selectedTarget.border === 'dashed' ? 'solid' : 'dashed' })}className="w-6 h-6 flex items-center justify-center rounded-md text-primary-foreground hover:bg-primary-foreground/15">- {selectedTarget.shape === 'circle' ? <Circle size={14} /> : <RectangleHorizontal size={14} />}+ {selectedTarget.border === 'dashed' ? <SquareDashed size={14} /> : <Square size={14} />}</button><buttontype="button"diff --git a/src/ui/shared/ScreenshotView.tsx b/src/ui/shared/ScreenshotView.tsxindex b9dc2b0..0b27f0f 100644--- a/src/ui/shared/ScreenshotView.tsx+++ b/src/ui/shared/ScreenshotView.tsx@@ -57,7 +57,14 @@ function defaultTargetRect(screenshot: Screenshot): ClickTarget {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, shape: 'circle', color: DEFAULT_TARGET_COLOR };+ return {+ x: (width - w) / 2,+ y: (height - h) / 2,+ width: w,+ height: h,+ border: 'dashed',+ color: DEFAULT_TARGET_COLOR,+ };}export default function ScreenshotView({