@stackoverflow/stacks 1.10.2 → 2.0.0-rc.0

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.
Files changed (95) hide show
  1. package/README.md +15 -0
  2. package/dist/css/stacks.css +7428 -4429
  3. package/dist/css/stacks.min.css +1 -1
  4. package/lib/atomic/__snapshots__/color-new.less.test.ts.snap +3015 -0
  5. package/lib/atomic/__snapshots__/color.less.test.ts.snap +2886 -0
  6. package/lib/atomic/border.less +0 -258
  7. package/lib/atomic/color.less +26 -200
  8. package/lib/atomic/color.less.test.ts +12 -0
  9. package/lib/atomic/misc.less +7 -6
  10. package/lib/atomic/typography.less +0 -7
  11. package/lib/atomic/v1/__snapshots__/border.less.test.ts.snap +552 -0
  12. package/lib/atomic/v1/__snapshots__/color.less.test.ts.snap +6756 -0
  13. package/lib/atomic/v1/__snapshots__/typography.less.test.ts.snap +22 -0
  14. package/lib/atomic/v1/border.less +210 -0
  15. package/lib/atomic/v1/border.less.test.ts +14 -0
  16. package/lib/atomic/v1/color.less +183 -0
  17. package/lib/atomic/v1/color.less.test.ts +14 -0
  18. package/lib/atomic/v1/typography.less +8 -0
  19. package/lib/atomic/v1/typography.less.test.ts +14 -0
  20. package/lib/components/activity-indicator/activity-indicator.a11y.test.ts +1 -8
  21. package/lib/components/activity-indicator/activity-indicator.less +4 -4
  22. package/lib/components/anchor/anchor.a11y.test.ts +0 -5
  23. package/lib/components/anchor/anchor.less +4 -4
  24. package/lib/components/anchor/anchor.visual.test.ts +1 -1
  25. package/lib/components/avatar/avatar.less +2 -2
  26. package/lib/components/award-bling/award-bling.less +3 -3
  27. package/lib/components/badge/badge.a11y.test.ts +2 -12
  28. package/lib/components/badge/badge.less +40 -40
  29. package/lib/components/badge/badge.visual.test.ts +27 -5
  30. package/lib/components/block-link/block-link.a11y.test.ts +0 -7
  31. package/lib/components/block-link/block-link.less +8 -8
  32. package/lib/components/breadcrumbs/breadcrumbs.less +1 -1
  33. package/lib/components/button/button.a11y.test.ts +0 -3
  34. package/lib/components/button/button.less +40 -40
  35. package/lib/components/button/button.visual.test.ts +1 -1
  36. package/lib/components/check-control/check-control.a11y.test.ts +0 -5
  37. package/lib/components/check-control/check-control.visual.test.ts +1 -1
  38. package/lib/components/checkbox_radio/checkbox_radio.less +5 -5
  39. package/lib/components/checkbox_radio/checkbox_radio.visual.test.ts +1 -1
  40. package/lib/components/code-block/code-block.less +3 -3
  41. package/lib/components/description/description.a11y.test.ts +0 -1
  42. package/lib/components/description/description.visual.test.ts +1 -1
  43. package/lib/components/input-fill/input-fill.less +2 -2
  44. package/lib/components/input-icon/input-icon.less +2 -2
  45. package/lib/components/input-message/input-message.less +8 -8
  46. package/lib/components/input_textarea/input_textarea.less +6 -6
  47. package/lib/components/label/label.less +11 -11
  48. package/lib/components/link/link.a11y.test.ts +0 -8
  49. package/lib/components/link/link.less +8 -8
  50. package/lib/components/link-preview/link-preview.less +9 -9
  51. package/lib/components/menu/menu.less +3 -3
  52. package/lib/components/modal/modal.less +5 -4
  53. package/lib/components/navigation/navigation.less +11 -11
  54. package/lib/components/notice/notice.less +48 -48
  55. package/lib/components/pagination/pagination.less +3 -3
  56. package/lib/components/popover/popover.less +2 -2
  57. package/lib/components/popover/tooltip.test.ts +1 -1
  58. package/lib/components/post-summary/post-summary.less +40 -40
  59. package/lib/components/progress-bar/progress-bar.less +15 -15
  60. package/lib/components/prose/prose.less +15 -15
  61. package/lib/components/select/select.less +5 -5
  62. package/lib/components/sidebar-widget/sidebar-widget.less +12 -12
  63. package/lib/components/table/table.less +7 -7
  64. package/lib/components/tag/tag.less +25 -25
  65. package/lib/components/toggle-switch/toggle-switch.a11y.test.ts +0 -4
  66. package/lib/components/toggle-switch/toggle-switch.less +4 -4
  67. package/lib/components/toggle-switch/toggle-switch.visual.test.ts +12 -11
  68. package/lib/components/topbar/topbar.less +34 -34
  69. package/lib/components/uploader/uploader.less +15 -15
  70. package/lib/components/user-card/user-card.less +7 -7
  71. package/lib/exports/__snapshots__/color-mixins.less.test.ts.snap +539 -0
  72. package/lib/exports/__snapshots__/color.less.test.ts.snap +762 -0
  73. package/lib/exports/color-mixins.less +280 -0
  74. package/lib/exports/color-mixins.less.test.ts +150 -0
  75. package/lib/exports/color-sets.less +620 -0
  76. package/lib/exports/color.less +57 -0
  77. package/lib/exports/color.less.test.ts +12 -0
  78. package/lib/exports/exports.less +2 -1
  79. package/lib/exports/mixins.less +17 -5
  80. package/lib/exports/theme.less +85 -0
  81. package/lib/exports/v1/__snapshots__/constants-colors.less.test.ts.snap +902 -0
  82. package/lib/exports/v1/constants-colors.less +893 -0
  83. package/lib/exports/v1/constants-colors.less.test.ts +12 -0
  84. package/lib/stacks-static.less +5 -0
  85. package/lib/test/axe-apca/README.md +34 -0
  86. package/lib/test/axe-apca/index.ts +3 -0
  87. package/lib/test/axe-apca/package.wip.json +30 -0
  88. package/lib/test/axe-apca/src/apca-w3.d.ts +3 -0
  89. package/lib/test/axe-apca/src/axe-apca.test.ts +155 -0
  90. package/lib/test/axe-apca/src/axe-apca.ts +212 -0
  91. package/lib/test/less-test-utils.ts +28 -0
  92. package/lib/test/test-utils.ts +18 -1
  93. package/lib/tsconfig.json +1 -0
  94. package/package.json +14 -7
  95. package/lib/exports/constants-colors.less +0 -1100
