@ngbracket/a11y-devtools 0.5.0 → 0.7.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/CHANGELOG.md +46 -0
- package/README.md +59 -4
- package/bin/ngbr-a11y-report.mjs +5 -0
- package/dist/attribution.d.ts +22 -0
- package/dist/attribution.js +26 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +4 -1
- package/dist/inpage.global.js +378 -8
- package/dist/keyboard/accname.d.ts +42 -0
- package/dist/keyboard/accname.js +131 -0
- package/dist/keyboard/keyboard-scan.d.ts +14 -0
- package/dist/keyboard/keyboard-scan.js +117 -0
- package/dist/keyboard/tab-sequence.d.ts +58 -0
- package/dist/keyboard/tab-sequence.js +178 -0
- package/dist/overlay.d.ts +22 -0
- package/dist/overlay.js +157 -1
- package/dist/provider.d.ts +8 -0
- package/dist/provider.js +36 -4
- package/dist/report/headless.d.ts +7 -0
- package/dist/report/headless.js +2 -2
- package/dist/runner.d.ts +6 -0
- package/dist/runner.js +1 -0
- package/dist/scan.d.ts +7 -0
- package/dist/scan.js +6 -0
- package/package.json +1 -1
package/dist/inpage.global.js
CHANGED
|
@@ -12667,7 +12667,7 @@
|
|
|
12667
12667
|
isMultiline: function isMultiline() {
|
|
12668
12668
|
return _isMultiline;
|
|
12669
12669
|
},
|
|
12670
|
-
isNativelyFocusable: function
|
|
12670
|
+
isNativelyFocusable: function isNativelyFocusable3() {
|
|
12671
12671
|
return is_natively_focusable_default;
|
|
12672
12672
|
},
|
|
12673
12673
|
isNode: function isNode2() {
|
|
@@ -16086,7 +16086,7 @@
|
|
|
16086
16086
|
});
|
|
16087
16087
|
return tabbableElements;
|
|
16088
16088
|
}
|
|
16089
|
-
function
|
|
16089
|
+
function isNativelyFocusable2(el) {
|
|
16090
16090
|
var _nodeLookup8 = _nodeLookup(el), vNode = _nodeLookup8.vNode;
|
|
16091
16091
|
if (!vNode || focus_disabled_default(vNode)) {
|
|
16092
16092
|
return false;
|
|
@@ -16110,7 +16110,7 @@
|
|
|
16110
16110
|
}
|
|
16111
16111
|
return false;
|
|
16112
16112
|
}
|
|
16113
|
-
var is_natively_focusable_default =
|
|
16113
|
+
var is_natively_focusable_default = isNativelyFocusable2;
|
|
16114
16114
|
function _isFocusable(el) {
|
|
16115
16115
|
var _nodeLookup9 = _nodeLookup(el), vNode = _nodeLookup9.vNode;
|
|
16116
16116
|
if (vNode.props.nodeType !== 1) {
|
|
@@ -25398,7 +25398,7 @@
|
|
|
25398
25398
|
isAriaTextbox: function isAriaTextbox2() {
|
|
25399
25399
|
return is_aria_textbox_default;
|
|
25400
25400
|
},
|
|
25401
|
-
isDisabled: function
|
|
25401
|
+
isDisabled: function isDisabled3() {
|
|
25402
25402
|
return is_disabled_default;
|
|
25403
25403
|
},
|
|
25404
25404
|
isNativeSelect: function isNativeSelect2() {
|
|
@@ -25409,7 +25409,7 @@
|
|
|
25409
25409
|
}
|
|
25410
25410
|
});
|
|
25411
25411
|
var disabledNodeNames = ["fieldset", "button", "select", "input", "textarea"];
|
|
25412
|
-
function
|
|
25412
|
+
function isDisabled2(virtualNode) {
|
|
25413
25413
|
var disabledState = virtualNode._isDisabled;
|
|
25414
25414
|
if (typeof disabledState === "boolean") {
|
|
25415
25415
|
return disabledState;
|
|
@@ -25421,14 +25421,14 @@
|
|
|
25421
25421
|
} else if (ariaDisabled) {
|
|
25422
25422
|
disabledState = ariaDisabled === "true";
|
|
25423
25423
|
} else if (virtualNode.parent) {
|
|
25424
|
-
disabledState =
|
|
25424
|
+
disabledState = isDisabled2(virtualNode.parent);
|
|
25425
25425
|
} else {
|
|
25426
25426
|
disabledState = false;
|
|
25427
25427
|
}
|
|
25428
25428
|
virtualNode._isDisabled = disabledState;
|
|
25429
25429
|
return disabledState;
|
|
25430
25430
|
}
|
|
25431
|
-
var is_disabled_default =
|
|
25431
|
+
var is_disabled_default = isDisabled2;
|
|
25432
25432
|
function identicalLinksSamePurposeEvaluate(node, options, virtualNode) {
|
|
25433
25433
|
var accText = text_exports.accessibleTextVirtual(virtualNode);
|
|
25434
25434
|
var name = text_exports.sanitize(text_exports.removeUnicode(accText, {
|
|
@@ -34133,6 +34133,25 @@
|
|
|
34133
34133
|
});
|
|
34134
34134
|
|
|
34135
34135
|
// dist/attribution.js
|
|
34136
|
+
function resolveListenerEvents(node) {
|
|
34137
|
+
const ng = ngDebug();
|
|
34138
|
+
if (typeof ng?.getListeners !== "function")
|
|
34139
|
+
return [];
|
|
34140
|
+
let listeners;
|
|
34141
|
+
try {
|
|
34142
|
+
listeners = ng.getListeners(node) ?? [];
|
|
34143
|
+
} catch {
|
|
34144
|
+
return [];
|
|
34145
|
+
}
|
|
34146
|
+
const events = /* @__PURE__ */ new Set();
|
|
34147
|
+
for (const listener of listeners) {
|
|
34148
|
+
if (listener?.type === "output")
|
|
34149
|
+
continue;
|
|
34150
|
+
if (typeof listener?.name === "string")
|
|
34151
|
+
events.add(listener.name.toLowerCase());
|
|
34152
|
+
}
|
|
34153
|
+
return [...events];
|
|
34154
|
+
}
|
|
34136
34155
|
function ngDebug() {
|
|
34137
34156
|
return globalThis.ng;
|
|
34138
34157
|
}
|
|
@@ -34204,6 +34223,9 @@
|
|
|
34204
34223
|
}
|
|
34205
34224
|
|
|
34206
34225
|
// dist/overlay.js
|
|
34226
|
+
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
34227
|
+
var TAB_ORDER_COLOR = "#0b8f8f";
|
|
34228
|
+
var TAB_ORDER_WARN_COLOR = "#e8710a";
|
|
34207
34229
|
var OVERLAY_ATTR = "data-ngb-a11y-overlay";
|
|
34208
34230
|
var OVERLAY_EXCLUDE_SELECTOR = `[${OVERLAY_ATTR}]`;
|
|
34209
34231
|
var IMPACT_COLOR = {
|
|
@@ -34228,12 +34250,60 @@
|
|
|
34228
34250
|
zIndex: "2147483646"
|
|
34229
34251
|
});
|
|
34230
34252
|
doc.body.appendChild(container);
|
|
34253
|
+
const svg = doc.createElementNS(SVG_NS, "svg");
|
|
34254
|
+
svg.setAttribute(OVERLAY_ATTR, "");
|
|
34255
|
+
Object.assign(svg.style, {
|
|
34256
|
+
position: "fixed",
|
|
34257
|
+
inset: "0",
|
|
34258
|
+
width: "100%",
|
|
34259
|
+
height: "100%",
|
|
34260
|
+
pointerEvents: "none",
|
|
34261
|
+
overflow: "visible"
|
|
34262
|
+
});
|
|
34263
|
+
const connector = doc.createElementNS(SVG_NS, "polyline");
|
|
34264
|
+
connector.setAttribute("fill", "none");
|
|
34265
|
+
connector.setAttribute("stroke", TAB_ORDER_COLOR);
|
|
34266
|
+
connector.setAttribute("stroke-width", "2");
|
|
34267
|
+
connector.setAttribute("stroke-dasharray", "4 3");
|
|
34268
|
+
connector.setAttribute("opacity", "0.7");
|
|
34269
|
+
svg.appendChild(connector);
|
|
34270
|
+
container.appendChild(svg);
|
|
34271
|
+
const axPanel = doc.createElement("div");
|
|
34272
|
+
axPanel.setAttribute(OVERLAY_ATTR, "");
|
|
34273
|
+
Object.assign(axPanel.style, {
|
|
34274
|
+
position: "fixed",
|
|
34275
|
+
right: "12px",
|
|
34276
|
+
bottom: "12px",
|
|
34277
|
+
maxWidth: "320px",
|
|
34278
|
+
padding: "8px 10px",
|
|
34279
|
+
borderRadius: "6px",
|
|
34280
|
+
background: "rgba(20,22,28,0.94)",
|
|
34281
|
+
color: "#f4f4f5",
|
|
34282
|
+
font: "12px/1.5 ui-sans-serif, system-ui, sans-serif",
|
|
34283
|
+
boxShadow: "0 2px 12px rgba(0,0,0,0.4)",
|
|
34284
|
+
pointerEvents: "none",
|
|
34285
|
+
zIndex: "2147483647",
|
|
34286
|
+
display: "none"
|
|
34287
|
+
});
|
|
34288
|
+
container.appendChild(axPanel);
|
|
34231
34289
|
let highlights = [];
|
|
34290
|
+
let tabBadges = [];
|
|
34232
34291
|
const reposition = () => {
|
|
34233
34292
|
for (const { target, box } of highlights) {
|
|
34234
34293
|
positionBox(box, target);
|
|
34235
34294
|
}
|
|
34295
|
+
repositionTabOrder();
|
|
34236
34296
|
};
|
|
34297
|
+
function repositionTabOrder() {
|
|
34298
|
+
const points = [];
|
|
34299
|
+
for (const { target, badge } of tabBadges) {
|
|
34300
|
+
const rect = target.getBoundingClientRect();
|
|
34301
|
+
badge.style.top = `${rect.top}px`;
|
|
34302
|
+
badge.style.left = `${rect.left}px`;
|
|
34303
|
+
points.push(`${rect.left + rect.width / 2},${rect.top + rect.height / 2}`);
|
|
34304
|
+
}
|
|
34305
|
+
connector.setAttribute("points", points.join(" "));
|
|
34306
|
+
}
|
|
34237
34307
|
const raf = doc.defaultView?.requestAnimationFrame?.bind(doc.defaultView);
|
|
34238
34308
|
let scheduled = false;
|
|
34239
34309
|
const onViewportChange = () => {
|
|
@@ -34270,13 +34340,104 @@
|
|
|
34270
34340
|
highlights.push({ finding, target, box });
|
|
34271
34341
|
}
|
|
34272
34342
|
}
|
|
34343
|
+
function clearTabOrder() {
|
|
34344
|
+
for (const { badge } of tabBadges)
|
|
34345
|
+
badge.remove();
|
|
34346
|
+
tabBadges = [];
|
|
34347
|
+
connector.setAttribute("points", "");
|
|
34348
|
+
}
|
|
34349
|
+
function renderTabOrder(stops) {
|
|
34350
|
+
clearTabOrder();
|
|
34351
|
+
for (const stop of stops) {
|
|
34352
|
+
const target = stop.element;
|
|
34353
|
+
if (!target.isConnected)
|
|
34354
|
+
continue;
|
|
34355
|
+
const badge = buildBadge(doc, stop);
|
|
34356
|
+
container.appendChild(badge);
|
|
34357
|
+
tabBadges.push({ stop, target, badge });
|
|
34358
|
+
}
|
|
34359
|
+
repositionTabOrder();
|
|
34360
|
+
}
|
|
34361
|
+
function renderAxPanel(data) {
|
|
34362
|
+
if (!data) {
|
|
34363
|
+
axPanel.style.display = "none";
|
|
34364
|
+
axPanel.replaceChildren();
|
|
34365
|
+
return;
|
|
34366
|
+
}
|
|
34367
|
+
axPanel.replaceChildren(...buildAxPanelContent(doc, data));
|
|
34368
|
+
axPanel.style.display = "block";
|
|
34369
|
+
}
|
|
34273
34370
|
function destroy() {
|
|
34274
34371
|
clear();
|
|
34372
|
+
clearTabOrder();
|
|
34373
|
+
renderAxPanel(null);
|
|
34275
34374
|
win?.removeEventListener("scroll", onViewportChange, { capture: true });
|
|
34276
34375
|
win?.removeEventListener("resize", onViewportChange);
|
|
34277
34376
|
container.remove();
|
|
34278
34377
|
}
|
|
34279
|
-
return { render, clear, destroy };
|
|
34378
|
+
return { render, renderTabOrder, renderAxPanel, clear, clearTabOrder, destroy };
|
|
34379
|
+
}
|
|
34380
|
+
function buildAxPanelContent(doc, data) {
|
|
34381
|
+
const nodes = [];
|
|
34382
|
+
const header = doc.createElement("div");
|
|
34383
|
+
header.textContent = "Accessibility-tree preview \u2014 computed approximation";
|
|
34384
|
+
Object.assign(header.style, {
|
|
34385
|
+
fontWeight: "700",
|
|
34386
|
+
fontSize: "10px",
|
|
34387
|
+
letterSpacing: "0.02em",
|
|
34388
|
+
textTransform: "uppercase",
|
|
34389
|
+
color: "#a9b0bd",
|
|
34390
|
+
marginBottom: "4px"
|
|
34391
|
+
});
|
|
34392
|
+
header.title = "A computed name/role/state \u2014 an approximation of what assistive tech announces, not any one screen reader.";
|
|
34393
|
+
nodes.push(header);
|
|
34394
|
+
const row = (label, value, muted = false) => {
|
|
34395
|
+
const div = doc.createElement("div");
|
|
34396
|
+
const key = doc.createElement("span");
|
|
34397
|
+
key.textContent = `${label}: `;
|
|
34398
|
+
key.style.color = "#a9b0bd";
|
|
34399
|
+
const val = doc.createElement("span");
|
|
34400
|
+
val.textContent = value;
|
|
34401
|
+
if (muted)
|
|
34402
|
+
val.style.color = "#e8710a";
|
|
34403
|
+
div.append(key, val);
|
|
34404
|
+
return div;
|
|
34405
|
+
};
|
|
34406
|
+
nodes.push(row("role", data.role ?? `(none \u2014 <${data.tag}>)`));
|
|
34407
|
+
nodes.push(data.name ? row("name", `"${data.name}"`) : row("name", "(no accessible name)", true));
|
|
34408
|
+
if (data.description)
|
|
34409
|
+
nodes.push(row("description", `"${data.description}"`));
|
|
34410
|
+
if (data.states.length)
|
|
34411
|
+
nodes.push(row("states", data.states.join(", ")));
|
|
34412
|
+
if (data.component)
|
|
34413
|
+
nodes.push(row("component", data.component));
|
|
34414
|
+
return nodes;
|
|
34415
|
+
}
|
|
34416
|
+
function buildBadge(doc, stop) {
|
|
34417
|
+
const color = stop.positive ? TAB_ORDER_WARN_COLOR : TAB_ORDER_COLOR;
|
|
34418
|
+
const badge = doc.createElement("div");
|
|
34419
|
+
badge.setAttribute("data-ngb-tab-order", String(stop.order));
|
|
34420
|
+
const owner = stop.component ? ` \xB7 ${stop.component}` : "";
|
|
34421
|
+
const ti = stop.positive ? ` \xB7 tabindex=${stop.tabindex} (hijacks order)` : "";
|
|
34422
|
+
badge.title = `Tab stop ${stop.order}${owner}${ti}`;
|
|
34423
|
+
badge.textContent = String(stop.order);
|
|
34424
|
+
Object.assign(badge.style, {
|
|
34425
|
+
position: "fixed",
|
|
34426
|
+
transform: "translate(-50%, -50%)",
|
|
34427
|
+
minWidth: "16px",
|
|
34428
|
+
height: "16px",
|
|
34429
|
+
padding: "0 3px",
|
|
34430
|
+
boxSizing: "border-box",
|
|
34431
|
+
borderRadius: "8px",
|
|
34432
|
+
font: "10px/16px ui-monospace, monospace",
|
|
34433
|
+
fontWeight: "700",
|
|
34434
|
+
textAlign: "center",
|
|
34435
|
+
color: "#fff",
|
|
34436
|
+
background: color,
|
|
34437
|
+
border: "1px solid rgba(255,255,255,0.85)",
|
|
34438
|
+
pointerEvents: "none"
|
|
34439
|
+
});
|
|
34440
|
+
return badge;
|
|
34280
34441
|
}
|
|
34281
34442
|
function resolveTarget(doc, target) {
|
|
34282
34443
|
try {
|
|
@@ -34334,6 +34495,212 @@
|
|
|
34334
34495
|
}, 600);
|
|
34335
34496
|
}
|
|
34336
34497
|
|
|
34498
|
+
// dist/keyboard/tab-sequence.js
|
|
34499
|
+
var FOCUSABLE_SELECTOR = [
|
|
34500
|
+
"a[href]",
|
|
34501
|
+
"area[href]",
|
|
34502
|
+
"button",
|
|
34503
|
+
"input",
|
|
34504
|
+
"select",
|
|
34505
|
+
"textarea",
|
|
34506
|
+
"audio[controls]",
|
|
34507
|
+
"video[controls]",
|
|
34508
|
+
"summary",
|
|
34509
|
+
"iframe",
|
|
34510
|
+
"object",
|
|
34511
|
+
"embed",
|
|
34512
|
+
"[contenteditable]",
|
|
34513
|
+
"[tabindex]"
|
|
34514
|
+
].join(",");
|
|
34515
|
+
function nativeTabIndex(element) {
|
|
34516
|
+
return isNativelyFocusable(element) ? 0 : -1;
|
|
34517
|
+
}
|
|
34518
|
+
function isNativelyFocusable(element) {
|
|
34519
|
+
const tag = element.tagName.toLowerCase();
|
|
34520
|
+
switch (tag) {
|
|
34521
|
+
case "a":
|
|
34522
|
+
case "area":
|
|
34523
|
+
return element.hasAttribute("href");
|
|
34524
|
+
case "button":
|
|
34525
|
+
case "select":
|
|
34526
|
+
case "textarea":
|
|
34527
|
+
return true;
|
|
34528
|
+
case "input":
|
|
34529
|
+
return element.getAttribute("type")?.toLowerCase() !== "hidden";
|
|
34530
|
+
case "summary":
|
|
34531
|
+
return true;
|
|
34532
|
+
case "iframe":
|
|
34533
|
+
case "object":
|
|
34534
|
+
case "embed":
|
|
34535
|
+
return true;
|
|
34536
|
+
case "audio":
|
|
34537
|
+
case "video":
|
|
34538
|
+
return element.hasAttribute("controls");
|
|
34539
|
+
}
|
|
34540
|
+
const editable = element.getAttribute("contenteditable");
|
|
34541
|
+
return editable !== null && editable !== "false";
|
|
34542
|
+
}
|
|
34543
|
+
function resolvedTabIndex(element) {
|
|
34544
|
+
const attr = element.getAttribute("tabindex");
|
|
34545
|
+
if (attr === null)
|
|
34546
|
+
return nativeTabIndex(element);
|
|
34547
|
+
const parsed = Number.parseInt(attr, 10);
|
|
34548
|
+
return Number.isNaN(parsed) ? nativeTabIndex(element) : parsed;
|
|
34549
|
+
}
|
|
34550
|
+
function isDisabled(element) {
|
|
34551
|
+
if ("disabled" in element && element.disabled)
|
|
34552
|
+
return true;
|
|
34553
|
+
return element.closest("fieldset[disabled]") !== null && element.closest("legend") === null;
|
|
34554
|
+
}
|
|
34555
|
+
function isStructurallyHidden(element) {
|
|
34556
|
+
if (element.closest("[inert]") || element.closest("[hidden]"))
|
|
34557
|
+
return true;
|
|
34558
|
+
const closedDetails = element.closest("details:not([open])");
|
|
34559
|
+
return closedDetails !== null && element.closest("summary") === null && element !== closedDetails;
|
|
34560
|
+
}
|
|
34561
|
+
function defaultIsVisible(element) {
|
|
34562
|
+
const view = element.ownerDocument?.defaultView;
|
|
34563
|
+
if (!view?.getComputedStyle)
|
|
34564
|
+
return true;
|
|
34565
|
+
for (let node = element; node; node = node.parentElement) {
|
|
34566
|
+
const style = view.getComputedStyle(node);
|
|
34567
|
+
if (style.display === "none")
|
|
34568
|
+
return false;
|
|
34569
|
+
if (style.visibility === "hidden" || style.visibility === "collapse")
|
|
34570
|
+
return false;
|
|
34571
|
+
}
|
|
34572
|
+
return true;
|
|
34573
|
+
}
|
|
34574
|
+
function isTabbable(element, isVisible = defaultIsVisible) {
|
|
34575
|
+
if (resolvedTabIndex(element) < 0)
|
|
34576
|
+
return false;
|
|
34577
|
+
if (isDisabled(element))
|
|
34578
|
+
return false;
|
|
34579
|
+
if (isStructurallyHidden(element))
|
|
34580
|
+
return false;
|
|
34581
|
+
const editable = element.getAttribute("contenteditable");
|
|
34582
|
+
if (editable === "false" && !isNativelyFocusable(element) && !element.hasAttribute("tabindex")) {
|
|
34583
|
+
return false;
|
|
34584
|
+
}
|
|
34585
|
+
return isVisible(element);
|
|
34586
|
+
}
|
|
34587
|
+
function tabSequence(root = document, options = {}) {
|
|
34588
|
+
const isVisible = options.isVisible ?? defaultIsVisible;
|
|
34589
|
+
const prefixes = options.frameworkPrefixes ?? DEFAULT_FRAMEWORK_PREFIXES;
|
|
34590
|
+
const candidates = [...root.querySelectorAll(FOCUSABLE_SELECTOR)].filter((el) => isTabbable(el, isVisible));
|
|
34591
|
+
const withMeta = candidates.map((element, domIndex) => ({
|
|
34592
|
+
element,
|
|
34593
|
+
domIndex,
|
|
34594
|
+
tabindex: resolvedTabIndex(element),
|
|
34595
|
+
positive: /^\d+$/.test(element.getAttribute("tabindex") ?? "") && resolvedTabIndex(element) > 0
|
|
34596
|
+
}));
|
|
34597
|
+
const positives = withMeta.filter((m) => m.tabindex > 0).sort((a, b) => a.tabindex - b.tabindex || a.domIndex - b.domIndex);
|
|
34598
|
+
const zeros = withMeta.filter((m) => m.tabindex === 0);
|
|
34599
|
+
return [...positives, ...zeros].map((m, i) => {
|
|
34600
|
+
const componentPath = resolveComponentPath(m.element);
|
|
34601
|
+
return {
|
|
34602
|
+
element: m.element,
|
|
34603
|
+
order: i + 1,
|
|
34604
|
+
tabindex: m.tabindex,
|
|
34605
|
+
positive: m.positive,
|
|
34606
|
+
component: appComponentFromPath(componentPath, prefixes),
|
|
34607
|
+
componentPath
|
|
34608
|
+
};
|
|
34609
|
+
});
|
|
34610
|
+
}
|
|
34611
|
+
function visualOrderJumps(stops, getRect = (el) => el.getBoundingClientRect(), rowThreshold = 8) {
|
|
34612
|
+
const jumps = [];
|
|
34613
|
+
for (let i = 1; i < stops.length; i++) {
|
|
34614
|
+
const prev = getRect(stops[i - 1].element);
|
|
34615
|
+
const curr = getRect(stops[i].element);
|
|
34616
|
+
const movedUp = curr.top < prev.top - rowThreshold;
|
|
34617
|
+
const sameRowMovedLeft = Math.abs(curr.top - prev.top) <= rowThreshold && curr.left < prev.left - rowThreshold;
|
|
34618
|
+
if (movedUp || sameRowMovedLeft)
|
|
34619
|
+
jumps.push(i);
|
|
34620
|
+
}
|
|
34621
|
+
return jumps;
|
|
34622
|
+
}
|
|
34623
|
+
|
|
34624
|
+
// dist/keyboard/keyboard-scan.js
|
|
34625
|
+
var INTERACTIVE_ROLES = /* @__PURE__ */ new Set([
|
|
34626
|
+
"button",
|
|
34627
|
+
"link",
|
|
34628
|
+
"menuitem",
|
|
34629
|
+
"menuitemcheckbox",
|
|
34630
|
+
"menuitemradio",
|
|
34631
|
+
"tab",
|
|
34632
|
+
"switch",
|
|
34633
|
+
"checkbox",
|
|
34634
|
+
"radio",
|
|
34635
|
+
"option",
|
|
34636
|
+
"slider",
|
|
34637
|
+
"spinbutton",
|
|
34638
|
+
"combobox",
|
|
34639
|
+
"textbox",
|
|
34640
|
+
"searchbox",
|
|
34641
|
+
"treeitem"
|
|
34642
|
+
]);
|
|
34643
|
+
var KEY_EVENTS = ["keydown", "keyup", "keypress"];
|
|
34644
|
+
var UNDERSTANDING = "https://www.w3.org/WAI/WCAG22/Understanding";
|
|
34645
|
+
var KEYBOARD_URL = `${UNDERSTANDING}/keyboard.html`;
|
|
34646
|
+
var FOCUS_ORDER_URL = `${UNDERSTANDING}/focus-order.html`;
|
|
34647
|
+
function shortSelector(element) {
|
|
34648
|
+
const tag = element.tagName.toLowerCase();
|
|
34649
|
+
if (element.id)
|
|
34650
|
+
return `${tag}#${element.id}`;
|
|
34651
|
+
const classes = (element.getAttribute("class") ?? "").trim().split(/\s+/).filter(Boolean).slice(0, 2);
|
|
34652
|
+
return classes.length ? `${tag}.${classes.join(".")}` : tag;
|
|
34653
|
+
}
|
|
34654
|
+
function shortHtml(element) {
|
|
34655
|
+
const html = element.outerHTML ?? "";
|
|
34656
|
+
return html.length > 160 ? `${html.slice(0, 159)}\u2026` : html;
|
|
34657
|
+
}
|
|
34658
|
+
function scanKeyboard(root = document, options = {}) {
|
|
34659
|
+
const prefixes = options.frameworkPrefixes ?? DEFAULT_FRAMEWORK_PREFIXES;
|
|
34660
|
+
const isVisible = options.isVisible;
|
|
34661
|
+
const findings = [];
|
|
34662
|
+
const make = (element, id, impact, help, helpUrl) => {
|
|
34663
|
+
const componentPath = resolveComponentPath(element);
|
|
34664
|
+
return {
|
|
34665
|
+
id,
|
|
34666
|
+
impact,
|
|
34667
|
+
help,
|
|
34668
|
+
helpUrl,
|
|
34669
|
+
component: appComponentFromPath(componentPath, prefixes),
|
|
34670
|
+
componentPath,
|
|
34671
|
+
directives: resolveDirectiveNames(element),
|
|
34672
|
+
target: shortSelector(element),
|
|
34673
|
+
html: shortHtml(element)
|
|
34674
|
+
};
|
|
34675
|
+
};
|
|
34676
|
+
for (const element of root.querySelectorAll("*")) {
|
|
34677
|
+
if (isNativelyFocusable(element))
|
|
34678
|
+
continue;
|
|
34679
|
+
const role = element.getAttribute("role")?.toLowerCase() ?? "";
|
|
34680
|
+
const events = resolveListenerEvents(element);
|
|
34681
|
+
const hasClick = events.includes("click");
|
|
34682
|
+
const interactiveByRole = INTERACTIVE_ROLES.has(role);
|
|
34683
|
+
if (!hasClick && !interactiveByRole)
|
|
34684
|
+
continue;
|
|
34685
|
+
const focusable = isTabbable(element, isVisible);
|
|
34686
|
+
if (!focusable) {
|
|
34687
|
+
const reason = interactiveByRole ? `has role="${role}"` : "has a click handler";
|
|
34688
|
+
findings.push(make(element, "ngbr/unreachable-control", "serious", `Interactive element isn't reachable by keyboard \u2014 it ${reason} but is not a native control and has no tabindex >= 0, so keyboard and screen-reader users can't focus it. Add tabindex="0" (and a role, if missing), or use a <button>/<a>.`, KEYBOARD_URL));
|
|
34689
|
+
continue;
|
|
34690
|
+
}
|
|
34691
|
+
const hasKey = events.some((e) => KEY_EVENTS.includes(e));
|
|
34692
|
+
if (hasClick && !hasKey) {
|
|
34693
|
+
findings.push(make(element, "ngbr/click-without-key", "moderate", `Possible keyboard trap: this element has a (click) handler but no keyboard handler (keydown/keyup) and isn't a native button/link, so Enter/Space may not activate it. Verify by hand, then add a key handler or use a <button>.`, KEYBOARD_URL));
|
|
34694
|
+
}
|
|
34695
|
+
}
|
|
34696
|
+
const stops = tabSequence(root, { frameworkPrefixes: prefixes, isVisible });
|
|
34697
|
+
for (const jump of visualOrderJumps(stops)) {
|
|
34698
|
+
const stop = stops[jump];
|
|
34699
|
+
findings.push(make(stop.element, "ngbr/tab-order-mismatch", "moderate", `Possible tab-order mismatch: Tab reaches this control (stop ${stop.order}) after one that sits below or to the right of it, so focus jumps against the visual reading order. Heuristic \u2014 verify the order makes sense for a sighted keyboard user.`, FOCUS_ORDER_URL));
|
|
34700
|
+
}
|
|
34701
|
+
return findings;
|
|
34702
|
+
}
|
|
34703
|
+
|
|
34337
34704
|
// dist/scan.js
|
|
34338
34705
|
var runChain = Promise.resolve();
|
|
34339
34706
|
function scan(root = document, options, scanOptions) {
|
|
@@ -34371,6 +34738,9 @@
|
|
|
34371
34738
|
});
|
|
34372
34739
|
}
|
|
34373
34740
|
}
|
|
34741
|
+
if (scanOptions?.keyboard) {
|
|
34742
|
+
findings.push(...scanKeyboard(root, { frameworkPrefixes }));
|
|
34743
|
+
}
|
|
34374
34744
|
return findings;
|
|
34375
34745
|
}
|
|
34376
34746
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The keyboard layer, part C: a *computed approximation* of what assistive tech
|
|
3
|
+
* would announce for an element — its role, accessible name, description, and
|
|
4
|
+
* ARIA states.
|
|
5
|
+
*
|
|
6
|
+
* HONESTY GUARDRAIL (non-negotiable): this is a computed approximation, NEVER
|
|
7
|
+
* "what a screen reader says". Real output varies by screen reader
|
|
8
|
+
* (NVDA/JAWS/VoiceOver), browse vs. focus mode, verbosity, and browser. Callers
|
|
9
|
+
* must label it as such and must not brand it as any specific SR's output.
|
|
10
|
+
*
|
|
11
|
+
* The name and role come from **axe-core's own accessible-name commons** — the
|
|
12
|
+
* same well-tested implementation the scan already relies on — so there's one
|
|
13
|
+
* accname source, not a second home-grown one. axe is loaded via dynamic import
|
|
14
|
+
* (and only when this runs), so it never enters a consumer's static bundle; the
|
|
15
|
+
* prod-weight guard still holds.
|
|
16
|
+
*/
|
|
17
|
+
/** A computed approximation of an element's accessibility-tree node. */
|
|
18
|
+
export interface AxDescription {
|
|
19
|
+
/** Computed ARIA role, or null when axe can't resolve one. */
|
|
20
|
+
role: string | null;
|
|
21
|
+
/** Computed accessible name (may be empty — itself a finding worth noticing). */
|
|
22
|
+
name: string;
|
|
23
|
+
/** Computed accessible description (aria-describedby / title), or ''. */
|
|
24
|
+
description: string;
|
|
25
|
+
/** Compact human labels for the element's states, e.g. `['expanded', 'level 2']`. */
|
|
26
|
+
states: string[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Compute the accessibility-tree approximation for `element`. Resolves to sane
|
|
30
|
+
* defaults (no role, empty name) rather than throwing if axe's tree can't be
|
|
31
|
+
* built — e.g. a scan is mid-flight — so a focus-follow caller degrades quietly.
|
|
32
|
+
*/
|
|
33
|
+
export declare function describeElement(element: Element): Promise<AxDescription>;
|
|
34
|
+
/** The accessible description: `aria-describedby` targets' text, else the `title`. */
|
|
35
|
+
export declare function accessibleDescription(element: Element): string;
|
|
36
|
+
/**
|
|
37
|
+
* Compact, human-readable state labels — the states a screen reader would voice
|
|
38
|
+
* alongside role and name (expanded, checked, disabled, current, level, position
|
|
39
|
+
* in set). ARIA attributes take precedence, with native fallbacks (a real
|
|
40
|
+
* checkbox's `checked`, a disabled control, a heading's level).
|
|
41
|
+
*/
|
|
42
|
+
export declare function ariaStates(element: Element): string[];
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The keyboard layer, part C: a *computed approximation* of what assistive tech
|
|
3
|
+
* would announce for an element — its role, accessible name, description, and
|
|
4
|
+
* ARIA states.
|
|
5
|
+
*
|
|
6
|
+
* HONESTY GUARDRAIL (non-negotiable): this is a computed approximation, NEVER
|
|
7
|
+
* "what a screen reader says". Real output varies by screen reader
|
|
8
|
+
* (NVDA/JAWS/VoiceOver), browse vs. focus mode, verbosity, and browser. Callers
|
|
9
|
+
* must label it as such and must not brand it as any specific SR's output.
|
|
10
|
+
*
|
|
11
|
+
* The name and role come from **axe-core's own accessible-name commons** — the
|
|
12
|
+
* same well-tested implementation the scan already relies on — so there's one
|
|
13
|
+
* accname source, not a second home-grown one. axe is loaded via dynamic import
|
|
14
|
+
* (and only when this runs), so it never enters a consumer's static bundle; the
|
|
15
|
+
* prod-weight guard still holds.
|
|
16
|
+
*/
|
|
17
|
+
// axe is a heavy dynamic import; load it once and reuse. Typed loosely because
|
|
18
|
+
// the accname commons used here aren't part of axe's published type surface.
|
|
19
|
+
let axePromise;
|
|
20
|
+
function loadAxe() {
|
|
21
|
+
return (axePromise ??= import('axe-core').then((m) => (m.default ?? m)));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Compute the accessibility-tree approximation for `element`. Resolves to sane
|
|
25
|
+
* defaults (no role, empty name) rather than throwing if axe's tree can't be
|
|
26
|
+
* built — e.g. a scan is mid-flight — so a focus-follow caller degrades quietly.
|
|
27
|
+
*/
|
|
28
|
+
export async function describeElement(element) {
|
|
29
|
+
const axe = await loadAxe();
|
|
30
|
+
const doc = element.ownerDocument ?? document;
|
|
31
|
+
let role = null;
|
|
32
|
+
let name = '';
|
|
33
|
+
try {
|
|
34
|
+
axe.setup(doc);
|
|
35
|
+
const vnode = axe.utils.getNodeFromTree(element);
|
|
36
|
+
role = axe.commons.aria.getRole(element) ?? null;
|
|
37
|
+
name = vnode ? (axe.commons.text.accessibleTextVirtual(vnode) ?? '') : '';
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// Leave role=null / name='' — axe couldn't build a tree (e.g. run in flight).
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
try {
|
|
44
|
+
axe.teardown();
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
/* nothing set up */
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return { role, name, description: accessibleDescription(element), states: ariaStates(element) };
|
|
51
|
+
}
|
|
52
|
+
/** The accessible description: `aria-describedby` targets' text, else the `title`. */
|
|
53
|
+
export function accessibleDescription(element) {
|
|
54
|
+
const ids = element.getAttribute('aria-describedby');
|
|
55
|
+
if (ids) {
|
|
56
|
+
const doc = element.ownerDocument ?? document;
|
|
57
|
+
const text = ids
|
|
58
|
+
.split(/\s+/)
|
|
59
|
+
.filter(Boolean)
|
|
60
|
+
.map((id) => doc.getElementById(id)?.textContent?.trim() ?? '')
|
|
61
|
+
.filter(Boolean)
|
|
62
|
+
.join(' ');
|
|
63
|
+
if (text)
|
|
64
|
+
return text;
|
|
65
|
+
}
|
|
66
|
+
return element.getAttribute('title')?.trim() ?? '';
|
|
67
|
+
}
|
|
68
|
+
/** True for an ARIA attribute value that expresses "on" rather than "off"/absent. */
|
|
69
|
+
function isOn(value) {
|
|
70
|
+
return value !== null && value !== 'false' && value !== 'undefined';
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Compact, human-readable state labels — the states a screen reader would voice
|
|
74
|
+
* alongside role and name (expanded, checked, disabled, current, level, position
|
|
75
|
+
* in set). ARIA attributes take precedence, with native fallbacks (a real
|
|
76
|
+
* checkbox's `checked`, a disabled control, a heading's level).
|
|
77
|
+
*/
|
|
78
|
+
export function ariaStates(element) {
|
|
79
|
+
const states = [];
|
|
80
|
+
const attr = (name) => element.getAttribute(name);
|
|
81
|
+
const expanded = attr('aria-expanded');
|
|
82
|
+
if (expanded === 'true')
|
|
83
|
+
states.push('expanded');
|
|
84
|
+
else if (expanded === 'false')
|
|
85
|
+
states.push('collapsed');
|
|
86
|
+
const checked = attr('aria-checked');
|
|
87
|
+
if (checked === 'true')
|
|
88
|
+
states.push('checked');
|
|
89
|
+
else if (checked === 'false')
|
|
90
|
+
states.push('not checked');
|
|
91
|
+
else if (checked === 'mixed')
|
|
92
|
+
states.push('mixed');
|
|
93
|
+
else if ('checked' in element && element.checked)
|
|
94
|
+
states.push('checked');
|
|
95
|
+
const pressed = attr('aria-pressed');
|
|
96
|
+
if (pressed === 'true')
|
|
97
|
+
states.push('pressed');
|
|
98
|
+
else if (pressed === 'false')
|
|
99
|
+
states.push('not pressed');
|
|
100
|
+
if (attr('aria-selected') === 'true')
|
|
101
|
+
states.push('selected');
|
|
102
|
+
if (isOn(attr('aria-disabled')) || ('disabled' in element && element.disabled)) {
|
|
103
|
+
states.push('disabled');
|
|
104
|
+
}
|
|
105
|
+
if (isOn(attr('aria-required')) || ('required' in element && element.required)) {
|
|
106
|
+
states.push('required');
|
|
107
|
+
}
|
|
108
|
+
if (attr('aria-invalid') === 'true')
|
|
109
|
+
states.push('invalid');
|
|
110
|
+
if (attr('aria-readonly') === 'true')
|
|
111
|
+
states.push('read only');
|
|
112
|
+
const current = attr('aria-current');
|
|
113
|
+
if (isOn(current))
|
|
114
|
+
states.push(current === 'true' ? 'current' : `current ${current}`);
|
|
115
|
+
const haspopup = attr('aria-haspopup');
|
|
116
|
+
if (isOn(haspopup))
|
|
117
|
+
states.push(haspopup === 'true' ? 'has popup' : `has ${haspopup} popup`);
|
|
118
|
+
const level = attr('aria-level') ?? headingLevel(element);
|
|
119
|
+
if (level)
|
|
120
|
+
states.push(`level ${level}`);
|
|
121
|
+
const posinset = attr('aria-posinset');
|
|
122
|
+
const setsize = attr('aria-setsize');
|
|
123
|
+
if (posinset && setsize)
|
|
124
|
+
states.push(`${posinset} of ${setsize}`);
|
|
125
|
+
return states;
|
|
126
|
+
}
|
|
127
|
+
/** The heading level for a native `h1`–`h6`, else null. */
|
|
128
|
+
function headingLevel(element) {
|
|
129
|
+
const match = /^h([1-6])$/.exec(element.tagName.toLowerCase());
|
|
130
|
+
return match ? match[1] : null;
|
|
131
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { A11yFinding } from '../scan.js';
|
|
2
|
+
export interface KeyboardScanOptions {
|
|
3
|
+
/** UI-primitive prefixes to walk past during attribution; see the scan options. */
|
|
4
|
+
frameworkPrefixes?: readonly string[];
|
|
5
|
+
/** Visibility predicate override (tests); see {@link tabSequence}. */
|
|
6
|
+
isVisible?: (element: Element) => boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Scan `root` for keyboard-operability problems and return them as findings.
|
|
10
|
+
* Runs entirely in the page (needs the live `window.ng` for listeners and
|
|
11
|
+
* attribution), so it's a no-op — empty result — in production where that global
|
|
12
|
+
* is absent.
|
|
13
|
+
*/
|
|
14
|
+
export declare function scanKeyboard(root?: ParentNode, options?: KeyboardScanOptions): A11yFinding[];
|