{"code":"import { InvalidArgumentError } from './errors';\r\nvar Selection = (function () {\r\n    function Selection(element) {\r\n        this.element = element;\r\n    }\r\n    Selection.isSelection = function (value) {\r\n        return value instanceof Selection;\r\n    };\r\n    Selection.prototype.add = function (selection) {\r\n        if (Array.isArray(selection)) {\r\n            for (var _i = 0, selection_1 = selection; _i < selection_1.length; _i++) {\r\n                var s = selection_1[_i];\r\n                this.element.appendChild(s.element);\r\n            }\r\n        }\r\n        else {\r\n            this.element.appendChild(selection.element);\r\n        }\r\n        return this;\r\n    };\r\n    Selection.prototype.remove = function (selection) {\r\n        if (Array.isArray(selection)) {\r\n            for (var _i = 0, selection_2 = selection; _i < selection_2.length; _i++) {\r\n                var s = selection_2[_i];\r\n                this.element.removeChild(s.element);\r\n            }\r\n        }\r\n        else {\r\n            this.element.removeChild(selection.element);\r\n        }\r\n        return this;\r\n    };\r\n    Selection.prototype.set = function (selection) {\r\n        this.removeAll();\r\n        if (Array.isArray(selection)) {\r\n            for (var _i = 0, selection_3 = selection; _i < selection_3.length; _i++) {\r\n                var s = selection_3[_i];\r\n                this.element.appendChild(s.element);\r\n            }\r\n        }\r\n        else {\r\n            this.element.appendChild(selection.element);\r\n        }\r\n        return this;\r\n    };\r\n    Selection.prototype.removeAll = function () {\r\n        while (this.element.firstChild) {\r\n            this.element.removeChild(this.element.firstChild);\r\n        }\r\n        return this;\r\n    };\r\n    Selection.prototype.removeSelf = function () {\r\n        if (this.element.parentElement) {\r\n            this.element.parentElement.removeChild(this.element);\r\n        }\r\n        return this;\r\n    };\r\n    Selection.prototype.text = function (text) {\r\n        if (arguments.length === 0) {\r\n            return this.element.innerText;\r\n        }\r\n        else {\r\n            this.element.innerText = text;\r\n            return this;\r\n        }\r\n    };\r\n    Selection.prototype[\"class\"] = function (cls) {\r\n        if (arguments.length > 0) {\r\n            if (typeof cls === 'string') {\r\n                this.element.className = cls;\r\n            }\r\n            else {\r\n                for (var _i = 0, _a = Object.keys(cls); _i < _a.length; _i++) {\r\n                    var key = _a[_i];\r\n                    if (cls[key]) {\r\n                        this.element.classList.add(key);\r\n                    }\r\n                    else {\r\n                        this.element.classList.remove(key);\r\n                    }\r\n                }\r\n            }\r\n            return this;\r\n        }\r\n        else {\r\n            return this.element.className;\r\n        }\r\n    };\r\n    Selection.prototype.hasClass = function (cls) {\r\n        return this.element.classList.contains(cls);\r\n    };\r\n    Selection.prototype.attr = function (keyOrOptions, value) {\r\n        if (arguments.length === 2) {\r\n            if (typeof keyOrOptions === 'string') {\r\n                if (value !== undefined) {\r\n                    this.element.setAttribute(keyOrOptions, value.toString());\r\n                }\r\n                else {\r\n                    this.element.removeAttribute(keyOrOptions);\r\n                }\r\n            }\r\n            else {\r\n                throw new InvalidArgumentError(\"key should be a string\");\r\n            }\r\n        }\r\n        else if (arguments.length === 1) {\r\n            if (typeof keyOrOptions === 'string') {\r\n                return this.element.getAttribute(keyOrOptions) || undefined;\r\n            }\r\n            else {\r\n                for (var _i = 0, _a = Object.keys(keyOrOptions); _i < _a.length; _i++) {\r\n                    var key = _a[_i];\r\n                    var value_1 = keyOrOptions[key];\r\n                    if (value_1 !== undefined) {\r\n                        this.element.setAttribute(key, value_1.toString());\r\n                    }\r\n                    else {\r\n                        this.element.removeAttribute(key);\r\n                    }\r\n                }\r\n            }\r\n        }\r\n        else {\r\n            throw new InvalidArgumentError(\"expected 1 or 2 arguments\");\r\n        }\r\n        return this;\r\n    };\r\n    Selection.prototype.prop = function (keyOrOptions, value) {\r\n        if (arguments.length === 2) {\r\n            if (typeof keyOrOptions === 'string') {\r\n                this.element[keyOrOptions] = value;\r\n            }\r\n            else {\r\n                throw new InvalidArgumentError(\"key should be a string\");\r\n            }\r\n        }\r\n        else if (arguments.length === 1) {\r\n            if (typeof keyOrOptions === 'string') {\r\n                return this.element[keyOrOptions];\r\n            }\r\n            else {\r\n                for (var _i = 0, _a = Object.keys(keyOrOptions); _i < _a.length; _i++) {\r\n                    var key = _a[_i];\r\n                    this.element[key] = keyOrOptions[key];\r\n                }\r\n            }\r\n        }\r\n        else {\r\n            throw new InvalidArgumentError(\"expected 1 or 2 arguments\");\r\n        }\r\n        return this;\r\n    };\r\n    Selection.prototype.api = function (api) {\r\n        var elementAsAny = this.element;\r\n        if (arguments.length > 0) {\r\n            elementAsAny.__charge__ = elementAsAny.__charge__ || {};\r\n            elementAsAny.__charge__.api = api;\r\n            return this;\r\n        }\r\n        else {\r\n            return elementAsAny.__charge__ ? elementAsAny.__charge__.api : undefined;\r\n        }\r\n    };\r\n    Selection.prototype.on = function (name, handler) {\r\n        this.element.addEventListener(name, handler);\r\n    };\r\n    Selection.prototype.off = function (name, handler) {\r\n        this.element.removeEventListener(name, handler);\r\n    };\r\n    return Selection;\r\n}());\r\nfunction createSelectionFromElement(element) {\r\n    if (element instanceof HTMLElement) {\r\n        return new Selection(element);\r\n    }\r\n    else {\r\n        throw new Error(typeof (element) + ' elements are not supported yet in the Selection api');\r\n    }\r\n}\r\nfunction select(selector) {\r\n    if (typeof selector === 'string') {\r\n        var element_1 = document.querySelector(selector);\r\n        return createSelectionFromElement(element_1);\r\n    }\r\n    else if (selector instanceof Element) {\r\n        return createSelectionFromElement(selector);\r\n    }\r\n    else if (selector instanceof Selection) {\r\n        return selector;\r\n    }\r\n    else {\r\n        throw new Error('Invalid value passed into select(): ' + selector);\r\n    }\r\n}\r\nfunction selectAll(selector) {\r\n    if (typeof selector === 'string') {\r\n        var elements = document.querySelectorAll(selector);\r\n        return Array.from(elements).map(createSelectionFromElement);\r\n    }\r\n    else {\r\n        throw new Error('Invalid value passed into selectAll(): ' + selector);\r\n    }\r\n}\r\nfunction element(options) {\r\n    var element = document.createElement(options ? options.type || 'div' : 'div');\r\n    var selection = new Selection(element);\r\n    if (options) {\r\n        if (options[\"class\"]) {\r\n            selection[\"class\"](options[\"class\"]);\r\n        }\r\n        if (options.attr) {\r\n            selection.attr(options.attr);\r\n        }\r\n        if (options.prop) {\r\n            selection.prop(options.prop);\r\n        }\r\n        if (options.children) {\r\n            selection.set(options.children);\r\n        }\r\n        if (options.api) {\r\n            selection.api(options.api);\r\n        }\r\n    }\r\n    return selection;\r\n}\r\nexport { Selection, select, selectAll, element };\r\n//# sourceMappingURL=selection.js.map","references":["/Users/james/code/gitlab/charge/src/errors.ts"],"map":"{\"version\":3,\"file\":\"selection.js\",\"sourceRoot\":\"\",\"sources\":[\"../../src/selection.ts\"],\"names\":[],\"mappings\":\"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAuB/C;IAGE,mBAAmB,OAAoB;QAApB,YAAO,GAAP,OAAO,CAAa;IAEvC,CAAC;IAGa,qBAAW,GAAzB,UAA2B,KAAU;QACnC,OAAO,KAAK,YAAY,SAAS,CAAA;IACnC,CAAC;IAGM,uBAAG,GAAV,UAAY,SAAuC;QACjD,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;YAC5B,KAAgB,UAAS,EAAT,uBAAS,EAAT,uBAAS,EAAT,IAAS,EAAE;gBAAtB,IAAM,CAAC,kBAAA;gBACV,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;aACpC;SACF;aAAM;YACL,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;SAC5C;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAGM,0BAAM,GAAb,UAAe,SAAuC;QACpD,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;YAC5B,KAAgB,UAAS,EAAT,uBAAS,EAAT,uBAAS,EAAT,IAAS,EAAE;gBAAtB,IAAM,CAAC,kBAAA;gBACV,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;aACpC;SACF;aAAM;YACL,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;SAC5C;QAED,OAAO,IAAI,CAAA;IACb,CAAC;IAGM,uBAAG,GA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,OAAO,CAAC,GAAG,CAAC,CAAA;SAC3B;KACF;IAED,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,OAAO,EACL,SAAS,EACT,MAAM,EACN,SAAS,EACT,OAAO,EACR,CAAA\"}","dts":{"name":"/Users/james/code/gitlab/charge/selection.d.ts","writeByteOrderMark":false,"text":"interface ClassOptions {\r\n    [s: string]: boolean;\r\n}\r\ninterface AttributeOptions {\r\n    [s: string]: string | number | boolean | undefined;\r\n}\r\ninterface PropertyOptions {\r\n    [s: string]: any;\r\n}\r\ninterface ElementOptions<T> {\r\n    type?: string;\r\n    class?: string | ClassOptions | undefined;\r\n    attr?: AttributeOptions | undefined;\r\n    prop?: PropertyOptions | undefined;\r\n    children?: Array<Selection> | undefined;\r\n    api?: T;\r\n}\r\ndeclare class Selection<T = any> {\r\n    element: HTMLElement;\r\n    constructor(element: HTMLElement);\r\n    static isSelection(value: any): value is Selection;\r\n    add(selection: Selection | Array<Selection>): this;\r\n    remove(selection: Selection | Array<Selection>): this;\r\n    set(selection: Selection | Array<Selection>): this;\r\n    removeAll(): this;\r\n    removeSelf(): this;\r\n    text(): string;\r\n    text(text: string): this;\r\n    class(): string;\r\n    class(cls: string | ClassOptions): this;\r\n    hasClass(cls: string): boolean;\r\n    attr(key: string): string | undefined;\r\n    attr(options: AttributeOptions): this;\r\n    attr(key: string, value: string | number | boolean | undefined): this;\r\n    prop(key: string): any;\r\n    prop(options: PropertyOptions): this;\r\n    prop(key: string, value: any | undefined): this;\r\n    api(): T | undefined;\r\n    api(api: T): this;\r\n    on(name: string, handler: (evt: Event) => void): void;\r\n    off(name: string, handler?: (evt: Event) => void): void;\r\n}\r\ndeclare function select(selector: string | HTMLElement | Selection): Selection;\r\ndeclare function selectAll(selector: string): Array<Selection>;\r\ndeclare function element<T = any>(options?: ElementOptions<T>): Selection<T>;\r\nexport { Selection, select, selectAll, element };\r\n"}}
