@manik02/vue3-timepicker 0.2.2 → 0.4.0

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,119 +1,159 @@
1
- import { defineComponent as ce, ref as E, onMounted as le, watch as D, createElementBlock as W, openBlock as K, createElementVNode as X, Fragment as Ae, renderList as xe, normalizeClass as re, toDisplayString as Ve, nextTick as ve, computed as h, onBeforeUnmount as pe, createCommentVNode as ae, createVNode as ue, createBlock as de, unref as H, normalizeStyle as oe } from "vue";
2
- const Pe = { class: "timepicker-dropdown" }, Ie = ["tabindex", "onClick", "onMousemove"], ne = /* @__PURE__ */ ce({
1
+ import { defineComponent as he, ref as N, onMounted as de, onBeforeUnmount as ce, createElementBlock as Y, openBlock as W, normalizeClass as me, createElementVNode as J, Fragment as xe, renderList as we, toDisplayString as Pe, nextTick as ge, computed as p, watch as L, createCommentVNode as Z, createVNode as fe, createBlock as ve, normalizeStyle as ue, unref as R } from "vue";
2
+ const De = ["tabindex", "onClick", "onMousemove"], ne = /* @__PURE__ */ he({
3
3
  __name: "TimeColumn",
4
4
  props: {
5
5
  items: {},
6
6
  activeIndex: {}
7
7
  },
8
8
  emits: ["update:activeIndex", "select"],
9
- setup(t, { emit: o }) {
10
- const l = t, e = o, g = E(null);
11
- function r() {
12
- ve(() => {
13
- const S = g.value;
14
- if (!S) return;
15
- const c = S.querySelector(
9
+ setup(n, { emit: o }) {
10
+ const l = n, i = o, f = N(null), g = N(!1);
11
+ let u = null;
12
+ function P(m) {
13
+ const S = Array.from(m.querySelectorAll(".timepicker-option"));
14
+ if (!S.length) return 0;
15
+ const T = m.scrollTop + m.clientHeight / 2;
16
+ let V = 0, w = Number.POSITIVE_INFINITY;
17
+ for (let A = 0; A < S.length; A++) {
18
+ const C = S[A], r = C.offsetTop + C.offsetHeight / 2, d = Math.abs(r - T);
19
+ d < w && (w = d, V = A);
20
+ }
21
+ return V;
22
+ }
23
+ function D(m) {
24
+ if (!l.items.length) return 0;
25
+ if (!l.items[m]?.disabled) return m;
26
+ for (let S = 1; S < l.items.length; S++) {
27
+ const T = m - S, V = m + S;
28
+ if (T >= 0 && !l.items[T]?.disabled) return T;
29
+ if (V < l.items.length && !l.items[V]?.disabled) return V;
30
+ }
31
+ return m;
32
+ }
33
+ function I() {
34
+ ge(() => {
35
+ const m = f.value;
36
+ if (!m) return;
37
+ const S = m.querySelector(
16
38
  ".timepicker-option--active"
17
39
  );
18
- if (c) {
19
- const V = S.clientHeight, M = c.offsetTop, A = c.offsetHeight;
20
- S.scrollTop = M - V / 2 + A / 2;
40
+ if (S) {
41
+ const T = m.clientHeight, V = S.offsetTop, w = S.offsetHeight, A = V - T / 2 + w / 2;
42
+ g.value = !0, m.scrollTo({ top: A, behavior: "auto" }), u && clearTimeout(u), u = setTimeout(() => {
43
+ g.value = !1;
44
+ }, 70);
21
45
  }
22
46
  });
23
47
  }
24
- le(r), D(() => l.activeIndex, r);
25
- function y(S) {
26
- e("update:activeIndex", S), e("select", l.items[S]?.value);
48
+ function F() {
49
+ const m = f.value;
50
+ if (!m || g.value) return;
51
+ const S = P(m), T = D(S);
52
+ l.items[T]?.disabled || (E.value = T);
27
53
  }
28
- const x = E(l.activeIndex ?? 0);
29
- return (S, c) => (K(), W("div", Pe, [
30
- X("div", {
54
+ de(I), ce(() => {
55
+ u && clearTimeout(u);
56
+ });
57
+ function y(m) {
58
+ i("update:activeIndex", m), i("select", l.items[m]?.value);
59
+ }
60
+ function M(m) {
61
+ y(m);
62
+ }
63
+ const E = N(l.activeIndex ?? 0);
64
+ return (m, S) => (W(), Y("div", {
65
+ class: me(["timepicker-dropdown", {
66
+ "timepicker-dropdown--short": m.items.length <= 3
67
+ }])
68
+ }, [
69
+ J("div", {
31
70
  ref_key: "menu",
32
- ref: g,
71
+ ref: f,
33
72
  class: "timepicker-dropdown__panel",
34
73
  role: "listbox",
35
- tabindex: "-1"
74
+ tabindex: "-1",
75
+ onScroll: F
36
76
  }, [
37
- (K(!0), W(Ae, null, xe(S.items, (V, M) => (K(), W("div", {
38
- key: V.key,
39
- class: re(["timepicker-option", {
40
- "timepicker-option--active": M === S.activeIndex,
41
- "timepicker-option--disabled": V.disabled,
42
- "timepicker-option--focused": M === x.value
77
+ (W(!0), Y(xe, null, we(m.items, (T, V) => (W(), Y("div", {
78
+ key: T.key,
79
+ class: me(["timepicker-option", {
80
+ "timepicker-option--active": V === m.activeIndex,
81
+ "timepicker-option--disabled": T.disabled,
82
+ "timepicker-option--focused": V === E.value
43
83
  }]),
44
84
  role: "option",
45
- tabindex: V.disabled ? -1 : 0,
46
- onClick: (A) => !V.disabled && y(M),
47
- onMousemove: (A) => !V.disabled && (x.value = M)
48
- }, Ve(V.text), 43, Ie))), 128))
49
- ], 512)
50
- ]));
85
+ tabindex: T.disabled ? -1 : 0,
86
+ onClick: (w) => !T.disabled && M(V),
87
+ onMousemove: (w) => !T.disabled && (E.value = V)
88
+ }, Pe(T.text), 43, De))), 128))
89
+ ], 544)
90
+ ], 2));
51
91
  }
52
92
  });
53
- function he(t) {
54
- return t.h * 3600 + t.m * 60 + t.s;
93
+ function ye(n) {
94
+ return n.h * 3600 + n.m * 60 + n.s;
55
95
  }
56
- function ye(t) {
57
- return /(a|A|p|P)/.test(t);
96
+ function Ae(n) {
97
+ return /(a|A|p|P)/.test(n);
58
98
  }
59
- function we(t) {
60
- return /(p|P)/.test(t);
99
+ function Ee(n) {
100
+ return /(p|P)/.test(n);
61
101
  }
62
- function me(t) {
63
- return /k{1,2}/.test(t);
102
+ function pe(n) {
103
+ return /k{1,2}/.test(n);
64
104
  }
65
- function z(t, o) {
66
- if (!t || typeof t != "string") return { h: 0, m: 0, s: 0 };
67
- const l = t.match(/\d+/g) || [];
68
- let e = l[0] !== void 0 ? +l[0] : 0;
69
- const g = +l[1] || 0, r = +l[2] || 0;
70
- return { h: e, m: g, s: r };
105
+ function z(n, o) {
106
+ if (!n || typeof n != "string") return { h: 0, m: 0, s: 0 };
107
+ const l = n.match(/\d+/g) || [];
108
+ let i = l[0] !== void 0 ? +l[0] : 0;
109
+ const f = +l[1] || 0, g = +l[2] || 0;
110
+ return { h: i, m: f, s: g };
71
111
  }
72
- function De(t) {
73
- const o = t % 12;
112
+ function He(n) {
113
+ const o = n % 12;
74
114
  return o === 0 ? 12 : o;
75
115
  }
76
- function ge(t, o) {
77
- return o ? t % 12 + 12 : t % 12;
116
+ function Te(n, o) {
117
+ return o ? n % 12 + 12 : n % 12;
78
118
  }
79
- function Ee(t) {
80
- return /(s|ss)/.test(t);
119
+ function Ne(n) {
120
+ return /(s|ss)/.test(n);
81
121
  }
82
- function Z(t, o) {
83
- let { h: l, m: e, s: g } = o;
84
- const r = ye(t), y = l >= 12 ? "PM" : "AM";
85
- r && (l = De(l));
86
- const x = l === 0 ? 24 : l, S = {
122
+ function ie(n, o) {
123
+ let { h: l, m: i, s: f } = o;
124
+ const g = Ae(n), u = l >= 12 ? "PM" : "AM";
125
+ g && (l = He(l));
126
+ const P = l === 0 ? 24 : l, D = {
87
127
  HH: String(l).padStart(2, "0"),
88
128
  H: String(l),
89
129
  hh: String(l).padStart(2, "0"),
90
130
  h: String(l),
91
- kk: String(x).padStart(2, "0"),
92
- k: String(x),
93
- mm: String(e).padStart(2, "0"),
94
- m: String(e),
95
- ss: String(g).padStart(2, "0"),
96
- s: String(g),
97
- A: y,
98
- a: y.toLowerCase(),
99
- P: y,
100
- p: y.toLowerCase()
131
+ kk: String(P).padStart(2, "0"),
132
+ k: String(P),
133
+ mm: String(i).padStart(2, "0"),
134
+ m: String(i),
135
+ ss: String(f).padStart(2, "0"),
136
+ s: String(f),
137
+ A: u,
138
+ a: u.toLowerCase(),
139
+ P: u,
140
+ p: u.toLowerCase()
101
141
  };
102
- return t.replace(/HH|hh|kk|mm|ss|H|h|k|m|s|A|a|P|p/g, (c) => S[c] ?? c);
142
+ return n.replace(/HH|hh|kk|mm|ss|H|h|k|m|s|A|a|P|p/g, (I) => D[I] ?? I);
103
143
  }
104
- function O(t, o) {
105
- return he(t) - he(o);
144
+ function U(n, o) {
145
+ return ye(n) - ye(o);
106
146
  }
107
- function He(t, o, l) {
108
- return o && O(t, o) < 0 ? { ...o } : l && O(t, l) > 0 ? { ...l } : { ...t };
147
+ function $e(n, o, l) {
148
+ return o && U(n, o) < 0 ? { ...o } : l && U(n, l) > 0 ? { ...l } : { ...n };
109
149
  }
110
- function Te(t, o, l) {
111
- return !(o && O(t, o) < 0 || l && O(t, l) > 0);
150
+ function Me(n, o, l) {
151
+ return !(o && U(n, o) < 0 || l && U(n, l) > 0);
112
152
  }
113
- function Se(t, o) {
114
- return o.some(([l, e]) => O(t, l) >= 0 && O(t, e) <= 0);
153
+ function Ie(n, o) {
154
+ return o.some(([l, i]) => U(n, l) >= 0 && U(n, i) <= 0);
115
155
  }
116
- const be = /* @__PURE__ */ ce({
156
+ const ke = /* @__PURE__ */ he({
117
157
  __name: "TimeSelection",
118
158
  props: {
119
159
  open: { type: Boolean },
@@ -128,217 +168,234 @@ const be = /* @__PURE__ */ ce({
128
168
  secondStep: {}
129
169
  },
130
170
  emits: ["update:initTime", "open", "close", "update:open"],
131
- setup(t, { emit: o }) {
132
- const l = h(() => ye(r.format)), e = h(() => Ee(r.format)), g = h(() => me(r.format)), r = t, y = o, x = h({
133
- get: () => r.open ?? !1,
134
- set: (n) => {
135
- const p = r.open ?? !1;
136
- n !== p && (y("update:open", n), y(n ? "open" : "close"));
171
+ setup(n, { emit: o }) {
172
+ function l(a) {
173
+ return Math.max(1, a ?? 1);
174
+ }
175
+ const i = p(() => Ae(u.format)), f = p(() => Ne(u.format)), g = p(() => pe(u.format)), u = n, P = o, D = p({
176
+ get: () => u.open ?? !1,
177
+ set: (a) => {
178
+ const e = u.open ?? !1;
179
+ a !== e && (P("update:open", a), P(a ? "open" : "close"));
137
180
  }
138
- }), S = E(null);
139
- function c(n) {
140
- if (!x.value) return;
141
- const p = n.target;
142
- S.value && !S.value.contains(p) && (x.value = !1);
143
- }
144
- le(() => document.addEventListener("mousedown", c)), pe(
145
- () => document.removeEventListener("mousedown", c)
181
+ }), I = N(null);
182
+ function F(a) {
183
+ if (!D.value) return;
184
+ const e = a.target;
185
+ I.value && !I.value.contains(e) && (D.value = !1);
186
+ }
187
+ de(() => document.addEventListener("mousedown", F)), ce(
188
+ () => document.removeEventListener("mousedown", F)
146
189
  );
147
- function V(n) {
148
- n.key === "Escape" && x.value && (x.value = !1);
149
- }
150
- le(() => document.addEventListener("keydown", V)), pe(() => document.removeEventListener("keydown", V));
151
- const M = E(Math.floor(r.initTime.h / r.hourStep) || 0), A = E(Math.floor(r.initTime.m / r.minuteStep) || 0), L = E(Math.floor(r.initTime.s / r.secondStep) || 0);
152
- D(
153
- () => r.initTime,
154
- (n) => {
155
- const p = Math.max(1, r.hourStep), k = Math.max(1, r.minuteStep), T = Math.max(1, r.secondStep);
156
- let w = n.h;
157
- l.value ? (B.value = n.h >= 12 ? 1 : 0, w = n.h % 12) : g.value && n.h === 0 && (w = 24), M.value = Math.floor(w / p), A.value = Math.floor(n.m / k), L.value = Math.floor(n.s / T);
190
+ function y(a) {
191
+ a.key === "Escape" && D.value && (D.value = !1);
192
+ }
193
+ de(() => document.addEventListener("keydown", y)), ce(() => document.removeEventListener("keydown", y));
194
+ const M = N(Math.floor(u.initTime.h / u.hourStep) || 0), E = N(Math.floor(u.initTime.m / u.minuteStep) || 0), m = N(Math.floor(u.initTime.s / u.secondStep) || 0);
195
+ L(
196
+ () => u.initTime,
197
+ (a) => {
198
+ const e = l(u.hourStep), t = l(u.minuteStep), s = l(u.secondStep);
199
+ let h = a.h;
200
+ i.value ? (w.value = a.h >= 12 ? 1 : 0, h = a.h % 12) : g.value && a.h === 0 && (h = 24), M.value = Math.floor(h / e), E.value = Math.floor(a.m / t), m.value = Math.floor(a.s / s);
158
201
  }
159
202
  );
160
- function R(n, p) {
161
- const k = [];
162
- for (let T = 0; T < n; T += Math.max(1, p))
163
- k.push({ key: T, value: T, text: String(T).padStart(2, "0") });
164
- return k;
165
- }
166
- function q(n, p) {
167
- const k = Math.max(1, p), T = [];
168
- for (let w = 0; w < 12; w += k) {
169
- const se = w === 0 ? 12 : w, fe = n ? w === 0 ? 12 : w + 12 : w;
170
- T.push({ key: fe, value: fe, text: String(se).padStart(2, "0") });
203
+ function S(a, e) {
204
+ const t = [];
205
+ for (let s = 0; s < a; s += l(e))
206
+ t.push({ key: s, value: s, text: String(s).padStart(2, "0") });
207
+ return t;
208
+ }
209
+ function T(a, e) {
210
+ const t = l(e), s = [];
211
+ for (let h = 0; h < 12; h += t) {
212
+ const x = h === 0 ? 12 : h, be = a ? h === 0 ? 12 : h + 12 : h;
213
+ s.push({ key: be, value: be, text: String(x).padStart(2, "0") });
171
214
  }
172
- return T;
215
+ return s;
173
216
  }
174
- function U(n) {
175
- const p = Math.max(1, n), k = [];
176
- for (let T = 0; T < 24; T += p) {
177
- const w = T === 0 ? 24 : T;
178
- k.push({ key: T, value: T, text: String(w).padStart(2, "0") });
217
+ function V(a) {
218
+ const e = l(a), t = [];
219
+ for (let s = 0; s < 24; s += e) {
220
+ const h = s === 0 ? 24 : s;
221
+ t.push({ key: s, value: s, text: String(h).padStart(2, "0") });
179
222
  }
180
- return k;
181
- }
182
- const B = E(we(r.format) ? 1 : 0), _ = h(() => {
183
- if (!l.value)
184
- return g.value ? U(r.hourStep) : R(24, r.hourStep);
185
- const n = B.value === 1;
186
- return q(n, r.hourStep);
187
- }), N = h(() => R(60, r.minuteStep)), s = h(() => R(60, r.secondStep)), u = h(() => /\s[ap]$/.test(r.format)), d = h(() => {
188
- const n = u.value ? "am" : "AM", p = u.value ? "pm" : "PM";
223
+ return t;
224
+ }
225
+ const w = N(Ee(u.format) ? 1 : 0), A = p(() => {
226
+ if (!i.value)
227
+ return g.value ? V(u.hourStep) : S(24, u.hourStep);
228
+ const a = w.value === 1;
229
+ return T(a, u.hourStep);
230
+ }), C = p(() => S(60, u.minuteStep)), r = p(() => S(60, u.secondStep)), d = p(() => /\s[ap]$/.test(u.format)), c = p(() => {
231
+ const a = d.value ? "am" : "AM", e = d.value ? "pm" : "PM";
189
232
  return [
190
- { key: "AM", value: "AM", text: n },
191
- { key: "PM", value: "PM", text: p }
233
+ { key: "AM", value: "AM", text: a },
234
+ { key: "PM", value: "PM", text: e }
192
235
  ];
193
- }), v = h(
194
- () => N.value.map((n) => Number(n.value ?? 0))
195
- ), f = h(() => e.value ? s.value.map((n) => Number(n.value ?? 0)) : [0]);
196
- function b(n) {
197
- return Number(n.value ?? 0);
198
- }
199
- function C(n) {
200
- const p = n.findIndex((k) => !k.disabled);
201
- return p >= 0 ? p : 0;
202
- }
203
- function P(n) {
204
- return !(!Te(n, r.minTime, r.maxTime) || Se(n, r.disabledRanges ?? []) || r.isTimeDisabled?.(n));
205
- }
206
- const Y = h(() => _.value.map((n) => {
207
- const p = b(n), k = v.value.some(
208
- (T) => f.value.some(
209
- (w) => P({ h: p, m: T, s: w })
236
+ }), b = p(
237
+ () => C.value.map((a) => Number(a.value ?? 0))
238
+ ), v = p(() => f.value ? r.value.map((a) => Number(a.value ?? 0)) : [0]);
239
+ function k(a) {
240
+ return Number(a.value ?? 0);
241
+ }
242
+ function K(a) {
243
+ const e = a.findIndex((t) => !t.disabled);
244
+ return e >= 0 ? e : 0;
245
+ }
246
+ function G(a) {
247
+ return !(!Me(a, u.minTime, u.maxTime) || Ie(a, u.disabledRanges ?? []) || u.isTimeDisabled?.(a));
248
+ }
249
+ const B = p(() => A.value.map((a) => {
250
+ const e = k(a), t = b.value.some(
251
+ (s) => v.value.some(
252
+ (h) => G({ h: e, m: s, s: h })
210
253
  )
211
254
  );
212
255
  return {
213
- ...n,
214
- disabled: !k
256
+ ...a,
257
+ disabled: !t
215
258
  };
216
- })), $ = h(() => {
217
- const n = Number(_.value[M.value]?.value ?? 0);
218
- return N.value.map((p) => {
219
- const k = Number(p.value ?? 0), T = f.value.some(
220
- (w) => P({ h: n, m: k, s: w })
259
+ })), q = p(() => {
260
+ const a = Number(A.value[M.value]?.value ?? 0);
261
+ return C.value.map((e) => {
262
+ const t = Number(e.value ?? 0), s = v.value.some(
263
+ (h) => G({ h: a, m: t, s: h })
221
264
  );
222
265
  return {
223
- ...p,
224
- disabled: !T
266
+ ...e,
267
+ disabled: !s
225
268
  };
226
269
  });
227
- }), ee = h(() => {
228
- const n = Number(_.value[M.value]?.value ?? 0), p = Number(
229
- N.value[A.value]?.value ?? 0
270
+ }), O = p(() => {
271
+ const a = Number(A.value[M.value]?.value ?? 0), e = Number(
272
+ C.value[E.value]?.value ?? 0
230
273
  );
231
- return s.value.map((k) => {
232
- const T = Number(k.value ?? 0);
274
+ return r.value.map((t) => {
275
+ const s = Number(t.value ?? 0);
233
276
  return {
234
- ...k,
235
- disabled: !P({
236
- h: n,
237
- m: p,
238
- s: T
277
+ ...t,
278
+ disabled: !G({
279
+ h: a,
280
+ m: e,
281
+ s
239
282
  })
240
283
  };
241
284
  });
242
- }), J = h(() => {
243
- if (!l.value) return d.value;
244
- const n = Number(N.value[A.value]?.value ?? 0), p = e.value ? Number(s.value[L.value]?.value ?? 0) : 0;
245
- return d.value.map((k) => {
246
- const T = k.value === "PM", w = q(T, r.hourStep).some(
247
- (se) => P({
248
- h: Number(se.value ?? 0),
249
- m: n,
250
- s: p
285
+ }), ee = p(() => {
286
+ if (!i.value) return c.value;
287
+ const a = Number(C.value[E.value]?.value ?? 0), e = f.value ? Number(r.value[m.value]?.value ?? 0) : 0;
288
+ return c.value.map((t) => {
289
+ const s = t.value === "PM", h = T(s, u.hourStep).some(
290
+ (x) => G({
291
+ h: Number(x.value ?? 0),
292
+ m: a,
293
+ s: e
251
294
  })
252
295
  );
253
296
  return {
254
- ...k,
255
- disabled: !w
297
+ ...t,
298
+ disabled: !h
256
299
  };
257
300
  });
258
- }), te = h(() => B.value === 1 ? "PM" : "AM"), ie = h(() => {
259
- const n = Number(_.value[M.value]?.value ?? 0);
260
- return l.value ? te.value === "PM" ? ge(n, !0) : ge(n, !1) : g.value && n === 24 ? 0 : n;
261
- }), G = h(
262
- () => Number(N.value[A.value]?.value ?? 0)
263
- ), a = h(
264
- () => Number(s.value[L.value]?.value ?? 0)
301
+ }), oe = p(() => w.value === 1 ? "PM" : "AM"), te = p(() => {
302
+ const a = Number(A.value[M.value]?.value ?? 0);
303
+ return i.value ? oe.value === "PM" ? Te(a, !0) : Te(a, !1) : g.value && a === 24 ? 0 : a;
304
+ }), $ = p(
305
+ () => Number(C.value[E.value]?.value ?? 0)
306
+ ), re = p(
307
+ () => Number(r.value[m.value]?.value ?? 0)
265
308
  );
266
- D(Y, (n) => {
267
- n.length && (!n[M.value] || n[M.value].disabled) && (M.value = C(n));
268
- }), D($, (n) => {
269
- n.length && (!n[A.value] || n[A.value].disabled) && (A.value = C(n));
270
- }), D(ee, (n) => {
271
- !e.value || !n.length || (!n[L.value] || n[L.value].disabled) && (L.value = C(n));
272
- }), D(J, (n) => {
273
- !l.value || !n.length || (!n[B.value] || n[B.value].disabled) && (B.value = C(n));
309
+ function H(a, e, t) {
310
+ a.length && (!a[e] || a[e].disabled) && t(K(a));
311
+ }
312
+ L(B, (a) => {
313
+ H(a, M.value, (e) => {
314
+ M.value = e;
315
+ });
316
+ }), L(q, (a) => {
317
+ H(a, E.value, (e) => {
318
+ E.value = e;
319
+ });
320
+ }), L(O, (a) => {
321
+ !f.value || !a.length || H(a, m.value, (e) => {
322
+ m.value = e;
323
+ });
324
+ }), L(ee, (a) => {
325
+ !i.value || !a.length || H(a, w.value, (e) => {
326
+ w.value = e;
327
+ });
274
328
  });
275
- function i(n) {
276
- !e.value && !l.value && I();
329
+ function se(a) {
330
+ !f.value && !i.value && X();
277
331
  }
278
- function m(n) {
279
- l.value || I();
332
+ function Q(a) {
333
+ i.value || X();
280
334
  }
281
- function F(n) {
282
- I();
335
+ function le(a) {
336
+ X();
283
337
  }
284
- function I() {
285
- x.value = !1;
338
+ function X() {
339
+ D.value = !1;
286
340
  }
287
- return D(
288
- [ie, G, a],
289
- ([n, p, k]) => {
290
- y("update:initTime", { h: n, m: p, s: k });
341
+ return L(
342
+ [te, $, re],
343
+ ([a, e, t]) => {
344
+ P("update:initTime", { h: a, m: e, s: t });
291
345
  },
292
346
  { immediate: !0 }
293
- ), (n, p) => x.value ? (K(), W("div", {
347
+ ), (a, e) => D.value ? (W(), Y("div", {
294
348
  key: 0,
295
349
  class: "vtp-cols",
296
350
  ref_key: "root",
297
- ref: S
351
+ ref: I
298
352
  }, [
299
- ue(ne, {
353
+ fe(ne, {
300
354
  activeIndex: M.value,
301
- "onUpdate:activeIndex": p[0] || (p[0] = (k) => M.value = k),
302
- items: Y.value,
355
+ "onUpdate:activeIndex": e[0] || (e[0] = (t) => M.value = t),
356
+ items: B.value,
303
357
  label: "Hours"
304
358
  }, null, 8, ["activeIndex", "items"]),
305
- ue(ne, {
306
- activeIndex: A.value,
307
- "onUpdate:activeIndex": p[1] || (p[1] = (k) => A.value = k),
308
- items: $.value,
359
+ fe(ne, {
360
+ activeIndex: E.value,
361
+ "onUpdate:activeIndex": e[1] || (e[1] = (t) => E.value = t),
362
+ items: q.value,
309
363
  label: "Minutes",
310
- onSelect: i
364
+ onSelect: se
311
365
  }, null, 8, ["activeIndex", "items"]),
312
- e.value ? (K(), de(ne, {
366
+ f.value ? (W(), ve(ne, {
313
367
  key: 0,
314
- activeIndex: L.value,
315
- "onUpdate:activeIndex": p[2] || (p[2] = (k) => L.value = k),
316
- items: ee.value,
368
+ activeIndex: m.value,
369
+ "onUpdate:activeIndex": e[2] || (e[2] = (t) => m.value = t),
370
+ items: O.value,
317
371
  label: "Seconds",
318
- onSelect: m
319
- }, null, 8, ["activeIndex", "items"])) : ae("", !0),
320
- l.value ? (K(), de(ne, {
372
+ onSelect: Q
373
+ }, null, 8, ["activeIndex", "items"])) : Z("", !0),
374
+ i.value ? (W(), ve(ne, {
321
375
  key: 1,
322
- activeIndex: B.value,
323
- "onUpdate:activeIndex": p[3] || (p[3] = (k) => B.value = k),
324
- items: J.value,
376
+ activeIndex: w.value,
377
+ "onUpdate:activeIndex": e[3] || (e[3] = (t) => w.value = t),
378
+ items: ee.value,
325
379
  label: "AM/PM",
326
- onSelect: F
327
- }, null, 8, ["activeIndex", "items"])) : ae("", !0)
328
- ], 512)) : ae("", !0);
380
+ onSelect: le
381
+ }, null, 8, ["activeIndex", "items"])) : Z("", !0)
382
+ ], 512)) : Z("", !0);
329
383
  }
330
384
  });
331
- function $e(t) {
332
- return typeof t == "string" ? j.test(t) : Array.isArray(t) ? t.length === 2 && j.test(t[0] ?? "") && j.test(t[1] ?? "") : !1;
385
+ function Le(n) {
386
+ return typeof n == "string" ? j.test(n) : Array.isArray(n) ? n.length === 2 && j.test(n[0] ?? "") && j.test(n[1] ?? "") : !1;
387
+ }
388
+ function ae(n) {
389
+ return n == null || typeof n == "string" || typeof n == "number";
333
390
  }
334
- const Me = /^(HH|H|hh|h|kk|k):(mm|m)(?::(ss|s))?(?:\s*(A|a|P|p))?$/, j = /^([01]\d|2[0-3]):([0-5]\d)(:([0-5]\d))?$/, Q = typeof __DEV__ < "u" ? __DEV__ : typeof process < "u" && process.env && process.env.NODE_ENV !== "production", Le = {
391
+ const Ve = /^(HH|H|hh|h|kk|k):(mm|m)(?::(ss|s))?(?:\s*(A|a|P|p))?$/, j = /^([01]\d|2[0-3]):([0-5]\d)(:([0-5]\d))?$/, _ = typeof __DEV__ < "u" ? __DEV__ : typeof process < "u" && process.env && process.env.NODE_ENV !== "production", Fe = {
335
392
  modelValue: {
336
393
  type: [String, Array],
337
394
  default: void 0,
338
- validator: (t) => {
395
+ validator: (n) => {
339
396
  let o;
340
- return Array.isArray(t) ? o = t.length === 2 && t.every((l) => j.test(l)) : o = t == null || j.test(t), !o && Q && console.error(
341
- `[VueTimepicker] \`modelValue\` is wrong. Received: ${t}`
397
+ return Array.isArray(n) ? o = n.length === 2 && n.every((l) => j.test(l)) : o = n == null || j.test(n), !o && _ && console.error(
398
+ `[VueTimepicker] \`modelValue\` is wrong. Received: ${n}`
342
399
  ), o;
343
400
  }
344
401
  },
@@ -356,26 +413,26 @@ const Me = /^(HH|H|hh|h|kk|k):(mm|m)(?::(ss|s))?(?:\s*(A|a|P|p))?$/, j = /^([01]
356
413
  minTime: {
357
414
  type: String,
358
415
  default: void 0,
359
- validator: (t) => {
360
- const o = t == null || j.test(t);
361
- return !o && Q && console.error(`[VueTimepicker] \`minTime\` is wrong. Received: ${t}`), o;
416
+ validator: (n) => {
417
+ const o = n == null || j.test(n);
418
+ return !o && _ && console.error(`[VueTimepicker] \`minTime\` is wrong. Received: ${n}`), o;
362
419
  }
363
420
  },
364
421
  maxTime: {
365
422
  type: String,
366
423
  default: void 0,
367
- validator: (t) => {
368
- const o = t == null || j.test(t);
369
- return !o && Q && console.error(`[VueTimepicker] \`maxTime\` is wrong. Received: ${t}`), o;
424
+ validator: (n) => {
425
+ const o = n == null || j.test(n);
426
+ return !o && _ && console.error(`[VueTimepicker] \`maxTime\` is wrong. Received: ${n}`), o;
370
427
  }
371
428
  },
372
429
  disabledTimes: {
373
430
  type: Array,
374
431
  default: void 0,
375
- validator: (t) => {
376
- const o = t == null || t.every($e);
377
- return !o && Q && console.error(
378
- `[VueTimepicker] \`disabledTimes\` is wrong. Received: ${JSON.stringify(t)}`
432
+ validator: (n) => {
433
+ const o = n == null || n.every(Le);
434
+ return !o && _ && console.error(
435
+ `[VueTimepicker] \`disabledTimes\` is wrong. Received: ${JSON.stringify(n)}`
379
436
  ), o;
380
437
  }
381
438
  },
@@ -386,480 +443,527 @@ const Me = /^(HH|H|hh|h|kk|k):(mm|m)(?::(ss|s))?(?:\s*(A|a|P|p))?$/, j = /^([01]
386
443
  format: {
387
444
  type: String,
388
445
  default: "HH:mm",
389
- validator: (t) => {
390
- const o = Me.test(t);
391
- return !o && Q && console.error(
392
- `[VueTimepicker] \`format\` format is wrong. Received: ${t}`
446
+ validator: (n) => {
447
+ const o = Ve.test(n);
448
+ return !o && _ && console.error(
449
+ `[VueTimepicker] \`format\` format is wrong. Received: ${n}`
450
+ ), o;
451
+ }
452
+ },
453
+ placeholder: {
454
+ type: String,
455
+ default: "Select time"
456
+ },
457
+ inputWidth: {
458
+ type: [String, Number],
459
+ default: void 0,
460
+ validator: (n) => {
461
+ const o = ae(n);
462
+ return !o && _ && console.error(
463
+ `[VueTimepicker] \`inputWidth\` must be a string or number. Received: ${n}`
464
+ ), o;
465
+ }
466
+ },
467
+ componentWidth: {
468
+ type: [String, Number],
469
+ default: void 0,
470
+ validator: (n) => {
471
+ const o = ae(n);
472
+ return !o && _ && console.error(
473
+ `[VueTimepicker] \`componentWidth\` must be a string or number. Received: ${n}`
474
+ ), o;
475
+ }
476
+ },
477
+ minInputWidth: {
478
+ type: [String, Number],
479
+ default: void 0,
480
+ validator: (n) => {
481
+ const o = ae(n);
482
+ return !o && _ && console.error(
483
+ `[VueTimepicker] \`minInputWidth\` must be a string or number. Received: ${n}`
484
+ ), o;
485
+ }
486
+ },
487
+ maxInputWidth: {
488
+ type: [String, Number],
489
+ default: void 0,
490
+ validator: (n) => {
491
+ const o = ae(n);
492
+ return !o && _ && console.error(
493
+ `[VueTimepicker] \`maxInputWidth\` must be a string or number. Received: ${n}`
393
494
  ), o;
394
495
  }
395
496
  },
396
497
  size: {
397
498
  type: String,
398
499
  default: "md",
399
- validator: (t) => {
400
- const o = t === "xs" || t === "sm" || t === "md" || t === "lg" || t === "xl";
401
- return !o && Q && console.error(`[VueTimepicker] \`size\` is wrong. Received: ${t}`), o;
500
+ validator: (n) => {
501
+ const o = n === "xs" || n === "sm" || n === "md" || n === "lg" || n === "xl";
502
+ return !o && _ && console.error(`[VueTimepicker] \`size\` is wrong. Received: ${n}`), o;
402
503
  }
403
504
  }
404
505
  };
405
- function Ne(t) {
406
- const o = Me.exec(t);
407
- if (!o) throw new Error(`[useTimeMask] Invalid format: ${t}`);
408
- const [, l, e, g, r] = o, y = [], x = !!r, S = /^k{1,2}$/.test(l);
409
- let c = 0, V = 23;
410
- return x ? (c = 1, V = 12) : S && (c = 1, V = 24), y.push({ token: l, min: c, max: V }), y.push({ token: e, min: 0, max: 59 }), g && y.push({ token: g, min: 0, max: 59 }), {
411
- digitGroups: y,
412
- hasAmPm: !!r,
413
- ampmLowercase: r === "a" || r === "p"
506
+ function Ce(n) {
507
+ const o = Ve.exec(n);
508
+ if (!o) throw new Error(`[useTimeMask] Invalid format: ${n}`);
509
+ const [, l, i, f, g] = o, u = [], P = !!g, D = /^k{1,2}$/.test(l);
510
+ let I = 0, F = 23;
511
+ return P ? (I = 1, F = 12) : D && (I = 1, F = 24), u.push({ token: l, min: I, max: F }), u.push({ token: i, min: 0, max: 59 }), f && u.push({ token: f, min: 0, max: 59 }), {
512
+ digitGroups: u,
513
+ hasAmPm: !!g,
514
+ ampmLowercase: g === "a" || g === "p"
414
515
  };
415
516
  }
416
- function ke(t) {
417
- const o = h(() => Ne(t.value)), l = h(() => o.value.digitGroups.length * 2), e = E([]), g = E("AM"), r = E("");
418
- function y() {
419
- const { digitGroups: s, hasAmPm: u } = o.value;
420
- let d = "", v = 0;
421
- for (let f = 0; f < s.length; f++) {
422
- for (let b = 0; b < 2; b++)
423
- v < e.value.length && (d += String(e.value[v]), v++);
424
- v === (f + 1) * 2 && f < s.length - 1 && (d += ":");
425
- }
426
- if (u && v >= l.value) {
427
- const f = o.value.ampmLowercase ? g.value.toLowerCase() : g.value;
428
- d += " " + f;
429
- }
430
- return d;
517
+ function Se(n) {
518
+ const o = p(() => Ce(n.value)), l = p(() => o.value.digitGroups.length * 2), i = N([]), f = N("AM"), g = N("");
519
+ function u() {
520
+ const { digitGroups: r, hasAmPm: d } = o.value;
521
+ let c = "", b = 0;
522
+ for (let v = 0; v < r.length; v++) {
523
+ for (let k = 0; k < 2; k++)
524
+ b < i.value.length && (c += String(i.value[b]), b++);
525
+ b === (v + 1) * 2 && v < r.length - 1 && (c += ":");
526
+ }
527
+ if (d && b >= l.value) {
528
+ const v = o.value.ampmLowercase ? f.value.toLowerCase() : f.value;
529
+ c += " " + v;
530
+ }
531
+ return c;
431
532
  }
432
- function x(s) {
433
- const u = s * 2;
434
- if (e.value.length < u + 2) return;
435
- const d = e.value[u] * 10 + e.value[u + 1], { min: v, max: f } = o.value.digitGroups[s], b = Math.max(v, Math.min(f, d));
436
- b !== d && (e.value[u] = Math.floor(b / 10), e.value[u + 1] = b % 10);
533
+ function P(r) {
534
+ const d = r * 2;
535
+ if (i.value.length < d + 2) return;
536
+ const c = i.value[d] * 10 + i.value[d + 1], { min: b, max: v } = o.value.digitGroups[r], k = Math.max(b, Math.min(v, c));
537
+ k !== c && (i.value[d] = Math.floor(k / 10), i.value[d + 1] = k % 10);
437
538
  }
438
- function S() {
439
- for (let s = 0; s < o.value.digitGroups.length; s++)
440
- x(s);
539
+ function D() {
540
+ for (let r = 0; r < o.value.digitGroups.length; r++)
541
+ P(r);
441
542
  }
442
- function c(s) {
443
- const u = y();
444
- let d = 0;
445
- for (let v = 0; v < Math.min(s, u.length); v++)
446
- /\d/.test(u[v]) && d++;
447
- return d;
543
+ function I(r) {
544
+ const d = u();
545
+ let c = 0;
546
+ for (let b = 0; b < Math.min(r, d.length); b++)
547
+ /\d/.test(d[b]) && c++;
548
+ return c;
448
549
  }
449
- function V(s) {
450
- return s + Math.floor(s / 2);
550
+ function F(r) {
551
+ return r + Math.floor(r / 2);
451
552
  }
452
- function M(s, u) {
453
- if (s >= l.value) return l.value;
454
- const d = [...e.value];
455
- d[s] = u, e.value = d;
456
- const v = Math.floor(s / 2);
457
- return x(v), Math.min(s + 1, l.value);
553
+ function y(r, d) {
554
+ if (r >= l.value) return l.value;
555
+ const c = [...i.value];
556
+ c[r] = d, i.value = c;
557
+ const b = Math.floor(r / 2);
558
+ return P(b), Math.min(r + 1, l.value);
458
559
  }
459
- function A(s, u) {
460
- const d = y();
461
- r.value = d, s.value = d;
462
- const v = u !== void 0 ? Math.min(V(u), d.length) : d.length;
463
- s.selectionStart = s.selectionEnd = v, ve(() => {
464
- document.activeElement === s && (s.selectionStart = s.selectionEnd = v);
560
+ function M(r, d) {
561
+ const c = u();
562
+ g.value = c, r.value = c;
563
+ const b = d !== void 0 ? Math.min(F(d), c.length) : c.length;
564
+ r.selectionStart = r.selectionEnd = b, ge(() => {
565
+ document.activeElement === r && (r.selectionStart = r.selectionEnd = b);
465
566
  });
466
567
  }
467
- function L(s) {
468
- const u = s.key, d = s.target;
568
+ function E(r) {
569
+ const d = r.key, c = r.target;
469
570
  if (["Tab", "Escape", "ArrowLeft", "ArrowRight", "Home", "End"].includes(
470
- u
471
- ) || s.metaKey || s.ctrlKey)
571
+ d
572
+ ) || r.metaKey || r.ctrlKey)
472
573
  return;
473
- s.preventDefault();
474
- const v = d.selectionStart ?? 0, f = c(v);
475
- if (u === "Backspace") {
476
- f > 0 && A(d, f - 1);
574
+ r.preventDefault();
575
+ const b = c.selectionStart ?? 0, v = I(b);
576
+ if (d === "Backspace") {
577
+ v > 0 && M(c, v - 1);
477
578
  return;
478
579
  }
479
- if (u !== "Delete") {
580
+ if (d !== "Delete") {
480
581
  if (o.value.hasAmPm) {
481
- const b = u.toLowerCase();
482
- if (b === "a") {
483
- g.value = "AM", A(d, f);
582
+ const k = d.toLowerCase();
583
+ if (k === "a") {
584
+ f.value = "AM", M(c, v);
484
585
  return;
485
586
  }
486
- if (b === "p") {
487
- g.value = "PM", A(d, f);
587
+ if (k === "p") {
588
+ f.value = "PM", M(c, v);
488
589
  return;
489
590
  }
490
591
  }
491
- if (/^\d$/.test(u)) {
492
- const b = M(f, +u);
493
- A(d, b);
592
+ if (/^\d$/.test(d)) {
593
+ const k = y(v, +d);
594
+ M(c, k);
494
595
  return;
495
596
  }
496
597
  }
497
598
  }
498
- function R(s) {
499
- const u = s.target, d = u.value.replace(/\D/g, "").split("").map(Number).slice(0, l.value);
500
- e.value = d, S(), o.value.hasAmPm && (/p/i.test(u.value) ? g.value = "PM" : /a/i.test(u.value) && (g.value = "AM")), A(u);
599
+ function m(r) {
600
+ const d = r.target, c = d.value.replace(/\D/g, "").split("").map(Number).slice(0, l.value);
601
+ i.value = c, D(), o.value.hasAmPm && (/p/i.test(d.value) ? f.value = "PM" : /a/i.test(d.value) && (f.value = "AM")), M(d);
602
+ }
603
+ function S(r) {
604
+ r.preventDefault();
605
+ const d = r.clipboardData?.getData("text") ?? "", c = r.target, b = c.selectionStart ?? 0, v = d.replace(/\D/g, "").split("").map(Number);
606
+ let k = I(b);
607
+ for (const K of v) {
608
+ if (k >= l.value) break;
609
+ k = y(k, K);
610
+ }
611
+ o.value.hasAmPm && (/p\.?m\.?/i.test(d) ? f.value = "PM" : /a\.?m\.?/i.test(d) && (f.value = "AM")), M(c, k);
501
612
  }
502
- function q(s) {
503
- s.preventDefault();
504
- const u = s.clipboardData?.getData("text") ?? "", d = s.target, v = d.selectionStart ?? 0, f = u.replace(/\D/g, "").split("").map(Number);
505
- let b = c(v);
506
- for (const C of f) {
507
- if (b >= l.value) break;
508
- b = M(b, C);
509
- }
510
- o.value.hasAmPm && (/p\.?m\.?/i.test(u) ? g.value = "PM" : /a\.?m\.?/i.test(u) && (g.value = "AM")), A(d, b);
613
+ function T(r) {
614
+ const { digitGroups: d, hasAmPm: c } = o.value, b = [];
615
+ let v = r.h;
616
+ c ? (f.value = r.h >= 12 ? "PM" : "AM", v = r.h % 12, v === 0 && (v = 12)) : pe(n.value) && (v = r.h === 0 ? 24 : r.h), b.push(Math.floor(v / 10), v % 10), b.push(Math.floor(r.m / 10), r.m % 10), d.length > 2 && b.push(Math.floor(r.s / 10), r.s % 10), i.value = b, g.value = u();
511
617
  }
512
- function U(s) {
513
- const { digitGroups: u, hasAmPm: d } = o.value, v = [];
514
- let f = s.h;
515
- d ? (g.value = s.h >= 12 ? "PM" : "AM", f = s.h % 12, f === 0 && (f = 12)) : me(t.value) && (f = s.h === 0 ? 24 : s.h), v.push(Math.floor(f / 10), f % 10), v.push(Math.floor(s.m / 10), s.m % 10), u.length > 2 && v.push(Math.floor(s.s / 10), s.s % 10), e.value = v, r.value = y();
618
+ function V() {
619
+ i.value = [], g.value = "", f.value = "AM";
516
620
  }
517
- function B() {
518
- if (e.value.length < l.value) return null;
519
- const s = [];
520
- for (let f = 0; f < o.value.digitGroups.length; f++) {
521
- const b = f * 2;
522
- s.push(e.value[b] * 10 + e.value[b + 1]);
523
- }
524
- let u = s[0];
525
- const d = s[1], v = s[2] ?? 0;
526
- return o.value.hasAmPm && (u = g.value === "PM" ? u === 12 ? 12 : u + 12 : u === 12 ? 0 : u), me(t.value) && u === 24 && (u = 0), { h: u, m: d, s: v };
621
+ function w() {
622
+ if (i.value.length < l.value) return null;
623
+ const r = [];
624
+ for (let v = 0; v < o.value.digitGroups.length; v++) {
625
+ const k = v * 2;
626
+ r.push(i.value[k] * 10 + i.value[k + 1]);
627
+ }
628
+ let d = r[0];
629
+ const c = r[1], b = r[2] ?? 0;
630
+ return o.value.hasAmPm && (d = f.value === "PM" ? d === 12 ? 12 : d + 12 : d === 12 ? 0 : d), pe(n.value) && d === 24 && (d = 0), { h: d, m: c, s: b };
527
631
  }
528
- const _ = h(
529
- () => e.value.length >= l.value
530
- ), N = h(() => o.value.ampmLowercase);
632
+ const A = p(
633
+ () => i.value.length >= l.value
634
+ ), C = p(() => o.value.ampmLowercase);
531
635
  return {
532
- inputValue: r,
533
- handleKeydown: L,
534
- handleInput: R,
535
- handlePaste: q,
536
- setFromTime: U,
537
- getParsedTime: B,
538
- isComplete: _,
636
+ inputValue: g,
637
+ handleKeydown: E,
638
+ handleInput: m,
639
+ handlePaste: S,
640
+ setFromTime: T,
641
+ clear: V,
642
+ getParsedTime: w,
643
+ isComplete: A,
539
644
  totalDigits: l,
540
- displayPosToDigitIndex: c,
541
- ampm: g,
542
- ampmLowercase: N
645
+ displayPosToDigitIndex: I,
646
+ ampm: f,
647
+ ampmLowercase: C
543
648
  };
544
649
  }
545
- const Be = ["data-size", "data-validation", "data-disabled"], Fe = ["value", "placeholder", "disabled"], _e = ["value", "placeholder", "disabled"], Re = ["value", "placeholder", "disabled"], Ke = /* @__PURE__ */ ce({
650
+ const Be = ["data-size", "data-validation", "data-disabled"], Re = ["value", "placeholder", "disabled"], _e = ["value", "placeholder", "disabled"], Ke = /* @__PURE__ */ he({
546
651
  __name: "TimePicker",
547
- props: Le,
652
+ props: Fe,
548
653
  emits: ["update:modelValue", "update:validationState", "validate", "open", "close", "error"],
549
- setup(t, { emit: o }) {
550
- const l = E(null), e = t, g = o, r = E(!1), y = E(!1), x = E("valid"), S = E("valid");
551
- D(r, (a) => {
552
- if (e.disabled && a) {
553
- r.value = !1;
554
- return;
555
- }
556
- a && (y.value = !1);
557
- }), D(y, (a) => {
558
- if (e.disabled && a) {
559
- y.value = !1;
654
+ setup(n, { emit: o }) {
655
+ const l = N(null), i = n, f = o, g = N(!1), u = N(!1), P = N("valid"), D = N("valid");
656
+ function I() {
657
+ g.value = !1, u.value = !1;
658
+ }
659
+ function F(e, t) {
660
+ if (i.disabled && t) {
661
+ I();
560
662
  return;
561
663
  }
562
- a && (r.value = !1);
563
- }), D(
564
- () => e.disabled,
565
- (a) => {
566
- a && (r.value = !1, y.value = !1);
664
+ t && (e === "first" ? u.value = !1 : g.value = !1);
665
+ }
666
+ L(g, (e) => {
667
+ F("first", e);
668
+ }), L(u, (e) => {
669
+ F("second", e);
670
+ }), L(
671
+ () => i.disabled,
672
+ (e) => {
673
+ e && I();
567
674
  }
568
675
  );
569
- const c = h({
676
+ const y = p({
570
677
  get() {
571
- if (Array.isArray(e.modelValue)) {
572
- const [a, i] = e.modelValue;
573
- return [z(a, e.format), z(i, e.format)];
678
+ if (Array.isArray(i.modelValue)) {
679
+ const [e, t] = i.modelValue;
680
+ return [z(e, i.format), z(t, i.format)];
574
681
  } else
575
- return z(e.modelValue, e.format);
682
+ return z(i.modelValue, i.format);
576
683
  },
577
- set(a) {
578
- Array.isArray(a) ? g("update:modelValue", [
579
- Z("HH:mm:ss", a[0]),
580
- Z("HH:mm:ss", a[1])
581
- ]) : g("update:modelValue", Z("HH:mm:ss", a));
684
+ set(e) {
685
+ Array.isArray(e) ? f("update:modelValue", [
686
+ ie("HH:mm:ss", e[0]),
687
+ ie("HH:mm:ss", e[1])
688
+ ]) : f("update:modelValue", ie("HH:mm:ss", e));
582
689
  }
583
- }), V = h(
584
- () => e.minTime ? z(e.minTime) : null
585
- ), M = h(
586
- () => e.maxTime ? z(e.maxTime) : null
587
- ), A = h(() => !V.value || !M.value ? !0 : O(V.value, M.value) <= 0), L = h(() => x.value === "out-of-range" || e.range && S.value === "out-of-range" ? "out-of-range" : x.value === "invalid" || e.range && S.value === "invalid" ? "invalid" : "valid"), R = h(() => (e.disabledTimes ?? []).map((i) => {
588
- const m = Array.isArray(i) ? i : [i, i], F = z(m[0]), I = z(m[1]);
589
- return O(F, I) <= 0 ? [F, I] : [I, F];
690
+ }), M = p(
691
+ () => i.minTime ? z(i.minTime) : null
692
+ ), E = p(
693
+ () => i.maxTime ? z(i.maxTime) : null
694
+ ), m = p(() => !M.value || !E.value ? !0 : U(M.value, E.value) <= 0), S = p(() => P.value === "out-of-range" || i.range && D.value === "out-of-range" ? "out-of-range" : P.value === "invalid" || i.range && D.value === "invalid" ? "invalid" : "valid"), T = p(() => (i.disabledTimes ?? []).map((t) => {
695
+ const s = Array.isArray(t) ? t : [t, t], h = z(s[0]), x = z(s[1]);
696
+ return U(h, x) <= 0 ? [h, x] : [x, h];
590
697
  }));
591
- function q(a) {
592
- return !!(Se(a, R.value) || e.isTimeDisabled?.(a));
698
+ function V(e) {
699
+ return !!(Ie(e, T.value) || i.isTimeDisabled?.(e));
593
700
  }
594
- function U(a) {
595
- return a === "first" ? Array.isArray(c.value) ? c.value[0] : c.value : Array.isArray(c.value) ? c.value[1] : c.value;
701
+ function w(e) {
702
+ return e === "first" ? Array.isArray(y.value) ? y.value[0] : y.value : Array.isArray(y.value) ? y.value[1] : y.value;
596
703
  }
597
- function B(a, i) {
598
- if (a === "first") {
599
- Array.isArray(c.value) ? c.value = [i, c.value[1]] : c.value = i;
704
+ function A(e) {
705
+ const t = i.modelValue;
706
+ return Array.isArray(t) ? e === "first" ? !!t[0] : !!t[1] : e === "second" ? !1 : typeof t == "string" && t.length > 0;
707
+ }
708
+ function C(e, t) {
709
+ if (e === "first") {
710
+ Array.isArray(y.value) ? y.value = [t, y.value[1]] : y.value = t;
600
711
  return;
601
712
  }
602
- Array.isArray(c.value) && (c.value = [c.value[0], i]);
603
- }
604
- function _(a, i, m, F) {
605
- if (a === "first" ? x.value = i : S.value = i, g("validate", {
606
- target: a,
607
- state: i,
608
- reason: m,
609
- value: F ? Z("HH:mm:ss", F) : null
610
- }), i === "valid") {
713
+ Array.isArray(y.value) && (y.value = [y.value[0], t]);
714
+ }
715
+ function r(e, t, s, h) {
716
+ if (e === "first" ? P.value = t : D.value = t, f("validate", {
717
+ target: e,
718
+ state: t,
719
+ reason: s,
720
+ value: h ? ie("HH:mm:ss", h) : null
721
+ }), t === "valid") {
611
722
  l.value = null;
612
723
  return;
613
724
  }
614
- if (i === "out-of-range") {
615
- l.value = "OUT_OF_RANGE", g("error", {
725
+ if (t === "out-of-range") {
726
+ l.value = "OUT_OF_RANGE", f("error", {
616
727
  code: "OUT_OF_RANGE",
617
728
  message: "Time is outside min/max bounds and was clamped."
618
729
  });
619
730
  return;
620
731
  }
621
- l.value = m ?? "BAD_TIME", g("error", {
622
- code: m ?? "BAD_TIME",
623
- message: m === "DISABLED" ? "Time is disabled by disabledTimes or isTimeDisabled." : "Time is invalid."
732
+ l.value = s ?? "BAD_TIME", f("error", {
733
+ code: s ?? "BAD_TIME",
734
+ message: s === "DISABLED" ? "Time is disabled by disabledTimes or isTimeDisabled." : "Time is invalid."
624
735
  });
625
736
  }
626
- D(
627
- L,
628
- (a) => {
629
- g("update:validationState", a);
737
+ L(
738
+ S,
739
+ (e) => {
740
+ f("update:validationState", e);
630
741
  },
631
742
  { immediate: !0 }
632
743
  );
633
- const N = h(
634
- () => A.value ? V.value : null
635
- ), s = h(
636
- () => A.value ? M.value : null
744
+ const d = p(
745
+ () => m.value ? M.value : null
746
+ ), c = p(
747
+ () => m.value ? E.value : null
637
748
  );
638
- function u(a) {
639
- return He(
640
- a,
641
- N.value,
642
- s.value
749
+ function b(e) {
750
+ return $e(
751
+ e,
752
+ d.value,
753
+ c.value
643
754
  );
644
755
  }
645
- function d(a, i, m) {
646
- const F = !Te(
647
- i,
648
- N.value,
649
- s.value
650
- ), I = u(i);
651
- return q(I) ? (m.emitValidation && _(a, "invalid", "DISABLED", I), !1) : (B(a, I), m.emitValidation && (F ? _(a, "out-of-range", "OUT_OF_RANGE", I) : _(a, "valid", void 0, I)), !0);
756
+ function v(e, t, s) {
757
+ const h = !Me(
758
+ t,
759
+ d.value,
760
+ c.value
761
+ ), x = b(t);
762
+ return V(x) ? (s.emitValidation && r(e, "invalid", "DISABLED", x), !1) : (C(e, x), s.emitValidation && (h ? r(e, "out-of-range", "OUT_OF_RANGE", x) : r(e, "valid", void 0, x)), !0);
652
763
  }
653
- const v = h({
764
+ const k = p({
654
765
  get() {
655
- return Array.isArray(c.value) ? c.value[0] : c.value;
766
+ return Array.isArray(y.value) ? y.value[0] : y.value;
656
767
  },
657
- set(a) {
658
- d("first", a, { emitValidation: !0 });
768
+ set(e) {
769
+ !A("first") && !g.value || v("first", e, { emitValidation: !0 });
659
770
  }
660
- }), f = h({
771
+ }), K = p({
661
772
  get() {
662
- return Array.isArray(c.value) ? c.value[1] : c.value;
773
+ return Array.isArray(y.value) ? y.value[1] : y.value;
663
774
  },
664
- set(a) {
665
- Array.isArray(c.value) && d("second", a, { emitValidation: !0 });
775
+ set(e) {
776
+ !A("second") && !u.value || Array.isArray(y.value) && v("second", e, { emitValidation: !0 });
666
777
  }
667
778
  });
668
- h(() => {
669
- if (!e.modelValue) return "—";
670
- const a = (i) => Z(e.format, i);
671
- return e.range ? `${a(v.value)} → ${a(f.value)}` : a(v.value);
672
- }), D(
673
- () => e.range,
674
- (a) => {
675
- if (a) {
676
- if (!Array.isArray(e.modelValue))
779
+ L(
780
+ () => i.range,
781
+ (e) => {
782
+ if (e) {
783
+ if (i.modelValue != null && !Array.isArray(i.modelValue))
677
784
  throw new RangeError(
678
- `Model value must be an array for range selection: ${e.modelValue}`
785
+ `Model value must be an array for range selection: ${i.modelValue}`
679
786
  );
680
- } else if (Array.isArray(e.modelValue))
787
+ } else if (Array.isArray(i.modelValue))
681
788
  throw new RangeError(
682
- `Model value must be a single string for single time selection: ${e.modelValue}`
789
+ `Model value must be a single string for single time selection: ${i.modelValue}`
683
790
  );
684
791
  },
685
792
  { immediate: !0 }
686
- ), D(
687
- () => [N.value, s.value, e.range],
688
- () => {
689
- d("first", U("first"), {
690
- emitValidation: !0
691
- }), e.range && d("second", U("second"), {
692
- emitValidation: !0
693
- });
694
- },
793
+ );
794
+ function G() {
795
+ A("first") && v("first", w("first"), {
796
+ emitValidation: !0
797
+ }), i.range && A("second") && v("second", w("second"), {
798
+ emitValidation: !0
799
+ });
800
+ }
801
+ L(
802
+ () => [d.value, c.value, i.range],
803
+ G,
695
804
  { immediate: !0 }
696
- ), D(
697
- () => [R.value, e.isTimeDisabled, e.range],
698
- () => {
699
- d("first", U("first"), {
700
- emitValidation: !0
701
- }), e.range && d("second", U("second"), {
702
- emitValidation: !0
703
- });
704
- },
805
+ ), L(
806
+ () => [T.value, i.isTimeDisabled, i.range],
807
+ G,
705
808
  { immediate: !0 }
706
809
  );
707
- const b = h(() => e.format ?? "HH:mm:ss"), C = h(() => {
708
- let a = b.value.length;
709
- return /[AaPp]$/.test(b.value) && (a += 1), `${Math.min(12, Math.max(4, a))}ch`;
710
- }), P = ke(b), Y = P.inputValue, $ = ke(b), ee = $.inputValue;
711
- D(
712
- () => [v.value, b.value],
713
- ([a]) => {
714
- P.setFromTime(a);
810
+ const B = p(() => i.format ?? "HH:mm:ss"), q = p(() => i.placeholder ?? "Select time");
811
+ function O(e) {
812
+ if (e == null) return;
813
+ if (typeof e == "number") return `${e}px`;
814
+ const t = e.trim();
815
+ return t.length > 0 ? t : void 0;
816
+ }
817
+ const ee = p(() => {
818
+ let e = Math.max(
819
+ B.value.length,
820
+ q.value.length
821
+ );
822
+ return /[AaPp]$/.test(B.value) && (e = Math.max(e, B.value.length + 1)), `${Math.min(20, Math.max(6, e))}ch`;
823
+ }), oe = p(() => {
824
+ const e = {}, t = O(i.componentWidth), s = O(i.inputWidth), h = O(i.minInputWidth), x = O(i.maxInputWidth);
825
+ return t && (e["--vtp-component-width"] = t), s && (e["--vtp-input-width"] = s), h && (e["--vtp-input-min-width"] = h), x && (e["--vtp-input-max-width"] = x), e;
826
+ }), te = p(() => ({
827
+ width: `var(--vtp-input-width, ${ee.value})`,
828
+ minWidth: "var(--vtp-input-min-width, 0)",
829
+ maxWidth: "var(--vtp-input-max-width, none)"
830
+ })), $ = Se(B), re = $.inputValue, H = Se(B), se = H.inputValue;
831
+ L(
832
+ () => [k.value, B.value],
833
+ ([e]) => {
834
+ if (!A("first")) {
835
+ $.clear();
836
+ return;
837
+ }
838
+ $.setFromTime(e);
715
839
  },
716
840
  { immediate: !0 }
717
- ), D(
718
- () => [f.value, b.value, e.range],
719
- ([a, , i]) => {
720
- if (!i) {
721
- $.setFromTime({ h: 0, m: 0, s: 0 });
841
+ ), L(
842
+ () => [K.value, B.value, i.range],
843
+ ([e, , t]) => {
844
+ if (!t || !A("second")) {
845
+ H.clear();
722
846
  return;
723
847
  }
724
- $.setFromTime(a);
848
+ H.setFromTime(e);
725
849
  },
726
850
  { immediate: !0 }
727
851
  );
728
- const J = E(null);
729
- function te(a) {
730
- if (e.disabled) return;
731
- if (a.key === "Enter") {
732
- a.preventDefault(), G("first");
852
+ const Q = N(null);
853
+ function le(e) {
854
+ if (i.disabled) return;
855
+ if (e.key === "Enter") {
856
+ e.preventDefault(), a("first");
733
857
  return;
734
858
  }
735
- /^\d$/.test(a.key) && (r.value = !1, y.value = !1);
736
- const i = a.target, m = P.displayPosToDigitIndex(i.selectionStart ?? 0), F = /^\d$/.test(a.key) && m >= P.totalDigits.value - 1;
737
- if (P.handleKeydown(a), /^\d$/.test(a.key)) {
738
- const I = P.getParsedTime();
739
- I && d("first", I, { emitValidation: !1 });
859
+ /^\d$/.test(e.key) && (g.value = !1, u.value = !1);
860
+ const t = e.target, s = $.displayPosToDigitIndex(t.selectionStart ?? 0), h = /^\d$/.test(e.key) && s >= $.totalDigits.value - 1;
861
+ if ($.handleKeydown(e), /^\d$/.test(e.key)) {
862
+ const x = $.getParsedTime();
863
+ x && v("first", x, { emitValidation: !1 });
740
864
  }
741
- e.range && F && J.value && (G("first"), ve(() => {
742
- const I = J.value;
743
- I && (I.focus(), I.selectionStart = I.selectionEnd = 0);
865
+ i.range && h && Q.value && (a("first"), ge(() => {
866
+ const x = Q.value;
867
+ x && (x.focus(), x.selectionStart = x.selectionEnd = 0);
744
868
  }));
745
869
  }
746
- function ie(a) {
747
- if (!e.disabled) {
748
- if (a.key === "Enter") {
749
- a.preventDefault(), G("second");
870
+ function X(e) {
871
+ if (!i.disabled) {
872
+ if (e.key === "Enter") {
873
+ e.preventDefault(), a("second");
750
874
  return;
751
875
  }
752
- if (/^\d$/.test(a.key) && (r.value = !1, y.value = !1), $.handleKeydown(a), /^\d$/.test(a.key)) {
753
- const i = $.getParsedTime();
754
- i && d("second", i, { emitValidation: !1 });
876
+ if (/^\d$/.test(e.key) && (g.value = !1, u.value = !1), H.handleKeydown(e), /^\d$/.test(e.key)) {
877
+ const t = H.getParsedTime();
878
+ t && v("second", t, { emitValidation: !1 });
755
879
  }
756
880
  }
757
881
  }
758
- function G(a) {
759
- const m = (a === "first" ? P : $).getParsedTime();
760
- m ? d(a, m, { emitValidation: !0 }) : _(a, "invalid", "BAD_TIME"), a === "first" ? P.setFromTime(v.value) : e.range && $.setFromTime(f.value);
882
+ function a(e) {
883
+ const t = e === "first" ? $ : H, s = t.getParsedTime();
884
+ s ? v(e, s, { emitValidation: !0 }) : t.inputValue.value.trim() ? r(e, "invalid", "BAD_TIME") : !i.range && e === "first" && (f("update:modelValue", null), r("first", "valid")), e === "first" ? A("first") ? $.setFromTime(k.value) : $.clear() : i.range && (A("second") ? H.setFromTime(K.value) : H.clear());
761
885
  }
762
- return (a, i) => (K(), W("div", {
886
+ return (e, t) => (W(), Y("div", {
763
887
  class: "timepicker-shell",
764
- "data-size": e.size,
765
- "data-validation": L.value,
766
- "data-disabled": e.disabled ? "true" : "false"
888
+ "data-size": i.size,
889
+ "data-validation": S.value,
890
+ "data-disabled": i.disabled ? "true" : "false",
891
+ style: ue(oe.value)
767
892
  }, [
768
- e.range ? (K(), W("div", {
769
- key: 1,
770
- class: re(["timepicker-shell__input", {
771
- "timepicker-shell__input--error": l.value,
772
- "timepicker-shell__input--disabled": e.disabled
773
- }])
774
- }, [
775
- X("input", {
776
- type: "text",
777
- class: "timepicker-field",
778
- value: H(Y),
779
- placeholder: b.value,
780
- style: oe({ width: C.value }),
781
- disabled: e.disabled,
782
- onFocus: i[4] || (i[4] = (m) => !e.disabled && (r.value = !0)),
783
- onKeydown: te,
784
- onInput: i[5] || (i[5] = //@ts-ignore
785
- (...m) => H(P).handleInput && H(P).handleInput(...m)),
786
- onPaste: i[6] || (i[6] = //@ts-ignore
787
- (...m) => H(P).handlePaste && H(P).handlePaste(...m)),
788
- onBlur: i[7] || (i[7] = (m) => !e.disabled && G("first"))
789
- }, null, 44, _e),
790
- i[16] || (i[16] = X("span", { class: "timepicker-separator" }, "–", -1)),
791
- X("input", {
792
- ref_key: "secondInputRef",
793
- ref: J,
794
- type: "text",
795
- class: "timepicker-field",
796
- value: H(ee),
797
- placeholder: b.value,
798
- style: oe({ width: C.value }),
799
- disabled: e.disabled,
800
- onFocus: i[8] || (i[8] = (m) => !e.disabled && (y.value = !0)),
801
- onKeydown: ie,
802
- onInput: i[9] || (i[9] = //@ts-ignore
803
- (...m) => H($).handleInput && H($).handleInput(...m)),
804
- onPaste: i[10] || (i[10] = //@ts-ignore
805
- (...m) => H($).handlePaste && H($).handlePaste(...m)),
806
- onBlur: i[11] || (i[11] = (m) => !e.disabled && G("second"))
807
- }, null, 44, Re)
808
- ], 2)) : (K(), W("div", {
809
- key: 0,
810
- class: re(["timepicker-shell__input", {
893
+ J("div", {
894
+ class: me(["timepicker-shell__input", {
811
895
  "timepicker-shell__input--error": l.value,
812
- "timepicker-shell__input--disabled": e.disabled
896
+ "timepicker-shell__input--disabled": i.disabled
813
897
  }])
814
898
  }, [
815
- X("input", {
899
+ J("input", {
816
900
  type: "text",
817
901
  class: "timepicker-field",
818
- value: H(Y),
819
- placeholder: b.value,
820
- style: oe({ width: C.value }),
821
- disabled: e.disabled,
822
- onFocus: i[0] || (i[0] = (m) => !e.disabled && (r.value = !0)),
823
- onKeydown: te,
824
- onInput: i[1] || (i[1] = //@ts-ignore
825
- (...m) => H(P).handleInput && H(P).handleInput(...m)),
826
- onPaste: i[2] || (i[2] = //@ts-ignore
827
- (...m) => H(P).handlePaste && H(P).handlePaste(...m)),
828
- onBlur: i[3] || (i[3] = (m) => !e.disabled && G("first"))
829
- }, null, 44, Fe)
830
- ], 2)),
831
- X("div", null, [
832
- ue(be, {
833
- open: r.value,
834
- "onUpdate:open": i[12] || (i[12] = (m) => r.value = m),
835
- initTime: v.value,
836
- "onUpdate:initTime": i[13] || (i[13] = (m) => v.value = m),
837
- format: e.format,
838
- "hour-step": e.hourStep,
839
- "minute-step": e.minuteStep,
840
- "second-step": e.secondStep,
841
- "min-time": N.value,
842
- "max-time": s.value,
843
- "disabled-ranges": R.value,
844
- "is-time-disabled": e.isTimeDisabled
902
+ value: R(re),
903
+ placeholder: q.value,
904
+ style: ue(te.value),
905
+ disabled: i.disabled,
906
+ onFocus: t[0] || (t[0] = (s) => !i.disabled && (g.value = !0)),
907
+ onKeydown: le,
908
+ onInput: t[1] || (t[1] = //@ts-ignore
909
+ (...s) => R($).handleInput && R($).handleInput(...s)),
910
+ onPaste: t[2] || (t[2] = //@ts-ignore
911
+ (...s) => R($).handlePaste && R($).handlePaste(...s)),
912
+ onBlur: t[3] || (t[3] = (s) => !i.disabled && a("first"))
913
+ }, null, 44, Re),
914
+ i.range ? (W(), Y(xe, { key: 0 }, [
915
+ t[12] || (t[12] = J("span", { class: "timepicker-separator" }, "–", -1)),
916
+ J("input", {
917
+ ref_key: "secondInputRef",
918
+ ref: Q,
919
+ type: "text",
920
+ class: "timepicker-field",
921
+ value: R(se),
922
+ placeholder: q.value,
923
+ style: ue(te.value),
924
+ disabled: i.disabled,
925
+ onFocus: t[4] || (t[4] = (s) => !i.disabled && (u.value = !0)),
926
+ onKeydown: X,
927
+ onInput: t[5] || (t[5] = //@ts-ignore
928
+ (...s) => R(H).handleInput && R(H).handleInput(...s)),
929
+ onPaste: t[6] || (t[6] = //@ts-ignore
930
+ (...s) => R(H).handlePaste && R(H).handlePaste(...s)),
931
+ onBlur: t[7] || (t[7] = (s) => !i.disabled && a("second"))
932
+ }, null, 44, _e)
933
+ ], 64)) : Z("", !0)
934
+ ], 2),
935
+ J("div", null, [
936
+ fe(ke, {
937
+ open: g.value,
938
+ "onUpdate:open": t[8] || (t[8] = (s) => g.value = s),
939
+ initTime: k.value,
940
+ "onUpdate:initTime": t[9] || (t[9] = (s) => k.value = s),
941
+ format: i.format,
942
+ "hour-step": i.hourStep,
943
+ "minute-step": i.minuteStep,
944
+ "second-step": i.secondStep,
945
+ "min-time": d.value,
946
+ "max-time": c.value,
947
+ "disabled-ranges": T.value,
948
+ "is-time-disabled": i.isTimeDisabled
845
949
  }, null, 8, ["open", "initTime", "format", "hour-step", "minute-step", "second-step", "min-time", "max-time", "disabled-ranges", "is-time-disabled"]),
846
- e.range ? (K(), de(be, {
950
+ i.range ? (W(), ve(ke, {
847
951
  key: 0,
848
- open: y.value,
849
- "onUpdate:open": i[14] || (i[14] = (m) => y.value = m),
850
- initTime: f.value,
851
- "onUpdate:initTime": i[15] || (i[15] = (m) => f.value = m),
852
- format: e.format,
853
- "hour-step": e.hourStep,
854
- "minute-step": e.minuteStep,
855
- "second-step": e.secondStep,
856
- "min-time": N.value,
857
- "max-time": s.value,
858
- "disabled-ranges": R.value,
859
- "is-time-disabled": e.isTimeDisabled
860
- }, null, 8, ["open", "initTime", "format", "hour-step", "minute-step", "second-step", "min-time", "max-time", "disabled-ranges", "is-time-disabled"])) : ae("", !0)
952
+ open: u.value,
953
+ "onUpdate:open": t[10] || (t[10] = (s) => u.value = s),
954
+ initTime: K.value,
955
+ "onUpdate:initTime": t[11] || (t[11] = (s) => K.value = s),
956
+ format: i.format,
957
+ "hour-step": i.hourStep,
958
+ "minute-step": i.minuteStep,
959
+ "second-step": i.secondStep,
960
+ "min-time": d.value,
961
+ "max-time": c.value,
962
+ "disabled-ranges": T.value,
963
+ "is-time-disabled": i.isTimeDisabled
964
+ }, null, 8, ["open", "initTime", "format", "hour-step", "minute-step", "second-step", "min-time", "max-time", "disabled-ranges", "is-time-disabled"])) : Z("", !0)
861
965
  ])
862
- ], 8, Be));
966
+ ], 12, Be));
863
967
  }
864
968
  });
865
969
  export {