UNPKG

next

Version:

The React Framework

1 lines • 9.68 kB
(function(){"use strict";var t={};!function(){t.d=function(r,c){for(var I in c){if(t.o(c,I)&&!t.o(r,I)){Object.defineProperty(r,I,{enumerable:true,get:c[I]})}}}}();!function(){t.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)}}();!function(){t.r=function(t){if(typeof Symbol!=="undefined"&&Symbol.toStringTag){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}Object.defineProperty(t,"__esModule",{value:true})}}();if(typeof t!=="undefined")t.ab=__dirname+"/";var r={};t.r(r);t.d(r,{CLSThresholds:function(){return k},FCPThresholds:function(){return E},INPThresholds:function(){return j},LCPThresholds:function(){return W},TTFBThresholds:function(){return z},onCLS:function(){return P},onFCP:function(){return M},onINP:function(){return x},onLCP:function(){return U},onTTFB:function(){return D}});let c=-1;const n=()=>c,e=t=>{addEventListener("pageshow",(r=>{r.persisted&&(c=r.timeStamp,t(r))}),!0)},i=(t,r,c,I)=>{let L,w;return E=>{r.value>=0&&(E||I)&&(w=r.value-(L??0),(w||void 0===L)&&(L=r.value,r.delta=w,r.rating=((t,r)=>t>r[1]?"poor":t>r[0]?"needs-improvement":"good")(r.value,c),t(r)))}},o=t=>{requestAnimationFrame((()=>requestAnimationFrame((()=>t()))))},s=()=>{const t=performance.getEntriesByType("navigation")[0];if(t&&t.responseStart>0&&t.responseStart<performance.now())return t},a=()=>s()?.activationStart??0;let I=-1;const L=new Set,f=()=>"hidden"!==document.visibilityState||document.prerendering?1/0:0,h=t=>{if("hidden"===document.visibilityState){if("visibilitychange"===t.type)for(const t of L)t();isFinite(I)||(I="visibilitychange"===t.type?t.timeStamp:0,removeEventListener("prerenderingchange",h,!0))}},d=(t=!1)=>{if(t&&(I=1/0),I<0){const t=a(),r=document.prerendering?void 0:globalThis.performance.getEntriesByType("visibility-state").find((r=>"hidden"===r.name&&r.startTime>=t))?.startTime;I=r??f(),addEventListener("visibilitychange",h,!0),addEventListener("prerenderingchange",h,!0),e((()=>{setTimeout((()=>{I=f()}))}))}return{get firstHiddenTime(){return I},onHidden(t){L.add(t)}}},l=(t,r=-1,c,I=0,L,w,E)=>{const k=s(),A=k?.navigationId||0;let F="navigate";c?F=c:n()>=0?F="back-forward-cache":k&&(document.prerendering||a()>0?F="prerender":document.wasDiscarded?F="restore":k.type&&(F=k.type.replace(/_/g,"-")));return{name:t,value:r,rating:"good",delta:0,entries:[],id:`v6-${Date.now()}-${Math.floor(8999999999999*Math.random())+1e12}`,navigationType:F,navigationId:I||A,navigationInteractionId:L,navigationURL:w||k?.name,navigationStartTime:E||0}},w=new WeakMap;function u(t,r){let c=w.get(r);return c||(c=new WeakMap,w.set(r,c)),c.get(t)||c.set(t,new r),c.get(t)}class v{t;i=0;o=[];h(t){if(t.hadRecentInput)return;const r=this.o[0],c=this.o.at(-1);this.i&&r&&c&&t.startTime-c.startTime<1e3&&t.startTime-r.startTime<5e3?(this.i+=t.value,this.o.push(t)):(this.i=t.value,this.o=[t]),this.t?.(t)}}const m=(t,r,c={})=>{try{const I=t.filter((t=>PerformanceObserver.supportedEntryTypes.includes(t)));if(I.length>0){const t=new PerformanceObserver((t=>{queueMicrotask((()=>{const c=t.getEntries();I.length>1&&c.sort(((t,r)=>t.startTime+t.duration-(r.startTime+r.duration))),r(c)}))}));for(const r of I)t.observe({type:r,buffered:!0,...c});return t}}catch{}},p=t=>globalThis.PerformanceObserver?.supportedEntryTypes?.includes("soft-navigation")&&"function"==typeof globalThis.PerformanceSoftNavigation?.prototype?.getLargestInteractionContentfulPaint&&t&&t.reportSoftNavs,b=(t,r)=>{if(t.set(r.navigationId,r),t.size>2){const r=t.keys().next().value;void 0!==r&&t.delete(r)}},T=t=>{let r=!1;return()=>{r||(t(),r=!0)}};class y{l}const _=t=>{document.prerendering?addEventListener("prerenderingchange",t,!0):t()},E=[1800,3e3],M=(t,r={})=>{const c=p(r);_((()=>{const I=u(r,y),L=d();let w,k=l("FCP");const A=m(["paint"],(t=>{for(const r of t)"first-contentful-paint"===r.name&&(A.disconnect(),r.startTime<L.firstHiddenTime&&(k.value=Math.max(r.startTime-a(),0),k.entries.push(r),k.navigationId=r.navigationId||k.navigationId,w(!0)))}));if(A&&(w=i(t,k,E,r.reportAllChanges),e((c=>{k=l("FCP",-1,"back-forward-cache",k.navigationId,k.navigationInteractionId,k.navigationURL,n()),w=i(t,k,E,r.reportAllChanges),o((()=>{k.value=performance.now()-c.timeStamp,w(!0)}))}))),c){m(["soft-navigation"],(c=>{c.forEach((c=>{I.l&&c.navigationId&&b(I.l,c);const L=Math.max((c.presentationTime||c.paintTime||0)-c.startTime,0);k=l("FCP",L,"soft-navigation",c.navigationId,c.interactionId,c.name,c.startTime),w=i(t,k,E,r.reportAllChanges),w(!0)}))}),r)}}))},k=[.1,.25],P=(t,r={})=>{const c=d();M(T((()=>{let I,L=l("CLS",0);const w=u(r,v),h=(c,E,A,F,R)=>{L=l("CLS",0,c,E,A,F,R),w.i=0,I=i(t,L,k,r.reportAllChanges)},d=(t=!1)=>{w.i>L.value&&(L.value=w.i,L.entries=w.o),I(t)},g=t=>{d(!0),h("soft-navigation",t.navigationId,t.interactionId,t.name,t.startTime)},b=t=>{for(const r of t)"soft-navigation"!==r.entryType?w.h(r):g(r);d()},E=["layout-shift"];p(r)&&E.push("soft-navigation");const A=m(E,b);A&&(I=i(t,L,k,r.reportAllChanges),c.onHidden((()=>{b(A.takeRecords()),I(!0)})),e((()=>{h("back-forward-cache",L.navigationId,L.navigationInteractionId,L.navigationURL,n()),o(I)})),setTimeout(I))})))};let A=0,F=1/0,R=0;const C=t=>{for(const r of t)r.interactionId&&(F=Math.min(F,r.interactionId),R=Math.max(R,r.interactionId),A=R?(R-F)/7+1:0)};let O;const N=()=>O?A:performance.interactionCount??0,B=()=>{"interactionCount"in performance||O||(O=m(["event"],C,{durationThreshold:0}))};class S{u=0;v=[];m=new Map;p;T;_(){return N()-this.u}M(){this.u=N(),this.v.length=0,this.m.clear()}L(t){const r=this._(),c=Math.min(this.v.length-1,Math.floor(r/50));return!r||-1!==c||"soft-navigation"!==t&&"back-forward-cache"!==t?this.v[c]:{P:8,id:-1,entries:[]}}h(t){if(this.p?.(t),!t.interactionId)return;const r=this.v.at(-1);let c=this.m.get(t.interactionId);if(c||this.v.length<10||t.duration>r.P){if(c?t.duration>c.P?(c.entries=[t],c.P=t.duration):t.duration===c.P&&t.startTime===c.entries[0].startTime&&c.entries.push(t):(c={id:t.interactionId,entries:[t],P:t.duration},this.m.set(c.id,c),this.v.push(c)),this.v.sort(((t,r)=>r.P-t.P)),this.v.length>10){const t=this.v.splice(10);for(const r of t)this.m.delete(r.id)}this.T?.(c)}}}const q=t=>{const r="requestIdleCallback"in globalThis?1e3:0,c=globalThis.requestIdleCallback||setTimeout,I=globalThis.cancelIdleCallback||clearTimeout;if("hidden"===document.visibilityState)t();else{const L=T(t);let w=-1;const a=()=>{I(w),L()};addEventListener("visibilitychange",a,{once:!0,capture:!0}),w=c((()=>{removeEventListener("visibilitychange",a,{capture:!0}),L()}),{timeout:r})}},j=[200,500],x=(t,r={})=>{if(!globalThis.PerformanceEventTiming||!("interactionId"in PerformanceEventTiming.prototype))return;const c=d();_((()=>{B();let I,L=l("INP");const w=u(r,S),f=(c,E,k,A,F)=>{w.M(),L=l("INP",-1,c,E,k,A,F),I=i(t,L,j,r.reportAllChanges)},h=()=>{const t=w.L(L.navigationType);t&&t.P!==L.value&&(L.value=t.P,L.entries=t.entries,I())},d=t=>{h(),I(!0),f("soft-navigation",t.navigationId,t.interactionId,t.name,t.startTime)},g=(t,r=!1)=>{q((()=>{for(const r of t)"soft-navigation"!==r.entryType?w.h(r):d(r);h(),r&&I(!0)}))},E=["event","first-input"];p(r)&&E.push("soft-navigation");const k=m(E,g,{...r,durationThreshold:r.durationThreshold??40});I=i(t,L,j,r.reportAllChanges),k&&(c.onHidden((()=>{g(k.takeRecords(),!0)})),e((()=>{f("back-forward-cache",L.navigationId,L.navigationInteractionId,L.navigationURL,n())})))}))};class H{p;l;h(t){this.p?.(t)}}const W=[2500,4e3],U=(t,r={})=>{let c=!1;const I=p(r);_((()=>{let L,w=d(),E=l("LCP");const k=u(r,H),p=(I,k,A,F,R)=>{E=l("LCP",-1,I,k,A,F,R),L=i(t,E,W,r.reportAllChanges),c=!1,"soft-navigation"===I&&(w=d(!0))},T=t=>{k.l&&t.navigationId&&b(k.l,t),c||L(!0),p("soft-navigation",t.navigationId,t.interactionId,t.name,t.startTime);const r=t.getLargestInteractionContentfulPaint?.();r&&y([r])},y=t=>{r.reportAllChanges||I||(t=t.slice(-1));for(const r of t){if(!r)continue;if("soft-navigation"===r.entryType){T(r);continue}let t=0,c=[],I=r.startTime;if("largest-contentful-paint"===r.entryType)t=Math.max(r.startTime-a(),0),k.h(r),c=[r];else if("interaction-contentful-paint"===r.entryType){const L=r;if(!E.navigationId)continue;if("interactionId"in L&&L.interactionId!=E.navigationInteractionId)continue;I=L.largestContentfulPaint?.renderTime||0,t=Math.max(I-r.startTime,0),L.largestContentfulPaint&&(k.h(L.largestContentfulPaint),c=[L.largestContentfulPaint])}I<w.firstHiddenTime&&(E.value=t,E.entries=c,L())}},A=["largest-contentful-paint"];I&&A.push("interaction-contentful-paint","soft-navigation");const F=m(A,y);if(F){L=i(t,E,W,r.reportAllChanges);const w=["keydown","click","visibilitychange"],h=t=>{if(t.isTrusted&&!c){const t=E.id;q((()=>{if(!c){if(!I){F.disconnect();for(const t of w)removeEventListener(t,h,{capture:!0})}t===E.id&&(c=!0,L(!0))}}))}};for(const t of w)addEventListener(t,h,{capture:!0});e((I=>{p("back-forward-cache",E.navigationId,E.navigationInteractionId,E.navigationURL,n()),L=i(t,E,W,r.reportAllChanges),o((()=>{E.value=performance.now()-I.timeStamp,c=!0,L(!0)}))}))}}))},z=[800,1800],$=t=>{document.prerendering?_((()=>$(t))):"complete"!==document.readyState?addEventListener("load",(()=>$(t)),!0):setTimeout(t)},D=(t,r={})=>{const c=p(r);let I=l("TTFB"),L=i(t,I,z,r.reportAllChanges);$((()=>{const w=s();if(w){const E=w.responseStart;if(I.value=Math.max(E-a(),0),I.entries=[w],L(!0),e((()=>{I=l("TTFB",0,"back-forward-cache",I.navigationId,I.navigationInteractionId,I.navigationURL,n()),L=i(t,I,z,r.reportAllChanges),L(!0)})),c){m(["soft-navigation"],(c=>{c.forEach((c=>{c.navigationId&&(I=l("TTFB",0,"soft-navigation",c.navigationId,c.interactionId,c.name,c.startTime),I.entries=[c],L=i(t,I,z,r.reportAllChanges),L(!0))}))}),r)}}}))};module.exports=r})();