numora 3.5.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,400 +1,537 @@
1
- var re = Object.defineProperty;
2
- var ie = (e, t, n) => t in e ? re(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var w = (e, t, n) => ie(e, typeof t != "symbol" ? t + "" : t, n);
4
- var b = /* @__PURE__ */ ((e) => (e.Blur = "blur", e.Change = "change", e))(b || {}), L = /* @__PURE__ */ ((e) => (e.None = "none", e.Thousand = "thousand", e.Lakh = "lakh", e.Wan = "wan", e))(L || {});
5
- const B = 2, G = 0, k = b.Blur, se = ",", Z = L.None, C = ".", W = !1, U = !1, z = !1, J = !1;
6
- function y(e) {
7
- return e.replace(/[-[\]/{}()*+?.\\^$|]/g, "\\$&");
1
+ var ee = Object.defineProperty;
2
+ var te = (t, e, n) => e in t ? ee(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
+ var A = (t, e, n) => te(t, typeof e != "symbol" ? e + "" : e, n);
4
+ var I = /* @__PURE__ */ ((t) => (t.Blur = "blur", t.Change = "change", t))(I || {}), y = /* @__PURE__ */ ((t) => (t.None = "none", t.Thousand = "thousand", t.Lakh = "lakh", t.Wan = "wan", t))(y || {});
5
+ const L = {
6
+ InsertText: "insertText",
7
+ InsertFromPaste: "insertFromPaste",
8
+ InsertFromDrop: "insertFromDrop",
9
+ DeleteContentBackward: "deleteContentBackward",
10
+ DeleteContentForward: "deleteContentForward",
11
+ DeleteByCut: "deleteByCut",
12
+ DeleteByDrag: "deleteByDrag",
13
+ DeleteSoftLineBackward: "deleteSoftLineBackward",
14
+ DeleteHardLineBackward: "deleteHardLineBackward",
15
+ DeleteSoftLineForward: "deleteSoftLineForward",
16
+ DeleteHardLineForward: "deleteHardLineForward",
17
+ HistoryUndo: "historyUndo",
18
+ HistoryRedo: "historyRedo"
19
+ }, ne = 2, re = 0, se = I.Blur, ie = ",", ae = y.None, $ = ".", ce = !1, le = !1, he = !1, ue = !1, oe = !1, U = /* @__PURE__ */ new Map();
20
+ function m(t, e = "g") {
21
+ const n = `${t}:${e}`;
22
+ let r = U.get(n);
23
+ return r || (r = new RegExp(t, e), U.set(n, r)), r;
8
24
  }
9
- const P = /* @__PURE__ */ new Map();
10
- function _(e, t = "g") {
11
- const n = `${e}:${t}`;
12
- let r = P.get(n);
13
- return r || (r = new RegExp(e, t), P.set(n, r)), r;
25
+ function M(t) {
26
+ return t.replace(/[-[\]/{}()*+?.\\^$|]/g, "\\$&");
14
27
  }
15
- function ae(e, t = "g") {
16
- const n = y(e);
17
- return _(n, t);
18
- }
19
- const ce = /[.,]/g;
20
- function x(e) {
28
+ const de = /[.,]/g;
29
+ function G(t) {
21
30
  return {
22
- decimalSeparator: (e == null ? void 0 : e.decimalSeparator) ?? C,
23
- thousandSeparator: e == null ? void 0 : e.thousandSeparator
31
+ decimalSeparator: (t == null ? void 0 : t.decimalSeparator) ?? $,
32
+ thousandSeparator: t == null ? void 0 : t.thousandSeparator
24
33
  };
25
34
  }
26
- function Y(e, t) {
27
- const n = e.startsWith("-"), r = n ? e.slice(1) : e, [i = "", s = ""] = r.split(t);
35
+ function K(t, e) {
36
+ const n = t.startsWith("-"), r = n ? t.slice(1) : t, [s = "", i = ""] = r.split(e);
28
37
  return {
29
38
  sign: n ? "-" : "",
30
- integer: i,
31
- decimal: s
39
+ integer: s,
40
+ decimal: i
32
41
  };
33
42
  }
34
- const le = (e, t, n = C) => {
35
- const { sign: r, integer: i, decimal: s } = Y(e, n);
36
- if (!s) return e;
37
- const a = s.slice(0, t);
38
- return `${r}${i}${n}${a}`;
39
- }, oe = (e, t = C) => {
40
- const n = e.indexOf(t);
41
- if (n === -1 || n === e.length - 1) return e;
42
- const r = e.slice(0, n + 1), i = e.slice(n + 1), a = t === "." || t === "," ? ce : _("[,\\." + y(t) + "]", "g");
43
- return r + i.replace(a, "");
44
- }, he = (e, t = 0, n = C) => {
45
- if (t <= 0) return e;
46
- const { sign: r, integer: i, decimal: s } = Y(e, n);
47
- if (s.length >= t)
48
- return e;
49
- const a = s.padEnd(t, "0");
50
- return `${r}${i}${n}${a}`;
51
- }, D = {
43
+ const fe = (t, e, n = $) => {
44
+ const { sign: r, integer: s, decimal: i } = K(t, n);
45
+ if (!i) return t;
46
+ const a = i.slice(0, e);
47
+ return `${r}${s}${n}${a}`;
48
+ }, Se = (t, e = $) => {
49
+ const n = t.indexOf(e);
50
+ if (n === -1 || n === t.length - 1) return t;
51
+ const r = t.slice(0, n + 1), s = t.slice(n + 1), a = e === "." || e === "," ? de : m("[,\\." + M(e) + "]", "g");
52
+ return r + s.replace(a, "");
53
+ }, ge = (t, e = 0, n = $) => {
54
+ if (e <= 0) return t;
55
+ const { sign: r, integer: s, decimal: i } = K(t, n);
56
+ if (i.length >= e)
57
+ return t;
58
+ const a = i.padEnd(e, "0");
59
+ return `${r}${s}${n}${a}`;
60
+ }, Ee = (t, e = !1, n = ".") => {
61
+ const r = M(n), s = m(`[^0-9${r}]`, "g");
62
+ if (!e)
63
+ return t.replace(s, "");
64
+ const i = t.startsWith("-"), a = t.replace(s, "");
65
+ return i && (a.length > 0 || t === "-") ? "-" + a : a;
66
+ }, pe = /([+-]?\d+\.?\d*)[eE]([+-]?\d+)/g, Y = /^0+$/, R = /\.?0+$/;
67
+ function Le(t) {
68
+ return !t.includes("e") && !t.includes("E") ? t : t.replace(pe, (e, n, r) => {
69
+ const s = parseInt(r, 10);
70
+ if (s === 0) return n;
71
+ const i = n.startsWith("-"), a = i ? n.slice(1) : n, [c, h = ""] = a.split("."), l = s > 0 ? De(c, h, s) : we(c, h, Math.abs(s));
72
+ return i ? "-" + l : l;
73
+ });
74
+ }
75
+ function De(t, e, n) {
76
+ const r = t + e;
77
+ if (r === "0" || Y.test(r))
78
+ return "0";
79
+ const s = e.length;
80
+ if (n <= s) {
81
+ const a = r.slice(0, t.length + n), c = r.slice(t.length + n);
82
+ return c ? `${a}.${c}` : a;
83
+ }
84
+ const i = n - s;
85
+ return r + "0".repeat(i);
86
+ }
87
+ function we(t, e, n) {
88
+ const r = t + e;
89
+ if (r === "0" || Y.test(r))
90
+ return "0";
91
+ const i = t.length - n;
92
+ if (i <= 0) {
93
+ const a = Math.abs(i), c = `0.${"0".repeat(a)}${r}`;
94
+ return _(c);
95
+ }
96
+ if (i < t.length) {
97
+ const a = r.slice(0, i), c = r.slice(i), h = `${a}.${c}`;
98
+ return _(h);
99
+ }
100
+ return _(r);
101
+ }
102
+ function _(t) {
103
+ if (!t.includes("."))
104
+ return t;
105
+ if (t === "0.")
106
+ return "0";
107
+ if (t.startsWith("0.")) {
108
+ const e = t.replace(R, "");
109
+ return e === "0" ? "0" : e || "0";
110
+ }
111
+ if (t.startsWith("-0.")) {
112
+ const e = t.replace(R, "");
113
+ return e === "-0" || e === "0" ? "0" : e || "0";
114
+ }
115
+ return t.replace(R, "") || t;
116
+ }
117
+ const ye = /(\d+\.?\d*)\s*([kmbt])/gi, Ie = /^0+/, Ae = /^(-?)0+([1-9])/, Ne = /^-?0+$/, Ce = /\.?0+$/, be = {
118
+ k: 3,
119
+ // Thousand
120
+ m: 6,
121
+ // Million
122
+ b: 9,
123
+ // Billion
124
+ t: 12
125
+ // Trillion
126
+ };
127
+ function Te(t) {
128
+ return t.replace(ye, (e, n, r) => {
129
+ const s = r.toLowerCase(), i = be[s];
130
+ if (!i)
131
+ return e;
132
+ const [a, c = ""] = n.split("."), h = a.replace(Ie, "") || "0";
133
+ let l;
134
+ if (c.length === 0)
135
+ l = h + "0".repeat(i);
136
+ else if (c.length <= i) {
137
+ const u = i - c.length;
138
+ l = h + c + "0".repeat(u);
139
+ } else {
140
+ const u = c.slice(0, i), f = c.slice(i);
141
+ l = h + u + "." + f;
142
+ }
143
+ return l = l.replace(Ae, "$1$2"), Ne.test(l) && (l = "0"), l.includes(".") && (l = l.replace(Ce, "")), l;
144
+ });
145
+ }
146
+ function ve(t) {
147
+ if (!t || t === "0" || t === "-0" || t === "-" || t === ".")
148
+ return t;
149
+ const e = t.startsWith("-"), n = e ? t.slice(1) : t;
150
+ if (n === ".")
151
+ return t;
152
+ if (n.includes(".")) {
153
+ const [s, i] = n.split(".");
154
+ if (s) {
155
+ const c = (s.replace(/^0+/, "") || "0") + "." + i;
156
+ return e ? "-" + c : c;
157
+ }
158
+ return t;
159
+ }
160
+ if (n.startsWith("0")) {
161
+ const s = n.replace(/^0+/, "") || "0";
162
+ return e ? "-" + s : s;
163
+ }
164
+ return t;
165
+ }
166
+ function Me(t, e = ".") {
167
+ return t && (t === e ? "0" + e : t === "-" + e ? "-0" + e : t.startsWith("-" + e) ? "-0" + t.slice(1) : t.startsWith(e) ? "0" + t : t);
168
+ }
169
+ function $e(t, e, n = ".") {
170
+ if (e < 0 || t.length <= e) return t;
171
+ let r = t.slice(0, e);
172
+ return r.endsWith(n) && (r = r.slice(0, -1)), r === "-" ? "" : r;
173
+ }
174
+ function xe(t) {
175
+ return t.replace(/[\s\u200B]/g, "");
176
+ }
177
+ function Re(t) {
178
+ return t.replace(
179
+ /[\uFF10-\uFF19]/g,
180
+ (e) => String.fromCharCode(e.charCodeAt(0) - 65248)
181
+ );
182
+ }
183
+ function b(t, e) {
184
+ return t.replace(m(M(e)), "");
185
+ }
186
+ const _e = (t, e) => {
187
+ let n = xe(t);
188
+ return e != null && e.thousandSeparator && (n = b(n, e.thousandSeparator)), n = Re(n), e != null && e.enableCompactNotation && (n = Te(n)), n = Le(n), n = Ee(
189
+ n,
190
+ e == null ? void 0 : e.enableNegative,
191
+ e == null ? void 0 : e.decimalSeparator
192
+ ), n = Se(n, e == null ? void 0 : e.decimalSeparator), e != null && e.enableLeadingZeros || (n = ve(n)), e != null && e.autoAddLeadingZero && (n = Me(n, e == null ? void 0 : e.decimalSeparator)), (e == null ? void 0 : e.maxLength) !== void 0 && (n = $e(
193
+ n,
194
+ e.maxLength,
195
+ e == null ? void 0 : e.decimalSeparator
196
+ )), n;
197
+ }, C = {
52
198
  thousand: { size: 3 },
53
199
  lakh: { firstGroup: 3, restGroup: 2 },
54
200
  wan: { size: 4 }
55
- }, ue = /^(0+)/;
56
- function Q(e, t, n = L.Thousand, r = !1, i = ".") {
57
- if (!e || e === "0" || e === i || e === "-" || e === `-${i}`)
58
- return e;
59
- const s = e.includes(i), a = e.startsWith("-"), c = a ? e.slice(1) : e, [o, l] = c.split(i);
60
- if (!o) {
61
- const u = l ? `${i}${l}` : c;
62
- return a ? `-${u}` : u;
201
+ }, ke = /^(0+)/;
202
+ function Q(t, e, n = y.Thousand, r = !1, s = ".") {
203
+ if (!t || t === "0" || t === s || t === "-" || t === `-${s}`)
204
+ return t;
205
+ const i = t.includes(s), a = t.startsWith("-"), c = a ? t.slice(1) : t, [h, l] = c.split(s);
206
+ if (!h) {
207
+ const o = l ? `${s}${l}` : c;
208
+ return a ? `-${o}` : o;
63
209
  }
64
- if (r && o.startsWith("0") && o.length > 1) {
65
- const u = o.match(ue);
66
- if (u) {
67
- const S = u[1], E = o.slice(S.length);
68
- if (E) {
69
- const p = X(E, t, n), d = S + p, f = a ? "-" : "";
70
- return s ? l ? `${f}${d}${i}${l}` : `${f}${d}${i}` : `${f}${d}`;
210
+ if (r && h.startsWith("0") && h.length > 1) {
211
+ const o = h.match(ke);
212
+ if (o) {
213
+ const p = o[1], g = h.slice(p.length);
214
+ if (g) {
215
+ const D = j(g, e, n), S = p + D, d = a ? "-" : "";
216
+ return i ? l ? `${d}${S}${s}${l}` : `${d}${S}${s}` : `${d}${S}`;
71
217
  }
72
218
  }
73
219
  }
74
- const h = X(o, t, n), g = a ? "-" : "";
75
- return s ? l ? `${g}${h}${i}${l}` : `${g}${h}${i}` : `${g}${h}`;
220
+ const u = j(h, e, n), f = a ? "-" : "";
221
+ return i ? l ? `${f}${u}${s}${l}` : `${f}${u}${s}` : `${f}${u}`;
76
222
  }
77
- function X(e, t, n) {
78
- if (e === "0" || e === "")
79
- return e;
223
+ function j(t, e, n) {
224
+ if (t === "0" || t === "")
225
+ return t;
80
226
  switch (n) {
81
- case L.None:
82
- return e;
83
- case L.Thousand:
84
- return j(e, t, D.thousand.size);
85
- case L.Lakh:
86
- return de(e, t);
87
- case L.Wan:
88
- return j(e, t, D.wan.size);
227
+ case y.None:
228
+ return t;
229
+ case y.Thousand:
230
+ return H(t, e, C.thousand.size);
231
+ case y.Lakh:
232
+ return Be(t, e);
233
+ case y.Wan:
234
+ return H(t, e, C.wan.size);
89
235
  default:
90
- return e;
236
+ return t;
91
237
  }
92
238
  }
93
- function de(e, t) {
94
- if (e.length <= D.lakh.firstGroup)
95
- return e;
96
- const n = [], r = e.length - D.lakh.firstGroup;
97
- n.unshift(e.slice(r));
98
- for (let i = r; i > 0; i -= D.lakh.restGroup)
99
- n.unshift(e.slice(Math.max(0, i - D.lakh.restGroup), i));
100
- return n.join(t);
239
+ function Be(t, e) {
240
+ if (t.length <= C.lakh.firstGroup)
241
+ return t;
242
+ const n = [], r = t.length - C.lakh.firstGroup;
243
+ n.unshift(t.slice(r));
244
+ for (let s = r; s > 0; s -= C.lakh.restGroup)
245
+ n.unshift(t.slice(Math.max(0, s - C.lakh.restGroup), s));
246
+ return n.join(e);
101
247
  }
102
- function j(e, t, n) {
248
+ function H(t, e, n) {
103
249
  const r = [];
104
- for (let i = e.length; i > 0; i -= n)
105
- r.unshift(e.slice(Math.max(0, i - n), i));
106
- return r.join(t);
107
- }
108
- function fe(e, t, n) {
109
- return (t == null ? void 0 : t.formatOn) === b.Change && t.thousandSeparator ? Q(
110
- e,
111
- t.thousandSeparator,
112
- t.ThousandStyle ?? L.None,
113
- t.enableLeadingZeros,
114
- (n == null ? void 0 : n.decimalSeparator) ?? C
115
- ) : e;
250
+ for (let s = t.length; s > 0; s -= n)
251
+ r.unshift(t.slice(Math.max(0, s - n), s));
252
+ return r.join(e);
116
253
  }
117
- function $(e, t, n) {
254
+ function N(t, e, n) {
118
255
  let r = 0;
119
- for (let i = 0; i < t && i < e.length; i++)
120
- e[i] !== n && r++;
256
+ for (let s = 0; s < e && s < t.length; s++)
257
+ t[s] !== n && r++;
121
258
  return r;
122
259
  }
123
- function ge(e, t, n) {
124
- if (t === 0)
260
+ function me(t, e, n) {
261
+ if (e === 0)
125
262
  return 0;
126
263
  let r = 0;
127
- for (let i = 0; i < e.length; i++)
128
- if (e[i] !== n) {
129
- if (r === t - 1)
130
- return i + 1;
264
+ for (let s = 0; s < t.length; s++)
265
+ if (t[s] !== n) {
266
+ if (r === e - 1)
267
+ return s + 1;
131
268
  r++;
132
269
  }
133
- return e.length;
270
+ return t.length;
134
271
  }
135
- function R(e, t, n) {
136
- if (t === 0)
272
+ function B(t, e, n) {
273
+ if (e === 0)
137
274
  return 0;
138
275
  let r = 0;
139
- for (let i = 0; i < e.length; i++)
140
- if (e[i] !== n) {
141
- if (r++, r === t)
142
- return i + 1;
143
- if (r > t)
144
- return i;
276
+ for (let s = 0; s < t.length; s++)
277
+ if (t[s] !== n) {
278
+ if (r++, r === e)
279
+ return s + 1;
280
+ if (r > e)
281
+ return s;
145
282
  }
146
- return e.length;
283
+ return t.length;
147
284
  }
148
- function V(e, t, n) {
149
- return t < 0 || t >= e.length ? !1 : e[t] === n;
285
+ function O(t, e, n) {
286
+ return e < 0 || e >= t.length ? !1 : t[e] === n;
150
287
  }
151
- const Se = /\d/;
152
- function Ee(e, t = {}) {
288
+ const Ge = /\d/;
289
+ function Ze(t, e = {}) {
153
290
  const {
154
291
  thousandSeparator: n,
155
292
  decimalSeparator: r = ".",
156
- prefix: i = "",
157
- suffix: s = ""
158
- } = t, a = new Array(e.length + 1).fill(!0);
159
- if (i && a.fill(!1, 0, i.length), s) {
160
- const c = e.length - s.length;
161
- a.fill(!1, c + 1, e.length + 1);
293
+ prefix: s = "",
294
+ suffix: i = ""
295
+ } = e, a = new Array(t.length + 1).fill(!0);
296
+ if (s && a.fill(!1, 0, s.length), i) {
297
+ const c = t.length - i.length;
298
+ a.fill(!1, c + 1, t.length + 1);
162
299
  }
163
- for (let c = 0; c < e.length; c++) {
164
- const o = e[c];
165
- (n && o === n || o === r) && (a[c] = !1, c + 1 < e.length && !Se.test(e[c + 1]) && (a[c + 1] = !1));
300
+ for (let c = 0; c < t.length; c++) {
301
+ const h = t[c];
302
+ (n && h === n || h === r) && (a[c] = !1, c + 1 < t.length && !Ge.test(t[c + 1]) && (a[c + 1] = !1));
166
303
  }
167
304
  return a.some((c) => c) || a.fill(!0), a;
168
305
  }
169
- function O(e, t, n, r) {
170
- const i = e.length;
171
- if (t = Math.max(0, Math.min(t, i)), r === "left") {
172
- for (; t >= 0 && !n[t]; )
173
- t--;
174
- t === -1 && (t = n.indexOf(!0));
306
+ function Z(t, e, n, r) {
307
+ const s = t.length;
308
+ if (e = Math.max(0, Math.min(e, s)), r === "left") {
309
+ for (; e >= 0 && !n[e]; )
310
+ e--;
311
+ e === -1 && (e = n.indexOf(!0));
175
312
  } else if (r === "right") {
176
- for (; t <= i && !n[t]; )
177
- t++;
178
- t > i && (t = n.lastIndexOf(!0));
179
- } else if (!n[t]) {
180
- let s = t;
181
- for (; s <= i && !n[s]; )
182
- s++;
183
- let a = t;
313
+ for (; e <= s && !n[e]; )
314
+ e++;
315
+ e > s && (e = n.lastIndexOf(!0));
316
+ } else if (!n[e]) {
317
+ let i = e;
318
+ for (; i <= s && !n[i]; )
319
+ i++;
320
+ let a = e;
184
321
  for (; a >= 0 && !n[a]; )
185
322
  a--;
186
- s <= i && a >= 0 ? t = t - a < s - t ? a : s : s <= i ? t = s : a >= 0 && (t = a);
323
+ i <= s && a >= 0 ? e = e - a < i - e ? a : i : i <= s ? e = i : a >= 0 && (e = a);
187
324
  }
188
- return (t === -1 || t > i) && (t = i), t;
325
+ return (e === -1 || e > s) && (e = s), e;
189
326
  }
190
- const q = /(\d+\.?\d*)\s*[kmbt]$/i, pe = (e, t) => e === t;
191
- function me(e, t, n, r, i, s, a = ".", c = {}) {
327
+ const P = /(\d+\.?\d*)\s*[kmbt]$/i, We = (t, e) => t === e;
328
+ function Ue(t, e, n, r, s, i, a = ".", c = {}) {
192
329
  if (n < 0)
193
330
  return 0;
194
- if (n > e.length || e === "" || t === "" || q.test(e) && !q.test(t) && t.length > e.length && n >= e.length - 1)
195
- return t.length;
196
- const o = t.length < e.length, l = V(
197
- e,
331
+ if (n > t.length || t === "" || e === "" || P.test(t) && !P.test(e) && e.length > t.length && n >= t.length - 1)
332
+ return e.length;
333
+ const h = e.length < t.length, l = O(
334
+ t,
198
335
  n,
199
336
  r
200
- ), h = e.indexOf(a), g = t.indexOf(a);
201
- if (c.isCharacterEquivalent && e !== t) {
202
- const d = {
337
+ ), u = t.indexOf(a), f = e.indexOf(a);
338
+ if (c.isCharacterEquivalent && t !== e) {
339
+ const S = {
203
340
  thousandSeparator: r || void 0,
204
341
  ...c
205
- }, f = be(
206
- e,
342
+ }, d = je(
207
343
  t,
344
+ e,
208
345
  n,
209
- c.isCharacterEquivalent || pe,
210
- s,
211
- d
346
+ c.isCharacterEquivalent || We,
347
+ i,
348
+ S
212
349
  );
213
- if (f !== void 0)
214
- return f;
350
+ if (d !== void 0)
351
+ return d;
215
352
  }
216
- const S = /* @__PURE__ */ new Map(), E = (d, f, N) => {
217
- const m = `${d === e ? "o" : "n"}:${f}`;
218
- return S.has(m) || S.set(m, $(d, f, r)), S.get(m);
353
+ const p = /* @__PURE__ */ new Map(), g = (S, d, E) => {
354
+ const w = `${S === t ? "o" : "n"}:${d}`;
355
+ return p.has(w) || p.set(w, N(S, d, r)), p.get(w);
219
356
  };
220
- if (o)
221
- return Le(
222
- e,
357
+ if (h)
358
+ return He(
223
359
  t,
360
+ e,
224
361
  n,
225
362
  r,
226
363
  l,
227
- h,
228
- g,
229
- s,
364
+ u,
365
+ f,
366
+ i,
230
367
  c,
231
- E
368
+ g
232
369
  );
233
- const p = De(
234
- e,
370
+ const D = Je(
235
371
  t,
372
+ e,
236
373
  n,
237
374
  r,
238
375
  l,
239
- E
376
+ g
240
377
  );
241
- return c.boundary ? O(t, p, c.boundary) : p;
378
+ return c.boundary ? Z(e, D, c.boundary) : D;
242
379
  }
243
- function be(e, t, n, r, i, s) {
244
- const a = e.length, c = t.length;
245
- let o = 0, l = 0, h = c;
246
- for (let f = 0; f < a; f++) {
247
- let N = -1;
248
- for (let m = o; m < c; m++)
380
+ function je(t, e, n, r, s, i) {
381
+ const a = t.length, c = e.length;
382
+ let h = 0, l = 0, u = c;
383
+ for (let d = 0; d < a; d++) {
384
+ let E = -1;
385
+ for (let w = h; w < c; w++)
249
386
  if (r(
250
- e[f],
251
- t[m],
387
+ t[d],
388
+ e[w],
252
389
  {
253
- oldValue: e,
254
- newValue: t,
255
- typedRange: i,
256
- oldIndex: f,
257
- newIndex: m
390
+ oldValue: t,
391
+ newValue: e,
392
+ typedRange: s,
393
+ oldIndex: d,
394
+ newIndex: w
258
395
  }
259
396
  )) {
260
- N = m;
397
+ E = w;
261
398
  break;
262
399
  }
263
- N !== -1 && (o = N + 1, f < n ? l = N + 1 : h === c && /\d/.test(e[f]) && (h = N));
400
+ E !== -1 && (h = E + 1, d < n ? l = E + 1 : u === c && /\d/.test(t[d]) && (u = E));
264
401
  }
265
- if (l > h) return h;
266
- const g = t.length < e.length || i !== void 0 && i.isDelete === !1;
267
- let u, S = !1, E = !1;
268
- if (g) {
269
- u = l;
270
- const f = s.thousandSeparator, N = s.decimalSeparator ?? ".", m = u < t.length ? t[u] : "";
271
- f && m === f ? (n > 0 ? e[n - 1] : "") === f ? (u = h, S = !0) : E = !0 : m === N && (E = !0);
402
+ if (l > u) return u;
403
+ const f = e.length < t.length || s !== void 0 && s.isDelete === !1;
404
+ let o, p = !1, g = !1;
405
+ if (f) {
406
+ o = l;
407
+ const d = i.thousandSeparator, E = i.decimalSeparator ?? ".", w = o < e.length ? e[o] : "";
408
+ d && w === d ? (n > 0 ? t[n - 1] : "") === d ? (o = u, p = !0) : g = !0 : w === E && (g = !0);
272
409
  } else
273
- u = n - l < h - n ? l : h;
274
- const p = g && !S ? "left" : "right";
275
- if (s.boundary)
276
- return E ? u : O(t, u, s.boundary, p);
277
- const d = s.thousandSeparator;
278
- if (!E && d && u >= 0 && u < t.length && t[u] === d)
279
- if (g && !S)
280
- for (; u > 0 && t[u] === d; ) u--;
410
+ o = n - l < u - n ? l : u;
411
+ const D = f && !p ? "left" : "right";
412
+ if (i.boundary)
413
+ return g ? o : Z(e, o, i.boundary, D);
414
+ const S = i.thousandSeparator;
415
+ if (!g && S && o >= 0 && o < e.length && e[o] === S)
416
+ if (f && !p)
417
+ for (; o > 0 && e[o] === S; ) o--;
281
418
  else
282
- for (; u < t.length && t[u] === d; ) u++;
283
- return u;
419
+ for (; o < e.length && e[o] === S; ) o++;
420
+ return o;
284
421
  }
285
- function Le(e, t, n, r, i, s, a, c, o = {}, l = $) {
286
- if (i)
287
- return Ne(
288
- e,
422
+ function He(t, e, n, r, s, i, a, c, h = {}, l = N) {
423
+ if (s)
424
+ return Pe(
289
425
  t,
426
+ e,
290
427
  n,
291
428
  r,
292
429
  a,
293
430
  l
294
431
  );
295
- const h = l(e, n, r), g = l(e, e.length, r), u = l(t, t.length, r), S = g - u, E = $e(
296
- e,
432
+ const u = l(t, n, r), f = l(t, t.length, r), o = l(e, e.length, r), p = f - o, g = ze(
433
+ t,
297
434
  n,
298
435
  r,
299
- h,
300
- S,
301
- s,
436
+ u,
437
+ p,
438
+ i,
302
439
  c,
303
440
  l
304
- ), p = s === -1 || n <= s, d = ve(
305
- t,
306
- E,
441
+ ), D = i === -1 || n <= i, S = Xe(
442
+ e,
443
+ g,
307
444
  r,
308
- S,
309
- c,
310
445
  p,
446
+ c,
447
+ D,
311
448
  a,
312
449
  l
313
450
  );
314
- return o.boundary ? O(t, d, o.boundary) : d;
451
+ return h.boundary ? Z(e, S, h.boundary) : S;
315
452
  }
316
- function Ne(e, t, n, r, i, s = $) {
453
+ function Pe(t, e, n, r, s, i = N) {
317
454
  const a = n + 1;
318
- if (a < e.length) {
319
- const c = s(e, a, r), o = ge(
320
- t,
455
+ if (a < t.length) {
456
+ const c = i(t, a, r), h = me(
457
+ e,
321
458
  c,
322
459
  r
323
460
  );
324
- return o < t.length && t[o] !== r ? o + 1 : o;
461
+ return h < e.length && e[h] !== r ? h + 1 : h;
325
462
  }
326
463
  return n;
327
464
  }
328
- function $e(e, t, n, r, i, s, a, c = $) {
465
+ function ze(t, e, n, r, s, i, a, c = N) {
329
466
  if (a) {
330
- const { start: l, isDelete: h } = a;
331
- return h ? c(e, l, n) : Math.max(0, c(e, l, n));
467
+ const { start: l, isDelete: u } = a;
468
+ return u ? c(t, l, n) : Math.max(0, c(t, l, n));
332
469
  }
333
- return t > 0 && e[t - 1] === n && i > 0 ? r + 1 : r;
470
+ return e > 0 && t[e - 1] === n && s > 0 ? r + 1 : r;
334
471
  }
335
- function H(e, t, n, r, i, s, a = $) {
336
- if (t > 0 && t < e.length && a(e, t, r) === n) {
337
- if (e[t] === r && s && i > 0 && t < e.length - 1)
338
- return t + 1;
339
- if (!s && i > 0 && t < e.length - 1)
340
- return Math.min(t + 1, e.length);
472
+ function z(t, e, n, r, s, i, a = N) {
473
+ if (e > 0 && e < t.length && a(t, e, r) === n) {
474
+ if (t[e] === r && i && s > 0 && e < t.length - 1)
475
+ return e + 1;
476
+ if (!i && s > 0 && e < t.length - 1)
477
+ return Math.min(e + 1, t.length);
341
478
  }
342
- return t;
479
+ return e;
343
480
  }
344
- function ve(e, t, n, r, i, s, a, c = $) {
345
- if (s && a !== -1) {
346
- const l = e.substring(0, a), h = c(l, l.length, n);
347
- if (t <= h) {
348
- const g = R(
481
+ function Xe(t, e, n, r, s, i, a, c = N) {
482
+ if (i && a !== -1) {
483
+ const l = t.substring(0, a), u = c(l, l.length, n);
484
+ if (e <= u) {
485
+ const f = B(
349
486
  l,
350
- t,
487
+ e,
351
488
  n
352
489
  );
353
- return H(l, g, t, n, r, i, c);
490
+ return z(l, f, e, n, r, s, c);
354
491
  }
355
492
  }
356
- const o = R(
357
- e,
493
+ const h = B(
358
494
  t,
495
+ e,
359
496
  n
360
497
  );
361
- return H(e, o, t, n, r, i, c);
498
+ return z(t, h, e, n, r, s, c);
362
499
  }
363
- function De(e, t, n, r, i, s = $) {
364
- const a = n >= e.length, c = s(e, n, r), o = s(e, e.length, r), l = s(t, t.length, r);
365
- if (a || c === o)
366
- return t.length;
367
- const h = l - o;
368
- let g = c;
369
- h > 0 && !a && c < o && (g = c + 1);
370
- const u = R(
371
- t,
372
- g,
500
+ function Je(t, e, n, r, s, i = N) {
501
+ const a = n >= t.length, c = i(t, n, r), h = i(t, t.length, r), l = i(e, e.length, r);
502
+ if (a || c === h)
503
+ return e.length;
504
+ const u = l - h;
505
+ let f = c;
506
+ u > 0 && !a && c < h && (f = c + 1);
507
+ const o = B(
508
+ e,
509
+ f,
373
510
  r
374
511
  );
375
- return i && !V(t, u, r) ? Math.max(0, u - 1) : u;
512
+ return s && !O(e, o, r) ? Math.max(0, o - 1) : o;
376
513
  }
377
- function Ce(e, t, n) {
378
- const { selectionStart: r, selectionEnd: i, endOffset: s = 0 } = e;
379
- if (r !== i) {
380
- const h = i - r;
514
+ function qe(t, e, n) {
515
+ const { selectionStart: r, selectionEnd: s, endOffset: i = 0 } = t;
516
+ if (r !== s) {
517
+ const u = s - r;
381
518
  return {
382
519
  start: r,
383
- end: i,
384
- deletedLength: h,
520
+ end: s,
521
+ deletedLength: u,
385
522
  isDelete: !1
386
523
  };
387
524
  }
388
- if (s > 0) {
389
- const h = s;
525
+ if (i > 0) {
526
+ const u = i;
390
527
  return {
391
528
  start: r,
392
- end: r + h,
393
- deletedLength: h,
529
+ end: r + u,
530
+ deletedLength: u,
394
531
  isDelete: !0
395
532
  };
396
533
  }
397
- const c = t.length, o = n.length, l = c - o;
534
+ const c = e.length, h = n.length, l = c - h;
398
535
  if (!(l <= 0))
399
536
  return {
400
537
  start: r,
@@ -403,673 +540,528 @@ function Ce(e, t, n) {
403
540
  isDelete: !1
404
541
  };
405
542
  }
406
- function we(e, t) {
407
- if (e === t)
543
+ function Ke(t, e) {
544
+ if (t === e)
408
545
  return;
409
546
  let n = 0;
410
- for (; n < e.length && n < t.length && e[n] === t[n]; )
547
+ for (; n < t.length && n < e.length && t[n] === e[n]; )
411
548
  n++;
412
- let r = e.length - 1, i = t.length - 1;
413
- for (; r >= n && i >= n && e[r] === t[i]; )
414
- r--, i--;
415
- const s = r - n + 1, a = i - n + 1;
416
- if (!(s === 0 && a === 0))
549
+ let r = t.length - 1, s = e.length - 1;
550
+ for (; r >= n && s >= n && t[r] === e[s]; )
551
+ r--, s--;
552
+ const i = r - n + 1, a = s - n + 1;
553
+ if (!(i === 0 && a === 0))
417
554
  return {
418
555
  start: n,
419
556
  end: r + 1,
420
- deletedLength: s,
421
- isDelete: s > a
557
+ deletedLength: i,
558
+ isDelete: i > a
422
559
  };
423
560
  }
424
- function K(e, t) {
425
- if (e.value = e.value, e === null)
426
- return !1;
427
- if (e.createTextRange) {
428
- const n = e.createTextRange();
429
- return n.move("character", t), n.select(), !0;
430
- }
431
- return e.selectionStart !== null || e.selectionStart === 0 ? (e.focus(), e.setSelectionRange(t, t), !0) : (e.focus(), !1);
432
- }
433
- function ye(e, t, n) {
434
- return e.selectionStart === 0 && e.selectionEnd === e.value.length ? null : (K(e, t), setTimeout(() => {
435
- e.value === n && e.selectionStart !== t && K(e, t);
436
- }, 0));
437
- }
438
- function Ie(e) {
439
- return Math.max(e.selectionStart, e.selectionEnd);
561
+ function Ye(t, e, n, r) {
562
+ const s = b(t, r);
563
+ return s === t ? null : {
564
+ raw: s,
565
+ rawStart: b(t.slice(0, e), r).length,
566
+ rawEnd: b(t.slice(0, n), r).length
567
+ };
440
568
  }
441
- function Me(e, t, n) {
442
- if ((n == null ? void 0 : n.formatOn) !== b.Change || !n.thousandSeparator)
569
+ function Qe(t, e, n) {
570
+ if ((n == null ? void 0 : n.formatOn) !== I.Change || !n.thousandSeparator)
443
571
  return;
444
- const { selectionStart: r, selectionEnd: i, value: s } = t;
445
- if (r === null || i === null || r !== i)
572
+ const { selectionStart: r, selectionEnd: s, value: i } = e;
573
+ if (r === null || s === null || r !== s)
446
574
  return;
447
- const { key: a } = e, c = n.thousandSeparator;
448
- a === "Backspace" && r > 0 && s[r - 1] === c && t.setSelectionRange(r - 1, r - 1), a === "Delete" && s[r] === c && t.setSelectionRange(r + 1, r + 1);
575
+ const { key: a } = t, c = n.thousandSeparator;
576
+ a === "Backspace" && r > 0 && i[r - 1] === c && e.setSelectionRange(r - 1, r - 1), a === "Delete" && i[r] === c && e.setSelectionRange(r + 1, r + 1);
449
577
  }
450
- function F(e, t, n, r, i, s, a) {
451
- if (!i) return;
452
- const { selectionStart: c = 0, selectionEnd: o = 0, endOffset: l = 0 } = i;
453
- let h = Ce(
454
- { selectionStart: c, selectionEnd: o, endOffset: l },
578
+ function V(t, e, n, r, s, i) {
579
+ if (!r) return null;
580
+ const { selectionStart: a = 0, selectionEnd: c = 0, endOffset: h = 0 } = r;
581
+ let l = qe(
582
+ { selectionStart: a, selectionEnd: c, endOffset: h },
455
583
  t,
456
- n
584
+ e
457
585
  );
458
- if (h || (h = we(t, n)), !h) return;
459
- const g = Ee(n, {
460
- thousandSeparator: (a == null ? void 0 : a.thousandSeparator) ?? s.thousandSeparator,
586
+ if (l || (l = Ke(t, e)), !l) return null;
587
+ const u = Ze(e, {
588
+ thousandSeparator: (i == null ? void 0 : i.thousandSeparator) ?? s.thousandSeparator,
461
589
  decimalSeparator: s.decimalSeparator
462
- }), u = {
463
- thousandSeparator: (a == null ? void 0 : a.thousandSeparator) ?? s.thousandSeparator,
590
+ }), f = {
591
+ thousandSeparator: (i == null ? void 0 : i.thousandSeparator) ?? s.thousandSeparator,
464
592
  decimalSeparator: s.decimalSeparator,
465
- isCharacterEquivalent: (d, f) => {
466
- const N = (a == null ? void 0 : a.thousandSeparator) ?? s.thousandSeparator;
467
- return N && d === N ? !1 : d === f;
593
+ isCharacterEquivalent: (g, D) => {
594
+ const S = (i == null ? void 0 : i.thousandSeparator) ?? s.thousandSeparator;
595
+ return S && g === S ? !1 : g === D;
468
596
  },
469
- boundary: g
470
- }, S = (a == null ? void 0 : a.thousandSeparator) ?? s.thousandSeparator ?? ",", E = (a == null ? void 0 : a.ThousandStyle) ?? L.None, p = me(
597
+ boundary: u
598
+ }, o = (i == null ? void 0 : i.thousandSeparator) ?? s.thousandSeparator ?? ",", p = (i == null ? void 0 : i.thousandStyle) ?? y.None;
599
+ return Ue(
471
600
  t,
601
+ e,
472
602
  n,
473
- r,
474
- S,
475
- E,
476
- h,
603
+ o,
604
+ p,
605
+ l,
477
606
  s.decimalSeparator,
478
- u
607
+ f
479
608
  );
480
- ye(e, p, n);
481
- }
482
- const Te = (e, t = !1, n = ".") => {
483
- const r = y(n), i = _(`[^0-9${r}]`, "g");
484
- if (!t)
485
- return e.replace(i, "");
486
- const s = e.startsWith("-"), a = e.replace(i, "");
487
- return s && (a.length > 0 || e === "-") ? "-" + a : a;
488
- }, Ae = /([+-]?\d+\.?\d*)[eE]([+-]?\d+)/g, ee = /^0+$/, T = /\.?0+$/;
489
- function Re(e) {
490
- return !e.includes("e") && !e.includes("E") ? e : e.replace(Ae, (t, n, r) => {
491
- const i = parseInt(r, 10);
492
- if (i === 0) return n;
493
- const s = n.startsWith("-"), a = s ? n.slice(1) : n, [c, o = ""] = a.split("."), l = i > 0 ? _e(c, o, i) : xe(c, o, Math.abs(i));
494
- return s ? "-" + l : l;
495
- });
496
- }
497
- function _e(e, t, n) {
498
- const r = e + t;
499
- if (r === "0" || ee.test(r))
500
- return "0";
501
- const i = t.length;
502
- if (n <= i) {
503
- const a = r.slice(0, e.length + n), c = r.slice(e.length + n);
504
- return c ? `${a}.${c}` : a;
505
- }
506
- const s = n - i;
507
- return r + "0".repeat(s);
508
609
  }
509
- function xe(e, t, n) {
510
- const r = e + t;
511
- if (r === "0" || ee.test(r))
512
- return "0";
513
- const s = e.length - n;
514
- if (s <= 0) {
515
- const a = Math.abs(s), c = `0.${"0".repeat(a)}${r}`;
516
- return A(c);
517
- }
518
- if (s < e.length) {
519
- const a = r.slice(0, s), c = r.slice(s), o = `${a}.${c}`;
520
- return A(o);
521
- }
522
- return A(r);
610
+ function F(t, e, n, r) {
611
+ setTimeout(() => {
612
+ t.value === e && (t.selectionStart !== n || t.selectionEnd !== r) && t.setSelectionRange(n, r);
613
+ }, 0);
523
614
  }
524
- function A(e) {
525
- if (!e.includes("."))
526
- return e;
527
- if (e === "0.")
528
- return "0";
529
- if (e.startsWith("0.")) {
530
- const t = e.replace(T, "");
531
- return t === "0" ? "0" : t || "0";
532
- }
533
- if (e.startsWith("-0.")) {
534
- const t = e.replace(T, "");
535
- return t === "-0" || t === "0" ? "0" : t || "0";
536
- }
537
- return e.replace(T, "") || e;
615
+ function T(t, e, n) {
616
+ const r = t.value;
617
+ r === e && t.selectionStart === n && t.selectionEnd === n || (t.setRangeText(e, 0, r.length, "end"), t.setSelectionRange(n, n), F(t, e, n, n));
538
618
  }
539
- const Oe = /(\d+\.?\d*)\s*([kmbt])/gi, Be = /^0+/, Ge = /^(-?)0+([1-9])/, ke = /^-?0+$/, Ze = /\.?0+$/, We = {
540
- k: 3,
541
- // Thousand
542
- m: 6,
543
- // Million
544
- b: 9,
545
- // Billion
546
- t: 12
547
- // Trillion
548
- };
549
- function Ue(e) {
550
- return e.replace(Oe, (t, n, r) => {
551
- const i = r.toLowerCase(), s = We[i];
552
- if (!s)
553
- return t;
554
- const [a, c = ""] = n.split("."), o = a.replace(Be, "") || "0";
555
- let l;
556
- if (c.length === 0)
557
- l = o + "0".repeat(s);
558
- else if (c.length <= s) {
559
- const h = s - c.length;
560
- l = o + c + "0".repeat(h);
561
- } else {
562
- const h = c.slice(0, s), g = c.slice(s);
563
- l = o + h + "." + g;
564
- }
565
- return l = l.replace(Ge, "$1$2"), ke.test(l) && (l = "0"), l.includes(".") && (l = l.replace(Ze, "")), l;
566
- });
619
+ function Oe(t, e, n, r) {
620
+ t.value === e && t.selectionStart === n && t.selectionEnd === r || (t.setRangeText(e, 0, t.value.length, "preserve"), t.setSelectionRange(n, r), F(t, e, n, r));
567
621
  }
568
- function ze(e) {
569
- if (!e || e === "0" || e === "-0" || e === "-" || e === ".")
570
- return e;
571
- const t = e.startsWith("-"), n = t ? e.slice(1) : e;
572
- if (n === ".")
573
- return e;
574
- if (n.includes(".")) {
575
- const [i, s] = n.split(".");
576
- if (i) {
577
- const c = (i.replace(/^0+/, "") || "0") + "." + s;
578
- return t ? "-" + c : c;
579
- }
580
- return e;
581
- }
582
- if (n.startsWith("0")) {
583
- const i = n.replace(/^0+/, "") || "0";
584
- return t ? "-" + i : i;
585
- }
586
- return e;
587
- }
588
- function Je(e) {
589
- return e.replace(/[\s\u200B]/g, "");
590
- }
591
- function v(e, t) {
592
- const n = ae(t);
593
- return e.replace(n, "");
594
- }
595
- const Pe = (e, t) => {
596
- let n = Je(e);
597
- return t != null && t.thousandSeparator && (n = v(n, t.thousandSeparator)), t != null && t.enableCompactNotation && (n = Ue(n)), n = Re(n), n = Te(
598
- n,
599
- t == null ? void 0 : t.enableNegative,
600
- t == null ? void 0 : t.decimalSeparator
601
- ), n = oe(n, t == null ? void 0 : t.decimalSeparator), t != null && t.enableLeadingZeros || (n = ze(n)), n;
602
- };
603
- function Xe(e, t, n) {
604
- return {
605
- enableCompactNotation: e == null ? void 0 : e.enableCompactNotation,
606
- enableNegative: e == null ? void 0 : e.enableNegative,
607
- enableLeadingZeros: e == null ? void 0 : e.enableLeadingZeros,
608
- decimalSeparator: t.decimalSeparator,
609
- thousandSeparator: n ? t.thousandSeparator : void 0
610
- };
611
- }
612
- function M(e, t, n, r) {
613
- const i = x(n), s = r ?? (n == null ? void 0 : n.formatOn) === b.Change, a = Pe(
614
- e,
615
- Xe(n, i, s)
616
- ), c = le(
617
- a,
618
- t,
619
- i.decimalSeparator
620
- ), o = (n == null ? void 0 : n.decimalMinLength) ?? 0, l = he(
622
+ function x(t, e, n, r) {
623
+ const s = G(n), a = r ?? (n == null ? void 0 : n.formatOn) === I.Change ? n : { ...n, thousandSeparator: void 0 }, c = _e(t, a), h = fe(
621
624
  c,
622
- o,
623
- i.decimalSeparator
625
+ e,
626
+ s.decimalSeparator
627
+ ), l = (n == null ? void 0 : n.decimalMinLength) ?? 0, u = ge(
628
+ h,
629
+ l,
630
+ s.decimalSeparator
624
631
  );
625
- return { formatted: fe(l, n, i), raw: l };
632
+ return { formatted: (n == null ? void 0 : n.formatOn) === I.Change && !!n.thousandSeparator ? Q(
633
+ u,
634
+ n.thousandSeparator,
635
+ n.thousandStyle ?? y.None,
636
+ n.enableLeadingZeros,
637
+ s.decimalSeparator
638
+ ) : u, raw: u };
626
639
  }
627
- function ft(e, t, n) {
640
+ function ht(t, e, n) {
628
641
  const r = !!(n != null && n.thousandSeparator);
629
- return M(
630
- e,
642
+ return x(
631
643
  t,
644
+ e,
632
645
  n,
633
646
  r
634
647
  );
635
648
  }
636
- function je(e, t, n) {
637
- if (e.inputType === "insertFromPaste" || e.inputType === "insertFromDrop")
638
- return null;
639
- const r = e.target, i = r.value, s = r.selectionStart ?? 0, a = r.selectionEnd ?? 0, c = x(n);
640
- let o = e.data ?? "";
641
- if (e.inputType === "insertText" && (e.data === "," || e.data === ".")) {
649
+ function Ve(t, e, n) {
650
+ if (t.inputType === L.InsertFromPaste || t.inputType === L.InsertFromDrop)
651
+ return { type: "skip" };
652
+ const r = t.target, s = r.value, i = r.selectionStart ?? 0, a = r.selectionEnd ?? 0, c = G(n);
653
+ let h = t.data ?? "";
654
+ if (t.inputType === L.InsertText && (t.data === "," || t.data === ".")) {
642
655
  const d = c.decimalSeparator;
643
- if ((i.slice(0, s) + i.slice(a)).includes(d))
644
- return e.preventDefault(), null;
645
- o = d;
656
+ if ((s.slice(0, i) + s.slice(a)).includes(d))
657
+ return { type: "reject" };
658
+ h = d;
646
659
  }
647
- let l, h;
648
- switch (e.inputType) {
649
- case "insertText": {
650
- l = i.slice(0, s) + o + i.slice(a), h = s + o.length;
660
+ if (t.inputType === L.InsertText && /^\d$/.test(h)) {
661
+ const d = c.decimalSeparator, E = s.indexOf(d);
662
+ if (E !== -1 && i > E) {
663
+ const w = s.length - E - 1, W = a - i;
664
+ if (w - W + 1 > e)
665
+ return { type: "reject" };
666
+ }
667
+ }
668
+ let l, u, f = 0;
669
+ const o = i !== a;
670
+ switch (t.inputType) {
671
+ case L.InsertText: {
672
+ l = s.slice(0, i) + h + s.slice(a), u = i + h.length;
651
673
  break;
652
674
  }
653
- case "deleteContentBackward": {
654
- if (s !== a)
655
- l = i.slice(0, s) + i.slice(a), h = s;
656
- else {
657
- const d = Math.max(0, s - 1);
658
- l = i.slice(0, d) + i.slice(s), h = d;
659
- }
675
+ case L.DeleteContentBackward: {
676
+ const d = o ? i : Math.max(0, i - 1), E = o ? a : i;
677
+ l = s.slice(0, d) + s.slice(E), u = d;
678
+ break;
679
+ }
680
+ case L.DeleteContentForward: {
681
+ const d = o ? a : i + 1;
682
+ l = s.slice(0, i) + s.slice(d), u = i, o || (f = 1);
683
+ break;
684
+ }
685
+ case L.DeleteByCut:
686
+ case L.DeleteByDrag: {
687
+ l = s.slice(0, i) + s.slice(a), u = i;
660
688
  break;
661
689
  }
662
- case "deleteContentForward": {
663
- s !== a ? (l = i.slice(0, s) + i.slice(a), h = s) : (l = i.slice(0, s) + i.slice(s + 1), h = s);
690
+ case L.DeleteSoftLineBackward:
691
+ case L.DeleteHardLineBackward: {
692
+ const d = o ? i : 0;
693
+ l = s.slice(0, d) + s.slice(a), u = d;
664
694
  break;
665
695
  }
666
- case "deleteByCut":
667
- case "deleteByDrag": {
668
- l = i.slice(0, s) + i.slice(a), h = s;
696
+ case L.DeleteSoftLineForward:
697
+ case L.DeleteHardLineForward: {
698
+ const d = o ? a : s.length;
699
+ l = s.slice(0, i) + s.slice(d), u = i, o || (f = s.length - i);
669
700
  break;
670
701
  }
671
702
  default:
672
- return null;
703
+ return { type: "skip" };
704
+ }
705
+ if ((n == null ? void 0 : n.maxLength) !== void 0 && t.inputType === L.InsertText) {
706
+ const d = n.thousandSeparator;
707
+ if ((d ? b(l, d).length : l.length) > n.maxLength)
708
+ return { type: "reject" };
673
709
  }
674
- e.preventDefault();
675
- const g = (n == null ? void 0 : n.formatOn) === b.Change, { formatted: u, raw: S } = M(
710
+ const p = (n == null ? void 0 : n.formatOn) === I.Change, { formatted: g, raw: D } = x(
676
711
  l,
677
- t,
712
+ e,
678
713
  n,
679
- g
714
+ p
680
715
  );
681
- r.setRangeText(u, 0, i.length, "end");
682
- const E = e.inputType === "deleteContentForward" ? 1 : 0;
683
- return l !== u ? F(
684
- r,
716
+ if (n != null && n.isAllowed && !n.isAllowed(D))
717
+ return { type: "reject" };
718
+ let S;
719
+ return l !== g ? S = V(
685
720
  l,
721
+ g,
686
722
  u,
687
- h,
688
723
  {
689
- selectionStart: s,
724
+ selectionStart: i,
690
725
  selectionEnd: a,
691
- endOffset: E
726
+ endOffset: f
692
727
  },
693
728
  c,
694
729
  n
695
- ) : r.setSelectionRange(h, h), { formatted: u, raw: S };
696
- }
697
- function qe(e, t, n) {
698
- if (e === "Backspace" || e === "Delete")
699
- return e === "Delete" && t === n ? {
700
- endOffset: 1
701
- } : {
702
- endOffset: 0
703
- };
730
+ ) ?? u : S = u, { type: "handled", formatted: g, raw: D, cursorPos: S };
704
731
  }
705
- function He(e, t) {
706
- const n = e.target;
707
- return Me(e, n, t), qe(e.key, n.selectionStart, n.selectionEnd);
708
- }
709
- function Ke(e, t, n, r) {
710
- const i = e.target, s = i.value, a = Ie(i), c = x(r), o = (r == null ? void 0 : r.formatOn) === b.Change, { formatted: l, raw: h } = M(
711
- s,
712
- t,
713
- r,
714
- o
715
- );
716
- return i.value = l, s !== l && F(
717
- i,
718
- s,
719
- l,
720
- a,
721
- n,
722
- c,
723
- r
724
- ), { formatted: l, raw: h };
732
+ function Fe(t, e) {
733
+ const n = t.target;
734
+ if (Qe(t, n, e), t.key !== "Backspace" && t.key !== "Delete") return;
735
+ const r = n.selectionStart ?? 0, s = n.selectionEnd ?? 0;
736
+ return {
737
+ selectionStart: r,
738
+ selectionEnd: s,
739
+ endOffset: t.key === "Delete" && r === s ? 1 : 0
740
+ };
725
741
  }
726
- function Ye(e, t, n, r) {
727
- const i = r - n;
728
- return e + t + i;
742
+ function et(t, e, n, r) {
743
+ const s = r - n;
744
+ return t + e + s;
729
745
  }
730
- function Qe(e, t, n) {
731
- var u;
732
- e.preventDefault();
733
- const r = e.target, { value: i, selectionStart: s, selectionEnd: a } = r, c = ((u = e.clipboardData) == null ? void 0 : u.getData("text/plain")) || "", o = i.slice(0, s || 0) + c + i.slice(a || 0), { formatted: l, raw: h } = M(
734
- o,
735
- t,
746
+ function tt(t, e, n) {
747
+ var o;
748
+ const r = t.target, { value: s, selectionStart: i, selectionEnd: a } = r, c = ((o = t.clipboardData) == null ? void 0 : o.getData("text/plain")) || "", h = s.slice(0, i || 0) + c + s.slice(a || 0), { formatted: l, raw: u } = x(
749
+ h,
750
+ e,
736
751
  n,
737
752
  !0
738
753
  );
739
- r.value = l;
740
- const g = Ye(
741
- s || 0,
754
+ if (n != null && n.isAllowed && !n.isAllowed(u))
755
+ return { type: "reject" };
756
+ const f = et(
757
+ i || 0,
742
758
  c.length,
743
- o.length,
759
+ h.length,
744
760
  l.length
745
761
  );
746
- return r.setSelectionRange(g, g), { formatted: l, raw: h };
762
+ return { type: "handled", formatted: l, raw: u, cursorPos: f };
747
763
  }
748
- function Ve(e, t) {
749
- const n = y(e);
750
- return t ? `^-?[0-9]*[${n}]?[0-9]*$` : `^[0-9]*[${n}]?[0-9]*$`;
751
- }
752
- function Fe(e) {
753
- var t, n;
764
+ function nt(t) {
765
+ var e, n;
754
766
  try {
755
- const i = new Intl.NumberFormat(e).formatToParts(123456789e-2);
767
+ const s = new Intl.NumberFormat(t).formatToParts(123456789e-2);
756
768
  return {
757
- decimalSeparator: ((t = i.find((s) => s.type === "decimal")) == null ? void 0 : t.value) ?? ".",
758
- thousandSeparator: ((n = i.find((s) => s.type === "group")) == null ? void 0 : n.value) ?? ","
769
+ decimalSeparator: ((e = s.find((i) => i.type === "decimal")) == null ? void 0 : e.value) ?? ".",
770
+ thousandSeparator: ((n = s.find((i) => i.type === "group")) == null ? void 0 : n.value) ?? ","
759
771
  };
760
772
  } catch {
761
773
  return { thousandSeparator: ",", decimalSeparator: "." };
762
774
  }
763
775
  }
764
- function et(e, t) {
765
- if (!e) return t;
766
- const r = Fe(e === !0 ? void 0 : e);
776
+ function rt(t, e) {
777
+ if (!t) return e;
778
+ const r = nt(t === !0 ? void 0 : t);
767
779
  return {
768
- thousandSeparator: t.thousandSeparator ?? r.thousandSeparator,
769
- decimalSeparator: t.decimalSeparator ?? r.decimalSeparator
780
+ thousandSeparator: e.thousandSeparator ?? r.thousandSeparator,
781
+ decimalSeparator: e.decimalSeparator ?? r.decimalSeparator
770
782
  };
771
783
  }
772
- function tt(e) {
773
- nt(e.decimalMaxLength), rt(e.decimalMinLength), it(e.decimalMinLength, e.decimalMaxLength), st(e.formatOn), at(e.thousandSeparator), ct(e.thousandStyle), lt(e.decimalSeparator), ot(e.thousandSeparator, e.decimalSeparator), I("enableCompactNotation", e.enableCompactNotation), I("enableNegative", e.enableNegative), I("enableLeadingZeros", e.enableLeadingZeros), I("rawValueMode", e.rawValueMode), ht(e.onChange);
784
+ function st(t) {
785
+ k("decimalMaxLength", t.decimalMaxLength), k("decimalMinLength", t.decimalMinLength), it(t.decimalMinLength, t.decimalMaxLength), q("formatOn", t.formatOn, [I.Blur, I.Change]), X("thousandSeparator", t.thousandSeparator), q("thousandStyle", t.thousandStyle, Object.values(y)), X("decimalSeparator", t.decimalSeparator), at(t.thousandSeparator, t.decimalSeparator), v("enableCompactNotation", t.enableCompactNotation), v("enableNegative", t.enableNegative), v("enableLeadingZeros", t.enableLeadingZeros), v("autoAddLeadingZero", t.autoAddLeadingZero), v("rawValueMode", t.rawValueMode), k("maxLength", t.maxLength), J("isAllowed", t.isAllowed), J("onChange", t.onChange);
774
786
  }
775
- function nt(e) {
776
- if (e !== void 0) {
777
- if (typeof e != "number")
778
- throw new Error(
779
- `decimalMaxLength must be a number. Received: ${typeof e} (${JSON.stringify(e)})`
780
- );
781
- if (!Number.isInteger(e))
782
- throw new Error(
783
- `decimalMaxLength must be an integer. Received: ${e}`
784
- );
785
- if (e < 0)
786
- throw new Error(
787
- `decimalMaxLength must be non-negative. Received: ${e}`
788
- );
789
- }
787
+ function k(t, e) {
788
+ if (e !== void 0 && (typeof e != "number" || !Number.isInteger(e) || e < 0))
789
+ throw new Error(`${t} must be a non-negative integer. Received: ${JSON.stringify(e)}`);
790
790
  }
791
- function rt(e) {
792
- if (e !== void 0) {
793
- if (typeof e != "number")
794
- throw new Error(
795
- `decimalMinLength must be a number. Received: ${typeof e} (${JSON.stringify(e)})`
796
- );
797
- if (!Number.isInteger(e))
798
- throw new Error(
799
- `decimalMinLength must be an integer. Received: ${e}`
800
- );
801
- if (e < 0)
802
- throw new Error(
803
- `decimalMinLength must be non-negative. Received: ${e}`
804
- );
805
- }
791
+ function X(t, e) {
792
+ if (e !== void 0 && (typeof e != "string" || e.length !== 1))
793
+ throw new Error(`${t} must be a single character. Received: ${JSON.stringify(e)}`);
806
794
  }
807
- function it(e, t) {
808
- if (!(e === void 0 || t === void 0) && e > t)
809
- throw new Error(
810
- `decimalMinLength (${e}) cannot be greater than decimalMaxLength (${t}).`
811
- );
795
+ function v(t, e) {
796
+ if (e !== void 0 && typeof e != "boolean")
797
+ throw new Error(`${t} must be a boolean. Received: ${JSON.stringify(e)}`);
812
798
  }
813
- function st(e) {
814
- if (e !== void 0 && e !== b.Blur && e !== b.Change)
815
- throw new Error(
816
- `formatOn must be either ${b.Blur} or ${b.Change}. Received: ${JSON.stringify(e)}`
817
- );
818
- }
819
- function at(e) {
820
- if (e !== void 0) {
821
- if (typeof e != "string")
822
- throw new Error(
823
- `thousandSeparator must be a string. Received: ${typeof e} (${JSON.stringify(e)})`
824
- );
825
- if (e.length === 0)
826
- throw new Error(
827
- `thousandSeparator cannot be empty. Received: ${JSON.stringify(e)}`
828
- );
829
- if (e.length > 1)
830
- throw new Error(
831
- `thousandSeparator must be a single character. Received: "${e}" (length: ${e.length})`
832
- );
833
- }
834
- }
835
- function ct(e) {
836
- if (e !== void 0 && !Object.values(L).includes(e))
837
- throw new Error(
838
- `ThousandStyle must be one of: ${Object.values(L).map((t) => `'${t}'`).join(", ")}. Received: ${JSON.stringify(e)}`
839
- );
840
- }
841
- function lt(e) {
842
- if (e !== void 0) {
843
- if (typeof e != "string")
844
- throw new Error(
845
- `decimalSeparator must be a string. Received: ${typeof e} (${JSON.stringify(e)})`
846
- );
847
- if (e.length === 0)
848
- throw new Error(
849
- `decimalSeparator cannot be empty. Received: ${JSON.stringify(e)}`
850
- );
851
- if (e.length > 1)
852
- throw new Error(
853
- `decimalSeparator must be a single character. Received: "${e}" (length: ${e.length})`
854
- );
855
- }
799
+ function J(t, e) {
800
+ if (e !== void 0 && typeof e != "function")
801
+ throw new Error(`${t} must be a function. Received: ${JSON.stringify(e)}`);
856
802
  }
857
- function ot(e, t) {
858
- if (!(e === void 0 || t === void 0) && e === t)
803
+ function q(t, e, n) {
804
+ if (e !== void 0 && !n.includes(e))
859
805
  throw new Error(
860
- `Decimal separator can't be same as thousand separator. thousandSeparator: ${e}, decimalSeparator: ${t}`
806
+ `${t} must be one of: ${n.map((r) => `'${r}'`).join(", ")}. Received: ${JSON.stringify(e)}`
861
807
  );
862
808
  }
863
- function I(e, t) {
864
- if (t !== void 0 && typeof t != "boolean")
809
+ function it(t, e) {
810
+ if (!(t === void 0 || e === void 0) && t > e)
865
811
  throw new Error(
866
- `${e} must be a boolean. Received: ${typeof t} (${JSON.stringify(t)})`
812
+ `decimalMinLength (${t}) cannot be greater than decimalMaxLength (${e}).`
867
813
  );
868
814
  }
869
- function ht(e) {
870
- if (e !== void 0 && typeof e != "function")
815
+ function at(t, e) {
816
+ if (!(t === void 0 || e === void 0) && t === e)
871
817
  throw new Error(
872
- `onChange must be a function or undefined. Received: ${typeof e} (${JSON.stringify(e)})`
818
+ `decimalSeparator cannot equal thousandSeparator. Both were ${JSON.stringify(t)}.`
873
819
  );
874
820
  }
875
- class gt {
876
- constructor(t, {
877
- decimalMaxLength: n = B,
878
- decimalMinLength: r = G,
879
- formatOn: i = k,
880
- thousandSeparator: s,
881
- thousandStyle: a = Z,
882
- decimalSeparator: c,
883
- locale: o,
884
- enableCompactNotation: l = W,
885
- enableNegative: h = U,
886
- enableLeadingZeros: g = z,
887
- rawValueMode: u = J,
888
- onChange: S,
889
- ...E
890
- }) {
891
- w(this, "element");
892
- w(this, "resolvedOptions");
893
- w(this, "rawValue", "");
894
- w(this, "caretPositionBeforeChange");
895
- tt({
896
- decimalMaxLength: n,
897
- decimalMinLength: r,
898
- formatOn: i,
899
- thousandSeparator: s,
900
- thousandStyle: a,
901
- decimalSeparator: c,
902
- enableCompactNotation: l,
903
- enableNegative: h,
904
- enableLeadingZeros: g,
905
- rawValueMode: u,
906
- onChange: S
907
- });
908
- const p = {
909
- decimalMaxLength: n,
910
- decimalMinLength: r,
911
- onChange: S,
912
- formatOn: i,
913
- thousandSeparator: s,
914
- thousandStyle: a,
915
- decimalSeparator: c,
916
- locale: o,
917
- enableCompactNotation: l,
918
- enableNegative: h,
919
- enableLeadingZeros: g,
920
- rawValueMode: u,
921
- ...E
922
- };
923
- if (this.resolvedOptions = this.getResolvedOptions(p), this.createInputElement(t, p), this.setupEventListeners(), this.resolvedOptions.rawValueMode && this.element.value) {
924
- const d = this.element.value, f = this.resolvedOptions.thousandSeparator ? v(d, this.resolvedOptions.thousandSeparator) : d;
925
- this.rawValue = f, this.element.value = this.formatValueForDisplay(f);
926
- } else if (this.element.value) {
927
- const d = this.element.value;
928
- this.element.value = this.formatValueForDisplay(d);
929
- }
930
- }
931
- createInputElement(t, n) {
932
- 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");
933
- const r = Ve(this.resolvedOptions.decimalSeparator, this.resolvedOptions.enableNegative);
934
- this.element.setAttribute("pattern", r);
821
+ const ct = /* @__PURE__ */ new Set([
822
+ "decimalMaxLength",
823
+ "decimalMinLength",
824
+ "formatOn",
825
+ "thousandSeparator",
826
+ "thousandStyle",
827
+ "decimalSeparator",
828
+ "locale",
829
+ "enableCompactNotation",
830
+ "enableNegative",
831
+ "enableLeadingZeros",
832
+ "autoAddLeadingZero",
833
+ "rawValueMode",
834
+ "maxLength",
835
+ "isAllowed",
836
+ "onChange",
837
+ "value",
838
+ "defaultValue",
839
+ // Protected native attrs set explicitly in createInputElement.
840
+ "type",
841
+ "inputMode",
842
+ "spellcheck",
843
+ "autocomplete"
844
+ ]);
845
+ class ut {
846
+ constructor(e, n) {
847
+ A(this, "element");
848
+ A(this, "resolvedOptions");
849
+ A(this, "rawValue", "");
850
+ // True while we're applying our own setRangeText. The synchronous `input` event that
851
+ // setRangeText fires must NOT re-enter handleChange's broadcast path, or onChange
852
+ // double-fires and the cursor is recomputed against the post-write value.
853
+ // try/finally in withInternalWrite guarantees this clears even if the write throws.
854
+ A(this, "suppressNextInputEvent", !1);
855
+ // Mouse-driven focus: the browser commits the click→selection mapping AFTER focus
856
+ // fires, using the input's current value. If we strip separators in the focus handler,
857
+ // the click X-coord then maps to a position N digits too far right (where N = separators
858
+ // before the click point). Set on mousedown, cleared on click after we strip + map -
859
+ // click fires after the browser has finalised the caret, so selectionStart reflects
860
+ // the user's intended position when we read it.
861
+ A(this, "pendingMouseStrip", !1);
862
+ A(this, "caretPositionBeforeChange");
863
+ st(n);
935
864
  const {
936
- decimalMaxLength: i,
865
+ decimalMaxLength: r = ne,
866
+ decimalMinLength: s = re,
867
+ formatOn: i = se,
868
+ thousandSeparator: a,
869
+ thousandStyle: c = ae,
870
+ decimalSeparator: h,
871
+ locale: l,
872
+ enableCompactNotation: u = ce,
873
+ enableNegative: f = le,
874
+ enableLeadingZeros: o = he,
875
+ autoAddLeadingZero: p = ue,
876
+ rawValueMode: g = oe,
877
+ maxLength: D,
878
+ isAllowed: S,
879
+ onChange: d
880
+ } = n, E = rt(l, { thousandSeparator: a, decimalSeparator: h });
881
+ this.resolvedOptions = {
882
+ decimalMaxLength: r,
937
883
  decimalMinLength: s,
938
- formatOn: a,
939
- thousandSeparator: c,
940
- thousandStyle: o,
941
- decimalSeparator: l,
942
- locale: h,
943
- enableCompactNotation: g,
944
- enableNegative: u,
945
- enableLeadingZeros: S,
946
- rawValueMode: E,
947
- onChange: p,
948
- value: d,
949
- defaultValue: f,
950
- type: N,
951
- inputMode: m,
952
- spellcheck: te,
953
- autocomplete: ut,
954
- ...ne
955
- } = n;
956
- Object.assign(this.element, ne), d !== void 0 ? this.element.value = d : f !== void 0 && (this.element.defaultValue = f, this.element.value = f), t.appendChild(this.element);
884
+ formatOn: i,
885
+ thousandSeparator: E.thousandSeparator ?? ie,
886
+ thousandStyle: c,
887
+ decimalSeparator: E.decimalSeparator ?? $,
888
+ enableCompactNotation: u,
889
+ enableNegative: f,
890
+ enableLeadingZeros: o,
891
+ autoAddLeadingZero: p,
892
+ rawValueMode: g,
893
+ maxLength: D,
894
+ isAllowed: S,
895
+ onChange: d
896
+ }, this.createInputElement(e, n), this.setupEventListeners(), this.setDefaultValue();
957
897
  }
958
- setupEventListeners() {
959
- this.element.addEventListener("beforeinput", this.handleBeforeInput.bind(this)), this.element.addEventListener("input", this.handleChange.bind(this)), this.element.addEventListener("keydown", this.handleKeyDown.bind(this)), this.element.addEventListener("paste", this.handlePaste.bind(this)), this.resolvedOptions.formatOn === b.Blur && this.resolvedOptions.thousandSeparator && (this.element.addEventListener("focus", this.handleFocus.bind(this)), this.element.addEventListener("blur", this.handleBlur.bind(this)));
898
+ toRaw(e) {
899
+ const n = this.resolvedOptions.thousandSeparator;
900
+ return n ? b(e, n) : e;
960
901
  }
961
- getResolvedOptions(t) {
962
- const n = et(t.locale, {
963
- thousandSeparator: t.thousandSeparator,
964
- decimalSeparator: t.decimalSeparator
965
- });
966
- return {
967
- decimalMaxLength: t.decimalMaxLength ?? B,
968
- decimalMinLength: t.decimalMinLength ?? G,
969
- formatOn: t.formatOn ?? k,
970
- thousandSeparator: n.thousandSeparator ?? se,
971
- thousandStyle: t.thousandStyle ?? Z,
972
- decimalSeparator: n.decimalSeparator ?? C,
973
- enableCompactNotation: t.enableCompactNotation ?? W,
974
- enableNegative: t.enableNegative ?? U,
975
- enableLeadingZeros: t.enableLeadingZeros ?? z,
976
- rawValueMode: t.rawValueMode ?? J,
977
- onChange: t.onChange
978
- };
902
+ setDefaultValue() {
903
+ if (!this.element.value) return;
904
+ const e = this.toRaw(this.element.value);
905
+ this.resolvedOptions.rawValueMode && (this.rawValue = e), this.element.value = this.applyDisplaySeparators(e);
979
906
  }
980
- buildFormattingOptions() {
981
- return {
982
- formatOn: this.resolvedOptions.formatOn,
983
- thousandSeparator: this.resolvedOptions.thousandSeparator,
984
- ThousandStyle: this.resolvedOptions.thousandStyle,
985
- enableCompactNotation: this.resolvedOptions.enableCompactNotation,
986
- enableNegative: this.resolvedOptions.enableNegative,
987
- enableLeadingZeros: this.resolvedOptions.enableLeadingZeros,
988
- decimalSeparator: this.resolvedOptions.decimalSeparator,
989
- decimalMinLength: this.resolvedOptions.decimalMinLength,
990
- rawValueMode: this.resolvedOptions.rawValueMode
991
- };
907
+ createInputElement(e, n) {
908
+ const r = e instanceof HTMLInputElement;
909
+ this.element = r ? e : document.createElement("input"), this.element.setAttribute("type", "text"), this.element.setAttribute("inputmode", "decimal"), this.element.setAttribute("spellcheck", "false"), this.element.setAttribute("autocomplete", "off");
910
+ const s = M(this.resolvedOptions.decimalSeparator), i = this.resolvedOptions.enableNegative ? "-?" : "";
911
+ this.element.setAttribute("pattern", `^${i}[0-9]*[${s}]?[0-9]*$`);
912
+ const a = Object.fromEntries(
913
+ Object.entries(n).filter(([c]) => !ct.has(c))
914
+ );
915
+ Object.assign(this.element, a), n.value !== void 0 ? this.element.value = n.value : n.defaultValue !== void 0 && (this.element.defaultValue = n.defaultValue, this.element.value = n.defaultValue), r || e.appendChild(this.element);
916
+ }
917
+ setupEventListeners() {
918
+ this.element.addEventListener("beforeinput", this.handleBeforeInput.bind(this)), this.element.addEventListener("input", this.handleChange.bind(this)), this.element.addEventListener("keydown", this.handleKeyDown.bind(this)), this.element.addEventListener("paste", this.handlePaste.bind(this)), this.resolvedOptions.formatOn === I.Blur && this.resolvedOptions.thousandSeparator && (this.element.addEventListener("focus", this.handleFocus.bind(this)), this.element.addEventListener("blur", this.handleBlur.bind(this)), this.element.addEventListener("mousedown", this.handleMouseDown.bind(this)), this.element.addEventListener("click", this.handleClick.bind(this)));
919
+ }
920
+ /**
921
+ * Runs `fn` with `suppressNextInputEvent` set so the synchronous `input` event fired
922
+ * by `setRangeText` is short-circuited in `handleChange`. Exactly one set/clear pair
923
+ * per write; try/finally guarantees the flag clears even if `fn` throws.
924
+ */
925
+ withInternalWrite(e) {
926
+ this.suppressNextInputEvent = !0;
927
+ try {
928
+ e();
929
+ } finally {
930
+ this.suppressNextInputEvent = !1;
931
+ }
992
932
  }
993
- handleValueChange(t, n) {
933
+ handleValueChange(e, n) {
994
934
  if (this.resolvedOptions.rawValueMode && n !== void 0 && (this.rawValue = n), this.resolvedOptions.onChange) {
995
- const r = this.resolvedOptions.rawValueMode ? this.rawValue : t;
935
+ const r = this.resolvedOptions.rawValueMode ? this.rawValue : e;
996
936
  this.resolvedOptions.onChange(r);
997
937
  }
998
938
  }
999
- formatValueForDisplay(t) {
1000
- if (!t)
1001
- return t;
1002
- const { thousandSeparator: n, thousandStyle: r, enableLeadingZeros: i, decimalSeparator: s } = this.resolvedOptions;
1003
- return n && r !== L.None ? Q(
1004
- t,
939
+ applyDisplaySeparators(e) {
940
+ if (!e)
941
+ return e;
942
+ const { thousandSeparator: n, thousandStyle: r, enableLeadingZeros: s, decimalSeparator: i } = this.resolvedOptions;
943
+ return n && r !== y.None ? Q(
944
+ e,
1005
945
  n,
1006
946
  r,
1007
- i,
1008
- s
1009
- ) : t;
947
+ s,
948
+ i
949
+ ) : e;
1010
950
  }
1011
- handleBeforeInput(t) {
1012
- je(
1013
- t,
951
+ handleBeforeInput(e) {
952
+ const n = Ve(
953
+ e,
1014
954
  this.resolvedOptions.decimalMaxLength,
1015
- this.buildFormattingOptions()
955
+ this.resolvedOptions
1016
956
  );
957
+ switch (n.type) {
958
+ case "handled": {
959
+ e.preventDefault(), this.withInternalWrite(
960
+ () => T(this.element, n.formatted, n.cursorPos)
961
+ ), this.handleValueChange(n.formatted, n.raw);
962
+ break;
963
+ }
964
+ case "reject":
965
+ e.preventDefault();
966
+ break;
967
+ }
1017
968
  }
1018
- handleChange(t) {
1019
- const { formatted: n, raw: r } = Ke(
1020
- t,
969
+ handleChange(e) {
970
+ if (this.suppressNextInputEvent) return;
971
+ const n = e.target;
972
+ if (e instanceof InputEvent && (e.inputType === L.HistoryUndo || e.inputType === L.HistoryRedo)) {
973
+ const l = this.toRaw(n.value);
974
+ this.caretPositionBeforeChange = void 0, this.handleValueChange(n.value, l);
975
+ return;
976
+ }
977
+ const r = n.value, s = Math.max(n.selectionStart ?? 0, n.selectionEnd ?? 0), i = G(this.resolvedOptions), a = this.resolvedOptions.formatOn === I.Change, { formatted: c, raw: h } = x(
978
+ r,
1021
979
  this.resolvedOptions.decimalMaxLength,
1022
- this.caretPositionBeforeChange,
1023
- this.buildFormattingOptions()
980
+ this.resolvedOptions,
981
+ a
1024
982
  );
1025
- this.caretPositionBeforeChange = void 0, this.handleValueChange(n, r);
983
+ if (r !== c) {
984
+ const l = V(
985
+ r,
986
+ c,
987
+ s,
988
+ this.caretPositionBeforeChange,
989
+ i,
990
+ this.resolvedOptions
991
+ );
992
+ this.withInternalWrite(
993
+ () => T(n, c, l ?? c.length)
994
+ );
995
+ }
996
+ this.caretPositionBeforeChange = void 0, this.handleValueChange(c, h);
1026
997
  }
1027
- handleKeyDown(t) {
1028
- const n = t.target, { selectionStart: r, selectionEnd: i } = n, s = this.buildFormattingOptions(), a = He(t, {
1029
- formatOn: s.formatOn,
1030
- thousandSeparator: s.thousandSeparator,
1031
- ThousandStyle: s.ThousandStyle,
1032
- decimalSeparator: s.decimalSeparator
1033
- });
1034
- a ? this.caretPositionBeforeChange = {
1035
- selectionStart: r ?? 0,
1036
- selectionEnd: i ?? 0,
1037
- endOffset: a.endOffset
1038
- } : this.caretPositionBeforeChange = {
1039
- selectionStart: r ?? 0,
1040
- selectionEnd: i ?? 0
998
+ handleKeyDown(e) {
999
+ const n = e.target;
1000
+ this.caretPositionBeforeChange = Fe(e, this.resolvedOptions) ?? {
1001
+ selectionStart: n.selectionStart ?? 0,
1002
+ selectionEnd: n.selectionEnd ?? 0
1041
1003
  };
1042
1004
  }
1043
- handlePaste(t) {
1044
- const { formatted: n, raw: r } = Qe(t, this.resolvedOptions.decimalMaxLength, this.buildFormattingOptions());
1045
- this.handleValueChange(n, r);
1046
- const i = new Event("input", { bubbles: !0, cancelable: !0 });
1047
- this.element.dispatchEvent(i);
1005
+ handlePaste(e) {
1006
+ e.preventDefault();
1007
+ const n = tt(e, this.resolvedOptions.decimalMaxLength, this.resolvedOptions);
1008
+ n.type !== "reject" && (this.withInternalWrite(
1009
+ () => T(this.element, n.formatted, n.cursorPos)
1010
+ ), this.handleValueChange(n.formatted, n.raw));
1048
1011
  }
1049
- handleFocus(t) {
1050
- if (this.resolvedOptions.formatOn === b.Blur && this.resolvedOptions.thousandSeparator) {
1051
- const n = t.target;
1052
- n.value = v(n.value, this.resolvedOptions.thousandSeparator);
1053
- }
1012
+ stripSeparatorsAndMapCaret(e) {
1013
+ const n = this.resolvedOptions.thousandSeparator;
1014
+ if (!n || this.resolvedOptions.thousandStyle === y.None) return;
1015
+ const r = e.selectionStart ?? 0, s = e.selectionEnd ?? e.value.length, i = Ye(e.value, r, s, n);
1016
+ i && (this.withInternalWrite(
1017
+ () => Oe(e, i.raw, i.rawStart, i.rawEnd)
1018
+ ), this.handleValueChange(i.raw, i.raw));
1054
1019
  }
1055
- handleBlur(t) {
1056
- const n = t.target, { thousandSeparator: r, thousandStyle: i } = this.resolvedOptions;
1057
- if (r && i !== L.None && n.value) {
1058
- const s = this.formatValueForDisplay(n.value);
1059
- n.value = s;
1060
- const a = this.resolvedOptions.rawValueMode ? v(s, r) : void 0;
1061
- this.handleValueChange(s, a);
1062
- }
1020
+ handleFocus(e) {
1021
+ this.pendingMouseStrip || this.stripSeparatorsAndMapCaret(e.target);
1022
+ }
1023
+ handleMouseDown() {
1024
+ this.pendingMouseStrip = !0;
1025
+ }
1026
+ handleClick(e) {
1027
+ this.pendingMouseStrip && (this.pendingMouseStrip = !1, this.stripSeparatorsAndMapCaret(e.target));
1028
+ }
1029
+ handleBlur(e) {
1030
+ this.pendingMouseStrip = !1;
1031
+ const n = e.target, { thousandSeparator: r, thousandStyle: s } = this.resolvedOptions;
1032
+ if (!r || s === y.None || !n.value) return;
1033
+ const i = this.applyDisplaySeparators(n.value);
1034
+ i !== n.value && this.withInternalWrite(
1035
+ () => T(n, i, i.length)
1036
+ );
1037
+ const a = this.resolvedOptions.rawValueMode ? this.toRaw(i) : void 0;
1038
+ this.handleValueChange(i, a);
1063
1039
  }
1064
1040
  getValue() {
1065
1041
  return this.resolvedOptions.rawValueMode ? this.rawValue : this.element.value;
1066
1042
  }
1067
- setValue(t) {
1043
+ /**
1044
+ * Sets the input's value programmatically.
1045
+ *
1046
+ * @param value - The new value. In `rawValueMode`, this is treated as raw and re-formatted for display.
1047
+ * @param options.undoable - Defaults to `true`: routes the write through `setRangeText`
1048
+ * so the browser's undo stack stays intact and `Ctrl+Z` can revert this call. Pass
1049
+ * `false` only when you intentionally want to wipe the undo history (e.g. form reset).
1050
+ */
1051
+ setValue(e, n) {
1052
+ let r;
1068
1053
  if (this.resolvedOptions.rawValueMode) {
1069
- const n = this.resolvedOptions.thousandSeparator ? v(t, this.resolvedOptions.thousandSeparator) : t;
1070
- this.rawValue = n, this.element.value = this.formatValueForDisplay(n);
1054
+ const s = this.toRaw(e);
1055
+ this.rawValue = s, r = this.applyDisplaySeparators(s);
1071
1056
  } else
1072
- this.element.value = t;
1057
+ r = e;
1058
+ if ((n == null ? void 0 : n.undoable) === !1) {
1059
+ this.element.value = r;
1060
+ return;
1061
+ }
1062
+ this.withInternalWrite(
1063
+ () => T(this.element, r, r.length)
1064
+ );
1073
1065
  }
1074
1066
  disable() {
1075
1067
  this.element.disabled = !0;
@@ -1077,11 +1069,11 @@ class gt {
1077
1069
  enable() {
1078
1070
  this.element.disabled = !1;
1079
1071
  }
1080
- addEventListener(t, n) {
1081
- this.element.addEventListener(t, n);
1072
+ addEventListener(e, n) {
1073
+ this.element.addEventListener(e, n);
1082
1074
  }
1083
- removeEventListener(t, n) {
1084
- this.element.removeEventListener(t, n);
1075
+ removeEventListener(e, n) {
1076
+ this.element.removeEventListener(e, n);
1085
1077
  }
1086
1078
  /**
1087
1079
  * Returns the underlying HTMLInputElement for direct access.
@@ -1103,45 +1095,62 @@ class gt {
1103
1095
  * In rawValueMode, the value will be formatted for display.
1104
1096
  * Otherwise, sets the value directly.
1105
1097
  */
1106
- set value(t) {
1107
- this.setValue(t);
1098
+ set value(e) {
1099
+ this.setValue(e);
1108
1100
  }
1109
1101
  /**
1110
1102
  * Gets the value as a number, similar to HTMLInputElement.valueAsNumber.
1111
1103
  * Returns NaN if the value cannot be converted to a number.
1104
+ *
1105
+ * **Precision warning**: this getter returns a JavaScript `number` (IEEE 754 double).
1106
+ * Values beyond ~15 significant digits will lose precision. Numora is designed around
1107
+ * string values for this reason - prefer {@link getValue} when exact precision matters.
1108
+ * Treat `valueAsNumber` strictly as an escape hatch for arithmetic that you already know
1109
+ * is safe at float precision.
1112
1110
  */
1113
1111
  get valueAsNumber() {
1114
- const t = this.getValue();
1115
- if (!t)
1112
+ const e = this.getValue();
1113
+ if (!e)
1116
1114
  return NaN;
1117
- const n = this.resolvedOptions.thousandSeparator ? v(t, this.resolvedOptions.thousandSeparator) : t, r = this.resolvedOptions.decimalSeparator && this.resolvedOptions.decimalSeparator !== "." ? n.replace(new RegExp(y(this.resolvedOptions.decimalSeparator), "g"), ".") : n;
1115
+ const n = this.toRaw(e), r = this.resolvedOptions.decimalSeparator && this.resolvedOptions.decimalSeparator !== "." ? n.replace(new RegExp(M(this.resolvedOptions.decimalSeparator), "g"), ".") : n;
1118
1116
  return parseFloat(r);
1119
1117
  }
1120
1118
  /**
1121
1119
  * Sets the value from a number, similar to HTMLInputElement.valueAsNumber.
1122
1120
  */
1123
- set valueAsNumber(t) {
1124
- if (isNaN(t)) {
1121
+ set valueAsNumber(e) {
1122
+ if (isNaN(e)) {
1125
1123
  this.setValue("");
1126
1124
  return;
1127
1125
  }
1128
- const n = t.toString();
1126
+ const n = e.toString();
1129
1127
  this.setValue(n);
1130
1128
  }
1131
1129
  }
1132
1130
  export {
1133
- b as FormatOn,
1134
- gt as NumoraInput,
1135
- L as ThousandStyle,
1136
- et as applyLocale,
1137
- M as formatInputValue,
1138
- ft as formatValueForDisplay,
1139
- Ve as getNumoraPattern,
1140
- Fe as getSeparatorsFromLocale,
1141
- je as handleOnBeforeInputNumoraInput,
1142
- Ke as handleOnChangeNumoraInput,
1143
- He as handleOnKeyDownNumoraInput,
1144
- Qe as handleOnPasteNumoraInput,
1145
- v as removeThousandSeparators,
1146
- tt as validateNumoraInputOptions
1131
+ I as FormatOn,
1132
+ L as InputType,
1133
+ ut as NumoraInput,
1134
+ y as ThousandStyle,
1135
+ rt as applyLocale,
1136
+ Ye as computeStripSeparatorsResult,
1137
+ Te as expandCompactNotation,
1138
+ Le as expandScientificNotation,
1139
+ xe as filterMobileKeyboardArtifacts,
1140
+ ht as formatValueForDisplay,
1141
+ nt as getSeparatorsFromLocale,
1142
+ Ve as handleOnBeforeInputNumoraInput,
1143
+ Fe as handleOnKeyDownNumoraInput,
1144
+ tt as handleOnPasteNumoraInput,
1145
+ Re as normalizeFullWidthDigits,
1146
+ Me as prependLeadingZero,
1147
+ Se as removeExtraDecimalSeparators,
1148
+ ve as removeLeadingZeros,
1149
+ Ee as removeNonNumericCharacters,
1150
+ b as removeThousandSeparators,
1151
+ _e as sanitizeNumoraInput,
1152
+ $e as truncateToMaxLength,
1153
+ st as validateNumoraInputOptions,
1154
+ Oe as writeStripPreservingUndo,
1155
+ T as writeValuePreservingUndo
1147
1156
  };