(function(n,s){typeof exports=="object"&&typeof module<"u"?module.exports=s(require("react")):typeof define=="function"&&define.amd?define(["react"],s):(n=typeof globalThis<"u"?globalThis:n||self,n.LazyLoad=s(n.React))})(this,function(n){"use strict";var w=Object.defineProperty;var L=(n,s,l)=>s in n?w(n,s,{enumerable:!0,configurable:!0,writable:!0,value:l}):n[s]=l;var u=(n,s,l)=>(L(n,typeof s!="symbol"?s+"":s,l),l);const l=(t=>t&&typeof t=="object"&&"default"in t?t:{default:t})(n),f=(t,o)=>typeof getComputedStyle<"u"?getComputedStyle(t,null).getPropertyValue(o):t.style.getPropertyValue(o),m=t=>f(t,"overflow")+f(t,"overflow-y")+f(t,"overflow-x"),y=t=>{if(!(t instanceof HTMLElement))return window;let o=t;for(;o&&!(o===document.body||o===document.documentElement||!o.parentNode);){if(/(scroll|auto)/.test(m(o)))return o;o=o.parentNode}return window};class h extends n.Component{constructor(e){super(e);u(this,"elementObserver");u(this,"wrapper");u(this,"lazyLoadHandler",e=>{var a,d;const{onContentVisible:r}=this.props,[i]=e,{isIntersecting:c}=i;if(c){this.setState({visible:!0},()=>{r&&r()});const p=(a=this.wrapper)==null?void 0:a.current;p&&p instanceof HTMLElement&&((d=this.elementObserver)==null||d.unobserve(p))}});this.elementObserver=null,this.wrapper=l.default.createRef(),this.state={visible:!1}}componentDidMount(){var a;this.getEventNode();const{offset:e,threshold:r}=this.props,i={rootMargin:typeof e=="number"?`${e}px`:e||"0px",threshold:r||0};this.elementObserver=new IntersectionObserver(this.lazyLoadHandler,i);const c=(a=this.wrapper)==null?void 0:a.current;c instanceof HTMLElement&&this.elementObserver.observe(c)}shouldComponentUpdate(e,r){return r.visible}componentWillUnmount(){var r,i;const e=(r=this.wrapper)==null?void 0:r.current;e&&e instanceof HTMLElement&&((i=this.elementObserver)==null||i.unobserve(e))}getEventNode(){var e;return y((e=this.wrapper)==null?void 0:e.current)}render(){const{children:e,className:r,height:i,width:c,elementType:a}=this.props,{visible:d}=this.state,p={height:i,width:c},v=`LazyLoad${d?" is-visible":""}${r?` ${r}`:""}`,b=a||"div";return n.createElement(b,{className:v,style:p,ref:this.wrapper},d&&n.Children.only(e))}}return u(h,"defaultProps",{elementType:"div",className:"",offset:0,threshold:0,width:null,onContentVisible:null,height:null}),h});