@stackoverflow/stacks 2.0.1 → 2.0.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/css/stacks.css +5 -5
- package/dist/css/stacks.min.css +1 -1
- package/lib/components/empty-state/empty-state.a11y.test.ts +17 -0
- package/lib/components/empty-state/empty-state.visual.test.ts +17 -0
- package/lib/components/progress-bar/progress-bar.a11y.test.ts +200 -0
- package/lib/components/progress-bar/progress-bar.visual.test.ts +199 -0
- package/lib/components/table/table.a11y.test.ts +113 -0
- package/lib/components/table/table.visual.test.ts +105 -0
- package/lib/exports/__snapshots__/color-mixins.less.test.ts.snap +2 -2
- package/lib/exports/__snapshots__/color.less.test.ts.snap +4 -4
- package/lib/exports/color-sets.less +4 -4
- package/lib/test/test-utils.ts +1 -1
- package/package.json +7 -7
- package/lib/test/axe-apca/README.md +0 -53
- package/lib/test/axe-apca/index.ts +0 -3
- package/lib/test/axe-apca/package.wip.json +0 -30
- package/lib/test/axe-apca/src/apca-w3.d.ts +0 -3
- package/lib/test/axe-apca/src/axe-apca.test.ts +0 -231
- package/lib/test/axe-apca/src/axe-apca.ts +0 -220
|
@@ -104,10 +104,10 @@ body:not(.theme-highcontrast).theme-system .theme-light__forced .themed {
|
|
|
104
104
|
--green-600: hsl(148, 75%, 15%);
|
|
105
105
|
--red-100: hsl(0, 72%, 96%);
|
|
106
106
|
--red-200: hsl(0, 70%, 93%);
|
|
107
|
-
--red-300: hsl(0,
|
|
107
|
+
--red-300: hsl(0, 66%, 80%);
|
|
108
108
|
--red-400: hsl(0, 60%, 49%);
|
|
109
109
|
--red-500: hsl(0, 65%, 37%);
|
|
110
|
-
--red-600: hsl(0, 65%,
|
|
110
|
+
--red-600: hsl(0, 65%, 22%);
|
|
111
111
|
--yellow-100: hsl(43, 80%, 96%);
|
|
112
112
|
--yellow-200: hsl(43, 80%, 88%);
|
|
113
113
|
--yellow-300: hsl(43, 85%, 72%);
|
|
@@ -483,8 +483,8 @@ body.theme-highcontrast.theme-system .theme-light__forced {
|
|
|
483
483
|
--red-200: hsl(0, 80%, 96%);
|
|
484
484
|
--red-300: hsl(0, 60%, 49%);
|
|
485
485
|
--red-400: hsl(0, 65%, 37%);
|
|
486
|
-
--red-500: hsl(0,
|
|
487
|
-
--red-600: hsl(0,
|
|
486
|
+
--red-500: hsl(0, 65%, 22%);
|
|
487
|
+
--red-600: hsl(0, 65%, 22%);
|
|
488
488
|
--yellow-100: hsl(41, 80%, 96%);
|
|
489
489
|
--yellow-200: hsl(41, 80%, 96%);
|
|
490
490
|
--yellow-300: hsl(43, 85%, 50%);
|
|
@@ -190,10 +190,10 @@
|
|
|
190
190
|
.set-red() {
|
|
191
191
|
100: hsl(0, 72%, 96%);
|
|
192
192
|
200: hsl(0, 70%, 93%);
|
|
193
|
-
300: hsl(0,
|
|
193
|
+
300: hsl(0, 66%, 80%);
|
|
194
194
|
400: hsl(0, 60%, 49%);
|
|
195
195
|
500: hsl(0, 65%, 37%);
|
|
196
|
-
600: hsl(0, 65%,
|
|
196
|
+
600: hsl(0, 65%, 22%);
|
|
197
197
|
}
|
|
198
198
|
.set-red-dark() {
|
|
199
199
|
100: hsl(358, 29%, 19%);
|
|
@@ -208,8 +208,8 @@
|
|
|
208
208
|
200: hsl(0, 80%, 96%);
|
|
209
209
|
300: hsl(0, 60%, 49%);
|
|
210
210
|
400: hsl(0, 65%, 37%);
|
|
211
|
-
500: hsl(0,
|
|
212
|
-
600: hsl(0,
|
|
211
|
+
500: hsl(0, 65%, 22%);
|
|
212
|
+
600: hsl(0, 65%, 22%);
|
|
213
213
|
}
|
|
214
214
|
.set-red-hc-dark() {
|
|
215
215
|
100: hsl(358, 30%, 19%);
|
package/lib/test/test-utils.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { screen } from "@testing-library/dom";
|
|
|
3
3
|
import { visualDiff } from "@web/test-runner-visual-regression";
|
|
4
4
|
import type { TemplateResult } from "lit-html";
|
|
5
5
|
import axe from "axe-core";
|
|
6
|
-
import registerAxeAPCA from "
|
|
6
|
+
import registerAxeAPCA from "axe-apca";
|
|
7
7
|
|
|
8
8
|
const customConformanceThresholdFn = (fontSize: string): number | null => {
|
|
9
9
|
return parseFloat(fontSize) >= 32 ? 45 : 60;
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/StackExchange/Stacks.git"
|
|
7
7
|
},
|
|
8
|
-
"version": "2.0.
|
|
8
|
+
"version": "2.0.2",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist",
|
|
11
11
|
"lib"
|
|
@@ -44,24 +44,24 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@11ty/eleventy": "^2.0.1",
|
|
47
|
-
"@highlightjs/cdn-assets": "^11.
|
|
47
|
+
"@highlightjs/cdn-assets": "^11.9.0",
|
|
48
48
|
"@open-wc/testing": "^3.2.0",
|
|
49
49
|
"@rollup/plugin-commonjs": "^25.0.4",
|
|
50
|
-
"@rollup/plugin-replace": "^5.0.
|
|
51
|
-
"@stackoverflow/stacks-editor": "^0.
|
|
50
|
+
"@rollup/plugin-replace": "^5.0.4",
|
|
51
|
+
"@stackoverflow/stacks-editor": "^0.9.0",
|
|
52
52
|
"@stackoverflow/stacks-icons": "^6.0.0",
|
|
53
53
|
"@testing-library/dom": "^9.3.3",
|
|
54
54
|
"@testing-library/user-event": "^14.5.1",
|
|
55
55
|
"@types/cssbeautify": "^0.3.2",
|
|
56
56
|
"@types/less": "^3.0.3",
|
|
57
57
|
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
|
58
|
-
"@typescript-eslint/parser": "^6.7.
|
|
58
|
+
"@typescript-eslint/parser": "^6.7.5",
|
|
59
59
|
"@web/dev-server-esbuild": "^0.4.1",
|
|
60
60
|
"@web/dev-server-rollup": "^0.5.2",
|
|
61
61
|
"@web/test-runner": "^0.17.1",
|
|
62
62
|
"@web/test-runner-playwright": "^0.10.1",
|
|
63
63
|
"@web/test-runner-visual-regression": "^0.8.2",
|
|
64
|
-
"apca
|
|
64
|
+
"axe-apca": "^0.0.3",
|
|
65
65
|
"concurrently": "^8.2.1",
|
|
66
66
|
"css-loader": "^6.8.1",
|
|
67
67
|
"cssbeautify": "^0.3.1",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"stylelint-config-recommended": "^13.0.0",
|
|
86
86
|
"stylelint-config-standard": "^34.0.0",
|
|
87
87
|
"terser-webpack-plugin": "^5.3.9",
|
|
88
|
-
"ts-loader": "^9.
|
|
88
|
+
"ts-loader": "^9.5.0",
|
|
89
89
|
"typescript": "^5.2.2",
|
|
90
90
|
"vitest": "^0.33.0",
|
|
91
91
|
"webpack": "^5.88.2",
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# axe-apca
|
|
2
|
-
|
|
3
|
-
⚠️ *Once this package become more mature and stable it should be extracted in its own repo (e.g. StackExchange/axe-apca) and published as an npm package. This will allow to use the rule/checks in many contexts including our Core codebase.*
|
|
4
|
-
|
|
5
|
-
This package contains custom axe rules and checks for [APCA](https://readtech.org/) Bronze and Silver+ [conformance levels](https://readtech.org/ARC/tests/visual-readability-contrast/?tn=criterion).
|
|
6
|
-
|
|
7
|
-
## Usage
|
|
8
|
-
|
|
9
|
-
### Installation
|
|
10
|
-
|
|
11
|
-
⚠️ *The following command doesn't work because this package is not published on npm yet.*
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
npm install --save-dev axe-core axe-apca
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
### Setup
|
|
18
|
-
|
|
19
|
-
```js
|
|
20
|
-
import axe from "axe-core";
|
|
21
|
-
import { registerAxeAPCA } from 'axe-apca';
|
|
22
|
-
|
|
23
|
-
registerAxeAPCA('bronze'); // or registerAxeAPCA('silver');
|
|
24
|
-
|
|
25
|
-
// consider turning off default WCAG 2.1 AA color contrast rules when using APCA
|
|
26
|
-
axe.configure({
|
|
27
|
-
rules: [{ id: "color-contrast", enabled: false }]
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
axe.run(document, (err, results) => {
|
|
31
|
-
if (err) throw err;
|
|
32
|
-
console.log(results);
|
|
33
|
-
});
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
### Using custom APCA thresholds
|
|
37
|
-
|
|
38
|
-
To set custom thresholds for APCA checks, follow these steps:
|
|
39
|
-
|
|
40
|
-
1. Use `custom` as the first argument when calling `registerAxeAPCA`.
|
|
41
|
-
1. Provide a function as the second argument, optionally accepting `fontSize` and `fontWeight` arguments.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
```js
|
|
45
|
-
const customConformanceThresholdFn = (fontSize, fontWeight) => {
|
|
46
|
-
const size = parseFloat(fontSize);
|
|
47
|
-
const weight = parseFloat(fontWeight);
|
|
48
|
-
|
|
49
|
-
return size >= 32 || weight > 700 ? 45 : 60;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
registerAxeAPCA('custom', customConformanceThresholdFn);
|
|
53
|
-
```
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "axe-apca",
|
|
3
|
-
"description": "Axe rules to check against APCA bronze and silver+ conformance levels.",
|
|
4
|
-
"repository": {
|
|
5
|
-
"type": "git",
|
|
6
|
-
"url": "https://github.com/StackExchange/axe-apca.git"
|
|
7
|
-
},
|
|
8
|
-
"version": "0.0.0",
|
|
9
|
-
"main": "TODO",
|
|
10
|
-
"types": "TODO",
|
|
11
|
-
"scripts": {
|
|
12
|
-
"build": "TODO: transpile ts to js",
|
|
13
|
-
"test": "web-test-runner"
|
|
14
|
-
},
|
|
15
|
-
"license": "MIT",
|
|
16
|
-
"dependencies": {
|
|
17
|
-
"apca-w3": "^0.1.9"
|
|
18
|
-
},
|
|
19
|
-
"peerDependencies": {
|
|
20
|
-
"axe-core": "^4.0.0"
|
|
21
|
-
},
|
|
22
|
-
"devDependencies": {
|
|
23
|
-
"@open-wc/testing": "^3.2.0",
|
|
24
|
-
"@web/dev-server-esbuild": "^0.4.1",
|
|
25
|
-
"@web/dev-server-rollup": "^0.5.2",
|
|
26
|
-
"@web/test-runner": "^0.16.1",
|
|
27
|
-
"@web/test-runner-playwright": "^0.10.1",
|
|
28
|
-
"typescript": "^5.1.6"
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import { html, fixture, expect } from "@open-wc/testing";
|
|
2
|
-
import axe from "axe-core";
|
|
3
|
-
import type { AxeResults } from "axe-core";
|
|
4
|
-
import registerAxeAPCA from "./axe-apca";
|
|
5
|
-
|
|
6
|
-
const runAxe = async (el: HTMLElement): Promise<AxeResults> => {
|
|
7
|
-
return new Promise((resolve, reject) => {
|
|
8
|
-
axe.run(el, (err, results) => {
|
|
9
|
-
if (err) reject(err);
|
|
10
|
-
resolve(results);
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
describe("axe-apca", () => {
|
|
16
|
-
describe("custom conformance level", () => {
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
const customConformanceThresholdFn = (
|
|
19
|
-
fontSize: string
|
|
20
|
-
): number | null => {
|
|
21
|
-
return parseFloat(fontSize) >= 32 ? 45 : 60;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
registerAxeAPCA("custom", customConformanceThresholdFn);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("should check for APCA accessibility contrast violations", async () => {
|
|
28
|
-
const el: HTMLElement = await fixture(
|
|
29
|
-
html`<p
|
|
30
|
-
style="background: white; color: black; font-size: 12px; font-weight: 400;"
|
|
31
|
-
>
|
|
32
|
-
Some copy
|
|
33
|
-
</p>`
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
const results = await runAxe(el);
|
|
37
|
-
|
|
38
|
-
const apcaPasses = results.passes.filter((violation) =>
|
|
39
|
-
violation.id.includes("color-contrast-apca-custom")
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
await expect(apcaPasses.length).to.equal(1);
|
|
43
|
-
|
|
44
|
-
const passNode = apcaPasses[0].nodes[0];
|
|
45
|
-
expect(passNode.all[0].message).to.include(
|
|
46
|
-
"Element has sufficient APCA custom level lightness contrast"
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("should detect APCA accessibility contrast violations", async () => {
|
|
51
|
-
const el: HTMLElement = await fixture(
|
|
52
|
-
html`<p
|
|
53
|
-
style="background: white; color: lightgray; font-size: 12px; font-weight: 400;"
|
|
54
|
-
>
|
|
55
|
-
Some copy
|
|
56
|
-
</p>`
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
const results = await runAxe(el);
|
|
60
|
-
|
|
61
|
-
const apcaViolations = results.violations.filter((violation) =>
|
|
62
|
-
violation.id.includes("color-contrast-apca-custom")
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
await expect(apcaViolations.length).to.equal(1);
|
|
66
|
-
|
|
67
|
-
const violationNode = apcaViolations[0].nodes[0];
|
|
68
|
-
expect(violationNode.failureSummary).to.include(
|
|
69
|
-
"Element has insufficient APCA custom level contrast"
|
|
70
|
-
);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("should check nested nodes", async () => {
|
|
74
|
-
const el: HTMLElement = await fixture(
|
|
75
|
-
html`<div style="background: black;">
|
|
76
|
-
<h2>Some title</h2>
|
|
77
|
-
<p>Some copy</p>
|
|
78
|
-
<button style="background: black;">Some button</button>
|
|
79
|
-
</div>`
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
const results = await runAxe(el);
|
|
83
|
-
|
|
84
|
-
const apcaViolations = results.violations.filter((violation) =>
|
|
85
|
-
violation.id.includes("color-contrast-apca-custom")
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
await expect(apcaViolations[0].nodes.length).to.equal(3);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
describe("bronze conformance level", () => {
|
|
93
|
-
beforeEach(() => {
|
|
94
|
-
registerAxeAPCA("bronze");
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it("should check for APCA accessibility contrast violations", async () => {
|
|
98
|
-
const el: HTMLElement = await fixture(
|
|
99
|
-
html`<p
|
|
100
|
-
style="background: white; color: black; font-size: 12px; font-weight: 400;"
|
|
101
|
-
>
|
|
102
|
-
Some copy
|
|
103
|
-
</p>`
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
const results = await runAxe(el);
|
|
107
|
-
|
|
108
|
-
const apcaPasses = results.passes.filter((violation) =>
|
|
109
|
-
violation.id.includes("color-contrast-apca-bronze")
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
await expect(apcaPasses.length).to.equal(1);
|
|
113
|
-
|
|
114
|
-
const passNode = apcaPasses[0].nodes[0];
|
|
115
|
-
expect(passNode.all[0].message).to.include(
|
|
116
|
-
"Element has sufficient APCA bronze level lightness contrast"
|
|
117
|
-
);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("should detect APCA accessibility contrast violations", async () => {
|
|
121
|
-
const el: HTMLElement = await fixture(
|
|
122
|
-
html`<p
|
|
123
|
-
style="background: white; color: gray; font-size: 12px; font-weight: 400;"
|
|
124
|
-
>
|
|
125
|
-
Some copy
|
|
126
|
-
</p>`
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
const results = await runAxe(el);
|
|
130
|
-
|
|
131
|
-
const apcaViolations = results.violations.filter((violation) =>
|
|
132
|
-
violation.id.includes("color-contrast-apca-bronze")
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
await expect(apcaViolations.length).to.equal(1);
|
|
136
|
-
|
|
137
|
-
const violationNode = apcaViolations[0].nodes[0];
|
|
138
|
-
expect(violationNode.failureSummary).to.include(
|
|
139
|
-
"Element has insufficient APCA bronze level contrast"
|
|
140
|
-
);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it("should check nested nodes", async () => {
|
|
144
|
-
const el: HTMLElement = await fixture(
|
|
145
|
-
html`<div style="background: black;">
|
|
146
|
-
<h2>Some title</h2>
|
|
147
|
-
<p>Some copy</p>
|
|
148
|
-
<button style="background: black;">Some button</button>
|
|
149
|
-
</div>`
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
const results = await runAxe(el);
|
|
153
|
-
|
|
154
|
-
const apcaViolations = results.violations.filter((violation) =>
|
|
155
|
-
violation.id.includes("color-contrast-apca-bronze")
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
await expect(apcaViolations[0].nodes.length).to.equal(3);
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
describe("silver conformance level", () => {
|
|
163
|
-
beforeEach(() => {
|
|
164
|
-
registerAxeAPCA("silver");
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it("should check for APCA accessibility contrast violations", async () => {
|
|
168
|
-
const el: HTMLElement = await fixture(
|
|
169
|
-
html`<p
|
|
170
|
-
style="background: white; color: black; font-size: 14px; font-weight: 400;"
|
|
171
|
-
>
|
|
172
|
-
Some copy
|
|
173
|
-
</p>`
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
const results = await runAxe(el);
|
|
177
|
-
|
|
178
|
-
const apcaPasses = results.passes.filter((violation) =>
|
|
179
|
-
violation.id.includes("color-contrast-apca-silver")
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
await expect(apcaPasses.length).to.equal(1);
|
|
183
|
-
|
|
184
|
-
const passNode = apcaPasses[0].nodes[0];
|
|
185
|
-
expect(passNode.all[0].message).to.include(
|
|
186
|
-
"Element has sufficient APCA silver level lightness contrast"
|
|
187
|
-
);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it("should detect APCA accessibility contrast violations", async () => {
|
|
191
|
-
const el: HTMLElement = await fixture(
|
|
192
|
-
html`<p
|
|
193
|
-
style="background: white; color: black; font-size: 12px; font-weight: 400;"
|
|
194
|
-
>
|
|
195
|
-
Some copy
|
|
196
|
-
</p>`
|
|
197
|
-
);
|
|
198
|
-
|
|
199
|
-
const results = await runAxe(el);
|
|
200
|
-
|
|
201
|
-
const apcaViolations = results.violations.filter((violation) =>
|
|
202
|
-
violation.id.includes("color-contrast-apca-silver")
|
|
203
|
-
);
|
|
204
|
-
|
|
205
|
-
await expect(apcaViolations.length).to.equal(1);
|
|
206
|
-
|
|
207
|
-
const violationNode = apcaViolations[0].nodes[0];
|
|
208
|
-
expect(violationNode.failureSummary).to.include(
|
|
209
|
-
"Element has insufficient APCA silver level contrast"
|
|
210
|
-
);
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
it("should check nested nodes", async () => {
|
|
214
|
-
const el: HTMLElement = await fixture(
|
|
215
|
-
html`<div style="background: black;">
|
|
216
|
-
<h2>Some title</h2>
|
|
217
|
-
<p>Some copy</p>
|
|
218
|
-
<button style="background: black;">Some button</button>
|
|
219
|
-
</div>`
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
const results = await runAxe(el);
|
|
223
|
-
|
|
224
|
-
const apcaViolations = results.violations.filter((violation) =>
|
|
225
|
-
violation.id.includes("color-contrast-apca-silver")
|
|
226
|
-
);
|
|
227
|
-
|
|
228
|
-
await expect(apcaViolations[0].nodes.length).to.equal(3);
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
});
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import { calcAPCA } from "apca-w3";
|
|
2
|
-
import axe from "axe-core";
|
|
3
|
-
import type { Check, Rule } from "axe-core";
|
|
4
|
-
|
|
5
|
-
// Augment Axe types to include the color utilities we use in this file
|
|
6
|
-
// https://github.com/dequelabs/axe-core/blob/develop/lib/commons/color/color.js
|
|
7
|
-
type Color = {
|
|
8
|
-
red: number;
|
|
9
|
-
green: number;
|
|
10
|
-
blue: number;
|
|
11
|
-
alpha: number;
|
|
12
|
-
toHexString: () => string;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
type ConformanceLevel = "bronze" | "silver" | "custom";
|
|
16
|
-
|
|
17
|
-
type ConformanceThresholdFn = (
|
|
18
|
-
fontSize: string,
|
|
19
|
-
fontWeight: string
|
|
20
|
-
) => number | null;
|
|
21
|
-
|
|
22
|
-
declare module "axe-core" {
|
|
23
|
-
const commons: {
|
|
24
|
-
color: {
|
|
25
|
-
getForegroundColor: (
|
|
26
|
-
node: HTMLElement,
|
|
27
|
-
_: unknown,
|
|
28
|
-
bgColor: Color | null
|
|
29
|
-
) => Color | null;
|
|
30
|
-
getBackgroundColor: (node: HTMLElement) => Color | null;
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const getAPCASilverPlusThreshold = (
|
|
36
|
-
fontSize: string,
|
|
37
|
-
fontWeight: string
|
|
38
|
-
): number | null => {
|
|
39
|
-
const silverPlusAPCALookupTable = [
|
|
40
|
-
// See https://readtech.org/ARC/tests/visual-readability-contrast/?tn=criterion (May 22, 2022)
|
|
41
|
-
// font size in px | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 weights
|
|
42
|
-
[10, -1, -1, -1, -1, -1, -1, -1, -1, -1],
|
|
43
|
-
[12, -1, -1, -1, -1, -1, -1, -1, -1, -1],
|
|
44
|
-
[14, -1, -1, -1, 100, 100, 90, 75, -1, -1],
|
|
45
|
-
[15, -1, -1, -1, 100, 100, 90, 70, -1, -1],
|
|
46
|
-
[16, -1, -1, -1, 90, 75, 70, 60, 60, -1],
|
|
47
|
-
[18, -1, -1, 100, 75, 70, 60, 55, 55, 55],
|
|
48
|
-
[21, -1, -1, 90, 70, 60, 55, 50, 50, 50],
|
|
49
|
-
[24, -1, -1, 75, 60, 55, 50, 45, 45, 45],
|
|
50
|
-
[28, -1, 100, 70, 55, 50, 45, 43, 43, 43],
|
|
51
|
-
[32, -1, 90, 65, 50, 45, 43, 40, 40, 40],
|
|
52
|
-
[36, -1, 75, 60, 45, 43, 40, 38, 38, 38],
|
|
53
|
-
[48, 90, 60, 55, 43, 40, 38, 35, 35, 35],
|
|
54
|
-
[60, 75, 55, 50, 40, 38, 35, 33, 33, 33],
|
|
55
|
-
[72, 60, 50, 45, 38, 35, 33, 30, 30, 30],
|
|
56
|
-
[96, 50, 45, 40, 35, 33, 30, 25, 25, 25],
|
|
57
|
-
];
|
|
58
|
-
|
|
59
|
-
const size = parseFloat(fontSize);
|
|
60
|
-
const weight = parseFloat(fontWeight);
|
|
61
|
-
|
|
62
|
-
// Go over the table backwards to find the first matching font size and then the weight.
|
|
63
|
-
// The value null is returned when the combination of font size and weight does not have
|
|
64
|
-
// any elegible APCA luminosity silver compliant thresholds (represented by -1 in the table).
|
|
65
|
-
silverPlusAPCALookupTable.reverse();
|
|
66
|
-
for (const [rowSize, ...rowWeights] of silverPlusAPCALookupTable) {
|
|
67
|
-
if (size >= rowSize) {
|
|
68
|
-
for (const [idx, keywordWeight] of [
|
|
69
|
-
900, 800, 700, 600, 500, 400, 300, 200, 100,
|
|
70
|
-
].entries()) {
|
|
71
|
-
if (weight >= keywordWeight) {
|
|
72
|
-
const threshold = rowWeights[rowWeights.length - 1 - idx];
|
|
73
|
-
return threshold === -1 ? null : threshold;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return null;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const getAPCABronzeThreshold = (fontSize: string): number | null => {
|
|
83
|
-
const size = parseFloat(fontSize);
|
|
84
|
-
|
|
85
|
-
// APCA Bronze Level Conformance
|
|
86
|
-
// https://readtech.org/ARC/tests/visual-readability-contrast/?tn=criterion
|
|
87
|
-
switch (true) {
|
|
88
|
-
case size >= 32:
|
|
89
|
-
return 45;
|
|
90
|
-
case size >= 16:
|
|
91
|
-
return 60;
|
|
92
|
-
default:
|
|
93
|
-
return 75;
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const generateColorContrastAPCAConformanceCheck = (
|
|
98
|
-
conformanceLevel: string,
|
|
99
|
-
conformanceThresholdFn: ConformanceThresholdFn
|
|
100
|
-
): Check => ({
|
|
101
|
-
id: `color-contrast-apca-${conformanceLevel}-conformance`,
|
|
102
|
-
metadata: {
|
|
103
|
-
impact: "serious",
|
|
104
|
-
messages: {
|
|
105
|
-
pass:
|
|
106
|
-
"Element has sufficient APCA " +
|
|
107
|
-
conformanceLevel +
|
|
108
|
-
" level lightness contrast (Lc) of ${data.apcaContrast}Lc (foreground color: ${data.fgColor}, background color: ${data.bgColor}, font size: ${data.fontSize}, font weight: ${data.fontWeight}). Expected minimum APCA contrast of ${data.apcaThreshold}}",
|
|
109
|
-
fail: {
|
|
110
|
-
default:
|
|
111
|
-
"Element has insufficient APCA " +
|
|
112
|
-
conformanceLevel +
|
|
113
|
-
" level contrast of ${data.apcaContrast}Lc (foreground color: ${data.fgColor}, background color: ${data.bgColor}, font size: ${data.fontSize}, font weight: ${data.fontWeight}). Expected minimum APCA lightness contrast of ${data.apcaThreshold}Lc",
|
|
114
|
-
increaseFont:
|
|
115
|
-
"Element has insufficient APCA " +
|
|
116
|
-
conformanceLevel +
|
|
117
|
-
" level contrast of ${data.apcaContrast}Lc (foreground color: ${data.fgColor}, background color: ${data.bgColor}, font size: ${data.fontSize}, font weight: ${data.fontWeight}). Increase font size and/or font weight to meet APCA conformance minimums",
|
|
118
|
-
},
|
|
119
|
-
incomplete: "Unable to determine APCA lightness contrast (Lc)",
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
evaluate: function (node: HTMLElement) {
|
|
123
|
-
const nodeStyle = window.getComputedStyle(node);
|
|
124
|
-
const fontSize = nodeStyle.getPropertyValue("font-size");
|
|
125
|
-
const fontWeight = nodeStyle.getPropertyValue("font-weight");
|
|
126
|
-
|
|
127
|
-
const bgColor: Color | null =
|
|
128
|
-
axe.commons.color.getBackgroundColor(node);
|
|
129
|
-
const fgColor: Color | null = axe.commons.color.getForegroundColor(
|
|
130
|
-
node,
|
|
131
|
-
false,
|
|
132
|
-
bgColor
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
// missing data to determine APCA contrast for this node
|
|
136
|
-
if (!bgColor || !fgColor || !fontSize || !fontWeight) {
|
|
137
|
-
return undefined;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const toRGBA = (color: Color) => {
|
|
141
|
-
return `rgba(${color.red}, ${color.green}, ${color.blue}, ${color.alpha})`;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const apcaContrast = Math.abs(
|
|
145
|
-
calcAPCA(toRGBA(fgColor), toRGBA(bgColor))
|
|
146
|
-
);
|
|
147
|
-
const apcaThreshold = conformanceThresholdFn(fontSize, fontWeight);
|
|
148
|
-
|
|
149
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
150
|
-
// @ts-ignore
|
|
151
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
152
|
-
this.data({
|
|
153
|
-
fgColor: fgColor.toHexString(),
|
|
154
|
-
bgColor: bgColor.toHexString(),
|
|
155
|
-
fontSize: `${((parseFloat(fontSize) * 72) / 96).toFixed(
|
|
156
|
-
1
|
|
157
|
-
)}pt (${fontSize}px)`,
|
|
158
|
-
fontWeight: fontWeight,
|
|
159
|
-
apcaContrast: Math.round(apcaContrast * 100) / 100,
|
|
160
|
-
apcaThreshold: apcaThreshold,
|
|
161
|
-
messageKey: apcaThreshold === null ? "increaseFont" : "default",
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
return apcaThreshold ? apcaContrast >= apcaThreshold : false;
|
|
165
|
-
},
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
const generateColorContrastAPCARule = (conformanceLevel: string): Rule => ({
|
|
169
|
-
id: `color-contrast-apca-${conformanceLevel}`,
|
|
170
|
-
impact: "serious",
|
|
171
|
-
matches: "color-contrast-matches",
|
|
172
|
-
metadata: {
|
|
173
|
-
description: `Ensures the contrast between foreground and background colors meets APCA ${conformanceLevel} level conformance minimums thresholds`,
|
|
174
|
-
tags: ["apca", "wcag3", `apca-${conformanceLevel}`],
|
|
175
|
-
help: "Elements must meet APCA conformance minimums thresholds",
|
|
176
|
-
helpUrl:
|
|
177
|
-
"https://readtech.org/ARC/tests/visual-readability-contrast/?tn=criterion",
|
|
178
|
-
},
|
|
179
|
-
all: [`color-contrast-apca-${conformanceLevel}-conformance`],
|
|
180
|
-
tags: ["apca", "wcag3", `apca-${conformanceLevel}`],
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
const colorContrastAPCASilverConformanceCheck =
|
|
184
|
-
generateColorContrastAPCAConformanceCheck(
|
|
185
|
-
"silver",
|
|
186
|
-
getAPCASilverPlusThreshold
|
|
187
|
-
);
|
|
188
|
-
|
|
189
|
-
const colorContrastAPCABronzeConformanceCheck =
|
|
190
|
-
generateColorContrastAPCAConformanceCheck("bronze", getAPCABronzeThreshold);
|
|
191
|
-
|
|
192
|
-
const colorContrastAPCASilverRule = generateColorContrastAPCARule("silver");
|
|
193
|
-
const colorContrastAPCABronzeRule = generateColorContrastAPCARule("bronze");
|
|
194
|
-
|
|
195
|
-
const registerAxeAPCA = (
|
|
196
|
-
conformanceLevel: ConformanceLevel,
|
|
197
|
-
customConformanceThresholdFn?: ConformanceThresholdFn
|
|
198
|
-
) => {
|
|
199
|
-
axe.configure({
|
|
200
|
-
rules: [generateColorContrastAPCARule(conformanceLevel)],
|
|
201
|
-
checks: [
|
|
202
|
-
generateColorContrastAPCAConformanceCheck(
|
|
203
|
-
conformanceLevel,
|
|
204
|
-
customConformanceThresholdFn ||
|
|
205
|
-
(conformanceLevel === "silver"
|
|
206
|
-
? getAPCASilverPlusThreshold
|
|
207
|
-
: getAPCABronzeThreshold)
|
|
208
|
-
),
|
|
209
|
-
],
|
|
210
|
-
});
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
export {
|
|
214
|
-
colorContrastAPCASilverRule,
|
|
215
|
-
colorContrastAPCASilverConformanceCheck,
|
|
216
|
-
colorContrastAPCABronzeRule,
|
|
217
|
-
colorContrastAPCABronzeConformanceCheck,
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
export default registerAxeAPCA;
|