UNPKG

react-native

Version:

A framework for building native apps using React

1,719 lines (1,618 loc) • 192 kB
/** * 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. * * @flow * @format * @oncall flow */ // Adapted from https://github.com/flow-typed/flow-typed/blob/main/definitions/environments/dom/flow_v0.261.x-/dom.js /* 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; } // https://wicg.github.io/file-system-access/#drag-and-drop 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 { @@iterator(): Iterator<string>; +[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 SecurityPolicyViolationEventHandler = ( event: SecurityPolicyViolationEvent, ) => mixed; type SecurityPolicyViolationEventListener = | {handleEvent: SecurityPolicyViolationEventHandler, ...} | SecurityPolicyViolationEventHandler; type USBConnectionEventHandler = (event: USBConnectionEvent) => mixed; type USBConnectionEventListener = | {handleEvent: USBConnectionEventHandler, ...} | USBConnectionEventHandler; 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 SecurityPolicyViolationEventTypes = 'securitypolicyviolation'; type USBConnectionEventTypes = 'connect' | 'disconnect'; type EventListenerOptionsOrUseCapture = | boolean | { capture?: boolean, once?: boolean, passive?: boolean, signal?: AbortSignal, ... }; 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: SecurityPolicyViolationEventTypes, listener: SecurityPolicyViolationEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture, ): void; addEventListener( type: USBConnectionEventTypes, listener: USBConnectionEventListener, 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: SecurityPolicyViolationEventTypes, listener: SecurityPolicyViolationEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture, ): void; removeEventListener( type: USBConnectionEventTypes, listener: USBConnectionEventListener, 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: USBConnectionEventTypes, listener: USBConnectionEventListener, ) => 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: USBConnectionEventTypes, listener: USBConnectionEventListener, ) => 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; } // https://www.w3.org/TR/clipboard-apis/#typedefdef-clipboarditemdata // Raw string | Blob are allowed per https://webidl.spec.whatwg.org/#es-promise type ClipboardItemData = string | Blob | Promise<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; } declare class SecurityPolicyViolationEvent extends Event { +documentURI: string; +referrer: string; +blockedURI: string; +effectiveDirective: string; +violatedDirective: string; +originalPolicy: string; +sourceFile: string; +sample: string; +disposition: 'enforce' | 'report'; +statusCode: number; +lineNumber: number; +columnNumber: number; } // https://developer.mozilla.org/en-US/docs/Web/API/USBConnectionEvent declare class USBConnectionEvent extends Event { device: USBDevice; } // 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; replaceChildren(...nodes: $ReadOnlyArray<Node | string>): void; 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; } declare class NodeList<T> { @@iterator(): Iterator<T>; length: number; item(index: number): T; [index: number]: T; forEach<This>( callbackfn: (this: This, value: T, index: number, list: NodeList<T>) => any, thisArg: This, ): void; entries(): Iterator<[number, T]>; keys(): Iterator<number>; values(): Iterator<T>; } declare class NamedNodeMap { @@iterator(): Iterator<Attr>; length: number; removeNamedItemNS(namespaceURI: string, localName: string): Attr; item(index: number): Attr; [index: number | string]: Attr; removeNamedItem(name: string): Attr; getNamedItem(name: string): Attr; setNamedItem(arg: Attr): Attr; getNamedItemNS(namespaceURI: string, localName: string): Attr; setNamedItemNS(arg: Attr): Attr; } declare class Attr extends Node { isId: boolean; specified: boolean; ownerElement: Element | null; value: string; name: string; namespaceURI: string | null; prefix: string | null; localName: string; } declare class HTMLCollection<+Elem: HTMLElement> { @@iterator(): Iterator<Elem>; length: number; item(nameOrIndex?: any, optionalIndex?: any): Elem | null; namedItem(name: string): Elem | null; [index: number | string]: Elem; } // from https://www.w3.org/TR/custom-elements/#extensions-to-document-interface-to-register // See also https://github.com/w3c/webcomponents/ type ElementRegistrationOptions = { +prototype?: { // from https://www.w3.org/TR/custom-elements/#types-of-callbacks // See also https://github.com/w3c/webcomponents/ +createdCallback?: () => mixed, +attachedCallback?: () => mixed, +detachedCallback?: () => mixed, +attributeChangedCallback?: (( // attribute is set attributeLocalName: string, oldAttributeValue: null, newAttributeValue: string, attributeNamespace: string, ) => mixed) & // attribute is changed (( attributeLocalName: string, oldAttributeValue: string, newAttributeValue: string, attributeNamespace: string, ) => mixed) & // attribute is removed (( attributeLocalName: string, oldAttributeValue: string, newAttributeValue: null, attributeNamespace: string, ) => mixed), ... }, +extends?: string, ... }; type ElementCreationOptions = {is: string, ...}; declare class Document extends Node { +timeline: DocumentTimeline; getAnimations(): Array<Animation>; +URL: string; adoptNode<T: Node>(source: T): T; anchors: HTMLCollection<HTMLAnchorElement>; applets: HTMLCollection<HTMLAppletElement>; body: HTMLBodyElement | null; +characterSet: string; /** * Legacy alias of `characterSet` * @deprecated */ +charset: string; close(): void; +contentType: string; cookie: string; createAttribute(name: string): Attr; createAttributeNS(namespaceURI: string | null, qualifiedName: string): Attr; createCDATASection(data: string): Text; createComment(data: string): Comment; createDocumentFragment(): DocumentFragment; createElement( tagName: 'a', options?: ElementCreationOptions, ): HTMLAnchorElement; createElement( tagName: 'area', options?: ElementCreationOptions, ): HTMLAreaElement; createElement( tagName: 'audio', options?: ElementCreationOptions, ): HTMLAudioElement; createElement( tagName: 'blockquote', options?: ElementCreationOptions, ): HTMLQuoteElement; createElement( tagName: 'body', options?: ElementCreationOptions, ): HTMLBodyElement; createElement(tagName: 'br', options?: ElementCreationOptions): HTMLBRElement; createElement( tagName: 'button', options?: ElementCreationOptions, ): HTMLButtonElement; createElement( tagName: 'canvas', options?: ElementCreationOptions, ): HTMLCanvasElement; createElement( tagName: 'col', options?: ElementCreationOptions, ): HTMLTableColElement; createElement( tagName: 'colgroup', options?: ElementCreationOptions, ): HTMLTableColElement; createElement( tagName: 'data', options?: ElementCreationOptions, ): HTMLDataElement; createElement( tagName: 'datalist', options?: ElementCreationOptions, ): HTMLDataListElement; createElement( tagName: 'del', options?: ElementCreationOptions, ): HTMLModElement; createElement( tagName: 'details', options?: ElementCreationOptions, ): HTMLDetailsElement; createElement( tagName: 'dialog', options?: ElementCreationOptions, ): HTMLDialogElement; createElement( tagName: 'div', options?: ElementCreationOptions, ): HTMLDivElement; createElement( tagName: 'dl', options?: ElementCreationOptions, ): HTMLDListElement; createElement( tagName: 'embed', options?: ElementCreationOptions, ): HTMLEmbedElement; createElement( tagName: 'fieldset', options?: ElementCreationOptions, ): HTMLFieldSetElement; createElement( tagName: 'form', options?: ElementCreationOptions, ): HTMLFormElement; createElement( tagName: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6', options?: ElementCreationOptions, ): HTMLHeadingElement; createElement( tagName: 'head', options?: ElementCreationOptions, ): HTMLHeadElement; createElement(tagName: 'hr', options?: ElementCreationOptions): HTMLHRElement; createElement( tagName: 'html', options?: ElementCreationOptions, ): HTMLHtmlElement; createElement( tagName: 'iframe', options?: ElementCreationOptions, ): HTMLIFrameElement; createElement( tagName: 'img', options?: ElementCreationOptions, ): HTMLImageElement; createElement( tagName: 'input', options?: ElementCreationOptions, ): HTMLInputElement; createElement( tagName: 'ins', options?: ElementCreationOptions, ): HTMLModElement; createElement( tagName: 'label', options?: ElementCreationOptions, ): HTMLLabelElement; createElement( tagName: 'legend', options?: ElementCreationOptions, ): HTMLLegendElement; createElement(tagName: 'li', options?: ElementCreationOptions): HTMLLIElement; createElement( tagName: 'link', options?: ElementCreationOptions, ): HTMLLinkElement; createElement( tagName: 'map', options?: ElementCreationOptions, ): HTMLMapElement; createElement( tagName: 'meta', options?: ElementCreationOptions, ): HTMLMetaElement; createElement( tagName: 'meter', options?: ElementCreationOptions, ): HTMLMeterElement; createElement( tagName: 'object', options?: ElementCreationOptions, ): HTMLObjectElement; createElement( tagName: 'ol', options?: ElementCreationOptions, ): HTMLOListElement; createElement( tagName: 'optgroup', options?: ElementCreationOptions, ): HTMLOptGroupElement; createElement( tagName: 'option', options?: ElementCreationOptions, ): HTMLOptionElement; createElement( tagName: 'p', options?: ElementCreationOptions, ): HTMLParagraphElement; createElement( tagName: 'param', options?: ElementCreationOptions, ): HTMLParamElement; createElement( tagName: 'picture', options?: ElementCreationOptions, ): HTMLPictureElement; createElement( tagName: 'pre', options?: ElementCreationOptions, ): HTMLPreElement; createElement( tagName: 'progress', options?: ElementCreationOptions, ): HTMLProgressElement; createElement( tagName: 'q', options?: ElementCreationOptions, ): HTMLQuoteElement; createElement( tagName: 'script', options?: ElementCreationOptions, ): HTMLScriptElement; createElement( tagName: 'select', options?: ElementCreationOptions, ): HTMLSelectElement; createElement( tagName: 'source', options?: ElementCreationOptions, ): HTMLSourceElement; createElement( tagName: 'span', options?: ElementCreationOptions, ): HTMLSpanElement; createElement( tagName: 'style', options?: ElementCreationOptions, ): HTMLStyleElement; createElement( tagName: 'textarea', options?: ElementCreationOptions, ): HTMLTextAreaElement; createElement( tagName: 'time', options?: ElementCreationOptions, ): HTMLTimeElement; createElement( tagName: 'title', options?: ElementCreationOptions, ): HTMLTitleElement; createElement( tagName: 'track', options?: ElementCreationOptions, ): HTMLTrackElement; createElement( tagName: 'video', options?: ElementCreationOptions, ): HTMLVideoElement; createElement( tagName: 'table', options?: ElementCreationOptions, ): HTMLTableElement; createElement( tagName: 'caption', options?: ElementCreationOptions, ): HTMLTableCaptionElement; createElement( tagName: 'thead' | 'tfoot' | 'tbody', options?: ElementCreationOptions, ): HTMLTableSectionElement; createElement( tagName: 'tr', options?: ElementCreationOptions, ): HTMLTableRowElement; createElement( tagName: 'td' | 'th', options?: ElementCreationOptions, ): HTMLTableCellElement; createElement( tagName: 'template', options?: ElementCreationOptions, ): HTMLTemplateElement; createElement( tagName: 'ul', options?: ElementCreationOptions, ): HTMLUListElement; createElement(tagName: string, options?: ElementCreationOptions): HTMLElement; createElementNS( namespaceURI: string | null, qualifiedName: string, options?: ElementCreationOptions, ): Element; createTextNode(data: string): Text; currentScript: HTMLScriptElement | null; dir: 'rtl' | 'ltr'; +doctype: DocumentType | null; +documentElement: HTMLElement | null; documentMode: number; +documentURI: string; domain: string | null; embeds: HTMLCollection<HTMLEmbedElement>; exitFullscreen(): Promise<void>; queryCommandSupported(cmdID: string): boolean; execCommand(cmdID: string, showUI?: boolean, value?: any): boolean; forms: HTMLCollection<HTMLFormElement>; fullscreenElement: Element | null; fullscreenEnabled: boolean; getElementsByClassName(classNames: string): HTMLCollection<HTMLElement>; getElementsByName(elementName: string): HTMLCollection<HTMLElement>; getElementsByTagName(name: 'a'): HTMLCollection<HTMLAnchorElement>; getElementsByTagName(name: 'area'): HTMLCollection<HTMLAreaElement>; getElementsByTagName(name: 'audio'): HTMLCollection<HTMLAudioElement>; getElementsByTagName(name: 'blockquote'): HTMLCollection<HTMLQuoteElement>; getElementsByTagName(name: 'body'): HTMLCollection<HTMLBodyElement>; getElementsByTagName(name: 'br'): HTMLCollection<HTMLBRElement>; getElementsByTagName(name: 'button'): HTMLCollection<HTMLButtonElement>; getElementsByTagName(name: 'canvas'): HTM