/*! Built with http://stenciljs.com */
import{h}from"./webcomponents.core.js";var LazyImg=function(){function e(){}return e.prototype.componentDidLoad=function(){this.addIntersectionObserver()},e.prototype.componentWillUpdate=function(){this.src!==this.oldSrc&&this.addIntersectionObserver(),this.oldSrc=this.src},e.prototype.handleImage=function(){var e=this.el.shadowRoot.querySelector("img");e.setAttribute("src",e.getAttribute("data-src")),e.onload=function(){e.removeAttribute("data-src")}},e.prototype.addIntersectionObserver=function(){var e=this;this.src&&("IntersectionObserver"in window?(this.io=new IntersectionObserver(function(t){t[0].isIntersecting&&(e.handleImage(),e.removeIntersectionObserver())}),this.io.observe(this.el.shadowRoot.querySelector("img"))):this.handleImage())},e.prototype.removeIntersectionObserver=function(){this.io&&(this.io.disconnect(),this.io=null)},e.prototype.render=function(){return h("img",{"data-src":this.src,alt:this.alt})},Object.defineProperty(e,"is",{get:function(){return"ema-lazy-img"},enumerable:!0,configurable:!0}),Object.defineProperty(e,"encapsulation",{get:function(){return"shadow"},enumerable:!0,configurable:!0}),Object.defineProperty(e,"properties",{get:function(){return{alt:{type:String,attr:"alt"},el:{elementRef:!0},oldSrc:{state:!0},src:{type:String,attr:"src"}}},enumerable:!0,configurable:!0}),Object.defineProperty(e,"style",{get:function(){return":host{display:block}img{max-width:100%}"},enumerable:!0,configurable:!0}),e}();export{LazyImg as EmaLazyImg};