@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.
- 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 +292 -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,183 @@
|
|
|
1
|
+
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
2
|
+
// or more contributor license agreements. See the NOTICE file
|
|
3
|
+
// distributed with this work for additional information
|
|
4
|
+
// regarding copyright ownership. The SFC licenses this file
|
|
5
|
+
// to you under the Apache License, Version 2.0 (the
|
|
6
|
+
// "License"); you may not use this file except in compliance
|
|
7
|
+
// with the License. You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing,
|
|
12
|
+
// software distributed under the License is distributed on an
|
|
13
|
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
// KIND, either express or implied. See the License for the
|
|
15
|
+
// specific language governing permissions and limitations
|
|
16
|
+
// under the License.
|
|
17
|
+
|
|
18
|
+
import { isElement } from './element.js'
|
|
19
|
+
|
|
20
|
+
export interface Rect {
|
|
21
|
+
left: number;
|
|
22
|
+
top: number;
|
|
23
|
+
right: number;
|
|
24
|
+
bottom: number;
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface Coordinate {
|
|
30
|
+
x: number;
|
|
31
|
+
y: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ImageMapResult {
|
|
35
|
+
image: Element | null;
|
|
36
|
+
rect: Rect;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// The sub-region accepted by getClientRegion and the scrolling helpers. A bare
|
|
40
|
+
// coordinate means the single pixel at that point, matching Closure's
|
|
41
|
+
// `new goog.math.Rect(region.x, region.y, 1, 1)` coercion.
|
|
42
|
+
export type Region = { left: number; top: number; width: number; height: number } | Coordinate;
|
|
43
|
+
|
|
44
|
+
// Reading a rect is injectable because isShownElement memoises it across the
|
|
45
|
+
// hundreds of reads one isDisplayed call makes; everyone else wants the plain
|
|
46
|
+
// uncached read.
|
|
47
|
+
export type RectReader = (elem: Element) => Rect;
|
|
48
|
+
|
|
49
|
+
export function createRect(left: number, top: number, width: number, height: number): Rect {
|
|
50
|
+
return {
|
|
51
|
+
left: left,
|
|
52
|
+
top: top,
|
|
53
|
+
right: left + width,
|
|
54
|
+
bottom: top + height,
|
|
55
|
+
width: width,
|
|
56
|
+
height: height,
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function clamp(value: number, min: number, max: number): number {
|
|
61
|
+
return Math.min(Math.max(value, min), max)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function getAreaRelativeRect(area: HTMLAreaElement): Rect {
|
|
65
|
+
var shape = area.shape.toLowerCase()
|
|
66
|
+
var coords = area.coords.split(',').map(function (value) {
|
|
67
|
+
return Number(value.trim())
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
if (shape === 'rect' && coords.length === 4) {
|
|
71
|
+
return createRect(coords[0], coords[1], coords[2] - coords[0], coords[3] - coords[1])
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (shape === 'circle' && coords.length === 3) {
|
|
75
|
+
return createRect(coords[0] - coords[2], coords[1] - coords[2], coords[2] * 2, coords[2] * 2)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (shape === 'poly' && coords.length > 2) {
|
|
79
|
+
var minX = coords[0]
|
|
80
|
+
var minY = coords[1]
|
|
81
|
+
var maxX = minX
|
|
82
|
+
var maxY = minY
|
|
83
|
+
|
|
84
|
+
for (var index = 2; index + 1 < coords.length; index += 2) {
|
|
85
|
+
minX = Math.min(minX, coords[index])
|
|
86
|
+
maxX = Math.max(maxX, coords[index])
|
|
87
|
+
minY = Math.min(minY, coords[index + 1])
|
|
88
|
+
maxY = Math.max(maxY, coords[index + 1])
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return createRect(minX, minY, maxX - minX, maxY - minY)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return createRect(0, 0, 0, 0)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function findImageUsingMap(mapName: string, doc: Document): Element | null {
|
|
98
|
+
// Use querySelector instead of a full-DOM scan; escape the map name so
|
|
99
|
+
// special characters in the CSS attribute value string are handled safely.
|
|
100
|
+
return doc.querySelector('[usemap="#' + mapName.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"]')
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function maybeFindImageMap(elem: Element, getRect: RectReader = getClientRect): ImageMapResult | null {
|
|
104
|
+
var isMap = isElement(elem, 'MAP')
|
|
105
|
+
if (!isMap && !isElement(elem, 'AREA')) {
|
|
106
|
+
return null
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
var map = isMap ? elem : isElement(elem.parentNode, 'MAP') ? elem.parentNode : null
|
|
110
|
+
var image: Element | null = null
|
|
111
|
+
var rect = createRect(0, 0, 0, 0)
|
|
112
|
+
|
|
113
|
+
if (isElement(map, 'MAP') && (map as HTMLMapElement).name) {
|
|
114
|
+
image = findImageUsingMap((map as HTMLMapElement).name, (map as HTMLMapElement).ownerDocument)
|
|
115
|
+
if (image) {
|
|
116
|
+
rect = getRect(image)
|
|
117
|
+
if (!isMap && isElement(elem, 'AREA') && (elem as HTMLAreaElement).shape.toLowerCase() !== 'default') {
|
|
118
|
+
var relativeRect = getAreaRelativeRect(elem as HTMLAreaElement)
|
|
119
|
+
var relativeX = Math.min(Math.max(relativeRect.left, 0), rect.width)
|
|
120
|
+
var relativeY = Math.min(Math.max(relativeRect.top, 0), rect.height)
|
|
121
|
+
var width = Math.min(relativeRect.width, rect.width - relativeX)
|
|
122
|
+
var height = Math.min(relativeRect.height, rect.height - relativeY)
|
|
123
|
+
rect = createRect(relativeX + rect.left, relativeY + rect.top, width, height)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return { image: image, rect: rect }
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// getRect is threaded through to the image-map lookup so a memoising caller
|
|
132
|
+
// keeps its cache for the <img> an <area> resolves to, not just the <area>.
|
|
133
|
+
export function getClientRect(elem: Element, getRect?: RectReader): Rect {
|
|
134
|
+
var imageMap = maybeFindImageMap(elem, getRect || getClientRect)
|
|
135
|
+
if (imageMap) {
|
|
136
|
+
return imageMap.rect
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
var elemTagName = typeof elem.tagName === 'string' ? elem.tagName : ''
|
|
140
|
+
if (elemTagName.toUpperCase() === 'HTML') {
|
|
141
|
+
var doc = elem.ownerDocument
|
|
142
|
+
// In quirks mode (no DOCTYPE), viewport dimensions come from document.body;
|
|
143
|
+
// documentElement.clientWidth/Height is unreliable and can be 0.
|
|
144
|
+
var sizeElem = doc.compatMode === 'CSS1Compat' ? doc.documentElement : (doc.body || doc.documentElement)
|
|
145
|
+
return createRect(0, 0, sizeElem.clientWidth, sizeElem.clientHeight)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
try {
|
|
149
|
+
var nativeRect = elem.getBoundingClientRect()
|
|
150
|
+
return {
|
|
151
|
+
left: nativeRect.left,
|
|
152
|
+
top: nativeRect.top,
|
|
153
|
+
right: nativeRect.right,
|
|
154
|
+
bottom: nativeRect.bottom,
|
|
155
|
+
width: nativeRect.right - nativeRect.left,
|
|
156
|
+
height: nativeRect.bottom - nativeRect.top,
|
|
157
|
+
}
|
|
158
|
+
} catch (_error) {
|
|
159
|
+
return createRect(0, 0, 0, 0)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// The element's rect, optionally narrowed to a sub-region clamped inside it.
|
|
164
|
+
// Each edge is clamped against the edge computed before it, so a region wider
|
|
165
|
+
// than the element collapses to the element rather than spilling past it --
|
|
166
|
+
// preserve that ordering, it is load-bearing.
|
|
167
|
+
export function getClientRegion(elem: Element, optRegion?: Region, getRect: RectReader = getClientRect): Rect {
|
|
168
|
+
var rect = getRect(elem)
|
|
169
|
+
if (!optRegion) {
|
|
170
|
+
return rect
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
var region = 'left' in optRegion
|
|
174
|
+
? optRegion
|
|
175
|
+
: { left: optRegion.x, top: optRegion.y, width: 1, height: 1 }
|
|
176
|
+
|
|
177
|
+
var left = clamp(rect.left + region.left, rect.left, rect.right)
|
|
178
|
+
var top = clamp(rect.top + region.top, rect.top, rect.bottom)
|
|
179
|
+
var right = clamp(left + region.width, left, rect.right)
|
|
180
|
+
var bottom = clamp(top + region.height, top, rect.bottom)
|
|
181
|
+
|
|
182
|
+
return createRect(left, top, right - left, bottom - top)
|
|
183
|
+
}
|
|
@@ -0,0 +1,336 @@
|
|
|
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 {
|
|
19
|
+
JAVASCRIPT_ERROR,
|
|
20
|
+
NO_SUCH_WINDOW,
|
|
21
|
+
SCRIPT_TIMEOUT,
|
|
22
|
+
STALE_ELEMENT_REFERENCE,
|
|
23
|
+
UNKNOWN_ERROR,
|
|
24
|
+
botError,
|
|
25
|
+
} from './error.js'
|
|
26
|
+
|
|
27
|
+
// bot.inject: the element cache, the {ELEMENT}/{WINDOW} handle format and the
|
|
28
|
+
// {status, value} response envelope that injected scripts talk through.
|
|
29
|
+
//
|
|
30
|
+
// Statuses are W3C error strings, and success is 'success'. bot.inject sent
|
|
31
|
+
// bot.ErrorCode numbers (0, 10, 28...), the JSON wire protocol's encoding;
|
|
32
|
+
// a consumer that compared against those numbers has to compare strings now.
|
|
33
|
+
|
|
34
|
+
export const ELEMENT_KEY = 'ELEMENT'
|
|
35
|
+
export const WINDOW_KEY = 'WINDOW'
|
|
36
|
+
export const SUCCESS = 'success'
|
|
37
|
+
|
|
38
|
+
// Both live on the document rather than in module state because every atom is
|
|
39
|
+
// a separate bundle with its own module scope: the document is the only thing
|
|
40
|
+
// two injected atoms share. They must stay byte-identical to bot.inject.cache,
|
|
41
|
+
// or an id minted by a Closure atom is stale to a TypeScript one and the
|
|
42
|
+
// reverse, for as long as both kinds are injected into the same page.
|
|
43
|
+
const CACHE_KEY = '$wdc_'
|
|
44
|
+
const ELEMENT_KEY_PREFIX = ':wdc:'
|
|
45
|
+
|
|
46
|
+
export interface Response {
|
|
47
|
+
status: string
|
|
48
|
+
value: unknown
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type Cacheable = Element | Document | Window
|
|
52
|
+
type Cache = Record<string, unknown> & { nextId: number }
|
|
53
|
+
|
|
54
|
+
function getCache(optDoc?: Document | null): Cache {
|
|
55
|
+
const doc = (optDoc || document) as unknown as Record<string, Cache | undefined>
|
|
56
|
+
let cache = doc[CACHE_KEY]
|
|
57
|
+
if (!cache) {
|
|
58
|
+
// The id counter lives in the cache so it resets whenever the cache does.
|
|
59
|
+
cache = doc[CACHE_KEY] = { nextId: Date.now() } as Cache
|
|
60
|
+
}
|
|
61
|
+
// The original notes nextId sometimes reads back as NaN; reseed rather than
|
|
62
|
+
// mint ':wdc:NaN'.
|
|
63
|
+
if (!cache.nextId) {
|
|
64
|
+
cache.nextId = Date.now()
|
|
65
|
+
}
|
|
66
|
+
return cache
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Keyed by the owning document, so a window -- which has no ownerDocument --
|
|
70
|
+
// and a document both land in the current document's cache.
|
|
71
|
+
export function addElement(el: Cacheable): string {
|
|
72
|
+
const cache = getCache((el as Element).ownerDocument)
|
|
73
|
+
for (const key in cache) {
|
|
74
|
+
if (cache[key] == el) {
|
|
75
|
+
return key
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const id = ELEMENT_KEY_PREFIX + cache.nextId++
|
|
79
|
+
cache[id] = el
|
|
80
|
+
return id
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Stale rather than no-such-element for an unknown key: the id may have come
|
|
84
|
+
// from a previous document's cache, which is gone after a navigation.
|
|
85
|
+
export function getElement(key: string, optDoc?: Document): Element | Window {
|
|
86
|
+
key = decodeURIComponent(key)
|
|
87
|
+
const doc = optDoc || document
|
|
88
|
+
const cache = getCache(doc)
|
|
89
|
+
// The cache also holds its own id counter, which is not a handle.
|
|
90
|
+
const el = cache[key] as Record<string, unknown> | number | undefined
|
|
91
|
+
if (typeof el !== 'object' || el === null) {
|
|
92
|
+
throw botError(STALE_ELEMENT_REFERENCE, 'Element does not exist in cache')
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if ('setInterval' in el) {
|
|
96
|
+
if (el['closed']) {
|
|
97
|
+
delete cache[key]
|
|
98
|
+
throw botError(NO_SUCH_WINDOW, 'Window has been closed.')
|
|
99
|
+
}
|
|
100
|
+
return el as unknown as Window
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Attached means reachable from the documentElement, stepping out of shadow
|
|
104
|
+
// roots through their host.
|
|
105
|
+
let node = el as unknown as Node | null
|
|
106
|
+
while (node) {
|
|
107
|
+
if (node == doc.documentElement) {
|
|
108
|
+
return el as unknown as Element
|
|
109
|
+
}
|
|
110
|
+
if ((node as ShadowRoot).host && node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
|
|
111
|
+
node = (node as ShadowRoot).host
|
|
112
|
+
}
|
|
113
|
+
node = node.parentNode
|
|
114
|
+
}
|
|
115
|
+
delete cache[key]
|
|
116
|
+
throw botError(STALE_ELEMENT_REFERENCE, 'Element is no longer attached to the DOM')
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function isArrayLike(value: object): value is ArrayLike<unknown> {
|
|
120
|
+
return typeof (value as { length?: unknown }).length == 'number'
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Makes a value JSON-safe: elements and documents become {ELEMENT: id},
|
|
124
|
+
// windows {WINDOW: id}, functions their source, undefined null, and other
|
|
125
|
+
// objects are walked keeping only string keys.
|
|
126
|
+
//
|
|
127
|
+
// `seen` is never popped, so an object reached twice through different paths
|
|
128
|
+
// -- not a cycle, just shared -- is reported as recursive too. Inherited from
|
|
129
|
+
// bot.inject.wrapValue; kept because it is what consumers get today.
|
|
130
|
+
export function wrapValue(value: unknown): unknown {
|
|
131
|
+
const seen: object[] = []
|
|
132
|
+
const wrap = (value: unknown): unknown => {
|
|
133
|
+
switch (typeof value) {
|
|
134
|
+
case 'string':
|
|
135
|
+
case 'number':
|
|
136
|
+
case 'boolean':
|
|
137
|
+
return value
|
|
138
|
+
case 'function':
|
|
139
|
+
return value.toString()
|
|
140
|
+
case 'object': {
|
|
141
|
+
if (value === null) {
|
|
142
|
+
return null
|
|
143
|
+
}
|
|
144
|
+
// A real Array is mapped without joining `seen` -- goog.typeOf calls it
|
|
145
|
+
// 'array', not 'object' -- so the same array twice is not "recursive".
|
|
146
|
+
if (Array.isArray(value)) {
|
|
147
|
+
return value.map(wrap)
|
|
148
|
+
}
|
|
149
|
+
if (seen.indexOf(value) >= 0) {
|
|
150
|
+
throw botError(JAVASCRIPT_ERROR, 'Recursive object cannot be transferred')
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Duck-typed rather than instanceof, which is false for a node from
|
|
154
|
+
// another frame's realm.
|
|
155
|
+
const nodeType = (value as { nodeType?: unknown }).nodeType
|
|
156
|
+
if ('nodeType' in value && (nodeType == Node.ELEMENT_NODE || nodeType == Node.DOCUMENT_NODE)) {
|
|
157
|
+
return { [ELEMENT_KEY]: addElement(value as Element) }
|
|
158
|
+
}
|
|
159
|
+
if ('document' in value) {
|
|
160
|
+
return { [WINDOW_KEY]: addElement(value as Window) }
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
seen.push(value)
|
|
164
|
+
if (isArrayLike(value)) {
|
|
165
|
+
return Array.prototype.map.call(value, wrap)
|
|
166
|
+
}
|
|
167
|
+
const result: Record<string, unknown> = {}
|
|
168
|
+
for (const key in value) {
|
|
169
|
+
result[key] = wrap((value as Record<string, unknown>)[key])
|
|
170
|
+
}
|
|
171
|
+
return result
|
|
172
|
+
}
|
|
173
|
+
default:
|
|
174
|
+
return null
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return wrap(value)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Resolves {ELEMENT}/{WINDOW} handles against optDoc's cache. Functions pass
|
|
181
|
+
// through untouched so a script can be handed a callback.
|
|
182
|
+
export function unwrapValue(value: unknown, optDoc?: Document): unknown {
|
|
183
|
+
if (Array.isArray(value)) {
|
|
184
|
+
return value.map((v) => unwrapValue(v, optDoc))
|
|
185
|
+
}
|
|
186
|
+
if (typeof value == 'function') {
|
|
187
|
+
return value
|
|
188
|
+
}
|
|
189
|
+
if (value !== null && typeof value == 'object') {
|
|
190
|
+
const obj = value as Record<string, unknown>
|
|
191
|
+
if (ELEMENT_KEY in obj) {
|
|
192
|
+
return getElement(obj[ELEMENT_KEY] as string, optDoc)
|
|
193
|
+
}
|
|
194
|
+
if (WINDOW_KEY in obj) {
|
|
195
|
+
return getElement(obj[WINDOW_KEY] as string, optDoc)
|
|
196
|
+
}
|
|
197
|
+
const result: Record<string, unknown> = {}
|
|
198
|
+
for (const key in obj) {
|
|
199
|
+
result[key] = unwrapValue(obj[key], optDoc)
|
|
200
|
+
}
|
|
201
|
+
return result
|
|
202
|
+
}
|
|
203
|
+
return value
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export function wrapResponse(value: unknown): Response {
|
|
207
|
+
return { status: SUCCESS, value: wrapValue(value) }
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Only a string code is a status. A DOMException carries a legacy numeric
|
|
211
|
+
// `code` (12 for a bad selector), which would otherwise leak through as one.
|
|
212
|
+
export function wrapError(err: unknown): Response {
|
|
213
|
+
const code = (err as { code?: unknown } | null)?.code
|
|
214
|
+
return {
|
|
215
|
+
status: typeof code == 'string' ? code : UNKNOWN_ERROR,
|
|
216
|
+
value: { message: (err as Error | null)?.message },
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Compiles `fn` in the target window's realm so that globals it names resolve
|
|
221
|
+
// there. A string is a function body; a function is recompiled from its
|
|
222
|
+
// source, which assumes it closes over nothing outside that window.
|
|
223
|
+
function recompileFunction(fn: Function | string, theWindow: Window): Function {
|
|
224
|
+
const WindowFunction = (theWindow as unknown as { Function: FunctionConstructor }).Function
|
|
225
|
+
if (typeof fn === 'string') {
|
|
226
|
+
return new WindowFunction(fn)
|
|
227
|
+
}
|
|
228
|
+
return theWindow == window ? fn : new WindowFunction('return (' + fn + ').apply(null,arguments);')
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export function executeScript(
|
|
232
|
+
fn: Function | string,
|
|
233
|
+
args: unknown[],
|
|
234
|
+
optStringify?: boolean,
|
|
235
|
+
optWindow?: Window,
|
|
236
|
+
): string | Response {
|
|
237
|
+
const win = optWindow || window
|
|
238
|
+
let ret: Response
|
|
239
|
+
try {
|
|
240
|
+
const compiled = recompileFunction(fn, win)
|
|
241
|
+
const unwrappedArgs = unwrapValue(args, win.document) as unknown[]
|
|
242
|
+
ret = wrapResponse(compiled.apply(null, unwrappedArgs))
|
|
243
|
+
} catch (ex) {
|
|
244
|
+
ret = wrapError(ex)
|
|
245
|
+
}
|
|
246
|
+
return optStringify ? JSON.stringify(ret) : ret
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// The script finishes by calling the callback appended as its last argument.
|
|
250
|
+
// onDone is always called exactly once: with that value, with the error the
|
|
251
|
+
// script threw, on timeout, or when the window unloads underneath it.
|
|
252
|
+
export function executeAsyncScript(
|
|
253
|
+
fn: Function | string,
|
|
254
|
+
args: unknown[],
|
|
255
|
+
timeout: number,
|
|
256
|
+
onDone: (result: string | Response) => void,
|
|
257
|
+
optStringify?: boolean,
|
|
258
|
+
optWindow?: Window,
|
|
259
|
+
): void {
|
|
260
|
+
const win = optWindow || window
|
|
261
|
+
let timeoutId: number | undefined
|
|
262
|
+
let responseSent = false
|
|
263
|
+
|
|
264
|
+
function onunload(): void {
|
|
265
|
+
sendResponse(
|
|
266
|
+
UNKNOWN_ERROR,
|
|
267
|
+
Error('Detected a page unload event; asynchronous script execution does not work across page loads.'),
|
|
268
|
+
)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function sendResponse(status: string, value: unknown): void {
|
|
272
|
+
if (responseSent) {
|
|
273
|
+
return
|
|
274
|
+
}
|
|
275
|
+
// Marked before delivery, so an onDone that throws cannot be followed by
|
|
276
|
+
// the timeout or the unload handler delivering a second response.
|
|
277
|
+
responseSent = true
|
|
278
|
+
win.removeEventListener('unload', onunload, true)
|
|
279
|
+
win.clearTimeout(timeoutId)
|
|
280
|
+
let response: Response
|
|
281
|
+
if (status != SUCCESS) {
|
|
282
|
+
const cause = value as { message?: string; stack?: string }
|
|
283
|
+
const err = botError(status, cause.message || value + '')
|
|
284
|
+
err.stack = cause.stack
|
|
285
|
+
response = wrapError(err)
|
|
286
|
+
} else {
|
|
287
|
+
// A value that cannot be transferred, such as a cyclic object, is the
|
|
288
|
+
// script's error to report, not an exception thrown back into it.
|
|
289
|
+
try {
|
|
290
|
+
response = wrapResponse(value)
|
|
291
|
+
} catch (e) {
|
|
292
|
+
response = wrapError(e)
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
onDone(optStringify ? JSON.stringify(response) : response)
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (win.closed) {
|
|
299
|
+
sendResponse(UNKNOWN_ERROR, 'Unable to execute script; the target window is closed.')
|
|
300
|
+
return
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
win.addEventListener('unload', onunload, true)
|
|
304
|
+
|
|
305
|
+
const startTime = Date.now()
|
|
306
|
+
// Compiling and unwrapping sit inside the try, as they do in executeScript,
|
|
307
|
+
// so a syntax error or a stale element argument reaches onDone with its own
|
|
308
|
+
// status. bot.inject threw those out of the atom instead.
|
|
309
|
+
try {
|
|
310
|
+
const compiled = recompileFunction(fn, win)
|
|
311
|
+
const unwrappedArgs = unwrapValue(args, win.document) as unknown[]
|
|
312
|
+
unwrappedArgs.push((value: unknown) => sendResponse(SUCCESS, value))
|
|
313
|
+
compiled.apply(win, unwrappedArgs)
|
|
314
|
+
|
|
315
|
+
// Armed after the call, so a script that calls back from a zero-length
|
|
316
|
+
// timer is not beaten to it by its own timeout -- and not at all if it
|
|
317
|
+
// already called back, or the timer would outlive the call for nothing.
|
|
318
|
+
if (!responseSent) {
|
|
319
|
+
timeoutId = win.setTimeout(() => {
|
|
320
|
+
sendResponse(
|
|
321
|
+
SCRIPT_TIMEOUT,
|
|
322
|
+
Error('Timed out waiting for asynchronous script result after ' + (Date.now() - startTime) + ' ms'),
|
|
323
|
+
)
|
|
324
|
+
}, Math.max(0, timeout))
|
|
325
|
+
}
|
|
326
|
+
} catch (ex) {
|
|
327
|
+
const code = (ex as { code?: unknown }).code
|
|
328
|
+
sendResponse(typeof code == 'string' ? code : UNKNOWN_ERROR, ex)
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// webdriver.atoms.inject.getWindow: the window named by a {WINDOW: id} handle,
|
|
333
|
+
// or the current one.
|
|
334
|
+
export function getWindow(optWindow?: { [WINDOW_KEY]: string }): Window {
|
|
335
|
+
return optWindow ? (getElement(optWindow[WINDOW_KEY]) as Window) : window
|
|
336
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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 { isEnabled } from './enabled.js'
|
|
19
|
+
import isShown from './shown.js'
|
|
20
|
+
import { getEffectiveStyle } from './style.js'
|
|
21
|
+
|
|
22
|
+
// Opacity is ignored deliberately: a fully transparent control still takes
|
|
23
|
+
// clicks, so it is interactable even though it is not displayed.
|
|
24
|
+
export function isInteractable(element: Element): boolean {
|
|
25
|
+
return (
|
|
26
|
+
isShown(element, /* optIgnoreOpacity= */ true) &&
|
|
27
|
+
isEnabled(element) &&
|
|
28
|
+
getEffectiveStyle(element, 'pointer-events') !== 'none'
|
|
29
|
+
)
|
|
30
|
+
}
|