class ElementHelper {
    constructor(tagName, className = '', innerHtml = '') {
        this.classes = [];
        if (typeof tagName === 'string') {
            this.elem = document.createElement(tagName);
        }
        else {
            this.elem = tagName;
        }
        if (className) {
            this.setClass(className);
        }
        if (innerHtml) {
            this.setInnerHTML(innerHtml);
        }
    }
    setClass(className) {
        this.elem.className = className;
        this.classes = [className];
        return this;
    }
    addClass(className) {
        if (!this.classes.includes(className)) {
            this.classes.push(className);
            this.elem.className = this.classes.join(' ');
        }
        return this;
    }
    removeClass(className) {
        const pos = this.classes.indexOf(className);
        if (pos !== -1) {
            this.classes.splice(pos, 1);
            this.elem.className = this.classes.join(' ');
        }
        return this;
    }
    appendChild(node) {
        this.elem.appendChild(node instanceof ElementHelper ? node.getElem() : node);
        return this;
    }
    append(node) {
        this.elem.append(node instanceof ElementHelper ? node.getElem() : node);
        return this;
    }
    css(styles) {
        const k = 'color';
        this.elem.style[k] = 's';
        Object.entries(styles).forEach(([key, value]) => {
            this.elem.style[key] = value || '';
        });
        return this;
    }
    getElem() {
        return this.elem;
    }
    getInnerHTML() {
        return this.elem.innerHTML;
    }
    setInnerHTML(html) {
        this.elem.innerHTML = html;
        return this;
    }
    setContentEditable(enable) {
        this.elem.contentEditable = enable ? 'true' : 'false';
        return this;
    }
    onClick(handler) {
        this.elem.onclick = handler;
        return this;
    }
    addEventListener(type, listener, options) {
        this.elem.addEventListener(type, listener, options);
        return this;
    }
    removeEventListener(type, listener, options) {
        this.elem.removeEventListener(type, listener, options);
        return this;
    }
    getBoundingClientRect() {
        return this.elem.getBoundingClientRect();
    }
    focus() {
        this.elem.focus();
        return this;
    }
    startObserve(callback, options) {
        this.stopObserve();
        this.observer = new MutationObserver(callback);
        this.observer.observe(this.elem, options);
    }
    stopObserve() {
        if (this.observer) {
            this.observer.disconnect();
            this.observer = undefined;
        }
    }
}
export default ElementHelper;
//# sourceMappingURL=ElementHelper.js.map