numora 3.1.0 → 3.2.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 +33 -213
- package/dist/NumoraInput.d.ts +0 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +238 -207
- package/dist/types.d.ts +2 -1
- package/dist/utils/locale.d.ts +14 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,250 +3,70 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/numora)
|
|
4
4
|
[](https://www.npmjs.com/package/numora)
|
|
5
5
|
|
|
6
|
-
A lightweight, framework-agnostic numeric input library
|
|
6
|
+
A lightweight, framework-agnostic numeric input library. Zero dependencies, TypeScript-first.
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
- **Type safety** - fully typed API for better developer experience
|
|
10
|
-
- **Framework agnostic** - use with any framework or vanilla JavaScript
|
|
11
|
-
- **Customizable** - extensive options to fit your specific needs
|
|
12
|
-
|
|
13
|
-
## Demo
|
|
14
|
-
|
|
15
|
-
Check out the [live demo](https://numora.xyz/) to see Numora in action.
|
|
16
|
-
|
|
17
|
-
## Features
|
|
18
|
-
|
|
19
|
-
| Feature | Description |
|
|
20
|
-
|---------|-------------|
|
|
21
|
-
| **⭐️ Zero Dependencies** | No external dependencies, minimal bundle size |
|
|
22
|
-
| **⭐️ Framework Agnostic** | Works with any framework or vanilla JavaScript |
|
|
23
|
-
| **Decimal Precision Control** | Configure minimum and maximum decimal places (`decimalMinLength`, `decimalMaxLength`) |
|
|
24
|
-
| **Minimum Decimal Places** | Automatically pad values with zeros to ensure minimum decimal places (e.g., `"1"` with `decimalMinLength: 2` becomes `"1.00"`) |
|
|
25
|
-
| **Thousand Separators** | Customizable thousand separators with multiple grouping styles (`Thousand`, `Lakh`, `Wan`, `None`) |
|
|
26
|
-
| **Custom Decimal Separator** | Support for different decimal separators (e.g., `.` or `,`) |
|
|
27
|
-
| **Format on Blur/Change** | Choose when to apply formatting: `on blur (clean editing)` or `on change (real-time)` |
|
|
28
|
-
| **Compact Notation Expansion** | When enabled, expands compact notation during paste/setValue (e.g., `"1k"` → `"1000"`, `"1.5m"` → `"1500000"`, `"2B"` → `"2000000000"`) |
|
|
29
|
-
| **Scientific Notation Expansion** | Always automatically expands scientific notation (e.g., `"1.5e-7"` → `"0.00000015"`, `"2e+5"` → `"200000"`) |
|
|
30
|
-
| **Negative Number Support** | Optional support for negative numbers with `enableNegative` |
|
|
31
|
-
| **Leading Zeros Support** | Control leading zero behavior with `enableLeadingZeros` |
|
|
32
|
-
| **Raw Value Mode** | Get unformatted numeric values while displaying formatted values |
|
|
33
|
-
| **Paste Event Handling** | Intelligent paste handling with automatic sanitization, formatting, and cursor positioning |
|
|
34
|
-
| **Cursor Position Preservation** | Smart cursor positioning that works with thousand separators, even during formatting |
|
|
35
|
-
| **Thousand Separator Skipping** | On delete/backspace, cursor automatically skips over thousand separators for better UX |
|
|
36
|
-
| **Mobile Keyboard Optimization** | Automatic `inputmode="decimal"` for mobile numeric keyboards |
|
|
37
|
-
| **Mobile Keyboard Filtering** | Automatically filters non-breaking spaces and Unicode whitespace artifacts from mobile keyboards |
|
|
38
|
-
| **Non-numeric Character Filtering** | Automatic removal of invalid characters |
|
|
39
|
-
| **Comma/Dot Conversion** | When `thousandStyle` is `None`, typing comma or dot automatically converts to the configured `decimalSeparator` |
|
|
40
|
-
| **Character Equivalence** | Automatic conversion of commas to dots (or custom decimal separator) for easier input |
|
|
41
|
-
| **Sanitization** | Comprehensive input sanitization for security and data integrity |
|
|
42
|
-
| **TypeScript Support** | Full TypeScript definitions included |
|
|
43
|
-
|
|
44
|
-
## 📊 Comparison
|
|
45
|
-
|
|
46
|
-
| Feature | Numora | react-number-format | Native Number Input |
|
|
47
|
-
|---------|--------|---------------------|---------------------|
|
|
48
|
-
| **Framework Support** | ✅ All frameworks | ❌ React only | ✅ All frameworks |
|
|
49
|
-
| **Dependencies** | ✅ Zero | ⚠️ React required | ✅ Zero |
|
|
50
|
-
| **Raw Value Mode** | ✅ Yes | ⚠️ Limited | ❌ No |
|
|
51
|
-
| **Comma/Dot Conversion** | ✅ Yes | ⚠️ Limited | ❌ No |
|
|
52
|
-
| **Scientific Notation** | ✅ Auto-expand | ❌ No | ❌ No |
|
|
53
|
-
| **Display Formatting Utils** | ❌ No | ❌ No | ❌ No |
|
|
54
|
-
| **Compact Notation** | ✅ Auto-expand | ❌ No | ❌ No |
|
|
55
|
-
| **Mobile Support** | ✅ Yes | ✅ Yes | ⚠️ Limited |
|
|
56
|
-
| **Decimal Precision Control** | ✅ Yes | ✅ Yes | ❌ Limited |
|
|
57
|
-
| **Thousand Separators** | ✅ Customizable | ✅ Yes | ❌ No |
|
|
58
|
-
| **Custom Decimal Separator** | ✅ Yes | ✅ Yes | ❌ No (always `.`) |
|
|
59
|
-
| **Formatting Options** | ✅ Blur/Change modes | ✅ Multiple modes | ❌ No |
|
|
60
|
-
| **Cursor Preservation** | ✅ Advanced | ✅ Basic | ❌ N/A |
|
|
61
|
-
| **TypeScript Support** | ✅ Yes | ✅ Yes | ⚠️ Partial |
|
|
62
|
-
| **Paste Handling** | ✅ Intelligent | ✅ Yes | ⚠️ Basic |
|
|
63
|
-
| **Grouping Styles** | ✅ Thousand/Lakh/Wan | ✅ Thousand/Lakh/Wan | ❌ No |
|
|
64
|
-
| **Leading Zeros Control** | ✅ Yes | ✅ Yes | ❌ No |
|
|
65
|
-
|
|
66
|
-
## Installation
|
|
8
|
+
## Install
|
|
67
9
|
|
|
68
10
|
```bash
|
|
69
11
|
npm install numora
|
|
70
|
-
# or
|
|
71
|
-
bun add numora
|
|
72
|
-
# or
|
|
73
|
-
pnpm add numora
|
|
12
|
+
# or pnpm add numora / bun add numora
|
|
74
13
|
```
|
|
75
14
|
|
|
76
15
|
## Usage
|
|
77
16
|
|
|
78
|
-
### Basic Example
|
|
79
|
-
|
|
80
|
-
```typescript
|
|
81
|
-
import { NumoraInput } from 'numora';
|
|
82
|
-
|
|
83
|
-
// Get the container element where you want to mount the input
|
|
84
|
-
const container = document.querySelector('#my-input-container');
|
|
85
|
-
|
|
86
|
-
// Create a new NumoraInput instance
|
|
87
|
-
const numoraInput = new NumoraInput(container, {
|
|
88
|
-
decimalMaxLength: 2,
|
|
89
|
-
onChange: (value) => {
|
|
90
|
-
console.log('Value changed:', value);
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### Advanced Example
|
|
96
|
-
|
|
97
17
|
```typescript
|
|
98
18
|
import { NumoraInput, FormatOn, ThousandStyle } from 'numora';
|
|
99
19
|
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
// Decimal options
|
|
104
|
-
decimalMaxLength: 18,
|
|
105
|
-
decimalMinLength: 2, // Pads with zeros: "1" becomes "1.00"
|
|
106
|
-
decimalSeparator: '.',
|
|
107
|
-
|
|
108
|
-
// Thousand separator options
|
|
20
|
+
const input = new NumoraInput(document.querySelector('#amount'), {
|
|
21
|
+
decimalMaxLength: 2,
|
|
22
|
+
decimalMinLength: 2,
|
|
109
23
|
thousandSeparator: ',',
|
|
110
24
|
thousandStyle: ThousandStyle.Thousand,
|
|
111
|
-
formatOn: FormatOn.
|
|
112
|
-
|
|
113
|
-
// Additional features
|
|
114
|
-
enableCompactNotation: true, // Expands "1k" → "1000" on paste/setValue
|
|
115
|
-
enableNegative: false,
|
|
116
|
-
enableLeadingZeros: false,
|
|
117
|
-
rawValueMode: true, // Get unformatted values in onChange
|
|
118
|
-
|
|
119
|
-
// Standard input properties
|
|
120
|
-
placeholder: 'Enter amount',
|
|
121
|
-
className: 'numora-input',
|
|
122
|
-
|
|
123
|
-
// Event handler
|
|
124
|
-
onChange: (value) => {
|
|
125
|
-
console.log('Raw value:', value); // Unformatted if rawValueMode is true
|
|
126
|
-
console.log('Display value:', numoraInput.value); // Formatted display value
|
|
127
|
-
console.log('As number:', numoraInput.valueAsNumber); // Parsed as number
|
|
128
|
-
},
|
|
129
|
-
});
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### Compact Notation Example
|
|
133
|
-
|
|
134
|
-
```typescript
|
|
135
|
-
import { NumoraInput } from 'numora';
|
|
136
|
-
|
|
137
|
-
const container = document.querySelector('#my-input-container');
|
|
138
|
-
|
|
139
|
-
const numoraInput = new NumoraInput(container, {
|
|
140
|
-
enableCompactNotation: true,
|
|
141
|
-
onChange: (value) => {
|
|
142
|
-
console.log('Value:', value);
|
|
143
|
-
},
|
|
25
|
+
formatOn: FormatOn.Blur,
|
|
26
|
+
onChange: (value) => console.log(value),
|
|
144
27
|
});
|
|
145
28
|
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
|
|
29
|
+
// Get / set value
|
|
30
|
+
input.value = '1234.56';
|
|
31
|
+
console.log(input.valueAsNumber); // 1234.56
|
|
149
32
|
```
|
|
150
33
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
```typescript
|
|
154
|
-
import { NumoraInput } from 'numora';
|
|
155
|
-
|
|
156
|
-
const container = document.querySelector('#my-input-container');
|
|
157
|
-
|
|
158
|
-
const numoraInput = new NumoraInput(container, {
|
|
159
|
-
decimalMaxLength: 18,
|
|
160
|
-
onChange: (value) => {
|
|
161
|
-
console.log('Value:', value);
|
|
162
|
-
},
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
// Scientific notation is ALWAYS automatically expanded
|
|
166
|
-
// User can paste "1.5e-7" and it becomes "0.00000015"
|
|
167
|
-
// User can paste "2e+5" and it becomes "200000"
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
### Comma/Dot Conversion Example
|
|
171
|
-
|
|
172
|
-
```typescript
|
|
173
|
-
import { NumoraInput, ThousandStyle } from 'numora';
|
|
174
|
-
|
|
175
|
-
const container = document.querySelector('#my-input-container');
|
|
176
|
-
|
|
177
|
-
const numoraInput = new NumoraInput(container, {
|
|
178
|
-
decimalSeparator: ',', // European format
|
|
179
|
-
thousandStyle: ThousandStyle.None, // Required for comma/dot conversion
|
|
180
|
-
decimalMaxLength: 2,
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
// When thousandStyle is None:
|
|
184
|
-
// - User types "." → automatically converted to ","
|
|
185
|
-
// - User types "," → automatically converted to ","
|
|
186
|
-
// This makes it easier for users without knowing the exact separator
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
### Programmatic Value Control
|
|
34
|
+
## Features
|
|
190
35
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
// Set a new value
|
|
198
|
-
numoraInput.setValue('1234.56');
|
|
199
|
-
// or
|
|
200
|
-
numoraInput.value = '1234.56';
|
|
201
|
-
|
|
202
|
-
// Set from a number
|
|
203
|
-
numoraInput.valueAsNumber = 1234.56;
|
|
204
|
-
|
|
205
|
-
// Get as a number
|
|
206
|
-
const numericValue = numoraInput.valueAsNumber;
|
|
207
|
-
|
|
208
|
-
// Enable/disable the input
|
|
209
|
-
numoraInput.disable();
|
|
210
|
-
numoraInput.enable();
|
|
211
|
-
|
|
212
|
-
// Access the underlying HTMLInputElement
|
|
213
|
-
const inputElement = numoraInput.getElement();
|
|
214
|
-
inputElement.addEventListener('focus', () => {
|
|
215
|
-
console.log('Input focused');
|
|
216
|
-
});
|
|
217
|
-
```
|
|
36
|
+
- [Sanitization](https://numora.xyz/docs/numora/features/sanitization) - filters invalid characters and mobile keyboard artifacts
|
|
37
|
+
- [Formatting](https://numora.xyz/docs/numora/features/formatting) - thousand separators (Thousand/Lakh/Wan), format on blur or change
|
|
38
|
+
- [Decimals](https://numora.xyz/docs/numora/features/decimals) - min/max decimal places, custom decimal separator, raw value mode
|
|
39
|
+
- [Compact Notation](https://numora.xyz/docs/numora/features/compact-notation) - expands "1k" → "1000" on paste/setValue (opt-in)
|
|
40
|
+
- [Scientific Notation](https://numora.xyz/docs/numora/features/scientific-notation) - always expands "1.5e-7" → "0.00000015" automatically
|
|
41
|
+
- [Leading Zeros](https://numora.xyz/docs/numora/features/leading-zeros) - configurable leading zero behavior
|
|
218
42
|
|
|
219
43
|
## Options
|
|
220
44
|
|
|
221
|
-
The NumoraInput constructor accepts the following options:
|
|
222
|
-
|
|
223
45
|
| Option | Type | Default | Description |
|
|
224
46
|
|--------|------|---------|-------------|
|
|
225
|
-
| `decimalMaxLength` | `number` | `2` | Maximum
|
|
226
|
-
| `decimalMinLength` | `number` | `0` | Minimum
|
|
227
|
-
| `decimalSeparator` | `string` | `'.'` |
|
|
228
|
-
| `thousandSeparator` | `string` | `','` |
|
|
47
|
+
| `decimalMaxLength` | `number` | `2` | Maximum decimal places allowed |
|
|
48
|
+
| `decimalMinLength` | `number` | `0` | Minimum decimal places (pads with zeros) |
|
|
49
|
+
| `decimalSeparator` | `string` | `'.'` | Decimal separator character |
|
|
50
|
+
| `thousandSeparator` | `string` | `','` | Thousand separator character |
|
|
229
51
|
| `thousandStyle` | `ThousandStyle` | `ThousandStyle.None` | Grouping style: `Thousand`, `Lakh`, `Wan`, or `None` |
|
|
230
52
|
| `formatOn` | `FormatOn` | `FormatOn.Blur` | When to apply formatting: `Blur` or `Change` |
|
|
231
|
-
| `enableCompactNotation` | `boolean` | `false` |
|
|
53
|
+
| `enableCompactNotation` | `boolean` | `false` | Expand compact notation on paste/setValue |
|
|
232
54
|
| `enableNegative` | `boolean` | `false` | Allow negative numbers |
|
|
233
|
-
| `enableLeadingZeros` | `boolean` | `false` | Allow leading zeros
|
|
234
|
-
| `rawValueMode` | `boolean` | `false` | Return unformatted values in `onChange`
|
|
235
|
-
| `onChange` | `(value: string) => void` | `undefined` |
|
|
236
|
-
| `value` | `string` | `undefined` | Initial value (controlled
|
|
237
|
-
| `defaultValue` | `string` | `undefined` | Initial
|
|
55
|
+
| `enableLeadingZeros` | `boolean` | `false` | Allow leading zeros |
|
|
56
|
+
| `rawValueMode` | `boolean` | `false` | Return unformatted values in `onChange` |
|
|
57
|
+
| `onChange` | `(value: string) => void` | `undefined` | Called when value changes |
|
|
58
|
+
| `value` | `string` | `undefined` | Initial value (controlled) |
|
|
59
|
+
| `defaultValue` | `string` | `undefined` | Initial value (uncontrolled) |
|
|
238
60
|
|
|
239
|
-
All standard HTMLInputElement properties are also supported (
|
|
61
|
+
All standard `HTMLInputElement` properties are also supported (`placeholder`, `className`, `disabled`, etc.).
|
|
240
62
|
|
|
241
|
-
|
|
63
|
+
## Documentation
|
|
242
64
|
|
|
243
|
-
|
|
65
|
+
Full docs and live demo at [numora.xyz/docs/numora](https://numora.xyz/docs/numora).
|
|
244
66
|
|
|
245
|
-
|
|
67
|
+
## Framework Adapters
|
|
246
68
|
|
|
247
|
-
- **React**: [`numora-react`](../react/README.md)
|
|
248
|
-
- **Vue**: Coming soon
|
|
249
|
-
- **Svelte**: Use the core package directly
|
|
69
|
+
- **React**: [`numora-react`](../react/README.md)
|
|
250
70
|
|
|
251
71
|
## License
|
|
252
72
|
|
package/dist/NumoraInput.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './NumoraInput';
|
|
2
2
|
export { ThousandStyle, FormatOn } from './types';
|
|
3
|
+
export { getSeparatorsFromLocale, resolveLocaleOptions } from './utils/locale';
|
|
3
4
|
export { handleOnChangeNumoraInput, handleOnPasteNumoraInput, handleOnKeyDownNumoraInput, } from './utils/event-handlers';
|
|
4
5
|
export { formatValueForDisplay, formatInputValue, } from './utils/format-utils';
|
|
5
6
|
export type { FormattingOptions, CaretPositionInfo } from './types';
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
1
|
+
"use strict";var oe=Object.defineProperty;var le=(e,t,n)=>t in e?oe(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 p=(e=>(e.Blur="blur",e.Change="change",e))(p||{}),E=(e=>(e.None="none",e.Thousand="thousand",e.Lakh="lakh",e.Wan="wan",e.Locale="locale",e))(E||{});const G=2,Z=0,P=p.Blur,he=",",H=E.None,$=".",k=!1,B=!1,W=!1,U=!1;function y(e){return e.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}const z=new Map;function O(e,t="g"){const n=`${e}:${t}`;let r=z.get(n);return r||(r=new RegExp(e,t),z.set(n,r)),r}function ue(e,t="g"){const n=y(e);return O(n,t)}const de=/[.,]/g;function _(e){return{decimalSeparator:(e==null?void 0:e.decimalSeparator)??$,thousandSeparator:e==null?void 0:e.thousandSeparator}}function Y(e,t){const n=e.startsWith("-"),r=n?e.slice(1):e,[a="",i=""]=r.split(t);return{sign:n?"-":"",integer:a,decimal:i}}function fe(e,t){if(!e.value.includes(t))return!1;const{selectionStart:n,selectionEnd:r,value:a}=e;return!a.slice(n??0,r??0).includes(t)}function ge(e,t,n){const{key:r}=e;if(r!==","&&r!==".")return!1;if(fe(t,n))return!0;if(r!==n){const{selectionStart:a,selectionEnd:i,value:s}=t,c=a??0,l=i??c;t.value=s.slice(0,c)+n+s.slice(l);const o=c+1;return t.setSelectionRange(o,o),!0}return!1}const Se=(e,t,n=$)=>{const{sign:r,integer:a,decimal:i}=Y(e,n);if(!i)return e;const s=i.slice(0,t);return`${r}${a}${n}${s}`},Ee=(e,t=$)=>{const n=e.indexOf(t);if(n===-1||n===e.length-1)return e;const r=e.slice(0,n+1),a=e.slice(n+1),s=t==="."||t===","?de:O("[,\\."+y(t)+"]","g");return r+a.replace(s,"")},me=(e,t=0,n=$)=>{if(t<=0)return e;const{sign:r,integer:a,decimal:i}=Y(e,n);if(i.length>=t)return e;const s=i.padEnd(t,"0");return`${r}${a}${n}${s}`},v={thousand:{size:3},lakh:{firstGroup:3,restGroup:2},wan:{size:4}},pe=/^(0+)/;function Q(e,t,n=E.Thousand,r=!1,a="."){if(!e||e==="0"||e===a||e==="-"||e===`-${a}`)return e;const i=e.includes(a),s=e.startsWith("-"),c=s?e.slice(1):e,[l,o]=c.split(a);if(!l){const u=o?`${a}${o}`:c;return s?`-${u}`:u}if(r&&l.startsWith("0")&&l.length>1){const u=l.match(pe);if(u){const g=u[1],S=l.slice(g.length);if(S){const m=J(S,t,n),f=g+m,b=s?"-":"";return i?o?`${b}${f}${a}${o}`:`${b}${f}${a}`:`${b}${f}`}}}const h=J(l,t,n),d=s?"-":"";return i?o?`${d}${h}${a}${o}`:`${d}${h}${a}`:`${d}${h}`}function J(e,t,n){if(e==="0"||e==="")return e;switch(n){case E.None:return e;case E.Thousand:return X(e,t,v.thousand.size);case E.Lakh:return be(e,t);case E.Wan:return X(e,t,v.wan.size);default:return e}}function be(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 a=r;a>0;a-=v.lakh.restGroup)n.unshift(e.slice(Math.max(0,a-v.lakh.restGroup),a));return n.join(t)}function X(e,t,n){const r=[];for(let a=e.length;a>0;a-=n)r.unshift(e.slice(Math.max(0,a-n),a));return r.join(t)}function Le(e,t,n){return(t==null?void 0:t.formatOn)===p.Change&&t.thousandSeparator?Q(e,t.thousandSeparator,t.ThousandStyle??E.None,t.enableLeadingZeros,(n==null?void 0:n.decimalSeparator)??$):e}function N(e,t,n){let r=0;for(let a=0;a<t&&a<e.length;a++)e[a]!==n&&r++;return r}function Ne(e,t,n){if(t===0)return 0;let r=0;for(let a=0;a<e.length;a++)if(e[a]!==n){if(r===t-1)return a+1;r++}return e.length}function T(e,t,n){if(t===0)return 0;let r=0;for(let a=0;a<e.length;a++)if(e[a]!==n){if(r++,r===t)return a+1;if(r>t)return a}return e.length}function V(e,t,n){return t<0||t>=e.length?!1:e[t]===n}const ve=/\d/;function $e(e,t={}){const{thousandSeparator:n,decimalSeparator:r=".",prefix:a="",suffix:i=""}=t,s=new Array(e.length+1).fill(!0);if(a&&s.fill(!1,0,a.length),i){const c=e.length-i.length;s.fill(!1,c+1,e.length+1)}for(let c=0;c<e.length;c++){const l=e[c];(n&&l===n||l===r)&&(s[c]=!1,c+1<e.length&&!ve.test(e[c+1])&&(s[c+1]=!1))}return s.some(c=>c)||s.fill(!0),s}function x(e,t,n,r){const a=e.length;if(t=Math.max(0,Math.min(t,a)),!n[t]){let i=t;for(;i<=a&&!n[i];)i++;let s=t;for(;s>=0&&!n[s];)s--;i<=a&&s>=0?t=t-s<i-t?s:i:i<=a?t=i:s>=0&&(t=s)}return(t===-1||t>a)&&(t=a),t}const j=/(\d+\.?\d*)\s*[kmbt]$/i,De=(e,t)=>e===t;function ye(e,t,n,r,a,i,s=".",c={}){if(n<0)return 0;if(n>e.length||e===""||t===""||j.test(e)&&!j.test(t)&&t.length>e.length&&n>=e.length-1)return t.length;const l=t.length<e.length,o=V(e,n,r),h=e.indexOf(s),d=t.indexOf(s);if(c.isCharacterEquivalent&&e!==t){const f=we(e,t,n,c.isCharacterEquivalent||De,i,c);if(f!==void 0)return f}const g=new Map,S=(f,b,w)=>{const C=`${f===e?"o":"n"}:${b}`;return g.has(C)||g.set(C,N(f,b,r)),g.get(C)};if(l)return Ce(e,t,n,r,o,h,d,i,c,S);const m=Re(e,t,n,r,o,S);return c.boundary?x(t,m,c.boundary):m}function we(e,t,n,r,a,i){const s=e.length,c=t.length;let l=0,o=0,h=c;for(let u=0;u<s;u++){let g=-1;for(let S=l;S<c;S++)if(r(e[u],t[S],{oldValue:e,newValue:t,typedRange:a,oldIndex:u,newIndex:S})){g=S;break}g!==-1&&(l=g+1,u<n?o=g+1:h===c&&/\d/.test(e[u])&&(h=g))}if(o>h)return h;const d=n-o<h-n?o:h;return i.boundary?x(t,d,i.boundary):d}function Ce(e,t,n,r,a,i,s,c,l={},o=N){if(a)return Ie(e,t,n,r,s,o);const h=o(e,n,r),d=o(e,e.length,r),u=o(t,t.length,r),g=d-u,S=Me(e,n,r,h,g,i,c,o),m=i===-1||n<=i,f=Ae(t,S,r,g,c,m,s,o);return l.boundary?x(t,f,l.boundary):f}function Ie(e,t,n,r,a,i=N){const s=n+1;if(s<e.length){const c=i(e,s,r),l=Ne(t,c,r);return l<t.length&&t[l]!==r?l+1:l}return n}function Me(e,t,n,r,a,i,s,c=N){if(s){const{start:o,isDelete:h}=s;return h?c(e,o,n):Math.max(0,c(e,o,n))}return t>0&&e[t-1]===n&&a>0?r+1:r}function K(e,t,n,r,a,i,s=N){if(t>0&&t<e.length&&s(e,t,r)===n){if(e[t]===r&&i&&a>0&&t<e.length-1)return t+1;if(!i&&a>0&&t<e.length-1)return Math.min(t+1,e.length)}return t}function Ae(e,t,n,r,a,i,s,c=N){if(i&&s!==-1){const o=e.substring(0,s),h=c(o,o.length,n);if(t<=h){const d=T(o,t,n);return K(o,d,t,n,r,a,c)}}const l=T(e,t,n);return K(e,l,t,n,r,a,c)}function Re(e,t,n,r,a,i=N){const s=n>=e.length,c=i(e,n,r),l=i(e,e.length,r),o=i(t,t.length,r);if(s||c===l)return t.length;const h=o-l;let d=c;h>0&&!s&&c<l&&(d=c+1);const u=T(t,d,r);return a&&!V(t,u,r)?Math.max(0,u-1):u}function Te(e,t,n){const{selectionStart:r,selectionEnd:a,endOffset:i=0}=e;if(r!==a){const h=a-r;return{start:r,end:a,deletedLength:h,isDelete:!1}}if(i>0){const h=i;return{start:r,end:r+h,deletedLength:h,isDelete:!0}}const c=t.length,l=n.length,o=c-l;if(!(o<=0))return{start:r,end:r+o,deletedLength:o,isDelete:!1}}function Oe(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,a=t.length-1;for(;r>=n&&a>=n&&e[r]===t[a];)r--,a--;const i=r-n+1,s=a-n+1;if(!(i===0&&s===0))return{start:n,end:r+1,deletedLength:i,isDelete:i>s}}function q(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 _e(e,t,n){return e.selectionStart===0&&e.selectionEnd===e.value.length?null:(q(e,t),setTimeout(()=>{e.value===n&&e.selectionStart!==t&&q(e,t)},0))}function xe(e){return Math.max(e.selectionStart,e.selectionEnd)}function Ge(e,t,n){if((n==null?void 0:n.formatOn)!==p.Change||!n.thousandSeparator)return;const{selectionStart:r,selectionEnd:a,value:i}=t;if(r===null||a===null||r!==a)return;const{key:s}=e,c=n.thousandSeparator;s==="Backspace"&&r>0&&i[r-1]===c&&t.setSelectionRange(r-1,r-1),s==="Delete"&&i[r]===c&&t.setSelectionRange(r+1,r+1)}function Ze(e,t,n,r,a,i,s){if(!a)return;const{selectionStart:c=0,selectionEnd:l=0,endOffset:o=0}=a;let h=Te({selectionStart:c,selectionEnd:l,endOffset:o},t,n);if(h||(h=Oe(t,n)),!h)return;const d=$e(n,{thousandSeparator:(s==null?void 0:s.thousandSeparator)??i.thousandSeparator,decimalSeparator:i.decimalSeparator}),u={thousandSeparator:(s==null?void 0:s.thousandSeparator)??i.thousandSeparator,isCharacterEquivalent:(f,b)=>{const w=(s==null?void 0:s.thousandSeparator)??i.thousandSeparator;return w&&f===w?!1:f===b},boundary:d},g=(s==null?void 0:s.thousandSeparator)??i.thousandSeparator??",",S=(s==null?void 0:s.ThousandStyle)??E.None,m=ye(t,n,r,g,S,h,i.decimalSeparator,u);_e(e,m,n)}const Pe=(e,t=!1,n=".")=>{const r=y(n),a=O(`[^0-9${r}]`,"g");if(!t)return e.replace(a,"");const i=e.startsWith("-"),s=e.replace(a,"");return i&&(s.length>0||e==="-")?"-"+s:s},ke=/([+-]?\d+\.?\d*)[eE]([+-]?\d+)/g,F=/^0+$/,A=/\.?0+$/;function Be(e){return!e.includes("e")&&!e.includes("E")?e:e.replace(ke,(t,n,r)=>{const a=parseInt(r,10);if(a===0)return n;const i=n.startsWith("-"),s=i?n.slice(1):n,[c,l=""]=s.split("."),o=a>0?We(c,l,a):Ue(c,l,Math.abs(a));return i?"-"+o:o})}function We(e,t,n){const r=e+t;if(r==="0"||F.test(r))return"0";const a=t.length;if(n<=a){const s=r.slice(0,e.length+n),c=r.slice(e.length+n);return c?`${s}.${c}`:s}const i=n-a;return r+"0".repeat(i)}function Ue(e,t,n){const r=e+t;if(r==="0"||F.test(r))return"0";const i=e.length-n;if(i<=0){const s=Math.abs(i),c=`0.${"0".repeat(s)}${r}`;return R(c)}if(i<e.length){const s=r.slice(0,i),c=r.slice(i),l=`${s}.${c}`;return R(l)}return R(r)}function R(e){if(!e.includes("."))return e;if(e==="0.")return"0";if(e.startsWith("0.")){const t=e.replace(A,"");return t==="0"?"0":t||"0"}if(e.startsWith("-0.")){const t=e.replace(A,"");return t==="-0"||t==="0"?"0":t||"0"}return e.replace(A,"")||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 a=r.toLowerCase(),i=qe[a];if(!i)return t;const[s,c=""]=n.split("."),l=s.replace(Je,"")||"0";let o;if(c.length===0)o=l+"0".repeat(i);else if(c.length<=i){const h=i-c.length;o=l+c+"0".repeat(h)}else{const h=c.slice(0,i),d=c.slice(i);o=l+h+"."+d}return o=o.replace(Xe,"$1$2"),je.test(o)&&(o="0"),o.includes(".")&&(o=o.replace(Ke,"")),o})}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[a,i]=n.split(".");if(a){const c=(a.replace(/^0+/,"")||"0")+"."+i;return t?"-"+c:c}return e}if(n.startsWith("0")){const a=n.replace(/^0+/,"")||"0";return t?"-"+a:a}return e}function Qe(e){return e.replace(/[\s\u200B]/g,"")}function L(e,t){const n=ue(t);return e.replace(n,"")}const Ve=(e,t)=>{let n=Qe(e);return t!=null&&t.thousandSeparator&&(n=L(n,t.thousandSeparator)),t!=null&&t.enableCompactNotation&&(n=He(n)),n=Be(n),n=Pe(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 M(e,t,n,r){const a=_(n),i=r??(n==null?void 0:n.formatOn)===p.Change,s=Ve(e,Fe(n,a,i)),c=Se(s,t,a.decimalSeparator),l=(n==null?void 0:n.decimalMinLength)??0,o=me(c,l,a.decimalSeparator);return{formatted:Le(o,n,a),raw:o}}function et(e,t,n){const r=!!(n!=null&&n.thousandSeparator);return M(e,t,n,r)}function tt(e,t,n){if(e==="Backspace"||e==="Delete")return e==="Delete"&&t===n?{endOffset:1}:{endOffset:0}}function ee(e,t){const{decimalSeparator:n}=_(t),r=e.target;if(ge(e,r,n)){e.preventDefault();return}return Ge(e,r,t),tt(e.key,r.selectionStart,r.selectionEnd)}function te(e,t,n,r){const a=e.target,i=a.value,s=xe(a),c=_(r),l=(r==null?void 0:r.formatOn)===p.Change,{formatted:o,raw:h}=M(i,t,r,l);return a.value=o,i!==o&&Ze(a,i,o,s,n,c,r),{formatted:o,raw:h}}function nt(e,t,n,r){const a=r-n;return e+t+a}function ne(e,t,n){var u;e.preventDefault();const r=e.target,{value:a,selectionStart:i,selectionEnd:s}=r,c=((u=e.clipboardData)==null?void 0:u.getData("text/plain"))||"",l=a.slice(0,i||0)+c+a.slice(s||0),{formatted:o,raw:h}=M(l,t,n,!0);r.value=o;const d=nt(i||0,c.length,l.length,o.length);return r.setSelectionRange(d,d),{formatted:o,raw:h}}function re(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 a=new Intl.NumberFormat(e).formatToParts(123456789e-2);return{decimalSeparator:((t=a.find(i=>i.type==="decimal"))==null?void 0:t.value)??".",thousandSeparator:((n=a.find(i=>i.type==="group"))==null?void 0:n.value)??","}}catch{return{thousandSeparator:",",decimalSeparator:"."}}}function ie(e){let t=e.thousandSeparator??he,n=e.decimalSeparator??$,r=e.thousandStyle??H;if(e.thousandStyle===E.Locale||e.decimalSeparator==="auto"){const i=ae();e.thousandStyle===E.Locale&&(t=e.thousandSeparator??i.thousandSeparator,n=e.decimalSeparator==="auto"||e.decimalSeparator===void 0?i.decimalSeparator:e.decimalSeparator,r=E.Thousand),e.decimalSeparator==="auto"&&(n=i.decimalSeparator)}return{thousandSeparator:t,thousandStyle:r,decimalSeparator:n}}function se(e){rt(e.decimalMaxLength),at(e.decimalMinLength),it(e.decimalMinLength,e.decimalMaxLength),st(e.formatOn),ct(e.thousandSeparator),ot(e.thousandStyle),lt(e.decimalSeparator),ht(e.thousandSeparator,e.decimalSeparator),I("enableCompactNotation",e.enableCompactNotation),I("enableNegative",e.enableNegative),I("enableLeadingZeros",e.enableLeadingZeros),I("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 at(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 it(e,t){if(!(e===void 0||t===void 0)&&e>t)throw new Error(`decimalMinLength (${e}) cannot be greater than decimalMaxLength (${t}).`)}function st(e){if(e!==void 0&&e!==p.Blur&&e!==p.Change)throw new Error(`formatOn must be either ${p.Blur} or ${p.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 ot(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 lt(e){if(!(e===void 0||e==="auto")){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)&&t!=="auto"&&e===t)throw new Error(`Decimal separator can't be same as thousand separator. thousandSeparator: ${e}, decimalSeparator: ${t}`)}function I(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=G,decimalMinLength:r=Z,formatOn:a=P,thousandSeparator:i,thousandStyle:s=H,decimalSeparator:c,enableCompactNotation:l=k,enableNegative:o=B,enableLeadingZeros:h=W,rawValueMode:d=U,onChange:u,...g}){D(this,"element");D(this,"resolvedOptions");D(this,"rawValue","");D(this,"caretPositionBeforeChange");se({decimalMaxLength:n,decimalMinLength:r,formatOn:a,thousandSeparator:i,thousandStyle:s,decimalSeparator:c,enableCompactNotation:l,enableNegative:o,enableLeadingZeros:h,rawValueMode:d,onChange:u});const S={decimalMaxLength:n,decimalMinLength:r,onChange:u,formatOn:a,thousandSeparator:i,thousandStyle:s,decimalSeparator:c,enableCompactNotation:l,enableNegative:o,enableLeadingZeros:h,rawValueMode:d,...g};if(this.resolvedOptions=this.getResolvedOptions(S),this.createInputElement(t,S),this.setupEventListeners(),this.resolvedOptions.rawValueMode&&this.element.value){const m=this.element.value,f=this.resolvedOptions.thousandSeparator?L(m,this.resolvedOptions.thousandSeparator):m;this.rawValue=f,this.element.value=this.formatValueForDisplay(f)}else if(this.element.value){const m=this.element.value;this.element.value=this.formatValueForDisplay(m)}}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=re(this.resolvedOptions.decimalSeparator,this.resolvedOptions.enableNegative);this.element.setAttribute("pattern",r);const{decimalMaxLength:a,decimalMinLength:i,formatOn:s,thousandSeparator:c,thousandStyle:l,decimalSeparator:o,enableCompactNotation:h,enableNegative:d,enableLeadingZeros:u,rawValueMode:g,onChange:S,value:m,defaultValue:f,type:b,inputMode:w,spellcheck:C,autocomplete:ft,...ce}=n;Object.assign(this.element,ce),m!==void 0?this.element.value=m:f!==void 0&&(this.element.defaultValue=f,this.element.value=f),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===p.Blur&&this.resolvedOptions.thousandSeparator&&(this.element.addEventListener("focus",this.handleFocus.bind(this)),this.element.addEventListener("blur",this.handleBlur.bind(this)))}getResolvedOptions(t){const n=ie({thousandSeparator:t.thousandSeparator,thousandStyle:t.thousandStyle,decimalSeparator:t.decimalSeparator});return{decimalMaxLength:t.decimalMaxLength??G,decimalMinLength:t.decimalMinLength??Z,formatOn:t.formatOn??P,thousandSeparator:n.thousandSeparator,thousandStyle:n.thousandStyle,decimalSeparator:n.decimalSeparator,enableCompactNotation:t.enableCompactNotation??k,enableNegative:t.enableNegative??B,enableLeadingZeros:t.enableLeadingZeros??W,rawValueMode:t.rawValueMode??U,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:a,decimalSeparator:i}=this.resolvedOptions;return n&&r!==E.None?Q(t,n,r,a,i):t}handleChange(t){const{formatted:n,raw:r}=te(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:a}=n,i=this.buildFormattingOptions(),s=ee(t,{formatOn:i.formatOn,thousandSeparator:i.thousandSeparator,ThousandStyle:i.ThousandStyle,decimalSeparator:i.decimalSeparator});s?this.caretPositionBeforeChange={selectionStart:r??0,selectionEnd:a??0,endOffset:s.endOffset}:this.caretPositionBeforeChange={selectionStart:r??0,selectionEnd:a??0}}handlePaste(t){const{formatted:n,raw:r}=ne(t,this.resolvedOptions.decimalMaxLength,this.buildFormattingOptions());this.handleValueChange(n,r);const a=new Event("input",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(a)}handleFocus(t){if(this.resolvedOptions.formatOn===p.Blur&&this.resolvedOptions.thousandSeparator){const n=t.target;n.value=L(n.value,this.resolvedOptions.thousandSeparator)}}handleBlur(t){const n=t.target,{thousandSeparator:r,thousandStyle:a}=this.resolvedOptions;if(r&&a!==E.None&&n.value){const i=this.formatValueForDisplay(n.value);n.value=i;const s=this.resolvedOptions.rawValueMode?L(i,r):void 0;this.handleValueChange(i,s)}}getValue(){return this.resolvedOptions.rawValueMode?this.rawValue:this.element.value}setValue(t){if(this.resolvedOptions.rawValueMode){const n=this.resolvedOptions.thousandSeparator?L(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?L(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=p;exports.NumoraInput=dt;exports.ThousandStyle=E;exports.formatInputValue=M;exports.formatValueForDisplay=et;exports.getNumoraPattern=re;exports.getSeparatorsFromLocale=ae;exports.handleOnChangeNumoraInput=te;exports.handleOnKeyDownNumoraInput=ee;exports.handleOnPasteNumoraInput=ne;exports.removeThousandSeparators=L;exports.resolveLocaleOptions=ie;exports.validateNumoraInputOptions=se;
|