It is necessary to simplify and adapt the js library SVGnest for operation without a web interface and SVG elements. That is, creating a function that takes an array of data about shapes (currently rectangles) as input and based on defined parameters provides results on the placement of each element after all iterations have been completed.
For example, we have an array of rectangles, where each rectangle is described by its width, height, and id. To avoid confusion in the array of rectangles, each subsequent rectangle is added with the size in X of the previous one. Link to example: JSFiddle.
Two new parameters need to be added to the function svgnest.js, which already accepts parameters from the library settings page: the number of iterations (i.e., after how many to stop and return the array) and the dimensions of the "active rectangle" that was previously selected manually.
var config = {
clipperScale: 10000000,
curveTolerance: 0,
spacing: 0,
rotations: 4,
populationSize: 10,
mutationRate: 10,
useHoles: false,
exploreConcave: false,
// ↓ to add new params ↓
iterations: 100,
mainRectangle: {
width: 1000,
height: 500
}
};
The function should perform calculations based on the provided data and parameters and return an array with results for each rectangle, including its identifier, new X and Y coordinates, and rotation angle, for example:
[
{id: 1, x: 10.5, y: 20.3, rotate: 0},
{id: 2, x: 15.2, y: 30.4, rotate: 90},
...
]
It is also necessary to change the initial calculation point on the placement plane of the elements. Instead of starting from the top left point for sorting elements, it should now start from the bottom left corner and proceed from left to right, that is, calculation based on width and from bottom to top.

All necessary js files for processing should be merged into one file, for example, svgNewNest.js, to simplify integration and use of the function. Anything not needed for calculations should not be added, as there is no interaction with SVG here.
<script src="util/pathsegpolyfill.js"></script> should not be added
<script src="util/matrix.js"></script> <!-- import to svgnest.js -->
<script src="util/domparser.js"></script> should not be added
<script src="util/clipper.js"></script> <!-- import to svgnest.js -->
<script src="util/parallel.js"></script>
<script src="util/geometryutil.js"></script> <!-- import to svgnest.js -->
<script src="util/placementworker.js"></script> <!-- import to svgnest.js -->
<script src="svgparser.js"></script> should not be added
<script src="svgnest.js"></script> <!-- this is the main function -->
<script src="util/filesaver.js"></script> should not be added