web-vitals
Advanced tools
Comparing version 3.0.0-beta.0 to 3.0.0-beta.1
@@ -6,2 +6,2 @@ export { onCLS as getCLS } from './onCLS.js'; | ||
export { onLCP as getLCP } from './onLCP.js'; | ||
export { onTTFB as getTFB } from './onTTFB.js'; | ||
export { onTTFB as getTTFB } from './onTTFB.js'; |
/* | ||
* Copyright 2020 Google LLC | ||
* Copyright 2022 Google LLC | ||
* | ||
@@ -21,2 +21,2 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
export { onLCP as getLCP } from './onLCP.js'; | ||
export { onTTFB as getTFB } from './onTTFB.js'; | ||
export { onTTFB as getTTFB } from './onTTFB.js'; |
@@ -1,2 +0,2 @@ | ||
import { Metric, ReportHandler } from '../types.js'; | ||
export declare const bindReporter: (callback: ReportHandler, metric: Metric, reportAllChanges?: boolean | undefined) => (forceReport?: boolean | undefined) => void; | ||
import { Metric, ReportCallback } from '../types.js'; | ||
export declare const bindReporter: (callback: ReportCallback, metric: Metric, reportAllChanges?: boolean | undefined) => (forceReport?: boolean | undefined) => void; |
@@ -1,2 +0,2 @@ | ||
import { ReportHandler } from './types.js'; | ||
export declare const onCLS: (onReport: ReportHandler, reportAllChanges?: boolean | undefined) => void; | ||
import { ReportCallback, ReportOpts } from './types.js'; | ||
export declare const onCLS: (onReport: ReportCallback, opts?: ReportOpts | undefined) => void; |
@@ -24,3 +24,5 @@ /* | ||
let fcpValue = -1; | ||
export const onCLS = (onReport, reportAllChanges) => { | ||
export const onCLS = (onReport, opts) => { | ||
// Set defaults | ||
opts = opts || {}; | ||
// Start monitoring FCP so we can only report CLS if FCP is also reported. | ||
@@ -74,3 +76,3 @@ // Note: this is done to match the current behavior of CrUX. | ||
if (po) { | ||
report = bindReporter(onReportWrapped, metric, reportAllChanges); | ||
report = bindReporter(onReportWrapped, metric, opts.reportAllChanges); | ||
onHidden(() => { | ||
@@ -84,5 +86,5 @@ handleEntries(po.takeRecords()); | ||
metric = initMetric('CLS', 0); | ||
report = bindReporter(onReportWrapped, metric, reportAllChanges); | ||
report = bindReporter(onReportWrapped, metric, opts.reportAllChanges); | ||
}); | ||
} | ||
}; |
@@ -1,2 +0,2 @@ | ||
import { ReportHandler } from './types.js'; | ||
export declare const onFCP: (onReport: ReportHandler, reportAllChanges?: boolean | undefined) => void; | ||
import { ReportCallback, ReportOpts } from './types.js'; | ||
export declare const onFCP: (onReport: ReportCallback, opts?: ReportOpts | undefined) => void; |
@@ -21,3 +21,5 @@ /* | ||
import { observe } from './lib/observe.js'; | ||
export const onFCP = (onReport, reportAllChanges) => { | ||
export const onFCP = (onReport, opts) => { | ||
// Set defaults | ||
opts = opts || {}; | ||
const visibilityWatcher = getVisibilityWatcher(); | ||
@@ -51,3 +53,3 @@ let metric = initMetric('FCP'); | ||
if (fcpEntry || po) { | ||
report = bindReporter(onReport, metric, reportAllChanges); | ||
report = bindReporter(onReport, metric, opts.reportAllChanges); | ||
if (fcpEntry) { | ||
@@ -58,3 +60,3 @@ handleEntries([fcpEntry]); | ||
metric = initMetric('FCP'); | ||
report = bindReporter(onReport, metric, reportAllChanges); | ||
report = bindReporter(onReport, metric, opts.reportAllChanges); | ||
requestAnimationFrame(() => { | ||
@@ -61,0 +63,0 @@ requestAnimationFrame(() => { |
@@ -1,2 +0,2 @@ | ||
import { ReportHandler } from './types.js'; | ||
export declare const onFID: (onReport: ReportHandler, reportAllChanges?: boolean | undefined) => void; | ||
import { ReportCallback, ReportOpts } from './types.js'; | ||
export declare const onFID: (onReport: ReportCallback, opts?: ReportOpts | undefined) => void; |
@@ -23,3 +23,5 @@ /* | ||
import { firstInputPolyfill, resetFirstInputPolyfill } from './lib/polyfills/firstInputPolyfill.js'; | ||
export const onFID = (onReport, reportAllChanges) => { | ||
export const onFID = (onReport, opts) => { | ||
// Set defaults | ||
opts = opts || {}; | ||
const visibilityWatcher = getVisibilityWatcher(); | ||
@@ -40,3 +42,3 @@ let metric = initMetric('FID'); | ||
const po = observe('first-input', handleEntries); | ||
report = bindReporter(onReport, metric, reportAllChanges); | ||
report = bindReporter(onReport, metric, opts.reportAllChanges); | ||
if (po) { | ||
@@ -55,3 +57,3 @@ onHidden(() => { | ||
metric = initMetric('FID'); | ||
report = bindReporter(onReport, metric, reportAllChanges); | ||
report = bindReporter(onReport, metric, opts.reportAllChanges); | ||
window.webVitals.resetFirstInputPolyfill(); | ||
@@ -66,3 +68,3 @@ window.webVitals.firstInputPolyfill(handleEntry); | ||
metric = initMetric('FID'); | ||
report = bindReporter(onReport, metric, reportAllChanges); | ||
report = bindReporter(onReport, metric, opts.reportAllChanges); | ||
resetFirstInputPolyfill(); | ||
@@ -69,0 +71,0 @@ firstInputPolyfill(handleEntry); |
@@ -1,2 +0,2 @@ | ||
import { ReportHandler } from './types.js'; | ||
export declare const onINP: (onReport: ReportHandler, reportAllChanges?: boolean | undefined) => void; | ||
import { ReportCallback, ReportOpts } from './types.js'; | ||
export declare const onINP: (onReport: ReportCallback, opts?: ReportOpts | undefined) => void; |
@@ -86,3 +86,5 @@ /* | ||
}; | ||
export const onINP = (onReport, reportAllChanges) => { | ||
export const onINP = (onReport, opts) => { | ||
// Set defaults | ||
opts = opts || {}; | ||
// TODO(philipwalton): remove once the polyfill is no longer needed. | ||
@@ -112,5 +114,5 @@ initInteractionCountPolyfill(); | ||
// gained. | ||
durationThreshold: 40, | ||
durationThreshold: opts.durationThreshold || 40, | ||
}); | ||
report = bindReporter(onReport, metric, reportAllChanges); | ||
report = bindReporter(onReport, metric, opts.reportAllChanges); | ||
if (po) { | ||
@@ -133,5 +135,5 @@ onHidden(() => { | ||
metric = initMetric('INP'); | ||
report = bindReporter(onReport, metric, reportAllChanges); | ||
report = bindReporter(onReport, metric, opts.reportAllChanges); | ||
}); | ||
} | ||
}; |
@@ -1,2 +0,2 @@ | ||
import { ReportHandler } from './types.js'; | ||
export declare const onLCP: (onReport: ReportHandler, reportAllChanges?: boolean | undefined) => void; | ||
import { ReportCallback, ReportOpts } from './types.js'; | ||
export declare const onLCP: (onReport: ReportCallback, opts?: ReportOpts | undefined) => void; |
@@ -23,3 +23,5 @@ /* | ||
const reportedMetricIDs = {}; | ||
export const onLCP = (onReport, reportAllChanges) => { | ||
export const onLCP = (onReport, opts) => { | ||
// Set defaults | ||
opts = opts || {}; | ||
const visibilityWatcher = getVisibilityWatcher(); | ||
@@ -45,3 +47,3 @@ let metric = initMetric('LCP'); | ||
if (po) { | ||
report = bindReporter(onReport, metric, reportAllChanges); | ||
report = bindReporter(onReport, metric, opts.reportAllChanges); | ||
const stopListening = () => { | ||
@@ -64,3 +66,3 @@ if (!reportedMetricIDs[metric.id]) { | ||
metric = initMetric('LCP'); | ||
report = bindReporter(onReport, metric, reportAllChanges); | ||
report = bindReporter(onReport, metric, opts.reportAllChanges); | ||
requestAnimationFrame(() => { | ||
@@ -67,0 +69,0 @@ requestAnimationFrame(() => { |
@@ -1,2 +0,2 @@ | ||
import { ReportHandler } from './types.js'; | ||
export declare const onTTFB: (onReport: ReportHandler, reportAllChanges?: boolean | undefined) => void; | ||
import { ReportCallback, ReportOpts } from './types.js'; | ||
export declare const onTTFB: (onReport: ReportCallback, opts?: ReportOpts | undefined) => void; |
@@ -30,5 +30,7 @@ /* | ||
}; | ||
export const onTTFB = (onReport, reportAllChanges) => { | ||
export const onTTFB = (onReport, opts) => { | ||
// Set defaults | ||
opts = opts || {}; | ||
let metric = initMetric('TTFB'); | ||
let report = bindReporter(onReport, metric, reportAllChanges); | ||
let report = bindReporter(onReport, metric, opts.reportAllChanges); | ||
afterLoad(() => { | ||
@@ -50,3 +52,3 @@ const navigationEntry = getNavigationEntry(); | ||
metric = initMetric('TTFB'); | ||
report = bindReporter(onReport, metric, reportAllChanges); | ||
report = bindReporter(onReport, metric, opts.reportAllChanges); | ||
metric.value = performance.now() - event.timeStamp; | ||
@@ -53,0 +55,0 @@ report(true); |
@@ -9,5 +9,9 @@ export interface Metric { | ||
} | ||
export interface ReportHandler { | ||
export interface ReportCallback { | ||
(metric: Metric): void; | ||
} | ||
export interface ReportOpts { | ||
reportAllChanges?: boolean; | ||
durationThreshold?: number; | ||
} | ||
interface PerformanceEntryMap { | ||
@@ -14,0 +18,0 @@ 'navigation': PerformanceNavigationTiming; |
@@ -1,1 +0,1 @@ | ||
!function(n){"use strict";var e,t=!1,i=function(n){addEventListener("pageshow",(function(e){e.persisted&&(t=!0,n(e))}),!0)},r=function(){return window.performance&&(performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]||function(){var n=performance.timing,e={entryType:"navigation",startTime:0};for(var t in n)"navigationStart"!==t&&"toJSON"!==t&&(e[t]=Math.max(n[t]-n.navigationStart,0));return e}())},a=function(n,e){var i=r();return{name:n,value:void 0===e?-1:e,delta:0,entries:[],id:"v2-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:t?"back_forward_cache":i&&i.type}},o=function(n,e,t){try{if(PerformanceObserver.supportedEntryTypes.includes(n)){var i=new PerformanceObserver((function(n){e(n.getEntries())}));return i.observe(Object.assign({type:n,buffered:!0},t||{})),i}}catch(n){}},c=function(n,e){var t=function t(i){"pagehide"!==i.type&&"hidden"!==document.visibilityState||(n(i),e&&(removeEventListener("visibilitychange",t,!0),removeEventListener("pagehide",t,!0)))};addEventListener("visibilitychange",t,!0),addEventListener("pagehide",t,!0)},u=function(n,e,t){var i;return function(r){e.value>=0&&(r||t)&&(e.delta=e.value-(i||0),(e.delta||void 0===i)&&(i=e.value,n(e)))}},f=-1,s=function(){c((function(n){var e=n.timeStamp;f=e}),!0)},d=function(){return f<0&&((f=window.webVitals.firstHiddenTime)===1/0&&s(),i((function(){setTimeout((function(){f="hidden"===document.visibilityState?0:1/0,s()}),0)}))),{get firstHiddenTime(){return f}}},l=function(n,e){var t,r=d(),c=a("FCP"),f=function(n){n.forEach((function(n){"first-contentful-paint"===n.name&&(l&&l.disconnect(),n.startTime<r.firstHiddenTime&&(c.value=n.startTime,c.entries.push(n),t(!0)))}))},s=window.performance&&window.performance.getEntriesByName&&window.performance.getEntriesByName("first-contentful-paint")[0],l=s?null:o("paint",f);(s||l)&&(t=u(n,c,e),s&&f([s]),i((function(i){c=a("FCP"),t=u(n,c,e),requestAnimationFrame((function(){requestAnimationFrame((function(){c.value=performance.now()-i.timeStamp,t(!0)}))}))})))},v=!1,m=-1,p=function(n,e){v||(l((function(n){m=n.value})),v=!0);var t,r=function(e){m>-1&&n(e)},f=a("CLS",0),s=0,d=[],p=function(n){n.forEach((function(n){if(!n.hadRecentInput){var e=d[0],i=d[d.length-1];s&&n.startTime-i.startTime<1e3&&n.startTime-e.startTime<5e3?(s+=n.value,d.push(n)):(s=n.value,d=[n]),s>f.value&&(f.value=s,f.entries=d,t())}}))},h=o("layout-shift",p);h&&(t=u(r,f,e),c((function(){p(h.takeRecords()),t(!0)})),i((function(){s=0,m=-1,f=a("CLS",0),t=u(r,f,e)})))},h=function(n,e){var t,r=d(),f=a("FID"),s=function(n){n.startTime<r.firstHiddenTime&&(f.value=n.processingStart-n.startTime,f.entries.push(n),t(!0))},l=function(n){n.forEach(s)},v=o("first-input",l);t=u(n,f,e),v&&c((function(){l(v.takeRecords()),v.disconnect()}),!0),v||window.webVitals.firstInputPolyfill(s),i((function(){f=a("FID"),t=u(n,f,e),window.webVitals.resetFirstInputPolyfill(),window.webVitals.firstInputPolyfill(s)}))},y=0,g=1/0,T=0,w=function(n){n.forEach((function(n){n.interactionId&&(g=Math.min(g,n.interactionId),T=Math.max(T,n.interactionId),y=T?(T-g)/7+1:0)}))},E=function(){return e?y:performance.interactionCount||0},b=function(){"interactionCount"in performance||e||(e=o("event",w,{type:"event",buffered:!0,durationThreshold:0}))},I=0,P=function(){return E()-I},F=[],S={},L=function(n,e){b();var t,r=a("INP"),f=function(n){n.forEach((function(n){n.interactionId&&function(n){var e=F[F.length-1],t=S[n.interactionId];if(t||F.length<10||n.duration>e.latency){if(t)t.entries.push(n),t.latency=Math.max(t.latency,n.duration);else{var i={id:n.interactionId,latency:n.duration,entries:[n]};S[i.id]=i,F.push(i)}F.sort((function(n,e){return e.latency-n.latency})),F.splice(10).forEach((function(n){delete S[n.id]}))}}(n)}));var e,i=(e=Math.min(F.length-1,Math.floor(P()/50)),F[e]);i&&i.latency!==r.value&&(r.value=i.latency,r.entries=i.entries,t())},s=o("event",f,{durationThreshold:40});t=u(n,r,e),s&&(c((function(){f(s.takeRecords()),r.value<0&&P()>0&&(r.value=0,r.entries=[]),t(!0)})),i((function(){F=[],I=E(),r=a("INP"),t=u(n,r,e)})))},C={},M=function(n,e){var t,r=d(),f=a("LCP"),s=function(n){var e=n[n.length-1];if(e){var i=e.startTime;i<r.firstHiddenTime&&(f.value=i,f.entries=[e],t())}},l=o("largest-contentful-paint",s);if(l){t=u(n,f,e);var v=function(){C[f.id]||(s(l.takeRecords()),l.disconnect(),C[f.id]=!0,t(!0))};["keydown","click"].forEach((function(n){addEventListener(n,v,{once:!0,capture:!0})})),c(v,!0),i((function(i){f=a("LCP"),t=u(n,f,e),requestAnimationFrame((function(){requestAnimationFrame((function(){f.value=performance.now()-i.timeStamp,C[f.id]=!0,t(!0)}))}))}))}},B=function(n,e){var t,o=a("TTFB"),c=u(n,o,e);t=function(){var n=r();if(n){if(o.value=n.responseStart,o.value<0||o.value>performance.now())return;o.entries=[n],c(!0)}},"complete"===document.readyState?setTimeout(t,0):addEventListener("load",(function(){return setTimeout(t,0)})),i((function(t){o=a("TTFB"),c=u(n,o,e),o.value=performance.now()-t.timeStamp,c(!0)}))};n.getCLS=p,n.getFCP=l,n.getFID=h,n.getINP=L,n.getLCP=M,n.getTFB=B,n.onCLS=p,n.onFCP=l,n.onFID=h,n.onINP=L,n.onLCP=M,n.onTTFB=B,Object.defineProperty(n,"__esModule",{value:!0})}(this.webVitals=this.webVitals||{}); | ||
!function(e){"use strict";var n,t=!1,i=function(e){addEventListener("pageshow",(function(n){n.persisted&&(t=!0,e(n))}),!0)},r=function(){return window.performance&&(performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]||function(){var e=performance.timing,n={entryType:"navigation",startTime:0};for(var t in e)"navigationStart"!==t&&"toJSON"!==t&&(n[t]=Math.max(e[t]-e.navigationStart,0));return n}())},a=function(e,n){var i=r();return{name:e,value:void 0===n?-1:n,delta:0,entries:[],id:"v2-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:t?"back_forward_cache":i&&i.type}},o=function(e,n,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var i=new PerformanceObserver((function(e){n(e.getEntries())}));return i.observe(Object.assign({type:e,buffered:!0},t||{})),i}}catch(e){}},c=function(e,n){var t=function t(i){"pagehide"!==i.type&&"hidden"!==document.visibilityState||(e(i),n&&(removeEventListener("visibilitychange",t,!0),removeEventListener("pagehide",t,!0)))};addEventListener("visibilitychange",t,!0),addEventListener("pagehide",t,!0)},u=function(e,n,t){var i;return function(r){n.value>=0&&(r||t)&&(n.delta=n.value-(i||0),(n.delta||void 0===i)&&(i=n.value,e(n)))}},f=-1,s=function(){c((function(e){var n=e.timeStamp;f=n}),!0)},l=function(){return f<0&&((f=window.webVitals.firstHiddenTime)===1/0&&s(),i((function(){setTimeout((function(){f="hidden"===document.visibilityState?0:1/0,s()}),0)}))),{get firstHiddenTime(){return f}}},d=function(e,n){n=n||{};var t,r=l(),c=a("FCP"),f=function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(d&&d.disconnect(),e.startTime<r.firstHiddenTime&&(c.value=e.startTime,c.entries.push(e),t(!0)))}))},s=window.performance&&window.performance.getEntriesByName&&window.performance.getEntriesByName("first-contentful-paint")[0],d=s?null:o("paint",f);(s||d)&&(t=u(e,c,n.reportAllChanges),s&&f([s]),i((function(i){c=a("FCP"),t=u(e,c,n.reportAllChanges),requestAnimationFrame((function(){requestAnimationFrame((function(){c.value=performance.now()-i.timeStamp,t(!0)}))}))})))},v=!1,m=-1,p=function(e,n){n=n||{},v||(d((function(e){m=e.value})),v=!0);var t,r=function(n){m>-1&&e(n)},f=a("CLS",0),s=0,l=[],p=function(e){e.forEach((function(e){if(!e.hadRecentInput){var n=l[0],i=l[l.length-1];s&&e.startTime-i.startTime<1e3&&e.startTime-n.startTime<5e3?(s+=e.value,l.push(e)):(s=e.value,l=[e]),s>f.value&&(f.value=s,f.entries=l,t())}}))},h=o("layout-shift",p);h&&(t=u(r,f,n.reportAllChanges),c((function(){p(h.takeRecords()),t(!0)})),i((function(){s=0,m=-1,f=a("CLS",0),t=u(r,f,n.reportAllChanges)})))},h=function(e,n){n=n||{};var t,r=l(),f=a("FID"),s=function(e){e.startTime<r.firstHiddenTime&&(f.value=e.processingStart-e.startTime,f.entries.push(e),t(!0))},d=function(e){e.forEach(s)},v=o("first-input",d);t=u(e,f,n.reportAllChanges),v&&c((function(){d(v.takeRecords()),v.disconnect()}),!0),v||window.webVitals.firstInputPolyfill(s),i((function(){f=a("FID"),t=u(e,f,n.reportAllChanges),window.webVitals.resetFirstInputPolyfill(),window.webVitals.firstInputPolyfill(s)}))},g=0,y=1/0,T=0,w=function(e){e.forEach((function(e){e.interactionId&&(y=Math.min(y,e.interactionId),T=Math.max(T,e.interactionId),g=T?(T-y)/7+1:0)}))},C=function(){return n?g:performance.interactionCount||0},E=function(){"interactionCount"in performance||n||(n=o("event",w,{type:"event",buffered:!0,durationThreshold:0}))},b=0,I=function(){return C()-b},P=[],F={},A=function(e,n){n=n||{},E();var t,r=a("INP"),f=function(e){e.forEach((function(e){e.interactionId&&function(e){var n=P[P.length-1],t=F[e.interactionId];if(t||P.length<10||e.duration>n.latency){if(t)t.entries.push(e),t.latency=Math.max(t.latency,e.duration);else{var i={id:e.interactionId,latency:e.duration,entries:[e]};F[i.id]=i,P.push(i)}P.sort((function(e,n){return n.latency-e.latency})),P.splice(10).forEach((function(e){delete F[e.id]}))}}(e)}));var n,i=(n=Math.min(P.length-1,Math.floor(I()/50)),P[n]);i&&i.latency!==r.value&&(r.value=i.latency,r.entries=i.entries,t())},s=o("event",f,{durationThreshold:n.durationThreshold||40});t=u(e,r,n.reportAllChanges),s&&(c((function(){f(s.takeRecords()),r.value<0&&I()>0&&(r.value=0,r.entries=[]),t(!0)})),i((function(){P=[],b=C(),r=a("INP"),t=u(e,r,n.reportAllChanges)})))},S={},L=function(e,n){n=n||{};var t,r=l(),f=a("LCP"),s=function(e){var n=e[e.length-1];if(n){var i=n.startTime;i<r.firstHiddenTime&&(f.value=i,f.entries=[n],t())}},d=o("largest-contentful-paint",s);if(d){t=u(e,f,n.reportAllChanges);var v=function(){S[f.id]||(s(d.takeRecords()),d.disconnect(),S[f.id]=!0,t(!0))};["keydown","click"].forEach((function(e){addEventListener(e,v,{once:!0,capture:!0})})),c(v,!0),i((function(i){f=a("LCP"),t=u(e,f,n.reportAllChanges),requestAnimationFrame((function(){requestAnimationFrame((function(){f.value=performance.now()-i.timeStamp,S[f.id]=!0,t(!0)}))}))}))}},M=function(e,n){n=n||{};var t,o=a("TTFB"),c=u(e,o,n.reportAllChanges);t=function(){var e=r();if(e){if(o.value=e.responseStart,o.value<0||o.value>performance.now())return;o.entries=[e],c(!0)}},"complete"===document.readyState?setTimeout(t,0):addEventListener("load",(function(){return setTimeout(t,0)})),i((function(t){o=a("TTFB"),c=u(e,o,n.reportAllChanges),o.value=performance.now()-t.timeStamp,c(!0)}))};e.getCLS=p,e.getFCP=d,e.getFID=h,e.getINP=A,e.getLCP=L,e.getTTFB=M,e.onCLS=p,e.onFCP=d,e.onFID=h,e.onINP=A,e.onLCP=L,e.onTTFB=M,Object.defineProperty(e,"__esModule",{value:!0})}(this.webVitals=this.webVitals||{}); |
@@ -1,1 +0,1 @@ | ||
var n,e=!1,t=function(n){addEventListener("pageshow",(function(t){t.persisted&&(e=!0,n(t))}),!0)},i=function(){return window.performance&&(performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]||function(){var n=performance.timing,e={entryType:"navigation",startTime:0};for(var t in n)"navigationStart"!==t&&"toJSON"!==t&&(e[t]=Math.max(n[t]-n.navigationStart,0));return e}())},a=function(n,t){var a=i();return{name:n,value:void 0===t?-1:t,delta:0,entries:[],id:"v2-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:e?"back_forward_cache":a&&a.type}},r=function(n,e,t){try{if(PerformanceObserver.supportedEntryTypes.includes(n)){var i=new PerformanceObserver((function(n){e(n.getEntries())}));return i.observe(Object.assign({type:n,buffered:!0},t||{})),i}}catch(n){}},o=function(n,e){var t=function t(i){"pagehide"!==i.type&&"hidden"!==document.visibilityState||(n(i),e&&(removeEventListener("visibilitychange",t,!0),removeEventListener("pagehide",t,!0)))};addEventListener("visibilitychange",t,!0),addEventListener("pagehide",t,!0)},c=function(n,e,t){var i;return function(a){e.value>=0&&(a||t)&&(e.delta=e.value-(i||0),(e.delta||void 0===i)&&(i=e.value,n(e)))}},u=-1,f=function(){o((function(n){var e=n.timeStamp;u=e}),!0)},s=function(){return u<0&&((u=window.webVitals.firstHiddenTime)===1/0&&f(),t((function(){setTimeout((function(){u="hidden"===document.visibilityState?0:1/0,f()}),0)}))),{get firstHiddenTime(){return u}}},d=function(n,e){var i,o=s(),u=a("FCP"),f=function(n){n.forEach((function(n){"first-contentful-paint"===n.name&&(l&&l.disconnect(),n.startTime<o.firstHiddenTime&&(u.value=n.startTime,u.entries.push(n),i(!0)))}))},d=window.performance&&window.performance.getEntriesByName&&window.performance.getEntriesByName("first-contentful-paint")[0],l=d?null:r("paint",f);(d||l)&&(i=c(n,u,e),d&&f([d]),t((function(t){u=a("FCP"),i=c(n,u,e),requestAnimationFrame((function(){requestAnimationFrame((function(){u.value=performance.now()-t.timeStamp,i(!0)}))}))})))},l=!1,v=-1,m=function(n,e){l||(d((function(n){v=n.value})),l=!0);var i,u=function(e){v>-1&&n(e)},f=a("CLS",0),s=0,m=[],p=function(n){n.forEach((function(n){if(!n.hadRecentInput){var e=m[0],t=m[m.length-1];s&&n.startTime-t.startTime<1e3&&n.startTime-e.startTime<5e3?(s+=n.value,m.push(n)):(s=n.value,m=[n]),s>f.value&&(f.value=s,f.entries=m,i())}}))},h=r("layout-shift",p);h&&(i=c(u,f,e),o((function(){p(h.takeRecords()),i(!0)})),t((function(){s=0,v=-1,f=a("CLS",0),i=c(u,f,e)})))},p=function(n,e){var i,u=s(),f=a("FID"),d=function(n){n.startTime<u.firstHiddenTime&&(f.value=n.processingStart-n.startTime,f.entries.push(n),i(!0))},l=function(n){n.forEach(d)},v=r("first-input",l);i=c(n,f,e),v&&o((function(){l(v.takeRecords()),v.disconnect()}),!0),v||window.webVitals.firstInputPolyfill(d),t((function(){f=a("FID"),i=c(n,f,e),window.webVitals.resetFirstInputPolyfill(),window.webVitals.firstInputPolyfill(d)}))},h=0,y=1/0,g=0,T=function(n){n.forEach((function(n){n.interactionId&&(y=Math.min(y,n.interactionId),g=Math.max(g,n.interactionId),h=g?(g-y)/7+1:0)}))},w=function(){return n?h:performance.interactionCount||0},E=function(){"interactionCount"in performance||n||(n=r("event",T,{type:"event",buffered:!0,durationThreshold:0}))},I=0,b=function(){return w()-I},S=[],F={},P=function(n,e){E();var i,u=a("INP"),f=function(n){n.forEach((function(n){n.interactionId&&function(n){var e=S[S.length-1],t=F[n.interactionId];if(t||S.length<10||n.duration>e.latency){if(t)t.entries.push(n),t.latency=Math.max(t.latency,n.duration);else{var i={id:n.interactionId,latency:n.duration,entries:[n]};F[i.id]=i,S.push(i)}S.sort((function(n,e){return e.latency-n.latency})),S.splice(10).forEach((function(n){delete F[n.id]}))}}(n)}));var e,t=(e=Math.min(S.length-1,Math.floor(b()/50)),S[e]);t&&t.latency!==u.value&&(u.value=t.latency,u.entries=t.entries,i())},s=r("event",f,{durationThreshold:40});i=c(n,u,e),s&&(o((function(){f(s.takeRecords()),u.value<0&&b()>0&&(u.value=0,u.entries=[]),i(!0)})),t((function(){S=[],I=w(),u=a("INP"),i=c(n,u,e)})))},L={},C=function(n,e){var i,u=s(),f=a("LCP"),d=function(n){var e=n[n.length-1];if(e){var t=e.startTime;t<u.firstHiddenTime&&(f.value=t,f.entries=[e],i())}},l=r("largest-contentful-paint",d);if(l){i=c(n,f,e);var v=function(){L[f.id]||(d(l.takeRecords()),l.disconnect(),L[f.id]=!0,i(!0))};["keydown","click"].forEach((function(n){addEventListener(n,v,{once:!0,capture:!0})})),o(v,!0),t((function(t){f=a("LCP"),i=c(n,f,e),requestAnimationFrame((function(){requestAnimationFrame((function(){f.value=performance.now()-t.timeStamp,L[f.id]=!0,i(!0)}))}))}))}},M=function(n,e){var r,o=a("TTFB"),u=c(n,o,e);r=function(){var n=i();if(n){if(o.value=n.responseStart,o.value<0||o.value>performance.now())return;o.entries=[n],u(!0)}},"complete"===document.readyState?setTimeout(r,0):addEventListener("load",(function(){return setTimeout(r,0)})),t((function(t){o=a("TTFB"),u=c(n,o,e),o.value=performance.now()-t.timeStamp,u(!0)}))};export{m as getCLS,d as getFCP,p as getFID,P as getINP,C as getLCP,M as getTFB,m as onCLS,d as onFCP,p as onFID,P as onINP,C as onLCP,M as onTTFB}; | ||
var e,n=!1,t=function(e){addEventListener("pageshow",(function(t){t.persisted&&(n=!0,e(t))}),!0)},i=function(){return window.performance&&(performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]||function(){var e=performance.timing,n={entryType:"navigation",startTime:0};for(var t in e)"navigationStart"!==t&&"toJSON"!==t&&(n[t]=Math.max(e[t]-e.navigationStart,0));return n}())},r=function(e,t){var r=i();return{name:e,value:void 0===t?-1:t,delta:0,entries:[],id:"v2-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:n?"back_forward_cache":r&&r.type}},a=function(e,n,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var i=new PerformanceObserver((function(e){n(e.getEntries())}));return i.observe(Object.assign({type:e,buffered:!0},t||{})),i}}catch(e){}},o=function(e,n){var t=function t(i){"pagehide"!==i.type&&"hidden"!==document.visibilityState||(e(i),n&&(removeEventListener("visibilitychange",t,!0),removeEventListener("pagehide",t,!0)))};addEventListener("visibilitychange",t,!0),addEventListener("pagehide",t,!0)},c=function(e,n,t){var i;return function(r){n.value>=0&&(r||t)&&(n.delta=n.value-(i||0),(n.delta||void 0===i)&&(i=n.value,e(n)))}},u=-1,f=function(){o((function(e){var n=e.timeStamp;u=n}),!0)},s=function(){return u<0&&((u=window.webVitals.firstHiddenTime)===1/0&&f(),t((function(){setTimeout((function(){u="hidden"===document.visibilityState?0:1/0,f()}),0)}))),{get firstHiddenTime(){return u}}},l=function(e,n){n=n||{};var i,o=s(),u=r("FCP"),f=function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(d&&d.disconnect(),e.startTime<o.firstHiddenTime&&(u.value=e.startTime,u.entries.push(e),i(!0)))}))},l=window.performance&&window.performance.getEntriesByName&&window.performance.getEntriesByName("first-contentful-paint")[0],d=l?null:a("paint",f);(l||d)&&(i=c(e,u,n.reportAllChanges),l&&f([l]),t((function(t){u=r("FCP"),i=c(e,u,n.reportAllChanges),requestAnimationFrame((function(){requestAnimationFrame((function(){u.value=performance.now()-t.timeStamp,i(!0)}))}))})))},d=!1,v=-1,m=function(e,n){n=n||{},d||(l((function(e){v=e.value})),d=!0);var i,u=function(n){v>-1&&e(n)},f=r("CLS",0),s=0,m=[],p=function(e){e.forEach((function(e){if(!e.hadRecentInput){var n=m[0],t=m[m.length-1];s&&e.startTime-t.startTime<1e3&&e.startTime-n.startTime<5e3?(s+=e.value,m.push(e)):(s=e.value,m=[e]),s>f.value&&(f.value=s,f.entries=m,i())}}))},h=a("layout-shift",p);h&&(i=c(u,f,n.reportAllChanges),o((function(){p(h.takeRecords()),i(!0)})),t((function(){s=0,v=-1,f=r("CLS",0),i=c(u,f,n.reportAllChanges)})))},p=function(e,n){n=n||{};var i,u=s(),f=r("FID"),l=function(e){e.startTime<u.firstHiddenTime&&(f.value=e.processingStart-e.startTime,f.entries.push(e),i(!0))},d=function(e){e.forEach(l)},v=a("first-input",d);i=c(e,f,n.reportAllChanges),v&&o((function(){d(v.takeRecords()),v.disconnect()}),!0),v||window.webVitals.firstInputPolyfill(l),t((function(){f=r("FID"),i=c(e,f,n.reportAllChanges),window.webVitals.resetFirstInputPolyfill(),window.webVitals.firstInputPolyfill(l)}))},h=0,g=1/0,y=0,T=function(e){e.forEach((function(e){e.interactionId&&(g=Math.min(g,e.interactionId),y=Math.max(y,e.interactionId),h=y?(y-g)/7+1:0)}))},w=function(){return e?h:performance.interactionCount||0},C=function(){"interactionCount"in performance||e||(e=a("event",T,{type:"event",buffered:!0,durationThreshold:0}))},E=0,A=function(){return w()-E},I=[],b={},S=function(e,n){n=n||{},C();var i,u=r("INP"),f=function(e){e.forEach((function(e){e.interactionId&&function(e){var n=I[I.length-1],t=b[e.interactionId];if(t||I.length<10||e.duration>n.latency){if(t)t.entries.push(e),t.latency=Math.max(t.latency,e.duration);else{var i={id:e.interactionId,latency:e.duration,entries:[e]};b[i.id]=i,I.push(i)}I.sort((function(e,n){return n.latency-e.latency})),I.splice(10).forEach((function(e){delete b[e.id]}))}}(e)}));var n,t=(n=Math.min(I.length-1,Math.floor(A()/50)),I[n]);t&&t.latency!==u.value&&(u.value=t.latency,u.entries=t.entries,i())},s=a("event",f,{durationThreshold:n.durationThreshold||40});i=c(e,u,n.reportAllChanges),s&&(o((function(){f(s.takeRecords()),u.value<0&&A()>0&&(u.value=0,u.entries=[]),i(!0)})),t((function(){I=[],E=w(),u=r("INP"),i=c(e,u,n.reportAllChanges)})))},F={},P=function(e,n){n=n||{};var i,u=s(),f=r("LCP"),l=function(e){var n=e[e.length-1];if(n){var t=n.startTime;t<u.firstHiddenTime&&(f.value=t,f.entries=[n],i())}},d=a("largest-contentful-paint",l);if(d){i=c(e,f,n.reportAllChanges);var v=function(){F[f.id]||(l(d.takeRecords()),d.disconnect(),F[f.id]=!0,i(!0))};["keydown","click"].forEach((function(e){addEventListener(e,v,{once:!0,capture:!0})})),o(v,!0),t((function(t){f=r("LCP"),i=c(e,f,n.reportAllChanges),requestAnimationFrame((function(){requestAnimationFrame((function(){f.value=performance.now()-t.timeStamp,F[f.id]=!0,i(!0)}))}))}))}},L=function(e,n){n=n||{};var a,o=r("TTFB"),u=c(e,o,n.reportAllChanges);a=function(){var e=i();if(e){if(o.value=e.responseStart,o.value<0||o.value>performance.now())return;o.entries=[e],u(!0)}},"complete"===document.readyState?setTimeout(a,0):addEventListener("load",(function(){return setTimeout(a,0)})),t((function(t){o=r("TTFB"),u=c(e,o,n.reportAllChanges),o.value=performance.now()-t.timeStamp,u(!0)}))};export{m as getCLS,l as getFCP,p as getFID,S as getINP,P as getLCP,L as getTTFB,m as onCLS,l as onFCP,p as onFID,S as onINP,P as onLCP,L as onTTFB}; |
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).webVitals=e.webVitals||{})}(this,(function(e){"use strict";var n,t=!1,i=function(e){addEventListener("pageshow",(function(n){n.persisted&&(t=!0,e(n))}),!0)},r=function(){return window.performance&&(performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]||function(){var e=performance.timing,n={entryType:"navigation",startTime:0};for(var t in e)"navigationStart"!==t&&"toJSON"!==t&&(n[t]=Math.max(e[t]-e.navigationStart,0));return n}())},a=function(e,n){var i=r();return{name:e,value:void 0===n?-1:n,delta:0,entries:[],id:"v2-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:t?"back_forward_cache":i&&i.type}},o=function(e,n,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var i=new PerformanceObserver((function(e){n(e.getEntries())}));return i.observe(Object.assign({type:e,buffered:!0},t||{})),i}}catch(e){}},c=function(e,n){var t=function t(i){"pagehide"!==i.type&&"hidden"!==document.visibilityState||(e(i),n&&(removeEventListener("visibilitychange",t,!0),removeEventListener("pagehide",t,!0)))};addEventListener("visibilitychange",t,!0),addEventListener("pagehide",t,!0)},u=function(e,n,t){var i;return function(r){n.value>=0&&(r||t)&&(n.delta=n.value-(i||0),(n.delta||void 0===i)&&(i=n.value,e(n)))}},f=-1,s=function(){c((function(e){var n=e.timeStamp;f=n}),!0)},d=function(){return f<0&&((f=window.webVitals.firstHiddenTime)===1/0&&s(),i((function(){setTimeout((function(){f="hidden"===document.visibilityState?0:1/0,s()}),0)}))),{get firstHiddenTime(){return f}}},l=function(e,n){var t,r=d(),c=a("FCP"),f=function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(l&&l.disconnect(),e.startTime<r.firstHiddenTime&&(c.value=e.startTime,c.entries.push(e),t(!0)))}))},s=window.performance&&window.performance.getEntriesByName&&window.performance.getEntriesByName("first-contentful-paint")[0],l=s?null:o("paint",f);(s||l)&&(t=u(e,c,n),s&&f([s]),i((function(i){c=a("FCP"),t=u(e,c,n),requestAnimationFrame((function(){requestAnimationFrame((function(){c.value=performance.now()-i.timeStamp,t(!0)}))}))})))},v=!1,m=-1,p=function(e,n){v||(l((function(e){m=e.value})),v=!0);var t,r=function(n){m>-1&&e(n)},f=a("CLS",0),s=0,d=[],p=function(e){e.forEach((function(e){if(!e.hadRecentInput){var n=d[0],i=d[d.length-1];s&&e.startTime-i.startTime<1e3&&e.startTime-n.startTime<5e3?(s+=e.value,d.push(e)):(s=e.value,d=[e]),s>f.value&&(f.value=s,f.entries=d,t())}}))},h=o("layout-shift",p);h&&(t=u(r,f,n),c((function(){p(h.takeRecords()),t(!0)})),i((function(){s=0,m=-1,f=a("CLS",0),t=u(r,f,n)})))},h=function(e,n){var t,r=d(),f=a("FID"),s=function(e){e.startTime<r.firstHiddenTime&&(f.value=e.processingStart-e.startTime,f.entries.push(e),t(!0))},l=function(e){e.forEach(s)},v=o("first-input",l);t=u(e,f,n),v&&c((function(){l(v.takeRecords()),v.disconnect()}),!0),v||window.webVitals.firstInputPolyfill(s),i((function(){f=a("FID"),t=u(e,f,n),window.webVitals.resetFirstInputPolyfill(),window.webVitals.firstInputPolyfill(s)}))},y=0,g=1/0,T=0,w=function(e){e.forEach((function(e){e.interactionId&&(g=Math.min(g,e.interactionId),T=Math.max(T,e.interactionId),y=T?(T-g)/7+1:0)}))},b=function(){return n?y:performance.interactionCount||0},E=function(){"interactionCount"in performance||n||(n=o("event",w,{type:"event",buffered:!0,durationThreshold:0}))},I=0,P=function(){return b()-I},F=[],S={},L=function(e,n){E();var t,r=a("INP"),f=function(e){e.forEach((function(e){e.interactionId&&function(e){var n=F[F.length-1],t=S[e.interactionId];if(t||F.length<10||e.duration>n.latency){if(t)t.entries.push(e),t.latency=Math.max(t.latency,e.duration);else{var i={id:e.interactionId,latency:e.duration,entries:[e]};S[i.id]=i,F.push(i)}F.sort((function(e,n){return n.latency-e.latency})),F.splice(10).forEach((function(e){delete S[e.id]}))}}(e)}));var n,i=(n=Math.min(F.length-1,Math.floor(P()/50)),F[n]);i&&i.latency!==r.value&&(r.value=i.latency,r.entries=i.entries,t())},s=o("event",f,{durationThreshold:40});t=u(e,r,n),s&&(c((function(){f(s.takeRecords()),r.value<0&&P()>0&&(r.value=0,r.entries=[]),t(!0)})),i((function(){F=[],I=b(),r=a("INP"),t=u(e,r,n)})))},C={},M=function(e,n){var t,r=d(),f=a("LCP"),s=function(e){var n=e[e.length-1];if(n){var i=n.startTime;i<r.firstHiddenTime&&(f.value=i,f.entries=[n],t())}},l=o("largest-contentful-paint",s);if(l){t=u(e,f,n);var v=function(){C[f.id]||(s(l.takeRecords()),l.disconnect(),C[f.id]=!0,t(!0))};["keydown","click"].forEach((function(e){addEventListener(e,v,{once:!0,capture:!0})})),c(v,!0),i((function(i){f=a("LCP"),t=u(e,f,n),requestAnimationFrame((function(){requestAnimationFrame((function(){f.value=performance.now()-i.timeStamp,C[f.id]=!0,t(!0)}))}))}))}},B=function(e,n){var t,o=a("TTFB"),c=u(e,o,n);t=function(){var e=r();if(e){if(o.value=e.responseStart,o.value<0||o.value>performance.now())return;o.entries=[e],c(!0)}},"complete"===document.readyState?setTimeout(t,0):addEventListener("load",(function(){return setTimeout(t,0)})),i((function(t){o=a("TTFB"),c=u(e,o,n),o.value=performance.now()-t.timeStamp,c(!0)}))};e.getCLS=p,e.getFCP=l,e.getFID=h,e.getINP=L,e.getLCP=M,e.getTFB=B,e.onCLS=p,e.onFCP=l,e.onFID=h,e.onINP=L,e.onLCP=M,e.onTTFB=B,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).webVitals=e.webVitals||{})}(this,(function(e){"use strict";var n,t=!1,i=function(e){addEventListener("pageshow",(function(n){n.persisted&&(t=!0,e(n))}),!0)},r=function(){return window.performance&&(performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]||function(){var e=performance.timing,n={entryType:"navigation",startTime:0};for(var t in e)"navigationStart"!==t&&"toJSON"!==t&&(n[t]=Math.max(e[t]-e.navigationStart,0));return n}())},a=function(e,n){var i=r();return{name:e,value:void 0===n?-1:n,delta:0,entries:[],id:"v2-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:t?"back_forward_cache":i&&i.type}},o=function(e,n,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var i=new PerformanceObserver((function(e){n(e.getEntries())}));return i.observe(Object.assign({type:e,buffered:!0},t||{})),i}}catch(e){}},c=function(e,n){var t=function t(i){"pagehide"!==i.type&&"hidden"!==document.visibilityState||(e(i),n&&(removeEventListener("visibilitychange",t,!0),removeEventListener("pagehide",t,!0)))};addEventListener("visibilitychange",t,!0),addEventListener("pagehide",t,!0)},u=function(e,n,t){var i;return function(r){n.value>=0&&(r||t)&&(n.delta=n.value-(i||0),(n.delta||void 0===i)&&(i=n.value,e(n)))}},f=-1,s=function(){c((function(e){var n=e.timeStamp;f=n}),!0)},l=function(){return f<0&&((f=window.webVitals.firstHiddenTime)===1/0&&s(),i((function(){setTimeout((function(){f="hidden"===document.visibilityState?0:1/0,s()}),0)}))),{get firstHiddenTime(){return f}}},d=function(e,n){n=n||{};var t,r=l(),c=a("FCP"),f=function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(d&&d.disconnect(),e.startTime<r.firstHiddenTime&&(c.value=e.startTime,c.entries.push(e),t(!0)))}))},s=window.performance&&window.performance.getEntriesByName&&window.performance.getEntriesByName("first-contentful-paint")[0],d=s?null:o("paint",f);(s||d)&&(t=u(e,c,n.reportAllChanges),s&&f([s]),i((function(i){c=a("FCP"),t=u(e,c,n.reportAllChanges),requestAnimationFrame((function(){requestAnimationFrame((function(){c.value=performance.now()-i.timeStamp,t(!0)}))}))})))},p=!1,v=-1,m=function(e,n){n=n||{},p||(d((function(e){v=e.value})),p=!0);var t,r=function(n){v>-1&&e(n)},f=a("CLS",0),s=0,l=[],m=function(e){e.forEach((function(e){if(!e.hadRecentInput){var n=l[0],i=l[l.length-1];s&&e.startTime-i.startTime<1e3&&e.startTime-n.startTime<5e3?(s+=e.value,l.push(e)):(s=e.value,l=[e]),s>f.value&&(f.value=s,f.entries=l,t())}}))},h=o("layout-shift",m);h&&(t=u(r,f,n.reportAllChanges),c((function(){m(h.takeRecords()),t(!0)})),i((function(){s=0,v=-1,f=a("CLS",0),t=u(r,f,n.reportAllChanges)})))},h=function(e,n){n=n||{};var t,r=l(),f=a("FID"),s=function(e){e.startTime<r.firstHiddenTime&&(f.value=e.processingStart-e.startTime,f.entries.push(e),t(!0))},d=function(e){e.forEach(s)},p=o("first-input",d);t=u(e,f,n.reportAllChanges),p&&c((function(){d(p.takeRecords()),p.disconnect()}),!0),p||window.webVitals.firstInputPolyfill(s),i((function(){f=a("FID"),t=u(e,f,n.reportAllChanges),window.webVitals.resetFirstInputPolyfill(),window.webVitals.firstInputPolyfill(s)}))},g=0,y=1/0,T=0,w=function(e){e.forEach((function(e){e.interactionId&&(y=Math.min(y,e.interactionId),T=Math.max(T,e.interactionId),g=T?(T-y)/7+1:0)}))},C=function(){return n?g:performance.interactionCount||0},b=function(){"interactionCount"in performance||n||(n=o("event",w,{type:"event",buffered:!0,durationThreshold:0}))},E=0,I=function(){return C()-E},P=[],F={},A=function(e,n){n=n||{},b();var t,r=a("INP"),f=function(e){e.forEach((function(e){e.interactionId&&function(e){var n=P[P.length-1],t=F[e.interactionId];if(t||P.length<10||e.duration>n.latency){if(t)t.entries.push(e),t.latency=Math.max(t.latency,e.duration);else{var i={id:e.interactionId,latency:e.duration,entries:[e]};F[i.id]=i,P.push(i)}P.sort((function(e,n){return n.latency-e.latency})),P.splice(10).forEach((function(e){delete F[e.id]}))}}(e)}));var n,i=(n=Math.min(P.length-1,Math.floor(I()/50)),P[n]);i&&i.latency!==r.value&&(r.value=i.latency,r.entries=i.entries,t())},s=o("event",f,{durationThreshold:n.durationThreshold||40});t=u(e,r,n.reportAllChanges),s&&(c((function(){f(s.takeRecords()),r.value<0&&I()>0&&(r.value=0,r.entries=[]),t(!0)})),i((function(){P=[],E=C(),r=a("INP"),t=u(e,r,n.reportAllChanges)})))},S={},L=function(e,n){n=n||{};var t,r=l(),f=a("LCP"),s=function(e){var n=e[e.length-1];if(n){var i=n.startTime;i<r.firstHiddenTime&&(f.value=i,f.entries=[n],t())}},d=o("largest-contentful-paint",s);if(d){t=u(e,f,n.reportAllChanges);var p=function(){S[f.id]||(s(d.takeRecords()),d.disconnect(),S[f.id]=!0,t(!0))};["keydown","click"].forEach((function(e){addEventListener(e,p,{once:!0,capture:!0})})),c(p,!0),i((function(i){f=a("LCP"),t=u(e,f,n.reportAllChanges),requestAnimationFrame((function(){requestAnimationFrame((function(){f.value=performance.now()-i.timeStamp,S[f.id]=!0,t(!0)}))}))}))}},M=function(e,n){n=n||{};var t,o=a("TTFB"),c=u(e,o,n.reportAllChanges);t=function(){var e=r();if(e){if(o.value=e.responseStart,o.value<0||o.value>performance.now())return;o.entries=[e],c(!0)}},"complete"===document.readyState?setTimeout(t,0):addEventListener("load",(function(){return setTimeout(t,0)})),i((function(t){o=a("TTFB"),c=u(e,o,n.reportAllChanges),o.value=performance.now()-t.timeStamp,c(!0)}))};e.getCLS=m,e.getFCP=d,e.getFID=h,e.getINP=A,e.getLCP=L,e.getTTFB=M,e.onCLS=m,e.onFCP=d,e.onFID=h,e.onINP=A,e.onLCP=L,e.onTTFB=M,Object.defineProperty(e,"__esModule",{value:!0})})); |
@@ -1,1 +0,1 @@ | ||
var webVitals=function(e){"use strict";var n,t,i,r,a,o=!1,c=function(e){addEventListener("pageshow",(function(n){n.persisted&&(o=!0,e(n))}),!0)},u=function(){return window.performance&&(performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]||function(){var e=performance.timing,n={entryType:"navigation",startTime:0};for(var t in e)"navigationStart"!==t&&"toJSON"!==t&&(n[t]=Math.max(e[t]-e.navigationStart,0));return n}())},f=function(e,n){var t=u();return{name:e,value:void 0===n?-1:n,delta:0,entries:[],id:"v2-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:o?"back_forward_cache":t&&t.type}},s=function(e,n,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var i=new PerformanceObserver((function(e){n(e.getEntries())}));return i.observe(Object.assign({type:e,buffered:!0},t||{})),i}}catch(e){}},d=function(e,n){var t=function t(i){"pagehide"!==i.type&&"hidden"!==document.visibilityState||(e(i),n&&(removeEventListener("visibilitychange",t,!0),removeEventListener("pagehide",t,!0)))};addEventListener("visibilitychange",t,!0),addEventListener("pagehide",t,!0)},v=function(e,n,t){var i;return function(r){n.value>=0&&(r||t)&&(n.delta=n.value-(i||0),(n.delta||void 0===i)&&(i=n.value,e(n)))}},m=-1,l=function(){return"hidden"===document.visibilityState?0:1/0},p=function(){d((function(e){var n=e.timeStamp;m=n}),!0)},h=function(){return m<0&&(m=l(),p(),c((function(){setTimeout((function(){m=l(),p()}),0)}))),{get firstHiddenTime(){return m}}},y=function(e,n){var t,i=h(),r=f("FCP"),a=function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(u&&u.disconnect(),e.startTime<i.firstHiddenTime&&(r.value=e.startTime,r.entries.push(e),t(!0)))}))},o=window.performance&&window.performance.getEntriesByName&&window.performance.getEntriesByName("first-contentful-paint")[0],u=o?null:s("paint",a);(o||u)&&(t=v(e,r,n),o&&a([o]),c((function(i){r=f("FCP"),t=v(e,r,n),requestAnimationFrame((function(){requestAnimationFrame((function(){r.value=performance.now()-i.timeStamp,t(!0)}))}))})))},g=!1,T=-1,E=function(e,n){g||(y((function(e){T=e.value})),g=!0);var t,i=function(n){T>-1&&e(n)},r=f("CLS",0),a=0,o=[],u=function(e){e.forEach((function(e){if(!e.hadRecentInput){var n=o[0],i=o[o.length-1];a&&e.startTime-i.startTime<1e3&&e.startTime-n.startTime<5e3?(a+=e.value,o.push(e)):(a=e.value,o=[e]),a>r.value&&(r.value=a,r.entries=o,t())}}))},m=s("layout-shift",u);m&&(t=v(i,r,n),d((function(){u(m.takeRecords()),t(!0)})),c((function(){a=0,T=-1,r=f("CLS",0),t=v(i,r,n)})))},w={passive:!0,capture:!0},L=new Date,S=function(e,r){n||(n=r,t=e,i=new Date,I(removeEventListener),b())},b=function(){if(t>=0&&t<i-L){var e={entryType:"first-input",name:n.type,target:n.target,cancelable:n.cancelable,startTime:n.timeStamp,processingStart:n.timeStamp+t};r.forEach((function(n){n(e)})),r=[]}},F=function(e){if(e.cancelable){var n=(e.timeStamp>1e12?new Date:performance.now())-e.timeStamp;"pointerdown"==e.type?function(e,n){var t=function(){S(e,n),r()},i=function(){r()},r=function(){removeEventListener("pointerup",t,w),removeEventListener("pointercancel",i,w)};addEventListener("pointerup",t,w),addEventListener("pointercancel",i,w)}(n,e):S(n,e)}},I=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(n){return e(n,F,w)}))},P=function(e,i){var a,o=h(),u=f("FID"),m=function(e){e.startTime<o.firstHiddenTime&&(u.value=e.processingStart-e.startTime,u.entries.push(e),a(!0))},l=function(e){e.forEach(m)},p=s("first-input",l);a=v(e,u,i),p&&d((function(){l(p.takeRecords()),p.disconnect()}),!0),p&&c((function(){var o;u=f("FID"),a=v(e,u,i),r=[],t=-1,n=null,I(addEventListener),o=m,r.push(o),b()}))},C=0,M=1/0,k=0,B=function(e){e.forEach((function(e){e.interactionId&&(M=Math.min(M,e.interactionId),k=Math.max(k,e.interactionId),C=k?(k-M)/7+1:0)}))},D=function(){return a?C:performance.interactionCount||0},N=function(){"interactionCount"in performance||a||(a=s("event",B,{type:"event",buffered:!0,durationThreshold:0}))},O=0,R=function(){return D()-O},q=[],A={},H=function(e,n){N();var t,i=f("INP"),r=function(e){e.forEach((function(e){e.interactionId&&function(e){var n=q[q.length-1],t=A[e.interactionId];if(t||q.length<10||e.duration>n.latency){if(t)t.entries.push(e),t.latency=Math.max(t.latency,e.duration);else{var i={id:e.interactionId,latency:e.duration,entries:[e]};A[i.id]=i,q.push(i)}q.sort((function(e,n){return n.latency-e.latency})),q.splice(10).forEach((function(e){delete A[e.id]}))}}(e)}));var n,r=(n=Math.min(q.length-1,Math.floor(R()/50)),q[n]);r&&r.latency!==i.value&&(i.value=r.latency,i.entries=r.entries,t())},a=s("event",r,{durationThreshold:40});t=v(e,i,n),a&&(d((function(){r(a.takeRecords()),i.value<0&&R()>0&&(i.value=0,i.entries=[]),t(!0)})),c((function(){q=[],O=D(),i=f("INP"),t=v(e,i,n)})))},_={},x=function(e,n){var t,i=h(),r=f("LCP"),a=function(e){var n=e[e.length-1];if(n){var a=n.startTime;a<i.firstHiddenTime&&(r.value=a,r.entries=[n],t())}},o=s("largest-contentful-paint",a);if(o){t=v(e,r,n);var u=function(){_[r.id]||(a(o.takeRecords()),o.disconnect(),_[r.id]=!0,t(!0))};["keydown","click"].forEach((function(e){addEventListener(e,u,{once:!0,capture:!0})})),d(u,!0),c((function(i){r=f("LCP"),t=v(e,r,n),requestAnimationFrame((function(){requestAnimationFrame((function(){r.value=performance.now()-i.timeStamp,_[r.id]=!0,t(!0)}))}))}))}},j=function(e,n){var t,i=f("TTFB"),r=v(e,i,n);t=function(){var e=u();if(e){if(i.value=e.responseStart,i.value<0||i.value>performance.now())return;i.entries=[e],r(!0)}},"complete"===document.readyState?setTimeout(t,0):addEventListener("load",(function(){return setTimeout(t,0)})),c((function(t){i=f("TTFB"),r=v(e,i,n),i.value=performance.now()-t.timeStamp,r(!0)}))};return e.getCLS=E,e.getFCP=y,e.getFID=P,e.getINP=H,e.getLCP=x,e.getTFB=j,e.onCLS=E,e.onFCP=y,e.onFID=P,e.onINP=H,e.onLCP=x,e.onTTFB=j,Object.defineProperty(e,"__esModule",{value:!0}),e}({}); | ||
var webVitals=function(e){"use strict";var n,t,i,r,a,o=!1,c=function(e){addEventListener("pageshow",(function(n){n.persisted&&(o=!0,e(n))}),!0)},u=function(){return window.performance&&(performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]||function(){var e=performance.timing,n={entryType:"navigation",startTime:0};for(var t in e)"navigationStart"!==t&&"toJSON"!==t&&(n[t]=Math.max(e[t]-e.navigationStart,0));return n}())},f=function(e,n){var t=u();return{name:e,value:void 0===n?-1:n,delta:0,entries:[],id:"v2-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:o?"back_forward_cache":t&&t.type}},s=function(e,n,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var i=new PerformanceObserver((function(e){n(e.getEntries())}));return i.observe(Object.assign({type:e,buffered:!0},t||{})),i}}catch(e){}},l=function(e,n){var t=function t(i){"pagehide"!==i.type&&"hidden"!==document.visibilityState||(e(i),n&&(removeEventListener("visibilitychange",t,!0),removeEventListener("pagehide",t,!0)))};addEventListener("visibilitychange",t,!0),addEventListener("pagehide",t,!0)},d=function(e,n,t){var i;return function(r){n.value>=0&&(r||t)&&(n.delta=n.value-(i||0),(n.delta||void 0===i)&&(i=n.value,e(n)))}},v=-1,p=function(){return"hidden"===document.visibilityState?0:1/0},m=function(){l((function(e){var n=e.timeStamp;v=n}),!0)},h=function(){return v<0&&(v=p(),m(),c((function(){setTimeout((function(){v=p(),m()}),0)}))),{get firstHiddenTime(){return v}}},g=function(e,n){n=n||{};var t,i=h(),r=f("FCP"),a=function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(u&&u.disconnect(),e.startTime<i.firstHiddenTime&&(r.value=e.startTime,r.entries.push(e),t(!0)))}))},o=window.performance&&window.performance.getEntriesByName&&window.performance.getEntriesByName("first-contentful-paint")[0],u=o?null:s("paint",a);(o||u)&&(t=d(e,r,n.reportAllChanges),o&&a([o]),c((function(i){r=f("FCP"),t=d(e,r,n.reportAllChanges),requestAnimationFrame((function(){requestAnimationFrame((function(){r.value=performance.now()-i.timeStamp,t(!0)}))}))})))},y=!1,T=-1,E=function(e,n){n=n||{},y||(g((function(e){T=e.value})),y=!0);var t,i=function(n){T>-1&&e(n)},r=f("CLS",0),a=0,o=[],u=function(e){e.forEach((function(e){if(!e.hadRecentInput){var n=o[0],i=o[o.length-1];a&&e.startTime-i.startTime<1e3&&e.startTime-n.startTime<5e3?(a+=e.value,o.push(e)):(a=e.value,o=[e]),a>r.value&&(r.value=a,r.entries=o,t())}}))},v=s("layout-shift",u);v&&(t=d(i,r,n.reportAllChanges),l((function(){u(v.takeRecords()),t(!0)})),c((function(){a=0,T=-1,r=f("CLS",0),t=d(i,r,n.reportAllChanges)})))},w={passive:!0,capture:!0},C=new Date,L=function(e,r){n||(n=r,t=e,i=new Date,A(removeEventListener),S())},S=function(){if(t>=0&&t<i-C){var e={entryType:"first-input",name:n.type,target:n.target,cancelable:n.cancelable,startTime:n.timeStamp,processingStart:n.timeStamp+t};r.forEach((function(n){n(e)})),r=[]}},b=function(e){if(e.cancelable){var n=(e.timeStamp>1e12?new Date:performance.now())-e.timeStamp;"pointerdown"==e.type?function(e,n){var t=function(){L(e,n),r()},i=function(){r()},r=function(){removeEventListener("pointerup",t,w),removeEventListener("pointercancel",i,w)};addEventListener("pointerup",t,w),addEventListener("pointercancel",i,w)}(n,e):L(n,e)}},A=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(n){return e(n,b,w)}))},F=function(e,i){i=i||{};var a,o=h(),u=f("FID"),v=function(e){e.startTime<o.firstHiddenTime&&(u.value=e.processingStart-e.startTime,u.entries.push(e),a(!0))},p=function(e){e.forEach(v)},m=s("first-input",p);a=d(e,u,i.reportAllChanges),m&&l((function(){p(m.takeRecords()),m.disconnect()}),!0),m&&c((function(){var o;u=f("FID"),a=d(e,u,i.reportAllChanges),r=[],t=-1,n=null,A(addEventListener),o=v,r.push(o),S()}))},I=0,P=1/0,M=0,k=function(e){e.forEach((function(e){e.interactionId&&(P=Math.min(P,e.interactionId),M=Math.max(M,e.interactionId),I=M?(M-P)/7+1:0)}))},B=function(){return a?I:performance.interactionCount||0},D=function(){"interactionCount"in performance||a||(a=s("event",k,{type:"event",buffered:!0,durationThreshold:0}))},N=0,O=function(){return B()-N},R=[],q={},H=function(e,n){n=n||{},D();var t,i=f("INP"),r=function(e){e.forEach((function(e){e.interactionId&&function(e){var n=R[R.length-1],t=q[e.interactionId];if(t||R.length<10||e.duration>n.latency){if(t)t.entries.push(e),t.latency=Math.max(t.latency,e.duration);else{var i={id:e.interactionId,latency:e.duration,entries:[e]};q[i.id]=i,R.push(i)}R.sort((function(e,n){return n.latency-e.latency})),R.splice(10).forEach((function(e){delete q[e.id]}))}}(e)}));var n,r=(n=Math.min(R.length-1,Math.floor(O()/50)),R[n]);r&&r.latency!==i.value&&(i.value=r.latency,i.entries=r.entries,t())},a=s("event",r,{durationThreshold:n.durationThreshold||40});t=d(e,i,n.reportAllChanges),a&&(l((function(){r(a.takeRecords()),i.value<0&&O()>0&&(i.value=0,i.entries=[]),t(!0)})),c((function(){R=[],N=B(),i=f("INP"),t=d(e,i,n.reportAllChanges)})))},_={},x=function(e,n){n=n||{};var t,i=h(),r=f("LCP"),a=function(e){var n=e[e.length-1];if(n){var a=n.startTime;a<i.firstHiddenTime&&(r.value=a,r.entries=[n],t())}},o=s("largest-contentful-paint",a);if(o){t=d(e,r,n.reportAllChanges);var u=function(){_[r.id]||(a(o.takeRecords()),o.disconnect(),_[r.id]=!0,t(!0))};["keydown","click"].forEach((function(e){addEventListener(e,u,{once:!0,capture:!0})})),l(u,!0),c((function(i){r=f("LCP"),t=d(e,r,n.reportAllChanges),requestAnimationFrame((function(){requestAnimationFrame((function(){r.value=performance.now()-i.timeStamp,_[r.id]=!0,t(!0)}))}))}))}},j=function(e,n){n=n||{};var t,i=f("TTFB"),r=d(e,i,n.reportAllChanges);t=function(){var e=u();if(e){if(i.value=e.responseStart,i.value<0||i.value>performance.now())return;i.entries=[e],r(!0)}},"complete"===document.readyState?setTimeout(t,0):addEventListener("load",(function(){return setTimeout(t,0)})),c((function(t){i=f("TTFB"),r=d(e,i,n.reportAllChanges),i.value=performance.now()-t.timeStamp,r(!0)}))};return e.getCLS=E,e.getFCP=g,e.getFID=F,e.getINP=H,e.getLCP=x,e.getTTFB=j,e.onCLS=E,e.onFCP=g,e.onFID=F,e.onINP=H,e.onLCP=x,e.onTTFB=j,Object.defineProperty(e,"__esModule",{value:!0}),e}({}); |
@@ -1,1 +0,1 @@ | ||
var e,n,t,i,a,r=!1,o=function(e){addEventListener("pageshow",(function(n){n.persisted&&(r=!0,e(n))}),!0)},c=function(){return window.performance&&(performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]||function(){var e=performance.timing,n={entryType:"navigation",startTime:0};for(var t in e)"navigationStart"!==t&&"toJSON"!==t&&(n[t]=Math.max(e[t]-e.navigationStart,0));return n}())},u=function(e,n){var t=c();return{name:e,value:void 0===n?-1:n,delta:0,entries:[],id:"v2-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:r?"back_forward_cache":t&&t.type}},f=function(e,n,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var i=new PerformanceObserver((function(e){n(e.getEntries())}));return i.observe(Object.assign({type:e,buffered:!0},t||{})),i}}catch(e){}},s=function(e,n){var t=function t(i){"pagehide"!==i.type&&"hidden"!==document.visibilityState||(e(i),n&&(removeEventListener("visibilitychange",t,!0),removeEventListener("pagehide",t,!0)))};addEventListener("visibilitychange",t,!0),addEventListener("pagehide",t,!0)},d=function(e,n,t){var i;return function(a){n.value>=0&&(a||t)&&(n.delta=n.value-(i||0),(n.delta||void 0===i)&&(i=n.value,e(n)))}},v=-1,m=function(){return"hidden"===document.visibilityState?0:1/0},p=function(){s((function(e){var n=e.timeStamp;v=n}),!0)},l=function(){return v<0&&(v=m(),p(),o((function(){setTimeout((function(){v=m(),p()}),0)}))),{get firstHiddenTime(){return v}}},h=function(e,n){var t,i=l(),a=u("FCP"),r=function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(s&&s.disconnect(),e.startTime<i.firstHiddenTime&&(a.value=e.startTime,a.entries.push(e),t(!0)))}))},c=window.performance&&window.performance.getEntriesByName&&window.performance.getEntriesByName("first-contentful-paint")[0],s=c?null:f("paint",r);(c||s)&&(t=d(e,a,n),c&&r([c]),o((function(i){a=u("FCP"),t=d(e,a,n),requestAnimationFrame((function(){requestAnimationFrame((function(){a.value=performance.now()-i.timeStamp,t(!0)}))}))})))},y=!1,g=-1,T=function(e,n){y||(h((function(e){g=e.value})),y=!0);var t,i=function(n){g>-1&&e(n)},a=u("CLS",0),r=0,c=[],v=function(e){e.forEach((function(e){if(!e.hadRecentInput){var n=c[0],i=c[c.length-1];r&&e.startTime-i.startTime<1e3&&e.startTime-n.startTime<5e3?(r+=e.value,c.push(e)):(r=e.value,c=[e]),r>a.value&&(a.value=r,a.entries=c,t())}}))},m=f("layout-shift",v);m&&(t=d(i,a,n),s((function(){v(m.takeRecords()),t(!0)})),o((function(){r=0,g=-1,a=u("CLS",0),t=d(i,a,n)})))},E={passive:!0,capture:!0},w=new Date,S=function(i,a){e||(e=a,n=i,t=new Date,F(removeEventListener),L())},L=function(){if(n>=0&&n<t-w){var a={entryType:"first-input",name:e.type,target:e.target,cancelable:e.cancelable,startTime:e.timeStamp,processingStart:e.timeStamp+n};i.forEach((function(e){e(a)})),i=[]}},b=function(e){if(e.cancelable){var n=(e.timeStamp>1e12?new Date:performance.now())-e.timeStamp;"pointerdown"==e.type?function(e,n){var t=function(){S(e,n),a()},i=function(){a()},a=function(){removeEventListener("pointerup",t,E),removeEventListener("pointercancel",i,E)};addEventListener("pointerup",t,E),addEventListener("pointercancel",i,E)}(n,e):S(n,e)}},F=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(n){return e(n,b,E)}))},I=function(t,a){var r,c=l(),v=u("FID"),m=function(e){e.startTime<c.firstHiddenTime&&(v.value=e.processingStart-e.startTime,v.entries.push(e),r(!0))},p=function(e){e.forEach(m)},h=f("first-input",p);r=d(t,v,a),h&&s((function(){p(h.takeRecords()),h.disconnect()}),!0),h&&o((function(){var o;v=u("FID"),r=d(t,v,a),i=[],n=-1,e=null,F(addEventListener),o=m,i.push(o),L()}))},C=0,P=1/0,k=0,M=function(e){e.forEach((function(e){e.interactionId&&(P=Math.min(P,e.interactionId),k=Math.max(k,e.interactionId),C=k?(k-P)/7+1:0)}))},B=function(){return a?C:performance.interactionCount||0},D=function(){"interactionCount"in performance||a||(a=f("event",M,{type:"event",buffered:!0,durationThreshold:0}))},N=0,R=function(){return B()-N},q=[],x={},A=function(e,n){D();var t,i=u("INP"),a=function(e){e.forEach((function(e){e.interactionId&&function(e){var n=q[q.length-1],t=x[e.interactionId];if(t||q.length<10||e.duration>n.latency){if(t)t.entries.push(e),t.latency=Math.max(t.latency,e.duration);else{var i={id:e.interactionId,latency:e.duration,entries:[e]};x[i.id]=i,q.push(i)}q.sort((function(e,n){return n.latency-e.latency})),q.splice(10).forEach((function(e){delete x[e.id]}))}}(e)}));var n,a=(n=Math.min(q.length-1,Math.floor(R()/50)),q[n]);a&&a.latency!==i.value&&(i.value=a.latency,i.entries=a.entries,t())},r=f("event",a,{durationThreshold:40});t=d(e,i,n),r&&(s((function(){a(r.takeRecords()),i.value<0&&R()>0&&(i.value=0,i.entries=[]),t(!0)})),o((function(){q=[],N=B(),i=u("INP"),t=d(e,i,n)})))},H={},O=function(e,n){var t,i=l(),a=u("LCP"),r=function(e){var n=e[e.length-1];if(n){var r=n.startTime;r<i.firstHiddenTime&&(a.value=r,a.entries=[n],t())}},c=f("largest-contentful-paint",r);if(c){t=d(e,a,n);var v=function(){H[a.id]||(r(c.takeRecords()),c.disconnect(),H[a.id]=!0,t(!0))};["keydown","click"].forEach((function(e){addEventListener(e,v,{once:!0,capture:!0})})),s(v,!0),o((function(i){a=u("LCP"),t=d(e,a,n),requestAnimationFrame((function(){requestAnimationFrame((function(){a.value=performance.now()-i.timeStamp,H[a.id]=!0,t(!0)}))}))}))}},_=function(e,n){var t,i=u("TTFB"),a=d(e,i,n);t=function(){var e=c();if(e){if(i.value=e.responseStart,i.value<0||i.value>performance.now())return;i.entries=[e],a(!0)}},"complete"===document.readyState?setTimeout(t,0):addEventListener("load",(function(){return setTimeout(t,0)})),o((function(t){i=u("TTFB"),a=d(e,i,n),i.value=performance.now()-t.timeStamp,a(!0)}))};export{T as getCLS,h as getFCP,I as getFID,A as getINP,O as getLCP,_ as getTFB,T as onCLS,h as onFCP,I as onFID,A as onINP,O as onLCP,_ as onTTFB}; | ||
var e,n,t,i,r,a=!1,o=function(e){addEventListener("pageshow",(function(n){n.persisted&&(a=!0,e(n))}),!0)},c=function(){return window.performance&&(performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]||function(){var e=performance.timing,n={entryType:"navigation",startTime:0};for(var t in e)"navigationStart"!==t&&"toJSON"!==t&&(n[t]=Math.max(e[t]-e.navigationStart,0));return n}())},u=function(e,n){var t=c();return{name:e,value:void 0===n?-1:n,delta:0,entries:[],id:"v2-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:a?"back_forward_cache":t&&t.type}},f=function(e,n,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var i=new PerformanceObserver((function(e){n(e.getEntries())}));return i.observe(Object.assign({type:e,buffered:!0},t||{})),i}}catch(e){}},s=function(e,n){var t=function t(i){"pagehide"!==i.type&&"hidden"!==document.visibilityState||(e(i),n&&(removeEventListener("visibilitychange",t,!0),removeEventListener("pagehide",t,!0)))};addEventListener("visibilitychange",t,!0),addEventListener("pagehide",t,!0)},l=function(e,n,t){var i;return function(r){n.value>=0&&(r||t)&&(n.delta=n.value-(i||0),(n.delta||void 0===i)&&(i=n.value,e(n)))}},d=-1,v=function(){return"hidden"===document.visibilityState?0:1/0},p=function(){s((function(e){var n=e.timeStamp;d=n}),!0)},m=function(){return d<0&&(d=v(),p(),o((function(){setTimeout((function(){d=v(),p()}),0)}))),{get firstHiddenTime(){return d}}},h=function(e,n){n=n||{};var t,i=m(),r=u("FCP"),a=function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(s&&s.disconnect(),e.startTime<i.firstHiddenTime&&(r.value=e.startTime,r.entries.push(e),t(!0)))}))},c=window.performance&&window.performance.getEntriesByName&&window.performance.getEntriesByName("first-contentful-paint")[0],s=c?null:f("paint",a);(c||s)&&(t=l(e,r,n.reportAllChanges),c&&a([c]),o((function(i){r=u("FCP"),t=l(e,r,n.reportAllChanges),requestAnimationFrame((function(){requestAnimationFrame((function(){r.value=performance.now()-i.timeStamp,t(!0)}))}))})))},g=!1,y=-1,T=function(e,n){n=n||{},g||(h((function(e){y=e.value})),g=!0);var t,i=function(n){y>-1&&e(n)},r=u("CLS",0),a=0,c=[],d=function(e){e.forEach((function(e){if(!e.hadRecentInput){var n=c[0],i=c[c.length-1];a&&e.startTime-i.startTime<1e3&&e.startTime-n.startTime<5e3?(a+=e.value,c.push(e)):(a=e.value,c=[e]),a>r.value&&(r.value=a,r.entries=c,t())}}))},v=f("layout-shift",d);v&&(t=l(i,r,n.reportAllChanges),s((function(){d(v.takeRecords()),t(!0)})),o((function(){a=0,y=-1,r=u("CLS",0),t=l(i,r,n.reportAllChanges)})))},E={passive:!0,capture:!0},w=new Date,C=function(i,r){e||(e=r,n=i,t=new Date,A(removeEventListener),S())},S=function(){if(n>=0&&n<t-w){var r={entryType:"first-input",name:e.type,target:e.target,cancelable:e.cancelable,startTime:e.timeStamp,processingStart:e.timeStamp+n};i.forEach((function(e){e(r)})),i=[]}},L=function(e){if(e.cancelable){var n=(e.timeStamp>1e12?new Date:performance.now())-e.timeStamp;"pointerdown"==e.type?function(e,n){var t=function(){C(e,n),r()},i=function(){r()},r=function(){removeEventListener("pointerup",t,E),removeEventListener("pointercancel",i,E)};addEventListener("pointerup",t,E),addEventListener("pointercancel",i,E)}(n,e):C(n,e)}},A=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(n){return e(n,L,E)}))},b=function(t,r){r=r||{};var a,c=m(),d=u("FID"),v=function(e){e.startTime<c.firstHiddenTime&&(d.value=e.processingStart-e.startTime,d.entries.push(e),a(!0))},p=function(e){e.forEach(v)},h=f("first-input",p);a=l(t,d,r.reportAllChanges),h&&s((function(){p(h.takeRecords()),h.disconnect()}),!0),h&&o((function(){var o;d=u("FID"),a=l(t,d,r.reportAllChanges),i=[],n=-1,e=null,A(addEventListener),o=v,i.push(o),S()}))},F=0,I=1/0,P=0,k=function(e){e.forEach((function(e){e.interactionId&&(I=Math.min(I,e.interactionId),P=Math.max(P,e.interactionId),F=P?(P-I)/7+1:0)}))},M=function(){return r?F:performance.interactionCount||0},B=function(){"interactionCount"in performance||r||(r=f("event",k,{type:"event",buffered:!0,durationThreshold:0}))},D=0,N=function(){return M()-D},R=[],q={},x=function(e,n){n=n||{},B();var t,i=u("INP"),r=function(e){e.forEach((function(e){e.interactionId&&function(e){var n=R[R.length-1],t=q[e.interactionId];if(t||R.length<10||e.duration>n.latency){if(t)t.entries.push(e),t.latency=Math.max(t.latency,e.duration);else{var i={id:e.interactionId,latency:e.duration,entries:[e]};q[i.id]=i,R.push(i)}R.sort((function(e,n){return n.latency-e.latency})),R.splice(10).forEach((function(e){delete q[e.id]}))}}(e)}));var n,r=(n=Math.min(R.length-1,Math.floor(N()/50)),R[n]);r&&r.latency!==i.value&&(i.value=r.latency,i.entries=r.entries,t())},a=f("event",r,{durationThreshold:n.durationThreshold||40});t=l(e,i,n.reportAllChanges),a&&(s((function(){r(a.takeRecords()),i.value<0&&N()>0&&(i.value=0,i.entries=[]),t(!0)})),o((function(){R=[],D=M(),i=u("INP"),t=l(e,i,n.reportAllChanges)})))},H={},O=function(e,n){n=n||{};var t,i=m(),r=u("LCP"),a=function(e){var n=e[e.length-1];if(n){var a=n.startTime;a<i.firstHiddenTime&&(r.value=a,r.entries=[n],t())}},c=f("largest-contentful-paint",a);if(c){t=l(e,r,n.reportAllChanges);var d=function(){H[r.id]||(a(c.takeRecords()),c.disconnect(),H[r.id]=!0,t(!0))};["keydown","click"].forEach((function(e){addEventListener(e,d,{once:!0,capture:!0})})),s(d,!0),o((function(i){r=u("LCP"),t=l(e,r,n.reportAllChanges),requestAnimationFrame((function(){requestAnimationFrame((function(){r.value=performance.now()-i.timeStamp,H[r.id]=!0,t(!0)}))}))}))}},_=function(e,n){n=n||{};var t,i=u("TTFB"),r=l(e,i,n.reportAllChanges);t=function(){var e=c();if(e){if(i.value=e.responseStart,i.value<0||i.value>performance.now())return;i.entries=[e],r(!0)}},"complete"===document.readyState?setTimeout(t,0):addEventListener("load",(function(){return setTimeout(t,0)})),o((function(t){i=u("TTFB"),r=l(e,i,n.reportAllChanges),i.value=performance.now()-t.timeStamp,r(!0)}))};export{T as getCLS,h as getFCP,b as getFID,x as getINP,O as getLCP,_ as getTTFB,T as onCLS,h as onFCP,b as onFID,x as onINP,O as onLCP,_ as onTTFB}; |
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).webVitals={})}(this,(function(e){"use strict";var n,t,i,r,a,o=!1,c=function(e){addEventListener("pageshow",(function(n){n.persisted&&(o=!0,e(n))}),!0)},u=function(){return window.performance&&(performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]||function(){var e=performance.timing,n={entryType:"navigation",startTime:0};for(var t in e)"navigationStart"!==t&&"toJSON"!==t&&(n[t]=Math.max(e[t]-e.navigationStart,0));return n}())},f=function(e,n){var t=u();return{name:e,value:void 0===n?-1:n,delta:0,entries:[],id:"v2-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:o?"back_forward_cache":t&&t.type}},s=function(e,n,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var i=new PerformanceObserver((function(e){n(e.getEntries())}));return i.observe(Object.assign({type:e,buffered:!0},t||{})),i}}catch(e){}},d=function(e,n){var t=function t(i){"pagehide"!==i.type&&"hidden"!==document.visibilityState||(e(i),n&&(removeEventListener("visibilitychange",t,!0),removeEventListener("pagehide",t,!0)))};addEventListener("visibilitychange",t,!0),addEventListener("pagehide",t,!0)},v=function(e,n,t){var i;return function(r){n.value>=0&&(r||t)&&(n.delta=n.value-(i||0),(n.delta||void 0===i)&&(i=n.value,e(n)))}},m=-1,l=function(){return"hidden"===document.visibilityState?0:1/0},p=function(){d((function(e){var n=e.timeStamp;m=n}),!0)},h=function(){return m<0&&(m=l(),p(),c((function(){setTimeout((function(){m=l(),p()}),0)}))),{get firstHiddenTime(){return m}}},y=function(e,n){var t,i=h(),r=f("FCP"),a=function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(u&&u.disconnect(),e.startTime<i.firstHiddenTime&&(r.value=e.startTime,r.entries.push(e),t(!0)))}))},o=window.performance&&window.performance.getEntriesByName&&window.performance.getEntriesByName("first-contentful-paint")[0],u=o?null:s("paint",a);(o||u)&&(t=v(e,r,n),o&&a([o]),c((function(i){r=f("FCP"),t=v(e,r,n),requestAnimationFrame((function(){requestAnimationFrame((function(){r.value=performance.now()-i.timeStamp,t(!0)}))}))})))},g=!1,T=-1,E=function(e,n){g||(y((function(e){T=e.value})),g=!0);var t,i=function(n){T>-1&&e(n)},r=f("CLS",0),a=0,o=[],u=function(e){e.forEach((function(e){if(!e.hadRecentInput){var n=o[0],i=o[o.length-1];a&&e.startTime-i.startTime<1e3&&e.startTime-n.startTime<5e3?(a+=e.value,o.push(e)):(a=e.value,o=[e]),a>r.value&&(r.value=a,r.entries=o,t())}}))},m=s("layout-shift",u);m&&(t=v(i,r,n),d((function(){u(m.takeRecords()),t(!0)})),c((function(){a=0,T=-1,r=f("CLS",0),t=v(i,r,n)})))},w={passive:!0,capture:!0},L=new Date,S=function(e,r){n||(n=r,t=e,i=new Date,I(removeEventListener),b())},b=function(){if(t>=0&&t<i-L){var e={entryType:"first-input",name:n.type,target:n.target,cancelable:n.cancelable,startTime:n.timeStamp,processingStart:n.timeStamp+t};r.forEach((function(n){n(e)})),r=[]}},F=function(e){if(e.cancelable){var n=(e.timeStamp>1e12?new Date:performance.now())-e.timeStamp;"pointerdown"==e.type?function(e,n){var t=function(){S(e,n),r()},i=function(){r()},r=function(){removeEventListener("pointerup",t,w),removeEventListener("pointercancel",i,w)};addEventListener("pointerup",t,w),addEventListener("pointercancel",i,w)}(n,e):S(n,e)}},I=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(n){return e(n,F,w)}))},P=function(e,i){var a,o=h(),u=f("FID"),m=function(e){e.startTime<o.firstHiddenTime&&(u.value=e.processingStart-e.startTime,u.entries.push(e),a(!0))},l=function(e){e.forEach(m)},p=s("first-input",l);a=v(e,u,i),p&&d((function(){l(p.takeRecords()),p.disconnect()}),!0),p&&c((function(){var o;u=f("FID"),a=v(e,u,i),r=[],t=-1,n=null,I(addEventListener),o=m,r.push(o),b()}))},C=0,M=1/0,k=0,B=function(e){e.forEach((function(e){e.interactionId&&(M=Math.min(M,e.interactionId),k=Math.max(k,e.interactionId),C=k?(k-M)/7+1:0)}))},D=function(){return a?C:performance.interactionCount||0},N=function(){"interactionCount"in performance||a||(a=s("event",B,{type:"event",buffered:!0,durationThreshold:0}))},x=0,O=function(){return D()-x},R=[],q={},A=function(e,n){N();var t,i=f("INP"),r=function(e){e.forEach((function(e){e.interactionId&&function(e){var n=R[R.length-1],t=q[e.interactionId];if(t||R.length<10||e.duration>n.latency){if(t)t.entries.push(e),t.latency=Math.max(t.latency,e.duration);else{var i={id:e.interactionId,latency:e.duration,entries:[e]};q[i.id]=i,R.push(i)}R.sort((function(e,n){return n.latency-e.latency})),R.splice(10).forEach((function(e){delete q[e.id]}))}}(e)}));var n,r=(n=Math.min(R.length-1,Math.floor(O()/50)),R[n]);r&&r.latency!==i.value&&(i.value=r.latency,i.entries=r.entries,t())},a=s("event",r,{durationThreshold:40});t=v(e,i,n),a&&(d((function(){r(a.takeRecords()),i.value<0&&O()>0&&(i.value=0,i.entries=[]),t(!0)})),c((function(){R=[],x=D(),i=f("INP"),t=v(e,i,n)})))},H={},_=function(e,n){var t,i=h(),r=f("LCP"),a=function(e){var n=e[e.length-1];if(n){var a=n.startTime;a<i.firstHiddenTime&&(r.value=a,r.entries=[n],t())}},o=s("largest-contentful-paint",a);if(o){t=v(e,r,n);var u=function(){H[r.id]||(a(o.takeRecords()),o.disconnect(),H[r.id]=!0,t(!0))};["keydown","click"].forEach((function(e){addEventListener(e,u,{once:!0,capture:!0})})),d(u,!0),c((function(i){r=f("LCP"),t=v(e,r,n),requestAnimationFrame((function(){requestAnimationFrame((function(){r.value=performance.now()-i.timeStamp,H[r.id]=!0,t(!0)}))}))}))}},j=function(e,n){var t,i=f("TTFB"),r=v(e,i,n);t=function(){var e=u();if(e){if(i.value=e.responseStart,i.value<0||i.value>performance.now())return;i.entries=[e],r(!0)}},"complete"===document.readyState?setTimeout(t,0):addEventListener("load",(function(){return setTimeout(t,0)})),c((function(t){i=f("TTFB"),r=v(e,i,n),i.value=performance.now()-t.timeStamp,r(!0)}))};e.getCLS=E,e.getFCP=y,e.getFID=P,e.getINP=A,e.getLCP=_,e.getTFB=j,e.onCLS=E,e.onFCP=y,e.onFID=P,e.onINP=A,e.onLCP=_,e.onTTFB=j,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).webVitals={})}(this,(function(e){"use strict";var n,t,i,r,a,o=!1,c=function(e){addEventListener("pageshow",(function(n){n.persisted&&(o=!0,e(n))}),!0)},u=function(){return window.performance&&(performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]||function(){var e=performance.timing,n={entryType:"navigation",startTime:0};for(var t in e)"navigationStart"!==t&&"toJSON"!==t&&(n[t]=Math.max(e[t]-e.navigationStart,0));return n}())},f=function(e,n){var t=u();return{name:e,value:void 0===n?-1:n,delta:0,entries:[],id:"v2-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:o?"back_forward_cache":t&&t.type}},s=function(e,n,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var i=new PerformanceObserver((function(e){n(e.getEntries())}));return i.observe(Object.assign({type:e,buffered:!0},t||{})),i}}catch(e){}},l=function(e,n){var t=function t(i){"pagehide"!==i.type&&"hidden"!==document.visibilityState||(e(i),n&&(removeEventListener("visibilitychange",t,!0),removeEventListener("pagehide",t,!0)))};addEventListener("visibilitychange",t,!0),addEventListener("pagehide",t,!0)},d=function(e,n,t){var i;return function(r){n.value>=0&&(r||t)&&(n.delta=n.value-(i||0),(n.delta||void 0===i)&&(i=n.value,e(n)))}},p=-1,v=function(){return"hidden"===document.visibilityState?0:1/0},m=function(){l((function(e){var n=e.timeStamp;p=n}),!0)},h=function(){return p<0&&(p=v(),m(),c((function(){setTimeout((function(){p=v(),m()}),0)}))),{get firstHiddenTime(){return p}}},g=function(e,n){n=n||{};var t,i=h(),r=f("FCP"),a=function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(u&&u.disconnect(),e.startTime<i.firstHiddenTime&&(r.value=e.startTime,r.entries.push(e),t(!0)))}))},o=window.performance&&window.performance.getEntriesByName&&window.performance.getEntriesByName("first-contentful-paint")[0],u=o?null:s("paint",a);(o||u)&&(t=d(e,r,n.reportAllChanges),o&&a([o]),c((function(i){r=f("FCP"),t=d(e,r,n.reportAllChanges),requestAnimationFrame((function(){requestAnimationFrame((function(){r.value=performance.now()-i.timeStamp,t(!0)}))}))})))},y=!1,T=-1,E=function(e,n){n=n||{},y||(g((function(e){T=e.value})),y=!0);var t,i=function(n){T>-1&&e(n)},r=f("CLS",0),a=0,o=[],u=function(e){e.forEach((function(e){if(!e.hadRecentInput){var n=o[0],i=o[o.length-1];a&&e.startTime-i.startTime<1e3&&e.startTime-n.startTime<5e3?(a+=e.value,o.push(e)):(a=e.value,o=[e]),a>r.value&&(r.value=a,r.entries=o,t())}}))},p=s("layout-shift",u);p&&(t=d(i,r,n.reportAllChanges),l((function(){u(p.takeRecords()),t(!0)})),c((function(){a=0,T=-1,r=f("CLS",0),t=d(i,r,n.reportAllChanges)})))},w={passive:!0,capture:!0},C=new Date,L=function(e,r){n||(n=r,t=e,i=new Date,A(removeEventListener),S())},S=function(){if(t>=0&&t<i-C){var e={entryType:"first-input",name:n.type,target:n.target,cancelable:n.cancelable,startTime:n.timeStamp,processingStart:n.timeStamp+t};r.forEach((function(n){n(e)})),r=[]}},b=function(e){if(e.cancelable){var n=(e.timeStamp>1e12?new Date:performance.now())-e.timeStamp;"pointerdown"==e.type?function(e,n){var t=function(){L(e,n),r()},i=function(){r()},r=function(){removeEventListener("pointerup",t,w),removeEventListener("pointercancel",i,w)};addEventListener("pointerup",t,w),addEventListener("pointercancel",i,w)}(n,e):L(n,e)}},A=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(n){return e(n,b,w)}))},F=function(e,i){i=i||{};var a,o=h(),u=f("FID"),p=function(e){e.startTime<o.firstHiddenTime&&(u.value=e.processingStart-e.startTime,u.entries.push(e),a(!0))},v=function(e){e.forEach(p)},m=s("first-input",v);a=d(e,u,i.reportAllChanges),m&&l((function(){v(m.takeRecords()),m.disconnect()}),!0),m&&c((function(){var o;u=f("FID"),a=d(e,u,i.reportAllChanges),r=[],t=-1,n=null,A(addEventListener),o=p,r.push(o),S()}))},I=0,P=1/0,M=0,k=function(e){e.forEach((function(e){e.interactionId&&(P=Math.min(P,e.interactionId),M=Math.max(M,e.interactionId),I=M?(M-P)/7+1:0)}))},B=function(){return a?I:performance.interactionCount||0},D=function(){"interactionCount"in performance||a||(a=s("event",k,{type:"event",buffered:!0,durationThreshold:0}))},N=0,x=function(){return B()-N},O=[],R={},q=function(e,n){n=n||{},D();var t,i=f("INP"),r=function(e){e.forEach((function(e){e.interactionId&&function(e){var n=O[O.length-1],t=R[e.interactionId];if(t||O.length<10||e.duration>n.latency){if(t)t.entries.push(e),t.latency=Math.max(t.latency,e.duration);else{var i={id:e.interactionId,latency:e.duration,entries:[e]};R[i.id]=i,O.push(i)}O.sort((function(e,n){return n.latency-e.latency})),O.splice(10).forEach((function(e){delete R[e.id]}))}}(e)}));var n,r=(n=Math.min(O.length-1,Math.floor(x()/50)),O[n]);r&&r.latency!==i.value&&(i.value=r.latency,i.entries=r.entries,t())},a=s("event",r,{durationThreshold:n.durationThreshold||40});t=d(e,i,n.reportAllChanges),a&&(l((function(){r(a.takeRecords()),i.value<0&&x()>0&&(i.value=0,i.entries=[]),t(!0)})),c((function(){O=[],N=B(),i=f("INP"),t=d(e,i,n.reportAllChanges)})))},H={},_=function(e,n){n=n||{};var t,i=h(),r=f("LCP"),a=function(e){var n=e[e.length-1];if(n){var a=n.startTime;a<i.firstHiddenTime&&(r.value=a,r.entries=[n],t())}},o=s("largest-contentful-paint",a);if(o){t=d(e,r,n.reportAllChanges);var u=function(){H[r.id]||(a(o.takeRecords()),o.disconnect(),H[r.id]=!0,t(!0))};["keydown","click"].forEach((function(e){addEventListener(e,u,{once:!0,capture:!0})})),l(u,!0),c((function(i){r=f("LCP"),t=d(e,r,n.reportAllChanges),requestAnimationFrame((function(){requestAnimationFrame((function(){r.value=performance.now()-i.timeStamp,H[r.id]=!0,t(!0)}))}))}))}},j=function(e,n){n=n||{};var t,i=f("TTFB"),r=d(e,i,n.reportAllChanges);t=function(){var e=u();if(e){if(i.value=e.responseStart,i.value<0||i.value>performance.now())return;i.entries=[e],r(!0)}},"complete"===document.readyState?setTimeout(t,0):addEventListener("load",(function(){return setTimeout(t,0)})),c((function(t){i=f("TTFB"),r=d(e,i,n.reportAllChanges),i.value=performance.now()-t.timeStamp,r(!0)}))};e.getCLS=E,e.getFCP=g,e.getFID=F,e.getINP=q,e.getLCP=_,e.getTTFB=j,e.onCLS=E,e.onFCP=g,e.onFID=F,e.onINP=q,e.onLCP=_,e.onTTFB=j,Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "web-vitals", | ||
"version": "3.0.0-beta.0", | ||
"version": "3.0.0-beta.1", | ||
"description": "Easily measure performance metrics in JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "dist/web-vitals.umd.js", |
@@ -194,3 +194,3 @@ # `web-vitals` | ||
Each of the Web Vitals metrics is exposed as a single function that takes an `onReport` callback. This callback will be called any time the metric value is available and ready to be reported. | ||
Each of the Web Vitals metrics is exposed as a single function that takes a `callback` function that will be called any time the metric value is available and ready to be reported. | ||
@@ -225,5 +225,5 @@ The following example measures each of the Core Web Vitals metrics and logs the result to the console once its value is ready to report. | ||
In most cases, you only want `onReport` to be called when the metric is ready to be reported. However, it is possible to report every change (e.g. each layout shift as it happens) by setting the optional, second argument (`reportAllChanges`) to `true`. | ||
In most cases, you only want the `callback` function to be called when the metric is ready to be reported. However, it is possible to report every change (e.g. each layout shift as it happens) by setting `reportAllChanges` to `true` in the optional, [configuration object](#reportopts) (second parameter). | ||
This can be useful when debugging, but in general using `reportAllChanges` is not needed (or recommended). | ||
This can be useful when debugging, but in general using `reportAllChanges` is not needed (or recommended) for measuring these metrics in production. | ||
@@ -234,3 +234,3 @@ ```js | ||
// Logs CLS as the value changes. | ||
onCLS(console.log, true); | ||
onCLS(console.log, {reportAllChange: true}); | ||
``` | ||
@@ -258,3 +258,3 @@ | ||
_**Note:** the first time the `onReport` function is called, its `value` and `delta` properties will be the same._ | ||
_**Note:** the first time the `callback` function is called, its `value` and `delta` properties will be the same._ | ||
@@ -579,6 +579,6 @@ In addition to using the `id` field to group multiple deltas for the same metric, it can also be used to differentiate different metrics reported on the same page. For example, after a back/forward cache restore, a new metric object is created with a new `id` (since back/forward cache restores are considered separate page visits). | ||
#### `ReportHandler` | ||
#### `ReportCallback` | ||
```ts | ||
interface ReportHandler { | ||
interface ReportCallback { | ||
(metric: Metric): void; | ||
@@ -588,2 +588,11 @@ } | ||
#### `ReportOpts` | ||
```ts | ||
interface ReportOpts { | ||
reportAllChanges?: boolean; | ||
durationThreshold?: number; | ||
} | ||
``` | ||
#### `FirstInputPolyfillEntry` | ||
@@ -632,10 +641,10 @@ | ||
```ts | ||
type onCLS = (onReport: ReportHandler, reportAllChanges?: boolean) => void | ||
type onCLS = (callback: ReportCallback, opts?: ReportOpts) => void | ||
``` | ||
Calculates the [CLS](https://web.dev/cls/) value for the current page and calls the `onReport` function once the value is ready to be reported, along with all `layout-shift` performance entries that were used in the metric value calculation. The reported value is a [double](https://heycam.github.io/webidl/#idl-double) (corresponding to a [layout shift score](https://web.dev/cls/#layout-shift-score)). | ||
Calculates the [CLS](https://web.dev/cls/) value for the current page and calls the `callback` function once the value is ready to be reported, along with all `layout-shift` performance entries that were used in the metric value calculation. The reported value is a [double](https://heycam.github.io/webidl/#idl-double) (corresponding to a [layout shift score](https://web.dev/cls/#layout-shift-score)). | ||
If the `reportAllChanges` param is `true`, the `onReport` function will be called as soon as the value is initially determined as well as any time the value changes throughout the page lifespan. | ||
If the `reportAllChanges` [configuration option](#reportopts) is set to `true`, the `callback` function will be called as soon as the value is initially determined as well as any time the value changes throughout the page lifespan. | ||
_**Important:** CLS should be continually monitored for changes throughout the entire lifespan of a page—including if the user returns to the page after it's been hidden/backgrounded. However, since browsers often [will not fire additional callbacks once the user has backgrounded a page](https://developers.google.com/web/updates/2018/07/page-lifecycle-api#advice-hidden), `onReport` is always called when the page's visibility state changes to hidden. As a result, the `onReport` function might be called multiple times during the same page load (see [Reporting only the delta of changes](#report-only-the-delta-of-changes) for how to manage this)._ | ||
_**Important:** CLS should be continually monitored for changes throughout the entire lifespan of a page—including if the user returns to the page after it's been hidden/backgrounded. However, since browsers often [will not fire additional callbacks once the user has backgrounded a page](https://developers.google.com/web/updates/2018/07/page-lifecycle-api#advice-hidden), `callback` is always called when the page's visibility state changes to hidden. As a result, the `callback` function might be called multiple times during the same page load (see [Reporting only the delta of changes](#report-only-the-delta-of-changes) for how to manage this)._ | ||
@@ -645,6 +654,6 @@ #### `onFCP()` | ||
```ts | ||
type onFCP = (onReport: ReportHandler, reportAllChanges?: boolean) => void | ||
type onFCP = (callback: ReportCallback, opts?: ReportOpts) => void | ||
``` | ||
Calculates the [FCP](https://web.dev/fcp/) value for the current page and calls the `onReport` function once the value is ready, along with the relevant `paint` performance entry used to determine the value. The reported value is a [`DOMHighResTimeStamp`](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp). | ||
Calculates the [FCP](https://web.dev/fcp/) value for the current page and calls the `callback` function once the value is ready, along with the relevant `paint` performance entry used to determine the value. The reported value is a [`DOMHighResTimeStamp`](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp). | ||
@@ -654,6 +663,6 @@ #### `onFID()` | ||
```ts | ||
type onFID = (onReport: ReportHandler, reportAllChanges?: boolean) => void | ||
type onFID = (callback: ReportCallback, opts?: ReportOpts) => void | ||
``` | ||
Calculates the [FID](https://web.dev/fid/) value for the current page and calls the `onReport` function once the value is ready, along with the relevant `first-input` performance entry used to determine the value (and optionally the input event if using the [FID polyfill](#fid-polyfill)). The reported value is a [`DOMHighResTimeStamp`](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp). | ||
Calculates the [FID](https://web.dev/fid/) value for the current page and calls the `callback` function once the value is ready, along with the relevant `first-input` performance entry used to determine the value (and optionally the input event if using the [FID polyfill](#fid-polyfill)). The reported value is a [`DOMHighResTimeStamp`](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp). | ||
@@ -665,20 +674,22 @@ _**Important:** since FID is only reported after the user interacts with the page, it's possible that it will not be reported for some page loads._ | ||
```ts | ||
type onINP = (onReport: ReportHandler, reportAllChanges?: boolean) => void | ||
type onINP = (callback: ReportCallback, opts?: ReportOpts) => void | ||
``` | ||
Calculates the [INP](https://web.dev/responsiveness/) value for the current page and calls the `onReport` function once the value is ready, along with the `event` performance entries reported for that interaction. The reported value is a [`DOMHighResTimeStamp`](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp). | ||
Calculates the [INP](https://web.dev/responsiveness/) value for the current page and calls the `callback` function once the value is ready, along with the `event` performance entries reported for that interaction. The reported value is a [`DOMHighResTimeStamp`](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp). | ||
If the `reportAllChanges` param is `true`, the `onReport` function will be called as soon as the value is initially determined as well as any time the value changes throughout the page lifespan. | ||
A custom `durationThreshold` [configuration option](#reportopts) can optionally be passed to control what `event-timing` entries are considered for INP reporting. The default threshold is `40`, which means INP scores of less than 40 are reported as 0. Note that this will not affect your 75th percentile INP value unless that value is also less than 40 (well below the recommended [good](https://web.dev/inp/#what-is-a-good-inp-score) threshold). | ||
_**Important:** INP should be continually monitored for changes throughout the entire lifespan of a page—including if the user returns to the page after it's been hidden/backgrounded. However, since browsers often [will not fire additional callbacks once the user has backgrounded a page](https://developers.google.com/web/updates/2018/07/page-lifecycle-api#advice-hidden), `onReport` is always called when the page's visibility state changes to hidden. As a result, the `onReport` function might be called multiple times during the same page load (see [Reporting only the delta of changes](#report-only-the-delta-of-changes) for how to manage this)._ | ||
If the `reportAllChanges` [configuration option](#reportopts) is set to `true`, the `callback` function will be called as soon as the value is initially determined as well as any time the value changes throughout the page lifespan. | ||
_**Important:** INP should be continually monitored for changes throughout the entire lifespan of a page—including if the user returns to the page after it's been hidden/backgrounded. However, since browsers often [will not fire additional callbacks once the user has backgrounded a page](https://developers.google.com/web/updates/2018/07/page-lifecycle-api#advice-hidden), `callback` is always called when the page's visibility state changes to hidden. As a result, the `callback` function might be called multiple times during the same page load (see [Reporting only the delta of changes](#report-only-the-delta-of-changes) for how to manage this)._ | ||
#### `onLCP()` | ||
```ts | ||
type onLCP = (onReport: ReportHandler, reportAllChanges?: boolean) => void | ||
type onLCP = (callback: ReportCallback, opts?: ReportOpts) => void | ||
``` | ||
Calculates the [LCP](https://web.dev/lcp/) value for the current page and calls the `onReport` function once the value is ready (along with the relevant `largest-contentful-paint` performance entry used to determine the value). The reported value is a [`DOMHighResTimeStamp`](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp). | ||
Calculates the [LCP](https://web.dev/lcp/) value for the current page and calls the `callback` function once the value is ready (along with the relevant `largest-contentful-paint` performance entry used to determine the value). The reported value is a [`DOMHighResTimeStamp`](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp). | ||
If the `reportAllChanges` param is `true`, the `onReport` function will be called any time a new `largest-contentful-paint` performance entry is dispatched, or once the final value of the metric has been determined. | ||
If the `reportAllChanges` [configuration option](#reportopts) is set to `true`, the `callback` function will be called any time a new `largest-contentful-paint` performance entry is dispatched, or once the final value of the metric has been determined. | ||
@@ -688,8 +699,8 @@ #### `onTTFB()` | ||
```ts | ||
type onTTFB = (onReport: ReportHandler, reportAllChanges?: boolean) => void | ||
type onTTFB = (callback: ReportCallback, opts?: ReportOpts) => void | ||
``` | ||
Calculates the [TTFB](https://web.dev/time-to-first-byte/) value for the current page and calls the `onReport` function once the page has loaded, along with the relevant `navigation` performance entry used to determine the value. The reported value is a [`DOMHighResTimeStamp`](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp). | ||
Calculates the [TTFB](https://web.dev/time-to-first-byte/) value for the current page and calls the `callback` function once the page has loaded, along with the relevant `navigation` performance entry used to determine the value. The reported value is a [`DOMHighResTimeStamp`](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp). | ||
Note, this function waits until after the page is loaded to call `onReport` in order to ensure all properties of the `navigation` entry are populated. This is useful if you want to report on other metrics exposed by the [Navigation Timing API](https://w3c.github.io/navigation-timing/). | ||
Note, this function waits until after the page is loaded to call `callback` in order to ensure all properties of the `navigation` entry are populated. This is useful if you want to report on other metrics exposed by the [Navigation Timing API](https://w3c.github.io/navigation-timing/). | ||
@@ -775,3 +786,3 @@ For example, the TTFB metric starts from the page's [time origin](https://www.w3.org/TR/hr-time-2/#sec-time-origin), which means it [includes](https://developers.google.com/web/fundamentals/performance/navigation-and-resource-timing#the_life_and_timings_of_a_network_request) time spent on DNS lookup, connection negotiation, network latency, and unloading the previous document. If, in addition to TTFB, you want a metric that excludes these timings and _just_ captures the time spent making the request and receiving the first byte of the response, you could compute that from data found on the performance entry: | ||
- [**Core Web Vitals Custom Tag template**](https://www.simoahava.com/custom-templates/core-web-vitals/): Custom GTM template tag to [add measurement handlers](https://www.simoahava.com/analytics/track-core-web-vitals-in-ga4-with-google-tag-manager/) for all Core Web Vitals metrics. | ||
- [**`web-vitals-reporter`**](https://github.com/treosh/web-vitals-reporter): JavaScript library to batch `onReport` callbacks and send data with a single request. | ||
- [**`web-vitals-reporter`**](https://github.com/treosh/web-vitals-reporter): JavaScript library to batch `callback` functions and send data with a single request. | ||
@@ -778,0 +789,0 @@ ## License |
/* | ||
* Copyright 2020 Google LLC | ||
* Copyright 2022 Google LLC | ||
* | ||
@@ -22,2 +22,2 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
export {onLCP as getLCP} from './onLCP.js'; | ||
export {onTTFB as getTFB} from './onTTFB.js'; | ||
export {onTTFB as getTTFB} from './onTTFB.js'; |
@@ -17,7 +17,7 @@ /* | ||
import {Metric, ReportHandler} from '../types.js'; | ||
import {Metric, ReportCallback} from '../types.js'; | ||
export const bindReporter = ( | ||
callback: ReportHandler, | ||
callback: ReportCallback, | ||
metric: Metric, | ||
@@ -24,0 +24,0 @@ reportAllChanges?: boolean, |
@@ -23,3 +23,3 @@ /* | ||
import {onFCP} from './onFCP.js'; | ||
import {LayoutShift, Metric, ReportHandler} from './types.js'; | ||
import {LayoutShift, Metric, ReportCallback, ReportOpts} from './types.js'; | ||
@@ -30,3 +30,6 @@ | ||
export const onCLS = (onReport: ReportHandler, reportAllChanges?: boolean) => { | ||
export const onCLS = (onReport: ReportCallback, opts?: ReportOpts) => { | ||
// Set defaults | ||
opts = opts || {}; | ||
// Start monitoring FCP so we can only report CLS if FCP is also reported. | ||
@@ -41,3 +44,3 @@ // Note: this is done to match the current behavior of CrUX. | ||
const onReportWrapped: ReportHandler = (arg) => { | ||
const onReportWrapped: ReportCallback = (arg) => { | ||
if (fcpValue > -1) { | ||
@@ -87,3 +90,3 @@ onReport(arg); | ||
if (po) { | ||
report = bindReporter(onReportWrapped, metric, reportAllChanges); | ||
report = bindReporter(onReportWrapped, metric, opts.reportAllChanges); | ||
@@ -99,5 +102,5 @@ onHidden(() => { | ||
metric = initMetric('CLS', 0); | ||
report = bindReporter(onReportWrapped, metric, reportAllChanges); | ||
report = bindReporter(onReportWrapped, metric, opts!.reportAllChanges); | ||
}); | ||
} | ||
}; |
@@ -22,6 +22,9 @@ /* | ||
import {observe} from './lib/observe.js'; | ||
import {Metric, ReportHandler} from './types.js'; | ||
import {Metric, ReportCallback, ReportOpts} from './types.js'; | ||
export const onFCP = (onReport: ReportHandler, reportAllChanges?: boolean) => { | ||
export const onFCP = (onReport: ReportCallback, opts?: ReportOpts) => { | ||
// Set defaults | ||
opts = opts || {}; | ||
const visibilityWatcher = getVisibilityWatcher(); | ||
@@ -60,3 +63,3 @@ let metric = initMetric('FCP'); | ||
if (fcpEntry || po) { | ||
report = bindReporter(onReport, metric, reportAllChanges); | ||
report = bindReporter(onReport, metric, opts.reportAllChanges); | ||
@@ -69,3 +72,3 @@ if (fcpEntry) { | ||
metric = initMetric('FCP'); | ||
report = bindReporter(onReport, metric, reportAllChanges); | ||
report = bindReporter(onReport, metric, opts!.reportAllChanges); | ||
requestAnimationFrame(() => { | ||
@@ -72,0 +75,0 @@ requestAnimationFrame(() => { |
@@ -24,6 +24,9 @@ /* | ||
import {firstInputPolyfill, resetFirstInputPolyfill} from './lib/polyfills/firstInputPolyfill.js'; | ||
import {FirstInputPolyfillCallback, Metric, PerformanceEventTiming, ReportHandler} from './types.js'; | ||
import {FirstInputPolyfillCallback, Metric, PerformanceEventTiming, ReportCallback, ReportOpts} from './types.js'; | ||
export const onFID = (onReport: ReportHandler, reportAllChanges?: boolean) => { | ||
export const onFID = (onReport: ReportCallback, opts?: ReportOpts) => { | ||
// Set defaults | ||
opts = opts || {}; | ||
const visibilityWatcher = getVisibilityWatcher(); | ||
@@ -47,3 +50,3 @@ let metric = initMetric('FID'); | ||
const po = observe('first-input', handleEntries); | ||
report = bindReporter(onReport, metric, reportAllChanges); | ||
report = bindReporter(onReport, metric, opts.reportAllChanges); | ||
@@ -64,3 +67,3 @@ if (po) { | ||
metric = initMetric('FID'); | ||
report = bindReporter(onReport, metric, reportAllChanges); | ||
report = bindReporter(onReport, metric, opts!.reportAllChanges); | ||
window.webVitals.resetFirstInputPolyfill(); | ||
@@ -74,3 +77,3 @@ window.webVitals.firstInputPolyfill(handleEntry as FirstInputPolyfillCallback); | ||
metric = initMetric('FID'); | ||
report = bindReporter(onReport, metric, reportAllChanges); | ||
report = bindReporter(onReport, metric, opts!.reportAllChanges); | ||
resetFirstInputPolyfill(); | ||
@@ -77,0 +80,0 @@ firstInputPolyfill(handleEntry as FirstInputPolyfillCallback); |
@@ -23,3 +23,3 @@ /* | ||
import {getInteractionCount, initInteractionCountPolyfill} from './lib/polyfills/interactionCountPolyfill.js'; | ||
import {Metric, PerformanceEventTiming, ReportHandler} from './types.js'; | ||
import {Metric, PerformanceEventTiming, ReportCallback, ReportOpts} from './types.js'; | ||
@@ -108,3 +108,6 @@ interface Interaction { | ||
export const onINP = (onReport: ReportHandler, reportAllChanges?: boolean) => { | ||
export const onINP = (onReport: ReportCallback, opts?: ReportOpts) => { | ||
// Set defaults | ||
opts = opts || {}; | ||
// TODO(philipwalton): remove once the polyfill is no longer needed. | ||
@@ -139,6 +142,6 @@ initInteractionCountPolyfill(); | ||
// gained. | ||
durationThreshold: 40, | ||
durationThreshold: opts.durationThreshold || 40, | ||
} as PerformanceObserverInit); | ||
report = bindReporter(onReport, metric, reportAllChanges); | ||
report = bindReporter(onReport, metric, opts.reportAllChanges); | ||
@@ -166,5 +169,5 @@ if (po) { | ||
metric = initMetric('INP'); | ||
report = bindReporter(onReport, metric, reportAllChanges); | ||
report = bindReporter(onReport, metric, opts!.reportAllChanges); | ||
}); | ||
} | ||
}; |
@@ -23,3 +23,3 @@ /* | ||
import {onHidden} from './lib/onHidden.js'; | ||
import {Metric, ReportHandler} from './types.js'; | ||
import {Metric, ReportCallback, ReportOpts} from './types.js'; | ||
@@ -29,3 +29,6 @@ | ||
export const onLCP = (onReport: ReportHandler, reportAllChanges?: boolean) => { | ||
export const onLCP = (onReport: ReportCallback, opts?: ReportOpts) => { | ||
// Set defaults | ||
opts = opts || {}; | ||
const visibilityWatcher = getVisibilityWatcher(); | ||
@@ -55,3 +58,3 @@ let metric = initMetric('LCP'); | ||
if (po) { | ||
report = bindReporter(onReport, metric, reportAllChanges); | ||
report = bindReporter(onReport, metric, opts.reportAllChanges); | ||
@@ -78,3 +81,3 @@ const stopListening = () => { | ||
metric = initMetric('LCP'); | ||
report = bindReporter(onReport, metric, reportAllChanges); | ||
report = bindReporter(onReport, metric, opts!.reportAllChanges); | ||
requestAnimationFrame(() => { | ||
@@ -81,0 +84,0 @@ requestAnimationFrame(() => { |
@@ -21,3 +21,3 @@ /* | ||
import {getNavigationEntry} from './lib/getNavigationEntry.js'; | ||
import {ReportHandler} from './types.js'; | ||
import {ReportCallback, ReportOpts} from './types.js'; | ||
@@ -35,5 +35,8 @@ | ||
export const onTTFB = (onReport: ReportHandler, reportAllChanges?: boolean) => { | ||
export const onTTFB = (onReport: ReportCallback, opts?: ReportOpts) => { | ||
// Set defaults | ||
opts = opts || {}; | ||
let metric = initMetric('TTFB'); | ||
let report = bindReporter(onReport, metric, reportAllChanges); | ||
let report = bindReporter(onReport, metric, opts.reportAllChanges); | ||
@@ -60,3 +63,3 @@ afterLoad(() => { | ||
metric = initMetric('TTFB'); | ||
report = bindReporter(onReport, metric, reportAllChanges); | ||
report = bindReporter(onReport, metric, opts!.reportAllChanges); | ||
metric.value = performance.now() - event.timeStamp; | ||
@@ -63,0 +66,0 @@ report(true); |
@@ -49,7 +49,12 @@ /* | ||
export interface ReportHandler { | ||
export interface ReportCallback { | ||
(metric: Metric): void; | ||
} | ||
interface PerformanceEntryMap { | ||
export interface ReportOpts { | ||
reportAllChanges?: boolean; | ||
durationThreshold?: number; | ||
} | ||
interface PerformanceEntryMap { | ||
'navigation': PerformanceNavigationTiming; | ||
@@ -56,0 +61,0 @@ 'resource': PerformanceResourceTiming; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
183098
2565
780
0