'use strict';

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

const index = require('./index-58ea899e.js');
const component = require('./component-1e352960.js');
const globalSlimmerRegistry = require('./global-slimmer-registry-b3bce7e0.js');
const componentUsageRuntimeMetrics = require('./component-usage-runtime-metrics-4572c5b7.js');
const domNodeSubjectObserverFactory = require('./dom-node-subject-observer-factory-9110cb94.js');
const vegaEventId = require('./vega-event-id-c08ce3d3.js');
const number = require('./number-4816603d.js');
const childNodesEventPreventSlimmer = require('./child-nodes-event-prevent-slimmer-9b7095a4.js');
const eventEmitSlimmer = require('./event-emit-slimmer-bcb458b2.js');
const staticSubjectTitle = require('./static-subject-title-5829a298.js');
const changeManager = require('./change-manager-a297e4d2.js');
const keyboardManagerSlimmer = require('./keyboard-manager-slimmer-879ff4f3.js');
const formFieldControllerSlimmer = require('./form-field-controller-slimmer-0f3a028e.js');
const requiredFieldRule = require('./required-field-rule-d73c1d8c.js');
const subStateNotifySlimmer = require('./sub-state-notify-slimmer-b33171b0.js');
const minNumberRule = require('./min-number-rule-dc555309.js');
require('./observer-f49483e8.js');
require('./ui-ae4ee13d.js');
require('./internal-vega-event-manager-fef893bf.js');
require('./vega-env-manager-23b8b23c.js');
require('./feature-flag-controller-9129ef52.js');
require('./index-f054eb5d.js');
require('./dynamic-slimmer-f31fdfd7.js');
require('./try-get-document-c0ebd39a.js');
require('./keyboard-manager-5ed6c472.js');
require('./type-guard-3ec852d7.js');
require('./breakpoints-ebde4837.js');
require('./ui-32120990.js');
require('./typography-4560e7f1.js');
require('./internal-translation-controller-fb1532f4.js');
require('./string-39438062.js');
require('./misc-3d30df91.js');
require('./vega-internal-event-id-87014e4f.js');
require('./index-592b4052.js');
require('./page-resize-observer-slimmer-273d62ef.js');
require('./breakpoints-1cc2c4c6.js');
require('./internal-form-field-validation-rule.abstract-07cdff46.js');
require('./mutation-observer-slimmer-749d5020.js');
require('./mutation-observer-filters-38cebc6d.js');
require('./array-249289f2.js');
require('./sub-state-observer-slimmer-b8f6f27b.js');

