优化类型检测

This commit is contained in:
Harvey committed 2020-05-19 14:23:29 +08:00
1 parent 3e609bb153
commit 9760d6268f
6 files changed
+168 -342

No files matched your search

+1 -1
View File
@@ -132,8 +132,8 @@ export default class Artplayer extends Emitter {
networkMonitor: false,
layers: [],
contextmenu: [],
quality: [],
controls: [],
quality: [],
highlight: [],
plugins: [],
whitelist: [],
+22 -40
View File
@@ -7,6 +7,17 @@ function validElement(value, type, paths) {
);
}
const component = {
html: validElement,
disable: 'boolean|undefined',
name: 'string|undefined',
index: 'number|undefined',
style: 'object|undefined',
click: 'function|undefined',
mounted: 'function|undefined',
tooltip: 'string|undefined',
};
export default {
container: validElement,
url: 'string',
@@ -40,28 +51,18 @@ export default {
networkMonitor: 'boolean',
plugins: ['function'],
whitelist: ['string|function|regexp'],
layers: [
layers: [component],
contextmenu: [component],
controls: [
{
disable: 'boolean|undefined',
name: 'string|undefined',
index: 'number|undefined',
html: validElement,
style: 'object|undefined',
click: 'function|undefined',
mounted: 'function|undefined',
tooltip: 'string|undefined',
},
],
contextmenu: [
{
disable: 'boolean|undefined',
name: 'string|undefined',
index: 'number|undefined',
html: validElement,
style: 'object|undefined',
click: 'function|undefined',
mounted: 'function|undefined',
tooltip: 'string|undefined',
...component,
position: (value, type, paths) => {
const position = ['top', 'left', 'right'];
return errorHandle(
position.includes(value),
`${paths.join('.')} only accept ${position.toString()} as parameters, but got ${type}`,
);
},
},
],
quality: [
@@ -71,25 +72,6 @@ export default {
url: 'string',
},
],
controls: [
{
disable: 'boolean|undefined',
name: 'string|undefined',
index: 'number|undefined',
html: validElement,
style: 'object|undefined',
click: 'function|undefined',
mounted: 'function|undefined',
tooltip: 'string|undefined',
position: (value, type, paths) => {
const position = ['top', 'left', 'right'];
return errorHandle(
position.includes(value),
`${paths.join('.')} only accept ${position.toString()} as parameters`,
);
},
},
],
highlight: [
{
time: 'number',
+8 -3
View File
@@ -1,7 +1,12 @@
{
"include": ["types"],
"include": [
"types/*"
],
"compilerOptions": {
"lib": ["es2015"],
"lib": [
"es2018",
"dom"
],
"strict": true
}
}
}
+27 -176
View File
@@ -1,193 +1,60 @@
type Component = {
html: string | HTMLElement;
disable?: boolean;
name?: string;
index?: number;
style?: object;
click?: Function;
mounted?: Function;
tooltip?: string;
};
export default class Artplayer {
constructor(option: {
/**
* Selector or a dom element (required)
*/
container: string;
/**
* Video url or a function that returns a promise value of url (required)
*/
container: string | HTMLElement;
url: string;
/**
* Video cover url
*/
poster?: string;
/**
* Video title
*/
title?: string;
/**
* Theme color like: #fff
*/
theme?: string;
/**
* Display language
*/
lang?: 'en' | 'zh-cn' | 'zh-tw';
/**
* Initialize volume 0 ~ 1, will be overwritten by cached values
*/
lang?: string;
volume?: number;
/**
* Whether to live by default
*/
isLive?: boolean;
/**
* Whether to mute by default
*/
muted?: boolean;
/**
* Whether to autoplay by default
*/
autoplay?: boolean;
/**
* Whether to automatically adapt to the size of the container
*/
autoSize?: boolean;
/**
* When the player scrolls out of the viewport, the mini player mode is automatically enabled
*/
autoMin?: boolean;
/**
* Whether to loop
*/
loop?: boolean;
/**
* Whether to display flip button
*/
flip?: boolean;
/**
* Whether to display playbackRate button
*/
playbackRate?: boolean;
/**
* Whether to display aspectRatio option
*/
aspectRatio?: boolean;
/**
* Whether to display screenshot button
*/
screenshot?: boolean;
/**
* Whether to display setting button
*/
setting?: boolean;
/**
* Whether to use hotkey
*/
hotkey?: boolean;
/**
* Whether to display pip button
*/
pip?: boolean;
/**
* Whether to play mutually exclusive when multiple players
*/
mutex?: boolean;
/**
* Whether to display the light mode in the context menu
*/
light?: boolean;
/**
* Whether to use blurred background in the context menu and settings panel
*/
backdrop?: boolean;
/**
* Whether to display fullscreen button
*/
fullscreen?: boolean;
/**
* Whether to display web fullscreen button
*/
fullscreenWeb?: boolean;
/**
* Subtitle time offset plugin
*/
subtitleOffset?: boolean;
/**
* Mini progress bar plugin
*/
miniProgressBar?: boolean;
/**
* Local video preview plugin. By default, a configuration is added in the settings panel.
*/
localVideo?: boolean;
/**
* Local subtitle preview plugin. By default, a configuration is added in the settings panel.
*/
localSubtitle?: boolean;
/**
* A network monitor is used to monitor the blocking of the video.
*/
networkMonitor?: boolean;
/**
* Initialize the custom plugins
*/
plugins?: Function[];
/**
* Initialize the custom whitelist
*/
whitelist?: [string, Function, RegExp];
/**
* Initialize the custom layer
*/
layers?: object[];
/**
* Initialize the custom contextmenu
*/
contextmenu?: object[];
/**
* Initialize the custom quality
*/
quality?: object[];
/**
* Initialize the custom controls
*/
controls?: object[];
/**
* Initialize the custom highlight
*/
highlight?: object[];
/**
* Thumbnails option
*/
whitelist?: (string | Function | RegExp)[];
layers?: Component[];
contextmenu?: Component[];
controls?: Component[];
quality?: {
default?: boolean;
name: string;
url: string;
}[];
highlight?: {
time: number;
text: string;
}[];
thumbnails?: {
url: string;
number?: number;
@@ -195,30 +62,14 @@ export default class Artplayer {
height?: number;
column?: number;
};
/**
* Subtitle option
*/
subtitle?: {
url: string;
style: object;
};
/**
* More video attributes
*/
moreVideoAttr?: object;
/**
* Custom icon
*/
icons?: {
[propName: string]: string;
[propName: string]: string | HTMLElement;
};
/**
* Custom video type
*/
customType?: {
[propName: string]: Function;
};