/**
 * modules/core/domHelpers.js — Helpers DOM sin frameworks.
 */
(function (g) {
    g.modules = g.modules || {};
    g.modules.core = g.modules.core || {};
    g.modules.core.dom = {
        qs: function (sel, root) {
            return (root || document).querySelector(sel);
        },
        qsa: function (sel, root) {
            return Array.prototype.slice.call((root || document).querySelectorAll(sel));
        },
        el: function (tag, attrs, children) {
            var node = document.createElement(tag);
            if (attrs) {
                Object.keys(attrs).forEach(function (k) {
                    if (k === 'className') node.className = attrs[k];
                    else if (k === 'text') node.textContent = attrs[k];
                    else if (k === 'html') node.innerHTML = attrs[k];
                    else if (k.slice(0, 2) === 'on' && typeof attrs[k] === 'function') node.addEventListener(k.slice(2).toLowerCase(), attrs[k]);
                    else node.setAttribute(k, attrs[k]);
                });
            }
            (children || []).forEach(function (ch) {
                if (ch) node.appendChild(typeof ch === 'string' ? document.createTextNode(ch) : ch);
            });
            return node;
        },
        removeEl: function (node) {
            if (node && node.parentNode) node.parentNode.removeChild(node);
        },
    };
})(typeof window !== 'undefined' ? window : this);