var __decorate$3 = (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 VegaInputNumericRenderer extends globalSlimmerRegistry.VegaSlimmer {
  constructor() {
    super(...arguments);
    this.onInputChange = (payload) => {
      this.valueController.updateValue(payload.detail);
    };
    this.onInputBlur = (payload) => {
      const vegaInput = payload.host;
      const normalizedValue = vegaInput.value.replace(/,/g, '');
      if (normalizedValue !== '' && !isNaN(normalizedValue)) {
        let inputValue = number.normalizeNumberByRanger(Number(normalizedValue), this.min, this.max);
        if (this.integerOnly) {
          if (inputValue === this.min) {
            inputValue = Math.ceil(this.min);
          }
          else if (inputValue === this.max) {
            inputValue = Math.floor(this.max);
          }
        }
        if (inputValue !== Number(normalizedValue)) {
          this.valueController.updateValue(inputValue.toString());
        }
      }
    };
  }
  getInputRef() {
    return this.vegaInputRef.shadowRoot.querySelector('input');
  }
  getContainerRef() {
    return this.vegaInputRef.shadowRoot.querySelector('.vega-input-container');
  }
  render() {
    const maskOptions = {
      thousandComma: this.thousandComma,
    };
    if (this.integerOnly) {
      maskOptions.precision = 0;
    }
    return (index.h("vega-input", { value: this.value || '', showClearIcon: this.showClearIcon, disabled: this.disabled, label: this.label, hint: this.hint, required: this.required, type: "number", placeholder: this.placeholder, size: this.size === 'small' ? 'small' : 'default', prefixIcon: this.prefixIcon, ref: (ref) => {
        this.vegaInputRef = ref;
        domNodeSubjectObserverFactory.DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, vegaEventId.VegaChange, (payload) => this.onInputChange(payload));
        domNodeSubjectObserverFactory.DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, vegaEventId.VegaBlur, (payload) => this.onInputBlur(payload));
      }, maskConfig: {
        type: 'number',
        options: maskOptions,
      } }));
  }
}
__decorate$3([
  globalSlimmerRegistry.MapToComponentField()
], VegaInputNumericRenderer.prototype, "prefixIcon", void 0);
__decorate$3([
  globalSlimmerRegistry.MapToComponentField()
], VegaInputNumericRenderer.prototype, "showClearIcon", void 0);
__decorate$3([
  globalSlimmerRegistry.MapToComponentField()
], VegaInputNumericRenderer.prototype, "value", void 0);
__decorate$3([
  globalSlimmerRegistry.MapToComponentField()
], VegaInputNumericRenderer.prototype, "size", void 0);
__decorate$3([
  globalSlimmerRegistry.MapToComponentField()
], VegaInputNumericRenderer.prototype, "disabled", void 0);
__decorate$3([
  globalSlimmerRegistry.MapToComponentField()
], VegaInputNumericRenderer.prototype, "placeholder", void 0);
__decorate$3([
  globalSlimmerRegistry.MapToComponentField()
], VegaInputNumericRenderer.prototype, "label", void 0);
__decorate$3([
  globalSlimmerRegistry.MapToComponentField()
], VegaInputNumericRenderer.prototype, "hint", void 0);
__decorate$3([
  globalSlimmerRegistry.MapToComponentField()
], VegaInputNumericRenderer.prototype, "required", void 0);
__decorate$3([
  globalSlimmerRegistry.MapToComponentField()
], VegaInputNumericRenderer.prototype, "thousandComma", void 0);
__decorate$3([
  globalSlimmerRegistry.MapToComponentField()
], VegaInputNumericRenderer.prototype, "integerOnly", void 0);
__decorate$3([
  globalSlimmerRegistry.MapToComponentField()
], VegaInputNumericRenderer.prototype, "min", void 0);
__decorate$3([
  globalSlimmerRegistry.MapToComponentField()
], VegaInputNumericRenderer.prototype, "max", void 0);
__decorate$3([
  globalSlimmerRegistry.MapToComponentField()
], VegaInputNumericRenderer.prototype, "valueController", void 0);

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;
};
/**
 * Input numeric value controller
 */
class VegaInputNumericValueController extends globalSlimmerRegistry.VegaSlimmer {
  /**
   * The `watchValue` function emits a change event with the current value and notifies the
   * `ChangeManager` about a form element value change.
   */
  watchValue() {
    this.changeEventEmitter.emit(this.value);
    changeManager.ChangeManager.notify(staticSubjectTitle.FORM_ELEMENT_VALUE_CHANGE, {
      host: this.host,
      detail: this.value,
    });
  }
  /**
   * Sets a value based on the input and emits a change event with that value.
   *
   * @param {string} input - input value
   */
  updateValue(input) {
    this.value = input;
  }
}
__decorate$2([
  globalSlimmerRegistry.MapToComponentField()
], VegaInputNumericValueController.prototype, "host", void 0);
__decorate$2([
  globalSlimmerRegistry.MapToComponentField({ writable: true })
], VegaInputNumericValueController.prototype, "value", void 0);
__decorate$2([
  globalSlimmerRegistry.MapToComponentField()
], VegaInputNumericValueController.prototype, "changeEventEmitter", void 0);
__decorate$2([
  globalSlimmerRegistry.MapToComponentMethod('watchValue')
], VegaInputNumericValueController.prototype, "watchValue", 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;
};
/**
 * Input numeric keyboard controller
 */
