import { F as FeatureFlag } from './feature-flag-controller-30f7b625.js';
import { V as VegaLoader, a as VegaNotify, b as VegaEventManager, c as VegaZIndexManager, w as waitForVega, d as VegaSkeletonLoader, e as VegaTranslation, f as VegaRTETokenExtension, g as VegaRTELanguageExtension, h as VegaRTEFunctionExtension, i as VegaRTETableExtension } from './token-extension-3c07558d.js';
import { V as VegaThemeManager } from './split-cell-operation-8045ac1d.js';
import { M as MapToComponentMethod, V as VegaSlimmer, s as setVegaLogLevel, G as GlobalSlimmersRegistry } from './global-slimmer-registry-17c4efd4.js';
import { V as VegaDialog } from './vega-dialog-controller-bbb2fc52.js';
import { T as TypographyUrls } from './typography-396de03f.js';
import { V as VegaIconManager } from './icon-manager-539d7cf7.js';
import { V as VegaInternalTranslation, s as staticTranslations } from './internal-translation-controller-d7dee4a0.js';
import { V as ValidCreditCardNumberRule } from './valid-credit-card-number-rule-a826dd49.js';
import { v as vegaEnvManager } from './vega-env-manager-8f8dc473.js';
import { U as UPDATE_TRANSLATION } from './static-subject-title-52f93124.js';
import { C as ChangeManager } from './change-manager-6a7eb88c.js';
import { O as Observer } from './observer-3959f9dd.js';
import { f as forceUpdate } from './index-090d31ca.js';
import { V as VegaRTEContent } from './content-state-b3d319b4.js';
import { v as vegaNonceManager, s as setVegaNonce } from './vega-nonce-manager-497e5eb5.js';
import { V as VegaRTEPresetToolbarItems } from './code-block-3af53bbb.js';

var __decorate$2 = (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;
};
/**
 * The `VegaWatchMethodCancelSlimmer` class is a TypeScript class that removes
 * the body of watch methods when a component is not fully instantiated and
 * applies the original method body when the component is fully instantiated.
 */
class VegaWatchMethodCancelSlimmer extends VegaSlimmer {
  /**
   * The constructor function takes a component object as a parameter and assigns it to the "component"
   * property of the class.
   *
   * @param {GlobalSlimmerConfig} option - The `option` parameter is of type `GlobalSlimmerConfig`.
   * It is an object that represents a component in a software system.
   */
  constructor(option) {
    super();
    this.originalWatchers = new Map();
    /**
     * while component reattached, the component will call `connectedCallback` but not call `componentDidLoad`,
     * so we add this flag to skip empty the watch function in this case.
     */
    this.hasDisconnected = false;
    this.isEnabled = FeatureFlag.isEnabled('VEGA_REACT.PREVENT_CALL_WATCH_METHOD_BEFORE_COMPONENT_LOAD') &&
      FeatureFlag.isEnabled('VEGA_FRAMEWORK.PREVENT_CALL_WATCH_METHOD_BEFORE_COMPONENT_LOAD');
    this.component = option.component;
  }
  /**
   * The connectedCallback function removes the body of watch methods when the component is not fully
   * instantiated.
   */
  connectedCallback() {
    if (!this.isEnabled)
      return;
    if (this.hasDisconnected)
      return;
    const watchers = this.component.constructor['watchers'];
    for (const propName in watchers) {
      const watchMethodNames = watchers[propName];
      watchMethodNames.forEach((methodName) => {
        // while watch method listen by multiple property, we should skip make originalMethod as empty.
        if (!this.originalWatchers.has(methodName)) {
          const originalMethod = this.component[methodName];
          this.originalWatchers.set(methodName, originalMethod);
          /**
           * Remove the watch method body when the component not fully instantiated.
           */
          // eslint-disable-next-line @typescript-eslint/no-empty-function
          this.component[methodName] = function () { };
        }
      });
    }
  }
  /**
   * The `@MapToComponentMethod('disconnectedCallback')` decorator is used to map the `disconnectedCallback` method
   * to the corresponding method in the Stencil component.
   */
  disconnectedCallback() {
    if (!this.isEnabled)
      return;
    this.hasDisconnected = true;
  }
  /**
   * The `componentDidLoad` function applies the original method body to the component's watchers when
   * the component is fully instantiated.
   */
  componentDidLoad() {
    if (!this.isEnabled)
      return;
    this.originalWatchers.forEach((method, methodName) => {
      const originalMethodBody = method;
      /**
       * Apply the watch original method body when the component fully instantiated.
       *
       * @param {...any} args - watch method args
       * @returns {unknown} method results
       */
      this.component[methodName] = function (...args) {
        return originalMethodBody.apply(this, args);
      };
    });
  }
}
__decorate$2([
  MapToComponentMethod('connectedCallback')
], VegaWatchMethodCancelSlimmer.prototype, "connectedCallback", null);
__decorate$2([
  MapToComponentMethod('disconnectedCallback')
], VegaWatchMethodCancelSlimmer.prototype, "disconnectedCallback", null);
__decorate$2([
  MapToComponentMethod('componentDidLoad')
], VegaWatchMethodCancelSlimmer.prototype, "componentDidLoad", null);

