browser-debugger-cli 0.8.0 → 0.10.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/README.md +7 -1
- package/dist/cdp/schema.d.ts +4 -1
- package/dist/cdp/schema.js +48 -7
- package/dist/commands/cdp.js +3 -2
- package/dist/commands/cleanup.d.ts +11 -0
- package/dist/commands/cleanup.js +161 -57
- package/dist/commands/console.d.ts +20 -1
- package/dist/commands/console.js +57 -17
- package/dist/commands/details.js +3 -2
- package/dist/commands/dom/DomElementResolver.d.ts +10 -3
- package/dist/commands/dom/DomElementResolver.js +35 -17
- package/dist/commands/dom/a11y.d.ts +10 -0
- package/dist/commands/dom/a11y.js +29 -6
- package/dist/commands/dom/eval.d.ts +3 -1
- package/dist/commands/dom/eval.js +29 -4
- package/dist/commands/dom/form.js +16 -62
- package/dist/commands/dom/formInteraction.js +189 -119
- package/dist/commands/dom/formSummary.d.ts +49 -0
- package/dist/commands/dom/formSummary.js +180 -0
- package/dist/commands/dom/frames.d.ts +2 -1
- package/dist/commands/dom/frames.js +17 -2
- package/dist/commands/dom/get.d.ts +6 -5
- package/dist/commands/dom/get.js +92 -82
- package/dist/commands/dom/helpers/index.d.ts +1 -1
- package/dist/commands/dom/helpers/index.js +1 -1
- package/dist/commands/dom/helpers/keyAttributes.d.ts +20 -0
- package/dist/commands/dom/helpers/keyAttributes.js +54 -0
- package/dist/commands/dom/helpers/query.d.ts +44 -17
- package/dist/commands/dom/helpers/query.js +300 -106
- package/dist/commands/dom/helpers/runElementCommand.d.ts +10 -2
- package/dist/commands/dom/helpers/runElementCommand.js +98 -30
- package/dist/commands/dom/helpers/screenshot.d.ts +4 -1
- package/dist/commands/dom/helpers/screenshot.js +239 -51
- package/dist/commands/dom/index.d.ts +4 -1
- package/dist/commands/dom/index.js +22 -7
- package/dist/commands/dom/inspect.d.ts +15 -0
- package/dist/commands/dom/inspect.js +82 -0
- package/dist/commands/dom/layout.d.ts +14 -0
- package/dist/commands/dom/layout.js +54 -0
- package/dist/commands/dom/listeners.d.ts +5 -1
- package/dist/commands/dom/listeners.js +15 -5
- package/dist/commands/dom/query.js +2 -3
- package/dist/commands/dom/screenshot.d.ts +12 -2
- package/dist/commands/dom/screenshot.js +27 -3
- package/dist/commands/dom/semanticUtils.d.ts +16 -10
- package/dist/commands/dom/semanticUtils.js +53 -16
- package/dist/commands/dom/wait.d.ts +13 -0
- package/dist/commands/dom/wait.js +83 -0
- package/dist/commands/helpJson.js +2 -2
- package/dist/commands/network/list.js +17 -13
- package/dist/commands/optionBehaviors.js +154 -21
- package/dist/commands/page.d.ts +3 -2
- package/dist/commands/page.js +100 -5
- package/dist/commands/peek.js +4 -11
- package/dist/commands/sessions.d.ts +8 -0
- package/dist/commands/sessions.js +19 -0
- package/dist/commands/shared/CommandRunner.js +4 -4
- package/dist/commands/shared/commonOptions.d.ts +4 -0
- package/dist/commands/shared/commonOptions.js +9 -0
- package/dist/commands/shared/dataFetcher.js +2 -2
- package/dist/commands/shared/followMode.d.ts +21 -1
- package/dist/commands/shared/followMode.js +29 -2
- package/dist/commands/shared/handleValidationError.d.ts +2 -2
- package/dist/commands/shared/handleValidationError.js +12 -3
- package/dist/commands/shared/optionTypes.d.ts +61 -5
- package/dist/commands/shared/startHelpers.d.ts +66 -0
- package/dist/commands/shared/startHelpers.js +103 -13
- package/dist/commands/shared/validation.d.ts +14 -2
- package/dist/commands/shared/validation.js +20 -3
- package/dist/commands/start.d.ts +63 -0
- package/dist/commands/start.js +115 -15
- package/dist/commands/status.js +29 -7
- package/dist/commands/stop.js +7 -6
- package/dist/commands/tail.js +4 -11
- package/dist/commands/types.d.ts +2 -0
- package/dist/commands.js +2 -0
- package/dist/connection/chromeIdentity.d.ts +65 -0
- package/dist/connection/chromeIdentity.js +143 -0
- package/dist/connection/launcher/profilePreferences.d.ts +47 -0
- package/dist/connection/launcher/profilePreferences.js +151 -0
- package/dist/connection/launcher.d.ts +21 -2
- package/dist/connection/launcher.js +42 -16
- package/dist/connection/portReservation.d.ts +14 -4
- package/dist/connection/portReservation.js +21 -6
- package/dist/connection/startupExit.d.ts +8 -0
- package/dist/connection/startupExit.js +15 -6
- package/dist/constants.d.ts +6 -2
- package/dist/constants.js +9 -2
- package/dist/daemon/SessionController.js +23 -7
- package/dist/daemon/errors.d.ts +1 -1
- package/dist/daemon/errors.js +1 -1
- package/dist/daemon/launcher.d.ts +10 -2
- package/dist/daemon/launcher.js +8 -7
- package/dist/daemon/server/SocketServer.js +1 -2
- package/dist/daemon/session/Session.d.ts +20 -0
- package/dist/daemon/session/Session.js +80 -9
- package/dist/daemon/session/chromeConnection.d.ts +9 -0
- package/dist/daemon/session/chromeConnection.js +45 -8
- package/dist/daemon/session/commandRegistry.d.ts +14 -1
- package/dist/daemon/session/commandRegistry.js +113 -67
- package/dist/daemon/session/interactions.d.ts +48 -9
- package/dist/daemon/session/interactions.js +46 -9
- package/dist/daemon/session/triggeredRequests.d.ts +67 -0
- package/dist/daemon/session/triggeredRequests.js +157 -0
- package/dist/daemon/session/types.d.ts +5 -1
- package/dist/daemon.js +10630 -3601
- package/dist/errors/messages.d.ts +456 -24
- package/dist/errors/messages.js +862 -67
- package/dist/index.js +6915 -3401
- package/dist/ipc/client.d.ts +21 -1
- package/dist/ipc/client.js +35 -3
- package/dist/ipc/protocol/commands.d.ts +145 -5
- package/dist/ipc/protocol/commands.js +4 -0
- package/dist/ipc/protocol/domTypes.d.ts +291 -7
- package/dist/ipc/protocol/inspectTypes.d.ts +388 -0
- package/dist/ipc/protocol/inspectTypes.js +10 -0
- package/dist/ipc/session/lifecycle.d.ts +8 -1
- package/dist/ipc/session/queries.d.ts +5 -1
- package/dist/ipc/session/types.d.ts +5 -0
- package/dist/ipc/transport/index.d.ts +2 -1
- package/dist/ipc/transport/index.js +2 -2
- package/dist/runtime/dom/actionEffects.d.ts +185 -0
- package/dist/runtime/dom/actionEffects.js +402 -0
- package/dist/runtime/dom/actionEffectsScripts.d.ts +90 -0
- package/dist/runtime/dom/actionEffectsScripts.js +426 -0
- package/dist/runtime/dom/elementGeometry.d.ts +170 -0
- package/dist/runtime/dom/elementGeometry.js +553 -0
- package/dist/runtime/dom/elementInfo.d.ts +103 -0
- package/dist/runtime/dom/elementInfo.js +256 -0
- package/dist/runtime/dom/evalHelpers.d.ts +51 -6
- package/dist/runtime/dom/evalHelpers.js +136 -26
- package/dist/runtime/dom/eventListeners.d.ts +2 -1
- package/dist/runtime/dom/eventListeners.js +184 -47
- package/dist/runtime/dom/formDiscovery.d.ts +1 -1
- package/dist/runtime/dom/formDiscovery.js +116 -16
- package/dist/runtime/dom/formFillHelpers/fill.d.ts +9 -0
- package/dist/runtime/dom/formFillHelpers/fill.js +178 -14
- package/dist/runtime/dom/formFillHelpers/index.d.ts +2 -2
- package/dist/runtime/dom/formFillHelpers/index.js +2 -2
- package/dist/runtime/dom/formFillHelpers/pressKey.js +14 -3
- package/dist/runtime/dom/formFillHelpers/scroll.d.ts +3 -0
- package/dist/runtime/dom/formFillHelpers/scroll.js +60 -18
- package/dist/runtime/dom/formFillHelpers/shared.d.ts +17 -0
- package/dist/runtime/dom/formFillHelpers/shared.js +25 -1
- package/dist/runtime/dom/formFillHelpers/stability.d.ts +20 -6
- package/dist/runtime/dom/formFillHelpers/stability.js +50 -19
- package/dist/runtime/dom/formSubmitHelpers.d.ts +3 -0
- package/dist/runtime/dom/formSubmitHelpers.js +89 -15
- package/dist/runtime/dom/frameLayout.d.ts +60 -0
- package/dist/runtime/dom/frameLayout.js +140 -0
- package/dist/runtime/dom/frameOrigin.d.ts +50 -0
- package/dist/runtime/dom/frameOrigin.js +62 -0
- package/dist/runtime/dom/frameScopedConnection.d.ts +92 -0
- package/dist/runtime/dom/frameScopedConnection.js +252 -0
- package/dist/runtime/dom/frameSelection.d.ts +12 -1
- package/dist/runtime/dom/frameSelection.js +22 -3
- package/dist/runtime/dom/frames.d.ts +61 -5
- package/dist/runtime/dom/frames.js +329 -75
- package/dist/runtime/dom/inspect.d.ts +28 -0
- package/dist/runtime/dom/inspect.js +557 -0
- package/dist/runtime/dom/inspectAllStyles.d.ts +62 -0
- package/dist/runtime/dom/inspectAllStyles.js +385 -0
- package/dist/runtime/dom/inspectCascade.d.ts +94 -0
- package/dist/runtime/dom/inspectCascade.js +371 -0
- package/dist/runtime/dom/inspectCascadeModel.d.ts +39 -0
- package/dist/runtime/dom/inspectCascadeModel.js +232 -0
- package/dist/runtime/dom/inspectHints.d.ts +62 -0
- package/dist/runtime/dom/inspectHints.js +305 -0
- package/dist/runtime/dom/inspectLayoutModel.d.ts +87 -0
- package/dist/runtime/dom/inspectLayoutModel.js +346 -0
- package/dist/runtime/dom/inspectModel.d.ts +74 -0
- package/dist/runtime/dom/inspectModel.js +184 -0
- package/dist/runtime/dom/inspectPaintModel.d.ts +157 -0
- package/dist/runtime/dom/inspectPaintModel.js +461 -0
- package/dist/runtime/dom/inspectRules.d.ts +37 -0
- package/dist/runtime/dom/inspectRules.js +101 -0
- package/dist/runtime/dom/inspectScripts.d.ts +132 -0
- package/dist/runtime/dom/inspectScripts.js +263 -0
- package/dist/runtime/dom/inspectTree.d.ts +40 -0
- package/dist/runtime/dom/inspectTree.js +134 -0
- package/dist/runtime/dom/inspectVariables.d.ts +33 -0
- package/dist/runtime/dom/inspectVariables.js +94 -0
- package/dist/runtime/dom/inspectWhyModel.d.ts +20 -0
- package/dist/runtime/dom/inspectWhyModel.js +134 -0
- package/dist/runtime/dom/layout.d.ts +71 -0
- package/dist/runtime/dom/layout.js +340 -0
- package/dist/runtime/dom/listenerPageScripts.d.ts +72 -0
- package/dist/runtime/dom/listenerPageScripts.js +365 -0
- package/dist/runtime/dom/listenerSummary.d.ts +136 -11
- package/dist/runtime/dom/listenerSummary.js +361 -22
- package/dist/runtime/dom/pageActivity.d.ts +41 -0
- package/dist/runtime/dom/pageActivity.js +123 -0
- package/dist/runtime/dom/reactEventHelpers.d.ts +63 -2
- package/dist/runtime/dom/reactEventHelpers.js +220 -41
- package/dist/runtime/dom/targetNode.d.ts +80 -27
- package/dist/runtime/dom/targetNode.js +249 -33
- package/dist/runtime/dom/wait.d.ts +25 -0
- package/dist/runtime/dom/wait.js +199 -0
- package/dist/runtime/dom/waitCondition.d.ts +71 -0
- package/dist/runtime/dom/waitCondition.js +75 -0
- package/dist/runtime/page/emulation.d.ts +71 -0
- package/dist/runtime/page/emulation.js +117 -0
- package/dist/runtime/page/loadingState.d.ts +36 -0
- package/dist/runtime/page/loadingState.js +86 -0
- package/dist/runtime/page/navigation.d.ts +46 -2
- package/dist/runtime/page/navigation.js +69 -33
- package/dist/session/QueryCacheManager.d.ts +11 -1
- package/dist/session/QueryCacheManager.js +25 -3
- package/dist/session/chromeOwners.d.ts +34 -0
- package/dist/session/chromeOwners.js +51 -0
- package/dist/session/cleanup/staleSession.d.ts +11 -1
- package/dist/session/cleanup/staleSession.js +17 -6
- package/dist/session/cleanup/userCommands.js +2 -4
- package/dist/session/metadata.d.ts +5 -1
- package/dist/session/metadata.js +2 -1
- package/dist/session/paths.d.ts +77 -3
- package/dist/session/paths.js +111 -5
- package/dist/session/port.d.ts +31 -7
- package/dist/session/port.js +50 -43
- package/dist/session/portClaims.d.ts +66 -0
- package/dist/session/portClaims.js +284 -0
- package/dist/session/sessionList.d.ts +58 -0
- package/dist/session/sessionList.js +199 -0
- package/dist/session/sessionName.d.ts +46 -0
- package/dist/session/sessionName.js +97 -0
- package/dist/telemetry/a11y.d.ts +18 -3
- package/dist/telemetry/a11y.js +170 -29
- package/dist/telemetry/console.d.ts +1 -0
- package/dist/telemetry/console.js +100 -5
- package/dist/telemetry/network.js +3 -1
- package/dist/telemetry/requestKinds.d.ts +32 -0
- package/dist/telemetry/requestKinds.js +61 -0
- package/dist/telemetry/requestState.d.ts +31 -0
- package/dist/telemetry/requestState.js +38 -0
- package/dist/types.d.ts +112 -3
- package/dist/ui/formatters/a11y.js +3 -0
- package/dist/ui/formatters/console/chronological.d.ts +8 -0
- package/dist/ui/formatters/console/chronological.js +17 -4
- package/dist/ui/formatters/console/json.js +3 -4
- package/dist/ui/formatters/console/shared.d.ts +12 -0
- package/dist/ui/formatters/console.d.ts +2 -2
- package/dist/ui/formatters/console.js +1 -1
- package/dist/ui/formatters/details.d.ts +8 -0
- package/dist/ui/formatters/details.js +61 -4
- package/dist/ui/formatters/dom.d.ts +27 -14
- package/dist/ui/formatters/dom.js +88 -59
- package/dist/ui/formatters/form.js +29 -18
- package/dist/ui/formatters/inspect.d.ts +39 -0
- package/dist/ui/formatters/inspect.js +596 -0
- package/dist/ui/formatters/keyAttributes.d.ts +19 -0
- package/dist/ui/formatters/keyAttributes.js +84 -0
- package/dist/ui/formatters/layout.d.ts +31 -0
- package/dist/ui/formatters/layout.js +53 -0
- package/dist/ui/formatters/listeners.d.ts +3 -2
- package/dist/ui/formatters/listeners.js +73 -9
- package/dist/ui/formatters/networkHeaders.d.ts +13 -0
- package/dist/ui/formatters/networkHeaders.js +36 -3
- package/dist/ui/formatters/networkList.d.ts +29 -1
- package/dist/ui/formatters/networkList.js +86 -20
- package/dist/ui/formatters/preview.js +2 -1
- package/dist/ui/formatters/requestStatus.d.ts +1 -17
- package/dist/ui/formatters/requestStatus.js +2 -30
- package/dist/ui/formatters/sessions.d.ts +12 -0
- package/dist/ui/formatters/sessions.js +40 -0
- package/dist/ui/formatters/status.d.ts +21 -2
- package/dist/ui/formatters/status.js +47 -10
- package/dist/ui/formatters/triggeredRequests.d.ts +36 -0
- package/dist/ui/formatters/triggeredRequests.js +65 -0
- package/dist/ui/formatting.d.ts +19 -0
- package/dist/ui/formatting.js +31 -36
- package/dist/ui/messages/chrome.d.ts +9 -0
- package/dist/ui/messages/chrome.js +17 -5
- package/dist/ui/messages/commands.d.ts +504 -14
- package/dist/ui/messages/commands.js +835 -21
- package/dist/ui/messages/consoleMessages.d.ts +10 -0
- package/dist/ui/messages/consoleMessages.js +17 -0
- package/dist/ui/messages/hints.js +2 -1
- package/dist/ui/messages/networkMessages.d.ts +14 -0
- package/dist/ui/messages/networkMessages.js +18 -0
- package/dist/ui/messages/preview.js +5 -4
- package/dist/ui/messages/session.d.ts +30 -21
- package/dist/ui/messages/session.js +48 -26
- package/dist/ui/messages/sessionCommand.d.ts +43 -0
- package/dist/ui/messages/sessionCommand.js +52 -0
- package/dist/utils/async.d.ts +17 -0
- package/dist/utils/async.js +36 -0
- package/dist/utils/color.d.ts +84 -0
- package/dist/utils/color.js +376 -0
- package/dist/utils/cssValues.d.ts +109 -0
- package/dist/utils/cssValues.js +236 -0
- package/dist/utils/http.d.ts +22 -1
- package/dist/utils/http.js +28 -9
- package/dist/utils/selectorFilters.d.ts +48 -8
- package/dist/utils/selectorFilters.js +296 -53
- package/dist/utils/shellDetection.d.ts +8 -2
- package/dist/utils/shellDetection.js +120 -33
- package/dist/utils/suggestions.d.ts +26 -0
- package/dist/utils/suggestions.js +73 -0
- package/dist/utils/taskMappings.js +10 -0
- package/dist/utils/url.d.ts +12 -2
- package/dist/utils/url.js +69 -7
- package/package.json +1 -1
- package/dist/ui/formatters/sessionFormatters.d.ts +0 -58
- package/dist/ui/formatters/sessionFormatters.js +0 -121
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The child tree of `bdg dom inspect`: the page-side walk's children
|
|
3
|
+
* ({@link RawTreeNode}) with sizes rounded, consecutive identical siblings
|
|
4
|
+
* (same label, size and layout) grouped into one row with a count
|
|
5
|
+
* (`li.card ×33 266x107`), and cut to a number of rows in document order.
|
|
6
|
+
*/
|
|
7
|
+
import { containerKind } from './inspectLayoutModel.js';
|
|
8
|
+
/** Default depth of the tree */
|
|
9
|
+
export const DEFAULT_TREE_DEPTH = 2;
|
|
10
|
+
/** Default number of rows */
|
|
11
|
+
export const DEFAULT_TREE_LIMIT = 20;
|
|
12
|
+
/** Characters of text kept per row */
|
|
13
|
+
const ROW_TEXT_LENGTH = 30;
|
|
14
|
+
/**
|
|
15
|
+
* Cut a row's text on a whole character.
|
|
16
|
+
*
|
|
17
|
+
* @param text - Text
|
|
18
|
+
* @returns At most {@link ROW_TEXT_LENGTH} characters, with `…` when cut
|
|
19
|
+
*/
|
|
20
|
+
export function rowText(text) {
|
|
21
|
+
const characters = Array.from(text);
|
|
22
|
+
return characters.length > ROW_TEXT_LENGTH
|
|
23
|
+
? `${characters.slice(0, ROW_TEXT_LENGTH).join('').trimEnd()}…`
|
|
24
|
+
: text;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* One child as a tree row (its children converted too).
|
|
28
|
+
*
|
|
29
|
+
* @param raw - Child from the page-side walk
|
|
30
|
+
* @returns Tree row
|
|
31
|
+
*/
|
|
32
|
+
function toNode(raw) {
|
|
33
|
+
const layout = containerKind(raw.display);
|
|
34
|
+
const children = raw.children ? groupSiblings(raw.children.map(toNode)) : undefined;
|
|
35
|
+
return {
|
|
36
|
+
element: raw.label,
|
|
37
|
+
x: Math.round(raw.x * 10) / 10,
|
|
38
|
+
y: Math.round(raw.y * 10) / 10,
|
|
39
|
+
w: Math.round(raw.w),
|
|
40
|
+
h: Math.round(raw.h),
|
|
41
|
+
...(layout && { layout }),
|
|
42
|
+
...(raw.text && { text: rowText(raw.text) }),
|
|
43
|
+
...(children && children.length > 0 && { children }),
|
|
44
|
+
...(raw.childCount && { childCount: raw.childCount }),
|
|
45
|
+
...(raw.hidden && { hiddenChildren: raw.hidden }),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Whether two siblings look the same in the tree.
|
|
50
|
+
*
|
|
51
|
+
* @param a - Row
|
|
52
|
+
* @param b - Row
|
|
53
|
+
* @returns True for the same label, size and layout
|
|
54
|
+
*/
|
|
55
|
+
function identical(a, b) {
|
|
56
|
+
return a.element === b.element && a.w === b.w && a.h === b.h && a.layout === b.layout;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Group runs of identical siblings into one row with a count. A group keeps
|
|
60
|
+
* its text only when every member has the same, and lists no children.
|
|
61
|
+
*
|
|
62
|
+
* @param nodes - Sibling rows
|
|
63
|
+
* @returns Rows with runs grouped
|
|
64
|
+
*/
|
|
65
|
+
export function groupSiblings(nodes) {
|
|
66
|
+
const grouped = [];
|
|
67
|
+
for (let i = 0; i < nodes.length;) {
|
|
68
|
+
const first = nodes[i];
|
|
69
|
+
let run = 1;
|
|
70
|
+
while (i + run < nodes.length && identical(first, nodes[i + run]))
|
|
71
|
+
run++;
|
|
72
|
+
if (run === 1) {
|
|
73
|
+
grouped.push(first);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const members = nodes.slice(i, i + run);
|
|
77
|
+
const sameText = members.every((member) => member.text === first.text);
|
|
78
|
+
const { children: _children, childCount: _count, hiddenChildren: _hidden, text, ...row } = first;
|
|
79
|
+
grouped.push({ ...row, ...(sameText && text && { text }), count: run });
|
|
80
|
+
}
|
|
81
|
+
i += run;
|
|
82
|
+
}
|
|
83
|
+
return grouped;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Rows a node takes in the tree (itself and its listed descendants).
|
|
87
|
+
*
|
|
88
|
+
* @param node - Row
|
|
89
|
+
* @returns Row count
|
|
90
|
+
*/
|
|
91
|
+
function rowCount(node) {
|
|
92
|
+
return 1 + (node.children ?? []).reduce((sum, child) => sum + rowCount(child), 0);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Keep the first rows in document order.
|
|
96
|
+
*
|
|
97
|
+
* @param nodes - Rows
|
|
98
|
+
* @param budget - Rows still allowed (decremented)
|
|
99
|
+
* @returns Kept rows and the number left out
|
|
100
|
+
*/
|
|
101
|
+
function prune(nodes, budget) {
|
|
102
|
+
const kept = [];
|
|
103
|
+
let dropped = 0;
|
|
104
|
+
for (const node of nodes) {
|
|
105
|
+
if (budget.left <= 0) {
|
|
106
|
+
dropped += rowCount(node);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
budget.left--;
|
|
110
|
+
if (!node.children) {
|
|
111
|
+
kept.push(node);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const sub = prune(node.children, budget);
|
|
115
|
+
dropped += sub.dropped;
|
|
116
|
+
const { children: _children, ...row } = node;
|
|
117
|
+
kept.push(sub.kept.length > 0 ? { ...row, children: sub.kept } : row);
|
|
118
|
+
}
|
|
119
|
+
return { kept, dropped };
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The child tree from the page-side walk: grouped, then cut to `limit` rows.
|
|
123
|
+
*
|
|
124
|
+
* @param raw - Children from the walk
|
|
125
|
+
* @param limit - Rows shown at most
|
|
126
|
+
* @param skipped - Children the walk did not reach (counted as left out)
|
|
127
|
+
* @returns Rows and the number of rows left out
|
|
128
|
+
*/
|
|
129
|
+
export function buildTree(raw, limit, skipped = 0) {
|
|
130
|
+
const rows = groupSiblings(raw.map(toNode));
|
|
131
|
+
const { kept, dropped } = prune(rows, { left: limit });
|
|
132
|
+
return { children: kept, moreRows: dropped + skipped };
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=inspectTree.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `var()` in declared values: which custom properties a value uses, which of
|
|
3
|
+
* them are not set, and the value with them substituted. A fallback counts
|
|
4
|
+
* only when its custom property is not set.
|
|
5
|
+
*/
|
|
6
|
+
import type { StyleMap } from './inspectLayoutModel.js';
|
|
7
|
+
/**
|
|
8
|
+
* The custom properties a value uses that are not set and have no fallback:
|
|
9
|
+
* the fallback of an unset one is used instead (and checked in turn).
|
|
10
|
+
*
|
|
11
|
+
* @param value - Value as written
|
|
12
|
+
* @param style - Computed styles (custom properties included)
|
|
13
|
+
* @returns Names of the unset custom properties
|
|
14
|
+
*/
|
|
15
|
+
export declare function unsetVariables(value: string, style: StyleMap): string[];
|
|
16
|
+
/**
|
|
17
|
+
* The custom properties a value takes its value from (fallbacks only when
|
|
18
|
+
* used).
|
|
19
|
+
*
|
|
20
|
+
* @param value - Value as written
|
|
21
|
+
* @param style - Computed styles
|
|
22
|
+
* @returns Names
|
|
23
|
+
*/
|
|
24
|
+
export declare function usedVariables(value: string, style: StyleMap): string[];
|
|
25
|
+
/**
|
|
26
|
+
* A value with its custom properties substituted.
|
|
27
|
+
*
|
|
28
|
+
* @param value - Value as written
|
|
29
|
+
* @param style - Computed styles
|
|
30
|
+
* @returns Substituted value (unset ones without fallback left as written)
|
|
31
|
+
*/
|
|
32
|
+
export declare function substituteVariables(value: string, style: StyleMap): string;
|
|
33
|
+
//# sourceMappingURL=inspectVariables.d.ts.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `var()` in declared values: which custom properties a value uses, which of
|
|
3
|
+
* them are not set, and the value with them substituted. A fallback counts
|
|
4
|
+
* only when its custom property is not set.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The top-level `var()` calls of a value.
|
|
8
|
+
*
|
|
9
|
+
* @param value - Value as written
|
|
10
|
+
* @returns Calls in order (nested ones are inside a fallback)
|
|
11
|
+
*/
|
|
12
|
+
function varCalls(value) {
|
|
13
|
+
const calls = [];
|
|
14
|
+
for (let start = value.indexOf('var('); start !== -1; start = value.indexOf('var(', start + 1)) {
|
|
15
|
+
const end = closingParen(value, start + 3);
|
|
16
|
+
const [name = '', ...fallback] = value.slice(start + 4, end).split(',');
|
|
17
|
+
calls.push({
|
|
18
|
+
start,
|
|
19
|
+
end,
|
|
20
|
+
name: name.trim(),
|
|
21
|
+
...(fallback.length > 0 && { fallback: fallback.join(',').trim() }),
|
|
22
|
+
});
|
|
23
|
+
start = end;
|
|
24
|
+
}
|
|
25
|
+
return calls;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Index of the parenthesis that closes the one at `open`.
|
|
29
|
+
*
|
|
30
|
+
* @param text - Text
|
|
31
|
+
* @param open - Index of `(`
|
|
32
|
+
* @returns Index of the matching `)` (the end of the text when unbalanced)
|
|
33
|
+
*/
|
|
34
|
+
function closingParen(text, open) {
|
|
35
|
+
let depth = 0;
|
|
36
|
+
for (let i = open; i < text.length; i++) {
|
|
37
|
+
if (text[i] === '(')
|
|
38
|
+
depth++;
|
|
39
|
+
if (text[i] === ')' && --depth === 0)
|
|
40
|
+
return i;
|
|
41
|
+
}
|
|
42
|
+
return text.length;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The custom properties a value uses that are not set and have no fallback:
|
|
46
|
+
* the fallback of an unset one is used instead (and checked in turn).
|
|
47
|
+
*
|
|
48
|
+
* @param value - Value as written
|
|
49
|
+
* @param style - Computed styles (custom properties included)
|
|
50
|
+
* @returns Names of the unset custom properties
|
|
51
|
+
*/
|
|
52
|
+
export function unsetVariables(value, style) {
|
|
53
|
+
return varCalls(value).flatMap((call) => {
|
|
54
|
+
if (style[call.name] !== undefined)
|
|
55
|
+
return [];
|
|
56
|
+
return call.fallback !== undefined ? unsetVariables(call.fallback, style) : [call.name];
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The custom properties a value takes its value from (fallbacks only when
|
|
61
|
+
* used).
|
|
62
|
+
*
|
|
63
|
+
* @param value - Value as written
|
|
64
|
+
* @param style - Computed styles
|
|
65
|
+
* @returns Names
|
|
66
|
+
*/
|
|
67
|
+
export function usedVariables(value, style) {
|
|
68
|
+
return varCalls(value).flatMap((call) => style[call.name] !== undefined || call.fallback === undefined
|
|
69
|
+
? [call.name]
|
|
70
|
+
: usedVariables(call.fallback, style));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* A value with its custom properties substituted.
|
|
74
|
+
*
|
|
75
|
+
* @param value - Value as written
|
|
76
|
+
* @param style - Computed styles
|
|
77
|
+
* @returns Substituted value (unset ones without fallback left as written)
|
|
78
|
+
*/
|
|
79
|
+
export function substituteVariables(value, style) {
|
|
80
|
+
let result = '';
|
|
81
|
+
let last = 0;
|
|
82
|
+
for (const call of varCalls(value)) {
|
|
83
|
+
const set = style[call.name];
|
|
84
|
+
const replacement = set !== undefined
|
|
85
|
+
? set.trim()
|
|
86
|
+
: call.fallback !== undefined
|
|
87
|
+
? substituteVariables(call.fallback, style)
|
|
88
|
+
: value.slice(call.start, call.end + 1);
|
|
89
|
+
result += value.slice(last, call.start) + replacement;
|
|
90
|
+
last = call.end + 1;
|
|
91
|
+
}
|
|
92
|
+
return result + value.slice(last);
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=inspectVariables.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dom inspect --why <property>`: every declaration of a property on the
|
|
3
|
+
* element, the winner first, with `var()` values substituted and where the
|
|
4
|
+
* winner's custom properties are set. A shorthand gives one answer when one
|
|
5
|
+
* declaration sets all its longhands (listing every declaration it beats on
|
|
6
|
+
* any of them), else one per longhand.
|
|
7
|
+
*/
|
|
8
|
+
import type { InspectWhy } from '../../ipc/protocol/inspectTypes.js';
|
|
9
|
+
import { type Resolution } from './inspectCascade.js';
|
|
10
|
+
import type { CascadeInput, PropertyGroup } from './inspectCascadeModel.js';
|
|
11
|
+
/**
|
|
12
|
+
* `--why` for a property.
|
|
13
|
+
*
|
|
14
|
+
* @param group - The property and its longhands
|
|
15
|
+
* @param cascade - Resolved properties
|
|
16
|
+
* @param input - Matched rules, computed style and the label function
|
|
17
|
+
* @returns One entry, or one per longhand when they differ
|
|
18
|
+
*/
|
|
19
|
+
export declare function buildWhy(group: PropertyGroup, cascade: Map<string, Resolution>, input: CascadeInput): InspectWhy[];
|
|
20
|
+
//# sourceMappingURL=inspectWhyModel.d.ts.map
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dom inspect --why <property>`: every declaration of a property on the
|
|
3
|
+
* element, the winner first, with `var()` values substituted and where the
|
|
4
|
+
* winner's custom properties are set. A shorthand gives one answer when one
|
|
5
|
+
* declaration sets all its longhands (listing every declaration it beats on
|
|
6
|
+
* any of them), else one per longhand.
|
|
7
|
+
*/
|
|
8
|
+
import { normalizeProperty } from './inspectAllStyles.js';
|
|
9
|
+
import { resolveCascade } from './inspectCascade.js';
|
|
10
|
+
import { substituteVariables, unsetVariables, usedVariables, } from './inspectVariables.js';
|
|
11
|
+
/**
|
|
12
|
+
* `--why` for a property.
|
|
13
|
+
*
|
|
14
|
+
* @param group - The property and its longhands
|
|
15
|
+
* @param cascade - Resolved properties
|
|
16
|
+
* @param input - Matched rules, computed style and the label function
|
|
17
|
+
* @returns One entry, or one per longhand when they differ
|
|
18
|
+
*/
|
|
19
|
+
export function buildWhy(group, cascade, input) {
|
|
20
|
+
const whys = group.longhands.map((longhand) => whyOf(longhand, cascade.get(longhand), input));
|
|
21
|
+
const [first] = whys;
|
|
22
|
+
if (!first || group.shorthand === undefined)
|
|
23
|
+
return whys;
|
|
24
|
+
const winner = JSON.stringify(first.chain[0]);
|
|
25
|
+
if (!whys.every((why) => JSON.stringify(why.chain[0]) === winner))
|
|
26
|
+
return whys;
|
|
27
|
+
const values = whys.map((why) => why.computed);
|
|
28
|
+
const computed = values.every((value) => value === first.computed)
|
|
29
|
+
? first.computed
|
|
30
|
+
: values.join(' ');
|
|
31
|
+
const beaten = whys.flatMap((why) => why.chain.slice(1));
|
|
32
|
+
const overridden = [...new Map(beaten.map((entry) => [JSON.stringify(entry), entry])).values()];
|
|
33
|
+
const chain = [...first.chain.slice(0, 1), ...overridden];
|
|
34
|
+
return [{ ...first, property: group.shorthand, computed, chain }];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* `--why` for one longhand.
|
|
38
|
+
*
|
|
39
|
+
* @param property - Longhand
|
|
40
|
+
* @param resolution - Its resolution
|
|
41
|
+
* @param input - Matched rules, computed style and the label function
|
|
42
|
+
* @returns Why
|
|
43
|
+
*/
|
|
44
|
+
function whyOf(property, resolution, input) {
|
|
45
|
+
const winner = resolution?.winner;
|
|
46
|
+
const chain = [
|
|
47
|
+
...(winner
|
|
48
|
+
? [whyEntry(winner, winner.ancestor !== undefined ? 'inherited' : 'applied', input)]
|
|
49
|
+
: []),
|
|
50
|
+
...(resolution?.overridden ?? []).map((d) => whyEntry(d, 'overridden', input)),
|
|
51
|
+
];
|
|
52
|
+
const variables = winner ? variableSources(winner, input) : [];
|
|
53
|
+
return {
|
|
54
|
+
property,
|
|
55
|
+
computed: normalizeProperty(property, input.style[property] ?? ''),
|
|
56
|
+
chain,
|
|
57
|
+
...(variables.length > 0 && { variables }),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* One declaration in a `--why` chain: a shorthand's as written, `var()`
|
|
62
|
+
* substituted (or the custom properties that are not set), with the
|
|
63
|
+
* selector's specificity.
|
|
64
|
+
*
|
|
65
|
+
* @param declaration - Declaration
|
|
66
|
+
* @param status - Applied, overridden or inherited
|
|
67
|
+
* @param input - Computed style and the label function
|
|
68
|
+
* @returns Entry
|
|
69
|
+
*/
|
|
70
|
+
function whyEntry(declaration, status, input) {
|
|
71
|
+
const value = declaration.via ? (declaration.written ?? declaration.value) : declaration.value;
|
|
72
|
+
const unset = value.includes('var(') ? unsetVariables(value, input.style) : [];
|
|
73
|
+
const resolved = value.includes('var(') ? resolvedValue(declaration, value, input) : value;
|
|
74
|
+
const { specificity, layer, condition } = declaration.source;
|
|
75
|
+
return {
|
|
76
|
+
value,
|
|
77
|
+
...(declaration.via && { via: declaration.via }),
|
|
78
|
+
...(unset.length > 0 ? { unset } : resolved !== value && { resolved }),
|
|
79
|
+
source: input.label(declaration),
|
|
80
|
+
...(specificity && { specificity }),
|
|
81
|
+
status,
|
|
82
|
+
...(declaration.important && { important: true }),
|
|
83
|
+
...(layer && { layer }),
|
|
84
|
+
...(condition && { condition }),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** How many levels of custom properties set from others are followed */
|
|
88
|
+
const MAX_VARIABLE_DEPTH = 5;
|
|
89
|
+
/**
|
|
90
|
+
* Where the custom properties the winning value uses are set, and those
|
|
91
|
+
* their values use in turn (`--bs-btn-border-width: var(--bs-border-width)`).
|
|
92
|
+
*
|
|
93
|
+
* @param winner - Winning declaration
|
|
94
|
+
* @param input - Matched rules, computed style and the label function
|
|
95
|
+
* @returns The variables with a declaration (on the element or an ancestor)
|
|
96
|
+
*/
|
|
97
|
+
function variableSources(winner, input) {
|
|
98
|
+
const found = [];
|
|
99
|
+
let names = usedVariables(winner.written ?? winner.value, input.style);
|
|
100
|
+
for (let depth = 0; names.length > 0 && depth < MAX_VARIABLE_DEPTH; depth++) {
|
|
101
|
+
const cascade = resolveCascade(input.matched, names);
|
|
102
|
+
const next = names.flatMap((name) => {
|
|
103
|
+
const declaration = cascade.get(name)?.winner;
|
|
104
|
+
if (!declaration || found.some((variable) => variable.name === name))
|
|
105
|
+
return [];
|
|
106
|
+
found.push({
|
|
107
|
+
name,
|
|
108
|
+
value: declaration.value,
|
|
109
|
+
source: input.label(declaration),
|
|
110
|
+
...(declaration.ancestor !== undefined && { inherited: declaration.ancestor }),
|
|
111
|
+
});
|
|
112
|
+
return usedVariables(declaration.value, input.style);
|
|
113
|
+
});
|
|
114
|
+
names = [...new Set(next)];
|
|
115
|
+
}
|
|
116
|
+
return found;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* A `var()` value substituted; a color longhand's in hex (Tailwind's
|
|
120
|
+
* `lab()` and `oklch()` tokens are unreadable).
|
|
121
|
+
*
|
|
122
|
+
* @param declaration - Declaration
|
|
123
|
+
* @param value - Its value as shown
|
|
124
|
+
* @param input - Computed style
|
|
125
|
+
* @returns Substituted value
|
|
126
|
+
*/
|
|
127
|
+
function resolvedValue(declaration, value, input) {
|
|
128
|
+
const substituted = substituteVariables(value, input.style);
|
|
129
|
+
const isColor = declaration.via === undefined && declaration.property.endsWith('color');
|
|
130
|
+
return isColor && !substituted.includes('var(')
|
|
131
|
+
? normalizeProperty(declaration.property, substituted)
|
|
132
|
+
: substituted;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=inspectWhyModel.js.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Positions, sizes and visibility of elements (`bdg dom layout`).
|
|
3
|
+
*
|
|
4
|
+
* One page-side pass per command measures every match: its box in page and
|
|
5
|
+
* viewport coordinates (iframe offsets included), what clips it, whether it
|
|
6
|
+
* is rendered, what covers its center and the styles that decide how it
|
|
7
|
+
* shows. The measurements are classified outside the page
|
|
8
|
+
* ({@link classifyViewportPosition}).
|
|
9
|
+
*/
|
|
10
|
+
import type { CDPConnection } from '../../connection/cdp.js';
|
|
11
|
+
import type { DomLayoutCommand } from '../../ipc/protocol/commands.js';
|
|
12
|
+
import type { LayoutComputedStyle, LayoutResult, PageLayout } from '../../ipc/protocol/domTypes.js';
|
|
13
|
+
import { type ElementGeometry } from './elementGeometry.js';
|
|
14
|
+
/** Matches measured per command (the rest are counted as omitted) */
|
|
15
|
+
export declare const LAYOUT_ELEMENT_LIMIT = 100;
|
|
16
|
+
/**
|
|
17
|
+
* Page-side end of a visible span kept clear of an overlay scrollbar along
|
|
18
|
+
* an edge (16 CSS px wide): overlay scrollbars (macOS, mobile) show for about a
|
|
19
|
+
* second after a scroll and catch hit tests, which then return the scroller.
|
|
20
|
+
* The span ends before the strip when it reaches into it and also shows
|
|
21
|
+
* outside it; without overlay scrollbars along the edge it is unchanged.
|
|
22
|
+
* Arguments: span start and end, the edge, whether overlay scrollbars show there.
|
|
23
|
+
*/
|
|
24
|
+
export declare const CLEAR_OF_SCROLLBAR_JS = "(start, end, edge, overlay) =>\n overlay && end > edge - 16 && edge - 16 > start ? edge - 16 : end";
|
|
25
|
+
/** One element as {@link LAYOUT_JS} measures it. */
|
|
26
|
+
export interface RawElementLayout {
|
|
27
|
+
index: number;
|
|
28
|
+
tag: string;
|
|
29
|
+
element: string;
|
|
30
|
+
text: string;
|
|
31
|
+
context: string;
|
|
32
|
+
geometry: ElementGeometry;
|
|
33
|
+
/** The element on top at its visible center, and whether it paints nothing there */
|
|
34
|
+
cover: {
|
|
35
|
+
element: string;
|
|
36
|
+
transparent: boolean;
|
|
37
|
+
} | null;
|
|
38
|
+
computed: LayoutComputedStyle;
|
|
39
|
+
}
|
|
40
|
+
/** What {@link LAYOUT_JS} returns. */
|
|
41
|
+
export interface RawLayout {
|
|
42
|
+
/** Elements the selector matched */
|
|
43
|
+
count: number;
|
|
44
|
+
/** Set when at least one element was measured */
|
|
45
|
+
page?: PageLayout;
|
|
46
|
+
elements: RawElementLayout[];
|
|
47
|
+
/** Measured inside a cross-origin iframe: `page` and the coordinates are that frame's */
|
|
48
|
+
crossOriginFrame?: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Measure the elements a selector (or cached index) refers to.
|
|
52
|
+
*
|
|
53
|
+
* @param cdp - CDP connection
|
|
54
|
+
* @param params - Selector (and index) or backend node id
|
|
55
|
+
* @returns Layout report
|
|
56
|
+
* @throws CommandError (83) no match, (81) index out of range or invalid
|
|
57
|
+
* selector, (87) the cached element left the page
|
|
58
|
+
*/
|
|
59
|
+
export declare function inspectLayout(cdp: CDPConnection, params: DomLayoutCommand): Promise<LayoutResult>;
|
|
60
|
+
/**
|
|
61
|
+
* Turn page-side measurements into the layout report: rounded page and
|
|
62
|
+
* viewport coordinates, viewport position and text preview per element.
|
|
63
|
+
*
|
|
64
|
+
* @param raw - Measurements with at least one element
|
|
65
|
+
* @param params - Request (selector and index)
|
|
66
|
+
* @returns Layout report
|
|
67
|
+
*/
|
|
68
|
+
export declare function buildLayoutResult(raw: RawLayout & {
|
|
69
|
+
page: PageLayout;
|
|
70
|
+
}, params: Pick<DomLayoutCommand, 'selector' | 'index'>): LayoutResult;
|
|
71
|
+
//# sourceMappingURL=layout.d.ts.map
|