class VegaInputNumericKeyboardController extends keyboardManagerSlimmer.KeyboardManagerSlimmer {
  constructor() {
    super((target) => {
      return [
        {
          keyCode: ['ArrowUp', 'ArrowDown'],
          activeElementInScope: [target.host],
          // eslint-disable-next-line jsdoc/require-jsdoc
          callback: target.onArrowUpOrDown,
        },
        // Vega-input converts number inputs to text. When using the ArrowUp key in a text input,
        //   the cursor moves to the front. Since the value changes,
        //   vega-input formats the value and moves the cursor to the end, causing flickering.
        //   This behavior is prevented here.
        {
          keyCode: ['ArrowUp'],
          eventName: 'keydown',
          activeElementInScope: [target.host],
          /*
           * The below method is e2e-test covered in
           * @see{module:vega-input-numeric-increment-keyboard-e2e}
           */
          // eslint-disable-next-line jsdoc/require-jsdoc
          callback: /* istanbul ignore next */ (event) => {
            event.preventDefault();
          },
        },
      ];
    });
    /*
     * The below method is e2e-test covered in
     * @see{module:vega-input-numeric-increment-keyboard-e2e}
     */
    /* istanbul ignore next */
    /**
     * Update the value while press ArrowUp or ArrowDown
     *
     * @param {KeyboardEvent} event - keyboard event
     */
    this.onArrowUpOrDown = (event) => {
      const updateValue = event.shiftKey ? this.majorIncrement : this.minorIncrement;
      const value = number.convertToNumber(this.value.replace(/,/g, '')) || 0;
      const decimalCount = Math.max(number.countDecimals(value), number.countDecimals(updateValue));
      if (event.code === 'ArrowUp') {
        this.valueController.updateValue(`${(value + updateValue).toFixed(decimalCount)}`);
      }
      else if (event.code === 'ArrowDown') {
        this.valueController.updateValue(`${(value - updateValue).toFixed(decimalCount)}`);
      }
    };
  }
}
__decorate$1([
  globalSlimmerRegistry.MapToComponentField()
], VegaInputNumericKeyboardController.prototype, "host", void 0);
__decorate$1([
  globalSlimmerRegistry.MapToComponentField()
], VegaInputNumericKeyboardController.prototype, "value", void 0);
__decorate$1([
  globalSlimmerRegistry.MapToComponentField()
], VegaInputNumericKeyboardController.prototype, "minorIncrement", void 0);
__decorate$1([
  globalSlimmerRegistry.MapToComponentField()
], VegaInputNumericKeyboardController.prototype, "majorIncrement", void 0);
__decorate$1([
  globalSlimmerRegistry.MapToComponentField()
], VegaInputNumericKeyboardController.prototype, "valueController", void 0);

