Skip to content

Add canvas record/PNG capture and restyle the UI#5

Merged
vecnode merged 1 commit into
mainfrom
canvas-capture-and-restyle
Jun 28, 2026
Merged

Add canvas record/PNG capture and restyle the UI#5
vecnode merged 1 commit into
mainfrom
canvas-capture-and-restyle

Conversation

@vecnode

@vecnode vecnode commented Jun 28, 2026

Copy link
Copy Markdown
Owner

What & why

Two things: a high-performance canvas capture feature, and an Anthropic-style visual refresh of the editor chrome.

Canvas record + PNG capture

The sketch runs in a sandboxed, opaque-origin iframe, so the parent page cannot reach its canvas. Capture therefore happens inside the iframe using the browser-native, GPU-backed pipeline, and only the finished bytes cross the boundary via postMessage — no per-frame pixel copying on the main thread.

  • src/main.cpp — new POST /api/save-media?ext=… endpoint. Writes the binary body to outputs/ with a server-generated, millisecond-stamped filename (…_capture.png / …_recording.webm). The ext is sanitised to lowercase alphanumerics and checked against an allow-list (png/jpg/jpeg/webm/mp4), so the client never controls a path. Global payload cap raised to 256 MiB (recordings); the script handler keeps its own 5 MiB limit.
  • public/index.html — the right collapsible side panel gains Record (toggle) and Capture PNG buttons.
  • public/script.js — an injected captureController (canvas.captureStream + MediaRecorder for WebM, canvas.toBlob for PNG), parent-side record/capture logic, and a /api/save-media uploader. Both outputs land in outputs/. The default sketch now draws a sample circle so the preview shows content immediately.

UI restyle (no structural/DOM changes)

Warm ivory surfaces, clay accent, refined typography, recoloured terminal row, focus rings, and panel-button styles. The sketch render keeps square corners (no border-radius) so the canvas — and any recording/capture of it — is never clipped; every other surface stays rounded.

Reviewer notes

  • Verified by building the Debug target (compiles, links, assets re-embedded), node --check on script.js, and a launch smoke test (binds 127.0.0.1, starts cleanly).
  • Known limitations (documented in AGENTS.md): WebKitGTK MediaRecorder support varies by version (the controller feature-detects and reports a clear error); PNG snapshots of WEBGL sketches may be blank because p5 doesn't set preserveDrawingBuffer (video of WEBGL is fine).
  • The full click-through (Run → Record/Capture) wasn't automated headlessly.

🤖 Generated with Claude Code

Capture feature:
- New POST /api/save-media endpoint writes PNG/WebM blobs to outputs/
  with a server-generated, millisecond-stamped filename; the ext query
  param is sanitised and allow-listed (no client-controlled path).
  Global payload cap raised to 256 MiB for recordings; per-handler
  limits unchanged.
- Right side panel gains Record (toggle) and Capture PNG buttons.
- Capture happens inside the sandboxed sketch iframe via the GPU-backed
  canvas.captureStream + MediaRecorder (video) and canvas.toBlob (PNG);
  bytes are transferred to the parent over postMessage and uploaded.
  Keeps the opaque-origin sandbox intact.
- Default sketch now draws a sample circle for an immediate preview.

UI restyle (no structural/DOM changes):
- Warm ivory surfaces, clay accent, refined typography, terminal
  recolour, focus rings, panel-button styles.
- Sketch render keeps square corners (no radius) so the canvas and its
  recording are never clipped; other surfaces remain rounded.

Docs: AGENTS.md updated with the new route, capture flow, and the
WebKitGTK / WEBGL-snapshot caveats.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vecnode vecnode merged commit 84d220d into main Jun 28, 2026
@vecnode vecnode deleted the canvas-capture-and-restyle branch June 28, 2026 01:05
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