JavaScript implementation of "2d rectangular bin packing": https://github.com/juj/RectangleBinPack
Demo at: https://pkbinpack.herokuapp.com/index.html
More info later on: http://www.piotrkowalski.pw/en-us/boczne/short-articles/2d-bin-packing-javascript/