adverich-kun-ui 0.1.525 → 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,247 +1,264 @@
|
|
|
1
|
-
import { ref as
|
|
2
|
-
import { clamp as
|
|
3
|
-
function
|
|
4
|
-
const r =
|
|
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 y } from "./numberFormatUtils.js";
|
|
3
|
+
function ue(n, c) {
|
|
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
|
});
|
|
10
|
-
function b(e, t = 2, l = !
|
|
10
|
+
function b(e, t = 2, u = !1, l = !0) {
|
|
11
11
|
if (e == null || isNaN(e)) return "";
|
|
12
|
-
const
|
|
13
|
-
let
|
|
14
|
-
const m =
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
let
|
|
18
|
-
|
|
19
|
-
const D =
|
|
20
|
-
return
|
|
21
|
-
}
|
|
22
|
-
function
|
|
12
|
+
const f = Number(t), d = Number(e) < 0 ? "-" : "", i = Math.abs(Number(e));
|
|
13
|
+
let s = k(i, f);
|
|
14
|
+
const m = f + 1;
|
|
15
|
+
s.length < m && (s = s.padStart(m, "0"));
|
|
16
|
+
const w = s.slice(0, s.length - f) || "0";
|
|
17
|
+
let V = f > 0 ? s.slice(-f) : "";
|
|
18
|
+
f > 0 && u && (V = V.replace(/0+$/, ""));
|
|
19
|
+
const D = l ? w.replace(/\B(?=(\d{3})+(?!\d))/g, ".") : w;
|
|
20
|
+
return f === 0 || !V || V.length === 0 ? d + D : d + D + "," + V;
|
|
21
|
+
}
|
|
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
|
-
|
|
27
|
+
const F = C((e) => {
|
|
28
|
+
c("update:modelValue", e);
|
|
29
|
+
}, 100);
|
|
30
|
+
function K(e) {
|
|
28
31
|
const t = o.value;
|
|
29
32
|
if (!t) return;
|
|
30
|
-
let
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
33
|
-
let i =
|
|
34
|
-
i = i.replace(/^0+(\d)/, "$1"), r.value = i,
|
|
33
|
+
let u = t.value;
|
|
34
|
+
const l = Number(n.precision), f = t.selectionStart || 0;
|
|
35
|
+
if (l === 0) {
|
|
36
|
+
let i = u.replace(/[^0-9\-]/g, "");
|
|
37
|
+
i = i.replace(/^0+(\d)/, "$1"), r.value = i, N(() => {
|
|
35
38
|
if (!o.value) return;
|
|
36
39
|
o.value.value = i;
|
|
37
|
-
const
|
|
38
|
-
o.value.setSelectionRange(
|
|
39
|
-
}),
|
|
40
|
+
const m = Math.min(i.length, f);
|
|
41
|
+
o.value.setSelectionRange(m, m);
|
|
42
|
+
}), c("input", i);
|
|
43
|
+
const s = x(i);
|
|
44
|
+
isNaN(s) || F(s);
|
|
40
45
|
return;
|
|
41
46
|
}
|
|
42
|
-
if (
|
|
43
|
-
const i =
|
|
44
|
-
|
|
47
|
+
if (u = u.replace(/\./g, ",").replace(/\s+/g, ""), u = u.replace(/[^0-9,\-]/g, ""), (u.match(/,/g) || []).length > 1) {
|
|
48
|
+
const i = u.split(","), s = i.shift() || "", m = i.join("");
|
|
49
|
+
u = s + (m.length ? "," + m : "");
|
|
45
50
|
}
|
|
46
|
-
if (
|
|
47
|
-
const [i,
|
|
48
|
-
|
|
51
|
+
if (u.includes(",")) {
|
|
52
|
+
const [i, s = ""] = u.split(","), m = s.slice(0, l);
|
|
53
|
+
u = i + (m.length ? "," + m : ",");
|
|
49
54
|
}
|
|
50
|
-
r.value =
|
|
55
|
+
r.value = u, N(E), N(() => {
|
|
51
56
|
const i = f;
|
|
52
57
|
t.setSelectionRange(i, i);
|
|
53
|
-
}),
|
|
58
|
+
}), c("input", u);
|
|
59
|
+
const d = x(u);
|
|
60
|
+
isNaN(d) || F(d);
|
|
61
|
+
}
|
|
62
|
+
function C(e, t = 250) {
|
|
63
|
+
let u;
|
|
64
|
+
return (...l) => {
|
|
65
|
+
clearTimeout(u), u = setTimeout(() => e(...l), t);
|
|
66
|
+
};
|
|
54
67
|
}
|
|
55
|
-
function
|
|
68
|
+
function E() {
|
|
56
69
|
o.value && (o.value.value = r.value);
|
|
57
70
|
}
|
|
58
|
-
function
|
|
59
|
-
if (
|
|
60
|
-
const t = Number(n.modelValue),
|
|
71
|
+
function H(e) {
|
|
72
|
+
if (h.value = !0, !o.value) return;
|
|
73
|
+
const t = Number(n.modelValue), u = Number(n.precision);
|
|
61
74
|
if (isNaN(t)) {
|
|
62
|
-
r.value = "",
|
|
75
|
+
r.value = "", c("focus");
|
|
63
76
|
return;
|
|
64
77
|
}
|
|
65
78
|
if (t === 0) {
|
|
66
|
-
r.value = "",
|
|
79
|
+
r.value = "", N(() => {
|
|
67
80
|
try {
|
|
68
81
|
o.value.setSelectionRange(0, 0);
|
|
69
82
|
} catch {
|
|
70
83
|
}
|
|
71
|
-
}),
|
|
84
|
+
}), c("focus");
|
|
72
85
|
return;
|
|
73
86
|
}
|
|
74
|
-
let
|
|
75
|
-
const f =
|
|
76
|
-
let
|
|
77
|
-
|
|
87
|
+
let l = k(Math.abs(t), u);
|
|
88
|
+
const f = l.slice(0, l.length - u) || "0";
|
|
89
|
+
let d = u > 0 ? l.slice(-u) : "";
|
|
90
|
+
u > 0 && (d = d.replace(/0+$/, "")), r.value = (t < 0 ? "-" : "") + f + (d.length ? "," + d : ""), N(() => {
|
|
78
91
|
try {
|
|
79
|
-
const
|
|
80
|
-
o.value.setSelectionRange(
|
|
92
|
+
const i = r.value.length;
|
|
93
|
+
o.value.setSelectionRange(i, i);
|
|
81
94
|
} catch {
|
|
82
95
|
}
|
|
83
|
-
}),
|
|
96
|
+
}), c("focus");
|
|
84
97
|
}
|
|
85
|
-
function
|
|
86
|
-
|
|
98
|
+
function j() {
|
|
99
|
+
h.value = !1;
|
|
87
100
|
let e = (r.value ?? "").toString().trim();
|
|
88
101
|
e || (e = "0");
|
|
89
|
-
let t =
|
|
90
|
-
isNaN(t) && (t = 0), t =
|
|
102
|
+
let t = x(e);
|
|
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");
|
|
91
104
|
}
|
|
92
|
-
function
|
|
93
|
-
return Number(n.precision) === 0 ? e === "" ? "0" : e.replace(/^0+(\d)/, "$1") : e.padStart(
|
|
94
|
-
}
|
|
95
|
-
function
|
|
96
|
-
let
|
|
97
|
-
for (let
|
|
98
|
-
/\d/.test(e[
|
|
99
|
-
return
|
|
100
|
-
}
|
|
101
|
-
function
|
|
102
|
-
let
|
|
103
|
-
for (let
|
|
104
|
-
if (/\d/.test(e[
|
|
105
|
-
if (
|
|
106
|
-
|
|
105
|
+
function T(e) {
|
|
106
|
+
return Number(n.precision) === 0 ? e === "" ? "0" : e.replace(/^0+(\d)/, "$1") : e.padStart(A.value, "0");
|
|
107
|
+
}
|
|
108
|
+
function B(e, t) {
|
|
109
|
+
let u = 0;
|
|
110
|
+
for (let l = 0; l < t; l++)
|
|
111
|
+
/\d/.test(e[l]) && u++;
|
|
112
|
+
return u;
|
|
113
|
+
}
|
|
114
|
+
function U(e, t) {
|
|
115
|
+
let u = 0;
|
|
116
|
+
for (let l = 0; l < e.length; l++)
|
|
117
|
+
if (/\d/.test(e[l])) {
|
|
118
|
+
if (u === t) return l;
|
|
119
|
+
u++;
|
|
107
120
|
}
|
|
108
|
-
for (let
|
|
109
|
-
if (/\d/.test(e[
|
|
121
|
+
for (let l = e.length - 1; l >= 0; l--)
|
|
122
|
+
if (/\d/.test(e[l])) return l + 1;
|
|
110
123
|
return e.length;
|
|
111
124
|
}
|
|
112
|
-
function
|
|
125
|
+
function P() {
|
|
113
126
|
const e = Number(n.precision) + 1;
|
|
114
127
|
a = String(a || "").padStart(e, "0");
|
|
115
|
-
const t = Math.max(1, a.length - Number(n.precision)),
|
|
116
|
-
a = k(
|
|
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);
|
|
129
|
+
a = k(i, Number(n.precision)), r.value = b(i, Number(n.precision), !1), c("update:modelValue", i), c("input", i), N(() => {
|
|
117
130
|
if (o.value)
|
|
118
131
|
try {
|
|
119
|
-
const
|
|
120
|
-
let
|
|
121
|
-
for (;
|
|
122
|
-
o.value.setSelectionRange(
|
|
132
|
+
const s = r.value;
|
|
133
|
+
let m = U(s, S.value);
|
|
134
|
+
for (; m < s.length && !/\d/.test(s[m]); ) m++;
|
|
135
|
+
o.value.setSelectionRange(m, m);
|
|
123
136
|
} catch {
|
|
124
137
|
o.value.setSelectionRange(r.value.length, r.value.length);
|
|
125
138
|
}
|
|
126
139
|
});
|
|
127
140
|
}
|
|
128
|
-
function
|
|
129
|
-
|
|
130
|
-
const e =
|
|
131
|
-
a = k(t, Number(n.precision)), a =
|
|
141
|
+
function q() {
|
|
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");
|
|
132
145
|
}
|
|
133
|
-
function
|
|
134
|
-
|
|
135
|
-
var
|
|
146
|
+
function z(e) {
|
|
147
|
+
h.value = !0, N(() => {
|
|
148
|
+
var u;
|
|
136
149
|
if (!o.value) return;
|
|
137
|
-
if ((e == null ? void 0 : e.relatedTarget) !== void 0 || ((
|
|
138
|
-
const
|
|
139
|
-
o.value.setSelectionRange(
|
|
150
|
+
if ((e == null ? void 0 : e.relatedTarget) !== void 0 || ((u = e == null ? void 0 : e.sourceCapabilities) == null ? void 0 : u.firesTouchEvents) === !1) {
|
|
151
|
+
const l = r.value.length;
|
|
152
|
+
o.value.setSelectionRange(l, l), S.value = r.value.replace(/\D/g, "").length;
|
|
140
153
|
} else {
|
|
141
|
-
const
|
|
142
|
-
|
|
154
|
+
const l = o.value.selectionStart || 0;
|
|
155
|
+
S.value = B(r.value, l);
|
|
143
156
|
}
|
|
144
|
-
}),
|
|
157
|
+
}), c("focus");
|
|
145
158
|
}
|
|
146
|
-
function
|
|
159
|
+
function G(e) {
|
|
147
160
|
var t;
|
|
148
161
|
(t = e.preventDefault) == null || t.call(e);
|
|
149
162
|
}
|
|
150
|
-
function
|
|
163
|
+
function J(e) {
|
|
151
164
|
if (n.formatMode !== "bank") return;
|
|
152
|
-
const { key: t, target:
|
|
165
|
+
const { key: t, target: u } = e, l = /^[0-9]$/.test(t), f = t === "Backspace", d = t === "Delete", i = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(t), s = e.ctrlKey || e.metaKey, m = t === "Home", w = t === "End";
|
|
153
166
|
if (t === "Tab") return;
|
|
154
|
-
if (
|
|
155
|
-
|
|
167
|
+
if (m) {
|
|
168
|
+
N(() => {
|
|
156
169
|
if (!o.value) return;
|
|
157
|
-
const
|
|
158
|
-
o.value.setSelectionRange(
|
|
170
|
+
const L = r.value.search(/\d/);
|
|
171
|
+
o.value.setSelectionRange(L, L);
|
|
159
172
|
});
|
|
160
173
|
return;
|
|
161
174
|
}
|
|
162
|
-
if (
|
|
163
|
-
|
|
175
|
+
if (w) {
|
|
176
|
+
N(() => {
|
|
164
177
|
if (!o.value) return;
|
|
165
178
|
const R = r.value;
|
|
166
179
|
o.value.setSelectionRange(R.length, R.length);
|
|
167
180
|
});
|
|
168
181
|
return;
|
|
169
182
|
}
|
|
170
|
-
if (
|
|
171
|
-
const
|
|
183
|
+
if (i || s) return;
|
|
184
|
+
const D = (u == null ? void 0 : u.selectionStart) ?? 0, _ = r.value || "", v = B(_, D);
|
|
172
185
|
e.preventDefault();
|
|
173
|
-
const
|
|
174
|
-
for (; a.length <
|
|
175
|
-
if (
|
|
176
|
-
a = a.substring(0,
|
|
186
|
+
const I = Number(n.precision) + 1;
|
|
187
|
+
for (; a.length < I; ) a = "0" + a;
|
|
188
|
+
if (l)
|
|
189
|
+
a = a.substring(0, v) + t + a.substring(v), S.value = v + 1;
|
|
177
190
|
else if (f) {
|
|
178
|
-
if (
|
|
179
|
-
const R =
|
|
180
|
-
a = a.substring(0, R) + a.substring(R + 1),
|
|
191
|
+
if (v > 0) {
|
|
192
|
+
const R = v - 1;
|
|
193
|
+
a = a.substring(0, R) + a.substring(R + 1), S.value = R;
|
|
181
194
|
}
|
|
182
|
-
} else if (
|
|
183
|
-
|
|
195
|
+
} else if (d)
|
|
196
|
+
v < a.length && (a = a.substring(0, v) + a.substring(v + 1), S.value = v);
|
|
184
197
|
else return;
|
|
185
|
-
for (; a.length <
|
|
186
|
-
|
|
198
|
+
for (; a.length < I; ) a = "0" + a;
|
|
199
|
+
P();
|
|
187
200
|
}
|
|
188
|
-
function
|
|
201
|
+
function O() {
|
|
189
202
|
let e;
|
|
190
|
-
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));
|
|
191
204
|
}
|
|
192
|
-
function
|
|
205
|
+
function Q() {
|
|
193
206
|
let e;
|
|
194
|
-
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));
|
|
195
208
|
}
|
|
196
|
-
function
|
|
197
|
-
n.formatMode === "bank" ? (a = "0".repeat(Number(n.precision) + 1),
|
|
209
|
+
function W() {
|
|
210
|
+
n.formatMode === "bank" ? (a = "0".repeat(Number(n.precision) + 1), S.value = Number(n.precision) + 1, P(), N(() => {
|
|
198
211
|
var e, t;
|
|
199
212
|
return (t = (e = o.value) == null ? void 0 : e.focus) == null ? void 0 : t.call(e);
|
|
200
|
-
})) : (r.value = "",
|
|
213
|
+
})) : (r.value = "", c("update:modelValue", null), N(() => {
|
|
201
214
|
var e, t;
|
|
202
215
|
return (t = (e = o.value) == null ? void 0 : e.focus) == null ? void 0 : t.call(e);
|
|
203
216
|
}));
|
|
204
217
|
}
|
|
205
|
-
|
|
218
|
+
ee(
|
|
206
219
|
[() => n.modelValue, () => n.precision, () => n.formatMode],
|
|
207
|
-
([e, t,
|
|
208
|
-
if (
|
|
209
|
-
|
|
220
|
+
([e, t, u]) => {
|
|
221
|
+
if (u !== "bank") {
|
|
222
|
+
if (h.value) {
|
|
223
|
+
const l = Number(e ?? 0);
|
|
224
|
+
l === 0 ? r.value = "" : r.value = b(l, Number(t), !0, !1);
|
|
225
|
+
} else
|
|
226
|
+
r.value = b(Number(e ?? 0), Number(t), !1, !0);
|
|
210
227
|
return;
|
|
211
228
|
}
|
|
212
229
|
if (e == null || isNaN(e))
|
|
213
230
|
r.value = b(0, Number(t), !1), a = "0".repeat(Number(t) + 1);
|
|
214
231
|
else {
|
|
215
|
-
const
|
|
232
|
+
const l = Number(e), f = g(l, n.min, n.max);
|
|
216
233
|
a = k(f, Number(t)), a.length < Number(t) + 1 && (a = a.padStart(Number(t) + 1, "0")), r.value = b(f, Number(t), !1);
|
|
217
234
|
}
|
|
218
235
|
},
|
|
219
236
|
{ immediate: !0 }
|
|
220
237
|
);
|
|
221
|
-
function
|
|
222
|
-
return n.formatMode !== "bank" ?
|
|
238
|
+
function X(e) {
|
|
239
|
+
return n.formatMode !== "bank" ? K() : G(e);
|
|
223
240
|
}
|
|
224
|
-
function
|
|
225
|
-
return n.formatMode !== "bank" ?
|
|
241
|
+
function Y(e) {
|
|
242
|
+
return n.formatMode !== "bank" ? H() : z(e);
|
|
226
243
|
}
|
|
227
|
-
function
|
|
228
|
-
return n.formatMode !== "bank" ?
|
|
244
|
+
function Z(e) {
|
|
245
|
+
return n.formatMode !== "bank" ? j() : q();
|
|
229
246
|
}
|
|
230
247
|
return {
|
|
231
248
|
inputValue: r,
|
|
232
249
|
numberInput: o,
|
|
233
|
-
rootRef:
|
|
234
|
-
validateKey:
|
|
235
|
-
handleFocus:
|
|
236
|
-
handleBlur:
|
|
237
|
-
handleInput:
|
|
238
|
-
onIncrement:
|
|
239
|
-
onDecrement:
|
|
240
|
-
onClear:
|
|
241
|
-
isActive:
|
|
242
|
-
focus:
|
|
250
|
+
rootRef: $,
|
|
251
|
+
validateKey: J,
|
|
252
|
+
handleFocus: Y,
|
|
253
|
+
handleBlur: Z,
|
|
254
|
+
handleInput: X,
|
|
255
|
+
onIncrement: O,
|
|
256
|
+
onDecrement: Q,
|
|
257
|
+
onClear: W,
|
|
258
|
+
isActive: h,
|
|
259
|
+
focus: h
|
|
243
260
|
};
|
|
244
261
|
}
|
|
245
262
|
export {
|
|
246
|
-
|
|
263
|
+
ue as useKunNumberField
|
|
247
264
|
};
|