adverich-kun-ui 0.1.401 → 0.1.403
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,130 +1,131 @@
|
|
|
1
|
-
import { ref as
|
|
1
|
+
import { ref as N, computed as j, watch as q, nextTick as C } from "vue";
|
|
2
2
|
import { format as h, clamp as w, toRawNumberString as S, fromRawString as L } from "./numberFormatUtils.js";
|
|
3
3
|
function O(t, o) {
|
|
4
|
-
const u =
|
|
5
|
-
let
|
|
4
|
+
const u = N(""), r = N(null), F = N(null), x = N(!1), s = N(0);
|
|
5
|
+
let n = "";
|
|
6
6
|
const K = j(() => Number(t.precision) > 0 ? Number(t.precision) + 1 : 1);
|
|
7
|
-
function d(
|
|
8
|
-
return Number(t.precision) === 0 ?
|
|
7
|
+
function d(e) {
|
|
8
|
+
return Number(t.precision) === 0 ? e === "" ? "0" : e.replace(/^0+(\d)/, "$1") : e.padStart(K.value, "0");
|
|
9
9
|
}
|
|
10
|
-
q(() => t.modelValue, (
|
|
11
|
-
if (
|
|
12
|
-
u.value = h(0, t),
|
|
10
|
+
q(() => t.modelValue, (e) => {
|
|
11
|
+
if (e == null || isNaN(e))
|
|
12
|
+
u.value = h(0, t), n = "0".repeat(Number(t.precision) + 1);
|
|
13
13
|
else {
|
|
14
|
-
const i = parseFloat(
|
|
15
|
-
|
|
14
|
+
const i = parseFloat(e), c = w(i, t.min, t.max);
|
|
15
|
+
n = S(c, Number(t.precision)), n.length < Number(t.precision) + 1 && (n = n.padStart(Number(t.precision) + 1, "0")), u.value = h(c, t);
|
|
16
16
|
}
|
|
17
17
|
}, { immediate: !0 });
|
|
18
|
-
function $(
|
|
19
|
-
const { key: i, target: c } =
|
|
18
|
+
function $(e) {
|
|
19
|
+
const { key: i, target: c } = e, l = /^[0-9]$/.test(i), A = i === "Backspace", y = i === "Delete", g = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(i), b = e.ctrlKey || e.metaKey, m = i === "Home", z = i === "End";
|
|
20
20
|
if (m) {
|
|
21
21
|
C(() => {
|
|
22
|
-
if (!
|
|
23
|
-
const
|
|
24
|
-
|
|
22
|
+
if (!r.value) return;
|
|
23
|
+
const v = u.value.search(/\d/);
|
|
24
|
+
r.value.setSelectionRange(v, v);
|
|
25
25
|
});
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
28
|
if (z) {
|
|
29
29
|
C(() => {
|
|
30
|
-
if (!
|
|
31
|
-
const
|
|
32
|
-
|
|
30
|
+
if (!r.value) return;
|
|
31
|
+
const a = u.value;
|
|
32
|
+
r.value.setSelectionRange(a.length, a.length);
|
|
33
33
|
});
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
if (g || b) return;
|
|
37
37
|
const D = E(u.value, c.selectionStart);
|
|
38
|
-
|
|
38
|
+
e.preventDefault();
|
|
39
39
|
const k = Number(t.precision) + 1;
|
|
40
|
-
for (;
|
|
41
|
-
|
|
40
|
+
for (; n.length < k; )
|
|
41
|
+
n = "0" + n;
|
|
42
42
|
const f = R(u.value, D);
|
|
43
43
|
if (l)
|
|
44
|
-
|
|
44
|
+
n = n.substring(0, f) + i + n.substring(f), s.value = f + 1;
|
|
45
45
|
else if (A && D > 0) {
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
48
|
-
const U = Math.max(0,
|
|
49
|
-
|
|
46
|
+
const a = R(u.value, D), v = a - 1;
|
|
47
|
+
if (n.length <= Number(t.precision) + 1) {
|
|
48
|
+
const U = Math.max(0, a - 1);
|
|
49
|
+
n = n.slice(0, U) + n.slice(a), n = d(n), s.value = a, V();
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
} else y && D < u.value.length && f <
|
|
54
|
-
for (
|
|
55
|
-
|
|
52
|
+
a > 0 && (n = n.slice(0, v) + n.slice(a), n = d(n), s.value = v);
|
|
53
|
+
} else y && D < u.value.length && f < n.length && (n = n.substring(0, f) + n.substring(f + 1), s.value = f);
|
|
54
|
+
for (n = d(n); n.length < k; )
|
|
55
|
+
n = "0" + n;
|
|
56
56
|
V();
|
|
57
57
|
}
|
|
58
|
-
function R(
|
|
58
|
+
function R(e, i) {
|
|
59
59
|
let c = 0;
|
|
60
60
|
for (let l = 0; l < i; l++)
|
|
61
|
-
/\d/.test(
|
|
61
|
+
/\d/.test(e[l]) && c++;
|
|
62
62
|
return c;
|
|
63
63
|
}
|
|
64
|
-
function B(
|
|
64
|
+
function B(e, i) {
|
|
65
65
|
let c = 0;
|
|
66
|
-
for (let l = 0; l <
|
|
67
|
-
if (/\d/.test(
|
|
66
|
+
for (let l = 0; l < e.length; l++)
|
|
67
|
+
if (/\d/.test(e[l])) {
|
|
68
68
|
if (c === i)
|
|
69
69
|
return l;
|
|
70
70
|
c++;
|
|
71
71
|
}
|
|
72
|
-
for (let l =
|
|
73
|
-
if (/\d/.test(
|
|
72
|
+
for (let l = e.length - 1; l >= 0; l--)
|
|
73
|
+
if (/\d/.test(e[l]))
|
|
74
74
|
return l + 1;
|
|
75
|
-
return
|
|
75
|
+
return e.length;
|
|
76
76
|
}
|
|
77
|
-
function E(
|
|
78
|
-
for (; i <
|
|
77
|
+
function E(e, i) {
|
|
78
|
+
for (; i < e.length && !/\d/.test(e[i]); )
|
|
79
79
|
i++;
|
|
80
|
-
if (i >=
|
|
81
|
-
for (i =
|
|
80
|
+
if (i >= e.length)
|
|
81
|
+
for (i = e.length; i > 0 && !/\d/.test(e[i - 1]); )
|
|
82
82
|
i--;
|
|
83
|
-
const c =
|
|
83
|
+
const c = e.search(/\d/);
|
|
84
84
|
return i < c && (i = c), i;
|
|
85
85
|
}
|
|
86
86
|
function V() {
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
const i = Math.max(1,
|
|
90
|
-
|
|
91
|
-
if (
|
|
87
|
+
const e = Number(t.precision) + 1;
|
|
88
|
+
n.padStart(e, "0");
|
|
89
|
+
const i = Math.max(1, n.length - Number(t.precision)), c = n.slice(0, i) || "0", l = n.slice(i).padEnd(Number(t.precision), "0").slice(0, Number(t.precision)), A = `${c}.${l}`, y = parseFloat(A), g = w(y, t.min, t.max);
|
|
90
|
+
n = S(g, Number(t.precision)), u.value = h(g, t), o("update:modelValue", g), o("input", g), C(() => {
|
|
91
|
+
if (r.value)
|
|
92
92
|
try {
|
|
93
93
|
const b = u.value;
|
|
94
94
|
let m = B(b, s.value);
|
|
95
95
|
for (; m < b.length && !/\d/.test(b[m]); )
|
|
96
96
|
m++;
|
|
97
|
-
|
|
97
|
+
r.value.setSelectionRange(m, m);
|
|
98
98
|
} catch {
|
|
99
|
-
|
|
99
|
+
r.value.setSelectionRange(u.value.length, u.value.length);
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
103
|
function M() {
|
|
104
|
-
x.value = !1,
|
|
105
|
-
const
|
|
106
|
-
|
|
104
|
+
x.value = !1, n = d(n);
|
|
105
|
+
const e = L(n, Number(t.precision)), i = w(e, t.min, t.max);
|
|
106
|
+
n = S(i, Number(t.precision)), n = d(n), u.value = h(i, t), o("update:modelValue", i), o("blur");
|
|
107
107
|
}
|
|
108
108
|
function P() {
|
|
109
109
|
var i;
|
|
110
110
|
x.value = !0;
|
|
111
|
-
const
|
|
112
|
-
s.value = R(u.value,
|
|
111
|
+
const e = ((i = r.value) == null ? void 0 : i.selectionStart) || 0;
|
|
112
|
+
s.value = R(u.value, e), o("focus");
|
|
113
113
|
}
|
|
114
114
|
function T() {
|
|
115
|
-
let
|
|
116
|
-
|
|
115
|
+
let e = L(n, Number(t.precision)) || 0;
|
|
116
|
+
e = w(e + Number(t.step), t.min, t.max), n = S(e, Number(t.precision)), u.value = h(e, t), o("update:modelValue", e);
|
|
117
117
|
}
|
|
118
118
|
function H() {
|
|
119
|
-
let
|
|
120
|
-
|
|
119
|
+
let e = L(n, Number(t.precision)) || 0;
|
|
120
|
+
e = w(e - Number(t.step), t.min, t.max), n = S(e, Number(t.precision)), u.value = h(e, t), o("update:modelValue", e);
|
|
121
121
|
}
|
|
122
122
|
function I() {
|
|
123
|
-
e
|
|
123
|
+
var e;
|
|
124
|
+
n = "0".repeat(Number(t.precision) + 1), s.value = Number(t.precision) + 1, V(), (e = r.value) == null || e.focus();
|
|
124
125
|
}
|
|
125
126
|
return {
|
|
126
127
|
inputValue: u,
|
|
127
|
-
numberInput:
|
|
128
|
+
numberInput: r,
|
|
128
129
|
rootRef: F,
|
|
129
130
|
validateKey: $,
|
|
130
131
|
handleFocus: P,
|