calkit 0.1.0 → 0.2.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.
@@ -1,4 +1,4 @@
1
- (function(C,B){typeof exports=="object"&&typeof module<"u"?B(exports):typeof define=="function"&&define.amd?define(["exports"],B):(C=typeof globalThis<"u"?globalThis:C||self,B(C.CalDatepicker={}))})(this,(function(C){"use strict";class B extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this._initialized=!1}static get styles(){return[]}connectedCallback(){this._initialized||(this._adoptStyles(),this._initialized=!0),this.render()}_adoptStyles(){const e=this.constructor.styles;if(e.length)if("adoptedStyleSheets"in this.shadowRoot)this.shadowRoot.adoptedStyleSheets=e.map(a=>{if(a instanceof CSSStyleSheet)return a;const t=new CSSStyleSheet;return t.replaceSync(a),t});else for(const a of e){const t=document.createElement("style");t.textContent=a instanceof CSSStyleSheet?"":a,this.shadowRoot.prepend(t)}}render(){}emit(e,a={}){this.dispatchEvent(new CustomEvent(e,{detail:a,bubbles:!0,composed:!0}))}showStatus(e,a,t={}){if(!this._store)return;const{autoDismiss:n,dismissible:r=!0}=t;clearTimeout(this._statusTimer),this._store.set({statusType:e,statusMessage:a,statusDismissible:r}),this.emit("cal:status",{type:e,message:a}),n&&n>0&&(this._statusTimer=setTimeout(()=>this.clearStatus(),n))}clearStatus(){this._store&&(clearTimeout(this._statusTimer),this._store.set({statusType:null,statusMessage:null,statusDismissible:!0}),this.emit("cal:status",{type:null,message:null}))}$(e){return this.shadowRoot.querySelector(e)}$$(e){return this.shadowRoot.querySelectorAll(e)}}function ae(s){let e={...s};const a=new Set;return{get(t){return e[t]},set(t){const n=e;e={...e,...t};let r=!1;for(const o of Object.keys(t))if(n[o]!==e[o]){r=!0;break}if(r)for(const o of a)o(e,n)},getState(){return e},subscribe(t){return a.add(t),()=>a.delete(t)}}}const K=["January","February","March","April","May","June","July","August","September","October","November","December"],ne=["Su","Mo","Tu","We","Th","Fr","Sa"];function se(s=0){const e=[];for(let a=0;a<7;a++)e.push(ne[(s+a)%7]);return e}function W(s,e){return new Date(s,e+1,0).getDate()}function re(s,e){return new Date(s,e,1).getDay()}function y(s){if(typeof s=="string")return s;const e=s instanceof Date?s:new Date(s.year,s.month,s.day),a=e.getFullYear(),t=String(e.getMonth()+1).padStart(2,"0"),n=String(e.getDate()).padStart(2,"0");return`${a}-${t}-${n}`}function w(s){if(!s)return null;if(s instanceof Date)return s;if(typeof s=="string"){const[e,a,t]=s.split("-").map(Number);return!e||!a||!t?null:new Date(e,a-1,t)}return null}function S(s,e){if(!s||!e)return!1;const a=w(s),t=w(e);return!a||!t?!1:a.getFullYear()===t.getFullYear()&&a.getMonth()===t.getMonth()&&a.getDate()===t.getDate()}function oe(s,e,a){if(!s||!e||!a)return!1;const t=w(s),n=w(e),r=w(a);if(!t||!n||!r)return!1;const o=t.getTime(),l=Math.min(n.getTime(),r.getTime()),i=Math.max(n.getTime(),r.getTime());return o>=l&&o<=i}function G(){return y(new Date)}function z(s,e,a){const t=new Date(s,e+a,1);return{year:t.getFullYear(),month:t.getMonth()}}function le(s,e,a=0){const t=W(s,e),r=(re(s,e)-a+7)%7,o=[],l=G(),i=z(s,e,-1),g=W(i.year,i.month);for(let d=r-1;d>=0;d--){const b=g-d,p=y({year:i.year,month:i.month,day:b});o.push({year:i.year,month:i.month,day:b,dateString:p,isCurrentMonth:!1,isToday:p===l})}for(let d=1;d<=t;d++){const b=y({year:s,month:e,day:d});o.push({year:s,month:e,day:d,dateString:b,isCurrentMonth:!0,isToday:b===l})}const h=z(s,e,1);let u=1;for(;o.length<42;){const d=y({year:h.year,month:h.month,day:u});o.push({year:h.year,month:h.month,day:u,dateString:d,isCurrentMonth:!1,isToday:d===l}),u++}return o}const ie=`
1
+ (function(A,B){typeof exports=="object"&&typeof module<"u"?B(exports):typeof define=="function"&&define.amd?define(["exports"],B):(A=typeof globalThis<"u"?globalThis:A||self,B(A.CalDatepicker={}))})(this,(function(A){"use strict";class B extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this._initialized=!1}static get styles(){return[]}connectedCallback(){this._initialized||(this._adoptStyles(),this._initialized=!0),this.render()}_adoptStyles(){const e=this.constructor.styles;if(e.length)if("adoptedStyleSheets"in this.shadowRoot)this.shadowRoot.adoptedStyleSheets=e.map(a=>{if(a instanceof CSSStyleSheet)return a;const t=new CSSStyleSheet;return t.replaceSync(a),t});else for(const a of e){const t=document.createElement("style");t.textContent=a instanceof CSSStyleSheet?"":a,this.shadowRoot.prepend(t)}}render(){}clear(){}emit(e,a={}){this.dispatchEvent(new CustomEvent(e,{detail:a,bubbles:!0,composed:!0}))}showStatus(e,a,t={}){if(!this._store)return;const{autoDismiss:n,dismissible:r=!0}=t;clearTimeout(this._statusTimer),this._store.set({statusType:e,statusMessage:a,statusDismissible:r}),this.emit("cal:status",{type:e,message:a}),n&&n>0&&(this._statusTimer=setTimeout(()=>this.clearStatus(),n))}clearStatus(){this._store&&(clearTimeout(this._statusTimer),this._store.set({statusType:null,statusMessage:null,statusDismissible:!0}),this.emit("cal:status",{type:null,message:null}))}$(e){return this.shadowRoot.querySelector(e)}$$(e){return this.shadowRoot.querySelectorAll(e)}}function le(s){let e={...s};const a=new Set;return{get(t){return e[t]},set(t){const n=e;e={...e,...t};let r=!1;for(const o of Object.keys(t))if(n[o]!==e[o]){r=!0;break}if(r)for(const o of a)o(e,n)},getState(){return e},subscribe(t){return a.add(t),()=>a.delete(t)}}}const X=["January","February","March","April","May","June","July","August","September","October","November","December"],ie=["Su","Mo","Tu","We","Th","Fr","Sa"];function ce(s){if(!s)return X;try{const e=new Intl.DateTimeFormat(s,{month:"long"});return Array.from({length:12},(a,t)=>{const n=e.format(new Date(2024,t,1));return n.charAt(0).toUpperCase()+n.slice(1)})}catch{return X}}function q(s){if(!s)return["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];try{const e=new Intl.DateTimeFormat(s,{month:"short"});return Array.from({length:12},(a,t)=>{const n=e.format(new Date(2024,t,1));return n.charAt(0).toUpperCase()+n.slice(1)})}catch{return["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}}function de(s=0,e){if(e)try{const t=new Intl.DateTimeFormat(e,{weekday:"short"}),n=[];for(let r=0;r<7;r++){const o=new Date(2024,0,7+(s+r)%7),l=t.format(o);n.push(l.charAt(0).toUpperCase()+l.slice(1))}return n}catch{}const a=[];for(let t=0;t<7;t++)a.push(ie[(s+t)%7]);return a}function Q(s,e){return new Date(s,e+1,0).getDate()}function ge(s,e){return new Date(s,e,1).getDay()}function m(s){if(typeof s=="string")return s;const e=s instanceof Date?s:new Date(s.year,s.month,s.day),a=e.getFullYear(),t=String(e.getMonth()+1).padStart(2,"0"),n=String(e.getDate()).padStart(2,"0");return`${a}-${t}-${n}`}function D(s){if(!s)return null;if(s instanceof Date)return s;if(typeof s=="string"){const[e,a,t]=s.split("-").map(Number);return!e||!a||!t?null:new Date(e,a-1,t)}return null}function E(s,e){if(!s||!e)return!1;const a=D(s),t=D(e);return!a||!t?!1:a.getFullYear()===t.getFullYear()&&a.getMonth()===t.getMonth()&&a.getDate()===t.getDate()}function ue(s,e,a){if(!s||!e||!a)return!1;const t=D(s),n=D(e),r=D(a);if(!t||!n||!r)return!1;const o=t.getTime(),l=Math.min(n.getTime(),r.getTime()),i=Math.max(n.getTime(),r.getTime());return o>=l&&o<=i}function J(){return m(new Date)}function z(s,e,a){const t=new Date(s,e+a,1);return{year:t.getFullYear(),month:t.getMonth()}}function he(s,e,a=0){const t=Q(s,e),r=(ge(s,e)-a+7)%7,o=[],l=J(),i=z(s,e,-1),h=Q(i.year,i.month);for(let u=r-1;u>=0;u--){const p=h-u,b=m({year:i.year,month:i.month,day:p});o.push({year:i.year,month:i.month,day:p,dateString:b,isCurrentMonth:!1,isToday:b===l})}for(let u=1;u<=t;u++){const p=m({year:s,month:e,day:u});o.push({year:s,month:e,day:u,dateString:p,isCurrentMonth:!0,isToday:p===l})}const d=z(s,e,1);let g=1;for(;o.length<42;){const u=m({year:d.year,month:d.month,day:g});o.push({year:d.year,month:d.month,day:g,dateString:u,isCurrentMonth:!1,isToday:u===l}),g++}return o}const pe=`
2
2
  :host {
3
3
  /* Light theme (default) */
4
4
  --cal-bg: 0 0% 100%;
@@ -166,7 +166,7 @@
166
166
  --cal-status-success-border: 152 40% 28%;
167
167
  }
168
168
  }
