UNPKG

happy-dom

Version:

Happy DOM is a JavaScript implementation of a web browser without its graphical user interface. It includes many web standards from WHATWG DOM and HTML.

101 lines 2.41 kB
import CSSStyleDeclaration from '../../css/declaration/CSSStyleDeclaration.js'; import * as PropertySymbol from '../../PropertySymbol.js'; import Element from '../element/Element.js'; import HTMLElementUtility from '../html-element/HTMLElementUtility.js'; import DOMStringMap from '../element/DOMStringMap.js'; /** * SVG Element. * * Reference: * https://developer.mozilla.org/en-US/docs/Web/API/SVGElement. */ export default class SVGElement extends Element { // Events onabort = null; onerror = null; onload = null; onresize = null; onscroll = null; onunload = null; // Internal properties [PropertySymbol.style] = null; // Private properties #dataset = null; /** * Returns viewport. * * @returns SVG rect. */ get viewportElement() { return null; } /** * Returns current translate. * * @returns Element. */ get ownerSVGElement() { let parent = this[PropertySymbol.parentNode]; while (parent) { if (parent[PropertySymbol.localName] === 'svg') { return parent; } parent = parent[PropertySymbol.parentNode]; } return null; } /** * Returns data set. * * @returns Data set. */ get dataset() { return (this.#dataset ??= new DOMStringMap(this)); } /** * Returns style. * * @returns Style. */ get style() { if (!this[PropertySymbol.style]) { this[PropertySymbol.style] = new CSSStyleDeclaration(this); } return this[PropertySymbol.style]; } /** * Returns tab index. * * @returns Tab index. */ get tabIndex() { const tabIndex = this.getAttribute('tabindex'); return tabIndex !== null ? Number(tabIndex) : -1; } /** * Returns tab index. * * @param tabIndex Tab index. */ set tabIndex(tabIndex) { if (tabIndex === -1) { this.removeAttribute('tabindex'); } else { this.setAttribute('tabindex', String(tabIndex)); } } /** * Triggers a blur event. */ blur() { HTMLElementUtility.blur(this); } /** * Triggers a focus event. */ focus() { HTMLElementUtility.focus(this); } } //# sourceMappingURL=SVGElement.js.map