happy-dom-without-node
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.
675 lines • 20.4 kB
TypeScript
import Node from '../node/Node.js';
import * as PropertySymbol from '../../PropertySymbol.js';
import ShadowRoot from '../shadow-root/ShadowRoot.js';
import DOMRect from './DOMRect.js';
import DOMTokenList from '../../dom-token-list/DOMTokenList.js';
import HTMLCollection from './HTMLCollection.js';
import NodeList from '../node/NodeList.js';
import DOMRectList from './DOMRectList.js';
import Attr from '../attr/Attr.js';
import NamedNodeMap from '../../named-node-map/NamedNodeMap.js';
import Event from '../../event/Event.js';
import CSSStyleDeclaration from '../../css/declaration/CSSStyleDeclaration.js';
import NodeTypeEnum from '../node/NodeTypeEnum.js';
import IHTMLElementTagNameMap from '../../config/IHTMLElementTagNameMap.js';
import ISVGElementTagNameMap from '../../config/ISVGElementTagNameMap.js';
import IChildNode from '../child-node/IChildNode.js';
import INonDocumentTypeChildNode from '../child-node/INonDocumentTypeChildNode.js';
import IParentNode from '../parent-node/IParentNode.js';
type InsertAdjacentPosition = 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend';
/**
* Element.
*/
export default class Element extends Node implements IChildNode, INonDocumentTypeChildNode, IParentNode {
static [PropertySymbol.observedAttributes]: string[];
static [PropertySymbol.tagName]: string | null;
static [PropertySymbol.localName]: string | null;
static [PropertySymbol.namespaceURI]: string | null;
static observedAttributes: string[];
cloneNode: (deep?: boolean) => Element;
oncancel: (event: Event) => void | null;
onerror: (event: Event) => void | null;
onscroll: (event: Event) => void | null;
onselect: (event: Event) => void | null;
onwheel: (event: Event) => void | null;
oncopy: (event: Event) => void | null;
oncut: (event: Event) => void | null;
onpaste: (event: Event) => void | null;
oncompositionend: (event: Event) => void | null;
oncompositionstart: (event: Event) => void | null;
oncompositionupdate: (event: Event) => void | null;
onblur: (event: Event) => void | null;
onfocus: (event: Event) => void | null;
onfocusin: (event: Event) => void | null;
onfocusout: (event: Event) => void | null;
onfullscreenchange: (event: Event) => void | null;
onfullscreenerror: (event: Event) => void | null;
onkeydown: (event: Event) => void | null;
onkeyup: (event: Event) => void | null;
onauxclick: (event: Event) => void | null;
onclick: (event: Event) => void | null;
oncontextmenu: (event: Event) => void | null;
ondblclick: (event: Event) => void | null;
onmousedown: (event: Event) => void | null;
onmouseenter: (event: Event) => void | null;
onmouseleave: (event: Event) => void | null;
onmousemove: (event: Event) => void | null;
onmouseout: (event: Event) => void | null;
onmouseover: (event: Event) => void | null;
onmouseup: (event: Event) => void | null;
ontouchcancel: (event: Event) => void | null;
ontouchend: (event: Event) => void | null;
ontouchmove: (event: Event) => void | null;
ontouchstart: (event: Event) => void | null;
[PropertySymbol.children]: HTMLCollection<Element>;
[PropertySymbol.classList]: DOMTokenList;
[PropertySymbol.isValue]: string | null;
[PropertySymbol.computedStyle]: CSSStyleDeclaration | null;
[PropertySymbol.nodeType]: NodeTypeEnum;
[PropertySymbol.tagName]: string | null;
[PropertySymbol.localName]: string | null;
[PropertySymbol.prefix]: string | null;
[PropertySymbol.shadowRoot]: ShadowRoot | null;
[PropertySymbol.scrollHeight]: number;
[PropertySymbol.scrollWidth]: number;
[PropertySymbol.scrollTop]: number;
[PropertySymbol.scrollLeft]: number;
[PropertySymbol.attributes]: NamedNodeMap;
[PropertySymbol.namespaceURI]: string | null;
/**
* Returns tag name.
*
* @returns Tag name.
*/
get tagName(): string;
/**
* Returns prefix.
*
* @returns Prefix.
*/
get prefix(): string | null;
/**
* Returns shadow root.
*
* @returns Shadow root.
*/
get shadowRoot(): ShadowRoot | null;
/**
* Returns scroll height.
*
* @returns Scroll height.
*/
get scrollHeight(): number;
/**
* Returns scroll width.
*
* @returns Scroll width.
*/
get scrollWidth(): number;
/**
* Returns scroll top.
*
* @returns Scroll top.
*/
get scrollTop(): number;
/**
* Sets scroll top.
*
* @param value Scroll top.
*/
set scrollTop(value: number);
/**
* Returns scroll left.
*
* @returns Scroll left.
*/
get scrollLeft(): number;
/**
* Sets scroll left.
*
* @param value Scroll left.
*/
set scrollLeft(value: number);
/**
* Returns attributes.
*
* @returns Attributes.
*/
get attributes(): NamedNodeMap;
/**
* Returns namespace URI.
*
* @returns Namespace URI.
*/
get namespaceURI(): string | null;
/**
* Returns element children.
*/
get children(): HTMLCollection<Element>;
/**
* Returns class list.
*
* @returns Class list.
*/
get classList(): DOMTokenList;
/**
* Returns ID.
*
* @returns ID.
*/
get id(): string;
/**
* Sets ID.
*
* @param id ID.
*/
set id(id: string);
/**
* Returns class name.
*
* @returns Class name.
*/
get className(): string;
/**
* Sets class name.
*
* @param className Class name.
*/
set className(className: string);
/**
* Node name.
*
* @returns Node name.
*/
get nodeName(): string;
/**
* Local name.
*
* @returns Local name.
*/
get localName(): string;
/**
* Returns role.
*
* @returns Role.
*/
get role(): string;
/**
* Sets role.
*
* @param role Role.
*/
set role(role: string);
/**
* Previous element sibling.
*
* @returns Element.
*/
get previousElementSibling(): Element;
/**
* Next element sibling.
*
* @returns Element.
*/
get nextElementSibling(): Element;
/**
* Get text value of children.
*
* @returns Text content.
*/
get textContent(): string;
/**
* Sets text content.
*
* @param textContent Text content.
*/
set textContent(textContent: string);
/**
* Returns inner HTML.
*
* @returns HTML.
*/
get innerHTML(): string;
/**
* Sets inner HTML.
*
* @param html HTML.
*/
set innerHTML(html: string);
/**
* Returns outer HTML.
*
* @returns HTML.
*/
get outerHTML(): string;
/**
* Returns outer HTML.
*
* @param html HTML.
*/
set outerHTML(html: string);
/**
* First element child.
*
* @returns Element.
*/
get firstElementChild(): Element;
/**
* Last element child.
*
* @returns Element.
*/
get lastElementChild(): Element;
/**
* Last element child.
*
* @returns Element.
*/
get childElementCount(): number;
/**
* Returns slot.
*
* @returns Slot.
*/
get slot(): string;
/**
* Returns slot.
*
* @param slot Slot.
*/
set slot(title: string);
/**
* Attribute changed callback.
*
* @param name Name.
* @param oldValue Old value.
* @param newValue New value.
*/
attributeChangedCallback?(name: string, oldValue: string, newValue: string): void;
/**
* Returns inner HTML and optionally the content of shadow roots.
*
* This is a feature implemented in Chromium, but not supported by Mozilla yet.
*
* @see https://web.dev/declarative-shadow-dom/
* @see https://chromestatus.com/feature/5191745052606464
* @param [options] Options.
* @param [options.includeShadowRoots] Set to "true" to include shadow roots.
* @returns HTML.
*/
getInnerHTML(options?: {
includeShadowRoots?: boolean;
}): string;
/**
* @override
*/
[PropertySymbol.cloneNode](deep?: boolean): Element;
/**
* @override
*/
[PropertySymbol.appendChild](node: Node): Node;
/**
* @override
*/
[PropertySymbol.removeChild](node: Node): Node;
/**
* @override
*/
[PropertySymbol.insertBefore](newNode: Node, referenceNode: Node | null): Node;
/**
* Removes the node from its parent.
*/
remove(): void;
/**
* The Node.replaceWith() method replaces this Node in the children list of its parent with a set of Node or DOMString objects.
*
* @param nodes List of Node or DOMString.
*/
replaceWith(...nodes: (Node | string)[]): void;
/**
* Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, just before this ChildNode. DOMString objects are inserted as equivalent Text nodes.
*
* @param nodes List of Node or DOMString.
*/
before(...nodes: (string | Node)[]): void;
/**
* Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, just after this ChildNode. DOMString objects are inserted as equivalent Text nodes.
*
* @param nodes List of Node or DOMString.
*/
after(...nodes: (string | Node)[]): void;
/**
* Inserts a set of Node objects or DOMString objects after the last child of the ParentNode. DOMString objects are inserted as equivalent Text nodes.
*
* @param nodes List of Node or DOMString.
*/
append(...nodes: (string | Node)[]): void;
/**
* Inserts a set of Node objects or DOMString objects before the first child of the ParentNode. DOMString objects are inserted as equivalent Text nodes.
*
* @param nodes List of Node or DOMString.
*/
prepend(...nodes: (string | Node)[]): void;
/**
* Replaces the existing children of a node with a specified new set of children.
*
* @param nodes List of Node or DOMString.
*/
replaceChildren(...nodes: (string | Node)[]): void;
/**
* Inserts a node to the given position.
*
* @param position Position to insert element.
* @param element Node to insert.
* @returns Inserted node or null if couldn't insert.
*/
insertAdjacentElement(position: InsertAdjacentPosition, element: Node): Node | null;
/**
* Inserts an HTML string to the given position.
*
* @param position Position to insert text.
* @param text HTML string to insert.
*/
insertAdjacentHTML(position: InsertAdjacentPosition, text: string): void;
/**
* Inserts text to the given position.
*
* @param position Position to insert text.
* @param text String to insert.
*/
insertAdjacentText(position: InsertAdjacentPosition, text: string): void;
/**
* Sets an attribute.
*
* @param name Name.
* @param value Value.
*/
setAttribute(name: string, value: string): void;
/**
* Sets a namespace attribute.
*
* @param namespaceURI Namespace URI.
* @param name Name.
* @param value Value.
*/
setAttributeNS(namespaceURI: string, name: string, value: string): void;
/**
* Returns attribute names.
*
* @returns Attribute names.
*/
getAttributeNames(): string[];
/**
* Returns attribute value.
*
* @param name Name.
*/
getAttribute(name: string): string;
/**
* Toggle an attribute.
* Returns `true` if attribute name is eventually present, and `false` otherwise.
*
* @param name A DOMString specifying the name of the attribute to be toggled.
* @param force A boolean value to determine whether the attribute should be added or removed, no matter whether the attribute is present or not at the moment.
*/
toggleAttribute(name: string, force?: boolean): boolean;
/**
* Returns namespace attribute value.
*
* @param namespace Namespace URI.
* @param localName Local name.
*/
getAttributeNS(namespace: string | null, localName: string): string;
/**
* Returns a boolean value indicating whether the specified element has the attribute or not.
*
* @param name Attribute name.
* @returns True if attribute exists, false otherwise.
*/
hasAttribute(name: string): boolean;
/**
* Returns a boolean value indicating whether the specified element has the namespace attribute or not.
*
* @param namespace Namespace URI.
* @param localName Local name.
* @returns True if attribute exists, false otherwise.
*/
hasAttributeNS(namespace: string | null, localName: string): boolean;
/**
* Returns "true" if the element has attributes.
*
* @returns "true" if the element has attributes.
*/
hasAttributes(): boolean;
/**
* Removes an attribute.
*
* @param name Name.
*/
removeAttribute(name: string): void;
/**
* Removes a namespace attribute.
*
* @param namespace Namespace URI.
* @param localName Local name.
*/
removeAttributeNS(namespace: string | null, localName: string): void;
/**
* Attaches a shadow root.
*
* @param init Shadow root init.
* @param init.mode Shadow root mode.
* @returns Shadow root.
*/
attachShadow(init: {
mode: string;
}): ShadowRoot;
/**
* Converts to string.
*
* @returns String.
*/
toString(): string;
/**
* Returns the size of an element and its position relative to the viewport.
*
* @returns DOM rect.
*/
getBoundingClientRect(): DOMRect;
/**
* Returns a collection of DOMRect objects that indicate the bounding rectangles for each CSS border box in a client.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getClientRects
* @returns DOM rect list.
*/
getClientRects(): DOMRectList;
/**
* The matches() method checks to see if the Element would be selected by the provided selectorString.
*
* @param selector Selector.
* @returns "true" if matching.
*/
matches(selector: string): boolean;
/**
* Traverses the Element and its parents (heading toward the document root) until it finds a node that matches the provided selector string.
*
* @param selector Selector.
* @returns Closest matching element.
*/
closest(selector: string): Element;
/**
* Query CSS selector to find matching nodes.
*
* @param selector CSS selector.
* @returns Matching elements.
*/
querySelectorAll<K extends keyof IHTMLElementTagNameMap>(selector: K): NodeList<IHTMLElementTagNameMap[K]>;
/**
* Query CSS selector to find matching elments.
*
* @param selector CSS selector.
* @returns Matching elements.
*/
querySelectorAll<K extends keyof ISVGElementTagNameMap>(selector: K): NodeList<ISVGElementTagNameMap[K]>;
/**
* Query CSS selector to find matching elments.
*
* @param selector CSS selector.
* @returns Matching elements.
*/
querySelectorAll(selector: string): NodeList<Element>;
/**
* Query CSS Selector to find matching node.
*
* @param selector CSS selector.
* @returns Matching element.
*/
querySelector<K extends keyof IHTMLElementTagNameMap>(selector: K): IHTMLElementTagNameMap[K] | null;
/**
* Query CSS Selector to find matching node.
*
* @param selector CSS selector.
* @returns Matching element.
*/
querySelector<K extends keyof ISVGElementTagNameMap>(selector: K): ISVGElementTagNameMap[K] | null;
/**
* Query CSS Selector to find matching node.
*
* @param selector CSS selector.
* @returns Matching element.
*/
querySelector(selector: string): Element | null;
/**
* Returns an elements by class name.
*
* @param className Tag name.
* @returns Matching element.
*/
getElementsByClassName(className: string): HTMLCollection<Element>;
/**
* Returns an elements by tag name.
*
* @param tagName Tag name.
* @returns Matching element.
*/
getElementsByTagName<K extends keyof IHTMLElementTagNameMap>(tagName: K): HTMLCollection<IHTMLElementTagNameMap[K]>;
/**
* Returns an elements by tag name.
*
* @param tagName Tag name.
* @returns Matching element.
*/
getElementsByTagName<K extends keyof ISVGElementTagNameMap>(tagName: K): HTMLCollection<ISVGElementTagNameMap[K]>;
/**
* Returns an elements by tag name.
*
* @param tagName Tag name.
* @returns Matching element.
*/
getElementsByTagName(tagName: string): HTMLCollection<Element>;
/**
* Returns an elements by tag name and namespace.
*
* @param namespaceURI Namespace URI.
* @param tagName Tag name.
* @returns Matching element.
*/
getElementsByTagNameNS<K extends keyof IHTMLElementTagNameMap>(namespaceURI: 'http://www.w3.org/1999/xhtml', tagName: K): HTMLCollection<IHTMLElementTagNameMap[K]>;
/**
* Returns an elements by tag name and namespace.
*
* @param namespaceURI Namespace URI.
* @param tagName Tag name.
* @returns Matching element.
*/
getElementsByTagNameNS<K extends keyof ISVGElementTagNameMap>(namespaceURI: 'http://www.w3.org/2000/svg', tagName: K): HTMLCollection<ISVGElementTagNameMap[K]>;
/**
* Returns an elements by tag name and namespace.
*
* @param namespaceURI Namespace URI.
* @param tagName Tag name.
* @returns Matching element.
*/
getElementsByTagNameNS(namespaceURI: string, tagName: string): HTMLCollection<Element>;
/**
* The setAttributeNode() method adds a new Attr node to the specified element.
*
* @param attribute Attribute.
* @returns Replaced attribute.
*/
setAttributeNode(attribute: Attr): Attr | null;
/**
* The setAttributeNodeNS() method adds a new Attr node to the specified element.
*
* @param attribute Attribute.
* @returns Replaced attribute.
*/
setAttributeNodeNS(attribute: Attr): Attr | null;
/**
* Returns an Attr node.
*
* @param name Name.
* @returns Replaced attribute.
*/
getAttributeNode(name: string): Attr | null;
/**
* Returns a namespaced Attr node.
*
* @param namespace Namespace.
* @param localName Name.
* @returns Replaced attribute.
*/
getAttributeNodeNS(namespace: string | null, localName: string): Attr | null;
/**
* Removes an Attr node.
*
* @param attribute Attribute.
* @returns Removed attribute.
*/
removeAttributeNode(attribute: Attr): Attr | null;
/**
* Removes an Attr node.
*
* @param attribute Attribute.
* @returns Removed attribute.
*/
removeAttributeNodeNS(attribute: Attr): Attr | null;
/**
* Scrolls to a particular set of coordinates.
*
* @param x X position or options object.
* @param y Y position.
*/
scroll(x: {
top?: number;
left?: number;
behavior?: string;
} | number, y?: number): void;
/**
* Scrolls to a particular set of coordinates.
*
* @param x X position or options object.
* @param y Y position.
*/
scrollTo(x: {
top?: number;
left?: number;
behavior?: string;
} | number, y?: number): void;
/**
* Scrolls the element's ancestor containers such that the element on which scrollIntoView() is called is visible to the user.
*
* @param [_options] Options.
*/
scrollIntoView(_options?: boolean | {
behavior?: 'smooth' | 'instant' | 'auto';
block?: 'start' | 'center' | 'end' | 'nearest';
inline?: 'start' | 'center' | 'end' | 'nearest';
}): void;
/**
* @override
*/
dispatchEvent(event: Event): boolean;
}
export {};
//# sourceMappingURL=Element.d.ts.map