@selenium/atoms 4.51.0-nightly202609302012 → 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.
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -1
- package/dist/typescript/active-element.d.ts +2 -0
- package/dist/typescript/active-element.d.ts.map +1 -0
- package/dist/typescript/active-element.js +19 -0
- package/dist/typescript/active-element.js.map +1 -0
- package/dist/typescript/clear-local-storage.d.ts +3 -0
- package/dist/typescript/clear-local-storage.d.ts.map +1 -0
- package/dist/typescript/clear-local-storage.js +25 -0
- package/dist/typescript/clear-local-storage.js.map +1 -0
- package/dist/typescript/clear-session-storage.d.ts +3 -0
- package/dist/typescript/clear-session-storage.d.ts.map +1 -0
- package/dist/typescript/clear-session-storage.js +25 -0
- package/dist/typescript/clear-session-storage.js.map +1 -0
- package/dist/typescript/clear.d.ts +3 -0
- package/dist/typescript/clear.d.ts.map +1 -0
- package/dist/typescript/clear.js +67 -0
- package/dist/typescript/clear.js.map +1 -0
- package/dist/typescript/click.d.ts +4 -0
- package/dist/typescript/click.d.ts.map +1 -0
- package/dist/typescript/click.js +52 -0
- package/dist/typescript/click.js.map +1 -0
- package/dist/typescript/core/attribute.d.ts +3 -0
- package/dist/typescript/core/attribute.d.ts.map +1 -0
- package/dist/typescript/core/attribute.js +60 -0
- package/dist/typescript/core/attribute.js.map +1 -0
- package/dist/typescript/core/color.d.ts +2 -0
- package/dist/typescript/core/color.d.ts.map +1 -0
- package/dist/typescript/core/color.js +248 -0
- package/dist/typescript/core/color.js.map +1 -0
- package/dist/typescript/core/editable.d.ts +5 -0
- package/dist/typescript/core/editable.d.ts.map +1 -0
- package/dist/typescript/core/editable.js +55 -0
- package/dist/typescript/core/editable.js.map +1 -0
- package/dist/typescript/core/element.d.ts +6 -0
- package/dist/typescript/core/element.d.ts.map +1 -0
- package/dist/typescript/core/element.js +97 -0
- package/dist/typescript/core/element.js.map +1 -0
- package/dist/typescript/core/enabled.d.ts +2 -0
- package/dist/typescript/core/enabled.d.ts.map +1 -0
- package/dist/typescript/core/enabled.js +69 -0
- package/dist/typescript/core/enabled.js.map +1 -0
- package/dist/typescript/core/error.d.ts +13 -0
- package/dist/typescript/core/error.d.ts.map +1 -0
- package/dist/typescript/core/error.js +40 -0
- package/dist/typescript/core/error.js.map +1 -0
- package/dist/typescript/core/events.d.ts +91 -0
- package/dist/typescript/core/events.d.ts.map +1 -0
- package/dist/typescript/core/events.js +131 -0
- package/dist/typescript/core/events.js.map +1 -0
- package/dist/typescript/core/focus.d.ts +4 -0
- package/dist/typescript/core/focus.d.ts.map +1 -0
- package/dist/typescript/core/focus.js +88 -0
- package/dist/typescript/core/focus.js.map +1 -0
- package/dist/typescript/core/focusable.d.ts +2 -0
- package/dist/typescript/core/focusable.d.ts.map +1 -0
- package/dist/typescript/core/focusable.js +36 -0
- package/dist/typescript/core/focusable.js.map +1 -0
- package/dist/typescript/core/form.d.ts +2 -0
- package/dist/typescript/core/form.d.ts.map +1 -0
- package/dist/typescript/core/form.js +76 -0
- package/dist/typescript/core/form.js.map +1 -0
- package/dist/typescript/core/frame.d.ts +8 -0
- package/dist/typescript/core/frame.d.ts.map +1 -0
- package/dist/typescript/core/frame.js +95 -0
- package/dist/typescript/core/frame.js.map +1 -0
- package/dist/typescript/core/geometry.d.ts +28 -0
- package/dist/typescript/core/geometry.d.ts.map +1 -0
- package/dist/typescript/core/geometry.js +134 -0
- package/dist/typescript/core/geometry.js.map +1 -0
- package/dist/typescript/core/inject.d.ts +21 -0
- package/dist/typescript/core/inject.d.ts.map +1 -0
- package/dist/typescript/core/inject.js +282 -0
- package/dist/typescript/core/inject.js.map +1 -0
- package/dist/typescript/core/interactable.d.ts +2 -0
- package/dist/typescript/core/interactable.d.ts.map +1 -0
- package/dist/typescript/core/interactable.js +27 -0
- package/dist/typescript/core/interactable.js.map +1 -0
- package/dist/typescript/core/keyboard.d.ts +15 -0
- package/dist/typescript/core/keyboard.d.ts.map +1 -0
- package/dist/typescript/core/keyboard.js +356 -0
- package/dist/typescript/core/keyboard.js.map +1 -0
- package/dist/typescript/core/keys.d.ts +65 -0
- package/dist/typescript/core/keys.d.ts.map +1 -0
- package/dist/typescript/core/keys.js +125 -0
- package/dist/typescript/core/keys.js.map +1 -0
- package/dist/typescript/core/locators.d.ts +6 -0
- package/dist/typescript/core/locators.d.ts.map +1 -0
- package/dist/typescript/core/locators.js +610 -0
- package/dist/typescript/core/locators.js.map +1 -0
- package/dist/typescript/core/mouse.d.ts +17 -0
- package/dist/typescript/core/mouse.d.ts.map +1 -0
- package/dist/typescript/core/mouse.js +186 -0
- package/dist/typescript/core/mouse.js.map +1 -0
- package/dist/typescript/core/overflow.d.ts +5 -0
- package/dist/typescript/core/overflow.d.ts.map +1 -0
- package/dist/typescript/core/overflow.js +133 -0
- package/dist/typescript/core/overflow.js.map +1 -0
- package/dist/typescript/core/scroll.d.ts +3 -0
- package/dist/typescript/core/scroll.d.ts.map +1 -0
- package/dist/typescript/core/scroll.js +77 -0
- package/dist/typescript/core/scroll.js.map +1 -0
- package/dist/typescript/core/shown.d.ts +3 -0
- package/dist/typescript/core/shown.d.ts.map +1 -0
- package/dist/typescript/core/shown.js +190 -0
- package/dist/typescript/core/shown.js.map +1 -0
- package/dist/typescript/core/storage.d.ts +14 -0
- package/dist/typescript/core/storage.d.ts.map +1 -0
- package/dist/typescript/core/storage.js +98 -0
- package/dist/typescript/core/storage.js.map +1 -0
- package/dist/typescript/core/style.d.ts +2 -0
- package/dist/typescript/core/style.d.ts.map +1 -0
- package/dist/typescript/core/style.js +32 -0
- package/dist/typescript/core/style.js.map +1 -0
- package/dist/typescript/core/useragent.d.ts +3 -0
- package/dist/typescript/core/useragent.d.ts.map +1 -0
- package/dist/typescript/core/useragent.js +31 -0
- package/dist/typescript/core/useragent.js.map +1 -0
- package/dist/typescript/default-content.d.ts +2 -0
- package/dist/typescript/default-content.d.ts.map +1 -0
- package/dist/typescript/default-content.js +20 -0
- package/dist/typescript/default-content.js.map +1 -0
- package/dist/typescript/execute-async-script.d.ts +2 -0
- package/dist/typescript/execute-async-script.d.ts.map +1 -0
- package/dist/typescript/execute-async-script.js +20 -0
- package/dist/typescript/execute-async-script.js.map +1 -0
- package/dist/typescript/execute-script.d.ts +2 -0
- package/dist/typescript/execute-script.d.ts.map +1 -0
- package/dist/typescript/execute-script.js +20 -0
- package/dist/typescript/execute-script.js.map +1 -0
- package/dist/typescript/find-element-fragment.d.ts +8 -0
- package/dist/typescript/find-element-fragment.d.ts.map +1 -0
- package/dist/typescript/find-element-fragment.js +39 -0
- package/dist/typescript/find-element-fragment.js.map +1 -0
- package/dist/typescript/find-element.d.ts +2 -0
- package/dist/typescript/find-element.d.ts.map +1 -0
- package/dist/typescript/find-element.js +18 -0
- package/dist/typescript/find-element.js.map +1 -0
- package/dist/typescript/find-elements.d.ts +1 -2
- package/dist/typescript/find-elements.d.ts.map +1 -1
- package/dist/typescript/find-elements.js +1 -289
- package/dist/typescript/find-elements.js.map +1 -1
- package/dist/typescript/frame-by-id-or-name.d.ts +2 -0
- package/dist/typescript/frame-by-id-or-name.d.ts.map +1 -0
- package/dist/typescript/frame-by-id-or-name.js +22 -0
- package/dist/typescript/frame-by-id-or-name.js.map +1 -0
- package/dist/typescript/frame-by-index.d.ts +2 -0
- package/dist/typescript/frame-by-index.d.ts.map +1 -0
- package/dist/typescript/frame-by-index.js +19 -0
- package/dist/typescript/frame-by-index.js.map +1 -0
- package/dist/typescript/get-attribute-value.d.ts +2 -0
- package/dist/typescript/get-attribute-value.d.ts.map +1 -0
- package/dist/typescript/get-attribute-value.js +22 -0
- package/dist/typescript/get-attribute-value.js.map +1 -0
- package/dist/typescript/get-effective-style.d.ts +3 -0
- package/dist/typescript/get-effective-style.d.ts.map +1 -0
- package/dist/typescript/get-effective-style.js +84 -0
- package/dist/typescript/get-effective-style.js.map +1 -0
- package/dist/typescript/get-element-from-cache.d.ts +2 -0
- package/dist/typescript/get-element-from-cache.d.ts.map +1 -0
- package/dist/typescript/get-element-from-cache.js +20 -0
- package/dist/typescript/get-element-from-cache.js.map +1 -0
- package/dist/typescript/get-frame-window.d.ts +2 -0
- package/dist/typescript/get-frame-window.d.ts.map +1 -0
- package/dist/typescript/get-frame-window.js +22 -0
- package/dist/typescript/get-frame-window.js.map +1 -0
- package/dist/typescript/get-local-storage-item.d.ts +3 -0
- package/dist/typescript/get-local-storage-item.d.ts.map +1 -0
- package/dist/typescript/get-local-storage-item.js +25 -0
- package/dist/typescript/get-local-storage-item.js.map +1 -0
- package/dist/typescript/get-local-storage-key.d.ts +3 -0
- package/dist/typescript/get-local-storage-key.d.ts.map +1 -0
- package/dist/typescript/get-local-storage-key.js +26 -0
- package/dist/typescript/get-local-storage-key.js.map +1 -0
- package/dist/typescript/get-local-storage-keys.d.ts +3 -0
- package/dist/typescript/get-local-storage-keys.d.ts.map +1 -0
- package/dist/typescript/get-local-storage-keys.js +25 -0
- package/dist/typescript/get-local-storage-keys.js.map +1 -0
- package/dist/typescript/get-local-storage-size.d.ts +3 -0
- package/dist/typescript/get-local-storage-size.d.ts.map +1 -0
- package/dist/typescript/get-local-storage-size.js +25 -0
- package/dist/typescript/get-local-storage-size.js.map +1 -0
- package/dist/typescript/get-location.d.ts +9 -0
- package/dist/typescript/get-location.d.ts.map +1 -0
- package/dist/typescript/get-location.js +49 -0
- package/dist/typescript/get-location.js.map +1 -0
- package/dist/typescript/get-session-storage-item.d.ts +3 -0
- package/dist/typescript/get-session-storage-item.d.ts.map +1 -0
- package/dist/typescript/get-session-storage-item.js +25 -0
- package/dist/typescript/get-session-storage-item.js.map +1 -0
- package/dist/typescript/get-session-storage-key.d.ts +3 -0
- package/dist/typescript/get-session-storage-key.d.ts.map +1 -0
- package/dist/typescript/get-session-storage-key.js +26 -0
- package/dist/typescript/get-session-storage-key.js.map +1 -0
- package/dist/typescript/get-session-storage-keys.d.ts +3 -0
- package/dist/typescript/get-session-storage-keys.d.ts.map +1 -0
- package/dist/typescript/get-session-storage-keys.js +25 -0
- package/dist/typescript/get-session-storage-keys.js.map +1 -0
- package/dist/typescript/get-session-storage-size.d.ts +3 -0
- package/dist/typescript/get-session-storage-size.d.ts.map +1 -0
- package/dist/typescript/get-session-storage-size.js +25 -0
- package/dist/typescript/get-session-storage-size.js.map +1 -0
- package/dist/typescript/get-size.d.ts +7 -0
- package/dist/typescript/get-size.d.ts.map +1 -0
- package/dist/typescript/get-size.js +36 -0
- package/dist/typescript/get-size.js.map +1 -0
- package/dist/typescript/get-text.d.ts +3 -0
- package/dist/typescript/get-text.d.ts.map +1 -0
- package/dist/typescript/get-text.js +294 -0
- package/dist/typescript/get-text.js.map +1 -0
- package/dist/typescript/get-top-left-coordinates.d.ts +4 -0
- package/dist/typescript/get-top-left-coordinates.d.ts.map +1 -0
- package/dist/typescript/get-top-left-coordinates.js +36 -0
- package/dist/typescript/get-top-left-coordinates.js.map +1 -0
- package/dist/typescript/is-displayed.d.ts +1 -2
- package/dist/typescript/is-displayed.d.ts.map +1 -1
- package/dist/typescript/is-displayed.js +3 -396
- package/dist/typescript/is-displayed.js.map +1 -1
- package/dist/typescript/is-editable.d.ts +2 -0
- package/dist/typescript/is-editable.d.ts.map +1 -0
- package/dist/typescript/is-editable.js +18 -0
- package/dist/typescript/is-editable.js.map +1 -0
- package/dist/typescript/is-enabled.d.ts +2 -0
- package/dist/typescript/is-enabled.d.ts.map +1 -0
- package/dist/typescript/is-enabled.js +18 -0
- package/dist/typescript/is-enabled.js.map +1 -0
- package/dist/typescript/is-focusable.d.ts +2 -0
- package/dist/typescript/is-focusable.d.ts.map +1 -0
- package/dist/typescript/is-focusable.js +20 -0
- package/dist/typescript/is-focusable.js.map +1 -0
- package/dist/typescript/is-interactable.d.ts +2 -0
- package/dist/typescript/is-interactable.d.ts.map +1 -0
- package/dist/typescript/is-interactable.js +19 -0
- package/dist/typescript/is-interactable.js.map +1 -0
- package/dist/typescript/is-selected.d.ts +3 -0
- package/dist/typescript/is-selected.d.ts.map +1 -0
- package/dist/typescript/is-selected.js +29 -0
- package/dist/typescript/is-selected.js.map +1 -0
- package/dist/typescript/remove-local-storage-item.d.ts +3 -0
- package/dist/typescript/remove-local-storage-item.d.ts.map +1 -0
- package/dist/typescript/remove-local-storage-item.js +25 -0
- package/dist/typescript/remove-local-storage-item.js.map +1 -0
- package/dist/typescript/remove-session-storage-item.d.ts +3 -0
- package/dist/typescript/remove-session-storage-item.d.ts.map +1 -0
- package/dist/typescript/remove-session-storage-item.js +25 -0
- package/dist/typescript/remove-session-storage-item.js.map +1 -0
- package/dist/typescript/set-local-storage-item.d.ts +3 -0
- package/dist/typescript/set-local-storage-item.d.ts.map +1 -0
- package/dist/typescript/set-local-storage-item.js +26 -0
- package/dist/typescript/set-local-storage-item.js.map +1 -0
- package/dist/typescript/set-session-storage-item.d.ts +3 -0
- package/dist/typescript/set-session-storage-item.d.ts.map +1 -0
- package/dist/typescript/set-session-storage-item.js +26 -0
- package/dist/typescript/set-session-storage-item.js.map +1 -0
- package/dist/typescript/submit.d.ts +3 -0
- package/dist/typescript/submit.d.ts.map +1 -0
- package/dist/typescript/submit.js +50 -0
- package/dist/typescript/submit.js.map +1 -0
- package/dist/typescript/type.d.ts +3 -0
- package/dist/typescript/type.d.ts.map +1 -0
- package/dist/typescript/type.js +201 -0
- package/dist/typescript/type.js.map +1 -0
- package/index.ts +40 -0
- package/package.json +296 -5
- package/typescript/active-element.ts +19 -0
- package/typescript/clear-local-storage.ts +27 -0
- package/typescript/clear-session-storage.ts +27 -0
- package/typescript/clear.ts +73 -0
- package/typescript/click.ts +55 -0
- package/typescript/core/attribute.ts +68 -0
- package/typescript/core/color.ts +257 -0
- package/typescript/core/editable.ts +63 -0
- package/typescript/core/element.ts +110 -0
- package/typescript/core/enabled.ts +76 -0
- package/typescript/core/error.ts +41 -0
- package/typescript/core/events.ts +268 -0
- package/typescript/core/focus.ts +92 -0
- package/typescript/core/focusable.ts +38 -0
- package/typescript/core/form.ts +81 -0
- package/typescript/core/frame.ts +105 -0
- package/typescript/core/geometry.ts +183 -0
- package/typescript/core/inject.ts +336 -0
- package/typescript/core/interactable.ts +30 -0
- package/typescript/core/keyboard.ts +369 -0
- package/typescript/core/keys.ts +204 -0
- package/typescript/core/locators.ts +704 -0
- package/typescript/core/mouse.ts +211 -0
- package/typescript/core/overflow.ts +172 -0
- package/typescript/core/scroll.ts +92 -0
- package/typescript/core/shown.ts +233 -0
- package/typescript/core/storage.ts +111 -0
- package/typescript/core/style.ts +32 -0
- package/typescript/core/useragent.ts +33 -0
- package/typescript/default-content.ts +20 -0
- package/typescript/execute-async-script.ts +20 -0
- package/typescript/execute-script.ts +20 -0
- package/typescript/find-element-fragment.ts +45 -0
- package/typescript/find-element.ts +18 -0
- package/typescript/find-elements.ts +1 -326
- package/typescript/frame-by-id-or-name.ts +22 -0
- package/typescript/frame-by-index.ts +19 -0
- package/typescript/get-attribute-value.ts +22 -0
- package/typescript/get-effective-style.ts +93 -0
- package/typescript/get-element-from-cache.ts +20 -0
- package/typescript/get-frame-window.ts +22 -0
- package/typescript/get-local-storage-item.ts +27 -0
- package/typescript/get-local-storage-key.ts +28 -0
- package/typescript/get-local-storage-keys.ts +27 -0
- package/typescript/get-local-storage-size.ts +27 -0
- package/typescript/get-location.ts +63 -0
- package/typescript/get-session-storage-item.ts +27 -0
- package/typescript/get-session-storage-key.ts +28 -0
- package/typescript/get-session-storage-keys.ts +27 -0
- package/typescript/get-session-storage-size.ts +27 -0
- package/typescript/get-size.ts +43 -0
- package/typescript/get-text.ts +353 -0
- package/typescript/get-top-left-coordinates.ts +38 -0
- package/typescript/is-displayed.ts +3 -498
- package/typescript/is-editable.ts +18 -0
- package/typescript/is-enabled.ts +18 -0
- package/typescript/is-focusable.ts +20 -0
- package/typescript/is-interactable.ts +19 -0
- package/typescript/is-selected.ts +31 -0
- package/typescript/remove-local-storage-item.ts +27 -0
- package/typescript/remove-session-storage-item.ts +27 -0
- package/typescript/set-local-storage-item.ts +28 -0
- package/typescript/set-session-storage-item.ts +28 -0
- package/typescript/submit.ts +53 -0
- 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
|