@@ -0,0 +1,12 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { renderLess } from "../../test/less-test-utils";
3
+
4
+ describe("constants-colors", () => {
5
+ it("should output all the css generated by the v1 colors/theming generation mixins", async () => {
6
+ const css = await renderLess(`
7
+ @import "./lib/exports/v1/constants-colors.less";
8
+ `);
9
+
10
+ expect(css).toMatchSnapshot();
11
+ });
12
+ });
@@ -56,6 +56,11 @@
56
56
  // LESS CONSTANTS AND MIXINS
57
57
  @import "exports/exports.less";
58
58
 
59
+ // -- ATOMIC CLASSES (v1 colors)
60
+ @import "atomic/v1/border.less"; // Deprecated
61
+ @import "atomic/v1/color.less"; // Deprecated
62
+ @import "atomic/v1/typography.less"; // Deprecated
63
+
59
64
  // -- ATOMIC CLASSES
60
65
  @import "atomic/border.less";
61
66
  @import "atomic/color.less";
@@ -0,0 +1,34 @@
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
+ ```
@@ -0,0 +1,3 @@
1
+ import registerAxeAPCA from "./src/axe-apca";
2
+
3
+ export default registerAxeAPCA;
@@ -0,0 +1,30 @@
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
+ }
@@ -0,0 +1,3 @@
1
+ declare module "apca-w3" {
2
+ export function calcAPCA(textColor: string, bgColor: string): number;
3
+ }
@@ -0,0 +1,155 @@
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("bronze conformance level", () => {
17
+ beforeEach(() => {
18
+ registerAxeAPCA("bronze");
19
+ });
20
+
21
+ it("should check for APCA accessibility contrast violations", async () => {
22
+ const el: HTMLElement = await fixture(
23
+ html`<p
24
+ style="background: white; color: black; font-size: 12px; font-weight: 400;"
25
+ >
26
+ Some copy
27
+ </p>`
28
+ );
29
+
30
+ const results = await runAxe(el);
31
+
32
+ const apcaPasses = results.passes.filter((violation) =>
33
+ violation.id.includes("color-contrast-apca-bronze")
34
+ );
35
+
36
+ await expect(apcaPasses.length).to.equal(1);
37
+
38
+ const passNode = apcaPasses[0].nodes[0];
39
+ expect(passNode.all[0].message).to.include(
40
+ "Element has sufficient APCA bronze level lightness contrast"
41
+ );
42
+ });
43
+
44
+ it("should detect APCA accessibility contrast violations", async () => {
45
+ const el: HTMLElement = await fixture(
46
+ html`<p
47
+ style="background: white; color: lightgray; font-size: 12px; font-weight: 400;"
48
+ >
49
+ Some copy
50
+ </p>`
51
+ );
52
+
53
+ const results = await runAxe(el);
54
+
55
+ const apcaViolations = results.violations.filter((violation) =>
56
+ violation.id.includes("color-contrast-apca-bronze")
57
+ );
58
+
59
+ await expect(apcaViolations.length).to.equal(1);
60
+
61
+ const violationNode = apcaViolations[0].nodes[0];
62
+ expect(violationNode.failureSummary).to.include(
63
+ "Element has insufficient APCA bronze level contrast"
64
+ );
65
+ });
66
+
67
+ it("should check nested nodes", async () => {
68
+ const el: HTMLElement = await fixture(
69
+ html`<div style="background: black;">
70
+ <h2>Some title</h2>
71
+ <p>Some copy</p>
72
+ <button style="background: black;">Some button</button>
73
+ </div>`
74
+ );
75
+
76
+ const results = await runAxe(el);
77
+
78
+ const apcaViolations = results.violations.filter((violation) =>
79
+ violation.id.includes("color-contrast-apca-bronze")
80
+ );
81
+
82
+ await expect(apcaViolations[0].nodes.length).to.equal(3);
83
+ });
84
+ });
85
+
86
+ describe("silver conformance level", () => {
87
+ beforeEach(() => {
88
+ registerAxeAPCA("silver");
89
+ });
90
+
91
+ it("should check for APCA accessibility contrast violations", async () => {
92
+ const el: HTMLElement = await fixture(
93
+ html`<p
94
+ style="background: white; color: black; font-size: 14px; font-weight: 400;"
95
+ >
96
+ Some copy
97
+ </p>`
98
+ );
99
+
100
+ const results = await runAxe(el);
101
+
102
+ const apcaPasses = results.passes.filter((violation) =>
103
+ violation.id.includes("color-contrast-apca-silver")
104
+ );
105
+
106
+ await expect(apcaPasses.length).to.equal(1);
107
+
108
+ const passNode = apcaPasses[0].nodes[0];
109
+ expect(passNode.all[0].message).to.include(
110
+ "Element has sufficient APCA silver level lightness contrast"
111
+ );
112
+ });
113
+
114
+ it("should detect APCA accessibility contrast violations", async () => {
115
+ const el: HTMLElement = await fixture(
116
+ html`<p
117
+ style="background: white; color: black; font-size: 12px; font-weight: 400;"
118
+ >
119
+ Some copy
120
+ </p>`
121
+ );
122
+
123
+ const results = await runAxe(el);
124
+
125
+ const apcaViolations = results.violations.filter((violation) =>
126
+ violation.id.includes("color-contrast-apca-silver")
127
+ );
128
+
129
+ await expect(apcaViolations.length).to.equal(1);
130
+
131
+ const violationNode = apcaViolations[0].nodes[0];
132
+ expect(violationNode.failureSummary).to.include(
133
+ "Element has insufficient APCA silver level contrast"
134
+ );
135
+ });
136
+
137
+ it("should check nested nodes", async () => {
138
+ const el: HTMLElement = await fixture(
139
+ html`<div style="background: black;">
140
+ <h2>Some title</h2>
141
+ <p>Some copy</p>
142
+ <button style="background: black;">Some button</button>
143
+ </div>`
144
+ );
145
+
146
+ const results = await runAxe(el);
147
+
148
+ const apcaViolations = results.violations.filter((violation) =>
149
+ violation.id.includes("color-contrast-apca-silver")
150
+ );
151
+
152
+ await expect(apcaViolations[0].nodes.length).to.equal(3);
153
+ });
154
+ });
155
+ });
@@ -0,0 +1,212 @@
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
+ declare module "axe-core" {
16
+ const commons: {
17
+ color: {
18
+ getForegroundColor: (
19
+ node: HTMLElement,
20
+ _: unknown,
21
+ bgColor: Color | null
22
+ ) => Color | null;
23
+ getBackgroundColor: (node: HTMLElement) => Color | null;
24
+ };
25
+ };
26
+ }
27
+
28
+ const getAPCASilverPlusThreshold = (
29
+ fontSize: string,
30
+ fontWeight: string
31
+ ): number | null => {
32
+ const silverPlusAPCALookupTable = [
33
+ // See https://readtech.org/ARC/tests/visual-readability-contrast/?tn=criterion (May 22, 2022)
34
+ // font size in px | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 weights
35
+ [10, -1, -1, -1, -1, -1, -1, -1, -1, -1],
36
+ [12, -1, -1, -1, -1, -1, -1, -1, -1, -1],
37
+ [14, -1, -1, -1, 100, 100, 90, 75, -1, -1],
38
+ [15, -1, -1, -1, 100, 100, 90, 70, -1, -1],
39
+ [16, -1, -1, -1, 90, 75, 70, 60, 60, -1],
40
+ [18, -1, -1, 100, 75, 70, 60, 55, 55, 55],
41
+ [21, -1, -1, 90, 70, 60, 55, 50, 50, 50],
42
+ [24, -1, -1, 75, 60, 55, 50, 45, 45, 45],
43
+ [28, -1, 100, 70, 55, 50, 45, 43, 43, 43],
44
+ [32, -1, 90, 65, 50, 45, 43, 40, 40, 40],
45
+ [36, -1, 75, 60, 45, 43, 40, 38, 38, 38],
46
+ [48, 90, 60, 55, 43, 40, 38, 35, 35, 35],
47
+ [60, 75, 55, 50, 40, 38, 35, 33, 33, 33],
48
+ [72, 60, 50, 45, 38, 35, 33, 30, 30, 30],
49
+ [96, 50, 45, 40, 35, 33, 30, 25, 25, 25],
50
+ ];
51
+
52
+ const size = parseFloat(fontSize);
53
+ const weight = parseFloat(fontWeight);
54
+
55
+ // Go over the table backwards to find the first matching font size and then the weight.
56
+ // The value null is returned when the combination of font size and weight does not have
57
+ // any elegible APCA luminosity silver compliant thresholds (represented by -1 in the table).
58
+ silverPlusAPCALookupTable.reverse();
59
+ for (const [rowSize, ...rowWeights] of silverPlusAPCALookupTable) {
60
+ if (size >= rowSize) {
61
+ for (const [idx, keywordWeight] of [
62
+ 900, 800, 700, 600, 500, 400, 300, 200, 100,
63
+ ].entries()) {
64
+ if (weight >= keywordWeight) {
65
+ const threshold = rowWeights[rowWeights.length - 1 - idx];
66
+ return threshold === -1 ? null : threshold;
67
+ }
68
+ }
69
+ }
70
+ }
71
+
72
+ return null;
73
+ };
74
+
75
+ const getAPCABronzeThreshold = (fontSize: string): number | null => {
76
+ const size = parseFloat(fontSize);
77
+
78
+ // APCA Bronze Level Conformance
79
+ // https://readtech.org/ARC/tests/visual-readability-contrast/?tn=criterion
80
+ switch (true) {
81
+ case size >= 32:
82
+ return 45;
83
+ case size >= 16:
84
+ return 60;
85
+ default:
86
+ return 75;
87
+ }
88
+ };
89
+
90
+ const generateColorContrastAPCAConformanceCheck = (
91
+ conformanceLevel: string,
92
+ conformanceThresholdFn: (
93
+ fontSize: string,
94
+ fontWeight: string
95
+ ) => number | null
96
+ ): Check => ({
97
+ id: `color-contrast-apca-${conformanceLevel}-conformance`,
98
+ metadata: {
99
+ impact: "serious",
100
+ messages: {
101
+ pass:
102
+ "Element has sufficient APCA " +
103
+ conformanceLevel +
104
+ " 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}}",
105
+ fail: {
106
+ default:
107
+ "Element has insufficient APCA " +
108
+ conformanceLevel +
109
+ " 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",
110
+ increaseFont:
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}). Increase font size and/or font weight to meet APCA conformance minimums",
114
+ },
115
+ incomplete: "Unable to determine APCA lightness contrast (Lc)",
116
+ },
117
+ },
118
+ evaluate: function (node: HTMLElement) {
119
+ const nodeStyle = window.getComputedStyle(node);
120
+ const fontSize = nodeStyle.getPropertyValue("font-size");
121
+ const fontWeight = nodeStyle.getPropertyValue("font-weight");
122
+
123
+ const bgColor: Color | null =
124
+ axe.commons.color.getBackgroundColor(node);
125
+ const fgColor: Color | null = axe.commons.color.getForegroundColor(
126
+ node,
127
+ false,
128
+ bgColor
129
+ );
130
+
131
+ // missing data to determine APCA contrast for this node
132
+ if (!bgColor || !fgColor || !fontSize || !fontWeight) {
133
+ return undefined;
134
+ }
135
+
136
+ const toRGBA = (color: Color) => {
137
+ return `rgba(${color.red}, ${color.green}, ${color.blue}, ${color.alpha})`;
138
+ };
139
+
140
+ const apcaContrast = Math.abs(
141
+ calcAPCA(toRGBA(fgColor), toRGBA(bgColor))
142
+ );
143
+ const apcaThreshold = conformanceThresholdFn(fontSize, fontWeight);
144
+
145
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
146
+ // @ts-ignore
147
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
148
+ this.data({
149
+ fgColor: fgColor.toHexString(),
150
+ bgColor: bgColor.toHexString(),
151
+ fontSize: `${((parseFloat(fontSize) * 72) / 96).toFixed(
152
+ 1
153
+ )}pt (${fontSize}px)`,
154
+ fontWeight: fontWeight,
155
+ apcaContrast: Math.round(apcaContrast * 100) / 100,
156
+ apcaThreshold: apcaThreshold,
157
+ messageKey: apcaThreshold === null ? "increaseFont" : "default",
158
+ });
159
+
160
+ return apcaThreshold ? apcaContrast >= apcaThreshold : false;
161
+ },
162
+ });
163
+
164
+ const generateColorContrastAPCARule = (conformanceLevel: string): Rule => ({
165
+ id: `color-contrast-apca-${conformanceLevel}`,
166
+ impact: "serious",
167
+ matches: "color-contrast-matches",
168
+ metadata: {
169
+ description: `Ensures the contrast between foreground and background colors meets APCA ${conformanceLevel} level conformance minimums thresholds`,
170
+ tags: ["apca", "wcag3", `apca-${conformanceLevel}`],
171
+ help: "Elements must meet APCA conformance minimums thresholds",
172
+ helpUrl:
173
+ "https://readtech.org/ARC/tests/visual-readability-contrast/?tn=criterion",
174
+ },
175
+ all: [`color-contrast-apca-${conformanceLevel}-conformance`],
176
+ tags: ["apca", "wcag3", `apca-${conformanceLevel}`],
177
+ });
178
+
179
+ const colorContrastAPCASilverConformanceCheck =
180
+ generateColorContrastAPCAConformanceCheck(
181
+ "silver",
182
+ getAPCASilverPlusThreshold
183
+ );
184
+
185
+ const colorContrastAPCABronzeConformanceCheck =
186
+ generateColorContrastAPCAConformanceCheck("bronze", getAPCABronzeThreshold);
187
+
188
+ const colorContrastAPCASilverRule = generateColorContrastAPCARule("silver");
189
+ const colorContrastAPCABronzeRule = generateColorContrastAPCARule("bronze");
190
+
191
+ const registerAxeAPCA = (conformanceLevel: "bronze" | "silver") => {
192
+ axe.configure({
193
+ rules: [generateColorContrastAPCARule(conformanceLevel)],
194
+ checks: [
195
+ generateColorContrastAPCAConformanceCheck(
196
+ conformanceLevel,
197
+ conformanceLevel === "bronze"
198
+ ? getAPCABronzeThreshold
199
+ : getAPCASilverPlusThreshold
200
+ ),
201
+ ],
202
+ });
203
+ };
204
+
205
+ export {
206
+ colorContrastAPCASilverRule,
207
+ colorContrastAPCASilverConformanceCheck,
208
+ colorContrastAPCABronzeRule,
209
+ colorContrastAPCABronzeConformanceCheck,
210
+ };
211
+
212
+ export default registerAxeAPCA;
@@ -0,0 +1,28 @@
1
+ import beautify from "cssbeautify";
2
+ import * as less from "less";
3
+ import * as path from "path";
4
+ import * as fs from "fs";
5
+
6
+ // cssbeautify is an old package that doesn't support ES modules
7
+ const cssbeautify = beautify as (css: string) => string;
8
+
9
+ const getSubdirectories = (dirPath: string): string[] => {
10
+ const subdirs = fs
11
+ .readdirSync(dirPath)
12
+ .map((file) => path.join(dirPath, file))
13
+ .filter((path) => fs.statSync(path).isDirectory());
14
+ return subdirs.reduce(
15
+ (acc, subdir) => [...acc, subdir, ...getSubdirectories(subdir)],
16
+ subdirs
17
+ );
18
+ };
19
+
20
+ const renderLess = async (lessCode: string) => {
21
+ const { css } = await less.render(lessCode, {
22
+ paths: getSubdirectories(path.join(__dirname, "../")),
23
+ });
24
+
25
+ return cssbeautify(css);
26
+ };
27
+
28
+ export { renderLess };
@@ -2,6 +2,10 @@ import { html, fixture, expect, unsafeStatic } from "@open-wc/testing";
2
2
  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
+ import axe from "axe-core";
6
+ import registerAxeAPCA from "./axe-apca";
7
+
8
+ registerAxeAPCA("bronze");
5
9
 
6
10
  const colorThemes = ["dark", "light"];
7
11
  const baseThemes = ["", "highcontrast"];
@@ -317,7 +321,20 @@ const runComponentTest = ({
317
321
  }
318
322
 
319
323
  if (type === "a11y") {
320
- // TODO add conditional option for high contrast mode to test against AAA
324
+ const highcontrast = theme?.includes("highcontrast");
325
+ axe.configure({
326
+ rules: [
327
+ // for non-high contrast, we disable WCAG 2.1 AA (4.5:1)
328
+ // and use APCA bronze level instead
329
+ { id: "color-contrast", enabled: false },
330
+ {
331
+ id: "color-contrast-apca-bronze",
332
+ enabled: !highcontrast,
333
+ },
334
+ // for high contrast, we check against WCAG 2.1 AAA (7:1)
335
+ { id: "color-contrast-enhanced", enabled: highcontrast },
336
+ ],
337
+ });
321
338
  await expect(el).to.be.accessible();
322
339
  }
323
340
 
package/lib/tsconfig.json CHANGED
@@ -8,6 +8,7 @@
8
8
  "moduleResolution": "node",
9
9
  "skipLibCheck": true,
10
10
  "declaration": true,
11
+ "allowSyntheticDefaultImports": true,
11
12
  "paths": {
12
13
  "@open-wc/testing": ["./test/open-wc-testing-patch.d.ts"]
13
14
  }
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": "1.10.2",
8
+ "version": "2.0.0-rc.0",
9
9
  "files": [
10
10
  "dist",
11
11
  "lib"
@@ -22,12 +22,14 @@
22
22
  "build:docs": "webpack --mode=production --config ./docs/webpack.config.js && cd ./docs && eleventy",
23
23
  "start:webpack": "webpack --watch --config ./docs/webpack.config.js",
24
24
  "start:eleventy": "cd ./docs && eleventy --serve",
25
- "test": "npm run test:unit && npm run test:a11y && npm run test:visual",
25
+ "test": "npm run test:less && npm run test:unit && npm run test:a11y && npm run test:visual",
26
26
  "test:a11y": "web-test-runner --group=a11y",
27
27
  "test:unit": "web-test-runner --group=unit",
28
28
  "test:unit:watch": "web-test-runner --group=unit --watch",
29
29
  "test:visual": "pwsh run-test-visual.ps1 npx web-test-runner --group=visual",
30
30
  "test:visual:update": "pwsh run-test-visual.ps1 npx web-test-runner --group=visual --update-visual-baseline",
31
+ "test:less": "vitest run .less.test.ts",
32
+ "test:less:update": "npm run test:less -- -u",
31
33
  "prepublishOnly": "npm run build",
32
34
  "format": "prettier --write ./lib",
33
35
  "lint": "concurrently -n w: npm:lint:*",
@@ -44,21 +46,25 @@
44
46
  "@11ty/eleventy": "^2.0.1",
45
47
  "@highlightjs/cdn-assets": "^11.8.0",
46
48
  "@open-wc/testing": "^3.2.0",
47
- "@rollup/plugin-commonjs": "^25.0.3",
49
+ "@rollup/plugin-commonjs": "^25.0.4",
48
50
  "@rollup/plugin-replace": "^5.0.2",
49
51
  "@stackoverflow/stacks-editor": "^0.8.8",
50
- "@stackoverflow/stacks-icons": "^5.4.0",
52
+ "@stackoverflow/stacks-icons": "^5.5.0",
51
53
  "@testing-library/dom": "^9.3.1",
52
54
  "@testing-library/user-event": "^14.4.3",
53
- "@typescript-eslint/eslint-plugin": "^6.2.1",
54
- "@typescript-eslint/parser": "^6.2.1",
55
+ "@types/cssbeautify": "^0.3.2",
56
+ "@types/less": "^3.0.3",
57
+ "@typescript-eslint/eslint-plugin": "^6.4.0",
58
+ "@typescript-eslint/parser": "^6.4.0",
55
59
  "@web/dev-server-esbuild": "^0.4.1",
56
60
  "@web/dev-server-rollup": "^0.5.2",
57
61
  "@web/test-runner": "^0.17.0",
58
62
  "@web/test-runner-playwright": "^0.10.1",
59
63
  "@web/test-runner-visual-regression": "^0.8.2",
64
+ "apca-w3": "^0.1.9",
60
65
  "concurrently": "^8.2.0",
61
66
  "css-loader": "^6.8.1",
67
+ "cssbeautify": "^0.3.1",
62
68
  "cssnano": "^6.0.1",
63
69
  "docsearch.js": "^2.6.3",
64
70
  "eleventy-plugin-highlightjs": "^1.1.0",
@@ -73,7 +79,7 @@
73
79
  "mini-css-extract-plugin": "^2.7.6",
74
80
  "postcss-less": "^6.0.0",
75
81
  "postcss-loader": "^7.3.3",
76
- "prettier": "^3.0.0",
82
+ "prettier": "^3.0.1",
77
83
  "rollup-plugin-postcss": "^4.0.2",
78
84
  "stylelint": "^15.10.2",
79
85
  "stylelint-config-recommended": "^13.0.0",
@@ -81,6 +87,7 @@
81
87
  "terser-webpack-plugin": "^5.3.9",
82
88
  "ts-loader": "^9.4.4",
83
89
  "typescript": "^5.1.6",
90
+ "vitest": "^0.33.0",
84
91
  "webpack": "^5.88.2",
85
92
  "webpack-cli": "^5.1.4",
86
93
  "webpack-merge": "^5.9.0"