forked from facebook/flow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdom.js
More file actions
4469 lines (4094 loc) · 190 KB
/
dom.js
File metadata and controls
4469 lines (4094 loc) · 190 KB
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Modifications Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at http://www.apache.org/licenses/LICENSE-2.0
* THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
* WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
* MERCHANTABLITY OR NON-INFRINGEMENT.
* See the Apache Version 2.0 License for specific language governing permissions
* and limitations under the License.
*
* Portions copyright (c) World Wide Web Consortium, (Massachusetts Institute
* of Technology, European Research Consortium for Informatics and Mathematics,
* Keio University, Beihang). All Rights Reserved. This work is distributed
* under the W3C Software and Document License [1] in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* [1] http://www.w3.org/Consortium/Legal/copyright-software
*
* @flow
*/
// @lint-ignore-every LICENSELINT
/* Files */
declare class Blob {
constructor(blobParts?: Array<any>, options?: {
type?: string,
endings?: string,
...
}): void;
isClosed: boolean;
size: number;
type: string;
close(): void;
slice(start?: number, end?: number, contentType?: string): Blob;
arrayBuffer(): Promise<ArrayBuffer>;
text(): Promise<string>,
stream(): ReadableStream,
}
declare class FileReader extends EventTarget {
+EMPTY: 0;
+LOADING: 1;
+DONE: 2;
+error: null | DOMError;
+readyState: 0 | 1 | 2;
+result: null | string | ArrayBuffer;
abort(): void;
onabort: null | (ev: ProgressEvent) => any;
onerror: null | (ev: ProgressEvent) => any;
onload: null | (ev: ProgressEvent) => any;
onloadend: null | (ev: ProgressEvent) => any;
onloadstart: null | (ev: ProgressEvent) => any;
onprogress: null | (ev: ProgressEvent) => any;
readAsArrayBuffer(blob: Blob): void;
readAsBinaryString(blob: Blob): void;
readAsDataURL(blob: Blob): void;
readAsText(blob: Blob, encoding?: string): void;
}
declare type FilePropertyBag = {
type?: string,
lastModified?: number,
...
};
declare class File extends Blob {
constructor(
fileBits: $ReadOnlyArray<string | BufferDataSource | Blob>,
filename: string,
options?: FilePropertyBag,
): void;
lastModified: number;
name: string;
}
declare class FileList {
@@iterator(): Iterator<File>;
length: number;
item(index: number): File;
[index: number]: File;
}
/* DataTransfer */
declare class DataTransfer {
clearData(format?: string): void;
getData(format: string): string;
setData(format: string, data: string): void;
setDragImage(image: Element, x: number, y: number): void;
dropEffect: string;
effectAllowed: string;
files: FileList; // readonly
items: DataTransferItemList; // readonly
types: Array<string>; // readonly
}
declare class DataTransferItemList {
@@iterator(): Iterator<DataTransferItem>;
length: number; // readonly
[index: number]: DataTransferItem;
add(data: string, type: string): ?DataTransferItem;
add(data: File): ?DataTransferItem;
remove(index: number): void;
clear(): void;
};
declare class DataTransferItem {
kind: string; // readonly
type: string; // readonly
getAsString(_callback: ?(data: string) => mixed): void;
getAsFile(): ?File;
/*
* This is not supported by all browsers, please have a fallback plan for it.
* For more information, please checkout
* https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/webkitGetAsEntry
*/
webkitGetAsEntry(): void | () => any;
};
/* DOM */
declare type DOMStringMap = { [key:string]: string, ... }
declare class DOMStringList {
+[key:number]: string;
+length: number;
item(number): string | null;
contains(string): boolean;
}
declare class DOMError {
name: string;
}
declare type ElementDefinitionOptions = { extends?: string, ... }
declare interface CustomElementRegistry {
define(name: string, ctor: Class<Element>, options?: ElementDefinitionOptions): void;
get(name: string): any;
whenDefined(name: string): Promise<void>;
}
declare interface ShadowRoot extends DocumentFragment {
+delegatesFocus: boolean;
+host: Element;
// flowlint unsafe-getters-setters:off
get innerHTML(): string;
set innerHTML(value: string | TrustedHTML): void;
// flowlint unsafe-getters-setters:error
+mode: ShadowRootMode;
// From DocumentOrShadowRoot Mixin.
+styleSheets: StyleSheetList;
adoptedStyleSheets: Array<CSSStyleSheet>;
}
declare type ShadowRootMode = 'open'|'closed';
declare type ShadowRootInit = {
delegatesFocus?: boolean,
mode: ShadowRootMode,
...
}
declare type ScrollToOptions = {
top?: number;
left?: number;
behavior?: 'auto' | 'smooth';
...
}
type EventHandler = (event: Event) => mixed
type EventListener = { handleEvent: EventHandler, ... } | EventHandler
type MouseEventHandler = (event: MouseEvent) => mixed
type MouseEventListener = { handleEvent: MouseEventHandler, ... } | MouseEventHandler
type FocusEventHandler = (event: FocusEvent) => mixed
type FocusEventListener = { handleEvent: FocusEventHandler, ... } | FocusEventHandler
type KeyboardEventHandler = (event: KeyboardEvent) => mixed
type KeyboardEventListener = { handleEvent: KeyboardEventHandler, ... } | KeyboardEventHandler
type InputEventHandler = (event: InputEvent) => mixed
type InputEventListener = { handleEvent: InputEventHandler, ... } | InputEventHandler
type TouchEventHandler = (event: TouchEvent) => mixed
type TouchEventListener = { handleEvent: TouchEventHandler, ... } | TouchEventHandler
type WheelEventHandler = (event: WheelEvent) => mixed
type WheelEventListener = { handleEvent: WheelEventHandler, ... } | WheelEventHandler
type AbortProgressEventHandler = (event: ProgressEvent) => mixed
type AbortProgressEventListener = { handleEvent: AbortProgressEventHandler, ... } | AbortProgressEventHandler
type ProgressEventHandler = (event: ProgressEvent) => mixed
type ProgressEventListener = { handleEvent: ProgressEventHandler, ... } | ProgressEventHandler
type DragEventHandler = (event: DragEvent) => mixed
type DragEventListener = { handleEvent: DragEventHandler, ... } | DragEventHandler
type PointerEventHandler = (event: PointerEvent) => mixed
type PointerEventListener = { handleEvent: PointerEventHandler, ... } | PointerEventHandler
type AnimationEventHandler = (event: AnimationEvent) => mixed
type AnimationEventListener = { handleEvent: AnimationEventHandler, ... } | AnimationEventHandler
type ClipboardEventHandler = (event: ClipboardEvent) => mixed
type ClipboardEventListener = { handleEvent: ClipboardEventHandler, ... } | ClipboardEventHandler
type TransitionEventHandler = (event: TransitionEvent) => mixed
type TransitionEventListener = { handleEvent: TransitionEventHandler, ... } | TransitionEventHandler
type MessageEventHandler = (event: MessageEvent) => mixed
type MessageEventListener = { handleEvent: MessageEventHandler, ... } | MessageEventHandler
type BeforeUnloadEventHandler = (event: BeforeUnloadEvent) => mixed
type BeforeUnloadEventListener = { handleEvent: BeforeUnloadEventHandler, ... } | BeforeUnloadEventHandler
type StorageEventHandler = (event: StorageEvent) => mixed
type StorageEventListener = { handleEvent: StorageEventHandler, ... } | StorageEventHandler
type MediaKeySessionType = 'temporary' | 'persistent-license';
type MediaKeyStatus = 'usable' | 'expired' | 'released' | 'output-restricted' | 'output-downscaled' | 'status-pending' | 'internal-error';
type MouseEventTypes = 'contextmenu' | 'mousedown' | 'mouseenter' | 'mouseleave' | 'mousemove' | 'mouseout' | 'mouseover' | 'mouseup' | 'click' | 'dblclick';
type FocusEventTypes = 'blur' | 'focus' | 'focusin' | 'focusout';
type KeyboardEventTypes = 'keydown' | 'keyup' | 'keypress';
type InputEventTypes = 'input' | 'beforeinput'
type TouchEventTypes = 'touchstart' | 'touchmove' | 'touchend' | 'touchcancel';
type WheelEventTypes = 'wheel';
type AbortProgressEventTypes = 'abort';
type ProgressEventTypes = 'abort' | 'error' | 'load' | 'loadend' | 'loadstart' | 'progress' | 'timeout';
type DragEventTypes = 'drag' | 'dragend' | 'dragenter' | 'dragexit' | 'dragleave' | 'dragover' | 'dragstart' | 'drop';
type PointerEventTypes = 'pointerover' | 'pointerenter' | 'pointerdown' | 'pointermove' | 'pointerup' | 'pointercancel' | 'pointerout' | 'pointerleave' | 'gotpointercapture' | 'lostpointercapture';
type AnimationEventTypes = 'animationstart' | 'animationend' | 'animationiteration';
type ClipboardEventTypes = 'clipboardchange' | 'cut' | 'copy' | 'paste';
type TransitionEventTypes = 'transitionrun' | 'transitionstart' | 'transitionend' | 'transitioncancel';
type MessageEventTypes = string;
type BeforeUnloadEventTypes = 'beforeunload';
type StorageEventTypes = 'storage';
type EventListenerOptionsOrUseCapture = boolean | {
capture?: boolean,
once?: boolean,
passive?: boolean,
...
};
declare class EventTarget {
addEventListener(type: MouseEventTypes, listener: MouseEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
addEventListener(type: FocusEventTypes, listener: FocusEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
addEventListener(type: KeyboardEventTypes, listener: KeyboardEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
addEventListener(type: InputEventTypes, listener: InputEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
addEventListener(type: TouchEventTypes, listener: TouchEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
addEventListener(type: WheelEventTypes, listener: WheelEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
addEventListener(type: AbortProgressEventTypes, listener: AbortProgressEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
addEventListener(type: ProgressEventTypes, listener: ProgressEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
addEventListener(type: DragEventTypes, listener: DragEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
addEventListener(type: PointerEventTypes, listener: PointerEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
addEventListener(type: AnimationEventTypes, listener: AnimationEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
addEventListener(type: ClipboardEventTypes, listener: ClipboardEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
addEventListener(type: TransitionEventTypes, listener: TransitionEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
addEventListener(type: MessageEventTypes, listener: MessageEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
addEventListener(type: BeforeUnloadEventTypes, listener: BeforeUnloadEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
addEventListener(type: StorageEventTypes, listener: StorageEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
addEventListener(type: string, listener: EventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: MouseEventTypes, listener: MouseEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: FocusEventTypes, listener: FocusEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: KeyboardEventTypes, listener: KeyboardEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: InputEventTypes, listener: InputEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: TouchEventTypes, listener: TouchEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: WheelEventTypes, listener: WheelEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: AbortProgressEventTypes, listener: AbortProgressEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: ProgressEventTypes, listener: ProgressEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: DragEventTypes, listener: DragEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: PointerEventTypes, listener: PointerEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: AnimationEventTypes, listener: AnimationEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: ClipboardEventTypes, listener: ClipboardEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: TransitionEventTypes, listener: TransitionEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: MessageEventTypes, listener: MessageEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: BeforeUnloadEventTypes, listener: BeforeUnloadEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: StorageEventTypes, listener: StorageEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
removeEventListener(type: string, listener: EventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
attachEvent?: (type: MouseEventTypes, listener: MouseEventListener) => void;
attachEvent?: (type: FocusEventTypes, listener: FocusEventListener) => void;
attachEvent?: (type: KeyboardEventTypes, listener: KeyboardEventListener) => void;
attachEvent?: (type: InputEventTypes, listener: InputEventListener) => void;
attachEvent?: (type: TouchEventTypes, listener: TouchEventListener) => void;
attachEvent?: (type: WheelEventTypes, listener: WheelEventListener) => void;
attachEvent?: (type: AbortProgressEventTypes, listener: AbortProgressEventListener) => void;
attachEvent?: (type: ProgressEventTypes, listener: ProgressEventListener) => void;
attachEvent?: (type: DragEventTypes, listener: DragEventListener) => void;
attachEvent?: (type: PointerEventTypes, listener: PointerEventListener) => void;
attachEvent?: (type: AnimationEventTypes, listener: AnimationEventListener) => void;
attachEvent?: (type: ClipboardEventTypes, listener: ClipboardEventListener) => void;
attachEvent?: (type: TransitionEventTypes, listener: TransitionEventListener) => void;
attachEvent?: (type: MessageEventTypes, listener: MessageEventListener) => void;
attachEvent?: (type: BeforeUnloadEventTypes, listener: BeforeUnloadEventListener) => void;
attachEvent?: (type: StorageEventTypes, listener: StorageEventListener) => void;
attachEvent?: (type: string, listener: EventListener) => void;
detachEvent?: (type: MouseEventTypes, listener: MouseEventListener) => void;
detachEvent?: (type: FocusEventTypes, listener: FocusEventListener) => void;
detachEvent?: (type: KeyboardEventTypes, listener: KeyboardEventListener) => void;
detachEvent?: (type: InputEventTypes, listener: InputEventListener) => void;
detachEvent?: (type: TouchEventTypes, listener: TouchEventListener) => void;
detachEvent?: (type: WheelEventTypes, listener: WheelEventListener) => void;
detachEvent?: (type: AbortProgressEventTypes, listener: AbortProgressEventListener) => void;
detachEvent?: (type: ProgressEventTypes, listener: ProgressEventListener) => void;
detachEvent?: (type: DragEventTypes, listener: DragEventListener) => void;
detachEvent?: (type: PointerEventTypes, listener: PointerEventListener) => void;
detachEvent?: (type: AnimationEventTypes, listener: AnimationEventListener) => void;
detachEvent?: (type: ClipboardEventTypes, listener: ClipboardEventListener) => void;
detachEvent?: (type: TransitionEventTypes, listener: TransitionEventListener) => void;
detachEvent?: (type: MessageEventTypes, listener: MessageEventListener) => void;
detachEvent?: (type: BeforeUnloadEventTypes, listener: BeforeUnloadEventListener) => void;
detachEvent?: (type: StorageEventTypes, listener: StorageEventListener) => void;
detachEvent?: (type: string, listener: EventListener) => void;
dispatchEvent(evt: Event): boolean;
// Deprecated
cancelBubble: boolean;
initEvent(eventTypeArg: string, canBubbleArg: boolean, cancelableArg: boolean): void;
}
// https://dom.spec.whatwg.org/#dictdef-eventinit
type Event$Init = {
bubbles?: boolean,
cancelable?: boolean,
composed?: boolean,
/** Non-standard. See `composed` instead. */
scoped?: boolean,
...
}
// https://dom.spec.whatwg.org/#interface-event
declare class Event {
constructor(type: string, eventInitDict?: Event$Init): void;
/**
* Returns the type of event, e.g. "click", "hashchange", or "submit".
*/
+type: string;
/**
* Returns the object to which event is dispatched (its target).
*/
+target: EventTarget; // TODO: nullable
/** @deprecated */
+srcElement: Element; // TODO: nullable
/**
* Returns the object whose event listener's callback is currently being invoked.
*/
+currentTarget: EventTarget; // TODO: nullable
/**
* Returns the invocation target objects of event's path (objects on which
* listeners will be invoked), except for any nodes in shadow trees of which
* the shadow root's mode is "closed" that are not reachable from event's
* currentTarget.
*/
composedPath(): Array<EventTarget>;
+NONE: number;
+AT_TARGET: number;
+BUBBLING_PHASE: number;
+CAPTURING_PHASE: number;
/**
* Returns the event's phase, which is one of NONE, CAPTURING_PHASE, AT_TARGET,
* and BUBBLING_PHASE.
*/
+eventPhase: number;
/**
* When dispatched in a tree, invoking this method prevents event from reaching
* any objects other than the current object.
*/
stopPropagation(): void;
/**
* Invoking this method prevents event from reaching any registered event
* listeners after the current one finishes running and, when dispatched in a
* tree, also prevents event from reaching any other objects.
*/
stopImmediatePropagation(): void;
/**
* Returns true or false depending on how event was initialized. True if
* event goes through its target's ancestors in reverse tree order, and
* false otherwise.
*/
+bubbles: boolean;
/**
* Returns true or false depending on how event was initialized. Its
* return value does not always carry meaning, but true can indicate
* that part of the operation during which event was dispatched, can
* be canceled by invoking the preventDefault() method.
*/
+cancelable: boolean;
// returnValue: boolean; // legacy, and some subclasses still define it as a string!
/**
* If invoked when the cancelable attribute value is true, and while
* executing a listener for the event with passive set to false, signals to
* the operation that caused event to be dispatched that it needs to be
* canceled.
*/
preventDefault(): void;
/**
* Returns true if preventDefault() was invoked successfully to indicate
* cancelation, and false otherwise.
*/
+defaultPrevented: boolean;
/**
* Returns true or false depending on how event was initialized. True if
* event invokes listeners past a ShadowRoot node that is the root of its
* target, and false otherwise.
*/
+composed: boolean;
/**
* Returns true if event was dispatched by the user agent, and false otherwise.
*/
+isTrusted: boolean;
/**
* Returns the event's timestamp as the number of milliseconds measured relative
* to the time origin.
*/
+timeStamp: number;
/** Non-standard. See Event.prototype.composedPath */
+deepPath?: () => EventTarget[];
/** Non-standard. See Event.prototype.composed */
+scoped: boolean;
/**
* @deprecated
*/
initEvent(
type: string,
bubbles: boolean,
cancelable: boolean
): void;
}
type CustomEvent$Init = { ...Event$Init, detail?: any, ... }
declare class CustomEvent extends Event {
constructor(type: string, eventInitDict?: CustomEvent$Init): void;
detail: any;
// deprecated
initCustomEvent(
type: string,
bubbles: boolean,
cancelable: boolean,
detail: any
): CustomEvent;
}
type UIEvent$Init = { ...Event$Init, detail?: number, view?: any, ... }
declare class UIEvent extends Event {
constructor(typeArg: string, uiEventInit?: UIEvent$Init): void;
detail: number;
view: any;
}
declare class CompositionEvent extends UIEvent {
data: string | null;
locale: string,
}
type MouseEvent$MouseEventInit = {
screenX?: number,
screenY?: number,
clientX?: number,
clientY?: number,
ctrlKey?: boolean,
shiftKey?: boolean,
altKey?: boolean,
metaKey?: boolean,
button?: number,
buttons?: number,
region?: string | null,
relatedTarget?: EventTarget | null,
...
};
declare class MouseEvent extends UIEvent {
constructor(
typeArg: string,
mouseEventInit?: MouseEvent$MouseEventInit,
): void;
altKey: boolean;
button: number;
buttons: number;
clientX: number;
clientY: number;
ctrlKey: boolean;
metaKey: boolean;
movementX: number;
movementY: number;
offsetX: number;
offsetY: number;
pageX: number;
pageY: number;
region: string | null;
relatedTarget: EventTarget | null;
screenX: number;
screenY: number;
shiftKey: boolean;
x: number;
y: number;
getModifierState(keyArg: string): boolean;
}
declare class FocusEvent extends UIEvent {
relatedTarget: ?EventTarget;
}
type WheelEvent$Init = {
...MouseEvent$MouseEventInit,
deltaX?: number,
deltaY?: number,
deltaZ?: number;
deltaMode?: 0x00 | 0x01 | 0x02,
...
}
declare class WheelEvent extends MouseEvent {
static +DOM_DELTA_PIXEL: 0x00;
static +DOM_DELTA_LINE: 0x01;
static +DOM_DELTA_PAGE: 0x02;
constructor(type: string, eventInitDict?: WheelEvent$Init): void;
+deltaX: number;
+deltaY: number;
+deltaZ: number;
+deltaMode: 0x00 | 0x01 | 0x02;
}
declare class DragEvent extends MouseEvent {
dataTransfer: ?DataTransfer; // readonly
}
type PointerEvent$PointerEventInit = MouseEvent$MouseEventInit & {
pointerId?: number,
width?: number,
height?: number,
pressure?: number,
tangentialPressure?: number,
tiltX?: number,
tiltY?: number,
twist?: number,
pointerType?: string,
isPrimary?: boolean,
...
};
declare class PointerEvent extends MouseEvent {
constructor(
typeArg: string,
pointerEventInit?: PointerEvent$PointerEventInit,
): void;
pointerId: number;
width: number;
height: number;
pressure: number;
tangentialPressure: number;
tiltX: number;
tiltY: number;
twist: number;
pointerType: string;
isPrimary: boolean;
}
declare class ProgressEvent extends Event {
lengthComputable: boolean;
loaded: number;
total: number;
// Deprecated
initProgressEvent(
typeArg: string,
canBubbleArg: boolean,
cancelableArg: boolean,
lengthComputableArg: boolean,
loadedArg: number,
totalArg: number
): void;
}
declare class PromiseRejectionEvent extends Event {
promise: Promise<any>;
reason: any;
}
type PageTransitionEventInit = {
...Event$Init,
persisted: boolean,
...
}
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#the-pagetransitionevent-interface
declare class PageTransitionEvent extends Event {
constructor(type: string, init?: PageTransitionEventInit): void;
+persisted: boolean;
}
// used for websockets and postMessage, for example. See:
// https://www.w3.org/TR/2011/WD-websockets-20110419/
// and
// https://www.w3.org/TR/2008/WD-html5-20080610/comms.html
// and
// https://html.spec.whatwg.org/multipage/comms.html#the-messageevent-interfaces
declare class MessageEvent extends Event {
data: mixed;
origin: string;
lastEventId: string;
source: WindowProxy;
}
// https://www.w3.org/TR/eventsource/
declare class EventSource extends EventTarget {
constructor(url: string, configuration?: { withCredentials: boolean, ... }): void;
+CLOSED: 2;
+CONNECTING: 0;
+OPEN: 1;
+readyState: 0 | 1 | 2;
+url: string;
+withCredentials: boolean;
onerror: () => void;
onmessage: MessageEventListener;
onopen: () => void;
close: () => void;
}
// https://w3c.github.io/uievents/#idl-keyboardeventinit
type KeyboardEvent$Init = {
...UIEvent$Init,
/**
* Initializes the `key` attribute of the KeyboardEvent object to the unicode
* character string representing the meaning of a key after taking into
* account all keyboard modifiers (such as shift-state). This value is the
* final effective value of the key. If the key is not a printable character,
* then it should be one of the key values defined in [UIEvents-Key](https://www.w3.org/TR/uievents-key/).
*
* NOTE: not `null`, this results in `evt.key === 'null'`!
*/
key?: string | void,
/**
* Initializes the `code` attribute of the KeyboardEvent object to the unicode
* character string representing the key that was pressed, ignoring any
* keyboard modifications such as keyboard layout. This value should be one
* of the code values defined in [UIEvents-Code](https://www.w3.org/TR/uievents-code/).
*
* NOTE: not `null`, this results in `evt.code === 'null'`!
*/
code?: string | void,
/**
* Initializes the `location` attribute of the KeyboardEvent object to one of
* the following location numerical constants:
*
* DOM_KEY_LOCATION_STANDARD (numerical value 0)
* DOM_KEY_LOCATION_LEFT (numerical value 1)
* DOM_KEY_LOCATION_RIGHT (numerical value 2)
* DOM_KEY_LOCATION_NUMPAD (numerical value 3)
*/
location?: number,
/**
* Initializes the `ctrlKey` attribute of the KeyboardEvent object to true if
* the Control key modifier is to be considered active, false otherwise.
*/
ctrlKey?: boolean,
/**
* Initializes the `shiftKey` attribute of the KeyboardEvent object to true if
* the Shift key modifier is to be considered active, false otherwise.
*/
shiftKey?: boolean,
/**
* Initializes the `altKey` attribute of the KeyboardEvent object to true if
* the Alt (alternative) (or Option) key modifier is to be considered active,
* false otherwise.
*/
altKey?: boolean,
/**
* Initializes the `metaKey` attribute of the KeyboardEvent object to true if
* the Meta key modifier is to be considered active, false otherwise.
*/
metaKey?: boolean,
/**
* Initializes the `repeat` attribute of the KeyboardEvent object. This
* attribute should be set to true if the the current KeyboardEvent is
* considered part of a repeating sequence of similar events caused by the
* long depression of any single key, false otherwise.
*/
repeat?: boolean,
/**
* Initializes the `isComposing` attribute of the KeyboardEvent object. This
* attribute should be set to true if the event being constructed occurs as
* part of a composition sequence, false otherwise.
*/
isComposing?: boolean,
/**
* Initializes the `charCode` attribute of the KeyboardEvent to the Unicode
* code point for the event’s character.
*/
charCode?: number,
/**
* Initializes the `keyCode` attribute of the KeyboardEvent to the system-
* and implementation-dependent numerical code signifying the unmodified
* identifier associated with the key pressed.
*/
keyCode?: number,
/** Initializes the `which` attribute */
which?: number,
...
}
// https://w3c.github.io/uievents/#idl-keyboardevent
declare class KeyboardEvent extends UIEvent {
constructor(typeArg: string, init?: KeyboardEvent$Init): void;
/** `true` if the Alt (alternative) (or "Option") key modifier was active. */
+altKey: boolean;
/**
* Holds a string that identifies the physical key being pressed. The value
* is not affected by the current keyboard layout or modifier state, so a
* particular key will always return the same value.
*/
+code: string;
/** `true` if the Control (control) key modifier was active. */
+ctrlKey: boolean;
/**
* `true` if the key event occurs as part of a composition session, i.e.,
* after a `compositionstart` event and before the corresponding
* `compositionend` event.
*/
+isComposing: boolean;
/**
* Holds a [key attribute value](https://www.w3.org/TR/uievents-key/#key-attribute-value)
* corresponding to the key pressed. */
+key: string;
/** An indication of the logical location of the key on the device. */
+location: number;
/** `true` if the meta (Meta) key (or "Command") modifier was active. */
+metaKey: boolean;
/** `true` if the key has been pressed in a sustained manner. */
+repeat: boolean;
/** `true` if the shift (Shift) key modifier was active. */
+shiftKey: boolean;
/**
* Queries the state of a modifier using a key value.
*
* Returns `true` if it is a modifier key and the modifier is activated,
* `false` otherwise.
*/
getModifierState(keyArg?: string): boolean;
/**
* Holds a character value, for keypress events which generate character
* input. The value is the Unicode reference number (code point) of that
* character (e.g. event.charCode = event.key.charCodeAt(0) for printable
* characters). For keydown or keyup events, the value of charCode is 0.
*
* @deprecated You should use KeyboardEvent.key instead, if available.
*/
+charCode: number;
/**
* Holds a system- and implementation-dependent numerical code signifying
* the unmodified identifier associated with the key pressed. Unlike the
* `key` attribute, the set of possible values are not normatively defined.
* Typically, these value of the keyCode SHOULD represent the decimal
* codepoint in ASCII or Windows 1252, but MAY be drawn from a different
* appropriate character set. Implementations that are unable to identify
* a key use the key value 0.
*
* @deprecated You should use KeyboardEvent.key instead, if available.
*/
+keyCode: number;
/**
* Holds a system- and implementation-dependent numerical code signifying
* the unmodified identifier associated with the key pressed. In most cases,
* the value is identical to keyCode.
*
* @deprecated You should use KeyboardEvent.key instead, if available.
*/
+which: number;
}
type InputEvent$Init = {
...UIEvent$Init,
inputType?: string,
data?: string,
dataTransfer?: DataTransfer,
isComposing?: boolean,
ranges?: Array<any>, // TODO: StaticRange
...
}
declare class InputEvent extends UIEvent {
constructor(typeArg: string, inputEventInit: InputEvent$Init): void;
+data: string | null;
+dataTransfer: DataTransfer | null;
+inputType: string;
+isComposing: boolean;
getTargetRanges(): Array<any>; // TODO: StaticRange
}
declare class AnimationEvent extends Event {
animationName: string;
elapsedTime: number;
pseudoElement: string;
// deprecated
initAnimationEvent: (
type: 'animationstart' | 'animationend' | 'animationiteration',
canBubble: boolean,
cancelable: boolean,
animationName: string,
elapsedTime: number
) => void;
}
// https://html.spec.whatwg.org/multipage/webappapis.html#the-errorevent-interface
declare class ErrorEvent extends Event {
constructor(
type: string,
eventInitDict?: {
...Event$Init,
message?: string,
filename?: string,
lineno?: number,
colno?: number,
error?: any,
...
},
): void;
+message: string;
+filename: string;
+lineno: number;
+colno: number;
+error: any;
}
// https://html.spec.whatwg.org/multipage/web-messaging.html#broadcasting-to-other-browsing-contexts
declare class BroadcastChannel extends EventTarget {
name: string;
onmessage: ?(event: MessageEvent) => void;
onmessageerror: ?(event: MessageEvent) => void;
constructor(name: string): void;
postMessage(msg: mixed): void;
close(): void;
}
// https://www.w3.org/TR/touch-events/#idl-def-Touch
declare class Touch {
clientX: number,
clientY: number,
identifier: number,
pageX: number,
pageY: number,
screenX: number,
screenY: number,
target: EventTarget,
}
// https://www.w3.org/TR/touch-events/#idl-def-TouchList
// TouchList#item(index) will return null if n > #length. Should #item's
// return type just been Touch?
declare class TouchList {
@@iterator(): Iterator<Touch>;
length: number,
item(index: number): null | Touch,
[index: number]: Touch,
}
// https://www.w3.org/TR/touch-events/#touchevent-interface
declare class TouchEvent extends UIEvent {
altKey: boolean,
changedTouches: TouchList,
ctrlKey: boolean,
metaKey: boolean,
shiftKey: boolean,
targetTouches: TouchList,
touches: TouchList,
}
// https://www.w3.org/TR/webstorage/#the-storageevent-interface
declare class StorageEvent extends Event {
key: ?string,
oldValue: ?string,
newValue: ?string,
url: string,
storageArea: ?Storage,
}
type ClipboardItemData = string | Blob;
type PresentationStyle = "attachment" | "inline" | "unspecified";
type ClipboardItemOptions = {
presentationStyle?: PresentationStyle;
...
}
declare class ClipboardItem {
+types: $ReadOnlyArray<string>;
getType(type: string): Promise<Blob>;
constructor(items: {[type: string]: ClipboardItemData}, options?: ClipboardItemOptions): void;
}
// https://w3c.github.io/clipboard-apis/ as of 15 May 2018
type ClipboardEvent$Init = {
...Event$Init,
clipboardData: DataTransfer | null,
...
};
declare class ClipboardEvent extends Event {
constructor(type: ClipboardEventTypes, eventInit?: ClipboardEvent$Init): void;
+clipboardData: ?DataTransfer; // readonly
}
// https://www.w3.org/TR/2017/WD-css-transitions-1-20171130/#interface-transitionevent
type TransitionEvent$Init = {
...Event$Init,
propertyName: string,
elapsedTime: number,
pseudoElement: string,
...
};
declare class TransitionEvent extends Event {
constructor(type: TransitionEventTypes, eventInit?: TransitionEvent$Init): void;
+propertyName: string; // readonly
+elapsedTime: number; // readonly
+pseudoElement: string; // readonly
}
// https://www.w3.org/TR/html50/browsers.html#beforeunloadevent
declare class BeforeUnloadEvent extends Event {
returnValue: string,
}
// TODO: *Event
declare class Node extends EventTarget {
baseURI: ?string;
childNodes: NodeList<Node>;
firstChild: ?Node;
+isConnected: boolean;
lastChild: ?Node;
nextSibling: ?Node;
nodeName: string;
nodeType: number;
nodeValue: string;
ownerDocument: Document;
parentElement: ?Element;
parentNode: ?Node;
previousSibling: ?Node;
rootNode: Node;
textContent: string;
appendChild<T: Node>(newChild: T): T;
cloneNode(deep?: boolean): this;
compareDocumentPosition(other: Node): number;
contains(other: ?Node): boolean;
getRootNode(options?: { composed: boolean, ... }): Node;
hasChildNodes(): boolean;
insertBefore<T: Node>(newChild: T, refChild?: ?Node): T;
isDefaultNamespace(namespaceURI: string): boolean;
isEqualNode(arg: Node): boolean;
isSameNode(other: Node): boolean;
lookupNamespaceURI(prefix: string): string;
lookupPrefix(namespaceURI: string): string;
normalize(): void;
removeChild<T: Node>(oldChild: T): T;
replaceChild<T: Node>(newChild: Node, oldChild: T): T;
static ATTRIBUTE_NODE: number;
static CDATA_SECTION_NODE: number;
static COMMENT_NODE: number;
static DOCUMENT_FRAGMENT_NODE: number;
static DOCUMENT_NODE: number;
static DOCUMENT_POSITION_CONTAINED_BY: number;
static DOCUMENT_POSITION_CONTAINS: number;
static DOCUMENT_POSITION_DISCONNECTED: number;
static DOCUMENT_POSITION_FOLLOWING: number;
static DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: number;
static DOCUMENT_POSITION_PRECEDING: number;
static DOCUMENT_TYPE_NODE: number;
static ELEMENT_NODE: number;
static ENTITY_NODE: number;
static ENTITY_REFERENCE_NODE: number;
static NOTATION_NODE: number;
static PROCESSING_INSTRUCTION_NODE: number;
static TEXT_NODE: number;
// Non-standard
innerText?: string;
outerText?: string;
}