{"version":3,"file":"sfds.mjs","sources":["../../src/icons/index.js","../../src/js/icons.js"],"sourcesContent":["import { icons } from './data.json'\n\nconst templates = {}\n\nfor (const [id, { aliases = [], svg }] of Object.entries(icons)) {\n  const template = createElementTemplate(svg)\n  templates[id] = template\n  for (const alias of aliases) {\n    templates[alias] = template\n  }\n}\n\nconst defaultProps = {\n  height: 20\n}\n\nexport function render (symbol, props = {}) {\n  const { strict, ...rest } = props\n  if (Object.prototype.hasOwnProperty.call(templates, symbol)) {\n    const attrs = Object.assign({}, defaultProps, rest)\n    const template = templates[symbol]\n    return template(attrs)\n  } else if (strict) {\n    throw new Error(`No such sfgov icon: \"${symbol}\"`)\n  } else {\n    return ''\n  }\n}\n\nconst observedAttributes = ['symbol', 'width', 'height']\n\nexport class SFGovIcon extends window.HTMLElement {\n  static get observedAttributes () {\n    return observedAttributes\n  }\n\n  static get icons () {\n    return icons\n  }\n\n  static get symbols () {\n    return Object.keys(icons)\n  }\n\n  connectedCallback () {\n    if (!this.hasAttribute('role')) {\n      this.setAttribute('role', 'img')\n    }\n    this.render()\n  }\n\n  get symbol () {\n    return this.getAttribute('symbol')\n  }\n\n  set symbol (value) {\n    this.setAttribute('symbol', value)\n  }\n\n  attributeChangedCallback (...args) {\n    this.render()\n  }\n\n  render () {\n    const { props } = this\n    const svg = render(this.symbol, props)\n    if (svg) {\n      if (this.__svg) {\n        this.replaceChild(svg, this.__svg)\n      } else {\n        this.appendChild(svg)\n      }\n      this.__svg = svg\n    }\n  }\n\n  get props () {\n    const props = { }\n    for (const attr of observedAttributes) {\n      if (this.hasAttribute(attr)) {\n        props[attr] = this.getAttribute(attr)\n      }\n    }\n    return props\n  }\n}\n\nfunction createElementTemplate (markup) {\n  let template = document.createElement('div')\n  template.innerHTML = markup\n  template = template.firstElementChild\n  return (attrs = {}) => {\n    const clone = template.cloneNode(true)\n    for (const [name, value] of Object.entries(attrs)) {\n      clone.setAttribute(name, value)\n    }\n    return clone\n  }\n}\n","import { SFGovIcon } from '../icons'\n\nwindow.customElements.define('sfgov-icon', SFGovIcon)\n\nif (!document.getElementById('sfgov-icon-css')) {\n  const style = document.createElement('style')\n  style.textContent = `\n    sfgov-icon {\n      display: inline-flex;\n      align-items: center;\n    }\n\n    sfgov-icon svg {\n      fill: currentColor;\n    }\n  `\n  document.head.appendChild(style)\n}\n"],"names":["templates","Object","entries","icons","id","aliases","template","createElementTemplate","svg","alias","defaultProps","height","observedAttributes","SFGovIcon","window","HTMLElement","this","hasAttribute","setAttribute","render","getAttribute","value","props","symbol","strict","rest","prototype","hasOwnProperty","call","attrs","assign","Error","__svg","replaceChild","appendChild","attr","keys","markup","document","createElement","innerHTML","firstElementChild","clone","cloneNode","name","customElements","define","getElementById","style","textContent","head"],"mappings":"knGAIA,u4fAFMA,EAAY,SAEwBC,OAAOC,QAAQC,kBAAQ,iBAArDC,kBAAMC,QAAAA,aAAU,KACpBC,EAAWC,IADaC,KAE9BR,EAAUI,GAAME,YACID,kCAAS,KAAlBI,UACTT,EAAUS,GAASH,kCAIvB,IAAMI,EAAe,CACnBC,OAAQ,IAgBV,IAAMC,EAAqB,CAAC,SAAU,QAAS,UAElCC,oPAAkBC,OAAOC,iIAapC,WACOC,KAAKC,aAAa,cAChBC,aAAa,OAAQ,YAEvBC,6BAGP,kBACSH,KAAKI,aAAa,eAG3B,SAAYC,QACLH,aAAa,SAAUG,2CAG9B,gBACOF,+BAGP,eACUG,EAAUN,KAAVM,MACFd,EAjDH,SAAiBe,OAAQD,yDAAQ,GAC9BE,EAAoBF,EAApBE,OAAWC,IAASH,QACxBrB,OAAOyB,UAAUC,eAAeC,KAAK5B,EAAWuB,GAAS,KACrDM,EAAQ5B,OAAO6B,OAAO,GAAIpB,EAAce,UAEvCnB,EADUN,EAAUuB,IACXM,GACX,GAAIL,QACH,IAAIO,qCAA8BR,cAEjC,GAwCKJ,CAAOH,KAAKO,OAAQD,GAC5Bd,IACEQ,KAAKgB,WACFC,aAAazB,EAAKQ,KAAKgB,YAEvBE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