Enhance types (#1841)

* 🏷️(type) enhance QualityOptions type

Some optional properties in the QualityOptions were missing. The forced
and onChange property allwoing to use an external handler.

* ♻️(type) use Plyr.Provider for the readonly provider property

A type exists to define all available providers. This type isn't used in
the Plyr class definition and the same provider list is also defined.
This code is refactored to use the Plyr.Provider type

* 🏷️(type) add missing elements property in Plyr class

In Plyr class, you can access elements set in cache. This property is
missing in the class definition. The Plyr.Elements is for now
incomplete.
This commit is contained in:
Manuel Raynaud 2020-12-20 10:18:53 +01:00 committed by GitHub
parent c853adc760
commit 32a4039f7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

30
src/js/plyr.d.ts vendored
View File

@ -138,10 +138,15 @@ declare class Plyr {
*/ */
ratio?: string; ratio?: string;
/**
* Access Elements cache
*/
elements: Plyr.Elements;
/** /**
* Returns the current video Provider * Returns the current video Provider
*/ */
readonly provider: 'html5' | 'vimeo' | 'youtube'; readonly provider: Plyr.Provider;
/** /**
* Returns the native API for Vimeo or Youtube players * Returns the native API for Vimeo or Youtube players
@ -510,6 +515,8 @@ declare namespace Plyr {
interface QualityOptions { interface QualityOptions {
default: number; default: number;
forced?: boolean;
onChange?: (quality: number) => void;
options: number[]; options: number[];
} }
@ -560,6 +567,27 @@ declare namespace Plyr {
src?: string | string[]; src?: string | string[];
} }
export interface Elements {
buttons: {
airplay?: HTMLButtonElement;
captions?: HTMLButtonElement;
download?: HTMLButtonElement;
fastForward?: HTMLButtonElement;
fullscreen?: HTMLButtonElement;
mute?: HTMLButtonElement;
pip?: HTMLButtonElement;
play?: HTMLButtonElement | HTMLButtonElement[];
restart?: HTMLButtonElement;
rewind?: HTMLButtonElement;
settings?: HTMLButtonElement;
};
captions: HTMLElement | null;
container: HTMLElement | null;
controls: HTMLElement | null;
fullscreen: HTMLElement | null;
wrapper: HTMLElement | null;
}
interface SourceInfo { interface SourceInfo {
/** /**
* Note: YouTube and Vimeo are currently not supported as audio sources. * Note: YouTube and Vimeo are currently not supported as audio sources.