happy-dom 2.40.3 → 2.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of happy-dom might be problematic. Click here for more details.
- package/lib/css/CSSStyleDeclaration.js +1 -1
- package/lib/css/CSSStyleDeclaration.js.map +1 -1
- package/lib/dom-token-list/DOMTokenList.d.ts +104 -0
- package/lib/dom-token-list/DOMTokenList.js +209 -0
- package/lib/dom-token-list/DOMTokenList.js.map +1 -0
- package/lib/dom-token-list/IDOMTokenList.d.ts +18 -0
- package/lib/dom-token-list/IDOMTokenList.js +3 -0
- package/lib/dom-token-list/IDOMTokenList.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/nodes/document/Document.d.ts +14 -0
- package/lib/nodes/document/Document.js +21 -0
- package/lib/nodes/document/Document.js.map +1 -1
- package/lib/nodes/document/IDocument.d.ts +20 -2
- package/lib/nodes/element/Element.d.ts +15 -5
- package/lib/nodes/element/Element.js +28 -3
- package/lib/nodes/element/Element.js.map +1 -1
- package/lib/nodes/element/IElement.d.ts +2 -2
- package/lib/nodes/html-label-element/HTMLLabelElement.d.ts +0 -1
- package/lib/nodes/html-label-element/HTMLLabelElement.js +2 -6
- package/lib/nodes/html-label-element/HTMLLabelElement.js.map +1 -1
- package/lib/nodes/html-link-element/HTMLLinkElement.d.ts +12 -0
- package/lib/nodes/html-link-element/HTMLLinkElement.js +26 -0
- package/lib/nodes/html-link-element/HTMLLinkElement.js.map +1 -1
- package/lib/nodes/html-link-element/IHTMLLinkElement.d.ts +2 -0
- package/lib/selection/Selection.d.ts +95 -0
- package/lib/selection/Selection.js +127 -0
- package/lib/selection/Selection.js.map +1 -0
- package/lib/window/IWindow.d.ts +5 -1
- package/lib/window/Window.d.ts +3 -0
- package/lib/window/Window.js +3 -0
- package/lib/window/Window.js.map +1 -1
- package/package.json +2 -2
- package/src/css/CSSStyleDeclaration.ts +1 -1
- package/src/dom-token-list/DOMTokenList.ts +219 -0
- package/src/dom-token-list/IDOMTokenList.ts +19 -0
- package/src/index.ts +3 -1
- package/src/nodes/document/Document.ts +20 -0
- package/src/nodes/document/IDocument.ts +21 -2
- package/src/nodes/element/Element.ts +30 -3
- package/src/nodes/element/IElement.ts +2 -2
- package/src/nodes/html-label-element/HTMLLabelElement.ts +1 -5
- package/src/nodes/html-link-element/HTMLLinkElement.ts +26 -0
- package/src/nodes/html-link-element/IHTMLLinkElement.ts +2 -0
- package/src/selection/Selection.ts +140 -0
- package/src/window/IWindow.ts +5 -1
- package/src/window/Window.ts +3 -0
- package/lib/nodes/element/ClassList.d.ts +0 -40
- package/lib/nodes/element/ClassList.js +0 -99
- package/lib/nodes/element/ClassList.js.map +0 -1
- package/src/nodes/element/ClassList.ts +0 -92
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "happy-dom",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.43.0",
|
4
4
|
"license": "MIT",
|
5
5
|
"homepage": "https://github.com/capricorn86/happy-dom",
|
6
6
|
"repository": "https://github.com/capricorn86/happy-dom",
|
@@ -75,5 +75,5 @@
|
|
75
75
|
"ts-jest": "^26.5.6",
|
76
76
|
"typescript": "^4.2.4"
|
77
77
|
},
|
78
|
-
"gitHead": "
|
78
|
+
"gitHead": "ac202fdcad3d4e5b6a85d98728526ffca1a3b6d8"
|
79
79
|
}
|
@@ -0,0 +1,219 @@
|
|
1
|
+
import DOMException from '../exception/DOMException';
|
2
|
+
import Element from '../nodes/element/Element';
|
3
|
+
import IDOMTokenList from './IDOMTokenList';
|
4
|
+
|
5
|
+
/**
|
6
|
+
* DOM Token List.
|
7
|
+
*
|
8
|
+
* Reference:
|
9
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList.
|
10
|
+
*/
|
11
|
+
export default class DOMTokenList implements IDOMTokenList {
|
12
|
+
public readonly length = 0;
|
13
|
+
private _ownerElement: Element;
|
14
|
+
private _attributeName: string;
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Constructor.
|
18
|
+
*
|
19
|
+
* @param ownerElement Owner element.
|
20
|
+
* @param attributeName Attribute name.
|
21
|
+
*/
|
22
|
+
constructor(ownerElement: Element, attributeName) {
|
23
|
+
this._ownerElement = ownerElement;
|
24
|
+
this._attributeName = attributeName;
|
25
|
+
this._updateIndices();
|
26
|
+
}
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Set value.
|
30
|
+
*
|
31
|
+
* @param value Value.
|
32
|
+
*/
|
33
|
+
public set value(value: string) {
|
34
|
+
this._ownerElement.setAttributeNS(null, this._attributeName, value);
|
35
|
+
}
|
36
|
+
|
37
|
+
/**
|
38
|
+
* Get value.
|
39
|
+
*/
|
40
|
+
public get value(): string {
|
41
|
+
return this._ownerElement.getAttributeNS(null, this._attributeName);
|
42
|
+
}
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Get ClassName.
|
46
|
+
*
|
47
|
+
* @param index Index.
|
48
|
+
* */
|
49
|
+
public item(index: number | string): string {
|
50
|
+
index = typeof index === 'number' ? index : 0;
|
51
|
+
return index >= 0 && this[index] ? this[index] : null;
|
52
|
+
}
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Replace Token.
|
56
|
+
*
|
57
|
+
* @param token Token.
|
58
|
+
* @param newToken NewToken.
|
59
|
+
*/
|
60
|
+
public replace(token: string, newToken: string): boolean {
|
61
|
+
const attr = this._ownerElement.getAttributeNS(null, this._attributeName);
|
62
|
+
const list = attr ? attr.split(' ') : [];
|
63
|
+
const index = list.indexOf(token);
|
64
|
+
if (index === -1) {
|
65
|
+
return false;
|
66
|
+
}
|
67
|
+
list[index] = newToken;
|
68
|
+
this._ownerElement.setAttributeNS(null, this._attributeName, list.join(' '));
|
69
|
+
return true;
|
70
|
+
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Supports.
|
74
|
+
*
|
75
|
+
* @param token Token.
|
76
|
+
*/
|
77
|
+
public supports(token: string): boolean {
|
78
|
+
// TODO: Only implemented for classList, which does not have any supported tokens
|
79
|
+
throw new DOMException(
|
80
|
+
`Failed to execute '${token}' on 'DOMTokenList': DOMTokenList has no supported tokens.`,
|
81
|
+
'TypeError'
|
82
|
+
);
|
83
|
+
}
|
84
|
+
|
85
|
+
/**
|
86
|
+
* Returns an iterator, allowing you to go through all values of the key/value pairs contained in this object.
|
87
|
+
*
|
88
|
+
*
|
89
|
+
*/
|
90
|
+
public values(): IterableIterator<string> {
|
91
|
+
const attr = this._ownerElement.getAttributeNS(null, this._attributeName);
|
92
|
+
return (attr ? attr.split(' ') : []).values();
|
93
|
+
}
|
94
|
+
|
95
|
+
/**
|
96
|
+
* Returns an iterator, allowing you to go through all key/value pairs contained in this object.
|
97
|
+
*
|
98
|
+
*
|
99
|
+
*/
|
100
|
+
public entries(): IterableIterator<[number, string]> {
|
101
|
+
const attr = this._ownerElement.getAttributeNS(null, this._attributeName);
|
102
|
+
return (attr ? attr.split(' ') : []).entries();
|
103
|
+
}
|
104
|
+
|
105
|
+
/**
|
106
|
+
* Executes a provided callback function once for each DOMTokenList element.
|
107
|
+
*
|
108
|
+
* @param callback
|
109
|
+
* @param thisArg
|
110
|
+
*/
|
111
|
+
public forEach(callback: (currentValue, currentIndex, listObj) => void, thisArg?: this): void {
|
112
|
+
const attr = this._ownerElement.getAttributeNS(null, this._attributeName);
|
113
|
+
return (attr ? attr.split(' ') : []).forEach(callback, thisArg);
|
114
|
+
}
|
115
|
+
|
116
|
+
/**
|
117
|
+
* Returns an iterator, allowing you to go through all keys of the key/value pairs contained in this object.
|
118
|
+
*
|
119
|
+
*/
|
120
|
+
public keys(): IterableIterator<number> {
|
121
|
+
const attr = this._ownerElement.getAttributeNS(null, this._attributeName);
|
122
|
+
return (attr ? attr.split(' ') : []).keys();
|
123
|
+
}
|
124
|
+
|
125
|
+
/**
|
126
|
+
* Adds tokens.
|
127
|
+
*
|
128
|
+
* @param tokens Tokens.
|
129
|
+
*/
|
130
|
+
public add(...tokens: string[]): void {
|
131
|
+
const attr = this._ownerElement.getAttributeNS(null, this._attributeName);
|
132
|
+
const list = attr ? attr.split(' ') : [];
|
133
|
+
|
134
|
+
for (const token of tokens) {
|
135
|
+
const index = list.indexOf(token);
|
136
|
+
if (index === -1) {
|
137
|
+
list.push(token);
|
138
|
+
} else {
|
139
|
+
list[index] = token;
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
143
|
+
this._ownerElement.setAttributeNS(null, this._attributeName, list.join(' '));
|
144
|
+
}
|
145
|
+
|
146
|
+
/**
|
147
|
+
* Removes tokens.
|
148
|
+
*
|
149
|
+
* @param tokens Tokens.
|
150
|
+
*/
|
151
|
+
public remove(...tokens: string[]): void {
|
152
|
+
const attr = this._ownerElement.getAttributeNS(null, this._attributeName);
|
153
|
+
const list = attr ? attr.split(' ') : [];
|
154
|
+
|
155
|
+
for (const token of tokens) {
|
156
|
+
const index = list.indexOf(token);
|
157
|
+
if (index !== -1) {
|
158
|
+
list.splice(index, 1);
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
this._ownerElement.setAttributeNS(null, this._attributeName, list.join(' '));
|
163
|
+
}
|
164
|
+
|
165
|
+
/**
|
166
|
+
* Check if the list contains a class.
|
167
|
+
*
|
168
|
+
* @param className Class name.
|
169
|
+
* @returns TRUE if it contains.
|
170
|
+
*/
|
171
|
+
public contains(className: string): boolean {
|
172
|
+
const attr = this._ownerElement.getAttributeNS(null, this._attributeName);
|
173
|
+
return (attr ? attr.split(' ') : []).includes(className);
|
174
|
+
}
|
175
|
+
|
176
|
+
/**
|
177
|
+
* Toggle a class name.
|
178
|
+
*
|
179
|
+
* @param token A string representing the class name you want to toggle.
|
180
|
+
* @param [force] If included, turns the toggle into a one way-only operation. If set to `false`, then class name will only be removed, but not added. If set to `true`, then class name will only be added, but not removed.
|
181
|
+
* @returns A boolean value, `true` or `false`, indicating whether class name is in the list after the call or not.
|
182
|
+
*/
|
183
|
+
public toggle(token: string, force?: boolean): boolean {
|
184
|
+
let shouldAdd: boolean;
|
185
|
+
|
186
|
+
if (force !== undefined) {
|
187
|
+
shouldAdd = force;
|
188
|
+
} else {
|
189
|
+
shouldAdd = !this.contains(token);
|
190
|
+
}
|
191
|
+
|
192
|
+
if (shouldAdd) {
|
193
|
+
this.add(token);
|
194
|
+
return true;
|
195
|
+
}
|
196
|
+
|
197
|
+
this.remove(token);
|
198
|
+
|
199
|
+
return false;
|
200
|
+
}
|
201
|
+
|
202
|
+
/**
|
203
|
+
* Updates indices.
|
204
|
+
*/
|
205
|
+
public _updateIndices(): void {
|
206
|
+
const attr = this._ownerElement.getAttribute('class');
|
207
|
+
const list = attr ? Array.from(new Set(attr.split(' '))) : [];
|
208
|
+
|
209
|
+
for (let i = list.length - 1, max = this.length; i < max; i++) {
|
210
|
+
delete this[i];
|
211
|
+
}
|
212
|
+
|
213
|
+
for (let i = 0, max = list.length; i < max; i++) {
|
214
|
+
this[i] = list[i];
|
215
|
+
}
|
216
|
+
|
217
|
+
(<number>this.length) = list.length;
|
218
|
+
}
|
219
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
/**
|
2
|
+
* IDOMTokenList.
|
3
|
+
*/
|
4
|
+
export default interface IDOMTokenList {
|
5
|
+
value: string;
|
6
|
+
readonly length: number;
|
7
|
+
item(index: number | string): string;
|
8
|
+
contains(token: string): boolean;
|
9
|
+
add(...tokens: string[]): void;
|
10
|
+
remove(...tokens: string[]): void;
|
11
|
+
toggle(token: string, force?: boolean): boolean;
|
12
|
+
replace(token: string, newToken: string): boolean;
|
13
|
+
supports(token: string): boolean;
|
14
|
+
|
15
|
+
values(): IterableIterator<string>;
|
16
|
+
entries(): IterableIterator<[number, string]>;
|
17
|
+
forEach(callback: (currentValue, currentIndex, listObj) => void, thisArg?: this): void;
|
18
|
+
keys(): IterableIterator<number>;
|
19
|
+
}
|
package/src/index.ts
CHANGED
@@ -106,6 +106,7 @@ import ChildLessElements from './config/ChildLessElements';
|
|
106
106
|
import CSSStyleSheet from './css/CSSStyleSheet';
|
107
107
|
import Storage from './storage/Storage';
|
108
108
|
import URLSearchParams from './url-search-params/URLSearchParams';
|
109
|
+
import Selection from './selection/Selection';
|
109
110
|
|
110
111
|
export {
|
111
112
|
AsyncWindow,
|
@@ -215,5 +216,6 @@ export {
|
|
215
216
|
ChildLessElements,
|
216
217
|
CSSStyleSheet,
|
217
218
|
Storage,
|
218
|
-
URLSearchParams
|
219
|
+
URLSearchParams,
|
220
|
+
Selection
|
219
221
|
};
|
@@ -21,6 +21,7 @@ import CSSStyleSheet from '../../css/CSSStyleSheet';
|
|
21
21
|
import DOMException from '../../exception/DOMException';
|
22
22
|
import CookieUtility from '../../cookie/CookieUtility';
|
23
23
|
import IElement from '../element/IElement';
|
24
|
+
import IHTMLScriptElement from '../html-script-element/IHTMLScriptElement';
|
24
25
|
import IHTMLElement from '../html-element/IHTMLElement';
|
25
26
|
import IDocumentType from '../document-type/IDocumentType';
|
26
27
|
import INode from '../node/INode';
|
@@ -35,6 +36,7 @@ import IHTMLStyleElement from '../html-style-element/IHTMLStyleElement';
|
|
35
36
|
import DocumentReadyStateEnum from './DocumentReadyStateEnum';
|
36
37
|
import DocumentReadyStateManager from './DocumentReadyStateManager';
|
37
38
|
import Location from '../../location/Location';
|
39
|
+
import Selection from '../../selection/Selection';
|
38
40
|
|
39
41
|
/**
|
40
42
|
* Document.
|
@@ -239,6 +241,15 @@ export default class Document extends Node implements IDocument {
|
|
239
241
|
return this._defaultView.location;
|
240
242
|
}
|
241
243
|
|
244
|
+
/**
|
245
|
+
* Returns scripts.
|
246
|
+
*
|
247
|
+
* @returns Scripts.
|
248
|
+
*/
|
249
|
+
public get scripts(): IHTMLCollection<IHTMLScriptElement> {
|
250
|
+
return <IHTMLCollection<IHTMLScriptElement>>this.getElementsByTagName('script');
|
251
|
+
}
|
252
|
+
|
242
253
|
/**
|
243
254
|
* Inserts a set of Node objects or DOMString objects after the last child of the ParentNode. DOMString objects are inserted as equivalent Text nodes.
|
244
255
|
*
|
@@ -699,6 +710,15 @@ export default class Document extends Node implements IDocument {
|
|
699
710
|
return adopted;
|
700
711
|
}
|
701
712
|
|
713
|
+
/**
|
714
|
+
* Returns selection.
|
715
|
+
*
|
716
|
+
* @returns Selection.
|
717
|
+
*/
|
718
|
+
public getSelection(): Selection {
|
719
|
+
return new Selection();
|
720
|
+
}
|
721
|
+
|
702
722
|
/**
|
703
723
|
* @override
|
704
724
|
*/
|
@@ -11,6 +11,12 @@ import IParentNode from '../parent-node/IParentNode';
|
|
11
11
|
import INode from '../node/INode';
|
12
12
|
import ICharacterData from '../character-data/ICharacterData';
|
13
13
|
import IDocumentFragment from '../document-fragment/IDocumentFragment';
|
14
|
+
import Selection from '../../selection/Selection';
|
15
|
+
import IHTMLCollection from '../element/IHTMLCollection';
|
16
|
+
import IHTMLScriptElement from '../html-script-element/IHTMLScriptElement';
|
17
|
+
import CSSStyleSheet from '../../css/CSSStyleSheet';
|
18
|
+
import Location from '../../location/Location';
|
19
|
+
import DocumentReadyStateEnum from './DocumentReadyStateEnum';
|
14
20
|
|
15
21
|
/**
|
16
22
|
* Document.
|
@@ -23,7 +29,13 @@ export default interface IDocument extends IParentNode {
|
|
23
29
|
readonly doctype: IDocumentType;
|
24
30
|
readonly body: IHTMLElement;
|
25
31
|
readonly head: IHTMLElement;
|
32
|
+
readonly scripts: IHTMLCollection<IHTMLScriptElement>;
|
26
33
|
readonly activeElement: IHTMLElement;
|
34
|
+
readonly styleSheets: CSSStyleSheet[];
|
35
|
+
readonly scrollingElement: IHTMLElement;
|
36
|
+
readonly location: Location;
|
37
|
+
readonly readyState: DocumentReadyStateEnum;
|
38
|
+
cookie: string;
|
27
39
|
|
28
40
|
/**
|
29
41
|
* Replaces the document HTML with new HTML.
|
@@ -68,7 +80,7 @@ export default interface IDocument extends IParentNode {
|
|
68
80
|
* @param data Text data.
|
69
81
|
* @returns Text node.
|
70
82
|
*/
|
71
|
-
createTextNode(data
|
83
|
+
createTextNode(data?: string): ICharacterData;
|
72
84
|
|
73
85
|
/**
|
74
86
|
* Creates a comment node.
|
@@ -76,7 +88,7 @@ export default interface IDocument extends IParentNode {
|
|
76
88
|
* @param data Text data.
|
77
89
|
* @returns Text node.
|
78
90
|
*/
|
79
|
-
createComment(data
|
91
|
+
createComment(data?: string): ICharacterData;
|
80
92
|
|
81
93
|
/**
|
82
94
|
* Creates a document fragment.
|
@@ -152,4 +164,11 @@ export default interface IDocument extends IParentNode {
|
|
152
164
|
* @returns Adopted node.
|
153
165
|
*/
|
154
166
|
adoptNode(node: INode): INode;
|
167
|
+
|
168
|
+
/**
|
169
|
+
* Returns selection.
|
170
|
+
*
|
171
|
+
* @returns Selection.
|
172
|
+
*/
|
173
|
+
getSelection(): Selection;
|
155
174
|
}
|
@@ -3,7 +3,8 @@ import ShadowRoot from '../shadow-root/ShadowRoot';
|
|
3
3
|
import Attr from '../../attribute/Attr';
|
4
4
|
import DOMRect from './DOMRect';
|
5
5
|
import Range from './Range';
|
6
|
-
import
|
6
|
+
import DOMTokenList from '../../dom-token-list/DOMTokenList';
|
7
|
+
import IDOMTokenList from '../../dom-token-list/IDOMTokenList';
|
7
8
|
import QuerySelector from '../../query-selector/QuerySelector';
|
8
9
|
import SelectorItem from '../../query-selector/SelectorItem';
|
9
10
|
import MutationRecord from '../../mutation-observer/MutationRecord';
|
@@ -36,13 +37,26 @@ export default class Element extends Node implements IElement {
|
|
36
37
|
public tagName: string = null;
|
37
38
|
public nodeType = Node.ELEMENT_NODE;
|
38
39
|
public shadowRoot: IShadowRoot = null;
|
39
|
-
public
|
40
|
+
public _attributes: { [k: string]: Attr } = {};
|
40
41
|
public scrollTop = 0;
|
41
42
|
public scrollLeft = 0;
|
42
43
|
public children: IHTMLCollection<IElement> = HTMLCollectionFactory.create();
|
43
|
-
public _attributes: { [k: string]: Attr } = {};
|
44
44
|
public readonly namespaceURI: string = null;
|
45
45
|
|
46
|
+
private _classList: DOMTokenList = null;
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Returns class list.
|
50
|
+
*
|
51
|
+
* @returns Class list.
|
52
|
+
*/
|
53
|
+
public get classList(): IDOMTokenList {
|
54
|
+
if (!this._classList) {
|
55
|
+
this._classList = new DOMTokenList(this, 'class');
|
56
|
+
}
|
57
|
+
return <IDOMTokenList>this._classList;
|
58
|
+
}
|
59
|
+
|
46
60
|
/**
|
47
61
|
* Returns ID.
|
48
62
|
*
|
@@ -769,6 +783,8 @@ export default class Element extends Node implements IElement {
|
|
769
783
|
|
770
784
|
this._attributes[name] = attribute;
|
771
785
|
|
786
|
+
this._updateDomListIndices();
|
787
|
+
|
772
788
|
if (
|
773
789
|
this.attributeChangedCallback &&
|
774
790
|
(<typeof Element>this.constructor)._observedAttributes &&
|
@@ -842,6 +858,8 @@ export default class Element extends Node implements IElement {
|
|
842
858
|
public removeAttributeNode(attribute: Attr): void {
|
843
859
|
delete this._attributes[attribute.name];
|
844
860
|
|
861
|
+
this._updateDomListIndices();
|
862
|
+
|
845
863
|
if (
|
846
864
|
this.attributeChangedCallback &&
|
847
865
|
(<typeof Element>this.constructor)._observedAttributes &&
|
@@ -933,4 +951,13 @@ export default class Element extends Node implements IElement {
|
|
933
951
|
}
|
934
952
|
return name.toLowerCase();
|
935
953
|
}
|
954
|
+
|
955
|
+
/**
|
956
|
+
* Updates DOM list indices.
|
957
|
+
*/
|
958
|
+
protected _updateDomListIndices(): void {
|
959
|
+
if (this._classList) {
|
960
|
+
this._classList._updateIndices();
|
961
|
+
}
|
962
|
+
}
|
936
963
|
}
|
@@ -2,7 +2,7 @@ import IShadowRoot from '../shadow-root/IShadowRoot';
|
|
2
2
|
import Attr from '../../attribute/Attr';
|
3
3
|
import DOMRect from './DOMRect';
|
4
4
|
import Range from './Range';
|
5
|
-
import
|
5
|
+
import IDOMTokenList from '../../dom-token-list/IDOMTokenList';
|
6
6
|
import INode from './../node/INode';
|
7
7
|
import IChildNode from '../child-node/IChildNode';
|
8
8
|
import IParentNode from '../parent-node/IParentNode';
|
@@ -16,7 +16,7 @@ export type TInsertAdjacentPositions = 'beforebegin' | 'afterbegin' | 'beforeend
|
|
16
16
|
export default interface IElement extends IChildNode, INonDocumentTypeChildNode, IParentNode {
|
17
17
|
readonly tagName: string;
|
18
18
|
readonly shadowRoot: IShadowRoot;
|
19
|
-
readonly classList:
|
19
|
+
readonly classList: IDOMTokenList;
|
20
20
|
readonly namespaceURI: string;
|
21
21
|
scrollTop: number;
|
22
22
|
scrollLeft: number;
|
@@ -10,8 +10,6 @@ import IHTMLLabelElement from './IHTMLLabelElement';
|
|
10
10
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement.
|
11
11
|
*/
|
12
12
|
export default class HTMLLabelElement extends HTMLElement implements IHTMLLabelElement {
|
13
|
-
public _htmlFor: string = null;
|
14
|
-
|
15
13
|
/**
|
16
14
|
* Returns a string containing the ID of the labeled control. This reflects the "for" attribute.
|
17
15
|
*
|
@@ -73,8 +71,6 @@ export default class HTMLLabelElement extends HTMLElement implements IHTMLLabelE
|
|
73
71
|
* @returns Cloned node.
|
74
72
|
*/
|
75
73
|
public cloneNode(deep = false): IHTMLLabelElement {
|
76
|
-
|
77
|
-
clone._htmlFor = this._htmlFor;
|
78
|
-
return clone;
|
74
|
+
return <HTMLLabelElement>super.cloneNode(deep);
|
79
75
|
}
|
80
76
|
}
|
@@ -7,6 +7,8 @@ import IHTMLLinkElement from './IHTMLLinkElement';
|
|
7
7
|
import Event from '../../event/Event';
|
8
8
|
import ErrorEvent from '../../event/events/ErrorEvent';
|
9
9
|
import INode from '../../nodes/node/INode';
|
10
|
+
import DOMTokenList from '../../dom-token-list/DOMTokenList';
|
11
|
+
import IDOMTokenList from '../../dom-token-list/IDOMTokenList';
|
10
12
|
|
11
13
|
/**
|
12
14
|
* HTML Link Element.
|
@@ -19,6 +21,19 @@ export default class HTMLLinkElement extends HTMLElement implements IHTMLLinkEle
|
|
19
21
|
public onload: (event: Event) => void = null;
|
20
22
|
public readonly sheet: CSSStyleSheet = null;
|
21
23
|
public _evaluateCSS = true;
|
24
|
+
private _relList: DOMTokenList = null;
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Returns rel list.
|
28
|
+
*
|
29
|
+
* @returns Rel list.
|
30
|
+
*/
|
31
|
+
public get relList(): IDOMTokenList {
|
32
|
+
if (!this._relList) {
|
33
|
+
this._relList = new DOMTokenList(this, 'rel');
|
34
|
+
}
|
35
|
+
return <IDOMTokenList>this._relList;
|
36
|
+
}
|
22
37
|
|
23
38
|
/**
|
24
39
|
* Returns as.
|
@@ -259,4 +274,15 @@ export default class HTMLLinkElement extends HTMLElement implements IHTMLLinkEle
|
|
259
274
|
}
|
260
275
|
}
|
261
276
|
}
|
277
|
+
|
278
|
+
/**
|
279
|
+
* Updates DOM list indices.
|
280
|
+
*/
|
281
|
+
protected _updateDomListIndices(): void {
|
282
|
+
super._updateDomListIndices();
|
283
|
+
|
284
|
+
if (this._relList) {
|
285
|
+
this._relList._updateIndices();
|
286
|
+
}
|
287
|
+
}
|
262
288
|
}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import CSSStyleSheet from '../../css/CSSStyleSheet';
|
2
|
+
import IDOMTokenList from '../../dom-token-list/IDOMTokenList';
|
2
3
|
import IHTMLElement from '../html-element/IHTMLElement';
|
3
4
|
|
4
5
|
/**
|
@@ -9,6 +10,7 @@ import IHTMLElement from '../html-element/IHTMLElement';
|
|
9
10
|
*/
|
10
11
|
export default interface IHTMLLinkElement extends IHTMLElement {
|
11
12
|
readonly sheet: CSSStyleSheet;
|
13
|
+
readonly relList: IDOMTokenList;
|
12
14
|
as: string;
|
13
15
|
crossOrigin: string;
|
14
16
|
href: string;
|
@@ -0,0 +1,140 @@
|
|
1
|
+
import INode from '../nodes/node/INode';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Selection.
|
5
|
+
*
|
6
|
+
* Reference:
|
7
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Selection.
|
8
|
+
*/
|
9
|
+
export default class Selection {
|
10
|
+
public readonly anchorNode: INode = null;
|
11
|
+
public readonly anchorOffset: number = 0;
|
12
|
+
public readonly baseNode: INode = null;
|
13
|
+
public readonly baseOffset: number = 0;
|
14
|
+
public readonly extentNode: INode = null;
|
15
|
+
public readonly extentOffset: number = 0;
|
16
|
+
public readonly focusNode: INode = null;
|
17
|
+
public readonly focusOffset: number = 0;
|
18
|
+
public readonly isCollapsed: boolean = true;
|
19
|
+
public readonly rangeCount: number = 0;
|
20
|
+
public readonly type: string = 'None';
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Adds a range.
|
24
|
+
*
|
25
|
+
* @param _range Range.
|
26
|
+
*/
|
27
|
+
public addRange(_range: object): void {
|
28
|
+
// Do nothing.
|
29
|
+
}
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Collapses the current selection to a single point.
|
33
|
+
*
|
34
|
+
* @param _node Node.
|
35
|
+
* @param _offset Offset.
|
36
|
+
*/
|
37
|
+
public collapse(_node: INode, _offset?: number): void {
|
38
|
+
// Do nothing.
|
39
|
+
}
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Collapses the selection to the end.
|
43
|
+
*/
|
44
|
+
public collapseToEnd(): void {
|
45
|
+
// Do nothing.
|
46
|
+
}
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Collapses the selection to the start.
|
50
|
+
*/
|
51
|
+
public collapseToStart(): void {
|
52
|
+
// Do nothing.
|
53
|
+
}
|
54
|
+
|
55
|
+
/**
|
56
|
+
* Indicates whether a specified node is part of the selection.
|
57
|
+
*
|
58
|
+
* @param _node Node.
|
59
|
+
* @param _partialContainer Partial container.
|
60
|
+
* @returns Always returns "true" for now.
|
61
|
+
*/
|
62
|
+
public containsNode(_node: INode, _partialContainer?: INode): boolean {
|
63
|
+
return true;
|
64
|
+
}
|
65
|
+
|
66
|
+
/**
|
67
|
+
* Deletes the selected text from the document's DOM.
|
68
|
+
*/
|
69
|
+
public deleteFromDocument(): void {
|
70
|
+
// Do nothing.
|
71
|
+
}
|
72
|
+
|
73
|
+
/**
|
74
|
+
* Moves the focus of the selection to a specified point.
|
75
|
+
*
|
76
|
+
* @param _node Node.
|
77
|
+
* @param _offset Offset.
|
78
|
+
*/
|
79
|
+
public extend(_node: INode, _offset?: number): void {
|
80
|
+
// Do nothing.
|
81
|
+
}
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Moves the focus of the selection to a specified point.
|
85
|
+
*
|
86
|
+
* @param _index Index.
|
87
|
+
*/
|
88
|
+
public getRangeAt(_index: number): object {
|
89
|
+
throw new Error('Not a valid index.');
|
90
|
+
}
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Removes a range from a selection.
|
94
|
+
*
|
95
|
+
* @param _range Range.
|
96
|
+
*/
|
97
|
+
public removeRange(_range: object): void {
|
98
|
+
// Do nothing.
|
99
|
+
}
|
100
|
+
|
101
|
+
/**
|
102
|
+
* Removes all ranges.
|
103
|
+
*/
|
104
|
+
public removeAllRanges(): void {
|
105
|
+
// Do nothing.
|
106
|
+
}
|
107
|
+
|
108
|
+
/**
|
109
|
+
* Selects all children.
|
110
|
+
*
|
111
|
+
* @param _parentNode Parent node.
|
112
|
+
*/
|
113
|
+
public selectAllChildren(_parentNode: INode): void {
|
114
|
+
// Do nothing.
|
115
|
+
}
|
116
|
+
|
117
|
+
/**
|
118
|
+
* Sets the selection to be a range including all or parts of two specified DOM nodes, and any content located between them.
|
119
|
+
*
|
120
|
+
* @param _anchorNode Anchor node.
|
121
|
+
* @param _anchorOffset Anchor offset.
|
122
|
+
* @param _focusNode Focus node.
|
123
|
+
* @param _focusOffset Focus offset.
|
124
|
+
*/
|
125
|
+
public setBaseAndExtent(
|
126
|
+
_anchorNode: INode,
|
127
|
+
_anchorOffset: number,
|
128
|
+
_focusNode: INode,
|
129
|
+
_focusOffset: number
|
130
|
+
): void {
|
131
|
+
// Do nothing.
|
132
|
+
}
|
133
|
+
|
134
|
+
/**
|
135
|
+
* Returns string currently being represented by the selection object.
|
136
|
+
*/
|
137
|
+
public toString(): string {
|
138
|
+
return '';
|
139
|
+
}
|
140
|
+
}
|