@axe-core/react 4.6.2-alpha.379 → 4.6.2-alpha.380

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.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import axeCore = require('axe-core');
1
+ import axeCore from 'axe-core';
2
+
2
3
  declare let React: any;
3
4
  declare let ReactDOM: any;
4
5
  /**
@@ -18,4 +19,5 @@ interface ReactSpec extends axeCore.Spec {
18
19
  * @param {Function} _logger Logger implementation
19
20
  */
20
21
  declare function reactAxe(_React: typeof React, _ReactDOM: typeof ReactDOM, _timeout: number, _conf?: ReactSpec, _context?: axeCore.ElementContext, _logger?: (results: axeCore.AxeResults) => void): Promise<void>;
21
- export = reactAxe;
22
+
23
+ export { reactAxe as default };
package/dist/index.js CHANGED
@@ -1,49 +1,108 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // index.ts
30
+ var react_exports = {};
31
+ __export(react_exports, {
32
+ default: () => reactAxe
33
+ });
34
+ module.exports = __toCommonJS(react_exports);
35
+ var import_axe_core = __toESM(require("axe-core"));
36
+ var rIC = __toESM(require("requestidlecallback"));
37
+
38
+ // after.ts
39
+ var restoreFunctions = [];
40
+ function after(host, name, cb) {
41
+ const originalFn = host[name];
42
+ let restoreFn;
43
+ if (originalFn) {
44
+ host[name] = function(...args) {
45
+ originalFn.apply(this, args);
46
+ cb(host);
47
+ };
48
+ restoreFn = function() {
49
+ host[name] = originalFn;
50
+ };
51
+ } else {
52
+ host[name] = function() {
53
+ cb(host);
54
+ };
55
+ restoreFn = function() {
56
+ delete host[name];
10
57
  };
11
- return __assign.apply(this, arguments);
58
+ }
59
+ restoreFunctions.push(restoreFn);
60
+ }
61
+ after.restorePatchedMethods = function() {
62
+ restoreFunctions.forEach((restoreFn) => restoreFn());
63
+ restoreFunctions = [];
12
64
  };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
65
+
66
+ // cache.ts
67
+ var _cache = {};
68
+ var cache = {
69
+ set(key, value) {
70
+ _cache[key] = value;
71
+ },
72
+ get(key) {
73
+ return _cache[key];
74
+ },
75
+ clear() {
76
+ Object.keys(_cache).forEach((key) => {
77
+ delete _cache[key];
78
+ });
79
+ }
15
80
  };
16
- /* global Promise */
17
- var axeCore = require("axe-core");
18
- var rIC = require("requestidlecallback");
19
- var after = require("./after");
20
- var cache_1 = __importDefault(require("./cache"));
81
+ var cache_default = cache;
82
+
83
+ // index.ts
21
84
  var requestIdleCallback = rIC.request;
22
85
  var cancelIdleCallback = rIC.cancel;
23
86
  var React;
24
87
  var ReactDOM;
25
88
  var logger;
26
- // contrasted against Chrome default color of #ffffff
27
89
  var lightTheme = {
28
- serious: '#d93251',
29
- minor: '#d24700',
30
- text: 'black'
90
+ serious: "#d93251",
91
+ minor: "#d24700",
92
+ text: "black"
31
93
  };
32
- // contrasted against Safari dark mode color of #535353
33
94
  var darkTheme = {
34
- serious: '#ffb3b3',
35
- minor: '#ffd500',
36
- text: 'white'
95
+ serious: "#ffb3b3",
96
+ minor: "#ffd500",
97
+ text: "white"
37
98
  };
38
- var theme = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
39
- ? darkTheme
40
- : lightTheme;
41
- var boldCourier = 'font-weight:bold;font-family:Courier;';
42
- var critical = "color:".concat(theme.serious, ";font-weight:bold;");
43
- var serious = "color:".concat(theme.serious, ";font-weight:normal;");
44
- var moderate = "color:".concat(theme.minor, ";font-weight:bold;");
45
- var minor = "color:".concat(theme.minor, ";font-weight:normal;");
46
- var defaultReset = "font-color:".concat(theme.text, ";font-weight:normal;");
99
+ var theme = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? darkTheme : lightTheme;
100
+ var boldCourier = "font-weight:bold;font-family:Courier;";
101
+ var critical = `color:${theme.serious};font-weight:bold;`;
102
+ var serious = `color:${theme.serious};font-weight:normal;`;
103
+ var moderate = `color:${theme.minor};font-weight:bold;`;
104
+ var minor = `color:${theme.minor};font-weight:normal;`;
105
+ var defaultReset = `font-color:${theme.text};font-weight:normal;`;
47
106
  var idleId;
48
107
  var timeout;
49
108
  var context;
@@ -51,314 +110,243 @@ var conf;
51
110
  var _createElement;
52
111
  var components = {};
53
112
  var nodes = [document.documentElement];
