forked from capricorn86/happy-dom
/
IWindow.ts
375 lines (356 loc) · 15 KB
/
IWindow.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
import CustomElementRegistry from '../custom-element/CustomElementRegistry';
import Document from '../nodes/document/Document';
import HTMLDocument from '../nodes/html-document/HTMLDocument';
import XMLDocument from '../nodes/xml-document/XMLDocument';
import SVGDocument from '../nodes/svg-document/SVGDocument';
import Node from '../nodes/node/Node';
import Text from '../nodes/text/Text';
import Comment from '../nodes/comment/Comment';
import ShadowRoot from '../nodes/shadow-root/ShadowRoot';
import Element from '../nodes/element/Element';
import HTMLTemplateElement from '../nodes/html-template-element/HTMLTemplateElement';
import HTMLFormElement from '../nodes/html-form-element/HTMLFormElement';
import HTMLElement from '../nodes/html-element/HTMLElement';
import HTMLUnknownElement from '../nodes/html-unknown-element/HTMLUnknownElement';
import HTMLInputElement from '../nodes/html-input-element/HTMLInputElement';
import HTMLSelectElement from '../nodes/html-input-element/HTMLSelectElement';
import HTMLTextAreaElement from '../nodes/html-text-area-element/HTMLTextAreaElement';
import HTMLLinkElement from '../nodes/html-link-element/HTMLLinkElement';
import HTMLStyleElement from '../nodes/html-style-element/HTMLStyleElement';
import HTMLSlotElement from '../nodes/html-slot-element/HTMLSlotElement';
import HTMLLabelElement from '../nodes/html-label-element/HTMLLabelElement';
import HTMLMetaElement from '../nodes/html-meta-element/HTMLMetaElement';
import HTMLMediaElement from '../nodes/html-media-element/HTMLMediaElement';
import HTMLAudioElement from '../nodes/html-audio-element/HTMLAudioElement';
import HTMLVideoElement from '../nodes/html-video-element/HTMLVideoElement';
import HTMLBaseElement from '../nodes/html-base-element/HTMLBaseElement';
import SVGSVGElement from '../nodes/svg-element/SVGSVGElement';
import SVGElement from '../nodes/svg-element/SVGElement';
import HTMLScriptElement from '../nodes/html-script-element/HTMLScriptElement';
import HTMLDialogElement from '../nodes/html-dialog-element/HTMLDialogElement';
import HTMLImageElement from '../nodes/html-image-element/HTMLImageElement';
import Image from '../nodes/html-image-element/Image';
import DocumentFragment from '../nodes/document-fragment/DocumentFragment';
import CharacterData from '../nodes/character-data/CharacterData';
import TreeWalker from '../tree-walker/TreeWalker';
import Event from '../event/Event';
import CustomEvent from '../event/events/CustomEvent';
import AnimationEvent from '../event/events/AnimationEvent';
import KeyboardEvent from '../event/events/KeyboardEvent';
import ProgressEvent from '../event/events/ProgressEvent';
import MediaQueryListEvent from '../event/events/MediaQueryListEvent';
import EventTarget from '../event/EventTarget';
import { URL, URLSearchParams } from 'url';
import Location from '../location/Location';
import MutationObserver from '../mutation-observer/MutationObserver';
import DOMParser from '../dom-parser/DOMParser';
import XMLSerializer from '../xml-serializer/XMLSerializer';
import ResizeObserver from '../resize-observer/ResizeObserver';
import Blob from '../file/Blob';
import File from '../file/File';
import DOMException from '../exception/DOMException';
import FileReader from '../file/FileReader';
import History from '../history/History';
import CSSStyleSheet from '../css/CSSStyleSheet';
import CSSStyleDeclaration from '../css/declaration/CSSStyleDeclaration';
import CSS from '../css/CSS';
import CSSUnitValue from '../css/CSSUnitValue';
import CSSRule from '../css/CSSRule';
import CSSContainerRule from '../css/rules/CSSContainerRule';
import CSSFontFaceRule from '../css/rules/CSSFontFaceRule';
import CSSKeyframeRule from '../css/rules/CSSKeyframeRule';
import CSSKeyframesRule from '../css/rules/CSSKeyframesRule';
import CSSMediaRule from '../css/rules/CSSMediaRule';
import CSSStyleRule from '../css/rules/CSSStyleRule';
import PointerEvent from '../event/events/PointerEvent';
import MouseEvent from '../event/events/MouseEvent';
import FocusEvent from '../event/events/FocusEvent';
import WheelEvent from '../event/events/WheelEvent';
import DataTransfer from '../event/DataTransfer';
import DataTransferItem from '../event/DataTransferItem';
import DataTransferItemList from '../event/DataTransferItemList';
import InputEvent from '../event/events/InputEvent';
import UIEvent from '../event/UIEvent';
import ErrorEvent from '../event/events/ErrorEvent';
import StorageEvent from '../event/events/StorageEvent';
import Screen from '../screen/Screen';
import AsyncTaskManager from '../async-task-manager/AsyncTaskManager';
import Storage from '../storage/Storage';
import NodeFilter from '../tree-walker/NodeFilter';
import HTMLCollection from '../nodes/element/HTMLCollection';
import NodeList from '../nodes/node/NodeList';
import Selection from '../selection/Selection';
import IEventTarget from '../event/IEventTarget';
import Navigator from '../navigator/Navigator';
import MimeType from '../navigator/MimeType';
import MimeTypeArray from '../navigator/MimeTypeArray';
import Plugin from '../navigator/Plugin';
import PluginArray from '../navigator/PluginArray';
import IResponseInit from '../fetch/IResponseInit';
import IRequest from '../fetch/IRequest';
import IHeaders from '../fetch/IHeaders';
import IRequestInit from '../fetch/IRequestInit';
import IResponse from '../fetch/IResponse';
import Range from '../range/Range';
import MediaQueryList from '../match-media/MediaQueryList';
import XMLHttpRequest from '../xml-http-request/XMLHttpRequest';
import XMLHttpRequestUpload from '../xml-http-request/XMLHttpRequestUpload';
import XMLHttpRequestEventTarget from '../xml-http-request/XMLHttpRequestEventTarget';
import DOMRect from '../nodes/element/DOMRect';
import Window from './Window';
import Attr from '../nodes/attr/Attr';
import NamedNodeMap from '../named-node-map/NamedNodeMap';
import { Performance } from 'perf_hooks';
import IElement from '../nodes/element/IElement';
import ProcessingInstruction from '../nodes/processing-instruction/ProcessingInstruction';
import IHappyDOMSettings from './IHappyDOMSettings';
import RequestInfo from '../fetch/RequestInfo';
import FileList from '../nodes/html-input-element/FileList';
/**
* Window without dependencies to server side specific packages.
*/
export default interface IWindow extends IEventTarget, NodeJS.Global {
// Public Properties
readonly happyDOM: {
whenAsyncComplete: () => Promise<void>;
cancelAsync: () => void;
asyncTaskManager: AsyncTaskManager;
setInnerWidth: (width: number) => void;
setInnerHeight: (height: number) => void;
setURL: (url: string) => void;
settings: IHappyDOMSettings;
};
// Global classes
readonly Node: typeof Node;
readonly HTMLElement: typeof HTMLElement;
readonly HTMLUnknownElement: typeof HTMLUnknownElement;
readonly HTMLTemplateElement: typeof HTMLTemplateElement;
readonly HTMLFormElement: typeof HTMLFormElement;
readonly HTMLInputElement: typeof HTMLInputElement;
readonly HTMLSelectElement: typeof HTMLSelectElement;
readonly HTMLTextAreaElement: typeof HTMLTextAreaElement;
readonly HTMLImageElement: typeof HTMLImageElement;
readonly HTMLScriptElement: typeof HTMLScriptElement;
readonly HTMLLinkElement: typeof HTMLLinkElement;
readonly HTMLStyleElement: typeof HTMLStyleElement;
readonly HTMLSlotElement: typeof HTMLSlotElement;
readonly HTMLLabelElement: typeof HTMLLabelElement;
readonly HTMLMetaElement: typeof HTMLMetaElement;
readonly HTMLMediaElement: typeof HTMLMediaElement;
readonly HTMLAudioElement: typeof HTMLAudioElement;
readonly HTMLVideoElement: typeof HTMLVideoElement;
readonly HTMLBaseElement: typeof HTMLBaseElement;
readonly HTMLDialogElement: typeof HTMLDialogElement;
readonly Attr: typeof Attr;
readonly NamedNodeMap: typeof NamedNodeMap;
readonly SVGSVGElement: typeof SVGSVGElement;
readonly SVGElement: typeof SVGElement;
readonly Image: typeof Image;
readonly Text: typeof Text;
readonly Comment: typeof Comment;
readonly ShadowRoot: typeof ShadowRoot;
readonly Element: typeof Element;
readonly DocumentFragment: typeof DocumentFragment;
readonly CharacterData: typeof CharacterData;
readonly ProcessingInstruction: typeof ProcessingInstruction;
readonly NodeFilter: typeof NodeFilter;
readonly TreeWalker: typeof TreeWalker;
readonly DOMParser: typeof DOMParser;
readonly MutationObserver: typeof MutationObserver;
readonly Document: typeof Document;
readonly HTMLDocument: typeof HTMLDocument;
readonly XMLDocument: typeof XMLDocument;
readonly SVGDocument: typeof SVGDocument;
readonly Event: typeof Event;
readonly UIEvent: typeof UIEvent;
readonly CustomEvent: typeof CustomEvent;
readonly AnimationEvent: typeof AnimationEvent;
readonly KeyboardEvent: typeof KeyboardEvent;
readonly PointerEvent: typeof PointerEvent;
readonly MouseEvent: typeof MouseEvent;
readonly FocusEvent: typeof FocusEvent;
readonly WheelEvent: typeof WheelEvent;
readonly InputEvent: typeof InputEvent;
readonly ErrorEvent: typeof ErrorEvent;
readonly StorageEvent: typeof StorageEvent;
readonly ProgressEvent: typeof ProgressEvent;
readonly MediaQueryListEvent: typeof MediaQueryListEvent;
readonly EventTarget: typeof EventTarget;
readonly DataTransfer: typeof DataTransfer;
readonly DataTransferItem: typeof DataTransferItem;
readonly DataTransferItemList: typeof DataTransferItemList;
readonly URL: typeof URL;
readonly URLSearchParams: typeof URLSearchParams;
readonly Location: typeof Location;
readonly CustomElementRegistry: typeof CustomElementRegistry;
readonly Window: typeof Window;
readonly XMLSerializer: typeof XMLSerializer;
readonly ResizeObserver: typeof ResizeObserver;
readonly CSSStyleSheet: typeof CSSStyleSheet;
readonly Blob: typeof Blob;
readonly File: typeof File;
readonly FileReader: typeof FileReader;
readonly DOMException: typeof DOMException;
readonly History: typeof History;
readonly Screen: typeof Screen;
readonly Storage: typeof Storage;
readonly HTMLCollection: typeof HTMLCollection;
readonly NodeList: typeof NodeList;
readonly CSSUnitValue: typeof CSSUnitValue;
readonly CSS: CSS;
readonly CSSRule: typeof CSSRule;
readonly CSSContainerRule: typeof CSSContainerRule;
readonly CSSFontFaceRule: typeof CSSFontFaceRule;
readonly CSSKeyframeRule: typeof CSSKeyframeRule;
readonly CSSKeyframesRule: typeof CSSKeyframesRule;
readonly CSSMediaRule: typeof CSSMediaRule;
readonly CSSStyleRule: typeof CSSStyleRule;
readonly Selection: typeof Selection;
readonly Navigator: typeof Navigator;
readonly MimeType: typeof MimeType;
readonly MimeTypeArray: typeof MimeTypeArray;
readonly Plugin: typeof Plugin;
readonly PluginArray: typeof PluginArray;
readonly Headers: { new (init?: string[][] | Record<string, string> | IHeaders): IHeaders };
readonly Request: { new (input: string | IRequest, init?: IRequestInit): IRequest };
readonly Response: { new (body?: unknown | null, init?: IResponseInit): IResponse };
readonly Range: typeof Range;
readonly DOMRect: typeof DOMRect;
readonly XMLHttpRequest: typeof XMLHttpRequest;
readonly XMLHttpRequestUpload: typeof XMLHttpRequestUpload;
readonly XMLHttpRequestEventTarget: typeof XMLHttpRequestEventTarget;
readonly FileList: typeof FileList;
// Events
onload: (event: Event) => void;
onerror: (event: ErrorEvent) => void;
// Public Properties
readonly document: Document;
readonly customElements: CustomElementRegistry;
readonly location: Location;
readonly history: History;
readonly navigator: Navigator;
readonly console: Console;
readonly self: IWindow;
readonly top: IWindow;
readonly parent: IWindow;
readonly window: IWindow;
readonly globalThis: IWindow;
readonly screen: Screen;
readonly innerWidth: number;
readonly innerHeight: number;
readonly sessionStorage: Storage;
readonly localStorage: Storage;
readonly performance: Performance;
readonly pageXOffset: number;
readonly pageYOffset: number;
readonly scrollX: number;
readonly scrollY: number;
/**
* Evaluates code.
*
* @param code Code.
* @returns Result.
*/
eval(code: string): unknown;
/**
* Returns an object containing the values of all CSS properties of an element.
*
* @param element Element.
* @returns CSS style declaration.
*/
getComputedStyle(element: IElement): CSSStyleDeclaration;
/**
* Returns selection.
*
* @returns Selection.
*/
getSelection(): Selection;
/**
* Scrolls to a particular set of coordinates.
*
* @param x X position or options object.
* @param y Y position.
*/
scroll(x: { top?: number; left?: number; behavior?: string } | number, y?: number): void;
/**
* Scrolls to a particular set of coordinates.
*
* @param x X position or options object.
* @param y Y position.
*/
scrollTo(x: { top?: number; left?: number; behavior?: string } | number, y?: number): void;
/**
* Returns a new MediaQueryList object that can then be used to determine if the document matches the media query string.
*
* @param mediaQueryString A string specifying the media query to parse into a MediaQueryList.
* @returns A new MediaQueryList.
*/
matchMedia(mediaQueryString: string): MediaQueryList;
/**
* Sets a timer which executes a function once the timer expires.
*
* @param callback Function to be executed.
* @param [delay=0] Delay in ms.
* @returns Timeout ID.
*/
setTimeout(callback: () => void, delay?: number): NodeJS.Timeout;
/**
* Cancels a timeout previously established by calling setTimeout().
*
* @param id ID of the timeout.
*/
clearTimeout(id: NodeJS.Timeout): void;
/**
* Calls a function with a fixed time delay between each call.
*
* @param callback Function to be executed.
* @param [delay=0] Delay in ms.
* @returns Interval ID.
*/
setInterval(callback: () => void, delay?: number): NodeJS.Timeout;
/**
* Cancels a timed repeating action which was previously established by a call to setInterval().
*
* @param id ID of the interval.
*/
clearInterval(id: NodeJS.Timeout): void;
/**
* Mock animation frames with timeouts.
*
* @param {Function} callback Callback.
* @returns {NodeJS.Timeout} Timeout ID.
*/
requestAnimationFrame(callback: (timestamp: number) => void): NodeJS.Timeout;
/**
* Mock animation frames with timeouts.
*
* @param {NodeJS.Timeout} id Timeout ID.
*/
cancelAnimationFrame(id: NodeJS.Timeout): void;
/**
* This method provides an easy, logical way to fetch resources asynchronously across the network.
*
* @param url URL.
* @param [init] Init.
* @returns Promise.
*/
fetch(url: RequestInfo, init?: IRequestInit): Promise<IResponse>;
/**
* Creates a Base64-encoded ASCII string from a binary string (i.e., a string in which each character in the string is treated as a byte of binary data).
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/btoa
* @param data Binary data.
* @returns Base64-encoded string.
*/
btoa(data: unknown): string;
/**
* Decodes a string of data which has been encoded using Base64 encoding.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/atob
* @see https://infra.spec.whatwg.org/#forgiving-base64-encode.
* @see Https://html.spec.whatwg.org/multipage/webappapis.html#btoa.
* @param data Binary string.
* @returns An ASCII string containing decoded data from encodedData.
*/
atob(data: unknown): string;
}