import { types } from "assets/types.js"; class widget { #node; constructor(node, classname, name) { types.check_html_element(node); types.check_string(name, true); types.check_string(classname); node.classList.add(classname); if (name !== undefined && name !== null) { types.block_strings(name, [" ", "#", "\t", "\n"]); node.classList.add(name); node.classList.add(classname + "-" + name); } this.#node = node; } get node() { if (!(this.#node instanceof HTMLElement)) { throw new ReferenceError("Widget had been removed."); } return this.#node; } _add_event(name, callback) { types.check_string(name); types.check_callback(callback); this.node.addEventListener(name, (event) => { callback(event, this); }); } set _content(target) { types.check_string(target); const node = this.node; if (node instanceof HTMLInputElement) { node.value = target return; } if (node instanceof HTMLImageElement) { node.src = target; return; } node.innetText = target; } _drop_content() { const node = this.node; if (node instanceof HTMLInputElement) { node.value = ""; return; } while (node.childElementCound) { node.lastChild.remove(); } } place(target) { types.check_html_element(target); target.appendChild(this.node); } _append(target) { if (this.node instanceof HTMLInputElement) { throw new ReferenceError("Can not append into input element."); } if (target instanceof HTMLElement) { this.node.appendChild(target); return; } if (target instanceof widget) { this.node.appendChild(target.node); return; } throw new TypeError("New item must be HTML element or widget."); } add_click(callback) { this._add_event("click", callback); } get style() { return this.node.style; } } export { widget };