1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | export declare function setErrorHandler(value: setErrorHandler.ErrorHandler | undefined): void;
|
8 | export declare namespace setErrorHandler {
|
9 | |
10 |
|
11 |
|
12 |
|
13 | type ErrorHandler = (error: Error) => void;
|
14 | }
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | export declare class EventTarget<TEventMap extends Record<string, Event> = Record<string, Event>, TMode extends "standard" | "strict" = "standard"> {
|
20 | |
21 |
|
22 |
|
23 | constructor();
|
24 | /**
|
25 | * Add an event listener.
|
26 | * @param type The event type.
|
27 | * @param callback The event listener.
|
28 | * @param options Options.
|
29 | */
|
30 | addEventListener<T extends string & keyof TEventMap>(type: T, callback?: EventTarget.EventListener<this, TEventMap[T]> | null, options?: EventTarget.AddOptions): void;
|
31 | /**
|
32 | * Add an event listener.
|
33 | * @param type The event type.
|
34 | * @param callback The event listener.
|
35 | * @param options Options.
|
36 | */
|
37 | addEventListener(type: string, callback?: EventTarget.FallbackEventListener<this, TMode>, options?: EventTarget.AddOptions): void;
|
38 | /**
|
39 | * Add an event listener.
|
40 | * @param type The event type.
|
41 | * @param callback The event listener.
|
42 | * @param capture The capture flag.
|
43 | * @deprecated Use `{capture: boolean}` object instead of a boolean value.
|
44 | */
|
45 | addEventListener<T extends string & keyof TEventMap>(type: T, callback: EventTarget.EventListener<this, TEventMap[T]> | null | undefined, capture: boolean): void;
|
46 | /**
|
47 | * Add an event listener.
|
48 | * @param type The event type.
|
49 | * @param callback The event listener.
|
50 | * @param capture The capture flag.
|
51 | * @deprecated Use `{capture: boolean}` object instead of a boolean value.
|
52 | */
|
53 | addEventListener(type: string, callback: EventTarget.FallbackEventListener<this, TMode>, capture: boolean): void;
|
54 | /**
|
55 | * Remove an added event listener.
|
56 | * @param type The event type.
|
57 | * @param callback The event listener.
|
58 | * @param options Options.
|
59 | */
|
60 | removeEventListener<T extends string & keyof TEventMap>(type: T, callback?: EventTarget.EventListener<this, TEventMap[T]> | null, options?: EventTarget.Options): void;
|
61 | /**
|
62 | * Remove an added event listener.
|
63 | * @param type The event type.
|
64 | * @param callback The event listener.
|
65 | * @param options Options.
|
66 | */
|
67 | removeEventListener(type: string, callback?: EventTarget.FallbackEventListener<this, TMode>, options?: EventTarget.Options): void;
|
68 | /**
|
69 | * Remove an added event listener.
|
70 | * @param type The event type.
|
71 | * @param callback The event listener.
|
72 | * @param capture The capture flag.
|
73 | * @deprecated Use `{capture: boolean}` object instead of a boolean value.
|
74 | */
|
75 | removeEventListener<T extends string & keyof TEventMap>(type: T, callback: EventTarget.EventListener<this, TEventMap[T]> | null | undefined, capture: boolean): void;
|
76 | /**
|
77 | * Remove an added event listener.
|
78 | * @param type The event type.
|
79 | * @param callback The event listener.
|
80 | * @param capture The capture flag.
|
81 | * @deprecated Use `{capture: boolean}` object instead of a boolean value.
|
82 | */
|
83 | removeEventListener(type: string, callback: EventTarget.FallbackEventListener<this, TMode>, capture: boolean): void;
|
84 | /**
|
85 | * Dispatch an event.
|
86 | * @param event The `Event` object to dispatch.
|
87 | */
|
88 | dispatchEvent<T extends string & keyof TEventMap>(event: EventTarget.EventData<TEventMap, TMode, T>): boolean;
|
89 | /**
|
90 | * Dispatch an event.
|
91 | * @param event The `Event` object to dispatch.
|
92 | */
|
93 | dispatchEvent(event: EventTarget.FallbackEvent<TMode>): boolean;
|
94 | }
|
95 | export declare namespace EventTarget {
|
96 | /**
|
97 | * The event listener.
|
98 | */
|
99 | type EventListener<TEventTarget extends EventTarget<any, any>, TEvent extends Event> = CallbackFunction<TEventTarget, TEvent> | CallbackObject<TEvent>;
|
100 | /**
|
101 | * The event listener function.
|
102 | */
|
103 | interface CallbackFunction<TEventTarget extends EventTarget<any, any>, TEvent extends Event> {
|
104 | (this: TEventTarget, event: TEvent): void;
|
105 | }
|
106 | /**
|
107 | * The event listener object.
|
108 | * @see https://dom.spec.whatwg.org/#callbackdef-eventlistener
|
109 | */
|
110 | interface CallbackObject<TEvent extends Event> {
|
111 | handleEvent(event: TEvent): void;
|
112 | }
|
113 | /**
|
114 | * The common options for both `addEventListener` and `removeEventListener` methods.
|
115 | * @see https://dom.spec.whatwg.org/#dictdef-eventlisteneroptions
|
116 | */
|
117 | interface Options {
|
118 | capture?: boolean;
|
119 | }
|
120 | /**
|
121 | * The options for the `addEventListener` methods.
|
122 | * @see https://dom.spec.whatwg.org/#dictdef-addeventlisteneroptions
|
123 | */
|
124 | interface AddOptions extends Options {
|
125 | passive?: boolean;
|
126 | once?: boolean;
|
127 | signal?: AbortSignal | null | undefined;
|
128 | }
|
129 | /**
|
130 | * The abort signal.
|
131 | * @see https://dom.spec.whatwg.org/#abortsignal
|
132 | */
|
133 | interface AbortSignal extends EventTarget<{
|
134 | abort: Event;
|
135 | }> {
|
136 | readonly aborted: boolean;
|
137 | onabort: CallbackFunction<this, Event> | null;
|
138 | }
|
139 | /**
|
140 | * The event data to dispatch in strict mode.
|
141 | */
|
142 | type EventData<TEventMap extends Record<string, Event>, TMode extends "standard" | "strict", TEventType extends string> = TMode extends "strict" ? IsValidEventMap<TEventMap> extends true ? ExplicitType<TEventType> & Omit<TEventMap[TEventType], keyof Event> & Partial<Omit<Event, "type">> : never : never;
|
143 | /**
|
144 | * Define explicit `type` property if `T` is a string literal.
|
145 | * Otherwise, never.
|
146 | */
|
147 | type ExplicitType<T extends string> = string extends T ? never : {
|
148 | readonly type: T;
|
149 | };
|
150 | /**
|
151 | * The event listener type in standard mode.
|
152 | * Otherwise, never.
|
153 | */
|
154 | type FallbackEventListener<TEventTarget extends EventTarget<any, any>, TMode extends "standard" | "strict"> = TMode extends "standard" ? EventListener<TEventTarget, Event> | null | undefined : never;
|
155 | /**
|
156 | * The event type in standard mode.
|
157 | * Otherwise, never.
|
158 | */
|
159 | type FallbackEvent<TMode extends "standard" | "strict"> = TMode extends "standard" ? Event : never;
|
160 | /**
|
161 | * Check if given event map is valid.
|
162 | * It's valid if the keys of the event map are narrower than `string`.
|
163 | */
|
164 | type IsValidEventMap<T> = string extends keyof T ? false : true;
|
165 | }
|
166 | /**
|
167 | * An implementation of `Event` interface, that wraps a given event object.
|
168 | * `EventTarget` shim can control the internal state of this `Event` objects.
|
169 | * @see https://dom.spec.whatwg.org/#event
|
170 | */
|
171 | export declare class Event<TEventType extends string = string> {
|
172 | /**
|
173 | * @see https://dom.spec.whatwg.org/#dom-event-none
|
174 | */
|
175 | static get NONE(): number;
|
176 | /**
|
177 | * @see https://dom.spec.whatwg.org/#dom-event-capturing_phase
|
178 | */
|
179 | static get CAPTURING_PHASE(): number;
|
180 | /**
|
181 | * @see https://dom.spec.whatwg.org/#dom-event-at_target
|
182 | */
|
183 | static get AT_TARGET(): number;
|
184 | /**
|
185 | * @see https://dom.spec.whatwg.org/#dom-event-bubbling_phase
|
186 | */
|
187 | static get BUBBLING_PHASE(): number;
|
188 | /**
|
189 | * Initialize this event instance.
|
190 | * @param type The type of this event.
|
191 | * @param eventInitDict Options to initialize.
|
192 | * @see https://dom.spec.whatwg.org/#dom-event-event
|
193 | */
|
194 | constructor(type: TEventType, eventInitDict?: Event.EventInit);
|
195 | /**
|
196 | * The type of this event.
|
197 | * @see https://dom.spec.whatwg.org/#dom-event-type
|
198 | */
|
199 | get type(): TEventType;
|
200 | /**
|
201 | * The event target of the current dispatching.
|
202 | * @see https://dom.spec.whatwg.org/#dom-event-target
|
203 | */
|
204 | get target(): EventTarget | null;
|
205 | /**
|
206 | * The event target of the current dispatching.
|
207 | * @deprecated Use the `target` property instead.
|
208 | * @see https://dom.spec.whatwg.org/#dom-event-srcelement
|
209 | */
|
210 | get srcElement(): EventTarget | null;
|
211 | /**
|
212 | * The event target of the current dispatching.
|
213 | * @see https://dom.spec.whatwg.org/#dom-event-currenttarget
|
214 | */
|
215 | get currentTarget(): EventTarget | null;
|
216 | /**
|
217 | * The event target of the current dispatching.
|
218 | * This doesn't support node tree.
|
219 | * @see https://dom.spec.whatwg.org/#dom-event-composedpath
|
220 | */
|
221 | composedPath(): EventTarget[];
|
222 | /**
|
223 | * @see https://dom.spec.whatwg.org/#dom-event-none
|
224 | */
|
225 | get NONE(): number;
|
226 | /**
|
227 | * @see https://dom.spec.whatwg.org/#dom-event-capturing_phase
|
228 | */
|
229 | get CAPTURING_PHASE(): number;
|
230 | /**
|
231 | * @see https://dom.spec.whatwg.org/#dom-event-at_target
|
232 | */
|
233 | get AT_TARGET(): number;
|
234 | /**
|
235 | * @see https://dom.spec.whatwg.org/#dom-event-bubbling_phase
|
236 | */
|
237 | get BUBBLING_PHASE(): number;
|
238 | /**
|
239 | * The current event phase.
|
240 | * @see https://dom.spec.whatwg.org/#dom-event-eventphase
|
241 | */
|
242 | get eventPhase(): number;
|
243 | /**
|
244 | * Stop event bubbling.
|
245 | * Because this shim doesn't support node tree, this merely changes the `cancelBubble` property value.
|
246 | * @see https://dom.spec.whatwg.org/#dom-event-stoppropagation
|
247 | */
|
248 | stopPropagation(): void;
|
249 | /**
|
250 | * `true` if event bubbling was stopped.
|
251 | * @deprecated
|
252 | * @see https://dom.spec.whatwg.org/#dom-event-cancelbubble
|
253 | */
|
254 | get cancelBubble(): boolean;
|
255 | /**
|
256 | * Stop event bubbling if `true` is set.
|
257 | * @deprecated Use the `stopPropagation()` method instead.
|
258 | * @see https://dom.spec.whatwg.org/#dom-event-cancelbubble
|
259 | */
|
260 | set cancelBubble(value: boolean);
|
261 | /**
|
262 | * Stop event bubbling and subsequent event listener callings.
|
263 | * @see https://dom.spec.whatwg.org/#dom-event-stopimmediatepropagation
|
264 | */
|
265 | stopImmediatePropagation(): void;
|
266 | /**
|
267 | * `true` if this event will bubble.
|
268 | * @see https://dom.spec.whatwg.org/#dom-event-bubbles
|
269 | */
|
270 | get bubbles(): boolean;
|
271 | /**
|
272 | * `true` if this event can be canceled by the `preventDefault()` method.
|
273 | * @see https://dom.spec.whatwg.org/#dom-event-cancelable
|
274 | */
|
275 | get cancelable(): boolean;
|
276 | /**
|
277 | * `true` if the default behavior will act.
|
278 | * @deprecated Use the `defaultPrevented` proeprty instead.
|
279 | * @see https://dom.spec.whatwg.org/#dom-event-returnvalue
|
280 | */
|
281 | get returnValue(): boolean;
|
282 | /**
|
283 | * Cancel the default behavior if `false` is set.
|
284 | * @deprecated Use the `preventDefault()` method instead.
|
285 | * @see https://dom.spec.whatwg.org/#dom-event-returnvalue
|
286 | */
|
287 | set returnValue(value: boolean);
|
288 | /**
|
289 | * Cancel the default behavior.
|
290 | * @see https://dom.spec.whatwg.org/#dom-event-preventdefault
|
291 | */
|
292 | preventDefault(): void;
|
293 | /**
|
294 | * `true` if the default behavior was canceled.
|
295 | * @see https://dom.spec.whatwg.org/#dom-event-defaultprevented
|
296 | */
|
297 | get defaultPrevented(): boolean;
|
298 | /**
|
299 | * @see https://dom.spec.whatwg.org/#dom-event-composed
|
300 | */
|
301 | get composed(): boolean;
|
302 | /**
|
303 | * @see https://dom.spec.whatwg.org/#dom-event-istrusted
|
304 | */
|
305 | get isTrusted(): boolean;
|
306 | /**
|
307 | * @see https://dom.spec.whatwg.org/#dom-event-timestamp
|
308 | */
|
309 | get timeStamp(): number;
|
310 | /**
|
311 | * @deprecated Don't use this method. The constructor did initialization.
|
312 | */
|
313 | initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void;
|
314 | }
|
315 | export declare namespace Event {
|
316 | /**
|
317 | * The options of the `Event` constructor.
|
318 | * @see https://dom.spec.whatwg.org/#dictdef-eventinit
|
319 | */
|
320 | interface EventInit {
|
321 | bubbles?: boolean;
|
322 | cancelable?: boolean;
|
323 | composed?: boolean;
|
324 | }
|
325 | }
|
326 | /**
|
327 | * Get the current value of a given event attribute.
|
328 | * @param target The `EventTarget` object to get.
|
329 | * @param type The event type.
|
330 | */
|
331 | export declare function getEventAttributeValue<TEventTarget extends EventTarget<any, any>, TEvent extends Event>(target: TEventTarget, type: string): EventTarget.CallbackFunction<TEventTarget, TEvent> | null;
|
332 | /**
|
333 | * Set an event listener to a given event attribute.
|
334 | * @param target The `EventTarget` object to set.
|
335 | * @param type The event type.
|
336 | * @param callback The event listener.
|
337 | */
|
338 | export declare function setEventAttributeValue(target: EventTarget<any, any>, type: string, callback: EventTarget.CallbackFunction<any, any> | null): void;
|
339 | /**
|
340 | * Define an `EventTarget` class that has event attibutes.
|
341 | * @param types The types to define event attributes.
|
342 | * @deprecated Use `getEventAttributeValue`/`setEventAttributeValue` pair on your derived class instead because of static analysis friendly.
|
343 | */
|
344 | export declare function defineCustomEventTarget<TEventMap extends Record<string, Event>, TMode extends "standard" | "strict" = "standard">(...types: (string & keyof TEventMap)[]): defineCustomEventTarget.CustomEventTargetConstructor<TEventMap, TMode>;
|
345 | export declare namespace defineCustomEventTarget {
|
346 | /**
|
347 | * The interface of CustomEventTarget constructor.
|
348 | */
|
349 | type CustomEventTargetConstructor<TEventMap extends Record<string, Event>, TMode extends "standard" | "strict"> = {
|
350 | /**
|
351 | * Create a new instance.
|
352 | */
|
353 | new (): CustomEventTarget<TEventMap, TMode>;
|
354 | /**
|
355 | * prototype object.
|
356 | */
|
357 | prototype: CustomEventTarget<TEventMap, TMode>;
|
358 | };
|
359 | /**
|
360 | * The interface of CustomEventTarget.
|
361 | */
|
362 | type CustomEventTarget<TEventMap extends Record<string, Event>, TMode extends "standard" | "strict"> = EventTarget<TEventMap, TMode> & defineEventAttribute.EventAttributes<any, TEventMap>;
|
363 | }
|
364 | /**
|
365 | * Define an event attribute.
|
366 | * @param target The `EventTarget` object to define an event attribute.
|
367 | * @param type The event type to define.
|
368 | * @param _eventClass Unused, but to infer `Event` class type.
|
369 | * @deprecated Use `getEventAttributeValue`/`setEventAttributeValue` pair on your derived class instead because of static analysis friendly.
|
370 | */
|
371 | export declare function defineEventAttribute<TEventTarget extends EventTarget, TEventType extends string, TEventConstrucor extends typeof Event>(target: TEventTarget, type: TEventType, _eventClass?: TEventConstrucor): asserts target is TEventTarget & defineEventAttribute.EventAttributes<TEventTarget, Record<TEventType, InstanceType<TEventConstrucor>>>;
|
372 | export declare namespace defineEventAttribute {
|
373 | /**
|
374 | * Definition of event attributes.
|
375 | */
|
376 | type EventAttributes<TEventTarget extends EventTarget<any, any>, TEventMap extends Record<string, Event>> = {
|
377 | [P in string & keyof TEventMap as `on${P}`]: EventTarget.CallbackFunction<TEventTarget, TEventMap[P]> | null;
|
378 | };
|
379 | }
|
380 | /**
|
381 | * Set the warning handler.
|
382 | * @param value The warning handler to set.
|
383 | */
|
384 | export declare function setWarningHandler(value: setWarningHandler.WarningHandler | undefined): void;
|
385 | export declare namespace setWarningHandler {
|
386 | /**
|
387 | * The warning information.
|
388 | */
|
389 | interface Warning {
|
390 | /**
|
391 | * The code of this warning.
|
392 | */
|
393 | code: string;
|
394 | /**
|
395 | * The message in English.
|
396 | */
|
397 | message: string;
|
398 | /**
|
399 | * The arguments for replacing placeholders in the text.
|
400 | */
|
401 | args: any[];
|
402 | }
|
403 | /**
|
404 | * The warning handler.
|
405 | * @param warning The warning.
|
406 | */
|
407 | type WarningHandler = (warning: Warning) => void;
|
408 | }
|
409 | export default EventTarget;
|
410 |
|
411 | export {};
|
412 |
|
\ | No newline at end of file |