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
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
/// <reference no-default-lib="true" />
/// <reference lib="deno.ns" />
/// <reference lib="deno.shared_globals" />
/// <reference lib="deno.webstorage" />
/// <reference lib="esnext" />
/// <reference lib="deno.cache" />
/** @category Platform */
interface WindowEventMap {
"error": ErrorEvent;
"unhandledrejection": PromiseRejectionEvent;
"rejectionhandled": PromiseRejectionEvent;
}
/** @category Platform */
interface Window extends EventTarget {
readonly window: Window & typeof globalThis;
readonly self: Window & typeof globalThis;
onerror: ((this: Window, ev: ErrorEvent) => any) | null;
onload: ((this: Window, ev: Event) => any) | null;
onbeforeunload: ((this: Window, ev: Event) => any) | null;
onunload: ((this: Window, ev: Event) => any) | null;
onunhandledrejection:
| ((this: Window, ev: PromiseRejectionEvent) => any)
| null;
onrejectionhandled:
| ((this: Window, ev: PromiseRejectionEvent) => any)
| null;
close: () => void;
readonly closed: boolean;
alert: (message?: string) => void;
confirm: (message?: string) => boolean;
prompt: (message?: string, defaultValue?: string) => string | null;
Deno: typeof Deno;
Navigator: typeof Navigator;
navigator: Navigator;
Location: typeof Location;
location: Location;
localStorage: Storage;
sessionStorage: Storage;
caches: CacheStorage;
name: string;
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;
}
/** @category Platform */
declare var Window: {
readonly prototype: Window;
new (): never;
};
/** @category Platform */
declare var window: Window & typeof globalThis;
/** @category Platform */
declare var self: Window & typeof globalThis;
/** @category Platform */
declare var closed: boolean;
/** @category Platform */
declare function close(): void;
/** @category Events */
declare var onerror: ((this: Window, ev: ErrorEvent) => any) | null;
/** @category Events */
declare var onload: ((this: Window, ev: Event) => any) | null;
/** @category Events */
declare var onbeforeunload: ((this: Window, ev: Event) => any) | null;
/** @category Events */
declare var onunload: ((this: Window, ev: Event) => any) | null;
/** @category Events */
declare var onunhandledrejection:
| ((this: Window, ev: PromiseRejectionEvent) => any)
| null;
/** @category Storage */
declare var localStorage: Storage;
/** @category Storage */
declare var sessionStorage: Storage;
/** @category Cache */
declare var caches: CacheStorage;
/** @category Platform */
interface Navigator {
readonly gpu: GPU;
readonly hardwareConcurrency: number;
readonly userAgent: string;
readonly language: string;
readonly languages: string[];
}
/** @category Platform */
declare var Navigator: {
readonly prototype: Navigator;
new (): never;
};
/** @category Platform */
declare var navigator: Navigator;
/**
* Shows the given message and waits for the enter key pressed.
*
* If the stdin is not interactive, it does nothing.
*
* @category Platform
*
* @param message
*/
declare function alert(message?: string): void;
/**
* Shows the given message and waits for the answer. Returns the user's answer as boolean.
*
* Only `y` and `Y` are considered as true.
*
* If the stdin is not interactive, it returns false.
*
* @category Platform
*
* @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.
*
* If the default value is given and the user inputs the empty string, then it returns the given
* default value.
*
* If the default value is not given and the user inputs the empty string, it returns the empty
* string.
*
* If the stdin is not interactive, it returns null.
*
* @category Platform
*
* @param message
* @param defaultValue
*/
declare function prompt(message?: string, defaultValue?: string): string | null;
/** Registers an event listener in the global scope, which will be called
* synchronously whenever the event `type` is dispatched.
*
* ```ts
* addEventListener('unload', () => { console.log('All finished!'); });
* ...
* dispatchEvent(new Event('unload'));
* ```
*
* @category Events
*/
declare function addEventListener<
K extends keyof WindowEventMap,
>(
type: K,
listener: (this: Window, ev: WindowEventMap[K]) => any,
options?: boolean | AddEventListenerOptions,
): void;
/** @category Events */
declare function addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
): void;
/** Remove a previously registered event listener from the global scope
*
* ```ts
* const listener = () => { console.log('hello'); };
* addEventListener('load', listener);
* removeEventListener('load', listener);
* ```
*
* @category Events
*/
declare function removeEventListener<
K extends keyof WindowEventMap,
>(
type: K,
listener: (this: Window, ev: WindowEventMap[K]) => any,
options?: boolean | EventListenerOptions,
): void;
/** @category Events */
declare function removeEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | EventListenerOptions,
): void;
// TODO(nayeemrmn): Move this to `extensions/web` where its implementation is.
// 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
* `globalThis.location`.
*
* @category Platform
*/
interface Location {
/** 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;
}
// TODO(nayeemrmn): Move this to `extensions/web` where its implementation is.
// 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
* `globalThis.location`.
*
* @category Platform
*/
declare var Location: {
readonly prototype: Location;
new (): never;
};
// TODO(nayeemrmn): Move this to `extensions/web` where its implementation is.
// The types there must first be split into window, worker and global types.
/** @category Platform */
declare var location: Location;
/** @category Platform */
declare var name: string;
|