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

fitt-canvas

v2.0.1

Published

A reusable canvas image-stacking library for real-time product customization previews.

Downloads

69

Readme

fitt-canvas

A reusable canvas image-stacking library for real-time product customization previews.

React TypeScript HTML5 Canvas

Description

Pass an ordered list of image URLs and this library composites them on an HTML5 Canvas, producing a stacked product preview (e.g. a trouser with different pockets, stitching, and fabric overlays). It handles:

  • Dimension-agnostic – consumer provides width and height; no hardcoded layout constants.
  • Animated zoom & focus – smooth spring-style transitions via requestAnimationFrame when zoom, focusX, or focusY change.
  • HiDPI / Retina rendering – uses devicePixelRatio (and optional renderScale) so images stay sharp on all screens.
  • Image caching – decoded images are cached internally (up to 200 entries) to avoid redundant network requests.
  • Flicker-free drawing – renders to an off-screen buffer, then blits to the visible canvas.
  • Thumbnail exportsaveImageBlobCompressed accepts optional output dimensions for card-friendly preview images.

Installation

npm install fitt-canvas

Usage

Basic

import { Canvas } from "fitt-canvas";

<Canvas
  width={800}
  height={600}
  imageList={[
    "https://example.com/base-layer.png",
    "https://example.com/pocket-layer.png",
    "https://example.com/stitching-layer.png",
  ]}
/>;

With zoom and animated transitions

<Canvas
  width={canvasWidth}
  height={canvasHeight}
  imageList={images}
  zoom={2}
  focusX={0.5}
  focusY={0.25}
  backgroundColor="#f0f4f7"
  transitionDuration={300}
/>

Canvas Props

| Prop | Type | Default | Description | | -------------------- | ------------------ | ----------- | --------------------------------------------------------------------------- | | width | number | required | Width of the canvas container in CSS pixels. | | height | number | required | Height of the canvas container in CSS pixels. | | imageList | string[] | required | Ordered image URLs to stack/composite. | | zoom | number | 1 | Zoom level. 1 = fit image to container, >1 = zoom in. | | focusX | number | 0.5 | Horizontal focus point when zoomed (0 = left, 0.5 = center, 1 = right). | | focusY | number | 0.5 | Vertical focus point when zoomed (0 = top, 0.5 = center, 1 = bottom). | | backgroundColor | string | "#ededed" | Canvas background color. | | renderScale | number | 1 | Extra DPR multiplier for crisper rendering at the cost of memory. | | transitionDuration | number | 300 | Duration in ms for animated zoom/focus transitions. 0 = instant. | | className | string | — | CSS class for the canvas element. | | style | CSSProperties | — | Inline styles for the canvas element. | | onDrawComplete | () => void | — | Callback after all images are drawn. | | onImageError | (urls: string[]) => void | — | Callback with URLs that failed to load. |

Utilities

import {
  saveImage,
  saveImageBlobCompressed,
  clearImageCache,
  getDeviceScreenMode,
  useWindowSize,
} from "fitt-canvas";

saveImageBlobCompressed

Composites all images and returns the result as a Blob.

saveImageBlobCompressed(
  imageList,        // string[] – image URLs
  callback,         // (blob: Blob | null) => void
  format?,          // "image/png" | "image/jpeg" | "image/webp"
  quality?,         // number (0–1, for jpeg/webp)
  outputWidth?,     // number – optional thumbnail width
  outputHeight?,    // number – optional thumbnail height
);

When outputWidth / outputHeight are provided, the canvas is created at that size and images are contain-fitted into it — ideal for generating card preview thumbnails.

saveImage

Same as above but returns a data-URL string instead of a Blob. Also accepts optional outputWidth / outputHeight.

useWindowSize

React hook that returns [width, height] of the viewport, debounced.

getDeviceScreenMode

Returns { isDesktop, isTablet, isMobile } based on a width value.

License

This project is licensed under the MIT License.

© 2023 raju sirigineedi | ravitejasunkara | charanbolisetti