chore: update workflow
This commit is contained in:
+5
-6
@@ -2,7 +2,6 @@
|
||||
import defaultApiBackend from './api.js';
|
||||
|
||||
export default (options) => {
|
||||
|
||||
// default options
|
||||
const defaultOption = {
|
||||
container: options.element || document.getElementsByClassName('dplayer')[0],
|
||||
@@ -19,7 +18,7 @@ export default (options) => {
|
||||
video: {},
|
||||
contextmenu: [],
|
||||
mutex: true,
|
||||
pluginOptions:{hls:{},flvjs:{},dash:{},webtorrent:{}}
|
||||
pluginOptions: { hls: {}, flvjs: {}, dash: {}, webtorrent: {} },
|
||||
};
|
||||
for (const defaultKey in defaultOption) {
|
||||
if (defaultOption.hasOwnProperty(defaultKey) && !options.hasOwnProperty(defaultKey)) {
|
||||
@@ -52,16 +51,16 @@ export default (options) => {
|
||||
text: 'Video info',
|
||||
click: (player) => {
|
||||
player.infoPanel.triggle();
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
text: 'About author',
|
||||
link: 'https://diygod.me'
|
||||
link: 'https://diygod.me',
|
||||
},
|
||||
{
|
||||
text: `DPlayer v${DPLAYER_VERSION}`,
|
||||
link: 'https://github.com/MoePlayer/DPlayer'
|
||||
}
|
||||
link: 'https://github.com/MoePlayer/DPlayer',
|
||||
},
|
||||
]);
|
||||
|
||||
return options;
|
||||
|
||||
+144
-151
@@ -25,15 +25,14 @@ let index = 0;
|
||||
const instances = [];
|
||||
|
||||
class DPlayer {
|
||||
|
||||
/**
|
||||
* DPlayer constructor function
|
||||
*
|
||||
* @param {Object} options - See README
|
||||
* @constructor
|
||||
*/
|
||||
constructor (options) {
|
||||
this.options = handleOption({preload:options.video.type === 'webtorrent' ? 'none' : 'metadata', ...options});
|
||||
constructor(options) {
|
||||
this.options = handleOption({ preload: options.video.type === 'webtorrent' ? 'none' : 'metadata', ...options });
|
||||
|
||||
if (this.options.video.quality) {
|
||||
this.qualityIndex = this.options.video.defaultQuality;
|
||||
@@ -116,12 +115,20 @@ class DPlayer {
|
||||
this.setting = new Setting(this);
|
||||
this.plugins = {};
|
||||
|
||||
document.addEventListener('click', () => {
|
||||
this.focus = false;
|
||||
}, true);
|
||||
this.container.addEventListener('click', () => {
|
||||
this.focus = true;
|
||||
}, true);
|
||||
document.addEventListener(
|
||||
'click',
|
||||
() => {
|
||||
this.focus = false;
|
||||
},
|
||||
true
|
||||
);
|
||||
this.container.addEventListener(
|
||||
'click',
|
||||
() => {
|
||||
this.focus = true;
|
||||
},
|
||||
true
|
||||
);
|
||||
|
||||
this.paused = true;
|
||||
|
||||
@@ -131,7 +138,7 @@ class DPlayer {
|
||||
|
||||
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);
|
||||
|
||||
@@ -144,17 +151,16 @@ class DPlayer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Seek video
|
||||
*/
|
||||
seek (time) {
|
||||
* Seek video
|
||||
*/
|
||||
seek(time) {
|
||||
time = Math.max(time, 0);
|
||||
if (this.video.duration) {
|
||||
time = Math.min(time, this.video.duration);
|
||||
}
|
||||
if (this.video.currentTime < time) {
|
||||
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')}`);
|
||||
}
|
||||
|
||||
@@ -171,7 +177,7 @@ class DPlayer {
|
||||
/**
|
||||
* Play video
|
||||
*/
|
||||
play () {
|
||||
play() {
|
||||
this.paused = false;
|
||||
if (this.video.paused) {
|
||||
this.bezel.switch(Icons.play);
|
||||
@@ -180,10 +186,11 @@ class DPlayer {
|
||||
this.template.playButton.innerHTML = Icons.pause;
|
||||
|
||||
const playedPromise = Promise.resolve(this.video.play());
|
||||
playedPromise.catch(() => {
|
||||
this.pause();
|
||||
}).then(() => {
|
||||
});
|
||||
playedPromise
|
||||
.catch(() => {
|
||||
this.pause();
|
||||
})
|
||||
.then(() => {});
|
||||
this.timer.enable('loading');
|
||||
this.container.classList.remove('dplayer-paused');
|
||||
this.container.classList.add('dplayer-playing');
|
||||
@@ -202,7 +209,7 @@ class DPlayer {
|
||||
/**
|
||||
* Pause video
|
||||
*/
|
||||
pause () {
|
||||
pause() {
|
||||
this.paused = true;
|
||||
this.container.classList.remove('dplayer-loading');
|
||||
|
||||
@@ -220,14 +227,12 @@ class DPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
switchVolumeIcon () {
|
||||
switchVolumeIcon() {
|
||||
if (this.volume() >= 0.95) {
|
||||
this.template.volumeIcon.innerHTML = Icons.volumeUp;
|
||||
}
|
||||
else if (this.volume() > 0) {
|
||||
} else if (this.volume() > 0) {
|
||||
this.template.volumeIcon.innerHTML = Icons.volumeDown;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this.template.volumeIcon.innerHTML = Icons.volumeOff;
|
||||
}
|
||||
}
|
||||
@@ -235,7 +240,7 @@ class DPlayer {
|
||||
/**
|
||||
* Set volume
|
||||
*/
|
||||
volume (percentage, nostorage, nonotice) {
|
||||
volume(percentage, nostorage, nonotice) {
|
||||
percentage = parseFloat(percentage);
|
||||
if (!isNaN(percentage)) {
|
||||
percentage = Math.max(percentage, 0);
|
||||
@@ -263,11 +268,10 @@ class DPlayer {
|
||||
/**
|
||||
* Toggle between play and pause
|
||||
*/
|
||||
toggle () {
|
||||
toggle() {
|
||||
if (this.video.paused) {
|
||||
this.play();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this.pause();
|
||||
}
|
||||
}
|
||||
@@ -275,7 +279,7 @@ class DPlayer {
|
||||
/**
|
||||
* attach event
|
||||
*/
|
||||
on (name, callback) {
|
||||
on(name, callback) {
|
||||
this.events.on(name, callback);
|
||||
}
|
||||
|
||||
@@ -285,7 +289,7 @@ class DPlayer {
|
||||
* @param {Object} video - new video info
|
||||
* @param {Object} danmaku - new danmaku info
|
||||
*/
|
||||
switchVideo (video, danmakuAPI) {
|
||||
switchVideo(video, danmakuAPI) {
|
||||
this.pause();
|
||||
this.video.poster = video.pic ? video.pic : '';
|
||||
this.video.src = video.url;
|
||||
@@ -309,28 +313,23 @@ class DPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
initMSE (video, type) {
|
||||
initMSE(video, type) {
|
||||
this.type = type;
|
||||
if (this.options.video.customType && this.options.video.customType[type]) {
|
||||
if (Object.prototype.toString.call(this.options.video.customType[type]) === '[object Function]') {
|
||||
this.options.video.customType[type](this.video, this);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
console.error(`Illegal customType: ${type}`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (this.type === 'auto') {
|
||||
if (/m3u8(#|\?|$)/i.exec(video.src)) {
|
||||
this.type = 'hls';
|
||||
}
|
||||
else if (/.flv(#|\?|$)/i.exec(video.src)) {
|
||||
} else if (/.flv(#|\?|$)/i.exec(video.src)) {
|
||||
this.type = 'flv';
|
||||
}
|
||||
else if (/.mpd(#|\?|$)/i.exec(video.src)) {
|
||||
} else if (/.mpd(#|\?|$)/i.exec(video.src)) {
|
||||
this.type = 'dash';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this.type = 'normal';
|
||||
}
|
||||
}
|
||||
@@ -340,111 +339,107 @@ class DPlayer {
|
||||
}
|
||||
|
||||
switch (this.type) {
|
||||
// https://github.com/video-dev/hls.js
|
||||
case 'hls':
|
||||
if (Hls) {
|
||||
if (Hls.isSupported()) {
|
||||
const options = this.options.pluginOptions.hls;
|
||||
const hls = new Hls(options);
|
||||
this.plugins.hls = hls;
|
||||
hls.loadSource(video.src);
|
||||
hls.attachMedia(video);
|
||||
this.events.on('destroy', () => {
|
||||
hls.destroy();
|
||||
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
|
||||
// https://github.com/video-dev/hls.js
|
||||
case 'hls':
|
||||
if (window.Hls) {
|
||||
if (window.Hls.isSupported()) {
|
||||
const options = this.options.pluginOptions.hls;
|
||||
const hls = new window.Hls(options);
|
||||
this.plugins.hls = hls;
|
||||
hls.loadSource(video.src);
|
||||
hls.attachMedia(video);
|
||||
this.events.on('destroy', () => {
|
||||
hls.destroy();
|
||||
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 (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', () => {
|
||||
client.remove(torrentId);
|
||||
client.destroy();
|
||||
delete this.plugins.webtorrent;
|
||||
window.dashjs.MediaPlayer().reset();
|
||||
delete this.plugins.dash;
|
||||
});
|
||||
} else {
|
||||
this.notice("Error: Can't find dashjs.");
|
||||
}
|
||||
else {
|
||||
this.notice('Error: Webtorrent is not supported.');
|
||||
break;
|
||||
|
||||
// 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.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.notice('Error: Can\'t find Webtorrent.');
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
initVideo (video, type) {
|
||||
initVideo(video, type) {
|
||||
this.initMSE(video, type);
|
||||
|
||||
/**
|
||||
@@ -478,8 +473,7 @@ class DPlayer {
|
||||
this.bar.set('played', 1, 'width');
|
||||
if (!this.setting.loop) {
|
||||
this.pause();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this.seek(0);
|
||||
this.play();
|
||||
}
|
||||
@@ -524,12 +518,11 @@ class DPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
switchQuality (index) {
|
||||
switchQuality(index) {
|
||||
index = typeof index === 'string' ? parseInt(index) : index;
|
||||
if (this.qualityIndex === index || this.switchingQuality) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this.qualityIndex = index;
|
||||
}
|
||||
this.switchingQuality = true;
|
||||
@@ -544,7 +537,7 @@ class DPlayer {
|
||||
screenshot: this.options.screenshot,
|
||||
preload: 'auto',
|
||||
url: this.quality.url,
|
||||
subtitle: this.options.subtitle
|
||||
subtitle: this.options.subtitle,
|
||||
});
|
||||
const videoEle = new DOMParser().parseFromString(videoHTML, 'text/html').body.firstChild;
|
||||
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.style.opacity = opacity;
|
||||
if (this.noticeTime) {
|
||||
@@ -590,21 +583,21 @@ class DPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
resize () {
|
||||
resize() {
|
||||
if (this.danmaku) {
|
||||
this.danmaku.resize();
|
||||
}
|
||||
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');
|
||||
}
|
||||
|
||||
speed (rate) {
|
||||
speed(rate) {
|
||||
this.video.playbackRate = rate;
|
||||
}
|
||||
|
||||
destroy () {
|
||||
destroy() {
|
||||
instances.splice(instances.indexOf(this), 1);
|
||||
this.pause();
|
||||
this.controller.destroy();
|
||||
@@ -614,7 +607,7 @@ class DPlayer {
|
||||
this.events.trigger('destroy');
|
||||
}
|
||||
|
||||
static get version () {
|
||||
static get version() {
|
||||
/* global DPLAYER_VERSION */
|
||||
return DPLAYER_VERSION;
|
||||
}
|
||||
|
||||
+29
-31
@@ -1,19 +1,18 @@
|
||||
const isMobile = /mobile/i.test(window.navigator.userAgent);
|
||||
|
||||
const utils = {
|
||||
|
||||
/**
|
||||
* Parse second to time string
|
||||
*
|
||||
* @param {Number} second
|
||||
* @return {String} 00:00 or 00:00:00
|
||||
*/
|
||||
* Parse second to time string
|
||||
*
|
||||
* @param {Number} second
|
||||
* @return {String} 00:00 or 00:00:00
|
||||
*/
|
||||
secondToTime: (second) => {
|
||||
second = second || 0;
|
||||
if (second === 0 || second == Infinity || second.toString() === 'NaN') {
|
||||
return '00:00'
|
||||
if (second === 0 || second === Infinity || second.toString() === 'NaN') {
|
||||
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 min = Math.floor((second - hour * 3600) / 60);
|
||||
const sec = Math.floor(second - hour * 3600 - min * 60);
|
||||
@@ -33,8 +32,7 @@ const utils = {
|
||||
actualLeft += current.offsetLeft;
|
||||
current = current.offsetParent;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
while (current !== null && current !== element) {
|
||||
actualLeft += current.offsetLeft;
|
||||
current = current.offsetParent;
|
||||
@@ -51,8 +49,8 @@ const utils = {
|
||||
* getBoundingClientRect 在 Firefox 11 及以下返回的值会把 transform 的值也包含进去
|
||||
* getBoundingClientRect 在 Opera 10.5 及以下返回的值缺失 width、height 值
|
||||
*/
|
||||
getBoundingClientRectViewLeft (element) {
|
||||
const scrollTop = window.scrollY || window.pageYOffset || document.body.scrollTop + (document.documentElement && document.documentElement.scrollTop || 0);
|
||||
getBoundingClientRectViewLeft(element) {
|
||||
const scrollTop = window.scrollY || window.pageYOffset || document.body.scrollTop + ((document.documentElement && document.documentElement.scrollTop) || 0);
|
||||
|
||||
if (element.getBoundingClientRect) {
|
||||
if (typeof this.getBoundingClientRectViewLeft.offset !== 'number') {
|
||||
@@ -73,19 +71,18 @@ const utils = {
|
||||
}
|
||||
},
|
||||
|
||||
getScrollPosition () {
|
||||
getScrollPosition() {
|
||||
return {
|
||||
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) {
|
||||
document.documentElement.scrollLeft = left;
|
||||
document.documentElement.scrollTop = top;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
window.scrollTo(left, top);
|
||||
}
|
||||
},
|
||||
@@ -101,11 +98,12 @@ const utils = {
|
||||
localStorage.setItem(key, value);
|
||||
},
|
||||
|
||||
get: (key) => localStorage.getItem(key)
|
||||
get: (key) => localStorage.getItem(key),
|
||||
},
|
||||
|
||||
cumulativeOffset: (element) => {
|
||||
let top = 0, left = 0;
|
||||
let top = 0,
|
||||
left = 0;
|
||||
do {
|
||||
top += element.offsetTop || 0;
|
||||
left += element.offsetLeft || 0;
|
||||
@@ -114,14 +112,14 @@ const utils = {
|
||||
|
||||
return {
|
||||
top: top,
|
||||
left: left
|
||||
left: left,
|
||||
};
|
||||
},
|
||||
|
||||
nameMap: {
|
||||
dragStart: isMobile ? 'touchstart' : 'mousedown',
|
||||
dragMove: isMobile ? 'touchmove' : 'mousemove',
|
||||
dragEnd: isMobile ? 'touchend' : 'mouseup'
|
||||
dragEnd: isMobile ? 'touchend' : 'mouseup',
|
||||
},
|
||||
|
||||
color2Number: (color) => {
|
||||
@@ -131,21 +129,21 @@ const utils = {
|
||||
if (color.length === 3) {
|
||||
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),
|
||||
|
||||
number2Type: (number) => {
|
||||
switch (number) {
|
||||
case 0:
|
||||
return 'right';
|
||||
case 1:
|
||||
return 'top';
|
||||
case 2:
|
||||
return 'bottom';
|
||||
default:
|
||||
return 'right';
|
||||
case 0:
|
||||
return 'right';
|
||||
case 1:
|
||||
return 'top';
|
||||
case 2:
|
||||
return 'bottom';
|
||||
default:
|
||||
return 'right';
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user