// snippets/CoreWebVitals/CLS.js | sha256:738b86913a0a20f5 | https://github.com/nucliweb/webperf-snippets/blob/main/snippets/CoreWebVitals/CLS.js (async()=>{if(!PerformanceObserver.supportedEntryTypes?.includes("layout-shift"))return{script:"CLS",status:"unsupported",error:"layout-shift entries not supported in this browser"};let e=0,t=0,r=null,s=null;const o=o=>{o.hadRecentInput||(s&&o.startTime-s.startTime<1e3&&o.startTime-r.startTime<5e3?t+=o.value:(t=o.value,r=o),s=o,e=Math.max(e,t))},n=e=>e<=.1?"good":e<=.25?"needs-improvement":"poor",i=()=>{n(e)},a=new PerformanceObserver(e=>{for(const t of e.getEntries())o(t);i()});a.observe({type:"layout-shift",buffered:!0}),document.addEventListener("visibilitychange",()=>{if("hidden"===document.visibilityState){for(const e of a.takeRecords())o(e);i()}}),window.getCLS=()=>{i();const t=n(e);return{script:"CLS",status:"ok",metric:"CLS",value:Math.round(1e4*e)/1e4,unit:"score",rating:t,thresholds:{good:.1,needsImprovement:.25}}},await new Promise(e=>setTimeout(e,100));const u=e,d=n(u);return{script:"CLS",status:"ok",metric:"CLS",value:Math.round(1e4*u)/1e4,unit:"score",rating:d,thresholds:{good:.1,needsImprovement:.25},message:"CLS tracking active. Call getCLS() for updated value after page interactions.",getDataFn:"getCLS"}})();