diff --git a/src/loader.ts b/src/loader.ts index 62b6124..010d259 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-promise-reject-errors */ /* eslint-disable @typescript-eslint/no-use-before-define */ import './types'; - + function isScriptAdded(src: string): boolean { const url = src.startsWith('//') ? window.location.protocol + src : src; for (let i = 0; i < document.scripts.length; i += 1) { diff --git a/src/types.ts b/src/types.ts index a4f2ea1..9bde448 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,32 +1,63 @@ namespace Kinescope { - type VideoQuality = number | 'auto'; - - declare enum PlayerEvents { - Ready = 'Ready', - CurrentTrackChanged = 'CurrentTrackChanged', - SizeChanged = 'SizeChanged', - QualityChanged = 'QualityChanged', - Play = 'Play', - Playing = 'Playing', - Pause = 'Pause', - Ended = 'Ended', - TimeUpdate = 'TimeUpdate', - Waiting = 'Waiting', - Progress = 'Progress', - DurationChange = 'DurationChange', - VolumeChange = 'VolumeChange', - PlaybackRateChange = 'PlaybackRateChange', - Seeked = 'Seeked', - SeekChapter = 'SeekChapter', - FullscreenChange = 'FullscreenChange', - PipChange = 'PipChange', - CallAction = 'CallAction', - CallBookmark = 'CallBookmark', - Error = 'Error', - Destroy = 'Destroy', - } + type DefineAll> = T; + + type PlayerEventKeys = + | 'Ready' + | 'CurrentTrackChanged' + | 'SizeChanged' + | 'QualityChanged' + | 'Play' + | 'Playing' + | 'Pause' + | 'Ended' + | 'TimeUpdate' + | 'Waiting' + | 'Progress' + | 'DurationChange' + | 'VolumeChange' + | 'PlaybackRateChange' + | 'Seeked' + | 'SeekChapter' + | 'FullscreenChange' + | 'PipChange' + | 'CallAction' + | 'CallBookmark' + | 'Error' + | 'Destroy'; + + type PlayerEvents = DefineAll< + PlayerEventKeys, + { + Ready: 'ready'; + CurrentTrackChanged: 'currenttrackchanged'; + SizeChanged: 'sizechanged'; + QualityChanged: 'qualitychanged'; + Play: 'play'; + Playing: 'playing'; + Pause: 'pause'; + Ended: 'ended'; + TimeUpdate: 'timeupdate'; + Waiting: 'waiting'; + Progress: 'progress'; + DurationChange: 'durationchange'; + VolumeChange: 'volumechange'; + PlaybackRateChange: 'playbackratechange'; + Seeked: 'seeked'; + SeekChapter: 'seekchapter'; + FullscreenChange: 'fullscreenchange'; + PipChange: 'pipchange'; + CallAction: 'callaction'; + CallBookmark: 'callbookmark'; + Error: 'error'; + Destroy: 'destroy'; + } + >; + + declare const PlayerEvents: PlayerEvents; export declare namespace IframePlayer { + export type VideoQuality = number | 'auto'; + export interface PlaylistItemOptions { /** Заголовок видео-ролика. Отображается в верхней части плеера. */ title?: string; @@ -111,24 +142,7 @@ namespace Kinescope { } export interface UpdatablePlayerOptions { - /** Настройки UI */ - ui?: { - /** Водяной знак. */ - watermark?: { - /** Текст */ - text: string; - /** - * - `stripes` - линиями; - * - `random` - в случайных местах; - * По умолчанию `random`. - */ - mode?: 'stripes' | 'random'; - /** Коэффициент масштабирования размера текста в зависимости от размера плеера. По умолчанию `0.25`. */ - scale?: number; - /** Длительность показа/скрытия (мс). Если не указано, текст показывается постоянно. */ - displayTimeout?: number | { visible: number; hidden: number }; - }; - }; + ui?: Pick, 'watermark'>; } export interface CreateOptions { @@ -207,6 +221,21 @@ namespace Kinescope { mainPlayButton?: boolean; /** Показывать ли кнопку выбора скорости воспроизведения. */ playbackRateButton?: boolean; + /** Водяной знак. */ + watermark?: { + /** Текст */ + text: string; + /** + * - `stripes` - линиями; + * - `random` - в случайных местах; + * По умолчанию `random`. + */ + mode?: 'stripes' | 'random'; + /** Коэффициент масштабирования размера текста в зависимости от размера плеера. По умолчанию `0.25`. */ + scale?: number; + /** Длительность показа/скрытия (мс). Если не указано, текст показывается постоянно. */ + displayTimeout?: number | { visible: number; hidden: number }; + }; }; /** Настройки темы. */ @@ -235,9 +264,9 @@ namespace Kinescope { export interface Player { readonly Events: Player.Events; - on(event: T, handler: Player.EventHandler): this; - once(event: T, handler: Player.EventHandler): this; - off(event: T, handler: Player.EventHandler): this; + on(event: T, handler: Player.EventHandler): this; + once(event: T, handler: Player.EventHandler): this; + off(event: T, handler: Player.EventHandler): this; isPaused(): Promise; @@ -305,12 +334,11 @@ namespace Kinescope { } export namespace Player { - export type Events = typeof PlayerEvents; - - type DefineAll> = T; + export type EventType = PlayerEvents[keyof PlayerEvents]; + export type Events = PlayerEvents; - type EventMap = DefineAll< - PlayerEvents, + export type EventMap = DefineAll< + EventType, { [PlayerEvents.Ready]: { quality: VideoQuality; @@ -373,7 +401,7 @@ namespace Kinescope { } >; - export type EventHandler = (event: { + export type EventHandler = (event: { readonly type: T; readonly target: Player; readonly data: EventMap[T]; @@ -388,4 +416,8 @@ namespace Kinescope { /** Returns all created players. */ export function getAll(): readonly IframePlayer.Player[]; } + + // export type IframePlayer = typeof IframePlayer; } + +// type Kinescope = typeof Kinescope;