@ctrl/dom 0.1.4 → 0.1.5
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/aria/_chunks/roles-list-BXCvPLJT.cjs +4 -0
- package/dist/aria/_chunks/roles-list-rVVxaIPs.js +4 -0
- package/dist/aria/index.cjs +1 -232
- package/dist/aria/index.js +1 -198
- package/dist/aria/internal.cjs +1 -69
- package/dist/aria/internal.js +1 -30
- package/dist/cli/_chunks/report-z52LF7nA.js +12 -0
- package/dist/cli/_chunks/rolldown-runtime-H3fMLYWS.js +1 -0
- package/dist/cli/ctrl-dom.js +2 -181
- package/dist/cli/jest-reporter.js +2 -54
- package/dist/cli/vitest-reporter.js +2 -81
- package/dist/dom/_chunks/src-sZY6a2LC.js +49 -0
- package/dist/dom/index.js +1 -3
- package/dist/dom/internal.js +1 -434
- package/dist/dom/types/window/clock.d.ts +2 -2
- package/dist/jest-dom/_chunks/matchers-CGTk9GX9.cjs +31 -0
- package/dist/jest-dom/_chunks/matchers-Chf0yHoo.js +31 -0
- package/dist/jest-dom/index.cjs +1 -5
- package/dist/jest-dom/index.js +1 -6
- package/dist/jest-dom/jest-globals.cjs +1 -6
- package/dist/jest-dom/jest-globals.js +1 -7
- package/dist/jest-dom/matchers.cjs +1 -53
- package/dist/jest-dom/matchers.js +1 -3
- package/dist/jest-dom/vitest.cjs +1 -6
- package/dist/jest-dom/vitest.js +1 -7
- package/dist/react/_chunks/pure-CCeTO5Mk.js +1 -0
- package/dist/react/_chunks/pure-DQzwul4s.cjs +1 -0
- package/dist/react/dont-cleanup-after-each.cjs +1 -3
- package/dist/react/dont-cleanup-after-each.js +1 -4
- package/dist/react/index.cjs +1 -47
- package/dist/react/index.js +1 -35
- package/dist/react/pure.cjs +1 -17
- package/dist/react/pure.js +1 -5
- package/dist/register/index.js +1 -11
- package/dist/register/pure.js +1 -147
- package/dist/testing-library/_chunks/aria-snapshot-diff-80G4meO2.cjs +14 -0
- package/dist/testing-library/_chunks/aria-snapshot-diff-B1L8s_sM.js +14 -0
- package/dist/testing-library/agent.cjs +10 -720
- package/dist/testing-library/agent.js +10 -712
- package/dist/testing-library/index.cjs +19 -2459
- package/dist/testing-library/index.js +19 -2380
- package/dist/user-event/index.cjs +33 -3924
- package/dist/user-event/index.js +33 -3899
- package/dist/user-event/types/ctrl-dom.d.ts +1 -1
- package/dist/vitest-environment/_chunks/rolldown-runtime-BhWHdk3m.js +1 -0
- package/dist/vitest-environment/failure-snapshot.js +1 -42
- package/dist/vitest-environment/index.js +1 -185
- package/dist/vitest-environment/plugin.js +1 -90
- package/package.json +1 -1
- package/dist/aria/_chunks/roles-list-CYZF-l9K.js +0 -1503
- package/dist/aria/_chunks/roles-list-D4WCyRO_.cjs +0 -1754
- package/dist/cli/_chunks/report-DdncYfuJ.js +0 -93
- package/dist/dom/_chunks/src-Cp3oLry4.js +0 -47610
- package/dist/jest-dom/_chunks/matchers-CDnnXUfG.js +0 -2211
- package/dist/jest-dom/_chunks/matchers-D988Ducb.cjs +0 -2516
- package/dist/react/_chunks/pure-DZ97z2oT.cjs +0 -498
- package/dist/react/_chunks/pure-PtE2hivW.js +0 -420
- package/dist/testing-library/_chunks/aria-snapshot-diff-D7PzpXew.cjs +0 -1170
- package/dist/testing-library/_chunks/aria-snapshot-diff-Q8Wj33K0.js +0 -985
|
@@ -1,1754 +0,0 @@
|
|
|
1
|
-
let _ctrl_dom_internal = require("@ctrl/dom/internal");
|
|
2
|
-
|
|
3
|
-
// src/forms.ts
|
|
4
|
-
/** Canonical `type` IDL value of an HTML input: https://html.spec.whatwg.org/multipage/input.html#attr-input-type */
|
|
5
|
-
const INPUT_TYPES = /* @__PURE__ */ new Set([
|
|
6
|
-
"hidden",
|
|
7
|
-
"text",
|
|
8
|
-
"search",
|
|
9
|
-
"tel",
|
|
10
|
-
"url",
|
|
11
|
-
"email",
|
|
12
|
-
"password",
|
|
13
|
-
"date",
|
|
14
|
-
"month",
|
|
15
|
-
"week",
|
|
16
|
-
"time",
|
|
17
|
-
"datetime-local",
|
|
18
|
-
"number",
|
|
19
|
-
"range",
|
|
20
|
-
"color",
|
|
21
|
-
"checkbox",
|
|
22
|
-
"radio",
|
|
23
|
-
"file",
|
|
24
|
-
"submit",
|
|
25
|
-
"image",
|
|
26
|
-
"reset",
|
|
27
|
-
"button"
|
|
28
|
-
]);
|
|
29
|
-
function inputType(impl) {
|
|
30
|
-
const t = (0, _ctrl_dom_internal.attr)(impl, "type");
|
|
31
|
-
if (t === null) return "text";
|
|
32
|
-
if (INPUT_TYPES.has(t)) return t;
|
|
33
|
-
const lower = t.toLowerCase();
|
|
34
|
-
return INPUT_TYPES.has(lower) ? lower : "text";
|
|
35
|
-
}
|
|
36
|
-
/** Child text content (https://dom.spec.whatwg.org/#concept-child-text-content). */
|
|
37
|
-
function childTextContent(impl) {
|
|
38
|
-
let s = "";
|
|
39
|
-
for (let c = impl.first; c !== null; c = c.next) if (c.type === 3 || c.type === 4) s += c.data;
|
|
40
|
-
return s;
|
|
41
|
-
}
|
|
42
|
-
/** `input.value` / `textarea.value`. */
|
|
43
|
-
function controlValue(impl) {
|
|
44
|
-
const v = impl.node.value;
|
|
45
|
-
if (typeof v === "string") return v;
|
|
46
|
-
if (impl.tag === _ctrl_dom_internal.T.textarea) return childTextContent(impl);
|
|
47
|
-
return (0, _ctrl_dom_internal.attr)(impl, "value") ?? "";
|
|
48
|
-
}
|
|
49
|
-
/** `input.checked` (checkedness). */
|
|
50
|
-
function checkedness(impl) {
|
|
51
|
-
const v = impl.node.checked;
|
|
52
|
-
if (typeof v === "boolean") return v;
|
|
53
|
-
return (0, _ctrl_dom_internal.attr)(impl, "checked") !== null;
|
|
54
|
-
}
|
|
55
|
-
/** `input.indeterminate` (IDL-only flag, never reflected). */
|
|
56
|
-
function indeterminate(impl) {
|
|
57
|
-
return impl.node.indeterminate === true;
|
|
58
|
-
}
|
|
59
|
-
/** The select's list of options: https://html.spec.whatwg.org/multipage/form-elements.html#concept-select-option-list */
|
|
60
|
-
function listOfOptions(select, out) {
|
|
61
|
-
for (let c = select.first; c !== null; c = c.next) {
|
|
62
|
-
if (c.ns !== _ctrl_dom_internal.HTML_NS) continue;
|
|
63
|
-
if (c.tag === _ctrl_dom_internal.T.option) out.push(c);
|
|
64
|
-
else if (c.tag === _ctrl_dom_internal.T.optgroup) {
|
|
65
|
-
for (let o = c.first; o !== null; o = o.next) if (o.tag === _ctrl_dom_internal.T.option && o.ns === _ctrl_dom_internal.HTML_NS) out.push(o);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return out;
|
|
69
|
-
}
|
|
70
|
-
/** Display size: https://html.spec.whatwg.org/multipage/form-elements.html#concept-select-size */
|
|
71
|
-
function selectSize(impl) {
|
|
72
|
-
const s = (0, _ctrl_dom_internal.attr)(impl, "size");
|
|
73
|
-
if (s === null) return 0;
|
|
74
|
-
const m = /^[\t\n\f\r ]*\+?(\d+)/.exec(s);
|
|
75
|
-
if (m === null) return 0;
|
|
76
|
-
const n = Number(m[1]);
|
|
77
|
-
return n > 2147483647 ? 0 : n;
|
|
78
|
-
}
|
|
79
|
-
/** Selectedness of each option per the HTML "selectedness setting algorithm" applied to the initial (attribute) state. */
|
|
80
|
-
function fallbackSelected(select, option) {
|
|
81
|
-
if (select === null) return (0, _ctrl_dom_internal.attr)(option, "selected") !== null;
|
|
82
|
-
const options = listOfOptions(select, []);
|
|
83
|
-
if ((0, _ctrl_dom_internal.attr)(select, "multiple") !== null) return (0, _ctrl_dom_internal.attr)(option, "selected") !== null;
|
|
84
|
-
let chosen = null;
|
|
85
|
-
for (const o of options) if ((0, _ctrl_dom_internal.attr)(o, "selected") !== null) chosen = o;
|
|
86
|
-
if (chosen === null && selectSize(select) <= 1) for (const o of options) {
|
|
87
|
-
if ((0, _ctrl_dom_internal.attr)(o, "disabled") !== null) continue;
|
|
88
|
-
if (o.parent !== null && o.parent.tag === _ctrl_dom_internal.T.optgroup && (0, _ctrl_dom_internal.attr)(o.parent, "disabled") !== null) continue;
|
|
89
|
-
chosen = o;
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
return chosen === option;
|
|
93
|
-
}
|
|
94
|
-
function owningSelect(option) {
|
|
95
|
-
const p = option.parent;
|
|
96
|
-
if (p === null) return null;
|
|
97
|
-
if (p.tag === _ctrl_dom_internal.T.select && p.ns === _ctrl_dom_internal.HTML_NS) return p;
|
|
98
|
-
if (p.tag === _ctrl_dom_internal.T.optgroup && p.parent !== null && p.parent.tag === _ctrl_dom_internal.T.select && p.parent.ns === _ctrl_dom_internal.HTML_NS) return p.parent;
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
/** `option.selected` (selectedness). */
|
|
102
|
-
function optionSelected(option) {
|
|
103
|
-
const v = option.node.selected;
|
|
104
|
-
if (typeof v === "boolean") return v;
|
|
105
|
-
return fallbackSelected(owningSelect(option), option);
|
|
106
|
-
}
|
|
107
|
-
/** `select.selectedOptions`, in tree order. */
|
|
108
|
-
function selectedOptions(select) {
|
|
109
|
-
const so = select.node.selectedOptions;
|
|
110
|
-
if (so !== void 0 && so !== null && typeof so.length === "number") {
|
|
111
|
-
const out = [];
|
|
112
|
-
for (let i = 0; i < so.length; i++) out.push(so[i][_ctrl_dom_internal.$impl]);
|
|
113
|
-
return out;
|
|
114
|
-
}
|
|
115
|
-
const out = [];
|
|
116
|
-
for (const o of listOfOptions(select, [])) if (optionSelected(o)) out.push(o);
|
|
117
|
-
return out;
|
|
118
|
-
}
|
|
119
|
-
/** https://html.spec.whatwg.org/multipage/forms.html#category-label (as jsdom implements it). */
|
|
120
|
-
function isLabelable(impl) {
|
|
121
|
-
if (impl.type !== _ctrl_dom_internal.ELEMENT_NODE || impl.ns !== _ctrl_dom_internal.HTML_NS) return false;
|
|
122
|
-
switch (impl.tag) {
|
|
123
|
-
case _ctrl_dom_internal.T.button:
|
|
124
|
-
case _ctrl_dom_internal.T.meter:
|
|
125
|
-
case _ctrl_dom_internal.T.output:
|
|
126
|
-
case _ctrl_dom_internal.T.progress:
|
|
127
|
-
case _ctrl_dom_internal.T.select:
|
|
128
|
-
case _ctrl_dom_internal.T.textarea: return true;
|
|
129
|
-
case _ctrl_dom_internal.T.input: return inputType(impl) !== "hidden";
|
|
130
|
-
}
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
var LabelIndex = class {
|
|
134
|
-
version;
|
|
135
|
-
map;
|
|
136
|
-
constructor(version) {
|
|
137
|
-
this.version = version;
|
|
138
|
-
this.map = /* @__PURE__ */ new Map();
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
/**
|
|
142
|
-
* Label associations per tree root, rebuilt when the document version changes (jsdom memoizes
|
|
143
|
-
* the same way). Held in the document's derived caches (dropped on node removal) so a stale index
|
|
144
|
-
* never keeps a removed tree alive.
|
|
145
|
-
*/
|
|
146
|
-
const LABEL_INDEXES = {};
|
|
147
|
-
const newLabelIndexes = () => /* @__PURE__ */ new WeakMap();
|
|
148
|
-
const EMPTY = [];
|
|
149
|
-
function buildLabelIndex(root, version) {
|
|
150
|
-
const index = new LabelIndex(version);
|
|
151
|
-
const labels = [];
|
|
152
|
-
let ids = null;
|
|
153
|
-
const useDocIds = root.type === _ctrl_dom_internal.DOCUMENT_NODE;
|
|
154
|
-
let anyFor = false;
|
|
155
|
-
for (let n = root; n !== null;) {
|
|
156
|
-
if (n.type === _ctrl_dom_internal.ELEMENT_NODE) {
|
|
157
|
-
if (n.tag === _ctrl_dom_internal.T.label && n.ns === _ctrl_dom_internal.HTML_NS) {
|
|
158
|
-
labels.push(n);
|
|
159
|
-
if ((0, _ctrl_dom_internal.attr)(n, "for") !== null) anyFor = true;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
if (n.first !== null) n = n.first;
|
|
163
|
-
else {
|
|
164
|
-
let cur = n;
|
|
165
|
-
n = null;
|
|
166
|
-
while (cur !== null && cur !== root) {
|
|
167
|
-
if (cur.next !== null) {
|
|
168
|
-
n = cur.next;
|
|
169
|
-
break;
|
|
170
|
-
}
|
|
171
|
-
cur = cur.parent;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
if (labels.length === 0) return index;
|
|
176
|
-
if (anyFor && !useDocIds) {
|
|
177
|
-
ids = /* @__PURE__ */ new Map();
|
|
178
|
-
for (let n = root; n !== null;) {
|
|
179
|
-
if (n.type === _ctrl_dom_internal.ELEMENT_NODE && n.id !== "" && !ids.has(n.id)) ids.set(n.id, n);
|
|
180
|
-
if (n.first !== null) n = n.first;
|
|
181
|
-
else {
|
|
182
|
-
let cur = n;
|
|
183
|
-
n = null;
|
|
184
|
-
while (cur !== null && cur !== root) {
|
|
185
|
-
if (cur.next !== null) {
|
|
186
|
-
n = cur.next;
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
cur = cur.parent;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
for (const label of labels) {
|
|
195
|
-
const control = labeledControl(label, useDocIds ? root : null, ids);
|
|
196
|
-
if (control === null) continue;
|
|
197
|
-
const list = index.map.get(control);
|
|
198
|
-
if (list === void 0) index.map.set(control, [label]);
|
|
199
|
-
else list.push(label);
|
|
200
|
-
}
|
|
201
|
-
return index;
|
|
202
|
-
}
|
|
203
|
-
/** https://html.spec.whatwg.org/multipage/forms.html#labeled-control */
|
|
204
|
-
function labeledControl(label, docRoot, ids) {
|
|
205
|
-
const forValue = (0, _ctrl_dom_internal.attr)(label, "for");
|
|
206
|
-
if (forValue !== null) {
|
|
207
|
-
if (forValue === "") return null;
|
|
208
|
-
let target;
|
|
209
|
-
if (docRoot !== null) target = docRoot.node._idLookup(forValue);
|
|
210
|
-
else target = ids?.get(forValue) ?? null;
|
|
211
|
-
return target !== null && isLabelable(target) ? target : null;
|
|
212
|
-
}
|
|
213
|
-
for (let n = label.first; n !== null;) {
|
|
214
|
-
if (n.type === _ctrl_dom_internal.ELEMENT_NODE && isLabelable(n)) return n;
|
|
215
|
-
if (n.first !== null) n = n.first;
|
|
216
|
-
else {
|
|
217
|
-
let cur = n;
|
|
218
|
-
n = null;
|
|
219
|
-
while (cur !== null && cur !== label) {
|
|
220
|
-
if (cur.next !== null) {
|
|
221
|
-
n = cur.next;
|
|
222
|
-
break;
|
|
223
|
-
}
|
|
224
|
-
cur = cur.parent;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return null;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* `element.labels` as jsdom computes it: null for non-labelable elements, otherwise the
|
|
232
|
-
* label elements (tree order, same tree) whose labeled control is the element.
|
|
233
|
-
*/
|
|
234
|
-
function labelsOf(impl) {
|
|
235
|
-
if (!isLabelable(impl)) return null;
|
|
236
|
-
const root = (0, _ctrl_dom_internal.treeRoot)(impl);
|
|
237
|
-
const version = impl.doc[_ctrl_dom_internal.$version];
|
|
238
|
-
const labelIndexes = (0, _ctrl_dom_internal.derivedCache)(impl.doc, LABEL_INDEXES, newLabelIndexes);
|
|
239
|
-
let index = labelIndexes.get(root);
|
|
240
|
-
if (index === void 0 || index.version !== version) {
|
|
241
|
-
index = buildLabelIndex(root, version);
|
|
242
|
-
labelIndexes.set(root, index);
|
|
243
|
-
}
|
|
244
|
-
return index.map.get(impl) ?? EMPTY;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// src/role.ts
|
|
248
|
-
/** Tag id by local name for any namespace (type selectors / `localName` checks are namespace-agnostic). */
|
|
249
|
-
function anyTag(impl) {
|
|
250
|
-
return impl.tag !== 0 ? impl.tag : (0, _ctrl_dom_internal.tagId)(impl.name);
|
|
251
|
-
}
|
|
252
|
-
/** Present and not the empty string (aria-query constraint "set"). */
|
|
253
|
-
function isSet(impl, name) {
|
|
254
|
-
const v = (0, _ctrl_dom_internal.attr)(impl, name);
|
|
255
|
-
return v !== null && v !== "";
|
|
256
|
-
}
|
|
257
|
-
/** `[name="value"]` for HTML attributes whose values match ASCII case-insensitively in selectors (`type`, `scope`). */
|
|
258
|
-
function eqCI(v, lower) {
|
|
259
|
-
return v !== null && v.length === lower.length && (v === lower || v.toLowerCase() === lower);
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* The single implicit role Testing Library 10.4 computes for an element, or "" for none
|
|
263
|
-
* (`getImplicitAriaRoles(el)[0] ?? ""`). Every aria-query@5.3.0 element entry maps to
|
|
264
|
-
* exactly one role, so the list form always has at most one element.
|
|
265
|
-
*/
|
|
266
|
-
function implicitRole(impl) {
|
|
267
|
-
return implicitRoleImpl(impl, false);
|
|
268
|
-
}
|
|
269
|
-
/** jest-dom@7's `getImplicitAriaRoles` variant (see module comment). */
|
|
270
|
-
function implicitRoleJestDom(impl) {
|
|
271
|
-
return implicitRoleImpl(impl, true);
|
|
272
|
-
}
|
|
273
|
-
function implicitRoleImpl(impl, jd) {
|
|
274
|
-
if (impl.type !== _ctrl_dom_internal.ELEMENT_NODE) return "";
|
|
275
|
-
switch (anyTag(impl)) {
|
|
276
|
-
case 0: return "";
|
|
277
|
-
case _ctrl_dom_internal.T.input: return inputRole(impl, jd);
|
|
278
|
-
case _ctrl_dom_internal.T.select: return (0, _ctrl_dom_internal.attr)(impl, "multiple") === null && (0, _ctrl_dom_internal.attr)(impl, "size") === null ? "combobox" : "listbox";
|
|
279
|
-
case _ctrl_dom_internal.T.th: {
|
|
280
|
-
const scope = (0, _ctrl_dom_internal.attr)(impl, "scope");
|
|
281
|
-
if (eqCI(scope, "col") || eqCI(scope, "colgroup")) return "columnheader";
|
|
282
|
-
if (eqCI(scope, "row") || eqCI(scope, "rowgroup")) return "rowheader";
|
|
283
|
-
return "columnheader";
|
|
284
|
-
}
|
|
285
|
-
case _ctrl_dom_internal.T.aside: return "complementary";
|
|
286
|
-
case _ctrl_dom_internal.T.form:
|
|
287
|
-
if (jd) return (0, _ctrl_dom_internal.attr)(impl, "aria-label") !== null || (0, _ctrl_dom_internal.attr)(impl, "aria-labelledby") !== null || (0, _ctrl_dom_internal.attr)(impl, "name") !== null ? "form" : "";
|
|
288
|
-
return isSet(impl, "aria-label") || isSet(impl, "aria-labelledby") || isSet(impl, "name") ? "form" : "";
|
|
289
|
-
case _ctrl_dom_internal.T.img:
|
|
290
|
-
if (jd) return "img";
|
|
291
|
-
return (0, _ctrl_dom_internal.attr)(impl, "alt") === "" ? "presentation" : "img";
|
|
292
|
-
case _ctrl_dom_internal.T.a:
|
|
293
|
-
case _ctrl_dom_internal.T.area:
|
|
294
|
-
if (jd) return (0, _ctrl_dom_internal.attr)(impl, "href") !== null ? "link" : "generic";
|
|
295
|
-
return isSet(impl, "href") ? "link" : "generic";
|
|
296
|
-
case _ctrl_dom_internal.T.section:
|
|
297
|
-
if (jd) return (0, _ctrl_dom_internal.attr)(impl, "aria-label") !== null || (0, _ctrl_dom_internal.attr)(impl, "aria-labelledby") !== null ? "region" : "generic";
|
|
298
|
-
return isSet(impl, "aria-label") || isSet(impl, "aria-labelledby") ? "region" : "generic";
|
|
299
|
-
case _ctrl_dom_internal.T.article: return "article";
|
|
300
|
-
case _ctrl_dom_internal.T.header: return "banner";
|
|
301
|
-
case _ctrl_dom_internal.T.blockquote: return "blockquote";
|
|
302
|
-
case _ctrl_dom_internal.T.button: return "button";
|
|
303
|
-
case _ctrl_dom_internal.T.caption: return "caption";
|
|
304
|
-
case _ctrl_dom_internal.T.td: return "cell";
|
|
305
|
-
case _ctrl_dom_internal.T.code: return "code";
|
|
306
|
-
case _ctrl_dom_internal.T.footer: return "contentinfo";
|
|
307
|
-
case _ctrl_dom_internal.T.dd: return "definition";
|
|
308
|
-
case _ctrl_dom_internal.T.del: return "deletion";
|
|
309
|
-
case _ctrl_dom_internal.T.dialog: return "dialog";
|
|
310
|
-
case _ctrl_dom_internal.T.html: return "document";
|
|
311
|
-
case _ctrl_dom_internal.T.em: return "emphasis";
|
|
312
|
-
case _ctrl_dom_internal.T.figure: return "figure";
|
|
313
|
-
case _ctrl_dom_internal.T.b:
|
|
314
|
-
case _ctrl_dom_internal.T.bdo:
|
|
315
|
-
case _ctrl_dom_internal.T.body:
|
|
316
|
-
case _ctrl_dom_internal.T.data:
|
|
317
|
-
case _ctrl_dom_internal.T.div:
|
|
318
|
-
case _ctrl_dom_internal.T.hgroup:
|
|
319
|
-
case _ctrl_dom_internal.T.i:
|
|
320
|
-
case _ctrl_dom_internal.T.pre:
|
|
321
|
-
case _ctrl_dom_internal.T.q:
|
|
322
|
-
case _ctrl_dom_internal.T.samp:
|
|
323
|
-
case _ctrl_dom_internal.T.small:
|
|
324
|
-
case _ctrl_dom_internal.T.span:
|
|
325
|
-
case _ctrl_dom_internal.T.u: return "generic";
|
|
326
|
-
case _ctrl_dom_internal.T.details:
|
|
327
|
-
case _ctrl_dom_internal.T.fieldset:
|
|
328
|
-
case _ctrl_dom_internal.T.optgroup:
|
|
329
|
-
case _ctrl_dom_internal.T.address: return "group";
|
|
330
|
-
case _ctrl_dom_internal.T.h1:
|
|
331
|
-
case _ctrl_dom_internal.T.h2:
|
|
332
|
-
case _ctrl_dom_internal.T.h3:
|
|
333
|
-
case _ctrl_dom_internal.T.h4:
|
|
334
|
-
case _ctrl_dom_internal.T.h5:
|
|
335
|
-
case _ctrl_dom_internal.T.h6: return "heading";
|
|
336
|
-
case _ctrl_dom_internal.T.ins: return "insertion";
|
|
337
|
-
case _ctrl_dom_internal.T.menu:
|
|
338
|
-
case _ctrl_dom_internal.T.ol:
|
|
339
|
-
case _ctrl_dom_internal.T.ul: return "list";
|
|
340
|
-
case _ctrl_dom_internal.T.datalist: return "listbox";
|
|
341
|
-
case _ctrl_dom_internal.T.li: return "listitem";
|
|
342
|
-
case _ctrl_dom_internal.T.main: return "main";
|
|
343
|
-
case _ctrl_dom_internal.T.mark: return "mark";
|
|
344
|
-
case _ctrl_dom_internal.T.math: return "math";
|
|
345
|
-
case _ctrl_dom_internal.T.meter: return "meter";
|
|
346
|
-
case _ctrl_dom_internal.T.nav: return "navigation";
|
|
347
|
-
case _ctrl_dom_internal.T.option: return "option";
|
|
348
|
-
case _ctrl_dom_internal.T.p: return "paragraph";
|
|
349
|
-
case _ctrl_dom_internal.T.progress: return "progressbar";
|
|
350
|
-
case _ctrl_dom_internal.T.tr: return "row";
|
|
351
|
-
case _ctrl_dom_internal.T.tbody:
|
|
352
|
-
case _ctrl_dom_internal.T.tfoot:
|
|
353
|
-
case _ctrl_dom_internal.T.thead: return "rowgroup";
|
|
354
|
-
case _ctrl_dom_internal.T.hr: return "separator";
|
|
355
|
-
case _ctrl_dom_internal.T.output: return "status";
|
|
356
|
-
case _ctrl_dom_internal.T.strong: return "strong";
|
|
357
|
-
case _ctrl_dom_internal.T.sub: return "subscript";
|
|
358
|
-
case _ctrl_dom_internal.T.sup: return "superscript";
|
|
359
|
-
case _ctrl_dom_internal.T.table: return "table";
|
|
360
|
-
case _ctrl_dom_internal.T.dfn:
|
|
361
|
-
case _ctrl_dom_internal.T.dt: return "term";
|
|
362
|
-
case _ctrl_dom_internal.T.textarea: return "textbox";
|
|
363
|
-
case _ctrl_dom_internal.T.time: return "time";
|
|
364
|
-
default: return "";
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
function inputRole(impl, jd) {
|
|
368
|
-
const list = (0, _ctrl_dom_internal.attr)(impl, "list");
|
|
369
|
-
const typeAttr = (0, _ctrl_dom_internal.attr)(impl, "type");
|
|
370
|
-
const typeIsText = impl.ns === _ctrl_dom_internal.HTML_NS && inputType(impl) === "text";
|
|
371
|
-
if ((jd ? list !== null : list !== null && list !== "") && (typeIsText || eqCI(typeAttr, "email") || eqCI(typeAttr, "search") || eqCI(typeAttr, "tel") || eqCI(typeAttr, "url"))) return "combobox";
|
|
372
|
-
if (list === null) {
|
|
373
|
-
if (eqCI(typeAttr, "search")) return "searchbox";
|
|
374
|
-
if (typeAttr === null) return "textbox";
|
|
375
|
-
if (typeIsText || eqCI(typeAttr, "email") || eqCI(typeAttr, "tel") || eqCI(typeAttr, "url")) return "textbox";
|
|
376
|
-
}
|
|
377
|
-
if (typeAttr === null) return "";
|
|
378
|
-
switch (typeAttr.toLowerCase()) {
|
|
379
|
-
case "button":
|
|
380
|
-
case "image":
|
|
381
|
-
case "reset":
|
|
382
|
-
case "submit": return "button";
|
|
383
|
-
case "checkbox": return "checkbox";
|
|
384
|
-
case "radio": return "radio";
|
|
385
|
-
case "range": return "slider";
|
|
386
|
-
case "number": return "spinbutton";
|
|
387
|
-
default: return "";
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
/** Testing Library's `getImplicitAriaRoles(el)`: a fresh array of zero or one role. */
|
|
391
|
-
function getImplicitRoles(impl) {
|
|
392
|
-
const r = implicitRole(impl);
|
|
393
|
-
return r === "" ? [] : [r];
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* The role Testing Library matches `*ByRole` against without `queryFallbacks`: the first
|
|
397
|
-
* " "-separated token of the role attribute when present (possibly ""), else the implicit
|
|
398
|
-
* role ("" for none).
|
|
399
|
-
*/
|
|
400
|
-
function tlRole(impl) {
|
|
401
|
-
const role = (0, _ctrl_dom_internal.attr)(impl, "role");
|
|
402
|
-
if (role !== null) {
|
|
403
|
-
const sp = role.indexOf(" ");
|
|
404
|
-
return sp === -1 ? role : role.slice(0, sp);
|
|
405
|
-
}
|
|
406
|
-
return implicitRole(impl);
|
|
407
|
-
}
|
|
408
|
-
/** dom-accessibility-api's localNameToRoleMappings, by tag id. */
|
|
409
|
-
const DAA_ROLE_BY_TAG = [];
|
|
410
|
-
for (const [name, role] of Object.entries({
|
|
411
|
-
article: "article",
|
|
412
|
-
aside: "complementary",
|
|
413
|
-
button: "button",
|
|
414
|
-
datalist: "listbox",
|
|
415
|
-
dd: "definition",
|
|
416
|
-
details: "group",
|
|
417
|
-
dialog: "dialog",
|
|
418
|
-
dt: "term",
|
|
419
|
-
fieldset: "group",
|
|
420
|
-
figure: "figure",
|
|
421
|
-
form: "form",
|
|
422
|
-
footer: "contentinfo",
|
|
423
|
-
h1: "heading",
|
|
424
|
-
h2: "heading",
|
|
425
|
-
h3: "heading",
|
|
426
|
-
h4: "heading",
|
|
427
|
-
h5: "heading",
|
|
428
|
-
h6: "heading",
|
|
429
|
-
header: "banner",
|
|
430
|
-
hr: "separator",
|
|
431
|
-
html: "document",
|
|
432
|
-
legend: "legend",
|
|
433
|
-
li: "listitem",
|
|
434
|
-
math: "math",
|
|
435
|
-
main: "main",
|
|
436
|
-
menu: "list",
|
|
437
|
-
nav: "navigation",
|
|
438
|
-
ol: "list",
|
|
439
|
-
optgroup: "group",
|
|
440
|
-
option: "option",
|
|
441
|
-
output: "status",
|
|
442
|
-
progress: "progressbar",
|
|
443
|
-
section: "region",
|
|
444
|
-
summary: "button",
|
|
445
|
-
table: "table",
|
|
446
|
-
tbody: "rowgroup",
|
|
447
|
-
textarea: "textbox",
|
|
448
|
-
tfoot: "rowgroup",
|
|
449
|
-
td: "cell",
|
|
450
|
-
th: "columnheader",
|
|
451
|
-
thead: "rowgroup",
|
|
452
|
-
tr: "row",
|
|
453
|
-
ul: "list"
|
|
454
|
-
})) DAA_ROLE_BY_TAG[(0, _ctrl_dom_internal.tagId)(name)] = role;
|
|
455
|
-
/** https://rawgit.com/w3c/aria/stable/#global_states as listed by dom-accessibility-api. */
|
|
456
|
-
const GLOBAL_ARIA_05 = [
|
|
457
|
-
"aria-atomic",
|
|
458
|
-
"aria-busy",
|
|
459
|
-
"aria-controls",
|
|
460
|
-
"aria-current",
|
|
461
|
-
"aria-describedby",
|
|
462
|
-
"aria-details",
|
|
463
|
-
"aria-dropeffect",
|
|
464
|
-
"aria-flowto",
|
|
465
|
-
"aria-grabbed",
|
|
466
|
-
"aria-hidden",
|
|
467
|
-
"aria-keyshortcuts",
|
|
468
|
-
"aria-label",
|
|
469
|
-
"aria-labelledby",
|
|
470
|
-
"aria-live",
|
|
471
|
-
"aria-owns",
|
|
472
|
-
"aria-relevant",
|
|
473
|
-
"aria-roledescription"
|
|
474
|
-
];
|
|
475
|
-
const GLOBAL_ARIA_06 = [
|
|
476
|
-
"aria-atomic",
|
|
477
|
-
"aria-busy",
|
|
478
|
-
"aria-controls",
|
|
479
|
-
"aria-current",
|
|
480
|
-
"aria-description",
|
|
481
|
-
"aria-describedby",
|
|
482
|
-
"aria-details",
|
|
483
|
-
"aria-dropeffect",
|
|
484
|
-
"aria-flowto",
|
|
485
|
-
"aria-grabbed",
|
|
486
|
-
"aria-hidden",
|
|
487
|
-
"aria-keyshortcuts",
|
|
488
|
-
"aria-label",
|
|
489
|
-
"aria-labelledby",
|
|
490
|
-
"aria-live",
|
|
491
|
-
"aria-owns",
|
|
492
|
-
"aria-relevant",
|
|
493
|
-
"aria-roledescription"
|
|
494
|
-
];
|
|
495
|
-
function isProhibited(role, name, flavor) {
|
|
496
|
-
switch (role) {
|
|
497
|
-
case "caption":
|
|
498
|
-
case "code":
|
|
499
|
-
case "deletion":
|
|
500
|
-
case "emphasis":
|
|
501
|
-
case "insertion":
|
|
502
|
-
case "paragraph":
|
|
503
|
-
case "presentation":
|
|
504
|
-
case "strong":
|
|
505
|
-
case "subscript":
|
|
506
|
-
case "superscript": return name === "aria-label" || name === "aria-labelledby";
|
|
507
|
-
case "none": return flavor === 6 && (name === "aria-label" || name === "aria-labelledby");
|
|
508
|
-
case "generic": return name === "aria-label" || name === "aria-labelledby" || name === "aria-roledescription";
|
|
509
|
-
default: return false;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
function hasGlobalAriaAttributes(impl, role, flavor) {
|
|
513
|
-
if (impl.attrs === null) return false;
|
|
514
|
-
const list = flavor === 6 ? GLOBAL_ARIA_06 : GLOBAL_ARIA_05;
|
|
515
|
-
for (let i = 0; i < list.length; i++) {
|
|
516
|
-
const name = list[i];
|
|
517
|
-
if ((0, _ctrl_dom_internal.attr)(impl, name) !== null && !isProhibited(role, name, flavor)) return true;
|
|
518
|
-
}
|
|
519
|
-
return false;
|
|
520
|
-
}
|
|
521
|
-
/** dom-accessibility-api getExplicitRole: first " "-token of the trimmed role attribute, null when empty. */
|
|
522
|
-
function daaExplicitRole(impl) {
|
|
523
|
-
const role = (0, _ctrl_dom_internal.attr)(impl, "role");
|
|
524
|
-
if (role === null) return null;
|
|
525
|
-
const trimmed = role.trim();
|
|
526
|
-
const sp = trimmed.indexOf(" ");
|
|
527
|
-
const first = sp === -1 ? trimmed : trimmed.slice(0, sp);
|
|
528
|
-
return first.length > 0 ? first : null;
|
|
529
|
-
}
|
|
530
|
-
/** dom-accessibility-api getImplicitRole. */
|
|
531
|
-
function daaImplicitRole(impl, flavor) {
|
|
532
|
-
const tag = anyTag(impl);
|
|
533
|
-
const mapped = DAA_ROLE_BY_TAG[tag];
|
|
534
|
-
if (mapped !== void 0) return mapped;
|
|
535
|
-
switch (tag) {
|
|
536
|
-
case _ctrl_dom_internal.T.a:
|
|
537
|
-
case _ctrl_dom_internal.T.area:
|
|
538
|
-
case _ctrl_dom_internal.T.link: return (0, _ctrl_dom_internal.attr)(impl, "href") !== null ? "link" : null;
|
|
539
|
-
case _ctrl_dom_internal.T.img: return (0, _ctrl_dom_internal.attr)(impl, "alt") === "" && !hasGlobalAriaAttributes(impl, "img", flavor) ? "presentation" : "img";
|
|
540
|
-
case _ctrl_dom_internal.T.input: {
|
|
541
|
-
if (impl.ns !== _ctrl_dom_internal.HTML_NS) return null;
|
|
542
|
-
const type = inputType(impl);
|
|
543
|
-
switch (type) {
|
|
544
|
-
case "button":
|
|
545
|
-
case "image":
|
|
546
|
-
case "reset":
|
|
547
|
-
case "submit": return "button";
|
|
548
|
-
case "checkbox":
|
|
549
|
-
case "radio": return type;
|
|
550
|
-
case "range": return "slider";
|
|
551
|
-
case "email":
|
|
552
|
-
case "tel":
|
|
553
|
-
case "text":
|
|
554
|
-
case "url": return (0, _ctrl_dom_internal.attr)(impl, "list") !== null ? "combobox" : "textbox";
|
|
555
|
-
case "search": return (0, _ctrl_dom_internal.attr)(impl, "list") !== null ? "combobox" : "searchbox";
|
|
556
|
-
case "number": return "spinbutton";
|
|
557
|
-
default: return null;
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
case _ctrl_dom_internal.T.select:
|
|
561
|
-
if ((0, _ctrl_dom_internal.attr)(impl, "multiple") !== null || impl.ns === _ctrl_dom_internal.HTML_NS && selectSize(impl) > 1) return "listbox";
|
|
562
|
-
return "combobox";
|
|
563
|
-
}
|
|
564
|
-
return null;
|
|
565
|
-
}
|
|
566
|
-
function isPresentationRole(role, flavor) {
|
|
567
|
-
return role === "presentation" || flavor === 6 && role === "none";
|
|
568
|
-
}
|
|
569
|
-
/** dom-accessibility-api `getRole(element)`. */
|
|
570
|
-
function daaGetRole(impl, flavor) {
|
|
571
|
-
const explicitRole = daaExplicitRole(impl);
|
|
572
|
-
if (explicitRole === null || isPresentationRole(explicitRole, flavor)) {
|
|
573
|
-
const implicit = daaImplicitRole(impl, flavor);
|
|
574
|
-
if (!isPresentationRole(explicitRole, flavor) || hasGlobalAriaAttributes(impl, implicit ?? "", flavor)) return implicit;
|
|
575
|
-
}
|
|
576
|
-
return explicitRole;
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
// src/tree.ts
|
|
580
|
-
/** The NodeImpl behind a public wrapper. */
|
|
581
|
-
function implOf(node) {
|
|
582
|
-
const impl = node[_ctrl_dom_internal.$impl];
|
|
583
|
-
if (impl === void 0) throw new TypeError("Expected a node created by @ctrl/dom.");
|
|
584
|
-
return impl;
|
|
585
|
-
}
|
|
586
|
-
function nextInTreeWithin(n, root) {
|
|
587
|
-
if (n.first !== null) return n.first;
|
|
588
|
-
let cur = n;
|
|
589
|
-
while (cur !== null && cur !== root) {
|
|
590
|
-
if (cur.next !== null) return cur.next;
|
|
591
|
-
cur = cur.parent;
|
|
592
|
-
}
|
|
593
|
-
return null;
|
|
594
|
-
}
|
|
595
|
-
/**
|
|
596
|
-
* `root.getElementById(id)` for a Document or DocumentFragment/ShadowRoot root.
|
|
597
|
-
* https://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid
|
|
598
|
-
*/
|
|
599
|
-
function elementByIdInRoot(root, id) {
|
|
600
|
-
if (id === "") return null;
|
|
601
|
-
if (root.type === _ctrl_dom_internal.DOCUMENT_NODE) return root.node._idLookup(id);
|
|
602
|
-
for (let n = root.first; n !== null; n = nextInTreeWithin(n, root)) if (n.type === _ctrl_dom_internal.ELEMENT_NODE && n.id === id) return n;
|
|
603
|
-
return null;
|
|
604
|
-
}
|
|
605
|
-
/**
|
|
606
|
-
* dom-accessibility-api's `queryIdRefs(node, attributeName)`: split the attribute on " "
|
|
607
|
-
* and resolve each token with `node.getRootNode().getElementById(token)`.
|
|
608
|
-
* https://w3c.github.io/aria/#valuetype_idref_list
|
|
609
|
-
*
|
|
610
|
-
* Deviation: when the root is a detached element (which has no getElementById, so
|
|
611
|
-
* dom-accessibility-api throws a TypeError), this returns no elements.
|
|
612
|
-
*/
|
|
613
|
-
function queryIdRefs(impl, value, out) {
|
|
614
|
-
if (value === null) return out;
|
|
615
|
-
const root = (0, _ctrl_dom_internal.treeRoot)(impl);
|
|
616
|
-
if (root.type === _ctrl_dom_internal.ELEMENT_NODE) return out;
|
|
617
|
-
let start = 0;
|
|
618
|
-
const len = value.length;
|
|
619
|
-
while (start <= len) {
|
|
620
|
-
let end = value.indexOf(" ", start);
|
|
621
|
-
if (end === -1) end = len;
|
|
622
|
-
if (end > start) {
|
|
623
|
-
const el = elementByIdInRoot(root, value.slice(start, end));
|
|
624
|
-
if (el !== null) out.push(el);
|
|
625
|
-
}
|
|
626
|
-
start = end + 1;
|
|
627
|
-
}
|
|
628
|
-
return out;
|
|
629
|
-
}
|
|
630
|
-
/** https://dom.spec.whatwg.org/#dom-node-textcontent for an element (descendant text, tree order). */
|
|
631
|
-
function textContent(impl) {
|
|
632
|
-
let s = "";
|
|
633
|
-
for (let n = impl.first; n !== null; n = nextInTreeWithin(n, impl)) if (n.type === _ctrl_dom_internal.TEXT_NODE || n.type === _ctrl_dom_internal.CDATA_SECTION_NODE) s += n.data;
|
|
634
|
-
return s;
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
// src/style.ts
|
|
638
|
-
const K_NONE = 0;
|
|
639
|
-
const K_INLINE = 1;
|
|
640
|
-
const K_OTHER = 2;
|
|
641
|
-
/** jsdom default-stylesheet display classification (by local name, any namespace). */
|
|
642
|
-
function jsdomUaKind(impl) {
|
|
643
|
-
const tag = impl.tag !== 0 ? impl.tag : (0, _ctrl_dom_internal.tagId)(impl.name);
|
|
644
|
-
const hidden = (0, _ctrl_dom_internal.attr)(impl, "hidden");
|
|
645
|
-
if (hidden !== null && tag !== _ctrl_dom_internal.T.embed && hidden.toLowerCase() !== "until-found") return K_NONE;
|
|
646
|
-
if ((0, _ctrl_dom_internal.attr)(impl, "popover") !== null && !(tag === _ctrl_dom_internal.T.dialog && (0, _ctrl_dom_internal.attr)(impl, "open") !== null)) return K_NONE;
|
|
647
|
-
switch (tag) {
|
|
648
|
-
case 0: return K_INLINE;
|
|
649
|
-
case _ctrl_dom_internal.T.area:
|
|
650
|
-
case _ctrl_dom_internal.T.base:
|
|
651
|
-
case _ctrl_dom_internal.T.basefont:
|
|
652
|
-
case _ctrl_dom_internal.T.datalist:
|
|
653
|
-
case _ctrl_dom_internal.T.head:
|
|
654
|
-
case _ctrl_dom_internal.T.link:
|
|
655
|
-
case _ctrl_dom_internal.T.meta:
|
|
656
|
-
case _ctrl_dom_internal.T.noembed:
|
|
657
|
-
case _ctrl_dom_internal.T.noframes:
|
|
658
|
-
case _ctrl_dom_internal.T.param:
|
|
659
|
-
case _ctrl_dom_internal.T.rp:
|
|
660
|
-
case _ctrl_dom_internal.T.script:
|
|
661
|
-
case _ctrl_dom_internal.T.style:
|
|
662
|
-
case _ctrl_dom_internal.T.template:
|
|
663
|
-
case _ctrl_dom_internal.T.title: return K_NONE;
|
|
664
|
-
case _ctrl_dom_internal.T.dialog: return (0, _ctrl_dom_internal.attr)(impl, "open") === null ? K_NONE : K_OTHER;
|
|
665
|
-
case _ctrl_dom_internal.T.input: {
|
|
666
|
-
const type = (0, _ctrl_dom_internal.attr)(impl, "type");
|
|
667
|
-
return type !== null && type.toLowerCase() === "hidden" ? K_NONE : K_OTHER;
|
|
668
|
-
}
|
|
669
|
-
case _ctrl_dom_internal.T.html:
|
|
670
|
-
case _ctrl_dom_internal.T.body:
|
|
671
|
-
case _ctrl_dom_internal.T.address:
|
|
672
|
-
case _ctrl_dom_internal.T.blockquote:
|
|
673
|
-
case _ctrl_dom_internal.T.center:
|
|
674
|
-
case _ctrl_dom_internal.T.div:
|
|
675
|
-
case _ctrl_dom_internal.T.figure:
|
|
676
|
-
case _ctrl_dom_internal.T.figcaption:
|
|
677
|
-
case _ctrl_dom_internal.T.footer:
|
|
678
|
-
case _ctrl_dom_internal.T.form:
|
|
679
|
-
case _ctrl_dom_internal.T.header:
|
|
680
|
-
case _ctrl_dom_internal.T.hr:
|
|
681
|
-
case _ctrl_dom_internal.T.legend:
|
|
682
|
-
case _ctrl_dom_internal.T.listing:
|
|
683
|
-
case _ctrl_dom_internal.T.main:
|
|
684
|
-
case _ctrl_dom_internal.T.p:
|
|
685
|
-
case _ctrl_dom_internal.T.plaintext:
|
|
686
|
-
case _ctrl_dom_internal.T.pre:
|
|
687
|
-
case _ctrl_dom_internal.T.search:
|
|
688
|
-
case _ctrl_dom_internal.T.xmp:
|
|
689
|
-
case _ctrl_dom_internal.T.slot:
|
|
690
|
-
case _ctrl_dom_internal.T.article:
|
|
691
|
-
case _ctrl_dom_internal.T.aside:
|
|
692
|
-
case _ctrl_dom_internal.T.h1:
|
|
693
|
-
case _ctrl_dom_internal.T.h2:
|
|
694
|
-
case _ctrl_dom_internal.T.h3:
|
|
695
|
-
case _ctrl_dom_internal.T.h4:
|
|
696
|
-
case _ctrl_dom_internal.T.h5:
|
|
697
|
-
case _ctrl_dom_internal.T.h6:
|
|
698
|
-
case _ctrl_dom_internal.T.hgroup:
|
|
699
|
-
case _ctrl_dom_internal.T.nav:
|
|
700
|
-
case _ctrl_dom_internal.T.section:
|
|
701
|
-
case _ctrl_dom_internal.T.dir:
|
|
702
|
-
case _ctrl_dom_internal.T.dd:
|
|
703
|
-
case _ctrl_dom_internal.T.dl:
|
|
704
|
-
case _ctrl_dom_internal.T.dt:
|
|
705
|
-
case _ctrl_dom_internal.T.menu:
|
|
706
|
-
case _ctrl_dom_internal.T.ol:
|
|
707
|
-
case _ctrl_dom_internal.T.ul:
|
|
708
|
-
case _ctrl_dom_internal.T.li:
|
|
709
|
-
case _ctrl_dom_internal.T.ruby:
|
|
710
|
-
case _ctrl_dom_internal.T.rt:
|
|
711
|
-
case _ctrl_dom_internal.T.table:
|
|
712
|
-
case _ctrl_dom_internal.T.caption:
|
|
713
|
-
case _ctrl_dom_internal.T.colgroup:
|
|
714
|
-
case _ctrl_dom_internal.T.col:
|
|
715
|
-
case _ctrl_dom_internal.T.thead:
|
|
716
|
-
case _ctrl_dom_internal.T.tbody:
|
|
717
|
-
case _ctrl_dom_internal.T.tfoot:
|
|
718
|
-
case _ctrl_dom_internal.T.tr:
|
|
719
|
-
case _ctrl_dom_internal.T.td:
|
|
720
|
-
case _ctrl_dom_internal.T.th:
|
|
721
|
-
case _ctrl_dom_internal.T.button:
|
|
722
|
-
case _ctrl_dom_internal.T.fieldset:
|
|
723
|
-
case _ctrl_dom_internal.T.details:
|
|
724
|
-
case _ctrl_dom_internal.T.summary:
|
|
725
|
-
case _ctrl_dom_internal.T.marquee: return K_OTHER;
|
|
726
|
-
default: return K_INLINE;
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
/** Computed `display` is `none` (the element itself; `display` is not inherited). */
|
|
730
|
-
function isDisplayNone(impl) {
|
|
731
|
-
const d = (0, _ctrl_dom_internal.computedDisplay)(impl);
|
|
732
|
-
if (d !== (0, _ctrl_dom_internal.uaDisplay)(impl)) return d === "none";
|
|
733
|
-
return jsdomUaKind(impl) === K_NONE;
|
|
734
|
-
}
|
|
735
|
-
/** Computed `display` is exactly `inline` (accname: inline children are not space-separated). */
|
|
736
|
-
function isDisplayInline(impl) {
|
|
737
|
-
const d = (0, _ctrl_dom_internal.computedDisplay)(impl);
|
|
738
|
-
if (d !== (0, _ctrl_dom_internal.uaDisplay)(impl)) return d === "inline";
|
|
739
|
-
return jsdomUaKind(impl) === K_INLINE;
|
|
740
|
-
}
|
|
741
|
-
/**
|
|
742
|
-
* Computed `visibility` is exactly `hidden` (inherited). `collapse` does not count: Testing
|
|
743
|
-
* Library and dom-accessibility-api compare against "hidden" only.
|
|
744
|
-
*/
|
|
745
|
-
function isVisibilityHidden(impl) {
|
|
746
|
-
return (0, _ctrl_dom_internal.computedVisibility)(impl) === "hidden";
|
|
747
|
-
}
|
|
748
|
-
/**
|
|
749
|
-
* Textual `content` of `::before` / `::after` as dom-accessibility-api extracts it from
|
|
750
|
-
* `getComputedStyle(el, pseudo).getPropertyValue("content")`: a value that starts and ends
|
|
751
|
-
* with a quote, with the outer quotes sliced off; anything else is "".
|
|
752
|
-
*/
|
|
753
|
-
function pseudoText(impl, pseudo) {
|
|
754
|
-
if ((0, _ctrl_dom_internal.pseudoContent)(impl, pseudo) === "") return "";
|
|
755
|
-
const content = (0, _ctrl_dom_internal.computedValue)(impl, "content", pseudo);
|
|
756
|
-
if (/^["'].*["']$/.test(content)) return content.slice(1, -1);
|
|
757
|
-
return "";
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
// src/accname.ts
|
|
761
|
-
const COMPUTE_NAME = 0;
|
|
762
|
-
const COMPUTE_DESCRIPTION = 1;
|
|
763
|
-
/** Per-computation state (one per top-level call). */
|
|
764
|
-
var Ctx = class {
|
|
765
|
-
consulted;
|
|
766
|
-
compute;
|
|
767
|
-
hidden;
|
|
768
|
-
pseudo;
|
|
769
|
-
gcs;
|
|
770
|
-
flavor;
|
|
771
|
-
/** Set when a dynamic form-control state (value, selectedness) was read: the result must not be cached. */
|
|
772
|
-
usedState;
|
|
773
|
-
constructor(compute, options, flavor) {
|
|
774
|
-
this.consulted = /* @__PURE__ */ new Set();
|
|
775
|
-
this.compute = compute;
|
|
776
|
-
const gcs = options?.getComputedStyle;
|
|
777
|
-
this.gcs = typeof gcs === "function" ? gcs : null;
|
|
778
|
-
this.pseudo = options?.computedStyleSupportsPseudoElements ?? this.gcs !== null;
|
|
779
|
-
this.hidden = options?.hidden ?? false;
|
|
780
|
-
this.flavor = flavor;
|
|
781
|
-
this.usedState = false;
|
|
782
|
-
}
|
|
783
|
-
};
|
|
784
|
-
function roleOf(ctx, n) {
|
|
785
|
-
return n.type === _ctrl_dom_internal.ELEMENT_NODE ? daaGetRole(n, ctx.flavor) : null;
|
|
786
|
-
}
|
|
787
|
-
/** 2E: https://w3c.github.io/accname/#step2E — button, combobox, listbox, textbox, range. */
|
|
788
|
-
function isControl(role) {
|
|
789
|
-
switch (role) {
|
|
790
|
-
case "button":
|
|
791
|
-
case "combobox":
|
|
792
|
-
case "listbox":
|
|
793
|
-
case "textbox": return true;
|
|
794
|
-
default: return isRange(role);
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
function isRange(role) {
|
|
798
|
-
switch (role) {
|
|
799
|
-
case "meter":
|
|
800
|
-
case "progressbar":
|
|
801
|
-
case "scrollbar":
|
|
802
|
-
case "slider":
|
|
803
|
-
case "spinbutton": return true;
|
|
804
|
-
default: return false;
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
/** https://w3c.github.io/aria/#namefromcontent (dom-accessibility-api's list). */
|
|
808
|
-
function allowsNameFromContent(role) {
|
|
809
|
-
switch (role) {
|
|
810
|
-
case "button":
|
|
811
|
-
case "cell":
|
|
812
|
-
case "checkbox":
|
|
813
|
-
case "columnheader":
|
|
814
|
-
case "gridcell":
|
|
815
|
-
case "heading":
|
|
816
|
-
case "label":
|
|
817
|
-
case "legend":
|
|
818
|
-
case "link":
|
|
819
|
-
case "menuitem":
|
|
820
|
-
case "menuitemcheckbox":
|
|
821
|
-
case "menuitemradio":
|
|
822
|
-
case "option":
|
|
823
|
-
case "radio":
|
|
824
|
-
case "row":
|
|
825
|
-
case "rowheader":
|
|
826
|
-
case "switch":
|
|
827
|
-
case "tab":
|
|
828
|
-
case "tooltip":
|
|
829
|
-
case "treeitem": return true;
|
|
830
|
-
default: return false;
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
function wrapperOf(n) {
|
|
834
|
-
return n.node;
|
|
835
|
-
}
|
|
836
|
-
/** dom-accessibility-api isHidden (2A). */
|
|
837
|
-
function isHidden(ctx, n) {
|
|
838
|
-
if (n.type !== _ctrl_dom_internal.ELEMENT_NODE) return false;
|
|
839
|
-
if ((0, _ctrl_dom_internal.attr)(n, "hidden") !== null || (0, _ctrl_dom_internal.attr)(n, "aria-hidden") === "true") return true;
|
|
840
|
-
const gcs = ctx.gcs;
|
|
841
|
-
if (gcs !== null) {
|
|
842
|
-
const style = gcs(wrapperOf(n));
|
|
843
|
-
return style.getPropertyValue("display") === "none" || style.getPropertyValue("visibility") === "hidden";
|
|
844
|
-
}
|
|
845
|
-
return isDisplayNone(n) || isVisibilityHidden(n);
|
|
846
|
-
}
|
|
847
|
-
function displayIsInline(ctx, n) {
|
|
848
|
-
const gcs = ctx.gcs;
|
|
849
|
-
if (gcs !== null) return gcs(wrapperOf(n)).getPropertyValue("display") === "inline";
|
|
850
|
-
return isDisplayInline(n);
|
|
851
|
-
}
|
|
852
|
-
/** getTextualContent(getComputedStyle(node, pseudo)) */
|
|
853
|
-
function pseudoContent(ctx, n, pseudo) {
|
|
854
|
-
const gcs = ctx.gcs;
|
|
855
|
-
if (gcs !== null) {
|
|
856
|
-
const content = gcs(wrapperOf(n), pseudo).getPropertyValue("content");
|
|
857
|
-
if (/^["'].*["']$/.test(content)) return content.slice(1, -1);
|
|
858
|
-
return "";
|
|
859
|
-
}
|
|
860
|
-
return pseudoText(n, pseudo);
|
|
861
|
-
}
|
|
862
|
-
function isLocal(n, tag) {
|
|
863
|
-
return n.type === _ctrl_dom_internal.ELEMENT_NODE && anyTag(n) === tag;
|
|
864
|
-
}
|
|
865
|
-
/** `input.type` for HTML inputs; "" for other elements (their `type` is undefined). */
|
|
866
|
-
function htmlInputType(n) {
|
|
867
|
-
return n.ns === _ctrl_dom_internal.HTML_NS && n.tag === _ctrl_dom_internal.T.input ? inputType(n) : "";
|
|
868
|
-
}
|
|
869
|
-
function findAttr(n, name) {
|
|
870
|
-
const attrs = n.attrs;
|
|
871
|
-
if (attrs === null) return null;
|
|
872
|
-
for (let i = 0; i < attrs.length; i++) {
|
|
873
|
-
const a = attrs[i];
|
|
874
|
-
if ((a.rare === null ? a.localName : a.rare.name) === name) return a;
|
|
875
|
-
}
|
|
876
|
-
return null;
|
|
877
|
-
}
|
|
878
|
-
/** useAttribute: a non-blank attribute that has not been consulted yet. */
|
|
879
|
-
function useAttribute(ctx, n, name) {
|
|
880
|
-
const a = findAttr(n, name);
|
|
881
|
-
if (a !== null && !ctx.consulted.has(a) && a.value.trim() !== "") {
|
|
882
|
-
ctx.consulted.add(a);
|
|
883
|
-
return a.value;
|
|
884
|
-
}
|
|
885
|
-
return null;
|
|
886
|
-
}
|
|
887
|
-
/** 2F.i: name from content (plus aria-owns, slots and CSS generated content). */
|
|
888
|
-
function computeMiscTextAlternative(ctx, node, isEmbeddedInLabel) {
|
|
889
|
-
let accumulatedText = "";
|
|
890
|
-
const isEl = node.type === _ctrl_dom_internal.ELEMENT_NODE;
|
|
891
|
-
if (isEl && ctx.pseudo) accumulatedText = `${pseudoContent(ctx, node, "::before")} ${accumulatedText}`;
|
|
892
|
-
if (isEl && anyTag(node) === _ctrl_dom_internal.T.slot) {
|
|
893
|
-
const assigned = slotAssignedNodes(node);
|
|
894
|
-
if (assigned !== null && assigned.length > 0) for (let i = 0; i < assigned.length; i++) accumulatedText += childText(ctx, assigned[i], isEmbeddedInLabel);
|
|
895
|
-
else for (let c = node.first; c !== null; c = c.next) accumulatedText += childText(ctx, c, isEmbeddedInLabel);
|
|
896
|
-
} else {
|
|
897
|
-
for (let c = node.first; c !== null; c = c.next) accumulatedText += childText(ctx, c, isEmbeddedInLabel);
|
|
898
|
-
if (isEl) {
|
|
899
|
-
const owns = (0, _ctrl_dom_internal.attr)(node, "aria-owns");
|
|
900
|
-
if (owns !== null) {
|
|
901
|
-
const owned = queryIdRefs(node, owns, []);
|
|
902
|
-
for (let i = 0; i < owned.length; i++) accumulatedText += childText(ctx, owned[i], isEmbeddedInLabel);
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
|
-
if (isEl && ctx.pseudo) accumulatedText = `${accumulatedText} ${pseudoContent(ctx, node, "::after")}`;
|
|
907
|
-
return accumulatedText.trim();
|
|
908
|
-
}
|
|
909
|
-
function childText(ctx, child, isEmbeddedInLabel) {
|
|
910
|
-
const result = computeTextAlternative(ctx, child, isEmbeddedInLabel, false, true);
|
|
911
|
-
if (child.type === _ctrl_dom_internal.ELEMENT_NODE && !displayIsInline(ctx, child)) return ` ${result} `;
|
|
912
|
-
return result;
|
|
913
|
-
}
|
|
914
|
-
function slotAssignedNodes(slot) {
|
|
915
|
-
const fn = slot.node.assignedNodes;
|
|
916
|
-
if (typeof fn !== "function") return null;
|
|
917
|
-
const nodes = fn.call(slot.node);
|
|
918
|
-
const out = [];
|
|
919
|
-
for (let i = 0; i < nodes.length; i++) out.push(nodes[i][_ctrl_dom_internal.$impl]);
|
|
920
|
-
return out;
|
|
921
|
-
}
|
|
922
|
-
function computeTooltipAttributeValue(ctx, n) {
|
|
923
|
-
if (n.type !== _ctrl_dom_internal.ELEMENT_NODE) return null;
|
|
924
|
-
return useAttribute(ctx, n, "title");
|
|
925
|
-
}
|
|
926
|
-
/** 2D: native host-language text alternatives (html-aam, svg-aam). */
|
|
927
|
-
function computeElementTextAlternative(ctx, node) {
|
|
928
|
-
if (node.type !== _ctrl_dom_internal.ELEMENT_NODE) return null;
|
|
929
|
-
const tag = anyTag(node);
|
|
930
|
-
if (tag === _ctrl_dom_internal.T.fieldset) {
|
|
931
|
-
ctx.consulted.add(node);
|
|
932
|
-
for (let c = node.first; c !== null; c = c.next) if (isLocal(c, _ctrl_dom_internal.T.legend)) return computeTextAlternative(ctx, c, false, false, false);
|
|
933
|
-
} else if (tag === _ctrl_dom_internal.T.table) {
|
|
934
|
-
ctx.consulted.add(node);
|
|
935
|
-
for (let c = node.first; c !== null; c = c.next) if (isLocal(c, _ctrl_dom_internal.T.caption)) return computeTextAlternative(ctx, c, false, false, false);
|
|
936
|
-
} else if (tag === _ctrl_dom_internal.T.svg) {
|
|
937
|
-
ctx.consulted.add(node);
|
|
938
|
-
for (let c = node.first; c !== null; c = c.next) if (c.type === _ctrl_dom_internal.ELEMENT_NODE && c.ns === _ctrl_dom_internal.SVG_NS && c.name === "title") return textContent(c);
|
|
939
|
-
return null;
|
|
940
|
-
} else if (tag === _ctrl_dom_internal.T.img || tag === _ctrl_dom_internal.T.area) {
|
|
941
|
-
const nameFromAlt = useAttribute(ctx, node, "alt");
|
|
942
|
-
if (nameFromAlt !== null) return nameFromAlt;
|
|
943
|
-
} else if (tag === _ctrl_dom_internal.T.optgroup) {
|
|
944
|
-
const nameFromLabel = useAttribute(ctx, node, "label");
|
|
945
|
-
if (nameFromLabel !== null) return nameFromLabel;
|
|
946
|
-
}
|
|
947
|
-
const type = tag === _ctrl_dom_internal.T.input ? htmlInputType(node) : "";
|
|
948
|
-
if (type === "button" || type === "submit" || type === "reset") {
|
|
949
|
-
const nameFromValue = useAttribute(ctx, node, "value");
|
|
950
|
-
if (nameFromValue !== null) return nameFromValue;
|
|
951
|
-
if (type === "submit") return "Submit";
|
|
952
|
-
if (type === "reset") return "Reset";
|
|
953
|
-
}
|
|
954
|
-
const labels = labelsOf(node);
|
|
955
|
-
if (labels !== null && labels.length !== 0) {
|
|
956
|
-
ctx.consulted.add(node);
|
|
957
|
-
let out = "";
|
|
958
|
-
for (let i = 0; i < labels.length; i++) {
|
|
959
|
-
const label = computeTextAlternative(ctx, labels[i], true, false, true);
|
|
960
|
-
if (label.length > 0) out = out === "" ? label : `${out} ${label}`;
|
|
961
|
-
}
|
|
962
|
-
return out;
|
|
963
|
-
}
|
|
964
|
-
if (type === "image") {
|
|
965
|
-
const nameFromAlt = useAttribute(ctx, node, "alt");
|
|
966
|
-
if (nameFromAlt !== null) return nameFromAlt;
|
|
967
|
-
const nameFromTitle = useAttribute(ctx, node, "title");
|
|
968
|
-
if (nameFromTitle !== null) return nameFromTitle;
|
|
969
|
-
return "Submit Query";
|
|
970
|
-
}
|
|
971
|
-
if (roleOf(ctx, node) === "button") {
|
|
972
|
-
const nameFromSubTree = computeMiscTextAlternative(ctx, node, false);
|
|
973
|
-
if (nameFromSubTree !== "") return nameFromSubTree;
|
|
974
|
-
}
|
|
975
|
-
return null;
|
|
976
|
-
}
|
|
977
|
-
/** querySelectedOptions(listbox) */
|
|
978
|
-
function selectedOptionsOf(ctx, listbox) {
|
|
979
|
-
if (anyTag(listbox) === _ctrl_dom_internal.T.select) {
|
|
980
|
-
ctx.usedState = true;
|
|
981
|
-
if (listbox.ns === _ctrl_dom_internal.HTML_NS) return selectedOptions(listbox);
|
|
982
|
-
return querySelectorAllSubtree(listbox, "selected", null);
|
|
983
|
-
}
|
|
984
|
-
return querySelectorAllSubtree(listbox, "aria-selected", "true");
|
|
985
|
-
}
|
|
986
|
-
/** `element.querySelectorAll("[name]")` / `[name="value"]` over the element and its aria-owns roots' descendants. */
|
|
987
|
-
function querySelectorAllSubtree(el, name, value) {
|
|
988
|
-
const out = [];
|
|
989
|
-
collectDescendantsWithAttr(el, name, value, out);
|
|
990
|
-
const owns = (0, _ctrl_dom_internal.attr)(el, "aria-owns");
|
|
991
|
-
if (owns !== null) {
|
|
992
|
-
const roots = queryIdRefs(el, owns, []);
|
|
993
|
-
for (let i = 0; i < roots.length; i++) collectDescendantsWithAttr(roots[i], name, value, out);
|
|
994
|
-
}
|
|
995
|
-
return out;
|
|
996
|
-
}
|
|
997
|
-
function collectDescendantsWithAttr(root, name, value, out) {
|
|
998
|
-
for (let n = root.first; n !== null;) {
|
|
999
|
-
if (n.type === _ctrl_dom_internal.ELEMENT_NODE) {
|
|
1000
|
-
const v = (0, _ctrl_dom_internal.attr)(n, name);
|
|
1001
|
-
if (v !== null && (value === null || v === value)) out.push(n);
|
|
1002
|
-
}
|
|
1003
|
-
if (n.first !== null) n = n.first;
|
|
1004
|
-
else {
|
|
1005
|
-
let cur = n;
|
|
1006
|
-
n = null;
|
|
1007
|
-
while (cur !== null && cur !== root) {
|
|
1008
|
-
if (cur.next !== null) {
|
|
1009
|
-
n = cur.next;
|
|
1010
|
-
break;
|
|
1011
|
-
}
|
|
1012
|
-
cur = cur.parent;
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
function getValueOfTextbox(ctx, el) {
|
|
1018
|
-
const tag = anyTag(el);
|
|
1019
|
-
if ((tag === _ctrl_dom_internal.T.input || tag === _ctrl_dom_internal.T.textarea) && el.ns === _ctrl_dom_internal.HTML_NS) {
|
|
1020
|
-
ctx.usedState = true;
|
|
1021
|
-
return controlValue(el);
|
|
1022
|
-
}
|
|
1023
|
-
return textContent(el);
|
|
1024
|
-
}
|
|
1025
|
-
function computeTextAlternative(ctx, current, isEmbeddedInLabel, isReferenced, recursion) {
|
|
1026
|
-
const consulted = ctx.consulted;
|
|
1027
|
-
if (consulted.has(current)) return "";
|
|
1028
|
-
if (!ctx.hidden && !isReferenced && isHidden(ctx, current)) {
|
|
1029
|
-
consulted.add(current);
|
|
1030
|
-
return "";
|
|
1031
|
-
}
|
|
1032
|
-
const isEl = current.type === _ctrl_dom_internal.ELEMENT_NODE;
|
|
1033
|
-
if (isEl && ctx.compute === COMPUTE_NAME && !isReferenced) {
|
|
1034
|
-
const labelAttr = findAttr(current, "aria-labelledby");
|
|
1035
|
-
if (labelAttr !== null && !consulted.has(labelAttr)) {
|
|
1036
|
-
const labelElements = queryIdRefs(current, labelAttr.value, []);
|
|
1037
|
-
if (labelElements.length > 0) {
|
|
1038
|
-
consulted.add(labelAttr);
|
|
1039
|
-
let out = "";
|
|
1040
|
-
for (let i = 0; i < labelElements.length; i++) {
|
|
1041
|
-
const part = computeTextAlternative(ctx, labelElements[i], isEmbeddedInLabel, true, false);
|
|
1042
|
-
out = i === 0 ? part : `${out} ${part}`;
|
|
1043
|
-
}
|
|
1044
|
-
return out;
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
}
|
|
1048
|
-
const role = isEl ? daaGetRole(current, ctx.flavor) : null;
|
|
1049
|
-
const skipToStep2E = recursion && ctx.compute === COMPUTE_NAME && isControl(role);
|
|
1050
|
-
if (!skipToStep2E) {
|
|
1051
|
-
const ariaLabel = isEl ? ((0, _ctrl_dom_internal.attr)(current, "aria-label") ?? "").trim() : "";
|
|
1052
|
-
if (ariaLabel !== "" && ctx.compute === COMPUTE_NAME) {
|
|
1053
|
-
consulted.add(current);
|
|
1054
|
-
return ariaLabel;
|
|
1055
|
-
}
|
|
1056
|
-
if (role !== "presentation" && role !== "none") {
|
|
1057
|
-
const elementTextAlternative = computeElementTextAlternative(ctx, current);
|
|
1058
|
-
if (elementTextAlternative !== null) {
|
|
1059
|
-
consulted.add(current);
|
|
1060
|
-
return elementTextAlternative;
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
if (role === "menu") {
|
|
1065
|
-
consulted.add(current);
|
|
1066
|
-
return "";
|
|
1067
|
-
}
|
|
1068
|
-
if (skipToStep2E || isEmbeddedInLabel || isReferenced) {
|
|
1069
|
-
if (role === "combobox" || role === "listbox") {
|
|
1070
|
-
consulted.add(current);
|
|
1071
|
-
const selected = selectedOptionsOf(ctx, current);
|
|
1072
|
-
if (selected.length === 0) {
|
|
1073
|
-
if (isLocal(current, _ctrl_dom_internal.T.input)) {
|
|
1074
|
-
ctx.usedState = true;
|
|
1075
|
-
return current.ns === _ctrl_dom_internal.HTML_NS ? controlValue(current) : "";
|
|
1076
|
-
}
|
|
1077
|
-
return "";
|
|
1078
|
-
}
|
|
1079
|
-
let out = "";
|
|
1080
|
-
for (let i = 0; i < selected.length; i++) {
|
|
1081
|
-
const part = computeTextAlternative(ctx, selected[i], isEmbeddedInLabel, false, true);
|
|
1082
|
-
out = i === 0 ? part : `${out} ${part}`;
|
|
1083
|
-
}
|
|
1084
|
-
return out;
|
|
1085
|
-
}
|
|
1086
|
-
if (isRange(role)) {
|
|
1087
|
-
consulted.add(current);
|
|
1088
|
-
const valueText = (0, _ctrl_dom_internal.attr)(current, "aria-valuetext");
|
|
1089
|
-
if (valueText !== null) return valueText;
|
|
1090
|
-
const valueNow = (0, _ctrl_dom_internal.attr)(current, "aria-valuenow");
|
|
1091
|
-
if (valueNow !== null) return valueNow;
|
|
1092
|
-
return (0, _ctrl_dom_internal.attr)(current, "value") || "";
|
|
1093
|
-
}
|
|
1094
|
-
if (role === "textbox") {
|
|
1095
|
-
consulted.add(current);
|
|
1096
|
-
return getValueOfTextbox(ctx, current);
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
if (allowsNameFromContent(role) || isEl && isReferenced || isEl && anyTag(current) === _ctrl_dom_internal.T.caption) {
|
|
1100
|
-
const accumulatedText2F = computeMiscTextAlternative(ctx, current, isEmbeddedInLabel);
|
|
1101
|
-
if (accumulatedText2F !== "") {
|
|
1102
|
-
consulted.add(current);
|
|
1103
|
-
return accumulatedText2F;
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
if (current.type === _ctrl_dom_internal.TEXT_NODE) {
|
|
1107
|
-
consulted.add(current);
|
|
1108
|
-
return current.data;
|
|
1109
|
-
}
|
|
1110
|
-
if (recursion) {
|
|
1111
|
-
consulted.add(current);
|
|
1112
|
-
return computeMiscTextAlternative(ctx, current, isEmbeddedInLabel);
|
|
1113
|
-
}
|
|
1114
|
-
const tooltipAttributeValue = computeTooltipAttributeValue(ctx, current);
|
|
1115
|
-
if (tooltipAttributeValue !== null) {
|
|
1116
|
-
consulted.add(current);
|
|
1117
|
-
return tooltipAttributeValue;
|
|
1118
|
-
}
|
|
1119
|
-
consulted.add(current);
|
|
1120
|
-
return "";
|
|
1121
|
-
}
|
|
1122
|
-
/** asFlatString: trim and collapse runs of 2+ whitespace characters to one space. */
|
|
1123
|
-
function asFlatString(s) {
|
|
1124
|
-
return s.trim().replace(/\s\s+/g, " ");
|
|
1125
|
-
}
|
|
1126
|
-
/** https://w3c.github.io/accname/#mapping_additional_nd_te */
|
|
1127
|
-
function computeTextAlternativeImpl(root, options, flavor) {
|
|
1128
|
-
const ctx = new Ctx(options?.compute === "description" ? COMPUTE_DESCRIPTION : COMPUTE_NAME, options, flavor);
|
|
1129
|
-
return asFlatString(computeTextAlternative(ctx, root, false, ctx.compute === COMPUTE_DESCRIPTION, false));
|
|
1130
|
-
}
|
|
1131
|
-
/** https://w3c.github.io/aria/#namefromprohibited */
|
|
1132
|
-
function prohibitsNaming(role, flavor) {
|
|
1133
|
-
switch (role) {
|
|
1134
|
-
case "caption":
|
|
1135
|
-
case "code":
|
|
1136
|
-
case "deletion":
|
|
1137
|
-
case "emphasis":
|
|
1138
|
-
case "generic":
|
|
1139
|
-
case "insertion":
|
|
1140
|
-
case "paragraph":
|
|
1141
|
-
case "presentation":
|
|
1142
|
-
case "strong":
|
|
1143
|
-
case "subscript":
|
|
1144
|
-
case "superscript": return true;
|
|
1145
|
-
case "none": return flavor === 6;
|
|
1146
|
-
default: return false;
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
/**
|
|
1150
|
-
* dom-accessibility-api defaults `getComputedStyle` to `window.getComputedStyle.bind(window)`,
|
|
1151
|
-
* so a user-replaced one (`getComputedStyleOverride`) is what it reads when the caller passes
|
|
1152
|
-
* none. Returns `options` unchanged (no allocation) unless a replacement is installed; then
|
|
1153
|
-
* the replacement is passed explicitly, keeping upstream's `computedStyleSupportsPseudoElements`
|
|
1154
|
-
* default (`false` when the caller did not pass `getComputedStyle`).
|
|
1155
|
-
*/
|
|
1156
|
-
function withStyleOverride(root, options) {
|
|
1157
|
-
if (options !== void 0 && options.getComputedStyle !== void 0) return options;
|
|
1158
|
-
const gcs = (0, _ctrl_dom_internal.getComputedStyleOverride)(root);
|
|
1159
|
-
if (gcs === null) return options;
|
|
1160
|
-
return {
|
|
1161
|
-
...options,
|
|
1162
|
-
getComputedStyle: gcs,
|
|
1163
|
-
computedStyleSupportsPseudoElements: options?.computedStyleSupportsPseudoElements ?? false
|
|
1164
|
-
};
|
|
1165
|
-
}
|
|
1166
|
-
function isDefaultOptions(options) {
|
|
1167
|
-
if (options === void 0) return true;
|
|
1168
|
-
return options.getComputedStyle === void 0 && options.computedStyleSupportsPseudoElements !== true && options.hidden !== true && options.compute !== "description";
|
|
1169
|
-
}
|
|
1170
|
-
/**
|
|
1171
|
-
* https://w3c.github.io/accname/#mapping_additional_nd_name
|
|
1172
|
-
*
|
|
1173
|
-
* With default options (what Testing Library's `name` filter and jest-dom pass) the result
|
|
1174
|
-
* is cached on the element, stamped with `Document._version` and `_styleVersion`, unless
|
|
1175
|
-
* the computation read dynamic form-control state (values, selectedness), which changes
|
|
1176
|
-
* without bumping the document version.
|
|
1177
|
-
*/
|
|
1178
|
-
function computeAccessibleNameImpl(root, options, flavor) {
|
|
1179
|
-
if (root.type === _ctrl_dom_internal.ELEMENT_NODE && prohibitsNaming(daaGetRole(root, flavor), flavor)) return "";
|
|
1180
|
-
const cacheable = flavor === 5 && root.type === _ctrl_dom_internal.ELEMENT_NODE && isDefaultOptions(options);
|
|
1181
|
-
const doc = root.doc;
|
|
1182
|
-
if (cacheable) {
|
|
1183
|
-
const c = root.cache;
|
|
1184
|
-
if (c !== null && c.nameVersion === doc[_ctrl_dom_internal.$version] && c.ariaNameStyleVersion === doc[_ctrl_dom_internal.$styleVersion]) return c.name;
|
|
1185
|
-
}
|
|
1186
|
-
const ctx = new Ctx(COMPUTE_NAME, options, flavor);
|
|
1187
|
-
const name = asFlatString(computeTextAlternative(ctx, root, false, false, false));
|
|
1188
|
-
if (cacheable && !ctx.usedState) {
|
|
1189
|
-
const c = (0, _ctrl_dom_internal.nodeCache)(root);
|
|
1190
|
-
c.nameVersion = doc[_ctrl_dom_internal.$version];
|
|
1191
|
-
c.ariaNameStyleVersion = doc[_ctrl_dom_internal.$styleVersion];
|
|
1192
|
-
c.name = name;
|
|
1193
|
-
}
|
|
1194
|
-
return name;
|
|
1195
|
-
}
|
|
1196
|
-
/** https://w3c.github.io/accname/#mapping_additional_nd_description */
|
|
1197
|
-
function computeAccessibleDescriptionImpl(root, options, flavor) {
|
|
1198
|
-
let description = "";
|
|
1199
|
-
if (root.type === _ctrl_dom_internal.ELEMENT_NODE) {
|
|
1200
|
-
const describedBy = (0, _ctrl_dom_internal.attr)(root, "aria-describedby");
|
|
1201
|
-
if (describedBy !== null) {
|
|
1202
|
-
const refs = queryIdRefs(root, describedBy, []);
|
|
1203
|
-
const opts = {
|
|
1204
|
-
...options,
|
|
1205
|
-
compute: "description"
|
|
1206
|
-
};
|
|
1207
|
-
for (let i = 0; i < refs.length; i++) {
|
|
1208
|
-
const part = computeTextAlternativeImpl(refs[i], opts, flavor);
|
|
1209
|
-
description = i === 0 ? part : `${description} ${part}`;
|
|
1210
|
-
}
|
|
1211
|
-
}
|
|
1212
|
-
if (description === "" && flavor === 6) description = (0, _ctrl_dom_internal.attr)(root, "aria-description") ?? "";
|
|
1213
|
-
if (description === "") description = (0, _ctrl_dom_internal.attr)(root, "title") ?? "";
|
|
1214
|
-
}
|
|
1215
|
-
return description;
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
// src/states.ts
|
|
1219
|
-
function checkBooleanAttribute(impl, name) {
|
|
1220
|
-
const v = (0, _ctrl_dom_internal.attr)(impl, name);
|
|
1221
|
-
if (v === "true") return true;
|
|
1222
|
-
if (v === "false") return false;
|
|
1223
|
-
}
|
|
1224
|
-
function isHTMLTag(impl, tag) {
|
|
1225
|
-
return impl.tag === tag && impl.ns === _ctrl_dom_internal.HTML_NS;
|
|
1226
|
-
}
|
|
1227
|
-
/** false/true if (not)selected, undefined if not selectable. `<option>` uses its selectedness. */
|
|
1228
|
-
function computeAriaSelected(impl) {
|
|
1229
|
-
if (isHTMLTag(impl, _ctrl_dom_internal.T.option)) return optionSelected(impl);
|
|
1230
|
-
return checkBooleanAttribute(impl, "aria-selected");
|
|
1231
|
-
}
|
|
1232
|
-
function computeAriaBusy(impl) {
|
|
1233
|
-
return (0, _ctrl_dom_internal.attr)(impl, "aria-busy") === "true";
|
|
1234
|
-
}
|
|
1235
|
-
/**
|
|
1236
|
-
* false/true if (not)checked, undefined if not checkable. HTML `<input>` elements of every
|
|
1237
|
-
* type use their checkedness (undefined while indeterminate); others read `aria-checked`
|
|
1238
|
-
* (`"mixed"` → undefined, as in Testing Library).
|
|
1239
|
-
*/
|
|
1240
|
-
function computeAriaChecked(impl) {
|
|
1241
|
-
if (isHTMLTag(impl, _ctrl_dom_internal.T.input)) {
|
|
1242
|
-
if (indeterminate(impl)) return void 0;
|
|
1243
|
-
return checkedness(impl);
|
|
1244
|
-
}
|
|
1245
|
-
return checkBooleanAttribute(impl, "aria-checked");
|
|
1246
|
-
}
|
|
1247
|
-
/** Tri-state checked: true / false / "mixed" / undefined (not checkable). */
|
|
1248
|
-
function ariaCheckedState(impl) {
|
|
1249
|
-
if (isHTMLTag(impl, _ctrl_dom_internal.T.input)) {
|
|
1250
|
-
if (indeterminate(impl)) return "mixed";
|
|
1251
|
-
return checkedness(impl);
|
|
1252
|
-
}
|
|
1253
|
-
const v = (0, _ctrl_dom_internal.attr)(impl, "aria-checked");
|
|
1254
|
-
if (v === "true") return true;
|
|
1255
|
-
if (v === "false") return false;
|
|
1256
|
-
if (v === "mixed") return "mixed";
|
|
1257
|
-
}
|
|
1258
|
-
function computeAriaPressed(impl) {
|
|
1259
|
-
return checkBooleanAttribute(impl, "aria-pressed");
|
|
1260
|
-
}
|
|
1261
|
-
/** Tri-state pressed: true / false / "mixed" / undefined. */
|
|
1262
|
-
function ariaPressedState(impl) {
|
|
1263
|
-
const v = (0, _ctrl_dom_internal.attr)(impl, "aria-pressed");
|
|
1264
|
-
if (v === "true") return true;
|
|
1265
|
-
if (v === "false") return false;
|
|
1266
|
-
if (v === "mixed") return "mixed";
|
|
1267
|
-
}
|
|
1268
|
-
function computeAriaCurrent(impl) {
|
|
1269
|
-
return checkBooleanAttribute(impl, "aria-current") ?? (0, _ctrl_dom_internal.attr)(impl, "aria-current") ?? false;
|
|
1270
|
-
}
|
|
1271
|
-
function computeAriaExpanded(impl) {
|
|
1272
|
-
return checkBooleanAttribute(impl, "aria-expanded");
|
|
1273
|
-
}
|
|
1274
|
-
/** Explicit `aria-level` (if truthy as a Number) or the h1–h6 level; undefined otherwise. */
|
|
1275
|
-
function computeHeadingLevel(impl) {
|
|
1276
|
-
const ariaLevel = (0, _ctrl_dom_internal.attr)(impl, "aria-level");
|
|
1277
|
-
if (ariaLevel !== null && ariaLevel !== "") {
|
|
1278
|
-
const n = Number(ariaLevel);
|
|
1279
|
-
if (n) return n;
|
|
1280
|
-
}
|
|
1281
|
-
if (impl.ns !== _ctrl_dom_internal.HTML_NS) return void 0;
|
|
1282
|
-
switch (impl.tag) {
|
|
1283
|
-
case _ctrl_dom_internal.T.h1: return 1;
|
|
1284
|
-
case _ctrl_dom_internal.T.h2: return 2;
|
|
1285
|
-
case _ctrl_dom_internal.T.h3: return 3;
|
|
1286
|
-
case _ctrl_dom_internal.T.h4: return 4;
|
|
1287
|
-
case _ctrl_dom_internal.T.h5: return 5;
|
|
1288
|
-
case _ctrl_dom_internal.T.h6: return 6;
|
|
1289
|
-
default: return;
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
function computeAriaValueNow(impl) {
|
|
1293
|
-
const v = (0, _ctrl_dom_internal.attr)(impl, "aria-valuenow");
|
|
1294
|
-
return v === null ? void 0 : +v;
|
|
1295
|
-
}
|
|
1296
|
-
function computeAriaValueMax(impl) {
|
|
1297
|
-
const v = (0, _ctrl_dom_internal.attr)(impl, "aria-valuemax");
|
|
1298
|
-
return v === null ? void 0 : +v;
|
|
1299
|
-
}
|
|
1300
|
-
function computeAriaValueMin(impl) {
|
|
1301
|
-
const v = (0, _ctrl_dom_internal.attr)(impl, "aria-valuemin");
|
|
1302
|
-
return v === null ? void 0 : +v;
|
|
1303
|
-
}
|
|
1304
|
-
function computeAriaValueText(impl) {
|
|
1305
|
-
return (0, _ctrl_dom_internal.attr)(impl, "aria-valuetext") ?? void 0;
|
|
1306
|
-
}
|
|
1307
|
-
/**
|
|
1308
|
-
* dom-accessibility-api@0.6 `isDisabled`: `disabled` on button, fieldset, input, optgroup,
|
|
1309
|
-
* option, select, textarea (by local name), else `aria-disabled="true"`.
|
|
1310
|
-
* https://www.w3.org/TR/html-aam-1.0/#html-attribute-state-and-property-mappings
|
|
1311
|
-
*/
|
|
1312
|
-
function isDisabledImpl(impl) {
|
|
1313
|
-
switch (anyTag(impl)) {
|
|
1314
|
-
case _ctrl_dom_internal.T.button:
|
|
1315
|
-
case _ctrl_dom_internal.T.fieldset:
|
|
1316
|
-
case _ctrl_dom_internal.T.input:
|
|
1317
|
-
case _ctrl_dom_internal.T.optgroup:
|
|
1318
|
-
case _ctrl_dom_internal.T.option:
|
|
1319
|
-
case _ctrl_dom_internal.T.select:
|
|
1320
|
-
case _ctrl_dom_internal.T.textarea: if ((0, _ctrl_dom_internal.attr)(impl, "disabled") !== null) return true;
|
|
1321
|
-
}
|
|
1322
|
-
return (0, _ctrl_dom_internal.attr)(impl, "aria-disabled") === "true";
|
|
1323
|
-
}
|
|
1324
|
-
|
|
1325
|
-
// src/hidden.ts
|
|
1326
|
-
/**
|
|
1327
|
-
* Subtree exclusion for one element: `element.hidden === true` (HTMLElement only),
|
|
1328
|
-
* `aria-hidden="true"`, or computed `display: none`.
|
|
1329
|
-
*/
|
|
1330
|
-
function isSubtreeInaccessibleImpl(impl) {
|
|
1331
|
-
if (impl.ns === _ctrl_dom_internal.HTML_NS && (0, _ctrl_dom_internal.attr)(impl, "hidden") !== null) return true;
|
|
1332
|
-
if ((0, _ctrl_dom_internal.attr)(impl, "aria-hidden") === "true") return true;
|
|
1333
|
-
return isDisplayNone(impl);
|
|
1334
|
-
}
|
|
1335
|
-
const CHAIN_HIDDEN = 1;
|
|
1336
|
-
/**
|
|
1337
|
-
* Whether `impl` or any ancestor element (`parentElement` chain) is subtree-inaccessible.
|
|
1338
|
-
* Memoized per element, stamped with `Document._version` + `_styleVersion`, so one query
|
|
1339
|
-
* reuses an ancestor's answer across all its descendants and repeated queries over an
|
|
1340
|
-
* unchanged document are O(1) per element.
|
|
1341
|
-
*/
|
|
1342
|
-
function chainInaccessible(impl, version, styleVersion) {
|
|
1343
|
-
const c = impl.cache;
|
|
1344
|
-
if (c !== null && c.ariaHiddenVersion === version && c.ariaHiddenStyleVersion === styleVersion) return (c.ariaHiddenBits & CHAIN_HIDDEN) !== 0;
|
|
1345
|
-
let hidden = isSubtreeInaccessibleImpl(impl);
|
|
1346
|
-
if (!hidden) {
|
|
1347
|
-
const p = impl.parent;
|
|
1348
|
-
if (p !== null && p.type === _ctrl_dom_internal.ELEMENT_NODE) hidden = chainInaccessible(p, version, styleVersion);
|
|
1349
|
-
}
|
|
1350
|
-
const cache = c ?? (0, _ctrl_dom_internal.nodeCache)(impl);
|
|
1351
|
-
cache.ariaHiddenVersion = version;
|
|
1352
|
-
cache.ariaHiddenStyleVersion = styleVersion;
|
|
1353
|
-
cache.ariaHiddenBits = hidden ? CHAIN_HIDDEN : 0;
|
|
1354
|
-
return hidden;
|
|
1355
|
-
}
|
|
1356
|
-
/** Testing Library's `isInaccessible(element)` with the default subtree check. */
|
|
1357
|
-
function isInaccessibleImpl(impl) {
|
|
1358
|
-
if (isVisibilityHidden(impl)) return true;
|
|
1359
|
-
const doc = impl.doc;
|
|
1360
|
-
return chainInaccessible(impl, doc[_ctrl_dom_internal.$version], doc[_ctrl_dom_internal.$styleVersion]);
|
|
1361
|
-
}
|
|
1362
|
-
/**
|
|
1363
|
-
* Testing Library's `isInaccessible(element, { isSubtreeInaccessible: cachedIsSubtreeInaccessible })`
|
|
1364
|
-
* while the window's `getComputedStyle` is user-replaced (`getComputedStyleOverride`): every
|
|
1365
|
-
* style read goes through `gcs` exactly where role-helpers.js calls
|
|
1366
|
-
* `window.getComputedStyle(element)` — `visibility` of the element, then `display` per
|
|
1367
|
-
* ancestor. `memo` plays upstream's per-query `subtreeIsInaccessibleCache` (pass null for a
|
|
1368
|
-
* one-off call). Nothing is cached on the nodes: the replacement's answers are not versioned.
|
|
1369
|
-
*/
|
|
1370
|
-
function isInaccessibleWithStyle(impl, gcs, memo) {
|
|
1371
|
-
if (gcs(impl.node).visibility === "hidden") return true;
|
|
1372
|
-
for (let cur = impl; cur !== null && cur.type === _ctrl_dom_internal.ELEMENT_NODE; cur = cur.parent) {
|
|
1373
|
-
let hidden = memo !== null ? memo.get(cur) : void 0;
|
|
1374
|
-
if (hidden === void 0) {
|
|
1375
|
-
hidden = isSubtreeInaccessibleWithStyle(cur, gcs);
|
|
1376
|
-
if (memo !== null) memo.set(cur, hidden);
|
|
1377
|
-
}
|
|
1378
|
-
if (hidden) return true;
|
|
1379
|
-
}
|
|
1380
|
-
return false;
|
|
1381
|
-
}
|
|
1382
|
-
/** role-helpers.js `isSubtreeInaccessible` reading `display` through `gcs`. */
|
|
1383
|
-
function isSubtreeInaccessibleWithStyle(impl, gcs) {
|
|
1384
|
-
if (impl.ns === _ctrl_dom_internal.HTML_NS && (0, _ctrl_dom_internal.attr)(impl, "hidden") !== null) return true;
|
|
1385
|
-
if ((0, _ctrl_dom_internal.attr)(impl, "aria-hidden") === "true") return true;
|
|
1386
|
-
return gcs(impl.node).display === "none";
|
|
1387
|
-
}
|
|
1388
|
-
const NO_WINDOW = "Owner document of the element needs to have an associated window.";
|
|
1389
|
-
function checkGetComputedStyle(impl, options) {
|
|
1390
|
-
if (options !== void 0 && "getComputedStyle" in options && options.getComputedStyle !== void 0) {
|
|
1391
|
-
const gcs = options.getComputedStyle;
|
|
1392
|
-
if (typeof gcs !== "function") throw new TypeError(NO_WINDOW);
|
|
1393
|
-
return gcs;
|
|
1394
|
-
}
|
|
1395
|
-
if (impl.doc[_ctrl_dom_internal.$window] === null) throw new TypeError(NO_WINDOW);
|
|
1396
|
-
return (0, _ctrl_dom_internal.getComputedStyleOverride)(impl);
|
|
1397
|
-
}
|
|
1398
|
-
/**
|
|
1399
|
-
* @returns `true` if every child of the element is inaccessible
|
|
1400
|
-
* https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion
|
|
1401
|
-
*/
|
|
1402
|
-
function isSubtreeInaccessible(element, options) {
|
|
1403
|
-
const impl = implOf(element);
|
|
1404
|
-
const gcs = checkGetComputedStyle(impl, options);
|
|
1405
|
-
if (gcs === null) return isSubtreeInaccessibleImpl(impl);
|
|
1406
|
-
if (impl.ns === _ctrl_dom_internal.HTML_NS && (0, _ctrl_dom_internal.attr)(impl, "hidden") !== null) return true;
|
|
1407
|
-
if ((0, _ctrl_dom_internal.attr)(impl, "aria-hidden") === "true") return true;
|
|
1408
|
-
return gcs(element).display === "none";
|
|
1409
|
-
}
|
|
1410
|
-
/**
|
|
1411
|
-
* Partial implementation of https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion which should
|
|
1412
|
-
* only be used for elements with a non-presentational role. Implements aria-hidden
|
|
1413
|
-
* semantics (parent overrides child); ignores "Children Presentational: True".
|
|
1414
|
-
*/
|
|
1415
|
-
function isInaccessible(element, options) {
|
|
1416
|
-
const impl = implOf(element);
|
|
1417
|
-
const gcs = checkGetComputedStyle(impl, options);
|
|
1418
|
-
const custom = options?.isSubtreeInaccessible;
|
|
1419
|
-
if (gcs === null && custom === void 0) return isInaccessibleImpl(impl);
|
|
1420
|
-
if (gcs !== null ? gcs(element).visibility === "hidden" : isVisibilityHidden(impl)) return true;
|
|
1421
|
-
for (let cur = impl; cur !== null && cur.type === _ctrl_dom_internal.ELEMENT_NODE; cur = cur.parent) {
|
|
1422
|
-
const el = cur.node;
|
|
1423
|
-
if (custom !== void 0 ? custom(el) : gcs !== null ? isSubtreeInaccessible(el, { getComputedStyle: gcs }) : isSubtreeInaccessibleImpl(cur)) return true;
|
|
1424
|
-
}
|
|
1425
|
-
return false;
|
|
1426
|
-
}
|
|
1427
|
-
|
|
1428
|
-
// src/roles-list.ts
|
|
1429
|
-
/** Role → elements (tree order), keyed in order of first appearance. Implicit role "" elements are skipped. */
|
|
1430
|
-
function getRolesImpl(container, hidden) {
|
|
1431
|
-
const out = /* @__PURE__ */ new Map();
|
|
1432
|
-
const gcs = hidden ? null : (0, _ctrl_dom_internal.getComputedStyleOverride)(container);
|
|
1433
|
-
const memo = gcs !== null ? /* @__PURE__ */ new Map() : null;
|
|
1434
|
-
for (let n = container; n !== null;) {
|
|
1435
|
-
if (n.type === _ctrl_dom_internal.ELEMENT_NODE && (hidden || !(gcs === null ? isInaccessibleImpl(n) : isInaccessibleWithStyle(n, gcs, memo)))) {
|
|
1436
|
-
const roleAttr = (0, _ctrl_dom_internal.attr)(n, "role");
|
|
1437
|
-
let role;
|
|
1438
|
-
if (roleAttr !== null) {
|
|
1439
|
-
const sp = roleAttr.indexOf(" ");
|
|
1440
|
-
role = sp === -1 ? roleAttr : roleAttr.slice(0, sp);
|
|
1441
|
-
} else role = implicitRole(n);
|
|
1442
|
-
if (roleAttr !== null || role !== "") {
|
|
1443
|
-
const list = out.get(role);
|
|
1444
|
-
if (list === void 0) out.set(role, [n]);
|
|
1445
|
-
else list.push(n);
|
|
1446
|
-
}
|
|
1447
|
-
}
|
|
1448
|
-
let next = null;
|
|
1449
|
-
for (let c = n.first; c !== null; c = c.next) if (c.type === _ctrl_dom_internal.ELEMENT_NODE) {
|
|
1450
|
-
next = c;
|
|
1451
|
-
break;
|
|
1452
|
-
}
|
|
1453
|
-
if (next === null) {
|
|
1454
|
-
let cur = n;
|
|
1455
|
-
while (cur !== null && cur !== container) {
|
|
1456
|
-
for (let s = cur.next; s !== null; s = s.next) if (s.type === _ctrl_dom_internal.ELEMENT_NODE) {
|
|
1457
|
-
next = s;
|
|
1458
|
-
break;
|
|
1459
|
-
}
|
|
1460
|
-
if (next !== null) break;
|
|
1461
|
-
cur = cur.parent;
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1464
|
-
n = next;
|
|
1465
|
-
}
|
|
1466
|
-
return out;
|
|
1467
|
-
}
|
|
1468
|
-
/** Testing Library's `getRoles(container, { hidden })`. */
|
|
1469
|
-
function getRoles(container, options = {}) {
|
|
1470
|
-
const map = getRolesImpl(implOf(container), options.hidden ?? false);
|
|
1471
|
-
const out = {};
|
|
1472
|
-
for (const [role, list] of map) out[role] = list.map((n) => n.node);
|
|
1473
|
-
return out;
|
|
1474
|
-
}
|
|
1475
|
-
/**
|
|
1476
|
-
* Testing Library's `prettyRoles(dom, { hidden, includeDescription })`. `prettyDOM` formats
|
|
1477
|
-
* `el.cloneNode(false)` (it lives in @ctrl/dom/testing-library, which passes its own).
|
|
1478
|
-
*/
|
|
1479
|
-
function prettyRoles(dom, options, prettyDOM) {
|
|
1480
|
-
const root = implOf(dom);
|
|
1481
|
-
const map = getRolesImpl(root, options.hidden ?? false);
|
|
1482
|
-
const gcs = (0, _ctrl_dom_internal.getComputedStyleOverride)(root);
|
|
1483
|
-
const pseudo = options.computedStyleSupportsPseudoElements ?? false;
|
|
1484
|
-
const nameOptions = gcs === null ? { computedStyleSupportsPseudoElements: pseudo } : {
|
|
1485
|
-
computedStyleSupportsPseudoElements: pseudo,
|
|
1486
|
-
getComputedStyle: gcs
|
|
1487
|
-
};
|
|
1488
|
-
const delimiterBar = "-".repeat(50);
|
|
1489
|
-
const parts = [];
|
|
1490
|
-
for (const [role, elements] of map) {
|
|
1491
|
-
if (role === "generic") continue;
|
|
1492
|
-
const elementsString = elements.map((el) => {
|
|
1493
|
-
const nameString = `Name "${computeAccessibleNameImpl(el, nameOptions, 5)}":\n`;
|
|
1494
|
-
const domString = prettyDOM(el.node.cloneNode(false));
|
|
1495
|
-
if (options.includeDescription) return `${nameString}${`Description "${computeAccessibleDescriptionImpl(el, nameOptions, 5)}":\n`}${domString}`;
|
|
1496
|
-
return `${nameString}${domString}`;
|
|
1497
|
-
}).join("\n\n");
|
|
1498
|
-
parts.push(`${role}:\n\n${elementsString}\n\n${delimiterBar}`);
|
|
1499
|
-
}
|
|
1500
|
-
return parts.join("\n");
|
|
1501
|
-
}
|
|
1502
|
-
|
|
1503
|
-
Object.defineProperty(exports, "anyTag", {
|
|
1504
|
-
enumerable: true,
|
|
1505
|
-
get: function () {
|
|
1506
|
-
return anyTag;
|
|
1507
|
-
}
|
|
1508
|
-
});
|
|
1509
|
-
Object.defineProperty(exports, "ariaCheckedState", {
|
|
1510
|
-
enumerable: true,
|
|
1511
|
-
get: function () {
|
|
1512
|
-
return ariaCheckedState;
|
|
1513
|
-
}
|
|
1514
|
-
});
|
|
1515
|
-
Object.defineProperty(exports, "ariaPressedState", {
|
|
1516
|
-
enumerable: true,
|
|
1517
|
-
get: function () {
|
|
1518
|
-
return ariaPressedState;
|
|
1519
|
-
}
|
|
1520
|
-
});
|
|
1521
|
-
Object.defineProperty(exports, "computeAccessibleDescriptionImpl", {
|
|
1522
|
-
enumerable: true,
|
|
1523
|
-
get: function () {
|
|
1524
|
-
return computeAccessibleDescriptionImpl;
|
|
1525
|
-
}
|
|
1526
|
-
});
|
|
1527
|
-
Object.defineProperty(exports, "computeAccessibleNameImpl", {
|
|
1528
|
-
enumerable: true,
|
|
1529
|
-
get: function () {
|
|
1530
|
-
return computeAccessibleNameImpl;
|
|
1531
|
-
}
|
|
1532
|
-
});
|
|
1533
|
-
Object.defineProperty(exports, "computeAriaBusy", {
|
|
1534
|
-
enumerable: true,
|
|
1535
|
-
get: function () {
|
|
1536
|
-
return computeAriaBusy;
|
|
1537
|
-
}
|
|
1538
|
-
});
|
|
1539
|
-
Object.defineProperty(exports, "computeAriaChecked", {
|
|
1540
|
-
enumerable: true,
|
|
1541
|
-
get: function () {
|
|
1542
|
-
return computeAriaChecked;
|
|
1543
|
-
}
|
|
1544
|
-
});
|
|
1545
|
-
Object.defineProperty(exports, "computeAriaCurrent", {
|
|
1546
|
-
enumerable: true,
|
|
1547
|
-
get: function () {
|
|
1548
|
-
return computeAriaCurrent;
|
|
1549
|
-
}
|
|
1550
|
-
});
|
|
1551
|
-
Object.defineProperty(exports, "computeAriaExpanded", {
|
|
1552
|
-
enumerable: true,
|
|
1553
|
-
get: function () {
|
|
1554
|
-
return computeAriaExpanded;
|
|
1555
|
-
}
|
|
1556
|
-
});
|
|
1557
|
-
Object.defineProperty(exports, "computeAriaPressed", {
|
|
1558
|
-
enumerable: true,
|
|
1559
|
-
get: function () {
|
|
1560
|
-
return computeAriaPressed;
|
|
1561
|
-
}
|
|
1562
|
-
});
|
|
1563
|
-
Object.defineProperty(exports, "computeAriaSelected", {
|
|
1564
|
-
enumerable: true,
|
|
1565
|
-
get: function () {
|
|
1566
|
-
return computeAriaSelected;
|
|
1567
|
-
}
|
|
1568
|
-
});
|
|
1569
|
-
Object.defineProperty(exports, "computeAriaValueMax", {
|
|
1570
|
-
enumerable: true,
|
|
1571
|
-
get: function () {
|
|
1572
|
-
return computeAriaValueMax;
|
|
1573
|
-
}
|
|
1574
|
-
});
|
|
1575
|
-
Object.defineProperty(exports, "computeAriaValueMin", {
|
|
1576
|
-
enumerable: true,
|
|
1577
|
-
get: function () {
|
|
1578
|
-
return computeAriaValueMin;
|
|
1579
|
-
}
|
|
1580
|
-
});
|
|
1581
|
-
Object.defineProperty(exports, "computeAriaValueNow", {
|
|
1582
|
-
enumerable: true,
|
|
1583
|
-
get: function () {
|
|
1584
|
-
return computeAriaValueNow;
|
|
1585
|
-
}
|
|
1586
|
-
});
|
|
1587
|
-
Object.defineProperty(exports, "computeAriaValueText", {
|
|
1588
|
-
enumerable: true,
|
|
1589
|
-
get: function () {
|
|
1590
|
-
return computeAriaValueText;
|
|
1591
|
-
}
|
|
1592
|
-
});
|
|
1593
|
-
Object.defineProperty(exports, "computeHeadingLevel", {
|
|
1594
|
-
enumerable: true,
|
|
1595
|
-
get: function () {
|
|
1596
|
-
return computeHeadingLevel;
|
|
1597
|
-
}
|
|
1598
|
-
});
|
|
1599
|
-
Object.defineProperty(exports, "computeTextAlternativeImpl", {
|
|
1600
|
-
enumerable: true,
|
|
1601
|
-
get: function () {
|
|
1602
|
-
return computeTextAlternativeImpl;
|
|
1603
|
-
}
|
|
1604
|
-
});
|
|
1605
|
-
Object.defineProperty(exports, "daaExplicitRole", {
|
|
1606
|
-
enumerable: true,
|
|
1607
|
-
get: function () {
|
|
1608
|
-
return daaExplicitRole;
|
|
1609
|
-
}
|
|
1610
|
-
});
|
|
1611
|
-
Object.defineProperty(exports, "daaGetRole", {
|
|
1612
|
-
enumerable: true,
|
|
1613
|
-
get: function () {
|
|
1614
|
-
return daaGetRole;
|
|
1615
|
-
}
|
|
1616
|
-
});
|
|
1617
|
-
Object.defineProperty(exports, "daaImplicitRole", {
|
|
1618
|
-
enumerable: true,
|
|
1619
|
-
get: function () {
|
|
1620
|
-
return daaImplicitRole;
|
|
1621
|
-
}
|
|
1622
|
-
});
|
|
1623
|
-
Object.defineProperty(exports, "getImplicitRoles", {
|
|
1624
|
-
enumerable: true,
|
|
1625
|
-
get: function () {
|
|
1626
|
-
return getImplicitRoles;
|
|
1627
|
-
}
|
|
1628
|
-
});
|
|
1629
|
-
Object.defineProperty(exports, "getRoles", {
|
|
1630
|
-
enumerable: true,
|
|
1631
|
-
get: function () {
|
|
1632
|
-
return getRoles;
|
|
1633
|
-
}
|
|
1634
|
-
});
|
|
1635
|
-
Object.defineProperty(exports, "getRolesImpl", {
|
|
1636
|
-
enumerable: true,
|
|
1637
|
-
get: function () {
|
|
1638
|
-
return getRolesImpl;
|
|
1639
|
-
}
|
|
1640
|
-
});
|
|
1641
|
-
Object.defineProperty(exports, "implOf", {
|
|
1642
|
-
enumerable: true,
|
|
1643
|
-
get: function () {
|
|
1644
|
-
return implOf;
|
|
1645
|
-
}
|
|
1646
|
-
});
|
|
1647
|
-
Object.defineProperty(exports, "implicitRole", {
|
|
1648
|
-
enumerable: true,
|
|
1649
|
-
get: function () {
|
|
1650
|
-
return implicitRole;
|
|
1651
|
-
}
|
|
1652
|
-
});
|
|
1653
|
-
Object.defineProperty(exports, "implicitRoleJestDom", {
|
|
1654
|
-
enumerable: true,
|
|
1655
|
-
get: function () {
|
|
1656
|
-
return implicitRoleJestDom;
|
|
1657
|
-
}
|
|
1658
|
-
});
|
|
1659
|
-
Object.defineProperty(exports, "inputType", {
|
|
1660
|
-
enumerable: true,
|
|
1661
|
-
get: function () {
|
|
1662
|
-
return inputType;
|
|
1663
|
-
}
|
|
1664
|
-
});
|
|
1665
|
-
Object.defineProperty(exports, "isDisabledImpl", {
|
|
1666
|
-
enumerable: true,
|
|
1667
|
-
get: function () {
|
|
1668
|
-
return isDisabledImpl;
|
|
1669
|
-
}
|
|
1670
|
-
});
|
|
1671
|
-
Object.defineProperty(exports, "isDisplayInline", {
|
|
1672
|
-
enumerable: true,
|
|
1673
|
-
get: function () {
|
|
1674
|
-
return isDisplayInline;
|
|
1675
|
-
}
|
|
1676
|
-
});
|
|
1677
|
-
Object.defineProperty(exports, "isDisplayNone", {
|
|
1678
|
-
enumerable: true,
|
|
1679
|
-
get: function () {
|
|
1680
|
-
return isDisplayNone;
|
|
1681
|
-
}
|
|
1682
|
-
});
|
|
1683
|
-
Object.defineProperty(exports, "isInaccessible", {
|
|
1684
|
-
enumerable: true,
|
|
1685
|
-
get: function () {
|
|
1686
|
-
return isInaccessible;
|
|
1687
|
-
}
|
|
1688
|
-
});
|
|
1689
|
-
Object.defineProperty(exports, "isInaccessibleImpl", {
|
|
1690
|
-
enumerable: true,
|
|
1691
|
-
get: function () {
|
|
1692
|
-
return isInaccessibleImpl;
|
|
1693
|
-
}
|
|
1694
|
-
});
|
|
1695
|
-
Object.defineProperty(exports, "isInaccessibleWithStyle", {
|
|
1696
|
-
enumerable: true,
|
|
1697
|
-
get: function () {
|
|
1698
|
-
return isInaccessibleWithStyle;
|
|
1699
|
-
}
|
|
1700
|
-
});
|
|
1701
|
-
Object.defineProperty(exports, "isLabelable", {
|
|
1702
|
-
enumerable: true,
|
|
1703
|
-
get: function () {
|
|
1704
|
-
return isLabelable;
|
|
1705
|
-
}
|
|
1706
|
-
});
|
|
1707
|
-
Object.defineProperty(exports, "isSubtreeInaccessible", {
|
|
1708
|
-
enumerable: true,
|
|
1709
|
-
get: function () {
|
|
1710
|
-
return isSubtreeInaccessible;
|
|
1711
|
-
}
|
|
1712
|
-
});
|
|
1713
|
-
Object.defineProperty(exports, "isSubtreeInaccessibleImpl", {
|
|
1714
|
-
enumerable: true,
|
|
1715
|
-
get: function () {
|
|
1716
|
-
return isSubtreeInaccessibleImpl;
|
|
1717
|
-
}
|
|
1718
|
-
});
|
|
1719
|
-
Object.defineProperty(exports, "isVisibilityHidden", {
|
|
1720
|
-
enumerable: true,
|
|
1721
|
-
get: function () {
|
|
1722
|
-
return isVisibilityHidden;
|
|
1723
|
-
}
|
|
1724
|
-
});
|
|
1725
|
-
Object.defineProperty(exports, "labelsOf", {
|
|
1726
|
-
enumerable: true,
|
|
1727
|
-
get: function () {
|
|
1728
|
-
return labelsOf;
|
|
1729
|
-
}
|
|
1730
|
-
});
|
|
1731
|
-
Object.defineProperty(exports, "prettyRoles", {
|
|
1732
|
-
enumerable: true,
|
|
1733
|
-
get: function () {
|
|
1734
|
-
return prettyRoles;
|
|
1735
|
-
}
|
|
1736
|
-
});
|
|
1737
|
-
Object.defineProperty(exports, "queryIdRefs", {
|
|
1738
|
-
enumerable: true,
|
|
1739
|
-
get: function () {
|
|
1740
|
-
return queryIdRefs;
|
|
1741
|
-
}
|
|
1742
|
-
});
|
|
1743
|
-
Object.defineProperty(exports, "tlRole", {
|
|
1744
|
-
enumerable: true,
|
|
1745
|
-
get: function () {
|
|
1746
|
-
return tlRole;
|
|
1747
|
-
}
|
|
1748
|
-
});
|
|
1749
|
-
Object.defineProperty(exports, "withStyleOverride", {
|
|
1750
|
-
enumerable: true,
|
|
1751
|
-
get: function () {
|
|
1752
|
-
return withStyleOverride;
|
|
1753
|
-
}
|
|
1754
|
-
});
|