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-1"
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 N, 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 = N(""), r = N(null), F = N(null), x = N(!1), s = N(0);
5
- let n = "";
6
- const K = j(() => Number(t.precision) > 0 ? Number(t.precision) + 1 : 1);
7
- function d(e) {
8
- return Number(t.precision) === 0 ? e === "" ? "0" : e.replace(/^0+(\d)/, "$1") : e.padStart(K.value, "0");
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
- q(() => t.modelValue, (e) => {
11
- if (e == null || isNaN(e))
12
- u.value = h(0, t), n = "0".repeat(Number(t.precision) + 1);
13
- else {
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
- }
17
- }, { immediate: !0 });
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: 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
- if (m) {
21
- C(() => {
22
- if (!r.value) return;
23
- const v = u.value.search(/\d/);
24
- r.value.setSelectionRange(v, v);
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 (z) {
29
- C(() => {
30
- if (!r.value) return;
31
- const a = u.value;
32
- r.value.setSelectionRange(a.length, a.length);
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 (g || b) return;
37
- const D = E(u.value, c.selectionStart);
44
+ if (o || b) return;
45
+ const V = E(l.value, r.selectionStart);
38
46
  e.preventDefault();
39
- const k = Number(t.precision) + 1;
40
- for (; n.length < k; )
41
- n = "0" + n;
42
- const f = R(u.value, D);
43
- if (l)
44
- n = n.substring(0, f) + i + n.substring(f), s.value = f + 1;
45
- else if (A && D > 0) {
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();
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 && (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
- V();
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 R(e, i) {
59
- let c = 0;
60
- for (let l = 0; l < i; l++)
61
- /\d/.test(e[l]) && c++;
62
- return c;
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, i) {
65
- let c = 0;
66
- for (let l = 0; l < e.length; l++)
67
- if (/\d/.test(e[l])) {
68
- if (c === i)
69
- return l;
70
- c++;
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 l = e.length - 1; l >= 0; l--)
73
- if (/\d/.test(e[l]))
74
- return l + 1;
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, i) {
78
- for (; i < e.length && !/\d/.test(e[i]); )
79
- i++;
80
- if (i >= e.length)
81
- for (i = e.length; i > 0 && !/\d/.test(e[i - 1]); )
82
- i--;
83
- const c = e.search(/\d/);
84
- return i < c && (i = c), i;
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 V() {
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)
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 = u.value;
94
- let m = B(b, s.value);
95
- for (; m < b.length && !/\d/.test(b[m]); )
96
- m++;
97
- r.value.setSelectionRange(m, m);
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
- r.value.setSelectionRange(u.value.length, u.value.length);
107
+ c.value.setSelectionRange(l.value.length, l.value.length);
100
108
  }
101
109
  });
102
110
  }
103
111
  function M() {
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
- }
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
- 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
+ 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(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);
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
- n = "0".repeat(Number(t.precision) + 1), s.value = Number(t.precision) + 1, V(), (e = r.value) == null || e.focus();
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: u,
128
- numberInput: r,
135
+ inputValue: l,
136
+ numberInput: c,
129
137
  rootRef: F,
130
138
  validateKey: $,
131
- handleFocus: P,
139
+ handleFocus: T,
132
140
  handleBlur: M,
133
- onIncrement: T,
134
- onDecrement: H,
135
- onClear: I,
136
- isActive: x,
137
- focus: x
141
+ onIncrement: H,
142
+ onDecrement: I,
143
+ onClear: z,
144
+ isActive: R,
145
+ focus: R
138
146
  };
139
147
  }
140
148
  export {
141
- O as useKunNumberField
149
+ Q as useKunNumberField
142
150
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adverich-kun-ui",
3
- "version": "0.1.455",
3
+ "version": "0.1.456",
4
4
  "type": "module",
5
5
  "description": "Una librería de componentes Vue.js con Tailwind CSS",
6
6
  "main": "dist/index.js",