/
IElement.ts
267 lines (236 loc) · 6.68 KB
/
IElement.ts
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
import IShadowRoot from '../shadow-root/IShadowRoot';
import Attr from '../../attribute/Attr';
import DOMRect from './DOMRect';
import IDOMTokenList from '../../dom-token-list/IDOMTokenList';
import INode from './../node/INode';
import IChildNode from '../child-node/IChildNode';
import IParentNode from '../parent-node/IParentNode';
import INonDocumentTypeChildNode from '../child-node/INonDocumentTypeChildNode';
import IDOMRectList from './IDOMRectList';
export type TInsertAdjacentPositions = 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend';
/**
* Element.
*/
export default interface IElement extends IChildNode, INonDocumentTypeChildNode, IParentNode {
readonly tagName: string;
readonly shadowRoot: IShadowRoot;
readonly classList: IDOMTokenList;
readonly namespaceURI: string;
scrollTop: number;
scrollLeft: number;
id: string;
className: string;
innerHTML: string;
outerHTML: string;
slot: string;
readonly nodeName: string;
readonly localName: string;
readonly attributes: { [k: string]: Attr | number };
/**
* 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;
/**
* 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;
/**
* Returns namespace attribute value.
*
* @param namespace Namespace URI.
* @param localName Local name.
*/
getAttributeNS(namespace: string, 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, 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, localName: string): void;
/**
* Attaches a shadow root.
*
* @param _shadowRootInit Shadow root init.
* @returns Shadow root.
*/
attachShadow(_shadowRootInit: { mode: string }): IShadowRoot;
/**
* 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;
/**
* 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(): IDOMRectList<DOMRect>;
/**
* 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): IElement;
/**
* The setAttributeNode() method adds a new Attr node to the specified element.
*
* @param attribute Attribute.
* @returns Replaced attribute.
*/
setAttributeNode(attribute: Attr): Attr;
/**
* The setAttributeNodeNS() method adds a new Attr node to the specified element.
*
* @param attribute Attribute.
* @returns Replaced attribute.
*/
setAttributeNodeNS(attribute: Attr): Attr;
/**
* Returns an Attr node.
*
* @param name Name.
* @returns Replaced attribute.
*/
getAttributeNode(name: string): Attr;
/**
* Returns a namespaced Attr node.
*
* @param namespace Namespace.
* @param nodeName Node name.
* @returns Replaced attribute.
*/
getAttributeNodeNS(namespace: string, nodeName: string): Attr;
/**
* Removes an Attr node.
*
* @param attribute Attribute.
*/
removeAttributeNode(attribute: Attr): void;
/**
* Removes an Attr node.
*
* @param attribute Attribute.
*/
removeAttributeNodeNS(attribute: Attr): void;
/**
* Clones a node.
*
* @override
* @param [deep=false] "true" to clone deep.
* @returns Cloned node.
*/
cloneNode(deep: boolean): IElement;
/**
* 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: TInsertAdjacentPositions, node: INode): INode | null;
/**
* Inserts an HTML string to the given position.
*
* @param position Position to insert text.
* @param text HTML string to insert.
*/
insertAdjacentHTML(position: TInsertAdjacentPositions, text: string): void;
/**
* Inserts text to the given position.
*
* @param position Position to insert text.
* @param text String to insert.
*/
insertAdjacentText(position: TInsertAdjacentPositions, text: string): void;
}