npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rasamjs/viewport

v0.3.1

Published

Pan and zoom for rasam SVG drawings.

Readme

@rasamjs/viewport

The optional editor adapter owns minimap lifecycle and follows document/viewport replacement through structural capabilities.

Pan and zoom for rasam SVG drawings. Peer dependency: @rasamjs/core version ^0.2.0. @rasamjs/[email protected] is published. The programmatic camera, wheel pan/zoom, keyboard shortcuts, Space/middle-button pan and two-finger pinch are available. Unreleased editor additions provide primary-button hand mode, native-input suspension and immutable camera snapshots with direct restoration.

import { SVG } from '@rasamjs/core';
import { Viewport } from '@rasamjs/viewport';
import { exportSvg } from '@rasamjs/core/interchange';

const drawing = SVG(document.querySelector<HTMLElement>('#drawing')!, { width: 600, height: 400 });
const viewport = new Viewport(drawing);
const camera = viewport.camera;
viewport.hand = true; // Primary-button drag pans with a grab cursor.
viewport.suspended = true; // Pause camera input while another tool owns a gesture.
viewport.setCamera(camera); // Programmatic methods still work while suspended.
viewport.suspended = false;
viewport.hand = false;
viewport.zoomTo(2, { x: 100, y: 80 });
viewport.panBy(30, 20);
viewport.fit();
// Export the original document viewBox, then restore the camera immediately.
const svg = viewport.withHome(() => exportSvg(drawing));
// Dispose explicitly, or destroy the drawing to dispose automatically.
viewport.destroy();

The camera is the root <svg>'s viewBox. Camera changes are written as temporary changes, so @rasamjs/history never records them as undo steps.

Give the drawing host overflow-anchor: none to keep page scroll anchoring from following shapes when the camera moves. Pass editor overlays in overlays so they redraw once per animation frame. Do not edit the root viewBox directly while a viewport is active. Use a synchronous withHome callback for export; a plain exportSvg(drawing) saves the current camera.

Wheel pans; Shift+wheel pans across; Ctrl/Cmd+wheel zooms at the pointer. Set wheel: 'zoom' to zoom plain wheels as well. Ctrl/Cmd+wheel and trackpad pinch continue to zoom in either mode. Ctrl/Cmd+= and Ctrl/Cmd+- zoom about the view center; Ctrl/Cmd+0 shows actual size. Shift+1 fits the drawing and Shift+2 fits options.selection.nodes. Keyboard shortcuts accept body or drawing-host focus, leave editable fields and outside focus alone, and can be disabled with keyboard: false.

Hold Space and drag, or drag with the middle mouse button, to pan without moving or selecting shapes. Two touch pointers take over an existing edit, restore that edit's starting state, then zoom and pan around their midpoint. The host disables native touch gestures while pinch is enabled. Use spacePan: false, middlePan: false or pinch: false to opt out. Destroy restores the host cursor and touch-action styles. Hand mode also supports a primary touch. Suspension releases camera captures and leaves pointer presses available for editing; resume restores hand mode's cursor.

See API.md and RELEASING.md.

Use with an editor

The viewport only needs core at runtime. Connect the optional editing packages through their public APIs:

import { History } from '@rasamjs/history';
import { Selection, connectTransformer } from '@rasamjs/selection';
import { Transformer } from '@rasamjs/transformer';

const history = new History(drawing);
const transformer = new Transformer(drawing);
const selection = new Selection(drawing);
const disconnect = connectTransformer(selection, transformer);
const viewport = new Viewport(drawing, { selection, overlays: [transformer] });

selection.on('change', () => history.breakMerge());
viewport.on('change', ({ zoom }) => {
  zoomLabel.textContent = `${Math.round(zoom * 100)}%`;
});

// On teardown, disconnect the bridge and restore host styles before destroying editors.
disconnect();
viewport.destroy();
selection.destroy();
transformer.destroy();
history.destroy();

Selection refreshes itself after camera changes; list the transformer in overlays to refresh its controls. Make the drawing host focusable (tabindex="0") and return focus to it after toolbar actions so keyboard shortcuts remain available. Existing roots must be mounted, outermost SVGs with uniform preserveAspectRatio scaling.

Run bun run --filter @rasamjs/viewport dev from the workspace, then open http://127.0.0.1:4179/examples/index.html. The editor example combines zoom controls, selection, shared handles, undo/redo and home-view SVG download. Build the workspace first with bun run build for editor dependencies.

Run bun run --filter @rasamjs/viewport bench:wheel for the 5,000-shape wheel benchmark. It writes wheel-benchmark.json, including frame intervals and input-to-change latency for Chromium, Firefox and WebKit. Synthetic input excludes OS routing; rAF intervals do not isolate paint time. Results are observations rather than a hardware speed requirement. Correctness checks cover coalescing, focus, history and an unchanged home-view export. Use the optional minimap for a limited-rate drawing preview with a draggable camera rectangle:

import { Minimap } from '@rasamjs/viewport/minimap';
const minimap = new Minimap(drawing, minimapHost, { viewport });