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AA,GACI,KAAA,QAAY,GAAa,EAAA,EAC3B,CAIV,CAKD,OAAe,IACb,E,EACQ,UAAU,IAAA,SAAS,EAAc,GACvC,IAAA,EAAO,KAAA,QACR,EAAA,SAAA,KAAA,UAAM,EAAY,IAAY,SAAS,QAAA,EAAA,GACtC,OAAA,GACD,EAAA,WAAA,EAAA,YAAA,GAAM,EAAY,WAAY,IAAS,EAAE,WAAA,KAAA,GACxC,EAAe,WAAA,IAAA,GAAA,EAChB,MAEA,EAAA,YAAA,EAAA,WAAA,IACF,EAAA,WAAA,IAAA,QAGiB,C,IAGd,UAAa,GAAK,SAAa,EAAC,GACjC,GAAA,MAAA,QAAA,GAAM,QAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,OAAA,IAAA,CACC,IAAI,EAAM,EAAA,GACjB,KAAA,QAAA,iBAAA,EAAA,EACF,MAKO,KAAS,QAAO,iBAAkB,EAAA,GAGtC,OAAI,I,IAEH,UAAA,IAAA,SAAA,EAAA,GAED,GAAI,MAAA,QAAc,GAChB,QAAS,EAAK,EAAC,EAAQ,EAAK,EAAA,EAAA,OAAA,IAAA,CAC7B,IAAA,EAAA,EAAA,GAEG,KAAQ,QAAM,oBAAA,EAAA,EAChB,MAIA,KAAA,QAAa,oBAAkB,EAAA,GAElC,OAAA,IAGD,EACD,C,CAvNM,G","file":"/npm/@chargeui/charge@0.1.0/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@chargeui/charge@0.1.0/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","class InvalidArgumentError extends Error { }\n\nexport {\n  InvalidArgumentError\n}","import { InvalidArgumentError } from \"./errors\"\n\ninterface ClassOptions {\n  [s: string]: boolean\n}\n\ninterface AttributeOptions {\n  [s: string]: string | number | boolean | undefined\n}\n\ninterface PropertyOptions {\n  [s: string]: any\n}\n\ninterface ElementOptions {\n  type?: string\n  class?: string | ClassOptions | undefined\n  attr?: AttributeOptions | undefined\n  prop?: PropertyOptions | undefined\n  children?: Array<Selection> | undefined\n}\n\nclass Selection {\n\n  /** Creates a new selection with the element provided */\n  constructor(public element: HTMLElement) {\n\n  }\n\n  /** Returns true if the value passed in is a Selection */\n  public static isSelection (value: any): value is Selection {\n    return value instanceof Selection\n  }\n\n  /** Add a selected element, or array of selected elements to this selection */\n  public add (selection: Selection | Array<Selection>): this {\n    if (Array.isArray(selection)) {\n      for (const s of selection) {\n        this.element.appendChild(s.element)\n      }\n    } else {\n      this.element.appendChild(selection.element)\n    }\n    return this\n  }\n\n  /** Removes children from this selection */\n  public remove (selection: Selection | Array<Selection>): this {\n    if (Array.isArray(selection)) {\n      for (const s of selection) {\n        this.element.removeChild(s.element)\n      }\n    } else {\n      this.element.removeChild(selection.element)\n    }\n\n    return this\n  }\n\n  /** Sets the child elements of this selection */\n  public set (selection: Selection | Array<Selection>): this {\n    this.removeAll()\n\n    if (Array.isArray(selection)) {\n      for (const s of selection) {\n        this.element.appendChild(s.element)\n      }\n    } else {\n      this.element.appendChild(selection.element)\n    }\n\n    return this\n  }\n\n  /** Removes all children elements from this element */\n  public removeAll (): this {\n    while (this.element.firstChild) {\n      this.element.removeChild(this.element.firstChild)\n    }\n    return this\n  }\n\n  /** Detaches this element from its parent */\n  public removeSelf (): this {\n    if (this.element.parentElement) {\n      this.element.parentElement.removeChild(this.element)\n    }\n    return this\n  }\n\n  /** Gets the text of the selected element */\n  public text (): string\n  /** Sets the text of ths selected element */\n  public text (text: string): this\n  public text (text?: string): this | string {\n    if (arguments.length === 0) {\n      return this.element.innerText\n    } else {\n      this.element.innerText = text\n      return this\n    }\n  }\n\n  /** Gets the class for the element */\n  public class (): string\n  /** Sets the class for the element */\n  public class (cls: string | ClassOptions): this\n  public class (cls?: string | ClassOptions): this | string {\n    if (arguments.length > 0) {\n      if (typeof cls === 'string') {\n        this.element.className = cls\n      } else {\n        for (const key of Object.keys(cls)) {\n          if (cls[key]) {\n            this.element.classList.add(key)\n          } else {\n            this.element.classList.remove(key)\n          }\n        }\n      }\n      return this\n    } else {\n      return this.element.className\n    }\n  }\n\n  /** Returns true if the selected element has the class */\n  public hasClass (cls: string): boolean {\n    return this.element.classList.contains(cls)\n  }\n\n  /** Gets an attribute on the element */\n  public attr (key: string): string | undefined\n  /** Sets one or more attributes on the element */\n  public attr (options: AttributeOptions): this\n  /** Sets an attribute on the element */\n  public attr (key: string, value: string | number | boolean | undefined): this\n  public attr (keyOrOptions: string | AttributeOptions, value?: string | number | boolean | undefined): this | string | undefined {\n    if (arguments.length === 2) {\n      if (typeof keyOrOptions === 'string') {\n        if (value !== undefined) {\n          this.element.setAttribute(keyOrOptions, value.toString())\n        } else {\n          this.element.removeAttribute(keyOrOptions)\n        }\n      } else {\n        throw new InvalidArgumentError(\"key should be a string\")\n      }\n    } else if (arguments.length === 1) {\n      if (typeof keyOrOptions === 'string') {\n        return this.element.getAttribute(keyOrOptions) || undefined\n      } else {\n        for (const key of Object.keys(keyOrOptions)) {\n          const value = keyOrOptions[key]\n          if (value !== undefined) {\n            this.element.setAttribute(key, value.toString())\n          } else {\n            this.element.removeAttribute(key)\n          }\n        }\n      }\n    } else {\n      throw new InvalidArgumentError(\"expected 1 or 2 arguments\")\n    }\n    return this\n  }\n\n  /** Gets a property of the element */\n  public prop (key: string): any\n  /** Sets one or more properties of the element */\n  public prop (options: PropertyOptions): this\n  /** Sets a property of the element */\n  public prop (key: string, value: any | undefined): this\n  public prop (keyOrOptions: string | PropertyOptions, value?: any | undefined): this | any {\n    if (arguments.length === 2) {\n      if (typeof keyOrOptions === 'string') {\n        (this.element as any)[keyOrOptions] = value\n      } else {\n        throw new InvalidArgumentError(\"key should be a string\")\n      }\n    } else if (arguments.length === 1) {\n      if (typeof keyOrOptions === 'string') {\n        return (this.element as any)[keyOrOptions]\n      } else {\n        for (const key of Object.keys(keyOrOptions)) {\n          (this.element as any)[key] = keyOrOptions[key]\n        }\n      }\n    } else {\n      throw new InvalidArgumentError(\"expected 1 or 2 arguments\")\n    }\n    return this\n  }\n}\n\nfunction createSelectionFromElement (element: Element): Selection {\n  if (element instanceof HTMLElement) {\n    return new Selection(element)\n  } else {\n    throw new Error(typeof (element) + ' elements are not supported yet in the Selection api')\n  }\n}\n\n/** Selects an element in the document (using document.querySelector under the hood)\n *  An element can be converted into a selection using this method\n */\nfunction select (selector: string | HTMLElement | Selection): Selection {\n  if (typeof selector === 'string') {\n    const element = document.querySelector(selector)\n    return createSelectionFromElement(element)\n  } else if (selector instanceof Element) {\n    return createSelectionFromElement(selector)\n  } else if (selector instanceof Selection) {\n    return selector\n  } else {\n    throw new Error('Invalid value passed into select(): ' + selector)\n  }\n}\n\n/** Selects all elements from the document (using document.querySelectorAll under the hood) */\nfunction selectAll (selector: string): Array<Selection> {\n  if (typeof selector === 'string') {\n    const elements = document.querySelectorAll(selector)\n    return Array.from(elements).map(createSelectionFromElement)\n  } else {\n    throw new Error('Invalid value passed into selectAll(): ' + selector)\n  }\n}\n\n/** Creates a new detached element */\nfunction element (options?: ElementOptions): Selection {\n  const element = document.createElement(options ? options.type || 'div' : 'div')\n  const selection = new Selection(element)\n\n  if (options) {\n    if (options.class) {\n      selection.class(options.class)\n    }\n\n    if (options.attr) {\n      selection.attr(options.attr)\n    }\n\n    if (options.prop) {\n      selection.prop(options.prop)\n    }\n\n    if (options.children) {\n      selection.set(options.children)\n    }\n  }\n\n\n  return selection\n}\n\nexport {\n  Selection,\n  select,\n  selectAll,\n  element\n}"]}