import { readFile, updateHTMLOptions, showRelatedHTML, syncHTMLValue, insertHTMLChild, createCustomEvent, } from "@/components/helper"; import "@/components/background.css" export default class Background { #el = document.createElement("div") #parentEl #videoEl #default = { location: `${import.meta.env.BASE_URL}assets/${import.meta.env.VITE_BACKGROUND_FOLDER}/`, image: "operator_bg.png" } #config = { video: { name: null, volume: 100, }, useVideo: false, name: null } #musicObj constructor(el) { this.#parentEl = el this.#el.id = "background-box" this.image = this.#default.location + this.#default.image this.#el.innerHTML = ` ` insertHTMLChild(this.#parentEl, this.#el) this.#videoEl = document.getElementById("video-src") } resetImage() { document.getElementById("custom-background").value = "" document.getElementById("custom-background-clear").disabled = true this.#config.name = null this.image = this.#default.location + this.#default.image } resetVideo() { this.#config.video.name = null this.#videoEl.src = "" document.getElementById("custom-video-background").value = "" document.getElementById("custom-video-background-clear").disabled = true } reset() { this.resetImage() this.resetVideo() } link(musicObj) { this.#musicObj = musicObj } get useVideo() { return this.#config.useVideo } set useVideo(v) { this.#config.useVideo = v } set image(v) { this.#el.style.backgroundImage = `url("${v}")` } set video(v) { const update = (url, v = null) => { this.#config.video.name = { isLocalFile: v !== null, value: v ? v.name : url } this.#videoEl.src = url this.#videoEl.load() document.getElementById("custom-video-background-clear").disabled = false } if (typeof v === "object") { readFile( v, (blobURL) => update(blobURL, v) ) } else { update(v) } } get volume() { return this.#config.video.volume } set volume(v) { v = parseInt(v) this.#config.video.volume = v this.#videoEl.volume = v / 100 } get current() { return this.#config.name || this.#default.image } set default(v) { this.#default.image = v this.#musicObj.music = v this.image = this.#default.location + this.#default.image } set custom(v) { const update = (url, v = null) => { this.#config.name = { isLocalFile: v !== null, value: v ? v.name : url } this.image = url document.getElementById("custom-background-clear").disabled = false } if (typeof v === "object") { readFile( v, (blobURL) => update(blobURL, v) ) } else { update(v) } } get config() { return { default: this.#default.image, ...this.#config } } get backCompatibilityFns() { const _this = this return { currentBackground: _this.current, setBackgoundImage: (v) => _this.image = v, setDefaultBackground: (v) => _this.default = v, setBackground: (v) => _this.custom = v, resetBackground: _this.resetImage, setVideo: (e) => _this.video = e.target.files[0], getVideoVolume: () => _this.volume, setVideoVolume: (v) => _this.volume = v, setVideoFromWE: (url) => _this.video = url, resetVideo: _this.resetVideo } } get HTML() { return `