Module 4616

895 characters · in 2ff9999db49bbf4e.js
Dependencies
Lazily required by (0)none
Lazily requires (0)none
Source Raw
function(t,s,e){e.d(s,{A:()=>h});var i=e(477900),n=e(582128),a=e(503698),o=e.n(a),r=e(760328);class d extends n.PureComponent{unmounting=!1;state={loaded:!1};static defaultProps={width:0,height:0,alt:""};constructor(t){super(t),this.initialize()}componentDidUpdate(t){t.src!==this.props.src&&this.setState({loaded:!1},()=>this.initialize())}initialize(){let t;(t=this.props.src,new Promise((s,e)=>{null==t&&e(Error("No image src passed"));let i=new Image;i.src=t,i.onload=()=>s(i),i.onerror=t=>e(t)})).then(()=>{this.unmounting||this.setState({loaded:!0})})}componentWillUnmount(){this.unmounting=!0}render(){let{className:t,src:s,alt:e,width:n,height:a,onLoad:d,style:h,imageClassName:l}=this.props,{loaded:c}=this.state;return(0,i.jsx)("div",{className:t,style:{...h,width:n,height:a},children:(0,i.jsx)("img",{className:o()(r.S,l,{[r.K]:c}),width:n,height:a,src:s,alt:e,onLoad:d})})}}let h=d}