@ngbracket/a11y-devtools 0.8.0 → 0.10.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,6 +34222,336 @@
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);
34313
+ }
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
+ };
34336
+ });
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);
34347
+ }
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++;
34365
+ }
34366
+ if (insideCount > 0 && outsideCount > 0)
34367
+ results.push({ element: modal, insideCount, outsideCount });
34368
+ }
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
+ };
34424
+ };
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;
34439
+ }
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));
34443
+ }
34444
+ }
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));
34447
+ }
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));
34452
+ }
34453
+ return findings;
34454
+ }
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);
34464
+ }
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);
34478
+ }
34479
+ return { kind: "pending" };
34480
+ }
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;
34487
+ }
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);
34501
+ }
34502
+ function commonAncestor(elements) {
34503
+ let candidate = elements[0];
34504
+ while (candidate && !elements.every((el) => candidate.contains(el))) {
34505
+ candidate = candidate.parentElement;
34506
+ }
34507
+ return candidate ?? elements[0];
34508
+ }
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
+ };
34553
+ }
34554
+
34225
34555
  // dist/overlay.js
34226
34556
  var SVG_NS = "http://www.w3.org/2000/svg";
34227
34557
  var TAB_ORDER_COLOR = "#0b8f8f";
@@ -34534,237 +34864,6 @@
34534
34864
  }, 600);
34535
34865
  }
