2022-01-20 02:10:16 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2020-01-29 12:54:23 -05:00
|
|
|
|
|
|
|
/// <reference no-default-lib="true" />
|
2020-02-19 00:34:11 -05:00
|
|
|
/// <reference lib="deno.ns" />
|
|
|
|
/// <reference lib="deno.shared_globals" />
|
2021-03-01 05:31:13 -05:00
|
|
|
/// <reference lib="deno.webgpu" />
|
2021-05-10 06:02:47 -04:00
|
|
|
/// <reference lib="deno.webstorage" />
|
2020-01-29 12:54:23 -05:00
|
|
|
/// <reference lib="esnext" />
|
2022-09-28 08:11:12 -04:00
|
|
|
/// <reference lib="deno.cache" />
|
2020-01-29 12:54:23 -05:00
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web APIs */
|
2022-04-13 05:50:57 -04:00
|
|
|
interface WindowEventMap {
|
|
|
|
"error": ErrorEvent;
|
2022-07-21 17:54:53 -04:00
|
|
|
"unhandledrejection": PromiseRejectionEvent;
|
2022-04-13 05:50:57 -04:00
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web APIs */
|
2020-10-11 18:04:43 -04:00
|
|
|
declare class Window extends EventTarget {
|
|
|
|
new(): Window;
|
2020-04-11 11:42:02 -04:00
|
|
|
readonly window: Window & typeof globalThis;
|
|
|
|
readonly self: Window & typeof globalThis;
|
2022-04-13 05:50:57 -04:00
|
|
|
onerror: ((this: Window, ev: ErrorEvent) => any) | null;
|
2020-04-11 11:42:02 -04:00
|
|
|
onload: ((this: Window, ev: Event) => any) | null;
|
2022-10-13 04:47:47 -04:00
|
|
|
onbeforeunload: ((this: Window, ev: Event) => any) | null;
|
2020-04-11 11:42:02 -04:00
|
|
|
onunload: ((this: Window, ev: Event) => any) | null;
|
2022-07-21 17:54:53 -04:00
|
|
|
onunhandledrejection:
|
|
|
|
| ((this: Window, ev: PromiseRejectionEvent) => any)
|
|
|
|
| null;
|
2020-03-24 23:56:40 -04:00
|
|
|
close: () => void;
|
2020-04-11 11:42:02 -04:00
|
|
|
readonly closed: boolean;
|
2020-10-13 09:31:59 -04:00
|
|
|
alert: (message?: string) => void;
|
|
|
|
confirm: (message?: string) => boolean;
|
|
|
|
prompt: (message?: string, defaultValue?: string) => string | null;
|
2020-01-29 12:54:23 -05:00
|
|
|
Deno: typeof Deno;
|
2021-03-08 07:27:49 -05:00
|
|
|
Navigator: typeof Navigator;
|
2021-03-01 05:31:13 -05:00
|
|
|
navigator: Navigator;
|
2021-03-08 07:27:49 -05:00
|
|
|
Location: typeof Location;
|
|
|
|
location: Location;
|
2021-05-10 06:02:47 -04:00
|
|
|
localStorage: Storage;
|
|
|
|
sessionStorage: Storage;
|
2022-09-28 08:11:12 -04:00
|
|
|
caches: CacheStorage;
|
2022-04-13 05:50:57 -04:00
|
|
|
|
|
|
|
addEventListener<K extends keyof WindowEventMap>(
|
|
|
|
type: K,
|
|
|
|
listener: (
|
|
|
|
this: Window,
|
|
|
|
ev: WindowEventMap[K],
|
|
|
|
) => any,
|
|
|
|
options?: boolean | AddEventListenerOptions,
|
|
|
|
): void;
|
|
|
|
addEventListener(
|
|
|
|
type: string,
|
|
|
|
listener: EventListenerOrEventListenerObject,
|
|
|
|
options?: boolean | AddEventListenerOptions,
|
|
|
|
): void;
|
|
|
|
removeEventListener<K extends keyof WindowEventMap>(
|
|
|
|
type: K,
|
|
|
|
listener: (
|
|
|
|
this: Window,
|
|
|
|
ev: WindowEventMap[K],
|
|
|
|
) => any,
|
|
|
|
options?: boolean | EventListenerOptions,
|
|
|
|
): void;
|
|
|
|
removeEventListener(
|
|
|
|
type: string,
|
|
|
|
listener: EventListenerOrEventListenerObject,
|
|
|
|
options?: boolean | EventListenerOptions,
|
|
|
|
): void;
|
2020-01-29 12:54:23 -05:00
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web APIs */
|
2020-09-25 17:23:35 -04:00
|
|
|
declare var window: Window & typeof globalThis;
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web APIs */
|
2020-09-25 17:23:35 -04:00
|
|
|
declare var self: Window & typeof globalThis;
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category DOM Events */
|
2022-04-13 05:50:57 -04:00
|
|
|
declare var onerror: ((this: Window, ev: ErrorEvent) => any) | null;
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category DOM Events */
|
2020-09-25 17:23:35 -04:00
|
|
|
declare var onload: ((this: Window, ev: Event) => any) | null;
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category DOM Events */
|
2022-10-13 04:47:47 -04:00
|
|
|
declare var onbeforeunload: ((this: Window, ev: Event) => any) | null;
|
|
|
|
/** @category DOM Events */
|
2020-09-25 17:23:35 -04:00
|
|
|
declare var onunload: ((this: Window, ev: Event) => any) | null;
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Observability */
|
2022-07-21 17:54:53 -04:00
|
|
|
declare var onunhandledrejection:
|
|
|
|
| ((this: Window, ev: PromiseRejectionEvent) => any)
|
|
|
|
| null;
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Storage API */
|
2021-05-10 06:02:47 -04:00
|
|
|
declare var localStorage: Storage;
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Storage API */
|
2021-05-10 06:02:47 -04:00
|
|
|
declare var sessionStorage: Storage;
|
2022-09-28 08:11:12 -04:00
|
|
|
/** @category Cache API */
|
|
|
|
declare var caches: CacheStorage;
|
2021-03-01 05:31:13 -05:00
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web APIs */
|
2021-03-08 07:27:49 -05:00
|
|
|
declare class Navigator {
|
|
|
|
constructor();
|
2021-03-01 05:31:13 -05:00
|
|
|
readonly gpu: GPU;
|
2021-07-29 15:45:11 -04:00
|
|
|
readonly hardwareConcurrency: number;
|
2022-05-14 06:00:02 -04:00
|
|
|
readonly userAgent: string;
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|
2020-01-29 12:54:23 -05:00
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web APIs */
|
2021-03-08 07:27:49 -05:00
|
|
|
declare var navigator: Navigator;
|
|
|
|
|
2020-10-13 09:31:59 -04:00
|
|
|
/**
|
|
|
|
* Shows the given message and waits for the enter key pressed.
|
2022-08-16 23:12:24 -04:00
|
|
|
*
|
2020-10-13 09:31:59 -04:00
|
|
|
* If the stdin is not interactive, it does nothing.
|
2022-08-16 23:12:24 -04:00
|
|
|
*
|
|
|
|
* @category Web APIs
|
|
|
|
*
|
2020-10-13 09:31:59 -04:00
|
|
|
* @param message
|
|
|
|
*/
|
|
|
|
declare function alert(message?: string): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the given message and waits for the answer. Returns the user's answer as boolean.
|
2022-08-16 23:12:24 -04:00
|
|
|
*
|
2020-10-13 09:31:59 -04:00
|
|
|
* Only `y` and `Y` are considered as true.
|
2022-08-16 23:12:24 -04:00
|
|
|
*
|
2020-10-13 09:31:59 -04:00
|
|
|
* If the stdin is not interactive, it returns false.
|
2022-08-16 23:12:24 -04:00
|
|
|
*
|
|
|
|
* @category Web APIs
|
|
|
|
*
|
2020-10-13 09:31:59 -04:00
|
|
|
* @param message
|
|
|
|
*/
|
|
|
|
declare function confirm(message?: string): boolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the given message and waits for the user's input. Returns the user's input as string.
|
2022-08-16 23:12:24 -04:00
|
|
|
*
|
2020-10-13 09:31:59 -04:00
|
|
|
* If the default value is given and the user inputs the empty string, then it returns the given
|
|
|
|
* default value.
|
2022-08-16 23:12:24 -04:00
|
|
|
*
|
2020-10-13 09:31:59 -04:00
|
|
|
* If the default value is not given and the user inputs the empty string, it returns null.
|
2022-08-16 23:12:24 -04:00
|
|
|
*
|
2020-10-13 09:31:59 -04:00
|
|
|
* If the stdin is not interactive, it returns null.
|
2022-08-16 23:12:24 -04:00
|
|
|
*
|
|
|
|
* @category Web APIs
|
|
|
|
*
|
2020-10-13 09:31:59 -04:00
|
|
|
* @param message
|
|
|
|
* @param defaultValue
|
|
|
|
*/
|
|
|
|
declare function prompt(message?: string, defaultValue?: string): string | null;
|
2021-01-17 10:28:54 -05:00
|
|
|
|
2021-06-14 21:16:06 -04:00
|
|
|
/** Registers an event listener in the global scope, which will be called
|
|
|
|
* synchronously whenever the event `type` is dispatched.
|
|
|
|
*
|
2022-02-22 14:41:59 -05:00
|
|
|
* ```ts
|
|
|
|
* addEventListener('unload', () => { console.log('All finished!'); });
|
|
|
|
* ...
|
|
|
|
* dispatchEvent(new Event('unload'));
|
|
|
|
* ```
|
2022-08-16 23:12:24 -04:00
|
|
|
*
|
|
|
|
* @category DOM Events
|
2021-06-14 21:16:06 -04:00
|
|
|
*/
|
2022-04-13 05:50:57 -04:00
|
|
|
declare function addEventListener<
|
|
|
|
K extends keyof WindowEventMap,
|
|
|
|
>(
|
|
|
|
type: K,
|
|
|
|
listener: (this: Window, ev: WindowEventMap[K]) => any,
|
|
|
|
options?: boolean | AddEventListenerOptions,
|
|
|
|
): void;
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category DOM Events */
|
2021-06-14 21:16:06 -04:00
|
|
|
declare function addEventListener(
|
|
|
|
type: string,
|
2022-04-13 05:50:57 -04:00
|
|
|
listener: EventListenerOrEventListenerObject,
|
|
|
|
options?: boolean | AddEventListenerOptions,
|
2021-06-14 21:16:06 -04:00
|
|
|
): void;
|
|
|
|
|
|
|
|
/** Remove a previously registered event listener from the global scope
|
|
|
|
*
|
2022-02-22 14:41:59 -05:00
|
|
|
* ```ts
|
|
|
|
* const listener = () => { console.log('hello'); };
|
|
|
|
* addEventListener('load', listener);
|
|
|
|
* removeEventListener('load', listener);
|
|
|
|
* ```
|
2022-08-16 23:12:24 -04:00
|
|
|
*
|
|
|
|
* @category DOM Events
|
2021-06-14 21:16:06 -04:00
|
|
|
*/
|
2022-04-13 05:50:57 -04:00
|
|
|
declare function removeEventListener<
|
|
|
|
K extends keyof WindowEventMap,
|
|
|
|
>(
|
|
|
|
type: K,
|
|
|
|
listener: (this: Window, ev: WindowEventMap[K]) => any,
|
|
|
|
options?: boolean | EventListenerOptions,
|
|
|
|
): void;
|
2021-06-14 21:16:06 -04:00
|
|
|
declare function removeEventListener(
|
|
|
|
type: string,
|
2022-04-13 05:50:57 -04:00
|
|
|
listener: EventListenerOrEventListenerObject,
|
|
|
|
options?: boolean | EventListenerOptions,
|
2021-06-14 21:16:06 -04:00
|
|
|
): void;
|
|
|
|
|
2021-04-30 15:51:48 -04:00
|
|
|
// TODO(nayeemrmn): Move this to `extensions/web` where its implementation is.
|
2021-01-17 10:28:54 -05:00
|
|
|
// The types there must first be split into window, worker and global types.
|
|
|
|
/** The location (URL) of the object it is linked to. Changes done on it are
|
|
|
|
* reflected on the object it relates to. Accessible via
|
2022-08-16 23:12:24 -04:00
|
|
|
* `globalThis.location`.
|
|
|
|
*
|
|
|
|
* @category Web APIs
|
|
|
|
*/
|
2021-01-17 10:28:54 -05:00
|
|
|
declare class Location {
|
|
|
|
constructor();
|
|
|
|
/** Returns a DOMStringList object listing the origins of the ancestor
|
|
|
|
* browsing contexts, from the parent browsing context to the top-level
|
|
|
|
* browsing context.
|
|
|
|
*
|
|
|
|
* Always empty in Deno. */
|
|
|
|
readonly ancestorOrigins: DOMStringList;
|
|
|
|
/** Returns the Location object's URL's fragment (includes leading "#" if
|
|
|
|
* non-empty).
|
|
|
|
*
|
|
|
|
* Cannot be set in Deno. */
|
|
|
|
hash: string;
|
|
|
|
/** Returns the Location object's URL's host and port (if different from the
|
|
|
|
* default port for the scheme).
|
|
|
|
*
|
|
|
|
* Cannot be set in Deno. */
|
|
|
|
host: string;
|
|
|
|
/** Returns the Location object's URL's host.
|
|
|
|
*
|
|
|
|
* Cannot be set in Deno. */
|
|
|
|
hostname: string;
|
|
|
|
/** Returns the Location object's URL.
|
|
|
|
*
|
|
|
|
* Cannot be set in Deno. */
|
|
|
|
href: string;
|
|
|
|
toString(): string;
|
|
|
|
/** Returns the Location object's URL's origin. */
|
|
|
|
readonly origin: string;
|
|
|
|
/** Returns the Location object's URL's path.
|
|
|
|
*
|
|
|
|
* Cannot be set in Deno. */
|
|
|
|
pathname: string;
|
|
|
|
/** Returns the Location object's URL's port.
|
|
|
|
*
|
|
|
|
* Cannot be set in Deno. */
|
|
|
|
port: string;
|
|
|
|
/** Returns the Location object's URL's scheme.
|
|
|
|
*
|
|
|
|
* Cannot be set in Deno. */
|
|
|
|
protocol: string;
|
|
|
|
/** Returns the Location object's URL's query (includes leading "?" if
|
|
|
|
* non-empty).
|
|
|
|
*
|
|
|
|
* Cannot be set in Deno. */
|
|
|
|
search: string;
|
|
|
|
/** Navigates to the given URL.
|
|
|
|
*
|
|
|
|
* Cannot be set in Deno. */
|
|
|
|
assign(url: string): void;
|
|
|
|
/** Reloads the current page.
|
|
|
|
*
|
|
|
|
* Disabled in Deno. */
|
|
|
|
reload(): void;
|
|
|
|
/** @deprecated */
|
|
|
|
reload(forcedReload: boolean): void;
|
|
|
|
/** Removes the current page from the session history and navigates to the
|
|
|
|
* given URL.
|
|
|
|
*
|
|
|
|
* Disabled in Deno. */
|
|
|
|
replace(url: string): void;
|
|
|
|
}
|
|
|
|
|
2021-04-30 15:51:48 -04:00
|
|
|
// TODO(nayeemrmn): Move this to `extensions/web` where its implementation is.
|
2021-01-17 10:28:54 -05:00
|
|
|
// The types there must first be split into window, worker and global types.
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web APIs */
|
2021-01-17 10:28:54 -05:00
|
|
|
declare var location: Location;
|