@matthewp/linkedom
Version:
A triple-linked lists based DOM implementation
48 lines (41 loc) • 1.04 kB
JavaScript
;
const {Element} = require('../interface/element.js');
const classNames = new WeakMap;
const handler = {
get(target, name) {
return target[name];
},
set(target, name, value) {
target[name] = value;
return true;
}
};
/**
* @implements globalThis.SVGElement
*/
class SVGElement extends Element {
constructor(ownerDocument, localName, ownerSVGElement = null) {
super(ownerDocument, localName);
this.ownerSVGElement = ownerSVGElement;
}
get className() {
if (!classNames.has(this))
classNames.set(this, new Proxy({baseVal: '', animVal: ''}, handler));
return classNames.get(this);
}
/* c8 ignore start */
set className(value) {
const {classList} = this;
classList.clear();
classList.add(...value.split(/\s+/));
}
/* c8 ignore stop */
setAttribute(name, value) {
if (name === 'style') {
const {className} = this;
className.baseVal = className.animVal = value;
}
super.setAttribute(name, value);
}
}
exports.SVGElement = SVGElement