kplayer-ts 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ import { KPlayerOptions } from '../ts/types';
2
+ import { default as Icons } from '../ts/icons';
3
+ interface RenderPlayerOptions {
4
+ options: KPlayerOptions;
5
+ index: number;
6
+ tran: (key: string) => string;
7
+ icons: typeof Icons;
8
+ mobile: boolean;
9
+ video: {
10
+ current: boolean;
11
+ pic?: string;
12
+ screenshot?: boolean;
13
+ airplay?: boolean;
14
+ chromecast?: boolean;
15
+ preload?: string;
16
+ url?: string;
17
+ subtitle?: KPlayerOptions["subtitle"];
18
+ };
19
+ }
20
+ export default function renderPlayer({ options, index: _index, tran, icons, mobile: _mobile, video, }: RenderPlayerOptions): string;
21
+ export {};
@@ -0,0 +1,12 @@
1
+ import { SubtitleOptions } from '../ts/types';
2
+ interface RenderVideoOptions {
3
+ current?: boolean;
4
+ airplay?: boolean;
5
+ pic?: string;
6
+ screenshot?: boolean;
7
+ preload?: string;
8
+ url?: string;
9
+ subtitle?: SubtitleOptions | null;
10
+ }
11
+ export default function renderVideo({ current, airplay, pic, screenshot, preload, url, subtitle, }?: RenderVideoOptions): string;
12
+ export {};
@@ -0,0 +1,39 @@
1
+ import { default as Kplayer } from './player';
2
+ import { AdItem } from './types';
3
+ declare class Ad {
4
+ player: Kplayer;
5
+ options: {
6
+ url: AdItem[];
7
+ } | null;
8
+ currentAd: AdItem | null;
9
+ adContainer: HTMLDivElement | null;
10
+ adContent: HTMLDivElement;
11
+ skipBtn: HTMLButtonElement;
12
+ deeplinkBtn: HTMLButtonElement;
13
+ adLabel: HTMLDivElement;
14
+ skipTimer?: ReturnType<typeof setInterval>;
15
+ skipRemaining: number;
16
+ adMarkers: HTMLElement[];
17
+ private _timeUpdateBound;
18
+ private _shownAds;
19
+ private _adVideo;
20
+ constructor(player: Kplayer);
21
+ private _createAdContainer;
22
+ private _createMarker;
23
+ private _renderBarMarkers;
24
+ private _bindTimeUpdate;
25
+ private _showAd;
26
+ private _showImageAd;
27
+ private _showTextAd;
28
+ private _showVideoAd;
29
+ private _startSkipTimer;
30
+ private _skipAd;
31
+ private _closeAd;
32
+ _loadVAST(url: string): Promise<void>;
33
+ private _fetchVASTAndRegister;
34
+ private _registerVMAPMarkers;
35
+ private _parseVASTAndShow;
36
+ private _parseTime;
37
+ destroy(): void;
38
+ }
39
+ export default Ad;
@@ -0,0 +1,10 @@
1
+ import { default as Template } from './template';
2
+ type BarType = "volume" | "played" | "loaded" | "awaken";
3
+ type BarDirection = "width" | "height";
4
+ declare class Bar {
5
+ elements: Partial<Record<BarType, HTMLElement>>;
6
+ constructor(template: Template);
7
+ set(type: BarType, percentage: number, direction: BarDirection): void;
8
+ get(type: BarType): number;
9
+ }
10
+ export default Bar;
@@ -0,0 +1,6 @@
1
+ declare class Bezel {
2
+ container: HTMLElement;
3
+ constructor(container: HTMLElement);
4
+ switch(icon: string): void;
5
+ }
6
+ export default Bezel;
@@ -0,0 +1,12 @@
1
+ import { default as KPlayer } from './player';
2
+ declare class ContextMenu {
3
+ player: KPlayer;
4
+ shown: boolean;
5
+ contextmenuHandler: (e: MouseEvent) => void;
6
+ videoContextHandler: (e: MouseEvent) => void;
7
+ constructor(player: KPlayer);
8
+ show(x: number, y: number): void;
9
+ hide(): void;
10
+ destroy(): void;
11
+ }
12
+ export default ContextMenu;
@@ -0,0 +1,38 @@
1
+ import { default as Thumbnails } from './thumbnails';
2
+ import { default as KPlayer } from './player';
3
+ declare class Controller {
4
+ player: KPlayer;
5
+ autoHideTimer: number;
6
+ disableAutoHide: boolean;
7
+ thumbnails?: Thumbnails;
8
+ setAutoHideHandler?: () => void;
9
+ private _skipBtn;
10
+ private _skipTarget;
11
+ private session;
12
+ private currentMedia;
13
+ constructor(player: KPlayer);
14
+ initPlayButton(): void;
15
+ initSeekButtons(): void;
16
+ initHighlights(): void;
17
+ private _createSkipButton;
18
+ private _updateSkipButton;
19
+ initThumbnails(): void;
20
+ initPlayedBar(): void;
21
+ initFullButton(): void;
22
+ initVolumeButton(): void;
23
+ initQualityButton(): void;
24
+ initScreenshotButton(): void;
25
+ initAirplayButton(): void;
26
+ initChromecast(): void;
27
+ initChromecastButton(): void;
28
+ initSubtitleButton(): void;
29
+ _showTitleBar(): void;
30
+ _hideTitleBar(): void;
31
+ setAutoHide(): void;
32
+ show(): void;
33
+ hide(): void;
34
+ isShow(): boolean;
35
+ toggle(): void;
36
+ destroy(): void;
37
+ }
38
+ export default Controller;
@@ -0,0 +1,11 @@
1
+ type EventCallback = (info?: unknown) => void;
2
+ declare class Events {
3
+ events: Record<string, EventCallback[]>;
4
+ videoEvents: string[];
5
+ playerEvents: string[];
6
+ constructor();
7
+ on(name: string, callback: EventCallback): void;
8
+ trigger(name: string, info?: unknown): void;
9
+ type(name: string): string | null;
10
+ }
11
+ export default Events;
@@ -0,0 +1,15 @@
1
+ import { default as KPlayer } from './player';
2
+ import { FullScreenType, ScrollPosition } from './types';
3
+ declare class FullScreen {
4
+ player: KPlayer;
5
+ lastScrollPosition: ScrollPosition;
6
+ fullscreenchange: () => void;
7
+ docfullscreenchange: () => void;
8
+ constructor(player: KPlayer);
9
+ isFullScreen(type?: FullScreenType): Element | boolean | null;
10
+ request(type?: FullScreenType): void;
11
+ cancel(type?: FullScreenType): void;
12
+ toggle(type?: FullScreenType): void;
13
+ destroy(): void;
14
+ }
15
+ export default FullScreen;
@@ -0,0 +1,11 @@
1
+ import { default as KPlayer } from './player';
2
+ declare class HotKey {
3
+ player: KPlayer;
4
+ doHotKeyHandler: (e: KeyboardEvent) => void;
5
+ cancelFullScreenHandler: (e: KeyboardEvent) => void;
6
+ constructor(player: KPlayer);
7
+ doHotKey(e: KeyboardEvent): void;
8
+ cancelFullScreen(e: KeyboardEvent): void;
9
+ destroy(): void;
10
+ }
11
+ export default HotKey;
@@ -0,0 +1,6 @@
1
+ declare function i18n(this: {
2
+ lang: string;
3
+ fallbackLang: string;
4
+ tran: (key: string) => string;
5
+ }, lang: string): void;
6
+ export { i18n };
@@ -0,0 +1,22 @@
1
+ declare const Icons: {
2
+ play: string;
3
+ pause: string;
4
+ volumeUp: string;
5
+ volumeDown: string;
6
+ volumeOff: string;
7
+ full: string;
8
+ fullWeb: string;
9
+ setting: string;
10
+ right: string;
11
+ pallette: string;
12
+ camera: string;
13
+ subtitle: string;
14
+ loading: string;
15
+ airplay: string;
16
+ chromecast: string;
17
+ back: string;
18
+ rewind: string;
19
+ forward: string;
20
+ video: string;
21
+ };
22
+ export default Icons;
@@ -0,0 +1,3 @@
1
+ import { default as KPlayer } from './player';
2
+ export default KPlayer;
3
+ export type { KPlayerOptions, VideoQuality, SubtitleOptions, SubtitleItem, AdOptions, AdItem, HighlightItem, TitleOptions, ContextMenuItem, } from './types';
@@ -0,0 +1,16 @@
1
+ import { default as KPlayer } from './player';
2
+ import { default as Template } from './template';
3
+ declare class InfoPanel {
4
+ container: HTMLElement;
5
+ template: Template;
6
+ video: HTMLVideoElement;
7
+ player: KPlayer;
8
+ beginTime: number;
9
+ constructor(player: KPlayer);
10
+ show(): void;
11
+ hide(): void;
12
+ triggle(): void;
13
+ update(): void;
14
+ fps(value: number): void;
15
+ }
16
+ export default InfoPanel;
@@ -0,0 +1,5 @@
1
+ import { KPlayerOptions } from './types';
2
+ declare const _default: (options: Partial<KPlayerOptions> & {
3
+ video: KPlayerOptions["video"];
4
+ }) => KPlayerOptions;
5
+ export default _default;
@@ -0,0 +1,107 @@
1
+ import { default as Template } from './template';
2
+ import { default as Ad } from './ad';
3
+ import { default as Events } from './events';
4
+ import { default as FullScreen } from './fullscreen';
5
+ import { default as User } from './user';
6
+ import { default as Subtitle } from './subtitle';
7
+ import { default as Subtitles } from './subtitles';
8
+ import { default as Bar } from './bar';
9
+ import { default as Timer } from './timer';
10
+ import { default as Bezel } from './bezel';
11
+ import { default as Controller } from './controller';
12
+ import { default as Setting } from './setting';
13
+ import { default as HotKey } from './hotkey';
14
+ import { default as ContextMenu } from './contextmenu';
15
+ import { default as InfoPanel } from './info-panel';
16
+ import { KPlayerOptions } from './types';
17
+ interface HlsLevel {
18
+ height?: number;
19
+ bitrate?: number;
20
+ }
21
+ interface HlsInstance {
22
+ levels: HlsLevel[];
23
+ currentLevel: number;
24
+ nextLevel: number;
25
+ loadLevel: number;
26
+ autoLevelEnabled: boolean;
27
+ loadSource(src: string): void;
28
+ attachMedia(video: HTMLVideoElement): void;
29
+ destroy(): void;
30
+ on(event: string, cb: (...args: unknown[]) => void): void;
31
+ off(event: string, cb: (...args: unknown[]) => void): void;
32
+ DefaultConfig?: {
33
+ loader: unknown;
34
+ };
35
+ }
36
+ declare class KPlayer {
37
+ options: KPlayerOptions;
38
+ tran: (key: string) => string;
39
+ events: Events;
40
+ user: User;
41
+ container: HTMLElement;
42
+ noticeList: Record<string, ReturnType<typeof setTimeout> | null>;
43
+ hlsQualityList: unknown[];
44
+ hlsCurrentLevel: number;
45
+ hlsAutoEnabled: boolean;
46
+ template: Template;
47
+ video: HTMLVideoElement;
48
+ bar: Bar;
49
+ bezel: Bezel;
50
+ fullScreen: FullScreen;
51
+ controller: Controller;
52
+ setting: Setting;
53
+ plugins: Record<string, unknown>;
54
+ docClickFun: () => void;
55
+ containerClickFun: () => void;
56
+ focus: boolean;
57
+ paused: boolean;
58
+ timer: Timer;
59
+ hotkey: HotKey;
60
+ contextmenu: ContextMenu;
61
+ infoPanel: InfoPanel;
62
+ ad?: Ad;
63
+ subtitle?: Subtitle;
64
+ subtitles?: Subtitles;
65
+ awaken?: unknown;
66
+ moveBar: boolean;
67
+ type?: string;
68
+ qualityIndex?: number;
69
+ quality?: {
70
+ name: string;
71
+ url: string;
72
+ type?: string;
73
+ };
74
+ switchingQuality: boolean;
75
+ prevIndex?: number;
76
+ prevVideo?: HTMLVideoElement;
77
+ constructor(options: Partial<KPlayerOptions> & {
78
+ video: KPlayerOptions["video"];
79
+ });
80
+ seek(time: number): void;
81
+ play(fromNative?: boolean): void;
82
+ pause(fromNative?: boolean): void;
83
+ switchVolumeIcon(): void;
84
+ volume(percentage?: number, nostorage?: boolean, nonotice?: boolean): number;
85
+ toggle(): void;
86
+ on(name: string, callback: (info?: unknown) => void): void;
87
+ initMSE(video: HTMLVideoElement, type: string): void;
88
+ initVideo(video: HTMLVideoElement, type: string): void;
89
+ getHlsLevelLabel(level: HlsLevel): string;
90
+ updateHlsQualityCurrentLabel(): void;
91
+ buildHlsQualityMenu(hls: HlsInstance, HlsLib: {
92
+ Events: Record<string, string>;
93
+ isSupported: () => boolean;
94
+ DefaultConfig: {
95
+ loader: unknown;
96
+ };
97
+ } & (new (opts: unknown) => HlsInstance)): void;
98
+ switchQuality(index: number | string): void;
99
+ notice(text: string, time?: number, opacity?: number, id?: string): void;
100
+ resize(): void;
101
+ speed(rate: number): void;
102
+ destroy(): void;
103
+ static get version(): string;
104
+ private _loadSubtitleTexts;
105
+ loadSubtitleByIndex(index: number): Promise<void>;
106
+ }
107
+ export default KPlayer;
@@ -0,0 +1,14 @@
1
+ import { default as KPlayer } from './player';
2
+ declare class Setting {
3
+ player: KPlayer;
4
+ loop: boolean;
5
+ showAwaken: number;
6
+ unlimitAwaken: number;
7
+ airplayEntry: HTMLElement | null;
8
+ chromecastEntry: HTMLElement | null;
9
+ screenshotEntry: HTMLElement | null;
10
+ constructor(player: KPlayer);
11
+ hide(): void;
12
+ show(): void;
13
+ }
14
+ export default Setting;
@@ -0,0 +1,22 @@
1
+ import { default as Events } from './events';
2
+ import { SubtitleOptions } from './types';
3
+ declare class Subtitle {
4
+ container: HTMLElement;
5
+ video: HTMLVideoElement;
6
+ options: SubtitleOptions;
7
+ events: Events;
8
+ private _track;
9
+ constructor(container: HTMLElement, video: HTMLVideoElement, options: SubtitleOptions, events: Events);
10
+ init(): void;
11
+ loadVttText(vttText: string): Promise<void>;
12
+ private _onTimeUpdateBound?;
13
+ private _onTimeUpdate;
14
+ private _clearTrack;
15
+ private _parseVtt;
16
+ private _timeToSeconds;
17
+ show(): void;
18
+ hide(): void;
19
+ toggle(): void;
20
+ destroy(): void;
21
+ }
22
+ export default Subtitle;
@@ -0,0 +1,19 @@
1
+ import { default as KPlayer } from './player';
2
+ declare class Subtitles {
3
+ player: KPlayer;
4
+ constructor(player: KPlayer);
5
+ reloadTrack(): void;
6
+ clearSelected(): void;
7
+ selectSubtitle(index: number): void;
8
+ selectOff(): void;
9
+ subContainerShow(): void;
10
+ subContainerHide(): void;
11
+ hide(): void;
12
+ show(): void;
13
+ adaptiveHeight(): void;
14
+ updateUrls(urls: Array<{
15
+ url?: string;
16
+ lang?: string;
17
+ }>): void;
18
+ }
19
+ export default Subtitles;
@@ -0,0 +1,94 @@
1
+ import { KPlayerOptions } from './types';
2
+ interface TemplateOptions {
3
+ container: HTMLElement;
4
+ options: KPlayerOptions;
5
+ index: number;
6
+ tran: (key: string) => string;
7
+ }
8
+ declare class Template {
9
+ container: HTMLElement;
10
+ options: KPlayerOptions;
11
+ index: number;
12
+ tran: (key: string) => string;
13
+ volumeBar: HTMLElement;
14
+ volumeBarWrap: HTMLElement;
15
+ volumeBarWrapWrap: HTMLElement;
16
+ volumeButton: HTMLElement;
17
+ volumeButtonIcon: HTMLElement;
18
+ volumeIcon: HTMLElement;
19
+ playedBar: HTMLElement;
20
+ loadedBar: HTMLElement;
21
+ playedBarWrap: HTMLElement;
22
+ playedBarTime: HTMLElement;
23
+ awaken: HTMLElement | null;
24
+ awakenLoading: HTMLElement | null;
25
+ video: HTMLVideoElement;
26
+ bezel: HTMLElement;
27
+ playButton: HTMLElement;
28
+ mobilePlayButton: HTMLElement;
29
+ videoWrap: HTMLElement;
30
+ controllerMask: HTMLElement;
31
+ ptime: HTMLElement;
32
+ settingButton: HTMLElement;
33
+ settingBox: HTMLElement;
34
+ mask: HTMLElement;
35
+ loop: HTMLElement;
36
+ loopToggle: HTMLInputElement;
37
+ showAwaken: HTMLElement;
38
+ showAwakenToggle: HTMLInputElement;
39
+ unlimitAwaken: HTMLElement;
40
+ unlimitAwakenToggle: HTMLInputElement;
41
+ speed: HTMLElement;
42
+ speedItem: NodeListOf<HTMLElement>;
43
+ awakenOpacityBar: HTMLElement | null;
44
+ awakenOpacityBarWrap: HTMLElement | null;
45
+ awakenOpacityBarWrapWrap: HTMLElement | null;
46
+ awakenOpacityBox: HTMLElement | null;
47
+ dtime: HTMLElement;
48
+ controller: HTMLElement;
49
+ browserFullButton: HTMLElement;
50
+ webFullButton: HTMLElement;
51
+ menu: HTMLElement;
52
+ menuItem: NodeListOf<HTMLElement>;
53
+ qualityList: HTMLElement;
54
+ camareButton: HTMLElement | null;
55
+ airplayButton: HTMLElement | null;
56
+ chromecastButton: HTMLElement | null;
57
+ subtitleButton: HTMLElement | null;
58
+ subtitleButtonInner: HTMLElement | null;
59
+ subtitlesBox: HTMLElement | null;
60
+ subtitlesItem: NodeListOf<HTMLElement>;
61
+ subtitle: HTMLElement;
62
+ subtrack: HTMLTrackElement | null;
63
+ barPreview: HTMLElement;
64
+ barWrap: HTMLElement;
65
+ noticeList: HTMLElement;
66
+ infoPanel: HTMLElement | null;
67
+ infoPanelClose: HTMLElement | null;
68
+ infoVersion: HTMLElement | null;
69
+ infoFPS: HTMLElement | null;
70
+ infoType: HTMLElement | null;
71
+ infoUrl: HTMLElement | null;
72
+ infoResolution: HTMLElement | null;
73
+ infoDuration: HTMLElement | null;
74
+ infoAwakenId: HTMLElement | null;
75
+ infoAwakenApi: HTMLElement | null;
76
+ infoAwakenAmount: HTMLElement | null;
77
+ subtitlesButton: HTMLElement | {
78
+ addEventListener: () => void;
79
+ dataset: Record<string, string>;
80
+ style: Record<string, string>;
81
+ };
82
+ qualityButton: HTMLElement;
83
+ titleBar: HTMLElement | null;
84
+ titleBack: HTMLElement | null;
85
+ titleMain: HTMLElement | null;
86
+ titleDesc: HTMLElement | null;
87
+ subtitleEntry: HTMLElement | null;
88
+ qualityEntry: HTMLElement | null;
89
+ qualityItems: NodeListOf<HTMLElement>;
90
+ constructor(options: TemplateOptions);
91
+ init(): void;
92
+ static NewNotice(text: string, opacity: number, id?: string): HTMLElement;
93
+ }
94
+ export default Template;
@@ -0,0 +1,18 @@
1
+ import { default as Events } from './events';
2
+ interface ThumbnailsOptions {
3
+ container: HTMLElement;
4
+ barWidth: number;
5
+ url: string;
6
+ events?: Events;
7
+ }
8
+ declare class Thumbnails {
9
+ container: HTMLElement;
10
+ barWidth: number;
11
+ events?: Events;
12
+ constructor(options: ThumbnailsOptions);
13
+ resize(width: number, height: number, barWrapWidth: number): void;
14
+ show(): void;
15
+ move(position: number): void;
16
+ hide(): void;
17
+ }
18
+ export default Thumbnails;
@@ -0,0 +1,22 @@
1
+ import { default as KPlayer } from './player';
2
+ type TimerType = "loading" | "info" | "fps";
3
+ declare class Timer {
4
+ player: KPlayer;
5
+ types: TimerType[];
6
+ loadingChecker?: ReturnType<typeof setInterval>;
7
+ infoChecker?: ReturnType<typeof setInterval>;
8
+ enableloadingChecker: boolean;
9
+ enableinfoChecker: boolean;
10
+ enablefpsChecker: boolean;
11
+ fpsStart?: Date;
12
+ fpsIndex: number;
13
+ constructor(player: KPlayer);
14
+ init(): void;
15
+ initloadingChecker(): void;
16
+ initfpsChecker(): void;
17
+ initinfoChecker(): void;
18
+ enable(type: TimerType): void;
19
+ disable(type: TimerType): void;
20
+ destroy(): void;
21
+ }
22
+ export default Timer;