accented 0.0.1-dev.4 → 1.0.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.
- package/NOTICE +14 -0
- package/README.md +71 -0
- package/dist/accented.d.ts +28 -7
- package/dist/accented.d.ts.map +1 -1
- package/dist/accented.js +107 -42
- package/dist/accented.js.map +1 -1
- package/dist/common/tokens.d.ts +7 -0
- package/dist/common/tokens.d.ts.map +1 -0
- package/dist/common/tokens.js +8 -0
- package/dist/common/tokens.js.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +4 -0
- package/dist/constants.js.map +1 -0
- package/dist/dom-updater.d.ts +1 -6
- package/dist/dom-updater.d.ts.map +1 -1
- package/dist/dom-updater.js +136 -20
- package/dist/dom-updater.js.map +1 -1
- package/dist/elements/accented-dialog.d.ts +359 -0
- package/dist/elements/accented-dialog.d.ts.map +1 -0
- package/dist/elements/accented-dialog.js +377 -0
- package/dist/elements/accented-dialog.js.map +1 -0
- package/dist/elements/accented-trigger.d.ts +364 -0
- package/dist/elements/accented-trigger.d.ts.map +1 -0
- package/dist/elements/accented-trigger.js +214 -0
- package/dist/elements/accented-trigger.js.map +1 -0
- package/dist/fullscreen-listener.d.ts +2 -0
- package/dist/fullscreen-listener.d.ts.map +1 -0
- package/dist/fullscreen-listener.js +17 -0
- package/dist/fullscreen-listener.js.map +1 -0
- package/dist/intersection-observer.d.ts +5 -0
- package/dist/intersection-observer.d.ts.map +1 -0
- package/dist/intersection-observer.js +34 -0
- package/dist/intersection-observer.js.map +1 -0
- package/dist/log-and-rethrow.d.ts +2 -0
- package/dist/log-and-rethrow.d.ts.map +1 -0
- package/dist/log-and-rethrow.js +6 -0
- package/dist/log-and-rethrow.js.map +1 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +28 -0
- package/dist/logger.js.map +1 -0
- package/dist/register-elements.d.ts +2 -0
- package/dist/register-elements.d.ts.map +1 -0
- package/dist/register-elements.js +20 -0
- package/dist/register-elements.js.map +1 -0
- package/dist/resize-listener.d.ts +2 -0
- package/dist/resize-listener.d.ts.map +1 -0
- package/dist/resize-listener.js +17 -0
- package/dist/resize-listener.js.map +1 -0
- package/dist/scanner.d.ts +3 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +153 -0
- package/dist/scanner.js.map +1 -0
- package/dist/scroll-listeners.d.ts +2 -0
- package/dist/scroll-listeners.d.ts.map +1 -0
- package/dist/scroll-listeners.js +37 -0
- package/dist/scroll-listeners.js.map +1 -0
- package/dist/state.d.ts +7 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +16 -0
- package/dist/state.js.map +1 -0
- package/dist/task-queue.d.ts +5 -6
- package/dist/task-queue.d.ts.map +1 -1
- package/dist/task-queue.js +30 -25
- package/dist/task-queue.js.map +1 -1
- package/dist/types.d.ts +227 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/are-elements-with-issues-equal.d.ts +3 -0
- package/dist/utils/are-elements-with-issues-equal.d.ts.map +1 -0
- package/dist/utils/are-elements-with-issues-equal.js +5 -0
- package/dist/utils/are-elements-with-issues-equal.js.map +1 -0
- package/dist/utils/are-issue-sets-equal.d.ts +3 -0
- package/dist/utils/are-issue-sets-equal.d.ts.map +1 -0
- package/dist/utils/are-issue-sets-equal.js +6 -0
- package/dist/utils/are-issue-sets-equal.js.map +1 -0
- package/dist/utils/containing-blocks.d.ts +3 -0
- package/dist/utils/containing-blocks.d.ts.map +1 -0
- package/dist/utils/containing-blocks.js +46 -0
- package/dist/utils/containing-blocks.js.map +1 -0
- package/dist/utils/contains.d.ts +2 -0
- package/dist/utils/contains.d.ts.map +1 -0
- package/dist/utils/contains.js +19 -0
- package/dist/utils/contains.js.map +1 -0
- package/dist/utils/deduplicate-nodes.d.ts +2 -0
- package/dist/utils/deduplicate-nodes.d.ts.map +1 -0
- package/dist/utils/deduplicate-nodes.js +4 -0
- package/dist/utils/deduplicate-nodes.js.map +1 -0
- package/dist/utils/deep-merge.d.ts +4 -0
- package/dist/utils/deep-merge.d.ts.map +1 -0
- package/dist/utils/deep-merge.js +21 -0
- package/dist/utils/deep-merge.js.map +1 -0
- package/dist/utils/dom-helpers.d.ts +9 -0
- package/dist/utils/dom-helpers.d.ts.map +1 -0
- package/dist/utils/dom-helpers.js +34 -0
- package/dist/utils/dom-helpers.js.map +1 -0
- package/dist/utils/ensure-non-empty.d.ts +2 -0
- package/dist/utils/ensure-non-empty.d.ts.map +1 -0
- package/dist/utils/ensure-non-empty.js +7 -0
- package/dist/utils/ensure-non-empty.js.map +1 -0
- package/dist/utils/get-element-html.d.ts +2 -0
- package/dist/utils/get-element-html.d.ts.map +1 -0
- package/dist/utils/get-element-html.js +16 -0
- package/dist/utils/get-element-html.js.map +1 -0
- package/dist/utils/get-element-position.d.ts +11 -0
- package/dist/utils/get-element-position.d.ts.map +1 -0
- package/dist/utils/get-element-position.js +70 -0
- package/dist/utils/get-element-position.js.map +1 -0
- package/dist/utils/get-parent.d.ts +2 -0
- package/dist/utils/get-parent.d.ts.map +1 -0
- package/dist/utils/get-parent.js +12 -0
- package/dist/utils/get-parent.js.map +1 -0
- package/dist/utils/get-scan-context.d.ts +3 -0
- package/dist/utils/get-scan-context.d.ts.map +1 -0
- package/dist/utils/get-scan-context.js +28 -0
- package/dist/utils/get-scan-context.js.map +1 -0
- package/dist/utils/get-scrollable-ancestors.d.ts +2 -0
- package/dist/utils/get-scrollable-ancestors.d.ts.map +1 -0
- package/dist/utils/get-scrollable-ancestors.js +19 -0
- package/dist/utils/get-scrollable-ancestors.js.map +1 -0
- package/dist/utils/is-node-in-scan-context.d.ts +3 -0
- package/dist/utils/is-node-in-scan-context.d.ts.map +1 -0
- package/dist/utils/is-node-in-scan-context.js +26 -0
- package/dist/utils/is-node-in-scan-context.js.map +1 -0
- package/dist/utils/is-non-empty.d.ts +2 -0
- package/dist/utils/is-non-empty.d.ts.map +1 -0
- package/dist/utils/is-non-empty.js +4 -0
- package/dist/utils/is-non-empty.js.map +1 -0
- package/dist/utils/normalize-context.d.ts +3 -0
- package/dist/utils/normalize-context.d.ts.map +1 -0
- package/dist/utils/normalize-context.js +59 -0
- package/dist/utils/normalize-context.js.map +1 -0
- package/dist/utils/recalculate-positions.d.ts +2 -0
- package/dist/utils/recalculate-positions.d.ts.map +1 -0
- package/dist/utils/recalculate-positions.js +27 -0
- package/dist/utils/recalculate-positions.js.map +1 -0
- package/dist/utils/recalculate-scrollable-ancestors.d.ts +2 -0
- package/dist/utils/recalculate-scrollable-ancestors.d.ts.map +1 -0
- package/dist/utils/recalculate-scrollable-ancestors.js +13 -0
- package/dist/utils/recalculate-scrollable-ancestors.js.map +1 -0
- package/dist/utils/shadow-dom-aware-mutation-observer.d.ts +10 -0
- package/dist/utils/shadow-dom-aware-mutation-observer.d.ts.map +1 -0
- package/dist/utils/shadow-dom-aware-mutation-observer.js +61 -0
- package/dist/utils/shadow-dom-aware-mutation-observer.js.map +1 -0
- package/dist/utils/supports-anchor-positioning.d.ts +6 -0
- package/dist/utils/supports-anchor-positioning.d.ts.map +1 -0
- package/dist/utils/supports-anchor-positioning.js +4 -0
- package/dist/utils/supports-anchor-positioning.js.map +1 -0
- package/dist/utils/transform-violations.d.ts +4 -0
- package/dist/utils/transform-violations.d.ts.map +1 -0
- package/dist/utils/transform-violations.js +61 -0
- package/dist/utils/transform-violations.js.map +1 -0
- package/dist/utils/update-elements-with-issues.d.ts +13 -0
- package/dist/utils/update-elements-with-issues.d.ts.map +1 -0
- package/dist/utils/update-elements-with-issues.js +96 -0
- package/dist/utils/update-elements-with-issues.js.map +1 -0
- package/dist/validate-options.d.ts +3 -0
- package/dist/validate-options.d.ts.map +1 -0
- package/dist/validate-options.js +129 -0
- package/dist/validate-options.js.map +1 -0
- package/package.json +21 -8
- package/src/accented.test.ts +24 -0
- package/src/accented.ts +130 -0
- package/src/common/tokens.ts +10 -0
- package/src/constants.ts +3 -0
- package/src/dom-updater.ts +165 -0
- package/src/elements/accented-dialog.ts +419 -0
- package/src/elements/accented-trigger.ts +251 -0
- package/src/fullscreen-listener.ts +21 -0
- package/src/intersection-observer.ts +39 -0
- package/src/log-and-rethrow.ts +8 -0
- package/src/logger.ts +36 -0
- package/src/register-elements.ts +21 -0
- package/src/resize-listener.ts +21 -0
- package/src/scanner.ts +195 -0
- package/src/scroll-listeners.ts +45 -0
- package/src/state.ts +35 -0
- package/src/task-queue.test.ts +136 -0
- package/src/task-queue.ts +61 -0
- package/src/types.ts +258 -0
- package/src/utils/are-elements-with-issues-equal.ts +11 -0
- package/src/utils/are-issue-sets-equal.test.ts +53 -0
- package/src/utils/are-issue-sets-equal.ts +12 -0
- package/src/utils/containing-blocks.ts +60 -0
- package/src/utils/contains.test.ts +54 -0
- package/src/utils/contains.ts +19 -0
- package/src/utils/deduplicate-nodes.ts +3 -0
- package/src/utils/deep-merge.test.ts +41 -0
- package/src/utils/deep-merge.ts +24 -0
- package/src/utils/dom-helpers.ts +42 -0
- package/src/utils/ensure-non-empty.ts +6 -0
- package/src/utils/get-element-html.ts +15 -0
- package/src/utils/get-element-position.ts +89 -0
- package/src/utils/get-parent.ts +14 -0
- package/src/utils/get-scan-context.test.ts +85 -0
- package/src/utils/get-scan-context.ts +36 -0
- package/src/utils/get-scrollable-ancestors.ts +22 -0
- package/src/utils/is-node-in-scan-context.test.ts +70 -0
- package/src/utils/is-node-in-scan-context.ts +29 -0
- package/src/utils/is-non-empty.ts +3 -0
- package/src/utils/normalize-context.test.ts +105 -0
- package/src/utils/normalize-context.ts +65 -0
- package/src/utils/recalculate-positions.ts +27 -0
- package/src/utils/recalculate-scrollable-ancestors.ts +13 -0
- package/src/utils/shadow-dom-aware-mutation-observer.ts +75 -0
- package/src/utils/supports-anchor-positioning.ts +7 -0
- package/src/utils/transform-violations.test.ts +128 -0
- package/src/utils/transform-violations.ts +74 -0
- package/src/utils/update-elements-with-issues.test.ts +371 -0
- package/src/utils/update-elements-with-issues.ts +144 -0
- package/src/validate-options.ts +184 -0
- package/dist/utils/issuesToElements.d.ts +0 -3
- package/dist/utils/issuesToElements.d.ts.map +0 -1
- package/dist/utils/issuesToElements.js +0 -16
- package/dist/utils/issuesToElements.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-options.d.ts","sourceRoot":"","sources":["../src/validate-options.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EAMhB,MAAM,YAAY,CAAC;AA+GpB,wBAAgB,eAAe,CAAC,OAAO,EAAE,eAAe,QAgEvD"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { allowedAxeOptions } from './types.js';
|
|
2
|
+
import { isNode, isNodeList } from './utils/dom-helpers.js';
|
|
3
|
+
function isSelector(contextFragment) {
|
|
4
|
+
return (typeof contextFragment === 'string' ||
|
|
5
|
+
isNode(contextFragment) ||
|
|
6
|
+
'fromShadowDom' in contextFragment);
|
|
7
|
+
}
|
|
8
|
+
function validateSelector(selector) {
|
|
9
|
+
if (typeof selector === 'string') {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (isNode(selector)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if ('fromShadowDom' in selector) {
|
|
16
|
+
if (!Array.isArray(selector.fromShadowDom) ||
|
|
17
|
+
selector.fromShadowDom.length < 2 ||
|
|
18
|
+
!selector.fromShadowDom.every((item) => typeof item === 'string')) {
|
|
19
|
+
throw new TypeError(`Accented: invalid argument. \`fromShadowDom\` must be an array of strings with at least 2 elements. It’s currently set to ${selector.fromShadowDom}.`);
|
|
20
|
+
}
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const neverSelector = selector;
|
|
24
|
+
throw new TypeError(`Accented: invalid argument. The selector must be one of: string, Node, or an object with a \`fromShadowDom\` property. It’s currently set to ${neverSelector}.`);
|
|
25
|
+
}
|
|
26
|
+
function isSelectorList(contextFragment) {
|
|
27
|
+
return ((typeof contextFragment === 'object' && isNodeList(contextFragment)) ||
|
|
28
|
+
(Array.isArray(contextFragment) && contextFragment.every((item) => isSelector(item))));
|
|
29
|
+
}
|
|
30
|
+
function validateSelectorList(selectorList) {
|
|
31
|
+
if (isNodeList(selectorList)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (Array.isArray(selectorList)) {
|
|
35
|
+
for (const selector of selectorList) {
|
|
36
|
+
validateSelector(selector);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const neverSelectorList = selectorList;
|
|
41
|
+
throw new TypeError(`Accented: invalid argument. The selector list must either be a NodeList or an array. It’s currently set to ${neverSelectorList}.`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function isContextProp(contextFragment) {
|
|
45
|
+
return isSelector(contextFragment) || isSelectorList(contextFragment);
|
|
46
|
+
}
|
|
47
|
+
function validateContextProp(context) {
|
|
48
|
+
if (isSelector(context)) {
|
|
49
|
+
validateSelector(context);
|
|
50
|
+
}
|
|
51
|
+
else if (isSelectorList(context)) {
|
|
52
|
+
validateSelectorList(context);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const neverContext = context;
|
|
56
|
+
throw new TypeError(`Accented: invalid argument. The context property must either be a selector or a selector list. It’s currently set to ${neverContext}.`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function isContextObject(contextFragment) {
|
|
60
|
+
return (typeof contextFragment === 'object' &&
|
|
61
|
+
contextFragment !== null &&
|
|
62
|
+
('include' in contextFragment || 'exclude' in contextFragment));
|
|
63
|
+
}
|
|
64
|
+
function validateContextObject(contextObject) {
|
|
65
|
+
if ('include' in contextObject && contextObject.include !== undefined) {
|
|
66
|
+
validateContextProp(contextObject.include);
|
|
67
|
+
}
|
|
68
|
+
if ('exclude' in contextObject && contextObject.exclude !== undefined) {
|
|
69
|
+
validateContextProp(contextObject.exclude);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function validateContext(context) {
|
|
73
|
+
if (isContextProp(context)) {
|
|
74
|
+
validateContextProp(context);
|
|
75
|
+
}
|
|
76
|
+
else if (isContextObject(context)) {
|
|
77
|
+
validateContextObject(context);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const neverContext = context;
|
|
81
|
+
throw new TypeError(`Accented: invalid context argument. It’s currently set to ${neverContext}.`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// The space of valid CSS and HTML names is wider than this,
|
|
85
|
+
// but with Unicode it gets complicated quickly, so I'm sticking to only allowing
|
|
86
|
+
// lowercase alphanumeric names that possibly contain dashes that start with a letter.
|
|
87
|
+
const nameRegex = /^[a-z]([a-z0-9]|-)+$/;
|
|
88
|
+
export function validateOptions(options) {
|
|
89
|
+
if (typeof options !== 'object' || options === null) {
|
|
90
|
+
throw new TypeError(`Accented: invalid argument. The options parameter must be an object if provided. It’s currently set to ${options}.`);
|
|
91
|
+
}
|
|
92
|
+
if (options.throttle !== undefined) {
|
|
93
|
+
if (typeof options.throttle !== 'object' || options.throttle === null) {
|
|
94
|
+
throw new TypeError(`Accented: invalid argument. \`throttle\` option must be an object if provided. It’s currently set to ${options.throttle}.`);
|
|
95
|
+
}
|
|
96
|
+
if (options.throttle.wait !== undefined &&
|
|
97
|
+
(typeof options.throttle.wait !== 'number' || options.throttle.wait < 0)) {
|
|
98
|
+
throw new TypeError(`Accented: invalid argument. \`throttle.wait\` option must be a non-negative number if provided. It’s currently set to ${options.throttle.wait}.`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (options.output !== undefined) {
|
|
102
|
+
if (typeof options.output !== 'object' || options.output === null) {
|
|
103
|
+
throw new TypeError(`Accented: invalid argument. \`output\` option must be an object if provided. It’s currently set to ${options.output}.`);
|
|
104
|
+
}
|
|
105
|
+
if (options.output.console !== undefined && typeof options.output.console !== 'boolean') {
|
|
106
|
+
console.warn(`Accented: invalid argument. \`output.console\` option is expected to be a boolean. It’s currently set to ${options.output.console}.`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (options.callback !== undefined && typeof options.callback !== 'function') {
|
|
110
|
+
throw new TypeError(`Accented: invalid argument. \`callback\` option must be a function if provided. It’s currently set to ${options.callback}.`);
|
|
111
|
+
}
|
|
112
|
+
if (options.name !== undefined &&
|
|
113
|
+
(typeof options.name !== 'string' || !options.name.match(nameRegex))) {
|
|
114
|
+
throw new TypeError(`Accented: invalid argument. \`name\` option must be a string that starts with a lowercase letter and only contains lowercase alphanumeric characters and dashes. It’s currently set to ${options.name}.`);
|
|
115
|
+
}
|
|
116
|
+
if (options.axeOptions !== undefined) {
|
|
117
|
+
if (typeof options.axeOptions !== 'object' || options.axeOptions === null) {
|
|
118
|
+
throw new TypeError(`Accented: invalid argument. \`axeOptions\` option must be an object if provided. It’s currently set to ${options.axeOptions}.`);
|
|
119
|
+
}
|
|
120
|
+
const unsupportedKeys = Object.keys(options.axeOptions).filter((key) => !allowedAxeOptions.includes(key));
|
|
121
|
+
if (unsupportedKeys.length > 0) {
|
|
122
|
+
throw new TypeError(`Accented: invalid argument. \`axeOptions\` contains the following unsupported keys: ${unsupportedKeys.join(', ')}. Valid options are: ${allowedAxeOptions.join(', ')}.`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (options.context !== undefined) {
|
|
126
|
+
validateContext(options.context);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=validate-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-options.js","sourceRoot":"","sources":["../src/validate-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAS/C,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAE5D,SAAS,UAAU,CAAC,eAAwB;IAC1C,OAAO,CACL,OAAO,eAAe,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AAG,CAAC,CACxE,CAAC;QACF,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,SAAS,CACjB,uFAAuF,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,wBAAwB,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CACzK,CAAC;QACJ,CAAC;IACH,CAAC;IACD,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAClC,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "accented",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A frontend library for continuous accessibility testing and issue highlighting",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/accented.js",
|
|
7
7
|
"files": [
|
|
8
|
-
"dist"
|
|
8
|
+
"dist",
|
|
9
|
+
"src",
|
|
10
|
+
"NOTICE"
|
|
9
11
|
],
|
|
10
12
|
"repository": {
|
|
11
13
|
"type": "git",
|
|
@@ -14,6 +16,7 @@
|
|
|
14
16
|
"keywords": [
|
|
15
17
|
"accessibility",
|
|
16
18
|
"a11y",
|
|
19
|
+
"a11y-testing",
|
|
17
20
|
"axe",
|
|
18
21
|
"axe-core"
|
|
19
22
|
],
|
|
@@ -22,13 +25,23 @@
|
|
|
22
25
|
"bugs": {
|
|
23
26
|
"url": "https://github.com/pomerantsev/accented/issues"
|
|
24
27
|
},
|
|
25
|
-
"homepage": "https://
|
|
28
|
+
"homepage": "https://www.accented.dev",
|
|
26
29
|
"dependencies": {
|
|
27
|
-
"
|
|
30
|
+
"@preact/signals-core": "^1.8.0",
|
|
31
|
+
"axe-core": "^4.10.3"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/jsdom": "^21.1.7",
|
|
35
|
+
"jsdom": "^26.0.0"
|
|
28
36
|
},
|
|
29
37
|
"scripts": {
|
|
30
|
-
"build": "
|
|
31
|
-
"
|
|
32
|
-
"
|
|
38
|
+
"build": "pnpm copyCommon && tsc",
|
|
39
|
+
"copyCommon": "node --import tsx ./scripts/copy-common.ts",
|
|
40
|
+
"watchCommon": "node --import tsx ./scripts/watch-common.ts",
|
|
41
|
+
"checkBuiltFiles": "node --import tsx ./scripts/check-built-files.ts",
|
|
42
|
+
"checkImportsInBuiltFiles": "node ./dist/accented.js",
|
|
43
|
+
"typecheckTests": "tsc -p ./tsconfig.test.json",
|
|
44
|
+
"watch": "pnpm copyCommon && (pnpm watchCommon & tsc --watch)",
|
|
45
|
+
"test": "node --test --import tsx \"./**/*.test.ts\""
|
|
33
46
|
}
|
|
34
47
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { suite, test } from 'node:test';
|
|
3
|
+
import type { Mock } from 'node:test';
|
|
4
|
+
|
|
5
|
+
import { accented } from './accented';
|
|
6
|
+
|
|
7
|
+
suite('Accented', () => {
|
|
8
|
+
test('runs without errors in NodeJS and issues a warning and a trace (it’s meant to be a no-op on the server side)', (t) => {
|
|
9
|
+
t.mock.method(console, 'warn', () => {});
|
|
10
|
+
t.mock.method(console, 'trace', () => {});
|
|
11
|
+
accented();
|
|
12
|
+
assert.equal((console.warn as Mock<() => void>).mock.callCount(), 1);
|
|
13
|
+
assert.equal((console.trace as Mock<() => void>).mock.callCount(), 1);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
suite('argument validation', () => {
|
|
17
|
+
// @ts-expect-error
|
|
18
|
+
assert.throws(() => accented({ throttle: null }));
|
|
19
|
+
// @ts-expect-error
|
|
20
|
+
assert.throws(() => accented({ throttle: 1000 }));
|
|
21
|
+
|
|
22
|
+
assert.throws(() => accented({ throttle: { wait: -1 } }));
|
|
23
|
+
});
|
|
24
|
+
});
|
package/src/accented.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { createDomUpdater } from './dom-updater.js';
|
|
2
|
+
import { setupResizeListener as setupFullscreenListener } from './fullscreen-listener.js';
|
|
3
|
+
import { setupIntersectionObserver } from './intersection-observer.js';
|
|
4
|
+
import { logAndRethrow } from './log-and-rethrow.js';
|
|
5
|
+
import { createLogger } from './logger.js';
|
|
6
|
+
import { registerElements } from './register-elements.js';
|
|
7
|
+
import { setupResizeListener } from './resize-listener.js';
|
|
8
|
+
import { createScanner } from './scanner.js';
|
|
9
|
+
import { setupScrollListeners } from './scroll-listeners.js';
|
|
10
|
+
import { enabled, extendedElementsWithIssues } from './state.js';
|
|
11
|
+
import type { AccentedOptions, DisableAccented } from './types.ts';
|
|
12
|
+
import { initializeContainingBlockSupportSet } from './utils/containing-blocks.js';
|
|
13
|
+
import { deepMerge } from './utils/deep-merge.js';
|
|
14
|
+
import { supportsAnchorPositioning } from './utils/supports-anchor-positioning.js';
|
|
15
|
+
import { validateOptions } from './validate-options.js';
|
|
16
|
+
|
|
17
|
+
export type { AccentedOptions, DisableAccented };
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Enables the continuous scanning and highlighting of accessibility issues on the page.
|
|
21
|
+
*
|
|
22
|
+
* @param {AccentedOptions} options - The options object (optional).
|
|
23
|
+
*
|
|
24
|
+
* @returns A `disable` function that takes no parameters. When called, disables the scanning and highlighting, and cleans up any changes that Accented has made to the page.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* accented();
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const disableAccented = accented({
|
|
31
|
+
* output: {
|
|
32
|
+
* console: false
|
|
33
|
+
* },
|
|
34
|
+
* throttle: {
|
|
35
|
+
* wait: 500,
|
|
36
|
+
* leading: false
|
|
37
|
+
* },
|
|
38
|
+
* callback: ({ elementsWithIssues, performance }) => {
|
|
39
|
+
* console.log('Elements with issues:', elementsWithIssues);
|
|
40
|
+
* console.log('Total blocking time:', performance.totalBlockingTime);
|
|
41
|
+
* }
|
|
42
|
+
* });
|
|
43
|
+
*/
|
|
44
|
+
export function accented(options: AccentedOptions = {}): DisableAccented {
|
|
45
|
+
validateOptions(options);
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
49
|
+
console.warn(
|
|
50
|
+
'Accented: this script can only run in the browser, and it’s likely running on the server now. Exiting.',
|
|
51
|
+
);
|
|
52
|
+
console.trace();
|
|
53
|
+
return () => {};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const defaultOutput: Required<AccentedOptions['output']> = {
|
|
57
|
+
console: true,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const defaultThrottle: Required<AccentedOptions['throttle']> = {
|
|
61
|
+
wait: 1000,
|
|
62
|
+
leading: true,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// IMPORTANT: when changing any of the properties or values, also do the following:
|
|
66
|
+
// * update the default value in the type documentation accordingly;
|
|
67
|
+
// * update validations and validation tests if necessary;
|
|
68
|
+
// * update examples in the accented() function JSDoc;
|
|
69
|
+
// * update examples in the Readme.
|
|
70
|
+
const defaultOptions: Required<AccentedOptions> = {
|
|
71
|
+
context: document,
|
|
72
|
+
axeOptions: {},
|
|
73
|
+
name: 'accented',
|
|
74
|
+
output: defaultOutput,
|
|
75
|
+
throttle: defaultThrottle,
|
|
76
|
+
callback: () => {},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const { context, axeOptions, name, output, throttle, callback } = deepMerge(
|
|
80
|
+
defaultOptions,
|
|
81
|
+
options,
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
if (enabled.value) {
|
|
85
|
+
console.warn(
|
|
86
|
+
'You are trying to run the Accented library more than once, which may lead to errors. See https://www.accented.dev/getting-started#run-once-per-page',
|
|
87
|
+
);
|
|
88
|
+
console.trace();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
enabled.value = true;
|
|
92
|
+
|
|
93
|
+
initializeContainingBlockSupportSet();
|
|
94
|
+
registerElements(name);
|
|
95
|
+
|
|
96
|
+
const { disconnect: cleanupIntersectionObserver, intersectionObserver } =
|
|
97
|
+
setupIntersectionObserver();
|
|
98
|
+
const cleanupScanner = createScanner(name, context, axeOptions, throttle, callback);
|
|
99
|
+
const cleanupDomUpdater = createDomUpdater(name, intersectionObserver);
|
|
100
|
+
const cleanupLogger = output.console ? createLogger() : () => {};
|
|
101
|
+
const cleanupScrollListeners = setupScrollListeners();
|
|
102
|
+
const cleanupResizeListener = supportsAnchorPositioning(window)
|
|
103
|
+
? () => {}
|
|
104
|
+
: setupResizeListener();
|
|
105
|
+
const cleanupFullscreenListener = supportsAnchorPositioning(window)
|
|
106
|
+
? () => {}
|
|
107
|
+
: setupFullscreenListener();
|
|
108
|
+
|
|
109
|
+
return () => {
|
|
110
|
+
try {
|
|
111
|
+
enabled.value = false;
|
|
112
|
+
extendedElementsWithIssues.value = [];
|
|
113
|
+
cleanupScanner();
|
|
114
|
+
cleanupDomUpdater();
|
|
115
|
+
cleanupLogger();
|
|
116
|
+
cleanupScrollListeners();
|
|
117
|
+
cleanupResizeListener();
|
|
118
|
+
cleanupFullscreenListener();
|
|
119
|
+
if (cleanupIntersectionObserver) {
|
|
120
|
+
cleanupIntersectionObserver();
|
|
121
|
+
}
|
|
122
|
+
} catch (error) {
|
|
123
|
+
logAndRethrow(error);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
} catch (error) {
|
|
127
|
+
logAndRethrow(error);
|
|
128
|
+
return () => {};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const primaryColorDark = 'oklch(0.5 0.3 0)';
|
|
2
|
+
export const primaryColorLight = 'oklch(0.8 0.2 0)';
|
|
3
|
+
export const colorLight = 'oklch(0.98 0 0)';
|
|
4
|
+
export const colorDark = 'oklch(0.22 0 0)';
|
|
5
|
+
|
|
6
|
+
/* https://systemfontstack.com/ */
|
|
7
|
+
export const fontSystemSans =
|
|
8
|
+
'-apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, Adwaita Sans, Cantarell, Ubuntu, roboto, noto, helvetica, arial, sans-serif';
|
|
9
|
+
export const fontSystemMono =
|
|
10
|
+
'Menlo, Consolas, Monaco, Adwaita Mono, Liberation Mono, Lucida Console, monospace';
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { effect } from '@preact/signals-core';
|
|
2
|
+
import { primaryColorDark } from './common/tokens.js';
|
|
3
|
+
import { extendedElementsWithIssues, rootNodes } from './state.js';
|
|
4
|
+
import type { ExtendedElementWithIssues } from './types.ts';
|
|
5
|
+
import { areElementsWithIssuesEqual } from './utils/are-elements-with-issues-equal.js';
|
|
6
|
+
import { isDocument, isDocumentFragment, isShadowRoot } from './utils/dom-helpers.js';
|
|
7
|
+
import { getParent } from './utils/get-parent.js';
|
|
8
|
+
import { supportsAnchorPositioning } from './utils/supports-anchor-positioning.js';
|
|
9
|
+
|
|
10
|
+
const shouldInsertTriggerInsideElement = (element: Element): boolean => {
|
|
11
|
+
/**
|
|
12
|
+
* No parent means that the element is a root node,
|
|
13
|
+
* which cannot have siblings.
|
|
14
|
+
*/
|
|
15
|
+
const noParent = !getParent(element);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Table cells get a special treatment because if a sibling to a TH or TD is inserted,
|
|
19
|
+
* it alters the table layout, no matter how that sibling is positioned.
|
|
20
|
+
* We don't want tables to look broken, so we're inserting the trigger inside the table cell.
|
|
21
|
+
*/
|
|
22
|
+
const isTableCell = element.nodeName === 'TH' || element.nodeName === 'TD';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* We want to put the trigger inside the <summary> element,
|
|
26
|
+
* because otherwise it will be hidden by the browser when the <details> element is collapsed
|
|
27
|
+
* (since none of the siblings of <summary> are visible then).
|
|
28
|
+
*/
|
|
29
|
+
const isSummary = element.nodeName === 'SUMMARY';
|
|
30
|
+
|
|
31
|
+
return noParent || isTableCell || isSummary;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export function createDomUpdater(name: string, intersectionObserver?: IntersectionObserver) {
|
|
35
|
+
const attrName = `data-${name}`;
|
|
36
|
+
|
|
37
|
+
function getAnchorNames(anchorNameValue: string) {
|
|
38
|
+
return anchorNameValue
|
|
39
|
+
.split(',')
|
|
40
|
+
.map((anchorName) => anchorName.trim())
|
|
41
|
+
.filter((anchorName) => anchorName.startsWith('--'));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function setAnchorName(elementWithIssues: ExtendedElementWithIssues) {
|
|
45
|
+
const { element, id, anchorNameValue } = elementWithIssues;
|
|
46
|
+
const anchorNames = getAnchorNames(anchorNameValue);
|
|
47
|
+
if (anchorNames.length > 0) {
|
|
48
|
+
element.style.setProperty('anchor-name', `${anchorNameValue}, --${name}-anchor-${id}`);
|
|
49
|
+
} else {
|
|
50
|
+
element.style.setProperty('anchor-name', `--${name}-anchor-${id}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function removeAnchorName(elementWithIssues: ExtendedElementWithIssues) {
|
|
55
|
+
const { element, anchorNameValue } = elementWithIssues;
|
|
56
|
+
const anchorNames = getAnchorNames(anchorNameValue);
|
|
57
|
+
if (anchorNames.length > 0) {
|
|
58
|
+
element.style.setProperty('anchor-name', anchorNames.join(', '));
|
|
59
|
+
} else {
|
|
60
|
+
element.style.removeProperty('anchor-name');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function setIssues(extendedElementsWithIssues: Array<ExtendedElementWithIssues>) {
|
|
65
|
+
for (const elementWithIssues of extendedElementsWithIssues) {
|
|
66
|
+
if (elementWithIssues.skipRender) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
elementWithIssues.element.setAttribute(attrName, elementWithIssues.id.toString());
|
|
70
|
+
if (supportsAnchorPositioning(window)) {
|
|
71
|
+
setAnchorName(elementWithIssues);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (shouldInsertTriggerInsideElement(elementWithIssues.element)) {
|
|
75
|
+
elementWithIssues.element.insertAdjacentElement('beforeend', elementWithIssues.trigger);
|
|
76
|
+
} else {
|
|
77
|
+
elementWithIssues.element.insertAdjacentElement('afterend', elementWithIssues.trigger);
|
|
78
|
+
}
|
|
79
|
+
if (intersectionObserver) {
|
|
80
|
+
intersectionObserver.observe(elementWithIssues.element);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function removeIssues(extendedElementsWithIssues: Array<ExtendedElementWithIssues>) {
|
|
86
|
+
for (const elementWithIssues of extendedElementsWithIssues) {
|
|
87
|
+
if (elementWithIssues.skipRender) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
elementWithIssues.element.removeAttribute(attrName);
|
|
91
|
+
if (supportsAnchorPositioning(window)) {
|
|
92
|
+
removeAnchorName(elementWithIssues);
|
|
93
|
+
}
|
|
94
|
+
elementWithIssues.trigger.remove();
|
|
95
|
+
if (intersectionObserver) {
|
|
96
|
+
intersectionObserver.unobserve(elementWithIssues.element);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const stylesheet = new CSSStyleSheet();
|
|
102
|
+
stylesheet.replaceSync(`
|
|
103
|
+
@layer ${name} {
|
|
104
|
+
:root {
|
|
105
|
+
/* Ensure that the primary / secondary color combination meets WCAG 1.4.3 Contrast (Minimum) */
|
|
106
|
+
/* OKLCH stuff: https://oklch.com/ */
|
|
107
|
+
--${name}-primary-color: ${primaryColorDark};
|
|
108
|
+
--${name}-secondary-color: oklch(0.98 0 0);
|
|
109
|
+
--${name}-outline-width: 2px;
|
|
110
|
+
--${name}-outline-style: solid;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
[${attrName}]:not(:focus-visible) {
|
|
114
|
+
outline-width: var(--${name}-outline-width) !important;
|
|
115
|
+
outline-offset: calc(-1 * var(--${name}-outline-width)) !important;
|
|
116
|
+
outline-color: var(--${name}-primary-color) !important;
|
|
117
|
+
outline-style: var(--${name}-outline-style) !important;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
`);
|
|
121
|
+
|
|
122
|
+
let previousExtendedElementsWithIssues: Array<ExtendedElementWithIssues> = [];
|
|
123
|
+
|
|
124
|
+
let previousRootNodes: Set<Node> = new Set();
|
|
125
|
+
|
|
126
|
+
const disposeOfStyleSheetsEffect = effect(() => {
|
|
127
|
+
const newRootNodes = rootNodes.value;
|
|
128
|
+
const addedRootNodes = [...newRootNodes].filter((rootNode) => !previousRootNodes.has(rootNode));
|
|
129
|
+
const removedRootNodes = [...previousRootNodes].filter(
|
|
130
|
+
(rootNode) => !newRootNodes.has(rootNode),
|
|
131
|
+
);
|
|
132
|
+
for (const rootNode of addedRootNodes) {
|
|
133
|
+
if (isDocument(rootNode) || (isDocumentFragment(rootNode) && isShadowRoot(rootNode))) {
|
|
134
|
+
rootNode.adoptedStyleSheets.push(stylesheet);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
for (const rootNode of removedRootNodes) {
|
|
138
|
+
if (isDocument(rootNode) || (isDocumentFragment(rootNode) && isShadowRoot(rootNode))) {
|
|
139
|
+
rootNode.adoptedStyleSheets.splice(rootNode.adoptedStyleSheets.indexOf(stylesheet), 1);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
previousRootNodes = newRootNodes;
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const disposeOfElementsEffect = effect(() => {
|
|
146
|
+
const added = extendedElementsWithIssues.value.filter((elementWithIssues) => {
|
|
147
|
+
return !previousExtendedElementsWithIssues.some((previousElementWithIssues) =>
|
|
148
|
+
areElementsWithIssuesEqual(previousElementWithIssues, elementWithIssues),
|
|
149
|
+
);
|
|
150
|
+
});
|
|
151
|
+
const removed = previousExtendedElementsWithIssues.filter((previousElementWithIssues) => {
|
|
152
|
+
return !extendedElementsWithIssues.value.some((elementWithIssues) =>
|
|
153
|
+
areElementsWithIssuesEqual(elementWithIssues, previousElementWithIssues),
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
removeIssues(removed);
|
|
157
|
+
setIssues(added);
|
|
158
|
+
previousExtendedElementsWithIssues = [...extendedElementsWithIssues.value];
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
return () => {
|
|
162
|
+
disposeOfStyleSheetsEffect();
|
|
163
|
+
disposeOfElementsEffect();
|
|
164
|
+
};
|
|
165
|
+
}
|