text: /**
   * MaxRectsBinPack 0.2.1
   * Copyright (c) 2017-present @06wj
   * @license MIT
   */
  !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.MaxRectsBinPack=t():e.MaxRectsBinPack=t()}("undefined"!=typeof self?self:this,function(){return function(e){var t={};function i(n){if(t[n])return t[n].exports;var a=t[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,i),a.l=!0,a.exports}return i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)i.d(n,a,function(t){return e[t]}.bind(null,a));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=0)}([function(e,t,i){e.exports=i(1)},function(e,t,i){"use strict";function n(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}i.r(t);var a=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.x=t,this.y=i,this.width=n,this.height=a}var t,i,a;return t=e,a=[{key:"isContainedIn",value:function(e,t){return e.isContainedIn(t)}}],(i=[{key:"clone",value:function(){return new e(this.x,this.y,this.width,this.height)}},{key:"isContainedIn",value:function(e){return this.x>=e.x&&this.y>=e.y&&this.x+this.width<=e.x+e.width&&this.y+this.height<=e.y+e.height}}])&&n(t.prototype,i),a&&n(t,a),e}();function h(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}i.d(t,"Packer",function(){return c}),i.d(t,"ShortSideFit",function(){return r}),i.d(t,"LongSideFit",function(){return o}),i.d(t,"AreaFit",function(){return u}),i.d(t,"BottomLeft",function(){return l}),i.d(t,"ContactPoint",function(){return s});var r="ShortSideFit",o="LongSideFit",u="AreaFit",l="BottomLeft",s="ContactPoint",c=function(){function e(t,i,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Object.assign(this,{allowRotate:!1,pot:!1,square:!1,padding:0}),this.usedRectangles=[],this.freeRectangles=[],this.init(t,i,n)}var t,i,n;return t=e,(i=[{key:"init",value:function(e,t,i){this.maxWidth=e,this.maxHeight=t,Object.assign(this,i),this.reset()}},{key:"reset",value:function(){this.usedRectangles.length=0,this.freeRectangles.length=0,this.freeRectangles.push(new a(0,0,this.maxWidth,this.maxHeight))}},{key:"insert",value:function(e,t,i){var n=new a,h={value:0},c={value:0};i=i||r;var d=this.padding,f=2*d;switch(d&&(e+=f,t+=f),i){case r:n=this._findPositionForNewNodeShortSideFit(e,t,h,c);break;case o:n=this._findPositionForNewNodeLongSideFit(e,t,h,c);break;case u:n=this._findPositionForNewNodeAreaFit(e,t,h,c);break;case l:n=this._findPositionForNewNodeBottomLeft(e,t,h,c);break;case s:n=this._findPositionForNewNodeContactPoint(e,t,h)}return 0===n.height?n:(this._placeRectangle(n),n)}},{key:"_cloneRectangles",value:function(e){var t=[];return e.forEach(function(e,i){t.push({x:e.x,y:e.y,width:e.width,height:e.height,_index:i})}),t}},{key:"insertRects",value:function(e,t){t||(t=this.getBestRule(e));var i=-1,n=-1,h={rects:[],rule:t,width:i,height:n,realWidth:i,realHeight:n},r=e.length,o=this.padding,u=2*o;if(o)for(var l=0;l<r;l++){var s=e[l];s.width+=u,s.height+=u}for(;e.length>0;){for(var c=1/0,d=1/0,f=-1,v=new a,g=0;g<e.length;g++){var y={value:0},w={value:0},x=this._scoreRectangle(e[g].width,e[g].height,t,y,w);(y.value<c||y.value===c&&w.value<d)&&(c=y.value,d=w.value,v=x,f=g)}if(-1===f)break;this._placeRectangle(v);var p=e.splice(f,1)[0],b={x:v.x,y:v.y,width:v.width,height:v.height};p.width===v.width&&p.height===v.height||(b.rotated=!0),i=Math.max(i,b.x+b.width),n=Math.max(n,b.y+b.height),p.fitInfo=b,h.rects.push(p)}var m=h.rects.length;if(h.fitCount=m,h.unfitCount=r-m,h.done=0===h.unfitCount,o)for(var _=0;_<m;_++){var M=h.rects[_];M.width-=u,M.height-=u;var R=M.fitInfo;R.x+=o,R.y+=o,R.width-=u,R.height-=u}h.realWidth=i,h.realHeight=n,h.realArea=i*n;var k=Math.ceil(Math.log(i)/Math.log(2)),N=Math.ceil(Math.log(n)/Math.log(2));return h.binWidth=Math.pow(2,k),h.binHeight=Math.pow(2,N),h.binArea=h.binWidth*h.binHeight,this.pot?(h.width=h.binWidth,h.height=h.binHeight):(h.width=i,h.height=n),h.area=h.width*h.height,h}},{key:"getBestRule",value:function(e){var t=this,i=[r,o,u,l,s],n=[];return i.forEach(function(i,a){var h=t._cloneRectangles(e);t.reset();var r=t.insertRects(h,i);r._ruleIndex=a,r.done&&n.push(r)}),this.reset(),n.sort(function(e,t){var i=0;return i=(i=(i=i||e.area-t.area)||e.binArea-t.binArea)||e.realArea-t.realArea}),i[n[0]._ruleIndex]}},{key:"_findPositionForNewNodeShortSideFit",value:function(e,t,i,n){var h,r,o,u,l=this.freeRectangles,s=new a;i.value=1/0;for(var c=0;c<l.length;c++){var d=l[c];d.width>=e&&d.height>=t&&(h=Math.abs(d.width-e),r=Math.abs(d.height-t),o=Math.min(h,r),u=Math.max(h,r),(o<i.value||o===i.value&&u<n.value)&&(s.x=d.x,s.y=d.y,s.width=e,s.height=t,i.value=o,n.value=u)),this.allowRotate&&d.width>=t&&d.height>=e&&(h=Math.abs(d.width-t),r=Math.abs(d.height-e),o=Math.min(h,r),u=Math.max(h,r),(o<i.value||o===i.value&&u<n.value)&&(s.x=d.x,s.y=d.y,s.width=t,s.height=e,i.value=o,n.value=u))}return s}},{key:"_findPositionForNewNodeLongSideFit",value:function(e,t,i,n){var h,r,o,u,l=this.freeRectangles,s=new a;n.value=-1/0;for(var c=0;c<l.length;c++){var d=l[c];d.width>=e&&d.height>=t&&(h=Math.abs(d.width-e),r=Math.abs(d.height-t),o=Math.min(h,r),((u=Math.max(h,r))>n.value||u===n.value&&o>i.value)&&(s.x=d.x,s.y=d.y,s.width=e,s.height=t,i.value=o,n.value=u)),this.allowRotate&&d.width>=t&&d.height>=e&&(h=Math.abs(d.width-t),r=Math.abs(d.height-e),o=Math.min(h,r),((u=Math.max(h,r))>n.value||u===n.value&&o>i.value)&&(s.x=d.x,s.y=d.y,s.width=t,s.height=e,i.value=o,n.value=u))}return s}},{key:"_findPositionForNewNodeAreaFit",value:function(e,t,i,n){var h,r,o,u=this.freeRectangles,l=new a;i.value=1/0;for(var s=0;s<u.length;s++){var c=u[s],d=c.width*c.height-e*t;c.width>=e&&c.height>=t&&(h=Math.abs(c.width-e),r=Math.abs(c.height-t),o=Math.min(h,r),(d<i.value||d===i.value&&o<n.value)&&(l.x=c.x,l.y=c.y,l.width=e,l.height=t,n.value=o,i=d)),this.allowRotate&&c.width>=t&&c.height>=e&&(h=Math.abs(c.width-t),r=Math.abs(c.height-e),o=Math.min(h,r),(d<i.value||d===i.value&&o<n.value)&&(l.x=c.x,l.y=c.y,l.width=t,l.height=e,n.value=o,i.value=d))}return l}},{key:"_findPositionForNewNodeBottomLeft",value:function(e,t,i,n){var h,r=this.freeRectangles,o=new a;i.value=1/0;for(var u=0;u<r.length;u++){var l=r[u];l.width>=e&&l.height>=t&&((h=l.y+t)<i.value||h===i.value&&l.x<n.value)&&(o.x=l.x,o.y=l.y,o.width=e,o.height=t,i.value=h,n.value=l.x),this.allowRotate&&l.width>=t&&l.height>=e&&((h=l.y+e)<i.value||h===i.value&&l.x<n.value)&&(o.x=l.x,o.y=l.y,o.width=t,o.height=e,i.value=h,n.value=l.x)}return o}},{key:"_findPositionForNewNodeContactPoint",value:function(e,t,i){var n,h=this.freeRectangles,r=new a;i.value=-1;for(var o=0;o<h.length;o++){var u=h[o];u.width>=e&&u.height>=t&&(n=this._contactPointScoreNode(u.x,u.y,e,t))>i.value&&(r.x=u.x,r.y=u.y,r.width=e,r.height=t,i=n),this.allowRotate&&u.width>=t&&u.height>=e&&(n=this._contactPointScoreNode(u.x,u.y,t,e))>i.value&&(r.x=u.x,r.y=u.y,r.width=t,r.height=e,i.value=n)}return r}},{key:"_scoreRectangle",value:function(e,t,i,n,h){var c=new a;switch(n.value=1/0,h.value=1/0,i){case r:c=this._findPositionForNewNodeShortSideFit(e,t,n,h);break;case o:c=this._findPositionForNewNodeLongSideFit(e,t,h,n);break;case u:c=this._findPositionForNewNodeAreaFit(e,t,n,h);break;case l:c=this._findPositionForNewNodeBottomLeft(e,t,n,h);break;case s:c=this._findPositionForNewNodeContactPoint(e,t,n),n.value=-n.value}return 0===c.height&&(n.value=1/0,h.value=1/0),c}},{key:"_placeRectangle",value:function(e){for(var t=this.freeRectangles.length,i=0;i<t;i++)this._splitFreeNode(this.freeRectangles[i],e)&&(this.freeRectangles.splice(i,1),i--,t--);this._pruneFreeList(),this.usedRectangles.push(e)}},{key:"_splitFreeNode",value:function(e,t){var i,n=this.freeRectangles,a=t.x>=e.x+e.width||t.x+t.width<=e.x,h=t.y>=e.y+e.height||t.y+t.height<=e.y;return!a&&!h&&(t.y>e.y&&((i=e.clone()).height=t.y-i.y,n.push(i)),t.y+t.height<e.y+e.height&&((i=e.clone()).y=t.y+t.height,i.height=e.y+e.height-(t.y+t.height),n.push(i)),t.x>e.x&&((i=e.clone()).width=t.x-i.x,n.push(i)),t.x+t.width<e.x+e.width&&((i=e.clone()).x=t.x+t.width,i.width=e.x+e.width-(t.x+t.width),n.push(i)),!0)}},{key:"_commonIntervalLength",value:function(e,t,i,n){return t<i||n<e?0:Math.min(t,n)-Math.max(e,i)}},{key:"_contactPointScoreNode",value:function(e,t,i,n){var a,h=this.usedRectangles,r=0;0!==e&&e+i!==this.maxWidth||(r+=n),0!==t&&t+n!==this.maxHeight||(r+=i);for(var o=0;o<h.length;o++)(a=h[o]).x!==e+i&&a.x+a.width!==e||(r+=this._commonIntervalLength(a.y,a.y+a.height,t,t+n)),a.y!==t+n&&a.y+a.height!==t||(r+=this._commonIntervalLength(a.x,a.x+a.width,e,e+i));return r}},{key:"_pruneFreeList",value:function(){for(var e=this.freeRectangles,t=0;t<e.length;t++)for(var i=t+1;i<e.length;i++){if(a.isContainedIn(e[t],e[i])){e.splice(t,1);break}a.isContainedIn(e[i],e[t])&&e.splice(i,1)}}},{key:"_occupancy",value:function(){for(var e=this.usedRectangles,t=0,i=0;i<e.length;i++)t+=e[i].width*e[i].height;return t/(this.maxWidth*this.maxHeight)}}])&&h(t.prototype,i),n&&h(t,n),e}()}])});