Filling in leftover space
In reading over the calculatePositions function, it seems like it wouldn't be too difficult to keep track of spaces left behind when a column is cut off (with space remaining) by an element too wide to fit into it. If we could keep track of those positions (perhaps in a separate array?) we could have an option to "fill in empty space" later on, when we come across tiles small enough to fit. See this example:
If we wanted to go the extra mile, perhaps we could also provide an option like "maxUnsortDistance" to provide some way to limit the distance a tile can be moved from where it would otherwise have appeared, to fill in empty space (which can be adjusted to account for how important sorting order is to the particular application).
Is this something you've looked into before? It doesn't seem terribly difficult, but would be extremely useful! I haven't seen any library that does this so far (I've been looking for one).