happy-dom 2.42.0 → 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/{nodes/element → dom-token-list}/DOMTokenList.d.ts +32 -29
- package/lib/dom-token-list/DOMTokenList.js +209 -0
- package/lib/dom-token-list/DOMTokenList.js.map +1 -0
- package/lib/{nodes/element → dom-token-list}/IDOMTokenList.d.ts +6 -4
- package/lib/{nodes/element → dom-token-list}/IDOMTokenList.js +0 -0
- package/lib/dom-token-list/IDOMTokenList.js.map +1 -0
- package/lib/nodes/document/Document.d.ts +2 -1
- package/lib/nodes/document/Document.js.map +1 -1
- package/lib/nodes/document/IDocument.d.ts +13 -2
- package/lib/nodes/element/Element.d.ts +12 -2
- package/lib/nodes/element/Element.js +27 -2
- 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/window/IWindow.d.ts +2 -1
- package/package.json +2 -2
- package/src/css/CSSStyleDeclaration.ts +1 -1
- package/src/dom-token-list/DOMTokenList.ts +219 -0
- package/src/{nodes/element → dom-token-list}/IDOMTokenList.ts +6 -4
- package/src/nodes/document/Document.ts +3 -2
- package/src/nodes/document/IDocument.ts +13 -2
- package/src/nodes/element/Element.ts +29 -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/window/IWindow.ts +2 -1
- package/lib/nodes/element/DOMTokenList.js +0 -205
- package/lib/nodes/element/DOMTokenList.js.map +0 -1
- package/lib/nodes/element/IDOMTokenList.js.map +0 -1
- package/src/nodes/element/DOMTokenList.ts +0 -201
@@ -5,6 +5,7 @@ import IHTMLLinkElement from './IHTMLLinkElement';
|
|
5
5
|
import Event from '../../event/Event';
|
6
6
|
import ErrorEvent from '../../event/events/ErrorEvent';
|
7
7
|
import INode from '../../nodes/node/INode';
|
8
|
+
import IDOMTokenList from '../../dom-token-list/IDOMTokenList';
|
8
9
|
/**
|
9
10
|
* HTML Link Element.
|
10
11
|
*
|
@@ -16,6 +17,13 @@ export default class HTMLLinkElement extends HTMLElement implements IHTMLLinkEle
|
|
16
17
|
onload: (event: Event) => void;
|
17
18
|
readonly sheet: CSSStyleSheet;
|
18
19
|
_evaluateCSS: boolean;
|
20
|
+
private _relList;
|
21
|
+
/**
|
22
|
+
* Returns rel list.
|
23
|
+
*
|
24
|
+
* @returns Rel list.
|
25
|
+
*/
|
26
|
+
get relList(): IDOMTokenList;
|
19
27
|
/**
|
20
28
|
* Returns as.
|
21
29
|
*
|
@@ -124,4 +132,8 @@ export default class HTMLLinkElement extends HTMLElement implements IHTMLLinkEle
|
|
124
132
|
* @override
|
125
133
|
*/
|
126
134
|
_connectToNode(parentNode?: INode): void;
|
135
|
+
/**
|
136
|
+
* Updates DOM list indices.
|
137
|
+
*/
|
138
|
+
protected _updateDomListIndices(): void;
|
127
139
|
}
|
@@ -23,6 +23,7 @@ var ResourceFetcher_1 = __importDefault(require("../../fetch/ResourceFetcher"));
|
|
23
23
|
var HTMLElement_1 = __importDefault(require("../html-element/HTMLElement"));
|
24
24
|
var Event_1 = __importDefault(require("../../event/Event"));
|
25
25
|
var ErrorEvent_1 = __importDefault(require("../../event/events/ErrorEvent"));
|
26
|
+
var DOMTokenList_1 = __importDefault(require("../../dom-token-list/DOMTokenList"));
|
26
27
|
/**
|
27
28
|
* HTML Link Element.
|
28
29
|
*
|
@@ -37,8 +38,24 @@ var HTMLLinkElement = /** @class */ (function (_super) {
|
|
37
38
|
_this.onload = null;
|
38
39
|
_this.sheet = null;
|
39
40
|
_this._evaluateCSS = true;
|
41
|
+
_this._relList = null;
|
40
42
|
return _this;
|
41
43
|
}
|
44
|
+
Object.defineProperty(HTMLLinkElement.prototype, "relList", {
|
45
|
+
/**
|
46
|
+
* Returns rel list.
|
47
|
+
*
|
48
|
+
* @returns Rel list.
|
49
|
+
*/
|
50
|
+
get: function () {
|
51
|
+
if (!this._relList) {
|
52
|
+
this._relList = new DOMTokenList_1.default(this, 'rel');
|
53
|
+
}
|
54
|
+
return this._relList;
|
55
|
+
},
|
56
|
+
enumerable: false,
|
57
|
+
configurable: true
|
58
|
+
});
|
42
59
|
Object.defineProperty(HTMLLinkElement.prototype, "as", {
|
43
60
|
/**
|
44
61
|
* Returns as.
|
@@ -281,6 +298,15 @@ var HTMLLinkElement = /** @class */ (function (_super) {
|
|
281
298
|
}
|
282
299
|
}
|
283
300
|
};
|
301
|
+
/**
|
302
|
+
* Updates DOM list indices.
|
303
|
+
*/
|
304
|
+
HTMLLinkElement.prototype._updateDomListIndices = function () {
|
305
|
+
_super.prototype._updateDomListIndices.call(this);
|
306
|
+
if (this._relList) {
|
307
|
+
this._relList._updateIndices();
|
308
|
+
}
|
309
|
+
};
|
284
310
|
return HTMLLinkElement;
|
285
311
|
}(HTMLElement_1.default));
|
286
312
|
exports.default = HTMLLinkElement;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"HTMLLinkElement.js","sourceRoot":"","sources":["../../../src/nodes/html-link-element/HTMLLinkElement.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AACA,0EAAoD;AACpD,gFAA0D;AAC1D,4EAAsD;AAGtD,4DAAsC;AACtC,6EAAuD;
|
1
|
+
{"version":3,"file":"HTMLLinkElement.js","sourceRoot":"","sources":["../../../src/nodes/html-link-element/HTMLLinkElement.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AACA,0EAAoD;AACpD,gFAA0D;AAC1D,4EAAsD;AAGtD,4DAAsC;AACtC,6EAAuD;AAEvD,mFAA6D;AAG7D;;;;;GAKG;AACH;IAA6C,mCAAW;IAAxD;QAAA,qEA6QC;QA5QO,aAAO,GAAgC,IAAI,CAAC;QAC5C,YAAM,GAA2B,IAAI,CAAC;QAC7B,WAAK,GAAkB,IAAI,CAAC;QACrC,kBAAY,GAAG,IAAI,CAAC;QACnB,cAAQ,GAAiB,IAAI,CAAC;;IAwQvC,CAAC;IAjQA,sBAAW,oCAAO;QALlB;;;;WAIG;aACH;YACC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;gBACnB,IAAI,CAAC,QAAQ,GAAG,IAAI,sBAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;aAC9C;YACD,OAAsB,IAAI,CAAC,QAAQ,CAAC;QACrC,CAAC;;;OAAA;IAOD,sBAAW,+BAAE;QALb;;;;WAIG;aACH;YACC,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;QAC9C,CAAC;QAED;;;;WAIG;aACH,UAAc,EAAU;YACvB,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QACrC,CAAC;;;OATA;IAgBD,sBAAW,wCAAW;QALtB;;;;WAIG;aACH;YACC,OAAO,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;QAC/C,CAAC;QAED;;;;WAIG;aACH,UAAuB,WAAmB;YACzC,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC;QACvD,CAAC;;;OATA;IAgBD,sBAAW,iCAAI;QALf;;;;WAIG;aACH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AAC,CAAC,CAAC;aACJ;SACD;IACF,CAAC;IAED;;OAEG;IACO,+CAAqB,GAA/B;QACC,iBAAM,qBAAqB,WAAE,CAAC;QAE9B,IAAI,IAAI,CAAC,QAAQ,EAAE;YAClB,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC;SAC/B;IACF,CAAC;IACF,sBAAC;AAAD,CAAC,AA7QD,CAA6C,qBAAW,GA6QvD"}
|
@@ -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
|
* HTML Link Element.
|
@@ -8,6 +9,7 @@ import IHTMLElement from '../html-element/IHTMLElement';
|
|
8
9
|
*/
|
9
10
|
export default interface IHTMLLinkElement extends IHTMLElement {
|
10
11
|
readonly sheet: CSSStyleSheet;
|
12
|
+
readonly relList: IDOMTokenList;
|
11
13
|
as: string;
|
12
14
|
crossOrigin: string;
|
13
15
|
href: string;
|
package/lib/window/IWindow.d.ts
CHANGED
@@ -70,10 +70,11 @@ import URLSearchParams from '../url-search-params/URLSearchParams';
|
|
70
70
|
import HTMLCollection from '../nodes/element/HTMLCollection';
|
71
71
|
import NodeList from '../nodes/node/NodeList';
|
72
72
|
import Selection from '../selection/Selection';
|
73
|
+
import IEventTarget from '../event/IEventTarget';
|
73
74
|
/**
|
74
75
|
* Window.
|
75
76
|
*/
|
76
|
-
export default interface IWindow {
|
77
|
+
export default interface IWindow extends IEventTarget {
|
77
78
|
readonly happyDOM: {
|
78
79
|
whenAsyncComplete: () => Promise<void>;
|
79
80
|
cancelAsync: () => void;
|
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
|
+
}
|
@@ -1,8 +1,10 @@
|
|
1
1
|
/**
|
2
2
|
* IDOMTokenList.
|
3
3
|
*/
|
4
|
-
export default interface IDOMTokenList
|
5
|
-
|
4
|
+
export default interface IDOMTokenList {
|
5
|
+
value: string;
|
6
|
+
readonly length: number;
|
7
|
+
item(index: number | string): string;
|
6
8
|
contains(token: string): boolean;
|
7
9
|
add(...tokens: string[]): void;
|
8
10
|
remove(...tokens: string[]): void;
|
@@ -10,8 +12,8 @@ export default interface IDOMTokenList<T> {
|
|
10
12
|
replace(token: string, newToken: string): boolean;
|
11
13
|
supports(token: string): boolean;
|
12
14
|
|
13
|
-
values(): IterableIterator<
|
14
|
-
entries(): IterableIterator<[number,
|
15
|
+
values(): IterableIterator<string>;
|
16
|
+
entries(): IterableIterator<[number, string]>;
|
15
17
|
forEach(callback: (currentValue, currentIndex, listObj) => void, thisArg?: this): void;
|
16
18
|
keys(): IterableIterator<number>;
|
17
19
|
}
|
@@ -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';
|
@@ -245,8 +246,8 @@ export default class Document extends Node implements IDocument {
|
|
245
246
|
*
|
246
247
|
* @returns Scripts.
|
247
248
|
*/
|
248
|
-
public get scripts(): IHTMLCollection<
|
249
|
-
return this.getElementsByTagName('script');
|
249
|
+
public get scripts(): IHTMLCollection<IHTMLScriptElement> {
|
250
|
+
return <IHTMLCollection<IHTMLScriptElement>>this.getElementsByTagName('script');
|
250
251
|
}
|
251
252
|
|
252
253
|
/**
|
@@ -12,6 +12,11 @@ import INode from '../node/INode';
|
|
12
12
|
import ICharacterData from '../character-data/ICharacterData';
|
13
13
|
import IDocumentFragment from '../document-fragment/IDocumentFragment';
|
14
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';
|
15
20
|
|
16
21
|
/**
|
17
22
|
* Document.
|
@@ -24,7 +29,13 @@ export default interface IDocument extends IParentNode {
|
|
24
29
|
readonly doctype: IDocumentType;
|
25
30
|
readonly body: IHTMLElement;
|
26
31
|
readonly head: IHTMLElement;
|
32
|
+
readonly scripts: IHTMLCollection<IHTMLScriptElement>;
|
27
33
|
readonly activeElement: IHTMLElement;
|
34
|
+
readonly styleSheets: CSSStyleSheet[];
|
35
|
+
readonly scrollingElement: IHTMLElement;
|
36
|
+
readonly location: Location;
|
37
|
+
readonly readyState: DocumentReadyStateEnum;
|
38
|
+
cookie: string;
|
28
39
|
|
29
40
|
/**
|
30
41
|
* Replaces the document HTML with new HTML.
|
@@ -69,7 +80,7 @@ export default interface IDocument extends IParentNode {
|
|
69
80
|
* @param data Text data.
|
70
81
|
* @returns Text node.
|
71
82
|
*/
|
72
|
-
createTextNode(data
|
83
|
+
createTextNode(data?: string): ICharacterData;
|
73
84
|
|
74
85
|
/**
|
75
86
|
* Creates a comment node.
|
@@ -77,7 +88,7 @@ export default interface IDocument extends IParentNode {
|
|
77
88
|
* @param data Text data.
|
78
89
|
* @returns Text node.
|
79
90
|
*/
|
80
|
-
createComment(data
|
91
|
+
createComment(data?: string): ICharacterData;
|
81
92
|
|
82
93
|
/**
|
83
94
|
* Creates a document fragment.
|
@@ -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 DOMTokenList from '
|
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';
|
@@ -37,13 +38,25 @@ export default class Element extends Node implements IElement {
|
|
37
38
|
public nodeType = Node.ELEMENT_NODE;
|
38
39
|
public shadowRoot: IShadowRoot = null;
|
39
40
|
public _attributes: { [k: string]: Attr } = {};
|
40
|
-
public readonly classList = new DOMTokenList(this);
|
41
41
|
public scrollTop = 0;
|
42
42
|
public scrollLeft = 0;
|
43
43
|
public children: IHTMLCollection<IElement> = HTMLCollectionFactory.create();
|
44
|
-
|
45
44
|
public readonly namespaceURI: string = null;
|
46
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
|
+
|
47
60
|
/**
|
48
61
|
* Returns ID.
|
49
62
|
*
|
@@ -770,6 +783,8 @@ export default class Element extends Node implements IElement {
|
|
770
783
|
|
771
784
|
this._attributes[name] = attribute;
|
772
785
|
|
786
|
+
this._updateDomListIndices();
|
787
|
+
|
773
788
|
if (
|
774
789
|
this.attributeChangedCallback &&
|
775
790
|
(<typeof Element>this.constructor)._observedAttributes &&
|
@@ -843,6 +858,8 @@ export default class Element extends Node implements IElement {
|
|
843
858
|
public removeAttributeNode(attribute: Attr): void {
|
844
859
|
delete this._attributes[attribute.name];
|
845
860
|
|
861
|
+
this._updateDomListIndices();
|
862
|
+
|
846
863
|
if (
|
847
864
|
this.attributeChangedCallback &&
|
848
865
|
(<typeof Element>this.constructor)._observedAttributes &&
|
@@ -934,4 +951,13 @@ export default class Element extends Node implements IElement {
|
|
934
951
|
}
|
935
952
|
return name.toLowerCase();
|
936
953
|
}
|
954
|
+
|
955
|
+
/**
|
956
|
+
* Updates DOM list indices.
|
957
|
+
*/
|
958
|
+
protected _updateDomListIndices(): void {
|
959
|
+
if (this._classList) {
|
960
|
+
this._classList._updateIndices();
|
961
|
+
}
|
962
|
+
}
|
937
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;
|
package/src/window/IWindow.ts
CHANGED
@@ -69,11 +69,12 @@ import URLSearchParams from '../url-search-params/URLSearchParams';
|
|
69
69
|
import HTMLCollection from '../nodes/element/HTMLCollection';
|
70
70
|
import NodeList from '../nodes/node/NodeList';
|
71
71
|
import Selection from '../selection/Selection';
|
72
|
+
import IEventTarget from '../event/IEventTarget';
|
72
73
|
|
73
74
|
/**
|
74
75
|
* Window.
|
75
76
|
*/
|
76
|
-
export default interface IWindow {
|
77
|
+
export default interface IWindow extends IEventTarget {
|
77
78
|
// Public Properties
|
78
79
|
readonly happyDOM: {
|
79
80
|
whenAsyncComplete: () => Promise<void>;
|