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