numora 2.0.0 → 2.0.2

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 CHANGED
@@ -1,6 +1,7 @@
1
1
  # numora
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/numora.svg)](https://www.npmjs.com/package/numora)
4
+ [![npm downloads](https://img.shields.io/npm/dm/numora.svg)](https://www.npmjs.com/package/numora)
4
5
 
5
6
  A lightweight, framework-agnostic numeric input library for handling currency and decimal inputs in **financial/DeFi** applications. Built with TypeScript and designed for modern web applications with:
6
7
 
@@ -11,30 +12,84 @@ A lightweight, framework-agnostic numeric input library for handling currency an
11
12
 
12
13
  ## Demo
13
14
 
14
- Check out the [live demo](https://numora.netlify.app/) to see Numora in action.
15
+ Check out the [live demo](https://numora.xyz/) to see Numora in action.
15
16
 
16
17
  ## Features
17
18
 
18
- - Validates and sanitizes numeric input
19
- - Limits decimal places
20
- - Handles paste events
21
- - Converts commas to dots
22
- - Prevents multiple decimal points
23
- - Customizable with various options
24
- - Framework-agnostic core with adapters for popular frameworks
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
+ ## 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
+ ## 📊 Comparison
58
+
59
+ | Feature | Numora | react-number-format | Native Number Input |
60
+ |---------|--------|---------------------|---------------------|
61
+ | **Framework Support** | ✅ All frameworks | ❌ React only | ✅ All frameworks |
62
+ | **Dependencies** | ✅ Zero | ⚠️ React required | ✅ Zero |
63
+ | **Raw Value Mode** | ✅ Yes | ⚠️ Limited | ❌ No |
64
+ | **Comma/Dot Conversion** | ✅ Yes | ⚠️ Limited | ❌ No |
65
+ | **Scientific Notation** | ✅ Auto-expand | ❌ No | ❌ No |
66
+ | **Display Formatting Utils** | ✅ Yes | ❌ No | ❌ No |
67
+ | **Compact Notation** | ✅ Auto-expand | ❌ No | ❌ No |
68
+ | **Mobile Support** | ✅ Yes | ✅ Yes | ⚠️ Limited |
69
+ | **Decimal Precision Control** | ✅ Yes | ✅ Yes | ❌ Limited |
70
+ | **Thousand Separators** | ✅ Customizable | ✅ Yes | ❌ No |
71
+ | **Custom Decimal Separator** | ✅ Yes | ✅ Yes | ❌ No (always `.`) |
72
+ | **Formatting Options** | ✅ Blur/Change modes | ✅ Multiple modes | ❌ No |
73
+ | **Cursor Preservation** | ✅ Advanced | ✅ Basic | ❌ N/A |
74
+ | **TypeScript Support** | ✅ Yes | ✅ Yes | ⚠️ Partial |
75
+ | **Paste Handling** | ✅ Intelligent | ✅ Yes | ⚠️ Basic |
76
+ | **Grouping Styles** | ✅ Thousand/Lakh/Wan | ✅ Thousand/Lakh/Wan | ❌ No |
77
+ | **Leading Zeros Control** | ✅ Yes | ✅ Yes | ❌ No |
25
78
 
26
79
  ## Installation
27
80
 
28
81
  ```bash
29
82
  npm install numora
30
83
  # or
31
- yarn add numora
84
+ bun add numora
32
85
  # or
33
86
  pnpm add numora
34
87
  ```
35
88
 
36
89
  ## Usage
37
90
 
91
+ ### Basic Example
92
+
38
93
  ```typescript
39
94
  import { NumoraInput } from 'numora';
40
95
 
@@ -42,32 +97,187 @@ import { NumoraInput } from 'numora';
42
97
  const container = document.querySelector('#my-input-container');
43
98
 
44
99
  // Create a new NumoraInput instance
45
- const NumoraInput = new NumoraInput(container, {
100
+ const numoraInput = new NumoraInput(container, {
46
101
  decimalMaxLength: 2,
47
102
  onChange: (value) => {
48
103
  console.log('Value changed:', value);
49
- // Do something with the value
50
104
  },
51
- // ... all other input properties you want
105
+ });
106
+ ```
107
+
108
+ ### Advanced Example
109
+
110
+ ```typescript
111
+ import { NumoraInput, FormatOn, ThousandStyle } from 'numora';
112
+
113
+ const container = document.querySelector('#my-input-container');
114
+
115
+ const numoraInput = new NumoraInput(container, {
116
+ // Decimal options
117
+ decimalMaxLength: 18,
118
+ decimalMinLength: 2, // Pads with zeros: "1" becomes "1.00"
119
+ decimalSeparator: '.',
120
+
121
+ // Thousand separator options
122
+ thousandSeparator: ',',
123
+ thousandStyle: ThousandStyle.Thousand,
124
+ formatOn: FormatOn.Change, // or FormatOn.Blur
125
+
126
+ // Additional features
127
+ enableCompactNotation: true, // Expands "1k" → "1000" on paste/setValue
128
+ enableNegative: false,
129
+ enableLeadingZeros: false,
130
+ rawValueMode: true, // Get unformatted values in onChange
131
+
132
+ // Standard input properties
133
+ placeholder: 'Enter amount',
134
+ className: 'numora-input',
135
+
136
+ // Event handler
137
+ onChange: (value) => {
138
+ console.log('Raw value:', value); // Unformatted if rawValueMode is true
139
+ console.log('Display value:', numoraInput.value); // Formatted display value
140
+ console.log('As number:', numoraInput.valueAsNumber); // Parsed as number
141
+ },
142
+ });
143
+ ```
144
+
145
+ ### Compact Notation Example
146
+
147
+ ```typescript
148
+ import { NumoraInput } from 'numora';
149
+
150
+ const container = document.querySelector('#my-input-container');
151
+
152
+ const numoraInput = new NumoraInput(container, {
153
+ enableCompactNotation: true,
154
+ onChange: (value) => {
155
+ console.log('Value:', value);
156
+ },
157
+ });
158
+
159
+ // When user pastes "1.5k" or you call setValue("1.5k")
160
+ // It automatically expands to "1500"
161
+ numoraInput.setValue('1.5k'); // Display: "1,500" (if thousand separator enabled)
162
+ ```
163
+
164
+ ### Scientific Notation Example
165
+
166
+ ```typescript
167
+ import { NumoraInput } from 'numora';
168
+
169
+ const container = document.querySelector('#my-input-container');
170
+
171
+ const numoraInput = new NumoraInput(container, {
172
+ decimalMaxLength: 18,
173
+ onChange: (value) => {
174
+ console.log('Value:', value);
175
+ },
176
+ });
177
+
178
+ // Scientific notation is ALWAYS automatically expanded
179
+ // User can paste "1.5e-7" and it becomes "0.00000015"
180
+ // User can paste "2e+5" and it becomes "200000"
181
+ ```
182
+
183
+ ### Comma/Dot Conversion Example
184
+
185
+ ```typescript
186
+ import { NumoraInput, ThousandStyle } from 'numora';
187
+
188
+ const container = document.querySelector('#my-input-container');
189
+
190
+ const numoraInput = new NumoraInput(container, {
191
+ decimalSeparator: ',', // European format
192
+ thousandStyle: ThousandStyle.None, // Required for comma/dot conversion
193
+ decimalMaxLength: 2,
194
+ });
195
+
196
+ // When thousandStyle is None:
197
+ // - User types "." → automatically converted to ","
198
+ // - User types "," → automatically converted to ","
199
+ // This makes it easier for users without knowing the exact separator
200
+ ```
201
+
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
+ ### Programmatic Value Control
221
+
222
+ ```typescript
223
+ // Get the current value
224
+ const currentValue = numoraInput.getValue();
225
+ // or
226
+ const currentValue = numoraInput.value;
227
+
228
+ // Set a new value
229
+ numoraInput.setValue('1234.56');
230
+ // or
231
+ numoraInput.value = '1234.56';
232
+
233
+ // Set from a number
234
+ numoraInput.valueAsNumber = 1234.56;
235
+
236
+ // Get as a number
237
+ const numericValue = numoraInput.valueAsNumber;
238
+
239
+ // Enable/disable the input
240
+ numoraInput.disable();
241
+ numoraInput.enable();
242
+
243
+ // Access the underlying HTMLInputElement
244
+ const inputElement = numoraInput.getElement();
245
+ inputElement.addEventListener('focus', () => {
246
+ console.log('Input focused');
52
247
  });
53
248
  ```
54
249
 
55
250
  ## Options
56
251
 
57
252
  The NumoraInput constructor accepts the following options:
253
+
58
254
  | Option | Type | Default | Description |
59
- | --------------- | -------- | --------- | -------------------------------------------------------- |
60
- | decimalMaxLength | number | 2 | Maximum number of decimal places allowed |
61
- | onChange | function | undefined | Callback function that runs when the input value changes |
62
- | supports all input properties | - | - | - |
255
+ |--------|------|---------|-------------|
256
+ | `decimalMaxLength` | `number` | `2` | Maximum number of decimal places allowed |
257
+ | `decimalMinLength` | `number` | `0` | Minimum number of decimal places (pads with zeros) |
258
+ | `decimalSeparator` | `string` | `'.'` | Character used as decimal separator |
259
+ | `thousandSeparator` | `string` | `','` | Character used as thousand separator (set to empty string to disable) |
260
+ | `thousandStyle` | `ThousandStyle` | `ThousandStyle.None` | Grouping style: `Thousand`, `Lakh`, `Wan`, or `None` |
261
+ | `formatOn` | `FormatOn` | `FormatOn.Blur` | When to apply formatting: `Blur` or `Change` |
262
+ | `enableCompactNotation` | `boolean` | `false` | Enable expansion of compact notation (e.g., "1k" → "1000") on paste/setValue |
263
+ | `enableNegative` | `boolean` | `false` | Allow negative numbers |
264
+ | `enableLeadingZeros` | `boolean` | `false` | Allow leading zeros before decimal point |
265
+ | `rawValueMode` | `boolean` | `false` | Return unformatted values in `onChange` callback |
266
+ | `onChange` | `(value: string) => void` | `undefined` | Callback function that runs when the input value changes |
267
+ | `value` | `string` | `undefined` | Initial value (controlled mode) |
268
+ | `defaultValue` | `string` | `undefined` | Initial default value (uncontrolled mode) |
269
+
270
+ All standard HTMLInputElement properties are also supported (e.g., `placeholder`, `className`, `disabled`, `id`, etc.).
271
+
272
+ **Note:** Scientific notation expansion (e.g., `"1.5e-7"` → `"0.00000015"`) always happens automatically and is not configurable.
63
273
 
64
274
  ## Framework Adapters
65
275
 
66
276
  Numora is also available for popular frameworks:
67
277
 
68
- - React: `numora-react` (in progress)
69
- - Vue: `numora-vue` (in progress)
70
- - Svelte: `numora`
278
+ - **React**: [`numora-react`](../react/README.md) - React component wrapper
279
+ - **Vue**: Coming soon
280
+ - **Svelte**: Use the core package directly
71
281
 
72
282
  ## License
73
283
 
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export * from './NumoraInput';
2
2
  export { ThousandStyle, FormatOn } from './types';
3
+ export { handleOnChangeNumoraInput, handleOnPasteNumoraInput, handleOnKeyDownNumoraInput, formatValueForNumora, } from './utils/event-handlers';
4
+ export type { FormattingOptions, CaretPositionInfo } from './types';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var Q=Object.defineProperty;var X=(e,t,n)=>t in e?Q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var w=(e,t,n)=>X(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var v=(e=>(e.Blur="blur",e.Change="change",e))(v||{}),p=(e=>(e.None="none",e.Thousand="thousand",e.Lakh="lakh",e.Wan="wan",e))(p||{});const I=2,x=0,O=v.Blur,R=",",_=p.None,E=".",P=!1,B=!1,W=!1,k=!1;function M(e){return e.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}function C(e){return{decimalSeparator:(e==null?void 0:e.decimalSeparator)??E,thousandSeparator:e==null?void 0:e.thousandSeparator}}function Y(e,t){if(e.key!==t)return!1;const n=e.target;return n?n.value.includes(t):!1}function V(e,t,n,r){const{selectionStart:i,selectionEnd:a,value:s}=t,{key:o}=e,c=n==null?void 0:n.ThousandStyle;if(c!==p.None&&c!==void 0||o!==","&&o!==".")return!1;if(Y(e,r))return!0;if(o!==r){const l=i??0,h=a??l,d=s.slice(0,l)+r+s.slice(h);t.value=d;const u=l+1;return t.setSelectionRange(u,u),!0}return!1}const F=(e,t,n=E)=>{const[r,i]=e.split(n);return i?`${r}${n}${i.slice(0,t)}`:e},ee=(e,t=E)=>{const n=M(t),r=new RegExp(`(${n}.*?)${n}`,"g");return e.replace(r,`$1${t}`)},te=(e,t=0,n=E)=>{if(t===0)return e;if(!e||e==="0"||e===n||e==="-"||e===`-${n}`)return e==="-"||e===`-${n}`?`-${n}${"0".repeat(t)}`:e===n?`${n}${"0".repeat(t)}`:`${e}${n}${"0".repeat(t)}`;const r=e.includes(n),i=e.startsWith("-"),a=i?e.slice(1):e,[s,o=""]=a.split(n);if(!r){const c="0".repeat(t);return i?`-${s}${n}${c}`:`${s}${n}${c}`}if(o.length<t){const c=t-o.length,l=o+"0".repeat(c);return i?`-${s}${n}${l}`:`${s}${n}${l}`}return e},ne=(e,t=!1,n=".")=>{const r=M(n),i=new RegExp(`[^0-9${r}]`,"g");if(!t)return e.replace(i,"");const a=e.startsWith("-"),s=e.replace(i,"");if(a){if(s.length>0)return"-"+s;if(e==="-")return"-"}return s};function re(e){const t=/([+-]?\d+\.?\d*)[eE]([+-]?\d+)/g;let n=e,r;const i=[];for(;(r=t.exec(e))!==null;){const a=r[0],s=r[1],o=parseInt(r[2],10);let c;if(o===0)c=s;else{const l=s.startsWith("-"),h=l?s.slice(1):s,[d,u=""]=h.split(".");o>0?c=se(d,u,o):c=ie(d,u,Math.abs(o)),l&&(c="-"+c)}i.push({full:a,expanded:c})}for(const{full:a,expanded:s}of i)n=n.replace(a,s);return n}function se(e,t,n){const r=e+t;if(r==="0"||r.match(/^0+$/))return"0";const i=t.length;if(n<=i){const s=r.slice(0,e.length+n),o=r.slice(e.length+n);return o?`${s}.${o}`:s}const a=n-i;return r+"0".repeat(a)}function ie(e,t,n){const r=e+t;if(r==="0"||r.match(/^0+$/))return"0";const s=e.length-n;if(s<=0){const o=Math.abs(s),c=`0.${"0".repeat(o)}${r}`;return y(c)}if(s<e.length){const o=r.slice(0,s),c=r.slice(s),l=`${o}.${c}`;return y(l)}return y(r)}function y(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 ae(e){const t=/(\d+\.?\d*)\s*(Qa|Qi|Sx|Sp|[kmbMTO]|N)/gi;return e.replace(t,(n,r,i)=>{const a={k:3,m:6,M:6,b:9,T:12,Qa:15,Qi:18,Sx:21,Sp:24,O:27,N:30};let s;if(i.length>1)s=a[i]||a[i.charAt(0).toUpperCase()+i.slice(1).toLowerCase()];else{const f=i.toLowerCase();s=a[i]||a[f]}if(!s)return n;const o=r.startsWith("-"),c=o?r.slice(1):r,[l,h=""]=c.split("."),d=l.replace(/^0+/,"")||"0";let u;if(h.length===0)u=d+"0".repeat(s);else if(h.length<=s){const f=s-h.length;u=d+h+"0".repeat(f)}else{const f=h.slice(0,s),g=h.slice(s);u=d+f+"."+g}return u=u.replace(/^(-?)0+([1-9])/,"$1$2"),u.match(/^-?0+$/)&&(u=o?"-0":"0"),u=u.replace(/\.?0+$/,""),o&&!u.startsWith("-")?"-"+u:u})}function oe(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[i,a]=n.split(".");if(i&&i.length>0){const o=(i.replace(/^0+/,"")||"0")+"."+a;return t?"-"+o:o}return e}if(n.startsWith("0")&&n.length>1){const i=n.replace(/^0+/,"")||"0";return t?"-"+i:i}return e}function ce(e){return e.replace(/[\u00A0\u2000-\u200B\u202F\u205F\u3000]/g," ").replace(/\s/g,"")}function L(e,t){const n=M(t);return e.replace(new RegExp(n,"g"),"")}const le=(e,t)=>{let n=ce(e);return t!=null&&t.thousandSeparator&&(n=L(n,t.thousandSeparator)),t!=null&&t.enableCompactNotation&&(n=ae(n)),n=re(n),n=ne(n,t==null?void 0:t.enableNegative,t==null?void 0:t.decimalSeparator),n=ee(n,(t==null?void 0:t.decimalSeparator)||E),t!=null&&t.enableLeadingZeros||(n=oe(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}}const N={thousand:{size:3},lakh:{firstGroup:3,restGroup:2},wan:{size:4}};function U(e,t,n,r=!1,i="."){if(!e||e==="0"||e===i||e==="-"||e===`-${i}`)return e;const a=e.includes(i),s=e.startsWith("-"),o=s?e.slice(1):e,[c,l]=o.split(i);if(!c){const u=l?`${i}${l}`:o;return s?`-${u}`:u}if(r&&c.startsWith("0")&&c.length>1){const u=c.match(/^(0+)/);if(u){const f=u[1],g=c.slice(f.length);if(g){const b=Z(g,t,n),$=f+b,D=s?"-":"";return a?l?`${D}${$}${i}${l}`:`${D}${$}${i}`:`${D}${$}`}}}const h=Z(c,t,n),d=s?"-":"";return a?l?`${d}${h}${i}${l}`:`${d}${h}${i}`:`${d}${h}`}function Z(e,t,n){if(e==="0"||e==="")return e;switch(n){case p.None:return e;case p.Thousand:return ue(e,t);case p.Lakh:return de(e,t);case p.Wan:return fe(e,t);default:return e}}function ue(e,t){return z(e,t,N.thousand.size)}function de(e,t){if(e.length<=N.lakh.firstGroup)return e;const n=e.split("").reverse(),r=[],i=n.slice(0,N.lakh.firstGroup).reverse().join("");r.push(i);for(let a=N.lakh.firstGroup;a<n.length;a+=N.lakh.restGroup)r.push(n.slice(a,a+N.lakh.restGroup).reverse().join(""));return r.reverse().join(t)}function fe(e,t){return z(e,t,N.wan.size)}function z(e,t,n){const r=e.split("").reverse(),i=[];for(let a=0;a<r.length;a+=n)i.push(r.slice(a,a+n).reverse().join(""));return i.reverse().join(t)}function ge(e,t,n){return(t==null?void 0:t.formatOn)==="change"&&t.thousandSeparator?U(e,t.thousandSeparator,t.ThousandStyle??p.None,t.enableLeadingZeros,(n==null?void 0:n.decimalSeparator)??E):e}function S(e,t,n,r="."){let i=0;for(let a=0;a<t&&a<e.length;a++){const s=e[a];s!==n&&s!==r&&i++}return i}function be(e,t,n,r="."){if(t===0)return 0;let i=0;for(let a=0;a<e.length;a++){const s=e[a];if(s!==n&&s!==r){if(i===t-1)return a+1;i++}}return e.length}function A(e,t,n,r="."){if(t===0)return 0;let i=0;for(let a=0;a<e.length;a++){const s=e[a];if(s!==n&&s!==r){if(i++,i===t)return a+1;if(i>t)return a}}return e.length}function j(e,t,n){return t<0||t>=e.length?!1:e[t]===n}function pe(e,t={}){const{thousandSeparator:n,decimalSeparator:r=".",prefix:i="",suffix:a=""}=t,s=Array.from({length:e.length+1}).map(()=>!0);if(i&&s.fill(!1,0,i.length),a){const o=e.length-a.length;s.fill(!1,o+1,e.length+1)}for(let o=0;o<e.length;o++){const c=e[o];(n&&c===n||c===r)&&(s[o]=!1,o+1<e.length&&!/\d/.test(e[o+1])&&(s[o+1]=!1))}return s.some(o=>o)||s.fill(!0),s}function T(e,t,n,r){const i=e.length;if(t=Math.max(0,Math.min(t,i)),!n[t]){let a=t;for(;a<=i&&!n[a];)a++;let s=t;for(;s>=0&&!n[s];)s--;a<=i&&s>=0?t=t-s<a-t?s:a:a<=i?t=a:s>=0&&(t=s)}return(t===-1||t>i)&&(t=i),t}const J=(e,t)=>e===t;function Se(e,t,n,r,i,a,s=".",o={}){if(n<0)return 0;if(n>e.length||e===""||t==="")return t.length;const c=t.length<e.length,l=j(e,n,r),h=e.indexOf(s),d=t.indexOf(s);if(o.isCharacterEquivalent&&e!==t){const g=ve(e,t,n,o.isCharacterEquivalent||J,a,o);if(g!==void 0)return g}if(c)return $e(e,t,n,r,l,h,d,a,s,o);const f=Le(e,t,n,r,l,s);return o.boundary?T(t,f,o.boundary):f}function ve(e,t,n,r,i,a){const s=e.length,o=t.length,c={},l=new Array(s);for(let g=0;g<s;g++){l[g]=-1;for(let b=0;b<o;b++){if(c[b])continue;if(r(e[g],t[b],{oldValue:e,newValue:t,typedRange:i,oldIndex:g,newIndex:b})){l[g]=b,c[b]=!0;break}}}let h=n;for(;h<s&&(l[h]===-1||!/\d/.test(e[h]));)h++;const d=h===s||l[h]===-1?o:l[h];for(h=n-1;h>=0&&l[h]===-1;)h--;const u=h===-1||l[h]===-1?0:l[h]+1;if(u>d)return d;const f=n-u<d-n?u:d;return a.boundary?T(t,f,a.boundary):f}function $e(e,t,n,r,i,a,s,o,c,l={}){if(i)return Ee(e,t,n,r,s,c);const h=S(e,n,r,c),d=S(e,e.length,r,c),u=S(t,t.length,r,c),f=d-u,g=Ne(e,n,r,h,f,a,o,c),b=a===-1||n<=a,$=we(t,g,r,f,o,c,b,s);return l.boundary?T(t,$,l.boundary):$}function Ee(e,t,n,r,i,a){const s=n+1;if(s<e.length){const o=S(e,s,r,a),c=be(t,o,r,a);return c<t.length&&t[c]!==r?c+1:c}return n}function Ne(e,t,n,r,i,a,s,o){if(s){const{start:l,isDelete:h}=s;return h?S(e,l,n,o):Math.max(0,S(e,l,n,o))}return t>0&&e[t-1]===n&&i>0?r+1:r}function we(e,t,n,r,i,a,s,o){if(s&&o!==-1){const l=e.substring(0,o),h=S(l,l.length,n,a);if(t<=h){const d=A(l,t,n,a);if(d>0&&d<l.length&&S(l,d,n,a)===t){if(l[d]===n&&i&&r>0&&d<l.length-1)return d+1;if(!i&&r>0&&d<l.length-1)return Math.min(d+1,l.length)}return d}}const c=A(e,t,n,a);if(c>0&&c<e.length&&S(e,c,n,a)===t){if(e[c]===n&&i&&r>0&&c<e.length-1)return c+1;if(!i&&r>0&&c<e.length-1)return Math.min(c+1,e.length)}return c}function Le(e,t,n,r,i,a){const s=n>=e.length,o=S(e,n,r,a),c=S(e,e.length,r,a),l=S(t,t.length,r,a);if(s||o===c)return t.length;const h=l-c;let d=o;h>0&&!s&&o<c&&(d=o+1);const u=A(t,d,r,a);return i&&!j(t,u,r)?Math.max(0,u-1):u}function Me(e,t,n){const{selectionStart:r,selectionEnd:i,endOffset:a=0}=e;if(r!==i){const h=i-r;return{start:r,end:i,deletedLength:h,isDelete:!1}}if(a>0){const h=a;return{start:r,end:r+h,deletedLength:h,isDelete:!0}}const o=t.length,c=n.length,l=o-c;if(!(l<=0))return{start:r,end:r+l,deletedLength:l,isDelete:!1}}function De(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 a=r-n+1,s=i-n+1;if(!(a===0&&s===0))return{start:n,end:r+1,deletedLength:a,isDelete:a>s}}function G(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 me(e,t,n){return e.selectionStart===0&&e.selectionEnd===e.value.length?null:(G(e,t),setTimeout(()=>{e.value===n&&e.selectionStart!==t&&G(e,t)},0))}function ye(e){return Math.max(e.selectionStart,e.selectionEnd)}function Ae(e,t,n){if((n==null?void 0:n.formatOn)!==v.Change||!n.thousandSeparator)return;const{selectionStart:r,selectionEnd:i,value:a}=t;if(r===null||i===null||r!==i)return;const{key:s}=e,o=n.thousandSeparator;s==="Backspace"&&r>0&&a[r-1]===o&&t.setSelectionRange(r-1,r-1),s==="Delete"&&a[r]===o&&t.setSelectionRange(r+1,r+1)}function Ce(e,t,n,r,i,a,s){if(!i)return;const{selectionStart:o=0,selectionEnd:c=0,endOffset:l=0}=i;let h=Me({selectionStart:o,selectionEnd:c,endOffset:l},t,n);if(h||(h=De(t,n)),!h)return;const d=pe(n,{thousandSeparator:(s==null?void 0:s.thousandSeparator)??a.thousandSeparator,decimalSeparator:a.decimalSeparator}),u={thousandSeparator:(s==null?void 0:s.thousandSeparator)??a.thousandSeparator,isCharacterEquivalent:J,boundary:d},f=(s==null?void 0:s.thousandSeparator)??a.thousandSeparator??",",g=(s==null?void 0:s.ThousandStyle)??p.None,b=Se(t,n,r,f,g,h,a.decimalSeparator,u);me(e,b,n)}function H(e,t,n,r,i){const a=le(e,he(r,i,n)),s=F(a,t,i.decimalSeparator),o=(r==null?void 0:r.decimalMinLength)??0,c=te(s,o,i.decimalSeparator),l=c;return{formatted:ge(c,r,i),raw:l}}function Te(e,t,n){if(e==="Backspace"||e==="Delete")return e==="Delete"&&t===n?{endOffset:1}:{endOffset:0}}function Ie(e,t){const{decimalSeparator:n}=C(t),r=e.target;if(V(e,r,t,n)){e.preventDefault();return}return Ae(e,r,t),Te(e.key,r.selectionStart,r.selectionEnd)}function xe(e,t,n,r){const i=e.target,a=i.value,s=ye(i),o=C(r),c=(r==null?void 0:r.formatOn)===v.Change,{formatted:l,raw:h}=H(a,t,c,r,o);i.value=l,r!=null&&r.rawValueMode&&i.setAttribute("data-raw-value",h),a!==l&&Ce(i,a,l,s,n,o,r)}function Oe(e,t,n,r){const i=r-n;return e+t+i}function Re(e,t,n){var f;e.preventDefault();const r=e.target,{value:i,selectionStart:a,selectionEnd:s}=r,o=C(n),c=((f=e.clipboardData)==null?void 0:f.getData("text/plain"))||"",l=i.slice(0,a||0)+c+i.slice(s||0),{formatted:h,raw:d}=H(l,t,!0,n,o);r.value=h,n!=null&&n.rawValueMode&&r.setAttribute("data-raw-value",d);const u=Oe(a||0,c.length,l.length,h.length);return r.setSelectionRange(u,u),r.value}function _e(e,t){const n=M(e);return t?`^-?[0-9]*[${n}]?[0-9]*$`:`^[0-9]*[${n}]?[0-9]*$`}function Pe(e){Be(e.decimalMaxLength),We(e.decimalMinLength),ke(e.decimalMinLength,e.decimalMaxLength),Ze(e.formatOn),Ge(e.thousandSeparator),Ue(e.thousandStyle),ze(e.decimalSeparator),je(e.thousandSeparator,e.decimalSeparator),m("enableCompactNotation",e.enableCompactNotation),m("enableNegative",e.enableNegative),m("enableLeadingZeros",e.enableLeadingZeros),m("rawValueMode",e.rawValueMode),Je(e.onChange)}function Be(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 We(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 ke(e,t){if(!(e===void 0||t===void 0)&&e>t)throw new Error(`decimalMinLength (${e}) cannot be greater than decimalMaxLength (${t}).`)}function Ze(e){if(e!==void 0&&e!==v.Blur&&e!==v.Change)throw new Error(`formatOn must be either ${v.Blur} or ${v.Change}. Received: ${JSON.stringify(e)}`)}function Ge(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 Ue(e){if(e!==void 0&&!Object.values(p).includes(e))throw new Error(`ThousandStyle must be one of: ${Object.values(p).map(t=>`'${t}'`).join(", ")}. Received: ${JSON.stringify(e)}`)}function ze(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 je(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 Je(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 He{constructor(t,{decimalMaxLength:n=I,decimalMinLength:r=x,formatOn:i=O,thousandSeparator:a=R,thousandStyle:s=_,decimalSeparator:o=E,enableCompactNotation:c=P,enableNegative:l=B,enableLeadingZeros:h=W,rawValueMode:d=k,onChange:u,...f}){w(this,"element");w(this,"options");w(this,"resolvedOptions");w(this,"rawValue","");w(this,"caretPositionBeforeChange");if(Pe({decimalMaxLength:n,decimalMinLength:r,formatOn:i,thousandSeparator:a,thousandStyle:s,decimalSeparator:o,enableCompactNotation:c,enableNegative:l,enableLeadingZeros:h,rawValueMode:d,onChange:u}),this.options={decimalMaxLength:n,decimalMinLength:r,onChange:u,formatOn:i,thousandSeparator:a,thousandStyle:s,decimalSeparator:o,enableCompactNotation:c,enableNegative:l,enableLeadingZeros:h,rawValueMode:d,...f},this.resolvedOptions=this.getResolvedOptions(),this.createInputElement(t),this.setupEventListeners(),this.resolvedOptions.rawValueMode&&this.element.value){const g=this.element.value,b=this.resolvedOptions.thousandSeparator?L(g,this.resolvedOptions.thousandSeparator):g;this.rawValue=b,this.element.value=this.formatValueForDisplay(b)}else if(this.element.value&&!this.resolvedOptions.rawValueMode){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 K=_e(this.resolvedOptions.decimalSeparator,this.resolvedOptions.enableNegative);this.element.setAttribute("pattern",K)}const{decimalMaxLength:n,decimalMinLength:r,formatOn:i,thousandSeparator:a,thousandStyle:s,decimalSeparator:o,enableCompactNotation:c,enableNegative:l,enableLeadingZeros:h,rawValueMode:d,onChange:u,value:f,defaultValue:g,type:b,inputMode:$,spellcheck:D,autocomplete:qe,...q}=this.options;Object.assign(this.element,q),f!==void 0?this.element.value=f: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===v.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??I,decimalMinLength:this.options.decimalMinLength??x,formatOn:this.options.formatOn??O,thousandSeparator:this.options.thousandSeparator??R,thousandStyle:this.options.thousandStyle??_,decimalSeparator:this.options.decimalSeparator??E,enableCompactNotation:this.options.enableCompactNotation??P,enableNegative:this.options.enableNegative??B,enableLeadingZeros:this.options.enableLeadingZeros??W,rawValueMode:this.options.rawValueMode??k,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){const r=n??t;if(this.resolvedOptions.rawValueMode&&this.updateRawValue(r),this.resolvedOptions.onChange){const i=this.resolvedOptions.rawValueMode?this.rawValue:t;this.resolvedOptions.onChange(i)}}formatValueForDisplay(t){if(!t)return t;const{thousandSeparator:n,thousandStyle:r,enableLeadingZeros:i,decimalSeparator:a}=this.resolvedOptions;return n&&r!==p.None?U(t,n,r,i,a):t}handleChange(t){const n=t.target;xe(t,this.resolvedOptions.decimalMaxLength,this.caretPositionBeforeChange,this.buildFormattingOptions()),this.caretPositionBeforeChange=void 0,this.handleValueChange(n.value)}handleKeyDown(t){const n=t.target,{selectionStart:r,selectionEnd:i}=n,a=this.buildFormattingOptions(),s=Ie(t,{formatOn:a.formatOn,thousandSeparator:a.thousandSeparator,ThousandStyle:a.ThousandStyle,decimalSeparator:a.decimalSeparator});s?this.caretPositionBeforeChange={selectionStart:r??0,selectionEnd:i??0,endOffset:s.endOffset}:this.caretPositionBeforeChange={selectionStart:r??0,selectionEnd:i??0}}handlePaste(t){const n=Re(t,this.resolvedOptions.decimalMaxLength,this.buildFormattingOptions());this.handleValueChange(n);const r=new Event("input",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(r)}handleFocus(t){if(this.resolvedOptions.formatOn===v.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:i}=this.resolvedOptions;if(r&&i!==p.None&&n.value){const a=n.value,s=this.formatValueForDisplay(n.value);if(n.value=s,this.handleValueChange(s),a!==s){const o=new Event("input",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(o);const c=new Event("change",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(c)}}}updateRawValue(t){const n=this.element.getAttribute("data-raw-value");if(n!==null){this.rawValue=n,this.element.removeAttribute("data-raw-value");return}if(!this.resolvedOptions.thousandSeparator){this.rawValue=t;return}this.rawValue=L(t,this.resolvedOptions.thousandSeparator)}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(M(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=v;exports.NumoraInput=He;exports.ThousandStyle=p;
1
+ "use strict";var V=Object.defineProperty;var F=(e,t,n)=>t in e?V(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var w=(e,t,n)=>F(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var v=(e=>(e.Blur="blur",e.Change="change",e))(v||{}),b=(e=>(e.None="none",e.Thousand="thousand",e.Lakh="lakh",e.Wan="wan",e))(b||{});const x=2,O=0,R=v.Blur,_=",",P=b.None,E=".",B=!1,W=!1,k=!1,Z=!1;function m(e){return e.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}function y(e){return{decimalSeparator:(e==null?void 0:e.decimalSeparator)??E,thousandSeparator:e==null?void 0:e.thousandSeparator}}function ee(e,t){if(e.key!==t)return!1;const n=e.target;return n?n.value.includes(t):!1}function te(e,t,n,r){const{selectionStart:i,selectionEnd:a,value:s}=t,{key:o}=e,c=n==null?void 0:n.ThousandStyle;if(c!==b.None&&c!==void 0||o!==","&&o!==".")return!1;if(ee(e,r))return!0;if(o!==r){const l=i??0,h=a??l,d=s.slice(0,l)+r+s.slice(h);t.value=d;const u=l+1;return t.setSelectionRange(u,u),!0}return!1}const ne=(e,t,n=E)=>{const[r,i]=e.split(n);return i?`${r}${n}${i.slice(0,t)}`:e},re=(e,t=E)=>{const n=m(t),r=new RegExp(`(${n}.*?)${n}`,"g");return e.replace(r,`$1${t}`)},se=(e,t=0,n=E)=>{if(t===0)return e;if(!e||e==="0"||e===n||e==="-"||e===`-${n}`)return e==="-"||e===`-${n}`?`-${n}${"0".repeat(t)}`:e===n?`${n}${"0".repeat(t)}`:`${e}${n}${"0".repeat(t)}`;const r=e.includes(n),i=e.startsWith("-"),a=i?e.slice(1):e,[s,o=""]=a.split(n);if(!r){const c="0".repeat(t);return i?`-${s}${n}${c}`:`${s}${n}${c}`}if(o.length<t){const c=t-o.length,l=o+"0".repeat(c);return i?`-${s}${n}${l}`:`${s}${n}${l}`}return e},ie=(e,t=!1,n=".")=>{const r=m(n),i=new RegExp(`[^0-9${r}]`,"g");if(!t)return e.replace(i,"");const a=e.startsWith("-"),s=e.replace(i,"");if(a){if(s.length>0)return"-"+s;if(e==="-")return"-"}return s};function ae(e){const t=/([+-]?\d+\.?\d*)[eE]([+-]?\d+)/g;let n=e,r;const i=[];for(;(r=t.exec(e))!==null;){const a=r[0],s=r[1],o=parseInt(r[2],10);let c;if(o===0)c=s;else{const l=s.startsWith("-"),h=l?s.slice(1):s,[d,u=""]=h.split(".");o>0?c=oe(d,u,o):c=ce(d,u,Math.abs(o)),l&&(c="-"+c)}i.push({full:a,expanded:c})}for(const{full:a,expanded:s}of i)n=n.replace(a,s);return n}function oe(e,t,n){const r=e+t;if(r==="0"||r.match(/^0+$/))return"0";const i=t.length;if(n<=i){const s=r.slice(0,e.length+n),o=r.slice(e.length+n);return o?`${s}.${o}`:s}const a=n-i;return r+"0".repeat(a)}function ce(e,t,n){const r=e+t;if(r==="0"||r.match(/^0+$/))return"0";const s=e.length-n;if(s<=0){const o=Math.abs(s),c=`0.${"0".repeat(o)}${r}`;return A(c)}if(s<e.length){const o=r.slice(0,s),c=r.slice(s),l=`${o}.${c}`;return A(l)}return A(r)}function A(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 le(e){const t=/(\d+\.?\d*)\s*(Qa|Qi|Sx|Sp|[kmbMTO]|N)/gi;return e.replace(t,(n,r,i)=>{const a={k:3,m:6,M:6,b:9,T:12,Qa:15,Qi:18,Sx:21,Sp:24,O:27,N:30};let s;if(i.length>1)s=a[i]||a[i.charAt(0).toUpperCase()+i.slice(1).toLowerCase()];else{const f=i.toLowerCase();s=a[i]||a[f]}if(!s)return n;const o=r.startsWith("-"),c=o?r.slice(1):r,[l,h=""]=c.split("."),d=l.replace(/^0+/,"")||"0";let u;if(h.length===0)u=d+"0".repeat(s);else if(h.length<=s){const f=s-h.length;u=d+h+"0".repeat(f)}else{const f=h.slice(0,s),g=h.slice(s);u=d+f+"."+g}return u=u.replace(/^(-?)0+([1-9])/,"$1$2"),u.match(/^-?0+$/)&&(u=o?"-0":"0"),u=u.replace(/\.?0+$/,""),o&&!u.startsWith("-")?"-"+u:u})}function he(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[i,a]=n.split(".");if(i&&i.length>0){const o=(i.replace(/^0+/,"")||"0")+"."+a;return t?"-"+o:o}return e}if(n.startsWith("0")&&n.length>1){const i=n.replace(/^0+/,"")||"0";return t?"-"+i:i}return e}function ue(e){return e.replace(/[\u00A0\u2000-\u200B\u202F\u205F\u3000]/g," ").replace(/\s/g,"")}function L(e,t){const n=m(t);return e.replace(new RegExp(n,"g"),"")}const de=(e,t)=>{let n=ue(e);return t!=null&&t.thousandSeparator&&(n=L(n,t.thousandSeparator)),t!=null&&t.enableCompactNotation&&(n=le(n)),n=ae(n),n=ie(n,t==null?void 0:t.enableNegative,t==null?void 0:t.decimalSeparator),n=re(n,(t==null?void 0:t.decimalSeparator)||E),t!=null&&t.enableLeadingZeros||(n=he(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}}const N={thousand:{size:3},lakh:{firstGroup:3,restGroup:2},wan:{size:4}};function z(e,t,n,r=!1,i="."){if(!e||e==="0"||e===i||e==="-"||e===`-${i}`)return e;const a=e.includes(i),s=e.startsWith("-"),o=s?e.slice(1):e,[c,l]=o.split(i);if(!c){const u=l?`${i}${l}`:o;return s?`-${u}`:u}if(r&&c.startsWith("0")&&c.length>1){const u=c.match(/^(0+)/);if(u){const f=u[1],g=c.slice(f.length);if(g){const p=G(g,t,n),$=f+p,D=s?"-":"";return a?l?`${D}${$}${i}${l}`:`${D}${$}${i}`:`${D}${$}`}}}const h=G(c,t,n),d=s?"-":"";return a?l?`${d}${h}${i}${l}`:`${d}${h}${i}`:`${d}${h}`}function G(e,t,n){if(e==="0"||e==="")return e;switch(n){case b.None:return e;case b.Thousand:return ge(e,t);case b.Lakh:return pe(e,t);case b.Wan:return be(e,t);default:return e}}function ge(e,t){return j(e,t,N.thousand.size)}function pe(e,t){if(e.length<=N.lakh.firstGroup)return e;const n=e.split("").reverse(),r=[],i=n.slice(0,N.lakh.firstGroup).reverse().join("");r.push(i);for(let a=N.lakh.firstGroup;a<n.length;a+=N.lakh.restGroup)r.push(n.slice(a,a+N.lakh.restGroup).reverse().join(""));return r.reverse().join(t)}function be(e,t){return j(e,t,N.wan.size)}function j(e,t,n){const r=e.split("").reverse(),i=[];for(let a=0;a<r.length;a+=n)i.push(r.slice(a,a+n).reverse().join(""));return i.reverse().join(t)}function Se(e,t,n){return(t==null?void 0:t.formatOn)==="change"&&t.thousandSeparator?z(e,t.thousandSeparator,t.ThousandStyle??b.None,t.enableLeadingZeros,(n==null?void 0:n.decimalSeparator)??E):e}function S(e,t,n,r="."){let i=0;for(let a=0;a<t&&a<e.length;a++){const s=e[a];s!==n&&s!==r&&i++}return i}function ve(e,t,n,r="."){if(t===0)return 0;let i=0;for(let a=0;a<e.length;a++){const s=e[a];if(s!==n&&s!==r){if(i===t-1)return a+1;i++}}return e.length}function C(e,t,n,r="."){if(t===0)return 0;let i=0;for(let a=0;a<e.length;a++){const s=e[a];if(s!==n&&s!==r){if(i++,i===t)return a+1;if(i>t)return a}}return e.length}function J(e,t,n){return t<0||t>=e.length?!1:e[t]===n}function $e(e,t={}){const{thousandSeparator:n,decimalSeparator:r=".",prefix:i="",suffix:a=""}=t,s=Array.from({length:e.length+1}).map(()=>!0);if(i&&s.fill(!1,0,i.length),a){const o=e.length-a.length;s.fill(!1,o+1,e.length+1)}for(let o=0;o<e.length;o++){const c=e[o];(n&&c===n||c===r)&&(s[o]=!1,o+1<e.length&&!/\d/.test(e[o+1])&&(s[o+1]=!1))}return s.some(o=>o)||s.fill(!0),s}function T(e,t,n,r){const i=e.length;if(t=Math.max(0,Math.min(t,i)),!n[t]){let a=t;for(;a<=i&&!n[a];)a++;let s=t;for(;s>=0&&!n[s];)s--;a<=i&&s>=0?t=t-s<a-t?s:a:a<=i?t=a:s>=0&&(t=s)}return(t===-1||t>i)&&(t=i),t}const H=(e,t)=>e===t;function Ee(e,t,n,r,i,a,s=".",o={}){if(n<0)return 0;if(n>e.length||e===""||t==="")return t.length;const c=t.length<e.length,l=J(e,n,r),h=e.indexOf(s),d=t.indexOf(s);if(o.isCharacterEquivalent&&e!==t){const g=Ne(e,t,n,o.isCharacterEquivalent||H,a,o);if(g!==void 0)return g}if(c)return we(e,t,n,r,l,h,d,a,s,o);const f=Me(e,t,n,r,l,s);return o.boundary?T(t,f,o.boundary):f}function Ne(e,t,n,r,i,a){const s=e.length,o=t.length,c={},l=new Array(s);for(let g=0;g<s;g++){l[g]=-1;for(let p=0;p<o;p++){if(c[p])continue;if(r(e[g],t[p],{oldValue:e,newValue:t,typedRange:i,oldIndex:g,newIndex:p})){l[g]=p,c[p]=!0;break}}}let h=n;for(;h<s&&(l[h]===-1||!/\d/.test(e[h]));)h++;const d=h===s||l[h]===-1?o:l[h];for(h=n-1;h>=0&&l[h]===-1;)h--;const u=h===-1||l[h]===-1?0:l[h]+1;if(u>d)return d;const f=n-u<d-n?u:d;return a.boundary?T(t,f,a.boundary):f}function we(e,t,n,r,i,a,s,o,c,l={}){if(i)return Le(e,t,n,r,s,c);const h=S(e,n,r,c),d=S(e,e.length,r,c),u=S(t,t.length,r,c),f=d-u,g=me(e,n,r,h,f,a,o,c),p=a===-1||n<=a,$=De(t,g,r,f,o,c,p,s);return l.boundary?T(t,$,l.boundary):$}function Le(e,t,n,r,i,a){const s=n+1;if(s<e.length){const o=S(e,s,r,a),c=ve(t,o,r,a);return c<t.length&&t[c]!==r?c+1:c}return n}function me(e,t,n,r,i,a,s,o){if(s){const{start:l,isDelete:h}=s;return h?S(e,l,n,o):Math.max(0,S(e,l,n,o))}return t>0&&e[t-1]===n&&i>0?r+1:r}function De(e,t,n,r,i,a,s,o){if(s&&o!==-1){const l=e.substring(0,o),h=S(l,l.length,n,a);if(t<=h){const d=C(l,t,n,a);if(d>0&&d<l.length&&S(l,d,n,a)===t){if(l[d]===n&&i&&r>0&&d<l.length-1)return d+1;if(!i&&r>0&&d<l.length-1)return Math.min(d+1,l.length)}return d}}const c=C(e,t,n,a);if(c>0&&c<e.length&&S(e,c,n,a)===t){if(e[c]===n&&i&&r>0&&c<e.length-1)return c+1;if(!i&&r>0&&c<e.length-1)return Math.min(c+1,e.length)}return c}function Me(e,t,n,r,i,a){const s=n>=e.length,o=S(e,n,r,a),c=S(e,e.length,r,a),l=S(t,t.length,r,a);if(s||o===c)return t.length;const h=l-c;let d=o;h>0&&!s&&o<c&&(d=o+1);const u=C(t,d,r,a);return i&&!J(t,u,r)?Math.max(0,u-1):u}function ye(e,t,n){const{selectionStart:r,selectionEnd:i,endOffset:a=0}=e;if(r!==i){const h=i-r;return{start:r,end:i,deletedLength:h,isDelete:!1}}if(a>0){const h=a;return{start:r,end:r+h,deletedLength:h,isDelete:!0}}const o=t.length,c=n.length,l=o-c;if(!(l<=0))return{start:r,end:r+l,deletedLength:l,isDelete:!1}}function Ae(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 a=r-n+1,s=i-n+1;if(!(a===0&&s===0))return{start:n,end:r+1,deletedLength:a,isDelete:a>s}}function U(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 Ce(e,t,n){return e.selectionStart===0&&e.selectionEnd===e.value.length?null:(U(e,t),setTimeout(()=>{e.value===n&&e.selectionStart!==t&&U(e,t)},0))}function Te(e){return Math.max(e.selectionStart,e.selectionEnd)}function Ie(e,t,n){if((n==null?void 0:n.formatOn)!==v.Change||!n.thousandSeparator)return;const{selectionStart:r,selectionEnd:i,value:a}=t;if(r===null||i===null||r!==i)return;const{key:s}=e,o=n.thousandSeparator;s==="Backspace"&&r>0&&a[r-1]===o&&t.setSelectionRange(r-1,r-1),s==="Delete"&&a[r]===o&&t.setSelectionRange(r+1,r+1)}function xe(e,t,n,r,i,a,s){if(!i)return;const{selectionStart:o=0,selectionEnd:c=0,endOffset:l=0}=i;let h=ye({selectionStart:o,selectionEnd:c,endOffset:l},t,n);if(h||(h=Ae(t,n)),!h)return;const d=$e(n,{thousandSeparator:(s==null?void 0:s.thousandSeparator)??a.thousandSeparator,decimalSeparator:a.decimalSeparator}),u={thousandSeparator:(s==null?void 0:s.thousandSeparator)??a.thousandSeparator,isCharacterEquivalent:H,boundary:d},f=(s==null?void 0:s.thousandSeparator)??a.thousandSeparator??",",g=(s==null?void 0:s.ThousandStyle)??b.None,p=Ee(t,n,r,f,g,h,a.decimalSeparator,u);Ce(e,p,n)}function I(e,t,n,r,i){const a=de(e,fe(r,i,n)),s=ne(a,t,i.decimalSeparator),o=(r==null?void 0:r.decimalMinLength)??0,c=se(s,o,i.decimalSeparator),l=c;return{formatted:Se(c,r,i),raw:l}}function Oe(e,t,n){if(e==="Backspace"||e==="Delete")return e==="Delete"&&t===n?{endOffset:1}:{endOffset:0}}function K(e,t){const{decimalSeparator:n}=y(t),r=e.target;if(te(e,r,t,n)){e.preventDefault();return}return Ie(e,r,t),Oe(e.key,r.selectionStart,r.selectionEnd)}function q(e,t,n,r){const i=e.target,a=i.value,s=Te(i),o=y(r),c=(r==null?void 0:r.formatOn)===v.Change,{formatted:l,raw:h}=I(a,t,c,r,o);i.value=l,r!=null&&r.rawValueMode&&i.setAttribute("data-raw-value",h),a!==l&&xe(i,a,l,s,n,o,r)}function Re(e,t,n,r){const i=r-n;return e+t+i}function Q(e,t,n){var f;e.preventDefault();const r=e.target,{value:i,selectionStart:a,selectionEnd:s}=r,o=y(n),c=((f=e.clipboardData)==null?void 0:f.getData("text/plain"))||"",l=i.slice(0,a||0)+c+i.slice(s||0),{formatted:h,raw:d}=I(l,t,!0,n,o);r.value=h,n!=null&&n.rawValueMode&&r.setAttribute("data-raw-value",d);const u=Re(a||0,c.length,l.length,h.length);return r.setSelectionRange(u,u),r.value}function _e(e,t,n){if(!e)return e;const r=y(n),i=!0,{formatted:a}=I(e,t,i,n,r);return a}function Pe(e,t){const n=m(e);return t?`^-?[0-9]*[${n}]?[0-9]*$`:`^[0-9]*[${n}]?[0-9]*$`}function Be(e){We(e.decimalMaxLength),ke(e.decimalMinLength),Ze(e.decimalMinLength,e.decimalMaxLength),Ge(e.formatOn),Ue(e.thousandSeparator),ze(e.thousandStyle),je(e.decimalSeparator),Je(e.thousandSeparator,e.decimalSeparator),M("enableCompactNotation",e.enableCompactNotation),M("enableNegative",e.enableNegative),M("enableLeadingZeros",e.enableLeadingZeros),M("rawValueMode",e.rawValueMode),He(e.onChange)}function We(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 ke(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 Ze(e,t){if(!(e===void 0||t===void 0)&&e>t)throw new Error(`decimalMinLength (${e}) cannot be greater than decimalMaxLength (${t}).`)}function Ge(e){if(e!==void 0&&e!==v.Blur&&e!==v.Change)throw new Error(`formatOn must be either ${v.Blur} or ${v.Change}. Received: ${JSON.stringify(e)}`)}function Ue(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 ze(e){if(e!==void 0&&!Object.values(b).includes(e))throw new Error(`ThousandStyle must be one of: ${Object.values(b).map(t=>`'${t}'`).join(", ")}. Received: ${JSON.stringify(e)}`)}function je(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 Je(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 He(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 Ke{constructor(t,{decimalMaxLength:n=x,decimalMinLength:r=O,formatOn:i=R,thousandSeparator:a=_,thousandStyle:s=P,decimalSeparator:o=E,enableCompactNotation:c=B,enableNegative:l=W,enableLeadingZeros:h=k,rawValueMode:d=Z,onChange:u,...f}){w(this,"element");w(this,"options");w(this,"resolvedOptions");w(this,"rawValue","");w(this,"caretPositionBeforeChange");if(Be({decimalMaxLength:n,decimalMinLength:r,formatOn:i,thousandSeparator:a,thousandStyle:s,decimalSeparator:o,enableCompactNotation:c,enableNegative:l,enableLeadingZeros:h,rawValueMode:d,onChange:u}),this.options={decimalMaxLength:n,decimalMinLength:r,onChange:u,formatOn:i,thousandSeparator:a,thousandStyle:s,decimalSeparator:o,enableCompactNotation:c,enableNegative:l,enableLeadingZeros:h,rawValueMode:d,...f},this.resolvedOptions=this.getResolvedOptions(),this.createInputElement(t),this.setupEventListeners(),this.resolvedOptions.rawValueMode&&this.element.value){const g=this.element.value,p=this.resolvedOptions.thousandSeparator?L(g,this.resolvedOptions.thousandSeparator):g;this.rawValue=p,this.element.value=this.formatValueForDisplay(p)}else if(this.element.value&&!this.resolvedOptions.rawValueMode){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 Y=Pe(this.resolvedOptions.decimalSeparator,this.resolvedOptions.enableNegative);this.element.setAttribute("pattern",Y)}const{decimalMaxLength:n,decimalMinLength:r,formatOn:i,thousandSeparator:a,thousandStyle:s,decimalSeparator:o,enableCompactNotation:c,enableNegative:l,enableLeadingZeros:h,rawValueMode:d,onChange:u,value:f,defaultValue:g,type:p,inputMode:$,spellcheck:D,autocomplete:qe,...X}=this.options;Object.assign(this.element,X),f!==void 0?this.element.value=f: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===v.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??O,formatOn:this.options.formatOn??R,thousandSeparator:this.options.thousandSeparator??_,thousandStyle:this.options.thousandStyle??P,decimalSeparator:this.options.decimalSeparator??E,enableCompactNotation:this.options.enableCompactNotation??B,enableNegative:this.options.enableNegative??W,enableLeadingZeros:this.options.enableLeadingZeros??k,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){const r=n??t;if(this.resolvedOptions.rawValueMode&&this.updateRawValue(r),this.resolvedOptions.onChange){const i=this.resolvedOptions.rawValueMode?this.rawValue:t;this.resolvedOptions.onChange(i)}}formatValueForDisplay(t){if(!t)return t;const{thousandSeparator:n,thousandStyle:r,enableLeadingZeros:i,decimalSeparator:a}=this.resolvedOptions;return n&&r!==b.None?z(t,n,r,i,a):t}handleChange(t){const n=t.target;q(t,this.resolvedOptions.decimalMaxLength,this.caretPositionBeforeChange,this.buildFormattingOptions()),this.caretPositionBeforeChange=void 0,this.handleValueChange(n.value)}handleKeyDown(t){const n=t.target,{selectionStart:r,selectionEnd:i}=n,a=this.buildFormattingOptions(),s=K(t,{formatOn:a.formatOn,thousandSeparator:a.thousandSeparator,ThousandStyle:a.ThousandStyle,decimalSeparator:a.decimalSeparator});s?this.caretPositionBeforeChange={selectionStart:r??0,selectionEnd:i??0,endOffset:s.endOffset}:this.caretPositionBeforeChange={selectionStart:r??0,selectionEnd:i??0}}handlePaste(t){const n=Q(t,this.resolvedOptions.decimalMaxLength,this.buildFormattingOptions());this.handleValueChange(n);const r=new Event("input",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(r)}handleFocus(t){if(this.resolvedOptions.formatOn===v.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:i}=this.resolvedOptions;if(r&&i!==b.None&&n.value){const a=n.value,s=this.formatValueForDisplay(n.value);if(n.value=s,this.handleValueChange(s),a!==s){const o=new Event("input",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(o);const c=new Event("change",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(c)}}}updateRawValue(t){const n=this.element.getAttribute("data-raw-value");if(n!==null){this.rawValue=n,this.element.removeAttribute("data-raw-value");return}if(!this.resolvedOptions.thousandSeparator){this.rawValue=t;return}this.rawValue=L(t,this.resolvedOptions.thousandSeparator)}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(m(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=v;exports.NumoraInput=Ke;exports.ThousandStyle=b;exports.formatValueForNumora=_e;exports.handleOnChangeNumoraInput=q;exports.handleOnKeyDownNumoraInput=K;exports.handleOnPasteNumoraInput=Q;
package/dist/index.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  var Q = Object.defineProperty;
2
2
  var X = (e, t, n) => t in e ? Q(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var N = (e, t, n) => X(e, typeof t != "symbol" ? t + "" : t, n);
3
+ var w = (e, t, n) => X(e, typeof t != "symbol" ? t + "" : t, n);
4
4
  var v = /* @__PURE__ */ ((e) => (e.Blur = "blur", e.Change = "change", e))(v || {}), b = /* @__PURE__ */ ((e) => (e.None = "none", e.Thousand = "thousand", e.Lakh = "lakh", e.Wan = "wan", e))(b || {});
5
- const x = 2, I = 0, R = v.Blur, O = ",", _ = b.None, E = ".", P = !1, B = !1, W = !1, k = !1;
5
+ const I = 2, R = 0, O = v.Blur, _ = ",", P = b.None, E = ".", B = !1, W = !1, k = !1, Z = !1;
6
6
  function D(e) {
7
7
  return e.replace(/[-[\]/{}()*+?.\\^$|]/g, "\\$&");
8
8
  }
9
- function C(e) {
9
+ function y(e) {
10
10
  return {
11
11
  decimalSeparator: (e == null ? void 0 : e.decimalSeparator) ?? E,
12
12
  thousandSeparator: e == null ? void 0 : e.thousandSeparator
@@ -104,15 +104,15 @@ function ie(e, t, n) {
104
104
  const s = e.length - n;
105
105
  if (s <= 0) {
106
106
  const o = Math.abs(s), c = `0.${"0".repeat(o)}${r}`;
107
- return y(c);
107
+ return A(c);
108
108
  }
109
109
  if (s < e.length) {
110
110
  const o = r.slice(0, s), c = r.slice(s), l = `${o}.${c}`;
111
- return y(l);
111
+ return A(l);
112
112
  }
113
- return y(r);
113
+ return A(r);
114
114
  }
115
- function y(e) {
115
+ function A(e) {
116
116
  if (!e.includes("."))
117
117
  return e;
118
118
  if (e === "0" || e === "0.")
@@ -221,12 +221,12 @@ function he(e, t, n) {
221
221
  thousandSeparator: n ? t.thousandSeparator : void 0
222
222
  };
223
223
  }
224
- const w = {
224
+ const N = {
225
225
  thousand: { size: 3 },
226
226
  lakh: { firstGroup: 3, restGroup: 2 },
227
227
  wan: { size: 4 }
228
228
  };
229
- function U(e, t, n, r = !1, i = ".") {
229
+ function z(e, t, n, r = !1, i = ".") {
230
230
  if (!e || e === "0" || e === i || e === "-" || e === `-${i}`)
231
231
  return e;
232
232
  const a = e.includes(i), s = e.startsWith("-"), o = s ? e.slice(1) : e, [c, l] = o.split(i);
@@ -239,15 +239,15 @@ function U(e, t, n, r = !1, i = ".") {
239
239
  if (u) {
240
240
  const f = u[1], g = c.slice(f.length);
241
241
  if (g) {
242
- const p = Z(g, t, n), $ = f + p, M = s ? "-" : "";
242
+ const p = G(g, t, n), $ = f + p, M = s ? "-" : "";
243
243
  return a ? l ? `${M}${$}${i}${l}` : `${M}${$}${i}` : `${M}${$}`;
244
244
  }
245
245
  }
246
246
  }
247
- const h = Z(c, t, n), d = s ? "-" : "";
247
+ const h = G(c, t, n), d = s ? "-" : "";
248
248
  return a ? l ? `${d}${h}${i}${l}` : `${d}${h}${i}` : `${d}${h}`;
249
249
  }
250
- function Z(e, t, n) {
250
+ function G(e, t, n) {
251
251
  if (e === "0" || e === "")
252
252
  return e;
253
253
  switch (n) {
@@ -264,28 +264,28 @@ function Z(e, t, n) {
264
264
  }
265
265
  }
266
266
  function ue(e, t) {
267
- return z(e, t, w.thousand.size);
267
+ return j(e, t, N.thousand.size);
268
268
  }
269
269
  function de(e, t) {
270
- if (e.length <= w.lakh.firstGroup)
270
+ if (e.length <= N.lakh.firstGroup)
271
271
  return e;
272
- const n = e.split("").reverse(), r = [], i = n.slice(0, w.lakh.firstGroup).reverse().join("");
272
+ const n = e.split("").reverse(), r = [], i = n.slice(0, N.lakh.firstGroup).reverse().join("");
273
273
  r.push(i);
274
- for (let a = w.lakh.firstGroup; a < n.length; a += w.lakh.restGroup)
275
- r.push(n.slice(a, a + w.lakh.restGroup).reverse().join(""));
274
+ for (let a = N.lakh.firstGroup; a < n.length; a += N.lakh.restGroup)
275
+ r.push(n.slice(a, a + N.lakh.restGroup).reverse().join(""));
276
276
  return r.reverse().join(t);
277
277
  }
278
278
  function fe(e, t) {
279
- return z(e, t, w.wan.size);
279
+ return j(e, t, N.wan.size);
280
280
  }
281
- function z(e, t, n) {
281
+ function j(e, t, n) {
282
282
  const r = e.split("").reverse(), i = [];
283
283
  for (let a = 0; a < r.length; a += n)
284
284
  i.push(r.slice(a, a + n).reverse().join(""));
285
285
  return i.reverse().join(t);
286
286
  }
287
287
  function ge(e, t, n) {
288
- return (t == null ? void 0 : t.formatOn) === "change" && t.thousandSeparator ? U(
288
+ return (t == null ? void 0 : t.formatOn) === "change" && t.thousandSeparator ? z(
289
289
  e,
290
290
  t.thousandSeparator,
291
291
  t.ThousandStyle ?? b.None,
@@ -315,7 +315,7 @@ function pe(e, t, n, r = ".") {
315
315
  }
316
316
  return e.length;
317
317
  }
318
- function A(e, t, n, r = ".") {
318
+ function C(e, t, n, r = ".") {
319
319
  if (t === 0)
320
320
  return 0;
321
321
  let i = 0;
@@ -330,7 +330,7 @@ function A(e, t, n, r = ".") {
330
330
  }
331
331
  return e.length;
332
332
  }
333
- function j(e, t, n) {
333
+ function J(e, t, n) {
334
334
  return t < 0 || t >= e.length ? !1 : e[t] === n;
335
335
  }
336
336
  function be(e, t = {}) {
@@ -363,13 +363,13 @@ function T(e, t, n, r) {
363
363
  }
364
364
  return (t === -1 || t > i) && (t = i), t;
365
365
  }
366
- const J = (e, t) => e === t;
366
+ const H = (e, t) => e === t;
367
367
  function Se(e, t, n, r, i, a, s = ".", o = {}) {
368
368
  if (n < 0)
369
369
  return 0;
370
370
  if (n > e.length || e === "" || t === "")
371
371
  return t.length;
372
- const c = t.length < e.length, l = j(
372
+ const c = t.length < e.length, l = J(
373
373
  e,
374
374
  n,
375
375
  r
@@ -379,7 +379,7 @@ function Se(e, t, n, r, i, a, s = ".", o = {}) {
379
379
  e,
380
380
  t,
381
381
  n,
382
- o.isCharacterEquivalent || J,
382
+ o.isCharacterEquivalent || H,
383
383
  a,
384
384
  o
385
385
  );
@@ -466,7 +466,7 @@ function $e(e, t, n, r, i, a, s, o, c, l = {}) {
466
466
  t.length,
467
467
  r,
468
468
  c
469
- ), f = d - u, g = we(
469
+ ), f = d - u, g = Ne(
470
470
  e,
471
471
  n,
472
472
  r,
@@ -475,7 +475,7 @@ function $e(e, t, n, r, i, a, s, o, c, l = {}) {
475
475
  a,
476
476
  o,
477
477
  c
478
- ), p = a === -1 || n <= a, $ = Ne(
478
+ ), p = a === -1 || n <= a, $ = we(
479
479
  t,
480
480
  g,
481
481
  r,
@@ -505,7 +505,7 @@ function Ee(e, t, n, r, i, a) {
505
505
  }
506
506
  return n;
507
507
  }
508
- function we(e, t, n, r, i, a, s, o) {
508
+ function Ne(e, t, n, r, i, a, s, o) {
509
509
  if (s) {
510
510
  const { start: l, isDelete: h } = s;
511
511
  return h ? S(
@@ -522,7 +522,7 @@ function we(e, t, n, r, i, a, s, o) {
522
522
  }
523
523
  return t > 0 && e[t - 1] === n && i > 0 ? r + 1 : r;
524
524
  }
525
- function Ne(e, t, n, r, i, a, s, o) {
525
+ function we(e, t, n, r, i, a, s, o) {
526
526
  if (s && o !== -1) {
527
527
  const l = e.substring(0, o), h = S(
528
528
  l,
@@ -531,7 +531,7 @@ function Ne(e, t, n, r, i, a, s, o) {
531
531
  a
532
532
  );
533
533
  if (t <= h) {
534
- const d = A(
534
+ const d = C(
535
535
  l,
536
536
  t,
537
537
  n,
@@ -551,7 +551,7 @@ function Ne(e, t, n, r, i, a, s, o) {
551
551
  return d;
552
552
  }
553
553
  }
554
- const c = A(
554
+ const c = C(
555
555
  e,
556
556
  t,
557
557
  n,
@@ -592,13 +592,13 @@ function Le(e, t, n, r, i, a) {
592
592
  const h = l - c;
593
593
  let d = o;
594
594
  h > 0 && !s && o < c && (d = o + 1);
595
- const u = A(
595
+ const u = C(
596
596
  t,
597
597
  d,
598
598
  r,
599
599
  a
600
600
  );
601
- return i && !j(t, u, r) ? Math.max(0, u - 1) : u;
601
+ return i && !J(t, u, r) ? Math.max(0, u - 1) : u;
602
602
  }
603
603
  function De(e, t, n) {
604
604
  const { selectionStart: r, selectionEnd: i, endOffset: a = 0 } = e;
@@ -647,7 +647,7 @@ function Me(e, t) {
647
647
  isDelete: a > s
648
648
  };
649
649
  }
650
- function G(e, t) {
650
+ function U(e, t) {
651
651
  if (e.value = e.value, e === null)
652
652
  return !1;
653
653
  if (e.createTextRange) {
@@ -657,8 +657,8 @@ function G(e, t) {
657
657
  return e.selectionStart !== null || e.selectionStart === 0 ? (e.focus(), e.setSelectionRange(t, t), !0) : (e.focus(), !1);
658
658
  }
659
659
  function me(e, t, n) {
660
- return e.selectionStart === 0 && e.selectionEnd === e.value.length ? null : (G(e, t), setTimeout(() => {
661
- e.value === n && e.selectionStart !== t && G(e, t);
660
+ return e.selectionStart === 0 && e.selectionEnd === e.value.length ? null : (U(e, t), setTimeout(() => {
661
+ e.value === n && e.selectionStart !== t && U(e, t);
662
662
  }, 0));
663
663
  }
664
664
  function ye(e) {
@@ -687,7 +687,7 @@ function Ce(e, t, n, r, i, a, s) {
687
687
  decimalSeparator: a.decimalSeparator
688
688
  }), u = {
689
689
  thousandSeparator: (s == null ? void 0 : s.thousandSeparator) ?? a.thousandSeparator,
690
- isCharacterEquivalent: J,
690
+ isCharacterEquivalent: H,
691
691
  boundary: d
692
692
  }, f = (s == null ? void 0 : s.thousandSeparator) ?? a.thousandSeparator ?? ",", g = (s == null ? void 0 : s.ThousandStyle) ?? b.None, p = Se(
693
693
  t,
@@ -701,7 +701,7 @@ function Ce(e, t, n, r, i, a, s) {
701
701
  );
702
702
  me(e, p, n);
703
703
  }
704
- function H(e, t, n, r, i) {
704
+ function x(e, t, n, r, i) {
705
705
  const a = le(
706
706
  e,
707
707
  he(r, i, n)
@@ -725,7 +725,7 @@ function Te(e, t, n) {
725
725
  };
726
726
  }
727
727
  function xe(e, t) {
728
- const { decimalSeparator: n } = C(t), r = e.target;
728
+ const { decimalSeparator: n } = y(t), r = e.target;
729
729
  if (V(e, r, t, n)) {
730
730
  e.preventDefault();
731
731
  return;
@@ -733,7 +733,7 @@ function xe(e, t) {
733
733
  return Ae(e, r, t), Te(e.key, r.selectionStart, r.selectionEnd);
734
734
  }
735
735
  function Ie(e, t, n, r) {
736
- const i = e.target, a = i.value, s = ye(i), o = C(r), c = (r == null ? void 0 : r.formatOn) === v.Change, { formatted: l, raw: h } = H(
736
+ const i = e.target, a = i.value, s = ye(i), o = y(r), c = (r == null ? void 0 : r.formatOn) === v.Change, { formatted: l, raw: h } = x(
737
737
  a,
738
738
  t,
739
739
  c,
@@ -757,7 +757,7 @@ function Re(e, t, n, r) {
757
757
  function Oe(e, t, n) {
758
758
  var f;
759
759
  e.preventDefault();
760
- const r = e.target, { value: i, selectionStart: a, selectionEnd: s } = r, o = C(n), c = ((f = e.clipboardData) == null ? void 0 : f.getData("text/plain")) || "", l = i.slice(0, a || 0) + c + i.slice(s || 0), { formatted: h, raw: d } = H(
760
+ const r = e.target, { value: i, selectionStart: a, selectionEnd: s } = r, o = y(n), c = ((f = e.clipboardData) == null ? void 0 : f.getData("text/plain")) || "", l = i.slice(0, a || 0) + c + i.slice(s || 0), { formatted: h, raw: d } = x(
761
761
  l,
762
762
  t,
763
763
  !0,
@@ -773,6 +773,18 @@ function Oe(e, t, n) {
773
773
  );
774
774
  return r.setSelectionRange(u, u), r.value;
775
775
  }
776
+ function Ke(e, t, n) {
777
+ if (!e)
778
+ return e;
779
+ const r = y(n), i = !0, { formatted: a } = x(
780
+ e,
781
+ t,
782
+ i,
783
+ n,
784
+ r
785
+ );
786
+ return a;
787
+ }
776
788
  function _e(e, t) {
777
789
  const n = D(e);
778
790
  return t ? `^-?[0-9]*[${n}]?[0-9]*$` : `^[0-9]*[${n}]?[0-9]*$`;
@@ -880,26 +892,26 @@ function Je(e) {
880
892
  `onChange must be a function or undefined. Received: ${typeof e} (${JSON.stringify(e)})`
881
893
  );
882
894
  }
883
- class Ke {
895
+ class Qe {
884
896
  constructor(t, {
885
- decimalMaxLength: n = x,
886
- decimalMinLength: r = I,
887
- formatOn: i = R,
888
- thousandSeparator: a = O,
889
- thousandStyle: s = _,
897
+ decimalMaxLength: n = I,
898
+ decimalMinLength: r = R,
899
+ formatOn: i = O,
900
+ thousandSeparator: a = _,
901
+ thousandStyle: s = P,
890
902
  decimalSeparator: o = E,
891
- enableCompactNotation: c = P,
892
- enableNegative: l = B,
893
- enableLeadingZeros: h = W,
894
- rawValueMode: d = k,
903
+ enableCompactNotation: c = B,
904
+ enableNegative: l = W,
905
+ enableLeadingZeros: h = k,
906
+ rawValueMode: d = Z,
895
907
  onChange: u,
896
908
  ...f
897
909
  }) {
898
- N(this, "element");
899
- N(this, "options");
900
- N(this, "resolvedOptions");
901
- N(this, "rawValue", "");
902
- N(this, "caretPositionBeforeChange");
910
+ w(this, "element");
911
+ w(this, "options");
912
+ w(this, "resolvedOptions");
913
+ w(this, "rawValue", "");
914
+ w(this, "caretPositionBeforeChange");
903
915
  if (Pe({
904
916
  decimalMaxLength: n,
905
917
  decimalMinLength: r,
@@ -969,16 +981,16 @@ class Ke {
969
981
  }
970
982
  getResolvedOptions() {
971
983
  return {
972
- decimalMaxLength: this.options.decimalMaxLength ?? x,
973
- decimalMinLength: this.options.decimalMinLength ?? I,
974
- formatOn: this.options.formatOn ?? R,
975
- thousandSeparator: this.options.thousandSeparator ?? O,
976
- thousandStyle: this.options.thousandStyle ?? _,
984
+ decimalMaxLength: this.options.decimalMaxLength ?? I,
985
+ decimalMinLength: this.options.decimalMinLength ?? R,
986
+ formatOn: this.options.formatOn ?? O,
987
+ thousandSeparator: this.options.thousandSeparator ?? _,
988
+ thousandStyle: this.options.thousandStyle ?? P,
977
989
  decimalSeparator: this.options.decimalSeparator ?? E,
978
- enableCompactNotation: this.options.enableCompactNotation ?? P,
979
- enableNegative: this.options.enableNegative ?? B,
980
- enableLeadingZeros: this.options.enableLeadingZeros ?? W,
981
- rawValueMode: this.options.rawValueMode ?? k,
990
+ enableCompactNotation: this.options.enableCompactNotation ?? B,
991
+ enableNegative: this.options.enableNegative ?? W,
992
+ enableLeadingZeros: this.options.enableLeadingZeros ?? k,
993
+ rawValueMode: this.options.rawValueMode ?? Z,
982
994
  onChange: this.options.onChange
983
995
  };
984
996
  }
@@ -1006,7 +1018,7 @@ class Ke {
1006
1018
  if (!t)
1007
1019
  return t;
1008
1020
  const { thousandSeparator: n, thousandStyle: r, enableLeadingZeros: i, decimalSeparator: a } = this.resolvedOptions;
1009
- return n && r !== b.None ? U(
1021
+ return n && r !== b.None ? z(
1010
1022
  t,
1011
1023
  n,
1012
1024
  r,
@@ -1149,6 +1161,10 @@ class Ke {
1149
1161
  }
1150
1162
  export {
1151
1163
  v as FormatOn,
1152
- Ke as NumoraInput,
1153
- b as ThousandStyle
1164
+ Qe as NumoraInput,
1165
+ b as ThousandStyle,
1166
+ Ke as formatValueForNumora,
1167
+ Ie as handleOnChangeNumoraInput,
1168
+ xe as handleOnKeyDownNumoraInput,
1169
+ Oe as handleOnPasteNumoraInput
1154
1170
  };
@@ -22,3 +22,13 @@ export declare function handleOnKeyDownNumoraInput(e: KeyboardEvent, formattingO
22
22
  */
23
23
  export declare function handleOnChangeNumoraInput(e: Event, decimalMaxLength: number, caretPositionBeforeChange?: CaretPositionInfo, formattingOptions?: FormattingOptions): void;
24
24
  export declare function handleOnPasteNumoraInput(e: ClipboardEvent, decimalMaxLength: number, formattingOptions?: FormattingOptions): string;
25
+ /**
26
+ * Formats a value programmatically using Numora's full pipeline.
27
+ * This is useful for formatting values that are set externally (e.g., from props in React).
28
+ *
29
+ * @param value - The raw value to format
30
+ * @param maxDecimals - Maximum number of decimal places allowed
31
+ * @param formattingOptions - Formatting options (formatOn, thousandSeparator, etc.)
32
+ * @returns The formatted value string
33
+ */
34
+ export declare function formatValueForNumora(value: string, maxDecimals: number, formattingOptions?: FormattingOptions): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "numora",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Precision-first numeric input library for DeFi and financial applications",
5
5
  "homepage": "https://numora.xyz/",
6
6
  "main": "dist/index.js",
@@ -57,6 +57,9 @@
57
57
  "vite": "^6.2.2",
58
58
  "vitest": "^3.0.9"
59
59
  },
60
+ "publishConfig": {
61
+ "access": "public"
62
+ },
60
63
  "scripts": {
61
64
  "build": "vite build && tsc --emitDeclarationOnly",
62
65
  "test": "vitest run",