{"version":3,"sources":["jsdelivr-header.js","/npm/binpacking@0.0.1/js/packer.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ECkFoB,oBAAX,OAAyB,OAAS,OAAO,SArC7B,OAAS,SAAS,EAAG,GACxC,KAAK,KAAK,EAAG,EACf,GAEO,UAAY,CAEjB,KAAM,SAAS,EAAG,GAChB,KAAK,KAAO,CAAE,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EACrC,EAEA,IAAK,SAAS,GACZ,IAAI,EAAG,EAAM,EACb,IAAK,EAAI,EAAG,EAAI,EAAO,OAAQ,IAC7B,EAAQ,EAAO,IACX,EAAO,KAAK,SAAS,KAAK,KAAM,EAAM,EAAG,EAAM,MACjD,EAAM,IAAM,KAAK,UAAU,EAAM,EAAM,EAAG,EAAM,GAEtD,EAEA,SAAU,SAAS,EAAM,EAAG,GAC1B,OAAI,EAAK,KACA,KAAK,SAAS,EAAK,MAAO,EAAG,IAAM,KAAK,SAAS,EAAK,KAAM,EAAG,GAC9D,GAAK,EAAK,GAAO,GAAK,EAAK,EAC5B,EAEA,IACX,EAEA,UAAW,SAAS,EAAM,EAAG,GAI3B,OAHA,EAAK,MAAO,EACZ,EAAK,KAAQ,CAAE,EAAG,EAAK,EAAO,EAAG,EAAK,EAAI,EAAG,EAAG,EAAK,EAAO,EAAG,EAAK,EAAI,GACxE,EAAK,MAAQ,CAAE,EAAG,EAAK,EAAI,EAAG,EAAG,EAAK,EAAO,EAAG,EAAK,EAAI,EAAG,EAAG,GACxD,CACT","file":"/npm/binpacking@0.0.1/js/packer.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/binpacking@0.0.1/js/packer.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/******************************************************************************\n\nThis is a very simple binary tree based bin packing algorithm that is initialized\nwith a fixed width and height and will fit each block into the first node where\nit fits and then split that node into 2 parts (down and right) to track the\nremaining whitespace.\n\nBest results occur when the input blocks are sorted by height, or even better\nwhen sorted by max(width,height).\n\nInputs:\n------\n\n  w:       width of target rectangle\n  h:      height of target rectangle\n  blocks: array of any objects that have .w and .h attributes\n\nOutputs:\n-------\n\n  marks each block that fits with a .fit attribute pointing to a\n  node with .x and .y coordinates\n\nExample:\n-------\n\n  var blocks = [\n    { w: 100, h: 100 },\n    { w: 100, h: 100 },\n    { w:  80, h:  80 },\n    { w:  80, h:  80 },\n    etc\n    etc\n  ];\n\n  var packer = new Packer(500, 500);\n  packer.fit(blocks);\n\n  for(var n = 0 ; n < blocks.length ; n++) {\n    var block = blocks[n];\n    if (block.fit) {\n      Draw(block.fit.x, block.fit.y, block.w, block.h);\n    }\n  }\n\n\n******************************************************************************/\n\n-function (exports) {\n\n\nvar Packer = exports.Packer = function(w, h) {\n  this.init(w, h);\n};\n\nPacker.prototype = {\n\n  init: function(w, h) {\n    this.root = { x: 0, y: 0, w: w, h: h };\n  },\n\n  fit: function(blocks) {\n    var n, node, block;\n    for (n = 0; n < blocks.length; n++) {\n      block = blocks[n];\n      if (node = this.findNode(this.root, block.w, block.h))\n        block.fit = this.splitNode(node, block.w, block.h);\n    }\n  },\n\n  findNode: function(root, w, h) {\n    if (root.used)\n      return this.findNode(root.right, w, h) || this.findNode(root.down, w, h);\n    else if ((w <= root.w) && (h <= root.h))\n      return root;\n    else\n      return null;\n  },\n\n  splitNode: function(node, w, h) {\n    node.used = true;\n    node.down  = { x: node.x,     y: node.y + h, w: node.w,     h: node.h - h };\n    node.right = { x: node.x + w, y: node.y,     w: node.w - w, h: h          };\n    return node;\n  }\n\n}\n\n}(typeof window !== 'undefined' ? window : module.exports);"]}