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