adverich-kun-ui 0.1.522 → 0.1.523

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