numora 3.0.2 → 3.1.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.
- package/README.md +1 -32
- package/dist/features/compact-notation.d.ts +6 -2
- package/dist/features/formatting/cursor-position.d.ts +44 -1
- package/dist/features/formatting/digit-counting.d.ts +35 -12
- package/dist/features/formatting/index.d.ts +0 -4
- package/dist/features/non-numeric-characters.d.ts +1 -0
- package/dist/features/sanitization.d.ts +1 -1
- package/dist/features/scientific-notation.d.ts +4 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +1 -1
- package/dist/index.mjs +538 -875
- package/dist/utils/regex-cache.d.ts +40 -0
- package/dist/validation.d.ts +1 -2
- package/package.json +5 -3
- package/dist/features/formatting/character-equivalence.d.ts +0 -9
- package/dist/features/formatting/large-number.d.ts +0 -39
- package/dist/features/formatting/numeric-formatting-utils.d.ts +0 -24
- package/dist/features/formatting/percent.d.ts +0 -45
- package/dist/features/formatting/subscript-notation.d.ts +0 -20
package/README.md
CHANGED
|
@@ -41,19 +41,6 @@ Check out the [live demo](https://numora.xyz/) to see Numora in action.
|
|
|
41
41
|
| **Sanitization** | Comprehensive input sanitization for security and data integrity |
|
|
42
42
|
| **TypeScript Support** | Full TypeScript definitions included |
|
|
43
43
|
|
|
44
|
-
## Display Formatting Utilities
|
|
45
|
-
|
|
46
|
-
Numora also exports utility functions for formatting numbers for display (outside of the input component):
|
|
47
|
-
|
|
48
|
-
| Utility | Description | Example |
|
|
49
|
-
|---------|-------------|---------|
|
|
50
|
-
| `formatPercent` | Format decimal values as percentages | `formatPercent("0.01", 2)` → `"1.00%"` |
|
|
51
|
-
| `formatLargePercent` | Format large percentages with scale notation (k, M, T, etc.) | `formatLargePercent("1000", 2)` → `"100000%"` |
|
|
52
|
-
| `formatLargeNumber` | Format large numbers with scale notation | `formatLargeNumber("1234")` → `"1.23k"` |
|
|
53
|
-
| `condenseDecimalZeros` | Condense leading decimal zeros to subscript notation | `condenseDecimalZeros("0.000001", 8)` → `"0₆1"` |
|
|
54
|
-
|
|
55
|
-
These utilities use string arithmetic to avoid floating-point precision issues.
|
|
56
|
-
|
|
57
44
|
## 📊 Comparison
|
|
58
45
|
|
|
59
46
|
| Feature | Numora | react-number-format | Native Number Input |
|
|
@@ -63,7 +50,7 @@ These utilities use string arithmetic to avoid floating-point precision issues.
|
|
|
63
50
|
| **Raw Value Mode** | ✅ Yes | ⚠️ Limited | ❌ No |
|
|
64
51
|
| **Comma/Dot Conversion** | ✅ Yes | ⚠️ Limited | ❌ No |
|
|
65
52
|
| **Scientific Notation** | ✅ Auto-expand | ❌ No | ❌ No |
|
|
66
|
-
| **Display Formatting Utils** |
|
|
53
|
+
| **Display Formatting Utils** | ❌ No | ❌ No | ❌ No |
|
|
67
54
|
| **Compact Notation** | ✅ Auto-expand | ❌ No | ❌ No |
|
|
68
55
|
| **Mobile Support** | ✅ Yes | ✅ Yes | ⚠️ Limited |
|
|
69
56
|
| **Decimal Precision Control** | ✅ Yes | ✅ Yes | ❌ Limited |
|
|
@@ -199,24 +186,6 @@ const numoraInput = new NumoraInput(container, {
|
|
|
199
186
|
// This makes it easier for users without knowing the exact separator
|
|
200
187
|
```
|
|
201
188
|
|
|
202
|
-
### Using Display Formatting Utilities
|
|
203
|
-
|
|
204
|
-
```typescript
|
|
205
|
-
import { formatPercent, formatLargePercent, formatLargeNumber, condenseDecimalZeros } from 'numora';
|
|
206
|
-
|
|
207
|
-
// Format as percentage
|
|
208
|
-
const percent = formatPercent('0.01', 2); // "1.00%"
|
|
209
|
-
const largePercent = formatLargePercent('1000', 2); // "100000%"
|
|
210
|
-
|
|
211
|
-
// Format large numbers with scale notation
|
|
212
|
-
const large = formatLargeNumber('1234567'); // "1.23M"
|
|
213
|
-
const small = formatLargeNumber('1234'); // "1.23k"
|
|
214
|
-
|
|
215
|
-
// Condense decimal zeros
|
|
216
|
-
const condensed = condenseDecimalZeros('0.000001', 8); // "0₆1"
|
|
217
|
-
const condensed2 = condenseDecimalZeros('0.000123', 8); // "0₃123"
|
|
218
|
-
```
|
|
219
|
-
|
|
220
189
|
### Programmatic Value Control
|
|
221
190
|
|
|
222
191
|
```typescript
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Static regex patterns for compact notation processing.
|
|
3
|
+
* Defined at module level to avoid recompilation on each function call.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Expands compact notation (k, m, b, t) to full numbers using string manipulation.
|
|
7
|
+
* Handles formats like: 1k, 1.5m, 2B, 1M, 2.5T (case-insensitive)
|
|
4
8
|
* Uses string arithmetic to avoid precision loss with large numbers.
|
|
5
9
|
*
|
|
6
10
|
* @param value - The string value that may contain compact notation
|
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Advanced cursor position calculation for formatted numeric inputs.
|
|
3
3
|
* Handles cursor preservation during formatting changes, insertion, and deletion operations.
|
|
4
|
+
*
|
|
5
|
+
* ## Algorithm Overview
|
|
6
|
+
*
|
|
7
|
+
* The cursor position calculation uses a "meaningful digit" approach:
|
|
8
|
+
* 1. Count the number of actual digits (0-9) before the cursor, ignoring separators
|
|
9
|
+
* 2. After formatting, find the position that has the same number of digits before it
|
|
10
|
+
* 3. Apply adjustments for separator boundaries and special cases
|
|
11
|
+
*
|
|
12
|
+
* ## Processing Flow
|
|
13
|
+
*
|
|
14
|
+
* ```
|
|
15
|
+
* calculateCursorPositionAfterFormatting()
|
|
16
|
+
* ├── Guard clauses (empty values, out of bounds)
|
|
17
|
+
* ├── Compact notation detection (1k → 1000)
|
|
18
|
+
* ├── Character mapping approach (optional, for complex transformations)
|
|
19
|
+
* └── Route to handler based on operation type:
|
|
20
|
+
* ├── handleDeletion() - for backspace/delete operations
|
|
21
|
+
* │ ├── handleSeparatorDeletion() - cursor was on separator
|
|
22
|
+
* │ ├── Calculate target digit count
|
|
23
|
+
* │ └── Find new position + fine-tune for separators
|
|
24
|
+
* └── handleInsertion() - for typing/paste operations
|
|
25
|
+
* ├── Handle cursor at end
|
|
26
|
+
* └── Find position maintaining digit-relative position
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* ## Key Concepts
|
|
30
|
+
*
|
|
31
|
+
* - **Meaningful digits**: Numeric characters (0-9) that represent actual value
|
|
32
|
+
* - **Separators**: Thousand separators that are formatting-only (not part of value)
|
|
33
|
+
* - **Digit index**: The nth digit from the start (ignoring separators)
|
|
34
|
+
* - **ChangeRange**: Info about what was typed/deleted to distinguish Delete vs Backspace
|
|
35
|
+
*
|
|
36
|
+
* ## Edge Cases Handled
|
|
37
|
+
*
|
|
38
|
+
* - Cursor at start/end of input
|
|
39
|
+
* - Cursor on separator during deletion
|
|
40
|
+
* - Delete key vs Backspace key (different cursor behavior)
|
|
41
|
+
* - Compact notation expansion (1k → 1000)
|
|
42
|
+
* - Integer/decimal part transitions
|
|
43
|
+
* - Boundary constraints (prefix/suffix)
|
|
44
|
+
*
|
|
45
|
+
* @module cursor-position
|
|
4
46
|
*/
|
|
5
47
|
import type { ChangeRange } from './constants';
|
|
6
48
|
import { ThousandStyle } from '@/types';
|
|
@@ -15,6 +57,7 @@ export type IsCharacterEquivalent = (char1: string, char2: string, context: {
|
|
|
15
57
|
oldIndex: number;
|
|
16
58
|
newIndex: number;
|
|
17
59
|
}) => boolean;
|
|
60
|
+
export declare const defaultIsCharacterEquivalent: IsCharacterEquivalent;
|
|
18
61
|
/**
|
|
19
62
|
* Options for cursor position calculation.
|
|
20
63
|
*/
|
|
@@ -36,7 +79,7 @@ export interface CursorPositionOptions {
|
|
|
36
79
|
* @param newFormattedValue - The formatted value after formatting
|
|
37
80
|
* @param oldCursorPosition - The cursor position in the old formatted value
|
|
38
81
|
* @param separator - The thousand separator character used in formatting
|
|
39
|
-
*
|
|
82
|
+
* Will be removed in a future major version. Pass any value; it is ignored.
|
|
40
83
|
* @param changeRange - Optional change range info to distinguish Delete vs Backspace
|
|
41
84
|
* @param decimalSeparator - The decimal separator character (default: '.')
|
|
42
85
|
* @param options - Additional options for cursor calculation
|
|
@@ -1,23 +1,48 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Utilities for counting and locating meaningful digits in formatted numbers.
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
|
+
* ## Core Concept
|
|
5
|
+
*
|
|
6
|
+
* "Meaningful digits" are the actual numeric characters (0-9) in a formatted string,
|
|
7
|
+
* excluding formatting characters like thousand separators and decimal points.
|
|
8
|
+
*
|
|
9
|
+
* For example, in "1,234.56":
|
|
10
|
+
* - Meaningful digits: 1, 2, 3, 4, 5, 6 (count = 6)
|
|
11
|
+
* - Non-meaningful: comma (,) and period (.)
|
|
12
|
+
*
|
|
13
|
+
* ## Usage in Cursor Positioning
|
|
14
|
+
*
|
|
15
|
+
* These utilities enable cursor preservation during formatting by:
|
|
16
|
+
* 1. Counting digits before cursor in OLD value
|
|
17
|
+
* 2. Finding position with same digit count in NEW value
|
|
18
|
+
*
|
|
19
|
+
* Example: Typing "0" in "99|" (cursor at end)
|
|
20
|
+
* - Old value: "99" → 2 digits before cursor
|
|
21
|
+
* - User types: "0" → becomes "990"
|
|
22
|
+
* - Formatting: "990" → "990" (no separator yet)
|
|
23
|
+
* - New cursor: position after 3rd digit = position 3
|
|
24
|
+
*
|
|
25
|
+
* Example: Typing "9" in "99|9" → "9,999"
|
|
26
|
+
* - Old value: "999" → 3 digits before cursor at position 2
|
|
27
|
+
* - After formatting: "9,999"
|
|
28
|
+
* - Find position with 3 digits before it → position 4 (after "9,99")
|
|
29
|
+
*
|
|
30
|
+
* @module digit-counting
|
|
4
31
|
*/
|
|
5
32
|
/**
|
|
6
|
-
* Counts meaningful
|
|
33
|
+
* Counts meaningful non-thousand-separator characters (digits and decimal separator) before a position.
|
|
7
34
|
* This is the core digit counting logic used throughout cursor positioning.
|
|
8
35
|
*
|
|
9
36
|
* @param value - The formatted string value
|
|
10
37
|
* @param position - The position to count up to
|
|
11
38
|
* @param separator - The thousand separator character
|
|
12
|
-
* @param decimalSeparator - The decimal separator character (default: '.')
|
|
13
39
|
* @returns The count of meaningful digits before the position
|
|
14
40
|
*
|
|
15
41
|
* @example
|
|
16
42
|
* countMeaningfulDigitsBeforePosition("1,234", 3, ",") // Returns: 2 (digits "1" and "2")
|
|
17
|
-
* countMeaningfulDigitsBeforePosition("1,234.56", 8, ",") // Returns:
|
|
18
|
-
* countMeaningfulDigitsBeforePosition("1.234,56", 8, ".", ",") // Returns: 6
|
|
43
|
+
* countMeaningfulDigitsBeforePosition("1,234.56", 8, ",") // Returns: 7
|
|
19
44
|
*/
|
|
20
|
-
export declare function countMeaningfulDigitsBeforePosition(value: string, position: number, separator: string
|
|
45
|
+
export declare function countMeaningfulDigitsBeforePosition(value: string, position: number, separator: string): number;
|
|
21
46
|
/**
|
|
22
47
|
* Finds the position in the string for a specific digit index.
|
|
23
48
|
* Returns the position AFTER the digit at targetDigitIndex.
|
|
@@ -25,13 +50,12 @@ export declare function countMeaningfulDigitsBeforePosition(value: string, posit
|
|
|
25
50
|
* @param value - The formatted string value
|
|
26
51
|
* @param targetDigitIndex - The zero-based index of the target digit
|
|
27
52
|
* @param separator - The thousand separator character
|
|
28
|
-
* @param decimalSeparator - The decimal separator character (default: '.')
|
|
29
53
|
* @returns The position after the target digit
|
|
30
54
|
*
|
|
31
55
|
* @example
|
|
32
|
-
* findPositionForDigitIndex("1,234",
|
|
56
|
+
* findPositionForDigitIndex("1,234", 3, ",") // Returns: 4 (after digit "3")
|
|
33
57
|
*/
|
|
34
|
-
export declare function findPositionForDigitIndex(value: string, targetDigitIndex: number, separator: string
|
|
58
|
+
export declare function findPositionForDigitIndex(value: string, targetDigitIndex: number, separator: string): number;
|
|
35
59
|
/**
|
|
36
60
|
* Finds the position in the string where the digit count equals targetDigitCount.
|
|
37
61
|
* Returns the position after reaching the target count.
|
|
@@ -39,13 +63,12 @@ export declare function findPositionForDigitIndex(value: string, targetDigitInde
|
|
|
39
63
|
* @param value - The formatted string value
|
|
40
64
|
* @param targetDigitCount - The target number of digits
|
|
41
65
|
* @param separator - The thousand separator character
|
|
42
|
-
* @param decimalSeparator - The decimal separator character (default: '.')
|
|
43
66
|
* @returns The position where digit count equals target
|
|
44
67
|
*
|
|
45
68
|
* @example
|
|
46
|
-
* findPositionWithMeaningfulDigitCount("1,234", 3, ",") // Returns:
|
|
69
|
+
* findPositionWithMeaningfulDigitCount("1,234", 3, ",") // Returns: 4 (after "2,3")
|
|
47
70
|
*/
|
|
48
|
-
export declare function findPositionWithMeaningfulDigitCount(value: string, targetDigitCount: number, separator: string
|
|
71
|
+
export declare function findPositionWithMeaningfulDigitCount(value: string, targetDigitCount: number, separator: string): number;
|
|
49
72
|
/**
|
|
50
73
|
* Checks if a position in the string is on a separator character.
|
|
51
74
|
*
|
|
@@ -14,7 +14,3 @@ export { findChangedRangeFromCaretPositions, findChangeRange } from './change-de
|
|
|
14
14
|
export { getCaretBoundary, getCaretPosInBoundary } from './cursor-boundary';
|
|
15
15
|
export { setCaretPosition, setCaretPositionWithRetry, getInputCaretPosition, updateCursorPosition, skipOverThousandSeparatorOnDelete } from './caret-position-utils';
|
|
16
16
|
export { countMeaningfulDigitsBeforePosition, findPositionForDigitIndex, findPositionWithMeaningfulDigitCount, isPositionOnSeparator, } from './digit-counting';
|
|
17
|
-
export { formatPercent, formatLargePercent } from './percent';
|
|
18
|
-
export { condenseDecimalZeros } from './subscript-notation';
|
|
19
|
-
export { formatLargeNumber, type FormatLargeNumberOptions } from './large-number';
|
|
20
|
-
export { applyDecimalPrecision, applyScaleNotation, compareStrings, isVeryLarge } from './numeric-formatting-utils';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { FormattingOptions, Separators } from '@/types';
|
|
2
2
|
/**
|
|
3
3
|
* Removes all occurrences of thousand separator from a string.
|
|
4
|
-
*
|
|
4
|
+
* Uses cached regex for performance optimization.
|
|
5
5
|
*
|
|
6
6
|
* @param value - The string to remove separators from
|
|
7
7
|
* @param thousandSeparator - The thousand separator character to remove
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static regex patterns for scientific notation processing.
|
|
3
|
+
* Defined at module level to avoid recompilation on each function call.
|
|
4
|
+
*/
|
|
1
5
|
/**
|
|
2
6
|
* Expands scientific notation to decimal notation using string manipulation only.
|
|
3
7
|
* Handles formats like: 1.5e-7, 2e+5, 1.23e-4, etc.
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ export { ThousandStyle, FormatOn } from './types';
|
|
|
3
3
|
export { handleOnChangeNumoraInput, handleOnPasteNumoraInput, handleOnKeyDownNumoraInput, } from './utils/event-handlers';
|
|
4
4
|
export { formatValueForDisplay, formatInputValue, } from './utils/format-utils';
|
|
5
5
|
export type { FormattingOptions, CaretPositionInfo } from './types';
|
|
6
|
-
export { formatPercent, formatLargePercent } from './features/formatting/percent';
|
|
7
|
-
export { formatLargeNumber, type FormatLargeNumberOptions } from './features/formatting/large-number';
|
|
8
|
-
export { condenseDecimalZeros } from './features/formatting/subscript-notation';
|
|
9
6
|
export { removeThousandSeparators } from './features/sanitization';
|
|
7
|
+
export { validateNumoraInputOptions } from './validation';
|
|
8
|
+
export { getNumoraPattern } from './utils/input-pattern';
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var ae=Object.defineProperty;var ce=(e,t,n)=>t in e?ae(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var v=(e,t,n)=>ce(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var $=(e=>(e.Blur="blur",e.Change="change",e))($||{}),m=(e=>(e.None="none",e.Thousand="thousand",e.Lakh="lakh",e.Wan="wan",e))(m||{});const _=2,z=0,Z=$.Blur,B=",",W=m.None,N=".",le=!1,k=!1,U=!1,G=!1;function I(e){return{decimalSeparator:(e==null?void 0:e.decimalSeparator)??N,thousandSeparator:e==null?void 0:e.thousandSeparator}}function K(e,t){const n=e.startsWith("-"),s=n?e.slice(1):e,[o="",r=""]=s.split(t);return{sign:n?"-":"",integer:o,decimal:r}}function he(e,t){if(!e.value.includes(t))return!1;const{selectionStart:n,selectionEnd:s,value:o}=e;return!o.slice(n??0,s??0).includes(t)}function ue(e,t,n){const{key:s}=e;if(s!==","&&s!==".")return!1;if(he(t,n))return!0;if(s!==n){const{selectionStart:o,selectionEnd:r,value:i}=t,a=o??0,c=r??a;t.value=i.slice(0,a)+n+i.slice(c);const l=a+1;return t.setSelectionRange(l,l),!0}return!1}const fe=(e,t,n=N)=>{const{sign:s,integer:o,decimal:r}=K(e,n);if(!e.includes(n))return e;const a=r.slice(0,t);return`${s}${o}${n}${a}`},de=(e,t=N)=>{const n=e.indexOf(t);if(n===-1)return e;const s=e.slice(0,n+1),r=e.slice(n+1).split(",").join("").split(".").join("").split(t).join("");return s+r},ge=(e,t=0,n=N)=>{if(t<=0)return e;const{sign:s,integer:o,decimal:r}=K(e,n);if(r.length>=t)return e.includes(n)?e:`${s}${o}${n}${r}`;const i=r.padEnd(t,"0");return`${s}${o}${n}${i}`},E={thousand:{size:3},lakh:{firstGroup:3,restGroup:2},wan:{size:4}};function y(e,t,n=m.Thousand,s=!1,o="."){if(!e||e==="0"||e===o||e==="-"||e===`-${o}`)return e;const r=e.includes(o),i=e.startsWith("-"),a=i?e.slice(1):e,[c,l]=a.split(o);if(!c){const f=l?`${o}${l}`:a;return i?`-${f}`:f}if(s&&c.startsWith("0")&&c.length>1){const f=c.match(/^(0+)/);if(f){const d=f[1],g=c.slice(d.length);if(g){const p=j(g,t,n),S=d+p,D=i?"-":"";return r?l?`${D}${S}${o}${l}`:`${D}${S}${o}`:`${D}${S}`}}}const h=j(c,t,n),u=i?"-":"";return r?l?`${u}${h}${o}${l}`:`${u}${h}${o}`:`${u}${h}`}function j(e,t,n){if(e==="0"||e==="")return e;switch(n){case m.None:return e;case m.Thousand:return pe(e,t);case m.Lakh:return me(e,t);case m.Wan:return Se(e,t);default:return e}}function pe(e,t){return q(e,t,E.thousand.size)}function me(e,t){if(e.length<=E.lakh.firstGroup)return e;const n=e.split("").reverse(),s=[],o=n.slice(0,E.lakh.firstGroup).reverse().join("");s.push(o);for(let r=E.lakh.firstGroup;r<n.length;r+=E.lakh.restGroup)s.push(n.slice(r,r+E.lakh.restGroup).reverse().join(""));return s.reverse().join(t)}function Se(e,t){return q(e,t,E.wan.size)}function q(e,t,n){const s=e.split("").reverse(),o=[];for(let r=0;r<s.length;r+=n)o.push(s.slice(r,r+n).reverse().join(""));return o.reverse().join(t)}function $e(e,t,n){return(t==null?void 0:t.formatOn)===$.Change&&t.thousandSeparator?y(e,t.thousandSeparator,t.ThousandStyle??m.None,t.enableLeadingZeros,(n==null?void 0:n.decimalSeparator)??N):e}function b(e,t,n,s="."){let o=0;for(let r=0;r<t&&r<e.length;r++)e[r]!==n&&o++;return o}function be(e,t,n,s="."){if(t===0)return 0;let o=0;for(let r=0;r<e.length;r++)if(e[r]!==n){if(o===t-1)return r+1;o++}return e.length}function A(e,t,n,s="."){if(t===0)return 0;let o=0;for(let r=0;r<e.length;r++)if(e[r]!==n){if(o++,o===t)return r+1;if(o>t)return r}return e.length}function Q(e,t,n){return t<0||t>=e.length?!1:e[t]===n}function Ne(e,t={}){const{thousandSeparator:n,decimalSeparator:s=".",prefix:o="",suffix:r=""}=t,i=Array.from({length:e.length+1}).map(()=>!0);if(o&&i.fill(!1,0,o.length),r){const a=e.length-r.length;i.fill(!1,a+1,e.length+1)}for(let a=0;a<e.length;a++){const c=e[a];(n&&c===n||c===s)&&(i[a]=!1,a+1<e.length&&!/\d/.test(e[a+1])&&(i[a+1]=!1))}return i.some(a=>a)||i.fill(!0),i}function P(e,t,n,s){const o=e.length;if(t=Math.max(0,Math.min(t,o)),!n[t]){let r=t;for(;r<=o&&!n[r];)r++;let i=t;for(;i>=0&&!n[i];)i--;r<=o&&i>=0?t=t-i<r-t?i:r:r<=o?t=r:i>=0&&(t=i)}return(t===-1||t>o)&&(t=o),t}const H=(e,t)=>e===t;function De(e,t,n,s,o,r,i=".",a={}){if(n<0)return 0;if(n>e.length||e===""||t==="")return t.length;const c=/(\d+\.?\d*)\s*[kmbMTOQaqiSxsxSpOoNn]$/i;if(c.test(e)&&!c.test(t)&&t.length>e.length&&n>=e.length-1)return t.length;const l=t.length<e.length,h=Q(e,n,s),u=e.indexOf(i),f=t.indexOf(i);if(a.isCharacterEquivalent&&e!==t){const p=Le(e,t,n,a.isCharacterEquivalent||H,r,a);if(p!==void 0)return p}if(l)return Ee(e,t,n,s,h,u,f,r,i,a);const g=Me(e,t,n,s,h,i);return a.boundary?P(t,g,a.boundary):g}function Le(e,t,n,s,o,r){const i=e.length,a=t.length,c={},l=new Array(i);for(let g=0;g<i;g++){l[g]=-1;for(let p=0;p<a;p++){if(c[p])continue;if(s(e[g],t[p],{oldValue:e,newValue:t,typedRange:o,oldIndex:g,newIndex:p})){l[g]=p,c[p]=!0;break}}}let h=n;for(;h<i&&(l[h]===-1||!/\d/.test(e[h]));)h++;const u=h===i||l[h]===-1?a:l[h];for(h=n-1;h>=0&&l[h]===-1;)h--;const f=h===-1||l[h]===-1?0:l[h]+1;if(f>u)return u;const d=n-f<u-n?f:u;return r.boundary?P(t,d,r.boundary):d}function Ee(e,t,n,s,o,r,i,a,c,l={}){if(o)return we(e,t,n,s,i,c);const h=b(e,n,s,c),u=b(e,e.length,s,c),f=b(t,t.length,s,c),d=u-f,g=ve(e,n,s,h,d,r,a,c),p=r===-1||n<=r,S=ye(t,g,s,d,a,c,p,i);return l.boundary?P(t,S,l.boundary):S}function we(e,t,n,s,o,r){const i=n+1;if(i<e.length){const a=b(e,i,s,r),c=be(t,a,s,r);return c<t.length&&t[c]!==s?c+1:c}return n}function ve(e,t,n,s,o,r,i,a){if(i){const{start:l,isDelete:h}=i;return h?b(e,l,n,a):Math.max(0,b(e,l,n,a))}return t>0&&e[t-1]===n&&o>0?s+1:s}function ye(e,t,n,s,o,r,i,a){if(i&&a!==-1){const l=e.substring(0,a),h=b(l,l.length,n,r);if(t<=h){const u=A(l,t,n,r);if(u>0&&u<l.length&&b(l,u,n,r)===t){if(l[u]===n&&o&&s>0&&u<l.length-1)return u+1;if(!o&&s>0&&u<l.length-1)return Math.min(u+1,l.length)}return u}}const c=A(e,t,n,r);if(c>0&&c<e.length&&b(e,c,n,r)===t){if(e[c]===n&&o&&s>0&&c<e.length-1)return c+1;if(!o&&s>0&&c<e.length-1)return Math.min(c+1,e.length)}return c}function Me(e,t,n,s,o,r){const i=n>=e.length,a=b(e,n,s,r),c=b(e,e.length,s,r),l=b(t,t.length,s,r);if(i||a===c)return t.length;const h=l-c;let u=a;h>0&&!i&&a<c&&(u=a+1);const f=A(t,u,s,r);return o&&!Q(t,f,s)?Math.max(0,f-1):f}function xe(e,t,n){const{selectionStart:s,selectionEnd:o,endOffset:r=0}=e;if(s!==o){const h=o-s;return{start:s,end:o,deletedLength:h,isDelete:!1}}if(r>0){const h=r;return{start:s,end:s+h,deletedLength:h,isDelete:!0}}const a=t.length,c=n.length,l=a-c;if(!(l<=0))return{start:s,end:s+l,deletedLength:l,isDelete:!1}}function Ce(e,t){if(e===t)return;let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;let s=e.length-1,o=t.length-1;for(;s>=n&&o>=n&&e[s]===t[o];)s--,o--;const r=s-n+1,i=o-n+1;if(!(r===0&&i===0))return{start:n,end:s+1,deletedLength:r,isDelete:r>i}}function J(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 Te(e,t,n){return e.selectionStart===0&&e.selectionEnd===e.value.length?null:(J(e,t),setTimeout(()=>{e.value===n&&e.selectionStart!==t&&J(e,t)},0))}function Ae(e){return Math.max(e.selectionStart,e.selectionEnd)}function Ie(e,t,n){if((n==null?void 0:n.formatOn)!==$.Change||!n.thousandSeparator)return;const{selectionStart:s,selectionEnd:o,value:r}=t;if(s===null||o===null||s!==o)return;const{key:i}=e,a=n.thousandSeparator;i==="Backspace"&&s>0&&r[s-1]===a&&t.setSelectionRange(s-1,s-1),i==="Delete"&&r[s]===a&&t.setSelectionRange(s+1,s+1)}function Pe(e,t,n,s,o,r,i){if(!o)return;const{selectionStart:a=0,selectionEnd:c=0,endOffset:l=0}=o;let h=xe({selectionStart:a,selectionEnd:c,endOffset:l},t,n);if(h||(h=Ce(t,n)),!h)return;const u=Ne(n,{thousandSeparator:(i==null?void 0:i.thousandSeparator)??r.thousandSeparator,decimalSeparator:r.decimalSeparator}),f={thousandSeparator:(i==null?void 0:i.thousandSeparator)??r.thousandSeparator,isCharacterEquivalent:H,boundary:u},d=(i==null?void 0:i.thousandSeparator)??r.thousandSeparator??",",g=(i==null?void 0:i.ThousandStyle)??m.None,p=De(t,n,s,d,g,h,r.decimalSeparator,f);Te(e,p,n)}function V(e){const[t,n=""]=e.split(".");return t.length+n.length>30}function X(e,t){const n=e.replace(".",""),s=t.replace(".",""),o=Math.max(n.length,s.length),r=n.padStart(o,"0"),i=s.padStart(o,"0");for(let a=0;a<o;a++){const c=parseInt(r[a],10),l=parseInt(i[a],10);if(c!==l)return c-l}return 0}const Oe=[{suffix:"N",zeros:30},{suffix:"O",zeros:27},{suffix:"Sp",zeros:24},{suffix:"Sx",zeros:21},{suffix:"Qi",zeros:18},{suffix:"Qa",zeros:15},{suffix:"T",zeros:12},{suffix:"B",zeros:9},{suffix:"M",zeros:6},{suffix:"k",zeros:3}];function Y(e,t,n=0){const[s,o=""]=e.split(t),r=s.replace(/^0+/,"")||"0";for(const i of Oe)if(i.zeros>=n&&(r.length>i.zeros||r.length===i.zeros&&o.length>0)){const a=i.zeros;if(r.length>a){const c=r.slice(0,-a),u=(r.slice(-a)+o).replace(/0+$/,"");return{scaledValue:u?`${c}${t}${u}`:c,scaleSuffix:i.suffix}}else{const c=a-r.length,l="0",u=("0".repeat(c)+r+o).replace(/0+$/,"");return{scaledValue:u?`${l}${t}${u}`:l,scaleSuffix:i.suffix}}}return{scaledValue:e,scaleSuffix:""}}function O(e,t,n,s,o=!1,r=!1){if(r&&o&&n>0)return`0${s}${"0".repeat(n)}`;const[i,a=""]=e.split(s);let c;if(t===0)c=i;else if(a.length===0){const l="0".repeat(Math.max(t,n));c=`${i}${s}${l}`}else if(a.length<t){const l=Math.max(t-a.length,n-a.length);c=`${i}${s}${a}${"0".repeat(l)}`}else c=`${i}${s}${a.slice(0,t)}`;if(n>0){const[l,h=""]=c.split(s);if(h.length<n){const u=n-h.length;c=`${l}${s}${h}${"0".repeat(u)}`}}if(n===0)c=c.replace(/(\.[0-9]*?)0+$/,"$1").replace(/\.$/,"");else{const[l,h=""]=c.split(s);if(h){const u=h.replace(/0+$/,""),f=u.length>=n?u:h.slice(0,n);c=f?`${l}${s}${f}`:l}}return c}function F(e,t){return!e||e==="0"||e===t||e==="-"||e===`-${t}`}function ee(e){const t=e.startsWith("-");return{isNegative:t,absoluteValue:t?e.slice(1):e}}function te(e,t){if(!e||e==="0")return"0";const n=e.includes(t),[s,o=""]=n?e.split(t):[e,""];let r;if(o.length<=2){const a=2-o.length;r=s+o+"0".repeat(a)}else r=s+o.slice(0,2)+t+o.slice(2);let i=r.replace(/^0+/,"")||"0";if(i.startsWith(t)&&(i="0"+i),i.includes(t)){const[a,c]=i.split(t);return a==="0"&&!c?"0":i}return i}function Re(e,t){const{decimals:n,decimalSeparator:s,thousandSeparator:o,thousandStyle:r,decimalsMin:i=0}=t;if(F(e,s))return"0";const{isNegative:a,absoluteValue:c}=ee(e),l=te(c,s);let h=l;o&&r!==m.None&&(h=y(l,o,r,!1,s));const u=O(h,n,i,s,!1,e==="0");return`${a?"-":""}${u}`}function _e(e,t=2,n=N,s,o=m.None){const r=Re(e,{decimals:t,decimalSeparator:n,thousandSeparator:s,thousandStyle:o,decimalsMin:t});return r==="0"?"0%":`${r}%`}function ze(e,t=2,n={}){const{missingPlaceholder:s="?",veryLargePlaceholder:o="🔥",decimalsUnder:r=1e3,decimalSeparator:i=N,thousandSeparator:a,thousandStyle:c=m.None}=n;if(e==null||e==="")return s;if(F(e,i))return"0%";const{isNegative:l,absoluteValue:h}=ee(e),u=te(h,i);if(V(u))return o;const{scaledValue:f,scaleSuffix:d}=Y(u,i),p=X(f,r.toString())<0?t:0;let S=f;a&&c!==m.None&&(S=y(f,a,c,!1,i));const D=O(S,p,p,i,!1,!1);return`${l?"-":""}${D}${d}%`}function Ze(e){const t="₀₁₂₃₄₅₆₇₈₉";return e.replace(/[0-9]/g,n=>t[+n])}function Be(e,t=8,n=N){if(!e||!e.includes(n))return e;const s=e.startsWith("-"),o=s?e.slice(1):e,[r,i]=o.split(n);if(!i||!i.length)return e;const a=i.match(/^(0{3,})/);if(!a)return e;const l=a[1].length,h=i.slice(l),u=r==="0"&&l>=5?l+1:l,f=Ze(u.toString());let d=`0${f}${h}`;const g=f.length,p=Math.max(0,t-g-1);h.length>p&&(d=`0${f}${h.slice(0,p)}`),d=d.replace(/0+$/,"");const S=r==="0"?d:`${r}${d}`;return s?`-${S}`:S}const L={minScale:0,decimalsUnder:1e3,decimals:2,decimalsMin:0,decimalsMinAppliesToZero:!1,veryLargePlaceholder:"🔥",decimalSeparator:N};function We(e,t={}){const{minScale:n=L.minScale,decimalsUnder:s=L.decimalsUnder,decimals:o=L.decimals,decimalsMin:r=L.decimalsMin,decimalsMinAppliesToZero:i=L.decimalsMinAppliesToZero,veryLargePlaceholder:a=L.veryLargePlaceholder,decimalSeparator:c=L.decimalSeparator,thousandSeparator:l,thousandStyle:h=m.None}=t;if(!e||e==="0"||e===c||e==="-"||e===`-${c}`)return i&&r>0?`0${c}${"0".repeat(r)}`:"0";const u=e.startsWith("-"),f=u?e.slice(1):e;if(V(f))return a;const{scaledValue:d,scaleSuffix:g}=Y(f,c,n),S=X(d,s.toString())<0?o:0;let D=d;l&&h!==m.None&&(D=y(d,l,h,!1,c));const R=O(D,S,r,c,i,e==="0");return`${u?"-":""}${R}${g}`}function x(e){return e.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}const ke=(e,t=!1,n=".")=>{const s=x(n),o=new RegExp(`[^0-9${s}]`,"g");if(!t)return e.replace(o,"");const r=e.startsWith("-"),i=e.replace(o,"");if(r){if(i.length>0)return"-"+i;if(e==="-")return"-"}return i};function Ue(e){const t=/([+-]?\d+\.?\d*)[eE]([+-]?\d+)/g;let n=e,s;const o=[];for(;(s=t.exec(e))!==null;){const r=s[0],i=s[1],a=parseInt(s[2],10);let c;if(a===0)c=i;else{const l=i.startsWith("-"),h=l?i.slice(1):i,[u,f=""]=h.split(".");a>0?c=Ge(u,f,a):c=je(u,f,Math.abs(a)),l&&(c="-"+c)}o.push({full:r,expanded:c})}for(const{full:r,expanded:i}of o)n=n.replace(r,i);return n}function Ge(e,t,n){const s=e+t;if(s==="0"||s.match(/^0+$/))return"0";const o=t.length;if(n<=o){const i=s.slice(0,e.length+n),a=s.slice(e.length+n);return a?`${i}.${a}`:i}const r=n-o;return s+"0".repeat(r)}function je(e,t,n){const s=e+t;if(s==="0"||s.match(/^0+$/))return"0";const i=e.length-n;if(i<=0){const a=Math.abs(i),c=`0.${"0".repeat(a)}${s}`;return T(c)}if(i<e.length){const a=s.slice(0,i),c=s.slice(i),l=`${a}.${c}`;return T(l)}return T(s)}function T(e){if(!e.includes("."))return e;if(e==="0"||e==="0.")return"0";if(e.startsWith("0.")){const t=e.replace(/\.?0+$/,"");return t==="0"?"0":t||"0"}if(e.startsWith("-0.")){const t=e.replace(/\.?0+$/,"");return t==="-0"||t==="0"?"0":t||"0"}return e.replace(/\.?0+$/,"")||e}function Je(e){const t=/(\d+\.?\d*)\s*(Qa|Qi|Sx|Sp|[kmbMTO]|N)/gi;return e.replace(t,(n,s,o)=>{const r={k:3,K:3,m:6,M:6,b:9,B:9,T:12,t:12};let i;if(o.length>1){const d=o.charAt(0).toUpperCase()+o.slice(1).toLowerCase();i=r[o]||r[d]}else{const d=o.toLowerCase();i=r[o]||r[d]}if(!i)return n;const a=s.startsWith("-"),c=a?s.slice(1):s,[l,h=""]=c.split("."),u=l.replace(/^0+/,"")||"0";let f;if(h.length===0)f=u+"0".repeat(i);else if(h.length<=i){const d=i-h.length;f=u+h+"0".repeat(d)}else{const d=h.slice(0,i),g=h.slice(i);f=u+d+"."+g}return f=f.replace(/^(-?)0+([1-9])/,"$1$2"),f.match(/^-?0+$/)&&(f=a?"-0":"0"),f.includes(".")&&(f=f.replace(/\.?0+$/,"")),a&&!f.startsWith("-")?"-"+f:f})}function Ke(e){if(!e||e==="0"||e==="-0"||e==="-"||e===".")return e;const t=e.startsWith("-"),n=t?e.slice(1):e;if(!n||n==="0"||n===".")return e;if(n.includes(".")){const[o,r]=n.split(".");if(o&&o.length>0){const a=(o.replace(/^0+/,"")||"0")+"."+r;return t?"-"+a:a}return e}if(n.startsWith("0")&&n.length>1){const o=n.replace(/^0+/,"")||"0";return t?"-"+o:o}return e}function qe(e){return e.replace(/[\u00A0\u2000-\u200B\u202F\u205F\u3000]/g," ").replace(/\s/g,"")}function w(e,t){const n=x(t);return e.replace(new RegExp(n,"g"),"")}const Qe=(e,t)=>{let n=qe(e);return t!=null&&t.thousandSeparator&&(n=w(n,t.thousandSeparator)),t!=null&&t.enableCompactNotation&&(n=Je(n)),n=Ue(n),n=ke(n,t==null?void 0:t.enableNegative,t==null?void 0:t.decimalSeparator),n=de(n,(t==null?void 0:t.decimalSeparator)||N),t!=null&&t.enableLeadingZeros||(n=Ke(n)),n};function He(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 C(e,t,n,s){const o=I(n),r=s??(n==null?void 0:n.formatOn)===$.Change,i=Qe(e,He(n,o,r)),a=fe(i,t,o.decimalSeparator),c=(n==null?void 0:n.decimalMinLength)??0,l=ge(a,c,o.decimalSeparator),h=l;return{formatted:$e(l,n,o),raw:h}}function Ve(e,t,n){const s=!!(n!=null&&n.thousandSeparator);return C(e,t,n,s)}function Xe(e,t,n){if(e==="Backspace"||e==="Delete")return e==="Delete"&&t===n?{endOffset:1}:{endOffset:0}}function ne(e,t){const{decimalSeparator:n}=I(t),s=e.target;if(ue(e,s,n)){e.preventDefault();return}return Ie(e,s,t),Xe(e.key,s.selectionStart,s.selectionEnd)}function se(e,t,n,s){const o=e.target,r=o.value,i=Ae(o),a=I(s),c=(s==null?void 0:s.formatOn)===$.Change,{formatted:l,raw:h}=C(r,t,s,c);return o.value=l,r!==l&&Pe(o,r,l,i,n,a,s),{formatted:l,raw:h}}function Ye(e,t,n,s){const o=s-n;return e+t+o}function re(e,t,n){var f;e.preventDefault();const s=e.target,{value:o,selectionStart:r,selectionEnd:i}=s,a=((f=e.clipboardData)==null?void 0:f.getData("text/plain"))||"",c=o.slice(0,r||0)+a+o.slice(i||0),{formatted:l,raw:h}=C(c,t,n,!0);s.value=l;const u=Ye(r||0,a.length,c.length,l.length);return s.setSelectionRange(u,u),{formatted:l,raw:h}}function Fe(e,t){const n=x(e);return t?`^-?[0-9]*[${n}]?[0-9]*$`:`^[0-9]*[${n}]?[0-9]*$`}function et(e){tt(e.decimalMaxLength),nt(e.decimalMinLength),st(e.decimalMinLength,e.decimalMaxLength),rt(e.formatOn),it(e.thousandSeparator),ot(e.thousandStyle),at(e.decimalSeparator),ct(e.thousandSeparator,e.decimalSeparator),M("enableCompactNotation",e.enableCompactNotation),M("enableNegative",e.enableNegative),M("enableLeadingZeros",e.enableLeadingZeros),M("rawValueMode",e.rawValueMode),lt(e.onChange)}function tt(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 nt(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 rt(e){if(e!==void 0&&e!==$.Blur&&e!==$.Change)throw new Error(`formatOn must be either ${$.Blur} or ${$.Change}. Received: ${JSON.stringify(e)}`)}function it(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 ot(e){if(e!==void 0&&!Object.values(m).includes(e))throw new Error(`ThousandStyle must be one of: ${Object.values(m).map(t=>`'${t}'`).join(", ")}. Received: ${JSON.stringify(e)}`)}function at(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 ct(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 lt(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 ht{constructor(t,{decimalMaxLength:n=_,decimalMinLength:s=z,formatOn:o=Z,thousandSeparator:r=B,thousandStyle:i=W,decimalSeparator:a=N,enableCompactNotation:c=!0,enableNegative:l=k,enableLeadingZeros:h=U,rawValueMode:u=G,onChange:f,...d}){v(this,"element");v(this,"options");v(this,"resolvedOptions");v(this,"rawValue","");v(this,"caretPositionBeforeChange");if(et({decimalMaxLength:n,decimalMinLength:s,formatOn:o,thousandSeparator:r,thousandStyle:i,decimalSeparator:a,enableCompactNotation:c,enableNegative:l,enableLeadingZeros:h,rawValueMode:u,onChange:f}),this.options={decimalMaxLength:n,decimalMinLength:s,onChange:f,formatOn:o,thousandSeparator:r,thousandStyle:i,decimalSeparator:a,enableCompactNotation:c,enableNegative:l,enableLeadingZeros:h,rawValueMode:u,...d},this.resolvedOptions=this.getResolvedOptions(),this.createInputElement(t),this.setupEventListeners(),this.resolvedOptions.rawValueMode&&this.element.value){const g=this.element.value,p=this.resolvedOptions.thousandSeparator?w(g,this.resolvedOptions.thousandSeparator):g;this.rawValue=p,this.element.value=this.formatValueForDisplay(p)}else if(this.element.value){const g=this.element.value;this.element.value=this.formatValueForDisplay(g)}}createInputElement(t){if(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"),this.resolvedOptions.decimalSeparator!==void 0&&this.resolvedOptions.enableNegative!==void 0){const oe=Fe(this.resolvedOptions.decimalSeparator,this.resolvedOptions.enableNegative);this.element.setAttribute("pattern",oe)}const{decimalMaxLength:n,decimalMinLength:s,formatOn:o,thousandSeparator:r,thousandStyle:i,decimalSeparator:a,enableCompactNotation:c,enableNegative:l,enableLeadingZeros:h,rawValueMode:u,onChange:f,value:d,defaultValue:g,type:p,inputMode:S,spellcheck:D,autocomplete:R,...ie}=this.options;Object.assign(this.element,ie),d!==void 0?this.element.value=d:g!==void 0&&(this.element.defaultValue=g,this.element.value=g),t.appendChild(this.element)}setupEventListeners(){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===$.Blur&&this.resolvedOptions.thousandSeparator&&(this.element.addEventListener("focus",this.handleFocus.bind(this)),this.element.addEventListener("blur",this.handleBlur.bind(this)))}getResolvedOptions(){return{decimalMaxLength:this.options.decimalMaxLength??_,decimalMinLength:this.options.decimalMinLength??z,formatOn:this.options.formatOn??Z,thousandSeparator:this.options.thousandSeparator??B,thousandStyle:this.options.thousandStyle??W,decimalSeparator:this.options.decimalSeparator??N,enableCompactNotation:this.options.enableCompactNotation??le,enableNegative:this.options.enableNegative??k,enableLeadingZeros:this.options.enableLeadingZeros??U,rawValueMode:this.options.rawValueMode??G,onChange:this.options.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 s=this.resolvedOptions.rawValueMode?this.rawValue:t;this.resolvedOptions.onChange(s)}}formatValueForDisplay(t){if(!t)return t;const{thousandSeparator:n,thousandStyle:s,enableLeadingZeros:o,decimalSeparator:r}=this.resolvedOptions;return n&&s!==m.None?y(t,n,s,o,r):t}handleChange(t){const{formatted:n,raw:s}=se(t,this.resolvedOptions.decimalMaxLength,this.caretPositionBeforeChange,this.buildFormattingOptions());this.caretPositionBeforeChange=void 0,this.handleValueChange(n,s)}handleKeyDown(t){const n=t.target,{selectionStart:s,selectionEnd:o}=n,r=this.buildFormattingOptions(),i=ne(t,{formatOn:r.formatOn,thousandSeparator:r.thousandSeparator,ThousandStyle:r.ThousandStyle,decimalSeparator:r.decimalSeparator});i?this.caretPositionBeforeChange={selectionStart:s??0,selectionEnd:o??0,endOffset:i.endOffset}:this.caretPositionBeforeChange={selectionStart:s??0,selectionEnd:o??0}}handlePaste(t){const{formatted:n,raw:s}=re(t,this.resolvedOptions.decimalMaxLength,this.buildFormattingOptions());this.handleValueChange(n,s);const o=new Event("input",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(o)}handleFocus(t){if(this.resolvedOptions.formatOn===$.Blur&&this.resolvedOptions.thousandSeparator){const n=t.target;n.value=w(n.value,this.resolvedOptions.thousandSeparator)}}handleBlur(t){const n=t.target,{thousandSeparator:s,thousandStyle:o}=this.resolvedOptions;if(s&&o!==m.None&&n.value){n.value;const r=this.formatValueForDisplay(n.value);n.value=r;const i=this.resolvedOptions.rawValueMode?w(r,s):void 0;this.handleValueChange(r,i)}}getValue(){return this.resolvedOptions.rawValueMode?this.rawValue:this.element.value}setValue(t){if(this.resolvedOptions.rawValueMode){const n=this.resolvedOptions.thousandSeparator?w(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?w(t,this.resolvedOptions.thousandSeparator):t,s=this.resolvedOptions.decimalSeparator&&this.resolvedOptions.decimalSeparator!=="."?n.replace(new RegExp(x(this.resolvedOptions.decimalSeparator),"g"),"."):n;return parseFloat(s)}set valueAsNumber(t){if(isNaN(t)){this.setValue("");return}const n=t.toString();this.setValue(n)}}exports.FormatOn=$;exports.NumoraInput=ht;exports.ThousandStyle=m;exports.condenseDecimalZeros=Be;exports.formatInputValue=C;exports.formatLargeNumber=We;exports.formatLargePercent=ze;exports.formatPercent=_e;exports.formatValueForDisplay=Ve;exports.handleOnChangeNumoraInput=se;exports.handleOnKeyDownNumoraInput=ne;exports.handleOnPasteNumoraInput=re;exports.removeThousandSeparators=w;
|
|
1
|
+
"use strict";var ce=Object.defineProperty;var le=(e,t,n)=>t in e?ce(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var D=(e,t,n)=>le(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||{}),E=(e=>(e.None="none",e.Thousand="thousand",e.Lakh="lakh",e.Wan="wan",e))(E||{});const x=2,G=0,Z=m.Blur,P=",",k=E.None,L=".",B=!1,W=!1,U=!1,z=!1;function w(e){return e.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}const J=new Map;function T(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 he(e,t="g"){const n=w(e);return T(n,t)}const ue=/[.,]/g;function O(e){return{decimalSeparator:(e==null?void 0:e.decimalSeparator)??L,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}}function de(e,t){if(!e.value.includes(t))return!1;const{selectionStart:n,selectionEnd:r,value:i}=e;return!i.slice(n??0,r??0).includes(t)}function fe(e,t,n){const{key:r}=e;if(r!==","&&r!==".")return!1;if(de(t,n))return!0;if(r!==n){const{selectionStart:i,selectionEnd:s,value:a}=t,o=i??0,l=s??o;t.value=a.slice(0,o)+n+a.slice(l);const c=o+1;return t.setSelectionRange(c,c),!0}return!1}const ge=(e,t,n=L)=>{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}`},Se=(e,t=L)=>{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===","?ue:T("[,\\."+w(t)+"]","g");return r+i.replace(a,"")},Ee=(e,t=0,n=L)=>{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}`},v={thousand:{size:3},lakh:{firstGroup:3,restGroup:2},wan:{size:4}},pe=/^(0+)/;function Q(e,t,n=E.Thousand,r=!1,i="."){if(!e||e==="0"||e===i||e==="-"||e===`-${i}`)return e;const s=e.includes(i),a=e.startsWith("-"),o=a?e.slice(1):e,[l,c]=o.split(i);if(!l){const u=c?`${i}${c}`:o;return a?`-${u}`:u}if(r&&l.startsWith("0")&&l.length>1){const u=l.match(pe);if(u){const g=u[1],f=l.slice(g.length);if(f){const S=X(f,t,n),p=g+S,b=a?"-":"";return s?c?`${b}${p}${i}${c}`:`${b}${p}${i}`:`${b}${p}`}}}const h=X(l,t,n),d=a?"-":"";return s?c?`${d}${h}${i}${c}`:`${d}${h}${i}`:`${d}${h}`}function X(e,t,n){if(e==="0"||e==="")return e;switch(n){case E.None:return e;case E.Thousand:return j(e,t,v.thousand.size);case E.Lakh:return me(e,t);case E.Wan:return j(e,t,v.wan.size);default:return e}}function me(e,t){if(e.length<=v.lakh.firstGroup)return e;const n=[],r=e.length-v.lakh.firstGroup;n.unshift(e.slice(r));for(let i=r;i>0;i-=v.lakh.restGroup)n.unshift(e.slice(Math.max(0,i-v.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 be(e,t,n){return(t==null?void 0:t.formatOn)===m.Change&&t.thousandSeparator?Q(e,t.thousandSeparator,t.ThousandStyle??E.None,t.enableLeadingZeros,(n==null?void 0:n.decimalSeparator)??L):e}function $(e,t,n){let r=0;for(let i=0;i<t&&i<e.length;i++)e[i]!==n&&r++;return r}function Ne(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 Le=/\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 o=e.length-s.length;a.fill(!1,o+1,e.length+1)}for(let o=0;o<e.length;o++){const l=e[o];(n&&l===n||l===r)&&(a[o]=!1,o+1<e.length&&!Le.test(e[o+1])&&(a[o+1]=!1))}return a.some(o=>o)||a.fill(!0),a}function _(e,t,n,r){const i=e.length;if(t=Math.max(0,Math.min(t,i)),!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,F=(e,t)=>e===t;function De(e,t,n,r,i,s,a=".",o={}){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 l=t.length<e.length,c=V(e,n,r),h=e.indexOf(a),d=t.indexOf(a);if(o.isCharacterEquivalent&&e!==t){const p=ve(e,t,n,o.isCharacterEquivalent||F,s,o);if(p!==void 0)return p}const g=new Map,f=(p,b,ae)=>{const C=`${p===e?"o":"n"}:${b}`;return g.has(C)||g.set(C,$(p,b,r)),g.get(C)};if(l)return we(e,t,n,r,c,h,d,s,o,f);const S=Me(e,t,n,r,c,f);return o.boundary?_(t,S,o.boundary):S}function ve(e,t,n,r,i,s){const a=e.length,o=t.length;let l=0,c=0,h=o;for(let u=0;u<a;u++){let g=-1;for(let f=l;f<o;f++)if(r(e[u],t[f],{oldValue:e,newValue:t,typedRange:i,oldIndex:u,newIndex:f})){g=f;break}g!==-1&&(l=g+1,u<n?c=g+1:h===o&&/\d/.test(e[u])&&(h=g))}if(c>h)return h;const d=n-c<h-n?c:h;return s.boundary?_(t,d,s.boundary):d}function we(e,t,n,r,i,s,a,o,l={},c=$){if(i)return Ce(e,t,n,r,a,c);const h=c(e,n,r),d=c(e,e.length,r),u=c(t,t.length,r),g=d-u,f=ye(e,n,r,h,g,s,o,c),S=s===-1||n<=s,p=Ie(t,f,r,g,o,S,a,c);return l.boundary?_(t,p,l.boundary):p}function Ce(e,t,n,r,i,s=$){const a=n+1;if(a<e.length){const o=s(e,a,r),l=Ne(t,o,r);return l<t.length&&t[l]!==r?l+1:l}return n}function ye(e,t,n,r,i,s,a,o=$){if(a){const{start:c,isDelete:h}=a;return h?o(e,c,n):Math.max(0,o(e,c,n))}return t>0&&e[t-1]===n&&i>0?r+1:r}function q(e,t,n,r,i,s,a=$){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 Ie(e,t,n,r,i,s,a,o=$){if(s&&a!==-1){const c=e.substring(0,a),h=o(c,c.length,n);if(t<=h){const d=R(c,t,n);return q(c,d,t,n,r,i,o)}}const l=R(e,t,n);return q(e,l,t,n,r,i,o)}function Me(e,t,n,r,i,s=$){const a=n>=e.length,o=s(e,n,r),l=s(e,e.length,r),c=s(t,t.length,r);if(a||o===l)return t.length;const h=c-l;let d=o;h>0&&!a&&o<l&&(d=o+1);const u=R(t,d,r);return i&&!V(t,u,r)?Math.max(0,u-1):u}function Ae(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 o=t.length,l=n.length,c=o-l;if(!(c<=0))return{start:r,end:r+c,deletedLength:c,isDelete:!1}}function Re(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 Te(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 Oe(e){return Math.max(e.selectionStart,e.selectionEnd)}function _e(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,o=n.thousandSeparator;a==="Backspace"&&r>0&&s[r-1]===o&&t.setSelectionRange(r-1,r-1),a==="Delete"&&s[r]===o&&t.setSelectionRange(r+1,r+1)}function xe(e,t,n,r,i,s,a){if(!i)return;const{selectionStart:o=0,selectionEnd:l=0,endOffset:c=0}=i;let h=Ae({selectionStart:o,selectionEnd:l,endOffset:c},t,n);if(h||(h=Re(t,n)),!h)return;const d=$e(n,{thousandSeparator:(a==null?void 0:a.thousandSeparator)??s.thousandSeparator,decimalSeparator:s.decimalSeparator}),u={thousandSeparator:(a==null?void 0:a.thousandSeparator)??s.thousandSeparator,isCharacterEquivalent:F,boundary:d},g=(a==null?void 0:a.thousandSeparator)??s.thousandSeparator??",",f=(a==null?void 0:a.ThousandStyle)??E.None,S=De(t,n,r,g,f,h,s.decimalSeparator,u);Te(e,S,n)}const Ge=(e,t=!1,n=".")=>{const r=w(n),i=T(`[^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+$/,M=/\.?0+$/;function Pe(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,[o,l=""]=a.split("."),c=i>0?ke(o,l,i):Be(o,l,Math.abs(i));return s?"-"+c:c})}function ke(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),o=r.slice(e.length+n);return o?`${a}.${o}`:a}const s=n-i;return r+"0".repeat(s)}function Be(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),o=`0.${"0".repeat(a)}${r}`;return A(o)}if(s<e.length){const a=r.slice(0,s),o=r.slice(s),l=`${a}.${o}`;return A(l)}return A(r)}function A(e){if(!e.includes("."))return e;if(e==="0.")return"0";if(e.startsWith("0.")){const t=e.replace(M,"");return t==="0"?"0":t||"0"}if(e.startsWith("-0.")){const t=e.replace(M,"");return t==="-0"||t==="0"?"0":t||"0"}return e.replace(M,"")||e}const We=/(\d+\.?\d*)\s*([kmbt])/gi,Ue=/^0+/,ze=/^(-?)0+([1-9])/,Je=/^-?0+$/,Xe=/\.?0+$/,je={k:3,m:6,b:9,t:12};function Ke(e){return e.replace(We,(t,n,r)=>{const i=r.toLowerCase(),s=je[i];if(!s)return t;const[a,o=""]=n.split("."),l=a.replace(Ue,"")||"0";let c;if(o.length===0)c=l+"0".repeat(s);else if(o.length<=s){const h=s-o.length;c=l+o+"0".repeat(h)}else{const h=o.slice(0,s),d=o.slice(s);c=l+h+"."+d}return c=c.replace(ze,"$1$2"),Je.test(c)&&(c="0"),c.includes(".")&&(c=c.replace(Xe,"")),c})}function qe(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 o=(i.replace(/^0+/,"")||"0")+"."+s;return t?"-"+o:o}return e}if(n.startsWith("0")){const i=n.replace(/^0+/,"")||"0";return t?"-"+i:i}return e}function He(e){return e.replace(/[\s\u200B]/g,"")}function N(e,t){const n=he(t);return e.replace(n,"")}const Ye=(e,t)=>{let n=He(e);return t!=null&&t.thousandSeparator&&(n=N(n,t.thousandSeparator)),t!=null&&t.enableCompactNotation&&(n=Ke(n)),n=Pe(n),n=Ge(n,t==null?void 0:t.enableNegative,t==null?void 0:t.decimalSeparator),n=Se(n,t==null?void 0:t.decimalSeparator),t!=null&&t.enableLeadingZeros||(n=qe(n)),n};function Qe(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=O(n),s=r??(n==null?void 0:n.formatOn)===m.Change,a=Ye(e,Qe(n,i,s)),o=ge(a,t,i.decimalSeparator),l=(n==null?void 0:n.decimalMinLength)??0,c=Ee(o,l,i.decimalSeparator);return{formatted:be(c,n,i),raw:c}}function Ve(e,t,n){const r=!!(n!=null&&n.thousandSeparator);return I(e,t,n,r)}function Fe(e,t,n){if(e==="Backspace"||e==="Delete")return e==="Delete"&&t===n?{endOffset:1}:{endOffset:0}}function te(e,t){const{decimalSeparator:n}=O(t),r=e.target;if(fe(e,r,n)){e.preventDefault();return}return _e(e,r,t),Fe(e.key,r.selectionStart,r.selectionEnd)}function ne(e,t,n,r){const i=e.target,s=i.value,a=Oe(i),o=O(r),l=(r==null?void 0:r.formatOn)===m.Change,{formatted:c,raw:h}=I(s,t,r,l);return i.value=c,s!==c&&xe(i,s,c,a,n,o,r),{formatted:c,raw:h}}function et(e,t,n,r){const i=r-n;return e+t+i}function re(e,t,n){var u;e.preventDefault();const r=e.target,{value:i,selectionStart:s,selectionEnd:a}=r,o=((u=e.clipboardData)==null?void 0:u.getData("text/plain"))||"",l=i.slice(0,s||0)+o+i.slice(a||0),{formatted:c,raw:h}=I(l,t,n,!0);r.value=c;const d=et(s||0,o.length,l.length,c.length);return r.setSelectionRange(d,d),{formatted:c,raw:h}}function ie(e,t){const n=w(e);return t?`^-?[0-9]*[${n}]?[0-9]*$`:`^[0-9]*[${n}]?[0-9]*$`}function se(e){tt(e.decimalMaxLength),nt(e.decimalMinLength),rt(e.decimalMinLength,e.decimalMaxLength),it(e.formatOn),st(e.thousandSeparator),at(e.thousandStyle),ot(e.decimalSeparator),ct(e.thousandSeparator,e.decimalSeparator),y("enableCompactNotation",e.enableCompactNotation),y("enableNegative",e.enableNegative),y("enableLeadingZeros",e.enableLeadingZeros),y("rawValueMode",e.rawValueMode),lt(e.onChange)}function tt(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 nt(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 rt(e,t){if(!(e===void 0||t===void 0)&&e>t)throw new Error(`decimalMinLength (${e}) cannot be greater than decimalMaxLength (${t}).`)}function it(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 st(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 at(e){if(e!==void 0&&!Object.values(E).includes(e))throw new Error(`ThousandStyle must be one of: ${Object.values(E).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 ct(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 y(e,t){if(t!==void 0&&typeof t!="boolean")throw new Error(`${e} must be a boolean. Received: ${typeof t} (${JSON.stringify(t)})`)}function lt(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 ht{constructor(t,{decimalMaxLength:n=x,decimalMinLength:r=G,formatOn:i=Z,thousandSeparator:s=P,thousandStyle:a=k,decimalSeparator:o=L,enableCompactNotation:l=B,enableNegative:c=W,enableLeadingZeros:h=U,rawValueMode:d=z,onChange:u,...g}){D(this,"element");D(this,"options");D(this,"resolvedOptions");D(this,"rawValue","");D(this,"caretPositionBeforeChange");if(se({decimalMaxLength:n,decimalMinLength:r,formatOn:i,thousandSeparator:s,thousandStyle:a,decimalSeparator:o,enableCompactNotation:l,enableNegative:c,enableLeadingZeros:h,rawValueMode:d,onChange:u}),this.options={decimalMaxLength:n,decimalMinLength:r,onChange:u,formatOn:i,thousandSeparator:s,thousandStyle:a,decimalSeparator:o,enableCompactNotation:l,enableNegative:c,enableLeadingZeros:h,rawValueMode:d,...g},this.resolvedOptions=this.getResolvedOptions(),this.createInputElement(t),this.setupEventListeners(),this.resolvedOptions.rawValueMode&&this.element.value){const f=this.element.value,S=this.resolvedOptions.thousandSeparator?N(f,this.resolvedOptions.thousandSeparator):f;this.rawValue=S,this.element.value=this.formatValueForDisplay(S)}else if(this.element.value){const f=this.element.value;this.element.value=this.formatValueForDisplay(f)}}createInputElement(t){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 n=ie(this.resolvedOptions.decimalSeparator,this.resolvedOptions.enableNegative);this.element.setAttribute("pattern",n);const{decimalMaxLength:r,decimalMinLength:i,formatOn:s,thousandSeparator:a,thousandStyle:o,decimalSeparator:l,enableCompactNotation:c,enableNegative:h,enableLeadingZeros:d,rawValueMode:u,onChange:g,value:f,defaultValue:S,type:p,inputMode:b,spellcheck:ae,autocomplete:C,...oe}=this.options;Object.assign(this.element,oe),f!==void 0?this.element.value=f:S!==void 0&&(this.element.defaultValue=S,this.element.value=S),t.appendChild(this.element)}setupEventListeners(){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(){return{decimalMaxLength:this.options.decimalMaxLength??x,decimalMinLength:this.options.decimalMinLength??G,formatOn:this.options.formatOn??Z,thousandSeparator:this.options.thousandSeparator??P,thousandStyle:this.options.thousandStyle??k,decimalSeparator:this.options.decimalSeparator??L,enableCompactNotation:this.options.enableCompactNotation??B,enableNegative:this.options.enableNegative??W,enableLeadingZeros:this.options.enableLeadingZeros??U,rawValueMode:this.options.rawValueMode??z,onChange:this.options.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!==E.None?Q(t,n,r,i,s):t}handleChange(t){const{formatted:n,raw:r}=ne(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=te(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}=re(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=N(n.value,this.resolvedOptions.thousandSeparator)}}handleBlur(t){const n=t.target,{thousandSeparator:r,thousandStyle:i}=this.resolvedOptions;if(r&&i!==E.None&&n.value){const s=this.formatValueForDisplay(n.value);n.value=s;const a=this.resolvedOptions.rawValueMode?N(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?N(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?N(t,this.resolvedOptions.thousandSeparator):t,r=this.resolvedOptions.decimalSeparator&&this.resolvedOptions.decimalSeparator!=="."?n.replace(new RegExp(w(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=ht;exports.ThousandStyle=E;exports.formatInputValue=I;exports.formatValueForDisplay=Ve;exports.getNumoraPattern=ie;exports.handleOnChangeNumoraInput=ne;exports.handleOnKeyDownNumoraInput=te;exports.handleOnPasteNumoraInput=re;exports.removeThousandSeparators=N;exports.validateNumoraInputOptions=se;
|