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.
Files changed (304) hide show
  1. package/README.md +7 -1
  2. package/dist/cdp/schema.d.ts +4 -1
  3. package/dist/cdp/schema.js +48 -7
  4. package/dist/commands/cdp.js +3 -2
  5. package/dist/commands/cleanup.d.ts +11 -0
  6. package/dist/commands/cleanup.js +161 -57
  7. package/dist/commands/console.d.ts +20 -1
  8. package/dist/commands/console.js +57 -17
  9. package/dist/commands/details.js +3 -2
  10. package/dist/commands/dom/DomElementResolver.d.ts +10 -3
  11. package/dist/commands/dom/DomElementResolver.js +35 -17
  12. package/dist/commands/dom/a11y.d.ts +10 -0
  13. package/dist/commands/dom/a11y.js +29 -6
  14. package/dist/commands/dom/eval.d.ts +3 -1
  15. package/dist/commands/dom/eval.js +29 -4
  16. package/dist/commands/dom/form.js +16 -62
  17. package/dist/commands/dom/formInteraction.js +189 -119
  18. package/dist/commands/dom/formSummary.d.ts +49 -0
  19. package/dist/commands/dom/formSummary.js +180 -0
  20. package/dist/commands/dom/frames.d.ts +2 -1
  21. package/dist/commands/dom/frames.js +17 -2
  22. package/dist/commands/dom/get.d.ts +6 -5
  23. package/dist/commands/dom/get.js +92 -82
  24. package/dist/commands/dom/helpers/index.d.ts +1 -1
  25. package/dist/commands/dom/helpers/index.js +1 -1
  26. package/dist/commands/dom/helpers/keyAttributes.d.ts +20 -0
  27. package/dist/commands/dom/helpers/keyAttributes.js +54 -0
  28. package/dist/commands/dom/helpers/query.d.ts +44 -17
  29. package/dist/commands/dom/helpers/query.js +300 -106
  30. package/dist/commands/dom/helpers/runElementCommand.d.ts +10 -2
  31. package/dist/commands/dom/helpers/runElementCommand.js +98 -30
  32. package/dist/commands/dom/helpers/screenshot.d.ts +4 -1
  33. package/dist/commands/dom/helpers/screenshot.js +239 -51
  34. package/dist/commands/dom/index.d.ts +4 -1
  35. package/dist/commands/dom/index.js +22 -7
  36. package/dist/commands/dom/inspect.d.ts +15 -0
  37. package/dist/commands/dom/inspect.js +82 -0
  38. package/dist/commands/dom/layout.d.ts +14 -0
  39. package/dist/commands/dom/layout.js +54 -0
  40. package/dist/commands/dom/listeners.d.ts +5 -1
  41. package/dist/commands/dom/listeners.js +15 -5
  42. package/dist/commands/dom/query.js +2 -3
  43. package/dist/commands/dom/screenshot.d.ts +12 -2
  44. package/dist/commands/dom/screenshot.js +27 -3
  45. package/dist/commands/dom/semanticUtils.d.ts +16 -10
  46. package/dist/commands/dom/semanticUtils.js +53 -16
  47. package/dist/commands/dom/wait.d.ts +13 -0
  48. package/dist/commands/dom/wait.js +83 -0
  49. package/dist/commands/helpJson.js +2 -2
  50. package/dist/commands/network/list.js +17 -13
  51. package/dist/commands/optionBehaviors.js +154 -21
  52. package/dist/commands/page.d.ts +3 -2
  53. package/dist/commands/page.js +100 -5
  54. package/dist/commands/peek.js +4 -11
  55. package/dist/commands/sessions.d.ts +8 -0
  56. package/dist/commands/sessions.js +19 -0
  57. package/dist/commands/shared/CommandRunner.js +4 -4
  58. package/dist/commands/shared/commonOptions.d.ts +4 -0
  59. package/dist/commands/shared/commonOptions.js +9 -0
  60. package/dist/commands/shared/dataFetcher.js +2 -2
  61. package/dist/commands/shared/followMode.d.ts +21 -1
  62. package/dist/commands/shared/followMode.js +29 -2
  63. package/dist/commands/shared/handleValidationError.d.ts +2 -2
  64. package/dist/commands/shared/handleValidationError.js +12 -3
  65. package/dist/commands/shared/optionTypes.d.ts +61 -5
  66. package/dist/commands/shared/startHelpers.d.ts +66 -0
  67. package/dist/commands/shared/startHelpers.js +103 -13
  68. package/dist/commands/shared/validation.d.ts +14 -2
  69. package/dist/commands/shared/validation.js +20 -3
  70. package/dist/commands/start.d.ts +63 -0
  71. package/dist/commands/start.js +115 -15
  72. package/dist/commands/status.js +29 -7
  73. package/dist/commands/stop.js +7 -6
  74. package/dist/commands/tail.js +4 -11
  75. package/dist/commands/types.d.ts +2 -0
  76. package/dist/commands.js +2 -0
  77. package/dist/connection/chromeIdentity.d.ts +65 -0
  78. package/dist/connection/chromeIdentity.js +143 -0
  79. package/dist/connection/launcher/profilePreferences.d.ts +47 -0
  80. package/dist/connection/launcher/profilePreferences.js +151 -0
  81. package/dist/connection/launcher.d.ts +21 -2
  82. package/dist/connection/launcher.js +42 -16
  83. package/dist/connection/portReservation.d.ts +14 -4
  84. package/dist/connection/portReservation.js +21 -6
  85. package/dist/connection/startupExit.d.ts +8 -0
  86. package/dist/connection/startupExit.js +15 -6
  87. package/dist/constants.d.ts +6 -2
  88. package/dist/constants.js +9 -2
  89. package/dist/daemon/SessionController.js +23 -7
  90. package/dist/daemon/errors.d.ts +1 -1
  91. package/dist/daemon/errors.js +1 -1
  92. package/dist/daemon/launcher.d.ts +10 -2
  93. package/dist/daemon/launcher.js +8 -7
  94. package/dist/daemon/server/SocketServer.js +1 -2
  95. package/dist/daemon/session/Session.d.ts +20 -0
  96. package/dist/daemon/session/Session.js +80 -9
  97. package/dist/daemon/session/chromeConnection.d.ts +9 -0
  98. package/dist/daemon/session/chromeConnection.js +45 -8
  99. package/dist/daemon/session/commandRegistry.d.ts +14 -1
  100. package/dist/daemon/session/commandRegistry.js +113 -67
  101. package/dist/daemon/session/interactions.d.ts +48 -9
  102. package/dist/daemon/session/interactions.js +46 -9
  103. package/dist/daemon/session/triggeredRequests.d.ts +67 -0
  104. package/dist/daemon/session/triggeredRequests.js +157 -0
  105. package/dist/daemon/session/types.d.ts +5 -1
  106. package/dist/daemon.js +10630 -3601
  107. package/dist/errors/messages.d.ts +456 -24
  108. package/dist/errors/messages.js +862 -67
  109. package/dist/index.js +6915 -3401
  110. package/dist/ipc/client.d.ts +21 -1
  111. package/dist/ipc/client.js +35 -3
  112. package/dist/ipc/protocol/commands.d.ts +145 -5
  113. package/dist/ipc/protocol/commands.js +4 -0
  114. package/dist/ipc/protocol/domTypes.d.ts +291 -7
  115. package/dist/ipc/protocol/inspectTypes.d.ts +388 -0
  116. package/dist/ipc/protocol/inspectTypes.js +10 -0
  117. package/dist/ipc/session/lifecycle.d.ts +8 -1
  118. package/dist/ipc/session/queries.d.ts +5 -1
  119. package/dist/ipc/session/types.d.ts +5 -0
  120. package/dist/ipc/transport/index.d.ts +2 -1
  121. package/dist/ipc/transport/index.js +2 -2
  122. package/dist/runtime/dom/actionEffects.d.ts +185 -0
  123. package/dist/runtime/dom/actionEffects.js +402 -0
  124. package/dist/runtime/dom/actionEffectsScripts.d.ts +90 -0
  125. package/dist/runtime/dom/actionEffectsScripts.js +426 -0
  126. package/dist/runtime/dom/elementGeometry.d.ts +170 -0
  127. package/dist/runtime/dom/elementGeometry.js +553 -0
  128. package/dist/runtime/dom/elementInfo.d.ts +103 -0
  129. package/dist/runtime/dom/elementInfo.js +256 -0
  130. package/dist/runtime/dom/evalHelpers.d.ts +51 -6
  131. package/dist/runtime/dom/evalHelpers.js +136 -26
  132. package/dist/runtime/dom/eventListeners.d.ts +2 -1
  133. package/dist/runtime/dom/eventListeners.js +184 -47
  134. package/dist/runtime/dom/formDiscovery.d.ts +1 -1
  135. package/dist/runtime/dom/formDiscovery.js +116 -16
  136. package/dist/runtime/dom/formFillHelpers/fill.d.ts +9 -0
  137. package/dist/runtime/dom/formFillHelpers/fill.js +178 -14
  138. package/dist/runtime/dom/formFillHelpers/index.d.ts +2 -2
  139. package/dist/runtime/dom/formFillHelpers/index.js +2 -2
  140. package/dist/runtime/dom/formFillHelpers/pressKey.js +14 -3
  141. package/dist/runtime/dom/formFillHelpers/scroll.d.ts +3 -0
  142. package/dist/runtime/dom/formFillHelpers/scroll.js +60 -18
  143. package/dist/runtime/dom/formFillHelpers/shared.d.ts +17 -0
  144. package/dist/runtime/dom/formFillHelpers/shared.js +25 -1
  145. package/dist/runtime/dom/formFillHelpers/stability.d.ts +20 -6
  146. package/dist/runtime/dom/formFillHelpers/stability.js +50 -19
  147. package/dist/runtime/dom/formSubmitHelpers.d.ts +3 -0
  148. package/dist/runtime/dom/formSubmitHelpers.js +89 -15
  149. package/dist/runtime/dom/frameLayout.d.ts +60 -0
  150. package/dist/runtime/dom/frameLayout.js +140 -0
  151. package/dist/runtime/dom/frameOrigin.d.ts +50 -0
  152. package/dist/runtime/dom/frameOrigin.js +62 -0
  153. package/dist/runtime/dom/frameScopedConnection.d.ts +92 -0
  154. package/dist/runtime/dom/frameScopedConnection.js +252 -0
  155. package/dist/runtime/dom/frameSelection.d.ts +12 -1
  156. package/dist/runtime/dom/frameSelection.js +22 -3
  157. package/dist/runtime/dom/frames.d.ts +61 -5
  158. package/dist/runtime/dom/frames.js +329 -75
  159. package/dist/runtime/dom/inspect.d.ts +28 -0
  160. package/dist/runtime/dom/inspect.js +557 -0
  161. package/dist/runtime/dom/inspectAllStyles.d.ts +62 -0
  162. package/dist/runtime/dom/inspectAllStyles.js +385 -0
  163. package/dist/runtime/dom/inspectCascade.d.ts +94 -0
  164. package/dist/runtime/dom/inspectCascade.js +371 -0
  165. package/dist/runtime/dom/inspectCascadeModel.d.ts +39 -0
  166. package/dist/runtime/dom/inspectCascadeModel.js +232 -0
  167. package/dist/runtime/dom/inspectHints.d.ts +62 -0
  168. package/dist/runtime/dom/inspectHints.js +305 -0
  169. package/dist/runtime/dom/inspectLayoutModel.d.ts +87 -0
  170. package/dist/runtime/dom/inspectLayoutModel.js +346 -0
  171. package/dist/runtime/dom/inspectModel.d.ts +74 -0
  172. package/dist/runtime/dom/inspectModel.js +184 -0
  173. package/dist/runtime/dom/inspectPaintModel.d.ts +157 -0
  174. package/dist/runtime/dom/inspectPaintModel.js +461 -0
  175. package/dist/runtime/dom/inspectRules.d.ts +37 -0
  176. package/dist/runtime/dom/inspectRules.js +101 -0
  177. package/dist/runtime/dom/inspectScripts.d.ts +132 -0
  178. package/dist/runtime/dom/inspectScripts.js +263 -0
  179. package/dist/runtime/dom/inspectTree.d.ts +40 -0
  180. package/dist/runtime/dom/inspectTree.js +134 -0
  181. package/dist/runtime/dom/inspectVariables.d.ts +33 -0
  182. package/dist/runtime/dom/inspectVariables.js +94 -0
  183. package/dist/runtime/dom/inspectWhyModel.d.ts +20 -0
  184. package/dist/runtime/dom/inspectWhyModel.js +134 -0
  185. package/dist/runtime/dom/layout.d.ts +71 -0
  186. package/dist/runtime/dom/layout.js +340 -0
  187. package/dist/runtime/dom/listenerPageScripts.d.ts +72 -0
  188. package/dist/runtime/dom/listenerPageScripts.js +365 -0
  189. package/dist/runtime/dom/listenerSummary.d.ts +136 -11
  190. package/dist/runtime/dom/listenerSummary.js +361 -22
  191. package/dist/runtime/dom/pageActivity.d.ts +41 -0
  192. package/dist/runtime/dom/pageActivity.js +123 -0
  193. package/dist/runtime/dom/reactEventHelpers.d.ts +63 -2
  194. package/dist/runtime/dom/reactEventHelpers.js +220 -41
  195. package/dist/runtime/dom/targetNode.d.ts +80 -27
  196. package/dist/runtime/dom/targetNode.js +249 -33
  197. package/dist/runtime/dom/wait.d.ts +25 -0
  198. package/dist/runtime/dom/wait.js +199 -0
  199. package/dist/runtime/dom/waitCondition.d.ts +71 -0
  200. package/dist/runtime/dom/waitCondition.js +75 -0
  201. package/dist/runtime/page/emulation.d.ts +71 -0
  202. package/dist/runtime/page/emulation.js +117 -0
  203. package/dist/runtime/page/loadingState.d.ts +36 -0
  204. package/dist/runtime/page/loadingState.js +86 -0
  205. package/dist/runtime/page/navigation.d.ts +46 -2
  206. package/dist/runtime/page/navigation.js +69 -33
  207. package/dist/session/QueryCacheManager.d.ts +11 -1
  208. package/dist/session/QueryCacheManager.js +25 -3
  209. package/dist/session/chromeOwners.d.ts +34 -0
  210. package/dist/session/chromeOwners.js +51 -0
  211. package/dist/session/cleanup/staleSession.d.ts +11 -1
  212. package/dist/session/cleanup/staleSession.js +17 -6
  213. package/dist/session/cleanup/userCommands.js +2 -4
  214. package/dist/session/metadata.d.ts +5 -1
  215. package/dist/session/metadata.js +2 -1
  216. package/dist/session/paths.d.ts +77 -3
  217. package/dist/session/paths.js +111 -5
  218. package/dist/session/port.d.ts +31 -7
  219. package/dist/session/port.js +50 -43
  220. package/dist/session/portClaims.d.ts +66 -0
  221. package/dist/session/portClaims.js +284 -0
  222. package/dist/session/sessionList.d.ts +58 -0
  223. package/dist/session/sessionList.js +199 -0
  224. package/dist/session/sessionName.d.ts +46 -0
  225. package/dist/session/sessionName.js +97 -0
  226. package/dist/telemetry/a11y.d.ts +18 -3
  227. package/dist/telemetry/a11y.js +170 -29
  228. package/dist/telemetry/console.d.ts +1 -0
  229. package/dist/telemetry/console.js +100 -5
  230. package/dist/telemetry/network.js +3 -1
  231. package/dist/telemetry/requestKinds.d.ts +32 -0
  232. package/dist/telemetry/requestKinds.js +61 -0
  233. package/dist/telemetry/requestState.d.ts +31 -0
  234. package/dist/telemetry/requestState.js +38 -0
  235. package/dist/types.d.ts +112 -3
  236. package/dist/ui/formatters/a11y.js +3 -0
  237. package/dist/ui/formatters/console/chronological.d.ts +8 -0
  238. package/dist/ui/formatters/console/chronological.js +17 -4
  239. package/dist/ui/formatters/console/json.js +3 -4
  240. package/dist/ui/formatters/console/shared.d.ts +12 -0
  241. package/dist/ui/formatters/console.d.ts +2 -2
  242. package/dist/ui/formatters/console.js +1 -1
  243. package/dist/ui/formatters/details.d.ts +8 -0
  244. package/dist/ui/formatters/details.js +61 -4
  245. package/dist/ui/formatters/dom.d.ts +27 -14
  246. package/dist/ui/formatters/dom.js +88 -59
  247. package/dist/ui/formatters/form.js +29 -18
  248. package/dist/ui/formatters/inspect.d.ts +39 -0
  249. package/dist/ui/formatters/inspect.js +596 -0
  250. package/dist/ui/formatters/keyAttributes.d.ts +19 -0
  251. package/dist/ui/formatters/keyAttributes.js +84 -0
  252. package/dist/ui/formatters/layout.d.ts +31 -0
  253. package/dist/ui/formatters/layout.js +53 -0
  254. package/dist/ui/formatters/listeners.d.ts +3 -2
  255. package/dist/ui/formatters/listeners.js +73 -9
  256. package/dist/ui/formatters/networkHeaders.d.ts +13 -0
  257. package/dist/ui/formatters/networkHeaders.js +36 -3
  258. package/dist/ui/formatters/networkList.d.ts +29 -1
  259. package/dist/ui/formatters/networkList.js +86 -20
  260. package/dist/ui/formatters/preview.js +2 -1
  261. package/dist/ui/formatters/requestStatus.d.ts +1 -17
  262. package/dist/ui/formatters/requestStatus.js +2 -30
  263. package/dist/ui/formatters/sessions.d.ts +12 -0
  264. package/dist/ui/formatters/sessions.js +40 -0
  265. package/dist/ui/formatters/status.d.ts +21 -2
  266. package/dist/ui/formatters/status.js +47 -10
  267. package/dist/ui/formatters/triggeredRequests.d.ts +36 -0
  268. package/dist/ui/formatters/triggeredRequests.js +65 -0
  269. package/dist/ui/formatting.d.ts +19 -0
  270. package/dist/ui/formatting.js +31 -36
  271. package/dist/ui/messages/chrome.d.ts +9 -0
  272. package/dist/ui/messages/chrome.js +17 -5
  273. package/dist/ui/messages/commands.d.ts +504 -14
  274. package/dist/ui/messages/commands.js +835 -21
  275. package/dist/ui/messages/consoleMessages.d.ts +10 -0
  276. package/dist/ui/messages/consoleMessages.js +17 -0
  277. package/dist/ui/messages/hints.js +2 -1
  278. package/dist/ui/messages/networkMessages.d.ts +14 -0
  279. package/dist/ui/messages/networkMessages.js +18 -0
  280. package/dist/ui/messages/preview.js +5 -4
  281. package/dist/ui/messages/session.d.ts +30 -21
  282. package/dist/ui/messages/session.js +48 -26
  283. package/dist/ui/messages/sessionCommand.d.ts +43 -0
  284. package/dist/ui/messages/sessionCommand.js +52 -0
  285. package/dist/utils/async.d.ts +17 -0
  286. package/dist/utils/async.js +36 -0
  287. package/dist/utils/color.d.ts +84 -0
  288. package/dist/utils/color.js +376 -0
  289. package/dist/utils/cssValues.d.ts +109 -0
  290. package/dist/utils/cssValues.js +236 -0
  291. package/dist/utils/http.d.ts +22 -1
  292. package/dist/utils/http.js +28 -9
  293. package/dist/utils/selectorFilters.d.ts +48 -8
  294. package/dist/utils/selectorFilters.js +296 -53
  295. package/dist/utils/shellDetection.d.ts +8 -2
  296. package/dist/utils/shellDetection.js +120 -33
  297. package/dist/utils/suggestions.d.ts +26 -0
  298. package/dist/utils/suggestions.js +73 -0
  299. package/dist/utils/taskMappings.js +10 -0
  300. package/dist/utils/url.d.ts +12 -2
  301. package/dist/utils/url.js +69 -7
  302. package/package.json +1 -1
  303. package/dist/ui/formatters/sessionFormatters.d.ts +0 -58
  304. package/dist/ui/formatters/sessionFormatters.js +0 -121
