@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,76 @@
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 { getProperty } from './attribute.js'
19
+ import { isElement } from './element.js'
20
+
21
+ // Elements that support the "disabled" attribute, per HTML 4.01 17.12.1.
22
+ // Anything else is unconditionally enabled.
23
+ const DISABLED_ATTRIBUTE_SUPPORTED = ['BUTTON', 'INPUT', 'OPTGROUP', 'OPTION', 'SELECT', 'TEXTAREA']
24
+
25
+ function getPreviousElementSibling(node: Node): Element | null {
26
+ let sibling = node.previousSibling
27
+ while (sibling && sibling.nodeType !== 1 /* ELEMENT_NODE */) {
28
+ sibling = sibling.previousSibling
29
+ }
30
+ return sibling as Element | null
31
+ }
32
+
33
+ // A <fieldset disabled> disables its descendants, except those inside its
34
+ // *first* <legend>. Later legends are not exempt.
35
+ function isInsideDisabledFieldset(element: Element): boolean {
36
+ let node: Node | null = element
37
+ while (node) {
38
+ const parent = node.parentNode
39
+ if (parent && isElement(parent, 'FIELDSET') && getProperty(parent as Element, 'disabled')) {
40
+ if (!isElement(node, 'LEGEND')) {
41
+ return true
42
+ }
43
+ // Being a legend only exempts us if no legend precedes us.
44
+ let sibling = getPreviousElementSibling(node)
45
+ while (sibling) {
46
+ if (isElement(sibling, 'LEGEND')) {
47
+ return true
48
+ }
49
+ sibling = getPreviousElementSibling(sibling)
50
+ }
51
+ }
52
+ node = parent
53
+ }
54
+ return false
55
+ }
56
+
57
+ export function isEnabled(element: Element): boolean {
58
+ const isSupported = DISABLED_ATTRIBUTE_SUPPORTED.some((tagName) => isElement(element, tagName))
59
+ if (!isSupported) {
60
+ return true
61
+ }
62
+
63
+ if (getProperty(element, 'disabled')) {
64
+ return false
65
+ }
66
+
67
+ // An OPTION or OPTGROUP can inherit its state from an ancestor SELECT or
68
+ // OPTGROUP. isElement() rejects a null parent, so a detached node simply
69
+ // reports enabled rather than recursing into nothing.
70
+ const parent = element.parentNode
71
+ if ((parent && parent.nodeType === 1 && isElement(element, 'OPTGROUP')) || isElement(element, 'OPTION')) {
72
+ return isEnabled(parent as Element)
73
+ }
74
+
75
+ return !isInsideDisabledFieldset(element)
76
+ }
@@ -0,0 +1,41 @@
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
+ // WebDriver error codes carried by atoms back across the wire. The injecting
19
+ // binding reads `code` off the thrown error to pick the right exception type,
20
+ // so these strings are part of the protocol surface, not free text.
21
+ export const INVALID_SELECTOR = 'invalid selector'
22
+ export const INVALID_ARGUMENT = 'invalid argument'
23
+ export const NO_SUCH_ELEMENT = 'no such element'
24
+ export const NO_SUCH_FRAME = 'no such frame'
25
+ export const NO_SUCH_WINDOW = 'no such window'
26
+ export const STALE_ELEMENT_REFERENCE = 'stale element reference'
27
+ export const JAVASCRIPT_ERROR = 'javascript error'
28
+ export const SCRIPT_TIMEOUT = 'script timeout'
29
+ // W3C's code for both of Closure's ELEMENT_NOT_VISIBLE (click on a hidden
30
+ // element) and its INVALID_ELEMENT_STATE for typing into one.
31
+ export const ELEMENT_NOT_INTERACTABLE = 'element not interactable'
32
+ export const INVALID_ELEMENT_STATE = 'invalid element state'
33
+ // bot.Error.State.UNKNOWN_ERROR, which bot.ErrorCode.UNKNOWN_ERROR (13) mapped
34
+ // onto. The storage atoms raise it when web storage is unavailable.
35
+ export const UNKNOWN_ERROR = 'unknown error'
36
+
37
+ export function botError(code: string, message: string): Error {
38
+ const err = new Error(message)
39
+ ;(err as unknown as Record<string, unknown>)['code'] = code
40
+ return err
41
+ }
@@ -0,0 +1,268 @@
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
+ // Builds synthetic DOM events and dispatches them, for the interaction atoms.
19
+ //
20
+ // bot.events used document.createEvent + initMouseEvent, assigned key fields
21
+ // onto plain Events, and fired no pointer, beforeinput or mouseenter/leave
22
+ // events at all. This builds every event with its constructor so listeners
23
+ // see what real input gives them: key/code on key events, inputType/data on
24
+ // input events, buttons and a real click count on mouse events, pointer
25
+ // events, and `composed` set wherever the browser sets it -- without which a
26
+ // click inside a shadow root never reaches a document listener.
27
+ //
28
+ // What stays different from real input is unavoidable: isTrusted is false,
29
+ // and an untrusted event runs no default action except a click's activation
30
+ // behaviour, so the callers insert text and toggle options themselves.
31
+ //
32
+ // Not ported, with where they were used: touch (touchscreen), MSGesture /
33
+ // MSPointer (Internet Explorer), mouse wheel and MozMousePixelScroll
34
+ // (scrolling), orientationchange (touchscreen), propertychange (IE).
35
+
36
+ interface Modifiers {
37
+ altKey?: boolean
38
+ ctrlKey?: boolean
39
+ shiftKey?: boolean
40
+ metaKey?: boolean
41
+ }
42
+
43
+ export interface MouseArgs extends Modifiers {
44
+ clientX: number
45
+ clientY: number
46
+ button?: number
47
+ // The buttons held *after* this event, as the browser reports them: 1 on
48
+ // mousedown of the primary button, 0 on its mouseup.
49
+ buttons?: number
50
+ // The click count for click, mousedown and mouseup; 0 for the others.
51
+ detail?: number
52
+ relatedTarget?: EventTarget | null
53
+ }
54
+
55
+ export interface PointerArgs extends MouseArgs {
56
+ pointerId?: number
57
+ pointerType?: string
58
+ isPrimary?: boolean
59
+ }
60
+
61
+ export interface KeyboardArgs extends Modifiers {
62
+ key: string
63
+ code: string
64
+ // The legacy numbers are the caller's to choose: they differ by engine on
65
+ // keydown and keyup (Firefox reports 61 for '=', Chrome 187) and are the
66
+ // character code on keypress in both.
67
+ keyCode?: number
68
+ charCode?: number
69
+ location?: number
70
+ repeat?: boolean
71
+ }
72
+
73
+ export interface InputArgs {
74
+ inputType: string
75
+ data?: string | null
76
+ }
77
+
78
+ export interface TextArgs {
79
+ data: string
80
+ }
81
+
82
+ export interface FocusArgs {
83
+ relatedTarget?: EventTarget | null
84
+ }
85
+
86
+ export interface SubmitArgs {
87
+ submitter?: HTMLElement | null
88
+ }
89
+
90
+ type Target = Element | Document | Window
91
+
92
+ // goog.dom.getOwnerDocument: a document is its own owner.
93
+ function ownerDocument(target: Target): Document {
94
+ if ((target as Node).nodeType === Node.DOCUMENT_NODE) {
95
+ return target as Document
96
+ }
97
+ return (target as Element).ownerDocument || (target as Window).document
98
+ }
99
+
100
+ // Constructors come from the target's own window, so a listener in a frame
101
+ // that checks `event instanceof MouseEvent` sees its own realm's class.
102
+ function realm(target: Target): Window & typeof globalThis {
103
+ return (ownerDocument(target).defaultView || window) as Window & typeof globalThis
104
+ }
105
+
106
+ interface Shape {
107
+ bubbles: boolean
108
+ cancelable: boolean
109
+ composed: boolean
110
+ }
111
+
112
+ type Build<A> = (win: Window & typeof globalThis, type: string, shape: Shape, args: A) => Event
113
+
114
+ // One factory per event type. toString gives the DOM event name, so a factory
115
+ // can key a map or be handed to addEventListener-style code directly.
116
+ export class EventFactory<A = unknown> {
117
+ constructor(
118
+ private readonly type: string,
119
+ private readonly shape: Shape,
120
+ private readonly build: Build<A>,
121
+ ) {}
122
+
123
+ create(target: Target, args: A): Event {
124
+ return this.build(realm(target), this.type, this.shape, args)
125
+ }
126
+
127
+ toString(): string {
128
+ return this.type
129
+ }
130
+ }
131
+
132
+ function modifiers(args: Modifiers): Modifiers {
133
+ return {
134
+ altKey: !!args.altKey,
135
+ ctrlKey: !!args.ctrlKey,
136
+ shiftKey: !!args.shiftKey,
137
+ metaKey: !!args.metaKey,
138
+ }
139
+ }
140
+
141
+ // screenX/Y mirror clientX/Y. Not strictly correct, but pages under test
142
+ // depend on relative positions, which this preserves, and the true screen
143
+ // offset of the viewport is not knowable from script.
144
+ function mouseInit(win: Window, shape: Shape, args: MouseArgs): MouseEventInit {
145
+ return {
146
+ ...shape,
147
+ ...modifiers(args),
148
+ view: win,
149
+ detail: args.detail ?? 0,
150
+ clientX: args.clientX,
151
+ clientY: args.clientY,
152
+ screenX: args.clientX,
153
+ screenY: args.clientY,
154
+ button: args.button ?? 0,
155
+ buttons: args.buttons ?? 0,
156
+ relatedTarget: args.relatedTarget ?? null,
157
+ }
158
+ }
159
+
160
+ const plain: Build<unknown> = (win, type, shape) => new win.Event(type, shape)
161
+
162
+ const focus: Build<FocusArgs | undefined> = (win, type, shape, args) =>
163
+ new win.FocusEvent(type, { ...shape, view: win, relatedTarget: args?.relatedTarget ?? null })
164
+
165
+ const mouse: Build<MouseArgs> = (win, type, shape, args) => new win.MouseEvent(type, mouseInit(win, shape, args))
166
+
167
+ // A mouse's pointer: id 1, primary, 1x1, and the spec's 0.5 pressure while a
168
+ // button is held.
169
+ const pointer: Build<PointerArgs> = (win, type, shape, args) =>
170
+ new win.PointerEvent(type, {
171
+ ...mouseInit(win, shape, args),
172
+ pointerId: args.pointerId ?? 1,
173
+ pointerType: args.pointerType ?? 'mouse',
174
+ isPrimary: args.isPrimary ?? true,
175
+ width: 1,
176
+ height: 1,
177
+ pressure: args.buttons ? 0.5 : 0,
178
+ })
179
+
180
+ // keyCode, charCode and which are the legacy members of KeyboardEventInit;
181
+ // Chrome and Firefox both honour them.
182
+ const keyboard: Build<KeyboardArgs> = (win, type, shape, args) =>
183
+ new win.KeyboardEvent(type, {
184
+ ...shape,
185
+ ...modifiers(args),
186
+ view: win,
187
+ key: args.key,
188
+ code: args.code,
189
+ location: args.location ?? 0,
190
+ repeat: !!args.repeat,
191
+ keyCode: args.keyCode ?? 0,
192
+ charCode: args.charCode ?? 0,
193
+ which: args.keyCode || args.charCode || 0,
194
+ } as KeyboardEventInit)
195
+
196
+ const input: Build<InputArgs> = (win, type, shape, args) =>
197
+ new win.InputEvent(type, { ...shape, view: win, inputType: args.inputType, data: args.data ?? null })
198
+
199
+ // textInput is the legacy TextEvent, which has no constructor. Chrome, Firefox
200
+ // and Safari all still fire it between beforeinput and input, and some
201
+ // editors still listen for it.
202
+ const text: Build<TextArgs> = (win, type, shape, args) => {
203
+ const event = win.document.createEvent('TextEvent') as Event & {
204
+ initTextEvent(type: string, bubbles: boolean, cancelable: boolean, view: Window, data: string): void
205
+ }
206
+ event.initTextEvent(type, shape.bubbles, shape.cancelable, win, args.data)
207
+ return event
208
+ }
209
+
210
+ const submit: Build<SubmitArgs | undefined> = (win, type, shape, args) =>
211
+ new win.SubmitEvent(type, { ...shape, submitter: args?.submitter ?? null })
212
+
213
+ // Bubbles / cancelable / composed as UI Events, Pointer Events, Input Events
214
+ // and HTML define them for the real event.
215
+ function shape(bubbles: boolean, cancelable: boolean, composed: boolean): Shape {
216
+ return { bubbles, cancelable, composed }
217
+ }
218
+
219
+ const ui = shape(true, true, true)
220
+
221
+ export const EventType = {
222
+ CHANGE: new EventFactory('change', shape(true, false, false), plain),
223
+ SELECT: new EventFactory('select', shape(true, false, false), plain),
224
+ SUBMIT: new EventFactory('submit', shape(true, true, false), submit),
225
+
226
+ BLUR: new EventFactory('blur', shape(false, false, true), focus),
227
+ FOCUS: new EventFactory('focus', shape(false, false, true), focus),
228
+ FOCUSIN: new EventFactory('focusin', shape(true, false, true), focus),
229
+ FOCUSOUT: new EventFactory('focusout', shape(true, false, true), focus),
230
+
231
+ BEFOREINPUT: new EventFactory('beforeinput', ui, input),
232
+ INPUT: new EventFactory('input', shape(true, false, true), input),
233
+ TEXTINPUT: new EventFactory('textInput', shape(true, true, false), text),
234
+
235
+ KEYDOWN: new EventFactory('keydown', ui, keyboard),
236
+ KEYPRESS: new EventFactory('keypress', ui, keyboard),
237
+ KEYUP: new EventFactory('keyup', ui, keyboard),
238
+
239
+ CLICK: new EventFactory('click', ui, mouse),
240
+ CONTEXTMENU: new EventFactory('contextmenu', ui, mouse),
241
+ DBLCLICK: new EventFactory('dblclick', ui, mouse),
242
+ MOUSEDOWN: new EventFactory('mousedown', ui, mouse),
243
+ MOUSEMOVE: new EventFactory('mousemove', ui, mouse),
244
+ MOUSEOUT: new EventFactory('mouseout', ui, mouse),
245
+ MOUSEOVER: new EventFactory('mouseover', ui, mouse),
246
+ MOUSEUP: new EventFactory('mouseup', ui, mouse),
247
+ MOUSEENTER: new EventFactory('mouseenter', shape(false, false, false), mouse),
248
+ MOUSELEAVE: new EventFactory('mouseleave', shape(false, false, false), mouse),
249
+
250
+ POINTERDOWN: new EventFactory('pointerdown', ui, pointer),
251
+ POINTERMOVE: new EventFactory('pointermove', ui, pointer),
252
+ POINTEROUT: new EventFactory('pointerout', ui, pointer),
253
+ POINTEROVER: new EventFactory('pointerover', ui, pointer),
254
+ POINTERUP: new EventFactory('pointerup', ui, pointer),
255
+ POINTERENTER: new EventFactory('pointerenter', shape(false, false, false), pointer),
256
+ POINTERLEAVE: new EventFactory('pointerleave', shape(false, false, false), pointer),
257
+ }
258
+
259
+ // Whether the event went through uncancelled.
260
+ export function fire<A>(target: Target, type: EventFactory<A>, args: A): boolean {
261
+ return target.dispatchEvent(type.create(target, args))
262
+ }
263
+
264
+ // Dispatched events carry isTrusted: false, which is how a page tells them
265
+ // from real input.
266
+ export function isSynthetic(event: Event): boolean {
267
+ return !event.isTrusted
268
+ }
@@ -0,0 +1,92 @@
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 { isElement } from './element.js'
19
+ import { isFocusable } from './focusable.js'
20
+
21
+ // The focused element, looking through open shadow roots: document.activeElement
22
+ // stops at the shadow host.
23
+ function getDeepActiveElement(doc: Document): Element | null {
24
+ return throughOpenShadowRoots(doc.activeElement)
25
+ }
26
+
27
+ // The focused element as seen from `element`. A closed shadow root hides its
28
+ // focused element from the document, but not from a node inside it: when
29
+ // focus is within the element's own shadow root, that root's active element
30
+ // is the true one, and the document would only report the host.
31
+ export function getActiveElementFrom(element: Element): Element | null {
32
+ const root = element.getRootNode() as Node & Partial<DocumentOrShadowRoot>
33
+ if (root !== element.ownerDocument && root.activeElement) {
34
+ return throughOpenShadowRoots(root.activeElement)
35
+ }
36
+ return getDeepActiveElement(element.ownerDocument)
37
+ }
38
+
39
+ // The focused element itself, or a shadow host whose tree holds focus: the
40
+ // one its own root reports as active. Keys already go to either, so typing
41
+ // into one needs no focusing or interactability check.
42
+ export function holdsFocus(element: Element): boolean {
43
+ const root = element.getRootNode() as Node & Partial<DocumentOrShadowRoot>
44
+ return element === getActiveElementFrom(element) || element === root.activeElement
45
+ }
46
+
47
+ function throughOpenShadowRoots(active: Element | null): Element | null {
48
+ while (active && active.shadowRoot && active.shadowRoot.activeElement) {
49
+ active = active.shadowRoot.activeElement
50
+ }
51
+ return active
52
+ }
53
+
54
+ function focusTarget(element: Element): Element {
55
+ for (let node: Element | null = element; node; node = node.parentElement) {
56
+ if (isFocusable(node)) {
57
+ return node
58
+ }
59
+ }
60
+ return element
61
+ }
62
+
63
+ // Focuses the element, or its nearest focusable ancestor, as a click or a
64
+ // keyboard interaction would. Returns whether focus moved to it.
65
+ //
66
+ // focus() already blurs whatever had focus, so the explicit blur is only for
67
+ // a target that cannot take focus: a real click on non-focusable content
68
+ // still takes focus away from the field that had it. When focus lands
69
+ // somewhere else, a focus handler moved it there on purpose, so it is left
70
+ // alone. preventScroll because the caller has already scrolled the element
71
+ // into view and a second scroll would move it again.
72
+ export function focusOnElement(element: Element): boolean {
73
+ const target = focusTarget(element)
74
+ const previous = getActiveElementFrom(target)
75
+ if (previous === target) {
76
+ return false
77
+ }
78
+ if (typeof (target as HTMLElement).focus === 'function') {
79
+ ;(target as HTMLElement).focus({ preventScroll: true })
80
+ }
81
+ const active = getActiveElementFrom(target)
82
+ if (active === target) {
83
+ return true
84
+ }
85
+ if (active !== previous) {
86
+ return false
87
+ }
88
+ if (active && !isElement(active, 'BODY') && typeof (active as HTMLElement).blur === 'function') {
89
+ ;(active as HTMLElement).blur()
90
+ }
91
+ return false
92
+ }
@@ -0,0 +1,38 @@
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 { getAttribute, getProperty } from './attribute.js'
19
+ import { isEditable } from './editable.js'
20
+ import { isElement } from './element.js'
21
+
22
+ // http://www.w3.org/TR/html401/interact/scripts.html#adef-onfocus
23
+ const FOCUSABLE_FORM_FIELDS = ['A', 'AREA', 'BUTTON', 'INPUT', 'LABEL', 'SELECT', 'TEXTAREA']
24
+
25
+ // An element can take focus if it is a form field, carries a non-negative
26
+ // tabindex, or is editable.
27
+ export function isFocusable(element: Element): boolean {
28
+ if (FOCUSABLE_FORM_FIELDS.some((tagName) => isElement(element, tagName))) {
29
+ return true
30
+ }
31
+ // The attribute has to be present for tabindex to count — the tabIndex
32
+ // property reports a default for several tags that were never marked up
33
+ // with one.
34
+ if (getAttribute(element, 'tabindex') != null && Number(getProperty(element, 'tabIndex')) >= 0) {
35
+ return true
36
+ }
37
+ return isEditable(element)
38
+ }
@@ -0,0 +1,81 @@
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 { EventType, fire } from './events.js'
19
+
20
+ // <input> types that count against implicit submission (HTML, "implicit
21
+ // submission"): with more than one in the form and no submit button, Enter
22
+ // does not submit.
23
+ const BLOCKS_IMPLICIT_SUBMISSION = [
24
+ 'text',
25
+ 'search',
26
+ 'url',
27
+ 'tel',
28
+ 'email',
29
+ 'password',
30
+ 'date',
31
+ 'month',
32
+ 'week',
33
+ 'time',
34
+ 'datetime-local',
35
+ 'number',
36
+ ]
37
+
38
+ function isSubmitButton(element: Element): element is HTMLButtonElement | HTMLInputElement {
39
+ const type = (element as HTMLInputElement).type
40
+ if (element.tagName === 'BUTTON') {
41
+ return type === 'submit'
42
+ }
43
+ return element.tagName === 'INPUT' && (type === 'submit' || type === 'image')
44
+ }
45
+
46
+ // Enter in a form field, as HTML defines it: click the form's default button
47
+ // (its first submit button), which submits through the button's own
48
+ // activation behaviour; with no button, submit only if the field is the one
49
+ // field that would block it.
50
+ //
51
+ // This replaces bot.Keyboard.maybeSubmitForm_, which looked only at <input>s
52
+ // (so a <button type=submit> never counted), counted hidden and checkbox
53
+ // inputs as fields, and submitted with form.submit() -- skipping both the
54
+ // click on the default button and constraint validation, which real Enter
55
+ // runs.
56
+ export function implicitlySubmit(field: HTMLInputElement): void {
57
+ const form = field.form
58
+ if (!form) {
59
+ return
60
+ }
61
+ // Read through the prototype because a control named "elements" or
62
+ // "requestSubmit" shadows the form's own property.
63
+ const win = (form.ownerDocument.defaultView || window) as Window & typeof globalThis
64
+ const formPrototype = win.HTMLFormElement.prototype
65
+ const controls = Object.getOwnPropertyDescriptor(formPrototype, 'elements')!.get!.call(form) as HTMLFormControlsCollection
66
+ const elements = Array.from(controls)
67
+ const defaultButton = elements.find(isSubmitButton)
68
+ if (defaultButton) {
69
+ if (!defaultButton.disabled) {
70
+ // A keyboard-initiated click: no position and a click count of 0.
71
+ fire(defaultButton, EventType.CLICK, { clientX: 0, clientY: 0, detail: 0 })
72
+ }
73
+ return
74
+ }
75
+ const blocking = elements.filter(
76
+ (element) => element.tagName === 'INPUT' && BLOCKS_IMPLICIT_SUBMISSION.includes((element as HTMLInputElement).type),
77
+ )
78
+ if (blocking.length <= 1) {
79
+ formPrototype.requestSubmit.call(form)
80
+ }
81
+ }