feat: Sketch & Annotation Canvas — phase 1 (annotate media images) (#2036)#2082
Merged
Conversation
New GET/PUT /api/media/sketches/:key persists freehand annotation strokes (JSON vectors + flattened PNG) as a per-image file sidecar under data/media-sketches/, Zod-validated and image-only. Phase 1 of #2036. Claude-Session: https://claude.ai/code/session_01KSyAbxEjURcLPhugG8MZCw
Pure stroke model/renderer (client/src/lib/sketchCanvas.js), a pointer-event <canvas> overlay component (mouse/pen/touch, draw/erase/undo, color+size), and the deep-linkable /media/annotate/:mediaKey page with save + client-side PNG export. Phase 1 of #2036. Claude-Session: https://claude.ai/code/session_01KSyAbxEjURcLPhugG8MZCw
Adds the /media/annotate route (+ bare index), NAV_COMMANDS entry, MediaCard "Annotate" action wired from Media History and Collection detail, the client API wrappers, and a changelog entry. Phase 1 of #2036. Claude-Session: https://claude.ai/code/session_01KSyAbxEjURcLPhugG8MZCw
…2036) Review fixes: (1) track a single active pointerId so a second finger/palm can't hijack the in-progress stroke on touch; (2) reset strokes/dims/imageError synchronously when the :mediaKey route param changes, since React Router reuses the component instance across param changes (no remount). Claude-Session: https://claude.ai/code/session_01KSyAbxEjURcLPhugG8MZCw
Review fix (codex): a re-save carrying strokes but no PNG left the prior <id>.png on disk while the JSON recorded hasPng:false, so getSketchPng/`/png` kept streaming the stale export. Now unlink the PNG in that branch; regression test covers save-with-PNG then save-without. Claude-Session: https://claude.ai/code/session_01KSyAbxEjURcLPhugG8MZCw
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sketch & Annotation Canvas — Phase 1 (Refs #2036)
Ships the first phase of the Sketch & Annotation Canvas: a lightweight drawing surface to mark up already-generated images.
What shipped (Phase 1)
<canvas>stroke layer over the target image with draw/erase, per-stroke color + brush size, undo, and clear. No new heavy deps — a ~120-line pure stroke model/renderer (client/src/lib/sketchCanvas.js) drives it.pointerdown/move/uphandle mouse, pen, AND touch;touch-action: noneso drawing doesn't scroll. Verified layout/behavior at 360px width./media/annotate/:mediaKey(mediaKey is the URL source of truth), with a stale/unsupported-key fallback and a bare/media/annotatelanding. Registered inNAV_COMMANDS(⌘K + voice: "annotate"/"sketch").GET/PUT /api/media/sketches/:keysaves a per-image sidecar underdata/media-sketches/(JSON strokes in natural-pixel space + flattened PNG; retrievable at/png). Follows thedocs/STORAGE.mdfile-sidecar classification (media-adjacent, non-relational) usingatomicWrite/tryReadFile. Empty strokes remove the sidecar.Out of scope (remain open on #2036)
Umbrella issue stays open (
Refs, notCloses); I'll comment there on what shipped/remains.Tests
server/services/mediaSketches.test.js— save/load round-trip, PNG decode/persist, empty-strokes removal, sanitize/clamp, non-image + invalid-key rejection.server/routes/mediaSketches.test.js— GET/PUT//pngHTTP contract incl. 400 (malformed) and 404 (no export).client/src/lib/sketchCanvas.test.js— stroke model (create/append/undo/clamp) + renderer (polyline vs dot, erase compositing, skip-invalid).portos_testPostgres is provisioned in this environment (unrelated).Test plan
https://claude.ai/code/session_01KSyAbxEjURcLPhugG8MZCw