🎬 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): apply shape properties to the current selection
Luis Ortiz3d7b19e62145
diff --git a/src/core/screenshot/render.ts b/src/core/screenshot/render.tsindex 492f42a..e77f5d4 100644--- a/src/core/screenshot/render.ts+++ b/src/core/screenshot/render.ts@@ -1,7 +1,7 @@import type { Screenshot } from '@/core/guides/types';import { resolveTarget, resolveViewport } from './geometry';import type { Annotation, ArrowEnd } from './types';-import { LINE_WIDTHS } from './types';+import { FONT_FAMILIES, FONT_SIZES, LINE_HEIGHTS, LINE_WIDTHS } from './types';const TARGET_STROKE = 3.5;const TARGET_RADIUS = 12;@@ -87,18 +87,20 @@ function drawAnnotation(ctx: OffscreenCanvasRenderingContext2D, a: Annotation, octx.save();switch (a.type) {case 'box':- ctx.lineWidth = LINE_WIDTHS[a.lineWidth ?? 'small'];+ ctx.lineWidth = LINE_WIDTHS[a.lineWidth ?? 'ms'];if (a.fill && a.fill !== 'transparent') {ctx.fillStyle = a.fill;drawRoundedRect(ctx, a.x, a.y, a.w, a.h, a.radius ?? 0);ctx.fill();}- ctx.strokeStyle = a.color;- drawRoundedRect(ctx, a.x, a.y, a.w, a.h, a.radius ?? 0);- ctx.stroke();+ if (ctx.lineWidth > 0) {+ ctx.strokeStyle = a.color;+ drawRoundedRect(ctx, a.x, a.y, a.w, a.h, a.radius ?? 0);+ ctx.stroke();+ }break;case 'ellipse':- ctx.lineWidth = LINE_WIDTHS[a.lineWidth ?? 'small'];+ ctx.lineWidth = LINE_WIDTHS[a.lineWidth ?? 'ms'];ctx.beginPath();ctx.ellipse(a.x + a.w / 2, a.y + a.h / 2, Math.abs(a.w / 2), Math.abs(a.h / 2), 0, 0, Math.PI * 2);if (a.fill && a.fill !== 'transparent') {@@ -116,7 +118,7 @@ function drawAnnotation(ctx: OffscreenCanvasRenderingContext2D, a: Annotation, octx.stroke();break;case 'arrow': {- const w = LINE_WIDTHS[a.lineWidth ?? 'small'];+ const w = LINE_WIDTHS[a.lineWidth ?? 'ms'];ctx.strokeStyle = a.color;ctx.fillStyle = a.color;ctx.lineWidth = w;@@ -128,14 +130,22 @@ function drawAnnotation(ctx: OffscreenCanvasRenderingContext2D, a: Annotation, odrawArrowEnd(ctx, a.x1, a.y1, a.x2, a.y2, w, a.end ?? 'arrow-solid');break;}- case 'text':+ case 'text': {+ const px = a.fontSize ? FONT_SIZES[a.fontSize] : a.size;+ const family = FONT_FAMILIES[a.fontFamily ?? 'sans-serif'];+ const style = a.fontStyle === 'italic' ? 'italic ' : '';+ const weight = a.fontStyle === 'bold' ? 700 : 500;ctx.fillStyle = a.color;- ctx.font = `${a.weight ?? 600} ${a.size}px Poppins, sans-serif`;- ctx.fillText(a.text, a.x, a.y);+ ctx.font = `${style}${weight} ${px}px ${family}`;+ const lh = px * LINE_HEIGHTS[a.lineHeight ?? 'md'];+ a.text.split('\n').forEach((line, i) => {+ ctx.fillText(line, a.x, a.y + i * lh);+ });break;+ }case 'freehand':ctx.strokeStyle = a.color;- ctx.lineWidth = LINE_WIDTHS[a.lineWidth ?? 'medium'];+ ctx.lineWidth = LINE_WIDTHS[a.lineWidth ?? 'md'];ctx.lineJoin = 'round';ctx.lineCap = 'round';ctx.beginPath();diff --git a/src/core/screenshot/types.ts b/src/core/screenshot/types.tsindex 88aa598..af20699 100644--- a/src/core/screenshot/types.ts+++ b/src/core/screenshot/types.ts@@ -20,9 +20,39 @@ export interface ClickTarget extends ScreenshotBounds {color: string;}-export type LineWidth = 'small' | 'medium' | 'large';+export type LineWidth = 'none' | 'xs' | 'sm' | 'ms' | 'md' | 'ml' | 'lg' | 'xl';-export const LINE_WIDTHS: Record<LineWidth, number> = { small: 3, medium: 6, large: 10 };+export const LINE_WIDTHS: Record<LineWidth, number> = {+ none: 0,+ xs: 1,+ sm: 2,+ ms: 3,+ md: 5,+ ml: 7,+ lg: 10,+ xl: 14,+};++export const LINE_WIDTH_ORDER: LineWidth[] = ['none', 'xs', 'sm', 'ms', 'md', 'ml', 'lg', 'xl'];++export type FontFamily = 'sans-serif' | 'serif' | 'monospace';+export type FontStyleName = 'normal' | 'bold' | 'italic';+export type FontSizeName = 'xs' | 'sm' | 'md' | 'lg' | 'xl';+export type LineHeightName = 'sm' | 'md' | 'lg';++export const FONT_FAMILIES: Record<FontFamily, string> = {+ 'sans-serif': 'Poppins, sans-serif',+ serif: 'Georgia, serif',+ monospace: 'ui-monospace, monospace',+};++export const FONT_SIZES: Record<FontSizeName, number> = { xs: 16, sm: 22, md: 30, lg: 42, xl: 60 };+export const LINE_HEIGHTS: Record<LineHeightName, number> = { sm: 1.1, md: 1.4, lg: 1.9 };++export const FONT_FAMILY_ORDER: FontFamily[] = ['sans-serif', 'serif', 'monospace'];+export const FONT_STYLE_ORDER: FontStyleName[] = ['normal', 'bold', 'italic'];+export const FONT_SIZE_ORDER: FontSizeName[] = ['xs', 'sm', 'md', 'lg', 'xl'];+export const LINE_HEIGHT_ORDER: LineHeightName[] = ['sm', 'md', 'lg'];export type ArrowEnd = 'none' | 'bar' | 'arrow' | 'arrow-solid' | 'circle' | 'circle-solid' | 'square' | 'square-solid';@@ -92,7 +122,19 @@ export type Annotation =lineWidth?: LineWidth;end?: ArrowEnd;}- | { id: string; type: 'text'; x: number; y: number; text: string; color: string; size: number; weight?: number }+ | {+ id: string;+ type: 'text';+ x: number;+ y: number;+ text: string;+ color: string;+ size: number;+ fontSize?: FontSizeName;+ fontFamily?: FontFamily;+ fontStyle?: FontStyleName;+ lineHeight?: LineHeightName;+ }| { id: string; type: 'freehand'; points: number[]; color: string; lineWidth?: LineWidth }| { 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; border: TargetBorder };diff --git a/src/locales/en.yml b/src/locales/en.ymlindex a72bf09..afcd6d3 100644--- a/src/locales/en.yml+++ b/src/locales/en.yml@@ -201,10 +201,30 @@ annotationEditor:fillColor: "fill color"noFill: "none"lineWidth: "line width"- width_small: "Small"- width_medium: "Medium"- width_large: "Large"cornerRadius: "corner radius"+ font: "font"+ fontStyle: "font style"+ lineHeight: "line height"+ style_normal: "Normal"+ style_bold: "Bold"+ style_italic: "Italic"+ size_xs: "Extra small"+ size_sm: "Small"+ size_md: "Medium"+ size_lg: "Large"+ size_xl: "Extra large"+ height_sm: "Small"+ height_md: "Medium"+ height_lg: "Large"+ width_none: "No outline"+ width_xs: "Extra small"+ width_sm: "Small"+ width_ms: "Medium small"+ width_md: "Medium"+ width_ml: "Medium large"+ width_lg: "Large"+ width_xl: "Extra large"+ zoom: "Zoom"cropHint: "Drag to crop, or drag a corner to resize"resetCrop: "Reset crop"arrowEnd: "end"diff --git a/src/locales/es.yml b/src/locales/es.ymlindex 3eefc94..e4866ca 100644--- a/src/locales/es.yml+++ b/src/locales/es.yml@@ -201,10 +201,30 @@ annotationEditor:fillColor: "relleno"noFill: "ninguno"lineWidth: "grosor"- width_small: "Fino"- width_medium: "Medio"- width_large: "Grueso"cornerRadius: "radio"+ font: "fuente"+ fontStyle: "estilo"+ lineHeight: "interlineado"+ style_normal: "Normal"+ style_bold: "Negrita"+ style_italic: "Cursiva"+ size_xs: "Muy pequeño"+ size_sm: "Pequeño"+ size_md: "Mediano"+ size_lg: "Grande"+ size_xl: "Muy grande"+ height_sm: "Pequeño"+ height_md: "Mediano"+ height_lg: "Grande"+ width_none: "Sin contorno"+ width_xs: "Muy fino"+ width_sm: "Fino"+ width_ms: "Medio fino"+ width_md: "Medio"+ width_ml: "Medio grueso"+ width_lg: "Grueso"+ width_xl: "Muy grueso"+ zoom: "Zoom"cropHint: "Arrastra para recortar o arrastra una esquina para redimensionar"resetCrop: "Restablecer recorte"arrowEnd: "punta"diff --git a/src/locales/fr.yml b/src/locales/fr.ymlindex cf5e228..9494845 100644--- a/src/locales/fr.yml+++ b/src/locales/fr.yml@@ -201,10 +201,30 @@ annotationEditor:fillColor: "remplissage"noFill: "aucun"lineWidth: "épaisseur"- width_small: "Fin"- width_medium: "Moyen"- width_large: "Épais"cornerRadius: "rayon"+ font: "police"+ fontStyle: "style"+ lineHeight: "interligne"+ style_normal: "Normal"+ style_bold: "Gras"+ style_italic: "Italique"+ size_xs: "Très petit"+ size_sm: "Petit"+ size_md: "Moyen"+ size_lg: "Grand"+ size_xl: "Très grand"+ height_sm: "Petit"+ height_md: "Moyen"+ height_lg: "Grand"+ width_none: "Sans contour"+ width_xs: "Très fin"+ width_sm: "Fin"+ width_ms: "Moyen fin"+ width_md: "Moyen"+ width_ml: "Moyen épais"+ width_lg: "Épais"+ width_xl: "Très épais"+ zoom: "Zoom"cropHint: "Faites glisser pour recadrer, ou un coin pour redimensionner"resetCrop: "Réinitialiser"arrowEnd: "extrémité"diff --git a/src/locales/pt-BR.yml b/src/locales/pt-BR.ymlindex 0035d3b..3e31c34 100644--- a/src/locales/pt-BR.yml+++ b/src/locales/pt-BR.yml@@ -201,10 +201,30 @@ annotationEditor:fillColor: "preenchimento"noFill: "nenhum"lineWidth: "espessura"- width_small: "Fina"- width_medium: "Média"- width_large: "Grossa"cornerRadius: "raio"+ font: "fonte"+ fontStyle: "estilo"+ lineHeight: "entrelinha"+ style_normal: "Normal"+ style_bold: "Negrito"+ style_italic: "Itálico"+ size_xs: "Muito pequeno"+ size_sm: "Pequeno"+ size_md: "Médio"+ size_lg: "Grande"+ size_xl: "Muito grande"+ height_sm: "Pequeno"+ height_md: "Médio"+ height_lg: "Grande"+ width_none: "Sem contorno"+ width_xs: "Muito fina"+ width_sm: "Fina"+ width_ms: "Média fina"+ width_md: "Média"+ width_ml: "Média grossa"+ width_lg: "Grossa"+ width_xl: "Muito grossa"+ zoom: "Zoom"cropHint: "Arraste para recortar ou arraste um canto para redimensionar"resetCrop: "Redefinir recorte"arrowEnd: "ponta"diff --git a/src/ui/shared/AnnotationEditor.tsx b/src/ui/shared/AnnotationEditor.tsxindex f401126..ee77b66 100644--- a/src/ui/shared/AnnotationEditor.tsx+++ b/src/ui/shared/AnnotationEditor.tsx@@ -31,8 +31,28 @@ import {resizeAnnotation,resolveTarget,} from '@/core/screenshot/geometry';-import type { Annotation, ArrowEnd, LineWidth, ScreenshotEdits, TargetBorder } from '@/core/screenshot/types';-import { ARROW_ENDS, SHAPE_COLORS, TARGET_COLORS } from '@/core/screenshot/types';+import type {+ Annotation,+ ArrowEnd,+ FontFamily,+ FontSizeName,+ FontStyleName,+ LineHeightName,+ LineWidth,+ ScreenshotEdits,+ TargetBorder,+} from '@/core/screenshot/types';+import {+ ARROW_ENDS,+ FONT_FAMILY_ORDER,+ FONT_SIZE_ORDER,+ FONT_SIZES,+ FONT_STYLE_ORDER,+ LINE_HEIGHT_ORDER,+ LINE_WIDTH_ORDER,+ SHAPE_COLORS,+ TARGET_COLORS,+} from '@/core/screenshot/types';type EditorMode = 'crop' | 'annotate' | 'redact';type EditorTool = 'select' | 'eraser' | 'box' | 'ellipse' | 'arrow' | 'text' | 'freehand';@@ -86,8 +106,6 @@ const TOOLS: { id: EditorTool; icon: ComponentType<{ size?: number }>; labelKey:{ id: 'freehand', icon: PenTool, labelKey: 'annotationEditor.toolFreehand' },];-const LINE_WIDTH_OPTIONS: LineWidth[] = ['small', 'medium', 'large'];-function initialModeFor(tool: 'annotate' | 'redact' | 'crop' | 'target'): EditorMode {if (tool === 'redact') return 'redact';if (tool === 'crop') return 'crop';@@ -219,10 +237,13 @@ export default function AnnotationEditor({ screenshot, tool, onDone, onCancel }:const [targetPicker, setTargetPicker] = useState(false);const [mode, setMode] = useState<EditorMode>(initialModeFor(tool));const [fill, setFill] = useState('transparent');- const [lineWidth, setLineWidth] = useState<LineWidth>('small');+ const [lineWidth, setLineWidth] = useState<LineWidth>('ms');const [radius, setRadius] = useState(0);const [arrowEnd, setArrowEnd] = useState<ArrowEnd>('arrow-solid');- const [textSize, setTextSize] = useState(DEFAULT_TEXT_SIZE);+ const [fontFamily, setFontFamily] = useState<FontFamily>('sans-serif');+ const [fontStyle, setFontStyle] = useState<FontStyleName>('normal');+ const [fontSize, setFontSize] = useState<FontSizeName>('md');+ const [lineHeight, setLineHeight] = useState<LineHeightName>('md');const [past, setPast] = useState<Annotation[][]>([]);const [future, setFuture] = useState<Annotation[][]>([]);@@ -251,6 +272,12 @@ export default function AnnotationEditor({ screenshot, tool, onDone, onCancel }:const selected = annotations.find((a) => a.id === selectedId);const selectedTarget = selected?.type === 'target' ? selected : null;+ const patchSelected = (patch: Record<string, unknown>) => {+ if (!selectedId || selectedId === TARGET_ID) return;+ pushHistory();+ setAnnotations((prev) => prev.map((a) => (a.id === selectedId ? ({ ...a, ...patch } as Annotation) : a)));+ };+const updateTarget = (patch: { color?: string; border?: TargetBorder }) => {setAnnotations((prev) => prev.map((a) => (a.id === TARGET_ID && a.type === 'target' ? { ...a, ...patch } : a)));};@@ -433,7 +460,7 @@ export default function AnnotationEditor({ screenshot, tool, onDone, onCancel }:const rect = canvasRef.current?.getBoundingClientRect();setTextEditor({x: p.x,- y: p.y + textSize,+ y: p.y + FONT_SIZES[fontSize],left: rect ? e.clientX - rect.left : 0,top: rect ? e.clientY - rect.top : 0,});@@ -574,6 +601,10 @@ export default function AnnotationEditor({ screenshot, tool, onDone, onCancel }:setCropDraft(null);};+ const setProp = (key: string, value: unknown) => {+ patchSelected({ [key]: value });+ };+const handleColorSelect = (c: string) => {setColor(c);setAnnotations((prev) => prev.map((a) => (a.id === selectedId && a.type !== 'redact' ? { ...a, color: c } : a)));@@ -590,7 +621,11 @@ export default function AnnotationEditor({ screenshot, tool, onDone, onCancel }:y: textEditor.y,text: textValue.trim(),color,- size: textSize,+ size: FONT_SIZES[fontSize],+ fontSize,+ fontFamily,+ fontStyle,+ lineHeight,},]);}@@ -793,7 +828,10 @@ export default function AnnotationEditor({ screenshot, tool, onDone, onCancel }:{i18n.t('annotationEditor.fillColor')}<selectvalue={fill}- onChange={(e) => setFill(e.target.value)}+ onChange={(e) => {+ setFill(e.target.value);+ setProp('fill', e.target.value);+ }}className="h-7 rounded-lg border border-border bg-card px-1.5 text-[11px] text-foreground outline-none"style={{ color: fill === 'transparent' ? undefined : fill }}>@@ -810,10 +848,13 @@ export default function AnnotationEditor({ screenshot, tool, onDone, onCancel }:{i18n.t('annotationEditor.lineWidth')}<selectvalue={lineWidth}- onChange={(e) => setLineWidth(e.target.value as LineWidth)}+ onChange={(e) => {+ setLineWidth(e.target.value as LineWidth);+ setProp('lineWidth', e.target.value);+ }}className="h-7 rounded-lg border border-border bg-card px-1.5 text-[11px] text-foreground outline-none capitalize">- {LINE_WIDTH_OPTIONS.map((w) => (+ {LINE_WIDTH_ORDER.map((w) => (<option key={w} value={w}>{i18n.t(`annotationEditor.width_${w}`)}</option>@@ -829,7 +870,10 @@ export default function AnnotationEditor({ screenshot, tool, onDone, onCancel }:min={0}max={60}value={radius}- onChange={(e) => setRadius(Number(e.target.value))}+ onChange={(e) => {+ setRadius(Number(e.target.value));+ setProp('radius', Number(e.target.value));+ }}className="w-24 h-7 accent-accent"/></label>@@ -839,7 +883,10 @@ export default function AnnotationEditor({ screenshot, tool, onDone, onCancel }:{i18n.t('annotationEditor.arrowEnd')}<selectvalue={arrowEnd}- onChange={(e) => setArrowEnd(e.target.value as ArrowEnd)}+ onChange={(e) => {+ setArrowEnd(e.target.value as ArrowEnd);+ setProp('end', e.target.value);+ }}className="h-7 rounded-lg border border-border bg-card px-1.5 text-[11px] text-foreground outline-none">{ARROW_ENDS.map((end) => (@@ -851,17 +898,76 @@ export default function AnnotationEditor({ screenshot, tool, onDone, onCancel }:</label>)}{activeTool === 'text' && (- <label className="flex flex-col items-center gap-1 text-[10px] font-semibold text-muted-foreground">- {i18n.t('annotationEditor.fontSize')}- <input- type="range"- min={12}- max={96}- value={textSize}- onChange={(e) => setTextSize(Number(e.target.value))}- className="w-24 h-7 accent-accent"- />- </label>+ <>+ <label className="flex flex-col items-center gap-1 text-[10px] font-semibold text-muted-foreground">+ {i18n.t('annotationEditor.font')}+ <select+ value={fontFamily}+ onChange={(e) => {+ setFontFamily(e.target.value as FontFamily);+ setProp('fontFamily', e.target.value);+ }}+ className="h-7 rounded-lg border border-border bg-card px-1.5 text-[11px] text-foreground outline-none"+ >+ {FONT_FAMILY_ORDER.map((f) => (+ <option key={f} value={f}>+ {f}+ </option>+ ))}+ </select>+ </label>+ <label className="flex flex-col items-center gap-1 text-[10px] font-semibold text-muted-foreground">+ {i18n.t('annotationEditor.fontStyle')}+ <select+ value={fontStyle}+ onChange={(e) => {+ setFontStyle(e.target.value as FontStyleName);+ setProp('fontStyle', e.target.value);+ }}+ className="h-7 rounded-lg border border-border bg-card px-1.5 text-[11px] text-foreground outline-none"+ >+ {FONT_STYLE_ORDER.map((f) => (+ <option key={f} value={f}>+ {i18n.t(`annotationEditor.style_${f}`)}+ </option>+ ))}+ </select>+ </label>+ <label className="flex flex-col items-center gap-1 text-[10px] font-semibold text-muted-foreground">+ {i18n.t('annotationEditor.fontSize')}+ <select+ value={fontSize}+ onChange={(e) => {+ setFontSize(e.target.value as FontSizeName);+ setProp('fontSize', e.target.value);+ }}+ className="h-7 rounded-lg border border-border bg-card px-1.5 text-[11px] text-foreground outline-none"+ >+ {FONT_SIZE_ORDER.map((f) => (+ <option key={f} value={f}>+ {i18n.t(`annotationEditor.size_${f}`)}+ </option>+ ))}+ </select>+ </label>+ <label className="flex flex-col items-center gap-1 text-[10px] font-semibold text-muted-foreground">+ {i18n.t('annotationEditor.lineHeight')}+ <select+ value={lineHeight}+ onChange={(e) => {+ setLineHeight(e.target.value as LineHeightName);+ setProp('lineHeight', e.target.value);+ }}+ className="h-7 rounded-lg border border-border bg-card px-1.5 text-[11px] text-foreground outline-none"+ >+ {LINE_HEIGHT_ORDER.map((f) => (+ <option key={f} value={f}>+ {i18n.t(`annotationEditor.height_${f}`)}+ </option>+ ))}+ </select>+ </label>+ </>)}</div>)}