import { errorHandle, query, addClass, replaceElement, isMobile } from './utils';
export default class Template {
constructor(art) {
this.art = art;
const { option, constructor, whitelist } = art;
if (option.container instanceof Element) {
this.$container = option.container;
} else {
this.$container = query(option.container);
errorHandle(this.$container, `No container element found by ${option.container}`);
}
const type = this.$container.tagName.toLowerCase();
errorHandle(type === 'div', `Unsupported container element type, only support 'div' but got '${type}'`);
errorHandle(
constructor.instances.every((ins) => ins.template.$container !== this.$container),
'Cannot mount multiple instances on the same dom element',
);
this.query = this.query.bind(this);
this.$container.dataset.artId = art.id;
this.$original = this.$container.cloneNode(true);
if (whitelist.state) {
this.desktop();
} else {
this.mobile();
}
}
static get html() {
return `
Player version:
${process.env.APP_VER}
[x]
`;
}
query(className) {
return query(className, this.$container);
}
desktop() {
const { option } = this.art;
if (!option.useSSR) {
this.$container.innerHTML = Template.html;
}
this.$player = this.query('.art-video-player');
this.$video = this.query('.art-video');
this.$track = this.query('track');
this.$poster = this.query('.art-poster');
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.$controlsCenter = this.query('.art-controls-center');
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.$info = this.query('.art-info');
this.$infoPanel = this.query('.art-info-panel');
this.$infoClose = this.query('.art-info-close');
this.$miniHeader = this.query('.art-mini-header');
this.$miniTitle = this.query('.art-mini-title');
this.$miniClose = this.query('.art-mini-close');
this.$contextmenu = this.query('.art-contextmenus');
if (option.backdrop) {
addClass(this.$setting, 'art-backdrop-filter');
addClass(this.$contextmenu, 'art-backdrop-filter');
addClass(this.$info, 'art-backdrop-filter');
}
if (isMobile) {
addClass(this.$player, 'art-mobile');
}
}
mobile() {
this.$container.innerHTML = `
`;
this.$player = this.query('.art-video-player');
this.$video = this.query('.art-video');
}
destroy(removeHtml) {
if (removeHtml) {
replaceElement(this.$original, this.$container);
} else {
addClass(this.$player, 'art-destroy');
}
}
}