@ngbracket/a11y-devtools 0.10.1 → 0.11.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 +26 -0
- package/README.md +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/inpage.global.js +529 -529
- package/dist/keyboard/tab-sequence.js +4 -1
- package/dist/provider.d.ts +17 -0
- package/dist/provider.js +66 -11
- package/dist/toggle.d.ts +61 -0
- package/dist/toggle.js +173 -0
- package/package.json +1 -1
package/dist/inpage.global.js
CHANGED
|
@@ -34222,6 +34222,318 @@
|
|
|
34222
34222
|
return names;
|
|
34223
34223
|
}
|
|
34224
34224
|
|
|
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";
|
|
34229
|
+
var TAB_BADGE_GUTTER = 10;
|
|
34230
|
+
var TAB_BADGE_MIN_X = 9;
|
|
34231
|
+
var LABEL_MIN_TOP = 2;
|
|
34232
|
+
var OVERLAY_ATTR = "data-ngb-a11y-overlay";
|
|
34233
|
+
var OVERLAY_EXCLUDE_SELECTOR = `[${OVERLAY_ATTR}]`;
|
|
34234
|
+
var IMPACT_COLOR = {
|
|
34235
|
+
critical: "#d32029",
|
|
34236
|
+
serious: "#e8710a",
|
|
34237
|
+
moderate: "#c9a227",
|
|
34238
|
+
minor: "#3b7dd8",
|
|
34239
|
+
none: "#8a8a8a"
|
|
34240
|
+
};
|
|
34241
|
+
function colorFor(impact) {
|
|
34242
|
+
return IMPACT_COLOR[impact ?? "none"];
|
|
34243
|
+
}
|
|
34244
|
+
function createOverlay(options = {}) {
|
|
34245
|
+
const doc = options.document ?? document;
|
|
34246
|
+
const container = doc.createElement("div");
|
|
34247
|
+
container.setAttribute(OVERLAY_ATTR, "");
|
|
34248
|
+
Object.assign(container.style, {
|
|
34249
|
+
position: "fixed",
|
|
34250
|
+
inset: "0",
|
|
34251
|
+
pointerEvents: "none",
|
|
34252
|
+
// pass clicks through; individual boxes opt back in
|
|
34253
|
+
zIndex: "2147483646"
|
|
34254
|
+
});
|
|
34255
|
+
doc.body.appendChild(container);
|
|
34256
|
+
const svg = doc.createElementNS(SVG_NS, "svg");
|
|
34257
|
+
svg.setAttribute(OVERLAY_ATTR, "");
|
|
34258
|
+
Object.assign(svg.style, {
|
|
34259
|
+
position: "fixed",
|
|
34260
|
+
inset: "0",
|
|
34261
|
+
width: "100%",
|
|
34262
|
+
height: "100%",
|
|
34263
|
+
pointerEvents: "none",
|
|
34264
|
+
overflow: "visible"
|
|
34265
|
+
});
|
|
34266
|
+
const connector = doc.createElementNS(SVG_NS, "polyline");
|
|
34267
|
+
connector.setAttribute("fill", "none");
|
|
34268
|
+
connector.setAttribute("stroke", TAB_ORDER_COLOR);
|
|
34269
|
+
connector.setAttribute("stroke-width", "2");
|
|
34270
|
+
connector.setAttribute("stroke-dasharray", "4 3");
|
|
34271
|
+
connector.setAttribute("opacity", "0.7");
|
|
34272
|
+
svg.appendChild(connector);
|
|
34273
|
+
container.appendChild(svg);
|
|
34274
|
+
const axPanel = doc.createElement("div");
|
|
34275
|
+
axPanel.setAttribute(OVERLAY_ATTR, "");
|
|
34276
|
+
Object.assign(axPanel.style, {
|
|
34277
|
+
position: "fixed",
|
|
34278
|
+
right: "12px",
|
|
34279
|
+
bottom: "12px",
|
|
34280
|
+
maxWidth: "320px",
|
|
34281
|
+
padding: "8px 10px",
|
|
34282
|
+
borderRadius: "6px",
|
|
34283
|
+
background: "rgba(20,22,28,0.94)",
|
|
34284
|
+
color: "#f4f4f5",
|
|
34285
|
+
font: "12px/1.5 ui-sans-serif, system-ui, sans-serif",
|
|
34286
|
+
boxShadow: "0 2px 12px rgba(0,0,0,0.4)",
|
|
34287
|
+
pointerEvents: "none",
|
|
34288
|
+
zIndex: "2147483647",
|
|
34289
|
+
display: "none"
|
|
34290
|
+
});
|
|
34291
|
+
container.appendChild(axPanel);
|
|
34292
|
+
let highlights = [];
|
|
34293
|
+
let tabBadges = [];
|
|
34294
|
+
const reposition = () => {
|
|
34295
|
+
for (const { target, box } of highlights) {
|
|
34296
|
+
positionBox(box, target);
|
|
34297
|
+
}
|
|
34298
|
+
decollideLabels();
|
|
34299
|
+
repositionTabOrder();
|
|
34300
|
+
};
|
|
34301
|
+
function decollideLabels() {
|
|
34302
|
+
const labels = [];
|
|
34303
|
+
const boxes = [];
|
|
34304
|
+
for (const { target, box } of highlights) {
|
|
34305
|
+
const label = box.firstElementChild;
|
|
34306
|
+
if (!label)
|
|
34307
|
+
continue;
|
|
34308
|
+
const rect = target.getBoundingClientRect();
|
|
34309
|
+
labels.push(label);
|
|
34310
|
+
boxes.push({ left: rect.left, width: label.offsetWidth, baseTop: rect.top - label.offsetHeight, height: label.offsetHeight });
|
|
34311
|
+
}
|
|
34312
|
+
const tops = resolveLabelStack(boxes);
|
|
34313
|
+
for (let i = 0; i < labels.length; i++) {
|
|
34314
|
+
const extraUp = boxes[i].baseTop - tops[i];
|
|
34315
|
+
labels[i].style.transform = extraUp > 0 ? `translateY(calc(-100% - ${extraUp}px))` : "translateY(-100%)";
|
|
34316
|
+
}
|
|
34317
|
+
}
|
|
34318
|
+
function repositionTabOrder() {
|
|
34319
|
+
const points = [];
|
|
34320
|
+
for (const { target, badge } of tabBadges) {
|
|
34321
|
+
const rect = target.getBoundingClientRect();
|
|
34322
|
+
const y = rect.top + rect.height / 2;
|
|
34323
|
+
const x = Math.max(TAB_BADGE_MIN_X, rect.left - TAB_BADGE_GUTTER);
|
|
34324
|
+
badge.style.top = `${y}px`;
|
|
34325
|
+
badge.style.left = `${x}px`;
|
|
34326
|
+
points.push(`${x},${y}`);
|
|
34327
|
+
}
|
|
34328
|
+
connector.setAttribute("points", points.join(" "));
|
|
34329
|
+
}
|
|
34330
|
+
const raf = doc.defaultView?.requestAnimationFrame?.bind(doc.defaultView);
|
|
34331
|
+
let scheduled = false;
|
|
34332
|
+
const onViewportChange = () => {
|
|
34333
|
+
if (!raf) {
|
|
34334
|
+
reposition();
|
|
34335
|
+
return;
|
|
34336
|
+
}
|
|
34337
|
+
if (scheduled)
|
|
34338
|
+
return;
|
|
34339
|
+
scheduled = true;
|
|
34340
|
+
raf(() => {
|
|
34341
|
+
scheduled = false;
|
|
34342
|
+
reposition();
|
|
34343
|
+
});
|
|
34344
|
+
};
|
|
34345
|
+
const win = doc.defaultView;
|
|
34346
|
+
win?.addEventListener("scroll", onViewportChange, { passive: true, capture: true });
|
|
34347
|
+
win?.addEventListener("resize", onViewportChange, { passive: true });
|
|
34348
|
+
function clear() {
|
|
34349
|
+
for (const { box } of highlights)
|
|
34350
|
+
box.remove();
|
|
34351
|
+
highlights = [];
|
|
34352
|
+
}
|
|
34353
|
+
function render(findings) {
|
|
34354
|
+
clear();
|
|
34355
|
+
for (const finding of findings) {
|
|
34356
|
+
const target = resolveTarget(doc, finding.target);
|
|
34357
|
+
if (!target)
|
|
34358
|
+
continue;
|
|
34359
|
+
const box = buildBox(doc, finding);
|
|
34360
|
+
box.addEventListener("click", () => flashAndScroll(target, box));
|
|
34361
|
+
container.appendChild(box);
|
|
34362
|
+
positionBox(box, target);
|
|
34363
|
+
highlights.push({ finding, target, box });
|
|
34364
|
+
}
|
|
34365
|
+
decollideLabels();
|
|
34366
|
+
}
|
|
34367
|
+
function clearTabOrder() {
|
|
34368
|
+
for (const { badge } of tabBadges)
|
|
34369
|
+
badge.remove();
|
|
34370
|
+
tabBadges = [];
|
|
34371
|
+
connector.setAttribute("points", "");
|
|
34372
|
+
}
|
|
34373
|
+
function renderTabOrder(stops) {
|
|
34374
|
+
clearTabOrder();
|
|
34375
|
+
for (const stop of stops) {
|
|
34376
|
+
const target = stop.element;
|
|
34377
|
+
if (!target.isConnected)
|
|
34378
|
+
continue;
|
|
34379
|
+
const badge = buildBadge(doc, stop);
|
|
34380
|
+
container.appendChild(badge);
|
|
34381
|
+
tabBadges.push({ stop, target, badge });
|
|
34382
|
+
}
|
|
34383
|
+
repositionTabOrder();
|
|
34384
|
+
}
|
|
34385
|
+
function renderAxPanel(data) {
|
|
34386
|
+
if (!data) {
|
|
34387
|
+
axPanel.style.display = "none";
|
|
34388
|
+
axPanel.replaceChildren();
|
|
34389
|
+
return;
|
|
34390
|
+
}
|
|
34391
|
+
axPanel.replaceChildren(...buildAxPanelContent(doc, data));
|
|
34392
|
+
axPanel.style.display = "block";
|
|
34393
|
+
}
|
|
34394
|
+
function destroy() {
|
|
34395
|
+
clear();
|
|
34396
|
+
clearTabOrder();
|
|
34397
|
+
renderAxPanel(null);
|
|
34398
|
+
win?.removeEventListener("scroll", onViewportChange, { capture: true });
|
|
34399
|
+
win?.removeEventListener("resize", onViewportChange);
|
|
34400
|
+
container.remove();
|
|
34401
|
+
}
|
|
34402
|
+
return { render, renderTabOrder, renderAxPanel, clear, clearTabOrder, destroy };
|
|
34403
|
+
}
|
|
34404
|
+
function buildAxPanelContent(doc, data) {
|
|
34405
|
+
const nodes = [];
|
|
34406
|
+
const header = doc.createElement("div");
|
|
34407
|
+
header.textContent = "Accessibility-tree preview \u2014 computed approximation";
|
|
34408
|
+
Object.assign(header.style, {
|
|
34409
|
+
fontWeight: "700",
|
|
34410
|
+
fontSize: "10px",
|
|
34411
|
+
letterSpacing: "0.02em",
|
|
34412
|
+
textTransform: "uppercase",
|
|
34413
|
+
color: "#a9b0bd",
|
|
34414
|
+
marginBottom: "4px"
|
|
34415
|
+
});
|
|
34416
|
+
header.title = "A computed name/role/state \u2014 an approximation of what assistive tech announces, not any one screen reader.";
|
|
34417
|
+
nodes.push(header);
|
|
34418
|
+
const row = (label, value, muted = false) => {
|
|
34419
|
+
const div = doc.createElement("div");
|
|
34420
|
+
const key = doc.createElement("span");
|
|
34421
|
+
key.textContent = `${label}: `;
|
|
34422
|
+
key.style.color = "#a9b0bd";
|
|
34423
|
+
const val = doc.createElement("span");
|
|
34424
|
+
val.textContent = value;
|
|
34425
|
+
if (muted)
|
|
34426
|
+
val.style.color = "#e8710a";
|
|
34427
|
+
div.append(key, val);
|
|
34428
|
+
return div;
|
|
34429
|
+
};
|
|
34430
|
+
nodes.push(row("role", data.role ?? `(none \u2014 <${data.tag}>)`));
|
|
34431
|
+
nodes.push(data.name ? row("name", `"${data.name}"`) : row("name", "(no accessible name)", true));
|
|
34432
|
+
if (data.description)
|
|
34433
|
+
nodes.push(row("description", `"${data.description}"`));
|
|
34434
|
+
if (data.states.length)
|
|
34435
|
+
nodes.push(row("states", data.states.join(", ")));
|
|
34436
|
+
if (data.component)
|
|
34437
|
+
nodes.push(row("component", data.component));
|
|
34438
|
+
return nodes;
|
|
34439
|
+
}
|
|
34440
|
+
function buildBadge(doc, stop) {
|
|
34441
|
+
const color = stop.positive ? TAB_ORDER_WARN_COLOR : TAB_ORDER_COLOR;
|
|
34442
|
+
const badge = doc.createElement("div");
|
|
34443
|
+
badge.setAttribute("data-ngb-tab-order", String(stop.order));
|
|
34444
|
+
const owner = stop.component ? ` \xB7 ${stop.component}` : "";
|
|
34445
|
+
const ti = stop.positive ? ` \xB7 tabindex=${stop.tabindex} (hijacks order)` : "";
|
|
34446
|
+
badge.title = `Tab stop ${stop.order}${owner}${ti}`;
|
|
34447
|
+
badge.textContent = String(stop.order);
|
|
34448
|
+
Object.assign(badge.style, {
|
|
34449
|
+
position: "fixed",
|
|
34450
|
+
transform: "translate(-50%, -50%)",
|
|
34451
|
+
minWidth: "16px",
|
|
34452
|
+
height: "16px",
|
|
34453
|
+
padding: "0 3px",
|
|
34454
|
+
boxSizing: "border-box",
|
|
34455
|
+
borderRadius: "8px",
|
|
34456
|
+
font: "10px/16px ui-monospace, monospace",
|
|
34457
|
+
fontWeight: "700",
|
|
34458
|
+
textAlign: "center",
|
|
34459
|
+
color: "#fff",
|
|
34460
|
+
background: color,
|
|
34461
|
+
border: "1px solid rgba(255,255,255,0.85)",
|
|
34462
|
+
pointerEvents: "none"
|
|
34463
|
+
});
|
|
34464
|
+
return badge;
|
|
34465
|
+
}
|
|
34466
|
+
function resolveTarget(doc, target) {
|
|
34467
|
+
try {
|
|
34468
|
+
return doc.querySelector(target);
|
|
34469
|
+
} catch {
|
|
34470
|
+
return null;
|
|
34471
|
+
}
|
|
34472
|
+
}
|
|
34473
|
+
function buildBox(doc, finding) {
|
|
34474
|
+
const color = colorFor(finding.impact);
|
|
34475
|
+
const box = doc.createElement("div");
|
|
34476
|
+
box.setAttribute("data-impact", finding.impact ?? "none");
|
|
34477
|
+
box.title = `${finding.id}: ${finding.help}`;
|
|
34478
|
+
Object.assign(box.style, {
|
|
34479
|
+
position: "fixed",
|
|
34480
|
+
boxSizing: "border-box",
|
|
34481
|
+
border: `2px solid ${color}`,
|
|
34482
|
+
borderRadius: "2px",
|
|
34483
|
+
background: `${color}1a`,
|
|
34484
|
+
// ~10% alpha
|
|
34485
|
+
pointerEvents: "auto",
|
|
34486
|
+
cursor: "pointer"
|
|
34487
|
+
});
|
|
34488
|
+
const label = doc.createElement("span");
|
|
34489
|
+
label.textContent = finding.component ? `${finding.component} \xB7 ${finding.id}` : finding.id;
|
|
34490
|
+
Object.assign(label.style, {
|
|
34491
|
+
position: "absolute",
|
|
34492
|
+
top: "0",
|
|
34493
|
+
left: "0",
|
|
34494
|
+
transform: "translateY(-100%)",
|
|
34495
|
+
padding: "1px 4px",
|
|
34496
|
+
font: "11px/1.4 ui-monospace, monospace",
|
|
34497
|
+
color: "#fff",
|
|
34498
|
+
background: color,
|
|
34499
|
+
whiteSpace: "nowrap"
|
|
34500
|
+
});
|
|
34501
|
+
box.appendChild(label);
|
|
34502
|
+
return box;
|
|
34503
|
+
}
|
|
34504
|
+
function resolveLabelStack(items, minTop = LABEL_MIN_TOP) {
|
|
34505
|
+
const order = items.map((it, i) => ({ it, i })).sort((a, b) => a.it.baseTop - b.it.baseTop || a.it.left - b.it.left);
|
|
34506
|
+
const placed = [];
|
|
34507
|
+
const tops = new Array(items.length);
|
|
34508
|
+
for (const { it, i } of order) {
|
|
34509
|
+
let top = it.baseTop;
|
|
34510
|
+
const hits = (t) => placed.some((p) => it.left < p.right && it.left + it.width > p.left && t < p.bottom && t + it.height > p.top);
|
|
34511
|
+
let guard = 0;
|
|
34512
|
+
while (hits(top) && top > minTop && guard++ < 60)
|
|
34513
|
+
top -= it.height + 2;
|
|
34514
|
+
tops[i] = top;
|
|
34515
|
+
placed.push({ left: it.left, right: it.left + it.width, top, bottom: top + it.height });
|
|
34516
|
+
}
|
|
34517
|
+
return tops;
|
|
34518
|
+
}
|
|
34519
|
+
function positionBox(box, target) {
|
|
34520
|
+
const rect = target.getBoundingClientRect();
|
|
34521
|
+
Object.assign(box.style, {
|
|
34522
|
+
top: `${rect.top}px`,
|
|
34523
|
+
left: `${rect.left}px`,
|
|
34524
|
+
width: `${rect.width}px`,
|
|
34525
|
+
height: `${rect.height}px`
|
|
34526
|
+
});
|
|
34527
|
+
}
|
|
34528
|
+
function flashAndScroll(target, box) {
|
|
34529
|
+
target.scrollIntoView({ block: "center", behavior: "smooth" });
|
|
34530
|
+
const original = box.style.boxShadow;
|
|
34531
|
+
box.style.boxShadow = "0 0 0 4px rgba(255,255,255,0.6)";
|
|
34532
|
+
box.ownerDocument.defaultView?.setTimeout(() => {
|
|
34533
|
+
box.style.boxShadow = original;
|
|
34534
|
+
}, 600);
|
|
34535
|
+
}
|
|
34536
|
+
|
|
34225
34537
|
// dist/keyboard/tab-sequence.js
|
|
34226
34538
|
var FOCUSABLE_SELECTOR = [
|
|
34227
34539
|
"a[href]",
|
|
@@ -34317,7 +34629,7 @@
|
|
|
34317
34629
|
function tabSequence(root = document, options = {}) {
|
|
34318
34630
|
const isVisible = options.isVisible ?? defaultIsVisible;
|
|
34319
34631
|
const prefixes = options.frameworkPrefixes ?? DEFAULT_FRAMEWORK_PREFIXES;
|
|
34320
|
-
const candidates = [...root.querySelectorAll(FOCUSABLE_SELECTOR)].filter((el) => isTabbable(el, isVisible));
|
|
34632
|
+
const candidates = [...root.querySelectorAll(FOCUSABLE_SELECTOR)].filter((el) => !el.closest(OVERLAY_EXCLUDE_SELECTOR) && isTabbable(el, isVisible));
|
|
34321
34633
|
const withMeta = candidates.map((element, domIndex) => ({
|
|
34322
34634
|
element,
|
|
34323
34635
|
domIndex,
|
|
@@ -34335,550 +34647,238 @@
|
|
|
34335
34647
|
positive: m.positive,
|
|
34336
34648
|
component: appComponentFromPath(componentPath, prefixes),
|
|
34337
34649
|
componentPath
|
|
34338
|
-
};
|
|
34339
|
-
});
|
|
34340
|
-
}
|
|
34341
|
-
function stopRect(el) {
|
|
34342
|
-
const box = el.getBoundingClientRect();
|
|
34343
|
-
const lines = el.getClientRects();
|
|
34344
|
-
if (lines.length === 0)
|
|
34345
|
-
return { top: box.top, left: box.left, right: box.right };
|
|
34346
|
-
const first = lines[0];
|
|
34347
|
-
const last = lines[lines.length - 1];
|
|
34348
|
-
return { top: first.top, left: first.left, right: box.right, endTop: last.top, endLeft: last.left };
|
|
34349
|
-
}
|
|
34350
|
-
function visualOrderJumps(stops, getRect = stopRect, rowThreshold = 8) {
|
|
34351
|
-
const jumps = [];
|
|
34352
|
-
for (let i = 1; i < stops.length; i++) {
|
|
34353
|
-
const prev = getRect(stops[i - 1].element);
|
|
34354
|
-
const curr = getRect(stops[i].element);
|
|
34355
|
-
const prevTop = prev.endTop ?? prev.top;
|
|
34356
|
-
const prevLeft = prev.endLeft ?? prev.left;
|
|
34357
|
-
const movedUp = curr.top < prevTop - rowThreshold;
|
|
34358
|
-
const nextColumn = curr.left >= (prev.right ?? prev.left + rowThreshold);
|
|
34359
|
-
const sameRowMovedLeft = Math.abs(curr.top - prevTop) <= rowThreshold && curr.left < prevLeft - rowThreshold;
|
|
34360
|
-
if (movedUp && !nextColumn || sameRowMovedLeft)
|
|
34361
|
-
jumps.push(i);
|
|
34362
|
-
}
|
|
34363
|
-
return jumps;
|
|
34364
|
-
}
|
|
34365
|
-
|
|
34366
|
-
// dist/keyboard/focus-trap.js
|
|
34367
|
-
function findUncontainedModals(root = document, options = {}) {
|
|
34368
|
-
const stops = tabSequence(root, options);
|
|
34369
|
-
if (stops.length === 0)
|
|
34370
|
-
return [];
|
|
34371
|
-
const results = [];
|
|
34372
|
-
for (const modal of root.querySelectorAll('[aria-modal="true"]')) {
|
|
34373
|
-
let insideCount = 0;
|
|
34374
|
-
let outsideCount = 0;
|
|
34375
|
-
for (const stop of stops) {
|
|
34376
|
-
if (modal.contains(stop.element))
|
|
34377
|
-
insideCount++;
|
|
34378
|
-
else
|
|
34379
|
-
outsideCount++;
|
|
34380
|
-
}
|
|
34381
|
-
if (insideCount > 0 && outsideCount > 0)
|
|
34382
|
-
results.push({ element: modal, insideCount, outsideCount });
|
|
34383
|
-
}
|
|
34384
|
-
return results;
|
|
34385
|
-
}
|
|
34386
|
-
|
|
34387
|
-
// dist/keyboard/keyboard-scan.js
|
|
34388
|
-
var INTERACTIVE_ROLES = /* @__PURE__ */ new Set([
|
|
34389
|
-
"button",
|
|
34390
|
-
"link",
|
|
34391
|
-
"menuitem",
|
|
34392
|
-
"menuitemcheckbox",
|
|
34393
|
-
"menuitemradio",
|
|
34394
|
-
"tab",
|
|
34395
|
-
"switch",
|
|
34396
|
-
"checkbox",
|
|
34397
|
-
"radio",
|
|
34398
|
-
"option",
|
|
34399
|
-
"slider",
|
|
34400
|
-
"spinbutton",
|
|
34401
|
-
"combobox",
|
|
34402
|
-
"textbox",
|
|
34403
|
-
"searchbox",
|
|
34404
|
-
"treeitem"
|
|
34405
|
-
]);
|
|
34406
|
-
var KEY_EVENTS = ["keydown", "keyup", "keypress"];
|
|
34407
|
-
var UNDERSTANDING = "https://www.w3.org/WAI/WCAG22/Understanding";
|
|
34408
|
-
var KEYBOARD_URL = `${UNDERSTANDING}/keyboard.html`;
|
|
34409
|
-
var FOCUS_ORDER_URL = `${UNDERSTANDING}/focus-order.html`;
|
|
34410
|
-
var DIALOG_MODAL_URL = "https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/";
|
|
34411
|
-
function shortSelector(element) {
|
|
34412
|
-
const tag = element.tagName.toLowerCase();
|
|
34413
|
-
if (element.id)
|
|
34414
|
-
return `${tag}#${element.id}`;
|
|
34415
|
-
const classes = (element.getAttribute("class") ?? "").trim().split(/\s+/).filter(Boolean).slice(0, 2);
|
|
34416
|
-
return classes.length ? `${tag}.${classes.join(".")}` : tag;
|
|
34417
|
-
}
|
|
34418
|
-
function shortHtml(element) {
|
|
34419
|
-
const html = element.outerHTML ?? "";
|
|
34420
|
-
return html.length > 160 ? `${html.slice(0, 159)}\u2026` : html;
|
|
34421
|
-
}
|
|
34422
|
-
function scanKeyboard(root = document, options = {}) {
|
|
34423
|
-
const prefixes = options.frameworkPrefixes ?? DEFAULT_FRAMEWORK_PREFIXES;
|
|
34424
|
-
const isVisible = options.isVisible;
|
|
34425
|
-
const findings = [];
|
|
34426
|
-
const make = (element, id, impact, help, helpUrl) => {
|
|
34427
|
-
const componentPath = resolveComponentPath(element);
|
|
34428
|
-
return {
|
|
34429
|
-
id,
|
|
34430
|
-
impact,
|
|
34431
|
-
help,
|
|
34432
|
-
helpUrl,
|
|
34433
|
-
component: appComponentFromPath(componentPath, prefixes),
|
|
34434
|
-
componentPath,
|
|
34435
|
-
directives: resolveDirectiveNames(element),
|
|
34436
|
-
target: shortSelector(element),
|
|
34437
|
-
html: shortHtml(element)
|
|
34438
|
-
};
|
|
34439
|
-
};
|
|
34440
|
-
for (const element of root.querySelectorAll("*")) {
|
|
34441
|
-
if (isNativelyFocusable(element))
|
|
34442
|
-
continue;
|
|
34443
|
-
const role = element.getAttribute("role")?.toLowerCase() ?? "";
|
|
34444
|
-
const events = resolveListenerEvents(element);
|
|
34445
|
-
const hasClick = events.includes("click");
|
|
34446
|
-
const interactiveByRole = INTERACTIVE_ROLES.has(role);
|
|
34447
|
-
if (!hasClick && !interactiveByRole)
|
|
34448
|
-
continue;
|
|
34449
|
-
if (!interactiveByRole && hasFocusableDescendant(element))
|
|
34450
|
-
continue;
|
|
34451
|
-
const focusable = isTabbable(element, isVisible);
|
|
34452
|
-
if (!focusable) {
|
|
34453
|
-
const reason = interactiveByRole ? `has role="${role}"` : "has a click handler";
|
|
34454
|
-
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));
|
|
34455
|
-
continue;
|
|
34456
|
-
}
|
|
34457
|
-
const hasKey = events.some((e) => KEY_EVENTS.includes(e));
|
|
34458
|
-
if (hasClick && !hasKey) {
|
|
34459
|
-
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));
|
|
34460
|
-
}
|
|
34461
|
-
}
|
|
34462
|
-
for (const modal of findUncontainedModals(root, { frameworkPrefixes: prefixes, isVisible })) {
|
|
34463
|
-
findings.push(make(modal.element, "ngbr/modal-focus-not-contained", "moderate", `Possible missing focus trap: this element has aria-modal="true", but ${modal.outsideCount} tabbable element(s) outside it are still reachable, so a keyboard user can Tab out of the modal to the page behind. Mark the background inert or trap focus within the dialog. Heuristic \u2014 verify manually.`, DIALOG_MODAL_URL));
|
|
34464
|
-
}
|
|
34465
|
-
const stops = tabSequence(root, { frameworkPrefixes: prefixes, isVisible });
|
|
34466
|
-
for (const jump of visualOrderJumps(stops)) {
|
|
34467
|
-
const stop = stops[jump];
|
|
34468
|
-
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));
|
|
34469
|
-
}
|
|
34470
|
-
return findings;
|
|
34471
|
-
}
|
|
34472
|
-
|
|
34473
|
-
// dist/keyboard/focus-walk.js
|
|
34474
|
-
function detectTabTrap(observations, collapsible = /* @__PURE__ */ new Set()) {
|
|
34475
|
-
const seq = [];
|
|
34476
|
-
for (const obs of observations) {
|
|
34477
|
-
const prev = seq[seq.length - 1];
|
|
34478
|
-
if (obs !== null && obs === prev && collapsible.has(obs))
|
|
34479
|
-
continue;
|
|
34480
|
-
seq.push(obs);
|
|
34481
|
-
}
|
|
34482
|
-
const lastSeen = /* @__PURE__ */ new Map();
|
|
34483
|
-
for (let i = 0; i < seq.length; i++) {
|
|
34484
|
-
const id = seq[i];
|
|
34485
|
-
if (id === null)
|
|
34486
|
-
continue;
|
|
34487
|
-
const before = lastSeen.get(id);
|
|
34488
|
-
if (before !== void 0) {
|
|
34489
|
-
const between = seq.slice(before, i);
|
|
34490
|
-
if (between.includes(null))
|
|
34491
|
-
return { kind: "complete" };
|
|
34492
|
-
return { kind: "trap", cycle: between };
|
|
34493
|
-
}
|
|
34494
|
-
lastSeen.set(id, i);
|
|
34495
|
-
}
|
|
34496
|
-
return { kind: "pending" };
|
|
34497
|
-
}
|
|
34498
|
-
var NO_KEYBOARD_TRAP_URL = "https://www.w3.org/WAI/WCAG22/Understanding/no-keyboard-trap.html";
|
|
34499
|
-
function deepActiveElement(doc) {
|
|
34500
|
-
let active = doc.activeElement;
|
|
34501
|
-
while (active?.shadowRoot?.activeElement)
|
|
34502
|
-
active = active.shadowRoot.activeElement;
|
|
34503
|
-
return active;
|
|
34504
|
-
}
|
|
34505
|
-
function containedByOpenModal(elements) {
|
|
34506
|
-
const modalOf = (el) => {
|
|
34507
|
-
const aria = el.closest('[aria-modal="true"]');
|
|
34508
|
-
if (aria)
|
|
34509
|
-
return aria;
|
|
34510
|
-
try {
|
|
34511
|
-
return el.closest("dialog:modal");
|
|
34512
|
-
} catch {
|
|
34513
|
-
return null;
|
|
34514
|
-
}
|
|
34515
|
-
};
|
|
34516
|
-
const first = elements[0] ? modalOf(elements[0]) : null;
|
|
34517
|
-
return first !== null && elements.every((el) => modalOf(el) === first);
|
|
34518
|
-
}
|
|
34519
|
-
function commonAncestor(elements) {
|
|
34520
|
-
let candidate = elements[0];
|
|
34521
|
-
while (candidate && !elements.every((el) => candidate.contains(el))) {
|
|
34522
|
-
candidate = candidate.parentElement;
|
|
34523
|
-
}
|
|
34524
|
-
return candidate ?? elements[0];
|
|
34525
|
-
}
|
|
34526
|
-
function createFocusWalkProbe(doc = document, frameworkPrefixes = DEFAULT_FRAMEWORK_PREFIXES) {
|
|
34527
|
-
const ids = /* @__PURE__ */ new WeakMap();
|
|
34528
|
-
const byId = /* @__PURE__ */ new Map();
|
|
34529
|
-
return {
|
|
34530
|
-
probe() {
|
|
34531
|
-
const active = deepActiveElement(doc);
|
|
34532
|
-
if (!active || active === doc.body || active === doc.documentElement) {
|
|
34533
|
-
return { id: null, iframe: false };
|
|
34534
|
-
}
|
|
34535
|
-
let id = ids.get(active);
|
|
34536
|
-
if (id === void 0) {
|
|
34537
|
-
id = byId.size + 1;
|
|
34538
|
-
ids.set(active, id);
|
|
34539
|
-
byId.set(id, active);
|
|
34540
|
-
}
|
|
34541
|
-
return { id, iframe: active.tagName === "IFRAME" };
|
|
34542
|
-
},
|
|
34543
|
-
stopCount() {
|
|
34544
|
-
return tabSequence(doc, { frameworkPrefixes }).length;
|
|
34545
|
-
},
|
|
34546
|
-
trapFinding(cycle, shiftTabEscapes) {
|
|
34547
|
-
const elements = [...new Set(cycle)].map((id) => byId.get(id)).filter((el) => el !== void 0);
|
|
34548
|
-
if (elements.length === 0 || containedByOpenModal(elements))
|
|
34549
|
-
return null;
|
|
34550
|
-
const owner = elements.length === 1 ? elements[0] : commonAncestor(elements);
|
|
34551
|
-
const reachable = new Set(byId.values());
|
|
34552
|
-
const unreached = tabSequence(doc, { frameworkPrefixes }).filter((stop) => !reachable.has(stop.element)).length;
|
|
34553
|
-
const where = elements.length === 1 ? "focus stays on this element when Tab is pressed" : `Tab cycles through ${elements.length} controls inside this element and never leaves`;
|
|
34554
|
-
const reach = unreached > 0 ? `, so ${unreached} tabbable control(s) in the page are never reached` : "";
|
|
34555
|
-
const shift = shiftTabEscapes ? " Shift+Tab does get out, but Tab alone should too." : " Shift+Tab doesn't get out either.";
|
|
34556
|
-
const componentPath = resolveComponentPath(owner);
|
|
34557
|
-
return {
|
|
34558
|
-
id: "ngbr/focus-trap",
|
|
34559
|
-
impact: shiftTabEscapes ? "moderate" : "serious",
|
|
34560
|
-
help: `Possible keyboard trap: ${where}${reach}.${shift} If this widget deliberately keeps Tab (e.g. a code editor), it must tell users how to leave (such as Escape); otherwise let Tab move focus on. Found by real Tab presses \u2014 verify manually.`,
|
|
34561
|
-
helpUrl: NO_KEYBOARD_TRAP_URL,
|
|
34562
|
-
component: appComponentFromPath(componentPath, frameworkPrefixes),
|
|
34563
|
-
componentPath,
|
|
34564
|
-
directives: resolveDirectiveNames(owner),
|
|
34565
|
-
target: shortSelector(owner),
|
|
34566
|
-
html: shortHtml(owner)
|
|
34567
|
-
};
|
|
34568
|
-
}
|
|
34569
|
-
};
|
|
34650
|
+
};
|
|
34651
|
+
});
|
|
34570
34652
|
}
|
|
34571
|
-
|
|
34572
|
-
|
|
34573
|
-
|
|
34574
|
-
|
|
34575
|
-
|
|
34576
|
-
|
|
34577
|
-
|
|
34578
|
-
|
|
34579
|
-
var OVERLAY_ATTR = "data-ngb-a11y-overlay";
|
|
34580
|
-
var OVERLAY_EXCLUDE_SELECTOR = `[${OVERLAY_ATTR}]`;
|
|
34581
|
-
var IMPACT_COLOR = {
|
|
34582
|
-
critical: "#d32029",
|
|
34583
|
-
serious: "#e8710a",
|
|
34584
|
-
moderate: "#c9a227",
|
|
34585
|
-
minor: "#3b7dd8",
|
|
34586
|
-
none: "#8a8a8a"
|
|
34587
|
-
};
|
|
34588
|
-
function colorFor(impact) {
|
|
34589
|
-
return IMPACT_COLOR[impact ?? "none"];
|
|
34653
|
+
function stopRect(el) {
|
|
34654
|
+
const box = el.getBoundingClientRect();
|
|
34655
|
+
const lines = el.getClientRects();
|
|
34656
|
+
if (lines.length === 0)
|
|
34657
|
+
return { top: box.top, left: box.left, right: box.right };
|
|
34658
|
+
const first = lines[0];
|
|
34659
|
+
const last = lines[lines.length - 1];
|
|
34660
|
+
return { top: first.top, left: first.left, right: box.right, endTop: last.top, endLeft: last.left };
|
|
34590
34661
|
}
|
|
34591
|
-
function
|
|
34592
|
-
const
|
|
34593
|
-
|
|
34594
|
-
|
|
34595
|
-
|
|
34596
|
-
|
|
34597
|
-
|
|
34598
|
-
|
|
34599
|
-
|
|
34600
|
-
|
|
34601
|
-
|
|
34602
|
-
|
|
34603
|
-
const svg = doc.createElementNS(SVG_NS, "svg");
|
|
34604
|
-
svg.setAttribute(OVERLAY_ATTR, "");
|
|
34605
|
-
Object.assign(svg.style, {
|
|
34606
|
-
position: "fixed",
|
|
34607
|
-
inset: "0",
|
|
34608
|
-
width: "100%",
|
|
34609
|
-
height: "100%",
|
|
34610
|
-
pointerEvents: "none",
|
|
34611
|
-
overflow: "visible"
|
|
34612
|
-
});
|
|
34613
|
-
const connector = doc.createElementNS(SVG_NS, "polyline");
|
|
34614
|
-
connector.setAttribute("fill", "none");
|
|
34615
|
-
connector.setAttribute("stroke", TAB_ORDER_COLOR);
|
|
34616
|
-
connector.setAttribute("stroke-width", "2");
|
|
34617
|
-
connector.setAttribute("stroke-dasharray", "4 3");
|
|
34618
|
-
connector.setAttribute("opacity", "0.7");
|
|
34619
|
-
svg.appendChild(connector);
|
|
34620
|
-
container.appendChild(svg);
|
|
34621
|
-
const axPanel = doc.createElement("div");
|
|
34622
|
-
axPanel.setAttribute(OVERLAY_ATTR, "");
|
|
34623
|
-
Object.assign(axPanel.style, {
|
|
34624
|
-
position: "fixed",
|
|
34625
|
-
right: "12px",
|
|
34626
|
-
bottom: "12px",
|
|
34627
|
-
maxWidth: "320px",
|
|
34628
|
-
padding: "8px 10px",
|
|
34629
|
-
borderRadius: "6px",
|
|
34630
|
-
background: "rgba(20,22,28,0.94)",
|
|
34631
|
-
color: "#f4f4f5",
|
|
34632
|
-
font: "12px/1.5 ui-sans-serif, system-ui, sans-serif",
|
|
34633
|
-
boxShadow: "0 2px 12px rgba(0,0,0,0.4)",
|
|
34634
|
-
pointerEvents: "none",
|
|
34635
|
-
zIndex: "2147483647",
|
|
34636
|
-
display: "none"
|
|
34637
|
-
});
|
|
34638
|
-
container.appendChild(axPanel);
|
|
34639
|
-
let highlights = [];
|
|
34640
|
-
let tabBadges = [];
|
|
34641
|
-
const reposition = () => {
|
|
34642
|
-
for (const { target, box } of highlights) {
|
|
34643
|
-
positionBox(box, target);
|
|
34644
|
-
}
|
|
34645
|
-
decollideLabels();
|
|
34646
|
-
repositionTabOrder();
|
|
34647
|
-
};
|
|
34648
|
-
function decollideLabels() {
|
|
34649
|
-
const labels = [];
|
|
34650
|
-
const boxes = [];
|
|
34651
|
-
for (const { target, box } of highlights) {
|
|
34652
|
-
const label = box.firstElementChild;
|
|
34653
|
-
if (!label)
|
|
34654
|
-
continue;
|
|
34655
|
-
const rect = target.getBoundingClientRect();
|
|
34656
|
-
labels.push(label);
|
|
34657
|
-
boxes.push({ left: rect.left, width: label.offsetWidth, baseTop: rect.top - label.offsetHeight, height: label.offsetHeight });
|
|
34658
|
-
}
|
|
34659
|
-
const tops = resolveLabelStack(boxes);
|
|
34660
|
-
for (let i = 0; i < labels.length; i++) {
|
|
34661
|
-
const extraUp = boxes[i].baseTop - tops[i];
|
|
34662
|
-
labels[i].style.transform = extraUp > 0 ? `translateY(calc(-100% - ${extraUp}px))` : "translateY(-100%)";
|
|
34663
|
-
}
|
|
34662
|
+
function visualOrderJumps(stops, getRect = stopRect, rowThreshold = 8) {
|
|
34663
|
+
const jumps = [];
|
|
34664
|
+
for (let i = 1; i < stops.length; i++) {
|
|
34665
|
+
const prev = getRect(stops[i - 1].element);
|
|
34666
|
+
const curr = getRect(stops[i].element);
|
|
34667
|
+
const prevTop = prev.endTop ?? prev.top;
|
|
34668
|
+
const prevLeft = prev.endLeft ?? prev.left;
|
|
34669
|
+
const movedUp = curr.top < prevTop - rowThreshold;
|
|
34670
|
+
const nextColumn = curr.left >= (prev.right ?? prev.left + rowThreshold);
|
|
34671
|
+
const sameRowMovedLeft = Math.abs(curr.top - prevTop) <= rowThreshold && curr.left < prevLeft - rowThreshold;
|
|
34672
|
+
if (movedUp && !nextColumn || sameRowMovedLeft)
|
|
34673
|
+
jumps.push(i);
|
|
34664
34674
|
}
|
|
34665
|
-
|
|
34666
|
-
|
|
34667
|
-
|
|
34668
|
-
|
|
34669
|
-
|
|
34670
|
-
|
|
34671
|
-
|
|
34672
|
-
|
|
34673
|
-
|
|
34675
|
+
return jumps;
|
|
34676
|
+
}
|
|
34677
|
+
|
|
34678
|
+
// dist/keyboard/focus-trap.js
|
|
34679
|
+
function findUncontainedModals(root = document, options = {}) {
|
|
34680
|
+
const stops = tabSequence(root, options);
|
|
34681
|
+
if (stops.length === 0)
|
|
34682
|
+
return [];
|
|
34683
|
+
const results = [];
|
|
34684
|
+
for (const modal of root.querySelectorAll('[aria-modal="true"]')) {
|
|
34685
|
+
let insideCount = 0;
|
|
34686
|
+
let outsideCount = 0;
|
|
34687
|
+
for (const stop of stops) {
|
|
34688
|
+
if (modal.contains(stop.element))
|
|
34689
|
+
insideCount++;
|
|
34690
|
+
else
|
|
34691
|
+
outsideCount++;
|
|
34674
34692
|
}
|
|
34675
|
-
|
|
34693
|
+
if (insideCount > 0 && outsideCount > 0)
|
|
34694
|
+
results.push({ element: modal, insideCount, outsideCount });
|
|
34676
34695
|
}
|
|
34677
|
-
|
|
34678
|
-
|
|
34679
|
-
|
|
34680
|
-
|
|
34681
|
-
|
|
34682
|
-
|
|
34683
|
-
|
|
34684
|
-
|
|
34685
|
-
|
|
34686
|
-
|
|
34687
|
-
|
|
34688
|
-
|
|
34689
|
-
|
|
34690
|
-
|
|
34696
|
+
return results;
|
|
34697
|
+
}
|
|
34698
|
+
|
|
34699
|
+
// dist/keyboard/keyboard-scan.js
|
|
34700
|
+
var INTERACTIVE_ROLES = /* @__PURE__ */ new Set([
|
|
34701
|
+
"button",
|
|
34702
|
+
"link",
|
|
34703
|
+
"menuitem",
|
|
34704
|
+
"menuitemcheckbox",
|
|
34705
|
+
"menuitemradio",
|
|
34706
|
+
"tab",
|
|
34707
|
+
"switch",
|
|
34708
|
+
"checkbox",
|
|
34709
|
+
"radio",
|
|
34710
|
+
"option",
|
|
34711
|
+
"slider",
|
|
34712
|
+
"spinbutton",
|
|
34713
|
+
"combobox",
|
|
34714
|
+
"textbox",
|
|
34715
|
+
"searchbox",
|
|
34716
|
+
"treeitem"
|
|
34717
|
+
]);
|
|
34718
|
+
var KEY_EVENTS = ["keydown", "keyup", "keypress"];
|
|
34719
|
+
var UNDERSTANDING = "https://www.w3.org/WAI/WCAG22/Understanding";
|
|
34720
|
+
var KEYBOARD_URL = `${UNDERSTANDING}/keyboard.html`;
|
|
34721
|
+
var FOCUS_ORDER_URL = `${UNDERSTANDING}/focus-order.html`;
|
|
34722
|
+
var DIALOG_MODAL_URL = "https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/";
|
|
34723
|
+
function shortSelector(element) {
|
|
34724
|
+
const tag = element.tagName.toLowerCase();
|
|
34725
|
+
if (element.id)
|
|
34726
|
+
return `${tag}#${element.id}`;
|
|
34727
|
+
const classes = (element.getAttribute("class") ?? "").trim().split(/\s+/).filter(Boolean).slice(0, 2);
|
|
34728
|
+
return classes.length ? `${tag}.${classes.join(".")}` : tag;
|
|
34729
|
+
}
|
|
34730
|
+
function shortHtml(element) {
|
|
34731
|
+
const html = element.outerHTML ?? "";
|
|
34732
|
+
return html.length > 160 ? `${html.slice(0, 159)}\u2026` : html;
|
|
34733
|
+
}
|
|
34734
|
+
function scanKeyboard(root = document, options = {}) {
|
|
34735
|
+
const prefixes = options.frameworkPrefixes ?? DEFAULT_FRAMEWORK_PREFIXES;
|
|
34736
|
+
const isVisible = options.isVisible;
|
|
34737
|
+
const findings = [];
|
|
34738
|
+
const make = (element, id, impact, help, helpUrl) => {
|
|
34739
|
+
const componentPath = resolveComponentPath(element);
|
|
34740
|
+
return {
|
|
34741
|
+
id,
|
|
34742
|
+
impact,
|
|
34743
|
+
help,
|
|
34744
|
+
helpUrl,
|
|
34745
|
+
component: appComponentFromPath(componentPath, prefixes),
|
|
34746
|
+
componentPath,
|
|
34747
|
+
directives: resolveDirectiveNames(element),
|
|
34748
|
+
target: shortSelector(element),
|
|
34749
|
+
html: shortHtml(element)
|
|
34750
|
+
};
|
|
34691
34751
|
};
|
|
34692
|
-
const
|
|
34693
|
-
|
|
34694
|
-
|
|
34695
|
-
|
|
34696
|
-
|
|
34697
|
-
|
|
34698
|
-
|
|
34699
|
-
|
|
34700
|
-
|
|
34701
|
-
|
|
34702
|
-
|
|
34703
|
-
|
|
34704
|
-
|
|
34705
|
-
|
|
34706
|
-
|
|
34707
|
-
|
|
34708
|
-
container.appendChild(box);
|
|
34709
|
-
positionBox(box, target);
|
|
34710
|
-
highlights.push({ finding, target, box });
|
|
34711
|
-
}
|
|
34712
|
-
decollideLabels();
|
|
34713
|
-
}
|
|
34714
|
-
function clearTabOrder() {
|
|
34715
|
-
for (const { badge } of tabBadges)
|
|
34716
|
-
badge.remove();
|
|
34717
|
-
tabBadges = [];
|
|
34718
|
-
connector.setAttribute("points", "");
|
|
34719
|
-
}
|
|
34720
|
-
function renderTabOrder(stops) {
|
|
34721
|
-
clearTabOrder();
|
|
34722
|
-
for (const stop of stops) {
|
|
34723
|
-
const target = stop.element;
|
|
34724
|
-
if (!target.isConnected)
|
|
34725
|
-
continue;
|
|
34726
|
-
const badge = buildBadge(doc, stop);
|
|
34727
|
-
container.appendChild(badge);
|
|
34728
|
-
tabBadges.push({ stop, target, badge });
|
|
34752
|
+
for (const element of root.querySelectorAll("*")) {
|
|
34753
|
+
if (isNativelyFocusable(element))
|
|
34754
|
+
continue;
|
|
34755
|
+
const role = element.getAttribute("role")?.toLowerCase() ?? "";
|
|
34756
|
+
const events = resolveListenerEvents(element);
|
|
34757
|
+
const hasClick = events.includes("click");
|
|
34758
|
+
const interactiveByRole = INTERACTIVE_ROLES.has(role);
|
|
34759
|
+
if (!hasClick && !interactiveByRole)
|
|
34760
|
+
continue;
|
|
34761
|
+
if (!interactiveByRole && hasFocusableDescendant(element))
|
|
34762
|
+
continue;
|
|
34763
|
+
const focusable = isTabbable(element, isVisible);
|
|
34764
|
+
if (!focusable) {
|
|
34765
|
+
const reason = interactiveByRole ? `has role="${role}"` : "has a click handler";
|
|
34766
|
+
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));
|
|
34767
|
+
continue;
|
|
34729
34768
|
}
|
|
34730
|
-
|
|
34731
|
-
|
|
34732
|
-
|
|
34733
|
-
if (!data) {
|
|
34734
|
-
axPanel.style.display = "none";
|
|
34735
|
-
axPanel.replaceChildren();
|
|
34736
|
-
return;
|
|
34769
|
+
const hasKey = events.some((e) => KEY_EVENTS.includes(e));
|
|
34770
|
+
if (hasClick && !hasKey) {
|
|
34771
|
+
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));
|
|
34737
34772
|
}
|
|
34738
|
-
axPanel.replaceChildren(...buildAxPanelContent(doc, data));
|
|
34739
|
-
axPanel.style.display = "block";
|
|
34740
34773
|
}
|
|
34741
|
-
|
|
34742
|
-
|
|
34743
|
-
clearTabOrder();
|
|
34744
|
-
renderAxPanel(null);
|
|
34745
|
-
win?.removeEventListener("scroll", onViewportChange, { capture: true });
|
|
34746
|
-
win?.removeEventListener("resize", onViewportChange);
|
|
34747
|
-
container.remove();
|
|
34774
|
+
for (const modal of findUncontainedModals(root, { frameworkPrefixes: prefixes, isVisible })) {
|
|
34775
|
+
findings.push(make(modal.element, "ngbr/modal-focus-not-contained", "moderate", `Possible missing focus trap: this element has aria-modal="true", but ${modal.outsideCount} tabbable element(s) outside it are still reachable, so a keyboard user can Tab out of the modal to the page behind. Mark the background inert or trap focus within the dialog. Heuristic \u2014 verify manually.`, DIALOG_MODAL_URL));
|
|
34748
34776
|
}
|
|
34749
|
-
|
|
34750
|
-
|
|
34751
|
-
|
|
34752
|
-
|
|
34753
|
-
|
|
34754
|
-
|
|
34755
|
-
Object.assign(header.style, {
|
|
34756
|
-
fontWeight: "700",
|
|
34757
|
-
fontSize: "10px",
|
|
34758
|
-
letterSpacing: "0.02em",
|
|
34759
|
-
textTransform: "uppercase",
|
|
34760
|
-
color: "#a9b0bd",
|
|
34761
|
-
marginBottom: "4px"
|
|
34762
|
-
});
|
|
34763
|
-
header.title = "A computed name/role/state \u2014 an approximation of what assistive tech announces, not any one screen reader.";
|
|
34764
|
-
nodes.push(header);
|
|
34765
|
-
const row = (label, value, muted = false) => {
|
|
34766
|
-
const div = doc.createElement("div");
|
|
34767
|
-
const key = doc.createElement("span");
|
|
34768
|
-
key.textContent = `${label}: `;
|
|
34769
|
-
key.style.color = "#a9b0bd";
|
|
34770
|
-
const val = doc.createElement("span");
|
|
34771
|
-
val.textContent = value;
|
|
34772
|
-
if (muted)
|
|
34773
|
-
val.style.color = "#e8710a";
|
|
34774
|
-
div.append(key, val);
|
|
34775
|
-
return div;
|
|
34776
|
-
};
|
|
34777
|
-
nodes.push(row("role", data.role ?? `(none \u2014 <${data.tag}>)`));
|
|
34778
|
-
nodes.push(data.name ? row("name", `"${data.name}"`) : row("name", "(no accessible name)", true));
|
|
34779
|
-
if (data.description)
|
|
34780
|
-
nodes.push(row("description", `"${data.description}"`));
|
|
34781
|
-
if (data.states.length)
|
|
34782
|
-
nodes.push(row("states", data.states.join(", ")));
|
|
34783
|
-
if (data.component)
|
|
34784
|
-
nodes.push(row("component", data.component));
|
|
34785
|
-
return nodes;
|
|
34786
|
-
}
|
|
34787
|
-
function buildBadge(doc, stop) {
|
|
34788
|
-
const color = stop.positive ? TAB_ORDER_WARN_COLOR : TAB_ORDER_COLOR;
|
|
34789
|
-
const badge = doc.createElement("div");
|
|
34790
|
-
badge.setAttribute("data-ngb-tab-order", String(stop.order));
|
|
34791
|
-
const owner = stop.component ? ` \xB7 ${stop.component}` : "";
|
|
34792
|
-
const ti = stop.positive ? ` \xB7 tabindex=${stop.tabindex} (hijacks order)` : "";
|
|
34793
|
-
badge.title = `Tab stop ${stop.order}${owner}${ti}`;
|
|
34794
|
-
badge.textContent = String(stop.order);
|
|
34795
|
-
Object.assign(badge.style, {
|
|
34796
|
-
position: "fixed",
|
|
34797
|
-
transform: "translate(-50%, -50%)",
|
|
34798
|
-
minWidth: "16px",
|
|
34799
|
-
height: "16px",
|
|
34800
|
-
padding: "0 3px",
|
|
34801
|
-
boxSizing: "border-box",
|
|
34802
|
-
borderRadius: "8px",
|
|
34803
|
-
font: "10px/16px ui-monospace, monospace",
|
|
34804
|
-
fontWeight: "700",
|
|
34805
|
-
textAlign: "center",
|
|
34806
|
-
color: "#fff",
|
|
34807
|
-
background: color,
|
|
34808
|
-
border: "1px solid rgba(255,255,255,0.85)",
|
|
34809
|
-
pointerEvents: "none"
|
|
34810
|
-
});
|
|
34811
|
-
return badge;
|
|
34777
|
+
const stops = tabSequence(root, { frameworkPrefixes: prefixes, isVisible });
|
|
34778
|
+
for (const jump of visualOrderJumps(stops)) {
|
|
34779
|
+
const stop = stops[jump];
|
|
34780
|
+
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));
|
|
34781
|
+
}
|
|
34782
|
+
return findings;
|
|
34812
34783
|
}
|
|
34813
|
-
|
|
34814
|
-
|
|
34815
|
-
|
|
34816
|
-
|
|
34817
|
-
|
|
34784
|
+
|
|
34785
|
+
// dist/keyboard/focus-walk.js
|
|
34786
|
+
function detectTabTrap(observations, collapsible = /* @__PURE__ */ new Set()) {
|
|
34787
|
+
const seq = [];
|
|
34788
|
+
for (const obs of observations) {
|
|
34789
|
+
const prev = seq[seq.length - 1];
|
|
34790
|
+
if (obs !== null && obs === prev && collapsible.has(obs))
|
|
34791
|
+
continue;
|
|
34792
|
+
seq.push(obs);
|
|
34793
|
+
}
|
|
34794
|
+
const lastSeen = /* @__PURE__ */ new Map();
|
|
34795
|
+
for (let i = 0; i < seq.length; i++) {
|
|
34796
|
+
const id = seq[i];
|
|
34797
|
+
if (id === null)
|
|
34798
|
+
continue;
|
|
34799
|
+
const before = lastSeen.get(id);
|
|
34800
|
+
if (before !== void 0) {
|
|
34801
|
+
const between = seq.slice(before, i);
|
|
34802
|
+
if (between.includes(null))
|
|
34803
|
+
return { kind: "complete" };
|
|
34804
|
+
return { kind: "trap", cycle: between };
|
|
34805
|
+
}
|
|
34806
|
+
lastSeen.set(id, i);
|
|
34818
34807
|
}
|
|
34808
|
+
return { kind: "pending" };
|
|
34819
34809
|
}
|
|
34820
|
-
|
|
34821
|
-
|
|
34822
|
-
|
|
34823
|
-
|
|
34824
|
-
|
|
34825
|
-
|
|
34826
|
-
position: "fixed",
|
|
34827
|
-
boxSizing: "border-box",
|
|
34828
|
-
border: `2px solid ${color}`,
|
|
34829
|
-
borderRadius: "2px",
|
|
34830
|
-
background: `${color}1a`,
|
|
34831
|
-
// ~10% alpha
|
|
34832
|
-
pointerEvents: "auto",
|
|
34833
|
-
cursor: "pointer"
|
|
34834
|
-
});
|
|
34835
|
-
const label = doc.createElement("span");
|
|
34836
|
-
label.textContent = finding.component ? `${finding.component} \xB7 ${finding.id}` : finding.id;
|
|
34837
|
-
Object.assign(label.style, {
|
|
34838
|
-
position: "absolute",
|
|
34839
|
-
top: "0",
|
|
34840
|
-
left: "0",
|
|
34841
|
-
transform: "translateY(-100%)",
|
|
34842
|
-
padding: "1px 4px",
|
|
34843
|
-
font: "11px/1.4 ui-monospace, monospace",
|
|
34844
|
-
color: "#fff",
|
|
34845
|
-
background: color,
|
|
34846
|
-
whiteSpace: "nowrap"
|
|
34847
|
-
});
|
|
34848
|
-
box.appendChild(label);
|
|
34849
|
-
return box;
|
|
34810
|
+
var NO_KEYBOARD_TRAP_URL = "https://www.w3.org/WAI/WCAG22/Understanding/no-keyboard-trap.html";
|
|
34811
|
+
function deepActiveElement(doc) {
|
|
34812
|
+
let active = doc.activeElement;
|
|
34813
|
+
while (active?.shadowRoot?.activeElement)
|
|
34814
|
+
active = active.shadowRoot.activeElement;
|
|
34815
|
+
return active;
|
|
34850
34816
|
}
|
|
34851
|
-
function
|
|
34852
|
-
const
|
|
34853
|
-
|
|
34854
|
-
|
|
34855
|
-
|
|
34856
|
-
|
|
34857
|
-
|
|
34858
|
-
|
|
34859
|
-
|
|
34860
|
-
|
|
34861
|
-
|
|
34862
|
-
|
|
34863
|
-
|
|
34864
|
-
return tops;
|
|
34817
|
+
function containedByOpenModal(elements) {
|
|
34818
|
+
const modalOf = (el) => {
|
|
34819
|
+
const aria = el.closest('[aria-modal="true"]');
|
|
34820
|
+
if (aria)
|
|
34821
|
+
return aria;
|
|
34822
|
+
try {
|
|
34823
|
+
return el.closest("dialog:modal");
|
|
34824
|
+
} catch {
|
|
34825
|
+
return null;
|
|
34826
|
+
}
|
|
34827
|
+
};
|
|
34828
|
+
const first = elements[0] ? modalOf(elements[0]) : null;
|
|
34829
|
+
return first !== null && elements.every((el) => modalOf(el) === first);
|
|
34865
34830
|
}
|
|
34866
|
-
function
|
|
34867
|
-
|
|
34868
|
-
|
|
34869
|
-
|
|
34870
|
-
|
|
34871
|
-
|
|
34872
|
-
height: `${rect.height}px`
|
|
34873
|
-
});
|
|
34831
|
+
function commonAncestor(elements) {
|
|
34832
|
+
let candidate = elements[0];
|
|
34833
|
+
while (candidate && !elements.every((el) => candidate.contains(el))) {
|
|
34834
|
+
candidate = candidate.parentElement;
|
|
34835
|
+
}
|
|
34836
|
+
return candidate ?? elements[0];
|
|
34874
34837
|
}
|
|
34875
|
-
function
|
|
34876
|
-
|
|
34877
|
-
const
|
|
34878
|
-
|
|
34879
|
-
|
|
34880
|
-
|
|
34881
|
-
|
|
34838
|
+
function createFocusWalkProbe(doc = document, frameworkPrefixes = DEFAULT_FRAMEWORK_PREFIXES) {
|
|
34839
|
+
const ids = /* @__PURE__ */ new WeakMap();
|
|
34840
|
+
const byId = /* @__PURE__ */ new Map();
|
|
34841
|
+
return {
|
|
34842
|
+
probe() {
|
|
34843
|
+
const active = deepActiveElement(doc);
|
|
34844
|
+
if (!active || active === doc.body || active === doc.documentElement) {
|
|
34845
|
+
return { id: null, iframe: false };
|
|
34846
|
+
}
|
|
34847
|
+
let id = ids.get(active);
|
|
34848
|
+
if (id === void 0) {
|
|
34849
|
+
id = byId.size + 1;
|
|
34850
|
+
ids.set(active, id);
|
|
34851
|
+
byId.set(id, active);
|
|
34852
|
+
}
|
|
34853
|
+
return { id, iframe: active.tagName === "IFRAME" };
|
|
34854
|
+
},
|
|
34855
|
+
stopCount() {
|
|
34856
|
+
return tabSequence(doc, { frameworkPrefixes }).length;
|
|
34857
|
+
},
|
|
34858
|
+
trapFinding(cycle, shiftTabEscapes) {
|
|
34859
|
+
const elements = [...new Set(cycle)].map((id) => byId.get(id)).filter((el) => el !== void 0);
|
|
34860
|
+
if (elements.length === 0 || containedByOpenModal(elements))
|
|
34861
|
+
return null;
|
|
34862
|
+
const owner = elements.length === 1 ? elements[0] : commonAncestor(elements);
|
|
34863
|
+
const reachable = new Set(byId.values());
|
|
34864
|
+
const unreached = tabSequence(doc, { frameworkPrefixes }).filter((stop) => !reachable.has(stop.element)).length;
|
|
34865
|
+
const where = elements.length === 1 ? "focus stays on this element when Tab is pressed" : `Tab cycles through ${elements.length} controls inside this element and never leaves`;
|
|
34866
|
+
const reach = unreached > 0 ? `, so ${unreached} tabbable control(s) in the page are never reached` : "";
|
|
34867
|
+
const shift = shiftTabEscapes ? " Shift+Tab does get out, but Tab alone should too." : " Shift+Tab doesn't get out either.";
|
|
34868
|
+
const componentPath = resolveComponentPath(owner);
|
|
34869
|
+
return {
|
|
34870
|
+
id: "ngbr/focus-trap",
|
|
34871
|
+
impact: shiftTabEscapes ? "moderate" : "serious",
|
|
34872
|
+
help: `Possible keyboard trap: ${where}${reach}.${shift} If this widget deliberately keeps Tab (e.g. a code editor), it must tell users how to leave (such as Escape); otherwise let Tab move focus on. Found by real Tab presses \u2014 verify manually.`,
|
|
34873
|
+
helpUrl: NO_KEYBOARD_TRAP_URL,
|
|
34874
|
+
component: appComponentFromPath(componentPath, frameworkPrefixes),
|
|
34875
|
+
componentPath,
|
|
34876
|
+
directives: resolveDirectiveNames(owner),
|
|
34877
|
+
target: shortSelector(owner),
|
|
34878
|
+
html: shortHtml(owner)
|
|
34879
|
+
};
|
|
34880
|
+
}
|
|
34881
|
+
};
|
|
34882
34882
|
}
|
|
34883
34883
|
|
|
34884
34884
|
// dist/scan.js
|