-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattributes.js
37 lines (37 loc) · 1 KB
/
attributes.js
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
import { ClassName } from './class-name';
import { StyleSet } from './style';
/**
* Represents a tag's attribute set.
*/
export class AttrSet {
constructor() {
this.className = new ClassName();
this.style = new StyleSet();
this.additionalAttributes = {};
}
copy() {
const newSet = new AttrSet();
newSet.className = this.className.copy();
newSet.id = this.id;
newSet.style = this.style.copy();
newSet.additionalAttributes = Object.assign({}, this.additionalAttributes);
return newSet;
}
/** Set single attribute */
set(key, value) {
this.additionalAttributes[key] = value;
return this;
}
/** Remove attributes */
remove(...attrs) {
for (const cn of attrs) {
delete this.additionalAttributes[cn];
}
return this;
}
/** Check if an attribute is set */
has(key) {
return key in this.additionalAttributes;
}
}
//# sourceMappingURL=attributes.js.map