import{c as t}from"./p-f021dfd0.js";import{I as i}from"./p-8ffe7be8.js";class s{constructor(i,s,h){var r;this.el=i,this.attributes=s,this.onLoad=h,this.hasLoaded=!1,t(this.el)||(this.intersectionObs=this.canObserveIntersection()?new IntersectionObserver(this.onIntersection.bind(this)):void 0,this.mutationObs=this.canObserveMutations()?new MutationObserver(this.onMutation.bind(this)):void 0,null===(r=this.mutationObs)||void 0===r||r.observe(this.el,{childList:!0,subtree:!0,attributeFilter:this.attributes}),this.lazyLoad())}didLoad(){return this.hasLoaded}destroy(){var t,i;null===(t=this.intersectionObs)||void 0===t||t.disconnect(),null===(i=this.mutationObs)||void 0===i||i.disconnect()}canObserveIntersection(){return i&&window.IntersectionObserver}canObserveMutations(){return i&&window.MutationObserver}lazyLoad(){var t;this.canObserveIntersection()?null===(t=this.intersectionObs)||void 0===t||t.observe(this.el):this.load()}onIntersection(t){t.forEach((t=>{(t.intersectionRatio>0||t.isIntersecting)&&(this.load(),this.intersectionObs.unobserve(t.target))}))}onMutation(){this.hasLoaded&&this.load()}getLazyElements(){return this.el.querySelectorAll(".lazy")}load(){window.requestAnimationFrame((()=>{this.getLazyElements().forEach(this.loadEl.bind(this))}))}loadEl(t){var i,s;null===(i=this.intersectionObs)||void 0===i||i.unobserve(t),this.hasLoaded=!0,null===(s=this.onLoad)||void 0===s||s.call(this,t)}}export{s as L}