forked from dequelabs/axe-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabstract-virtual-node.js
More file actions
43 lines (35 loc) · 1000 Bytes
/
abstract-virtual-node.js
File metadata and controls
43 lines (35 loc) · 1000 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const whitespaceRegex = /[\t\r\n\f]/g;
class AbstractVirtualNode {
constructor() {
this.parent = undefined;
}
get props() {
throw new Error(
'VirtualNode class must have a "props" object consisting ' +
'of "nodeType" and "nodeName" properties'
);
}
get attrNames() {
throw new Error('VirtualNode class must have an "attrNames" property');
}
attr() {
throw new Error('VirtualNode class must have an "attr" function');
}
hasAttr() {
throw new Error('VirtualNode class must have a "hasAttr" function');
}
hasClass(className) {
// get the value of the class attribute as svgs return a SVGAnimatedString
// if you access the className property
const classAttr = this.attr('class');
if (!classAttr) {
return false;
}
const selector = ' ' + className + ' ';
return (
(' ' + classAttr + ' ').replace(whitespaceRegex, ' ').indexOf(selector) >=
0
);
}
}
export default AbstractVirtualNode;