169
- `,ce=`
169
+ `,be=`
170
170
  :host {
171
171
  display: inline-block;
172
172
  font-family: inherit;
@@ -207,7 +207,7 @@
207
207
  [hidden] {
208
208
  display: none !important;
209
209
  }
210
- `,de=`
210
+ `,fe=`
211
211
  @keyframes cal-fade-in {
212
212
  from { opacity: 0; }
213
213
  to { opacity: 1; }
@@ -271,7 +271,7 @@
271
271
  .cal-skeleton--rect {
272
272
  border-radius: var(--cal-radius-sm);
273
273
  }
274
- `,X={blue:{bg:"var(--cal-booking-blue-bg)",fg:"var(--cal-booking-blue-fg)",hover:"var(--cal-booking-blue-hover)"},green:{bg:"var(--cal-booking-green-bg)",fg:"var(--cal-booking-green-fg)",hover:"var(--cal-booking-green-hover)"},red:{bg:"var(--cal-booking-red-bg)",fg:"var(--cal-booking-red-fg)",hover:"var(--cal-booking-red-hover)"},orange:{bg:"var(--cal-booking-orange-bg)",fg:"var(--cal-booking-orange-fg)",hover:"var(--cal-booking-orange-hover)"},gray:{bg:"var(--cal-booking-gray-bg)",fg:"var(--cal-booking-gray-fg)",hover:"var(--cal-booking-gray-hover)"}},A="blue";function O(s){return X[s]||X[A]}function ge(s,e=[],a={},t=null){const n=e.find(p=>p.end===s),r=e.find(p=>p.start===s),o=e.find(p=>p.start<s&&p.end>s);let l="available",i=null,g=!1,h=null,u=null,d=null;n&&r?(l="half-day",g=!0,h=O(n.color||A),u=O(r.color||A)):o?(l="booked",d=O(o.color||A)):r&&!n?(l="checkin-only",u=O(r.color||A)):n&&!r&&(l="checkout-only",h=O(n.color||A));const b=a[s];if(b&&(b.status&&(l=b.status),b.label!==void 0&&(i=b.label)),t){const p=t(s);p&&(p.status&&(l=p.status),p.label!==void 0&&(i=p.label))}return{status:l,label:i,checkoutBooking:n,checkinBooking:r,halfDay:g,colorOut:h,colorIn:u,colorFull:d}}function ue(s,e,a=[]){if(!s||!e)return!0;const t=s<e?s:e,n=s<e?e:s;for(const r of a)if(t<r.end&&n>r.start)return!1;return!0}function he(s,e,a=[]){return!s||!e?!1:!ue(s,e,a)}function pe(s){const{year:e,month:a,firstDay:t=0,selectedDates:n=[],rangeStart:r,rangeEnd:o,hoverDate:l,minDate:i,maxDate:g,disabledDates:h=[],mode:u="single",focusedDate:d,onSelect:b,onHover:p,bookings:T=null,dayData:k=null,labelFormula:D=null,showLabelsOnHover:Ye=!1}=s,E=T!==null,Y=document.createElement("div");Y.setAttribute("role","grid"),Y.classList.add("cal-grid");const P=document.createElement("div");P.setAttribute("role","row"),P.classList.add("cal-weekdays");for(const _ of se(t)){const M=document.createElement("div");M.setAttribute("role","columnheader"),M.setAttribute("aria-label",_),M.classList.add("cal-weekday"),M.textContent=_,P.appendChild(M)}Y.appendChild(P);const Be=le(e,a,t),J=u==="range"&&r&&!o&&l||E&&r&&!o&&l?l:o,ze=E?he(r,l,T):!1;let $;return Be.forEach((_,M)=>{M%7===0&&($=document.createElement("div"),$.setAttribute("role","row"),$.classList.add("cal-row"),Y.appendChild($));const c=document.createElement("button");c.setAttribute("role","gridcell"),c.setAttribute("part","day"),c.classList.add("cal-day");const f=_.dateString;c.dataset.date=f;const Oe=new Date(_.year,_.month,_.day);c.setAttribute("aria-label",Oe.toLocaleDateString("en-US",{weekday:"long",year:"numeric",month:"long",day:"numeric"})),_.isCurrentMonth||c.classList.add("cal-day--outside"),_.isToday&&c.classList.add("cal-day--today");let m=null,F=!1;if(E){m=ge(f,T,k||{},D);const{status:v,label:x,halfDay:R,colorOut:H,colorIn:N,colorFull:j}=m;if(v==="booked"&&(c.classList.add("cal-day--booked"),j&&(c.style.setProperty("--booking-bg",`hsl(${j.bg})`),c.style.setProperty("--booking-fg",`hsl(${j.fg})`),c.style.setProperty("--booking-hover",`hsl(${j.hover})`)),F=!0),v==="blocked"&&(c.classList.add("cal-day--blocked"),F=!0),R&&(c.classList.add("cal-day--half-day"),H&&c.style.setProperty("--half-day-color-out",`hsl(${H.bg})`),N&&c.style.setProperty("--half-day-color-in",`hsl(${N.bg})`),F=!0),v==="checkout-only"&&(c.classList.add("cal-day--checkout-only"),H&&c.style.setProperty("--half-day-color-out",`hsl(${H.bg})`)),v==="checkin-only"&&(c.classList.add("cal-day--checkin-only"),N&&c.style.setProperty("--half-day-color-in",`hsl(${N.bg})`)),Ye){let L=null;if(R&&m.checkoutBooking&&m.checkinBooking)L=`${m.checkoutBooking.label||""} / ${m.checkinBooking.label||""}`;else if(v==="booked"){const I=T.find(te=>te.start<=f&&te.end>f);I&&(L=I.label)}else v==="checkout-only"&&m.checkoutBooking?L=m.checkoutBooking.label:v==="checkin-only"&&m.checkinBooking&&(L=m.checkinBooking.label);L&&c.setAttribute("data-booking-label",L)}if(ze&&r&&!o&&l){const L=r<l?r:l,I=r<l?l:r;f>=L&&f<=I&&c.classList.add("cal-day--invalid-range")}}if(E?r&&o&&(S(f,r)||S(f,o))?(c.classList.add("cal-day--selected"),c.setAttribute("aria-selected","true")):c.setAttribute("aria-selected","false"):n.some(x=>S(x,f))?(c.classList.add("cal-day--selected"),c.setAttribute("aria-selected","true")):c.setAttribute("aria-selected","false"),(u==="range"||E)&&r&&J){const v=S(f,r),x=S(f,J),R=oe(f,r,J);v&&c.classList.add("cal-day--range-start"),x&&c.classList.add("cal-day--range-end"),R&&!v&&!x&&c.classList.add("cal-day--in-range")}const ee=be(f,i,g,h)||F;if(ee&&(c.classList.add("cal-day--disabled"),c.disabled=!0,c.setAttribute("aria-disabled","true")),d&&S(f,d)?c.setAttribute("tabindex","0"):c.setAttribute("tabindex","-1"),E&&m&&m.label!=null){c.classList.add("cal-day--with-label");const v=document.createElement("span");v.classList.add("cal-day__number"),v.textContent=_.day,c.appendChild(v);const x=document.createElement("span");x.classList.add("cal-day__label"),x.textContent=m.label,c.appendChild(x)}else c.textContent=_.day;ee?E&&c.addEventListener("mouseenter",()=>p==null?void 0:p(f)):(c.addEventListener("click",()=>b==null?void 0:b(f)),c.addEventListener("mouseenter",()=>p==null?void 0:p(f))),$.appendChild(c)}),Y.addEventListener("mouseleave",()=>p==null?void 0:p(null)),Y}function be(s,e,a,t){return!!(t.includes(s)||e&&s<e||a&&s>a)}const fe=`
274
+ `,Z={blue:{bg:"var(--cal-booking-blue-bg)",fg:"var(--cal-booking-blue-fg)",hover:"var(--cal-booking-blue-hover)"},green:{bg:"var(--cal-booking-green-bg)",fg:"var(--cal-booking-green-fg)",hover:"var(--cal-booking-green-hover)"},red:{bg:"var(--cal-booking-red-bg)",fg:"var(--cal-booking-red-fg)",hover:"var(--cal-booking-red-hover)"},orange:{bg:"var(--cal-booking-orange-bg)",fg:"var(--cal-booking-orange-fg)",hover:"var(--cal-booking-orange-hover)"},gray:{bg:"var(--cal-booking-gray-bg)",fg:"var(--cal-booking-gray-fg)",hover:"var(--cal-booking-gray-hover)"}},T="blue";function P(s,e){return e&&e[s]?e[s]:Z[s]||Z[T]}function ve(s,e=[],a={},t=null,n=null){const r=e.find(f=>f.end===s),o=e.find(f=>f.start===s),l=e.find(f=>f.start<s&&f.end>s);let i="available",h=null,d=!1,g=null,u=null,p=null;r&&o?(i="half-day",d=!0,g=P(r.color||T,n),u=P(o.color||T,n)):l?(i="booked",p=P(l.color||T,n)):o&&!r?(i="checkin-only",u=P(o.color||T,n)):r&&!o&&(i="checkout-only",g=P(r.color||T,n));const b=a[s];if(b&&(b.status&&(i=b.status),b.label!==void 0&&(h=b.label)),t){const f=t(s);f&&(f.status&&(i=f.status),f.label!==void 0&&(h=f.label))}return{status:i,label:h,checkoutBooking:r,checkinBooking:o,halfDay:d,colorOut:g,colorIn:u,colorFull:p}}function ye(s,e,a=[]){if(!s||!e)return!0;const t=s<e?s:e,n=s<e?e:s;for(const r of a)if(t<r.end&&n>r.start)return!1;return!0}function me(s,e,a=[]){return!s||!e?!1:!ye(s,e,a)}function ke(s){const{year:e,month:a,firstDay:t=0,selectedDates:n=[],rangeStart:r,rangeEnd:o,hoverDate:l,minDate:i,maxDate:h,disabledDates:d=[],mode:g="single",focusedDate:u,onSelect:p,onHover:b,bookings:f=null,dayData:G=null,labelFormula:U=null,showLabelsOnHover:_=!1,locale:L,customColors:$e=null}=s,M=f!==null,Y=document.createElement("div");Y.setAttribute("role","grid"),Y.classList.add("cal-grid");const F=document.createElement("div");F.setAttribute("role","row"),F.classList.add("cal-weekdays");for(const w of de(t,L)){const C=document.createElement("div");C.setAttribute("role","columnheader"),C.setAttribute("aria-label",w),C.classList.add("cal-weekday"),C.textContent=w,F.appendChild(C)}Y.appendChild(F);const Fe=he(e,a,t),W=g==="range"&&r&&!o&&l||M&&r&&!o&&l?l:o,Re=M?me(r,l,f):!1;let O;return Fe.forEach((w,C)=>{C%7===0&&(O=document.createElement("div"),O.setAttribute("role","row"),O.classList.add("cal-row"),Y.appendChild(O));const c=document.createElement("button");c.setAttribute("role","gridcell"),c.setAttribute("part","day"),c.classList.add("cal-day");const v=w.dateString;c.dataset.date=v;const Ne=new Date(w.year,w.month,w.day);c.setAttribute("aria-label",Ne.toLocaleDateString("en-US",{weekday:"long",year:"numeric",month:"long",day:"numeric"})),w.isCurrentMonth||c.classList.add("cal-day--outside"),w.isToday&&c.classList.add("cal-day--today");let k=null,R=!1;if(M){k=ve(v,f,G||{},U,$e);const{status:y,label:x,halfDay:N,colorOut:I,colorIn:H,colorFull:j}=k;if(y==="booked"&&(c.classList.add("cal-day--booked"),j&&(c.style.setProperty("--booking-bg",`hsl(${j.bg})`),c.style.setProperty("--booking-fg",`hsl(${j.fg})`),c.style.setProperty("--booking-hover",`hsl(${j.hover})`)),R=!0),y==="blocked"&&(c.classList.add("cal-day--blocked"),R=!0),N&&(c.classList.add("cal-day--half-day"),I&&c.style.setProperty("--half-day-color-out",`hsl(${I.bg})`),H&&c.style.setProperty("--half-day-color-in",`hsl(${H.bg})`),R=!0),y==="checkout-only"&&(c.classList.add("cal-day--checkout-only"),I&&c.style.setProperty("--half-day-color-out",`hsl(${I.bg})`)),y==="checkin-only"&&(c.classList.add("cal-day--checkin-only"),H&&c.style.setProperty("--half-day-color-in",`hsl(${H.bg})`)),_){let S=null;if(N&&k.checkoutBooking&&k.checkinBooking)S=`${k.checkoutBooking.label||""} / ${k.checkinBooking.label||""}`;else if(y==="booked"){const K=f.find(oe=>oe.start<=v&&oe.end>v);K&&(S=K.label)}else y==="checkout-only"&&k.checkoutBooking?S=k.checkoutBooking.label:y==="checkin-only"&&k.checkinBooking&&(S=k.checkinBooking.label);S&&c.setAttribute("data-booking-label",S)}if(Re&&r&&!o&&l){const S=r<l?r:l,K=r<l?l:r;v>=S&&v<=K&&c.classList.add("cal-day--invalid-range")}}if(M?r&&o&&(E(v,r)||E(v,o))?(c.classList.add("cal-day--selected"),c.setAttribute("aria-selected","true")):c.setAttribute("aria-selected","false"):n.some(x=>E(x,v))?(c.classList.add("cal-day--selected"),c.setAttribute("aria-selected","true")):c.setAttribute("aria-selected","false"),(g==="range"||M)&&r&&W){const y=E(v,r),x=E(v,W),N=ue(v,r,W);y&&c.classList.add("cal-day--range-start"),x&&c.classList.add("cal-day--range-end"),N&&!y&&!x&&c.classList.add("cal-day--in-range")}const re=_e(v,i,h,d)||R;if(re&&(c.classList.add("cal-day--disabled"),c.disabled=!0,c.setAttribute("aria-disabled","true")),u&&E(v,u)?c.setAttribute("tabindex","0"):c.setAttribute("tabindex","-1"),M&&k&&k.label!=null){c.classList.add("cal-day--with-label");const y=document.createElement("span");y.classList.add("cal-day__number"),y.textContent=w.day,c.appendChild(y);const x=document.createElement("span");x.classList.add("cal-day__label"),x.textContent=k.label,c.appendChild(x)}else c.textContent=w.day;re?M&&c.addEventListener("mouseenter",()=>b==null?void 0:b(v)):(c.addEventListener("click",()=>p==null?void 0:p(v)),c.addEventListener("mouseenter",()=>b==null?void 0:b(v))),O.appendChild(c)}),Y.addEventListener("mouseleave",()=>b==null?void 0:b(null)),Y}function _e(s,e,a,t){return!!(t.includes(s)||e&&s<e||a&&s>a)}const we=`
275
275
  .cal-grid {
276
276
  display: flex;
277
277
  flex-direction: column;
@@ -529,7 +529,7 @@
529
529
  pointer-events: none;
530
530
  z-index: 10;
531
531
  }
532
- `,q='<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M10 12L6 8l4-4"/></svg>',U='<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M6 4l4 4-4 4"/></svg>';function Q({year:s,month:e,onPrev:a,onNext:t,onTitleClick:n}){const r=document.createElement("div");r.classList.add("cal-nav");const o=document.createElement("button");o.classList.add("cal-nav__btn","cal-nav__btn--prev"),o.innerHTML=q,o.setAttribute("aria-label","Previous month"),o.addEventListener("click",a);const l=n?"button":"div",i=document.createElement(l);i.classList.add("cal-nav__title"),n&&(i.classList.add("cal-nav__title--interactive"),i.setAttribute("aria-label",`Select month and year, currently ${K[e]} ${s}`),i.addEventListener("click",n)),i.setAttribute("aria-live","polite"),i.textContent=`${K[e]} ${s}`;const g=document.createElement("button");return g.classList.add("cal-nav__btn","cal-nav__btn--next"),g.innerHTML=U,g.setAttribute("aria-label","Next month"),g.addEventListener("click",t),r.appendChild(o),r.appendChild(i),r.appendChild(g),r}const ve=`
532
+ `,V='<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M10 12L6 8l4-4"/></svg>',ee='<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M6 4l4 4-4 4"/></svg>';function te({year:s,month:e,onPrev:a,onNext:t,onTitleClick:n,locale:r}){const o=document.createElement("div");o.classList.add("cal-nav");const l=document.createElement("button");l.classList.add("cal-nav__btn","cal-nav__btn--prev"),l.innerHTML=V,l.setAttribute("aria-label","Previous month"),l.addEventListener("click",a);const i=ce(r),h=n?"button":"div",d=document.createElement(h);d.classList.add("cal-nav__title"),n&&(d.classList.add("cal-nav__title--interactive"),d.setAttribute("aria-label",`Select month and year, currently ${i[e]} ${s}`),d.addEventListener("click",n)),d.setAttribute("aria-live","polite"),d.textContent=`${i[e]} ${s}`;const g=document.createElement("button");return g.classList.add("cal-nav__btn","cal-nav__btn--next"),g.innerHTML=ee,g.setAttribute("aria-label","Next month"),g.addEventListener("click",t),o.appendChild(l),o.appendChild(d),o.appendChild(g),o}const xe=`
533
533
  .cal-nav {
534
534
  display: flex;
535
535
  align-items: center;
@@ -570,7 +570,7 @@
570
570
  .cal-nav__title--interactive:hover {
571
571
  background: hsl(var(--cal-hover));
572
572
  }
573
- `,ye=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function me({pickerYear:s,viewMonth:e,viewYear:a,onMonthSelect:t,onYearPrev:n,onYearNext:r,onClose:o}){const l=document.createElement("div");l.classList.add("cal-myp","cal-animate-fade");const i=document.createElement("div");i.classList.add("cal-myp__year-nav");const g=document.createElement("button");g.classList.add("cal-nav__btn"),g.innerHTML=q,g.setAttribute("aria-label","Previous year"),g.addEventListener("click",n);const h=document.createElement("div");h.classList.add("cal-myp__year-label"),h.textContent=s;const u=document.createElement("button");u.classList.add("cal-nav__btn"),u.innerHTML=U,u.setAttribute("aria-label","Next year"),u.addEventListener("click",r),i.appendChild(g),i.appendChild(h),i.appendChild(u),l.appendChild(i);const d=document.createElement("div");d.classList.add("cal-myp__grid");const b=new Date,p=b.getMonth(),T=b.getFullYear();for(let k=0;k<12;k++){const D=document.createElement("button");D.classList.add("cal-myp__cell"),D.textContent=ye[k],k===e&&s===a&&D.classList.add("cal-myp__cell--active"),k===p&&s===T&&D.classList.add("cal-myp__cell--today"),D.addEventListener("click",()=>t(k,s)),d.appendChild(D)}return l.appendChild(d),l.addEventListener("keydown",k=>{k.key==="Escape"&&(k.stopPropagation(),o())}),l}const ke=`
573
+ `;function De({pickerYear:s,viewMonth:e,viewYear:a,onMonthSelect:t,onYearPrev:n,onYearNext:r,onClose:o,locale:l}){const i=document.createElement("div");i.classList.add("cal-myp","cal-animate-fade");const h=document.createElement("div");h.classList.add("cal-myp__year-nav");const d=document.createElement("button");d.classList.add("cal-nav__btn"),d.innerHTML=V,d.setAttribute("aria-label","Previous year"),d.addEventListener("click",n);const g=document.createElement("div");g.classList.add("cal-myp__year-label"),g.textContent=s;const u=document.createElement("button");u.classList.add("cal-nav__btn"),u.innerHTML=ee,u.setAttribute("aria-label","Next year"),u.addEventListener("click",r),h.appendChild(d),h.appendChild(g),h.appendChild(u),i.appendChild(h);const p=document.createElement("div");p.classList.add("cal-myp__grid");const b=q(l),f=new Date,G=f.getMonth(),U=f.getFullYear();for(let _=0;_<12;_++){const L=document.createElement("button");L.classList.add("cal-myp__cell"),L.textContent=b[_],_===e&&s===a&&L.classList.add("cal-myp__cell--active"),_===G&&s===U&&L.classList.add("cal-myp__cell--today"),L.addEventListener("click",()=>t(_,s)),p.appendChild(L)}return i.appendChild(p),i.addEventListener("keydown",_=>{_.key==="Escape"&&(_.stopPropagation(),o())}),i}const Le=`
574
574
  .cal-myp {
575
575
  width: calc(7 * var(--cal-cell-size));
576
576
  }
@@ -628,7 +628,7 @@
628
628
  border: 1px solid hsl(var(--cal-border));
629
629
  font-weight: 600;
630
630
  }
631
- `;function _e(){return[{key:"today",label:"Today",resolve(){const s=G();return{start:s,end:s}}},{key:"this-week",label:"This Week",resolve(){const s=new Date,e=s.getDay(),a=new Date(s);a.setDate(s.getDate()-e);const t=new Date(a);return t.setDate(a.getDate()+6),{start:y(a),end:y(t)}}},{key:"next-7",label:"Next 7 Days",resolve(){const s=new Date,e=new Date;return e.setDate(s.getDate()+6),{start:y(s),end:y(e)}}},{key:"next-30",label:"Next 30 Days",resolve(){const s=new Date,e=new Date;return e.setDate(s.getDate()+29),{start:y(s),end:y(e)}}}]}function xe({presetKeys:s,onSelect:e}){const a=document.createElement("div");a.classList.add("cal-presets");const t=_e(),n=s.map(r=>t.find(o=>o.key===r)).filter(Boolean);for(const r of n){const o=document.createElement("button");o.classList.add("cal-preset"),o.textContent=r.label,o.addEventListener("click",()=>{e==null||e(r.resolve())}),a.appendChild(o)}return a}const we=`
631
+ `,ae={today:"Today","this-week":"This Week","next-7":"Next 7 Days","next-30":"Next 30 Days"};function $(s,e){if(!e)return ae[s]||s;try{if(s==="today"){const n=new Intl.RelativeTimeFormat(e,{numeric:"auto"}).formatToParts(0,"day").map(r=>r.value).join("");return n.charAt(0).toUpperCase()+n.slice(1)}}catch{}return ae[s]||s}function Se(s){return[{key:"today",label:$("today",s),resolve(){const e=J();return{start:e,end:e}}},{key:"this-week",label:$("this-week",s),resolve(){const e=new Date,a=e.getDay(),t=new Date(e);t.setDate(e.getDate()-a);const n=new Date(t);return n.setDate(t.getDate()+6),{start:m(t),end:m(n)}}},{key:"next-7",label:$("next-7",s),resolve(){const e=new Date,a=new Date;return a.setDate(e.getDate()+6),{start:m(e),end:m(a)}}},{key:"next-30",label:$("next-30",s),resolve(){const e=new Date,a=new Date;return a.setDate(e.getDate()+29),{start:m(e),end:m(a)}}}]}function Ee({presetKeys:s,onSelect:e,locale:a}){const t=document.createElement("div");t.classList.add("cal-presets");const n=Se(a),r=s.map(o=>n.find(l=>l.key===o)).filter(Boolean);for(const o of r){const l=document.createElement("button");l.classList.add("cal-preset"),l.textContent=o.label,l.addEventListener("click",()=>{e==null||e(o.resolve())}),t.appendChild(l)}return t}const Me=`
632
632
  .cal-presets {
633
633
  display: flex;
634
634
  flex-wrap: wrap;
@@ -654,7 +654,7 @@
654
654
  .cal-preset:hover {
655
655
  background: hsl(var(--cal-hover));
656
656
  }
657
- `;function De({trigger:s,content:e,onClose:a}){const t=document.createElement("div");t.classList.add("cal-popover"),t.setAttribute("role","dialog"),t.setAttribute("aria-modal","false"),t.style.display="none",t.appendChild(e);let n=!1;function r(){t.classList.remove("cal-popover--above");const u=s.getBoundingClientRect(),d=t.offsetHeight,b=window.innerHeight-u.bottom,p=u.top;b<d+8&&p>b?(t.classList.add("cal-popover--above"),t.style.top="auto",t.style.bottom="100%",t.style.marginBottom="4px",t.style.marginTop="0"):(t.style.top="100%",t.style.bottom="auto",t.style.marginTop="4px",t.style.marginBottom="0")}function o(){n||(n=!0,t.style.display="",t.classList.add("cal-animate-slide-up"),requestAnimationFrame(()=>r()),document.addEventListener("click",i,!0),document.addEventListener("keydown",g,!0))}function l(){n&&(n=!1,t.style.display="none",t.classList.remove("cal-animate-slide-up"),document.removeEventListener("click",i,!0),document.removeEventListener("keydown",g,!0),a==null||a())}function i(u){var b;const d=(b=s.getRootNode())==null?void 0:b.host;d&&!d.contains(u.target)&&u.target!==d&&l()}function g(u){u.key==="Escape"&&(u.stopPropagation(),l())}function h(){n&&(n=!1,t.style.display="none",t.classList.remove("cal-animate-slide-up")),document.removeEventListener("click",i,!0),document.removeEventListener("keydown",g,!0)}return{panel:t,open:o,close:l,destroy:h,get isOpen(){return n}}}const Le=`
657
+ `;function Ce({trigger:s,content:e,onClose:a}){const t=document.createElement("div");t.classList.add("cal-popover"),t.setAttribute("role","dialog"),t.setAttribute("aria-modal","false"),t.style.display="none",t.appendChild(e);let n=!1;function r(){t.classList.remove("cal-popover--above");const g=s.getBoundingClientRect(),u=t.offsetHeight,p=window.innerHeight-g.bottom,b=g.top;p<u+8&&b>p?(t.classList.add("cal-popover--above"),t.style.top="auto",t.style.bottom="100%",t.style.marginBottom="4px",t.style.marginTop="0"):(t.style.top="100%",t.style.bottom="auto",t.style.marginTop="4px",t.style.marginBottom="0")}function o(){n||(n=!0,t.style.display="",t.classList.add("cal-animate-slide-up"),requestAnimationFrame(()=>r()),document.addEventListener("click",i,!0),document.addEventListener("keydown",h,!0))}function l(){n&&(n=!1,t.style.display="none",t.classList.remove("cal-animate-slide-up"),document.removeEventListener("click",i,!0),document.removeEventListener("keydown",h,!0),a==null||a())}function i(g){var p;const u=(p=s.getRootNode())==null?void 0:p.host;u&&!u.contains(g.target)&&g.target!==u&&l()}function h(g){g.key==="Escape"&&(g.stopPropagation(),l())}function d(){n&&(n=!1,t.style.display="none",t.classList.remove("cal-animate-slide-up")),document.removeEventListener("click",i,!0),document.removeEventListener("keydown",h,!0)}return{panel:t,open:o,close:l,destroy:d,get isOpen(){return n}}}const Ae=`
658
658
  .cal-popover-wrapper {
659
659
  position: relative;
660
660
  display: inline-block;
@@ -699,7 +699,7 @@
699
699
  display: flex;
700
700
  color: hsl(var(--cal-fg-muted));
701
701
  }
702
- `;function Se({rows:s=5}={}){const e=document.createElement("div");e.setAttribute("role","status"),e.setAttribute("aria-label","Loading..."),e.classList.add("cal-skeleton-calendar-grid");for(let t=0;t<7;t++){const n=document.createElement("div");n.classList.add("cal-skeleton","cal-skeleton-calendar-grid__header"),e.appendChild(n)}const a=7*s;for(let t=0;t<a;t++){const n=document.createElement("div");n.classList.add("cal-skeleton","cal-skeleton-calendar-grid__day"),e.appendChild(n)}return e}const Ee=`
702
+ `;function Te({rows:s=5}={}){const e=document.createElement("div");e.setAttribute("role","status"),e.setAttribute("aria-label","Loading..."),e.classList.add("cal-skeleton-calendar-grid");for(let t=0;t<7;t++){const n=document.createElement("div");n.classList.add("cal-skeleton","cal-skeleton-calendar-grid__header"),e.appendChild(n)}const a=7*s;for(let t=0;t<a;t++){const n=document.createElement("div");n.classList.add("cal-skeleton","cal-skeleton-calendar-grid__day"),e.appendChild(n)}return e}const Ye=`
703
703
  .cal-skeleton-time-grid {
704
704
  display: grid;
705
705
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
@@ -732,7 +732,7 @@
732
732
  aspect-ratio: 1;
733
733
  border-radius: var(--cal-radius-sm) !important;
734
734
  }
735
- `,Z={error:'<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><circle cx="7" cy="7" r="6"/><path d="M7 4v3M7 9.5v.01"/></svg>',warning:'<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><path d="M7 1.5L1 12.5h12L7 1.5zM7 6v2.5M7 10.5v.01"/></svg>',info:'<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><circle cx="7" cy="7" r="6"/><path d="M7 6.5V10M7 4.5v.01"/></svg>',success:'<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><circle cx="7" cy="7" r="6"/><path d="M4.5 7l2 2L9.5 5"/></svg>'};function Me({type:s="info",message:e,dismissible:a=!0,onDismiss:t}){const n=document.createElement("div");n.classList.add("cal-status",`cal-status--${s}`,"cal-animate-slide-up"),n.setAttribute("role",s==="error"?"alert":"status"),n.setAttribute("aria-live",s==="error"?"assertive":"polite");const r=document.createElement("span");r.classList.add("cal-status__icon"),r.innerHTML=Z[s]||Z.info,n.appendChild(r);const o=document.createElement("span");if(o.classList.add("cal-status__text"),o.textContent=e,n.appendChild(o),a){const l=document.createElement("button");l.classList.add("cal-status__close"),l.setAttribute("aria-label","Dismiss"),l.innerHTML='<svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><path d="M3 3l6 6M9 3l-6 6"/></svg>',l.addEventListener("click",()=>t==null?void 0:t()),n.appendChild(l)}return n}const Ce=`
735
+ `,ne={error:'<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><circle cx="7" cy="7" r="6"/><path d="M7 4v3M7 9.5v.01"/></svg>',warning:'<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><path d="M7 1.5L1 12.5h12L7 1.5zM7 6v2.5M7 10.5v.01"/></svg>',info:'<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><circle cx="7" cy="7" r="6"/><path d="M7 6.5V10M7 4.5v.01"/></svg>',success:'<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><circle cx="7" cy="7" r="6"/><path d="M4.5 7l2 2L9.5 5"/></svg>'};function Be({type:s="info",message:e,dismissible:a=!0,onDismiss:t}){const n=document.createElement("div");n.classList.add("cal-status",`cal-status--${s}`,"cal-animate-slide-up"),n.setAttribute("role",s==="error"?"alert":"status"),n.setAttribute("aria-live",s==="error"?"assertive":"polite");const r=document.createElement("span");r.classList.add("cal-status__icon"),r.innerHTML=ne[s]||ne.info,n.appendChild(r);const o=document.createElement("span");if(o.classList.add("cal-status__text"),o.textContent=e,n.appendChild(o),a){const l=document.createElement("button");l.classList.add("cal-status__close"),l.setAttribute("aria-label","Dismiss"),l.innerHTML='<svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><path d="M3 3l6 6M9 3l-6 6"/></svg>',l.addEventListener("click",()=>t==null?void 0:t()),n.appendChild(l)}return n}const ze=`
736
736
  .cal-status {
737
737
  display: flex;
738
738
  align-items: center;
@@ -794,7 +794,7 @@
794
794
  color: hsl(var(--cal-status-success-fg));
795
795
  border: 1px solid hsl(var(--cal-status-success-border));
796
796
  }
797
- `,Ae='<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="3" width="12" height="11" rx="2"/><path d="M5 1v3M11 1v3M2 7h12"/></svg>',Te=`
797
+ `,Pe='<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="3" width="12" height="11" rx="2"/><path d="M5 1v3M11 1v3M2 7h12"/></svg>',Oe=`
798
798
  .cal-picker {
799
799
  background: hsl(var(--cal-bg));
800
800
  border-radius: var(--cal-radius);
@@ -814,5 +814,5 @@
814
814
  .cal-month {
815
815
  flex: 0 0 auto;
816
816
  }
817
- `;class V extends B{static get styles(){return[ie,ce,de,fe,ve,ke,we,Le,Ee,Ce,Te]}static get observedAttributes(){return["mode","display","theme","value","min-date","max-date","disabled-dates","first-day","locale","presets","placeholder","loading"]}constructor(){super();const e=new Date;this._store=ae({viewYear:e.getFullYear(),viewMonth:e.getMonth(),selectedDates:[],rangeStart:null,rangeEnd:null,hoverDate:null,isOpen:!1,focusedDate:G(),navDirection:null,pickingMonth:!1,pickerYear:e.getFullYear(),statusType:null,statusMessage:null,statusDismissible:!0}),this._popover=null,this._unsubscribe=null,this._rendering=!1}get mode(){return this.getAttribute("mode")||"single"}get display(){return this.getAttribute("display")||"inline"}get placeholder(){return this.getAttribute("placeholder")||"Select date"}get firstDay(){return parseInt(this.getAttribute("first-day")||"0",10)}get minDate(){return this.getAttribute("min-date")||null}get maxDate(){return this.getAttribute("max-date")||null}get loading(){return this.hasAttribute("loading")}set loading(e){e?this.setAttribute("loading",""):this.removeAttribute("loading")}get disabledDates(){const e=this.getAttribute("disabled-dates");return e?e.split(",").map(a=>a.trim()):[]}get presetKeys(){const e=this.getAttribute("presets");return e?e.split(",").map(a=>a.trim()):[]}get value(){const e=this._store.getState();return this.mode==="range"?e.rangeStart&&e.rangeEnd?{start:e.rangeStart,end:e.rangeEnd}:null:this.mode==="multi"?[...e.selectedDates]:e.selectedDates[0]||null}set value(e){if(this.mode==="range"&&e&&typeof e=="object"){const a=typeof e.start=="string"?e.start:y(e.start),t=typeof e.end=="string"?e.end:y(e.end);this._store.set({rangeStart:a,rangeEnd:t,selectedDates:[a,t]}),this._navigateToDate(a)}else this.mode==="multi"&&Array.isArray(e)?(this._store.set({selectedDates:e}),e.length&&this._navigateToDate(e[0])):typeof e=="string"?(this._store.set({selectedDates:[e],rangeStart:null,rangeEnd:null}),this._navigateToDate(e)):this._store.set({selectedDates:[],rangeStart:null,rangeEnd:null})}_navigateToDate(e){const a=w(e);a&&this._store.set({viewYear:a.getFullYear(),viewMonth:a.getMonth()})}connectedCallback(){super.connectedCallback(),this._unsubscribe=this._store.subscribe((a,t)=>{if(this._rendering)return;a.hoverDate!==t.hoverDate&&a.viewYear===t.viewYear&&a.viewMonth===t.viewMonth&&a.selectedDates===t.selectedDates&&a.rangeStart===t.rangeStart&&a.rangeEnd===t.rangeEnd&&a.isOpen===t.isOpen&&a.navDirection===t.navDirection&&a.pickingMonth===t.pickingMonth&&a.pickerYear===t.pickerYear?this._updateGridHighlight(a):this.render()});const e=this.getAttribute("value");if(e)if(this.mode==="range"&&e.includes("/")){const[a,t]=e.split("/");this.value={start:a,end:t}}else this.mode==="multi"&&e.includes(",")?this.value=e.split(",").map(a=>a.trim()):this.value=e}disconnectedCallback(){var e,a;(e=this._unsubscribe)==null||e.call(this),(a=this._popover)==null||a.destroy(),clearTimeout(this._statusTimer)}attributeChangedCallback(e,a,t){if(a!==t){if(e==="value"&&this._initialized)if(this.mode==="range"&&t&&t.includes("/")){const[n,r]=t.split("/");this.value={start:n,end:r}}else this.mode==="multi"&&t&&t.includes(",")?this.value=t.split(",").map(n=>n.trim()):this.value=t;this._initialized&&this.render()}}_handleSelect(e){const a=this._store.getState();if(this.mode==="single")this._store.set({selectedDates:[e],focusedDate:e}),this.emit("cal:change",{value:e}),this.display==="popover"&&this.close();else if(this.mode==="range")if(!a.rangeStart||a.rangeEnd)this._store.set({rangeStart:e,rangeEnd:null,selectedDates:[e],focusedDate:e});else{let t=a.rangeStart,n=e;t>n&&([t,n]=[n,t]),this._store.set({rangeStart:t,rangeEnd:n,selectedDates:[t,n],hoverDate:null,focusedDate:n}),this.emit("cal:change",{value:{start:t,end:n}}),this.display==="popover"&&this.close()}else if(this.mode==="multi"){const t=[...a.selectedDates],n=t.findIndex(r=>S(r,e));n>=0?t.splice(n,1):t.push(e),t.sort(),this._store.set({selectedDates:t,focusedDate:e}),this.emit("cal:change",{value:t})}}_handleHover(e){this.mode==="range"&&this._store.set({hoverDate:e})}_handlePresetSelect({start:e,end:a}){this._store.set({rangeStart:e,rangeEnd:a,selectedDates:[e,a],hoverDate:null}),this._navigateToDate(e),this.emit("cal:change",{value:{start:e,end:a}}),this.display==="popover"&&this.close()}_prevMonth(){const{viewYear:e,viewMonth:a}=this._store.getState(),{year:t,month:n}=z(e,a,-1);this._store.set({viewYear:t,viewMonth:n,navDirection:"prev"}),this.emit("cal:month-change",{year:t,month:n})}_nextMonth(){const{viewYear:e,viewMonth:a}=this._store.getState(),{year:t,month:n}=z(e,a,1);this._store.set({viewYear:t,viewMonth:n,navDirection:"next"}),this.emit("cal:month-change",{year:t,month:n})}_toggleMonthPicker(){const e=this._store.getState();this._store.set({pickingMonth:!e.pickingMonth,pickerYear:e.viewYear})}_selectMonthFromPicker(e,a){this._store.set({viewYear:a,viewMonth:e,pickingMonth:!1}),this.emit("cal:month-change",{year:a,month:e})}_handleKeydown(e){if(e.key==="Escape"&&this._store.get("pickingMonth")){e.stopPropagation(),this._store.set({pickingMonth:!1});return}const a=this._store.getState(),t=w(a.focusedDate);if(!t)return;let n=null;switch(e.key){case"ArrowLeft":n=new Date(t),n.setDate(t.getDate()-1);break;case"ArrowRight":n=new Date(t),n.setDate(t.getDate()+1);break;case"ArrowUp":n=new Date(t),n.setDate(t.getDate()-7);break;case"ArrowDown":n=new Date(t),n.setDate(t.getDate()+7);break;case"Enter":case" ":e.preventDefault(),this._handleSelect(a.focusedDate);return;case"Escape":this.display==="popover"&&this.close();return;default:return}if(n){e.preventDefault();const r=y(n);n.getMonth()!==a.viewMonth||n.getFullYear()!==a.viewYear?this._store.set({viewYear:n.getFullYear(),viewMonth:n.getMonth(),focusedDate:r,navDirection:n>t?"next":"prev"}):this._store.set({focusedDate:r}),requestAnimationFrame(()=>{const o=this.$(`[data-date="${r}"]`);o==null||o.focus()})}}_updateGridHighlight(e){const a=this.$$(".cal-day"),{rangeStart:t,hoverDate:n}=e,r=t&&!e.rangeEnd&&n?n:e.rangeEnd;for(const o of a){const l=o.dataset.date;if(!l||o.classList.contains("cal-day--disabled"))continue;const i=l===t,g=l===r;let h=!1;if(t&&r){const u=t<r?t:r,d=t<r?r:t;h=l>=u&&l<=d&&!i&&!g}o.classList.toggle("cal-day--range-start",i&&!!r),o.classList.toggle("cal-day--range-end",g&&!!r),o.classList.toggle("cal-day--in-range",h)}}open(){this._popover&&(this._popover.open(),this._store.set({isOpen:!0}),this.emit("cal:open"))}close(){this._popover&&(this._popover.close(),this._store.set({isOpen:!1}),this.emit("cal:close"))}goToMonth(e,a){this._store.set({viewYear:a,viewMonth:e})}_renderCalendarContent(){const e=this._store.getState(),a=document.createElement("div");if(a.classList.add("cal-picker"),e.statusType&&e.statusMessage&&a.appendChild(Me({type:e.statusType,message:e.statusMessage,dismissible:e.statusDismissible,onDismiss:()=>this.clearStatus()})),this.loading){const o=document.createElement("div");o.classList.add("cal-months");const l=document.createElement("div");return l.classList.add("cal-month"),l.appendChild(Se()),o.appendChild(l),a.appendChild(o),a.addEventListener("keydown",i=>this._handleKeydown(i)),a}const t=document.createElement("div");t.classList.add("cal-months");const n=this.mode==="range"&&this.hasAttribute("dual"),r=n?2:1;for(let o=0;o<r;o++){const{year:l,month:i}=o===0?{year:e.viewYear,month:e.viewMonth}:z(e.viewYear,e.viewMonth,1),g=document.createElement("div");if(g.classList.add("cal-month"),o===0&&g.appendChild(Q({year:l,month:i,onPrev:e.pickingMonth?()=>{}:()=>this._prevMonth(),onNext:e.pickingMonth?()=>{}:()=>{n||this._nextMonth()},onTitleClick:()=>this._toggleMonthPicker()})),o===1&&g.appendChild(Q({year:l,month:i,onPrev:()=>{},onNext:()=>this._nextMonth()})),e.pickingMonth&&o===0){const h=me({pickerYear:e.pickerYear,viewMonth:e.viewMonth,viewYear:e.viewYear,onMonthSelect:(u,d)=>this._selectMonthFromPicker(u,d),onYearPrev:()=>this._store.set({pickerYear:e.pickerYear-1}),onYearNext:()=>this._store.set({pickerYear:e.pickerYear+1}),onClose:()=>this._store.set({pickingMonth:!1})});g.appendChild(h)}else{const h=e.navDirection==="next"?"cal-animate-slide-left":e.navDirection==="prev"?"cal-animate-slide-right":"",u=pe({year:l,month:i,firstDay:this.firstDay,selectedDates:e.selectedDates,rangeStart:e.rangeStart,rangeEnd:e.rangeEnd,hoverDate:e.hoverDate,minDate:this.minDate,maxDate:this.maxDate,disabledDates:this.disabledDates,mode:this.mode,focusedDate:e.focusedDate,onSelect:d=>this._handleSelect(d),onHover:d=>this._handleHover(d)});h&&u.classList.add(h),g.appendChild(u)}t.appendChild(g)}return a.appendChild(t),this.mode==="range"&&this.presetKeys.length&&a.appendChild(xe({presetKeys:this.presetKeys,onSelect:o=>this._handlePresetSelect(o)})),a.addEventListener("keydown",o=>this._handleKeydown(o)),a}_formatTriggerText(){const e=this._store.getState();return this.mode==="range"&&e.rangeStart&&e.rangeEnd?`${this._formatShortDate(e.rangeStart)} – ${this._formatShortDate(e.rangeEnd)}`:e.selectedDates.length?this.mode==="multi"?`${e.selectedDates.length} dates selected`:this._formatShortDate(e.selectedDates[0]):null}_formatShortDate(e){const a=w(e);return a?`${K[a.getMonth()].slice(0,3)} ${a.getDate()}, ${a.getFullYear()}`:e}render(){var t;if(this._rendering)return;this._rendering=!0;const e=this.shadowRoot,a=[...e.childNodes];for(const n of a)n.nodeName!=="STYLE"&&!(n instanceof CSSStyleSheet)&&e.removeChild(n);if((t=this._popover)==null||t.destroy(),this._popover=null,this.display==="popover"){const n=document.createElement("div");n.classList.add("cal-popover-wrapper");const r=document.createElement("button");r.classList.add("cal-trigger");const o=document.createElement("span");o.classList.add("cal-trigger__icon"),o.innerHTML=Ae,r.appendChild(o);const l=this._formatTriggerText(),i=document.createElement("span");l?i.textContent=l:(i.textContent=this.placeholder,i.classList.add("cal-trigger--placeholder")),r.appendChild(i),n.appendChild(r);const g=this._renderCalendarContent(),h=De({trigger:r,content:g,onClose:()=>{this._store.set({isOpen:!1}),this.emit("cal:close")}});n.appendChild(h.panel),e.appendChild(n),r.addEventListener("click",u=>{u.stopPropagation(),h.isOpen?this.close():this.open()}),this._popover=h,this._store.get("isOpen")&&h.open()}else e.appendChild(this._renderCalendarContent());this._store.set({navDirection:null}),this._rendering=!1}}customElements.get("cal-datepicker")||customElements.define("cal-datepicker",V),C.CalDatepicker=V,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})}));
817
+ `;class se extends B{static get styles(){return[pe,be,fe,we,xe,Le,Me,Ae,Ye,ze,Oe]}static get observedAttributes(){return["mode","display","theme","value","min-date","max-date","disabled-dates","first-day","locale","presets","placeholder","loading"]}constructor(){super();const e=new Date;this._store=le({viewYear:e.getFullYear(),viewMonth:e.getMonth(),selectedDates:[],rangeStart:null,rangeEnd:null,hoverDate:null,isOpen:!1,focusedDate:J(),navDirection:null,pickingMonth:!1,pickerYear:e.getFullYear(),statusType:null,statusMessage:null,statusDismissible:!0}),this._popover=null,this._unsubscribe=null,this._rendering=!1}get mode(){return this.getAttribute("mode")||"single"}get display(){return this.getAttribute("display")||"inline"}get placeholder(){return this.getAttribute("placeholder")||"Select date"}get firstDay(){return parseInt(this.getAttribute("first-day")||"0",10)}get minDate(){return this.getAttribute("min-date")||null}get maxDate(){return this.getAttribute("max-date")||null}get locale(){return this.getAttribute("locale")||void 0}get loading(){return this.hasAttribute("loading")}set loading(e){e?this.setAttribute("loading",""):this.removeAttribute("loading")}get disabledDates(){const e=this.getAttribute("disabled-dates");return e?e.split(",").map(a=>a.trim()):[]}get presetKeys(){const e=this.getAttribute("presets");return e?e.split(",").map(a=>a.trim()):[]}get value(){const e=this._store.getState();return this.mode==="range"?e.rangeStart&&e.rangeEnd?{start:e.rangeStart,end:e.rangeEnd}:null:this.mode==="multi"?[...e.selectedDates]:e.selectedDates[0]||null}set value(e){if(this.mode==="range"&&e&&typeof e=="object"){const a=typeof e.start=="string"?e.start:m(e.start),t=typeof e.end=="string"?e.end:m(e.end);this._store.set({rangeStart:a,rangeEnd:t,selectedDates:[a,t]}),this._navigateToDate(a)}else this.mode==="multi"&&Array.isArray(e)?(this._store.set({selectedDates:e}),e.length&&this._navigateToDate(e[0])):typeof e=="string"?(this._store.set({selectedDates:[e],rangeStart:null,rangeEnd:null}),this._navigateToDate(e)):this._store.set({selectedDates:[],rangeStart:null,rangeEnd:null})}_navigateToDate(e){const a=D(e);a&&this._store.set({viewYear:a.getFullYear(),viewMonth:a.getMonth()})}connectedCallback(){super.connectedCallback(),this._unsubscribe=this._store.subscribe((a,t)=>{if(this._rendering)return;a.hoverDate!==t.hoverDate&&a.viewYear===t.viewYear&&a.viewMonth===t.viewMonth&&a.selectedDates===t.selectedDates&&a.rangeStart===t.rangeStart&&a.rangeEnd===t.rangeEnd&&a.isOpen===t.isOpen&&a.navDirection===t.navDirection&&a.pickingMonth===t.pickingMonth&&a.pickerYear===t.pickerYear?this._updateGridHighlight(a):this.render()});const e=this.getAttribute("value");if(e)if(this.mode==="range"&&e.includes("/")){const[a,t]=e.split("/");this.value={start:a,end:t}}else this.mode==="multi"&&e.includes(",")?this.value=e.split(",").map(a=>a.trim()):this.value=e}disconnectedCallback(){var e,a;(e=this._unsubscribe)==null||e.call(this),(a=this._popover)==null||a.destroy(),clearTimeout(this._statusTimer)}attributeChangedCallback(e,a,t){if(a!==t){if(e==="value"&&this._initialized)if(this.mode==="range"&&t&&t.includes("/")){const[n,r]=t.split("/");this.value={start:n,end:r}}else this.mode==="multi"&&t&&t.includes(",")?this.value=t.split(",").map(n=>n.trim()):this.value=t;this._initialized&&this.render()}}_handleSelect(e){const a=this._store.getState();if(this.mode==="single")this._store.set({selectedDates:[e],focusedDate:e}),this.emit("cal:change",{value:e}),this.display==="popover"&&this.close();else if(this.mode==="range")if(!a.rangeStart||a.rangeEnd)this._store.set({rangeStart:e,rangeEnd:null,selectedDates:[e],focusedDate:e});else{let t=a.rangeStart,n=e;t>n&&([t,n]=[n,t]),this._store.set({rangeStart:t,rangeEnd:n,selectedDates:[t,n],hoverDate:null,focusedDate:n}),this.emit("cal:change",{value:{start:t,end:n}}),this.display==="popover"&&this.close()}else if(this.mode==="multi"){const t=[...a.selectedDates],n=t.findIndex(r=>E(r,e));n>=0?t.splice(n,1):t.push(e),t.sort(),this._store.set({selectedDates:t,focusedDate:e}),this.emit("cal:change",{value:t})}}_handleHover(e){this.mode==="range"&&this._store.set({hoverDate:e})}_handlePresetSelect({start:e,end:a}){this._store.set({rangeStart:e,rangeEnd:a,selectedDates:[e,a],hoverDate:null}),this._navigateToDate(e),this.emit("cal:change",{value:{start:e,end:a}}),this.display==="popover"&&this.close()}_prevMonth(){const{viewYear:e,viewMonth:a}=this._store.getState(),{year:t,month:n}=z(e,a,-1);this._store.set({viewYear:t,viewMonth:n,navDirection:"prev"}),this.emit("cal:month-change",{year:t,month:n})}_nextMonth(){const{viewYear:e,viewMonth:a}=this._store.getState(),{year:t,month:n}=z(e,a,1);this._store.set({viewYear:t,viewMonth:n,navDirection:"next"}),this.emit("cal:month-change",{year:t,month:n})}_toggleMonthPicker(){const e=this._store.getState();this._store.set({pickingMonth:!e.pickingMonth,pickerYear:e.viewYear})}_selectMonthFromPicker(e,a){this._store.set({viewYear:a,viewMonth:e,pickingMonth:!1}),this.emit("cal:month-change",{year:a,month:e})}_handleKeydown(e){if(e.key==="Escape"&&this._store.get("pickingMonth")){e.stopPropagation(),this._store.set({pickingMonth:!1});return}const a=this._store.getState(),t=D(a.focusedDate);if(!t)return;let n=null;switch(e.key){case"ArrowLeft":n=new Date(t),n.setDate(t.getDate()-1);break;case"ArrowRight":n=new Date(t),n.setDate(t.getDate()+1);break;case"ArrowUp":n=new Date(t),n.setDate(t.getDate()-7);break;case"ArrowDown":n=new Date(t),n.setDate(t.getDate()+7);break;case"Enter":case" ":e.preventDefault(),this._handleSelect(a.focusedDate);return;case"Escape":this.display==="popover"&&this.close();return;default:return}if(n){e.preventDefault();const r=m(n);n.getMonth()!==a.viewMonth||n.getFullYear()!==a.viewYear?this._store.set({viewYear:n.getFullYear(),viewMonth:n.getMonth(),focusedDate:r,navDirection:n>t?"next":"prev"}):this._store.set({focusedDate:r}),requestAnimationFrame(()=>{const o=this.$(`[data-date="${r}"]`);o==null||o.focus()})}}_updateGridHighlight(e){const a=this.$$(".cal-day"),{rangeStart:t,hoverDate:n}=e,r=t&&!e.rangeEnd&&n?n:e.rangeEnd;for(const o of a){const l=o.dataset.date;if(!l||o.classList.contains("cal-day--disabled"))continue;const i=l===t,h=l===r;let d=!1;if(t&&r){const g=t<r?t:r,u=t<r?r:t;d=l>=g&&l<=u&&!i&&!h}o.classList.toggle("cal-day--range-start",i&&!!r),o.classList.toggle("cal-day--range-end",h&&!!r),o.classList.toggle("cal-day--in-range",d)}}open(){this._popover&&(this._popover.open(),this._store.set({isOpen:!0}),this.emit("cal:open"))}close(){this._popover&&(this._popover.close(),this._store.set({isOpen:!1}),this.emit("cal:close"))}goToMonth(e,a){this._store.set({viewYear:a,viewMonth:e})}clear(){this._store.set({selectedDates:[],rangeStart:null,rangeEnd:null,hoverDate:null}),this.emit("cal:change",{value:null})}_renderCalendarContent(){const e=this._store.getState(),a=document.createElement("div");if(a.classList.add("cal-picker"),e.statusType&&e.statusMessage&&a.appendChild(Be({type:e.statusType,message:e.statusMessage,dismissible:e.statusDismissible,onDismiss:()=>this.clearStatus()})),this.loading){const o=document.createElement("div");o.classList.add("cal-months");const l=document.createElement("div");return l.classList.add("cal-month"),l.appendChild(Te()),o.appendChild(l),a.appendChild(o),a.addEventListener("keydown",i=>this._handleKeydown(i)),a}const t=document.createElement("div");t.classList.add("cal-months");const n=this.mode==="range"&&this.hasAttribute("dual"),r=n?2:1;for(let o=0;o<r;o++){const{year:l,month:i}=o===0?{year:e.viewYear,month:e.viewMonth}:z(e.viewYear,e.viewMonth,1),h=document.createElement("div");if(h.classList.add("cal-month"),o===0&&h.appendChild(te({year:l,month:i,onPrev:e.pickingMonth?()=>{}:()=>this._prevMonth(),onNext:e.pickingMonth?()=>{}:()=>{n||this._nextMonth()},onTitleClick:()=>this._toggleMonthPicker(),locale:this.locale})),o===1&&h.appendChild(te({year:l,month:i,onPrev:()=>{},onNext:()=>this._nextMonth(),locale:this.locale})),e.pickingMonth&&o===0){const d=De({pickerYear:e.pickerYear,viewMonth:e.viewMonth,viewYear:e.viewYear,onMonthSelect:(g,u)=>this._selectMonthFromPicker(g,u),onYearPrev:()=>this._store.set({pickerYear:e.pickerYear-1}),onYearNext:()=>this._store.set({pickerYear:e.pickerYear+1}),onClose:()=>this._store.set({pickingMonth:!1}),locale:this.locale});h.appendChild(d)}else{const d=e.navDirection==="next"?"cal-animate-slide-left":e.navDirection==="prev"?"cal-animate-slide-right":"",g=ke({year:l,month:i,firstDay:this.firstDay,selectedDates:e.selectedDates,rangeStart:e.rangeStart,rangeEnd:e.rangeEnd,hoverDate:e.hoverDate,minDate:this.minDate,maxDate:this.maxDate,disabledDates:this.disabledDates,mode:this.mode,focusedDate:e.focusedDate,onSelect:u=>this._handleSelect(u),onHover:u=>this._handleHover(u),locale:this.locale});d&&g.classList.add(d),h.appendChild(g)}t.appendChild(h)}return a.appendChild(t),this.mode==="range"&&this.presetKeys.length&&a.appendChild(Ee({presetKeys:this.presetKeys,onSelect:o=>this._handlePresetSelect(o),locale:this.locale})),a.addEventListener("keydown",o=>this._handleKeydown(o)),a}_formatTriggerText(){const e=this._store.getState();return this.mode==="range"&&e.rangeStart&&e.rangeEnd?`${this._formatShortDate(e.rangeStart)} – ${this._formatShortDate(e.rangeEnd)}`:e.selectedDates.length?this.mode==="multi"?`${e.selectedDates.length} dates selected`:this._formatShortDate(e.selectedDates[0]):null}_formatShortDate(e){const a=D(e);if(!a)return e;if(this.locale)try{return new Intl.DateTimeFormat(this.locale,{month:"short",day:"numeric",year:"numeric"}).format(a)}catch{}return`${q(this.locale)[a.getMonth()]} ${a.getDate()}, ${a.getFullYear()}`}render(){var t;if(this._rendering)return;this._rendering=!0;const e=this.shadowRoot,a=[...e.childNodes];for(const n of a)n.nodeName!=="STYLE"&&!(n instanceof CSSStyleSheet)&&e.removeChild(n);if((t=this._popover)==null||t.destroy(),this._popover=null,this.display==="popover"){const n=document.createElement("div");n.classList.add("cal-popover-wrapper");const r=document.createElement("button");r.classList.add("cal-trigger");const o=document.createElement("span");o.classList.add("cal-trigger__icon"),o.innerHTML=Pe,r.appendChild(o);const l=this._formatTriggerText(),i=document.createElement("span");l?i.textContent=l:(i.textContent=this.placeholder,i.classList.add("cal-trigger--placeholder")),r.appendChild(i),n.appendChild(r);const h=this._renderCalendarContent(),d=Ce({trigger:r,content:h,onClose:()=>{this._store.set({isOpen:!1}),this.emit("cal:close")}});n.appendChild(d.panel),e.appendChild(n),r.addEventListener("click",g=>{g.stopPropagation(),d.isOpen?this.close():this.open()}),this._popover=d,this._store.get("isOpen")&&d.open()}else e.appendChild(this._renderCalendarContent());this._store.set({navDirection:null}),this._rendering=!1}}customElements.get("cal-datepicker")||customElements.define("cal-datepicker",se),A.CalDatepicker=se,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})}));
818
818
  //# sourceMappingURL=datepicker.umd.js.map