@volcengine/veplayer 1.15.1 → 1.15.2-rc.1
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.
Potentially problematic release.
This version of @volcengine/veplayer might be problematic. Click here for more details.
- package/.changeset/config.json +11 -0
- package/.changeset/curvy-yaks-smoke.md +5 -0
- package/.changeset/neat-eyes-search.md +5 -0
- package/.codebase/pipelines/create-api-doc.yaml +16 -0
- package/.eslintignore +5 -0
- package/.eslintrc.json +53 -0
- package/.stylelintrc.js +51 -0
- package/CHANGELOG.md +5665 -0
- package/DEV_README.md +39 -0
- package/LICENSE +20 -0
- package/README_EN.md +46 -0
- package/build.sh +44 -0
- package/docg.config.js +65 -0
- package/env/byteplus.js +30 -0
- package/env/volcengine.js +50 -0
- package/fixtures/favicon.ico +0 -0
- package/fixtures/index.base.js +59 -0
- package/fixtures/index.html +41 -0
- package/fixtures/index.js +185 -0
- package/libd.config.js +147 -0
- package/localhost+2-key.pem +28 -0
- package/localhost+2.pem +26 -0
- package/lux.config.mjs +37 -0
- package/package.json +123 -4
- package/sdkhub.config.json +10 -0
- package/src/@types/global.d.ts +35 -0
- package/src/assets/common/error.svg +3 -0
- package/src/assets/common/errorImg.png +0 -0
- package/src/assets/common/errorImg.svg +12 -0
- package/src/assets/icons/mobile/definition.svg +3 -0
- package/src/assets/icons/mobile/line.svg +3 -0
- package/src/assets/icons/mobile/mobileDanmu.svg +1 -0
- package/src/assets/icons/mobile/mobileDanmuAcitive.svg +1 -0
- package/src/assets/icons/mobile/mobileDanmuSetting.svg +1 -0
- package/src/assets/icons/mobile/mobileExitFullscreen.svg +1 -0
- package/src/assets/icons/mobile/mobileFullscreen.svg +1 -0
- package/src/assets/icons/mobile/mobilePause.svg +4 -0
- package/src/assets/icons/mobile/mobilePlay.svg +4 -0
- package/src/assets/icons/mobile/mobilePlaynext.svg +1 -0
- package/src/assets/icons/mobile/mobileRefresh.svg +1 -0
- package/src/assets/icons/mobile/more.svg +3 -0
- package/src/assets/icons/mobile/muted.svg +22 -0
- package/src/assets/icons/mobile/playbackrate.svg +3 -0
- package/src/assets/icons/pc/danmu.svg +1 -0
- package/src/assets/icons/pc/danmuActive.svg +1 -0
- package/src/assets/icons/pc/danmuSettings.svg +1 -0
- package/src/assets/icons/pc/download.svg +14 -0
- package/src/assets/icons/pc/exitFullscreen.svg +1 -0
- package/src/assets/icons/pc/exitMirror.svg +10 -0
- package/src/assets/icons/pc/extend.svg +1 -0
- package/src/assets/icons/pc/fullscreen.svg +1 -0
- package/src/assets/icons/pc/getMirror.svg +10 -0
- package/src/assets/icons/pc/list.svg +20 -0
- package/src/assets/icons/pc/noPoster.svg +119 -0
- package/src/assets/icons/pc/pause.svg +1 -0
- package/src/assets/icons/pc/pip.svg +1 -0
- package/src/assets/icons/pc/pipExit.svg +1 -0
- package/src/assets/icons/pc/play-next-btn.svg +4 -0
- package/src/assets/icons/pc/play.svg +1 -0
- package/src/assets/icons/pc/playNext.svg +1 -0
- package/src/assets/icons/pc/playerLoading.svg +1 -0
- package/src/assets/icons/pc/refresh.svg +1 -0
- package/src/assets/icons/pc/replay.svg +1 -0
- package/src/assets/icons/pc/reset.svg +6 -0
- package/src/assets/icons/pc/startPlay.svg +1 -0
- package/src/assets/icons/pc/subtitleclose.svg +5 -0
- package/src/assets/icons/pc/subtitleopen.svg +3 -0
- package/src/assets/icons/pc/theaterEnter.svg +1 -0
- package/src/assets/icons/pc/theaterExit.svg +1 -0
- package/src/assets/icons/pc/volumeLarge.svg +1 -0
- package/src/assets/icons/pc/volumeMuted.svg +1 -0
- package/src/assets/icons/pc/volumeSmall.svg +1 -0
- package/src/config/defaultPreset.ts +110 -0
- package/src/config/playerOptionMobile.ts +166 -0
- package/src/config/playerOptionPc.ts +147 -0
- package/src/config/playerPreset.ts +242 -0
- package/src/constants/api.ts +13 -0
- package/src/constants/event.ts +577 -0
- package/src/constants/player.ts +84 -0
- package/src/constants/plugin.ts +19 -0
- package/src/constants/umdMap.ts +137 -0
- package/src/constants/umdPlugins.json +68 -0
- package/src/core/index.ts +7 -0
- package/src/core/player.ts +2713 -0
- package/src/core/playerData.ts +812 -0
- package/src/env.d.ts +47 -0
- package/src/index.ts +24 -0
- package/src/index.umd.ts +54 -0
- package/src/interface/adaptRange.d.ts +33 -0
- package/src/interface/api.ts +132 -0
- package/src/interface/autoBitrate.d.ts +41 -0
- package/src/interface/index.ts +1685 -0
- package/src/interface/rtm.ts +56 -0
- package/src/interface/sdkErrorPlugin.ts +145 -0
- package/src/interface/subtitle.ts +381 -0
- package/src/interface/video.ts +107 -0
- package/src/interface/xgplayer.ts +748 -0
- package/src/lang/constants.ts +69 -0
- package/src/lang/en.ts +98 -0
- package/src/lang/index.ts +33 -0
- package/src/lang/jp.ts +100 -0
- package/src/lang/zh-hk.ts +80 -0
- package/src/lang/zh.ts +79 -0
- package/src/license/index.ts +315 -0
- package/src/license/ttlicense2.js +15 -0
- package/src/license/ttlicense2.wasm +0 -0
- package/src/music/icons/back.svg +3 -0
- package/src/music/icons/forward.svg +3 -0
- package/src/music/icons/loop.svg +10 -0
- package/src/music/icons/order.svg +10 -0
- package/src/music/icons/pause-circle.svg +23 -0
- package/src/music/icons/play-circle.svg +22 -0
- package/src/music/icons/random.svg +10 -0
- package/src/music/icons/sloop.svg +10 -0
- package/src/music/index.ts +5 -0
- package/src/music/music.ts +550 -0
- package/src/music/plugins/index.less +185 -0
- package/src/music/plugins/index.ts +6 -0
- package/src/music/plugins/musicBackward.ts +82 -0
- package/src/music/plugins/musicCover.ts +45 -0
- package/src/music/plugins/musicForward.ts +82 -0
- package/src/music/plugins/musicMeta.ts +32 -0
- package/src/music/plugins/musicMode.ts +152 -0
- package/src/music/plugins/musicNext.ts +93 -0
- package/src/music/plugins/musicPrev.ts +94 -0
- package/src/music/preset.ts +69 -0
- package/src/music/xhr.ts +37 -0
- package/src/plugins/common/extendPluginFactory.ts +132 -0
- package/src/plugins/common/mobilePlayerPanel.ts +253 -0
- package/src/plugins/external/LiveInfoPanel.ts +340 -0
- package/src/plugins/external/ad/adsPlugin.ts +1 -0
- package/src/plugins/external/aiSubtitleIconPlugin.ts +270 -0
- package/src/plugins/external/aiSubtitlePlugin.ts +452 -0
- package/src/plugins/external/definitionDemotePlugin.ts +591 -0
- package/src/plugins/external/memoryPlay.ts +247 -0
- package/src/plugins/external/mirrorPlugin.ts +141 -0
- package/src/plugins/external/playList/OptionList.ts +204 -0
- package/src/plugins/external/playList/index.ts +743 -0
- package/src/plugins/external/subtitle/index.ts +672 -0
- package/src/plugins/external/subtitle/nativeSubTitle.ts +115 -0
- package/src/plugins/external/timeShiftPlugin.ts +484 -0
- package/src/plugins/external/watermark/dynamicWatermark.less +13 -0
- package/src/plugins/external/watermark/dynamicWatermark.ts +449 -0
- package/src/plugins/external/watermark/dynamicWatermarkPlugin.ts +185 -0
- package/src/plugins/inner/common/autoplayPlugin.ts +435 -0
- package/src/plugins/inner/common/danmu/container.ts +120 -0
- package/src/plugins/inner/common/danmu/index.ts +683 -0
- package/src/plugins/inner/common/danmu/lang.ts +139 -0
- package/src/plugins/inner/common/danmu/panel.ts +20 -0
- package/src/plugins/inner/common/danmu/slider.ts +210 -0
- package/src/plugins/inner/common/danmu/state.ts +118 -0
- package/src/plugins/inner/common/danmu/switch.ts +74 -0
- package/src/plugins/inner/common/definitionBasePlugin.ts +353 -0
- package/src/plugins/inner/common/errorPlugin.ts +544 -0
- package/src/plugins/inner/common/liveLogger.ts +137 -0
- package/src/plugins/inner/common/poster/index.less +66 -0
- package/src/plugins/inner/common/poster/index.ts +178 -0
- package/src/plugins/inner/common/refreshPlugin.ts +88 -0
- package/src/plugins/inner/common/rtmPlugin.ts +62 -0
- package/src/plugins/inner/common/toastPlugin.ts +90 -0
- package/src/plugins/inner/common/unmutePlugin.ts +133 -0
- package/src/plugins/inner/common/vodLogger.ts +80 -0
- package/src/plugins/inner/mobile/DefinitionMobilePlugin.ts +217 -0
- package/src/plugins/inner/mobile/LineMobilePlugins.ts +169 -0
- package/src/plugins/inner/mobile/MoreButtonPlugin.ts +176 -0
- package/src/plugins/inner/mobile/PlaybackRatePlugin.ts +199 -0
- package/src/plugins/inner/pc/definitionPlugin.ts +203 -0
- package/src/plugins/inner/pc/multilinePlugin.ts +93 -0
- package/src/sdkPlugin/abr.ts +67 -0
- package/src/sdkPlugin/adaptRange.ts +49 -0
- package/src/sdkPlugin/authToken.ts +557 -0
- package/src/sdkPlugin/sdkPlugin.ts +125 -0
- package/src/sdkPlugin/sdkPluginManager.ts +157 -0
- package/src/sdkPlugin/strategy.ts +47 -0
- package/src/strategy/index.ts +740 -0
- package/src/strategy/vestrategy-h265-wrapper.ts +34 -0
- package/src/strategy/vestrategy-preload-wrapper.ts +414 -0
- package/src/streamAdapters/base.ts +89 -0
- package/src/streamAdapters/dash.ts +230 -0
- package/src/streamAdapters/default.ts +53 -0
- package/src/streamAdapters/hls.ts +278 -0
- package/src/streamAdapters/index.ts +40 -0
- package/src/streamAdapters/mp4.ts +214 -0
- package/src/style/bytelive/danmu.less +293 -0
- package/src/style/bytelive/definitionIcon.less +80 -0
- package/src/style/bytelive/error.less +165 -0
- package/src/style/bytelive/index.less +62 -0
- package/src/style/bytelive/loading.less +5 -0
- package/src/style/bytelive/mobiePlugin.less +2 -0
- package/src/style/bytelive/mobile.less +76 -0
- package/src/style/bytelive/moreButton.less +79 -0
- package/src/style/bytelive/panel.less +259 -0
- package/src/style/bytelive/pc.less +161 -0
- package/src/style/bytelive/refresh.less +3 -0
- package/src/style/bytelive/reset.less +4 -0
- package/src/style/bytelive/toast.less +61 -0
- package/src/style/bytelive/unmute.less +65 -0
- package/src/style/external/LiveInfoPanel.less +41 -0
- package/src/style/external/aisub.less +139 -0
- package/src/style/external/aisubIcon.less +25 -0
- package/src/style/external/index.less +5 -0
- package/src/style/external/larkWindow.less +36 -0
- package/src/style/external/mirror.less +27 -0
- package/src/style/external/playList.less +258 -0
- package/src/style/external/timeShift.less +102 -0
- package/src/style/external/vttSubtitle.less +25 -0
- package/src/utils/debug.ts +62 -0
- package/src/utils/definition.ts +61 -0
- package/src/utils/escapeHtml.ts +93 -0
- package/src/utils/eventMiddleWare.ts +108 -0
- package/src/utils/index.ts +621 -0
- package/src/utils/intervalTimer.ts +38 -0
- package/src/utils/isHijackBrowser.ts +71 -0
- package/src/utils/proxy.ts +139 -0
- package/src/utils/storage.ts +34 -0
- package/src/utils/time.ts +19 -0
- package/src/utils/toast/index.less +20 -0
- package/src/utils/toast/index.ts +21 -0
- package/src/utils/token.ts +395 -0
- package/src/utils/u8a.ts +4 -0
- package/src/utils/umdLoader.ts +193 -0
- package/src/utils/video.ts +43 -0
- package/src/utils/xhr.ts +160 -0
- package/src/veError/error.ts +301 -0
- package/src/veError/index.ts +681 -0
- package/src/veError/playerProxy.ts +69 -0
- package/tsconfig.json +27 -0
- package/index.d.ts +0 -6874
- package/index.min.css +0 -1
- package/index.min.js +0 -2
- package/plugin/DashAbralgo.js +0 -2
- package/plugin/XGVideo.js +0 -2
- package/plugin/danmuMask.js +0 -2
- package/plugin/danmujs.js +0 -3
- package/plugin/dash.js +0 -2
- package/plugin/flv.js +0 -2
- package/plugin/hls.js +0 -2
- package/plugin/hlsEncrypt.js +0 -2
- package/plugin/mp4Encrypt.js +0 -2
- package/plugin/preloader.js +0 -2
- package/plugin/streamprobe.js +0 -2
- package/plugin/vestrategy.js +0 -1
- package/plugin/vestrategy_adapt_range.js +0 -1
- package/plugin/vestrategy_h265.js +0 -1
- package/plugin/vestrategy_preload.js +0 -1
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
export interface langMap {
|
|
2
|
+
danmuSwitch: string;
|
|
3
|
+
danmuSetting: string;
|
|
4
|
+
openDanmu: string;
|
|
5
|
+
reset: string;
|
|
6
|
+
opacity: string;
|
|
7
|
+
area: string;
|
|
8
|
+
speed: string;
|
|
9
|
+
fontSize: string;
|
|
10
|
+
|
|
11
|
+
screen0: string;
|
|
12
|
+
screen1: string;
|
|
13
|
+
screen2: string;
|
|
14
|
+
screen3: string;
|
|
15
|
+
|
|
16
|
+
opacity0: string;
|
|
17
|
+
opacity1: string;
|
|
18
|
+
opacity2: string;
|
|
19
|
+
opacity3: string;
|
|
20
|
+
|
|
21
|
+
speed0: string;
|
|
22
|
+
speed1: string;
|
|
23
|
+
speed2: string;
|
|
24
|
+
speed3: string;
|
|
25
|
+
speed4: string;
|
|
26
|
+
speed5: string;
|
|
27
|
+
|
|
28
|
+
fontSize0: string;
|
|
29
|
+
fontSize1: string;
|
|
30
|
+
fontSize2: string;
|
|
31
|
+
[props: string]: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const zh: langMap = {
|
|
35
|
+
danmuSwitch: '弹幕开关',
|
|
36
|
+
danmuSetting: '弹幕设置',
|
|
37
|
+
openDanmu: '打开弹幕',
|
|
38
|
+
reset: '重置',
|
|
39
|
+
opacity: '不透明度',
|
|
40
|
+
area: '显示区域',
|
|
41
|
+
speed: '弹幕速度',
|
|
42
|
+
fontSize: '字体大小',
|
|
43
|
+
danmuMask: '智能挡板',
|
|
44
|
+
|
|
45
|
+
screen0: '1/4屏',
|
|
46
|
+
screen1: '半屏',
|
|
47
|
+
screen2: '3/4屏',
|
|
48
|
+
screen3: '全屏',
|
|
49
|
+
|
|
50
|
+
opacity0: '0',
|
|
51
|
+
opacity1: '1/3',
|
|
52
|
+
opacity2: '2/3',
|
|
53
|
+
opacity3: '1',
|
|
54
|
+
|
|
55
|
+
speed0: '0.25',
|
|
56
|
+
speed1: '0.5',
|
|
57
|
+
speed2: '正常',
|
|
58
|
+
speed3: '1.25',
|
|
59
|
+
speed4: '1.5',
|
|
60
|
+
speed5: '2',
|
|
61
|
+
|
|
62
|
+
fontSize0: '极小',
|
|
63
|
+
fontSize1: '适中',
|
|
64
|
+
fontSize2: '极大',
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const en: langMap = {
|
|
68
|
+
danmuSwitch: 'Barrage switch',
|
|
69
|
+
danmuSetting: 'Barrage settings',
|
|
70
|
+
openDanmu: 'Open Barrage',
|
|
71
|
+
reset: 'Reset',
|
|
72
|
+
opacity: 'Opacity',
|
|
73
|
+
area: 'Display area',
|
|
74
|
+
speed: 'Barrage speed',
|
|
75
|
+
fontSize: 'Font size',
|
|
76
|
+
danmuMask: 'Intelligent blocking',
|
|
77
|
+
|
|
78
|
+
screen0: '1/4 screen',
|
|
79
|
+
screen1: 'Half screen',
|
|
80
|
+
screen2: '3/4 screen',
|
|
81
|
+
screen3: 'Full screen',
|
|
82
|
+
|
|
83
|
+
opacity0: '0',
|
|
84
|
+
opacity1: '1/3',
|
|
85
|
+
opacity2: '2/3',
|
|
86
|
+
opacity3: '1',
|
|
87
|
+
|
|
88
|
+
speed0: '0.25',
|
|
89
|
+
speed1: '0.5',
|
|
90
|
+
speed2: 'Normal',
|
|
91
|
+
speed3: '1.25',
|
|
92
|
+
speed4: '1.5',
|
|
93
|
+
speed5: '2',
|
|
94
|
+
|
|
95
|
+
fontSize0: 'Minimal',
|
|
96
|
+
fontSize1: 'Moderate',
|
|
97
|
+
fontSize2: 'Great',
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const jp: langMap = en;
|
|
101
|
+
const zhHK: langMap = {
|
|
102
|
+
danmuSwitch: '彈幕開關',
|
|
103
|
+
danmuSetting: '彈幕設置',
|
|
104
|
+
openDanmu: '打開彈幕',
|
|
105
|
+
reset: '重置',
|
|
106
|
+
opacity: '不透明度',
|
|
107
|
+
area: '顯示區域',
|
|
108
|
+
speed: '彈幕速度',
|
|
109
|
+
fontSize: '字體大小',
|
|
110
|
+
danmuMask: '智能擋板',
|
|
111
|
+
|
|
112
|
+
screen0: '1/4屏',
|
|
113
|
+
screen1: '半屏',
|
|
114
|
+
screen2: '3/4屏',
|
|
115
|
+
screen3: '全屏',
|
|
116
|
+
|
|
117
|
+
opacity0: '0',
|
|
118
|
+
opacity1: '1/3',
|
|
119
|
+
opacity2: '2/3',
|
|
120
|
+
opacity3: '1',
|
|
121
|
+
|
|
122
|
+
speed0: '0.25',
|
|
123
|
+
speed1: '0.5',
|
|
124
|
+
speed2: '正常',
|
|
125
|
+
speed3: '1.25',
|
|
126
|
+
speed4: '1.5',
|
|
127
|
+
speed5: '2',
|
|
128
|
+
|
|
129
|
+
fontSize0: '極小',
|
|
130
|
+
fontSize1: '適中',
|
|
131
|
+
fontSize2: '極大',
|
|
132
|
+
};
|
|
133
|
+
export default {
|
|
134
|
+
zh,
|
|
135
|
+
'zh-cn': zh,
|
|
136
|
+
en,
|
|
137
|
+
jp,
|
|
138
|
+
'zh-hk': zhHK,
|
|
139
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import helpers from 'dom-helpers';
|
|
2
|
+
import State from './state';
|
|
3
|
+
export default class Panel {
|
|
4
|
+
root: HTMLElement;
|
|
5
|
+
state: State;
|
|
6
|
+
constructor(state: State) {
|
|
7
|
+
this.state = state;
|
|
8
|
+
this.root = document.createElement('div');
|
|
9
|
+
helpers.addClass(this.root, 'panel-box');
|
|
10
|
+
helpers.addEventListener(this.root, 'click', event => {
|
|
11
|
+
event.stopPropagation();
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
destroy() {
|
|
15
|
+
if (this.root.parentNode) {
|
|
16
|
+
this.root.parentNode.removeChild(this.root);
|
|
17
|
+
}
|
|
18
|
+
this.root = null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description 滑块
|
|
3
|
+
*/
|
|
4
|
+
import helpers from 'dom-helpers';
|
|
5
|
+
import throttle from 'lodash-es/throttle';
|
|
6
|
+
|
|
7
|
+
import { SliderItemProps, Tick } from './index';
|
|
8
|
+
|
|
9
|
+
enum DragStatus {
|
|
10
|
+
start = 1,
|
|
11
|
+
drag = 2,
|
|
12
|
+
end = 3,
|
|
13
|
+
}
|
|
14
|
+
export default class Slider {
|
|
15
|
+
parent: HTMLElement;
|
|
16
|
+
sliderTitle: HTMLElement;
|
|
17
|
+
sliderContent: HTMLElement;
|
|
18
|
+
sliderValue: HTMLElement;
|
|
19
|
+
wrapper: HTMLElement;
|
|
20
|
+
inner: HTMLElement;
|
|
21
|
+
button: HTMLElement;
|
|
22
|
+
ticks: Tick[] = [];
|
|
23
|
+
range = [0, 100];
|
|
24
|
+
currentValue = 0;
|
|
25
|
+
currentTick: Tick = { name: '', val: 0, renderVal: 0 };
|
|
26
|
+
buttonStatus: DragStatus = DragStatus.start;
|
|
27
|
+
startClientX = 0;
|
|
28
|
+
wrapperWidth = 1;
|
|
29
|
+
wrapperLeft = 0;
|
|
30
|
+
handleChange: Function = () => {};
|
|
31
|
+
itemProps: SliderItemProps;
|
|
32
|
+
|
|
33
|
+
constructor(div: HTMLElement, props: SliderItemProps) {
|
|
34
|
+
this.parent = div;
|
|
35
|
+
this.ticks = props.ticks;
|
|
36
|
+
this.itemProps = props;
|
|
37
|
+
this.sliderTitle = document.createElement('div');
|
|
38
|
+
this.sliderTitle.innerHTML = props.name;
|
|
39
|
+
this.sliderContent = document.createElement('div');
|
|
40
|
+
this.sliderValue = document.createElement('div');
|
|
41
|
+
|
|
42
|
+
this.wrapper = document.createElement('div');
|
|
43
|
+
this.inner = document.createElement('div');
|
|
44
|
+
this.button = document.createElement('div');
|
|
45
|
+
helpers.addClass(this.wrapper, 'wrapper');
|
|
46
|
+
helpers.addClass(this.parent, 'xg-player-slider');
|
|
47
|
+
helpers.addClass(this.sliderContent, 'line-slider');
|
|
48
|
+
helpers.addClass(this.sliderTitle, 'line-title');
|
|
49
|
+
helpers.addClass(this.sliderValue, 'line-value');
|
|
50
|
+
this.renderTicks();
|
|
51
|
+
this.rendInner();
|
|
52
|
+
this.parent.appendChild(this.sliderTitle);
|
|
53
|
+
this.parent.appendChild(this.sliderContent);
|
|
54
|
+
this.parent.appendChild(this.sliderValue);
|
|
55
|
+
this.sliderContent.appendChild(this.wrapper);
|
|
56
|
+
this.bindEvents();
|
|
57
|
+
this.setValue(props.defaultValue);
|
|
58
|
+
}
|
|
59
|
+
renderTicks() {
|
|
60
|
+
const wrapper = this.wrapper;
|
|
61
|
+
const ticks = document.createElement('div');
|
|
62
|
+
helpers.addClass(ticks, 'ticks');
|
|
63
|
+
for (let i = 1; i < this.ticks.length - 1; i++) {
|
|
64
|
+
const item = this.ticks[i];
|
|
65
|
+
const tick = document.createElement('div');
|
|
66
|
+
helpers.addClass(tick, 'tick');
|
|
67
|
+
helpers.style(tick, { left: item.val + '%' });
|
|
68
|
+
ticks.appendChild(tick);
|
|
69
|
+
}
|
|
70
|
+
wrapper.appendChild(ticks);
|
|
71
|
+
}
|
|
72
|
+
rendInner() {
|
|
73
|
+
const wrapper = this.wrapper;
|
|
74
|
+
const inner = this.inner;
|
|
75
|
+
helpers.addClass(inner, 'inner');
|
|
76
|
+
const button = this.button;
|
|
77
|
+
helpers.addClass(button, 'button');
|
|
78
|
+
wrapper.appendChild(inner);
|
|
79
|
+
wrapper.appendChild(button);
|
|
80
|
+
}
|
|
81
|
+
bindEvents() {
|
|
82
|
+
helpers.addEventListener(this.wrapper, 'click', this.onClick.bind(this));
|
|
83
|
+
helpers.addEventListener(
|
|
84
|
+
this.button,
|
|
85
|
+
'touchstart',
|
|
86
|
+
this.onTouchStart.bind(this),
|
|
87
|
+
);
|
|
88
|
+
helpers.addEventListener(
|
|
89
|
+
this.button,
|
|
90
|
+
'touchmove',
|
|
91
|
+
throttle(this.onTouchmove.bind(this), 30),
|
|
92
|
+
);
|
|
93
|
+
helpers.addEventListener(
|
|
94
|
+
this.button,
|
|
95
|
+
'touchend',
|
|
96
|
+
this.onTouchend.bind(this),
|
|
97
|
+
);
|
|
98
|
+
helpers.addEventListener(
|
|
99
|
+
this.button,
|
|
100
|
+
'touchcancel',
|
|
101
|
+
this.onTouchend.bind(this),
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
setValue(val: number): boolean {
|
|
105
|
+
if (val > this.range[1] || val < this.range[0]) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
this.currentTick = this.getCurrentTick(val);
|
|
110
|
+
this.currentValue = this.currentTick.val;
|
|
111
|
+
const percent = this.currentValue + '%';
|
|
112
|
+
setTimeout(() => {
|
|
113
|
+
helpers.style(this.inner, { width: percent });
|
|
114
|
+
helpers.style(this.button, { left: percent });
|
|
115
|
+
});
|
|
116
|
+
this.sliderValue.innerHTML = this.currentTick.name;
|
|
117
|
+
this.handleChange(this.currentValue);
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
renderText(props: SliderItemProps) {
|
|
121
|
+
this.ticks = props.ticks;
|
|
122
|
+
this.itemProps = props;
|
|
123
|
+
this.sliderTitle.innerHTML = props.name;
|
|
124
|
+
this.currentTick = this.ticks.filter(
|
|
125
|
+
tick => tick.val === this.currentValue,
|
|
126
|
+
)[0];
|
|
127
|
+
this.sliderValue.innerHTML = this.currentTick.name;
|
|
128
|
+
}
|
|
129
|
+
onChange(callback: Function) {
|
|
130
|
+
this.handleChange = callback;
|
|
131
|
+
}
|
|
132
|
+
getCurrentTick(val: number) {
|
|
133
|
+
for (let i = 0; i < this.ticks.length - 1; i++) {
|
|
134
|
+
if (this.ticks[i].val <= val && this.ticks[i + 1].val >= val) {
|
|
135
|
+
return val - this.ticks[i].val > this.ticks[i + 1].val - val
|
|
136
|
+
? this.ticks[i + 1]
|
|
137
|
+
: this.ticks[i];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return this.ticks[0];
|
|
141
|
+
}
|
|
142
|
+
onMousedown(event: MouseEvent) {
|
|
143
|
+
this.startClientX = event.clientX;
|
|
144
|
+
this.onStart();
|
|
145
|
+
}
|
|
146
|
+
onTouchStart(event: TouchEvent) {
|
|
147
|
+
event.stopPropagation();
|
|
148
|
+
this.startClientX = event.touches[0].clientX;
|
|
149
|
+
this.onStart();
|
|
150
|
+
}
|
|
151
|
+
onStart() {
|
|
152
|
+
this.buttonStatus = DragStatus.drag;
|
|
153
|
+
const position = helpers.offset(this.wrapper);
|
|
154
|
+
this.wrapperWidth = position.width;
|
|
155
|
+
this.wrapperLeft = position.left;
|
|
156
|
+
}
|
|
157
|
+
onMousemove(event: MouseEvent) {
|
|
158
|
+
if (this.buttonStatus !== DragStatus.drag) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const deltaX = event.clientX - this.startClientX;
|
|
162
|
+
this.onMove(deltaX);
|
|
163
|
+
}
|
|
164
|
+
onTouchmove(event: TouchEvent) {
|
|
165
|
+
event.stopPropagation();
|
|
166
|
+
|
|
167
|
+
const deltaX = event.touches[0].clientX - this.startClientX;
|
|
168
|
+
this.onMove(deltaX);
|
|
169
|
+
}
|
|
170
|
+
onMove(deltaX: number) {
|
|
171
|
+
const nextClientX = this.startClientX + deltaX;
|
|
172
|
+
if (
|
|
173
|
+
nextClientX - this.wrapperLeft < 0 ||
|
|
174
|
+
nextClientX - this.wrapperLeft > this.wrapperWidth
|
|
175
|
+
) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
this.startClientX = this.startClientX + deltaX;
|
|
179
|
+
const percent =
|
|
180
|
+
((this.startClientX - this.wrapperLeft) *
|
|
181
|
+
(this.range[1] - this.range[0])) /
|
|
182
|
+
this.wrapperWidth;
|
|
183
|
+
helpers.style(this.inner, { width: percent + '%' });
|
|
184
|
+
helpers.style(this.button, { left: percent + '%' });
|
|
185
|
+
}
|
|
186
|
+
onMouseup(event: MouseEvent) {
|
|
187
|
+
this.onEnd();
|
|
188
|
+
}
|
|
189
|
+
onTouchend() {
|
|
190
|
+
this.onEnd();
|
|
191
|
+
}
|
|
192
|
+
onEnd() {
|
|
193
|
+
this.buttonStatus = DragStatus.end;
|
|
194
|
+
const val =
|
|
195
|
+
((this.startClientX - this.wrapperLeft) *
|
|
196
|
+
(this.range[1] - this.range[0])) /
|
|
197
|
+
this.wrapperWidth;
|
|
198
|
+
this.setValue(val);
|
|
199
|
+
}
|
|
200
|
+
onClick(event: MouseEvent) {
|
|
201
|
+
event.stopPropagation();
|
|
202
|
+
const position = helpers.offset(this.wrapper);
|
|
203
|
+
this.wrapperWidth = position.width;
|
|
204
|
+
this.wrapperLeft = position.left;
|
|
205
|
+
const val =
|
|
206
|
+
((event.clientX - this.wrapperLeft) * (this.range[1] - this.range[0])) /
|
|
207
|
+
this.wrapperWidth;
|
|
208
|
+
this.setValue(val);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { IDanmuConfig, SliderItemProps } from './index';
|
|
2
|
+
|
|
3
|
+
import lang, { langMap } from './lang';
|
|
4
|
+
|
|
5
|
+
export default class State {
|
|
6
|
+
public curLang = 'en';
|
|
7
|
+
public curLangMap: langMap;
|
|
8
|
+
private _defaultConfig: IDanmuConfig = {
|
|
9
|
+
opacity: 99,
|
|
10
|
+
area: 99,
|
|
11
|
+
fontSize: 50,
|
|
12
|
+
speed: 40,
|
|
13
|
+
active: true,
|
|
14
|
+
usePanel: true,
|
|
15
|
+
danmuItems: [],
|
|
16
|
+
maskConfig: {
|
|
17
|
+
maskUrl: '',
|
|
18
|
+
maskOffset: 0,
|
|
19
|
+
interval: 200,
|
|
20
|
+
},
|
|
21
|
+
maskActive: false,
|
|
22
|
+
external: [
|
|
23
|
+
// {
|
|
24
|
+
// key: 'mask',
|
|
25
|
+
// name: '智能挡板',
|
|
26
|
+
// lang: {
|
|
27
|
+
// en: 'Intelligent blocking',
|
|
28
|
+
// zh: '智能挡板',
|
|
29
|
+
// 'zh-cn': '智能挡板',
|
|
30
|
+
// 'zh-hk': '智能擋板',
|
|
31
|
+
// },
|
|
32
|
+
// value: false,
|
|
33
|
+
// },
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
public sliderItemsProps: SliderItemProps[];
|
|
37
|
+
|
|
38
|
+
constructor(config: IDanmuConfig) {
|
|
39
|
+
Object.assign(this._defaultConfig, config);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
updateLang(language: string) {
|
|
43
|
+
this.curLang = language;
|
|
44
|
+
this.curLangMap = lang[language] || lang['en'];
|
|
45
|
+
const curLangMap = this.curLangMap;
|
|
46
|
+
this.sliderItemsProps = [
|
|
47
|
+
{
|
|
48
|
+
key: 'opacity',
|
|
49
|
+
name: curLangMap.opacity,
|
|
50
|
+
defaultValue: 99,
|
|
51
|
+
ticks: [
|
|
52
|
+
{ name: curLangMap.opacity0, val: 0, renderVal: 0 },
|
|
53
|
+
{ name: curLangMap.opacity1, val: 33, renderVal: 0.33 },
|
|
54
|
+
{ name: curLangMap.opacity2, val: 66, renderVal: 0.66 },
|
|
55
|
+
{ name: curLangMap.opacity3, val: 99, renderVal: 1 },
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
key: 'area',
|
|
60
|
+
name: curLangMap.area,
|
|
61
|
+
defaultValue: 99,
|
|
62
|
+
ticks: [
|
|
63
|
+
{ name: curLangMap.screen0, val: 0, renderVal: 1 / 4 },
|
|
64
|
+
{ name: curLangMap.screen1, val: 33, renderVal: 1 / 2 },
|
|
65
|
+
{ name: curLangMap.screen2, val: 66, renderVal: 3 / 4 },
|
|
66
|
+
{ name: curLangMap.screen3, val: 99, renderVal: 1 },
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
key: 'speed',
|
|
71
|
+
name: curLangMap.speed,
|
|
72
|
+
defaultValue: 40,
|
|
73
|
+
ticks: [
|
|
74
|
+
{ name: curLangMap.speed0, val: 0, renderVal: 1 / 4 },
|
|
75
|
+
{ name: curLangMap.speed1, val: 20, renderVal: 1 / 2 },
|
|
76
|
+
{ name: curLangMap.speed2, val: 40, renderVal: 1 },
|
|
77
|
+
{ name: curLangMap.speed3, val: 60, renderVal: 5 / 4 },
|
|
78
|
+
{ name: curLangMap.speed4, val: 80, renderVal: 3 / 2 },
|
|
79
|
+
{ name: curLangMap.speed5, val: 100, renderVal: 2 },
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
key: 'fontSize',
|
|
84
|
+
name: curLangMap.fontSize,
|
|
85
|
+
defaultValue: 50,
|
|
86
|
+
ticks: [
|
|
87
|
+
{ name: curLangMap.fontSize0, val: 0, renderVal: 14 },
|
|
88
|
+
{ name: curLangMap.fontSize1, val: 50, renderVal: 16 },
|
|
89
|
+
{ name: curLangMap.fontSize2, val: 100, renderVal: 20 },
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
];
|
|
93
|
+
this._defaultConfig.external.forEach(ex => {
|
|
94
|
+
ex.name = ex.lang[language] || ex.lang['en'];
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
getConfig(): IDanmuConfig {
|
|
99
|
+
return this._defaultConfig;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
updateConfig(config: Partial<IDanmuConfig>) {
|
|
103
|
+
Object.assign(this._defaultConfig, config);
|
|
104
|
+
// update UI
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
updateComments(danmuItems: []) {
|
|
108
|
+
this._defaultConfig.danmuItems = danmuItems;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
getRenderVal(key: string, val: number) {
|
|
112
|
+
const Item =
|
|
113
|
+
this.sliderItemsProps.find(item => item.key === key) ||
|
|
114
|
+
this.sliderItemsProps[0];
|
|
115
|
+
const Tick = Item.ticks.find(tick => tick.val === val) || Item.ticks[0];
|
|
116
|
+
return Tick.renderVal;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ExternalItem } from './index';
|
|
2
|
+
import helpers from 'dom-helpers';
|
|
3
|
+
import debounce from 'lodash-es/debounce';
|
|
4
|
+
|
|
5
|
+
export type SwitchInstance = InstanceType<typeof Switch>;
|
|
6
|
+
|
|
7
|
+
export default class Switch {
|
|
8
|
+
key: string;
|
|
9
|
+
name: string;
|
|
10
|
+
value: boolean;
|
|
11
|
+
root: HTMLElement;
|
|
12
|
+
$left: HTMLDivElement;
|
|
13
|
+
$right: HTMLDivElement;
|
|
14
|
+
callback: Function = () => {};
|
|
15
|
+
constructor(item: ExternalItem) {
|
|
16
|
+
this.key = item.key;
|
|
17
|
+
this.name = item.name;
|
|
18
|
+
this.value = item.value;
|
|
19
|
+
this.root = document.createElement('div');
|
|
20
|
+
helpers.addClass(this.root, 'xg-player-switch-wrapper');
|
|
21
|
+
this.render();
|
|
22
|
+
}
|
|
23
|
+
render() {
|
|
24
|
+
if (!this.root.childNodes.length) {
|
|
25
|
+
const left = document.createElement('div');
|
|
26
|
+
this.$left = left;
|
|
27
|
+
helpers.addClass(left, 'left');
|
|
28
|
+
left.innerHTML = this.name;
|
|
29
|
+
|
|
30
|
+
const right = document.createElement('div');
|
|
31
|
+
this.$right = right;
|
|
32
|
+
helpers.addClass(right, 'right');
|
|
33
|
+
|
|
34
|
+
right.innerHTML = `<label class="switch">
|
|
35
|
+
<input type="checkbox">
|
|
36
|
+
<span class="slider round"></span>
|
|
37
|
+
</label>`;
|
|
38
|
+
|
|
39
|
+
this.root.appendChild(left);
|
|
40
|
+
this.root.appendChild(right);
|
|
41
|
+
|
|
42
|
+
const input = this.$right.querySelector('input');
|
|
43
|
+
|
|
44
|
+
helpers.addEventListener(
|
|
45
|
+
this.$right,
|
|
46
|
+
'click',
|
|
47
|
+
debounce(event => {
|
|
48
|
+
event.stopPropagation();
|
|
49
|
+
this.value = !this.value;
|
|
50
|
+
if (this.value) {
|
|
51
|
+
input?.setAttribute('checked', 'checked');
|
|
52
|
+
} else {
|
|
53
|
+
input?.removeAttribute('checked');
|
|
54
|
+
}
|
|
55
|
+
this.callback(this.value);
|
|
56
|
+
}, 50),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const input = this.$right.querySelector('input');
|
|
61
|
+
if (this.value) {
|
|
62
|
+
input?.setAttribute('checked', 'checked');
|
|
63
|
+
} else {
|
|
64
|
+
input.removeAttribute('checked');
|
|
65
|
+
}
|
|
66
|
+
input.checked = this.value;
|
|
67
|
+
}
|
|
68
|
+
renderName(name = '') {
|
|
69
|
+
this.$left.innerHTML = name;
|
|
70
|
+
}
|
|
71
|
+
onChange(callback: Function) {
|
|
72
|
+
this.callback = callback;
|
|
73
|
+
}
|
|
74
|
+
}
|