@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.
Files changed (67) hide show
  1. package/README.md +56 -0
  2. package/dist/index.d.ts +4 -0
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +2 -0
  5. package/dist/index.js.map +1 -1
  6. package/dist/typescript/accessibility-snapshot-wire.d.ts +4 -0
  7. package/dist/typescript/accessibility-snapshot-wire.d.ts.map +1 -0
  8. package/dist/typescript/accessibility-snapshot-wire.js +18 -0
  9. package/dist/typescript/accessibility-snapshot-wire.js.map +1 -0
  10. package/dist/typescript/accessibility-snapshot.d.ts +3 -0
  11. package/dist/typescript/accessibility-snapshot.d.ts.map +1 -0
  12. package/dist/typescript/accessibility-snapshot.js +18 -0
  13. package/dist/typescript/accessibility-snapshot.js.map +1 -0
  14. package/dist/typescript/core/accessibility/accname.d.ts +6 -0
  15. package/dist/typescript/core/accessibility/accname.d.ts.map +1 -0
  16. package/dist/typescript/core/accessibility/accname.js +537 -0
  17. package/dist/typescript/core/accessibility/accname.js.map +1 -0
  18. package/dist/typescript/core/accessibility/context.d.ts +43 -0
  19. package/dist/typescript/core/accessibility/context.d.ts.map +1 -0
  20. package/dist/typescript/core/accessibility/context.js +49 -0
  21. package/dist/typescript/core/accessibility/context.js.map +1 -0
  22. package/dist/typescript/core/accessibility/hidden.d.ts +39 -0
  23. package/dist/typescript/core/accessibility/hidden.d.ts.map +1 -0
  24. package/dist/typescript/core/accessibility/hidden.js +216 -0
  25. package/dist/typescript/core/accessibility/hidden.js.map +1 -0
  26. package/dist/typescript/core/accessibility/roles.d.ts +28 -0
  27. package/dist/typescript/core/accessibility/roles.d.ts.map +1 -0
  28. package/dist/typescript/core/accessibility/roles.js +381 -0
  29. package/dist/typescript/core/accessibility/roles.js.map +1 -0
  30. package/dist/typescript/core/accessibility/snapshot.d.ts +13 -0
  31. package/dist/typescript/core/accessibility/snapshot.d.ts.map +1 -0
  32. package/dist/typescript/core/accessibility/snapshot.js +55 -0
  33. package/dist/typescript/core/accessibility/snapshot.js.map +1 -0
  34. package/dist/typescript/core/accessibility/states.d.ts +18 -0
  35. package/dist/typescript/core/accessibility/states.d.ts.map +1 -0
  36. package/dist/typescript/core/accessibility/states.js +215 -0
  37. package/dist/typescript/core/accessibility/states.js.map +1 -0
  38. package/dist/typescript/core/accessibility/tree.d.ts +10 -0
  39. package/dist/typescript/core/accessibility/tree.d.ts.map +1 -0
  40. package/dist/typescript/core/accessibility/tree.js +261 -0
  41. package/dist/typescript/core/accessibility/tree.js.map +1 -0
  42. package/dist/typescript/core/accessibility/types.d.ts +30 -0
  43. package/dist/typescript/core/accessibility/types.d.ts.map +1 -0
  44. package/dist/typescript/core/accessibility/types.js +18 -0
  45. package/dist/typescript/core/accessibility/types.js.map +1 -0
  46. package/dist/typescript/core/accessibility/value.d.ts +4 -0
  47. package/dist/typescript/core/accessibility/value.d.ts.map +1 -0
  48. package/dist/typescript/core/accessibility/value.js +83 -0
  49. package/dist/typescript/core/accessibility/value.js.map +1 -0
  50. package/dist/typescript/core/accessibility/wire.d.ts +57 -0
  51. package/dist/typescript/core/accessibility/wire.d.ts.map +1 -0
  52. package/dist/typescript/core/accessibility/wire.js +72 -0
  53. package/dist/typescript/core/accessibility/wire.js.map +1 -0
  54. package/index.ts +4 -0
  55. package/package.json +15 -1
  56. package/typescript/accessibility-snapshot-wire.ts +20 -0
  57. package/typescript/accessibility-snapshot.ts +21 -0
  58. package/typescript/core/accessibility/accname.ts +587 -0
  59. package/typescript/core/accessibility/context.ts +116 -0
  60. package/typescript/core/accessibility/hidden.ts +242 -0
  61. package/typescript/core/accessibility/roles.ts +410 -0
  62. package/typescript/core/accessibility/snapshot.ts +61 -0
  63. package/typescript/core/accessibility/states.ts +233 -0
  64. package/typescript/core/accessibility/tree.ts +306 -0
  65. package/typescript/core/accessibility/types.ts +52 -0
  66. package/typescript/core/accessibility/value.ts +89 -0
  67. package/typescript/core/accessibility/wire.ts +123 -0
