Arrange rectangular boxes inside a single container with a JavaScript packing heuristic, a standalone API, and an interactive 3D demo.
Try the demo · API reference · Demo guide · Benchmarks · Contributing
Project status: Available from a repository checkout. Not published to npm; upstream licensing is unresolved. Read the license status before adopting or redistributing the code.
| Capability | Details |
|---|---|
| Packing | Single-container EB-AFIT heuristic for rectangular boxes. |
| Search effort | Standard by default; optional extended search tries a second policy. |
| Rotation rules | Free, upright, or fixed per box type. |
| Downward settling | Optional post-pass closes vertical gaps while preserving packed volume. |
| JavaScript API | CommonJS, ES modules, and plain browser scripts; no runtime dependencies. |
| TypeScript | Included declarations for Node.js and the browser namespace. |
| Interactive demo | Inspect placements, rotate the view, and export JSON or PNG. |
| Validation | Independent geometry checks, seeded regressions, and reproducible benchmarks. |
Requires Node.js 22 or later. From the repository root:
const { pack } = require('./pack.js');
const result = pack({
container: { width: 4, height: 3, depth: 2 },
items: [{
id: 'carton', width: 2, height: 3, depth: 4,
quantity: 1, rotation: 'upright'
}],
settle: true
});
console.log(result.packedCount); // 1
console.log(result.utilization); // 1 (100%)
console.log(result.placements); // Positions and rotated dimensionsFor ES modules, import from ./pack.mjs. In a browser, load pack.js and call
BinPacking.pack(...). The solver is synchronous, does not modify input objects,
and returns independent results. Use one consistent measurement unit.
For an optional second search pass, set search: 'extended'; see the
quality/runtime tradeoff.
See the complete input/output reference, TypeScript usage, and local package archive instructions.
| Rule | Behavior |
|---|---|
free (default) |
Permute width, height, and depth. |
upright |
Keep original height on Y; width/depth may swap. |
fixed |
Preserve all three original axes. |
Rules always refer to the original container axes.
Settling is optional and defaults to
false in the API; the demo enables it through a checkbox.
Open the online workbench or open
index.html locally. Choose an example, edit box quantities and rotation rules,
and calculate the arrangement. Select a box to inspect its coordinates and base
contact. See the demo guide for controls and exports.
- This heuristic does not guarantee optimal packing.
- Geometric fit and downward settling do not guarantee physical stability. Weight, balance, and load-bearing strength are not modeled; overhangs may remain.
- Prefer integer dimensions in consistent units. A general decimal precision policy is not provided.
- The online demo calculates in a cancellable background worker. The synchronous library API and direct-file demo fallback can block the calling thread; displaying very large results can still pause the demo.
npm ci
npm run check # Runtime/package tests and TypeScript checks
npm run bench:check # Recorded packing-quality baseline
npm run bench:quick # Short timing and quality runRead the contribution guide, testing guide, and benchmark methodology. Timing comparisons are observational; CI checks correctness and packed volume.
| Guide | Contents |
|---|---|
| API reference | Inputs, results, rotations, settling, TypeScript, and package archives. |
| Demo guide | Camera controls, box inspection, exports, and limitations. |
| Benchmarks | Reproducible measurements, quality references, and optimization reports. |
| Testing | Geometry, regressions, package checks, and validation scope. |
| Changelog | Unreleased changes and integration notes. |
| Documentation index | Repository layout and site maintenance. |
The solver is a JavaScript conversion of wknechtel/3d-bin-pack, derived from Erhan Baltacıoğlu’s EB-AFIT work. Keep the upstream attribution intact.
The package remains private and UNLICENSED pending verified upstream
permissions. MIT is the preferred future license, but no project-wide license
grant is currently asserted. See license status and provenance.