var __decorate$1 = (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;
};
/**
 * Class responsible for observing translation updates and triggering re-renders.
 */
class VegaTranslateObserverSlimmer extends VegaSlimmer {
  constructor(option) {
    super();
    this.component = option.component;
  }
  /**
   * Component lifecycle - [connectedCallback]
   * Registers an observer to watch for translation updates, which triggers a forced update on the component.
   */
  connectedCallback() {
    this.observer = new Observer(this.isAcceptable.bind(this), () => {
      forceUpdate(this.component);
    });
    ChangeManager.register(UPDATE_TRANSLATION, this.observer);
  }
  /**
   * Component lifecycle - [disconnectedCallback]
   * Unregister the observer when the component is disconnected from the DOM.
   */
  disconnectedCallback() {
    if (this.observer) {
      ChangeManager.unregister(UPDATE_TRANSLATION, this.observer);
      this.observer = null;
    }
  }
  /**
   * Determines whether the observer should accept changes.
   *
   * @returns {boolean} Always returns true in the current implementation.
   */
  isAcceptable() {
    var _a, _b;
    const host = this.component['host'];
    return (_b = (_a = VegaInternalTranslation.getConnectedComponents().get(host.tagName)) === null || _a === void 0 ? void 0 : _a.has(host)) !== null && _b !== void 0 ? _b : false;
  }
}
__decorate$1([
  MapToComponentMethod('connectedCallback')
], VegaTranslateObserverSlimmer.prototype, "connectedCallback", null);
__decorate$1([
  MapToComponentMethod('disconnectedCallback')
], VegaTranslateObserverSlimmer.prototype, "disconnectedCallback", null);

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;
};
/**
 * Class responsible for injecting nonce into inline style attributes for vega components.
 */
class VegaNonceInjectorSlimmer extends VegaSlimmer {
  constructor(option) {
    super();
    this.component = option.component;
  }
  /**
   * Component lifecycle - [connectedCallback]
   * Registers an observer to watch for translation updates, which triggers a forced update on the component.
   */
  /**
   * Lifecycle callback that is invoked when the custom element is added to the DOM.
   *
   * This implementation overrides the `insertBefore` method of the element's shadow root
   * to automatically set the `nonce` attribute on any inline `<style>` elements that are inserted.
   * This is typically used to support Content Security Policy (CSP) by ensuring that dynamically
   * injected styles have the correct nonce value.
   */
  connectedCallback() {
    const shadowRoot = this.component['host'].shadowRoot;
    // override element#insertBefore to set nonce attribute for inline style element
    const originalInsertBefore = shadowRoot.insertBefore;
    /**
     * Overrides the shadowRoot's insertBefore method to inject a CSP nonce into any STYLE element being inserted.
     *
     * @template T - The type of Node being inserted.
     * @param {T} newElement - The new node to insert.
     * @param {Node | null} referenceElement - The node before which newElement is inserted, or null to insert at the end.
     * @returns {T} The inserted node.
     */
    shadowRoot.insertBefore = function (newElement, referenceElement) {
      if (newElement.nodeName === 'STYLE') {
        const nonce = vegaNonceManager.nonce;
        if (nonce !== undefined) {
          newElement.setAttribute('nonce', nonce);
        }
      }
      return originalInsertBefore.call(this, newElement, referenceElement);
    };
  }
}
__decorate([
  MapToComponentMethod('connectedCallback')
], VegaNonceInjectorSlimmer.prototype, "connectedCallback", null);

