@selenium/atoms 4.51.0 → 4.53.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 (392) hide show
  1. package/README.md +56 -0
  2. package/dist/index.d.ts +44 -0
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +42 -0
  5. package/dist/index.js.map +1 -1
  6. package/dist/typescript/accessibility-snapshot-wire.d.ts +4 -0
  7. package/dist/typescript/accessibility-snapshot-wire.d.ts.map +1 -0
  8. package/dist/typescript/accessibility-snapshot-wire.js +18 -0
  9. package/dist/typescript/accessibility-snapshot-wire.js.map +1 -0
  10. package/dist/typescript/accessibility-snapshot.d.ts +3 -0
  11. package/dist/typescript/accessibility-snapshot.d.ts.map +1 -0
  12. package/dist/typescript/accessibility-snapshot.js +18 -0
  13. package/dist/typescript/accessibility-snapshot.js.map +1 -0
  14. package/dist/typescript/active-element.d.ts +2 -0
  15. package/dist/typescript/active-element.d.ts.map +1 -0
  16. package/dist/typescript/active-element.js +19 -0
  17. package/dist/typescript/active-element.js.map +1 -0
  18. package/dist/typescript/clear-local-storage.d.ts +3 -0
  19. package/dist/typescript/clear-local-storage.d.ts.map +1 -0
  20. package/dist/typescript/clear-local-storage.js +25 -0
  21. package/dist/typescript/clear-local-storage.js.map +1 -0
  22. package/dist/typescript/clear-session-storage.d.ts +3 -0
  23. package/dist/typescript/clear-session-storage.d.ts.map +1 -0
  24. package/dist/typescript/clear-session-storage.js +25 -0
  25. package/dist/typescript/clear-session-storage.js.map +1 -0
  26. package/dist/typescript/clear.d.ts +3 -0
  27. package/dist/typescript/clear.d.ts.map +1 -0
  28. package/dist/typescript/clear.js +67 -0
  29. package/dist/typescript/clear.js.map +1 -0
  30. package/dist/typescript/click.d.ts +4 -0
  31. package/dist/typescript/click.d.ts.map +1 -0
  32. package/dist/typescript/click.js +52 -0
  33. package/dist/typescript/click.js.map +1 -0
  34. package/dist/typescript/core/accessibility/accname.d.ts +6 -0
  35. package/dist/typescript/core/accessibility/accname.d.ts.map +1 -0
  36. package/dist/typescript/core/accessibility/accname.js +537 -0
  37. package/dist/typescript/core/accessibility/accname.js.map +1 -0
  38. package/dist/typescript/core/accessibility/context.d.ts +43 -0
  39. package/dist/typescript/core/accessibility/context.d.ts.map +1 -0
  40. package/dist/typescript/core/accessibility/context.js +49 -0
  41. package/dist/typescript/core/accessibility/context.js.map +1 -0
  42. package/dist/typescript/core/accessibility/hidden.d.ts +39 -0
  43. package/dist/typescript/core/accessibility/hidden.d.ts.map +1 -0
  44. package/dist/typescript/core/accessibility/hidden.js +216 -0
  45. package/dist/typescript/core/accessibility/hidden.js.map +1 -0
  46. package/dist/typescript/core/accessibility/roles.d.ts +28 -0
  47. package/dist/typescript/core/accessibility/roles.d.ts.map +1 -0
  48. package/dist/typescript/core/accessibility/roles.js +381 -0
  49. package/dist/typescript/core/accessibility/roles.js.map +1 -0
  50. package/dist/typescript/core/accessibility/snapshot.d.ts +13 -0
  51. package/dist/typescript/core/accessibility/snapshot.d.ts.map +1 -0
  52. package/dist/typescript/core/accessibility/snapshot.js +55 -0
  53. package/dist/typescript/core/accessibility/snapshot.js.map +1 -0
  54. package/dist/typescript/core/accessibility/states.d.ts +18 -0
  55. package/dist/typescript/core/accessibility/states.d.ts.map +1 -0
  56. package/dist/typescript/core/accessibility/states.js +215 -0
  57. package/dist/typescript/core/accessibility/states.js.map +1 -0
  58. package/dist/typescript/core/accessibility/tree.d.ts +10 -0
  59. package/dist/typescript/core/accessibility/tree.d.ts.map +1 -0
  60. package/dist/typescript/core/accessibility/tree.js +261 -0
  61. package/dist/typescript/core/accessibility/tree.js.map +1 -0
  62. package/dist/typescript/core/accessibility/types.d.ts +30 -0
  63. package/dist/typescript/core/accessibility/types.d.ts.map +1 -0
  64. package/dist/typescript/core/accessibility/types.js +18 -0
  65. package/dist/typescript/core/accessibility/types.js.map +1 -0
  66. package/dist/typescript/core/accessibility/value.d.ts +4 -0
  67. package/dist/typescript/core/accessibility/value.d.ts.map +1 -0
  68. package/dist/typescript/core/accessibility/value.js +83 -0
  69. package/dist/typescript/core/accessibility/value.js.map +1 -0
  70. package/dist/typescript/core/accessibility/wire.d.ts +57 -0
  71. package/dist/typescript/core/accessibility/wire.d.ts.map +1 -0
  72. package/dist/typescript/core/accessibility/wire.js +72 -0
  73. package/dist/typescript/core/accessibility/wire.js.map +1 -0
  74. package/dist/typescript/core/attribute.d.ts +3 -0
  75. package/dist/typescript/core/attribute.d.ts.map +1 -0
  76. package/dist/typescript/core/attribute.js +60 -0
  77. package/dist/typescript/core/attribute.js.map +1 -0
  78. package/dist/typescript/core/color.d.ts +2 -0
  79. package/dist/typescript/core/color.d.ts.map +1 -0
  80. package/dist/typescript/core/color.js +248 -0
  81. package/dist/typescript/core/color.js.map +1 -0
  82. package/dist/typescript/core/editable.d.ts +5 -0
  83. package/dist/typescript/core/editable.d.ts.map +1 -0
  84. package/dist/typescript/core/editable.js +55 -0
  85. package/dist/typescript/core/editable.js.map +1 -0
  86. package/dist/typescript/core/element.d.ts +6 -0
  87. package/dist/typescript/core/element.d.ts.map +1 -0
  88. package/dist/typescript/core/element.js +97 -0
  89. package/dist/typescript/core/element.js.map +1 -0
  90. package/dist/typescript/core/enabled.d.ts +2 -0
  91. package/dist/typescript/core/enabled.d.ts.map +1 -0
  92. package/dist/typescript/core/enabled.js +69 -0
  93. package/dist/typescript/core/enabled.js.map +1 -0
  94. package/dist/typescript/core/error.d.ts +13 -0
  95. package/dist/typescript/core/error.d.ts.map +1 -0
  96. package/dist/typescript/core/error.js +40 -0
  97. package/dist/typescript/core/error.js.map +1 -0
  98. package/dist/typescript/core/events.d.ts +91 -0
  99. package/dist/typescript/core/events.d.ts.map +1 -0
  100. package/dist/typescript/core/events.js +131 -0
  101. package/dist/typescript/core/events.js.map +1 -0
  102. package/dist/typescript/core/focus.d.ts +4 -0
  103. package/dist/typescript/core/focus.d.ts.map +1 -0
  104. package/dist/typescript/core/focus.js +88 -0
  105. package/dist/typescript/core/focus.js.map +1 -0
  106. package/dist/typescript/core/focusable.d.ts +2 -0
  107. package/dist/typescript/core/focusable.d.ts.map +1 -0
  108. package/dist/typescript/core/focusable.js +36 -0
  109. package/dist/typescript/core/focusable.js.map +1 -0
  110. package/dist/typescript/core/form.d.ts +2 -0
  111. package/dist/typescript/core/form.d.ts.map +1 -0
  112. package/dist/typescript/core/form.js +76 -0
  113. package/dist/typescript/core/form.js.map +1 -0
  114. package/dist/typescript/core/frame.d.ts +8 -0
  115. package/dist/typescript/core/frame.d.ts.map +1 -0
  116. package/dist/typescript/core/frame.js +95 -0
  117. package/dist/typescript/core/frame.js.map +1 -0
  118. package/dist/typescript/core/geometry.d.ts +28 -0
  119. package/dist/typescript/core/geometry.d.ts.map +1 -0
  120. package/dist/typescript/core/geometry.js +134 -0
  121. package/dist/typescript/core/geometry.js.map +1 -0
  122. package/dist/typescript/core/inject.d.ts +21 -0
  123. package/dist/typescript/core/inject.d.ts.map +1 -0
  124. package/dist/typescript/core/inject.js +282 -0
  125. package/dist/typescript/core/inject.js.map +1 -0
  126. package/dist/typescript/core/interactable.d.ts +2 -0
  127. package/dist/typescript/core/interactable.d.ts.map +1 -0
  128. package/dist/typescript/core/interactable.js +27 -0
  129. package/dist/typescript/core/interactable.js.map +1 -0
  130. package/dist/typescript/core/keyboard.d.ts +15 -0
  131. package/dist/typescript/core/keyboard.d.ts.map +1 -0
  132. package/dist/typescript/core/keyboard.js +356 -0
  133. package/dist/typescript/core/keyboard.js.map +1 -0
  134. package/dist/typescript/core/keys.d.ts +65 -0
  135. package/dist/typescript/core/keys.d.ts.map +1 -0
  136. package/dist/typescript/core/keys.js +125 -0
  137. package/dist/typescript/core/keys.js.map +1 -0
  138. package/dist/typescript/core/locators.d.ts +6 -0
  139. package/dist/typescript/core/locators.d.ts.map +1 -0
  140. package/dist/typescript/core/locators.js +610 -0
  141. package/dist/typescript/core/locators.js.map +1 -0
  142. package/dist/typescript/core/mouse.d.ts +17 -0
  143. package/dist/typescript/core/mouse.d.ts.map +1 -0
  144. package/dist/typescript/core/mouse.js +186 -0
  145. package/dist/typescript/core/mouse.js.map +1 -0
  146. package/dist/typescript/core/overflow.d.ts +5 -0
  147. package/dist/typescript/core/overflow.d.ts.map +1 -0
  148. package/dist/typescript/core/overflow.js +133 -0
  149. package/dist/typescript/core/overflow.js.map +1 -0
  150. package/dist/typescript/core/scroll.d.ts +3 -0
  151. package/dist/typescript/core/scroll.d.ts.map +1 -0
  152. package/dist/typescript/core/scroll.js +77 -0
  153. package/dist/typescript/core/scroll.js.map +1 -0
  154. package/dist/typescript/core/shown.d.ts +3 -0
  155. package/dist/typescript/core/shown.d.ts.map +1 -0
  156. package/dist/typescript/core/shown.js +190 -0
  157. package/dist/typescript/core/shown.js.map +1 -0
  158. package/dist/typescript/core/storage.d.ts +14 -0
  159. package/dist/typescript/core/storage.d.ts.map +1 -0
  160. package/dist/typescript/core/storage.js +98 -0
  161. package/dist/typescript/core/storage.js.map +1 -0
  162. package/dist/typescript/core/style.d.ts +2 -0
  163. package/dist/typescript/core/style.d.ts.map +1 -0
  164. package/dist/typescript/core/style.js +32 -0
  165. package/dist/typescript/core/style.js.map +1 -0
  166. package/dist/typescript/core/useragent.d.ts +3 -0
  167. package/dist/typescript/core/useragent.d.ts.map +1 -0
  168. package/dist/typescript/core/useragent.js +31 -0
  169. package/dist/typescript/core/useragent.js.map +1 -0
  170. package/dist/typescript/default-content.d.ts +2 -0
  171. package/dist/typescript/default-content.d.ts.map +1 -0
  172. package/dist/typescript/default-content.js +20 -0
  173. package/dist/typescript/default-content.js.map +1 -0
  174. package/dist/typescript/execute-async-script.d.ts +2 -0
  175. package/dist/typescript/execute-async-script.d.ts.map +1 -0
  176. package/dist/typescript/execute-async-script.js +20 -0
  177. package/dist/typescript/execute-async-script.js.map +1 -0
  178. package/dist/typescript/execute-script.d.ts +2 -0
  179. package/dist/typescript/execute-script.d.ts.map +1 -0
  180. package/dist/typescript/execute-script.js +20 -0
  181. package/dist/typescript/execute-script.js.map +1 -0
  182. package/dist/typescript/find-element-fragment.d.ts +8 -0
  183. package/dist/typescript/find-element-fragment.d.ts.map +1 -0
  184. package/dist/typescript/find-element-fragment.js +39 -0
  185. package/dist/typescript/find-element-fragment.js.map +1 -0
  186. package/dist/typescript/find-element.d.ts +2 -0
  187. package/dist/typescript/find-element.d.ts.map +1 -0
  188. package/dist/typescript/find-element.js +18 -0
  189. package/dist/typescript/find-element.js.map +1 -0
  190. package/dist/typescript/find-elements.d.ts +1 -2
  191. package/dist/typescript/find-elements.d.ts.map +1 -1
  192. package/dist/typescript/find-elements.js +1 -289
  193. package/dist/typescript/find-elements.js.map +1 -1
  194. package/dist/typescript/frame-by-id-or-name.d.ts +2 -0
  195. package/dist/typescript/frame-by-id-or-name.d.ts.map +1 -0
  196. package/dist/typescript/frame-by-id-or-name.js +22 -0
  197. package/dist/typescript/frame-by-id-or-name.js.map +1 -0
  198. package/dist/typescript/frame-by-index.d.ts +2 -0
  199. package/dist/typescript/frame-by-index.d.ts.map +1 -0
  200. package/dist/typescript/frame-by-index.js +19 -0
  201. package/dist/typescript/frame-by-index.js.map +1 -0
  202. package/dist/typescript/get-attribute-value.d.ts +2 -0
  203. package/dist/typescript/get-attribute-value.d.ts.map +1 -0
  204. package/dist/typescript/get-attribute-value.js +22 -0
  205. package/dist/typescript/get-attribute-value.js.map +1 -0
  206. package/dist/typescript/get-effective-style.d.ts +3 -0
  207. package/dist/typescript/get-effective-style.d.ts.map +1 -0
  208. package/dist/typescript/get-effective-style.js +84 -0
  209. package/dist/typescript/get-effective-style.js.map +1 -0
  210. package/dist/typescript/get-element-from-cache.d.ts +2 -0
  211. package/dist/typescript/get-element-from-cache.d.ts.map +1 -0
  212. package/dist/typescript/get-element-from-cache.js +20 -0
  213. package/dist/typescript/get-element-from-cache.js.map +1 -0
  214. package/dist/typescript/get-frame-window.d.ts +2 -0
  215. package/dist/typescript/get-frame-window.d.ts.map +1 -0
  216. package/dist/typescript/get-frame-window.js +22 -0
  217. package/dist/typescript/get-frame-window.js.map +1 -0
  218. package/dist/typescript/get-local-storage-item.d.ts +3 -0
  219. package/dist/typescript/get-local-storage-item.d.ts.map +1 -0
  220. package/dist/typescript/get-local-storage-item.js +25 -0
  221. package/dist/typescript/get-local-storage-item.js.map +1 -0
  222. package/dist/typescript/get-local-storage-key.d.ts +3 -0
  223. package/dist/typescript/get-local-storage-key.d.ts.map +1 -0
  224. package/dist/typescript/get-local-storage-key.js +26 -0
  225. package/dist/typescript/get-local-storage-key.js.map +1 -0
  226. package/dist/typescript/get-local-storage-keys.d.ts +3 -0
  227. package/dist/typescript/get-local-storage-keys.d.ts.map +1 -0
  228. package/dist/typescript/get-local-storage-keys.js +25 -0
  229. package/dist/typescript/get-local-storage-keys.js.map +1 -0
  230. package/dist/typescript/get-local-storage-size.d.ts +3 -0
  231. package/dist/typescript/get-local-storage-size.d.ts.map +1 -0
  232. package/dist/typescript/get-local-storage-size.js +25 -0
  233. package/dist/typescript/get-local-storage-size.js.map +1 -0
  234. package/dist/typescript/get-location.d.ts +9 -0
  235. package/dist/typescript/get-location.d.ts.map +1 -0
  236. package/dist/typescript/get-location.js +49 -0
  237. package/dist/typescript/get-location.js.map +1 -0
  238. package/dist/typescript/get-session-storage-item.d.ts +3 -0
  239. package/dist/typescript/get-session-storage-item.d.ts.map +1 -0
  240. package/dist/typescript/get-session-storage-item.js +25 -0
  241. package/dist/typescript/get-session-storage-item.js.map +1 -0
  242. package/dist/typescript/get-session-storage-key.d.ts +3 -0
  243. package/dist/typescript/get-session-storage-key.d.ts.map +1 -0
  244. package/dist/typescript/get-session-storage-key.js +26 -0
  245. package/dist/typescript/get-session-storage-key.js.map +1 -0
  246. package/dist/typescript/get-session-storage-keys.d.ts +3 -0
  247. package/dist/typescript/get-session-storage-keys.d.ts.map +1 -0
  248. package/dist/typescript/get-session-storage-keys.js +25 -0
  249. package/dist/typescript/get-session-storage-keys.js.map +1 -0
  250. package/dist/typescript/get-session-storage-size.d.ts +3 -0
  251. package/dist/typescript/get-session-storage-size.d.ts.map +1 -0
  252. package/dist/typescript/get-session-storage-size.js +25 -0
  253. package/dist/typescript/get-session-storage-size.js.map +1 -0
  254. package/dist/typescript/get-size.d.ts +7 -0
  255. package/dist/typescript/get-size.d.ts.map +1 -0
  256. package/dist/typescript/get-size.js +36 -0
  257. package/dist/typescript/get-size.js.map +1 -0
  258. package/dist/typescript/get-text.d.ts +3 -0
  259. package/dist/typescript/get-text.d.ts.map +1 -0
  260. package/dist/typescript/get-text.js +294 -0
  261. package/dist/typescript/get-text.js.map +1 -0
  262. package/dist/typescript/get-top-left-coordinates.d.ts +4 -0
  263. package/dist/typescript/get-top-left-coordinates.d.ts.map +1 -0
  264. package/dist/typescript/get-top-left-coordinates.js +36 -0
  265. package/dist/typescript/get-top-left-coordinates.js.map +1 -0
  266. package/dist/typescript/is-displayed.d.ts +1 -2
  267. package/dist/typescript/is-displayed.d.ts.map +1 -1
  268. package/dist/typescript/is-displayed.js +3 -396
  269. package/dist/typescript/is-displayed.js.map +1 -1
  270. package/dist/typescript/is-editable.d.ts +2 -0
  271. package/dist/typescript/is-editable.d.ts.map +1 -0
  272. package/dist/typescript/is-editable.js +18 -0
  273. package/dist/typescript/is-editable.js.map +1 -0
  274. package/dist/typescript/is-enabled.d.ts +2 -0
  275. package/dist/typescript/is-enabled.d.ts.map +1 -0
  276. package/dist/typescript/is-enabled.js +18 -0
  277. package/dist/typescript/is-enabled.js.map +1 -0
  278. package/dist/typescript/is-focusable.d.ts +2 -0
  279. package/dist/typescript/is-focusable.d.ts.map +1 -0
  280. package/dist/typescript/is-focusable.js +20 -0
  281. package/dist/typescript/is-focusable.js.map +1 -0
  282. package/dist/typescript/is-interactable.d.ts +2 -0
  283. package/dist/typescript/is-interactable.d.ts.map +1 -0
  284. package/dist/typescript/is-interactable.js +19 -0
  285. package/dist/typescript/is-interactable.js.map +1 -0
  286. package/dist/typescript/is-selected.d.ts +3 -0
  287. package/dist/typescript/is-selected.d.ts.map +1 -0
  288. package/dist/typescript/is-selected.js +29 -0
  289. package/dist/typescript/is-selected.js.map +1 -0
  290. package/dist/typescript/remove-local-storage-item.d.ts +3 -0
  291. package/dist/typescript/remove-local-storage-item.d.ts.map +1 -0
  292. package/dist/typescript/remove-local-storage-item.js +25 -0
  293. package/dist/typescript/remove-local-storage-item.js.map +1 -0
  294. package/dist/typescript/remove-session-storage-item.d.ts +3 -0
  295. package/dist/typescript/remove-session-storage-item.d.ts.map +1 -0
  296. package/dist/typescript/remove-session-storage-item.js +25 -0
  297. package/dist/typescript/remove-session-storage-item.js.map +1 -0
  298. package/dist/typescript/set-local-storage-item.d.ts +3 -0
  299. package/dist/typescript/set-local-storage-item.d.ts.map +1 -0
  300. package/dist/typescript/set-local-storage-item.js +26 -0
  301. package/dist/typescript/set-local-storage-item.js.map +1 -0
  302. package/dist/typescript/set-session-storage-item.d.ts +3 -0
  303. package/dist/typescript/set-session-storage-item.d.ts.map +1 -0
  304. package/dist/typescript/set-session-storage-item.js +26 -0
  305. package/dist/typescript/set-session-storage-item.js.map +1 -0
  306. package/dist/typescript/submit.d.ts +3 -0
  307. package/dist/typescript/submit.d.ts.map +1 -0
  308. package/dist/typescript/submit.js +50 -0
  309. package/dist/typescript/submit.js.map +1 -0
  310. package/dist/typescript/type.d.ts +3 -0
  311. package/dist/typescript/type.d.ts.map +1 -0
  312. package/dist/typescript/type.js +201 -0
  313. package/dist/typescript/type.js.map +1 -0
  314. package/index.ts +44 -0
  315. package/package.json +306 -5
  316. package/typescript/accessibility-snapshot-wire.ts +20 -0
  317. package/typescript/accessibility-snapshot.ts +21 -0
  318. package/typescript/active-element.ts +19 -0
  319. package/typescript/clear-local-storage.ts +27 -0
  320. package/typescript/clear-session-storage.ts +27 -0
  321. package/typescript/clear.ts +73 -0
  322. package/typescript/click.ts +55 -0
  323. package/typescript/core/accessibility/accname.ts +587 -0
  324. package/typescript/core/accessibility/context.ts +116 -0
  325. package/typescript/core/accessibility/hidden.ts +242 -0
  326. package/typescript/core/accessibility/roles.ts +410 -0
  327. package/typescript/core/accessibility/snapshot.ts +61 -0
  328. package/typescript/core/accessibility/states.ts +233 -0
  329. package/typescript/core/accessibility/tree.ts +306 -0
  330. package/typescript/core/accessibility/types.ts +52 -0
  331. package/typescript/core/accessibility/value.ts +89 -0
  332. package/typescript/core/accessibility/wire.ts +123 -0
  333. package/typescript/core/attribute.ts +68 -0
  334. package/typescript/core/color.ts +257 -0
  335. package/typescript/core/editable.ts +63 -0
  336. package/typescript/core/element.ts +110 -0
  337. package/typescript/core/enabled.ts +76 -0
  338. package/typescript/core/error.ts +41 -0
  339. package/typescript/core/events.ts +268 -0
  340. package/typescript/core/focus.ts +92 -0
  341. package/typescript/core/focusable.ts +38 -0
  342. package/typescript/core/form.ts +81 -0
  343. package/typescript/core/frame.ts +105 -0
  344. package/typescript/core/geometry.ts +183 -0
  345. package/typescript/core/inject.ts +336 -0
  346. package/typescript/core/interactable.ts +30 -0
  347. package/typescript/core/keyboard.ts +369 -0
  348. package/typescript/core/keys.ts +204 -0
  349. package/typescript/core/locators.ts +704 -0
  350. package/typescript/core/mouse.ts +211 -0
  351. package/typescript/core/overflow.ts +172 -0
  352. package/typescript/core/scroll.ts +92 -0
  353. package/typescript/core/shown.ts +233 -0
  354. package/typescript/core/storage.ts +111 -0
  355. package/typescript/core/style.ts +32 -0
  356. package/typescript/core/useragent.ts +33 -0
  357. package/typescript/default-content.ts +20 -0
  358. package/typescript/execute-async-script.ts +20 -0
  359. package/typescript/execute-script.ts +20 -0
  360. package/typescript/find-element-fragment.ts +45 -0
  361. package/typescript/find-element.ts +18 -0
  362. package/typescript/find-elements.ts +1 -326
  363. package/typescript/frame-by-id-or-name.ts +22 -0
  364. package/typescript/frame-by-index.ts +19 -0
  365. package/typescript/get-attribute-value.ts +22 -0
  366. package/typescript/get-effective-style.ts +93 -0
  367. package/typescript/get-element-from-cache.ts +20 -0
  368. package/typescript/get-frame-window.ts +22 -0
  369. package/typescript/get-local-storage-item.ts +27 -0
  370. package/typescript/get-local-storage-key.ts +28 -0
  371. package/typescript/get-local-storage-keys.ts +27 -0
  372. package/typescript/get-local-storage-size.ts +27 -0
  373. package/typescript/get-location.ts +63 -0
  374. package/typescript/get-session-storage-item.ts +27 -0
  375. package/typescript/get-session-storage-key.ts +28 -0
  376. package/typescript/get-session-storage-keys.ts +27 -0
  377. package/typescript/get-session-storage-size.ts +27 -0
  378. package/typescript/get-size.ts +43 -0
  379. package/typescript/get-text.ts +353 -0
  380. package/typescript/get-top-left-coordinates.ts +38 -0
  381. package/typescript/is-displayed.ts +3 -498
  382. package/typescript/is-editable.ts +18 -0
  383. package/typescript/is-enabled.ts +18 -0
  384. package/typescript/is-focusable.ts +20 -0
  385. package/typescript/is-interactable.ts +19 -0
  386. package/typescript/is-selected.ts +31 -0
  387. package/typescript/remove-local-storage-item.ts +27 -0
  388. package/typescript/remove-session-storage-item.ts +27 -0
  389. package/typescript/set-local-storage-item.ts +28 -0
  390. package/typescript/set-session-storage-item.ts +28 -0
  391. package/typescript/submit.ts +53 -0
  392. package/typescript/type.ts +210 -0
