Add lasso selection and pasted images

Select tool (S): lasso picks ink strokes and images that lie entirely
inside the loop, a tap picks one object. Move, uniform resize, nudge,
delete, recolour, copy/cut/paste/duplicate, each one undo step. Holding
the pen's barrel button lassoes with any tool (Settings > Pen & touch).
Copying also writes a PNG of the selection to the system clipboard.

Images come in by paste, drop, the Insert image button or the page menu.
They are capped at 2400 px, stored as PNG/JPEG by content hash in a new
IndexedDB store, drawn between the markdown and the ink, and written to
the PDF both visibly and as papure/assets + per-page images.json.

Dark pages now invert each layer except images, so images keep their
colours; the inverted ink layer is screen-blended so highlighted text
stays bright.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UcbKnqfprs8hMkTVsYx1dh
This commit is contained in:
agent 2026-09-29 21:05:02 +00:00
parent 894291df7f
commit 84b9d4469f
26 changed files with 1274 additions and 39 deletions

29
spec.md
View file

@ -32,8 +32,8 @@ This is recomputed at export/save time (not creation order), since the trunk can
One canvas = **one `.pdf` file**, dual-layer:
- **Visual layer** (any standard PDF viewer sees this): rendered markdown as real vector text, ink drawn as PDF Ink annotations, original imported PDF content where applicable. Fully readable/printable by anyone, no app required.
- **Source-of-truth layer** (embedded file attachments, invisible in normal viewers): raw markdown source per page, full vector stroke data (points + pressure + tilt — richer than what Ink annotations can hold), and grid metadata (each page's tree position, size, and which PDF import it originated from, for provenance search).
- **Visual layer** (any standard PDF viewer sees this): rendered markdown as real vector text, pasted images, ink drawn as PDF Ink annotations, original imported PDF content where applicable. Fully readable/printable by anyone, no app required.
- **Source-of-truth layer** (embedded file attachments, invisible in normal viewers): raw markdown source per page, full vector stroke data (points + pressure + tilt — richer than what Ink annotations can hold), placed images per page (`papure/pages/<id>.images.json`) with each image's bytes stored once (`papure/assets/<hash>.png|jpg`), and grid metadata (each page's tree position, size, and which PDF import it originated from, for provenance search).
- App reads the attachment layer first to reconstruct the live editable canvas; falls back to parsing visual content only if attachments are missing.
**Libraries**: `pdf-lib` (write/edit/attach), `pdf.js` (render/import).
@ -61,6 +61,7 @@ Canvases (PDF files) live in a **file tree** you define, e.g. `school/english/le
- Live-rendered markdown (background layer) + vector ink (foreground layer), never converted to text.
- Full ink toolset: colors, highlighter, eraser.
- Lasso selection of ink and images; pasted images (§10).
- Search across typed markdown text.
- Pages remember their PDF-import origin, searchable.
- No export needed beyond the PDF itself (for now).
@ -93,10 +94,32 @@ Source: user-provided `palm-rejection-test.html` test harness. The acceptance po
- Undo/redo covers ink, erasing and page-tree changes.
- Strokes are written to the PDF both as Ink annotations and as JSON attachments.
## 10. Open Items
## 10. Selection & Images
**Page layers**, bottom to top: imported PDF → markdown → pasted images → ink. Ink can be written over an image.
**Select tool** (`S`, lasso):
- Drag draws a lasso; an ink stroke is selected only when *all* of its samples are inside it, an image only when all four corners are. A tap selects the single object under it (ink before images). Shift adds to the selection; `Ctrl+A` selects everything on the active page.
- A selection lives on one page. It shows as a dashed box with corner handles and an action bar (copy, cut, duplicate, delete, recolour ink).
- Drag the box to move, a corner to scale uniformly (ink width scales too); arrow keys nudge by 1 pt (Shift: 10 pt). Each move/resize is one undo step; the drag itself is only a preview.
- `Delete`/`Backspace` deletes, `Ctrl+C`/`X`/`V`/`D` copy, cut, paste, duplicate. `Escape`, pressing elsewhere or switching tools clears the selection.
- Holding the pen's barrel button lassoes whatever tool is active (Settings → Pen & touch → "Pen button selects"); its context menu is suppressed.
- Palm rejection: lassoing with a finger counts as drawing; dragging the selection box or its handles counts as navigating, so fingers can move a selection between pen strokes.
- The eraser never erases images; delete them with the Select tool.
**Clipboard**: copying keeps a vector copy in the app and writes a PNG of the selection to the system clipboard (for other apps). Pasting uses the vector copy while it's fresh (until the window loses focus or something else is copied); otherwise an image on the clipboard is pasted. Pastes land at the pointer if it's over a page, else in the middle of the visible part of the active page.
**Images** come in by paste, drag-and-drop, the toolbar's "Insert image" button, or "Paste" in the page menu.
- Normalised on the way in: the long edge is capped at 2400 px; transparent images stay PNG, JPEGs stay JPEG (quality 0.85, EXIF rotation applied), other images use whichever of PNG/JPEG is smaller. A PNG that already fits is kept byte for byte.
- Stored by SHA-256 content hash in IndexedDB (`assets` store), so one image placed many times is stored once — also in the PDF.
- Placed at 96 dpi (1 px = 0.75 pt), shrunk to at most 80 % of the page, and selected so it can be moved/resized straight away.
- Dark mode ("match" page style) inverts each page layer except images, so images keep their true colours. The ink layer is screen-blended so the highlighter still reads like it does in light mode.
## 11. Open Items
- [ ] Conflict copies: sync currently lets the newer version win silently; keep the losing version as a separate file.
- [ ] Tell the user when a new version of the app has been deployed (the service worker updates, but the open tab keeps old code until reload).
- [ ] CI that runs `check`, `test` and `build` on every pull request.
- [ ] Use recorded tilt for rendering.
- [ ] GitLab sync.
- [ ] Selection: drag across pages, rotate; image crop; "paste as new page" for slide screenshots.