import { errorHandle, query, addClass } from './utils';
export default class Template {
constructor(art) {
this.art = art;
if (art.option.container instanceof Element) {
this.$container = art.option.container;
} else {
this.$container = query(art.option.container);
errorHandle(this.$container, `No container element found by ${art.option.container}`);
}
errorHandle(
art.constructor.instances.every(art => art.template.$container !== this.$container),
'Cannot mount multiple instances on the same dom element',
);
errorHandle(
this.$container.clientWidth && this.$container.clientHeight,
'The width and height of the container cannot be 0',
);
if (art.whitelist.state) {
this.desktop();
} else {
this.mobile();
}
}
query(className) {
return query(className, this.$container);
}
desktop() {
const { theme, backdrop } = this.art.option;
this.$container.innerHTML = `
Player version:
__VERSION__
[x]
`;
this.$player = this.query('.art-video-player');
this.$video = this.query('.art-video');
this.$track = this.query('.art-video track');
this.$subtitle = this.query('.art-subtitle');
this.$danmuku = this.query('.art-danmuku');
this.$bottom = this.query('.art-bottom');
this.$progress = this.query('.art-progress');
this.$controls = this.query('.art-controls');
this.$controlsLeft = this.query('.art-controls-left');
this.$controlsRight = this.query('.art-controls-right');
this.$layer = this.query('.art-layers');
this.$loading = this.query('.art-loading');
this.$notice = this.query('.art-notice');
this.$noticeInner = this.query('.art-notice-inner');
this.$mask = this.query('.art-mask');
this.$state = this.query('.art-state');
this.$setting = this.query('.art-settings');
this.$settingInner = this.query('.art-setting-inner');
this.$settingBody = this.query('.art-setting-body');
this.$info = this.query('.art-info');
this.$infoPanel = this.query('.art-info-panel');
this.$infoClose = this.query('.art-info-close');
this.$pipHeader = this.query('.art-pip-header');
this.$pipTitle = this.query('.art-pip-title');
this.$pipClose = this.query('.art-pip-close');
this.$contextmenu = this.query('.art-contextmenus');
if (backdrop) {
addClass(this.$settingInner, 'art-backdrop-filter');
addClass(this.$info, 'art-backdrop-filter');
addClass(this.$contextmenu, 'art-backdrop-filter');
}
}
mobile() {
this.$container.innerHTML = `
`;
this.$player = this.query('.art-video-player');
this.$video = this.query('.art-video');
}
destroy(remove) {
if (remove) {
this.$container.innerHTML = '';
} else {
addClass(this.$player, 'art-destroy');
}
}
}