3A tiny JavaScript library for packing 2D rectangles into a near-square container,
4which is useful for generating CSS sprites and WebGL textures. Similar to [shelf-pack](https://github.com/mapbox/shelf-pack),
5but static (you can't add items once a layout is generated), and aims for maximal space utilization.
7A variation of algorithms used in
8[rectpack2D](https://github.com/TeamHypersomnia/rectpack2D) and
9[bin-pack](https://github.com/bryanburgers/bin-pack),
10which are in turn based on
11[this article by Blackpawn](http://blackpawn.com/texts/lightmaps/default.html).
13## [Demo](https://mapbox.github.io/potpack/)
18import potpack from 'potpack';
26const {w, h, fill} = potpack(boxes);
27// w and h are resulting container's width and height;
28// fill is the space utilization value (0 to 1), higher is better
30// potpack mutates the boxes array: it's sorted by height,
31// and box objects are augmented with x, y coordinates:
32boxes[0]; // {w: 300, h: 50, x: 100, y: 0}
33boxes[1]; // {w: 100, h: 200, x: 0, y: 0}
38Install with NPM (`npm install potpack`) or Yarn (`yarn add potpack`), then:
41// import as an ES module
42import potpack from 'potpack';
44// or require in Node / Browserify
45const potpack = require('potpack');
48Or use a browser build directly:
51<script src="https://unpkg.com/potpack@1.0.1/index.js"></script>
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list