2.0.0 • Published 3 years ago

potpack v2.0.0

Weekly downloads
386,572
License
ISC
Repository
github
Last release
3 years ago

potpack

A tiny JavaScript library for packing 2D rectangles into a near-square container, which is useful for generating CSS sprites and WebGL textures. Similar to shelf-pack, but static (you can't add items once a layout is generated), and aims for maximal space utilization.

A variation of algorithms used in rectpack2D and bin-pack, which are in turn based on this article by Blackpawn.

Demo

Example usage

import potpack from 'potpack';

const boxes = [
    {w: 300, h: 50},
    {w: 100, h: 200},
    ...
];

const {w, h, fill} = potpack(boxes);
// w and h are resulting container's width and height;
// fill is the space utilization value (0 to 1), higher is better

// potpack mutates the boxes array: it's sorted by height,
// and box objects are augmented with x, y coordinates:
boxes[0]; // {w: 300, h: 50,  x: 100, y: 0}
boxes[1]; // {w: 100, h: 200, x: 0,   y: 0}

Install

Install with NPM: npm install potpack.

Potpack is provided as a ES module, so it's only supported on modern browsers, excluding IE:

<script type="module">
import potpack from 'https://cdn.skypack.dev/potpack';
...
</script>

In Node, you can't use require — only import in ESM-capable versions (v12.15+):

import potpack from 'potpack';
@simosol/mapbox-gl-js-offlinebst-map-gl@mapcreator/mapbox-gl@datav-gi/datav-gi-js@everything-registry/sub-chunk-2464@langge-data/mapbox-gltest-map-azsftwrvwake_jsx-mapbox-glswsk-mapboxglthinknetmapsthree-nebulavnmapvizzuality-mapbox-glvietmap-glvietmaps-glkt-maplibre-gl@openmapvn/maplibre-glstdlib-forktiny-atlastrackasia-glthree-stdlibtoglib@americana/maplibre-gl@ark-org/map@autoxing/mapbox-gl@alantgeo/mapbox-gl@allmaps/layers@cczbby/mapbox-gl@cczbby/maplibre-gl@cgcs2000/mapbox-gl@0xfa11/maplibre-gl@deltadevs/three-stdlib@dfw810/mapbox-gl@datav-gi/datavgi-gl-jsxyd-mapbox-glxtal-gl@felix5/mapbox-webgl2@gvol-org/mapbox-gl@hansdo/maplibre-gl@fwoosh/app@goongmaps/goong-js@etherealengine/editor@geops/maplibre-gl@geomatico/mapbox-gl@globalfishingwatch/mapbox-gl@globalfishingwatch/maplibre-gl@krisdages/mapbox-gl@koordinates/maplibre-gl@ir-engine/editor@luqh_mapbox/mapbox-gl@maps-gl/maps-gl@mapgis/mapbox-gl@emuanalytics/maplibre-gl@jingsam/mapbox-gl@inelo/maplibre-gl@kantas/vector-js@ogix/mapbox-gl@react-three/lightmap@rczobor/maplibre-gl@plotly/mapbox-gl@sakitam-gis/mapbox-gl@saitonakamura/three-stdlib@rage997/three-nebula@openmapvn/openmapvn-gl@onthegomap/mapbox-gl@porsager/mapbox-gl@polygonjs/polygonjsp-mapbox-glpbf-basic-rendersdf-managerprotomaps-leafletpetr-maplibre-glrif-mapbox-gllg-mapbox-glmap-core-funcmapbox-glmapbox-gl--custom-stretchmapbox-gl-ahtmapbox-gl-custom-layermapbox-gl-tdtsdmapbox-gl-testmapbox-gl-tultmapbox-gl_wstdmapbox-gl-encryptedmapbox-gl-js-with-shapesmapbox-gl-kyemapglvmapmetrics-glmapmetrics-gl-testmaplibre-gl-reduce-functionalitiesmaplibre-gl-tdtsdmaplibre-glmaplibre-gl-ashmapbox-gl-mbtilesmapbox-with-shapesmapbox-gl-htmapbox-gl-hxmapmagic-glmapsi-gl
2.0.0

3 years ago

1.0.2

4 years ago

1.0.1

7 years ago

1.0.0

7 years ago