nepali-datepicker-vue
Version:
A Vue 3 Nepali Datepicker with TypeScript Support
647 lines (646 loc) • 37.5 kB
JavaScript
var be = Object.defineProperty;
var Se = (r, e, a) => e in r ? be(r, e, { enumerable: !0, configurable: !0, writable: !0, value: a }) : r[e] = a;
var H = (r, e, a) => Se(r, typeof e != "symbol" ? e + "" : e, a);
import { defineComponent as _e, ref as N, watch as $e, computed as Q, onUnmounted as Fe, createElementBlock as h, openBlock as c, normalizeClass as I, createElementVNode as g, createVNode as Qe, withDirectives as Ie, createCommentVNode as f, withKeys as xe, vModelText as Ae, withModifiers as A, Transition as Be, withCtx as Oe, toDisplayString as E, Fragment as _, renderList as $, unref as te } from "vue";
var u = [{ year: 2e3, days: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2001, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2002, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2003, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2004, days: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2005, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2006, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2007, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2008, days: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2009, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2010, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2011, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2012, days: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2013, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2014, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2015, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2016, days: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2017, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2018, days: [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2019, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2020, days: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2021, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2022, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2023, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2024, days: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2025, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2026, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2027, days: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2028, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2029, days: [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2030, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2031, days: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2032, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2033, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2034, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2035, days: [30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2036, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2037, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2038, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2039, days: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2040, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2041, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2042, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2043, days: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2044, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2045, days: [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2046, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2047, days: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2048, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2049, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2050, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2051, days: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2052, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2053, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2054, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2055, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2056, days: [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2057, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2058, days: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2059, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2060, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2061, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2062, days: [30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2063, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2064, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2065, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2066, days: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2067, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2068, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2069, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2070, days: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2071, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2072, days: [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2073, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2074, days: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2075, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2076, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2077, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2078, days: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2079, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2080, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2081, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2082, days: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2083, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2084, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2085, days: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2086, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2087, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2088, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2089, days: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2090, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2091, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2092, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2093, days: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31], totalDays: 0, daysTillNow: 0 }, { year: 2094, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2095, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2096, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }, { year: 2097, days: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2098, days: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2099, days: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], totalDays: 0, daysTillNow: 0 }, { year: 2100, days: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], totalDays: 0, daysTillNow: 0 }], le = 0;
u.forEach((r) => {
r.totalDays = r.days.reduce((e, a) => e + a, 0), le += r.totalDays, r.daysTillNow = le;
});
var j = new Date(1943, 3, 14).getTime(), ne = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], J = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], oe = ["आइतबार", "सोमबार", "मंगलबार", "बुधबार", "बिहिबार", "शुक्रबार", "शनिबार"], ue = ["आइत", "सोम", "मंगल", "बुध", "बिहि", "शुक्र", "शनि"], Z = ["Baisakh", "Jestha", "Asar", "Shrawan", "Bhadra", "Aswin", "Kartik", "Mangsir", "Poush", "Magh", "Falgun", "Chaitra"], ye = ["Bai", "Jes", "Asa", "Shr", "Bhd", "Asw", "Kar", "Man", "Pou", "Mag", "Fal", "Cha"], ie = ["बैशाख", "जेठ", "असार", "श्रावण", "भाद्र", "आश्विन", "कार्तिक", "मंसिर", "पौष", "माघ", "फाल्गुण", "चैत्र"], de = ["बै", "जे", "अ", "श्रा", "भा", "आ", "का", "मं", "पौ", "मा", "फा", "चै"], He = ["०", "१", "२", "३", "४", "५", "६", "७", "८", "९"];
function U(r) {
return r < 10 ? `0${r}` : `${r}`;
}
function B(r) {
let e = "";
for (let a = 0; a < r.length; a += 1) e += He[r.charCodeAt(a) - 48];
return e;
}
function Le(r) {
return (e) => r <= 2 ? String(e.getYear()).substring(2) : r === 3 ? String(e.getYear()).substring(1) : String(e.getYear());
}
function Pe(r) {
return (e) => r <= 2 ? B(String(e.getYear()).substring(2)) : B(r === 3 ? String(e.getYear()).substring(1) : String(e.getYear()));
}
function We(r) {
return (e) => r === 1 ? String(e.getMonth() + 1) : r === 2 ? U(e.getMonth() + 1) : r === 3 ? ye[e.getMonth()] : Z[e.getMonth()];
}
function Re(r) {
return (e) => r === 1 ? B(String(e.getMonth() + 1)) : r === 2 ? B(U(e.getMonth() + 1)) : r === 3 ? de[e.getMonth()] : ie[e.getMonth()];
}
function Ke(r) {
return (e) => r === 1 ? String(e.getDate()) : r === 2 ? U(e.getDate()) : r === 3 ? J[e.getDay()] : ne[e.getDay()];
}
function ze(r) {
return (e) => r === 1 ? B(String(e.getDate())) : r === 2 ? B(U(e.getDate())) : r === 3 ? ue[e.getDay()] : oe[e.getDay()];
}
function se(r) {
return () => r;
}
var X = { Y: Le, y: Pe, M: We, m: Re, D: Ke, d: ze };
function je(r) {
return r in X;
}
function qe(r) {
let e = !1, a = "", o = "", l = 0, y = [];
for (let d = 0; d < r.length; d += 1) {
let w = r[d];
if (w === o) {
l += 1;
continue;
}
if (o !== "" && (y.push(X[o](l)), o = "", l = 0), w === '"') {
e = !e;
continue;
}
!je(w) || e ? a += w : (a && (y.push(se(a)), a = ""), o = w, l = 1);
}
return a ? y.push(se(a)) : o && y.push(X[o](l)), y;
}
function Je(r, e) {
return qe(e).map((a) => a(r)).join("");
}
function re(r) {
let e = r.split(/[-./]/, 3), [a, o = 1, l = 1] = e.map((d) => {
let w = parseInt(d, 10);
if (Number.isNaN(w)) throw new Error("Invalid date");
return w;
});
if (a < u[0].year || a >= u[0].year + u.length) throw new Error("Nepal year out of range");
if (o < 1 || o > 12) throw new Error("Invalid nepali month must be between 1 - 12");
let y = u[a - u[0].year].days[o - 1];
if (l < 1 || l > y) throw new Error(`Invalid nepali date must be between 1 - ${y} in ${a} ${o}`);
return [a, o - 1, l];
}
var v = class i {
constructor(...e) {
H(this, "timestamp");
H(this, "year");
H(this, "month");
H(this, "day");
if (e.length === 0) this.setEnglishDate(/* @__PURE__ */ new Date());
else if (e.length === 1) {
let a = e[0];
if (typeof a == "object") if (a instanceof Date) this.setEnglishDate(a);
else if (a instanceof i) this.timestamp = a.timestamp, this.year = a.year, this.month = a.month, this.day = a.day;
else throw new Error("Invalid date argument");
else if (typeof a == "string") this.set(...re(a));
else if (typeof a == "number") this.setEnglishDate(new Date(a));
else throw new Error("Invalid date argument");
} else if (e.length === 3) this.set(e[0], e[1], e[2]);
else throw new Error("Invalid argument syntax");
}
setEnglishDate(e) {
this.timestamp = e;
let a = Math.floor((this.timestamp.getTime() - j) / 864e5), o = Math.floor(a / 366);
for (; a >= u[o].daysTillNow; ) o += 1;
let l = u[o - 1] ? u[o - 1].daysTillNow : 0;
a -= l;
let y = u[o];
for (this.year = y.year, this.month = 0; a >= y.days[this.month]; ) this.month += 1, a -= y.days[this.month - 1];
this.day = a + 1;
}
getEnglishDate() {
return this.timestamp;
}
parse(e) {
this.set(...re(e));
}
getYear() {
return this.year;
}
getMonth() {
return this.month;
}
getDate() {
return this.day;
}
getDay() {
return this.timestamp.getDay();
}
getHours() {
return this.timestamp.getHours();
}
getMinutes() {
return this.timestamp.getMinutes();
}
getSeconds() {
return this.timestamp.getSeconds();
}
getMilliseconds() {
return this.timestamp.getMilliseconds();
}
getTime() {
return this.timestamp.getTime();
}
setYear(e) {
this.set(e, this.month, this.day);
}
setMonth(e) {
this.set(this.year, e, this.day);
}
setDate(e) {
this.set(this.year, this.month, e);
}
set(e, a, o) {
let l = e + Math.floor(a / 12) - u[0].year, y = u[l], d = y.daysTillNow - y.totalDays, w = a % 12, V = w < 0 ? 12 + w : w;
for (let p = 0; p < V; p += 1) d += y.days[p];
d += o - 1, this.setEnglishDate(new Date(j + d * 864e5));
}
format(e) {
return Je(this, e);
}
toString() {
return `${this.year}/${this.month + 1}/${this.day}`;
}
addDays(e) {
let a = new Date(this.timestamp.getTime() + e * 864e5);
return new i(a);
}
addMonths(e) {
let a = this.year, o = this.month + e;
a += Math.floor(o / 12), o = o % 12, o < 0 && (o += 12, a -= 1);
let l = a - u[0].year;
if (l < 0 || l >= u.length) throw new Error("Resulting date is out of supported range");
let y = u[l].days[o], d = Math.min(this.day, y);
return new i(a, o, d);
}
addYears(e) {
let a = this.year + e;
if (a < u[0].year || a >= u[0].year + u.length) throw new Error("Resulting date is out of supported range");
let o = a - u[0].year;
if (this.month === 11 && this.day === 29) {
let l = u[o].days[11];
if (l < 29) return new i(a, 11, l);
}
return new i(a, this.month, this.day);
}
static minimum() {
return new Date(j);
}
static maximum() {
return new Date(j + u[u.length - 1].daysTillNow * 864e5);
}
daysInMonth() {
let e = this.year - u[0].year;
return u[e].days[this.month];
}
isLeapYear() {
let e = this.year - u[0].year;
return u[e].totalDays === 366;
}
getWeeksInMonth() {
let e = new i(this.year, this.month, 1).getDay(), a = this.daysInMonth();
return Math.ceil((e + a) / 7);
}
diff(e, a) {
switch (a) {
case "day":
return Math.floor((this.timestamp.getTime() - e.timestamp.getTime()) / 864e5);
case "month":
let o = this.year - e.year, l = this.month - e.month;
return o * 12 + l;
case "year":
return this.year - e.year;
default:
throw new Error("Invalid unit for diff calculation");
}
}
startOfDay() {
let e = new Date(this.timestamp);
return e.setHours(0, 0, 0, 0), new i(e);
}
endOfDay() {
let e = new Date(this.timestamp);
return e.setHours(23, 59, 59, 999), new i(e);
}
startOfWeek(e = 0) {
if (e < 0 || e > 6 || !Number.isInteger(e)) throw new Error("startOfWeek must be an integer between 0 and 6");
let a = (this.getDay() - e + 7) % 7;
return this.clone().startOfDay().addDays(-a);
}
endOfWeek(e = 0) {
return this.startOfWeek(e).addDays(6).endOfDay();
}
startOfMonth() {
return new i(this.year, this.month, 1);
}
endOfMonth() {
let e = this.daysInMonth();
return new i(this.year, this.month, e).endOfDay();
}
startOfYear() {
return new i(this.year, 0, 1);
}
endOfYear() {
let e = this.year - u[0].year, a = u[e].days[11];
return new i(this.year, 11, a).endOfDay();
}
static getMonthName(e, a = !1, o = !1) {
if (e < 0 || e > 11) throw new Error("Invalid month index, must be between 0-11");
let l = "";
return o ? l = a ? de[e] : ie[e] : l = a ? ye[e] : Z[e], l;
}
static getDayName(e, a = !1, o = !1) {
if (e < 0 || e > 6) throw new Error("Invalid day index, must be between 0-6");
let l = "";
return o ? l = a ? ue[e] : oe[e] : l = a ? J[e] : ne[e], l;
}
static isValid(e, a, o) {
try {
if (e < u[0].year || e >= u[0].year + u.length || a < 0 || a > 11) return !1;
let l = e - u[0].year, y = u[l].days[a];
return !(o < 1 || o > y);
} catch {
return !1;
}
}
isValid() {
return i.isValid(this.year, this.month, this.day);
}
static getCalendarDays(e, a) {
if (!i.isValid(e, a, 1)) throw new Error("Invalid year or month");
let o = { year: 0, month: 0, days: [] }, l = { year: 0, month: 0, days: [] }, y = { year: 0, month: 0, days: [] }, d = e - u[0].year, w = new i(e, a, 1).getDay(), V = u[d].days[a];
l.year = e, l.month = a;
let p = a - 1, Y = e, b = a + 1, C = e;
if (p < 0 && (p = 11, Y--), Y > u[0].year && (o.year = Y, o.month = p), Y >= u[0].year && w > 0) {
let m = Y - u[0].year, S = u[m].days[p];
for (let M = 0; M < w; M++) o.days.push(S - w + M + 1);
}
for (let m = 1; m <= V; m++) l.days.push(m);
b > 11 && (b = 0, C++), C < u[0].year + u.length && (y.year = C, y.month = b);
let T = 42 - w - l.days.length;
if (C < u[0].year + u.length && T > 0) for (let m = 1; m <= T; m++) y.days.push(m);
return { prevRemainingDays: w, prevMonth: o, currentMonth: l, nextMonth: y, remainingDays: T };
}
clone() {
return new i(this);
}
isAfter(e) {
return this.timestamp.getTime() > e.timestamp.getTime();
}
isBefore(e) {
return this.timestamp.getTime() < e.timestamp.getTime();
}
isEqual(e) {
return this.year === e.year && this.month === e.month && this.day === e.day;
}
isSame(e, a) {
switch (a) {
case "year":
return this.year === e.year;
case "month":
return this.year === e.year && this.month === e.month;
case "day":
return this.isEqual(e);
default:
throw new Error("Invalid unit for comparison");
}
}
static getQuarter(e, a) {
if (e < 1 || e > 4 || !Number.isInteger(e)) throw new Error("Quarter must be an integer between 1 and 4");
let o = a ?? new i().getYear(), l = (e - 1) * 3, y = new i(o, l, 1), d = new i(o, l + 2, 1).endOfMonth();
return { start: y, end: d };
}
getCurrentQuarter() {
return Math.floor(this.month / 3) + 1;
}
static getQuarters(e) {
let a = e ?? new i().getYear();
return { Q1: i.getQuarter(1, a), Q2: i.getQuarter(2, a), Q3: i.getQuarter(3, a), Q4: i.getQuarter(4, a) };
}
static getCurrentFiscalYear() {
let e = new i(), a = e.getYear();
return e.getMonth() < 3 ? a - 1 : a;
}
static getFiscalYearQuarter(e, a) {
if (e < 1 || e > 4 || !Number.isInteger(e)) throw new Error("Quarter must be an integer between 1 and 4");
let o = a ?? i.getCurrentFiscalYear(), l = o, y = (e - 1) * 3 + 3;
e === 4 && (l = o + 1, y = 0), y > 11 && (l++, y -= 12);
let d = y + 2, w = l;
d > 11 && (w++, d -= 12);
let V = new i(l, y, 1), p = new i(w, d, 1).endOfMonth();
return { start: V, end: p };
}
getCurrentFiscalYearQuarter() {
let e = this.getMonth();
return e >= 3 && e <= 5 ? 1 : e >= 6 && e <= 8 ? 2 : e >= 9 && e <= 11 ? 3 : 4;
}
getCurrentFiscalYearQuarterDates() {
let e = this.getCurrentFiscalYearQuarter(), a = i.getCurrentFiscalYear();
return i.getFiscalYearQuarter(e, a);
}
static getFiscalYearQuarters(e) {
let a = e ?? i.getCurrentFiscalYear();
return { Q1: i.getFiscalYearQuarter(1, a), Q2: i.getFiscalYearQuarter(2, a), Q3: i.getFiscalYearQuarter(3, a), Q4: i.getFiscalYearQuarter(4, a) };
}
};
const Ue = ["placeholder", "id"], Ge = {
key: 0,
xmlns: "http://www.w3.org/2000/svg",
viewBox: "0 0 1024 1024",
width: "1em",
height: "1em"
}, Xe = ["id"], Ze = { class: "calendar__body" }, ea = { class: "calendar__head" }, aa = { class: "calendar__header_label" }, ta = { key: 0 }, la = { key: 2 }, sa = { key: 4 }, ra = { class: "calendar__container" }, na = { key: 0 }, oa = { class: "calendar__weeks" }, ua = { class: "calendar__days" }, ya = ["title", "onClick"], ia = ["title", "onClick"], da = ["title", "onClick"], ha = ["onClick"], ca = ["onClick"], q = 10, ma = /* @__PURE__ */ _e({
__name: "NepaliDatePicker",
props: {
modelValue: {
type: String,
default: ""
},
yearSelect: {
type: Boolean,
default: !0
},
monthSelect: {
type: Boolean,
default: !0
},
class: {
type: String,
default: ""
},
placeholder: {
type: String,
default: ""
}
},
emits: ["update:modelValue", "onSelect"],
setup(r, { emit: e }) {
const a = r, o = e, l = N(a.modelValue ? new v(a.modelValue) : new v()), y = N(!1), d = N(a.modelValue), w = N(null), V = N(null), p = N(null), Y = N(null), b = N(a.modelValue ? new v(a.modelValue).getYear() : new v().getYear()), C = N(a.modelValue ? new v(a.modelValue).getMonth() : new v().getMonth()), T = N(!1), m = N(!1), S = N(u[0].year), M = N(u.length + u[0].year - 1), x = N(0);
$e(() => a.modelValue, () => {
d.value = a.modelValue, b.value = a.modelValue ? new v(a.modelValue).getYear() : new v().getYear(), C.value = a.modelValue ? new v(a.modelValue).getMonth() : new v().getMonth(), l.value = a.modelValue ? new v(a.modelValue) : new v();
});
const he = Q(() => l.value.year == S.value && l.value.month == 0 ? [] : (u.forEach((s) => {
let t = l.value.year, n = l.value.month - 1;
L.value[0].month == 0 && (t = t - 1, n = 11), s.year === t && s.days.forEach((D, k) => {
k === n && (V.value = D);
});
}), Array(V.value).fill(null).map((s, t) => new v(l.value.year, l.value.month - 1, t + 1)).slice(-(F.value ? F.value : 0)))), L = Q(() => (u.forEach((s) => {
s.year === l.value.year && s.days.forEach((t, n) => {
n === l.value.month && (w.value = t);
});
}), Array(w.value).fill(null).map((s, t) => new v(l.value.year, l.value.month, t + 1)))), ce = Q(() => l.value.year == M.value && l.value.month == 11 ? [] : (u.forEach((s) => {
let t = l.value.year, n = l.value.month + 1;
L.value[0].month == 11 && (t = t + 1, n = 0), s.year === t && s.days.forEach((D, k) => {
k === n && (p.value = D);
});
}), Array(p.value).fill(null).map((s, t) => new v(l.value.year, l.value.month + 1, t + 1)).slice(0, ee.value))), F = Q(() => {
const s = new v(b.value, C.value, 1);
return J.forEach((t, n) => {
s.format("DDD") === "Su" ? Y.value = 7 : s.format("DDD") === t && (Y.value = n);
}), Y.value;
}), ee = Q(() => 42 - L.value.length - (F.value ? F.value : 0)), me = () => {
if (m.value = !m.value, T.value = !1, m.value) {
const s = l.value.year, t = u.findIndex((n) => n.year === s);
x.value = Math.floor(t / q);
}
}, P = (s, t) => {
s ? y.value = !0 : t ? y.value = !1 : y.value = !y.value, y.value ? document.addEventListener("click", z) : (document.removeEventListener("click", z), ae());
}, ve = () => {
T.value = !T.value, m.value = !1;
}, we = () => {
let s = l.value.month + 1, t = l.value.year;
s > 11 && (t++, s = 0), t + 1 < S.value || t > M.value || (R(s, t), l.value = new v(t, s, 1));
}, ge = () => {
if (m.value)
x.value < Me.value - 1 && x.value++;
else {
let s = l.value.month, t = l.value.year + 1;
t < S.value || t > M.value || (R(s, t), l.value = new v(t, s, 1));
}
}, De = () => {
let s = l.value.month - 1, t = l.value.year;
s < 0 && (t--, s = 11), t < S.value || t > M.value || (R(s, t), l.value = new v(t, s, 1));
}, fe = () => {
if (m.value)
x.value > 0 && x.value--;
else {
let s = l.value.month, t = l.value.year - 1;
t < S.value || t > M.value || (R(s, t), l.value = new v(t, s, 1));
}
}, Te = (s) => a.modelValue ? new v(a.modelValue).getTime() === s.getTime() : !1, Ne = (s) => l.value.month == s, pe = (s) => l.value.year == s, Ee = (s) => {
const t = new v();
return s.day === t.day && s.year === t.year && s.month === t.month;
}, W = Q(() => {
const s = u.map((n) => n.year), t = x.value * q;
return s.slice(t, t + q);
}), Me = Q(() => Math.ceil(u.length / q)), G = (s) => {
let t = "";
const n = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", D = n.length;
let k = 0;
for (; k < s; )
t += n.charAt(Math.floor(Math.random() * D)), k += 1;
return t;
}, O = G(3) + G(3) + G(3), R = (s, t) => {
C.value = s, b.value = t;
}, ke = (s) => {
C.value = s, l.value.setMonth(s), T.value = !1;
}, Ye = (s) => {
b.value = s, l.value.setYear(s), m.value = !1, a.monthSelect && (T.value = !0);
}, K = (s) => {
l.value = s, d.value = l.value.format("YYYY-MM-DD"), o("update:modelValue", d.value), o("onSelect", d.value), P();
}, Ce = () => {
/^\d{4}-\d{2}-\d{2}$/.test(d.value) || (d.value = a.modelValue);
try {
const s = new v(d.value);
K(s);
} catch {
d.value = a.modelValue;
}
}, z = (s) => {
const t = document.getElementById("nepali-calendar-" + O), n = document.getElementById("nepali-date-input-" + O);
t && !t.contains(s.target) && n && !n.contains(s.target) && (y.value = !1, ae(), document.removeEventListener("click", z));
}, ae = () => {
T.value = !1, m.value = !1, l.value = a.modelValue ? new v(a.modelValue) : new v();
}, Ve = () => {
T.value = !1, m.value = !1, l.value = new v(), o("update:modelValue", ""), o("onSelect", ""), P(!1, !0);
};
return Fe(() => {
document.removeEventListener("click", z);
}), (s, t) => (c(), h("div", {
class: I(["nepali-datepicker", a.class]),
key: O
}, [
g("div", {
class: I(["calendar-input-div", r.modelValue ? "calendar-input-contain-value" : ""])
}, [
Ie(g("input", {
type: "text",
class: "calendar-input",
onClick: t[0] || (t[0] = (n) => P(!0)),
"onUpdate:modelValue": t[1] || (t[1] = (n) => d.value = n),
placeholder: r.placeholder,
"aria-haspopup": "true",
id: "nepali-date-input-" + O,
onKeyup: t[2] || (t[2] = xe((n) => Ce(), ["enter"]))
}, null, 40, Ue), [
[Ae, d.value]
]),
g("div", {
class: "calendar-input-icon calender-icon",
onClick: t[3] || (t[3] = A((n) => P(!0), ["stop"]))
}, [
y.value && r.modelValue ? f("", !0) : (c(), h("svg", Ge, t[11] || (t[11] = [
g("path", { d: "M940.218 107.055H730.764v-60.51H665.6v60.51H363.055v-60.51H297.89v60.51H83.78c-18.617 0-32.581 13.963-32.581 32.581v805.237c0 18.618 13.964 32.582 32.582 32.582h861.09c18.619 0 32.583-13.964 32.583-32.582V139.636c-4.655-18.618-18.619-32.581-37.237-32.581zm-642.327 65.163v60.51h65.164v-60.51h307.2v60.51h65.163v-60.51h176.873v204.8H116.364v-204.8H297.89zM116.364 912.291V442.18H912.29v470.11H116.364z" }, null, -1)
])))
]),
r.modelValue ? (c(), h("div", {
key: 0,
class: I(["calendar-input-icon", y.value ? "" : "calendar-clear-input"]),
onClick: t[4] || (t[4] = A((n) => Ve(), ["stop"]))
}, t[12] || (t[12] = [
g("svg", {
width: "1em",
height: "1em",
viewBox: "0 0 24 24",
fill: "none",
xmlns: "http://www.w3.org/2000/svg"
}, [
g("path", {
id: "Vector",
d: "M18 18L12 12M12 12L6 6M12 12L18 6M12 12L6 18",
"stroke-width": "2",
"stroke-linecap": "round",
"stroke-linejoin": "round"
})
], -1)
]), 2)) : f("", !0)
], 2),
Qe(Be, { name: "calendar-animation" }, {
default: Oe(() => [
y.value ? (c(), h("div", {
key: 0,
class: I(["calendar", { show: y.value }]),
id: "nepali-calendar-" + O,
style: { "user-select": "none" }
}, [
g("div", Ze, [
g("div", ea, [
g("div", null, [
g("button", {
class: "calendar__toggle_button",
onClick: t[5] || (t[5] = (n) => fe())
}, t[13] || (t[13] = [
g("i", { class: "calendar-icon-double-left" }, null, -1)
])),
!T.value && !m.value ? (c(), h("button", {
key: 0,
class: "calendar__toggle_button",
onClick: t[6] || (t[6] = (n) => De())
}, t[14] || (t[14] = [
g("i", { class: "calendar-icon-left" }, null, -1)
]))) : f("", !0)
]),
g("div", aa, [
r.monthSelect ? f("", !0) : (c(), h("a", ta, E(l.value.format("MMMM")), 1)),
!T.value && !m.value && r.monthSelect ? (c(), h("a", {
key: 1,
class: "calendar__header_selector",
onClick: A(ve, ["stop"])
}, E(l.value.format("MMMM")), 1)) : f("", !0),
r.yearSelect ? f("", !0) : (c(), h("a", la, E(l.value.format("YYYY")), 1)),
!m.value && r.yearSelect ? (c(), h("a", {
key: 3,
class: "calendar__header_selector",
onClick: A(me, ["stop"])
}, E(l.value.format("YYYY")), 1)) : f("", !0),
m.value && r.yearSelect ? (c(), h("a", sa, E(W.value[0]) + " ~ " + E(W.value[W.value.length - 1]), 1)) : f("", !0)
]),
g("div", null, [
!T.value && !m.value ? (c(), h("button", {
key: 0,
class: "calendar__toggle_button",
onClick: t[7] || (t[7] = (n) => we())
}, t[15] || (t[15] = [
g("i", { class: "calendar-icon-right" }, null, -1)
]))) : f("", !0),
g("button", {
class: "calendar__toggle_button",
onClick: t[8] || (t[8] = (n) => ge())
}, t[16] || (t[16] = [
g("i", { class: "calendar-icon-double-right" }, null, -1)
]))
])
]),
g("div", ra, [
!T.value && !m.value ? (c(), h("div", na, [
g("div", oa, [
(c(!0), h(_, null, $(te(J), (n, D) => (c(), h("div", {
key: D,
class: "calendar__weekday"
}, E(n), 1))), 128))
]),
g("div", ua, [
l.value.year == S.value && l.value.month == 0 ? (c(!0), h(_, { key: 0 }, $(F.value, (n) => (c(), h("div", {
class: "calendar__day_spacer",
key: n
}))), 128)) : f("", !0),
F.value ? (c(!0), h(_, { key: 1 }, $(he.value, (n, D) => (c(), h("div", {
key: D,
class: "calendar__day not_current_month",
title: `${n.year}-${n.month + 1}-${n.day}`,
onClick: (k) => K(n)
}, [
g("span", null, E(n.day), 1)
], 8, ya))), 128)) : f("", !0),
(c(!0), h(_, null, $(L.value, (n, D) => (c(), h("div", {
key: D,
class: I(["calendar__day", { selected: Te(n), today: Ee(n) }]),
title: `${n.year}-${n.month + 1}-${n.day}`,
onClick: (k) => K(n)
}, [
g("span", null, E(n.day), 1)
], 10, ia))), 128)),
F.value ? (c(!0), h(_, { key: 2 }, $(ce.value, (n, D) => (c(), h("div", {
key: D,
class: "calendar__day not_current_month",
title: `${n.year}-${n.month + 1}-${n.day}`,
onClick: (k) => K(n)
}, [
g("span", null, E(n.day), 1)
], 8, da))), 128)) : f("", !0),
l.value.year == M.value && l.value.month == 11 ? (c(!0), h(_, { key: 3 }, $(ee.value, (n) => (c(), h("div", {
class: "calendar__day_spacer",
key: n
}))), 128)) : f("", !0)
])
])) : f("", !0),
T.value ? (c(), h("div", {
key: 1,
class: "calendar__months",
onClick: t[9] || (t[9] = A(() => {
}, ["stop"]))
}, [
(c(!0), h(_, null, $(te(Z), (n, D) => (c(), h("div", {
class: I(["calendar_month", { selected: Ne(D) }]),
onClick: (k) => ke(D)
}, E(n), 11, ha))), 256))
])) : f("", !0),
m.value ? (c(), h("div", {
key: 2,
class: "calendar__years",
onClick: t[10] || (t[10] = A(() => {
}, ["stop"]))
}, [
(c(!0), h(_, null, $(W.value, (n) => (c(), h("div", {
class: I(["calendar__year", { selected: pe(n) }]),
onClick: (D) => Ye(n)
}, E(n), 11, ca))), 256))
])) : f("", !0)
])
])
], 10, Xe)) : f("", !0)
]),
_: 1
})
], 2));
}
}), va = (r, e) => {
const a = r.__vccOpts || r;
for (const [o, l] of e)
a[o] = l;
return a;
}, Da = /* @__PURE__ */ va(ma, [["__scopeId", "data-v-2be2f4ff"]]);
export {
Da as NepaliDatePicker
};