text: /**
   * @license
   *
   * Copyright IBM Corp. 2020
   *
   * This source code is licensed under the Apache-2.0 license found in the
   * LICENSE file in the root directory of this source tree.
   */
  
  'use strict';
  
  const { getAttributes, formatAttributes } = require('@carbon/icon-helpers');
  
  // For `@carbon/ibmdotcom-web-components`, we let our consumers set those attributes
  const omitAttrs = {
    class: true,
    role: true,
    'aria-labelledby': true,
  };
  
  /**
   * @param {object} descriptor Object representation of an SVG icon as generated by @carbon/icons
   * @returns {string} The `lit-html` template string version of the given SVG icon descriptor.
   */
  const toString = descriptor => {
    if (typeof descriptor === 'string') {
      return descriptor;
    }
    const { elem = 'svg', attrs = {}, content = [] } = descriptor;
    const children = content.map(toString).join('');
    if (elem !== 'svg') {
      return `<${elem} ${formatAttributes(attrs)}>${children}</${elem}>`;
    }
    return `<${elem} ${formatAttributes(getAttributes(attrs))}>${children}</${elem}>`;
  };
  
  /**
   * Function that takes a valid @carbon/icons style icon descriptor and returns a lit-html svg instance
   *
   * @param {object} descriptor Object representation of an SVG icon as generated by @carbon/icons
   */
  const icon = descriptor => {
    const attrs = getAttributes(
      Object.assign(descriptor.attrs, {
        '...': '${spread(attrs)}', // eslint-disable-line no-template-curly-in-string
      })
    );
    descriptor.attrs = Object.keys(attrs).reduce(
      (acc, attr) =>
        typeof attrs[attr] === 'undefined' || omitAttrs[attr]
          ? acc
          : {
              ...acc,
              [attr]: attrs[attr],
            },
      {}
    );
    descriptor.content = descriptor.content.reduce(
      (acc, item) => {
        // For `@carbon/ibmdotcom-web-components`, we let our consumers set the `<title>`
        if (item.elem !== 'title') {
          acc.push(item);
        }
        return acc;
      },
      ['${children}'] // eslint-disable-line no-template-curly-in-string
    );
    return `({ children, ...attrs } = {}) => svg\`${toString(descriptor)}\``;
  };
  
  module.exports = icon;
  