numora 3.5.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { FormatOn, ThousandStyle } from './types';
2
- export interface NumoraInputOptions extends Partial<Omit<HTMLInputElement, 'value' | 'defaultValue' | 'onChange'>> {
2
+ export interface NumoraInputOptions extends Partial<Omit<HTMLInputElement, 'value' | 'defaultValue' | 'onChange' | 'maxLength'>> {
3
3
  formatOn?: FormatOn;
4
4
  thousandSeparator?: string;
5
5
  thousandStyle?: ThousandStyle;
@@ -10,7 +10,12 @@ export interface NumoraInputOptions extends Partial<Omit<HTMLInputElement, 'valu
10
10
  enableCompactNotation?: boolean;
11
11
  enableNegative?: boolean;
12
12
  enableLeadingZeros?: boolean;
13
+ autoAddLeadingZero?: boolean;
13
14
  rawValueMode?: boolean;
15
+ /** Max raw length (digits + decimal sep + leading `-`). Separators not counted. */
16
+ maxLength?: number;
17
+ /** Reject keystroke/paste if this returns false. Called with post-sanitization raw value. */
18
+ isAllowed?: (rawValue: string) => boolean;
14
19
  onChange?: (value: string) => void;
15
20
  value?: string;
16
21
  defaultValue?: string;
@@ -19,22 +24,43 @@ export declare class NumoraInput {
19
24
  private element;
20
25
  private resolvedOptions;
21
26
  private rawValue;
27
+ private suppressNextInputEvent;
28
+ private pendingMouseStrip;
22
29
  private caretPositionBeforeChange?;
23
- constructor(container: HTMLElement, { decimalMaxLength, decimalMinLength, formatOn, thousandSeparator, thousandStyle, decimalSeparator, locale, enableCompactNotation, enableNegative, enableLeadingZeros, rawValueMode, onChange, ...rest }: NumoraInputOptions);
30
+ constructor(container: HTMLElement, options: NumoraInputOptions);
31
+ private toRaw;
32
+ private setDefaultValue;
24
33
  private createInputElement;
25
34
  private setupEventListeners;
26
- private getResolvedOptions;
27
- private buildFormattingOptions;
35
+ /**
36
+ * Runs `fn` with `suppressNextInputEvent` set so the synchronous `input` event fired
37
+ * by `setRangeText` is short-circuited in `handleChange`. Exactly one set/clear pair
38
+ * per write; try/finally guarantees the flag clears even if `fn` throws.
39
+ */
40
+ private withInternalWrite;
28
41
  private handleValueChange;
29
- private formatValueForDisplay;
42
+ private applyDisplaySeparators;
30
43
  private handleBeforeInput;
31
44
  private handleChange;
32
45
  private handleKeyDown;
33
46
  private handlePaste;
47
+ private stripSeparatorsAndMapCaret;
34
48
  private handleFocus;
49
+ private handleMouseDown;
50
+ private handleClick;
35
51
  private handleBlur;
36
52
  getValue(): string;
37
- setValue(value: string): void;
53
+ /**
54
+ * Sets the input's value programmatically.
55
+ *
56
+ * @param value - The new value. In `rawValueMode`, this is treated as raw and re-formatted for display.
57
+ * @param options.undoable - Defaults to `true`: routes the write through `setRangeText`
58
+ * so the browser's undo stack stays intact and `Ctrl+Z` can revert this call. Pass
59
+ * `false` only when you intentionally want to wipe the undo history (e.g. form reset).
60
+ */
61
+ setValue(value: string, options?: {
62
+ undoable?: boolean;
63
+ }): void;
38
64
  disable(): void;
39
65
  enable(): void;
40
66
  addEventListener(event: string, callback: EventListenerOrEventListenerObject): void;
@@ -59,6 +85,12 @@ export declare class NumoraInput {
59
85
  /**
60
86
  * Gets the value as a number, similar to HTMLInputElement.valueAsNumber.
61
87
  * Returns NaN if the value cannot be converted to a number.
88
+ *
89
+ * **Precision warning**: this getter returns a JavaScript `number` (IEEE 754 double).
90
+ * Values beyond ~15 significant digits will lose precision. Numora is designed around
91
+ * string values for this reason - prefer {@link getValue} when exact precision matters.
92
+ * Treat `valueAsNumber` strictly as an escape hatch for arithmetic that you already know
93
+ * is safe at float precision.
62
94
  */
63
95
  get valueAsNumber(): number;
64
96
  /**
package/dist/config.d.ts CHANGED
@@ -8,4 +8,5 @@ export declare const DEFAULT_DECIMAL_SEPARATOR = ".";
8
8
  export declare const DEFAULT_ENABLE_COMPACT_NOTATION = false;
9
9
  export declare const DEFAULT_ENABLE_NEGATIVE = false;
10
10
  export declare const DEFAULT_ENABLE_LEADING_ZEROS = false;
11
+ export declare const DEFAULT_AUTO_ADD_LEADING_ZERO = false;
11
12
  export declare const DEFAULT_RAW_VALUE_MODE = false;
@@ -3,10 +3,6 @@ import type { SeparatorOptions, Separators, FormattingOptions } from '@/types';
3
3
  * Normalizes separator configuration with defaults.
4
4
  */
5
5
  export declare function getSeparators(options: SeparatorOptions | FormattingOptions | undefined): Separators;
6
- /**
7
- * Handles keyboard events for decimal separators, converting comma/dot and preventing duplicates.
8
- */
9
- export declare function handleDecimalSeparatorKey(e: KeyboardEvent, inputElement: HTMLInputElement, decimalSeparator: string): boolean;
10
6
  /**
11
7
  * Trims decimals to a maximum length.
12
8
  */
@@ -1,36 +1,36 @@
1
1
  /**
2
- * Utility functions for setting and managing caret position.
3
- * Includes mobile browser workarounds and retry mechanisms.
2
+ * Pure caret-position math: where the caret should land after a value change, and
3
+ * helpers for the focus-strip path. DOM writes live in `./dom-writes.ts`.
4
4
  */
5
5
  import type { FormattingOptions, CaretPositionInfo, Separators } from '@/types';
6
6
  /**
7
- * Sets the caret position in an input element.
8
- * Includes workaround for Chrome/Safari mobile browser bugs.
9
- *
10
- * @param el - The input element
11
- * @param caretPos - The desired caret position
12
- * @returns True if successful, false otherwise
7
+ * Result of computing a focus-strip: the raw value with separators removed and the
8
+ * caret positions mapped from the formatted display indices to the raw indices.
13
9
  */
14
- export declare function setCaretPosition(el: HTMLInputElement, caretPos: number): boolean;
10
+ export interface StripSeparatorsResult {
11
+ raw: string;
12
+ rawStart: number;
13
+ rawEnd: number;
14
+ }
15
15
  /**
16
- * Sets caret position with retry mechanism for mobile browsers.
17
- * Mobile Chrome sometimes resets the caret position after we set it,
18
- * so we retry after a short timeout.
16
+ * Pure compute for the focus-strip path: takes the current formatted value plus the
17
+ * user's display caret/selection, returns the stripped value and the equivalent caret
18
+ * positions in the raw value. Returns `null` when no strip is needed (the value already
19
+ * contains no separators).
19
20
  *
20
- * @param el - The input element
21
- * @param caretPos - The desired caret position
22
- * @param currentValue - The current input value (for validation)
23
- * @returns Timeout ID that can be cleared if needed
24
- */
25
- export declare function setCaretPositionWithRetry(el: HTMLInputElement, caretPos: number, currentValue: string): ReturnType<typeof setTimeout> | null;
26
- /**
27
- * Gets the current caret position from an input element.
28
- * Uses max of selectionStart and selectionEnd to handle mobile browser quirks.
21
+ * The mapping rule: the new caret index equals the count of non-separator characters
22
+ * in the formatted prefix up to the display caret. The transformation is bijective on
23
+ * digits, so this exactly preserves which digit the user clicked on.
29
24
  *
30
- * @param el - The input element
31
- * @returns The current caret position
25
+ * Does NOT mutate the DOM. Callers own the write and any internal-write/broadcast wrapping.
26
+ *
27
+ * @param currentValue - The current (formatted) input value
28
+ * @param displayStart - selectionStart in the formatted value
29
+ * @param displayEnd - selectionEnd in the formatted value
30
+ * @param separator - The thousand separator character to strip
31
+ * @returns Strip result, or null if no separators present
32
32
  */
33
- export declare function getInputCaretPosition(el: HTMLInputElement): number;
33
+ export declare function computeStripSeparatorsResult(currentValue: string, displayStart: number, displayEnd: number, separator: string): StripSeparatorsResult | null;
34
34
  /**
35
35
  * Skips cursor over thousand separator when deleting/backspacing in 'change' mode.
36
36
  * This prevents the cursor from stopping on the separator, making deletion smoother.
@@ -41,14 +41,8 @@ export declare function getInputCaretPosition(el: HTMLInputElement): number;
41
41
  */
42
42
  export declare function skipOverThousandSeparatorOnDelete(e: KeyboardEvent, inputElement: HTMLInputElement, formattingOptions?: FormattingOptions): void;
43
43
  /**
44
- * Updates cursor position after value changes, handling both formatted and unformatted values.
45
- *
46
- * @param target - The input element
47
- * @param oldValue - The value before the change
48
- * @param newValue - The value after the change
49
- * @param oldCursorPosition - The cursor position before the change
50
- * @param caretPositionBeforeChange - Optional caret position info from keydown handler
51
- * @param separators - Separator configuration
52
- * @param formattingOptions - Optional formatting options
44
+ * Pure compute version of cursor-position resolution. Returns the cursor position the
45
+ * caret should land at after a value change, or null when the inputs don't provide enough
46
+ * signal to compute one. Does NOT mutate the DOM. Callers own the setSelectionRange call.
53
47
  */
54
- export declare function updateCursorPosition(target: HTMLInputElement, oldValue: string, newValue: string, oldCursorPosition: number, caretPositionBeforeChange: CaretPositionInfo | undefined, separators: Separators, formattingOptions?: FormattingOptions): void;
48
+ export declare function computeCursorPosition(oldValue: string, newValue: string, oldCursorPosition: number, caretPositionBeforeChange: CaretPositionInfo | undefined, separators: Separators, formattingOptions?: FormattingOptions): number | null;
@@ -50,14 +50,13 @@ import { ThousandStyle } from '@/types';
50
50
  * Type for character equivalence checking.
51
51
  * Returns true if two characters should be considered equivalent for cursor mapping.
52
52
  */
53
- export type IsCharacterEquivalent = (char1: string, char2: string, context: {
53
+ type IsCharacterEquivalent = (char1: string, char2: string, context: {
54
54
  oldValue: string;
55
55
  newValue: string;
56
56
  typedRange?: ChangeRange;
57
57
  oldIndex: number;
58
58
  newIndex: number;
59
59
  }) => boolean;
60
- export declare const defaultIsCharacterEquivalent: IsCharacterEquivalent;
61
60
  /**
62
61
  * Options for cursor position calculation.
63
62
  */
@@ -91,3 +90,4 @@ export interface CursorPositionOptions {
91
90
  * // Returns: 5 (cursor after last zero)
92
91
  */
93
92
  export declare function calculateCursorPositionAfterFormatting(oldFormattedValue: string, newFormattedValue: string, oldCursorPosition: number, separator: string, _groupStyle: ThousandStyle, changeRange?: ChangeRange, decimalSeparator?: string, options?: CursorPositionOptions): number;
93
+ export {};
@@ -0,0 +1,26 @@
1
+ /**
2
+ * DOM write helpers that preserve the browser's undo/redo stack.
3
+ *
4
+ * Direct `element.value = x` wipes the undo history. `setRangeText` registers an undo
5
+ * step instead, so Ctrl+Z keeps working. Every value mutation in NumoraInput should
6
+ * route through one of these helpers (the public `setValue({ undoable: false })`
7
+ * escape hatch is the only intentional exception).
8
+ */
9
+ /**
10
+ * Writes a new value to the input and sets the caret in one operation, preserving the
11
+ * undo stack. Skips the write if the value and caret are already what we want - that
12
+ * avoids adding a noisy no-op undo step.
13
+ *
14
+ * @param el - The input element
15
+ * @param newValue - The value to write
16
+ * @param cursorPos - The caret position to set after the write
17
+ */
18
+ export declare function writeValuePreservingUndo(el: HTMLInputElement, newValue: string, cursorPos: number): void;
19
+ /**
20
+ * Writes a focus-strip result: replaces the formatted value with raw digits and maps
21
+ * the caret/selection in one shot. Uses `preserve` (not `end`) so setRangeText does not
22
+ * snap the caret to the end of the string before setSelectionRange runs - that snap is
23
+ * what causes the visible left-then-right flicker when external `input` listeners paint
24
+ * between the two calls.
25
+ */
26
+ export declare function writeStripPreservingUndo(el: HTMLInputElement, raw: string, rawStart: number, rawEnd: number): void;
@@ -8,9 +8,10 @@
8
8
  */
9
9
  export type { ChangeRange } from './constants';
10
10
  export { GROUPING_CONFIG } from './constants';
11
- export { formatWithSeparators, formatNumoraInput } from './thousand-grouping';
12
- export { calculateCursorPositionAfterFormatting, type CursorPositionOptions, type IsCharacterEquivalent, } from './cursor-position';
11
+ export { formatWithSeparators } from './thousand-grouping';
12
+ export { calculateCursorPositionAfterFormatting, type CursorPositionOptions, } from './cursor-position';
13
13
  export { findChangedRangeFromCaretPositions, findChangeRange } from './change-detection';
14
14
  export { getCaretBoundary, getCaretPosInBoundary } from './cursor-boundary';
15
- export { setCaretPosition, setCaretPositionWithRetry, getInputCaretPosition, updateCursorPosition, skipOverThousandSeparatorOnDelete } from './caret-position-utils';
16
- export { countMeaningfulDigitsBeforePosition, findPositionForDigitIndex, findPositionWithMeaningfulDigitCount, isPositionOnSeparator, } from './digit-counting';
15
+ export { computeCursorPosition, computeStripSeparatorsResult, skipOverThousandSeparatorOnDelete, } from './caret-position-utils';
16
+ export type { StripSeparatorsResult } from './caret-position-utils';
17
+ export { writeValuePreservingUndo, writeStripPreservingUndo, } from './dom-writes';
@@ -2,7 +2,6 @@
2
2
  * Number formatting utilities with thousand separators.
3
3
  * Supports multiple grouping styles: thousand (Western), lakh (Indian), wan (Chinese)
4
4
  */
5
- import type { FormattingOptions, Separators } from '@/types';
6
5
  import { ThousandStyle } from '@/types';
7
6
  /**
8
7
  * Formats a numeric string with thousand separators based on the specified group style.
@@ -22,13 +21,3 @@ import { ThousandStyle } from '@/types';
22
21
  * formatWithSeparators("1234,56", ",", "thousand", false, ',') // "1,234,56"
23
22
  */
24
23
  export declare function formatWithSeparators(value: string, separator: string, groupStyle?: ThousandStyle, enableLeadingZeros?: boolean, decimalSeparator?: string): string;
25
- /**
26
- * Applies formatting to the input element if formatting is enabled.
27
- *
28
- * @param target - The input element
29
- * @param sanitizedAndTrimmedValue - The sanitized value to format
30
- * @param formattingOptions - Optional formatting options
31
- * @param separators - Optional separator configuration
32
- * @returns The formatted value, or the original value if formatting is not needed
33
- */
34
- export declare function formatNumoraInput(sanitizedAndTrimmedValue: string, formattingOptions?: FormattingOptions, separators?: Separators): string;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Normalizes fullwidth digits (U+FF10–U+FF19) to ASCII digits (0–9).
3
+ * Japanese and Chinese IME keyboards commonly input fullwidth digits
4
+ * that look identical to ASCII digits but are stripped by numeric filtering.
5
+ */
6
+ /**
7
+ * @param value - Input value potentially containing fullwidth digits
8
+ * @returns Value with fullwidth digits converted to ASCII
9
+ *
10
+ * @example
11
+ * normalizeFullWidthDigits("123") // Returns: "123"
12
+ */
13
+ export declare function normalizeFullWidthDigits(value: string): string;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Truncates the raw value to `maxLength` characters. Counts every character of the raw
3
+ * (post-sanitization, pre-format) string - digits, decimal separator, and a leading `-`.
4
+ *
5
+ * If truncation would leave a trailing decimal separator or a bare `-`, those are stripped
6
+ * so the result is never a malformed intermediate state purely from the truncation itself.
7
+ */
8
+ export declare function truncateToMaxLength(value: string, maxLength: number, decimalSeparator?: string): string;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Prepends `0` before a bare leading decimal separator so `.5` → `0.5` (and `-.5` → `-0.5`).
3
+ * Intended to run inside the sanitization pipeline AFTER `removeLeadingZeros`, since stripping
4
+ * `0.5` → `.5` is exactly the case this reverses.
5
+ */
6
+ export declare function prependLeadingZero(value: string, decimalSeparator?: string): string;
@@ -1,4 +1,4 @@
1
- import type { FormattingOptions, Separators } from '@/types';
1
+ import type { FormattingOptions } from '@/types';
2
2
  /**
3
3
  * Removes all occurrences of thousand separator from a string.
4
4
  * Uses cached regex for performance optimization.
@@ -8,37 +8,24 @@ import type { FormattingOptions, Separators } from '@/types';
8
8
  * @returns The string with all thousand separators removed
9
9
  */
10
10
  export declare function removeThousandSeparators(value: string, thousandSeparator: string): string;
11
- export interface SanitizationOptions {
12
- enableCompactNotation?: boolean;
13
- enableNegative?: boolean;
14
- enableLeadingZeros?: boolean;
15
- decimalSeparator?: string;
16
- thousandSeparator?: string;
17
- }
18
11
  /**
19
12
  * Sanitizes numeric input by:
20
13
  * 0. Filter mobile keyboard artifacts (non-breaking spaces, Unicode whitespace)
21
- * 1. Remove thousand separators (formatting, not data)
22
- * 2. (Optional) Expanding compact notation (e.g., 1k1000)
23
- * 3. Expanding scientific notation (e.g., 1.5e-50.000015)
24
- * 4. Removing non-numeric characters
25
- * 5. Removing extra decimal points
26
- * 6. (Optional) Removing leading zeros
14
+ * 1. Remove thousand separators (formatting, not data) - only when `thousandSeparator` is set
15
+ * 2. Normalizing fullwidth digits (e.g., 123123)
16
+ * 3. (Optional) Expanding compact notation (e.g., 1k1000)
17
+ * 4. Expanding scientific notation (e.g., 1.5e-5 → 0.000015)
18
+ * 5. Removing non-numeric characters
19
+ * 6. Removing extra decimal points
20
+ * 7. (Optional) Removing leading zeros
21
+ * 8. (Optional) Prepend `0` before a bare leading decimal separator (.5 → 0.5)
22
+ * 9. (Optional) Truncate raw to `maxLength` characters
27
23
  *
28
- * Note: Decimal separator conversion (comma ↔ dot) is handled in the keydown event
29
- * (handleDecimalSeparatorKey), not here, to avoid converting thousand separators.
24
+ * Note: Decimal separator conversion (comma ↔ dot) is handled in the beforeinput event
25
+ * (handleOnBeforeInputNumoraInput), not here, to avoid converting thousand separators.
30
26
  *
31
- * @param value - The string value to sanitize
32
- * @param options - Optional sanitization configuration
33
- * @returns The sanitized numeric string
27
+ * `formattingOptions.thousandSeparator` doubles as a flag: pass it to strip separators,
28
+ * leave it undefined to keep them. Callers that want to short-circuit removal (e.g.
29
+ * formatOn === 'blur' on the typing path) should set thousandSeparator to undefined.
34
30
  */
35
- export declare const sanitizeNumoraInput: (value: string, options?: SanitizationOptions) => string;
36
- /**
37
- * Builds sanitization options from formatting options and separators.
38
- *
39
- * @param formattingOptions - Optional formatting options
40
- * @param separators - Separator configuration
41
- * @param shouldRemoveThousandSeparators - Whether to remove thousand separators
42
- * @returns Sanitization options
43
- */
44
- export declare function buildSanitizationOptions(formattingOptions: FormattingOptions | undefined, separators: Separators, shouldRemoveThousandSeparators: boolean): SanitizationOptions;
31
+ export declare const sanitizeNumoraInput: (value: string, formattingOptions?: FormattingOptions) => string;
package/dist/index.d.ts CHANGED
@@ -1,9 +1,18 @@
1
1
  export * from './NumoraInput';
2
- export { ThousandStyle, FormatOn } from './types';
2
+ export { ThousandStyle, FormatOn, InputType } from './types';
3
3
  export { getSeparatorsFromLocale, applyLocale } from './utils/locale';
4
- export { handleOnBeforeInputNumoraInput, handleOnChangeNumoraInput, handleOnPasteNumoraInput, handleOnKeyDownNumoraInput, } from './utils/event-handlers';
5
- export { formatValueForDisplay, formatInputValue, } from './utils/format-utils';
4
+ export { handleOnBeforeInputNumoraInput, handleOnPasteNumoraInput, handleOnKeyDownNumoraInput, } from './utils/event-handlers';
5
+ export { formatValueForDisplay, } from './utils/format-utils';
6
6
  export type { FormattingOptions, CaretPositionInfo } from './types';
7
- export { removeThousandSeparators } from './features/sanitization';
7
+ export { sanitizeNumoraInput, removeThousandSeparators } from './features/sanitization';
8
+ export { filterMobileKeyboardArtifacts } from './features/mobile-keyboard-filtering';
9
+ export { normalizeFullWidthDigits } from './features/fullwidth-digits';
10
+ export { expandCompactNotation } from './features/compact-notation';
11
+ export { expandScientificNotation } from './features/scientific-notation';
12
+ export { removeNonNumericCharacters } from './features/non-numeric-characters';
13
+ export { removeExtraDecimalSeparators } from './features/decimals';
14
+ export { removeLeadingZeros } from './features/leading-zeros';
15
+ export { prependLeadingZero } from './features/prepend-leading-zero';
16
+ export { truncateToMaxLength } from './features/max-length';
8
17
  export { validateNumoraInputOptions } from './validation';
9
- export { getNumoraPattern } from './utils/input-pattern';
18
+ export { writeValuePreservingUndo, writeStripPreservingUndo, computeStripSeparatorsResult, type StripSeparatorsResult, } from './features/formatting';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var ue=Object.defineProperty;var de=(e,t,n)=>t in e?ue(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var w=(e,t,n)=>de(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var m=(e=>(e.Blur="blur",e.Change="change",e))(m||{}),b=(e=>(e.None="none",e.Thousand="thousand",e.Lakh="lakh",e.Wan="wan",e))(b||{});const B=2,G=0,k=m.Blur,fe=",",Z=b.None,C=".",W=!1,U=!1,P=!1,z=!1;function y(e){return e.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}const J=new Map;function O(e,t="g"){const n=`${e}:${t}`;let r=J.get(n);return r||(r=new RegExp(e,t),J.set(n,r)),r}function ge(e,t="g"){const n=y(e);return O(n,t)}const Se=/[.,]/g;function _(e){return{decimalSeparator:(e==null?void 0:e.decimalSeparator)??C,thousandSeparator:e==null?void 0:e.thousandSeparator}}function Y(e,t){const n=e.startsWith("-"),r=n?e.slice(1):e,[i="",s=""]=r.split(t);return{sign:n?"-":"",integer:i,decimal:s}}const pe=(e,t,n=C)=>{const{sign:r,integer:i,decimal:s}=Y(e,n);if(!s)return e;const a=s.slice(0,t);return`${r}${i}${n}${a}`},Ee=(e,t=C)=>{const n=e.indexOf(t);if(n===-1||n===e.length-1)return e;const r=e.slice(0,n+1),i=e.slice(n+1),a=t==="."||t===","?Se:O("[,\\."+y(t)+"]","g");return r+i.replace(a,"")},me=(e,t=0,n=C)=>{if(t<=0)return e;const{sign:r,integer:i,decimal:s}=Y(e,n);if(s.length>=t)return e;const a=s.padEnd(t,"0");return`${r}${i}${n}${a}`},$={thousand:{size:3},lakh:{firstGroup:3,restGroup:2},wan:{size:4}},be=/^(0+)/;function Q(e,t,n=b.Thousand,r=!1,i="."){if(!e||e==="0"||e===i||e==="-"||e===`-${i}`)return e;const s=e.includes(i),a=e.startsWith("-"),c=a?e.slice(1):e,[o,l]=c.split(i);if(!o){const u=l?`${i}${l}`:c;return a?`-${u}`:u}if(r&&o.startsWith("0")&&o.length>1){const u=o.match(be);if(u){const S=u[1],p=o.slice(S.length);if(p){const E=X(p,t,n),d=S+E,f=a?"-":"";return s?l?`${f}${d}${i}${l}`:`${f}${d}${i}`:`${f}${d}`}}}const h=X(o,t,n),g=a?"-":"";return s?l?`${g}${h}${i}${l}`:`${g}${h}${i}`:`${g}${h}`}function X(e,t,n){if(e==="0"||e==="")return e;switch(n){case b.None:return e;case b.Thousand:return j(e,t,$.thousand.size);case b.Lakh:return Ne(e,t);case b.Wan:return j(e,t,$.wan.size);default:return e}}function Ne(e,t){if(e.length<=$.lakh.firstGroup)return e;const n=[],r=e.length-$.lakh.firstGroup;n.unshift(e.slice(r));for(let i=r;i>0;i-=$.lakh.restGroup)n.unshift(e.slice(Math.max(0,i-$.lakh.restGroup),i));return n.join(t)}function j(e,t,n){const r=[];for(let i=e.length;i>0;i-=n)r.unshift(e.slice(Math.max(0,i-n),i));return r.join(t)}function Le(e,t,n){return(t==null?void 0:t.formatOn)===m.Change&&t.thousandSeparator?Q(e,t.thousandSeparator,t.ThousandStyle??b.None,t.enableLeadingZeros,(n==null?void 0:n.decimalSeparator)??C):e}function D(e,t,n){let r=0;for(let i=0;i<t&&i<e.length;i++)e[i]!==n&&r++;return r}function ve(e,t,n){if(t===0)return 0;let r=0;for(let i=0;i<e.length;i++)if(e[i]!==n){if(r===t-1)return i+1;r++}return e.length}function R(e,t,n){if(t===0)return 0;let r=0;for(let i=0;i<e.length;i++)if(e[i]!==n){if(r++,r===t)return i+1;if(r>t)return i}return e.length}function V(e,t,n){return t<0||t>=e.length?!1:e[t]===n}const De=/\d/;function $e(e,t={}){const{thousandSeparator:n,decimalSeparator:r=".",prefix:i="",suffix:s=""}=t,a=new Array(e.length+1).fill(!0);if(i&&a.fill(!1,0,i.length),s){const c=e.length-s.length;a.fill(!1,c+1,e.length+1)}for(let c=0;c<e.length;c++){const o=e[c];(n&&o===n||o===r)&&(a[c]=!1,c+1<e.length&&!De.test(e[c+1])&&(a[c+1]=!1))}return a.some(c=>c)||a.fill(!0),a}function x(e,t,n,r){const i=e.length;if(t=Math.max(0,Math.min(t,i)),r==="left"){for(;t>=0&&!n[t];)t--;t===-1&&(t=n.indexOf(!0))}else if(r==="right"){for(;t<=i&&!n[t];)t++;t>i&&(t=n.lastIndexOf(!0))}else if(!n[t]){let s=t;for(;s<=i&&!n[s];)s++;let a=t;for(;a>=0&&!n[a];)a--;s<=i&&a>=0?t=t-a<s-t?a:s:s<=i?t=s:a>=0&&(t=a)}return(t===-1||t>i)&&(t=i),t}const K=/(\d+\.?\d*)\s*[kmbt]$/i,Ce=(e,t)=>e===t;function we(e,t,n,r,i,s,a=".",c={}){if(n<0)return 0;if(n>e.length||e===""||t===""||K.test(e)&&!K.test(t)&&t.length>e.length&&n>=e.length-1)return t.length;const o=t.length<e.length,l=V(e,n,r),h=e.indexOf(a),g=t.indexOf(a);if(c.isCharacterEquivalent&&e!==t){const d={thousandSeparator:r||void 0,...c},f=ye(e,t,n,c.isCharacterEquivalent||Ce,s,d);if(f!==void 0)return f}const S=new Map,p=(d,f,L)=>{const N=`${d===e?"o":"n"}:${f}`;return S.has(N)||S.set(N,D(d,f,r)),S.get(N)};if(o)return Ie(e,t,n,r,l,h,g,s,c,p);const E=Re(e,t,n,r,l,p);return c.boundary?x(t,E,c.boundary):E}function ye(e,t,n,r,i,s){const a=e.length,c=t.length;let o=0,l=0,h=c;for(let f=0;f<a;f++){let L=-1;for(let N=o;N<c;N++)if(r(e[f],t[N],{oldValue:e,newValue:t,typedRange:i,oldIndex:f,newIndex:N})){L=N;break}L!==-1&&(o=L+1,f<n?l=L+1:h===c&&/\d/.test(e[f])&&(h=L))}if(l>h)return h;const g=t.length<e.length||i!==void 0&&i.isDelete===!1;let u,S=!1,p=!1;if(g){u=l;const f=s.thousandSeparator,L=s.decimalSeparator??".",N=u<t.length?t[u]:"";f&&N===f?(n>0?e[n-1]:"")===f?(u=h,S=!0):p=!0:N===L&&(p=!0)}else u=n-l<h-n?l:h;const E=g&&!S?"left":"right";if(s.boundary)return p?u:x(t,u,s.boundary,E);const d=s.thousandSeparator;if(!p&&d&&u>=0&&u<t.length&&t[u]===d)if(g&&!S)for(;u>0&&t[u]===d;)u--;else for(;u<t.length&&t[u]===d;)u++;return u}function Ie(e,t,n,r,i,s,a,c,o={},l=D){if(i)return Me(e,t,n,r,a,l);const h=l(e,n,r),g=l(e,e.length,r),u=l(t,t.length,r),S=g-u,p=Te(e,n,r,h,S,s,c,l),E=s===-1||n<=s,d=Ae(t,p,r,S,c,E,a,l);return o.boundary?x(t,d,o.boundary):d}function Me(e,t,n,r,i,s=D){const a=n+1;if(a<e.length){const c=s(e,a,r),o=ve(t,c,r);return o<t.length&&t[o]!==r?o+1:o}return n}function Te(e,t,n,r,i,s,a,c=D){if(a){const{start:l,isDelete:h}=a;return h?c(e,l,n):Math.max(0,c(e,l,n))}return t>0&&e[t-1]===n&&i>0?r+1:r}function q(e,t,n,r,i,s,a=D){if(t>0&&t<e.length&&a(e,t,r)===n){if(e[t]===r&&s&&i>0&&t<e.length-1)return t+1;if(!s&&i>0&&t<e.length-1)return Math.min(t+1,e.length)}return t}function Ae(e,t,n,r,i,s,a,c=D){if(s&&a!==-1){const l=e.substring(0,a),h=c(l,l.length,n);if(t<=h){const g=R(l,t,n);return q(l,g,t,n,r,i,c)}}const o=R(e,t,n);return q(e,o,t,n,r,i,c)}function Re(e,t,n,r,i,s=D){const a=n>=e.length,c=s(e,n,r),o=s(e,e.length,r),l=s(t,t.length,r);if(a||c===o)return t.length;const h=l-o;let g=c;h>0&&!a&&c<o&&(g=c+1);const u=R(t,g,r);return i&&!V(t,u,r)?Math.max(0,u-1):u}function Oe(e,t,n){const{selectionStart:r,selectionEnd:i,endOffset:s=0}=e;if(r!==i){const h=i-r;return{start:r,end:i,deletedLength:h,isDelete:!1}}if(s>0){const h=s;return{start:r,end:r+h,deletedLength:h,isDelete:!0}}const c=t.length,o=n.length,l=c-o;if(!(l<=0))return{start:r,end:r+l,deletedLength:l,isDelete:!1}}function _e(e,t){if(e===t)return;let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;let r=e.length-1,i=t.length-1;for(;r>=n&&i>=n&&e[r]===t[i];)r--,i--;const s=r-n+1,a=i-n+1;if(!(s===0&&a===0))return{start:n,end:r+1,deletedLength:s,isDelete:s>a}}function H(e,t){if(e.value=e.value,e===null)return!1;if(e.createTextRange){const n=e.createTextRange();return n.move("character",t),n.select(),!0}return e.selectionStart!==null||e.selectionStart===0?(e.focus(),e.setSelectionRange(t,t),!0):(e.focus(),!1)}function xe(e,t,n){return e.selectionStart===0&&e.selectionEnd===e.value.length?null:(H(e,t),setTimeout(()=>{e.value===n&&e.selectionStart!==t&&H(e,t)},0))}function Be(e){return Math.max(e.selectionStart,e.selectionEnd)}function Ge(e,t,n){if((n==null?void 0:n.formatOn)!==m.Change||!n.thousandSeparator)return;const{selectionStart:r,selectionEnd:i,value:s}=t;if(r===null||i===null||r!==i)return;const{key:a}=e,c=n.thousandSeparator;a==="Backspace"&&r>0&&s[r-1]===c&&t.setSelectionRange(r-1,r-1),a==="Delete"&&s[r]===c&&t.setSelectionRange(r+1,r+1)}function F(e,t,n,r,i,s,a){if(!i)return;const{selectionStart:c=0,selectionEnd:o=0,endOffset:l=0}=i;let h=Oe({selectionStart:c,selectionEnd:o,endOffset:l},t,n);if(h||(h=_e(t,n)),!h)return;const g=$e(n,{thousandSeparator:(a==null?void 0:a.thousandSeparator)??s.thousandSeparator,decimalSeparator:s.decimalSeparator}),u={thousandSeparator:(a==null?void 0:a.thousandSeparator)??s.thousandSeparator,decimalSeparator:s.decimalSeparator,isCharacterEquivalent:(d,f)=>{const L=(a==null?void 0:a.thousandSeparator)??s.thousandSeparator;return L&&d===L?!1:d===f},boundary:g},S=(a==null?void 0:a.thousandSeparator)??s.thousandSeparator??",",p=(a==null?void 0:a.ThousandStyle)??b.None,E=we(t,n,r,S,p,h,s.decimalSeparator,u);xe(e,E,n)}const ke=(e,t=!1,n=".")=>{const r=y(n),i=O(`[^0-9${r}]`,"g");if(!t)return e.replace(i,"");const s=e.startsWith("-"),a=e.replace(i,"");return s&&(a.length>0||e==="-")?"-"+a:a},Ze=/([+-]?\d+\.?\d*)[eE]([+-]?\d+)/g,ee=/^0+$/,T=/\.?0+$/;function We(e){return!e.includes("e")&&!e.includes("E")?e:e.replace(Ze,(t,n,r)=>{const i=parseInt(r,10);if(i===0)return n;const s=n.startsWith("-"),a=s?n.slice(1):n,[c,o=""]=a.split("."),l=i>0?Ue(c,o,i):Pe(c,o,Math.abs(i));return s?"-"+l:l})}function Ue(e,t,n){const r=e+t;if(r==="0"||ee.test(r))return"0";const i=t.length;if(n<=i){const a=r.slice(0,e.length+n),c=r.slice(e.length+n);return c?`${a}.${c}`:a}const s=n-i;return r+"0".repeat(s)}function Pe(e,t,n){const r=e+t;if(r==="0"||ee.test(r))return"0";const s=e.length-n;if(s<=0){const a=Math.abs(s),c=`0.${"0".repeat(a)}${r}`;return A(c)}if(s<e.length){const a=r.slice(0,s),c=r.slice(s),o=`${a}.${c}`;return A(o)}return A(r)}function A(e){if(!e.includes("."))return e;if(e==="0.")return"0";if(e.startsWith("0.")){const t=e.replace(T,"");return t==="0"?"0":t||"0"}if(e.startsWith("-0.")){const t=e.replace(T,"");return t==="-0"||t==="0"?"0":t||"0"}return e.replace(T,"")||e}const ze=/(\d+\.?\d*)\s*([kmbt])/gi,Je=/^0+/,Xe=/^(-?)0+([1-9])/,je=/^-?0+$/,Ke=/\.?0+$/,qe={k:3,m:6,b:9,t:12};function He(e){return e.replace(ze,(t,n,r)=>{const i=r.toLowerCase(),s=qe[i];if(!s)return t;const[a,c=""]=n.split("."),o=a.replace(Je,"")||"0";let l;if(c.length===0)l=o+"0".repeat(s);else if(c.length<=s){const h=s-c.length;l=o+c+"0".repeat(h)}else{const h=c.slice(0,s),g=c.slice(s);l=o+h+"."+g}return l=l.replace(Xe,"$1$2"),je.test(l)&&(l="0"),l.includes(".")&&(l=l.replace(Ke,"")),l})}function Ye(e){if(!e||e==="0"||e==="-0"||e==="-"||e===".")return e;const t=e.startsWith("-"),n=t?e.slice(1):e;if(n===".")return e;if(n.includes(".")){const[i,s]=n.split(".");if(i){const c=(i.replace(/^0+/,"")||"0")+"."+s;return t?"-"+c:c}return e}if(n.startsWith("0")){const i=n.replace(/^0+/,"")||"0";return t?"-"+i:i}return e}function Qe(e){return e.replace(/[\s\u200B]/g,"")}function v(e,t){const n=ge(t);return e.replace(n,"")}const Ve=(e,t)=>{let n=Qe(e);return t!=null&&t.thousandSeparator&&(n=v(n,t.thousandSeparator)),t!=null&&t.enableCompactNotation&&(n=He(n)),n=We(n),n=ke(n,t==null?void 0:t.enableNegative,t==null?void 0:t.decimalSeparator),n=Ee(n,t==null?void 0:t.decimalSeparator),t!=null&&t.enableLeadingZeros||(n=Ye(n)),n};function Fe(e,t,n){return{enableCompactNotation:e==null?void 0:e.enableCompactNotation,enableNegative:e==null?void 0:e.enableNegative,enableLeadingZeros:e==null?void 0:e.enableLeadingZeros,decimalSeparator:t.decimalSeparator,thousandSeparator:n?t.thousandSeparator:void 0}}function I(e,t,n,r){const i=_(n),s=r??(n==null?void 0:n.formatOn)===m.Change,a=Ve(e,Fe(n,i,s)),c=pe(a,t,i.decimalSeparator),o=(n==null?void 0:n.decimalMinLength)??0,l=me(c,o,i.decimalSeparator);return{formatted:Le(l,n,i),raw:l}}function et(e,t,n){const r=!!(n!=null&&n.thousandSeparator);return I(e,t,n,r)}function te(e,t,n){if(e.inputType==="insertFromPaste"||e.inputType==="insertFromDrop")return null;const r=e.target,i=r.value,s=r.selectionStart??0,a=r.selectionEnd??0,c=_(n);let o=e.data??"";if(e.inputType==="insertText"&&(e.data===","||e.data===".")){const d=c.decimalSeparator;if((i.slice(0,s)+i.slice(a)).includes(d))return e.preventDefault(),null;o=d}let l,h;switch(e.inputType){case"insertText":{l=i.slice(0,s)+o+i.slice(a),h=s+o.length;break}case"deleteContentBackward":{if(s!==a)l=i.slice(0,s)+i.slice(a),h=s;else{const d=Math.max(0,s-1);l=i.slice(0,d)+i.slice(s),h=d}break}case"deleteContentForward":{s!==a?(l=i.slice(0,s)+i.slice(a),h=s):(l=i.slice(0,s)+i.slice(s+1),h=s);break}case"deleteByCut":case"deleteByDrag":{l=i.slice(0,s)+i.slice(a),h=s;break}default:return null}e.preventDefault();const g=(n==null?void 0:n.formatOn)===m.Change,{formatted:u,raw:S}=I(l,t,n,g);r.setRangeText(u,0,i.length,"end");const p=e.inputType==="deleteContentForward"?1:0;return l!==u?F(r,l,u,h,{selectionStart:s,selectionEnd:a,endOffset:p},c,n):r.setSelectionRange(h,h),{formatted:u,raw:S}}function tt(e,t,n){if(e==="Backspace"||e==="Delete")return e==="Delete"&&t===n?{endOffset:1}:{endOffset:0}}function ne(e,t){const n=e.target;return Ge(e,n,t),tt(e.key,n.selectionStart,n.selectionEnd)}function re(e,t,n,r){const i=e.target,s=i.value,a=Be(i),c=_(r),o=(r==null?void 0:r.formatOn)===m.Change,{formatted:l,raw:h}=I(s,t,r,o);return i.value=l,s!==l&&F(i,s,l,a,n,c,r),{formatted:l,raw:h}}function nt(e,t,n,r){const i=r-n;return e+t+i}function ie(e,t,n){var u;e.preventDefault();const r=e.target,{value:i,selectionStart:s,selectionEnd:a}=r,c=((u=e.clipboardData)==null?void 0:u.getData("text/plain"))||"",o=i.slice(0,s||0)+c+i.slice(a||0),{formatted:l,raw:h}=I(o,t,n,!0);r.value=l;const g=nt(s||0,c.length,o.length,l.length);return r.setSelectionRange(g,g),{formatted:l,raw:h}}function se(e,t){const n=y(e);return t?`^-?[0-9]*[${n}]?[0-9]*$`:`^[0-9]*[${n}]?[0-9]*$`}function ae(e){var t,n;try{const i=new Intl.NumberFormat(e).formatToParts(123456789e-2);return{decimalSeparator:((t=i.find(s=>s.type==="decimal"))==null?void 0:t.value)??".",thousandSeparator:((n=i.find(s=>s.type==="group"))==null?void 0:n.value)??","}}catch{return{thousandSeparator:",",decimalSeparator:"."}}}function ce(e,t){if(!e)return t;const r=ae(e===!0?void 0:e);return{thousandSeparator:t.thousandSeparator??r.thousandSeparator,decimalSeparator:t.decimalSeparator??r.decimalSeparator}}function le(e){rt(e.decimalMaxLength),it(e.decimalMinLength),st(e.decimalMinLength,e.decimalMaxLength),at(e.formatOn),ct(e.thousandSeparator),lt(e.thousandStyle),ot(e.decimalSeparator),ht(e.thousandSeparator,e.decimalSeparator),M("enableCompactNotation",e.enableCompactNotation),M("enableNegative",e.enableNegative),M("enableLeadingZeros",e.enableLeadingZeros),M("rawValueMode",e.rawValueMode),ut(e.onChange)}function rt(e){if(e!==void 0){if(typeof e!="number")throw new Error(`decimalMaxLength must be a number. Received: ${typeof e} (${JSON.stringify(e)})`);if(!Number.isInteger(e))throw new Error(`decimalMaxLength must be an integer. Received: ${e}`);if(e<0)throw new Error(`decimalMaxLength must be non-negative. Received: ${e}`)}}function it(e){if(e!==void 0){if(typeof e!="number")throw new Error(`decimalMinLength must be a number. Received: ${typeof e} (${JSON.stringify(e)})`);if(!Number.isInteger(e))throw new Error(`decimalMinLength must be an integer. Received: ${e}`);if(e<0)throw new Error(`decimalMinLength must be non-negative. Received: ${e}`)}}function st(e,t){if(!(e===void 0||t===void 0)&&e>t)throw new Error(`decimalMinLength (${e}) cannot be greater than decimalMaxLength (${t}).`)}function at(e){if(e!==void 0&&e!==m.Blur&&e!==m.Change)throw new Error(`formatOn must be either ${m.Blur} or ${m.Change}. Received: ${JSON.stringify(e)}`)}function ct(e){if(e!==void 0){if(typeof e!="string")throw new Error(`thousandSeparator must be a string. Received: ${typeof e} (${JSON.stringify(e)})`);if(e.length===0)throw new Error(`thousandSeparator cannot be empty. Received: ${JSON.stringify(e)}`);if(e.length>1)throw new Error(`thousandSeparator must be a single character. Received: "${e}" (length: ${e.length})`)}}function lt(e){if(e!==void 0&&!Object.values(b).includes(e))throw new Error(`ThousandStyle must be one of: ${Object.values(b).map(t=>`'${t}'`).join(", ")}. Received: ${JSON.stringify(e)}`)}function ot(e){if(e!==void 0){if(typeof e!="string")throw new Error(`decimalSeparator must be a string. Received: ${typeof e} (${JSON.stringify(e)})`);if(e.length===0)throw new Error(`decimalSeparator cannot be empty. Received: ${JSON.stringify(e)}`);if(e.length>1)throw new Error(`decimalSeparator must be a single character. Received: "${e}" (length: ${e.length})`)}}function ht(e,t){if(!(e===void 0||t===void 0)&&e===t)throw new Error(`Decimal separator can't be same as thousand separator. thousandSeparator: ${e}, decimalSeparator: ${t}`)}function M(e,t){if(t!==void 0&&typeof t!="boolean")throw new Error(`${e} must be a boolean. Received: ${typeof t} (${JSON.stringify(t)})`)}function ut(e){if(e!==void 0&&typeof e!="function")throw new Error(`onChange must be a function or undefined. Received: ${typeof e} (${JSON.stringify(e)})`)}class dt{constructor(t,{decimalMaxLength:n=B,decimalMinLength:r=G,formatOn:i=k,thousandSeparator:s,thousandStyle:a=Z,decimalSeparator:c,locale:o,enableCompactNotation:l=W,enableNegative:h=U,enableLeadingZeros:g=P,rawValueMode:u=z,onChange:S,...p}){w(this,"element");w(this,"resolvedOptions");w(this,"rawValue","");w(this,"caretPositionBeforeChange");le({decimalMaxLength:n,decimalMinLength:r,formatOn:i,thousandSeparator:s,thousandStyle:a,decimalSeparator:c,enableCompactNotation:l,enableNegative:h,enableLeadingZeros:g,rawValueMode:u,onChange:S});const E={decimalMaxLength:n,decimalMinLength:r,onChange:S,formatOn:i,thousandSeparator:s,thousandStyle:a,decimalSeparator:c,locale:o,enableCompactNotation:l,enableNegative:h,enableLeadingZeros:g,rawValueMode:u,...p};if(this.resolvedOptions=this.getResolvedOptions(E),this.createInputElement(t,E),this.setupEventListeners(),this.resolvedOptions.rawValueMode&&this.element.value){const d=this.element.value,f=this.resolvedOptions.thousandSeparator?v(d,this.resolvedOptions.thousandSeparator):d;this.rawValue=f,this.element.value=this.formatValueForDisplay(f)}else if(this.element.value){const d=this.element.value;this.element.value=this.formatValueForDisplay(d)}}createInputElement(t,n){this.element=document.createElement("input"),this.element.setAttribute("type","text"),this.element.setAttribute("inputmode","decimal"),this.element.setAttribute("spellcheck","false"),this.element.setAttribute("autocomplete","off");const r=se(this.resolvedOptions.decimalSeparator,this.resolvedOptions.enableNegative);this.element.setAttribute("pattern",r);const{decimalMaxLength:i,decimalMinLength:s,formatOn:a,thousandSeparator:c,thousandStyle:o,decimalSeparator:l,locale:h,enableCompactNotation:g,enableNegative:u,enableLeadingZeros:S,rawValueMode:p,onChange:E,value:d,defaultValue:f,type:L,inputMode:N,spellcheck:oe,autocomplete:ft,...he}=n;Object.assign(this.element,he),d!==void 0?this.element.value=d:f!==void 0&&(this.element.defaultValue=f,this.element.value=f),t.appendChild(this.element)}setupEventListeners(){this.element.addEventListener("beforeinput",this.handleBeforeInput.bind(this)),this.element.addEventListener("input",this.handleChange.bind(this)),this.element.addEventListener("keydown",this.handleKeyDown.bind(this)),this.element.addEventListener("paste",this.handlePaste.bind(this)),this.resolvedOptions.formatOn===m.Blur&&this.resolvedOptions.thousandSeparator&&(this.element.addEventListener("focus",this.handleFocus.bind(this)),this.element.addEventListener("blur",this.handleBlur.bind(this)))}getResolvedOptions(t){const n=ce(t.locale,{thousandSeparator:t.thousandSeparator,decimalSeparator:t.decimalSeparator});return{decimalMaxLength:t.decimalMaxLength??B,decimalMinLength:t.decimalMinLength??G,formatOn:t.formatOn??k,thousandSeparator:n.thousandSeparator??fe,thousandStyle:t.thousandStyle??Z,decimalSeparator:n.decimalSeparator??C,enableCompactNotation:t.enableCompactNotation??W,enableNegative:t.enableNegative??U,enableLeadingZeros:t.enableLeadingZeros??P,rawValueMode:t.rawValueMode??z,onChange:t.onChange}}buildFormattingOptions(){return{formatOn:this.resolvedOptions.formatOn,thousandSeparator:this.resolvedOptions.thousandSeparator,ThousandStyle:this.resolvedOptions.thousandStyle,enableCompactNotation:this.resolvedOptions.enableCompactNotation,enableNegative:this.resolvedOptions.enableNegative,enableLeadingZeros:this.resolvedOptions.enableLeadingZeros,decimalSeparator:this.resolvedOptions.decimalSeparator,decimalMinLength:this.resolvedOptions.decimalMinLength,rawValueMode:this.resolvedOptions.rawValueMode}}handleValueChange(t,n){if(this.resolvedOptions.rawValueMode&&n!==void 0&&(this.rawValue=n),this.resolvedOptions.onChange){const r=this.resolvedOptions.rawValueMode?this.rawValue:t;this.resolvedOptions.onChange(r)}}formatValueForDisplay(t){if(!t)return t;const{thousandSeparator:n,thousandStyle:r,enableLeadingZeros:i,decimalSeparator:s}=this.resolvedOptions;return n&&r!==b.None?Q(t,n,r,i,s):t}handleBeforeInput(t){te(t,this.resolvedOptions.decimalMaxLength,this.buildFormattingOptions())}handleChange(t){const{formatted:n,raw:r}=re(t,this.resolvedOptions.decimalMaxLength,this.caretPositionBeforeChange,this.buildFormattingOptions());this.caretPositionBeforeChange=void 0,this.handleValueChange(n,r)}handleKeyDown(t){const n=t.target,{selectionStart:r,selectionEnd:i}=n,s=this.buildFormattingOptions(),a=ne(t,{formatOn:s.formatOn,thousandSeparator:s.thousandSeparator,ThousandStyle:s.ThousandStyle,decimalSeparator:s.decimalSeparator});a?this.caretPositionBeforeChange={selectionStart:r??0,selectionEnd:i??0,endOffset:a.endOffset}:this.caretPositionBeforeChange={selectionStart:r??0,selectionEnd:i??0}}handlePaste(t){const{formatted:n,raw:r}=ie(t,this.resolvedOptions.decimalMaxLength,this.buildFormattingOptions());this.handleValueChange(n,r);const i=new Event("input",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(i)}handleFocus(t){if(this.resolvedOptions.formatOn===m.Blur&&this.resolvedOptions.thousandSeparator){const n=t.target;n.value=v(n.value,this.resolvedOptions.thousandSeparator)}}handleBlur(t){const n=t.target,{thousandSeparator:r,thousandStyle:i}=this.resolvedOptions;if(r&&i!==b.None&&n.value){const s=this.formatValueForDisplay(n.value);n.value=s;const a=this.resolvedOptions.rawValueMode?v(s,r):void 0;this.handleValueChange(s,a)}}getValue(){return this.resolvedOptions.rawValueMode?this.rawValue:this.element.value}setValue(t){if(this.resolvedOptions.rawValueMode){const n=this.resolvedOptions.thousandSeparator?v(t,this.resolvedOptions.thousandSeparator):t;this.rawValue=n,this.element.value=this.formatValueForDisplay(n)}else this.element.value=t}disable(){this.element.disabled=!0}enable(){this.element.disabled=!1}addEventListener(t,n){this.element.addEventListener(t,n)}removeEventListener(t,n){this.element.removeEventListener(t,n)}getElement(){return this.element}get value(){return this.getValue()}set value(t){this.setValue(t)}get valueAsNumber(){const t=this.getValue();if(!t)return NaN;const n=this.resolvedOptions.thousandSeparator?v(t,this.resolvedOptions.thousandSeparator):t,r=this.resolvedOptions.decimalSeparator&&this.resolvedOptions.decimalSeparator!=="."?n.replace(new RegExp(y(this.resolvedOptions.decimalSeparator),"g"),"."):n;return parseFloat(r)}set valueAsNumber(t){if(isNaN(t)){this.setValue("");return}const n=t.toString();this.setValue(n)}}exports.FormatOn=m;exports.NumoraInput=dt;exports.ThousandStyle=b;exports.applyLocale=ce;exports.formatInputValue=I;exports.formatValueForDisplay=et;exports.getNumoraPattern=se;exports.getSeparatorsFromLocale=ae;exports.handleOnBeforeInputNumoraInput=te;exports.handleOnChangeNumoraInput=re;exports.handleOnKeyDownNumoraInput=ne;exports.handleOnPasteNumoraInput=ie;exports.removeThousandSeparators=v;exports.validateNumoraInputOptions=le;
1
+ "use strict";var Le=Object.defineProperty;var De=(t,e,n)=>e in t?Le(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var N=(t,e,n)=>De(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var I=(t=>(t.Blur="blur",t.Change="change",t))(I||{}),y=(t=>(t.None="none",t.Thousand="thousand",t.Lakh="lakh",t.Wan="wan",t))(y||{});const L={InsertText:"insertText",InsertFromPaste:"insertFromPaste",InsertFromDrop:"insertFromDrop",DeleteContentBackward:"deleteContentBackward",DeleteContentForward:"deleteContentForward",DeleteByCut:"deleteByCut",DeleteByDrag:"deleteByDrag",DeleteSoftLineBackward:"deleteSoftLineBackward",DeleteHardLineBackward:"deleteHardLineBackward",DeleteSoftLineForward:"deleteSoftLineForward",DeleteHardLineForward:"deleteHardLineForward",HistoryUndo:"historyUndo",HistoryRedo:"historyRedo"},we=2,ye=0,Ie=I.Blur,Ne=",",Ae=y.None,x=".",Ce=!1,be=!1,ve=!1,Te=!1,Me=!1,U=new Map;function B(t,e="g"){const n=`${t}:${e}`;let r=U.get(n);return r||(r=new RegExp(t,e),U.set(n,r)),r}function M(t){return t.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}const xe=/[.,]/g;function Z(t){return{decimalSeparator:(t==null?void 0:t.decimalSeparator)??x,thousandSeparator:t==null?void 0:t.thousandSeparator}}function q(t,e){const n=t.startsWith("-"),r=n?t.slice(1):t,[s="",i=""]=r.split(e);return{sign:n?"-":"",integer:s,decimal:i}}const $e=(t,e,n=x)=>{const{sign:r,integer:s,decimal:i}=q(t,n);if(!i)return t;const a=i.slice(0,e);return`${r}${s}${n}${a}`},Y=(t,e=x)=>{const n=t.indexOf(e);if(n===-1||n===t.length-1)return t;const r=t.slice(0,n+1),s=t.slice(n+1),a=e==="."||e===","?xe:B("[,\\."+M(e)+"]","g");return r+s.replace(a,"")},Re=(t,e=0,n=x)=>{if(e<=0)return t;const{sign:r,integer:s,decimal:i}=q(t,n);if(i.length>=e)return t;const a=i.padEnd(e,"0");return`${r}${s}${n}${a}`},Q=(t,e=!1,n=".")=>{const r=M(n),s=B(`[^0-9${r}]`,"g");if(!e)return t.replace(s,"");const i=t.startsWith("-"),a=t.replace(s,"");return i&&(a.length>0||t==="-")?"-"+a:a},_e=/([+-]?\d+\.?\d*)[eE]([+-]?\d+)/g,O=/^0+$/,R=/\.?0+$/;function V(t){return!t.includes("e")&&!t.includes("E")?t:t.replace(_e,(e,n,r)=>{const s=parseInt(r,10);if(s===0)return n;const i=n.startsWith("-"),a=i?n.slice(1):n,[c,h=""]=a.split("."),l=s>0?me(c,h,s):ke(c,h,Math.abs(s));return i?"-"+l:l})}function me(t,e,n){const r=t+e;if(r==="0"||O.test(r))return"0";const s=e.length;if(n<=s){const a=r.slice(0,t.length+n),c=r.slice(t.length+n);return c?`${a}.${c}`:a}const i=n-s;return r+"0".repeat(i)}function ke(t,e,n){const r=t+e;if(r==="0"||O.test(r))return"0";const i=t.length-n;if(i<=0){const a=Math.abs(i),c=`0.${"0".repeat(a)}${r}`;return _(c)}if(i<t.length){const a=r.slice(0,i),c=r.slice(i),h=`${a}.${c}`;return _(h)}return _(r)}function _(t){if(!t.includes("."))return t;if(t==="0.")return"0";if(t.startsWith("0.")){const e=t.replace(R,"");return e==="0"?"0":e||"0"}if(t.startsWith("-0.")){const e=t.replace(R,"");return e==="-0"||e==="0"?"0":e||"0"}return t.replace(R,"")||t}const Be=/(\d+\.?\d*)\s*([kmbt])/gi,Ze=/^0+/,Ge=/^(-?)0+([1-9])/,We=/^-?0+$/,Ue=/\.?0+$/,Pe={k:3,m:6,b:9,t:12};function F(t){return t.replace(Be,(e,n,r)=>{const s=r.toLowerCase(),i=Pe[s];if(!i)return e;const[a,c=""]=n.split("."),h=a.replace(Ze,"")||"0";let l;if(c.length===0)l=h+"0".repeat(i);else if(c.length<=i){const o=i-c.length;l=h+c+"0".repeat(o)}else{const o=c.slice(0,i),f=c.slice(i);l=h+o+"."+f}return l=l.replace(Ge,"$1$2"),We.test(l)&&(l="0"),l.includes(".")&&(l=l.replace(Ue,"")),l})}function ee(t){if(!t||t==="0"||t==="-0"||t==="-"||t===".")return t;const e=t.startsWith("-"),n=e?t.slice(1):t;if(n===".")return t;if(n.includes(".")){const[s,i]=n.split(".");if(s){const c=(s.replace(/^0+/,"")||"0")+"."+i;return e?"-"+c:c}return t}if(n.startsWith("0")){const s=n.replace(/^0+/,"")||"0";return e?"-"+s:s}return t}function te(t,e="."){return t&&(t===e?"0"+e:t==="-"+e?"-0"+e:t.startsWith("-"+e)?"-0"+t.slice(1):t.startsWith(e)?"0"+t:t)}function ne(t,e,n="."){if(e<0||t.length<=e)return t;let r=t.slice(0,e);return r.endsWith(n)&&(r=r.slice(0,-1)),r==="-"?"":r}function re(t){return t.replace(/[\s\u200B]/g,"")}function se(t){return t.replace(/[\uFF10-\uFF19]/g,e=>String.fromCharCode(e.charCodeAt(0)-65248))}function A(t,e){return t.replace(B(M(e)),"")}const ie=(t,e)=>{let n=re(t);return e!=null&&e.thousandSeparator&&(n=A(n,e.thousandSeparator)),n=se(n),e!=null&&e.enableCompactNotation&&(n=F(n)),n=V(n),n=Q(n,e==null?void 0:e.enableNegative,e==null?void 0:e.decimalSeparator),n=Y(n,e==null?void 0:e.decimalSeparator),e!=null&&e.enableLeadingZeros||(n=ee(n)),e!=null&&e.autoAddLeadingZero&&(n=te(n,e==null?void 0:e.decimalSeparator)),(e==null?void 0:e.maxLength)!==void 0&&(n=ne(n,e.maxLength,e==null?void 0:e.decimalSeparator)),n},v={thousand:{size:3},lakh:{firstGroup:3,restGroup:2},wan:{size:4}},je=/^(0+)/;function ae(t,e,n=y.Thousand,r=!1,s="."){if(!t||t==="0"||t===s||t==="-"||t===`-${s}`)return t;const i=t.includes(s),a=t.startsWith("-"),c=a?t.slice(1):t,[h,l]=c.split(s);if(!h){const u=l?`${s}${l}`:c;return a?`-${u}`:u}if(r&&h.startsWith("0")&&h.length>1){const u=h.match(je);if(u){const E=u[1],p=h.slice(E.length);if(p){const D=P(p,e,n),S=E+D,d=a?"-":"";return i?l?`${d}${S}${s}${l}`:`${d}${S}${s}`:`${d}${S}`}}}const o=P(h,e,n),f=a?"-":"";return i?l?`${f}${o}${s}${l}`:`${f}${o}${s}`:`${f}${o}`}function P(t,e,n){if(t==="0"||t==="")return t;switch(n){case y.None:return t;case y.Thousand:return j(t,e,v.thousand.size);case y.Lakh:return ze(t,e);case y.Wan:return j(t,e,v.wan.size);default:return t}}function ze(t,e){if(t.length<=v.lakh.firstGroup)return t;const n=[],r=t.length-v.lakh.firstGroup;n.unshift(t.slice(r));for(let s=r;s>0;s-=v.lakh.restGroup)n.unshift(t.slice(Math.max(0,s-v.lakh.restGroup),s));return n.join(e)}function j(t,e,n){const r=[];for(let s=t.length;s>0;s-=n)r.unshift(t.slice(Math.max(0,s-n),s));return r.join(e)}function C(t,e,n){let r=0;for(let s=0;s<e&&s<t.length;s++)t[s]!==n&&r++;return r}function He(t,e,n){if(e===0)return 0;let r=0;for(let s=0;s<t.length;s++)if(t[s]!==n){if(r===e-1)return s+1;r++}return t.length}function k(t,e,n){if(e===0)return 0;let r=0;for(let s=0;s<t.length;s++)if(t[s]!==n){if(r++,r===e)return s+1;if(r>e)return s}return t.length}function ce(t,e,n){return e<0||e>=t.length?!1:t[e]===n}const Xe=/\d/;function Je(t,e={}){const{thousandSeparator:n,decimalSeparator:r=".",prefix:s="",suffix:i=""}=e,a=new Array(t.length+1).fill(!0);if(s&&a.fill(!1,0,s.length),i){const c=t.length-i.length;a.fill(!1,c+1,t.length+1)}for(let c=0;c<t.length;c++){const h=t[c];(n&&h===n||h===r)&&(a[c]=!1,c+1<t.length&&!Xe.test(t[c+1])&&(a[c+1]=!1))}return a.some(c=>c)||a.fill(!0),a}function G(t,e,n,r){const s=t.length;if(e=Math.max(0,Math.min(e,s)),r==="left"){for(;e>=0&&!n[e];)e--;e===-1&&(e=n.indexOf(!0))}else if(r==="right"){for(;e<=s&&!n[e];)e++;e>s&&(e=n.lastIndexOf(!0))}else if(!n[e]){let i=e;for(;i<=s&&!n[i];)i++;let a=e;for(;a>=0&&!n[a];)a--;i<=s&&a>=0?e=e-a<i-e?a:i:i<=s?e=i:a>=0&&(e=a)}return(e===-1||e>s)&&(e=s),e}const z=/(\d+\.?\d*)\s*[kmbt]$/i,Ke=(t,e)=>t===e;function qe(t,e,n,r,s,i,a=".",c={}){if(n<0)return 0;if(n>t.length||t===""||e===""||z.test(t)&&!z.test(e)&&e.length>t.length&&n>=t.length-1)return e.length;const h=e.length<t.length,l=ce(t,n,r),o=t.indexOf(a),f=e.indexOf(a);if(c.isCharacterEquivalent&&t!==e){const S={thousandSeparator:r||void 0,...c},d=Ye(t,e,n,c.isCharacterEquivalent||Ke,i,S);if(d!==void 0)return d}const E=new Map,p=(S,d,g)=>{const w=`${S===t?"o":"n"}:${d}`;return E.has(w)||E.set(w,C(S,d,r)),E.get(w)};if(h)return Qe(t,e,n,r,l,o,f,i,c,p);const D=et(t,e,n,r,l,p);return c.boundary?G(e,D,c.boundary):D}function Ye(t,e,n,r,s,i){const a=t.length,c=e.length;let h=0,l=0,o=c;for(let d=0;d<a;d++){let g=-1;for(let w=h;w<c;w++)if(r(t[d],e[w],{oldValue:t,newValue:e,typedRange:s,oldIndex:d,newIndex:w})){g=w;break}g!==-1&&(h=g+1,d<n?l=g+1:o===c&&/\d/.test(t[d])&&(o=g))}if(l>o)return o;const f=e.length<t.length||s!==void 0&&s.isDelete===!1;let u,E=!1,p=!1;if(f){u=l;const d=i.thousandSeparator,g=i.decimalSeparator??".",w=u<e.length?e[u]:"";d&&w===d?(n>0?t[n-1]:"")===d?(u=o,E=!0):p=!0:w===g&&(p=!0)}else u=n-l<o-n?l:o;const D=f&&!E?"left":"right";if(i.boundary)return p?u:G(e,u,i.boundary,D);const S=i.thousandSeparator;if(!p&&S&&u>=0&&u<e.length&&e[u]===S)if(f&&!E)for(;u>0&&e[u]===S;)u--;else for(;u<e.length&&e[u]===S;)u++;return u}function Qe(t,e,n,r,s,i,a,c,h={},l=C){if(s)return Oe(t,e,n,r,a,l);const o=l(t,n,r),f=l(t,t.length,r),u=l(e,e.length,r),E=f-u,p=Ve(t,n,r,o,E,i,c,l),D=i===-1||n<=i,S=Fe(e,p,r,E,c,D,a,l);return h.boundary?G(e,S,h.boundary):S}function Oe(t,e,n,r,s,i=C){const a=n+1;if(a<t.length){const c=i(t,a,r),h=He(e,c,r);return h<e.length&&e[h]!==r?h+1:h}return n}function Ve(t,e,n,r,s,i,a,c=C){if(a){const{start:l,isDelete:o}=a;return o?c(t,l,n):Math.max(0,c(t,l,n))}return e>0&&t[e-1]===n&&s>0?r+1:r}function H(t,e,n,r,s,i,a=C){if(e>0&&e<t.length&&a(t,e,r)===n){if(t[e]===r&&i&&s>0&&e<t.length-1)return e+1;if(!i&&s>0&&e<t.length-1)return Math.min(e+1,t.length)}return e}function Fe(t,e,n,r,s,i,a,c=C){if(i&&a!==-1){const l=t.substring(0,a),o=c(l,l.length,n);if(e<=o){const f=k(l,e,n);return H(l,f,e,n,r,s,c)}}const h=k(t,e,n);return H(t,h,e,n,r,s,c)}function et(t,e,n,r,s,i=C){const a=n>=t.length,c=i(t,n,r),h=i(t,t.length,r),l=i(e,e.length,r);if(a||c===h)return e.length;const o=l-h;let f=c;o>0&&!a&&c<h&&(f=c+1);const u=k(e,f,r);return s&&!ce(e,u,r)?Math.max(0,u-1):u}function tt(t,e,n){const{selectionStart:r,selectionEnd:s,endOffset:i=0}=t;if(r!==s){const o=s-r;return{start:r,end:s,deletedLength:o,isDelete:!1}}if(i>0){const o=i;return{start:r,end:r+o,deletedLength:o,isDelete:!0}}const c=e.length,h=n.length,l=c-h;if(!(l<=0))return{start:r,end:r+l,deletedLength:l,isDelete:!1}}function nt(t,e){if(t===e)return;let n=0;for(;n<t.length&&n<e.length&&t[n]===e[n];)n++;let r=t.length-1,s=e.length-1;for(;r>=n&&s>=n&&t[r]===e[s];)r--,s--;const i=r-n+1,a=s-n+1;if(!(i===0&&a===0))return{start:n,end:r+1,deletedLength:i,isDelete:i>a}}function le(t,e,n,r){const s=A(t,r);return s===t?null:{raw:s,rawStart:A(t.slice(0,e),r).length,rawEnd:A(t.slice(0,n),r).length}}function rt(t,e,n){if((n==null?void 0:n.formatOn)!==I.Change||!n.thousandSeparator)return;const{selectionStart:r,selectionEnd:s,value:i}=e;if(r===null||s===null||r!==s)return;const{key:a}=t,c=n.thousandSeparator;a==="Backspace"&&r>0&&i[r-1]===c&&e.setSelectionRange(r-1,r-1),a==="Delete"&&i[r]===c&&e.setSelectionRange(r+1,r+1)}function he(t,e,n,r,s,i){if(!r)return null;const{selectionStart:a=0,selectionEnd:c=0,endOffset:h=0}=r;let l=tt({selectionStart:a,selectionEnd:c,endOffset:h},t,e);if(l||(l=nt(t,e)),!l)return null;const o=Je(e,{thousandSeparator:(i==null?void 0:i.thousandSeparator)??s.thousandSeparator,decimalSeparator:s.decimalSeparator}),f={thousandSeparator:(i==null?void 0:i.thousandSeparator)??s.thousandSeparator,decimalSeparator:s.decimalSeparator,isCharacterEquivalent:(p,D)=>{const S=(i==null?void 0:i.thousandSeparator)??s.thousandSeparator;return S&&p===S?!1:p===D},boundary:o},u=(i==null?void 0:i.thousandSeparator)??s.thousandSeparator??",",E=(i==null?void 0:i.thousandStyle)??y.None;return qe(t,e,n,u,E,l,s.decimalSeparator,f)}function oe(t,e,n,r){setTimeout(()=>{t.value===e&&(t.selectionStart!==n||t.selectionEnd!==r)&&t.setSelectionRange(n,r)},0)}function b(t,e,n){const r=t.value;r===e&&t.selectionStart===n&&t.selectionEnd===n||(t.setRangeText(e,0,r.length,"end"),t.setSelectionRange(n,n),oe(t,e,n,n))}function ue(t,e,n,r){t.value===e&&t.selectionStart===n&&t.selectionEnd===r||(t.setRangeText(e,0,t.value.length,"preserve"),t.setSelectionRange(n,r),oe(t,e,n,r))}function $(t,e,n,r){const s=Z(n),a=r??(n==null?void 0:n.formatOn)===I.Change?n:{...n,thousandSeparator:void 0},c=ie(t,a),h=$e(c,e,s.decimalSeparator),l=(n==null?void 0:n.decimalMinLength)??0,o=Re(h,l,s.decimalSeparator);return{formatted:(n==null?void 0:n.formatOn)===I.Change&&!!n.thousandSeparator?ae(o,n.thousandSeparator,n.thousandStyle??y.None,n.enableLeadingZeros,s.decimalSeparator):o,raw:o}}function st(t,e,n){const r=!!(n!=null&&n.thousandSeparator);return $(t,e,n,r)}function de(t,e,n){if(t.inputType===L.InsertFromPaste||t.inputType===L.InsertFromDrop)return{type:"skip"};const r=t.target,s=r.value,i=r.selectionStart??0,a=r.selectionEnd??0,c=Z(n);let h=t.data??"";if(t.inputType===L.InsertText&&(t.data===","||t.data===".")){const d=c.decimalSeparator;if((s.slice(0,i)+s.slice(a)).includes(d))return{type:"reject"};h=d}if(t.inputType===L.InsertText&&/^\d$/.test(h)){const d=c.decimalSeparator,g=s.indexOf(d);if(g!==-1&&i>g){const w=s.length-g-1,W=a-i;if(w-W+1>e)return{type:"reject"}}}let l,o,f=0;const u=i!==a;switch(t.inputType){case L.InsertText:{l=s.slice(0,i)+h+s.slice(a),o=i+h.length;break}case L.DeleteContentBackward:{const d=u?i:Math.max(0,i-1),g=u?a:i;l=s.slice(0,d)+s.slice(g),o=d;break}case L.DeleteContentForward:{const d=u?a:i+1;l=s.slice(0,i)+s.slice(d),o=i,u||(f=1);break}case L.DeleteByCut:case L.DeleteByDrag:{l=s.slice(0,i)+s.slice(a),o=i;break}case L.DeleteSoftLineBackward:case L.DeleteHardLineBackward:{const d=u?i:0;l=s.slice(0,d)+s.slice(a),o=d;break}case L.DeleteSoftLineForward:case L.DeleteHardLineForward:{const d=u?a:s.length;l=s.slice(0,i)+s.slice(d),o=i,u||(f=s.length-i);break}default:return{type:"skip"}}if((n==null?void 0:n.maxLength)!==void 0&&t.inputType===L.InsertText){const d=n.thousandSeparator;if((d?A(l,d).length:l.length)>n.maxLength)return{type:"reject"}}const E=(n==null?void 0:n.formatOn)===I.Change,{formatted:p,raw:D}=$(l,e,n,E);if(n!=null&&n.isAllowed&&!n.isAllowed(D))return{type:"reject"};let S;return l!==p?S=he(l,p,o,{selectionStart:i,selectionEnd:a,endOffset:f},c,n)??o:S=o,{type:"handled",formatted:p,raw:D,cursorPos:S}}function fe(t,e){const n=t.target;if(rt(t,n,e),t.key!=="Backspace"&&t.key!=="Delete")return;const r=n.selectionStart??0,s=n.selectionEnd??0;return{selectionStart:r,selectionEnd:s,endOffset:t.key==="Delete"&&r===s?1:0}}function it(t,e,n,r){const s=r-n;return t+e+s}function Se(t,e,n){var u;const r=t.target,{value:s,selectionStart:i,selectionEnd:a}=r,c=((u=t.clipboardData)==null?void 0:u.getData("text/plain"))||"",h=s.slice(0,i||0)+c+s.slice(a||0),{formatted:l,raw:o}=$(h,e,n,!0);if(n!=null&&n.isAllowed&&!n.isAllowed(o))return{type:"reject"};const f=it(i||0,c.length,h.length,l.length);return{type:"handled",formatted:l,raw:o,cursorPos:f}}function pe(t){var e,n;try{const s=new Intl.NumberFormat(t).formatToParts(123456789e-2);return{decimalSeparator:((e=s.find(i=>i.type==="decimal"))==null?void 0:e.value)??".",thousandSeparator:((n=s.find(i=>i.type==="group"))==null?void 0:n.value)??","}}catch{return{thousandSeparator:",",decimalSeparator:"."}}}function ge(t,e){if(!t)return e;const r=pe(t===!0?void 0:t);return{thousandSeparator:e.thousandSeparator??r.thousandSeparator,decimalSeparator:e.decimalSeparator??r.decimalSeparator}}function Ee(t){m("decimalMaxLength",t.decimalMaxLength),m("decimalMinLength",t.decimalMinLength),at(t.decimalMinLength,t.decimalMaxLength),K("formatOn",t.formatOn,[I.Blur,I.Change]),X("thousandSeparator",t.thousandSeparator),K("thousandStyle",t.thousandStyle,Object.values(y)),X("decimalSeparator",t.decimalSeparator),ct(t.thousandSeparator,t.decimalSeparator),T("enableCompactNotation",t.enableCompactNotation),T("enableNegative",t.enableNegative),T("enableLeadingZeros",t.enableLeadingZeros),T("autoAddLeadingZero",t.autoAddLeadingZero),T("rawValueMode",t.rawValueMode),m("maxLength",t.maxLength),J("isAllowed",t.isAllowed),J("onChange",t.onChange)}function m(t,e){if(e!==void 0&&(typeof e!="number"||!Number.isInteger(e)||e<0))throw new Error(`${t} must be a non-negative integer. Received: ${JSON.stringify(e)}`)}function X(t,e){if(e!==void 0&&(typeof e!="string"||e.length!==1))throw new Error(`${t} must be a single character. Received: ${JSON.stringify(e)}`)}function T(t,e){if(e!==void 0&&typeof e!="boolean")throw new Error(`${t} must be a boolean. Received: ${JSON.stringify(e)}`)}function J(t,e){if(e!==void 0&&typeof e!="function")throw new Error(`${t} must be a function. Received: ${JSON.stringify(e)}`)}function K(t,e,n){if(e!==void 0&&!n.includes(e))throw new Error(`${t} must be one of: ${n.map(r=>`'${r}'`).join(", ")}. Received: ${JSON.stringify(e)}`)}function at(t,e){if(!(t===void 0||e===void 0)&&t>e)throw new Error(`decimalMinLength (${t}) cannot be greater than decimalMaxLength (${e}).`)}function ct(t,e){if(!(t===void 0||e===void 0)&&t===e)throw new Error(`decimalSeparator cannot equal thousandSeparator. Both were ${JSON.stringify(t)}.`)}const lt=new Set(["decimalMaxLength","decimalMinLength","formatOn","thousandSeparator","thousandStyle","decimalSeparator","locale","enableCompactNotation","enableNegative","enableLeadingZeros","autoAddLeadingZero","rawValueMode","maxLength","isAllowed","onChange","value","defaultValue","type","inputMode","spellcheck","autocomplete"]);class ht{constructor(e,n){N(this,"element");N(this,"resolvedOptions");N(this,"rawValue","");N(this,"suppressNextInputEvent",!1);N(this,"pendingMouseStrip",!1);N(this,"caretPositionBeforeChange");Ee(n);const{decimalMaxLength:r=we,decimalMinLength:s=ye,formatOn:i=Ie,thousandSeparator:a,thousandStyle:c=Ae,decimalSeparator:h,locale:l,enableCompactNotation:o=Ce,enableNegative:f=be,enableLeadingZeros:u=ve,autoAddLeadingZero:E=Te,rawValueMode:p=Me,maxLength:D,isAllowed:S,onChange:d}=n,g=ge(l,{thousandSeparator:a,decimalSeparator:h});this.resolvedOptions={decimalMaxLength:r,decimalMinLength:s,formatOn:i,thousandSeparator:g.thousandSeparator??Ne,thousandStyle:c,decimalSeparator:g.decimalSeparator??x,enableCompactNotation:o,enableNegative:f,enableLeadingZeros:u,autoAddLeadingZero:E,rawValueMode:p,maxLength:D,isAllowed:S,onChange:d},this.createInputElement(e,n),this.setupEventListeners(),this.setDefaultValue()}toRaw(e){const n=this.resolvedOptions.thousandSeparator;return n?A(e,n):e}setDefaultValue(){if(!this.element.value)return;const e=this.toRaw(this.element.value);this.resolvedOptions.rawValueMode&&(this.rawValue=e),this.element.value=this.applyDisplaySeparators(e)}createInputElement(e,n){const r=e instanceof HTMLInputElement;this.element=r?e:document.createElement("input"),this.element.setAttribute("type","text"),this.element.setAttribute("inputmode","decimal"),this.element.setAttribute("spellcheck","false"),this.element.setAttribute("autocomplete","off");const s=M(this.resolvedOptions.decimalSeparator),i=this.resolvedOptions.enableNegative?"-?":"";this.element.setAttribute("pattern",`^${i}[0-9]*[${s}]?[0-9]*$`);const a=Object.fromEntries(Object.entries(n).filter(([c])=>!lt.has(c)));Object.assign(this.element,a),n.value!==void 0?this.element.value=n.value:n.defaultValue!==void 0&&(this.element.defaultValue=n.defaultValue,this.element.value=n.defaultValue),r||e.appendChild(this.element)}setupEventListeners(){this.element.addEventListener("beforeinput",this.handleBeforeInput.bind(this)),this.element.addEventListener("input",this.handleChange.bind(this)),this.element.addEventListener("keydown",this.handleKeyDown.bind(this)),this.element.addEventListener("paste",this.handlePaste.bind(this)),this.resolvedOptions.formatOn===I.Blur&&this.resolvedOptions.thousandSeparator&&(this.element.addEventListener("focus",this.handleFocus.bind(this)),this.element.addEventListener("blur",this.handleBlur.bind(this)),this.element.addEventListener("mousedown",this.handleMouseDown.bind(this)),this.element.addEventListener("click",this.handleClick.bind(this)))}withInternalWrite(e){this.suppressNextInputEvent=!0;try{e()}finally{this.suppressNextInputEvent=!1}}handleValueChange(e,n){if(this.resolvedOptions.rawValueMode&&n!==void 0&&(this.rawValue=n),this.resolvedOptions.onChange){const r=this.resolvedOptions.rawValueMode?this.rawValue:e;this.resolvedOptions.onChange(r)}}applyDisplaySeparators(e){if(!e)return e;const{thousandSeparator:n,thousandStyle:r,enableLeadingZeros:s,decimalSeparator:i}=this.resolvedOptions;return n&&r!==y.None?ae(e,n,r,s,i):e}handleBeforeInput(e){const n=de(e,this.resolvedOptions.decimalMaxLength,this.resolvedOptions);switch(n.type){case"handled":{e.preventDefault(),this.withInternalWrite(()=>b(this.element,n.formatted,n.cursorPos)),this.handleValueChange(n.formatted,n.raw);break}case"reject":e.preventDefault();break}}handleChange(e){if(this.suppressNextInputEvent)return;const n=e.target;if(e instanceof InputEvent&&(e.inputType===L.HistoryUndo||e.inputType===L.HistoryRedo)){const l=this.toRaw(n.value);this.caretPositionBeforeChange=void 0,this.handleValueChange(n.value,l);return}const r=n.value,s=Math.max(n.selectionStart??0,n.selectionEnd??0),i=Z(this.resolvedOptions),a=this.resolvedOptions.formatOn===I.Change,{formatted:c,raw:h}=$(r,this.resolvedOptions.decimalMaxLength,this.resolvedOptions,a);if(r!==c){const l=he(r,c,s,this.caretPositionBeforeChange,i,this.resolvedOptions);this.withInternalWrite(()=>b(n,c,l??c.length))}this.caretPositionBeforeChange=void 0,this.handleValueChange(c,h)}handleKeyDown(e){const n=e.target;this.caretPositionBeforeChange=fe(e,this.resolvedOptions)??{selectionStart:n.selectionStart??0,selectionEnd:n.selectionEnd??0}}handlePaste(e){e.preventDefault();const n=Se(e,this.resolvedOptions.decimalMaxLength,this.resolvedOptions);n.type!=="reject"&&(this.withInternalWrite(()=>b(this.element,n.formatted,n.cursorPos)),this.handleValueChange(n.formatted,n.raw))}stripSeparatorsAndMapCaret(e){const n=this.resolvedOptions.thousandSeparator;if(!n||this.resolvedOptions.thousandStyle===y.None)return;const r=e.selectionStart??0,s=e.selectionEnd??e.value.length,i=le(e.value,r,s,n);i&&(this.withInternalWrite(()=>ue(e,i.raw,i.rawStart,i.rawEnd)),this.handleValueChange(i.raw,i.raw))}handleFocus(e){this.pendingMouseStrip||this.stripSeparatorsAndMapCaret(e.target)}handleMouseDown(){this.pendingMouseStrip=!0}handleClick(e){this.pendingMouseStrip&&(this.pendingMouseStrip=!1,this.stripSeparatorsAndMapCaret(e.target))}handleBlur(e){this.pendingMouseStrip=!1;const n=e.target,{thousandSeparator:r,thousandStyle:s}=this.resolvedOptions;if(!r||s===y.None||!n.value)return;const i=this.applyDisplaySeparators(n.value);i!==n.value&&this.withInternalWrite(()=>b(n,i,i.length));const a=this.resolvedOptions.rawValueMode?this.toRaw(i):void 0;this.handleValueChange(i,a)}getValue(){return this.resolvedOptions.rawValueMode?this.rawValue:this.element.value}setValue(e,n){let r;if(this.resolvedOptions.rawValueMode){const s=this.toRaw(e);this.rawValue=s,r=this.applyDisplaySeparators(s)}else r=e;if((n==null?void 0:n.undoable)===!1){this.element.value=r;return}this.withInternalWrite(()=>b(this.element,r,r.length))}disable(){this.element.disabled=!0}enable(){this.element.disabled=!1}addEventListener(e,n){this.element.addEventListener(e,n)}removeEventListener(e,n){this.element.removeEventListener(e,n)}getElement(){return this.element}get value(){return this.getValue()}set value(e){this.setValue(e)}get valueAsNumber(){const e=this.getValue();if(!e)return NaN;const n=this.toRaw(e),r=this.resolvedOptions.decimalSeparator&&this.resolvedOptions.decimalSeparator!=="."?n.replace(new RegExp(M(this.resolvedOptions.decimalSeparator),"g"),"."):n;return parseFloat(r)}set valueAsNumber(e){if(isNaN(e)){this.setValue("");return}const n=e.toString();this.setValue(n)}}exports.FormatOn=I;exports.InputType=L;exports.NumoraInput=ht;exports.ThousandStyle=y;exports.applyLocale=ge;exports.computeStripSeparatorsResult=le;exports.expandCompactNotation=F;exports.expandScientificNotation=V;exports.filterMobileKeyboardArtifacts=re;exports.formatValueForDisplay=st;exports.getSeparatorsFromLocale=pe;exports.handleOnBeforeInputNumoraInput=de;exports.handleOnKeyDownNumoraInput=fe;exports.handleOnPasteNumoraInput=Se;exports.normalizeFullWidthDigits=se;exports.prependLeadingZero=te;exports.removeExtraDecimalSeparators=Y;exports.removeLeadingZeros=ee;exports.removeNonNumericCharacters=Q;exports.removeThousandSeparators=A;exports.sanitizeNumoraInput=ie;exports.truncateToMaxLength=ne;exports.validateNumoraInputOptions=Ee;exports.writeStripPreservingUndo=ue;exports.writeValuePreservingUndo=b;