chore: update workflow

This commit is contained in:
DIYgod
2019-09-24 01:34:03 +08:00
parent 4ddc860317
commit cb95daa97d
16 changed files with 1394 additions and 805 deletions
+2
View File
@@ -0,0 +1,2 @@
dist
demo
+12 -17
View File
@@ -1,15 +1,17 @@
{ {
"extends": "eslint:recommended", "extends": ["eslint:recommended", "plugin:prettier/recommended"],
"plugins": ["prettier"],
"parserOptions": { "parserOptions": {
"ecmaVersion": 10, "ecmaVersion": 2018,
"sourceType": "module" "sourceType": "module"
}, },
"env": { "env": {
"browser": true "es6": true,
"browser": true,
"node": true,
}, },
"rules": { "rules": {
"no-console": 0, "no-console": 0,
"no-extra-parens": 1,
"block-scoped-var": 1, "block-scoped-var": 1,
"curly": 1, "curly": 1,
"eqeqeq": 1, "eqeqeq": 1,
@@ -20,7 +22,6 @@
"comma-spacing": 1, "comma-spacing": 1,
"comma-style": 1, "comma-style": 1,
"func-call-spacing": 1, "func-call-spacing": 1,
"indent": 1,
"keyword-spacing": 1, "keyword-spacing": 1,
"linebreak-style": 1, "linebreak-style": 1,
"lines-around-comment": 1, "lines-around-comment": 1,
@@ -31,14 +32,12 @@
"prefer-const": 1, "prefer-const": 1,
"no-unsafe-negation": 1, "no-unsafe-negation": 1,
"array-callback-return": 1, "array-callback-return": 1,
"dot-location": 1,
"dot-notation": 1, "dot-notation": 1,
"no-eval": 1, "no-eval": 1,
"no-extend-native": 1, "no-extend-native": 1,
"no-extra-label": 1, "no-extra-label": 1,
"semi": 1, "semi": 1,
"space-before-blocks": 1, "space-before-blocks": 1,
"space-before-function-paren": 1,
"space-in-parens": 1, "space-in-parens": 1,
"space-unary-ops": 1, "space-unary-ops": 1,
"spaced-comment": 1, "spaced-comment": 1,
@@ -50,14 +49,10 @@
"no-useless-rename": 1, "no-useless-rename": 1,
"rest-spread-spacing": 1, "rest-spread-spacing": 1,
"no-trailing-spaces": 1, "no-trailing-spaces": 1,
"quotes": [1, "single"] "no-control-regex": 0,
}, "prettier/prettier": 0,
"globals": { "no-await-in-loop": 1,
"require": false, "require-atomic-updates": 0,
"module": false, "no-prototype-builtins": 0
"Hls": false,
"flvjs": false,
"dashjs": false,
"WebTorrent": false
} }
} }
+2
View File
@@ -0,0 +1,2 @@
dist
demo
+7
View File
@@ -0,0 +1,7 @@
{
"printWidth": 233,
"tabWidth": 4,
"singleQuote": true,
"trailingComma": "es5",
"arrowParens": "always"
}
-4
View File
File diff suppressed because one or more lines are too long
-1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+80 -69
View File
@@ -1,71 +1,82 @@
{ {
"name": "dplayer", "name": "dplayer",
"version": "1.25.0", "version": "1.25.0",
"description": "Wow, such a lovely HTML5 danmaku video player", "description": "Wow, such a lovely HTML5 danmaku video player",
"main": "dist/DPlayer.min.js", "main": "dist/DPlayer.min.js",
"style": "dist/DPlayer.min.css", "scripts": {
"scripts": { "start": "npm run dev",
"start": "npm run dev", "build": "cross-env NODE_ENV=production webpack --config webpack/prod.config.js --progress --display-error-details --colors",
"build": "cross-env NODE_ENV=production webpack --config webpack/prod.config.js --progress --display-error-details --colors", "dev": "cross-env NODE_ENV=development webpack-dev-server --config webpack/dev.config.js --watch --colors",
"dev": "cross-env NODE_ENV=development webpack-dev-server --config webpack/dev.config.js --watch --colors", "test": "eslint src webpack",
"test": "eslint src webpack", "format": "eslint \"**/*.js\" --fix && prettier \"**/*.{js,json,md}\" --write",
"docs:dev": "vuepress dev docs", "format:staged": "eslint \"**/*.js\" --fix && pretty-quick --staged --verbose --pattern \"**/*.{js,json,md}\"",
"docs:build": "vuepress build docs" "format:check": "eslint \"**/*.js\" && prettier-check \"**/*.{js,json,md}\"",
}, "docs:dev": "vuepress dev docs",
"files": [ "docs:build": "vuepress build docs"
"dist" },
], "files": [
"repository": { "dist"
"url": "git+https://github.com/DIYgod/DPlayer.git", ],
"type": "git" "repository": {
}, "url": "git+https://github.com/DIYgod/DPlayer.git",
"keywords": [ "type": "git"
"player", },
"danmaku", "keywords": [
"video", "player",
"html5" "danmaku",
], "video",
"author": "DIYgod", "html5"
"license": "MIT", ],
"bugs": { "gitHooks": {
"url": "https://github.com/DIYgod/DPlayer/issues" "pre-commit": "npm run format:staged"
}, },
"homepage": "https://github.com/DIYgod/DPlayer#readme", "author": "DIYgod",
"devDependencies": { "license": "MIT",
"@babel/core": "^7.4.5", "bugs": {
"@babel/preset-env": "^7.4.5", "url": "https://github.com/DIYgod/DPlayer/issues"
"@vuepress/plugin-back-to-top": "1.0.1", },
"@vuepress/plugin-google-analytics": "1.0.1", "homepage": "https://github.com/DIYgod/DPlayer#readme",
"@vuepress/plugin-pwa": "1.0.1", "devDependencies": {
"art-template": "4.13.2", "@babel/core": "^7.6.0",
"art-template-loader": "1.4.3", "@babel/preset-env": "^7.4.5",
"autoprefixer": "^9.6.0", "@vuepress/plugin-back-to-top": "1.1.0",
"babel-loader": "^8.0.6", "@vuepress/plugin-google-analytics": "1.1.0",
"cross-env": "^5.2.0", "@vuepress/plugin-pwa": "1.1.0",
"css-loader": "^2.1.1", "art-template": "4.13.2",
"cssnano": "^4.1.10", "art-template-loader": "1.4.3",
"eslint": "^5.16.0", "autoprefixer": "^9.6.1",
"eslint-loader": "^2.1.2", "babel-loader": "^8.0.6",
"exports-loader": "^0.7.0", "cross-env": "^6.0.0",
"file-loader": "^4.0.0", "css-loader": "^3.2.0",
"git-revision-webpack-plugin": "^3.0.3", "cssnano": "^4.1.10",
"mini-css-extract-plugin": "0.7.0", "eslint": "^6.4.0",
"node-sass": "^4.12.0", "eslint-config-prettier": "^6.3.0",
"postcss-loader": "^3.0.0", "eslint-loader": "^3.0.0",
"sass-loader": "^7.1.0", "eslint-plugin-prettier": "^3.1.1",
"strip-loader": "^0.1.2", "exports-loader": "^0.7.0",
"style-loader": "^1.0.0", "file-loader": "^4.0.0",
"svg-inline-loader": "0.8.0", "git-revision-webpack-plugin": "^3.0.3",
"template-string-optimize-loader": "^3.0.0", "mini-css-extract-plugin": "0.8.0",
"url-loader": "^2.0.0", "node-sass": "^4.12.0",
"vuepress": "1.0.1", "postcss-loader": "^3.0.0",
"webpack": "^4.33.0", "prettier": "^1.18.2",
"webpack-cli": "3.3.2", "prettier-check": "^2.0.0",
"webpack-dev-server": "^3.6.0" "pretty-quick": "^1.11.1",
}, "sass-loader": "^8.0.0",
"dependencies": { "strip-loader": "^0.1.2",
"axios": "0.19.0", "style-loader": "^1.0.0",
"balloon-css": "^0.5.0", "svg-inline-loader": "0.8.0",
"promise-polyfill": "8.1.0" "template-string-optimize-loader": "^3.0.0",
} "url-loader": "^2.1.0",
"vuepress": "1.1.0",
"webpack": "^4.40.2",
"webpack-cli": "3.3.9",
"webpack-dev-server": "^3.8.1",
"yorkie": "^2.0.0"
},
"dependencies": {
"axios": "0.19.0",
"balloon-css": "^1.0.3",
"promise-polyfill": "8.1.3"
}
} }
+5 -6
View File
@@ -2,7 +2,6 @@
import defaultApiBackend from './api.js'; import defaultApiBackend from './api.js';
export default (options) => { export default (options) => {
// default options // default options
const defaultOption = { const defaultOption = {
container: options.element || document.getElementsByClassName('dplayer')[0], container: options.element || document.getElementsByClassName('dplayer')[0],
@@ -19,7 +18,7 @@ export default (options) => {
video: {}, video: {},
contextmenu: [], contextmenu: [],
mutex: true, mutex: true,
pluginOptions:{hls:{},flvjs:{},dash:{},webtorrent:{}} pluginOptions: { hls: {}, flvjs: {}, dash: {}, webtorrent: {} },
}; };
for (const defaultKey in defaultOption) { for (const defaultKey in defaultOption) {
if (defaultOption.hasOwnProperty(defaultKey) && !options.hasOwnProperty(defaultKey)) { if (defaultOption.hasOwnProperty(defaultKey) && !options.hasOwnProperty(defaultKey)) {
@@ -52,16 +51,16 @@ export default (options) => {
text: 'Video info', text: 'Video info',
click: (player) => { click: (player) => {
player.infoPanel.triggle(); player.infoPanel.triggle();
} },
}, },
{ {
text: 'About author', text: 'About author',
link: 'https://diygod.me' link: 'https://diygod.me',
}, },
{ {
text: `DPlayer v${DPLAYER_VERSION}`, text: `DPlayer v${DPLAYER_VERSION}`,
link: 'https://github.com/MoePlayer/DPlayer' link: 'https://github.com/MoePlayer/DPlayer',
} },
]); ]);
return options; return options;
+144 -151
View File
@@ -25,15 +25,14 @@ let index = 0;
const instances = []; const instances = [];
class DPlayer { class DPlayer {
/** /**
* DPlayer constructor function * DPlayer constructor function
* *
* @param {Object} options - See README * @param {Object} options - See README
* @constructor * @constructor
*/ */
constructor (options) { constructor(options) {
this.options = handleOption({preload:options.video.type === 'webtorrent' ? 'none' : 'metadata', ...options}); this.options = handleOption({ preload: options.video.type === 'webtorrent' ? 'none' : 'metadata', ...options });
if (this.options.video.quality) { if (this.options.video.quality) {
this.qualityIndex = this.options.video.defaultQuality; this.qualityIndex = this.options.video.defaultQuality;
@@ -116,12 +115,20 @@ class DPlayer {
this.setting = new Setting(this); this.setting = new Setting(this);
this.plugins = {}; this.plugins = {};
document.addEventListener('click', () => { document.addEventListener(
this.focus = false; 'click',
}, true); () => {
this.container.addEventListener('click', () => { this.focus = false;
this.focus = true; },
}, true); true
);
this.container.addEventListener(
'click',
() => {
this.focus = true;
},
true
);
this.paused = true; this.paused = true;
@@ -131,7 +138,7 @@ class DPlayer {
this.contextmenu = new ContextMenu(this); this.contextmenu = new ContextMenu(this);
this.initVideo(this.video, this.quality && this.quality.type || this.options.video.type); this.initVideo(this.video, (this.quality && this.quality.type) || this.options.video.type);
this.infoPanel = new InfoPanel(this); this.infoPanel = new InfoPanel(this);
@@ -144,17 +151,16 @@ class DPlayer {
} }
/** /**
* Seek video * Seek video
*/ */
seek (time) { seek(time) {
time = Math.max(time, 0); time = Math.max(time, 0);
if (this.video.duration) { if (this.video.duration) {
time = Math.min(time, this.video.duration); time = Math.min(time, this.video.duration);
} }
if (this.video.currentTime < time) { if (this.video.currentTime < time) {
this.notice(`${this.tran('FF')} ${(time - this.video.currentTime).toFixed(0)} ${this.tran('s')}`); this.notice(`${this.tran('FF')} ${(time - this.video.currentTime).toFixed(0)} ${this.tran('s')}`);
} } else if (this.video.currentTime > time) {
else if (this.video.currentTime > time) {
this.notice(`${this.tran('REW')} ${(this.video.currentTime - time).toFixed(0)} ${this.tran('s')}`); this.notice(`${this.tran('REW')} ${(this.video.currentTime - time).toFixed(0)} ${this.tran('s')}`);
} }
@@ -171,7 +177,7 @@ class DPlayer {
/** /**
* Play video * Play video
*/ */
play () { play() {
this.paused = false; this.paused = false;
if (this.video.paused) { if (this.video.paused) {
this.bezel.switch(Icons.play); this.bezel.switch(Icons.play);
@@ -180,10 +186,11 @@ class DPlayer {
this.template.playButton.innerHTML = Icons.pause; this.template.playButton.innerHTML = Icons.pause;
const playedPromise = Promise.resolve(this.video.play()); const playedPromise = Promise.resolve(this.video.play());
playedPromise.catch(() => { playedPromise
this.pause(); .catch(() => {
}).then(() => { this.pause();
}); })
.then(() => {});
this.timer.enable('loading'); this.timer.enable('loading');
this.container.classList.remove('dplayer-paused'); this.container.classList.remove('dplayer-paused');
this.container.classList.add('dplayer-playing'); this.container.classList.add('dplayer-playing');
@@ -202,7 +209,7 @@ class DPlayer {
/** /**
* Pause video * Pause video
*/ */
pause () { pause() {
this.paused = true; this.paused = true;
this.container.classList.remove('dplayer-loading'); this.container.classList.remove('dplayer-loading');
@@ -220,14 +227,12 @@ class DPlayer {
} }
} }
switchVolumeIcon () { switchVolumeIcon() {
if (this.volume() >= 0.95) { if (this.volume() >= 0.95) {
this.template.volumeIcon.innerHTML = Icons.volumeUp; this.template.volumeIcon.innerHTML = Icons.volumeUp;
} } else if (this.volume() > 0) {
else if (this.volume() > 0) {
this.template.volumeIcon.innerHTML = Icons.volumeDown; this.template.volumeIcon.innerHTML = Icons.volumeDown;
} } else {
else {
this.template.volumeIcon.innerHTML = Icons.volumeOff; this.template.volumeIcon.innerHTML = Icons.volumeOff;
} }
} }
@@ -235,7 +240,7 @@ class DPlayer {
/** /**
* Set volume * Set volume
*/ */
volume (percentage, nostorage, nonotice) { volume(percentage, nostorage, nonotice) {
percentage = parseFloat(percentage); percentage = parseFloat(percentage);
if (!isNaN(percentage)) { if (!isNaN(percentage)) {
percentage = Math.max(percentage, 0); percentage = Math.max(percentage, 0);
@@ -263,11 +268,10 @@ class DPlayer {
/** /**
* Toggle between play and pause * Toggle between play and pause
*/ */
toggle () { toggle() {
if (this.video.paused) { if (this.video.paused) {
this.play(); this.play();
} } else {
else {
this.pause(); this.pause();
} }
} }
@@ -275,7 +279,7 @@ class DPlayer {
/** /**
* attach event * attach event
*/ */
on (name, callback) { on(name, callback) {
this.events.on(name, callback); this.events.on(name, callback);
} }
@@ -285,7 +289,7 @@ class DPlayer {
* @param {Object} video - new video info * @param {Object} video - new video info
* @param {Object} danmaku - new danmaku info * @param {Object} danmaku - new danmaku info
*/ */
switchVideo (video, danmakuAPI) { switchVideo(video, danmakuAPI) {
this.pause(); this.pause();
this.video.poster = video.pic ? video.pic : ''; this.video.poster = video.pic ? video.pic : '';
this.video.src = video.url; this.video.src = video.url;
@@ -309,28 +313,23 @@ class DPlayer {
} }
} }
initMSE (video, type) { initMSE(video, type) {
this.type = type; this.type = type;
if (this.options.video.customType && this.options.video.customType[type]) { if (this.options.video.customType && this.options.video.customType[type]) {
if (Object.prototype.toString.call(this.options.video.customType[type]) === '[object Function]') { if (Object.prototype.toString.call(this.options.video.customType[type]) === '[object Function]') {
this.options.video.customType[type](this.video, this); this.options.video.customType[type](this.video, this);
} } else {
else {
console.error(`Illegal customType: ${type}`); console.error(`Illegal customType: ${type}`);
} }
} } else {
else {
if (this.type === 'auto') { if (this.type === 'auto') {
if (/m3u8(#|\?|$)/i.exec(video.src)) { if (/m3u8(#|\?|$)/i.exec(video.src)) {
this.type = 'hls'; this.type = 'hls';
} } else if (/.flv(#|\?|$)/i.exec(video.src)) {
else if (/.flv(#|\?|$)/i.exec(video.src)) {
this.type = 'flv'; this.type = 'flv';
} } else if (/.mpd(#|\?|$)/i.exec(video.src)) {
else if (/.mpd(#|\?|$)/i.exec(video.src)) {
this.type = 'dash'; this.type = 'dash';
} } else {
else {
this.type = 'normal'; this.type = 'normal';
} }
} }
@@ -340,111 +339,107 @@ class DPlayer {
} }
switch (this.type) { switch (this.type) {
// https://github.com/video-dev/hls.js // https://github.com/video-dev/hls.js
case 'hls': case 'hls':
if (Hls) { if (window.Hls) {
if (Hls.isSupported()) { if (window.Hls.isSupported()) {
const options = this.options.pluginOptions.hls; const options = this.options.pluginOptions.hls;
const hls = new Hls(options); const hls = new window.Hls(options);
this.plugins.hls = hls; this.plugins.hls = hls;
hls.loadSource(video.src); hls.loadSource(video.src);
hls.attachMedia(video); hls.attachMedia(video);
this.events.on('destroy', () => { this.events.on('destroy', () => {
hls.destroy(); hls.destroy();
delete this.plugins.hls; delete this.plugins.hls;
});
}
else {
this.notice('Error: Hls is not supported.');
}
}
else {
this.notice('Error: Can\'t find Hls.');
}
break;
// https://github.com/Bilibili/flv.js
case 'flv':
if (flvjs) {
if (flvjs.isSupported()) {
const options = Object.assign(this.options.pluginOptions.flvjs,{
type: 'flv',
url: video.src
});
const flvPlayer = flvjs.createPlayer(options);
this.plugins.flvjs = flvPlayer;
flvPlayer.attachMediaElement(video);
flvPlayer.load();
this.events.on('destroy', () => {
flvPlayer.unload();
flvPlayer.detachMediaElement();
flvPlayer.destroy();
delete this.plugins.flvjs;
});
}
else {
this.notice('Error: flvjs is not supported.');
}
}
else {
this.notice('Error: Can\'t find flvjs.');
}
break;
// https://github.com/Dash-Industry-Forum/dash.js
case 'dash':
if (dashjs) {
const dashjsPlayer = dashjs.MediaPlayer().create().initialize(video, video.src, false);
const options = this.options.pluginOptions.dash;
dashjsPlayer.updateSettings(options);
this.plugins.dash = dashjsPlayer;
this.events.on('destroy', () => {
dashjs.MediaPlayer().reset();
delete this.plugins.dash;
});
}
else {
this.notice('Error: Can\'t find dashjs.');
}
break;
// https://github.com/webtorrent/webtorrent
case 'webtorrent':
if (WebTorrent) {
if (WebTorrent.WEBRTC_SUPPORT) {
this.container.classList.add('dplayer-loading');
const options = this.options.pluginOptions.webtorrent;
const client = new WebTorrent(options);
this.plugins.webtorrent = client;
const torrentId = video.src;
video.src = '';
video.preload = 'metadata';
video.addEventListener('durationchange', () => this.container.classList.remove('dplayer-loading'), {once: true});
client.add(torrentId, (torrent) => {
const file = torrent.files.find((file) => file.name.endsWith('.mp4'));
file.renderTo(this.video, {
autoplay: this.options.autoplay
}); });
}); } else {
this.notice('Error: Hls is not supported.');
}
} else {
this.notice("Error: Can't find Hls.");
}
break;
// https://github.com/Bilibili/flv.js
case 'flv':
if (window.flvjs) {
if (window.flvjs.isSupported()) {
const options = Object.assign(this.options.pluginOptions.flvjs, {
type: 'flv',
url: video.src,
});
const flvPlayer = window.flvjs.createPlayer(options);
this.plugins.flvjs = flvPlayer;
flvPlayer.attachMediaElement(video);
flvPlayer.load();
this.events.on('destroy', () => {
flvPlayer.unload();
flvPlayer.detachMediaElement();
flvPlayer.destroy();
delete this.plugins.flvjs;
});
} else {
this.notice('Error: flvjs is not supported.');
}
} else {
this.notice("Error: Can't find flvjs.");
}
break;
// https://github.com/Dash-Industry-Forum/dash.js
case 'dash':
if (window.dashjs) {
const dashjsPlayer = window.dashjs
.MediaPlayer()
.create()
.initialize(video, video.src, false);
const options = this.options.pluginOptions.dash;
dashjsPlayer.updateSettings(options);
this.plugins.dash = dashjsPlayer;
this.events.on('destroy', () => { this.events.on('destroy', () => {
client.remove(torrentId); window.dashjs.MediaPlayer().reset();
client.destroy(); delete this.plugins.dash;
delete this.plugins.webtorrent;
}); });
} else {
this.notice("Error: Can't find dashjs.");
} }
else { break;
this.notice('Error: Webtorrent is not supported.');
// https://github.com/webtorrent/webtorrent
case 'webtorrent':
if (window.WebTorrent) {
if (window.WebTorrent.WEBRTC_SUPPORT) {
this.container.classList.add('dplayer-loading');
const options = this.options.pluginOptions.webtorrent;
const client = new window.WebTorrent(options);
this.plugins.webtorrent = client;
const torrentId = video.src;
video.src = '';
video.preload = 'metadata';
video.addEventListener('durationchange', () => this.container.classList.remove('dplayer-loading'), { once: true });
client.add(torrentId, (torrent) => {
const file = torrent.files.find((file) => file.name.endsWith('.mp4'));
file.renderTo(this.video, {
autoplay: this.options.autoplay,
});
});
this.events.on('destroy', () => {
client.remove(torrentId);
client.destroy();
delete this.plugins.webtorrent;
});
} else {
this.notice('Error: Webtorrent is not supported.');
}
} else {
this.notice("Error: Can't find Webtorrent.");
} }
} break;
else {
this.notice('Error: Can\'t find Webtorrent.');
}
break;
} }
} }
} }
initVideo (video, type) { initVideo(video, type) {
this.initMSE(video, type); this.initMSE(video, type);
/** /**
@@ -478,8 +473,7 @@ class DPlayer {
this.bar.set('played', 1, 'width'); this.bar.set('played', 1, 'width');
if (!this.setting.loop) { if (!this.setting.loop) {
this.pause(); this.pause();
} } else {
else {
this.seek(0); this.seek(0);
this.play(); this.play();
} }
@@ -524,12 +518,11 @@ class DPlayer {
} }
} }
switchQuality (index) { switchQuality(index) {
index = typeof index === 'string' ? parseInt(index) : index; index = typeof index === 'string' ? parseInt(index) : index;
if (this.qualityIndex === index || this.switchingQuality) { if (this.qualityIndex === index || this.switchingQuality) {
return; return;
} } else {
else {
this.qualityIndex = index; this.qualityIndex = index;
} }
this.switchingQuality = true; this.switchingQuality = true;
@@ -544,7 +537,7 @@ class DPlayer {
screenshot: this.options.screenshot, screenshot: this.options.screenshot,
preload: 'auto', preload: 'auto',
url: this.quality.url, url: this.quality.url,
subtitle: this.options.subtitle subtitle: this.options.subtitle,
}); });
const videoEle = new DOMParser().parseFromString(videoHTML, 'text/html').body.firstChild; const videoEle = new DOMParser().parseFromString(videoHTML, 'text/html').body.firstChild;
this.template.videoWrap.insertBefore(videoEle, this.template.videoWrap.getElementsByTagName('div')[0]); this.template.videoWrap.insertBefore(videoEle, this.template.videoWrap.getElementsByTagName('div')[0]);
@@ -575,7 +568,7 @@ class DPlayer {
}); });
} }
notice (text, time = 2000, opacity = 0.8) { notice(text, time = 2000, opacity = 0.8) {
this.template.notice.innerHTML = text; this.template.notice.innerHTML = text;
this.template.notice.style.opacity = opacity; this.template.notice.style.opacity = opacity;
if (this.noticeTime) { if (this.noticeTime) {
@@ -590,21 +583,21 @@ class DPlayer {
} }
} }
resize () { resize() {
if (this.danmaku) { if (this.danmaku) {
this.danmaku.resize(); this.danmaku.resize();
} }
if (this.controller.thumbnails) { if (this.controller.thumbnails) {
this.controller.thumbnails.resize(160, this.video.videoHeight / this.video.videoWidth * 160, this.template.barWrap.offsetWidth); this.controller.thumbnails.resize(160, (this.video.videoHeight / this.video.videoWidth) * 160, this.template.barWrap.offsetWidth);
} }
this.events.trigger('resize'); this.events.trigger('resize');
} }
speed (rate) { speed(rate) {
this.video.playbackRate = rate; this.video.playbackRate = rate;
} }
destroy () { destroy() {
instances.splice(instances.indexOf(this), 1); instances.splice(instances.indexOf(this), 1);
this.pause(); this.pause();
this.controller.destroy(); this.controller.destroy();
@@ -614,7 +607,7 @@ class DPlayer {
this.events.trigger('destroy'); this.events.trigger('destroy');
} }
static get version () { static get version() {
/* global DPLAYER_VERSION */ /* global DPLAYER_VERSION */
return DPLAYER_VERSION; return DPLAYER_VERSION;
} }
+29 -31
View File
@@ -1,19 +1,18 @@
const isMobile = /mobile/i.test(window.navigator.userAgent); const isMobile = /mobile/i.test(window.navigator.userAgent);
const utils = { const utils = {
/** /**
* Parse second to time string * Parse second to time string
* *
* @param {Number} second * @param {Number} second
* @return {String} 00:00 or 00:00:00 * @return {String} 00:00 or 00:00:00
*/ */
secondToTime: (second) => { secondToTime: (second) => {
second = second || 0; second = second || 0;
if (second === 0 || second == Infinity || second.toString() === 'NaN') { if (second === 0 || second === Infinity || second.toString() === 'NaN') {
return '00:00' return '00:00';
} }
const add0 = (num) => num < 10 ? '0' + num : '' + num; const add0 = (num) => (num < 10 ? '0' + num : '' + num);
const hour = Math.floor(second / 3600); const hour = Math.floor(second / 3600);
const min = Math.floor((second - hour * 3600) / 60); const min = Math.floor((second - hour * 3600) / 60);
const sec = Math.floor(second - hour * 3600 - min * 60); const sec = Math.floor(second - hour * 3600 - min * 60);
@@ -33,8 +32,7 @@ const utils = {
actualLeft += current.offsetLeft; actualLeft += current.offsetLeft;
current = current.offsetParent; current = current.offsetParent;
} }
} } else {
else {
while (current !== null && current !== element) { while (current !== null && current !== element) {
actualLeft += current.offsetLeft; actualLeft += current.offsetLeft;
current = current.offsetParent; current = current.offsetParent;
@@ -51,8 +49,8 @@ const utils = {
* getBoundingClientRect 在 Firefox 11 及以下返回的值会把 transform 的值也包含进去 * getBoundingClientRect 在 Firefox 11 及以下返回的值会把 transform 的值也包含进去
* getBoundingClientRect 在 Opera 10.5 及以下返回的值缺失 width、height 值 * getBoundingClientRect 在 Opera 10.5 及以下返回的值缺失 width、height 值
*/ */
getBoundingClientRectViewLeft (element) { getBoundingClientRectViewLeft(element) {
const scrollTop = window.scrollY || window.pageYOffset || document.body.scrollTop + (document.documentElement && document.documentElement.scrollTop || 0); const scrollTop = window.scrollY || window.pageYOffset || document.body.scrollTop + ((document.documentElement && document.documentElement.scrollTop) || 0);
if (element.getBoundingClientRect) { if (element.getBoundingClientRect) {
if (typeof this.getBoundingClientRectViewLeft.offset !== 'number') { if (typeof this.getBoundingClientRectViewLeft.offset !== 'number') {
@@ -73,19 +71,18 @@ const utils = {
} }
}, },
getScrollPosition () { getScrollPosition() {
return { return {
left: window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0, left: window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0,
top: window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0 top: window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0,
}; };
}, },
setScrollPosition ({left = 0, top = 0}) { setScrollPosition({ left = 0, top = 0 }) {
if (this.isFirefox) { if (this.isFirefox) {
document.documentElement.scrollLeft = left; document.documentElement.scrollLeft = left;
document.documentElement.scrollTop = top; document.documentElement.scrollTop = top;
} } else {
else {
window.scrollTo(left, top); window.scrollTo(left, top);
} }
}, },
@@ -101,11 +98,12 @@ const utils = {
localStorage.setItem(key, value); localStorage.setItem(key, value);
}, },
get: (key) => localStorage.getItem(key) get: (key) => localStorage.getItem(key),
}, },
cumulativeOffset: (element) => { cumulativeOffset: (element) => {
let top = 0, left = 0; let top = 0,
left = 0;
do { do {
top += element.offsetTop || 0; top += element.offsetTop || 0;
left += element.offsetLeft || 0; left += element.offsetLeft || 0;
@@ -114,14 +112,14 @@ const utils = {
return { return {
top: top, top: top,
left: left left: left,
}; };
}, },
nameMap: { nameMap: {
dragStart: isMobile ? 'touchstart' : 'mousedown', dragStart: isMobile ? 'touchstart' : 'mousedown',
dragMove: isMobile ? 'touchmove' : 'mousemove', dragMove: isMobile ? 'touchmove' : 'mousemove',
dragEnd: isMobile ? 'touchend' : 'mouseup' dragEnd: isMobile ? 'touchend' : 'mouseup',
}, },
color2Number: (color) => { color2Number: (color) => {
@@ -131,21 +129,21 @@ const utils = {
if (color.length === 3) { if (color.length === 3) {
color = `${color[0]}${color[0]}${color[1]}${color[1]}${color[2]}${color[2]}`; color = `${color[0]}${color[0]}${color[1]}${color[1]}${color[2]}${color[2]}`;
} }
return parseInt(color, 16) + 0x000000 & 0xffffff; return (parseInt(color, 16) + 0x000000) & 0xffffff;
}, },
number2Color: (number) => '#' + ('00000' + number.toString(16)).slice(-6), number2Color: (number) => '#' + ('00000' + number.toString(16)).slice(-6),
number2Type: (number) => { number2Type: (number) => {
switch (number) { switch (number) {
case 0: case 0:
return 'right'; return 'right';
case 1: case 1:
return 'top'; return 'top';
case 2: case 2:
return 'bottom'; return 'bottom';
default: default:
return 'right'; return 'right';
} }
}, },
}; };
+29 -38
View File
@@ -1,17 +1,17 @@
/* eslint-disable no-undef */
const path = require('path'); const path = require('path');
const webpack = require('webpack'); const webpack = require('webpack');
const GitRevisionPlugin = require('git-revision-webpack-plugin'); const GitRevisionPlugin = require('git-revision-webpack-plugin');
const gitRevisionPlugin = new GitRevisionPlugin(); const gitRevisionPlugin = new GitRevisionPlugin();
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
module.exports = { module.exports = {
mode: 'development', mode: 'development',
devtool: 'cheap-module-source-map', devtool: 'cheap-module-source-map',
entry: { entry: {
'DPlayer': './src/js/index.js' DPlayer: './src/js/index.js',
}, },
output: { output: {
@@ -21,23 +21,17 @@ module.exports = {
libraryTarget: 'umd', libraryTarget: 'umd',
libraryExport: 'default', libraryExport: 'default',
umdNamedDefine: true, umdNamedDefine: true,
publicPath: '/' publicPath: '/',
}, },
resolve: { resolve: {
modules: ['node_modules'], modules: ['node_modules'],
extensions: ['.js', '.scss'] extensions: ['.js', '.scss'],
}, },
module: { module: {
strictExportPresence: true, strictExportPresence: true,
rules: [ rules: [
{
test: /\.js$/,
enforce: 'pre',
loader: 'eslint-loader',
include: path.resolve(__dirname, '../src/js'),
},
{ {
test: /\.js$/, test: /\.js$/,
use: [ use: [
@@ -45,10 +39,10 @@ module.exports = {
loader: 'babel-loader', loader: 'babel-loader',
options: { options: {
cacheDirectory: true, cacheDirectory: true,
presets: ['@babel/preset-env'] presets: ['@babel/preset-env'],
} },
} },
] ],
}, },
{ {
test: /\.scss$/, test: /\.scss$/,
@@ -57,36 +51,34 @@ module.exports = {
{ {
loader: 'css-loader', loader: 'css-loader',
options: { options: {
importLoaders: 1 importLoaders: 1,
} },
}, },
{ {
loader: 'postcss-loader', loader: 'postcss-loader',
options: { options: {
config: { plugins: [autoprefixer, cssnano],
path: path.join(__dirname, 'postcss.config.js') },
}
}
}, },
'sass-loader' 'sass-loader',
] ],
}, },
{ {
test: /\.(png|jpg)$/, test: /\.(png|jpg)$/,
loader: 'url-loader', loader: 'url-loader',
options: { options: {
'limit': 40000 limit: 40000,
} },
}, },
{ {
test: /\.svg$/, test: /\.svg$/,
loader: 'svg-inline-loader' loader: 'svg-inline-loader',
}, },
{ {
test: /\.art$/, test: /\.art$/,
loader: 'art-template-loader' loader: 'art-template-loader',
} },
] ],
}, },
devServer: { devServer: {
@@ -96,29 +88,28 @@ module.exports = {
quiet: false, quiet: false,
open: true, open: true,
historyApiFallback: { historyApiFallback: {
disableDotRule: true disableDotRule: true,
}, },
watchOptions: { watchOptions: {
ignored: /node_modules/ ignored: /node_modules/,
} },
}, },
plugins: [ plugins: [
new webpack.DefinePlugin({ new webpack.DefinePlugin({
DPLAYER_VERSION: `"${require('../package.json').version}"`, DPLAYER_VERSION: `"${require('../package.json').version}"`,
GIT_HASH: JSON.stringify(gitRevisionPlugin.version()) GIT_HASH: JSON.stringify(gitRevisionPlugin.version()),
}) }),
], ],
node: { node: {
dgram: 'empty', dgram: 'empty',
fs: 'empty', fs: 'empty',
net: 'empty', net: 'empty',
tls: 'empty' tls: 'empty',
}, },
performance: { performance: {
hints: false hints: false,
} },
}; };
-6
View File
@@ -1,6 +0,0 @@
module.exports = {
plugins: {
'autoprefixer': {},
'cssnano': {}
}
};
+22 -36
View File
@@ -1,12 +1,11 @@
/* eslint-disable no-undef */
const path = require('path'); const path = require('path');
const webpack = require('webpack'); const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const GitRevisionPlugin = require('git-revision-webpack-plugin'); const GitRevisionPlugin = require('git-revision-webpack-plugin');
const gitRevisionPlugin = new GitRevisionPlugin(); const gitRevisionPlugin = new GitRevisionPlugin();
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
module.exports = { module.exports = {
mode: 'production', mode: 'production',
bail: true, bail: true,
@@ -14,7 +13,7 @@ module.exports = {
devtool: 'source-map', devtool: 'source-map',
entry: { entry: {
'DPlayer': './src/js/index.js' DPlayer: './src/js/index.js',
}, },
output: { output: {
@@ -24,23 +23,17 @@ module.exports = {
libraryTarget: 'umd', libraryTarget: 'umd',
libraryExport: 'default', libraryExport: 'default',
umdNamedDefine: true, umdNamedDefine: true,
publicPath: '/' publicPath: '/',
}, },
resolve: { resolve: {
modules: ['node_modules'], modules: ['node_modules'],
extensions: ['.js', '.scss'] extensions: ['.js', '.scss'],
}, },
module: { module: {
strictExportPresence: true, strictExportPresence: true,
rules: [ rules: [
{
test: /\.js$/,
enforce: 'pre',
loader: 'eslint-loader',
include: path.resolve(__dirname, '../src/js'),
},
{ {
test: /\.js$/, test: /\.js$/,
use: [ use: [
@@ -49,59 +42,53 @@ module.exports = {
loader: 'babel-loader', loader: 'babel-loader',
options: { options: {
cacheDirectory: true, cacheDirectory: true,
presets: ['@babel/preset-env'] presets: ['@babel/preset-env'],
} },
} },
] ],
}, },
{ {
test: /\.scss$/, test: /\.scss$/,
use: [ use: [
MiniCssExtractPlugin.loader, 'style-loader',
{ {
loader: 'css-loader', loader: 'css-loader',
options: { options: {
importLoaders: 1, importLoaders: 1,
sourceMap: true },
}
}, },
{ {
loader: 'postcss-loader', loader: 'postcss-loader',
options: { options: {
config: { plugins: [autoprefixer, cssnano],
path: path.join(__dirname, 'postcss.config.js') },
}
}
}, },
'sass-loader', 'sass-loader',
] ],
}, },
{ {
test: /\.(png|jpg)$/, test: /\.(png|jpg)$/,
loader: 'url-loader', loader: 'url-loader',
options: { options: {
'limit': 40000 limit: 40000,
} },
}, },
{ {
test: /\.svg$/, test: /\.svg$/,
loader: 'svg-inline-loader' loader: 'svg-inline-loader',
}, },
{ {
test: /\.art$/, test: /\.art$/,
loader: 'art-template-loader' loader: 'art-template-loader',
} },
] ],
}, },
plugins: [ plugins: [
new webpack.DefinePlugin({ new webpack.DefinePlugin({
DPLAYER_VERSION: `"${require('../package.json').version}"`, DPLAYER_VERSION: `"${require('../package.json').version}"`,
GIT_HASH: JSON.stringify(gitRevisionPlugin.version()) GIT_HASH: JSON.stringify(gitRevisionPlugin.version()),
}), }),
new MiniCssExtractPlugin({
filename: '[name].min.css'
})
], ],
node: { node: {
@@ -109,6 +96,5 @@ module.exports = {
fs: 'empty', fs: 'empty',
net: 'empty', net: 'empty',
tls: 'empty', tls: 'empty',
} },
}; };
+1060 -444
View File
File diff suppressed because it is too large Load Diff