accented 0.0.0-20250424114613 → 0.0.0-20250701143712
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/README.md +44 -193
- package/dist/accented.d.ts +7 -7
- package/dist/accented.d.ts.map +1 -1
- package/dist/accented.js +30 -27
- package/dist/accented.js.map +1 -1
- package/dist/common/tokens.d.ts +2 -0
- package/dist/common/tokens.d.ts.map +1 -0
- package/dist/common/tokens.js +2 -0
- package/dist/common/tokens.js.map +1 -0
- package/dist/constants.d.ts +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +1 -1
- package/dist/constants.js.map +1 -1
- package/dist/dom-updater.d.ts +1 -1
- package/dist/dom-updater.d.ts.map +1 -1
- package/dist/dom-updater.js +14 -13
- package/dist/dom-updater.js.map +1 -1
- package/dist/elements/accented-dialog.d.ts +2 -3
- package/dist/elements/accented-dialog.d.ts.map +1 -1
- package/dist/elements/accented-dialog.js +14 -8
- package/dist/elements/accented-dialog.js.map +1 -1
- package/dist/elements/accented-trigger.d.ts +3 -4
- package/dist/elements/accented-trigger.d.ts.map +1 -1
- package/dist/elements/accented-trigger.js +10 -10
- package/dist/elements/accented-trigger.js.map +1 -1
- package/dist/fullscreen-listener.d.ts +1 -1
- package/dist/fullscreen-listener.d.ts.map +1 -1
- package/dist/fullscreen-listener.js +3 -4
- package/dist/fullscreen-listener.js.map +1 -1
- package/dist/intersection-observer.d.ts +1 -1
- package/dist/intersection-observer.d.ts.map +1 -1
- package/dist/intersection-observer.js +12 -6
- package/dist/intersection-observer.js.map +1 -1
- package/dist/log-and-rethrow.d.ts +1 -1
- package/dist/log-and-rethrow.d.ts.map +1 -1
- package/dist/log-and-rethrow.js +2 -3
- package/dist/log-and-rethrow.js.map +1 -1
- package/dist/logger.d.ts +1 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +2 -2
- package/dist/logger.js.map +1 -1
- package/dist/register-elements.d.ts +1 -1
- package/dist/register-elements.d.ts.map +1 -1
- package/dist/register-elements.js +6 -7
- package/dist/register-elements.js.map +1 -1
- package/dist/resize-listener.d.ts +1 -1
- package/dist/resize-listener.d.ts.map +1 -1
- package/dist/resize-listener.js +3 -4
- package/dist/resize-listener.js.map +1 -1
- package/dist/scanner.d.ts +2 -2
- package/dist/scanner.d.ts.map +1 -1
- package/dist/scanner.js +36 -36
- package/dist/scanner.js.map +1 -1
- package/dist/scroll-listeners.d.ts +1 -1
- package/dist/scroll-listeners.d.ts.map +1 -1
- package/dist/scroll-listeners.js +3 -4
- package/dist/scroll-listeners.js.map +1 -1
- package/dist/state.d.ts +1 -1
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +4 -5
- package/dist/state.js.map +1 -1
- package/dist/task-queue.d.ts +2 -2
- package/dist/task-queue.d.ts.map +1 -1
- package/dist/task-queue.js +1 -1
- package/dist/task-queue.js.map +1 -1
- package/dist/types.d.ts +102 -46
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/are-elements-with-issues-equal.d.ts +2 -2
- package/dist/utils/are-elements-with-issues-equal.d.ts.map +1 -1
- package/dist/utils/are-elements-with-issues-equal.js +3 -3
- package/dist/utils/are-elements-with-issues-equal.js.map +1 -1
- package/dist/utils/are-issue-sets-equal.d.ts +2 -2
- package/dist/utils/are-issue-sets-equal.d.ts.map +1 -1
- package/dist/utils/are-issue-sets-equal.js +3 -3
- package/dist/utils/are-issue-sets-equal.js.map +1 -1
- package/dist/utils/containing-blocks.d.ts.map +1 -1
- package/dist/utils/containing-blocks.js +1 -1
- package/dist/utils/containing-blocks.js.map +1 -1
- package/dist/utils/contains.d.ts +1 -1
- package/dist/utils/contains.d.ts.map +1 -1
- package/dist/utils/contains.js +1 -1
- package/dist/utils/contains.js.map +1 -1
- package/dist/utils/deduplicate-nodes.js +0 -1
- package/dist/utils/deduplicate-nodes.js.map +1 -1
- package/dist/utils/deep-merge.d.ts +1 -1
- package/dist/utils/deep-merge.d.ts.map +1 -1
- package/dist/utils/deep-merge.js +8 -5
- package/dist/utils/deep-merge.js.map +1 -1
- package/dist/utils/dom-helpers.d.ts.map +1 -1
- package/dist/utils/dom-helpers.js +4 -2
- package/dist/utils/dom-helpers.js.map +1 -1
- package/dist/utils/ensure-non-empty.d.ts +1 -1
- package/dist/utils/ensure-non-empty.d.ts.map +1 -1
- package/dist/utils/ensure-non-empty.js +2 -2
- package/dist/utils/ensure-non-empty.js.map +1 -1
- package/dist/utils/get-element-html.d.ts +1 -1
- package/dist/utils/get-element-html.d.ts.map +1 -1
- package/dist/utils/get-element-html.js +4 -2
- package/dist/utils/get-element-html.js.map +1 -1
- package/dist/utils/get-element-position.d.ts +2 -2
- package/dist/utils/get-element-position.d.ts.map +1 -1
- package/dist/utils/get-element-position.js +21 -25
- package/dist/utils/get-element-position.js.map +1 -1
- package/dist/utils/get-parent.d.ts +1 -1
- package/dist/utils/get-parent.d.ts.map +1 -1
- package/dist/utils/get-parent.js +1 -1
- package/dist/utils/get-parent.js.map +1 -1
- package/dist/utils/get-scan-context.d.ts +2 -2
- package/dist/utils/get-scan-context.d.ts.map +1 -1
- package/dist/utils/get-scan-context.js +9 -9
- package/dist/utils/get-scan-context.js.map +1 -1
- package/dist/utils/get-scrollable-ancestors.d.ts +1 -1
- package/dist/utils/get-scrollable-ancestors.d.ts.map +1 -1
- package/dist/utils/get-scrollable-ancestors.js +5 -5
- package/dist/utils/get-scrollable-ancestors.js.map +1 -1
- package/dist/utils/is-node-in-scan-context.d.ts +2 -2
- package/dist/utils/is-node-in-scan-context.d.ts.map +1 -1
- package/dist/utils/is-node-in-scan-context.js +5 -5
- package/dist/utils/is-node-in-scan-context.js.map +1 -1
- 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 +2 -2
- package/dist/utils/normalize-context.d.ts.map +1 -1
- package/dist/utils/normalize-context.js +10 -8
- package/dist/utils/normalize-context.js.map +1 -1
- package/dist/utils/recalculate-positions.d.ts +1 -1
- package/dist/utils/recalculate-positions.d.ts.map +1 -1
- package/dist/utils/recalculate-positions.js +5 -5
- package/dist/utils/recalculate-positions.js.map +1 -1
- package/dist/utils/recalculate-scrollable-ancestors.d.ts +1 -1
- package/dist/utils/recalculate-scrollable-ancestors.d.ts.map +1 -1
- package/dist/utils/recalculate-scrollable-ancestors.js +4 -4
- package/dist/utils/recalculate-scrollable-ancestors.js.map +1 -1
- package/dist/utils/shadow-dom-aware-mutation-observer.d.ts +1 -1
- package/dist/utils/shadow-dom-aware-mutation-observer.d.ts.map +1 -1
- package/dist/utils/shadow-dom-aware-mutation-observer.js +19 -22
- package/dist/utils/shadow-dom-aware-mutation-observer.js.map +1 -1
- package/dist/utils/supports-anchor-positioning.d.ts +1 -1
- package/dist/utils/supports-anchor-positioning.d.ts.map +1 -1
- package/dist/utils/supports-anchor-positioning.js +1 -1
- package/dist/utils/supports-anchor-positioning.js.map +1 -1
- package/dist/utils/transform-violations.d.ts +2 -2
- package/dist/utils/transform-violations.d.ts.map +1 -1
- package/dist/utils/transform-violations.js +9 -9
- package/dist/utils/transform-violations.js.map +1 -1
- package/dist/utils/update-elements-with-issues.d.ts +3 -3
- package/dist/utils/update-elements-with-issues.d.ts.map +1 -1
- package/dist/utils/update-elements-with-issues.js +34 -29
- package/dist/utils/update-elements-with-issues.js.map +1 -1
- package/dist/validate-options.d.ts +2 -2
- package/dist/validate-options.d.ts.map +1 -1
- package/dist/validate-options.js +24 -23
- package/dist/validate-options.js.map +1 -1
- package/package.json +7 -4
- package/src/accented.test.ts +2 -2
- package/src/accented.ts +39 -32
- package/src/common/tokens.ts +1 -0
- package/src/constants.ts +1 -1
- package/src/dom-updater.ts +26 -19
- package/src/elements/accented-dialog.ts +69 -43
- package/src/elements/accented-trigger.ts +54 -43
- package/src/fullscreen-listener.ts +15 -11
- package/src/intersection-observer.ts +27 -16
- package/src/log-and-rethrow.ts +2 -3
- package/src/logger.ts +8 -6
- package/src/register-elements.ts +7 -7
- package/src/resize-listener.ts +15 -11
- package/src/scanner.ts +66 -50
- package/src/scroll-listeners.ts +27 -19
- package/src/state.ts +24 -21
- package/src/task-queue.test.ts +5 -4
- package/src/task-queue.ts +2 -2
- package/src/types.ts +151 -95
- package/src/utils/are-elements-with-issues-equal.ts +7 -5
- package/src/utils/are-issue-sets-equal.test.ts +10 -6
- package/src/utils/are-issue-sets-equal.ts +8 -6
- package/src/utils/containing-blocks.ts +6 -3
- package/src/utils/contains.test.ts +2 -2
- package/src/utils/contains.ts +1 -1
- package/src/utils/deduplicate-nodes.ts +1 -1
- package/src/utils/deep-merge.test.ts +8 -1
- package/src/utils/deep-merge.ts +14 -8
- package/src/utils/dom-helpers.ts +6 -2
- package/src/utils/ensure-non-empty.ts +2 -2
- package/src/utils/get-element-html.ts +4 -2
- package/src/utils/get-element-position.ts +37 -24
- package/src/utils/get-parent.ts +1 -1
- package/src/utils/get-scan-context.test.ts +14 -8
- package/src/utils/get-scan-context.ts +12 -15
- package/src/utils/get-scrollable-ancestors.ts +8 -5
- package/src/utils/is-node-in-scan-context.test.ts +3 -3
- package/src/utils/is-node-in-scan-context.ts +6 -6
- package/src/utils/is-non-empty.ts +3 -0
- package/src/utils/normalize-context.test.ts +9 -9
- package/src/utils/normalize-context.ts +17 -10
- package/src/utils/recalculate-positions.ts +5 -5
- package/src/utils/recalculate-scrollable-ancestors.ts +4 -4
- package/src/utils/shadow-dom-aware-mutation-observer.ts +21 -24
- package/src/utils/supports-anchor-positioning.ts +3 -3
- package/src/utils/transform-violations.test.ts +22 -20
- package/src/utils/transform-violations.ts +14 -10
- package/src/utils/update-elements-with-issues.test.ts +49 -49
- package/src/utils/update-elements-with-issues.ts +96 -71
- package/src/validate-options.ts +91 -38
package/src/validate-options.ts
CHANGED
|
@@ -1,47 +1,67 @@
|
|
|
1
|
-
import type { Selector, SelectorList, ContextProp, ContextObject, AccentedOptions, Context } from './types';
|
|
2
1
|
import { allowedAxeOptions } from './types.js';
|
|
2
|
+
import type {
|
|
3
|
+
AccentedOptions,
|
|
4
|
+
Context,
|
|
5
|
+
ContextObject,
|
|
6
|
+
ContextProp,
|
|
7
|
+
Selector,
|
|
8
|
+
SelectorList,
|
|
9
|
+
} from './types.ts';
|
|
3
10
|
import { isNode, isNodeList } from './utils/dom-helpers.js';
|
|
4
11
|
|
|
5
12
|
function isSelector(contextFragment: Context): contextFragment is Selector {
|
|
6
|
-
return
|
|
7
|
-
|
|
8
|
-
||
|
|
13
|
+
return (
|
|
14
|
+
typeof contextFragment === 'string' ||
|
|
15
|
+
isNode(contextFragment) ||
|
|
16
|
+
'fromShadowDom' in contextFragment
|
|
17
|
+
);
|
|
9
18
|
}
|
|
10
19
|
|
|
11
20
|
function validateSelector(selector: Selector) {
|
|
12
21
|
if (typeof selector === 'string') {
|
|
13
22
|
return;
|
|
14
|
-
}
|
|
23
|
+
}
|
|
24
|
+
if (isNode(selector)) {
|
|
15
25
|
return;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
!selector.fromShadowDom
|
|
26
|
+
}
|
|
27
|
+
if ('fromShadowDom' in selector) {
|
|
28
|
+
if (
|
|
29
|
+
!Array.isArray(selector.fromShadowDom) ||
|
|
30
|
+
selector.fromShadowDom.length < 2 ||
|
|
31
|
+
!selector.fromShadowDom.every((item) => typeof item === 'string')
|
|
20
32
|
) {
|
|
21
|
-
throw new TypeError(
|
|
33
|
+
throw new TypeError(
|
|
34
|
+
`Accented: invalid argument. \`fromShadowDom\` must be an array of strings with at least 2 elements. It’s currently set to ${selector.fromShadowDom}.`,
|
|
35
|
+
);
|
|
22
36
|
}
|
|
23
37
|
return;
|
|
24
|
-
} else {
|
|
25
|
-
const neverSelector: never = selector;
|
|
26
|
-
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}.`);
|
|
27
38
|
}
|
|
39
|
+
const neverSelector: never = selector;
|
|
40
|
+
throw new TypeError(
|
|
41
|
+
`Accented: invalid argument. The selector must be one of: string, Node, or an object with a \`fromShadowDom\` property. It’s currently set to ${neverSelector}.`,
|
|
42
|
+
);
|
|
28
43
|
}
|
|
29
44
|
|
|
30
45
|
function isSelectorList(contextFragment: Context): contextFragment is SelectorList {
|
|
31
|
-
return (
|
|
32
|
-
|
|
46
|
+
return (
|
|
47
|
+
(typeof contextFragment === 'object' && isNodeList(contextFragment)) ||
|
|
48
|
+
(Array.isArray(contextFragment) && contextFragment.every((item) => isSelector(item)))
|
|
49
|
+
);
|
|
33
50
|
}
|
|
34
51
|
|
|
35
52
|
function validateSelectorList(selectorList: SelectorList) {
|
|
36
53
|
if (isNodeList(selectorList)) {
|
|
37
54
|
return;
|
|
38
|
-
}
|
|
55
|
+
}
|
|
56
|
+
if (Array.isArray(selectorList)) {
|
|
39
57
|
for (const selector of selectorList) {
|
|
40
58
|
validateSelector(selector);
|
|
41
59
|
}
|
|
42
60
|
} else {
|
|
43
61
|
const neverSelectorList: never = selectorList;
|
|
44
|
-
throw new TypeError(
|
|
62
|
+
throw new TypeError(
|
|
63
|
+
`Accented: invalid argument. The selector list must either be a NodeList or an array. It’s currently set to ${neverSelectorList}.`,
|
|
64
|
+
);
|
|
45
65
|
}
|
|
46
66
|
}
|
|
47
67
|
|
|
@@ -56,21 +76,26 @@ function validateContextProp(context: Selector | SelectorList) {
|
|
|
56
76
|
validateSelectorList(context);
|
|
57
77
|
} else {
|
|
58
78
|
const neverContext: never = context;
|
|
59
|
-
throw new TypeError(
|
|
79
|
+
throw new TypeError(
|
|
80
|
+
`Accented: invalid argument. The context property must either be a selector or a selector list. It’s currently set to ${neverContext}.`,
|
|
81
|
+
);
|
|
60
82
|
}
|
|
61
83
|
}
|
|
62
84
|
|
|
63
85
|
function isContextObject(contextFragment: Context): contextFragment is ContextObject {
|
|
64
|
-
return
|
|
65
|
-
|
|
86
|
+
return (
|
|
87
|
+
typeof contextFragment === 'object' &&
|
|
88
|
+
contextFragment !== null &&
|
|
89
|
+
('include' in contextFragment || 'exclude' in contextFragment)
|
|
90
|
+
);
|
|
66
91
|
}
|
|
67
92
|
|
|
68
93
|
function validateContextObject(contextObject: ContextObject) {
|
|
69
|
-
if ('include' in contextObject) {
|
|
70
|
-
validateContextProp(contextObject.include
|
|
94
|
+
if ('include' in contextObject && contextObject.include !== undefined) {
|
|
95
|
+
validateContextProp(contextObject.include);
|
|
71
96
|
}
|
|
72
|
-
if ('exclude' in contextObject) {
|
|
73
|
-
validateContextProp(contextObject.exclude
|
|
97
|
+
if ('exclude' in contextObject && contextObject.exclude !== undefined) {
|
|
98
|
+
validateContextProp(contextObject.exclude);
|
|
74
99
|
}
|
|
75
100
|
}
|
|
76
101
|
|
|
@@ -81,7 +106,9 @@ function validateContext(context: Context) {
|
|
|
81
106
|
validateContextObject(context);
|
|
82
107
|
} else {
|
|
83
108
|
const neverContext: never = context;
|
|
84
|
-
throw new TypeError(
|
|
109
|
+
throw new TypeError(
|
|
110
|
+
`Accented: invalid context argument. It’s currently set to ${neverContext}.`,
|
|
111
|
+
);
|
|
85
112
|
}
|
|
86
113
|
}
|
|
87
114
|
|
|
@@ -90,39 +117,65 @@ function validateContext(context: Context) {
|
|
|
90
117
|
// lowercase alphanumeric names that possibly contain dashes that start with a letter.
|
|
91
118
|
const nameRegex = /^[a-z]([a-z0-9]|-)+$/;
|
|
92
119
|
|
|
93
|
-
export
|
|
120
|
+
export function validateOptions(options: AccentedOptions) {
|
|
94
121
|
if (typeof options !== 'object' || options === null) {
|
|
95
|
-
throw new TypeError(
|
|
122
|
+
throw new TypeError(
|
|
123
|
+
`Accented: invalid argument. The options parameter must be an object if provided. It’s currently set to ${options}.`,
|
|
124
|
+
);
|
|
96
125
|
}
|
|
97
126
|
if (options.throttle !== undefined) {
|
|
98
127
|
if (typeof options.throttle !== 'object' || options.throttle === null) {
|
|
99
|
-
throw new TypeError(
|
|
128
|
+
throw new TypeError(
|
|
129
|
+
`Accented: invalid argument. \`throttle\` option must be an object if provided. It’s currently set to ${options.throttle}.`,
|
|
130
|
+
);
|
|
100
131
|
}
|
|
101
|
-
if (
|
|
102
|
-
|
|
132
|
+
if (
|
|
133
|
+
options.throttle.wait !== undefined &&
|
|
134
|
+
(typeof options.throttle.wait !== 'number' || options.throttle.wait < 0)
|
|
135
|
+
) {
|
|
136
|
+
throw new TypeError(
|
|
137
|
+
`Accented: invalid argument. \`throttle.wait\` option must be a non-negative number if provided. It’s currently set to ${options.throttle.wait}.`,
|
|
138
|
+
);
|
|
103
139
|
}
|
|
104
140
|
}
|
|
105
141
|
if (options.output !== undefined) {
|
|
106
142
|
if (typeof options.output !== 'object' || options.output === null) {
|
|
107
|
-
throw new TypeError(
|
|
143
|
+
throw new TypeError(
|
|
144
|
+
`Accented: invalid argument. \`output\` option must be an object if provided. It’s currently set to ${options.output}.`,
|
|
145
|
+
);
|
|
108
146
|
}
|
|
109
147
|
if (options.output.console !== undefined && typeof options.output.console !== 'boolean') {
|
|
110
|
-
console.warn(
|
|
148
|
+
console.warn(
|
|
149
|
+
`Accented: invalid argument. \`output.console\` option is expected to be a boolean. It’s currently set to ${options.output.console}.`,
|
|
150
|
+
);
|
|
111
151
|
}
|
|
112
152
|
}
|
|
113
153
|
if (options.callback !== undefined && typeof options.callback !== 'function') {
|
|
114
|
-
throw new TypeError(
|
|
154
|
+
throw new TypeError(
|
|
155
|
+
`Accented: invalid argument. \`callback\` option must be a function if provided. It’s currently set to ${options.callback}.`,
|
|
156
|
+
);
|
|
115
157
|
}
|
|
116
|
-
if (
|
|
117
|
-
|
|
158
|
+
if (
|
|
159
|
+
options.name !== undefined &&
|
|
160
|
+
(typeof options.name !== 'string' || !options.name.match(nameRegex))
|
|
161
|
+
) {
|
|
162
|
+
throw new TypeError(
|
|
163
|
+
`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}.`,
|
|
164
|
+
);
|
|
118
165
|
}
|
|
119
166
|
if (options.axeOptions !== undefined) {
|
|
120
167
|
if (typeof options.axeOptions !== 'object' || options.axeOptions === null) {
|
|
121
|
-
throw new TypeError(
|
|
168
|
+
throw new TypeError(
|
|
169
|
+
`Accented: invalid argument. \`axeOptions\` option must be an object if provided. It’s currently set to ${options.axeOptions}.`,
|
|
170
|
+
);
|
|
122
171
|
}
|
|
123
|
-
const unsupportedKeys = Object.keys(options.axeOptions).filter(
|
|
172
|
+
const unsupportedKeys = Object.keys(options.axeOptions).filter(
|
|
173
|
+
(key) => !(allowedAxeOptions as unknown as Array<string>).includes(key),
|
|
174
|
+
);
|
|
124
175
|
if (unsupportedKeys.length > 0) {
|
|
125
|
-
throw new TypeError(
|
|
176
|
+
throw new TypeError(
|
|
177
|
+
`Accented: invalid argument. \`axeOptions\` contains the following unsupported keys: ${unsupportedKeys.join(', ')}. Valid options are: ${allowedAxeOptions.join(', ')}.`,
|
|
178
|
+
);
|
|
126
179
|
}
|
|
127
180
|
}
|
|
128
181
|
if (options.context !== undefined) {
|