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