'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-58ea899e.js');
const icons = require('./icons-dbc3eb9c.js');
const typeGuard = require('./type-guard-8fd7909d.js');
const component = require('./component-334e6818.js');
const designToken = require('./design-token-362120c0.js');
const ui = require('./ui-fe7a2158.js');
const iconManager = require('./icon-manager-d14c9a96.js');
const log = require('./global-slimmer-registry-7bbdb1f2.js');
const injectVegaSlimmer = require('./inject-vega-slimmer-26fffae4.js');
const componentUsageRuntimeMetrics = require('./component-usage-runtime-metrics-b717b38b.js');
const tryGetDocument = require('./try-get-document-c0ebd39a.js');
const index$1 = require('./index-592b4052.js');
require('./breakpoints-ebde4837.js');
require('./ui-32120990.js');
require('./regex-397aba10.js');
require('./typography-4560e7f1.js');
require('./internal-translation-controller-38f68a4c.js');
require('./change-manager-72f643de.js');
require('./static-subject-title-5829a298.js');
require('./responsive-format-facade-44c14e82.js');
require('./breakpoints-1cc2c4c6.js');
require('./number-4816603d.js');
require('./pixel-98f2a10c.js');
require('./array-249289f2.js');
require('./feature-flag-controller-09933b7a.js');
require('./index-f054eb5d.js');
require('./state-border-formatter-189711cc.js');
require('./create-public-api-runtime-metrics-slimmer-1b8ecfb4.js');
require('./dynamic-slimmer-0050c489.js');
require('./misc-3d30df91.js');

