(()=>{"use strict";class e{constructor(e={}){this.config={lazyOffset:50,imageQuality:85,placeholder:{color:"#F1F1F1",blurHashLevel:4},screens:{sm:640,md:768,lg:1024,xl:1280,"2xl":1536},cdnUrl:e.cdnUrl||"",...e},this.processedImages=new WeakSet,this.processedVideos=new WeakSet,this.init()}init(){this.processLCPElements(),"complete"===document.readyState?this.setupLazyLoading():window.addEventListener("load",(()=>this.setupLazyLoading()))}processLCPElements(){this.identifyLCPElements().forEach((e=>{"IMG"===e.tagName?this.processLCPImage(e):"H1"===e.tagName||"H2"===e.tagName?this.optimizeHeading(e):e.hasAttribute("data-frontis-bg")&&this.processLCPBackground(e)}))}identifyLCPElements(){const e=[],t=document.querySelector("h1, h2");t&&e.push(t);const s=document.querySelector(".hero img, .banner img, header img");s&&e.push(s);const i=Array.from(document.querySelectorAll("img")).filter((e=>{const t=e.getBoundingClientRect();return t.top<window.innerHeight&&t.width>200&&t.height>200}));return e.push(...i),e}async processLCPImage(e){if(this.processedImages.has(e))return;const t=e.getAttribute("src")||e.getAttribute("data-src");if(t)try{const s=document.createElement("link");s.rel="preload",s.as="image",s.href=t,document.head.appendChild(s);const i=await this.getImageSize(t),r=this.getOptimizedUrl(t,{quality:90,width:i.width});e.src=r,e.setAttribute("width",i.width),e.setAttribute("height",i.height),e.style.aspectRatio=`${i.width} / ${i.height}`,e.setAttribute("fetchpriority","high"),this.processedImages.add(e)}catch(e){console.warn("Frontis: Error processing LCP image:",e)}}optimizeHeading(e){e.style.display="block";const t=document.createElement("style");t.textContent=`\n      ${e.tagName.toLowerCase()} {\n        font-display: swap !important;\n      }\n    `,document.head.appendChild(t)}async processLCPBackground(e){if(this.processedImages.has(e))return;const t=e.getAttribute("data-frontis-bg")||this.getBgImageUrl(e);if(t)try{const s=document.createElement("link");s.rel="preload",s.as="image",s.href=t,document.head.appendChild(s);const i=this.getOptimizedUrl(t,{quality:90});e.style.backgroundImage=`url("${i}")`,this.processedImages.add(e)}catch(e){console.warn("Frontis: Error processing LCP background:",e)}}setupLazyLoading(){this.setupObserver(),this.processImages(),this.processVideos(),this.watchDOM()}}new e({lazyOffset:100,placeholder:{color:"#E2E2E2",blurHashLevel:4}})})();