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