UNPKG

v-datepicker-lite

Version:

A lightweight Vue 3 date picker with date, time, date-time, week, and month modes

1,089 lines (1,088 loc) 39 kB
import { defineComponent as x, computed as H, createElementBlock as k, openBlock as h, createElementVNode as f, Fragment as I, renderList as A, unref as D, toDisplayString as N, normalizeClass as F, ref as P, watch as B, nextTick as L, onMounted as K, shallowRef as oe, isMemoSame as re, createTextVNode as Z, withMemo as ie, createCommentVNode as q, createBlock as W, createVNode as E, renderSlot as Q, normalizeProps as ee, guardReactiveProps as te, withCtx as G } from "vue"; import ce from "v-tooltip-lite"; const U = (t, i = "YYYY-MM-DD") => { const a = t.getFullYear(), s = String(t.getMonth() + 1).padStart(2, "0"), e = String(t.getDate()).padStart(2, "0"), u = String(t.getHours()).padStart(2, "0"), n = String(t.getMinutes()).padStart(2, "0"), c = String(t.getSeconds()).padStart(2, "0"), o = String(t.getMilliseconds()).padStart(3, "0"); return i.replace("YYYY", a.toString()).replace("MM", s).replace("DD", e).replace("HH", u).replace("mm", n).replace("ss", c).replace("sss", o); }, J = (t) => { if (!t) return null; if (/^\d{4}-\d{2}-\d{2}$/.test(t)) { const [a, s, e] = t.split("-").map(Number); return new Date(a, s - 1, e); } const i = new Date(t); return isNaN(i.getTime()) ? null : i; }, R = (t, i) => t.getFullYear() === i.getFullYear() && t.getMonth() === i.getMonth() && t.getDate() === i.getDate(), ue = (t, i) => t.getFullYear() === i.getFullYear() && t.getMonth() === i.getMonth(), de = (t) => { const i = new Date(t.getFullYear(), 0, 1), a = (t.getTime() - i.getTime()) / 864e5; return Math.ceil((a + i.getDay() + 1) / 7); }, le = (t, i) => { const a = new Date(t, i, 1), e = new Date(t, i + 1, 0).getDate(), u = a.getDay(), n = [], c = /* @__PURE__ */ new Date(), o = i === 0 ? 11 : i - 1, g = i === 0 ? t - 1 : t, S = new Date(g, o + 1, 0).getDate(); for (let v = u - 1; v >= 0; v--) { const r = new Date(g, o, S - v); n.push({ date: r, day: S - v, month: o, year: g, isCurrentMonth: !1, isToday: R(r, c), isSelected: !1, isDisabled: !1 }); } for (let v = 1; v <= e; v++) { const r = new Date(t, i, v); n.push({ date: r, day: v, month: i, year: t, isCurrentMonth: !0, isToday: R(r, c), isSelected: !1, isDisabled: !1 }); } const M = 42 - n.length, T = i === 11 ? 0 : i + 1, $ = i === 11 ? t + 1 : t; for (let v = 1; v <= M; v++) { const r = new Date($, T, v); n.push({ date: r, day: v, month: T, year: $, isCurrentMonth: !1, isToday: R(r, c), isSelected: !1, isDisabled: !1 }); } return n; }, me = (t, i) => { const a = le(t, i), s = []; for (let e = 0; e < a.length; e += 7) { const u = a.slice(e, e + 7), n = de(u[0].date); s.push({ weekNumber: n, days: u, isSelected: !1 }); } return s; }, ae = (t) => [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ].map((a, s) => ({ month: s, year: t, name: a, isSelected: !1, isDisabled: !1 })), se = (t, i, a, s) => { const e = U(t, "YYYY-MM-DD"); return i && e < i || a && e > a ? !0 : s ? s.some((u) => u.end ? e >= u.start && e <= u.end : e === u.start) : !1; }, X = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ], ne = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], ve = { class: "date-picker-content dates" }, pe = { class: "date-picker-table" }, he = { class: "date-picker-weekdays-row" }, fe = { class: "date-picker-days-body" }, ge = ["onClick", "disabled"], ke = /* @__PURE__ */ x({ __name: "DateView", props: { currentDate: {}, selectedDate: {}, minDate: {}, maxDate: {}, disabledDates: {} }, emits: ["select"], setup(t, { emit: i }) { const a = t, s = i, e = H(() => le(a.currentDate.getFullYear(), a.currentDate.getMonth()).map((o) => ({ ...o, isSelected: a.selectedDate ? R(o.date, a.selectedDate) : !1, isDisabled: se(o.date, a.minDate, a.maxDate, a.disabledDates) }))), u = H(() => { const c = []; for (let o = 0; o < e.value.length; o += 7) c.push(e.value.slice(o, o + 7)); return c.filter((o) => o.some((g) => g.isCurrentMonth)); }), n = (c) => { c.isDisabled || s("select", c.date); }; return (c, o) => (h(), k("div", ve, [ f("table", pe, [ f("thead", null, [ f("tr", he, [ (h(!0), k(I, null, A(D(ne), (g) => (h(), k("th", { key: g }, N(g), 1))), 128)) ]) ]), f("tbody", fe, [ (h(!0), k(I, null, A(u.value, (g, S) => (h(), k("tr", { key: S, class: "date-picker-week-row" }, [ (h(!0), k(I, null, A(g, (M) => (h(), k("td", { key: `${M.year}-${M.month}-${M.day}`, class: "date-picker-day-cell" }, [ f("button", { class: F([ "date-picker-day", { "other-month": !M.isCurrentMonth, today: M.isToday, selected: M.isSelected, disabled: M.isDisabled } ]), onClick: (T) => n(M), disabled: M.isDisabled }, N(M.day), 11, ge) ]))), 128)) ]))), 128)) ]) ]) ])); } }), De = { class: "date-picker-content" }, ye = { class: "date-picker-table date-picker-week-table", cellpadding: "0", cellspacing: "0" }, Me = { class: "date-picker-weekdays-row" }, be = { class: "date-picker-weeks-body" }, Se = ["onClick"], _e = { class: "date-picker-week-number-cell" }, we = { class: "date-picker-week-number" }, Ye = /* @__PURE__ */ x({ __name: "WeekView", props: { currentDate: {}, selectedDate: {} }, emits: ["select"], setup(t, { emit: i }) { const a = t, s = i, e = H(() => me(a.currentDate.getFullYear(), a.currentDate.getMonth()).map((c) => { const o = a.selectedDate ? c.days.some((g) => R(g.date, a.selectedDate)) : !1; return { ...c, isSelected: o }; })), u = (n) => { var o; const c = ((o = n.days.find((g) => g.isCurrentMonth)) == null ? void 0 : o.date) || n.days[0].date; s("select", c); }; return (n, c) => (h(), k("div", De, [ f("table", ye, [ f("thead", null, [ f("tr", Me, [ c[0] || (c[0] = f("th", { class: "date-picker-weekday date-picker-week-header" }, "Wk", -1)), (h(!0), k(I, null, A(D(ne), (o) => (h(), k("th", { key: o }, N(o), 1))), 128)) ]) ]), f("tbody", be, [ (h(!0), k(I, null, A(e.value, (o) => (h(), k("tr", { key: o.weekNumber, class: F([ "date-picker-week-row", { selected: o.isSelected } ]), onClick: (g) => u(o) }, [ f("td", _e, [ f("div", we, N(o.weekNumber), 1) ]), (h(!0), k(I, null, A(o.days, (g) => (h(), k("td", { key: `${g.year}-${g.month}-${g.day}`, class: "date-picker-day-cell" }, [ f("button", { class: F([ "date-picker-day", { "other-month": !g.isCurrentMonth, today: g.isToday } ]) }, N(g.day), 3) ]))), 128)) ], 10, Se))), 128)) ]) ]) ])); } }); function $e(t, i = "24h", a = 1, s) { const e = P(0), u = P(0), n = P([]), c = P(!1), o = H(() => i === "12h"), g = () => { if (t) e.value = t.getHours(), u.value = t.getMinutes(), c.value = !0; else { const l = /* @__PURE__ */ new Date(); e.value = l.getHours(), u.value = l.getMinutes(), c.value = !1; } M(); }, S = (l) => { l ? (e.value = l.getHours(), u.value = l.getMinutes(), c.value = !0) : c.value = !1; }, M = () => { const l = [], d = o.value ? 1 : 0; for (let p = 0; p < (o.value ? 2 : 1); p++) { const C = o.value ? p === 0 ? " AM" : " PM" : ""; for (let y = d; y <= (o.value ? 12 : 23); y++) for (let b = 0; b < 60; b += a) { const m = (o.value, y), _ = o.value ? y === 12 ? p === 0 ? 0 : 12 : y + p * 12 : y, O = `${String(m).padStart(2, "0")}:${String(b).padStart(2, "0")}` + C; l.push({ display: O, value: `${String(_).padStart(2, "0")}:${String(b).padStart(2, "0")}`, hour: _, minute: b }); } } o.value ? n.value = l.map((p) => p.display) : n.value = l.map((p) => p.value); }, T = () => { if (!c.value) return ""; if (o.value) { const l = e.value === 0 ? 12 : e.value > 12 ? e.value - 12 : e.value, d = e.value < 12 ? " AM" : " PM"; return `${String(l).padStart(2, "0")}:${String(u.value).padStart( 2, "0" )}${d}`; } return `${String(e.value).padStart(2, "0")}:${String(u.value).padStart(2, "0")}`; }; return { hours: e, minutes: u, timeOptions: n, is12HourFormat: o, initializeTime: g, updateTime: S, generateTimeOptions: M, getCurrentTimeString: T, selectTime: (l) => { let d, p; if (o.value) { const [y, b] = l.split(" "), [m, _] = y.split(":"); d = parseInt(m), p = parseInt(_), b === "AM" ? d === 12 && (d = 0) : d !== 12 && (d += 12); } else { const [y, b] = l.split(":"); d = parseInt(y), p = parseInt(b); } if (c.value && e.value === d && u.value === p) { c.value = !1, s("update", null); return; } e.value = d, u.value = p, c.value = !0; const C = t ? new Date(t.getTime()) : /* @__PURE__ */ new Date(); C.setHours(d, p, 0, 0), s("update", C); }, scrollToSelected: (l) => { if (!l || !c.value) return; const d = n.value.findIndex((p) => p === T()); if (d >= 0) { const C = l.clientHeight, y = d * 30 - C / 2 + 30 / 2; l.scrollTop = Math.max(0, y); } }, onTimeUpdate: (l) => { e.value = l.getHours(), u.value = l.getMinutes(), c.value = !0, s("update", l); } }; } const Te = { class: "time-picker-container" }, He = ["aria-selected", "onClick"], j = /* @__PURE__ */ x({ __name: "TimeView", props: { selectedTime: {}, timeFormat: { default: "24h" }, minuteInterval: { default: 1 } }, emits: ["update"], setup(t, { emit: i }) { const a = t, s = i, e = P(null), { timeOptions: u, initializeTime: n, updateTime: c, getCurrentTimeString: o, selectTime: g, scrollToSelected: S } = $e(a.selectedTime, a.timeFormat, a.minuteInterval, s); return B( () => a.selectedTime, (M) => { c(M), L(() => { S(e.value); }); }, { immediate: !0 } ), B( () => a.timeFormat, () => { n(), L(() => { S(e.value); }); } ), B( () => a.minuteInterval, () => { n(), L(() => { S(e.value); }); } ), K(() => { n(), L(() => { setTimeout(() => { S(e.value); }, 3); }); }), (M, T) => (h(), k("div", Te, [ f("div", { ref_key: "timeListRef", ref: e, class: "time-wheel", role: "listbox", "aria-label": "Time Selection" }, [ (h(!0), k(I, null, A(D(u), ($) => (h(), k("div", { key: $, class: F(["time-option", { selected: $ === D(o)() }]), role: "option", "aria-selected": $ === D(o)(), onClick: (v) => D(g)($) }, N($), 11, He))), 128)) ], 512) ])); } }), Ce = { class: "year-view-layout" }, Pe = { class: "years-section" }, Fe = { class: "months-section" }, Ie = { class: "date-picker-table date-picker-months-table" }, Ae = { class: "date-picker-months-body" }, Ne = /* @__PURE__ */ x({ __name: "YearView", props: { currentDate: {}, selectedDate: {} }, emits: ["select", "month-select"], setup(t, { emit: i }) { const a = t, s = i, e = H(() => a.currentDate.getFullYear()), u = H(() => { var l; return (l = a.selectedDate) == null ? void 0 : l.getFullYear(); }), n = oe([]), c = P(null), o = P(!1), g = () => { const d = (/* @__PURE__ */ new Date()).getFullYear() + 20, p = u.value || e.value, C = Math.max(1900, p - 40), y = Math.min(d, p + 9), b = []; for (let m = C; m <= y; m++) b.push(m); n.value = b; }; K(() => { g(), S(!1); }), B( () => a.currentDate, (l, d) => { if (l.getFullYear() !== d.getFullYear()) { const p = l.getFullYear(); (!n.value.includes(p) || n.value.indexOf(p) < 10 || n.value.indexOf(p) > n.value.length - 10) && g(), S(!0); } } ); const S = (l = !1) => { L(() => { setTimeout(() => { if (!c.value) return; const d = c.value.querySelector(".year-item.selected") || c.value.querySelector(".year-item.current"); d && d.scrollIntoView({ block: "center", behavior: l ? "smooth" : "auto" }); }, 50); }); }, M = async (l) => { const d = l.target; if (!d || o.value) return; const p = 1900, C = (/* @__PURE__ */ new Date()).getFullYear() + 30; if (d.scrollTop === 0) { const y = n.value[0]; if (y > p) { o.value = !0; const b = Math.min(20, y - p), m = Array.from({ length: b }, (O, w) => y - b + w), _ = d.scrollHeight; n.value = [...m, ...n.value], await L(); const Y = d.scrollHeight; d.scrollTop = Y - _, setTimeout(() => { o.value = !1; }, 50); } } else if (d.scrollTop + d.clientHeight >= d.scrollHeight - 5) { const y = n.value[n.value.length - 1]; if (y < C) { o.value = !0; const b = Math.min(10, C - y), m = Array.from({ length: b }, (_, Y) => y + 1 + Y); n.value = [...n.value, ...m], await L(), setTimeout(() => { o.value = !1; }, 50); } } }, T = H(() => ae(e.value).map((l) => ({ ...l, isSelected: a.selectedDate ? l.month === a.selectedDate.getMonth() && l.year === a.selectedDate.getFullYear() : !1 }))), $ = H(() => { const l = []; for (let d = 0; d < T.value.length; d += 3) l.push(T.value.slice(d, d + 3)); return l; }), v = (l) => { s("select", l); }, r = (l) => { s("month-select", l.month); }; return (l, d) => (h(), k("div", Ce, [ f("div", Pe, [ f("div", { class: "years-list", ref_key: "yearsListRef", ref: c, onScroll: M }, [ (h(!0), k(I, null, A(n.value, (p, C, y, b) => { const m = [p, p === u.value, p === e.value]; if (b && b.key === p && re(b, m)) return b; const _ = (h(), k("button", { key: p, class: F([ "year-item", { selected: p === u.value, current: p === e.value } ]), onClick: (Y) => v(p) }, [ Z(N(p), 1) ], 10, ["onClick"])); return _.memo = m, _; }, d, 0), 128)) ], 544) ]), f("div", Fe, [ f("table", Ie, [ f("tbody", Ae, [ (h(!0), k(I, null, A($.value, (p, C) => (h(), k("tr", { key: C, class: "date-picker-months-row" }, [ (h(!0), k(I, null, A(p, (y) => (h(), k("td", { key: y.month, class: "date-picker-month-cell" }, [ ie([y.month, y.isSelected, y.isDisabled], () => (h(), k("button", { class: F([ "date-picker-month", { selected: y.isSelected, disabled: y.isDisabled } ]), onClick: (b) => r(y), disabled: y.isDisabled }, [ Z(N(y.name.substring(0, 3)), 1) ], 10, ["onClick", "disabled"])), d, 2) ]))), 128)) ]))), 128)) ]) ]) ]) ])); } }), Ve = { class: "date-picker-content months" }, xe = { class: "date-picker-table date-picker-months-table" }, qe = { class: "date-picker-months-body" }, Be = ["onClick", "disabled"], Le = /* @__PURE__ */ x({ __name: "MonthView", props: { currentDate: {}, selectedDate: {} }, emits: ["select"], setup(t, { emit: i }) { const a = t, s = i, e = H(() => ae(a.currentDate.getFullYear()).map((o) => ({ ...o, isSelected: a.selectedDate ? o.month === a.selectedDate.getMonth() && o.year === a.selectedDate.getFullYear() : !1 }))), u = H(() => { const c = []; for (let o = 0; o < e.value.length; o += 3) c.push(e.value.slice(o, o + 3)); return c; }), n = (c) => { s("select", c.month); }; return (c, o) => (h(), k("div", Ve, [ f("table", xe, [ f("tbody", qe, [ (h(!0), k(I, null, A(u.value, (g, S) => (h(), k("tr", { key: S, class: "date-picker-months-row" }, [ (h(!0), k(I, null, A(g, (M) => (h(), k("td", { key: M.month, class: "date-picker-month-cell" }, [ f("button", { class: F([ "date-picker-month", { selected: M.isSelected, disabled: M.isDisabled } ]), onClick: (T) => n(M), disabled: M.isDisabled }, N(M.name), 11, Be) ]))), 128)) ]))), 128)) ]) ]) ])); } }), Re = /* @__PURE__ */ x({ __name: "DatePickerHeader", props: { currentDate: {}, viewMode: {} }, emits: ["header-click"], setup(t, { emit: i }) { const a = t, s = i, e = H(() => { const n = a.currentDate.getFullYear(), c = a.currentDate.getMonth(); switch (a.viewMode) { case "date": return `${X[c]} ${n}`; case "year": const o = Math.floor(n / 10) * 10, g = o + 9; return `${o}${g}`; default: return `${X[c]} ${n}`; } }), u = () => { s("header-click"); }; return (n, c) => (h(), k("button", { class: "date-picker-title", onClick: u, type: "button" }, N(e.value), 1)); } }); function Oe(t, i) { const a = H(() => t.value ? t.value instanceof Date ? t.value : J(t.value) : null), s = P(a.value ? new Date(a.value) : /* @__PURE__ */ new Date()), e = P("date"); B(a, (m) => { m && (s.value.getFullYear() !== m.getFullYear() || s.value.getMonth() !== m.getMonth()) && (s.value = new Date(m)); }); const u = (m) => { const _ = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z?$/, Y = /^\d{4}-\d{2}-\d{2}$/; return _.test(m) ? m.includes(".") ? "YYYY-MM-DDTHH:mm:ss.sssZ" : "YYYY-MM-DDTHH:mm:ssZ" : Y.test(m) ? "YYYY-MM-DD" : t.format || "YYYY-MM-DD"; }, n = H(() => { if (!t.value) return !1; if (t.value instanceof Date) return !0; const m = u(t.value); return m.includes("H") || m.includes("h") || m.includes("m") || m.includes("T"); }), c = H(() => { if (!t.minDate) return !0; const m = J(t.minDate); if (!m) return !0; const _ = s.value.getFullYear(), Y = s.value.getMonth(); return new Date(_, Y, 1) > m; }), o = H(() => { if (!t.maxDate) return !0; const m = J(t.maxDate); if (!m) return !0; const _ = s.value.getFullYear(), Y = s.value.getMonth(); return new Date(_, Y + 1, 0) < m; }), g = () => { c.value && (s.value = new Date(s.value.getFullYear(), s.value.getMonth() - 1, 1)); }, S = () => { o.value && (s.value = new Date(s.value.getFullYear(), s.value.getMonth() + 1, 1)); }, M = () => { s.value = new Date(s.value.getFullYear() - 1, s.value.getMonth(), 1); }, T = () => { s.value = new Date(s.value.getFullYear() + 1, s.value.getMonth(), 1); }, $ = () => { s.value = new Date(s.value.getFullYear() - 10, s.value.getMonth(), 1); }, v = () => { s.value = new Date(s.value.getFullYear() + 10, s.value.getMonth(), 1); }, r = () => { s.value = /* @__PURE__ */ new Date(), e.value = "date"; }, l = () => { switch (e.value) { case "date": e.value = "year"; break; case "year": e.value = "date"; break; } }, d = (m) => { if (!se(m, t.minDate, t.maxDate, t.disabledDates)) { if (a.value && R(a.value, m)) { i("update:value", null), i("change", null), i("select", null); return; } t.mode === "dateTime" && a.value && m.setHours(a.value.getHours(), a.value.getMinutes()), b(m); } }, p = (m) => { if (a.value && R(a.value, m)) { i("update:value", null), i("change", null), i("select", null); return; } b(m); }, C = (m) => { const _ = new Date(s.value.getFullYear(), m, 1); if (s.value = _, e.value = "date", t.mode === "month") { if (a.value && ue(a.value, _)) { i("update:value", null), i("change", null), i("select", null); return; } b(_); } }, y = (m) => { s.value = new Date(m, s.value.getMonth(), 1), e.value = "date"; }, b = (m, _ = !1) => { let Y; if (typeof t.value == "string" || t.value === null || t.value === void 0) if (t.format && t.format !== "YYYY-MM-DD" && !_ && t.mode !== "dateTime" && t.mode !== "time") Y = U(m, t.format); else if (t.mode === "dateTime" || t.mode === "time" || _) Y = m.toISOString(); else { const O = m.getFullYear(), w = String(m.getMonth() + 1).padStart(2, "0"), V = String(m.getDate()).padStart(2, "0"); Y = `${O}-${w}-${V}`; } else Y = m; i("update:value", Y), i("change", Y), i("select", Y); }; return { currentDate: s, viewMode: e, selectedDate: a, canGoPrev: c, canGoNext: o, hasTime: n, goToPrevMonth: g, goToNextMonth: S, goToPrevYear: M, goToNextYear: T, goToPrevDecade: $, goToNextDecade: v, goToCurrentDate: r, onHeaderClick: l, onDateSelect: d, onWeekSelect: p, onMonthSelect: C, onYearSelect: y, emitValue: b }; } const ze = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><g fill="none" fill-rule="evenodd"><path d="M24 0v24H0V0zM12.593 23.258l-.011.002l-.071.035l-.02.004l-.014-.004l-.071-.035q-.016-.005-.024.005l-.004.01l-.017.428l.005.02l.01.013l.104.074l.015.004l.012-.004l.104-.074l.012-.016l.004-.017l-.017-.427q-.004-.016-.017-.018m.265-.113l-.013.002l-.185.093l-.01.01l-.003.011l.018.43l.005.012l.008.007l.201.093q.019.005.029-.008l.004-.014l-.034-.614q-.005-.019-.02-.022m-.715.002a.02.02 0 0 0-.027.006l-.006.014l-.034.614q.001.018.017.024l.015-.002l.201-.093l.01-.008l.004-.011l.017-.43l-.003-.012l-.01-.01z"/><path fill="currentColor" d="M8.293 12.707a1 1 0 0 1 0-1.414l5.657-5.657a1 1 0 1 1 1.414 1.414L10.414 12l4.95 4.95a1 1 0 0 1-1.414 1.414z"/></g></svg>', We = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><g fill="none" fill-rule="evenodd"><path d="M24 0v24H0V0zM12.593 23.258l-.011.002l-.071.035l-.02.004l-.014-.004l-.071-.035q-.016-.005-.024.005l-.004.01l-.017.428l.005.02l.01.013l.104.074l.015.004l.012-.004l.104-.074l.012-.016l.004-.017l-.017-.427q-.004-.016-.017-.018m.265-.113l-.013.002l-.185.093l-.01.01l-.003.011l.018.43l.005.012l.008.007l.201.093q.019.005.029-.008l.004-.014l-.034-.614q-.005-.019-.02-.022m-.715.002a.02.02 0 0 0-.027.006l-.006.014l-.034.614q.001.018.017.024l.015-.002l.201-.093l.01-.008l.004-.011l.017-.43l-.003-.012l-.01-.01z"/><path fill="currentColor" d="M15.707 11.293a1 1 0 0 1 0 1.414l-5.657 5.657a1 1 0 1 1-1.414-1.414l4.95-4.95l-4.95-4.95a1 1 0 0 1 1.414-1.414z"/></g></svg>', Ee = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M12 18a6 6 0 1 1 0-12a6 6 0 0 1 0 12m0-1.5a4.5 4.5 0 1 0 0-9a4.5 4.5 0 0 0 0 9"/></svg>', Ge = { key: 0, class: "date-picker-header" }, Je = { class: "date-picker-nav ml-auto" }, Ue = ["disabled"], Ze = ["innerHTML"], Xe = ["innerHTML"], je = ["disabled"], Ke = ["innerHTML"], Qe = { class: "date-picker-date-section" }, et = { key: 0, class: "date-picker-time-section" }, ht = /* @__PURE__ */ x({ __name: "DatePicker", props: { value: {}, mode: { default: "date" }, minDate: {}, maxDate: {}, disabledDates: {}, format: { default: "YYYY-MM-DD" }, disabled: { type: Boolean }, readonly: { type: Boolean }, timeFormat: { default: "24h" }, minuteInterval: { default: 1 } }, emits: ["update:value", "change", "select"], setup(t, { emit: i }) { const a = t, s = i, { currentDate: e, viewMode: u, selectedDate: n, canGoPrev: c, canGoNext: o, hasTime: g, goToPrevMonth: S, goToNextMonth: M, goToPrevYear: T, goToNextYear: $, goToPrevDecade: v, goToNextDecade: r, goToCurrentDate: l, onHeaderClick: d, onDateSelect: p, onWeekSelect: C, onMonthSelect: y, onYearSelect: b, emitValue: m } = Oe(a, s), _ = (w) => { if (w === null) { if (n.value) { const V = new Date(n.value); V.setHours(0, 0, 0, 0); const z = U(V, "YYYY-MM-DD"); s("update:value", z), s("change", z), s("select", z); } return; } if (a.mode === "dateTime" && n.value) { const V = new Date(n.value.getTime()); V.setHours(w.getHours(), w.getMinutes(), 0, 0), m(V, !0); } else m(w, !0); }, Y = () => { u.value === "year" ? v() : u.value === "month" ? T() : S(); }, O = () => { u.value === "year" ? r() : u.value === "month" ? $() : M(); }; return (w, V) => (h(), k("div", { class: F(["date-picker", w.mode == "dateTime" && "date-picker-container-wide"]) }, [ w.mode !== "time" ? (h(), k("div", Ge, [ E(Re, { "current-date": D(e), "view-mode": D(u), onHeaderClick: D(d) }, null, 8, ["current-date", "view-mode", "onHeaderClick"]), f("div", Je, [ f("button", { class: "date-picker-nav-button", disabled: !D(c), onClick: Y, type: "button", "aria-label": "Previous" }, [ f("span", { class: "date-picker-nav-icon", innerHTML: D(ze) }, null, 8, Ze) ], 8, Ue), f("button", { class: "date-picker-nav-button", onClick: V[0] || (V[0] = //@ts-ignore (...z) => D(l) && D(l)(...z)), type: "button", "aria-label": "Current Date" }, [ f("span", { class: "date-picker-nav-icon", innerHTML: D(Ee) }, null, 8, Xe) ]), f("button", { class: "date-picker-nav-button", disabled: !D(o), onClick: O, type: "button", "aria-label": "Next" }, [ f("span", { class: "date-picker-nav-icon", innerHTML: D(We) }, null, 8, Ke) ], 8, je) ]) ])) : q("", !0), f("div", { class: F({ "date-picker-datetime-layout": w.mode === "dateTime" && D(u) === "date" }) }, [ f("div", Qe, [ D(u) === "date" && (w.mode === "date" || w.mode === "dateTime") ? (h(), W(ke, { key: 0, "current-date": D(e), "selected-date": D(n), "min-date": w.minDate, "max-date": w.maxDate, "disabled-dates": w.disabledDates, onSelect: D(p) }, null, 8, ["current-date", "selected-date", "min-date", "max-date", "disabled-dates", "onSelect"])) : q("", !0), w.mode === "week" && D(u) === "date" ? (h(), W(Ye, { key: 1, "current-date": D(e), "selected-date": D(n), onSelect: D(C) }, null, 8, ["current-date", "selected-date", "onSelect"])) : q("", !0), D(u) !== "year" && (D(u) === "month" || w.mode === "month") ? (h(), W(Le, { key: 2, "current-date": D(e), "selected-date": D(n), onSelect: D(y) }, null, 8, ["current-date", "selected-date", "onSelect"])) : q("", !0), D(u) === "year" ? (h(), W(Ne, { key: 3, "current-date": D(e), "selected-date": D(n), onSelect: D(b), onMonthSelect: D(y) }, null, 8, ["current-date", "selected-date", "onSelect", "onMonthSelect"])) : q("", !0) ]), w.mode === "dateTime" && D(u) === "date" ? (h(), k("div", et, [ E(j, { "selected-time": D(g) ? D(n) : null, "time-format": w.timeFormat, "minute-interval": w.minuteInterval, onUpdate: _ }, null, 8, ["selected-time", "time-format", "minute-interval"]) ])) : q("", !0) ], 2), w.mode === "time" ? (h(), W(j, { key: 1, "selected-time": D(n), "time-format": w.timeFormat, "minute-interval": w.minuteInterval, onUpdate: _ }, null, 8, ["selected-time", "time-format", "minute-interval"])) : q("", !0) ], 2)); } }), tt = { ref: "dropdownRef", class: "time-picker-dropdown" }, lt = { class: "time-picker-sections" }, at = { class: "time-picker-time-section" }, st = ["onClick"], nt = { class: "time-picker-time-section" }, ot = ["onClick"], rt = { key: 0, class: "time-picker-time-section time-picker-period-section" }, it = /* @__PURE__ */ x({ __name: "TimePickerDropdown", props: { selectedHour: {}, selectedMinute: {}, selectedPeriod: {}, is12Hour: { type: Boolean }, minuteInterval: { default: 1 } }, emits: ["select-hour", "select-minute", "select-period", "close"], setup(t, { expose: i, emit: a }) { const s = t, e = a, u = P(null), n = P(null), c = P(null), o = H(() => s.is12Hour ? Array.from({ length: 12 }, (v, r) => r + 1) : Array.from({ length: 24 }, (v, r) => r)), g = H(() => { const v = s.minuteInterval, r = Math.floor(60 / v); return Array.from({ length: r }, (l, d) => d * v); }), S = () => { if (u.value) { const v = u.value.querySelectorAll(".time-picker-option-button"), r = Array.from(v).findIndex((l) => l.classList.contains("selected")); r !== -1 && v[r].scrollIntoView({ block: "center", behavior: "auto" }); } if (n.value) { const v = n.value.querySelectorAll(".time-picker-option-button"), r = Array.from(v).findIndex((l) => l.classList.contains("selected")); r !== -1 && v[r].scrollIntoView({ block: "center", behavior: "auto" }); } if (s.is12Hour && c.value) { const v = c.value.querySelectorAll(".time-picker-option-button"), r = Array.from(v).findIndex((l) => l.classList.contains("selected")); r !== -1 && v[r].scrollIntoView({ block: "center", behavior: "auto" }); } }, M = (v) => { e("select-hour", v); }, T = (v) => { e("select-minute", v); }, $ = (v) => { e("select-period", v); }; return i({ scrollToSelected: S }), (v, r) => (h(), k("div", tt, [ f("div", lt, [ f("div", at, [ f("div", { ref_key: "hourScroll", ref: u, class: "time-picker-options-scroll" }, [ (h(!0), k(I, null, A(o.value, (l) => (h(), k("button", { key: l, type: "button", class: F(["time-picker-option-button", { selected: l === v.selectedHour }]), onClick: (d) => M(l) }, N(String(l).padStart(2, "0")), 11, st))), 128)) ], 512) ]), f("div", nt, [ f("div", { ref_key: "minuteScroll", ref: n, class: "time-picker-options-scroll" }, [ (h(!0), k(I, null, A(g.value, (l) => (h(), k("button", { key: l, type: "button", class: F(["time-picker-option-button", { selected: l === v.selectedMinute }]), onClick: (d) => T(l) }, N(String(l).padStart(2, "0")), 11, ot))), 128)) ], 512) ]), v.is12Hour ? (h(), k("div", rt, [ f("div", { ref_key: "periodScroll", ref: c, class: "time-picker-options-scroll" }, [ f("button", { type: "button", class: F(["time-picker-option-button", { selected: v.selectedPeriod === "AM" }]), onClick: r[0] || (r[0] = (l) => $("AM")) }, " AM ", 2), f("button", { type: "button", class: F(["time-picker-option-button", { selected: v.selectedPeriod === "PM" }]), onClick: r[1] || (r[1] = (l) => $("PM")) }, " PM ", 2) ], 512) ])) : q("", !0) ]) ], 512)); } }), ct = ["disabled"], ut = { class: "time-display" }, dt = /* @__PURE__ */ x({ __name: "TimePickerInput", props: { hour: {}, minute: {}, period: {}, is12Hour: { type: Boolean }, triggerClass: {}, disabled: { type: Boolean }, readonly: { type: Boolean } }, setup(t) { const i = t, a = H(() => { const s = String(i.minute).padStart(2, "0"); if (i.is12Hour) { let e = i.hour % 12; return e === 0 && (e = 12), `${String(e).padStart(2, "0")}:${s} ${i.period}`; } else return `${String(i.hour).padStart(2, "0")}:${s}`; }); return (s, e) => Q(s.$slots, "default", ee(te({ displayTime: a.value })), () => [ f("button", { type: "button", class: F(["time-picker-input", [s.triggerClass, { "is-disabled": s.disabled, "is-readonly": s.readonly }]]), disabled: s.disabled || s.readonly }, [ f("span", ut, N(a.value), 1), e[0] || (e[0] = f("svg", { class: "time-picker-clock-icon", xmlns: "http://www.w3.org/2000/svg", width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round" }, [ f("circle", { cx: "12", cy: "12", r: "10" }), f("polyline", { points: "12,6 12,12 16,14" }) ], -1)) ], 10, ct) ]); } }), mt = { style: { width: "100%" } }, ft = /* @__PURE__ */ x({ __name: "TimePicker", props: { modelValue: { default: null }, timeFormat: { default: "12h" }, triggerClass: {}, style: {}, className: {}, offset: { default: () => [0, 10] }, minuteInterval: { default: 1 }, disabled: { type: Boolean, default: !1 }, readonly: { type: Boolean, default: !1 } }, emits: ["update:modelValue"], setup(t, { emit: i }) { const a = t, s = i, e = P(12), u = P(0), n = P("AM"), c = P(null), o = H(() => a.timeFormat === "12h"), g = () => { if (a.modelValue) { let r = 0, l = 0; if (a.modelValue instanceof Date) r = a.modelValue.getHours(), l = a.modelValue.getMinutes(); else if (typeof a.modelValue == "string") { const [d, p] = a.modelValue.split(":"); r = parseInt(d), l = parseInt(p); } else { const d = /* @__PURE__ */ new Date(); r = d.getHours(), l = d.getMinutes(); } u.value = l, o.value ? r === 0 ? (e.value = 12, n.value = "AM") : r === 12 ? (e.value = 12, n.value = "PM") : r > 12 ? (e.value = r - 12, n.value = "PM") : (e.value = r, n.value = "AM") : e.value = r; } else { const r = /* @__PURE__ */ new Date(), l = r.getHours(), d = r.getMinutes(); u.value = d, o.value ? l === 0 ? (e.value = 12, n.value = "AM") : l === 12 ? (e.value = 12, n.value = "PM") : l > 12 ? (e.value = l - 12, n.value = "PM") : (e.value = l, n.value = "AM") : e.value = l; } }, S = () => { let r = e.value; o.value && (n.value === "AM" && r === 12 ? r = 0 : n.value === "PM" && r !== 12 && (r += 12)); const l = `${String(r).padStart(2, "0")}:${String(u.value).padStart(2, "0")}`; s("update:modelValue", l); }, M = (r) => { e.value = r, S(); }, T = (r) => { u.value = r, S(); }, $ = (r) => { n.value = r, S(); }, v = () => { var r; (r = c == null ? void 0 : c.value) == null || r.scrollToSelected(); }; return B(() => a.modelValue, g, { immediate: !0 }), B(() => a.timeFormat, g), B(() => a.minuteInterval, g), (r, l) => (h(), k("div", mt, [ E(D(ce), { trigger: "click", placement: "bottom-start", onOnShow: v, teleport: "", arrow: !1, offset: r.offset, triggerClass: "w-full", "class-name": `v-time-picker ${r.className}`, styles: r.style, style: { width: "100%" } }, { trigger: G(() => [ E(dt, { hour: e.value, minute: u.value, period: n.value, "is12-hour": o.value, "trigger-class": r.triggerClass, disabled: r.disabled, readonly: r.readonly }, { default: G(({ displayTime: d }) => [ Q(r.$slots, "default", ee(te({ displayTime: d }))) ]), _: 3 }, 8, ["hour", "minute", "period", "is12-hour", "trigger-class", "disabled", "readonly"]) ]), default: G(() => [ E(it, { ref_key: "dropdownRef", ref: c, "selected-hour": e.value, "selected-minute": u.value, "selected-period": n.value, "is12-hour": o.value, "minute-interval": r.minuteInterval, onSelectHour: M, onSelectMinute: T, onSelectPeriod: $ }, null, 8, ["selected-hour", "selected-minute", "selected-period", "is12-hour", "minute-interval"]) ]), _: 3 }, 8, ["offset", "class-name", "styles"]) ])); } }); export { ft as TimePicker, ht as default };