版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

525 строки
20 KiB

  1. /// <reference types="node" />
  2. /// <reference types="node" />
  3. /// <reference types="node" />
  4. /// <reference types="node" />
  5. import CustomElementRegistry from '../custom-element/CustomElementRegistry';
  6. import Document from '../nodes/document/Document';
  7. import HTMLDocument from '../nodes/html-document/HTMLDocument';
  8. import XMLDocument from '../nodes/xml-document/XMLDocument';
  9. import SVGDocument from '../nodes/svg-document/SVGDocument';
  10. import Node from '../nodes/node/Node';
  11. import Text from '../nodes/text/Text';
  12. import Comment from '../nodes/comment/Comment';
  13. import ShadowRoot from '../nodes/shadow-root/ShadowRoot';
  14. import Element from '../nodes/element/Element';
  15. import HTMLTemplateElement from '../nodes/html-template-element/HTMLTemplateElement';
  16. import HTMLFormElement from '../nodes/html-form-element/HTMLFormElement';
  17. import HTMLElement from '../nodes/html-element/HTMLElement';
  18. import HTMLUnknownElement from '../nodes/html-unknown-element/HTMLUnknownElement';
  19. import HTMLInputElement from '../nodes/html-input-element/HTMLInputElement';
  20. import HTMLSelectElement from '../nodes/html-select-element/HTMLSelectElement';
  21. import HTMLTextAreaElement from '../nodes/html-text-area-element/HTMLTextAreaElement';
  22. import HTMLLinkElement from '../nodes/html-link-element/HTMLLinkElement';
  23. import HTMLStyleElement from '../nodes/html-style-element/HTMLStyleElement';
  24. import HTMLSlotElement from '../nodes/html-slot-element/HTMLSlotElement';
  25. import HTMLLabelElement from '../nodes/html-label-element/HTMLLabelElement';
  26. import HTMLMetaElement from '../nodes/html-meta-element/HTMLMetaElement';
  27. import HTMLMediaElement from '../nodes/html-media-element/HTMLMediaElement';
  28. import HTMLAudioElement from '../nodes/html-audio-element/HTMLAudioElement';
  29. import HTMLVideoElement from '../nodes/html-video-element/HTMLVideoElement';
  30. import HTMLBaseElement from '../nodes/html-base-element/HTMLBaseElement';
  31. import HTMLIFrameElement from '../nodes/html-iframe-element/HTMLIFrameElement';
  32. import HTMLDialogElement from '../nodes/html-dialog-element/HTMLDialogElement';
  33. import SVGSVGElement from '../nodes/svg-element/SVGSVGElement';
  34. import SVGElement from '../nodes/svg-element/SVGElement';
  35. import SVGGraphicsElement from '../nodes/svg-element/SVGGraphicsElement';
  36. import HTMLScriptElement from '../nodes/html-script-element/HTMLScriptElement';
  37. import HTMLImageElement from '../nodes/html-image-element/HTMLImageElement';
  38. import DocumentFragment from '../nodes/document-fragment/DocumentFragment';
  39. import CharacterData from '../nodes/character-data/CharacterData';
  40. import TreeWalker from '../tree-walker/TreeWalker';
  41. import Event from '../event/Event';
  42. import CustomEvent from '../event/events/CustomEvent';
  43. import AnimationEvent from '../event/events/AnimationEvent';
  44. import KeyboardEvent from '../event/events/KeyboardEvent';
  45. import MessageEvent from '../event/events/MessageEvent';
  46. import ProgressEvent from '../event/events/ProgressEvent';
  47. import MediaQueryListEvent from '../event/events/MediaQueryListEvent';
  48. import EventTarget from '../event/EventTarget';
  49. import MessagePort from '../event/MessagePort';
  50. import { URL, URLSearchParams } from 'url';
  51. import Location from '../location/Location';
  52. import MutationObserver from '../mutation-observer/MutationObserver';
  53. import XMLSerializer from '../xml-serializer/XMLSerializer';
  54. import ResizeObserver from '../resize-observer/ResizeObserver';
  55. import Blob from '../file/Blob';
  56. import File from '../file/File';
  57. import DOMException from '../exception/DOMException';
  58. import History from '../history/History';
  59. import CSSStyleSheet from '../css/CSSStyleSheet';
  60. import CSSStyleDeclaration from '../css/declaration/CSSStyleDeclaration';
  61. import CSS from '../css/CSS';
  62. import CSSUnitValue from '../css/CSSUnitValue';
  63. import CSSRule from '../css/CSSRule';
  64. import CSSContainerRule from '../css/rules/CSSContainerRule';
  65. import CSSFontFaceRule from '../css/rules/CSSFontFaceRule';
  66. import CSSKeyframeRule from '../css/rules/CSSKeyframeRule';
  67. import CSSKeyframesRule from '../css/rules/CSSKeyframesRule';
  68. import CSSMediaRule from '../css/rules/CSSMediaRule';
  69. import CSSStyleRule from '../css/rules/CSSStyleRule';
  70. import MouseEvent from '../event/events/MouseEvent';
  71. import PointerEvent from '../event/events/PointerEvent';
  72. import FocusEvent from '../event/events/FocusEvent';
  73. import WheelEvent from '../event/events/WheelEvent';
  74. import DataTransfer from '../event/DataTransfer';
  75. import DataTransferItem from '../event/DataTransferItem';
  76. import DataTransferItemList from '../event/DataTransferItemList';
  77. import InputEvent from '../event/events/InputEvent';
  78. import UIEvent from '../event/UIEvent';
  79. import ErrorEvent from '../event/events/ErrorEvent';
  80. import StorageEvent from '../event/events/StorageEvent';
  81. import Screen from '../screen/Screen';
  82. import AsyncTaskManager from '../async-task-manager/AsyncTaskManager';
  83. import IResponse from '../fetch/IResponse';
  84. import IResponseInit from '../fetch/IResponseInit';
  85. import IRequest from '../fetch/IRequest';
  86. import IRequestInit from '../fetch/IRequestInit';
  87. import IHeaders from '../fetch/IHeaders';
  88. import IHeadersInit from '../fetch/IHeadersInit';
  89. import Storage from '../storage/Storage';
  90. import IWindow from './IWindow';
  91. import HTMLCollection from '../nodes/element/HTMLCollection';
  92. import NodeList from '../nodes/node/NodeList';
  93. import MediaQueryList from '../match-media/MediaQueryList';
  94. import Selection from '../selection/Selection';
  95. import Navigator from '../navigator/Navigator';
  96. import MimeType from '../navigator/MimeType';
  97. import MimeTypeArray from '../navigator/MimeTypeArray';
  98. import Plugin from '../navigator/Plugin';
  99. import PluginArray from '../navigator/PluginArray';
  100. import DOMRect from '../nodes/element/DOMRect';
  101. import * as PerfHooks from 'perf_hooks';
  102. import XMLHttpRequestUpload from '../xml-http-request/XMLHttpRequestUpload';
  103. import XMLHttpRequestEventTarget from '../xml-http-request/XMLHttpRequestEventTarget';
  104. import Attr from '../nodes/attr/Attr';
  105. import NamedNodeMap from '../named-node-map/NamedNodeMap';
  106. import IElement from '../nodes/element/IElement';
  107. import ProcessingInstruction from '../nodes/processing-instruction/ProcessingInstruction';
  108. import RequestInfo from '../fetch/RequestInfo';
  109. import FileList from '../nodes/html-input-element/FileList';
  110. import IHappyDOMOptions from './IHappyDOMOptions';
  111. /**
  112. * Browser window.
  113. *
  114. * Reference:
  115. * https://developer.mozilla.org/en-US/docs/Web/API/Window.
  116. */
  117. export default class Window extends EventTarget implements IWindow {
  118. readonly happyDOM: {
  119. whenAsyncComplete: () => Promise<void>;
  120. cancelAsync: () => void;
  121. asyncTaskManager: AsyncTaskManager;
  122. setInnerWidth: (width: number) => void;
  123. setInnerHeight: (height: number) => void;
  124. setURL: (url: string) => void;
  125. settings: {
  126. disableJavaScriptEvaluation: boolean;
  127. disableJavaScriptFileLoading: boolean;
  128. disableCSSFileLoading: boolean;
  129. disableIframePageLoading: boolean;
  130. enableFileSystemHttpRequests: boolean;
  131. };
  132. };
  133. readonly Node: typeof Node;
  134. readonly HTMLElement: typeof HTMLElement;
  135. readonly HTMLUnknownElement: typeof HTMLUnknownElement;
  136. readonly HTMLTemplateElement: typeof HTMLTemplateElement;
  137. readonly HTMLFormElement: typeof HTMLFormElement;
  138. readonly HTMLInputElement: typeof HTMLInputElement;
  139. readonly HTMLSelectElement: typeof HTMLSelectElement;
  140. readonly HTMLTextAreaElement: typeof HTMLTextAreaElement;
  141. readonly HTMLImageElement: typeof HTMLImageElement;
  142. readonly HTMLScriptElement: typeof HTMLScriptElement;
  143. readonly HTMLLinkElement: typeof HTMLLinkElement;
  144. readonly HTMLStyleElement: typeof HTMLStyleElement;
  145. readonly HTMLLabelElement: typeof HTMLLabelElement;
  146. readonly HTMLSlotElement: typeof HTMLSlotElement;
  147. readonly HTMLMetaElement: typeof HTMLMetaElement;
  148. readonly HTMLMediaElement: typeof HTMLMediaElement;
  149. readonly HTMLAudioElement: typeof HTMLAudioElement;
  150. readonly HTMLVideoElement: typeof HTMLVideoElement;
  151. readonly HTMLBaseElement: typeof HTMLBaseElement;
  152. readonly HTMLIFrameElement: typeof HTMLIFrameElement;
  153. readonly HTMLDialogElement: typeof HTMLDialogElement;
  154. readonly Attr: typeof Attr;
  155. readonly NamedNodeMap: typeof NamedNodeMap;
  156. readonly SVGSVGElement: typeof SVGSVGElement;
  157. readonly SVGElement: typeof SVGElement;
  158. readonly SVGGraphicsElement: typeof SVGGraphicsElement;
  159. readonly Text: typeof Text;
  160. readonly Comment: typeof Comment;
  161. readonly ShadowRoot: typeof ShadowRoot;
  162. readonly ProcessingInstruction: typeof ProcessingInstruction;
  163. readonly Element: typeof Element;
  164. readonly DocumentFragment: typeof DocumentFragment;
  165. readonly CharacterData: typeof CharacterData;
  166. readonly NodeFilter: {
  167. FILTER_ACCEPT: number;
  168. FILTER_REJECT: number;
  169. FILTER_SKIP: number;
  170. SHOW_ALL: number;
  171. SHOW_ELEMENT: number;
  172. SHOW_ATTRIBUTE: number;
  173. SHOW_TEXT: number;
  174. SHOW_CDATA_SECTION: number;
  175. SHOW_ENTITY_REFERENCE: number;
  176. SHOW_ENTITY: number;
  177. SHOW_PROCESSING_INSTRUCTION: number;
  178. SHOW_COMMENT: number;
  179. SHOW_DOCUMENT: number;
  180. SHOW_DOCUMENT_TYPE: number;
  181. SHOW_DOCUMENT_FRAGMENT: number;
  182. SHOW_NOTATION: number;
  183. };
  184. readonly TreeWalker: typeof TreeWalker;
  185. readonly MutationObserver: typeof MutationObserver;
  186. readonly Document: typeof Document;
  187. readonly HTMLDocument: typeof HTMLDocument;
  188. readonly XMLDocument: typeof XMLDocument;
  189. readonly SVGDocument: typeof SVGDocument;
  190. readonly Event: typeof Event;
  191. readonly UIEvent: typeof UIEvent;
  192. readonly CustomEvent: typeof CustomEvent;
  193. readonly AnimationEvent: typeof AnimationEvent;
  194. readonly KeyboardEvent: typeof KeyboardEvent;
  195. readonly MessageEvent: typeof MessageEvent;
  196. readonly MouseEvent: typeof MouseEvent;
  197. readonly PointerEvent: typeof PointerEvent;
  198. readonly FocusEvent: typeof FocusEvent;
  199. readonly WheelEvent: typeof WheelEvent;
  200. readonly InputEvent: typeof InputEvent;
  201. readonly ErrorEvent: typeof ErrorEvent;
  202. readonly StorageEvent: typeof StorageEvent;
  203. readonly ProgressEvent: typeof ProgressEvent;
  204. readonly MediaQueryListEvent: typeof MediaQueryListEvent;
  205. readonly EventTarget: typeof EventTarget;
  206. readonly MessagePort: typeof MessagePort;
  207. readonly DataTransfer: typeof DataTransfer;
  208. readonly DataTransferItem: typeof DataTransferItem;
  209. readonly DataTransferItemList: typeof DataTransferItemList;
  210. readonly URL: typeof URL;
  211. readonly Location: typeof Location;
  212. readonly CustomElementRegistry: typeof CustomElementRegistry;
  213. readonly Window: typeof Window;
  214. readonly XMLSerializer: typeof XMLSerializer;
  215. readonly ResizeObserver: typeof ResizeObserver;
  216. readonly CSSStyleSheet: typeof CSSStyleSheet;
  217. readonly Blob: typeof Blob;
  218. readonly File: typeof File;
  219. readonly DOMException: typeof DOMException;
  220. readonly History: typeof History;
  221. readonly Screen: typeof Screen;
  222. readonly Storage: typeof Storage;
  223. readonly URLSearchParams: typeof URLSearchParams;
  224. readonly HTMLCollection: typeof HTMLCollection;
  225. readonly NodeList: typeof NodeList;
  226. readonly CSSUnitValue: typeof CSSUnitValue;
  227. readonly CSSRule: typeof CSSRule;
  228. readonly CSSContainerRule: typeof CSSContainerRule;
  229. readonly CSSFontFaceRule: typeof CSSFontFaceRule;
  230. readonly CSSKeyframeRule: typeof CSSKeyframeRule;
  231. readonly CSSKeyframesRule: typeof CSSKeyframesRule;
  232. readonly CSSMediaRule: typeof CSSMediaRule;
  233. readonly CSSStyleRule: typeof CSSStyleRule;
  234. readonly Selection: typeof Selection;
  235. readonly Navigator: typeof Navigator;
  236. readonly MimeType: typeof MimeType;
  237. readonly MimeTypeArray: typeof MimeTypeArray;
  238. readonly Plugin: typeof Plugin;
  239. readonly PluginArray: typeof PluginArray;
  240. readonly FileList: typeof FileList;
  241. readonly Headers: {
  242. new (init?: IHeadersInit): IHeaders;
  243. };
  244. readonly DOMRect: typeof DOMRect;
  245. readonly Request: {
  246. new (input: string | {
  247. href: string;
  248. } | IRequest, init?: IRequestInit): IRequest;
  249. };
  250. readonly Response: {
  251. new (body?: NodeJS.ReadableStream | null, init?: IResponseInit): IResponse;
  252. };
  253. readonly XMLHttpRequestUpload: typeof XMLHttpRequestUpload;
  254. readonly XMLHttpRequestEventTarget: typeof XMLHttpRequestEventTarget;
  255. readonly XMLHttpRequest: any;
  256. readonly DOMParser: any;
  257. readonly Range: any;
  258. readonly FileReader: any;
  259. readonly Image: any;
  260. readonly Audio: any;
  261. onload: (event: Event) => void;
  262. onerror: (event: ErrorEvent) => void;
  263. readonly document: Document;
  264. readonly customElements: CustomElementRegistry;
  265. readonly location: Location;
  266. readonly history: History;
  267. readonly navigator: Navigator;
  268. readonly console: Console;
  269. readonly self: this;
  270. readonly top: this;
  271. readonly parent: this;
  272. readonly window: this;
  273. readonly globalThis: this;
  274. readonly screen: Screen;
  275. readonly devicePixelRatio = 1;
  276. readonly sessionStorage: Storage;
  277. readonly localStorage: Storage;
  278. readonly performance: PerfHooks.Performance;
  279. readonly innerWidth: number;
  280. readonly innerHeight: number;
  281. ArrayBuffer: any;
  282. Boolean: any;
  283. Buffer: typeof globalThis.Buffer;
  284. DataView: any;
  285. Date: any;
  286. Error: any;
  287. EvalError: any;
  288. Float32Array: any;
  289. Float64Array: any;
  290. GLOBAL: any;
  291. Infinity: any;
  292. Int16Array: any;
  293. Int32Array: any;
  294. Int8Array: any;
  295. Intl: any;
  296. JSON: any;
  297. Map: any;
  298. Math: any;
  299. NaN: any;
  300. Number: any;
  301. Promise: any;
  302. RangeError: any;
  303. ReferenceError: any;
  304. RegExp: any;
  305. Reflect: any;
  306. Set: any;
  307. Symbol: any;
  308. SyntaxError: any;
  309. String: any;
  310. TypeError: any;
  311. URIError: any;
  312. Uint16Array: any;
  313. Uint32Array: any;
  314. Uint8Array: any;
  315. Uint8ClampedArray: any;
  316. WeakMap: any;
  317. WeakSet: any;
  318. clearImmediate: any;
  319. decodeURI: any;
  320. decodeURIComponent: any;
  321. encodeURI: any;
  322. encodeURIComponent: any;
  323. escape: any;
  324. global: any;
  325. isFinite: any;
  326. isNaN: any;
  327. parseFloat: any;
  328. parseInt: any;
  329. process: any;
  330. root: any;
  331. setImmediate: any;
  332. queueMicrotask: any;
  333. undefined: any;
  334. unescape: any;
  335. gc: any;
  336. v8debug: any;
  337. AbortController: any;
  338. AbortSignal: any;
  339. Array: any;
  340. Object: any;
  341. Function: any;
  342. private _setTimeout;
  343. private _clearTimeout;
  344. private _setInterval;
  345. private _clearInterval;
  346. /**
  347. * Constructor.
  348. *
  349. * @param [options] Options.
  350. * @param [options.innerWidth] Inner width. Defaults to "1024".
  351. * @param [options.innerHeight] Inner height. Defaults to "768".
  352. * @param [options.url] URL.
  353. * @param [options.settings] Settings.
  354. */
  355. constructor(options?: IHappyDOMOptions);
  356. /**
  357. * The number of pixels that the document is currently scrolled horizontally
  358. *
  359. * @returns number
  360. */
  361. get scrollX(): number;
  362. /**
  363. * The read-only Window property pageXOffset is an alias for scrollX.
  364. *
  365. * @returns number
  366. */
  367. get pageXOffset(): number;
  368. /**
  369. * The number of pixels that the document is currently scrolled vertically
  370. *
  371. * @returns number
  372. */
  373. get scrollY(): number;
  374. /**
  375. * The read-only Window property pageYOffset is an alias for scrollY.
  376. *
  377. * @returns number
  378. */
  379. get pageYOffset(): number;
  380. /**
  381. * The CSS interface holds useful CSS-related methods.
  382. *
  383. * @returns CSS interface.
  384. */
  385. get CSS(): CSS;
  386. /**
  387. * Evaluates code.
  388. *
  389. * @override
  390. * @param code Code.
  391. * @returns Result.
  392. */
  393. eval(code: string): unknown;
  394. /**
  395. * Returns an object containing the values of all CSS properties of an element.
  396. *
  397. * @param element Element.
  398. * @returns CSS style declaration.
  399. */
  400. getComputedStyle(element: IElement): CSSStyleDeclaration;
  401. /**
  402. * Returns selection.
  403. *
  404. * @returns Selection.
  405. */
  406. getSelection(): Selection;
  407. /**
  408. * Scrolls to a particular set of coordinates.
  409. *
  410. * @param x X position or options object.
  411. * @param y Y position.
  412. */
  413. scroll(x: {
  414. top?: number;
  415. left?: number;
  416. behavior?: string;
  417. } | number, y?: number): void;
  418. /**
  419. * Scrolls to a particular set of coordinates.
  420. *
  421. * @param x X position or options object.
  422. * @param y Y position.
  423. */
  424. scrollTo(x: {
  425. top?: number;
  426. left?: number;
  427. behavior?: string;
  428. } | number, y?: number): void;
  429. /**
  430. * Returns a new MediaQueryList object that can then be used to determine if the document matches the media query string.
  431. *
  432. * @param mediaQueryString A string specifying the media query to parse into a MediaQueryList.
  433. * @returns A new MediaQueryList.
  434. */
  435. matchMedia(mediaQueryString: string): MediaQueryList;
  436. /**
  437. * Sets a timer which executes a function once the timer expires.
  438. *
  439. * @override
  440. * @param callback Function to be executed.
  441. * @param [delay=0] Delay in ms.
  442. * @param args Arguments passed to the callback function.
  443. * @returns Timeout ID.
  444. */
  445. setTimeout(callback: Function, delay?: number, ...args: unknown[]): NodeJS.Timeout;
  446. /**
  447. * Cancels a timeout previously established by calling setTimeout().
  448. *
  449. * @override
  450. * @param id ID of the timeout.
  451. */
  452. clearTimeout(id: NodeJS.Timeout): void;
  453. /**
  454. * Calls a function with a fixed time delay between each call.
  455. *
  456. * @override
  457. * @param callback Function to be executed.
  458. * @param [delay=0] Delay in ms.
  459. * @param args Arguments passed to the callback function.
  460. * @returns Interval ID.
  461. */
  462. setInterval(callback: Function, delay?: number, ...args: unknown[]): NodeJS.Timeout;
  463. /**
  464. * Cancels a timed repeating action which was previously established by a call to setInterval().
  465. *
  466. * @override
  467. * @param id ID of the interval.
  468. */
  469. clearInterval(id: NodeJS.Timeout): void;
  470. /**
  471. * Mock animation frames with timeouts.
  472. *
  473. * @override
  474. * @param callback Callback.
  475. * @returns Timeout ID.
  476. */
  477. requestAnimationFrame(callback: (timestamp: number) => void): NodeJS.Timeout;
  478. /**
  479. * Mock animation frames with timeouts.
  480. *
  481. * @override
  482. * @param id Timeout ID.
  483. */
  484. cancelAnimationFrame(id: NodeJS.Timeout): void;
  485. /**
  486. * This method provides an easy, logical way to fetch resources asynchronously across the network.
  487. *
  488. * @override
  489. * @param url URL.
  490. * @param [init] Init.
  491. * @returns Promise.
  492. */
  493. fetch(url: RequestInfo, init?: IRequestInit): Promise<IResponse>;
  494. /**
  495. * 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).
  496. *
  497. * @see https://developer.mozilla.org/en-US/docs/Web/API/btoa
  498. * @param data Binay data.
  499. * @returns Base64-encoded string.
  500. */
  501. btoa(data: unknown): string;
  502. /**
  503. * Decodes a string of data which has been encoded using Base64 encoding.
  504. *
  505. * @see https://developer.mozilla.org/en-US/docs/Web/API/atob
  506. * @see https://infra.spec.whatwg.org/#forgiving-base64-encode.
  507. * @see Https://html.spec.whatwg.org/multipage/webappapis.html#btoa.
  508. * @param data Binay string.
  509. * @returns An ASCII string containing decoded data from encodedData.
  510. */
  511. atob(data: unknown): string;
  512. /**
  513. * Safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it spawned, or between a page and an iframe embedded within it.
  514. *
  515. * @param message Message.
  516. * @param [targetOrigin=*] Target origin.
  517. * @param _transfer Transfer. Not implemented.
  518. */
  519. postMessage(message: unknown, targetOrigin?: string, _transfer?: unknown[]): void;
  520. /**
  521. * Setup of VM context.
  522. */
  523. protected _setupVMContext(): void;
  524. }