{"versions":{"3.0.0":{"name":"@mapbox/shelf-pack","description":"A 2D rectangular bin packing data structure that uses the Shelf Best Height Fit heuristic","version":"3.0.0","main":"index.umd.js","jsnext:main":"index.js","license":"ISC","author":{"name":"Bryan Housel","email":"bryan@mapbox.com"},"repository":{"type":"git","url":"git+https://github.com/mapbox/shelf-pack.git"},"keywords":["bin packing","sprite"],"devDependencies":{"benchmark":"^2.1.0","bin-pack":"1.0.2","coveralls":"^2.11.12","documentation":"4.0.0-beta5","eslint":"^3.8.0","greenkeeper-postpublish":"^1.0.1","rollup":"0.41.4","tap":"^10.1.0"},"engines":{"node":">=4.0.0"},"scripts":{"bench":"npm run build && node bench/bench.js","build":"rollup -f umd -n ShelfPack index.js --no-indent --no-strict -o index.umd.js","docs":"documentation build index.js --lint --github --format html --output docs/","lint":"eslint index.js test/ bench/","test":"npm run build && npm run lint && tap --cov test/*.js","postpublish":"greenkeeper-postpublish"},"gitHead":"685083057b15f4e9dd26b7ee631d98ee66dadc11","bugs":{"url":"https://github.com/mapbox/shelf-pack/issues"},"homepage":"https://github.com/mapbox/shelf-pack#readme","_id":"@mapbox/shelf-pack@3.0.0","_shasum":"44e284c8336eeda1e9dbbb1d61954c70e26e5766","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.7.0","_npmUser":{"name":"anonymous","email":"bryan@mapbox.com"},"dist":{"shasum":"44e284c8336eeda1e9dbbb1d61954c70e26e5766","tarball":"http://123.232.10.234:8212/nexus/content/groups/npm-public/@mapbox/shelf-pack/-/shelf-pack-3.0.0.tgz","size":9285,"integrity":"sha512-zNg5cvVoLx9zigv6w0OTCxoB06b0bq7ozHU/+qW+XUsHW3akYRCvYS26ZTCxec3Ca0pIdQ0ApPZMIS0vI0v4cQ=="},"maintainers":[{"name":"anonymous","email":"bryan@mapbox.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/shelf-pack-3.0.0.tgz_1486960752384_0.3332601219881326"},"directories":{},"_cnpmcore_publish_time":"2021-12-19T21:17:54.249Z","contributors":[]},"3.1.0":{"name":"@mapbox/shelf-pack","description":"A 2D rectangular bin packing data structure that uses the Shelf Best Height Fit heuristic","version":"3.1.0","main":"index.umd.js","jsnext:main":"index.js","license":"ISC","author":{"name":"Bryan Housel","email":"bryan@mapbox.com"},"repository":{"type":"git","url":"git+https://github.com/mapbox/shelf-pack.git"},"keywords":["bin packing","sprite"],"devDependencies":{"benchmark":"^2.1.0","bin-pack":"1.0.2","coveralls":"^2.11.12","documentation":"4.0.0-beta5","eslint":"^3.8.0","rollup":"0.41.4","tap":"^10.1.0"},"engines":{"node":">=4.0.0"},"scripts":{"bench":"npm run build && node bench/bench.js","build":"rollup -f umd -n ShelfPack index.js --no-indent --no-strict -o index.umd.js","docs":"documentation build index.js --lint --github --format html --output docs/","lint":"eslint index.js test/ bench/","test":"npm run build && npm run lint && tap --cov test/*.js"},"gitHead":"0df4c218bfef9ba059012e83a45f6418d566366c","bugs":{"url":"https://github.com/mapbox/shelf-pack/issues"},"homepage":"https://github.com/mapbox/shelf-pack#readme","_id":"@mapbox/shelf-pack@3.1.0","_shasum":"1edea9c0bf6715b217171ba60646c201af520f6a","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.7.0","_npmUser":{"name":"anonymous","email":"bryan@mapbox.com"},"dist":{"shasum":"1edea9c0bf6715b217171ba60646c201af520f6a","tarball":"http://123.232.10.234:8212/nexus/content/groups/npm-public/@mapbox/shelf-pack/-/shelf-pack-3.1.0.tgz","size":9380,"integrity":"sha512-4ZzgSGi52fPTRDyjbwsOal4zBXw4Xbq3BTeAnXOQRCXsS5q49wAXMOp1sHK1sDEhL2KNHef3rSnJD4c3e0o/rw=="},"maintainers":[{"email":"dave.prukop@mapbox.com","name":"anonymous"},{"email":"lizzie.gooding@mapbox.com","name":"anonymous"},{"email":"mark.misener@mapbox.com","name":"anonymous"},{"email":"nick.italiano@mapbox.com","name":"anonymous"},{"email":"tara.adiseshan@gmail.com","name":"anonymous"},{"email":"eli.fitch.prof+npm@gmail.com","name":"anonymous"},{"email":"nadia.barbosa@mapbox.com","name":"anonymous"},{"email":"cameron@mapbox.com","name":"anonymous"},{"email":"bruno@mapbox.com","name":"anonymous"},{"email":"langston.smith@mapbox.com","name":"anonymous"},{"email":"rafa@mapbox.com","name":"anonymous"},{"email":"mxn@1ec5.org","name":"anonymous"},{"email":"liz.shigetoshi@mapbox.com","name":"anonymous"},{"email":"hello@johnfurrow.com","name":"anonymous"},{"email":"andrea.delrio@mapbox.com","name":"anonymous"},{"email":"ali@mapbox.com","name":"anonymous"},{"email":"ann.millspaugh@gmail.com","name":"anonymous"},{"email":"hello@franka.tech","name":"anonymous"},{"email":"charlie@mapbox.com","name":"anonymous"},{"email":"julianne@mapbox.com","name":"anonymous"},{"email":"dthompson@gmail.com","name":"anonymous"},{"email":"eric.alessandrini@mapbox.com","name":"anonymous"},{"email":"jayana.charles@mapbox.com","name":"anonymous"},{"email":"christopher.cailleaux@gmail.com","name":"anonymous"},{"email":"poornima@mapbox.com","name":"anonymous"},{"email":"bersabel.tadesse@mapbox.com","name":"anonymous"},{"email":"mallorywood413@gmail.com","name":"anonymous"},{"email":"luis@mapbox.com","name":"anonymous"},{"email":"pilar@mapbox.com","name":"anonymous"},{"email":"galia@mapbox.com","name":"anonymous"},{"email":"matt.gosline@mapbox.com","name":"anonymous"},{"email":"kelly.young@mapbox.com","name":"anonymous"},{"email":"mully@mapbox.com","name":"anonymous"},{"email":"mikel@groundtruth.in","name":"anonymous"},{"email":"danpat@danpat.net","name":"anonymous"},{"email":"macro.shen@mapbox.com","name":"anonymous"},{"email":"asheemm@gmail.com","name":"anonymous"},{"email":"john.sylak-glassman@mapbox.com","name":"anonymous"},{"email":"michael@mapbox.com","name":"anonymous"},{"email":"aj@mapbox.com","name":"anonymous"},{"email":"devin.boyer@mapbox.com","name":"anonymous"},{"email":"andrey@mapbox.com","name":"anonymous"},{"email":"flippmoke@gmail.com","name":"anonymous"},{"email":"safonov.ilya@gmail.com","name":"anonymous"},{"email":"denis.koronchik@gmail.com","name":"anonymous"},{"email":"peterqliu@gmail.com","name":"anonymous"},{"email":"rasagy@mapbox.com","name":"anonymous"},{"email":"chethan@mapbox.com","name":"anonymous"},{"email":"upendra@mapbox.com","name":"anonymous"},{"email":"cesar@mapbox.com","name":"anonymous"},{"email":"pavel@mapbox.com","name":"anonymous"},{"email":"olivia.brundage@mapbox.com","name":"anonymous"},{"email":"aileen.s.rowan@gmail.com","name":"anonymous"},{"email":"richman@mapbox.com","name":"anonymous"},{"email":"danny@mapbox.com","name":"anonymous"},{"email":"eliane@mapbox.com","name":"anonymous"},{"email":"nikinfour@gmail.com","name":"anonymous"},{"email":"gokul.ganesan@mapbox.com","name":"anonymous"},{"email":"blannon@gmail.com","name":"anonymous"},{"email":"sean@mapbox.com","name":"anonymous"},{"email":"me@lukasmartinelli.ch","name":"anonymous"},{"email":"krishna@mapbox.com","name":"anonymous"},{"email":"lindsay@mapbox.com","name":"anonymous"},{"email":"vestibule@anandthakker.net","name":"anonymous"},{"email":"chris.loer@mapbox.com","name":"anonymous"},{"email":"0o3ko0@gmail.com","name":"anonymous"},{"email":"sam.kronick@mapbox.com","name":"anonymous"},{"email":"manohar@mapbox.com","name":"anonymous"},{"email":"alex.parlato@mapbox.com","name":"anonymous"},{"email":"yunjie.li@mapbox.com","name":"anonymous"},{"email":"bharata+npm@mapbox.com","name":"anonymous"},{"email":"aarthy@mapbox.com","name":"anonymous"},{"email":"dane@mapbox.com","name":"anonymous"},{"email":"dana.sulit@mapbox.com","name":"anonymous"},{"email":"emmanuel.sambale@gmail.com","name":"anonymous"},{"email":"miles.sackler@mapbox.com","name":"anonymous"},{"email":"agafonkin@gmail.com","name":"anonymous"},{"email":"hello@chau-nguyen.de","name":"anonymous"},{"email":"michael.krasnyk@gmail.com","name":"anonymous"},{"email":"r.ragupathy85@gmail.com","name":"anonymous"},{"email":"vincent.sarago@mapbox.com","name":"anonymous"},{"email":"tony.chen@mapbox.com","name":"anonymous"},{"email":"arun.planemad@gmail.com","name":"anonymous"},{"email":"patrick@mapbox.com","name":"anonymous"},{"email":"laurier@mapbox.com","name":"anonymous"},{"email":"alice@mapbox.com","name":"anonymous"},{"email":"ansis.brammanis@gmail.com","name":"anonymous"},{"email":"oindrila.gupta92@gmail.com","name":"anonymous"},{"email":"virginia@mapbox.com","name":"anonymous"},{"email":"karito@mapbox.com","name":"anonymous"},{"email":"srividyabharadwaj26@gmail.com","name":"anonymous"},{"email":"perry@mapbox.com","name":"anonymous"},{"email":"colleen.mcginnis@mapbox.com","name":"anonymous"},{"email":"nat@mapbox.com","name":"anonymous"},{"email":"nick.cordella@mapbox.com","name":"anonymous"},{"email":"benjamin@mapbox.com","name":"anonymous"},{"email":"fischer@mapbox.com","name":"anonymous"},{"email":"kai@mapbox.com","name":"anonymous"},{"email":"paul@mapbox.com","name":"anonymous"},{"email":"max@mapbox.com","name":"anonymous"},{"email":"abhishek@mapbox.com","name":"anonymous"},{"email":"jothirnadh@mapbox.com","name":"anonymous"},{"email":"ryan.baumann@mapbox.com","name":"anonymous"},{"email":"dan@mapbox.com","name":"anonymous"},{"email":"lily@mapbox.com","name":"anonymous"},{"email":"amisha@mapbox.com","name":"anonymous"},{"email":"kara.e.mahoney@gmail.com","name":"anonymous"},{"email":"bhargav.kowshik@gmail.com","name":"anonymous"},{"email":"alinapaz@gmail.com","name":"anonymous"},{"email":"damon@mapbox.com","name":"anonymous"},{"email":"lyzi@mapbox.com","name":"anonymous"},{"email":"spam@freenerd.de","name":"anonymous"},{"email":"carol@mapbox.com","name":"anonymous"},{"email":"mayaqgao@gmail.com","name":"anonymous"},{"email":"camilla@mapbox.com","name":"anonymous"},{"email":"saman@mapbox.com","name":"anonymous"},{"email":"bryan@mapbox.com","name":"anonymous"},{"email":"daniel+npm@trvx.org","name":"anonymous"},{"email":"decorah@mapbox.com","name":"anonymous"},{"email":"ajith@mapbox.com","name":"anonymous"},{"email":"pratik@mapbox.com","name":"anonymous"},{"email":"morgan.herlocker@gmail.com","name":"anonymous"},{"email":"hi@jacquestardie.org","name":"anonymous"},{"email":"mollylloyd@gmail.com","name":"anonymous"},{"email":"john.firebaugh@gmail.com","name":"anonymous"},{"email":"tim.channell@gmail.com","name":"anonymous"},{"email":"ruben@mapbox.com","name":"anonymous"},{"email":"mail@kkaefer.com","name":"anonymous"},{"email":"brendan@mapbox.com","name":"anonymous"},{"email":"moritz@mapbox.com","name":"anonymous"},{"email":"karen@mapbox.com","name":"anonymous"},{"email":"david.dave.clark@gmail.com","name":"anonymous"},{"email":"amyleewalton@gmail.com","name":"anonymous"},{"email":"ian.villeda@gmail.com","name":"anonymous"},{"email":"nicki@mapbox.com","name":"anonymous"},{"email":"jake@jakepruitt.com","name":"anonymous"},{"email":"mcwhittemore@gmail.com","name":"anonymous"},{"email":"siyu.song@gmail.com","name":"anonymous"},{"email":"ghoshkaj@gmail.com","name":"anonymous"},{"email":"ulsh@mapbox.com","name":"anonymous"},{"email":"emily@mapbox.com","name":"anonymous"},{"email":"sam@mapbox.com","name":"anonymous"},{"email":"alex@mapbox.com","name":"anonymous"},{"email":"will@mapbox.com","name":"anonymous"},{"email":"sanjay@mapbox.com","name":"anonymous"},{"email":"sajjadkm@gmail.com","name":"anonymous"},{"email":"aruna@mapbox.com","name":"anonymous"},{"email":"kai@mapbox.com","name":"anonymous"},{"email":"matt@mattficke.com","name":"anonymous"},{"email":"andrew@mapbox.com","name":"anonymous"},{"email":"nicholas.ingalls@gmail.com","name":"anonymous"},{"email":"thomas.j.lee@gmail.com","name":"anonymous"},{"email":"dubois@mapbox.com","name":"anonymous"},{"email":"young@mapbox.com","name":"anonymous"},{"email":"ian@mapbox.com","name":"anonymous"},{"email":"jeff@miccolis.net","name":"anonymous"},{"email":"ryan.clark.j@gmail.com","name":"anonymous"},{"email":"lauren@mapbox.com","name":"anonymous"},{"email":"bobby@mapbox.com","name":"anonymous"},{"email":"tristen.brown@gmail.com","name":"anonymous"},{"email":"accounts@mapbox.com","name":"anonymous"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/shelf-pack-3.1.0.tgz_1503637672176_0.6718796011991799"},"directories":{},"_cnpmcore_publish_time":"2021-12-19T21:17:55.098Z","contributors":[]},"3.2.0":{"name":"@mapbox/shelf-pack","description":"A 2D rectangular bin packing data structure that uses the Shelf Best Height Fit heuristic","version":"3.2.0","main":"index.js","module":"index.mjs","license":"ISC","author":{"name":"Bryan Housel","email":"bryan@mapbox.com"},"repository":{"type":"git","url":"git+https://github.com/mapbox/shelf-pack.git"},"keywords":["bin packing","sprite"],"devDependencies":{"benchmark":"^2.1.0","bin-pack":"1.0.2","coveralls":"^3.0.0","documentation":"4.0.0-beta5","eslint":"^5.0.0","rollup":"0.60.0","tap":"^12.0.0"},"engines":{"node":">=6.0.0"},"scripts":{"bench":"npm run build && node bench/bench.js","build":"rollup -f umd -n ShelfPack index.mjs --no-indent --no-strict -o index.js","docs":"documentation build index.mjs --lint --github --format html --output docs/","lint":"eslint index.mjs test/ bench/","test":"npm run build && npm run lint && tap --cov test/*.js"},"gitHead":"aff2193ba439937aedaf38f97f2f26a8bc133453","bugs":{"url":"https://github.com/mapbox/shelf-pack/issues"},"homepage":"https://github.com/mapbox/shelf-pack#readme","_id":"@mapbox/shelf-pack@3.2.0","_npmVersion":"6.1.0","_nodeVersion":"6.7.0","_npmUser":{"name":"anonymous","email":"accounts+npmjs-04@mapbox.com"},"dist":{"integrity":"sha512-dyQxe6ukILV6qaEvxoKCIwhblgRjYp1ZGlClo4xvfbmxzFO5LYu7Tnrg2AZrRgN7VsSragsGcNjzUe9kCdKHYQ==","shasum":"df3630ecce8c042817c9a365b88078412963de64","tarball":"http://123.232.10.234:8212/nexus/content/groups/npm-public/@mapbox/shelf-pack/-/shelf-pack-3.2.0.tgz","fileCount":9,"unpackedSize":40618,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbSLU5CRA9TVsSAnZWagAAM20P/3APEbVp6b8TgVNYhFLi\nVOlH3GSv0vseD1qYdepH6wLQ14pNFaCdufr745rJ9WKei60b0Bj3uKHJ4cZU\naJ7Sb+TljTUYyz1DurYm/r0Yk52Gy3Xg2D+lIPUgsrZTfvihExrHBkJx1ZUh\negfcKaLFV9SH4rA0wY1iRSVoVstHLtBYMukoby92F97FzuOjaNwnHB20J1JZ\nmuWuFSMZvYbCz4ELJlX/9le9hAHTUe2WRovG0vf309QkL1TuQRtQ+iPuiv8M\nsxxbUzKSeWJ7NauwKLynkfUMbeUcaycRzDoOs6wgjEQnD+/bCz7HUUkQwt6V\njqh3OcSntJMle0KqUfs4ruTn9Bk+HEvwHL2h6ajXuqIlpETNKdE7gnd1B0YS\n3dvYU8plvM+lktmGivy9HoVAkd4go9LvbaUliCOWWqSdwEQwh1jKXEwlH64m\n8L48aId4OXnFcYP7j7c16Q85EnMKnoRFVJD8dbu9CdQw2cE8NVT7uk9fatGn\n4KbsFTIlsVTT2X72bTvEZubwWt57ctFlw6eQqbkhwrvFcrXqIwKige/geK//\nTu5vDjjYpIMvL0KlAq68TsYr0TTDdJ+ZhdM5EJeutuc64QxCzHKH7lL8DJAP\n8plNylFNStggeTPFYco8SaAKbUNlljwtLfLm0ZSITR5XPs665/yAEdwYhOHL\nA9g7\r\n=TcHS\r\n-----END PGP SIGNATURE-----\r\n","size":9364},"maintainers":[{"email":"accounts@mapbox.com","name":"anonymous"},{"email":"accounts+npmjs@mapbox.com","name":"anonymous"},{"email":"accounts+npmjs-01@mapbox.com","name":"anonymous"},{"email":"accounts+npmjs-02@mapbox.com","name":"anonymous"},{"email":"accounts+npmjs-03@mapbox.com","name":"anonymous"},{"email":"accounts+npmjs-04@mapbox.com","name":"anonymous"},{"email":"accounts+npmjs-05@mapbox.com","name":"anonymous"},{"email":"accounts+npmjs-06@mapbox.com","name":"anonymous"},{"email":"accounts+npmjs-07@mapbox.com","name":"anonymous"},{"email":"accounts+npmjs-08@mapbox.com","name":"anonymous"},{"email":"accounts+npmjs-09@mapbox.com","name":"anonymous"},{"email":"accounts+npmjs-advanced-actions@mapbox.com","name":"anonymous"},{"email":"accounts+npmjs-npm-ci@mapbox.com","name":"anonymous"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/shelf-pack_3.2.0_1531491640990_0.2681459632204286"},"_cnpmcore_publish_time":"2021-12-19T21:17:56.743Z","contributors":[]}},"dist-tags":{"latest":"3.2.0"},"name":"@mapbox/shelf-pack","time":{"created":"2022-01-26T19:14:17.158Z","modified":"2023-01-12T12:59:10.645Z","3.0.0":"2017-02-13T04:39:14.361Z","3.1.0":"2017-08-25T05:07:53.296Z","3.2.0":"2018-07-13T14:20:41.104Z"},"readme":"[![npm version](https://badge.fury.io/js/%40mapbox%2Fshelf-pack.svg)](https://badge.fury.io/js/%40mapbox%2Fshelf-pack)\n[![Build Status](https://secure.travis-ci.org/mapbox/shelf-pack.svg)](http://travis-ci.org/mapbox/shelf-pack)\n[![Coverage Status](https://coveralls.io/repos/github/mapbox/shelf-pack/badge.svg?branch=master)](https://coveralls.io/github/mapbox/shelf-pack?branch=master)\n\n## shelf-pack\n\nA 2D rectangular [bin packing](https://en.wikipedia.org/wiki/Bin_packing_problem)\ndata structure that uses the Shelf Best Height Fit heuristic.\n\n\n### What is it?\n\n`shelf-pack` is a library for packing little rectangles into a big rectangle.  This sounds simple enough,\nbut finding an optimal packing is a problem with [NP-Complete](https://en.wikipedia.org/wiki/NP-completeness)\ncomplexity.  One useful application of bin packing is to assemble icons or glyphs into a sprite texture.\n\nThere are many ways to approach the bin packing problem, but `shelf-pack` uses the Shelf Best\nHeight Fit heuristic.  It works by dividing the total space into \"shelves\", each with a certain height.\nThe allocator packs rectangles onto whichever shelf minimizes the amount of wasted vertical space.\n\n`shelf-pack` is simple, fast, and works best when the rectangles have similar heights (icons and glyphs\nare like this).  It is not a generalized bin packer, and can potentially waste a lot of space if the\nrectangles vary significantly in height.\n\n\n### How fast is it?\n\nReally fast!  `shelf-pack` is several orders of magnitude faster than the more general\n[`bin-pack`](https://www.npmjs.com/package/bin-pack) library.\n\n```bash\n> npm run bench\n\nShelfPack single allocate fixed size bins x 1,610 ops/sec ±1.21% (90 runs sampled)\nShelfPack single allocate random width bins x 1,475 ops/sec ±1.00% (89 runs sampled)\nShelfPack single allocate random height bins x 1,458 ops/sec ±1.00% (90 runs sampled)\nShelfPack single allocate random height and width bins x 1,346 ops/sec ±0.96% (89 runs sampled)\nShelfPack batch allocate fixed size bins x 1,522 ops/sec ±1.06% (86 runs sampled)\nShelfPack batch allocate random width bins x 1,427 ops/sec ±1.06% (89 runs sampled)\nShelfPack batch allocate random height bins x 1,350 ops/sec ±1.63% (90 runs sampled)\nShelfPack batch allocate random height and width bins x 1,257 ops/sec ±1.02% (89 runs sampled)\nBinPack batch allocate fixed size bins x 2.21 ops/sec ±6.60% (10 runs sampled)\nBinPack batch allocate random width bins x 0.50 ops/sec ±2.25% (6 runs sampled)\nBinPack batch allocate random height bins x 0.51 ops/sec ±1.97% (6 runs sampled)\nBinPack batch allocate random height and width bins x 0.51 ops/sec ±1.37% (6 runs sampled)\n```\n\n\n### Usage\n\n#### Basic Usage\n\n```js\nvar ShelfPack = require('@mapbox/shelf-pack');\n\n// Initialize the sprite with a width and height..\nvar sprite = new ShelfPack(64, 64);\n\n// Pack bins one at a time..\nfor (var i = 0; i < 5; i++) {\n    // packOne() accepts parameters: `width`, `height`, `id`\n    // and returns a single allocated Bin object..\n    // `id` is optional - if you skip it, shelf-pack will make up a number for you..\n    // (Protip: numeric ids are much faster than string ids)\n\n    var bin = sprite.packOne(32, 32);\n    console.log(bin || 'out of space');\n}\n\n/* output:\nBin { id: 1, x: 0, y: 0, w: 32, h: 32, maxw: 32, maxh: 32, refcount: 1 }\nBin { id: 2, x: 32, y: 0, w: 32, h: 32, maxw: 32, maxh: 32, refcount: 1 }\nBin { id: 3, x: 0, y: 32, w: 32, h: 32, maxw: 32, maxh: 32, refcount: 1 }\nBin { id: 4, x: 32, y: 32, w: 32, h: 32, maxw: 32, maxh: 32, refcount: 1 }\nout of space\n*/\n\n// Clear sprite and start over..\nsprite.clear();\n\n// Or, resize sprite by passing larger dimensions..\nsprite.resize(128, 128);   // width, height\n\n```\n\n\n#### Batch packing\n\n```js\nvar ShelfPack = require('@mapbox/shelf-pack');\n\n// If you don't want to think about the size of the sprite,\n// the `autoResize` option will allow it to grow as needed..\nvar sprite = new ShelfPack(10, 10, { autoResize: true });\n\n// Bins can be allocated in batches..\n// Each requested bin should have `w`, `h` (or `width`, `height`) properties..\nvar requests = [\n    { id: 'a', width: 10, height: 10 },\n    { id: 'b', width: 10, height: 12 },\n    { id: 'c', w: 10, h: 12 },\n    { id: 'd', w: 10, h: 10 }\n];\n\n// pack() returns an Array of packed Bin objects..\nvar results = sprite.pack(requests);\n\nresults.forEach(function(bin) {\n    console.log(bin);\n});\n\n/* output:\nBin { id: 'a', x: 0, y: 0, w: 10, h: 10, maxw: 10, maxh: 10, refcount: 1 }\nBin { id: 'b', x: 0, y: 10, w: 10, h: 12, maxw: 10, maxh: 12, refcount: 1 }\nBin { id: 'c', x: 10, y: 10, w: 10, h: 12, maxw: 10, maxh: 12, refcount: 1 }\nBin { id: 'd', x: 10, y: 0, w: 10, h: 10, maxw: 10, maxh: 10, refcount: 1 }\n*/\n\n// If you don't mind letting ShelfPack modify your objects,\n// the `inPlace` option will decorate your bin objects with `x` and `y` properties.\n// Fancy!\nvar myBins = [\n    { id: 'e', width: 12, height: 24 },\n    { id: 'f', width: 12, height: 12 },\n    { id: 'g', w: 10, h: 10 }\n];\n\nsprite.pack(myBins, { inPlace: true });\nmyBins.forEach(function(bin) {\n    console.log(bin);\n});\n\n/* output:\n{ id: 'e', width: 12, height: 24, x: 0, y: 22 }\n{ id: 'f', width: 12, height: 12, x: 20, y: 10 }\n{ id: 'g', w: 10, h: 10, x: 20, y: 0 }\n*/\n\n```\n\n#### Reference Counting\n\n```js\nvar ShelfPack = require('@mapbox/shelf-pack');\n\n// Initialize the sprite with a width and height..\nvar sprite = new ShelfPack(64, 64);\n\n// Allocated bins are automatically reference counted.\n// They start out having a refcount of 1.\n[100, 101, 102].forEach(function(id) {\n    var bin = sprite.packOne(16, 16, id);\n    console.log(bin);\n});\n\n/* output:\nBin { id: 100, x: 0, y: 0, w: 16, h: 16, maxw: 16, maxh: 16, refcount: 1 }\nBin { id: 101, x: 16, y: 0, w: 16, h: 16, maxw: 16, maxh: 16, refcount: 1 }\nBin { id: 102, x: 32, y: 0, w: 16, h: 16, maxw: 16, maxh: 16, refcount: 1 }\n*/\n\n// If you try to pack the same id again, shelf-pack will not re-pack it.\n// Instead, it will increment the reference count automatically..\nvar bin102 = sprite.packOne(16, 16, 102);\nconsole.log(bin102);\n\n/* output:\nBin { id: 102, x: 32, y: 0, w: 16, h: 16, maxw: 16, maxh: 16, refcount: 2 }\n*/\n\n// You can also manually increment the reference count..\nvar bin101 = sprite.getBin(101);\nsprite.ref(bin101);\nconsole.log(bin101);\n\n/* output:\nBin { id: 101, x: 16, y: 0, w: 16, h: 16, maxw: 16, maxh: 16, refcount: 2 }\n*/\n\n// ...and decrement it!\nvar bin100 = sprite.getBin(100);\nsprite.unref(bin100);\nconsole.log(bin100);\n\n/* output:\nBin { id: 100, x: 0, y: 0, w: 16, h: 16, maxw: 16, maxh: 16, refcount: 0 }\n*/\n\n// Bins with a refcount of 0 are considered free space.\n// Next time a bin is packed, shelf-back tries to reuse free space first.\n// See how Bin 103 gets allocated at [0,0] - Bin 100's old spot!\nvar bin103 = sprite.packOne(16, 15, 103);\nconsole.log(bin103);\n\n/* output:\nBin { id: 103, x: 0, y: 0, w: 16, h: 15, maxw: 16, maxh: 16, refcount: 1 }\n*/\n\n// Bin 103 may be smaller (16x15) but it knows 16x16 was its original size.\n// If that space becomes free again, a 16x16 bin will still fit there.\nsprite.unref(bin103)\nvar bin104 = sprite.packOne(16, 16, 104);\nconsole.log(bin104);\n\n/* output:\nBin { id: 104, x: 0, y: 0, w: 16, h: 16, maxw: 16, maxh: 16, refcount: 1 }\n*/\n\n```\n\n\n### Documentation\n\nComplete API documentation is here:  http://mapbox.github.io/shelf-pack/\n\n\n### See also\n\nJ. Jylänky, \"A Thousand Ways to Pack the Bin - A Practical\nApproach to Two-Dimensional Rectangle Bin Packing,\"\nhttp://clb.demon.fi/files/RectangleBinPack.pdf, 2010","users":{}}