版博士V2.0程序
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

387 linhas
17 KiB

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