inpspy 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/LICENSE +21 -0
- package/README.md +264 -2
- package/dist/index.cjs +980 -0
- package/dist/index.d.cts +198 -0
- package/dist/index.d.ts +198 -0
- package/dist/index.js +941 -0
- package/dist/react.cjs +56 -0
- package/dist/react.d.cts +14 -0
- package/dist/react.d.ts +14 -0
- package/dist/react.js +31 -0
- package/package.json +99 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/** Google's INP rating: good ≤ 200 ms, needs improvement ≤ 500 ms, poor above. */
|
|
2
|
+
type Rating = "good" | "needs-improvement" | "poor";
|
|
3
|
+
type Position = "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
4
|
+
/** Where the time of one interaction went. The three phases add up to `duration`. */
|
|
5
|
+
interface Phases {
|
|
6
|
+
/** From the input (click, tap, key press) until its first event handler started. Long when the main thread was busy with other work. */
|
|
7
|
+
inputDelay: number;
|
|
8
|
+
/** Time spent running the event handlers (pointerdown, pointerup, click, keydown, …) for this interaction. */
|
|
9
|
+
processing: number;
|
|
10
|
+
/** From the end of the handlers until the next frame was painted: style, layout, paint. */
|
|
11
|
+
presentationDelay: number;
|
|
12
|
+
}
|
|
13
|
+
/** A script that ran during the interaction, from the Long Animation Frames API. */
|
|
14
|
+
interface InpScript {
|
|
15
|
+
/** Script URL (`sourceURL`), or `""` when the browser doesn't report one. */
|
|
16
|
+
url: string;
|
|
17
|
+
/** Function name (`sourceFunctionName`), or `""`. */
|
|
18
|
+
functionName: string;
|
|
19
|
+
/** What called the script, e.g. `BUTTON#buy.onclick`, `TimerHandler:setTimeout`. */
|
|
20
|
+
invoker: string;
|
|
21
|
+
/** `event-listener`, `user-callback`, `classic-script`, `module-script`, `resolve-promise`, `reject-promise`. */
|
|
22
|
+
invokerType: string;
|
|
23
|
+
/** Time the script ran, in ms. */
|
|
24
|
+
duration: number;
|
|
25
|
+
/** Time spent in forced (synchronous) style and layout inside the script, in ms. */
|
|
26
|
+
forcedStyleAndLayoutDuration: number;
|
|
27
|
+
/** Script start, in ms since navigation start (same clock as `InpInteraction.startTime`). */
|
|
28
|
+
startTime: number;
|
|
29
|
+
/** The script comes from a different origin than the page. */
|
|
30
|
+
thirdParty: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* How scripts were attributed:
|
|
34
|
+
* - `loaf`: Long Animation Frames entries were found for the interaction (`scripts` may still be empty
|
|
35
|
+
* when no single script ran 5 ms or more, e.g. the time went into rendering);
|
|
36
|
+
* - `none`: the API is supported but no long animation frame (50 ms or more) overlapped the interaction;
|
|
37
|
+
* - `unsupported`: the browser has no Long Animation Frames API (needs Chromium 123+).
|
|
38
|
+
*/
|
|
39
|
+
type Attribution = "loaf" | "none" | "unsupported";
|
|
40
|
+
/** One user interaction (a click, tap or key press), measured with the Event Timing API. */
|
|
41
|
+
interface InpInteraction {
|
|
42
|
+
/** The browser's `interactionId`. */
|
|
43
|
+
id: number;
|
|
44
|
+
/** `pointer` for clicks and taps, `keyboard` for key presses. */
|
|
45
|
+
type: "pointer" | "keyboard";
|
|
46
|
+
/** The event types seen for this interaction, e.g. `["pointerdown", "pointerup", "click"]`. */
|
|
47
|
+
events: string[];
|
|
48
|
+
/** Input time, in ms since navigation start (`performance.now()` clock). */
|
|
49
|
+
startTime: number;
|
|
50
|
+
/** Time from the input until the next paint, in ms. This is the number INP is made of. */
|
|
51
|
+
duration: number;
|
|
52
|
+
rating: Rating;
|
|
53
|
+
phases: Phases;
|
|
54
|
+
/** A readable CSS selector for the target element, e.g. `button#buy.btn`, or `(removed element)`. */
|
|
55
|
+
target: string;
|
|
56
|
+
/** A short text hint for the target (its label or text), or `""`. */
|
|
57
|
+
targetText: string;
|
|
58
|
+
/** Scripts that ran during the interaction, longest first. */
|
|
59
|
+
scripts: InpScript[];
|
|
60
|
+
attribution: Attribution;
|
|
61
|
+
/** Page URL when the interaction happened. */
|
|
62
|
+
url: string;
|
|
63
|
+
}
|
|
64
|
+
interface InpSpyOptions {
|
|
65
|
+
/** Interactions at or above this duration (ms) show a toast and a console report. Default `200`. */
|
|
66
|
+
threshold?: number;
|
|
67
|
+
/** Event Timing `durationThreshold` (ms): shorter interactions are not recorded at all. Default `40`, minimum `16`. */
|
|
68
|
+
durationThreshold?: number;
|
|
69
|
+
/** Show the on-page overlay. Default `true`. */
|
|
70
|
+
overlay?: boolean;
|
|
71
|
+
/** Log a grouped console report for each slow interaction. Default `true`. */
|
|
72
|
+
console?: boolean;
|
|
73
|
+
/** How many interactions the panel and `getInteractions()` keep. Default `50`. */
|
|
74
|
+
maxEntries?: number;
|
|
75
|
+
/** Overlay corner. Default `"bottom-right"`. */
|
|
76
|
+
position?: Position;
|
|
77
|
+
/** How long a toast stays, in ms. `0` keeps toasts until closed. Default `8000`. */
|
|
78
|
+
toastDuration?: number;
|
|
79
|
+
/** Called for every recorded interaction (at or above `durationThreshold`), slow or not. */
|
|
80
|
+
onInteraction?: (interaction: InpInteraction) => void;
|
|
81
|
+
}
|
|
82
|
+
type ReportFormat = "markdown" | "json";
|
|
83
|
+
|
|
84
|
+
/** Which of the browser APIs inpspy uses are available here. Both `false` on the server. */
|
|
85
|
+
declare function getSupport(): {
|
|
86
|
+
eventTiming: boolean;
|
|
87
|
+
longAnimationFrames: boolean;
|
|
88
|
+
};
|
|
89
|
+
/** The page's interactions recorded since `start()` (oldest first, at most `maxEntries`). */
|
|
90
|
+
declare function getInteractions(): InpInteraction[];
|
|
91
|
+
/** The recorded interactions as a Markdown report (default) or JSON. */
|
|
92
|
+
declare function getReport(format?: ReportFormat): string;
|
|
93
|
+
/** Forgets all recorded interactions (and removes toasts). Keeps observing. */
|
|
94
|
+
declare function clear(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Starts measuring interactions: shows the overlay, logs slow interactions to the console and calls
|
|
97
|
+
* `onInteraction`. Returns `stop()`. Calling `start()` again replaces the running session.
|
|
98
|
+
* On the server (no `window`) it does nothing and returns a no-op.
|
|
99
|
+
*/
|
|
100
|
+
declare function start(options?: InpSpyOptions): () => void;
|
|
101
|
+
/** True while a session started by `start()` is running. */
|
|
102
|
+
declare function isRunning(): boolean;
|
|
103
|
+
|
|
104
|
+
/** The subset of a `PerformanceEventTiming` entry inpspy reads. */
|
|
105
|
+
interface EventEntryLike {
|
|
106
|
+
name: string;
|
|
107
|
+
startTime: number;
|
|
108
|
+
duration: number;
|
|
109
|
+
processingStart: number;
|
|
110
|
+
processingEnd: number;
|
|
111
|
+
interactionId: number;
|
|
112
|
+
}
|
|
113
|
+
/** The subset of a `PerformanceScriptTiming` (Long Animation Frames) inpspy reads. */
|
|
114
|
+
interface ScriptTimingLike {
|
|
115
|
+
startTime: number;
|
|
116
|
+
duration: number;
|
|
117
|
+
sourceURL?: string;
|
|
118
|
+
sourceFunctionName?: string;
|
|
119
|
+
invoker?: string;
|
|
120
|
+
invokerType?: string;
|
|
121
|
+
forcedStyleAndLayoutDuration?: number;
|
|
122
|
+
}
|
|
123
|
+
/** The subset of a `PerformanceLongAnimationFrameTiming` entry inpspy reads. */
|
|
124
|
+
interface LoafLike {
|
|
125
|
+
startTime: number;
|
|
126
|
+
duration: number;
|
|
127
|
+
scripts?: readonly ScriptTimingLike[];
|
|
128
|
+
}
|
|
129
|
+
/** Google's thresholds: good ≤ 200 ms, needs improvement ≤ 500 ms, poor above. */
|
|
130
|
+
declare function rate(duration: number): Rating;
|
|
131
|
+
interface Summary<T extends EventEntryLike> {
|
|
132
|
+
/** The longest entry. */
|
|
133
|
+
main: T;
|
|
134
|
+
startTime: number;
|
|
135
|
+
duration: number;
|
|
136
|
+
phases: Phases;
|
|
137
|
+
/** Entries that were presented in the same frame as the longest one (their handlers count as processing). */
|
|
138
|
+
frame: T[];
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Splits one interaction into input delay, processing and presentation delay.
|
|
142
|
+
*
|
|
143
|
+
* The interaction's duration is the longest entry's. Processing runs from the first handler to the last
|
|
144
|
+
* handler among the entries painted in the same frame (pointerdown, pointerup and click of one tap usually
|
|
145
|
+
* share a frame), so a slow click handler counts as processing, not as presentation of the pointerdown.
|
|
146
|
+
* The phases always add up to `duration`. Event Timing rounds durations to 8 ms, which is why entries
|
|
147
|
+
* within 8 ms of the same end time count as one frame.
|
|
148
|
+
*/
|
|
149
|
+
declare function summarize<T extends EventEntryLike>(entries: readonly T[]): Summary<T> | undefined;
|
|
150
|
+
/**
|
|
151
|
+
* The page INP estimate, as web-vitals computes it: the longest interaction, or with 50 or more
|
|
152
|
+
* interactions roughly the 98th percentile (one interaction is skipped for every 50).
|
|
153
|
+
*
|
|
154
|
+
* @param longest durations of the longest recorded interactions (any order; the 10 longest are enough)
|
|
155
|
+
* @param interactionCount how many interactions the page had in total
|
|
156
|
+
* @returns the estimate in ms, or `null` when nothing was recorded
|
|
157
|
+
*/
|
|
158
|
+
declare function estimateInp(longest: readonly number[], interactionCount: number): number | null;
|
|
159
|
+
/** True when `url` is on a different origin than the page. Empty URLs are not third-party. */
|
|
160
|
+
declare function isThirdParty(url: string, pageOrigin: string): boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Finds the Long Animation Frames that overlap an interaction ([start, end]) and lists the scripts that
|
|
163
|
+
* ran during it, longest first. Scripts from an overlapping frame that ran entirely before or after the
|
|
164
|
+
* interaction are left out.
|
|
165
|
+
*/
|
|
166
|
+
declare function attributeScripts(start: number, end: number, loafs: readonly LoafLike[], pageOrigin: string): {
|
|
167
|
+
attribution: Exclude<Attribution, "unsupported">;
|
|
168
|
+
scripts: InpScript[];
|
|
169
|
+
};
|
|
170
|
+
/** The subset of an `Element` the selector builder reads. */
|
|
171
|
+
interface ElementLike {
|
|
172
|
+
tagName: string;
|
|
173
|
+
id?: string;
|
|
174
|
+
getAttribute?(name: string): string | null;
|
|
175
|
+
textContent?: string | null;
|
|
176
|
+
parentElement?: ElementLike | null;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* A readable selector for an interaction target: `tag#id`, or `tag.class[data-testid]` prefixed with the
|
|
180
|
+
* closest ancestor that has an id (`#product button.add`). `(removed element)` for a null target.
|
|
181
|
+
*/
|
|
182
|
+
declare function describeElement(el: ElementLike | null | undefined): {
|
|
183
|
+
selector: string;
|
|
184
|
+
text: string;
|
|
185
|
+
};
|
|
186
|
+
interface ReportContext {
|
|
187
|
+
url: string;
|
|
188
|
+
/** Page INP estimate in ms, or null when nothing was recorded. */
|
|
189
|
+
inp: number | null;
|
|
190
|
+
/** Interactions on the page so far. */
|
|
191
|
+
interactionCount: number;
|
|
192
|
+
durationThreshold: number;
|
|
193
|
+
loafSupported: boolean;
|
|
194
|
+
}
|
|
195
|
+
/** Renders recorded interactions as Markdown (for an issue or PR) or JSON. */
|
|
196
|
+
declare function formatReport(interactions: readonly InpInteraction[], context: ReportContext, format?: ReportFormat): string;
|
|
197
|
+
|
|
198
|
+
export { type Attribution, type ElementLike, type EventEntryLike, type InpInteraction, type InpScript, type InpSpyOptions, type LoafLike, type Phases, type Position, type Rating, type ReportContext, type ReportFormat, type ScriptTimingLike, attributeScripts, clear, describeElement, estimateInp, formatReport, getInteractions, getReport, getSupport, isRunning, isThirdParty, rate, start, summarize };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/** Google's INP rating: good ≤ 200 ms, needs improvement ≤ 500 ms, poor above. */
|
|
2
|
+
type Rating = "good" | "needs-improvement" | "poor";
|
|
3
|
+
type Position = "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
4
|
+
/** Where the time of one interaction went. The three phases add up to `duration`. */
|
|
5
|
+
interface Phases {
|
|
6
|
+
/** From the input (click, tap, key press) until its first event handler started. Long when the main thread was busy with other work. */
|
|
7
|
+
inputDelay: number;
|
|
8
|
+
/** Time spent running the event handlers (pointerdown, pointerup, click, keydown, …) for this interaction. */
|
|
9
|
+
processing: number;
|
|
10
|
+
/** From the end of the handlers until the next frame was painted: style, layout, paint. */
|
|
11
|
+
presentationDelay: number;
|
|
12
|
+
}
|
|
13
|
+
/** A script that ran during the interaction, from the Long Animation Frames API. */
|
|
14
|
+
interface InpScript {
|
|
15
|
+
/** Script URL (`sourceURL`), or `""` when the browser doesn't report one. */
|
|
16
|
+
url: string;
|
|
17
|
+
/** Function name (`sourceFunctionName`), or `""`. */
|
|
18
|
+
functionName: string;
|
|
19
|
+
/** What called the script, e.g. `BUTTON#buy.onclick`, `TimerHandler:setTimeout`. */
|
|
20
|
+
invoker: string;
|
|
21
|
+
/** `event-listener`, `user-callback`, `classic-script`, `module-script`, `resolve-promise`, `reject-promise`. */
|
|
22
|
+
invokerType: string;
|
|
23
|
+
/** Time the script ran, in ms. */
|
|
24
|
+
duration: number;
|
|
25
|
+
/** Time spent in forced (synchronous) style and layout inside the script, in ms. */
|
|
26
|
+
forcedStyleAndLayoutDuration: number;
|
|
27
|
+
/** Script start, in ms since navigation start (same clock as `InpInteraction.startTime`). */
|
|
28
|
+
startTime: number;
|
|
29
|
+
/** The script comes from a different origin than the page. */
|
|
30
|
+
thirdParty: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* How scripts were attributed:
|
|
34
|
+
* - `loaf`: Long Animation Frames entries were found for the interaction (`scripts` may still be empty
|
|
35
|
+
* when no single script ran 5 ms or more, e.g. the time went into rendering);
|
|
36
|
+
* - `none`: the API is supported but no long animation frame (50 ms or more) overlapped the interaction;
|
|
37
|
+
* - `unsupported`: the browser has no Long Animation Frames API (needs Chromium 123+).
|
|
38
|
+
*/
|
|
39
|
+
type Attribution = "loaf" | "none" | "unsupported";
|
|
40
|
+
/** One user interaction (a click, tap or key press), measured with the Event Timing API. */
|
|
41
|
+
interface InpInteraction {
|
|
42
|
+
/** The browser's `interactionId`. */
|
|
43
|
+
id: number;
|
|
44
|
+
/** `pointer` for clicks and taps, `keyboard` for key presses. */
|
|
45
|
+
type: "pointer" | "keyboard";
|
|
46
|
+
/** The event types seen for this interaction, e.g. `["pointerdown", "pointerup", "click"]`. */
|
|
47
|
+
events: string[];
|
|
48
|
+
/** Input time, in ms since navigation start (`performance.now()` clock). */
|
|
49
|
+
startTime: number;
|
|
50
|
+
/** Time from the input until the next paint, in ms. This is the number INP is made of. */
|
|
51
|
+
duration: number;
|
|
52
|
+
rating: Rating;
|
|
53
|
+
phases: Phases;
|
|
54
|
+
/** A readable CSS selector for the target element, e.g. `button#buy.btn`, or `(removed element)`. */
|
|
55
|
+
target: string;
|
|
56
|
+
/** A short text hint for the target (its label or text), or `""`. */
|
|
57
|
+
targetText: string;
|
|
58
|
+
/** Scripts that ran during the interaction, longest first. */
|
|
59
|
+
scripts: InpScript[];
|
|
60
|
+
attribution: Attribution;
|
|
61
|
+
/** Page URL when the interaction happened. */
|
|
62
|
+
url: string;
|
|
63
|
+
}
|
|
64
|
+
interface InpSpyOptions {
|
|
65
|
+
/** Interactions at or above this duration (ms) show a toast and a console report. Default `200`. */
|
|
66
|
+
threshold?: number;
|
|
67
|
+
/** Event Timing `durationThreshold` (ms): shorter interactions are not recorded at all. Default `40`, minimum `16`. */
|
|
68
|
+
durationThreshold?: number;
|
|
69
|
+
/** Show the on-page overlay. Default `true`. */
|
|
70
|
+
overlay?: boolean;
|
|
71
|
+
/** Log a grouped console report for each slow interaction. Default `true`. */
|
|
72
|
+
console?: boolean;
|
|
73
|
+
/** How many interactions the panel and `getInteractions()` keep. Default `50`. */
|
|
74
|
+
maxEntries?: number;
|
|
75
|
+
/** Overlay corner. Default `"bottom-right"`. */
|
|
76
|
+
position?: Position;
|
|
77
|
+
/** How long a toast stays, in ms. `0` keeps toasts until closed. Default `8000`. */
|
|
78
|
+
toastDuration?: number;
|
|
79
|
+
/** Called for every recorded interaction (at or above `durationThreshold`), slow or not. */
|
|
80
|
+
onInteraction?: (interaction: InpInteraction) => void;
|
|
81
|
+
}
|
|
82
|
+
type ReportFormat = "markdown" | "json";
|
|
83
|
+
|
|
84
|
+
/** Which of the browser APIs inpspy uses are available here. Both `false` on the server. */
|
|
85
|
+
declare function getSupport(): {
|
|
86
|
+
eventTiming: boolean;
|
|
87
|
+
longAnimationFrames: boolean;
|
|
88
|
+
};
|
|
89
|
+
/** The page's interactions recorded since `start()` (oldest first, at most `maxEntries`). */
|
|
90
|
+
declare function getInteractions(): InpInteraction[];
|
|
91
|
+
/** The recorded interactions as a Markdown report (default) or JSON. */
|
|
92
|
+
declare function getReport(format?: ReportFormat): string;
|
|
93
|
+
/** Forgets all recorded interactions (and removes toasts). Keeps observing. */
|
|
94
|
+
declare function clear(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Starts measuring interactions: shows the overlay, logs slow interactions to the console and calls
|
|
97
|
+
* `onInteraction`. Returns `stop()`. Calling `start()` again replaces the running session.
|
|
98
|
+
* On the server (no `window`) it does nothing and returns a no-op.
|
|
99
|
+
*/
|
|
100
|
+
declare function start(options?: InpSpyOptions): () => void;
|
|
101
|
+
/** True while a session started by `start()` is running. */
|
|
102
|
+
declare function isRunning(): boolean;
|
|
103
|
+
|
|
104
|
+
/** The subset of a `PerformanceEventTiming` entry inpspy reads. */
|
|
105
|
+
interface EventEntryLike {
|
|
106
|
+
name: string;
|
|
107
|
+
startTime: number;
|
|
108
|
+
duration: number;
|
|
109
|
+
processingStart: number;
|
|
110
|
+
processingEnd: number;
|
|
111
|
+
interactionId: number;
|
|
112
|
+
}
|
|
113
|
+
/** The subset of a `PerformanceScriptTiming` (Long Animation Frames) inpspy reads. */
|
|
114
|
+
interface ScriptTimingLike {
|
|
115
|
+
startTime: number;
|
|
116
|
+
duration: number;
|
|
117
|
+
sourceURL?: string;
|
|
118
|
+
sourceFunctionName?: string;
|
|
119
|
+
invoker?: string;
|
|
120
|
+
invokerType?: string;
|
|
121
|
+
forcedStyleAndLayoutDuration?: number;
|
|
122
|
+
}
|
|
123
|
+
/** The subset of a `PerformanceLongAnimationFrameTiming` entry inpspy reads. */
|
|
124
|
+
interface LoafLike {
|
|
125
|
+
startTime: number;
|
|
126
|
+
duration: number;
|
|
127
|
+
scripts?: readonly ScriptTimingLike[];
|
|
128
|
+
}
|
|
129
|
+
/** Google's thresholds: good ≤ 200 ms, needs improvement ≤ 500 ms, poor above. */
|
|
130
|
+
declare function rate(duration: number): Rating;
|
|
131
|
+
interface Summary<T extends EventEntryLike> {
|
|
132
|
+
/** The longest entry. */
|
|
133
|
+
main: T;
|
|
134
|
+
startTime: number;
|
|
135
|
+
duration: number;
|
|
136
|
+
phases: Phases;
|
|
137
|
+
/** Entries that were presented in the same frame as the longest one (their handlers count as processing). */
|
|
138
|
+
frame: T[];
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Splits one interaction into input delay, processing and presentation delay.
|
|
142
|
+
*
|
|
143
|
+
* The interaction's duration is the longest entry's. Processing runs from the first handler to the last
|
|
144
|
+
* handler among the entries painted in the same frame (pointerdown, pointerup and click of one tap usually
|
|
145
|
+
* share a frame), so a slow click handler counts as processing, not as presentation of the pointerdown.
|
|
146
|
+
* The phases always add up to `duration`. Event Timing rounds durations to 8 ms, which is why entries
|
|
147
|
+
* within 8 ms of the same end time count as one frame.
|
|
148
|
+
*/
|
|
149
|
+
declare function summarize<T extends EventEntryLike>(entries: readonly T[]): Summary<T> | undefined;
|
|
150
|
+
/**
|
|
151
|
+
* The page INP estimate, as web-vitals computes it: the longest interaction, or with 50 or more
|
|
152
|
+
* interactions roughly the 98th percentile (one interaction is skipped for every 50).
|
|
153
|
+
*
|
|
154
|
+
* @param longest durations of the longest recorded interactions (any order; the 10 longest are enough)
|
|
155
|
+
* @param interactionCount how many interactions the page had in total
|
|
156
|
+
* @returns the estimate in ms, or `null` when nothing was recorded
|
|
157
|
+
*/
|
|
158
|
+
declare function estimateInp(longest: readonly number[], interactionCount: number): number | null;
|
|
159
|
+
/** True when `url` is on a different origin than the page. Empty URLs are not third-party. */
|
|
160
|
+
declare function isThirdParty(url: string, pageOrigin: string): boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Finds the Long Animation Frames that overlap an interaction ([start, end]) and lists the scripts that
|
|
163
|
+
* ran during it, longest first. Scripts from an overlapping frame that ran entirely before or after the
|
|
164
|
+
* interaction are left out.
|
|
165
|
+
*/
|
|
166
|
+
declare function attributeScripts(start: number, end: number, loafs: readonly LoafLike[], pageOrigin: string): {
|
|
167
|
+
attribution: Exclude<Attribution, "unsupported">;
|
|
168
|
+
scripts: InpScript[];
|
|
169
|
+
};
|
|
170
|
+
/** The subset of an `Element` the selector builder reads. */
|
|
171
|
+
interface ElementLike {
|
|
172
|
+
tagName: string;
|
|
173
|
+
id?: string;
|
|
174
|
+
getAttribute?(name: string): string | null;
|
|
175
|
+
textContent?: string | null;
|
|
176
|
+
parentElement?: ElementLike | null;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* A readable selector for an interaction target: `tag#id`, or `tag.class[data-testid]` prefixed with the
|
|
180
|
+
* closest ancestor that has an id (`#product button.add`). `(removed element)` for a null target.
|
|
181
|
+
*/
|
|
182
|
+
declare function describeElement(el: ElementLike | null | undefined): {
|
|
183
|
+
selector: string;
|
|
184
|
+
text: string;
|
|
185
|
+
};
|
|
186
|
+
interface ReportContext {
|
|
187
|
+
url: string;
|
|
188
|
+
/** Page INP estimate in ms, or null when nothing was recorded. */
|
|
189
|
+
inp: number | null;
|
|
190
|
+
/** Interactions on the page so far. */
|
|
191
|
+
interactionCount: number;
|
|
192
|
+
durationThreshold: number;
|
|
193
|
+
loafSupported: boolean;
|
|
194
|
+
}
|
|
195
|
+
/** Renders recorded interactions as Markdown (for an issue or PR) or JSON. */
|
|
196
|
+
declare function formatReport(interactions: readonly InpInteraction[], context: ReportContext, format?: ReportFormat): string;
|
|
197
|
+
|
|
198
|
+
export { type Attribution, type ElementLike, type EventEntryLike, type InpInteraction, type InpScript, type InpSpyOptions, type LoafLike, type Phases, type Position, type Rating, type ReportContext, type ReportFormat, type ScriptTimingLike, attributeScripts, clear, describeElement, estimateInp, formatReport, getInteractions, getReport, getSupport, isRunning, isThirdParty, rate, start, summarize };
|