adverich-kun-ui 0.1.521 → 0.1.522

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,48 +1,48 @@
1
- import { getCurrentInstance as z, useSlots as E, nextTick as P, computed as R, createElementBlock as l, openBlock as r, createCommentVNode as n, createElementVNode as d, normalizeClass as y, toDisplayString as u, mergeProps as U, unref as o, createBlock as I, renderSlot as x, createVNode as V, withCtx as H, Fragment as j, renderList as L } from "vue";
2
- import { KunNumberFieldProps as T } from "../composables/KunNumberFieldProps.js";
3
- import { useKunNumberField as q } from "../composables/useKunNumberFieldComposable.js";
4
- import G from "../../../KunBtn/src/components/KunBtn.vue.js";
1
+ import { getCurrentInstance as E, useSlots as P, nextTick as R, computed as U, createElementBlock as l, openBlock as s, createCommentVNode as n, createElementVNode as d, normalizeClass as c, toDisplayString as u, mergeProps as H, unref as o, createBlock as x, renderSlot as V, createVNode as j, withCtx as L, Fragment as D, renderList as T } from "vue";
2
+ import { KunNumberFieldProps as q } from "../composables/KunNumberFieldProps.js";
3
+ import { useKunNumberField as G } from "../composables/useKunNumberFieldComposable.js";
4
+ import J from "../../../KunBtn/src/components/KunBtn.vue.js";
5
5
  import f from "../../../KunIcon/src/components/KunIcon.vue.js";
