xgplayer 2.32.5 → 2.32.6
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/browser/controls/airplay.js +1 -1
- package/browser/controls/cssFullscreen.js +1 -1
- package/browser/controls/danmu.js +3 -1
- package/browser/controls/definition.js +1 -1
- package/browser/controls/download.js +1 -1
- package/browser/controls/enter.js +1 -1
- package/browser/controls/error.js +1 -1
- package/browser/controls/errorRetry.js +1 -1
- package/browser/controls/flex.js +1 -1
- package/browser/controls/fullscreen.js +1 -1
- package/browser/controls/loading.js +1 -1
- package/browser/controls/memoryPlay.js +1 -1
- package/browser/controls/miniplayer.js +9 -7
- package/browser/controls/mobile.js +1 -1
- package/browser/controls/nativeTextTrack.js +1 -1
- package/browser/controls/pc.js +1 -1
- package/browser/controls/pip.js +1 -1
- package/browser/controls/play.js +1 -1
- package/browser/controls/playNext.js +1 -1
- package/browser/controls/playbackRate.js +1 -1
- package/browser/controls/poster.js +1 -1
- package/browser/controls/progress.js +1 -1
- package/browser/controls/reload.js +1 -1
- package/browser/controls/replay.js +1 -1
- package/browser/controls/rotate.js +1 -1
- package/browser/controls/screenShot.js +1 -1
- package/browser/controls/start.js +1 -1
- package/browser/controls/textTrack.js +1 -1
- package/browser/controls/time.js +1 -1
- package/browser/controls/volume.js +1 -1
- package/browser/core_player.js +1 -1
- package/browser/core_player.js.map +1 -1
- package/browser/index.js +11 -7
- package/browser/index.js.map +1 -1
- package/browser/simple_player.js +1 -1
- package/browser/simple_player.js.map +1 -1
- package/dist/controls/airplay.js +1 -1
- package/dist/controls/cssFullscreen.js +1 -1
- package/dist/controls/danmu.js +3 -1
- package/dist/controls/definition.js +1 -1
- package/dist/controls/download.js +1 -1
- package/dist/controls/enter.js +1 -1
- package/dist/controls/error.js +1 -1
- package/dist/controls/errorRetry.js +1 -1
- package/dist/controls/flex.js +1 -1
- package/dist/controls/fullscreen.js +1 -1
- package/dist/controls/loading.js +1 -1
- package/dist/controls/memoryPlay.js +1 -1
- package/dist/controls/miniplayer.js +9 -7
- package/dist/controls/mobile.js +1 -1
- package/dist/controls/nativeTextTrack.js +1 -1
- package/dist/controls/pc.js +1 -1
- package/dist/controls/pip.js +1 -1
- package/dist/controls/play.js +1 -1
- package/dist/controls/playNext.js +1 -1
- package/dist/controls/playbackRate.js +1 -1
- package/dist/controls/poster.js +1 -1
- package/dist/controls/progress.js +1 -1
- package/dist/controls/reload.js +1 -1
- package/dist/controls/replay.js +1 -1
- package/dist/controls/rotate.js +1 -1
- package/dist/controls/screenShot.js +1 -1
- package/dist/controls/start.js +1 -1
- package/dist/controls/textTrack.js +1 -1
- package/dist/controls/time.js +1 -1
- package/dist/controls/volume.js +1 -1
- package/dist/core_player.js +2960 -2889
- package/dist/core_player.js.map +1 -1
- package/dist/index.js +1938 -3321
- package/dist/index.js.map +1 -1
- package/dist/index.min.css +1 -0
- package/dist/index.min.js +2 -0
- package/dist/index.min.js.map +1 -0
- package/dist/simple_player.js +274 -281
- package/dist/simple_player.js.map +1 -1
- package/es/_virtual/_rollupPluginBabelHelpers.js +216 -0
- package/es/constant.d.ts +4 -0
- package/es/constant.js +5 -0
- package/es/controls/airplay.js +1 -1
- package/es/controls/cssFullscreen.js +1 -1
- package/es/controls/danmu.js +3 -1
- package/es/controls/definition.js +1 -1
- package/es/controls/download.js +1 -1
- package/es/controls/enter.js +1 -1
- package/es/controls/error.js +1 -1
- package/es/controls/errorRetry.js +1 -1
- package/es/controls/flex.js +1 -1
- package/es/controls/fullscreen.js +1 -1
- package/es/controls/i18n.js +1 -1
- package/es/controls/keyboard.js +1 -1
- package/es/controls/loading.js +1 -1
- package/es/controls/localPreview.js +1 -1
- package/es/controls/memoryPlay.js +1 -1
- package/es/controls/miniplayer.js +9 -7
- package/es/controls/mobile.js +1 -1
- package/es/controls/nativeTextTrack.js +1 -1
- package/es/controls/pc.js +1 -1
- package/es/controls/pip.js +1 -1
- package/es/controls/play.js +1 -1
- package/es/controls/playNext.js +1 -1
- package/es/controls/playbackRate.js +1 -1
- package/es/controls/poster.js +1 -1
- package/es/controls/progress.js +1 -1
- package/es/controls/reload.js +1 -1
- package/es/controls/replay.js +1 -1
- package/es/controls/rotate.js +1 -1
- package/es/controls/screenShot.js +1 -1
- package/es/controls/start.js +1 -1
- package/es/controls/textTrack.js +1 -1
- package/es/controls/time.js +1 -1
- package/es/controls/volume.js +1 -1
- package/es/core_player.js +1 -1
- package/es/core_player.js.map +1 -1
- package/es/defaultConfig.d.ts +243 -0
- package/es/defaultConfig.js +85 -0
- package/es/error.d.ts +114 -0
- package/es/error.js +75 -0
- package/es/events.d.ts +61 -0
- package/es/events.js +62 -0
- package/es/icons.d.ts +2 -0
- package/es/index.css +499 -0
- package/es/index.d.ts +25 -0
- package/es/index.js +11 -7
- package/es/index.js.map +1 -1
- package/es/index.scss +29 -0
- package/es/index.umd.d.ts +60 -0
- package/es/index.umd.js +30 -0
- package/es/lang/en.d.ts +91 -0
- package/es/lang/en.js +77 -0
- package/es/lang/i18n.d.ts +36 -0
- package/es/lang/i18n.js +122 -0
- package/es/lang/index.d.ts +2 -0
- package/es/lang/jp.d.ts +91 -0
- package/es/lang/jp.js +77 -0
- package/es/lang/zh-cn.d.ts +91 -0
- package/es/lang/zh-cn.js +77 -0
- package/es/lang/zh-hk.d.ts +91 -0
- package/es/lang/zh-hk.js +77 -0
- package/es/mediaProxy.d.ts +334 -0
- package/es/mediaProxy.js +623 -0
- package/es/player.d.ts +825 -0
- package/es/player.js +1945 -0
- package/es/plugin/basePlugin.d.ts +180 -0
- package/es/plugin/basePlugin.js +259 -0
- package/es/plugin/hooksDescriptor.d.ts +60 -0
- package/es/plugin/hooksDescriptor.js +149 -0
- package/es/plugin/index.d.ts +13 -0
- package/es/plugin/plugin.d.ts +207 -0
- package/es/plugin/plugin.js +542 -0
- package/es/plugin/pluginsManager.d.ts +162 -0
- package/es/plugin/pluginsManager.js +362 -0
- package/es/plugin/preset.d.ts +1 -0
- package/es/plugin/preset.js +28 -0
- package/es/plugin/resizeObserver.d.ts +3 -0
- package/es/plugin/resizeObserver.js +108 -0
- package/es/plugins/assets/back.js +4 -0
- package/es/plugins/assets/download.js +4 -0
- package/es/plugins/assets/exitCssFull.js +4 -0
- package/es/plugins/assets/exitFull.js +4 -0
- package/es/plugins/assets/loading.js +4 -0
- package/es/plugins/assets/panel.js +4 -0
- package/es/plugins/assets/pause.js +4 -0
- package/es/plugins/assets/pipIcon.js +4 -0
- package/es/plugins/assets/pipIconExit.js +4 -0
- package/es/plugins/assets/play.js +4 -0
- package/es/plugins/assets/playNext.js +4 -0
- package/es/plugins/assets/replay.js +4 -0
- package/es/plugins/assets/requestCssFull.js +7 -0
- package/es/plugins/assets/requestFull.js +4 -0
- package/es/plugins/assets/rotate.js +4 -0
- package/es/plugins/assets/seekicon.js +4 -0
- package/es/plugins/assets/volumeLarge.js +4 -0
- package/es/plugins/assets/volumeMuted.js +4 -0
- package/es/plugins/assets/volumeSmall.js +4 -0
- package/es/plugins/common/iconPlugin.d.ts +5 -0
- package/es/plugins/common/iconPlugin.js +42 -0
- package/es/plugins/common/iconTools.d.ts +1 -0
- package/es/plugins/common/iconTools.js +8 -0
- package/es/plugins/common/index.scss +2 -0
- package/es/plugins/common/optionList.d.ts +15 -0
- package/es/plugins/common/optionList.js +120 -0
- package/es/plugins/common/optionsIcon.d.ts +40 -0
- package/es/plugins/common/optionsIcon.js +304 -0
- package/es/plugins/common/optionsIcon.scss +154 -0
- package/es/plugins/common/thumbnail.d.ts +62 -0
- package/es/plugins/common/thumbnail.js +191 -0
- package/es/plugins/common/thumbnail.scss +27 -0
- package/es/plugins/controls/index.css +132 -0
- package/es/plugins/controls/index.d.ts +73 -0
- package/es/plugins/controls/index.js +189 -0
- package/es/plugins/controls/index.scss +204 -0
- package/es/plugins/cssFullScreen/index.css +12 -0
- package/es/plugins/cssFullScreen/index.d.ts +40 -0
- package/es/plugins/cssFullScreen/index.js +136 -0
- package/es/plugins/cssFullScreen/index.scss +19 -0
- package/es/plugins/danmu/danmuIcon.d.ts +24 -0
- package/es/plugins/danmu/danmuIcon.js +98 -0
- package/es/plugins/danmu/danmuPanel.d.ts +39 -0
- package/es/plugins/danmu/danmuPanel.js +81 -0
- package/es/plugins/danmu/index.css +603 -0
- package/es/plugins/danmu/index.d.ts +96 -0
- package/es/plugins/danmu/index.js +313 -0
- package/es/plugins/danmu/index.scss +356 -0
- package/es/plugins/definition/index.css +4 -0
- package/es/plugins/definition/index.d.ts +38 -0
- package/es/plugins/definition/index.js +164 -0
- package/es/plugins/definition/index.scss +4 -0
- package/es/plugins/download/index.css +13 -0
- package/es/plugins/download/index.d.ts +31 -0
- package/es/plugins/download/index.js +107 -0
- package/es/plugins/download/index.scss +22 -0
- package/es/plugins/dynamicBg/index.css +16 -0
- package/es/plugins/dynamicBg/index.d.ts +83 -0
- package/es/plugins/dynamicBg/index.js +316 -0
- package/es/plugins/dynamicBg/index.scss +19 -0
- package/es/plugins/enter/index.css +104 -0
- package/es/plugins/enter/index.d.ts +19 -0
- package/es/plugins/enter/index.js +46 -0
- package/es/plugins/enter/index.scss +78 -0
- package/es/plugins/error/index.css +29 -0
- package/es/plugins/error/index.d.ts +8 -0
- package/es/plugins/error/index.js +75 -0
- package/es/plugins/error/index.scss +34 -0
- package/es/plugins/fpsDetect/index.d.ts +34 -0
- package/es/plugins/fpsDetect/index.js +149 -0
- package/es/plugins/fullscreen/backicon.d.ts +17 -0
- package/es/plugins/fullscreen/backicon.js +72 -0
- package/es/plugins/fullscreen/index.css +23 -0
- package/es/plugins/fullscreen/index.d.ts +58 -0
- package/es/plugins/fullscreen/index.js +202 -0
- package/es/plugins/fullscreen/index.scss +35 -0
- package/es/plugins/gapJump/index.d.ts +21 -0
- package/es/plugins/gapJump/index.js +142 -0
- package/es/plugins/keyboard/index.d.ts +89 -0
- package/es/plugins/keyboard/index.js +421 -0
- package/es/plugins/loading/index.css +58 -0
- package/es/plugins/loading/index.d.ts +11 -0
- package/es/plugins/loading/index.js +43 -0
- package/es/plugins/loading/index.scss +70 -0
- package/es/plugins/logger/index.d.ts +54 -0
- package/es/plugins/logger/index.js +311 -0
- package/es/plugins/miniScreen/index.css +179 -0
- package/es/plugins/miniScreen/index.d.ts +68 -0
- package/es/plugins/miniScreen/index.js +212 -0
- package/es/plugins/miniScreen/index.scss +198 -0
- package/es/plugins/miniScreen/miniScreenIcon.d.ts +11 -0
- package/es/plugins/miniScreen/miniScreenIcon.js +56 -0
- package/es/plugins/mobile/index.css +181 -0
- package/es/plugins/mobile/index.d.ts +125 -0
- package/es/plugins/mobile/index.js +631 -0
- package/es/plugins/mobile/index.scss +180 -0
- package/es/plugins/mobile/touch.d.ts +43 -0
- package/es/plugins/mobile/touch.js +214 -0
- package/es/plugins/netAdaption/index.d.ts +5 -0
- package/es/plugins/pc/index.css +3 -0
- package/es/plugins/pc/index.d.ts +14 -0
- package/es/plugins/pc/index.js +199 -0
- package/es/plugins/pc/index.scss +5 -0
- package/es/plugins/pip/index.css +12 -0
- package/es/plugins/pip/index.d.ts +37 -0
- package/es/plugins/pip/index.js +222 -0
- package/es/plugins/pip/index.scss +21 -0
- package/es/plugins/play/index.css +12 -0
- package/es/plugins/play/index.d.ts +23 -0
- package/es/plugins/play/index.js +127 -0
- package/es/plugins/play/index.scss +18 -0
- package/es/plugins/playNext/index.css +22 -0
- package/es/plugins/playNext/index.d.ts +19 -0
- package/es/plugins/playNext/index.js +104 -0
- package/es/plugins/playNext/index.scss +35 -0
- package/es/plugins/playbackRate/index.css +4 -0
- package/es/plugins/playbackRate/index.d.ts +31 -0
- package/es/plugins/playbackRate/index.js +140 -0
- package/es/plugins/playbackRate/index.scss +6 -0
- package/es/plugins/poster/index.css +39 -0
- package/es/plugins/poster/index.d.ts +27 -0
- package/es/plugins/poster/index.js +109 -0
- package/es/plugins/poster/index.scss +56 -0
- package/es/plugins/progress/index.css +234 -0
- package/es/plugins/progress/index.d.ts +178 -0
- package/es/plugins/progress/index.js +687 -0
- package/es/plugins/progress/index.scss +288 -0
- package/es/plugins/progress/innerList.d.ts +49 -0
- package/es/plugins/progress/innerList.js +285 -0
- package/es/plugins/progress/miniProgress.d.ts +9 -0
- package/es/plugins/progress/miniProgress.js +55 -0
- package/es/plugins/progressPreview/dotsApi.d.ts +1 -0
- package/es/plugins/progressPreview/dotsApi.js +269 -0
- package/es/plugins/progressPreview/index.css +190 -0
- package/es/plugins/progressPreview/index.d.ts +87 -0
- package/es/plugins/progressPreview/index.js +475 -0
- package/es/plugins/progressPreview/index.scss +235 -0
- package/es/plugins/prompt/index.css +47 -0
- package/es/plugins/prompt/index.d.ts +24 -0
- package/es/plugins/prompt/index.js +110 -0
- package/es/plugins/prompt/index.scss +53 -0
- package/es/plugins/replay/index.css +33 -0
- package/es/plugins/replay/index.d.ts +16 -0
- package/es/plugins/replay/index.js +109 -0
- package/es/plugins/replay/index.scss +41 -0
- package/es/plugins/rotate/index.css +0 -0
- package/es/plugins/rotate/index.d.ts +22 -0
- package/es/plugins/rotate/index.js +148 -0
- package/es/plugins/rotate/index.scss +0 -0
- package/es/plugins/rotate/index2.js +2 -0
- package/es/plugins/screenShot/index.css +3 -0
- package/es/plugins/screenShot/index.d.ts +30 -0
- package/es/plugins/screenShot/index.js +178 -0
- package/es/plugins/screenShot/index.scss +5 -0
- package/es/plugins/start/index.css +91 -0
- package/es/plugins/start/index.d.ts +41 -0
- package/es/plugins/start/index.js +267 -0
- package/es/plugins/start/index.scss +115 -0
- package/es/plugins/stats/index.d.ts +38 -0
- package/es/plugins/stats/index.js +194 -0
- package/es/plugins/testspeed/index.d.ts +26 -0
- package/es/plugins/testspeed/index.js +207 -0
- package/es/plugins/time/index.css +46 -0
- package/es/plugins/time/index.d.ts +28 -0
- package/es/plugins/time/index.js +225 -0
- package/es/plugins/time/index.scss +57 -0
- package/es/plugins/time/timesegments.d.ts +24 -0
- package/es/plugins/time/timesegments.js +216 -0
- package/es/plugins/track/index.css +91 -0
- package/es/plugins/track/index.d.ts +132 -0
- package/es/plugins/track/index.js +463 -0
- package/es/plugins/track/index.scss +111 -0
- package/es/plugins/track/nativeSubTitle.d.ts +22 -0
- package/es/plugins/track/nativeSubTitle.js +94 -0
- package/es/plugins/volume/index.css +95 -0
- package/es/plugins/volume/index.d.ts +88 -0
- package/es/plugins/volume/index.js +319 -0
- package/es/plugins/volume/index.scss +124 -0
- package/es/plugins/waitingTimeoutJump/index.d.ts +15 -0
- package/es/plugins/waitingTimeoutJump/index.js +88 -0
- package/es/presets/default-en.d.ts +33 -0
- package/es/presets/default-en.js +63 -0
- package/es/presets/default.d.ts +34 -0
- package/es/presets/default.js +70 -0
- package/es/presets/index.d.ts +4 -0
- package/es/presets/live.d.ts +94 -0
- package/es/presets/live.js +39 -0
- package/es/presets/mobile.d.ts +103 -0
- package/es/presets/mobile.js +34 -0
- package/es/simple_player.js +1 -1
- package/es/simple_player.js.map +1 -1
- package/es/state.d.ts +11 -0
- package/es/state.js +12 -0
- package/es/stateClassMap.d.ts +32 -0
- package/es/stateClassMap.js +32 -0
- package/es/style/common/animation.scss +16 -0
- package/es/style/common/svg-url.scss +70 -0
- package/es/style/common.scss +457 -0
- package/es/style/index.scss +4 -0
- package/es/style/variable.scss +76 -0
- package/es/utils/database.d.ts +31 -0
- package/es/utils/database.js +107 -0
- package/es/utils/debug.d.ts +10 -0
- package/es/utils/debug.js +43 -0
- package/es/utils/draggabilly.d.ts +54 -0
- package/es/utils/draggabilly.js +410 -0
- package/es/utils/sniffer.d.ts +28 -0
- package/es/utils/sniffer.js +150 -0
- package/es/utils/url.d.ts +1 -0
- package/es/utils/util.d.ts +304 -0
- package/es/utils/util.js +827 -0
- package/es/utils/xgplayerTimeRange.d.ts +7 -0
- package/es/utils/xgplayerTimeRange.js +25 -0
- package/es/version.d.ts +2 -0
- package/es/version.js +2 -0
- package/package.json +2 -3
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
export type Player = import('../player').default;
|
|
2
|
+
export type IPlayerOptions = import('../defaultConfig').IPlayerOptions;
|
|
3
|
+
export type IBasePluginOptions = {
|
|
4
|
+
[propName: string]: any;
|
|
5
|
+
index?: number;
|
|
6
|
+
player: Player;
|
|
7
|
+
pluginName: string;
|
|
8
|
+
config: {
|
|
9
|
+
[propName: string]: any;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* @typedef { import ('../player').default } Player
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @typedef { import ('../defaultConfig').IPlayerOptions } IPlayerOptions
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {{
|
|
20
|
+
* index?: number,
|
|
21
|
+
* player: Player,
|
|
22
|
+
* pluginName: string,
|
|
23
|
+
* config: {
|
|
24
|
+
* [propName: string]: any
|
|
25
|
+
* },
|
|
26
|
+
* [propName: string]: any;
|
|
27
|
+
* }} IBasePluginOptions
|
|
28
|
+
*/
|
|
29
|
+
declare class BasePlugin {
|
|
30
|
+
static defineGetterOrSetter(Obj: any, map: any): void;
|
|
31
|
+
/**
|
|
32
|
+
* @type { { [propName: string]: any } }
|
|
33
|
+
*/
|
|
34
|
+
static get defaultConfig(): {
|
|
35
|
+
[propName: string]: any;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* @type { string }
|
|
39
|
+
*/
|
|
40
|
+
static get pluginName(): string;
|
|
41
|
+
/**
|
|
42
|
+
* @param { IBasePluginOptions } args
|
|
43
|
+
*/
|
|
44
|
+
constructor(args: IBasePluginOptions);
|
|
45
|
+
/**
|
|
46
|
+
* @private
|
|
47
|
+
*/
|
|
48
|
+
private __args;
|
|
49
|
+
/**
|
|
50
|
+
* @private
|
|
51
|
+
*/
|
|
52
|
+
private __events;
|
|
53
|
+
__onceEvents: {};
|
|
54
|
+
config: {
|
|
55
|
+
[propName: string]: any;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* @readonly
|
|
59
|
+
* @type { Player }
|
|
60
|
+
*/
|
|
61
|
+
readonly player: Player;
|
|
62
|
+
/**
|
|
63
|
+
* @readonly
|
|
64
|
+
* @type { IPlayerOptions }
|
|
65
|
+
*/
|
|
66
|
+
readonly playerConfig: IPlayerOptions;
|
|
67
|
+
/**
|
|
68
|
+
* @readonly
|
|
69
|
+
* @type {string}
|
|
70
|
+
*/
|
|
71
|
+
readonly pluginName: string;
|
|
72
|
+
/**
|
|
73
|
+
* @param { IBasePluginOptions } args
|
|
74
|
+
*/
|
|
75
|
+
beforeCreate(args: IBasePluginOptions): void;
|
|
76
|
+
afterCreate(): void;
|
|
77
|
+
beforePlayerInit(): void;
|
|
78
|
+
onPluginsReady(): void;
|
|
79
|
+
afterPlayerInit(): void;
|
|
80
|
+
destroy(): void;
|
|
81
|
+
/**
|
|
82
|
+
* @private
|
|
83
|
+
* @param { any } args
|
|
84
|
+
*/
|
|
85
|
+
private __init;
|
|
86
|
+
logger: any;
|
|
87
|
+
/**
|
|
88
|
+
* 更新语言
|
|
89
|
+
* @param { string } lang
|
|
90
|
+
*/
|
|
91
|
+
updateLang(lang: string): void;
|
|
92
|
+
/**
|
|
93
|
+
* @type { string }
|
|
94
|
+
*/
|
|
95
|
+
get lang(): string;
|
|
96
|
+
get i18n(): import("../lang/i18n").IXGI18nText;
|
|
97
|
+
get i18nKeys(): {
|
|
98
|
+
[propName: string]: string;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* @description当前支持的事件类型
|
|
102
|
+
* @type { 'touch' | 'mouse' }
|
|
103
|
+
*/
|
|
104
|
+
get domEventType(): "touch" | "mouse";
|
|
105
|
+
/**
|
|
106
|
+
*
|
|
107
|
+
* @param { string | Array<string> } event
|
|
108
|
+
* @param { Function } callback
|
|
109
|
+
* @returns
|
|
110
|
+
*/
|
|
111
|
+
on(event: string | Array<string>, callback: Function): void;
|
|
112
|
+
/**
|
|
113
|
+
*
|
|
114
|
+
* @param { string } event
|
|
115
|
+
* @param { Function } callback
|
|
116
|
+
* @returns
|
|
117
|
+
*/
|
|
118
|
+
once(event: string, callback: Function): void;
|
|
119
|
+
/**
|
|
120
|
+
*
|
|
121
|
+
* @param { string } event
|
|
122
|
+
* @param { Function } callback
|
|
123
|
+
* @returns
|
|
124
|
+
*/
|
|
125
|
+
off(event: string, callback: Function): void;
|
|
126
|
+
offAll(): void;
|
|
127
|
+
/**
|
|
128
|
+
*
|
|
129
|
+
* @param { string } event
|
|
130
|
+
* @param {...any} res
|
|
131
|
+
* @returns
|
|
132
|
+
*/
|
|
133
|
+
emit(event: string, ...res: any[]): void;
|
|
134
|
+
emitUserAction(event: any, action: any, params?: {}): void;
|
|
135
|
+
/**
|
|
136
|
+
* @param { string } hookName
|
|
137
|
+
* @param { Function } handler
|
|
138
|
+
* @param { {pre: Function| null , next: Function | null} } preset
|
|
139
|
+
* @returns
|
|
140
|
+
*/
|
|
141
|
+
hook(hookName: string, handler: Function, preset?: {
|
|
142
|
+
pre: Function | null;
|
|
143
|
+
next: Function | null;
|
|
144
|
+
}, ...args: any[]): any;
|
|
145
|
+
/**
|
|
146
|
+
* @param { string } hookName
|
|
147
|
+
* @param { (plugin: any, ...args) => boolean | Promise<any> } handler
|
|
148
|
+
* @param {...any} args
|
|
149
|
+
* @returns { boolean } isSuccess
|
|
150
|
+
*/
|
|
151
|
+
useHooks(hookName: string, handler: (plugin: any, ...args: any[]) => boolean | Promise<any>, ...args: any[]): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* @param { string } hookName
|
|
154
|
+
* @param { (plugin: any, ...args) => boolean | Promise<any> } handler
|
|
155
|
+
* @param {...any} args
|
|
156
|
+
* @returns { boolean } isSuccess
|
|
157
|
+
*/
|
|
158
|
+
removeHooks(hookName: string, handler: (plugin: any, ...args: any[]) => boolean | Promise<any>, ...args: any[]): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* 注册子插件
|
|
161
|
+
* @param { any } plugin
|
|
162
|
+
* @param { any } [options]
|
|
163
|
+
* @param { string } [name]
|
|
164
|
+
* @returns { any }
|
|
165
|
+
*/
|
|
166
|
+
registerPlugin(plugin: any, options?: any, name?: string): any;
|
|
167
|
+
/**
|
|
168
|
+
*
|
|
169
|
+
* @param { string } name
|
|
170
|
+
* @returns { any | null }
|
|
171
|
+
*/
|
|
172
|
+
getPlugin(name: string): any | null;
|
|
173
|
+
__destroy(): void;
|
|
174
|
+
}
|
|
175
|
+
import Util from "../utils/util";
|
|
176
|
+
import Sniffer from "../utils/sniffer";
|
|
177
|
+
import Errors from "../error";
|
|
178
|
+
import * as Events from "../events";
|
|
179
|
+
import XG_DEBUG from "../utils/debug";
|
|
180
|
+
export { BasePlugin as default, Util, Sniffer, Errors, Events, XG_DEBUG };
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { createClass as _createClass, classCallCheck as _classCallCheck, objectSpread2 as _objectSpread2 } from "../_virtual/_rollupPluginBabelHelpers.js";
|
|
2
|
+
import util from "../utils/util.js";
|
|
3
|
+
export { default as Util } from "../utils/util.js";
|
|
4
|
+
import XG_DEBUG from "../utils/debug.js";
|
|
5
|
+
export { default as XG_DEBUG } from "../utils/debug.js";
|
|
6
|
+
import hooksDescriptor, { hook, useHooks, removeHooks, delHooksDescriptor } from "./hooksDescriptor.js";
|
|
7
|
+
function showErrorMsg(pluginName, msg) {
|
|
8
|
+
XG_DEBUG.logError("[".concat(pluginName, "] event or callback cant be undefined or null when call ").concat(msg));
|
|
9
|
+
}
|
|
10
|
+
var BasePlugin = /* @__PURE__ */ function() {
|
|
11
|
+
function BasePlugin2(args) {
|
|
12
|
+
_classCallCheck(this, BasePlugin2);
|
|
13
|
+
if (util.checkIsFunction(this.beforeCreate)) {
|
|
14
|
+
this.beforeCreate(args);
|
|
15
|
+
}
|
|
16
|
+
hooksDescriptor(this);
|
|
17
|
+
this.__args = args;
|
|
18
|
+
this.__events = {};
|
|
19
|
+
this.__onceEvents = {};
|
|
20
|
+
this.config = args.config || {};
|
|
21
|
+
this.player = null;
|
|
22
|
+
this.playerConfig = {};
|
|
23
|
+
this.pluginName = "";
|
|
24
|
+
this.__init(args);
|
|
25
|
+
}
|
|
26
|
+
_createClass(BasePlugin2, [{
|
|
27
|
+
key: "beforeCreate",
|
|
28
|
+
value: function beforeCreate(args) {
|
|
29
|
+
}
|
|
30
|
+
}, {
|
|
31
|
+
key: "afterCreate",
|
|
32
|
+
value: function afterCreate() {
|
|
33
|
+
}
|
|
34
|
+
}, {
|
|
35
|
+
key: "beforePlayerInit",
|
|
36
|
+
value: function beforePlayerInit() {
|
|
37
|
+
}
|
|
38
|
+
}, {
|
|
39
|
+
key: "onPluginsReady",
|
|
40
|
+
value: function onPluginsReady() {
|
|
41
|
+
}
|
|
42
|
+
}, {
|
|
43
|
+
key: "afterPlayerInit",
|
|
44
|
+
value: function afterPlayerInit() {
|
|
45
|
+
}
|
|
46
|
+
}, {
|
|
47
|
+
key: "destroy",
|
|
48
|
+
value: function destroy() {
|
|
49
|
+
}
|
|
50
|
+
}, {
|
|
51
|
+
key: "__init",
|
|
52
|
+
value: function __init(args) {
|
|
53
|
+
this.player = args.player;
|
|
54
|
+
this.playerConfig = args.player && args.player.config;
|
|
55
|
+
this.pluginName = args.pluginName ? args.pluginName.toLowerCase() : this.constructor.pluginName.toLowerCase();
|
|
56
|
+
this.logger = args.player && args.player.logger;
|
|
57
|
+
}
|
|
58
|
+
}, {
|
|
59
|
+
key: "updateLang",
|
|
60
|
+
value: function updateLang(lang) {
|
|
61
|
+
if (!lang) {
|
|
62
|
+
lang = this.lang;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}, {
|
|
66
|
+
key: "lang",
|
|
67
|
+
get: function get() {
|
|
68
|
+
return this.player.lang;
|
|
69
|
+
}
|
|
70
|
+
}, {
|
|
71
|
+
key: "i18n",
|
|
72
|
+
get: function get() {
|
|
73
|
+
return this.player.i18n;
|
|
74
|
+
}
|
|
75
|
+
}, {
|
|
76
|
+
key: "i18nKeys",
|
|
77
|
+
get: function get() {
|
|
78
|
+
return this.player.i18nKeys;
|
|
79
|
+
}
|
|
80
|
+
}, {
|
|
81
|
+
key: "domEventType",
|
|
82
|
+
get: function get() {
|
|
83
|
+
var _e = util.checkTouchSupport() ? "touch" : "mouse";
|
|
84
|
+
if (this.playerConfig && (this.playerConfig.domEventType === "touch" || this.playerConfig.domEventType === "mouse")) {
|
|
85
|
+
_e = this.playerConfig.domEventType;
|
|
86
|
+
}
|
|
87
|
+
return _e;
|
|
88
|
+
}
|
|
89
|
+
}, {
|
|
90
|
+
key: "on",
|
|
91
|
+
value: function on(event, callback) {
|
|
92
|
+
var _this = this;
|
|
93
|
+
if (!event || !callback || !this.player) {
|
|
94
|
+
showErrorMsg(this.pluginName, "plugin.on(event, callback)");
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (typeof event === "string") {
|
|
98
|
+
this.__events[event] = callback;
|
|
99
|
+
this.player.on(event, callback);
|
|
100
|
+
} else if (Array.isArray(event)) {
|
|
101
|
+
event.forEach(function(item) {
|
|
102
|
+
_this.__events[item] = callback;
|
|
103
|
+
_this.player.on(item, callback);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}, {
|
|
108
|
+
key: "once",
|
|
109
|
+
value: function once(event, callback) {
|
|
110
|
+
var _this2 = this;
|
|
111
|
+
if (!event || !callback || !this.player) {
|
|
112
|
+
showErrorMsg(this.pluginName, "plugin.once(event, callback)");
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (typeof event === "string") {
|
|
116
|
+
this.__onceEvents[event] = callback;
|
|
117
|
+
this.player.once(event, callback);
|
|
118
|
+
} else if (Array.isArray(event)) {
|
|
119
|
+
event.forEach(function(item) {
|
|
120
|
+
_this2.__onceEvents[item] = callback;
|
|
121
|
+
_this2.player.once(event, callback);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}, {
|
|
126
|
+
key: "off",
|
|
127
|
+
value: function off(event, callback) {
|
|
128
|
+
var _this3 = this;
|
|
129
|
+
if (!event || !callback || !this.player) {
|
|
130
|
+
showErrorMsg(this.pluginName, "plugin.off(event, callback)");
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (typeof event === "string") {
|
|
134
|
+
delete this.__events[event];
|
|
135
|
+
this.player.off(event, callback);
|
|
136
|
+
} else if (Array.isArray(event)) {
|
|
137
|
+
event.forEach(function(item) {
|
|
138
|
+
delete _this3.__events[event];
|
|
139
|
+
_this3.player.off(item, callback);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}, {
|
|
144
|
+
key: "offAll",
|
|
145
|
+
value: function offAll() {
|
|
146
|
+
var _this4 = this;
|
|
147
|
+
["__events", "__onceEvents"].forEach(function(key) {
|
|
148
|
+
Object.keys(_this4[key]).forEach(function(item) {
|
|
149
|
+
_this4[key][item] && _this4.off(item, _this4[key][item]);
|
|
150
|
+
item && delete _this4[key][item];
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
this.__events = {};
|
|
154
|
+
this.__onceEvents = {};
|
|
155
|
+
}
|
|
156
|
+
}, {
|
|
157
|
+
key: "emit",
|
|
158
|
+
value: function emit(event) {
|
|
159
|
+
var _this$player;
|
|
160
|
+
if (!this.player) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
for (var _len = arguments.length, res = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
164
|
+
res[_key - 1] = arguments[_key];
|
|
165
|
+
}
|
|
166
|
+
(_this$player = this.player).emit.apply(_this$player, [event].concat(res));
|
|
167
|
+
}
|
|
168
|
+
}, {
|
|
169
|
+
key: "emitUserAction",
|
|
170
|
+
value: function emitUserAction(event, action) {
|
|
171
|
+
var params = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
172
|
+
if (!this.player) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
var nParams = _objectSpread2(_objectSpread2({}, params), {}, {
|
|
176
|
+
pluginName: this.pluginName
|
|
177
|
+
});
|
|
178
|
+
this.player.emitUserAction(event, action, nParams);
|
|
179
|
+
}
|
|
180
|
+
}, {
|
|
181
|
+
key: "hook",
|
|
182
|
+
value: function hook$1(hookName, handler) {
|
|
183
|
+
return hook.call.apply(hook, [this].concat(Array.prototype.slice.call(arguments)));
|
|
184
|
+
}
|
|
185
|
+
}, {
|
|
186
|
+
key: "useHooks",
|
|
187
|
+
value: function useHooks$1(hookName, handler) {
|
|
188
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
189
|
+
args[_key2 - 2] = arguments[_key2];
|
|
190
|
+
}
|
|
191
|
+
return useHooks.call.apply(useHooks, [this].concat(Array.prototype.slice.call(arguments)));
|
|
192
|
+
}
|
|
193
|
+
}, {
|
|
194
|
+
key: "removeHooks",
|
|
195
|
+
value: function removeHooks$1(hookName, handler) {
|
|
196
|
+
for (var _len3 = arguments.length, args = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
197
|
+
args[_key3 - 2] = arguments[_key3];
|
|
198
|
+
}
|
|
199
|
+
return removeHooks.call.apply(removeHooks, [this].concat(Array.prototype.slice.call(arguments)));
|
|
200
|
+
}
|
|
201
|
+
}, {
|
|
202
|
+
key: "registerPlugin",
|
|
203
|
+
value: function registerPlugin(plugin) {
|
|
204
|
+
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
205
|
+
var name = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "";
|
|
206
|
+
if (!this.player) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
name && (options.pluginName = name);
|
|
210
|
+
return this.player.registerPlugin({
|
|
211
|
+
plugin,
|
|
212
|
+
options
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}, {
|
|
216
|
+
key: "getPlugin",
|
|
217
|
+
value: function getPlugin(name) {
|
|
218
|
+
return this.player ? this.player.getPlugin(name) : null;
|
|
219
|
+
}
|
|
220
|
+
}, {
|
|
221
|
+
key: "__destroy",
|
|
222
|
+
value: function __destroy() {
|
|
223
|
+
var _this5 = this;
|
|
224
|
+
var player = this.player;
|
|
225
|
+
var pluginName = this.pluginName;
|
|
226
|
+
this.offAll();
|
|
227
|
+
util.clearAllTimers(this);
|
|
228
|
+
if (util.checkIsFunction(this.destroy)) {
|
|
229
|
+
this.destroy();
|
|
230
|
+
}
|
|
231
|
+
["player", "playerConfig", "pluginName", "logger", "__args", "__hooks"].map(function(item) {
|
|
232
|
+
_this5[item] = null;
|
|
233
|
+
});
|
|
234
|
+
player.unRegisterPlugin(pluginName);
|
|
235
|
+
delHooksDescriptor(this);
|
|
236
|
+
}
|
|
237
|
+
}], [{
|
|
238
|
+
key: "defineGetterOrSetter",
|
|
239
|
+
value: function defineGetterOrSetter(Obj, map) {
|
|
240
|
+
for (var key in map) {
|
|
241
|
+
if (Object.prototype.hasOwnProperty.call(map, key)) {
|
|
242
|
+
Object.defineProperty(Obj, key, map[key]);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}, {
|
|
247
|
+
key: "defaultConfig",
|
|
248
|
+
get: function get() {
|
|
249
|
+
return {};
|
|
250
|
+
}
|
|
251
|
+
}, {
|
|
252
|
+
key: "pluginName",
|
|
253
|
+
get: function get() {
|
|
254
|
+
return "pluginName";
|
|
255
|
+
}
|
|
256
|
+
}]);
|
|
257
|
+
return BasePlugin2;
|
|
258
|
+
}();
|
|
259
|
+
export { BasePlugin as default };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hook decorator, add hooks props for for an instance
|
|
3
|
+
* @param { any } instance
|
|
4
|
+
* @param { Array<string> } [hookNames]
|
|
5
|
+
*/
|
|
6
|
+
declare function hooksDescriptor(instance: any, presetHooks?: any[]): void;
|
|
7
|
+
/**
|
|
8
|
+
* 给某个处理函数添加hook能力
|
|
9
|
+
* @param { string } hookName
|
|
10
|
+
* @param { Function } handler
|
|
11
|
+
* @param { { pre?: any, next?:any } } preset
|
|
12
|
+
* {
|
|
13
|
+
* pre: () => { // run beafore hook},
|
|
14
|
+
* next: () => { // run after hook return}
|
|
15
|
+
* }
|
|
16
|
+
*/
|
|
17
|
+
export function hook(hookName: string, handler: Function, preset?: {
|
|
18
|
+
pre?: any;
|
|
19
|
+
next?: any;
|
|
20
|
+
}): any;
|
|
21
|
+
export class hook {
|
|
22
|
+
/**
|
|
23
|
+
* 给某个处理函数添加hook能力
|
|
24
|
+
* @param { string } hookName
|
|
25
|
+
* @param { Function } handler
|
|
26
|
+
* @param { { pre?: any, next?:any } } preset
|
|
27
|
+
* {
|
|
28
|
+
* pre: () => { // run beafore hook},
|
|
29
|
+
* next: () => { // run after hook return}
|
|
30
|
+
* }
|
|
31
|
+
*/
|
|
32
|
+
constructor(hookName: string, handler: Function, preset?: {
|
|
33
|
+
pre?: any;
|
|
34
|
+
next?: any;
|
|
35
|
+
});
|
|
36
|
+
__hooks: {};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* add hooks
|
|
40
|
+
* @param { string } hookName
|
|
41
|
+
* @param { Function } handler
|
|
42
|
+
*/
|
|
43
|
+
export function useHooks(hookName: string, handler: Function): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Add hooks to a plugin
|
|
46
|
+
* @param { string } pluginName
|
|
47
|
+
* @param {...any} args
|
|
48
|
+
*/
|
|
49
|
+
export function usePluginHooks(pluginName: string, ...args: any[]): any;
|
|
50
|
+
export function removePluginHooks(pluginName: any, ...args: any[]): any;
|
|
51
|
+
/**
|
|
52
|
+
* remove hook
|
|
53
|
+
* @param { string } hookName
|
|
54
|
+
* @param { (plugin: any, ..args) => {} } handler
|
|
55
|
+
* @returns void
|
|
56
|
+
*/
|
|
57
|
+
export function removeHooks(hookName: string, handler: (plugin: any, args: any) => {}): void;
|
|
58
|
+
export function delHooksDescriptor(instance: any): void;
|
|
59
|
+
export function runHooks(obj: any, hookName: any, handler: any, ...args: any[]): any;
|
|
60
|
+
export { hooksDescriptor as default };
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { toConsumableArray as _toConsumableArray } from "../_virtual/_rollupPluginBabelHelpers.js";
|
|
2
|
+
function callHandler(obj, handler, next) {
|
|
3
|
+
for (var _len = arguments.length, args = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
|
|
4
|
+
args[_key - 3] = arguments[_key];
|
|
5
|
+
}
|
|
6
|
+
var ret = handler.call.apply(handler, [obj].concat(args));
|
|
7
|
+
if (!next || typeof next !== "function") {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (ret && ret.then) {
|
|
11
|
+
ret.then(function() {
|
|
12
|
+
for (var _len2 = arguments.length, args2 = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
13
|
+
args2[_key2] = arguments[_key2];
|
|
14
|
+
}
|
|
15
|
+
next.call.apply(next, [obj].concat(args2));
|
|
16
|
+
});
|
|
17
|
+
} else {
|
|
18
|
+
next.call.apply(next, [obj].concat(args));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function hook(hookName, handler) {
|
|
22
|
+
var preset = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {
|
|
23
|
+
pre: null,
|
|
24
|
+
next: null
|
|
25
|
+
};
|
|
26
|
+
if (!this.__hooks) {
|
|
27
|
+
this.__hooks = {};
|
|
28
|
+
}
|
|
29
|
+
!this.__hooks[hookName] && (this.__hooks[hookName] = null);
|
|
30
|
+
return function() {
|
|
31
|
+
var _arguments = arguments, _this = this;
|
|
32
|
+
if (preset.pre) {
|
|
33
|
+
try {
|
|
34
|
+
var _preset$pre;
|
|
35
|
+
(_preset$pre = preset.pre).call.apply(_preset$pre, [this].concat(Array.prototype.slice.call(arguments)));
|
|
36
|
+
} catch (e) {
|
|
37
|
+
e.message = "[pluginName: ".concat(this.pluginName, ":").concat(hookName, ":pre error] >> ").concat(e.message);
|
|
38
|
+
throw e;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (this.__hooks && this.__hooks[hookName]) {
|
|
42
|
+
try {
|
|
43
|
+
var _this$__hooks$hookNam;
|
|
44
|
+
var preRet = (_this$__hooks$hookNam = this.__hooks[hookName]).call.apply(_this$__hooks$hookNam, [this, this].concat(Array.prototype.slice.call(arguments)));
|
|
45
|
+
if (preRet) {
|
|
46
|
+
if (preRet.then) {
|
|
47
|
+
preRet.then(function(isContinue) {
|
|
48
|
+
if (isContinue !== false) {
|
|
49
|
+
callHandler.apply(void 0, [_this, handler, preset.next].concat(_toConsumableArray(_arguments)));
|
|
50
|
+
}
|
|
51
|
+
}).catch(function(e) {
|
|
52
|
+
throw e;
|
|
53
|
+
});
|
|
54
|
+
} else {
|
|
55
|
+
callHandler.apply(void 0, [this, handler, preset.next].concat(Array.prototype.slice.call(arguments)));
|
|
56
|
+
}
|
|
57
|
+
} else if (preRet === void 0) {
|
|
58
|
+
callHandler.apply(void 0, [this, handler, preset.next].concat(Array.prototype.slice.call(arguments)));
|
|
59
|
+
}
|
|
60
|
+
} catch (e) {
|
|
61
|
+
e.message = "[pluginName: ".concat(this.pluginName, ":").concat(hookName, "] >> ").concat(e.message);
|
|
62
|
+
throw e;
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
callHandler.apply(void 0, [this, handler, preset.next].concat(Array.prototype.slice.call(arguments)));
|
|
66
|
+
}
|
|
67
|
+
}.bind(this);
|
|
68
|
+
}
|
|
69
|
+
function useHooks(hookName, handler) {
|
|
70
|
+
var __hooks = this.__hooks;
|
|
71
|
+
if (!__hooks) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (!__hooks.hasOwnProperty(hookName)) {
|
|
75
|
+
console.warn("has no supported hook which name [".concat(hookName, "]"));
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
__hooks && (__hooks[hookName] = handler);
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
function removeHooks(hookName, handler) {
|
|
82
|
+
var __hooks = this.__hooks;
|
|
83
|
+
if (!__hooks) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
delete __hooks[hookName];
|
|
87
|
+
}
|
|
88
|
+
function usePluginHooks(pluginName) {
|
|
89
|
+
if (!this.plugins || !this.plugins[pluginName.toLowerCase()]) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
var plugin = this.plugins[pluginName.toLowerCase()];
|
|
93
|
+
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
94
|
+
args[_key3 - 1] = arguments[_key3];
|
|
95
|
+
}
|
|
96
|
+
return plugin.useHooks && plugin.useHooks.apply(plugin, args);
|
|
97
|
+
}
|
|
98
|
+
function removePluginHooks(pluginName) {
|
|
99
|
+
if (!this.plugins || !this.plugins[pluginName.toLowerCase()]) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
var plugin = this.plugins[pluginName.toLowerCase()];
|
|
103
|
+
if (plugin) {
|
|
104
|
+
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
105
|
+
args[_key4 - 1] = arguments[_key4];
|
|
106
|
+
}
|
|
107
|
+
return plugin.removeHooks && plugin.removeHooks.apply(plugin, args);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function hooksDescriptor(instance) {
|
|
111
|
+
var presetHooks = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
112
|
+
instance.__hooks = {};
|
|
113
|
+
presetHooks && presetHooks.map(function(item) {
|
|
114
|
+
instance.__hooks[item] = null;
|
|
115
|
+
});
|
|
116
|
+
Object.defineProperty(instance, "hooks", {
|
|
117
|
+
get: function get() {
|
|
118
|
+
return instance.__hooks && Object.keys(instance.__hooks).map(function(key) {
|
|
119
|
+
if (instance.__hooks[key]) {
|
|
120
|
+
return key;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function delHooksDescriptor(instance) {
|
|
127
|
+
instance.__hooks = null;
|
|
128
|
+
}
|
|
129
|
+
function runHooks(obj, hookName, handler) {
|
|
130
|
+
for (var _len5 = arguments.length, args = new Array(_len5 > 3 ? _len5 - 3 : 0), _key5 = 3; _key5 < _len5; _key5++) {
|
|
131
|
+
args[_key5 - 3] = arguments[_key5];
|
|
132
|
+
}
|
|
133
|
+
if (obj.__hooks && obj.__hooks[hookName]) {
|
|
134
|
+
var _obj$__hooks$hookName;
|
|
135
|
+
var ret = (_obj$__hooks$hookName = obj.__hooks[hookName]).call.apply(_obj$__hooks$hookName, [obj, obj].concat(args));
|
|
136
|
+
if (ret && ret.then) {
|
|
137
|
+
ret.then(function(data) {
|
|
138
|
+
return data === false ? null : handler.call.apply(handler, [obj, obj].concat(args));
|
|
139
|
+
}).catch(function(e) {
|
|
140
|
+
console.warn("[runHooks]".concat(hookName, " reject"), e.message);
|
|
141
|
+
});
|
|
142
|
+
} else if (ret !== false) {
|
|
143
|
+
return handler.call.apply(handler, [obj, obj].concat(args));
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
return handler.call.apply(handler, [obj, obj].concat(args));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
export { hooksDescriptor as default, delHooksDescriptor, hook, removeHooks, removePluginHooks, runHooks, useHooks, usePluginHooks };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import pluginsManager from "./pluginsManager";
|
|
2
|
+
import BasePlugin from "./basePlugin";
|
|
3
|
+
import hooksDescriptor from "./hooksDescriptor";
|
|
4
|
+
import STATE_CLASS from "../stateClassMap";
|
|
5
|
+
import { POSITIONS } from "./plugin";
|
|
6
|
+
import { ROOT_TYPES } from "./plugin";
|
|
7
|
+
import Sniffer from "../utils/sniffer";
|
|
8
|
+
import Errors from "../error";
|
|
9
|
+
import Util from "../utils/util";
|
|
10
|
+
import * as Events from "../events";
|
|
11
|
+
import { STATES } from "../state";
|
|
12
|
+
import Plugin from "./plugin";
|
|
13
|
+
export { pluginsManager, BasePlugin, hooksDescriptor, STATE_CLASS, POSITIONS, ROOT_TYPES, Sniffer, Errors, Util, Events, STATES, Plugin as default };
|