adverich-kun-ui 0.1.526 → 0.1.527
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.
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ref as M, computed as p, watch as ee, nextTick as N } from "vue";
|
|
2
|
-
import { clamp as g, toRawNumberString as k, fromRawString as
|
|
2
|
+
import { clamp as g, toRawNumberString as k, fromRawString as y } from "./numberFormatUtils.js";
|
|
3
3
|
function ue(n, c) {
|
|
4
|
-
const r = M(""), o = M(null),
|
|
4
|
+
const r = M(""), o = M(null), $ = M(null), h = M(!1), S = M(0);
|
|
5
5
|
let a = "";
|
|
6
|
-
const
|
|
6
|
+
const A = p(() => {
|
|
7
7
|
const e = Number(n.precision);
|
|
8
8
|
return e > 0 ? e + 1 : 1;
|
|
9
9
|
});
|
|
@@ -19,14 +19,14 @@ function ue(n, c) {
|
|
|
19
19
|
const D = l ? w.replace(/\B(?=(\d{3})+(?!\d))/g, ".") : w;
|
|
20
20
|
return f === 0 || !V || V.length === 0 ? d + D : d + D + "," + V;
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function x(e) {
|
|
23
23
|
if (e == null) return NaN;
|
|
24
24
|
let t = String(e).trim();
|
|
25
25
|
return t ? (t = t.replace(/\s+/g, ""), t = t.replace(/\./g, ""), t = t.replace(/,/g, "."), t = t.replace(/[^0-9\.\-]/g, ""), t === "" ? NaN : parseFloat(t)) : NaN;
|
|
26
26
|
}
|
|
27
|
-
const
|
|
27
|
+
const F = C((e) => {
|
|
28
28
|
c("update:modelValue", e);
|
|
29
|
-
},
|
|
29
|
+
}, 100);
|
|
30
30
|
function K(e) {
|
|
31
31
|
const t = o.value;
|
|
32
32
|
if (!t) return;
|
|
@@ -37,9 +37,11 @@ function ue(n, c) {
|
|
|
37
37
|
i = i.replace(/^0+(\d)/, "$1"), r.value = i, N(() => {
|
|
38
38
|
if (!o.value) return;
|
|
39
39
|
o.value.value = i;
|
|
40
|
-
const
|
|
41
|
-
o.value.setSelectionRange(
|
|
40
|
+
const m = Math.min(i.length, f);
|
|
41
|
+
o.value.setSelectionRange(m, m);
|
|
42
42
|
}), c("input", i);
|
|
43
|
+
const s = x(i);
|
|
44
|
+
isNaN(s) || F(s);
|
|
43
45
|
return;
|
|
44
46
|
}
|
|
45
47
|
if (u = u.replace(/\./g, ",").replace(/\s+/g, ""), u = u.replace(/[^0-9,\-]/g, ""), (u.match(/,/g) || []).length > 1) {
|
|
@@ -54,8 +56,8 @@ function ue(n, c) {
|
|
|
54
56
|
const i = f;
|
|
55
57
|
t.setSelectionRange(i, i);
|
|
56
58
|
}), c("input", u);
|
|
57
|
-
const d =
|
|
58
|
-
isNaN(d) ||
|
|
59
|
+
const d = x(u);
|
|
60
|
+
isNaN(d) || F(d);
|
|
59
61
|
}
|
|
60
62
|
function C(e, t = 250) {
|
|
61
63
|
let u;
|
|
@@ -97,13 +99,13 @@ function ue(n, c) {
|
|
|
97
99
|
h.value = !1;
|
|
98
100
|
let e = (r.value ?? "").toString().trim();
|
|
99
101
|
e || (e = "0");
|
|
100
|
-
let t =
|
|
102
|
+
let t = x(e);
|
|
101
103
|
isNaN(t) && (t = 0), t = g(t, n.min, n.max), r.value = b(t, Number(n.precision), !1), c("update:modelValue", t), c("blur");
|
|
102
104
|
}
|
|
103
|
-
function
|
|
104
|
-
return Number(n.precision) === 0 ? e === "" ? "0" : e.replace(/^0+(\d)/, "$1") : e.padStart(
|
|
105
|
+
function T(e) {
|
|
106
|
+
return Number(n.precision) === 0 ? e === "" ? "0" : e.replace(/^0+(\d)/, "$1") : e.padStart(A.value, "0");
|
|
105
107
|
}
|
|
106
|
-
function
|
|
108
|
+
function B(e, t) {
|
|
107
109
|
let u = 0;
|
|
108
110
|
for (let l = 0; l < t; l++)
|
|
109
111
|
/\d/.test(e[l]) && u++;
|
|
@@ -120,7 +122,7 @@ function ue(n, c) {
|
|
|
120
122
|
if (/\d/.test(e[l])) return l + 1;
|
|
121
123
|
return e.length;
|
|
122
124
|
}
|
|
123
|
-
function
|
|
125
|
+
function P() {
|
|
124
126
|
const e = Number(n.precision) + 1;
|
|
125
127
|
a = String(a || "").padStart(e, "0");
|
|
126
128
|
const t = Math.max(1, a.length - Number(n.precision)), u = a.slice(0, t) || "0", l = a.slice(t).padEnd(Number(n.precision), "0").slice(0, Number(n.precision)), f = `${u}.${l}`, d = parseFloat(f), i = g(d, n.min, n.max);
|
|
@@ -137,9 +139,9 @@ function ue(n, c) {
|
|
|
137
139
|
});
|
|
138
140
|
}
|
|
139
141
|
function q() {
|
|
140
|
-
h.value = !1, a =
|
|
141
|
-
const e =
|
|
142
|
-
a = k(t, Number(n.precision)), a =
|
|
142
|
+
h.value = !1, a = T(a);
|
|
143
|
+
const e = y(a, Number(n.precision)), t = g(e, n.min, n.max);
|
|
144
|
+
a = k(t, Number(n.precision)), a = T(a), r.value = b(t, Number(n.precision), !1), c("update:modelValue", t), c("blur");
|
|
143
145
|
}
|
|
144
146
|
function z(e) {
|
|
145
147
|
h.value = !0, N(() => {
|
|
@@ -150,7 +152,7 @@ function ue(n, c) {
|
|
|
150
152
|
o.value.setSelectionRange(l, l), S.value = r.value.replace(/\D/g, "").length;
|
|
151
153
|
} else {
|
|
152
154
|
const l = o.value.selectionStart || 0;
|
|
153
|
-
S.value =
|
|
155
|
+
S.value = B(r.value, l);
|
|
154
156
|
}
|
|
155
157
|
}), c("focus");
|
|
156
158
|
}
|
|
@@ -165,8 +167,8 @@ function ue(n, c) {
|
|
|
165
167
|
if (m) {
|
|
166
168
|
N(() => {
|
|
167
169
|
if (!o.value) return;
|
|
168
|
-
const
|
|
169
|
-
o.value.setSelectionRange(
|
|
170
|
+
const L = r.value.search(/\d/);
|
|
171
|
+
o.value.setSelectionRange(L, L);
|
|
170
172
|
});
|
|
171
173
|
return;
|
|
172
174
|
}
|
|
@@ -179,10 +181,10 @@ function ue(n, c) {
|
|
|
179
181
|
return;
|
|
180
182
|
}
|
|
181
183
|
if (i || s) return;
|
|
182
|
-
const D = (u == null ? void 0 : u.selectionStart) ?? 0, _ = r.value || "", v =
|
|
184
|
+
const D = (u == null ? void 0 : u.selectionStart) ?? 0, _ = r.value || "", v = B(_, D);
|
|
183
185
|
e.preventDefault();
|
|
184
|
-
const
|
|
185
|
-
for (; a.length <
|
|
186
|
+
const I = Number(n.precision) + 1;
|
|
187
|
+
for (; a.length < I; ) a = "0" + a;
|
|
186
188
|
if (l)
|
|
187
189
|
a = a.substring(0, v) + t + a.substring(v), S.value = v + 1;
|
|
188
190
|
else if (f) {
|
|
@@ -193,19 +195,19 @@ function ue(n, c) {
|
|
|
193
195
|
} else if (d)
|
|
194
196
|
v < a.length && (a = a.substring(0, v) + a.substring(v + 1), S.value = v);
|
|
195
197
|
else return;
|
|
196
|
-
for (; a.length <
|
|
197
|
-
|
|
198
|
+
for (; a.length < I; ) a = "0" + a;
|
|
199
|
+
P();
|
|
198
200
|
}
|
|
199
201
|
function O() {
|
|
200
202
|
let e;
|
|
201
|
-
n.formatMode === "bank" ? (e =
|
|
203
|
+
n.formatMode === "bank" ? (e = y(a, Number(n.precision)) || 0, e = g(e + Number(n.step), n.min, n.max), a = k(e, Number(n.precision)), r.value = b(e, Number(n.precision), !1), c("update:modelValue", e), c("input", e)) : (e = Number(n.modelValue ?? 0) || 0, e = g(e + Number(n.step), n.min, n.max), r.value = b(e, Number(n.precision), !1), c("update:modelValue", e), c("input", e));
|
|
202
204
|
}
|
|
203
205
|
function Q() {
|
|
204
206
|
let e;
|
|
205
|
-
n.formatMode === "bank" ? (e =
|
|
207
|
+
n.formatMode === "bank" ? (e = y(a, Number(n.precision)) || 0, e = g(e - Number(n.step), n.min, n.max), a = k(e, Number(n.precision)), r.value = b(e, Number(n.precision), !1), c("update:modelValue", e), c("input", e)) : (e = Number(n.modelValue ?? 0) || 0, e = g(e - Number(n.step), n.min, n.max), r.value = b(e, Number(n.precision), !1), c("update:modelValue", e), c("input", e));
|
|
206
208
|
}
|
|
207
209
|
function W() {
|
|
208
|
-
n.formatMode === "bank" ? (a = "0".repeat(Number(n.precision) + 1), S.value = Number(n.precision) + 1,
|
|
210
|
+
n.formatMode === "bank" ? (a = "0".repeat(Number(n.precision) + 1), S.value = Number(n.precision) + 1, P(), N(() => {
|
|
209
211
|
var e, t;
|
|
210
212
|
return (t = (e = o.value) == null ? void 0 : e.focus) == null ? void 0 : t.call(e);
|
|
211
213
|
})) : (r.value = "", c("update:modelValue", null), N(() => {
|
|
@@ -245,7 +247,7 @@ function ue(n, c) {
|
|
|
245
247
|
return {
|
|
246
248
|
inputValue: r,
|
|
247
249
|
numberInput: o,
|
|
248
|
-
rootRef:
|
|
250
|
+
rootRef: $,
|
|
249
251
|
validateKey: J,
|
|
250
252
|
handleFocus: Y,
|
|
251
253
|
handleBlur: Z,
|