const vegaIconCss = ":host(.v-text-primary),.v-text-primary{color:rgba(var(--v-text-primary, 32, 54, 69, 1))}:host(.v-text-secondary),.v-text-secondary{color:rgba(var(--v-text-secondary, 107, 116, 125, 1))}:host(.v-text-inverted-primary),.v-text-inverted-primary{color:rgba(var(--v-text-inverted-primary, 252, 252, 252, 1))}:host(.v-text-inverted-secondary),.v-text-inverted-secondary{color:rgba(var(--v-text-inverted-secondary, 188, 186, 213, 1))}:host(.v-text-black),.v-text-black{color:rgba(var(--v-text-black, 32, 54, 69, 1))}:host(.v-text-white),.v-text-white{color:rgba(var(--v-text-white, 252, 252, 252, 1))}:host(.v-text-brand),.v-text-brand{color:rgba(var(--v-text-brand, 51, 57, 61, 1))}:host(.v-text-danger-link),.v-text-danger-link{color:rgba(var(--v-text-danger-link, 230, 50, 87, 1))}:host(.v-text-danger-link-hover),.v-text-danger-link-hover{color:rgba(var(--v-text-danger-link-hover, 233, 71, 104, 1))}:host(.v-text-danger-link-active),.v-text-danger-link-active{color:rgba(var(--v-text-danger-link-active, 189, 41, 71, 1))}:host(.v-text-danger-link-focus),.v-text-danger-link-focus{color:rgba(var(--v-text-danger-link-focus, 240, 52, 91, 1))}:host(.v-text-danger-link-visited),.v-text-danger-link-visited{color:rgba(var(--v-text-danger-link-visited, 230, 50, 87, 1))}:host(.v-text-disabled),.v-text-disabled{color:rgba(var(--v-text-disabled, 176, 180, 181, 1))}:host(.v-text-error),.v-text-error{color:rgba(var(--v-text-error, 189, 41, 71, 1))}:host(.v-text-input-disabled),.v-text-input-disabled{color:rgba(var(--v-text-input-disabled, 107, 116, 125, 1))}:host(.v-text-input-placeholder),.v-text-input-placeholder{color:rgba(var(--v-text-input-placeholder, 176, 180, 181, 1))}:host(.v-text-link),.v-text-link{color:rgba(var(--v-text-link, 19, 98, 226, 1))}:host(.v-text-link-hover),.v-text-link-hover{color:rgba(var(--v-text-link-hover, 4, 112, 236, 1))}:host(.v-text-link-active),.v-text-link-active{color:rgba(var(--v-text-link-active, 29, 65, 195, 1))}:host(.v-text-link-focus),.v-text-link-focus{color:rgba(var(--v-text-link-focus, 4, 112, 236, 1))}:host(.v-text-link-visited),.v-text-link-visited{color:rgba(var(--v-text-link-visited, 95, 56, 206, 1))}:host(.v-text-on-action),.v-text-on-action{color:rgba(var(--v-text-on-action, 252, 252, 252, 1))}:host(.v-text-on-danger),.v-text-on-danger{color:rgba(var(--v-text-on-danger, 252, 252, 252, 1))}:host(.v-text-on-disabled),.v-text-on-disabled{color:rgba(var(--v-text-on-disabled, 252, 252, 252, 1))}:host(.v-text-sidebar-link),.v-text-sidebar-link{color:rgba(var(--v-text-sidebar-link, 188, 186, 213, 1))}:host(.v-text-sidebar-link-hover),.v-text-sidebar-link-hover{color:rgba(var(--v-text-sidebar-link-hover, 18, 18, 39, 1))}:host(.v-text-sidebar-link-selected),.v-text-sidebar-link-selected{color:rgba(var(--v-text-sidebar-link-selected, 252, 252, 252, 1))}:host(.v-text-site-footer-link),.v-text-site-footer-link{color:rgba(var(--v-text-site-footer-link, 171, 198, 216, 1))}:host(.v-text-site-footer-link-hover),.v-text-site-footer-link-hover{color:rgba(var(--v-text-site-footer-link-hover, 199, 217, 229, 1))}:host(.v-text-site-footer-link-active),.v-text-site-footer-link-active{color:rgba(var(--v-text-site-footer-link-active, 143, 179, 203, 1))}:host(.v-text-success),.v-text-success{color:rgba(var(--v-text-success, 1, 128, 31, 1))}:host(.v-text-inverted-success),.v-text-inverted-success{color:rgba(var(--v-text-inverted-success, 89, 217, 119, 1))}:host(.v-text-accent1-primary),.v-text-accent1-primary{color:rgba(var(--v-text-accent1-primary, 115, 230, 220, 1))}:host(.v-text-accent2-primary),.v-text-accent2-primary{color:rgba(var(--v-text-accent2-primary, 128, 107, 255, 1))}:host(.v-text-accent3-primary),.v-text-accent3-primary{color:rgba(var(--v-text-accent3-primary, 255, 220, 131, 1))}:host(.v-text-accent4-primary),.v-text-accent4-primary{color:rgba(var(--v-text-accent4-primary, 255, 149, 113, 1))}:host(.v-text-accent5-primary),.v-text-accent5-primary{color:rgba(var(--v-text-accent5-primary, 0, 187, 255, 1))}:host(.v-text-accent6-primary),.v-text-accent6-primary{color:rgba(var(--v-text-accent6-primary, 240, 52, 91, 1))}:host(.v-text-accent7-primary),.v-text-accent7-primary{color:rgba(var(--v-text-accent7-primary, 37, 159, 159, 1))}:host(.v-text-accent8-primary),.v-text-accent8-primary{color:rgba(var(--v-text-accent8-primary, 86, 61, 130, 1))}:host(.v-text-accent9-primary),.v-text-accent9-primary{color:rgba(var(--v-text-accent9-primary, 255, 191, 63, 1))}:host(.v-text-accent10-primary),.v-text-accent10-primary{color:rgba(var(--v-text-accent10-primary, 237, 122, 35, 1))}:host(.v-w-0),.v-w-0{width:0px}:host(.v-w-size-0),.v-w-size-0{width:0px}:host(.v-w-size-4),.v-w-size-4{width:4px}:host(.v-w-size-8),.v-w-size-8{width:8px}:host(.v-w-size-12),.v-w-size-12{width:12px}:host(.v-w-size-16),.v-w-size-16{width:16px}:host(.v-w-size-20),.v-w-size-20{width:20px}:host(.v-w-size-24),.v-w-size-24{width:24px}:host(.v-w-size-32),.v-w-size-32{width:32px}:host(.v-w-size-40),.v-w-size-40{width:40px}:host(.v-w-size-48),.v-w-size-48{width:48px}:host(.v-w-size-64),.v-w-size-64{width:64px}:host(.v-w-size-72),.v-w-size-72{width:72px}:host(.v-w-size-80),.v-w-size-80{width:80px}:host(.v-w-size-112),.v-w-size-112{width:112px}:host(.v-w-size-2),.v-w-size-2{width:2px}:host(.v-h-0),.v-h-0{height:0px}:host(.v-h-size-0),.v-h-size-0{height:0px}:host(.v-h-size-4),.v-h-size-4{height:4px}:host(.v-h-size-8),.v-h-size-8{height:8px}:host(.v-h-size-12),.v-h-size-12{height:12px}:host(.v-h-size-16),.v-h-size-16{height:16px}:host(.v-h-size-20),.v-h-size-20{height:20px}:host(.v-h-size-24),.v-h-size-24{height:24px}:host(.v-h-size-32),.v-h-size-32{height:32px}:host(.v-h-size-40),.v-h-size-40{height:40px}:host(.v-h-size-48),.v-h-size-48{height:48px}:host(.v-h-size-64),.v-h-size-64{height:64px}:host(.v-h-size-72),.v-h-size-72{height:72px}:host(.v-h-size-80),.v-h-size-80{height:80px}:host(.v-h-size-112),.v-h-size-112{height:112px}:host(.v-h-size-2),.v-h-size-2{height:2px}:host{display:inline-flex;user-select:none}i{line-height:1}:host(:not(.vega-auto-size)) ::slotted(svg){width:100%;height:100%}";