@@ -0,0 +1,410 @@
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
+ // Role computation: the explicit role attribute with the WAI-ARIA 1.2 fallback
19
+ // and conflict rules, then the html-aam implicit mapping. Where html-aam says
20
+ // an element has "no corresponding role" this reports `generic`, so the
21
+ // pruning rule in ADR 18205 treats it like a div. Two rows deliberately
22
+ // diverge from html-aam towards what engines expose, and the roles test page
23
+ // pins them: input type=password is a textbox and summary is a button.
24
+
25
+ // WAI-ARIA 1.2 roles authors may use (abstract roles left out), plus the
26
+ // graphics module roles that svg maps to.
27
+ const CONCRETE_ROLES: ReadonlySet<string> = new Set([
28
+ 'alert', 'alertdialog', 'application', 'article', 'banner', 'blockquote', 'button',
29
+ 'caption', 'cell', 'checkbox', 'code', 'columnheader', 'combobox', 'complementary',
30
+ 'contentinfo', 'definition', 'deletion', 'dialog', 'directory', 'document', 'emphasis',
31
+ 'feed', 'figure', 'form', 'generic', 'grid', 'gridcell', 'group', 'heading', 'img',
32
+ 'insertion', 'link', 'list', 'listbox', 'listitem', 'log', 'main', 'marquee', 'math',
33
+ 'menu', 'menubar', 'menuitem', 'menuitemcheckbox', 'menuitemradio', 'meter',
34
+ 'navigation', 'none', 'note', 'option', 'paragraph', 'presentation', 'progressbar',
35
+ 'radio', 'radiogroup', 'region', 'row', 'rowgroup', 'rowheader', 'scrollbar', 'search',
36
+ 'searchbox', 'separator', 'slider', 'spinbutton', 'status', 'strong', 'subscript',
37
+ 'superscript', 'switch', 'tab', 'table', 'tablist', 'tabpanel', 'term', 'textbox', 'time',
38
+ 'timer', 'toolbar', 'tooltip', 'tree', 'treegrid', 'treeitem',
39
+ 'graphics-document', 'graphics-object', 'graphics-symbol',
40
+ ])
41
+
42
+ // WAI-ARIA 1.2 §6.4, global states and properties, including the four the
43
+ // spec deprecates as globals but still lists. Their presence stops
44
+ // none/presentation from applying (§9.1).
45
+ const GLOBAL_ARIA_ATTRIBUTES: ReadonlyArray<string> = [
46
+ 'aria-atomic', 'aria-busy', 'aria-controls', 'aria-current', 'aria-describedby',
47
+ 'aria-description', 'aria-details', 'aria-disabled', 'aria-dropeffect', 'aria-errormessage',
48
+ 'aria-flowto', 'aria-grabbed', 'aria-haspopup', 'aria-hidden', 'aria-invalid',
49
+ 'aria-keyshortcuts', 'aria-label', 'aria-labelledby', 'aria-live', 'aria-owns',
50
+ 'aria-relevant', 'aria-roledescription',
51
+ ]
52
+
53
+ // Elements that take focus on their own, when not disabled.
54
+ const NATIVELY_FOCUSABLE: ReadonlySet<string> = new Set(['button', 'iframe', 'input', 'select', 'summary', 'textarea'])
55
+
56
+ // Not a WAI-ARIA role: the token ADR 18205 uses for frame leaves, which the
57
+ // bindings replace with the child document's tree.
58
+ const FRAME_ELEMENTS: ReadonlySet<string> = new Set(['frame', 'iframe'])
59
+
60
+ const SECTIONING_CONTENT: ReadonlySet<string> = new Set(['article', 'aside', 'nav', 'section'])
61
+ // html-aam: a header or footer is a landmark only outside these elements and
62
+ // outside elements with these roles.
63
+ const HEADER_FOOTER_SCOPES: ReadonlySet<string> = new Set(['article', 'aside', 'main', 'nav', 'section'])
64
+ const HEADER_FOOTER_SCOPE_ROLES: ReadonlySet<string> = new Set(['article', 'complementary', 'main', 'navigation', 'region'])
65
+ const LIST_PARENTS: ReadonlySet<string> = new Set(['menu', 'ol', 'ul'])
66
+
67
+ export function isPresentational(role: string): boolean {
68
+ return role === 'none' || role === 'presentation'
69
+ }
70
+
71
+ /**
72
+ * How the role of another element is found when one element's role depends
73
+ * on it (a cell on its table, an li on its list). The snapshot context
74
+ * passes its cached lookup so the owner is computed once for all of them.
75
+ */
76
+ export type RoleLookup = (element: Element) => string
77
+
78
+ /**
79
+ * The first token of the role attribute that names a role authors may use,
80
+ * or null when there is none. Tokens match ASCII case-insensitively, which is
81
+ * what engines do.
82
+ */
83
+ export function explicitRole(element: Element): string | null {
84
+ const attribute = element.getAttribute('role')
85
+ if (!attribute) {
86
+ return null
87
+ }
88
+ for (const token of attribute.trim().toLowerCase().split(/\s+/)) {
89
+ if (CONCRETE_ROLES.has(token)) {
90
+ return token
91
+ }
92
+ }
93
+ return null
94
+ }
95
+
96
+ function hasGlobalAriaAttribute(element: Element): boolean {
97
+ return GLOBAL_ARIA_ATTRIBUTES.some((name) => element.hasAttribute(name))
98
+ }
99
+
100
+ // "Focusable" in the §9.1 sense: the element can take focus at all, including
101
+ // through a negative tabindex. This is narrower than core/focusable.ts, which
102
+ // answers WebDriver's question and counts every anchor and label. The states
103
+ // module uses the same notion for what an ancestor's aria-disabled reaches.
104
+ export function canTakeFocus(element: Element): boolean {
105
+ const name = element.localName
106
+ if (NATIVELY_FOCUSABLE.has(name)) {
107
+ // A disabled control or a hidden input cannot take focus, whatever its tabindex.
108
+ if (name === 'input' && (element as HTMLInputElement).type === 'hidden') {
109
+ return false
110
+ }
111
+ return !('disabled' in element && (element as HTMLInputElement).disabled)
112
+ }
113
+ const tabindex = element.getAttribute('tabindex')
114
+ if (tabindex !== null && /^\s*[-+]?\d+\s*$/.test(tabindex)) {
115
+ return true
116
+ }
117
+ if (name === 'a' || name === 'area') {
118
+ return element.hasAttribute('href')
119
+ }
120
+ return (element as HTMLElement).isContentEditable === true
121
+ }
122
+
123
+ // html-aam makes some roles depend on whether the element has an accessible
124
+ // name (section, form, aside inside sectioning content). Only the author
125
+ // sources that can produce one are checked here: aria-label, an
126
+ // aria-labelledby that resolves to something with a text alternative, or a
127
+ // title. The full name computation is not what those rows ask for.
128
+ function hasAuthorName(element: Element): boolean {
129
+ const label = element.getAttribute('aria-label')
130
+ if (label !== null && label.trim() !== '') {
131
+ return true
132
+ }
133
+ const labelledBy = element.getAttribute('aria-labelledby')
134
+ if (labelledBy !== null && labelledBy.trim() !== '') {
135
+ const root = element.getRootNode() as Document | ShadowRoot
136
+ for (const id of labelledBy.trim().split(/\s+/)) {
137
+ const target = root.getElementById(id)
138
+ if (target && hasTextAlternative(target)) {
139
+ return true
140
+ }
141
+ }
142
+ }
143
+ const title = element.getAttribute('title')
144
+ return title !== null && title.trim() !== ''
145
+ }
146
+
147
+ // The attributes accname reads for the text alternative of an element inside
148
+ // a referenced label when it has no text of its own: an image's alt, a label
149
+ // or tooltip, a control's value.
150
+ const ALTERNATIVE_ATTRIBUTES = ['aria-label', 'alt', 'title', 'value']
151
+
152
+ // Whether a referenced label can contribute any text: its own text content,
153
+ // or an alternative on it or on an element below it.
154
+ function hasTextAlternative(target: Element): boolean {
155
+ if ((target.textContent || '').trim() !== '') {
156
+ return true
157
+ }
158
+ const elements = [target, ...Array.from(target.querySelectorAll('*'))]
159
+ return elements.some((candidate) =>
160
+ ALTERNATIVE_ATTRIBUTES.some((attribute) => (candidate.getAttribute(attribute) || '').trim() !== ''),
161
+ )
162
+ }
163
+
164
+ // WAI-ARIA 1.2 §9.1: when an element with required owned elements is
165
+ // presentational, so are those owned elements.
166
+ function ownerIsPresentational(owner: Element | null, lookup: RoleLookup): boolean {
167
+ return owner !== null && isPresentational(lookup(owner))
168
+ }
169
+
170
+ function hasAncestor(element: Element, names: ReadonlySet<string>, roles: ReadonlySet<string> | null = null): boolean {
171
+ for (let parent = element.parentElement; parent; parent = parent.parentElement) {
172
+ if (names.has(parent.localName)) {
173
+ return true
174
+ }
175
+ if (roles !== null) {
176
+ const role = explicitRole(parent)
177
+ if (role !== null && roles.has(role)) {
178
+ return true
179
+ }
180
+ }
181
+ }
182
+ return false
183
+ }
184
+
185
+ function inputRole(input: HTMLInputElement): string {
186
+ // The IDL property already folds unknown and missing types to "text".
187
+ const type = input.type
188
+ const hasList = input.hasAttribute('list')
189
+ switch (type) {
190
+ case 'button':
191
+ case 'image':
192
+ case 'reset':
193
+ case 'submit':
194
+ return 'button'
195
+ case 'checkbox':
196
+ return 'checkbox'
197
+ case 'radio':
198
+ return 'radio'
199
+ case 'range':
200
+ return 'slider'
201
+ case 'number':
202
+ return 'spinbutton'
203
+ case 'search':
204
+ return hasList ? 'combobox' : 'searchbox'
205
+ case 'email':
206
+ case 'tel':
207
+ case 'text':
208
+ case 'url':
209
+ return hasList ? 'combobox' : 'textbox'
210
+ case 'password':
211
+ // html-aam: no corresponding role. Engines expose a textbox, and
212
+ // dropping password fields from the tree would hide a control users act on.
213
+ return 'textbox'
214
+ default:
215
+ // color, date, datetime-local, file, hidden, month, time, week.
216
+ return 'generic'
217
+ }
218
+ }
219
+
220
+ function tableCellRole(cell: Element, lookup: RoleLookup): string {
221
+ const table = cell.closest('table')
222
+ if (!table) {
223
+ return 'cell'
224
+ }
225
+ const tableRole = lookup(table)
226
+ if (isPresentational(tableRole)) {
227
+ return 'generic'
228
+ }
229
+ return tableRole === 'grid' || tableRole === 'treegrid' ? 'gridcell' : 'cell'
230
+ }
231
+
232
+ function tableHeaderRole(header: Element, lookup: RoleLookup): string {
233
+ if (ownerIsPresentational(header.closest('table'), lookup)) {
234
+ return 'generic'
235
+ }
236
+ const scope = (header.getAttribute('scope') || '').toLowerCase()
237
+ return scope === 'row' || scope === 'rowgroup' ? 'rowheader' : 'columnheader'
238
+ }
239
+
240
+ function tablePartRole(part: Element, role: string, lookup: RoleLookup): string {
241
+ return ownerIsPresentational(part.closest('table'), lookup) ? 'generic' : role
242
+ }
243
+
244
+ /**
245
+ * The html-aam implicit role of an element, with no regard to its role
246
+ * attribute. `lookup` finds the role of an element this one depends on.
247
+ */
248
+ export function implicitRole(element: Element, lookup: RoleLookup = computeRole): string {
249
+ switch (element.localName) {
250
+ case 'a':
251
+ case 'area':
252
+ return element.hasAttribute('href') ? 'link' : 'generic'
253
+ case 'address':
254
+ case 'details':
255
+ case 'fieldset':
256
+ case 'hgroup':
257
+ case 'optgroup':
258
+ return 'group'
259
+ case 'article':
260
+ return 'article'
261
+ case 'aside':
262
+ if (!hasAncestor(element, SECTIONING_CONTENT)) {
263
+ return 'complementary'
264
+ }
265
+ return hasAuthorName(element) ? 'complementary' : 'generic'
266
+ case 'blockquote':
267
+ return 'blockquote'
268
+ case 'button':
269
+ return 'button'
270
+ case 'caption':
271
+ return 'caption'
272
+ case 'code':
273
+ return 'code'
274
+ case 'datalist':
275
+ return 'listbox'
276
+ case 'dd':
277
+ return 'definition'
278
+ case 'del':
279
+ return 'deletion'
280
+ case 'dfn':
281
+ case 'dt':
282
+ return 'term'
283
+ case 'dialog':
284
+ return 'dialog'
285
+ case 'em':
286
+ return 'emphasis'
287
+ case 'figure':
288
+ return 'figure'
289
+ case 'footer':
290
+ return hasAncestor(element, HEADER_FOOTER_SCOPES, HEADER_FOOTER_SCOPE_ROLES) ? 'generic' : 'contentinfo'
291
+ case 'form':
292
+ // html-aam: a landmark only with an accessible name, otherwise no role.
293
+ return hasAuthorName(element) ? 'form' : 'generic'
294
+ case 'frame':
295
+ case 'iframe':
296
+ return 'iframe'
297
+ case 'h1':
298
+ case 'h2':
299
+ case 'h3':
300
+ case 'h4':
301
+ case 'h5':
302
+ case 'h6':
303
+ return 'heading'
304
+ case 'header':
305
+ return hasAncestor(element, HEADER_FOOTER_SCOPES, HEADER_FOOTER_SCOPE_ROLES) ? 'generic' : 'banner'
306
+ case 'hr':
307
+ return 'separator'
308
+ case 'html':
309
+ return 'document'
310
+ case 'img':
311
+ if (element.getAttribute('alt') === '' && !hasGlobalAriaAttribute(element) && !canTakeFocus(element)) {
312
+ return 'presentation'
313
+ }
314
+ return 'img'
315
+ case 'input':
316
+ return inputRole(element as HTMLInputElement)
317
+ case 'ins':
318
+ return 'insertion'
319
+ case 'li': {
320
+ const parent = element.parentElement
321
+ if (!parent || !LIST_PARENTS.has(parent.localName) || ownerIsPresentational(parent, lookup)) {
322
+ return 'generic'
323
+ }
324
+ return 'listitem'
325
+ }
326
+ case 'main':
327
+ return 'main'
328
+ case 'math':
329
+ return 'math'
330
+ case 'menu':
331
+ case 'ol':
332
+ case 'ul':
333
+ return 'list'
334
+ case 'meter':
335
+ return 'meter'
336
+ case 'nav':
337
+ return 'navigation'
338
+ case 'option':
339
+ return 'option'
340
+ case 'output':
341
+ return 'status'
342
+ case 'p':
343
+ return 'paragraph'
344
+ case 'progress':
345
+ return 'progressbar'
346
+ case 'search':
347
+ return 'search'
348
+ case 'section':
349
+ return hasAuthorName(element) ? 'region' : 'generic'
350
+ case 'select': {
351
+ const select = element as HTMLSelectElement
352
+ return select.multiple || select.size > 1 ? 'listbox' : 'combobox'
353
+ }
354
+ case 'strong':
355
+ return 'strong'
356
+ case 'sub':
357
+ return 'subscript'
358
+ case 'summary':
359
+ // html-aam: no corresponding role. Engines expose the disclosure control
360
+ // as a button, and that is what users click.
361
+ return 'button'
362
+ case 'sup':
363
+ return 'superscript'
364
+ case 'svg':
365
+ return 'graphics-document'
366
+ case 'table':
367
+ return 'table'
368
+ case 'tbody':
369
+ case 'tfoot':
370
+ case 'thead':
371
+ return tablePartRole(element, 'rowgroup', lookup)
372
+ case 'td':
373
+ return tableCellRole(element, lookup)
374
+ case 'textarea':
375
+ return 'textbox'
376
+ case 'th':
377
+ return tableHeaderRole(element, lookup)
378
+ case 'time':
379
+ return 'time'
380
+ case 'tr':
381
+ return tablePartRole(element, 'row', lookup)
382
+ default:
383
+ return 'generic'
384
+ }
385
+ }
386
+
387
+ /**
388
+ * The role the snapshot reports for an element: the explicit role when it
389
+ * names a usable role and is not a presentational role on an element that
390
+ * cannot be presentational (WAI-ARIA 1.2 §9.1), otherwise the implicit one.
391
+ * `lookup` finds the role of an element this one depends on; without one,
392
+ * it is computed afresh.
393
+ */
394
+ export function computeRole(element: Element, lookup: RoleLookup = computeRole): string {
395
+ if (FRAME_ELEMENTS.has(element.localName)) {
396
+ // The token is how the bindings find the frames whose documents they
397
+ // stitch in, so an explicit role (ARIA in HTML allows application,
398
+ // document, img and the presentational pair) never replaces it; the
399
+ // embedded document is exposed whatever the frame element is called.
400
+ return 'iframe'
401
+ }
402
+ const explicit = explicitRole(element)
403
+ if (explicit === null) {
404
+ return implicitRole(element, lookup)
405
+ }
406
+ if (isPresentational(explicit) && (canTakeFocus(element) || hasGlobalAriaAttribute(element))) {
407
+ return implicitRole(element, lookup)
408
+ }
409
+ return explicit
410
+ }
@@ -0,0 +1,61 @@
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 { createContext } from './context.js'
20
+ import { buildTree } from './tree.js'
21
+ import type { AccessibilityNode, SnapshotOptions } from './types.js'
22
+
23
+ const DOCUMENT_NODE = 9
24
+
25
+ function isDocument(node: unknown): node is Document {
26
+ return !!node && typeof node === 'object' && (node as Node).nodeType === DOCUMENT_NODE
27
+ }
28
+
29
+ // A root that is not attached cannot answer "hidden" or "focused" questions, and
30
+ // a non-element root has no tree to walk, so both are refused up front rather
31
+ // than producing a partial snapshot the caller cannot distinguish from a real one.
32
+ function resolveRoot(root: Element | Document | null | undefined): Element {
33
+ if (root === undefined || root === null) {
34
+ return document.documentElement
35
+ }
36
+ if (isDocument(root)) {
37
+ return root.documentElement
38
+ }
39
+ if (!isElement(root)) {
40
+ throw new Error('accessibilitySnapshot: root must be an Element or a Document')
41
+ }
42
+ if (!root.isConnected) {
43
+ throw new Error('accessibilitySnapshot: root is detached from its document')
44
+ }
45
+ return root
46
+ }
47
+
48
+ /**
49
+ * Computes an accessibility snapshot of the subtree rooted at `root`, or of the
50
+ * whole document when no root is given.
51
+ *
52
+ * The output is *computed* by script, not read from the browser's own
53
+ * accessibility tree. Frames are reported as `iframe` leaves and never
54
+ * descended into; callers stitch child-document snapshots in themselves.
55
+ *
56
+ */
57
+ function accessibilitySnapshot(root?: Element | Document | null, options?: SnapshotOptions): AccessibilityNode {
58
+ return buildTree(resolveRoot(root), createContext(options))
59
+ }
60
+
61
+ export default accessibilitySnapshot