accented 1.2.0 → 1.2.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/utils/get-scan-context.d.ts.map +1 -1
- package/dist/utils/get-scan-context.js +9 -2
- package/dist/utils/get-scan-context.js.map +1 -1
- package/dist/utils/normalize-context.d.ts.map +1 -1
- package/dist/utils/normalize-context.js +3 -0
- package/dist/utils/normalize-context.js.map +1 -1
- package/package.json +2 -2
- package/src/utils/get-scan-context.ts +10 -2
- package/src/utils/normalize-context.test.ts +43 -0
- package/src/utils/normalize-context.ts +2 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-scan-context.d.ts","sourceRoot":"","sources":["../../src/utils/get-scan-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"get-scan-context.d.ts","sourceRoot":"","sources":["../../src/utils/get-scan-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAcxD,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,GAAG,WAAW,CA6BhF"}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { contains } from './contains.js';
|
|
2
2
|
import { deduplicateNodes } from './deduplicate-nodes.js';
|
|
3
|
+
import { isDocumentFragment, isShadowRoot } from './dom-helpers.js';
|
|
3
4
|
import { isNodeInScanContext } from './is-node-in-scan-context.js';
|
|
4
5
|
import { normalizeContext } from './normalize-context.js';
|
|
6
|
+
function replaceShadowRootsWithHosts(nodes) {
|
|
7
|
+
// If an element is a shadow root, we can't use it in context directly,
|
|
8
|
+
// we have to pass its host instead:
|
|
9
|
+
// https://github.com/dequelabs/axe-core/issues/4941
|
|
10
|
+
return nodes.map((node) => (isDocumentFragment(node) && isShadowRoot(node) ? node.host : node));
|
|
11
|
+
}
|
|
5
12
|
export function getScanContext(nodes, context) {
|
|
6
13
|
const { include: contextInclude, exclude: contextExclude } = normalizeContext(context);
|
|
7
14
|
// Filter only nodes that are included by context (see isNodeInContext above).
|
|
@@ -21,8 +28,8 @@ export function getScanContext(nodes, context) {
|
|
|
21
28
|
exclude.push(...excludeDescendants);
|
|
22
29
|
}
|
|
23
30
|
return {
|
|
24
|
-
include: deduplicateNodes(include),
|
|
25
|
-
exclude: deduplicateNodes(exclude),
|
|
31
|
+
include: replaceShadowRootsWithHosts(deduplicateNodes(include)),
|
|
32
|
+
exclude: replaceShadowRootsWithHosts(deduplicateNodes(exclude)),
|
|
26
33
|
};
|
|
27
34
|
}
|
|
28
35
|
//# sourceMappingURL=get-scan-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-scan-context.js","sourceRoot":"","sources":["../../src/utils/get-scan-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,MAAM,UAAU,cAAc,CAAC,KAAkB,EAAE,OAAgB;IACjE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAEvF,8EAA8E;IAC9E,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAC3C,mBAAmB,CAAC,IAAI,EAAE;QACxB,OAAO,EAAE,cAAc;QACvB,OAAO,EAAE,cAAc;KACxB,CAAC,CACH,CAAC;IAEF,MAAM,OAAO,GAAgB,EAAE,CAAC;IAChC,MAAM,OAAO,GAAgB,EAA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O,KAAK,EAAE,OAAO,EAAe,WAAW,EAAY,MAAM,aAAa,CAAC;AA8C/E,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,WAAW,
|
|
1
|
+
{"version":3,"file":"normalize-context.d.ts","sourceRoot":"","sources":["../../src/utils/normalize-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAe,WAAW,EAAY,MAAM,aAAa,CAAC;AA8C/E,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,WAAW,CAoB9D"}
|
|
@@ -44,6 +44,9 @@ export function normalizeContext(context) {
|
|
|
44
44
|
if (context.include !== undefined) {
|
|
45
45
|
contextInclude = contextPropToNodes(context.include);
|
|
46
46
|
}
|
|
47
|
+
else {
|
|
48
|
+
contextInclude = [document];
|
|
49
|
+
}
|
|
47
50
|
if (context.exclude !== undefined) {
|
|
48
51
|
contextExclude = contextPropToNodes(context.exclude);
|
|
49
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize-context.js","sourceRoot":"","sources":["../../src/utils/normalize-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,SAAS,kBAAkB,CACzB,SAAgC,EAChC,IAA2B;IAE3B,MAAM,mBAAmB,GAAG,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IAChE,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IACzC,CAAC;IACD,MAAM,aAAa,GAAkB,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACxD,IAAI,CAAC,UAAU,CAAC,a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AgB;IAC/C,IAAI,cAAc,GAAgB,EAAE,CAAC;IACrC,IAAI,cAAc,GAAgB,EAAE,CAAC;IACrC,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,SAAS,IAAI,OAAO,IAAI,SAAS,IAAI,OAAO,CAAC,EAAE,CAAC;QAClF,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YAClC,cAAc,GAAG,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACvD,CAAC;aAAM,CAAC;YACN,cAAc,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC9B,CAAC;QACD,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YAClC,cAAc,GAAG,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;SAAM,CAAC;QACN,cAAc,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO;QACL,OAAO,EAAE,cAAc;QACvB,OAAO,EAAE,cAAc;KACxB,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "accented",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "A frontend library for continuous accessibility testing and issue highlighting",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/accented.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/jsdom": "^27.0.0",
|
|
35
|
-
"jsdom": "^27.0
|
|
35
|
+
"jsdom": "^27.1.0"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "pnpm copyCommon && tsc",
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import type { Context, ScanContext } from '../types.ts';
|
|
2
2
|
import { contains } from './contains.js';
|
|
3
3
|
import { deduplicateNodes } from './deduplicate-nodes.js';
|
|
4
|
+
import { isDocumentFragment, isShadowRoot } from './dom-helpers.js';
|
|
4
5
|
import { isNodeInScanContext } from './is-node-in-scan-context.js';
|
|
5
6
|
import { normalizeContext } from './normalize-context.js';
|
|
6
7
|
|
|
8
|
+
function replaceShadowRootsWithHosts(nodes: Array<Node>) {
|
|
9
|
+
// If an element is a shadow root, we can't use it in context directly,
|
|
10
|
+
// we have to pass its host instead:
|
|
11
|
+
// https://github.com/dequelabs/axe-core/issues/4941
|
|
12
|
+
return nodes.map((node) => (isDocumentFragment(node) && isShadowRoot(node) ? node.host : node));
|
|
13
|
+
}
|
|
14
|
+
|
|
7
15
|
export function getScanContext(nodes: Array<Node>, context: Context): ScanContext {
|
|
8
16
|
const { include: contextInclude, exclude: contextExclude } = normalizeContext(context);
|
|
9
17
|
|
|
@@ -30,7 +38,7 @@ export function getScanContext(nodes: Array<Node>, context: Context): ScanContex
|
|
|
30
38
|
}
|
|
31
39
|
|
|
32
40
|
return {
|
|
33
|
-
include: deduplicateNodes(include),
|
|
34
|
-
exclude: deduplicateNodes(exclude),
|
|
41
|
+
include: replaceShadowRootsWithHosts(deduplicateNodes(include)),
|
|
42
|
+
exclude: replaceShadowRootsWithHosts(deduplicateNodes(exclude)),
|
|
35
43
|
};
|
|
36
44
|
}
|
|
@@ -7,6 +7,7 @@ suite('normalizeContext', () => {
|
|
|
7
7
|
test('when document is passed, only document is returned in include', () => {
|
|
8
8
|
const dom = new JSDOM('<div id="test"></div>');
|
|
9
9
|
const { document } = dom.window;
|
|
10
|
+
global.document = document;
|
|
10
11
|
const normalizedContext = normalizeContext(document);
|
|
11
12
|
|
|
12
13
|
assert.deepEqual(normalizedContext, {
|
|
@@ -18,6 +19,7 @@ suite('normalizeContext', () => {
|
|
|
18
19
|
test('when an element is passed, only that element is returned in include', () => {
|
|
19
20
|
const dom = new JSDOM('<div id="test"></div>');
|
|
20
21
|
const { document } = dom.window;
|
|
22
|
+
global.document = document;
|
|
21
23
|
const element = document.querySelector('#test')!;
|
|
22
24
|
const normalizedContext = normalizeContext(element);
|
|
23
25
|
|
|
@@ -68,6 +70,7 @@ suite('normalizeContext', () => {
|
|
|
68
70
|
<div class="doesnt-match"></div>
|
|
69
71
|
</div>`);
|
|
70
72
|
const { document } = dom.window;
|
|
73
|
+
global.document = document;
|
|
71
74
|
const matchingElements = document.querySelectorAll('.matches');
|
|
72
75
|
const normalizedContext = normalizeContext(matchingElements);
|
|
73
76
|
|
|
@@ -78,6 +81,46 @@ suite('normalizeContext', () => {
|
|
|
78
81
|
});
|
|
79
82
|
});
|
|
80
83
|
|
|
84
|
+
test('when an object with `include` and `exclude` is passed, the matched elements are returned in respective arrays', () => {
|
|
85
|
+
const dom = new JSDOM(`<div>
|
|
86
|
+
<div class="matches"></div>
|
|
87
|
+
<div class="matches"></div>
|
|
88
|
+
<div class="doesnt-match"></div>
|
|
89
|
+
</div>`);
|
|
90
|
+
const { document } = dom.window;
|
|
91
|
+
global.document = document;
|
|
92
|
+
const matchingIncludeElements = document.querySelectorAll('.matches');
|
|
93
|
+
const matchingExcludeElements = document.querySelectorAll('.doesnt-match');
|
|
94
|
+
const normalizedContext = normalizeContext({
|
|
95
|
+
include: '.matches',
|
|
96
|
+
exclude: '.doesnt-match',
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
assert.deepEqual(normalizedContext, {
|
|
100
|
+
include: Array.from(matchingIncludeElements),
|
|
101
|
+
exclude: Array.from(matchingExcludeElements),
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('when an object with only `exclude` is passed, `include` is implicitly set to `document`', () => {
|
|
106
|
+
const dom = new JSDOM(`<div>
|
|
107
|
+
<div class="matches"></div>
|
|
108
|
+
<div class="matches"></div>
|
|
109
|
+
<div class="doesnt-match"></div>
|
|
110
|
+
</div>`);
|
|
111
|
+
const { document } = dom.window;
|
|
112
|
+
global.document = document;
|
|
113
|
+
const matchingExcludeElements = document.querySelectorAll('.doesnt-match');
|
|
114
|
+
const normalizedContext = normalizeContext({
|
|
115
|
+
exclude: '.doesnt-match',
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
assert.deepEqual(normalizedContext, {
|
|
119
|
+
include: [document],
|
|
120
|
+
exclude: Array.from(matchingExcludeElements),
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
81
124
|
test('when an object with `fromShadowDom` is passed, all the matching nodes are included', () => {
|
|
82
125
|
const dom = new JSDOM(`<div>
|
|
83
126
|
<div class="host"></div>
|
|
@@ -50,6 +50,8 @@ export function normalizeContext(context: Context): ScanContext {
|
|
|
50
50
|
if (typeof context === 'object' && ('include' in context || 'exclude' in context)) {
|
|
51
51
|
if (context.include !== undefined) {
|
|
52
52
|
contextInclude = contextPropToNodes(context.include);
|
|
53
|
+
} else {
|
|
54
|
+
contextInclude = [document];
|
|
53
55
|
}
|
|
54
56
|
if (context.exclude !== undefined) {
|
|
55
57
|
contextExclude = contextPropToNodes(context.exclude);
|