@ngbracket/a11y-devtools 0.10.1 → 0.12.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 +68 -0
- package/README.md +4 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/inpage.global.js +585 -480
- package/dist/keyboard/focus-trap.js +2 -0
- package/dist/keyboard/tab-sequence.d.ts +18 -0
- package/dist/keyboard/tab-sequence.js +52 -1
- package/dist/overlay.js +5 -0
- package/dist/pill-menu.d.ts +35 -0
- package/dist/pill-menu.js +185 -0
- package/dist/provider.d.ts +30 -0
- package/dist/provider.js +136 -20
- package/dist/settings.d.ts +39 -0
- package/dist/settings.js +68 -0
- package/dist/toggle.d.ts +66 -0
- package/dist/toggle.js +204 -0
- package/dist/top-layer.d.ts +40 -0
- package/dist/top-layer.js +117 -0
- package/package.json +1 -1
package/dist/inpage.global.js
CHANGED
|
@@ -34222,351 +34222,80 @@
|
|
|
34222
34222
|
return names;
|
|
34223
34223
|
}
|
|
34224
34224
|
|
|
34225
|
-
// dist/
|
|
34226
|
-
var
|
|
34227
|
-
"
|
|
34228
|
-
"
|
|
34229
|
-
"
|
|
34230
|
-
"
|
|
34231
|
-
"
|
|
34232
|
-
"
|
|
34233
|
-
"
|
|
34234
|
-
"
|
|
34235
|
-
"
|
|
34236
|
-
"
|
|
34237
|
-
"
|
|
34238
|
-
"
|
|
34239
|
-
|
|
34240
|
-
|
|
34241
|
-
|
|
34242
|
-
|
|
34243
|
-
|
|
34244
|
-
|
|
34245
|
-
function nativeTabIndex(element) {
|
|
34246
|
-
return isNativelyFocusable(element) ? 0 : -1;
|
|
34247
|
-
}
|
|
34248
|
-
function isNativelyFocusable(element) {
|
|
34249
|
-
const tag = element.tagName.toLowerCase();
|
|
34250
|
-
switch (tag) {
|
|
34251
|
-
case "a":
|
|
34252
|
-
case "area":
|
|
34253
|
-
return element.hasAttribute("href");
|
|
34254
|
-
case "button":
|
|
34255
|
-
case "select":
|
|
34256
|
-
case "textarea":
|
|
34257
|
-
return true;
|
|
34258
|
-
case "input":
|
|
34259
|
-
return element.getAttribute("type")?.toLowerCase() !== "hidden";
|
|
34260
|
-
case "summary":
|
|
34261
|
-
return true;
|
|
34262
|
-
case "iframe":
|
|
34263
|
-
case "object":
|
|
34264
|
-
case "embed":
|
|
34265
|
-
return true;
|
|
34266
|
-
case "audio":
|
|
34267
|
-
case "video":
|
|
34268
|
-
return element.hasAttribute("controls");
|
|
34269
|
-
}
|
|
34270
|
-
const editable = element.getAttribute("contenteditable");
|
|
34271
|
-
return editable !== null && editable !== "false";
|
|
34272
|
-
}
|
|
34273
|
-
function resolvedTabIndex(element) {
|
|
34274
|
-
const attr = element.getAttribute("tabindex");
|
|
34275
|
-
if (attr === null)
|
|
34276
|
-
return nativeTabIndex(element);
|
|
34277
|
-
const parsed = Number.parseInt(attr, 10);
|
|
34278
|
-
return Number.isNaN(parsed) ? nativeTabIndex(element) : parsed;
|
|
34279
|
-
}
|
|
34280
|
-
function isDisabled(element) {
|
|
34281
|
-
if ("disabled" in element && element.disabled)
|
|
34282
|
-
return true;
|
|
34283
|
-
return element.closest("fieldset[disabled]") !== null && element.closest("legend") === null;
|
|
34284
|
-
}
|
|
34285
|
-
function isStructurallyHidden(element) {
|
|
34286
|
-
if (element.closest("[inert]") || element.closest("[hidden]"))
|
|
34287
|
-
return true;
|
|
34288
|
-
const closedDetails = element.closest("details:not([open])");
|
|
34289
|
-
return closedDetails !== null && element.closest("summary") === null && element !== closedDetails;
|
|
34290
|
-
}
|
|
34291
|
-
function defaultIsVisible(element) {
|
|
34292
|
-
const view = element.ownerDocument?.defaultView;
|
|
34293
|
-
if (!view?.getComputedStyle)
|
|
34294
|
-
return true;
|
|
34295
|
-
for (let node = element; node; node = node.parentElement) {
|
|
34296
|
-
const style = view.getComputedStyle(node);
|
|
34297
|
-
if (style.display === "none")
|
|
34298
|
-
return false;
|
|
34299
|
-
if (style.visibility === "hidden" || style.visibility === "collapse")
|
|
34300
|
-
return false;
|
|
34301
|
-
}
|
|
34302
|
-
return true;
|
|
34303
|
-
}
|
|
34304
|
-
function isTabbable(element, isVisible = defaultIsVisible) {
|
|
34305
|
-
if (resolvedTabIndex(element) < 0)
|
|
34306
|
-
return false;
|
|
34307
|
-
if (isDisabled(element))
|
|
34308
|
-
return false;
|
|
34309
|
-
if (isStructurallyHidden(element))
|
|
34310
|
-
return false;
|
|
34311
|
-
const editable = element.getAttribute("contenteditable");
|
|
34312
|
-
if (editable === "false" && !isNativelyFocusable(element) && !element.hasAttribute("tabindex")) {
|
|
34225
|
+
// dist/top-layer.js
|
|
34226
|
+
var POPOVER_LAYER_STYLE = {
|
|
34227
|
+
position: "fixed",
|
|
34228
|
+
inset: "0",
|
|
34229
|
+
width: "100%",
|
|
34230
|
+
height: "100%",
|
|
34231
|
+
maxWidth: "none",
|
|
34232
|
+
maxHeight: "none",
|
|
34233
|
+
margin: "0",
|
|
34234
|
+
padding: "0",
|
|
34235
|
+
border: "0",
|
|
34236
|
+
background: "transparent",
|
|
34237
|
+
color: "inherit",
|
|
34238
|
+
overflow: "visible"
|
|
34239
|
+
};
|
|
34240
|
+
var managed = /* @__PURE__ */ new WeakSet();
|
|
34241
|
+
function safeMatches(el, selector) {
|
|
34242
|
+
try {
|
|
34243
|
+
return el.matches(selector);
|
|
34244
|
+
} catch {
|
|
34313
34245
|
return false;
|
|
34314
34246
|
}
|
|
34315
|
-
return isVisible(element);
|
|
34316
34247
|
}
|
|
34317
|
-
function
|
|
34318
|
-
|
|
34319
|
-
const prefixes = options.frameworkPrefixes ?? DEFAULT_FRAMEWORK_PREFIXES;
|
|
34320
|
-
const candidates = [...root.querySelectorAll(FOCUSABLE_SELECTOR)].filter((el) => isTabbable(el, isVisible));
|
|
34321
|
-
const withMeta = candidates.map((element, domIndex) => ({
|
|
34322
|
-
element,
|
|
34323
|
-
domIndex,
|
|
34324
|
-
tabindex: resolvedTabIndex(element),
|
|
34325
|
-
positive: /^\d+$/.test(element.getAttribute("tabindex") ?? "") && resolvedTabIndex(element) > 0
|
|
34326
|
-
}));
|
|
34327
|
-
const positives = withMeta.filter((m) => m.tabindex > 0).sort((a, b) => a.tabindex - b.tabindex || a.domIndex - b.domIndex);
|
|
34328
|
-
const zeros = withMeta.filter((m) => m.tabindex === 0);
|
|
34329
|
-
return [...positives, ...zeros].map((m, i) => {
|
|
34330
|
-
const componentPath = resolveComponentPath(m.element);
|
|
34331
|
-
return {
|
|
34332
|
-
element: m.element,
|
|
34333
|
-
order: i + 1,
|
|
34334
|
-
tabindex: m.tabindex,
|
|
34335
|
-
positive: m.positive,
|
|
34336
|
-
component: appComponentFromPath(componentPath, prefixes),
|
|
34337
|
-
componentPath
|
|
34338
|
-
};
|
|
34339
|
-
});
|
|
34248
|
+
function isModalDialog(el) {
|
|
34249
|
+
return el.tagName === "DIALOG" && safeMatches(el, ":modal");
|
|
34340
34250
|
}
|
|
34341
|
-
function
|
|
34342
|
-
const
|
|
34343
|
-
|
|
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 };
|
|
34251
|
+
function blockingModalDialog(doc = document, isModal = isModalDialog) {
|
|
34252
|
+
const open = [...doc.querySelectorAll("dialog[open]")].filter(isModal);
|
|
34253
|
+
return open.at(-1) ?? null;
|
|
34349
34254
|
}
|
|
34350
|
-
function
|
|
34351
|
-
const
|
|
34352
|
-
|
|
34353
|
-
|
|
34354
|
-
|
|
34355
|
-
|
|
34356
|
-
|
|
34357
|
-
|
|
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);
|
|
34255
|
+
function keepInTopLayer(el, options = {}) {
|
|
34256
|
+
const doc = options.document ?? el.ownerDocument;
|
|
34257
|
+
const isModal = options.isModal ?? isModalDialog;
|
|
34258
|
+
const canPopover = typeof el.showPopover === "function";
|
|
34259
|
+
managed.add(el);
|
|
34260
|
+
if (canPopover) {
|
|
34261
|
+
el.setAttribute("popover", "manual");
|
|
34262
|
+
Object.assign(el.style, POPOVER_LAYER_STYLE);
|
|
34362
34263
|
}
|
|
34363
|
-
|
|
34364
|
-
|
|
34365
|
-
|
|
34366
|
-
|
|
34367
|
-
|
|
34368
|
-
|
|
34369
|
-
|
|
34370
|
-
|
|
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
|
-
};
|
|
34264
|
+
const show = () => {
|
|
34265
|
+
if (!canPopover)
|
|
34266
|
+
return;
|
|
34267
|
+
try {
|
|
34268
|
+
if (safeMatches(el, ":popover-open"))
|
|
34269
|
+
el.hidePopover();
|
|
34270
|
+
el.showPopover();
|
|
34271
|
+
} catch {
|
|
34568
34272
|
}
|
|
34569
34273
|
};
|
|
34274
|
+
const place = () => {
|
|
34275
|
+
const parent = blockingModalDialog(doc, isModal) ?? doc.body;
|
|
34276
|
+
if (el.parentNode !== parent)
|
|
34277
|
+
parent.appendChild(el);
|
|
34278
|
+
show();
|
|
34279
|
+
};
|
|
34280
|
+
const observer = new MutationObserver(place);
|
|
34281
|
+
observer.observe(doc.documentElement, {
|
|
34282
|
+
subtree: true,
|
|
34283
|
+
attributes: true,
|
|
34284
|
+
attributeFilter: ["open"]
|
|
34285
|
+
});
|
|
34286
|
+
const onToggle = (event) => {
|
|
34287
|
+
if (event.target instanceof Element && managed.has(event.target))
|
|
34288
|
+
return;
|
|
34289
|
+
if (event.newState === "open")
|
|
34290
|
+
place();
|
|
34291
|
+
};
|
|
34292
|
+
doc.addEventListener("toggle", onToggle, true);
|
|
34293
|
+
place();
|
|
34294
|
+
return () => {
|
|
34295
|
+
observer.disconnect();
|
|
34296
|
+
doc.removeEventListener("toggle", onToggle, true);
|
|
34297
|
+
managed.delete(el);
|
|
34298
|
+
};
|
|
34570
34299
|
}
|
|
34571
34300
|
|
|
34572
34301
|
// dist/overlay.js
|
|
@@ -34600,6 +34329,7 @@
|
|
|
34600
34329
|
zIndex: "2147483646"
|
|
34601
34330
|
});
|
|
34602
34331
|
doc.body.appendChild(container);
|
|
34332
|
+
const releaseTopLayer = keepInTopLayer(container, { document: doc });
|
|
34603
34333
|
const svg = doc.createElementNS(SVG_NS, "svg");
|
|
34604
34334
|
svg.setAttribute(OVERLAY_ATTR, "");
|
|
34605
34335
|
Object.assign(svg.style, {
|
|
@@ -34727,158 +34457,533 @@
|
|
|
34727
34457
|
container.appendChild(badge);
|
|
34728
34458
|
tabBadges.push({ stop, target, badge });
|
|
34729
34459
|
}
|
|
34730
|
-
repositionTabOrder();
|
|
34731
|
-
}
|
|
34732
|
-
function renderAxPanel(data) {
|
|
34733
|
-
if (!data) {
|
|
34734
|
-
axPanel.style.display = "none";
|
|
34735
|
-
axPanel.replaceChildren();
|
|
34736
|
-
return;
|
|
34460
|
+
repositionTabOrder();
|
|
34461
|
+
}
|
|
34462
|
+
function renderAxPanel(data) {
|
|
34463
|
+
if (!data) {
|
|
34464
|
+
axPanel.style.display = "none";
|
|
34465
|
+
axPanel.replaceChildren();
|
|
34466
|
+
return;
|
|
34467
|
+
}
|
|
34468
|
+
axPanel.replaceChildren(...buildAxPanelContent(doc, data));
|
|
34469
|
+
axPanel.style.display = "block";
|
|
34470
|
+
}
|
|
34471
|
+
function destroy() {
|
|
34472
|
+
clear();
|
|
34473
|
+
clearTabOrder();
|
|
34474
|
+
renderAxPanel(null);
|
|
34475
|
+
win?.removeEventListener("scroll", onViewportChange, { capture: true });
|
|
34476
|
+
win?.removeEventListener("resize", onViewportChange);
|
|
34477
|
+
releaseTopLayer();
|
|
34478
|
+
container.remove();
|
|
34479
|
+
}
|
|
34480
|
+
return { render, renderTabOrder, renderAxPanel, clear, clearTabOrder, destroy };
|
|
34481
|
+
}
|
|
34482
|
+
function buildAxPanelContent(doc, data) {
|
|
34483
|
+
const nodes = [];
|
|
34484
|
+
const header = doc.createElement("div");
|
|
34485
|
+
header.textContent = "Accessibility-tree preview \u2014 computed approximation";
|
|
34486
|
+
Object.assign(header.style, {
|
|
34487
|
+
fontWeight: "700",
|
|
34488
|
+
fontSize: "10px",
|
|
34489
|
+
letterSpacing: "0.02em",
|
|
34490
|
+
textTransform: "uppercase",
|
|
34491
|
+
color: "#a9b0bd",
|
|
34492
|
+
marginBottom: "4px"
|
|
34493
|
+
});
|
|
34494
|
+
header.title = "A computed name/role/state \u2014 an approximation of what assistive tech announces, not any one screen reader.";
|
|
34495
|
+
nodes.push(header);
|
|
34496
|
+
const row = (label, value, muted = false) => {
|
|
34497
|
+
const div = doc.createElement("div");
|
|
34498
|
+
const key = doc.createElement("span");
|
|
34499
|
+
key.textContent = `${label}: `;
|
|
34500
|
+
key.style.color = "#a9b0bd";
|
|
34501
|
+
const val = doc.createElement("span");
|
|
34502
|
+
val.textContent = value;
|
|
34503
|
+
if (muted)
|
|
34504
|
+
val.style.color = "#e8710a";
|
|
34505
|
+
div.append(key, val);
|
|
34506
|
+
return div;
|
|
34507
|
+
};
|
|
34508
|
+
nodes.push(row("role", data.role ?? `(none \u2014 <${data.tag}>)`));
|
|
34509
|
+
nodes.push(data.name ? row("name", `"${data.name}"`) : row("name", "(no accessible name)", true));
|
|
34510
|
+
if (data.description)
|
|
34511
|
+
nodes.push(row("description", `"${data.description}"`));
|
|
34512
|
+
if (data.states.length)
|
|
34513
|
+
nodes.push(row("states", data.states.join(", ")));
|
|
34514
|
+
if (data.component)
|
|
34515
|
+
nodes.push(row("component", data.component));
|
|
34516
|
+
return nodes;
|
|
34517
|
+
}
|
|
34518
|
+
function buildBadge(doc, stop) {
|
|
34519
|
+
const color = stop.positive ? TAB_ORDER_WARN_COLOR : TAB_ORDER_COLOR;
|
|
34520
|
+
const badge = doc.createElement("div");
|
|
34521
|
+
badge.setAttribute("data-ngb-tab-order", String(stop.order));
|
|
34522
|
+
const owner = stop.component ? ` \xB7 ${stop.component}` : "";
|
|
34523
|
+
const ti = stop.positive ? ` \xB7 tabindex=${stop.tabindex} (hijacks order)` : "";
|
|
34524
|
+
badge.title = `Tab stop ${stop.order}${owner}${ti}`;
|
|
34525
|
+
badge.textContent = String(stop.order);
|
|
34526
|
+
Object.assign(badge.style, {
|
|
34527
|
+
position: "fixed",
|
|
34528
|
+
transform: "translate(-50%, -50%)",
|
|
34529
|
+
minWidth: "16px",
|
|
34530
|
+
height: "16px",
|
|
34531
|
+
padding: "0 3px",
|
|
34532
|
+
boxSizing: "border-box",
|
|
34533
|
+
borderRadius: "8px",
|
|
34534
|
+
font: "10px/16px ui-monospace, monospace",
|
|
34535
|
+
fontWeight: "700",
|
|
34536
|
+
textAlign: "center",
|
|
34537
|
+
color: "#fff",
|
|
34538
|
+
background: color,
|
|
34539
|
+
border: "1px solid rgba(255,255,255,0.85)",
|
|
34540
|
+
pointerEvents: "none"
|
|
34541
|
+
});
|
|
34542
|
+
return badge;
|
|
34543
|
+
}
|
|
34544
|
+
function resolveTarget(doc, target) {
|
|
34545
|
+
try {
|
|
34546
|
+
return doc.querySelector(target);
|
|
34547
|
+
} catch {
|
|
34548
|
+
return null;
|
|
34549
|
+
}
|
|
34550
|
+
}
|
|
34551
|
+
function buildBox(doc, finding) {
|
|
34552
|
+
const color = colorFor(finding.impact);
|
|
34553
|
+
const box = doc.createElement("div");
|
|
34554
|
+
box.setAttribute("data-impact", finding.impact ?? "none");
|
|
34555
|
+
box.title = `${finding.id}: ${finding.help}`;
|
|
34556
|
+
Object.assign(box.style, {
|
|
34557
|
+
position: "fixed",
|
|
34558
|
+
boxSizing: "border-box",
|
|
34559
|
+
border: `2px solid ${color}`,
|
|
34560
|
+
borderRadius: "2px",
|
|
34561
|
+
background: `${color}1a`,
|
|
34562
|
+
// ~10% alpha
|
|
34563
|
+
pointerEvents: "auto",
|
|
34564
|
+
cursor: "pointer"
|
|
34565
|
+
});
|
|
34566
|
+
const label = doc.createElement("span");
|
|
34567
|
+
label.textContent = finding.component ? `${finding.component} \xB7 ${finding.id}` : finding.id;
|
|
34568
|
+
Object.assign(label.style, {
|
|
34569
|
+
position: "absolute",
|
|
34570
|
+
top: "0",
|
|
34571
|
+
left: "0",
|
|
34572
|
+
transform: "translateY(-100%)",
|
|
34573
|
+
padding: "1px 4px",
|
|
34574
|
+
font: "11px/1.4 ui-monospace, monospace",
|
|
34575
|
+
color: "#fff",
|
|
34576
|
+
background: color,
|
|
34577
|
+
whiteSpace: "nowrap"
|
|
34578
|
+
});
|
|
34579
|
+
box.appendChild(label);
|
|
34580
|
+
return box;
|
|
34581
|
+
}
|
|
34582
|
+
function resolveLabelStack(items, minTop = LABEL_MIN_TOP) {
|
|
34583
|
+
const order = items.map((it, i) => ({ it, i })).sort((a, b) => a.it.baseTop - b.it.baseTop || a.it.left - b.it.left);
|
|
34584
|
+
const placed = [];
|
|
34585
|
+
const tops = new Array(items.length);
|
|
34586
|
+
for (const { it, i } of order) {
|
|
34587
|
+
let top = it.baseTop;
|
|
34588
|
+
const hits = (t) => placed.some((p) => it.left < p.right && it.left + it.width > p.left && t < p.bottom && t + it.height > p.top);
|
|
34589
|
+
let guard = 0;
|
|
34590
|
+
while (hits(top) && top > minTop && guard++ < 60)
|
|
34591
|
+
top -= it.height + 2;
|
|
34592
|
+
tops[i] = top;
|
|
34593
|
+
placed.push({ left: it.left, right: it.left + it.width, top, bottom: top + it.height });
|
|
34594
|
+
}
|
|
34595
|
+
return tops;
|
|
34596
|
+
}
|
|
34597
|
+
function positionBox(box, target) {
|
|
34598
|
+
const rect = target.getBoundingClientRect();
|
|
34599
|
+
Object.assign(box.style, {
|
|
34600
|
+
top: `${rect.top}px`,
|
|
34601
|
+
left: `${rect.left}px`,
|
|
34602
|
+
width: `${rect.width}px`,
|
|
34603
|
+
height: `${rect.height}px`
|
|
34604
|
+
});
|
|
34605
|
+
}
|
|
34606
|
+
function flashAndScroll(target, box) {
|
|
34607
|
+
target.scrollIntoView({ block: "center", behavior: "smooth" });
|
|
34608
|
+
const original = box.style.boxShadow;
|
|
34609
|
+
box.style.boxShadow = "0 0 0 4px rgba(255,255,255,0.6)";
|
|
34610
|
+
box.ownerDocument.defaultView?.setTimeout(() => {
|
|
34611
|
+
box.style.boxShadow = original;
|
|
34612
|
+
}, 600);
|
|
34613
|
+
}
|
|
34614
|
+
|
|
34615
|
+
// dist/keyboard/tab-sequence.js
|
|
34616
|
+
function isFocusSentinel(el) {
|
|
34617
|
+
if (el.childElementCount > 0 || (el.textContent ?? "").trim() !== "")
|
|
34618
|
+
return false;
|
|
34619
|
+
return el.getAttribute("aria-hidden") === "true" || el.hasAttribute("data-focus-guard");
|
|
34620
|
+
}
|
|
34621
|
+
function sentinelTrappedModal(root, order) {
|
|
34622
|
+
const modals = [...root.querySelectorAll('[aria-modal="true"]')].reverse();
|
|
34623
|
+
for (const modal of modals) {
|
|
34624
|
+
const inside = order.map((el) => modal.contains(el));
|
|
34625
|
+
const first = inside.indexOf(true);
|
|
34626
|
+
const last = inside.lastIndexOf(true);
|
|
34627
|
+
if (first === -1 || inside.slice(first, last + 1).includes(false))
|
|
34628
|
+
continue;
|
|
34629
|
+
const before = order[first - 1];
|
|
34630
|
+
const after = order[last + 1];
|
|
34631
|
+
if (before && after && isFocusSentinel(before) && isFocusSentinel(after))
|
|
34632
|
+
return modal;
|
|
34633
|
+
}
|
|
34634
|
+
return null;
|
|
34635
|
+
}
|
|
34636
|
+
var FOCUSABLE_SELECTOR = [
|
|
34637
|
+
"a[href]",
|
|
34638
|
+
"area[href]",
|
|
34639
|
+
"button",
|
|
34640
|
+
"input",
|
|
34641
|
+
"select",
|
|
34642
|
+
"textarea",
|
|
34643
|
+
"audio[controls]",
|
|
34644
|
+
"video[controls]",
|
|
34645
|
+
"summary",
|
|
34646
|
+
"iframe",
|
|
34647
|
+
"object",
|
|
34648
|
+
"embed",
|
|
34649
|
+
"[contenteditable]",
|
|
34650
|
+
"[tabindex]"
|
|
34651
|
+
].join(",");
|
|
34652
|
+
function hasFocusableDescendant(element) {
|
|
34653
|
+
return element.querySelector(FOCUSABLE_SELECTOR) !== null;
|
|
34654
|
+
}
|
|
34655
|
+
function nativeTabIndex(element) {
|
|
34656
|
+
return isNativelyFocusable(element) ? 0 : -1;
|
|
34657
|
+
}
|
|
34658
|
+
function isNativelyFocusable(element) {
|
|
34659
|
+
const tag = element.tagName.toLowerCase();
|
|
34660
|
+
switch (tag) {
|
|
34661
|
+
case "a":
|
|
34662
|
+
case "area":
|
|
34663
|
+
return element.hasAttribute("href");
|
|
34664
|
+
case "button":
|
|
34665
|
+
case "select":
|
|
34666
|
+
case "textarea":
|
|
34667
|
+
return true;
|
|
34668
|
+
case "input":
|
|
34669
|
+
return element.getAttribute("type")?.toLowerCase() !== "hidden";
|
|
34670
|
+
case "summary":
|
|
34671
|
+
return true;
|
|
34672
|
+
case "iframe":
|
|
34673
|
+
case "object":
|
|
34674
|
+
case "embed":
|
|
34675
|
+
return true;
|
|
34676
|
+
case "audio":
|
|
34677
|
+
case "video":
|
|
34678
|
+
return element.hasAttribute("controls");
|
|
34679
|
+
}
|
|
34680
|
+
const editable = element.getAttribute("contenteditable");
|
|
34681
|
+
return editable !== null && editable !== "false";
|
|
34682
|
+
}
|
|
34683
|
+
function resolvedTabIndex(element) {
|
|
34684
|
+
const attr = element.getAttribute("tabindex");
|
|
34685
|
+
if (attr === null)
|
|
34686
|
+
return nativeTabIndex(element);
|
|
34687
|
+
const parsed = Number.parseInt(attr, 10);
|
|
34688
|
+
return Number.isNaN(parsed) ? nativeTabIndex(element) : parsed;
|
|
34689
|
+
}
|
|
34690
|
+
function isDisabled(element) {
|
|
34691
|
+
if ("disabled" in element && element.disabled)
|
|
34692
|
+
return true;
|
|
34693
|
+
return element.closest("fieldset[disabled]") !== null && element.closest("legend") === null;
|
|
34694
|
+
}
|
|
34695
|
+
function isStructurallyHidden(element) {
|
|
34696
|
+
if (element.closest("[inert]") || element.closest("[hidden]"))
|
|
34697
|
+
return true;
|
|
34698
|
+
const closedDetails = element.closest("details:not([open])");
|
|
34699
|
+
return closedDetails !== null && element.closest("summary") === null && element !== closedDetails;
|
|
34700
|
+
}
|
|
34701
|
+
function defaultIsVisible(element) {
|
|
34702
|
+
const view = element.ownerDocument?.defaultView;
|
|
34703
|
+
if (!view?.getComputedStyle)
|
|
34704
|
+
return true;
|
|
34705
|
+
for (let node = element; node; node = node.parentElement) {
|
|
34706
|
+
const style = view.getComputedStyle(node);
|
|
34707
|
+
if (style.display === "none")
|
|
34708
|
+
return false;
|
|
34709
|
+
if (style.visibility === "hidden" || style.visibility === "collapse")
|
|
34710
|
+
return false;
|
|
34711
|
+
}
|
|
34712
|
+
return true;
|
|
34713
|
+
}
|
|
34714
|
+
function isTabbable(element, isVisible = defaultIsVisible) {
|
|
34715
|
+
if (resolvedTabIndex(element) < 0)
|
|
34716
|
+
return false;
|
|
34717
|
+
if (isDisabled(element))
|
|
34718
|
+
return false;
|
|
34719
|
+
if (isStructurallyHidden(element))
|
|
34720
|
+
return false;
|
|
34721
|
+
const editable = element.getAttribute("contenteditable");
|
|
34722
|
+
if (editable === "false" && !isNativelyFocusable(element) && !element.hasAttribute("tabindex")) {
|
|
34723
|
+
return false;
|
|
34724
|
+
}
|
|
34725
|
+
return isVisible(element);
|
|
34726
|
+
}
|
|
34727
|
+
function tabSequence(root = document, options = {}) {
|
|
34728
|
+
const isVisible = options.isVisible ?? defaultIsVisible;
|
|
34729
|
+
const prefixes = options.frameworkPrefixes ?? DEFAULT_FRAMEWORK_PREFIXES;
|
|
34730
|
+
const doc = root instanceof Document ? root : root.ownerDocument;
|
|
34731
|
+
const modal = doc ? blockingModalDialog(doc, options.isModal) : null;
|
|
34732
|
+
let candidates = [...root.querySelectorAll(FOCUSABLE_SELECTOR)].filter((el) => !el.closest(OVERLAY_EXCLUDE_SELECTOR) && (!modal || modal.contains(el)) && isTabbable(el, isVisible));
|
|
34733
|
+
const trapped = modal ? null : sentinelTrappedModal(root, candidates);
|
|
34734
|
+
if (trapped)
|
|
34735
|
+
candidates = candidates.filter((el) => trapped.contains(el));
|
|
34736
|
+
if (!options.includeSentinels)
|
|
34737
|
+
candidates = candidates.filter((el) => !isFocusSentinel(el));
|
|
34738
|
+
const withMeta = candidates.map((element, domIndex) => ({
|
|
34739
|
+
element,
|
|
34740
|
+
domIndex,
|
|
34741
|
+
tabindex: resolvedTabIndex(element),
|
|
34742
|
+
positive: /^\d+$/.test(element.getAttribute("tabindex") ?? "") && resolvedTabIndex(element) > 0
|
|
34743
|
+
}));
|
|
34744
|
+
const positives = withMeta.filter((m) => m.tabindex > 0).sort((a, b) => a.tabindex - b.tabindex || a.domIndex - b.domIndex);
|
|
34745
|
+
const zeros = withMeta.filter((m) => m.tabindex === 0);
|
|
34746
|
+
return [...positives, ...zeros].map((m, i) => {
|
|
34747
|
+
const componentPath = resolveComponentPath(m.element);
|
|
34748
|
+
return {
|
|
34749
|
+
element: m.element,
|
|
34750
|
+
order: i + 1,
|
|
34751
|
+
tabindex: m.tabindex,
|
|
34752
|
+
positive: m.positive,
|
|
34753
|
+
component: appComponentFromPath(componentPath, prefixes),
|
|
34754
|
+
componentPath
|
|
34755
|
+
};
|
|
34756
|
+
});
|
|
34757
|
+
}
|
|
34758
|
+
function stopRect(el) {
|
|
34759
|
+
const box = el.getBoundingClientRect();
|
|
34760
|
+
const lines = el.getClientRects();
|
|
34761
|
+
if (lines.length === 0)
|
|
34762
|
+
return { top: box.top, left: box.left, right: box.right };
|
|
34763
|
+
const first = lines[0];
|
|
34764
|
+
const last = lines[lines.length - 1];
|
|
34765
|
+
return { top: first.top, left: first.left, right: box.right, endTop: last.top, endLeft: last.left };
|
|
34766
|
+
}
|
|
34767
|
+
function visualOrderJumps(stops, getRect = stopRect, rowThreshold = 8) {
|
|
34768
|
+
const jumps = [];
|
|
34769
|
+
for (let i = 1; i < stops.length; i++) {
|
|
34770
|
+
const prev = getRect(stops[i - 1].element);
|
|
34771
|
+
const curr = getRect(stops[i].element);
|
|
34772
|
+
const prevTop = prev.endTop ?? prev.top;
|
|
34773
|
+
const prevLeft = prev.endLeft ?? prev.left;
|
|
34774
|
+
const movedUp = curr.top < prevTop - rowThreshold;
|
|
34775
|
+
const nextColumn = curr.left >= (prev.right ?? prev.left + rowThreshold);
|
|
34776
|
+
const sameRowMovedLeft = Math.abs(curr.top - prevTop) <= rowThreshold && curr.left < prevLeft - rowThreshold;
|
|
34777
|
+
if (movedUp && !nextColumn || sameRowMovedLeft)
|
|
34778
|
+
jumps.push(i);
|
|
34779
|
+
}
|
|
34780
|
+
return jumps;
|
|
34781
|
+
}
|
|
34782
|
+
|
|
34783
|
+
// dist/keyboard/focus-trap.js
|
|
34784
|
+
function findUncontainedModals(root = document, options = {}) {
|
|
34785
|
+
const stops = tabSequence(root, options);
|
|
34786
|
+
if (stops.length === 0)
|
|
34787
|
+
return [];
|
|
34788
|
+
const results = [];
|
|
34789
|
+
for (const modal of root.querySelectorAll('[aria-modal="true"]')) {
|
|
34790
|
+
let insideCount = 0;
|
|
34791
|
+
let outsideCount = 0;
|
|
34792
|
+
for (const stop of stops) {
|
|
34793
|
+
if (modal.contains(stop.element))
|
|
34794
|
+
insideCount++;
|
|
34795
|
+
else
|
|
34796
|
+
outsideCount++;
|
|
34797
|
+
}
|
|
34798
|
+
if (insideCount > 0 && outsideCount > 0)
|
|
34799
|
+
results.push({ element: modal, insideCount, outsideCount });
|
|
34800
|
+
}
|
|
34801
|
+
return results;
|
|
34802
|
+
}
|
|
34803
|
+
|
|
34804
|
+
// dist/keyboard/keyboard-scan.js
|
|
34805
|
+
var INTERACTIVE_ROLES = /* @__PURE__ */ new Set([
|
|
34806
|
+
"button",
|
|
34807
|
+
"link",
|
|
34808
|
+
"menuitem",
|
|
34809
|
+
"menuitemcheckbox",
|
|
34810
|
+
"menuitemradio",
|
|
34811
|
+
"tab",
|
|
34812
|
+
"switch",
|
|
34813
|
+
"checkbox",
|
|
34814
|
+
"radio",
|
|
34815
|
+
"option",
|
|
34816
|
+
"slider",
|
|
34817
|
+
"spinbutton",
|
|
34818
|
+
"combobox",
|
|
34819
|
+
"textbox",
|
|
34820
|
+
"searchbox",
|
|
34821
|
+
"treeitem"
|
|
34822
|
+
]);
|
|
34823
|
+
var KEY_EVENTS = ["keydown", "keyup", "keypress"];
|
|
34824
|
+
var UNDERSTANDING = "https://www.w3.org/WAI/WCAG22/Understanding";
|
|
34825
|
+
var KEYBOARD_URL = `${UNDERSTANDING}/keyboard.html`;
|
|
34826
|
+
var FOCUS_ORDER_URL = `${UNDERSTANDING}/focus-order.html`;
|
|
34827
|
+
var DIALOG_MODAL_URL = "https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/";
|
|
34828
|
+
function shortSelector(element) {
|
|
34829
|
+
const tag = element.tagName.toLowerCase();
|
|
34830
|
+
if (element.id)
|
|
34831
|
+
return `${tag}#${element.id}`;
|
|
34832
|
+
const classes = (element.getAttribute("class") ?? "").trim().split(/\s+/).filter(Boolean).slice(0, 2);
|
|
34833
|
+
return classes.length ? `${tag}.${classes.join(".")}` : tag;
|
|
34834
|
+
}
|
|
34835
|
+
function shortHtml(element) {
|
|
34836
|
+
const html = element.outerHTML ?? "";
|
|
34837
|
+
return html.length > 160 ? `${html.slice(0, 159)}\u2026` : html;
|
|
34838
|
+
}
|
|
34839
|
+
function scanKeyboard(root = document, options = {}) {
|
|
34840
|
+
const prefixes = options.frameworkPrefixes ?? DEFAULT_FRAMEWORK_PREFIXES;
|
|
34841
|
+
const isVisible = options.isVisible;
|
|
34842
|
+
const findings = [];
|
|
34843
|
+
const make = (element, id, impact, help, helpUrl) => {
|
|
34844
|
+
const componentPath = resolveComponentPath(element);
|
|
34845
|
+
return {
|
|
34846
|
+
id,
|
|
34847
|
+
impact,
|
|
34848
|
+
help,
|
|
34849
|
+
helpUrl,
|
|
34850
|
+
component: appComponentFromPath(componentPath, prefixes),
|
|
34851
|
+
componentPath,
|
|
34852
|
+
directives: resolveDirectiveNames(element),
|
|
34853
|
+
target: shortSelector(element),
|
|
34854
|
+
html: shortHtml(element)
|
|
34855
|
+
};
|
|
34856
|
+
};
|
|
34857
|
+
for (const element of root.querySelectorAll("*")) {
|
|
34858
|
+
if (isNativelyFocusable(element))
|
|
34859
|
+
continue;
|
|
34860
|
+
const role = element.getAttribute("role")?.toLowerCase() ?? "";
|
|
34861
|
+
const events = resolveListenerEvents(element);
|
|
34862
|
+
const hasClick = events.includes("click");
|
|
34863
|
+
const interactiveByRole = INTERACTIVE_ROLES.has(role);
|
|
34864
|
+
if (!hasClick && !interactiveByRole)
|
|
34865
|
+
continue;
|
|
34866
|
+
if (!interactiveByRole && hasFocusableDescendant(element))
|
|
34867
|
+
continue;
|
|
34868
|
+
const focusable = isTabbable(element, isVisible);
|
|
34869
|
+
if (!focusable) {
|
|
34870
|
+
const reason = interactiveByRole ? `has role="${role}"` : "has a click handler";
|
|
34871
|
+
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));
|
|
34872
|
+
continue;
|
|
34873
|
+
}
|
|
34874
|
+
const hasKey = events.some((e) => KEY_EVENTS.includes(e));
|
|
34875
|
+
if (hasClick && !hasKey) {
|
|
34876
|
+
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
34877
|
}
|
|
34738
|
-
axPanel.replaceChildren(...buildAxPanelContent(doc, data));
|
|
34739
|
-
axPanel.style.display = "block";
|
|
34740
34878
|
}
|
|
34741
|
-
|
|
34742
|
-
|
|
34743
|
-
clearTabOrder();
|
|
34744
|
-
renderAxPanel(null);
|
|
34745
|
-
win?.removeEventListener("scroll", onViewportChange, { capture: true });
|
|
34746
|
-
win?.removeEventListener("resize", onViewportChange);
|
|
34747
|
-
container.remove();
|
|
34879
|
+
for (const modal of findUncontainedModals(root, { frameworkPrefixes: prefixes, isVisible })) {
|
|
34880
|
+
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
34881
|
}
|
|
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;
|
|
34882
|
+
const stops = tabSequence(root, { frameworkPrefixes: prefixes, isVisible });
|
|
34883
|
+
for (const jump of visualOrderJumps(stops)) {
|
|
34884
|
+
const stop = stops[jump];
|
|
34885
|
+
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));
|
|
34886
|
+
}
|
|
34887
|
+
return findings;
|
|
34812
34888
|
}
|
|
34813
|
-
|
|
34814
|
-
|
|
34815
|
-
|
|
34816
|
-
|
|
34817
|
-
|
|
34889
|
+
|
|
34890
|
+
// dist/keyboard/focus-walk.js
|
|
34891
|
+
function detectTabTrap(observations, collapsible = /* @__PURE__ */ new Set()) {
|
|
34892
|
+
const seq = [];
|
|
34893
|
+
for (const obs of observations) {
|
|
34894
|
+
const prev = seq[seq.length - 1];
|
|
34895
|
+
if (obs !== null && obs === prev && collapsible.has(obs))
|
|
34896
|
+
continue;
|
|
34897
|
+
seq.push(obs);
|
|
34898
|
+
}
|
|
34899
|
+
const lastSeen = /* @__PURE__ */ new Map();
|
|
34900
|
+
for (let i = 0; i < seq.length; i++) {
|
|
34901
|
+
const id = seq[i];
|
|
34902
|
+
if (id === null)
|
|
34903
|
+
continue;
|
|
34904
|
+
const before = lastSeen.get(id);
|
|
34905
|
+
if (before !== void 0) {
|
|
34906
|
+
const between = seq.slice(before, i);
|
|
34907
|
+
if (between.includes(null))
|
|
34908
|
+
return { kind: "complete" };
|
|
34909
|
+
return { kind: "trap", cycle: between };
|
|
34910
|
+
}
|
|
34911
|
+
lastSeen.set(id, i);
|
|
34818
34912
|
}
|
|
34913
|
+
return { kind: "pending" };
|
|
34819
34914
|
}
|
|
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;
|
|
34915
|
+
var NO_KEYBOARD_TRAP_URL = "https://www.w3.org/WAI/WCAG22/Understanding/no-keyboard-trap.html";
|
|
34916
|
+
function deepActiveElement(doc) {
|
|
34917
|
+
let active = doc.activeElement;
|
|
34918
|
+
while (active?.shadowRoot?.activeElement)
|
|
34919
|
+
active = active.shadowRoot.activeElement;
|
|
34920
|
+
return active;
|
|
34850
34921
|
}
|
|
34851
|
-
function
|
|
34852
|
-
const
|
|
34853
|
-
|
|
34854
|
-
|
|
34855
|
-
|
|
34856
|
-
|
|
34857
|
-
|
|
34858
|
-
|
|
34859
|
-
|
|
34860
|
-
|
|
34861
|
-
|
|
34862
|
-
|
|
34863
|
-
|
|
34864
|
-
return tops;
|
|
34922
|
+
function containedByOpenModal(elements) {
|
|
34923
|
+
const modalOf = (el) => {
|
|
34924
|
+
const aria = el.closest('[aria-modal="true"]');
|
|
34925
|
+
if (aria)
|
|
34926
|
+
return aria;
|
|
34927
|
+
try {
|
|
34928
|
+
return el.closest("dialog:modal");
|
|
34929
|
+
} catch {
|
|
34930
|
+
return null;
|
|
34931
|
+
}
|
|
34932
|
+
};
|
|
34933
|
+
const first = elements[0] ? modalOf(elements[0]) : null;
|
|
34934
|
+
return first !== null && elements.every((el) => modalOf(el) === first);
|
|
34865
34935
|
}
|
|
34866
|
-
function
|
|
34867
|
-
|
|
34868
|
-
|
|
34869
|
-
|
|
34870
|
-
|
|
34871
|
-
|
|
34872
|
-
height: `${rect.height}px`
|
|
34873
|
-
});
|
|
34936
|
+
function commonAncestor(elements) {
|
|
34937
|
+
let candidate = elements[0];
|
|
34938
|
+
while (candidate && !elements.every((el) => candidate.contains(el))) {
|
|
34939
|
+
candidate = candidate.parentElement;
|
|
34940
|
+
}
|
|
34941
|
+
return candidate ?? elements[0];
|
|
34874
34942
|
}
|
|
34875
|
-
function
|
|
34876
|
-
|
|
34877
|
-
const
|
|
34878
|
-
|
|
34879
|
-
|
|
34880
|
-
|
|
34881
|
-
|
|
34943
|
+
function createFocusWalkProbe(doc = document, frameworkPrefixes = DEFAULT_FRAMEWORK_PREFIXES) {
|
|
34944
|
+
const ids = /* @__PURE__ */ new WeakMap();
|
|
34945
|
+
const byId = /* @__PURE__ */ new Map();
|
|
34946
|
+
return {
|
|
34947
|
+
probe() {
|
|
34948
|
+
const active = deepActiveElement(doc);
|
|
34949
|
+
if (!active || active === doc.body || active === doc.documentElement) {
|
|
34950
|
+
return { id: null, iframe: false };
|
|
34951
|
+
}
|
|
34952
|
+
let id = ids.get(active);
|
|
34953
|
+
if (id === void 0) {
|
|
34954
|
+
id = byId.size + 1;
|
|
34955
|
+
ids.set(active, id);
|
|
34956
|
+
byId.set(id, active);
|
|
34957
|
+
}
|
|
34958
|
+
return { id, iframe: active.tagName === "IFRAME" };
|
|
34959
|
+
},
|
|
34960
|
+
stopCount() {
|
|
34961
|
+
return tabSequence(doc, { frameworkPrefixes }).length;
|
|
34962
|
+
},
|
|
34963
|
+
trapFinding(cycle, shiftTabEscapes) {
|
|
34964
|
+
const elements = [...new Set(cycle)].map((id) => byId.get(id)).filter((el) => el !== void 0);
|
|
34965
|
+
if (elements.length === 0 || containedByOpenModal(elements))
|
|
34966
|
+
return null;
|
|
34967
|
+
const owner = elements.length === 1 ? elements[0] : commonAncestor(elements);
|
|
34968
|
+
const reachable = new Set(byId.values());
|
|
34969
|
+
const unreached = tabSequence(doc, { frameworkPrefixes }).filter((stop) => !reachable.has(stop.element)).length;
|
|
34970
|
+
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`;
|
|
34971
|
+
const reach = unreached > 0 ? `, so ${unreached} tabbable control(s) in the page are never reached` : "";
|
|
34972
|
+
const shift = shiftTabEscapes ? " Shift+Tab does get out, but Tab alone should too." : " Shift+Tab doesn't get out either.";
|
|
34973
|
+
const componentPath = resolveComponentPath(owner);
|
|
34974
|
+
return {
|
|
34975
|
+
id: "ngbr/focus-trap",
|
|
34976
|
+
impact: shiftTabEscapes ? "moderate" : "serious",
|
|
34977
|
+
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.`,
|
|
34978
|
+
helpUrl: NO_KEYBOARD_TRAP_URL,
|
|
34979
|
+
component: appComponentFromPath(componentPath, frameworkPrefixes),
|
|
34980
|
+
componentPath,
|
|
34981
|
+
directives: resolveDirectiveNames(owner),
|
|
34982
|
+
target: shortSelector(owner),
|
|
34983
|
+
html: shortHtml(owner)
|
|
34984
|
+
};
|
|
34985
|
+
}
|
|
34986
|
+
};
|
|
34882
34987
|
}
|
|
34883
34988
|
|
|
34884
34989
|
// dist/scan.js
|