diff --git a/types/dplayer/dplayer-tests.ts b/types/dplayer/dplayer-tests.ts new file mode 100644 index 0000000000..a3c46b58c4 --- /dev/null +++ b/types/dplayer/dplayer-tests.ts @@ -0,0 +1,19 @@ +import DPlayer, { DPlayerOptions } from 'dplayer'; + +const dp = new DPlayer({ + container: document.querySelector('#dplayer'), + screenshot: true, + video: { + url: 'demo.mp4', + pic: 'demo.jpg', + thumbnails: 'thumbnails.jpg' + }, + subtitle: { + url: 'webvtt.vtt' + }, + danmaku: { + id: 'demo', + api: 'https://api.prprpr.me/dplayer3/' + } +}); +console.log(dp); diff --git a/types/dplayer/index.d.ts b/types/dplayer/index.d.ts new file mode 100644 index 0000000000..7dac6c76b8 --- /dev/null +++ b/types/dplayer/index.d.ts @@ -0,0 +1,160 @@ +// Type definitions for dplayer 1.24 +// Project: https://github.com/DIYgod/DPlayer#readme +// Definitions by: Guanyunhan +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module 'dplayer' { + export type Lang = 'en' | 'zh-cn' | 'zh-tw'; + export type Preload = 'none' | 'metadata' | 'auto'; + export type VideoType = 'auto' | 'hls' | 'flv' | 'dash' | 'webtorrent' | 'normal'; + export type SubTitleType = 'webvtt' | 'ass'; + export type DirectionType = 'top' | 'right' | 'bottom'; + + export enum DPlayerEvents { + abort = 'abort', + canplay = 'canplay', + canplaythrough = 'canplaythrough', + durationchange = 'durationchange', + emptied = 'emptied', + ended = 'ended', + error = 'error', + loadeddata = 'loadeddata', + loadedmetadata = 'loadedmetadata', + loadstart = 'loadstart', + mozaudioavailable = 'mozaudioavailable', + pause = 'pause', + play = 'play', + playing = 'playing', + progress = 'progress', + ratechange = 'ratechange', + seeked = 'seeked', + seeking = 'seeking', + stalled = 'stalled', + suspend = 'suspend', + timeupdate = 'timeupdate', + volumechange = 'volumechange', + waiting = 'waiting', + screenshot = 'screenshot', + thumbnails_show = 'thumbnails_show', + thumbnails_hide = 'thumbnails_hide', + danmaku_show = 'danmaku_show', + danmaku_hide = 'danmaku_hide', + danmaku_clear = 'danmaku_clear', + danmaku_loaded = 'danmaku_loaded', + danmaku_send = 'danmaku_send', + danmaku_opacity = 'danmaku_opacity', + contextmenu_show = 'contextmenu_show', + contextmenu_hide = 'contextmenu_hide', + notice_show = 'notice_show', + notice_hide = 'notice_hide', + quality_start = 'quality_start', + quality_end = 'quality_end', + destroy = 'destroy', + resize = 'resize', + fullscreen = 'fullscreen', + fullscreen_cancel = 'fullscreen_cancel', + subtitle_show = 'subtitle_show', + subtitle_hide = 'subtitle_hide', + subtitle_change = 'subtitle_change' + } + + export interface DPlayerOptions { + [key: string]: any; + + container: HTMLElement; + live?: boolean; + autoplay?: boolean; + theme?: string; + loop?: boolean; + lang?: Lang | string; + screenshot?: boolean; + hotkey?: boolean; + preload?: Preload; + logo?: string; + volume?: number; + mutex?: boolean; + video?: DPlayerVideo; + subtitle?: DPlayerSubTitle; + danmaku?: DPlayerDanmaku; + contextmenu?: Array; + highlight?: Array; + apiBackend?: DPlayerAPIBackend; + } + + export interface DPlayerDanmakuItem { + text: string; + color: string; + type: DirectionType; + } + + export interface DPlayerContextMenuItem { + text: string; + link?: string; + click?: Function; + } + + export interface DPlayerHighLightItem { + text: string; + time: number; + } + + export interface DPlayerVideo { + url: string; + pic?: string; + thumbnails?: string; + type?: VideoType | string; + } + + export interface DPlayerSubTitle { + url: string; + type?: SubTitleType; + fontSize?: string; + bottom?: string; + color?: string; + } + + export interface DPlayerDanmaku { + id: string; + api: string; + token?: string; + maximum?: string; + addition?: Array; + user?: string; + bottom?: string; + unlimited?: boolean; + } + + export interface DPlayerAPIBackend { + read(endpoint: any, callback: Function): void; + + send(endpoint: any, danmakuData: DPlayerDanmakuItem, callback: Function): void; + } + + export default class DPlayer { + public events: any; + + constructor(options: DPlayerOptions); + + play(): void; + + pause(): void; + + seek(time: number): void; + + toggle(): void; + + on(event: DPlayerEvents, handler: Function): void; + + switchVideo(video: DPlayerVideo, danmaku: DPlayerDanmaku): void; + + notice(text: string, time: number, opacity: number): void; + + switchQuality(index: number): void; + + destroy(): void; + + speed(rate: number): void; + + volume(percentage: number, nostorage: boolean, nonotice: boolean): void; + } +} diff --git a/types/dplayer/tsconfig.json b/types/dplayer/tsconfig.json new file mode 100644 index 0000000000..712b73893c --- /dev/null +++ b/types/dplayer/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "allowSyntheticDefaultImports": true + }, + "files": [ + "index.d.ts", + "dplayer-tests.ts" + ] +} diff --git a/types/dplayer/tslint.json b/types/dplayer/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/dplayer/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }