web-vitals
Advanced tools
Comparing version 3.1.0 to 3.1.1
@@ -20,3 +20,3 @@ /* | ||
const getLargestLayoutShiftEntry = (entries) => { | ||
return entries.reduce((a, b) => a && a.value > b.value ? a : b); | ||
return entries.reduce((a, b) => (a && a.value > b.value ? a : b)); | ||
}; | ||
@@ -23,0 +23,0 @@ const getLargestLayoutShiftSource = (sources) => { |
@@ -23,4 +23,6 @@ /* | ||
// Sort by: 1) duration (DESC), then 2) processing time (DESC) | ||
return b.duration - a.duration || (b.processingEnd - b.processingStart) - | ||
(a.processingEnd - a.processingStart); | ||
return (b.duration - a.duration || | ||
b.processingEnd - | ||
b.processingStart - | ||
(a.processingEnd - a.processingStart)); | ||
})[0]; | ||
@@ -27,0 +29,0 @@ metric.attribution = { |
@@ -25,10 +25,13 @@ /* | ||
const lcpEntry = metric.entries[metric.entries.length - 1]; | ||
const lcpResourceEntry = lcpEntry.url && performance | ||
.getEntriesByType('resource') | ||
.filter((e) => e.name === lcpEntry.url)[0]; | ||
const lcpResourceEntry = lcpEntry.url && | ||
performance | ||
.getEntriesByType('resource') | ||
.filter((e) => e.name === lcpEntry.url)[0]; | ||
const ttfb = Math.max(0, navigationEntry.responseStart - activationStart); | ||
const lcpRequestStart = Math.max(ttfb, | ||
// Prefer `requestStart` (if TOA is set), otherwise use `startTime`. | ||
lcpResourceEntry ? (lcpResourceEntry.requestStart || | ||
lcpResourceEntry.startTime) - activationStart : 0); | ||
lcpResourceEntry | ||
? (lcpResourceEntry.requestStart || lcpResourceEntry.startTime) - | ||
activationStart | ||
: 0); | ||
const lcpResponseEnd = Math.max(lcpRequestStart, lcpResourceEntry ? lcpResourceEntry.responseEnd - activationStart : 0); | ||
@@ -35,0 +38,0 @@ const lcpRenderTime = Math.max(lcpResponseEnd, lcpEntry ? lcpEntry.startTime - activationStart : 0); |
@@ -19,3 +19,3 @@ /* | ||
const navEntry = getNavigationEntry(); | ||
return navEntry && navEntry.activationStart || 0; | ||
return (navEntry && navEntry.activationStart) || 0; | ||
}; |
@@ -22,3 +22,3 @@ /* | ||
startTime: 0, | ||
type: type == 2 ? 'back_forward' : (type === 1 ? 'reload' : 'navigate'), | ||
type: type == 2 ? 'back_forward' : type === 1 ? 'reload' : 'navigate', | ||
}; | ||
@@ -35,10 +35,12 @@ for (const key in timing) { | ||
if (window.__WEB_VITALS_POLYFILL__) { | ||
return window.performance && (performance.getEntriesByType && | ||
performance.getEntriesByType('navigation')[0] || | ||
getNavigationEntryFromPerformanceTiming()); | ||
return (window.performance && | ||
((performance.getEntriesByType && | ||
performance.getEntriesByType('navigation')[0]) || | ||
getNavigationEntryFromPerformanceTiming())); | ||
} | ||
else { | ||
return window.performance && (performance.getEntriesByType && | ||
return (window.performance && | ||
performance.getEntriesByType && | ||
performance.getEntriesByType('navigation')[0]); | ||
} | ||
}; |
@@ -18,4 +18,5 @@ /* | ||
const name = node.nodeName; | ||
return node.nodeType === 1 ? | ||
name.toLowerCase() : name.toUpperCase().replace(/^#/, ''); | ||
return node.nodeType === 1 | ||
? name.toLowerCase() | ||
: name.toUpperCase().replace(/^#/, ''); | ||
}; | ||
@@ -27,4 +28,8 @@ export const getSelector = (node, maxLen) => { | ||
const el = node; | ||
const part = el.id ? '#' + el.id : getName(el) + ((el.className && el.className.length) ? | ||
'.' + el.className.replace(/\s+/g, '.') : ''); | ||
const part = el.id | ||
? '#' + el.id | ||
: getName(el) + | ||
(el.className && el.className.length | ||
? '.' + el.className.replace(/\s+/g, '.') | ||
: ''); | ||
if (sel.length + part.length > (maxLen || 100) - 1) | ||
@@ -31,0 +36,0 @@ return sel || part; |
@@ -24,4 +24,5 @@ /* | ||
// event logic below). | ||
return document.visibilityState === 'hidden' && | ||
!document.prerendering ? 0 : Infinity; | ||
return document.visibilityState === 'hidden' && !document.prerendering | ||
? 0 | ||
: Infinity; | ||
}; | ||
@@ -86,4 +87,4 @@ const onVisibilityUpdate = (event) => { | ||
return firstHiddenTime; | ||
} | ||
}, | ||
}; | ||
}; |
@@ -34,4 +34,3 @@ /* | ||
else { | ||
navigationType = | ||
navEntry.type.replace(/_/g, '-'); | ||
navigationType = navEntry.type.replace(/_/g, '-'); | ||
} | ||
@@ -38,0 +37,0 @@ } |
export interface OnHiddenCallback { | ||
(event: Event): void; | ||
} | ||
export declare const onHidden: (cb: OnHiddenCallback, once?: boolean) => void; | ||
export declare const onHidden: (cb: OnHiddenCallback) => void; |
@@ -16,10 +16,6 @@ /* | ||
*/ | ||
export const onHidden = (cb, once) => { | ||
export const onHidden = (cb) => { | ||
const onHiddenOrPageHide = (event) => { | ||
if (event.type === 'pagehide' || document.visibilityState === 'hidden') { | ||
cb(event); | ||
if (once) { | ||
removeEventListener('visibilitychange', onHiddenOrPageHide, true); | ||
removeEventListener('pagehide', onHiddenOrPageHide, true); | ||
} | ||
} | ||
@@ -26,0 +22,0 @@ }; |
@@ -44,3 +44,3 @@ /* | ||
firstInputDelay = delay; | ||
firstInputTimeStamp = new Date; | ||
firstInputTimeStamp = new Date(); | ||
eachEventType(removeEventListener); | ||
@@ -129,3 +129,3 @@ reportFirstInputDelayIfRecordedAndValid(); | ||
const isEpochTime = event.timeStamp > 1e12; | ||
const now = isEpochTime ? new Date : performance.now(); | ||
const now = isEpochTime ? new Date() : performance.now(); | ||
// Input delay is the delta between when the system received the event | ||
@@ -147,9 +147,4 @@ // (e.g. event.timeStamp) and when it could run the callback (e.g. `now`). | ||
const eachEventType = (callback) => { | ||
const eventTypes = [ | ||
'mousedown', | ||
'keydown', | ||
'touchstart', | ||
'pointerdown', | ||
]; | ||
const eventTypes = ['mousedown', 'keydown', 'touchstart', 'pointerdown']; | ||
eventTypes.forEach((type) => callback(type, onInput, listenerOpts)); | ||
}; |
@@ -25,4 +25,5 @@ /* | ||
maxKnownInteractionId = Math.max(maxKnownInteractionId, e.interactionId); | ||
interactionCountEstimate = maxKnownInteractionId ? | ||
(maxKnownInteractionId - minKnownInteractionId) / 7 + 1 : 0; | ||
interactionCountEstimate = maxKnownInteractionId | ||
? (maxKnownInteractionId - minKnownInteractionId) / 7 + 1 | ||
: 0; | ||
} | ||
@@ -29,0 +30,0 @@ }); |
@@ -19,6 +19,6 @@ /* | ||
import { observe } from './lib/observe.js'; | ||
import { onHidden } from './lib/onHidden.js'; | ||
import { bindReporter } from './lib/bindReporter.js'; | ||
import { doubleRAF } from './lib/doubleRAF.js'; | ||
import { whenActivated } from './lib/whenActivated.js'; | ||
import { onHidden } from './lib/onHidden.js'; | ||
import { runOnce } from './lib/runOnce.js'; | ||
import { onFCP } from './onFCP.js'; | ||
@@ -49,15 +49,11 @@ /** | ||
opts = opts || {}; | ||
whenActivated(() => { | ||
// Start monitoring FCP so we can only report CLS if FCP is also reported. | ||
// Note: this is done to match the current behavior of CrUX. | ||
onFCP(runOnce(() => { | ||
// https://web.dev/cls/#what-is-a-good-cls-score | ||
const thresholds = [0.1, 0.25]; | ||
let metric = initMetric('CLS'); | ||
let metric = initMetric('CLS', 0); | ||
let report; | ||
let fcpValue = -1; | ||
let sessionValue = 0; | ||
let sessionEntries = []; | ||
const onReportWrapped = (arg) => { | ||
if (fcpValue > -1) { | ||
onReport(arg); | ||
} | ||
}; | ||
// const handleEntries = (entries: Metric['entries']) => { | ||
@@ -84,26 +80,15 @@ const handleEntries = (entries) => { | ||
} | ||
// If the current session value is larger than the current CLS value, | ||
// update CLS and the entries contributing to it. | ||
if (sessionValue > metric.value) { | ||
metric.value = sessionValue; | ||
metric.entries = sessionEntries; | ||
report(); | ||
} | ||
} | ||
}); | ||
// If the current session value is larger than the current CLS value, | ||
// update CLS and the entries contributing to it. | ||
if (sessionValue > metric.value) { | ||
metric.value = sessionValue; | ||
metric.entries = sessionEntries; | ||
report(); | ||
} | ||
}; | ||
const po = observe('layout-shift', handleEntries); | ||
if (po) { | ||
report = bindReporter(onReportWrapped, metric, thresholds, opts.reportAllChanges); | ||
// Start monitoring FCP so we can only report CLS if FCP is also reported. | ||
// Note: this is done to match the current behavior of CrUX. | ||
// Also, if there have not been any layout shifts when FCP is dispatched, | ||
// call "report" with a zero value | ||
onFCP((fcpMetric) => { | ||
fcpValue = fcpMetric.value; | ||
if (metric.value < 0) { | ||
metric.value = 0; | ||
report(); | ||
} | ||
}); | ||
report = bindReporter(onReport, metric, thresholds, opts.reportAllChanges); | ||
onHidden(() => { | ||
@@ -117,9 +102,12 @@ handleEntries(po.takeRecords()); | ||
sessionValue = 0; | ||
fcpValue = -1; | ||
metric = initMetric('CLS', 0); | ||
report = bindReporter(onReportWrapped, metric, thresholds, opts.reportAllChanges); | ||
report = bindReporter(onReport, metric, thresholds, opts.reportAllChanges); | ||
doubleRAF(() => report()); | ||
}); | ||
// Queue a task to report (if nothing else triggers a report first). | ||
// This allows CLS to be reported as soon as FCP fires when | ||
// `reportAllChanges` is true. | ||
setTimeout(report, 0); | ||
} | ||
}); | ||
})); | ||
}; |
@@ -22,3 +22,4 @@ /* | ||
import { onHidden } from './lib/onHidden.js'; | ||
import { firstInputPolyfill, resetFirstInputPolyfill } from './lib/polyfills/firstInputPolyfill.js'; | ||
import { firstInputPolyfill, resetFirstInputPolyfill, } from './lib/polyfills/firstInputPolyfill.js'; | ||
import { runOnce } from './lib/runOnce.js'; | ||
import { whenActivated } from './lib/whenActivated.js'; | ||
@@ -57,6 +58,6 @@ /** | ||
if (po) { | ||
onHidden(() => { | ||
onHidden(runOnce(() => { | ||
handleEntries(po.takeRecords()); | ||
po.disconnect(); | ||
}, true); | ||
})); | ||
} | ||
@@ -63,0 +64,0 @@ if (window.__WEB_VITALS_POLYFILL__) { |
@@ -21,3 +21,3 @@ /* | ||
import { onHidden } from './lib/onHidden.js'; | ||
import { getInteractionCount, initInteractionCountPolyfill } from './lib/polyfills/interactionCountPolyfill.js'; | ||
import { getInteractionCount, initInteractionCountPolyfill, } from './lib/polyfills/interactionCountPolyfill.js'; | ||
import { whenActivated } from './lib/whenActivated.js'; | ||
@@ -61,4 +61,3 @@ // Used to store the interaction count after a bfcache restore, since p98 | ||
existingInteraction.entries.push(entry); | ||
existingInteraction.latency = | ||
Math.max(existingInteraction.latency, entry.duration); | ||
existingInteraction.latency = Math.max(existingInteraction.latency, entry.duration); | ||
} | ||
@@ -142,4 +141,4 @@ else { | ||
return interaction.entries.some((prevEntry) => { | ||
return entry.duration === prevEntry.duration && | ||
entry.startTime === prevEntry.startTime; | ||
return (entry.duration === prevEntry.duration && | ||
entry.startTime === prevEntry.startTime); | ||
}); | ||
@@ -146,0 +145,0 @@ }); |
@@ -24,2 +24,3 @@ /* | ||
import { onHidden } from './lib/onHidden.js'; | ||
import { runOnce } from './lib/runOnce.js'; | ||
import { whenActivated } from './lib/whenActivated.js'; | ||
@@ -68,3 +69,3 @@ const reportedMetricIDs = {}; | ||
report = bindReporter(onReport, metric, thresholds, opts.reportAllChanges); | ||
const stopListening = () => { | ||
const stopListening = runOnce(() => { | ||
if (!reportedMetricIDs[metric.id]) { | ||
@@ -76,3 +77,3 @@ handleEntries(po.takeRecords()); | ||
} | ||
}; | ||
}); | ||
// Stop listening after input. Note: while scrolling is an input that | ||
@@ -82,5 +83,5 @@ // stops LCP observation, it's unreliable since it can be programmatically | ||
['keydown', 'click'].forEach((type) => { | ||
addEventListener(type, stopListening, { once: true, capture: true }); | ||
addEventListener(type, stopListening, true); | ||
}); | ||
onHidden(stopListening, true); | ||
onHidden(stopListening); | ||
// Only report after a bfcache restore if the `PerformanceObserver` | ||
@@ -87,0 +88,0 @@ // successfully registered. |
@@ -16,3 +16,3 @@ /* | ||
*/ | ||
import { firstInputPolyfill, resetFirstInputPolyfill } from './lib/polyfills/firstInputPolyfill.js'; | ||
import { firstInputPolyfill, resetFirstInputPolyfill, } from './lib/polyfills/firstInputPolyfill.js'; | ||
import { getFirstHiddenTime } from './lib/polyfills/getFirstHiddenTimePolyfill.js'; | ||
@@ -19,0 +19,0 @@ resetFirstInputPolyfill(); |
@@ -22,5 +22,5 @@ import { FirstInputPolyfillCallback } from './types/polyfills.js'; | ||
interface PerformanceEntryMap { | ||
'navigation': PerformanceNavigationTiming; | ||
'resource': PerformanceResourceTiming; | ||
'paint': PerformancePaintTiming; | ||
navigation: PerformanceNavigationTiming; | ||
resource: PerformanceResourceTiming; | ||
paint: PerformancePaintTiming; | ||
} | ||
@@ -27,0 +27,0 @@ declare global { |
@@ -1,1 +0,1 @@ | ||
var webVitals=function(e){"use strict";var t,n,r,i,a,o=function(){return window.performance&&performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]},u=function(e){if("loading"===document.readyState)return"loading";var t=o();if(t){if(e<t.domInteractive)return"loading";if(0===t.domContentLoadedEventStart||e<t.domContentLoadedEventStart)return"dom-interactive";if(0===t.domComplete||e<t.domComplete)return"dom-content-loaded"}return"complete"},c=function(e){var t=e.nodeName;return 1===e.nodeType?t.toLowerCase():t.toUpperCase().replace(/^#/,"")},s=function(e,t){var n="";try{for(;e&&9!==e.nodeType;){var r=e,i=r.id?"#"+r.id:c(r)+(r.className&&r.className.length?"."+r.className.replace(/\s+/g,"."):"");if(n.length+i.length>(t||100)-1)return n||i;if(n=n?i+">"+n:i,r.id)break;e=r.parentNode}}catch(e){}return n},f=-1,d=function(){return f},l=function(e){addEventListener("pageshow",(function(t){t.persisted&&(f=t.timeStamp,e(t))}),!0)},v=function(){var e=o();return e&&e.activationStart||0},m=function(e,t){var n=o(),r="navigate";return d()>=0?r="back-forward-cache":n&&(r=document.prerendering||v()>0?"prerender":document.wasDiscarded?"restore":n.type.replace(/_/g,"-")),{name:e,value:void 0===t?-1:t,rating:"good",delta:0,entries:[],id:"v3-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:r}},p=function(e,t,n){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var r=new PerformanceObserver((function(e){Promise.resolve().then((function(){t(e.getEntries())}))}));return r.observe(Object.assign({type:e,buffered:!0},n||{})),r}}catch(e){}},h=function(e,t){var n=function n(r){"pagehide"!==r.type&&"hidden"!==document.visibilityState||(e(r),t&&(removeEventListener("visibilitychange",n,!0),removeEventListener("pagehide",n,!0)))};addEventListener("visibilitychange",n,!0),addEventListener("pagehide",n,!0)},g=function(e,t,n,r){var i,a;return function(o){t.value>=0&&(o||r)&&((a=t.value-(i||0))||void 0===i)&&(i=t.value,t.delta=a,t.rating=function(e,t){return e>t[1]?"poor":e>t[0]?"needs-improvement":"good"}(t.value,n),e(t))}},T=function(e){requestAnimationFrame((function(){return requestAnimationFrame((function(){return e()}))}))},y=function(e){document.prerendering?addEventListener("prerenderingchange",(function(){return e()}),!0):e()},E=-1,S=function(){return"hidden"!==document.visibilityState||document.prerendering?1/0:0},b=function(e){"hidden"===document.visibilityState&&E>-1&&(E="visibilitychange"===e.type?e.timeStamp:0,C())},L=function(){addEventListener("visibilitychange",b,!0),addEventListener("prerenderingchange",b,!0)},C=function(){removeEventListener("visibilitychange",b,!0),removeEventListener("prerenderingchange",b,!0)},w=function(){return E<0&&(E=S(),L(),l((function(){setTimeout((function(){E=S(),L()}),0)}))),{get firstHiddenTime(){return E}}},M=function(e,t){t=t||{},y((function(){var n,r=[1800,3e3],i=w(),a=m("FCP"),o=p("paint",(function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(o.disconnect(),e.startTime<i.firstHiddenTime&&(a.value=Math.max(e.startTime-v(),0),a.entries.push(e),n(!0)))}))}));o&&(n=g(e,a,r,t.reportAllChanges),l((function(i){a=m("FCP"),n=g(e,a,r,t.reportAllChanges),T((function(){a.value=performance.now()-i.timeStamp,n(!0)}))})))}))},F={passive:!0,capture:!0},P=new Date,A=function(e,i){t||(t=i,n=e,r=new Date,B(removeEventListener),I())},I=function(){if(n>=0&&n<r-P){var e={entryType:"first-input",name:t.type,target:t.target,cancelable:t.cancelable,startTime:t.timeStamp,processingStart:t.timeStamp+n};i.forEach((function(t){t(e)})),i=[]}},x=function(e){if(e.cancelable){var t=(e.timeStamp>1e12?new Date:performance.now())-e.timeStamp;"pointerdown"==e.type?function(e,t){var n=function(){A(e,t),i()},r=function(){i()},i=function(){removeEventListener("pointerup",n,F),removeEventListener("pointercancel",r,F)};addEventListener("pointerup",n,F),addEventListener("pointercancel",r,F)}(t,e):A(t,e)}},B=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(t){return e(t,x,F)}))},D=function(e,r){r=r||{},y((function(){var a,o=[100,300],u=w(),c=m("FID"),s=function(e){e.startTime<u.firstHiddenTime&&(c.value=e.processingStart-e.startTime,c.entries.push(e),a(!0))},f=function(e){e.forEach(s)},d=p("first-input",f);a=g(e,c,o,r.reportAllChanges),d&&h((function(){f(d.takeRecords()),d.disconnect()}),!0),d&&l((function(){var u;c=m("FID"),a=g(e,c,o,r.reportAllChanges),i=[],n=-1,t=null,B(addEventListener),u=s,i.push(u),I()}))}))},k=0,N=1/0,R=0,q=function(e){e.forEach((function(e){e.interactionId&&(N=Math.min(N,e.interactionId),R=Math.max(R,e.interactionId),k=R?(R-N)/7+1:0)}))},H=function(){return a?k:performance.interactionCount||0},O=function(){"interactionCount"in performance||a||(a=p("event",q,{type:"event",buffered:!0,durationThreshold:0}))},_=0,j=function(){return H()-_},V=[],U={},z=function(e){var t=V[V.length-1],n=U[e.interactionId];if(n||V.length<10||e.duration>t.latency){if(n)n.entries.push(e),n.latency=Math.max(n.latency,e.duration);else{var r={id:e.interactionId,latency:e.duration,entries:[e]};U[r.id]=r,V.push(r)}V.sort((function(e,t){return t.latency-e.latency})),V.splice(10).forEach((function(e){delete U[e.id]}))}},G=function(e,t){t=t||{},y((function(){var n=[200,500];O();var r,i=m("INP"),a=function(e){e.forEach((function(e){(e.interactionId&&z(e),"first-input"===e.entryType)&&(!V.some((function(t){return t.entries.some((function(t){return e.duration===t.duration&&e.startTime===t.startTime}))}))&&z(e))}));var t,n=(t=Math.min(V.length-1,Math.floor(j()/50)),V[t]);n&&n.latency!==i.value&&(i.value=n.latency,i.entries=n.entries,r())},o=p("event",a,{durationThreshold:t.durationThreshold||40});r=g(e,i,n,t.reportAllChanges),o&&(o.observe({type:"first-input",buffered:!0}),h((function(){a(o.takeRecords()),i.value<0&&j()>0&&(i.value=0,i.entries=[]),r(!0)})),l((function(){V=[],_=H(),i=m("INP"),r=g(e,i,n,t.reportAllChanges)})))}))},J={},K=function e(t){document.prerendering?y((function(){return e(t)})):"complete"!==document.readyState?addEventListener("load",(function(){return e(t)}),!0):setTimeout(t,0)},Q=function(e,t){t=t||{};var n=[800,1800],r=m("TTFB"),i=g(e,r,n,t.reportAllChanges);K((function(){var a=o();if(a){var u=a.responseStart;if(u<=0||u>performance.now())return;r.value=Math.max(u-v(),0),r.entries=[a],i(!0),l((function(){r=m("TTFB",0),(i=g(e,r,n,t.reportAllChanges))(!0)}))}}))};return e.onCLS=function(e,t){!function(e,t){t=t||{},y((function(){var n,r=[.1,.25],i=m("CLS"),a=-1,o=0,u=[],c=function(t){a>-1&&e(t)},s=function(e){e.forEach((function(e){if(!e.hadRecentInput){var t=u[0],r=u[u.length-1];o&&e.startTime-r.startTime<1e3&&e.startTime-t.startTime<5e3?(o+=e.value,u.push(e)):(o=e.value,u=[e]),o>i.value&&(i.value=o,i.entries=u,n())}}))},f=p("layout-shift",s);f&&(n=g(c,i,r,t.reportAllChanges),M((function(e){a=e.value,i.value<0&&(i.value=0,n())})),h((function(){s(f.takeRecords()),n(!0)})),l((function(){o=0,a=-1,i=m("CLS",0),n=g(c,i,r,t.reportAllChanges),T((function(){return n()}))})))}))}((function(t){!function(e){if(e.entries.length){var t=e.entries.reduce((function(e,t){return e&&e.value>t.value?e:t}));if(t&&t.sources&&t.sources.length){var n=(r=t.sources).find((function(e){return e.node&&1===e.node.nodeType}))||r[0];if(n)return void(e.attribution={largestShiftTarget:s(n.node),largestShiftTime:t.startTime,largestShiftValue:t.value,largestShiftSource:n,largestShiftEntry:t,loadState:u(t.startTime)})}}var r;e.attribution={}}(t),e(t)}),t)},e.onFCP=function(e,t){M((function(t){!function(e){if(e.entries.length){var t=o(),n=e.entries[e.entries.length-1];if(t){var r=t.activationStart||0,i=Math.max(0,t.responseStart-r);return void(e.attribution={timeToFirstByte:i,firstByteToFCP:e.value-i,loadState:u(e.entries[0].startTime),navigationEntry:t,fcpEntry:n})}}e.attribution={timeToFirstByte:0,firstByteToFCP:e.value,loadState:u(d())}}(t),e(t)}),t)},e.onFID=function(e,t){D((function(t){!function(e){var t=e.entries[0];e.attribution={eventTarget:s(t.target),eventType:t.name,eventTime:t.startTime,eventEntry:t,loadState:u(t.startTime)}}(t),e(t)}),t)},e.onINP=function(e,t){G((function(t){!function(e){if(e.entries.length){var t=e.entries.sort((function(e,t){return t.duration-e.duration||t.processingEnd-t.processingStart-(e.processingEnd-e.processingStart)}))[0];e.attribution={eventTarget:s(t.target),eventType:t.name,eventTime:t.startTime,eventEntry:t,loadState:u(t.startTime)}}else e.attribution={}}(t),e(t)}),t)},e.onLCP=function(e,t){!function(e,t){t=t||{},y((function(){var n,r=[2500,4e3],i=w(),a=m("LCP"),o=function(e){var t=e[e.length-1];if(t){var r=Math.max(t.startTime-v(),0);r<i.firstHiddenTime&&(a.value=r,a.entries=[t],n())}},u=p("largest-contentful-paint",o);if(u){n=g(e,a,r,t.reportAllChanges);var c=function(){J[a.id]||(o(u.takeRecords()),u.disconnect(),J[a.id]=!0,n(!0))};["keydown","click"].forEach((function(e){addEventListener(e,c,{once:!0,capture:!0})})),h(c,!0),l((function(i){a=m("LCP"),n=g(e,a,r,t.reportAllChanges),T((function(){a.value=performance.now()-i.timeStamp,J[a.id]=!0,n(!0)}))}))}}))}((function(t){!function(e){if(e.entries.length){var t=o();if(t){var n=t.activationStart||0,r=e.entries[e.entries.length-1],i=r.url&&performance.getEntriesByType("resource").filter((function(e){return e.name===r.url}))[0],a=Math.max(0,t.responseStart-n),u=Math.max(a,i?(i.requestStart||i.startTime)-n:0),c=Math.max(u,i?i.responseEnd-n:0),f=Math.max(c,r?r.startTime-n:0),d={element:s(r.element),timeToFirstByte:a,resourceLoadDelay:u-a,resourceLoadTime:c-u,elementRenderDelay:f-c,navigationEntry:t,lcpEntry:r};return r.url&&(d.url=r.url),i&&(d.lcpResourceEntry=i),void(e.attribution=d)}}e.attribution={timeToFirstByte:0,resourceLoadDelay:0,resourceLoadTime:0,elementRenderDelay:e.value}}(t),e(t)}),t)},e.onTTFB=function(e,t){Q((function(t){!function(e){if(e.entries.length){var t=e.entries[0],n=t.activationStart||0,r=Math.max(t.domainLookupStart-n,0),i=Math.max(t.connectStart-n,0),a=Math.max(t.requestStart-n,0);e.attribution={waitingTime:r,dnsTime:i-r,connectionTime:a-i,requestTime:e.value-a,navigationEntry:t}}else e.attribution={waitingTime:0,dnsTime:0,connectionTime:0,requestTime:0}}(t),e(t)}),t)},Object.defineProperty(e,"__esModule",{value:!0}),e}({}); | ||
var webVitals=function(e){"use strict";var t,n,r,i,a,o=function(){return window.performance&&performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]},u=function(e){if("loading"===document.readyState)return"loading";var t=o();if(t){if(e<t.domInteractive)return"loading";if(0===t.domContentLoadedEventStart||e<t.domContentLoadedEventStart)return"dom-interactive";if(0===t.domComplete||e<t.domComplete)return"dom-content-loaded"}return"complete"},c=function(e){var t=e.nodeName;return 1===e.nodeType?t.toLowerCase():t.toUpperCase().replace(/^#/,"")},s=function(e,t){var n="";try{for(;e&&9!==e.nodeType;){var r=e,i=r.id?"#"+r.id:c(r)+(r.className&&r.className.length?"."+r.className.replace(/\s+/g,"."):"");if(n.length+i.length>(t||100)-1)return n||i;if(n=n?i+">"+n:i,r.id)break;e=r.parentNode}}catch(e){}return n},f=-1,d=function(){return f},l=function(e){addEventListener("pageshow",(function(t){t.persisted&&(f=t.timeStamp,e(t))}),!0)},m=function(){var e=o();return e&&e.activationStart||0},v=function(e,t){var n=o(),r="navigate";return d()>=0?r="back-forward-cache":n&&(r=document.prerendering||m()>0?"prerender":document.wasDiscarded?"restore":n.type.replace(/_/g,"-")),{name:e,value:void 0===t?-1:t,rating:"good",delta:0,entries:[],id:"v3-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:r}},p=function(e,t,n){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var r=new PerformanceObserver((function(e){Promise.resolve().then((function(){t(e.getEntries())}))}));return r.observe(Object.assign({type:e,buffered:!0},n||{})),r}}catch(e){}},h=function(e,t,n,r){var i,a;return function(o){t.value>=0&&(o||r)&&((a=t.value-(i||0))||void 0===i)&&(i=t.value,t.delta=a,t.rating=function(e,t){return e>t[1]?"poor":e>t[0]?"needs-improvement":"good"}(t.value,n),e(t))}},g=function(e){requestAnimationFrame((function(){return requestAnimationFrame((function(){return e()}))}))},T=function(e){var t=function(t){"pagehide"!==t.type&&"hidden"!==document.visibilityState||e(t)};addEventListener("visibilitychange",t,!0),addEventListener("pagehide",t,!0)},y=function(e){var t=!1;return function(n){t||(e(n),t=!0)}},E=-1,S=function(){return"hidden"!==document.visibilityState||document.prerendering?1/0:0},b=function(e){"hidden"===document.visibilityState&&E>-1&&(E="visibilitychange"===e.type?e.timeStamp:0,L())},C=function(){addEventListener("visibilitychange",b,!0),addEventListener("prerenderingchange",b,!0)},L=function(){removeEventListener("visibilitychange",b,!0),removeEventListener("prerenderingchange",b,!0)},w=function(){return E<0&&(E=S(),C(),l((function(){setTimeout((function(){E=S(),C()}),0)}))),{get firstHiddenTime(){return E}}},M=function(e){document.prerendering?addEventListener("prerenderingchange",(function(){return e()}),!0):e()},F=function(e,t){t=t||{},M((function(){var n,r=[1800,3e3],i=w(),a=v("FCP"),o=p("paint",(function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(o.disconnect(),e.startTime<i.firstHiddenTime&&(a.value=Math.max(e.startTime-m(),0),a.entries.push(e),n(!0)))}))}));o&&(n=h(e,a,r,t.reportAllChanges),l((function(i){a=v("FCP"),n=h(e,a,r,t.reportAllChanges),g((function(){a.value=performance.now()-i.timeStamp,n(!0)}))})))}))},P={passive:!0,capture:!0},A=new Date,I=function(e,i){t||(t=i,n=e,r=new Date,D(removeEventListener),x())},x=function(){if(n>=0&&n<r-A){var e={entryType:"first-input",name:t.type,target:t.target,cancelable:t.cancelable,startTime:t.timeStamp,processingStart:t.timeStamp+n};i.forEach((function(t){t(e)})),i=[]}},B=function(e){if(e.cancelable){var t=(e.timeStamp>1e12?new Date:performance.now())-e.timeStamp;"pointerdown"==e.type?function(e,t){var n=function(){I(e,t),i()},r=function(){i()},i=function(){removeEventListener("pointerup",n,P),removeEventListener("pointercancel",r,P)};addEventListener("pointerup",n,P),addEventListener("pointercancel",r,P)}(t,e):I(t,e)}},D=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(t){return e(t,B,P)}))},k=function(e,r){r=r||{},M((function(){var a,o=[100,300],u=w(),c=v("FID"),s=function(e){e.startTime<u.firstHiddenTime&&(c.value=e.processingStart-e.startTime,c.entries.push(e),a(!0))},f=function(e){e.forEach(s)},d=p("first-input",f);a=h(e,c,o,r.reportAllChanges),d&&T(y((function(){f(d.takeRecords()),d.disconnect()}))),d&&l((function(){var u;c=v("FID"),a=h(e,c,o,r.reportAllChanges),i=[],n=-1,t=null,D(addEventListener),u=s,i.push(u),x()}))}))},N=0,R=1/0,q=0,H=function(e){e.forEach((function(e){e.interactionId&&(R=Math.min(R,e.interactionId),q=Math.max(q,e.interactionId),N=q?(q-R)/7+1:0)}))},O=function(){return a?N:performance.interactionCount||0},_=function(){"interactionCount"in performance||a||(a=p("event",H,{type:"event",buffered:!0,durationThreshold:0}))},j=0,V=function(){return O()-j},U=[],z={},G=function(e){var t=U[U.length-1],n=z[e.interactionId];if(n||U.length<10||e.duration>t.latency){if(n)n.entries.push(e),n.latency=Math.max(n.latency,e.duration);else{var r={id:e.interactionId,latency:e.duration,entries:[e]};z[r.id]=r,U.push(r)}U.sort((function(e,t){return t.latency-e.latency})),U.splice(10).forEach((function(e){delete z[e.id]}))}},J=function(e,t){t=t||{},M((function(){var n=[200,500];_();var r,i=v("INP"),a=function(e){e.forEach((function(e){(e.interactionId&&G(e),"first-input"===e.entryType)&&(!U.some((function(t){return t.entries.some((function(t){return e.duration===t.duration&&e.startTime===t.startTime}))}))&&G(e))}));var t,n=(t=Math.min(U.length-1,Math.floor(V()/50)),U[t]);n&&n.latency!==i.value&&(i.value=n.latency,i.entries=n.entries,r())},o=p("event",a,{durationThreshold:t.durationThreshold||40});r=h(e,i,n,t.reportAllChanges),o&&(o.observe({type:"first-input",buffered:!0}),T((function(){a(o.takeRecords()),i.value<0&&V()>0&&(i.value=0,i.entries=[]),r(!0)})),l((function(){U=[],j=O(),i=v("INP"),r=h(e,i,n,t.reportAllChanges)})))}))},K={},Q=function e(t){document.prerendering?M((function(){return e(t)})):"complete"!==document.readyState?addEventListener("load",(function(){return e(t)}),!0):setTimeout(t,0)},W=function(e,t){t=t||{};var n=[800,1800],r=v("TTFB"),i=h(e,r,n,t.reportAllChanges);Q((function(){var a=o();if(a){var u=a.responseStart;if(u<=0||u>performance.now())return;r.value=Math.max(u-m(),0),r.entries=[a],i(!0),l((function(){r=v("TTFB",0),(i=h(e,r,n,t.reportAllChanges))(!0)}))}}))};return e.onCLS=function(e,t){!function(e,t){t=t||{},F(y((function(){var n,r=[.1,.25],i=v("CLS",0),a=0,o=[],u=function(e){e.forEach((function(e){if(!e.hadRecentInput){var t=o[0],n=o[o.length-1];a&&e.startTime-n.startTime<1e3&&e.startTime-t.startTime<5e3?(a+=e.value,o.push(e)):(a=e.value,o=[e])}})),a>i.value&&(i.value=a,i.entries=o,n())},c=p("layout-shift",u);c&&(n=h(e,i,r,t.reportAllChanges),T((function(){u(c.takeRecords()),n(!0)})),l((function(){a=0,i=v("CLS",0),n=h(e,i,r,t.reportAllChanges),g((function(){return n()}))})),setTimeout(n,0))})))}((function(t){!function(e){if(e.entries.length){var t=e.entries.reduce((function(e,t){return e&&e.value>t.value?e:t}));if(t&&t.sources&&t.sources.length){var n=(r=t.sources).find((function(e){return e.node&&1===e.node.nodeType}))||r[0];if(n)return void(e.attribution={largestShiftTarget:s(n.node),largestShiftTime:t.startTime,largestShiftValue:t.value,largestShiftSource:n,largestShiftEntry:t,loadState:u(t.startTime)})}}var r;e.attribution={}}(t),e(t)}),t)},e.onFCP=function(e,t){F((function(t){!function(e){if(e.entries.length){var t=o(),n=e.entries[e.entries.length-1];if(t){var r=t.activationStart||0,i=Math.max(0,t.responseStart-r);return void(e.attribution={timeToFirstByte:i,firstByteToFCP:e.value-i,loadState:u(e.entries[0].startTime),navigationEntry:t,fcpEntry:n})}}e.attribution={timeToFirstByte:0,firstByteToFCP:e.value,loadState:u(d())}}(t),e(t)}),t)},e.onFID=function(e,t){k((function(t){!function(e){var t=e.entries[0];e.attribution={eventTarget:s(t.target),eventType:t.name,eventTime:t.startTime,eventEntry:t,loadState:u(t.startTime)}}(t),e(t)}),t)},e.onINP=function(e,t){J((function(t){!function(e){if(e.entries.length){var t=e.entries.sort((function(e,t){return t.duration-e.duration||t.processingEnd-t.processingStart-(e.processingEnd-e.processingStart)}))[0];e.attribution={eventTarget:s(t.target),eventType:t.name,eventTime:t.startTime,eventEntry:t,loadState:u(t.startTime)}}else e.attribution={}}(t),e(t)}),t)},e.onLCP=function(e,t){!function(e,t){t=t||{},M((function(){var n,r=[2500,4e3],i=w(),a=v("LCP"),o=function(e){var t=e[e.length-1];if(t){var r=Math.max(t.startTime-m(),0);r<i.firstHiddenTime&&(a.value=r,a.entries=[t],n())}},u=p("largest-contentful-paint",o);if(u){n=h(e,a,r,t.reportAllChanges);var c=y((function(){K[a.id]||(o(u.takeRecords()),u.disconnect(),K[a.id]=!0,n(!0))}));["keydown","click"].forEach((function(e){addEventListener(e,c,!0)})),T(c),l((function(i){a=v("LCP"),n=h(e,a,r,t.reportAllChanges),g((function(){a.value=performance.now()-i.timeStamp,K[a.id]=!0,n(!0)}))}))}}))}((function(t){!function(e){if(e.entries.length){var t=o();if(t){var n=t.activationStart||0,r=e.entries[e.entries.length-1],i=r.url&&performance.getEntriesByType("resource").filter((function(e){return e.name===r.url}))[0],a=Math.max(0,t.responseStart-n),u=Math.max(a,i?(i.requestStart||i.startTime)-n:0),c=Math.max(u,i?i.responseEnd-n:0),f=Math.max(c,r?r.startTime-n:0),d={element:s(r.element),timeToFirstByte:a,resourceLoadDelay:u-a,resourceLoadTime:c-u,elementRenderDelay:f-c,navigationEntry:t,lcpEntry:r};return r.url&&(d.url=r.url),i&&(d.lcpResourceEntry=i),void(e.attribution=d)}}e.attribution={timeToFirstByte:0,resourceLoadDelay:0,resourceLoadTime:0,elementRenderDelay:e.value}}(t),e(t)}),t)},e.onTTFB=function(e,t){W((function(t){!function(e){if(e.entries.length){var t=e.entries[0],n=t.activationStart||0,r=Math.max(t.domainLookupStart-n,0),i=Math.max(t.connectStart-n,0),a=Math.max(t.requestStart-n,0);e.attribution={waitingTime:r,dnsTime:i-r,connectionTime:a-i,requestTime:e.value-a,navigationEntry:t}}else e.attribution={waitingTime:0,dnsTime:0,connectionTime:0,requestTime:0}}(t),e(t)}),t)},Object.defineProperty(e,"__esModule",{value:!0}),e}({}); |
@@ -1,1 +0,1 @@ | ||
var e,t,n,r,i,a=function(){return window.performance&&performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]},o=function(e){if("loading"===document.readyState)return"loading";var t=a();if(t){if(e<t.domInteractive)return"loading";if(0===t.domContentLoadedEventStart||e<t.domContentLoadedEventStart)return"dom-interactive";if(0===t.domComplete||e<t.domComplete)return"dom-content-loaded"}return"complete"},u=function(e){var t=e.nodeName;return 1===e.nodeType?t.toLowerCase():t.toUpperCase().replace(/^#/,"")},c=function(e,t){var n="";try{for(;e&&9!==e.nodeType;){var r=e,i=r.id?"#"+r.id:u(r)+(r.className&&r.className.length?"."+r.className.replace(/\s+/g,"."):"");if(n.length+i.length>(t||100)-1)return n||i;if(n=n?i+">"+n:i,r.id)break;e=r.parentNode}}catch(e){}return n},s=-1,f=function(){return s},d=function(e){addEventListener("pageshow",(function(t){t.persisted&&(s=t.timeStamp,e(t))}),!0)},l=function(){var e=a();return e&&e.activationStart||0},m=function(e,t){var n=a(),r="navigate";return f()>=0?r="back-forward-cache":n&&(r=document.prerendering||l()>0?"prerender":document.wasDiscarded?"restore":n.type.replace(/_/g,"-")),{name:e,value:void 0===t?-1:t,rating:"good",delta:0,entries:[],id:"v3-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:r}},v=function(e,t,n){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var r=new PerformanceObserver((function(e){Promise.resolve().then((function(){t(e.getEntries())}))}));return r.observe(Object.assign({type:e,buffered:!0},n||{})),r}}catch(e){}},p=function(e,t){var n=function n(r){"pagehide"!==r.type&&"hidden"!==document.visibilityState||(e(r),t&&(removeEventListener("visibilitychange",n,!0),removeEventListener("pagehide",n,!0)))};addEventListener("visibilitychange",n,!0),addEventListener("pagehide",n,!0)},h=function(e,t,n,r){var i,a;return function(o){t.value>=0&&(o||r)&&((a=t.value-(i||0))||void 0===i)&&(i=t.value,t.delta=a,t.rating=function(e,t){return e>t[1]?"poor":e>t[0]?"needs-improvement":"good"}(t.value,n),e(t))}},g=function(e){requestAnimationFrame((function(){return requestAnimationFrame((function(){return e()}))}))},y=function(e){document.prerendering?addEventListener("prerenderingchange",(function(){return e()}),!0):e()},T=-1,E=function(){return"hidden"!==document.visibilityState||document.prerendering?1/0:0},S=function(e){"hidden"===document.visibilityState&&T>-1&&(T="visibilitychange"===e.type?e.timeStamp:0,L())},b=function(){addEventListener("visibilitychange",S,!0),addEventListener("prerenderingchange",S,!0)},L=function(){removeEventListener("visibilitychange",S,!0),removeEventListener("prerenderingchange",S,!0)},C=function(){return T<0&&(T=E(),b(),d((function(){setTimeout((function(){T=E(),b()}),0)}))),{get firstHiddenTime(){return T}}},w=function(e,t){t=t||{},y((function(){var n,r=[1800,3e3],i=C(),a=m("FCP"),o=v("paint",(function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(o.disconnect(),e.startTime<i.firstHiddenTime&&(a.value=Math.max(e.startTime-l(),0),a.entries.push(e),n(!0)))}))}));o&&(n=h(e,a,r,t.reportAllChanges),d((function(i){a=m("FCP"),n=h(e,a,r,t.reportAllChanges),g((function(){a.value=performance.now()-i.timeStamp,n(!0)}))})))}))},M=function(e,t){!function(e,t){t=t||{},y((function(){var n,r=[.1,.25],i=m("CLS"),a=-1,o=0,u=[],c=function(t){a>-1&&e(t)},s=function(e){e.forEach((function(e){if(!e.hadRecentInput){var t=u[0],r=u[u.length-1];o&&e.startTime-r.startTime<1e3&&e.startTime-t.startTime<5e3?(o+=e.value,u.push(e)):(o=e.value,u=[e]),o>i.value&&(i.value=o,i.entries=u,n())}}))},f=v("layout-shift",s);f&&(n=h(c,i,r,t.reportAllChanges),w((function(e){a=e.value,i.value<0&&(i.value=0,n())})),p((function(){s(f.takeRecords()),n(!0)})),d((function(){o=0,a=-1,i=m("CLS",0),n=h(c,i,r,t.reportAllChanges),g((function(){return n()}))})))}))}((function(t){!function(e){if(e.entries.length){var t=e.entries.reduce((function(e,t){return e&&e.value>t.value?e:t}));if(t&&t.sources&&t.sources.length){var n=(r=t.sources).find((function(e){return e.node&&1===e.node.nodeType}))||r[0];if(n)return void(e.attribution={largestShiftTarget:c(n.node),largestShiftTime:t.startTime,largestShiftValue:t.value,largestShiftSource:n,largestShiftEntry:t,loadState:o(t.startTime)})}}var r;e.attribution={}}(t),e(t)}),t)},x=function(e,t){w((function(t){!function(e){if(e.entries.length){var t=a(),n=e.entries[e.entries.length-1];if(t){var r=t.activationStart||0,i=Math.max(0,t.responseStart-r);return void(e.attribution={timeToFirstByte:i,firstByteToFCP:e.value-i,loadState:o(e.entries[0].startTime),navigationEntry:t,fcpEntry:n})}}e.attribution={timeToFirstByte:0,firstByteToFCP:e.value,loadState:o(f())}}(t),e(t)}),t)},A={passive:!0,capture:!0},F=new Date,I=function(r,i){e||(e=i,t=r,n=new Date,P(removeEventListener),B())},B=function(){if(t>=0&&t<n-F){var i={entryType:"first-input",name:e.type,target:e.target,cancelable:e.cancelable,startTime:e.timeStamp,processingStart:e.timeStamp+t};r.forEach((function(e){e(i)})),r=[]}},D=function(e){if(e.cancelable){var t=(e.timeStamp>1e12?new Date:performance.now())-e.timeStamp;"pointerdown"==e.type?function(e,t){var n=function(){I(e,t),i()},r=function(){i()},i=function(){removeEventListener("pointerup",n,A),removeEventListener("pointercancel",r,A)};addEventListener("pointerup",n,A),addEventListener("pointercancel",r,A)}(t,e):I(t,e)}},P=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(t){return e(t,D,A)}))},k=function(n,i){i=i||{},y((function(){var a,o=[100,300],u=C(),c=m("FID"),s=function(e){e.startTime<u.firstHiddenTime&&(c.value=e.processingStart-e.startTime,c.entries.push(e),a(!0))},f=function(e){e.forEach(s)},l=v("first-input",f);a=h(n,c,o,i.reportAllChanges),l&&p((function(){f(l.takeRecords()),l.disconnect()}),!0),l&&d((function(){var u;c=m("FID"),a=h(n,c,o,i.reportAllChanges),r=[],t=-1,e=null,P(addEventListener),u=s,r.push(u),B()}))}))},R=function(e,t){k((function(t){!function(e){var t=e.entries[0];e.attribution={eventTarget:c(t.target),eventType:t.name,eventTime:t.startTime,eventEntry:t,loadState:o(t.startTime)}}(t),e(t)}),t)},N=0,q=1/0,H=0,O=function(e){e.forEach((function(e){e.interactionId&&(q=Math.min(q,e.interactionId),H=Math.max(H,e.interactionId),N=H?(H-q)/7+1:0)}))},j=function(){return i?N:performance.interactionCount||0},U=function(){"interactionCount"in performance||i||(i=v("event",O,{type:"event",buffered:!0,durationThreshold:0}))},V=0,_=function(){return j()-V},z=[],G={},J=function(e){var t=z[z.length-1],n=G[e.interactionId];if(n||z.length<10||e.duration>t.latency){if(n)n.entries.push(e),n.latency=Math.max(n.latency,e.duration);else{var r={id:e.interactionId,latency:e.duration,entries:[e]};G[r.id]=r,z.push(r)}z.sort((function(e,t){return t.latency-e.latency})),z.splice(10).forEach((function(e){delete G[e.id]}))}},K=function(e,t){t=t||{},y((function(){var n=[200,500];U();var r,i=m("INP"),a=function(e){e.forEach((function(e){(e.interactionId&&J(e),"first-input"===e.entryType)&&(!z.some((function(t){return t.entries.some((function(t){return e.duration===t.duration&&e.startTime===t.startTime}))}))&&J(e))}));var t,n=(t=Math.min(z.length-1,Math.floor(_()/50)),z[t]);n&&n.latency!==i.value&&(i.value=n.latency,i.entries=n.entries,r())},o=v("event",a,{durationThreshold:t.durationThreshold||40});r=h(e,i,n,t.reportAllChanges),o&&(o.observe({type:"first-input",buffered:!0}),p((function(){a(o.takeRecords()),i.value<0&&_()>0&&(i.value=0,i.entries=[]),r(!0)})),d((function(){z=[],V=j(),i=m("INP"),r=h(e,i,n,t.reportAllChanges)})))}))},Q=function(e,t){K((function(t){!function(e){if(e.entries.length){var t=e.entries.sort((function(e,t){return t.duration-e.duration||t.processingEnd-t.processingStart-(e.processingEnd-e.processingStart)}))[0];e.attribution={eventTarget:c(t.target),eventType:t.name,eventTime:t.startTime,eventEntry:t,loadState:o(t.startTime)}}else e.attribution={}}(t),e(t)}),t)},W={},X=function(e,t){!function(e,t){t=t||{},y((function(){var n,r=[2500,4e3],i=C(),a=m("LCP"),o=function(e){var t=e[e.length-1];if(t){var r=Math.max(t.startTime-l(),0);r<i.firstHiddenTime&&(a.value=r,a.entries=[t],n())}},u=v("largest-contentful-paint",o);if(u){n=h(e,a,r,t.reportAllChanges);var c=function(){W[a.id]||(o(u.takeRecords()),u.disconnect(),W[a.id]=!0,n(!0))};["keydown","click"].forEach((function(e){addEventListener(e,c,{once:!0,capture:!0})})),p(c,!0),d((function(i){a=m("LCP"),n=h(e,a,r,t.reportAllChanges),g((function(){a.value=performance.now()-i.timeStamp,W[a.id]=!0,n(!0)}))}))}}))}((function(t){!function(e){if(e.entries.length){var t=a();if(t){var n=t.activationStart||0,r=e.entries[e.entries.length-1],i=r.url&&performance.getEntriesByType("resource").filter((function(e){return e.name===r.url}))[0],o=Math.max(0,t.responseStart-n),u=Math.max(o,i?(i.requestStart||i.startTime)-n:0),s=Math.max(u,i?i.responseEnd-n:0),f=Math.max(s,r?r.startTime-n:0),d={element:c(r.element),timeToFirstByte:o,resourceLoadDelay:u-o,resourceLoadTime:s-u,elementRenderDelay:f-s,navigationEntry:t,lcpEntry:r};return r.url&&(d.url=r.url),i&&(d.lcpResourceEntry=i),void(e.attribution=d)}}e.attribution={timeToFirstByte:0,resourceLoadDelay:0,resourceLoadTime:0,elementRenderDelay:e.value}}(t),e(t)}),t)},Y=function e(t){document.prerendering?y((function(){return e(t)})):"complete"!==document.readyState?addEventListener("load",(function(){return e(t)}),!0):setTimeout(t,0)},Z=function(e,t){t=t||{};var n=[800,1800],r=m("TTFB"),i=h(e,r,n,t.reportAllChanges);Y((function(){var o=a();if(o){var u=o.responseStart;if(u<=0||u>performance.now())return;r.value=Math.max(u-l(),0),r.entries=[o],i(!0),d((function(){r=m("TTFB",0),(i=h(e,r,n,t.reportAllChanges))(!0)}))}}))},$=function(e,t){Z((function(t){!function(e){if(e.entries.length){var t=e.entries[0],n=t.activationStart||0,r=Math.max(t.domainLookupStart-n,0),i=Math.max(t.connectStart-n,0),a=Math.max(t.requestStart-n,0);e.attribution={waitingTime:r,dnsTime:i-r,connectionTime:a-i,requestTime:e.value-a,navigationEntry:t}}else e.attribution={waitingTime:0,dnsTime:0,connectionTime:0,requestTime:0}}(t),e(t)}),t)};export{M as onCLS,x as onFCP,R as onFID,Q as onINP,X as onLCP,$ as onTTFB}; | ||
var e,t,n,r,i,a=function(){return window.performance&&performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]},o=function(e){if("loading"===document.readyState)return"loading";var t=a();if(t){if(e<t.domInteractive)return"loading";if(0===t.domContentLoadedEventStart||e<t.domContentLoadedEventStart)return"dom-interactive";if(0===t.domComplete||e<t.domComplete)return"dom-content-loaded"}return"complete"},u=function(e){var t=e.nodeName;return 1===e.nodeType?t.toLowerCase():t.toUpperCase().replace(/^#/,"")},c=function(e,t){var n="";try{for(;e&&9!==e.nodeType;){var r=e,i=r.id?"#"+r.id:u(r)+(r.className&&r.className.length?"."+r.className.replace(/\s+/g,"."):"");if(n.length+i.length>(t||100)-1)return n||i;if(n=n?i+">"+n:i,r.id)break;e=r.parentNode}}catch(e){}return n},s=-1,f=function(){return s},d=function(e){addEventListener("pageshow",(function(t){t.persisted&&(s=t.timeStamp,e(t))}),!0)},l=function(){var e=a();return e&&e.activationStart||0},m=function(e,t){var n=a(),r="navigate";return f()>=0?r="back-forward-cache":n&&(r=document.prerendering||l()>0?"prerender":document.wasDiscarded?"restore":n.type.replace(/_/g,"-")),{name:e,value:void 0===t?-1:t,rating:"good",delta:0,entries:[],id:"v3-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:r}},v=function(e,t,n){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var r=new PerformanceObserver((function(e){Promise.resolve().then((function(){t(e.getEntries())}))}));return r.observe(Object.assign({type:e,buffered:!0},n||{})),r}}catch(e){}},p=function(e,t,n,r){var i,a;return function(o){t.value>=0&&(o||r)&&((a=t.value-(i||0))||void 0===i)&&(i=t.value,t.delta=a,t.rating=function(e,t){return e>t[1]?"poor":e>t[0]?"needs-improvement":"good"}(t.value,n),e(t))}},h=function(e){requestAnimationFrame((function(){return requestAnimationFrame((function(){return e()}))}))},g=function(e){var t=function(t){"pagehide"!==t.type&&"hidden"!==document.visibilityState||e(t)};addEventListener("visibilitychange",t,!0),addEventListener("pagehide",t,!0)},T=function(e){var t=!1;return function(n){t||(e(n),t=!0)}},y=-1,E=function(){return"hidden"!==document.visibilityState||document.prerendering?1/0:0},S=function(e){"hidden"===document.visibilityState&&y>-1&&(y="visibilitychange"===e.type?e.timeStamp:0,C())},b=function(){addEventListener("visibilitychange",S,!0),addEventListener("prerenderingchange",S,!0)},C=function(){removeEventListener("visibilitychange",S,!0),removeEventListener("prerenderingchange",S,!0)},L=function(){return y<0&&(y=E(),b(),d((function(){setTimeout((function(){y=E(),b()}),0)}))),{get firstHiddenTime(){return y}}},w=function(e){document.prerendering?addEventListener("prerenderingchange",(function(){return e()}),!0):e()},M=function(e,t){t=t||{},w((function(){var n,r=[1800,3e3],i=L(),a=m("FCP"),o=v("paint",(function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(o.disconnect(),e.startTime<i.firstHiddenTime&&(a.value=Math.max(e.startTime-l(),0),a.entries.push(e),n(!0)))}))}));o&&(n=p(e,a,r,t.reportAllChanges),d((function(i){a=m("FCP"),n=p(e,a,r,t.reportAllChanges),h((function(){a.value=performance.now()-i.timeStamp,n(!0)}))})))}))},x=function(e,t){!function(e,t){t=t||{},M(T((function(){var n,r=[.1,.25],i=m("CLS",0),a=0,o=[],u=function(e){e.forEach((function(e){if(!e.hadRecentInput){var t=o[0],n=o[o.length-1];a&&e.startTime-n.startTime<1e3&&e.startTime-t.startTime<5e3?(a+=e.value,o.push(e)):(a=e.value,o=[e])}})),a>i.value&&(i.value=a,i.entries=o,n())},c=v("layout-shift",u);c&&(n=p(e,i,r,t.reportAllChanges),g((function(){u(c.takeRecords()),n(!0)})),d((function(){a=0,i=m("CLS",0),n=p(e,i,r,t.reportAllChanges),h((function(){return n()}))})),setTimeout(n,0))})))}((function(t){!function(e){if(e.entries.length){var t=e.entries.reduce((function(e,t){return e&&e.value>t.value?e:t}));if(t&&t.sources&&t.sources.length){var n=(r=t.sources).find((function(e){return e.node&&1===e.node.nodeType}))||r[0];if(n)return void(e.attribution={largestShiftTarget:c(n.node),largestShiftTime:t.startTime,largestShiftValue:t.value,largestShiftSource:n,largestShiftEntry:t,loadState:o(t.startTime)})}}var r;e.attribution={}}(t),e(t)}),t)},A=function(e,t){M((function(t){!function(e){if(e.entries.length){var t=a(),n=e.entries[e.entries.length-1];if(t){var r=t.activationStart||0,i=Math.max(0,t.responseStart-r);return void(e.attribution={timeToFirstByte:i,firstByteToFCP:e.value-i,loadState:o(e.entries[0].startTime),navigationEntry:t,fcpEntry:n})}}e.attribution={timeToFirstByte:0,firstByteToFCP:e.value,loadState:o(f())}}(t),e(t)}),t)},F={passive:!0,capture:!0},I=new Date,B=function(r,i){e||(e=i,t=r,n=new Date,k(removeEventListener),D())},D=function(){if(t>=0&&t<n-I){var i={entryType:"first-input",name:e.type,target:e.target,cancelable:e.cancelable,startTime:e.timeStamp,processingStart:e.timeStamp+t};r.forEach((function(e){e(i)})),r=[]}},P=function(e){if(e.cancelable){var t=(e.timeStamp>1e12?new Date:performance.now())-e.timeStamp;"pointerdown"==e.type?function(e,t){var n=function(){B(e,t),i()},r=function(){i()},i=function(){removeEventListener("pointerup",n,F),removeEventListener("pointercancel",r,F)};addEventListener("pointerup",n,F),addEventListener("pointercancel",r,F)}(t,e):B(t,e)}},k=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(t){return e(t,P,F)}))},R=function(n,i){i=i||{},w((function(){var a,o=[100,300],u=L(),c=m("FID"),s=function(e){e.startTime<u.firstHiddenTime&&(c.value=e.processingStart-e.startTime,c.entries.push(e),a(!0))},f=function(e){e.forEach(s)},l=v("first-input",f);a=p(n,c,o,i.reportAllChanges),l&&g(T((function(){f(l.takeRecords()),l.disconnect()}))),l&&d((function(){var u;c=m("FID"),a=p(n,c,o,i.reportAllChanges),r=[],t=-1,e=null,k(addEventListener),u=s,r.push(u),D()}))}))},N=function(e,t){R((function(t){!function(e){var t=e.entries[0];e.attribution={eventTarget:c(t.target),eventType:t.name,eventTime:t.startTime,eventEntry:t,loadState:o(t.startTime)}}(t),e(t)}),t)},q=0,H=1/0,O=0,j=function(e){e.forEach((function(e){e.interactionId&&(H=Math.min(H,e.interactionId),O=Math.max(O,e.interactionId),q=O?(O-H)/7+1:0)}))},U=function(){return i?q:performance.interactionCount||0},V=function(){"interactionCount"in performance||i||(i=v("event",j,{type:"event",buffered:!0,durationThreshold:0}))},_=0,z=function(){return U()-_},G=[],J={},K=function(e){var t=G[G.length-1],n=J[e.interactionId];if(n||G.length<10||e.duration>t.latency){if(n)n.entries.push(e),n.latency=Math.max(n.latency,e.duration);else{var r={id:e.interactionId,latency:e.duration,entries:[e]};J[r.id]=r,G.push(r)}G.sort((function(e,t){return t.latency-e.latency})),G.splice(10).forEach((function(e){delete J[e.id]}))}},Q=function(e,t){t=t||{},w((function(){var n=[200,500];V();var r,i=m("INP"),a=function(e){e.forEach((function(e){(e.interactionId&&K(e),"first-input"===e.entryType)&&(!G.some((function(t){return t.entries.some((function(t){return e.duration===t.duration&&e.startTime===t.startTime}))}))&&K(e))}));var t,n=(t=Math.min(G.length-1,Math.floor(z()/50)),G[t]);n&&n.latency!==i.value&&(i.value=n.latency,i.entries=n.entries,r())},o=v("event",a,{durationThreshold:t.durationThreshold||40});r=p(e,i,n,t.reportAllChanges),o&&(o.observe({type:"first-input",buffered:!0}),g((function(){a(o.takeRecords()),i.value<0&&z()>0&&(i.value=0,i.entries=[]),r(!0)})),d((function(){G=[],_=U(),i=m("INP"),r=p(e,i,n,t.reportAllChanges)})))}))},W=function(e,t){Q((function(t){!function(e){if(e.entries.length){var t=e.entries.sort((function(e,t){return t.duration-e.duration||t.processingEnd-t.processingStart-(e.processingEnd-e.processingStart)}))[0];e.attribution={eventTarget:c(t.target),eventType:t.name,eventTime:t.startTime,eventEntry:t,loadState:o(t.startTime)}}else e.attribution={}}(t),e(t)}),t)},X={},Y=function(e,t){!function(e,t){t=t||{},w((function(){var n,r=[2500,4e3],i=L(),a=m("LCP"),o=function(e){var t=e[e.length-1];if(t){var r=Math.max(t.startTime-l(),0);r<i.firstHiddenTime&&(a.value=r,a.entries=[t],n())}},u=v("largest-contentful-paint",o);if(u){n=p(e,a,r,t.reportAllChanges);var c=T((function(){X[a.id]||(o(u.takeRecords()),u.disconnect(),X[a.id]=!0,n(!0))}));["keydown","click"].forEach((function(e){addEventListener(e,c,!0)})),g(c),d((function(i){a=m("LCP"),n=p(e,a,r,t.reportAllChanges),h((function(){a.value=performance.now()-i.timeStamp,X[a.id]=!0,n(!0)}))}))}}))}((function(t){!function(e){if(e.entries.length){var t=a();if(t){var n=t.activationStart||0,r=e.entries[e.entries.length-1],i=r.url&&performance.getEntriesByType("resource").filter((function(e){return e.name===r.url}))[0],o=Math.max(0,t.responseStart-n),u=Math.max(o,i?(i.requestStart||i.startTime)-n:0),s=Math.max(u,i?i.responseEnd-n:0),f=Math.max(s,r?r.startTime-n:0),d={element:c(r.element),timeToFirstByte:o,resourceLoadDelay:u-o,resourceLoadTime:s-u,elementRenderDelay:f-s,navigationEntry:t,lcpEntry:r};return r.url&&(d.url=r.url),i&&(d.lcpResourceEntry=i),void(e.attribution=d)}}e.attribution={timeToFirstByte:0,resourceLoadDelay:0,resourceLoadTime:0,elementRenderDelay:e.value}}(t),e(t)}),t)},Z=function e(t){document.prerendering?w((function(){return e(t)})):"complete"!==document.readyState?addEventListener("load",(function(){return e(t)}),!0):setTimeout(t,0)},$=function(e,t){t=t||{};var n=[800,1800],r=m("TTFB"),i=p(e,r,n,t.reportAllChanges);Z((function(){var o=a();if(o){var u=o.responseStart;if(u<=0||u>performance.now())return;r.value=Math.max(u-l(),0),r.entries=[o],i(!0),d((function(){r=m("TTFB",0),(i=p(e,r,n,t.reportAllChanges))(!0)}))}}))},ee=function(e,t){$((function(t){!function(e){if(e.entries.length){var t=e.entries[0],n=t.activationStart||0,r=Math.max(t.domainLookupStart-n,0),i=Math.max(t.connectStart-n,0),a=Math.max(t.requestStart-n,0);e.attribution={waitingTime:r,dnsTime:i-r,connectionTime:a-i,requestTime:e.value-a,navigationEntry:t}}else e.attribution={waitingTime:0,dnsTime:0,connectionTime:0,requestTime:0}}(t),e(t)}),t)};export{x as onCLS,A as onFCP,N as onFID,W as onINP,Y as onLCP,ee as onTTFB}; |
@@ -1,1 +0,1 @@ | ||
!function(e){"use strict";var n,t=-1,i=function(e){addEventListener("pageshow",(function(n){n.persisted&&(t=n.timeStamp,e(n))}),!0)},r=function(){return window.performance&&(performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]||function(){var e=performance.timing,n=performance.navigation.type,t={entryType:"navigation",startTime:0,type:2==n?"back_forward":1===n?"reload":"navigate"};for(var i in e)"navigationStart"!==i&&"toJSON"!==i&&(t[i]=Math.max(e[i]-e.navigationStart,0));return t}())},a=function(){var e=r();return e&&e.activationStart||0},o=function(e,n){var i=r(),o="navigate";return t>=0?o="back-forward-cache":i&&(o=document.prerendering||a()>0?"prerender":document.wasDiscarded?"restore":i.type.replace(/_/g,"-")),{name:e,value:void 0===n?-1:n,rating:"good",delta:0,entries:[],id:"v3-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:o}},c=function(e,n,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var i=new PerformanceObserver((function(e){Promise.resolve().then((function(){n(e.getEntries())}))}));return i.observe(Object.assign({type:e,buffered:!0},t||{})),i}}catch(e){}},u=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)},s=function(e,n,t,i){var r,a;return function(o){n.value>=0&&(o||i)&&((a=n.value-(r||0))||void 0===r)&&(r=n.value,n.delta=a,n.rating=function(e,n){return e>n[1]?"poor":e>n[0]?"needs-improvement":"good"}(n.value,t),e(n))}},f=function(e){requestAnimationFrame((function(){return requestAnimationFrame((function(){return e()}))}))},d=function(e){document.prerendering?addEventListener("prerenderingchange",(function(){return e()}),!0):e()},l=-1,v=function(e){"hidden"===document.visibilityState&&l>-1&&(l="visibilitychange"===e.type?e.timeStamp:0,m())},p=function(){addEventListener("visibilitychange",v,!0),addEventListener("prerenderingchange",v,!0)},m=function(){removeEventListener("visibilitychange",v,!0),removeEventListener("prerenderingchange",v,!0)},h=function(){return l<0&&((l=window.webVitals.firstHiddenTime)===1/0&&p(),i((function(){setTimeout((function(){l="hidden"!==document.visibilityState||document.prerendering?1/0:0,p()}),0)}))),{get firstHiddenTime(){return l}}},g=function(e,n){n=n||{},d((function(){var t,r=[1800,3e3],u=h(),d=o("FCP"),l=c("paint",(function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(l.disconnect(),e.startTime<u.firstHiddenTime&&(d.value=Math.max(e.startTime-a(),0),d.entries.push(e),t(!0)))}))}));l&&(t=s(e,d,r,n.reportAllChanges),i((function(i){d=o("FCP"),t=s(e,d,r,n.reportAllChanges),f((function(){d.value=performance.now()-i.timeStamp,t(!0)}))})))}))},y=function(e,n){n=n||{},d((function(){var t,r=[.1,.25],a=o("CLS"),d=-1,l=0,v=[],p=function(n){d>-1&&e(n)},m=function(e){e.forEach((function(e){if(!e.hadRecentInput){var n=v[0],i=v[v.length-1];l&&e.startTime-i.startTime<1e3&&e.startTime-n.startTime<5e3?(l+=e.value,v.push(e)):(l=e.value,v=[e]),l>a.value&&(a.value=l,a.entries=v,t())}}))},h=c("layout-shift",m);h&&(t=s(p,a,r,n.reportAllChanges),g((function(e){d=e.value,a.value<0&&(a.value=0,t())})),u((function(){m(h.takeRecords()),t(!0)})),i((function(){l=0,d=-1,a=o("CLS",0),t=s(p,a,r,n.reportAllChanges),f((function(){return t()}))})))}))},T=function(e,n){n=n||{},d((function(){var t,r=[100,300],a=h(),f=o("FID"),d=function(e){e.startTime<a.firstHiddenTime&&(f.value=e.processingStart-e.startTime,f.entries.push(e),t(!0))},l=function(e){e.forEach(d)},v=c("first-input",l);t=s(e,f,r,n.reportAllChanges),v&&u((function(){l(v.takeRecords()),v.disconnect()}),!0),console.warn('The web-vitals "base+polyfill" build is deprecated. See: https://bit.ly/3aqzsGm'),v||window.webVitals.firstInputPolyfill(d),i((function(){f=o("FID"),t=s(e,f,r,n.reportAllChanges),window.webVitals.resetFirstInputPolyfill(),window.webVitals.firstInputPolyfill(d)}))}))},b=0,w=1/0,C=0,E=function(e){e.forEach((function(e){e.interactionId&&(w=Math.min(w,e.interactionId),C=Math.max(C,e.interactionId),b=C?(C-w)/7+1:0)}))},L=function(){return n?b:performance.interactionCount||0},P=function(){"interactionCount"in performance||n||(n=c("event",E,{type:"event",buffered:!0,durationThreshold:0}))},S=0,I=function(){return L()-S},F=[],A={},M=function(e){var n=F[F.length-1],t=A[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]};A[i.id]=i,F.push(i)}F.sort((function(e,n){return n.latency-e.latency})),F.splice(10).forEach((function(e){delete A[e.id]}))}},k=function(e,n){n=n||{},d((function(){var t=[200,500];P();var r,a=o("INP"),f=function(e){e.forEach((function(e){(e.interactionId&&M(e),"first-input"===e.entryType)&&(!F.some((function(n){return n.entries.some((function(n){return e.duration===n.duration&&e.startTime===n.startTime}))}))&&M(e))}));var n,t=(n=Math.min(F.length-1,Math.floor(I()/50)),F[n]);t&&t.latency!==a.value&&(a.value=t.latency,a.entries=t.entries,r())},d=c("event",f,{durationThreshold:n.durationThreshold||40});r=s(e,a,t,n.reportAllChanges),d&&(d.observe({type:"first-input",buffered:!0}),u((function(){f(d.takeRecords()),a.value<0&&I()>0&&(a.value=0,a.entries=[]),r(!0)})),i((function(){F=[],S=L(),a=o("INP"),r=s(e,a,t,n.reportAllChanges)})))}))},x={},B=function(e,n){n=n||{},d((function(){var t,r=[2500,4e3],d=h(),l=o("LCP"),v=function(e){var n=e[e.length-1];if(n){var i=Math.max(n.startTime-a(),0);i<d.firstHiddenTime&&(l.value=i,l.entries=[n],t())}},p=c("largest-contentful-paint",v);if(p){t=s(e,l,r,n.reportAllChanges);var m=function(){x[l.id]||(v(p.takeRecords()),p.disconnect(),x[l.id]=!0,t(!0))};["keydown","click"].forEach((function(e){addEventListener(e,m,{once:!0,capture:!0})})),u(m,!0),i((function(i){l=o("LCP"),t=s(e,l,r,n.reportAllChanges),f((function(){l.value=performance.now()-i.timeStamp,x[l.id]=!0,t(!0)}))}))}}))},D=function e(n){document.prerendering?d((function(){return e(n)})):"complete"!==document.readyState?addEventListener("load",(function(){return e(n)}),!0):setTimeout(n,0)},V=function(e,n){n=n||{};var t=[800,1800],c=o("TTFB"),u=s(e,c,t,n.reportAllChanges);D((function(){var f=r();if(f){var d=f.responseStart;if(d<=0||d>performance.now())return;c.value=Math.max(d-a(),0),c.entries=[f],u(!0),i((function(){c=o("TTFB",0),(u=s(e,c,t,n.reportAllChanges))(!0)}))}}))};e.getCLS=y,e.getFCP=g,e.getFID=T,e.getINP=k,e.getLCP=B,e.getTTFB=V,e.onCLS=y,e.onFCP=g,e.onFID=T,e.onINP=k,e.onLCP=B,e.onTTFB=V,Object.defineProperty(e,"__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=n.timeStamp,e(n))}),!0)},r=function(){return window.performance&&(performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]||function(){var e=performance.timing,n=performance.navigation.type,t={entryType:"navigation",startTime:0,type:2==n?"back_forward":1===n?"reload":"navigate"};for(var i in e)"navigationStart"!==i&&"toJSON"!==i&&(t[i]=Math.max(e[i]-e.navigationStart,0));return t}())},a=function(){var e=r();return e&&e.activationStart||0},o=function(e,n){var i=r(),o="navigate";return t>=0?o="back-forward-cache":i&&(o=document.prerendering||a()>0?"prerender":document.wasDiscarded?"restore":i.type.replace(/_/g,"-")),{name:e,value:void 0===n?-1:n,rating:"good",delta:0,entries:[],id:"v3-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:o}},u=function(e,n,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var i=new PerformanceObserver((function(e){Promise.resolve().then((function(){n(e.getEntries())}))}));return i.observe(Object.assign({type:e,buffered:!0},t||{})),i}}catch(e){}},c=function(e,n,t,i){var r,a;return function(o){n.value>=0&&(o||i)&&((a=n.value-(r||0))||void 0===r)&&(r=n.value,n.delta=a,n.rating=function(e,n){return e>n[1]?"poor":e>n[0]?"needs-improvement":"good"}(n.value,t),e(n))}},s=function(e){requestAnimationFrame((function(){return requestAnimationFrame((function(){return e()}))}))},f=function(e){var n=function(n){"pagehide"!==n.type&&"hidden"!==document.visibilityState||e(n)};addEventListener("visibilitychange",n,!0),addEventListener("pagehide",n,!0)},d=function(e){var n=!1;return function(t){n||(e(t),n=!0)}},l=-1,v=function(e){"hidden"===document.visibilityState&&l>-1&&(l="visibilitychange"===e.type?e.timeStamp:0,m())},p=function(){addEventListener("visibilitychange",v,!0),addEventListener("prerenderingchange",v,!0)},m=function(){removeEventListener("visibilitychange",v,!0),removeEventListener("prerenderingchange",v,!0)},h=function(){return l<0&&((l=window.webVitals.firstHiddenTime)===1/0&&p(),i((function(){setTimeout((function(){l="hidden"!==document.visibilityState||document.prerendering?1/0:0,p()}),0)}))),{get firstHiddenTime(){return l}}},g=function(e){document.prerendering?addEventListener("prerenderingchange",(function(){return e()}),!0):e()},y=function(e,n){n=n||{},g((function(){var t,r=[1800,3e3],f=h(),d=o("FCP"),l=u("paint",(function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(l.disconnect(),e.startTime<f.firstHiddenTime&&(d.value=Math.max(e.startTime-a(),0),d.entries.push(e),t(!0)))}))}));l&&(t=c(e,d,r,n.reportAllChanges),i((function(i){d=o("FCP"),t=c(e,d,r,n.reportAllChanges),s((function(){d.value=performance.now()-i.timeStamp,t(!0)}))})))}))},T=function(e,n){n=n||{},y(d((function(){var t,r=[.1,.25],a=o("CLS",0),d=0,l=[],v=function(e){e.forEach((function(e){if(!e.hadRecentInput){var n=l[0],t=l[l.length-1];d&&e.startTime-t.startTime<1e3&&e.startTime-n.startTime<5e3?(d+=e.value,l.push(e)):(d=e.value,l=[e])}})),d>a.value&&(a.value=d,a.entries=l,t())},p=u("layout-shift",v);p&&(t=c(e,a,r,n.reportAllChanges),f((function(){v(p.takeRecords()),t(!0)})),i((function(){d=0,a=o("CLS",0),t=c(e,a,r,n.reportAllChanges),s((function(){return t()}))})),setTimeout(t,0))})))},b=function(e,n){n=n||{},g((function(){var t,r=[100,300],a=h(),s=o("FID"),l=function(e){e.startTime<a.firstHiddenTime&&(s.value=e.processingStart-e.startTime,s.entries.push(e),t(!0))},v=function(e){e.forEach(l)},p=u("first-input",v);t=c(e,s,r,n.reportAllChanges),p&&f(d((function(){v(p.takeRecords()),p.disconnect()}))),console.warn('The web-vitals "base+polyfill" build is deprecated. See: https://bit.ly/3aqzsGm'),p||window.webVitals.firstInputPolyfill(l),i((function(){s=o("FID"),t=c(e,s,r,n.reportAllChanges),window.webVitals.resetFirstInputPolyfill(),window.webVitals.firstInputPolyfill(l)}))}))},w=0,C=1/0,E=0,P=function(e){e.forEach((function(e){e.interactionId&&(C=Math.min(C,e.interactionId),E=Math.max(E,e.interactionId),w=E?(E-C)/7+1:0)}))},S=function(){return n?w:performance.interactionCount||0},I=function(){"interactionCount"in performance||n||(n=u("event",P,{type:"event",buffered:!0,durationThreshold:0}))},L=0,F=function(){return S()-L},A=[],M={},k=function(e){var n=A[A.length-1],t=M[e.interactionId];if(t||A.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]};M[i.id]=i,A.push(i)}A.sort((function(e,n){return n.latency-e.latency})),A.splice(10).forEach((function(e){delete M[e.id]}))}},x=function(e,n){n=n||{},g((function(){var t=[200,500];I();var r,a=o("INP"),s=function(e){e.forEach((function(e){(e.interactionId&&k(e),"first-input"===e.entryType)&&(!A.some((function(n){return n.entries.some((function(n){return e.duration===n.duration&&e.startTime===n.startTime}))}))&&k(e))}));var n,t=(n=Math.min(A.length-1,Math.floor(F()/50)),A[n]);t&&t.latency!==a.value&&(a.value=t.latency,a.entries=t.entries,r())},d=u("event",s,{durationThreshold:n.durationThreshold||40});r=c(e,a,t,n.reportAllChanges),d&&(d.observe({type:"first-input",buffered:!0}),f((function(){s(d.takeRecords()),a.value<0&&F()>0&&(a.value=0,a.entries=[]),r(!0)})),i((function(){A=[],L=S(),a=o("INP"),r=c(e,a,t,n.reportAllChanges)})))}))},B={},D=function(e,n){n=n||{},g((function(){var t,r=[2500,4e3],l=h(),v=o("LCP"),p=function(e){var n=e[e.length-1];if(n){var i=Math.max(n.startTime-a(),0);i<l.firstHiddenTime&&(v.value=i,v.entries=[n],t())}},m=u("largest-contentful-paint",p);if(m){t=c(e,v,r,n.reportAllChanges);var g=d((function(){B[v.id]||(p(m.takeRecords()),m.disconnect(),B[v.id]=!0,t(!0))}));["keydown","click"].forEach((function(e){addEventListener(e,g,!0)})),f(g),i((function(i){v=o("LCP"),t=c(e,v,r,n.reportAllChanges),s((function(){v.value=performance.now()-i.timeStamp,B[v.id]=!0,t(!0)}))}))}}))},V=function e(n){document.prerendering?g((function(){return e(n)})):"complete"!==document.readyState?addEventListener("load",(function(){return e(n)}),!0):setTimeout(n,0)},H=function(e,n){n=n||{};var t=[800,1800],u=o("TTFB"),s=c(e,u,t,n.reportAllChanges);V((function(){var f=r();if(f){var d=f.responseStart;if(d<=0||d>performance.now())return;u.value=Math.max(d-a(),0),u.entries=[f],s(!0),i((function(){u=o("TTFB",0),(s=c(e,u,t,n.reportAllChanges))(!0)}))}}))};e.getCLS=T,e.getFCP=y,e.getFID=b,e.getINP=x,e.getLCP=D,e.getTTFB=H,e.onCLS=T,e.onFCP=y,e.onFID=b,e.onINP=x,e.onLCP=D,e.onTTFB=H,Object.defineProperty(e,"__esModule",{value:!0})}(this.webVitals=this.webVitals||{}); |
@@ -1,1 +0,1 @@ | ||
var e,n=-1,t=function(e){addEventListener("pageshow",(function(t){t.persisted&&(n=t.timeStamp,e(t))}),!0)},i=function(){return window.performance&&(performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]||function(){var e=performance.timing,n=performance.navigation.type,t={entryType:"navigation",startTime:0,type:2==n?"back_forward":1===n?"reload":"navigate"};for(var i in e)"navigationStart"!==i&&"toJSON"!==i&&(t[i]=Math.max(e[i]-e.navigationStart,0));return t}())},r=function(){var e=i();return e&&e.activationStart||0},a=function(e,t){var a=i(),o="navigate";return n>=0?o="back-forward-cache":a&&(o=document.prerendering||r()>0?"prerender":document.wasDiscarded?"restore":a.type.replace(/_/g,"-")),{name:e,value:void 0===t?-1:t,rating:"good",delta:0,entries:[],id:"v3-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:o}},o=function(e,n,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var i=new PerformanceObserver((function(e){Promise.resolve().then((function(){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,i){var r,a;return function(o){n.value>=0&&(o||i)&&((a=n.value-(r||0))||void 0===r)&&(r=n.value,n.delta=a,n.rating=function(e,n){return e>n[1]?"poor":e>n[0]?"needs-improvement":"good"}(n.value,t),e(n))}},s=function(e){requestAnimationFrame((function(){return requestAnimationFrame((function(){return e()}))}))},f=function(e){document.prerendering?addEventListener("prerenderingchange",(function(){return e()}),!0):e()},d=-1,l=function(e){"hidden"===document.visibilityState&&d>-1&&(d="visibilitychange"===e.type?e.timeStamp:0,p())},v=function(){addEventListener("visibilitychange",l,!0),addEventListener("prerenderingchange",l,!0)},p=function(){removeEventListener("visibilitychange",l,!0),removeEventListener("prerenderingchange",l,!0)},m=function(){return d<0&&((d=window.webVitals.firstHiddenTime)===1/0&&v(),t((function(){setTimeout((function(){d="hidden"!==document.visibilityState||document.prerendering?1/0:0,v()}),0)}))),{get firstHiddenTime(){return d}}},h=function(e,n){n=n||{},f((function(){var i,c=[1800,3e3],f=m(),d=a("FCP"),l=o("paint",(function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(l.disconnect(),e.startTime<f.firstHiddenTime&&(d.value=Math.max(e.startTime-r(),0),d.entries.push(e),i(!0)))}))}));l&&(i=u(e,d,c,n.reportAllChanges),t((function(t){d=a("FCP"),i=u(e,d,c,n.reportAllChanges),s((function(){d.value=performance.now()-t.timeStamp,i(!0)}))})))}))},g=function(e,n){n=n||{},f((function(){var i,r=[.1,.25],f=a("CLS"),d=-1,l=0,v=[],p=function(n){d>-1&&e(n)},m=function(e){e.forEach((function(e){if(!e.hadRecentInput){var n=v[0],t=v[v.length-1];l&&e.startTime-t.startTime<1e3&&e.startTime-n.startTime<5e3?(l+=e.value,v.push(e)):(l=e.value,v=[e]),l>f.value&&(f.value=l,f.entries=v,i())}}))},g=o("layout-shift",m);g&&(i=u(p,f,r,n.reportAllChanges),h((function(e){d=e.value,f.value<0&&(f.value=0,i())})),c((function(){m(g.takeRecords()),i(!0)})),t((function(){l=0,d=-1,f=a("CLS",0),i=u(p,f,r,n.reportAllChanges),s((function(){return i()}))})))}))},y=function(e,n){n=n||{},f((function(){var i,r=[100,300],s=m(),f=a("FID"),d=function(e){e.startTime<s.firstHiddenTime&&(f.value=e.processingStart-e.startTime,f.entries.push(e),i(!0))},l=function(e){e.forEach(d)},v=o("first-input",l);i=u(e,f,r,n.reportAllChanges),v&&c((function(){l(v.takeRecords()),v.disconnect()}),!0),console.warn('The web-vitals "base+polyfill" build is deprecated. See: https://bit.ly/3aqzsGm'),v||window.webVitals.firstInputPolyfill(d),t((function(){f=a("FID"),i=u(e,f,r,n.reportAllChanges),window.webVitals.resetFirstInputPolyfill(),window.webVitals.firstInputPolyfill(d)}))}))},T=0,b=1/0,w=0,C=function(e){e.forEach((function(e){e.interactionId&&(b=Math.min(b,e.interactionId),w=Math.max(w,e.interactionId),T=w?(w-b)/7+1:0)}))},E=function(){return e?T:performance.interactionCount||0},L=function(){"interactionCount"in performance||e||(e=o("event",C,{type:"event",buffered:!0,durationThreshold:0}))},S=0,I=function(){return E()-S},P=[],A={},F=function(e){var n=P[P.length-1],t=A[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]};A[i.id]=i,P.push(i)}P.sort((function(e,n){return n.latency-e.latency})),P.splice(10).forEach((function(e){delete A[e.id]}))}},M=function(e,n){n=n||{},f((function(){var i=[200,500];L();var r,s=a("INP"),f=function(e){e.forEach((function(e){(e.interactionId&&F(e),"first-input"===e.entryType)&&(!P.some((function(n){return n.entries.some((function(n){return e.duration===n.duration&&e.startTime===n.startTime}))}))&&F(e))}));var n,t=(n=Math.min(P.length-1,Math.floor(I()/50)),P[n]);t&&t.latency!==s.value&&(s.value=t.latency,s.entries=t.entries,r())},d=o("event",f,{durationThreshold:n.durationThreshold||40});r=u(e,s,i,n.reportAllChanges),d&&(d.observe({type:"first-input",buffered:!0}),c((function(){f(d.takeRecords()),s.value<0&&I()>0&&(s.value=0,s.entries=[]),r(!0)})),t((function(){P=[],S=E(),s=a("INP"),r=u(e,s,i,n.reportAllChanges)})))}))},k={},x=function(e,n){n=n||{},f((function(){var i,f=[2500,4e3],d=m(),l=a("LCP"),v=function(e){var n=e[e.length-1];if(n){var t=Math.max(n.startTime-r(),0);t<d.firstHiddenTime&&(l.value=t,l.entries=[n],i())}},p=o("largest-contentful-paint",v);if(p){i=u(e,l,f,n.reportAllChanges);var h=function(){k[l.id]||(v(p.takeRecords()),p.disconnect(),k[l.id]=!0,i(!0))};["keydown","click"].forEach((function(e){addEventListener(e,h,{once:!0,capture:!0})})),c(h,!0),t((function(t){l=a("LCP"),i=u(e,l,f,n.reportAllChanges),s((function(){l.value=performance.now()-t.timeStamp,k[l.id]=!0,i(!0)}))}))}}))},B=function e(n){document.prerendering?f((function(){return e(n)})):"complete"!==document.readyState?addEventListener("load",(function(){return e(n)}),!0):setTimeout(n,0)},D=function(e,n){n=n||{};var o=[800,1800],c=a("TTFB"),s=u(e,c,o,n.reportAllChanges);B((function(){var f=i();if(f){var d=f.responseStart;if(d<=0||d>performance.now())return;c.value=Math.max(d-r(),0),c.entries=[f],s(!0),t((function(){c=a("TTFB",0),(s=u(e,c,o,n.reportAllChanges))(!0)}))}}))};export{g as getCLS,h as getFCP,y as getFID,M as getINP,x as getLCP,D as getTTFB,g as onCLS,h as onFCP,y as onFID,M as onINP,x as onLCP,D as onTTFB}; | ||
var e,n=-1,t=function(e){addEventListener("pageshow",(function(t){t.persisted&&(n=t.timeStamp,e(t))}),!0)},i=function(){return window.performance&&(performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]||function(){var e=performance.timing,n=performance.navigation.type,t={entryType:"navigation",startTime:0,type:2==n?"back_forward":1===n?"reload":"navigate"};for(var i in e)"navigationStart"!==i&&"toJSON"!==i&&(t[i]=Math.max(e[i]-e.navigationStart,0));return t}())},r=function(){var e=i();return e&&e.activationStart||0},a=function(e,t){var a=i(),o="navigate";return n>=0?o="back-forward-cache":a&&(o=document.prerendering||r()>0?"prerender":document.wasDiscarded?"restore":a.type.replace(/_/g,"-")),{name:e,value:void 0===t?-1:t,rating:"good",delta:0,entries:[],id:"v3-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:o}},o=function(e,n,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var i=new PerformanceObserver((function(e){Promise.resolve().then((function(){n(e.getEntries())}))}));return i.observe(Object.assign({type:e,buffered:!0},t||{})),i}}catch(e){}},c=function(e,n,t,i){var r,a;return function(o){n.value>=0&&(o||i)&&((a=n.value-(r||0))||void 0===r)&&(r=n.value,n.delta=a,n.rating=function(e,n){return e>n[1]?"poor":e>n[0]?"needs-improvement":"good"}(n.value,t),e(n))}},u=function(e){requestAnimationFrame((function(){return requestAnimationFrame((function(){return e()}))}))},s=function(e){var n=function(n){"pagehide"!==n.type&&"hidden"!==document.visibilityState||e(n)};addEventListener("visibilitychange",n,!0),addEventListener("pagehide",n,!0)},f=function(e){var n=!1;return function(t){n||(e(t),n=!0)}},d=-1,l=function(e){"hidden"===document.visibilityState&&d>-1&&(d="visibilitychange"===e.type?e.timeStamp:0,p())},v=function(){addEventListener("visibilitychange",l,!0),addEventListener("prerenderingchange",l,!0)},p=function(){removeEventListener("visibilitychange",l,!0),removeEventListener("prerenderingchange",l,!0)},m=function(){return d<0&&((d=window.webVitals.firstHiddenTime)===1/0&&v(),t((function(){setTimeout((function(){d="hidden"!==document.visibilityState||document.prerendering?1/0:0,v()}),0)}))),{get firstHiddenTime(){return d}}},h=function(e){document.prerendering?addEventListener("prerenderingchange",(function(){return e()}),!0):e()},g=function(e,n){n=n||{},h((function(){var i,s=[1800,3e3],f=m(),d=a("FCP"),l=o("paint",(function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(l.disconnect(),e.startTime<f.firstHiddenTime&&(d.value=Math.max(e.startTime-r(),0),d.entries.push(e),i(!0)))}))}));l&&(i=c(e,d,s,n.reportAllChanges),t((function(t){d=a("FCP"),i=c(e,d,s,n.reportAllChanges),u((function(){d.value=performance.now()-t.timeStamp,i(!0)}))})))}))},y=function(e,n){n=n||{},g(f((function(){var i,r=[.1,.25],f=a("CLS",0),d=0,l=[],v=function(e){e.forEach((function(e){if(!e.hadRecentInput){var n=l[0],t=l[l.length-1];d&&e.startTime-t.startTime<1e3&&e.startTime-n.startTime<5e3?(d+=e.value,l.push(e)):(d=e.value,l=[e])}})),d>f.value&&(f.value=d,f.entries=l,i())},p=o("layout-shift",v);p&&(i=c(e,f,r,n.reportAllChanges),s((function(){v(p.takeRecords()),i(!0)})),t((function(){d=0,f=a("CLS",0),i=c(e,f,r,n.reportAllChanges),u((function(){return i()}))})),setTimeout(i,0))})))},T=function(e,n){n=n||{},h((function(){var i,r=[100,300],u=m(),d=a("FID"),l=function(e){e.startTime<u.firstHiddenTime&&(d.value=e.processingStart-e.startTime,d.entries.push(e),i(!0))},v=function(e){e.forEach(l)},p=o("first-input",v);i=c(e,d,r,n.reportAllChanges),p&&s(f((function(){v(p.takeRecords()),p.disconnect()}))),console.warn('The web-vitals "base+polyfill" build is deprecated. See: https://bit.ly/3aqzsGm'),p||window.webVitals.firstInputPolyfill(l),t((function(){d=a("FID"),i=c(e,d,r,n.reportAllChanges),window.webVitals.resetFirstInputPolyfill(),window.webVitals.firstInputPolyfill(l)}))}))},w=0,b=1/0,C=0,E=function(e){e.forEach((function(e){e.interactionId&&(b=Math.min(b,e.interactionId),C=Math.max(C,e.interactionId),w=C?(C-b)/7+1:0)}))},S=function(){return e?w:performance.interactionCount||0},I=function(){"interactionCount"in performance||e||(e=o("event",E,{type:"event",buffered:!0,durationThreshold:0}))},L=0,P=function(){return S()-L},A=[],F={},M=function(e){var n=A[A.length-1],t=F[e.interactionId];if(t||A.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,A.push(i)}A.sort((function(e,n){return n.latency-e.latency})),A.splice(10).forEach((function(e){delete F[e.id]}))}},k=function(e,n){n=n||{},h((function(){var i=[200,500];I();var r,u=a("INP"),f=function(e){e.forEach((function(e){(e.interactionId&&M(e),"first-input"===e.entryType)&&(!A.some((function(n){return n.entries.some((function(n){return e.duration===n.duration&&e.startTime===n.startTime}))}))&&M(e))}));var n,t=(n=Math.min(A.length-1,Math.floor(P()/50)),A[n]);t&&t.latency!==u.value&&(u.value=t.latency,u.entries=t.entries,r())},d=o("event",f,{durationThreshold:n.durationThreshold||40});r=c(e,u,i,n.reportAllChanges),d&&(d.observe({type:"first-input",buffered:!0}),s((function(){f(d.takeRecords()),u.value<0&&P()>0&&(u.value=0,u.entries=[]),r(!0)})),t((function(){A=[],L=S(),u=a("INP"),r=c(e,u,i,n.reportAllChanges)})))}))},x={},B=function(e,n){n=n||{},h((function(){var i,d=[2500,4e3],l=m(),v=a("LCP"),p=function(e){var n=e[e.length-1];if(n){var t=Math.max(n.startTime-r(),0);t<l.firstHiddenTime&&(v.value=t,v.entries=[n],i())}},h=o("largest-contentful-paint",p);if(h){i=c(e,v,d,n.reportAllChanges);var g=f((function(){x[v.id]||(p(h.takeRecords()),h.disconnect(),x[v.id]=!0,i(!0))}));["keydown","click"].forEach((function(e){addEventListener(e,g,!0)})),s(g),t((function(t){v=a("LCP"),i=c(e,v,d,n.reportAllChanges),u((function(){v.value=performance.now()-t.timeStamp,x[v.id]=!0,i(!0)}))}))}}))},D=function e(n){document.prerendering?h((function(){return e(n)})):"complete"!==document.readyState?addEventListener("load",(function(){return e(n)}),!0):setTimeout(n,0)},H=function(e,n){n=n||{};var o=[800,1800],u=a("TTFB"),s=c(e,u,o,n.reportAllChanges);D((function(){var f=i();if(f){var d=f.responseStart;if(d<=0||d>performance.now())return;u.value=Math.max(d-r(),0),u.entries=[f],s(!0),t((function(){u=a("TTFB",0),(s=c(e,u,o,n.reportAllChanges))(!0)}))}}))};export{y as getCLS,g as getFCP,T as getFID,k as getINP,B as getLCP,H as getTTFB,y as onCLS,g as onFCP,T as onFID,k as onINP,B as onLCP,H as onTTFB}; |
@@ -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=n.timeStamp,e(n))}),!0)},u=function(){return window.performance&&performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]},f=function(){var e=u();return e&&e.activationStart||0},s=function(e,n){var t=u(),i="navigate";return o>=0?i="back-forward-cache":t&&(i=document.prerendering||f()>0?"prerender":document.wasDiscarded?"restore":t.type.replace(/_/g,"-")),{name:e,value:void 0===n?-1:n,rating:"good",delta:0,entries:[],id:"v3-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:i}},d=function(e,n,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var i=new PerformanceObserver((function(e){Promise.resolve().then((function(){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)},v=function(e,n,t,i){var r,a;return function(o){n.value>=0&&(o||i)&&((a=n.value-(r||0))||void 0===r)&&(r=n.value,n.delta=a,n.rating=function(e,n){return e>n[1]?"poor":e>n[0]?"needs-improvement":"good"}(n.value,t),e(n))}},p=function(e){requestAnimationFrame((function(){return requestAnimationFrame((function(){return e()}))}))},m=function(e){document.prerendering?addEventListener("prerenderingchange",(function(){return e()}),!0):e()},h=-1,g=function(){return"hidden"!==document.visibilityState||document.prerendering?1/0:0},y=function(e){"hidden"===document.visibilityState&&h>-1&&(h="visibilitychange"===e.type?e.timeStamp:0,E())},T=function(){addEventListener("visibilitychange",y,!0),addEventListener("prerenderingchange",y,!0)},E=function(){removeEventListener("visibilitychange",y,!0),removeEventListener("prerenderingchange",y,!0)},C=function(){return h<0&&(h=g(),T(),c((function(){setTimeout((function(){h=g(),T()}),0)}))),{get firstHiddenTime(){return h}}},L=function(e,n){n=n||{},m((function(){var t,i=[1800,3e3],r=C(),a=s("FCP"),o=d("paint",(function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(o.disconnect(),e.startTime<r.firstHiddenTime&&(a.value=Math.max(e.startTime-f(),0),a.entries.push(e),t(!0)))}))}));o&&(t=v(e,a,i,n.reportAllChanges),c((function(r){a=s("FCP"),t=v(e,a,i,n.reportAllChanges),p((function(){a.value=performance.now()-r.timeStamp,t(!0)}))})))}))},b=function(e,n){n=n||{},m((function(){var t,i=[.1,.25],r=s("CLS"),a=-1,o=0,u=[],f=function(n){a>-1&&e(n)},m=function(e){e.forEach((function(e){if(!e.hadRecentInput){var n=u[0],i=u[u.length-1];o&&e.startTime-i.startTime<1e3&&e.startTime-n.startTime<5e3?(o+=e.value,u.push(e)):(o=e.value,u=[e]),o>r.value&&(r.value=o,r.entries=u,t())}}))},h=d("layout-shift",m);h&&(t=v(f,r,i,n.reportAllChanges),L((function(e){a=e.value,r.value<0&&(r.value=0,t())})),l((function(){m(h.takeRecords()),t(!0)})),c((function(){o=0,a=-1,r=s("CLS",0),t=v(f,r,i,n.reportAllChanges),p((function(){return t()}))})))}))},w={passive:!0,capture:!0},S=new Date,P=function(e,r){n||(n=r,t=e,i=new Date,F(removeEventListener),I())},I=function(){if(t>=0&&t<i-S){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=[]}},A=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(){P(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):P(n,e)}},F=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(n){return e(n,A,w)}))},M=function(e,i){i=i||{},m((function(){var a,o=[100,300],u=C(),f=s("FID"),p=function(e){e.startTime<u.firstHiddenTime&&(f.value=e.processingStart-e.startTime,f.entries.push(e),a(!0))},m=function(e){e.forEach(p)},h=d("first-input",m);a=v(e,f,o,i.reportAllChanges),h&&l((function(){m(h.takeRecords()),h.disconnect()}),!0),h&&c((function(){var c;f=s("FID"),a=v(e,f,o,i.reportAllChanges),r=[],t=-1,n=null,F(addEventListener),c=p,r.push(c),I()}))}))},D=0,k=1/0,B=0,x=function(e){e.forEach((function(e){e.interactionId&&(k=Math.min(k,e.interactionId),B=Math.max(B,e.interactionId),D=B?(B-k)/7+1:0)}))},R=function(){return a?D:performance.interactionCount||0},H=function(){"interactionCount"in performance||a||(a=d("event",x,{type:"event",buffered:!0,durationThreshold:0}))},N=0,O=function(){return R()-N},_=[],j={},q=function(e){var n=_[_.length-1],t=j[e.interactionId];if(t||_.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]};j[i.id]=i,_.push(i)}_.sort((function(e,n){return n.latency-e.latency})),_.splice(10).forEach((function(e){delete j[e.id]}))}},V=function(e,n){n=n||{},m((function(){var t=[200,500];H();var i,r=s("INP"),a=function(e){e.forEach((function(e){(e.interactionId&&q(e),"first-input"===e.entryType)&&(!_.some((function(n){return n.entries.some((function(n){return e.duration===n.duration&&e.startTime===n.startTime}))}))&&q(e))}));var n,t=(n=Math.min(_.length-1,Math.floor(O()/50)),_[n]);t&&t.latency!==r.value&&(r.value=t.latency,r.entries=t.entries,i())},o=d("event",a,{durationThreshold:n.durationThreshold||40});i=v(e,r,t,n.reportAllChanges),o&&(o.observe({type:"first-input",buffered:!0}),l((function(){a(o.takeRecords()),r.value<0&&O()>0&&(r.value=0,r.entries=[]),i(!0)})),c((function(){_=[],N=R(),r=s("INP"),i=v(e,r,t,n.reportAllChanges)})))}))},z={},G=function(e,n){n=n||{},m((function(){var t,i=[2500,4e3],r=C(),a=s("LCP"),o=function(e){var n=e[e.length-1];if(n){var i=Math.max(n.startTime-f(),0);i<r.firstHiddenTime&&(a.value=i,a.entries=[n],t())}},u=d("largest-contentful-paint",o);if(u){t=v(e,a,i,n.reportAllChanges);var m=function(){z[a.id]||(o(u.takeRecords()),u.disconnect(),z[a.id]=!0,t(!0))};["keydown","click"].forEach((function(e){addEventListener(e,m,{once:!0,capture:!0})})),l(m,!0),c((function(r){a=s("LCP"),t=v(e,a,i,n.reportAllChanges),p((function(){a.value=performance.now()-r.timeStamp,z[a.id]=!0,t(!0)}))}))}}))},J=function e(n){document.prerendering?m((function(){return e(n)})):"complete"!==document.readyState?addEventListener("load",(function(){return e(n)}),!0):setTimeout(n,0)},K=function(e,n){n=n||{};var t=[800,1800],i=s("TTFB"),r=v(e,i,t,n.reportAllChanges);J((function(){var a=u();if(a){var o=a.responseStart;if(o<=0||o>performance.now())return;i.value=Math.max(o-f(),0),i.entries=[a],r(!0),c((function(){i=s("TTFB",0),(r=v(e,i,t,n.reportAllChanges))(!0)}))}}))};return e.getCLS=b,e.getFCP=L,e.getFID=M,e.getINP=V,e.getLCP=G,e.getTTFB=K,e.onCLS=b,e.onFCP=L,e.onFID=M,e.onINP=V,e.onLCP=G,e.onTTFB=K,Object.defineProperty(e,"__esModule",{value:!0}),e}({}); | ||
var webVitals=function(e){"use strict";var n,t,r,i,o,a=-1,c=function(e){addEventListener("pageshow",(function(n){n.persisted&&(a=n.timeStamp,e(n))}),!0)},u=function(){return window.performance&&performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]},f=function(){var e=u();return e&&e.activationStart||0},s=function(e,n){var t=u(),r="navigate";return a>=0?r="back-forward-cache":t&&(r=document.prerendering||f()>0?"prerender":document.wasDiscarded?"restore":t.type.replace(/_/g,"-")),{name:e,value:void 0===n?-1:n,rating:"good",delta:0,entries:[],id:"v3-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:r}},d=function(e,n,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var r=new PerformanceObserver((function(e){Promise.resolve().then((function(){n(e.getEntries())}))}));return r.observe(Object.assign({type:e,buffered:!0},t||{})),r}}catch(e){}},l=function(e,n,t,r){var i,o;return function(a){n.value>=0&&(a||r)&&((o=n.value-(i||0))||void 0===i)&&(i=n.value,n.delta=o,n.rating=function(e,n){return e>n[1]?"poor":e>n[0]?"needs-improvement":"good"}(n.value,t),e(n))}},v=function(e){requestAnimationFrame((function(){return requestAnimationFrame((function(){return e()}))}))},p=function(e){var n=function(n){"pagehide"!==n.type&&"hidden"!==document.visibilityState||e(n)};addEventListener("visibilitychange",n,!0),addEventListener("pagehide",n,!0)},m=function(e){var n=!1;return function(t){n||(e(t),n=!0)}},h=-1,g=function(){return"hidden"!==document.visibilityState||document.prerendering?1/0:0},y=function(e){"hidden"===document.visibilityState&&h>-1&&(h="visibilitychange"===e.type?e.timeStamp:0,E())},T=function(){addEventListener("visibilitychange",y,!0),addEventListener("prerenderingchange",y,!0)},E=function(){removeEventListener("visibilitychange",y,!0),removeEventListener("prerenderingchange",y,!0)},C=function(){return h<0&&(h=g(),T(),c((function(){setTimeout((function(){h=g(),T()}),0)}))),{get firstHiddenTime(){return h}}},L=function(e){document.prerendering?addEventListener("prerenderingchange",(function(){return e()}),!0):e()},b=function(e,n){n=n||{},L((function(){var t,r=[1800,3e3],i=C(),o=s("FCP"),a=d("paint",(function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(a.disconnect(),e.startTime<i.firstHiddenTime&&(o.value=Math.max(e.startTime-f(),0),o.entries.push(e),t(!0)))}))}));a&&(t=l(e,o,r,n.reportAllChanges),c((function(i){o=s("FCP"),t=l(e,o,r,n.reportAllChanges),v((function(){o.value=performance.now()-i.timeStamp,t(!0)}))})))}))},w=function(e,n){n=n||{},b(m((function(){var t,r=[.1,.25],i=s("CLS",0),o=0,a=[],u=function(e){e.forEach((function(e){if(!e.hadRecentInput){var n=a[0],t=a[a.length-1];o&&e.startTime-t.startTime<1e3&&e.startTime-n.startTime<5e3?(o+=e.value,a.push(e)):(o=e.value,a=[e])}})),o>i.value&&(i.value=o,i.entries=a,t())},f=d("layout-shift",u);f&&(t=l(e,i,r,n.reportAllChanges),p((function(){u(f.takeRecords()),t(!0)})),c((function(){o=0,i=s("CLS",0),t=l(e,i,r,n.reportAllChanges),v((function(){return t()}))})),setTimeout(t,0))})))},S={passive:!0,capture:!0},P=new Date,I=function(e,i){n||(n=i,t=e,r=new Date,M(removeEventListener),A())},A=function(){if(t>=0&&t<r-P){var e={entryType:"first-input",name:n.type,target:n.target,cancelable:n.cancelable,startTime:n.timeStamp,processingStart:n.timeStamp+t};i.forEach((function(n){n(e)})),i=[]}},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(){I(e,n),i()},r=function(){i()},i=function(){removeEventListener("pointerup",t,S),removeEventListener("pointercancel",r,S)};addEventListener("pointerup",t,S),addEventListener("pointercancel",r,S)}(n,e):I(n,e)}},M=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(n){return e(n,F,S)}))},D=function(e,r){r=r||{},L((function(){var o,a=[100,300],u=C(),f=s("FID"),v=function(e){e.startTime<u.firstHiddenTime&&(f.value=e.processingStart-e.startTime,f.entries.push(e),o(!0))},h=function(e){e.forEach(v)},g=d("first-input",h);o=l(e,f,a,r.reportAllChanges),g&&p(m((function(){h(g.takeRecords()),g.disconnect()}))),g&&c((function(){var c;f=s("FID"),o=l(e,f,a,r.reportAllChanges),i=[],t=-1,n=null,M(addEventListener),c=v,i.push(c),A()}))}))},k=0,B=1/0,x=0,R=function(e){e.forEach((function(e){e.interactionId&&(B=Math.min(B,e.interactionId),x=Math.max(x,e.interactionId),k=x?(x-B)/7+1:0)}))},H=function(){return o?k:performance.interactionCount||0},N=function(){"interactionCount"in performance||o||(o=d("event",R,{type:"event",buffered:!0,durationThreshold:0}))},O=0,_=function(){return H()-O},j=[],q={},V=function(e){var n=j[j.length-1],t=q[e.interactionId];if(t||j.length<10||e.duration>n.latency){if(t)t.entries.push(e),t.latency=Math.max(t.latency,e.duration);else{var r={id:e.interactionId,latency:e.duration,entries:[e]};q[r.id]=r,j.push(r)}j.sort((function(e,n){return n.latency-e.latency})),j.splice(10).forEach((function(e){delete q[e.id]}))}},z=function(e,n){n=n||{},L((function(){var t=[200,500];N();var r,i=s("INP"),o=function(e){e.forEach((function(e){(e.interactionId&&V(e),"first-input"===e.entryType)&&(!j.some((function(n){return n.entries.some((function(n){return e.duration===n.duration&&e.startTime===n.startTime}))}))&&V(e))}));var n,t=(n=Math.min(j.length-1,Math.floor(_()/50)),j[n]);t&&t.latency!==i.value&&(i.value=t.latency,i.entries=t.entries,r())},a=d("event",o,{durationThreshold:n.durationThreshold||40});r=l(e,i,t,n.reportAllChanges),a&&(a.observe({type:"first-input",buffered:!0}),p((function(){o(a.takeRecords()),i.value<0&&_()>0&&(i.value=0,i.entries=[]),r(!0)})),c((function(){j=[],O=H(),i=s("INP"),r=l(e,i,t,n.reportAllChanges)})))}))},G={},J=function(e,n){n=n||{},L((function(){var t,r=[2500,4e3],i=C(),o=s("LCP"),a=function(e){var n=e[e.length-1];if(n){var r=Math.max(n.startTime-f(),0);r<i.firstHiddenTime&&(o.value=r,o.entries=[n],t())}},u=d("largest-contentful-paint",a);if(u){t=l(e,o,r,n.reportAllChanges);var h=m((function(){G[o.id]||(a(u.takeRecords()),u.disconnect(),G[o.id]=!0,t(!0))}));["keydown","click"].forEach((function(e){addEventListener(e,h,!0)})),p(h),c((function(i){o=s("LCP"),t=l(e,o,r,n.reportAllChanges),v((function(){o.value=performance.now()-i.timeStamp,G[o.id]=!0,t(!0)}))}))}}))},K=function e(n){document.prerendering?L((function(){return e(n)})):"complete"!==document.readyState?addEventListener("load",(function(){return e(n)}),!0):setTimeout(n,0)},Q=function(e,n){n=n||{};var t=[800,1800],r=s("TTFB"),i=l(e,r,t,n.reportAllChanges);K((function(){var o=u();if(o){var a=o.responseStart;if(a<=0||a>performance.now())return;r.value=Math.max(a-f(),0),r.entries=[o],i(!0),c((function(){r=s("TTFB",0),(i=l(e,r,t,n.reportAllChanges))(!0)}))}}))};return e.getCLS=w,e.getFCP=b,e.getFID=D,e.getINP=z,e.getLCP=J,e.getTTFB=Q,e.onCLS=w,e.onFCP=b,e.onFID=D,e.onINP=z,e.onLCP=J,e.onTTFB=Q,Object.defineProperty(e,"__esModule",{value:!0}),e}({}); |
@@ -1,1 +0,1 @@ | ||
var e,n,t,i,r,a=-1,o=function(e){addEventListener("pageshow",(function(n){n.persisted&&(a=n.timeStamp,e(n))}),!0)},c=function(){return window.performance&&performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]},u=function(){var e=c();return e&&e.activationStart||0},f=function(e,n){var t=c(),i="navigate";return a>=0?i="back-forward-cache":t&&(i=document.prerendering||u()>0?"prerender":document.wasDiscarded?"restore":t.type.replace(/_/g,"-")),{name:e,value:void 0===n?-1:n,rating:"good",delta:0,entries:[],id:"v3-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:i}},s=function(e,n,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var i=new PerformanceObserver((function(e){Promise.resolve().then((function(){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,i){var r,a;return function(o){n.value>=0&&(o||i)&&((a=n.value-(r||0))||void 0===r)&&(r=n.value,n.delta=a,n.rating=function(e,n){return e>n[1]?"poor":e>n[0]?"needs-improvement":"good"}(n.value,t),e(n))}},l=function(e){requestAnimationFrame((function(){return requestAnimationFrame((function(){return e()}))}))},p=function(e){document.prerendering?addEventListener("prerenderingchange",(function(){return e()}),!0):e()},m=-1,h=function(){return"hidden"!==document.visibilityState||document.prerendering?1/0:0},g=function(e){"hidden"===document.visibilityState&&m>-1&&(m="visibilitychange"===e.type?e.timeStamp:0,T())},y=function(){addEventListener("visibilitychange",g,!0),addEventListener("prerenderingchange",g,!0)},T=function(){removeEventListener("visibilitychange",g,!0),removeEventListener("prerenderingchange",g,!0)},E=function(){return m<0&&(m=h(),y(),o((function(){setTimeout((function(){m=h(),y()}),0)}))),{get firstHiddenTime(){return m}}},L=function(e,n){n=n||{},p((function(){var t,i=[1800,3e3],r=E(),a=f("FCP"),c=s("paint",(function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(c.disconnect(),e.startTime<r.firstHiddenTime&&(a.value=Math.max(e.startTime-u(),0),a.entries.push(e),t(!0)))}))}));c&&(t=v(e,a,i,n.reportAllChanges),o((function(r){a=f("FCP"),t=v(e,a,i,n.reportAllChanges),l((function(){a.value=performance.now()-r.timeStamp,t(!0)}))})))}))},C=function(e,n){n=n||{},p((function(){var t,i=[.1,.25],r=f("CLS"),a=-1,c=0,u=[],p=function(n){a>-1&&e(n)},m=function(e){e.forEach((function(e){if(!e.hadRecentInput){var n=u[0],i=u[u.length-1];c&&e.startTime-i.startTime<1e3&&e.startTime-n.startTime<5e3?(c+=e.value,u.push(e)):(c=e.value,u=[e]),c>r.value&&(r.value=c,r.entries=u,t())}}))},h=s("layout-shift",m);h&&(t=v(p,r,i,n.reportAllChanges),L((function(e){a=e.value,r.value<0&&(r.value=0,t())})),d((function(){m(h.takeRecords()),t(!0)})),o((function(){c=0,a=-1,r=f("CLS",0),t=v(p,r,i,n.reportAllChanges),l((function(){return t()}))})))}))},b={passive:!0,capture:!0},w=new Date,S=function(i,r){e||(e=r,n=i,t=new Date,P(removeEventListener),A())},A=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=[]}},I=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,b),removeEventListener("pointercancel",i,b)};addEventListener("pointerup",t,b),addEventListener("pointercancel",i,b)}(n,e):S(n,e)}},P=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(n){return e(n,I,b)}))},F=function(t,r){r=r||{},p((function(){var a,c=[100,300],u=E(),l=f("FID"),p=function(e){e.startTime<u.firstHiddenTime&&(l.value=e.processingStart-e.startTime,l.entries.push(e),a(!0))},m=function(e){e.forEach(p)},h=s("first-input",m);a=v(t,l,c,r.reportAllChanges),h&&d((function(){m(h.takeRecords()),h.disconnect()}),!0),h&&o((function(){var o;l=f("FID"),a=v(t,l,c,r.reportAllChanges),i=[],n=-1,e=null,P(addEventListener),o=p,i.push(o),A()}))}))},M=0,k=1/0,D=0,x=function(e){e.forEach((function(e){e.interactionId&&(k=Math.min(k,e.interactionId),D=Math.max(D,e.interactionId),M=D?(D-k)/7+1:0)}))},B=function(){return r?M:performance.interactionCount||0},R=function(){"interactionCount"in performance||r||(r=s("event",x,{type:"event",buffered:!0,durationThreshold:0}))},H=0,N=function(){return B()-H},O=[],q={},j=function(e){var n=O[O.length-1],t=q[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]};q[i.id]=i,O.push(i)}O.sort((function(e,n){return n.latency-e.latency})),O.splice(10).forEach((function(e){delete q[e.id]}))}},_=function(e,n){n=n||{},p((function(){var t=[200,500];R();var i,r=f("INP"),a=function(e){e.forEach((function(e){(e.interactionId&&j(e),"first-input"===e.entryType)&&(!O.some((function(n){return n.entries.some((function(n){return e.duration===n.duration&&e.startTime===n.startTime}))}))&&j(e))}));var n,t=(n=Math.min(O.length-1,Math.floor(N()/50)),O[n]);t&&t.latency!==r.value&&(r.value=t.latency,r.entries=t.entries,i())},c=s("event",a,{durationThreshold:n.durationThreshold||40});i=v(e,r,t,n.reportAllChanges),c&&(c.observe({type:"first-input",buffered:!0}),d((function(){a(c.takeRecords()),r.value<0&&N()>0&&(r.value=0,r.entries=[]),i(!0)})),o((function(){O=[],H=B(),r=f("INP"),i=v(e,r,t,n.reportAllChanges)})))}))},z={},G=function(e,n){n=n||{},p((function(){var t,i=[2500,4e3],r=E(),a=f("LCP"),c=function(e){var n=e[e.length-1];if(n){var i=Math.max(n.startTime-u(),0);i<r.firstHiddenTime&&(a.value=i,a.entries=[n],t())}},p=s("largest-contentful-paint",c);if(p){t=v(e,a,i,n.reportAllChanges);var m=function(){z[a.id]||(c(p.takeRecords()),p.disconnect(),z[a.id]=!0,t(!0))};["keydown","click"].forEach((function(e){addEventListener(e,m,{once:!0,capture:!0})})),d(m,!0),o((function(r){a=f("LCP"),t=v(e,a,i,n.reportAllChanges),l((function(){a.value=performance.now()-r.timeStamp,z[a.id]=!0,t(!0)}))}))}}))},J=function e(n){document.prerendering?p((function(){return e(n)})):"complete"!==document.readyState?addEventListener("load",(function(){return e(n)}),!0):setTimeout(n,0)},K=function(e,n){n=n||{};var t=[800,1800],i=f("TTFB"),r=v(e,i,t,n.reportAllChanges);J((function(){var a=c();if(a){var s=a.responseStart;if(s<=0||s>performance.now())return;i.value=Math.max(s-u(),0),i.entries=[a],r(!0),o((function(){i=f("TTFB",0),(r=v(e,i,t,n.reportAllChanges))(!0)}))}}))};export{C as getCLS,L as getFCP,F as getFID,_ as getINP,G as getLCP,K as getTTFB,C as onCLS,L as onFCP,F as onFID,_ as onINP,G as onLCP,K as onTTFB}; | ||
var e,n,t,r,i,a=-1,o=function(e){addEventListener("pageshow",(function(n){n.persisted&&(a=n.timeStamp,e(n))}),!0)},c=function(){return window.performance&&performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]},u=function(){var e=c();return e&&e.activationStart||0},f=function(e,n){var t=c(),r="navigate";return a>=0?r="back-forward-cache":t&&(r=document.prerendering||u()>0?"prerender":document.wasDiscarded?"restore":t.type.replace(/_/g,"-")),{name:e,value:void 0===n?-1:n,rating:"good",delta:0,entries:[],id:"v3-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:r}},s=function(e,n,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var r=new PerformanceObserver((function(e){Promise.resolve().then((function(){n(e.getEntries())}))}));return r.observe(Object.assign({type:e,buffered:!0},t||{})),r}}catch(e){}},d=function(e,n,t,r){var i,a;return function(o){n.value>=0&&(o||r)&&((a=n.value-(i||0))||void 0===i)&&(i=n.value,n.delta=a,n.rating=function(e,n){return e>n[1]?"poor":e>n[0]?"needs-improvement":"good"}(n.value,t),e(n))}},l=function(e){requestAnimationFrame((function(){return requestAnimationFrame((function(){return e()}))}))},v=function(e){var n=function(n){"pagehide"!==n.type&&"hidden"!==document.visibilityState||e(n)};addEventListener("visibilitychange",n,!0),addEventListener("pagehide",n,!0)},p=function(e){var n=!1;return function(t){n||(e(t),n=!0)}},m=-1,h=function(){return"hidden"!==document.visibilityState||document.prerendering?1/0:0},g=function(e){"hidden"===document.visibilityState&&m>-1&&(m="visibilitychange"===e.type?e.timeStamp:0,T())},y=function(){addEventListener("visibilitychange",g,!0),addEventListener("prerenderingchange",g,!0)},T=function(){removeEventListener("visibilitychange",g,!0),removeEventListener("prerenderingchange",g,!0)},E=function(){return m<0&&(m=h(),y(),o((function(){setTimeout((function(){m=h(),y()}),0)}))),{get firstHiddenTime(){return m}}},C=function(e){document.prerendering?addEventListener("prerenderingchange",(function(){return e()}),!0):e()},L=function(e,n){n=n||{},C((function(){var t,r=[1800,3e3],i=E(),a=f("FCP"),c=s("paint",(function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(c.disconnect(),e.startTime<i.firstHiddenTime&&(a.value=Math.max(e.startTime-u(),0),a.entries.push(e),t(!0)))}))}));c&&(t=d(e,a,r,n.reportAllChanges),o((function(i){a=f("FCP"),t=d(e,a,r,n.reportAllChanges),l((function(){a.value=performance.now()-i.timeStamp,t(!0)}))})))}))},b=function(e,n){n=n||{},L(p((function(){var t,r=[.1,.25],i=f("CLS",0),a=0,c=[],u=function(e){e.forEach((function(e){if(!e.hadRecentInput){var n=c[0],t=c[c.length-1];a&&e.startTime-t.startTime<1e3&&e.startTime-n.startTime<5e3?(a+=e.value,c.push(e)):(a=e.value,c=[e])}})),a>i.value&&(i.value=a,i.entries=c,t())},p=s("layout-shift",u);p&&(t=d(e,i,r,n.reportAllChanges),v((function(){u(p.takeRecords()),t(!0)})),o((function(){a=0,i=f("CLS",0),t=d(e,i,r,n.reportAllChanges),l((function(){return t()}))})),setTimeout(t,0))})))},w={passive:!0,capture:!0},S=new Date,A=function(r,i){e||(e=i,n=r,t=new Date,F(removeEventListener),I())},I=function(){if(n>=0&&n<t-S){var i={entryType:"first-input",name:e.type,target:e.target,cancelable:e.cancelable,startTime:e.timeStamp,processingStart:e.timeStamp+n};r.forEach((function(e){e(i)})),r=[]}},P=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(){A(e,n),i()},r=function(){i()},i=function(){removeEventListener("pointerup",t,w),removeEventListener("pointercancel",r,w)};addEventListener("pointerup",t,w),addEventListener("pointercancel",r,w)}(n,e):A(n,e)}},F=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(n){return e(n,P,w)}))},M=function(t,i){i=i||{},C((function(){var a,c=[100,300],u=E(),l=f("FID"),m=function(e){e.startTime<u.firstHiddenTime&&(l.value=e.processingStart-e.startTime,l.entries.push(e),a(!0))},h=function(e){e.forEach(m)},g=s("first-input",h);a=d(t,l,c,i.reportAllChanges),g&&v(p((function(){h(g.takeRecords()),g.disconnect()}))),g&&o((function(){var o;l=f("FID"),a=d(t,l,c,i.reportAllChanges),r=[],n=-1,e=null,F(addEventListener),o=m,r.push(o),I()}))}))},k=0,D=1/0,x=0,B=function(e){e.forEach((function(e){e.interactionId&&(D=Math.min(D,e.interactionId),x=Math.max(x,e.interactionId),k=x?(x-D)/7+1:0)}))},R=function(){return i?k:performance.interactionCount||0},H=function(){"interactionCount"in performance||i||(i=s("event",B,{type:"event",buffered:!0,durationThreshold:0}))},N=0,O=function(){return R()-N},q=[],j={},_=function(e){var n=q[q.length-1],t=j[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 r={id:e.interactionId,latency:e.duration,entries:[e]};j[r.id]=r,q.push(r)}q.sort((function(e,n){return n.latency-e.latency})),q.splice(10).forEach((function(e){delete j[e.id]}))}},z=function(e,n){n=n||{},C((function(){var t=[200,500];H();var r,i=f("INP"),a=function(e){e.forEach((function(e){(e.interactionId&&_(e),"first-input"===e.entryType)&&(!q.some((function(n){return n.entries.some((function(n){return e.duration===n.duration&&e.startTime===n.startTime}))}))&&_(e))}));var n,t=(n=Math.min(q.length-1,Math.floor(O()/50)),q[n]);t&&t.latency!==i.value&&(i.value=t.latency,i.entries=t.entries,r())},c=s("event",a,{durationThreshold:n.durationThreshold||40});r=d(e,i,t,n.reportAllChanges),c&&(c.observe({type:"first-input",buffered:!0}),v((function(){a(c.takeRecords()),i.value<0&&O()>0&&(i.value=0,i.entries=[]),r(!0)})),o((function(){q=[],N=R(),i=f("INP"),r=d(e,i,t,n.reportAllChanges)})))}))},G={},J=function(e,n){n=n||{},C((function(){var t,r=[2500,4e3],i=E(),a=f("LCP"),c=function(e){var n=e[e.length-1];if(n){var r=Math.max(n.startTime-u(),0);r<i.firstHiddenTime&&(a.value=r,a.entries=[n],t())}},m=s("largest-contentful-paint",c);if(m){t=d(e,a,r,n.reportAllChanges);var h=p((function(){G[a.id]||(c(m.takeRecords()),m.disconnect(),G[a.id]=!0,t(!0))}));["keydown","click"].forEach((function(e){addEventListener(e,h,!0)})),v(h),o((function(i){a=f("LCP"),t=d(e,a,r,n.reportAllChanges),l((function(){a.value=performance.now()-i.timeStamp,G[a.id]=!0,t(!0)}))}))}}))},K=function e(n){document.prerendering?C((function(){return e(n)})):"complete"!==document.readyState?addEventListener("load",(function(){return e(n)}),!0):setTimeout(n,0)},Q=function(e,n){n=n||{};var t=[800,1800],r=f("TTFB"),i=d(e,r,t,n.reportAllChanges);K((function(){var a=c();if(a){var s=a.responseStart;if(s<=0||s>performance.now())return;r.value=Math.max(s-u(),0),r.entries=[a],i(!0),o((function(){r=f("TTFB",0),(i=d(e,r,t,n.reportAllChanges))(!0)}))}}))};export{b as getCLS,L as getFCP,M as getFID,z as getINP,J as getLCP,Q as getTTFB,b as onCLS,L as onFCP,M as onFID,z as onINP,J as onLCP,Q as onTTFB}; |
{ | ||
"name": "web-vitals", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "Easily measure performance metrics in JavaScript", | ||
@@ -99,2 +99,4 @@ "type": "module", | ||
"dev": "run-p watch test:server", | ||
"format": "prettier \"**/*.{cjs,css,html,js,json,md,ts,yml,yaml}\" --write --ignore-path .gitignore", | ||
"format:check": "prettier \"**/*.{cjs,css,html,js,json,html,md,ts,yml,yaml}\" --check --ignore-path .gitignore", | ||
"lint": "eslint \"*.js\" \"src/**/*.ts\" \"test/**/*.js\"", | ||
@@ -146,2 +148,8 @@ "lint:fix": "eslint --fix \"*.js\" \"src/**/*.ts\" \"test/**/*.js\"", | ||
}, | ||
"prettier": { | ||
"arrowParens": "always", | ||
"bracketSpacing": false, | ||
"quoteProps": "preserve", | ||
"singleQuote": true | ||
}, | ||
"devDependencies": { | ||
@@ -156,3 +164,3 @@ "@babel/core": "^7.19.3", | ||
"@wdio/mocha-framework": "^7.25.1", | ||
"@wdio/selenium-standalone-service": "^7.25.1", | ||
"@wdio/selenium-standalone-service": "^7.26.0", | ||
"@wdio/spec-reporter": "^7.25.1", | ||
@@ -162,14 +170,20 @@ "body-parser": "^1.20.0", | ||
"eslint": "^8.24.0", | ||
"eslint-config-google": "^0.14.0", | ||
"express": "^4.18.1", | ||
"fs-extra": "^10.1.0", | ||
"husky": "^8.0.1", | ||
"lint-staged": "^13.0.3", | ||
"npm-run-all": "^4.1.5", | ||
"nunjucks": "^3.2.3", | ||
"prettier": "^2.8.0", | ||
"rollup": "^2.79.1", | ||
"rollup-plugin-babel": "^4.4.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"selenium-standalone": "^8.2.3", | ||
"typescript": "^4.8.4", | ||
"wdio-chromedriver-service": "^8.0.0" | ||
}, | ||
"lint-staged": { | ||
"**/*.{js,ts}": "eslint --fix --ignore-path .gitignore", | ||
"**/*.{cjs,css,html,js,json,html,md,ts,yml,yaml}": "prettier --write --ignore-path .gitignore" | ||
} | ||
} |
130
README.md
@@ -134,3 +134,3 @@ # `web-vitals` | ||
It's important that the code is inlined directly into the HTML. *Do not link to an external script file, as that will negatively affect performance: | ||
It's important that the code is inlined directly into the HTML. _Do not link to an external script file, as that will negatively affect performance:_ | ||
@@ -178,14 +178,14 @@ ```html | ||
<script> | ||
(function() { | ||
var script = document.createElement('script'); | ||
script.src = 'https://unpkg.com/web-vitals@3/dist/web-vitals.iife.js'; | ||
script.onload = function() { | ||
// When loading `web-vitals` using a classic script, all the public | ||
// methods can be found on the `webVitals` global namespace. | ||
webVitals.onCLS(console.log); | ||
webVitals.onFID(console.log); | ||
webVitals.onLCP(console.log); | ||
} | ||
document.head.appendChild(script); | ||
}()) | ||
(function () { | ||
var script = document.createElement('script'); | ||
script.src = 'https://unpkg.com/web-vitals@3/dist/web-vitals.iife.js'; | ||
script.onload = function () { | ||
// When loading `web-vitals` using a classic script, all the public | ||
// methods can be found on the `webVitals` global namespace. | ||
webVitals.onCLS(console.log); | ||
webVitals.onFID(console.log); | ||
webVitals.onLCP(console.log); | ||
}; | ||
document.head.appendChild(script); | ||
})(); | ||
</script> | ||
@@ -199,3 +199,7 @@ ``` | ||
<script type="module"> | ||
import {onCLS, onFID, onLCP} from 'https://unpkg.com/web-vitals@3/dist/web-vitals.attribution.js?module'; | ||
import { | ||
onCLS, | ||
onFID, | ||
onLCP, | ||
} from 'https://unpkg.com/web-vitals@3/dist/web-vitals.attribution.js?module'; | ||
@@ -212,14 +216,15 @@ onCLS(console.log); | ||
<script> | ||
(function() { | ||
var script = document.createElement('script'); | ||
script.src = 'https://unpkg.com/web-vitals@3/dist/web-vitals.attribution.iife.js'; | ||
script.onload = function() { | ||
// When loading `web-vitals` using a classic script, all the public | ||
// methods can be found on the `webVitals` global namespace. | ||
webVitals.onCLS(console.log); | ||
webVitals.onFID(console.log); | ||
webVitals.onLCP(console.log); | ||
} | ||
document.head.appendChild(script); | ||
}()) | ||
(function () { | ||
var script = document.createElement('script'); | ||
script.src = | ||
'https://unpkg.com/web-vitals@3/dist/web-vitals.attribution.iife.js'; | ||
script.onload = function () { | ||
// When loading `web-vitals` using a classic script, all the public | ||
// methods can be found on the `webVitals` global namespace. | ||
webVitals.onCLS(console.log); | ||
webVitals.onFID(console.log); | ||
webVitals.onLCP(console.log); | ||
}; | ||
document.head.appendChild(script); | ||
})(); | ||
</script> | ||
@@ -313,3 +318,3 @@ ``` | ||
(navigator.sendBeacon && navigator.sendBeacon('/analytics', body)) || | ||
fetch('/analytics', {body, method: 'POST', keepalive: true}); | ||
fetch('/analytics', {body, method: 'POST', keepalive: true}); | ||
} | ||
@@ -459,3 +464,3 @@ | ||
metric_delta: delta, // Optional. | ||
} | ||
}; | ||
@@ -512,3 +517,3 @@ switch (name) { | ||
(navigator.sendBeacon && navigator.sendBeacon('/analytics', body)) || | ||
fetch('/analytics', {body, method: 'POST', keepalive: true}); | ||
fetch('/analytics', {body, method: 'POST', keepalive: true}); | ||
@@ -701,3 +706,8 @@ queue.clear(); | ||
*/ | ||
entries: (PerformanceEntry | LayoutShift | FirstInputPolyfillEntry | NavigationTimingPolyfillEntry)[]; | ||
entries: ( | ||
| PerformanceEntry | ||
| LayoutShift | ||
| FirstInputPolyfillEntry | ||
| NavigationTimingPolyfillEntry | ||
)[]; | ||
@@ -715,3 +725,9 @@ /** | ||
*/ | ||
navigationType: 'navigate' | 'reload' | 'back-forward' | 'back-forward-cache' | 'prerender' | 'restore'; | ||
navigationType: | ||
| 'navigate' | ||
| 'reload' | ||
| 'back-forward' | ||
| 'back-forward-cache' | ||
| 'prerender' | ||
| 'restore'; | ||
} | ||
@@ -740,3 +756,3 @@ ``` | ||
*/ | ||
attribution: {[key: string]: unknown}; | ||
attribution: {[key: string]: unknown}; | ||
} | ||
@@ -800,3 +816,7 @@ ``` | ||
*/ | ||
type LoadState = 'loading' | 'dom-interactive' | 'dom-content-loaded' | 'complete'; | ||
type LoadState = | ||
| 'loading' | ||
| 'dom-interactive' | ||
| 'dom-content-loaded' | ||
| 'complete'; | ||
``` | ||
@@ -809,3 +829,6 @@ | ||
```ts | ||
type FirstInputPolyfillEntry = Omit<PerformanceEventTiming, 'processingEnd' | 'toJSON'> | ||
type FirstInputPolyfillEntry = Omit< | ||
PerformanceEventTiming, | ||
'processingEnd' | 'toJSON' | ||
>; | ||
``` | ||
@@ -826,7 +849,14 @@ | ||
```ts | ||
type NavigationTimingPolyfillEntry = Omit<PerformanceNavigationTiming, | ||
'initiatorType' | 'nextHopProtocol' | 'redirectCount' | 'transferSize' | | ||
'encodedBodySize' | 'decodedBodySize' | 'type'> & { | ||
type NavigationTimingPolyfillEntry = Omit< | ||
PerformanceNavigationTiming, | ||
| 'initiatorType' | ||
| 'nextHopProtocol' | ||
| 'redirectCount' | ||
| 'transferSize' | ||
| 'encodedBodySize' | ||
| 'decodedBodySize' | ||
| 'type' | ||
> & { | ||
type: PerformanceNavigationTiming['type']; | ||
} | ||
}; | ||
``` | ||
@@ -851,3 +881,3 @@ | ||
```ts | ||
type onCLS = (callback: CLSReportCallback, opts?: ReportOpts) => void | ||
type onCLS = (callback: CLSReportCallback, opts?: ReportOpts) => void; | ||
``` | ||
@@ -864,3 +894,3 @@ | ||
```ts | ||
type onFCP = (callback: FCPReportCallback, opts?: ReportOpts) => void | ||
type onFCP = (callback: FCPReportCallback, opts?: ReportOpts) => void; | ||
``` | ||
@@ -873,3 +903,3 @@ | ||
```ts | ||
type onFID = (callback: FIDReportCallback, opts?: ReportOpts) => void | ||
type onFID = (callback: FIDReportCallback, opts?: ReportOpts) => void; | ||
``` | ||
@@ -884,6 +914,6 @@ | ||
```ts | ||
type onINP = (callback: INPReportCallback, opts?: ReportOpts) => void | ||
type onINP = (callback: INPReportCallback, opts?: ReportOpts) => void; | ||
``` | ||
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). | ||
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). | ||
@@ -899,3 +929,3 @@ 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). | ||
```ts | ||
type onLCP = (callback: LCPReportCallback, opts?: ReportOpts) => void | ||
type onLCP = (callback: LCPReportCallback, opts?: ReportOpts) => void; | ||
``` | ||
@@ -910,3 +940,3 @@ | ||
```ts | ||
type onTTFB = (callback: TTFBReportCallback, opts?: ReportOpts) => void | ||
type onTTFB = (callback: TTFBReportCallback, opts?: ReportOpts) => void; | ||
``` | ||
@@ -999,7 +1029,7 @@ | ||
*/ | ||
loadState: LoadState, | ||
loadState: LoadState; | ||
/** | ||
* The `PerformancePaintTiming` entry corresponding to FCP. | ||
*/ | ||
fcpEntry?: PerformancePaintTiming, | ||
fcpEntry?: PerformancePaintTiming; | ||
/** | ||
@@ -1035,3 +1065,3 @@ * The `navigation` entry of the current page, which is useful for diagnosing | ||
*/ | ||
eventEntry: PerformanceEventTiming | FirstInputPolyfillEntry, | ||
eventEntry: PerformanceEventTiming | FirstInputPolyfillEntry; | ||
/** | ||
@@ -1087,3 +1117,3 @@ * The loading state of the document at the time when the first interaction | ||
*/ | ||
element?: string, | ||
element?: string; | ||
/** | ||
@@ -1093,3 +1123,3 @@ * The URL (if applicable) of the LCP image resource. If the LCP element | ||
*/ | ||
url?: string, | ||
url?: string; | ||
/** | ||
@@ -1096,0 +1126,0 @@ * The time from when the user initiates loading the page until when the |
@@ -20,12 +20,17 @@ /* | ||
import {onCLS as unattributedOnCLS} from '../onCLS.js'; | ||
import {CLSReportCallback, CLSReportCallbackWithAttribution, CLSMetric, CLSMetricWithAttribution, ReportOpts} from '../types.js'; | ||
import { | ||
CLSReportCallback, | ||
CLSReportCallbackWithAttribution, | ||
CLSMetric, | ||
CLSMetricWithAttribution, | ||
ReportOpts, | ||
} from '../types.js'; | ||
const getLargestLayoutShiftEntry = (entries: LayoutShift[]) => { | ||
return entries.reduce((a, b) => a && a.value > b.value ? a : b); | ||
} | ||
return entries.reduce((a, b) => (a && a.value > b.value ? a : b)); | ||
}; | ||
const getLargestLayoutShiftSource = (sources: LayoutShiftAttribution[]) => { | ||
return sources.find((s) => s.node && s.node.nodeType === 1) || sources[0]; | ||
} | ||
}; | ||
@@ -52,3 +57,3 @@ const attributeCLS = (metric: CLSMetric): void => { | ||
(metric as CLSMetricWithAttribution).attribution = {}; | ||
} | ||
}; | ||
@@ -76,7 +81,13 @@ /** | ||
*/ | ||
export const onCLS = (onReport: CLSReportCallbackWithAttribution, opts?: ReportOpts) => { | ||
unattributedOnCLS(((metric: CLSMetric) => { | ||
attributeCLS(metric); | ||
onReport(metric); | ||
}) as CLSReportCallback, opts); | ||
export const onCLS = ( | ||
onReport: CLSReportCallbackWithAttribution, | ||
opts?: ReportOpts | ||
) => { | ||
unattributedOnCLS( | ||
((metric: CLSMetric) => { | ||
attributeCLS(metric); | ||
onReport(metric); | ||
}) as CLSReportCallback, | ||
opts | ||
); | ||
}; |
@@ -21,5 +21,10 @@ /* | ||
import {onFCP as unattributedOnFCP} from '../onFCP.js'; | ||
import {FCPMetric, FCPMetricWithAttribution, FCPReportCallback, FCPReportCallbackWithAttribution, ReportOpts} from '../types.js'; | ||
import { | ||
FCPMetric, | ||
FCPMetricWithAttribution, | ||
FCPReportCallback, | ||
FCPReportCallbackWithAttribution, | ||
ReportOpts, | ||
} from '../types.js'; | ||
const attributeFCP = (metric: FCPMetric): void => { | ||
@@ -58,7 +63,13 @@ if (metric.entries.length) { | ||
*/ | ||
export const onFCP = (onReport: FCPReportCallbackWithAttribution, opts?: ReportOpts) => { | ||
unattributedOnFCP(((metric: FCPMetricWithAttribution) => { | ||
attributeFCP(metric); | ||
onReport(metric); | ||
}) as FCPReportCallback, opts); | ||
export const onFCP = ( | ||
onReport: FCPReportCallbackWithAttribution, | ||
opts?: ReportOpts | ||
) => { | ||
unattributedOnFCP( | ||
((metric: FCPMetricWithAttribution) => { | ||
attributeFCP(metric); | ||
onReport(metric); | ||
}) as FCPReportCallback, | ||
opts | ||
); | ||
}; |
@@ -20,5 +20,10 @@ /* | ||
import {onFID as unattributedOnFID} from '../onFID.js'; | ||
import {FIDMetric, FIDMetricWithAttribution, FIDReportCallback, FIDReportCallbackWithAttribution, ReportOpts} from '../types.js'; | ||
import { | ||
FIDMetric, | ||
FIDMetricWithAttribution, | ||
FIDReportCallback, | ||
FIDReportCallbackWithAttribution, | ||
ReportOpts, | ||
} from '../types.js'; | ||
const attributeFID = (metric: FIDMetric): void => { | ||
@@ -44,7 +49,13 @@ const fidEntry = metric.entries[0]; | ||
*/ | ||
export const onFID = (onReport: FIDReportCallbackWithAttribution, opts?: ReportOpts) => { | ||
unattributedOnFID(((metric: FIDMetricWithAttribution) => { | ||
attributeFID(metric); | ||
onReport(metric); | ||
}) as FIDReportCallback, opts); | ||
export const onFID = ( | ||
onReport: FIDReportCallbackWithAttribution, | ||
opts?: ReportOpts | ||
) => { | ||
unattributedOnFID( | ||
((metric: FIDMetricWithAttribution) => { | ||
attributeFID(metric); | ||
onReport(metric); | ||
}) as FIDReportCallback, | ||
opts | ||
); | ||
}; |
@@ -20,5 +20,10 @@ /* | ||
import {onINP as unattributedOnINP} from '../onINP.js'; | ||
import {INPMetric, INPMetricWithAttribution, INPReportCallback, INPReportCallbackWithAttribution, ReportOpts} from '../types.js'; | ||
import { | ||
INPMetric, | ||
INPMetricWithAttribution, | ||
INPReportCallback, | ||
INPReportCallbackWithAttribution, | ||
ReportOpts, | ||
} from '../types.js'; | ||
const attributeINP = (metric: INPMetric): void => { | ||
@@ -28,4 +33,8 @@ if (metric.entries.length) { | ||
// Sort by: 1) duration (DESC), then 2) processing time (DESC) | ||
return b.duration - a.duration || (b.processingEnd - b.processingStart) - | ||
(a.processingEnd - a.processingStart); | ||
return ( | ||
b.duration - a.duration || | ||
b.processingEnd - | ||
b.processingStart - | ||
(a.processingEnd - a.processingStart) | ||
); | ||
})[0]; | ||
@@ -73,7 +82,13 @@ | ||
*/ | ||
export const onINP = (onReport: INPReportCallbackWithAttribution, opts?: ReportOpts) => { | ||
unattributedOnINP(((metric: INPMetricWithAttribution) => { | ||
attributeINP(metric); | ||
onReport(metric); | ||
}) as INPReportCallback, opts); | ||
export const onINP = ( | ||
onReport: INPReportCallbackWithAttribution, | ||
opts?: ReportOpts | ||
) => { | ||
unattributedOnINP( | ||
((metric: INPMetricWithAttribution) => { | ||
attributeINP(metric); | ||
onReport(metric); | ||
}) as INPReportCallback, | ||
opts | ||
); | ||
}; |
@@ -17,9 +17,14 @@ /* | ||
import {getNavigationEntry} from '../lib/getNavigationEntry.js'; | ||
import {getSelector} from '../lib/getSelector.js'; | ||
import {onLCP as unattributedOnLCP} from '../onLCP.js'; | ||
import {LCPAttribution, LCPMetric, LCPMetricWithAttribution, LCPReportCallback, LCPReportCallbackWithAttribution, ReportOpts} from '../types.js'; | ||
import { | ||
LCPAttribution, | ||
LCPMetric, | ||
LCPMetricWithAttribution, | ||
LCPReportCallback, | ||
LCPReportCallbackWithAttribution, | ||
ReportOpts, | ||
} from '../types.js'; | ||
const attributeLCP = (metric: LCPMetric) => { | ||
@@ -32,3 +37,5 @@ if (metric.entries.length) { | ||
const lcpEntry = metric.entries[metric.entries.length - 1]; | ||
const lcpResourceEntry = lcpEntry.url &&performance | ||
const lcpResourceEntry = | ||
lcpEntry.url && | ||
performance | ||
.getEntriesByType('resource') | ||
@@ -42,4 +49,6 @@ .filter((e) => e.name === lcpEntry.url)[0]; | ||
// Prefer `requestStart` (if TOA is set), otherwise use `startTime`. | ||
lcpResourceEntry ? (lcpResourceEntry.requestStart || | ||
lcpResourceEntry.startTime) - activationStart : 0 | ||
lcpResourceEntry | ||
? (lcpResourceEntry.requestStart || lcpResourceEntry.startTime) - | ||
activationStart | ||
: 0 | ||
); | ||
@@ -97,7 +106,13 @@ const lcpResponseEnd = Math.max( | ||
*/ | ||
export const onLCP = (onReport: LCPReportCallbackWithAttribution, opts?: ReportOpts) => { | ||
unattributedOnLCP(((metric: LCPMetricWithAttribution) => { | ||
attributeLCP(metric); | ||
onReport(metric); | ||
}) as LCPReportCallback, opts); | ||
export const onLCP = ( | ||
onReport: LCPReportCallbackWithAttribution, | ||
opts?: ReportOpts | ||
) => { | ||
unattributedOnLCP( | ||
((metric: LCPMetricWithAttribution) => { | ||
attributeLCP(metric); | ||
onReport(metric); | ||
}) as LCPReportCallback, | ||
opts | ||
); | ||
}; |
@@ -18,5 +18,10 @@ /* | ||
import {onTTFB as unattributedOnTTFB} from '../onTTFB.js'; | ||
import {TTFBMetric, TTFBMetricWithAttribution, TTFBReportCallback, TTFBReportCallbackWithAttribution, ReportOpts} from '../types.js'; | ||
import { | ||
TTFBMetric, | ||
TTFBMetricWithAttribution, | ||
TTFBReportCallback, | ||
TTFBReportCallbackWithAttribution, | ||
ReportOpts, | ||
} from '../types.js'; | ||
const attributeTTFB = (metric: TTFBMetric): void => { | ||
@@ -28,7 +33,13 @@ if (metric.entries.length) { | ||
const dnsStart = Math.max( | ||
navigationEntry.domainLookupStart - activationStart, 0); | ||
navigationEntry.domainLookupStart - activationStart, | ||
0 | ||
); | ||
const connectStart = Math.max( | ||
navigationEntry.connectStart - activationStart, 0); | ||
navigationEntry.connectStart - activationStart, | ||
0 | ||
); | ||
const requestStart = Math.max( | ||
navigationEntry.requestStart - activationStart, 0); | ||
navigationEntry.requestStart - activationStart, | ||
0 | ||
); | ||
@@ -68,7 +79,13 @@ (metric as TTFBMetricWithAttribution).attribution = { | ||
*/ | ||
export const onTTFB = (onReport: TTFBReportCallbackWithAttribution, opts?: ReportOpts) => { | ||
unattributedOnTTFB(((metric: TTFBMetricWithAttribution) => { | ||
attributeTTFB(metric); | ||
onReport(metric); | ||
}) as TTFBReportCallback, opts); | ||
export const onTTFB = ( | ||
onReport: TTFBReportCallbackWithAttribution, | ||
opts?: ReportOpts | ||
) => { | ||
unattributedOnTTFB( | ||
((metric: TTFBMetricWithAttribution) => { | ||
attributeTTFB(metric); | ||
onReport(metric); | ||
}) as TTFBReportCallback, | ||
opts | ||
); | ||
}; |
@@ -26,8 +26,12 @@ /* | ||
export const onBFCacheRestore = (cb: onBFCacheRestoreCallback) => { | ||
addEventListener('pageshow', (event) => { | ||
if (event.persisted) { | ||
bfcacheRestoreTime = event.timeStamp; | ||
cb(event); | ||
} | ||
}, true); | ||
addEventListener( | ||
'pageshow', | ||
(event) => { | ||
if (event.persisted) { | ||
bfcacheRestoreTime = event.timeStamp; | ||
cb(event); | ||
} | ||
}, | ||
true | ||
); | ||
}; |
@@ -19,3 +19,2 @@ /* | ||
const getRating = (value: number, thresholds: number[]) => { | ||
@@ -31,3 +30,2 @@ if (value > thresholds[1]) { | ||
export const bindReporter = ( | ||
@@ -37,3 +35,3 @@ callback: ReportCallback, | ||
thresholds: number[], | ||
reportAllChanges?: boolean, | ||
reportAllChanges?: boolean | ||
) => { | ||
@@ -59,3 +57,3 @@ let prevValue: number; | ||
} | ||
} | ||
} | ||
}; | ||
}; |
@@ -19,6 +19,5 @@ /* | ||
export const getActivationStart = (): number => { | ||
const navEntry = getNavigationEntry(); | ||
return navEntry && navEntry.activationStart || 0; | ||
return (navEntry && navEntry.activationStart) || 0; | ||
}; |
@@ -20,3 +20,2 @@ /* | ||
export const getLoadState = (timestamp: number): LoadState => { | ||
@@ -30,12 +29,15 @@ if (document.readyState === 'loading') { | ||
if (navigationEntry) { | ||
if (timestamp < navigationEntry.domInteractive) { | ||
return 'loading'; | ||
} else if (navigationEntry.domContentLoadedEventStart === 0 || | ||
timestamp < navigationEntry.domContentLoadedEventStart) { | ||
} else if ( | ||
navigationEntry.domContentLoadedEventStart === 0 || | ||
timestamp < navigationEntry.domContentLoadedEventStart | ||
) { | ||
// If the `domContentLoadedEventStart` timestamp has not yet been | ||
// set, or if the given timestamp is less than that value. | ||
return 'dom-interactive'; | ||
} else if (navigationEntry.domComplete === 0 || | ||
timestamp < navigationEntry.domComplete) { | ||
} else if ( | ||
navigationEntry.domComplete === 0 || | ||
timestamp < navigationEntry.domComplete | ||
) { | ||
// If the `domComplete` timestamp has not yet been | ||
@@ -51,2 +53,2 @@ // set, or if the given timestamp is less than that value. | ||
return 'complete'; | ||
} | ||
}; |
@@ -19,32 +19,43 @@ /* | ||
const getNavigationEntryFromPerformanceTiming = | ||
(): NavigationTimingPolyfillEntry => { | ||
const timing = performance.timing; | ||
const type = performance.navigation.type; | ||
const getNavigationEntryFromPerformanceTiming = (): NavigationTimingPolyfillEntry => { | ||
const timing = performance.timing; | ||
const type = performance.navigation.type; | ||
const navigationEntry: {[key: string]: number | string} = { | ||
entryType: 'navigation', | ||
startTime: 0, | ||
type: type == 2 ? 'back_forward' : type === 1 ? 'reload' : 'navigate', | ||
}; | ||
const navigationEntry: {[key: string]: number | string} = { | ||
entryType: 'navigation', | ||
startTime: 0, | ||
type: type == 2 ? 'back_forward' : (type === 1 ? 'reload' : 'navigate'), | ||
}; | ||
for (const key in timing) { | ||
if (key !== 'navigationStart' && key !== 'toJSON') { | ||
navigationEntry[key] = Math.max( | ||
for (const key in timing) { | ||
if (key !== 'navigationStart' && key !== 'toJSON') { | ||
navigationEntry[key] = Math.max( | ||
(timing[key as keyof PerformanceTiming] as number) - | ||
timing.navigationStart, 0); | ||
timing.navigationStart, | ||
0 | ||
); | ||
} | ||
} | ||
} | ||
return navigationEntry as unknown as NavigationTimingPolyfillEntry; | ||
}; | ||
return navigationEntry as unknown as NavigationTimingPolyfillEntry; | ||
}; | ||
export const getNavigationEntry = (): PerformanceNavigationTiming | NavigationTimingPolyfillEntry | undefined => { | ||
export const getNavigationEntry = (): | ||
| PerformanceNavigationTiming | ||
| NavigationTimingPolyfillEntry | ||
| undefined => { | ||
if (window.__WEB_VITALS_POLYFILL__) { | ||
return window.performance && (performance.getEntriesByType && | ||
performance.getEntriesByType('navigation')[0] || | ||
getNavigationEntryFromPerformanceTiming()); | ||
return ( | ||
window.performance && | ||
((performance.getEntriesByType && | ||
performance.getEntriesByType('navigation')[0]) || | ||
getNavigationEntryFromPerformanceTiming()) | ||
); | ||
} else { | ||
return window.performance && (performance.getEntriesByType && | ||
performance.getEntriesByType('navigation')[0]); | ||
return ( | ||
window.performance && | ||
performance.getEntriesByType && | ||
performance.getEntriesByType('navigation')[0] | ||
); | ||
} | ||
}; |
@@ -1,2 +0,1 @@ | ||
/* | ||
@@ -20,5 +19,6 @@ * Copyright 2022 Google LLC | ||
const name = node.nodeName; | ||
return node.nodeType === 1 ? | ||
name.toLowerCase() : name.toUpperCase().replace(/^#/, ''); | ||
} | ||
return node.nodeType === 1 | ||
? name.toLowerCase() | ||
: name.toUpperCase().replace(/^#/, ''); | ||
}; | ||
@@ -30,6 +30,9 @@ export const getSelector = (node: Node | null | undefined, maxLen?: number) => { | ||
while (node && node.nodeType !== 9) { | ||
const el: Element = (node as Element); | ||
const part = el.id ? '#' + el.id : getName(el) + ( | ||
(el.className && el.className.length) ? | ||
'.' + el.className.replace(/\s+/g, '.') : ''); | ||
const el: Element = node as Element; | ||
const part = el.id | ||
? '#' + el.id | ||
: getName(el) + | ||
(el.className && el.className.length | ||
? '.' + el.className.replace(/\s+/g, '.') | ||
: ''); | ||
if (sel.length + part.length > (maxLen || 100) - 1) return sel || part; | ||
@@ -36,0 +39,0 @@ sel = sel ? part + '>' + sel : part; |
@@ -19,3 +19,2 @@ /* | ||
let firstHiddenTime = -1; | ||
@@ -29,5 +28,6 @@ | ||
// event logic below). | ||
return document.visibilityState === 'hidden' && | ||
!document.prerendering ? 0 : Infinity; | ||
} | ||
return document.visibilityState === 'hidden' && !document.prerendering | ||
? 0 | ||
: Infinity; | ||
}; | ||
@@ -50,3 +50,3 @@ const onVisibilityUpdate = (event: Event) => { | ||
} | ||
} | ||
}; | ||
@@ -67,3 +67,2 @@ const addChangeListeners = () => { | ||
export const getVisibilityWatcher = () => { | ||
@@ -99,4 +98,4 @@ if (firstHiddenTime < 0) { | ||
return firstHiddenTime; | ||
} | ||
} | ||
}, | ||
}; | ||
}; |
@@ -23,3 +23,2 @@ /* | ||
export const initMetric = (name: Metric['name'], value?: number): Metric => { | ||
@@ -37,4 +36,6 @@ const navEntry = getNavigationEntry(); | ||
} else { | ||
navigationType = | ||
navEntry.type.replace(/_/g, '-') as Metric['navigationType']; | ||
navigationType = navEntry.type.replace( | ||
/_/g, | ||
'-' | ||
) as Metric['navigationType']; | ||
} | ||
@@ -41,0 +42,0 @@ } |
@@ -17,5 +17,7 @@ /* | ||
import {FirstInputPolyfillEntry, NavigationTimingPolyfillEntry} from '../types.js'; | ||
import { | ||
FirstInputPolyfillEntry, | ||
NavigationTimingPolyfillEntry, | ||
} from '../types.js'; | ||
interface PerformanceEntryMap { | ||
@@ -42,3 +44,3 @@ 'event': PerformanceEventTiming[]; | ||
callback: (entries: PerformanceEntryMap[K]) => void, | ||
opts?: PerformanceObserverInit, | ||
opts?: PerformanceObserverInit | ||
): PerformanceObserver | undefined => { | ||
@@ -55,6 +57,11 @@ try { | ||
}); | ||
po.observe(Object.assign({ | ||
type, | ||
buffered: true, | ||
}, opts || {}) as PerformanceObserverInit); | ||
po.observe( | ||
Object.assign( | ||
{ | ||
type, | ||
buffered: true, | ||
}, | ||
opts || {} | ||
) as PerformanceObserverInit | ||
); | ||
return po; | ||
@@ -61,0 +68,0 @@ } |
@@ -17,3 +17,2 @@ /* | ||
export interface OnHiddenCallback { | ||
@@ -23,13 +22,8 @@ (event: Event): void; | ||
export const onHidden = (cb: OnHiddenCallback, once?: boolean) => { | ||
export const onHidden = (cb: OnHiddenCallback) => { | ||
const onHiddenOrPageHide = (event: Event) => { | ||
if (event.type === 'pagehide' || document.visibilityState === 'hidden') { | ||
cb(event); | ||
if (once) { | ||
removeEventListener('visibilitychange', onHiddenOrPageHide, true); | ||
removeEventListener('pagehide', onHiddenOrPageHide, true); | ||
} | ||
} | ||
} | ||
}; | ||
addEventListener('visibilitychange', onHiddenOrPageHide, true); | ||
@@ -36,0 +30,0 @@ // Some browsers have buggy implementations of visibilitychange, |
@@ -17,12 +17,15 @@ /* | ||
import {FirstInputPolyfillEntry, FirstInputPolyfillCallback} from '../../types.js'; | ||
import { | ||
FirstInputPolyfillEntry, | ||
FirstInputPolyfillCallback, | ||
} from '../../types.js'; | ||
type addOrRemoveEventListener = | ||
typeof addEventListener | typeof removeEventListener; | ||
| typeof addEventListener | ||
| typeof removeEventListener; | ||
let firstInputEvent: Event|null; | ||
let firstInputEvent: Event | null; | ||
let firstInputDelay: number; | ||
let firstInputTimeStamp: Date; | ||
let callbacks: FirstInputPolyfillCallback[] | ||
let callbacks: FirstInputPolyfillCallback[]; | ||
@@ -41,3 +44,3 @@ const listenerOpts: AddEventListenerOptions = {passive: true, capture: true}; | ||
reportFirstInputDelayIfRecordedAndValid(); | ||
} | ||
}; | ||
@@ -49,3 +52,3 @@ export const resetFirstInputPolyfill = () => { | ||
eachEventType(addEventListener); | ||
} | ||
}; | ||
@@ -60,3 +63,3 @@ /** | ||
firstInputDelay = delay; | ||
firstInputTimeStamp = new Date; | ||
firstInputTimeStamp = new Date(); | ||
@@ -66,3 +69,3 @@ eachEventType(removeEventListener); | ||
} | ||
} | ||
}; | ||
@@ -79,5 +82,7 @@ /** | ||
// - https://github.com/GoogleChromeLabs/first-input-delay/issues/7 | ||
if (firstInputDelay >= 0 && | ||
// @ts-ignore (subtracting two dates always returns a number) | ||
firstInputDelay < firstInputTimeStamp - startTimeStamp) { | ||
if ( | ||
firstInputDelay >= 0 && | ||
// @ts-ignore (subtracting two dates always returns a number) | ||
firstInputDelay < firstInputTimeStamp - startTimeStamp | ||
) { | ||
const entry = { | ||
@@ -91,3 +96,3 @@ entryType: 'first-input', | ||
} as FirstInputPolyfillEntry; | ||
callbacks.forEach(function(callback) { | ||
callbacks.forEach(function (callback) { | ||
callback(entry); | ||
@@ -97,3 +102,3 @@ }); | ||
} | ||
} | ||
}; | ||
@@ -117,3 +122,3 @@ /** | ||
removePointerEventListeners(); | ||
} | ||
}; | ||
@@ -127,3 +132,3 @@ /** | ||
removePointerEventListeners(); | ||
} | ||
}; | ||
@@ -136,7 +141,7 @@ /** | ||
removeEventListener('pointercancel', onPointerCancel, listenerOpts); | ||
} | ||
}; | ||
addEventListener('pointerup', onPointerUp, listenerOpts); | ||
addEventListener('pointercancel', onPointerCancel, listenerOpts); | ||
} | ||
}; | ||
@@ -159,7 +164,7 @@ /** | ||
const isEpochTime = event.timeStamp > 1e12; | ||
const now = isEpochTime ? new Date : performance.now(); | ||
const now = isEpochTime ? new Date() : performance.now(); | ||
// Input delay is the delta between when the system received the event | ||
// (e.g. event.timeStamp) and when it could run the callback (e.g. `now`). | ||
const delay = now as number - event.timeStamp; | ||
const delay = (now as number) - event.timeStamp; | ||
@@ -172,3 +177,3 @@ if (event.type == 'pointerdown') { | ||
} | ||
} | ||
}; | ||
@@ -180,9 +185,4 @@ /** | ||
const eachEventType = (callback: addOrRemoveEventListener) => { | ||
const eventTypes = [ | ||
'mousedown', | ||
'keydown', | ||
'touchstart', | ||
'pointerdown', | ||
]; | ||
const eventTypes = ['mousedown', 'keydown', 'touchstart', 'pointerdown']; | ||
eventTypes.forEach((type) => callback(type, onInput, listenerOpts)); | ||
} | ||
}; |
@@ -17,4 +17,3 @@ /* | ||
let firstHiddenTime = | ||
document.visibilityState === 'hidden' ? 0 : Infinity; | ||
let firstHiddenTime = document.visibilityState === 'hidden' ? 0 : Infinity; | ||
@@ -26,3 +25,3 @@ const onVisibilityChange = (event: Event) => { | ||
} | ||
} | ||
}; | ||
@@ -29,0 +28,0 @@ // Note: do not add event listeners unconditionally (outside of polyfills). |
@@ -20,3 +20,2 @@ /* | ||
declare global { | ||
@@ -38,7 +37,8 @@ interface Performance { | ||
interactionCountEstimate = maxKnownInteractionId ? | ||
(maxKnownInteractionId - minKnownInteractionId) / 7 + 1 : 0; | ||
interactionCountEstimate = maxKnownInteractionId | ||
? (maxKnownInteractionId - minKnownInteractionId) / 7 + 1 | ||
: 0; | ||
} | ||
}); | ||
} | ||
}; | ||
@@ -53,3 +53,3 @@ let po: PerformanceObserver | undefined; | ||
return po ? interactionCountEstimate : performance.interactionCount || 0; | ||
} | ||
}; | ||
@@ -56,0 +56,0 @@ /** |
@@ -17,3 +17,2 @@ /* | ||
export const whenActivated = (callback: () => void) => { | ||
@@ -25,2 +24,2 @@ if (document.prerendering) { | ||
} | ||
} | ||
}; |
148
src/onCLS.ts
@@ -20,10 +20,9 @@ /* | ||
import {observe} from './lib/observe.js'; | ||
import {onHidden} from './lib/onHidden.js'; | ||
import {bindReporter} from './lib/bindReporter.js'; | ||
import {doubleRAF} from './lib/doubleRAF.js'; | ||
import {whenActivated} from './lib/whenActivated.js'; | ||
import {onHidden} from './lib/onHidden.js'; | ||
import {runOnce} from './lib/runOnce.js'; | ||
import {onFCP} from './onFCP.js'; | ||
import {CLSMetric, CLSReportCallback, ReportOpts} from './types.js'; | ||
/** | ||
@@ -54,87 +53,86 @@ * Calculates the [CLS](https://web.dev/cls/) value for the current page and | ||
whenActivated(() => { | ||
// https://web.dev/cls/#what-is-a-good-cls-score | ||
const thresholds = [0.1, 0.25]; | ||
// Start monitoring FCP so we can only report CLS if FCP is also reported. | ||
// Note: this is done to match the current behavior of CrUX. | ||
onFCP( | ||
runOnce(() => { | ||
// https://web.dev/cls/#what-is-a-good-cls-score | ||
const thresholds = [0.1, 0.25]; | ||
let metric = initMetric('CLS'); | ||
let report: ReturnType<typeof bindReporter>; | ||
let metric = initMetric('CLS', 0); | ||
let report: ReturnType<typeof bindReporter>; | ||
let fcpValue = -1; | ||
let sessionValue = 0; | ||
let sessionEntries: PerformanceEntry[] = []; | ||
let sessionValue = 0; | ||
let sessionEntries: PerformanceEntry[] = []; | ||
const onReportWrapped: CLSReportCallback = (arg) => { | ||
if (fcpValue > -1) { | ||
onReport(arg); | ||
} | ||
}; | ||
// const handleEntries = (entries: Metric['entries']) => { | ||
const handleEntries = (entries: LayoutShift[]) => { | ||
entries.forEach((entry) => { | ||
// Only count layout shifts without recent user input. | ||
if (!entry.hadRecentInput) { | ||
const firstSessionEntry = sessionEntries[0]; | ||
const lastSessionEntry = sessionEntries[sessionEntries.length - 1]; | ||
// const handleEntries = (entries: Metric['entries']) => { | ||
const handleEntries = (entries: LayoutShift[]) => { | ||
entries.forEach((entry) => { | ||
// Only count layout shifts without recent user input. | ||
if (!entry.hadRecentInput) { | ||
const firstSessionEntry = sessionEntries[0]; | ||
const lastSessionEntry = sessionEntries[sessionEntries.length - 1]; | ||
// If the entry occurred less than 1 second after the previous entry | ||
// and less than 5 seconds after the first entry in the session, | ||
// include the entry in the current session. Otherwise, start a new | ||
// session. | ||
if (sessionValue && | ||
// If the entry occurred less than 1 second after the previous entry | ||
// and less than 5 seconds after the first entry in the session, | ||
// include the entry in the current session. Otherwise, start a new | ||
// session. | ||
if ( | ||
sessionValue && | ||
entry.startTime - lastSessionEntry.startTime < 1000 && | ||
entry.startTime - firstSessionEntry.startTime < 5000) { | ||
sessionValue += entry.value; | ||
sessionEntries.push(entry); | ||
} else { | ||
sessionValue = entry.value; | ||
sessionEntries = [entry]; | ||
entry.startTime - firstSessionEntry.startTime < 5000 | ||
) { | ||
sessionValue += entry.value; | ||
sessionEntries.push(entry); | ||
} else { | ||
sessionValue = entry.value; | ||
sessionEntries = [entry]; | ||
} | ||
} | ||
}); | ||
// If the current session value is larger than the current CLS value, | ||
// update CLS and the entries contributing to it. | ||
if (sessionValue > metric.value) { | ||
metric.value = sessionValue; | ||
metric.entries = sessionEntries; | ||
report(); | ||
} | ||
// If the current session value is larger than the current CLS value, | ||
// update CLS and the entries contributing to it. | ||
if (sessionValue > metric.value) { | ||
metric.value = sessionValue; | ||
metric.entries = sessionEntries; | ||
report(); | ||
} | ||
}); | ||
}; | ||
}; | ||
const po = observe('layout-shift', handleEntries); | ||
if (po) { | ||
report = bindReporter( | ||
onReportWrapped, metric, thresholds, opts!.reportAllChanges); | ||
const po = observe('layout-shift', handleEntries); | ||
if (po) { | ||
report = bindReporter( | ||
onReport, | ||
metric, | ||
thresholds, | ||
opts!.reportAllChanges | ||
); | ||
// Start monitoring FCP so we can only report CLS if FCP is also reported. | ||
// Note: this is done to match the current behavior of CrUX. | ||
// Also, if there have not been any layout shifts when FCP is dispatched, | ||
// call "report" with a zero value | ||
onFCP((fcpMetric) => { | ||
fcpValue = fcpMetric.value; | ||
if (metric.value < 0) { | ||
metric.value = 0; | ||
report(); | ||
} | ||
}); | ||
onHidden(() => { | ||
handleEntries(po.takeRecords() as CLSMetric['entries']); | ||
report(true); | ||
}); | ||
onHidden(() => { | ||
handleEntries(po.takeRecords() as CLSMetric['entries']); | ||
report(true); | ||
}); | ||
// Only report after a bfcache restore if the `PerformanceObserver` | ||
// successfully registered. | ||
onBFCacheRestore(() => { | ||
sessionValue = 0; | ||
metric = initMetric('CLS', 0); | ||
report = bindReporter( | ||
onReport, | ||
metric, | ||
thresholds, | ||
opts!.reportAllChanges | ||
); | ||
// Only report after a bfcache restore if the `PerformanceObserver` | ||
// successfully registered. | ||
onBFCacheRestore(() => { | ||
sessionValue = 0; | ||
fcpValue = -1; | ||
metric = initMetric('CLS', 0); | ||
report = bindReporter( | ||
onReportWrapped, metric, thresholds, opts!.reportAllChanges); | ||
doubleRAF(() => report()); | ||
}); | ||
doubleRAF(() => report()); | ||
}); | ||
} | ||
}); | ||
// Queue a task to report (if nothing else triggers a report first). | ||
// This allows CLS to be reported as soon as FCP fires when | ||
// `reportAllChanges` is true. | ||
setTimeout(report, 0); | ||
} | ||
}) | ||
); | ||
}; |
@@ -68,3 +68,7 @@ /* | ||
report = bindReporter( | ||
onReport, metric, thresholds, opts!.reportAllChanges); | ||
onReport, | ||
metric, | ||
thresholds, | ||
opts!.reportAllChanges | ||
); | ||
@@ -76,3 +80,7 @@ // Only report after a bfcache restore if the `PerformanceObserver` | ||
report = bindReporter( | ||
onReport, metric, thresholds, opts!.reportAllChanges); | ||
onReport, | ||
metric, | ||
thresholds, | ||
opts!.reportAllChanges | ||
); | ||
@@ -79,0 +87,0 @@ doubleRAF(() => { |
@@ -23,5 +23,14 @@ /* | ||
import {onHidden} from './lib/onHidden.js'; | ||
import {firstInputPolyfill, resetFirstInputPolyfill} from './lib/polyfills/firstInputPolyfill.js'; | ||
import { | ||
firstInputPolyfill, | ||
resetFirstInputPolyfill, | ||
} from './lib/polyfills/firstInputPolyfill.js'; | ||
import {runOnce} from './lib/runOnce.js'; | ||
import {whenActivated} from './lib/whenActivated.js'; | ||
import {FIDMetric, FirstInputPolyfillCallback, ReportCallback, ReportOpts} from './types.js'; | ||
import { | ||
FIDMetric, | ||
FirstInputPolyfillCallback, | ||
ReportCallback, | ||
ReportOpts, | ||
} from './types.js'; | ||
@@ -56,7 +65,7 @@ /** | ||
} | ||
} | ||
}; | ||
const handleEntries = (entries: FIDMetric['entries']) => { | ||
(entries as PerformanceEventTiming[]).forEach(handleEntry); | ||
} | ||
}; | ||
@@ -67,14 +76,20 @@ const po = observe('first-input', handleEntries); | ||
if (po) { | ||
onHidden(() => { | ||
handleEntries(po.takeRecords() as FIDMetric['entries']); | ||
po.disconnect(); | ||
}, true); | ||
onHidden( | ||
runOnce(() => { | ||
handleEntries(po.takeRecords() as FIDMetric['entries']); | ||
po.disconnect(); | ||
}) | ||
); | ||
} | ||
if (window.__WEB_VITALS_POLYFILL__) { | ||
console.warn('The web-vitals "base+polyfill" build is deprecated. See: https://bit.ly/3aqzsGm'); | ||
console.warn( | ||
'The web-vitals "base+polyfill" build is deprecated. See: https://bit.ly/3aqzsGm' | ||
); | ||
// Prefer the native implementation if available, | ||
if (!po) { | ||
window.webVitals.firstInputPolyfill(handleEntry as FirstInputPolyfillCallback) | ||
window.webVitals.firstInputPolyfill( | ||
handleEntry as FirstInputPolyfillCallback | ||
); | ||
} | ||
@@ -84,6 +99,12 @@ onBFCacheRestore(() => { | ||
report = bindReporter( | ||
onReport, metric, thresholds, opts!.reportAllChanges); | ||
onReport, | ||
metric, | ||
thresholds, | ||
opts!.reportAllChanges | ||
); | ||
window.webVitals.resetFirstInputPolyfill(); | ||
window.webVitals.firstInputPolyfill(handleEntry as FirstInputPolyfillCallback); | ||
window.webVitals.firstInputPolyfill( | ||
handleEntry as FirstInputPolyfillCallback | ||
); | ||
}); | ||
@@ -96,3 +117,7 @@ } else { | ||
report = bindReporter( | ||
onReport, metric, thresholds, opts!.reportAllChanges); | ||
onReport, | ||
metric, | ||
thresholds, | ||
opts!.reportAllChanges | ||
); | ||
@@ -99,0 +124,0 @@ resetFirstInputPolyfill(); |
@@ -22,3 +22,6 @@ /* | ||
import {onHidden} from './lib/onHidden.js'; | ||
import {getInteractionCount, initInteractionCountPolyfill} from './lib/polyfills/interactionCountPolyfill.js'; | ||
import { | ||
getInteractionCount, | ||
initInteractionCountPolyfill, | ||
} from './lib/polyfills/interactionCountPolyfill.js'; | ||
import {whenActivated} from './lib/whenActivated.js'; | ||
@@ -43,3 +46,3 @@ import {INPMetric, ReportCallback, ReportOpts} from './types.js'; | ||
return getInteractionCount() - prevInteractionCount; | ||
} | ||
}; | ||
@@ -67,3 +70,3 @@ // To prevent unnecessary memory usage on pages with lots of interactions, | ||
const minLongestInteraction = | ||
longestInteractionList[longestInteractionList.length - 1] | ||
longestInteractionList[longestInteractionList.length - 1]; | ||
@@ -74,10 +77,14 @@ const existingInteraction = longestInteractionMap[entry.interactionId!]; | ||
// or if it's part of an existing interaction. | ||
if (existingInteraction || | ||
longestInteractionList.length < MAX_INTERACTIONS_TO_CONSIDER || | ||
entry.duration > minLongestInteraction.latency) { | ||
if ( | ||
existingInteraction || | ||
longestInteractionList.length < MAX_INTERACTIONS_TO_CONSIDER || | ||
entry.duration > minLongestInteraction.latency | ||
) { | ||
// If the interaction already exists, update it. Otherwise create one. | ||
if (existingInteraction) { | ||
existingInteraction.entries.push(entry); | ||
existingInteraction.latency = | ||
Math.max(existingInteraction.latency, entry.duration); | ||
existingInteraction.latency = Math.max( | ||
existingInteraction.latency, | ||
entry.duration | ||
); | ||
} else { | ||
@@ -88,3 +95,3 @@ const interaction = { | ||
entries: [entry], | ||
} | ||
}; | ||
longestInteractionMap[interaction.id] = interaction; | ||
@@ -100,3 +107,3 @@ longestInteractionList.push(interaction); | ||
} | ||
} | ||
}; | ||
@@ -108,7 +115,9 @@ /** | ||
const estimateP98LongestInteraction = () => { | ||
const candidateInteractionIndex = Math.min(longestInteractionList.length - 1, | ||
Math.floor(getInteractionCountForNavigation() / 50)); | ||
const candidateInteractionIndex = Math.min( | ||
longestInteractionList.length - 1, | ||
Math.floor(getInteractionCountForNavigation() / 50) | ||
); | ||
return longestInteractionList[candidateInteractionIndex]; | ||
} | ||
return longestInteractionList[candidateInteractionIndex]; | ||
}; | ||
@@ -171,8 +180,12 @@ /** | ||
if (entry.entryType === 'first-input') { | ||
const noMatchingEntry = !longestInteractionList.some((interaction) => { | ||
return interaction.entries.some((prevEntry) => { | ||
return entry.duration === prevEntry.duration && | ||
entry.startTime === prevEntry.startTime; | ||
}); | ||
}); | ||
const noMatchingEntry = !longestInteractionList.some( | ||
(interaction) => { | ||
return interaction.entries.some((prevEntry) => { | ||
return ( | ||
entry.duration === prevEntry.duration && | ||
entry.startTime === prevEntry.startTime | ||
); | ||
}); | ||
} | ||
); | ||
if (noMatchingEntry) { | ||
@@ -233,3 +246,7 @@ processEntry(entry); | ||
report = bindReporter( | ||
onReport, metric, thresholds, opts!.reportAllChanges); | ||
onReport, | ||
metric, | ||
thresholds, | ||
opts!.reportAllChanges | ||
); | ||
}); | ||
@@ -236,0 +253,0 @@ } |
@@ -25,6 +25,6 @@ /* | ||
import {onHidden} from './lib/onHidden.js'; | ||
import {runOnce} from './lib/runOnce.js'; | ||
import {whenActivated} from './lib/whenActivated.js'; | ||
import {LCPMetric, ReportCallback, ReportOpts} from './types.js'; | ||
const reportedMetricIDs: Record<string, boolean> = {}; | ||
@@ -56,3 +56,3 @@ | ||
const handleEntries = (entries: LCPMetric['entries']) => { | ||
const lastEntry = (entries[entries.length - 1] as LargestContentfulPaint); | ||
const lastEntry = entries[entries.length - 1] as LargestContentfulPaint; | ||
if (lastEntry) { | ||
@@ -80,5 +80,9 @@ // The startTime attribute returns the value of the renderTime if it is | ||
report = bindReporter( | ||
onReport, metric, thresholds, opts!.reportAllChanges); | ||
onReport, | ||
metric, | ||
thresholds, | ||
opts!.reportAllChanges | ||
); | ||
const stopListening = () => { | ||
const stopListening = runOnce(() => { | ||
if (!reportedMetricIDs[metric.id]) { | ||
@@ -90,3 +94,3 @@ handleEntries(po!.takeRecords() as LCPMetric['entries']); | ||
} | ||
} | ||
}); | ||
@@ -97,6 +101,6 @@ // Stop listening after input. Note: while scrolling is an input that | ||
['keydown', 'click'].forEach((type) => { | ||
addEventListener(type, stopListening, {once: true, capture: true}); | ||
addEventListener(type, stopListening, true); | ||
}); | ||
onHidden(stopListening, true); | ||
onHidden(stopListening); | ||
@@ -108,3 +112,7 @@ // Only report after a bfcache restore if the `PerformanceObserver` | ||
report = bindReporter( | ||
onReport, metric, thresholds, opts!.reportAllChanges); | ||
onReport, | ||
metric, | ||
thresholds, | ||
opts!.reportAllChanges | ||
); | ||
@@ -111,0 +119,0 @@ doubleRAF(() => { |
@@ -25,3 +25,2 @@ /* | ||
/** | ||
@@ -40,3 +39,3 @@ * Runs in the next task after the page is done loading and/or prerendering. | ||
} | ||
} | ||
}; | ||
@@ -67,3 +66,7 @@ /** | ||
let report = bindReporter( | ||
onReport, metric, thresholds, opts.reportAllChanges); | ||
onReport, | ||
metric, | ||
thresholds, | ||
opts.reportAllChanges | ||
); | ||
@@ -98,3 +101,7 @@ whenReady(() => { | ||
report = bindReporter( | ||
onReport, metric, thresholds, opts!.reportAllChanges); | ||
onReport, | ||
metric, | ||
thresholds, | ||
opts!.reportAllChanges | ||
); | ||
@@ -101,0 +108,0 @@ report(true); |
@@ -17,3 +17,6 @@ /* | ||
import {firstInputPolyfill, resetFirstInputPolyfill} from './lib/polyfills/firstInputPolyfill.js'; | ||
import { | ||
firstInputPolyfill, | ||
resetFirstInputPolyfill, | ||
} from './lib/polyfills/firstInputPolyfill.js'; | ||
import {getFirstHiddenTime} from './lib/polyfills/getFirstHiddenTimePolyfill.js'; | ||
@@ -20,0 +23,0 @@ |
@@ -29,3 +29,2 @@ /* | ||
// -------------------------------------------------------------------------- | ||
@@ -55,5 +54,5 @@ // Web Vitals package globals | ||
interface PerformanceEntryMap { | ||
'navigation': PerformanceNavigationTiming; | ||
'resource': PerformanceResourceTiming; | ||
'paint': PerformancePaintTiming; | ||
navigation: PerformanceNavigationTiming; | ||
resource: PerformanceResourceTiming; | ||
paint: PerformancePaintTiming; | ||
} | ||
@@ -71,3 +70,5 @@ | ||
interface Performance { | ||
getEntriesByType<K extends keyof PerformanceEntryMap>(type: K): PerformanceEntryMap[K][] | ||
getEntriesByType<K extends keyof PerformanceEntryMap>( | ||
type: K | ||
): PerformanceEntryMap[K][]; | ||
} | ||
@@ -74,0 +75,0 @@ |
@@ -17,5 +17,7 @@ /* | ||
import {FirstInputPolyfillEntry, NavigationTimingPolyfillEntry} from './polyfills.js'; | ||
import { | ||
FirstInputPolyfillEntry, | ||
NavigationTimingPolyfillEntry, | ||
} from './polyfills.js'; | ||
export interface Metric { | ||
@@ -60,3 +62,8 @@ /** | ||
*/ | ||
entries: (PerformanceEntry | LayoutShift | FirstInputPolyfillEntry | NavigationTimingPolyfillEntry)[]; | ||
entries: ( | ||
| PerformanceEntry | ||
| LayoutShift | ||
| FirstInputPolyfillEntry | ||
| NavigationTimingPolyfillEntry | ||
)[]; | ||
@@ -74,3 +81,9 @@ /** | ||
*/ | ||
navigationType: 'navigate' | 'reload' | 'back-forward' | 'back-forward-cache' | 'prerender' | 'restore'; | ||
navigationType: | ||
| 'navigate' | ||
| 'reload' | ||
| 'back-forward' | ||
| 'back-forward-cache' | ||
| 'prerender' | ||
| 'restore'; | ||
} | ||
@@ -114,2 +127,6 @@ | ||
*/ | ||
export type LoadState = 'loading' | 'dom-interactive' | 'dom-content-loaded' | 'complete'; | ||
export type LoadState = | ||
| 'loading' | ||
| 'dom-interactive' | ||
| 'dom-content-loaded' | ||
| 'complete'; |
@@ -19,3 +19,2 @@ /* | ||
/** | ||
@@ -34,3 +33,3 @@ * A CLS-specific version of the Metric object. | ||
*/ | ||
export interface CLSAttribution { | ||
export interface CLSAttribution { | ||
/** | ||
@@ -37,0 +36,0 @@ * A selector identifying the first element (in document order) that |
@@ -20,3 +20,2 @@ /* | ||
/** | ||
@@ -35,3 +34,3 @@ * An FCP-specific version of the Metric object. | ||
*/ | ||
export interface FCPAttribution { | ||
export interface FCPAttribution { | ||
/** | ||
@@ -51,7 +50,7 @@ * The time from when the user initiates loading the page until when the | ||
*/ | ||
loadState: LoadState, | ||
loadState: LoadState; | ||
/** | ||
* The `PerformancePaintTiming` entry corresponding to FCP. | ||
*/ | ||
fcpEntry?: PerformancePaintTiming, | ||
fcpEntry?: PerformancePaintTiming; | ||
/** | ||
@@ -58,0 +57,0 @@ * The `navigation` entry of the current page, which is useful for diagnosing |
@@ -20,3 +20,2 @@ /* | ||
/** | ||
@@ -54,3 +53,3 @@ * An FID-specific version of the Metric object. | ||
*/ | ||
eventEntry: PerformanceEventTiming | FirstInputPolyfillEntry, | ||
eventEntry: PerformanceEventTiming | FirstInputPolyfillEntry; | ||
/** | ||
@@ -57,0 +56,0 @@ * The loading state of the document at the time when the first interaction |
@@ -19,3 +19,2 @@ /* | ||
/** | ||
@@ -22,0 +21,0 @@ * An INP-specific version of the Metric object. |
@@ -20,3 +20,2 @@ /* | ||
/** | ||
@@ -39,3 +38,3 @@ * An LCP-specific version of the Metric object. | ||
*/ | ||
element?: string, | ||
element?: string; | ||
/** | ||
@@ -45,3 +44,3 @@ * The URL (if applicable) of the LCP image resource. If the LCP element | ||
*/ | ||
url?: string, | ||
url?: string; | ||
/** | ||
@@ -48,0 +47,0 @@ * The time from when the user initiates loading the page until when the |
@@ -17,3 +17,6 @@ /* | ||
export type FirstInputPolyfillEntry = Omit<PerformanceEventTiming, 'processingEnd'>; | ||
export type FirstInputPolyfillEntry = Omit< | ||
PerformanceEventTiming, | ||
'processingEnd' | ||
>; | ||
@@ -24,6 +27,13 @@ export interface FirstInputPolyfillCallback { | ||
export type NavigationTimingPolyfillEntry = Omit<PerformanceNavigationTiming, | ||
'initiatorType' | 'nextHopProtocol' | 'redirectCount' | 'transferSize' | | ||
'encodedBodySize' | 'decodedBodySize' | 'type'> & { | ||
export type NavigationTimingPolyfillEntry = Omit< | ||
PerformanceNavigationTiming, | ||
| 'initiatorType' | ||
| 'nextHopProtocol' | ||
| 'redirectCount' | ||
| 'transferSize' | ||
| 'encodedBodySize' | ||
| 'decodedBodySize' | ||
| 'type' | ||
> & { | ||
type: PerformanceNavigationTiming['type']; | ||
} | ||
}; |
@@ -20,3 +20,2 @@ /* | ||
/** | ||
@@ -35,3 +34,3 @@ * A TTFB-specific version of the Metric object. | ||
*/ | ||
export interface TTFBAttribution { | ||
export interface TTFBAttribution { | ||
/** | ||
@@ -38,0 +37,0 @@ * The total time from when the user initiates loading the page to when the |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
374726
143
6164
1243
26
1