@selenium/atoms 4.51.0 → 4.52.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 (331) hide show
  1. package/dist/index.d.ts +40 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +40 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/typescript/active-element.d.ts +2 -0
  6. package/dist/typescript/active-element.d.ts.map +1 -0
  7. package/dist/typescript/active-element.js +19 -0
  8. package/dist/typescript/active-element.js.map +1 -0
  9. package/dist/typescript/clear-local-storage.d.ts +3 -0
  10. package/dist/typescript/clear-local-storage.d.ts.map +1 -0
  11. package/dist/typescript/clear-local-storage.js +25 -0
  12. package/dist/typescript/clear-local-storage.js.map +1 -0
  13. package/dist/typescript/clear-session-storage.d.ts +3 -0
  14. package/dist/typescript/clear-session-storage.d.ts.map +1 -0
  15. package/dist/typescript/clear-session-storage.js +25 -0
  16. package/dist/typescript/clear-session-storage.js.map +1 -0
  17. package/dist/typescript/clear.d.ts +3 -0
  18. package/dist/typescript/clear.d.ts.map +1 -0
  19. package/dist/typescript/clear.js +67 -0
  20. package/dist/typescript/clear.js.map +1 -0
  21. package/dist/typescript/click.d.ts +4 -0
  22. package/dist/typescript/click.d.ts.map +1 -0
  23. package/dist/typescript/click.js +52 -0
  24. package/dist/typescript/click.js.map +1 -0
  25. package/dist/typescript/core/attribute.d.ts +3 -0
  26. package/dist/typescript/core/attribute.d.ts.map +1 -0
  27. package/dist/typescript/core/attribute.js +60 -0
  28. package/dist/typescript/core/attribute.js.map +1 -0
  29. package/dist/typescript/core/color.d.ts +2 -0
  30. package/dist/typescript/core/color.d.ts.map +1 -0
  31. package/dist/typescript/core/color.js +248 -0
  32. package/dist/typescript/core/color.js.map +1 -0
  33. package/dist/typescript/core/editable.d.ts +5 -0
  34. package/dist/typescript/core/editable.d.ts.map +1 -0
  35. package/dist/typescript/core/editable.js +55 -0
  36. package/dist/typescript/core/editable.js.map +1 -0
  37. package/dist/typescript/core/element.d.ts +6 -0
  38. package/dist/typescript/core/element.d.ts.map +1 -0
  39. package/dist/typescript/core/element.js +97 -0
  40. package/dist/typescript/core/element.js.map +1 -0
  41. package/dist/typescript/core/enabled.d.ts +2 -0
  42. package/dist/typescript/core/enabled.d.ts.map +1 -0
  43. package/dist/typescript/core/enabled.js +69 -0
  44. package/dist/typescript/core/enabled.js.map +1 -0
  45. package/dist/typescript/core/error.d.ts +13 -0
  46. package/dist/typescript/core/error.d.ts.map +1 -0
  47. package/dist/typescript/core/error.js +40 -0
  48. package/dist/typescript/core/error.js.map +1 -0
  49. package/dist/typescript/core/events.d.ts +91 -0
  50. package/dist/typescript/core/events.d.ts.map +1 -0
  51. package/dist/typescript/core/events.js +131 -0
  52. package/dist/typescript/core/events.js.map +1 -0
  53. package/dist/typescript/core/focus.d.ts +4 -0
  54. package/dist/typescript/core/focus.d.ts.map +1 -0
  55. package/dist/typescript/core/focus.js +88 -0
  56. package/dist/typescript/core/focus.js.map +1 -0
  57. package/dist/typescript/core/focusable.d.ts +2 -0
  58. package/dist/typescript/core/focusable.d.ts.map +1 -0
  59. package/dist/typescript/core/focusable.js +36 -0
  60. package/dist/typescript/core/focusable.js.map +1 -0
  61. package/dist/typescript/core/form.d.ts +2 -0
  62. package/dist/typescript/core/form.d.ts.map +1 -0
  63. package/dist/typescript/core/form.js +76 -0
  64. package/dist/typescript/core/form.js.map +1 -0
  65. package/dist/typescript/core/frame.d.ts +8 -0
  66. package/dist/typescript/core/frame.d.ts.map +1 -0
  67. package/dist/typescript/core/frame.js +95 -0
  68. package/dist/typescript/core/frame.js.map +1 -0
  69. package/dist/typescript/core/geometry.d.ts +28 -0
  70. package/dist/typescript/core/geometry.d.ts.map +1 -0
  71. package/dist/typescript/core/geometry.js +134 -0
  72. package/dist/typescript/core/geometry.js.map +1 -0
  73. package/dist/typescript/core/inject.d.ts +21 -0
  74. package/dist/typescript/core/inject.d.ts.map +1 -0
  75. package/dist/typescript/core/inject.js +282 -0
  76. package/dist/typescript/core/inject.js.map +1 -0
  77. package/dist/typescript/core/interactable.d.ts +2 -0
  78. package/dist/typescript/core/interactable.d.ts.map +1 -0
  79. package/dist/typescript/core/interactable.js +27 -0
  80. package/dist/typescript/core/interactable.js.map +1 -0
  81. package/dist/typescript/core/keyboard.d.ts +15 -0
  82. package/dist/typescript/core/keyboard.d.ts.map +1 -0
  83. package/dist/typescript/core/keyboard.js +356 -0
  84. package/dist/typescript/core/keyboard.js.map +1 -0
  85. package/dist/typescript/core/keys.d.ts +65 -0
  86. package/dist/typescript/core/keys.d.ts.map +1 -0
  87. package/dist/typescript/core/keys.js +125 -0
  88. package/dist/typescript/core/keys.js.map +1 -0
  89. package/dist/typescript/core/locators.d.ts +6 -0
  90. package/dist/typescript/core/locators.d.ts.map +1 -0
  91. package/dist/typescript/core/locators.js +610 -0
  92. package/dist/typescript/core/locators.js.map +1 -0
  93. package/dist/typescript/core/mouse.d.ts +17 -0
  94. package/dist/typescript/core/mouse.d.ts.map +1 -0
  95. package/dist/typescript/core/mouse.js +186 -0
  96. package/dist/typescript/core/mouse.js.map +1 -0
  97. package/dist/typescript/core/overflow.d.ts +5 -0
  98. package/dist/typescript/core/overflow.d.ts.map +1 -0
  99. package/dist/typescript/core/overflow.js +133 -0
  100. package/dist/typescript/core/overflow.js.map +1 -0
  101. package/dist/typescript/core/scroll.d.ts +3 -0
  102. package/dist/typescript/core/scroll.d.ts.map +1 -0
  103. package/dist/typescript/core/scroll.js +77 -0
  104. package/dist/typescript/core/scroll.js.map +1 -0
  105. package/dist/typescript/core/shown.d.ts +3 -0
  106. package/dist/typescript/core/shown.d.ts.map +1 -0
  107. package/dist/typescript/core/shown.js +190 -0
  108. package/dist/typescript/core/shown.js.map +1 -0
  109. package/dist/typescript/core/storage.d.ts +14 -0
  110. package/dist/typescript/core/storage.d.ts.map +1 -0
  111. package/dist/typescript/core/storage.js +98 -0
  112. package/dist/typescript/core/storage.js.map +1 -0
  113. package/dist/typescript/core/style.d.ts +2 -0
  114. package/dist/typescript/core/style.d.ts.map +1 -0
  115. package/dist/typescript/core/style.js +32 -0
  116. package/dist/typescript/core/style.js.map +1 -0
  117. package/dist/typescript/core/useragent.d.ts +3 -0
  118. package/dist/typescript/core/useragent.d.ts.map +1 -0
  119. package/dist/typescript/core/useragent.js +31 -0
  120. package/dist/typescript/core/useragent.js.map +1 -0
  121. package/dist/typescript/default-content.d.ts +2 -0
  122. package/dist/typescript/default-content.d.ts.map +1 -0
  123. package/dist/typescript/default-content.js +20 -0
  124. package/dist/typescript/default-content.js.map +1 -0
  125. package/dist/typescript/execute-async-script.d.ts +2 -0
  126. package/dist/typescript/execute-async-script.d.ts.map +1 -0
  127. package/dist/typescript/execute-async-script.js +20 -0
  128. package/dist/typescript/execute-async-script.js.map +1 -0
  129. package/dist/typescript/execute-script.d.ts +2 -0
  130. package/dist/typescript/execute-script.d.ts.map +1 -0
  131. package/dist/typescript/execute-script.js +20 -0
  132. package/dist/typescript/execute-script.js.map +1 -0
  133. package/dist/typescript/find-element-fragment.d.ts +8 -0
  134. package/dist/typescript/find-element-fragment.d.ts.map +1 -0
  135. package/dist/typescript/find-element-fragment.js +39 -0
  136. package/dist/typescript/find-element-fragment.js.map +1 -0
  137. package/dist/typescript/find-element.d.ts +2 -0
  138. package/dist/typescript/find-element.d.ts.map +1 -0
  139. package/dist/typescript/find-element.js +18 -0
  140. package/dist/typescript/find-element.js.map +1 -0
  141. package/dist/typescript/find-elements.d.ts +1 -2
  142. package/dist/typescript/find-elements.d.ts.map +1 -1
  143. package/dist/typescript/find-elements.js +1 -289
  144. package/dist/typescript/find-elements.js.map +1 -1
  145. package/dist/typescript/frame-by-id-or-name.d.ts +2 -0
  146. package/dist/typescript/frame-by-id-or-name.d.ts.map +1 -0
  147. package/dist/typescript/frame-by-id-or-name.js +22 -0
  148. package/dist/typescript/frame-by-id-or-name.js.map +1 -0
  149. package/dist/typescript/frame-by-index.d.ts +2 -0
  150. package/dist/typescript/frame-by-index.d.ts.map +1 -0
  151. package/dist/typescript/frame-by-index.js +19 -0
  152. package/dist/typescript/frame-by-index.js.map +1 -0
  153. package/dist/typescript/get-attribute-value.d.ts +2 -0
  154. package/dist/typescript/get-attribute-value.d.ts.map +1 -0
  155. package/dist/typescript/get-attribute-value.js +22 -0
  156. package/dist/typescript/get-attribute-value.js.map +1 -0
  157. package/dist/typescript/get-effective-style.d.ts +3 -0
  158. package/dist/typescript/get-effective-style.d.ts.map +1 -0
  159. package/dist/typescript/get-effective-style.js +84 -0
  160. package/dist/typescript/get-effective-style.js.map +1 -0
  161. package/dist/typescript/get-element-from-cache.d.ts +2 -0
  162. package/dist/typescript/get-element-from-cache.d.ts.map +1 -0
  163. package/dist/typescript/get-element-from-cache.js +20 -0
  164. package/dist/typescript/get-element-from-cache.js.map +1 -0
  165. package/dist/typescript/get-frame-window.d.ts +2 -0
  166. package/dist/typescript/get-frame-window.d.ts.map +1 -0
  167. package/dist/typescript/get-frame-window.js +22 -0
  168. package/dist/typescript/get-frame-window.js.map +1 -0
  169. package/dist/typescript/get-local-storage-item.d.ts +3 -0
  170. package/dist/typescript/get-local-storage-item.d.ts.map +1 -0
  171. package/dist/typescript/get-local-storage-item.js +25 -0
  172. package/dist/typescript/get-local-storage-item.js.map +1 -0
  173. package/dist/typescript/get-local-storage-key.d.ts +3 -0
  174. package/dist/typescript/get-local-storage-key.d.ts.map +1 -0
  175. package/dist/typescript/get-local-storage-key.js +26 -0
  176. package/dist/typescript/get-local-storage-key.js.map +1 -0
  177. package/dist/typescript/get-local-storage-keys.d.ts +3 -0
  178. package/dist/typescript/get-local-storage-keys.d.ts.map +1 -0
  179. package/dist/typescript/get-local-storage-keys.js +25 -0
  180. package/dist/typescript/get-local-storage-keys.js.map +1 -0
  181. package/dist/typescript/get-local-storage-size.d.ts +3 -0
  182. package/dist/typescript/get-local-storage-size.d.ts.map +1 -0
  183. package/dist/typescript/get-local-storage-size.js +25 -0
  184. package/dist/typescript/get-local-storage-size.js.map +1 -0
  185. package/dist/typescript/get-location.d.ts +9 -0
  186. package/dist/typescript/get-location.d.ts.map +1 -0
  187. package/dist/typescript/get-location.js +49 -0
  188. package/dist/typescript/get-location.js.map +1 -0
  189. package/dist/typescript/get-session-storage-item.d.ts +3 -0
  190. package/dist/typescript/get-session-storage-item.d.ts.map +1 -0
  191. package/dist/typescript/get-session-storage-item.js +25 -0
  192. package/dist/typescript/get-session-storage-item.js.map +1 -0
  193. package/dist/typescript/get-session-storage-key.d.ts +3 -0
  194. package/dist/typescript/get-session-storage-key.d.ts.map +1 -0
  195. package/dist/typescript/get-session-storage-key.js +26 -0
  196. package/dist/typescript/get-session-storage-key.js.map +1 -0
  197. package/dist/typescript/get-session-storage-keys.d.ts +3 -0
  198. package/dist/typescript/get-session-storage-keys.d.ts.map +1 -0
  199. package/dist/typescript/get-session-storage-keys.js +25 -0
  200. package/dist/typescript/get-session-storage-keys.js.map +1 -0
  201. package/dist/typescript/get-session-storage-size.d.ts +3 -0
  202. package/dist/typescript/get-session-storage-size.d.ts.map +1 -0
  203. package/dist/typescript/get-session-storage-size.js +25 -0
  204. package/dist/typescript/get-session-storage-size.js.map +1 -0
  205. package/dist/typescript/get-size.d.ts +7 -0
  206. package/dist/typescript/get-size.d.ts.map +1 -0
  207. package/dist/typescript/get-size.js +36 -0
  208. package/dist/typescript/get-size.js.map +1 -0
  209. package/dist/typescript/get-text.d.ts +3 -0
  210. package/dist/typescript/get-text.d.ts.map +1 -0
  211. package/dist/typescript/get-text.js +294 -0
  212. package/dist/typescript/get-text.js.map +1 -0
  213. package/dist/typescript/get-top-left-coordinates.d.ts +4 -0
  214. package/dist/typescript/get-top-left-coordinates.d.ts.map +1 -0
  215. package/dist/typescript/get-top-left-coordinates.js +36 -0
  216. package/dist/typescript/get-top-left-coordinates.js.map +1 -0
  217. package/dist/typescript/is-displayed.d.ts +1 -2
  218. package/dist/typescript/is-displayed.d.ts.map +1 -1
  219. package/dist/typescript/is-displayed.js +3 -396
  220. package/dist/typescript/is-displayed.js.map +1 -1
  221. package/dist/typescript/is-editable.d.ts +2 -0
  222. package/dist/typescript/is-editable.d.ts.map +1 -0
  223. package/dist/typescript/is-editable.js +18 -0
  224. package/dist/typescript/is-editable.js.map +1 -0
  225. package/dist/typescript/is-enabled.d.ts +2 -0
  226. package/dist/typescript/is-enabled.d.ts.map +1 -0
  227. package/dist/typescript/is-enabled.js +18 -0
  228. package/dist/typescript/is-enabled.js.map +1 -0
  229. package/dist/typescript/is-focusable.d.ts +2 -0
  230. package/dist/typescript/is-focusable.d.ts.map +1 -0
  231. package/dist/typescript/is-focusable.js +20 -0
  232. package/dist/typescript/is-focusable.js.map +1 -0
  233. package/dist/typescript/is-interactable.d.ts +2 -0
  234. package/dist/typescript/is-interactable.d.ts.map +1 -0
  235. package/dist/typescript/is-interactable.js +19 -0
  236. package/dist/typescript/is-interactable.js.map +1 -0
  237. package/dist/typescript/is-selected.d.ts +3 -0
  238. package/dist/typescript/is-selected.d.ts.map +1 -0
  239. package/dist/typescript/is-selected.js +29 -0
  240. package/dist/typescript/is-selected.js.map +1 -0
  241. package/dist/typescript/remove-local-storage-item.d.ts +3 -0
  242. package/dist/typescript/remove-local-storage-item.d.ts.map +1 -0
  243. package/dist/typescript/remove-local-storage-item.js +25 -0
  244. package/dist/typescript/remove-local-storage-item.js.map +1 -0
  245. package/dist/typescript/remove-session-storage-item.d.ts +3 -0
  246. package/dist/typescript/remove-session-storage-item.d.ts.map +1 -0
  247. package/dist/typescript/remove-session-storage-item.js +25 -0
  248. package/dist/typescript/remove-session-storage-item.js.map +1 -0
  249. package/dist/typescript/set-local-storage-item.d.ts +3 -0
  250. package/dist/typescript/set-local-storage-item.d.ts.map +1 -0
  251. package/dist/typescript/set-local-storage-item.js +26 -0
  252. package/dist/typescript/set-local-storage-item.js.map +1 -0
  253. package/dist/typescript/set-session-storage-item.d.ts +3 -0
  254. package/dist/typescript/set-session-storage-item.d.ts.map +1 -0
  255. package/dist/typescript/set-session-storage-item.js +26 -0
  256. package/dist/typescript/set-session-storage-item.js.map +1 -0
  257. package/dist/typescript/submit.d.ts +3 -0
  258. package/dist/typescript/submit.d.ts.map +1 -0
  259. package/dist/typescript/submit.js +50 -0
  260. package/dist/typescript/submit.js.map +1 -0
  261. package/dist/typescript/type.d.ts +3 -0
  262. package/dist/typescript/type.d.ts.map +1 -0
  263. package/dist/typescript/type.js +201 -0
  264. package/dist/typescript/type.js.map +1 -0
  265. package/index.ts +40 -0
  266. package/package.json +292 -5
  267. package/typescript/active-element.ts +19 -0
  268. package/typescript/clear-local-storage.ts +27 -0
  269. package/typescript/clear-session-storage.ts +27 -0
  270. package/typescript/clear.ts +73 -0
  271. package/typescript/click.ts +55 -0
  272. package/typescript/core/attribute.ts +68 -0
  273. package/typescript/core/color.ts +257 -0
  274. package/typescript/core/editable.ts +63 -0
  275. package/typescript/core/element.ts +110 -0
  276. package/typescript/core/enabled.ts +76 -0
  277. package/typescript/core/error.ts +41 -0
  278. package/typescript/core/events.ts +268 -0
  279. package/typescript/core/focus.ts +92 -0
  280. package/typescript/core/focusable.ts +38 -0
  281. package/typescript/core/form.ts +81 -0
  282. package/typescript/core/frame.ts +105 -0
  283. package/typescript/core/geometry.ts +183 -0
  284. package/typescript/core/inject.ts +336 -0
  285. package/typescript/core/interactable.ts +30 -0
  286. package/typescript/core/keyboard.ts +369 -0
  287. package/typescript/core/keys.ts +204 -0
  288. package/typescript/core/locators.ts +704 -0
  289. package/typescript/core/mouse.ts +211 -0
  290. package/typescript/core/overflow.ts +172 -0
  291. package/typescript/core/scroll.ts +92 -0
  292. package/typescript/core/shown.ts +233 -0
  293. package/typescript/core/storage.ts +111 -0
  294. package/typescript/core/style.ts +32 -0
  295. package/typescript/core/useragent.ts +33 -0
  296. package/typescript/default-content.ts +20 -0
  297. package/typescript/execute-async-script.ts +20 -0
  298. package/typescript/execute-script.ts +20 -0
  299. package/typescript/find-element-fragment.ts +45 -0
  300. package/typescript/find-element.ts +18 -0
  301. package/typescript/find-elements.ts +1 -326
  302. package/typescript/frame-by-id-or-name.ts +22 -0
  303. package/typescript/frame-by-index.ts +19 -0
  304. package/typescript/get-attribute-value.ts +22 -0
  305. package/typescript/get-effective-style.ts +93 -0
  306. package/typescript/get-element-from-cache.ts +20 -0
  307. package/typescript/get-frame-window.ts +22 -0
  308. package/typescript/get-local-storage-item.ts +27 -0
  309. package/typescript/get-local-storage-key.ts +28 -0
  310. package/typescript/get-local-storage-keys.ts +27 -0
  311. package/typescript/get-local-storage-size.ts +27 -0
  312. package/typescript/get-location.ts +63 -0
  313. package/typescript/get-session-storage-item.ts +27 -0
  314. package/typescript/get-session-storage-key.ts +28 -0
  315. package/typescript/get-session-storage-keys.ts +27 -0
  316. package/typescript/get-session-storage-size.ts +27 -0
  317. package/typescript/get-size.ts +43 -0
  318. package/typescript/get-text.ts +353 -0
  319. package/typescript/get-top-left-coordinates.ts +38 -0
  320. package/typescript/is-displayed.ts +3 -498
  321. package/typescript/is-editable.ts +18 -0
  322. package/typescript/is-enabled.ts +18 -0
  323. package/typescript/is-focusable.ts +20 -0
  324. package/typescript/is-interactable.ts +19 -0
  325. package/typescript/is-selected.ts +31 -0
  326. package/typescript/remove-local-storage-item.ts +27 -0
  327. package/typescript/remove-session-storage-item.ts +27 -0
  328. package/typescript/set-local-storage-item.ts +28 -0
  329. package/typescript/set-session-storage-item.ts +28 -0
  330. package/typescript/submit.ts +53 -0
  331. package/typescript/type.ts +210 -0
