Initial commit

This commit is contained in:
2026-04-15 17:08:39 +02:00
parent ae164c47a8
commit 47fd1c2b7a
1819 changed files with 685388 additions and 0 deletions

15
node_modules/potpack/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,15 @@
ISC License
Copyright (c) 2025, Mapbox
Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.

53
node_modules/potpack/README.md generated vendored Normal file
View File

@@ -0,0 +1,53 @@
# 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](https://github.com/mapbox/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](https://github.com/TeamHypersomnia/rectpack2D) and
[bin-pack](https://github.com/bryanburgers/bin-pack),
which are in turn based on
[this article by Blackpawn](http://blackpawn.com/texts/lightmaps/default.html).
## [Demo](https://mapbox.github.io/potpack/)
## Example usage
```js
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:
```html
<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+):
```js
import potpack from 'potpack';
```

55
node_modules/potpack/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,55 @@
/**
* @typedef {Object} PotpackBox
* @property {number} w Box width.
* @property {number} h Box height.
* @property {number} [x] X coordinate in the resulting container.
* @property {number} [y] Y coordinate in the resulting container.
*/
/**
* @typedef {Object} PotpackStats
* @property {number} w Width of the resulting container.
* @property {number} h Height of the resulting container.
* @property {number} fill The space utilization value (0 to 1). Higher is better.
*/
/**
* Packs 2D rectangles into a near-square container.
*
* Mutates the {@link boxes} array: it's sorted (by height/width),
* and box objects are augmented with `x`, `y` coordinates.
*
* @param {PotpackBox[]} boxes
* @return {PotpackStats}
*/
export default function potpack(boxes: PotpackBox[]): PotpackStats;
export type PotpackBox = {
/**
* Box width.
*/
w: number;
/**
* Box height.
*/
h: number;
/**
* X coordinate in the resulting container.
*/
x?: number | undefined;
/**
* Y coordinate in the resulting container.
*/
y?: number | undefined;
};
export type PotpackStats = {
/**
* Width of the resulting container.
*/
w: number;
/**
* Height of the resulting container.
*/
h: number;
/**
* The space utilization value (0 to 1). Higher is better.
*/
fill: number;
};

117
node_modules/potpack/index.js generated vendored Normal file
View File

@@ -0,0 +1,117 @@
/**
* @typedef {Object} PotpackBox
* @property {number} w Box width.
* @property {number} h Box height.
* @property {number} [x] X coordinate in the resulting container.
* @property {number} [y] Y coordinate in the resulting container.
*/
/**
* @typedef {Object} PotpackStats
* @property {number} w Width of the resulting container.
* @property {number} h Height of the resulting container.
* @property {number} fill The space utilization value (0 to 1). Higher is better.
*/
/**
* Packs 2D rectangles into a near-square container.
*
* Mutates the {@link boxes} array: it's sorted (by height/width),
* and box objects are augmented with `x`, `y` coordinates.
*
* @param {PotpackBox[]} boxes
* @return {PotpackStats}
*/
export default function potpack(boxes) {
// calculate total box area and maximum box width
let area = 0;
let maxWidth = 0;
for (const box of boxes) {
area += box.w * box.h;
maxWidth = Math.max(maxWidth, box.w);
}
// sort the boxes for insertion by height, descending
boxes.sort((a, b) => b.h - a.h);
// aim for a squarish resulting container,
// slightly adjusted for sub-100% space utilization
const startWidth = Math.max(Math.ceil(Math.sqrt(area / 0.95)), maxWidth);
// start with a single empty space, unbounded at the bottom
const spaces = [{x: 0, y: 0, w: startWidth, h: Infinity}];
let width = 0;
let height = 0;
for (const box of boxes) {
// look through spaces backwards so that we check smaller spaces first
for (let i = spaces.length - 1; i >= 0; i--) {
const space = spaces[i];
// look for empty spaces that can accommodate the current box
if (box.w > space.w || box.h > space.h) continue;
// found the space; add the box to its top-left corner
// |-------|-------|
// | box | |
// |_______| |
// | space |
// |_______________|
box.x = space.x;
box.y = space.y;
height = Math.max(height, box.y + box.h);
width = Math.max(width, box.x + box.w);
if (box.w === space.w && box.h === space.h) {
// space matches the box exactly; remove it
const last = spaces.pop();
if (last && i < spaces.length) spaces[i] = last;
} else if (box.h === space.h) {
// space matches the box height; update it accordingly
// |-------|---------------|
// | box | updated space |
// |_______|_______________|
space.x += box.w;
space.w -= box.w;
} else if (box.w === space.w) {
// space matches the box width; update it accordingly
// |---------------|
// | box |
// |_______________|
// | updated space |
// |_______________|
space.y += box.h;
space.h -= box.h;
} else {
// otherwise the box splits the space into two spaces
// |-------|-----------|
// | box | new space |
// |_______|___________|
// | updated space |
// |___________________|
spaces.push({
x: space.x + box.w,
y: space.y,
w: space.w - box.w,
h: box.h
});
space.y += box.h;
space.h -= box.h;
}
break;
}
}
return {
w: width, // container width
h: height, // container height
fill: (area / (width * height)) || 0 // space utilization
};
}

43
node_modules/potpack/package.json generated vendored Normal file
View File

@@ -0,0 +1,43 @@
{
"name": "potpack",
"version": "2.1.0",
"description": "A tiny library for packing 2D rectangles (for sprite layouts)",
"main": "index.js",
"type": "module",
"exports": "./index.js",
"types": "index.d.ts",
"sideEffects": false,
"files": [
"index.js",
"index.d.ts"
],
"scripts": {
"pretest": "eslint *.js",
"test": "tsc && node test.js",
"prepublishOnly": "npm test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/mapbox/potpack.git"
},
"keywords": [
"algorithms",
"sprites",
"bin packing",
"geometry",
"rectangles"
],
"author": "Vladimir Agafonkin",
"license": "ISC",
"bugs": {
"url": "https://github.com/mapbox/potpack/issues"
},
"homepage": "https://mapbox.github.io/potpack/",
"devDependencies": {
"@mapbox/shelf-pack": "^3.2.0",
"bin-pack": "^1.0.2",
"eslint": "^9.31.0",
"eslint-config-mourner": "^4.0.2",
"typescript": "^5.8.3"
}
}