persian-date-kit 0.0.3 → 0.0.5

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Darvix
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  Production-ready Persian (Jalali) date pickers for React.
4
4
 
5
+ [![GitHub](https://img.shields.io/github/stars/aliseyedabady/darvix-persian-date-kit?style=social)](https://github.com/aliseyedabady/darvix-persian-date-kit)
6
+
7
+ **Repository:** [https://github.com/aliseyedabady/darvix-persian-date-kit](https://github.com/aliseyedabady/darvix-persian-date-kit)
8
+
5
9
  ## Key principles
6
10
  - **Gregorian-only internally**: component values are always `Date | null` (Gregorian). Jalali is only for display/input.
7
11
  - **Controlled components**: you own the state (`value` + `onChange`).
@@ -142,7 +146,30 @@ export function RHFExample() {
142
146
 
143
147
  ## Development (this repo)
144
148
 
149
+ Clone the repository:
150
+
151
+ ```bash
152
+ git clone https://github.com/aliseyedabady/darvix-persian-date-kit.git
153
+ cd darvix-persian-date-kit
154
+ npm install
155
+ ```
156
+
157
+ Run development server:
158
+
145
159
  ```bash
146
160
  npm run dev
161
+ ```
162
+
163
+ Build for production:
164
+
165
+ ```bash
147
166
  npm run build
148
167
  ```
168
+
169
+ ## Contributing
170
+
171
+ Contributions are welcome! Please feel free to submit a Pull Request.
172
+
173
+ ## License
174
+
175
+ MIT © [Darvix](https://github.com/aliseyedabady/darvix-persian-date-kit)
@@ -0,0 +1 @@
1
+ "use strict";const O=require("react/jsx-runtime"),ue=require("react"),ce=require("react-dom");function de(t){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const e=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(r,s,e.get?e:{enumerable:!0,get:()=>t[s]})}}return r.default=t,Object.freeze(r)}const b=de(ue);function Ft(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var vt={exports:{}},le=vt.exports,Pt;function Rt(){return Pt||(Pt=1,(function(t,r){(function(s,e){t.exports=e()})(le,(function(){var s=1e3,e=6e4,p=36e5,l="millisecond",v="second",x="minute",L="hour",D="day",U="week",M="month",tt="quarter",N="year",S="date",P="Invalid Date",W=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,C=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,F={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(i){var n=["th","st","nd","rd"],o=i%100;return"["+i+(n[(o-20)%10]||n[o]||n[0])+"]"}},Y=function(i,n,o){var h=String(i);return!h||h.length>=n?i:""+Array(n+1-h.length).join(o)+i},rt={s:Y,z:function(i){var n=-i.utcOffset(),o=Math.abs(n),h=Math.floor(o/60),u=o%60;return(n<=0?"+":"-")+Y(h,2,"0")+":"+Y(u,2,"0")},m:function i(n,o){if(n.date()<o.date())return-i(o,n);var h=12*(o.year()-n.year())+(o.month()-n.month()),u=n.clone().add(h,M),$=o-u<0,y=n.clone().add(h+($?-1:1),M);return+(-(h+(o-u)/($?u-y:y-u))||0)},a:function(i){return i<0?Math.ceil(i)||0:Math.floor(i)},p:function(i){return{M,y:N,w:U,d:D,D:S,h:L,m:x,s:v,ms:l,Q:tt}[i]||String(i||"").toLowerCase().replace(/s$/,"")},u:function(i){return i===void 0}},G="en",H={};H[G]=F;var et="$isDayjsObject",B=function(i){return i instanceof w||!(!i||!i[et])},d=function i(n,o,h){var u;if(!n)return G;if(typeof n=="string"){var $=n.toLowerCase();H[$]&&(u=$),o&&(H[$]=o,u=$);var y=n.split("-");if(!u&&y.length>1)return i(y[0])}else{var _=n.name;H[_]=n,u=_}return!h&&u&&(G=u),u||!h&&G},c=function(i,n){if(B(i))return i.clone();var o=typeof n=="object"?n:{};return o.date=i,o.args=arguments,new w(o)},f=rt;f.l=d,f.i=B,f.w=function(i,n){return c(i,{locale:n.$L,utc:n.$u,x:n.$x,$offset:n.$offset})};var w=(function(){function i(o){this.$L=d(o.locale,null,!0),this.parse(o),this.$x=this.$x||o.x||{},this[et]=!0}var n=i.prototype;return n.parse=function(o){this.$d=(function(h){var u=h.date,$=h.utc;if(u===null)return new Date(NaN);if(f.u(u))return new Date;if(u instanceof Date)return new Date(u);if(typeof u=="string"&&!/Z$/i.test(u)){var y=u.match(W);if(y){var _=y[2]-1||0,k=(y[7]||"0").substring(0,3);return $?new Date(Date.UTC(y[1],_,y[3]||1,y[4]||0,y[5]||0,y[6]||0,k)):new Date(y[1],_,y[3]||1,y[4]||0,y[5]||0,y[6]||0,k)}}return new Date(u)})(o),this.init()},n.init=function(){var o=this.$d;this.$y=o.getFullYear(),this.$M=o.getMonth(),this.$D=o.getDate(),this.$W=o.getDay(),this.$H=o.getHours(),this.$m=o.getMinutes(),this.$s=o.getSeconds(),this.$ms=o.getMilliseconds()},n.$utils=function(){return f},n.isValid=function(){return this.$d.toString()!==P},n.isSame=function(o,h){var u=c(o);return this.startOf(h)<=u&&u<=this.endOf(h)},n.isAfter=function(o,h){return c(o)<this.startOf(h)},n.isBefore=function(o,h){return this.endOf(h)<c(o)},n.$g=function(o,h,u){return f.u(o)?this[h]:this.set(u,o)},n.unix=function(){return Math.floor(this.valueOf()/1e3)},n.valueOf=function(){return this.$d.getTime()},n.startOf=function(o,h){var u=this,$=!!f.u(h)||h,y=f.p(o),_=function(st,V){var nt=f.w(u.$u?Date.UTC(u.$y,V,st):new Date(u.$y,V,st),u);return $?nt:nt.endOf(D)},k=function(st,V){return f.w(u.toDate()[st].apply(u.toDate("s"),($?[0,0,0,0]:[23,59,59,999]).slice(V)),u)},J=this.$W,E=this.$M,R=this.$D,K="set"+(this.$u?"UTC":"");switch(y){case N:return $?_(1,0):_(31,11);case M:return $?_(1,E):_(0,E+1);case U:var z=this.$locale().weekStart||0,it=(J<z?J+7:J)-z;return _($?R-it:R+(6-it),E);case D:case S:return k(K+"Hours",0);case L:return k(K+"Minutes",1);case x:return k(K+"Seconds",2);case v:return k(K+"Milliseconds",3);default:return this.clone()}},n.endOf=function(o){return this.startOf(o,!1)},n.$set=function(o,h){var u,$=f.p(o),y="set"+(this.$u?"UTC":""),_=(u={},u[D]=y+"Date",u[S]=y+"Date",u[M]=y+"Month",u[N]=y+"FullYear",u[L]=y+"Hours",u[x]=y+"Minutes",u[v]=y+"Seconds",u[l]=y+"Milliseconds",u)[$],k=$===D?this.$D+(h-this.$W):h;if($===M||$===N){var J=this.clone().set(S,1);J.$d[_](k),J.init(),this.$d=J.set(S,Math.min(this.$D,J.daysInMonth())).$d}else _&&this.$d[_](k);return this.init(),this},n.set=function(o,h){return this.clone().$set(o,h)},n.get=function(o){return this[f.p(o)]()},n.add=function(o,h){var u,$=this;o=Number(o);var y=f.p(h),_=function(E){var R=c($);return f.w(R.date(R.date()+Math.round(E*o)),$)};if(y===M)return this.set(M,this.$M+o);if(y===N)return this.set(N,this.$y+o);if(y===D)return _(1);if(y===U)return _(7);var k=(u={},u[x]=e,u[L]=p,u[v]=s,u)[y]||1,J=this.$d.getTime()+o*k;return f.w(J,this)},n.subtract=function(o,h){return this.add(-1*o,h)},n.format=function(o){var h=this,u=this.$locale();if(!this.isValid())return u.invalidDate||P;var $=o||"YYYY-MM-DDTHH:mm:ssZ",y=f.z(this),_=this.$H,k=this.$m,J=this.$M,E=u.weekdays,R=u.months,K=u.meridiem,z=function(V,nt,ut,Z){return V&&(V[nt]||V(h,$))||ut[nt].slice(0,Z)},it=function(V){return f.s(_%12||12,V,"0")},st=K||function(V,nt,ut){var Z=V<12?"AM":"PM";return ut?Z.toLowerCase():Z};return $.replace(C,(function(V,nt){return nt||(function(ut){switch(ut){case"YY":return String(h.$y).slice(-2);case"YYYY":return f.s(h.$y,4,"0");case"M":return J+1;case"MM":return f.s(J+1,2,"0");case"MMM":return z(u.monthsShort,J,R,3);case"MMMM":return z(R,J);case"D":return h.$D;case"DD":return f.s(h.$D,2,"0");case"d":return String(h.$W);case"dd":return z(u.weekdaysMin,h.$W,E,2);case"ddd":return z(u.weekdaysShort,h.$W,E,3);case"dddd":return E[h.$W];case"H":return String(_);case"HH":return f.s(_,2,"0");case"h":return it(1);case"hh":return it(2);case"a":return st(_,k,!0);case"A":return st(_,k,!1);case"m":return String(k);case"mm":return f.s(k,2,"0");case"s":return String(h.$s);case"ss":return f.s(h.$s,2,"0");case"SSS":return f.s(h.$ms,3,"0");case"Z":return y}return null})(V)||y.replace(":","")}))},n.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},n.diff=function(o,h,u){var $,y=this,_=f.p(h),k=c(o),J=(k.utcOffset()-this.utcOffset())*e,E=this-k,R=function(){return f.m(y,k)};switch(_){case N:$=R()/12;break;case M:$=R();break;case tt:$=R()/3;break;case U:$=(E-J)/6048e5;break;case D:$=(E-J)/864e5;break;case L:$=E/p;break;case x:$=E/e;break;case v:$=E/s;break;default:$=E}return u?$:f.a($)},n.daysInMonth=function(){return this.endOf(M).$D},n.$locale=function(){return H[this.$L]},n.locale=function(o,h){if(!o)return this.$L;var u=this.clone(),$=d(o,h,!0);return $&&(u.$L=$),u},n.clone=function(){return f.w(this.$d,this)},n.toDate=function(){return new Date(this.valueOf())},n.toJSON=function(){return this.isValid()?this.toISOString():null},n.toISOString=function(){return this.$d.toISOString()},n.toString=function(){return this.$d.toUTCString()},i})(),m=w.prototype;return c.prototype=m,[["$ms",l],["$s",v],["$m",x],["$H",L],["$W",D],["$M",M],["$y",N],["$D",S]].forEach((function(i){m[i[1]]=function(n){return this.$g(n,i[0],i[1])}})),c.extend=function(i,n){return i.$i||(i(n,w,c),i.$i=!0),c},c.locale=d,c.isDayjs=B,c.unix=function(i){return c(1e3*i)},c.en=H[G],c.Ls=H,c.p={},c}))})(vt)),vt.exports}var fe=Rt();const Ct=Ft(fe);var _t={exports:{}},he=_t.exports,Jt;function pe(){return Jt||(Jt=1,(function(t,r){(function(s,e){t.exports=e(Rt())})(he,(function(s){function e(v){return v&&typeof v=="object"&&"default"in v?v:{default:v}}var p=e(s),l={name:"fa",weekdays:"یک‌شنبه_دوشنبه_سه‌شنبه_چهارشنبه_پنج‌شنبه_جمعه_شنبه".split("_"),weekdaysShort:"یک‌شنبه_دوشنبه_سه‌شنبه_چهارشنبه_پنج‌شنبه_جمعه_شنبه".split("_"),weekdaysMin:"ی_د_س_چ_پ_ج_ش".split("_"),weekStart:6,months:"ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر".split("_"),monthsShort:"ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر".split("_"),ordinal:function(v){return v},formats:{LT:"HH:mm",LTS:"HH:mm:ss",L:"DD/MM/YYYY",LL:"D MMMM YYYY",LLL:"D MMMM YYYY HH:mm",LLLL:"dddd, D MMMM YYYY HH:mm"},relativeTime:{future:"در %s",past:"%s پیش",s:"چند ثانیه",m:"یک دقیقه",mm:"%d دقیقه",h:"یک ساعت",hh:"%d ساعت",d:"یک روز",dd:"%d روز",M:"یک ماه",MM:"%d ماه",y:"یک سال",yy:"%d سال"}};return p.default.locale(l,null,!0),l}))})(_t)),_t.exports}var me=pe();const ye=Ft(me);function je(t,r,s){let e=A((t+A(r-8,6)+100100)*1461,4)+A(153*ft(r+9,12)+2,5)+s-34840408;return e=e-A(A(t+100100+A(r-8,6),100)*3,4)+752,e}const $t=[-61,9,38,199,426,686,756,818,1111,1181,1210,1635,2060,2097,2192,2262,2324,2394,2456,3178],at=Math.floor;function ft(t,r){return t-~~(t/r)*r}function A(t,r){return~~(t/r)}function $e(t,r){const s=$t.length,e=t+621;let p=-14,l=$t[0],v,x,L;if(t<l||t>=$t[s-1])throw new Error(`Invalid Jalaali year ${t}`);for(let M=1;M<s&&(v=$t[M],x=v-l,!(t<v));M+=1)p=p+A(x,33)*8+A(ft(x,33),4),l=v;L=t-l,p=p+A(L,33)*8+A(ft(L,33)+3,4),ft(x,33)===4&&x-L===4&&(p+=1);const D=A(e,4)-A((A(e,100)+1)*3,4)-150,U=20+p-D;return{gy:e,march:U}}function ge(t,r,s){const e=$e(t);return je(e.gy,3,e.march)+(r-1)*31-A(r,7)*(r-7)+s-1}function ve(t){let r=4*t+139361631;r=r+A(A(4*t+183187720,146097)*3,4)*4-3908;const s=A(ft(r,1461),4)*5+308,e=A(ft(s,153),5)+1,p=ft(A(s,153),12)+1;return[A(r,1461)-100100+A(8-p,6),p,e]}function _e(t,r,s){return ve(ge(t,r,s))}function Me(t,r,s){const e={year:t,month:r,day:s},p=[0,31,59,90,120,151,181,212,243,273,304,334];let l;t<=1600?(t-=621,e.year=0):(t-=1600,e.year=979);const v=t>2?t+1:t;return l=at((v+3)/4)+365*t-at((v+99)/100)-80+p[r-1]+at((v+399)/400)+s,e.year+=33*at(l/12053),l%=12053,e.year+=4*at(l/1461),l%=1461,l>365&&(e.year+=at((l-1)/365),l=(l-1)%365),e.month=l<186?1+at(l/31):7+at((l-186)/30),e.day=1+(l<186?l%31:(l-186)%30),[e.year,e.month,e.day]}var gt={J:(t,r,s)=>Me(t,r,s),G:(t,r,s)=>_e(t,r,s)};const De=/^(\d{4})[-/]?(\d{1,2})[-/]?(\d{0,2})(.*)$/,we=/\[.*?\]|jY{2,4}|jM{1,4}|jD{1,2}|Y{2,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,kt="date",pt="day",ct="month",dt="year",Tt="week",be="YYYY-MM-DDTHH:mm:ssZ",xe={jmonths:"فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند".split("_")},Se=(t,r,s)=>{const e=r.prototype,p=e.$utils(),l=d=>d.$C==="jalali",v=p.prettyUnit||p.p,x=p.isUndefined||p.u,L=p.padStart||p.s,D=p.monthDiff||p.m,U=p.absFloor||p.a,M=d=>function(...c){const f=d.bind(this)(...c);return f.$C=this.$C,f.isJalali()&&f.InitJalali(),f};e.startOf=M(e.startOf),e.endOf=M(e.endOf),e.add=M(e.add),e.subtract=M(e.subtract),e.set=M(e.set);const tt=e.parse,N=e.init,S=e.startOf,P=e.$set,W=e.add,C=e.format,F=e.diff,Y=e.year,rt=e.month,G=e.date,H=e.daysInMonth,et=e.toArray;s.$C="gregory",s.$fdow=6,s.calendar=function(d){return s.$C=d,s},e.calendar=function(d){const c=this.clone();return c.$C=d,c.isJalali()&&c.InitJalali(),c},e.isJalali=function(){return l(this)},s.en.jmonths="Farvardin_Ordibehesht_Khordaad_Tir_Mordaad_Shahrivar_Mehr_Aabaan_Aazar_Dey_Bahman_Esfand".split("_"),s.locale("fa",{...ye,...xe},!0);const B=function(d,c){return s(d,{locale:c.$L,utc:c.$u,calendar:c.$C})};e.init=function(d={}){N.bind(this)(d),this.isJalali()&&this.InitJalali()},e.parse=function(d){if(this.$C=d.calendar||this.$C||s.$C,d.jalali&&typeof d.date=="string"&&/.*[^Z]$/i.test(d.date)){const c=d.date.match(De);if(c){const[f,w,m]=gt.G(Number.parseInt(c[1],10),Number.parseInt(c[2],10),Number.parseInt(c[3]||1,10));d.date=`${f}-${w}-${m}${c[4]||""}`}}return tt.bind(this)(d)},e.InitJalali=function(){const[d,c,f]=gt.J(this.$y,this.$M+1,this.$D);this.$jy=d,this.$jM=c-1,this.$jD=f},e.startOf=function(d,c){if(!l(this))return S.bind(this)(d,c);const f=x(c)?!0:c,w=v(d),m=(n,o,h=this.$jy)=>{const[u,$,y]=gt.G(h,o+1,n),_=B(new Date(u,$-1,y),this);return(f?_:_.endOf(pt)).$set("hour",1)},i=(this.$W+(7-s.$fdow))%7;switch(w){case dt:return f?m(1,0):m(0,0,this.$jy+1);case ct:return f?m(1,this.$jM):m(0,(this.$jM+1)%12,this.$jy+Math.floor((this.$jM+1)/12));case Tt:return f?m(this.$jD-i,this.$jM):m(this.$jD+(6-i),this.$jM);default:return S.bind(this)(d,c)}},e.$set=function(d,c){if(!l(this))return P.bind(this)(d,c);const f=v(d),w=(m,i,n=this.$jy)=>{const[o,h,u]=gt.G(n,i+1,m);return this.$d.setFullYear(o),this.$d.setMonth(h-1),this.$d.setDate(u),this};switch(f){case kt:case pt:w(c,this.$jM);break;case ct:w(this.$jD,c);break;case dt:w(this.$jD,this.$jM,c);break;default:return P.bind(this)(d,c)}return this.init(),this},e.add=function(d,c){if(!l(this))return W.bind(this)(d,c);d=Number(d);const f=c&&(c.length===1||c==="ms")?c:v(c),w=(m,i)=>{const n=this.set(kt,1).set(m,i+d);return n.set(kt,Math.min(this.$jD,n.daysInMonth()))};if(["M",ct].includes(f)){const m=this.$jM+d,i=m<0?-Math.ceil(-m/12):Math.floor(m/12),n=this.$jD,o=this.set(pt,1).add(i,dt).set(ct,m-i*12);return o.set(pt,Math.min(o.daysInMonth(),n))}if(["y",dt].includes(f))return w(dt,this.$jy);if(["d",pt].includes(f)){const m=new Date(this.$d);return m.setDate(m.getDate()+d),B(m,this)}if(["w",Tt].includes(f)){const m=new Date(this.$d);return m.setDate(m.getDate()+d*7),B(m,this)}return W.bind(this)(d,c)},e.format=function(d,c){if(!l(this))return C.bind(this)(d,c);const f=d||be,w=c||this.$locale(),{jmonths:m}=w;return f.replace(we,i=>{if(i.includes("["))return i.replace(/\[|\]/g,"");switch(i){case"YY":return String(this.$jy).slice(-2);case"YYYY":return String(this.$jy);case"M":return String(this.$jM+1);case"MM":return L(this.$jM+1,2,"0");case"MMM":return m[this.$jM].slice(0,3);case"MMMM":return m[this.$jM];case"D":return String(this.$jD);case"DD":return L(this.$jD,2,"0");default:return C.bind(this)(i,c)}})},e.diff=function(d,c,f){if(!l(this))return F.bind(this)(d,c,f);const w=v(c),m=s(d);let i=D(this,m);switch(w){case dt:i/=12;break;case ct:break;default:return F.bind(this)(d,c,f)}return f?i:U(i)},e.$g=function(d,c,f){return x(d)?this[c]:this.set(f,d)},e.year=function(d){return l(this)?this.$g(d,"$jy",dt):Y.bind(this)(d)},e.month=function(d){return l(this)?this.$g(d,"$jM",ct):rt.bind(this)(d)},e.date=function(d){return l(this)?this.$g(d,"$jD",pt):G.bind(this)(d)},e.daysInMonth=function(){return l(this)?this.endOf(ct).$jD:H.bind(this)()},et&&(e.toArray=function(){return l(this)?[this.$jy,this.$jM,this.$jD,this.$H,this.$m,this.$s,this.$ms]:et.bind(this)()}),e.clone=function(){return B(this.toDate(),this)}};var ke=Se;Ct.extend(ke);function Dt(t){return String(t).padStart(2,"0")}function Ht(t){return String(t).padStart(4,"0")}function Q(t){const r=Ct(t).calendar("jalali");return{jy:r.year(),jm:r.month()+1,jd:r.date()}}function q(t){const{jy:r,jm:s,jd:e}=t,p=`${Ht(r)}-${Dt(s)}-${Dt(e)}`,l=Ct(p,{jalali:!0}).calendar("gregory").startOf("day");if(!l.isValid())throw new Error(`Invalid Jalali date parts: ${p}`);return l.toDate()}function Vt(t,r={}){const s=r.separator??"/";return`${Ht(t.jy)}${s}${Dt(t.jm)}${s}${Dt(t.jd)}`}function Ut(t){const r=Q(t);return{...r,formatted:Vt(r)}}function Ye(t){return t.replace(/[^\d]+/g,"-")}function Oe(t){return q(t)}function Wt(t,r={}){const s=t.trim();if(!s)return null;const p=(r.allowLooseSeparators?Ye(s):s).match(/^(\d{4})[-/](\d{1,2})[-/](\d{1,2})$/);if(!p)return null;const l=Number(p[1]),v=Number(p[2]),x=Number(p[3]);try{return q({jy:l,jm:v,jd:x})}catch{return null}}const Ce=1440*60*1e3;function wt(t){return Date.UTC(t.getFullYear(),t.getMonth(),t.getDate())}function ot(t,r){const s=wt(t),e=wt(r);return s===e?0:s<e?-1:1}function Mt(t,r){return ot(t,r)===0}function lt(t,r){const s=new Date(t);return s.setDate(s.getDate()+r),s}function yt(t,r,s){return!(r&&ot(t,r)<0||s&&ot(t,s)>0)}function Le(t,r,s){return r&&ot(t,r)<0?new Date(r):s&&ot(t,s)>0?new Date(s):new Date(t)}function Gt(t,r){const s=t.jy*12+(t.jm-1)+r,e=Math.floor(s/12),p=(s%12+12)%12+1;return{jy:e,jm:p}}function Bt(t,r){const s=q({jy:t,jm:r,jd:1}),e=Gt({jy:t,jm:r},1),p=q({jy:e.jy,jm:e.jm,jd:1});return Math.round((wt(p)-wt(s))/Ce)}function Ot(t,r){const s=Q(t),e=Gt({jy:s.jy,jm:s.jm},r),p=Bt(e.jy,e.jm),l=Math.min(s.jd,p);return q({jy:e.jy,jm:e.jm,jd:l})}function zt(t){const{jy:r,jm:s}=t,e=t.weekStartsOn??6,p=q({jy:r,jm:s,jd:1}),v=(p.getDay()-e+7)%7,x=lt(p,-v),L=[];for(let D=0;D<6;D++){const U=[];for(let M=0;M<7;M++){const tt=D*7+M,N=lt(x,tt),S=Q(N);U.push({gregorian:N,jalali:S,inCurrentMonth:S.jy===r&&S.jm===s})}L.push(U)}return L}const Ee=["bottom","top","left","right"];function It(t,r,s){return Math.min(Math.max(t,r),s)}const Ae=typeof window<"u"?b.useLayoutEffect:b.useEffect;function qt(t,r,s,e={}){const p=e.gutter??8,l=e.padding??8,v=e.strategy??"fixed",x=e.align??"end",L=e.placements?.join("|")??"",D=b.useMemo(()=>e.placements&&e.placements.length?e.placements:Ee,[L]),[U,M]=b.useState("bottom"),[tt,N]=b.useState(()=>({position:v,top:0,left:0})),S=b.useCallback(()=>{const P=r.current,W=s.current;if(!P||!W)return;const C=P.getBoundingClientRect(),F=W.getBoundingClientRect(),Y=window.innerWidth,rt=window.innerHeight,G=rt-C.bottom-l,H=C.top-l,et=C.left-l,B=Y-C.right-l;function d(i){return i==="bottom"?G:i==="top"?H:i==="left"?et:B}function c(i){return i==="bottom"||i==="top"?F.height+p<=d(i):F.width+p<=d(i)}let f=D.find(c)??D.reduce((i,n)=>d(n)>d(i)?n:i,D[0]),w=0,m=0;f==="bottom"||f==="top"?(w=f==="bottom"?C.bottom+p:C.top-p-F.height,x==="start"?m=C.left:x==="center"?m=C.left+(C.width-F.width)/2:m=C.right-F.width):(m=f==="right"?C.right+p:C.left-p-F.width,x==="start"?w=C.top:x==="center"?w=C.top+(C.height-F.height)/2:w=C.bottom-F.height),w=It(w,l,rt-l-F.height),m=It(m,l,Y-l-F.width),v==="absolute"&&(w+=window.scrollY,m+=window.scrollX),M(i=>i===f?i:f),N(i=>i.position===v&&i.top===w&&i.left===m?i:{position:v,top:w,left:m})},[x,r,p,l,s,v,D]);return Ae(()=>{if(!t)return;S();const P=window.requestAnimationFrame(S);return()=>window.cancelAnimationFrame(P)},[t,S]),b.useEffect(()=>{if(!t)return;let P=0;const W=()=>{P||(P=window.requestAnimationFrame(()=>{P=0,S()}))};return window.addEventListener("resize",W),document.addEventListener("scroll",W,!0),()=>{window.removeEventListener("resize",W),document.removeEventListener("scroll",W,!0),P&&window.cancelAnimationFrame(P)}},[t,S]),{style:tt,placement:U,update:S}}function I(...t){return t.filter(Boolean).join(" ")}function Ne(t){return Ut(t).formatted}function Pe(t){return Wt(t,{allowLooseSeparators:!0})}function Je(t,r,s){return yt(t,r,s)?t:null}function mt(t){const s=Q(t??new Date);return{jy:s.jy,jm:s.jm}}function Yt(){const t=new Date;return t.setHours(0,0,0,0),t}function Te(t){const{value:r,onChange:s,minDate:e,maxDate:p,disabled:l,placeholder:v,open:x,onOpenChange:L,mode:D="popover",popover:U,formatValue:M=Ne,parseValue:tt=Pe,weekdays:N,monthLabels:S,renderMonthLabel:P,prevIcon:W,nextIcon:C,className:F,classes:Y}=t,rt=b.useRef(null),G=b.useRef(null),H=b.useRef(null),et=b.useRef(null),B=b.useRef(!1),[d,c]=b.useState(!1),[f,w]=b.useState(!1),m=D==="inline"?!0:x??f,i=b.useCallback(a=>{L?.(a),D!=="inline"&&x===void 0&&w(a)},[D,L,x]);b.useEffect(()=>{c(!0)},[]);const[n,o]=b.useState(()=>mt(r)),[h,u]=b.useState(()=>r??Yt()),[$,y]=b.useState(()=>r?M(r):""),[_,k]=b.useState("days"),[J,E]=b.useState(()=>{const a=mt(r).jy;return a-a%12}),[R,K]=b.useState(()=>mt(r).jy);b.useEffect(()=>{if(B.current)return;y(r?M(r):""),o(mt(r)),u(r??Yt());const a=mt(r).jy;K(a),E(a-a%12)},[r,M]),b.useEffect(()=>{if(D!=="popover"||!m)return;const a=j=>{const g=rt.current;if(!g)return;const T=G.current;j.target instanceof Node&&!g.contains(j.target)&&!(T&&T.contains(j.target))&&i(!1)};return document.addEventListener("pointerdown",a),()=>document.removeEventListener("pointerdown",a)},[D,m,i]),b.useEffect(()=>{m&&et.current?.focus()},[m]);const z=U??{},it=z.portal??!0,{style:st}=qt(D==="popover"&&m&&it,H,G,{gutter:z.gutter,padding:z.padding,strategy:z.strategy,placements:z.placements,align:z.align??"end"}),V=b.useMemo(()=>P?P(n.jy,n.jm):S&&S.length===12?`${S[n.jm-1]??String(n.jm)} ${n.jy}`:`${n.jy} / ${n.jm}`,[S,P,n.jm,n.jy]),nt=b.useMemo(()=>N&&N.length===7?N:["1","2","3","4","5","6","7"],[N]),ut=b.useMemo(()=>zt({jy:n.jy,jm:n.jm}),[n.jm,n.jy]),Z=r??null,Lt=b.useMemo(()=>Yt(),[]);function Zt(a){const j=Q(a);o({jy:j.jy,jm:j.jm})}function bt(){if(l)return;i(!0);const a=Z??h??Lt;Zt(a),k("days");const j=Q(a).jy;K(j),E(j-j%12)}function xt(){i(!1),k("days"),H.current?.focus()}function Et(a){const j=a.trim();if(!j){s(null);return}const g=tt(j);if(!g){y(Z?M(Z):j);return}const T=Je(g,e,p);if(!T){y(Z?M(Z):j);return}s(T)}function Kt(a){if(!l){if(a.key==="ArrowDown"){a.preventDefault(),bt();return}if(a.key==="Escape"){m&&(a.preventDefault(),xt());return}if(a.key==="Enter"){a.preventDefault(),Et($);return}}}function Xt(a){if(m&&!l){if(a.key==="Escape"){a.preventDefault(),xt();return}if(_==="days"){if(a.key==="ArrowLeft"){a.preventDefault(),u(j=>lt(j,-1));return}if(a.key==="ArrowRight"){a.preventDefault(),u(j=>lt(j,1));return}if(a.key==="ArrowUp"){a.preventDefault(),u(j=>lt(j,-7));return}if(a.key==="ArrowDown"){a.preventDefault(),u(j=>lt(j,7));return}if(a.key==="PageUp"){a.preventDefault(),jt(-1);return}if(a.key==="PageDown"){a.preventDefault(),jt(1);return}if(a.key==="Enter"){if(a.preventDefault(),!yt(h,e,p))return;s(h),y(M(h)),xt()}}}}b.useEffect(()=>{if(!m)return;const a=Q(h);o(j=>j.jy===a.jy&&j.jm===a.jm?j:{jy:a.jy,jm:a.jm})},[h,m]);function Qt(a){l||yt(a.gregorian,e,p)&&(s(a.gregorian),y(M(a.gregorian)),u(a.gregorian),i(!1),H.current?.focus())}function te(a){return l?!0:!yt(a.gregorian,e,p)}function jt(a){const j=q({jy:n.jy,jm:n.jm,jd:1}),g=Ot(j,a),T=Q(g);o({jy:T.jy,jm:T.jm}),u(X=>{const ht=Q(X);return ht.jy===n.jy&&ht.jm===n.jm?Ot(X,a):g})}function ee(){jt(-1)}function ne(){jt(1)}function re(a){const j=q({jy:a,jm:1,jd:1}),g=q({jy:a+1,jm:1,jd:1});return{start:j,endExclusive:g}}function se(a,j){const g=q({jy:a,jm:j,jd:1}),T=j===12?{jy:a+1,jm:1}:{jy:a,jm:j+1},X=q({jy:T.jy,jm:T.jm,jd:1});return{start:g,endExclusive:X}}function At(a){return!(e&&ot(a.endExclusive,e)<=0||p&&ot(a.start,p)>0)}function ie(){if(_==="days"){k("years");const a=n.jy;K(a),E(a-a%12)}else k("days")}function ae(a){K(a),k("months")}function oe(a){const j={jy:R,jm:a};o(j),u(()=>{const g=Q(h).jd;try{return q({jy:j.jy,jm:j.jm,jd:g})}catch{return q({jy:j.jy,jm:j.jm,jd:1})}}),k("days")}const St=O.jsxs("div",{ref:et,tabIndex:-1,className:"dvx-pdp__calendar",onKeyDown:Xt,children:[O.jsxs("div",{className:I("dvx-pdp__header",Y?.header),children:[O.jsx("button",{type:"button",className:I("dvx-pdp__nav",Y?.navButton),onClick:_==="days"?ee:()=>E(a=>a-12),"aria-label":"Previous month",children:W??"‹"}),O.jsx("button",{type:"button",className:I("dvx-pdp__monthLabel",Y?.monthLabel),onClick:ie,"aria-label":"Choose month and year",children:_==="days"?V:R}),O.jsx("button",{type:"button",className:I("dvx-pdp__nav",Y?.navButton),onClick:_==="days"?ne:()=>E(a=>a+12),"aria-label":"Next month",children:C??"›"})]}),_==="days"?O.jsxs("div",{className:I("dvx-pdp__grid",Y?.grid),children:[O.jsx("div",{className:"dvx-pdp__weekdays","aria-hidden":"true",children:nt.map((a,j)=>O.jsx("div",{className:I("dvx-pdp__weekday",Y?.weekday),children:a},j))}),O.jsx("div",{className:"dvx-pdp__days",children:ut.map((a,j)=>O.jsx("div",{className:"dvx-pdp__row",children:a.map(g=>{const T=te(g),X=Z?Mt(g.gregorian,Z):!1,ht=Mt(g.gregorian,Lt),Nt=Mt(g.gregorian,h);return O.jsx("button",{type:"button",className:I("dvx-pdp__day",Y?.day,!g.inCurrentMonth&&I("dvx-pdp__day--outside",Y?.dayOutside),T&&I("dvx-pdp__day--disabled",Y?.dayDisabled),X&&I("dvx-pdp__day--selected",Y?.daySelected),ht&&I("dvx-pdp__day--today",Y?.dayToday),Nt&&"dvx-pdp__day--focused"),disabled:T,onClick:()=>Qt(g),onMouseEnter:()=>{g.inCurrentMonth&&u(g.gregorian)},"aria-pressed":X,children:g.jalali.jd},`${g.jalali.jy}-${g.jalali.jm}-${g.jalali.jd}`)})},j))})]}):_==="years"?O.jsx("div",{className:"dvx-pdp__panel",children:O.jsx("div",{className:"dvx-pdp__panelGrid",children:Array.from({length:12}).map((a,j)=>{const g=J+j,T=At(re(g)),X=g===n.jy;return O.jsx("button",{type:"button",className:I("dvx-pdp__cell",X&&"dvx-pdp__cell--active"),disabled:!T,onClick:()=>ae(g),children:g},g)})})}):O.jsx("div",{className:"dvx-pdp__panel",children:O.jsx("div",{className:"dvx-pdp__panelGrid",children:Array.from({length:12}).map((a,j)=>{const g=j+1,T=At(se(R,g)),X=R===n.jy&&g===n.jm,ht=S&&S.length===12?S[g-1]??String(g):String(g);return O.jsx("button",{type:"button",className:I("dvx-pdp__cell",X&&"dvx-pdp__cell--active"),disabled:!T,onClick:()=>oe(g),children:ht},g)})})})]});return O.jsxs("div",{ref:rt,className:I("dvx-pdp",D==="inline"&&"dvx-pdp--inline",F,Y?.root),dir:"rtl",children:[D==="inline"?null:O.jsxs("div",{className:"dvx-pdp__control",children:[O.jsx("input",{ref:H,className:I("dvx-pdp__input",Y?.input),disabled:l,placeholder:v,inputMode:"numeric",autoComplete:"off",value:$,onChange:a=>y(a.target.value),onClick:()=>{m||bt()},onFocus:()=>{B.current=!0},onBlur:()=>{B.current=!1,Et($)},onKeyDown:Kt,"aria-haspopup":"dialog","aria-expanded":m}),O.jsx("button",{type:"button",className:I("dvx-pdp__button",Y?.button),onClick:()=>m?i(!1):bt(),disabled:l,"aria-label":"Open calendar",children:O.jsx("svg",{viewBox:"0 0 24 24",width:"18",height:"18","aria-hidden":"true",children:O.jsx("path",{fill:"currentColor",d:"M7 2a1 1 0 0 1 1 1v1h8V3a1 1 0 1 1 2 0v1h1.5A2.5 2.5 0 0 1 22 6.5v13A2.5 2.5 0 0 1 19.5 22h-15A2.5 2.5 0 0 1 2 19.5v-13A2.5 2.5 0 0 1 4.5 4H6V3a1 1 0 0 1 1-1Zm0 6H4v11.5c0 .276.224.5.5.5h15c.276 0 .5-.224.5-.5V8H7Zm-2.5-2c-.276 0-.5.224-.5.5V6h16v.5c0-.276-.224-.5-.5-.5H4.5Z"})})})]}),D==="inline"?St:m?it&&d?ce.createPortal(O.jsx("div",{ref:G,className:I("dvx-pdp__popover","dvx-pdp__popover--portal",Y?.popover),dir:"rtl",style:{...st,right:"auto",bottom:"auto"},role:"dialog","aria-modal":"false",children:St}),document.body):O.jsx("div",{ref:G,className:I("dvx-pdp__popover",Y?.popover),role:"dialog","aria-modal":"false",children:St}):null]})}exports.PersianDatePicker=Te;exports.addDays=lt;exports.addJalaliMonths=Ot;exports.buildJalaliMonthGrid=zt;exports.clampToRange=Le;exports.compareDays=ot;exports.formatJalali=Vt;exports.fromJalaliParts=q;exports.getJalaliMonthLength=Bt;exports.isSameDay=Mt;exports.isWithinRange=yt;exports.parseJalaliText=Wt;exports.toGregorian=Oe;exports.toJalali=Ut;exports.toJalaliParts=Q;exports.usePopoverPosition=qt;