6
- import J from "../../../../icons/IconClose.vue.js";
7
- const O = {
6
+ import O from "../../../../icons/IconClose.vue.js";
7
+ const Q = {
8
8
  key: 0,
9
9
  class: "h-full"
10
- }, Q = ["disabled"], W = {
10
+ }, W = ["disabled"], X = {
11
11
  key: 1,
12
12
  class: "mx-2"
13
- }, X = {
13
+ }, Y = {
14
14
  key: 2,
15
15
  class: "flex items-center justify-center h-full pl-2"
16
- }, Y = ["value", "placeholder", "readonly", "disabled", "maxlength", "aria-invalid"], Z = {
16
+ }, Z = ["value", "placeholder", "readonly", "disabled", "maxlength", "aria-invalid"], _ = {
17
17
  key: 3,
18
18
  class: "px-2"
19
- }, _ = {
19
+ }, ee = {
20
20
  key: 0,
21
21
  class: "flex items-center h-full"
22
- }, ee = ["disabled"], te = ["disabled"], oe = {
22
+ }, te = ["disabled"], oe = ["disabled"], re = {
23
23
  key: 1,
24
24
  class: "flex flex-col items-center justify-center border-l border-slate-600"
25
- }, re = ["disabled"], se = ["disabled"], le = {
25
+ }, se = ["disabled"], le = ["disabled"], ne = {
26
26
  key: 5,
27
27
  class: "flex items-center justify-center h-full pr-1"
28
- }, ne = {
28
+ }, de = {
29
29
  key: 6,
30
30
  class: "h-full"
31
- }, de = ["disabled"], ie = {
31
+ }, ie = ["disabled"], ae = {
32
32
  key: 7,
33
33
  class: "ml-2"
34
- }, ae = {
34
+ }, ue = {
35
35
  key: 0,
36
36
  class: "h-[1.25rem]"
37
- }, ue = {
37
+ }, pe = {
38
38
  key: 0,
39
39
  class: "text-red-500 text-sm text-center"
40
- }, pe = { key: 0 }, be = { key: 1 }, ce = {
40
+ }, be = { key: 0 }, ye = { key: 1 }, ce = {
41
41
  key: 1,
42
42
  class: "text-xs text-center"
43
- }, we = {
43
+ }, ge = {
44
44
  __name: "KunNumberField",
45
- props: T,
45
+ props: q,
46
46
  emits: [
47
47
  "update:modelValue",
48
48
  "focus",
@@ -52,47 +52,50 @@ const O = {
52
52
  "keyDown",
53
53
  "keyUp"
54
54
  ],
55
- setup(D, { expose: F, emit: K }) {
56
- const p = D, b = K, k = `number-input-${z().uid}`, m = E(), N = !!m["prepend-icon"], A = !!m["append-icon"], {
55
+ setup(F, { expose: K, emit: N }) {
56
+ const p = F, b = N, k = `number-input-${E().uid}`, m = P(), A = !!m["prepend-icon"], B = !!m["append-icon"], {
57
57
  inputValue: h,
58
- numberInput: c,
58
+ numberInput: y,
59
59
  rootRef: v,
60
60
  onIncrement: i,
61
61
  onDecrement: a,
62
- onClear: B,
63
- validateKey: M,
62
+ onClear: M,
63
+ validateKey: S,
64
64
  focus: w,
65
65
  handleFocus: g,
66
- handleBlur: C
67
- } = q(p, b);
68
- F({
69
- numberInput: c,
66
+ handleBlur: C,
67
+ handleInput: I
68
+ } = G(p, b);
69
+ K({
70
+ numberInput: y,
70
71
  rootRef: v,
71
72
  focus: () => {
72
- P(() => {
73
+ R(() => {
73
74
  var e;
74
- (e = c.value) == null || e.focus();
75
+ (e = y.value) == null || e.focus();
75
76
  });
76
77
  }
77
78
  });
78
- const S = R(() => p.density === "compact" ? "p-1" : p.density === "comfortable" ? "p-2" : "p-3");
79
- return (e, s) => (r(), l("div", {
79
+ const $ = U(
80
+ () => p.density === "compact" ? "p-1" : p.density === "comfortable" ? "p-2" : "p-3"
81
+ );
82
+ return (e, r) => (s(), l("div", {
80
83
  class: "w-full flex flex-col relative h-fit",
81
84
  ref_key: "rootRef",
82
85
  ref: v
83
86
  }, [
84
- e.label ? (r(), l("label", {
87
+ e.label ? (s(), l("label", {
85
88
  key: 0,
86
89
  for: k,
87
- class: y([
90
+ class: c([
88
91
  e.labelColor,
89
92
  "absolute left-2 transition-all duration-200 ease-in-out pointer-events-none select-none z-10",
90
93
  "-top-2.25 text-xs opacity-80"
91
94
  ])
92
95
  }, u(e.label), 3)) : n("", !0),
93
- d("div", U({ class: "w-full flex flex-col justify-center relative" }, e.$attrs), [
96
+ d("div", H({ class: "w-full flex flex-col justify-center relative" }, e.$attrs), [
94
97
  d("div", {
95
- class: y(["flex items-center w-full h-full border", [
98
+ class: c(["flex items-center w-full h-full border", [
96
99
  e.bgInput,
97
100
  e.rounded,
98
101
  o(w) ? "border-slate-400 dark:border-slate-600 shadow-[0_0_0_1px_rgba(59,130,246,0.5)]" : e.borderColor,
@@ -100,25 +103,25 @@ const O = {
100
103
  e.error ? "bg-red-200 dark:bg-red-900" : ""
101
104
  ]])
102
105
  }, [
103
- !e.noArrows && e.controlVariant === "split" ? (r(), l("div", O, [
106
+ !e.noArrows && e.controlVariant === "split" ? (s(), l("div", Q, [
104
107
  d("button", {
105
108
  type: "button",
106
109
  class: "p-3 text-lg border-r border-slate-600 text-black dark:text-white disabled:opacity-50 cursor-pointer hover:opacity-80",
107
- onClick: s[0] || (s[0] = (...t) => o(a) && o(a)(...t)),
110
+ onClick: r[0] || (r[0] = (...t) => o(a) && o(a)(...t)),
108
111
  disabled: e.disabled || e.readonly
109
- }, "−", 8, Q)
112
+ }, "−", 8, W)
110
113
  ])) : n("", !0),
111
- e.prefix ? (r(), l("div", W, u(e.prefix), 1)) : n("", !0),
112
- e.prependIcon || N ? (r(), l("div", X, [
113
- e.prependIcon ? (r(), I(f, {
114
+ e.prefix ? (s(), l("div", X, u(e.prefix), 1)) : n("", !0),
115
+ e.prependIcon || A ? (s(), l("div", Y, [
116
+ e.prependIcon ? (s(), x(f, {
114
117
  key: 0,
115
118
  icon: e.prependIcon
116
- }, null, 8, ["icon"])) : x(e.$slots, "prepend-icon", { key: 1 })
119
+ }, null, 8, ["icon"])) : V(e.$slots, "prepend-icon", { key: 1 })
117
120
  ])) : n("", !0),
118
121
  d("input", {
119
122
  id: k,
120
123
  ref_key: "numberInput",
121
- ref: c,
124
+ ref: y,
122
125
  type: "text",
123
126
  value: o(h),
124
127
  placeholder: e.placeholder,
@@ -126,97 +129,98 @@ const O = {
126
129
  disabled: e.disabled,
127
130
  maxlength: e.maxlength,
128
131
  autocomplete: "off",
129
- class: y(["w-full h-full bg-transparent rounded focus:outline-none", [S.value, e.textColor, e.placeholderColor, e.textCenter ? "text-center" : ""]]),
132
+ class: c(["w-full h-full bg-transparent rounded focus:outline-none", [$.value, e.textColor, e.placeholderColor, e.textCenter ? "text-center" : ""]]),
130
133
  "aria-invalid": e.error ? "true" : "false",
131
- onBlur: s[1] || (s[1] = (...t) => o(C) && o(C)(...t)),
132
- onFocus: s[2] || (s[2] = (...t) => o(g) && o(g)(...t)),
133
- onKeydown: s[3] || (s[3] = (t) => (o(M)(t), b("keyDown", t))),
134
- onKeyup: s[4] || (s[4] = (t) => b("keyUp", t)),
134
+ onBlur: r[1] || (r[1] = (...t) => o(C) && o(C)(...t)),
135
+ onFocus: r[2] || (r[2] = (...t) => o(g) && o(g)(...t)),
136
+ onInput: r[3] || (r[3] = (...t) => o(I) && o(I)(...t)),
137
+ onKeydown: r[4] || (r[4] = (t) => (o(S)(t), b("keyDown", t))),
138
+ onKeyup: r[5] || (r[5] = (t) => b("keyUp", t)),
135
139
  inputmode: "decimal",
136
140
  pattern: "[0-9]+([\\.,][0-9]+)?"
137
- }, null, 42, Y),
138
- e.clearable && o(h) != null ? (r(), l("div", Z, [
139
- V(G, {
140
- onClick: o(B),
141
+ }, null, 42, Z),
142
+ e.clearable && o(h) != null ? (s(), l("div", _, [
143
+ j(J, {
144
+ onClick: o(M),
141
145
  rounded: "rounded-full",
142
146
  bgColor: "bg-red-500/75",
143
147
  disabled: e.disabled || e.readonly,
144
148
  class: "h-6 w-6"
145
149
  }, {
146
- default: H(() => [
147
- V(f, {
148
- icon: J,
150
+ default: L(() => [
151
+ j(f, {
152
+ icon: O,
149
153
  size: "text-xs"
150
154
  })
151
155
  ]),
152
156
  _: 1
153
157
  }, 8, ["onClick", "disabled"])
154
158
  ])) : n("", !0),
155
- e.noArrows ? n("", !0) : (r(), l(j, { key: 4 }, [
156
- e.controlVariant === "default" ? (r(), l("div", _, [
159
+ e.noArrows ? n("", !0) : (s(), l(D, { key: 4 }, [
160
+ e.controlVariant === "default" ? (s(), l("div", ee, [
157
161
  d("button", {
158
162
  type: "button",
159
163
  class: "flex items-center border-l border-slate-600 p-3 justify-center text-black dark:text-white hover:text-black/80 dark:hover:text-white/80 disabled:opacity-50 cursor-pointer hover:opacity-80",
160
- onClick: s[5] || (s[5] = (...t) => o(i) && o(i)(...t)),
164
+ onClick: r[6] || (r[6] = (...t) => o(i) && o(i)(...t)),
161
165
  disabled: e.disabled || e.readonly
162
- }, " ", 8, ee),
166
+ }, "▲", 8, te),
163
167
  d("button", {
164
168
  type: "button",
165
169
  class: "flex items-center border-l border-slate-600 p-3 justify-center text-black dark:text-white hover:text-black/80 dark:hover:text-white/80 disabled:opacity-50 cursor-pointer hover:opacity-80",
166
- onClick: s[6] || (s[6] = (...t) => o(a) && o(a)(...t)),
170
+ onClick: r[7] || (r[7] = (...t) => o(a) && o(a)(...t)),
167
171
  disabled: e.disabled || e.readonly
168
- }, " ", 8, te)
172
+ }, "▼", 8, oe)
169
173
  ])) : n("", !0),
170
- e.controlVariant === "stacked" ? (r(), l("div", oe, [
174
+ e.controlVariant === "stacked" ? (s(), l("div", re, [
171
175
  d("div", {
172
176
  class: "border-b border-slate-600 pb-1 px-3 flex hover:opacity-80 cursor-pointer",
173
- onClick: s[7] || (s[7] = (...t) => o(i) && o(i)(...t))
177
+ onClick: r[8] || (r[8] = (...t) => o(i) && o(i)(...t))
174
178
  }, [
175
179
  d("button", {
176
180
  type: "button",
177
181
  class: "text-xs text-black dark:text-white hover:text-black/80 dark:hover:text-white/80 disabled:opacity-50 cursor-pointer",
178
182
  disabled: e.disabled || e.readonly
179
- }, "▲", 8, re)
183
+ }, "▲", 8, se)
180
184
  ]),
181
185
  d("div", {
182
186
  class: "border-t border-slate-600 pt-1 px-3 flex hover:opacity-80 cursor-pointer",
183
- onClick: s[8] || (s[8] = (...t) => o(a) && o(a)(...t))
187
+ onClick: r[9] || (r[9] = (...t) => o(a) && o(a)(...t))
184
188
  }, [
185
189
  d("button", {
186
190
  type: "button",
187
191
  class: "text-xs text-black dark:text-white hover:text-black/80 dark:hover:text-white/80 disabled:opacity-50 cursor-pointer",
188
192
  disabled: e.disabled || e.readonly
189
- }, "▼", 8, se)
193
+ }, "▼", 8, le)
190
194
  ])
191
195
  ])) : n("", !0)
192
196
  ], 64)),
193
- e.appendIcon || A ? (r(), l("div", le, [
194
- e.appendIcon ? (r(), I(f, {
197
+ e.appendIcon || B ? (s(), l("div", ne, [
198
+ e.appendIcon ? (s(), x(f, {
195
199
  key: 0,
196
200
  icon: e.appendIcon
197
- }, null, 8, ["icon"])) : x(e.$slots, "append-icon", { key: 1 })
201
+ }, null, 8, ["icon"])) : V(e.$slots, "append-icon", { key: 1 })
198
202
  ])) : n("", !0),
199
- !e.noArrows && e.controlVariant === "split" ? (r(), l("div", ne, [
203
+ !e.noArrows && e.controlVariant === "split" ? (s(), l("div", de, [
200
204
  d("button", {
201
205
  type: "button",
202
206
  class: "p-3 text-lg border-l border-slate-600 text-black dark:text-white disabled:opacity-50 cursor-pointer hover:opacity-80",
203
- onClick: s[9] || (s[9] = (...t) => o(i) && o(i)(...t)),
207
+ onClick: r[10] || (r[10] = (...t) => o(i) && o(i)(...t)),
204
208
  disabled: e.disabled || e.readonly
205
- }, "+", 8, de)
209
+ }, "+", 8, ie)
206
210
  ])) : n("", !0),
207
- e.suffix ? (r(), l("div", ie, u(e.suffix), 1)) : n("", !0)
211
+ e.suffix ? (s(), l("div", ae, u(e.suffix), 1)) : n("", !0)
208
212
  ], 2),
209
- e.hideDetails ? n("", !0) : (r(), l("div", ae, [
210
- e.error || e.errorMessages ? (r(), l("div", ue, [
211
- Array.isArray(e.errorMessages) ? (r(), l("div", pe, [
212
- (r(!0), l(j, null, L(e.errorMessages, (t, $) => (r(), l("div", { key: $ }, u(t), 1))), 128))
213
- ])) : typeof e.errorMessages == "string" ? (r(), l("div", be, u(e.errorMessages), 1)) : n("", !0)
214
- ])) : e.hint && (e.persistentHint || o(w)) ? (r(), l("div", ce, u(e.hint), 1)) : n("", !0)
213
+ e.hideDetails ? n("", !0) : (s(), l("div", ue, [
214
+ e.error || e.errorMessages ? (s(), l("div", pe, [
215
+ Array.isArray(e.errorMessages) ? (s(), l("div", be, [
216
+ (s(!0), l(D, null, T(e.errorMessages, (t, z) => (s(), l("div", { key: z }, u(t), 1))), 128))
217
+ ])) : typeof e.errorMessages == "string" ? (s(), l("div", ye, u(e.errorMessages), 1)) : n("", !0)
218
+ ])) : e.hint && (e.persistentHint || o(w)) ? (s(), l("div", ce, u(e.hint), 1)) : n("", !0)
215
219
  ]))
216
220
  ], 16)
217
221
  ], 512));
218
222
  }
219
223
  };
220
224
  export {
221
- we as default
225
+ ge as default
222
226
  };
@@ -43,7 +43,12 @@ const e = {
43
43
  locale: { type: String, default: "es-AR" },
44
44
  separator: { type: String, default: "," },
45
45
  useGrouping: { type: Boolean, default: !0 },
46
- precision: { type: [Number, String], default: 2 }
46
+ precision: { type: [Number, String], default: 2 },
47
+ formatMode: {
48
+ type: String,
49
+ default: "natural"
50
+ // 'bank' | 'natural'
51
+ }
47
52
  };
48
53
  export {
49
54
  e as KunNumberFieldProps
@@ -1,158 +1,238 @@
1
- import { ref as w, computed as q, watch as G, nextTick as V } from "vue";
2
- import { format as h, clamp as x, toRawNumberString as D, fromRawString as C } from "./numberFormatUtils.js";
3
- function W(i, s) {
4
- const l = w(""), a = w(null), K = w(null), R = w(!1), o = w(0);
5
- let t = "";
6
- const L = q(() => {
7
- const e = Number(i.precision);
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);
5
+ let a = "";
6
+ const C = Y(() => {
7
+ const e = Number(n.precision);
8
8
  return e > 0 ? e + 1 : 1;
9
9
  });
10
- function N(e) {
11
- return Number(i.precision) === 0 ? e === "" ? "0" : e.replace(/^0+(\d)/, "$1") : e.padStart(L.value, "0");
12
- }
13
- G(
14
- [() => i.modelValue, () => i.precision],
15
- ([e, n], [r, u]) => {
16
- if (e == null || isNaN(e))
17
- l.value = h(0, { ...i, precision: n }), t = "0".repeat(Number(n) + 1);
18
- else {
19
- const v = parseFloat(e), g = x(v, i.min, i.max);
20
- t = D(g, Number(n)), t.length < Number(n) + 1 && (t = t.padStart(Number(n) + 1, "0")), l.value = h(g, { ...i, precision: n });
21
- }
22
- },
23
- { immediate: !0 }
24
- );
25
- function k(e) {
26
- const { key: n, target: r } = e, u = /^[0-9]$/.test(n), v = n === "Backspace", g = n === "Delete", d = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(n), b = e.ctrlKey || e.metaKey, m = n === "Home", U = n === "End";
27
- if (n === "Tab")
28
- return;
29
- if (m) {
30
- V(() => {
31
- if (!a.value) return;
32
- const S = l.value.search(/\d/);
33
- a.value.setSelectionRange(S, S);
34
- });
10
+ function K(e) {
11
+ const t = c.value;
12
+ 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);
35
23
  return;
36
24
  }
37
- if (U) {
38
- V(() => {
39
- if (!a.value) return;
40
- const c = l.value;
41
- a.value.setSelectionRange(c.length, c.length);
42
- });
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 : "");
28
+ }
29
+ if (u.includes(",")) {
30
+ const [r, f = ""] = u.split(","), m = f.slice(0, i);
31
+ u = r + (m.length ? "," + m : ",");
32
+ }
33
+ l.value = u, h(L), h(() => {
34
+ const r = s;
35
+ t.setSelectionRange(r, r);
36
+ }), o("input", u);
37
+ }
38
+ function L() {
39
+ c.value && (c.value.value = l.value);
40
+ }
41
+ function A(e) {
42
+ if (k.value = !0, !c.value) return;
43
+ const t = parseFloat(n.modelValue ?? 0), u = Number(n.precision);
44
+ if (isNaN(t)) {
45
+ l.value = "", o("focus");
43
46
  return;
44
47
  }
45
- if (d || b) return;
46
- const T = $(l.value, r.selectionStart);
47
- e.preventDefault();
48
- const F = Number(i.precision) + 1;
49
- for (; t.length < F; )
50
- t = "0" + t;
51
- const f = y(l.value, T);
52
- if (u)
53
- t = t.substring(0, f) + n + t.substring(f), o.value = f + 1;
54
- else if (v && T > 0) {
55
- const c = y(l.value, T), S = c - 1;
56
- if (t.length <= Number(i.precision) + 1) {
57
- const j = Math.max(0, c - 1);
58
- t = t.slice(0, j) + t.slice(c), t = N(t), o.value = c, A();
59
- return;
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;
56
+ 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
+ }
61
+ } catch {
60
62
  }
61
- c > 0 && (t = t.slice(0, S) + t.slice(c), t = N(t), o.value = S);
62
- } else g && T < l.value.length && f < t.length && (t = t.substring(0, f) + t.substring(f + 1), o.value = f);
63
- for (t = N(t); t.length < F; )
64
- t = "0" + t;
65
- A();
66
- }
67
- function y(e, n) {
68
- let r = 0;
69
- for (let u = 0; u < n; u++)
70
- /\d/.test(e[u]) && r++;
71
- return r;
72
- }
73
- function E(e, n) {
74
- let r = 0;
75
- for (let u = 0; u < e.length; u++)
76
- if (/\d/.test(e[u])) {
77
- if (r === n)
78
- return u;
79
- r++;
63
+ }), o("focus");
64
+ }
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");
71
+ }
72
+ 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++;
80
87
  }
81
- for (let u = e.length - 1; u >= 0; u--)
82
- if (/\d/.test(e[u]))
83
- return u + 1;
88
+ for (let i = e.length - 1; i >= 0; i--)
89
+ if (/\d/.test(e[i])) return i + 1;
84
90
  return e.length;
85
91
  }
86
- function $(e, n) {
87
- for (; n < e.length && !/\d/.test(e[n]); )
88
- n++;
89
- if (n >= e.length)
90
- for (n = e.length; n > 0 && !/\d/.test(e[n - 1]); )
91
- n--;
92
- const r = e.search(/\d/);
93
- return n < r && (n = r), n;
94
- }
95
- function A() {
96
- const e = Number(i.precision) + 1;
97
- t.padStart(e, "0");
98
- 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)), v = `${r}.${u}`, g = parseFloat(v), d = x(g, i.min, i.max);
99
- t = D(d, Number(i.precision)), l.value = h(d, i), s("update:modelValue", d), s("input", d), V(() => {
100
- if (a.value)
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;
98
+ }
99
+ function R() {
100
+ const e = Number(n.precision) + 1;
101
+ 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)
101
105
  try {
102
- const b = l.value;
103
- let m = E(b, o.value);
104
- for (; m < b.length && !/\d/.test(b[m]); )
105
- m++;
106
- a.value.setSelectionRange(m, m);
106
+ const m = l.value;
107
+ let N = $(m, b.value);
108
+ for (; N < m.length && !/\d/.test(m[N]); ) N++;
109
+ c.value.setSelectionRange(N, N);
107
110
  } catch {
108
- a.value.setSelectionRange(l.value.length, l.value.length);
111
+ c.value.setSelectionRange(l.value.length, l.value.length);
109
112
  }
110
113
  });
111
114
  }
112
- function B() {
113
- R.value = !1, t = N(t);
114
- const e = C(t, Number(i.precision)), n = x(e, i.min, i.max);
115
- t = D(n, Number(i.precision)), t = N(t), l.value = h(n, i), s("update:modelValue", n), s("blur");
116
- }
117
- function M(e) {
118
- R.value = !0, V(() => {
119
- var r;
120
- if (!a.value) return;
121
- if ((e == null ? void 0 : e.relatedTarget) !== void 0 || ((r = e == null ? void 0 : e.sourceCapabilities) == null ? void 0 : r.firesTouchEvents) === !1) {
122
- const u = l.value.length;
123
- a.value.setSelectionRange(u, u), o.value = l.value.replace(/\D/g, "").length;
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;
124
127
  } else {
125
- const u = a.value.selectionStart || 0;
126
- o.value = y(l.value, u);
128
+ const i = c.value.selectionStart || 0;
129
+ b.value = D(l.value, i);
127
130
  }
128
- }), s("focus");
131
+ }), o("focus");
129
132
  }
130
- function H() {
131
- let e = C(t, Number(i.precision)) || 0;
132
- e = x(e + Number(i.step), i.min, i.max), t = D(e, Number(i.precision)), l.value = h(e, i), s("update:modelValue", e);
133
+ function j(e) {
134
+ var t;
135
+ (t = e.preventDefault) == null || t.call(e);
133
136
  }
134
- function I() {
135
- let e = C(t, Number(i.precision)) || 0;
136
- e = x(e - Number(i.step), i.min, i.max), t = D(e, Number(i.precision)), l.value = h(e, i), s("update:modelValue", e);
137
+ function z(e) {
138
+ 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";
140
+ if (t === "Tab") return;
141
+ if (N) {
142
+ h(() => {
143
+ if (!c.value) return;
144
+ const F = l.value.search(/\d/);
145
+ c.value.setSelectionRange(F, F);
146
+ });
147
+ return;
148
+ }
149
+ if (Q) {
150
+ h(() => {
151
+ if (!c.value) return;
152
+ const g = l.value;
153
+ c.value.setSelectionRange(g.length, g.length);
154
+ });
155
+ return;
156
+ }
157
+ if (f || m) return;
158
+ const W = (u == null ? void 0 : u.selectionStart) ?? 0, V = E(l.value, W);
159
+ 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;
171
+ }
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);
175
+ else return;
176
+ for (a = x(a); a.length < T; ) a = "0" + a;
177
+ R();
178
+ }
179
+ function U() {
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));
182
+ }
183
+ function Z() {
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));
186
+ }
187
+ function q() {
188
+ n.formatMode === "bank" ? (a = "0".repeat(Number(n.precision) + 1), b.value = Number(n.precision) + 1, R(), h(() => {
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(() => {
192
+ var e, t;
193
+ return (t = (e = c.value) == null ? void 0 : e.focus) == null ? void 0 : t.call(e);
194
+ }));
195
+ }
196
+ _(
197
+ [() => n.modelValue, () => n.precision, () => n.formatMode],
198
+ ([e, t, u]) => {
199
+ if (u !== "bank") {
200
+ l.value = d(e ?? 0, { ...n, precision: t });
201
+ return;
202
+ }
203
+ if (e == null || isNaN(e))
204
+ l.value = d(0, { ...n, precision: t }), a = "0".repeat(Number(t) + 1);
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 });
208
+ }
209
+ },
210
+ { immediate: !0 }
211
+ );
212
+ function G(e) {
213
+ return n.formatMode !== "bank" ? K() : j(e);
214
+ }
215
+ function J(e) {
216
+ return n.formatMode !== "bank" ? A(e) : H(e);
137
217
  }
138
- function z() {
139
- var e;
140
- t = "0".repeat(Number(i.precision) + 1), o.value = Number(i.precision) + 1, A(), (e = a.value) == null || e.focus();
218
+ function O(e) {
219
+ return n.formatMode !== "bank" ? I() : P();
141
220
  }
142
221
  return {
143
222
  inputValue: l,
144
- numberInput: a,
145
- rootRef: K,
146
- validateKey: k,
147
- handleFocus: M,
148
- handleBlur: B,
149
- onIncrement: H,
150
- onDecrement: I,
151
- onClear: z,
152
- isActive: R,
153
- focus: R
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
154
234
  };
155
235
  }
156
236
  export {
157
- W as useKunNumberField
237
+ ne as useKunNumberField
158
238
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adverich-kun-ui",
3
- "version": "0.1.521",
3
+ "version": "0.1.522",
4
4
  "type": "module",
5
5
  "description": "Una librería de componentes Vue.js con Tailwind CSS",
6
6
  "main": "dist/index.js",