date-picker-np
Version:
Nepali Date Picker for React
942 lines (941 loc) • 37.2 kB
JavaScript
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".date-picker-container,.date-picker-container *{box-sizing:border-box;margin:0}.date-picker-container{position:relative;font-family:sans-serif;font-size:12px;-webkit-user-select:none;user-select:none;color:#0e0e0e;width:fit-content}.date-picker-input-container{position:relative;border-radius:4px;border:1px solid gray;overflow:hidden}.date-picker-input{border-radius:4px;border:none;outline:none;min-width:140px;width:100%;min-height:28px;padding:0 10px;display:flex;align-items:center;background:transparent}.date-picker-input:focus{outline:none}.date-picker-input-container-disabled{opacity:.5;cursor:not-allowed}.date-picker-input-disabled{cursor:not-allowed}.date-picker-input-right-icon{display:flex;position:absolute;right:8px;top:50%;transform:translateY(-50%);pointer-events:none}:root{--date-picker-np-hover-color: rgb(218, 218, 218)}.date-picker-body-container{display:grid;grid-template-columns:repeat(7,1fr);text-align:center}.date-picker-week-days-container>div{line-height:14px;padding:4px 0 8px}.date-picker-dates-container>div{line-height:30px;height:30px;cursor:pointer}.date-picker-dates-container .prev-month-days,.date-picker-dates-container .next-month-days{opacity:.4;cursor:default}.date-picker-dates-container>div:not(.prev-month-days,.next-month-days,.date-picker-date-disabled,.date-picker-selected-date):hover{background:var(--date-picker-np-hover-color)}.date-picker-dates-container .date-picker-selected-date{background:#0085b1;color:#fff}.date-picker-dates-container>.date-picker-date-disabled{background:#fff;opacity:.4;cursor:default}.date-picker-calendar{position:absolute;top:20%;border:1px solid rgb(226,226,226);box-shadow:0 0 20px #0000001a;border-radius:4px;min-width:220px;width:220px;min-height:284px;height:284px;background:#fff;padding:4px 8px}.date-picker-calendar-header{display:flex;justify-content:space-between;align-items:center;margin:2px 0;height:30px;line-height:16px}.date-picker-calendar-header-arrow{display:flex;justify-content:center;align-items:center;cursor:pointer;width:30px;height:30px}.date-picker-calendar-header-arrow.date-picker-calendar-header-arrow-disabled{opacity:.4;cursor:default}.date-picker-calendar-header-dropdown-text{border:1px solid gray;padding:4px 10px;cursor:pointer}.date-picker-selector-container{position:absolute;bottom:0;left:0;z-index:1;display:flex;flex-direction:column;width:100%;height:100%;background:#fff;padding:4px 8px 10px}.date-picker-selector-header{display:flex;align-items:center;justify-content:center;height:34px;flex-shrink:0}.date-picker-selector-block-container{display:grid;grid-template-columns:repeat(3,1fr);overflow:hidden;flex:1}.date-picker-selector-block-container>div{display:grid;place-items:center;cursor:pointer}.date-picker-selector-block-container>div>div{padding:10px}.date-picker-selector-block-container>div>div.date-picker-selector-block-selected{color:#fff;background:#02769c}.date-picker-selector-block-container>div.date-picker-selector-block-disabled{opacity:.4;cursor:default}.date-picker-selector-block-container>div:hover:not(.date-picker-selector-block-disabled)>div:not(.date-picker-selector-block-selected){background:#e2e2e2}.date-picker-year-selector-block-container{display:grid;grid-template-columns:repeat(3,1fr);overflow:auto;margin:4px 0 2px}.date-picker-year-selector-block-container>div{height:38px;line-height:38px;text-align:center;cursor:pointer}.date-picker-year-selector-block-container>div:not(.date-picker-selector-block-disabled,.date-picker-year-selector-block-selected):hover{background:#e2e2e2}.date-picker-year-selector-block-container>div.date-picker-year-selector-block-selected{background:#02769c;color:#fff}.date-picker-year-selector-block-container>div.date-picker-selector-block-disabled{opacity:.4;cursor:default}.date-picker-year-selector-block-container::-webkit-scrollbar{width:4px}.date-picker-year-selector-block-container::-webkit-scrollbar-thumb{background:#888;border-radius:4px}.date-picker-year-selector-block-container::-webkit-scrollbar-thumb:hover{background:#555}.date-picker-calendar-footer{display:flex;justify-content:space-between;padding:10px;line-height:24px}.date-picker-calendar-footer>.date-picker-calendar-footer-btn{font-weight:medium;color:#00008b;cursor:pointer}.date-picker-calendar-footer-btn.date-picker-calendar-footer-btn-disabled{cursor:default;opacity:.4}")),document.head.appendChild(e)}}catch(r){console.error("vite-plugin-css-injected-by-js",r)}})();
import { jsx as h, Fragment as J, jsxs as A } from "react/jsx-runtime";
import { forwardRef as r3, useEffect as I, useRef as Y, useState as M, useLayoutEffect as X } from "react";
const Z = ({ onClick: e }) => /* @__PURE__ */ h(
"svg",
{
width: "24",
height: "24",
viewBox: "0 0 24 24",
fill: "none",
xmlns: "http://www.w3.org/2000/svg",
onClick: e,
children: /* @__PURE__ */ h(
"path",
{
d: "M9 18L15 12L9 6",
stroke: "#262E3C",
strokeWidth: "1.66667",
strokeLinecap: "round",
strokeLinejoin: "round"
}
)
}
), o3 = ({ onClick: e }) => /* @__PURE__ */ h(
"div",
{
style: {
transform: "rotate(180deg)",
display: "flex"
},
children: /* @__PURE__ */ h(Z, { onClick: e })
}
), a3 = () => /* @__PURE__ */ h(
"svg",
{
width: "16",
height: "16",
viewBox: "0 0 16 16",
fill: "none",
xmlns: "http://www.w3.org/2000/svg",
children: /* @__PURE__ */ h(
"path",
{
d: "M2.16666 6.16667H13.8333M4.90732 3.16667V1.83333M11.074 3.16667V1.83333M11.5 3.16667H4.49999C3.88115 3.16667 3.28766 3.4125 2.85007 3.85008C2.41249 4.28767 2.16666 4.88116 2.16666 5.5V11.8333C2.16666 12.4522 2.41249 13.0457 2.85007 13.4832C3.28766 13.9208 3.88115 14.1667 4.49999 14.1667H11.5C12.1188 14.1667 12.7123 13.9208 13.1499 13.4832C13.5875 13.0457 13.8333 12.4522 13.8333 11.8333V5.5C13.8333 4.88116 13.5875 4.28767 13.1499 3.85008C12.7123 3.4125 12.1188 3.16667 11.5 3.16667Z",
stroke: "currentColor",
strokeWidth: "1.5",
strokeLinecap: "round",
strokeLinejoin: "round"
}
)
}
), s3 = 4, G = "1921-04-13", R = [
{ year: 1978, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 1979, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 1980, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 1981, months: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30] },
{ year: 1982, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 1983, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 1984, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 1985, months: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30] },
{ year: 1986, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 1987, months: [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 1988, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 1989, months: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30] },
{ year: 1990, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 1991, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30] },
{ year: 1992, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 1993, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 1994, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 1995, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30] },
{ year: 1996, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 1997, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 1998, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 1999, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2e3, months: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 2001, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2002, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2003, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2004, months: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 2005, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2006, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2007, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2008, months: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31] },
{ year: 2009, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2010, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2011, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2012, months: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30] },
{ year: 2013, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2014, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2015, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2016, months: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30] },
{ year: 2017, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2018, months: [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2019, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 2020, months: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2021, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2022, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30] },
{ year: 2023, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 2024, months: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2025, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2026, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2027, months: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 2028, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2029, months: [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2030, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2031, months: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 2032, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2033, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2034, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2035, months: [30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31] },
{ year: 2036, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2037, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2038, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2039, months: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30] },
{ year: 2040, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2041, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2042, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2043, months: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30] },
{ year: 2044, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2045, months: [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2046, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2047, months: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2048, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2049, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30] },
{ year: 2050, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 2051, months: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2052, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2053, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30] },
{ year: 2054, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 2055, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2056, months: [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2057, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2058, months: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 2059, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2060, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2061, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2062, months: [31, 31, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31] },
{ year: 2063, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2064, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2065, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2066, months: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31] },
{ year: 2067, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2068, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2069, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2070, months: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30] },
{ year: 2071, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2072, months: [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2073, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2074, months: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2075, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2076, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30] },
{ year: 2077, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 2078, months: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2079, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2080, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30] },
{ year: 2081, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 2082, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2083, months: [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30] },
{ year: 2084, months: [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30] },
{ year: 2085, months: [31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30] },
{ year: 2086, months: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30] },
{ year: 2087, months: [31, 31, 32, 31, 31, 31, 30, 30, 30, 30, 30, 30] },
{ year: 2088, months: [30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30] },
{ year: 2089, months: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30] },
{ year: 2090, months: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30] },
{ year: 2091, months: [31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30] },
{ year: 2092, months: [30, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30] },
{ year: 2093, months: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30] },
{ year: 2094, months: [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30] },
{ year: 2095, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 30, 30, 30] },
{ year: 2096, months: [30, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2097, months: [31, 32, 31, 31, 31, 30, 30, 30, 29, 30, 30, 30] },
{ year: 2098, months: [31, 31, 32, 31, 31, 31, 29, 30, 29, 30, 29, 31] },
{ year: 2099, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] }
], i3 = () => {
let e = s3;
for (let t = 0; t < R.length; t++) {
const n = R[t];
R[t].startWeek = n.months.map((r) => {
const o = e;
return e = (r + o) % 7, e = e === 0 ? 7 : e, o;
});
}
};
i3();
const k = R, K = k[0].year, Q = k[k.length - 1].year, c3 = Array.from({ length: k.length }).map(
(e, t) => K + t
), e3 = [
{ name_np: "बैशाख", name_en: "Baisakh", month_position: 1 },
{ name_np: "जेठ", name_en: "Jestha", month_position: 2 },
{ name_np: "असार", name_en: "Asar", month_position: 3 },
{ name_np: "साउन", name_en: "Shrawan", month_position: 4 },
{ name_np: "भदौ", name_en: "Bhadra", month_position: 5 },
{ name_np: "असोज", name_en: "Ashoj", month_position: 6 },
{ name_np: "कार्तिक", name_en: "Kartik", month_position: 7 },
{ name_np: "मंसिर", name_en: "Mangsir", month_position: 8 },
{ name_np: "पुष", name_en: "Poush", month_position: 9 },
{ name_np: "माघ", name_en: "Magh", month_position: 10 },
{ name_np: "फागुन", name_en: "Falgun", month_position: 11 },
{ name_np: "चैत", name_en: "Chaitra", month_position: 12 }
], h3 = [
{ name_en: "Sun", name_np: "आइत", week_position: 1 },
{ name_en: "Mon", name_np: "सोम", week_position: 2 },
{ name_en: "Tue", name_np: "मंगल", week_position: 3 },
{ name_en: "Wed", name_np: "बुध", week_position: 4 },
{ name_en: "Thu", name_np: "बिही", week_position: 5 },
{ name_en: "Fri", name_np: "शुक्र", week_position: 6 },
{ name_en: "Sat", name_np: "शनि", week_position: 7 }
], d3 = 32, l3 = "gray", m3 = "white", z = 220, C = 284, g = (e) => {
try {
const [t, n, r, ...o] = e.split("-");
return (o == null ? void 0 : o.length) > 0 ? {
year: "yyyy",
month: "mm",
day: "dd"
} : {
year: t,
month: n,
day: r
};
} catch {
return {
year: "yyyy",
month: "mm",
day: "dd"
};
}
}, _ = (e) => {
if (!e) return !1;
try {
const { year: t, month: n, day: r } = g(e), o = k.find(({ year: a }) => a === +t);
return o ? +r >= 1 && +r <= o.months[+n - 1] || r === "dd" : !1;
} catch {
return !1;
}
}, H = (e) => {
try {
const { year: t, month: n } = g(e), r = k.find(({ year: o }) => o === +t);
return r ? r.months[+n - 1] : 0;
} catch {
return 0;
}
}, y3 = (e) => {
try {
const { year: t, month: n } = g(e);
return +n == 1 ? +t > k[0].year ? H(`${+t - 1}-12-dd`) : 0 : H(`${t}-${+n - 1}-dd`);
} catch {
return 0;
}
}, j = (e) => {
try {
const { year: t, month: n } = g(e);
return +n == 1 && +t > k[0].year ? `${+t - 1}-12-dd` : `${t}-${(+n - 1).toString().padStart(2, "0")}-dd`;
} catch {
return "";
}
}, q = (e) => {
try {
const { year: t, month: n } = g(e);
return +n == 12 && +t < k[k.length - 1].year ? `${+t + 1}-01-dd` : `${t}-${(+n + 1).toString().padStart(2, "0")}-dd`;
} catch {
return "";
}
}, B = () => {
const e = Math.ceil(
((/* @__PURE__ */ new Date()).getTime() - new Date(G).getTime()) / 864e5
);
let t = 0;
for (let n = 0; n < k.length; n++) {
const { year: r, months: o } = k[n];
for (let a = 0; a < o.length; a++) {
const s = t + o[a];
if (s < e)
t = s;
else {
const i = (a + 1).toString().padStart(2, "0"), c = (e - t).toString().padStart(2, "0");
return `${r}-${i}-${c}`;
}
}
}
return "";
}, x = (e, t) => {
const { year: n, month: r, day: o } = g(e), { year: a, month: s, day: i } = g(t), c = isNaN(+o) || isNaN(+i);
return n === a ? r === s ? c ? !0 : +o >= +i : +r >= +s : +n >= +a;
}, V = (e, t) => {
const { year: n, month: r, day: o } = g(e), { year: a, month: s, day: i } = g(t), c = isNaN(+o) || isNaN(+i);
return n === a ? r === s ? c ? !0 : +o <= +i : +r <= +s : +n <= +a;
}, t3 = (e) => typeof e != "string" ? "" : (e = e.replace(/\s/g, ""), e.split("-").map((t) => t.length === 1 ? t.padStart(2, "0") : t).join("-")), u3 = (e) => e ? e.split("-").map((t) => +t) : [0, 0, 0], F = (e, t, n) => {
if (!t && !n) return !0;
let r = !1;
if (t && _(t))
if (x(e, t ?? "")) r = !0;
else return !1;
if (n && _(n))
if (V(e, n ?? "")) r = !0;
else return !1;
return r;
}, f3 = (e, t, n, r) => {
const o = B();
let a = o;
return r && F(e, t, n) ? e : (F(o, t, n) ? a = o : t && _(t) ? a = t : n && _(n) && (a = n), a = t3(a), a = a.slice(0, 8) + "dd", a);
}, M3 = (e) => {
if (!e || typeof e != "string") return "";
try {
const t = Math.ceil(
(new Date(e).getTime() - new Date(G).getTime()) / 864e5
) + 1;
let n = 0;
for (let r = 0; r < k.length; r++) {
const { year: o, months: a } = k[r];
for (let s = 0; s < a.length; s++) {
const i = n + a[s];
if (i < t)
n = i;
else {
const c = (s + 1).toString().padStart(2, "0"), d = (t - n).toString().padStart(2, "0");
return `${o}-${c}-${d}`;
}
}
}
} catch {
return "";
}
return "";
}, $3 = (e) => {
if (!e || typeof e != "string" || !_(e))
return "";
try {
let t = 0;
const { year: n, month: r, day: o } = g(e);
for (let s = 0; s < k.length; s++) {
const i = k[s];
if (i.year === +n) {
for (let c = 0; c < i.months.length; c++) {
const d = i.months[c];
if (c + 1 < +r)
t += d;
else {
t += +o - 1;
break;
}
}
break;
} else
i.months.forEach((c) => {
t += c;
});
}
return new Date(
t * 24 * 60 * 60 * 1e3 + new Date(G).getTime()
).toISOString().split("T")[0];
} catch {
return "";
}
}, I3 = (e) => {
if (!_(e))
return console.error("Invalid date passed."), {};
const t = B();
if (!F(e, "", t))
return console.error("Date of birth should not be future date."), {};
let n = 0, r = 0, o = 0;
try {
const {
year: a,
month: s,
day: i
} = g(e), {
year: c,
month: d,
day: l
} = g(t);
if (isNaN(+a) || isNaN(+s) || isNaN(+i))
return {};
+d > +s ? n = +c - +a : +d == +s ? (n = +c - +a, +l < +i && n--) : n = +c - +a - 1, n < 0 && (n = 0), +c - n > +a ? (r = 12 - +s, r += +d, +l < +i && r--) : (r = +d - +s, +l < +i && r--);
let u = +s + r;
if (u >= 12 && (u = u - 12), +d - u != 0) {
const { year: D, month: f } = g(
j(t)
), m = k.find(
(p) => p.year === +D
);
if (!m) return {};
o = m.months[+f - 1] - +i, o += +l;
} else
o = +l - +i;
} catch {
return {};
}
return { years: n, months: r, days: o };
}, p3 = ({
event: e,
container: t,
input: n
}) => {
const r = e.target;
if (r === t || t.contains(r))
return;
const o = n.value;
return _(o) ? o : "";
};
var U = /* @__PURE__ */ ((e) => (e.AUTO = "auto", e.TOP = "top", e.BOTTOM = "bottom", e))(U || {});
const k3 = (e, t) => {
let n = 0, r = 0;
const o = e.getBoundingClientRect(), a = o.left, s = o.top, i = window.document.documentElement.scrollWidth, c = a + z, d = s + C + o.height;
return t === "fixed" ? (n = c > i ? i - z : o.x, r = o.y) : (n = c > i ? -c + i : 0, d > innerHeight && innerHeight > C + o.height && s > C ? r = -1 : r = 1), { x: n, y: r };
}, _3 = (e, t, n, r) => r === "fixed" ? t > 0 && t + C + n > window.innerHeight && t > C ? t - C : t + n + 2 : e === U.AUTO ? t > 0 ? n + 2 : -C : e === U.TOP ? -C : n + 2, D3 = r3(
({
value: e,
onChange: t,
inputContainerStyles: n,
setIsCalendarOpen: r,
disabled: o,
placeholder: a,
inputElement: s,
hasCalendarIcon: i = !0,
calendarIcon: c,
calendarColor: d
}, l) => {
const u = () => {
const m = l && "current" in l && l.current;
m == null || m.focus();
};
I(() => {
const m = l && "current" in l && l.current;
if (!m) return;
const p = () => {
r(!0), m.setSelectionRange(10, 10);
}, y = (w) => {
const v = m.value;
w.key === "Enter" && m.value ? (t(_(v) ? v : ""), r(!1), m.blur()) : w.key === "Tab" && (t(v), r(!1));
};
return m.addEventListener("focus", p), m.addEventListener("keydown", y), s && m.addEventListener("click", p), () => {
m.removeEventListener("focus", p), m.removeEventListener("keydown", y), s && m.removeEventListener("click", p);
};
}, []);
const { height: D, ...f } = n;
return /* @__PURE__ */ h(J, { children: s ? /* @__PURE__ */ h(
"div",
{
ref: l,
style: {
width: f.width
},
children: s
}
) : /* @__PURE__ */ A(
"div",
{
className: `date-picker-input-container ${o ? "date-picker-input-container-disabled" : ""}`,
onClick: u,
style: {
paddingRight: i ? "20px" : void 0,
...f
},
children: [
/* @__PURE__ */ h(
"input",
{
ref: l,
type: "text",
placeholder: a ?? "Select Date",
className: `date-picker-input ${o ? "date-picker-input-disabled" : ""}`,
style: {
height: D
},
disabled: o,
...o ? {
value: e,
onChange: () => {
}
} : {}
}
),
i && /* @__PURE__ */ h(
"div",
{
className: "date-picker-input-right-icon",
style: {
color: d || l3,
opacity: o ? 0.5 : 1
},
children: c ?? /* @__PURE__ */ h(a3, {})
}
)
]
}
) });
}
), g3 = [
"०",
"१",
"२",
"३",
"४",
"५",
"६",
"७",
"८",
"९"
], b = (e, t) => !t || e === "en" ? t : t.toString().split("").map((n) => n >= "0" && n <= "9" ? g3[+n] : n).join(""), w3 = ({ lang: e }) => /* @__PURE__ */ h("div", { className: "date-picker-body-container date-picker-week-days-container", children: h3.map(({ name_en: t, name_np: n }) => /* @__PURE__ */ h("div", { children: e === "en" ? t : n }, t)) }), v3 = ({
date: e,
handleChange: t,
min: n,
max: r,
lang: o,
calendarStyles: a
}) => {
var y;
const s = H(e), i = y3(e), { year: c, month: d, day: l } = g(e), u = (y = k.find((w) => w.year === +c)) == null ? void 0 : y.startWeek[+d - 1], D = i - u + 2, f = (s + u - 1) % 7;
let m = f > 0 ? 7 - f : 0;
return (u - 1 + s + (f > 0 ? 7 - f : 0)) / 7 === 5 && (m = m + 7), /* @__PURE__ */ A(J, { children: [
/* @__PURE__ */ h(w3, { lang: o }),
/* @__PURE__ */ A("div", { className: "date-picker-body-container date-picker-dates-container", children: [
Array.from({ length: u - 1 }).map((w, v) => /* @__PURE__ */ h("div", { className: "prev-month-days", children: b(
o,
i > 0 ? D + v : void 0
) }, v)),
Array.from({ length: s }).map((w, v) => {
var $, O, N;
const T = v + 1;
let E = !1;
n && _(n) && (E = !x(
e.slice(0, 8) + T,
n
)), !E && r && _(r) && (E = !V(
e.slice(0, 8) + T,
r
));
const S = T === +l;
return /* @__PURE__ */ h(
"div",
{
className: `${S ? "date-picker-selected-date" : ""} ${E ? "date-picker-date-disabled" : ""}`,
onClick: () => !E && t(T),
style: {
...S ? {
color: ($ = a == null ? void 0 : a.dates) == null ? void 0 : $.activeTextColor,
backgroundColor: (O = a == null ? void 0 : a.dates) == null ? void 0 : O.activeBackgroundColor
} : {
"--date-picker-np-hover-color": (N = a == null ? void 0 : a.dates) == null ? void 0 : N.hoverBackgroundColor
}
},
children: b(o, T)
},
v
);
}),
Array.from({
length: m
}).map((w, v) => /* @__PURE__ */ h("div", { className: "next-month-days", children: b(o, v + 1) }, v))
] })
] });
}, N3 = ({
hasValidValue: e,
onChange: t,
min: n,
max: r,
lang: o,
calendarStyles: a
}) => {
var d;
let s = !1;
const i = B();
n && _(n) && (s = !x(i, n)), !s && r && _(r) && (s = !V(i, r));
const c = (d = a == null ? void 0 : a.footer) == null ? void 0 : d.textColor;
return /* @__PURE__ */ A("div", { className: "date-picker-calendar-footer", children: [
/* @__PURE__ */ h(
"div",
{
className: `date-picker-calendar-footer-btn ${e ? "" : "date-picker-calendar-footer-btn-disabled"}`,
style: {
color: c
},
onClick: () => e && t(""),
children: o === "en" ? "Clear" : "हटाउनुहोस्"
}
),
/* @__PURE__ */ h(
"div",
{
className: `date-picker-calendar-footer-btn ${s ? "date-picker-calendar-footer-btn-disabled" : ""}`,
style: {
color: c
},
onClick: () => !s && t(B()),
children: o === "en" ? "Today" : "आज"
}
)
] });
}, T3 = ({
selectedYear: e,
setSelectedYear: t,
setActiveSelector: n,
lang: r,
minYear: o,
maxYear: a
}) => {
const s = Y(null), i = (c) => {
t(c), n("month");
};
return I(() => {
const d = s.current.children;
for (let l = 0; l < d.length; l++)
if (d[l].textContent === String(b(r, e))) {
d[l].scrollIntoView({
block: "nearest",
inline: "nearest"
});
break;
}
}, [e, r]), /* @__PURE__ */ h(
"div",
{
ref: s,
className: "date-picker-year-selector-block-container",
children: c3.map((c) => {
const d = c === e, l = c < o || c > a;
return /* @__PURE__ */ h(
"div",
{
onClick: () => !l && i(c),
className: `
${d ? "date-picker-year-selector-block-selected" : ""} ${l ? "date-picker-selector-block-disabled" : ""}`,
children: b(r, c)
},
c
);
})
}
);
}, E3 = ({
handleMonthChange: e,
minMonth: t,
maxMonth: n,
lang: r
}) => /* @__PURE__ */ h("div", { className: "date-picker-selector-block-container", children: e3.map(({ name_en: o, name_np: a, month_position: s }) => {
const i = s < t || s > n;
return /* @__PURE__ */ h(
"div",
{
onClick: () => !i && e(s),
className: i ? "date-picker-selector-block-disabled" : void 0,
children: /* @__PURE__ */ h("div", { children: r === "en" ? o : a })
},
o
);
}) }), A3 = ({
year: e,
handleChange: t,
setIsDropdownOpen: n,
min: r,
max: o,
lang: a
}) => {
const [s, i] = M(
"year"
), [c, d] = M(e);
let l = K, u = Q, D = 1, f = 12;
if (r && _(r)) {
const { year: y, month: w } = g(r);
l = +y, c === +y && (D = +w);
}
if (o && _(o)) {
const { year: y, month: w } = g(o);
u = +y, c === +y && (f = +w);
}
const m = (y) => {
t(`${c}-${y.toString().padStart(2, "0")}-dd`), setTimeout(() => n(!1));
};
return I(() => {
const y = (w) => {
w.key === "Escape" && n(!1);
};
return window.addEventListener("keydown", y), () => window.removeEventListener("keydown", y);
}, []), /* @__PURE__ */ A("div", { className: "date-picker-selector-container", children: [
/* @__PURE__ */ h("div", { className: "date-picker-selector-header", children: /* @__PURE__ */ h("div", { className: "date-picker-calendar-header-dropdown-text", children: b(a, s === "year" ? "Select Year" : "Select Month") }) }),
s === "year" && /* @__PURE__ */ h(
T3,
{
selectedYear: c,
setSelectedYear: d,
setActiveSelector: i,
minYear: l,
maxYear: u,
lang: a
}
),
s === "month" && /* @__PURE__ */ h(
E3,
{
handleMonthChange: m,
minMonth: D,
maxMonth: f,
lang: a
}
)
] });
}, C3 = ({
date: e,
handleChange: t,
min: n,
max: r,
lang: o
}) => {
var m;
const [a, s] = M(!1), i = () => t(q(e)), c = () => t(j(e)), [d, l] = u3(e);
let u = d === K && l === 1, D = d === Q && l === 12;
n && _(n) && !u && (u = !x(
j(e),
n
)), r && _(r) && !D && (D = !V(
q(e),
r
));
const f = `${(m = e3[l - 1]) == null ? void 0 : m[o === "en" ? "name_en" : "name_np"]} ${b(o, d)}`;
return /* @__PURE__ */ A("div", { className: "date-picker-calendar-header", children: [
/* @__PURE__ */ h(
"div",
{
className: `date-picker-calendar-header-arrow ${u ? "date-picker-calendar-header-arrow-disabled" : ""}`,
onClick: () => !u && c(),
children: /* @__PURE__ */ h(o3, {})
}
),
/* @__PURE__ */ A("div", { className: "date-picker-calendar-header-dropdown-container", children: [
/* @__PURE__ */ h(
"p",
{
className: "date-picker-calendar-header-dropdown-text",
onClick: () => s(!a),
children: f
}
),
a && /* @__PURE__ */ h(
A3,
{
year: d,
handleChange: t,
setIsDropdownOpen: s,
min: n,
max: r,
lang: o
}
)
] }),
/* @__PURE__ */ h(
"div",
{
className: `date-picker-calendar-header-arrow ${D ? "date-picker-calendar-header-arrow-disabled" : ""}`,
onClick: () => !D && i(),
children: /* @__PURE__ */ h(Z, {})
}
)
] });
}, L3 = ({
value: e = "yyyy-mm-dd",
onChange: t,
calendarPositions: n,
min: r,
max: o,
lang: a,
calendarStyles: s,
position: i
}) => {
const c = _(e), [d, l] = M(""), u = (f) => {
const { year: m, month: p } = g(d);
t(
`${m}-${p.toString().padStart(2, "0")}-${f.toString().padStart(2, "0")}`
);
};
X(() => {
const f = f3(e, r, o, c);
l(f);
}, [e]);
const D = d.slice(0, 7) === (e == null ? void 0 : e.slice(0, 7)) ? e : d;
return /* @__PURE__ */ A(
"div",
{
className: "date-picker-calendar",
style: {
...n,
position: i === "fixed" ? i : void 0
},
children: [
/* @__PURE__ */ h(
C3,
{
date: d,
handleChange: (f) => l(f),
min: r,
max: o,
lang: a,
calendarStyles: s
}
),
/* @__PURE__ */ h(
v3,
{
date: D,
handleChange: u,
min: r,
max: o,
lang: a,
calendarStyles: s
}
),
/* @__PURE__ */ h(
N3,
{
hasValidValue: c,
onChange: t,
min: r,
max: o,
lang: a,
calendarStyles: s
}
)
]
}
);
}, O3 = ({
value: e,
onChange: t,
min: n,
max: r,
disabled: o,
placeholder: a,
inputElement: s,
inputContainerStyles: i = {},
calendarStyles: c = {},
hasCalendarIcon: d,
calendarIcon: l,
calendarColor: u,
lang: D = "en",
menuPosition: f = "auto",
position: m = "absolute"
}) => {
const p = Y(null), y = Y(null), [w, v] = M({
x: 0,
y: 0
}), [T, E] = M(!1), S = (N) => {
if (o) return;
const L = t3(N);
t(
F(L, n, r) ? L : ""
), E(!1), y.current && (y.current.value = L ?? "");
};
X(() => {
const N = () => {
if (!T) return;
const { x: L, y: P } = k3(
p == null ? void 0 : p.current,
m
);
v({ x: L, y: P });
};
return N(), window.addEventListener("resize", N, !0), window.addEventListener("scroll", N, !0), () => {
window.removeEventListener("resize", N, !0), window.removeEventListener("scroll", N, !0);
};
}, [T, m]), I(() => {
const N = y == null ? void 0 : y.current, L = p == null ? void 0 : p.current;
if (!N || !T) return;
const P = (n3) => {
const W = p3({
event: n3,
container: L,
input: N
});
W !== void 0 && (W !== e ? S(W) : E(!1));
};
return window.addEventListener("mousedown", P), () => {
window.removeEventListener("mousedown", P);
};
}, [T]), I(() => {
y.current && (y.current.value = _(e) ? e ?? "" : "");
}, [e]);
const $ = (i == null ? void 0 : i.height) || d3, O = _3(
f,
w.y,
$,
m
);
return /* @__PURE__ */ A(
"div",
{
className: "date-picker-container",
ref: p,
style: {
width: i.width
},
children: [
/* @__PURE__ */ h(
D3,
{
ref: y,
value: e,
onChange: S,
setIsCalendarOpen: E,
inputContainerStyles: {
...i,
height: $,
background: i.background ?? m3
},
disabled: o,
placeholder: a,
inputElement: s,
hasCalendarIcon: d,
calendarIcon: l,
calendarColor: u
}
),
!o && T && /* @__PURE__ */ h(
L3,
{
position: m,
calendarPositions: {
top: O,
left: w.x,
zIndex: 1e6
},
value: e,
onChange: S,
min: n,
max: r,
lang: D,
calendarStyles: {
...c
}
}
)
]
}
);
};
export {
I3 as calculateAge,
M3 as convertADToBS,
$3 as convertBSToAD,
O3 as default,
B as getTodayBSDate
};