accented 0.0.1-dev.1 → 0.0.1-dev.2
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/accented.d.ts +6 -0
- package/dist/accented.d.ts.map +1 -0
- package/dist/accented.js +39 -0
- package/dist/accented.js.map +1 -0
- package/dist/dom-updater.d.ts +7 -0
- package/dist/dom-updater.d.ts.map +1 -0
- package/dist/dom-updater.js +28 -0
- package/dist/dom-updater.js.map +1 -0
- package/dist/task-queue.d.ts +11 -0
- package/dist/task-queue.d.ts.map +1 -0
- package/dist/task-queue.js +29 -0
- package/dist/task-queue.js.map +1 -0
- package/dist/utils/issuesToElements.d.ts +3 -0
- package/dist/utils/issuesToElements.d.ts.map +1 -0
- package/dist/utils/issuesToElements.js +17 -0
- package/dist/utils/issuesToElements.js.map +1 -0
- package/package.json +5 -3
- package/src/accented.js +0 -31
- package/src/task-queue.js +0 -37
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accented.d.ts","sourceRoot":"","sources":["../src/accented.ts"],"names":[],"mappings":"AAKA,KAAK,aAAa,GAAG;IACnB,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B,CAAC;AAMF,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,KAAK,GAAE,aAAkB,QAuCzD"}
|
package/dist/accented.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import axe from 'axe-core';
|
|
2
|
+
import TaskQueue from './task-queue';
|
|
3
|
+
import DomUpdater from './dom-updater';
|
|
4
|
+
import issuesToElements from './utils/issuesToElements';
|
|
5
|
+
const defaultProps = {
|
|
6
|
+
outputToConsole: true
|
|
7
|
+
};
|
|
8
|
+
export default function accented(props = {}) {
|
|
9
|
+
const { outputToConsole } = { ...defaultProps, ...props };
|
|
10
|
+
const domUpdater = new DomUpdater();
|
|
11
|
+
const taskQueue = new TaskQueue(async () => {
|
|
12
|
+
performance.mark('axe-start');
|
|
13
|
+
const result = await axe.run();
|
|
14
|
+
const axeMeasure = performance.measure('axe', 'axe-start');
|
|
15
|
+
const elements = issuesToElements(result.violations);
|
|
16
|
+
domUpdater.update(elements);
|
|
17
|
+
if (outputToConsole) {
|
|
18
|
+
console.log('Result:', result);
|
|
19
|
+
}
|
|
20
|
+
console.log('Axe run duration:', Math.round(axeMeasure.duration), 'ms');
|
|
21
|
+
});
|
|
22
|
+
taskQueue.add(document);
|
|
23
|
+
const mutationObserver = new MutationObserver(mutationList => {
|
|
24
|
+
// TODO: filter out irrelevant mutations
|
|
25
|
+
for (const mutationRecord of mutationList) {
|
|
26
|
+
if (mutationRecord.type === 'attributes' && mutationRecord.attributeName === 'data-accented') {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
taskQueue.add(mutationRecord.target);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
// TODO: read more about the params and decide which ones we need.
|
|
33
|
+
mutationObserver.observe(document, {
|
|
34
|
+
subtree: true,
|
|
35
|
+
childList: true,
|
|
36
|
+
attributes: true
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=accented.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accented.js","sourceRoot":"","sources":["../src/accented.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,UAAU,MAAM,eAAe,CAAC;AACvC,OAAO,gBAAgB,MAAM,0BAA0B,CAAC;AAMxD,MAAM,YAAY,GAA4B;IAC5C,eAAe,EAAE,IAAI;CACtB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,QAAuB,EAAE;IACxD,MAAM,EAAC,eAAe,EAAC,GAAG,EAAC,GAAG,YAAY,EAAE,GAAG,KAAK,EAAC,CAAC;IAEtD,MAAM,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC;IAEpC,MAAM,SAAS,GAA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ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,OAAO,UAAU;;IAC7B,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAAM;;IAM9B,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC;CAqBnC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const attrName = 'data-accented';
|
|
2
|
+
export default class DomUpdater {
|
|
3
|
+
elements = [];
|
|
4
|
+
constructor() {
|
|
5
|
+
this.#addStylesheetToDocument();
|
|
6
|
+
}
|
|
7
|
+
update(newElements) {
|
|
8
|
+
for (const element of this.elements) {
|
|
9
|
+
element.removeAttribute(attrName);
|
|
10
|
+
}
|
|
11
|
+
this.elements = [...newElements];
|
|
12
|
+
for (const element of this.elements) {
|
|
13
|
+
element.setAttribute(attrName, '');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
#addStylesheetToDocument() {
|
|
17
|
+
// TODO: is this the preferred way of adding a stylesheet?
|
|
18
|
+
const styleElement = document.createElement('style');
|
|
19
|
+
styleElement.innerText = `
|
|
20
|
+
[${attrName}]:not(:focus-visible) {
|
|
21
|
+
outline: 2px solid red !important;
|
|
22
|
+
outline-offset: -2px;
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
document.head.appendChild(styleElement);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=dom-updater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom-updater.js","sourceRoot":"","sources":["../src/dom-updater.ts"],"names":[],"mappings":"AAAA,MAAM,QAAQ,GAAG,eAAe,CAAC;AAEjC,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,QAAQ,GAAmB,EAAE,CAAC;IAE9B;QACE,IAAI,CAAC,wBAAwB,EAAE,CAAC;IAClC,CAAC;IAED,MAAM,CAAC,WAA2B;QAChC,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACpC,OAAO,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QACpC,CAAC;QACD,IAAI,CAAC,QAAQ,GAAG,CAAC,GAAG,WAAW,CAAC,CAAC;QACjC,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACpC,OAAO,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IAED,wBAAwB;QACtB,0DAA0D;QAC1D,MAAM,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACrD,YAAY,CAAC,SAAS,GAAG;SACpB,QAAQ;;;;KAIZ,CAAC;QACF,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IAC1C,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type TaskCallback = () => void;
|
|
2
|
+
export default class TaskQueue<T> {
|
|
3
|
+
#private;
|
|
4
|
+
items: Set<T>;
|
|
5
|
+
idleCallbackId: number | null;
|
|
6
|
+
asyncCallback: TaskCallback | null;
|
|
7
|
+
constructor(asyncCallback: TaskCallback);
|
|
8
|
+
add(item: T): void;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=task-queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-queue.d.ts","sourceRoot":"","sources":["../src/task-queue.ts"],"names":[],"mappings":"AAAA,KAAK,YAAY,GAAG,MAAM,IAAI,CAAC;AAG/B,MAAM,CAAC,OAAO,OAAO,SAAS,CAAC,CAAC;;IAC9B,KAAK,SAAgB;IAErB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAQ;IAErC,aAAa,EAAE,YAAY,GAAG,IAAI,CAAQ;gBAE9B,aAAa,EAAE,YAAY;IA0BvC,GAAG,CAAC,IAAI,EAAE,CAAC;CAIZ"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// TODO: add generic typing
|
|
2
|
+
export default class TaskQueue {
|
|
3
|
+
items = new Set();
|
|
4
|
+
idleCallbackId = null;
|
|
5
|
+
asyncCallback = null;
|
|
6
|
+
constructor(asyncCallback) {
|
|
7
|
+
this.asyncCallback = asyncCallback;
|
|
8
|
+
}
|
|
9
|
+
// TODO: test all the asynchronicity
|
|
10
|
+
#scheduleRun() {
|
|
11
|
+
if (this.idleCallbackId !== null || this.items.size === 0) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
this.idleCallbackId = requestIdleCallback(() => this.#run());
|
|
15
|
+
}
|
|
16
|
+
async #run() {
|
|
17
|
+
this.items.clear();
|
|
18
|
+
if (this.asyncCallback) {
|
|
19
|
+
await this.asyncCallback();
|
|
20
|
+
}
|
|
21
|
+
this.idleCallbackId = null;
|
|
22
|
+
this.#scheduleRun();
|
|
23
|
+
}
|
|
24
|
+
add(item) {
|
|
25
|
+
this.items.add(item);
|
|
26
|
+
this.#scheduleRun();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=task-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-queue.js","sourceRoot":"","sources":["../src/task-queue.ts"],"names":[],"mappings":"AAEA,2BAA2B;AAC3B,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,KAAK,GAAG,IAAI,GAAG,EAAK,CAAC;IAErB,cAAc,GAAkB,IAAI,CAAC;IAErC,aAAa,GAAwB,IAAI,CAAC;IAE1C,YAAY,aAA2B;QACrC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAED,oCAAoC;IAEpC,YAAY;QACV,IAAI,IAAI,CAAC,cAAc,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YAC1D,OAAO;QACT,CAAC;QAED,IAAI,CAAC,cAAc,GAAG,mBAAmB,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAC/D,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QAEnB,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACvB,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QAC7B,CAAC;QAED,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAE3B,IAAI,CAAC,YAAY,EAAE,CAAC;IACtB,CAAC;IAED,GAAG,CAAC,IAAO;QACT,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACrB,IAAI,CAAC,YAAY,EAAE,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"issuesToElements.d.ts","sourceRoot":"","sources":["../../src/utils/issuesToElements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,MAAM,EAAE,OAAO,UAAU,CAAC,UAAU,aAgB5E"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AxeResults } from 'axe-core';
|
|
2
|
+
export default function issuesToElements(issues) {
|
|
3
|
+
const elements = new Set();
|
|
4
|
+
for (const issue of issues) {
|
|
5
|
+
for (const node of issue.nodes) {
|
|
6
|
+
// TODO: how to make this easier / more reliable?
|
|
7
|
+
if (typeof node.target[0] === 'string') {
|
|
8
|
+
const element = document.querySelector(node.target[0]);
|
|
9
|
+
if (element) {
|
|
10
|
+
elements.add(element);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return [...elements];
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=issuesToElements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"issuesToElements.js","sourceRoot":"","sources":["../../src/utils/issuesToElements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,MAAoC;IAC3E,MAAM,QAAQ,GAAiB,IAAI,GAAG,EAAE,CAAC;IAEzC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YAC/B,iDAAiD;YACjD,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;gBACvC,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;gBACvD,IAAI,OAAO,EAAE,CAAC;oBACZ,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;gBACxB,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC;AACvB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "accented",
|
|
3
|
-
"version": "0.0.1-dev.
|
|
3
|
+
"version": "0.0.1-dev.2",
|
|
4
4
|
"description": "Continuous accessibility testing and issue highlighting for web development",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "dist/accented.js",
|
|
6
6
|
"files": [
|
|
7
|
-
"
|
|
7
|
+
"dist"
|
|
8
8
|
],
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
"axe-core": "^4.10.2"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
|
+
"build": "tsc",
|
|
30
|
+
"watch": "tsc --watch",
|
|
29
31
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
30
32
|
}
|
|
31
33
|
}
|
package/src/accented.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import axe from 'axe-core';
|
|
2
|
-
import TaskQueue from './task-queue.js';
|
|
3
|
-
|
|
4
|
-
export default function accented() {
|
|
5
|
-
const taskQueue = new TaskQueue(async () => {
|
|
6
|
-
performance.mark('axe-start');
|
|
7
|
-
|
|
8
|
-
const result = await axe.run();
|
|
9
|
-
|
|
10
|
-
const axeMeasure = performance.measure('axe', 'axe-start');
|
|
11
|
-
|
|
12
|
-
console.log('Result:', result);
|
|
13
|
-
console.log('Axe run duration:', Math.round(axeMeasure.duration), 'ms');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
taskQueue.add(document);
|
|
17
|
-
|
|
18
|
-
const mutationObserver = new MutationObserver(mutationList => {
|
|
19
|
-
// TODO: filter out irrelevant mutations
|
|
20
|
-
for (const mutationRecord of mutationList) {
|
|
21
|
-
taskQueue.add(mutationRecord.target);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
// TODO: read more about the params and decide which ones we need.
|
|
26
|
-
mutationObserver.observe(document, {
|
|
27
|
-
subtree: true,
|
|
28
|
-
childList: true,
|
|
29
|
-
attributes: true
|
|
30
|
-
});
|
|
31
|
-
}
|
package/src/task-queue.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// TODO: add generic typing
|
|
2
|
-
export default class TaskQueue {
|
|
3
|
-
items = new Set();
|
|
4
|
-
|
|
5
|
-
idleCallbackId = null;
|
|
6
|
-
|
|
7
|
-
asyncCallback = null;
|
|
8
|
-
|
|
9
|
-
constructor(asyncCallback) {
|
|
10
|
-
this.asyncCallback = asyncCallback;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// TODO: test all the asynchronicity
|
|
14
|
-
|
|
15
|
-
#scheduleRun() {
|
|
16
|
-
if (this.idleCallbackId !== null || this.items.size === 0) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
this.idleCallbackId = requestIdleCallback(() => this.#run());
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async #run() {
|
|
24
|
-
this.items.clear();
|
|
25
|
-
|
|
26
|
-
await this.asyncCallback();
|
|
27
|
-
|
|
28
|
-
this.idleCallbackId = null;
|
|
29
|
-
|
|
30
|
-
this.#scheduleRun();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
add(item) {
|
|
34
|
-
this.items.add(item);
|
|
35
|
-
this.#scheduleRun();
|
|
36
|
-
}
|
|
37
|
-
}
|