1 |
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).webVitals=e.webVitals||{})}(this,(function(e){"use strict";var t=function(e,t){return{name:e,value:void 0===t?-1:t,delta:0,entries:[],id:"v1-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12)}},n=function(e,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){if("first-input"===e&&!("PerformanceEventTiming"in self))return;var n=new PerformanceObserver((function(e){return e.getEntries().map(t)}));return n.observe({type:e,buffered:!0}),n}}catch(e){}},i=function(e,t){var n=function n(i){"pagehide"!==i.type&&"hidden"!==document.visibilityState||(e(i),t&&(removeEventListener("visibilitychange",n,!0),removeEventListener("pagehide",n,!0)))};addEventListener("visibilitychange",n,!0),addEventListener("pagehide",n,!0)},a=function(e){addEventListener("pageshow",(function(t){t.persisted&&e(t)}),!0)},r="function"==typeof WeakSet?new WeakSet:new Set,o=function(e,t,n){var i;return function(){t.value>=0&&(n||r.has(t)||"hidden"===document.visibilityState)&&(t.delta=t.value-(i||0),(t.delta||void 0===i)&&(i=t.value,e(t)))}},u=-1,s=function(){i((function(e){var t=e.timeStamp;u=t}),!0)},c=function(){return u<0&&((u=self.webVitals.firstHiddenTime)===1/0&&s(),a((function(){setTimeout((function(){u="hidden"===document.visibilityState?0:1/0,s()}),0)}))),{get timeStamp(){return u}}};e.getCLS=function(e,r){var u,s=t("CLS",0),c=function(e){e.hadRecentInput||(s.value+=e.value,s.entries.push(e),u())},f=n("layout-shift",c);f&&(u=o(e,s,r),i((function(){f.takeRecords().map(c),u()})),a((function(){s=t("CLS",0),u=o(e,s,r)})))},e.getFCP=function(e,i){var u,s=c(),f=t("FCP"),d=function(e){"first-contentful-paint"===e.name&&(l&&l.disconnect(),e.startTime<s.timeStamp&&(f.value=e.startTime,f.entries.push(e),r.add(f),u()))},m=performance.getEntriesByName("first-contentful-paint")[0],l=m?null:n("paint",d);(m||l)&&(u=o(e,f,i),m&&d(m),a((function(n){f=t("FCP"),u=o(e,f,i),requestAnimationFrame((function(){requestAnimationFrame((function(){f.value=performance.now()-n.timeStamp,r.add(f),u()}))}))})))},e.getFID=function(e,u){var s,f=c(),d=t("FID"),m=function(e){e.startTime<f.timeStamp&&(d.value=e.processingStart-e.startTime,d.entries.push(e),r.add(d),s())},l=n("first-input",m);s=o(e,d,u),l&&i((function(){l.takeRecords().map(m),l.disconnect()}),!0),l||window.webVitals.firstInputPolyfill(m),a((function(){d=t("FID"),s=o(e,d,u),window.webVitals.resetFirstInputPolyfill(),window.webVitals.firstInputPolyfill(m)}))},e.getLCP=function(e,u){var s,f=c(),d=t("LCP"),m=function(e){var t=e.startTime;t<f.timeStamp&&(d.value=t,d.entries.push(e)),s()},l=n("largest-contentful-paint",m);if(l){s=o(e,d,u);var p=function(){r.has(d)||(l.takeRecords().map(m),l.disconnect(),r.add(d),s())};["keydown","click"].forEach((function(e){addEventListener(e,p,{once:!0,capture:!0})})),i(p,!0),a((function(n){d=t("LCP"),s=o(e,d,u),requestAnimationFrame((function(){requestAnimationFrame((function(){d.value=performance.now()-n.timeStamp,r.add(d),s()}))}))}))}},e.getTTFB=function(e){var n,i=t("TTFB");n=function(){try{var t=performance.getEntriesByType("navigation")[0]||function(){var e=performance.timing,t={entryType:"navigation",startTime:0};for(var n in e)"navigationStart"!==n&&"toJSON"!==n&&(t[n]=Math.max(e[n]-e.navigationStart,0));return t}();if(i.value=i.delta=t.responseStart,i.value<0)return;i.entries=[t],e(i)}catch(e){}},"complete"===document.readyState?setTimeout(n,0):addEventListener("pageshow",n)},Object.defineProperty(e,"__esModule",{value:!0})}));
|