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 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);
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 I = Z(() => {
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 = !1) {
10
+ function b(e, t = 2, u = !1, l = !0) {
11
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) {
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
- function $(e) {
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 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(() => {
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 c = Math.min(i.length, f);
38
- o.value.setSelectionRange(c, c);
39
- }), s("input", i);
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 (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 : "");
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 (l.includes(",")) {
47
- const [i, c = ""] = l.split(","), m = c.slice(0, u);
48
- l = i + (m.length ? "," + m : ",");
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 = l, d(A), d(() => {
55
+ r.value = u, N(E), N(() => {
51
56
  const i = f;
52
57
  t.setSelectionRange(i, i);
53
- }), s("input", l);
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 A() {
68
+ function E() {
56
69
  o.value && (o.value.value = r.value);
57
70
  }
58
- function K(e) {
59
- if (w.value = !0, !o.value) return;
60
- const t = Number(n.modelValue), l = Number(n.precision);
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 = "", s("focus");
75
+ r.value = "", c("focus");
63
76
  return;
64
77
  }
65
78
  if (t === 0) {
66
- r.value = "", d(() => {
79
+ r.value = "", N(() => {
67
80
  try {
68
81
  o.value.setSelectionRange(0, 0);
69
82
  } catch {
70
83
  }
71
- }), s("focus");
84
+ }), c("focus");
72
85
  return;
73
86
  }
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(() => {
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 c = r.value.length;
80
- o.value.setSelectionRange(c, c);
92
+ const i = r.value.length;
93
+ o.value.setSelectionRange(i, i);
81
94
  } catch {
82
95
  }
83
- }), s("focus");
96
+ }), c("focus");
84
97
  }
85
- function C() {
86
- w.value = !1;
98
+ function j() {
99
+ h.value = !1;
87
100
  let e = (r.value ?? "").toString().trim();
88
101
  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");
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 x(e) {
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;
100
- }
101
- function E(e, t) {
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++;
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 u = e.length - 1; u >= 0; u--)
109
- if (/\d/.test(e[u])) return u + 1;
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 F() {
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)), 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(() => {
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 m = r.value;
120
- let N = E(m, h.value);
121
- for (; N < m.length && !/\d/.test(m[N]); ) N++;
122
- o.value.setSelectionRange(N, N);
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 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");
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 j(e) {
134
- w.value = !0, d(() => {
135
- var l;
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 || ((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;
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 u = o.value.selectionStart || 0;
142
- h.value = y(r.value, u);
154
+ const l = o.value.selectionStart || 0;
155
+ S.value = B(r.value, l);
143
156
  }
144
- }), s("focus");
157
+ }), c("focus");
145
158
  }
146
- function U(e) {
159
+ function G(e) {
147
160
  var t;
148
161
  (t = e.preventDefault) == null || t.call(e);
149
162
  }
150
- function q(e) {
163
+ function J(e) {
151
164
  if (n.formatMode !== "bank") return;
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";
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 (N) {
155
- d(() => {
167
+ if (m) {
168
+ N(() => {
156
169
  if (!o.value) return;
157
- const P = r.value.search(/\d/);
158
- o.value.setSelectionRange(P, P);
170
+ const L = r.value.search(/\d/);
171
+ o.value.setSelectionRange(L, L);
159
172
  });
160
173
  return;
161
174
  }
162
- if (S) {
163
- d(() => {
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 (c || m) return;
171
- const X = (l == null ? void 0 : l.selectionStart) ?? 0, Y = r.value || "", g = y(Y, X);
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 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;
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 (g > 0) {
179
- const R = g - 1;
180
- a = a.substring(0, R) + a.substring(R + 1), h.value = R;
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 (i)
183
- g < a.length && (a = a.substring(0, g) + a.substring(g + 1), h.value = g);
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 < B; ) a = "0" + a;
186
- F();
198
+ for (; a.length < I; ) a = "0" + a;
199
+ P();
187
200
  }
188
- function z() {
201
+ function O() {
189
202
  let 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));
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 G() {
205
+ function Q() {
193
206
  let 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));
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 J() {
197
- n.formatMode === "bank" ? (a = "0".repeat(Number(n.precision) + 1), h.value = Number(n.precision) + 1, F(), d(() => {
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 = "", s("update:modelValue", null), d(() => {
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, l]) => {
208
- if (l !== "bank") {
209
- r.value = b(Number(e ?? 0), Number(t), !1);
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 u = Number(e), f = v(u, n.min, n.max);
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 O(e) {
222
- return n.formatMode !== "bank" ? $() : U(e);
238
+ function X(e) {
239
+ return n.formatMode !== "bank" ? K() : G(e);
223
240
  }
224
- function Q(e) {
225
- return n.formatMode !== "bank" ? K() : j(e);
241
+ function Y(e) {
242
+ return n.formatMode !== "bank" ? H() : z(e);
226
243
  }
227
- function W(e) {
228
- return n.formatMode !== "bank" ? C() : H();
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: 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
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
- te as useKunNumberField
263
+ ue as useKunNumberField
247
264
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adverich-kun-ui",
3
- "version": "0.1.525",
3
+ "version": "0.1.527",
4
4
  "type": "module",
5
5
  "description": "Una librería de componentes Vue.js con Tailwind CSS",
6
6
  "main": "dist/index.js",