34536
34866
 
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 nativeTabIndex(element) {
34555
- return isNativelyFocusable(element) ? 0 : -1;
34556
- }
34557
- function isNativelyFocusable(element) {
34558
- const tag = element.tagName.toLowerCase();
34559
- switch (tag) {
34560
- case "a":
34561
- case "area":
34562
- return element.hasAttribute("href");
34563
- case "button":
34564
- case "select":
34565
- case "textarea":
34566
- return true;
34567
- case "input":
34568
- return element.getAttribute("type")?.toLowerCase() !== "hidden";
34569
- case "summary":
34570
- return true;
34571
- case "iframe":
34572
- case "object":
34573
- case "embed":
34574
- return true;
34575
- case "audio":
34576
- case "video":
34577
- return element.hasAttribute("controls");
34578
- }
34579
- const editable = element.getAttribute("contenteditable");
34580
- return editable !== null && editable !== "false";
34581
- }
34582
- function resolvedTabIndex(element) {
34583
- const attr = element.getAttribute("tabindex");
34584
- if (attr === null)
34585
- return nativeTabIndex(element);
34586
- const parsed = Number.parseInt(attr, 10);
34587
- return Number.isNaN(parsed) ? nativeTabIndex(element) : parsed;
34588
- }
34589
- function isDisabled(element) {
34590
- if ("disabled" in element && element.disabled)
34591
- return true;
34592
- return element.closest("fieldset[disabled]") !== null && element.closest("legend") === null;
34593
- }
34594
- function isStructurallyHidden(element) {
34595
- if (element.closest("[inert]") || element.closest("[hidden]"))
34596
- return true;
34597
- const closedDetails = element.closest("details:not([open])");
34598
- return closedDetails !== null && element.closest("summary") === null && element !== closedDetails;
34599
- }
34600
- function defaultIsVisible(element) {
34601
- const view = element.ownerDocument?.defaultView;
34602
- if (!view?.getComputedStyle)
34603
- return true;
34604
- for (let node = element; node; node = node.parentElement) {
34605
- const style = view.getComputedStyle(node);
34606
- if (style.display === "none")
34607
- return false;
34608
- if (style.visibility === "hidden" || style.visibility === "collapse")
34609
- return false;
34610
- }
34611
- return true;
34612
- }
34613
- function isTabbable(element, isVisible = defaultIsVisible) {
34614
- if (resolvedTabIndex(element) < 0)
34615
- return false;
34616
- if (isDisabled(element))
34617
- return false;
34618
- if (isStructurallyHidden(element))
34619
- return false;
34620
- const editable = element.getAttribute("contenteditable");
34621
- if (editable === "false" && !isNativelyFocusable(element) && !element.hasAttribute("tabindex")) {
34622
- return false;
34623
- }
34624
- return isVisible(element);
34625
- }
34626
- function tabSequence(root = document, options = {}) {
34627
- const isVisible = options.isVisible ?? defaultIsVisible;
34628
- const prefixes = options.frameworkPrefixes ?? DEFAULT_FRAMEWORK_PREFIXES;
34629
- const candidates = [...root.querySelectorAll(FOCUSABLE_SELECTOR)].filter((el) => isTabbable(el, isVisible));
34630
- const withMeta = candidates.map((element, domIndex) => ({
34631
- element,
34632
- domIndex,
34633
- tabindex: resolvedTabIndex(element),
34634
- positive: /^\d+$/.test(element.getAttribute("tabindex") ?? "") && resolvedTabIndex(element) > 0
34635
- }));
34636
- const positives = withMeta.filter((m) => m.tabindex > 0).sort((a, b) => a.tabindex - b.tabindex || a.domIndex - b.domIndex);
34637
- const zeros = withMeta.filter((m) => m.tabindex === 0);
34638
- return [...positives, ...zeros].map((m, i) => {
34639
- const componentPath = resolveComponentPath(m.element);
34640
- return {
34641
- element: m.element,
34642
- order: i + 1,
34643
- tabindex: m.tabindex,
34644
- positive: m.positive,
34645
- component: appComponentFromPath(componentPath, prefixes),
34646
- componentPath
34647
- };
34648
- });
34649
- }
34650
- function visualOrderJumps(stops, getRect = (el) => el.getBoundingClientRect(), rowThreshold = 8) {
34651
- const jumps = [];
34652
- for (let i = 1; i < stops.length; i++) {
34653
- const prev = getRect(stops[i - 1].element);
34654
- const curr = getRect(stops[i].element);
34655
- const movedUp = curr.top < prev.top - rowThreshold;
34656
- const sameRowMovedLeft = Math.abs(curr.top - prev.top) <= rowThreshold && curr.left < prev.left - rowThreshold;
34657
- if (movedUp || sameRowMovedLeft)
34658
- jumps.push(i);
34659
- }
34660
- return jumps;
34661
- }
34662
-
34663
- // dist/keyboard/focus-trap.js
34664
- function findUncontainedModals(root = document, options = {}) {
34665
- const stops = tabSequence(root, options);
34666
- if (stops.length === 0)
34667
- return [];
34668
- const results = [];
34669
- for (const modal of root.querySelectorAll('[aria-modal="true"]')) {
34670
- let insideCount = 0;
34671
- let outsideCount = 0;
34672
- for (const stop of stops) {
34673
- if (modal.contains(stop.element))
34674
- insideCount++;
34675
- else
34676
- outsideCount++;
34677
- }
34678
- if (insideCount > 0 && outsideCount > 0)
34679
- results.push({ element: modal, insideCount, outsideCount });
34680
- }
34681
- return results;
34682
- }
34683
-
34684
- // dist/keyboard/keyboard-scan.js
34685
- var INTERACTIVE_ROLES = /* @__PURE__ */ new Set([
34686
- "button",
34687
- "link",
34688
- "menuitem",
34689
- "menuitemcheckbox",
34690
- "menuitemradio",
34691
- "tab",
34692
- "switch",
34693
- "checkbox",
34694
- "radio",
34695
- "option",
34696
- "slider",
34697
- "spinbutton",
34698
- "combobox",
34699
- "textbox",
34700
- "searchbox",
34701
- "treeitem"
34702
- ]);
34703
- var KEY_EVENTS = ["keydown", "keyup", "keypress"];
34704
- var UNDERSTANDING = "https://www.w3.org/WAI/WCAG22/Understanding";
34705
- var KEYBOARD_URL = `${UNDERSTANDING}/keyboard.html`;
34706
- var FOCUS_ORDER_URL = `${UNDERSTANDING}/focus-order.html`;
34707
- var DIALOG_MODAL_URL = "https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/";
34708
- function shortSelector(element) {
34709
- const tag = element.tagName.toLowerCase();
34710
- if (element.id)
34711
- return `${tag}#${element.id}`;
34712
- const classes = (element.getAttribute("class") ?? "").trim().split(/\s+/).filter(Boolean).slice(0, 2);
34713
- return classes.length ? `${tag}.${classes.join(".")}` : tag;
34714
- }
34715
- function shortHtml(element) {
34716
- const html = element.outerHTML ?? "";
34717
- return html.length > 160 ? `${html.slice(0, 159)}\u2026` : html;
34718
- }
34719
- function scanKeyboard(root = document, options = {}) {
34720
- const prefixes = options.frameworkPrefixes ?? DEFAULT_FRAMEWORK_PREFIXES;
34721
- const isVisible = options.isVisible;
34722
- const findings = [];
34723
- const make = (element, id, impact, help, helpUrl) => {
34724
- const componentPath = resolveComponentPath(element);
34725
- return {
34726
- id,
34727
- impact,
34728
- help,
34729
- helpUrl,
34730
- component: appComponentFromPath(componentPath, prefixes),
34731
- componentPath,
34732
- directives: resolveDirectiveNames(element),
34733
- target: shortSelector(element),
34734
- html: shortHtml(element)
34735
- };
34736
- };
34737
- for (const element of root.querySelectorAll("*")) {
34738
- if (isNativelyFocusable(element))
34739
- continue;
34740
- const role = element.getAttribute("role")?.toLowerCase() ?? "";
34741
- const events = resolveListenerEvents(element);
34742
- const hasClick = events.includes("click");
34743
- const interactiveByRole = INTERACTIVE_ROLES.has(role);
34744
- if (!hasClick && !interactiveByRole)
34745
- continue;
34746
- const focusable = isTabbable(element, isVisible);
34747
- if (!focusable) {
34748
- const reason = interactiveByRole ? `has role="${role}"` : "has a click handler";
34749
- 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));
34750
- continue;
34751
- }
34752
- const hasKey = events.some((e) => KEY_EVENTS.includes(e));
34753
- if (hasClick && !hasKey) {
34754
- 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));
34755
- }
34756
- }
34757
- for (const modal of findUncontainedModals(root, { frameworkPrefixes: prefixes, isVisible })) {
34758
- 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));
34759
- }
34760
- const stops = tabSequence(root, { frameworkPrefixes: prefixes, isVisible });
34761
- for (const jump of visualOrderJumps(stops)) {
34762
- const stop = stops[jump];
34763
- 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));
34764
- }
34765
- return findings;
34766
- }
34767
-
34768
34867
  // dist/scan.js
