//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// TypeScript helpers (universal micro-lib.) | Author: Sergei Y.Kitaev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Helpers for HTMLElement-element (static class):
class HElement {
    static ById(id, tagName = null) {
        return HById.ElementOf(id, tagName);
    }
    static GetById(id, tagName = null) {
        var element = document.getElementById(id);
        if (!tagName)
            return element;
        return element && element.tagName == tagName ? element : null;
    }
    static IsDisabled(element) {
        return element.disabled === true;
    }
    static ContainsPoint(element, x, y) {
        let rect = element.getBoundingClientRect();
        return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom;
    }
    static ContainsMousePointer(element, e) {
        return HElement.ContainsPoint(element, e.clientX, e.clientY);
    }
    static IsFocused(element) {
        let activeElement = HDoc.FocusedElement();
        return !!activeElement && element == activeElement;
    }
    static ContainsFocus(element) {
        let activeElement = document.activeElement;
        return !!activeElement && element.contains(activeElement);
    }
    static ScriptCurrent() {
        let scriptTags = document.getElementsByTagName('script');
        if (scriptTags.length == 0)
            throw new Error('ScriptCurrentElement function must be called from <script> tag.');
        let element = scriptTags[scriptTags.length - 1].parentElement;
        if (!element)
            throw new Error('Unknown element of <script> tag (ScriptCurrentElement function)');
        return element;
    }
    static ScriptCurrent_Get() {
        let scriptTags = document.getElementsByTagName('script');
        return scriptTags.length > 0 ?
            scriptTags[scriptTags.length - 1].parentElement :
            null;
    }
    static UseClass(element, className, use) {
        if (use)
            HElement.IncludeClass(element, className);
        else
            HElement.ExcludeClass(element, className);
    }
    static IncludeClass(element, className) {
        var classList = element.classList;
        if (!classList.contains(className)) {
            classList.add(className);
            return true;
        }
        return false;
    }
    static ExcludeClass(element, className) {
        var classList = element.classList;
        if (classList.contains(className)) {
            classList.remove(className);
            return true;
        }
        return false;
    }
    static Click(element) {
        if (HElement.IsDisabled(element))
            return false;
        element.click();
        return true;
    }
    static ClickIfNotNull(element) {
        return element ? HElement.Click(element) : false;
    }
    static DeferredClick(element, milliseconds = 0) {
        if (HElement.IsDisabled(element))
            return false;
        milliseconds = HOps.NullSubst(milliseconds, 0);
        setTimeout(() => { element.click(); }, milliseconds);
        return true;
    }
    static DeferredFocus(element, milliseconds = 0) {
        milliseconds = HOps.NullSubst(milliseconds, 0);
        setTimeout(() => { element.focus(); }, milliseconds);
    }
    static Select(element) {
        let elem = element;
        if (!elem.select)
            return false;
        elem.select();
        return true;
    }
    static DeferredSelect(element, milliseconds = 0) {
        milliseconds = HOps.NullSubst(milliseconds, 0);
        let elem = element;
        if (!elem.select)
            return false;
        setTimeout(() => { elem.select(); }, milliseconds);
        return true;
    }
    static FocusSelect(element) {
        element.focus();
        HElement.Select(element);
    }
    static DeferredFocusSelect(element, milliseconds = 0) {
        milliseconds = HOps.NullSubst(milliseconds, 0);
        let elem = element;
        setTimeout(() => {
            element.focus();
            if (elem.select)
                elem.select();
        }, milliseconds);
    }
    static SelectAll(container) {
        if (DOC.selection) { // IE
            var body = document.body;
            let range = body.createTextRange ? body.createTextRange() : null;
            if (range) {
                range.moveToElementText(container);
                range.select();
                return true;
            }
            return false;
        }
        let selection = window.getSelection ? window.getSelection() : null;
        if (!selection)
            return false;
        let range = document.createRange();
        range.selectNode(container);
        selection.removeAllRanges();
        selection.addRange(range);
        return true;
    }
    static DeferredSelectAll(container, milliseconds = 0) {
        milliseconds = HOps.NullSubst(milliseconds, 0);
        setTimeout(() => { HElement.SelectAll(container); }, milliseconds);
    }
    static DeferredScrollIntoView(element, milliseconds = 0) {
        milliseconds = HOps.NullSubst(milliseconds, 0);
        setTimeout(() => { element.scrollIntoView(); }, milliseconds);
    }
} // HElement
//# sourceMappingURL=HElement.js.map