1 | /*
|
2 | * Copyright 2020 Google LLC
|
3 | *
|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | * you may not use this file except in compliance with the License.
|
6 | * You may obtain a copy of the License at
|
7 | *
|
8 | * https://www.apache.org/licenses/LICENSE-2.0
|
9 | *
|
10 | * Unless required by applicable law or agreed to in writing, software
|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 | * See the License for the specific language governing permissions and
|
14 | * limitations under the License.
|
15 | */
|
16 |
|
17 | import {FirstInputPolyfillCallback} from './types/polyfills.js';
|
18 |
|
19 | export * from './types/base.js';
|
20 | export * from './types/polyfills.js';
|
21 |
|
22 | export * from './types/cls.js';
|
23 | export * from './types/fcp.js';
|
24 | export * from './types/fid.js';
|
25 | export * from './types/inp.js';
|
26 | export * from './types/lcp.js';
|
27 | export * from './types/ttfb.js';
|
28 |
|
29 | // --------------------------------------------------------------------------
|
30 | // Web Vitals package globals
|
31 | // --------------------------------------------------------------------------
|
32 |
|
33 | export interface WebVitalsGlobal {
|
34 | firstInputPolyfill: (onFirstInput: FirstInputPolyfillCallback) => void;
|
35 | resetFirstInputPolyfill: () => void;
|
36 | firstHiddenTime: number;
|
37 | }
|
38 |
|
39 | declare global {
|
40 | interface Window {
|
41 | webVitals: WebVitalsGlobal;
|
42 |
|
43 | // Build flags:
|
44 | __WEB_VITALS_POLYFILL__: boolean;
|
45 | }
|
46 | }
|
47 |
|
48 | // --------------------------------------------------------------------------
|
49 | // Everything below is modifications to built-in modules.
|
50 | // --------------------------------------------------------------------------
|
51 |
|
52 | interface PerformanceEntryMap {
|
53 | navigation: PerformanceNavigationTiming;
|
54 | resource: PerformanceResourceTiming;
|
55 | paint: PerformancePaintTiming;
|
56 | }
|
57 |
|
58 | // Update built-in types to be more accurate.
|
59 | declare global {
|
60 | interface Document {
|
61 | // https://wicg.github.io/nav-speculation/prerendering.html#document-prerendering
|
62 | prerendering?: boolean;
|
63 | // https://wicg.github.io/page-lifecycle/#sec-api
|
64 | wasDiscarded?: boolean;
|
65 | }
|
66 |
|
67 | interface Performance {
|
68 | getEntriesByType<K extends keyof PerformanceEntryMap>(
|
69 | type: K
|
70 | ): PerformanceEntryMap[K][];
|
71 | }
|
72 |
|
73 | // https://w3c.github.io/event-timing/#sec-modifications-perf-timeline
|
74 | interface PerformanceObserverInit {
|
75 | durationThreshold?: number;
|
76 | }
|
77 |
|
78 | // https://wicg.github.io/nav-speculation/prerendering.html#performance-navigation-timing-extension
|
79 | interface PerformanceNavigationTiming {
|
80 | activationStart?: number;
|
81 | }
|
82 |
|
83 | // https://wicg.github.io/event-timing/#sec-performance-event-timing
|
84 | interface PerformanceEventTiming extends PerformanceEntry {
|
85 | duration: DOMHighResTimeStamp;
|
86 | interactionId?: number;
|
87 | }
|
88 |
|
89 | // https://wicg.github.io/layout-instability/#sec-layout-shift-attribution
|
90 | interface LayoutShiftAttribution {
|
91 | node?: Node;
|
92 | previousRect: DOMRectReadOnly;
|
93 | currentRect: DOMRectReadOnly;
|
94 | }
|
95 |
|
96 | // https://wicg.github.io/layout-instability/#sec-layout-shift
|
97 | interface LayoutShift extends PerformanceEntry {
|
98 | value: number;
|
99 | sources: LayoutShiftAttribution[];
|
100 | hadRecentInput: boolean;
|
101 | }
|
102 |
|
103 | // https://w3c.github.io/largest-contentful-paint/#sec-largest-contentful-paint-interface
|
104 | interface LargestContentfulPaint extends PerformanceEntry {
|
105 | renderTime: DOMHighResTimeStamp;
|
106 | loadTime: DOMHighResTimeStamp;
|
107 | size: number;
|
108 | id: string;
|
109 | url: string;
|
110 | element?: Element;
|
111 | }
|
112 | }
|