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