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