@@ -0,0 +1,369 @@
1
+ // Licensed to the Software Freedom Conservancy (SFC) under one
2
+ // or more contributor license agreements. See the NOTICE file
3
+ // distributed with this work for additional information
4
+ // regarding copyright ownership. The SFC licenses this file
5
+ // to you under the Apache License, Version 2.0 (the
6
+ // "License"); you may not use this file except in compliance
7
+ // with the License. You may obtain a copy of the License at
8
+ //
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
+ //
11
+ // Unless required by applicable law or agreed to in writing,
12
+ // software distributed under the License is distributed on an
13
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ // KIND, either express or implied. See the License for the
15
+ // specific language governing permissions and limitations
16
+ // under the License.
17
+
18
+ import { isContentEditable, isEditable, isFileInput } from './editable.js'
19
+ import { isElement } from './element.js'
20
+ import { UNKNOWN_ERROR, botError } from './error.js'
21
+ import { type EventFactory, EventType, type KeyboardArgs, fire } from './events.js'
22
+ import { focusOnElement, getActiveElementFrom, holdsFocus } from './focus.js'
23
+ import { implicitlySubmit } from './form.js'
24
+ import { type Key, Keys, isModifier, keyCodeFor } from './keys.js'
25
+
26
+ // A virtual keyboard that produces what a real key press produces: keydown,
27
+ // keypress for character keys and Enter, beforeinput / textInput / input
28
+ // around the edit, and keyup -- each with key, code and the engine's legacy
29
+ // codes -- and that performs the edit itself, since an untrusted key event has
30
+ // no default action.
31
+ //
32
+ // Replaces bot.Keyboard. Differences, all toward what a real keyboard does:
33
+ // - Events go to whichever element has focus when the key is pressed, so a
34
+ // page that moves focus from a handler (one-time-code fields, auto-advance)
35
+ // keeps receiving the typing where a user's would go. bot.Keyboard always
36
+ // typed into the element it started with.
37
+ // - beforeinput is fired, with inputType and data, and cancelling it cancels
38
+ // the edit; so does cancelling textInput.
39
+ // - contenteditable is edited. bot.Keyboard appended to an expando `value`
40
+ // there and never changed the DOM.
41
+ // - maxlength is respected, and a character outside the BMP is one key.
42
+ // - No keypress for Escape, arrows or Meta: Firefox stopped firing those.
43
+ // - Caret movement uses the element's own selection direction instead of a
44
+ // tracked position, and there is no serialisable state: none of the atoms
45
+ // that use the keyboard carry one across calls.
46
+ export class Keyboard {
47
+ private element: Element | null = null
48
+ private readonly pressed = new Set<Key>()
49
+
50
+ isPressed(key: Key): boolean {
51
+ return this.pressed.has(key)
52
+ }
53
+
54
+ // Focuses the element, as clicking into it would, and when that moved focus
55
+ // puts the caret at the end of its text. A shadow host whose tree already
56
+ // holds focus is left alone: focusing the host itself would blur the field
57
+ // inside it that the keys are meant for.
58
+ moveCursor(element: Element): void {
59
+ this.element = element
60
+ if (!holdsFocus(element) && focusOnElement(element) && isEditable(element)) {
61
+ caretToEnd(element)
62
+ }
63
+ }
64
+
65
+ pressKey(key: Key): void {
66
+ if (isModifier(key) && this.isPressed(key)) {
67
+ throw botError(UNKNOWN_ERROR, 'Cannot press a modifier key that is already pressed.')
68
+ }
69
+ const repeat = this.isPressed(key)
70
+ // A modifier reports itself as held on its own keydown.
71
+ this.pressed.add(key)
72
+
73
+ const target = this.target()
74
+ if (!this.fireKey(target, EventType.KEYDOWN, key, repeat)) {
75
+ return
76
+ }
77
+ if ((key.character || key === Keys.ENTER) && !this.fireKey(target, EventType.KEYPRESS, key, repeat)) {
78
+ return
79
+ }
80
+ // A file input's value cannot be set from script; uploads are the
81
+ // driver's job, not the keyboard's.
82
+ if (isEditable(target) && !isFileInput(target)) {
83
+ this.edit(target, key)
84
+ }
85
+ if (key === Keys.ENTER && isElement(target, 'INPUT')) {
86
+ implicitlySubmit(target as HTMLInputElement)
87
+ }
88
+ }
89
+
90
+ releaseKey(key: Key): void {
91
+ if (!this.isPressed(key)) {
92
+ throw botError(UNKNOWN_ERROR, 'Cannot release a key that is not pressed. (' + key.key + ')')
93
+ }
94
+ // ...and as released on its own keyup.
95
+ this.pressed.delete(key)
96
+ this.fireKey(this.target(), EventType.KEYUP, key, false)
97
+ }
98
+
99
+ releaseModifiers(): void {
100
+ for (const key of [Keys.ALT, Keys.CONTROL, Keys.META, Keys.SHIFT]) {
101
+ if (this.isPressed(key)) {
102
+ this.releaseKey(key)
103
+ }
104
+ }
105
+ }
106
+
107
+ // Key events go where focus is, as they do for a real keyboard, falling back
108
+ // to the element being typed into when focus is nowhere in particular.
109
+ private target(): Element {
110
+ const element = this.element as Element
111
+ const active = getActiveElementFrom(element)
112
+ return active && !isElement(active, 'BODY') ? active : element
113
+ }
114
+
115
+ private typed(key: Key): string {
116
+ return (this.isPressed(Keys.SHIFT) ? key.shiftCharacter : key.character) as string
117
+ }
118
+
119
+ private fireKey(target: Element, type: EventFactory<KeyboardArgs>, key: Key, repeat: boolean): boolean {
120
+ const win = target.ownerDocument.defaultView || window
121
+ let keyValue = key.key
122
+ let keyCode = keyCodeFor(key, win)
123
+ let charCode = 0
124
+ if (key.character) {
125
+ keyValue = this.typed(key)
126
+ }
127
+ // keypress carries the typed character's code on both fields, in Chrome
128
+ // and in Firefox (which used to put it on charCode alone).
129
+ if (type === EventType.KEYPRESS) {
130
+ keyCode = charCode = key.character ? (keyValue.codePointAt(0) as number) : key.keyCode
131
+ }
132
+ return fire(target, type, {
133
+ key: keyValue,
134
+ code: key.code,
135
+ keyCode,
136
+ charCode,
137
+ location: key.location,
138
+ repeat,
139
+ altKey: this.isPressed(Keys.ALT),
140
+ ctrlKey: this.isPressed(Keys.CONTROL),
141
+ metaKey: this.isPressed(Keys.META) || this.isPressed(Keys.META_RIGHT),
142
+ shiftKey: this.isPressed(Keys.SHIFT),
143
+ })
144
+ }
145
+
146
+ private edit(target: Element, key: Key): void {
147
+ const shift = this.isPressed(Keys.SHIFT)
148
+ if (isContentEditable(target)) {
149
+ editContent(target, key, key.character ? this.typed(key) : null, shift)
150
+ return
151
+ }
152
+ const field = target as HTMLInputElement | HTMLTextAreaElement
153
+ if (key.character) {
154
+ insertText(field, this.typed(key), 'insertText')
155
+ } else if (key === Keys.ENTER) {
156
+ if (isElement(field, 'TEXTAREA')) {
157
+ insertText(field, '\n', 'insertLineBreak')
158
+ } else {
159
+ // A single-line field takes no line break, but still announces one.
160
+ fire(field, EventType.BEFOREINPUT, { inputType: 'insertLineBreak', data: null })
161
+ }
162
+ } else if (key === Keys.BACKSPACE || key === Keys.DELETE) {
163
+ deleteText(field, key === Keys.DELETE)
164
+ } else if (key === Keys.LEFT || key === Keys.RIGHT || key === Keys.HOME || key === Keys.END) {
165
+ moveCaret(field, key, shift)
166
+ }
167
+ }
168
+ }
169
+
170
+ type TextField = HTMLInputElement | HTMLTextAreaElement
171
+
172
+ // email, number and the date-like types have a value but no selection API
173
+ // (selectionStart is null). Edits there go at the end, which is where the
174
+ // caret is after moveCursor.
175
+ function supportsSelection(field: TextField): boolean {
176
+ try {
177
+ return typeof field.selectionStart === 'number'
178
+ } catch (_unsupported) {
179
+ return false
180
+ }
181
+ }
182
+
183
+ function caretToEnd(element: Element): void {
184
+ if (isContentEditable(element)) {
185
+ const selection = element.ownerDocument.getSelection()
186
+ if (selection) {
187
+ selection.selectAllChildren(element)
188
+ selection.collapseToEnd()
189
+ }
190
+ return
191
+ }
192
+ const field = element as TextField
193
+ if (supportsSelection(field)) {
194
+ field.setSelectionRange(field.value.length, field.value.length)
195
+ }
196
+ }
197
+
198
+ function selectionOf(field: TextField): [number, number] {
199
+ if (supportsSelection(field)) {
200
+ return [field.selectionStart as number, field.selectionEnd as number]
201
+ }
202
+ return [field.value.length, field.value.length]
203
+ }
204
+
205
+ function replaceRange(field: TextField, text: string, start: number, end: number): void {
206
+ if (supportsSelection(field)) {
207
+ field.setRangeText(text, start, end, 'end')
208
+ } else {
209
+ field.value = field.value.slice(0, start) + text + field.value.slice(end)
210
+ }
211
+ }
212
+
213
+ // beforeinput, textInput, the edit, input -- the order both engines use.
214
+ // setRangeText fires no input event of its own, so it is fired here.
215
+ function insertText(field: TextField, text: string, inputType: string): void {
216
+ const data = inputType === 'insertText' ? text : null
217
+ if (!fire(field, EventType.BEFOREINPUT, { inputType, data })) {
218
+ return
219
+ }
220
+ if (inputType === 'insertText' && !fire(field, EventType.TEXTINPUT, { data: text })) {
221
+ return
222
+ }
223
+ const [start, end] = selectionOf(field)
224
+ if (field.maxLength >= 0 && field.value.length - (end - start) + text.length > field.maxLength) {
225
+ return
226
+ }
227
+ replaceRange(field, text, start, end)
228
+ fire(field, EventType.INPUT, { inputType, data })
229
+ }
230
+
231
+ // One character, or a whole surrogate pair, before or after a collapsed
232
+ // caret; the selection when there is one. Nothing to delete means no events,
233
+ // as with a real Backspace at the start of a field.
234
+ function deleteText(field: TextField, forward: boolean): void {
235
+ let [start, end] = selectionOf(field)
236
+ const value = field.value
237
+ if (start === end) {
238
+ if (forward) {
239
+ if (end >= value.length) {
240
+ return
241
+ }
242
+ end = stepRight(value, end)
243
+ } else {
244
+ if (start <= 0) {
245
+ return
246
+ }
247
+ start = stepLeft(value, start)
248
+ }
249
+ }
250
+ const inputType = forward ? 'deleteContentForward' : 'deleteContentBackward'
251
+ if (!fire(field, EventType.BEFOREINPUT, { inputType, data: null })) {
252
+ return
253
+ }
254
+ replaceRange(field, '', start, end)
255
+ fire(field, EventType.INPUT, { inputType, data: null })
256
+ }
257
+
258
+ // One character left or right of `index`, never splitting a surrogate pair.
259
+ function stepLeft(value: string, index: number): number {
260
+ return Math.max(index - (isSurrogatePairAt(value, index - 2) ? 2 : 1), 0)
261
+ }
262
+
263
+ function stepRight(value: string, index: number): number {
264
+ return Math.min(index + (isSurrogatePairAt(value, index) ? 2 : 1), value.length)
265
+ }
266
+
267
+ function isSurrogatePairAt(value: string, index: number): boolean {
268
+ if (index < 0 || index + 1 >= value.length) {
269
+ return false
270
+ }
271
+ const high = value.charCodeAt(index)
272
+ const low = value.charCodeAt(index + 1)
273
+ return high >= 0xd800 && high <= 0xdbff && low >= 0xdc00 && low <= 0xdfff
274
+ }
275
+
276
+ // Arrow, Home and End, with shift extending from the selection's anchor the
277
+ // way a real field does. The anchor is whichever end the selection direction
278
+ // says is not moving. Up and Down are not handled: they move by line, which a
279
+ // field's selection API cannot express.
280
+ function moveCaret(field: TextField, key: Key, shift: boolean): void {
281
+ if (!supportsSelection(field)) {
282
+ return
283
+ }
284
+ const [start, end] = selectionOf(field)
285
+ const length = field.value.length
286
+ const backward = field.selectionDirection === 'backward'
287
+ const anchor = backward ? end : start
288
+ const focus = backward ? start : end
289
+
290
+ if (!shift) {
291
+ let caret: number
292
+ if (key === Keys.HOME) {
293
+ caret = 0
294
+ } else if (key === Keys.END) {
295
+ caret = length
296
+ } else if (start !== end) {
297
+ caret = key === Keys.LEFT ? start : end
298
+ } else {
299
+ caret = key === Keys.LEFT ? stepLeft(field.value, start) : stepRight(field.value, end)
300
+ }
301
+ field.setSelectionRange(caret, caret, 'none')
302
+ return
303
+ }
304
+
305
+ let moved: number
306
+ if (key === Keys.HOME) {
307
+ moved = 0
308
+ } else if (key === Keys.END) {
309
+ moved = length
310
+ } else if (key === Keys.LEFT) {
311
+ moved = stepLeft(field.value, focus)
312
+ } else {
313
+ moved = stepRight(field.value, focus)
314
+ }
315
+ // A selection with no prior extent is anchored at the caret.
316
+ const fixed = start === end ? start : anchor
317
+ field.setSelectionRange(Math.min(fixed, moved), Math.max(fixed, moved), moved < fixed ? 'backward' : 'forward')
318
+ }
319
+
320
+ // contenteditable edits go through execCommand: it is deprecated, but it is
321
+ // the one way a script can edit rich content that keeps the browser's undo
322
+ // stack, normalises the markup the way typing would, and fires a trusted
323
+ // input event with the right inputType. It does not fire beforeinput, so
324
+ // that is fired first and honoured here.
325
+ function editContent(target: Element, key: Key, typed: string | null, shift: boolean): void {
326
+ const doc = target.ownerDocument
327
+ const selection = doc.getSelection()
328
+ if (selection && !(selection.anchorNode && target.contains(selection.anchorNode))) {
329
+ selection.selectAllChildren(target)
330
+ selection.collapseToEnd()
331
+ }
332
+
333
+ if (typed !== null) {
334
+ if (!fire(target, EventType.BEFOREINPUT, { inputType: 'insertText', data: typed })) {
335
+ return
336
+ }
337
+ if (!fire(target, EventType.TEXTINPUT, { data: typed })) {
338
+ return
339
+ }
340
+ doc.execCommand('insertText', false, typed)
341
+ return
342
+ }
343
+
344
+ const commands: Array<[Key, string, string]> = [
345
+ [Keys.ENTER, 'insertParagraph', 'insertParagraph'],
346
+ [Keys.BACKSPACE, 'deleteContentBackward', 'delete'],
347
+ [Keys.DELETE, 'deleteContentForward', 'forwardDelete'],
348
+ ]
349
+ const command = commands.find(([k]) => k === key)
350
+ if (command) {
351
+ if (fire(target, EventType.BEFOREINPUT, { inputType: command[1], data: null })) {
352
+ doc.execCommand(command[2], false)
353
+ }
354
+ return
355
+ }
356
+
357
+ // Selection.modify is non-standard but present in every supported engine;
358
+ // it is the only API that moves a caret by character or line boundary.
359
+ const modify = selection && (selection as Selection & { modify?: Function }).modify
360
+ if (!modify) {
361
+ return
362
+ }
363
+ const alter = shift ? 'extend' : 'move'
364
+ if (key === Keys.LEFT || key === Keys.RIGHT) {
365
+ modify.call(selection, alter, key === Keys.LEFT ? 'backward' : 'forward', 'character')
366
+ } else if (key === Keys.HOME || key === Keys.END) {
367
+ modify.call(selection, alter, key === Keys.HOME ? 'backward' : 'forward', 'lineboundary')
368
+ }
369
+ }
@@ -0,0 +1,204 @@
1
+ // Licensed to the Software Freedom Conservancy (SFC) under one
2
+ // or more contributor license agreements. See the NOTICE file
3
+ // distributed with this work for additional information
4
+ // regarding copyright ownership. The SFC licenses this file
5
+ // to you under the Apache License, Version 2.0 (the
6
+ // "License"); you may not use this file except in compliance
7
+ // with the License. You may obtain a copy of the License at
8
+ //
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
+ //
11
+ // Unless required by applicable law or agreed to in writing,
12
+ // software distributed under the License is distributed on an
13
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ // KIND, either express or implied. See the License for the
15
+ // specific language governing permissions and limitations
16
+ // under the License.
17
+
18
+ import { isGecko, isMac } from './useragent.js'
19
+
20
+ // The keys the keyboard knows, each carrying what a real press reports: the
21
+ // `key` and `code` values, the legacy keyCode for keydown / keyup, and for
22
+ // character keys the character typed without and with shift.
23
+ //
24
+ // keyCodes match what Chrome and Firefox report for real presses (recorded
25
+ // 2026-10-13). They agree except for '=', '-', ';' and Meta, where Firefox has
26
+ // its own numbers; `gecko` carries those.
27
+
28
+ export const LOCATION_STANDARD = 0
29
+ export const LOCATION_LEFT = 1
30
+ export const LOCATION_RIGHT = 2
31
+ export const LOCATION_NUMPAD = 3
32
+
33
+ export interface Key {
34
+ // The key value for a non-character key ('Enter', 'ArrowLeft').
35
+ readonly key: string
36
+ readonly code: string
37
+ readonly keyCode: number
38
+ readonly gecko?: number
39
+ readonly location: number
40
+ readonly character: string | null
41
+ readonly shiftCharacter: string | null
42
+ }
43
+
44
+ function key(
45
+ keyValue: string,
46
+ code: string,
47
+ keyCode: number,
48
+ options: { gecko?: number; location?: number; character?: string; shiftCharacter?: string } = {},
49
+ ): Key {
50
+ return {
51
+ key: keyValue,
52
+ code,
53
+ keyCode,
54
+ gecko: options.gecko,
55
+ location: options.location ?? LOCATION_STANDARD,
56
+ character: options.character ?? null,
57
+ shiftCharacter: options.shiftCharacter ?? options.character ?? null,
58
+ }
59
+ }
60
+
61
+ function character(code: string, keyCode: number, ch: string, shifted?: string, gecko?: number): Key {
62
+ return key(ch, code, keyCode, { character: ch, shiftCharacter: shifted, gecko })
63
+ }
64
+
65
+ function numpad(code: string, keyCode: number, ch: string): Key {
66
+ return key(ch, code, keyCode, { character: ch, location: LOCATION_NUMPAD })
67
+ }
68
+
69
+ function letters(): Record<string, Key> {
70
+ const result: Record<string, Key> = {}
71
+ for (let i = 0; i < 26; i++) {
72
+ const upper = String.fromCharCode(65 + i)
73
+ result[upper] = character('Key' + upper, 65 + i, upper.toLowerCase(), upper)
74
+ }
75
+ return result
76
+ }
77
+
78
+ function functionKeys(): Record<string, Key> {
79
+ const result: Record<string, Key> = {}
80
+ for (let i = 1; i <= 12; i++) {
81
+ result['F' + i] = key('F' + i, 'F' + i, 111 + i)
82
+ }
83
+ return result
84
+ }
85
+
86
+ const DIGIT_SHIFTS = ')!@#$%^&*('
87
+
88
+ function digits(): Record<string, Key> {
89
+ const names = ['ZERO', 'ONE', 'TWO', 'THREE', 'FOUR', 'FIVE', 'SIX', 'SEVEN', 'EIGHT', 'NINE']
90
+ const result: Record<string, Key> = {}
91
+ names.forEach((name, i) => {
92
+ result[name] = character('Digit' + i, 48 + i, String(i), DIGIT_SHIFTS[i])
93
+ result['NUM_' + name] = numpad('Numpad' + i, 96 + i, String(i))
94
+ })
95
+ return result
96
+ }
97
+
98
+ export const Keys = {
99
+ BACKSPACE: key('Backspace', 'Backspace', 8),
100
+ TAB: key('Tab', 'Tab', 9),
101
+ ENTER: key('Enter', 'Enter', 13),
102
+ SHIFT: key('Shift', 'ShiftLeft', 16, { location: LOCATION_LEFT }),
103
+ CONTROL: key('Control', 'ControlLeft', 17, { location: LOCATION_LEFT }),
104
+ ALT: key('Alt', 'AltLeft', 18, { location: LOCATION_LEFT }),
105
+ PAUSE: key('Pause', 'Pause', 19),
106
+ CAPS_LOCK: key('CapsLock', 'CapsLock', 20),
107
+ ESC: key('Escape', 'Escape', 27),
108
+ SPACE: character('Space', 32, ' '),
109
+ PAGE_UP: key('PageUp', 'PageUp', 33),
110
+ PAGE_DOWN: key('PageDown', 'PageDown', 34),
111
+ END: key('End', 'End', 35),
112
+ HOME: key('Home', 'Home', 36),
113
+ LEFT: key('ArrowLeft', 'ArrowLeft', 37),
114
+ UP: key('ArrowUp', 'ArrowUp', 38),
115
+ RIGHT: key('ArrowRight', 'ArrowRight', 39),
116
+ DOWN: key('ArrowDown', 'ArrowDown', 40),
117
+ PRINT_SCREEN: key('PrintScreen', 'PrintScreen', 44),
118
+ INSERT: key('Insert', 'Insert', 45),
119
+ DELETE: key('Delete', 'Delete', 46),
120
+
121
+ ...digits(),
122
+ ...letters(),
123
+
124
+ // Firefox on macOS reports 224 for both Meta keys; every other combination
125
+ // reports the Windows-style 91 / 92. Firefox on Linux is not verified.
126
+ META: key('Meta', 'MetaLeft', 91, { gecko: 91, location: LOCATION_LEFT }),
127
+ META_RIGHT: key('Meta', 'MetaRight', 92, { gecko: 92, location: LOCATION_RIGHT }),
128
+ CONTEXT_MENU: key('ContextMenu', 'ContextMenu', 93),
129
+
130
+ NUM_MULTIPLY: numpad('NumpadMultiply', 106, '*'),
131
+ NUM_PLUS: numpad('NumpadAdd', 107, '+'),
132
+ NUM_MINUS: numpad('NumpadSubtract', 109, '-'),
133
+ NUM_PERIOD: numpad('NumpadDecimal', 110, '.'),
134
+ NUM_DIVISION: numpad('NumpadDivide', 111, '/'),
135
+ NUM_LOCK: key('NumLock', 'NumLock', 144, { location: LOCATION_NUMPAD }),
136
+ SEPARATOR: numpad('NumpadComma', 108, ','),
137
+
138
+ ...functionKeys(),
139
+
140
+ EQUALS: character('Equal', 187, '=', '+', 61),
141
+ HYPHEN: character('Minus', 189, '-', '_', 173),
142
+ COMMA: character('Comma', 188, ',', '<'),
143
+ PERIOD: character('Period', 190, '.', '>'),
144
+ SLASH: character('Slash', 191, '/', '?'),
145
+ BACKTICK: character('Backquote', 192, '`', '~'),
146
+ OPEN_BRACKET: character('BracketLeft', 219, '[', '{'),
147
+ BACKSLASH: character('Backslash', 220, '\\', '|'),
148
+ CLOSE_BRACKET: character('BracketRight', 221, ']', '}'),
149
+ SEMICOLON: character('Semicolon', 186, ';', ':', 59),
150
+ APOSTROPHE: character('Quote', 222, "'", '"'),
151
+ }
152
+
153
+ export const MODIFIERS: readonly Key[] = [Keys.ALT, Keys.CONTROL, Keys.META, Keys.SHIFT]
154
+
155
+ export function isModifier(k: Key): boolean {
156
+ return MODIFIERS.includes(k)
157
+ }
158
+
159
+ // The keyCode a keydown or keyup for this key reports in the given window's
160
+ // engine.
161
+ export function keyCodeFor(k: Key, win: Window): number {
162
+ if (!isGecko(win)) {
163
+ if (k === Keys.META_RIGHT && isMac(win)) {
164
+ return 93
165
+ }
166
+ return k.keyCode
167
+ }
168
+ if ((k === Keys.META || k === Keys.META_RIGHT) && isMac(win)) {
169
+ return 224
170
+ }
171
+ return k.gecko ?? k.keyCode
172
+ }
173
+
174
+ // Character to (key, needs shift). Numpad keys never win: a typed '1' is the
175
+ // digit row's 1, as on a real keyboard without a numpad.
176
+ const CHAR_TO_KEY = new Map<string, { key: Key; shift: boolean }>()
177
+ for (const k of Object.values(Keys) as Key[]) {
178
+ if (!k.character || k.location === LOCATION_NUMPAD) {
179
+ continue
180
+ }
181
+ if (!CHAR_TO_KEY.has(k.character)) {
182
+ CHAR_TO_KEY.set(k.character, { key: k, shift: false })
183
+ }
184
+ if (k.shiftCharacter && k.shiftCharacter !== k.character) {
185
+ CHAR_TO_KEY.set(k.shiftCharacter, { key: k, shift: true })
186
+ }
187
+ }
188
+
189
+ // A key that types `ch`, a single code point. For characters not on a US
190
+ // layout there is no true keyCode to report; the upper-case code point is
191
+ // sometimes right and at least positive, which is what bot.Keyboard did.
192
+ export function fromChar(ch: string): { key: Key; shift: boolean } {
193
+ if (Array.from(ch).length !== 1) {
194
+ throw new Error('Argument not a single character: ' + ch)
195
+ }
196
+ const known = CHAR_TO_KEY.get(ch)
197
+ if (known) {
198
+ return known
199
+ }
200
+ const upper = ch.toUpperCase()
201
+ const lower = ch.toLowerCase()
202
+ const k = key(ch, '', upper.codePointAt(0) as number, { character: lower, shiftCharacter: upper })
203
+ return { key: k, shift: ch !== lower }
204
+ }