/**
 * Default export function that will be used by stencil global script,
 * which will be invoked before library loaded.
 */
function appGlobalScript () {
  disableFeatureFlagFromClientGlobal();
  enableFeatureFlagFromClientGlobal();
  injectVegaLoaderIntoGlobal();
  injectVegaNotifyIntoGlobal();
  injectVegaThemeManagerIntoGlobal();
  injectVegaLogLevelIntoGlobal();
  injectVegaDialogIntoGlobal();
  registerGlobalVegaSlimmers();
  injectSetEventSemanticsIntoGlobal();
  injectVegaTypography();
  injectVegaIconManager();
  injectVegaZIndexManagerIntoGlobal();
  injectValidCreditCardNumberRuleIntoGlobal();
  initRuntimeMetricsTelemetryCollection();
  injectWaitForVegaIntoGlobal();
  injectVegaSkeletonLoaderIntoGlobal();
  injectVegaTranslationIntoGlobal();
  injectVegaRichTextEditorClassIntoGlobal();
  injectVegaPublicValidationRules();
  applyBrandingFromClientGlobal();
  injectSetNonceIntoGlobal();
  patchHeadInsertBeforeWithNonce();
}
/**
 * Disable feature flags from the client global defined lists.
 */
function disableFeatureFlagFromClientGlobal() {
  if (globalThis['VegaDisabledFeatureKeys']) {
    FeatureFlag.disable(...globalThis['VegaDisabledFeatureKeys']);
  }
}
/**
 * This function enables feature flags based on a global variable in TypeScript.
 */
function enableFeatureFlagFromClientGlobal() {
  if (globalThis['VegaEnabledFeatureKeys']) {
    FeatureFlag.enable(...globalThis['VegaEnabledFeatureKeys']);
  }
}
/**
 * Inject VegaLoader to global as a public api
 */
function injectVegaLoaderIntoGlobal() {
  globalThis['VegaLoader'] = VegaLoader;
}
/**
 * Inject VegaNotify to global as a public api
 */
function injectVegaNotifyIntoGlobal() {
  globalThis.VegaNotify = VegaNotify;
}
/**
 * Inject VegaThemeManager to global as a public api
 */
function injectVegaThemeManagerIntoGlobal() {
  globalThis.VegaThemeManager = VegaThemeManager;
}
/**
 * Inject VegaLogLevel to global as a public api
 */
function injectVegaLogLevelIntoGlobal() {
  globalThis.setVegaLogLevel = setVegaLogLevel;
}
/**
 * Inject VegaDialog to global as a public api
 */
function injectVegaDialogIntoGlobal() {
  globalThis.VegaDialog = VegaDialog;
}
/**
 * register global vega slimmers
 */
function registerGlobalVegaSlimmers() {
  GlobalSlimmersRegistry.register([
    VegaWatchMethodCancelSlimmer,
    VegaTranslateObserverSlimmer,
    VegaNonceInjectorSlimmer,
  ]);
}
/**
 * Inject setEventSemantics to global as a public api
 */
function injectSetEventSemanticsIntoGlobal() {
  globalThis.VegaEventManager = VegaEventManager;
}
/**
 * Inject Vega typography stylesheet
 */