@@ -0,0 +1,63 @@
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 { getClientRect } from './core/geometry.js'
19
+ import isShown from './core/shown.js'
20
+
21
+ // goog.math.Rect's serialised form. The Closure atom returned that object and
22
+ // bindings read these four keys off the wire, so the shape is part of the
23
+ // contract -- deliberately not the six-sided Rect used inside core/geometry.
24
+ export interface Bounds {
25
+ left: number;
26
+ top: number;
27
+ width: number;
28
+ height: number;
29
+ }
30
+
31
+ // The element's bounds in page space, or null when it is not shown.
32
+ //
33
+ // This is webdriver.atoms.element.getLocation, which was
34
+ // goog.style.getBounds behind an isShown guard: page offset from
35
+ // goog.style.getPageOffset, size from goog.style.getSize.
36
+ //
37
+ // Page space rather than client space is the whole point of this atom -- the
38
+ // coordinates do not move when the document scrolls. get_top_left_coordinates
39
+ // is the client-space counterpart.
40
+ //
41
+ // The size half follows get_size in measuring the border box via
42
+ // getBoundingClientRect, so the two atoms cannot disagree about how big an
43
+ // element is. That makes the width and height fractional and transform-aware
44
+ // where goog.style.getSize's were integer and transform-ignorant.
45
+ function getLocation(element: Element): Bounds | null {
46
+ if (!isShown(element)) {
47
+ return null
48
+ }
49
+
50
+ const rect = getClientRect(element)
51
+ const win = element.ownerDocument.defaultView
52
+ const scrollX = win ? win.pageXOffset : 0
53
+ const scrollY = win ? win.pageYOffset : 0
54
+
55
+ return {
56
+ left: rect.left + scrollX,
57
+ top: rect.top + scrollY,
58
+ width: rect.width,
59
+ height: rect.height,
60
+ }
61
+ }
62
+
63
+ export default getLocation
@@ -0,0 +1,27 @@
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 { getSessionStorage } from './core/storage.js'
19
+
20
+ // The stored value, or null when the key is absent.
21
+ //
22
+ // optWindow targets a frame other than the one the atom is running in.
23
+ function getSessionStorageItem(key: string, optWindow?: Window): string | null {
24
+ return getSessionStorage(optWindow).getItem(key)
25
+ }
26
+
27
+ export default getSessionStorageItem
@@ -0,0 +1,28 @@
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 { getSessionStorage } from './core/storage.js'
19
+
20
+ // The key at a position in the store, or null when the index is out of range.
21
+ // Storage order is not specified, so this is only meaningful alongside size().
22
+ //
23
+ // optWindow targets a frame other than the one the atom is running in.
24
+ function getSessionStorageKey(index: number, optWindow?: Window): string | null {
25
+ return getSessionStorage(optWindow).key(index)
26
+ }
27
+
28
+ export default getSessionStorageKey
@@ -0,0 +1,27 @@
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 { getSessionStorage } from './core/storage.js'
19
+
20
+ // Every key in the store, as an Array.
21
+ //
22
+ // optWindow targets a frame other than the one the atom is running in.
23
+ function getSessionStorageKeys(optWindow?: Window): string[] {
24
+ return getSessionStorage(optWindow).keySet()
25
+ }
26
+
27
+ export default getSessionStorageKeys
@@ -0,0 +1,27 @@
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 { getSessionStorage } from './core/storage.js'
19
+
20
+ // How many key/value pairs the store holds.
21
+ //
22
+ // optWindow targets a frame other than the one the atom is running in.
23
+ function getSessionStorageSize(optWindow?: Window): number {
24
+ return getSessionStorage(optWindow).size()
25
+ }
26
+
27
+ export default getSessionStorageSize
@@ -0,0 +1,43 @@
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 { getClientRect } from './core/geometry.js'
19
+
20
+ export interface Size {
21
+ width: number;
22
+ height: number;
23
+ }
24
+
25
+ // The size of an element's border box, as W3C Get Element Rect defines it.
26
+ //
27
+ // This deliberately does not reproduce goog.style.getSize, which the Closure
28
+ // get-size fragment used. That function read offsetWidth/offsetHeight, so it
29
+ // was integer-valued and ignored transforms, and for a display:none element it
30
+ // temporarily rewrote visibility/position/display, measured, and restored --
31
+ // mutating the DOM mid-read to serve a caller that no longer exists. No
32
+ // Selenium binding consumes get-size, and Appium's own copy of this atom has
33
+ // no such behaviour either.
34
+ //
35
+ // A hidden element therefore measures 0x0 here. If a force-visible measurement
36
+ // is ever needed again it should arrive under its own name rather than be
37
+ // folded back into "size".
38
+ function getSize(element: Element): Size {
39
+ const rect = getClientRect(element)
40
+ return { width: rect.width, height: rect.height }
41
+ }
42
+
43
+ export default getSize
@@ -0,0 +1,353 @@
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 isShown from './core/shown.js'
19
+ import { isElement } from './core/element.js'
20
+ import { getEffectiveStyle } from './core/style.js'
21
+
22
+ // Display values that do not force a newline before and after the element.
23
+ // "none" is in this list because display:none elements are skipped entirely
24
+ // and should not contribute a line break to the running line.
25
+ // "table-cell" and the column-group values are inline for line-break purposes
26
+ // even though they lay out in a grid. (dom.js line 1149)
27
+ const INLINE_DISPLAY_BOXES: ReadonlyArray<string> = [
28
+ 'inline',
29
+ 'inline-block',
30
+ 'inline-table',
31
+ 'none',
32
+ 'table-cell',
33
+ 'table-column',
34
+ 'table-column-group',
35
+ ]
36
+
37
+ // Two patterns for text-transform:capitalize, applied in order: the first
38
+ // titlecases the first letter of each word; the second titlecases a letter
39
+ // that opens a "_"- or "*"-delimited run. Unicode property escapes require the
40
+ // ES2015 "u" flag; the catch block supplies Latin-only fallback patterns for
41
+ // any engine that does not support them. (dom.js lines 1178-1193)
42
+ //
43
+ // NOTE: All patterns here use the RegExp constructor rather than literals.
44
+ // The fallback patterns use \uXXXX in string form so they survive any source
45
+ // file encoding that might convert the escape to a literal character (which
46
+ // would then be treated as a line terminator by the TypeScript parser).
47
+ const CAPITALIZE_PATTERNS: ReadonlyArray<RegExp> = (function () {
48
+ var letter = '\\p{L}\\u24B6-\\u24E9'
49
+ var wordCharacter = '\'_\\p{M}\\p{N}' + letter
50
+ try {
51
+ return [
52
+ new RegExp('(^|[^' + wordCharacter + '])([' + letter + '])', 'gu'),
53
+ new RegExp(
54
+ '(^|[^' + wordCharacter + '])([_*])([' + letter + '])', 'gu'),
55
+ ]
56
+ } catch (_ignored) {
57
+ // Latin-only fallback for engines without Unicode property escape support.
58
+ var latinLetters = 'A-Za-z\\u00C0-\\u02AF\\u1E00-\\u1EFF\\u24B6-\\u24E9'
59
+ var wordChars = '\'_0-9' + latinLetters + '\\u0300-\\u036F\\u1AB0-\\u1AFF\\u1DC0-\\u1DFF'
60
+ var lowerLetters = 'A-Za-z\\u00C0-\\u02AF\\u1E00-\\u1EFF\\u24D0-\\u24E9'
61
+ return [
62
+ new RegExp('(^|[^' + wordChars + '])([' + latinLetters + '])', 'g'),
63
+ new RegExp('(^|[^' + wordChars + '])([_*])([' + lowerLetters + '])', 'g'),
64
+ ]
65
+ }
66
+ })()
67
+
68
+ // U+2028 (LINE SEPARATOR) and U+2029 (PARAGRAPH SEPARATOR) are treated as
69
+ // breaking spaces by the spec and as line terminators by ES2017 and earlier,
70
+ // so they cannot appear literally inside a regex literal in TypeScript source.
71
+ // Use the RegExp constructor instead. (dom.js lines 1226-1230)
72
+ const BREAKING_SPACE_RE = new RegExp('[ \\f\\t\\v\\u2028\\u2029]+', 'g')
73
+ const PRE_SPACE_RE = new RegExp('[ \\f\\t\\v\\u2028\\u2029]', 'g')
74
+
75
+ // Trims all whitespace except NBSP (\xa0) from both ends of a string.
76
+ // (dom.js line 999: bot.dom.trimExcludingNonBreakingSpaceCharacters_)
77
+ function trimExcludingNbsp(str: string): string {
78
+ return str.replace(/^[^\S\xa0]+|[^\S\xa0]+$/g, '')
79
+ }
80
+
81
+ // goog.string.isEmptyOrWhitespace treats \xa0 as whitespace for this check.
82
+ // (referenced at dom.js lines 1079, 1115)
83
+ function isEmptyOrWhitespace(str: string): boolean {
84
+ return /^[\s\xa0]*$/.test(str)
85
+ }
86
+
87
+ // Joins the accumulated lines with '\n', trims each line and the overall
88
+ // result (excluding NBSP), then converts all remaining NBSP to regular spaces.
89
+ // (dom.js line 1010: bot.dom.concatenateCleanedLines_)
90
+ function concatenateCleanedLines(lines: string[]): string {
91
+ const trimmedLines = lines.map(trimExcludingNbsp)
92
+ const joined = trimmedLines.join('\n')
93
+ const trimmed = trimExcludingNbsp(joined)
94
+ return trimmed.replace(/\xa0/g, ' ')
95
+ }
96
+
97
+ // Appends the visible contribution of a text node to the running lines array,
98
+ // applying white-space collapsing rules and text-transform.
99
+ // (dom.js line 1203: bot.dom.appendVisibleTextLinesFromTextNode_)
100
+ function appendTextFromTextNode(
101
+ textNode: Text,
102
+ lines: string[],
103
+ whitespace: string | null,
104
+ textTransform: string | null,
105
+ ): void {
106
+ // Strip zero-width non-printing characters before regularising spaces, so
107
+ // the zero-width space, which is technically also a space, is not
108
+ // promoted to a regular space. (dom.js 1213)
109
+ // Stripped: U+200B (zero-width space), U+200E (LTR mark), U+200F (RTL mark).
110
+ var text = (textNode.nodeValue || '').replace(/[\u200b\u200e\u200f]/g, '')
111
+
112
+ // goog.string.canonicalizeNewlines: normalise \r\n and bare \r to \n.
113
+ // (dom.js 1218)
114
+ text = text.replace(/(\r\n|\r|\n)/g, '\n')
115
+
116
+ // white-space: normal and nowrap collapse newlines into spaces.
117
+ if (whitespace === 'normal' || whitespace === 'nowrap') {
118
+ text = text.replace(/\n/g, ' ')
119
+ }
120
+
121
+ // white-space: pre and pre-wrap protect internal spacing by converting
122
+ // breaking spaces to NBSP so they survive the later collapsing pass.
123
+ // All other white-space values collapse runs of breaking space to one space.
124
+ // PRE_SPACE_RE and BREAKING_SPACE_RE cover space, \f, \t, \v, U+2028, U+2029
125
+ // (dom.js 1226-1230; constructed as RegExp to avoid literal line terminators)
126
+ if (whitespace === 'pre' || whitespace === 'pre-wrap') {
127
+ text = text.replace(PRE_SPACE_RE, '\xa0')
128
+ } else {
129
+ text = text.replace(BREAKING_SPACE_RE, ' ')
130
+ }
131
+
132
+ // text-transform. The capitalize path applies both patterns in sequence:
133
+ // pattern 0 handles word-initial letters, pattern 1 handles letters
134
+ // immediately after a '_' or '*' that opens a run. (dom.js 1232-1247)
135
+ if (textTransform === 'capitalize') {
136
+ text = text.replace(CAPITALIZE_PATTERNS[0], function () {
137
+ return arguments[1] + (arguments[2] as string).toUpperCase()
138
+ })
139
+ text = text.replace(CAPITALIZE_PATTERNS[1], function () {
140
+ return arguments[1] + arguments[2] + (arguments[3] as string).toUpperCase()
141
+ })
142
+ } else if (textTransform === 'uppercase') {
143
+ text = text.toUpperCase()
144
+ } else if (textTransform === 'lowercase') {
145
+ text = text.toLowerCase()
146
+ }
147
+
148
+ // Merge into the last accumulated line. If the current line already ends
149
+ // with a space and the new text starts with one, drop the duplicate.
150
+ // (dom.js 1249-1254)
151
+ var currLine = lines.pop() || ''
152
+ if (currLine.endsWith(' ') && text.startsWith(' ')) {
153
+ text = text.substring(1)
154
+ }
155
+ lines.push(currLine + text)
156
+ }
157
+
158
+ // Core element traversal shared by both the flat-DOM and composed-DOM paths.
159
+ // isShownFn and childNodeFn are injected so each path plugs in its own
160
+ // visibility check and child dispatch. (dom.js lines 1049-1119)
161
+ function appendTextFromElementCommon(
162
+ elem: Element,
163
+ lines: string[],
164
+ isShownFn: (e: Element) => boolean,
165
+ childNodeFn: (
166
+ node: Node,
167
+ lines: string[],
168
+ shown: boolean,
169
+ whitespace: string | null,
170
+ textTransform: string | null,
171
+ ) => void,
172
+ ): void {
173
+ function currLine(): string {
174
+ return lines[lines.length - 1] ?? ''
175
+ }
176
+
177
+ // Guarded through a Node-typed alias: isElement returns `node is Element`,
178
+ // so testing elem directly would narrow it to never for the whole of the
179
+ // early-return's else path. isElement rather than a nodeName comparison
180
+ // because it uppercases for XML documents and reads tagName through its
181
+ // descriptor, which a clobbering `name="tagName"` cannot shadow.
182
+ const node: Node = elem
183
+ if (isElement(node, 'BR')) {
184
+ lines.push('')
185
+ return
186
+ }
187
+
188
+ const isTD = isElement(elem, 'TD')
189
+ const display = getEffectiveStyle(elem, 'display')
190
+ // <td> sometimes reports a block display value; treat it as inline so it
191
+ // behaves like a table cell for newline purposes. (dom.js 1063)
192
+ const isBlock = !isTD && !INLINE_DISPLAY_BOXES.includes(display || '')
193
+
194
+ // Insert a newline before a block element when the current line is non-empty,
195
+ // unless the previous sibling uses display:run-in (which flows into this
196
+ // element). A floated element is never run into. (dom.js 1070-1081)
197
+ // Dropped: styleFloat (IE-only). getPropertyValue('float') is the CSS name.
198
+ const previousElementSibling = elem.previousElementSibling
199
+ const prevDisplay = previousElementSibling
200
+ ? getEffectiveStyle(previousElementSibling, 'display')
201
+ : ''
202
+ const thisFloat = getEffectiveStyle(elem, 'float')
203
+ const runIntoThis = prevDisplay === 'run-in' && thisFloat === 'none'
204
+ if (isBlock && !runIntoThis && !isEmptyOrWhitespace(currLine())) {
205
+ lines.push('')
206
+ }
207
+
208
+ // A non-shown element still traverses its children so that a child with an
209
+ // explicit visibility:visible can contribute its text even when the parent
210
+ // has visibility:hidden. Text nodes that are direct children of a non-shown
211
+ // element are silenced via shown=false. (dom.js 1084-1088)
212
+ const shown = isShownFn(elem)
213
+
214
+ var whitespace: string | null = null
215
+ var textTransform: string | null = null
216
+ if (shown) {
217
+ whitespace = getEffectiveStyle(elem, 'white-space')
218
+ textTransform = getEffectiveStyle(elem, 'text-transform')
219
+ }
220
+
221
+ for (var i = 0; i < elem.childNodes.length; i++) {
222
+ childNodeFn(elem.childNodes[i], lines, shown, whitespace, textTransform)
223
+ }
224
+
225
+ const line = currLine()
226
+
227
+ // Table cells are separated by a space, not a tab. (dom.js 1107-1110)
228
+ if ((isTD || display === 'table-cell') && line && !line.endsWith(' ')) {
229
+ lines[lines.length - 1] += ' '
230
+ }
231
+
232
+ // Insert a newline after a block element when there is content on the
233
+ // current line, unless this element itself uses display:run-in.
234
+ // (dom.js 1114-1117)
235
+ if (isBlock && display !== 'run-in' && !isEmptyOrWhitespace(line)) {
236
+ lines.push('')
237
+ }
238
+ }
239
+
240
+ // Flat-DOM traversal: no Shadow DOM awareness.
241
+ // (dom.js lines 1127-1140: bot.dom.appendVisibleTextLinesFromElement_)
242
+ function appendTextFromElement(elem: Element, lines: string[]): void {
243
+ appendTextFromElementCommon(
244
+ elem,
245
+ lines,
246
+ isShown,
247
+ function (node, lines, shown, whitespace, textTransform) {
248
+ if (node.nodeType === Node.TEXT_NODE && shown) {
249
+ appendTextFromTextNode(
250
+ node as Text, lines, whitespace, textTransform)
251
+ } else if (isElement(node)) {
252
+ appendTextFromElement(node as Element, lines)
253
+ }
254
+ },
255
+ )
256
+ }
257
+
258
+ // Whether a node has been distributed (slotted) into a Shadow DOM element to
259
+ // be rendered elsewhere. When true the node must not be appended from its
260
+ // original position — the slot will append it. (dom.js lines 1437-1448)
261
+ // Dropped: getDestinationInsertionPoints (Shadow DOM v0, removed from browsers).
262
+ function isNodeDistributedIntoShadowDom(node: Node): boolean {
263
+ if (node.nodeType === Node.ELEMENT_NODE || node.nodeType === Node.TEXT_NODE) {
264
+ var slottable = node as Node & { assignedSlot?: HTMLSlotElement | null }
265
+ return slottable.assignedSlot != null
266
+ }
267
+ return false
268
+ }
269
+
270
+ // Composed-DOM node dispatch (Shadow DOM v1).
271
+ // (dom.js lines 1363-1428: bot.dom.appendVisibleTextLinesFromNodeInComposedDom_)
272
+ // Dropped: <CONTENT> element (Shadow DOM v0 only).
273
+ // Dropped: <SHADOW> element and olderShadowRoot (Shadow DOM v0 only).
274
+ function appendTextFromNodeInComposedDom(
275
+ node: Node,
276
+ lines: string[],
277
+ shown: boolean,
278
+ whitespace: string | null,
279
+ textTransform: string | null,
280
+ ): void {
281
+ if (node.nodeType === Node.TEXT_NODE && shown) {
282
+ appendTextFromTextNode(node as Text, lines, whitespace, textTransform)
283
+ } else if (isElement(node)) {
284
+ const castElem = node as Element
285
+ if (isElement(node, 'SLOT')) {
286
+ // <slot> distributes its assigned nodes. Walk up to see whether we're
287
+ // inside a ShadowRoot; if not, fall through to treat it as an unknown
288
+ // element. (dom.js 1373-1399 adapted for v1)
289
+ var parentNode: Node = node
290
+ while (parentNode.parentNode) {
291
+ parentNode = parentNode.parentNode
292
+ }
293
+ if (typeof ShadowRoot === 'function' && parentNode instanceof ShadowRoot) {
294
+ const slot = node as HTMLSlotElement
295
+ const assigned = slot.assignedNodes()
296
+ const childrenToTraverse: ArrayLike<Node> =
297
+ assigned.length > 0 ? assigned : slot.childNodes
298
+ for (var i = 0; i < childrenToTraverse.length; i++) {
299
+ appendTextFromNodeInComposedDom(
300
+ childrenToTraverse[i], lines, shown, whitespace, textTransform)
301
+ }
302
+ } else {
303
+ appendTextFromElementInComposedDom(castElem, lines)
304
+ }
305
+ } else {
306
+ appendTextFromElementInComposedDom(castElem, lines)
307
+ }
308
+ }
309
+ }
310
+
311
+ // Composed-DOM element traversal (Shadow DOM v1). Expands shadow roots before
312
+ // processing the element's own children so that slotted content is encountered
313
+ // in display order. (dom.js lines 1457-1481)
314
+ function appendTextFromElementInComposedDom(
315
+ elem: Element,
316
+ lines: string[],
317
+ ): void {
318
+ if (elem.shadowRoot) {
319
+ const whitespace = getEffectiveStyle(elem, 'white-space')
320
+ const textTransform = getEffectiveStyle(elem, 'text-transform')
321
+ elem.shadowRoot.childNodes.forEach(node =>
322
+ appendTextFromNodeInComposedDom(node, lines, true, whitespace, textTransform))
323
+ }
324
+
325
+ appendTextFromElementCommon(
326
+ elem,
327
+ lines,
328
+ isShown,
329
+ function (node, lines, shown, whitespace, textTransform) {
330
+ // Skip nodes that have been slotted elsewhere; they will be appended
331
+ // from their slot position in the composed tree. (dom.js 1472-1479)
332
+ if (!isNodeDistributedIntoShadowDom(node)) {
333
+ appendTextFromNodeInComposedDom(node, lines, shown, whitespace, textTransform)
334
+ }
335
+ },
336
+ )
337
+ }
338
+
339
+ // Returns the visible text of an element, matching bot.dom.getVisibleText and
340
+ // webdriver.atoms.element.getText. Uses the composed-DOM path on browsers that
341
+ // support ShadowRoot (every browser we support), falling back to the flat-DOM
342
+ // path otherwise. (dom.js lines 1026-1035)
343
+ function getText(element: Element): string {
344
+ const lines: string[] = []
345
+ if (typeof ShadowRoot === 'function') {
346
+ appendTextFromElementInComposedDom(element, lines)
347
+ } else {
348
+ appendTextFromElement(element, lines)
349
+ }
350
+ return concatenateCleanedLines(lines)
351
+ }
352
+
353
+ export default getText
@@ -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 { Coordinate, Region, getClientRegion } from './core/geometry.js'
19
+ import { scrollIntoView } from './core/scroll.js'
20
+
21
+ // Scrolls the element into the viewport and returns its position in client
22
+ // space.
23
+ //
24
+ // This is webdriver.atoms.element.getLocationInView, and it is the one atom
25
+ // outside the inject layer that mutates page state: it scrolls, and the scroll
26
+ // position is still changed when it returns. Callers that only want to read a
27
+ // position want get_location, which is page-space and moves nothing.
28
+ //
29
+ // optRegion narrows the target to a sub-region of the element, which is how
30
+ // callers scroll a specific point -- a click target, say -- into view rather
31
+ // than the element as a whole.
32
+ function getTopLeftCoordinates(element: Element, optRegion?: Region): Coordinate {
33
+ scrollIntoView(element, optRegion)
34
+ const region = getClientRegion(element, optRegion)
35
+ return { x: region.left, y: region.top }
36
+ }
37
+
38
+ export default getTopLeftCoordinates