accented 0.0.0-20250124142030
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/LICENSE +21 -0
- package/README.md +162 -0
- package/dist/accented.d.ts +27 -0
- package/dist/accented.d.ts.map +1 -0
- package/dist/accented.js +85 -0
- package/dist/accented.js.map +1 -0
- package/dist/dom-updater.d.ts +2 -0
- package/dist/dom-updater.d.ts.map +1 -0
- package/dist/dom-updater.js +96 -0
- package/dist/dom-updater.js.map +1 -0
- package/dist/elements/accented-container.d.ts +350 -0
- package/dist/elements/accented-container.d.ts.map +1 -0
- package/dist/elements/accented-container.js +131 -0
- package/dist/elements/accented-container.js.map +1 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +20 -0
- package/dist/logger.js.map +1 -0
- package/dist/scanner.d.ts +3 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +56 -0
- package/dist/scanner.js.map +1 -0
- package/dist/state.d.ts +5 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +8 -0
- package/dist/state.js.map +1 -0
- package/dist/task-queue.d.ts +10 -0
- package/dist/task-queue.d.ts.map +1 -0
- package/dist/task-queue.js +44 -0
- package/dist/task-queue.js.map +1 -0
- package/dist/types.d.ts +84 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/types.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/deep-merge.d.ts +4 -0
- package/dist/utils/deep-merge.d.ts.map +1 -0
- package/dist/utils/deep-merge.js +18 -0
- package/dist/utils/deep-merge.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 +39 -0
- package/dist/utils/transform-violations.js.map +1 -0
- package/dist/utils/update-elements-with-issues.d.ts +5 -0
- package/dist/utils/update-elements-with-issues.d.ts.map +1 -0
- package/dist/utils/update-elements-with-issues.js +46 -0
- package/dist/utils/update-elements-with-issues.js.map +1 -0
- package/package.json +38 -0
- package/src/accented.test.ts +24 -0
- package/src/accented.ts +99 -0
- package/src/dom-updater.ts +104 -0
- package/src/elements/accented-container.ts +147 -0
- package/src/logger.ts +21 -0
- package/src/scanner.ts +68 -0
- package/src/state.ts +12 -0
- package/src/task-queue.test.ts +135 -0
- package/src/task-queue.ts +59 -0
- package/src/types.ts +97 -0
- package/src/utils/are-issue-sets-equal.test.ts +49 -0
- package/src/utils/are-issue-sets-equal.ts +10 -0
- package/src/utils/deep-merge.test.ts +27 -0
- package/src/utils/deep-merge.ts +18 -0
- package/src/utils/transform-violations.test.ts +124 -0
- package/src/utils/transform-violations.ts +45 -0
- package/src/utils/update-elements-with-issues.test.ts +209 -0
- package/src/utils/update-elements-with-issues.ts +55 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import {suite, test} from 'node:test';
|
|
3
|
+
import transformViolations from './transform-violations';
|
|
4
|
+
|
|
5
|
+
import type { AxeResults } from 'axe-core';
|
|
6
|
+
type Violation = AxeResults['violations'][number];
|
|
7
|
+
type Node = Violation['nodes'][number];
|
|
8
|
+
|
|
9
|
+
const commonViolationProps1: Omit<Violation, 'nodes'> = {
|
|
10
|
+
id: 'id1',
|
|
11
|
+
help: 'help1',
|
|
12
|
+
helpUrl: 'http://example.com',
|
|
13
|
+
description: 'description1',
|
|
14
|
+
tags: [],
|
|
15
|
+
impact: 'serious'
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const commonViolationProps2: Omit<Violation, 'nodes'> = {
|
|
19
|
+
id: 'id2',
|
|
20
|
+
help: 'help2',
|
|
21
|
+
helpUrl: 'http://example.com',
|
|
22
|
+
description: 'description2',
|
|
23
|
+
tags: [],
|
|
24
|
+
impact: 'serious'
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// @ts-expect-error element is not HTMLElement
|
|
28
|
+
const element1: HTMLElement = {};
|
|
29
|
+
// @ts-expect-error element is not HTMLElement
|
|
30
|
+
const element2: HTMLElement = {};
|
|
31
|
+
// @ts-expect-error element is not HTMLElement
|
|
32
|
+
const element3: HTMLElement = {};
|
|
33
|
+
|
|
34
|
+
const commonNodeProps = {
|
|
35
|
+
html: '<div></div>',
|
|
36
|
+
any: [],
|
|
37
|
+
all: [],
|
|
38
|
+
none: []
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const node1: Node = {
|
|
42
|
+
...commonNodeProps,
|
|
43
|
+
element: element1,
|
|
44
|
+
target: ['div'],
|
|
45
|
+
failureSummary: 'summary1'
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const node2: Node = {
|
|
49
|
+
...commonNodeProps,
|
|
50
|
+
element: element2,
|
|
51
|
+
target: ['div'],
|
|
52
|
+
failureSummary: 'summary2'
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const node3: Node = {
|
|
56
|
+
...commonNodeProps,
|
|
57
|
+
element: element3,
|
|
58
|
+
target: ['div'],
|
|
59
|
+
failureSummary: 'summary3'
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
suite('transformViolations', () => {
|
|
63
|
+
test('one violation, one element', () => {
|
|
64
|
+
const violation: Violation = {
|
|
65
|
+
...commonViolationProps1,
|
|
66
|
+
nodes: [node1]
|
|
67
|
+
};
|
|
68
|
+
const elementsWithIssues = transformViolations([violation]);
|
|
69
|
+
assert.equal(elementsWithIssues.length, 1);
|
|
70
|
+
assert.equal(elementsWithIssues[0]?.element, element1);
|
|
71
|
+
assert.equal(elementsWithIssues[0].issues.length, 1);
|
|
72
|
+
assert.equal(elementsWithIssues[0].issues[0]?.id, 'id1');
|
|
73
|
+
assert.equal(elementsWithIssues[0].issues[0]?.description, 'summary1');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('two violations, two elements each', () => {
|
|
77
|
+
const violation1: Violation = {
|
|
78
|
+
...commonViolationProps1,
|
|
79
|
+
nodes: [node1, node2]
|
|
80
|
+
};
|
|
81
|
+
const violation2: Violation = {
|
|
82
|
+
...commonViolationProps2,
|
|
83
|
+
nodes: [node1, node3]
|
|
84
|
+
};
|
|
85
|
+
const elementsWithIssues = transformViolations([violation1, violation2]);
|
|
86
|
+
assert.equal(elementsWithIssues.length, 3);
|
|
87
|
+
const elementWithTwoIssues = elementsWithIssues.find(elementWithIssues => elementWithIssues.element === element1);
|
|
88
|
+
assert.equal(elementWithTwoIssues?.issues.length, 2);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('a violation in an iframe', () => {
|
|
92
|
+
const node: Node = {
|
|
93
|
+
...commonNodeProps,
|
|
94
|
+
element: element1,
|
|
95
|
+
// A target array whose length is > 1 signifies an element in an iframe
|
|
96
|
+
target: ['iframe', 'div'],
|
|
97
|
+
failureSummary: 'summary1'
|
|
98
|
+
};
|
|
99
|
+
const violation: Violation = {
|
|
100
|
+
...commonViolationProps1,
|
|
101
|
+
nodes: [node]
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const elementsWithIssues = transformViolations([violation]);
|
|
105
|
+
assert.equal(elementsWithIssues.length, 0);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('a violation in shadow DOM', () => {
|
|
109
|
+
const node: Node = {
|
|
110
|
+
...commonNodeProps,
|
|
111
|
+
element: element1,
|
|
112
|
+
// A target that contains an array within the outer array signifies an element in shadow DOM
|
|
113
|
+
target: [['div', 'div']],
|
|
114
|
+
failureSummary: 'summary1'
|
|
115
|
+
};
|
|
116
|
+
const violation: Violation = {
|
|
117
|
+
...commonViolationProps1,
|
|
118
|
+
nodes: [node]
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const elementsWithIssues = transformViolations([violation]);
|
|
122
|
+
assert.equal(elementsWithIssues.length, 0);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { AxeResults } from 'axe-core';
|
|
2
|
+
import type { Issue, ElementWithIssues } from '../types';
|
|
3
|
+
|
|
4
|
+
export default function transformViolations(violations: typeof AxeResults.violations) {
|
|
5
|
+
const elementsWithIssues: Array<ElementWithIssues> = [];
|
|
6
|
+
|
|
7
|
+
for (const violation of violations) {
|
|
8
|
+
for (const node of violation.nodes) {
|
|
9
|
+
const { element, target } = node;
|
|
10
|
+
|
|
11
|
+
// Although axe-core can perform iframe scanning, I haven't succeeded in it,
|
|
12
|
+
// and the docs suggest that the axe-core script should be explicitly included
|
|
13
|
+
// in each of the iframed documents anyway.
|
|
14
|
+
// It seems preferable to disallow iframe scanning and not report issues in elements within iframes
|
|
15
|
+
// in the case that such issues are for some reason reported by axe-core.
|
|
16
|
+
// A consumer of Accented can instead scan the iframed document by calling Accented initialization from that document.
|
|
17
|
+
const isInIframe = target.length > 1;
|
|
18
|
+
|
|
19
|
+
// Highlighting elements in shadow DOM is not yet supported, see https://github.com/pomerantsev/accented/issues/25
|
|
20
|
+
// Until then, we don’t want such elements to be added to the set.
|
|
21
|
+
const isInShadowDOM = Array.isArray(target[0]);
|
|
22
|
+
|
|
23
|
+
if (element && !isInIframe && !isInShadowDOM) {
|
|
24
|
+
const issue: Issue = {
|
|
25
|
+
id: violation.id,
|
|
26
|
+
title: violation.help,
|
|
27
|
+
description: node.failureSummary ?? violation.description,
|
|
28
|
+
url: violation.helpUrl,
|
|
29
|
+
impact: violation.impact ?? null
|
|
30
|
+
};
|
|
31
|
+
const existingElementIndex = elementsWithIssues.findIndex(elementWithIssues => elementWithIssues.element === element);
|
|
32
|
+
if (existingElementIndex === -1) {
|
|
33
|
+
elementsWithIssues.push({
|
|
34
|
+
element,
|
|
35
|
+
issues: [issue]
|
|
36
|
+
});
|
|
37
|
+
} else {
|
|
38
|
+
elementsWithIssues[existingElementIndex]!.issues.push(issue);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return elementsWithIssues;
|
|
45
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import {suite, test} from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import type { Signal } from '@preact/signals-core';
|
|
4
|
+
import { signal } from '@preact/signals-core';
|
|
5
|
+
import type { ExtendedElementWithIssues, Issue } from '../types';
|
|
6
|
+
import updateElementsWithIssues from './update-elements-with-issues';
|
|
7
|
+
|
|
8
|
+
import type { AxeResults, ImpactValue } from 'axe-core';
|
|
9
|
+
import type { AccentedContainer } from '../elements/accented-container';
|
|
10
|
+
type Violation = AxeResults['violations'][number];
|
|
11
|
+
type Node = Violation['nodes'][number];
|
|
12
|
+
|
|
13
|
+
const win: Window = {
|
|
14
|
+
document: {
|
|
15
|
+
// @ts-expect-error the return value is of incorrect type.
|
|
16
|
+
createElement: () => ({
|
|
17
|
+
style: {
|
|
18
|
+
setProperty: () => {}
|
|
19
|
+
},
|
|
20
|
+
dataset: {}
|
|
21
|
+
})
|
|
22
|
+
},
|
|
23
|
+
// @ts-expect-error we're missing a lot of properties
|
|
24
|
+
getComputedStyle: () => ({
|
|
25
|
+
zIndex: ''
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// @ts-expect-error element is not HTMLElement
|
|
30
|
+
const element1: HTMLElement = {};
|
|
31
|
+
// @ts-expect-error element is not HTMLElement
|
|
32
|
+
const element2: HTMLElement = {};
|
|
33
|
+
|
|
34
|
+
const accentedContainer = win.document.createElement('accented-container') as AccentedContainer;
|
|
35
|
+
|
|
36
|
+
const commonNodeProps = {
|
|
37
|
+
html: '<div></div>',
|
|
38
|
+
any: [],
|
|
39
|
+
all: [],
|
|
40
|
+
none: [],
|
|
41
|
+
target: ['div']
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const node1: Node = {
|
|
45
|
+
...commonNodeProps,
|
|
46
|
+
element: element1,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const node2: Node = {
|
|
50
|
+
...commonNodeProps,
|
|
51
|
+
element: element2,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const commonViolationProps = {
|
|
55
|
+
help: 'help',
|
|
56
|
+
helpUrl: 'http://example.com',
|
|
57
|
+
description: 'description',
|
|
58
|
+
tags: [],
|
|
59
|
+
impact: 'serious' as ImpactValue
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const violation1: Violation = {
|
|
63
|
+
...commonViolationProps,
|
|
64
|
+
id: 'id1',
|
|
65
|
+
nodes: [node1]
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const violation2: Violation = {
|
|
69
|
+
...commonViolationProps,
|
|
70
|
+
id: 'id2',
|
|
71
|
+
nodes: [node2]
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const violation3: Violation = {
|
|
75
|
+
...commonViolationProps,
|
|
76
|
+
id: 'id3',
|
|
77
|
+
nodes: [node2]
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const commonIssueProps = {
|
|
81
|
+
title: 'help',
|
|
82
|
+
description: 'description',
|
|
83
|
+
url: 'http://example.com',
|
|
84
|
+
impact: 'serious'
|
|
85
|
+
} as const;
|
|
86
|
+
|
|
87
|
+
const issue1: Issue = {
|
|
88
|
+
id: 'id1',
|
|
89
|
+
...commonIssueProps
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const issue2: Issue = {
|
|
93
|
+
id: 'id2',
|
|
94
|
+
...commonIssueProps
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const issue3: Issue = {
|
|
98
|
+
id: 'id3',
|
|
99
|
+
...commonIssueProps
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
suite('updateElementsWithIssues', () => {
|
|
103
|
+
test('no changes', () => {
|
|
104
|
+
const extendedElementsWithIssues: Signal<Array<ExtendedElementWithIssues>> = signal([
|
|
105
|
+
{
|
|
106
|
+
id: 1,
|
|
107
|
+
element: element1,
|
|
108
|
+
accentedContainer,
|
|
109
|
+
issues: signal([issue1])
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
id: 2,
|
|
113
|
+
element: element2,
|
|
114
|
+
accentedContainer,
|
|
115
|
+
issues: signal([issue2])
|
|
116
|
+
}
|
|
117
|
+
]);
|
|
118
|
+
updateElementsWithIssues(extendedElementsWithIssues, [violation1, violation2], win, 'accented');
|
|
119
|
+
assert.equal(extendedElementsWithIssues.value.length, 2);
|
|
120
|
+
assert.equal(extendedElementsWithIssues.value[0]?.element, element1);
|
|
121
|
+
assert.equal(extendedElementsWithIssues.value[0]?.issues.value.length, 1);
|
|
122
|
+
assert.equal(extendedElementsWithIssues.value[1]?.element, element2);
|
|
123
|
+
assert.equal(extendedElementsWithIssues.value[1]?.issues.value.length, 1);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('one issue added', () => {
|
|
127
|
+
const extendedElementsWithIssues: Signal<Array<ExtendedElementWithIssues>> = signal([
|
|
128
|
+
{
|
|
129
|
+
id: 1,
|
|
130
|
+
element: element1,
|
|
131
|
+
accentedContainer,
|
|
132
|
+
issues: signal([issue1])
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
id: 2,
|
|
136
|
+
element: element2,
|
|
137
|
+
accentedContainer,
|
|
138
|
+
issues: signal([issue2])
|
|
139
|
+
}
|
|
140
|
+
]);
|
|
141
|
+
updateElementsWithIssues(extendedElementsWithIssues, [violation1, violation2, violation3], win, 'accented');
|
|
142
|
+
assert.equal(extendedElementsWithIssues.value.length, 2);
|
|
143
|
+
assert.equal(extendedElementsWithIssues.value[0]?.element, element1);
|
|
144
|
+
assert.equal(extendedElementsWithIssues.value[0]?.issues.value.length, 1);
|
|
145
|
+
assert.equal(extendedElementsWithIssues.value[1]?.element, element2);
|
|
146
|
+
assert.equal(extendedElementsWithIssues.value[1]?.issues.value.length, 2);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('one issue removed', () => {
|
|
150
|
+
const extendedElementsWithIssues: Signal<Array<ExtendedElementWithIssues>> = signal([
|
|
151
|
+
{
|
|
152
|
+
id: 1,
|
|
153
|
+
element: element1,
|
|
154
|
+
accentedContainer,
|
|
155
|
+
issues: signal([issue1])
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
id: 2,
|
|
159
|
+
element: element2,
|
|
160
|
+
accentedContainer,
|
|
161
|
+
issues: signal([issue2, issue3])
|
|
162
|
+
}
|
|
163
|
+
]);
|
|
164
|
+
updateElementsWithIssues(extendedElementsWithIssues, [violation1, violation2], win, 'accented');
|
|
165
|
+
assert.equal(extendedElementsWithIssues.value.length, 2);
|
|
166
|
+
assert.equal(extendedElementsWithIssues.value[0]?.element, element1);
|
|
167
|
+
assert.equal(extendedElementsWithIssues.value[0]?.issues.value.length, 1);
|
|
168
|
+
assert.equal(extendedElementsWithIssues.value[1]?.element, element2);
|
|
169
|
+
assert.equal(extendedElementsWithIssues.value[1]?.issues.value.length, 1);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test('one element added', () => {
|
|
173
|
+
const extendedElementsWithIssues: Signal<Array<ExtendedElementWithIssues>> = signal([
|
|
174
|
+
{
|
|
175
|
+
id: 1,
|
|
176
|
+
element: element1,
|
|
177
|
+
accentedContainer,
|
|
178
|
+
issues: signal([issue1])
|
|
179
|
+
}
|
|
180
|
+
]);
|
|
181
|
+
updateElementsWithIssues(extendedElementsWithIssues, [violation1, violation2], win, 'accented');
|
|
182
|
+
assert.equal(extendedElementsWithIssues.value.length, 2);
|
|
183
|
+
assert.equal(extendedElementsWithIssues.value[0]?.element, element1);
|
|
184
|
+
assert.equal(extendedElementsWithIssues.value[0]?.issues.value.length, 1);
|
|
185
|
+
assert.equal(extendedElementsWithIssues.value[1]?.element, element2);
|
|
186
|
+
assert.equal(extendedElementsWithIssues.value[1]?.issues.value.length, 1);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test('one element removed', () => {
|
|
190
|
+
const extendedElementsWithIssues: Signal<Array<ExtendedElementWithIssues>> = signal([
|
|
191
|
+
{
|
|
192
|
+
id: 1,
|
|
193
|
+
element: element1,
|
|
194
|
+
accentedContainer,
|
|
195
|
+
issues: signal([issue1])
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
id: 2,
|
|
199
|
+
element: element2,
|
|
200
|
+
accentedContainer,
|
|
201
|
+
issues: signal([issue2])
|
|
202
|
+
}
|
|
203
|
+
]);
|
|
204
|
+
updateElementsWithIssues(extendedElementsWithIssues, [violation1], win, 'accented');
|
|
205
|
+
assert.equal(extendedElementsWithIssues.value.length, 1);
|
|
206
|
+
assert.equal(extendedElementsWithIssues.value[0]?.element, element1);
|
|
207
|
+
assert.equal(extendedElementsWithIssues.value[0]?.issues.value.length, 1);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { AxeResults } from 'axe-core';
|
|
2
|
+
import type { Signal } from '@preact/signals-core';
|
|
3
|
+
import { batch, signal } from '@preact/signals-core';
|
|
4
|
+
import type { ExtendedElementWithIssues } from '../types';
|
|
5
|
+
import transformViolations from './transform-violations.js';
|
|
6
|
+
import areIssueSetsEqual from './are-issue-sets-equal.js';
|
|
7
|
+
import type { AccentedContainer } from '../elements/accented-container';
|
|
8
|
+
|
|
9
|
+
let count = 0;
|
|
10
|
+
|
|
11
|
+
export default function updateElementsWithIssues(extendedElementsWithIssues: Signal<Array<ExtendedElementWithIssues>>, violations: typeof AxeResults.violations, win: Window, name: string) {
|
|
12
|
+
const updatedElementsWithIssues = transformViolations(violations);
|
|
13
|
+
|
|
14
|
+
batch(() => {
|
|
15
|
+
for (const updatedElementWithIssues of updatedElementsWithIssues) {
|
|
16
|
+
const existingElementIndex = extendedElementsWithIssues.value.findIndex(extendedElementWithIssues => extendedElementWithIssues.element === updatedElementWithIssues.element);
|
|
17
|
+
if (existingElementIndex > -1 && extendedElementsWithIssues.value[existingElementIndex] && !areIssueSetsEqual(extendedElementsWithIssues.value[existingElementIndex].issues.value, updatedElementWithIssues.issues)) {
|
|
18
|
+
extendedElementsWithIssues.value[existingElementIndex].issues.value = updatedElementWithIssues.issues;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const addedElementsWithIssues = updatedElementsWithIssues.filter(updatedElementWithIssues => {
|
|
23
|
+
return !extendedElementsWithIssues.value.some(extendedElementWithIssues => extendedElementWithIssues.element === updatedElementWithIssues.element);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const removedElementsWithIssues = extendedElementsWithIssues.value.filter(extendedElementWithIssues => {
|
|
27
|
+
return !updatedElementsWithIssues.some(updatedElementWithIssues => updatedElementWithIssues.element === extendedElementWithIssues.element);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (addedElementsWithIssues.length > 0 || removedElementsWithIssues.length > 0) {
|
|
31
|
+
extendedElementsWithIssues.value = [...extendedElementsWithIssues.value]
|
|
32
|
+
.filter(extendedElementWithIssues => {
|
|
33
|
+
return !removedElementsWithIssues.some(removedElementWithIssues => removedElementWithIssues.element === extendedElementWithIssues.element);
|
|
34
|
+
})
|
|
35
|
+
.concat(addedElementsWithIssues.map(addedElementWithIssues => {
|
|
36
|
+
const id = count++;
|
|
37
|
+
const accentedContainer = win.document.createElement(`${name}-container`) as AccentedContainer;
|
|
38
|
+
const elementZIndex = parseInt(win.getComputedStyle(addedElementWithIssues.element).zIndex, 10);
|
|
39
|
+
if (!isNaN(elementZIndex)) {
|
|
40
|
+
accentedContainer.style.setProperty('z-index', (elementZIndex + 1).toString());
|
|
41
|
+
}
|
|
42
|
+
accentedContainer.style.setProperty('position-anchor', `--${name}-anchor-${id}`);
|
|
43
|
+
accentedContainer.dataset.id = id.toString();
|
|
44
|
+
const issues = signal(addedElementWithIssues.issues);
|
|
45
|
+
accentedContainer.issues = issues;
|
|
46
|
+
return {
|
|
47
|
+
id,
|
|
48
|
+
element: addedElementWithIssues.element,
|
|
49
|
+
accentedContainer,
|
|
50
|
+
issues
|
|
51
|
+
};
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|