// snippets/Loading/Critical-CSS-Detection.js | sha256:d54510d6c691f440 | https://github.com/nucliweb/webperf-snippets/blob/main/snippets/Loading/Critical-CSS-Detection.js (()=>{function e(e){if(null==e||Number.isNaN(e))return"-";if(0===e)return"0 B";const t=["B","KB","MB","GB"],n=Math.max(0,Math.min(Math.floor(Math.log(e)/Math.log(1024)),t.length-1));return(e/Math.pow(1024,n)).toFixed(1)+" "+t[n]}const t=14336,n=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(e=>e.href&&!e.disabled),r=performance.getEntriesByType("resource").filter(e=>!e.name.endsWith("#webperf-snippets")),i=n.map(e=>{const t=e.href,n=e.getAttribute("media")||"all",i=r.find(e=>e.name===t);let l;l=i&&void 0!==i.renderBlockingStatus?"blocking"===i.renderBlockingStatus:"all"===n||""===n||"screen"===n||n.toLowerCase().includes("screen")&&!n.toLowerCase().includes("print");const s=i?i.transferSize:0,o=i?i.decodedBodySize:0,d=document.querySelector(`link[rel="preload"][as="style"][href="${t}"]`);let a=0,c=!1;try{const e=Array.from(document.styleSheets).find(e=>e.href===t);e&&e.cssRules&&(a=e.cssRules.length)}catch{c=!0}return{filename:t.split("/").pop().split("?")[0]||t,href:t,media:n,isRenderBlocking:l,transferSize:s,decodedSize:o,ruleCount:a,corsBlocked:c,preloaded:null!==d}}),l=Array.from(document.querySelectorAll("style")).map((e,t)=>{const n=e.innerHTML;return{index:t+1,size:new Blob([n]).size,ruleCount:(n.match(/\{[^}]*\}/g)||[]).length,inHead:null!==e.closest("head")}}),s=i.filter(e=>e.isRenderBlocking),o=i.filter(e=>!e.isRenderBlocking),d=l.reduce((e,t)=>e+t.size,0),a=s.reduce((e,t)=>e+t.decodedSize,0),c=i.reduce((e,t)=>e+t.transferSize,0);if(s.length>0){const e=Math.min(a/t*100,200),n=Math.min(Math.round(e/10),20);"█".repeat(n),"░".repeat(20-n)}l.length>0&&(d/t*100).toFixed(0);const g=[];s.length>0&&0===l.length&&g.push({code:"no-inline-critical-css",severity:"high",message:"No critical CSS inlined: all CSS loads via render-blocking requests",suggestion:"Extract above-the-fold styles into a