const vegaInputNumericCss = ":host{display:inline-block;width: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 VegaInputNumeric = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.vegaChange = index.createEvent(this, "vegaChange", 7);
    this.change = index.createEvent(this, "change", 7);
    this.globalSlimmers = {};
    this.valueController = new VegaInputNumericValueController();
    this.keyboardController = new VegaInputNumericKeyboardController();
    this.renderer = new VegaInputNumericRenderer();
    this.changeEventEmitter = eventEmitSlimmer.createEventEmitSlimmer(VegaInputNumeric, vegaEventId.VegaChange);
    this.inputEventPrevent = new childNodesEventPreventSlimmer.ChildNodesEventPreventSlimmer([vegaEventId.VegaChange], () => this.host, { useCapture: true });
    this.formFieldController = new formFieldControllerSlimmer.FormFieldControllerSlimmer({
      propertyRules: [
        {
          propertyName: 'required',
          ruleFactory: (isRequired) => (isRequired ? new requiredFieldRule.RequiredFieldRule() : null),
        },
        {
          propertyName: 'min',
          ruleFactory: (min) => typeof min === 'number' ? new minNumberRule.MinNumberRule({ minValue: min }) : null,
        },
        {
          propertyName: 'max',
          ruleFactory: (max) => typeof max === 'number' ? new minNumberRule.MaxNumberRule({ maxValue: max }) : null,
        },
      ],
      validationRulesName: 'validationRules',
      inputContainerGetter: () => this.renderer.getContainerRef(),
      touchableAreaGetter: () => [this.renderer.getInputRef()],
      defaultValue: '',
      attributeGetter: (propertyName) => this[propertyName],
    });
    this.prefixTextNotifySlimmer = subStateNotifySlimmer.createSubStateNotifySlimmer(VegaInputNumeric, 'prefixText', 'watchPrefixText');
    this.suffixTextNotifySlimmer = subStateNotifySlimmer.createSubStateNotifySlimmer(VegaInputNumeric, 'suffixText', 'watchSuffixText');
    this.isCompactInputWidthNotifySlimmer = subStateNotifySlimmer.createSubStateNotifySlimmer(VegaInputNumeric, 'isCompactInputWidth');
    this.vegaComponentUsageRuntimeMetricsSlimmer = new componentUsageRuntimeMetrics.VegaComponentUsageRuntimeMetricsSlimmer();
    this.isCompactInputWidth = true;
    /**
     * Text displayed before (to the left of) the numeric value inside the input
     * field. Use this to provide contextual information such as a currency
     * symbol (e.g., `'$'`) or unit prefix.
     *
     * @default ''
     * @vegaVersion 2.29.0
     */
    this.prefixText = '';
    /**
     * The current value of the numeric input field, represented as a string.
     *
     * This property is mutable and will be updated when the user types or uses
     * keyboard increment/decrement actions. It can also be set externally to
     * pre-populate or reset the field. When `thousandComma` is enabled, the
     * display is formatted with separators but the underlying value remains
     * unformatted. Changes to this property trigger the `vegaChange` event.
     *
     * @default ''
     * @vegaVersion 2.29.0
     */
    /* eslint-disable-next-line @stencil/strict-mutable */
    this.value = '';
    /**
     * Controls the visual size of the numeric input field.
     *
     * - `'medium'` — Standard height, suitable for most form layouts.
     * - `'small'` — Compact height, useful for dense UIs or inline editing.
     *
     * @default 'medium'
     * @vegaVersion 2.29.0
     */
    this.size = 'medium';
    /**
     * When `true`, the numeric input automatically formats the displayed value
     * with thousand separators (commas) as the user types (e.g., `1,000,000`).
     * The underlying `value` property remains an unformatted numeric string.
     *
     * @default false
     * @vegaVersion 2.29.0
     */
    this.thousandComma = false;
    /**
     * When `true`, restricts user input to whole numbers only — decimal points
     * and fractional digits are rejected. Useful for fields like quantity,
     * count, or age.
     *
     * @default false
     * @vegaVersion 2.29.0
     */
    this.integerOnly = false;
    /**
     * Specifies whether the numeric input field is disabled. When `true`, the
     * field is non-interactive — the user cannot type, focus, or use keyboard
     * controls to change the value.
     *
     * @default false
     * @vegaVersion 2.29.0
     */
    this.disabled = false;
    /**
     * The step value used when the user presses the `ArrowUp` or `ArrowDown`
     * key to increment or decrement the value. This controls fine-grained
     * adjustments to the numeric input.
     *
     * For larger jumps, see `majorIncrement` (activated with `Shift` + arrow
     * keys).
     *
     * @default 1
     * @vegaVersion 2.29.0
     */
    this.minorIncrement = 1;
    /**
     * The step value used when the user presses `Shift` + `ArrowUp` or
     * `Shift` + `ArrowDown` to increment or decrement the value by a larger
     * amount. This enables quick coarse-grained adjustments.
     *
     * For smaller steps, see `minorIncrement`.
     *
     * @default 10
     * @vegaVersion 2.29.0
     */
    this.majorIncrement = 10;
    /**
     * Specifies the visible label text rendered above the numeric input.
     * The label identifies the purpose of the field and serves as the
     * accessible name for screen readers.
     *
     * @default ''
     * @vegaVersion 2.29.0
     */
    this.label = '';
    /**
     * An array of custom validation rules applied to the numeric input in
     * addition to the built-in rules (`RequiredFieldRule`, `MinNumberRule`,
     * `MaxNumberRule`). Each rule must implement the `FormFieldValidationRule`
     * interface.
     *
     * Rules are evaluated in order when `autoValidation` is enabled or when
     * validation is triggered programmatically.
     *
     * @default []
     * @vegaVersion 2.29.0
     */
    this.validationRules = [];
    /**
     * Reflects the current validation status of the numeric input.
     *
     * - `true` — the field value passes all validation rules.
     * - `false` — one or more validation rules have failed.
     * - `null` — the field has not been validated yet (initial state).
     *
     * This property is mutable: it is updated automatically when
     * `autoValidation` is enabled, but can also be set manually to override
     * the validation state.
     *
     * @default null
     * @vegaVersion 2.29.0
     */
    /* eslint-disable-next-line @stencil/strict-mutable */
    this.isValid = null;
    /**
     * Determines whether the numeric input should be validated automatically as
     * the user interacts with it. When `true`, validation rules (including
     * `required`, `min`, `max`, and custom `validationRules`) are evaluated
     * and the `isValid` property is updated accordingly.
     *
     * Set to `false` to handle validation manually.
     *
     * @default true
     * @vegaVersion 2.29.0
     */
    this.autoValidation = true;
    /**
     * Controls whether a clear (×) icon button is shown inside the input field
     * when a value is present. Clicking the button resets the value to an empty
     * string and triggers the `vegaChange` event.
     *
     * @default true
     * @vegaVersion 2.53.0
     */
    this.showClearIcon = true;
    /**
     * Sets the minimum allowable value for the numeric input. When set, the
     * built-in `MinNumberRule` is applied during validation. Values below this
     * threshold will cause validation to fail.
     *
     * Set to `null` to remove the lower bound.
     *
     * @default null
     * @vegaVersion 2.63.0
     */
    this.min = null;
    /**
     * Sets the maximum allowable value for the numeric input. When set, the
     * built-in `MaxNumberRule` is applied during validation. Values above this
     * threshold will cause validation to fail.
     *
     * Set to `null` to remove the upper bound.
     *
     * @default null
     * @vegaVersion 2.63.0
     */
    this.max = null;
  }
  watchPrefixText() {
  }
  watchSuffixText() {
  }
  watchValue() {
  }
  watchValidationRules() {
  }
  render() {
    return component.sanitizeVegaComponent(index.h(index.Host, null, this.renderer.render()), this.host);
  }
  get host() { return index.getElement(this); }
  static get watchers() { return {
    "prefixText": ["watchPrefixText"],
    "suffixText": ["watchSuffixText"],
    "value": ["watchValue"],
    "validationRules": ["watchValidationRules"]
  }; }
};
__decorate([
  componentUsageRuntimeMetrics.InjectVegaGlobalSlimmer()
], VegaInputNumeric.prototype, "globalSlimmers", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaInputNumeric.prototype, "valueController", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaInputNumeric.prototype, "keyboardController", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaInputNumeric.prototype, "renderer", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaInputNumeric.prototype, "changeEventEmitter", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaInputNumeric.prototype, "inputEventPrevent", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaInputNumeric.prototype, "formFieldController", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaInputNumeric.prototype, "prefixTextNotifySlimmer", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaInputNumeric.prototype, "suffixTextNotifySlimmer", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaInputNumeric.prototype, "isCompactInputWidthNotifySlimmer", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaInputNumeric.prototype, "vegaComponentUsageRuntimeMetricsSlimmer", void 0);
VegaInputNumeric.style = vegaInputNumericCss;

exports.vega_input_numeric = VegaInputNumeric;
