@axe-core/react 4.7.1-alpha.384 → 4.7.1
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/dist/index.mjs +322 -0
- package/package.json +3 -2
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
// index.ts
|
|
2
|
+
import axeCore from "axe-core";
|
|
3
|
+
import * as rIC from "requestidlecallback";
|
|
4
|
+
|
|
5
|
+
// after.ts
|
|
6
|
+
var restoreFunctions = [];
|
|
7
|
+
function after(host, name, cb) {
|
|
8
|
+
const originalFn = host[name];
|
|
9
|
+
let restoreFn;
|
|
10
|
+
if (originalFn) {
|
|
11
|
+
host[name] = function(...args) {
|
|
12
|
+
originalFn.apply(this, args);
|
|
13
|
+
cb(host);
|
|
14
|
+
};
|
|
15
|
+
restoreFn = function() {
|
|
16
|
+
host[name] = originalFn;
|
|
17
|
+
};
|
|
18
|
+
} else {
|
|
19
|
+
host[name] = function() {
|
|
20
|
+
cb(host);
|
|
21
|
+
};
|
|
22
|
+
restoreFn = function() {
|
|
23
|
+
delete host[name];
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
restoreFunctions.push(restoreFn);
|
|
27
|
+
}
|
|
28
|
+
after.restorePatchedMethods = function() {
|
|
29
|
+
restoreFunctions.forEach((restoreFn) => restoreFn());
|
|
30
|
+
restoreFunctions = [];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// cache.ts
|
|
34
|
+
var _cache = {};
|
|
35
|
+
var cache = {
|
|
36
|
+
set(key, value) {
|
|
37
|
+
_cache[key] = value;
|
|
38
|
+
},
|
|
39
|
+
get(key) {
|
|
40
|
+
return _cache[key];
|
|
41
|
+
},
|
|
42
|
+
clear() {
|
|
43
|
+
Object.keys(_cache).forEach((key) => {
|
|
44
|
+
delete _cache[key];
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var cache_default = cache;
|
|
49
|
+
|
|
50
|
+
// index.ts
|
|
51
|
+
var requestIdleCallback = rIC.request;
|
|
52
|
+
var cancelIdleCallback = rIC.cancel;
|
|
53
|
+
var React;
|
|
54
|
+
var ReactDOM;
|
|
55
|
+
var logger;
|
|
56
|
+
var lightTheme = {
|
|
57
|
+
serious: "#d93251",
|
|
58
|
+
minor: "#d24700",
|
|
59
|
+
text: "black"
|
|
60
|
+
};
|
|
61
|
+
var darkTheme = {
|
|
62
|
+
serious: "#ffb3b3",
|
|
63
|
+
minor: "#ffd500",
|
|
64
|
+
text: "white"
|
|
65
|
+
};
|
|
66
|
+
var theme = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? darkTheme : lightTheme;
|
|
67
|
+
var boldCourier = "font-weight:bold;font-family:Courier;";
|
|
68
|
+
var critical = `color:${theme.serious};font-weight:bold;`;
|
|
69
|
+
var serious = `color:${theme.serious};font-weight:normal;`;
|
|
70
|
+
var moderate = `color:${theme.minor};font-weight:bold;`;
|
|
71
|
+
var minor = `color:${theme.minor};font-weight:normal;`;
|
|
72
|
+
var defaultReset = `font-color:${theme.text};font-weight:normal;`;
|
|
73
|
+
var idleId;
|
|
74
|
+
var timeout;
|
|
75
|
+
var context;
|
|
76
|
+
var conf;
|
|
77
|
+
var _createElement;
|
|
78
|
+
var components = {};
|
|
79
|
+
var nodes = [document.documentElement];
|
|
80
|
+
function debounce(func, wait, immediate) {
|
|
81
|
+
let _timeout;
|
|
82
|
+
return function(...args) {
|
|
83
|
+
const later = () => {
|
|
84
|
+
_timeout = null;
|
|
85
|
+
if (!immediate)
|
|
86
|
+
func.apply(this, args);
|
|
87
|
+
};
|
|
88
|
+
const callNow = immediate && !_timeout;
|
|
89
|
+
clearTimeout(_timeout);
|
|
90
|
+
_timeout = setTimeout(later, wait);
|
|
91
|
+
if (callNow)
|
|
92
|
+
func.apply(this, args);
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function getPath(node) {
|
|
96
|
+
const path = [node];
|
|
97
|
+
while (node && node.nodeName.toLowerCase() !== "html") {
|
|
98
|
+
path.push(node.parentNode);
|
|
99
|
+
node = node.parentNode;
|
|
100
|
+
}
|
|
101
|
+
if (!node || !node.parentNode) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
return path.reverse();
|
|
105
|
+
}
|
|
106
|
+
function getCommonParent(nodes2) {
|
|
107
|
+
let path;
|
|
108
|
+
let nextPath;
|
|
109
|
+
if (nodes2.length === 1) {
|
|
110
|
+
return nodes2.pop();
|
|
111
|
+
}
|
|
112
|
+
while (!path && nodes2.length) {
|
|
113
|
+
path = getPath(nodes2.pop());
|
|
114
|
+
}
|
|
115
|
+
while (nodes2.length) {
|
|
116
|
+
nextPath = getPath(nodes2.pop());
|
|
117
|
+
if (nextPath) {
|
|
118
|
+
path = path.filter((node, index) => {
|
|
119
|
+
return nextPath.length > index && nextPath[index] === node;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return path ? path[path.length - 1] : document;
|
|
124
|
+
}
|
|
125
|
+
function logElement(node, logFn) {
|
|
126
|
+
const el = document.querySelector(node.target.toString());
|
|
127
|
+
if (!el) {
|
|
128
|
+
logFn("Selector: %c%s", boldCourier, node.target.toString());
|
|
129
|
+
} else {
|
|
130
|
+
logFn("Element: %o", el);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function logHtml(node) {
|
|
134
|
+
console.log("HTML: %c%s", boldCourier, node.html);
|
|
135
|
+
}
|
|
136
|
+
function logFailureMessage(node, key) {
|
|
137
|
+
const message = axeCore._audit.data.failureSummaries[key].failureMessage(
|
|
138
|
+
node[key].map((check) => check.message || "")
|
|
139
|
+
);
|
|
140
|
+
console.error(message);
|
|
141
|
+
}
|
|
142
|
+
function failureSummary(node, key) {
|
|
143
|
+
if (node[key].length > 0) {
|
|
144
|
+
logElement(node, console.groupCollapsed);
|
|
145
|
+
logHtml(node);
|
|
146
|
+
logFailureMessage(node, key);
|
|
147
|
+
let relatedNodes = [];
|
|
148
|
+
node[key].forEach((check) => {
|
|
149
|
+
relatedNodes = relatedNodes.concat(check.relatedNodes);
|
|
150
|
+
});
|
|
151
|
+
if (relatedNodes.length > 0) {
|
|
152
|
+
console.groupCollapsed("Related nodes");
|
|
153
|
+
relatedNodes.forEach((relatedNode) => {
|
|
154
|
+
logElement(relatedNode, console.log);
|
|
155
|
+
logHtml(relatedNode);
|
|
156
|
+
});
|
|
157
|
+
console.groupEnd();
|
|
158
|
+
}
|
|
159
|
+
console.groupEnd();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function checkAndReport(node, timeout2) {
|
|
163
|
+
const disableDeduplicate = conf["disableDeduplicate"];
|
|
164
|
+
if (idleId) {
|
|
165
|
+
cancelIdleCallback(idleId);
|
|
166
|
+
idleId = void 0;
|
|
167
|
+
}
|
|
168
|
+
return new Promise((resolve, reject) => {
|
|
169
|
+
nodes.push(node);
|
|
170
|
+
idleId = requestIdleCallback(
|
|
171
|
+
() => {
|
|
172
|
+
let n = context;
|
|
173
|
+
if (n === void 0) {
|
|
174
|
+
n = getCommonParent(nodes.filter((node2) => node2.isConnected));
|
|
175
|
+
if (n.nodeName.toLowerCase() === "html") {
|
|
176
|
+
n = document;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
axeCore.configure({ allowedOrigins: ["<unsafe_all_origins>"] });
|
|
180
|
+
axeCore.run(
|
|
181
|
+
n,
|
|
182
|
+
{ reporter: "v2" },
|
|
183
|
+
function(error, results) {
|
|
184
|
+
if (error) {
|
|
185
|
+
return reject(error);
|
|
186
|
+
}
|
|
187
|
+
results.violations = results.violations.filter((result) => {
|
|
188
|
+
result.nodes = result.nodes.filter((node2) => {
|
|
189
|
+
const key = node2.target.toString() + result.id;
|
|
190
|
+
const retVal = !cache_default.get(key);
|
|
191
|
+
cache_default.set(key, key);
|
|
192
|
+
return disableDeduplicate || retVal;
|
|
193
|
+
});
|
|
194
|
+
return !!result.nodes.length;
|
|
195
|
+
});
|
|
196
|
+
if (results.violations.length) {
|
|
197
|
+
logger(results);
|
|
198
|
+
}
|
|
199
|
+
resolve();
|
|
200
|
+
}
|
|
201
|
+
);
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
timeout: timeout2
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
function checkNode(component) {
|
|
210
|
+
let node;
|
|
211
|
+
try {
|
|
212
|
+
node = ReactDOM.findDOMNode(component);
|
|
213
|
+
} catch (e) {
|
|
214
|
+
console.group("%caxe error: could not check node", critical);
|
|
215
|
+
console.group("%cComponent", serious);
|
|
216
|
+
console.error(component);
|
|
217
|
+
console.groupEnd();
|
|
218
|
+
console.group("%cError", serious);
|
|
219
|
+
console.error(e);
|
|
220
|
+
console.groupEnd();
|
|
221
|
+
console.groupEnd();
|
|
222
|
+
}
|
|
223
|
+
if (node) {
|
|
224
|
+
checkAndReport(node, timeout);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
function componentAfterRender(component) {
|
|
228
|
+
const debounceCheckNode = debounce(checkNode, timeout, true);
|
|
229
|
+
after(component, "componentDidMount", debounceCheckNode);
|
|
230
|
+
after(component, "componentDidUpdate", debounceCheckNode);
|
|
231
|
+
}
|
|
232
|
+
function addComponent(component) {
|
|
233
|
+
const reactInstance = component._reactInternalInstance || {};
|
|
234
|
+
const reactInstanceDebugID = reactInstance._debugID;
|
|
235
|
+
const reactFiberInstance = component._reactInternalFiber || {};
|
|
236
|
+
const reactFiberInstanceDebugID = reactFiberInstance._debugID;
|
|
237
|
+
const reactInternals = component._reactInternals || {};
|
|
238
|
+
const reactInternalsDebugID = reactInternals._debugID;
|
|
239
|
+
if (reactInstanceDebugID && !components[reactInstanceDebugID]) {
|
|
240
|
+
components[reactInstanceDebugID] = component;
|
|
241
|
+
componentAfterRender(component);
|
|
242
|
+
} else if (reactFiberInstanceDebugID && !components[reactFiberInstanceDebugID]) {
|
|
243
|
+
components[reactFiberInstanceDebugID] = component;
|
|
244
|
+
componentAfterRender(component);
|
|
245
|
+
} else if (reactInternalsDebugID && !components[reactInternalsDebugID]) {
|
|
246
|
+
components[reactInternalsDebugID] = component;
|
|
247
|
+
componentAfterRender(component);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
function logToConsole(results) {
|
|
251
|
+
console.group("%cNew axe issues", serious);
|
|
252
|
+
results.violations.forEach((result) => {
|
|
253
|
+
let fmt;
|
|
254
|
+
switch (result.impact) {
|
|
255
|
+
case "critical":
|
|
256
|
+
fmt = critical;
|
|
257
|
+
break;
|
|
258
|
+
case "serious":
|
|
259
|
+
fmt = serious;
|
|
260
|
+
break;
|
|
261
|
+
case "moderate":
|
|
262
|
+
fmt = moderate;
|
|
263
|
+
break;
|
|
264
|
+
case "minor":
|
|
265
|
+
fmt = minor;
|
|
266
|
+
break;
|
|
267
|
+
default:
|
|
268
|
+
fmt = minor;
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
console.groupCollapsed(
|
|
272
|
+
"%c%s: %c%s %s",
|
|
273
|
+
fmt,
|
|
274
|
+
result.impact,
|
|
275
|
+
defaultReset,
|
|
276
|
+
result.help,
|
|
277
|
+
result.helpUrl
|
|
278
|
+
);
|
|
279
|
+
result.nodes.forEach((node) => {
|
|
280
|
+
failureSummary(node, "any");
|
|
281
|
+
failureSummary(node, "none");
|
|
282
|
+
});
|
|
283
|
+
console.groupEnd();
|
|
284
|
+
});
|
|
285
|
+
console.groupEnd();
|
|
286
|
+
}
|
|
287
|
+
function reactAxe(_React, _ReactDOM, _timeout, _conf = {}, _context, _logger) {
|
|
288
|
+
React = _React;
|
|
289
|
+
ReactDOM = _ReactDOM;
|
|
290
|
+
timeout = _timeout;
|
|
291
|
+
context = _context;
|
|
292
|
+
conf = _conf;
|
|
293
|
+
logger = _logger || logToConsole;
|
|
294
|
+
const runOnly = conf["runOnly"];
|
|
295
|
+
if (runOnly) {
|
|
296
|
+
conf["rules"] = axeCore.getRules(runOnly).map((rule) => ({ ...rule, id: rule.ruleId, enabled: true }));
|
|
297
|
+
conf["disableOtherRules"] = true;
|
|
298
|
+
}
|
|
299
|
+
if (Object.keys(conf).length > 0) {
|
|
300
|
+
axeCore.configure(conf);
|
|
301
|
+
}
|
|
302
|
+
axeCore.configure({ allowedOrigins: ["<unsafe_all_origins>"] });
|
|
303
|
+
if (!_createElement) {
|
|
304
|
+
_createElement = React.createElement;
|
|
305
|
+
React.createElement = function(...args) {
|
|
306
|
+
const reactEl = _createElement.apply(this, args);
|
|
307
|
+
if (reactEl._owner && reactEl._owner._instance) {
|
|
308
|
+
addComponent(reactEl._owner._instance);
|
|
309
|
+
} else if (reactEl._owner && reactEl._owner.stateNode) {
|
|
310
|
+
addComponent(reactEl._owner.stateNode);
|
|
311
|
+
}
|
|
312
|
+
return reactEl;
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
return checkAndReport(document.body, timeout);
|
|
316
|
+
}
|
|
317
|
+
if (typeof module === "object") {
|
|
318
|
+
exports = module.exports = reactAxe;
|
|
319
|
+
}
|
|
320
|
+
export {
|
|
321
|
+
reactAxe as default
|
|
322
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axe-core/react",
|
|
3
|
-
"version": "4.7.1
|
|
3
|
+
"version": "4.7.1",
|
|
4
4
|
"description": "Dynamic accessibility analysis for React using axe-core",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"dist/cache.d.ts",
|
|
21
21
|
"dist/cache.js.map",
|
|
22
22
|
"dist/index.js",
|
|
23
|
+
"dist/index.mjs",
|
|
23
24
|
"dist/index.d.ts",
|
|
24
25
|
"dist/index.js.map"
|
|
25
26
|
],
|
|
@@ -91,5 +92,5 @@
|
|
|
91
92
|
"<rootDir>/test/jest.setup.js"
|
|
92
93
|
]
|
|
93
94
|
},
|
|
94
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "32caffdbe7688e43b73b242113e684ff31edfc7d"
|
|
95
96
|
}
|