Skip to content

feat(workbench): add share-as-image PNG card for event loop traces - #29

Merged
hoce1n merged 1 commit into
mainfrom
260810-feat-share-trace-image
Aug 11, 2026
Merged

hoce1n merged 1 commit into
mainfrom
260810-feat-share-trace-image

Conversation

@monkeycode-global

Copy link
Copy Markdown
Contributor

What

Adds a Share as image action to the step-mode controls in the workbench. It exports the current event-loop state (at whatever step the visitor is paused on) as a fixed 1200×630 PNG card — a snapshot of the trace data, not a screenshot.

How it works

  • New src/lib/share-image.ts: a dedicated Canvas 2D renderer that draws the card directly from LoopState (no html2canvas/dom-to-image — the app's oklch CSS palette is unreliable under DOM-rasterization and a screenshot would depend on the viewport/zoom).
  • Layout: JS badge + runtime.js wordmark, event loop trace — step N / total label, three lanes (Call Stack / Microtask Queue / Macrotask Queue) reusing the live UI's hint text, a monospace source excerpt centered on the currently-executing line, and a small runtimejs.vercel.app watermark.
  • Theme-independent: the card uses the dark DevTools palette hardcoded in oklch (mirrors the app's .dark theme), so exports look identical even when the visitor is in light mode.
  • Font: waits on document.fonts.ready and explicitly loads the JetBrains Mono weights (400/500/700) before painting, so exports don't silently fall back to a system font.
  • Truncation: lanes cap at 8 stack frames / 7 queue items with a +N more indicator (planLane), and long text is ellipsized to fit the lane width.
  • Output: sharePng feature-detects, in order — navigator.share with the image file (mobile native sheet) → navigator.clipboard.write via ClipboardItem (desktop paste) → plain download fallback. A button-label success indicator (copied! / shared! / saved!) and a share_image analytics event follow.
  • Button lives in the step-mode controls, guarded by the same canStep rule as the other trace-dependent controls.

Verification (headless Chromium, dev server)

  • Clipboard path: button → copied! → clipboard PNG is 1200×630, corner pixel (21,22,24) (dark bg), JS badge (243,223,35), non-blank (variance 493).
  • Light-mode toggle still exports a dark card (corner (21,22,24)).
  • Download fallback (clipboard/share removed): valid PNG signature, 1200×630, runtimejs-trace-step-60.png.
  • Fonts: document.fonts.check('400/700 16px "JetBrains Mono"') both true.
  • Rich synthetic state (12 frames, 10 microtasks, 9 macrotasks): lane titles render in the correct lane colors, microtask/macrotask chips render, +N more frames present, focused code line has the JS-yellow accent bar, and the gap between lane panels and the code panel is clean (no vertical clipping).

Checks

  • npm run typecheck — clean
  • npm run lint — 0 errors (8 pre-existing react-refresh warnings)
  • npm test — 57 pass / 0 fail (12 new: planLane / snippetAround / formatTraceLabel)
  • npm run build — succeeds (client, SSR, prerender)
  • Prettier — clean on new files

Scope

Client-side only — no backend, no image hosting/URL shortening. The site-wide og-image.png and social meta tags are untouched.

Adds a 'Share as image' action to the step-mode controls that renders the
current trace state (at whatever step the visitor is on) as a fixed
1200x630 PNG card via a dedicated Canvas 2D renderer — not a DOM
screenshot, so it is independent of the viewport and the visitor's theme.

- src/lib/share-image.ts: draws the card straight from LoopState with the
  app's dark DevTools palette hardcoded (oklch), so exports look identical
  regardless of the local light/dark preference. Header wordmark + step
  label, three lanes (Call Stack / Microtask / Macrotask) with the live
  UI's hint text, a source excerpt centered on the executing line, and a
  runtimejs.vercel.app watermark. Waits on document.fonts.ready + explicit
  JetBrains Mono loads before painting. Truncates long lanes with '+N
  more' (planLane) and ellipsizes long text. sharePng offers, in order:
  native share sheet → clipboard copy → download fallback, each
  feature-detected.
- Workbench.tsx: 'image' button in the step-mode controls (guarded by the
  same canStep rule as the other trace controls) with a copied!/shared!/
  saved! success indicator and a share_image analytics event.
- tests/share-image.test.ts: unit tests for planLane / snippetAround /
  formatTraceLabel.

Verified in headless Chromium: clipboard path yields a 1200x630 dark card
with the JS-yellow badge and colored lane titles; light-mode sessions
still export dark cards; download fallback produces a valid PNG; fonts
load as JetBrains Mono.
Co-authored-by: monkeycode-ai <monkeycode-ai@chaitin.com>
@vercel

vercel Bot commented Aug 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
runtimejs Ready Ready Preview Aug 11, 2026 6:01pm

@hoce1n
hoce1n merged commit 16c062a into main Aug 11, 2026
3 checks passed
@hoce1n
hoce1n deleted the 260810-feat-share-trace-image branch August 11, 2026 18:02

This branch was successfully deployed

1 active deployment
Preview — bcf7c86b Deployed Aug 11, 2026 by vercel[bot]
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.

2 participants