happy-dom 2.32.0 → 2.35.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/config/ElementClass.d.ts +0 -22
- package/lib/config/ElementClass.js +1 -23
- package/lib/config/ElementClass.js.map +1 -1
- package/lib/config/ElementTag.d.ts +2 -0
- package/lib/config/ElementTag.js +2 -0
- package/lib/config/ElementTag.js.map +1 -1
- package/lib/index.d.ts +6 -1
- package/lib/index.js +8 -2
- package/lib/index.js.map +1 -1
- package/lib/nodes/document/Document.d.ts +6 -0
- package/lib/nodes/document/Document.js +12 -0
- package/lib/nodes/document/Document.js.map +1 -1
- package/lib/nodes/html-image-element/HTMLImageElement.d.ts +5 -4
- package/lib/nodes/html-image-element/HTMLImageElement.js +7 -4
- package/lib/nodes/html-image-element/HTMLImageElement.js.map +1 -1
- package/lib/nodes/html-image-element/IHTMLImageElement.d.ts +2 -2
- package/lib/nodes/html-image-element/Image.d.ts +16 -0
- package/lib/nodes/html-image-element/Image.js +51 -0
- package/lib/nodes/html-image-element/Image.js.map +1 -0
- package/lib/nodes/html-input-element/IHTMLInputElement.d.ts +1 -1
- package/lib/nodes/html-label-element/HTMLLabelElement.d.ts +45 -0
- package/lib/nodes/html-label-element/HTMLLabelElement.js +113 -0
- package/lib/nodes/html-label-element/HTMLLabelElement.js.map +1 -0
- package/lib/nodes/html-label-element/IHTMLLabelElement.d.ts +13 -0
- package/lib/nodes/html-label-element/IHTMLLabelElement.js +3 -0
- package/lib/nodes/html-label-element/IHTMLLabelElement.js.map +1 -0
- package/lib/nodes/html-text-area-element/HTMLTextAreaElement.js +1 -1
- package/lib/nodes/html-text-area-element/HTMLTextAreaElement.js.map +1 -1
- package/lib/nodes/html-text-area-element/IHTMLTextAreaElement.d.ts +1 -1
- package/lib/window/IWindow.d.ts +8 -2
- package/lib/window/Window.d.ts +9 -2
- package/lib/window/Window.js +10 -2
- package/lib/window/Window.js.map +1 -1
- package/package.json +2 -2
- package/src/config/ElementClass.ts +1 -23
- package/src/config/ElementTag.ts +2 -0
- package/src/index.ts +10 -0
- package/src/nodes/document/Document.ts +9 -0
- package/src/nodes/html-image-element/HTMLImageElement.ts +11 -8
- package/src/nodes/html-image-element/IHTMLImageElement.ts +2 -2
- package/src/nodes/html-image-element/Image.ts +27 -0
- package/src/nodes/html-input-element/IHTMLInputElement.ts +1 -1
- package/src/nodes/html-label-element/HTMLLabelElement.ts +80 -0
- package/src/nodes/html-label-element/IHTMLLabelElement.ts +14 -0
- package/src/nodes/html-text-area-element/HTMLTextAreaElement.ts +1 -1
- package/src/nodes/html-text-area-element/IHTMLTextAreaElement.ts +1 -1
- package/src/window/IWindow.ts +8 -2
- package/src/window/Window.ts +10 -2
@@ -0,0 +1,27 @@
|
|
1
|
+
import HTMLImageElement from './HTMLImageElement';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Image as constructor.
|
5
|
+
*
|
6
|
+
* Reference:
|
7
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/Image.
|
8
|
+
*/
|
9
|
+
export default class Image extends HTMLImageElement {
|
10
|
+
/**
|
11
|
+
* Constructor.
|
12
|
+
*
|
13
|
+
* @param [width] Width.
|
14
|
+
* @param [height] Height.
|
15
|
+
*/
|
16
|
+
constructor(width: number = null, height: number = null) {
|
17
|
+
super();
|
18
|
+
|
19
|
+
if (width !== null) {
|
20
|
+
this.width = width;
|
21
|
+
}
|
22
|
+
|
23
|
+
if (height !== null) {
|
24
|
+
this.height = height;
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
@@ -11,6 +11,7 @@ import ValidityState from './ValidityState';
|
|
11
11
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement.
|
12
12
|
*/
|
13
13
|
export default interface IHTMLInputElement extends IHTMLElement {
|
14
|
+
readonly form: IHTMLFormElement;
|
14
15
|
formAction: string;
|
15
16
|
formMethod: string;
|
16
17
|
formNoValidate: boolean;
|
@@ -46,7 +47,6 @@ export default interface IHTMLInputElement extends IHTMLElement {
|
|
46
47
|
selectionStart: number;
|
47
48
|
selectionEnd: number;
|
48
49
|
selectionDirection: string;
|
49
|
-
form: IHTMLFormElement;
|
50
50
|
validity: ValidityState;
|
51
51
|
validationMessage: string;
|
52
52
|
willValidate: boolean;
|
@@ -0,0 +1,80 @@
|
|
1
|
+
import HTMLElement from '../html-element/HTMLElement';
|
2
|
+
import IHTMLElement from '../html-element/IHTMLElement';
|
3
|
+
import IHTMLFormElement from '../html-form-element/IHTMLFormElement';
|
4
|
+
import IHTMLLabelElement from './IHTMLLabelElement';
|
5
|
+
|
6
|
+
/**
|
7
|
+
* HTML Label Element.
|
8
|
+
*
|
9
|
+
* Reference:
|
10
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement.
|
11
|
+
*/
|
12
|
+
export default class HTMLLabelElement extends HTMLElement implements IHTMLLabelElement {
|
13
|
+
public _htmlFor: string = null;
|
14
|
+
|
15
|
+
/**
|
16
|
+
* Returns a string containing the ID of the labeled control. This reflects the "for" attribute.
|
17
|
+
*
|
18
|
+
* @returns ID of the labeled control.
|
19
|
+
*/
|
20
|
+
public get htmlFor(): string {
|
21
|
+
const htmlFor = this.getAttributeNS(null, 'for');
|
22
|
+
if (htmlFor !== null) {
|
23
|
+
return htmlFor;
|
24
|
+
}
|
25
|
+
return htmlFor !== null ? htmlFor : '';
|
26
|
+
}
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Sets a string containing the ID of the labeled control. This reflects the "for" attribute.
|
30
|
+
*
|
31
|
+
* @param htmlFor ID of the labeled control.
|
32
|
+
*/
|
33
|
+
public set htmlFor(htmlFor: string) {
|
34
|
+
this.setAttributeNS(null, 'for', htmlFor);
|
35
|
+
}
|
36
|
+
|
37
|
+
/**
|
38
|
+
* Returns an HTML element representing the control with which the label is associated.
|
39
|
+
*
|
40
|
+
* @returns Control element.
|
41
|
+
*/
|
42
|
+
public get control(): IHTMLElement {
|
43
|
+
const htmlFor = this.htmlFor;
|
44
|
+
if (htmlFor) {
|
45
|
+
return <IHTMLElement>this.ownerDocument.getElementById(htmlFor);
|
46
|
+
}
|
47
|
+
for (const child of this.children) {
|
48
|
+
if (child.tagName === 'INPUT') {
|
49
|
+
return <IHTMLElement>child;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
return null;
|
53
|
+
}
|
54
|
+
|
55
|
+
/**
|
56
|
+
* Returns the parent form element.
|
57
|
+
*
|
58
|
+
* @returns Form.
|
59
|
+
*/
|
60
|
+
public get form(): IHTMLFormElement {
|
61
|
+
let parent = <IHTMLElement>this.parentNode;
|
62
|
+
while (parent && parent.tagName !== 'FORM') {
|
63
|
+
parent = <IHTMLElement>parent.parentNode;
|
64
|
+
}
|
65
|
+
return <IHTMLFormElement>parent;
|
66
|
+
}
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Clones a node.
|
70
|
+
*
|
71
|
+
* @override
|
72
|
+
* @param [deep=false] "true" to clone deep.
|
73
|
+
* @returns Cloned node.
|
74
|
+
*/
|
75
|
+
public cloneNode(deep = false): IHTMLLabelElement {
|
76
|
+
const clone = <HTMLLabelElement>super.cloneNode(deep);
|
77
|
+
clone._htmlFor = this._htmlFor;
|
78
|
+
return clone;
|
79
|
+
}
|
80
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import IHTMLElement from '../html-element/IHTMLElement';
|
2
|
+
import IHTMLFormElement from '../html-form-element/IHTMLFormElement';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* HTML Label Element.
|
6
|
+
*
|
7
|
+
* Reference:
|
8
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement.
|
9
|
+
*/
|
10
|
+
export default interface IHTMLLabelElement extends IHTMLElement {
|
11
|
+
readonly control: IHTMLElement;
|
12
|
+
readonly form: IHTMLFormElement;
|
13
|
+
htmlFor: string;
|
14
|
+
}
|
@@ -361,7 +361,7 @@ export default class HTMLTextAreaElement extends HTMLElement implements IHTMLTex
|
|
361
361
|
public get form(): IHTMLFormElement {
|
362
362
|
let parent = <IHTMLElement>this.parentNode;
|
363
363
|
while (parent && parent.tagName !== 'FORM') {
|
364
|
-
parent = <IHTMLElement>
|
364
|
+
parent = <IHTMLElement>parent.parentNode;
|
365
365
|
}
|
366
366
|
return <IHTMLFormElement>parent;
|
367
367
|
}
|
@@ -10,6 +10,7 @@ import HTMLInputElementSelectionModeEnum from '../html-input-element/HTMLInputEl
|
|
10
10
|
*/
|
11
11
|
export default interface IHTMLTextAreaElement extends IHTMLElement {
|
12
12
|
readonly type: string;
|
13
|
+
readonly form: IHTMLFormElement;
|
13
14
|
defaultValue: string;
|
14
15
|
minLength: number;
|
15
16
|
maxLength: number;
|
@@ -27,7 +28,6 @@ export default interface IHTMLTextAreaElement extends IHTMLElement {
|
|
27
28
|
selectionStart: number;
|
28
29
|
selectionEnd: number;
|
29
30
|
selectionDirection: string;
|
30
|
-
form: IHTMLFormElement;
|
31
31
|
textLength: number;
|
32
32
|
|
33
33
|
/**
|
package/src/window/IWindow.ts
CHANGED
@@ -13,10 +13,15 @@ import HTMLFormElement from '../nodes/html-form-element/HTMLFormElement';
|
|
13
13
|
import HTMLElement from '../nodes/html-element/HTMLElement';
|
14
14
|
import HTMLInputElement from '../nodes/html-input-element/HTMLInputElement';
|
15
15
|
import HTMLTextAreaElement from '../nodes/html-text-area-element/HTMLTextAreaElement';
|
16
|
+
import HTMLLinkElement from '../nodes/html-link-element/HTMLLinkElement';
|
17
|
+
import HTMLStyleElement from '../nodes/html-style-element/HTMLStyleElement';
|
18
|
+
import HTMLSlotElement from '../nodes/html-slot-element/HTMLSlotElement';
|
19
|
+
import HTMLLabelElement from '../nodes/html-label-element/HTMLLabelElement';
|
16
20
|
import SVGSVGElement from '../nodes/svg-element/SVGSVGElement';
|
17
21
|
import SVGElement from '../nodes/svg-element/SVGElement';
|
18
22
|
import HTMLScriptElement from '../nodes/html-script-element/HTMLScriptElement';
|
19
23
|
import HTMLImageElement from '../nodes/html-image-element/HTMLImageElement';
|
24
|
+
import Image from '../nodes/html-image-element/Image';
|
20
25
|
import DocumentFragment from '../nodes/document-fragment/DocumentFragment';
|
21
26
|
import CharacterData from '../nodes/character-data/CharacterData';
|
22
27
|
import TreeWalker from '../tree-walker/TreeWalker';
|
@@ -54,8 +59,6 @@ import Screen from '../screen/Screen';
|
|
54
59
|
import AsyncTaskManager from './AsyncTaskManager';
|
55
60
|
import IResponse from './IResponse';
|
56
61
|
import Storage from '../storage/Storage';
|
57
|
-
import HTMLLinkElement from '../nodes/html-link-element/HTMLLinkElement';
|
58
|
-
import HTMLStyleElement from '../nodes/html-style-element/HTMLStyleElement';
|
59
62
|
import IFetchOptions from './IFetchOptions';
|
60
63
|
import NodeFilter from '../tree-walker/NodeFilter';
|
61
64
|
import Window from './Window';
|
@@ -85,8 +88,11 @@ export default interface IWindow {
|
|
85
88
|
readonly HTMLScriptElement: typeof HTMLScriptElement;
|
86
89
|
readonly HTMLLinkElement: typeof HTMLLinkElement;
|
87
90
|
readonly HTMLStyleElement: typeof HTMLStyleElement;
|
91
|
+
readonly HTMLSlotElement: typeof HTMLSlotElement;
|
92
|
+
readonly HTMLLabelElement: typeof HTMLLabelElement;
|
88
93
|
readonly SVGSVGElement: typeof SVGSVGElement;
|
89
94
|
readonly SVGElement: typeof SVGElement;
|
95
|
+
readonly Image: typeof Image;
|
90
96
|
readonly Text: typeof Text;
|
91
97
|
readonly Comment: typeof Comment;
|
92
98
|
readonly ShadowRoot: typeof ShadowRoot;
|
package/src/window/Window.ts
CHANGED
@@ -14,10 +14,15 @@ import HTMLFormElement from '../nodes/html-form-element/HTMLFormElement';
|
|
14
14
|
import HTMLElement from '../nodes/html-element/HTMLElement';
|
15
15
|
import HTMLInputElement from '../nodes/html-input-element/HTMLInputElement';
|
16
16
|
import HTMLTextAreaElement from '../nodes/html-text-area-element/HTMLTextAreaElement';
|
17
|
+
import HTMLLinkElement from '../nodes/html-link-element/HTMLLinkElement';
|
18
|
+
import HTMLStyleElement from '../nodes/html-style-element/HTMLStyleElement';
|
19
|
+
import HTMLSlotElement from '../nodes/html-slot-element/HTMLSlotElement';
|
20
|
+
import HTMLLabelElement from '../nodes/html-label-element/HTMLLabelElement';
|
17
21
|
import SVGSVGElement from '../nodes/svg-element/SVGSVGElement';
|
18
22
|
import SVGElement from '../nodes/svg-element/SVGElement';
|
19
23
|
import HTMLScriptElement from '../nodes/html-script-element/HTMLScriptElement';
|
20
24
|
import HTMLImageElement from '../nodes/html-image-element/HTMLImageElement';
|
25
|
+
import Image from '../nodes/html-image-element/Image';
|
21
26
|
import DocumentFragment from '../nodes/document-fragment/DocumentFragment';
|
22
27
|
import CharacterData from '../nodes/character-data/CharacterData';
|
23
28
|
import TreeWalker from '../tree-walker/TreeWalker';
|
@@ -59,8 +64,6 @@ import IResponse from './IResponse';
|
|
59
64
|
import AsyncTaskTypeEnum from './AsyncTaskTypeEnum';
|
60
65
|
import RelativeURL from '../location/RelativeURL';
|
61
66
|
import Storage from '../storage/Storage';
|
62
|
-
import HTMLLinkElement from '../nodes/html-link-element/HTMLLinkElement';
|
63
|
-
import HTMLStyleElement from '../nodes/html-style-element/HTMLStyleElement';
|
64
67
|
import IFetchOptions from './IFetchOptions';
|
65
68
|
import IWindow from './IWindow';
|
66
69
|
import URLSearchParams from '../url-search-params/URLSearchParams';
|
@@ -93,9 +96,12 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
93
96
|
public readonly HTMLInputElement = HTMLInputElement;
|
94
97
|
public readonly HTMLTextAreaElement = HTMLTextAreaElement;
|
95
98
|
public readonly HTMLImageElement = HTMLImageElement;
|
99
|
+
public readonly Image = Image;
|
96
100
|
public readonly HTMLScriptElement = HTMLScriptElement;
|
97
101
|
public readonly HTMLLinkElement = HTMLLinkElement;
|
98
102
|
public readonly HTMLStyleElement = HTMLStyleElement;
|
103
|
+
public readonly HTMLLabelElement = HTMLLabelElement;
|
104
|
+
public readonly HTMLSlotElement = HTMLSlotElement;
|
99
105
|
public readonly SVGSVGElement = SVGSVGElement;
|
100
106
|
public readonly SVGElement = SVGElement;
|
101
107
|
public readonly Text = Text;
|
@@ -147,6 +153,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
147
153
|
public readonly URLSearchParams = URLSearchParams;
|
148
154
|
public readonly HTMLCollection = HTMLCollection;
|
149
155
|
public readonly NodeList = NodeList;
|
156
|
+
public readonly MediaQueryList = MediaQueryList;
|
150
157
|
|
151
158
|
// Events
|
152
159
|
public onload: (event: Event) => void = null;
|
@@ -247,6 +254,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
247
254
|
|
248
255
|
DOMParser._ownerDocument = DOMParser._ownerDocument || this.document;
|
249
256
|
FileReader._ownerDocument = FileReader._ownerDocument || this.document;
|
257
|
+
Image.ownerDocument = Image.ownerDocument || this.document;
|
250
258
|
|
251
259
|
for (const eventType of NonImplementedEventTypes) {
|
252
260
|
if (!this[eventType]) {
|