export const name="Image Prioritizer";const externalBackgroundImages=[];export async function initialize({log:e,onLCP:n}){const t=e||console.log;n((e=>{handleLCPMetric(e,t)}),{reportAllChanges:!0})}function handleLCPMetric(e,n){for(const t of e.entries){if(!t.url||!(t.element instanceof HTMLElement)||t.element instanceof HTMLImageElement||t.element instanceof HTMLVideoElement)continue;if(t.url.startsWith("data:"))continue;if(t.element.style.backgroundImage)continue;if(t.url.length>500)return void n(`Skipping very long URL: ${t.url}`);if(t.element.tagName.length>100)return void n(`Skipping very long tag name: ${t.element.tagName}`);const e=t.element.getAttribute("id");if("string"==typeof e&&e.length>100)return void n(`Skipping very long ID: ${e}`);const o=t.element.getAttribute("class");if("string"==typeof o&&o.length>500)return void n(`Skipping very long className: ${o}`);const a={url:t.url,tag:t.element.tagName,id:e,class:o};n("Detected external LCP background image:",a),externalBackgroundImages.push(a)}}export async function finalize({extendRootData:e,log:n}){const t=n||console.log;if(0===externalBackgroundImages.length)return;const o=externalBackgroundImages.pop();t("Sending external background image for LCP element:",o),e({lcpElementExternalBackgroundImage:o})}