neoplayer 1.0.0

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.
@@ -0,0 +1,226 @@
1
+ /**
2
+ * Central type definitions for NeoPlayer
3
+ */
4
+ export type DanmakuType = 0 | 1 | 2 | 'right' | 'top' | 'bottom';
5
+ export interface DanmakuItem {
6
+ time: number;
7
+ type: DanmakuType;
8
+ color: number;
9
+ author: string;
10
+ text: string;
11
+ }
12
+ export interface DanmakuAPIOptions {
13
+ id: string;
14
+ address: string;
15
+ token?: string;
16
+ maximum?: number;
17
+ addition?: string[];
18
+ user?: string;
19
+ speedRate?: number;
20
+ }
21
+ export interface DanmakuOptions {
22
+ id: string;
23
+ api: string;
24
+ token?: string;
25
+ maximum?: number;
26
+ addition?: string[];
27
+ user?: string;
28
+ unlimited?: boolean;
29
+ speedRate?: number;
30
+ /** CSS value for bottom margin of the danmaku area, e.g. '60px' */
31
+ bottom?: string;
32
+ }
33
+ export interface VideoQualityOption {
34
+ name: string;
35
+ url: string;
36
+ type?: string;
37
+ }
38
+ export interface SubtitleUrlItem {
39
+ subtitle: string;
40
+ lang?: string;
41
+ name?: string;
42
+ }
43
+ export interface SubtitleOptions {
44
+ url: string | SubtitleUrlItem[];
45
+ type?: string;
46
+ fontSize?: string;
47
+ bottom?: string;
48
+ color?: string;
49
+ index?: number;
50
+ defaultSubtitle?: string | number;
51
+ }
52
+ export interface VideoOptions {
53
+ url: string;
54
+ pic?: string;
55
+ type?: string;
56
+ quality?: VideoQualityOption[];
57
+ defaultQuality?: number;
58
+ thumbnails?: string;
59
+ customType?: Record<string, (video: HTMLVideoElement, player: NeoPlayerInstance) => void>;
60
+ }
61
+ export interface ContextMenuItem {
62
+ text?: string;
63
+ key?: string;
64
+ link?: string;
65
+ click?: (player: NeoPlayerInstance) => void;
66
+ }
67
+ export interface ApiSendOptions {
68
+ url: string;
69
+ data: DanmakuItem;
70
+ success?: (data: unknown) => void;
71
+ error?: (msg?: string) => void;
72
+ }
73
+ export interface ApiReadOptions {
74
+ url: string;
75
+ success?: (data: DanmakuItem[]) => void;
76
+ error?: (msg?: string) => void;
77
+ }
78
+ export interface ApiBackend {
79
+ send: (options: ApiSendOptions) => void;
80
+ read: (options: ApiReadOptions) => void;
81
+ }
82
+ export interface HighlightItem {
83
+ text: string;
84
+ time: number;
85
+ }
86
+ export interface PluginOptions {
87
+ hls?: Record<string, unknown>;
88
+ flv?: {
89
+ mediaDataSource?: Record<string, unknown>;
90
+ config?: Record<string, unknown>;
91
+ };
92
+ dash?: Record<string, unknown>;
93
+ webtorrent?: Record<string, unknown>;
94
+ }
95
+ export interface NeoPlayerOptions {
96
+ container: HTMLElement;
97
+ live?: boolean;
98
+ autoplay?: boolean;
99
+ theme?: string;
100
+ loop?: boolean;
101
+ lang?: string;
102
+ screenshot?: boolean;
103
+ airplay?: boolean;
104
+ chromecast?: boolean;
105
+ hotkey?: boolean;
106
+ globalHotkey?: boolean;
107
+ preload?: 'none' | 'metadata' | 'auto';
108
+ volume?: number;
109
+ playbackSpeed?: number[];
110
+ apiBackend?: ApiBackend;
111
+ video: VideoOptions;
112
+ subtitle?: SubtitleOptions;
113
+ danmaku?: DanmakuOptions;
114
+ contextmenu?: ContextMenuItem[];
115
+ highlight?: HighlightItem[];
116
+ mutex?: boolean;
117
+ pluginOptions?: PluginOptions;
118
+ preventClickToggle?: boolean;
119
+ /** @deprecated use container */
120
+ element?: HTMLElement;
121
+ }
122
+ export type UserKey = 'opacity' | 'volume' | 'unlimited' | 'danmaku' | 'subtitle';
123
+ export interface UserStorageMap {
124
+ opacity: string;
125
+ volume: string;
126
+ unlimited: string;
127
+ danmaku: string;
128
+ subtitle: string;
129
+ }
130
+ export interface UserDefaults {
131
+ opacity: number;
132
+ volume: number;
133
+ unlimited: number;
134
+ danmaku: number;
135
+ subtitle: number;
136
+ }
137
+ export type VideoEventName = 'abort' | 'canplay' | 'canplaythrough' | 'durationchange' | 'emptied' | 'ended' | 'error' | 'loadeddata' | 'loadedmetadata' | 'loadstart' | 'mozaudioavailable' | 'pause' | 'play' | 'playing' | 'progress' | 'ratechange' | 'seeked' | 'seeking' | 'stalled' | 'suspend' | 'timeupdate' | 'volumechange' | 'waiting';
138
+ export type PlayerEventName = 'screenshot' | 'thumbnails_show' | 'thumbnails_hide' | 'danmaku_show' | 'danmaku_hide' | 'danmaku_clear' | 'danmaku_loaded' | 'danmaku_send' | 'danmaku_opacity' | 'danmaku_load_start' | 'danmaku_load_end' | 'contextmenu_show' | 'contextmenu_hide' | 'notice_show' | 'notice_hide' | 'quality_start' | 'quality_end' | 'destroy' | 'resize' | 'fullscreen' | 'fullscreen_cancel' | 'webfullscreen' | 'webfullscreen_cancel' | 'subtitle_show' | 'subtitle_hide' | 'subtitle_change';
139
+ export type AllEventName = VideoEventName | PlayerEventName;
140
+ export type EventCallback = (info?: unknown) => void;
141
+ export type BarType = 'volume' | 'played' | 'loaded' | 'danmaku';
142
+ export type BarDirection = 'width' | 'height';
143
+ export type FullScreenType = 'browser' | 'web';
144
+ export interface ScrollPosition {
145
+ left: number;
146
+ top: number;
147
+ }
148
+ export interface DanmakuConstructorOptions {
149
+ player: NeoPlayerInstance;
150
+ container: HTMLElement;
151
+ opacity: number;
152
+ callback: () => void;
153
+ error: (msg?: string) => void;
154
+ apiBackend: ApiBackend;
155
+ borderColor: string;
156
+ height: number;
157
+ time: () => number;
158
+ unlimited: number;
159
+ api: DanmakuAPIOptions;
160
+ events: import('./events').default;
161
+ tran: (key: string) => string;
162
+ }
163
+ export interface ThumbnailsOptions {
164
+ container: HTMLElement;
165
+ barWidth: number;
166
+ url: string;
167
+ events: import('./events').default;
168
+ }
169
+ export interface TemplateConstructorOptions {
170
+ container: HTMLElement;
171
+ options: NeoPlayerOptions;
172
+ index: number;
173
+ tran: (key: string) => string;
174
+ }
175
+ export interface NeoPlayerInstance {
176
+ options: NeoPlayerOptions;
177
+ video: HTMLVideoElement;
178
+ prevVideo: HTMLVideoElement | null;
179
+ container: HTMLElement;
180
+ paused: boolean;
181
+ focus: boolean;
182
+ moveBar: boolean;
183
+ type: string;
184
+ qualityIndex: number;
185
+ prevIndex: number;
186
+ quality: VideoQualityOption | undefined;
187
+ switchingQuality: boolean;
188
+ arrow: boolean;
189
+ noticeList: Record<string, ReturnType<typeof setTimeout> | null>;
190
+ _savedPlaybackRate: number;
191
+ plugins: Record<string, unknown>;
192
+ docClickFun: (() => void) | null;
193
+ containerClickFun: (() => void) | null;
194
+ tran: (key: string) => string;
195
+ events: import('./events').default;
196
+ user: import('./user').default;
197
+ template: import('./template').default;
198
+ bar: import('./bar').default;
199
+ bezel: import('./bezel').default;
200
+ fullScreen: import('./fullscreen').default;
201
+ controller: import('./controller').default;
202
+ danmaku?: import('./danmaku').default;
203
+ comment?: import('./comment').default;
204
+ setting: import('./setting').default;
205
+ hotkey: import('./hotkey').default;
206
+ contextmenu: import('./contextmenu').default;
207
+ infoPanel: import('./info-panel').default;
208
+ timer: import('./timer').default;
209
+ subtitle?: import('./subtitle').default;
210
+ subtitles?: import('./subtitles').default;
211
+ play(fromNative?: boolean): void;
212
+ pause(fromNative?: boolean): void;
213
+ toggle(): void;
214
+ seek(time: number, nonotice?: boolean): void;
215
+ volume(percentage?: number, nostorage?: boolean, nonotice?: boolean): number;
216
+ speed(rate: number): void;
217
+ switchVolumeIcon(): void;
218
+ notice(text: string, time?: number, opacity?: number, id?: string): void;
219
+ resize(): void;
220
+ destroy(): void;
221
+ on(name: AllEventName, callback: EventCallback): void;
222
+ initVideo(video: HTMLVideoElement, type: string): void;
223
+ initMSE(video: HTMLVideoElement, type: string): void;
224
+ switchQuality(index: number | string): void;
225
+ switchVideo(video: VideoOptions, danmakuAPI?: DanmakuOptions): void;
226
+ }
@@ -0,0 +1,11 @@
1
+ import { NeoPlayerInstance, UserKey } from './types';
2
+ declare class User {
3
+ private readonly storageName;
4
+ private readonly default;
5
+ private data;
6
+ constructor(player: NeoPlayerInstance);
7
+ private init;
8
+ get(key: UserKey): number;
9
+ set(key: UserKey, value: number): void;
10
+ }
11
+ export default User;
@@ -0,0 +1,34 @@
1
+ import { ScrollPosition } from './types';
2
+ declare const utils: {
3
+ /**
4
+ * Parse seconds into a time string (MM:SS or HH:MM:SS)
5
+ */
6
+ secondToTime(second: number): string;
7
+ /**
8
+ * Get element's left offset relative to viewport (legacy approach)
9
+ */
10
+ getElementViewLeft(element: HTMLElement): number;
11
+ /**
12
+ * Optimised: get element's left offset via getBoundingClientRect
13
+ */
14
+ getBoundingClientRectViewLeft(element: HTMLElement): number;
15
+ getScrollPosition(): ScrollPosition;
16
+ setScrollPosition({ left, top }: Partial<ScrollPosition>): void;
17
+ isMobile: boolean;
18
+ isFirefox: boolean;
19
+ isChrome: boolean;
20
+ isSafari: boolean;
21
+ storage: {
22
+ set(key: string, value: string | number): void;
23
+ get(key: string): string | null;
24
+ };
25
+ nameMap: {
26
+ readonly dragStart: "touchstart" | "mousedown";
27
+ readonly dragMove: "touchmove" | "mousemove";
28
+ readonly dragEnd: "touchend" | "mouseup";
29
+ };
30
+ color2Number(color: string): number;
31
+ number2Color(number: number): string;
32
+ number2Type(number: number | string): "right" | "top" | "bottom";
33
+ };
34
+ export default utils;
package/package.json ADDED
@@ -0,0 +1,96 @@
1
+ {
2
+ "name": "neoplayer",
3
+ "version": "1.0.0",
4
+ "description": "NeoPlayer is an HTML5 danmaku video player with comprehensive keyboard shortcuts.",
5
+ "main": "dist/NeoPlayer.min.js",
6
+ "module": "dist/NeoPlayer.esm.js",
7
+ "types": "dist/types/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/NeoPlayer.esm.js",
11
+ "require": "./dist/NeoPlayer.min.js",
12
+ "types": "./dist/types/index.d.ts"
13
+ },
14
+ "./dist/NeoPlayer.css": "./dist/NeoPlayer.css"
15
+ },
16
+ "sideEffects": [
17
+ "*.css"
18
+ ],
19
+ "scripts": {
20
+ "start": "npm run dev",
21
+ "build": "rollup -c rollup.config.mjs",
22
+ "dev": "rollup -c rollup.config.mjs --watch",
23
+ "typecheck": "tsc --noEmit",
24
+ "test": "",
25
+ "format": "prettier \"**/*.{ts,js,json,md}\" --write",
26
+ "format:check": "prettier \"**/*.{ts,js,json,md}\" --check",
27
+ "docs:dev": "npm run build && npm --prefix docs run docs:dev",
28
+ "docs:build": "npm run build && npm --prefix docs run docs:build",
29
+ "prepare": "node -e \"try{require('husky').install()}catch(e){if(e.code!=='MODULE_NOT_FOUND')throw e}\"",
30
+ "prepublishOnly": "npm run build && npm run typecheck"
31
+ },
32
+ "lint-staged": {
33
+ "**/*": "prettier --write --ignore-unknown"
34
+ },
35
+ "files": [
36
+ "dist/NeoPlayer.css",
37
+ "dist/NeoPlayer.min.js",
38
+ "dist/NeoPlayer.min.js.map",
39
+ "dist/NeoPlayer.esm.js",
40
+ "dist/NeoPlayer.esm.js.map",
41
+ "dist/types"
42
+ ],
43
+ "repository": {
44
+ "url": "git+https://github.com/Fluxonide/NeoPlayer.git",
45
+ "type": "git"
46
+ },
47
+ "keywords": [
48
+ "player",
49
+ "danmaku",
50
+ "video",
51
+ "html5"
52
+ ],
53
+ "author": "Fluxonide",
54
+ "license": "MIT",
55
+ "bugs": {
56
+ "url": "https://github.com/Fluxonide/NeoPlayer/issues"
57
+ },
58
+ "homepage": "https://github.com/Fluxonide/NeoPlayer#readme",
59
+ "devDependencies": {
60
+ "@rollup/plugin-commonjs": "^26.0.1",
61
+ "@rollup/plugin-node-resolve": "^15.2.3",
62
+ "@rollup/plugin-replace": "^5.0.7",
63
+ "@rollup/plugin-typescript": "^11.1.6",
64
+ "@rollup/plugin-url": "^8.0.2",
65
+ "@types/node": "^20.5.0",
66
+ "@vuepress/plugin-pwa": "1.9.9",
67
+ "autoprefixer": "^10.4.15",
68
+ "cssnano": "^6.0.1",
69
+ "husky": "^8.0.3",
70
+ "less": "^4.2.0",
71
+ "lint-staged": "^17.0.0",
72
+ "postcss": "^8.4.27",
73
+ "postcss-preset-env": "^9.1.1",
74
+ "prettier": "^3.0.1",
75
+ "pretty-quick": "^4.0.0",
76
+ "rollup": "^4.18.0",
77
+ "rollup-plugin-livereload": "^2.0.5",
78
+ "rollup-plugin-postcss": "^4.0.2",
79
+ "rollup-plugin-serve": "^2.0.2",
80
+ "rollup-plugin-string": "^3.0.0",
81
+ "tslib": "^2.6.2",
82
+ "typescript": "^5.2.2"
83
+ },
84
+ "dependencies": {
85
+ "axios": "^1.18.1",
86
+ "balloon-css": "^1.0.3",
87
+ "promise-polyfill": "8.3.0"
88
+ },
89
+ "overrides": {
90
+ "braces": "^3.0.3",
91
+ "micromatch": "^4.0.8",
92
+ "cross-spawn": "^7.0.6",
93
+ "highlight.js": "^11.9.0",
94
+ "http-proxy-middleware": "^3.0.0"
95
+ }
96
+ }