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

maxrects-packer

v3.0.0

Published

A max rectangle 2d bin packer for packing glyphs or images into multiple sprite-sheet/atlas

Readme

icon Max Rects Packer

Node.js CI codecov npm version npm NPM Type Definitions

A max rectangle 2D bin packing algorithm for packing glyphs or images into multiple sprite sheets or atlases. Minimalist, with no runtime dependency.

It differs from most packing libraries by what it optimizes: instead of creating one output image of minimum size, it aims for a small number of images under a maximum size. That avoids the single massive image that is not browser-friendly, and suits WebGL games where the GPU benefits from sprite sheets close to power-of-two sizes.

It is an evolved version of Multi-Bin-Packer that keeps the same interfaces and method names, so migrating usually means changing the import.

Install

npm install maxrects-packer --save

Usage

import { MaxRectsPacker } from "maxrects-packer";

const options = {
    smart: true,          // grow bins to the smallest size that fits
    pot: true,            // round grown bins up to a power of two
    square: false,
    allowRotation: true,
    border: 5
};
const packer = new MaxRectsPacker(1024, 1024, 2, options); // width, height, padding, options

const input = [
    { width: 600, height: 20, name: "tree" },                 // any object with width and height
    { width: 600, height: 20, name: "flower" },
    { width: 2000, height: 2000, name: "oversized background" }, // gets a bin of its own
    { width: 1000, height: 1000, name: "background", color: 0x000000ff },
    { width: 1000, height: 1000, name: "overlay" }
];

packer.addArray(input);        // sorts the input, then packs
packer.next();                 // stop adding to the bins that exist
packer.addArray([{ width: 256, height: 256, name: "late sprite" }]);   // fills bins created from here on

packer.bins.forEach((bin) => console.log(bin.width, bin.height, bin.rects));

const saved = packer.save();   // free space only, for reuse in a later run
const next = new MaxRectsPacker(1024, 1024, 2, options);
next.load(saved);
next.addArray([{ width: 256, height: 256, name: "after the reload" }]);   // only the rects that are new

addArray() writes x, y and rot onto the objects you pass in, so bin.rects holds your objects with their placement added. Packing is a heuristic — it does not promise the fewest possible bins.

CommonJS works too: const { MaxRectsPacker } = require("maxrects-packer");

Documentation

The full guide, the API reference generated from the source and the contributor documentation live at soimy.github.io/maxrects-packer:

  • User guide — options, packing, rotation and tags, repacking, persistence and the troubleshooting page with the sharp edges.
  • API reference — every exported class, interface and enum, with JSDoc.
  • Contributing — development setup, testing, architecture, behaviour contracts and compatibility.

Contributors should read CONTRIBUTING.md; AI agents should read AGENTS.md. Release history is in CHANGELOG.md.

Development

npm ci --include=dev   # --include=dev matters when NODE_ENV=production is set
npm test               # clean build + vitest suite
npm run cover          # coverage
npm run docs:build     # this documentation site

See docs/contributor/development.md for the full script list, the Toolchain (rollup + TypeScript 6/7 side by side, vitest, oxlint/oxfmt) and the worktree workflow.

License

MIT