@pr0vin/np-date-picker-vue-tw 1.0.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.
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { ref as k, onMounted as F, watch as L, createElementBlock as y, openBlock as g, createElementVNode as b, createCommentVNode as P, withDirectives as C, Fragment as N, renderList as M, toDisplayString as V, vModelSelect as O, unref as Y, normalizeClass as E } from "vue";
|
|
2
|
+
class B {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.bs = [
|
|
5
|
+
[2e3, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
6
|
+
[2001, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
7
|
+
[2002, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
8
|
+
[2003, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
9
|
+
[2004, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
10
|
+
[2005, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
11
|
+
[2006, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
12
|
+
[2007, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
13
|
+
[2008, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
|
|
14
|
+
[2009, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
15
|
+
[2010, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
16
|
+
[2011, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
17
|
+
[2012, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
|
18
|
+
[2013, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
19
|
+
[2014, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
20
|
+
[2015, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
21
|
+
[2016, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
|
22
|
+
[2017, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
23
|
+
[2018, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
24
|
+
[2019, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
25
|
+
[2020, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
26
|
+
[2021, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
27
|
+
[2022, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
|
28
|
+
[2023, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
29
|
+
[2024, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
30
|
+
[2025, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
31
|
+
[2026, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
32
|
+
[2027, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
33
|
+
[2028, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
34
|
+
[2029, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30],
|
|
35
|
+
[2030, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
36
|
+
[2031, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
37
|
+
[2032, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
38
|
+
[2033, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
39
|
+
[2034, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
40
|
+
[2035, 30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
|
|
41
|
+
[2036, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
42
|
+
[2037, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
43
|
+
[2038, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
44
|
+
[2039, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
|
45
|
+
[2040, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
46
|
+
[2041, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
47
|
+
[2042, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
48
|
+
[2043, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
|
49
|
+
[2044, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
50
|
+
[2045, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
51
|
+
[2046, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
52
|
+
[2047, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
53
|
+
[2048, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
54
|
+
[2049, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
|
55
|
+
[2050, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
56
|
+
[2051, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
57
|
+
[2052, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
58
|
+
[2053, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
|
59
|
+
[2054, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
60
|
+
[2055, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
61
|
+
[2056, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30],
|
|
62
|
+
[2057, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
63
|
+
[2058, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
64
|
+
[2059, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
65
|
+
[2060, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
66
|
+
[2061, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
67
|
+
[2062, 30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31],
|
|
68
|
+
[2063, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
69
|
+
[2064, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
70
|
+
[2065, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
71
|
+
[2066, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
|
|
72
|
+
[2067, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
73
|
+
[2068, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
74
|
+
[2069, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
75
|
+
[2070, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
|
76
|
+
[2071, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
77
|
+
[2072, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
78
|
+
[2073, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
79
|
+
[2074, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
80
|
+
[2075, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
81
|
+
[2076, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
|
82
|
+
[2077, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
83
|
+
[2078, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
84
|
+
[2079, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
85
|
+
[2080, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
|
86
|
+
[2081, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
87
|
+
[2082, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
88
|
+
[2083, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
89
|
+
[2084, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
90
|
+
[2085, 31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30],
|
|
91
|
+
[2086, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
92
|
+
[2087, 31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30],
|
|
93
|
+
[2088, 30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30],
|
|
94
|
+
[2089, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
95
|
+
[2090, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
96
|
+
[2091, 31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30],
|
|
97
|
+
[2092, 30, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
98
|
+
[2093, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
99
|
+
[2094, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
100
|
+
[2095, 31, 31, 32, 31, 31, 31, 30, 29, 30, 30, 30, 30],
|
|
101
|
+
[2096, 30, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
102
|
+
[2097, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
103
|
+
[2098, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 31],
|
|
104
|
+
[2099, 31, 32, 31, 32, 31, 29, 30, 30, 29, 30, 30, 31]
|
|
105
|
+
], this.nep_date = {
|
|
106
|
+
year: 0,
|
|
107
|
+
month: 0,
|
|
108
|
+
date: 0,
|
|
109
|
+
day: "",
|
|
110
|
+
nmonth: "",
|
|
111
|
+
num_day: 0
|
|
112
|
+
}, this.eng_date = {
|
|
113
|
+
year: 0,
|
|
114
|
+
month: 0,
|
|
115
|
+
date: 0,
|
|
116
|
+
day: "",
|
|
117
|
+
emonth: "",
|
|
118
|
+
num_day: 0
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
getDayOfWeek(n) {
|
|
122
|
+
return {
|
|
123
|
+
1: "आईतवार",
|
|
124
|
+
2: "सोमबार",
|
|
125
|
+
3: "मंगलवार",
|
|
126
|
+
4: "बुधबार",
|
|
127
|
+
5: "बिहीबार",
|
|
128
|
+
6: "शुक्रबार",
|
|
129
|
+
7: "शनिबार"
|
|
130
|
+
}[n];
|
|
131
|
+
}
|
|
132
|
+
getEnglishMonth(n) {
|
|
133
|
+
return {
|
|
134
|
+
1: "January",
|
|
135
|
+
2: "February",
|
|
136
|
+
3: "March",
|
|
137
|
+
4: "April",
|
|
138
|
+
5: "May",
|
|
139
|
+
6: "June",
|
|
140
|
+
7: "July",
|
|
141
|
+
8: "August",
|
|
142
|
+
9: "September",
|
|
143
|
+
10: "October",
|
|
144
|
+
11: "November",
|
|
145
|
+
12: "December"
|
|
146
|
+
}[n];
|
|
147
|
+
}
|
|
148
|
+
getNepaliMonth(n) {
|
|
149
|
+
return {
|
|
150
|
+
1: "बैशाख",
|
|
151
|
+
2: "जेष्ठ",
|
|
152
|
+
3: "असार",
|
|
153
|
+
4: "श्रावण",
|
|
154
|
+
5: "भाद्र",
|
|
155
|
+
6: "आश्विन",
|
|
156
|
+
7: "कार्तिक",
|
|
157
|
+
8: "मंसिर",
|
|
158
|
+
9: "पुष",
|
|
159
|
+
10: "माघ",
|
|
160
|
+
11: "फाल्गुन",
|
|
161
|
+
12: "चैत्र"
|
|
162
|
+
}[n];
|
|
163
|
+
}
|
|
164
|
+
isLeapYear(n) {
|
|
165
|
+
return n % 4 === 0 && n % 100 !== 0 || n % 400 === 0;
|
|
166
|
+
}
|
|
167
|
+
convertToNepaliNumber(n) {
|
|
168
|
+
const d = ["०", "१", "२", "३", "४", "५", "६", "७", "८", "९"];
|
|
169
|
+
return String(n).split("").map((p) => /[0-9]/.test(p) ? d[p] : p).join("");
|
|
170
|
+
}
|
|
171
|
+
engToNep(n, d, p) {
|
|
172
|
+
if (n < 1944 || n > 2033)
|
|
173
|
+
throw new Error("Supported only between 1944-2033");
|
|
174
|
+
const i = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], r = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
175
|
+
let v = 1944, a = 2e3, s = 9, w = 16, m = 0, u = 0, h = 7, S = a, _ = s, D = s;
|
|
176
|
+
for (let c = v; c < n; c++)
|
|
177
|
+
m += this.isLeapYear(c) ? r.reduce((t, l) => t + l, 0) : i.reduce((t, l) => t + l, 0);
|
|
178
|
+
for (let c = 1; c < d; c++)
|
|
179
|
+
m += this.isLeapYear(n) ? r[c] : i[c];
|
|
180
|
+
m += p - 1;
|
|
181
|
+
let T = 1;
|
|
182
|
+
for (u = w; m > 0; ) {
|
|
183
|
+
let c = this.bs[T][D];
|
|
184
|
+
u++, h++, u > c && (u = 1, _++, D++), _ > 12 && (_ = 1, S++), D > 12 && (D = 1, T++), h > 7 && (h = 1), m--;
|
|
185
|
+
}
|
|
186
|
+
return this.nep_date = {
|
|
187
|
+
year: S,
|
|
188
|
+
month: _,
|
|
189
|
+
date: u,
|
|
190
|
+
day: this.getDayOfWeek(h),
|
|
191
|
+
nmonth: this.getNepaliMonth(_),
|
|
192
|
+
num_day: h
|
|
193
|
+
}, this.nep_date;
|
|
194
|
+
}
|
|
195
|
+
adToBs(n) {
|
|
196
|
+
const [d, p, i] = n.split("-").map(Number), r = this.engToNep(d, p, i), v = r.year, a = r.month.toString().padStart(2, "0"), s = r.date.toString().padStart(2, "0");
|
|
197
|
+
return `${v}-${a}-${s}`;
|
|
198
|
+
}
|
|
199
|
+
getFirstDayOfMonth(n, d) {
|
|
200
|
+
let p = 1944;
|
|
201
|
+
for (let i = p; i <= 2100; i++)
|
|
202
|
+
for (let r = 1; r <= 12; r++)
|
|
203
|
+
for (let v = 1; v <= 31; v++)
|
|
204
|
+
try {
|
|
205
|
+
const a = this.engToNep(i, r, v);
|
|
206
|
+
if (a.year === n && a.month === d && a.date === 1)
|
|
207
|
+
return a.num_day;
|
|
208
|
+
} catch {
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const I = { class: "relative w-full nepali-calendar" }, j = ["value"], J = {
|
|
215
|
+
key: 0,
|
|
216
|
+
class: "absolute bg-white border shadow rounded p-3 mt-2 w-80 z-50"
|
|
217
|
+
}, z = { class: "flex justify-between mb-2" }, A = ["value"], U = ["value"], W = { class: "grid grid-cols-7 text-center font-semibold mb-1" }, q = { class: "grid grid-cols-7 gap-1 text-center" }, G = ["onClick"], H = {
|
|
218
|
+
__name: "NepaliDatePicker",
|
|
219
|
+
props: { modelValue: String },
|
|
220
|
+
emits: ["update:modelValue"],
|
|
221
|
+
setup(x, { emit: n }) {
|
|
222
|
+
const d = x, p = n, i = new B(), r = k(!1), v = ["आईत", "सोम", "मंगल", "बुध", "बिही", "शुक्र", "शनि"], a = k(null), s = k(null), w = k([]), m = k(null), u = k({ year: 0, month: 0, day: 0 }), h = (t, l, e) => `${t}-${String(l).padStart(2, "0")}-${String(e).padStart(2, "0")}`;
|
|
223
|
+
function S() {
|
|
224
|
+
const t = i.bs.find((o) => o[0] === a.value)?.[s.value];
|
|
225
|
+
if (!t) return;
|
|
226
|
+
const l = i.getFirstDayOfMonth(a.value, s.value), e = [];
|
|
227
|
+
for (let o = 1; o < l; o++) e.push(null);
|
|
228
|
+
for (let o = 1; o <= t; o++) e.push(o);
|
|
229
|
+
w.value = [];
|
|
230
|
+
for (let o = 0; o < e.length; o += 7) w.value.push(e.slice(o, o + 7));
|
|
231
|
+
}
|
|
232
|
+
function _(t) {
|
|
233
|
+
if (!t) return;
|
|
234
|
+
const l = h(a.value, s.value, t);
|
|
235
|
+
m.value = l, p("update:modelValue", l), r.value = !1;
|
|
236
|
+
}
|
|
237
|
+
function D(t) {
|
|
238
|
+
return t && u.value.year === a.value && u.value.month === s.value && u.value.day === t;
|
|
239
|
+
}
|
|
240
|
+
function T(t) {
|
|
241
|
+
return t ? m.value === h(a.value, s.value, t) : !1;
|
|
242
|
+
}
|
|
243
|
+
function c(t) {
|
|
244
|
+
t.target.closest(".nepali-calendar") || (r.value = !1);
|
|
245
|
+
}
|
|
246
|
+
return F(() => {
|
|
247
|
+
const t = /* @__PURE__ */ new Date(), l = i.engToNep(t.getFullYear(), t.getMonth() + 1, t.getDate());
|
|
248
|
+
if (u.value = {
|
|
249
|
+
year: l.year,
|
|
250
|
+
month: l.month,
|
|
251
|
+
day: l.date
|
|
252
|
+
}, d.modelValue) {
|
|
253
|
+
const [e, o, f] = d.modelValue.split("-");
|
|
254
|
+
a.value = parseInt(e), s.value = parseInt(o), m.value = h(a.value, s.value, parseInt(f));
|
|
255
|
+
} else
|
|
256
|
+
a.value = u.value.year, s.value = u.value.month, m.value = h(
|
|
257
|
+
u.value.year,
|
|
258
|
+
u.value.month,
|
|
259
|
+
u.value.day
|
|
260
|
+
);
|
|
261
|
+
S(), document.addEventListener("click", c);
|
|
262
|
+
}), L([a, s], S), (t, l) => (g(), y("div", I, [
|
|
263
|
+
b("input", {
|
|
264
|
+
type: "text",
|
|
265
|
+
readonly: "",
|
|
266
|
+
value: m.value,
|
|
267
|
+
onClick: l[0] || (l[0] = (e) => r.value = !r.value),
|
|
268
|
+
class: "w-full border rounded px-3 py-2 cursor-pointer",
|
|
269
|
+
placeholder: "Select date"
|
|
270
|
+
}, null, 8, j),
|
|
271
|
+
r.value ? (g(), y("div", J, [
|
|
272
|
+
b("div", z, [
|
|
273
|
+
C(b("select", {
|
|
274
|
+
"onUpdate:modelValue": l[1] || (l[1] = (e) => a.value = e),
|
|
275
|
+
class: "border p-1 rounded"
|
|
276
|
+
}, [
|
|
277
|
+
(g(), y(N, null, M(100, (e) => b("option", {
|
|
278
|
+
key: e,
|
|
279
|
+
value: 2e3 + e
|
|
280
|
+
}, V(2e3 + e), 9, A)), 64))
|
|
281
|
+
], 512), [
|
|
282
|
+
[O, a.value]
|
|
283
|
+
]),
|
|
284
|
+
C(b("select", {
|
|
285
|
+
"onUpdate:modelValue": l[2] || (l[2] = (e) => s.value = e),
|
|
286
|
+
class: "border p-1 rounded"
|
|
287
|
+
}, [
|
|
288
|
+
(g(), y(N, null, M(12, (e) => b("option", {
|
|
289
|
+
key: e,
|
|
290
|
+
value: e
|
|
291
|
+
}, V(Y(i).getNepaliMonth(e)), 9, U)), 64))
|
|
292
|
+
], 512), [
|
|
293
|
+
[O, s.value]
|
|
294
|
+
])
|
|
295
|
+
]),
|
|
296
|
+
b("div", W, [
|
|
297
|
+
(g(), y(N, null, M(v, (e, o) => b("div", {
|
|
298
|
+
key: o,
|
|
299
|
+
class: E(o === 6 ? "text-red-600" : "")
|
|
300
|
+
}, V(e), 3)), 64))
|
|
301
|
+
]),
|
|
302
|
+
b("div", q, [
|
|
303
|
+
(g(!0), y(N, null, M(w.value, (e, o) => (g(), y(N, { key: o }, [
|
|
304
|
+
(g(!0), y(N, null, M(e, (f, $) => (g(), y("div", {
|
|
305
|
+
key: $,
|
|
306
|
+
class: E(["p-2 border rounded cursor-pointer select-none", [
|
|
307
|
+
f === null ? "bg-gray-100 cursor-default text-gray-400" : "",
|
|
308
|
+
$ === 6 && f !== null ? "text-red-600" : "",
|
|
309
|
+
D(f) ? "bg-blue-200 text-blue-800 font-bold" : "",
|
|
310
|
+
T(f) ? "bg-blue-600 text-white font-bold" : ""
|
|
311
|
+
]]),
|
|
312
|
+
onClick: (K) => _(f)
|
|
313
|
+
}, V(f ? Y(i).convertToNepaliNumber(f) : ""), 11, G))), 128))
|
|
314
|
+
], 64))), 128))
|
|
315
|
+
])
|
|
316
|
+
])) : P("", !0)
|
|
317
|
+
]));
|
|
318
|
+
}
|
|
319
|
+
}, R = {
|
|
320
|
+
install(x) {
|
|
321
|
+
x.component("NepaliDatePicker", H);
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
export {
|
|
325
|
+
H as NepaliDatePicker,
|
|
326
|
+
R as NpDatePickerPlugin
|
|
327
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(k,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(k=typeof globalThis<"u"?globalThis:k||self,e(k.NpDatePickerVueTw={},k.Vue))})(this,(function(k,e){"use strict";class V{constructor(){this.bs=[[2e3,30,32,31,32,31,30,30,30,29,30,29,31],[2001,31,31,32,31,31,31,30,29,30,29,30,30],[2002,31,31,32,32,31,30,30,29,30,29,30,30],[2003,31,32,31,32,31,30,30,30,29,29,30,31],[2004,30,32,31,32,31,30,30,30,29,30,29,31],[2005,31,31,32,31,31,31,30,29,30,29,30,30],[2006,31,31,32,32,31,30,30,29,30,29,30,30],[2007,31,32,31,32,31,30,30,30,29,29,30,31],[2008,31,31,31,32,31,31,29,30,30,29,29,31],[2009,31,31,32,31,31,31,30,29,30,29,30,30],[2010,31,31,32,32,31,30,30,29,30,29,30,30],[2011,31,32,31,32,31,30,30,30,29,29,30,31],[2012,31,31,31,32,31,31,29,30,30,29,30,30],[2013,31,31,32,31,31,31,30,29,30,29,30,30],[2014,31,31,32,32,31,30,30,29,30,29,30,30],[2015,31,32,31,32,31,30,30,30,29,29,30,31],[2016,31,31,31,32,31,31,29,30,30,29,30,30],[2017,31,31,32,31,31,31,30,29,30,29,30,30],[2018,31,32,31,32,31,30,30,29,30,29,30,30],[2019,31,32,31,32,31,30,30,30,29,30,29,31],[2020,31,31,31,32,31,31,30,29,30,29,30,30],[2021,31,31,32,31,31,31,30,29,30,29,30,30],[2022,31,32,31,32,31,30,30,30,29,29,30,30],[2023,31,32,31,32,31,30,30,30,29,30,29,31],[2024,31,31,31,32,31,31,30,29,30,29,30,30],[2025,31,31,32,31,31,31,30,29,30,29,30,30],[2026,31,32,31,32,31,30,30,30,29,29,30,31],[2027,30,32,31,32,31,30,30,30,29,30,29,31],[2028,31,31,32,31,31,31,30,29,30,29,30,30],[2029,31,31,32,31,32,30,30,29,30,29,30,30],[2030,31,32,31,32,31,30,30,30,29,29,30,31],[2031,30,32,31,32,31,30,30,30,29,30,29,31],[2032,31,31,32,31,31,31,30,29,30,29,30,30],[2033,31,31,32,32,31,30,30,29,30,29,30,30],[2034,31,32,31,32,31,30,30,30,29,29,30,31],[2035,30,32,31,32,31,31,29,30,30,29,29,31],[2036,31,31,32,31,31,31,30,29,30,29,30,30],[2037,31,31,32,32,31,30,30,29,30,29,30,30],[2038,31,32,31,32,31,30,30,30,29,29,30,31],[2039,31,31,31,32,31,31,29,30,30,29,30,30],[2040,31,31,32,31,31,31,30,29,30,29,30,30],[2041,31,31,32,32,31,30,30,29,30,29,30,30],[2042,31,32,31,32,31,30,30,30,29,29,30,31],[2043,31,31,31,32,31,31,29,30,30,29,30,30],[2044,31,31,32,31,31,31,30,29,30,29,30,30],[2045,31,32,31,32,31,30,30,29,30,29,30,30],[2046,31,32,31,32,31,30,30,30,29,29,30,31],[2047,31,31,31,32,31,31,30,29,30,29,30,30],[2048,31,31,32,31,31,31,30,29,30,29,30,30],[2049,31,32,31,32,31,30,30,30,29,29,30,30],[2050,31,32,31,32,31,30,30,30,29,30,29,31],[2051,31,31,31,32,31,31,30,29,30,29,30,30],[2052,31,31,32,31,31,31,30,29,30,29,30,30],[2053,31,32,31,32,31,30,30,30,29,29,30,30],[2054,31,32,31,32,31,30,30,30,29,30,29,31],[2055,31,31,32,31,31,31,30,29,30,29,30,30],[2056,31,31,32,31,32,30,30,29,30,29,30,30],[2057,31,32,31,32,31,30,30,30,29,29,30,31],[2058,30,32,31,32,31,30,30,30,29,30,29,31],[2059,31,31,32,31,31,31,30,29,30,29,30,30],[2060,31,31,32,32,31,30,30,29,30,29,30,30],[2061,31,32,31,32,31,30,30,30,29,29,30,31],[2062,30,32,31,32,31,31,29,30,29,30,29,31],[2063,31,31,32,31,31,31,30,29,30,29,30,30],[2064,31,31,32,32,31,30,30,29,30,29,30,30],[2065,31,32,31,32,31,30,30,30,29,29,30,31],[2066,31,31,31,32,31,31,29,30,30,29,29,31],[2067,31,31,32,31,31,31,30,29,30,29,30,30],[2068,31,31,32,32,31,30,30,29,30,29,30,30],[2069,31,32,31,32,31,30,30,30,29,29,30,31],[2070,31,31,31,32,31,31,29,30,30,29,30,30],[2071,31,31,32,31,31,31,30,29,30,29,30,30],[2072,31,32,31,32,31,30,30,29,30,29,30,30],[2073,31,32,31,32,31,30,30,30,29,29,30,31],[2074,31,31,31,32,31,31,30,29,30,29,30,30],[2075,31,31,32,31,31,31,30,29,30,29,30,30],[2076,31,32,31,32,31,30,30,30,29,29,30,30],[2077,31,32,31,32,31,30,30,30,29,30,29,31],[2078,31,31,31,32,31,31,30,29,30,29,30,30],[2079,31,31,32,31,31,31,30,29,30,29,30,30],[2080,31,32,31,32,31,30,30,30,29,29,30,30],[2081,31,32,31,32,31,30,30,30,29,30,29,31],[2082,31,31,32,31,31,31,30,29,30,29,30,30],[2083,31,31,32,31,31,30,30,30,29,30,30,30],[2084,31,31,32,31,31,30,30,30,29,30,30,30],[2085,31,32,31,32,30,31,30,30,29,30,30,30],[2086,30,32,31,32,31,30,30,30,29,30,30,30],[2087,31,31,32,31,31,31,30,30,29,30,30,30],[2088,30,31,32,32,30,31,30,30,29,30,30,30],[2089,30,32,31,32,31,30,30,30,29,30,30,30],[2090,30,32,31,32,31,30,30,30,29,30,30,30],[2091,31,31,32,31,31,31,30,30,29,30,30,30],[2092,30,31,32,32,31,30,30,30,29,30,30,30],[2093,30,32,31,32,31,30,30,30,29,30,30,30],[2094,31,31,32,31,31,30,30,30,29,30,30,30],[2095,31,31,32,31,31,31,30,29,30,30,30,30],[2096,30,31,32,32,31,30,30,29,30,29,30,30],[2097,31,32,31,32,31,30,30,30,29,30,30,30],[2098,31,31,32,32,31,30,30,29,30,29,30,31],[2099,31,32,31,32,31,29,30,30,29,30,30,31]],this.nep_date={year:0,month:0,date:0,day:"",nmonth:"",num_day:0},this.eng_date={year:0,month:0,date:0,day:"",emonth:"",num_day:0}}getDayOfWeek(l){return{1:"आईतवार",2:"सोमबार",3:"मंगलवार",4:"बुधबार",5:"बिहीबार",6:"शुक्रबार",7:"शनिबार"}[l]}getEnglishMonth(l){return{1:"January",2:"February",3:"March",4:"April",5:"May",6:"June",7:"July",8:"August",9:"September",10:"October",11:"November",12:"December"}[l]}getNepaliMonth(l){return{1:"बैशाख",2:"जेष्ठ",3:"असार",4:"श्रावण",5:"भाद्र",6:"आश्विन",7:"कार्तिक",8:"मंसिर",9:"पुष",10:"माघ",11:"फाल्गुन",12:"चैत्र"}[l]}isLeapYear(l){return l%4===0&&l%100!==0||l%400===0}convertToNepaliNumber(l){const u=["०","१","२","३","४","५","६","७","८","९"];return String(l).split("").map(p=>/[0-9]/.test(p)?u[p]:p).join("")}engToNep(l,u,p){if(l<1944||l>2033)throw new Error("Supported only between 1944-2033");const d=[0,31,28,31,30,31,30,31,31,30,31,30,31],s=[0,31,29,31,30,31,30,31,31,30,31,30,31];let y=1944,o=2e3,i=9,N=16,f=0,c=0,h=7,D=o,b=i,_=i;for(let m=y;m<l;m++)f+=this.isLeapYear(m)?s.reduce((n,a)=>n+a,0):d.reduce((n,a)=>n+a,0);for(let m=1;m<u;m++)f+=this.isLeapYear(l)?s[m]:d[m];f+=p-1;let E=1;for(c=N;f>0;){let m=this.bs[E][_];c++,h++,c>m&&(c=1,b++,_++),b>12&&(b=1,D++),_>12&&(_=1,E++),h>7&&(h=1),f--}return this.nep_date={year:D,month:b,date:c,day:this.getDayOfWeek(h),nmonth:this.getNepaliMonth(b),num_day:h},this.nep_date}adToBs(l){const[u,p,d]=l.split("-").map(Number),s=this.engToNep(u,p,d),y=s.year,o=s.month.toString().padStart(2,"0"),i=s.date.toString().padStart(2,"0");return`${y}-${o}-${i}`}getFirstDayOfMonth(l,u){let p=1944;for(let d=p;d<=2100;d++)for(let s=1;s<=12;s++)for(let y=1;y<=31;y++)try{const o=this.engToNep(d,s,y);if(o.year===l&&o.month===u&&o.date===1)return o.num_day}catch{continue}return null}}const M={class:"relative w-full nepali-calendar"},T=["value"],x={key:0,class:"absolute bg-white border shadow rounded p-3 mt-2 w-80 z-50"},v={class:"flex justify-between mb-2"},F=["value"],L=["value"],P={class:"grid grid-cols-7 text-center font-semibold mb-1"},C={class:"grid grid-cols-7 gap-1 text-center"},$=["onClick"],B={__name:"NepaliDatePicker",props:{modelValue:String},emits:["update:modelValue"],setup(S,{emit:l}){const u=S,p=l,d=new V,s=e.ref(!1),y=["आईत","सोम","मंगल","बुध","बिही","शुक्र","शनि"],o=e.ref(null),i=e.ref(null),N=e.ref([]),f=e.ref(null),c=e.ref({year:0,month:0,day:0}),h=(n,a,t)=>`${n}-${String(a).padStart(2,"0")}-${String(t).padStart(2,"0")}`;function D(){const n=d.bs.find(r=>r[0]===o.value)?.[i.value];if(!n)return;const a=d.getFirstDayOfMonth(o.value,i.value),t=[];for(let r=1;r<a;r++)t.push(null);for(let r=1;r<=n;r++)t.push(r);N.value=[];for(let r=0;r<t.length;r+=7)N.value.push(t.slice(r,r+7))}function b(n){if(!n)return;const a=h(o.value,i.value,n);f.value=a,p("update:modelValue",a),s.value=!1}function _(n){return n&&c.value.year===o.value&&c.value.month===i.value&&c.value.day===n}function E(n){return n?f.value===h(o.value,i.value,n):!1}function m(n){n.target.closest(".nepali-calendar")||(s.value=!1)}return e.onMounted(()=>{const n=new Date,a=d.engToNep(n.getFullYear(),n.getMonth()+1,n.getDate());if(c.value={year:a.year,month:a.month,day:a.date},u.modelValue){const[t,r,g]=u.modelValue.split("-");o.value=parseInt(t),i.value=parseInt(r),f.value=h(o.value,i.value,parseInt(g))}else o.value=c.value.year,i.value=c.value.month,f.value=h(c.value.year,c.value.month,c.value.day);D(),document.addEventListener("click",m)}),e.watch([o,i],D),(n,a)=>(e.openBlock(),e.createElementBlock("div",M,[e.createElementVNode("input",{type:"text",readonly:"",value:f.value,onClick:a[0]||(a[0]=t=>s.value=!s.value),class:"w-full border rounded px-3 py-2 cursor-pointer",placeholder:"Select date"},null,8,T),s.value?(e.openBlock(),e.createElementBlock("div",x,[e.createElementVNode("div",v,[e.withDirectives(e.createElementVNode("select",{"onUpdate:modelValue":a[1]||(a[1]=t=>o.value=t),class:"border p-1 rounded"},[(e.openBlock(),e.createElementBlock(e.Fragment,null,e.renderList(100,t=>e.createElementVNode("option",{key:t,value:2e3+t},e.toDisplayString(2e3+t),9,F)),64))],512),[[e.vModelSelect,o.value]]),e.withDirectives(e.createElementVNode("select",{"onUpdate:modelValue":a[2]||(a[2]=t=>i.value=t),class:"border p-1 rounded"},[(e.openBlock(),e.createElementBlock(e.Fragment,null,e.renderList(12,t=>e.createElementVNode("option",{key:t,value:t},e.toDisplayString(e.unref(d).getNepaliMonth(t)),9,L)),64))],512),[[e.vModelSelect,i.value]])]),e.createElementVNode("div",P,[(e.openBlock(),e.createElementBlock(e.Fragment,null,e.renderList(y,(t,r)=>e.createElementVNode("div",{key:r,class:e.normalizeClass(r===6?"text-red-600":"")},e.toDisplayString(t),3)),64))]),e.createElementVNode("div",C,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(N.value,(t,r)=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:r},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t,(g,w)=>(e.openBlock(),e.createElementBlock("div",{key:w,class:e.normalizeClass(["p-2 border rounded cursor-pointer select-none",[g===null?"bg-gray-100 cursor-default text-gray-400":"",w===6&&g!==null?"text-red-600":"",_(g)?"bg-blue-200 text-blue-800 font-bold":"",E(g)?"bg-blue-600 text-white font-bold":""]]),onClick:Y=>b(g)},e.toDisplayString(g?e.unref(d).convertToNepaliNumber(g):""),11,$))),128))],64))),128))])])):e.createCommentVNode("",!0)]))}},O={install(S){S.component("NepaliDatePicker",B)}};k.NepaliDatePicker=B,k.NpDatePickerPlugin=O,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pr0vin/np-date-picker-vue-tw",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "dist/np-date-picker-vue-tw.umd.js",
|
|
5
|
+
"module": "dist/np-date-picker-vue-tw.es.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "vite build",
|
|
11
|
+
"dev": "vite"
|
|
12
|
+
},
|
|
13
|
+
"author": "Pravin Chaudahry",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"description": "A Nepali date picker Vue 3 component using Tailwind CSS",
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"vue": "^3.5.25"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@vitejs/plugin-vue": "^6.0.2",
|
|
21
|
+
"vite": "^7.2.6",
|
|
22
|
+
"vue": "^3.5.25"
|
|
23
|
+
}
|
|
24
|
+
}
|