function injectVegaTypography() {
  Object.keys(TypographyUrls).forEach((key) => {
    const { url } = TypographyUrls[key];
    const typographyLinkId = `vega-typography-${key}`;
    // eslint-disable-next-line no-restricted-globals
    if (!document.querySelector(`#${typographyLinkId}`)) {
      // eslint-disable-next-line no-restricted-globals
      const typographyLink = document.createElement('link');
      typographyLink.id = typographyLinkId;
      typographyLink.href = url;
      typographyLink.rel = 'stylesheet';
      // eslint-disable-next-line no-restricted-globals
      document.head.append(typographyLink);
    }
  });
}
/**
 * Inject VegaIconManager to global as a public api
 */
function injectVegaIconManager() {
  globalThis.VegaIconManager = VegaIconManager;
}
/**
 * Inject VegaZIndexManager to global as a public api
 */
function injectVegaZIndexManagerIntoGlobal() {
  globalThis.VegaZIndexManager = VegaZIndexManager;
}
/**
 * Inject ValidCreditCardNumberRule to global as a public api.
 */
function injectValidCreditCardNumberRuleIntoGlobal() {
  globalThis.ValidCreditCardNumberRule = ValidCreditCardNumberRule;
}
/**
 * init telemetry runtime metrics.
 * 1. Inject VegaEnvInfo to global
 * 2. Register runtime metrics add page hide listener method
 */
function initRuntimeMetricsTelemetryCollection() {
  globalThis.VegaEnvInfo = vegaEnvManager.getVegaEnv();
  // eslint-disable-next-line spellcheck/spell-checker
  void import('./index-bfc6dfa2.js').then((
  // eslint-disable-next-line spellcheck/spell-checker
  module) => {
    module['default']['init'](FeatureFlag);
  });
}
/**
 * Inject waitForVega to global as a public api
 */
function injectWaitForVegaIntoGlobal() {
  globalThis['waitForVega'] = waitForVega;
}
/**
 * Inject VegaSkeletonLoader to global as a public api
 */
function injectVegaSkeletonLoaderIntoGlobal() {
  globalThis.VegaSkeletonLoader = VegaSkeletonLoader;
}
/**
 * Inject VegaTranslation to global as a public api
 */
function injectVegaTranslationIntoGlobal() {
  globalThis.VegaTranslation = VegaTranslation;
  globalThis.VegaTranslationResourceEN = staticTranslations;
}
/**
 * Inject VegaRTEContent to global as a public api
 * Inject VegaRTETokenExtension to global as a public api
 * Inject VegaRTELanguageExtension to global as a public api
 * Inject VegaRTEPresetToolbarItems to global as a variable
 */
function injectVegaRichTextEditorClassIntoGlobal() {
  globalThis.VegaRTEContent = VegaRTEContent;
  globalThis.VegaRTETokenExtension = VegaRTETokenExtension;
  globalThis.VegaRTELanguageExtension = VegaRTELanguageExtension;
  globalThis.VegaRTEPresetToolbarItems = VegaRTEPresetToolbarItems;
  globalThis.VegaRTEFunctionExtension = VegaRTEFunctionExtension;
  globalThis.VegaRTETableExtension = VegaRTETableExtension;
}
/**
 * Inject VegaPublicValidationRules to global as a public api
 */
function injectVegaPublicValidationRules() {
  void import('./public-rules-ae0099c8.js').then((module) => {
    Object.entries(module).forEach(([name, value]) => {
      globalThis[name] = value;
    });
  });
}
/**
 * Switch the Vega theme to a new brand theme from the client global defined options.
 */
function applyBrandingFromClientGlobal() {
  if (globalThis['VegaThemeManagerApplyBranding']) {
    VegaThemeManager.applyBranding(globalThis['VegaThemeManagerApplyBranding']);
  }
}
/**
 * Injects the `setVegaNonce` function into the global scope as `setVegaNonce`.
 */
function injectSetNonceIntoGlobal() {
  globalThis.setVegaNonce = setVegaNonce;
}
/**
 * Patch document.head.insertBefore to ensure nonce is set on injected elements.
 */
function patchHeadInsertBeforeWithNonce() {
  vegaNonceManager.patchHeadInsertBeforeWithNonceToStencil();
}

const globalScripts = appGlobalScript;

export { globalScripts as g };
