(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.AtomUI = exports.ChildEnumerator = void 0;
    // refer http://youmightnotneedjquery.com/
    class ChildEnumerator {
        constructor(e) {
            this.e = e;
        }
        get current() {
            return this.item;
        }
        next() {
            if (!this.item) {
                this.item = this.e.firstElementChild;
            }
            else {
                this.item = this.item.nextElementSibling;
            }
            return this.item ? true : false;
        }
    }
    exports.ChildEnumerator = ChildEnumerator;
    class AtomUI {
        static outerHeight(el, margin = false) {
            let height = el.offsetHeight;
            if (!margin) {
                return height;
            }
            const style = getComputedStyle(el);
            height += parseInt(style.marginTop, 10) + parseInt(style.marginBottom, 10);
            return height;
        }
        static outerWidth(el, margin = false) {
            let width = el.offsetWidth;
            if (!margin) {
                return width;
            }
            const style = getComputedStyle(el);
            width += parseInt(style.marginLeft, 10) + parseInt(style.marginRight, 10);
            return width;
        }
        static innerWidth(el) {
            return el.clientWidth;
        }
        static innerHeight(el) {
            return el.clientHeight;
        }
        static scrollTop(el, y) {
            el.scrollTo(0, y);
        }
        static screenOffset(e) {
            const r = {
                x: e.offsetLeft,
                y: e.offsetTop,
                width: e.offsetWidth,
                height: e.offsetHeight
            };
            if (e.offsetParent) {
                const p = this.screenOffset(e.offsetParent);
                r.x += p.x;
                r.y += p.y;
            }
            return r;
        }
        static parseUrl(url) {
            const r = {};
            const plist = url.split("&");
            for (const item of plist) {
                const p = item.split("=");
                const key = decodeURIComponent(p[0]);
                if (!key) {
                    continue;
                }
                let val = p[1];
                if (val) {
                    val = decodeURIComponent(val);
                }
                // val = AtomUI.parseValue(val);
                r[key] = this.parseValue(val);
            }
            return r;
        }
        static parseValue(val) {
            let n;
            if (/^[0-9]+$/.test(val)) {
                n = parseInt(val, 10);
                if (!isNaN(n)) {
                    return n;
                }
                return val;
            }
            if (/^[0-9]+\.[0-9]+/gi.test(val)) {
                n = parseFloat(val);
                if (!isNaN(n)) {
                    return n;
                }
                return val;
            }
            if (val === "true") {
                return true;
            }
            if (val === "false") {
                return false;
            }
            return val;
        }
        static assignID(element) {
            if (!element.id) {
                element.id = "__waID" + AtomUI.getNewIndex();
            }
            return element.id;
        }
        static toNumber(text) {
            if (!text) {
                return 0;
            }
            if (text.constructor === String) {
                return parseFloat(text);
            }
            return 0;
        }
        static getNewIndex() {
            AtomUI.index = AtomUI.index + 1;
            return AtomUI.index;
        }
    }
    exports.AtomUI = AtomUI;
    AtomUI.index = 1001;
});
//# sourceMappingURL=AtomUI.js.map