mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-16 09:36:16 -08:00
移除深度合并依赖
This commit is contained in:
1 parent
dc8405403c
commit
b943bcde99
13 files changed
+232
-267
No files matched your search
@@ -46,7 +46,6 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"balloon-css": "^0.5.0",
|
||||
"deepmerge": "^2.2.1",
|
||||
"draggabilly": "^2.2.0",
|
||||
"option-validator": "^1.1.1",
|
||||
"resize-observer": "^1.0.0-alpha.1",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import merge from 'deepmerge';
|
||||
import { mergeDeep } from './utils';
|
||||
|
||||
let i18nMap = {
|
||||
'zh-cn': {
|
||||
@@ -84,7 +84,7 @@ export default class I18n {
|
||||
}
|
||||
|
||||
update(value) {
|
||||
i18nMap = merge(i18nMap, value);
|
||||
i18nMap = mergeDeep(i18nMap, value);
|
||||
this.init();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ import './style';
|
||||
import 'balloon-css/balloon.min.css';
|
||||
import Emitter from 'tiny-emitter';
|
||||
import optionValidator from 'option-validator';
|
||||
import merge from 'deepmerge';
|
||||
import * as utils from './utils';
|
||||
import scheme from './scheme';
|
||||
import config from './config';
|
||||
@@ -30,7 +29,8 @@ let id = 0;
|
||||
class Artplayer extends Emitter {
|
||||
constructor(option) {
|
||||
super();
|
||||
this.option = merge(Artplayer.DEFAULTS, option);
|
||||
this.option = utils.mergeDeep(Artplayer.DEFAULTS, option);
|
||||
console.log(this.option);
|
||||
optionValidator(this.option, scheme);
|
||||
this.init();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { errorHandle, setStyles, setStyle } from './utils';
|
||||
import { srtToVtt, vttToBlob } from './utils/subtitle';
|
||||
import { errorHandle, setStyles, setStyle, srtToVtt, vttToBlob } from './utils';
|
||||
|
||||
export default class Subtitle {
|
||||
constructor(art) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { errorHandle } from './utils';
|
||||
export default class Template {
|
||||
constructor(art) {
|
||||
if (art.option.container instanceof Element) {
|
||||
this.$container = this.option.container;
|
||||
this.$container = art.option.container;
|
||||
} else {
|
||||
this.$container = document.querySelector(art.option.container);
|
||||
}
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
export function append(parent, child) {
|
||||
if (child instanceof Element) {
|
||||
parent.appendChild(child);
|
||||
} else {
|
||||
parent.insertAdjacentHTML('beforeend', child);
|
||||
}
|
||||
return parent.lastElementChild;
|
||||
}
|
||||
|
||||
export function insertByIndex(parent, child, index) {
|
||||
const childs = Array.from(parent.children);
|
||||
child.dataset.index = index;
|
||||
const nextChild = childs.find(item => Number(item.dataset.index) >= Number(index));
|
||||
if (nextChild) {
|
||||
nextChild.insertAdjacentElement('beforebegin', child);
|
||||
} else {
|
||||
append(parent, child);
|
||||
}
|
||||
return child;
|
||||
}
|
||||
|
||||
export function setStyle(element, key, value) {
|
||||
element.style[key] = value;
|
||||
return element;
|
||||
}
|
||||
|
||||
export function setStyles(element, styles) {
|
||||
Object.keys(styles).forEach(key => {
|
||||
setStyle(element, key, styles[key]);
|
||||
});
|
||||
return element;
|
||||
}
|
||||
|
||||
export function getStyle(element, key, numberType = true) {
|
||||
const value = window.getComputedStyle(element, null).getPropertyValue(key);
|
||||
return numberType ? parseFloat(value) : value;
|
||||
}
|
||||
|
||||
export function sublings(target) {
|
||||
return Array.from(target.parentElement.children).filter(item => item !== target);
|
||||
}
|
||||
|
||||
export function inverseClass(target, className) {
|
||||
sublings(target).forEach(item => item.classList.remove(className));
|
||||
target.classList.add(className);
|
||||
}
|
||||
|
||||
export function tooltip(target, msg, pos = 'up') {
|
||||
target.setAttribute('data-balloon', msg);
|
||||
target.setAttribute('data-balloon-pos', pos);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
export class ArtPlayerError extends Error {
|
||||
constructor(message, context) {
|
||||
super(message);
|
||||
if (typeof Error.captureStackTrace === 'function') {
|
||||
Error.captureStackTrace(this, context || this.constructor);
|
||||
}
|
||||
this.name = 'ArtPlayerError';
|
||||
}
|
||||
}
|
||||
|
||||
export function errorHandle(condition, msg) {
|
||||
const isFun = typeof condition === 'function';
|
||||
if (isFun ? !isFun() : !condition) {
|
||||
throw new ArtPlayerError(msg);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,18 @@
|
||||
export * from './error';
|
||||
export * from './dom';
|
||||
export * from './subtitle';
|
||||
export class ArtPlayerError extends Error {
|
||||
constructor(message, context) {
|
||||
super(message);
|
||||
if (typeof Error.captureStackTrace === 'function') {
|
||||
Error.captureStackTrace(this, context || this.constructor);
|
||||
}
|
||||
this.name = 'ArtPlayerError';
|
||||
}
|
||||
}
|
||||
|
||||
export function errorHandle(condition, msg) {
|
||||
if (!condition) {
|
||||
throw new ArtPlayerError(msg);
|
||||
}
|
||||
}
|
||||
|
||||
export function clamp(num, a, b) {
|
||||
return Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b));
|
||||
@@ -48,6 +60,109 @@ export function debounce(func, wait, context) {
|
||||
fn.clearTimeout = function ct() {
|
||||
clearTimeout(timeout);
|
||||
};
|
||||
|
||||
|
||||
return fn;
|
||||
}
|
||||
|
||||
export function isObject(item) {
|
||||
return (item && typeof item === 'object' && !Array.isArray(item));
|
||||
}
|
||||
|
||||
export function isElement(item) {
|
||||
return item instanceof Element;
|
||||
}
|
||||
|
||||
export function mergeDeep(target, source) {
|
||||
const output = Object.assign({}, target);
|
||||
if (isObject(target) && isObject(source)) {
|
||||
Object.keys(source).forEach(key => {
|
||||
const value = source[key];
|
||||
if (isObject(value) && !isElement(value)) {
|
||||
if (!(key in target)) {
|
||||
Object.assign(output, {
|
||||
[key]: value,
|
||||
});
|
||||
} else {
|
||||
output[key] = mergeDeep(target[key], value);
|
||||
}
|
||||
} else {
|
||||
Object.assign(output, {
|
||||
[key]: value,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
export function append(parent, child) {
|
||||
if (child instanceof Element) {
|
||||
parent.appendChild(child);
|
||||
} else {
|
||||
parent.insertAdjacentHTML('beforeend', child);
|
||||
}
|
||||
return parent.lastElementChild;
|
||||
}
|
||||
|
||||
export function insertByIndex(parent, child, index) {
|
||||
const childs = Array.from(parent.children);
|
||||
child.dataset.index = index;
|
||||
const nextChild = childs.find(item => Number(item.dataset.index) >= Number(index));
|
||||
if (nextChild) {
|
||||
nextChild.insertAdjacentElement('beforebegin', child);
|
||||
} else {
|
||||
append(parent, child);
|
||||
}
|
||||
return child;
|
||||
}
|
||||
|
||||
export function setStyle(element, key, value) {
|
||||
element.style[key] = value;
|
||||
return element;
|
||||
}
|
||||
|
||||
export function setStyles(element, styles) {
|
||||
Object.keys(styles).forEach(key => {
|
||||
setStyle(element, key, styles[key]);
|
||||
});
|
||||
return element;
|
||||
}
|
||||
|
||||
export function getStyle(element, key, numberType = true) {
|
||||
const value = window.getComputedStyle(element, null).getPropertyValue(key);
|
||||
return numberType ? parseFloat(value) : value;
|
||||
}
|
||||
|
||||
export function sublings(target) {
|
||||
return Array.from(target.parentElement.children).filter(item => item !== target);
|
||||
}
|
||||
|
||||
export function inverseClass(target, className) {
|
||||
sublings(target).forEach(item => item.classList.remove(className));
|
||||
target.classList.add(className);
|
||||
}
|
||||
|
||||
export function tooltip(target, msg, pos = 'up') {
|
||||
target.setAttribute('data-balloon', msg);
|
||||
target.setAttribute('data-balloon-pos', pos);
|
||||
}
|
||||
|
||||
export function srtToVtt(srtText) {
|
||||
return 'WEBVTT \r\n\r\n'.concat(
|
||||
srtText
|
||||
.replace(/\{\\([ibu])\}/g, '</$1>')
|
||||
.replace(/\{\\([ibu])1\}/g, '<$1>')
|
||||
.replace(/\{([ibu])\}/g, '<$1>')
|
||||
.replace(/\{\/([ibu])\}/g, '</$1>')
|
||||
.replace(/(\d\d:\d\d:\d\d),(\d\d\d)/g, '$1.$2')
|
||||
.concat('\r\n\r\n'),
|
||||
);
|
||||
}
|
||||
|
||||
export function vttToBlob(vttText) {
|
||||
return URL.createObjectURL(
|
||||
new Blob([vttText], {
|
||||
type: 'text/vtt',
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
export function srtToVtt(srtText) {
|
||||
return 'WEBVTT \r\n\r\n'.concat(
|
||||
srtText
|
||||
.replace(/\{\\([ibu])\}/g, '</$1>')
|
||||
.replace(/\{\\([ibu])1\}/g, '<$1>')
|
||||
.replace(/\{([ibu])\}/g, '<$1>')
|
||||
.replace(/\{\/([ibu])\}/g, '</$1>')
|
||||
.replace(/(\d\d:\d\d:\d\d),(\d\d\d)/g, '$1.$2')
|
||||
.concat('\r\n\r\n'),
|
||||
);
|
||||
}
|
||||
|
||||
export function vttToBlob(vttText) {
|
||||
return URL.createObjectURL(
|
||||
new Blob([vttText], {
|
||||
type: 'text/vtt',
|
||||
}),
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user