Region-snap: Drag-to-Select Region Screenshots, Now an npm Package for Vue and React
Document preview, PDF viewing, and OCR workflows need region screenshots that stay aligned under scroll and zoom. Region-snap packages that interaction with three capture strategies and a replaceable renderer, so teams can drop it into Vue or React apps without writing the coordinate and scaling glue themselves.
Region-snap packages the annoying problem of "select a region, turn it into an image" into a single library. The selection interaction handles scroll, zoom via CSS transforms, touch long-press, and toolbar positioning, and outputs PNG, JPEG, or WebP. The core package is framework-agnostic, with Vue 3.3+ and React 17+ wrappers that expose getImage(), getBlob(), and getFile() for preview, upload, or OCR submission.
The library doesn't rely on one capture method. When the region sits entirely inside a qualifying image or PDF-rendered canvas, it crops at source resolution using drawImage(), saving a DOM re-render. For ordinary DOM content it falls back to a lazily loaded html2canvas renderer, which can be swapped for html2canvas-pro or a custom CaptureRenderer. Cross-origin iframes like Office Online are handled by createScreenCapture(), which uses browser screen sharing to grab the visible tab and crop the selection.
A separate scroll capture mode stitches overlapping frames while the user scrolls, producing long images up to 16384 pixels tall. The project is dual-licensed under AGPL-3.0 with a commercial option, and the docs call out that CORS misconfiguration can't be fixed by the library alone.
The three-path capture design acknowledges that no single screenshot technique works for all content: direct canvas cropping for images, html2canvas for DOM, and screen capture for iframes is a pragmatic trade-off between fidelity, performance, and cross-origin constraints.
Scroll capture stitching depends on frame overlap, so fast scrolling, large blank areas, repeating content, and fixed toolbars can break the match, making it a best-effort tool rather than a guarantee for long documents.
The AGPL-3.0 dual-license pattern is common in open-source UI libraries; it gives hobbyists free use but forces companies integrating it into closed-source products to either open-source their code or buy a commercial license.