[screenfull] Update types to v4.0

This commit is contained in:
Dimitri Benin 2019-02-25 20:12:48 +01:00
parent 339aca728c
commit 030a4fe9fe
4 changed files with 158 additions and 0 deletions

85
types/screenfull/index.d.ts vendored Normal file
View File

@ -0,0 +1,85 @@
// Type definitions for screenfull.js 4.0
// Project: https://github.com/sindresorhus/screenfull.js
// Definitions by: Ilia Choly <https://github.com/icholy>
// lionelb <https://github.com/lionelb>
// Joel Shepherd <https://github.com/joelshepherd>
// BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.5
export = screenfull;
export as namespace screenfull;
declare const screenfull: screenfull.Screenfull | false;
declare namespace screenfull {
interface Screenfull {
/**
* Returns a boolean whether fullscreen is active.
*/
readonly isFullscreen: boolean;
/**
* Returns the element currently in fullscreen, otherwise `null`.
*/
readonly element: Element | null;
/**
* Returns a boolean whether you are allowed to enter fullscreen. If your page is inside an `<iframe>`
* you will need to add a `allowfullscreen` attribute (+ `webkitallowfullscreen` and `mozallowfullscreen`).
*/
readonly enabled: boolean;
/**
* Exposes the raw properties (prefixed if needed) used internally.
*/
raw: RawEventNames;
/**
* Make an element fullscreen.
*
* If your page is inside an `<iframe>` you will need to add a `allowfullscreen` attribute
* (+ `webkitallowfullscreen` and `mozallowfullscreen`).
*
* Keep in mind that the browser will only enter fullscreen when initiated by user events like click, touch, key.
*
* @param element Default is `<html>`. If called with another element than the currently active,
* it will switch to that if it's a decendant.
* @returns A promise that resolves after the element enters fullscreen.
*/
request(element?: Element): Promise<void>;
/**
* Brings you out of fullscreen.
* @returns A promise that resolves after the element exits fullscreen.
*/
exit(): Promise<void>;
/**
* Requests fullscreen if not active, otherwise exits.
* @returns A promise that resolves after the element enters/exits fullscreen.
*/
toggle(elem?: Element): Promise<void>;
/**
* Add a listener for when the browser switches in and out of fullscreen or when there is an error.
*/
on(name: EventName, handler: (event: Event) => void): void;
/**
* Remove a previously registered event listener.
*/
off(name: EventName, handler: (event: Event) => void): void;
/**
* Alias for `.on('change', function)`.
*/
onchange(handler: (event: Event) => void): void;
/**
* Alias for `.on('error', function)`.
*/
onerror(handler: (event: Event) => void): void;
}
interface RawEventNames {
requestFullscreen: string;
exitFullscreen: string;
fullscreenElement: string;
fullscreenEnabled: string;
fullscreenchange: string;
fullscreenerror: string;
}
type EventName = 'change' | 'error';
}

View File

@ -0,0 +1,46 @@
import screenfull = require('screenfull');
if (screenfull) {
screenfull.enabled; // $ExpectType boolean
screenfull.enabled = false; // $ExpectError
screenfull.isFullscreen; // $ExpectType boolean
screenfull.isFullscreen = false; // $ExpectError
screenfull.element; // $ExpectType Element | null
screenfull.element = document.documentElement; // $ExpectError
if (screenfull.enabled) {
const elem: Element = document.getElementById('target')!;
screenfull.request(); // $ExpectType Promise<void>
screenfull.request(elem); // $ExpectType Promise<void>
screenfull.toggle(); // $ExpectType Promise<void>
screenfull.toggle(elem); // $ExpectType Promise<void>
screenfull.exit(); // $ExpectType Promise<void>
screenfull.on('change', event => {
event; // $ExpectType Event
});
screenfull.on('error', event => {
event; // $ExpectType Event
});
screenfull.off('change', event => {
event; // $ExpectType Event
});
screenfull.off('error', event => {
event; // $ExpectType Event
});
screenfull.onchange(event => {
event; // $ExpectType Event
});
screenfull.onerror(event => {
event; // $ExpectType Event
});
screenfull.raw.requestFullscreen; // $ExpectType string
screenfull.raw.exitFullscreen; // $ExpectType string
screenfull.raw.fullscreenElement; // $ExpectType string
screenfull.raw.fullscreenEnabled; // $ExpectType string
screenfull.raw.fullscreenchange; // $ExpectType string
screenfull.raw.fullscreenerror; // $ExpectType string
}
}

View File

@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"screenfull-tests.ts"
]
}

View File

@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}