@cmchu/screen-full
Version:
This module provides a straightforward set of APIs to control the browser's fullscreen functionality and listen for changes and errors in the fullscreen state. By encapsulating the native fullscreen APIs, it enables developers to uniformly handle fullscre
51 lines (44 loc) • 1.76 kB
TypeScript
// Define the shape of the imported 'api' object based on usage in the original code.
interface NativeApi {
fullscreenEnabled: keyof Document;
fullscreenElement: keyof Document;
requestFullscreen: keyof HTMLElement;
exitFullscreen: keyof Document;
}
declare const api: NativeApi;
// Define constants with their respective types
declare const FULLSCREEN_CHANGE_EVENT: "fullscreenchange";
declare const FULLSCREEN_ERROR_EVENT: "fullscreenerror";
declare const FULLSCREEN_EXIT_KEY: 27; // keyCode for Esc key
declare const FULLSCREEN_REQUEST_KEY: 122; // keyCode for F11 key
// Event listener type
type EventListener = (event: Event) => void;
// Main screenfull functions and properties type definitions
interface Screenfull {
request(element?: HTMLElement, options?: any): Promise<void> | undefined;
requestFullscreen(
element?: HTMLElement,
options?: any
): Promise<void> | undefined;
exit(element?: HTMLElement): Promise<void> | undefined;
exitFullscreen(element?: HTMLElement): Promise<void> | undefined;
onChange(callback: EventListener): void;
fullscreenchange(callback: EventListener): void;
fullscreenEnabled(): boolean;
isFullscreen(): boolean;
fullscreenElement(): HTMLElement | null;
onError(callback: EventListener): void;
fullscreenerror(callback: EventListener): void;
isEnabled: boolean;
isFull: boolean;
fullElement: HTMLElement | null;
}
// Define properties added via Object.defineProperties
interface ScreenfullExtended extends Screenfull {
isEnabled: boolean;
isFull: boolean;
fullElement: HTMLElement | null;
}
declare const screenfull: ScreenfullExtended;
// Export the screenfull object for external use
export default screenfull;