54
- // Returns a function, that, as long as it continues to be invoked, will not
55
- // be triggered. The function will be called after it stops being called for
56
- // N milliseconds. If `immediate` is passed, trigger the function on the
57
- // leading edge, instead of the trailing.
58
- // @see https://davidwalsh.name/javascript-debounce-function
59
113
  function debounce(func, wait, immediate) {
60
- var _timeout;
61
- return function () {
62
- var _this = this;
63
- var args = [];
64
- for (var _i = 0; _i < arguments.length; _i++) {
65
- args[_i] = arguments[_i];
66
- }
67
- var later = function () {
68
- _timeout = null;
69
- if (!immediate)
70
- func.apply(_this, args);
71
- };
72
- var callNow = immediate && !_timeout;
73
- clearTimeout(_timeout);
74
- _timeout = setTimeout(later, wait);
75
- if (callNow)
76
- func.apply(this, args);
114
+ let _timeout;
115
+ return function(...args) {
116
+ const later = () => {
117
+ _timeout = null;
118
+ if (!immediate)
119
+ func.apply(this, args);
77
120
  };
121
+ const callNow = immediate && !_timeout;
122
+ clearTimeout(_timeout);
123
+ _timeout = setTimeout(later, wait);
124
+ if (callNow)
125
+ func.apply(this, args);
126
+ };
78
127
  }
79
- /**
80
- * Return the entire parent tree of a node (from HTML down).
81
- * @param {Node} node
82
- * @return {Node[]}
83
- */
84
128
  function getPath(node) {
85
- var path = [node];
86
- while (node && node.nodeName.toLowerCase() !== 'html') {
87
- path.push(node.parentNode);
88
- node = node.parentNode;
89
- }
90
- if (!node || !node.parentNode) {
91
- return null;
92
- }
93
- return path.reverse();
129
+ const path = [node];
130
+ while (node && node.nodeName.toLowerCase() !== "html") {
131
+ path.push(node.parentNode);
132
+ node = node.parentNode;
133
+ }
134
+ if (!node || !node.parentNode) {
135
+ return null;
136
+ }
137
+ return path.reverse();
94
138
  }
95
- /**
96
- * Find the common parent of an array of nodes.
97
- * @param {Node[]} nodes
98
- * @return {Node}
99
- */
100
- function getCommonParent(nodes) {
101
- var path;
102
- var nextPath;
103
- if (nodes.length === 1) {
104
- return nodes.pop();
139
+ function getCommonParent(nodes2) {
140
+ let path;
141
+ let nextPath;
142
+ if (nodes2.length === 1) {
143
+ return nodes2.pop();
144
+ }
145
+ while (!path && nodes2.length) {
146
+ path = getPath(nodes2.pop());
147
+ }
148
+ while (nodes2.length) {
149
+ nextPath = getPath(nodes2.pop());
150
+ if (nextPath) {
151
+ path = path.filter((node, index) => {
152
+ return nextPath.length > index && nextPath[index] === node;
153
+ });
105
154
  }
106
- while (!path && nodes.length) {
107
- path = getPath(nodes.pop());
108
- }
109
- while (nodes.length) {
110
- nextPath = getPath(nodes.pop());
111
- if (nextPath) {
112
- path = path.filter(function (node, index) {
113
- return nextPath.length > index && nextPath[index] === node;
114
- });
115
- }
116
- }
117
- return path ? path[path.length - 1] : document;
155
+ }
156
+ return path ? path[path.length - 1] : document;
118
157
  }
119
- /**
120
- * Log the axe result node to the console
121
- * @param {NodeResult} node
122
- * @param {Function} logFn console log function to use (error, warn, log, etc.)
123
- */
124
158
  function logElement(node, logFn) {
125
- var el = document.querySelector(node.target.toString());
126
- if (!el) {
127
- logFn('Selector: %c%s', boldCourier, node.target.toString());
128
- }
129
- else {
130
- logFn('Element: %o', el);
131
- }
159
+ const el = document.querySelector(node.target.toString());
160
+ if (!el) {
161
+ logFn("Selector: %c%s", boldCourier, node.target.toString());
162
+ } else {
163
+ logFn("Element: %o", el);
164
+ }
132
165
  }
133
- /**
134
- * Log the axe result node html tot he console
135
- * @param {NodeResult} node
136
- */
137
166
  function logHtml(node) {
138
- console.log('HTML: %c%s', boldCourier, node.html);
167
+ console.log("HTML: %c%s", boldCourier, node.html);
139
168
  }
140
- /**
141
- * Log the failure message of a node result.
142
- * @param {NodeResult} node
143
- * @param {String} key which check array to log from (any, all, none)
144
- */
145
169
  function logFailureMessage(node, key) {
146
- // this exists on axe but we don't export it as part of the typescript
147
- // namespace, so just let me use it as I need
148
- var message = axeCore._audit.data.failureSummaries[key].failureMessage(node[key].map(function (check) { return check.message || ''; }));
149
- console.error(message);
170
+ const message = import_axe_core.default._audit.data.failureSummaries[key].failureMessage(
171
+ node[key].map((check) => check.message || "")
172
+ );
173
+ console.error(message);
150
174
  }
151
- /**
152
- * Log as a group the node result and failure message.
153
- * @param {NodeResult} node
154
- * @param {String} key which check array to log from (any, all, none)
155
- */
156
175
  function failureSummary(node, key) {
157
- if (node[key].length > 0) {
158
- logElement(node, console.groupCollapsed);
159
- logHtml(node);
160
- logFailureMessage(node, key);
161
- var relatedNodes_1 = [];
162
- node[key].forEach(function (check) {
163
- relatedNodes_1 = relatedNodes_1.concat(check.relatedNodes);
164
- });
165
- if (relatedNodes_1.length > 0) {
166
- console.groupCollapsed('Related nodes');
167
- relatedNodes_1.forEach(function (relatedNode) {
168
- logElement(relatedNode, console.log);
169
- logHtml(relatedNode);
170
- });
171
- console.groupEnd();
172
- }
173
- console.groupEnd();
176
+ if (node[key].length > 0) {
177
+ logElement(node, console.groupCollapsed);
178
+ logHtml(node);
179
+ logFailureMessage(node, key);
180
+ let relatedNodes = [];
181
+ node[key].forEach((check) => {
182
+ relatedNodes = relatedNodes.concat(check.relatedNodes);
183
+ });
184
+ if (relatedNodes.length > 0) {
185
+ console.groupCollapsed("Related nodes");
186
+ relatedNodes.forEach((relatedNode) => {
187
+ logElement(relatedNode, console.log);
188
+ logHtml(relatedNode);
189
+ });
190
+ console.groupEnd();
174
191
  }
192
+ console.groupEnd();
193
+ }
175
194
  }
176
- /**
177
- * Run axe against the passed in node and report violations
178
- * @param {*} node
179
- * @param {Number} timeout force call of axe.run after the timeout has passed (if not called before)
180
- * @return {Promise}
181
- */
182
- function checkAndReport(node, timeout) {
183
- var disableDeduplicate = conf['disableDeduplicate'];
184
- if (idleId) {
185
- cancelIdleCallback(idleId);
186
- idleId = undefined;
187
- }
188
- return new Promise(function (resolve, reject) {
189
- nodes.push(node);
190
- idleId = requestIdleCallback(function () {
191
- var n = context;
192
- if (n === undefined) {
193
- n = getCommonParent(nodes.filter(function (node) { return node.isConnected; }));
194
- if (n.nodeName.toLowerCase() === 'html') {
195
- // if the only common parent is the body, then analyze the whole page
196
- n = document;
197
- }
195
+ function checkAndReport(node, timeout2) {
196
+ const disableDeduplicate = conf["disableDeduplicate"];
197
+ if (idleId) {
198
+ cancelIdleCallback(idleId);
199
+ idleId = void 0;
200
+ }
201
+ return new Promise((resolve, reject) => {
202
+ nodes.push(node);
203
+ idleId = requestIdleCallback(
204
+ () => {
205
+ let n = context;
206
+ if (n === void 0) {
207
+ n = getCommonParent(nodes.filter((node2) => node2.isConnected));
208
+ if (n.nodeName.toLowerCase() === "html") {
209
+ n = document;
210
+ }
211
+ }
212
+ import_axe_core.default.configure({ allowedOrigins: ["<unsafe_all_origins>"] });
213
+ import_axe_core.default.run(
214
+ n,
215
+ { reporter: "v2" },
216
+ function(error, results) {
217
+ if (error) {
218
+ return reject(error);
198
219
  }
199
- axeCore.configure({ allowedOrigins: ['<unsafe_all_origins>'] });
200
- axeCore.run(n, { reporter: 'v2' }, function (error, results) {
201
- if (error) {
202
- return reject(error);
203
- }
204
- results.violations = results.violations.filter(function (result) {
205
- result.nodes = result.nodes.filter(function (node) {
206
- var key = node.target.toString() + result.id;
207
- var retVal = !cache_1.default.get(key);
208
- cache_1.default.set(key, key);
209
- return disableDeduplicate || retVal;
210
- });
211
- return !!result.nodes.length;
212
- });
213
- if (results.violations.length) {
214
- logger(results);
215
- }
216
- resolve();
220
+ results.violations = results.violations.filter((result) => {
221
+ result.nodes = result.nodes.filter((node2) => {
222
+ const key = node2.target.toString() + result.id;
223
+ const retVal = !cache_default.get(key);
224
+ cache_default.set(key, key);
225
+ return disableDeduplicate || retVal;
226
+ });
227
+ return !!result.nodes.length;
217
228
  });
218
- }, {
219
- timeout: timeout
220
- });
221
- });
229
+ if (results.violations.length) {
230
+ logger(results);
231
+ }
232
+ resolve();
233
+ }
234
+ );
235
+ },
236
+ {
237
+ timeout: timeout2
238
+ }
239
+ );
240
+ });
222
241
  }
223
- /**
224
- * Check the node for violations.
225
- * @param {Component} component
226
- */
227
242
  function checkNode(component) {
228
- var node;
229
- try {
230
- node = ReactDOM.findDOMNode(component);
231
- }
232
- catch (e) {
233
- console.group('%caxe error: could not check node', critical);
234
- console.group('%cComponent', serious);
235
- console.error(component);
236
- console.groupEnd();
237
- console.group('%cError', serious);
238
- console.error(e);
239
- console.groupEnd();
240
- console.groupEnd();
241
- }
242
- if (node) {
243
- checkAndReport(node, timeout);
244
- }
243
+ let node;
244
+ try {
245
+ node = ReactDOM.findDOMNode(component);
246
+ } catch (e) {
247
+ console.group("%caxe error: could not check node", critical);
248
+ console.group("%cComponent", serious);
249
+ console.error(component);
250
+ console.groupEnd();
251
+ console.group("%cError", serious);
252
+ console.error(e);
253
+ console.groupEnd();
254
+ console.groupEnd();
255
+ }
256
+ if (node) {
257
+ checkAndReport(node, timeout);
258
+ }
245
259
  }
246
- /**
247
- * Check the component for violations whenever the DOM updates
248
- * @param {Component} component
249
- */
250
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
251
260
  function componentAfterRender(component) {
252
- var debounceCheckNode = debounce(checkNode, timeout, true);
253
- after(component, 'componentDidMount', debounceCheckNode);
254
- after(component, 'componentDidUpdate', debounceCheckNode);
261
+ const debounceCheckNode = debounce(checkNode, timeout, true);
262
+ after(component, "componentDidMount", debounceCheckNode);
263
+ after(component, "componentDidUpdate", debounceCheckNode);
255
264
  }
256
- /**
257
- * Add a component to track.
258
- * @param {Component} component
259
- */
260
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
261
265
  function addComponent(component) {
262
- var reactInstance = component._reactInternalInstance || {};
263
- var reactInstanceDebugID = reactInstance._debugID;
264
- var reactFiberInstance = component._reactInternalFiber || {};
265
- var reactFiberInstanceDebugID = reactFiberInstance._debugID;
266
- var reactInternals = component._reactInternals || {};
267
- var reactInternalsDebugID = reactInternals._debugID;
268
- if (reactInstanceDebugID && !components[reactInstanceDebugID]) {
269
- components[reactInstanceDebugID] = component;
270
- componentAfterRender(component);
271
- }
272
- else if (reactFiberInstanceDebugID &&
273
- !components[reactFiberInstanceDebugID]) {
274
- components[reactFiberInstanceDebugID] = component;
275
- componentAfterRender(component);
276
- }
277
- else if (reactInternalsDebugID && !components[reactInternalsDebugID]) {
278
- components[reactInternalsDebugID] = component;
279
- componentAfterRender(component);
280
- }
266
+ const reactInstance = component._reactInternalInstance || {};
267
+ const reactInstanceDebugID = reactInstance._debugID;
268
+ const reactFiberInstance = component._reactInternalFiber || {};
269
+ const reactFiberInstanceDebugID = reactFiberInstance._debugID;
270
+ const reactInternals = component._reactInternals || {};
271
+ const reactInternalsDebugID = reactInternals._debugID;
272
+ if (reactInstanceDebugID && !components[reactInstanceDebugID]) {
273
+ components[reactInstanceDebugID] = component;
274
+ componentAfterRender(component);
275
+ } else if (reactFiberInstanceDebugID && !components[reactFiberInstanceDebugID]) {
276
+ components[reactFiberInstanceDebugID] = component;
277
+ componentAfterRender(component);
278
+ } else if (reactInternalsDebugID && !components[reactInternalsDebugID]) {
279
+ components[reactInternalsDebugID] = component;
280
+ componentAfterRender(component);
281
+ }
281
282
  }
282
- /**
283
- * Log axe violations to console.
284
- * @param {AxeResults} results
285
- */
286
283
  function logToConsole(results) {
287
- console.group('%cNew axe issues', serious);
288
- results.violations.forEach(function (result) {
289
- var fmt;
290
- switch (result.impact) {
291
- case 'critical':
292
- fmt = critical;
293
- break;
294
- case 'serious':
295
- fmt = serious;
296
- break;
297
- case 'moderate':
298
- fmt = moderate;
299
- break;
300
- case 'minor':
301
- fmt = minor;
302
- break;
303
- default:
304
- fmt = minor;
305
- break;
306
- }
307
- console.groupCollapsed('%c%s: %c%s %s', fmt, result.impact, defaultReset, result.help, result.helpUrl);
308
- result.nodes.forEach(function (node) {
309
- failureSummary(node, 'any');
310
- failureSummary(node, 'none');
311
- });
312
- console.groupEnd();
284
+ console.group("%cNew axe issues", serious);
285
+ results.violations.forEach((result) => {
286
+ let fmt;
287
+ switch (result.impact) {
288
+ case "critical":
289
+ fmt = critical;
290
+ break;
291
+ case "serious":
292
+ fmt = serious;
293
+ break;
294
+ case "moderate":
295
+ fmt = moderate;
296
+ break;
297
+ case "minor":
298
+ fmt = minor;
299
+ break;
300
+ default:
301
+ fmt = minor;
302
+ break;
303
+ }
304
+ console.groupCollapsed(
305
+ "%c%s: %c%s %s",
306
+ fmt,
307
+ result.impact,
308
+ defaultReset,
309
+ result.help,
310
+ result.helpUrl
311
+ );
312
+ result.nodes.forEach((node) => {
313
+ failureSummary(node, "any");
314
+ failureSummary(node, "none");
313
315
  });
314
316
  console.groupEnd();
317
+ });
318
+ console.groupEnd();
315
319
  }
316
- /**
317
- * Run axe against all changes made in a React app.
318
- * @parma {React} _React React instance
319
- * @param {ReactDOM} _ReactDOM ReactDOM instance
320
- * @param {Number} _timeout debounce timeout in milliseconds
321
- * @parma {Spec} conf React axe.configure Spec object
322
- * @param {ElementContext} _context axe ElementContent object
323
- * @param {Function} _logger Logger implementation
324
- */
325
- function reactAxe(_React, _ReactDOM, _timeout, _conf, _context, _logger) {
326
- if (_conf === void 0) { _conf = {}; }
327
- React = _React;
328
- ReactDOM = _ReactDOM;
329
- timeout = _timeout;
330
- context = _context;
331
- conf = _conf;
332
- logger = _logger || logToConsole;
333
- var runOnly = conf['runOnly'];
334
- if (runOnly) {
335
- conf['rules'] = axeCore
336
- .getRules(runOnly)
337
- .map(function (rule) { return (__assign(__assign({}, rule), { id: rule.ruleId, enabled: true })); });
338
- conf['disableOtherRules'] = true;
339
- }
340
- if (Object.keys(conf).length > 0) {
341
- axeCore.configure(conf);
342
- }
343
- axeCore.configure({ allowedOrigins: ['<unsafe_all_origins>'] });
344
- if (!_createElement) {
345
- _createElement = React.createElement;
346
- React.createElement = function () {
347
- var args = [];
348
- for (var _i = 0; _i < arguments.length; _i++) {
349
- args[_i] = arguments[_i];
350
- }
351
- var reactEl = _createElement.apply(this, args);
352
- if (reactEl._owner && reactEl._owner._instance) {
353
- addComponent(reactEl._owner._instance);
354
- }
355
- else if (reactEl._owner && reactEl._owner.stateNode) {
356
- addComponent(reactEl._owner.stateNode);
357
- }
358
- return reactEl;
359
- };
360
- }
361
- return checkAndReport(document.body, timeout);
320
+ function reactAxe(_React, _ReactDOM, _timeout, _conf = {}, _context, _logger) {
321
+ React = _React;
322
+ ReactDOM = _ReactDOM;
323
+ timeout = _timeout;
324
+ context = _context;
325
+ conf = _conf;
326
+ logger = _logger || logToConsole;
327
+ const runOnly = conf["runOnly"];
328
+ if (runOnly) {
329
+ conf["rules"] = import_axe_core.default.getRules(runOnly).map((rule) => ({ ...rule, id: rule.ruleId, enabled: true }));
330
+ conf["disableOtherRules"] = true;
331
+ }
332
+ if (Object.keys(conf).length > 0) {
333
+ import_axe_core.default.configure(conf);
334
+ }
335
+ import_axe_core.default.configure({ allowedOrigins: ["<unsafe_all_origins>"] });
336
+ if (!_createElement) {
337
+ _createElement = React.createElement;
338
+ React.createElement = function(...args) {
339
+ const reactEl = _createElement.apply(this, args);
340
+ if (reactEl._owner && reactEl._owner._instance) {
341
+ addComponent(reactEl._owner._instance);
342
+ } else if (reactEl._owner && reactEl._owner.stateNode) {
343
+ addComponent(reactEl._owner.stateNode);
344
+ }
345
+ return reactEl;
346
+ };
347
+ }
348
+ return checkAndReport(document.body, timeout);
349
+ }
350
+ if (typeof module === "object") {
351
+ exports = module.exports = reactAxe;
362
352
  }
363
- module.exports = reactAxe;
364
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,9 +1,17 @@
1
1
  {
2
2
  "name": "@axe-core/react",
3
- "version": "4.6.2-alpha.379+2e0fdb4",
3
+ "version": "4.6.2-alpha.380+076bfa9",
4
4
  "description": "Dynamic accessibility analysis for React using axe-core",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
7
15
  "files": [
8
16
  "dist/after.js",
9
17
  "dist/after.d.ts",
@@ -16,9 +24,10 @@
16
24
  "dist/index.js.map"
17
25
  ],
18
26
  "scripts": {
19
- "build": "tsc",
27
+ "build": "tsup index.ts --dts --format esm,cjs",
20
28
  "prepare": "npm run build",
21
29
  "test": "tsc && npm run test:types && jest",
30
+ "test:esm": "node esmTest.mjs",
22
31
  "test:types": "cd test && tsc"
23
32
  },
24
33
  "keywords": [
@@ -69,6 +78,7 @@
69
78
  "react-shadow": "^19.0.3",
70
79
  "sinon": "^14.0.1",
71
80
  "ts-node": "^10.9.1",
81
+ "tsup": "^6.7.0",
72
82
  "typescript": "^4.8.4"
73
83
  },
74
84
  "repository": {
@@ -81,5 +91,5 @@
81
91
  "<rootDir>/test/jest.setup.js"
82
92
  ]
83
93
  },
84
- "gitHead": "2e0fdb4a4661040b9b8dbb91bed1a96142e4fe0c"
94
+ "gitHead": "076bfa99f27f416b4eaff6d24cc23e8573fc72ee"
85
95
  }
package/dist/after.d.ts DELETED
@@ -1,6 +0,0 @@
1
- /// <reference types="react" />
2
- declare function after(host: React.Component, name: string, cb: Function): void;
3
- declare namespace after {
4
- var restorePatchedMethods: () => void;
5
- }
6
- export = after;
package/dist/after.js DELETED
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var restoreFunctions = [];
3
- function after(host, name, cb) {
4
- var originalFn = host[name];
5
- var restoreFn;
6
- if (originalFn) {
7
- host[name] = function () {
8
- var args = [];
9
- for (var _i = 0; _i < arguments.length; _i++) {
10
- args[_i] = arguments[_i];
11
- }
12
- originalFn.apply(this, args);
13
- cb(host);
14
- };
15
- restoreFn = function () {
16
- host[name] = originalFn;
17
- };
18
- }
19
- else {
20
- host[name] = function () {
21
- cb(host);
22
- };
23
- restoreFn = function () {
24
- delete host[name];
25
- };
26
- }
27
- restoreFunctions.push(restoreFn);
28
- }
29
- after.restorePatchedMethods = function () {
30
- restoreFunctions.forEach(function (restoreFn) { return restoreFn(); });
31
- restoreFunctions = [];
32
- };
33
- module.exports = after;
34
- //# sourceMappingURL=after.js.map
package/dist/after.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"after.js","sourceRoot":"","sources":["../after.ts"],"names":[],"mappings":";AAAA,IAAI,gBAAgB,GAAe,EAAE,CAAC;AAEtC,SAAS,KAAK,CAAC,IAAqB,EAAE,IAAY,EAAE,EAAY;IAC9D,IAAM,UAAU,GAAa,IAAI,CAAC,IAAI,CAAC,CAAC;IACxC,IAAI,SAAqB,CAAC;IAE1B,IAAI,UAAU,EAAE;QACd,IAAI,CAAC,IAAI,CAAC,GAAG;YAAS,cAAO;iBAAP,UAAO,EAAP,qBAAO,EAAP,IAAO;gBAAP,yBAAO;;YAC3B,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC7B,EAAE,CAAC,IAAI,CAAC,CAAC;QACX,CAAC,CAAC;QACF,SAAS,GAAG;YACV,IAAI,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC;QAC1B,CAAC,CAAC;KACH;SAAM;QACL,IAAI,CAAC,IAAI,CAAC,GAAG;YACX,EAAE,CAAC,IAAI,CAAC,CAAC;QACX,CAAC,CAAC;QACF,SAAS,GAAG;YACV,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC,CAAC;KACH;IAED,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACnC,CAAC;AAED,KAAK,CAAC,qBAAqB,GAAG;IAC5B,gBAAgB,CAAC,OAAO,CAAC,UAAA,SAAS,IAAI,OAAA,SAAS,EAAE,EAAX,CAAW,CAAC,CAAC;IACnD,gBAAgB,GAAG,EAAE,CAAC;AACxB,CAAC,CAAC;AAEF,iBAAS,KAAK,CAAC","sourcesContent":["let restoreFunctions: Function[] = [];\n\nfunction after(host: React.Component, name: string, cb: Function): void {\n const originalFn: Function = host[name];\n let restoreFn: () => void;\n\n if (originalFn) {\n host[name] = function(...args): void {\n originalFn.apply(this, args);\n cb(host);\n };\n restoreFn = function(): void {\n host[name] = originalFn;\n };\n } else {\n host[name] = function(): void {\n cb(host);\n };\n restoreFn = function(): void {\n delete host[name];\n };\n }\n\n restoreFunctions.push(restoreFn);\n}\n\nafter.restorePatchedMethods = function(): void {\n restoreFunctions.forEach(restoreFn => restoreFn());\n restoreFunctions = [];\n};\n\nexport = after;\n"]}
package/dist/cache.d.ts DELETED
@@ -1,6 +0,0 @@
1
- declare const cache: {
2
- set(key: string, value: string): void;
3
- get(key: string): string;
4
- clear(): void;
5
- };
6
- export default cache;
package/dist/cache.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var _cache = {};
4
- var cache = {
5
- set: function (key, value) {
6
- _cache[key] = value;
7
- },
8
- get: function (key) {
9
- return _cache[key];
10
- },
11
- clear: function () {
12
- Object.keys(_cache).forEach(function (key) {
13
- delete _cache[key];
14
- });
15
- }
16
- };
17
- exports.default = cache;
18
- //# sourceMappingURL=cache.js.map
package/dist/cache.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cache.js","sourceRoot":"","sources":["../cache.ts"],"names":[],"mappings":";;AAAA,IAAM,MAAM,GAA8B,EAAE,CAAC;AAE7C,IAAM,KAAK,GAAG;IACZ,GAAG,YAAC,GAAW,EAAE,KAAa;QAC5B,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACtB,CAAC;IACD,GAAG,YAAC,GAAW;QACb,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;IACD,KAAK;QACH,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAA,GAAG;YAC7B,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC;AAEF,kBAAe,KAAK,CAAC","sourcesContent":["const _cache: { [key: string]: string } = {};\n\nconst cache = {\n set(key: string, value: string): void {\n _cache[key] = value;\n },\n get(key: string): string {\n return _cache[key];\n },\n clear(): void {\n Object.keys(_cache).forEach(key => {\n delete _cache[key];\n });\n }\n};\n\nexport default cache;\n"]}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sour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B,GAAG,CAAC,UAAA,IAAI,IAAI,OAAA,uBAAM,IAAI,KAAE,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,IAAG,EAA7C,CAA6C,CAAC,CAAC;QAC9D,IAAI,CAAC,mBAAmB,CAAC,GAAG,IAAI,CAAC;KAClC;IAED,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;QAChC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;KACzB;IACD,OAAO,CAAC,SAAS,CAAC,EAAE,cAAc,EAAE,CAAC,sBAAsB,CAAC,EAAE,CAAC,CAAC;IAChE,IAAI,CAAC,cAAc,EAAE;QACnB,cAAc,GAAG,KAAK,CAAC,aAAa,CAAC;QAErC,KAAK,CAAC,aAAa,GAAG;YAAU,cAAO;iBAAP,UAAO,EAAP,qBAAO,EAAP,IAAO;gBAAP,yBAAO;;YACrC,IAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAEjD,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE;gBAC9C,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;aACxC;iBAAM,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE;gBACrD,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;aACxC;YAED,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC;KACH;IAED,OAAO,cAAc,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC;AAED,iBAAS,QAAQ,CAAC","sourcesContent":["/* global Promise */\nimport axeCore = require('axe-core');\nimport rIC = require('requestidlecallback');\nimport after = require('./after');\nimport cache from './cache';\n\nconst requestIdleCallback = rIC.request;\nconst cancelIdleCallback = rIC.cancel;\n\nlet React;\nlet ReactDOM;\nlet logger;\n\n// contrasted against Chrome default color of #ffffff\nconst lightTheme = {\n serious: '#d93251',\n minor: '#d24700',\n text: 'black'\n};\n\n// contrasted against Safari dark mode color of #535353\nconst darkTheme = {\n serious: '#ffb3b3',\n minor: '#ffd500',\n text: 'white'\n};\n\nconst theme =\n window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches\n ? darkTheme\n : lightTheme;\n\nconst boldCourier = 'font-weight:bold;font-family:Courier;';\nconst critical = `color:${theme.serious};font-weight:bold;`;\nconst serious = `color:${theme.serious};font-weight:normal;`;\nconst moderate = `color:${theme.minor};font-weight:bold;`;\nconst minor = `color:${theme.minor};font-weight:normal;`;\nconst defaultReset = `font-color:${theme.text};font-weight:normal;`;\n\nlet idleId: number | undefined;\nlet timeout: number;\nlet context: axeCore.ElementContext | undefined;\nlet conf: ReactSpec;\nlet _createElement: typeof React.createElement;\nconst components: { [id: number]: React.Component } = {};\nconst nodes: Node[] = [document.documentElement];\n\n// Returns a function, that, as long as it continues to be invoked, will not\n// be triggered. The function will be called after it stops being called for\n// N milliseconds. If `immediate` is passed, trigger the function on the\n// leading edge, instead of the trailing.\n// @see https://davidwalsh.name/javascript-debounce-function\nfunction debounce(func: Function, wait: number, immediate?: boolean): Function {\n let _timeout;\n return function (...args): void {\n const later = (): void => {\n _timeout = null;\n if (!immediate) func.apply(this, args);\n };\n const callNow = immediate && !_timeout;\n clearTimeout(_timeout);\n _timeout = setTimeout(later, wait);\n if (callNow) func.apply(this, args);\n };\n}\n\n/**\n * Return the entire parent tree of a node (from HTML down).\n * @param {Node} node\n * @return {Node[]}\n */\nfunction getPath(node: Node): Node[] {\n const path: Node[] = [node];\n while (node && node.nodeName.toLowerCase() !== 'html') {\n path.push(node.parentNode);\n node = node.parentNode;\n }\n if (!node || !node.parentNode) {\n return null;\n }\n return path.reverse();\n}\n\n/**\n * Find the common parent of an array of nodes.\n * @param {Node[]} nodes\n * @return {Node}\n */\nfunction getCommonParent(nodes: Node[]): Node {\n let path: Node[] | null;\n let nextPath: Node[] | null;\n if (nodes.length === 1) {\n return nodes.pop();\n }\n while (!path && nodes.length) {\n path = getPath(nodes.pop());\n }\n while (nodes.length) {\n nextPath = getPath(nodes.pop());\n if (nextPath) {\n path = path.filter((node: Node, index: number) => {\n return nextPath.length > index && nextPath[index] === node;\n });\n }\n }\n return path ? path[path.length - 1] : document;\n}\n\n/**\n * Log the axe result node to the console\n * @param {NodeResult} node\n * @param {Function} logFn console log function to use (error, warn, log, etc.)\n */\nfunction logElement(\n node: axeCore.NodeResult | axeCore.RelatedNode,\n logFn: (...args) => void\n): void {\n const el = document.querySelector(node.target.toString());\n if (!el) {\n logFn('Selector: %c%s', boldCourier, node.target.toString());\n } else {\n logFn('Element: %o', el);\n }\n}\n\n/**\n * Log the axe result node html tot he console\n * @param {NodeResult} node\n */\nfunction logHtml(node: axeCore.NodeResult | axeCore.RelatedNode): void {\n console.log('HTML: %c%s', boldCourier, node.html);\n}\n\n/**\n * Log the failure message of a node result.\n * @param {NodeResult} node\n * @param {String} key which check array to log from (any, all, none)\n */\nfunction logFailureMessage(\n node: axeCore.NodeResult,\n key: AxeCoreNodeResultKey\n): void {\n // this exists on axe but we don't export it as part of the typescript\n // namespace, so just let me use it as I need\n const message: string = (\n axeCore as unknown as AxeWithAudit\n )._audit.data.failureSummaries[key].failureMessage(\n node[key].map(check => check.message || '')\n );\n\n console.error(message);\n}\n\n/**\n * Log as a group the node result and failure message.\n * @param {NodeResult} node\n * @param {String} key which check array to log from (any, all, none)\n */\nfunction failureSummary(\n node: axeCore.NodeResult,\n key: AxeCoreNodeResultKey\n): void {\n if (node[key].length > 0) {\n logElement(node, console.groupCollapsed);\n logHtml(node);\n logFailureMessage(node, key);\n\n let relatedNodes: axeCore.RelatedNode[] = [];\n node[key].forEach(check => {\n relatedNodes = relatedNodes.concat(check.relatedNodes);\n });\n\n if (relatedNodes.length > 0) {\n console.groupCollapsed('Related nodes');\n relatedNodes.forEach(relatedNode => {\n logElement(relatedNode, console.log);\n logHtml(relatedNode);\n });\n console.groupEnd();\n }\n\n console.groupEnd();\n }\n}\n\n/**\n * Run axe against the passed in node and report violations\n * @param {*} node\n * @param {Number} timeout force call of axe.run after the timeout has passed (if not called before)\n * @return {Promise}\n */\nfunction checkAndReport(node: Node, timeout: number): Promise<void> {\n const disableDeduplicate = conf['disableDeduplicate'];\n\n if (idleId) {\n cancelIdleCallback(idleId);\n idleId = undefined;\n }\n\n return new Promise((resolve, reject) => {\n nodes.push(node);\n idleId = requestIdleCallback(\n () => {\n let n: axeCore.ElementContext | Node = context;\n if (n === undefined) {\n n = getCommonParent(nodes.filter(node => node.isConnected));\n if (n.nodeName.toLowerCase() === 'html') {\n // if the only common parent is the body, then analyze the whole page\n n = document;\n }\n }\n axeCore.configure({ allowedOrigins: ['<unsafe_all_origins>'] });\n axeCore.run(\n n,\n { reporter: 'v2' },\n function (error: Error, results: axeCore.AxeResults) {\n if (error) {\n return reject(error);\n }\n\n results.violations = results.violations.filter(result => {\n result.nodes = result.nodes.filter(node => {\n const key: string = node.target.toString() + result.id;\n const retVal = !cache.get(key);\n cache.set(key, key);\n return disableDeduplicate || retVal;\n });\n return !!result.nodes.length;\n });\n\n if (results.violations.length) {\n logger(results);\n }\n\n resolve();\n }\n );\n },\n {\n timeout: timeout\n }\n );\n });\n}\n\n/**\n * Check the node for violations.\n * @param {Component} component\n */\nfunction checkNode(component: React.Component): void {\n let node: Node;\n\n try {\n node = ReactDOM.findDOMNode(component);\n } catch (e) {\n console.group('%caxe error: could not check node', critical);\n console.group('%cComponent', serious);\n console.error(component);\n console.groupEnd();\n console.group('%cError', serious);\n console.error(e);\n console.groupEnd();\n console.groupEnd();\n }\n\n if (node) {\n checkAndReport(node, timeout);\n }\n}\n\n/**\n * Check the component for violations whenever the DOM updates\n * @param {Component} component\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction componentAfterRender(component: any): void {\n const debounceCheckNode: Function = debounce(checkNode, timeout, true);\n after(component, 'componentDidMount', debounceCheckNode);\n after(component, 'componentDidUpdate', debounceCheckNode);\n}\n\n/**\n * Add a component to track.\n * @param {Component} component\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction addComponent(component: any): void {\n const reactInstance = component._reactInternalInstance || {};\n const reactInstanceDebugID = reactInstance._debugID;\n const reactFiberInstance = component._reactInternalFiber || {};\n const reactFiberInstanceDebugID = reactFiberInstance._debugID;\n const reactInternals = component._reactInternals || {};\n const reactInternalsDebugID = reactInternals._debugID;\n\n if (reactInstanceDebugID && !components[reactInstanceDebugID]) {\n components[reactInstanceDebugID] = component;\n componentAfterRender(component);\n } else if (\n reactFiberInstanceDebugID &&\n !components[reactFiberInstanceDebugID]\n ) {\n components[reactFiberInstanceDebugID] = component;\n componentAfterRender(component);\n } else if (reactInternalsDebugID && !components[reactInternalsDebugID]) {\n components[reactInternalsDebugID] = component;\n componentAfterRender(component);\n }\n}\n\n/**\n * Log axe violations to console.\n * @param {AxeResults} results\n */\nfunction logToConsole(results: axeCore.AxeResults): void {\n console.group('%cNew axe issues', serious);\n results.violations.forEach(result => {\n let fmt: string;\n switch (result.impact) {\n case 'critical':\n fmt = critical;\n break;\n case 'serious':\n fmt = serious;\n break;\n case 'moderate':\n fmt = moderate;\n break;\n case 'minor':\n fmt = minor;\n break;\n default:\n fmt = minor;\n break;\n }\n console.groupCollapsed(\n '%c%s: %c%s %s',\n fmt,\n result.impact,\n defaultReset,\n result.help,\n result.helpUrl\n );\n result.nodes.forEach(node => {\n failureSummary(node, 'any');\n failureSummary(node, 'none');\n });\n console.groupEnd();\n });\n console.groupEnd();\n}\n\n/**\n * To support paramater of type runOnly\n */\ninterface ReactSpec extends axeCore.Spec {\n runOnly?: string[];\n disableDeduplicate?: boolean;\n}\n\n/**\n * Run axe against all changes made in a React app.\n * @parma {React} _React React instance\n * @param {ReactDOM} _ReactDOM ReactDOM instance\n * @param {Number} _timeout debounce timeout in milliseconds\n * @parma {Spec} conf React axe.configure Spec object\n * @param {ElementContext} _context axe ElementContent object\n * @param {Function} _logger Logger implementation\n */\nfunction reactAxe(\n _React: typeof React,\n _ReactDOM: typeof ReactDOM,\n _timeout: number,\n _conf = {} as ReactSpec,\n _context?: axeCore.ElementContext,\n _logger?: (results: axeCore.AxeResults) => void\n): Promise<void> {\n React = _React;\n ReactDOM = _ReactDOM;\n timeout = _timeout;\n context = _context;\n conf = _conf;\n logger = _logger || logToConsole;\n\n const runOnly = conf['runOnly'];\n if (runOnly) {\n conf['rules'] = axeCore\n .getRules(runOnly)\n .map(rule => ({ ...rule, id: rule.ruleId, enabled: true }));\n conf['disableOtherRules'] = true;\n }\n\n if (Object.keys(conf).length > 0) {\n axeCore.configure(conf);\n }\n axeCore.configure({ allowedOrigins: ['<unsafe_all_origins>'] });\n if (!_createElement) {\n _createElement = React.createElement;\n\n React.createElement = function (...args): React.Component {\n const reactEl = _createElement.apply(this, args);\n\n if (reactEl._owner && reactEl._owner._instance) {\n addComponent(reactEl._owner._instance);\n } else if (reactEl._owner && reactEl._owner.stateNode) {\n addComponent(reactEl._owner.stateNode);\n }\n\n return reactEl;\n };\n }\n\n return checkAndReport(document.body, timeout);\n}\n\nexport = reactAxe;\n"]}