Skip to content

Commit 29d8ac4

Browse files
committed
add source-generated typescript types
1 parent 935e300 commit 29d8ac4

File tree

7 files changed

+262
-296
lines changed

7 files changed

+262
-296
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
index.d.ts

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ISC License
22

3-
Copyright (c) 2022, Mapbox
3+
Copyright (c) 2025, Mapbox
44

55
Permission to use, copy, modify, and/or distribute this software for any purpose
66
with or without fee is hereby granted, provided that the above copyright notice

index.d.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

index.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
1-
1+
/**
2+
* @typedef {Object} PotpackBox
3+
* @property {number} w Box width.
4+
* @property {number} h Box height.
5+
* @property {number} [x] X coordinate in the resulting container.
6+
* @property {number} [y] Y coordinate in the resulting container.
7+
*/
8+
9+
/**
10+
* @typedef {Object} PotpackStats
11+
* @property {number} w Width of the resulting container.
12+
* @property {number} h Height of the resulting container.
13+
* @property {number} fill The space utilization value (0 to 1). Higher is better.
14+
*/
15+
16+
/**
17+
* Packs 2D rectangles into a near-square container.
18+
*
19+
* Mutates the {@link boxes} array: it's sorted (by height/width),
20+
* and box objects are augmented with `x`, `y` coordinates.
21+
*
22+
* @param {PotpackBox[]} boxes
23+
* @return {PotpackStats}
24+
*/
225
export default function potpack(boxes) {
326

427
// calculate total box area and maximum box width
@@ -46,7 +69,7 @@ export default function potpack(boxes) {
4669
if (box.w === space.w && box.h === space.h) {
4770
// space matches the box exactly; remove it
4871
const last = spaces.pop();
49-
if (i < spaces.length) spaces[i] = last;
72+
if (last && i < spaces.length) spaces[i] = last;
5073

5174
} else if (box.h === space.h) {
5275
// space matches the box height; update it accordingly

0 commit comments

Comments
 (0)