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