@wapri/gplayer 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +70 -3
- package/dist/VideoPlayer/index.d.ts +122 -0
- package/dist/VideoPlayer/index.vue.d.ts +72 -0
- package/dist/constant/icons.d.ts +4 -0
- package/dist/constant/index.d.ts +66 -0
- package/dist/core/icon.d.ts +5 -0
- package/dist/core/install.d.ts +7 -0
- package/dist/core/option.d.ts +10 -0
- package/dist/core/registry.d.ts +29 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.mjs +427 -0
- package/dist/plugins/abLoop.d.ts +3 -0
- package/dist/plugins/aspectRatio.d.ts +3 -0
- package/dist/plugins/filter.d.ts +3 -0
- package/dist/plugins/flip.d.ts +3 -0
- package/dist/plugins/index.d.ts +12 -0
- package/dist/plugins/pip.d.ts +3 -0
- package/dist/plugins/playbackRate.d.ts +3 -0
- package/dist/plugins/screenshot.d.ts +3 -0
- package/dist/types/player.d.ts +65 -0
- package/dist/types/plugin.d.ts +136 -0
- package/package.json +26 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wapri contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,70 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# @wapri/gplayer
|
|
2
|
+
|
|
3
|
+
基于 [artplayer](https://artplayer.org) 的 Vue 3 视频播放器组件:`<VideoPlayer>` 一个标签就能播,卸载时实例与监听一起回收;插件用 `key` 声明,内置插件各占右侧菜单一项。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @wapri/gplayer artplayer
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 快速开始
|
|
12
|
+
|
|
13
|
+
```vue
|
|
14
|
+
<template>
|
|
15
|
+
<VideoPlayer
|
|
16
|
+
url="https://www.w3schools.com/html/mov_bbb.mp4#t=0.1"
|
|
17
|
+
:plugins="['screenshot', { key: 'pip', setting: () => ({ autoEnter: true }) }]"
|
|
18
|
+
/>
|
|
19
|
+
</template>
|
|
20
|
+
|
|
21
|
+
<script setup lang="ts">
|
|
22
|
+
import { VideoPlayer } from '@wapri/gplayer'
|
|
23
|
+
</script>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 插件
|
|
27
|
+
|
|
28
|
+
`plugins` 的每一项可以是字符串(存在即启用,走默认配置),也可以是 `{ key, setting }`:
|
|
29
|
+
|
|
30
|
+
- `setting` 收到该插件的完整默认配置,返回要覆盖的字段。
|
|
31
|
+
- 同一个 key 只安装一次,后出现的配置覆盖先出现的;未注册的 key 警告后跳过。
|
|
32
|
+
- 需要在 `setting` 里读字段时用 `pluginEntry('key', fn)`,`config` 会带上该插件的类型。
|
|
33
|
+
|
|
34
|
+
内置插件:`playbackRate`、`aspectRatio`、`flip`、`screenshot`、`pip`、`abLoop`、`filter`。
|
|
35
|
+
|
|
36
|
+
自定义插件:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { definePlugin, registerPlugin } from '@wapri/gplayer'
|
|
40
|
+
|
|
41
|
+
registerPlugin(
|
|
42
|
+
definePlugin({
|
|
43
|
+
key: 'watermark',
|
|
44
|
+
label: '水印',
|
|
45
|
+
defaultConfig: { text: 'wapri' },
|
|
46
|
+
install({ art, setting, onCleanup }, config) {
|
|
47
|
+
// setting 与内置插件共用同一套右侧菜单 API
|
|
48
|
+
},
|
|
49
|
+
}),
|
|
50
|
+
)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## API
|
|
54
|
+
|
|
55
|
+
| 能力 | 说明 |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| Props | `url`、`poster`、`theme`、`lang`、`autoplay`、`muted`、`loop`、`volume`、`height`、`plugins`、`options` |
|
|
58
|
+
| Events | `ready`、`play`、`pause`、`ended`、`timeupdate`、`seek`、`error`、`volumechange`、`ratechange`、`flip`、`pip`、`screenshot`、`fullscreen`、`fullscreen-web`、`destroy` |
|
|
59
|
+
| 实例方法 | `player`、`play`、`pause`、`toggle`、`seek`、`screenshot`、`fullscreen` |
|
|
60
|
+
| 注册表 | `registerPlugin`、`definePlugin`、`pluginEntry`、`getPlugin`、`listPlugins`、`builtinPlugins` |
|
|
61
|
+
|
|
62
|
+
## 注意
|
|
63
|
+
|
|
64
|
+
- `plugins` 与 `options` 变化会重建实例,播放进度与播放状态会自动接上。
|
|
65
|
+
- 截图走 canvas 重绘,视频源需允许跨域;画面调节的滤镜会被一起画进截图。
|
|
66
|
+
- HLS / FLV 等流协议由业务通过 `options.customType` 或 artplayer 生态插件接入。
|
|
67
|
+
|
|
68
|
+
## 在线文档
|
|
69
|
+
|
|
70
|
+
https://sdmu-gaoqi.github.io/wapri/players
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { VideoPlayerInstance, VideoPlayerProps } from '../types/player';
|
|
2
|
+
|
|
3
|
+
export declare const VideoPlayer: import('../core/install').SFCWithInstall<import('vue').DefineComponent<import('vue').ExtractPropTypes<{
|
|
4
|
+
plugins: {
|
|
5
|
+
type: import('vue').PropType<import('..').PluginInput[]>;
|
|
6
|
+
default: () => never[];
|
|
7
|
+
};
|
|
8
|
+
url: {
|
|
9
|
+
type: import('vue').PropType<string>;
|
|
10
|
+
required: true;
|
|
11
|
+
};
|
|
12
|
+
poster: {
|
|
13
|
+
type: import('vue').PropType<string>;
|
|
14
|
+
};
|
|
15
|
+
theme: {
|
|
16
|
+
type: import('vue').PropType<string>;
|
|
17
|
+
};
|
|
18
|
+
lang: {
|
|
19
|
+
type: import('vue').PropType<string>;
|
|
20
|
+
};
|
|
21
|
+
volume: {
|
|
22
|
+
type: import('vue').PropType<number>;
|
|
23
|
+
};
|
|
24
|
+
muted: {
|
|
25
|
+
type: import('vue').PropType<boolean>;
|
|
26
|
+
};
|
|
27
|
+
autoplay: {
|
|
28
|
+
type: import('vue').PropType<boolean>;
|
|
29
|
+
};
|
|
30
|
+
loop: {
|
|
31
|
+
type: import('vue').PropType<boolean>;
|
|
32
|
+
};
|
|
33
|
+
height: {
|
|
34
|
+
type: import('vue').PropType<string | number>;
|
|
35
|
+
};
|
|
36
|
+
options: {
|
|
37
|
+
type: import('vue').PropType<import('../types/player').PlayerOption>;
|
|
38
|
+
default: () => {};
|
|
39
|
+
};
|
|
40
|
+
}>, {
|
|
41
|
+
player: import('artplayer/legacy').default | undefined;
|
|
42
|
+
play: () => Promise<void> | undefined;
|
|
43
|
+
pause: () => void;
|
|
44
|
+
toggle: () => void;
|
|
45
|
+
seek: (time: number) => void;
|
|
46
|
+
screenshot: (name?: string) => Promise<string> | undefined;
|
|
47
|
+
fullscreen: (state?: boolean) => void;
|
|
48
|
+
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
49
|
+
ready: () => void;
|
|
50
|
+
play: () => void;
|
|
51
|
+
pause: () => void;
|
|
52
|
+
ended: () => void;
|
|
53
|
+
timeupdate: () => void;
|
|
54
|
+
volumechange: () => void;
|
|
55
|
+
ratechange: () => void;
|
|
56
|
+
seek: (currentTime: number, time: number) => void;
|
|
57
|
+
error: (error: Error, reconnectTime: number) => void;
|
|
58
|
+
flip: (mode: import('..').FlipMode) => void;
|
|
59
|
+
pip: (state: boolean) => void;
|
|
60
|
+
screenshot: (dataUri: string) => void;
|
|
61
|
+
fullscreen: (state: boolean) => void;
|
|
62
|
+
"fullscreen-web": (state: boolean) => void;
|
|
63
|
+
destroy: () => void;
|
|
64
|
+
}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
|
|
65
|
+
plugins: {
|
|
66
|
+
type: import('vue').PropType<import('..').PluginInput[]>;
|
|
67
|
+
default: () => never[];
|
|
68
|
+
};
|
|
69
|
+
url: {
|
|
70
|
+
type: import('vue').PropType<string>;
|
|
71
|
+
required: true;
|
|
72
|
+
};
|
|
73
|
+
poster: {
|
|
74
|
+
type: import('vue').PropType<string>;
|
|
75
|
+
};
|
|
76
|
+
theme: {
|
|
77
|
+
type: import('vue').PropType<string>;
|
|
78
|
+
};
|
|
79
|
+
lang: {
|
|
80
|
+
type: import('vue').PropType<string>;
|
|
81
|
+
};
|
|
82
|
+
volume: {
|
|
83
|
+
type: import('vue').PropType<number>;
|
|
84
|
+
};
|
|
85
|
+
muted: {
|
|
86
|
+
type: import('vue').PropType<boolean>;
|
|
87
|
+
};
|
|
88
|
+
autoplay: {
|
|
89
|
+
type: import('vue').PropType<boolean>;
|
|
90
|
+
};
|
|
91
|
+
loop: {
|
|
92
|
+
type: import('vue').PropType<boolean>;
|
|
93
|
+
};
|
|
94
|
+
height: {
|
|
95
|
+
type: import('vue').PropType<string | number>;
|
|
96
|
+
};
|
|
97
|
+
options: {
|
|
98
|
+
type: import('vue').PropType<import('../types/player').PlayerOption>;
|
|
99
|
+
default: () => {};
|
|
100
|
+
};
|
|
101
|
+
}>> & Readonly<{
|
|
102
|
+
onScreenshot?: ((dataUri: string) => any) | undefined;
|
|
103
|
+
onFlip?: ((mode: import('..').FlipMode) => any) | undefined;
|
|
104
|
+
onPip?: ((state: boolean) => any) | undefined;
|
|
105
|
+
onFullscreen?: ((state: boolean) => any) | undefined;
|
|
106
|
+
onReady?: (() => any) | undefined;
|
|
107
|
+
onPlay?: (() => any) | undefined;
|
|
108
|
+
onPause?: (() => any) | undefined;
|
|
109
|
+
onEnded?: (() => any) | undefined;
|
|
110
|
+
onTimeupdate?: (() => any) | undefined;
|
|
111
|
+
onVolumechange?: (() => any) | undefined;
|
|
112
|
+
onRatechange?: (() => any) | undefined;
|
|
113
|
+
onSeek?: ((currentTime: number, time: number) => any) | undefined;
|
|
114
|
+
onError?: ((error: Error, reconnectTime: number) => any) | undefined;
|
|
115
|
+
"onFullscreen-web"?: ((state: boolean) => any) | undefined;
|
|
116
|
+
onDestroy?: (() => any) | undefined;
|
|
117
|
+
}>, {
|
|
118
|
+
plugins: import('..').PluginInput[];
|
|
119
|
+
options: import('../types/player').PlayerOption;
|
|
120
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>>;
|
|
121
|
+
export type { VideoPlayerInstance, VideoPlayerProps };
|
|
122
|
+
export default VideoPlayer;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { default as Artplayer } from 'artplayer';
|
|
2
|
+
import { FlipMode } from '../types/plugin';
|
|
3
|
+
import { VideoPlayerProps } from '../types/player';
|
|
4
|
+
|
|
5
|
+
declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<VideoPlayerProps>, {
|
|
6
|
+
plugins: () => never[];
|
|
7
|
+
options: () => {};
|
|
8
|
+
}>>, {
|
|
9
|
+
player: Artplayer | undefined;
|
|
10
|
+
play: () => Promise<void> | undefined;
|
|
11
|
+
pause: () => void;
|
|
12
|
+
toggle: () => void;
|
|
13
|
+
seek: (time: number) => void;
|
|
14
|
+
screenshot: (name?: string) => Promise<string> | undefined;
|
|
15
|
+
fullscreen: (state?: boolean) => void;
|
|
16
|
+
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
17
|
+
ready: () => void;
|
|
18
|
+
play: () => void;
|
|
19
|
+
pause: () => void;
|
|
20
|
+
ended: () => void;
|
|
21
|
+
timeupdate: () => void;
|
|
22
|
+
volumechange: () => void;
|
|
23
|
+
ratechange: () => void;
|
|
24
|
+
seek: (currentTime: number, time: number) => void;
|
|
25
|
+
error: (error: Error, reconnectTime: number) => void;
|
|
26
|
+
flip: (mode: FlipMode) => void;
|
|
27
|
+
pip: (state: boolean) => void;
|
|
28
|
+
screenshot: (dataUri: string) => void;
|
|
29
|
+
fullscreen: (state: boolean) => void;
|
|
30
|
+
"fullscreen-web": (state: boolean) => void;
|
|
31
|
+
destroy: () => void;
|
|
32
|
+
}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<VideoPlayerProps>, {
|
|
33
|
+
plugins: () => never[];
|
|
34
|
+
options: () => {};
|
|
35
|
+
}>>> & Readonly<{
|
|
36
|
+
onScreenshot?: ((dataUri: string) => any) | undefined;
|
|
37
|
+
onFlip?: ((mode: FlipMode) => any) | undefined;
|
|
38
|
+
onPip?: ((state: boolean) => any) | undefined;
|
|
39
|
+
onFullscreen?: ((state: boolean) => any) | undefined;
|
|
40
|
+
onReady?: (() => any) | undefined;
|
|
41
|
+
onPlay?: (() => any) | undefined;
|
|
42
|
+
onPause?: (() => any) | undefined;
|
|
43
|
+
onEnded?: (() => any) | undefined;
|
|
44
|
+
onTimeupdate?: (() => any) | undefined;
|
|
45
|
+
onVolumechange?: (() => any) | undefined;
|
|
46
|
+
onRatechange?: (() => any) | undefined;
|
|
47
|
+
onSeek?: ((currentTime: number, time: number) => any) | undefined;
|
|
48
|
+
onError?: ((error: Error, reconnectTime: number) => any) | undefined;
|
|
49
|
+
"onFullscreen-web"?: ((state: boolean) => any) | undefined;
|
|
50
|
+
onDestroy?: (() => any) | undefined;
|
|
51
|
+
}>, {
|
|
52
|
+
plugins: import('../types/plugin').PluginInput[];
|
|
53
|
+
options: import('../types/player').PlayerOption;
|
|
54
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
55
|
+
export default _default;
|
|
56
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
57
|
+
type __VLS_TypePropsToRuntimeProps<T> = {
|
|
58
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
59
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
60
|
+
} : {
|
|
61
|
+
type: import('vue').PropType<T[K]>;
|
|
62
|
+
required: true;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
type __VLS_WithDefaults<P, D> = {
|
|
66
|
+
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
|
|
67
|
+
default: D[K];
|
|
68
|
+
}> : P[K];
|
|
69
|
+
};
|
|
70
|
+
type __VLS_Prettify<T> = {
|
|
71
|
+
[K in keyof T]: T[K];
|
|
72
|
+
} & {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** AB 循环:首尾相接的双向箭头 */
|
|
2
|
+
export declare const abLoopIcon = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"22\" height=\"22\" viewBox=\"0 0 24 24\" fill=\"currentColor\">\n <path d=\"M17 2l4 4-4 4V7H7a3 3 0 0 0-3 3v1H2v-1a5 5 0 0 1 5-5h10V2z\"/>\n <path d=\"M7 22l-4-4 4-4v3h10a3 3 0 0 0 3-3v-1h2v1a5 5 0 0 1-5 5H7v3z\"/>\n</svg>";
|
|
3
|
+
/** 画面调节:三条滑杆 */
|
|
4
|
+
export declare const filterIcon = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"22\" height=\"22\" viewBox=\"0 0 24 24\" fill=\"currentColor\">\n <path d=\"M3 5h18v2H3V5zm0 6h18v2H3v-2zm0 6h18v2H3v-2z\" opacity=\".35\"/>\n <circle cx=\"8\" cy=\"6\" r=\"3\"/>\n <circle cx=\"15\" cy=\"12\" r=\"3\"/>\n <circle cx=\"10\" cy=\"18\" r=\"3\"/>\n</svg>";
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { AspectRatioValue, FlipMode, ScreenshotType } from '../types/plugin';
|
|
2
|
+
|
|
3
|
+
/** 包名,用于日志与提示前缀 */
|
|
4
|
+
export declare const packageName = "@wapri/gplayer";
|
|
5
|
+
/** 组件类名前缀,同时用于根容器与自定义图标 */
|
|
6
|
+
export declare const prefix = "wa-player";
|
|
7
|
+
/** 未传 `height` 时的容器比例 */
|
|
8
|
+
export declare const defaultPlayerRatio = "16 / 9";
|
|
9
|
+
/** 未传 `options` 时透传给 artplayer 的默认配置 */
|
|
10
|
+
export declare const defaultPlayerOption: {
|
|
11
|
+
lang: string;
|
|
12
|
+
setting: boolean;
|
|
13
|
+
fullscreen: boolean;
|
|
14
|
+
miniProgressBar: boolean;
|
|
15
|
+
};
|
|
16
|
+
/** 倍速插件的默认语速列表 */
|
|
17
|
+
export declare const defaultPlaybackRates: number[];
|
|
18
|
+
/** 倍速插件的默认语速 */
|
|
19
|
+
export declare const defaultPlaybackRate = 1;
|
|
20
|
+
/** 画面比例插件的默认比例列表 */
|
|
21
|
+
export declare const defaultAspectRatios: AspectRatioValue[];
|
|
22
|
+
/** 画面比例插件的默认比例 */
|
|
23
|
+
export declare const defaultAspectRatio: AspectRatioValue;
|
|
24
|
+
/** 翻转插件的默认方向列表 */
|
|
25
|
+
export declare const defaultFlipModes: FlipMode[];
|
|
26
|
+
/** 翻转插件的默认方向 */
|
|
27
|
+
export declare const defaultFlipMode: FlipMode;
|
|
28
|
+
/** 截图插件的默认文件名前缀 */
|
|
29
|
+
export declare const defaultScreenshotName = "screenshot";
|
|
30
|
+
/** 截图插件的默认图片格式 */
|
|
31
|
+
export declare const defaultScreenshotType = "image/png";
|
|
32
|
+
/** 截图插件的默认图片质量,仅 jpeg / webp 生效 */
|
|
33
|
+
export declare const defaultScreenshotQuality = 0.92;
|
|
34
|
+
/** 截图格式到文件后缀的映射 */
|
|
35
|
+
export declare const screenshotExtMap: Record<ScreenshotType, string>;
|
|
36
|
+
/** AB 循环插件默认的回跳提前量(秒) */
|
|
37
|
+
export declare const defaultAbLoopOffset = 0;
|
|
38
|
+
/** 画面调节插件的默认取值与区间 */
|
|
39
|
+
export declare const defaultFilterValue = 100;
|
|
40
|
+
export declare const defaultFilterMin = 0;
|
|
41
|
+
export declare const defaultFilterMax = 200;
|
|
42
|
+
export declare const defaultFilterStep = 1;
|
|
43
|
+
/** 各插件在右侧菜单里的名称 */
|
|
44
|
+
export declare const playbackRateLabel = "\u64AD\u653E\u901F\u5EA6";
|
|
45
|
+
export declare const aspectRatioLabel = "\u753B\u9762\u6BD4\u4F8B";
|
|
46
|
+
export declare const flipLabel = "\u753B\u9762\u7FFB\u8F6C";
|
|
47
|
+
export declare const screenshotLabel = "\u622A\u56FE";
|
|
48
|
+
export declare const pipLabel = "\u753B\u4E2D\u753B";
|
|
49
|
+
export declare const abLoopLabel = "AB \u5FAA\u73AF";
|
|
50
|
+
export declare const filterLabel = "\u753B\u9762\u8C03\u8282";
|
|
51
|
+
/** AB 循环插件的菜单项文案 */
|
|
52
|
+
export declare const abLoopSetStartText = "\u8BBE\u7F6E A \u70B9";
|
|
53
|
+
export declare const abLoopSetEndText = "\u8BBE\u7F6E B \u70B9";
|
|
54
|
+
export declare const abLoopClearText = "\u6E05\u9664 A-B";
|
|
55
|
+
export declare const abLoopEmptyTip = "\u672A\u8BBE\u7F6E";
|
|
56
|
+
/** AB 循环里只设了一个点时的占位 */
|
|
57
|
+
export declare const abLoopUnsetText = "--:--";
|
|
58
|
+
/** 画面调节插件的菜单项文案 */
|
|
59
|
+
export declare const filterBrightnessText = "\u4EAE\u5EA6";
|
|
60
|
+
export declare const filterContrastText = "\u5BF9\u6BD4\u5EA6";
|
|
61
|
+
export declare const filterSaturateText = "\u9971\u548C\u5EA6";
|
|
62
|
+
export declare const filterResetText = "\u6062\u590D\u9ED8\u8BA4";
|
|
63
|
+
/** 画中画插件的提示文案 */
|
|
64
|
+
export declare const pipUnsupportedText = "\u5F53\u524D\u6D4F\u89C8\u5668\u4E0D\u652F\u6301\u753B\u4E2D\u753B";
|
|
65
|
+
/** 截图插件的失败提示 */
|
|
66
|
+
export declare const screenshotFailedText = "\u622A\u56FE\u5931\u8D25\uFF0C\u89C6\u9891\u6E90\u9700\u5F00\u542F\u8DE8\u57DF\uFF08CORS\uFF09";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Option } from 'artplayer';
|
|
2
|
+
import { VideoPlayerProps } from '../types/player';
|
|
3
|
+
|
|
4
|
+
type PluginRunner = Option['plugins'];
|
|
5
|
+
/**
|
|
6
|
+
* 合并出 artplayer 的初始化配置。
|
|
7
|
+
* 优先级:组件默认值 < `options` < 顶层 props。
|
|
8
|
+
*/
|
|
9
|
+
export declare const resolveOption: (props: VideoPlayerProps, container: HTMLDivElement, plugins: PluginRunner) => Option;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { default as Artplayer } from 'artplayer';
|
|
2
|
+
import { BuiltinPluginKey, PluginConfig, PluginConfigMap, PluginDefinition, PluginEntry, PluginInput, PluginSetting, ResolvedPlugin } from '../types/plugin';
|
|
3
|
+
|
|
4
|
+
/** 注册插件;同 key 覆盖已有定义 */
|
|
5
|
+
export declare const registerPlugin: (definition: PluginDefinition) => PluginDefinition<PluginConfig>;
|
|
6
|
+
/** 声明插件,仅做类型推导,运行时原样返回 */
|
|
7
|
+
export declare const definePlugin: <T extends PluginConfig>(definition: PluginDefinition<T>) => PluginDefinition<T>;
|
|
8
|
+
/**
|
|
9
|
+
* 生成插件条目。
|
|
10
|
+
* `key` 命中内置插件时,`setting` 的入参带该插件的完整配置类型,可以直接读字段。
|
|
11
|
+
*/
|
|
12
|
+
export declare const pluginEntry: <K extends BuiltinPluginKey>(key: K, setting?: PluginSetting<PluginConfigMap[K]>) => PluginEntry;
|
|
13
|
+
/** 按 key 取插件定义 */
|
|
14
|
+
export declare const getPlugin: (key: string) => PluginDefinition<PluginConfig> | undefined;
|
|
15
|
+
/** 当前已注册的插件列表 */
|
|
16
|
+
export declare const listPlugins: () => PluginDefinition<PluginConfig>[];
|
|
17
|
+
/**
|
|
18
|
+
* 把 `plugins` 入参解析成待安装列表。
|
|
19
|
+
* 同一个 key 只保留一份,后出现的配置覆盖先出现的;未知 key 警告后跳过。
|
|
20
|
+
*/
|
|
21
|
+
export declare const resolvePlugins: (inputs?: PluginInput[]) => ResolvedPlugin[];
|
|
22
|
+
/**
|
|
23
|
+
* 生成可以交给 `option.plugins` 的函数列表,以及统一的清理函数。
|
|
24
|
+
* artplayer 只在构造时读一次 `plugins`,运行期没有卸载能力,所以清理交给这里。
|
|
25
|
+
*/
|
|
26
|
+
export declare const createPluginRunner: (plugins: ResolvedPlugin[]) => {
|
|
27
|
+
plugins: ((art: Artplayer) => void)[];
|
|
28
|
+
dispose: () => void;
|
|
29
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { VideoPlayer, VideoPlayer as default } from './VideoPlayer';
|
|
2
|
+
export type { VideoPlayerInstance, VideoPlayerProps } from './VideoPlayer';
|
|
3
|
+
export { definePlugin, getPlugin, listPlugins, pluginEntry, registerPlugin, resolvePlugins } from './core/registry';
|
|
4
|
+
export { builtinPlugins } from './plugins';
|
|
5
|
+
export { abLoopPlugin, aspectRatioPlugin, filterPlugin, flipPlugin, pipPlugin, playbackRatePlugin, screenshotPlugin, } from './plugins';
|
|
6
|
+
export { defaultPlayerRatio, packageName, prefix } from './constant';
|
|
7
|
+
export type { AbLoopConfig, AspectRatioConfig, AspectRatioValue, BuiltinPluginKey, FilterConfig, FlipConfig, FlipMode, PipConfig, PlaybackRateConfig, PluginConfig, PluginConfigMap, PluginContext, PluginDefinition, PluginEntry, PluginInput, PluginSetting, ResolvedPlugin, ScreenshotConfig, ScreenshotResult, ScreenshotType, } from './types/plugin';
|
|
8
|
+
export type { PlayerOption, VideoPlayerEmits } from './types/player';
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import { defineComponent as N, ref as H, shallowRef as I, computed as V, watch as m, onMounted as U, onBeforeUnmount as _, openBlock as A, createElementBlock as O, normalizeStyle as j, normalizeClass as W, unref as q } from "vue";
|
|
2
|
+
import x from "artplayer";
|
|
3
|
+
import { downloadBlob as D } from "@wapri/gbase";
|
|
4
|
+
const z = "@wapri/gplayer", K = "wa-player", Q = "16 / 9", G = {
|
|
5
|
+
lang: "zh-cn",
|
|
6
|
+
// 右侧菜单是插件的载体,默认打开
|
|
7
|
+
setting: !0,
|
|
8
|
+
fullscreen: !0,
|
|
9
|
+
miniProgressBar: !0
|
|
10
|
+
}, J = [0.5, 0.75, 1, 1.25, 1.5, 2], k = 1, X = ["default", "16:9", "4:3", "21:9"], y = "default", Y = ["normal", "horizontal", "vertical"], C = "normal", Z = "screenshot", ee = "image/png", te = 0.92, ne = {
|
|
11
|
+
"image/png": "png",
|
|
12
|
+
"image/jpeg": "jpg",
|
|
13
|
+
"image/webp": "webp"
|
|
14
|
+
}, le = 0, b = 100, oe = 0, ae = 200, ie = 1, se = "播放速度", ce = "画面比例", ue = "画面翻转", re = "截图", pe = "画中画", S = "AB 循环", de = "画面调节", fe = "设置 A 点", me = "设置 B 点", he = "清除 A-B", E = "未设置", ve = "--:--", ge = "亮度", ye = "对比度", be = "饱和度", we = "恢复默认", L = "截图失败,视频源需开启跨域(CORS)", Re = (e) => Object.fromEntries(Object.entries(e).filter(([, s]) => s !== void 0)), xe = (e, s, o) => {
|
|
15
|
+
var t, a, i, c, r, d, p;
|
|
16
|
+
return Re({
|
|
17
|
+
...G,
|
|
18
|
+
...e.options,
|
|
19
|
+
url: e.url,
|
|
20
|
+
poster: e.poster ?? ((t = e.options) == null ? void 0 : t.poster),
|
|
21
|
+
theme: e.theme ?? ((a = e.options) == null ? void 0 : a.theme),
|
|
22
|
+
lang: e.lang ?? ((i = e.options) == null ? void 0 : i.lang),
|
|
23
|
+
autoplay: e.autoplay ?? ((c = e.options) == null ? void 0 : c.autoplay),
|
|
24
|
+
muted: e.muted ?? ((r = e.options) == null ? void 0 : r.muted),
|
|
25
|
+
loop: e.loop ?? ((d = e.options) == null ? void 0 : d.loop),
|
|
26
|
+
volume: e.volume ?? ((p = e.options) == null ? void 0 : p.volume),
|
|
27
|
+
container: s,
|
|
28
|
+
plugins: o
|
|
29
|
+
});
|
|
30
|
+
}, Te = `<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="currentColor">
|
|
31
|
+
<path d="M17 2l4 4-4 4V7H7a3 3 0 0 0-3 3v1H2v-1a5 5 0 0 1 5-5h10V2z"/>
|
|
32
|
+
<path d="M7 22l-4-4 4-4v3h10a3 3 0 0 0 3-3v-1h2v1a5 5 0 0 1-5 5H7v3z"/>
|
|
33
|
+
</svg>`, M = `<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="currentColor">
|
|
34
|
+
<path d="M3 5h18v2H3V5zm0 6h18v2H3v-2zm0 6h18v2H3v-2z" opacity=".35"/>
|
|
35
|
+
<circle cx="8" cy="6" r="3"/>
|
|
36
|
+
<circle cx="15" cy="12" r="3"/>
|
|
37
|
+
<circle cx="10" cy="18" r="3"/>
|
|
38
|
+
</svg>`, $ = (e) => e === null ? ve : x.utils.secondToTime(e), Pe = {
|
|
39
|
+
key: "abLoop",
|
|
40
|
+
label: S,
|
|
41
|
+
defaultConfig: {
|
|
42
|
+
offset: le
|
|
43
|
+
},
|
|
44
|
+
install({ art: e, setting: s, onCleanup: o }, l) {
|
|
45
|
+
let t = null, a = null;
|
|
46
|
+
const i = () => t === null && a === null ? E : `${$(t)} - ${$(a)}`;
|
|
47
|
+
s({
|
|
48
|
+
html: S,
|
|
49
|
+
icon: Te,
|
|
50
|
+
tooltip: E,
|
|
51
|
+
selector: [
|
|
52
|
+
{ html: fe, value: "start" },
|
|
53
|
+
{ html: me, value: "end" },
|
|
54
|
+
{ html: he, value: "clear" }
|
|
55
|
+
],
|
|
56
|
+
onSelect: (r) => {
|
|
57
|
+
const d = String(r.value), p = e.currentTime;
|
|
58
|
+
return d === "start" && (t = p, a !== null && a <= t && (a = null)), d === "end" && (a = p, t !== null && a <= t && (t = null)), d === "clear" && (t = null, a = null), e.notice.show = i(), i();
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
const c = () => {
|
|
62
|
+
t === null || a === null || e.currentTime >= a - l.offset && (e.currentTime = t);
|
|
63
|
+
};
|
|
64
|
+
e.on("video:timeupdate", c), o(() => e.off("video:timeupdate", c));
|
|
65
|
+
}
|
|
66
|
+
}, v = (e) => e.cloneNode(!0), ke = {
|
|
67
|
+
key: "aspectRatio",
|
|
68
|
+
label: ce,
|
|
69
|
+
defaultConfig: {
|
|
70
|
+
ratios: X,
|
|
71
|
+
defaultRatio: y
|
|
72
|
+
},
|
|
73
|
+
install({ art: e, setting: s }, o) {
|
|
74
|
+
const l = (t) => t === y ? e.i18n.get("Default") : t;
|
|
75
|
+
o.defaultRatio !== y && (e.aspectRatio = o.defaultRatio), s({
|
|
76
|
+
html: e.i18n.get("Aspect Ratio"),
|
|
77
|
+
icon: v(e.icons.aspectRatio),
|
|
78
|
+
tooltip: l(o.defaultRatio),
|
|
79
|
+
selector: o.ratios.map((t) => ({
|
|
80
|
+
html: l(t),
|
|
81
|
+
value: t,
|
|
82
|
+
default: t === o.defaultRatio
|
|
83
|
+
})),
|
|
84
|
+
onSelect: (t) => {
|
|
85
|
+
const a = String(t.value);
|
|
86
|
+
return e.aspectRatio = a, l(a);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}, w = ["brightness", "contrast", "saturate"], Ce = {
|
|
91
|
+
brightness: ge,
|
|
92
|
+
contrast: ye,
|
|
93
|
+
saturate: be
|
|
94
|
+
}, Se = {
|
|
95
|
+
key: "filter",
|
|
96
|
+
label: de,
|
|
97
|
+
defaultConfig: {
|
|
98
|
+
brightness: b,
|
|
99
|
+
contrast: b,
|
|
100
|
+
saturate: b,
|
|
101
|
+
min: oe,
|
|
102
|
+
max: ae,
|
|
103
|
+
step: ie
|
|
104
|
+
},
|
|
105
|
+
install({ art: e, setting: s, onCleanup: o }, l) {
|
|
106
|
+
const t = {
|
|
107
|
+
brightness: l.brightness,
|
|
108
|
+
contrast: l.contrast,
|
|
109
|
+
saturate: l.saturate
|
|
110
|
+
}, a = [], i = () => {
|
|
111
|
+
e.video.style.filter = w.map((c) => `${c}(${t[c]}%)`).join(" ");
|
|
112
|
+
};
|
|
113
|
+
w.forEach((c) => {
|
|
114
|
+
const r = s({
|
|
115
|
+
html: Ce[c],
|
|
116
|
+
icon: M,
|
|
117
|
+
range: [t[c], l.min, l.max, l.step],
|
|
118
|
+
// 返回值会写回菜单项右侧的副标题
|
|
119
|
+
onChange: (d) => {
|
|
120
|
+
var p;
|
|
121
|
+
return t[c] = Number(((p = d.$range) == null ? void 0 : p.value) ?? t[c]), i(), `${t[c]}%`;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
a.push({ key: c, item: r });
|
|
125
|
+
}), s({
|
|
126
|
+
html: we,
|
|
127
|
+
icon: M,
|
|
128
|
+
tooltip: `${l.brightness}%`,
|
|
129
|
+
onClick: () => (w.forEach((c) => {
|
|
130
|
+
t[c] = l[c];
|
|
131
|
+
}), a.forEach(({ key: c, item: r }) => {
|
|
132
|
+
r.$range && (r.$range.value = String(t[c]));
|
|
133
|
+
}), i(), `${l.brightness}%`)
|
|
134
|
+
}), i(), o(() => {
|
|
135
|
+
e.video.style.filter = "";
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}, Ee = {
|
|
139
|
+
normal: "Normal",
|
|
140
|
+
horizontal: "Horizontal",
|
|
141
|
+
vertical: "Vertical"
|
|
142
|
+
}, Le = {
|
|
143
|
+
key: "flip",
|
|
144
|
+
label: ue,
|
|
145
|
+
defaultConfig: {
|
|
146
|
+
modes: Y,
|
|
147
|
+
defaultMode: C
|
|
148
|
+
},
|
|
149
|
+
install({ art: e, setting: s }, o) {
|
|
150
|
+
const l = (t) => e.i18n.get(Ee[t]);
|
|
151
|
+
o.defaultMode !== C && (e.flip = o.defaultMode), s({
|
|
152
|
+
html: e.i18n.get("Video Flip"),
|
|
153
|
+
icon: v(e.icons.flip),
|
|
154
|
+
tooltip: l(o.defaultMode),
|
|
155
|
+
selector: o.modes.map((t) => ({
|
|
156
|
+
html: l(t),
|
|
157
|
+
value: t,
|
|
158
|
+
default: t === o.defaultMode
|
|
159
|
+
})),
|
|
160
|
+
onSelect: (t) => {
|
|
161
|
+
const a = String(t.value);
|
|
162
|
+
return e.flip = a, l(a);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}, B = () => "pictureInPictureEnabled" in document && document.pictureInPictureEnabled, Me = {
|
|
167
|
+
key: "pip",
|
|
168
|
+
label: pe,
|
|
169
|
+
defaultConfig: {
|
|
170
|
+
autoEnter: !1
|
|
171
|
+
},
|
|
172
|
+
install({ art: e, setting: s, onCleanup: o }, l) {
|
|
173
|
+
const t = s({
|
|
174
|
+
html: e.i18n.get("PIP Mode"),
|
|
175
|
+
icon: v(e.icons.pip),
|
|
176
|
+
switch: e.pip,
|
|
177
|
+
onSwitch: () => {
|
|
178
|
+
const a = !e.pip;
|
|
179
|
+
return B() ? (e.pip = a, a) : (e.notice.show = e.i18n.get("PIP Not Supported"), e.pip);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
if (e.on("pip", (a) => {
|
|
183
|
+
t.switch = a;
|
|
184
|
+
}), l.autoEnter) {
|
|
185
|
+
const a = () => {
|
|
186
|
+
document.visibilityState === "hidden" && e.playing && B() && (e.pip = !0);
|
|
187
|
+
};
|
|
188
|
+
document.addEventListener("visibilitychange", a), o(() => document.removeEventListener("visibilitychange", a));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}, R = (e) => `${e}x`, $e = {
|
|
192
|
+
key: "playbackRate",
|
|
193
|
+
label: se,
|
|
194
|
+
defaultConfig: {
|
|
195
|
+
rates: J,
|
|
196
|
+
defaultRate: k
|
|
197
|
+
},
|
|
198
|
+
install({ art: e, setting: s }, o) {
|
|
199
|
+
o.defaultRate !== k && (e.playbackRate = o.defaultRate), s({
|
|
200
|
+
html: e.i18n.get("Play Speed"),
|
|
201
|
+
icon: v(e.icons.playbackRate),
|
|
202
|
+
tooltip: R(o.defaultRate),
|
|
203
|
+
selector: o.rates.map((l) => ({
|
|
204
|
+
html: R(l),
|
|
205
|
+
value: l,
|
|
206
|
+
default: l === o.defaultRate
|
|
207
|
+
})),
|
|
208
|
+
// 返回值会写回菜单项右侧的副标题
|
|
209
|
+
onSelect: (l) => {
|
|
210
|
+
const t = Number(l.value);
|
|
211
|
+
return Number.isNaN(t) ? "" : (e.playbackRate = t, R(t));
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}, Be = (e) => x.utils.secondToTime(e).replace(/:/g, "-"), ze = (e, s) => {
|
|
216
|
+
if (!e.videoWidth || !e.videoHeight) return null;
|
|
217
|
+
const o = document.createElement("canvas");
|
|
218
|
+
o.width = e.videoWidth, o.height = e.videoHeight;
|
|
219
|
+
const l = o.getContext("2d");
|
|
220
|
+
if (!l) return null;
|
|
221
|
+
const t = e.style.filter;
|
|
222
|
+
return t && (l.filter = t), l.drawImage(e, 0, 0, o.width, o.height), { dataUrl: o.toDataURL(s.type, s.quality), time: e.currentTime };
|
|
223
|
+
}, Fe = {
|
|
224
|
+
key: "screenshot",
|
|
225
|
+
label: re,
|
|
226
|
+
defaultConfig: {
|
|
227
|
+
filename: Z,
|
|
228
|
+
type: ee,
|
|
229
|
+
quality: te,
|
|
230
|
+
download: !0
|
|
231
|
+
},
|
|
232
|
+
install({ art: e, setting: s }, o) {
|
|
233
|
+
const l = () => o.type.replace("image/", "").toUpperCase();
|
|
234
|
+
s({
|
|
235
|
+
html: e.i18n.get("Screenshot"),
|
|
236
|
+
icon: v(e.icons.screenshot),
|
|
237
|
+
tooltip: l(),
|
|
238
|
+
onClick: async () => {
|
|
239
|
+
var t;
|
|
240
|
+
try {
|
|
241
|
+
const a = ze(e.video, o);
|
|
242
|
+
if (!a) return l();
|
|
243
|
+
if (o.download) {
|
|
244
|
+
const i = await (await fetch(a.dataUrl)).blob();
|
|
245
|
+
D(`${o.filename}_${Be(a.time)}.${ne[o.type]}`, i);
|
|
246
|
+
}
|
|
247
|
+
(t = o.onCapture) == null || t.call(o, a), e.emit("screenshot", a.dataUrl);
|
|
248
|
+
} catch (a) {
|
|
249
|
+
console.warn(`[${z}] ${L}`, a), e.notice.show = L;
|
|
250
|
+
}
|
|
251
|
+
return l();
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}, Ne = [
|
|
256
|
+
$e,
|
|
257
|
+
ke,
|
|
258
|
+
Le,
|
|
259
|
+
Fe,
|
|
260
|
+
Me,
|
|
261
|
+
Pe,
|
|
262
|
+
Se
|
|
263
|
+
], g = new Map(Ne.map((e) => [e.key, e])), qe = (e) => (g.set(e.key, e), e), De = (e) => e, Ke = (e, s) => ({ key: e, setting: s }), Qe = (e) => g.get(e), Ge = () => [...g.values()], He = (e) => typeof e == "string" ? { key: e } : e, Ie = (e = []) => {
|
|
264
|
+
const s = /* @__PURE__ */ new Map();
|
|
265
|
+
return e.forEach((o) => {
|
|
266
|
+
const l = He(o), t = g.get(l.key);
|
|
267
|
+
if (!t) {
|
|
268
|
+
console.warn(`[${z}] 未注册的插件:${l.key}`);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
const a = l.setting, i = a ? { ...t.defaultConfig, ...a({ ...t.defaultConfig }) } : { ...t.defaultConfig };
|
|
272
|
+
s.set(l.key, { definition: t, config: i });
|
|
273
|
+
}), [...s.values()];
|
|
274
|
+
}, Ve = (e) => {
|
|
275
|
+
const s = [];
|
|
276
|
+
return { plugins: e.map(({ definition: t, config: a }) => (i) => {
|
|
277
|
+
const c = {
|
|
278
|
+
art: i,
|
|
279
|
+
// artplayer 的 setting.add 运行时返回菜单项,类型声明却写成了 setting 组件本身
|
|
280
|
+
setting: (r) => i.setting.add(r),
|
|
281
|
+
onCleanup: (r) => {
|
|
282
|
+
s.push(r);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
t.install(c, a);
|
|
286
|
+
}), dispose: () => {
|
|
287
|
+
s.splice(0).forEach((t) => t());
|
|
288
|
+
} };
|
|
289
|
+
}, Ue = /* @__PURE__ */ N({
|
|
290
|
+
name: "VideoPlayer",
|
|
291
|
+
__name: "index",
|
|
292
|
+
props: {
|
|
293
|
+
url: {},
|
|
294
|
+
poster: {},
|
|
295
|
+
theme: {},
|
|
296
|
+
lang: {},
|
|
297
|
+
autoplay: { type: Boolean },
|
|
298
|
+
muted: { type: Boolean },
|
|
299
|
+
loop: { type: Boolean },
|
|
300
|
+
volume: {},
|
|
301
|
+
height: {},
|
|
302
|
+
plugins: { default: () => [] },
|
|
303
|
+
options: { default: () => ({}) }
|
|
304
|
+
},
|
|
305
|
+
emits: ["ready", "play", "pause", "ended", "timeupdate", "volumechange", "ratechange", "seek", "error", "flip", "pip", "screenshot", "fullscreen", "fullscreen-web", "destroy"],
|
|
306
|
+
setup(e, { expose: s, emit: o }) {
|
|
307
|
+
const l = e, t = o, a = H(), i = I();
|
|
308
|
+
let c;
|
|
309
|
+
const r = V(() => ({
|
|
310
|
+
position: "relative",
|
|
311
|
+
width: "100%",
|
|
312
|
+
background: "#000",
|
|
313
|
+
...l.height === void 0 ? { aspectRatio: Q } : { height: typeof l.height == "number" ? `${l.height}px` : l.height }
|
|
314
|
+
})), d = (n) => {
|
|
315
|
+
n.on("play", () => t("play")), n.on("pause", () => t("pause")), n.on("seek", (u, f) => t("seek", u, f)), n.on("flip", (u) => t("flip", u)), n.on("pip", (u) => t("pip", u)), n.on("screenshot", (u) => t("screenshot", u)), n.on("fullscreen", (u) => t("fullscreen", u)), n.on("fullscreenWeb", (u) => t("fullscreen-web", u)), n.on("error", (u, f) => t("error", u, f)), n.on("destroy", () => t("destroy")), n.on("video:ended", () => t("ended")), n.on("video:timeupdate", () => t("timeupdate")), n.on("video:volumechange", () => t("volumechange")), n.on("video:ratechange", () => t("ratechange"));
|
|
316
|
+
}, p = (n) => {
|
|
317
|
+
const u = a.value;
|
|
318
|
+
if (!u || !l.url) return;
|
|
319
|
+
const f = Ve(Ie(l.plugins));
|
|
320
|
+
c = f.dispose;
|
|
321
|
+
const h = new x(xe(l, u, f.plugins), (P) => {
|
|
322
|
+
n != null && n.currentTime && (P.currentTime = n.currentTime), n != null && n.playing && P.play().catch(() => {
|
|
323
|
+
}), t("ready");
|
|
324
|
+
});
|
|
325
|
+
i.value = h, d(h);
|
|
326
|
+
}, T = () => {
|
|
327
|
+
var n;
|
|
328
|
+
c == null || c(), c = void 0, (n = i.value) == null || n.destroy(), i.value = void 0;
|
|
329
|
+
}, F = () => {
|
|
330
|
+
var f, h;
|
|
331
|
+
const n = ((f = i.value) == null ? void 0 : f.currentTime) ?? 0, u = ((h = i.value) == null ? void 0 : h.playing) ?? !1;
|
|
332
|
+
T(), p({ currentTime: n, playing: u });
|
|
333
|
+
};
|
|
334
|
+
return m(
|
|
335
|
+
() => l.url,
|
|
336
|
+
(n) => {
|
|
337
|
+
if (!i.value) {
|
|
338
|
+
p();
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
n && (i.value.url = n);
|
|
342
|
+
}
|
|
343
|
+
), m(() => [l.plugins, l.options], F, { deep: !0 }), m(
|
|
344
|
+
() => l.poster,
|
|
345
|
+
(n) => {
|
|
346
|
+
i.value && n && (i.value.poster = n);
|
|
347
|
+
}
|
|
348
|
+
), m(
|
|
349
|
+
() => l.theme,
|
|
350
|
+
(n) => {
|
|
351
|
+
i.value && n && (i.value.theme = n);
|
|
352
|
+
}
|
|
353
|
+
), m(
|
|
354
|
+
() => l.volume,
|
|
355
|
+
(n) => {
|
|
356
|
+
i.value && n !== void 0 && (i.value.volume = n);
|
|
357
|
+
}
|
|
358
|
+
), m(
|
|
359
|
+
() => l.muted,
|
|
360
|
+
(n) => {
|
|
361
|
+
i.value && n !== void 0 && (i.value.muted = n);
|
|
362
|
+
}
|
|
363
|
+
), m(
|
|
364
|
+
() => l.loop,
|
|
365
|
+
(n) => {
|
|
366
|
+
i.value && n !== void 0 && (i.value.video.loop = n);
|
|
367
|
+
}
|
|
368
|
+
), U(p), _(T), s({
|
|
369
|
+
get player() {
|
|
370
|
+
return i.value;
|
|
371
|
+
},
|
|
372
|
+
play: () => {
|
|
373
|
+
var n;
|
|
374
|
+
return (n = i.value) == null ? void 0 : n.play();
|
|
375
|
+
},
|
|
376
|
+
pause: () => {
|
|
377
|
+
var n;
|
|
378
|
+
return (n = i.value) == null ? void 0 : n.pause();
|
|
379
|
+
},
|
|
380
|
+
toggle: () => {
|
|
381
|
+
var n;
|
|
382
|
+
return (n = i.value) == null ? void 0 : n.toggle();
|
|
383
|
+
},
|
|
384
|
+
seek: (n) => {
|
|
385
|
+
i.value && (i.value.currentTime = n);
|
|
386
|
+
},
|
|
387
|
+
screenshot: (n) => {
|
|
388
|
+
var u;
|
|
389
|
+
return (u = i.value) == null ? void 0 : u.screenshot(n);
|
|
390
|
+
},
|
|
391
|
+
fullscreen: (n) => {
|
|
392
|
+
i.value && (i.value.fullscreen = n ?? !i.value.fullscreen);
|
|
393
|
+
}
|
|
394
|
+
}), (n, u) => (A(), O("div", {
|
|
395
|
+
ref_key: "containerRef",
|
|
396
|
+
ref: a,
|
|
397
|
+
class: W(q(K)),
|
|
398
|
+
style: j(r.value)
|
|
399
|
+
}, null, 6));
|
|
400
|
+
}
|
|
401
|
+
}), _e = (e) => {
|
|
402
|
+
const s = e;
|
|
403
|
+
return s.install = (o) => {
|
|
404
|
+
e.name && o.component(e.name, e);
|
|
405
|
+
}, s;
|
|
406
|
+
}, Je = _e(Ue);
|
|
407
|
+
export {
|
|
408
|
+
Je as VideoPlayer,
|
|
409
|
+
Pe as abLoopPlugin,
|
|
410
|
+
ke as aspectRatioPlugin,
|
|
411
|
+
Ne as builtinPlugins,
|
|
412
|
+
Je as default,
|
|
413
|
+
Q as defaultPlayerRatio,
|
|
414
|
+
De as definePlugin,
|
|
415
|
+
Se as filterPlugin,
|
|
416
|
+
Le as flipPlugin,
|
|
417
|
+
Qe as getPlugin,
|
|
418
|
+
Ge as listPlugins,
|
|
419
|
+
z as packageName,
|
|
420
|
+
Me as pipPlugin,
|
|
421
|
+
$e as playbackRatePlugin,
|
|
422
|
+
Ke as pluginEntry,
|
|
423
|
+
K as prefix,
|
|
424
|
+
qe as registerPlugin,
|
|
425
|
+
Ie as resolvePlugins,
|
|
426
|
+
Fe as screenshotPlugin
|
|
427
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { abLoopPlugin } from './abLoop';
|
|
2
|
+
import { aspectRatioPlugin } from './aspectRatio';
|
|
3
|
+
import { filterPlugin } from './filter';
|
|
4
|
+
import { flipPlugin } from './flip';
|
|
5
|
+
import { pipPlugin } from './pip';
|
|
6
|
+
import { playbackRatePlugin } from './playbackRate';
|
|
7
|
+
import { screenshotPlugin } from './screenshot';
|
|
8
|
+
import { PluginDefinition } from '../types/plugin';
|
|
9
|
+
|
|
10
|
+
/** 内置插件,按右侧菜单的展示顺序排列 */
|
|
11
|
+
export declare const builtinPlugins: PluginDefinition[];
|
|
12
|
+
export { abLoopPlugin, aspectRatioPlugin, filterPlugin, flipPlugin, pipPlugin, playbackRatePlugin, screenshotPlugin };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { default as Artplayer, Option } from 'artplayer';
|
|
2
|
+
import { FlipMode, PluginInput } from './plugin';
|
|
3
|
+
|
|
4
|
+
/** 透传给 artplayer 的原生配置;容器、地址与插件由组件接管 */
|
|
5
|
+
export type PlayerOption = Omit<Partial<Option>, 'container' | 'plugins' | 'url'>;
|
|
6
|
+
/** 视频播放器属性 */
|
|
7
|
+
export type VideoPlayerProps = {
|
|
8
|
+
/** 视频地址 */
|
|
9
|
+
url: string;
|
|
10
|
+
/** 封面图 */
|
|
11
|
+
poster?: string;
|
|
12
|
+
/** 主题色,同时影响进度条与高亮 */
|
|
13
|
+
theme?: string;
|
|
14
|
+
/** 提示语言,artplayer 内置 `zh-cn`,其余语言用 `artplayer/i18n/*` 自行注入 */
|
|
15
|
+
lang?: string;
|
|
16
|
+
/** 是否自动播放;浏览器策略可能要求同时 `muted` */
|
|
17
|
+
autoplay?: boolean;
|
|
18
|
+
/** 是否静音 */
|
|
19
|
+
muted?: boolean;
|
|
20
|
+
/** 是否循环播放 */
|
|
21
|
+
loop?: boolean;
|
|
22
|
+
/** 初始音量,取值 0–1 */
|
|
23
|
+
volume?: number;
|
|
24
|
+
/** 容器高度,数字按 px;不传时按 16:9 自适应宽度 */
|
|
25
|
+
height?: number | string;
|
|
26
|
+
/** 插件配置,见 README 的「插件」一节 */
|
|
27
|
+
plugins?: PluginInput[];
|
|
28
|
+
/** 其余 artplayer 配置原样透传 */
|
|
29
|
+
options?: PlayerOption;
|
|
30
|
+
};
|
|
31
|
+
/** 组件实例方法 */
|
|
32
|
+
export type VideoPlayerInstance = {
|
|
33
|
+
/** 原始 artplayer 实例,未就绪时为 undefined */
|
|
34
|
+
readonly player: Artplayer | undefined;
|
|
35
|
+
/** 播放 */
|
|
36
|
+
play: () => Promise<void> | undefined;
|
|
37
|
+
/** 暂停 */
|
|
38
|
+
pause: () => void;
|
|
39
|
+
/** 播放 / 暂停切换 */
|
|
40
|
+
toggle: () => void;
|
|
41
|
+
/** 跳转到指定秒数 */
|
|
42
|
+
seek: (time: number) => void;
|
|
43
|
+
/** 截图,返回 dataURL */
|
|
44
|
+
screenshot: (name?: string) => Promise<string> | undefined;
|
|
45
|
+
/** 进入 / 退出全屏,不传则切换 */
|
|
46
|
+
fullscreen: (state?: boolean) => void;
|
|
47
|
+
};
|
|
48
|
+
/** 组件事件,参数与 artplayer 原始事件一致 */
|
|
49
|
+
export interface VideoPlayerEmits {
|
|
50
|
+
(event: 'ready'): void;
|
|
51
|
+
(event: 'play'): void;
|
|
52
|
+
(event: 'pause'): void;
|
|
53
|
+
(event: 'ended'): void;
|
|
54
|
+
(event: 'timeupdate'): void;
|
|
55
|
+
(event: 'volumechange'): void;
|
|
56
|
+
(event: 'ratechange'): void;
|
|
57
|
+
(event: 'seek', currentTime: number, time: number): void;
|
|
58
|
+
(event: 'error', error: Error, reconnectTime: number): void;
|
|
59
|
+
(event: 'flip', mode: FlipMode): void;
|
|
60
|
+
(event: 'pip', state: boolean): void;
|
|
61
|
+
(event: 'screenshot', dataUri: string): void;
|
|
62
|
+
(event: 'fullscreen', state: boolean): void;
|
|
63
|
+
(event: 'fullscreen-web', state: boolean): void;
|
|
64
|
+
(event: 'destroy'): void;
|
|
65
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { default as Artplayer, Setting, SettingOption } from 'artplayer';
|
|
2
|
+
|
|
3
|
+
/** 插件配置的通用形态;具体插件在 `PluginConfigMap` 里声明自己的字段 */
|
|
4
|
+
export type PluginConfig = Record<string, unknown>;
|
|
5
|
+
/** 倍速插件配置 */
|
|
6
|
+
export type PlaybackRateConfig = {
|
|
7
|
+
/** 可选语速列表 */
|
|
8
|
+
rates: number[];
|
|
9
|
+
/** 初始语速 */
|
|
10
|
+
defaultRate: number;
|
|
11
|
+
};
|
|
12
|
+
/** 画面比例:`default` 跟随视频原始比例,其余按 `宽:高` 写法 */
|
|
13
|
+
export type AspectRatioValue = 'default' | `${number}:${number}`;
|
|
14
|
+
/** 画面比例插件配置 */
|
|
15
|
+
export type AspectRatioConfig = {
|
|
16
|
+
/** 可选比例列表,`default` 为跟随视频原始比例 */
|
|
17
|
+
ratios: AspectRatioValue[];
|
|
18
|
+
/** 初始比例 */
|
|
19
|
+
defaultRatio: AspectRatioValue;
|
|
20
|
+
};
|
|
21
|
+
/** 翻转方向 */
|
|
22
|
+
export type FlipMode = 'normal' | 'horizontal' | 'vertical';
|
|
23
|
+
/** 翻转插件配置 */
|
|
24
|
+
export type FlipConfig = {
|
|
25
|
+
/** 可选方向列表 */
|
|
26
|
+
modes: FlipMode[];
|
|
27
|
+
/** 初始方向 */
|
|
28
|
+
defaultMode: FlipMode;
|
|
29
|
+
};
|
|
30
|
+
/** 截图输出格式 */
|
|
31
|
+
export type ScreenshotType = 'image/png' | 'image/jpeg' | 'image/webp';
|
|
32
|
+
/** 截图结果 */
|
|
33
|
+
export type ScreenshotResult = {
|
|
34
|
+
/** `data:image/...;base64,...` 形式的图片数据 */
|
|
35
|
+
dataUrl: string;
|
|
36
|
+
/** 截图时的播放进度(秒) */
|
|
37
|
+
time: number;
|
|
38
|
+
};
|
|
39
|
+
/** 截图插件配置 */
|
|
40
|
+
export type ScreenshotConfig = {
|
|
41
|
+
/** 文件名前缀,最终文件名为 `${filename}_${播放时间}.${后缀}` */
|
|
42
|
+
filename: string;
|
|
43
|
+
/** 图片格式 */
|
|
44
|
+
type: ScreenshotType;
|
|
45
|
+
/** 图片质量 0–1,仅 `image/jpeg` 与 `image/webp` 生效 */
|
|
46
|
+
quality: number;
|
|
47
|
+
/** 是否直接下载;为 `false` 时只通过 `onCapture` 回调 */
|
|
48
|
+
download: boolean;
|
|
49
|
+
/** 截图完成回调,下载关闭时可用于自定义保存 */
|
|
50
|
+
onCapture?: (result: ScreenshotResult) => void;
|
|
51
|
+
};
|
|
52
|
+
/** 画中画插件配置 */
|
|
53
|
+
export type PipConfig = {
|
|
54
|
+
/** 页面切到后台且正在播放时自动进入画中画 */
|
|
55
|
+
autoEnter: boolean;
|
|
56
|
+
};
|
|
57
|
+
/** AB 循环插件配置 */
|
|
58
|
+
export type AbLoopConfig = {
|
|
59
|
+
/** 回跳时相对 B 点的提前量(秒),避免停在最后一帧 */
|
|
60
|
+
offset: number;
|
|
61
|
+
};
|
|
62
|
+
/** 画面调节插件配置 */
|
|
63
|
+
export type FilterConfig = {
|
|
64
|
+
/** 初始亮度,100 为原始值 */
|
|
65
|
+
brightness: number;
|
|
66
|
+
/** 初始对比度,100 为原始值 */
|
|
67
|
+
contrast: number;
|
|
68
|
+
/** 初始饱和度,100 为原始值 */
|
|
69
|
+
saturate: number;
|
|
70
|
+
/** 滑杆最小值 */
|
|
71
|
+
min: number;
|
|
72
|
+
/** 滑杆最大值 */
|
|
73
|
+
max: number;
|
|
74
|
+
/** 滑杆步长 */
|
|
75
|
+
step: number;
|
|
76
|
+
};
|
|
77
|
+
/** 内置插件的配置映射,`plugins` 数组据此推导 `setting` 的入参类型 */
|
|
78
|
+
export type PluginConfigMap = {
|
|
79
|
+
playbackRate: PlaybackRateConfig;
|
|
80
|
+
aspectRatio: AspectRatioConfig;
|
|
81
|
+
flip: FlipConfig;
|
|
82
|
+
screenshot: ScreenshotConfig;
|
|
83
|
+
pip: PipConfig;
|
|
84
|
+
abLoop: AbLoopConfig;
|
|
85
|
+
filter: FilterConfig;
|
|
86
|
+
};
|
|
87
|
+
/** 内置插件的 key */
|
|
88
|
+
export type BuiltinPluginKey = keyof PluginConfigMap;
|
|
89
|
+
/**
|
|
90
|
+
* 插件配置覆盖函数。
|
|
91
|
+
* 入参是该插件的完整默认配置,返回值只需包含要改的字段。
|
|
92
|
+
*/
|
|
93
|
+
export type PluginSetting<T extends PluginConfig = PluginConfig> = (config: Readonly<T>) => Partial<T>;
|
|
94
|
+
/** 单个插件条目 */
|
|
95
|
+
export type PluginEntry = {
|
|
96
|
+
/** 插件 key,需已注册 */
|
|
97
|
+
key: string;
|
|
98
|
+
/** 覆盖默认配置;不传则用默认配置 */
|
|
99
|
+
setting?: PluginSetting;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* `plugins` 的入参形态:
|
|
103
|
+
* - 字符串:存在即启用,使用默认配置
|
|
104
|
+
* - 对象:启用并按 `setting` 覆盖默认配置
|
|
105
|
+
*
|
|
106
|
+
* 需要在 `setting` 里读到带类型的配置时,用 `pluginEntry('key', (config) => ...)` 生成条目。
|
|
107
|
+
*/
|
|
108
|
+
export type PluginInput = string | PluginEntry;
|
|
109
|
+
/** 插件安装上下文 */
|
|
110
|
+
export interface PluginContext {
|
|
111
|
+
/** artplayer 实例 */
|
|
112
|
+
art: Artplayer;
|
|
113
|
+
/**
|
|
114
|
+
* 往右侧设置菜单追加一项,返回菜单项本身。
|
|
115
|
+
* 菜单项是可变对象,插件可以回写 `html` / `tooltip` / `switch` 同步状态。
|
|
116
|
+
*/
|
|
117
|
+
setting: (option: Setting) => SettingOption;
|
|
118
|
+
/** 注册清理回调,组件卸载时先于 `destroy()` 执行 */
|
|
119
|
+
onCleanup: (cleanup: () => void) => void;
|
|
120
|
+
}
|
|
121
|
+
/** 插件定义 */
|
|
122
|
+
export interface PluginDefinition<T extends PluginConfig = PluginConfig> {
|
|
123
|
+
/** 唯一标识,`plugins` 里用它启用插件 */
|
|
124
|
+
key: string;
|
|
125
|
+
/** 插件名,同时作为右侧菜单项文案 */
|
|
126
|
+
label: string;
|
|
127
|
+
/** 默认配置,`setting` 在它之上覆盖 */
|
|
128
|
+
defaultConfig: T;
|
|
129
|
+
/** 安装插件,实例就绪后调用 */
|
|
130
|
+
install(context: PluginContext, config: T): void;
|
|
131
|
+
}
|
|
132
|
+
/** 已解析、待安装的插件 */
|
|
133
|
+
export type ResolvedPlugin = {
|
|
134
|
+
definition: PluginDefinition;
|
|
135
|
+
config: PluginConfig;
|
|
136
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wapri/gplayer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Vue 3 视频播放器:基于 artplayer 封装,插件通过 key + 配置覆盖声明",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "wapri contributors",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"main": "dist/index.mjs",
|
|
12
|
+
"module": "dist/index.mjs",
|
|
13
|
+
"types": "dist/index.d.ts",
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public",
|
|
16
|
+
"registry": "https://registry.npmjs.org/"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"artplayer": "^5.4.0",
|
|
20
|
+
"@wapri/gbase": "^2.3.0"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"vue": ">=3.3"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "node ../../scripts/clean-dist.mjs && vite build",
|
|
27
|
+
"dev": "vite build --watch"
|
|
28
|
+
}
|
|
6
29
|
}
|