@selenium/atoms 4.52.0 → 4.53.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/typescript/accessibility-snapshot-wire.d.ts +4 -0
- package/dist/typescript/accessibility-snapshot-wire.d.ts.map +1 -0
- package/dist/typescript/accessibility-snapshot-wire.js +18 -0
- package/dist/typescript/accessibility-snapshot-wire.js.map +1 -0
- package/dist/typescript/accessibility-snapshot.d.ts +3 -0
- package/dist/typescript/accessibility-snapshot.d.ts.map +1 -0
- package/dist/typescript/accessibility-snapshot.js +18 -0
- package/dist/typescript/accessibility-snapshot.js.map +1 -0
- package/dist/typescript/core/accessibility/accname.d.ts +6 -0
- package/dist/typescript/core/accessibility/accname.d.ts.map +1 -0
- package/dist/typescript/core/accessibility/accname.js +537 -0
- package/dist/typescript/core/accessibility/accname.js.map +1 -0
- package/dist/typescript/core/accessibility/context.d.ts +43 -0
- package/dist/typescript/core/accessibility/context.d.ts.map +1 -0
- package/dist/typescript/core/accessibility/context.js +49 -0
- package/dist/typescript/core/accessibility/context.js.map +1 -0
- package/dist/typescript/core/accessibility/hidden.d.ts +39 -0
- package/dist/typescript/core/accessibility/hidden.d.ts.map +1 -0
- package/dist/typescript/core/accessibility/hidden.js +216 -0
- package/dist/typescript/core/accessibility/hidden.js.map +1 -0
- package/dist/typescript/core/accessibility/roles.d.ts +28 -0
- package/dist/typescript/core/accessibility/roles.d.ts.map +1 -0
- package/dist/typescript/core/accessibility/roles.js +381 -0
- package/dist/typescript/core/accessibility/roles.js.map +1 -0
- package/dist/typescript/core/accessibility/snapshot.d.ts +13 -0
- package/dist/typescript/core/accessibility/snapshot.d.ts.map +1 -0
- package/dist/typescript/core/accessibility/snapshot.js +55 -0
- package/dist/typescript/core/accessibility/snapshot.js.map +1 -0
- package/dist/typescript/core/accessibility/states.d.ts +18 -0
- package/dist/typescript/core/accessibility/states.d.ts.map +1 -0
- package/dist/typescript/core/accessibility/states.js +215 -0
- package/dist/typescript/core/accessibility/states.js.map +1 -0
- package/dist/typescript/core/accessibility/tree.d.ts +10 -0
- package/dist/typescript/core/accessibility/tree.d.ts.map +1 -0
- package/dist/typescript/core/accessibility/tree.js +261 -0
- package/dist/typescript/core/accessibility/tree.js.map +1 -0
- package/dist/typescript/core/accessibility/types.d.ts +30 -0
- package/dist/typescript/core/accessibility/types.d.ts.map +1 -0
- package/dist/typescript/core/accessibility/types.js +18 -0
- package/dist/typescript/core/accessibility/types.js.map +1 -0
- package/dist/typescript/core/accessibility/value.d.ts +4 -0
- package/dist/typescript/core/accessibility/value.d.ts.map +1 -0
- package/dist/typescript/core/accessibility/value.js +83 -0
- package/dist/typescript/core/accessibility/value.js.map +1 -0
- package/dist/typescript/core/accessibility/wire.d.ts +57 -0
- package/dist/typescript/core/accessibility/wire.d.ts.map +1 -0
- package/dist/typescript/core/accessibility/wire.js +72 -0
- package/dist/typescript/core/accessibility/wire.js.map +1 -0
- package/index.ts +4 -0
- package/package.json +15 -1
- package/typescript/accessibility-snapshot-wire.ts +20 -0
- package/typescript/accessibility-snapshot.ts +21 -0
- package/typescript/core/accessibility/accname.ts +587 -0
- package/typescript/core/accessibility/context.ts +116 -0
- package/typescript/core/accessibility/hidden.ts +242 -0
- package/typescript/core/accessibility/roles.ts +410 -0
- package/typescript/core/accessibility/snapshot.ts +61 -0
- package/typescript/core/accessibility/states.ts +233 -0
- package/typescript/core/accessibility/tree.ts +306 -0
- package/typescript/core/accessibility/types.ts +52 -0
- package/typescript/core/accessibility/value.ts +89 -0
- package/typescript/core/accessibility/wire.ts +123 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
2
|
+
// or more contributor license agreements. See the NOTICE file
|
|
3
|
+
// distributed with this work for additional information
|
|
4
|
+
// regarding copyright ownership. The SFC licenses this file
|
|
5
|
+
// to you under the Apache License, Version 2.0 (the
|
|
6
|
+
// "License"); you may not use this file except in compliance
|
|
7
|
+
// with the License. You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing,
|
|
12
|
+
// software distributed under the License is distributed on an
|
|
13
|
+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
// KIND, either express or implied. See the License for the
|
|
15
|
+
// specific language governing permissions and limitations
|
|
16
|
+
// under the License.
|
|
17
|
+
|
|
18
|
+
import { isElement } from '../element.js'
|
|
19
|
+
import accessibilitySnapshot from './snapshot.js'
|
|
20
|
+
import type { AccessibilityNode, SnapshotOptions, StateValue } from './types.js'
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A node as the language bindings receive it: the same fields as
|
|
24
|
+
* `AccessibilityNode`, with every reference replaced by an index into the
|
|
25
|
+
* arrays that travel beside the JSON text.
|
|
26
|
+
*/
|
|
27
|
+
export interface WireNode {
|
|
28
|
+
role: string
|
|
29
|
+
name: string
|
|
30
|
+
description: string
|
|
31
|
+
value?: string
|
|
32
|
+
url?: string
|
|
33
|
+
states: Record<string, StateValue>
|
|
34
|
+
/** Index into `WireSnapshot.elements`; absent for text leaves. */
|
|
35
|
+
element?: number
|
|
36
|
+
/** Index into `WireSnapshot.windows`, on a frame node whose frame has a content window. */
|
|
37
|
+
frame?: number
|
|
38
|
+
children: WireNode[]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The shape the bindings fetch over WebDriver BiDi. The tree travels as one
|
|
43
|
+
* JSON string, so a binding parses it with its own JSON library instead of
|
|
44
|
+
* decoding a nested remote value; the elements and frame windows travel as
|
|
45
|
+
* plain arrays, which BiDi serializes as node references and browsing context
|
|
46
|
+
* ids in one pass.
|
|
47
|
+
*/
|
|
48
|
+
export interface WireSnapshot {
|
|
49
|
+
json: string
|
|
50
|
+
/** Every element the tree references, in order of first mention. */
|
|
51
|
+
elements: Element[]
|
|
52
|
+
/** The content window of every frame node, in order of first mention. */
|
|
53
|
+
windows: Window[]
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The root is an element of this document that is no longer attached to it. */
|
|
57
|
+
export interface WireError {
|
|
58
|
+
error: 'detached'
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface Encoded {
|
|
62
|
+
node: WireNode
|
|
63
|
+
elements: Element[]
|
|
64
|
+
windows: Window[]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Replaces the references in a tree with indices; pure, so it is unit tested without a DOM. */
|
|
68
|
+
export function encodeWire(tree: AccessibilityNode): Encoded {
|
|
69
|
+
const elements: Element[] = []
|
|
70
|
+
const windows: Window[] = []
|
|
71
|
+
|
|
72
|
+
function encode(node: AccessibilityNode): WireNode {
|
|
73
|
+
const out: WireNode = { role: node.role, name: node.name, description: node.description, states: node.states, children: [] }
|
|
74
|
+
if (node.value !== undefined) {
|
|
75
|
+
out.value = node.value
|
|
76
|
+
}
|
|
77
|
+
if (node.url !== undefined) {
|
|
78
|
+
out.url = node.url
|
|
79
|
+
}
|
|
80
|
+
if (node.element) {
|
|
81
|
+
out.element = elements.push(node.element) - 1
|
|
82
|
+
const window = node.role === 'iframe' ? (node.element as HTMLIFrameElement).contentWindow : null
|
|
83
|
+
if (window) {
|
|
84
|
+
out.frame = windows.push(window) - 1
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
out.children = node.children.map(encode)
|
|
88
|
+
return out
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return { node: encode(tree), elements, windows }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The snapshot of this document (no `root`), or of the subtree under `root`,
|
|
96
|
+
* in the wire shape. Answers `null` for a root this document does not own,
|
|
97
|
+
* so a binding tries each document until one answers: Firefox hands a shared
|
|
98
|
+
* id of another document's node to the called function as `null`, and may
|
|
99
|
+
* resolve one to the node itself in any document of the browsing context
|
|
100
|
+
* group, which the ownership check catches. Answers `{ error: 'detached' }`
|
|
101
|
+
* for a root no longer in its document, so a binding never has to read an
|
|
102
|
+
* exception's text.
|
|
103
|
+
*/
|
|
104
|
+
function accessibilitySnapshotWire(root?: Element | null, options?: SnapshotOptions): WireSnapshot | WireError | null {
|
|
105
|
+
if (root === null) {
|
|
106
|
+
return null
|
|
107
|
+
}
|
|
108
|
+
if (root !== undefined) {
|
|
109
|
+
if (!isElement(root)) {
|
|
110
|
+
throw new Error('accessibilitySnapshotWire: root must be an Element')
|
|
111
|
+
}
|
|
112
|
+
if (root.ownerDocument !== document) {
|
|
113
|
+
return null
|
|
114
|
+
}
|
|
115
|
+
if (!root.isConnected) {
|
|
116
|
+
return { error: 'detached' }
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const { node, elements, windows } = encodeWire(accessibilitySnapshot(root, options))
|
|
120
|
+
return { json: JSON.stringify(node), elements, windows }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export default accessibilitySnapshotWire
|