tab-trail 1.0.0 → 1.1.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 +13 -0
- package/README.md +25 -16
- package/data/api.json +8 -0
- package/data/features.json +48 -1
- package/data/limits.json +1 -1
- package/dist/index.mjs +9 -9
- package/dist/tab-trail.js +541 -19
- package/package.json +4 -4
package/dist/tab-trail.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Tab trail 1.
|
|
2
|
+
* Tab trail 1.1.0, https://matjazkorosec.com/tools/tab-trail
|
|
3
3
|
*
|
|
4
4
|
* MIT License
|
|
5
5
|
*
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
* SOFTWARE.
|
|
25
25
|
*/
|
|
26
26
|
(function(){
|
|
27
|
-
/* Tab trail 1.
|
|
28
|
-
var VERSION = "1.
|
|
27
|
+
/* Tab trail 1.1.0. Copyright (c) 2026 Matjaž Korošec. MIT License, full text: https://github.com/matjazkorosec/tab-trail/blob/main/LICENSE */
|
|
28
|
+
var VERSION = "1.1.0";
|
|
29
29
|
var ID = "tab-trail-host";
|
|
30
30
|
var prev = [].filter.call(document.querySelectorAll("[id='" + ID + "']"), function (e) { return typeof e.__close === "function"; })[0];
|
|
31
31
|
if (prev) { prev.__close(); return; }
|
|
@@ -423,6 +423,8 @@ style.textContent = [
|
|
|
423
423
|
".p.g{cursor:grabbing;user-select:none}",
|
|
424
424
|
".n b.e{color:#d0103a}",
|
|
425
425
|
".n b.ok{color:#1f7a3f}",
|
|
426
|
+
"button.lq{all:unset;cursor:pointer;color:#1e3a8a;font-weight:700}.cg{color:#5f564c}.pk{color:#c2410c}",
|
|
427
|
+
".bar{display:flex;gap:2px;height:24px;margin:6px 0 2px}.bar button{border:0;padding:0;min-width:6px;border-radius:4px;cursor:pointer}.bar button:focus-visible{outline:2px solid #1a1612;outline-offset:2px}.bl{display:flex;flex-wrap:wrap;gap:4px 12px;font-size:13px;margin:4px 0 8px}.bl em{width:10px;height:10px;border-radius:3px;display:inline-block;margin-right:5px}",
|
|
426
428
|
".s{cursor:pointer}",
|
|
427
429
|
"svg.in{z-index:1}",
|
|
428
430
|
"g.o{pointer-events:auto;cursor:pointer;-webkit-user-select:none;user-select:none}",
|
|
@@ -729,10 +731,12 @@ function fill() {
|
|
|
729
731
|
count(forcedBad.length, forcedBad.length === 1 ? " stop has tabindex above 0, which pulls it ahead of the page" : " stops have tabindex above 0, which pulls them ahead of the page", true);
|
|
730
732
|
chipList(forcedBad, true);
|
|
731
733
|
}
|
|
734
|
+
costDraw();
|
|
735
|
+
mapDraw();
|
|
732
736
|
if (skip) skipPanel();
|
|
733
737
|
if (had >= 0 && chips.length) chips[Math.min(had, chips.length - 1)].focus();
|
|
734
738
|
}
|
|
735
|
-
function sig() { return [stops.length].concat(missed, ["|"], hovers, ["|"], forced, ["|"], forcedBad); }
|
|
739
|
+
function sig() { return [stops.length, mapOn && mapOn.checked && JSON.stringify(regions()[0]), costOn && costOn.checked && goals().map(function (g) { return g.presses + g.name; }).join()].concat(missed, ["|"], hovers, ["|"], forced, ["|"], forcedBad); }
|
|
736
740
|
function chipList(list, num) {
|
|
737
741
|
var made = chipUl(info, list, function (m) { return (num && stops.indexOf(m) >= 0 ? stops.indexOf(m) + 1 + ": " : "") + label(m); }, function (m, c) {
|
|
738
742
|
shownEl = m;
|
|
@@ -767,6 +771,10 @@ var prevBtn = pageBtn("Previous", -1), nextBtn = pageBtn("Next", 1);
|
|
|
767
771
|
var group = document.createElement("div");
|
|
768
772
|
group.className = "cd gp";
|
|
769
773
|
group.appendChild(pager);
|
|
774
|
+
var costBox = document.createElement("div");
|
|
775
|
+
resCard.appendChild(costBox);
|
|
776
|
+
var mapBox = document.createElement("div");
|
|
777
|
+
resCard.appendChild(mapBox);
|
|
770
778
|
var jumpBox = document.createElement("div");
|
|
771
779
|
resCard.appendChild(jumpBox);
|
|
772
780
|
panel.appendChild(group);
|
|
@@ -863,6 +871,166 @@ function where(s) {
|
|
|
863
871
|
var r = s.getBoundingClientRect();
|
|
864
872
|
return scrollX + "," + scrollY + "," + r.left + "," + r.top;
|
|
865
873
|
}
|
|
874
|
+
var restSig = new WeakMap(), noRing = [], probRing = new Map(), SIG = ["outline-style", "outline-width", "outline-color", "box-shadow", "background-color", "background-image", "color", "text-decoration-line", "text-decoration-color", "opacity", "transform", "filter"];
|
|
875
|
+
function upOf(e) { return e && (e.parentElement || (e.parentNode && e.parentNode.host)); }
|
|
876
|
+
function focusSig(e) {
|
|
877
|
+
var out = [], up = upOf(e);
|
|
878
|
+
[[e], [e, "::before"], [e, "::after"], [up], [upOf(up)], [e.nextElementSibling], [e.firstElementChild], [e.labels && e.labels[0]]].forEach(function (x) {
|
|
879
|
+
if (!x[0]) return;
|
|
880
|
+
var c = getComputedStyle(x[0], x[1] || null), o = c.outlineStyle !== "none" && c.outlineWidth !== "0px";
|
|
881
|
+
SIG.forEach(function (k) { if (o || k.indexOf("outline") < 0) out.push(c.getPropertyValue(k)); });
|
|
882
|
+
["top", "right", "bottom", "left"].forEach(function (d) {
|
|
883
|
+
var w = c.getPropertyValue("border-" + d + "-width");
|
|
884
|
+
out.push(w, w === "0px" ? "" : c.getPropertyValue("border-" + d + "-color"));
|
|
885
|
+
});
|
|
886
|
+
});
|
|
887
|
+
return out.join("|");
|
|
888
|
+
}
|
|
889
|
+
function rest(e) {
|
|
890
|
+
if (!e) return;
|
|
891
|
+
if (e.matches(":hover")) restSig.delete(e);
|
|
892
|
+
else restSig.set(e, focusSig(e));
|
|
893
|
+
}
|
|
894
|
+
var noOutline = null;
|
|
895
|
+
function outlineRule(e) {
|
|
896
|
+
if (!noOutline) {
|
|
897
|
+
noOutline = [];
|
|
898
|
+
var go = function (list, src) {
|
|
899
|
+
for (var i = 0; i < list.length; i++) {
|
|
900
|
+
var r = list[i], st = r.style;
|
|
901
|
+
if (r.cssRules && r.cssRules.length) go(r.cssRules, src);
|
|
902
|
+
if (r.selectorText && st && (st.outlineStyle === "none" || /^0(px)?$/.test(st.outlineWidth))) parts(r.selectorText).forEach(function (p) { noOutline.push([p, src, p.replace(/:focus(-visible)?(?![\w-])/g, "").trim() || "*"]); });
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
Array.prototype.slice.call(document.styleSheets).concat(document.adoptedStyleSheets || []).forEach(function (sh) {
|
|
906
|
+
try { go(sh.cssRules, sh.href || (sh.ownerNode ? "an inline <style> in the page" : "a style sheet added by script")); } catch (x) {}
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
for (var i = 0; i < noOutline.length; i++) {
|
|
910
|
+
try { if (e.matches(noOutline[i][2])) return noOutline[i]; } catch (x) {}
|
|
911
|
+
}
|
|
912
|
+
return null;
|
|
913
|
+
}
|
|
914
|
+
var ghosts = [], ghostOf = new Map(), probGhost = new Map(), GHOST = { off: "is off screen", size: "has no size", inv: "is invisible", aria: "is inside aria-hidden" };
|
|
915
|
+
function unseen(e) {
|
|
916
|
+
var r = e.getBoundingClientRect();
|
|
917
|
+
if (r.width < 1 || r.height < 1) return "size";
|
|
918
|
+
if (r.right <= 0 || r.left >= innerWidth || r.bottom <= 0 || r.top >= innerHeight) return "off";
|
|
919
|
+
if (getComputedStyle(e).visibility === "hidden") return "inv";
|
|
920
|
+
for (var n = e; n; n = upOf(n)) if (getComputedStyle(n).opacity === "0") return "inv";
|
|
921
|
+
return "";
|
|
922
|
+
}
|
|
923
|
+
function ghostWhy(e) {
|
|
924
|
+
var why = unseen(e), lb = (e.labels && e.labels[0]) || (e.tagName === "INPUT" && e.nextElementSibling);
|
|
925
|
+
if (why && why !== "off" && lb && !unseen(lb)) why = "";
|
|
926
|
+
for (var n = e; n && !why; n = upOf(n)) if (n.getAttribute("aria-hidden") === "true") why = "aria";
|
|
927
|
+
return why;
|
|
928
|
+
}
|
|
929
|
+
function ghostCheck(s) {
|
|
930
|
+
if (hovers.some(function (h) { return hovSeen.has(h) && within(hovHid.get(h), s); })) return true;
|
|
931
|
+
var why = ghostWhy(s), was = ghosts.indexOf(s) >= 0;
|
|
932
|
+
if (!why) {
|
|
933
|
+
if (!was) log("OK", "Ghost stop", [ref(s), " is visible when Tab is on it."]);
|
|
934
|
+
else {
|
|
935
|
+
ghosts.splice(ghosts.indexOf(s), 1);
|
|
936
|
+
ghostOf.delete(s);
|
|
937
|
+
probGhost.get(s).fixed = true;
|
|
938
|
+
probGhost.delete(s);
|
|
939
|
+
renderJumps();
|
|
940
|
+
queue();
|
|
941
|
+
log("OK", "Ghost stop", [ref(s), " shows now when Tab is on it."]);
|
|
942
|
+
}
|
|
943
|
+
return false;
|
|
944
|
+
}
|
|
945
|
+
if (was) return true;
|
|
946
|
+
ghosts.push(s);
|
|
947
|
+
ghostOf.set(s, why);
|
|
948
|
+
renderJumps();
|
|
949
|
+
queue();
|
|
950
|
+
announce("Ghost stop: stop " + (stops.indexOf(s) + 1) + ", " + label(s) + ", " + GHOST[why] + ".");
|
|
951
|
+
var aria = why === "aria";
|
|
952
|
+
log("PROBLEM", "Ghost stop", [ref(s), " " + GHOST[why] + " when Tab is on it."], aiOf(aria ? W_NAME : W_VIS, aria ? "An element Tab can reach is not hidden from screen readers." : "The element shows on screen while it has keyboard focus.", aria ? "Remove aria-hidden, or add inert or tabindex=\"-1\" so Tab skips it too." : "Hide it with display: none or inert while it is closed, or show it when it gets focus.", [["Element", s, null, true]]), aria ? "4.1.2 A" : null);
|
|
953
|
+
probGhost.set(s, logs[logs.length - 1]);
|
|
954
|
+
return true;
|
|
955
|
+
}
|
|
956
|
+
var skipBad = null, noSkip = 0, skipSaid = null, probSkip = null, SKIPW = /(^|[^a-z\u010d\u0161\u017e])(skip|jump|main|content|presko\u010di|vsebina)(?![a-z\u010d\u0161\u017e])/i;
|
|
957
|
+
function mainRegion() { return [].filter.call(document.querySelectorAll("main,[role=main]"), shown)[0] || null; }
|
|
958
|
+
function tucked(e) {
|
|
959
|
+
var r = e.getBoundingClientRect();
|
|
960
|
+
return (r.width < 2 && r.height < 2) || r.bottom + scrollY <= 0 || r.right + scrollX <= 0;
|
|
961
|
+
}
|
|
962
|
+
function skipLink() {
|
|
963
|
+
for (var i = 0; i < 3 && i < stops.length; i++) {
|
|
964
|
+
var e = stops[i], h = e.getAttribute("href") || "";
|
|
965
|
+
if (e.tagName === "A" && h.charAt(0) === "#" && h.length > 1 && (SKIPW.test(label(e)) || (e !== deep() && tucked(e)))) return e;
|
|
966
|
+
}
|
|
967
|
+
return null;
|
|
968
|
+
}
|
|
969
|
+
function ahead(m) { return stops.filter(function (x) { return !within(m, x) && m.compareDocumentPosition(x) & 2; }).length; }
|
|
970
|
+
function skipCheck() {
|
|
971
|
+
var l = skipLink(), m = mainRegion(), why = "", n = 0, id = "", t = null;
|
|
972
|
+
if (l) {
|
|
973
|
+
id = l.getAttribute("href").slice(1);
|
|
974
|
+
try { id = decodeURIComponent(id); } catch (x) {}
|
|
975
|
+
t = document.getElementById(id) || document.getElementsByName(id)[0];
|
|
976
|
+
if (!t) why = "#" + id + " is missing";
|
|
977
|
+
else if (!shown(t)) why = "#" + id + " is hidden";
|
|
978
|
+
else if (!stops.some(function (x) { return x === t || within(t, x) || t.compareDocumentPosition(x) & 4; })) why = "nothing after #" + id + " takes focus";
|
|
979
|
+
} else if (m) {
|
|
980
|
+
n = ahead(m);
|
|
981
|
+
if (n < 15) n = 0;
|
|
982
|
+
}
|
|
983
|
+
var key = [l, why, n, !!m].join("|");
|
|
984
|
+
if (key === skipSaid) return;
|
|
985
|
+
skipSaid = key;
|
|
986
|
+
if (probSkip) probSkip.fixed = true;
|
|
987
|
+
probSkip = null;
|
|
988
|
+
skipBad = l && why ? { link: l, why: why, to: t } : null;
|
|
989
|
+
noSkip = n;
|
|
990
|
+
renderJumps();
|
|
991
|
+
queue();
|
|
992
|
+
if (skipBad) log("PROBLEM", "Broken skip link", [ref(l), " goes nowhere: " + why + "."], aiOf(W_BYPASS, "The skip link moves focus past the header to the main content.", t ? "Make #" + id + " visible, and put the main content after it." : "Give the main content id=\"" + id + "\", or point the link at the id it has.", [["Element", l], ["Main content", m]]));
|
|
993
|
+
else if (n) log("PROBLEM", "Broken skip link", [n + " stops before the main content, and no skip link."], aiOf(W_BYPASS, "A skip link as the first stop moves focus past the header to the main content.", "Add <a href=\"#main\">Skip to content</a> as the first link, and id=\"main\" on <main>.", [["Main content", m]]));
|
|
994
|
+
else if (l) return log("OK", "Broken skip link", [ref(l), " goes to #" + id + "."]);
|
|
995
|
+
else if (m) return log("OK", "Broken skip link", [pl(ahead(m), "stop comes", "stops come") + " before the main content, so a skip link is not needed."]);
|
|
996
|
+
else return log("INFO", "Broken skip link", ["No main region, so the skip link check has nothing to aim at."]);
|
|
997
|
+
probSkip = logs[logs.length - 1];
|
|
998
|
+
}
|
|
999
|
+
function live(m) { return stops.indexOf(m) >= 0; }
|
|
1000
|
+
function runs(list) {
|
|
1001
|
+
var out = [];
|
|
1002
|
+
byStop(list).forEach(function (e) {
|
|
1003
|
+
var g = out[out.length - 1];
|
|
1004
|
+
if (g && stops.indexOf(g[g.length - 1]) === stops.indexOf(e) - 1 && ghostOf.get(g[0]) === ghostOf.get(e)) g.push(e);
|
|
1005
|
+
else out.push([e]);
|
|
1006
|
+
});
|
|
1007
|
+
return out;
|
|
1008
|
+
}
|
|
1009
|
+
function span(g) {
|
|
1010
|
+
var a = stops.indexOf(g[0]) + 1, b = stops.indexOf(g[g.length - 1]) + 1;
|
|
1011
|
+
return a === b ? String(a) : a + " to " + b;
|
|
1012
|
+
}
|
|
1013
|
+
function ringCheck(s) {
|
|
1014
|
+
var was = noRing.indexOf(s) >= 0, before = restSig.get(s);
|
|
1015
|
+
if (!before) return log("SKIPPED", "No focus style", [ref(s), " has no style from before focus yet, or the mouse was on it. Judged on the next visit."]);
|
|
1016
|
+
if (before !== focusSig(s)) {
|
|
1017
|
+
if (!was) return log("OK", "No focus style", [ref(s), " changes when Tab is on it."]);
|
|
1018
|
+
noRing.splice(noRing.indexOf(s), 1);
|
|
1019
|
+
probRing.get(s).fixed = true;
|
|
1020
|
+
probRing.delete(s);
|
|
1021
|
+
renderJumps();
|
|
1022
|
+
queue();
|
|
1023
|
+
return log("OK", "No focus style", [ref(s), " shows focus now."]);
|
|
1024
|
+
}
|
|
1025
|
+
if (was) return;
|
|
1026
|
+
noRing.push(s);
|
|
1027
|
+
renderJumps();
|
|
1028
|
+
queue();
|
|
1029
|
+
announce("No focus style: stop " + (stops.indexOf(s) + 1) + ", " + label(s) + ", shows no focus.");
|
|
1030
|
+
var rule = outlineRule(s);
|
|
1031
|
+
log("PROBLEM", "No focus style", [ref(s), " shows nothing when Tab is on it."], aiOf(W_VIS, "The element shows a visible change when it has keyboard focus.", "Add :focus-visible { outline: 2px solid; outline-offset: 2px } for it" + (rule ? ", or remove outline: none from " + scrub(rule[0]) : "") + ".", [["Element", s, null, true]], rule ? ["CSS rule: " + scrub(rule[0]), "Style sheet: " + cleanUrl(rule[1])] : []));
|
|
1032
|
+
probRing.set(s, logs[logs.length - 1]);
|
|
1033
|
+
}
|
|
866
1034
|
function check(s, then) {
|
|
867
1035
|
function end() {
|
|
868
1036
|
var f = then;
|
|
@@ -871,7 +1039,7 @@ function check(s, then) {
|
|
|
871
1039
|
}
|
|
872
1040
|
if (!s) return end();
|
|
873
1041
|
var was = covered.indexOf(s) >= 0;
|
|
874
|
-
var at = where(s), still = 0, tries = 0;
|
|
1042
|
+
var at = where(s), still = 0, tries = 0, late = 0;
|
|
875
1043
|
function look() {
|
|
876
1044
|
if (closed || (covered.indexOf(s) >= 0) !== was) return end();
|
|
877
1045
|
var now = where(s);
|
|
@@ -888,9 +1056,25 @@ function check(s, then) {
|
|
|
888
1056
|
still = 0;
|
|
889
1057
|
} else still++;
|
|
890
1058
|
if (still < 2 && ++tries < 90) return requestAnimationFrame(look);
|
|
891
|
-
var
|
|
1059
|
+
var on = deep() === s;
|
|
1060
|
+
if (on && !late && ghostWhy(s)) {
|
|
1061
|
+
late = 1;
|
|
1062
|
+
return setTimeout(function () {
|
|
1063
|
+
if (closed) return end();
|
|
1064
|
+
if (deep() !== s) {
|
|
1065
|
+
log("SKIPPED", "Ghost stop", [ref(s), " lost focus before it could be judged."]);
|
|
1066
|
+
return end();
|
|
1067
|
+
}
|
|
1068
|
+
still = 0;
|
|
1069
|
+
look();
|
|
1070
|
+
}, 400);
|
|
1071
|
+
}
|
|
1072
|
+
nameOne(s);
|
|
1073
|
+
if (on && !ghostCheck(s)) ringCheck(s);
|
|
892
1074
|
tested(s);
|
|
893
1075
|
hidTested.add(s);
|
|
1076
|
+
if (ghosts.indexOf(s) >= 0) return end();
|
|
1077
|
+
var h = hideInfo(s);
|
|
894
1078
|
if (!h.tested) {
|
|
895
1079
|
log("SKIPPED", "Hidden focus", [ref(s), " " + h.why + ". Not tested."]);
|
|
896
1080
|
return end();
|
|
@@ -943,6 +1127,7 @@ function closedBy(p) {
|
|
|
943
1127
|
}
|
|
944
1128
|
function popClosed() {
|
|
945
1129
|
var p = openPop, from = opener, pn = popName(p), by = closedBy(p), pi = popInfo;
|
|
1130
|
+
if (by === " with Escape") exitOk(p);
|
|
946
1131
|
openPop = null;
|
|
947
1132
|
if (!from) return log("SKIPPED", "Lost focus", [pn, " closed" + by + ". It opened on its own, so there is no button to go back to."]);
|
|
948
1133
|
if (!from.isConnected || !shown(from)) return log("SKIPPED", "Lost focus", [pn, " closed" + by + ". The button that opened it is gone or hidden."]);
|
|
@@ -976,9 +1161,82 @@ function track(a) {
|
|
|
976
1161
|
openPop = p;
|
|
977
1162
|
opener = lastOut;
|
|
978
1163
|
popInfo = { sel: sel(p), html: snip(p) };
|
|
1164
|
+
if (isModal(p) && !natives.has(p)) {
|
|
1165
|
+
natives.add(p);
|
|
1166
|
+
log("INFO", "No way out", [popName(p), ": Native dialog: Escape closes it in the browser. Check by hand that the page does not block it."]);
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
var natives = new WeakSet(), noExit = [], okPops = [], CLOSE = /(^|[^a-z\u010d\u0161\u017e])(close|cancel|dismiss|no thanks|not now|skip|x|\u00d7|\u2715|\u2716|zapri|prekli\u010di|ne hvala)(?![a-z\u010d\u0161\u017e])/i;
|
|
1171
|
+
function isModal(p) {
|
|
1172
|
+
try { return p.matches("dialog:modal"); } catch (x) { return false; }
|
|
1173
|
+
}
|
|
1174
|
+
function popKey(p) { return popName(p).l + "|" + sel(p); }
|
|
1175
|
+
function exitOk(p) {
|
|
1176
|
+
var k = popKey(p);
|
|
1177
|
+
noExit = noExit.filter(function (x) {
|
|
1178
|
+
if (x[2] !== k) return true;
|
|
1179
|
+
x[3].fixed = true;
|
|
1180
|
+
return false;
|
|
1181
|
+
});
|
|
1182
|
+
renderJumps();
|
|
1183
|
+
}
|
|
1184
|
+
var nameOf = new WeakMap(), nameless = [], probName = new Map(), sameSaid = {}, ROLE = { A: "link", BUTTON: "button", SELECT: "combobox", TEXTAREA: "textbox", IFRAME: "frame", SUMMARY: "button" };
|
|
1185
|
+
function accName(e) {
|
|
1186
|
+
var t = named(e) || (/^(INPUT|AREA)$/.test(e.tagName) && (e.alt || (/^(submit|reset)$/.test(e.type) && e.type))) || "";
|
|
1187
|
+
if (!t.trim()) [].some.call(e.querySelectorAll("img[alt],[aria-label],svg title"), function (i) { return (t = i.getAttribute("alt") || i.getAttribute("aria-label") || i.textContent || "").trim(); });
|
|
1188
|
+
return scrub(t).replace(/\s+/g, " ").trim();
|
|
1189
|
+
}
|
|
1190
|
+
function roleOf(e) { return e.getAttribute("role") || ROLE[e.tagName] || (e.tagName === "INPUT" ? (/^(checkbox|radio)$/.test(e.type) ? e.type : /^(submit|button|reset|image)$/.test(e.type) ? "button" : "textbox") : e.tagName.toLowerCase()); }
|
|
1191
|
+
function nameOne(s) {
|
|
1192
|
+
var n = accName(s), was = nameless.indexOf(s) >= 0;
|
|
1193
|
+
nameOf.set(s, n);
|
|
1194
|
+
if (n && was) {
|
|
1195
|
+
nameless.splice(nameless.indexOf(s), 1);
|
|
1196
|
+
probName.get(s).fixed = true;
|
|
1197
|
+
probName.delete(s);
|
|
1198
|
+
renderJumps();
|
|
1199
|
+
log("OK", "Nameless stop", [ref(s), " has a name now."]);
|
|
1200
|
+
}
|
|
1201
|
+
if (n || was || s.shadowRoot || /^(AUDIO|VIDEO|OBJECT|EMBED)$/.test(s.tagName)) return n;
|
|
1202
|
+
nameless.push(s);
|
|
1203
|
+
log("PROBLEM", "Nameless stop", [ref(s), " has no name, so a screen reader reads only \"" + roleOf(s) + "\"."], aiOf(W_NAME, "Every Tab stop has a name that says what it does.", "Add visible text, an aria-label, or alt text on its image.", [["Element", s, null, true]]));
|
|
1204
|
+
probName.set(s, logs[logs.length - 1]);
|
|
1205
|
+
return n;
|
|
1206
|
+
}
|
|
1207
|
+
function nameCheck() {
|
|
1208
|
+
var by = {};
|
|
1209
|
+
stops.forEach(function (s) {
|
|
1210
|
+
var n = nameOne(s);
|
|
1211
|
+
if (s.tagName === "A" && n) (by[n] = by[n] || {})[s.getAttribute("href")] = 1;
|
|
1212
|
+
});
|
|
1213
|
+
Object.keys(by).forEach(function (n) {
|
|
1214
|
+
var k = Object.keys(by[n]).length;
|
|
1215
|
+
if (k > 2 && !sameSaid[n]) log("INFO", "Nameless stop", [k + " links share the name " + n + ". That passes 2.4.4 when the text around each one tells them apart."]);
|
|
1216
|
+
sameSaid[n] = sameSaid[n] || k > 2;
|
|
1217
|
+
});
|
|
1218
|
+
renderJumps();
|
|
1219
|
+
}
|
|
1220
|
+
function closer(p, ps) {
|
|
1221
|
+
return ps.filter(function (x) { return CLOSE.test(accName(x)) || /close|dismiss/i.test(x.id + " " + x.getAttribute("class")) || (x.matches("button:not([type]),[type=submit]") && x.closest("form[method=dialog]")); })[0] || null;
|
|
1222
|
+
}
|
|
1223
|
+
function loopCheck(p, from, to, d) {
|
|
1224
|
+
var ps = stops.filter(function (x) { return within(p, x); }), n = ps.length;
|
|
1225
|
+
var k = popKey(p), c = closer(p, ps), had = noExit.some(function (x) { return x[2] === k; });
|
|
1226
|
+
if (n < 2 || isModal(p) || ps[d > 0 ? n - 1 : 0] !== from || ps[d > 0 ? 0 : n - 1] !== to || (had && !c)) return;
|
|
1227
|
+
if (c) {
|
|
1228
|
+
if (had) exitOk(p);
|
|
1229
|
+
if (okPops.indexOf(k) < 0) log("OK", "No way out", [popName(p), ": Tab loops inside it, and ", ref(c), " closes it."]);
|
|
1230
|
+
okPops.push(k);
|
|
1231
|
+
return;
|
|
979
1232
|
}
|
|
1233
|
+
announce("No way out: " + popName(p).l + " has no close control Tab reaches.");
|
|
1234
|
+
log("PROBLEM", "No way out", [popName(p), ": Tab loops through " + n + " stops, and none of them closes it."], aiOf(W_TRAP, "A keyboard user can close the popup with a button Tab reaches.", "Add a Close button inside it, or let Escape close it.", [["Popup", p]]));
|
|
1235
|
+
noExit.push([p, n, k, logs[logs.length - 1]]);
|
|
1236
|
+
renderJumps();
|
|
980
1237
|
}
|
|
981
1238
|
function tap(e) {
|
|
1239
|
+
if (picking) return;
|
|
982
1240
|
tapIn = e.composedPath ? e.composedPath()[0] : e.target;
|
|
983
1241
|
tapT = Date.now();
|
|
984
1242
|
}
|
|
@@ -1008,6 +1266,29 @@ function renderJumps() {
|
|
|
1008
1266
|
count(covered.length, covered.length === 1 ? " stop is hidden when Tab reaches it" : " stops are hidden when Tab reaches them", true, false, jumpBox);
|
|
1009
1267
|
chipUl(jumpBox, byStop(covered), stopName, stopGo);
|
|
1010
1268
|
}
|
|
1269
|
+
var gl = ghosts.filter(live), nl = noRing.filter(live);
|
|
1270
|
+
if (skipBad) {
|
|
1271
|
+
count(1, " skip link goes nowhere", true, false, jumpBox);
|
|
1272
|
+
chipUl(jumpBox, [skipBad.link], function (l) { return stopName(l) + " \u2192 " + skipBad.why; }, stopGo);
|
|
1273
|
+
}
|
|
1274
|
+
if (noExit.length) {
|
|
1275
|
+
count(noExit.length, noExit.length === 1 ? " popup has no keyboard way out" : " popups have no keyboard way out", true, false, jumpBox);
|
|
1276
|
+
chipUl(jumpBox, noExit, function (x) { return popName(x[0]).l + ": Tab loops 1 to " + x[1]; }, function (x) { stopGo(stops.filter(function (y) { return within(x[0], y); })[0] || x[0]); });
|
|
1277
|
+
}
|
|
1278
|
+
var ml = nameless.filter(live);
|
|
1279
|
+
if (ml.length) {
|
|
1280
|
+
count(ml.length, ml.length === 1 ? " stop has no name for screen readers" : " stops have no name for screen readers", true, false, jumpBox);
|
|
1281
|
+
chipUl(jumpBox, byStop(ml), stopName, stopGo);
|
|
1282
|
+
}
|
|
1283
|
+
if (noSkip) count(noSkip, " stops before the main content, and no skip link", true, false, jumpBox);
|
|
1284
|
+
if (gl.length) {
|
|
1285
|
+
count(gl.length, gl.length === 1 ? " stop you can't see when Tab is on it" : " stops you can't see when Tab is on them", true, false, jumpBox);
|
|
1286
|
+
chipUl(jumpBox, runs(gl), function (g) { return span(g) + ": " + label(g[0]) + ", " + GHOST[ghostOf.get(g[0])].replace(/^(is|has) (inside )?/, ""); }, function (g) { stopGo(g[0]); });
|
|
1287
|
+
}
|
|
1288
|
+
if (nl.length) {
|
|
1289
|
+
count(nl.length, nl.length === 1 ? " stop shows no focus when Tab is on it" : " stops show no focus when Tab is on them", true, false, jumpBox);
|
|
1290
|
+
chipUl(jumpBox, byStop(nl), stopName, stopGo);
|
|
1291
|
+
}
|
|
1011
1292
|
if (trapped.length) {
|
|
1012
1293
|
count(trapped.length, trapped.length === 1 ? " stop where Tab gets stuck" : " stops where Tab gets stuck", true, false, jumpBox);
|
|
1013
1294
|
chipUl(jumpBox, byStop(trapped), stopName, stopGo);
|
|
@@ -1109,6 +1390,176 @@ spotBox.appendChild(light);
|
|
|
1109
1390
|
spotBox.appendChild(document.createTextNode("Spotlight"));
|
|
1110
1391
|
settings.insertBefore(spotBox, settings.firstChild);
|
|
1111
1392
|
light.addEventListener("change", function () { queue(); });
|
|
1393
|
+
var mapLabel = document.createElement("label");
|
|
1394
|
+
mapLabel.className = "k s";
|
|
1395
|
+
var mapOn = document.createElement("input");
|
|
1396
|
+
mapOn.type = "checkbox";
|
|
1397
|
+
mapLabel.appendChild(mapOn);
|
|
1398
|
+
mapLabel.appendChild(document.createTextNode("Region map"));
|
|
1399
|
+
settings.insertBefore(mapLabel, spotBox.nextSibling);
|
|
1400
|
+
var costLabel = document.createElement("label");
|
|
1401
|
+
costLabel.className = "k s";
|
|
1402
|
+
var costOn = document.createElement("input");
|
|
1403
|
+
costOn.type = "checkbox";
|
|
1404
|
+
costLabel.appendChild(costOn);
|
|
1405
|
+
costLabel.appendChild(document.createTextNode("Tab cost"));
|
|
1406
|
+
settings.insertBefore(costLabel, mapLabel);
|
|
1407
|
+
costOn.addEventListener("change", function () {
|
|
1408
|
+
if (!costOn.checked) endPick();
|
|
1409
|
+
costDraw();
|
|
1410
|
+
queue();
|
|
1411
|
+
});
|
|
1412
|
+
var picked = null, picking = false, pickAt = null, costGoals = [], PICKS = ["pointermove", "pointerdown", "mousedown", "pointerup", "mouseup", "click", "auxclick", "dblclick", "contextmenu"], GOALW = /(^|[^a-z\u010d\u0161\u017e])(add to cart|buy|checkout|book|reserve|subscribe|sign up|register|download|contact|get started|donate|v ko\u0161arico|kupi|naro\u010di|rezerviraj|prijava|naro\u010di se|prenesi|kontakt)(?![a-z\u010d\u0161\u017e])/i;
|
|
1413
|
+
function mainStop() {
|
|
1414
|
+
var m = mainRegion();
|
|
1415
|
+
return m ? stops.filter(function (x) { return within(m, x); })[0] || null : null;
|
|
1416
|
+
}
|
|
1417
|
+
function goals() {
|
|
1418
|
+
var out = [], m = mainRegion(), found = 0;
|
|
1419
|
+
function add(e, name, how) {
|
|
1420
|
+
if (e && !out.some(function (g) { return g.el === e || (name && g.name.toLowerCase() === name.toLowerCase()); })) out.push({ name: name, presses: stops.indexOf(e) + 1, how: how, el: e });
|
|
1421
|
+
}
|
|
1422
|
+
[].forEach.call(document.querySelectorAll("[data-tab-trail-goal]"), function (x) {
|
|
1423
|
+
found = 1;
|
|
1424
|
+
add(stops.indexOf(x) >= 0 ? x : stops.filter(function (y) { return within(x, y); })[0], x.getAttribute("data-tab-trail-goal"), "set in the page");
|
|
1425
|
+
});
|
|
1426
|
+
add(mainStop(), "the main content", "always");
|
|
1427
|
+
stops.forEach(function (e) {
|
|
1428
|
+
if (!GOALW.test(accName(e))) return;
|
|
1429
|
+
found = 1;
|
|
1430
|
+
add(e, label(e), "found by its words");
|
|
1431
|
+
});
|
|
1432
|
+
stops.forEach(function (e) {
|
|
1433
|
+
if (!e.form || !e.form.querySelector("input[type=email]") || !e.matches("button:not([type]),[type=submit]")) return;
|
|
1434
|
+
found = 1;
|
|
1435
|
+
add(e, label(e), "form with an e-mail field");
|
|
1436
|
+
});
|
|
1437
|
+
if (!found && m) add(stops.filter(function (x) { return x.tagName === "BUTTON" && within(m, x); }).sort(function (a, b) { var p = a.getBoundingClientRect(), q = b.getBoundingClientRect(); return q.width * q.height - p.width * p.height; })[0], "", "guessed");
|
|
1438
|
+
out.forEach(function (g) { if (!g.name) g.name = label(g.el); });
|
|
1439
|
+
var mg = out.filter(function (g) { return g.how === "always"; })[0], rest = out.filter(function (g) { return g !== mg; });
|
|
1440
|
+
out = out.filter(function (g) { return g === mg || rest.indexOf(g) < (mg ? 2 : 3); });
|
|
1441
|
+
if (picked && stops.indexOf(picked) >= 0) {
|
|
1442
|
+
out = out.filter(function (g) { return g.el !== picked; });
|
|
1443
|
+
out.unshift({ name: label(picked), presses: stops.indexOf(picked) + 1, how: "picked by you", el: picked });
|
|
1444
|
+
}
|
|
1445
|
+
return out;
|
|
1446
|
+
}
|
|
1447
|
+
function para(parent, cls, text) {
|
|
1448
|
+
var p = document.createElement("p");
|
|
1449
|
+
p.className = cls;
|
|
1450
|
+
p.textContent = text || "";
|
|
1451
|
+
parent.appendChild(p);
|
|
1452
|
+
return p;
|
|
1453
|
+
}
|
|
1454
|
+
function costDraw() {
|
|
1455
|
+
if (!costOn) return;
|
|
1456
|
+
while (costBox.firstChild) costBox.removeChild(costBox.firstChild);
|
|
1457
|
+
costGoals = costOn.checked ? goals() : [];
|
|
1458
|
+
if (!costOn.checked) return;
|
|
1459
|
+
para(costBox, "", "").appendChild(document.createElement("b")).textContent = "Tab presses to reach";
|
|
1460
|
+
costGoals.forEach(function (g) {
|
|
1461
|
+
var p = para(costBox, "n", "");
|
|
1462
|
+
p.appendChild(document.createElement("b")).textContent = String(g.presses);
|
|
1463
|
+
p.appendChild(document.createTextNode(" " + g.name + " "));
|
|
1464
|
+
p.appendChild(document.createElement("span")).textContent = "\u00b7 " + g.how;
|
|
1465
|
+
p.lastChild.className = "cg";
|
|
1466
|
+
if (g.el === picked) lbtn("lq", " Remove", p).addEventListener("click", function () {
|
|
1467
|
+
picked = null;
|
|
1468
|
+
costDraw();
|
|
1469
|
+
queue();
|
|
1470
|
+
costBox.querySelector("p:last-child button").focus();
|
|
1471
|
+
});
|
|
1472
|
+
});
|
|
1473
|
+
var ms = mainStop();
|
|
1474
|
+
if (ms && !skipLink() && stops.indexOf(ms) >= 10) para(costBox, "cg", "A skip link would make the main content 1.");
|
|
1475
|
+
var pl2 = para(costBox, picking ? "pk" : "", picking ? "Click the goal on the page. Escape cancels. " : "");
|
|
1476
|
+
lbtn("lq", picking ? "Cancel" : "Pick a goal", pl2).addEventListener("click", function () {
|
|
1477
|
+
if (picking) endPick();
|
|
1478
|
+
else {
|
|
1479
|
+
picking = true;
|
|
1480
|
+
PICKS.forEach(function (t) { addEventListener(t, pickEv, true); });
|
|
1481
|
+
}
|
|
1482
|
+
costDraw();
|
|
1483
|
+
costBox.querySelector("p:last-child button").focus();
|
|
1484
|
+
});
|
|
1485
|
+
skipPanel();
|
|
1486
|
+
}
|
|
1487
|
+
function endPick() {
|
|
1488
|
+
picking = false;
|
|
1489
|
+
pickAt = null;
|
|
1490
|
+
PICKS.forEach(function (t) { removeEventListener(t, pickEv, true); });
|
|
1491
|
+
costDraw();
|
|
1492
|
+
queue();
|
|
1493
|
+
}
|
|
1494
|
+
function pickEv(e) {
|
|
1495
|
+
var t = e.composedPath ? e.composedPath()[0] : e.target, s = null;
|
|
1496
|
+
if (!picking || within(host, t)) return;
|
|
1497
|
+
e.preventDefault();
|
|
1498
|
+
e.stopPropagation();
|
|
1499
|
+
for (var n = t; n && !s; n = upOf(n)) if (stops.indexOf(n) >= 0) s = n;
|
|
1500
|
+
if (e.type === "pointermove") {
|
|
1501
|
+
if (s !== pickAt) {
|
|
1502
|
+
pickAt = s;
|
|
1503
|
+
queue();
|
|
1504
|
+
}
|
|
1505
|
+
} else if (e.type === "click" && s) {
|
|
1506
|
+
picked = s;
|
|
1507
|
+
endPick();
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
mapOn.addEventListener("change", function () {
|
|
1511
|
+
tint = null;
|
|
1512
|
+
mapDraw();
|
|
1513
|
+
queue();
|
|
1514
|
+
});
|
|
1515
|
+
var REG = ["header", "nav", "main", "aside", "footer", "other"], REGC = ["#c2410c", "#9a3412", "#1f7a3f", "#5f564c", "#1e3a8a", "#7d756b"], LAND = { HEADER: "header", BANNER: "header", NAV: "nav", NAVIGATION: "nav", MAIN: "main", ASIDE: "aside", COMPLEMENTARY: "aside", FOOTER: "footer", CONTENTINFO: "footer" }, tint = null;
|
|
1516
|
+
function regionOf(e) {
|
|
1517
|
+
for (var n = upOf(e); n && n.nodeType === 1; n = upOf(n)) {
|
|
1518
|
+
var ro = n.getAttribute("role"), r = ro ? LAND[ro.split(" ")[0].toUpperCase()] : LAND[n.tagName];
|
|
1519
|
+
if (r && !ro && /^(HEADER|FOOTER)$/.test(n.tagName) && n.parentElement && n.parentElement.closest("article,aside,main,nav,section,[role=article],[role=complementary],[role=main],[role=navigation],[role=region]")) r = null;
|
|
1520
|
+
if (r) return [r, n];
|
|
1521
|
+
}
|
|
1522
|
+
return ["other", e];
|
|
1523
|
+
}
|
|
1524
|
+
function regions() {
|
|
1525
|
+
var out = { header: 0, nav: 0, main: 0, aside: 0, footer: 0, other: 0 }, els = {};
|
|
1526
|
+
stops.forEach(function (x) {
|
|
1527
|
+
var r = regionOf(x);
|
|
1528
|
+
out[r[0]]++;
|
|
1529
|
+
(els[r[0]] = els[r[0]] || []).indexOf(r[1]) < 0 && els[r[0]].push(r[1]);
|
|
1530
|
+
});
|
|
1531
|
+
return [out, els];
|
|
1532
|
+
}
|
|
1533
|
+
function mapDraw() {
|
|
1534
|
+
if (!mapOn) return;
|
|
1535
|
+
while (mapBox.firstChild) mapBox.removeChild(mapBox.firstChild);
|
|
1536
|
+
if (!mapOn.checked) return;
|
|
1537
|
+
var r = regions(), bar = document.createElement("div"), bl = document.createElement("div");
|
|
1538
|
+
count(stops.length, " stops, by region", false, false, mapBox);
|
|
1539
|
+
bar.className = "bar";
|
|
1540
|
+
bl.className = "bl";
|
|
1541
|
+
REG.forEach(function (k, i) {
|
|
1542
|
+
var n = r[0][k], name = k.charAt(0).toUpperCase() + k.slice(1);
|
|
1543
|
+
if (!n) return;
|
|
1544
|
+
var b = document.createElement("button"), sp = document.createElement("span"), em = document.createElement("em");
|
|
1545
|
+
b.type = "button";
|
|
1546
|
+
b.style.cssText = "flex:" + n + ";background:" + REGC[i];
|
|
1547
|
+
b.setAttribute("aria-label", name + " " + n);
|
|
1548
|
+
b.addEventListener("click", function () {
|
|
1549
|
+
tint = [r[1][k], REGC[i]];
|
|
1550
|
+
r[1][k][0].scrollIntoView({ block: "center", behavior: "smooth" });
|
|
1551
|
+
queue();
|
|
1552
|
+
});
|
|
1553
|
+
bar.appendChild(b);
|
|
1554
|
+
em.style.background = REGC[i];
|
|
1555
|
+
sp.appendChild(em);
|
|
1556
|
+
sp.appendChild(document.createTextNode(name + " " + n));
|
|
1557
|
+
bl.appendChild(sp);
|
|
1558
|
+
});
|
|
1559
|
+
mapBox.appendChild(bar);
|
|
1560
|
+
mapBox.appendChild(bl);
|
|
1561
|
+
skipPanel();
|
|
1562
|
+
}
|
|
1112
1563
|
chunk.addEventListener("change", function () { queue(); });
|
|
1113
1564
|
function paged() { return chunk.checked && stops.length > PAGE; }
|
|
1114
1565
|
function outT() { return skip.checked && !panelIn ? -1 : 0; }
|
|
@@ -1241,8 +1692,8 @@ function browser() {
|
|
|
1241
1692
|
if ((m = u.match(/Version\/(\d+)[^ ]* (Mobile\/\S+ )?Safari/))) return "Safari " + m[1];
|
|
1242
1693
|
return u;
|
|
1243
1694
|
}
|
|
1244
|
-
var CHECKS = ["Missed spots", "Hover menus", "Forced order", "Out of order", "Keyboard trap", "Hidden focus", "Lost focus"];
|
|
1245
|
-
var WCAG = { "Missed spots": "2.1.1 A", "Hover menus": "2.1.1 A", "Out of order": "2.4.3 A", "Forced order": "2.4.3 A", "Keyboard trap": "2.1.2 A", "Lost focus": "2.4.3 A", "Hidden focus": "2.4.11 AA" };
|
|
1695
|
+
var CHECKS = ["Missed spots", "Hover menus", "Forced order", "Out of order", "Keyboard trap", "Hidden focus", "Lost focus", "No focus style", "Ghost stop", "Broken skip link", "No way out", "Nameless stop"];
|
|
1696
|
+
var WCAG = { "Missed spots": "2.1.1 A", "Hover menus": "2.1.1 A", "Out of order": "2.4.3 A", "Forced order": "2.4.3 A", "Keyboard trap": "2.1.2 A", "Lost focus": "2.4.3 A", "Hidden focus": "2.4.11 AA", "No focus style": "2.4.7 AA", "Ghost stop": "2.4.7 AA", "Broken skip link": "2.4.1 A", "No way out": "2.1.2 A", "Nameless stop": "4.1.2 A" };
|
|
1246
1697
|
function showUrl(f) { return "https://matjazkorosec.com/tools/tab-trail#show-" + f.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, ""); }
|
|
1247
1698
|
function ranChecks() {
|
|
1248
1699
|
var out = [];
|
|
@@ -1311,6 +1762,8 @@ function review() {
|
|
|
1311
1762
|
if (lastStops < 0) log("INFO", "Scan", ["Found " + pl(stops.length, "stop", "stops") + ". Read " + pl(cssRules, "CSS rule", "CSS rules") + " from " + pl(cssSheets, "style sheet", "style sheets") + "."]);
|
|
1312
1763
|
else if (stops.length !== lastStops) log("INFO", "Scan", ["Page changed: " + pl(stops.length, "stop", "stops") + " now, " + lastStops + " before."]);
|
|
1313
1764
|
lastStops = stops.length;
|
|
1765
|
+
skipCheck();
|
|
1766
|
+
nameCheck();
|
|
1314
1767
|
cssBlocked.forEach(function (h) {
|
|
1315
1768
|
if (seenCss.has(h)) return;
|
|
1316
1769
|
seenCss.add(h);
|
|
@@ -1452,7 +1905,7 @@ function logText() {
|
|
|
1452
1905
|
});
|
|
1453
1906
|
return out.join("\n");
|
|
1454
1907
|
}
|
|
1455
|
-
var W_FORCE = "2.4.3 Focus Order (Level A). tabindex above 0 pulls it ahead of the page. It fails WCAG 2.4.3 when that order makes no sense (F44).", W_TRAP = "2.1.2 No Keyboard Trap (Level A)", W_KEY = "2.1.1 Keyboard (Level A)", W_VIS = "2.4.7 Focus Visible (Level AA)", W_ORDER = "2.4.3 Focus Order (Level A)", W_HIDE = "2.4.11 Focus Not Obscured (Minimum) (Level AA)";
|
|
1908
|
+
var W_FORCE = "2.4.3 Focus Order (Level A). tabindex above 0 pulls it ahead of the page. It fails WCAG 2.4.3 when that order makes no sense (F44).", W_TRAP = "2.1.2 No Keyboard Trap (Level A)", W_KEY = "2.1.1 Keyboard (Level A)", W_VIS = "2.4.7 Focus Visible (Level AA)", W_ORDER = "2.4.3 Focus Order (Level A)", W_HIDE = "2.4.11 Focus Not Obscured (Minimum) (Level AA)", W_NAME = "4.1.2 Name, Role, Value (Level A)", W_BYPASS = "2.4.1 Bypass Blocks (Level A)";
|
|
1456
1909
|
function cssId(t) { return /^[A-Za-z][\w-]*$/.test(t); }
|
|
1457
1910
|
function sel(e) {
|
|
1458
1911
|
if (!e || e.nodeType !== 1) return "";
|
|
@@ -1600,6 +2053,11 @@ function verifyOf(e) {
|
|
|
1600
2053
|
if (e.f === "Forced order") return "Reload the page and run Tab trail again: " + el("Element") + " has no tabindex above 0, its stop number matches its place on the page, and the Forced order count goes down by 1.";
|
|
1601
2054
|
if (e.f === "Hover menus") return "Press Tab until a link inside " + el("Element") + " has focus: the menu opens while focus is inside it, and Tab trail no longer lists it under hover menus.";
|
|
1602
2055
|
if (e.f === "Hidden focus") return "Press Tab until " + el("Element") + " has focus: part of it shows next to " + el("Covered by") + ", and its Hidden focus line in the log says in view or partly covered.";
|
|
2056
|
+
if (e.f === "Nameless stop") return "Hover the dot of " + el("Element") + " in Tab trail: it shows a name, not \"no name\".";
|
|
2057
|
+
if (e.f === "No way out") return "Open " + el("Popup") + " and press Tab until a Close button has focus, then Enter closes the popup.";
|
|
2058
|
+
if (e.f === "Broken skip link") return el("Element") ? "Reload the page, press Tab once and then Enter on " + el("Element") + ": the next Tab lands inside the main content." : "Reload the page and press Tab once: the first stop is a skip link, and Enter on it moves focus to the main content.";
|
|
2059
|
+
if (e.f === "Ghost stop") return a.crit === W_NAME ? "Reload the page and run Tab trail again: " + el("Element") + " is no longer inside aria-hidden, or Tab skips it, and the Ghost stop count goes down by 1." : "Press Tab until " + el("Element") + " has focus: it shows on screen, and its Ghost stop line in the log says OK.";
|
|
2060
|
+
if (e.f === "No focus style") return "Press Tab until " + el("Element") + " has focus: an outline or another visible change shows on it, and its No focus style line in the log says OK.";
|
|
1603
2061
|
if (e.f === "Keyboard trap") return "Put focus on " + el("Element") + " and press Tab: focus moves on to " + el("Expected next") + ", and the log shows an OK Out of order line.";
|
|
1604
2062
|
if (e.f === "Lost focus") return "Open the popup from " + el("Opened by") + " with Enter, then close it with Escape or its close button: focus is back on " + el("Opened by") + ", and the log shows an OK Lost focus line.";
|
|
1605
2063
|
if (el("Popup")) return "Reload so the popup shows, then press Tab once: focus lands inside " + el("Popup") + ".";
|
|
@@ -1614,7 +2072,7 @@ function coverage() {
|
|
|
1614
2072
|
var pops = logs.filter(function (e) { return e.f === "Lost focus"; }).length;
|
|
1615
2073
|
out.push("Lost focus: " + (pops ? "only " + pl(pops, "popup was", "popups were") : "no popups were") + " opened and closed in this run. Open and close every popup, menu and dialog on the page to check them all.");
|
|
1616
2074
|
out.push("Window size: everything was tested at " + innerWidth + " x " + innerHeight + " only. Sticky bars, menus and popups can behave differently on phones; run it again in a window about 390 px wide.");
|
|
1617
|
-
out.push("Not checked by Tab trail at all:
|
|
2075
|
+
out.push("Not checked by Tab trail at all: how strong the focus change is (contrast, size: AAA), accessible names of things Tab doesn't reach, color contrast of text, what a screen reader announces, and content inside iframes. Use axe DevTools or Lighthouse for names, contrast and iframes. Check focus visibility with Spotlight and screen reader output with VoiceOver or NVDA.");
|
|
1618
2076
|
return out;
|
|
1619
2077
|
}
|
|
1620
2078
|
var probLog = [], ignore = [], CAP = 200, judgedDir = {};
|
|
@@ -2144,7 +2602,8 @@ function dotsIn(list, layer) {
|
|
|
2144
2602
|
list.sort(function (a, b) { return (a[2] - 1 === current) - (b[2] - 1 === current); });
|
|
2145
2603
|
list.forEach(function (d) {
|
|
2146
2604
|
var big = d[2] > 99, on = d[2] - 1 === current;
|
|
2147
|
-
var g = el("g", { class: "o", "data-i": d[2] - 1 }, layer);
|
|
2605
|
+
var g = el("g", { class: "o", "data-i": d[2] - 1 }, layer), ds = stops[d[2] - 1];
|
|
2606
|
+
if (ds) el("title", {}, g).textContent = d[2] + " \u00b7 " + roleOf(ds) + " \u00b7 " + (nameOf.get(ds) || "no name");
|
|
2148
2607
|
if (on) el("circle", { cx: d[0], cy: d[1], r: big ? 19 : 17, fill: "none", stroke: "#ff8f57", "stroke-width": 4 }, g);
|
|
2149
2608
|
if (d[3] && !on) el("circle", { cx: d[0], cy: d[1], r: big ? 14 : 12, fill: "#fff", stroke: "#1a1612", "stroke-width": 2, "stroke-dasharray": "4 3" }, g);
|
|
2150
2609
|
else el("circle", { cx: d[0], cy: d[1], r: big ? 14 : 12, fill: on ? "#c2410c" : "#1a1612", stroke: "#fff", "stroke-width": 2 }, g);
|
|
@@ -2185,9 +2644,11 @@ function draw() {
|
|
|
2185
2644
|
if (win > last) win = last;
|
|
2186
2645
|
var lo = paged() ? win * PAGE : 0, hi = paged() ? Math.min(lo + PAGE, stops.length) : stops.length;
|
|
2187
2646
|
var red = [], at = [];
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2647
|
+
var edges = {};
|
|
2648
|
+
missed.concat(hovers, noRing.filter(live), ghosts.filter(live)).forEach(function (m) {
|
|
2649
|
+
var p = isPinned(m), r = m.getBoundingClientRect(), ed = ghostOf.get(m) === "off" ? (r.right <= 0 ? "l" : r.left >= innerWidth ? "r" : r.bottom <= 0 ? "t" : r.top >= innerHeight ? "b" : "") : "";
|
|
2650
|
+
if (ed) (edges[ed] = edges[ed] || []).push(m);
|
|
2651
|
+
else if (p || page) red.push([m, r, p]);
|
|
2191
2652
|
});
|
|
2192
2653
|
for (var i = lo; i < hi; i++) {
|
|
2193
2654
|
var sr = stops[i].getBoundingClientRect(), st = sr.width < 2 && sr.height < 2;
|
|
@@ -2195,7 +2656,7 @@ function draw() {
|
|
|
2195
2656
|
}
|
|
2196
2657
|
var fr = shownEl && hovers.indexOf(shownEl) < 0 && forced.indexOf(shownEl) >= 0 ? [shownEl.getBoundingClientRect(), isPinned(shownEl)] : null;
|
|
2197
2658
|
var lr = light.checked && spotEl && spotEl.isConnected ? spotEl.getBoundingClientRect() : null;
|
|
2198
|
-
var key = [shownEl];
|
|
2659
|
+
var key = [shownEl, skipBad && skipBad.why];
|
|
2199
2660
|
red.forEach(function (x) { if (!x[2]) key.push(x[0], x[1].left + sx, x[1].top + sy, x[1].width, x[1].height); });
|
|
2200
2661
|
if (fr && !fr[1]) key.push(fr[0].left + sx, fr[0].top + sy, fr[0].width, fr[0].height);
|
|
2201
2662
|
var keep = page && same(key, boxKey);
|
|
@@ -2214,6 +2675,39 @@ function draw() {
|
|
|
2214
2675
|
if (x[2]) box(m, r, under);
|
|
2215
2676
|
else if (!keep) box(m, { left: r.left + sx, top: r.top + sy, width: r.width, height: r.height }, underPg);
|
|
2216
2677
|
});
|
|
2678
|
+
Object.keys(edges).forEach(function (ed) {
|
|
2679
|
+
var vw = Math.min(innerWidth, document.documentElement.clientWidth || innerWidth), vh = Math.min(innerHeight, document.documentElement.clientHeight || innerHeight), v = ed === "l" || ed === "r", max = v ? vh : vw, lo = max, hi = 0;
|
|
2680
|
+
edges[ed].forEach(function (m) {
|
|
2681
|
+
var r = m.getBoundingClientRect();
|
|
2682
|
+
lo = Math.min(lo, v ? r.top : r.left);
|
|
2683
|
+
hi = Math.max(hi, v ? r.bottom : r.right);
|
|
2684
|
+
});
|
|
2685
|
+
lo = Math.max(4, Math.min(lo, max - 144));
|
|
2686
|
+
hi = Math.min(max - 4, Math.max(hi, lo + 140));
|
|
2687
|
+
var x = v ? (ed === "r" ? vw - 36 : 4) : lo, y = v ? lo : ed === "b" ? vh - 36 : 4, w = v ? 32 : hi - lo, h = v ? hi - lo : 32;
|
|
2688
|
+
el("rect", { x: x, y: y, width: w, height: h, rx: 6, fill: "rgba(208,16,58,.12)", stroke: "#d0103a", "stroke-width": 3, "stroke-dasharray": "7 5" }, under);
|
|
2689
|
+
el("path", { d: { r: "M-5 -9l10 9-10 9", l: "M5 -9l-10 9 10 9", t: "M-9 5l9-10 9 10", b: "M-9 -5l9 10 9-10" }[ed], transform: "translate(" + (x + (v ? 16 : 22)) + " " + (y + (v ? 22 : 16)) + ")", fill: "none", stroke: "#d0103a", "stroke-width": 3, "stroke-linecap": "round", "stroke-linejoin": "round" }, under);
|
|
2690
|
+
var t = el("text", { x: 0, y: 0, transform: "translate(" + (x + w / 2) + " " + (y + h / 2) + ")" + (v ? " rotate(-90)" : ""), fill: "#d0103a", stroke: "#fff", "stroke-width": 3, "paint-order": "stroke", "font-size": 11, "font-weight": 700, "font-family": "system-ui,sans-serif", "text-anchor": "middle", "dominant-baseline": "middle" }, under);
|
|
2691
|
+
t.textContent = runs(edges[ed]).map(span).join(", ");
|
|
2692
|
+
});
|
|
2693
|
+
costGoals.concat(pickAt ? [{ el: pickAt, pick: 1 }] : []).forEach(function (g) {
|
|
2694
|
+
if (!g.el.isConnected) return;
|
|
2695
|
+
var q = g.el.getBoundingClientRect(), t = g.pick ? "Click to make " + label(g.el) + " a goal" : g.name + ": " + g.presses;
|
|
2696
|
+
el("rect", { x: q.left - 4, y: q.top - 4, width: q.width + 8, height: q.height + 8, fill: "none", stroke: "#c2410c", "stroke-width": 3, "stroke-dasharray": g.pick ? "7 5" : "", rx: 6 }, under);
|
|
2697
|
+
el("rect", { x: q.right + 10, y: q.top + q.height / 2 - 11, width: t.length * 6.6 + 16, height: 22, fill: "#c2410c", rx: 11 }, under);
|
|
2698
|
+
el("text", { x: q.right + 18, y: q.top + q.height / 2 + 4, fill: "#fff", "font-size": 12, "font-weight": 700, "font-family": "system-ui,sans-serif" }, under).textContent = t;
|
|
2699
|
+
});
|
|
2700
|
+
if (tint && mapOn.checked) tint[0].filter(function (m) { return m.isConnected; }).forEach(function (m) {
|
|
2701
|
+
var q = m.getBoundingClientRect();
|
|
2702
|
+
el("rect", { x: q.left, y: q.top, width: q.width, height: q.height, fill: tint[1], "fill-opacity": 0.12, stroke: tint[1], "stroke-width": 2, rx: 4 }, under);
|
|
2703
|
+
});
|
|
2704
|
+
if (skipBad && skipBad.link.isConnected && page && !keep) {
|
|
2705
|
+
var ka = skipBad.link.getBoundingClientRect(), kt = skipBad.to && shown(skipBad.to) ? skipBad.to : mainRegion(), kb = kt ? kt.getBoundingClientRect() : null;
|
|
2706
|
+
var ax = Math.max(ka.left + sx, 13) + 14, ay = Math.max(ka.bottom + sy, 26) + 4, bx = kb ? kb.left + sx + 16 : ax + 160, by = kb ? Math.max(kb.top + sy + 16, ay + 40) : ay + 80;
|
|
2707
|
+
el("path", { d: "M" + ax + " " + ay + "L" + bx + " " + by, fill: "none", stroke: "#d0103a", "stroke-width": 3, "stroke-dasharray": "7 5", "stroke-linecap": "round" }, underPg);
|
|
2708
|
+
el("circle", { cx: bx, cy: by, r: 11, fill: "#fff", stroke: "#d0103a", "stroke-width": 3 }, underPg);
|
|
2709
|
+
el("path", { d: "M" + (bx - 5) + " " + (by - 5) + "l10 10m0 -10l-10 10", stroke: "#d0103a", "stroke-width": 3, "stroke-linecap": "round" }, underPg);
|
|
2710
|
+
}
|
|
2217
2711
|
if (fr) {
|
|
2218
2712
|
var hr = fr[0], hp = fr[1];
|
|
2219
2713
|
if (hp || (page && !keep)) {
|
|
@@ -2294,6 +2788,10 @@ function rescan() {
|
|
|
2294
2788
|
place();
|
|
2295
2789
|
pinned = new WeakMap();
|
|
2296
2790
|
scan();
|
|
2791
|
+
var fa = deep();
|
|
2792
|
+
noOutline = null;
|
|
2793
|
+
stops.forEach(function (x) { if (x !== fa && !restSig.has(x)) rest(x); });
|
|
2794
|
+
skipCheck();
|
|
2297
2795
|
if (!same(drawn, sig())) {
|
|
2298
2796
|
fill();
|
|
2299
2797
|
scan();
|
|
@@ -2404,6 +2902,7 @@ function step(s) {
|
|
|
2404
2902
|
return;
|
|
2405
2903
|
}
|
|
2406
2904
|
endPress();
|
|
2905
|
+
if (s !== deep()) rest(s);
|
|
2407
2906
|
s.focus({ focusVisible: true });
|
|
2408
2907
|
focus();
|
|
2409
2908
|
walked.add(s);
|
|
@@ -2430,10 +2929,10 @@ function step(s) {
|
|
|
2430
2929
|
var walkDone = [];
|
|
2431
2930
|
function untested() {
|
|
2432
2931
|
var judged = {};
|
|
2433
|
-
logs.forEach(function (e) { if ((e.k === "OK" || e.k === "PROBLEM") && e.f === "Lost focus") judged[e.f] = 1; });
|
|
2932
|
+
logs.forEach(function (e) { if ((e.k === "OK" || e.k === "PROBLEM") && (e.f === "Lost focus" || e.f === "Broken skip link" || e.f === "No way out")) judged[e.f] = 1; });
|
|
2434
2933
|
if (judgedDir[1] && judgedDir[-1]) judged["Out of order"] = judged["Keyboard trap"] = 1;
|
|
2435
2934
|
openProbs().forEach(function (e) { judged[e.f] = 1; });
|
|
2436
|
-
return ["Out of order", "Keyboard trap", "Lost focus"].filter(function (f) { return !judged[f]; });
|
|
2935
|
+
return ["Out of order", "Keyboard trap", "Lost focus", "No way out", "Broken skip link"].filter(function (f) { return !judged[f]; });
|
|
2437
2936
|
}
|
|
2438
2937
|
function sumDraw() {
|
|
2439
2938
|
sumLine.hidden = walking || walkEnd !== "done";
|
|
@@ -2441,7 +2940,7 @@ function sumDraw() {
|
|
|
2441
2940
|
var per = {}, probs = openProbs(), left = untested();
|
|
2442
2941
|
probs.forEach(function (e) { per[e.f] = (per[e.f] || 0) + 1; });
|
|
2443
2942
|
var red = CHECKS.filter(function (f) { return per[f]; }), ok = CHECKS.filter(function (f) { return !per[f] && left.indexOf(f) < 0; });
|
|
2444
|
-
var tabLeft = left.indexOf("Out of order") >= 0 || left.indexOf("Keyboard trap") >= 0, popLeft = left.indexOf("Lost focus") >= 0;
|
|
2943
|
+
var tabLeft = left.indexOf("Out of order") >= 0 || left.indexOf("Keyboard trap") >= 0, popLeft = left.indexOf("Lost focus") >= 0 || left.indexOf("No way out") >= 0;
|
|
2445
2944
|
while (sumLine.firstChild) sumLine.removeChild(sumLine.firstChild);
|
|
2446
2945
|
var b = document.createElement("b");
|
|
2447
2946
|
b.textContent = pl(CHECKS.length, "check", "checks") + ": " + ok.length + " passed, " + red.length + (red.length === 1 ? " found a problem, " : " found problems, ") + left.length + " not tested.";
|
|
@@ -2457,7 +2956,7 @@ function sumDraw() {
|
|
|
2457
2956
|
}
|
|
2458
2957
|
part("Passed", ok, "g");
|
|
2459
2958
|
part(red.length === 1 ? "Problem" : "Problems", red, "e", true);
|
|
2460
|
-
part("Not tested (" +
|
|
2959
|
+
part("Not tested (" + [tabLeft ? "press Tab and Shift+Tab" : "", popLeft ? "open and close a popup" : "", left.indexOf("Broken skip link") >= 0 ? "the page has no main region" : ""].filter(Boolean).join(", ") + ")", left, "q");
|
|
2461
2960
|
}
|
|
2462
2961
|
function startWalk() {
|
|
2463
2962
|
walking = true;
|
|
@@ -2477,6 +2976,7 @@ play.addEventListener("click", function () {
|
|
|
2477
2976
|
startWalk();
|
|
2478
2977
|
});
|
|
2479
2978
|
function interrupt(e) {
|
|
2979
|
+
if (picking) return;
|
|
2480
2980
|
if (!walking || (e.composedPath && e.composedPath().indexOf(host) >= 0)) return;
|
|
2481
2981
|
stopWalk("Paused by a click on the page" + walkedText());
|
|
2482
2982
|
}
|
|
@@ -2559,6 +3059,7 @@ function settle() {
|
|
|
2559
3059
|
var want = before >= 0 ? (before + pressed + n) % n : src ? after(src, pressed) : pressed > 0 ? 0 : n - 1;
|
|
2560
3060
|
if (before >= 0 && wantEl && stops.indexOf(wantEl) >= 0) want = stops.indexOf(wantEl);
|
|
2561
3061
|
var landed = popupOf(stops[current]), left = before >= 0 ? popupOf(stops[before]) : src ? popupOf(src) : null;
|
|
3062
|
+
if (landed && landed === left && before >= 0) loopCheck(landed, stops[before], stops[current], pressed);
|
|
2562
3063
|
if (first && pressed > 0 && !landed && !popMissed) {
|
|
2563
3064
|
for (var k = 0; k < n && !popMissed; k++) {
|
|
2564
3065
|
var pop = popupOf(stops[k]);
|
|
@@ -2648,6 +3149,11 @@ function back() {
|
|
|
2648
3149
|
}
|
|
2649
3150
|
}
|
|
2650
3151
|
function key(e) {
|
|
3152
|
+
if (picking && e.key === "Escape" && e.isTrusted) {
|
|
3153
|
+
e.preventDefault();
|
|
3154
|
+
e.stopPropagation();
|
|
3155
|
+
return endPick();
|
|
3156
|
+
}
|
|
2651
3157
|
if (e.code === "KeyF" && e.ctrlKey && e.shiftKey && !e.altKey && !e.metaKey) {
|
|
2652
3158
|
e.preventDefault();
|
|
2653
3159
|
e.stopPropagation();
|
|
@@ -2677,6 +3183,10 @@ function key(e) {
|
|
|
2677
3183
|
}
|
|
2678
3184
|
}
|
|
2679
3185
|
var fa = deep(), onBody = !fa || fa === document.body || fa === document.documentElement;
|
|
3186
|
+
if (e.key === "Escape" && e.isTrusted && openPop && !gone(openPop)) {
|
|
3187
|
+
var ep = openPop;
|
|
3188
|
+
setTimeout(function () { if (!closed && openPop === ep && !gone(ep)) log("INFO", "No way out", [popName(ep), ": Escape did not close it. WCAG 2.2 AA does not require Escape when Tab reaches a close button; it is a best practice (ARIA APG)."]); }, 300);
|
|
3189
|
+
}
|
|
2680
3190
|
if (e.key === "Escape" && !modal() && !(openPop && !gone(openPop)) && (onBody || inPanel())) close();
|
|
2681
3191
|
if (e.key === "Tab") {
|
|
2682
3192
|
endPress();
|
|
@@ -2689,6 +3199,7 @@ function key(e) {
|
|
|
2689
3199
|
var c = stops[(((before + pressed * k) % n) + n) % n];
|
|
2690
3200
|
if (tabbable(c)) {
|
|
2691
3201
|
wantEl = c;
|
|
3202
|
+
if (c !== fa) rest(c);
|
|
2692
3203
|
break;
|
|
2693
3204
|
}
|
|
2694
3205
|
}
|
|
@@ -2704,11 +3215,14 @@ function pick(e) {
|
|
|
2704
3215
|
var s = stops[+g.getAttribute("data-i")];
|
|
2705
3216
|
if (!s) return;
|
|
2706
3217
|
endPress();
|
|
3218
|
+
if (s !== deep()) rest(s);
|
|
2707
3219
|
s.focus({ preventScroll: true, focusVisible: true });
|
|
2708
3220
|
focus();
|
|
2709
3221
|
}
|
|
2710
3222
|
function close() {
|
|
2711
3223
|
closed = true;
|
|
3224
|
+
picking = false;
|
|
3225
|
+
PICKS.forEach(function (t) { removeEventListener(t, pickEv, true); });
|
|
2712
3226
|
stopWalk();
|
|
2713
3227
|
removeEventListener("pointerdown", interrupt, true);
|
|
2714
3228
|
removeEventListener("pointerdown", tap, true);
|
|
@@ -2799,6 +3313,14 @@ var api = {
|
|
|
2799
3313
|
},
|
|
2800
3314
|
problems: function () { return problemsOf(openProbs()); },
|
|
2801
3315
|
state: function () { return { walked: walkedN(), total: stops.length, done: !walking && walkEnd === "done" && stops.every(function (x) { return hidTested.has(x); }), untested: untested() }; },
|
|
3316
|
+
regions: function () { return regions()[0]; },
|
|
3317
|
+
cost: function (q) {
|
|
3318
|
+
if (q) {
|
|
3319
|
+
var e = document.querySelector(q);
|
|
3320
|
+
return e && stops.indexOf(e) >= 0 ? stops.indexOf(e) + 1 : null;
|
|
3321
|
+
}
|
|
3322
|
+
return goals().map(function (g) { return { name: g.name, presses: g.presses, how: g.how, selector: sel(g.el) }; });
|
|
3323
|
+
},
|
|
2802
3324
|
version: VERSION,
|
|
2803
3325
|
close: function () { close(); }
|
|
2804
3326
|
};
|