@reticular/speakable 1.5.0 → 1.6.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.
|
@@ -0,0 +1,2129 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EVENT_RESULT,
|
|
3
|
+
__commonJS,
|
|
4
|
+
__toESM
|
|
5
|
+
} from "./chunk-CL3DJBD7.js";
|
|
6
|
+
|
|
7
|
+
// ../node_modules/picocolors/picocolors.browser.js
|
|
8
|
+
var require_picocolors_browser = __commonJS({
|
|
9
|
+
"../node_modules/picocolors/picocolors.browser.js"(exports, module) {
|
|
10
|
+
"use strict";
|
|
11
|
+
var x = String;
|
|
12
|
+
var create = function() {
|
|
13
|
+
return { isColorSupported: false, reset: x, bold: x, dim: x, italic: x, underline: x, inverse: x, hidden: x, strikethrough: x, black: x, red: x, green: x, yellow: x, blue: x, magenta: x, cyan: x, white: x, gray: x, bgBlack: x, bgRed: x, bgGreen: x, bgYellow: x, bgBlue: x, bgMagenta: x, bgCyan: x, bgWhite: x, blackBright: x, redBright: x, greenBright: x, yellowBright: x, blueBright: x, magentaBright: x, cyanBright: x, whiteBright: x, bgBlackBright: x, bgRedBright: x, bgGreenBright: x, bgYellowBright: x, bgBlueBright: x, bgMagentaBright: x, bgCyanBright: x, bgWhiteBright: x };
|
|
14
|
+
};
|
|
15
|
+
module.exports = create();
|
|
16
|
+
module.exports.createColors = create;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// ../src/model/types.ts
|
|
21
|
+
var SUPPORTED_ROLES = [
|
|
22
|
+
// Original roles (22)
|
|
23
|
+
"button",
|
|
24
|
+
"link",
|
|
25
|
+
"heading",
|
|
26
|
+
"textbox",
|
|
27
|
+
"checkbox",
|
|
28
|
+
"radio",
|
|
29
|
+
"combobox",
|
|
30
|
+
"listbox",
|
|
31
|
+
"option",
|
|
32
|
+
"list",
|
|
33
|
+
"listitem",
|
|
34
|
+
"navigation",
|
|
35
|
+
"main",
|
|
36
|
+
"banner",
|
|
37
|
+
"contentinfo",
|
|
38
|
+
"region",
|
|
39
|
+
"img",
|
|
40
|
+
"article",
|
|
41
|
+
"complementary",
|
|
42
|
+
"form",
|
|
43
|
+
"search",
|
|
44
|
+
"generic",
|
|
45
|
+
// New roles (21)
|
|
46
|
+
"paragraph",
|
|
47
|
+
"blockquote",
|
|
48
|
+
"code",
|
|
49
|
+
"staticText",
|
|
50
|
+
"table",
|
|
51
|
+
"row",
|
|
52
|
+
"cell",
|
|
53
|
+
"columnheader",
|
|
54
|
+
"rowheader",
|
|
55
|
+
"term",
|
|
56
|
+
"definition",
|
|
57
|
+
"figure",
|
|
58
|
+
"caption",
|
|
59
|
+
"group",
|
|
60
|
+
"dialog",
|
|
61
|
+
"meter",
|
|
62
|
+
"progressbar",
|
|
63
|
+
"status",
|
|
64
|
+
"document",
|
|
65
|
+
"application",
|
|
66
|
+
"separator"
|
|
67
|
+
];
|
|
68
|
+
var CURRENT_MODEL_VERSION = {
|
|
69
|
+
major: 1,
|
|
70
|
+
minor: 0
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// ../src/extractor/aria-name.ts
|
|
74
|
+
function computeAccessibleName(element, visited = /* @__PURE__ */ new Set()) {
|
|
75
|
+
const warnings = [];
|
|
76
|
+
if (visited.has(element)) {
|
|
77
|
+
warnings.push({
|
|
78
|
+
message: "Circular reference detected in aria-labelledby chain",
|
|
79
|
+
element
|
|
80
|
+
});
|
|
81
|
+
return { name: "", warnings };
|
|
82
|
+
}
|
|
83
|
+
visited.add(element);
|
|
84
|
+
const labelledBy = element.getAttribute("aria-labelledby");
|
|
85
|
+
if (labelledBy) {
|
|
86
|
+
const name = computeNameFromLabelledBy(element, labelledBy, visited, warnings);
|
|
87
|
+
return { name, warnings };
|
|
88
|
+
}
|
|
89
|
+
const ariaLabel = element.getAttribute("aria-label");
|
|
90
|
+
if (ariaLabel && ariaLabel.trim()) {
|
|
91
|
+
return { name: ariaLabel.trim(), warnings };
|
|
92
|
+
}
|
|
93
|
+
if (isFormControl(element)) {
|
|
94
|
+
const labelName = computeNameFromLabel(element);
|
|
95
|
+
if (labelName) {
|
|
96
|
+
return { name: labelName, warnings };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (element.tagName.toLowerCase() === "img") {
|
|
100
|
+
const alt = element.getAttribute("alt");
|
|
101
|
+
if (alt !== null) {
|
|
102
|
+
return { name: alt.trim(), warnings };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (supportsNameFromContent(element)) {
|
|
106
|
+
const textName = computeNameFromContent(element, visited);
|
|
107
|
+
if (textName) {
|
|
108
|
+
return { name: textName, warnings };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const title = element.getAttribute("title");
|
|
112
|
+
if (title && title.trim()) {
|
|
113
|
+
return { name: title.trim(), warnings };
|
|
114
|
+
}
|
|
115
|
+
return { name: "", warnings };
|
|
116
|
+
}
|
|
117
|
+
function computeNameFromLabelledBy(element, labelledBy, visited, warnings) {
|
|
118
|
+
const document2 = element.ownerDocument;
|
|
119
|
+
if (!document2) {
|
|
120
|
+
return "";
|
|
121
|
+
}
|
|
122
|
+
const ids = labelledBy.trim().split(/\s+/);
|
|
123
|
+
const names = [];
|
|
124
|
+
for (const id of ids) {
|
|
125
|
+
if (!id) continue;
|
|
126
|
+
const referencedElement = document2.getElementById(id);
|
|
127
|
+
if (!referencedElement) {
|
|
128
|
+
warnings.push({
|
|
129
|
+
message: `aria-labelledby references non-existent ID: ${id}`,
|
|
130
|
+
element
|
|
131
|
+
});
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const result = computeAccessibleName(referencedElement, new Set(visited));
|
|
135
|
+
warnings.push(...result.warnings);
|
|
136
|
+
const name = result.name || getTextContent(referencedElement);
|
|
137
|
+
if (name) {
|
|
138
|
+
names.push(name);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return names.join(" ").trim();
|
|
142
|
+
}
|
|
143
|
+
function computeNameFromLabel(element) {
|
|
144
|
+
const document2 = element.ownerDocument;
|
|
145
|
+
if (!document2) {
|
|
146
|
+
return "";
|
|
147
|
+
}
|
|
148
|
+
const id = element.getAttribute("id");
|
|
149
|
+
if (id) {
|
|
150
|
+
const label = document2.querySelector(`label[for="${id}"]`);
|
|
151
|
+
if (label) {
|
|
152
|
+
return getTextContent(label);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const parentLabel = element.closest("label");
|
|
156
|
+
if (parentLabel) {
|
|
157
|
+
return getTextContent(parentLabel);
|
|
158
|
+
}
|
|
159
|
+
return "";
|
|
160
|
+
}
|
|
161
|
+
function computeNameFromContent(element, _visited) {
|
|
162
|
+
return getTextContent(element);
|
|
163
|
+
}
|
|
164
|
+
function getTextContent(element) {
|
|
165
|
+
if (element.getAttribute("aria-hidden") === "true") {
|
|
166
|
+
return "";
|
|
167
|
+
}
|
|
168
|
+
let text = "";
|
|
169
|
+
for (const node of Array.from(element.childNodes)) {
|
|
170
|
+
if (node.nodeType === 3) {
|
|
171
|
+
text += node.textContent || "";
|
|
172
|
+
} else if (node.nodeType === 1) {
|
|
173
|
+
const childElement = node;
|
|
174
|
+
if (childElement.getAttribute("aria-hidden") === "true") {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
text += getTextContent(childElement);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return text.trim();
|
|
181
|
+
}
|
|
182
|
+
function isFormControl(element) {
|
|
183
|
+
const tagName = element.tagName.toLowerCase();
|
|
184
|
+
return tagName === "input" || tagName === "textarea" || tagName === "select" || tagName === "button";
|
|
185
|
+
}
|
|
186
|
+
function supportsNameFromContent(element) {
|
|
187
|
+
const tagName = element.tagName.toLowerCase();
|
|
188
|
+
const role = element.getAttribute("role");
|
|
189
|
+
const contentElements = [
|
|
190
|
+
"button",
|
|
191
|
+
"a",
|
|
192
|
+
"h1",
|
|
193
|
+
"h2",
|
|
194
|
+
"h3",
|
|
195
|
+
"h4",
|
|
196
|
+
"h5",
|
|
197
|
+
"h6",
|
|
198
|
+
"summary",
|
|
199
|
+
"figcaption",
|
|
200
|
+
"legend",
|
|
201
|
+
"caption",
|
|
202
|
+
"th",
|
|
203
|
+
"td",
|
|
204
|
+
"li",
|
|
205
|
+
"dt",
|
|
206
|
+
"dd"
|
|
207
|
+
];
|
|
208
|
+
if (contentElements.includes(tagName)) {
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
const contentRoles = [
|
|
212
|
+
"button",
|
|
213
|
+
"link",
|
|
214
|
+
"heading",
|
|
215
|
+
"tab",
|
|
216
|
+
"treeitem",
|
|
217
|
+
"option",
|
|
218
|
+
"row",
|
|
219
|
+
"cell",
|
|
220
|
+
"columnheader",
|
|
221
|
+
"rowheader",
|
|
222
|
+
"tooltip",
|
|
223
|
+
"menuitem",
|
|
224
|
+
"menuitemcheckbox",
|
|
225
|
+
"menuitemradio"
|
|
226
|
+
];
|
|
227
|
+
if (role && contentRoles.includes(role)) {
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
function computeAccessibleDescription(element) {
|
|
233
|
+
const warnings = [];
|
|
234
|
+
const describedBy = element.getAttribute("aria-describedby");
|
|
235
|
+
if (describedBy) {
|
|
236
|
+
const description = computeDescriptionFromDescribedBy(
|
|
237
|
+
element,
|
|
238
|
+
describedBy,
|
|
239
|
+
warnings
|
|
240
|
+
);
|
|
241
|
+
if (description) {
|
|
242
|
+
return { description, warnings };
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const title = element.getAttribute("title");
|
|
246
|
+
if (title && title.trim()) {
|
|
247
|
+
return { description: title.trim(), warnings };
|
|
248
|
+
}
|
|
249
|
+
return { description: "", warnings };
|
|
250
|
+
}
|
|
251
|
+
function computeDescriptionFromDescribedBy(element, describedBy, warnings) {
|
|
252
|
+
const document2 = element.ownerDocument;
|
|
253
|
+
if (!document2) {
|
|
254
|
+
return "";
|
|
255
|
+
}
|
|
256
|
+
const ids = describedBy.trim().split(/\s+/);
|
|
257
|
+
const descriptions = [];
|
|
258
|
+
for (const id of ids) {
|
|
259
|
+
if (!id) continue;
|
|
260
|
+
const referencedElement = document2.getElementById(id);
|
|
261
|
+
if (!referencedElement) {
|
|
262
|
+
warnings.push({
|
|
263
|
+
message: `aria-describedby references non-existent ID: ${id}`,
|
|
264
|
+
element
|
|
265
|
+
});
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
const text = getTextContent(referencedElement);
|
|
269
|
+
if (text) {
|
|
270
|
+
descriptions.push(text);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return descriptions.join(" ").trim();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// ../src/extractor/role-mapper.ts
|
|
277
|
+
var IMPLICIT_ROLE_MAP = {
|
|
278
|
+
// Interactive elements
|
|
279
|
+
"button": "button",
|
|
280
|
+
"a": "link",
|
|
281
|
+
// Only if href attribute present
|
|
282
|
+
// Form controls
|
|
283
|
+
"input": "textbox",
|
|
284
|
+
// Default, varies by type
|
|
285
|
+
"textarea": "textbox",
|
|
286
|
+
"select": "listbox",
|
|
287
|
+
// Headings
|
|
288
|
+
"h1": "heading",
|
|
289
|
+
"h2": "heading",
|
|
290
|
+
"h3": "heading",
|
|
291
|
+
"h4": "heading",
|
|
292
|
+
"h5": "heading",
|
|
293
|
+
"h6": "heading",
|
|
294
|
+
// Landmarks
|
|
295
|
+
"nav": "navigation",
|
|
296
|
+
"main": "main",
|
|
297
|
+
"header": "banner",
|
|
298
|
+
// Only if not nested in article/section
|
|
299
|
+
"footer": "contentinfo",
|
|
300
|
+
// Only if not nested in article/section
|
|
301
|
+
"aside": "complementary",
|
|
302
|
+
"form": "form",
|
|
303
|
+
"section": "region",
|
|
304
|
+
// Only if has accessible name
|
|
305
|
+
// Lists
|
|
306
|
+
"ul": "list",
|
|
307
|
+
"ol": "list",
|
|
308
|
+
"li": "listitem",
|
|
309
|
+
// Images
|
|
310
|
+
"img": "img",
|
|
311
|
+
// Articles
|
|
312
|
+
"article": "article",
|
|
313
|
+
// Static content (new)
|
|
314
|
+
"p": "paragraph",
|
|
315
|
+
"blockquote": "blockquote",
|
|
316
|
+
"code": "code",
|
|
317
|
+
"pre": "code",
|
|
318
|
+
// Tables (new)
|
|
319
|
+
"table": "table",
|
|
320
|
+
"tr": "row",
|
|
321
|
+
"td": "cell",
|
|
322
|
+
"th": "columnheader",
|
|
323
|
+
// Default; scope="row" handled in computeImplicitRole
|
|
324
|
+
// Definition lists (new)
|
|
325
|
+
"dl": "list",
|
|
326
|
+
"dt": "term",
|
|
327
|
+
"dd": "definition",
|
|
328
|
+
// Figures (new)
|
|
329
|
+
"figure": "figure",
|
|
330
|
+
"figcaption": "caption",
|
|
331
|
+
// Disclosure (new)
|
|
332
|
+
"details": "group",
|
|
333
|
+
"summary": "button",
|
|
334
|
+
// Dialogs and widgets (new)
|
|
335
|
+
"dialog": "dialog",
|
|
336
|
+
"meter": "meter",
|
|
337
|
+
"progress": "progressbar",
|
|
338
|
+
"output": "status",
|
|
339
|
+
// Forms (new)
|
|
340
|
+
"fieldset": "group",
|
|
341
|
+
"legend": "caption",
|
|
342
|
+
// Embedded content (new)
|
|
343
|
+
"iframe": "document",
|
|
344
|
+
"video": "application",
|
|
345
|
+
"audio": "application",
|
|
346
|
+
// Separators (new)
|
|
347
|
+
"hr": "separator",
|
|
348
|
+
// Table caption (new)
|
|
349
|
+
"caption": "caption"
|
|
350
|
+
};
|
|
351
|
+
var INPUT_TYPE_ROLE_MAP = {
|
|
352
|
+
"button": "button",
|
|
353
|
+
"submit": "button",
|
|
354
|
+
"reset": "button",
|
|
355
|
+
"checkbox": "checkbox",
|
|
356
|
+
"radio": "radio",
|
|
357
|
+
"text": "textbox",
|
|
358
|
+
"email": "textbox",
|
|
359
|
+
"password": "textbox",
|
|
360
|
+
"search": "textbox",
|
|
361
|
+
"tel": "textbox",
|
|
362
|
+
"url": "textbox",
|
|
363
|
+
"number": "textbox"
|
|
364
|
+
};
|
|
365
|
+
function computeRole(element) {
|
|
366
|
+
const warnings = [];
|
|
367
|
+
const explicitRole = element.getAttribute("role");
|
|
368
|
+
if (explicitRole) {
|
|
369
|
+
const role = validateAndNormalizeRole(explicitRole, element, warnings);
|
|
370
|
+
if (role) {
|
|
371
|
+
return { role, warnings };
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
const implicitRole = computeImplicitRole(element, warnings);
|
|
375
|
+
return { role: implicitRole, warnings };
|
|
376
|
+
}
|
|
377
|
+
function validateAndNormalizeRole(roleAttr, element, warnings) {
|
|
378
|
+
const role = roleAttr.trim().toLowerCase();
|
|
379
|
+
if (role === "presentation" || role === "none") {
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
if (SUPPORTED_ROLES.includes(role)) {
|
|
383
|
+
return role;
|
|
384
|
+
}
|
|
385
|
+
warnings.push({
|
|
386
|
+
message: `Invalid or unsupported role: "${roleAttr}". Falling back to implicit role.`,
|
|
387
|
+
element
|
|
388
|
+
});
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
function computeImplicitRole(element, _warnings) {
|
|
392
|
+
const tagName = element.tagName.toLowerCase();
|
|
393
|
+
if (tagName === "input") {
|
|
394
|
+
return computeInputRole(element);
|
|
395
|
+
}
|
|
396
|
+
if (tagName === "a") {
|
|
397
|
+
return element.hasAttribute("href") ? "link" : null;
|
|
398
|
+
}
|
|
399
|
+
if (tagName === "header") {
|
|
400
|
+
return isTopLevelLandmark(element) ? "banner" : null;
|
|
401
|
+
}
|
|
402
|
+
if (tagName === "footer") {
|
|
403
|
+
return isTopLevelLandmark(element) ? "contentinfo" : null;
|
|
404
|
+
}
|
|
405
|
+
if (tagName === "th") {
|
|
406
|
+
const scope = element.getAttribute("scope");
|
|
407
|
+
return scope === "row" ? "rowheader" : "columnheader";
|
|
408
|
+
}
|
|
409
|
+
if (tagName === "section") {
|
|
410
|
+
return element.hasAttribute("aria-label") || element.hasAttribute("aria-labelledby") ? "region" : null;
|
|
411
|
+
}
|
|
412
|
+
const implicitRole = IMPLICIT_ROLE_MAP[tagName];
|
|
413
|
+
return implicitRole || null;
|
|
414
|
+
}
|
|
415
|
+
function computeInputRole(input) {
|
|
416
|
+
const type = (input.getAttribute("type") || "text").toLowerCase();
|
|
417
|
+
return INPUT_TYPE_ROLE_MAP[type] || "textbox";
|
|
418
|
+
}
|
|
419
|
+
function isTopLevelLandmark(element) {
|
|
420
|
+
let parent = element.parentElement;
|
|
421
|
+
while (parent) {
|
|
422
|
+
const tagName = parent.tagName.toLowerCase();
|
|
423
|
+
if (tagName === "article" || tagName === "section") {
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
parent = parent.parentElement;
|
|
427
|
+
}
|
|
428
|
+
return true;
|
|
429
|
+
}
|
|
430
|
+
function isAccessible(element) {
|
|
431
|
+
if (element.getAttribute("aria-hidden") === "true") {
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
const role = element.getAttribute("role");
|
|
435
|
+
if (role === "presentation" || role === "none") {
|
|
436
|
+
return false;
|
|
437
|
+
}
|
|
438
|
+
const roleResult = computeRole(element);
|
|
439
|
+
return roleResult.role !== null;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// ../src/extractor/state-extractor.ts
|
|
443
|
+
function extractState(element) {
|
|
444
|
+
const warnings = [];
|
|
445
|
+
const state = {};
|
|
446
|
+
const expanded = extractBooleanAttribute(element, "aria-expanded", warnings);
|
|
447
|
+
if (expanded !== void 0) {
|
|
448
|
+
state.expanded = expanded;
|
|
449
|
+
}
|
|
450
|
+
const checked = extractTriStateAttribute(element, "aria-checked", warnings);
|
|
451
|
+
if (checked !== void 0) {
|
|
452
|
+
state.checked = checked;
|
|
453
|
+
}
|
|
454
|
+
const pressed = extractTriStateAttribute(element, "aria-pressed", warnings);
|
|
455
|
+
if (pressed !== void 0) {
|
|
456
|
+
state.pressed = pressed;
|
|
457
|
+
}
|
|
458
|
+
const selected = extractBooleanAttribute(element, "aria-selected", warnings);
|
|
459
|
+
if (selected !== void 0) {
|
|
460
|
+
state.selected = selected;
|
|
461
|
+
}
|
|
462
|
+
const disabled = extractBooleanAttribute(element, "aria-disabled", warnings);
|
|
463
|
+
if (disabled !== void 0) {
|
|
464
|
+
state.disabled = disabled;
|
|
465
|
+
}
|
|
466
|
+
const invalid = extractBooleanAttribute(element, "aria-invalid", warnings);
|
|
467
|
+
if (invalid !== void 0) {
|
|
468
|
+
state.invalid = invalid;
|
|
469
|
+
}
|
|
470
|
+
const required = extractBooleanAttribute(element, "aria-required", warnings);
|
|
471
|
+
if (required !== void 0) {
|
|
472
|
+
state.required = required;
|
|
473
|
+
}
|
|
474
|
+
const readonly = extractBooleanAttribute(element, "aria-readonly", warnings);
|
|
475
|
+
if (readonly !== void 0) {
|
|
476
|
+
state.readonly = readonly;
|
|
477
|
+
}
|
|
478
|
+
const busy = extractBooleanAttribute(element, "aria-busy", warnings);
|
|
479
|
+
if (busy !== void 0) {
|
|
480
|
+
state.busy = busy;
|
|
481
|
+
}
|
|
482
|
+
const current = extractCurrentAttribute(element, warnings);
|
|
483
|
+
if (current !== void 0) {
|
|
484
|
+
state.current = current;
|
|
485
|
+
}
|
|
486
|
+
const grabbed = extractBooleanAttribute(element, "aria-grabbed", warnings);
|
|
487
|
+
if (grabbed !== void 0) {
|
|
488
|
+
state.grabbed = grabbed;
|
|
489
|
+
}
|
|
490
|
+
const hidden = extractBooleanAttribute(element, "aria-hidden", warnings);
|
|
491
|
+
if (hidden !== void 0) {
|
|
492
|
+
state.hidden = hidden;
|
|
493
|
+
}
|
|
494
|
+
const level = extractLevelAttribute(element, warnings);
|
|
495
|
+
if (level !== void 0) {
|
|
496
|
+
state.level = level;
|
|
497
|
+
}
|
|
498
|
+
const posinset = extractNumberAttribute(element, "aria-posinset", warnings);
|
|
499
|
+
if (posinset !== void 0) {
|
|
500
|
+
state.posinset = posinset;
|
|
501
|
+
}
|
|
502
|
+
const setsize = extractNumberAttribute(element, "aria-setsize", warnings);
|
|
503
|
+
if (setsize !== void 0) {
|
|
504
|
+
state.setsize = setsize;
|
|
505
|
+
}
|
|
506
|
+
extractNativeStates(element, state, warnings);
|
|
507
|
+
return { state, warnings };
|
|
508
|
+
}
|
|
509
|
+
function extractValue(element) {
|
|
510
|
+
const warnings = [];
|
|
511
|
+
const tagName = element.tagName.toLowerCase();
|
|
512
|
+
if (tagName === "input") {
|
|
513
|
+
return extractInputValue(element, warnings);
|
|
514
|
+
}
|
|
515
|
+
if (tagName === "textarea") {
|
|
516
|
+
return extractTextareaValue(element, warnings);
|
|
517
|
+
}
|
|
518
|
+
if (tagName === "select") {
|
|
519
|
+
return extractSelectValue(element, warnings);
|
|
520
|
+
}
|
|
521
|
+
const valueNow = element.getAttribute("aria-valuenow");
|
|
522
|
+
if (valueNow !== null) {
|
|
523
|
+
const current = parseFloat(valueNow);
|
|
524
|
+
if (!isNaN(current)) {
|
|
525
|
+
const valueMin = element.getAttribute("aria-valuemin");
|
|
526
|
+
const valueMax = element.getAttribute("aria-valuemax");
|
|
527
|
+
const valueText = element.getAttribute("aria-valuetext");
|
|
528
|
+
return {
|
|
529
|
+
value: {
|
|
530
|
+
current,
|
|
531
|
+
min: valueMin !== null ? parseFloat(valueMin) : void 0,
|
|
532
|
+
max: valueMax !== null ? parseFloat(valueMax) : void 0,
|
|
533
|
+
text: valueText || void 0
|
|
534
|
+
},
|
|
535
|
+
warnings
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
return { value: void 0, warnings };
|
|
540
|
+
}
|
|
541
|
+
function extractBooleanAttribute(element, attrName, warnings) {
|
|
542
|
+
const value = element.getAttribute(attrName);
|
|
543
|
+
if (value === null) {
|
|
544
|
+
return void 0;
|
|
545
|
+
}
|
|
546
|
+
const normalized = value.toLowerCase().trim();
|
|
547
|
+
if (normalized === "true") {
|
|
548
|
+
return true;
|
|
549
|
+
}
|
|
550
|
+
if (normalized === "false") {
|
|
551
|
+
return false;
|
|
552
|
+
}
|
|
553
|
+
warnings.push({
|
|
554
|
+
message: `Invalid ${attrName} value: "${value}". Expected "true" or "false".`,
|
|
555
|
+
element
|
|
556
|
+
});
|
|
557
|
+
return void 0;
|
|
558
|
+
}
|
|
559
|
+
function extractTriStateAttribute(element, attrName, warnings) {
|
|
560
|
+
const value = element.getAttribute(attrName);
|
|
561
|
+
if (value === null) {
|
|
562
|
+
return void 0;
|
|
563
|
+
}
|
|
564
|
+
const normalized = value.toLowerCase().trim();
|
|
565
|
+
if (normalized === "true") {
|
|
566
|
+
return true;
|
|
567
|
+
}
|
|
568
|
+
if (normalized === "false") {
|
|
569
|
+
return false;
|
|
570
|
+
}
|
|
571
|
+
if (normalized === "mixed") {
|
|
572
|
+
return "mixed";
|
|
573
|
+
}
|
|
574
|
+
warnings.push({
|
|
575
|
+
message: `Invalid ${attrName} value: "${value}". Expected "true", "false", or "mixed".`,
|
|
576
|
+
element
|
|
577
|
+
});
|
|
578
|
+
return void 0;
|
|
579
|
+
}
|
|
580
|
+
function extractCurrentAttribute(element, warnings) {
|
|
581
|
+
const value = element.getAttribute("aria-current");
|
|
582
|
+
if (value === null) {
|
|
583
|
+
return void 0;
|
|
584
|
+
}
|
|
585
|
+
const normalized = value.toLowerCase().trim();
|
|
586
|
+
const validValues = ["page", "step", "location", "date", "time", "true", "false"];
|
|
587
|
+
if (validValues.includes(normalized)) {
|
|
588
|
+
return normalized === "false" ? false : normalized;
|
|
589
|
+
}
|
|
590
|
+
warnings.push({
|
|
591
|
+
message: `Invalid aria-current value: "${value}". Expected one of: ${validValues.join(", ")}.`,
|
|
592
|
+
element
|
|
593
|
+
});
|
|
594
|
+
return void 0;
|
|
595
|
+
}
|
|
596
|
+
function extractLevelAttribute(element, warnings) {
|
|
597
|
+
const ariaLevel = element.getAttribute("aria-level");
|
|
598
|
+
if (ariaLevel !== null) {
|
|
599
|
+
const level = parseInt(ariaLevel, 10);
|
|
600
|
+
if (!isNaN(level) && level >= 1 && level <= 6) {
|
|
601
|
+
return level;
|
|
602
|
+
}
|
|
603
|
+
warnings.push({
|
|
604
|
+
message: `Invalid aria-level value: "${ariaLevel}". Expected integer 1-6.`,
|
|
605
|
+
element
|
|
606
|
+
});
|
|
607
|
+
return void 0;
|
|
608
|
+
}
|
|
609
|
+
const tagName = element.tagName.toLowerCase();
|
|
610
|
+
const match = tagName.match(/^h([1-6])$/);
|
|
611
|
+
if (match) {
|
|
612
|
+
return parseInt(match[1], 10);
|
|
613
|
+
}
|
|
614
|
+
return void 0;
|
|
615
|
+
}
|
|
616
|
+
function extractNumberAttribute(element, attrName, warnings) {
|
|
617
|
+
const value = element.getAttribute(attrName);
|
|
618
|
+
if (value === null) {
|
|
619
|
+
return void 0;
|
|
620
|
+
}
|
|
621
|
+
const num = parseInt(value, 10);
|
|
622
|
+
if (isNaN(num) || num < 1) {
|
|
623
|
+
warnings.push({
|
|
624
|
+
message: `Invalid ${attrName} value: "${value}". Expected positive integer.`,
|
|
625
|
+
element
|
|
626
|
+
});
|
|
627
|
+
return void 0;
|
|
628
|
+
}
|
|
629
|
+
return num;
|
|
630
|
+
}
|
|
631
|
+
function extractNativeStates(element, state, _warnings) {
|
|
632
|
+
const tagName = element.tagName.toLowerCase();
|
|
633
|
+
if (tagName === "input") {
|
|
634
|
+
const input = element;
|
|
635
|
+
const type = input.type.toLowerCase();
|
|
636
|
+
if (type === "checkbox" || type === "radio") {
|
|
637
|
+
if (state.checked === void 0) {
|
|
638
|
+
state.checked = input.checked;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
if ("disabled" in element) {
|
|
643
|
+
const htmlElement = element;
|
|
644
|
+
if (state.disabled === void 0 && htmlElement.disabled) {
|
|
645
|
+
state.disabled = true;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
if ("required" in element) {
|
|
649
|
+
const htmlElement = element;
|
|
650
|
+
if (state.required === void 0 && htmlElement.required) {
|
|
651
|
+
state.required = true;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
if ("readOnly" in element) {
|
|
655
|
+
const htmlElement = element;
|
|
656
|
+
if (state.readonly === void 0 && htmlElement.readOnly) {
|
|
657
|
+
state.readonly = true;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
function extractInputValue(input, warnings) {
|
|
662
|
+
const type = input.type.toLowerCase();
|
|
663
|
+
if (type === "checkbox" || type === "radio") {
|
|
664
|
+
return { value: void 0, warnings };
|
|
665
|
+
}
|
|
666
|
+
if (type === "button" || type === "submit" || type === "reset") {
|
|
667
|
+
return { value: void 0, warnings };
|
|
668
|
+
}
|
|
669
|
+
const value = input.value;
|
|
670
|
+
if (value) {
|
|
671
|
+
return {
|
|
672
|
+
value: {
|
|
673
|
+
current: value,
|
|
674
|
+
text: value
|
|
675
|
+
},
|
|
676
|
+
warnings
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
return { value: void 0, warnings };
|
|
680
|
+
}
|
|
681
|
+
function extractTextareaValue(textarea, warnings) {
|
|
682
|
+
const value = textarea.value;
|
|
683
|
+
if (value) {
|
|
684
|
+
return {
|
|
685
|
+
value: {
|
|
686
|
+
current: value,
|
|
687
|
+
text: value
|
|
688
|
+
},
|
|
689
|
+
warnings
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
return { value: void 0, warnings };
|
|
693
|
+
}
|
|
694
|
+
function extractSelectValue(select, warnings) {
|
|
695
|
+
const value = select.value;
|
|
696
|
+
const selectedOption = select.options[select.selectedIndex];
|
|
697
|
+
const text = selectedOption?.textContent || value;
|
|
698
|
+
if (value) {
|
|
699
|
+
return {
|
|
700
|
+
value: {
|
|
701
|
+
current: value,
|
|
702
|
+
text
|
|
703
|
+
},
|
|
704
|
+
warnings
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
return { value: void 0, warnings };
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
// ../src/extractor/focus-extractor.ts
|
|
711
|
+
var NATIVELY_FOCUSABLE_ELEMENTS = [
|
|
712
|
+
"a",
|
|
713
|
+
"button",
|
|
714
|
+
"input",
|
|
715
|
+
"select",
|
|
716
|
+
"textarea",
|
|
717
|
+
"area",
|
|
718
|
+
"iframe",
|
|
719
|
+
"object",
|
|
720
|
+
"embed",
|
|
721
|
+
"audio",
|
|
722
|
+
"video"
|
|
723
|
+
];
|
|
724
|
+
function extractFocusInfo(element) {
|
|
725
|
+
const tabindexAttr = element.getAttribute("tabindex");
|
|
726
|
+
const tabindex = tabindexAttr !== null ? parseInt(tabindexAttr, 10) : void 0;
|
|
727
|
+
const focusable = isFocusable(element, tabindex);
|
|
728
|
+
return {
|
|
729
|
+
focusable,
|
|
730
|
+
...tabindexAttr !== null && !isNaN(tabindex) && { tabindex }
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
function isFocusable(element, tabindex) {
|
|
734
|
+
const tagName = element.tagName.toLowerCase();
|
|
735
|
+
if (isDisabled(element)) {
|
|
736
|
+
return false;
|
|
737
|
+
}
|
|
738
|
+
if (tabindex !== void 0 && !isNaN(tabindex)) {
|
|
739
|
+
return true;
|
|
740
|
+
}
|
|
741
|
+
if (isNativelyFocusable(element, tagName)) {
|
|
742
|
+
return true;
|
|
743
|
+
}
|
|
744
|
+
return false;
|
|
745
|
+
}
|
|
746
|
+
function isNativelyFocusable(element, tagName) {
|
|
747
|
+
if (tagName === "a" || tagName === "area") {
|
|
748
|
+
return element.hasAttribute("href");
|
|
749
|
+
}
|
|
750
|
+
if (NATIVELY_FOCUSABLE_ELEMENTS.includes(tagName)) {
|
|
751
|
+
return true;
|
|
752
|
+
}
|
|
753
|
+
return false;
|
|
754
|
+
}
|
|
755
|
+
function isDisabled(element) {
|
|
756
|
+
if ("disabled" in element) {
|
|
757
|
+
const htmlElement = element;
|
|
758
|
+
if (htmlElement.disabled) {
|
|
759
|
+
return true;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
const ariaDisabled = element.getAttribute("aria-disabled");
|
|
763
|
+
if (ariaDisabled === "true") {
|
|
764
|
+
return true;
|
|
765
|
+
}
|
|
766
|
+
return false;
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
// ../src/extractor/tree-builder.ts
|
|
770
|
+
function isHidden(element) {
|
|
771
|
+
if (element.getAttribute("aria-hidden") === "true") return true;
|
|
772
|
+
if (typeof getComputedStyle === "function") {
|
|
773
|
+
try {
|
|
774
|
+
const style = getComputedStyle(element);
|
|
775
|
+
if (style.display === "none") return true;
|
|
776
|
+
if (style.visibility === "hidden") return true;
|
|
777
|
+
} catch {
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
return false;
|
|
781
|
+
}
|
|
782
|
+
function processChildNode(node, children, warnings) {
|
|
783
|
+
if (node.nodeType === 3) {
|
|
784
|
+
const text = (node.textContent || "").trim();
|
|
785
|
+
if (text.length > 0) {
|
|
786
|
+
children.push({
|
|
787
|
+
role: "staticText",
|
|
788
|
+
name: text,
|
|
789
|
+
state: {},
|
|
790
|
+
focus: { focusable: false },
|
|
791
|
+
children: []
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
if (node.nodeType === 1) {
|
|
797
|
+
const element = node;
|
|
798
|
+
if (isHidden(element)) return;
|
|
799
|
+
if (!isAccessible(element)) {
|
|
800
|
+
const grandchildren = collectChildrenFromRolelessElement(element, warnings);
|
|
801
|
+
children.push(...grandchildren);
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
const childNode = buildNodeRecursive(element, warnings);
|
|
805
|
+
if (childNode) children.push(childNode);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
function collectChildrenFromRolelessElement(element, warnings) {
|
|
809
|
+
const children = [];
|
|
810
|
+
if (element.shadowRoot) {
|
|
811
|
+
for (const child of Array.from(element.shadowRoot.childNodes)) {
|
|
812
|
+
processChildNode(child, children, warnings);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
for (const child of Array.from(element.childNodes)) {
|
|
816
|
+
processChildNode(child, children, warnings);
|
|
817
|
+
}
|
|
818
|
+
return children;
|
|
819
|
+
}
|
|
820
|
+
function buildAccessibilityTree(rootElement, sourceHash) {
|
|
821
|
+
const warnings = [];
|
|
822
|
+
if (isHidden(rootElement)) {
|
|
823
|
+
const model2 = {
|
|
824
|
+
version: CURRENT_MODEL_VERSION,
|
|
825
|
+
root: {
|
|
826
|
+
role: "generic",
|
|
827
|
+
name: "",
|
|
828
|
+
state: {},
|
|
829
|
+
focus: { focusable: false },
|
|
830
|
+
children: []
|
|
831
|
+
},
|
|
832
|
+
metadata: {
|
|
833
|
+
extractedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
834
|
+
...sourceHash && { sourceHash }
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
return { model: model2, warnings };
|
|
838
|
+
}
|
|
839
|
+
const rootNode = buildNodeRecursive(rootElement, warnings);
|
|
840
|
+
const accessibleRoot = rootNode || createGenericContainer(rootElement, warnings);
|
|
841
|
+
const model = {
|
|
842
|
+
version: CURRENT_MODEL_VERSION,
|
|
843
|
+
root: accessibleRoot,
|
|
844
|
+
metadata: {
|
|
845
|
+
extractedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
846
|
+
...sourceHash && { sourceHash }
|
|
847
|
+
}
|
|
848
|
+
};
|
|
849
|
+
return { model, warnings };
|
|
850
|
+
}
|
|
851
|
+
function buildNodeRecursive(element, warnings) {
|
|
852
|
+
if (isHidden(element)) {
|
|
853
|
+
return null;
|
|
854
|
+
}
|
|
855
|
+
if (!isAccessible(element)) {
|
|
856
|
+
return null;
|
|
857
|
+
}
|
|
858
|
+
const roleResult = computeRole(element);
|
|
859
|
+
warnings.push(...roleResult.warnings.map((w) => ({
|
|
860
|
+
message: w.message,
|
|
861
|
+
element: w.element
|
|
862
|
+
})));
|
|
863
|
+
if (!roleResult.role) {
|
|
864
|
+
return null;
|
|
865
|
+
}
|
|
866
|
+
const nameResult = computeAccessibleName(element);
|
|
867
|
+
warnings.push(...nameResult.warnings.map((w) => ({
|
|
868
|
+
message: w.message,
|
|
869
|
+
element: w.element
|
|
870
|
+
})));
|
|
871
|
+
const descResult = computeAccessibleDescription(element);
|
|
872
|
+
warnings.push(...descResult.warnings.map((w) => ({
|
|
873
|
+
message: w.message,
|
|
874
|
+
element: w.element
|
|
875
|
+
})));
|
|
876
|
+
const stateResult = extractState(element);
|
|
877
|
+
warnings.push(...stateResult.warnings.map((w) => ({
|
|
878
|
+
message: w.message,
|
|
879
|
+
element: w.element
|
|
880
|
+
})));
|
|
881
|
+
const valueResult = extractValue(element);
|
|
882
|
+
warnings.push(...valueResult.warnings.map((w) => ({
|
|
883
|
+
message: w.message,
|
|
884
|
+
element: w.element
|
|
885
|
+
})));
|
|
886
|
+
const focusInfo = extractFocusInfo(element);
|
|
887
|
+
const children = [];
|
|
888
|
+
if (element.shadowRoot) {
|
|
889
|
+
for (const child of Array.from(element.shadowRoot.childNodes)) {
|
|
890
|
+
processChildNode(child, children, warnings);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
for (const child of Array.from(element.childNodes)) {
|
|
894
|
+
processChildNode(child, children, warnings);
|
|
895
|
+
}
|
|
896
|
+
const node = {
|
|
897
|
+
role: roleResult.role,
|
|
898
|
+
name: nameResult.name,
|
|
899
|
+
...descResult.description && { description: descResult.description },
|
|
900
|
+
...valueResult.value && { value: valueResult.value },
|
|
901
|
+
state: stateResult.state,
|
|
902
|
+
focus: focusInfo,
|
|
903
|
+
children
|
|
904
|
+
};
|
|
905
|
+
return node;
|
|
906
|
+
}
|
|
907
|
+
function createGenericContainer(rootElement, warnings) {
|
|
908
|
+
const children = [];
|
|
909
|
+
if (rootElement.shadowRoot) {
|
|
910
|
+
for (const child of Array.from(rootElement.shadowRoot.childNodes)) {
|
|
911
|
+
processChildNode(child, children, warnings);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
for (const child of Array.from(rootElement.childNodes)) {
|
|
915
|
+
processChildNode(child, children, warnings);
|
|
916
|
+
}
|
|
917
|
+
return {
|
|
918
|
+
role: "generic",
|
|
919
|
+
name: "",
|
|
920
|
+
state: {},
|
|
921
|
+
focus: {
|
|
922
|
+
focusable: false
|
|
923
|
+
},
|
|
924
|
+
children
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
// ../src/cli/colors.ts
|
|
929
|
+
var import_picocolors = __toESM(require_picocolors_browser(), 1);
|
|
930
|
+
var identity = (s) => s;
|
|
931
|
+
function createColors(enabled) {
|
|
932
|
+
if (!enabled) {
|
|
933
|
+
return {
|
|
934
|
+
error: identity,
|
|
935
|
+
warning: identity,
|
|
936
|
+
info: identity,
|
|
937
|
+
success: identity,
|
|
938
|
+
heading: identity,
|
|
939
|
+
title: identity,
|
|
940
|
+
dim: identity,
|
|
941
|
+
roleName: identity,
|
|
942
|
+
stateName: identity,
|
|
943
|
+
elementName: identity,
|
|
944
|
+
sectionHeader: identity,
|
|
945
|
+
description: identity,
|
|
946
|
+
bold: identity,
|
|
947
|
+
enabled: false
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
return {
|
|
951
|
+
error: import_picocolors.default.red,
|
|
952
|
+
warning: import_picocolors.default.yellow,
|
|
953
|
+
info: import_picocolors.default.blue,
|
|
954
|
+
success: import_picocolors.default.green,
|
|
955
|
+
heading: (s) => import_picocolors.default.bold(import_picocolors.default.cyan(s)),
|
|
956
|
+
title: (s) => import_picocolors.default.bold(import_picocolors.default.cyan(s)),
|
|
957
|
+
dim: import_picocolors.default.dim,
|
|
958
|
+
roleName: import_picocolors.default.cyan,
|
|
959
|
+
stateName: import_picocolors.default.yellow,
|
|
960
|
+
elementName: (s) => import_picocolors.default.bold(import_picocolors.default.white(s)),
|
|
961
|
+
sectionHeader: (s) => import_picocolors.default.bold(import_picocolors.default.white(s)),
|
|
962
|
+
description: import_picocolors.default.dim,
|
|
963
|
+
bold: import_picocolors.default.bold,
|
|
964
|
+
enabled: true
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
// ../src/renderer/nvda-renderer.ts
|
|
969
|
+
function renderNVDA(model, colorize) {
|
|
970
|
+
const c = createColors(colorize ?? false);
|
|
971
|
+
const announcements = [];
|
|
972
|
+
renderNodeNVDA(model.root, announcements, c);
|
|
973
|
+
return announcements.join("\n");
|
|
974
|
+
}
|
|
975
|
+
function renderNodeNVDA(node, announcements, c) {
|
|
976
|
+
const announcement = formatNodeNVDA(node, c);
|
|
977
|
+
if (announcement) {
|
|
978
|
+
announcements.push(announcement);
|
|
979
|
+
}
|
|
980
|
+
for (const child of node.children) {
|
|
981
|
+
if (child.name && child.name === node.name && node.children.length === 1) {
|
|
982
|
+
for (const grandchild of child.children) {
|
|
983
|
+
renderNodeNVDA(grandchild, announcements, c);
|
|
984
|
+
}
|
|
985
|
+
continue;
|
|
986
|
+
}
|
|
987
|
+
renderNodeNVDA(child, announcements, c);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
function formatNodeNVDA(node, c) {
|
|
991
|
+
const parts = [];
|
|
992
|
+
if (node.name) {
|
|
993
|
+
parts.push(c.elementName(node.name));
|
|
994
|
+
}
|
|
995
|
+
const roleText = formatRoleNVDA(node);
|
|
996
|
+
if (roleText) {
|
|
997
|
+
parts.push(c.roleName(roleText));
|
|
998
|
+
}
|
|
999
|
+
const stateText = formatStatesNVDA(node);
|
|
1000
|
+
if (stateText) {
|
|
1001
|
+
parts.push(c.stateName(stateText));
|
|
1002
|
+
}
|
|
1003
|
+
if (node.value) {
|
|
1004
|
+
const valueText = node.value.text || String(node.value.current);
|
|
1005
|
+
if (valueText) {
|
|
1006
|
+
parts.push(valueText);
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
if (node.description) {
|
|
1010
|
+
parts.push(c.description(node.description));
|
|
1011
|
+
}
|
|
1012
|
+
return parts.join(", ");
|
|
1013
|
+
}
|
|
1014
|
+
function formatRoleNVDA(node) {
|
|
1015
|
+
const role = node.role;
|
|
1016
|
+
switch (role) {
|
|
1017
|
+
case "button":
|
|
1018
|
+
return "button";
|
|
1019
|
+
case "link":
|
|
1020
|
+
return "link";
|
|
1021
|
+
case "heading":
|
|
1022
|
+
if (node.state.level) {
|
|
1023
|
+
return `heading level ${node.state.level}`;
|
|
1024
|
+
}
|
|
1025
|
+
return "heading";
|
|
1026
|
+
case "textbox":
|
|
1027
|
+
return "edit";
|
|
1028
|
+
case "checkbox":
|
|
1029
|
+
return "checkbox";
|
|
1030
|
+
case "radio":
|
|
1031
|
+
return "radio button";
|
|
1032
|
+
case "combobox":
|
|
1033
|
+
return "combo box";
|
|
1034
|
+
case "listbox":
|
|
1035
|
+
return "list box";
|
|
1036
|
+
case "option":
|
|
1037
|
+
return "option";
|
|
1038
|
+
case "list":
|
|
1039
|
+
return "list";
|
|
1040
|
+
case "listitem":
|
|
1041
|
+
return "list item";
|
|
1042
|
+
case "navigation":
|
|
1043
|
+
return "navigation landmark";
|
|
1044
|
+
case "main":
|
|
1045
|
+
return "main landmark";
|
|
1046
|
+
case "banner":
|
|
1047
|
+
return "banner landmark";
|
|
1048
|
+
case "contentinfo":
|
|
1049
|
+
return "content information landmark";
|
|
1050
|
+
case "region":
|
|
1051
|
+
return "region landmark";
|
|
1052
|
+
case "complementary":
|
|
1053
|
+
return "complementary landmark";
|
|
1054
|
+
case "form":
|
|
1055
|
+
return "form landmark";
|
|
1056
|
+
case "search":
|
|
1057
|
+
return "search landmark";
|
|
1058
|
+
case "img":
|
|
1059
|
+
return "graphic";
|
|
1060
|
+
case "article":
|
|
1061
|
+
return "article";
|
|
1062
|
+
case "generic":
|
|
1063
|
+
return "";
|
|
1064
|
+
case "staticText":
|
|
1065
|
+
case "paragraph":
|
|
1066
|
+
case "cell":
|
|
1067
|
+
case "term":
|
|
1068
|
+
case "definition":
|
|
1069
|
+
case "caption":
|
|
1070
|
+
return "";
|
|
1071
|
+
case "blockquote":
|
|
1072
|
+
return "block quote";
|
|
1073
|
+
case "code":
|
|
1074
|
+
return "code";
|
|
1075
|
+
case "table":
|
|
1076
|
+
return "table";
|
|
1077
|
+
case "row":
|
|
1078
|
+
return "row";
|
|
1079
|
+
case "columnheader":
|
|
1080
|
+
return "column header";
|
|
1081
|
+
case "rowheader":
|
|
1082
|
+
return "row header";
|
|
1083
|
+
case "figure":
|
|
1084
|
+
return "figure";
|
|
1085
|
+
case "dialog":
|
|
1086
|
+
return "dialog";
|
|
1087
|
+
case "meter":
|
|
1088
|
+
return "meter";
|
|
1089
|
+
case "progressbar":
|
|
1090
|
+
return "progress bar";
|
|
1091
|
+
case "status":
|
|
1092
|
+
return "status";
|
|
1093
|
+
case "group":
|
|
1094
|
+
return node.name ? "grouping" : "";
|
|
1095
|
+
case "document":
|
|
1096
|
+
return "document";
|
|
1097
|
+
case "application":
|
|
1098
|
+
return "embedded object";
|
|
1099
|
+
case "separator":
|
|
1100
|
+
return "separator";
|
|
1101
|
+
default:
|
|
1102
|
+
return role;
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
function formatStatesNVDA(node) {
|
|
1106
|
+
const states = [];
|
|
1107
|
+
if (node.state.expanded !== void 0) {
|
|
1108
|
+
states.push(node.state.expanded ? "expanded" : "collapsed");
|
|
1109
|
+
}
|
|
1110
|
+
if (node.state.checked !== void 0) {
|
|
1111
|
+
if (node.state.checked === "mixed") {
|
|
1112
|
+
states.push("half checked");
|
|
1113
|
+
} else {
|
|
1114
|
+
states.push(node.state.checked ? "checked" : "not checked");
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
if (node.state.pressed !== void 0) {
|
|
1118
|
+
if (node.state.pressed === "mixed") {
|
|
1119
|
+
states.push("half pressed");
|
|
1120
|
+
} else {
|
|
1121
|
+
states.push(node.state.pressed ? "pressed" : "not pressed");
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
if (node.state.selected !== void 0) {
|
|
1125
|
+
states.push(node.state.selected ? "selected" : "not selected");
|
|
1126
|
+
}
|
|
1127
|
+
if (node.state.disabled) {
|
|
1128
|
+
states.push("unavailable");
|
|
1129
|
+
}
|
|
1130
|
+
if (node.state.invalid) {
|
|
1131
|
+
states.push("invalid entry");
|
|
1132
|
+
}
|
|
1133
|
+
if (node.state.required) {
|
|
1134
|
+
states.push("required");
|
|
1135
|
+
}
|
|
1136
|
+
if (node.state.readonly) {
|
|
1137
|
+
states.push("read only");
|
|
1138
|
+
}
|
|
1139
|
+
if (node.state.busy) {
|
|
1140
|
+
states.push("busy");
|
|
1141
|
+
}
|
|
1142
|
+
if (node.state.current) {
|
|
1143
|
+
if (node.state.current === "page") {
|
|
1144
|
+
states.push("current page");
|
|
1145
|
+
} else if (node.state.current === "step") {
|
|
1146
|
+
states.push("current step");
|
|
1147
|
+
} else if (node.state.current === "location") {
|
|
1148
|
+
states.push("current location");
|
|
1149
|
+
} else if (node.state.current === "date") {
|
|
1150
|
+
states.push("current date");
|
|
1151
|
+
} else if (node.state.current === "time") {
|
|
1152
|
+
states.push("current time");
|
|
1153
|
+
} else if (node.state.current === "true") {
|
|
1154
|
+
states.push("current");
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
if (node.state.grabbed !== void 0) {
|
|
1158
|
+
states.push(node.state.grabbed ? "grabbed" : "not grabbed");
|
|
1159
|
+
}
|
|
1160
|
+
return states.join(", ");
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
// ../src/renderer/jaws-renderer.ts
|
|
1164
|
+
function renderJAWS(model, colorize) {
|
|
1165
|
+
const c = createColors(colorize ?? false);
|
|
1166
|
+
const announcements = [];
|
|
1167
|
+
renderNodeJAWS(model.root, announcements, c);
|
|
1168
|
+
return announcements.join("\n");
|
|
1169
|
+
}
|
|
1170
|
+
function renderNodeJAWS(node, announcements, c) {
|
|
1171
|
+
const announcement = formatNodeJAWS(node, c);
|
|
1172
|
+
if (announcement) {
|
|
1173
|
+
announcements.push(announcement);
|
|
1174
|
+
}
|
|
1175
|
+
for (const child of node.children) {
|
|
1176
|
+
if (child.name && child.name === node.name && node.children.length === 1) {
|
|
1177
|
+
for (const grandchild of child.children) {
|
|
1178
|
+
renderNodeJAWS(grandchild, announcements, c);
|
|
1179
|
+
}
|
|
1180
|
+
continue;
|
|
1181
|
+
}
|
|
1182
|
+
renderNodeJAWS(child, announcements, c);
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
function formatNodeJAWS(node, c) {
|
|
1186
|
+
const parts = [];
|
|
1187
|
+
if (node.name) {
|
|
1188
|
+
parts.push(c.elementName(node.name));
|
|
1189
|
+
}
|
|
1190
|
+
const roleText = formatRoleJAWS(node);
|
|
1191
|
+
if (roleText) {
|
|
1192
|
+
parts.push(c.roleName(roleText));
|
|
1193
|
+
}
|
|
1194
|
+
const stateText = formatStatesJAWS(node);
|
|
1195
|
+
if (stateText) {
|
|
1196
|
+
parts.push(c.stateName(stateText));
|
|
1197
|
+
}
|
|
1198
|
+
if (node.value) {
|
|
1199
|
+
const valueText = node.value.text || String(node.value.current);
|
|
1200
|
+
if (valueText) {
|
|
1201
|
+
parts.push(valueText);
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
if (node.description) {
|
|
1205
|
+
parts.push(c.description(node.description));
|
|
1206
|
+
}
|
|
1207
|
+
return parts.join(", ");
|
|
1208
|
+
}
|
|
1209
|
+
function formatRoleJAWS(node) {
|
|
1210
|
+
const role = node.role;
|
|
1211
|
+
switch (role) {
|
|
1212
|
+
case "button":
|
|
1213
|
+
return "button";
|
|
1214
|
+
case "link":
|
|
1215
|
+
return "clickable";
|
|
1216
|
+
case "heading":
|
|
1217
|
+
if (node.state.level) {
|
|
1218
|
+
return `heading ${node.state.level}`;
|
|
1219
|
+
}
|
|
1220
|
+
return "heading";
|
|
1221
|
+
case "textbox":
|
|
1222
|
+
return "edit";
|
|
1223
|
+
case "checkbox":
|
|
1224
|
+
return "check box";
|
|
1225
|
+
case "radio":
|
|
1226
|
+
return "radio button";
|
|
1227
|
+
case "combobox":
|
|
1228
|
+
return "combo box";
|
|
1229
|
+
case "listbox":
|
|
1230
|
+
return "list box";
|
|
1231
|
+
case "option":
|
|
1232
|
+
return "option";
|
|
1233
|
+
case "list":
|
|
1234
|
+
return "list";
|
|
1235
|
+
case "listitem":
|
|
1236
|
+
return "list item";
|
|
1237
|
+
case "navigation":
|
|
1238
|
+
return "navigation region";
|
|
1239
|
+
case "main":
|
|
1240
|
+
return "main region";
|
|
1241
|
+
case "banner":
|
|
1242
|
+
return "banner region";
|
|
1243
|
+
case "contentinfo":
|
|
1244
|
+
return "content information region";
|
|
1245
|
+
case "region":
|
|
1246
|
+
return "region";
|
|
1247
|
+
case "img":
|
|
1248
|
+
return "graphic";
|
|
1249
|
+
case "article":
|
|
1250
|
+
return "article";
|
|
1251
|
+
case "complementary":
|
|
1252
|
+
return "complementary region";
|
|
1253
|
+
case "form":
|
|
1254
|
+
return "form";
|
|
1255
|
+
case "search":
|
|
1256
|
+
return "search region";
|
|
1257
|
+
case "generic":
|
|
1258
|
+
return "";
|
|
1259
|
+
case "staticText":
|
|
1260
|
+
case "paragraph":
|
|
1261
|
+
case "term":
|
|
1262
|
+
case "definition":
|
|
1263
|
+
case "caption":
|
|
1264
|
+
return "";
|
|
1265
|
+
case "blockquote":
|
|
1266
|
+
return "block quote";
|
|
1267
|
+
case "code":
|
|
1268
|
+
return "code";
|
|
1269
|
+
case "table": {
|
|
1270
|
+
const rows = node.children.filter((c) => c.role === "row");
|
|
1271
|
+
const rowCount = rows.length;
|
|
1272
|
+
const colCount = rows.length > 0 ? rows[0].children.length : 0;
|
|
1273
|
+
return `table with ${rowCount} rows and ${colCount} columns`;
|
|
1274
|
+
}
|
|
1275
|
+
case "row": {
|
|
1276
|
+
const pos = node.state.posinset ?? 0;
|
|
1277
|
+
return `row ${pos}`;
|
|
1278
|
+
}
|
|
1279
|
+
case "cell": {
|
|
1280
|
+
const pos = node.state.posinset ?? 0;
|
|
1281
|
+
return `column ${pos}`;
|
|
1282
|
+
}
|
|
1283
|
+
case "columnheader":
|
|
1284
|
+
return "column header";
|
|
1285
|
+
case "rowheader":
|
|
1286
|
+
return "row header";
|
|
1287
|
+
case "figure":
|
|
1288
|
+
return "figure";
|
|
1289
|
+
case "dialog":
|
|
1290
|
+
return "dialog";
|
|
1291
|
+
case "meter":
|
|
1292
|
+
return "meter";
|
|
1293
|
+
case "progressbar":
|
|
1294
|
+
return "progress bar";
|
|
1295
|
+
case "status":
|
|
1296
|
+
return "status";
|
|
1297
|
+
case "group":
|
|
1298
|
+
return node.name ? "group" : "";
|
|
1299
|
+
case "document":
|
|
1300
|
+
return "frame";
|
|
1301
|
+
case "application":
|
|
1302
|
+
return "embedded object";
|
|
1303
|
+
case "separator":
|
|
1304
|
+
return "separator";
|
|
1305
|
+
default:
|
|
1306
|
+
return role;
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
function formatStatesJAWS(node) {
|
|
1310
|
+
const states = [];
|
|
1311
|
+
if (node.state.expanded !== void 0) {
|
|
1312
|
+
states.push(node.state.expanded ? "expanded" : "collapsed");
|
|
1313
|
+
}
|
|
1314
|
+
if (node.state.checked !== void 0) {
|
|
1315
|
+
if (node.state.checked === "mixed") {
|
|
1316
|
+
states.push("partially checked");
|
|
1317
|
+
} else if (node.state.checked) {
|
|
1318
|
+
states.push("checked");
|
|
1319
|
+
} else {
|
|
1320
|
+
states.push("not checked");
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
if (node.state.pressed !== void 0) {
|
|
1324
|
+
if (node.state.pressed === "mixed") {
|
|
1325
|
+
states.push("partially pressed");
|
|
1326
|
+
} else if (node.state.pressed) {
|
|
1327
|
+
states.push("pressed");
|
|
1328
|
+
} else {
|
|
1329
|
+
states.push("not pressed");
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
if (node.state.selected !== void 0) {
|
|
1333
|
+
states.push(node.state.selected ? "selected" : "not selected");
|
|
1334
|
+
}
|
|
1335
|
+
if (node.state.disabled) {
|
|
1336
|
+
states.push("unavailable");
|
|
1337
|
+
}
|
|
1338
|
+
if (node.state.invalid) {
|
|
1339
|
+
states.push("invalid entry");
|
|
1340
|
+
}
|
|
1341
|
+
if (node.state.required) {
|
|
1342
|
+
states.push("required");
|
|
1343
|
+
}
|
|
1344
|
+
if (node.state.readonly) {
|
|
1345
|
+
states.push("read only");
|
|
1346
|
+
}
|
|
1347
|
+
if (node.state.busy) {
|
|
1348
|
+
states.push("busy");
|
|
1349
|
+
}
|
|
1350
|
+
if (node.state.current) {
|
|
1351
|
+
switch (node.state.current) {
|
|
1352
|
+
case "page":
|
|
1353
|
+
states.push("current page");
|
|
1354
|
+
break;
|
|
1355
|
+
case "step":
|
|
1356
|
+
states.push("current step");
|
|
1357
|
+
break;
|
|
1358
|
+
case "location":
|
|
1359
|
+
states.push("current location");
|
|
1360
|
+
break;
|
|
1361
|
+
case "date":
|
|
1362
|
+
states.push("current date");
|
|
1363
|
+
break;
|
|
1364
|
+
case "time":
|
|
1365
|
+
states.push("current time");
|
|
1366
|
+
break;
|
|
1367
|
+
case "true":
|
|
1368
|
+
states.push("current");
|
|
1369
|
+
break;
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
if (node.state.grabbed !== void 0) {
|
|
1373
|
+
states.push(node.state.grabbed ? "grabbed" : "not grabbed");
|
|
1374
|
+
}
|
|
1375
|
+
return states.join(", ");
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
// ../src/renderer/voiceover-renderer.ts
|
|
1379
|
+
function renderVoiceOver(model, colorize) {
|
|
1380
|
+
const c = createColors(colorize ?? false);
|
|
1381
|
+
const announcements = [];
|
|
1382
|
+
renderNodeVoiceOver(model.root, announcements, c);
|
|
1383
|
+
return announcements.join("\n");
|
|
1384
|
+
}
|
|
1385
|
+
function renderNodeVoiceOver(node, announcements, c) {
|
|
1386
|
+
const announcement = formatNodeVoiceOver(node, c);
|
|
1387
|
+
if (announcement) {
|
|
1388
|
+
announcements.push(announcement);
|
|
1389
|
+
}
|
|
1390
|
+
for (const child of node.children) {
|
|
1391
|
+
if (child.name && child.name === node.name && node.children.length === 1) {
|
|
1392
|
+
for (const grandchild of child.children) {
|
|
1393
|
+
renderNodeVoiceOver(grandchild, announcements, c);
|
|
1394
|
+
}
|
|
1395
|
+
continue;
|
|
1396
|
+
}
|
|
1397
|
+
renderNodeVoiceOver(child, announcements, c);
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
function formatNodeVoiceOver(node, c) {
|
|
1401
|
+
const parts = [];
|
|
1402
|
+
const roleFirst = shouldAnnounceRoleFirst(node.role);
|
|
1403
|
+
if (roleFirst) {
|
|
1404
|
+
const roleText = formatRoleVoiceOver(node);
|
|
1405
|
+
if (roleText) {
|
|
1406
|
+
parts.push(c.roleName(roleText));
|
|
1407
|
+
}
|
|
1408
|
+
if (node.name) {
|
|
1409
|
+
parts.push(c.elementName(node.name));
|
|
1410
|
+
}
|
|
1411
|
+
} else {
|
|
1412
|
+
if (node.name) {
|
|
1413
|
+
parts.push(c.elementName(node.name));
|
|
1414
|
+
}
|
|
1415
|
+
const roleText = formatRoleVoiceOver(node);
|
|
1416
|
+
if (roleText) {
|
|
1417
|
+
parts.push(c.roleName(roleText));
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
const stateText = formatStatesVoiceOver(node);
|
|
1421
|
+
if (stateText) {
|
|
1422
|
+
parts.push(c.stateName(stateText));
|
|
1423
|
+
}
|
|
1424
|
+
if (node.value) {
|
|
1425
|
+
const valueText = node.value.text || String(node.value.current);
|
|
1426
|
+
if (valueText) {
|
|
1427
|
+
parts.push(valueText);
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
if (node.description) {
|
|
1431
|
+
parts.push(c.description(node.description));
|
|
1432
|
+
}
|
|
1433
|
+
return parts.join(", ");
|
|
1434
|
+
}
|
|
1435
|
+
function shouldAnnounceRoleFirst(role) {
|
|
1436
|
+
return role === "heading" || role === "navigation" || role === "main" || role === "banner" || role === "contentinfo" || role === "complementary" || role === "region" || role === "form" || role === "search" || role === "blockquote" || role === "figure" || role === "dialog" || role === "group" || role === "document";
|
|
1437
|
+
}
|
|
1438
|
+
function formatRoleVoiceOver(node) {
|
|
1439
|
+
const role = node.role;
|
|
1440
|
+
switch (role) {
|
|
1441
|
+
case "button":
|
|
1442
|
+
return "button";
|
|
1443
|
+
case "link":
|
|
1444
|
+
return "link";
|
|
1445
|
+
case "heading":
|
|
1446
|
+
if (node.state.level) {
|
|
1447
|
+
return `heading level ${node.state.level}`;
|
|
1448
|
+
}
|
|
1449
|
+
return "heading";
|
|
1450
|
+
case "textbox":
|
|
1451
|
+
return "edit text";
|
|
1452
|
+
case "checkbox":
|
|
1453
|
+
return "checkbox";
|
|
1454
|
+
case "radio":
|
|
1455
|
+
return "radio button";
|
|
1456
|
+
case "combobox":
|
|
1457
|
+
return "combo box";
|
|
1458
|
+
case "listbox":
|
|
1459
|
+
return "list box";
|
|
1460
|
+
case "option":
|
|
1461
|
+
return "option";
|
|
1462
|
+
case "list":
|
|
1463
|
+
return "list";
|
|
1464
|
+
case "listitem":
|
|
1465
|
+
return "item";
|
|
1466
|
+
case "navigation":
|
|
1467
|
+
return "navigation";
|
|
1468
|
+
case "main":
|
|
1469
|
+
return "main";
|
|
1470
|
+
case "banner":
|
|
1471
|
+
return "banner";
|
|
1472
|
+
case "contentinfo":
|
|
1473
|
+
return "content information";
|
|
1474
|
+
case "region":
|
|
1475
|
+
return "region";
|
|
1476
|
+
case "complementary":
|
|
1477
|
+
return "complementary";
|
|
1478
|
+
case "form":
|
|
1479
|
+
return "form";
|
|
1480
|
+
case "search":
|
|
1481
|
+
return "search";
|
|
1482
|
+
case "img":
|
|
1483
|
+
return "image";
|
|
1484
|
+
case "article":
|
|
1485
|
+
return "article";
|
|
1486
|
+
case "generic":
|
|
1487
|
+
return "";
|
|
1488
|
+
case "staticText":
|
|
1489
|
+
case "paragraph":
|
|
1490
|
+
case "cell":
|
|
1491
|
+
case "term":
|
|
1492
|
+
case "definition":
|
|
1493
|
+
case "caption":
|
|
1494
|
+
return "";
|
|
1495
|
+
case "blockquote":
|
|
1496
|
+
return "blockquote";
|
|
1497
|
+
case "code":
|
|
1498
|
+
return "code";
|
|
1499
|
+
case "table": {
|
|
1500
|
+
const rows = node.children.filter((c) => c.role === "row");
|
|
1501
|
+
const rowCount = rows.length;
|
|
1502
|
+
const colCount = rows.length > 0 ? rows[0].children.length : 0;
|
|
1503
|
+
return `table, ${rowCount} rows, ${colCount} columns`;
|
|
1504
|
+
}
|
|
1505
|
+
case "row":
|
|
1506
|
+
return "row";
|
|
1507
|
+
case "columnheader":
|
|
1508
|
+
return "column header";
|
|
1509
|
+
case "rowheader":
|
|
1510
|
+
return "row header";
|
|
1511
|
+
case "figure":
|
|
1512
|
+
return "figure";
|
|
1513
|
+
case "dialog":
|
|
1514
|
+
return "web dialog";
|
|
1515
|
+
case "meter":
|
|
1516
|
+
return "level indicator";
|
|
1517
|
+
case "progressbar":
|
|
1518
|
+
return "progress indicator";
|
|
1519
|
+
case "status":
|
|
1520
|
+
return "status";
|
|
1521
|
+
case "group":
|
|
1522
|
+
return node.name ? "group" : "";
|
|
1523
|
+
case "document":
|
|
1524
|
+
return "frame";
|
|
1525
|
+
case "application":
|
|
1526
|
+
return "embedded object";
|
|
1527
|
+
case "separator":
|
|
1528
|
+
return "separator";
|
|
1529
|
+
default:
|
|
1530
|
+
return role;
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
function formatStatesVoiceOver(node) {
|
|
1534
|
+
const states = [];
|
|
1535
|
+
if (node.state.expanded !== void 0) {
|
|
1536
|
+
states.push(node.state.expanded ? "expanded" : "collapsed");
|
|
1537
|
+
}
|
|
1538
|
+
if (node.state.checked !== void 0) {
|
|
1539
|
+
if (node.state.checked === "mixed") {
|
|
1540
|
+
states.push("mixed");
|
|
1541
|
+
} else {
|
|
1542
|
+
states.push(node.state.checked ? "checked" : "unchecked");
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
if (node.state.pressed !== void 0) {
|
|
1546
|
+
if (node.state.pressed === "mixed") {
|
|
1547
|
+
states.push("mixed");
|
|
1548
|
+
} else {
|
|
1549
|
+
states.push(node.state.pressed ? "pressed" : "not pressed");
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
if (node.state.selected !== void 0) {
|
|
1553
|
+
states.push(node.state.selected ? "selected" : "unselected");
|
|
1554
|
+
}
|
|
1555
|
+
if (node.state.disabled) {
|
|
1556
|
+
states.push("dimmed");
|
|
1557
|
+
}
|
|
1558
|
+
if (node.state.invalid) {
|
|
1559
|
+
states.push("invalid data");
|
|
1560
|
+
}
|
|
1561
|
+
if (node.state.required) {
|
|
1562
|
+
states.push("required");
|
|
1563
|
+
}
|
|
1564
|
+
if (node.state.readonly) {
|
|
1565
|
+
states.push("read only");
|
|
1566
|
+
}
|
|
1567
|
+
if (node.state.busy) {
|
|
1568
|
+
states.push("busy");
|
|
1569
|
+
}
|
|
1570
|
+
if (node.state.current) {
|
|
1571
|
+
if (node.state.current === "page") {
|
|
1572
|
+
states.push("current page");
|
|
1573
|
+
} else if (node.state.current === "step") {
|
|
1574
|
+
states.push("current step");
|
|
1575
|
+
} else if (node.state.current === "location") {
|
|
1576
|
+
states.push("current location");
|
|
1577
|
+
} else if (node.state.current === "date") {
|
|
1578
|
+
states.push("current date");
|
|
1579
|
+
} else if (node.state.current === "time") {
|
|
1580
|
+
states.push("current time");
|
|
1581
|
+
} else if (node.state.current === "true") {
|
|
1582
|
+
states.push("current");
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
if (node.state.grabbed !== void 0) {
|
|
1586
|
+
states.push(node.state.grabbed ? "grabbed" : "not grabbed");
|
|
1587
|
+
}
|
|
1588
|
+
return states.join(", ");
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
// ../src/renderer/narrator-renderer.ts
|
|
1592
|
+
function renderNarrator(model, colorize) {
|
|
1593
|
+
const c = createColors(colorize ?? false);
|
|
1594
|
+
const announcements = [];
|
|
1595
|
+
renderNodeNarrator(model.root, announcements, c);
|
|
1596
|
+
return announcements.join("\n");
|
|
1597
|
+
}
|
|
1598
|
+
function renderNodeNarrator(node, announcements, c) {
|
|
1599
|
+
const announcement = formatNodeNarrator(node, c);
|
|
1600
|
+
if (announcement) {
|
|
1601
|
+
announcements.push(announcement);
|
|
1602
|
+
}
|
|
1603
|
+
for (const child of node.children) {
|
|
1604
|
+
if (child.name && child.name === node.name && node.children.length === 1) {
|
|
1605
|
+
for (const grandchild of child.children) {
|
|
1606
|
+
renderNodeNarrator(grandchild, announcements, c);
|
|
1607
|
+
}
|
|
1608
|
+
continue;
|
|
1609
|
+
}
|
|
1610
|
+
renderNodeNarrator(child, announcements, c);
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
function formatNodeNarrator(node, c) {
|
|
1614
|
+
const parts = [];
|
|
1615
|
+
const roleFirst = shouldAnnounceRoleFirst2(node.role);
|
|
1616
|
+
if (roleFirst) {
|
|
1617
|
+
const roleText = formatRoleNarrator(node);
|
|
1618
|
+
if (roleText) {
|
|
1619
|
+
parts.push(c.roleName(roleText));
|
|
1620
|
+
}
|
|
1621
|
+
if (node.name) {
|
|
1622
|
+
parts.push(c.elementName(node.name));
|
|
1623
|
+
}
|
|
1624
|
+
} else {
|
|
1625
|
+
if (node.name) {
|
|
1626
|
+
parts.push(c.elementName(node.name));
|
|
1627
|
+
}
|
|
1628
|
+
const roleText = formatRoleNarrator(node);
|
|
1629
|
+
if (roleText) {
|
|
1630
|
+
parts.push(c.roleName(roleText));
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
const stateText = formatStatesNarrator(node);
|
|
1634
|
+
if (stateText) {
|
|
1635
|
+
parts.push(c.stateName(stateText));
|
|
1636
|
+
}
|
|
1637
|
+
if (node.value) {
|
|
1638
|
+
const valueText = node.value.text || String(node.value.current);
|
|
1639
|
+
if (valueText) {
|
|
1640
|
+
parts.push(valueText);
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
if (node.description) {
|
|
1644
|
+
parts.push(c.description(node.description));
|
|
1645
|
+
}
|
|
1646
|
+
return parts.join(", ");
|
|
1647
|
+
}
|
|
1648
|
+
function shouldAnnounceRoleFirst2(role) {
|
|
1649
|
+
const roleFirstRoles = [
|
|
1650
|
+
"link",
|
|
1651
|
+
"heading",
|
|
1652
|
+
"navigation",
|
|
1653
|
+
"main",
|
|
1654
|
+
"banner",
|
|
1655
|
+
"contentinfo",
|
|
1656
|
+
"complementary",
|
|
1657
|
+
"region",
|
|
1658
|
+
"form",
|
|
1659
|
+
"search",
|
|
1660
|
+
"blockquote",
|
|
1661
|
+
"figure",
|
|
1662
|
+
"dialog",
|
|
1663
|
+
"group",
|
|
1664
|
+
"document"
|
|
1665
|
+
];
|
|
1666
|
+
return roleFirstRoles.includes(role);
|
|
1667
|
+
}
|
|
1668
|
+
function formatRoleNarrator(node) {
|
|
1669
|
+
const role = node.role;
|
|
1670
|
+
switch (role) {
|
|
1671
|
+
case "button":
|
|
1672
|
+
return "button";
|
|
1673
|
+
case "link":
|
|
1674
|
+
return "link";
|
|
1675
|
+
case "heading":
|
|
1676
|
+
if (node.state.level) {
|
|
1677
|
+
return `Heading level ${node.state.level}`;
|
|
1678
|
+
}
|
|
1679
|
+
return "Heading";
|
|
1680
|
+
case "textbox":
|
|
1681
|
+
return "edit";
|
|
1682
|
+
case "checkbox":
|
|
1683
|
+
return "check box";
|
|
1684
|
+
case "radio":
|
|
1685
|
+
return "radio button";
|
|
1686
|
+
case "combobox":
|
|
1687
|
+
return "combo box";
|
|
1688
|
+
case "listbox":
|
|
1689
|
+
return "list box";
|
|
1690
|
+
case "option":
|
|
1691
|
+
return "option";
|
|
1692
|
+
case "list":
|
|
1693
|
+
return "list";
|
|
1694
|
+
case "listitem":
|
|
1695
|
+
return "list item";
|
|
1696
|
+
case "navigation":
|
|
1697
|
+
return "navigation";
|
|
1698
|
+
case "main":
|
|
1699
|
+
return "main";
|
|
1700
|
+
case "banner":
|
|
1701
|
+
return "banner";
|
|
1702
|
+
case "contentinfo":
|
|
1703
|
+
return "content info";
|
|
1704
|
+
case "complementary":
|
|
1705
|
+
return "complementary";
|
|
1706
|
+
case "form":
|
|
1707
|
+
return "form";
|
|
1708
|
+
case "search":
|
|
1709
|
+
return "search";
|
|
1710
|
+
case "region":
|
|
1711
|
+
return "region";
|
|
1712
|
+
case "img":
|
|
1713
|
+
return "image";
|
|
1714
|
+
case "article":
|
|
1715
|
+
return "article";
|
|
1716
|
+
case "generic":
|
|
1717
|
+
return "";
|
|
1718
|
+
case "staticText":
|
|
1719
|
+
case "paragraph":
|
|
1720
|
+
case "cell":
|
|
1721
|
+
case "term":
|
|
1722
|
+
case "definition":
|
|
1723
|
+
case "caption":
|
|
1724
|
+
return "";
|
|
1725
|
+
case "blockquote":
|
|
1726
|
+
return "block quote";
|
|
1727
|
+
case "code":
|
|
1728
|
+
return "code";
|
|
1729
|
+
case "table": {
|
|
1730
|
+
const rows = node.children.filter((c) => c.role === "row");
|
|
1731
|
+
const rowCount = rows.length;
|
|
1732
|
+
const colCount = rows.length > 0 ? rows[0].children.length : 0;
|
|
1733
|
+
return `table, ${rowCount} rows, ${colCount} columns`;
|
|
1734
|
+
}
|
|
1735
|
+
case "row":
|
|
1736
|
+
return "row";
|
|
1737
|
+
case "columnheader":
|
|
1738
|
+
return "column header";
|
|
1739
|
+
case "rowheader":
|
|
1740
|
+
return "row header";
|
|
1741
|
+
case "figure":
|
|
1742
|
+
return "figure";
|
|
1743
|
+
case "dialog":
|
|
1744
|
+
return "dialog";
|
|
1745
|
+
case "meter":
|
|
1746
|
+
return "meter";
|
|
1747
|
+
case "progressbar":
|
|
1748
|
+
return "progress bar";
|
|
1749
|
+
case "status":
|
|
1750
|
+
return "status";
|
|
1751
|
+
case "group":
|
|
1752
|
+
return node.name ? "group" : "";
|
|
1753
|
+
case "document":
|
|
1754
|
+
return "document";
|
|
1755
|
+
case "application":
|
|
1756
|
+
return "application";
|
|
1757
|
+
case "separator":
|
|
1758
|
+
return "separator";
|
|
1759
|
+
default:
|
|
1760
|
+
return role;
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
function formatStatesNarrator(node) {
|
|
1764
|
+
const states = [];
|
|
1765
|
+
if (node.state.expanded !== void 0) {
|
|
1766
|
+
states.push(node.state.expanded ? "expanded" : "collapsed");
|
|
1767
|
+
}
|
|
1768
|
+
if (node.state.checked !== void 0) {
|
|
1769
|
+
if (node.state.checked === "mixed") {
|
|
1770
|
+
states.push("partially selected");
|
|
1771
|
+
} else {
|
|
1772
|
+
states.push(node.state.checked ? "checked" : "unchecked");
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
if (node.state.pressed !== void 0) {
|
|
1776
|
+
if (node.state.pressed === "mixed") {
|
|
1777
|
+
states.push("partially pressed");
|
|
1778
|
+
} else {
|
|
1779
|
+
states.push(node.state.pressed ? "pressed" : "not pressed");
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
if (node.state.selected !== void 0) {
|
|
1783
|
+
states.push(node.state.selected ? "selected" : "not selected");
|
|
1784
|
+
}
|
|
1785
|
+
if (node.state.disabled) {
|
|
1786
|
+
states.push("disabled");
|
|
1787
|
+
}
|
|
1788
|
+
if (node.state.invalid) {
|
|
1789
|
+
states.push("invalid");
|
|
1790
|
+
}
|
|
1791
|
+
if (node.state.required) {
|
|
1792
|
+
states.push("required");
|
|
1793
|
+
}
|
|
1794
|
+
if (node.state.readonly) {
|
|
1795
|
+
states.push("read only");
|
|
1796
|
+
}
|
|
1797
|
+
if (node.state.busy) {
|
|
1798
|
+
states.push("busy");
|
|
1799
|
+
}
|
|
1800
|
+
if (node.state.current) {
|
|
1801
|
+
if (node.state.current === "page") {
|
|
1802
|
+
states.push("current page");
|
|
1803
|
+
} else if (node.state.current === "step") {
|
|
1804
|
+
states.push("current step");
|
|
1805
|
+
} else if (node.state.current === "location") {
|
|
1806
|
+
states.push("current location");
|
|
1807
|
+
} else if (node.state.current === "date") {
|
|
1808
|
+
states.push("current date");
|
|
1809
|
+
} else if (node.state.current === "time") {
|
|
1810
|
+
states.push("current time");
|
|
1811
|
+
} else if (node.state.current === "true") {
|
|
1812
|
+
states.push("current");
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
if (node.state.grabbed !== void 0) {
|
|
1816
|
+
states.push(node.state.grabbed ? "grabbed" : "not grabbed");
|
|
1817
|
+
}
|
|
1818
|
+
return states.join(", ");
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
// ../src/renderer/audit-renderer.ts
|
|
1822
|
+
function generateAuditReport(model) {
|
|
1823
|
+
const statistics = {
|
|
1824
|
+
totalElements: 0,
|
|
1825
|
+
roleDistribution: {},
|
|
1826
|
+
landmarkCount: 0,
|
|
1827
|
+
headingCount: 0,
|
|
1828
|
+
interactiveCount: 0,
|
|
1829
|
+
focusableCount: 0,
|
|
1830
|
+
statesUsed: /* @__PURE__ */ new Set()
|
|
1831
|
+
};
|
|
1832
|
+
const landmarks = [];
|
|
1833
|
+
const headings = [];
|
|
1834
|
+
const interactiveElements = [];
|
|
1835
|
+
const issues = [];
|
|
1836
|
+
collectAuditData(model.root, statistics, landmarks, headings, interactiveElements);
|
|
1837
|
+
detectLandmarkIssues(landmarks, issues);
|
|
1838
|
+
detectHeadingIssues(headings, issues);
|
|
1839
|
+
detectInteractiveIssues(interactiveElements, issues);
|
|
1840
|
+
return {
|
|
1841
|
+
statistics,
|
|
1842
|
+
landmarks,
|
|
1843
|
+
headings,
|
|
1844
|
+
interactiveElements,
|
|
1845
|
+
issues
|
|
1846
|
+
};
|
|
1847
|
+
}
|
|
1848
|
+
function collectAuditData(node, statistics, landmarks, headings, interactiveElements) {
|
|
1849
|
+
if (node.role !== "generic") {
|
|
1850
|
+
statistics.totalElements++;
|
|
1851
|
+
statistics.roleDistribution[node.role] = (statistics.roleDistribution[node.role] || 0) + 1;
|
|
1852
|
+
if (isLandmark(node.role)) {
|
|
1853
|
+
statistics.landmarkCount++;
|
|
1854
|
+
landmarks.push(node);
|
|
1855
|
+
}
|
|
1856
|
+
if (node.role === "heading") {
|
|
1857
|
+
statistics.headingCount++;
|
|
1858
|
+
headings.push(node);
|
|
1859
|
+
}
|
|
1860
|
+
if (isInteractive(node.role)) {
|
|
1861
|
+
statistics.interactiveCount++;
|
|
1862
|
+
interactiveElements.push(node);
|
|
1863
|
+
}
|
|
1864
|
+
if (node.focus.focusable) {
|
|
1865
|
+
statistics.focusableCount++;
|
|
1866
|
+
}
|
|
1867
|
+
Object.keys(node.state).forEach((state) => {
|
|
1868
|
+
if (node.state[state] !== void 0) {
|
|
1869
|
+
statistics.statesUsed.add(state);
|
|
1870
|
+
}
|
|
1871
|
+
});
|
|
1872
|
+
}
|
|
1873
|
+
for (const child of node.children) {
|
|
1874
|
+
collectAuditData(child, statistics, landmarks, headings, interactiveElements);
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
function isLandmark(role) {
|
|
1878
|
+
return [
|
|
1879
|
+
"navigation",
|
|
1880
|
+
"main",
|
|
1881
|
+
"banner",
|
|
1882
|
+
"contentinfo",
|
|
1883
|
+
"region",
|
|
1884
|
+
"complementary",
|
|
1885
|
+
"form",
|
|
1886
|
+
"search"
|
|
1887
|
+
].includes(role);
|
|
1888
|
+
}
|
|
1889
|
+
function isInteractive(role) {
|
|
1890
|
+
return [
|
|
1891
|
+
"button",
|
|
1892
|
+
"link",
|
|
1893
|
+
"textbox",
|
|
1894
|
+
"checkbox",
|
|
1895
|
+
"radio",
|
|
1896
|
+
"combobox",
|
|
1897
|
+
"listbox",
|
|
1898
|
+
"option"
|
|
1899
|
+
].includes(role);
|
|
1900
|
+
}
|
|
1901
|
+
function detectLandmarkIssues(landmarks, issues) {
|
|
1902
|
+
if (landmarks.length === 0) {
|
|
1903
|
+
issues.push({
|
|
1904
|
+
severity: "info",
|
|
1905
|
+
message: "No landmarks found",
|
|
1906
|
+
suggestion: "Consider adding semantic landmarks (main, nav, aside, etc.)"
|
|
1907
|
+
});
|
|
1908
|
+
}
|
|
1909
|
+
landmarks.forEach((landmark) => {
|
|
1910
|
+
if (!landmark.name && ["navigation", "region", "complementary", "form"].includes(landmark.role)) {
|
|
1911
|
+
issues.push({
|
|
1912
|
+
severity: "warning",
|
|
1913
|
+
message: `${landmark.role} landmark has no accessible name`,
|
|
1914
|
+
suggestion: `Add aria-label="${landmark.role === "navigation" ? "Main navigation" : "Descriptive name"}" to the ${landmark.role} element`,
|
|
1915
|
+
element: {
|
|
1916
|
+
role: landmark.role,
|
|
1917
|
+
name: landmark.name
|
|
1918
|
+
}
|
|
1919
|
+
});
|
|
1920
|
+
}
|
|
1921
|
+
});
|
|
1922
|
+
const landmarksByRole = /* @__PURE__ */ new Map();
|
|
1923
|
+
landmarks.forEach((landmark) => {
|
|
1924
|
+
if (!landmarksByRole.has(landmark.role)) {
|
|
1925
|
+
landmarksByRole.set(landmark.role, []);
|
|
1926
|
+
}
|
|
1927
|
+
landmarksByRole.get(landmark.role).push(landmark);
|
|
1928
|
+
});
|
|
1929
|
+
landmarksByRole.forEach((nodes, role) => {
|
|
1930
|
+
if (nodes.length > 1) {
|
|
1931
|
+
const allUnnamed = nodes.every((n) => !n.name);
|
|
1932
|
+
const allSameName = nodes.every((n) => n.name === nodes[0].name);
|
|
1933
|
+
if (allUnnamed || allSameName) {
|
|
1934
|
+
issues.push({
|
|
1935
|
+
severity: "warning",
|
|
1936
|
+
message: `Multiple ${role} landmarks without distinguishing names`,
|
|
1937
|
+
suggestion: `Add unique aria-label attributes to distinguish between ${role} landmarks`
|
|
1938
|
+
});
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
});
|
|
1942
|
+
}
|
|
1943
|
+
function detectHeadingIssues(headings, issues) {
|
|
1944
|
+
if (headings.length === 0) {
|
|
1945
|
+
return;
|
|
1946
|
+
}
|
|
1947
|
+
const firstHeading = headings[0];
|
|
1948
|
+
if (firstHeading.state.level && firstHeading.state.level !== 1) {
|
|
1949
|
+
issues.push({
|
|
1950
|
+
severity: "error",
|
|
1951
|
+
message: `First heading is h${firstHeading.state.level} (should be h1)`,
|
|
1952
|
+
suggestion: `Change <h${firstHeading.state.level}> to <h1> or add h1 before it`,
|
|
1953
|
+
element: {
|
|
1954
|
+
role: firstHeading.role,
|
|
1955
|
+
name: firstHeading.name
|
|
1956
|
+
}
|
|
1957
|
+
});
|
|
1958
|
+
}
|
|
1959
|
+
for (let i = 1; i < headings.length; i++) {
|
|
1960
|
+
const prevLevel = headings[i - 1].state.level || 1;
|
|
1961
|
+
const currLevel = headings[i].state.level || 1;
|
|
1962
|
+
if (currLevel > prevLevel + 1) {
|
|
1963
|
+
issues.push({
|
|
1964
|
+
severity: "error",
|
|
1965
|
+
message: `Heading hierarchy violation: h${prevLevel} followed by h${currLevel} (skipped h${prevLevel + 1})`,
|
|
1966
|
+
suggestion: `Change h${currLevel} to h${prevLevel + 1} or add intermediate heading levels`,
|
|
1967
|
+
element: {
|
|
1968
|
+
role: headings[i].role,
|
|
1969
|
+
name: headings[i].name
|
|
1970
|
+
}
|
|
1971
|
+
});
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
function detectInteractiveIssues(elements, issues) {
|
|
1976
|
+
elements.forEach((element) => {
|
|
1977
|
+
if (!element.name) {
|
|
1978
|
+
issues.push({
|
|
1979
|
+
severity: "error",
|
|
1980
|
+
message: `${element.role} has no accessible name`,
|
|
1981
|
+
suggestion: element.role === "button" ? "Add text content or aria-label to button" : element.role === "link" ? "Add text content or aria-label to link" : `Add aria-label to ${element.role}`,
|
|
1982
|
+
element: {
|
|
1983
|
+
role: element.role,
|
|
1984
|
+
name: element.name
|
|
1985
|
+
}
|
|
1986
|
+
});
|
|
1987
|
+
}
|
|
1988
|
+
if (element.role === "textbox" && !element.name) {
|
|
1989
|
+
issues.push({
|
|
1990
|
+
severity: "error",
|
|
1991
|
+
message: "Input has no associated label",
|
|
1992
|
+
suggestion: "Add <label> element or aria-label attribute",
|
|
1993
|
+
element: {
|
|
1994
|
+
role: element.role,
|
|
1995
|
+
name: element.name
|
|
1996
|
+
}
|
|
1997
|
+
});
|
|
1998
|
+
}
|
|
1999
|
+
});
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
// src/analyzer.ts
|
|
2003
|
+
var LANDMARK_ROLES = /* @__PURE__ */ new Set([
|
|
2004
|
+
"navigation",
|
|
2005
|
+
"main",
|
|
2006
|
+
"banner",
|
|
2007
|
+
"contentinfo",
|
|
2008
|
+
"complementary",
|
|
2009
|
+
"region",
|
|
2010
|
+
"form",
|
|
2011
|
+
"search"
|
|
2012
|
+
]);
|
|
2013
|
+
var INTERACTIVE_ROLES = /* @__PURE__ */ new Set([
|
|
2014
|
+
"button",
|
|
2015
|
+
"link",
|
|
2016
|
+
"textbox",
|
|
2017
|
+
"checkbox",
|
|
2018
|
+
"radio",
|
|
2019
|
+
"combobox",
|
|
2020
|
+
"listbox",
|
|
2021
|
+
"option"
|
|
2022
|
+
]);
|
|
2023
|
+
function countStats(node) {
|
|
2024
|
+
const stats = { totalElements: 0, interactiveElements: 0, landmarks: 0, headings: 0 };
|
|
2025
|
+
function walk(n) {
|
|
2026
|
+
if (n.role !== "generic" && n.role !== "staticText") {
|
|
2027
|
+
stats.totalElements++;
|
|
2028
|
+
}
|
|
2029
|
+
if (INTERACTIVE_ROLES.has(n.role)) stats.interactiveElements++;
|
|
2030
|
+
if (LANDMARK_ROLES.has(n.role)) stats.landmarks++;
|
|
2031
|
+
if (n.role === "heading") stats.headings++;
|
|
2032
|
+
for (const child of n.children) walk(child);
|
|
2033
|
+
}
|
|
2034
|
+
walk(node);
|
|
2035
|
+
return stats;
|
|
2036
|
+
}
|
|
2037
|
+
function convertAuditFindings(model) {
|
|
2038
|
+
const report = generateAuditReport(model);
|
|
2039
|
+
return report.issues.map((issue) => ({
|
|
2040
|
+
severity: issue.severity,
|
|
2041
|
+
message: issue.message,
|
|
2042
|
+
selector: issue.element ? `${issue.element.role}${issue.element.name ? ` "${issue.element.name}"` : ""}` : issue.suggestion || ""
|
|
2043
|
+
}));
|
|
2044
|
+
}
|
|
2045
|
+
function analyzeDOM(root) {
|
|
2046
|
+
const { model } = buildAccessibilityTree(root);
|
|
2047
|
+
const nvdaText = renderNVDA(model, false);
|
|
2048
|
+
const jawsText = renderJAWS(model, false);
|
|
2049
|
+
const voiceoverText = renderVoiceOver(model, false);
|
|
2050
|
+
const narratorText = renderNarrator(model, false);
|
|
2051
|
+
const nvda = nvdaText.split("\n").filter(Boolean);
|
|
2052
|
+
const jaws = jawsText.split("\n").filter(Boolean);
|
|
2053
|
+
const voiceover = voiceoverText.split("\n").filter(Boolean);
|
|
2054
|
+
const narrator = narratorText.split("\n").filter(Boolean);
|
|
2055
|
+
const audit = convertAuditFindings(model);
|
|
2056
|
+
const stats = countStats(model.root);
|
|
2057
|
+
return { nvda, jaws, voiceover, narrator, audit, stats };
|
|
2058
|
+
}
|
|
2059
|
+
|
|
2060
|
+
// src/preview.ts
|
|
2061
|
+
var currentObserver = null;
|
|
2062
|
+
var debounceTimer = null;
|
|
2063
|
+
function getChannel() {
|
|
2064
|
+
return window.__STORYBOOK_ADDONS_CHANNEL__;
|
|
2065
|
+
}
|
|
2066
|
+
function findStoryRoot() {
|
|
2067
|
+
return document.getElementById("storybook-root") || document.getElementById("root") || document.body;
|
|
2068
|
+
}
|
|
2069
|
+
function runAnalysis() {
|
|
2070
|
+
const root = findStoryRoot();
|
|
2071
|
+
if (!root) return;
|
|
2072
|
+
const analysis = analyzeDOM(root);
|
|
2073
|
+
const channel = getChannel();
|
|
2074
|
+
if (channel) {
|
|
2075
|
+
channel.emit(EVENT_RESULT, analysis);
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
function debouncedAnalysis() {
|
|
2079
|
+
if (debounceTimer) clearTimeout(debounceTimer);
|
|
2080
|
+
debounceTimer = setTimeout(() => {
|
|
2081
|
+
runAnalysis();
|
|
2082
|
+
debounceTimer = null;
|
|
2083
|
+
}, 150);
|
|
2084
|
+
}
|
|
2085
|
+
function startObserving() {
|
|
2086
|
+
if (currentObserver) {
|
|
2087
|
+
currentObserver.disconnect();
|
|
2088
|
+
currentObserver = null;
|
|
2089
|
+
}
|
|
2090
|
+
const root = findStoryRoot();
|
|
2091
|
+
if (!root) return;
|
|
2092
|
+
currentObserver = new MutationObserver(() => {
|
|
2093
|
+
debouncedAnalysis();
|
|
2094
|
+
});
|
|
2095
|
+
currentObserver.observe(root, {
|
|
2096
|
+
childList: true,
|
|
2097
|
+
subtree: true,
|
|
2098
|
+
attributes: true,
|
|
2099
|
+
attributeFilter: [
|
|
2100
|
+
"aria-expanded",
|
|
2101
|
+
"aria-selected",
|
|
2102
|
+
"aria-checked",
|
|
2103
|
+
"aria-disabled",
|
|
2104
|
+
"aria-hidden",
|
|
2105
|
+
"aria-pressed",
|
|
2106
|
+
"aria-label",
|
|
2107
|
+
"aria-labelledby",
|
|
2108
|
+
"role",
|
|
2109
|
+
"disabled",
|
|
2110
|
+
"hidden"
|
|
2111
|
+
]
|
|
2112
|
+
});
|
|
2113
|
+
}
|
|
2114
|
+
var withSpeakable = (storyFn, _context) => {
|
|
2115
|
+
const result = storyFn();
|
|
2116
|
+
if (typeof window !== "undefined") {
|
|
2117
|
+
requestAnimationFrame(() => {
|
|
2118
|
+
setTimeout(() => {
|
|
2119
|
+
runAnalysis();
|
|
2120
|
+
startObserving();
|
|
2121
|
+
}, 100);
|
|
2122
|
+
});
|
|
2123
|
+
}
|
|
2124
|
+
return result;
|
|
2125
|
+
};
|
|
2126
|
+
var decorators = [withSpeakable];
|
|
2127
|
+
export {
|
|
2128
|
+
decorators
|
|
2129
|
+
};
|