var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
    r = Reflect.decorate(decorators, target, key, desc);
  else
    for (var i = decorators.length - 1; i >= 0; i--)
      if (d = decorators[i])
        r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
const VegaIcon = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.globalSlimmers = {};
    this.vegaComponentUsageRuntimeMetricsSlimmer = new componentUsageRuntimeMetrics.VegaComponentUsageRuntimeMetricsSlimmer();
    /**
     * Specifies the width and height of the icon.
     *    For Third Party Icons (e.g., Font Awesome),
     *    it sets the icon's font-size.
     *
     * @vegaVersion 1.0.4
     */
    this.size = 'size-16';
    /**
     * The below method is e2e-test covered in
     * @see {module:console-warn-when-load-fa-lib-timeout}
     */
    /* istanbul ignore next */
    this.cloneFAIconStyles = () => {
      if (this.isThirdPartyIcon(this.icon)) {
        const iconStyleHTML = this.getIconStyleHTML();
        if (iconStyleHTML) {
          this.appendStyles(iconStyleHTML);
        }
        let count = 0;
        const timerId = window.setInterval(() => {
          if (count < 10) {
            count++;
            const iconStyleHTML = this.getIconStyleHTML();
            if (iconStyleHTML) {
              this.appendStyles(iconStyleHTML);
              clearInterval(timerId);
              return;
            }
          }
          else {
            log.LogUtility.warn('[Vega] Loading Font Awesome timeout.', this.icon);
            clearInterval(timerId);
            return;
          }
        }, 300);
      }
    };
  }
  /**
   * The below method is e2e-test covered in
   * @see {module:icon-changed-from-vega-icon-to-fa-icon-class}
   */
  /* istanbul ignore next */
  watchIcon() {
    this.cloneFAIconStyles();
  }
  componentWillLoad() {
    this.cloneFAIconStyles();
  }
  render() {
    const iconFromTokenIndex = icons.Icons.findIndex((icon) => {
      return icon === this.icon;
    });
    if (iconManager.VegaIconManager.hasIcon(this.icon)) {
      const { icon, autoSize } = iconManager.VegaIconManager.getIcon(this.icon);
      const iconSize = autoSize ? null : this.size;
      return this.renderForVegaIconToken(icon, iconSize, autoSize);
    }
    else if (iconFromTokenIndex > -1) {
      return this.renderForVegaIconToken(icons.getIconFromToken(this.icon), this.size);
    }
    else {
      /**
       * The below method is e2e-test covered in
       * @see {module:render-correct-size-with-fa-icon}
       * @see {module:append-fa-icon-styles-to-shadow-dom}
       */
      /* istanbul ignore next */
      return this.renderForThirdPartyIcon();
    }
  }
  /**
   * Verify whether the icon is FA icon or not
   *
   * @param {string} icon - the icon name
   * @returns {boolean} - return true if the icon is FA icon
   */
  isThirdPartyIcon(icon) {
    return !iconManager.VegaIconManager.hasIcon(icon) && !icons.Icons.find((item) => item === icon);
  }
  renderForVegaIconToken(icon, size, isAutoSize = false) {
    const sizeClassName = size ? this.formatAndValidSize(this.size) : null;
    return component.sanitizeVegaComponent(index.h(index.Host, { class: ui.arrayToClassString([
        sizeClassName,
        this.color && designToken.formatAndValidTextColor(this.color),
        isAutoSize && 'vega-auto-size',
      ]), innerHTML: icon }, index.h("slot", null)), this.host);
  }
  /**
   * The below method is e2e-test covered in
   * @see {module:render-correct-size-with-fa-icon}
   * @see {module:append-fa-icon-styles-to-shadow-dom}
   */
  /* istanbul ignore next */
  renderForThirdPartyIcon() {
    return component.sanitizeVegaComponent(index.h(index.Host, { class: ui.arrayToClassString([this.color && designToken.formatAndValidTextColor(this.color)]), style: this.formatThirdPartyIconSize(this.size) }, index.h("i", { part: "icon", class: this.icon })), this.host);
  }
  formatAndValidSize(size) {
    return `v-w-${size} v-h-${size}`;
  }
  /**
   * The below method is e2e-test covered in
   * @see {module:render-correct-size-with-fa-icon}
   */
  /* istanbul ignore next */
  formatThirdPartyIconSize(size) {
    return { 'font-size': `${typeGuard.Spacing[size]}px` };
  }
  /**
   * The below method is e2e-test covered in
   * @see {module:append-fa-icon-styles-to-shadow-dom}
   */
  /* istanbul ignore next */
  appendStyles(iconStyles) {
    var _a;
    if (iconStyles && tryGetDocument.tryGetDocument()) {
      const styleElement = (_a = this.host.shadowRoot.querySelector('#fa-icon-styles')) !== null && _a !== void 0 ? _a : tryGetDocument.tryGetDocument().createElement('style');
      styleElement.id = 'fa-icon-styles';
      styleElement.innerHTML = index$1.htmlSanitizer.sanitize(iconStyles, index$1.styleSanitizeStrategy);
      this.host.shadowRoot.appendChild(styleElement);
    }
  }
  /**
   * The below method is e2e-test covered in
   * @see {module:append-fa-icon-styles-to-shadow-dom}
   */
  /* istanbul ignore next */
  getIconStyleHTML() {
    var _a;
    if (VegaIcon.iconStyleCache.has(this.icon)) {
      return VegaIcon.iconStyleCache.get(this.icon);
    }
    else {
      if (tryGetDocument.tryGetDocument()) {
        const iconElement = tryGetDocument.tryGetDocument().createElement('i');
        iconElement.className = this.icon;
        iconElement.style.display = 'none';
        tryGetDocument.tryGetDocument().body.appendChild(iconElement);
        const computedStyle = getComputedStyle(iconElement);
        // `fontFamily` is null in spec test. Skip it by using '?'
        if ((_a = computedStyle.fontFamily) === null || _a === void 0 ? void 0 : _a.includes('Font Awesome')) {
          const pseudoBeforeElementStyle = getComputedStyle(iconElement, '::before');
          const pseudoAfterElementStyle = getComputedStyle(iconElement, '::after');
          const styleHTML = `
				i {
					font-weight: ${computedStyle.fontWeight};
					font-family: ${computedStyle.fontFamily};
					font-style: ${computedStyle.fontStyle};
					position: ${computedStyle.position};
					letter-spacing: ${computedStyle.letterSpacing};
				}
				i::before {
					content: ${pseudoBeforeElementStyle.content};
					position: ${pseudoBeforeElementStyle.position};
					opacity: ${pseudoBeforeElementStyle.opacity};
				}
				i::after {
					content: ${pseudoAfterElementStyle.content};
					position: ${pseudoAfterElementStyle.position};
					opacity: ${pseudoAfterElementStyle.opacity};
				}
			`.replace(/[\n\t]/gi, '');
          VegaIcon.iconStyleCache.set(this.icon, styleHTML);
          tryGetDocument.tryGetDocument().body.removeChild(iconElement);
          return styleHTML;
        }
        else {
          tryGetDocument.tryGetDocument().body.removeChild(iconElement);
          return null;
        }
      }
    }
  }
  get host() { return index.getElement(this); }
  static get watchers() { return {
    "icon": ["watchIcon"]
  }; }
};
VegaIcon.iconStyleCache = new Map();
__decorate([
  componentUsageRuntimeMetrics.InjectVegaGlobalSlimmer()
], VegaIcon.prototype, "globalSlimmers", void 0);
__decorate([
  injectVegaSlimmer.InjectVegaSlimmer()
], VegaIcon.prototype, "vegaComponentUsageRuntimeMetricsSlimmer", void 0);
VegaIcon.style = vegaIconCss;

exports.vega_icon = VegaIcon;