34769
34868
  var runChain = Promise.resolve();
34770
34869
  function scan(root = document, options, scanOptions) {
@@ -34811,6 +34910,7 @@
34811
34910
  // dist/inpage.js
34812
34911
  var run = (options, scanOptions) => scan(document, options, scanOptions);
34813
34912
  globalThis.__ngbA11yScan = run;
34913
+ globalThis.__ngbA11yCreateFocusProbe = (prefixes) => createFocusWalkProbe(document, prefixes);
34814
34914
  })();
34815
34915
  /*! Bundled license information:
34816
34916
 
package/dist/inpage.js CHANGED
@@ -1,3 +1,7 @@
1
+ import { createFocusWalkProbe } from './keyboard/focus-walk.js';
1
2
  import { scan } from './scan.js';
2
3
  const run = (options, scanOptions) => scan(document, options, scanOptions);
3
4
  globalThis.__ngbA11yScan = run;
5
+ // The in-page half of the focus-trap walk: the driver creates a probe, presses
6
+ // real Tab keys, and asks the probe what has focus after each one.
7
+ globalThis.__ngbA11yCreateFocusProbe = (prefixes) => createFocusWalkProbe(document, prefixes);
@@ -0,0 +1,55 @@
1
+ import type { A11yFinding } from '../scan.js';
2
+ /** One observation from the walk: a focused element's id, or null when focus is on `<body>`/nothing. */
3
+ export type FocusObservation = number | null;
4
+ /** Outcome of {@link detectTabTrap} over the observations so far. */
5
+ export type TabWalkVerdict =
6
+ /** Focus wrapped past the end of the page and came back round — no trap. */
7
+ {
8
+ kind: 'complete';
9
+ }
10
+ /** Focus is cycling through `cycle` (element ids, in order) without ever leaving. */
11
+ | {
12
+ kind: 'trap';
13
+ cycle: number[];
14
+ }
15
+ /** Not enough evidence yet — keep pressing Tab. */
16
+ | {
17
+ kind: 'pending';
18
+ };
19
+ /**
20
+ * Classify a Tab walk. Browsers pass focus through `<body>` (null here) when Tab
21
+ * wraps off the end of the page, so an element seen again *after* a null means
22
+ * focus made a full lap; seen again with no null in between means it looped
23
+ * inside part of the page — a trap. The walk may start mid-page (wherever the
24
+ * browser's navigation starting point is), which this handles for free.
25
+ *
26
+ * Consecutive repeats of an `iframe` are the browser tabbing *inside* the frame
27
+ * (the parent document only ever sees the frame element), so callers pass
28
+ * `collapsible` ids to skip those rather than read them as a trap.
29
+ */
30
+ export declare function detectTabTrap(observations: readonly FocusObservation[], collapsible?: ReadonlySet<number>): TabWalkVerdict;
31
+ /** In-page half of the walk; installed on `window` by the report-mode bundle. */
32
+ export interface FocusWalkProbe {
33
+ /**
34
+ * The currently focused element's walk id (drilling into open shadow roots),
35
+ * or null when focus is on `<body>`/nothing. `iframe` is true when the focused
36
+ * element is a frame, whose inner Tab stops the parent can't see.
37
+ */
38
+ probe(): {
39
+ id: FocusObservation;
40
+ iframe: boolean;
41
+ };
42
+ /** Number of tabbable stops in the page, for sizing the walk. */
43
+ stopCount(): number;
44
+ /**
45
+ * Build the finding for a detected cycle, or null when the cycle is focus
46
+ * correctly contained in an open modal. `shiftTabEscapes` records whether
47
+ * Shift+Tab got out (it lowers the impact but it's still a problem).
48
+ */
49
+ trapFinding(cycle: readonly number[], shiftTabEscapes: boolean): A11yFinding | null;
50
+ }
51
+ /**
52
+ * Create the in-page probe. Ids are assigned on first sight and held in page
53
+ * memory only — the walk never writes to the DOM.
54
+ */
55
+ export declare function createFocusWalkProbe(doc?: Document, frameworkPrefixes?: readonly string[]): FocusWalkProbe;