@@ -0,0 +1,236 @@
1
+ /**
2
+ * Normalization of computed CSS values for `bdg dom inspect`: px as numbers
3
+ * rounded to one decimal (no unit), colors as hex, 1-4 value shorthands,
4
+ * shadow layers, grid tracks with `repeat()`, transforms decomposed from the
5
+ * matrices Chrome computes, and the first font family.
6
+ */
7
+ import { hexColor, hexColorsIn } from './color.js';
8
+ /** px lengths inside a value */
9
+ const PX_IN_VALUE = /(-?\d*\.?\d+(?:e-?\d+)?)px\b/g;
10
+ /**
11
+ * Round to one decimal (and drop `-0`).
12
+ *
13
+ * @param value - Number
14
+ * @returns e.g. 12.5, 0
15
+ */
16
+ export function round1(value) {
17
+ const rounded = Math.round(value * 10) / 10;
18
+ return Object.is(rounded, -0) ? 0 : rounded;
19
+ }
20
+ /**
21
+ * A px value as a number.
22
+ *
23
+ * @param value - Computed value, e.g. `12.5px`
24
+ * @returns Rounded number, or undefined when the value is not a single px length
25
+ */
26
+ export function pxNumber(value) {
27
+ const match = /^(-?\d*\.?\d+(?:e-?\d+)?)px$/.exec((value ?? '').trim());
28
+ return match ? round1(Number(match[1])) : undefined;
29
+ }
30
+ /**
31
+ * A length as {@link CssLength}.
32
+ *
33
+ * @param value - Computed value
34
+ * @returns Number for px, else the value as text
35
+ */
36
+ export function cssLength(value) {
37
+ return pxNumber(value) ?? normalizeCssValue(value ?? '');
38
+ }
39
+ /**
40
+ * A computed value with px lengths as rounded unitless numbers and colors as
41
+ * hex, e.g. `rgba(0, 0, 0, 0.2) 0px 1.25px 2px` → `#00000033 0 1.3 2`.
42
+ *
43
+ * @param value - Computed value
44
+ * @returns Normalized value
45
+ */
46
+ export function normalizeCssValue(value) {
47
+ return hexColorsIn(value)
48
+ .replace(PX_IN_VALUE, (_match, number) => String(round1(Number(number))))
49
+ .replace(/\s+/g, ' ')
50
+ .trim();
51
+ }
52
+ /**
53
+ * 1-4 values the way CSS shorthands write them (top, right, bottom, left).
54
+ *
55
+ * @param sides - Top, right, bottom, left
56
+ * @returns e.g. `10`, `10 0`, `10 0 1`, `1 2 3 4`
57
+ */
58
+ export function sidesShorthand(sides) {
59
+ const [top, right, bottom, left] = sides.map(String);
60
+ if (top === right && right === bottom && bottom === left)
61
+ return `${top}`;
62
+ if (top === bottom && right === left)
63
+ return `${top} ${right}`;
64
+ if (right === left)
65
+ return `${top} ${right} ${bottom}`;
66
+ return `${top} ${right} ${bottom} ${left}`;
67
+ }
68
+ /**
69
+ * Split a value at commas (or another separator) outside parentheses.
70
+ *
71
+ * @param value - e.g. `rgb(0, 0, 0) 0px 1px, rgb(1, 1, 1) 0px 2px`
72
+ * @param separator - Character to split at
73
+ * @returns Parts, trimmed
74
+ */
75
+ export function splitTopLevel(value, separator = ',') {
76
+ const parts = [];
77
+ let depth = 0;
78
+ let current = '';
79
+ for (const char of value) {
80
+ if (char === '(' || char === '[')
81
+ depth++;
82
+ if (char === ')' || char === ']')
83
+ depth--;
84
+ if (char === separator && depth === 0) {
85
+ parts.push(current.trim());
86
+ current = '';
87
+ }
88
+ else {
89
+ current += char;
90
+ }
91
+ }
92
+ if (current.trim())
93
+ parts.push(current.trim());
94
+ return parts;
95
+ }
96
+ /**
97
+ * The first family of a `font-family` list, without quotes.
98
+ *
99
+ * @param fontFamily - e.g. `"DM Sans", Arial, sans-serif`
100
+ * @returns e.g. `DM Sans`
101
+ */
102
+ export function firstFontFamily(fontFamily) {
103
+ const first = splitTopLevel(fontFamily)[0] ?? '';
104
+ return first.replace(/^["']|["']$/g, '');
105
+ }
106
+ /**
107
+ * Parse one shadow layer as Chrome computes it (`<color> <x> <y> <blur> [<spread>] [inset]`).
108
+ *
109
+ * @param layer - e.g. `rgba(0, 0, 0, 0.2) 0px 1px 2px 0px`
110
+ * @returns The layer, or undefined when it does not parse
111
+ */
112
+ function parseShadowLayer(layer) {
113
+ const color = /^((?:rgba?|lab|lch|oklab|oklch|color)\([^()]*\)|#[0-9a-f]{3,8}|[a-z]+)\s+/i.exec(layer);
114
+ const rest = (color ? layer.slice(color[0].length) : layer).split(/\s+/);
115
+ const lengths = rest.map(pxNumber).filter((n) => n !== undefined);
116
+ if (lengths.length < 2)
117
+ return undefined;
118
+ return {
119
+ x: lengths[0] ?? 0,
120
+ y: lengths[1] ?? 0,
121
+ blur: lengths[2] ?? 0,
122
+ spread: lengths[3] ?? 0,
123
+ color: hexColor(color?.[1] ?? 'currentcolor'),
124
+ inset: rest.includes('inset'),
125
+ };
126
+ }
127
+ /**
128
+ * The visible layers of a shadow: transparent layers and layers with no
129
+ * offset, blur or spread (Tailwind's ring placeholders) are left out.
130
+ *
131
+ * @param value - Computed `box-shadow` or `text-shadow`
132
+ * @returns Layers, outermost first
133
+ */
134
+ export function parseShadows(value) {
135
+ if (!value || value === 'none')
136
+ return [];
137
+ return splitTopLevel(value)
138
+ .map(parseShadowLayer)
139
+ .filter((layer) => layer !== undefined)
140
+ .filter((layer) => layer.color !== 'transparent' &&
141
+ (layer.x !== 0 || layer.y !== 0 || layer.blur !== 0 || layer.spread !== 0));
142
+ }
143
+ /**
144
+ * A shadow layer as text, e.g. `#00000033 0 1 2 0`, `inset #000 0 0 0 1`.
145
+ *
146
+ * @param layer - Shadow layer
147
+ * @param withSpread - Include the spread (box shadows)
148
+ * @returns Text
149
+ */
150
+ export function shadowText(layer, withSpread = true) {
151
+ const lengths = [layer.x, layer.y, layer.blur, ...(withSpread ? [layer.spread] : [])];
152
+ return `${layer.inset ? 'inset ' : ''}${layer.color} ${lengths.join(' ')}`;
153
+ }
154
+ /**
155
+ * Grid tracks with runs of equal sizes written as `repeat()`.
156
+ *
157
+ * @param value - Computed `grid-template-columns`/`rows`, e.g. `100px 100px 100px 50px`
158
+ * @returns e.g. `repeat(3,100) 50`; `none` stays `none`
159
+ */
160
+ export function compressTracks(value) {
161
+ if (!value || value === 'none')
162
+ return value;
163
+ const tracks = splitTopLevel(value, ' ').map((token) => normalizeCssValue(token));
164
+ const parts = [];
165
+ for (let i = 0; i < tracks.length;) {
166
+ let run = 1;
167
+ while (tracks[i + run] === tracks[i])
168
+ run++;
169
+ parts.push(run > 1 ? `repeat(${run},${tracks[i]})` : `${tracks[i]}`);
170
+ i += run;
171
+ }
172
+ return parts.join(' ');
173
+ }
174
+ /**
175
+ * Round a number for a transform (3 decimals at most).
176
+ *
177
+ * @param value - Number
178
+ * @returns Rounded number
179
+ */
180
+ function round3(value) {
181
+ const rounded = Math.round(value * 1000) / 1000;
182
+ return Object.is(rounded, -0) ? 0 : rounded;
183
+ }
184
+ /**
185
+ * A 2D matrix as translate/rotate/scale when it is one (no skew).
186
+ *
187
+ * @param m - a, b, c, d, e, f
188
+ * @returns e.g. `translate(10,20) rotate(45deg)`, or undefined for a skew
189
+ */
190
+ function decomposeMatrix([a = 1, b = 0, c = 0, d = 1, e = 0, f = 0]) {
191
+ if (Math.abs(a * c + b * d) > 1e-6)
192
+ return undefined;
193
+ const scaleX = Math.hypot(a, b);
194
+ const scaleY = scaleX === 0 ? 0 : (a * d - b * c) / scaleX;
195
+ const angle = round3((Math.atan2(b, a) * 180) / Math.PI);
196
+ const parts = [];
197
+ if (e !== 0 || f !== 0)
198
+ parts.push(`translate(${round1(e)},${round1(f)})`);
199
+ if (angle !== 0)
200
+ parts.push(`rotate(${angle}deg)`);
201
+ const [sx, sy] = [round3(scaleX), round3(scaleY)];
202
+ if (sx !== 1 || sy !== 1)
203
+ parts.push(sx === sy ? `scale(${sx})` : `scale(${sx},${sy})`);
204
+ return parts.length > 0 ? parts.join(' ') : 'none';
205
+ }
206
+ /**
207
+ * A computed transform in readable form: a 2D matrix as
208
+ * translate/rotate/scale, other matrices with rounded numbers.
209
+ *
210
+ * @param value - Computed `transform`, e.g. `matrix(1, 0, 0, 1, 10, 20)`
211
+ * @returns e.g. `translate(10,20)`; `none` when it does nothing
212
+ */
213
+ export function readableTransform(value) {
214
+ const match = /^(matrix|matrix3d)\((.*)\)$/.exec(value.trim());
215
+ if (!match)
216
+ return normalizeCssValue(value);
217
+ const numbers = (match[2] ?? '').split(',').map((n) => Number(n.trim()));
218
+ const decomposed = match[1] === 'matrix' ? decomposeMatrix(numbers) : undefined;
219
+ return decomposed ?? `${match[1]}(${numbers.map(round3).join(',')})`;
220
+ }
221
+ /**
222
+ * The file name of a URL in a CSS value: `url("https://x.com/a/b.png?v=1")` → `url(b.png)`;
223
+ * `data:` URLs become `url(data:…)`.
224
+ *
225
+ * @param value - Computed value with `url()`s
226
+ * @returns The value with short URLs
227
+ */
228
+ export function shortUrls(value) {
229
+ return value.replace(/url\((["']?)(.*?)\1\)/g, (_match, _quote, url) => {
230
+ if (url.startsWith('data:'))
231
+ return 'url(data:…)';
232
+ const name = url.split(/[?#]/)[0]?.split('/').filter(Boolean).pop() ?? url;
233
+ return `url(${name})`;
234
+ });
235
+ }
236
+ //# sourceMappingURL=cssValues.js.map
@@ -30,13 +30,34 @@ export interface FetchCDPTargetsOptions {
30
30
  * - Network errors are logged to help diagnose Chrome connectivity issues
31
31
  */
32
32
  export declare function fetchCDPTargets(port?: number, logger?: Logger, options?: FetchCDPTargetsOptions): Promise<CDPTarget[]>;
33
+ /**
34
+ * What answers on a DevTools HTTP endpoint: a Chrome (with its browser-level
35
+ * WebSocket URL), an HTTP server that is not DevTools, or nothing.
36
+ */
37
+ export type DevToolsProbe = {
38
+ kind: 'devtools';
39
+ wsUrl: string;
40
+ } | {
41
+ kind: 'not-devtools';
42
+ } | {
43
+ kind: 'unreachable';
44
+ };
45
+ /**
46
+ * Ask an endpoint for its DevTools version (`/json/version`).
47
+ *
48
+ * @param port - Chrome debugging port
49
+ * @param logger - Optional logger for debug output
50
+ * @param options - Host and HTTPS
51
+ * @returns What answered
52
+ */
53
+ export declare function probeDevToolsEndpoint(port: number, logger?: Logger, options?: Pick<FetchCDPTargetsOptions, 'host' | 'secure'>): Promise<DevToolsProbe>;
33
54
  /**
34
55
  * The browser-level DevTools WebSocket URL of a Chrome (`/json/version`).
35
56
  *
36
57
  * @param port - Chrome debugging port
37
58
  * @param logger - Optional logger for debug output
38
59
  * @param options - Host and HTTPS
39
- * @returns The URL, or null if Chrome could not be reached
60
+ * @returns The URL, or null if no Chrome answered
40
61
  */
41
62
  export declare function fetchBrowserWsUrl(port: number, logger?: Logger, options?: Pick<FetchCDPTargetsOptions, 'host' | 'secure'>): Promise<string | null>;
42
63
  /**
@@ -63,26 +63,45 @@ export async function fetchCDPTargets(port = DEFAULT_CDP_PORT, logger, options)
63
63
  }
64
64
  }
65
65
  /**
66
- * The browser-level DevTools WebSocket URL of a Chrome (`/json/version`).
66
+ * Ask an endpoint for its DevTools version (`/json/version`).
67
67
  *
68
68
  * @param port - Chrome debugging port
69
69
  * @param logger - Optional logger for debug output
70
70
  * @param options - Host and HTTPS
71
- * @returns The URL, or null if Chrome could not be reached
71
+ * @returns What answered
72
72
  */
73
- export async function fetchBrowserWsUrl(port, logger, options) {
73
+ export async function probeDevToolsEndpoint(port, logger, options) {
74
74
  const url = `${options?.secure ? 'https' : 'http'}://${options?.host ?? HTTP_LOCALHOST}:${port}/json/version`;
75
+ let response;
75
76
  try {
76
- const response = await fetch(url, { signal: AbortSignal.timeout(CDP_HTTP_TIMEOUT_MS) });
77
- if (!response.ok)
78
- return null;
79
- const data = (await response.json());
80
- return typeof data.webSocketDebuggerUrl === 'string' ? data.webSocketDebuggerUrl : null;
77
+ response = await fetch(url, { signal: AbortSignal.timeout(CDP_HTTP_TIMEOUT_MS) });
81
78
  }
82
79
  catch (error) {
83
80
  logger?.debug(`Chrome version request failed: ${getErrorMessage(error)} (${url})`);
84
- return null;
81
+ return { kind: 'unreachable' };
82
+ }
83
+ try {
84
+ const data = (await response.json());
85
+ const wsUrl = data?.webSocketDebuggerUrl;
86
+ if (response.ok && typeof wsUrl === 'string')
87
+ return { kind: 'devtools', wsUrl };
88
+ }
89
+ catch (error) {
90
+ logger?.debug(`Chrome version response is not JSON: ${getErrorMessage(error)} (${url})`);
85
91
  }
92
+ return { kind: 'not-devtools' };
93
+ }
94
+ /**
95
+ * The browser-level DevTools WebSocket URL of a Chrome (`/json/version`).
96
+ *
97
+ * @param port - Chrome debugging port
98
+ * @param logger - Optional logger for debug output
99
+ * @param options - Host and HTTPS
100
+ * @returns The URL, or null if no Chrome answered
101
+ */
102
+ export async function fetchBrowserWsUrl(port, logger, options) {
103
+ const probe = await probeDevToolsEndpoint(port, logger, options);
104
+ return probe.kind === 'devtools' ? probe.wsUrl : null;
86
105
  }
87
106
  /**
88
107
  * Fetch specific CDP target by ID from Chrome's HTTP API.
@@ -3,12 +3,16 @@
3
3
  * `:visible`.
4
4
  *
5
5
  * They are not CSS, so the selector is split here (in Node) into the CSS the
6
- * browser runs and the filters the page applies to its matches. They are only
7
- * supported at the end of the last compound of each selector in a list
8
- * (`li.item:has-text("x"):visible`, `a:text-is("Home"), button:visible`):
9
- * there they narrow down the elements the CSS part matched. Anywhere else
10
- * (`div:has-text("x") > button`, `:not(:visible)`) they would have to be
11
- * evaluated inside the browser's selector matching, which bdg cannot do.
6
+ * browser runs and the filters the page applies to its matches. A filter
7
+ * applies to the compound it is written in (`li.item:has-text("x"):visible`,
8
+ * `a:visible.active`). On the last compound it narrows down the matches; on an
9
+ * earlier one it scopes the rest of the selector, which is then matched under
10
+ * each element passing the filter: `li:has-text("Buy milk") .toggle` is the
11
+ * `.toggle` inside the row that says "Buy milk". Only descendant and child
12
+ * combinators can follow a filtered compound. Inside `:has()` filters test
13
+ * what an element contains (`li:has(label:text-is("x"))`); inside other
14
+ * pseudo-classes (`:not(:visible)`) they would have to be evaluated by the
15
+ * browser's selector matching, which bdg cannot do.
12
16
  */
13
17
  /** Filter applied in the page to the elements the CSS part matched. */
14
18
  export type SelectorFilter = {
@@ -19,11 +23,27 @@ export type SelectorFilter = {
19
23
  text: string;
20
24
  } | {
21
25
  kind: 'visible';
26
+ } | {
27
+ kind: 'has';
28
+ selectors: ScopedStep[][];
22
29
  };
23
- /** One selector of a selector list: the CSS to run and the filters for its matches. */
30
+ /** Combinators a scoped step can follow: descendant (` `) and child (`>`). */
31
+ export type ScopeCombinator = ' ' | '>';
32
+ /** CSS matched under a scope element (`:scope <combinator> <css>`), then filtered. */
33
+ export interface ScopedStep {
34
+ combinator: ScopeCombinator;
35
+ css: string;
36
+ filters: SelectorFilter[];
37
+ }
38
+ /**
39
+ * One selector of a selector list: the CSS to run and the filters for its
40
+ * matches; `steps` (when a filtered compound is not the last) are matched
41
+ * under each of them in turn, and the last step's matches are the result.
42
+ */
24
43
  export interface SelectorPart {
25
44
  css: string;
26
45
  filters: SelectorFilter[];
46
+ steps?: ScopedStep[];
27
47
  }
28
48
  /**
29
49
  * Split a selector into the CSS part and filters of each selector of its
@@ -31,9 +51,17 @@ export interface SelectorPart {
31
51
  *
32
52
  * @param selector - Selector as the user gave it
33
53
  * @returns The parts, or null for plain CSS (no filters anywhere), which runs unchanged
34
- * @throws CommandError (81) for a filter that is not at the end, or a malformed one
54
+ * @throws CommandError (81) for a misplaced or malformed filter
35
55
  */
36
56
  export declare function parseSelectorFilters(selector: string): SelectorPart[] | null;
57
+ /**
58
+ * The parts with every `:visible` filter removed, to count what only
59
+ * visibility excluded.
60
+ *
61
+ * @param parts - Parsed selector parts
62
+ * @returns Parts without `:visible`, or null when they have none
63
+ */
64
+ export declare function withoutVisibleFilters(parts: SelectorPart[]): SelectorPart[] | null;
37
65
  /**
38
66
  * Split a selector list at its top-level commas (not inside quotes,
39
67
  * attribute brackets or parentheses).
@@ -42,4 +70,16 @@ export declare function parseSelectorFilters(selector: string): SelectorPart[] |
42
70
  * @returns The selectors, untrimmed
43
71
  */
44
72
  export declare function splitSelectorList(selector: string): string[];
73
+ /**
74
+ * The compounds of a complex selector before its last one, with the rest
75
+ * after each (`mdn-search-modal form` gives `mdn-search-modal` with `form`):
76
+ * the ancestors a selector would have to cross shadow roots through.
77
+ *
78
+ * @param selector - One selector (a list gives nothing)
79
+ * @returns Leading compounds and the selector after each
80
+ */
81
+ export declare function leadingCompounds(selector: string): Array<{
82
+ compound: string;
83
+ rest: string;
84
+ }>;
45
85
  //# sourceMappingURL=selectorFilters.d.ts.map