import e from"react";var t=function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.i=function(e){return e},t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(t,r){t.exports=e},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),o=function(e){return e&&e.__esModule?e:{default:e}}(r(0)),a=function(e){function t(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);for(var r=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e)),n={},o=0;o<r.props.numCols;o++)n["col-"+o]=[];return r.state=n,r.cancel=function(){console.log("Cancelation not set yet")},r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),n(t,[{key:"render",value:function(){for(var e=[],t=0;t<this.props.numCols;t++)e.push(o.default.createElement("div",{style:{width:100/this.props.numCols+"%",display:"flex",flexDirection:"column",float:"left"},className:"react-image-masonry-col",key:"col-"+t},Object.values(this.state["col-"+t])));var r=this.props.hasOwnProperty("containerWidth")?this.props.containerWidth:"100%",n=this.props.hasOwnProperty("containerHeight")?this.props.containerHeight:this.props.scrollable?"500px":"auto",a=this.props.scrollable?"scroll":"hidden";return o.default.createElement("div",{ref:"container",style:{width:r,height:n,overflowX:"hidden",overflowY:a,margin:"auto"},className:this.props.className},o.default.createElement("style",null,"\n      .react-image-masonry-col * { width: 100%; box-sizing: border-box; }\n      @keyframes fadeIn { from { opacity:0; } to { opacity:1; } }\n    "),e)}},{key:"componentDidMount",value:function(){var e=this.getTiles(this.props);this.addTiles(e)}},{key:"componentWillReceiveProps",value:function(e){var t=this;try{if(e.numCols!==this.props.numCols||!this.areArraysEqual(e.imageUrls,this.props.imageUrls)||(e.children||[]).length!==(this.props.children||[]).length||!(e.children||[]).every((function(r,n){return e.children[n].key===t.props.children[n].key}))){for(var r={},n=0;n<e.numCols;n++)r["col-"+n]=[];this.setState(r),this.cancel();var o=this.getTiles(e);this.addTiles(o)}}catch(e){console.warn(e.message)}}},{key:"areArraysEqual",value:function(e,t){return e.length===t.length&&e.sort().every((function(e,r){return e===t.sort()[r]}))}},{key:"getTiles",value:function(e){var t=[];return e.imageUrls?t=e.imageUrls.map((function(e,t){return o.default.createElement("img",{src:e,alt:e,key:"img-"+t+Date.now(),style:{border:"2px solid transparent",boxSizing:"border-box"}})})):e.children?t=e.children:console.warn("No images were passed into react-image-masonry"),t}},{key:"getAllImageUrls",value:function(e){var t=this;if(!e)return[];if("img"===e.type)return[e.props.src];var r=!!e.props&&e.props.children;if(r){var n=[];return o.default.Children.forEach(r,(function(e){n=n.concat(t.getAllImageUrls(e))})),n}return[]}},{key:"loadImages",value:function(e){var t=this,r=[];return e.forEach((function(e){r.push(new Promise((function(r,n){var o=new Image;o.onload=r,o.onerror=n,o.src=e,t.cancel=function(){o.src=""}})))})),Promise.all(r)}},{key:"getShortestCol",value:function(e){var t=e.querySelectorAll(".react-image-masonry-col"),r=0;return t.forEach((function(e,n){e.offsetHeight<t[r].offsetHeight&&(r=n)})),r}},{key:"addTiles",value:function(e){var t=this;e.forEach((function(e,r){if(e){var n={};(!t.props.hasOwnProperty("animate")||t.props.animate)&&(n.animation="fadeIn 1s ease-in"),t.props.forceOrder&&(n.order=r),e&&e.props&&e.props.style&&(n=Object.assign({},e.props.style,n)),e=o.default.cloneElement(e,{style:n});var a=t.getAllImageUrls(e);t.loadImages(a).then((function(){var r=t.refs.container;if(r){var n=t.getShortestCol(r);t.setState(function(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}({},"col-"+n,t.state["col-"+n].concat([e])))}})).catch((function(e){console.error(e)}))}}))}}]),t}(o.default.Component);t.default=a}]);export default t;
//# sourceMappingURL=index.js.map
