accented 0.0.1-dev.0 → 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.
@@ -0,0 +1,6 @@
1
+ type AccentedProps = {
2
+ outputToConsole?: boolean;
3
+ };
4
+ export default function accented(props?: AccentedProps): void;
5
+ export {};
6
+ //# sourceMappingURL=accented.d.ts.map
@@ -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"}
@@ -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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,IAAI,gBAAgB,CAAC,YAAY,CAAC,EAAE;QAC3D,wCAAwC;QACxC,KAAK,MAAM,cAAc,IAAI,YAAY,EAAE,CAAC;YAC1C,IAAI,cAAc,CAAC,IAAI,KAAK,YAAY,IAAI,cAAc,CAAC,aAAa,KAAK,eAAe,EAAE,CAAC;gBAC7F,SAAS;YACX,CAAC;YACD,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QACvC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,kEAAkE;IAClE,gBAAgB,CAAC,OAAO,CAAC,QAAQ,EAAE;QACjC,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;QACf,UAAU,EAAE,IAAI;KACjB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,7 @@
1
+ export default class DomUpdater {
2
+ #private;
3
+ elements: Array<Element>;
4
+ constructor();
5
+ update(newElements: Array<Element>): void;
6
+ }
7
+ //# sourceMappingURL=dom-updater.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom-updater.d.ts","sourceRoot":"","sources":["../src/dom-updater.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,3 @@
1
+ import { AxeResults } from 'axe-core';
2
+ export default function issuesToElements(issues: typeof AxeResults.violations): Element[];
3
+ //# sourceMappingURL=issuesToElements.d.ts.map
@@ -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,12 +1,11 @@
1
1
  {
2
2
  "name": "accented",
3
- "version": "0.0.1-dev.0",
3
+ "version": "0.0.1-dev.2",
4
4
  "description": "Continuous accessibility testing and issue highlighting for web development",
5
- "main": "src/accented.js",
6
- "files": ["src"],
7
- "scripts": {
8
- "test": "echo \"Error: no test specified\" && exit 1"
9
- },
5
+ "main": "dist/accented.js",
6
+ "files": [
7
+ "dist"
8
+ ],
10
9
  "repository": {
11
10
  "type": "git",
12
11
  "url": "git+https://github.com/pomerantsev/accented.git"
@@ -25,5 +24,10 @@
25
24
  "homepage": "https://github.com/pomerantsev/accented#readme",
26
25
  "dependencies": {
27
26
  "axe-core": "^4.10.2"
27
+ },
28
+ "scripts": {
29
+ "build": "tsc",
30
+ "watch": "tsc --watch",
31
+ "test": "echo \"Error: no test specified\" && exit 1"
28
32
  }
29
- }
33
+ }
package/README.md DELETED
@@ -1,23 +0,0 @@
1
- # Accented
2
-
3
- Continuous accessibility testing and issue highlighting for web development
4
-
5
- This is a work in progress.
6
-
7
- ## High-level
8
-
9
- * Uses axe-core.
10
-
11
- ## Running locally
12
-
13
- * `npx http-server`
14
-
15
- ## Usage notes
16
-
17
- * On a page with many elements, axe-core may be slow. We may deal with this in two ways:
18
- * First, we'll ensure that we only scan the elements that changed.
19
- * Second, we'll see if it's possible to modify axe-core so it yields execution at certain intervals.
20
-
21
- ## Development notes
22
-
23
- * Placeholder favicon generated with https://favicon.io/favicon-generator/. I immediately forgot what the font was, but I won't relese this like this anyway.
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
- }