/** * @class SmartButton * @description SmartButton is a class that enables the creation of a movable button. */ export class SmartButton { constructor(buttonId) { this.button = document.getElementById(buttonId); if (!this.button) throw new Error("SmartButton not found"); this.isVisible = false; } /** * Move the smartButton to the target position * @param {number} x - X Position * @param {number} y - Y position */ moveTo(x, y) { Object.assign(this.button.style, { left: `${x}px`, top: `${y}px`, position: "absolute", }); this.show(); } show() { this.button.style.display = "block"; this.isVisible = true; } hide() { this.button.style.display = "none"; this.isVisible = false; } setPosition(x, y) { this.moveTo(x, y); } /** * * @returns {HTMLElement} */ getElement() { return this.button; } onClick(callback) { this.button.addEventListener("click", () => { callback(); }); } }