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/src/window/IWindow.ts
CHANGED
@@ -68,11 +68,13 @@ import Window from './Window';
|
|
68
68
|
import URLSearchParams from '../url-search-params/URLSearchParams';
|
69
69
|
import HTMLCollection from '../nodes/element/HTMLCollection';
|
70
70
|
import NodeList from '../nodes/node/NodeList';
|
71
|
+
import Selection from '../selection/Selection';
|
72
|
+
import IEventTarget from '../event/IEventTarget';
|
71
73
|
|
72
74
|
/**
|
73
75
|
* Window.
|
74
76
|
*/
|
75
|
-
export default interface IWindow {
|
77
|
+
export default interface IWindow extends IEventTarget {
|
76
78
|
// Public Properties
|
77
79
|
readonly happyDOM: {
|
78
80
|
whenAsyncComplete: () => Promise<void>;
|
@@ -148,6 +150,7 @@ export default interface IWindow {
|
|
148
150
|
readonly NodeList: typeof NodeList;
|
149
151
|
readonly CSSUnitValue: typeof CSSUnitValue;
|
150
152
|
readonly CSS: CSS;
|
153
|
+
readonly Selection: typeof Selection;
|
151
154
|
|
152
155
|
// Events
|
153
156
|
onload: (event: Event) => void;
|
@@ -164,6 +167,7 @@ export default interface IWindow {
|
|
164
167
|
readonly top: IWindow;
|
165
168
|
readonly parent: IWindow;
|
166
169
|
readonly window: IWindow;
|
170
|
+
readonly globalThis: IWindow;
|
167
171
|
readonly screen: Screen;
|
168
172
|
readonly innerWidth: number;
|
169
173
|
readonly innerHeight: number;
|
package/src/window/Window.ts
CHANGED
@@ -73,6 +73,7 @@ import URLSearchParams from '../url-search-params/URLSearchParams';
|
|
73
73
|
import HTMLCollection from '../nodes/element/HTMLCollection';
|
74
74
|
import NodeList from '../nodes/node/NodeList';
|
75
75
|
import MediaQueryList from '../match-media/MediaQueryList';
|
76
|
+
import Selection from '../selection/Selection';
|
76
77
|
import * as PerfHooks from 'perf_hooks';
|
77
78
|
|
78
79
|
const FETCH_RESPONSE_TYPE_METHODS = ['blob', 'json', 'text'];
|
@@ -160,6 +161,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
160
161
|
public readonly NodeList = NodeList;
|
161
162
|
public readonly MediaQueryList = MediaQueryList;
|
162
163
|
public readonly CSSUnitValue = CSSUnitValue;
|
164
|
+
public readonly Selection = Selection;
|
163
165
|
|
164
166
|
// Events
|
165
167
|
public onload: (event: Event) => void = null;
|
@@ -176,6 +178,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
176
178
|
public readonly top = this;
|
177
179
|
public readonly parent = this;
|
178
180
|
public readonly window = this;
|
181
|
+
public readonly globalThis = this;
|
179
182
|
public readonly screen = new Screen();
|
180
183
|
public readonly innerWidth = 1024;
|
181
184
|
public readonly innerHeight = 768;
|
@@ -1,40 +0,0 @@
|
|
1
|
-
import Element from './Element';
|
2
|
-
/**
|
3
|
-
* Class list.
|
4
|
-
*/
|
5
|
-
export default class ClassList {
|
6
|
-
private _ownerElement;
|
7
|
-
/**
|
8
|
-
* Adds class names.
|
9
|
-
*
|
10
|
-
* @param ownerElement Owner element.
|
11
|
-
*/
|
12
|
-
constructor(ownerElement: Element);
|
13
|
-
/**
|
14
|
-
* Adds class names.
|
15
|
-
*
|
16
|
-
* @param classNames Class names.
|
17
|
-
*/
|
18
|
-
add(...classNames: string[]): void;
|
19
|
-
/**
|
20
|
-
* Adds class names.
|
21
|
-
*
|
22
|
-
* @param classNames Class names.
|
23
|
-
*/
|
24
|
-
remove(...classNames: string[]): void;
|
25
|
-
/**
|
26
|
-
* Check if the list contains a class.
|
27
|
-
*
|
28
|
-
* @param className Class name.
|
29
|
-
* @returns TRUE if it contains.
|
30
|
-
*/
|
31
|
-
contains(className: string): boolean;
|
32
|
-
/**
|
33
|
-
* Toggle a class name.
|
34
|
-
*
|
35
|
-
* @param className A string representing the class name you want to toggle.
|
36
|
-
* @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.
|
37
|
-
* @returns A boolean value, `true` or `false`, indicating whether class name is in the list after the call or not.
|
38
|
-
*/
|
39
|
-
toggle(className: string, force?: boolean): boolean;
|
40
|
-
}
|
@@ -1,99 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
var DOMException_1 = __importDefault(require("../../exception/DOMException"));
|
7
|
-
/**
|
8
|
-
* Class list.
|
9
|
-
*/
|
10
|
-
var ClassList = /** @class */ (function () {
|
11
|
-
/**
|
12
|
-
* Adds class names.
|
13
|
-
*
|
14
|
-
* @param ownerElement Owner element.
|
15
|
-
*/
|
16
|
-
function ClassList(ownerElement) {
|
17
|
-
this._ownerElement = ownerElement;
|
18
|
-
}
|
19
|
-
/**
|
20
|
-
* Adds class names.
|
21
|
-
*
|
22
|
-
* @param classNames Class names.
|
23
|
-
*/
|
24
|
-
ClassList.prototype.add = function () {
|
25
|
-
var classNames = [];
|
26
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
27
|
-
classNames[_i] = arguments[_i];
|
28
|
-
}
|
29
|
-
var attr = this._ownerElement.getAttribute('class');
|
30
|
-
var list = attr ? attr.split(' ') : [];
|
31
|
-
for (var _a = 0, classNames_1 = classNames; _a < classNames_1.length; _a++) {
|
32
|
-
var className = classNames_1[_a];
|
33
|
-
if (!list.includes(className)) {
|
34
|
-
if (className.includes(' ')) {
|
35
|
-
throw new DOMException_1.default("Failed to execute 'add' on 'DOMTokenList': The token provided ('".concat(className, "') contains HTML space characters, which are not valid in tokens."));
|
36
|
-
}
|
37
|
-
list.push(className);
|
38
|
-
}
|
39
|
-
}
|
40
|
-
this._ownerElement.setAttribute('class', list.join(' '));
|
41
|
-
};
|
42
|
-
/**
|
43
|
-
* Adds class names.
|
44
|
-
*
|
45
|
-
* @param classNames Class names.
|
46
|
-
*/
|
47
|
-
ClassList.prototype.remove = function () {
|
48
|
-
var classNames = [];
|
49
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
50
|
-
classNames[_i] = arguments[_i];
|
51
|
-
}
|
52
|
-
var attr = this._ownerElement.getAttribute('class');
|
53
|
-
var list = attr ? attr.split(' ') : [];
|
54
|
-
for (var _a = 0, classNames_2 = classNames; _a < classNames_2.length; _a++) {
|
55
|
-
var className = classNames_2[_a];
|
56
|
-
var index = list.indexOf(className);
|
57
|
-
if (index !== -1) {
|
58
|
-
list.splice(index, 1);
|
59
|
-
}
|
60
|
-
}
|
61
|
-
this._ownerElement.setAttribute('class', list.join(' '));
|
62
|
-
};
|
63
|
-
/**
|
64
|
-
* Check if the list contains a class.
|
65
|
-
*
|
66
|
-
* @param className Class name.
|
67
|
-
* @returns TRUE if it contains.
|
68
|
-
*/
|
69
|
-
ClassList.prototype.contains = function (className) {
|
70
|
-
var attr = this._ownerElement.getAttribute('class');
|
71
|
-
var list = attr ? attr.split(' ') : [];
|
72
|
-
return list.includes(className);
|
73
|
-
};
|
74
|
-
/**
|
75
|
-
* Toggle a class name.
|
76
|
-
*
|
77
|
-
* @param className A string representing the class name you want to toggle.
|
78
|
-
* @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.
|
79
|
-
* @returns A boolean value, `true` or `false`, indicating whether class name is in the list after the call or not.
|
80
|
-
*/
|
81
|
-
ClassList.prototype.toggle = function (className, force) {
|
82
|
-
var shouldAdd;
|
83
|
-
if (force !== undefined) {
|
84
|
-
shouldAdd = force;
|
85
|
-
}
|
86
|
-
else {
|
87
|
-
shouldAdd = !this.contains(className);
|
88
|
-
}
|
89
|
-
if (shouldAdd) {
|
90
|
-
this.add(className);
|
91
|
-
return true;
|
92
|
-
}
|
93
|
-
this.remove(className);
|
94
|
-
return false;
|
95
|
-
};
|
96
|
-
return ClassList;
|
97
|
-
}());
|
98
|
-
exports.default = ClassList;
|
99
|
-
//# sourceMappingURL=ClassList.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"ClassList.js","sourceRoot":"","sources":["../../../src/nodes/element/ClassList.ts"],"names":[],"mappings":";;;;;AAAA,8EAAwD;AAGxD;;GAEG;AACH;IAGC;;;;OAIG;IACH,mBAAY,YAAqB;QAChC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACI,uBAAG,GAAV;QAAW,oBAAuB;aAAvB,UAAuB,EAAvB,qBAAuB,EAAvB,IAAuB;YAAvB,+BAAuB;;QACjC,IAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QACtD,IAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACzC,KAAwB,UAAU,EAAV,yBAAU,EAAV,wBAAU,EAAV,IAAU,EAAE;YAA/B,IAAM,SAAS,mBAAA;YACnB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;gBAC9B,IAAI,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;oBAC5B,MAAM,IAAI,sBAAY,CACrB,0EAAmE,SAAS,sEA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,SAAiB,EAAE,KAAe;QAC/C,IAAI,SAAkB,CAAC;QACvB,IAAI,KAAK,KAAK,SAAS,EAAE;YACxB,SAAS,GAAG,KAAK,CAAC;SAClB;aAAM;YACN,SAAS,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;SACtC;QAED,IAAI,SAAS,EAAE;YACd,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YACpB,OAAO,IAAI,CAAC;SACZ;QAED,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACvB,OAAO,KAAK,CAAC;IACd,CAAC;IACF,gBAAC;AAAD,CAAC,AArFD,IAqFC"}
|
@@ -1,92 +0,0 @@
|
|
1
|
-
import DOMException from '../../exception/DOMException';
|
2
|
-
import Element from './Element';
|
3
|
-
|
4
|
-
/**
|
5
|
-
* Class list.
|
6
|
-
*/
|
7
|
-
export default class ClassList {
|
8
|
-
private _ownerElement: Element;
|
9
|
-
|
10
|
-
/**
|
11
|
-
* Adds class names.
|
12
|
-
*
|
13
|
-
* @param ownerElement Owner element.
|
14
|
-
*/
|
15
|
-
constructor(ownerElement: Element) {
|
16
|
-
this._ownerElement = ownerElement;
|
17
|
-
}
|
18
|
-
|
19
|
-
/**
|
20
|
-
* Adds class names.
|
21
|
-
*
|
22
|
-
* @param classNames Class names.
|
23
|
-
*/
|
24
|
-
public add(...classNames: string[]): void {
|
25
|
-
const attr = this._ownerElement.getAttribute('class');
|
26
|
-
const list = attr ? attr.split(' ') : [];
|
27
|
-
for (const className of classNames) {
|
28
|
-
if (!list.includes(className)) {
|
29
|
-
if (className.includes(' ')) {
|
30
|
-
throw new DOMException(
|
31
|
-
`Failed to execute 'add' on 'DOMTokenList': The token provided ('${className}') contains HTML space characters, which are not valid in tokens.`
|
32
|
-
);
|
33
|
-
}
|
34
|
-
list.push(className);
|
35
|
-
}
|
36
|
-
}
|
37
|
-
this._ownerElement.setAttribute('class', list.join(' '));
|
38
|
-
}
|
39
|
-
|
40
|
-
/**
|
41
|
-
* Adds class names.
|
42
|
-
*
|
43
|
-
* @param classNames Class names.
|
44
|
-
*/
|
45
|
-
public remove(...classNames: string[]): void {
|
46
|
-
const attr = this._ownerElement.getAttribute('class');
|
47
|
-
const list = attr ? attr.split(' ') : [];
|
48
|
-
for (const className of classNames) {
|
49
|
-
const index = list.indexOf(className);
|
50
|
-
if (index !== -1) {
|
51
|
-
list.splice(index, 1);
|
52
|
-
}
|
53
|
-
}
|
54
|
-
this._ownerElement.setAttribute('class', list.join(' '));
|
55
|
-
}
|
56
|
-
|
57
|
-
/**
|
58
|
-
* Check if the list contains a class.
|
59
|
-
*
|
60
|
-
* @param className Class name.
|
61
|
-
* @returns TRUE if it contains.
|
62
|
-
*/
|
63
|
-
public contains(className: string): boolean {
|
64
|
-
const attr = this._ownerElement.getAttribute('class');
|
65
|
-
const list = attr ? attr.split(' ') : [];
|
66
|
-
return list.includes(className);
|
67
|
-
}
|
68
|
-
|
69
|
-
/**
|
70
|
-
* Toggle a class name.
|
71
|
-
*
|
72
|
-
* @param className A string representing the class name you want to toggle.
|
73
|
-
* @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.
|
74
|
-
* @returns A boolean value, `true` or `false`, indicating whether class name is in the list after the call or not.
|
75
|
-
*/
|
76
|
-
public toggle(className: string, force?: boolean): boolean {
|
77
|
-
let shouldAdd: boolean;
|
78
|
-
if (force !== undefined) {
|
79
|
-
shouldAdd = force;
|
80
|
-
} else {
|
81
|
-
shouldAdd = !this.contains(className);
|
82
|
-
}
|
83
|
-
|
84
|
-
if (shouldAdd) {
|
85
|
-
this.add(className);
|
86
|
-
return true;
|
87
|
-
}
|
88
|
-
|
89
|
-
this.remove(className);
|
90
|
-
return false;
|
91
|
-
}
|
92
|
-
}
|