happy-dom 2.31.1 → 2.34.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/README.md +1 -1
- 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/event/EventTarget.js +4 -0
- package/lib/event/EventTarget.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/match-media/MediaQueryList.d.ts +39 -0
- package/lib/match-media/MediaQueryList.js +82 -0
- package/lib/match-media/MediaQueryList.js.map +1 -0
- 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/nodes/node/Node.js +0 -4
- package/lib/nodes/node/Node.js.map +1 -1
- package/lib/window/IWindow.d.ts +8 -2
- package/lib/window/Window.d.ts +18 -2
- package/lib/window/Window.js +23 -2
- package/lib/window/Window.js.map +1 -1
- package/package.json +3 -3
- package/src/config/ElementClass.ts +1 -23
- package/src/config/ElementTag.ts +2 -0
- package/src/event/EventTarget.ts +6 -0
- package/src/index.ts +10 -0
- package/src/match-media/MediaQueryList.ts +52 -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/nodes/node/Node.ts +0 -6
- package/src/window/IWindow.ts +8 -2
- package/src/window/Window.ts +24 -2
@@ -1,27 +1,11 @@
|
|
1
|
-
import HTMLTemplateElement from '../nodes/html-template-element/HTMLTemplateElement';
|
2
|
-
import HTMLFormElement from '../nodes/html-form-element/HTMLFormElement';
|
3
1
|
import HTMLElement from '../nodes/html-element/HTMLElement';
|
4
|
-
import HTMLInputElement from '../nodes/html-input-element/HTMLInputElement';
|
5
|
-
import HTMLTextAreaElement from '../nodes/html-text-area-element/HTMLTextAreaElement';
|
6
|
-
import SVGSVGElement from '../nodes/svg-element/SVGSVGElement';
|
7
|
-
import SVGElement from '../nodes/svg-element/SVGElement';
|
8
|
-
import HTMLScriptElement from '../nodes/html-script-element/HTMLScriptElement';
|
9
|
-
import HTMLImageElement from '../nodes/html-image-element/HTMLImageElement';
|
10
|
-
import HTMLStyleElement from '../nodes/html-style-element/HTMLStyleElement';
|
11
|
-
import HTMLLinkElement from '../nodes/html-link-element/HTMLLinkElement';
|
12
2
|
|
13
3
|
export default {
|
14
|
-
HTMLTemplateElement: HTMLTemplateElement,
|
15
|
-
HTMLFormElement: HTMLFormElement,
|
16
|
-
HTMLInputElement: HTMLInputElement,
|
17
|
-
HTMLTextAreaElement: HTMLTextAreaElement,
|
18
4
|
HTMLElement: HTMLElement,
|
19
5
|
HTMLHeadElement: HTMLElement,
|
20
6
|
HTMLTitleElement: HTMLElement,
|
21
7
|
HTMLBaseElement: HTMLElement,
|
22
|
-
HTMLLinkElement: HTMLLinkElement,
|
23
8
|
HTMLMetaElement: HTMLElement,
|
24
|
-
HTMLStyleElement: HTMLStyleElement,
|
25
9
|
HTMLBodyElement: HTMLElement,
|
26
10
|
HTMLHeadingElement: HTMLElement,
|
27
11
|
HTMLParagraphElement: HTMLElement,
|
@@ -46,8 +30,6 @@ export default {
|
|
46
30
|
HTMLFieldSetElement: HTMLElement,
|
47
31
|
HTMLFontElement: HTMLElement,
|
48
32
|
HTMLHtmlElement: HTMLElement,
|
49
|
-
HTMLImageElement: HTMLImageElement,
|
50
|
-
HTMLLabelElement: HTMLElement,
|
51
33
|
HTMLLegendElement: HTMLElement,
|
52
34
|
HTMLMapElement: HTMLElement,
|
53
35
|
HTMLMarqueeElement: HTMLElement,
|
@@ -60,9 +42,7 @@ export default {
|
|
60
42
|
HTMLPictureElement: HTMLElement,
|
61
43
|
HTMLProgressElement: HTMLElement,
|
62
44
|
HTMLQuoteElement: HTMLElement,
|
63
|
-
HTMLScriptElement: HTMLScriptElement,
|
64
45
|
HTMLSelectElement: HTMLElement,
|
65
|
-
HTMLSlotElement: HTMLElement,
|
66
46
|
HTMLSourceElement: HTMLElement,
|
67
47
|
HTMLSpanElement: HTMLElement,
|
68
48
|
HTMLTableCaptionElement: HTMLElement,
|
@@ -81,7 +61,5 @@ export default {
|
|
81
61
|
HTMLParamElement: HTMLElement,
|
82
62
|
HTMLVideoElement: HTMLElement,
|
83
63
|
HTMLAudioElement: HTMLElement,
|
84
|
-
HTMLTrackElement: HTMLElement
|
85
|
-
SVGSVGElement: SVGSVGElement,
|
86
|
-
SVGElement: SVGElement
|
64
|
+
HTMLTrackElement: HTMLElement
|
87
65
|
};
|
package/src/config/ElementTag.ts
CHANGED
@@ -8,6 +8,7 @@ import HTMLScriptElement from '../nodes/html-script-element/HTMLScriptElement';
|
|
8
8
|
import HTMLImageElement from '../nodes/html-image-element/HTMLImageElement';
|
9
9
|
import HTMLLinkElement from '../nodes/html-link-element/HTMLLinkElement';
|
10
10
|
import HTMLStyleElement from '../nodes/html-style-element/HTMLStyleElement';
|
11
|
+
import HTMLLabelElement from '../nodes/html-label-element/HTMLLabelElement';
|
11
12
|
import HTMLSlotElement from '../nodes/html-slot-element/HTMLSlotElement';
|
12
13
|
|
13
14
|
export default {
|
@@ -19,6 +20,7 @@ export default {
|
|
19
20
|
img: HTMLImageElement,
|
20
21
|
link: HTMLLinkElement,
|
21
22
|
style: HTMLStyleElement,
|
23
|
+
label: HTMLLabelElement,
|
22
24
|
slot: HTMLSlotElement,
|
23
25
|
svg: SVGSVGElement,
|
24
26
|
circle: SVGElement,
|
package/src/event/EventTarget.ts
CHANGED
@@ -52,6 +52,12 @@ export default abstract class EventTarget implements IEventTarget {
|
|
52
52
|
|
53
53
|
event.currentTarget = this;
|
54
54
|
|
55
|
+
const onEventName = 'on' + event.type.toLowerCase();
|
56
|
+
|
57
|
+
if (typeof this[onEventName] === 'function') {
|
58
|
+
this[onEventName].call(this, event);
|
59
|
+
}
|
60
|
+
|
55
61
|
if (this._listeners[event.type]) {
|
56
62
|
for (const listener of this._listeners[event.type]) {
|
57
63
|
if ((<IEventListener>listener).handleEvent) {
|
package/src/index.ts
CHANGED
@@ -64,11 +64,16 @@ import HTMLTextAreaElement from './nodes/html-text-area-element/HTMLTextAreaElem
|
|
64
64
|
import IHTMLTextAreaElement from './nodes/html-text-area-element/IHTMLTextAreaElement';
|
65
65
|
import HTMLImageElement from './nodes/html-image-element/HTMLImageElement';
|
66
66
|
import IHTMLImageElement from './nodes/html-image-element/IHTMLImageElement';
|
67
|
+
import Image from './nodes/html-image-element/Image';
|
67
68
|
import HTMLScriptElement from './nodes/html-script-element/HTMLScriptElement';
|
68
69
|
import HTMLLinkElement from './nodes/html-link-element/HTMLLinkElement';
|
69
70
|
import IHTMLLinkElement from './nodes/html-link-element/IHTMLLinkElement';
|
70
71
|
import HTMLStyleElement from './nodes/html-style-element/HTMLStyleElement';
|
71
72
|
import IHTMLStyleElement from './nodes/html-style-element/IHTMLStyleElement';
|
73
|
+
import HTMLSlotElement from './nodes/html-slot-element/HTMLSlotElement';
|
74
|
+
import IHTMLSlotElement from './nodes/html-slot-element/IHTMLSlotElement';
|
75
|
+
import HTMLLabelElement from './nodes/html-label-element/HTMLLabelElement';
|
76
|
+
import IHTMLLabelElement from './nodes/html-label-element/IHTMLLabelElement';
|
72
77
|
import SVGElement from './nodes/svg-element/SVGElement';
|
73
78
|
import ISVGElement from './nodes/svg-element/ISVGElement';
|
74
79
|
import SVGGraphicsElement from './nodes/svg-element/SVGGraphicsElement';
|
@@ -166,11 +171,16 @@ export {
|
|
166
171
|
IHTMLTextAreaElement,
|
167
172
|
HTMLImageElement,
|
168
173
|
IHTMLImageElement,
|
174
|
+
Image,
|
169
175
|
HTMLScriptElement,
|
170
176
|
HTMLLinkElement,
|
171
177
|
IHTMLLinkElement,
|
172
178
|
HTMLStyleElement,
|
173
179
|
IHTMLStyleElement,
|
180
|
+
HTMLSlotElement,
|
181
|
+
IHTMLSlotElement,
|
182
|
+
HTMLLabelElement,
|
183
|
+
IHTMLLabelElement,
|
174
184
|
SVGElement,
|
175
185
|
ISVGElement,
|
176
186
|
SVGGraphicsElement,
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import EventTarget from '../event/EventTarget';
|
2
|
+
import Event from '../event/Event';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Media Query List.
|
6
|
+
*
|
7
|
+
* Reference:
|
8
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList.
|
9
|
+
*/
|
10
|
+
export default class MediaQueryList extends EventTarget {
|
11
|
+
public _matches = false;
|
12
|
+
public _media = '';
|
13
|
+
public onchange: (event: Event) => void = null;
|
14
|
+
|
15
|
+
/**
|
16
|
+
* Returns "true" if the document matches.
|
17
|
+
*
|
18
|
+
* @returns Matches.
|
19
|
+
*/
|
20
|
+
public get matches(): boolean {
|
21
|
+
return this._matches;
|
22
|
+
}
|
23
|
+
|
24
|
+
/**
|
25
|
+
* Returns the serialized media query.
|
26
|
+
*
|
27
|
+
* @returns Serialized media query.
|
28
|
+
*/
|
29
|
+
public get media(): string {
|
30
|
+
return this._media;
|
31
|
+
}
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Adds a listener.
|
35
|
+
*
|
36
|
+
* @deprecated
|
37
|
+
* @param callback Callback.
|
38
|
+
*/
|
39
|
+
public addListener(callback: (event: Event) => void): void {
|
40
|
+
this.addEventListener('change', callback);
|
41
|
+
}
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Removes listener.
|
45
|
+
*
|
46
|
+
* @deprecated
|
47
|
+
* @param callback Callback.
|
48
|
+
*/
|
49
|
+
public removeListener(callback: (event: Event) => void): void {
|
50
|
+
this.removeEventListener('change', callback);
|
51
|
+
}
|
52
|
+
}
|
@@ -8,6 +8,7 @@ import IHTMLImageElement from './IHTMLImageElement';
|
|
8
8
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement.
|
9
9
|
*/
|
10
10
|
export default class HTMLImageElement extends HTMLElement implements IHTMLImageElement {
|
11
|
+
public readonly tagName: string = 'IMG';
|
11
12
|
public readonly complete = false;
|
12
13
|
public readonly naturalHeight = 0;
|
13
14
|
public readonly naturalWidth = 0;
|
@@ -49,8 +50,9 @@ export default class HTMLImageElement extends HTMLElement implements IHTMLImageE
|
|
49
50
|
*
|
50
51
|
* @returns Height.
|
51
52
|
*/
|
52
|
-
public get height():
|
53
|
-
|
53
|
+
public get height(): number {
|
54
|
+
const height = this.getAttributeNS(null, 'height');
|
55
|
+
return height !== null ? Number(height) : 0;
|
54
56
|
}
|
55
57
|
|
56
58
|
/**
|
@@ -58,8 +60,8 @@ export default class HTMLImageElement extends HTMLElement implements IHTMLImageE
|
|
58
60
|
*
|
59
61
|
* @param height Height.
|
60
62
|
*/
|
61
|
-
public set height(height:
|
62
|
-
this.setAttributeNS(null, 'height', height);
|
63
|
+
public set height(height: number) {
|
64
|
+
this.setAttributeNS(null, 'height', String(height));
|
63
65
|
}
|
64
66
|
|
65
67
|
/**
|
@@ -179,8 +181,9 @@ export default class HTMLImageElement extends HTMLElement implements IHTMLImageE
|
|
179
181
|
*
|
180
182
|
* @returns Width.
|
181
183
|
*/
|
182
|
-
public get width():
|
183
|
-
|
184
|
+
public get width(): number {
|
185
|
+
const width = this.getAttributeNS(null, 'width');
|
186
|
+
return width !== null ? Number(width) : 0;
|
184
187
|
}
|
185
188
|
|
186
189
|
/**
|
@@ -188,8 +191,8 @@ export default class HTMLImageElement extends HTMLElement implements IHTMLImageE
|
|
188
191
|
*
|
189
192
|
* @param width Width.
|
190
193
|
*/
|
191
|
-
public set width(width:
|
192
|
-
this.setAttributeNS(null, 'width', width);
|
194
|
+
public set width(width: number) {
|
195
|
+
this.setAttributeNS(null, 'width', String(width));
|
193
196
|
}
|
194
197
|
|
195
198
|
/**
|
@@ -12,7 +12,7 @@ export default interface IHTMLImageElement extends IHTMLElement {
|
|
12
12
|
crossOrigin: string;
|
13
13
|
readonly currentSrc: string;
|
14
14
|
decoding: string;
|
15
|
-
height:
|
15
|
+
height: number;
|
16
16
|
isMap: boolean;
|
17
17
|
loading: string;
|
18
18
|
readonly naturalHeight: number;
|
@@ -22,7 +22,7 @@ export default interface IHTMLImageElement extends IHTMLElement {
|
|
22
22
|
src: string;
|
23
23
|
srcset: string;
|
24
24
|
useMap: string;
|
25
|
-
width:
|
25
|
+
width: number;
|
26
26
|
readonly x: number;
|
27
27
|
readonly y: number;
|
28
28
|
|
@@ -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/nodes/node/Node.ts
CHANGED
@@ -387,12 +387,6 @@ export default class Node extends EventTarget implements INode {
|
|
387
387
|
* @override
|
388
388
|
*/
|
389
389
|
public dispatchEvent(event: Event): boolean {
|
390
|
-
const onEventName = 'on' + event.type.toLowerCase();
|
391
|
-
|
392
|
-
if (typeof this[onEventName] === 'function') {
|
393
|
-
this[onEventName].call(this, event);
|
394
|
-
}
|
395
|
-
|
396
390
|
const returnValue = super.dispatchEvent(event);
|
397
391
|
|
398
392
|
if (event.bubbles && !event._propagationStopped) {
|
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,13 +64,12 @@ 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';
|
67
70
|
import HTMLCollection from '../nodes/element/HTMLCollection';
|
68
71
|
import NodeList from '../nodes/node/NodeList';
|
72
|
+
import MediaQueryList from '../match-media/MediaQueryList';
|
69
73
|
|
70
74
|
const FETCH_RESPONSE_TYPE_METHODS = ['blob', 'json', 'text'];
|
71
75
|
|
@@ -92,9 +96,12 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
92
96
|
public readonly HTMLInputElement = HTMLInputElement;
|
93
97
|
public readonly HTMLTextAreaElement = HTMLTextAreaElement;
|
94
98
|
public readonly HTMLImageElement = HTMLImageElement;
|
99
|
+
public readonly Image = Image;
|
95
100
|
public readonly HTMLScriptElement = HTMLScriptElement;
|
96
101
|
public readonly HTMLLinkElement = HTMLLinkElement;
|
97
102
|
public readonly HTMLStyleElement = HTMLStyleElement;
|
103
|
+
public readonly HTMLLabelElement = HTMLLabelElement;
|
104
|
+
public readonly HTMLSlotElement = HTMLSlotElement;
|
98
105
|
public readonly SVGSVGElement = SVGSVGElement;
|
99
106
|
public readonly SVGElement = SVGElement;
|
100
107
|
public readonly Text = Text;
|
@@ -146,6 +153,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
146
153
|
public readonly URLSearchParams = URLSearchParams;
|
147
154
|
public readonly HTMLCollection = HTMLCollection;
|
148
155
|
public readonly NodeList = NodeList;
|
156
|
+
public readonly MediaQueryList = MediaQueryList;
|
149
157
|
|
150
158
|
// Events
|
151
159
|
public onload: (event: Event) => void = null;
|
@@ -165,6 +173,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
165
173
|
public readonly screen = new Screen();
|
166
174
|
public readonly innerWidth = 1024;
|
167
175
|
public readonly innerHeight = 768;
|
176
|
+
public readonly devicePixelRatio = 1;
|
168
177
|
public readonly sessionStorage = new Storage();
|
169
178
|
public readonly localStorage = new Storage();
|
170
179
|
|
@@ -245,6 +254,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
245
254
|
|
246
255
|
DOMParser._ownerDocument = DOMParser._ownerDocument || this.document;
|
247
256
|
FileReader._ownerDocument = FileReader._ownerDocument || this.document;
|
257
|
+
Image.ownerDocument = Image.ownerDocument || this.document;
|
248
258
|
|
249
259
|
for (const eventType of NonImplementedEventTypes) {
|
250
260
|
if (!this[eventType]) {
|
@@ -346,6 +356,18 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
346
356
|
this.scroll(x, y);
|
347
357
|
}
|
348
358
|
|
359
|
+
/**
|
360
|
+
* Returns a new MediaQueryList object that can then be used to determine if the document matches the media query string.
|
361
|
+
*
|
362
|
+
* @param mediaQueryString A string specifying the media query to parse into a MediaQueryList.
|
363
|
+
* @returns A new MediaQueryList.
|
364
|
+
*/
|
365
|
+
public matchMedia(mediaQueryString: string): MediaQueryList {
|
366
|
+
const mediaQueryList = new MediaQueryList();
|
367
|
+
mediaQueryList._media = mediaQueryString;
|
368
|
+
return mediaQueryList;
|
369
|
+
}
|
370
|
+
|
349
371
|
/**
|
350
372
|
* Sets a timer which executes a function once the timer expires.
|
351
373
|
*
|