mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-26 17:01:20 -08:00
build all
Refactor utility functions for improved readability and consistency - Updated compatibility.js to use consistent line endings and formatting. - Refactored component.js for better readability and structure, including consistent use of arrow functions and binding. - Simplified dom.js functions with consistent formatting and improved readability. - Enhanced emitter.js with consistent formatting and arrow function usage. - Streamlined error.js for improved readability and consistency. - Refactored file.js to use consistent formatting and improved readability. - Improved format.js functions for better readability and consistency. - Updated index.js to maintain consistent export formatting. - Refactored property.js for improved readability and consistency. - Enhanced subtitle.js with consistent formatting and improved readability. - Refactored time.js for better readability and consistent formatting. fix: update lint script to target only source files for consistency Revert "fix: restore export statements for various plugins and update type definitions for better clarity" This reverts commit b5e969d81ec765cd8a34b06e6ef4f232ef25087f. fix: restore export statements for various plugins and update type definitions for better clarity Refactor type definitions to use interfaces instead of type aliases for better extensibility and clarity across i18n, icons, option, player, quality, setting, subtitle, template, and utils modules.
This commit is contained in:
1 parent
532dd67cfd
commit
35ad9883af
447 files changed
+18248
-17946
No files matched your search
+228
-226
@@ -1,258 +1,260 @@
|
||||
import { version } from '../package.json';
|
||||
import style from 'bundle-text:./style/index.less';
|
||||
import validator from 'option-validator';
|
||||
import Emitter from './utils/emitter';
|
||||
import * as utils from './utils';
|
||||
import scheme from './scheme';
|
||||
import config from './config';
|
||||
import Template from './template';
|
||||
import I18n from './i18n';
|
||||
import Player from './player';
|
||||
import Control from './control';
|
||||
import Contextmenu from './contextmenu';
|
||||
import Info from './info';
|
||||
import Subtitle from './subtitle';
|
||||
import Events from './events';
|
||||
import Hotkey from './hotkey';
|
||||
import Layer from './layer';
|
||||
import Loading from './loading';
|
||||
import Notice from './notice';
|
||||
import Mask from './mask';
|
||||
import Icons from './icons';
|
||||
import Setting from './setting';
|
||||
import Storage from './storage';
|
||||
import Plugins from './plugins';
|
||||
import style from 'bundle-text:./style/index.less'
|
||||
import validator from 'option-validator'
|
||||
import { version } from '../package.json'
|
||||
import config from './config'
|
||||
import Contextmenu from './contextmenu'
|
||||
import Control from './control'
|
||||
import Events from './events'
|
||||
import Hotkey from './hotkey'
|
||||
import I18n from './i18n'
|
||||
import Icons from './icons'
|
||||
import Info from './info'
|
||||
import Layer from './layer'
|
||||
import Loading from './loading'
|
||||
import Mask from './mask'
|
||||
import Notice from './notice'
|
||||
import Player from './player'
|
||||
import Plugins from './plugins'
|
||||
import scheme from './scheme'
|
||||
import Setting from './setting'
|
||||
import Storage from './storage'
|
||||
import Subtitle from './subtitle'
|
||||
import Template from './template'
|
||||
import * as utils from './utils'
|
||||
import Emitter from './utils/emitter'
|
||||
|
||||
let id = 0;
|
||||
const instances = [];
|
||||
let id = 0
|
||||
const instances = []
|
||||
export default class Artplayer extends Emitter {
|
||||
constructor(option, readyCallback) {
|
||||
super();
|
||||
constructor(option, readyCallback) {
|
||||
super()
|
||||
|
||||
this.id = ++id;
|
||||
this.id = ++id
|
||||
|
||||
const mergeOption = utils.mergeDeep(Artplayer.option, option);
|
||||
mergeOption.container = option.container;
|
||||
const mergeOption = utils.mergeDeep(Artplayer.option, option)
|
||||
mergeOption.container = option.container
|
||||
|
||||
this.option = validator(mergeOption, scheme);
|
||||
this.option = validator(mergeOption, scheme)
|
||||
|
||||
this.isLock = false;
|
||||
this.isReady = false;
|
||||
this.isFocus = false;
|
||||
this.isInput = false;
|
||||
this.isRotate = false;
|
||||
this.isDestroy = false;
|
||||
this.isLock = false
|
||||
this.isReady = false
|
||||
this.isFocus = false
|
||||
this.isInput = false
|
||||
this.isRotate = false
|
||||
this.isDestroy = false
|
||||
|
||||
this.template = new Template(this);
|
||||
this.events = new Events(this);
|
||||
this.storage = new Storage(this);
|
||||
this.icons = new Icons(this);
|
||||
this.i18n = new I18n(this);
|
||||
this.notice = new Notice(this);
|
||||
this.player = new Player(this);
|
||||
this.layers = new Layer(this);
|
||||
this.controls = new Control(this);
|
||||
this.contextmenu = new Contextmenu(this);
|
||||
this.subtitle = new Subtitle(this);
|
||||
this.info = new Info(this);
|
||||
this.loading = new Loading(this);
|
||||
this.hotkey = new Hotkey(this);
|
||||
this.mask = new Mask(this);
|
||||
this.setting = new Setting(this);
|
||||
this.plugins = new Plugins(this);
|
||||
this.template = new Template(this)
|
||||
this.events = new Events(this)
|
||||
this.storage = new Storage(this)
|
||||
this.icons = new Icons(this)
|
||||
this.i18n = new I18n(this)
|
||||
this.notice = new Notice(this)
|
||||
this.player = new Player(this)
|
||||
this.layers = new Layer(this)
|
||||
this.controls = new Control(this)
|
||||
this.contextmenu = new Contextmenu(this)
|
||||
this.subtitle = new Subtitle(this)
|
||||
this.info = new Info(this)
|
||||
this.loading = new Loading(this)
|
||||
this.hotkey = new Hotkey(this)
|
||||
this.mask = new Mask(this)
|
||||
this.setting = new Setting(this)
|
||||
this.plugins = new Plugins(this)
|
||||
|
||||
if (typeof readyCallback === 'function') {
|
||||
this.on('ready', () => readyCallback.call(this, this));
|
||||
}
|
||||
|
||||
if (Artplayer.DEBUG) {
|
||||
const log = (msg) => console.log(`[ART.${this.id}] -> ${msg}`);
|
||||
log('Version@' + Artplayer.version);
|
||||
for (let index = 0; index < config.events.length; index++) {
|
||||
this.on('video:' + config.events[index], (event) => log('Event@' + event.type));
|
||||
}
|
||||
}
|
||||
|
||||
instances.push(this);
|
||||
if (typeof readyCallback === 'function') {
|
||||
this.on('ready', () => readyCallback.call(this, this))
|
||||
}
|
||||
|
||||
static get instances() {
|
||||
return instances;
|
||||
if (Artplayer.DEBUG) {
|
||||
// eslint-disable-next-line no-console
|
||||
const log = msg => console.log(`[ART.${this.id}] -> ${msg}`)
|
||||
log(`Version@${Artplayer.version}`)
|
||||
for (let index = 0; index < config.events.length; index++) {
|
||||
this.on(`video:${config.events[index]}`, event => log(`Event@${event.type}`))
|
||||
}
|
||||
}
|
||||
|
||||
static get version() {
|
||||
return version;
|
||||
}
|
||||
instances.push(this)
|
||||
}
|
||||
|
||||
static get config() {
|
||||
return config;
|
||||
}
|
||||
static get instances() {
|
||||
return instances
|
||||
}
|
||||
|
||||
static get utils() {
|
||||
return utils;
|
||||
}
|
||||
static get version() {
|
||||
return version
|
||||
}
|
||||
|
||||
static get scheme() {
|
||||
return scheme;
|
||||
}
|
||||
static get config() {
|
||||
return config
|
||||
}
|
||||
|
||||
static get Emitter() {
|
||||
return Emitter;
|
||||
}
|
||||
static get utils() {
|
||||
return utils
|
||||
}
|
||||
|
||||
static get validator() {
|
||||
return validator;
|
||||
}
|
||||
static get scheme() {
|
||||
return scheme
|
||||
}
|
||||
|
||||
static get kindOf() {
|
||||
return validator.kindOf;
|
||||
}
|
||||
static get Emitter() {
|
||||
return Emitter
|
||||
}
|
||||
|
||||
static get html() {
|
||||
return Template.html;
|
||||
}
|
||||
static get validator() {
|
||||
return validator
|
||||
}
|
||||
|
||||
static get option() {
|
||||
return {
|
||||
id: '',
|
||||
container: '#artplayer',
|
||||
url: '',
|
||||
poster: '',
|
||||
type: '',
|
||||
theme: '#f00',
|
||||
volume: 0.7,
|
||||
isLive: false,
|
||||
muted: false,
|
||||
autoplay: false,
|
||||
autoSize: false,
|
||||
autoMini: false,
|
||||
loop: false,
|
||||
flip: false,
|
||||
playbackRate: false,
|
||||
aspectRatio: false,
|
||||
screenshot: false,
|
||||
setting: false,
|
||||
hotkey: true,
|
||||
pip: false,
|
||||
mutex: true,
|
||||
backdrop: true,
|
||||
fullscreen: false,
|
||||
fullscreenWeb: false,
|
||||
subtitleOffset: false,
|
||||
miniProgressBar: false,
|
||||
useSSR: false,
|
||||
playsInline: true,
|
||||
lock: false,
|
||||
gesture: true,
|
||||
fastForward: false,
|
||||
autoPlayback: false,
|
||||
autoOrientation: false,
|
||||
airplay: false,
|
||||
proxy: undefined,
|
||||
layers: [],
|
||||
contextmenu: [],
|
||||
controls: [],
|
||||
settings: [],
|
||||
quality: [],
|
||||
highlight: [],
|
||||
plugins: [],
|
||||
thumbnails: {
|
||||
url: '',
|
||||
number: 60,
|
||||
column: 10,
|
||||
width: 0,
|
||||
height: 0,
|
||||
scale: 1,
|
||||
},
|
||||
subtitle: {
|
||||
url: '',
|
||||
type: '',
|
||||
style: {},
|
||||
name: '',
|
||||
escape: true,
|
||||
encoding: 'utf-8',
|
||||
onVttLoad: (vtt) => vtt,
|
||||
},
|
||||
moreVideoAttr: {
|
||||
controls: false,
|
||||
preload: utils.isSafari ? 'auto' : 'metadata',
|
||||
},
|
||||
i18n: {},
|
||||
icons: {},
|
||||
cssVar: {},
|
||||
customType: {},
|
||||
lang: navigator?.language.toLowerCase(),
|
||||
};
|
||||
}
|
||||
static get kindOf() {
|
||||
return validator.kindOf
|
||||
}
|
||||
|
||||
get proxy() {
|
||||
return this.events.proxy;
|
||||
}
|
||||
static get html() {
|
||||
return Template.html
|
||||
}
|
||||
|
||||
get query() {
|
||||
return this.template.query;
|
||||
static get option() {
|
||||
return {
|
||||
id: '',
|
||||
container: '#artplayer',
|
||||
url: '',
|
||||
poster: '',
|
||||
type: '',
|
||||
theme: '#f00',
|
||||
volume: 0.7,
|
||||
isLive: false,
|
||||
muted: false,
|
||||
autoplay: false,
|
||||
autoSize: false,
|
||||
autoMini: false,
|
||||
loop: false,
|
||||
flip: false,
|
||||
playbackRate: false,
|
||||
aspectRatio: false,
|
||||
screenshot: false,
|
||||
setting: false,
|
||||
hotkey: true,
|
||||
pip: false,
|
||||
mutex: true,
|
||||
backdrop: true,
|
||||
fullscreen: false,
|
||||
fullscreenWeb: false,
|
||||
subtitleOffset: false,
|
||||
miniProgressBar: false,
|
||||
useSSR: false,
|
||||
playsInline: true,
|
||||
lock: false,
|
||||
gesture: true,
|
||||
fastForward: false,
|
||||
autoPlayback: false,
|
||||
autoOrientation: false,
|
||||
airplay: false,
|
||||
proxy: undefined,
|
||||
layers: [],
|
||||
contextmenu: [],
|
||||
controls: [],
|
||||
settings: [],
|
||||
quality: [],
|
||||
highlight: [],
|
||||
plugins: [],
|
||||
thumbnails: {
|
||||
url: '',
|
||||
number: 60,
|
||||
column: 10,
|
||||
width: 0,
|
||||
height: 0,
|
||||
scale: 1,
|
||||
},
|
||||
subtitle: {
|
||||
url: '',
|
||||
type: '',
|
||||
style: {},
|
||||
name: '',
|
||||
escape: true,
|
||||
encoding: 'utf-8',
|
||||
onVttLoad: vtt => vtt,
|
||||
},
|
||||
moreVideoAttr: {
|
||||
controls: false,
|
||||
preload: utils.isSafari ? 'auto' : 'metadata',
|
||||
},
|
||||
i18n: {},
|
||||
icons: {},
|
||||
cssVar: {},
|
||||
customType: {},
|
||||
lang: navigator?.language.toLowerCase(),
|
||||
}
|
||||
}
|
||||
|
||||
get video() {
|
||||
return this.template.$video;
|
||||
}
|
||||
get proxy() {
|
||||
return this.events.proxy
|
||||
}
|
||||
|
||||
destroy(removeHtml = true) {
|
||||
this.events.destroy();
|
||||
this.template.destroy(removeHtml);
|
||||
instances.splice(instances.indexOf(this), 1);
|
||||
this.isDestroy = true;
|
||||
this.emit('destroy');
|
||||
}
|
||||
get query() {
|
||||
return this.template.query
|
||||
}
|
||||
|
||||
get video() {
|
||||
return this.template.$video
|
||||
}
|
||||
|
||||
destroy(removeHtml = true) {
|
||||
this.events.destroy()
|
||||
this.template.destroy(removeHtml)
|
||||
instances.splice(instances.indexOf(this), 1)
|
||||
this.isDestroy = true
|
||||
this.emit('destroy')
|
||||
}
|
||||
}
|
||||
|
||||
Artplayer.STYLE = style;
|
||||
Artplayer.DEBUG = false;
|
||||
Artplayer.CONTEXTMENU = true;
|
||||
Artplayer.NOTICE_TIME = 2000;
|
||||
Artplayer.SETTING_WIDTH = 250;
|
||||
Artplayer.SETTING_ITEM_WIDTH = 200;
|
||||
Artplayer.SETTING_ITEM_HEIGHT = 35;
|
||||
Artplayer.RESIZE_TIME = 200;
|
||||
Artplayer.SCROLL_TIME = 200;
|
||||
Artplayer.SCROLL_GAP = 50;
|
||||
Artplayer.AUTO_PLAYBACK_MAX = 10;
|
||||
Artplayer.AUTO_PLAYBACK_MIN = 5;
|
||||
Artplayer.AUTO_PLAYBACK_TIMEOUT = 3000;
|
||||
Artplayer.RECONNECT_TIME_MAX = 5;
|
||||
Artplayer.RECONNECT_SLEEP_TIME = 1000;
|
||||
Artplayer.CONTROL_HIDE_TIME = 3000;
|
||||
Artplayer.DBCLICK_TIME = 300;
|
||||
Artplayer.DBCLICK_FULLSCREEN = true;
|
||||
Artplayer.MOBILE_DBCLICK_PLAY = true;
|
||||
Artplayer.MOBILE_CLICK_PLAY = false;
|
||||
Artplayer.AUTO_ORIENTATION_TIME = 200;
|
||||
Artplayer.INFO_LOOP_TIME = 1000;
|
||||
Artplayer.FAST_FORWARD_VALUE = 3;
|
||||
Artplayer.FAST_FORWARD_TIME = 1000;
|
||||
Artplayer.TOUCH_MOVE_RATIO = 0.5;
|
||||
Artplayer.VOLUME_STEP = 0.1;
|
||||
Artplayer.SEEK_STEP = 5;
|
||||
Artplayer.PLAYBACK_RATE = [0.5, 0.75, 1, 1.25, 1.5, 2];
|
||||
Artplayer.ASPECT_RATIO = ['default', '4:3', '16:9'];
|
||||
Artplayer.FLIP = ['normal', 'horizontal', 'vertical'];
|
||||
Artplayer.FULLSCREEN_WEB_IN_BODY = false;
|
||||
Artplayer.LOG_VERSION = true;
|
||||
Artplayer.USE_RAF = false;
|
||||
Artplayer.STYLE = style
|
||||
Artplayer.DEBUG = false
|
||||
Artplayer.CONTEXTMENU = true
|
||||
Artplayer.NOTICE_TIME = 2000
|
||||
Artplayer.SETTING_WIDTH = 250
|
||||
Artplayer.SETTING_ITEM_WIDTH = 200
|
||||
Artplayer.SETTING_ITEM_HEIGHT = 35
|
||||
Artplayer.RESIZE_TIME = 200
|
||||
Artplayer.SCROLL_TIME = 200
|
||||
Artplayer.SCROLL_GAP = 50
|
||||
Artplayer.AUTO_PLAYBACK_MAX = 10
|
||||
Artplayer.AUTO_PLAYBACK_MIN = 5
|
||||
Artplayer.AUTO_PLAYBACK_TIMEOUT = 3000
|
||||
Artplayer.RECONNECT_TIME_MAX = 5
|
||||
Artplayer.RECONNECT_SLEEP_TIME = 1000
|
||||
Artplayer.CONTROL_HIDE_TIME = 3000
|
||||
Artplayer.DBCLICK_TIME = 300
|
||||
Artplayer.DBCLICK_FULLSCREEN = true
|
||||
Artplayer.MOBILE_DBCLICK_PLAY = true
|
||||
Artplayer.MOBILE_CLICK_PLAY = false
|
||||
Artplayer.AUTO_ORIENTATION_TIME = 200
|
||||
Artplayer.INFO_LOOP_TIME = 1000
|
||||
Artplayer.FAST_FORWARD_VALUE = 3
|
||||
Artplayer.FAST_FORWARD_TIME = 1000
|
||||
Artplayer.TOUCH_MOVE_RATIO = 0.5
|
||||
Artplayer.VOLUME_STEP = 0.1
|
||||
Artplayer.SEEK_STEP = 5
|
||||
Artplayer.PLAYBACK_RATE = [0.5, 0.75, 1, 1.25, 1.5, 2]
|
||||
Artplayer.ASPECT_RATIO = ['default', '4:3', '16:9']
|
||||
Artplayer.FLIP = ['normal', 'horizontal', 'vertical']
|
||||
Artplayer.FULLSCREEN_WEB_IN_BODY = false
|
||||
Artplayer.LOG_VERSION = true
|
||||
Artplayer.USE_RAF = false
|
||||
|
||||
if (utils.isBrowser) {
|
||||
window['Artplayer'] = Artplayer;
|
||||
window.Artplayer = Artplayer
|
||||
|
||||
utils.setStyleText('artplayer-style', style);
|
||||
utils.setStyleText('artplayer-style', style)
|
||||
|
||||
setTimeout(() => {
|
||||
if (Artplayer.LOG_VERSION) {
|
||||
console.log(
|
||||
`%c ArtPlayer %c ${Artplayer.version} %c https://artplayer.org`,
|
||||
'color: #fff; background: #5f5f5f',
|
||||
'color: #fff; background: #4bc729',
|
||||
'',
|
||||
);
|
||||
}
|
||||
}, 100);
|
||||
setTimeout(() => {
|
||||
if (Artplayer.LOG_VERSION) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(
|
||||
`%c ArtPlayer %c ${Artplayer.version} %c https://artplayer.org`,
|
||||
'color: #fff; background: #5f5f5f',
|
||||
'color: #fff; background: #4bc729',
|
||||
'',
|
||||
)
|
||||
}
|
||||
}, 100)
|
||||
}
|
||||
Reference in new issue
Block a user